Skip to content

Commit

Permalink
Merge branch 'more-dsa-probing'
Browse files Browse the repository at this point in the history
Andrew Lunn says:

====================
More enabler patches for DSA probing

The complete set of patches for the reworked DSA probing is too big to
post as once. These subset contains some enablers which are easy to
review.

Eventually, the Marvell driver will instantiate its own internal MDIO
bus, rather than have the framework do it, thus allows devices on the
bus to be listed in the device tree. Initialize the main mutex as soon
as it is created, to avoid lifetime issues with the mdio bus.

A previous patch renamed all the DSA probe functions to make room for
a true device probe. However the recent merging of all the Marvell
switch drivers resulted in mv88e6xxx going back to the old probe
name. Rename it again, so we can have a driver probe function.

Add minimum support for the Marvell switch driver to probe as an MDIO
device, as well as an DSA driver. Later patches will then register
this device with the new DSA core framework.

Move the GPIO reset code out of the DSA code. Different drivers may
need different reset mechanisms, e.g. via a reset controller for
memory mapped devices. Don't clutter up the core with this. Let each
driver implement what it needs.

master_dev is no longer needed in the switch drivers, since they have
access to a device pointer from the probe function. Remove it.

Let the switch parse the eeprom length from its one device tree
node. This is required with the new binding when the central DSA
platform device no longer exists.
====================

Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
David S. Miller committed May 11, 2016
2 parents cb9b902 + f8cd875 commit c1869d5
Show file tree
Hide file tree
Showing 8 changed files with 177 additions and 78 deletions.
2 changes: 0 additions & 2 deletions Documentation/devicetree/bindings/net/dsa/dsa.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ A switch child node has the following optional property:
switch. Must be set if the switch can not detect
the presence and/or size of a connected EEPROM,
otherwise optional.
- reset-gpios : phandle and specifier to a gpio line connected to
reset pin of the switch chip.

A switch may have multiple "port" children nodes

Expand Down
35 changes: 35 additions & 0 deletions Documentation/devicetree/bindings/net/dsa/marvell.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
Marvell DSA Switch Device Tree Bindings
---------------------------------------

WARNING: This binding is currently unstable. Do not program it into a
FLASH never to be changed again. Once this binding is stable, this
warning will be removed.

If you need a stable binding, use the old dsa.txt binding.

Marvell Switches are MDIO devices. The following properties should be
placed as a child node of an mdio device.

The properties described here are those specific to Marvell devices.
Additional required and optional properties can be found in dsa.txt.

Required properties:
- compatible : Should be one of "marvell,mv88e6085",
- reg : Address on the MII bus for the switch.

Optional properties:

- reset-gpios : Should be a gpio specifier for a reset line

Example:

mdio {
#address-cells = <1>;
#size-cells = <0>;

switch0: switch@0 {
compatible = "marvell,mv88e6085";
reg = <0>;
reset-gpios = <&gpio5 1 GPIO_ACTIVE_LOW>;
};
};
4 changes: 2 additions & 2 deletions drivers/net/dsa/bcm_sf2.c
Original file line number Diff line number Diff line change
Expand Up @@ -949,8 +949,8 @@ static int bcm_sf2_sw_setup(struct dsa_switch *ds)
/* All the interesting properties are at the parent device_node
* level
*/
dn = ds->pd->of_node->parent;
bcm_sf2_identify_ports(priv, ds->pd->of_node);
dn = ds->cd->of_node->parent;
bcm_sf2_identify_ports(priv, ds->cd->of_node);

priv->irq0 = irq_of_parse_and_map(dn, 0);
priv->irq1 = irq_of_parse_and_map(dn, 1);
Expand Down
137 changes: 110 additions & 27 deletions drivers/net/dsa/mv88e6xxx.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* Copyright (c) 2015 CMC Electronics, Inc.
* Added support for VLAN Table Unit operations
*
* Copyright (c) 2016 Andrew Lunn <andrew@lunn.ch>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
Expand All @@ -17,6 +19,7 @@
#include <linux/if_bridge.h>
#include <linux/jiffies.h>
#include <linux/list.h>
#include <linux/mdio.h>
#include <linux/module.h>
#include <linux/netdevice.h>
#include <linux/gpio/consumer.h>
Expand Down Expand Up @@ -866,6 +869,16 @@ static int mv88e6xxx_read_eeprom_word(struct dsa_switch *ds, int addr)
return ret;
}

static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
{
struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);

if (mv88e6xxx_has(ps, MV88E6XXX_FLAG_EEPROM))
return ps->eeprom_len;

return 0;
}

