Skip to content

Commit 9d490b4

Browse files
viviendavem330
authored andcommitted
net: dsa: rename switch operations structure
Now that the dsa_switch_driver structure contains only function pointers as it is supposed to, rename it to the more appropriate dsa_switch_ops, uniformly to any other operations structure in the kernel. No functional changes here, basically just the result of something like: s/dsa_switch_driver *drv/dsa_switch_ops *ops/g However keep the {un,}register_switch_driver functions and their dsa_switch_drivers list as is, since they represent the -- likely to be deprecated soon -- legacy DSA registration framework. In the meantime, also fix the following checks from checkpatch.pl to make it happy with this patch: CHECK: Comparison to NULL could be written "!ops" raspberrypi#403: FILE: net/dsa/dsa.c:470: + if (ops == NULL) { CHECK: Comparison to NULL could be written "ds->ops->get_strings" raspberrypi#773: FILE: net/dsa/slave.c:697: + if (ds->ops->get_strings != NULL) CHECK: Comparison to NULL could be written "ds->ops->get_ethtool_stats" raspberrypi#824: FILE: net/dsa/slave.c:785: + if (ds->ops->get_ethtool_stats != NULL) CHECK: Comparison to NULL could be written "ds->ops->get_sset_count" raspberrypi#835: FILE: net/dsa/slave.c:798: + if (ds->ops->get_sset_count != NULL) total: 0 errors, 0 warnings, 4 checks, 784 lines checked Signed-off-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com> Acked-by: Florian Fainelli <f.fainelli@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent c7b7b48 commit 9d490b4

9 files changed

Lines changed: 137 additions & 137 deletions

File tree

‎Documentation/networking/dsa/dsa.txt‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,9 @@ to address individual switches in the tree.
227227

228228
dsa_switch: structure describing a switch device in the tree, referencing a
229229
dsa_switch_tree as a backpointer, slave network devices, master network device,
230-
and a reference to the backing dsa_switch_driver
230+
and a reference to the backing dsa_switch_ops
231231

232-
dsa_switch_driver: structure referencing function pointers, see below for a full
232+
dsa_switch_ops: structure referencing function pointers, see below for a full
233233
description.
234234

235235
Design limitations
@@ -357,10 +357,10 @@ regular HWMON devices in /sys/class/hwmon/.
357357
Driver development
358358
==================
359359

360-
DSA switch drivers need to implement a dsa_switch_driver structure which will
360+
DSA switch drivers need to implement a dsa_switch_ops structure which will
361361
contain the various members described below.
362362

363-
register_switch_driver() registers this dsa_switch_driver in its internal list
363+
register_switch_driver() registers this dsa_switch_ops in its internal list
364364
of drivers to probe for. unregister_switch_driver() does the exact opposite.
365365

366366
Unless requested differently by setting the priv_size member accordingly, DSA
@@ -379,7 +379,7 @@ Switch configuration
379379
buses, return a non-NULL string
380380

381381
- setup: setup function for the switch, this function is responsible for setting
382-
up the dsa_switch_driver private structure with all it needs: register maps,
382+
up the dsa_switch_ops private structure with all it needs: register maps,
383383
interrupts, mutexes, locks etc.. This function is also expected to properly
384384
configure the switch to separate all network interfaces from each other, that
385385
is, they should be isolated by the switch hardware itself, typically by creating

‎drivers/net/dsa/b53/b53_common.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1378,7 +1378,7 @@ static enum dsa_tag_protocol b53_get_tag_protocol(struct dsa_switch *ds)
13781378
return DSA_TAG_PROTO_NONE;
13791379
}
13801380

