From: Oleksij Rempel <o.rempel@pengutronix.de>
To: Arun.Ramadoss@microchip.com
Cc: olteanv@gmail.com, UNGLinuxDriver@microchip.com,
vivien.didelot@gmail.com, andrew@lunn.ch, f.fainelli@gmail.com,
kuba@kernel.org, edumazet@google.com, pabeni@redhat.com,
Woojung.Huh@microchip.com, davem@davemloft.net,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
kernel@pengutronix.de
Subject: Re: [PATCH v1 21/26] net: dsa: microchip: ksz8_r_sta_mac_table(): do not use error code for empty entries
Date: Tue, 29 Nov 2022 06:56:15 +0100 [thread overview]
Message-ID: <20221129055615.GB25526@pengutronix.de> (raw)
In-Reply-To: <90add896bd48f5ba80385df4d8a4e27c91f97e7d.camel@microchip.com>
On Tue, Nov 29, 2022 at 05:25:55AM +0000, Arun.Ramadoss@microchip.com wrote:
> On Mon, 2022-11-28 at 12:59 +0100, Oleksij Rempel wrote:
> > EXTERNAL EMAIL: Do not click links or open attachments unless you
> > know the content is safe
> >
> > This is a preparation for the next patch, to make use of read/write
> > errors.
> >
> > Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
> > ---
> > drivers/net/dsa/microchip/ksz8795.c | 94 +++++++++++++++++--------
> > ----
> > 1 file changed, 54 insertions(+), 40 deletions(-)
> >
> > diff --git a/drivers/net/dsa/microchip/ksz8795.c
> > b/drivers/net/dsa/microchip/ksz8795.c
> > index 1c08103c9f50..b7487be91f67 100644
> > --- a/drivers/net/dsa/microchip/ksz8795.c
> > +++ b/drivers/net/dsa/microchip/ksz8795.c
> > @@ -457,7 +457,7 @@ static int ksz8_r_dyn_mac_table(struct ksz_device
> > *dev, u16 addr, u8 *mac_addr,
> > }
> >
> > static int ksz8_r_sta_mac_table(struct ksz_device *dev, u16 addr,
> > - struct alu_struct *alu)
> > + struct alu_struct *alu, bool *valid)
> > {
> > u32 data_hi, data_lo;
> > const u8 *shifts;
> > @@ -470,28 +470,32 @@ static int ksz8_r_sta_mac_table(struct
> > ksz_device *dev, u16 addr,
> > ksz8_r_table(dev, TABLE_STATIC_MAC, addr, &data);
> > data_hi = data >> 32;
> > data_lo = (u32)data;
> > - if (data_hi & (masks[STATIC_MAC_TABLE_VALID] |
> > - masks[STATIC_MAC_TABLE_OVERRIDE])) {
> > - alu->mac[5] = (u8)data_lo;
> > - alu->mac[4] = (u8)(data_lo >> 8);
> > - alu->mac[3] = (u8)(data_lo >> 16);
> > - alu->mac[2] = (u8)(data_lo >> 24);
> > - alu->mac[1] = (u8)data_hi;
> > - alu->mac[0] = (u8)(data_hi >> 8);
> > - alu->port_forward =
> > - (data_hi & masks[STATIC_MAC_TABLE_FWD_PORTS])
> > >>
> > - shifts[STATIC_MAC_FWD_PORTS];
> > - alu->is_override =
> > - (data_hi & masks[STATIC_MAC_TABLE_OVERRIDE])
> > ? 1 : 0;
> > - data_hi >>= 1;
> > - alu->is_static = true;
> > - alu->is_use_fid =
> > - (data_hi & masks[STATIC_MAC_TABLE_USE_FID]) ?
> > 1 : 0;
> > - alu->fid = (data_hi & masks[STATIC_MAC_TABLE_FID]) >>
> > - shifts[STATIC_MAC_FID];
> > +
> > + if (!(data_hi & (masks[STATIC_MAC_TABLE_VALID] |
> > + masks[STATIC_MAC_TABLE_OVERRIDE]))) {
> > + *valid = false;
> > return 0;
> > }
> > - return -ENXIO;
> > +
> > + alu->mac[5] = (u8)data_lo;
> > + alu->mac[4] = (u8)(data_lo >> 8);
> > + alu->mac[3] = (u8)(data_lo >> 16);
> > + alu->mac[2] = (u8)(data_lo >> 24);
> > + alu->mac[1] = (u8)data_hi;
> > + alu->mac[0] = (u8)(data_hi >> 8);
>
> u64_to_ether_addr macro can be used to store address into array.
This should not be done in this patch.
> > + alu->port_forward =
> > + (data_hi & masks[STATIC_MAC_TABLE_FWD_PORTS]) >>
> > + shifts[STATIC_MAC_FWD_PORTS];
>
>
>
> > + alu->is_override = (data_hi &
> > masks[STATIC_MAC_TABLE_OVERRIDE]) ? 1 : 0;
> > + data_hi >>= 1;
> > + alu->is_static = true;
> > + alu->is_use_fid = (data_hi & masks[STATIC_MAC_TABLE_USE_FID])
> > ? 1 : 0;
> > + alu->fid = (data_hi & masks[STATIC_MAC_TABLE_FID]) >>
> > + shifts[STATIC_MAC_FID];
>
> Instead of masks and shifts, you consider using
> FIELD_GET(STATIC_MAC_TABLE_FID, data_hi);
I would love to do this, but in this case, complete driver should be
splittet in to KSZ88X3 and KSZ879X portions. FIELD_GET can't work with
dynamic masks and shifts.
I would say, it is not for this patch set.
> > +
> > + *valid = true;
> > +
> > + return 0;
> > }
> >
> > void ksz8_w_sta_mac_table(struct ksz_device *dev, u16 addr,
> > @@ -969,12 +973,13 @@ int ksz8_fdb_dump(struct ksz_device *dev, int
> > port,
> >
> > for (i = 0; i < dev->info->num_statics; i++) {
> > struct alu_struct alu;
> > + bool valid;
> >
> > - ret = ksz8_r_sta_mac_table(dev, i, &alu);
> > - if (ret == -ENXIO)
> > - continue;
> > + ret = ksz8_r_sta_mac_table(dev, i, &alu, &valid);
> > if (ret)
> > return ret;
> > + if (!valid)
> > + continue;
> >
> > if (!(alu.port_forward & BIT(port)))
> > continue;
> > @@ -1010,20 +1015,25 @@ static int ksz8_add_sta_mac(struct ksz_device
> > *dev, int port,
> > const unsigned char *addr, u16 vid)
> > {
> > struct alu_struct alu;
> > - int index;
> > + int index, ret;
> > int empty = 0;
> >
> > alu.port_forward = 0;
> > for (index = 0; index < dev->info->num_statics; index++) {
> > - if (!ksz8_r_sta_mac_table(dev, index, &alu)) {
> > - /* Found one already in static MAC table. */
> > - if (!memcmp(alu.mac, addr, ETH_ALEN) &&
> > - alu.fid == vid)
> > - break;
> > - /* Remember the first empty entry. */
> > - } else if (!empty) {
> > - empty = index + 1;
> > + bool valid;
> > +
> > + ret = ksz8_r_sta_mac_table(dev, index, &alu, &valid);
> > + if (ret)
> > + return ret;
> > + if (!valid) {
> > + /* Remember the first empty entry. */
> > + if (!empty)
> > + empty = index + 1;
> > + continue;
> > }
> > +
> > + if (!memcmp(alu.mac, addr, ETH_ALEN) && alu.fid ==
> > vid)
> > + break;
> > }
> >
> > /* no available entry */
> > @@ -1053,15 +1063,19 @@ static int ksz8_del_sta_mac(struct ksz_device
> > *dev, int port,
> > const unsigned char *addr, u16 vid)
> > {
> > struct alu_struct alu;
> > - int index;
> > + int index, ret;
>
> Variable declaration in separate line.
Is it a new coding style requirement? I can't find it here:
https://www.kernel.org/doc/html/v6.0/process/coding-style.html
> >
> > for (index = 0; index < dev->info->num_statics; index++) {
> > - if (!ksz8_r_sta_mac_table(dev, index, &alu)) {
> > - /* Found one already in static MAC table. */
> > - if (!memcmp(alu.mac, addr, ETH_ALEN) &&
> > - alu.fid == vid)
> > - break;
> > - }
> > + bool valid;
> > +
> > + ret = ksz8_r_sta_mac_table(dev, index, &alu, &valid);
> > + if (ret)
> > + return ret;
> > + if (!valid)
> > + continue;
> > +
> > + if (!memcmp(alu.mac, addr, ETH_ALEN) && alu.fid ==
> > vid)
> > + break;
> > }
> >
> > /* no available entry */
> > --
> > 2.30.2
> >
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
next prev parent reply other threads:[~2022-11-29 5:56 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-28 11:59 [PATCH v1 00/26] net: dsa: microchip: stats64, fdb, error Oleksij Rempel
2022-11-28 11:59 ` [PATCH v1 01/26] net: dsa: microchip: add stats64 support for ksz8 series of switches Oleksij Rempel
2022-11-28 11:59 ` [PATCH v1 02/26] net: dsa: microchip: ksz8: ksz8_fdb_dump: fix port validation and VID information Oleksij Rempel
2022-11-28 11:59 ` [PATCH v1 03/26] net: dsa: microchip: ksz8: ksz8_fdb_dump: fix not complete fdb extraction Oleksij Rempel
2022-11-28 11:59 ` [PATCH v1 04/26] net: dsa: microchip: ksz8: ksz8_fdb_dump: fix time stamp extraction Oleksij Rempel
2022-11-28 11:59 ` [PATCH v1 05/26] net: dsa: microchip: ksz8: ksz8_fdb_dump: do not extract ghost entry from empty table Oleksij Rempel
2022-11-28 11:59 ` [PATCH v1 06/26] net: dsa: microchip: ksz8863_smi: fix bulk access Oleksij Rempel
2022-11-28 11:59 ` [PATCH v1 07/26] net: dsa: microchip: ksz8_r_dyn_mac_table(): remove timestamp support Oleksij Rempel
2022-11-29 7:16 ` Arun.Ramadoss
2022-11-28 11:59 ` [PATCH v1 08/26] net: dsa: microchip: make ksz8_r_dyn_mac_table() static Oleksij Rempel
2022-11-28 11:59 ` [PATCH v1 09/26] net: dsa: microchip: ksz8_r_dyn_mac_table(): remove fid support Oleksij Rempel
2022-11-28 11:59 ` [PATCH v1 10/26] net: dsa: microchip: ksz8: refactor ksz8_fdb_dump() Oleksij Rempel
2022-11-29 8:29 ` Arun.Ramadoss
2022-11-29 8:50 ` Oleksij Rempel
2022-11-28 11:59 ` [PATCH v1 11/26] net: dsa: microchip: ksz8: ksz8_fdb_dump: dump static MAC table Oleksij Rempel
2022-11-28 11:59 ` [PATCH v1 12/26] net: dsa: microchip: ksz8: move static mac table operations to a separate functions Oleksij Rempel
2022-11-28 11:59 ` [PATCH v1 13/26] net: dsa: microchip: ksz8: add fdb_add/del support Oleksij Rempel
2022-11-28 11:59 ` [PATCH v1 14/26] net: dsa: microchip: KSZ88x3 fix loopback support Oleksij Rempel
2022-11-29 6:42 ` Arun.Ramadoss
2022-11-28 11:59 ` [PATCH v1 15/26] net: dsa: microchip: ksz8_r_dyn_mac_table(): move main part of the code out of if statement Oleksij Rempel
2022-11-28 11:59 ` [PATCH v1 16/26] net: dsa: microchip: ksz8_r_dyn_mac_table(): use ret instead of rc Oleksij Rempel
2022-11-28 11:59 ` [PATCH v1 17/26] net: dsa: microchip: ksz8_r_dyn_mac_table(): ksz: do not return EAGAIN on timeout Oleksij Rempel
2022-11-28 11:59 ` [PATCH v1 18/26] net: dsa: microchip: ksz8_r_dyn_mac_table(): return read/write error if we got any Oleksij Rempel
2022-11-28 11:59 ` [PATCH v1 19/26] net: dsa: microchip: ksz8_r_dyn_mac_table(): use entries variable to signal 0 entries Oleksij Rempel
2022-11-28 11:59 ` [PATCH v1 20/26] net: dsa: microchip: make ksz8_r_sta_mac_table() static Oleksij Rempel
2022-11-29 5:08 ` Arun.Ramadoss
2022-11-28 11:59 ` [PATCH v1 21/26] net: dsa: microchip: ksz8_r_sta_mac_table(): do not use error code for empty entries Oleksij Rempel
2022-11-29 5:25 ` Arun.Ramadoss
2022-11-29 5:56 ` Oleksij Rempel [this message]
2022-11-28 11:59 ` [PATCH v1 22/26] net: dsa: microchip: ksz8_r_sta_mac_table(): make use of error values provided by read/write functions Oleksij Rempel
2022-11-28 11:59 ` [PATCH v1 23/26] net: dsa: microchip: make ksz8_w_sta_mac_table() static Oleksij Rempel
2022-11-28 11:59 ` [PATCH v1 24/26] net: dsa: microchip: ksz8_w_sta_mac_table(): make use of error values provided by read/write functions Oleksij Rempel
2022-11-28 11:59 ` [PATCH v1 25/26] net: dsa: microchip: remove ksz_port:on variable Oleksij Rempel
2022-11-28 11:59 ` [PATCH v1 26/26] net: dsa: microchip: ksz8: do not force flow control by default Oleksij Rempel
2022-11-28 13:51 ` [PATCH v1 00/26] net: dsa: microchip: stats64, fdb, error Andrew Lunn
2022-11-28 21:05 ` Jakub Kicinski
2022-11-28 23:09 ` Jacob Keller
2022-11-29 5:35 ` Oleksij Rempel
2022-11-29 14:15 ` Andrew Lunn
2022-11-30 5:34 ` Oleksij Rempel
-- strict thread matches above, loose matches on Subject: below --
2022-11-28 12:00 Oleksij Rempel
2022-11-28 12:00 ` [PATCH v1 21/26] net: dsa: microchip: ksz8_r_sta_mac_table(): do not use error code for empty entries Oleksij Rempel
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=20221129055615.GB25526@pengutronix.de \
--to=o.rempel@pengutronix.de \
--cc=Arun.Ramadoss@microchip.com \
--cc=UNGLinuxDriver@microchip.com \
--cc=Woojung.Huh@microchip.com \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=f.fainelli@gmail.com \
--cc=kernel@pengutronix.de \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=olteanv@gmail.com \
--cc=pabeni@redhat.com \
--cc=vivien.didelot@gmail.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).