191da11f8SLennert Buytenhek /* 291da11f8SLennert Buytenhek * net/dsa/slave.c - Slave device handling 3e84665c9SLennert Buytenhek * Copyright (c) 2008-2009 Marvell Semiconductor 491da11f8SLennert Buytenhek * 591da11f8SLennert Buytenhek * This program is free software; you can redistribute it and/or modify 691da11f8SLennert Buytenhek * it under the terms of the GNU General Public License as published by 791da11f8SLennert Buytenhek * the Free Software Foundation; either version 2 of the License, or 891da11f8SLennert Buytenhek * (at your option) any later version. 991da11f8SLennert Buytenhek */ 1091da11f8SLennert Buytenhek 1191da11f8SLennert Buytenhek #include <linux/list.h> 1291da11f8SLennert Buytenhek #include <linux/netdevice.h> 13df02c6ffSLennert Buytenhek #include <linux/etherdevice.h> 1491da11f8SLennert Buytenhek #include <linux/phy.h> 1591da11f8SLennert Buytenhek #include "dsa_priv.h" 1691da11f8SLennert Buytenhek 1791da11f8SLennert Buytenhek /* slave mii_bus handling ***************************************************/ 1891da11f8SLennert Buytenhek static int dsa_slave_phy_read(struct mii_bus *bus, int addr, int reg) 1991da11f8SLennert Buytenhek { 2091da11f8SLennert Buytenhek struct dsa_switch *ds = bus->priv; 2191da11f8SLennert Buytenhek 22e84665c9SLennert Buytenhek if (ds->phys_port_mask & (1 << addr)) 2391da11f8SLennert Buytenhek return ds->drv->phy_read(ds, addr, reg); 2491da11f8SLennert Buytenhek 2591da11f8SLennert Buytenhek return 0xffff; 2691da11f8SLennert Buytenhek } 2791da11f8SLennert Buytenhek 2891da11f8SLennert Buytenhek static int dsa_slave_phy_write(struct mii_bus *bus, int addr, int reg, u16 val) 2991da11f8SLennert Buytenhek { 3091da11f8SLennert Buytenhek struct dsa_switch *ds = bus->priv; 3191da11f8SLennert Buytenhek 32e84665c9SLennert Buytenhek if (ds->phys_port_mask & (1 << addr)) 3391da11f8SLennert Buytenhek return ds->drv->phy_write(ds, addr, reg, val); 3491da11f8SLennert Buytenhek 3591da11f8SLennert Buytenhek return 0; 3691da11f8SLennert Buytenhek } 3791da11f8SLennert Buytenhek 3891da11f8SLennert Buytenhek void dsa_slave_mii_bus_init(struct dsa_switch *ds) 3991da11f8SLennert Buytenhek { 4091da11f8SLennert Buytenhek ds->slave_mii_bus->priv = (void *)ds; 4191da11f8SLennert Buytenhek ds->slave_mii_bus->name = "dsa slave smi"; 4291da11f8SLennert Buytenhek ds->slave_mii_bus->read = dsa_slave_phy_read; 4391da11f8SLennert Buytenhek ds->slave_mii_bus->write = dsa_slave_phy_write; 44f490be04SFlorian Fainelli snprintf(ds->slave_mii_bus->id, MII_BUS_ID_SIZE, "dsa-%d:%.2x", 45f490be04SFlorian Fainelli ds->index, ds->pd->sw_addr); 46e84665c9SLennert Buytenhek ds->slave_mii_bus->parent = &ds->master_mii_bus->dev; 4791da11f8SLennert Buytenhek } 4891da11f8SLennert Buytenhek 4991da11f8SLennert Buytenhek 5091da11f8SLennert Buytenhek /* slave device handling ****************************************************/ 51c0840801SLennert Buytenhek static int dsa_slave_init(struct net_device *dev) 52c0840801SLennert Buytenhek { 53c0840801SLennert Buytenhek struct dsa_slave_priv *p = netdev_priv(dev); 54c0840801SLennert Buytenhek 55e84665c9SLennert Buytenhek dev->iflink = p->parent->dst->master_netdev->ifindex; 56c0840801SLennert Buytenhek 57c0840801SLennert Buytenhek return 0; 58c0840801SLennert Buytenhek } 59c0840801SLennert Buytenhek 6091da11f8SLennert Buytenhek static int dsa_slave_open(struct net_device *dev) 6191da11f8SLennert Buytenhek { 62df02c6ffSLennert Buytenhek struct dsa_slave_priv *p = netdev_priv(dev); 63e84665c9SLennert Buytenhek struct net_device *master = p->parent->dst->master_netdev; 64df02c6ffSLennert Buytenhek int err; 65df02c6ffSLennert Buytenhek 66df02c6ffSLennert Buytenhek if (!(master->flags & IFF_UP)) 67df02c6ffSLennert Buytenhek return -ENETDOWN; 68df02c6ffSLennert Buytenhek 698feedbb4SJoe Perches if (!ether_addr_equal(dev->dev_addr, master->dev_addr)) { 70a748ee24SJiri Pirko err = dev_uc_add(master, dev->dev_addr); 71df02c6ffSLennert Buytenhek if (err < 0) 72df02c6ffSLennert Buytenhek goto out; 73df02c6ffSLennert Buytenhek } 74df02c6ffSLennert Buytenhek 75df02c6ffSLennert Buytenhek if (dev->flags & IFF_ALLMULTI) { 76df02c6ffSLennert Buytenhek err = dev_set_allmulti(master, 1); 77df02c6ffSLennert Buytenhek if (err < 0) 78df02c6ffSLennert Buytenhek goto del_unicast; 79df02c6ffSLennert Buytenhek } 80df02c6ffSLennert Buytenhek if (dev->flags & IFF_PROMISC) { 81df02c6ffSLennert Buytenhek err = dev_set_promiscuity(master, 1); 82df02c6ffSLennert Buytenhek if (err < 0) 83df02c6ffSLennert Buytenhek goto clear_allmulti; 84df02c6ffSLennert Buytenhek } 85df02c6ffSLennert Buytenhek 8691da11f8SLennert Buytenhek return 0; 87df02c6ffSLennert Buytenhek 88df02c6ffSLennert Buytenhek clear_allmulti: 89df02c6ffSLennert Buytenhek if (dev->flags & IFF_ALLMULTI) 90df02c6ffSLennert Buytenhek dev_set_allmulti(master, -1); 91df02c6ffSLennert Buytenhek del_unicast: 928feedbb4SJoe Perches if (!ether_addr_equal(dev->dev_addr, master->dev_addr)) 93a748ee24SJiri Pirko dev_uc_del(master, dev->dev_addr); 94df02c6ffSLennert Buytenhek out: 95df02c6ffSLennert Buytenhek return err; 9691da11f8SLennert Buytenhek } 9791da11f8SLennert Buytenhek 9891da11f8SLennert Buytenhek static int dsa_slave_close(struct net_device *dev) 9991da11f8SLennert Buytenhek { 100df02c6ffSLennert Buytenhek struct dsa_slave_priv *p = netdev_priv(dev); 101e84665c9SLennert Buytenhek struct net_device *master = p->parent->dst->master_netdev; 102df02c6ffSLennert Buytenhek 103df02c6ffSLennert Buytenhek dev_mc_unsync(master, dev); 104a748ee24SJiri Pirko dev_uc_unsync(master, dev); 105df02c6ffSLennert Buytenhek if (dev->flags & IFF_ALLMULTI) 106df02c6ffSLennert Buytenhek dev_set_allmulti(master, -1); 107df02c6ffSLennert Buytenhek if (dev->flags & IFF_PROMISC) 108df02c6ffSLennert Buytenhek dev_set_promiscuity(master, -1); 109df02c6ffSLennert Buytenhek 1108feedbb4SJoe Perches if (!ether_addr_equal(dev->dev_addr, master->dev_addr)) 111a748ee24SJiri Pirko dev_uc_del(master, dev->dev_addr); 112df02c6ffSLennert Buytenhek 11391da11f8SLennert Buytenhek return 0; 11491da11f8SLennert Buytenhek } 11591da11f8SLennert Buytenhek 11691da11f8SLennert Buytenhek static void dsa_slave_change_rx_flags(struct net_device *dev, int change) 11791da11f8SLennert Buytenhek { 11891da11f8SLennert Buytenhek struct dsa_slave_priv *p = netdev_priv(dev); 119e84665c9SLennert Buytenhek struct net_device *master = p->parent->dst->master_netdev; 12091da11f8SLennert Buytenhek 12191da11f8SLennert Buytenhek if (change & IFF_ALLMULTI) 12291da11f8SLennert Buytenhek dev_set_allmulti(master, dev->flags & IFF_ALLMULTI ? 1 : -1); 12391da11f8SLennert Buytenhek if (change & IFF_PROMISC) 12491da11f8SLennert Buytenhek dev_set_promiscuity(master, dev->flags & IFF_PROMISC ? 1 : -1); 12591da11f8SLennert Buytenhek } 12691da11f8SLennert Buytenhek 12791da11f8SLennert Buytenhek static void dsa_slave_set_rx_mode(struct net_device *dev) 12891da11f8SLennert Buytenhek { 12991da11f8SLennert Buytenhek struct dsa_slave_priv *p = netdev_priv(dev); 130e84665c9SLennert Buytenhek struct net_device *master = p->parent->dst->master_netdev; 13191da11f8SLennert Buytenhek 13291da11f8SLennert Buytenhek dev_mc_sync(master, dev); 133a748ee24SJiri Pirko dev_uc_sync(master, dev); 13491da11f8SLennert Buytenhek } 13591da11f8SLennert Buytenhek 136df02c6ffSLennert Buytenhek static int dsa_slave_set_mac_address(struct net_device *dev, void *a) 13791da11f8SLennert Buytenhek { 138df02c6ffSLennert Buytenhek struct dsa_slave_priv *p = netdev_priv(dev); 139e84665c9SLennert Buytenhek struct net_device *master = p->parent->dst->master_netdev; 140df02c6ffSLennert Buytenhek struct sockaddr *addr = a; 141df02c6ffSLennert Buytenhek int err; 142df02c6ffSLennert Buytenhek 143df02c6ffSLennert Buytenhek if (!is_valid_ether_addr(addr->sa_data)) 144df02c6ffSLennert Buytenhek return -EADDRNOTAVAIL; 145df02c6ffSLennert Buytenhek 146df02c6ffSLennert Buytenhek if (!(dev->flags & IFF_UP)) 147df02c6ffSLennert Buytenhek goto out; 148df02c6ffSLennert Buytenhek 1498feedbb4SJoe Perches if (!ether_addr_equal(addr->sa_data, master->dev_addr)) { 150a748ee24SJiri Pirko err = dev_uc_add(master, addr->sa_data); 151df02c6ffSLennert Buytenhek if (err < 0) 152df02c6ffSLennert Buytenhek return err; 153df02c6ffSLennert Buytenhek } 154df02c6ffSLennert Buytenhek 1558feedbb4SJoe Perches if (!ether_addr_equal(dev->dev_addr, master->dev_addr)) 156a748ee24SJiri Pirko dev_uc_del(master, dev->dev_addr); 157df02c6ffSLennert Buytenhek 158df02c6ffSLennert Buytenhek out: 159d08f161aSJoe Perches ether_addr_copy(dev->dev_addr, addr->sa_data); 16091da11f8SLennert Buytenhek 16191da11f8SLennert Buytenhek return 0; 16291da11f8SLennert Buytenhek } 16391da11f8SLennert Buytenhek 16491da11f8SLennert Buytenhek static int dsa_slave_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) 16591da11f8SLennert Buytenhek { 16691da11f8SLennert Buytenhek struct dsa_slave_priv *p = netdev_priv(dev); 16791da11f8SLennert Buytenhek 16891da11f8SLennert Buytenhek if (p->phy != NULL) 16928b04113SRichard Cochran return phy_mii_ioctl(p->phy, ifr, cmd); 17091da11f8SLennert Buytenhek 17191da11f8SLennert Buytenhek return -EOPNOTSUPP; 17291da11f8SLennert Buytenhek } 17391da11f8SLennert Buytenhek 17491da11f8SLennert Buytenhek 17591da11f8SLennert Buytenhek /* ethtool operations *******************************************************/ 17691da11f8SLennert Buytenhek static int 17791da11f8SLennert Buytenhek dsa_slave_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) 17891da11f8SLennert Buytenhek { 17991da11f8SLennert Buytenhek struct dsa_slave_priv *p = netdev_priv(dev); 18091da11f8SLennert Buytenhek int err; 18191da11f8SLennert Buytenhek 18291da11f8SLennert Buytenhek err = -EOPNOTSUPP; 18391da11f8SLennert Buytenhek if (p->phy != NULL) { 18491da11f8SLennert Buytenhek err = phy_read_status(p->phy); 18591da11f8SLennert Buytenhek if (err == 0) 18691da11f8SLennert Buytenhek err = phy_ethtool_gset(p->phy, cmd); 18791da11f8SLennert Buytenhek } 18891da11f8SLennert Buytenhek 18991da11f8SLennert Buytenhek return err; 19091da11f8SLennert Buytenhek } 19191da11f8SLennert Buytenhek 19291da11f8SLennert Buytenhek static int 19391da11f8SLennert Buytenhek dsa_slave_set_settings(struct net_device *dev, struct ethtool_cmd *cmd) 19491da11f8SLennert Buytenhek { 19591da11f8SLennert Buytenhek struct dsa_slave_priv *p = netdev_priv(dev); 19691da11f8SLennert Buytenhek 19791da11f8SLennert Buytenhek if (p->phy != NULL) 19891da11f8SLennert Buytenhek return phy_ethtool_sset(p->phy, cmd); 19991da11f8SLennert Buytenhek 20091da11f8SLennert Buytenhek return -EOPNOTSUPP; 20191da11f8SLennert Buytenhek } 20291da11f8SLennert Buytenhek 20391da11f8SLennert Buytenhek static void dsa_slave_get_drvinfo(struct net_device *dev, 20491da11f8SLennert Buytenhek struct ethtool_drvinfo *drvinfo) 20591da11f8SLennert Buytenhek { 2067826d43fSJiri Pirko strlcpy(drvinfo->driver, "dsa", sizeof(drvinfo->driver)); 2077826d43fSJiri Pirko strlcpy(drvinfo->version, dsa_driver_version, sizeof(drvinfo->version)); 2087826d43fSJiri Pirko strlcpy(drvinfo->fw_version, "N/A", sizeof(drvinfo->fw_version)); 2097826d43fSJiri Pirko strlcpy(drvinfo->bus_info, "platform", sizeof(drvinfo->bus_info)); 21091da11f8SLennert Buytenhek } 21191da11f8SLennert Buytenhek 21291da11f8SLennert Buytenhek static int dsa_slave_nway_reset(struct net_device *dev) 21391da11f8SLennert Buytenhek { 21491da11f8SLennert Buytenhek struct dsa_slave_priv *p = netdev_priv(dev); 21591da11f8SLennert Buytenhek 21691da11f8SLennert Buytenhek if (p->phy != NULL) 21791da11f8SLennert Buytenhek return genphy_restart_aneg(p->phy); 21891da11f8SLennert Buytenhek 21991da11f8SLennert Buytenhek return -EOPNOTSUPP; 22091da11f8SLennert Buytenhek } 22191da11f8SLennert Buytenhek 22291da11f8SLennert Buytenhek static u32 dsa_slave_get_link(struct net_device *dev) 22391da11f8SLennert Buytenhek { 22491da11f8SLennert Buytenhek struct dsa_slave_priv *p = netdev_priv(dev); 22591da11f8SLennert Buytenhek 22691da11f8SLennert Buytenhek if (p->phy != NULL) { 22791da11f8SLennert Buytenhek genphy_update_link(p->phy); 22891da11f8SLennert Buytenhek return p->phy->link; 22991da11f8SLennert Buytenhek } 23091da11f8SLennert Buytenhek 23191da11f8SLennert Buytenhek return -EOPNOTSUPP; 23291da11f8SLennert Buytenhek } 23391da11f8SLennert Buytenhek 23491da11f8SLennert Buytenhek static void dsa_slave_get_strings(struct net_device *dev, 23591da11f8SLennert Buytenhek uint32_t stringset, uint8_t *data) 23691da11f8SLennert Buytenhek { 23791da11f8SLennert Buytenhek struct dsa_slave_priv *p = netdev_priv(dev); 23891da11f8SLennert Buytenhek struct dsa_switch *ds = p->parent; 23991da11f8SLennert Buytenhek 24091da11f8SLennert Buytenhek if (stringset == ETH_SS_STATS) { 24191da11f8SLennert Buytenhek int len = ETH_GSTRING_LEN; 24291da11f8SLennert Buytenhek 24391da11f8SLennert Buytenhek strncpy(data, "tx_packets", len); 24491da11f8SLennert Buytenhek strncpy(data + len, "tx_bytes", len); 24591da11f8SLennert Buytenhek strncpy(data + 2 * len, "rx_packets", len); 24691da11f8SLennert Buytenhek strncpy(data + 3 * len, "rx_bytes", len); 24791da11f8SLennert Buytenhek if (ds->drv->get_strings != NULL) 24891da11f8SLennert Buytenhek ds->drv->get_strings(ds, p->port, data + 4 * len); 24991da11f8SLennert Buytenhek } 25091da11f8SLennert Buytenhek } 25191da11f8SLennert Buytenhek 25291da11f8SLennert Buytenhek static void dsa_slave_get_ethtool_stats(struct net_device *dev, 25391da11f8SLennert Buytenhek struct ethtool_stats *stats, 25491da11f8SLennert Buytenhek uint64_t *data) 25591da11f8SLennert Buytenhek { 25691da11f8SLennert Buytenhek struct dsa_slave_priv *p = netdev_priv(dev); 25791da11f8SLennert Buytenhek struct dsa_switch *ds = p->parent; 25891da11f8SLennert Buytenhek 25991da11f8SLennert Buytenhek data[0] = p->dev->stats.tx_packets; 26091da11f8SLennert Buytenhek data[1] = p->dev->stats.tx_bytes; 26191da11f8SLennert Buytenhek data[2] = p->dev->stats.rx_packets; 26291da11f8SLennert Buytenhek data[3] = p->dev->stats.rx_bytes; 26391da11f8SLennert Buytenhek if (ds->drv->get_ethtool_stats != NULL) 26491da11f8SLennert Buytenhek ds->drv->get_ethtool_stats(ds, p->port, data + 4); 26591da11f8SLennert Buytenhek } 26691da11f8SLennert Buytenhek 26791da11f8SLennert Buytenhek static int dsa_slave_get_sset_count(struct net_device *dev, int sset) 26891da11f8SLennert Buytenhek { 26991da11f8SLennert Buytenhek struct dsa_slave_priv *p = netdev_priv(dev); 27091da11f8SLennert Buytenhek struct dsa_switch *ds = p->parent; 27191da11f8SLennert Buytenhek 27291da11f8SLennert Buytenhek if (sset == ETH_SS_STATS) { 27391da11f8SLennert Buytenhek int count; 27491da11f8SLennert Buytenhek 27591da11f8SLennert Buytenhek count = 4; 27691da11f8SLennert Buytenhek if (ds->drv->get_sset_count != NULL) 27791da11f8SLennert Buytenhek count += ds->drv->get_sset_count(ds); 27891da11f8SLennert Buytenhek 27991da11f8SLennert Buytenhek return count; 28091da11f8SLennert Buytenhek } 28191da11f8SLennert Buytenhek 28291da11f8SLennert Buytenhek return -EOPNOTSUPP; 28391da11f8SLennert Buytenhek } 28491da11f8SLennert Buytenhek 28591da11f8SLennert Buytenhek static const struct ethtool_ops dsa_slave_ethtool_ops = { 28691da11f8SLennert Buytenhek .get_settings = dsa_slave_get_settings, 28791da11f8SLennert Buytenhek .set_settings = dsa_slave_set_settings, 28891da11f8SLennert Buytenhek .get_drvinfo = dsa_slave_get_drvinfo, 28991da11f8SLennert Buytenhek .nway_reset = dsa_slave_nway_reset, 29091da11f8SLennert Buytenhek .get_link = dsa_slave_get_link, 29191da11f8SLennert Buytenhek .get_strings = dsa_slave_get_strings, 29291da11f8SLennert Buytenhek .get_ethtool_stats = dsa_slave_get_ethtool_stats, 29391da11f8SLennert Buytenhek .get_sset_count = dsa_slave_get_sset_count, 29491da11f8SLennert Buytenhek }; 29591da11f8SLennert Buytenhek 296d442ad4aSStephen Hemminger #ifdef CONFIG_NET_DSA_TAG_DSA 297d442ad4aSStephen Hemminger static const struct net_device_ops dsa_netdev_ops = { 298c0840801SLennert Buytenhek .ndo_init = dsa_slave_init, 299d442ad4aSStephen Hemminger .ndo_open = dsa_slave_open, 300d442ad4aSStephen Hemminger .ndo_stop = dsa_slave_close, 301d442ad4aSStephen Hemminger .ndo_start_xmit = dsa_xmit, 302d442ad4aSStephen Hemminger .ndo_change_rx_flags = dsa_slave_change_rx_flags, 303d442ad4aSStephen Hemminger .ndo_set_rx_mode = dsa_slave_set_rx_mode, 304d442ad4aSStephen Hemminger .ndo_set_mac_address = dsa_slave_set_mac_address, 305d442ad4aSStephen Hemminger .ndo_do_ioctl = dsa_slave_ioctl, 306d442ad4aSStephen Hemminger }; 307d442ad4aSStephen Hemminger #endif 308d442ad4aSStephen Hemminger #ifdef CONFIG_NET_DSA_TAG_EDSA 309d442ad4aSStephen Hemminger static const struct net_device_ops edsa_netdev_ops = { 310c0840801SLennert Buytenhek .ndo_init = dsa_slave_init, 311d442ad4aSStephen Hemminger .ndo_open = dsa_slave_open, 312d442ad4aSStephen Hemminger .ndo_stop = dsa_slave_close, 313d442ad4aSStephen Hemminger .ndo_start_xmit = edsa_xmit, 314d442ad4aSStephen Hemminger .ndo_change_rx_flags = dsa_slave_change_rx_flags, 315d442ad4aSStephen Hemminger .ndo_set_rx_mode = dsa_slave_set_rx_mode, 316d442ad4aSStephen Hemminger .ndo_set_mac_address = dsa_slave_set_mac_address, 317d442ad4aSStephen Hemminger .ndo_do_ioctl = dsa_slave_ioctl, 318d442ad4aSStephen Hemminger }; 319d442ad4aSStephen Hemminger #endif 320d442ad4aSStephen Hemminger #ifdef CONFIG_NET_DSA_TAG_TRAILER 321d442ad4aSStephen Hemminger static const struct net_device_ops trailer_netdev_ops = { 322c0840801SLennert Buytenhek .ndo_init = dsa_slave_init, 323d442ad4aSStephen Hemminger .ndo_open = dsa_slave_open, 324d442ad4aSStephen Hemminger .ndo_stop = dsa_slave_close, 325d442ad4aSStephen Hemminger .ndo_start_xmit = trailer_xmit, 326d442ad4aSStephen Hemminger .ndo_change_rx_flags = dsa_slave_change_rx_flags, 327d442ad4aSStephen Hemminger .ndo_set_rx_mode = dsa_slave_set_rx_mode, 328d442ad4aSStephen Hemminger .ndo_set_mac_address = dsa_slave_set_mac_address, 329d442ad4aSStephen Hemminger .ndo_do_ioctl = dsa_slave_ioctl, 330d442ad4aSStephen Hemminger }; 331d442ad4aSStephen Hemminger #endif 33291da11f8SLennert Buytenhek 33391da11f8SLennert Buytenhek /* slave device setup *******************************************************/ 33491da11f8SLennert Buytenhek struct net_device * 33591da11f8SLennert Buytenhek dsa_slave_create(struct dsa_switch *ds, struct device *parent, 33691da11f8SLennert Buytenhek int port, char *name) 33791da11f8SLennert Buytenhek { 338e84665c9SLennert Buytenhek struct net_device *master = ds->dst->master_netdev; 33991da11f8SLennert Buytenhek struct net_device *slave_dev; 34091da11f8SLennert Buytenhek struct dsa_slave_priv *p; 34191da11f8SLennert Buytenhek int ret; 34291da11f8SLennert Buytenhek 34391da11f8SLennert Buytenhek slave_dev = alloc_netdev(sizeof(struct dsa_slave_priv), 34491da11f8SLennert Buytenhek name, ether_setup); 34591da11f8SLennert Buytenhek if (slave_dev == NULL) 34691da11f8SLennert Buytenhek return slave_dev; 34791da11f8SLennert Buytenhek 34891da11f8SLennert Buytenhek slave_dev->features = master->vlan_features; 349*7ad24ea4SWilfried Klaebe slave_dev->ethtool_ops = &dsa_slave_ethtool_ops; 3502fcc8005SBjørn Mork eth_hw_addr_inherit(slave_dev, master); 35191da11f8SLennert Buytenhek slave_dev->tx_queue_len = 0; 352d442ad4aSStephen Hemminger 353e84665c9SLennert Buytenhek switch (ds->dst->tag_protocol) { 354cf85d08fSLennert Buytenhek #ifdef CONFIG_NET_DSA_TAG_DSA 355cf85d08fSLennert Buytenhek case htons(ETH_P_DSA): 356d442ad4aSStephen Hemminger slave_dev->netdev_ops = &dsa_netdev_ops; 357cf85d08fSLennert Buytenhek break; 358cf85d08fSLennert Buytenhek #endif 35991da11f8SLennert Buytenhek #ifdef CONFIG_NET_DSA_TAG_EDSA 36091da11f8SLennert Buytenhek case htons(ETH_P_EDSA): 361d442ad4aSStephen Hemminger slave_dev->netdev_ops = &edsa_netdev_ops; 36291da11f8SLennert Buytenhek break; 36391da11f8SLennert Buytenhek #endif 364396138f0SLennert Buytenhek #ifdef CONFIG_NET_DSA_TAG_TRAILER 365396138f0SLennert Buytenhek case htons(ETH_P_TRAILER): 366d442ad4aSStephen Hemminger slave_dev->netdev_ops = &trailer_netdev_ops; 367396138f0SLennert Buytenhek break; 368396138f0SLennert Buytenhek #endif 36991da11f8SLennert Buytenhek default: 37091da11f8SLennert Buytenhek BUG(); 37191da11f8SLennert Buytenhek } 372d442ad4aSStephen Hemminger 37391da11f8SLennert Buytenhek SET_NETDEV_DEV(slave_dev, parent); 37491da11f8SLennert Buytenhek slave_dev->vlan_features = master->vlan_features; 37591da11f8SLennert Buytenhek 37691da11f8SLennert Buytenhek p = netdev_priv(slave_dev); 37791da11f8SLennert Buytenhek p->dev = slave_dev; 37891da11f8SLennert Buytenhek p->parent = ds; 37991da11f8SLennert Buytenhek p->port = port; 38091da11f8SLennert Buytenhek p->phy = ds->slave_mii_bus->phy_map[port]; 38191da11f8SLennert Buytenhek 38291da11f8SLennert Buytenhek ret = register_netdev(slave_dev); 38391da11f8SLennert Buytenhek if (ret) { 38491da11f8SLennert Buytenhek printk(KERN_ERR "%s: error %d registering interface %s\n", 38591da11f8SLennert Buytenhek master->name, ret, slave_dev->name); 38691da11f8SLennert Buytenhek free_netdev(slave_dev); 38791da11f8SLennert Buytenhek return NULL; 38891da11f8SLennert Buytenhek } 38991da11f8SLennert Buytenhek 39091da11f8SLennert Buytenhek netif_carrier_off(slave_dev); 39191da11f8SLennert Buytenhek 39291da11f8SLennert Buytenhek if (p->phy != NULL) { 393fb28ad35SKay Sievers phy_attach(slave_dev, dev_name(&p->phy->dev), 394f9a8f83bSFlorian Fainelli PHY_INTERFACE_MODE_GMII); 39591da11f8SLennert Buytenhek 39691da11f8SLennert Buytenhek p->phy->autoneg = AUTONEG_ENABLE; 39791da11f8SLennert Buytenhek p->phy->speed = 0; 39891da11f8SLennert Buytenhek p->phy->duplex = 0; 39991da11f8SLennert Buytenhek p->phy->advertising = p->phy->supported | ADVERTISED_Autoneg; 40091da11f8SLennert Buytenhek phy_start_aneg(p->phy); 40191da11f8SLennert Buytenhek } 40291da11f8SLennert Buytenhek 40391da11f8SLennert Buytenhek return slave_dev; 40491da11f8SLennert Buytenhek } 405