slave.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685
  1. /*
  2. * net/dsa/slave.c - Slave device handling
  3. * Copyright (c) 2008-2009 Marvell Semiconductor
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. */
  10. #include <linux/list.h>
  11. #include <linux/etherdevice.h>
  12. #include <linux/phy.h>
  13. #include <linux/phy_fixed.h>
  14. #include <linux/of_net.h>
  15. #include <linux/of_mdio.h>
  16. #include "dsa_priv.h"
  17. /* slave mii_bus handling ***************************************************/
  18. static int dsa_slave_phy_read(struct mii_bus *bus, int addr, int reg)
  19. {
  20. struct dsa_switch *ds = bus->priv;
  21. if (ds->phys_mii_mask & (1 << addr))
  22. return ds->drv->phy_read(ds, addr, reg);
  23. return 0xffff;
  24. }
  25. static int dsa_slave_phy_write(struct mii_bus *bus, int addr, int reg, u16 val)
  26. {
  27. struct dsa_switch *ds = bus->priv;
  28. if (ds->phys_mii_mask & (1 << addr))
  29. return ds->drv->phy_write(ds, addr, reg, val);
  30. return 0;
  31. }
  32. void dsa_slave_mii_bus_init(struct dsa_switch *ds)
  33. {
  34. ds->slave_mii_bus->priv = (void *)ds;
  35. ds->slave_mii_bus->name = "dsa slave smi";
  36. ds->slave_mii_bus->read = dsa_slave_phy_read;
  37. ds->slave_mii_bus->write = dsa_slave_phy_write;
  38. snprintf(ds->slave_mii_bus->id, MII_BUS_ID_SIZE, "dsa-%d:%.2x",
  39. ds->index, ds->pd->sw_addr);
  40. ds->slave_mii_bus->parent = ds->master_dev;
  41. ds->slave_mii_bus->phy_mask = ~ds->phys_mii_mask;
  42. }
  43. /* slave device handling ****************************************************/
  44. static int dsa_slave_init(struct net_device *dev)
  45. {
  46. struct dsa_slave_priv *p = netdev_priv(dev);
  47. dev->iflink = p->parent->dst->master_netdev->ifindex;
  48. return 0;
  49. }
  50. static int dsa_slave_open(struct net_device *dev)
  51. {
  52. struct dsa_slave_priv *p = netdev_priv(dev);
  53. struct net_device *master = p->parent->dst->master_netdev;
  54. struct dsa_switch *ds = p->parent;
  55. int err;
  56. if (!(master->flags & IFF_UP))
  57. return -ENETDOWN;
  58. if (!ether_addr_equal(dev->dev_addr, master->dev_addr)) {
  59. err = dev_uc_add(master, dev->dev_addr);
  60. if (err < 0)
  61. goto out;
  62. }
  63. if (dev->flags & IFF_ALLMULTI) {
  64. err = dev_set_allmulti(master, 1);
  65. if (err < 0)
  66. goto del_unicast;
  67. }
  68. if (dev->flags & IFF_PROMISC) {
  69. err = dev_set_promiscuity(master, 1);
  70. if (err < 0)
  71. goto clear_allmulti;
  72. }
  73. if (ds->drv->port_enable) {
  74. err = ds->drv->port_enable(ds, p->port, p->phy);
  75. if (err)
  76. goto clear_promisc;
  77. }
  78. if (p->phy)
  79. phy_start(p->phy);
  80. return 0;
  81. clear_promisc:
  82. if (dev->flags & IFF_PROMISC)
  83. dev_set_promiscuity(master, 0);
  84. clear_allmulti:
  85. if (dev->flags & IFF_ALLMULTI)
  86. dev_set_allmulti(master, -1);
  87. del_unicast:
  88. if (!ether_addr_equal(dev->dev_addr, master->dev_addr))
  89. dev_uc_del(master, dev->dev_addr);
  90. out:
  91. return err;
  92. }
  93. static int dsa_slave_close(struct net_device *dev)
  94. {
  95. struct dsa_slave_priv *p = netdev_priv(dev);
  96. struct net_device *master = p->parent->dst->master_netdev;
  97. struct dsa_switch *ds = p->parent;
  98. if (p->phy)
  99. phy_stop(p->phy);
  100. dev_mc_unsync(master, dev);
  101. dev_uc_unsync(master, dev);
  102. if (dev->flags & IFF_ALLMULTI)
  103. dev_set_allmulti(master, -1);
  104. if (dev->flags & IFF_PROMISC)
  105. dev_set_promiscuity(master, -1);
  106. if (!ether_addr_equal(dev->dev_addr, master->dev_addr))
  107. dev_uc_del(master, dev->dev_addr);
  108. if (ds->drv->port_disable)
  109. ds->drv->port_disable(ds, p->port, p->phy);
  110. return 0;
  111. }
  112. static void dsa_slave_change_rx_flags(struct net_device *dev, int change)
  113. {
  114. struct dsa_slave_priv *p = netdev_priv(dev);
  115. struct net_device *master = p->parent->dst->master_netdev;
  116. if (change & IFF_ALLMULTI)
  117. dev_set_allmulti(master, dev->flags & IFF_ALLMULTI ? 1 : -1);
  118. if (change & IFF_PROMISC)
  119. dev_set_promiscuity(master, dev->flags & IFF_PROMISC ? 1 : -1);
  120. }
  121. static void dsa_slave_set_rx_mode(struct net_device *dev)
  122. {
  123. struct dsa_slave_priv *p = netdev_priv(dev);
  124. struct net_device *master = p->parent->dst->master_netdev;
  125. dev_mc_sync(master, dev);
  126. dev_uc_sync(master, dev);
  127. }
  128. static int dsa_slave_set_mac_address(struct net_device *dev, void *a)
  129. {
  130. struct dsa_slave_priv *p = netdev_priv(dev);
  131. struct net_device *master = p->parent->dst->master_netdev;
  132. struct sockaddr *addr = a;
  133. int err;
  134. if (!is_valid_ether_addr(addr->sa_data))
  135. return -EADDRNOTAVAIL;
  136. if (!(dev->flags & IFF_UP))
  137. goto out;
  138. if (!ether_addr_equal(addr->sa_data, master->dev_addr)) {
  139. err = dev_uc_add(master, addr->sa_data);
  140. if (err < 0)
  141. return err;
  142. }
  143. if (!ether_addr_equal(dev->dev_addr, master->dev_addr))
  144. dev_uc_del(master, dev->dev_addr);
  145. out:
  146. ether_addr_copy(dev->dev_addr, addr->sa_data);
  147. return 0;
  148. }
  149. static int dsa_slave_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  150. {
  151. struct dsa_slave_priv *p = netdev_priv(dev);
  152. if (p->phy != NULL)
  153. return phy_mii_ioctl(p->phy, ifr, cmd);
  154. return -EOPNOTSUPP;
  155. }
  156. static netdev_tx_t dsa_slave_xmit(struct sk_buff *skb, struct net_device *dev)
  157. {
  158. struct dsa_slave_priv *p = netdev_priv(dev);
  159. return p->xmit(skb, dev);
  160. }
  161. static netdev_tx_t dsa_slave_notag_xmit(struct sk_buff *skb,
  162. struct net_device *dev)
  163. {
  164. struct dsa_slave_priv *p = netdev_priv(dev);
  165. skb->dev = p->parent->dst->master_netdev;
  166. dev_queue_xmit(skb);
  167. return NETDEV_TX_OK;
  168. }
  169. /* ethtool operations *******************************************************/
  170. static int
  171. dsa_slave_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  172. {
  173. struct dsa_slave_priv *p = netdev_priv(dev);
  174. int err;
  175. err = -EOPNOTSUPP;
  176. if (p->phy != NULL) {
  177. err = phy_read_status(p->phy);
  178. if (err == 0)
  179. err = phy_ethtool_gset(p->phy, cmd);
  180. }
  181. return err;
  182. }
  183. static int
  184. dsa_slave_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  185. {
  186. struct dsa_slave_priv *p = netdev_priv(dev);
  187. if (p->phy != NULL)
  188. return phy_ethtool_sset(p->phy, cmd);
  189. return -EOPNOTSUPP;
  190. }
  191. static void dsa_slave_get_drvinfo(struct net_device *dev,
  192. struct ethtool_drvinfo *drvinfo)
  193. {
  194. strlcpy(drvinfo->driver, "dsa", sizeof(drvinfo->driver));
  195. strlcpy(drvinfo->version, dsa_driver_version, sizeof(drvinfo->version));
  196. strlcpy(drvinfo->fw_version, "N/A", sizeof(drvinfo->fw_version));
  197. strlcpy(drvinfo->bus_info, "platform", sizeof(drvinfo->bus_info));
  198. }
  199. static int dsa_slave_get_regs_len(struct net_device *dev)
  200. {
  201. struct dsa_slave_priv *p = netdev_priv(dev);
  202. struct dsa_switch *ds = p->parent;
  203. if (ds->drv->get_regs_len)
  204. return ds->drv->get_regs_len(ds, p->port);
  205. return -EOPNOTSUPP;
  206. }
  207. static void
  208. dsa_slave_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *_p)
  209. {
  210. struct dsa_slave_priv *p = netdev_priv(dev);
  211. struct dsa_switch *ds = p->parent;
  212. if (ds->drv->get_regs)
  213. ds->drv->get_regs(ds, p->port, regs, _p);
  214. }
  215. static int dsa_slave_nway_reset(struct net_device *dev)
  216. {
  217. struct dsa_slave_priv *p = netdev_priv(dev);
  218. if (p->phy != NULL)
  219. return genphy_restart_aneg(p->phy);
  220. return -EOPNOTSUPP;
  221. }
  222. static u32 dsa_slave_get_link(struct net_device *dev)
  223. {
  224. struct dsa_slave_priv *p = netdev_priv(dev);
  225. if (p->phy != NULL) {
  226. genphy_update_link(p->phy);
  227. return p->phy->link;
  228. }
  229. return -EOPNOTSUPP;
  230. }
  231. static int dsa_slave_get_eeprom_len(struct net_device *dev)
  232. {
  233. struct dsa_slave_priv *p = netdev_priv(dev);
  234. struct dsa_switch *ds = p->parent;
  235. if (ds->pd->eeprom_len)
  236. return ds->pd->eeprom_len;
  237. if (ds->drv->get_eeprom_len)
  238. return ds->drv->get_eeprom_len(ds);
  239. return 0;
  240. }
  241. static int dsa_slave_get_eeprom(struct net_device *dev,
  242. struct ethtool_eeprom *eeprom, u8 *data)
  243. {
  244. struct dsa_slave_priv *p = netdev_priv(dev);
  245. struct dsa_switch *ds = p->parent;
  246. if (ds->drv->get_eeprom)
  247. return ds->drv->get_eeprom(ds, eeprom, data);
  248. return -EOPNOTSUPP;
  249. }
  250. static int dsa_slave_set_eeprom(struct net_device *dev,
  251. struct ethtool_eeprom *eeprom, u8 *data)
  252. {
  253. struct dsa_slave_priv *p = netdev_priv(dev);
  254. struct dsa_switch *ds = p->parent;
  255. if (ds->drv->set_eeprom)
  256. return ds->drv->set_eeprom(ds, eeprom, data);
  257. return -EOPNOTSUPP;
  258. }
  259. static void dsa_slave_get_strings(struct net_device *dev,
  260. uint32_t stringset, uint8_t *data)
  261. {
  262. struct dsa_slave_priv *p = netdev_priv(dev);
  263. struct dsa_switch *ds = p->parent;
  264. if (stringset == ETH_SS_STATS) {
  265. int len = ETH_GSTRING_LEN;
  266. strncpy(data, "tx_packets", len);
  267. strncpy(data + len, "tx_bytes", len);
  268. strncpy(data + 2 * len, "rx_packets", len);
  269. strncpy(data + 3 * len, "rx_bytes", len);
  270. if (ds->drv->get_strings != NULL)
  271. ds->drv->get_strings(ds, p->port, data + 4 * len);
  272. }
  273. }
  274. static void dsa_slave_get_ethtool_stats(struct net_device *dev,
  275. struct ethtool_stats *stats,
  276. uint64_t *data)
  277. {
  278. struct dsa_slave_priv *p = netdev_priv(dev);
  279. struct dsa_switch *ds = p->parent;
  280. data[0] = p->dev->stats.tx_packets;
  281. data[1] = p->dev->stats.tx_bytes;
  282. data[2] = p->dev->stats.rx_packets;
  283. data[3] = p->dev->stats.rx_bytes;
  284. if (ds->drv->get_ethtool_stats != NULL)
  285. ds->drv->get_ethtool_stats(ds, p->port, data + 4);
  286. }
  287. static int dsa_slave_get_sset_count(struct net_device *dev, int sset)
  288. {
  289. struct dsa_slave_priv *p = netdev_priv(dev);
  290. struct dsa_switch *ds = p->parent;
  291. if (sset == ETH_SS_STATS) {
  292. int count;
  293. count = 4;
  294. if (ds->drv->get_sset_count != NULL)
  295. count += ds->drv->get_sset_count(ds);
  296. return count;
  297. }
  298. return -EOPNOTSUPP;
  299. }
  300. static void dsa_slave_get_wol(struct net_device *dev, struct ethtool_wolinfo *w)
  301. {
  302. struct dsa_slave_priv *p = netdev_priv(dev);
  303. struct dsa_switch *ds = p->parent;
  304. if (ds->drv->get_wol)
  305. ds->drv->get_wol(ds, p->port, w);
  306. }
  307. static int dsa_slave_set_wol(struct net_device *dev, struct ethtool_wolinfo *w)
  308. {
  309. struct dsa_slave_priv *p = netdev_priv(dev);
  310. struct dsa_switch *ds = p->parent;
  311. int ret = -EOPNOTSUPP;
  312. if (ds->drv->set_wol)
  313. ret = ds->drv->set_wol(ds, p->port, w);
  314. return ret;
  315. }
  316. static int dsa_slave_set_eee(struct net_device *dev, struct ethtool_eee *e)
  317. {
  318. struct dsa_slave_priv *p = netdev_priv(dev);
  319. struct dsa_switch *ds = p->parent;
  320. int ret;
  321. if (!ds->drv->set_eee)
  322. return -EOPNOTSUPP;
  323. ret = ds->drv->set_eee(ds, p->port, p->phy, e);
  324. if (ret)
  325. return ret;
  326. if (p->phy)
  327. ret = phy_ethtool_set_eee(p->phy, e);
  328. return ret;
  329. }
  330. static int dsa_slave_get_eee(struct net_device *dev, struct ethtool_eee *e)
  331. {
  332. struct dsa_slave_priv *p = netdev_priv(dev);
  333. struct dsa_switch *ds = p->parent;
  334. int ret;
  335. if (!ds->drv->get_eee)
  336. return -EOPNOTSUPP;
  337. ret = ds->drv->get_eee(ds, p->port, e);
  338. if (ret)
  339. return ret;
  340. if (p->phy)
  341. ret = phy_ethtool_get_eee(p->phy, e);
  342. return ret;
  343. }
  344. static const struct ethtool_ops dsa_slave_ethtool_ops = {
  345. .get_settings = dsa_slave_get_settings,
  346. .set_settings = dsa_slave_set_settings,
  347. .get_drvinfo = dsa_slave_get_drvinfo,
  348. .get_regs_len = dsa_slave_get_regs_len,
  349. .get_regs = dsa_slave_get_regs,
  350. .nway_reset = dsa_slave_nway_reset,
  351. .get_link = dsa_slave_get_link,
  352. .get_eeprom_len = dsa_slave_get_eeprom_len,
  353. .get_eeprom = dsa_slave_get_eeprom,
  354. .set_eeprom = dsa_slave_set_eeprom,
  355. .get_strings = dsa_slave_get_strings,
  356. .get_ethtool_stats = dsa_slave_get_ethtool_stats,
  357. .get_sset_count = dsa_slave_get_sset_count,
  358. .set_wol = dsa_slave_set_wol,
  359. .get_wol = dsa_slave_get_wol,
  360. .set_eee = dsa_slave_set_eee,
  361. .get_eee = dsa_slave_get_eee,
  362. };
  363. static const struct net_device_ops dsa_slave_netdev_ops = {
  364. .ndo_init = dsa_slave_init,
  365. .ndo_open = dsa_slave_open,
  366. .ndo_stop = dsa_slave_close,
  367. .ndo_start_xmit = dsa_slave_xmit,
  368. .ndo_change_rx_flags = dsa_slave_change_rx_flags,
  369. .ndo_set_rx_mode = dsa_slave_set_rx_mode,
  370. .ndo_set_mac_address = dsa_slave_set_mac_address,
  371. .ndo_do_ioctl = dsa_slave_ioctl,
  372. };
  373. static void dsa_slave_adjust_link(struct net_device *dev)
  374. {
  375. struct dsa_slave_priv *p = netdev_priv(dev);
  376. struct dsa_switch *ds = p->parent;
  377. unsigned int status_changed = 0;
  378. if (p->old_link != p->phy->link) {
  379. status_changed = 1;
  380. p->old_link = p->phy->link;
  381. }
  382. if (p->old_duplex != p->phy->duplex) {
  383. status_changed = 1;
  384. p->old_duplex = p->phy->duplex;
  385. }
  386. if (p->old_pause != p->phy->pause) {
  387. status_changed = 1;
  388. p->old_pause = p->phy->pause;
  389. }
  390. if (ds->drv->adjust_link && status_changed)
  391. ds->drv->adjust_link(ds, p->port, p->phy);
  392. if (status_changed)
  393. phy_print_status(p->phy);
  394. }
  395. static int dsa_slave_fixed_link_update(struct net_device *dev,
  396. struct fixed_phy_status *status)
  397. {
  398. struct dsa_slave_priv *p = netdev_priv(dev);
  399. struct dsa_switch *ds = p->parent;
  400. if (ds->drv->fixed_link_update)
  401. ds->drv->fixed_link_update(ds, p->port, status);
  402. return 0;
  403. }
  404. /* slave device setup *******************************************************/
  405. static int dsa_slave_phy_setup(struct dsa_slave_priv *p,
  406. struct net_device *slave_dev)
  407. {
  408. struct dsa_switch *ds = p->parent;
  409. struct dsa_chip_data *cd = ds->pd;
  410. struct device_node *phy_dn, *port_dn;
  411. bool phy_is_fixed = false;
  412. u32 phy_flags = 0;
  413. int mode, ret;
  414. port_dn = cd->port_dn[p->port];
  415. mode = of_get_phy_mode(port_dn);
  416. if (mode < 0)
  417. mode = PHY_INTERFACE_MODE_NA;
  418. p->phy_interface = mode;
  419. phy_dn = of_parse_phandle(port_dn, "phy-handle", 0);
  420. if (of_phy_is_fixed_link(port_dn)) {
  421. /* In the case of a fixed PHY, the DT node associated
  422. * to the fixed PHY is the Port DT node
  423. */
  424. ret = of_phy_register_fixed_link(port_dn);
  425. if (ret) {
  426. netdev_err(slave_dev, "failed to register fixed PHY\n");
  427. return ret;
  428. }
  429. phy_is_fixed = true;
  430. phy_dn = port_dn;
  431. }
  432. if (ds->drv->get_phy_flags)
  433. phy_flags = ds->drv->get_phy_flags(ds, p->port);
  434. if (phy_dn)
  435. p->phy = of_phy_connect(slave_dev, phy_dn,
  436. dsa_slave_adjust_link, phy_flags,
  437. p->phy_interface);
  438. if (p->phy && phy_is_fixed)
  439. fixed_phy_set_link_update(p->phy, dsa_slave_fixed_link_update);
  440. /* We could not connect to a designated PHY, so use the switch internal
  441. * MDIO bus instead
  442. */
  443. if (!p->phy) {
  444. p->phy = ds->slave_mii_bus->phy_map[p->port];
  445. if (!p->phy)
  446. return -ENODEV;
  447. /* Use already configured phy mode */
  448. p->phy_interface = p->phy->interface;
  449. phy_connect_direct(slave_dev, p->phy, dsa_slave_adjust_link,
  450. p->phy_interface);
  451. } else {
  452. netdev_info(slave_dev, "attached PHY at address %d [%s]\n",
  453. p->phy->addr, p->phy->drv->name);
  454. }
  455. return 0;
  456. }
  457. int dsa_slave_suspend(struct net_device *slave_dev)
  458. {
  459. struct dsa_slave_priv *p = netdev_priv(slave_dev);
  460. netif_device_detach(slave_dev);
  461. if (p->phy) {
  462. phy_stop(p->phy);
  463. p->old_pause = -1;
  464. p->old_link = -1;
  465. p->old_duplex = -1;
  466. phy_suspend(p->phy);
  467. }
  468. return 0;
  469. }
  470. int dsa_slave_resume(struct net_device *slave_dev)
  471. {
  472. struct dsa_slave_priv *p = netdev_priv(slave_dev);
  473. netif_device_attach(slave_dev);
  474. if (p->phy) {
  475. phy_resume(p->phy);
  476. phy_start(p->phy);
  477. }
  478. return 0;
  479. }
  480. struct net_device *
  481. dsa_slave_create(struct dsa_switch *ds, struct device *parent,
  482. int port, char *name)
  483. {
  484. struct net_device *master = ds->dst->master_netdev;
  485. struct net_device *slave_dev;
  486. struct dsa_slave_priv *p;
  487. int ret;
  488. slave_dev = alloc_netdev(sizeof(struct dsa_slave_priv), name,
  489. NET_NAME_UNKNOWN, ether_setup);
  490. if (slave_dev == NULL)
  491. return slave_dev;
  492. slave_dev->features = master->vlan_features;
  493. slave_dev->ethtool_ops = &dsa_slave_ethtool_ops;
  494. eth_hw_addr_inherit(slave_dev, master);
  495. slave_dev->tx_queue_len = 0;
  496. slave_dev->netdev_ops = &dsa_slave_netdev_ops;
  497. SET_NETDEV_DEV(slave_dev, parent);
  498. slave_dev->dev.of_node = ds->pd->port_dn[port];
  499. slave_dev->vlan_features = master->vlan_features;
  500. p = netdev_priv(slave_dev);
  501. p->dev = slave_dev;
  502. p->parent = ds;
  503. p->port = port;
  504. switch (ds->dst->tag_protocol) {
  505. #ifdef CONFIG_NET_DSA_TAG_DSA
  506. case DSA_TAG_PROTO_DSA:
  507. p->xmit = dsa_netdev_ops.xmit;
  508. break;
  509. #endif
  510. #ifdef CONFIG_NET_DSA_TAG_EDSA
  511. case DSA_TAG_PROTO_EDSA:
  512. p->xmit = edsa_netdev_ops.xmit;
  513. break;
  514. #endif
  515. #ifdef CONFIG_NET_DSA_TAG_TRAILER
  516. case DSA_TAG_PROTO_TRAILER:
  517. p->xmit = trailer_netdev_ops.xmit;
  518. break;
  519. #endif
  520. #ifdef CONFIG_NET_DSA_TAG_BRCM
  521. case DSA_TAG_PROTO_BRCM:
  522. p->xmit = brcm_netdev_ops.xmit;
  523. break;
  524. #endif
  525. default:
  526. p->xmit = dsa_slave_notag_xmit;
  527. break;
  528. }
  529. p->old_pause = -1;
  530. p->old_link = -1;
  531. p->old_duplex = -1;
  532. ret = dsa_slave_phy_setup(p, slave_dev);
  533. if (ret) {
  534. free_netdev(slave_dev);
  535. return NULL;
  536. }
  537. ret = register_netdev(slave_dev);
  538. if (ret) {
  539. netdev_err(master, "error %d registering interface %s\n",
  540. ret, slave_dev->name);
  541. phy_disconnect(p->phy);
  542. free_netdev(slave_dev);
  543. return NULL;
  544. }
  545. netif_carrier_off(slave_dev);
  546. return slave_dev;
  547. }