1381-
static struct dsa_switch_driver b53_switch_ops = {
1381+
static struct dsa_switch_ops b53_switch_ops = {
13821382
.get_tag_protocol = b53_get_tag_protocol,
13831383
.setup = b53_setup,
13841384
.set_addr = b53_set_addr,
@@ -1618,7 +1618,7 @@ static int b53_switch_init(struct b53_device *dev)
16181618
dev->vta_regs[1] = chip->vta_regs[1];
16191619
dev->vta_regs[2] = chip->vta_regs[2];
16201620
dev->jumbo_pm_reg = chip->jumbo_pm_reg;
1621-
ds->drv = &b53_switch_ops;
1621+
ds->ops = &b53_switch_ops;
16221622
dev->cpu_port = chip->cpu_port;
16231623
dev->num_vlans = chip->vlans;
16241624
dev->num_arl_entries = chip->arl_entries;

‎drivers/net/dsa/bcm_sf2.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1581,7 +1581,7 @@ static int bcm_sf2_sw_setup(struct dsa_switch *ds)
15811581
return 0;
15821582
}
15831583

1584-
static struct dsa_switch_driver bcm_sf2_switch_driver = {
1584+
static struct dsa_switch_ops bcm_sf2_switch_ops = {
15851585
.setup = bcm_sf2_sw_setup,
15861586
.get_tag_protocol = bcm_sf2_sw_get_tag_protocol,
15871587
.set_addr = bcm_sf2_sw_set_addr,
@@ -1632,7 +1632,7 @@ static int bcm_sf2_sw_probe(struct platform_device *pdev)
16321632
priv = (struct bcm_sf2_priv *)(ds + 1);
16331633
ds->priv = priv;
16341634
ds->dev = &pdev->dev;
1635-
ds->drv = &bcm_sf2_switch_driver;
1635+
ds->ops = &bcm_sf2_switch_ops;
16361636

16371637
dev_set_drvdata(&pdev->dev, ds);
16381638

‎drivers/net/dsa/mv88e6060.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ mv88e6060_phy_write(struct dsa_switch *ds, int port, int regnum, u16 val)
252252
return reg_write(ds, addr, regnum, val);
253253
}
254254

255-
static struct dsa_switch_driver mv88e6060_switch_driver = {
255+
static struct dsa_switch_ops mv88e6060_switch_ops = {
256256
.get_tag_protocol = mv88e6060_get_tag_protocol,
257257
.probe = mv88e6060_drv_probe,
258258
.setup = mv88e6060_setup,
@@ -263,14 +263,14 @@ static struct dsa_switch_driver mv88e6060_switch_driver = {
263263

264264
static int __init mv88e6060_init(void)
265265
{
266-
register_switch_driver(&mv88e6060_switch_driver);
266+
register_switch_driver(&mv88e6060_switch_ops);
267267
return 0;
268268
}
269269
module_init(mv88e6060_init);
270270

271271
static void __exit mv88e6060_cleanup(void)
272272
{
273-
unregister_switch_driver(&mv88e6060_switch_driver);
273+
unregister_switch_driver(&mv88e6060_switch_ops);
274274
}
275275
module_exit(mv88e6060_cleanup);
276276

‎drivers/net/dsa/mv88e6xxx/chip.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3976,7 +3976,7 @@ static const char *mv88e6xxx_drv_probe(struct device *dsa_dev,
39763976
return NULL;
39773977
}
39783978

3979-
static struct dsa_switch_driver mv88e6xxx_switch_driver = {
3979+
static struct dsa_switch_ops mv88e6xxx_switch_ops = {
39803980
.probe = mv88e6xxx_drv_probe,
39813981
.get_tag_protocol = mv88e6xxx_get_tag_protocol,
39823982
.setup = mv88e6xxx_setup,
@@ -4025,7 +4025,7 @@ static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip,
40254025

40264026
ds->dev = dev;
40274027
ds->priv = chip;
4028-
ds->drv = &mv88e6xxx_switch_driver;
4028+
ds->ops = &mv88e6xxx_switch_ops;
40294029

40304030
dev_set_drvdata(dev, ds);
40314031

@@ -4118,15 +4118,15 @@ static struct mdio_driver mv88e6xxx_driver = {
41184118

41194119
static int __init mv88e6xxx_init(void)
41204120
{
4121-
register_switch_driver(&mv88e6xxx_switch_driver);
4121+
register_switch_driver(&mv88e6xxx_switch_ops);
41224122
return mdio_driver_register(&mv88e6xxx_driver);
41234123
}
41244124
module_init(mv88e6xxx_init);
41254125

41264126
static void __exit mv88e6xxx_cleanup(void)
41274127
{
41284128
mdio_driver_unregister(&mv88e6xxx_driver);
4129-
unregister_switch_driver(&mv88e6xxx_switch_driver);
4129+
unregister_switch_driver(&mv88e6xxx_switch_ops);
41304130
}
41314131
module_exit(mv88e6xxx_cleanup);
41324132

‎include/net/dsa.h‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,9 @@ struct dsa_switch {
165165
struct dsa_chip_data *cd;
166166

167167
/*
168-
* The used switch driver.
168+
* The switch operations.
169169
*/
170-
struct dsa_switch_driver *drv;
170+
struct dsa_switch_ops *ops;
171171

172172
/*
173173
* An array of which element [a] indicates which port on this
@@ -236,7 +236,7 @@ struct switchdev_obj;
236236
struct switchdev_obj_port_fdb;
237237
struct switchdev_obj_port_vlan;
238238

239-
struct dsa_switch_driver {
239+
struct dsa_switch_ops {
240240
struct list_head list;
241241

242242
/*
@@ -371,8 +371,8 @@ struct dsa_switch_driver {
371371
int (*cb)(struct switchdev_obj *obj));
372372
};
373373

374-
void register_switch_driver(struct dsa_switch_driver *type);
375-
void unregister_switch_driver(struct dsa_switch_driver *type);
374+
void register_switch_driver(struct dsa_switch_ops *type);
375+
void unregister_switch_driver(struct dsa_switch_ops *type);
376376
struct mii_bus *dsa_host_dev_to_mii_bus(struct device *dev);
377377

378378
static inline void *ds_to_priv(struct dsa_switch *ds)

‎net/dsa/dsa.c‎

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -61,27 +61,27 @@ const struct dsa_device_ops *dsa_device_ops[DSA_TAG_LAST] = {
6161
static DEFINE_MUTEX(dsa_switch_drivers_mutex);
6262
static LIST_HEAD(dsa_switch_drivers);
6363

64-
void register_switch_driver(struct dsa_switch_driver *drv)
64+
void register_switch_driver(struct dsa_switch_ops *ops)
6565
{
6666
mutex_lock(&dsa_switch_drivers_mutex);
67-
list_add_tail(&drv->list, &dsa_switch_drivers);
67+
list_add_tail(&ops->list, &dsa_switch_drivers);
6868
mutex_unlock(&dsa_switch_drivers_mutex);
6969
}
7070
EXPORT_SYMBOL_GPL(register_switch_driver);
7171

72-
void unregister_switch_driver(struct dsa_switch_driver *drv)
72+
void unregister_switch_driver(struct dsa_switch_ops *ops)
7373
{
7474
mutex_lock(&dsa_switch_drivers_mutex);
75-
list_del_init(&drv->list);
75+
list_del_init(&ops->list);
7676
mutex_unlock(&dsa_switch_drivers_mutex);
7777
}
7878
EXPORT_SYMBOL_GPL(unregister_switch_driver);
7979

80-
static struct dsa_switch_driver *
80+
static struct dsa_switch_ops *
8181
dsa_switch_probe(struct device *parent, struct device *host_dev, int sw_addr,
8282
const char **_name, void **priv)
8383
{
84-
struct dsa_switch_driver *ret;
84+
struct dsa_switch_ops *ret;
8585
struct list_head *list;
8686
const char *name;
8787

@@ -90,13 +90,13 @@ dsa_switch_probe(struct device *parent, struct device *host_dev, int sw_addr,
9090

9191
mutex_lock(&dsa_switch_drivers_mutex);
9292
list_for_each(list, &dsa_switch_drivers) {
93-
struct dsa_switch_driver *drv;
93+
struct dsa_switch_ops *ops;
9494

95-
drv = list_entry(list, struct dsa_switch_driver, list);
95+
ops = list_entry(list, struct dsa_switch_ops, list);
9696

97-
name = drv->probe(parent, host_dev, sw_addr, priv);
97+
name = ops->probe(parent, host_dev, sw_addr, priv);
9898
if (name != NULL) {
99-
ret = drv;
99+
ret = ops;
100100
break;
101101
}
102102
}
@@ -117,7 +117,7 @@ static ssize_t temp1_input_show(struct device *dev,
117117
struct dsa_switch *ds = dev_get_drvdata(dev);
118118
int temp, ret;
119119

120-
ret = ds->drv->get_temp(ds, &temp);
120+
ret = ds->ops->get_temp(ds, &temp);
121121
if (ret < 0)
122122
return ret;
123123

@@ -131,7 +131,7 @@ static ssize_t temp1_max_show(struct device *dev,
131131
struct dsa_switch *ds = dev_get_drvdata(dev);
132132
int temp, ret;
133133

134-
ret = ds->drv->get_temp_limit(ds, &temp);
134+
ret = ds->ops->get_temp_limit(ds, &temp);
135135
if (ret < 0)
136136
return ret;
137137

@@ -149,7 +149,7 @@ static ssize_t temp1_max_store(struct device *dev,
149149
if (ret < 0)
150150
return ret;
151151

152-
ret = ds->drv->set_temp_limit(ds, DIV_ROUND_CLOSEST(temp, 1000));
152+
ret = ds->ops->set_temp_limit(ds, DIV_ROUND_CLOSEST(temp, 1000));
153153
if (ret < 0)
154154
return ret;
155155

@@ -164,7 +164,7 @@ static ssize_t temp1_max_alarm_show(struct device *dev,
164164
bool alarm;
165165
int ret;
166166

167-
ret = ds->drv->get_temp_alarm(ds, &alarm);
167+
ret = ds->ops->get_temp_alarm(ds, &alarm);
168168
if (ret < 0)
169169
return ret;
170170

@@ -184,15 +184,15 @@ static umode_t dsa_hwmon_attrs_visible(struct kobject *kobj,
184184
{
185185
struct device *dev = container_of(kobj, struct device, kobj);
186186
struct dsa_switch *ds = dev_get_drvdata(dev);
187-
struct dsa_switch_driver *drv = ds->drv;
187+
struct dsa_switch_ops *ops = ds->ops;
188188
umode_t mode = attr->mode;
189189

190190
if (index == 1) {
191-
if (!drv->get_temp_limit)
191+
if (!ops->get_temp_limit)
192192
mode = 0;
193-
else if (!drv->set_temp_limit)
193+
else if (!ops->set_temp_limit)
194194
mode &= ~S_IWUSR;
195-
} else if (index == 2 && !drv->get_temp_alarm) {
195+
} else if (index == 2 && !ops->get_temp_alarm) {
196196
mode = 0;
197197
}
198198
return mode;
@@ -228,8 +228,8 @@ int dsa_cpu_dsa_setup(struct dsa_switch *ds, struct device *dev,
228228

229229
genphy_config_init(phydev);
230230
genphy_read_status(phydev);
231-
if (ds->drv->adjust_link)
232-
ds->drv->adjust_link(ds, port, phydev);
231+
if (ds->ops->adjust_link)
232+
ds->ops->adjust_link(ds, port, phydev);
233233
}
234234

235235
return 0;
@@ -303,7 +303,7 @@ void dsa_cpu_port_ethtool_restore(struct dsa_switch *ds)
303303

304304
static int dsa_switch_setup_one(struct dsa_switch *ds, struct device *parent)
305305
{
306-
struct dsa_switch_driver *drv = ds->drv;
306+
struct dsa_switch_ops *ops = ds->ops;
307307
struct dsa_switch_tree *dst = ds->dst;
308308
struct dsa_chip_data *cd = ds->cd;
309309
bool valid_name_found = false;
@@ -356,7 +356,7 @@ static int dsa_switch_setup_one(struct dsa_switch *ds, struct device *parent)
356356
if (dst->cpu_switch == index) {
357357
enum dsa_tag_protocol tag_protocol;
358358

359-
tag_protocol = drv->get_tag_protocol(ds);
359+
tag_protocol = ops->get_tag_protocol(ds);
360360
dst->tag_ops = dsa_resolve_tag_protocol(tag_protocol);
361361
if (IS_ERR(dst->tag_ops)) {
362362
ret = PTR_ERR(dst->tag_ops);
@@ -371,15 +371,15 @@ static int dsa_switch_setup_one(struct dsa_switch *ds, struct device *parent)
371371
/*
372372
* Do basic register setup.
373373
*/
374-
ret = drv->setup(ds);
374+
ret = ops->setup(ds);
375375
if (ret < 0)
376376
goto out;
377377

378-
ret = drv->set_addr(ds, dst->master_netdev->dev_addr);
378+
ret = ops->set_addr(ds, dst->master_netdev->dev_addr);
379379
if (ret < 0)
380380
goto out;
381381

382-
if (!ds->slave_mii_bus && drv->phy_read) {
382+
if (!ds->slave_mii_bus && ops->phy_read) {
383383
ds->slave_mii_bus = devm_mdiobus_alloc(parent);
384384
if (!ds->slave_mii_bus) {
385385
ret = -ENOMEM;
@@ -426,7 +426,7 @@ static int dsa_switch_setup_one(struct dsa_switch *ds, struct device *parent)
426426
* register with hardware monitoring subsystem.
427427
* Treat registration error as non-fatal and ignore it.
428428
*/
429-
if (drv->get_temp) {
429+
if (ops->get_temp) {
430430
const char *netname = netdev_name(dst->master_netdev);
431431
char hname[IFNAMSIZ + 1];
432432
int i, j;
@@ -457,7 +457,7 @@ dsa_switch_setup(struct dsa_switch_tree *dst, int index,
457457
struct device *parent, struct device *host_dev)
458458
{
459459
struct dsa_chip_data *cd = dst->pd->chip + index;
460-
struct dsa_switch_driver *drv;
460+
struct dsa_switch_ops *ops;
461461
struct dsa_switch *ds;
462462
int ret;
463463
const char *name;
@@ -466,8 +466,8 @@ dsa_switch_setup(struct dsa_switch_tree *dst, int index,
466466
/*
467467
* Probe for switch model.
468468
*/
469-
drv = dsa_switch_probe(parent, host_dev, cd->sw_addr, &name, &priv);
470-
if (drv == NULL) {
469+
ops = dsa_switch_probe(parent, host_dev, cd->sw_addr, &name, &priv);
470+
if (!ops) {
471471
netdev_err(dst->master_netdev, "[%d]: could not detect attached switch\n",
472472
index);
473473
return ERR_PTR(-EINVAL);
@@ -486,7 +486,7 @@ dsa_switch_setup(struct dsa_switch_tree *dst, int index,
486486
ds->dst = dst;
487487
ds->index = index;
488488
ds->cd = cd;
489-
ds->drv = drv;
489+
ds->ops = ops;
490490
ds->priv = priv;
491491
ds->dev = parent;
492492

@@ -541,7 +541,7 @@ static void dsa_switch_destroy(struct dsa_switch *ds)
541541
ds->dsa_port_mask |= ~(1 << port);
542542
}
543543

544-
if (ds->slave_mii_bus && ds->drv->phy_read)
544+
if (ds->slave_mii_bus && ds->ops->phy_read)
545545
mdiobus_unregister(ds->slave_mii_bus);
546546
}
547547

@@ -560,8 +560,8 @@ int dsa_switch_suspend(struct dsa_switch *ds)
560560
return ret;
561561
}
562562

563-
if (ds->drv->suspend)
564-
ret = ds->drv->suspend(ds);
563+
if (ds->ops->suspend)
564+
ret = ds->ops->suspend(ds);
565565

566566
return ret;
567567
}
@@ -571,8 +571,8 @@ int dsa_switch_resume(struct dsa_switch *ds)
571571
{
572572
int i, ret = 0;
573573

574-
if (ds->drv->resume)
575-
ret = ds->drv->resume(ds);
574+
if (ds->ops->resume)
575+
ret = ds->ops->resume(ds);
576576

577577
if (ret)
578578
return ret;

0 commit comments

Comments
 (0)