Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 1 | /* |
| 2 | * net/dsa/dsa.c - Hardware switch handling |
Lennert Buytenhek | e84665c | 2009-03-20 09:52:09 +0000 | [diff] [blame] | 3 | * Copyright (c) 2008-2009 Marvell Semiconductor |
Florian Fainelli | 5e95329b | 2013-03-22 10:50:50 +0000 | [diff] [blame] | 4 | * Copyright (c) 2013 Florian Fainelli <florian@openwrt.org> |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | */ |
| 11 | |
Guenter Roeck | 51579c3 | 2014-10-29 10:44:58 -0700 | [diff] [blame] | 12 | #include <linux/ctype.h> |
| 13 | #include <linux/device.h> |
| 14 | #include <linux/hwmon.h> |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 15 | #include <linux/list.h> |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 16 | #include <linux/platform_device.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 17 | #include <linux/slab.h> |
Paul Gortmaker | 3a9a231 | 2011-05-27 09:12:25 -0400 | [diff] [blame] | 18 | #include <linux/module.h> |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 19 | #include <net/dsa.h> |
Florian Fainelli | 5e95329b | 2013-03-22 10:50:50 +0000 | [diff] [blame] | 20 | #include <linux/of.h> |
| 21 | #include <linux/of_mdio.h> |
| 22 | #include <linux/of_platform.h> |
Florian Fainelli | 769a020 | 2015-03-09 14:31:21 -0700 | [diff] [blame] | 23 | #include <linux/of_net.h> |
Guenter Roeck | 51579c3 | 2014-10-29 10:44:58 -0700 | [diff] [blame] | 24 | #include <linux/sysfs.h> |
Neil Armstrong | cbc5d90 | 2015-10-06 15:40:32 +0100 | [diff] [blame] | 25 | #include <linux/phy_fixed.h> |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 26 | #include "dsa_priv.h" |
| 27 | |
| 28 | char dsa_driver_version[] = "0.1"; |
| 29 | |
| 30 | |
| 31 | /* switch driver registration ***********************************************/ |
| 32 | static DEFINE_MUTEX(dsa_switch_drivers_mutex); |
| 33 | static LIST_HEAD(dsa_switch_drivers); |
| 34 | |
| 35 | void register_switch_driver(struct dsa_switch_driver *drv) |
| 36 | { |
| 37 | mutex_lock(&dsa_switch_drivers_mutex); |
| 38 | list_add_tail(&drv->list, &dsa_switch_drivers); |
| 39 | mutex_unlock(&dsa_switch_drivers_mutex); |
| 40 | } |
Ben Hutchings | ad293b8 | 2011-11-25 14:34:07 +0000 | [diff] [blame] | 41 | EXPORT_SYMBOL_GPL(register_switch_driver); |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 42 | |
| 43 | void unregister_switch_driver(struct dsa_switch_driver *drv) |
| 44 | { |
| 45 | mutex_lock(&dsa_switch_drivers_mutex); |
| 46 | list_del_init(&drv->list); |
| 47 | mutex_unlock(&dsa_switch_drivers_mutex); |
| 48 | } |
Ben Hutchings | ad293b8 | 2011-11-25 14:34:07 +0000 | [diff] [blame] | 49 | EXPORT_SYMBOL_GPL(unregister_switch_driver); |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 50 | |
| 51 | static struct dsa_switch_driver * |
Alexander Duyck | b4d2394 | 2014-09-15 13:00:27 -0400 | [diff] [blame] | 52 | dsa_switch_probe(struct device *host_dev, int sw_addr, char **_name) |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 53 | { |
| 54 | struct dsa_switch_driver *ret; |
| 55 | struct list_head *list; |
| 56 | char *name; |
| 57 | |
| 58 | ret = NULL; |
| 59 | name = NULL; |
| 60 | |
| 61 | mutex_lock(&dsa_switch_drivers_mutex); |
| 62 | list_for_each(list, &dsa_switch_drivers) { |
| 63 | struct dsa_switch_driver *drv; |
| 64 | |
| 65 | drv = list_entry(list, struct dsa_switch_driver, list); |
| 66 | |
Alexander Duyck | b4d2394 | 2014-09-15 13:00:27 -0400 | [diff] [blame] | 67 | name = drv->probe(host_dev, sw_addr); |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 68 | if (name != NULL) { |
| 69 | ret = drv; |
| 70 | break; |
| 71 | } |
| 72 | } |
| 73 | mutex_unlock(&dsa_switch_drivers_mutex); |
| 74 | |
| 75 | *_name = name; |
| 76 | |
| 77 | return ret; |
| 78 | } |
| 79 | |
Guenter Roeck | 51579c3 | 2014-10-29 10:44:58 -0700 | [diff] [blame] | 80 | /* hwmon support ************************************************************/ |
| 81 | |
| 82 | #ifdef CONFIG_NET_DSA_HWMON |
| 83 | |
| 84 | static ssize_t temp1_input_show(struct device *dev, |
| 85 | struct device_attribute *attr, char *buf) |
| 86 | { |
| 87 | struct dsa_switch *ds = dev_get_drvdata(dev); |
| 88 | int temp, ret; |
| 89 | |
| 90 | ret = ds->drv->get_temp(ds, &temp); |
| 91 | if (ret < 0) |
| 92 | return ret; |
| 93 | |
| 94 | return sprintf(buf, "%d\n", temp * 1000); |
| 95 | } |
| 96 | static DEVICE_ATTR_RO(temp1_input); |
| 97 | |
| 98 | static ssize_t temp1_max_show(struct device *dev, |
| 99 | struct device_attribute *attr, char *buf) |
| 100 | { |
| 101 | struct dsa_switch *ds = dev_get_drvdata(dev); |
| 102 | int temp, ret; |
| 103 | |
| 104 | ret = ds->drv->get_temp_limit(ds, &temp); |
| 105 | if (ret < 0) |
| 106 | return ret; |
| 107 | |
| 108 | return sprintf(buf, "%d\n", temp * 1000); |
| 109 | } |
| 110 | |
| 111 | static ssize_t temp1_max_store(struct device *dev, |
| 112 | struct device_attribute *attr, const char *buf, |
| 113 | size_t count) |
| 114 | { |
| 115 | struct dsa_switch *ds = dev_get_drvdata(dev); |
| 116 | int temp, ret; |
| 117 | |
| 118 | ret = kstrtoint(buf, 0, &temp); |
| 119 | if (ret < 0) |
| 120 | return ret; |
| 121 | |
| 122 | ret = ds->drv->set_temp_limit(ds, DIV_ROUND_CLOSEST(temp, 1000)); |
| 123 | if (ret < 0) |
| 124 | return ret; |
| 125 | |
| 126 | return count; |
| 127 | } |
Vivien Didelot | e3122b7 | 2015-04-17 15:12:25 -0400 | [diff] [blame] | 128 | static DEVICE_ATTR_RW(temp1_max); |
Guenter Roeck | 51579c3 | 2014-10-29 10:44:58 -0700 | [diff] [blame] | 129 | |
| 130 | static ssize_t temp1_max_alarm_show(struct device *dev, |
| 131 | struct device_attribute *attr, char *buf) |
| 132 | { |
| 133 | struct dsa_switch *ds = dev_get_drvdata(dev); |
| 134 | bool alarm; |
| 135 | int ret; |
| 136 | |
| 137 | ret = ds->drv->get_temp_alarm(ds, &alarm); |
| 138 | if (ret < 0) |
| 139 | return ret; |
| 140 | |
| 141 | return sprintf(buf, "%d\n", alarm); |
| 142 | } |
| 143 | static DEVICE_ATTR_RO(temp1_max_alarm); |
| 144 | |
| 145 | static struct attribute *dsa_hwmon_attrs[] = { |
| 146 | &dev_attr_temp1_input.attr, /* 0 */ |
| 147 | &dev_attr_temp1_max.attr, /* 1 */ |
| 148 | &dev_attr_temp1_max_alarm.attr, /* 2 */ |
| 149 | NULL |
| 150 | }; |
| 151 | |
| 152 | static umode_t dsa_hwmon_attrs_visible(struct kobject *kobj, |
| 153 | struct attribute *attr, int index) |
| 154 | { |
| 155 | struct device *dev = container_of(kobj, struct device, kobj); |
| 156 | struct dsa_switch *ds = dev_get_drvdata(dev); |
| 157 | struct dsa_switch_driver *drv = ds->drv; |
| 158 | umode_t mode = attr->mode; |
| 159 | |
| 160 | if (index == 1) { |
| 161 | if (!drv->get_temp_limit) |
| 162 | mode = 0; |
Vivien Didelot | e3122b7 | 2015-04-17 15:12:25 -0400 | [diff] [blame] | 163 | else if (!drv->set_temp_limit) |
| 164 | mode &= ~S_IWUSR; |
Guenter Roeck | 51579c3 | 2014-10-29 10:44:58 -0700 | [diff] [blame] | 165 | } else if (index == 2 && !drv->get_temp_alarm) { |
| 166 | mode = 0; |
| 167 | } |
| 168 | return mode; |
| 169 | } |
| 170 | |
| 171 | static const struct attribute_group dsa_hwmon_group = { |
| 172 | .attrs = dsa_hwmon_attrs, |
| 173 | .is_visible = dsa_hwmon_attrs_visible, |
| 174 | }; |
| 175 | __ATTRIBUTE_GROUPS(dsa_hwmon); |
| 176 | |
| 177 | #endif /* CONFIG_NET_DSA_HWMON */ |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 178 | |
| 179 | /* basic switch operations **************************************************/ |
Andrew Lunn | 39b0c70 | 2015-08-31 15:56:49 +0200 | [diff] [blame] | 180 | static int dsa_cpu_dsa_setup(struct dsa_switch *ds, struct net_device *master) |
| 181 | { |
| 182 | struct dsa_chip_data *cd = ds->pd; |
| 183 | struct device_node *port_dn; |
| 184 | struct phy_device *phydev; |
Andrew Lunn | e448534 | 2015-08-31 15:56:50 +0200 | [diff] [blame] | 185 | int ret, port, mode; |
Andrew Lunn | 39b0c70 | 2015-08-31 15:56:49 +0200 | [diff] [blame] | 186 | |
| 187 | for (port = 0; port < DSA_MAX_PORTS; port++) { |
| 188 | if (!(dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))) |
| 189 | continue; |
| 190 | |
| 191 | port_dn = cd->port_dn[port]; |
| 192 | if (of_phy_is_fixed_link(port_dn)) { |
| 193 | ret = of_phy_register_fixed_link(port_dn); |
| 194 | if (ret) { |
| 195 | netdev_err(master, |
| 196 | "failed to register fixed PHY\n"); |
| 197 | return ret; |
| 198 | } |
| 199 | phydev = of_phy_find_device(port_dn); |
Andrew Lunn | e448534 | 2015-08-31 15:56:50 +0200 | [diff] [blame] | 200 | |
| 201 | mode = of_get_phy_mode(port_dn); |
| 202 | if (mode < 0) |
| 203 | mode = PHY_INTERFACE_MODE_NA; |
| 204 | phydev->interface = mode; |
| 205 | |
Andrew Lunn | 39b0c70 | 2015-08-31 15:56:49 +0200 | [diff] [blame] | 206 | genphy_config_init(phydev); |
| 207 | genphy_read_status(phydev); |
| 208 | if (ds->drv->adjust_link) |
| 209 | ds->drv->adjust_link(ds, port, phydev); |
| 210 | } |
| 211 | } |
| 212 | return 0; |
| 213 | } |
| 214 | |
Florian Fainelli | df19719 | 2015-03-05 12:35:06 -0800 | [diff] [blame] | 215 | static int dsa_switch_setup_one(struct dsa_switch *ds, struct device *parent) |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 216 | { |
Florian Fainelli | df19719 | 2015-03-05 12:35:06 -0800 | [diff] [blame] | 217 | struct dsa_switch_driver *drv = ds->drv; |
| 218 | struct dsa_switch_tree *dst = ds->dst; |
| 219 | struct dsa_chip_data *pd = ds->pd; |
Florian Fainelli | f9bf5a2 | 2013-01-21 09:58:51 +0000 | [diff] [blame] | 220 | bool valid_name_found = false; |
Florian Fainelli | df19719 | 2015-03-05 12:35:06 -0800 | [diff] [blame] | 221 | int index = ds->index; |
| 222 | int i, ret; |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 223 | |
| 224 | /* |
| 225 | * Validate supplied switch configuration. |
| 226 | */ |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 227 | for (i = 0; i < DSA_MAX_PORTS; i++) { |
| 228 | char *name; |
| 229 | |
| 230 | name = pd->port_names[i]; |
| 231 | if (name == NULL) |
| 232 | continue; |
| 233 | |
| 234 | if (!strcmp(name, "cpu")) { |
Lennert Buytenhek | e84665c | 2009-03-20 09:52:09 +0000 | [diff] [blame] | 235 | if (dst->cpu_switch != -1) { |
Joe Perches | a2ae600 | 2014-11-09 16:32:46 -0800 | [diff] [blame] | 236 | netdev_err(dst->master_netdev, |
| 237 | "multiple cpu ports?!\n"); |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 238 | ret = -EINVAL; |
| 239 | goto out; |
| 240 | } |
Lennert Buytenhek | e84665c | 2009-03-20 09:52:09 +0000 | [diff] [blame] | 241 | dst->cpu_switch = index; |
| 242 | dst->cpu_port = i; |
| 243 | } else if (!strcmp(name, "dsa")) { |
| 244 | ds->dsa_port_mask |= 1 << i; |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 245 | } else { |
Lennert Buytenhek | e84665c | 2009-03-20 09:52:09 +0000 | [diff] [blame] | 246 | ds->phys_port_mask |= 1 << i; |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 247 | } |
Florian Fainelli | f9bf5a2 | 2013-01-21 09:58:51 +0000 | [diff] [blame] | 248 | valid_name_found = true; |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 249 | } |
| 250 | |
Florian Fainelli | f9bf5a2 | 2013-01-21 09:58:51 +0000 | [diff] [blame] | 251 | if (!valid_name_found && i == DSA_MAX_PORTS) { |
| 252 | ret = -EINVAL; |
| 253 | goto out; |
| 254 | } |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 255 | |
Florian Fainelli | 0d8bcdd | 2014-08-27 17:04:51 -0700 | [diff] [blame] | 256 | /* Make the built-in MII bus mask match the number of ports, |
| 257 | * switch drivers can override this later |
| 258 | */ |
| 259 | ds->phys_mii_mask = ds->phys_port_mask; |
| 260 | |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 261 | /* |
Lennert Buytenhek | e84665c | 2009-03-20 09:52:09 +0000 | [diff] [blame] | 262 | * If the CPU connects to this switch, set the switch tree |
| 263 | * tagging protocol to the preferred tagging format of this |
| 264 | * switch. |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 265 | */ |
Alexander Duyck | 5075314 | 2014-09-15 13:00:19 -0400 | [diff] [blame] | 266 | if (dst->cpu_switch == index) { |
Florian Fainelli | 5929903 | 2015-03-05 12:35:07 -0800 | [diff] [blame] | 267 | switch (ds->tag_protocol) { |
Alexander Duyck | 5075314 | 2014-09-15 13:00:19 -0400 | [diff] [blame] | 268 | #ifdef CONFIG_NET_DSA_TAG_DSA |
| 269 | case DSA_TAG_PROTO_DSA: |
| 270 | dst->rcv = dsa_netdev_ops.rcv; |
| 271 | break; |
| 272 | #endif |
| 273 | #ifdef CONFIG_NET_DSA_TAG_EDSA |
| 274 | case DSA_TAG_PROTO_EDSA: |
| 275 | dst->rcv = edsa_netdev_ops.rcv; |
| 276 | break; |
| 277 | #endif |
| 278 | #ifdef CONFIG_NET_DSA_TAG_TRAILER |
| 279 | case DSA_TAG_PROTO_TRAILER: |
| 280 | dst->rcv = trailer_netdev_ops.rcv; |
| 281 | break; |
| 282 | #endif |
| 283 | #ifdef CONFIG_NET_DSA_TAG_BRCM |
| 284 | case DSA_TAG_PROTO_BRCM: |
| 285 | dst->rcv = brcm_netdev_ops.rcv; |
| 286 | break; |
| 287 | #endif |
Andrew Lunn | ae43928 | 2014-10-24 23:44:04 +0200 | [diff] [blame] | 288 | case DSA_TAG_PROTO_NONE: |
Alexander Duyck | 5075314 | 2014-09-15 13:00:19 -0400 | [diff] [blame] | 289 | break; |
Andrew Lunn | ae43928 | 2014-10-24 23:44:04 +0200 | [diff] [blame] | 290 | default: |
| 291 | ret = -ENOPROTOOPT; |
| 292 | goto out; |
Alexander Duyck | 5075314 | 2014-09-15 13:00:19 -0400 | [diff] [blame] | 293 | } |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 294 | |
Florian Fainelli | 5929903 | 2015-03-05 12:35:07 -0800 | [diff] [blame] | 295 | dst->tag_protocol = ds->tag_protocol; |
Alexander Duyck | 5075314 | 2014-09-15 13:00:19 -0400 | [diff] [blame] | 296 | } |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 297 | |
| 298 | /* |
| 299 | * Do basic register setup. |
| 300 | */ |
| 301 | ret = drv->setup(ds); |
| 302 | if (ret < 0) |
| 303 | goto out; |
| 304 | |
Lennert Buytenhek | e84665c | 2009-03-20 09:52:09 +0000 | [diff] [blame] | 305 | ret = drv->set_addr(ds, dst->master_netdev->dev_addr); |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 306 | if (ret < 0) |
| 307 | goto out; |
| 308 | |
Neil Armstrong | d4ac35d | 2015-10-06 15:40:37 +0100 | [diff] [blame] | 309 | ds->slave_mii_bus = devm_mdiobus_alloc(parent); |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 310 | if (ds->slave_mii_bus == NULL) { |
| 311 | ret = -ENOMEM; |
| 312 | goto out; |
| 313 | } |
| 314 | dsa_slave_mii_bus_init(ds); |
| 315 | |
| 316 | ret = mdiobus_register(ds->slave_mii_bus); |
| 317 | if (ret < 0) |
Neil Armstrong | d4ac35d | 2015-10-06 15:40:37 +0100 | [diff] [blame] | 318 | goto out; |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 319 | |
| 320 | |
| 321 | /* |
| 322 | * Create network devices for physical switch ports. |
| 323 | */ |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 324 | for (i = 0; i < DSA_MAX_PORTS; i++) { |
Lennert Buytenhek | e84665c | 2009-03-20 09:52:09 +0000 | [diff] [blame] | 325 | if (!(ds->phys_port_mask & (1 << i))) |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 326 | continue; |
| 327 | |
Guenter Roeck | d87d6f4 | 2015-02-24 13:15:32 -0800 | [diff] [blame] | 328 | ret = dsa_slave_create(ds, parent, i, pd->port_names[i]); |
| 329 | if (ret < 0) { |
Joe Perches | a2ae600 | 2014-11-09 16:32:46 -0800 | [diff] [blame] | 330 | netdev_err(dst->master_netdev, "[%d]: can't create dsa slave device for port %d(%s)\n", |
| 331 | index, i, pd->port_names[i]); |
Guenter Roeck | d87d6f4 | 2015-02-24 13:15:32 -0800 | [diff] [blame] | 332 | ret = 0; |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 333 | } |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 334 | } |
| 335 | |
Andrew Lunn | 39b0c70 | 2015-08-31 15:56:49 +0200 | [diff] [blame] | 336 | /* Perform configuration of the CPU and DSA ports */ |
| 337 | ret = dsa_cpu_dsa_setup(ds, dst->master_netdev); |
| 338 | if (ret < 0) { |
| 339 | netdev_err(dst->master_netdev, "[%d] : can't configure CPU and DSA ports\n", |
| 340 | index); |
| 341 | ret = 0; |
| 342 | } |
| 343 | |
Guenter Roeck | 51579c3 | 2014-10-29 10:44:58 -0700 | [diff] [blame] | 344 | #ifdef CONFIG_NET_DSA_HWMON |
| 345 | /* If the switch provides a temperature sensor, |
| 346 | * register with hardware monitoring subsystem. |
| 347 | * Treat registration error as non-fatal and ignore it. |
| 348 | */ |
| 349 | if (drv->get_temp) { |
| 350 | const char *netname = netdev_name(dst->master_netdev); |
| 351 | char hname[IFNAMSIZ + 1]; |
| 352 | int i, j; |
| 353 | |
| 354 | /* Create valid hwmon 'name' attribute */ |
| 355 | for (i = j = 0; i < IFNAMSIZ && netname[i]; i++) { |
| 356 | if (isalnum(netname[i])) |
| 357 | hname[j++] = netname[i]; |
| 358 | } |
| 359 | hname[j] = '\0'; |
| 360 | scnprintf(ds->hwmon_name, sizeof(ds->hwmon_name), "%s_dsa%d", |
| 361 | hname, index); |
| 362 | ds->hwmon_dev = hwmon_device_register_with_groups(NULL, |
| 363 | ds->hwmon_name, ds, dsa_hwmon_groups); |
| 364 | if (IS_ERR(ds->hwmon_dev)) |
| 365 | ds->hwmon_dev = NULL; |
| 366 | } |
| 367 | #endif /* CONFIG_NET_DSA_HWMON */ |
| 368 | |
Florian Fainelli | df19719 | 2015-03-05 12:35:06 -0800 | [diff] [blame] | 369 | return ret; |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 370 | |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 371 | out: |
Florian Fainelli | df19719 | 2015-03-05 12:35:06 -0800 | [diff] [blame] | 372 | return ret; |
| 373 | } |
| 374 | |
| 375 | static struct dsa_switch * |
| 376 | dsa_switch_setup(struct dsa_switch_tree *dst, int index, |
| 377 | struct device *parent, struct device *host_dev) |
| 378 | { |
| 379 | struct dsa_chip_data *pd = dst->pd->chip + index; |
| 380 | struct dsa_switch_driver *drv; |
| 381 | struct dsa_switch *ds; |
| 382 | int ret; |
| 383 | char *name; |
| 384 | |
| 385 | /* |
| 386 | * Probe for switch model. |
| 387 | */ |
| 388 | drv = dsa_switch_probe(host_dev, pd->sw_addr, &name); |
| 389 | if (drv == NULL) { |
| 390 | netdev_err(dst->master_netdev, "[%d]: could not detect attached switch\n", |
| 391 | index); |
| 392 | return ERR_PTR(-EINVAL); |
| 393 | } |
| 394 | netdev_info(dst->master_netdev, "[%d]: detected a %s switch\n", |
| 395 | index, name); |
| 396 | |
| 397 | |
| 398 | /* |
| 399 | * Allocate and initialise switch state. |
| 400 | */ |
Neil Armstrong | d4ac35d | 2015-10-06 15:40:37 +0100 | [diff] [blame] | 401 | ds = devm_kzalloc(parent, sizeof(*ds) + drv->priv_size, GFP_KERNEL); |
Florian Fainelli | df19719 | 2015-03-05 12:35:06 -0800 | [diff] [blame] | 402 | if (ds == NULL) |
Florian Fainelli | 2459534 | 2015-05-29 10:29:46 -0700 | [diff] [blame] | 403 | return ERR_PTR(-ENOMEM); |
Florian Fainelli | df19719 | 2015-03-05 12:35:06 -0800 | [diff] [blame] | 404 | |
| 405 | ds->dst = dst; |
| 406 | ds->index = index; |
| 407 | ds->pd = pd; |
| 408 | ds->drv = drv; |
Florian Fainelli | 5929903 | 2015-03-05 12:35:07 -0800 | [diff] [blame] | 409 | ds->tag_protocol = drv->tag_protocol; |
Florian Fainelli | df19719 | 2015-03-05 12:35:06 -0800 | [diff] [blame] | 410 | ds->master_dev = host_dev; |
| 411 | |
| 412 | ret = dsa_switch_setup_one(ds, parent); |
| 413 | if (ret) |
Florian Fainelli | 2459534 | 2015-05-29 10:29:46 -0700 | [diff] [blame] | 414 | return ERR_PTR(ret); |
Florian Fainelli | df19719 | 2015-03-05 12:35:06 -0800 | [diff] [blame] | 415 | |
| 416 | return ds; |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | static void dsa_switch_destroy(struct dsa_switch *ds) |
| 420 | { |
Neil Armstrong | cbc5d90 | 2015-10-06 15:40:32 +0100 | [diff] [blame] | 421 | struct device_node *port_dn; |
| 422 | struct phy_device *phydev; |
| 423 | struct dsa_chip_data *cd = ds->pd; |
| 424 | int port; |
| 425 | |
Guenter Roeck | 51579c3 | 2014-10-29 10:44:58 -0700 | [diff] [blame] | 426 | #ifdef CONFIG_NET_DSA_HWMON |
| 427 | if (ds->hwmon_dev) |
| 428 | hwmon_device_unregister(ds->hwmon_dev); |
| 429 | #endif |
Neil Armstrong | cbc5d90 | 2015-10-06 15:40:32 +0100 | [diff] [blame] | 430 | |
| 431 | /* Disable configuration of the CPU and DSA ports */ |
| 432 | for (port = 0; port < DSA_MAX_PORTS; port++) { |
| 433 | if (!(dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))) |
| 434 | continue; |
| 435 | |
| 436 | port_dn = cd->port_dn[port]; |
| 437 | if (of_phy_is_fixed_link(port_dn)) { |
| 438 | phydev = of_phy_find_device(port_dn); |
| 439 | if (phydev) { |
| 440 | int addr = phydev->addr; |
| 441 | |
| 442 | phy_device_free(phydev); |
| 443 | of_node_put(port_dn); |
| 444 | fixed_phy_del(addr); |
| 445 | } |
| 446 | } |
| 447 | } |
| 448 | |
| 449 | /* Destroy network devices for physical switch ports. */ |
| 450 | for (port = 0; port < DSA_MAX_PORTS; port++) { |
| 451 | if (!(ds->phys_port_mask & (1 << port))) |
| 452 | continue; |
| 453 | |
| 454 | if (!ds->ports[port]) |
| 455 | continue; |
| 456 | |
| 457 | unregister_netdev(ds->ports[port]); |
| 458 | free_netdev(ds->ports[port]); |
| 459 | } |
| 460 | |
Neil Armstrong | e410ddb | 2015-10-06 15:40:25 +0100 | [diff] [blame] | 461 | mdiobus_unregister(ds->slave_mii_bus); |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 462 | } |
| 463 | |
Thierry Reding | e506d40 | 2014-10-01 13:59:00 +0200 | [diff] [blame] | 464 | #ifdef CONFIG_PM_SLEEP |
Florian Fainelli | 2446254 | 2014-09-18 17:31:22 -0700 | [diff] [blame] | 465 | static int dsa_switch_suspend(struct dsa_switch *ds) |
| 466 | { |
| 467 | int i, ret = 0; |
| 468 | |
| 469 | /* Suspend slave network devices */ |
| 470 | for (i = 0; i < DSA_MAX_PORTS; i++) { |
Guenter Roeck | d79d210 | 2015-02-24 23:02:02 -0800 | [diff] [blame] | 471 | if (!dsa_is_port_initialized(ds, i)) |
Florian Fainelli | 2446254 | 2014-09-18 17:31:22 -0700 | [diff] [blame] | 472 | continue; |
| 473 | |
| 474 | ret = dsa_slave_suspend(ds->ports[i]); |
| 475 | if (ret) |
| 476 | return ret; |
| 477 | } |
| 478 | |
| 479 | if (ds->drv->suspend) |
| 480 | ret = ds->drv->suspend(ds); |
| 481 | |
| 482 | return ret; |
| 483 | } |
| 484 | |
| 485 | static int dsa_switch_resume(struct dsa_switch *ds) |
| 486 | { |
| 487 | int i, ret = 0; |
| 488 | |
| 489 | if (ds->drv->resume) |
| 490 | ret = ds->drv->resume(ds); |
| 491 | |
| 492 | if (ret) |
| 493 | return ret; |
| 494 | |
| 495 | /* Resume slave network devices */ |
| 496 | for (i = 0; i < DSA_MAX_PORTS; i++) { |
Guenter Roeck | d79d210 | 2015-02-24 23:02:02 -0800 | [diff] [blame] | 497 | if (!dsa_is_port_initialized(ds, i)) |
Florian Fainelli | 2446254 | 2014-09-18 17:31:22 -0700 | [diff] [blame] | 498 | continue; |
| 499 | |
| 500 | ret = dsa_slave_resume(ds->ports[i]); |
| 501 | if (ret) |
| 502 | return ret; |
| 503 | } |
| 504 | |
| 505 | return 0; |
| 506 | } |
Thierry Reding | e506d40 | 2014-10-01 13:59:00 +0200 | [diff] [blame] | 507 | #endif |
Florian Fainelli | 2446254 | 2014-09-18 17:31:22 -0700 | [diff] [blame] | 508 | |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 509 | |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 510 | /* link polling *************************************************************/ |
| 511 | static void dsa_link_poll_work(struct work_struct *ugly) |
| 512 | { |
Lennert Buytenhek | e84665c | 2009-03-20 09:52:09 +0000 | [diff] [blame] | 513 | struct dsa_switch_tree *dst; |
| 514 | int i; |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 515 | |
Lennert Buytenhek | e84665c | 2009-03-20 09:52:09 +0000 | [diff] [blame] | 516 | dst = container_of(ugly, struct dsa_switch_tree, link_poll_work); |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 517 | |
Lennert Buytenhek | e84665c | 2009-03-20 09:52:09 +0000 | [diff] [blame] | 518 | for (i = 0; i < dst->pd->nr_chips; i++) { |
| 519 | struct dsa_switch *ds = dst->ds[i]; |
| 520 | |
| 521 | if (ds != NULL && ds->drv->poll_link != NULL) |
| 522 | ds->drv->poll_link(ds); |
| 523 | } |
| 524 | |
| 525 | mod_timer(&dst->link_poll_timer, round_jiffies(jiffies + HZ)); |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 526 | } |
| 527 | |
Lennert Buytenhek | e84665c | 2009-03-20 09:52:09 +0000 | [diff] [blame] | 528 | static void dsa_link_poll_timer(unsigned long _dst) |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 529 | { |
Lennert Buytenhek | e84665c | 2009-03-20 09:52:09 +0000 | [diff] [blame] | 530 | struct dsa_switch_tree *dst = (void *)_dst; |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 531 | |
Lennert Buytenhek | e84665c | 2009-03-20 09:52:09 +0000 | [diff] [blame] | 532 | schedule_work(&dst->link_poll_work); |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 533 | } |
| 534 | |
| 535 | |
| 536 | /* platform driver init and cleanup *****************************************/ |
| 537 | static int dev_is_class(struct device *dev, void *class) |
| 538 | { |
| 539 | if (dev->class != NULL && !strcmp(dev->class->name, class)) |
| 540 | return 1; |
| 541 | |
| 542 | return 0; |
| 543 | } |
| 544 | |
| 545 | static struct device *dev_find_class(struct device *parent, char *class) |
| 546 | { |
| 547 | if (dev_is_class(parent, class)) { |
| 548 | get_device(parent); |
| 549 | return parent; |
| 550 | } |
| 551 | |
| 552 | return device_find_child(parent, class, dev_is_class); |
| 553 | } |
| 554 | |
Alexander Duyck | b4d2394 | 2014-09-15 13:00:27 -0400 | [diff] [blame] | 555 | struct mii_bus *dsa_host_dev_to_mii_bus(struct device *dev) |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 556 | { |
| 557 | struct device *d; |
| 558 | |
| 559 | d = dev_find_class(dev, "mdio_bus"); |
| 560 | if (d != NULL) { |
| 561 | struct mii_bus *bus; |
| 562 | |
| 563 | bus = to_mii_bus(d); |
| 564 | put_device(d); |
| 565 | |
| 566 | return bus; |
| 567 | } |
| 568 | |
| 569 | return NULL; |
| 570 | } |
Alexander Duyck | b4d2394 | 2014-09-15 13:00:27 -0400 | [diff] [blame] | 571 | EXPORT_SYMBOL_GPL(dsa_host_dev_to_mii_bus); |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 572 | |
| 573 | static struct net_device *dev_to_net_device(struct device *dev) |
| 574 | { |
| 575 | struct device *d; |
| 576 | |
| 577 | d = dev_find_class(dev, "net"); |
| 578 | if (d != NULL) { |
| 579 | struct net_device *nd; |
| 580 | |
| 581 | nd = to_net_dev(d); |
| 582 | dev_hold(nd); |
| 583 | put_device(d); |
| 584 | |
| 585 | return nd; |
| 586 | } |
| 587 | |
| 588 | return NULL; |
| 589 | } |
| 590 | |
Florian Fainelli | 5e95329b | 2013-03-22 10:50:50 +0000 | [diff] [blame] | 591 | #ifdef CONFIG_OF |
| 592 | static int dsa_of_setup_routing_table(struct dsa_platform_data *pd, |
| 593 | struct dsa_chip_data *cd, |
Pavel Nakonechny | 3030381 | 2015-04-05 00:46:21 +0300 | [diff] [blame] | 594 | int chip_index, int port_index, |
Florian Fainelli | 5e95329b | 2013-03-22 10:50:50 +0000 | [diff] [blame] | 595 | struct device_node *link) |
| 596 | { |
Florian Fainelli | 5e95329b | 2013-03-22 10:50:50 +0000 | [diff] [blame] | 597 | const __be32 *reg; |
Florian Fainelli | 5e95329b | 2013-03-22 10:50:50 +0000 | [diff] [blame] | 598 | int link_sw_addr; |
| 599 | struct device_node *parent_sw; |
| 600 | int len; |
| 601 | |
| 602 | parent_sw = of_get_parent(link); |
| 603 | if (!parent_sw) |
| 604 | return -EINVAL; |
| 605 | |
| 606 | reg = of_get_property(parent_sw, "reg", &len); |
| 607 | if (!reg || (len != sizeof(*reg) * 2)) |
| 608 | return -EINVAL; |
| 609 | |
Pavel Nakonechny | 3030381 | 2015-04-05 00:46:21 +0300 | [diff] [blame] | 610 | /* |
| 611 | * Get the destination switch number from the second field of its 'reg' |
| 612 | * property, i.e. for "reg = <0x19 1>" sw_addr is '1'. |
| 613 | */ |
Florian Fainelli | 5e95329b | 2013-03-22 10:50:50 +0000 | [diff] [blame] | 614 | link_sw_addr = be32_to_cpup(reg + 1); |
| 615 | |
| 616 | if (link_sw_addr >= pd->nr_chips) |
| 617 | return -EINVAL; |
| 618 | |
| 619 | /* First time routing table allocation */ |
| 620 | if (!cd->rtable) { |
Fabian Frederick | 5bc4b46 | 2014-11-14 19:36:42 +0100 | [diff] [blame] | 621 | cd->rtable = kmalloc_array(pd->nr_chips, sizeof(s8), |
| 622 | GFP_KERNEL); |
Florian Fainelli | 5e95329b | 2013-03-22 10:50:50 +0000 | [diff] [blame] | 623 | if (!cd->rtable) |
| 624 | return -ENOMEM; |
| 625 | |
| 626 | /* default to no valid uplink/downlink */ |
| 627 | memset(cd->rtable, -1, pd->nr_chips * sizeof(s8)); |
| 628 | } |
| 629 | |
Pavel Nakonechny | 3030381 | 2015-04-05 00:46:21 +0300 | [diff] [blame] | 630 | cd->rtable[link_sw_addr] = port_index; |
Florian Fainelli | 5e95329b | 2013-03-22 10:50:50 +0000 | [diff] [blame] | 631 | |
| 632 | return 0; |
Florian Fainelli | 5e95329b | 2013-03-22 10:50:50 +0000 | [diff] [blame] | 633 | } |
| 634 | |
Andrew Lunn | 1e72e6f | 2015-08-17 23:52:50 +0200 | [diff] [blame] | 635 | static int dsa_of_probe_links(struct dsa_platform_data *pd, |
| 636 | struct dsa_chip_data *cd, |
| 637 | int chip_index, int port_index, |
| 638 | struct device_node *port, |
| 639 | const char *port_name) |
| 640 | { |
| 641 | struct device_node *link; |
| 642 | int link_index; |
| 643 | int ret; |
| 644 | |
| 645 | for (link_index = 0;; link_index++) { |
| 646 | link = of_parse_phandle(port, "link", link_index); |
| 647 | if (!link) |
| 648 | break; |
| 649 | |
| 650 | if (!strcmp(port_name, "dsa") && pd->nr_chips > 1) { |
| 651 | ret = dsa_of_setup_routing_table(pd, cd, chip_index, |
| 652 | port_index, link); |
| 653 | if (ret) |
| 654 | return ret; |
| 655 | } |
| 656 | } |
| 657 | return 0; |
| 658 | } |
| 659 | |
Florian Fainelli | 2116824 | 2013-03-25 05:03:39 +0000 | [diff] [blame] | 660 | static void dsa_of_free_platform_data(struct dsa_platform_data *pd) |
| 661 | { |
| 662 | int i; |
| 663 | int port_index; |
| 664 | |
| 665 | for (i = 0; i < pd->nr_chips; i++) { |
| 666 | port_index = 0; |
Florian Fainelli | 5f64a7d | 2013-03-25 05:03:40 +0000 | [diff] [blame] | 667 | while (port_index < DSA_MAX_PORTS) { |
Fabian Frederick | 1f74714 | 2014-06-23 19:32:47 +0200 | [diff] [blame] | 668 | kfree(pd->chip[i].port_names[port_index]); |
Florian Fainelli | 5f64a7d | 2013-03-25 05:03:40 +0000 | [diff] [blame] | 669 | port_index++; |
| 670 | } |
Florian Fainelli | 2116824 | 2013-03-25 05:03:39 +0000 | [diff] [blame] | 671 | kfree(pd->chip[i].rtable); |
Russell King | e496ae6 | 2015-09-24 20:35:57 +0100 | [diff] [blame] | 672 | |
| 673 | /* Drop our reference to the MDIO bus device */ |
| 674 | if (pd->chip[i].host_dev) |
| 675 | put_device(pd->chip[i].host_dev); |
Florian Fainelli | 2116824 | 2013-03-25 05:03:39 +0000 | [diff] [blame] | 676 | } |
| 677 | kfree(pd->chip); |
| 678 | } |
| 679 | |
Florian Fainelli | f1a26a0 | 2015-03-05 12:35:04 -0800 | [diff] [blame] | 680 | static int dsa_of_probe(struct device *dev) |
Florian Fainelli | 5e95329b | 2013-03-22 10:50:50 +0000 | [diff] [blame] | 681 | { |
Florian Fainelli | f1a26a0 | 2015-03-05 12:35:04 -0800 | [diff] [blame] | 682 | struct device_node *np = dev->of_node; |
Andrew Lunn | 1e72e6f | 2015-08-17 23:52:50 +0200 | [diff] [blame] | 683 | struct device_node *child, *mdio, *ethernet, *port; |
Andrew Lunn | 6bc6d0a | 2015-08-08 17:09:14 +0200 | [diff] [blame] | 684 | struct mii_bus *mdio_bus, *mdio_bus_switch; |
Florian Fainelli | 769a020 | 2015-03-09 14:31:21 -0700 | [diff] [blame] | 685 | struct net_device *ethernet_dev; |
Florian Fainelli | 5e95329b | 2013-03-22 10:50:50 +0000 | [diff] [blame] | 686 | struct dsa_platform_data *pd; |
| 687 | struct dsa_chip_data *cd; |
| 688 | const char *port_name; |
| 689 | int chip_index, port_index; |
| 690 | const unsigned int *sw_addr, *port_reg; |
Guenter Roeck | 6793abb | 2014-10-29 10:45:01 -0700 | [diff] [blame] | 691 | u32 eeprom_len; |
Florian Fainelli | 2116824 | 2013-03-25 05:03:39 +0000 | [diff] [blame] | 692 | int ret; |
Florian Fainelli | 5e95329b | 2013-03-22 10:50:50 +0000 | [diff] [blame] | 693 | |
| 694 | mdio = of_parse_phandle(np, "dsa,mii-bus", 0); |
| 695 | if (!mdio) |
| 696 | return -EINVAL; |
| 697 | |
| 698 | mdio_bus = of_mdio_find_bus(mdio); |
| 699 | if (!mdio_bus) |
Florian Fainelli | b324c07 | 2015-03-05 12:35:05 -0800 | [diff] [blame] | 700 | return -EPROBE_DEFER; |
Florian Fainelli | 5e95329b | 2013-03-22 10:50:50 +0000 | [diff] [blame] | 701 | |
| 702 | ethernet = of_parse_phandle(np, "dsa,ethernet", 0); |
Russell King | e496ae6 | 2015-09-24 20:35:57 +0100 | [diff] [blame] | 703 | if (!ethernet) { |
| 704 | ret = -EINVAL; |
| 705 | goto out_put_mdio; |
| 706 | } |
Florian Fainelli | 5e95329b | 2013-03-22 10:50:50 +0000 | [diff] [blame] | 707 | |
Florian Fainelli | 769a020 | 2015-03-09 14:31:21 -0700 | [diff] [blame] | 708 | ethernet_dev = of_find_net_device_by_node(ethernet); |
Russell King | e496ae6 | 2015-09-24 20:35:57 +0100 | [diff] [blame] | 709 | if (!ethernet_dev) { |
| 710 | ret = -EPROBE_DEFER; |
| 711 | goto out_put_mdio; |
| 712 | } |
Florian Fainelli | 5e95329b | 2013-03-22 10:50:50 +0000 | [diff] [blame] | 713 | |
| 714 | pd = kzalloc(sizeof(*pd), GFP_KERNEL); |
Russell King | e496ae6 | 2015-09-24 20:35:57 +0100 | [diff] [blame] | 715 | if (!pd) { |
| 716 | ret = -ENOMEM; |
Russell King | 9861f72 | 2015-09-24 20:36:33 +0100 | [diff] [blame] | 717 | goto out_put_ethernet; |
Russell King | e496ae6 | 2015-09-24 20:35:57 +0100 | [diff] [blame] | 718 | } |
Florian Fainelli | 5e95329b | 2013-03-22 10:50:50 +0000 | [diff] [blame] | 719 | |
Florian Fainelli | f1a26a0 | 2015-03-05 12:35:04 -0800 | [diff] [blame] | 720 | dev->platform_data = pd; |
Florian Fainelli | 769a020 | 2015-03-09 14:31:21 -0700 | [diff] [blame] | 721 | pd->of_netdev = ethernet_dev; |
Tobias Waldekranz | e04449f | 2015-02-05 14:54:09 +0100 | [diff] [blame] | 722 | pd->nr_chips = of_get_available_child_count(np); |
Florian Fainelli | 5e95329b | 2013-03-22 10:50:50 +0000 | [diff] [blame] | 723 | if (pd->nr_chips > DSA_MAX_SWITCHES) |
| 724 | pd->nr_chips = DSA_MAX_SWITCHES; |
| 725 | |
Fabian Frederick | 6f2aed6 | 2014-11-14 19:38:23 +0100 | [diff] [blame] | 726 | pd->chip = kcalloc(pd->nr_chips, sizeof(struct dsa_chip_data), |
| 727 | GFP_KERNEL); |
Florian Fainelli | 5e95329b | 2013-03-22 10:50:50 +0000 | [diff] [blame] | 728 | if (!pd->chip) { |
| 729 | ret = -ENOMEM; |
| 730 | goto out_free; |
| 731 | } |
| 732 | |
Fabian Godehardt | d1c0b47 | 2014-05-16 06:21:44 +0200 | [diff] [blame] | 733 | chip_index = -1; |
Florian Fainelli | 5e95329b | 2013-03-22 10:50:50 +0000 | [diff] [blame] | 734 | for_each_available_child_of_node(np, child) { |
Fabian Godehardt | d1c0b47 | 2014-05-16 06:21:44 +0200 | [diff] [blame] | 735 | chip_index++; |
Florian Fainelli | 5e95329b | 2013-03-22 10:50:50 +0000 | [diff] [blame] | 736 | cd = &pd->chip[chip_index]; |
| 737 | |
Florian Fainelli | fa981d9 | 2014-08-27 17:04:49 -0700 | [diff] [blame] | 738 | cd->of_node = child; |
Russell King | e496ae6 | 2015-09-24 20:35:57 +0100 | [diff] [blame] | 739 | |
| 740 | /* When assigning the host device, increment its refcount */ |
| 741 | cd->host_dev = get_device(&mdio_bus->dev); |
Florian Fainelli | 5e95329b | 2013-03-22 10:50:50 +0000 | [diff] [blame] | 742 | |
| 743 | sw_addr = of_get_property(child, "reg", NULL); |
| 744 | if (!sw_addr) |
| 745 | continue; |
| 746 | |
| 747 | cd->sw_addr = be32_to_cpup(sw_addr); |
Florian Fainelli | c8cf89f | 2015-07-11 18:02:11 -0700 | [diff] [blame] | 748 | if (cd->sw_addr >= PHY_MAX_ADDR) |
Florian Fainelli | 5e95329b | 2013-03-22 10:50:50 +0000 | [diff] [blame] | 749 | continue; |
| 750 | |
Guenter Roeck | 50d4964 | 2015-04-29 10:56:15 -0700 | [diff] [blame] | 751 | if (!of_property_read_u32(child, "eeprom-length", &eeprom_len)) |
Guenter Roeck | 6793abb | 2014-10-29 10:45:01 -0700 | [diff] [blame] | 752 | cd->eeprom_len = eeprom_len; |
| 753 | |
Andrew Lunn | 6bc6d0a | 2015-08-08 17:09:14 +0200 | [diff] [blame] | 754 | mdio = of_parse_phandle(child, "mii-bus", 0); |
| 755 | if (mdio) { |
| 756 | mdio_bus_switch = of_mdio_find_bus(mdio); |
| 757 | if (!mdio_bus_switch) { |
| 758 | ret = -EPROBE_DEFER; |
| 759 | goto out_free_chip; |
| 760 | } |
Russell King | e496ae6 | 2015-09-24 20:35:57 +0100 | [diff] [blame] | 761 | |
| 762 | /* Drop the mdio_bus device ref, replacing the host |
| 763 | * device with the mdio_bus_switch device, keeping |
| 764 | * the refcount from of_mdio_find_bus() above. |
| 765 | */ |
| 766 | put_device(cd->host_dev); |
Andrew Lunn | 6bc6d0a | 2015-08-08 17:09:14 +0200 | [diff] [blame] | 767 | cd->host_dev = &mdio_bus_switch->dev; |
| 768 | } |
| 769 | |
Florian Fainelli | 5e95329b | 2013-03-22 10:50:50 +0000 | [diff] [blame] | 770 | for_each_available_child_of_node(child, port) { |
| 771 | port_reg = of_get_property(port, "reg", NULL); |
| 772 | if (!port_reg) |
| 773 | continue; |
| 774 | |
| 775 | port_index = be32_to_cpup(port_reg); |
Florian Fainelli | 8f5063e | 2015-07-11 18:02:10 -0700 | [diff] [blame] | 776 | if (port_index >= DSA_MAX_PORTS) |
| 777 | break; |
Florian Fainelli | 5e95329b | 2013-03-22 10:50:50 +0000 | [diff] [blame] | 778 | |
| 779 | port_name = of_get_property(port, "label", NULL); |
| 780 | if (!port_name) |
| 781 | continue; |
| 782 | |
Florian Fainelli | bd47497 | 2014-08-27 17:04:50 -0700 | [diff] [blame] | 783 | cd->port_dn[port_index] = port; |
| 784 | |
Florian Fainelli | 5e95329b | 2013-03-22 10:50:50 +0000 | [diff] [blame] | 785 | cd->port_names[port_index] = kstrdup(port_name, |
| 786 | GFP_KERNEL); |
| 787 | if (!cd->port_names[port_index]) { |
| 788 | ret = -ENOMEM; |
| 789 | goto out_free_chip; |
| 790 | } |
| 791 | |
Andrew Lunn | 1e72e6f | 2015-08-17 23:52:50 +0200 | [diff] [blame] | 792 | ret = dsa_of_probe_links(pd, cd, chip_index, |
| 793 | port_index, port, port_name); |
| 794 | if (ret) |
| 795 | goto out_free_chip; |
Florian Fainelli | 5e95329b | 2013-03-22 10:50:50 +0000 | [diff] [blame] | 796 | |
Florian Fainelli | 5e95329b | 2013-03-22 10:50:50 +0000 | [diff] [blame] | 797 | } |
| 798 | } |
| 799 | |
Russell King | e496ae6 | 2015-09-24 20:35:57 +0100 | [diff] [blame] | 800 | /* The individual chips hold their own refcount on the mdio bus, |
| 801 | * so drop ours */ |
| 802 | put_device(&mdio_bus->dev); |
| 803 | |
Florian Fainelli | 5e95329b | 2013-03-22 10:50:50 +0000 | [diff] [blame] | 804 | return 0; |
| 805 | |
| 806 | out_free_chip: |
Florian Fainelli | 2116824 | 2013-03-25 05:03:39 +0000 | [diff] [blame] | 807 | dsa_of_free_platform_data(pd); |
Florian Fainelli | 5e95329b | 2013-03-22 10:50:50 +0000 | [diff] [blame] | 808 | out_free: |
| 809 | kfree(pd); |
Florian Fainelli | f1a26a0 | 2015-03-05 12:35:04 -0800 | [diff] [blame] | 810 | dev->platform_data = NULL; |
Russell King | 9861f72 | 2015-09-24 20:36:33 +0100 | [diff] [blame] | 811 | out_put_ethernet: |
| 812 | put_device(ðernet_dev->dev); |
Russell King | e496ae6 | 2015-09-24 20:35:57 +0100 | [diff] [blame] | 813 | out_put_mdio: |
| 814 | put_device(&mdio_bus->dev); |
Florian Fainelli | 5e95329b | 2013-03-22 10:50:50 +0000 | [diff] [blame] | 815 | return ret; |
| 816 | } |
| 817 | |
Florian Fainelli | f1a26a0 | 2015-03-05 12:35:04 -0800 | [diff] [blame] | 818 | static void dsa_of_remove(struct device *dev) |
Florian Fainelli | 5e95329b | 2013-03-22 10:50:50 +0000 | [diff] [blame] | 819 | { |
Florian Fainelli | f1a26a0 | 2015-03-05 12:35:04 -0800 | [diff] [blame] | 820 | struct dsa_platform_data *pd = dev->platform_data; |
Florian Fainelli | 5e95329b | 2013-03-22 10:50:50 +0000 | [diff] [blame] | 821 | |
Florian Fainelli | f1a26a0 | 2015-03-05 12:35:04 -0800 | [diff] [blame] | 822 | if (!dev->of_node) |
Florian Fainelli | 5e95329b | 2013-03-22 10:50:50 +0000 | [diff] [blame] | 823 | return; |
| 824 | |
Florian Fainelli | 2116824 | 2013-03-25 05:03:39 +0000 | [diff] [blame] | 825 | dsa_of_free_platform_data(pd); |
Russell King | 9861f72 | 2015-09-24 20:36:33 +0100 | [diff] [blame] | 826 | put_device(&pd->of_netdev->dev); |
Florian Fainelli | 5e95329b | 2013-03-22 10:50:50 +0000 | [diff] [blame] | 827 | kfree(pd); |
| 828 | } |
| 829 | #else |
Florian Fainelli | f1a26a0 | 2015-03-05 12:35:04 -0800 | [diff] [blame] | 830 | static inline int dsa_of_probe(struct device *dev) |
Florian Fainelli | 5e95329b | 2013-03-22 10:50:50 +0000 | [diff] [blame] | 831 | { |
| 832 | return 0; |
| 833 | } |
| 834 | |
Florian Fainelli | f1a26a0 | 2015-03-05 12:35:04 -0800 | [diff] [blame] | 835 | static inline void dsa_of_remove(struct device *dev) |
Florian Fainelli | 5e95329b | 2013-03-22 10:50:50 +0000 | [diff] [blame] | 836 | { |
| 837 | } |
| 838 | #endif |
| 839 | |
Neil Armstrong | 4d7f3e7 | 2015-10-06 15:40:43 +0100 | [diff] [blame] | 840 | static int dsa_setup_dst(struct dsa_switch_tree *dst, struct net_device *dev, |
| 841 | struct device *parent, struct dsa_platform_data *pd) |
Florian Fainelli | c86e59b | 2015-03-05 12:35:08 -0800 | [diff] [blame] | 842 | { |
| 843 | int i; |
Neil Armstrong | 4d7f3e7 | 2015-10-06 15:40:43 +0100 | [diff] [blame] | 844 | unsigned configured = 0; |
Florian Fainelli | c86e59b | 2015-03-05 12:35:08 -0800 | [diff] [blame] | 845 | |
| 846 | dst->pd = pd; |
| 847 | dst->master_netdev = dev; |
| 848 | dst->cpu_switch = -1; |
| 849 | dst->cpu_port = -1; |
| 850 | |
| 851 | for (i = 0; i < pd->nr_chips; i++) { |
| 852 | struct dsa_switch *ds; |
| 853 | |
| 854 | ds = dsa_switch_setup(dst, i, parent, pd->chip[i].host_dev); |
| 855 | if (IS_ERR(ds)) { |
| 856 | netdev_err(dev, "[%d]: couldn't create dsa switch instance (error %ld)\n", |
| 857 | i, PTR_ERR(ds)); |
| 858 | continue; |
| 859 | } |
| 860 | |
| 861 | dst->ds[i] = ds; |
| 862 | if (ds->drv->poll_link != NULL) |
| 863 | dst->link_poll_needed = 1; |
Neil Armstrong | 4d7f3e7 | 2015-10-06 15:40:43 +0100 | [diff] [blame] | 864 | |
| 865 | ++configured; |
Florian Fainelli | c86e59b | 2015-03-05 12:35:08 -0800 | [diff] [blame] | 866 | } |
| 867 | |
| 868 | /* |
Neil Armstrong | 4d7f3e7 | 2015-10-06 15:40:43 +0100 | [diff] [blame] | 869 | * If no switch was found, exit cleanly |
| 870 | */ |
| 871 | if (!configured) |
| 872 | return -EPROBE_DEFER; |
| 873 | |
| 874 | /* |
Florian Fainelli | c86e59b | 2015-03-05 12:35:08 -0800 | [diff] [blame] | 875 | * If we use a tagging format that doesn't have an ethertype |
| 876 | * field, make sure that all packets from this point on get |
| 877 | * sent to the tag format's receive function. |
| 878 | */ |
| 879 | wmb(); |
| 880 | dev->dsa_ptr = (void *)dst; |
| 881 | |
| 882 | if (dst->link_poll_needed) { |
| 883 | INIT_WORK(&dst->link_poll_work, dsa_link_poll_work); |
| 884 | init_timer(&dst->link_poll_timer); |
| 885 | dst->link_poll_timer.data = (unsigned long)dst; |
| 886 | dst->link_poll_timer.function = dsa_link_poll_timer; |
| 887 | dst->link_poll_timer.expires = round_jiffies(jiffies + HZ); |
| 888 | add_timer(&dst->link_poll_timer); |
| 889 | } |
Neil Armstrong | 4d7f3e7 | 2015-10-06 15:40:43 +0100 | [diff] [blame] | 890 | |
| 891 | return 0; |
Florian Fainelli | c86e59b | 2015-03-05 12:35:08 -0800 | [diff] [blame] | 892 | } |
| 893 | |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 894 | static int dsa_probe(struct platform_device *pdev) |
| 895 | { |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 896 | struct dsa_platform_data *pd = pdev->dev.platform_data; |
| 897 | struct net_device *dev; |
Lennert Buytenhek | e84665c | 2009-03-20 09:52:09 +0000 | [diff] [blame] | 898 | struct dsa_switch_tree *dst; |
Florian Fainelli | c86e59b | 2015-03-05 12:35:08 -0800 | [diff] [blame] | 899 | int ret; |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 900 | |
Joe Perches | a2ae600 | 2014-11-09 16:32:46 -0800 | [diff] [blame] | 901 | pr_notice_once("Distributed Switch Architecture driver version %s\n", |
| 902 | dsa_driver_version); |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 903 | |
Florian Fainelli | 5e95329b | 2013-03-22 10:50:50 +0000 | [diff] [blame] | 904 | if (pdev->dev.of_node) { |
Florian Fainelli | f1a26a0 | 2015-03-05 12:35:04 -0800 | [diff] [blame] | 905 | ret = dsa_of_probe(&pdev->dev); |
Florian Fainelli | 5e95329b | 2013-03-22 10:50:50 +0000 | [diff] [blame] | 906 | if (ret) |
| 907 | return ret; |
| 908 | |
| 909 | pd = pdev->dev.platform_data; |
| 910 | } |
| 911 | |
Florian Fainelli | 769a020 | 2015-03-09 14:31:21 -0700 | [diff] [blame] | 912 | if (pd == NULL || (pd->netdev == NULL && pd->of_netdev == NULL)) |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 913 | return -EINVAL; |
| 914 | |
Florian Fainelli | 769a020 | 2015-03-09 14:31:21 -0700 | [diff] [blame] | 915 | if (pd->of_netdev) { |
| 916 | dev = pd->of_netdev; |
| 917 | dev_hold(dev); |
| 918 | } else { |
| 919 | dev = dev_to_net_device(pd->netdev); |
| 920 | } |
Florian Fainelli | 5e95329b | 2013-03-22 10:50:50 +0000 | [diff] [blame] | 921 | if (dev == NULL) { |
Florian Fainelli | b324c07 | 2015-03-05 12:35:05 -0800 | [diff] [blame] | 922 | ret = -EPROBE_DEFER; |
Florian Fainelli | 5e95329b | 2013-03-22 10:50:50 +0000 | [diff] [blame] | 923 | goto out; |
| 924 | } |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 925 | |
| 926 | if (dev->dsa_ptr != NULL) { |
| 927 | dev_put(dev); |
Florian Fainelli | 5e95329b | 2013-03-22 10:50:50 +0000 | [diff] [blame] | 928 | ret = -EEXIST; |
| 929 | goto out; |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 930 | } |
| 931 | |
Neil Armstrong | d4ac35d | 2015-10-06 15:40:37 +0100 | [diff] [blame] | 932 | dst = devm_kzalloc(&pdev->dev, sizeof(*dst), GFP_KERNEL); |
Lennert Buytenhek | e84665c | 2009-03-20 09:52:09 +0000 | [diff] [blame] | 933 | if (dst == NULL) { |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 934 | dev_put(dev); |
Florian Fainelli | 5e95329b | 2013-03-22 10:50:50 +0000 | [diff] [blame] | 935 | ret = -ENOMEM; |
| 936 | goto out; |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 937 | } |
| 938 | |
Lennert Buytenhek | e84665c | 2009-03-20 09:52:09 +0000 | [diff] [blame] | 939 | platform_set_drvdata(pdev, dst); |
| 940 | |
Neil Armstrong | 4d7f3e7 | 2015-10-06 15:40:43 +0100 | [diff] [blame] | 941 | ret = dsa_setup_dst(dst, dev, &pdev->dev, pd); |
| 942 | if (ret) |
| 943 | goto out; |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 944 | |
| 945 | return 0; |
Florian Fainelli | 5e95329b | 2013-03-22 10:50:50 +0000 | [diff] [blame] | 946 | |
| 947 | out: |
Florian Fainelli | f1a26a0 | 2015-03-05 12:35:04 -0800 | [diff] [blame] | 948 | dsa_of_remove(&pdev->dev); |
Florian Fainelli | 5e95329b | 2013-03-22 10:50:50 +0000 | [diff] [blame] | 949 | |
| 950 | return ret; |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 951 | } |
| 952 | |
Florian Fainelli | c86e59b | 2015-03-05 12:35:08 -0800 | [diff] [blame] | 953 | static void dsa_remove_dst(struct dsa_switch_tree *dst) |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 954 | { |
Lennert Buytenhek | e84665c | 2009-03-20 09:52:09 +0000 | [diff] [blame] | 955 | int i; |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 956 | |
Lennert Buytenhek | e84665c | 2009-03-20 09:52:09 +0000 | [diff] [blame] | 957 | if (dst->link_poll_needed) |
| 958 | del_timer_sync(&dst->link_poll_timer); |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 959 | |
Tejun Heo | 4382973 | 2012-08-20 14:51:24 -0700 | [diff] [blame] | 960 | flush_work(&dst->link_poll_work); |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 961 | |
Lennert Buytenhek | e84665c | 2009-03-20 09:52:09 +0000 | [diff] [blame] | 962 | for (i = 0; i < dst->pd->nr_chips; i++) { |
| 963 | struct dsa_switch *ds = dst->ds[i]; |
| 964 | |
Neil Armstrong | d4ac35d | 2015-10-06 15:40:37 +0100 | [diff] [blame] | 965 | if (ds) |
Lennert Buytenhek | e84665c | 2009-03-20 09:52:09 +0000 | [diff] [blame] | 966 | dsa_switch_destroy(ds); |
| 967 | } |
Florian Fainelli | c86e59b | 2015-03-05 12:35:08 -0800 | [diff] [blame] | 968 | } |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 969 | |
Florian Fainelli | c86e59b | 2015-03-05 12:35:08 -0800 | [diff] [blame] | 970 | static int dsa_remove(struct platform_device *pdev) |
| 971 | { |
| 972 | struct dsa_switch_tree *dst = platform_get_drvdata(pdev); |
| 973 | |
| 974 | dsa_remove_dst(dst); |
Florian Fainelli | f1a26a0 | 2015-03-05 12:35:04 -0800 | [diff] [blame] | 975 | dsa_of_remove(&pdev->dev); |
Florian Fainelli | 5e95329b | 2013-03-22 10:50:50 +0000 | [diff] [blame] | 976 | |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 977 | return 0; |
| 978 | } |
| 979 | |
| 980 | static void dsa_shutdown(struct platform_device *pdev) |
| 981 | { |
| 982 | } |
| 983 | |
Florian Fainelli | 3e8a72d | 2014-08-27 17:04:46 -0700 | [diff] [blame] | 984 | static int dsa_switch_rcv(struct sk_buff *skb, struct net_device *dev, |
| 985 | struct packet_type *pt, struct net_device *orig_dev) |
| 986 | { |
| 987 | struct dsa_switch_tree *dst = dev->dsa_ptr; |
| 988 | |
| 989 | if (unlikely(dst == NULL)) { |
| 990 | kfree_skb(skb); |
| 991 | return 0; |
| 992 | } |
| 993 | |
Alexander Duyck | 5075314 | 2014-09-15 13:00:19 -0400 | [diff] [blame] | 994 | return dst->rcv(skb, dev, pt, orig_dev); |
Florian Fainelli | 3e8a72d | 2014-08-27 17:04:46 -0700 | [diff] [blame] | 995 | } |
| 996 | |
Florian Fainelli | 61b7363 | 2014-08-29 12:42:07 -0700 | [diff] [blame] | 997 | static struct packet_type dsa_pack_type __read_mostly = { |
Florian Fainelli | 3e8a72d | 2014-08-27 17:04:46 -0700 | [diff] [blame] | 998 | .type = cpu_to_be16(ETH_P_XDSA), |
| 999 | .func = dsa_switch_rcv, |
| 1000 | }; |
| 1001 | |
Florian Fainelli | b73adef | 2015-02-24 13:15:33 -0800 | [diff] [blame] | 1002 | static struct notifier_block dsa_netdevice_nb __read_mostly = { |
| 1003 | .notifier_call = dsa_slave_netdevice_event, |
| 1004 | }; |
| 1005 | |
Florian Fainelli | 2446254 | 2014-09-18 17:31:22 -0700 | [diff] [blame] | 1006 | #ifdef CONFIG_PM_SLEEP |
| 1007 | static int dsa_suspend(struct device *d) |
| 1008 | { |
| 1009 | struct platform_device *pdev = to_platform_device(d); |
| 1010 | struct dsa_switch_tree *dst = platform_get_drvdata(pdev); |
| 1011 | int i, ret = 0; |
| 1012 | |
| 1013 | for (i = 0; i < dst->pd->nr_chips; i++) { |
| 1014 | struct dsa_switch *ds = dst->ds[i]; |
| 1015 | |
| 1016 | if (ds != NULL) |
| 1017 | ret = dsa_switch_suspend(ds); |
| 1018 | } |
| 1019 | |
| 1020 | return ret; |
| 1021 | } |
| 1022 | |
| 1023 | static int dsa_resume(struct device *d) |
| 1024 | { |
| 1025 | struct platform_device *pdev = to_platform_device(d); |
| 1026 | struct dsa_switch_tree *dst = platform_get_drvdata(pdev); |
| 1027 | int i, ret = 0; |
| 1028 | |
| 1029 | for (i = 0; i < dst->pd->nr_chips; i++) { |
| 1030 | struct dsa_switch *ds = dst->ds[i]; |
| 1031 | |
| 1032 | if (ds != NULL) |
| 1033 | ret = dsa_switch_resume(ds); |
| 1034 | } |
| 1035 | |
| 1036 | return ret; |
| 1037 | } |
| 1038 | #endif |
| 1039 | |
| 1040 | static SIMPLE_DEV_PM_OPS(dsa_pm_ops, dsa_suspend, dsa_resume); |
| 1041 | |
Florian Fainelli | 5e95329b | 2013-03-22 10:50:50 +0000 | [diff] [blame] | 1042 | static const struct of_device_id dsa_of_match_table[] = { |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 1043 | { .compatible = "brcm,bcm7445-switch-v4.0" }, |
Florian Fainelli | 5e95329b | 2013-03-22 10:50:50 +0000 | [diff] [blame] | 1044 | { .compatible = "marvell,dsa", }, |
| 1045 | {} |
| 1046 | }; |
| 1047 | MODULE_DEVICE_TABLE(of, dsa_of_match_table); |
| 1048 | |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 1049 | static struct platform_driver dsa_driver = { |
| 1050 | .probe = dsa_probe, |
| 1051 | .remove = dsa_remove, |
| 1052 | .shutdown = dsa_shutdown, |
| 1053 | .driver = { |
| 1054 | .name = "dsa", |
Florian Fainelli | 5e95329b | 2013-03-22 10:50:50 +0000 | [diff] [blame] | 1055 | .of_match_table = dsa_of_match_table, |
Florian Fainelli | 2446254 | 2014-09-18 17:31:22 -0700 | [diff] [blame] | 1056 | .pm = &dsa_pm_ops, |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 1057 | }, |
| 1058 | }; |
| 1059 | |
| 1060 | static int __init dsa_init_module(void) |
| 1061 | { |
Ben Hutchings | 7df899c | 2011-11-25 14:35:02 +0000 | [diff] [blame] | 1062 | int rc; |
| 1063 | |
Florian Fainelli | b73adef | 2015-02-24 13:15:33 -0800 | [diff] [blame] | 1064 | register_netdevice_notifier(&dsa_netdevice_nb); |
| 1065 | |
Ben Hutchings | 7df899c | 2011-11-25 14:35:02 +0000 | [diff] [blame] | 1066 | rc = platform_driver_register(&dsa_driver); |
| 1067 | if (rc) |
| 1068 | return rc; |
| 1069 | |
Florian Fainelli | 3e8a72d | 2014-08-27 17:04:46 -0700 | [diff] [blame] | 1070 | dev_add_pack(&dsa_pack_type); |
| 1071 | |
Ben Hutchings | 7df899c | 2011-11-25 14:35:02 +0000 | [diff] [blame] | 1072 | return 0; |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 1073 | } |
| 1074 | module_init(dsa_init_module); |
| 1075 | |
| 1076 | static void __exit dsa_cleanup_module(void) |
| 1077 | { |
Florian Fainelli | b73adef | 2015-02-24 13:15:33 -0800 | [diff] [blame] | 1078 | unregister_netdevice_notifier(&dsa_netdevice_nb); |
Florian Fainelli | 3e8a72d | 2014-08-27 17:04:46 -0700 | [diff] [blame] | 1079 | dev_remove_pack(&dsa_pack_type); |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 1080 | platform_driver_unregister(&dsa_driver); |
| 1081 | } |
| 1082 | module_exit(dsa_cleanup_module); |
| 1083 | |
Rusty Russell | 577d6a7 | 2011-01-24 14:32:52 -0600 | [diff] [blame] | 1084 | MODULE_AUTHOR("Lennert Buytenhek <buytenh@wantstofly.org>"); |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 1085 | MODULE_DESCRIPTION("Driver for Distributed Switch Architecture switch chips"); |
| 1086 | MODULE_LICENSE("GPL"); |
| 1087 | MODULE_ALIAS("platform:dsa"); |