|
|
@@ -78,18 +78,23 @@ static void dsa_dst_del_ds(struct dsa_switch_tree *dst,
|
|
|
kref_put(&dst->refcount, dsa_free_dst);
|
|
|
}
|
|
|
|
|
|
-static bool dsa_port_is_dsa(struct device_node *port)
|
|
|
+static bool dsa_port_is_valid(struct dsa_port *port)
|
|
|
{
|
|
|
- return !!of_parse_phandle(port, "link", 0);
|
|
|
+ return !!port->dn;
|
|
|
}
|
|
|
|
|
|
-static bool dsa_port_is_cpu(struct device_node *port)
|
|
|
+static bool dsa_port_is_dsa(struct dsa_port *port)
|
|
|
{
|
|
|
- return !!of_parse_phandle(port, "ethernet", 0);
|
|
|
+ return !!of_parse_phandle(port->dn, "link", 0);
|
|
|
}
|
|
|
|
|
|
-static bool dsa_ds_find_port(struct dsa_switch *ds,
|
|
|
- struct device_node *port)
|
|
|
+static bool dsa_port_is_cpu(struct dsa_port *port)
|
|
|
+{
|
|
|
+ return !!of_parse_phandle(port->dn, "ethernet", 0);
|
|
|
+}
|
|
|
+
|
|
|
+static bool dsa_ds_find_port_dn(struct dsa_switch *ds,
|
|
|
+ struct device_node *port)
|
|
|
{
|
|
|
u32 index;
|
|
|
|
|
|
@@ -99,8 +104,8 @@ static bool dsa_ds_find_port(struct dsa_switch *ds,
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
-static struct dsa_switch *dsa_dst_find_port(struct dsa_switch_tree *dst,
|
|
|
- struct device_node *port)
|
|
|
+static struct dsa_switch *dsa_dst_find_port_dn(struct dsa_switch_tree *dst,
|
|
|
+ struct device_node *port)
|
|
|
{
|
|
|
struct dsa_switch *ds;
|
|
|
u32 index;
|
|
|
@@ -110,7 +115,7 @@ static struct dsa_switch *dsa_dst_find_port(struct dsa_switch_tree *dst,
|
|
|
if (!ds)
|
|
|
continue;
|
|
|
|
|
|
- if (dsa_ds_find_port(ds, port))
|
|
|
+ if (dsa_ds_find_port_dn(ds, port))
|
|
|
return ds;
|
|
|
}
|
|
|
|
|
|
@@ -119,7 +124,7 @@ static struct dsa_switch *dsa_dst_find_port(struct dsa_switch_tree *dst,
|
|
|
|
|
|
static int dsa_port_complete(struct dsa_switch_tree *dst,
|
|
|
struct dsa_switch *src_ds,
|
|
|
- struct device_node *port,
|
|
|
+ struct dsa_port *port,
|
|
|
u32 src_port)
|
|
|
{
|
|
|
struct device_node *link;
|
|
|
@@ -127,11 +132,11 @@ static int dsa_port_complete(struct dsa_switch_tree *dst,
|
|
|
struct dsa_switch *dst_ds;
|
|
|
|
|
|
for (index = 0;; index++) {
|
|
|
- link = of_parse_phandle(port, "link", index);
|
|
|
+ link = of_parse_phandle(port->dn, "link", index);
|
|
|
if (!link)
|
|
|
break;
|
|
|
|
|
|
- dst_ds = dsa_dst_find_port(dst, link);
|
|
|
+ dst_ds = dsa_dst_find_port_dn(dst, link);
|
|
|
of_node_put(link);
|
|
|
|
|
|
if (!dst_ds)
|
|
|
@@ -150,13 +155,13 @@ static int dsa_port_complete(struct dsa_switch_tree *dst,
|
|
|
*/
|
|
|
static int dsa_ds_complete(struct dsa_switch_tree *dst, struct dsa_switch *ds)
|
|
|
{
|
|
|
- struct device_node *port;
|
|
|
+ struct dsa_port *port;
|
|
|
u32 index;
|
|
|
int err;
|
|
|
|
|
|
for (index = 0; index < DSA_MAX_PORTS; index++) {
|
|
|
- port = ds->ports[index].dn;
|
|
|
- if (!port)
|
|
|
+ port = &ds->ports[index];
|
|
|
+ if (!dsa_port_is_valid(port))
|
|
|
continue;
|
|
|
|
|
|
if (!dsa_port_is_dsa(port))
|
|
|
@@ -196,7 +201,7 @@ static int dsa_dst_complete(struct dsa_switch_tree *dst)
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
-static int dsa_dsa_port_apply(struct device_node *port, u32 index,
|
|
|
+static int dsa_dsa_port_apply(struct dsa_port *port, u32 index,
|
|
|
struct dsa_switch *ds)
|
|
|
{
|
|
|
int err;
|
|
|
@@ -211,13 +216,13 @@ static int dsa_dsa_port_apply(struct device_node *port, u32 index,
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
-static void dsa_dsa_port_unapply(struct device_node *port, u32 index,
|
|
|
+static void dsa_dsa_port_unapply(struct dsa_port *port, u32 index,
|
|
|
struct dsa_switch *ds)
|
|
|
{
|
|
|
dsa_cpu_dsa_destroy(port);
|
|
|
}
|
|
|
|
|
|
-static int dsa_cpu_port_apply(struct device_node *port, u32 index,
|
|
|
+static int dsa_cpu_port_apply(struct dsa_port *port, u32 index,
|
|
|
struct dsa_switch *ds)
|
|
|
{
|
|
|
int err;
|
|
|
@@ -234,7 +239,7 @@ static int dsa_cpu_port_apply(struct device_node *port, u32 index,
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
-static void dsa_cpu_port_unapply(struct device_node *port, u32 index,
|
|
|
+static void dsa_cpu_port_unapply(struct dsa_port *port, u32 index,
|
|
|
struct dsa_switch *ds)
|
|
|
{
|
|
|
dsa_cpu_dsa_destroy(port);
|
|
|
@@ -242,13 +247,13 @@ static void dsa_cpu_port_unapply(struct device_node *port, u32 index,
|
|
|
|
|
|
}
|
|
|
|
|
|
-static int dsa_user_port_apply(struct device_node *port, u32 index,
|
|
|
+static int dsa_user_port_apply(struct dsa_port *port, u32 index,
|
|
|
struct dsa_switch *ds)
|
|
|
{
|
|
|
const char *name;
|
|
|
int err;
|
|
|
|
|
|
- name = of_get_property(port, "label", NULL);
|
|
|
+ name = of_get_property(port->dn, "label", NULL);
|
|
|
if (!name)
|
|
|
name = "eth%d";
|
|
|
|
|
|
@@ -262,7 +267,7 @@ static int dsa_user_port_apply(struct device_node *port, u32 index,
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
-static void dsa_user_port_unapply(struct device_node *port, u32 index,
|
|
|
+static void dsa_user_port_unapply(struct dsa_port *port, u32 index,
|
|
|
struct dsa_switch *ds)
|
|
|
{
|
|
|
if (ds->ports[index].netdev) {
|
|
|
@@ -274,7 +279,7 @@ static void dsa_user_port_unapply(struct device_node *port, u32 index,
|
|
|
|
|
|
static int dsa_ds_apply(struct dsa_switch_tree *dst, struct dsa_switch *ds)
|
|
|
{
|
|
|
- struct device_node *port;
|
|
|
+ struct dsa_port *port;
|
|
|
u32 index;
|
|
|
int err;
|
|
|
|
|
|
@@ -308,8 +313,8 @@ static int dsa_ds_apply(struct dsa_switch_tree *dst, struct dsa_switch *ds)
|
|
|
}
|
|
|
|
|
|
for (index = 0; index < DSA_MAX_PORTS; index++) {
|
|
|
- port = ds->ports[index].dn;
|
|
|
- if (!port)
|
|
|
+ port = &ds->ports[index];
|
|
|
+ if (!dsa_port_is_valid(port))
|
|
|
continue;
|
|
|
|
|
|
if (dsa_port_is_dsa(port)) {
|
|
|
@@ -336,12 +341,12 @@ static int dsa_ds_apply(struct dsa_switch_tree *dst, struct dsa_switch *ds)
|
|
|
|
|
|
static void dsa_ds_unapply(struct dsa_switch_tree *dst, struct dsa_switch *ds)
|
|
|
{
|
|
|
- struct device_node *port;
|
|
|
+ struct dsa_port *port;
|
|
|
u32 index;
|
|
|
|
|
|
for (index = 0; index < DSA_MAX_PORTS; index++) {
|
|
|
- port = ds->ports[index].dn;
|
|
|
- if (!port)
|
|
|
+ port = &ds->ports[index];
|
|
|
+ if (!dsa_port_is_valid(port))
|
|
|
continue;
|
|
|
|
|
|
if (dsa_port_is_dsa(port)) {
|
|
|
@@ -425,7 +430,7 @@ static void dsa_dst_unapply(struct dsa_switch_tree *dst)
|
|
|
dst->applied = false;
|
|
|
}
|
|
|
|
|
|
-static int dsa_cpu_parse(struct device_node *port, u32 index,
|
|
|
+static int dsa_cpu_parse(struct dsa_port *port, u32 index,
|
|
|
struct dsa_switch_tree *dst,
|
|
|
struct dsa_switch *ds)
|
|
|
{
|
|
|
@@ -433,7 +438,7 @@ static int dsa_cpu_parse(struct device_node *port, u32 index,
|
|
|
struct net_device *ethernet_dev;
|
|
|
struct device_node *ethernet;
|
|
|
|
|
|
- ethernet = of_parse_phandle(port, "ethernet", 0);
|
|
|
+ ethernet = of_parse_phandle(port->dn, "ethernet", 0);
|
|
|
if (!ethernet)
|
|
|
return -EINVAL;
|
|
|
|
|
|
@@ -466,13 +471,13 @@ static int dsa_cpu_parse(struct device_node *port, u32 index,
|
|
|
|
|
|
static int dsa_ds_parse(struct dsa_switch_tree *dst, struct dsa_switch *ds)
|
|
|
{
|
|
|
- struct device_node *port;
|
|
|
+ struct dsa_port *port;
|
|
|
u32 index;
|
|
|
int err;
|
|
|
|
|
|
for (index = 0; index < DSA_MAX_PORTS; index++) {
|
|
|
- port = ds->ports[index].dn;
|
|
|
- if (!port)
|
|
|
+ port = &ds->ports[index];
|
|
|
+ if (!dsa_port_is_valid(port))
|
|
|
continue;
|
|
|
|
|
|
if (dsa_port_is_cpu(port)) {
|
|
|
@@ -533,14 +538,14 @@ static int dsa_parse_ports_dn(struct device_node *ports, struct dsa_switch *ds)
|
|
|
* to have access to a correct value, just like what
|
|
|
* net/dsa/dsa.c::dsa_switch_setup_one does.
|
|
|
*/
|
|
|
- if (!dsa_port_is_cpu(port))
|
|
|
+ if (!dsa_port_is_cpu(&ds->ports[reg]))
|
|
|
ds->enabled_port_mask |= 1 << reg;
|
|
|
}
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
-static int dsa_parse_member(struct device_node *np, u32 *tree, u32 *index)
|
|
|
+static int dsa_parse_member_dn(struct device_node *np, u32 *tree, u32 *index)
|
|
|
{
|
|
|
int err;
|
|
|
|
|
|
@@ -578,17 +583,19 @@ static struct device_node *dsa_get_ports(struct dsa_switch *ds,
|
|
|
return ports;
|
|
|
}
|
|
|
|
|
|
-static int _dsa_register_switch(struct dsa_switch *ds, struct device_node *np)
|
|
|
+static int _dsa_register_switch(struct dsa_switch *ds, struct device *dev)
|
|
|
{
|
|
|
- struct device_node *ports = dsa_get_ports(ds, np);
|
|
|
+ struct device_node *np = dev->of_node;
|
|
|
struct dsa_switch_tree *dst;
|
|
|
+ struct device_node *ports;
|
|
|
u32 tree, index;
|
|
|
int i, err;
|
|
|
|
|
|
- err = dsa_parse_member(np, &tree, &index);
|
|
|
+ err = dsa_parse_member_dn(np, &tree, &index);
|
|
|
if (err)
|
|
|
return err;
|
|
|
|
|
|
+ ports = dsa_get_ports(ds, np);
|
|
|
if (IS_ERR(ports))
|
|
|
return PTR_ERR(ports);
|
|
|
|
|
|
@@ -659,12 +666,12 @@ out:
|
|
|
return err;
|
|
|
}
|
|
|
|
|
|
-int dsa_register_switch(struct dsa_switch *ds, struct device_node *np)
|
|
|
+int dsa_register_switch(struct dsa_switch *ds, struct device *dev)
|
|
|
{
|
|
|
int err;
|
|
|
|
|
|
mutex_lock(&dsa2_mutex);
|
|
|
- err = _dsa_register_switch(ds, np);
|
|
|
+ err = _dsa_register_switch(ds, dev);
|
|
|
mutex_unlock(&dsa2_mutex);
|
|
|
|
|
|
return err;
|