public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v7] bfin_mac: convert bfin Ethernet driver to NAPI framework
@ 2014-07-22  7:38 Sonic Zhang
  2014-07-22  7:59 ` Eric Dumazet
  2014-07-22 22:16 ` Francois Romieu
  0 siblings, 2 replies; 10+ messages in thread
From: Sonic Zhang @ 2014-07-22  7:38 UTC (permalink / raw)
  To: David S. Miller, netdev; +Cc: Francois Romieu, adi-buildroot-devel, Sonic Zhang

From: Sonic Zhang <sonic.zhang@analog.com>

Ethernet RX DMA buffers are polled in NAPI work queue other than received
directly in DMA RX interrupt handler.

Signed-off-by: Sonic Zhang <sonic.zhang@analog.com>

---
v2-changes:
- avoid test NAPI_STATE_NPSVC bit in net device driver

v3-changes:
- use tabs while indenting the code

v4-changes:
- unconditionally complete the NAPI poll and re-enable the MAC_RX IRQ

v5-changes:
- should match open parenthesis

v6-changes:
- keep a count of bfin_mac_interrupt disabled mac_rx irq in the device private
area then call enable_irq in bfin_mac_poll

v7-changes:
- only IRQ disable when rx_irq_disabled is zero before the increment
and only do the IRQ enable when decrementing rx_irq_disabled will cause
it to become zero
---
 drivers/net/ethernet/adi/bfin_mac.c | 80 +++++++++++++++++++++++--------------
 drivers/net/ethernet/adi/bfin_mac.h |  2 +
 2 files changed, 52 insertions(+), 30 deletions(-)

diff --git a/drivers/net/ethernet/adi/bfin_mac.c b/drivers/net/ethernet/adi/bfin_mac.c
index 7ae74d4..8924802 100644
--- a/drivers/net/ethernet/adi/bfin_mac.c
+++ b/drivers/net/ethernet/adi/bfin_mac.c
@@ -1218,11 +1218,11 @@ out:
 #define RX_ERROR_MASK (RX_LONG | RX_ALIGN | RX_CRC | RX_LEN | \
 	RX_FRAG | RX_ADDR | RX_DMAO | RX_PHY | RX_LATE | RX_RANGE)
 
-static void bfin_mac_rx(struct net_device *dev)
+static void bfin_mac_rx(struct bfin_mac_local *lp, int budget)
 {
+	struct net_device *dev = lp->ndev;
 	struct sk_buff *skb, *new_skb;
 	unsigned short len;
-	struct bfin_mac_local *lp __maybe_unused = netdev_priv(dev);
 #if defined(BFIN_MAC_CSUM_OFFLOAD)
 	unsigned int i;
 	unsigned char fcs[ETH_FCS_LEN + 1];
@@ -1256,7 +1256,7 @@ static void bfin_mac_rx(struct net_device *dev)
 	current_rx_ptr->skb = new_skb;
 	current_rx_ptr->desc_a.start_addr = (unsigned long)new_skb->data - 2;
 
-	len = (unsigned short)((current_rx_ptr->status.status_word) & RX_FRLEN);
+	len = (unsigned short)(current_rx_ptr->status.status_word & RX_FRLEN);
 	/* Deduce Ethernet FCS length from Ethernet payload length */
 	len -= ETH_FCS_LEN;
 	skb_put(skb, len);
@@ -1294,7 +1294,8 @@ static void bfin_mac_rx(struct net_device *dev)
 	}
 #endif
 
-	netif_rx(skb);
+	napi_gro_receive(&lp->napi, skb);
+
 	dev->stats.rx_packets++;
 	dev->stats.rx_bytes += len;
 out:
@@ -1302,41 +1303,53 @@ out:
 	current_rx_ptr = current_rx_ptr->next;
 }
 