static int mv88e6xxx_get_eeprom(struct dsa_switch *ds,
struct ethtool_eeprom *eeprom, u8 *data)
{
Expand Down Expand Up @@ -2579,7 +2592,7 @@ static int mv88e6xxx_switch_reset(struct mv88e6xxx_priv_state *ps)
{
bool ppu_active = mv88e6xxx_has(ps, MV88E6XXX_FLAG_PPU_ACTIVE);
u16 is_reset = (ppu_active ? 0x8800 : 0xc800);
struct gpio_desc *gpiod = ps->ds->pd->reset;
struct gpio_desc *gpiod = ps->reset;
unsigned long timeout;
int ret;
int i;
Expand Down Expand Up @@ -3020,9 +3033,9 @@ static int mv88e6xxx_setup_global(struct mv88e6xxx_priv_state *ps)
for (i = 0; i < 32; i++) {
int nexthop = 0x1f;

if (ps->ds->pd->rtable &&
if (ps->ds->cd->rtable &&
i != ps->ds->index && i < ps->ds->dst->pd->nr_chips)
nexthop = ps->ds->pd->rtable[i] & 0x1f;
nexthop = ps->ds->cd->rtable[i] & 0x1f;

err = _mv88e6xxx_reg_write(
ps, REG_GLOBAL2,
Expand Down Expand Up @@ -3132,8 +3145,6 @@ static int mv88e6xxx_setup(struct dsa_switch *ds)

ps->ds = ds;

mutex_init(&ps->smi_mutex);

INIT_WORK(&ps->bridge_work, mv88e6xxx_bridge_work);

if (mv88e6xxx_has(ps, MV88E6XXX_FLAG_EEPROM))
Expand Down Expand Up @@ -3545,9 +3556,9 @@ mv88e6xxx_lookup_info(unsigned int prod_num, const struct mv88e6xxx_info *table,
return NULL;
}

static const char *mv88e6xxx_probe(struct device *dsa_dev,
struct device *host_dev, int sw_addr,
void **priv)
static const char *mv88e6xxx_drv_probe(struct device *dsa_dev,
struct device *host_dev, int sw_addr,
void **priv)
{
const struct mv88e6xxx_info *info;
struct mv88e6xxx_priv_state *ps;
Expand Down Expand Up @@ -3580,6 +3591,7 @@ static const char *mv88e6xxx_probe(struct device *dsa_dev,
ps->bus = bus;
ps->sw_addr = sw_addr;
ps->info = info;
mutex_init(&ps->smi_mutex);

*priv = ps;

Expand All @@ -3591,7 +3603,7 @@ static const char *mv88e6xxx_probe(struct device *dsa_dev,

struct dsa_switch_driver mv88e6xxx_switch_driver = {
.tag_protocol = DSA_TAG_PROTO_EDSA,
.probe = mv88e6xxx_probe,
.probe = mv88e6xxx_drv_probe,
.setup = mv88e6xxx_setup,
.set_addr = mv88e6xxx_set_addr,
.phy_read = mv88e6xxx_phy_read,
Expand All @@ -3608,6 +3620,7 @@ struct dsa_switch_driver mv88e6xxx_switch_driver = {
.set_temp_limit = mv88e6xxx_set_temp_limit,
.get_temp_alarm = mv88e6xxx_get_temp_alarm,
#endif
.get_eeprom_len = mv88e6xxx_get_eeprom_len,
.get_eeprom = mv88e6xxx_get_eeprom,
.set_eeprom = mv88e6xxx_set_eeprom,
.get_regs_len = mv88e6xxx_get_regs_len,
Expand All @@ -3626,36 +3639,106 @@ struct dsa_switch_driver mv88e6xxx_switch_driver = {
.port_fdb_dump = mv88e6xxx_port_fdb_dump,
};

static int __init mv88e6xxx_init(void)
int mv88e6xxx_probe(struct mdio_device *mdiodev)
{
register_switch_driver(&mv88e6xxx_switch_driver);
struct device *dev = &mdiodev->dev;
struct device_node *np = dev->of_node;
struct mv88e6xxx_priv_state *ps;
int id, prod_num, rev;
struct dsa_switch *ds;
u32 eeprom_len;
int err;

ds = devm_kzalloc(dev, sizeof(*ds) + sizeof(*ps), GFP_KERNEL);
if (!ds)
return -ENOMEM;

ps = (struct mv88e6xxx_priv_state *)(ds + 1);
ds->priv = ps;
ds->dev = dev;
ps->dev = dev;
ps->ds = ds;
ps->bus = mdiodev->bus;
ps->sw_addr = mdiodev->addr;
mutex_init(&ps->smi_mutex);

get_device(&ps->bus->dev);

ds->drv = &mv88e6xxx_switch_driver;

id = mv88e6xxx_reg_read(ps, REG_PORT(0), PORT_SWITCH_ID);
if (id < 0)
return id;

prod_num = (id & 0xfff0) >> 4;
rev = id & 0x000f;

ps->info = mv88e6xxx_lookup_info(prod_num, mv88e6xxx_table,
ARRAY_SIZE(mv88e6xxx_table));
if (!ps->info)
return -ENODEV;

ps->reset = devm_gpiod_get(&mdiodev->dev, "reset", GPIOD_ASIS);
if (IS_ERR(ps->reset)) {
err = PTR_ERR(ps->reset);
if (err == -ENOENT) {
/* Optional, so not an error */
ps->reset = NULL;
} else {
return err;
}
}

if (mv88e6xxx_has(ps, MV88E6XXX_FLAG_EEPROM) &&
!of_property_read_u32(np, "eeprom-length", &eeprom_len))
ps->eeprom_len = eeprom_len;

dev_set_drvdata(dev, ds);

dev_info(dev, "switch 0x%x probed: %s, revision %u\n",
prod_num, ps->info->name, rev);

return 0;
}

static void mv88e6xxx_remove(struct mdio_device *mdiodev)
{
struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev);
struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);

put_device(&ps->bus->dev);
}

static const struct of_device_id mv88e6xxx_of_match[] = {
{ .compatible = "marvell,mv88e6085" },
{ /* sentinel */ },
};

MODULE_DEVICE_TABLE(of, mv88e6xxx_of_match);

static struct mdio_driver mv88e6xxx_driver = {
.probe = mv88e6xxx_probe,
.remove = mv88e6xxx_remove,
.mdiodrv.driver = {
.name = "mv88e6085",
.of_match_table = mv88e6xxx_of_match,
},
};

static int __init mv88e6xxx_init(void)
{
register_switch_driver(&mv88e6xxx_switch_driver);
return mdio_driver_register(&mv88e6xxx_driver);
}
module_init(mv88e6xxx_init);

static void __exit mv88e6xxx_cleanup(void)
{
mdio_driver_unregister(&mv88e6xxx_driver);
unregister_switch_driver(&mv88e6xxx_switch_driver);
}
module_exit(mv88e6xxx_cleanup);

MODULE_ALIAS("platform:mv88e6085");
MODULE_ALIAS("platform:mv88e6095");
MODULE_ALIAS("platform:mv88e6095f");
MODULE_ALIAS("platform:mv88e6123");
MODULE_ALIAS("platform:mv88e6131");
MODULE_ALIAS("platform:mv88e6161");
MODULE_ALIAS("platform:mv88e6165");
MODULE_ALIAS("platform:mv88e6171");
MODULE_ALIAS("platform:mv88e6172");
MODULE_ALIAS("platform:mv88e6175");
MODULE_ALIAS("platform:mv88e6176");
MODULE_ALIAS("platform:mv88e6320");
MODULE_ALIAS("platform:mv88e6321");
MODULE_ALIAS("platform:mv88e6350");
MODULE_ALIAS("platform:mv88e6351");
MODULE_ALIAS("platform:mv88e6352");
MODULE_AUTHOR("Lennert Buytenhek <buytenh@wantstofly.org>");
MODULE_DESCRIPTION("Driver for Marvell 88E6XXX ethernet switch chips");
MODULE_LICENSE("GPL");
10 changes: 10 additions & 0 deletions drivers/net/dsa/mv88e6xxx.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#define __MV88E6XXX_H

#include <linux/if_vlan.h>
#include <linux/gpio/consumer.h>

#ifndef UINT64_MAX
#define UINT64_MAX (u64)(~((u64)0))
Expand Down Expand Up @@ -595,6 +596,15 @@ struct mv88e6xxx_priv_state {
DECLARE_BITMAP(port_state_update_mask, DSA_MAX_PORTS);

struct work_struct bridge_work;

/* A switch may have a GPIO line tied to its reset pin. Parse
* this from the device tree, and use it before performing
* switch soft reset.
*/
struct gpio_desc *reset;

/* set to size of eeprom if supported by the switch */
int eeprom_len;
};

enum stat_type {
Expand Down
19 changes: 4 additions & 15 deletions include/net/dsa.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include <linux/timer.h>
#include <linux/workqueue.h>
#include <linux/of.h>
#include <linux/of_gpio.h>
#include <linux/phy.h>
#include <linux/phy_fixed.h>
#include <linux/ethtool.h>
Expand Down Expand Up @@ -65,13 +64,6 @@ struct dsa_chip_data {
* NULL if there is only one switch chip.
*/
s8 *rtable;

/*
* A switch may have a GPIO line tied to its reset pin. Parse
* this from the device tree, and use it before performing
* switch soft reset.
*/
struct gpio_desc *reset;
};

struct dsa_platform_data {
Expand Down Expand Up @@ -128,6 +120,8 @@ struct dsa_switch_tree {
};

struct dsa_switch {
struct device *dev;

/*
* Parent switch tree, and switch index.
*/
Expand All @@ -143,18 +137,13 @@ struct dsa_switch {
/*
* Configuration data for this switch.
*/
struct dsa_chip_data *pd;
struct dsa_chip_data *cd;

/*
* The used switch driver.
*/
struct dsa_switch_driver *drv;

/*
* Reference to host device to use.
*/
struct device *master_dev;

#ifdef CONFIG_NET_DSA_HWMON
/*
* Hardware monitoring information
Expand Down Expand Up @@ -201,7 +190,7 @@ static inline u8 dsa_upstream_port(struct dsa_switch *ds)
if (dst->cpu_switch == ds->index)
return dst->cpu_port;
else
return ds->pd->rtable[dst->cpu_switch];
return ds->cd->rtable[dst->cpu_switch];
}

struct switchdev_trans;
Expand Down
Loading

0 comments on commit c1869d5

Please sign in to comment.