From: Andrew Lunn <andrew@lunn.ch>
To: Florian Fainelli <f.fainelli@gmail.com>,
Vivien Didelot <vivien.didelot@savoirfairelinux.com>,
netdev <netdev@vger.kernel.org>
Cc: Andrew Lunn <andrew@lunn.ch>
Subject: [PATCH RFC v2 05/32] net: dsa: Have the switch driver allocate there own private memory
Date: Sun, 28 Feb 2016 17:41:13 +0100 [thread overview]
Message-ID: <1456677700-23027-6-git-send-email-andrew@lunn.ch> (raw)
In-Reply-To: <1456677700-23027-1-git-send-email-andrew@lunn.ch>
Now the switch devices have a dev pointer, make use if it for allocating
the drivers private data structures using a devm_kzalloc().
Signed-off-by: Andrew Lunn <andrew@lunn.ch>
Acked-by: Florian Fainelli <f.fainelli@gmail.com>
---
v2: Added missing assignment of priv to ds->priv.
---
drivers/net/dsa/bcm_sf2.c | 9 +++++++--
drivers/net/dsa/mv88e6123.c | 6 +++---
drivers/net/dsa/mv88e6131.c | 6 +++---
drivers/net/dsa/mv88e6171.c | 6 +++---
drivers/net/dsa/mv88e6352.c | 6 +++---
drivers/net/dsa/mv88e6xxx.c | 13 ++++++++++---
drivers/net/dsa/mv88e6xxx.h | 5 ++++-
include/net/dsa.h | 8 +++++++-
8 files changed, 40 insertions(+), 19 deletions(-)
diff --git a/drivers/net/dsa/bcm_sf2.c b/drivers/net/dsa/bcm_sf2.c
index 6925b3c13895..fbb17e042e7b 100644
--- a/drivers/net/dsa/bcm_sf2.c
+++ b/drivers/net/dsa/bcm_sf2.c
@@ -929,7 +929,7 @@ static void bcm_sf2_identify_ports(struct bcm_sf2_priv *priv,
static int bcm_sf2_sw_setup(struct dsa_switch *ds, struct device *dev)
{
const char *reg_names[BCM_SF2_REGS_NUM] = BCM_SF2_REGS_NAME;
- struct bcm_sf2_priv *priv = ds_to_priv(ds);
+ struct bcm_sf2_priv *priv;
struct device_node *dn;
void __iomem **base;
unsigned int port;
@@ -937,6 +937,12 @@ static int bcm_sf2_sw_setup(struct dsa_switch *ds, struct device *dev)
u32 reg, rev;
int ret;
+ priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
+ if (!priv)
+ return -ENOMEM;
+
+ ds->priv = priv;
+
spin_lock_init(&priv->indir_lock);
mutex_init(&priv->stats_mutex);
@@ -1365,7 +1371,6 @@ static int bcm_sf2_sw_set_wol(struct dsa_switch *ds, int port,
static struct dsa_switch_driver bcm_sf2_switch_driver = {
.tag_protocol = DSA_TAG_PROTO_BRCM,
- .priv_size = sizeof(struct bcm_sf2_priv),
.probe = bcm_sf2_sw_probe,
.setup = bcm_sf2_sw_setup,
.set_addr = bcm_sf2_sw_set_addr,
diff --git a/drivers/net/dsa/mv88e6123.c b/drivers/net/dsa/mv88e6123.c
index fab428bb7545..9d39f108793b 100644
--- a/drivers/net/dsa/mv88e6123.c
+++ b/drivers/net/dsa/mv88e6123.c
@@ -70,13 +70,14 @@ static int mv88e6123_setup_global(struct dsa_switch *ds)
static int mv88e6123_setup(struct dsa_switch *ds, struct device *dev)
{
- struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
+ struct mv88e6xxx_priv_state *ps;
int ret;
- ret = mv88e6xxx_setup_common(ds);
+ ret = mv88e6xxx_setup_common(ds, dev);
if (ret < 0)
return ret;
+ ps = ds_to_priv(ds);
switch (ps->id) {
case PORT_SWITCH_ID_6123:
ps->num_ports = 3;
@@ -102,7 +103,6 @@ static int mv88e6123_setup(struct dsa_switch *ds, struct device *dev)
struct dsa_switch_driver mv88e6123_switch_driver = {
.tag_protocol = DSA_TAG_PROTO_EDSA,
- .priv_size = sizeof(struct mv88e6xxx_priv_state),
.probe = mv88e6123_probe,
.setup = mv88e6123_setup,
.set_addr = mv88e6xxx_set_addr_indirect,
diff --git a/drivers/net/dsa/mv88e6131.c b/drivers/net/dsa/mv88e6131.c
index d82cf3d38455..3103b4953af4 100644
--- a/drivers/net/dsa/mv88e6131.c
+++ b/drivers/net/dsa/mv88e6131.c
@@ -88,13 +88,14 @@ static int mv88e6131_setup_global(struct dsa_switch *ds)
static int mv88e6131_setup(struct dsa_switch *ds, struct device *dev)
{
- struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
+ struct mv88e6xxx_priv_state *ps;
int ret;
- ret = mv88e6xxx_setup_common(ds);
+ ret = mv88e6xxx_setup_common(ds, dev);
if (ret < 0)
return ret;
+ ps = ds_to_priv(ds);
mv88e6xxx_ppu_state_init(ds);
switch (ps->id) {
@@ -159,7 +160,6 @@ mv88e6131_phy_write(struct dsa_switch *ds,
struct dsa_switch_driver mv88e6131_switch_driver = {
.tag_protocol = DSA_TAG_PROTO_DSA,
- .priv_size = sizeof(struct mv88e6xxx_priv_state),
.probe = mv88e6131_probe,
.setup = mv88e6131_setup,
.set_addr = mv88e6xxx_set_addr_direct,
diff --git a/drivers/net/dsa/mv88e6171.c b/drivers/net/dsa/mv88e6171.c
index 9635f14ec1fb..29a77366afc6 100644
--- a/drivers/net/dsa/mv88e6171.c
+++ b/drivers/net/dsa/mv88e6171.c
@@ -66,13 +66,14 @@ static int mv88e6171_setup_global(struct dsa_switch *ds)
static int mv88e6171_setup(struct dsa_switch *ds, struct device *dev)
{
- struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
+ struct mv88e6xxx_priv_state *ps;
int ret;
- ret = mv88e6xxx_setup_common(ds);
+ ret = mv88e6xxx_setup_common(ds, dev);
if (ret < 0)
return ret;
+ ps = ds_to_priv(ds);
ps->num_ports = 7;
ret = mv88e6xxx_switch_reset(ds, true);
@@ -88,7 +89,6 @@ static int mv88e6171_setup(struct dsa_switch *ds, struct device *dev)
struct dsa_switch_driver mv88e6171_switch_driver = {
.tag_protocol = DSA_TAG_PROTO_EDSA,
- .priv_size = sizeof(struct mv88e6xxx_priv_state),
.probe = mv88e6171_probe,
.setup = mv88e6171_setup,
.set_addr = mv88e6xxx_set_addr_indirect,
diff --git a/drivers/net/dsa/mv88e6352.c b/drivers/net/dsa/mv88e6352.c
index c2c4153e3423..eb57a379b9cc 100644
--- a/drivers/net/dsa/mv88e6352.c
+++ b/drivers/net/dsa/mv88e6352.c
@@ -77,13 +77,14 @@ static int mv88e6352_setup_global(struct dsa_switch *ds)
static int mv88e6352_setup(struct dsa_switch *ds, struct device *dev)
{
- struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
+ struct mv88e6xxx_priv_state *ps;
int ret;
- ret = mv88e6xxx_setup_common(ds);
+ ret = mv88e6xxx_setup_common(ds, dev);
if (ret < 0)
return ret;
+ ps = ds_to_priv(ds);
ps->num_ports = 7;
mutex_init(&ps->eeprom_mutex);
@@ -301,7 +302,6 @@ static int mv88e6352_set_eeprom(struct dsa_switch *ds,
struct dsa_switch_driver mv88e6352_switch_driver = {
.tag_protocol = DSA_TAG_PROTO_EDSA,
- .priv_size = sizeof(struct mv88e6xxx_priv_state),
.probe = mv88e6352_probe,
.setup = mv88e6352_setup,
.set_addr = mv88e6xxx_set_addr_indirect,
diff --git a/drivers/net/dsa/mv88e6xxx.c b/drivers/net/dsa/mv88e6xxx.c
index 493ae8b5a48e..c2d26168fdf8 100644
--- a/drivers/net/dsa/mv88e6xxx.c
+++ b/drivers/net/dsa/mv88e6xxx.c
@@ -281,7 +281,7 @@ static void mv88e6xxx_ppu_reenable_work(struct work_struct *ugly)
ps = container_of(ugly, struct mv88e6xxx_priv_state, ppu_work);
if (mutex_trylock(&ps->ppu_mutex)) {
- struct dsa_switch *ds = ((struct dsa_switch *)ps) - 1;
+ struct dsa_switch *ds = ps->ds;
if (mv88e6xxx_ppu_enable(ds) == 0)
ps->ppu_disabled = 0;
@@ -2200,9 +2200,16 @@ int mv88e6xxx_setup_ports(struct dsa_switch *ds)
return 0;
}
-int mv88e6xxx_setup_common(struct dsa_switch *ds)
+int mv88e6xxx_setup_common(struct dsa_switch *ds, struct device *dev)
{
- struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
+ struct mv88e6xxx_priv_state *ps;
+
+ ps = devm_kzalloc(dev, sizeof(*ps), GFP_KERNEL);
+ if (!ps)
+ return -ENOMEM;
+
+ ds->priv = ps;
+ ps->ds = ds;
mutex_init(&ps->smi_mutex);
diff --git a/drivers/net/dsa/mv88e6xxx.h b/drivers/net/dsa/mv88e6xxx.h
index 931a09b92b9e..8a13162353cd 100644
--- a/drivers/net/dsa/mv88e6xxx.h
+++ b/drivers/net/dsa/mv88e6xxx.h
@@ -380,6 +380,9 @@ struct mv88e6xxx_vtu_stu_entry {
};
struct mv88e6xxx_priv_state {
+ /* The dsa_switch this private structure is related to */
+ struct dsa_switch *ds;
+
/* When using multi-chip addressing, this mutex protects
* access to the indirect access registers. (In single-chip
* mode, this mutex is effectively useless.)
@@ -439,7 +442,7 @@ char *mv88e6xxx_lookup_name(struct device *host_dev, int sw_addr,
const struct mv88e6xxx_switch_id *table,
unsigned int num);
int mv88e6xxx_setup_ports(struct dsa_switch *ds);
-int mv88e6xxx_setup_common(struct dsa_switch *ds);
+int mv88e6xxx_setup_common(struct dsa_switch *ds, struct device *dev);
int mv88e6xxx_setup_global(struct dsa_switch *ds);
int mv88e6xxx_reg_read(struct dsa_switch *ds, int addr, int reg);
int mv88e6xxx_reg_write(struct dsa_switch *ds, int addr, int reg, u16 val);
diff --git a/include/net/dsa.h b/include/net/dsa.h
index f5b4f1bcfdf3..05067b030962 100644
--- a/include/net/dsa.h
+++ b/include/net/dsa.h
@@ -130,6 +130,12 @@ struct dsa_switch {
int index;
/*
+ * Give the switch driver somewhere to hang its private data
+ * structure.
+ */
+ void *priv;
+
+ /*
* Tagging protocol understood by this switch
*/
enum dsa_tag_protocol tag_protocol;
@@ -340,7 +346,7 @@ struct mii_bus *dsa_host_dev_to_mii_bus(struct device *dev);
static inline void *ds_to_priv(struct dsa_switch *ds)
{
- return (void *)(ds + 1);
+ return ds->priv;
}
static inline bool dsa_uses_tagged_protocol(struct dsa_switch_tree *dst)
--
2.7.0
next prev parent reply other threads:[~2016-02-28 16:43 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-28 16:41 [PATCH RFC v2 00/32] Make DSA switches linux devices Andrew Lunn
2016-02-28 16:41 ` [PATCH RFC v2 01/32] net: dsa: Move platform data allocation for OF Andrew Lunn
2016-02-28 16:41 ` [PATCH RFC v2 02/32] dsa: Rename mv88e6123_61_65 to mv88e6123 to be consistent Andrew Lunn
2016-02-28 16:41 ` [PATCH RFC v2 03/32] dsa: Make setup and finish more symmetrical Andrew Lunn
2016-03-11 23:54 ` Florian Fainelli
2016-02-28 16:41 ` [PATCH RFC v2 04/32] net: dsa: Pass the dsa device to the switch drivers Andrew Lunn
2016-02-28 16:41 ` Andrew Lunn [this message]
2016-02-28 16:41 ` [PATCH RFC v2 06/32] net: dsa: Remove allocation of driver private memory Andrew Lunn
2016-02-28 16:41 ` [PATCH RFC v2 07/32] net: dsa: Keep the mii bus and address in the private structure Andrew Lunn
2016-02-28 16:41 ` [PATCH RFC v2 08/32] net: dsa: dsa.c: Refactor to increase symmetry Andrew Lunn
2016-03-11 23:54 ` Florian Fainelli
2016-02-28 16:41 ` [PATCH RFC v2 09/32] driver: component: Add support for empty match table Andrew Lunn
2016-02-28 16:41 ` [PATCH RFC v2 10/32] net: dsa: Add basic support for component master support Andrew Lunn
2016-02-28 16:41 ` [PATCH RFC v2 11/32] net: dsa: Keep a reference to the switch device for component matching Andrew Lunn
2016-02-28 16:41 ` [PATCH RFC v2 12/32] net: dsa: Add slave component matches based on a phandle to the slave Andrew Lunn
2016-02-28 16:41 ` [PATCH RFC v2 13/32] net: dsa: Make dsa,mii-bus optional Andrew Lunn
2016-02-28 16:41 ` [PATCH RFC v2 14/32] net: dsa: Add register/unregister functions for switch drivers Andrew Lunn
2016-02-28 16:41 ` [PATCH RFC v2 15/32] net: dsa: Rename DSA probe function Andrew Lunn
2016-02-28 16:41 ` [PATCH RFC v2 16/32] dsa: mv88e6xxx: Use bus in mv88e6xxx_lookup_name() Andrew Lunn
2016-02-28 16:41 ` [PATCH RFC v2 17/32] dsa: mv88e6xxx: Add shared code for binding/unbinding a switch driver Andrew Lunn
2016-02-28 16:41 ` [PATCH RFC v2 18/32] dsa: mv88e6xxx: Prepare for turning this into a library module Andrew Lunn
2016-02-29 2:40 ` Vivien Didelot
2016-02-29 14:53 ` Andrew Lunn
2016-02-28 16:41 ` [PATCH RFC v2 19/32] dsa: mv88e6xxx: Add macro for registering the drivers Andrew Lunn
2016-02-28 16:41 ` [PATCH RFC v2 20/32] dsa: Add mdio device support to Marvell switches Andrew Lunn
2016-02-28 16:41 ` [PATCH RFC v2 21/32] net: mdio: Add mdiodev_{read|write} helpers Andrew Lunn
2016-02-28 16:41 ` [PATCH RFC v2 22/32] net: dsa: Better integrate the drivers with mdio device Andrew Lunn
2016-02-28 16:41 ` [PATCH RFC v2 23/32] net: dsa: bcm_sf2: make it a real platform driver Andrew Lunn
2016-03-03 18:33 ` Florian Fainelli
2016-03-03 19:12 ` Andrew Lunn
2016-02-28 16:41 ` [PATCH RFC v2 24/32] net: dsa: Add some debug prints for error cases Andrew Lunn
2016-02-28 16:41 ` [PATCH RFC v2 25/32] net: dsa: Setup the switches after all have been probed Andrew Lunn
2016-02-28 16:41 ` [PATCH RFC v2 26/32] net: dsa: Only setup platform switches, not device switches Andrew Lunn
2016-02-28 16:41 ` [PATCH RFC v2 27/32] net: dsa: If a switch fails to probe, defer probing Andrew Lunn
2016-02-28 16:41 ` [PATCH RFC v2 28/32] Documentation: DSA: Describe how probe of DSA and switches work Andrew Lunn
2016-02-29 11:42 ` Sergei Shtylyov
2016-02-28 16:41 ` [PATCH RFC v2 29/32] dsa: slave: Don't reference NULL pointer during phy_disconnect Andrew Lunn
2016-02-28 16:41 ` [PATCH RFC v2 30/32] dsa: Destroy fixed link phys after the phy has been disconnected Andrew Lunn
2016-02-28 16:41 ` [PATCH RFC v2 31/32] dsa: dsa: Fix freeing of fixed-phys from user ports Andrew Lunn
2016-02-28 16:41 ` [PATCH RFC v2 32/32] phy: fixed: Fix removal of phys Andrew Lunn
2016-03-03 18:49 ` [PATCH RFC v2 00/32] Make DSA switches linux devices Florian Fainelli
2016-03-03 20:27 ` Andrew Lunn
2016-03-11 23:41 ` Florian Fainelli
2016-03-12 17:08 ` Andrew Lunn
2016-03-13 7:26 ` Vivien Didelot
2016-03-14 19:36 ` Florian Fainelli
2016-03-14 20: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=1456677700-23027-6-git-send-email-andrew@lunn.ch \
--to=andrew@lunn.ch \
--cc=f.fainelli@gmail.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).