+static int bfin_mac_poll(struct napi_struct *napi, int budget)
+{
+	int i = 0;
+	struct bfin_mac_local *lp = container_of(napi,
+						 struct bfin_mac_local,
+						 napi);
+
+	while (current_rx_ptr->status.status_word != 0 && i < budget) {
+		bfin_mac_rx(lp, budget);
+		i++;
+	}
+
+	if (i < budget) {
+		napi_complete(napi);
+		if (lp->rx_irq_disabled--)
+			if (!lp->rx_irq_disabled)
+				enable_irq(IRQ_MAC_RX);
+	}
+
+	return i;
+}
+
 /* interrupt routine to handle rx and error signal */
 static irqreturn_t bfin_mac_interrupt(int irq, void *dev_id)
 {
-	struct net_device *dev = dev_id;
-	int number = 0;
-
-get_one_packet:
-	if (current_rx_ptr->status.status_word == 0) {
-		/* no more new packet received */
-		if (number == 0) {
-			if (current_rx_ptr->next->status.status_word != 0) {
-				current_rx_ptr = current_rx_ptr->next;
-				goto real_rx;
-			}
-		}
-		bfin_write_DMA1_IRQ_STATUS(bfin_read_DMA1_IRQ_STATUS() |
-					   DMA_DONE | DMA_ERR);
-		return IRQ_HANDLED;
+	struct bfin_mac_local *lp = netdev_priv(dev_id);
+	u32 status;
+
+	status = bfin_read_DMA1_IRQ_STATUS();
+
+	bfin_write_DMA1_IRQ_STATUS(status | DMA_DONE | DMA_ERR);
+	if ((status & DMA_DONE) && napi_schedule_prep(&lp->napi)) {
+		if (!lp->rx_irq_disabled++)
+			disable_irq_nosync(IRQ_MAC_RX);
+		__napi_schedule(&lp->napi);
 	}
 
-real_rx:
-	bfin_mac_rx(dev);
-	number++;
-	goto get_one_packet;
+	return IRQ_HANDLED;
 }
 
 #ifdef CONFIG_NET_POLL_CONTROLLER
-static void bfin_mac_poll(struct net_device *dev)
+static void bfin_mac_poll_controller(struct net_device *dev)
 {
 	struct bfin_mac_local *lp = netdev_priv(dev);
 
-	disable_irq(IRQ_MAC_RX);
 	bfin_mac_interrupt(IRQ_MAC_RX, dev);
 	tx_reclaim_skb(lp);
-	enable_irq(IRQ_MAC_RX);
 }
 #endif				/* CONFIG_NET_POLL_CONTROLLER */
 
@@ -1428,14 +1441,13 @@ static void bfin_mac_timeout(struct net_device *dev)
 		tx_list_head = tx_list_head->next;
 	}
 
-	if (netif_queue_stopped(lp->ndev))
-		netif_wake_queue(lp->ndev);
+	if (netif_queue_stopped(dev))
+		netif_wake_queue(dev);
 
 	bfin_mac_enable(lp->phydev);
 
 	/* We can accept TX packets again */
 	dev->trans_start = jiffies; /* prevent tx timeout */
-	netif_wake_queue(dev);
 }
 
 static void bfin_mac_multicast_hash(struct net_device *dev)
@@ -1562,6 +1574,7 @@ static int bfin_mac_open(struct net_device *dev)
 		return ret;
 	pr_debug("hardware init finished\n");
 
+	napi_enable(&lp->napi);
 	netif_start_queue(dev);
 	netif_carrier_on(dev);
 
@@ -1579,6 +1592,7 @@ static int bfin_mac_close(struct net_device *dev)
 	pr_debug("%s: %s\n", dev->name, __func__);
 
 	netif_stop_queue(dev);
+	napi_disable(&lp->napi);
 	netif_carrier_off(dev);
 
 	phy_stop(lp->phydev);
@@ -1604,7 +1618,7 @@ static const struct net_device_ops bfin_mac_netdev_ops = {
 	.ndo_validate_addr	= eth_validate_addr,
 	.ndo_change_mtu		= eth_change_mtu,
 #ifdef CONFIG_NET_POLL_CONTROLLER
-	.ndo_poll_controller	= bfin_mac_poll,
+	.ndo_poll_controller	= bfin_mac_poll_controller,
 #endif
 };
 
