All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andy.shevchenko@gmail.com>
To: Joseph CHAMG <josright123@gmail.com>
Cc: "David S . Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>,
	Rob Herring <robh+dt@kernel.org>,
	joseph_chang@davicom.com.tw, netdev <netdev@vger.kernel.org>,
	devicetree <devicetree@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Andrew Lunn <andrew@lunn.ch>, Leon Romanovsky <leon@kernel.org>
Subject: Re: [PATCH v10, 2/2] net: Add dm9051 driver
Date: Wed, 5 Jan 2022 14:31:02 +0200	[thread overview]
Message-ID: <CAHp75VfvfokzL2anenFKGyLE68RJfJ7ktSGhh3q7rsi5woLaxg@mail.gmail.com> (raw)
In-Reply-To: <20220105081728.4289-3-josright123@gmail.com>

On Wed, Jan 5, 2022 at 10:18 AM Joseph CHAMG <josright123@gmail.com> wrote:

Missed commit message.

> v1-v4
>
> Add davicom dm9051 spi ethernet driver. The driver work for the
> device platform with spi master
>
> Test ok with raspberry pi 2 and pi 4, the spi configure used in
> my raspberry pi 4 is spi0.1, spi speed 31200000, and INT by pin 26.
>
> v5
>
> Work to eliminate the wrappers to be clear for read, swapped to
> phylib for phy connection tasks.
>
> Tested with raspberry pi 4. Test for netwroking function, CAT5
> cable unplug/plug and also ethtool detect for link state, and
> all are ok.
>
> v6
>
> remove the redundant code that phylib has support,
> adjust to be the reasonable sequence,
> fine tune comments, add comments for pause function support
>
> Tested with raspberry pi 4. Test for netwroking function, CAT5
> cable unplug/plug and also ethtool detect for link state, and
> all are ok.
>
> v7
>
> read/write registers must return error code to the callet,
> add to enable pause processing
>
> v8
>
> not parmanently set MAC by .ndo_set_mac_address
>
> correct rx function such as clear ISR,
> inblk avoid stack buffer,
> simple skb buffer process and
> easy use netif_rx_ni.
>
> simplely queue init and wake the queues,
> limit the start_xmit function use netif_stop_queue.
>
> descript that schedule delay is essential
> for tx_work and rxctrl_work
>
> eliminate ____cacheline_aligned and
> add static int msg_enable.
>
> v9
>
> use phylib, no need 'select MII' in Kconfig,
> make it clear in dm9051_xfer when using spi_sync,
> improve the registers read/write so that error code
> return as far as possible up the call stack.
>
> v10
>
> use regmap APIs for SPI and MDIO,
> modify to correcting such as include header files
> and program check styles

Changelog should go after the cutter '--- ' line below...

> Cc: Jakub Kicinski <kuba@kernel.org>
> Cc: Andrew Lunn <andrew@lunn.ch>
> Cc: Leon Romanovsky <leon@kernel.org>
> Cc: andy Shevchenko <andy.shevchenko@gmail.com>
> Signed-off-by: Joseph CHAMG <josright123@gmail.com>
> ---

...somewhere here.

...

> +#include <linux/etherdevice.h>
> +#include <linux/ethtool.h>
> +#include <linux/interrupt.h>
> +#include <linux/iopoll.h>
> +#include <linux/mii.h>
> +#include <linux/module.h>
> +#include <linux/netdevice.h>
> +#include <linux/phy.h>
> +#include <linux/regmap.h>
> +#include <linux/skbuff.h>
> +#include <linux/spinlock.h>
> +#include <linux/spi/spi.h>

...

> +/* spi master low level code */
> +static int hw_dm9051_spi_write(void *context, u8 reg, const u8 *data, size_t count)

> +static int hw_dm9051_spi_read(void *context, u8 reg, u8 *data, size_t count)

> +static int regmap_dm9051_reg_write(void *context, const void *data, size_t len)

> +static int regmap_dm9051_reg_read(void *context, const void *reg_buf, size_t reg_size,
> +                                 void *val, size_t val_size)

> +static int regmap_dm9051_reg_update_bits(void *context, unsigned int reg,
> +                                        unsigned int mask,
> +                                        unsigned int val)

All these are implemented by regmap SPI API. Why don't you use it?

...

> +static bool dm9051_regmap_readable(struct device *dev, unsigned int reg)
> +{
> +       return true;
> +}
> +
> +static bool dm9051_regmap_writeable(struct device *dev, unsigned int reg)
> +{
> +       return true;
> +}
> +
> +static bool dm9051_regmap_volatile(struct device *dev, unsigned int reg)
> +{
> +       return true; /* optional false */
> +}
> +
> +static bool dm9051_regmap_precious(struct device *dev, unsigned int reg)
> +{
> +       return true; /* optional false */
> +}

