From: Andrew Lunn <andrew@lunn.ch>
To: Guenter Roeck <linux@roeck-us.net>
Cc: netdev@vger.kernel.org, "David S. Miller" <davem@davemloft.net>,
Florian Fainelli <f.fainelli@gmail.com>,
Andrew Lunn <andrew@lunn.ch>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 09/15] net: dsa: Add support for switch EEPROM access
Date: Mon, 27 Oct 2014 03:41:21 +0100 [thread overview]
Message-ID: <20141027024121.GA16998@lunn.ch> (raw)
In-Reply-To: <1414342365-27191-10-git-send-email-linux@roeck-us.net>
On Sun, Oct 26, 2014 at 09:52:39AM -0700, Guenter Roeck wrote:
> On some chips it is possible to access the switch eeprom.
> Add infrastructure support for it.
>
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
> ---
> v2:
> - Add support for configuring switch EEPROM size through platform data
> or devicetree data
> - Do not compare new pointers against NULL
> - Check if get_eeprom pointer is set before calling it
>
> include/net/dsa.h | 10 ++++++++++
> net/dsa/dsa.c | 4 ++++
> net/dsa/slave.c | 41 +++++++++++++++++++++++++++++++++++++++++
> 3 files changed, 55 insertions(+)
>
> diff --git a/include/net/dsa.h b/include/net/dsa.h
> index 55e75e7..37856a2 100644
> --- a/include/net/dsa.h
> +++ b/include/net/dsa.h
> @@ -38,6 +38,9 @@ struct dsa_chip_data {
> struct device *host_dev;
> int sw_addr;
>
> + /* set to size of eeprom if supported by the switch */
> + int eeprom_len;
> +
> /* Device tree node pointer for this specific switch chip
> * used during switch setup in case additional properties
> * and resources needs to be used
> @@ -258,6 +261,13 @@ struct dsa_switch_driver {
> int (*set_temp_limit)(struct dsa_switch *ds, int temp);
> int (*get_temp_alarm)(struct dsa_switch *ds, bool *alarm);
> #endif
> +
> + /* EEPROM access */
> + int (*get_eeprom_len)(struct dsa_switch *ds);
> + int (*get_eeprom)(struct dsa_switch *ds,
> + struct ethtool_eeprom *eeprom, u8 *data);
> + int (*set_eeprom)(struct dsa_switch *ds,
> + struct ethtool_eeprom *eeprom, u8 *data);
> };
>
> void register_switch_driver(struct dsa_switch_driver *type);
> diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c
> index 5edbbca..1c1b925 100644
> --- a/net/dsa/dsa.c
> +++ b/net/dsa/dsa.c
> @@ -575,6 +575,7 @@ static int dsa_of_probe(struct platform_device *pdev)
> const char *port_name;
> int chip_index, port_index;
> const unsigned int *sw_addr, *port_reg;
> + u32 eeprom_length;
> int ret;
>
> mdio = of_parse_phandle(np, "dsa,mii-bus", 0);
> @@ -603,6 +604,9 @@ static int dsa_of_probe(struct platform_device *pdev)
> if (pd->nr_chips > DSA_MAX_SWITCHES)
> pd->nr_chips = DSA_MAX_SWITCHES;
>
> + if (!of_property_read_u32(np, "eeprom-length", &eeprom_length))
> + pd->eeprom_length = eeprom_length;
> +
Hi Guenter
I would of expected a property to indicate the eeprom is present, not
a length value. The switch determines the length, or at least the
minimum length. So the switch driver can return the length, if the
eeprom is indicated to be present.
Also, all device tree properties need to be documented. I've not
looked through all the patches, so maybe it is in a separate patch?
> +static int dsa_slave_get_eeprom_len(struct net_device *dev)
> +{
> + struct dsa_slave_priv *p = netdev_priv(dev);
> + struct dsa_switch *ds = p->parent;
> +
> + if (ds->pd->eeprom_len)
> + return ds->pd->eeprom_len;
> +
> + if (ds->drv->get_eeprom_len)
> + return ds->drv->get_eeprom_len(ds);
> +
> + return 0;
> +}
This also does not look right. The default is that there is no
property in DT, meaning the EEPROM is not present. So
ds->pd->eeprom_len is zero. So the first if is not taken. It then
calls into the driver which is return a length, independent of if it
is populated or not.
If we are going with your suggested binding, no value in DT, or a
value of 0 mean no EEPROM. If there is a value in DT
dsa_slave_get_eeprom_len() should return that value. Asking the driver
is redundant, you can remove the get_eeprom_len() call.
However, if DT just indicates the eeprom is populated or not, you
should call the driver get_eeprom_len() is the eeprom property is
present.
> +static int dsa_slave_get_eeprom(struct net_device *dev,
> + struct ethtool_eeprom *eeprom, u8 *data)
> +{
> + struct dsa_slave_priv *p = netdev_priv(dev);
> + struct dsa_switch *ds = p->parent;
> +
> + if (ds->drv->get_eeprom)
> + return ds->drv->get_eeprom(ds, eeprom, data);
This should be conditional on the length/present.
> +
> + return -EOPNOTSUPP;
> +}
> +
> +static int dsa_slave_set_eeprom(struct net_device *dev,
> + struct ethtool_eeprom *eeprom, u8 *data)
> +{
> + struct dsa_slave_priv *p = netdev_priv(dev);
> + struct dsa_switch *ds = p->parent;
> +
> + if (ds->drv->set_eeprom)
> + return ds->drv->set_eeprom(ds, eeprom, data);
Same again.
Andrew
> + return -EOPNOTSUPP;
> +}
> +
> static void dsa_slave_get_strings(struct net_device *dev,
> uint32_t stringset, uint8_t *data)
> {
> @@ -387,6 +425,9 @@ static const struct ethtool_ops dsa_slave_ethtool_ops = {
> .get_drvinfo = dsa_slave_get_drvinfo,
> .nway_reset = dsa_slave_nway_reset,
> .get_link = dsa_slave_get_link,
> + .get_eeprom_len = dsa_slave_get_eeprom_len,
> + .get_eeprom = dsa_slave_get_eeprom,
> + .set_eeprom = dsa_slave_set_eeprom,
> .get_strings = dsa_slave_get_strings,
> .get_ethtool_stats = dsa_slave_get_ethtool_stats,
> .get_sset_count = dsa_slave_get_sset_count,
> --
> 1.9.1
>
next prev parent reply other threads:[~2014-10-27 2:42 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-26 16:52 [PATCH v2 00/15] net: dsa: Fixes and enhancements Guenter Roeck
2014-10-26 16:52 ` [PATCH v2 01/15] net: dsa: Don't set skb->protocol on outgoing tagged packets Guenter Roeck
2014-10-28 19:19 ` Florian Fainelli
2014-10-28 19:23 ` Guenter Roeck
2014-10-26 16:52 ` [PATCH v2 02/15] net: dsa: Report known silicon revisions for Marvell 88E6060 Guenter Roeck
2014-10-26 16:52 ` [PATCH v2 03/15] net: dsa: Report known silicon revisions for Marvell 88E6131 Guenter Roeck
2014-10-26 16:52 ` [PATCH v2 04/15] net: dsa: Add support for Marvell 88E6352 Guenter Roeck
2014-10-26 16:52 ` [PATCH v2 05/15] net: dsa/mv88e6352: Add support for MV88E6176 Guenter Roeck
2014-10-26 16:52 ` [PATCH v2 06/15] net: dsa: Add support for reporting switch chip temperatures Guenter Roeck
2014-10-26 16:52 ` [PATCH v2 07/15] net: dsa/mv88e6352: Report chip temperature Guenter Roeck
2014-10-26 16:52 ` [PATCH v2 08/15] net: dsa/mv88e6123_61_65: " Guenter Roeck
2014-10-26 16:52 ` [PATCH v2 09/15] net: dsa: Add support for switch EEPROM access Guenter Roeck
2014-10-27 2:41 ` Andrew Lunn [this message]
2014-10-27 3:56 ` Guenter Roeck
2014-10-27 8:50 ` Richard Cochran
2014-10-27 13:22 ` Guenter Roeck
2014-10-27 13:59 ` Andrew Lunn
2014-10-27 15:42 ` Guenter Roeck
2014-10-28 13:31 ` Guenter Roeck
2014-10-28 16:49 ` [PATCH v3 " Guenter Roeck
2014-10-28 18:19 ` David Miller
2014-10-28 19:21 ` Guenter Roeck
2014-10-26 16:52 ` [PATCH v2 10/15] dsa: Add new optional devicetree property to describe EEPROM size Guenter Roeck
2014-10-28 16:50 ` [PATCH v3 " Guenter Roeck
2014-10-26 16:52 ` [PATCH v2 11/15] net: dsa/mv88e6352: Implement EEPROM access functions Guenter Roeck
2014-10-26 16:52 ` [PATCH v2 12/15] net: dsa: Add support for reading switch registers with ethtool Guenter Roeck
2014-10-26 16:52 ` [PATCH v2 13/15] net: dsa/mv88e6123_61_65: Add support for reading switch registers Guenter Roeck
2014-10-26 16:52 ` [PATCH v2 14/15] net: dsa/mv88e6352: " Guenter Roeck
2014-10-26 16:52 ` [PATCH v2 15/15] net: dsa: Provide additional RMON statistics Guenter Roeck
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=20141027024121.GA16998@lunn.ch \
--to=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=f.fainelli@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=netdev@vger.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 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).