netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Florian Fainelli <f.fainelli@gmail.com>
To: Andrew Lunn <andrew@lunn.ch>
Cc: netdev@vger.kernel.org, linville@tuxdriver.com,
	davem@davemloft.net, vivien.didelot@savoirfairelinux.com
Subject: Re: [PATCH net-next 6/7] net: systemport: Add support for WAKE_FILTER
Date: Tue, 17 Jul 2018 09:26:04 -0700	[thread overview]
Message-ID: <87910e9c-0783-98e9-eb44-ce85656912d8@gmail.com> (raw)
In-Reply-To: <20180717161459.GG968@lunn.ch>



On 07/17/2018 09:14 AM, Andrew Lunn wrote:
> On Tue, Jul 17, 2018 at 08:36:44AM -0700, Florian Fainelli wrote:
>> The SYSTEMPORT MAC allows up to 8 filters to be programmed to wake-up
>> from LAN. Verify that we have up to 8 filters and program them to the
>> appropriate RXCHK entries to be matched (along with their masks).
>>
>> We need to update the entry and exit to Wake-on-LAN mode to keep the
>> RXCHK engine running to match during suspend, but this is otherwise
>> fairly similar to Magic Packet detection.
>>
>> Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
>> ---
>>  drivers/net/ethernet/broadcom/bcmsysport.c | 111 +++++++++++++++++++++++++----
>>  drivers/net/ethernet/broadcom/bcmsysport.h |  14 +++-
>>  2 files changed, 109 insertions(+), 16 deletions(-)
>>
>> diff --git a/drivers/net/ethernet/broadcom/bcmsysport.c b/drivers/net/ethernet/broadcom/bcmsysport.c
>> index 511caec7030a..8d7ce3df1080 100644
>> --- a/drivers/net/ethernet/broadcom/bcmsysport.c
>> +++ b/drivers/net/ethernet/broadcom/bcmsysport.c
>> @@ -521,25 +521,31 @@ static void bcm_sysport_get_wol(struct net_device *dev,
>>  	struct bcm_sysport_priv *priv = netdev_priv(dev);
>>  	u32 reg;
>>  
>> -	wol->supported = WAKE_MAGIC | WAKE_MAGICSECURE;
>> +	wol->supported = WAKE_MAGIC | WAKE_MAGICSECURE | WAKE_FILTER;
>>  	wol->wolopts = priv->wolopts;
>>  
>> -	if (!(priv->wolopts & WAKE_MAGICSECURE))
>> -		return;
>> +	if (priv->wolopts & WAKE_MAGICSECURE) {
>> +		/* Return the programmed SecureOn password */
>> +		reg = umac_readl(priv, UMAC_PSW_MS);
>> +		put_unaligned_be16(reg, &wol->sopass[0]);
>> +		reg = umac_readl(priv, UMAC_PSW_LS);
>> +		put_unaligned_be32(reg, &wol->sopass[2]);
>> +	}
>>  
>> -	/* Return the programmed SecureOn password */
>> -	reg = umac_readl(priv, UMAC_PSW_MS);
>> -	put_unaligned_be16(reg, &wol->sopass[0]);
>> -	reg = umac_readl(priv, UMAC_PSW_LS);
>> -	put_unaligned_be32(reg, &wol->sopass[2]);
>> +	if (priv->wolopts & WAKE_FILTER)
>> +		bitmap_copy((unsigned long *)wol->sopass, priv->filters,
>> +			    WAKE_FILTER_BITS);
>>  }
>>  
>> +
>>  static int bcm_sysport_set_wol(struct net_device *dev,
> 
> Two blank lines...
> 
> 
> 
>>  			       struct ethtool_wolinfo *wol)
>>  {
>>  	struct bcm_sysport_priv *priv = netdev_priv(dev);
>>  	struct device *kdev = &priv->pdev->dev;
>> -	u32 supported = WAKE_MAGIC | WAKE_MAGICSECURE;
>> +	u32 supported = WAKE_MAGIC | WAKE_MAGICSECURE | WAKE_FILTER;
>> +	unsigned int index, i = 0;
>> +	u32 reg;
>>  
>>  	if (!device_can_wakeup(kdev))
>>  		return -ENOTSUPP;
>> @@ -555,6 +561,32 @@ static int bcm_sysport_set_wol(struct net_device *dev,
>>  			    UMAC_PSW_LS);
>>  	}
>>  
>> +	/* We support matching up to 8 filters only */
>> +	if (wol->wolopts & WAKE_FILTER) {
>> +		bitmap_copy(priv->filters, (unsigned long *)wol->sopass,
>> +			    WAKE_FILTER_BITS);
> 
> Shouldn't this be done after to the two checks for errors? Otherwise
> you have unexpected side effects.

How would you use the bitmap_* routines if you don't copy the bitmap
first? Besides, if the bitmap is too wide (next check), we zero it out,
so nothing will get programmed if we attempt a Wake-on-LAN suspend (and
priv->wolopts is not copied anyway) and the second check would reject a
zero bitmap as well.

> 
>> +
>> +		if (bitmap_weight(priv->filters, WAKE_FILTER_BITS) >
>> +				  RXCHK_BRCM_TAG_MAX) {
>> +			bitmap_zero(priv->filters, WAKE_FILTER_BITS);
>> +			return -ENOSPC;
>> +		}
>> +
>> +		if (bitmap_weight(priv->filters, WAKE_FILTER_BITS) == 0)
>> +			return -EINVAL;
>> +
>> +		for_each_set_bit(index, priv->filters, WAKE_FILTER_BITS) {
>> +			/* Write the index we want to match within the CID field */
>> +			reg = rxchk_readl(priv, RXCHK_BRCM_TAG(i));
>> +			reg &= ~(RXCHK_BRCM_TAG_CID_MASK <<
>> +				 RXCHK_BRCM_TAG_CID_SHIFT);
>> +			reg |= index << RXCHK_BRCM_TAG_CID_SHIFT;
>> +			rxchk_writel(priv, reg, RXCHK_BRCM_TAG(i));
>> +			rxchk_writel(priv, 0xff00ffff, RXCHK_BRCM_TAG_MASK(i));
>> +			i++;
>> +		}
>> +	}
> 
> How do you disable filters? It looks like you cannot pass all bits set
> to 0. Also, how do you disable a specific filter? The code above seems
> to be additive only. There does not appear to be a first write which
> disables all existing filters before writing the new set of filters.