These stubs are redundant.

...

> +static void regmap_lock_mutex(void *context)
> +{
> +       struct board_info *db = context;
> +
> +       mutex_lock(&db->regmap_mutex);
> +}
> +
> +static void regmap_unlock_mutex(void *context)
> +{
> +       struct board_info *db = context;
> +
> +       mutex_unlock(&db->regmap_mutex);
> +}

Why do you need this? Either you use lock provided by regmap, or you
disable locking for regmap and provide your own locking scheme (should
be justified in the commit message).

...

> +static struct regmap_config regconfig = {

> +       .name = "reg",

Do you need this?

> +       .reg_bits = 8,
> +       .val_bits = 8,
> +       .max_register = 0xff,
> +       .reg_stride = 1,
> +       .cache_type = REGCACHE_RBTREE,
> +       .val_format_endian = REGMAP_ENDIAN_LITTLE,

> +};

...

> +static int dm9051_map_poll(struct board_info *db)
> +{
> +       unsigned int mval;
> +       int ret;
> +
> +       ret = read_poll_timeout(regmap_read, ret, !ret || !(mval & EPCR_ERRE),
> +                               100, 10000, true, db->regmap, DM9051_EPCR, &mval);
> +       if (ret)
> +               netdev_err(db->ndev, "timeout in processing for phy/eeprom accessing\n");
> +       return ret;
> +}

regmap has a corresponding API, i.e. regmap_read_poll_timeout().

...

> +static int regmap_dm9051_phy_reg_write(void *context, unsigned int reg, unsigned int val)
> +{
> +       struct board_info *db = context;
> +       int ret;
> +
> +       regmap_write(db->regmap, DM9051_EPAR, DM9051_PHY | reg);

> +       regmap_write(db->regmap, DM9051_EPDRL, val & 0xff);
> +       regmap_write(db->regmap, DM9051_EPDRH, (val >> 8) && 0xff);

Shouldn't be this a bulk write?
Ditto for all other cases where you need to write 16-bit values in
sequential addresses.

> +       regmap_write(db->regmap, DM9051_EPCR, EPCR_EPOS | EPCR_ERPRW);
> +       ret = dm9051_map_poll(db);
> +       regmap_write(db->regmap, DM9051_EPCR, 0x0);
> +
> +       if (reg == MII_BMCR && !(val & 0x0800))
> +               mdelay(1); /* need for if activate phyxcer */
> +
> +       return ret;
> +}

...

> +static int devm_regmap_init_dm9051(struct device *dev, struct board_info *db)
> +{
> +       mutex_init(&db->regmap_mutex);
> +
> +       regconfig.lock_arg = db;
> +
> +       db->regmap = devm_regmap_init(dev, &regmap_spi, db, &regconfig);
> +       if (IS_ERR(db->regmap))
> +               return PTR_ERR(db->regmap);
> +       db->phymap = devm_regmap_init(dev, &phymap_mdio, db, &phyconfig);
> +       if (IS_ERR(db->phymap))
> +               return PTR_ERR(db->phymap);

Use corresponding regmap APIs, i.e. MDIO, SPI, etc.

> +       return 0;
> +}

...

> +{
> +       int ret;
> +       u8 rxb[1];
> +
> +       while (len--) {
> +               ret = hw_dm9051_spi_read(db, DM_SPI_MRCMD, rxb, 1);
> +               if (ret < 0)
> +                       return ret;
> +       }
> +       return ret;
> +}

I believe the regmap API provides this kind of read (bulk with no
increment addresses or so).

I stopped here, because it's enough for now. Just take your time to
see how other (recent) drivers are implemented.

-- 
With Best Regards,
Andy Shevchenko

  reply	other threads:[~2022-01-05 12:32 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-05  8:17 [PATCH v10, 0/2] ADD DM9051 ETHERNET DRIVER Joseph CHAMG
2022-01-05  8:17 ` [PATCH v10, 1/2] yaml: Add dm9051 SPI network yaml file Joseph CHAMG
2022-01-05  8:17 ` [PATCH v10, 2/2] net: Add dm9051 driver Joseph CHAMG
2022-01-05 12:31   ` Andy Shevchenko [this message]
2022-01-05 16:54   ` Andrew Lunn
2022-01-05 23:38   ` kernel test robot
2022-01-05 23:38     ` kernel test robot

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=CAHp75VfvfokzL2anenFKGyLE68RJfJ7ktSGhh3q7rsi5woLaxg@mail.gmail.com \
    --to=andy.shevchenko@gmail.com \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=devicetree@vger.kernel.org \
    --cc=joseph_chang@davicom.com.tw \
    --cc=josright123@gmail.com \
    --cc=kuba@kernel.org \
    --cc=leon@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --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.