@@ -1689,6 +1703,9 @@ static int bfin_mac_probe(struct platform_device *pdev)
 	lp->tx_reclaim_timer.data = (unsigned long)lp;
 	lp->tx_reclaim_timer.function = tx_reclaim_skb_timeout;
 
+	lp->rx_irq_disabled = 0;
+	netif_napi_add(ndev, &lp->napi, bfin_mac_poll, CONFIG_BFIN_RX_DESC_NUM);
+
 	spin_lock_init(&lp->lock);
 
 	/* now, enable interrupts */
@@ -1723,6 +1740,7 @@ out_err_phc:
 out_err_reg_ndev:
 	free_irq(IRQ_MAC_RX, ndev);
 out_err_request_irq:
+	netif_napi_del(&lp->napi);
 out_err_mii_probe:
 	mdiobus_unregister(lp->mii_bus);
 	mdiobus_free(lp->mii_bus);
@@ -1743,6 +1761,8 @@ static int bfin_mac_remove(struct platform_device *pdev)
 
 	unregister_netdev(ndev);
 
+	netif_napi_del(&lp->napi);
+
 	free_irq(IRQ_MAC_RX, ndev);
 
 	free_netdev(ndev);
diff --git a/drivers/net/ethernet/adi/bfin_mac.h b/drivers/net/ethernet/adi/bfin_mac.h
index 6dec86a..f7f2e68 100644
--- a/drivers/net/ethernet/adi/bfin_mac.h
+++ b/drivers/net/ethernet/adi/bfin_mac.h
@@ -80,6 +80,8 @@ struct bfin_mac_local {
 	int irq_wake_requested;
 	struct timer_list tx_reclaim_timer;
 	struct net_device *ndev;
+	struct napi_struct napi;
+	int rx_irq_disabled;
 
 	/* Data for EMAC_VLAN1 regs */
 	u16 vlan1_mask, vlan2_mask;
-- 
1.8.2.3

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH v7] bfin_mac: convert bfin Ethernet driver to NAPI framework
  2014-07-22  7:38 [PATCH v7] bfin_mac: convert bfin Ethernet driver to NAPI framework Sonic Zhang
@ 2014-07-22  7:59 ` Eric Dumazet
  2014-07-22  8:01   ` David Miller
  2014-07-22 22:16 ` Francois Romieu
  1 sibling, 1 reply; 10+ messages in thread
From: Eric Dumazet @ 2014-07-22  7:59 UTC (permalink / raw)
  To: Sonic Zhang
  Cc: David S. Miller, netdev, Francois Romieu, adi-buildroot-devel,
	Sonic Zhang

On Tue, 2014-07-22 at 15:38 +0800, Sonic Zhang wrote:
> From: Sonic Zhang <sonic.zhang@analog.com>

> +	if (i < budget) {
> +		napi_complete(napi);
> +		if (lp->rx_irq_disabled--)
> +			if (!lp->rx_irq_disabled)
> +				enable_irq(IRQ_MAC_RX);


You wrote :

	if (A--)
		if (!A)
			something();

Isnt a bit strange ???

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v7] bfin_mac: convert bfin Ethernet driver to NAPI framework
  2014-07-22  7:59 ` Eric Dumazet
@ 2014-07-22  8:01   ` David Miller
  2014-07-22  8:53     ` Sonic Zhang
  2014-07-22 10:12     ` Sonic Zhang
  0 siblings, 2 replies; 10+ messages in thread
From: David Miller @ 2014-07-22  8:01 UTC (permalink / raw)
  To: eric.dumazet; +Cc: sonic.adi, netdev, romieu, adi-buildroot-devel, sonic.zhang

From: Eric Dumazet <eric.dumazet@gmail.com>
Date: Tue, 22 Jul 2014 09:59:44 +0200

> On Tue, 2014-07-22 at 15:38 +0800, Sonic Zhang wrote:
>> From: Sonic Zhang <sonic.zhang@analog.com>
> 
>> +	if (i < budget) {
>> +		napi_complete(napi);
>> +		if (lp->rx_irq_disabled--)
>> +			if (!lp->rx_irq_disabled)
>> +				enable_irq(IRQ_MAC_RX);
> 
> 
> You wrote :
> 
> 	if (A--)
> 		if (!A)
> 			something();
> 
> Isnt a bit strange ???

Indeed, it's very strange, how about:

	if (!--lp->rx_irq_disabled)

which is the canonical way to express this.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v7] bfin_mac: convert bfin Ethernet driver to NAPI framework
  2014-07-22  8:01   ` David Miller