Either you disable WoL entirely (ethtool -s gphy wol d) and then we
don't put the hardware in a state that allows it to wake-up the system,
or you re-program a different set of filters by re-sending a new bitmask
of desired filters. This is not different from how you program/unprogram
MagicPacket with SecureOn password.
-- 
Florian

  reply	other threads:[~2018-07-17 16:59 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-17 15:36 [PATCH net-next 0/7] net: Support Wake-on-LAN using filters Florian Fainelli
2018-07-17 15:36 ` [PATCH ethtool] ethtool: Add support for WAKE_FILTER Florian Fainelli
2018-07-30 22:26   ` Florian Fainelli
2018-07-30 22:30     ` Andrew Lunn
2018-07-30 22:39       ` Florian Fainelli
2018-07-30 22:55         ` Andrew Lunn
2018-07-30 23:01     ` Andrew Lunn
2018-08-01 16:32     ` David Miller
2018-08-03 17:57       ` Florian Fainelli
2018-08-03 19:07         ` David Miller
2018-08-03 19:58           ` Florian Fainelli
2018-08-03 20:18             ` David Miller
2018-07-17 15:36 ` [PATCH net-next 1/7] net: dsa: bcm_sf2: Allow targeting CPU ports for CFP rules Florian Fainelli
2018-07-18  0:56   ` David Miller
2018-07-17 15:36 ` [PATCH net-next 2/7] net: dsa: bcm_sf2: Disable learning while in WoL Florian Fainelli
2018-07-17 15:54   ` Andrew Lunn
2018-07-17 16:06     ` Florian Fainelli
2018-07-17 15:36 ` [PATCH net-next 3/7] net: systemport: Do not re-configure upon WoL interrupt Florian Fainelli
2018-07-17 15:36 ` [PATCH net-next 4/7] net: systemport: Create helper to set MPD Florian Fainelli
2018-07-17 15:36 ` [PATCH net-next 5/7] ethtool: Add WAKE_FILTER bitmask Florian Fainelli
2018-07-17 15:36 ` [PATCH net-next 6/7] net: systemport: Add support for WAKE_FILTER Florian Fainelli
2018-07-17 16:14   ` Andrew Lunn
2018-07-17 16:26     ` Florian Fainelli [this message]
2018-07-17 16:49       ` Andrew Lunn
2018-07-17 16:57         ` Florian Fainelli
2018-07-17 17:06           ` Andrew Lunn
2018-07-18  9:15             ` Florian Fainelli
2018-07-19 22:25               ` Andrew Lunn
2018-07-20  9:34                 ` Florian Fainelli
2018-07-17 15:36 ` [PATCH net-next 7/7] net: dsa: bcm_sf2: Support WAKE_FILTER Florian Fainelli
2018-07-17 15:47 ` [PATCH net-next 0/7] net: Support Wake-on-LAN using filters Andrew Lunn
2018-07-17 16:06   ` Florian Fainelli
2018-07-17 16:21     ` Andrew Lunn
2018-07-17 16:28       ` Florian Fainelli
2018-07-17 16:51         ` Andrew Lunn

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=87910e9c-0783-98e9-eb44-ce85656912d8@gmail.com \
    --to=f.fainelli@gmail.com \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=linville@tuxdriver.com \
    --cc=netdev@vger.kernel.org \
    --cc=vivien.didelot@savoirfairelinux.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).