400-dsa-add-qca.patch 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068
  1. From patchwork Fri May 29 01:42:16 2015
  2. Content-Type: text/plain; charset="utf-8"
  3. MIME-Version: 1.0
  4. Content-Transfer-Encoding: 7bit
  5. Subject: [1/7] net: dsa: add new driver for ar8xxx family
  6. From: Mathieu Olivari <mathieu@codeaurora.org>
  7. X-Patchwork-Id: 477523
  8. X-Patchwork-Delegate: davem@davemloft.net
  9. Message-Id: <1432863742-18427-2-git-send-email-mathieu@codeaurora.org>
  10. To: robh+dt@kernel.org, pawel.moll@arm.com, mark.rutland@arm.com,
  11. ijc+devicetree@hellion.org.uk, galak@codeaurora.org,
  12. davem@davemloft.net, mathieu@codeaurora.org, andrew@lunn.ch,
  13. f.fainelli@gmail.com, linux@roeck-us.net, gang.chen.5i5j@gmail.com,
  14. jiri@resnulli.us, leitec@staticky.com, fabf@skynet.be,
  15. alexander.h.duyck@intel.com, pavel.nakonechny@skitlab.ru,
  16. joe@perches.com, sfeldma@gmail.com, nbd@nbd.name, juhosg@openwrt.org
  17. Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
  18. netdev@vger.kernel.org
  19. Date: Thu, 28 May 2015 18:42:16 -0700
  20. This patch contains initial init & registration code for QCA8337. It
  21. will detect a QCA8337 switch, if present and declared in DT/platform.
  22. Each port will be represented through a standalone net_device interface,
  23. as for other DSA switches. CPU can communicate with any of the ports by
  24. setting an IP@ on ethN interface. Ports cannot communicate with each
  25. other just yet.
  26. Link status will be reported through polling, and we don't use any
  27. encapsulation.
  28. Signed-off-by: Mathieu Olivari <mathieu@codeaurora.org>
  29. ---
  30. drivers/net/dsa/Kconfig | 7 ++
  31. drivers/net/dsa/Makefile | 1 +
  32. drivers/net/dsa/ar8xxx.c | 303 +++++++++++++++++++++++++++++++++++++++++++++++
  33. drivers/net/dsa/ar8xxx.h | 82 +++++++++++++
  34. net/dsa/dsa.c | 1 +
  35. 5 files changed, 394 insertions(+)
  36. create mode 100644 drivers/net/dsa/ar8xxx.c
  37. create mode 100644 drivers/net/dsa/ar8xxx.h
  38. --- a/drivers/net/dsa/Kconfig
  39. +++ b/drivers/net/dsa/Kconfig
  40. @@ -65,4 +65,13 @@ config NET_DSA_BCM_SF2
  41. This enables support for the Broadcom Starfighter 2 Ethernet
  42. switch chips.
  43. +config NET_DSA_AR8XXX
  44. + tristate "Qualcomm Atheros AR8XXX Ethernet switch family support"
  45. + depends on NET_DSA
  46. + select NET_DSA_TAG_QCA
  47. + select REGMAP
  48. + ---help---
  49. + This enables support for the Qualcomm Atheros AR8XXX Ethernet
  50. + switch chips.
  51. +
  52. endmenu
  53. --- a/drivers/net/dsa/Makefile
  54. +++ b/drivers/net/dsa/Makefile
  55. @@ -14,3 +14,4 @@ ifdef CONFIG_NET_DSA_MV88E6171
  56. mv88e6xxx_drv-y += mv88e6171.o
  57. endif
  58. obj-$(CONFIG_NET_DSA_BCM_SF2) += bcm_sf2.o
  59. +obj-$(CONFIG_NET_DSA_AR8XXX) += ar8xxx.o
  60. --- /dev/null
  61. +++ b/drivers/net/dsa/ar8xxx.c
  62. @@ -0,0 +1,529 @@
  63. +/*
  64. + * Copyright (C) 2009 Felix Fietkau <nbd@nbd.name>
  65. + * Copyright (C) 2011-2012 Gabor Juhos <juhosg@openwrt.org>
  66. + * Copyright (c) 2015, The Linux Foundation. All rights reserved.
  67. + *
  68. + * This program is free software; you can redistribute it and/or modify
  69. + * it under the terms of the GNU General Public License version 2 and
  70. + * only version 2 as published by the Free Software Foundation.
  71. + *
  72. + * This program is distributed in the hope that it will be useful,
  73. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  74. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  75. + * GNU General Public License for more details.
  76. + */
  77. +
  78. +#include <linux/module.h>
  79. +#include <linux/phy.h>
  80. +#include <linux/netdevice.h>
  81. +#include <net/dsa.h>
  82. +#include <linux/phy.h>
  83. +#include <linux/of_net.h>
  84. +#include <linux/of_platform.h>
  85. +
  86. +#include "ar8xxx.h"
  87. +
  88. +#define MIB_DESC(_s, _o, _n) \
  89. + { \
  90. + .size = (_s), \
  91. + .offset = (_o), \
  92. + .name = (_n), \
  93. + }
  94. +
  95. +static const struct ar8xxx_mib_desc ar8327_mib[] = {
  96. + MIB_DESC(1, 0x00, "RxBroad"),
  97. + MIB_DESC(1, 0x04, "RxPause"),
  98. + MIB_DESC(1, 0x08, "RxMulti"),
  99. + MIB_DESC(1, 0x0c, "RxFcsErr"),
  100. + MIB_DESC(1, 0x10, "RxAlignErr"),
  101. + MIB_DESC(1, 0x14, "RxRunt"),
  102. + MIB_DESC(1, 0x18, "RxFragment"),
  103. + MIB_DESC(1, 0x1c, "Rx64Byte"),
  104. + MIB_DESC(1, 0x20, "Rx128Byte"),
  105. + MIB_DESC(1, 0x24, "Rx256Byte"),
  106. + MIB_DESC(1, 0x28, "Rx512Byte"),
  107. + MIB_DESC(1, 0x2c, "Rx1024Byte"),
  108. + MIB_DESC(1, 0x30, "Rx1518Byte"),
  109. + MIB_DESC(1, 0x34, "RxMaxByte"),
  110. + MIB_DESC(1, 0x38, "RxTooLong"),
  111. + MIB_DESC(2, 0x3c, "RxGoodByte"),
  112. + MIB_DESC(2, 0x44, "RxBadByte"),
  113. + MIB_DESC(1, 0x4c, "RxOverFlow"),
  114. + MIB_DESC(1, 0x50, "Filtered"),
  115. + MIB_DESC(1, 0x54, "TxBroad"),
  116. + MIB_DESC(1, 0x58, "TxPause"),
  117. + MIB_DESC(1, 0x5c, "TxMulti"),
  118. + MIB_DESC(1, 0x60, "TxUnderRun"),
  119. + MIB_DESC(1, 0x64, "Tx64Byte"),
  120. + MIB_DESC(1, 0x68, "Tx128Byte"),
  121. + MIB_DESC(1, 0x6c, "Tx256Byte"),
  122. + MIB_DESC(1, 0x70, "Tx512Byte"),
  123. + MIB_DESC(1, 0x74, "Tx1024Byte"),
  124. + MIB_DESC(1, 0x78, "Tx1518Byte"),
  125. + MIB_DESC(1, 0x7c, "TxMaxByte"),
  126. + MIB_DESC(1, 0x80, "TxOverSize"),
  127. + MIB_DESC(2, 0x84, "TxByte"),
  128. + MIB_DESC(1, 0x8c, "TxCollision"),
  129. + MIB_DESC(1, 0x90, "TxAbortCol"),
  130. + MIB_DESC(1, 0x94, "TxMultiCol"),
  131. + MIB_DESC(1, 0x98, "TxSingleCol"),
  132. + MIB_DESC(1, 0x9c, "TxExcDefer"),
  133. + MIB_DESC(1, 0xa0, "TxDefer"),
  134. + MIB_DESC(1, 0xa4, "TxLateCol"),
  135. +};
  136. +
  137. +u32
  138. +ar8xxx_mii_read32(struct mii_bus *bus, int phy_id, int regnum)
  139. +{
  140. + u16 lo, hi;
  141. +
  142. + lo = bus->read(bus, phy_id, regnum);
  143. + hi = bus->read(bus, phy_id, regnum + 1);
  144. +
  145. + return (hi << 16) | lo;
  146. +}
  147. +
  148. +void
  149. +ar8xxx_mii_write32(struct mii_bus *bus, int phy_id, int regnum, u32 val)
  150. +{
  151. + u16 lo, hi;
  152. +
  153. + lo = val & 0xffff;
  154. + hi = (u16)(val >> 16);
  155. +
  156. + bus->write(bus, phy_id, regnum, lo);
  157. + bus->write(bus, phy_id, regnum + 1, hi);
  158. +}
  159. +
  160. +u32 ar8xxx_read(struct dsa_switch *ds, int reg)
  161. +{
  162. + struct mii_bus *bus = dsa_host_dev_to_mii_bus(ds->master_dev);
  163. + u16 r1, r2, page;
  164. + u32 val;
  165. +
  166. + split_addr((u32)reg, &r1, &r2, &page);
  167. +
  168. + mutex_lock(&bus->mdio_lock);
  169. +
  170. + bus->write(bus, 0x18, 0, page);
  171. + wait_for_page_switch();
  172. + val = ar8xxx_mii_read32(bus, 0x10 | r2, r1);
  173. +
  174. + mutex_unlock(&bus->mdio_lock);
  175. +
  176. + return val;
  177. +}
  178. +
  179. +void ar8xxx_write(struct dsa_switch *ds, int reg, u32 val)
  180. +{
  181. + struct mii_bus *bus = dsa_host_dev_to_mii_bus(ds->master_dev);
  182. + u16 r1, r2, page;
  183. +
  184. + split_addr((u32)reg, &r1, &r2, &page);
  185. +
  186. + mutex_lock(&bus->mdio_lock);
  187. +
  188. + bus->write(bus, 0x18, 0, page);
  189. + wait_for_page_switch();
  190. + ar8xxx_mii_write32(bus, 0x10 | r2, r1, val);
  191. +
  192. + mutex_unlock(&bus->mdio_lock);
  193. +}
  194. +
  195. +u32
  196. +ar8xxx_rmw(struct dsa_switch *ds, int reg, u32 mask, u32 val)
  197. +{
  198. + struct mii_bus *bus = dsa_host_dev_to_mii_bus(ds->master_dev);
  199. + u16 r1, r2, page;
  200. + u32 ret;
  201. +
  202. + split_addr((u32)reg, &r1, &r2, &page);
  203. +
  204. + mutex_lock(&bus->mdio_lock);
  205. +
  206. + bus->write(bus, 0x18, 0, page);
  207. + wait_for_page_switch();
  208. +
  209. + ret = ar8xxx_mii_read32(bus, 0x10 | r2, r1);
  210. + ret &= ~mask;
  211. + ret |= val;
  212. + ar8xxx_mii_write32(bus, 0x10 | r2, r1, ret);
  213. +
  214. + mutex_unlock(&bus->mdio_lock);
  215. +
  216. + return ret;
  217. +}
  218. +
  219. +static char *ar8xxx_probe(struct device *host_dev, int sw_addr)
  220. +{
  221. + struct mii_bus *bus = dsa_host_dev_to_mii_bus(host_dev);
  222. + u32 phy_id;
  223. +
  224. + if (!bus)
  225. + return NULL;
  226. +
  227. + /* sw_addr is irrelevant as the switch occupies the MDIO bus from
  228. + * addresses 0 to 4 (PHYs) and 16-23 (for MDIO 32bits protocol). So
  229. + * we'll probe address 0 to see if we see the right switch family.
  230. + */
  231. + phy_id = mdiobus_read(bus, 0, MII_PHYSID1) << 16;
  232. + phy_id |= mdiobus_read(bus, 0, MII_PHYSID2);
  233. +
  234. + switch (phy_id) {
  235. + case PHY_ID_QCA8337:
  236. + return "QCA8337";
  237. + default:
  238. + return NULL;
  239. + }
  240. +}
  241. +
  242. +static int ar8xxx_regmap_read(void *ctx, uint32_t reg, uint32_t *val)
  243. +{
  244. + struct dsa_switch *ds = (struct dsa_switch *)ctx;
  245. +
  246. + *val = ar8xxx_read(ds, reg);
  247. +
  248. + return 0;
  249. +}
  250. +
  251. +static int ar8xxx_regmap_write(void *ctx, uint32_t reg, uint32_t val)
  252. +{
  253. + struct dsa_switch *ds = (struct dsa_switch *)ctx;
  254. +
  255. + ar8xxx_write(ds, reg, val);
  256. +
  257. + return 0;
  258. +}
  259. +
  260. +static const struct regmap_range ar8xxx_readable_ranges[] = {
  261. + regmap_reg_range(0x0000, 0x00e4), /* Global control */
  262. + regmap_reg_range(0x0100, 0x0168), /* EEE control */
  263. + regmap_reg_range(0x0200, 0x0270), /* Parser control */
  264. + regmap_reg_range(0x0400, 0x0454), /* ACL */
  265. + regmap_reg_range(0x0600, 0x0718), /* Lookup */
  266. + regmap_reg_range(0x0800, 0x0b70), /* QM */
  267. + regmap_reg_range(0x0C00, 0x0c80), /* PKT */
  268. + regmap_reg_range(0x1000, 0x10ac), /* MIB - Port0 */
  269. + regmap_reg_range(0x1100, 0x11ac), /* MIB - Port1 */
  270. + regmap_reg_range(0x1200, 0x12ac), /* MIB - Port2 */
  271. + regmap_reg_range(0x1300, 0x13ac), /* MIB - Port3 */
  272. + regmap_reg_range(0x1400, 0x14ac), /* MIB - Port4 */
  273. + regmap_reg_range(0x1500, 0x15ac), /* MIB - Port5 */
  274. + regmap_reg_range(0x1600, 0x16ac), /* MIB - Port6 */
  275. +
  276. +};
  277. +
  278. +static struct regmap_access_table ar8xxx_readable_table = {
  279. + .yes_ranges = ar8xxx_readable_ranges,
  280. + .n_yes_ranges = ARRAY_SIZE(ar8xxx_readable_ranges),
  281. +};
  282. +
  283. +struct regmap_config ar8xxx_regmap_config = {
  284. + .reg_bits = 16,
  285. + .val_bits = 32,
  286. + .reg_stride = 4,
  287. + .max_register = 0x16ac, /* end MIB - Port6 range */
  288. + .reg_read = ar8xxx_regmap_read,
  289. + .reg_write = ar8xxx_regmap_write,
  290. + .rd_table = &ar8xxx_readable_table,
  291. +};
  292. +
  293. +static int ar8xxx_set_pad_ctrl(struct dsa_switch *ds, int port, int mode)
  294. +{
  295. + int reg;
  296. +
  297. + switch (port) {
  298. + case 0:
  299. + reg = AR8327_REG_PORT0_PAD_CTRL;
  300. + break;
  301. + case 6:
  302. + reg = AR8327_REG_PORT6_PAD_CTRL;
  303. + break;
  304. + default:
  305. + pr_err("Can't set PAD_CTRL on port %d\n", port);
  306. + return -EINVAL;
  307. + }
  308. +
  309. + /* DSA only supports 1 CPU port for now, so we'll take the assumption
  310. + * that P0 is connected to the CPU master_dev.
  311. + */
  312. + switch (mode) {
  313. + case PHY_INTERFACE_MODE_RGMII:
  314. + ar8xxx_write(ds, reg,
  315. + AR8327_PORT_PAD_RGMII_EN |
  316. + AR8327_PORT_PAD_RGMII_TX_DELAY(3) |
  317. + AR8327_PORT_PAD_RGMII_RX_DELAY(3));
  318. +
  319. + /* According to the datasheet, RGMII delay is enabled through
  320. + * PORT5_PAD_CTRL for all ports, rather than individual port
  321. + * registers
  322. + */
  323. + ar8xxx_write(ds, AR8327_REG_PORT5_PAD_CTRL,
  324. + AR8327_PORT_PAD_RGMII_RX_DELAY_EN);
  325. + break;
  326. + case PHY_INTERFACE_MODE_SGMII:
  327. + ar8xxx_write(ds, reg, AR8327_PORT_PAD_SGMII_EN);
  328. + break;
  329. + default:
  330. + pr_err("xMII mode %d not supported\n", mode);
  331. + return -EINVAL;
  332. + }
  333. +
  334. + return 0;
  335. +}
  336. +
  337. +static int ar8xxx_of_setup(struct dsa_switch *ds)
  338. +{
  339. + struct device_node *dn = ds->pd->of_node;
  340. + const char *s_phymode;
  341. + int ret, mode;
  342. + u32 phy_id, ctrl;
  343. +
  344. + /* If port6-phy-mode property exists, configure it accordingly */
  345. + if (!of_property_read_string(dn, "qca,port6-phy-mode", &s_phymode)) {
  346. + for (mode = 0; mode < PHY_INTERFACE_MODE_MAX; mode++)
  347. + if (!strcasecmp(s_phymode, phy_modes(mode)))
  348. + break;
  349. +
  350. + if (mode == PHY_INTERFACE_MODE_MAX)
  351. + pr_err("Unknown phy-mode: \"%s\"\n", s_phymode);
  352. +
  353. + ret = ar8xxx_set_pad_ctrl(ds, 6, mode);
  354. + if (ret < 0)
  355. + return ret;
  356. + }
  357. +
  358. + /* If a phy ID is specified for PORT6 mac, connect them together */
  359. + if (!of_property_read_u32(dn, "qca,port6-phy-id", &phy_id)) {
  360. + ar8xxx_rmw(ds, AR8327_PORT_LOOKUP_CTRL(6),
  361. + AR8327_PORT_LOOKUP_MEMBER, BIT(phy_to_port(phy_id)));
  362. + ar8xxx_rmw(ds, AR8327_PORT_LOOKUP_CTRL(phy_to_port(phy_id)),
  363. + AR8327_PORT_LOOKUP_MEMBER, BIT(6));
  364. +
  365. + /* We want the switch to be pass-through and act like a PHY on
  366. + * these ports. So BC/MC/UC & IGMP frames need to be accepted
  367. + */
  368. + ctrl = BIT(phy_to_port(phy_id)) | BIT(6);
  369. + ar8xxx_reg_set(ds, AR8327_REG_GLOBAL_FW_CTRL1,
  370. + ctrl << AR8327_GLOBAL_FW_CTRL1_IGMP_DP_S |
  371. + ctrl << AR8327_GLOBAL_FW_CTRL1_BC_DP_S |
  372. + ctrl << AR8327_GLOBAL_FW_CTRL1_MC_DP_S |
  373. + ctrl << AR8327_GLOBAL_FW_CTRL1_UC_DP_S);
  374. + }
  375. +
  376. + return 0;
  377. +}
  378. +
  379. +static int ar8xxx_setup(struct dsa_switch *ds)
  380. +{
  381. + struct ar8xxx_priv *priv = ds_to_priv(ds);
  382. + struct net_device *netdev = ds->dst->pd->of_netdev;
  383. + int ret, i, phy_mode;
  384. +
  385. + /* Start by setting up the register mapping */
  386. + priv->regmap = devm_regmap_init(ds->master_dev, NULL, ds,
  387. + &ar8xxx_regmap_config);
  388. +
  389. + if (IS_ERR(priv->regmap))
  390. + pr_warn("regmap initialization failed");
  391. +
  392. + /* Initialize CPU port pad mode (xMII type, delays...) */
  393. + phy_mode = of_get_phy_mode(netdev->dev.parent->of_node);
  394. + if (phy_mode < 0) {
  395. + pr_err("Can't find phy-mode for master device\n");
  396. + return phy_mode;
  397. + }
  398. +
  399. + ret = ar8xxx_set_pad_ctrl(ds, 0, phy_mode);
  400. + if (ret < 0)
  401. + return ret;
  402. +
  403. + /* Enable CPU Port */
  404. + ar8xxx_reg_set(ds, AR8327_REG_GLOBAL_FW_CTRL0,
  405. + AR8327_GLOBAL_FW_CTRL0_CPU_PORT_EN);
  406. +
  407. + /* Enable MIB counters */
  408. + ar8xxx_reg_set(ds, AR8327_REG_MIB, AR8327_MIB_CPU_KEEP);
  409. + ar8xxx_write(ds, AR8327_REG_MODULE_EN, AR8327_MODULE_EN_MIB);
  410. +
  411. + /* Enable QCA header mode on Port 0 */
  412. + ar8xxx_write(ds, AR8327_REG_PORT_HDR_CTRL(0),
  413. + AR8327_PORT_HDR_CTRL_ALL << AR8327_PORT_HDR_CTRL_TX_S |
  414. + AR8327_PORT_HDR_CTRL_ALL << AR8327_PORT_HDR_CTRL_RX_S);
  415. +
  416. + /* Disable forwarding by default on all ports */
  417. + for (i = 0; i < AR8327_NUM_PORTS; i++)
  418. + ar8xxx_rmw(ds, AR8327_PORT_LOOKUP_CTRL(i),
  419. + AR8327_PORT_LOOKUP_MEMBER, 0);
  420. +
  421. + /* Forward all unknown frames to CPU port for Linux processing */
  422. + ar8xxx_write(ds, AR8327_REG_GLOBAL_FW_CTRL1,
  423. + BIT(0) << AR8327_GLOBAL_FW_CTRL1_IGMP_DP_S |
  424. + BIT(0) << AR8327_GLOBAL_FW_CTRL1_BC_DP_S |
  425. + BIT(0) << AR8327_GLOBAL_FW_CTRL1_MC_DP_S |
  426. + BIT(0) << AR8327_GLOBAL_FW_CTRL1_UC_DP_S);
  427. +
  428. + /* Setup connection between CPU ports & PHYs */
  429. + for (i = 0; i < DSA_MAX_PORTS; i++) {
  430. + /* CPU port gets connected to all PHYs in the switch */
  431. + if (dsa_is_cpu_port(ds, i)) {
  432. + ar8xxx_rmw(ds, AR8327_PORT_LOOKUP_CTRL(0),
  433. + AR8327_PORT_LOOKUP_MEMBER,
  434. + ds->phys_port_mask << 1);
  435. + }
  436. +
  437. + /* Invividual PHYs gets connected to CPU port only */
  438. + if (ds->phys_port_mask & BIT(i)) {
  439. + int phy = phy_to_port(i);
  440. +
  441. + ar8xxx_rmw(ds, AR8327_PORT_LOOKUP_CTRL(phy),
  442. + AR8327_PORT_LOOKUP_MEMBER, BIT(0));
  443. +
  444. + /* Disable Auto-learning by default so the switch
  445. + * doesn't try to forward the frame to another port
  446. + */
  447. + ar8xxx_reg_clear(ds, AR8327_PORT_LOOKUP_CTRL(phy),
  448. + AR8327_PORT_LOOKUP_LEARN);
  449. + }
  450. + }
  451. +
  452. + ret = ar8xxx_of_setup(ds);
  453. + if (ret < 0)
  454. + return ret;
  455. +
  456. + return 0;
  457. +}
  458. +
  459. +static int ar8xxx_set_addr(struct dsa_switch *ds, u8 *addr)
  460. +{
  461. + return 0;
  462. +}
  463. +
  464. +static int ar8xxx_phy_read(struct dsa_switch *ds, int phy, int regnum)
  465. +{
  466. + struct mii_bus *bus = dsa_host_dev_to_mii_bus(ds->master_dev);
  467. +
  468. + return mdiobus_read(bus, phy, regnum);
  469. +}
  470. +
  471. +static int
  472. +ar8xxx_phy_write(struct dsa_switch *ds, int phy, int regnum, u16 val)
  473. +{
  474. + struct mii_bus *bus = dsa_host_dev_to_mii_bus(ds->master_dev);
  475. +
  476. + return mdiobus_write(bus, phy, regnum, val);
  477. +}
  478. +
  479. +static void ar8xxx_get_strings(struct dsa_switch *ds, int phy, uint8_t *data)
  480. +{
  481. + int i;
  482. +
  483. + for (i = 0; i < ARRAY_SIZE(ar8327_mib); i++) {
  484. + strncpy(data + i * ETH_GSTRING_LEN, ar8327_mib[i].name,
  485. + ETH_GSTRING_LEN);
  486. + }
  487. +}
  488. +
  489. +static void ar8xxx_get_ethtool_stats(struct dsa_switch *ds, int phy,
  490. + uint64_t *data)
  491. +{
  492. + const struct ar8xxx_mib_desc *mib;
  493. + uint32_t reg, i, port;
  494. + u64 hi;
  495. +
  496. + port = phy_to_port(phy);
  497. +
  498. + for (i = 0; i < ARRAY_SIZE(ar8327_mib); i++) {
  499. + mib = &ar8327_mib[i];
  500. + reg = AR8327_PORT_MIB_COUNTER(port) + mib->offset;
  501. +
  502. + data[i] = ar8xxx_read(ds, reg);
  503. + if (mib->size == 2) {
  504. + hi = ar8xxx_read(ds, reg + 4);
  505. + data[i] |= hi << 32;
  506. + }
  507. + }
  508. +}
  509. +
  510. +static int ar8xxx_get_sset_count(struct dsa_switch *ds)
  511. +{
  512. + return ARRAY_SIZE(ar8327_mib);
  513. +}
  514. +
  515. +static void ar8xxx_poll_link(struct dsa_switch *ds)
  516. +{
  517. + int i = 0;
  518. + struct net_device *dev;
  519. +
  520. + while ((dev = ds->ports[i++]) != NULL) {
  521. + u32 status;
  522. + int link;
  523. + int speed;
  524. + int duplex;
  525. +
  526. + status = ar8xxx_read(ds, AR8327_REG_PORT_STATUS(i));
  527. + link = !!(status & AR8XXX_PORT_STATUS_LINK_UP);
  528. + duplex = !!(status & AR8XXX_PORT_STATUS_DUPLEX);
  529. +
  530. + switch (status & AR8XXX_PORT_STATUS_SPEED) {
  531. + case AR8XXX_PORT_SPEED_10M:
  532. + speed = 10;
  533. + break;
  534. + case AR8XXX_PORT_SPEED_100M:
  535. + speed = 100;
  536. + break;
  537. + case AR8XXX_PORT_SPEED_1000M:
  538. + speed = 1000;
  539. + break;
  540. + default:
  541. + speed = 0;
  542. + }
  543. +
  544. + if (!link) {
  545. + /* This poll happens every ~1s, so we don't want to
  546. + * print the status every time. Only when the device
  547. + * transitions from Link UP to Link DOWN
  548. + */
  549. + if (netif_carrier_ok(dev))
  550. + netif_carrier_off(dev);
  551. + continue;
  552. + } else {
  553. + /* Same thing here. But we detect a Link UP event */
  554. + if (!netif_carrier_ok(dev))
  555. + netif_carrier_on(dev);
  556. + continue;
  557. + }
  558. + }
  559. +}
  560. +
  561. +static struct dsa_switch_driver ar8xxx_switch_driver = {
  562. + .tag_protocol = DSA_TAG_PROTO_QCA,
  563. + .priv_size = sizeof(struct ar8xxx_priv),
  564. + .probe = ar8xxx_probe,
  565. + .setup = ar8xxx_setup,
  566. + .set_addr = ar8xxx_set_addr,
  567. + .poll_link = ar8xxx_poll_link,
  568. + .phy_read = ar8xxx_phy_read,
  569. + .phy_write = ar8xxx_phy_write,
  570. + .get_strings = ar8xxx_get_strings,
  571. + .get_ethtool_stats = ar8xxx_get_ethtool_stats,
  572. + .get_sset_count = ar8xxx_get_sset_count,
  573. +};
  574. +
  575. +static int __init ar8xxx_init(void)
  576. +{
  577. + register_switch_driver(&ar8xxx_switch_driver);
  578. + return 0;
  579. +}
  580. +module_init(ar8xxx_init);
  581. +
  582. +static void __exit ar8xxx_cleanup(void)
  583. +{
  584. + unregister_switch_driver(&ar8xxx_switch_driver);
  585. +}
  586. +module_exit(ar8xxx_cleanup);
  587. +
  588. +MODULE_AUTHOR("Mathieu Olivari <mathieu@codeaurora.org>");
  589. +MODULE_DESCRIPTION("Driver for AR8XXX ethernet switch family");
  590. +MODULE_LICENSE("GPL");
  591. +MODULE_ALIAS("platform:ar8xxx");
  592. --- /dev/null
  593. +++ b/drivers/net/dsa/ar8xxx.h
  594. @@ -0,0 +1,156 @@
  595. +/*
  596. + * Copyright (C) 2009 Felix Fietkau <nbd@nbd.name>
  597. + * Copyright (C) 2011-2012 Gabor Juhos <juhosg@openwrt.org>
  598. + * Copyright (c) 2015, The Linux Foundation. All rights reserved.
  599. + *
  600. + * This program is free software; you can redistribute it and/or modify
  601. + * it under the terms of the GNU General Public License version 2 and
  602. + * only version 2 as published by the Free Software Foundation.
  603. + *
  604. + * This program is distributed in the hope that it will be useful,
  605. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  606. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  607. + * GNU General Public License for more details.
  608. + */
  609. +
  610. +#ifndef __AR8XXX_H
  611. +#define __AR8XXX_H
  612. +
  613. +#include <linux/delay.h>
  614. +#include <linux/regmap.h>
  615. +
  616. +struct ar8xxx_priv {
  617. + struct regmap *regmap;
  618. +};
  619. +
  620. +struct ar8xxx_mib_desc {
  621. + unsigned int size;
  622. + unsigned int offset;
  623. + const char *name;
  624. +};
  625. +
  626. +#define AR8327_NUM_PORTS 7
  627. +
  628. +#define PHY_ID_QCA8337 0x004dd036
  629. +
  630. +#define AR8327_REG_PORT0_PAD_CTRL 0x004
  631. +#define AR8327_REG_PORT5_PAD_CTRL 0x008
  632. +#define AR8327_REG_PORT6_PAD_CTRL 0x00c
  633. +#define AR8327_PORT_PAD_RGMII_EN BIT(26)
  634. +#define AR8327_PORT_PAD_RGMII_TX_DELAY(x) ((0x8 + (x & 0x3)) << 22)
  635. +#define AR8327_PORT_PAD_RGMII_RX_DELAY(x) ((0x10 + (x & 0x3)) << 20)
  636. +#define AR8327_PORT_PAD_RGMII_RX_DELAY_EN BIT(24)
  637. +#define AR8327_PORT_PAD_SGMII_EN BIT(7)
  638. +
  639. +#define AR8327_REG_MODULE_EN 0x030
  640. +#define AR8327_MODULE_EN_MIB BIT(0)
  641. +#define AR8327_MODULE_EN_ACL BIT(1)
  642. +#define AR8327_MODULE_EN_L3 BIT(2)
  643. +
  644. +#define AR8327_REG_MIB 0x034
  645. +#define AR8327_MIB_CPU_KEEP BIT(20)
  646. +
  647. +#define AR8327_REG_PORT_STATUS(_i) (0x07c + (_i) * 4)
  648. +#define AR8XXX_PORT_STATUS_SPEED GENMASK(2, 0)
  649. +#define AR8XXX_PORT_STATUS_SPEED_S 0
  650. +#define AR8XXX_PORT_STATUS_TXMAC BIT(2)
  651. +#define AR8XXX_PORT_STATUS_RXMAC BIT(3)
  652. +#define AR8XXX_PORT_STATUS_TXFLOW BIT(4)
  653. +#define AR8XXX_PORT_STATUS_RXFLOW BIT(5)
  654. +#define AR8XXX_PORT_STATUS_DUPLEX BIT(6)
  655. +#define AR8XXX_PORT_STATUS_LINK_UP BIT(8)
  656. +#define AR8XXX_PORT_STATUS_LINK_AUTO BIT(9)
  657. +#define AR8XXX_PORT_STATUS_LINK_PAUSE BIT(10)
  658. +
  659. +#define AR8327_REG_PORT_HDR_CTRL(_i) (0x9c + (_i * 4))
  660. +#define AR8327_PORT_HDR_CTRL_RX_MASK GENMASK(3, 2)
  661. +#define AR8327_PORT_HDR_CTRL_RX_S 2
  662. +#define AR8327_PORT_HDR_CTRL_TX_MASK GENMASK(1, 0)
  663. +#define AR8327_PORT_HDR_CTRL_TX_S 0
  664. +#define AR8327_PORT_HDR_CTRL_ALL 2
  665. +#define AR8327_PORT_HDR_CTRL_MGMT 1
  666. +#define AR8327_PORT_HDR_CTRL_NONE 0
  667. +
  668. +#define AR8327_REG_GLOBAL_FW_CTRL0 0x620
  669. +#define AR8327_GLOBAL_FW_CTRL0_CPU_PORT_EN BIT(10)
  670. +
  671. +#define AR8327_REG_GLOBAL_FW_CTRL1 0x624
  672. +#define AR8327_GLOBAL_FW_CTRL1_IGMP_DP_MASK GENMASK(30, 24)
  673. +#define AR8327_GLOBAL_FW_CTRL1_IGMP_DP_S 24
  674. +#define AR8327_GLOBAL_FW_CTRL1_BC_DP_MASK GENMASK(22, 16)
  675. +#define AR8327_GLOBAL_FW_CTRL1_BC_DP_S 16
  676. +#define AR8327_GLOBAL_FW_CTRL1_MC_DP_MASK GENMASK(14, 8)
  677. +#define AR8327_GLOBAL_FW_CTRL1_MC_DP_S 8
  678. +#define AR8327_GLOBAL_FW_CTRL1_UC_DP_MASK GENMASK(6, 0)
  679. +#define AR8327_GLOBAL_FW_CTRL1_UC_DP_S 0
  680. +
  681. +#define AR8327_PORT_LOOKUP_CTRL(_i) (0x660 + (_i) * 0xc)
  682. +#define AR8327_PORT_LOOKUP_MEMBER GENMASK(6, 0)
  683. +#define AR8327_PORT_LOOKUP_IN_MODE GENMASK(9, 8)
  684. +#define AR8327_PORT_LOOKUP_IN_MODE_S 8
  685. +#define AR8327_PORT_LOOKUP_STATE GENMASK(18, 16)
  686. +#define AR8327_PORT_LOOKUP_STATE_S 16
  687. +#define AR8327_PORT_LOOKUP_LEARN BIT(20)
  688. +#define AR8327_PORT_LOOKUP_ING_MIRROR_EN BIT(25)
  689. +
  690. +#define AR8327_PORT_MIB_COUNTER(_i) (0x1000 + (_i) * 0x100)
  691. +
  692. +/* port speed */
  693. +enum {
  694. + AR8XXX_PORT_SPEED_10M = 0,
  695. + AR8XXX_PORT_SPEED_100M = 1,
  696. + AR8XXX_PORT_SPEED_1000M = 2,
  697. + AR8XXX_PORT_SPEED_ERR = 3,
  698. +};
  699. +
  700. +static inline int port_to_phy(int port)
  701. +{
  702. + if (port >= 1 && port <= 6)
  703. + return port - 1;
  704. +
  705. + return -1;
  706. +}
  707. +
  708. +static inline int phy_to_port(int phy)
  709. +{
  710. + if (phy < 5)
  711. + return phy + 1;
  712. +
  713. + return -1;
  714. +}
  715. +
  716. +u32
  717. +ar8xxx_rmw(struct dsa_switch *ds, int reg, u32 mask, u32 val);
  718. +
  719. +static inline void
  720. +split_addr(u32 regaddr, u16 *r1, u16 *r2, u16 *page)
  721. +{
  722. + regaddr >>= 1;
  723. + *r1 = regaddr & 0x1e;
  724. +
  725. + regaddr >>= 5;
  726. + *r2 = regaddr & 0x7;
  727. +
  728. + regaddr >>= 3;
  729. + *page = regaddr & 0x1ff;
  730. +}
  731. +
  732. +static inline void
  733. +wait_for_page_switch(void)
  734. +{
  735. + udelay(5);
  736. +}
  737. +
  738. +static inline void
  739. +ar8xxx_reg_set(struct dsa_switch *ds, int reg, u32 val)
  740. +{
  741. + ar8xxx_rmw(ds, reg, 0, val);
  742. +}
  743. +
  744. +static inline void
  745. +ar8xxx_reg_clear(struct dsa_switch *ds, int reg, u32 val)
  746. +{
  747. + ar8xxx_rmw(ds, reg, val, 0);
  748. +}
  749. +
  750. +#endif /* __AR8XXX_H */
  751. --- a/net/dsa/dsa.c
  752. +++ b/net/dsa/dsa.c
  753. @@ -285,6 +285,11 @@ static int dsa_switch_setup_one(struct d
  754. dst->rcv = brcm_netdev_ops.rcv;
  755. break;
  756. #endif
  757. +#ifdef CONFIG_NET_DSA_TAG_QCA
  758. + case DSA_TAG_PROTO_QCA:
  759. + dst->rcv = qca_netdev_ops.rcv;
  760. + break;
  761. +#endif
  762. case DSA_TAG_PROTO_NONE:
  763. break;
  764. default:
  765. @@ -1041,6 +1046,7 @@ static SIMPLE_DEV_PM_OPS(dsa_pm_ops, dsa
  766. static const struct of_device_id dsa_of_match_table[] = {
  767. { .compatible = "brcm,bcm7445-switch-v4.0" },
  768. + { .compatible = "qca,ar8xxx", },
  769. { .compatible = "marvell,dsa", },
  770. {}
  771. };
  772. --- a/include/net/dsa.h
  773. +++ b/include/net/dsa.h
  774. @@ -26,6 +26,7 @@ enum dsa_tag_protocol {
  775. DSA_TAG_PROTO_TRAILER,
  776. DSA_TAG_PROTO_EDSA,
  777. DSA_TAG_PROTO_BRCM,
  778. + DSA_TAG_PROTO_QCA,
  779. };
  780. #define DSA_MAX_SWITCHES 4
  781. --- a/net/dsa/Kconfig
  782. +++ b/net/dsa/Kconfig
  783. @@ -27,6 +27,9 @@ config NET_DSA_HWMON
  784. via the hwmon sysfs interface and exposes the onboard sensors.
  785. # tagging formats
  786. +config NET_DSA_TAG_QCA
  787. + bool
  788. +
  789. config NET_DSA_TAG_BRCM
  790. bool
  791. --- a/net/dsa/Makefile
  792. +++ b/net/dsa/Makefile
  793. @@ -3,6 +3,7 @@ obj-$(CONFIG_NET_DSA) += dsa_core.o
  794. dsa_core-y += dsa.o slave.o
  795. # tagging formats
  796. +dsa_core-$(CONFIG_NET_DSA_TAG_QCA) += tag_qca.o
  797. dsa_core-$(CONFIG_NET_DSA_TAG_BRCM) += tag_brcm.o
  798. dsa_core-$(CONFIG_NET_DSA_TAG_DSA) += tag_dsa.o
  799. dsa_core-$(CONFIG_NET_DSA_TAG_EDSA) += tag_edsa.o
  800. --- a/net/dsa/dsa_priv.h
  801. +++ b/net/dsa/dsa_priv.h
  802. @@ -78,5 +78,7 @@ extern const struct dsa_device_ops trail
  803. /* tag_brcm.c */
  804. extern const struct dsa_device_ops brcm_netdev_ops;
  805. +/* tag_qca.c */
  806. +extern const struct dsa_device_ops qca_netdev_ops;
  807. #endif
  808. --- a/net/dsa/slave.c
  809. +++ b/net/dsa/slave.c
  810. @@ -1190,6 +1190,11 @@ int dsa_slave_create(struct dsa_switch *
  811. p->xmit = brcm_netdev_ops.xmit;
  812. break;
  813. #endif
  814. +#ifdef CONFIG_NET_DSA_TAG_QCA
  815. + case DSA_TAG_PROTO_QCA:
  816. + p->xmit = qca_netdev_ops.xmit;
  817. + break;
  818. +#endif
  819. default:
  820. p->xmit = dsa_slave_notag_xmit;
  821. break;
  822. --- /dev/null
  823. +++ b/net/dsa/tag_qca.c
  824. @@ -0,0 +1,158 @@
  825. +/*
  826. + * Copyright (c) 2015, The Linux Foundation. All rights reserved.
  827. + *
  828. + * This program is free software; you can redistribute it and/or modify
  829. + * it under the terms of the GNU General Public License version 2 and
  830. + * only version 2 as published by the Free Software Foundation.
  831. + *
  832. + * This program is distributed in the hope that it will be useful,
  833. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  834. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  835. + * GNU General Public License for more details.
  836. + */
  837. +
  838. +#include <linux/etherdevice.h>
  839. +#include "dsa_priv.h"
  840. +
  841. +#define QCA_HDR_LEN 2
  842. +#define QCA_HDR_VERSION 0x2
  843. +
  844. +#define QCA_HDR_RECV_VERSION_MASK GENMASK(15, 14)
  845. +#define QCA_HDR_RECV_VERSION_S 14
  846. +#define QCA_HDR_RECV_PRIORITY_MASK GENMASK(13, 11)
  847. +#define QCA_HDR_RECV_PRIORITY_S 11
  848. +#define QCA_HDR_RECV_TYPE_MASK GENMASK(10, 6)
  849. +#define QCA_HDR_RECV_TYPE_S 6
  850. +#define QCA_HDR_RECV_FRAME_IS_TAGGED BIT(3)
  851. +#define QCA_HDR_RECV_SOURCE_PORT_MASK GENMASK(2, 0)
  852. +
  853. +#define QCA_HDR_XMIT_VERSION_MASK GENMASK(15, 14)
  854. +#define QCA_HDR_XMIT_VERSION_S 14
  855. +#define QCA_HDR_XMIT_PRIORITY_MASK GENMASK(13, 11)
  856. +#define QCA_HDR_XMIT_PRIORITY_S 11
  857. +#define QCA_HDR_XMIT_CONTROL_MASK GENMASK(10, 8)
  858. +#define QCA_HDR_XMIT_CONTROL_S 8
  859. +#define QCA_HDR_XMIT_FROM_CPU BIT(7)
  860. +#define QCA_HDR_XMIT_DP_BIT_MASK GENMASK(6, 0)
  861. +
  862. +static inline int reg_to_port(int reg)
  863. +{
  864. + if (reg < 5)
  865. + return reg + 1;
  866. +
  867. + return -1;
  868. +}
  869. +
  870. +static inline int port_to_reg(int port)
  871. +{
  872. + if (port >= 1 && port <= 6)
  873. + return port - 1;
  874. +
  875. + return -1;
  876. +}
  877. +
  878. +static netdev_tx_t qca_tag_xmit(struct sk_buff *skb, struct net_device *dev)
  879. +{
  880. + struct dsa_slave_priv *p = netdev_priv(dev);
  881. + u16 *phdr, hdr;
  882. +
  883. + dev->stats.tx_packets++;
  884. + dev->stats.tx_bytes += skb->len;
  885. +
  886. + if (skb_cow_head(skb, 0) < 0)
  887. + goto out_free;
  888. +
  889. + skb_push(skb, QCA_HDR_LEN);
  890. +
  891. + memmove(skb->data, skb->data + QCA_HDR_LEN, 2 * ETH_ALEN);
  892. + phdr = (u16 *)(skb->data + 2 * ETH_ALEN);
  893. +
  894. + /* Set the version field, and set destination port information */
  895. + hdr = QCA_HDR_VERSION << QCA_HDR_XMIT_VERSION_S |
  896. + QCA_HDR_XMIT_FROM_CPU |
  897. + 1 << reg_to_port(p->port);
  898. +
  899. + *phdr = htons(hdr);
  900. +
  901. + skb->dev = p->parent->dst->master_netdev;
  902. + dev_queue_xmit(skb);
  903. +
  904. + return NETDEV_TX_OK;
  905. +
  906. +out_free:
  907. + kfree_skb(skb);
  908. + return NETDEV_TX_OK;
  909. +}
  910. +
  911. +static int qca_tag_rcv(struct sk_buff *skb, struct net_device *dev,
  912. + struct packet_type *pt, struct net_device *orig_dev)
  913. +{
  914. + struct dsa_switch_tree *dst = dev->dsa_ptr;
  915. + struct dsa_switch *ds;
  916. + u8 ver;
  917. + int port, phy;
  918. + __be16 *phdr, hdr;
  919. +
  920. + if (unlikely(!dst))
  921. + goto out_drop;
  922. +
  923. + skb = skb_unshare(skb, GFP_ATOMIC);
  924. + if (!skb)
  925. + goto out;
  926. +
  927. + if (unlikely(!pskb_may_pull(skb, QCA_HDR_LEN)))
  928. + goto out_drop;
  929. +
  930. + /* Ethernet is added by the switch between src addr and Ethertype
  931. + * At this point, skb->data points to ethertype so header should be
  932. + * right before
  933. + */
  934. + phdr = (__be16 *)(skb->data - 2);
  935. + hdr = ntohs(*phdr);
  936. +
  937. + /* Make sure the version is correct */
  938. + ver = (hdr & QCA_HDR_RECV_VERSION_MASK) >> QCA_HDR_RECV_VERSION_S;
  939. + if (unlikely(ver != QCA_HDR_VERSION))
  940. + goto out_drop;
  941. +
  942. + /* Remove QCA tag and recalculate checksum */
  943. + skb_pull_rcsum(skb, QCA_HDR_LEN);
  944. + memmove(skb->data - ETH_HLEN, skb->data - ETH_HLEN - QCA_HDR_LEN,
  945. + ETH_HLEN - QCA_HDR_LEN);
  946. +
  947. + /* This protocol doesn't support cascading multiple switches so it's
  948. + * safe to assume the switch is first in the tree
  949. + */
  950. + ds = dst->ds[0];
  951. + if (!ds)
  952. + goto out_drop;
  953. +
  954. + /* Get source port information */
  955. + port = (hdr & QCA_HDR_RECV_SOURCE_PORT_MASK);
  956. + phy = port_to_reg(port);
  957. + if (unlikely(phy < 0) || !ds->ports[phy])
  958. + goto out_drop;
  959. +
  960. + /* Update skb & forward the frame accordingly */
  961. + skb_push(skb, ETH_HLEN);
  962. + skb->pkt_type = PACKET_HOST;
  963. + skb->dev = ds->ports[phy];
  964. + skb->protocol = eth_type_trans(skb, skb->dev);
  965. +
  966. + skb->dev->stats.rx_packets++;
  967. + skb->dev->stats.rx_bytes += skb->len;
  968. +
  969. + netif_receive_skb(skb);
  970. +
  971. + return 0;
  972. +
  973. +out_drop:
  974. + kfree_skb(skb);
  975. +out:
  976. + return 0;
  977. +}
  978. +
  979. +const struct dsa_device_ops qca_netdev_ops = {
  980. + .xmit = qca_tag_xmit,
  981. + .rcv = qca_tag_rcv,
  982. +};
  983. --- /dev/null
  984. +++ b/Documentation/devicetree/bindings/net/dsa/qca-ar8xxx.txt
  985. @@ -0,0 +1,70 @@
  986. +* Qualcomm Atheros AR8xxx switch family
  987. +
  988. +Required properties:
  989. +
  990. +- compatible: should be "qca,ar8xxx"
  991. +- dsa,mii-bus: phandle to the MDIO bus controller, see dsa/dsa.txt
  992. +- dsa,ethernet: phandle to the CPU network interface controller, see dsa/dsa.txt
  993. +- #size-cells: must be 0
  994. +- #address-cells: must be 2, see dsa/dsa.txt
  995. +
  996. +Subnodes:
  997. +
  998. +The integrated switch subnode should be specified according to the binding
  999. +described in dsa/dsa.txt.
  1000. +
  1001. +Optional properties:
  1002. +
  1003. +- qca,port6-phy-mode: if specified, the driver will configure Port 6 in the
  1004. + given phy-mode. See Documentation/devicetree/bindings/net/ethernet.txt for
  1005. + the list of valid phy-mode.
  1006. +
  1007. +- qca,port6-phy-id: if specified, the driver will connect Port 6 to the PHY
  1008. + given as a parameter. In this case, Port6 and the corresponding PHY will be
  1009. + isolated from the rest of the switch. From a system perspective, they will
  1010. + act as a regular PHY.
  1011. +
  1012. +Example:
  1013. +
  1014. + dsa@0 {
  1015. + compatible = "qca,ar8xxx";
  1016. + #address-cells = <2>;
  1017. + #size-cells = <0>;
  1018. +
  1019. + dsa,ethernet = <&ethernet0>;
  1020. + dsa,mii-bus = <&mii_bus0>;
  1021. +
  1022. + switch@0 {
  1023. + #address-cells = <1>;
  1024. + #size-cells = <0>;
  1025. + reg = <0 0>; /* MDIO address 0, switch 0 in tree */
  1026. +
  1027. + qca,port6-phy-mode = "sgmii";
  1028. + qca,port6-phy-id = <4>;
  1029. +
  1030. + port@0 {
  1031. + reg = <11>;
  1032. + label = "cpu";
  1033. + };
  1034. +
  1035. + port@1 {
  1036. + reg = <0>;
  1037. + label = "lan1";
  1038. + };
  1039. +
  1040. + port@2 {
  1041. + reg = <1>;
  1042. + label = "lan2";
  1043. + };
  1044. +
  1045. + port@3 {
  1046. + reg = <2>;
  1047. + label = "lan3";
  1048. + };
  1049. +
  1050. + port@4 {
  1051. + reg = <3>;
  1052. + label = "lan4";
  1053. + };
  1054. + };
  1055. + };