@ 2014-07-22  8:53     ` Sonic Zhang
  2014-07-22  9:10       ` David Laight
  2014-07-22  9:51       ` Eric Dumazet
  2014-07-22 10:12     ` Sonic Zhang
  1 sibling, 2 replies; 10+ messages in thread
From: Sonic Zhang @ 2014-07-22  8:53 UTC (permalink / raw)
  To: David Miller
  Cc: Eric Dumazet, netdev, Francois Romieu, adi-buildroot-devel,
	Zhang, Sonic

Hi David,

On Tue, Jul 22, 2014 at 4:01 PM, David Miller <davem@davemloft.net> wrote:
> From: Eric Dumazet <eric.dumazet@gmail.com>
> Date: Tue, 22 Jul 2014 09:59:44 +0200
>
>> On Tue, 2014-07-22 at 15:38 +0800, Sonic Zhang wrote:
>>> From: Sonic Zhang <sonic.zhang@analog.com>
>>
>>> +    if (i < budget) {
>>> +            napi_complete(napi);
>>> +            if (lp->rx_irq_disabled--)
>>> +                    if (!lp->rx_irq_disabled)
>>> +                            enable_irq(IRQ_MAC_RX);
>>
>>
>> You wrote :
>>
>>       if (A--)
>>               if (!A)
>>                       something();
>>
>> Isnt a bit strange ???
>
> Indeed, it's very strange, how about:
>
>         if (!--lp->rx_irq_disabled)
>
> which is the canonical way to express this.

if (!--A)

doesn't equal to

if (A--)
        if (!A)

In net poll loop, because of NAPI state bit NAPI_STATE_NPSVC, the napi
poll callback may be called with A = 0 (MAC RX IRQ is enabled) if
napi_complete() other than __napi_complete() is used. See the
explanation in my last email.

In this case, the up condition decreases A to a negative number and
the interrupt handler condition "if (!A++)" can never increase A back
to 0 (disable the RX IRQ). While, the down condition only decreases A
if it is not 0.


Regards,

Sonic

^ permalink raw reply	[flat|nested] 10+ messages in thread

* RE: [PATCH v7] bfin_mac: convert bfin Ethernet driver to NAPI framework
  2014-07-22  8:53     ` Sonic Zhang
@ 2014-07-22  9:10       ` David Laight
  2014-07-22  9:51       ` Eric Dumazet
  1 sibling, 0 replies; 10+ messages in thread
From: David Laight @ 2014-07-22  9:10 UTC (permalink / raw)
  To: 'Sonic Zhang', David Miller
  Cc: Eric Dumazet, netdev, Francois Romieu,
	adi-buildroot-devel@lists.sourceforge.net, Zhang, Sonic

From: Sonic Zhang
...
> if (!--A)
> 
> doesn't equal to
> 
> if (A--)
>         if (!A)
> 
> In net poll loop, because of NAPI state bit NAPI_STATE_NPSVC, the napi
> poll callback may be called with A = 0 (MAC RX IRQ is enabled) if
> napi_complete() other than __napi_complete() is used. See the
> explanation in my last email.
> 
> In this case, the up condition decreases A to a negative number and
> the interrupt handler condition "if (!A++)" can never increase A back
> to 0 (disable the RX IRQ). While, the down condition only decreases A
> if it is not 0.

The logic doesn't matter, the C is equivalent - the compiler probably
generates the same code.
The only time they might be different is if 'A' is volatile.
Well, apart from the non-deterministic cases where other code is
modifying the variable at the same time - and you are at the whim
of the compiler.

	David


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v7] bfin_mac: convert bfin Ethernet driver to NAPI framework
  2014-07-22  8:53     ` Sonic Zhang
  2014-07-22  9:10       ` David Laight
@ 2014-07-22  9:51       ` Eric Dumazet
  2014-07-22 10:10         ` Sonic Zhang
  1 sibling, 1 reply; 10+ messages in thread
From: Eric Dumazet @ 2014-07-22  9:51 UTC (permalink / raw)
  To: Sonic Zhang
  Cc: David Miller, netdev, Francois Romieu, adi-buildroot-devel,
	Zhang, Sonic

On Tue, 2014-07-22 at 16:53 +0800, Sonic Zhang wrote:

> if (!--A)
> 
> doesn't equal to
> 
> if (A--)
>         if (!A)

It really does, no matter what you think.

In all cases, A is decremented.

In all cases, final action is done if and only if A was 1 before the
test(s)

Thats simple logic, and all your arguments about NAPI, IRQ, and moon
phase are irrelevant.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v7] bfin_mac: convert bfin Ethernet driver to NAPI framework
  2014-07-22  9:51       ` Eric Dumazet
@ 2014-07-22 10:10         ` Sonic Zhang
  0 siblings, 0 replies; 10+ messages in thread
From: Sonic Zhang @ 2014-07-22 10:10 UTC (permalink / raw)
  To: Eric Dumazet
  Cc: David Miller, netdev, Francois Romieu, adi-buildroot-devel,
	Zhang, Sonic

On Tue, Jul 22, 2014 at 5:51 PM, Eric Dumazet <eric.dumazet@gmail.com> wrote:
> On Tue, 2014-07-22 at 16:53 +0800, Sonic Zhang wrote:
>
>> if (!--A)
>>
>> doesn't equal to
>>
>> if (A--)
>>         if (!A)
>
> It really does, no matter what you think.
>
> In all cases, A is decremented.
>
> In all cases, final action is done if and only if A was 1 before the
> test(s)
>
> Thats simple logic, and all your arguments about NAPI, IRQ, and moon
> phase are irrelevant.
>

Thank you for correcting. I think I made a mistake on the condition logic.

Regards,

Sonic

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v7] bfin_mac: convert bfin Ethernet driver to NAPI framework
  2014-07-22  8:01   ` David Miller
  2014-07-22  8:53     ` Sonic Zhang
@ 2014-07-22 10:12     ` Sonic Zhang
  1 sibling, 0 replies; 10+ messages in thread
From: Sonic Zhang @ 2014-07-22 10:12 UTC (permalink / raw)
  To: David Miller
  Cc: Eric Dumazet, netdev, Francois Romieu, adi-buildroot-devel,
	Zhang, Sonic

Hi David,

On Tue, Jul 22, 2014 at 4:01 PM, David Miller <davem@davemloft.net> wrote:
> From: Eric Dumazet <eric.dumazet@gmail.com>
> Date: Tue, 22 Jul 2014 09:59:44 +0200
>
>> On Tue, 2014-07-22 at 15:38 +0800, Sonic Zhang wrote:
>>> From: Sonic Zhang <sonic.zhang@analog.com>
>>
>>> +    if (i < budget) {
>>> +            napi_complete(napi);
>>> +            if (lp->rx_irq_disabled--)
>>> +                    if (!lp->rx_irq_disabled)
>>> +                            enable_irq(IRQ_MAC_RX);
>>
>>
>> You wrote :
>>
>>       if (A--)
>>               if (!A)
>>                       something();
>>
>> Isnt a bit strange ???
>
> Indeed, it's very strange, how about:
>
>         if (!--lp->rx_irq_disabled)
>
> which is the canonical way to express this.

I made a mistake on the condition logic. Is following logic fine to you?

            if (lp->rx_irq_disabled > 0 && !--lp->rx_irq_disabled)
                            enable_irq(IRQ_MAC_RX);


Thanks,

Sonic Zhang

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v7] bfin_mac: convert bfin Ethernet driver to NAPI framework
  2014-07-22  7:38 [PATCH v7] bfin_mac: convert bfin Ethernet driver to NAPI framework Sonic Zhang
  2014-07-22  7:59 ` Eric Dumazet
@ 2014-07-22 22:16 ` Francois Romieu
  2014-07-24  8:28   ` Sonic Zhang
  1 sibling, 1 reply; 10+ messages in thread
From: Francois Romieu @ 2014-07-22 22:16 UTC (permalink / raw)
  To: Sonic Zhang
  Cc: David S. Miller, netdev, adi-buildroot-devel, Sonic Zhang,
	Eric Dumazet, David Laight

Sonic Zhang <sonic.adi@gmail.com> :
[...]
> diff --git a/drivers/net/ethernet/adi/bfin_mac.c b/drivers/net/ethernet/adi/bfin_mac.c
> index 7ae74d4..8924802 100644
> --- a/drivers/net/ethernet/adi/bfin_mac.c
> +++ b/drivers/net/ethernet/adi/bfin_mac.c
[...]
> @@ -1302,41 +1303,53 @@ out:
>  	current_rx_ptr = current_rx_ptr->next;
>  }
>  
> +static int bfin_mac_poll(struct napi_struct *napi, int budget)
> +{
> +	int i = 0;
> +	struct bfin_mac_local *lp = container_of(napi,
> +						 struct bfin_mac_local,
> +						 napi);
> +
> +	while (current_rx_ptr->status.status_word != 0 && i < budget) {
> +		bfin_mac_rx(lp, budget);
> +		i++;
> +	}
> +
> +	if (i < budget) {
> +		napi_complete(napi);
> +		if (lp->rx_irq_disabled--)
> +			if (!lp->rx_irq_disabled)
> +				enable_irq(IRQ_MAC_RX);
> +	}
[...]
>  static irqreturn_t bfin_mac_interrupt(int irq, void *dev_id)
>  {
> +	struct bfin_mac_local *lp = netdev_priv(dev_id);
> +	u32 status;
> +
> +	status = bfin_read_DMA1_IRQ_STATUS();
> +
> +	bfin_write_DMA1_IRQ_STATUS(status | DMA_DONE | DMA_ERR);
> +	if ((status & DMA_DONE) && napi_schedule_prep(&lp->napi)) {
> +		if (!lp->rx_irq_disabled++)
> +			disable_irq_nosync(IRQ_MAC_RX);
> +		__napi_schedule(&lp->napi);

If netpoll scavenges between napi_schedule_prep and lp->rx_irq_disabled++
on a different CPU, bfin_mac_interrupt may later __napi_schedule while
already napi_completed in netpoll...bfin_mac_poll(): bfin_mac_poll won't
be run in net_rx_action and IRQ_MAC_RX will stay disabled.

I don't know if something on the blackfin arch prevents the window to
widen and makes it moot.

As the bfin_mac driver requests the single non shared IRQ_MAC_RX irq,
couldn't we instead:

static irqreturn_t bfin_mac_interrupt(int irq, void *dev_id)
[...]
	if (status & DMA_DONE) {
		disable_irq_nosync(IRQ_MAC_RX);
		/* Code won't return here until a scheduled poll enables irq. */
		set_bit(BFIN_IRQ_DISABLED, &lp->flags);
		napi_schedule(&lp->napi);
	}

static int bfin_mac_poll(struct napi_struct *napi, int budget)
[...]
	if (i < budget) {
		napi_complete(napi);
		if (test_and_clear_bit(BFIN_IRQ_DISABLED, &lp->flags))
			enable_irq(IRQ_MAC_RX);
	}

Comments ?

-- 
Ueimor

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v7] bfin_mac: convert bfin Ethernet driver to NAPI framework
  2014-07-22 22:16 ` Francois Romieu
@ 2014-07-24  8:28   ` Sonic Zhang
  0 siblings, 0 replies; 10+ messages in thread
From: Sonic Zhang @ 2014-07-24  8:28 UTC (permalink / raw)
  To: Francois Romieu
  Cc: David S. Miller, netdev, adi-buildroot-devel, Sonic Zhang,
	Eric Dumazet, David Laight

Hi Francois,

On Wed, Jul 23, 2014 at 6:16 AM, Francois Romieu <romieu@fr.zoreil.com> wrote:
> Sonic Zhang <sonic.adi@gmail.com> :
> [...]
>> diff --git a/drivers/net/ethernet/adi/bfin_mac.c b/drivers/net/ethernet/adi/bfin_mac.c
>> index 7ae74d4..8924802 100644
>> --- a/drivers/net/ethernet/adi/bfin_mac.c
>> +++ b/drivers/net/ethernet/adi/bfin_mac.c
> [...]
>> @@ -1302,41 +1303,53 @@ out:
>>       current_rx_ptr = current_rx_ptr->next;
>>  }
>>
>> +static int bfin_mac_poll(struct napi_struct *napi, int budget)
>> +{
>> +     int i = 0;
>> +     struct bfin_mac_local *lp = container_of(napi,
>> +                                              struct bfin_mac_local,
>> +                                              napi);
>> +
>> +     while (current_rx_ptr->status.status_word != 0 && i < budget) {
>> +             bfin_mac_rx(lp, budget);
>> +             i++;
>> +     }
>> +
>> +     if (i < budget) {
>> +             napi_complete(napi);
>> +             if (lp->rx_irq_disabled--)
>> +                     if (!lp->rx_irq_disabled)
>> +                             enable_irq(IRQ_MAC_RX);
>> +     }
> [...]
>>  static irqreturn_t bfin_mac_interrupt(int irq, void *dev_id)
>>  {
>> +     struct bfin_mac_local *lp = netdev_priv(dev_id);
>> +     u32 status;
>> +
>> +     status = bfin_read_DMA1_IRQ_STATUS();
>> +
>> +     bfin_write_DMA1_IRQ_STATUS(status | DMA_DONE | DMA_ERR);
>> +     if ((status & DMA_DONE) && napi_schedule_prep(&lp->napi)) {
>> +             if (!lp->rx_irq_disabled++)
>> +                     disable_irq_nosync(IRQ_MAC_RX);
>> +             __napi_schedule(&lp->napi);
>
> If netpoll scavenges between napi_schedule_prep and lp->rx_irq_disabled++
> on a different CPU, bfin_mac_interrupt may later __napi_schedule while
> already napi_completed in netpoll...bfin_mac_poll(): bfin_mac_poll won't
> be run in net_rx_action and IRQ_MAC_RX will stay disabled.
>
> I don't know if something on the blackfin arch prevents the window to
> widen and makes it moot.
>
> As the bfin_mac driver requests the single non shared IRQ_MAC_RX irq,
> couldn't we instead:
>
> static irqreturn_t bfin_mac_interrupt(int irq, void *dev_id)
> [...]
>         if (status & DMA_DONE) {
>                 disable_irq_nosync(IRQ_MAC_RX);
>                 /* Code won't return here until a scheduled poll enables irq. */
>                 set_bit(BFIN_IRQ_DISABLED, &lp->flags);
>                 napi_schedule(&lp->napi);
>         }
>
> static int bfin_mac_poll(struct napi_struct *napi, int budget)
> [...]
>         if (i < budget) {
>                 napi_complete(napi);
>                 if (test_and_clear_bit(BFIN_IRQ_DISABLED, &lp->flags))
>                         enable_irq(IRQ_MAC_RX);
>         }
>
> Comments ?

Yes, you suggestion can make sure both the balanced operations of the
MAC RX IRQ and the NAPI poll is always called with MAC RX IRQ
disabled. I just tested your suggestion on Blackfin with and without
netpoll loop. Both work well.

Thanks,

Sonic Zhang

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2014-07-24  8:36 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-07-22  7:38 [PATCH v7] bfin_mac: convert bfin Ethernet driver to NAPI framework Sonic Zhang
2014-07-22  7:59 ` Eric Dumazet
2014-07-22  8:01   ` David Miller
2014-07-22  8:53     ` Sonic Zhang
2014-07-22  9:10       ` David Laight
2014-07-22  9:51       ` Eric Dumazet
2014-07-22 10:10         ` Sonic Zhang
2014-07-22 10:12     ` Sonic Zhang
2014-07-22 22:16 ` Francois Romieu
2014-07-24  8:28   ` Sonic Zhang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox