All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lukasz Stelmach <l.stelmach@samsung.com>
To: Jakub Kicinski <kuba@kernel.org>
Cc: "David S. Miller" <davem@davemloft.net>,
	"Andrew Lunn" <andrew@lunn.ch>,
	jim.cromie@gmail.com, "Heiner Kallweit" <hkallweit1@gmail.com>,
	"Rob Herring" <robh+dt@kernel.org>,
	"Kukjin Kim" <kgene@kernel.org>,
	"Krzysztof Kozlowski" <krzk@kernel.org>,
	"Russell King" <linux@armlinux.org.uk>,
	netdev@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-samsung-soc@vger.kernel.org,
	"Bartłomiej Żolnierkiewicz" <b.zolnierkie@samsung.com>,
	"Marek Szyprowski" <m.szyprowski@samsung.com>
Subject: Re: [PATCH net-next v16 3/3] net: ax88796c: ASIX AX88796C SPI Ethernet Adapter Driver
Date: Wed, 13 Oct 2021 23:14:20 +0200	[thread overview]
Message-ID: <dleftj1r4osk43.fsf%l.stelmach@samsung.com> (raw)
In-Reply-To: <20211001153940.28c5d60d@kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com> (Jakub Kicinski's message of "Fri, 1 Oct 2021 15:39:40 -0700")

[-- Attachment #1: Type: text/plain, Size: 2482 bytes --]

It was <2021-10-01 pią 15:39>, when Jakub Kicinski wrote:
> On Wed, 29 Sep 2021 16:08:54 +0200 Łukasz Stelmach wrote:
>> +static char *no_regs_list = "80018001,e1918001,8001a001,fc0d0000";
>
> static const char ...
>
>> +static int
>> +ax88796c_close(struct net_device *ndev)
>> +{
>> +	struct ax88796c_device *ax_local = to_ax88796c_device(ndev);
>> +
>> +	netif_stop_queue(ndev);
>
> This can run concurrently with the work which restarts the queue.
> You should take the mutex and purge the queue here, so that there 
> is no chance queue will get restarted by the work right after.
>> +	phy_stop(ndev->phydev);
>> +
>> +	mutex_lock(&ax_local->spi_lock);

This was a bit tricky. The function now looks like this (details in the
comments). In theory there is a chance of dropping a packet if the
ax88796c_work() runs between phy_stop() and mutex_lock(), but I'd say
the overall risk is negligible.

--8<---------------cut here---------------start------------->8---
static int
ax88796c_close(struct net_device *ndev)
{
        struct ax88796c_device *ax_local = to_ax88796c_device(ndev);

        phy_stop(ndev->phydev);

        /* We lock the mutex early not only to protect the device
         * against concurrent access, but also avoid waking up the
         * queue in ax88796c_work(). phy_stop() needs to be called
         * before because it locks the mutex to access SPI.
         */
        mutex_lock(&ax_local->spi_lock);

        netif_stop_queue(ndev);

        /* No more work can be scheduled now. Make any pending work,
         * including one already waiting for the mutex to be unlocked,
         * NOP.
         */
        clear_bit(EVENT_SET_MULTI, &ax_local->flags);
        clear_bit(EVENT_INTR, &ax_local->flags);
        clear_bit(EVENT_TX, &ax_local->flags);

        /* Disable MAC interrupts */
        AX_WRITE(&ax_local->ax_spi, IMR_MASKALL, P0_IMR);
        __skb_queue_purge(&ax_local->tx_wait_q);
        ax88796c_soft_reset(ax_local);

        mutex_unlock(&ax_local->spi_lock);

        cancel_work_sync(&ax_local->ax_work);

        free_irq(ndev->irq, ndev);

        return 0;
}
--8<---------------cut here---------------end--------------->8---



>> +MODULE_AUTHOR("ASIX");
>
> You can drop this, author should be human.

I looked at diff --stat and decided it is OK to put my name there (-;
-- 
Łukasz Stelmach
Samsung R&D Institute Poland
Samsung Electronics

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 487 bytes --]

WARNING: multiple messages have this Message-ID (diff)
From: Lukasz Stelmach <l.stelmach@samsung.com>
To: Jakub Kicinski <kuba@kernel.org>
Cc: "David S. Miller" <davem@davemloft.net>,
	"Andrew Lunn" <andrew@lunn.ch>,
	jim.cromie@gmail.com, "Heiner Kallweit" <hkallweit1@gmail.com>,
	"Rob Herring" <robh+dt@kernel.org>,
	"Kukjin Kim" <kgene@kernel.org>,
	"Krzysztof Kozlowski" <krzk@kernel.org>,
	"Russell King" <linux@armlinux.org.uk>,
	netdev@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-samsung-soc@vger.kernel.org,
	"Bartłomiej Żolnierkiewicz" <b.zolnierkie@samsung.com>,
	"Marek Szyprowski" <m.szyprowski@samsung.com>
Subject: Re: [PATCH net-next v16 3/3] net: ax88796c: ASIX AX88796C SPI Ethernet Adapter Driver
Date: Wed, 13 Oct 2021 23:14:20 +0200	[thread overview]
Message-ID: <dleftj1r4osk43.fsf%l.stelmach@samsung.com> (raw)
In-Reply-To: <20211001153940.28c5d60d@kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com> (Jakub Kicinski's message of "Fri, 1 Oct 2021 15:39:40 -0700")


[-- Attachment #1.1: Type: text/plain, Size: 2482 bytes --]

It was <2021-10-01 pią 15:39>, when Jakub Kicinski wrote:
> On Wed, 29 Sep 2021 16:08:54 +0200 Łukasz Stelmach wrote:
>> +static char *no_regs_list = "80018001,e1918001,8001a001,fc0d0000";
>
> static const char ...
>
>> +static int
>> +ax88796c_close(struct net_device *ndev)
>> +{
>> +	struct ax88796c_device *ax_local = to_ax88796c_device(ndev);
>> +
>> +	netif_stop_queue(ndev);
>
> This can run concurrently with the work which restarts the queue.
> You should take the mutex and purge the queue here, so that there 
> is no chance queue will get restarted by the work right after.
>> +	phy_stop(ndev->phydev);
>> +
>> +	mutex_lock(&ax_local->spi_lock);

This was a bit tricky. The function now looks like this (details in the
comments). In theory there is a chance of dropping a packet if the
ax88796c_work() runs between phy_stop() and mutex_lock(), but I'd say
the overall risk is negligible.

--8<---------------cut here---------------start------------->8---
static int
ax88796c_close(struct net_device *ndev)
{
        struct ax88796c_device *ax_local = to_ax88796c_device(ndev);

        phy_stop(ndev->phydev);

        /* We lock the mutex early not only to protect the device
         * against concurrent access, but also avoid waking up the
         * queue in ax88796c_work(). phy_stop() needs to be called
         * before because it locks the mutex to access SPI.
         */
        mutex_lock(&ax_local->spi_lock);

        netif_stop_queue(ndev);

        /* No more work can be scheduled now. Make any pending work,
         * including one already waiting for the mutex to be unlocked,
         * NOP.
         */
        clear_bit(EVENT_SET_MULTI, &ax_local->flags);
        clear_bit(EVENT_INTR, &ax_local->flags);
        clear_bit(EVENT_TX, &ax_local->flags);

        /* Disable MAC interrupts */
        AX_WRITE(&ax_local->ax_spi, IMR_MASKALL, P0_IMR);
        __skb_queue_purge(&ax_local->tx_wait_q);
        ax88796c_soft_reset(ax_local);

        mutex_unlock(&ax_local->spi_lock);

        cancel_work_sync(&ax_local->ax_work);

        free_irq(ndev->irq, ndev);

        return 0;
}
--8<---------------cut here---------------end--------------->8---



>> +MODULE_AUTHOR("ASIX");
>
> You can drop this, author should be human.

I looked at diff --stat and decided it is OK to put my name there (-;
-- 
Łukasz Stelmach
Samsung R&D Institute Poland
Samsung Electronics

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 487 bytes --]

[-- Attachment #2: Type: text/plain, Size: 176 bytes --]

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  parent reply	other threads:[~2021-10-13 21:14 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20210929140912eucas1p2c3a4eac8b6fadd635aec3bbb44e8882e@eucas1p2.samsung.com>
2021-09-29 14:08 ` [PATCH net-next v16 0/3] AX88796C SPI Ethernet Adapter Łukasz Stelmach
2021-09-29 14:08   ` Łukasz Stelmach
     [not found]   ` <CGME20210929140912eucas1p2a4a14d3f865dcfad98a21235fbc500bc@eucas1p2.samsung.com>
2021-09-29 14:08     ` [PATCH net-next v16 1/3] dt-bindings: vendor-prefixes: Add asix prefix Łukasz Stelmach
2021-09-29 14:08       ` Łukasz Stelmach
     [not found]   ` <CGME20210929140913eucas1p19ae6de17520916149879be71a33291c7@eucas1p1.samsung.com>
2021-09-29 14:08     ` [PATCH net-next v16 2/3] dt-bindings: net: Add bindings for AX88796C SPI Ethernet Adapter Łukasz Stelmach
2021-09-29 14:08       ` Łukasz Stelmach
     [not found]   ` <CGME20210929140913eucas1p2e76ab9b78b12d456dc74ab7d54ea81ac@eucas1p2.samsung.com>
2021-09-29 14:08     ` [PATCH net-next v16 3/3] net: ax88796c: ASIX AX88796C SPI Ethernet Adapter Driver Łukasz Stelmach
2021-09-29 14:08       ` Łukasz Stelmach
2021-10-01 22:39       ` Jakub Kicinski
2021-10-01 22:39         ` Jakub Kicinski
     [not found]         ` <CGME20211013211432eucas1p2cb6a119feec2c1a2c067d2753d69509d@eucas1p2.samsung.com>
2021-10-13 21:14           ` Lukasz Stelmach [this message]
2021-10-13 21:14             ` Lukasz Stelmach

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=dleftj1r4osk43.fsf%l.stelmach@samsung.com \
    --to=l.stelmach@samsung.com \
    --cc=andrew@lunn.ch \
    --cc=b.zolnierkie@samsung.com \
    --cc=davem@davemloft.net \
    --cc=devicetree@vger.kernel.org \
    --cc=hkallweit1@gmail.com \
    --cc=jim.cromie@gmail.com \
    --cc=kgene@kernel.org \
    --cc=krzk@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-samsung-soc@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=m.szyprowski@samsung.com \
    --cc=netdev@vger.kernel.org \
    --cc=robh+dt@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.