ksz_common.c 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228
  1. /*
  2. * Microchip switch driver main logic
  3. *
  4. * Copyright (C) 2017
  5. *
  6. * Permission to use, copy, modify, and/or distribute this software for any
  7. * purpose with or without fee is hereby granted, provided that the above
  8. * copyright notice and this permission notice appear in all copies.
  9. *
  10. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  11. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  12. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  13. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  14. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  15. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  16. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  17. */
  18. #include <linux/delay.h>
  19. #include <linux/export.h>
  20. #include <linux/gpio.h>
  21. #include <linux/kernel.h>
  22. #include <linux/module.h>
  23. #include <linux/platform_data/microchip-ksz.h>
  24. #include <linux/phy.h>
  25. #include <linux/etherdevice.h>
  26. #include <linux/if_bridge.h>
  27. #include <net/dsa.h>
  28. #include <net/switchdev.h>
  29. #include "ksz_priv.h"
  30. static const struct {
  31. int index;
  32. char string[ETH_GSTRING_LEN];
  33. } mib_names[TOTAL_SWITCH_COUNTER_NUM] = {
  34. { 0x00, "rx_hi" },
  35. { 0x01, "rx_undersize" },
  36. { 0x02, "rx_fragments" },
  37. { 0x03, "rx_oversize" },
  38. { 0x04, "rx_jabbers" },
  39. { 0x05, "rx_symbol_err" },
  40. { 0x06, "rx_crc_err" },
  41. { 0x07, "rx_align_err" },
  42. { 0x08, "rx_mac_ctrl" },
  43. { 0x09, "rx_pause" },
  44. { 0x0A, "rx_bcast" },
  45. { 0x0B, "rx_mcast" },
  46. { 0x0C, "rx_ucast" },
  47. { 0x0D, "rx_64_or_less" },
  48. { 0x0E, "rx_65_127" },
  49. { 0x0F, "rx_128_255" },
  50. { 0x10, "rx_256_511" },
  51. { 0x11, "rx_512_1023" },
  52. { 0x12, "rx_1024_1522" },
  53. { 0x13, "rx_1523_2000" },
  54. { 0x14, "rx_2001" },
  55. { 0x15, "tx_hi" },
  56. { 0x16, "tx_late_col" },
  57. { 0x17, "tx_pause" },
  58. { 0x18, "tx_bcast" },
  59. { 0x19, "tx_mcast" },
  60. { 0x1A, "tx_ucast" },
  61. { 0x1B, "tx_deferred" },
  62. { 0x1C, "tx_total_col" },
  63. { 0x1D, "tx_exc_col" },
  64. { 0x1E, "tx_single_col" },
  65. { 0x1F, "tx_mult_col" },
  66. { 0x80, "rx_total" },
  67. { 0x81, "tx_total" },
  68. { 0x82, "rx_discards" },
  69. { 0x83, "tx_discards" },
  70. };
  71. static void ksz_cfg(struct ksz_device *dev, u32 addr, u8 bits, bool set)
  72. {
  73. u8 data;
  74. ksz_read8(dev, addr, &data);
  75. if (set)
  76. data |= bits;
  77. else
  78. data &= ~bits;
  79. ksz_write8(dev, addr, data);
  80. }
  81. static void ksz_cfg32(struct ksz_device *dev, u32 addr, u32 bits, bool set)
  82. {
  83. u32 data;
  84. ksz_read32(dev, addr, &data);
  85. if (set)
  86. data |= bits;
  87. else
  88. data &= ~bits;
  89. ksz_write32(dev, addr, data);
  90. }
  91. static void ksz_port_cfg(struct ksz_device *dev, int port, int offset, u8 bits,
  92. bool set)
  93. {
  94. u32 addr;
  95. u8 data;
  96. addr = PORT_CTRL_ADDR(port, offset);
  97. ksz_read8(dev, addr, &data);
  98. if (set)
  99. data |= bits;
  100. else
  101. data &= ~bits;
  102. ksz_write8(dev, addr, data);
  103. }
  104. static void ksz_port_cfg32(struct ksz_device *dev, int port, int offset,
  105. u32 bits, bool set)
  106. {
  107. u32 addr;
  108. u32 data;
  109. addr = PORT_CTRL_ADDR(port, offset);
  110. ksz_read32(dev, addr, &data);
  111. if (set)
  112. data |= bits;
  113. else
  114. data &= ~bits;
  115. ksz_write32(dev, addr, data);
  116. }
  117. static int wait_vlan_ctrl_ready(struct ksz_device *dev, u32 waiton, int timeout)
  118. {
  119. u8 data;
  120. do {
  121. ksz_read8(dev, REG_SW_VLAN_CTRL, &data);
  122. if (!(data & waiton))
  123. break;
  124. usleep_range(1, 10);
  125. } while (timeout-- > 0);
  126. if (timeout <= 0)
  127. return -ETIMEDOUT;
  128. return 0;
  129. }
  130. static int get_vlan_table(struct dsa_switch *ds, u16 vid, u32 *vlan_table)
  131. {
  132. struct ksz_device *dev = ds->priv;
  133. int ret;
  134. mutex_lock(&dev->vlan_mutex);
  135. ksz_write16(dev, REG_SW_VLAN_ENTRY_INDEX__2, vid & VLAN_INDEX_M);
  136. ksz_write8(dev, REG_SW_VLAN_CTRL, VLAN_READ | VLAN_START);
  137. /* wait to be cleared */
  138. ret = wait_vlan_ctrl_ready(dev, VLAN_START, 1000);
  139. if (ret < 0) {
  140. dev_dbg(dev->dev, "Failed to read vlan table\n");
  141. goto exit;
  142. }
  143. ksz_read32(dev, REG_SW_VLAN_ENTRY__4, &vlan_table[0]);
  144. ksz_read32(dev, REG_SW_VLAN_ENTRY_UNTAG__4, &vlan_table[1]);
  145. ksz_read32(dev, REG_SW_VLAN_ENTRY_PORTS__4, &vlan_table[2]);
  146. ksz_write8(dev, REG_SW_VLAN_CTRL, 0);
  147. exit:
  148. mutex_unlock(&dev->vlan_mutex);
  149. return ret;
  150. }
  151. static int set_vlan_table(struct dsa_switch *ds, u16 vid, u32 *vlan_table)
  152. {
  153. struct ksz_device *dev = ds->priv;
  154. int ret;
  155. mutex_lock(&dev->vlan_mutex);
  156. ksz_write32(dev, REG_SW_VLAN_ENTRY__4, vlan_table[0]);
  157. ksz_write32(dev, REG_SW_VLAN_ENTRY_UNTAG__4, vlan_table[1]);
  158. ksz_write32(dev, REG_SW_VLAN_ENTRY_PORTS__4, vlan_table[2]);
  159. ksz_write16(dev, REG_SW_VLAN_ENTRY_INDEX__2, vid & VLAN_INDEX_M);
  160. ksz_write8(dev, REG_SW_VLAN_CTRL, VLAN_START | VLAN_WRITE);
  161. /* wait to be cleared */
  162. ret = wait_vlan_ctrl_ready(dev, VLAN_START, 1000);
  163. if (ret < 0) {
  164. dev_dbg(dev->dev, "Failed to write vlan table\n");
  165. goto exit;
  166. }
  167. ksz_write8(dev, REG_SW_VLAN_CTRL, 0);
  168. /* update vlan cache table */
  169. dev->vlan_cache[vid].table[0] = vlan_table[0];
  170. dev->vlan_cache[vid].table[1] = vlan_table[1];
  171. dev->vlan_cache[vid].table[2] = vlan_table[2];
  172. exit:
  173. mutex_unlock(&dev->vlan_mutex);
  174. return ret;
  175. }
  176. static void read_table(struct dsa_switch *ds, u32 *table)
  177. {
  178. struct ksz_device *dev = ds->priv;
  179. ksz_read32(dev, REG_SW_ALU_VAL_A, &table[0]);
  180. ksz_read32(dev, REG_SW_ALU_VAL_B, &table[1]);
  181. ksz_read32(dev, REG_SW_ALU_VAL_C, &table[2]);
  182. ksz_read32(dev, REG_SW_ALU_VAL_D, &table[3]);
  183. }
  184. static void write_table(struct dsa_switch *ds, u32 *table)
  185. {
  186. struct ksz_device *dev = ds->priv;
  187. ksz_write32(dev, REG_SW_ALU_VAL_A, table[0]);
  188. ksz_write32(dev, REG_SW_ALU_VAL_B, table[1]);
  189. ksz_write32(dev, REG_SW_ALU_VAL_C, table[2]);
  190. ksz_write32(dev, REG_SW_ALU_VAL_D, table[3]);
  191. }
  192. static int wait_alu_ready(struct ksz_device *dev, u32 waiton, int timeout)
  193. {
  194. u32 data;
  195. do {
  196. ksz_read32(dev, REG_SW_ALU_CTRL__4, &data);
  197. if (!(data & waiton))
  198. break;
  199. usleep_range(1, 10);
  200. } while (timeout-- > 0);
  201. if (timeout <= 0)
  202. return -ETIMEDOUT;
  203. return 0;
  204. }
  205. static int wait_alu_sta_ready(struct ksz_device *dev, u32 waiton, int timeout)
  206. {
  207. u32 data;
  208. do {
  209. ksz_read32(dev, REG_SW_ALU_STAT_CTRL__4, &data);
  210. if (!(data & waiton))
  211. break;
  212. usleep_range(1, 10);
  213. } while (timeout-- > 0);
  214. if (timeout <= 0)
  215. return -ETIMEDOUT;
  216. return 0;
  217. }
  218. static int ksz_reset_switch(struct dsa_switch *ds)
  219. {
  220. struct ksz_device *dev = ds->priv;
  221. u8 data8;
  222. u16 data16;
  223. u32 data32;
  224. /* reset switch */
  225. ksz_cfg(dev, REG_SW_OPERATION, SW_RESET, true);
  226. /* turn off SPI DO Edge select */
  227. ksz_read8(dev, REG_SW_GLOBAL_SERIAL_CTRL_0, &data8);
  228. data8 &= ~SPI_AUTO_EDGE_DETECTION;
  229. ksz_write8(dev, REG_SW_GLOBAL_SERIAL_CTRL_0, data8);
  230. /* default configuration */
  231. ksz_read8(dev, REG_SW_LUE_CTRL_1, &data8);
  232. data8 = SW_AGING_ENABLE | SW_LINK_AUTO_AGING |
  233. SW_SRC_ADDR_FILTER | SW_FLUSH_STP_TABLE | SW_FLUSH_MSTP_TABLE;
  234. ksz_write8(dev, REG_SW_LUE_CTRL_1, data8);
  235. /* disable interrupts */
  236. ksz_write32(dev, REG_SW_INT_MASK__4, SWITCH_INT_MASK);
  237. ksz_write32(dev, REG_SW_PORT_INT_MASK__4, 0x7F);
  238. ksz_read32(dev, REG_SW_PORT_INT_STATUS__4, &data32);
  239. /* set broadcast storm protection 10% rate */
  240. ksz_read16(dev, REG_SW_MAC_CTRL_2, &data16);
  241. data16 &= ~BROADCAST_STORM_RATE;
  242. data16 |= (BROADCAST_STORM_VALUE * BROADCAST_STORM_PROT_RATE) / 100;
  243. ksz_write16(dev, REG_SW_MAC_CTRL_2, data16);
  244. return 0;
  245. }
  246. static void port_setup(struct ksz_device *dev, int port, bool cpu_port)
  247. {
  248. u8 data8;
  249. u16 data16;
  250. /* enable tag tail for host port */
  251. if (cpu_port)
  252. ksz_port_cfg(dev, port, REG_PORT_CTRL_0, PORT_TAIL_TAG_ENABLE,
  253. true);
  254. ksz_port_cfg(dev, port, REG_PORT_CTRL_0, PORT_MAC_LOOPBACK, false);
  255. /* set back pressure */
  256. ksz_port_cfg(dev, port, REG_PORT_MAC_CTRL_1, PORT_BACK_PRESSURE, true);
  257. /* set flow control */
  258. ksz_port_cfg(dev, port, REG_PORT_CTRL_0,
  259. PORT_FORCE_TX_FLOW_CTRL | PORT_FORCE_RX_FLOW_CTRL, true);
  260. /* enable broadcast storm limit */
  261. ksz_port_cfg(dev, port, P_BCAST_STORM_CTRL, PORT_BROADCAST_STORM, true);
  262. /* disable DiffServ priority */
  263. ksz_port_cfg(dev, port, P_PRIO_CTRL, PORT_DIFFSERV_PRIO_ENABLE, false);
  264. /* replace priority */
  265. ksz_port_cfg(dev, port, REG_PORT_MRI_MAC_CTRL, PORT_USER_PRIO_CEILING,
  266. false);
  267. ksz_port_cfg32(dev, port, REG_PORT_MTI_QUEUE_CTRL_0__4,
  268. MTI_PVID_REPLACE, false);
  269. /* enable 802.1p priority */
  270. ksz_port_cfg(dev, port, P_PRIO_CTRL, PORT_802_1P_PRIO_ENABLE, true);
  271. /* configure MAC to 1G & RGMII mode */
  272. ksz_pread8(dev, port, REG_PORT_XMII_CTRL_1, &data8);
  273. data8 |= PORT_RGMII_ID_EG_ENABLE;
  274. data8 &= ~PORT_MII_NOT_1GBIT;
  275. data8 &= ~PORT_MII_SEL_M;
  276. data8 |= PORT_RGMII_SEL;
  277. ksz_pwrite8(dev, port, REG_PORT_XMII_CTRL_1, data8);
  278. /* clear pending interrupts */
  279. ksz_pread16(dev, port, REG_PORT_PHY_INT_ENABLE, &data16);
  280. }
  281. static void ksz_config_cpu_port(struct dsa_switch *ds)
  282. {
  283. struct ksz_device *dev = ds->priv;
  284. int i;
  285. ds->num_ports = dev->port_cnt;
  286. for (i = 0; i < ds->num_ports; i++) {
  287. if (dsa_is_cpu_port(ds, i) && (dev->cpu_ports & (1 << i))) {
  288. dev->cpu_port = i;
  289. /* enable cpu port */
  290. port_setup(dev, i, true);
  291. }
  292. }
  293. }
  294. static int ksz_setup(struct dsa_switch *ds)
  295. {
  296. struct ksz_device *dev = ds->priv;
  297. int ret = 0;
  298. dev->vlan_cache = devm_kcalloc(dev->dev, sizeof(struct vlan_table),
  299. dev->num_vlans, GFP_KERNEL);
  300. if (!dev->vlan_cache)
  301. return -ENOMEM;
  302. ret = ksz_reset_switch(ds);
  303. if (ret) {
  304. dev_err(ds->dev, "failed to reset switch\n");
  305. return ret;
  306. }
  307. /* accept packet up to 2000bytes */
  308. ksz_cfg(dev, REG_SW_MAC_CTRL_1, SW_LEGAL_PACKET_DISABLE, true);
  309. ksz_config_cpu_port(ds);
  310. ksz_cfg(dev, REG_SW_MAC_CTRL_1, MULTICAST_STORM_DISABLE, true);
  311. /* queue based egress rate limit */
  312. ksz_cfg(dev, REG_SW_MAC_CTRL_5, SW_OUT_RATE_LIMIT_QUEUE_BASED, true);
  313. /* start switch */
  314. ksz_cfg(dev, REG_SW_OPERATION, SW_START, true);
  315. return 0;
  316. }
  317. static enum dsa_tag_protocol ksz_get_tag_protocol(struct dsa_switch *ds,
  318. int port)
  319. {
  320. return DSA_TAG_PROTO_KSZ;
  321. }
  322. static int ksz_phy_read16(struct dsa_switch *ds, int addr, int reg)
  323. {
  324. struct ksz_device *dev = ds->priv;
  325. u16 val = 0;
  326. ksz_pread16(dev, addr, 0x100 + (reg << 1), &val);
  327. return val;
  328. }
  329. static int ksz_phy_write16(struct dsa_switch *ds, int addr, int reg, u16 val)
  330. {
  331. struct ksz_device *dev = ds->priv;
  332. ksz_pwrite16(dev, addr, 0x100 + (reg << 1), val);
  333. return 0;
  334. }
  335. static int ksz_enable_port(struct dsa_switch *ds, int port,
  336. struct phy_device *phy)
  337. {
  338. struct ksz_device *dev = ds->priv;
  339. /* setup slave port */
  340. port_setup(dev, port, false);
  341. return 0;
  342. }
  343. static void ksz_disable_port(struct dsa_switch *ds, int port,
  344. struct phy_device *phy)
  345. {
  346. struct ksz_device *dev = ds->priv;
  347. /* there is no port disable */
  348. ksz_port_cfg(dev, port, REG_PORT_CTRL_0, PORT_MAC_LOOPBACK, true);
  349. }
  350. static int ksz_sset_count(struct dsa_switch *ds, int port, int sset)
  351. {
  352. if (sset != ETH_SS_STATS)
  353. return 0;
  354. return TOTAL_SWITCH_COUNTER_NUM;
  355. }
  356. static void ksz_get_strings(struct dsa_switch *ds, int port,
  357. u32 stringset, uint8_t *buf)
  358. {
  359. int i;
  360. if (stringset != ETH_SS_STATS)
  361. return;
  362. for (i = 0; i < TOTAL_SWITCH_COUNTER_NUM; i++) {
  363. memcpy(buf + i * ETH_GSTRING_LEN, mib_names[i].string,
  364. ETH_GSTRING_LEN);
  365. }
  366. }
  367. static void ksz_get_ethtool_stats(struct dsa_switch *ds, int port,
  368. uint64_t *buf)
  369. {
  370. struct ksz_device *dev = ds->priv;
  371. int i;
  372. u32 data;
  373. int timeout;
  374. mutex_lock(&dev->stats_mutex);
  375. for (i = 0; i < TOTAL_SWITCH_COUNTER_NUM; i++) {
  376. data = MIB_COUNTER_READ;
  377. data |= ((mib_names[i].index & 0xFF) << MIB_COUNTER_INDEX_S);
  378. ksz_pwrite32(dev, port, REG_PORT_MIB_CTRL_STAT__4, data);
  379. timeout = 1000;
  380. do {
  381. ksz_pread32(dev, port, REG_PORT_MIB_CTRL_STAT__4,
  382. &data);
  383. usleep_range(1, 10);
  384. if (!(data & MIB_COUNTER_READ))
  385. break;
  386. } while (timeout-- > 0);
  387. /* failed to read MIB. get out of loop */
  388. if (!timeout) {
  389. dev_dbg(dev->dev, "Failed to get MIB\n");
  390. break;
  391. }
  392. /* count resets upon read */
  393. ksz_pread32(dev, port, REG_PORT_MIB_DATA, &data);
  394. dev->mib_value[i] += (uint64_t)data;
  395. buf[i] = dev->mib_value[i];
  396. }
  397. mutex_unlock(&dev->stats_mutex);
  398. }
  399. static void ksz_port_stp_state_set(struct dsa_switch *ds, int port, u8 state)
  400. {
  401. struct ksz_device *dev = ds->priv;
  402. u8 data;
  403. ksz_pread8(dev, port, P_STP_CTRL, &data);
  404. data &= ~(PORT_TX_ENABLE | PORT_RX_ENABLE | PORT_LEARN_DISABLE);
  405. switch (state) {
  406. case BR_STATE_DISABLED:
  407. data |= PORT_LEARN_DISABLE;
  408. break;
  409. case BR_STATE_LISTENING:
  410. data |= (PORT_RX_ENABLE | PORT_LEARN_DISABLE);
  411. break;
  412. case BR_STATE_LEARNING:
  413. data |= PORT_RX_ENABLE;
  414. break;
  415. case BR_STATE_FORWARDING:
  416. data |= (PORT_TX_ENABLE | PORT_RX_ENABLE);
  417. break;
  418. case BR_STATE_BLOCKING:
  419. data |= PORT_LEARN_DISABLE;
  420. break;
  421. default:
  422. dev_err(ds->dev, "invalid STP state: %d\n", state);
  423. return;
  424. }
  425. ksz_pwrite8(dev, port, P_STP_CTRL, data);
  426. }
  427. static void ksz_port_fast_age(struct dsa_switch *ds, int port)
  428. {
  429. struct ksz_device *dev = ds->priv;
  430. u8 data8;
  431. ksz_read8(dev, REG_SW_LUE_CTRL_1, &data8);
  432. data8 |= SW_FAST_AGING;
  433. ksz_write8(dev, REG_SW_LUE_CTRL_1, data8);
  434. data8 &= ~SW_FAST_AGING;
  435. ksz_write8(dev, REG_SW_LUE_CTRL_1, data8);
  436. }
  437. static int ksz_port_vlan_filtering(struct dsa_switch *ds, int port, bool flag)
  438. {
  439. struct ksz_device *dev = ds->priv;
  440. if (flag) {
  441. ksz_port_cfg(dev, port, REG_PORT_LUE_CTRL,
  442. PORT_VLAN_LOOKUP_VID_0, true);
  443. ksz_cfg32(dev, REG_SW_QM_CTRL__4, UNICAST_VLAN_BOUNDARY, true);
  444. ksz_cfg(dev, REG_SW_LUE_CTRL_0, SW_VLAN_ENABLE, true);
  445. } else {
  446. ksz_cfg(dev, REG_SW_LUE_CTRL_0, SW_VLAN_ENABLE, false);
  447. ksz_cfg32(dev, REG_SW_QM_CTRL__4, UNICAST_VLAN_BOUNDARY, false);
  448. ksz_port_cfg(dev, port, REG_PORT_LUE_CTRL,
  449. PORT_VLAN_LOOKUP_VID_0, false);
  450. }
  451. return 0;
  452. }
  453. static int ksz_port_vlan_prepare(struct dsa_switch *ds, int port,
  454. const struct switchdev_obj_port_vlan *vlan)
  455. {
  456. /* nothing needed */
  457. return 0;
  458. }
  459. static void ksz_port_vlan_add(struct dsa_switch *ds, int port,
  460. const struct switchdev_obj_port_vlan *vlan)
  461. {
  462. struct ksz_device *dev = ds->priv;
  463. u32 vlan_table[3];
  464. u16 vid;
  465. bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
  466. for (vid = vlan->vid_begin; vid <= vlan->vid_end; vid++) {
  467. if (get_vlan_table(ds, vid, vlan_table)) {
  468. dev_dbg(dev->dev, "Failed to get vlan table\n");
  469. return;
  470. }
  471. vlan_table[0] = VLAN_VALID | (vid & VLAN_FID_M);
  472. if (untagged)
  473. vlan_table[1] |= BIT(port);
  474. else
  475. vlan_table[1] &= ~BIT(port);
  476. vlan_table[1] &= ~(BIT(dev->cpu_port));
  477. vlan_table[2] |= BIT(port) | BIT(dev->cpu_port);
  478. if (set_vlan_table(ds, vid, vlan_table)) {
  479. dev_dbg(dev->dev, "Failed to set vlan table\n");
  480. return;
  481. }
  482. /* change PVID */
  483. if (vlan->flags & BRIDGE_VLAN_INFO_PVID)
  484. ksz_pwrite16(dev, port, REG_PORT_DEFAULT_VID, vid);
  485. }
  486. }
  487. static int ksz_port_vlan_del(struct dsa_switch *ds, int port,
  488. const struct switchdev_obj_port_vlan *vlan)
  489. {
  490. struct ksz_device *dev = ds->priv;
  491. bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
  492. u32 vlan_table[3];
  493. u16 vid;
  494. u16 pvid;
  495. ksz_pread16(dev, port, REG_PORT_DEFAULT_VID, &pvid);
  496. pvid = pvid & 0xFFF;
  497. for (vid = vlan->vid_begin; vid <= vlan->vid_end; vid++) {
  498. if (get_vlan_table(ds, vid, vlan_table)) {
  499. dev_dbg(dev->dev, "Failed to get vlan table\n");
  500. return -ETIMEDOUT;
  501. }
  502. vlan_table[2] &= ~BIT(port);
  503. if (pvid == vid)
  504. pvid = 1;
  505. if (untagged)
  506. vlan_table[1] &= ~BIT(port);
  507. if (set_vlan_table(ds, vid, vlan_table)) {
  508. dev_dbg(dev->dev, "Failed to set vlan table\n");
  509. return -ETIMEDOUT;
  510. }
  511. }
  512. ksz_pwrite16(dev, port, REG_PORT_DEFAULT_VID, pvid);
  513. return 0;
  514. }
  515. struct alu_struct {
  516. /* entry 1 */
  517. u8 is_static:1;
  518. u8 is_src_filter:1;
  519. u8 is_dst_filter:1;
  520. u8 prio_age:3;
  521. u32 _reserv_0_1:23;
  522. u8 mstp:3;
  523. /* entry 2 */
  524. u8 is_override:1;
  525. u8 is_use_fid:1;
  526. u32 _reserv_1_1:23;
  527. u8 port_forward:7;
  528. /* entry 3 & 4*/
  529. u32 _reserv_2_1:9;
  530. u8 fid:7;
  531. u8 mac[ETH_ALEN];
  532. };
  533. static int ksz_port_fdb_add(struct dsa_switch *ds, int port,
  534. const unsigned char *addr, u16 vid)
  535. {
  536. struct ksz_device *dev = ds->priv;
  537. u32 alu_table[4];
  538. u32 data;
  539. int ret = 0;
  540. mutex_lock(&dev->alu_mutex);
  541. /* find any entry with mac & vid */
  542. data = vid << ALU_FID_INDEX_S;
  543. data |= ((addr[0] << 8) | addr[1]);
  544. ksz_write32(dev, REG_SW_ALU_INDEX_0, data);
  545. data = ((addr[2] << 24) | (addr[3] << 16));
  546. data |= ((addr[4] << 8) | addr[5]);
  547. ksz_write32(dev, REG_SW_ALU_INDEX_1, data);
  548. /* start read operation */
  549. ksz_write32(dev, REG_SW_ALU_CTRL__4, ALU_READ | ALU_START);
  550. /* wait to be finished */
  551. ret = wait_alu_ready(dev, ALU_START, 1000);
  552. if (ret < 0) {
  553. dev_dbg(dev->dev, "Failed to read ALU\n");
  554. goto exit;
  555. }
  556. /* read ALU entry */
  557. read_table(ds, alu_table);
  558. /* update ALU entry */
  559. alu_table[0] = ALU_V_STATIC_VALID;
  560. alu_table[1] |= BIT(port);
  561. if (vid)
  562. alu_table[1] |= ALU_V_USE_FID;
  563. alu_table[2] = (vid << ALU_V_FID_S);
  564. alu_table[2] |= ((addr[0] << 8) | addr[1]);
  565. alu_table[3] = ((addr[2] << 24) | (addr[3] << 16));
  566. alu_table[3] |= ((addr[4] << 8) | addr[5]);
  567. write_table(ds, alu_table);
  568. ksz_write32(dev, REG_SW_ALU_CTRL__4, ALU_WRITE | ALU_START);
  569. /* wait to be finished */
  570. ret = wait_alu_ready(dev, ALU_START, 1000);
  571. if (ret < 0)
  572. dev_dbg(dev->dev, "Failed to write ALU\n");
  573. exit:
  574. mutex_unlock(&dev->alu_mutex);
  575. return ret;
  576. }
  577. static int ksz_port_fdb_del(struct dsa_switch *ds, int port,
  578. const unsigned char *addr, u16 vid)
  579. {
  580. struct ksz_device *dev = ds->priv;
  581. u32 alu_table[4];
  582. u32 data;
  583. int ret = 0;
  584. mutex_lock(&dev->alu_mutex);
  585. /* read any entry with mac & vid */
  586. data = vid << ALU_FID_INDEX_S;
  587. data |= ((addr[0] << 8) | addr[1]);
  588. ksz_write32(dev, REG_SW_ALU_INDEX_0, data);
  589. data = ((addr[2] << 24) | (addr[3] << 16));
  590. data |= ((addr[4] << 8) | addr[5]);
  591. ksz_write32(dev, REG_SW_ALU_INDEX_1, data);
  592. /* start read operation */
  593. ksz_write32(dev, REG_SW_ALU_CTRL__4, ALU_READ | ALU_START);
  594. /* wait to be finished */
  595. ret = wait_alu_ready(dev, ALU_START, 1000);
  596. if (ret < 0) {
  597. dev_dbg(dev->dev, "Failed to read ALU\n");
  598. goto exit;
  599. }
  600. ksz_read32(dev, REG_SW_ALU_VAL_A, &alu_table[0]);
  601. if (alu_table[0] & ALU_V_STATIC_VALID) {
  602. ksz_read32(dev, REG_SW_ALU_VAL_B, &alu_table[1]);
  603. ksz_read32(dev, REG_SW_ALU_VAL_C, &alu_table[2]);
  604. ksz_read32(dev, REG_SW_ALU_VAL_D, &alu_table[3]);
  605. /* clear forwarding port */
  606. alu_table[2] &= ~BIT(port);
  607. /* if there is no port to forward, clear table */
  608. if ((alu_table[2] & ALU_V_PORT_MAP) == 0) {
  609. alu_table[0] = 0;
  610. alu_table[1] = 0;
  611. alu_table[2] = 0;
  612. alu_table[3] = 0;
  613. }
  614. } else {
  615. alu_table[0] = 0;
  616. alu_table[1] = 0;
  617. alu_table[2] = 0;
  618. alu_table[3] = 0;
  619. }
  620. write_table(ds, alu_table);
  621. ksz_write32(dev, REG_SW_ALU_CTRL__4, ALU_WRITE | ALU_START);
  622. /* wait to be finished */
  623. ret = wait_alu_ready(dev, ALU_START, 1000);
  624. if (ret < 0)
  625. dev_dbg(dev->dev, "Failed to write ALU\n");
  626. exit:
  627. mutex_unlock(&dev->alu_mutex);
  628. return ret;
  629. }
  630. static void convert_alu(struct alu_struct *alu, u32 *alu_table)
  631. {
  632. alu->is_static = !!(alu_table[0] & ALU_V_STATIC_VALID);
  633. alu->is_src_filter = !!(alu_table[0] & ALU_V_SRC_FILTER);
  634. alu->is_dst_filter = !!(alu_table[0] & ALU_V_DST_FILTER);
  635. alu->prio_age = (alu_table[0] >> ALU_V_PRIO_AGE_CNT_S) &
  636. ALU_V_PRIO_AGE_CNT_M;
  637. alu->mstp = alu_table[0] & ALU_V_MSTP_M;
  638. alu->is_override = !!(alu_table[1] & ALU_V_OVERRIDE);
  639. alu->is_use_fid = !!(alu_table[1] & ALU_V_USE_FID);
  640. alu->port_forward = alu_table[1] & ALU_V_PORT_MAP;
  641. alu->fid = (alu_table[2] >> ALU_V_FID_S) & ALU_V_FID_M;
  642. alu->mac[0] = (alu_table[2] >> 8) & 0xFF;
  643. alu->mac[1] = alu_table[2] & 0xFF;
  644. alu->mac[2] = (alu_table[3] >> 24) & 0xFF;
  645. alu->mac[3] = (alu_table[3] >> 16) & 0xFF;
  646. alu->mac[4] = (alu_table[3] >> 8) & 0xFF;
  647. alu->mac[5] = alu_table[3] & 0xFF;
  648. }
  649. static int ksz_port_fdb_dump(struct dsa_switch *ds, int port,
  650. dsa_fdb_dump_cb_t *cb, void *data)
  651. {
  652. struct ksz_device *dev = ds->priv;
  653. int ret = 0;
  654. u32 ksz_data;
  655. u32 alu_table[4];
  656. struct alu_struct alu;
  657. int timeout;
  658. mutex_lock(&dev->alu_mutex);
  659. /* start ALU search */
  660. ksz_write32(dev, REG_SW_ALU_CTRL__4, ALU_START | ALU_SEARCH);
  661. do {
  662. timeout = 1000;
  663. do {
  664. ksz_read32(dev, REG_SW_ALU_CTRL__4, &ksz_data);
  665. if ((ksz_data & ALU_VALID) || !(ksz_data & ALU_START))
  666. break;
  667. usleep_range(1, 10);
  668. } while (timeout-- > 0);
  669. if (!timeout) {
  670. dev_dbg(dev->dev, "Failed to search ALU\n");
  671. ret = -ETIMEDOUT;
  672. goto exit;
  673. }
  674. /* read ALU table */
  675. read_table(ds, alu_table);
  676. convert_alu(&alu, alu_table);
  677. if (alu.port_forward & BIT(port)) {
  678. ret = cb(alu.mac, alu.fid, alu.is_static, data);
  679. if (ret)
  680. goto exit;
  681. }
  682. } while (ksz_data & ALU_START);
  683. exit:
  684. /* stop ALU search */
  685. ksz_write32(dev, REG_SW_ALU_CTRL__4, 0);
  686. mutex_unlock(&dev->alu_mutex);
  687. return ret;
  688. }
  689. static int ksz_port_mdb_prepare(struct dsa_switch *ds, int port,
  690. const struct switchdev_obj_port_mdb *mdb)
  691. {
  692. /* nothing to do */
  693. return 0;
  694. }
  695. static void ksz_port_mdb_add(struct dsa_switch *ds, int port,
  696. const struct switchdev_obj_port_mdb *mdb)
  697. {
  698. struct ksz_device *dev = ds->priv;
  699. u32 static_table[4];
  700. u32 data;
  701. int index;
  702. u32 mac_hi, mac_lo;
  703. mac_hi = ((mdb->addr[0] << 8) | mdb->addr[1]);
  704. mac_lo = ((mdb->addr[2] << 24) | (mdb->addr[3] << 16));
  705. mac_lo |= ((mdb->addr[4] << 8) | mdb->addr[5]);
  706. mutex_lock(&dev->alu_mutex);
  707. for (index = 0; index < dev->num_statics; index++) {
  708. /* find empty slot first */
  709. data = (index << ALU_STAT_INDEX_S) |
  710. ALU_STAT_READ | ALU_STAT_START;
  711. ksz_write32(dev, REG_SW_ALU_STAT_CTRL__4, data);
  712. /* wait to be finished */
  713. if (wait_alu_sta_ready(dev, ALU_STAT_START, 1000) < 0) {
  714. dev_dbg(dev->dev, "Failed to read ALU STATIC\n");
  715. goto exit;
  716. }
  717. /* read ALU static table */
  718. read_table(ds, static_table);
  719. if (static_table[0] & ALU_V_STATIC_VALID) {
  720. /* check this has same vid & mac address */
  721. if (((static_table[2] >> ALU_V_FID_S) == (mdb->vid)) &&
  722. ((static_table[2] & ALU_V_MAC_ADDR_HI) == mac_hi) &&
  723. (static_table[3] == mac_lo)) {
  724. /* found matching one */
  725. break;
  726. }
  727. } else {
  728. /* found empty one */
  729. break;
  730. }
  731. }
  732. /* no available entry */
  733. if (index == dev->num_statics)
  734. goto exit;
  735. /* add entry */
  736. static_table[0] = ALU_V_STATIC_VALID;
  737. static_table[1] |= BIT(port);
  738. if (mdb->vid)
  739. static_table[1] |= ALU_V_USE_FID;
  740. static_table[2] = (mdb->vid << ALU_V_FID_S);
  741. static_table[2] |= mac_hi;
  742. static_table[3] = mac_lo;
  743. write_table(ds, static_table);
  744. data = (index << ALU_STAT_INDEX_S) | ALU_STAT_START;
  745. ksz_write32(dev, REG_SW_ALU_STAT_CTRL__4, data);
  746. /* wait to be finished */
  747. if (wait_alu_sta_ready(dev, ALU_STAT_START, 1000) < 0)
  748. dev_dbg(dev->dev, "Failed to read ALU STATIC\n");
  749. exit:
  750. mutex_unlock(&dev->alu_mutex);
  751. }
  752. static int ksz_port_mdb_del(struct dsa_switch *ds, int port,
  753. const struct switchdev_obj_port_mdb *mdb)
  754. {
  755. struct ksz_device *dev = ds->priv;
  756. u32 static_table[4];
  757. u32 data;
  758. int index;
  759. int ret = 0;
  760. u32 mac_hi, mac_lo;
  761. mac_hi = ((mdb->addr[0] << 8) | mdb->addr[1]);
  762. mac_lo = ((mdb->addr[2] << 24) | (mdb->addr[3] << 16));
  763. mac_lo |= ((mdb->addr[4] << 8) | mdb->addr[5]);
  764. mutex_lock(&dev->alu_mutex);
  765. for (index = 0; index < dev->num_statics; index++) {
  766. /* find empty slot first */
  767. data = (index << ALU_STAT_INDEX_S) |
  768. ALU_STAT_READ | ALU_STAT_START;
  769. ksz_write32(dev, REG_SW_ALU_STAT_CTRL__4, data);
  770. /* wait to be finished */
  771. ret = wait_alu_sta_ready(dev, ALU_STAT_START, 1000);
  772. if (ret < 0) {
  773. dev_dbg(dev->dev, "Failed to read ALU STATIC\n");
  774. goto exit;
  775. }
  776. /* read ALU static table */
  777. read_table(ds, static_table);
  778. if (static_table[0] & ALU_V_STATIC_VALID) {
  779. /* check this has same vid & mac address */
  780. if (((static_table[2] >> ALU_V_FID_S) == (mdb->vid)) &&
  781. ((static_table[2] & ALU_V_MAC_ADDR_HI) == mac_hi) &&
  782. (static_table[3] == mac_lo)) {
  783. /* found matching one */
  784. break;
  785. }
  786. }
  787. }
  788. /* no available entry */
  789. if (index == dev->num_statics) {
  790. ret = -EINVAL;
  791. goto exit;
  792. }
  793. /* clear port */
  794. static_table[1] &= ~BIT(port);
  795. if ((static_table[1] & ALU_V_PORT_MAP) == 0) {
  796. /* delete entry */
  797. static_table[0] = 0;
  798. static_table[1] = 0;
  799. static_table[2] = 0;
  800. static_table[3] = 0;
  801. }
  802. write_table(ds, static_table);
  803. data = (index << ALU_STAT_INDEX_S) | ALU_STAT_START;
  804. ksz_write32(dev, REG_SW_ALU_STAT_CTRL__4, data);
  805. /* wait to be finished */
  806. ret = wait_alu_sta_ready(dev, ALU_STAT_START, 1000);
  807. if (ret < 0)
  808. dev_dbg(dev->dev, "Failed to read ALU STATIC\n");
  809. exit:
  810. mutex_unlock(&dev->alu_mutex);
  811. return ret;
  812. }
  813. static int ksz_port_mirror_add(struct dsa_switch *ds, int port,
  814. struct dsa_mall_mirror_tc_entry *mirror,
  815. bool ingress)
  816. {
  817. struct ksz_device *dev = ds->priv;
  818. if (ingress)
  819. ksz_port_cfg(dev, port, P_MIRROR_CTRL, PORT_MIRROR_RX, true);
  820. else
  821. ksz_port_cfg(dev, port, P_MIRROR_CTRL, PORT_MIRROR_TX, true);
  822. ksz_port_cfg(dev, port, P_MIRROR_CTRL, PORT_MIRROR_SNIFFER, false);
  823. /* configure mirror port */
  824. ksz_port_cfg(dev, mirror->to_local_port, P_MIRROR_CTRL,
  825. PORT_MIRROR_SNIFFER, true);
  826. ksz_cfg(dev, S_MIRROR_CTRL, SW_MIRROR_RX_TX, false);
  827. return 0;
  828. }
  829. static void ksz_port_mirror_del(struct dsa_switch *ds, int port,
  830. struct dsa_mall_mirror_tc_entry *mirror)
  831. {
  832. struct ksz_device *dev = ds->priv;
  833. u8 data;
  834. if (mirror->ingress)
  835. ksz_port_cfg(dev, port, P_MIRROR_CTRL, PORT_MIRROR_RX, false);
  836. else
  837. ksz_port_cfg(dev, port, P_MIRROR_CTRL, PORT_MIRROR_TX, false);
  838. ksz_pread8(dev, port, P_MIRROR_CTRL, &data);
  839. if (!(data & (PORT_MIRROR_RX | PORT_MIRROR_TX)))
  840. ksz_port_cfg(dev, mirror->to_local_port, P_MIRROR_CTRL,
  841. PORT_MIRROR_SNIFFER, false);
  842. }
  843. static const struct dsa_switch_ops ksz_switch_ops = {
  844. .get_tag_protocol = ksz_get_tag_protocol,
  845. .setup = ksz_setup,
  846. .phy_read = ksz_phy_read16,
  847. .phy_write = ksz_phy_write16,
  848. .port_enable = ksz_enable_port,
  849. .port_disable = ksz_disable_port,
  850. .get_strings = ksz_get_strings,
  851. .get_ethtool_stats = ksz_get_ethtool_stats,
  852. .get_sset_count = ksz_sset_count,
  853. .port_stp_state_set = ksz_port_stp_state_set,
  854. .port_fast_age = ksz_port_fast_age,
  855. .port_vlan_filtering = ksz_port_vlan_filtering,
  856. .port_vlan_prepare = ksz_port_vlan_prepare,
  857. .port_vlan_add = ksz_port_vlan_add,
  858. .port_vlan_del = ksz_port_vlan_del,
  859. .port_fdb_dump = ksz_port_fdb_dump,
  860. .port_fdb_add = ksz_port_fdb_add,
  861. .port_fdb_del = ksz_port_fdb_del,
  862. .port_mdb_prepare = ksz_port_mdb_prepare,
  863. .port_mdb_add = ksz_port_mdb_add,
  864. .port_mdb_del = ksz_port_mdb_del,
  865. .port_mirror_add = ksz_port_mirror_add,
  866. .port_mirror_del = ksz_port_mirror_del,
  867. };
  868. struct ksz_chip_data {
  869. u32 chip_id;
  870. const char *dev_name;
  871. int num_vlans;
  872. int num_alus;
  873. int num_statics;
  874. int cpu_ports;
  875. int port_cnt;
  876. };
  877. static const struct ksz_chip_data ksz_switch_chips[] = {
  878. {
  879. .chip_id = 0x00947700,
  880. .dev_name = "KSZ9477",
  881. .num_vlans = 4096,
  882. .num_alus = 4096,
  883. .num_statics = 16,
  884. .cpu_ports = 0x7F, /* can be configured as cpu port */
  885. .port_cnt = 7, /* total physical port count */
  886. },
  887. {
  888. .chip_id = 0x00989700,
  889. .dev_name = "KSZ9897",
  890. .num_vlans = 4096,
  891. .num_alus = 4096,
  892. .num_statics = 16,
  893. .cpu_ports = 0x7F, /* can be configured as cpu port */
  894. .port_cnt = 7, /* total physical port count */
  895. },
  896. };
  897. static int ksz_switch_init(struct ksz_device *dev)
  898. {
  899. int i;
  900. dev->ds->ops = &ksz_switch_ops;
  901. for (i = 0; i < ARRAY_SIZE(ksz_switch_chips); i++) {
  902. const struct ksz_chip_data *chip = &ksz_switch_chips[i];
  903. if (dev->chip_id == chip->chip_id) {
  904. dev->name = chip->dev_name;
  905. dev->num_vlans = chip->num_vlans;
  906. dev->num_alus = chip->num_alus;
  907. dev->num_statics = chip->num_statics;
  908. dev->port_cnt = chip->port_cnt;
  909. dev->cpu_ports = chip->cpu_ports;
  910. break;
  911. }
  912. }
  913. /* no switch found */
  914. if (!dev->port_cnt)
  915. return -ENODEV;
  916. return 0;
  917. }
  918. struct ksz_device *ksz_switch_alloc(struct device *base,
  919. const struct ksz_io_ops *ops,
  920. void *priv)
  921. {
  922. struct dsa_switch *ds;
  923. struct ksz_device *swdev;
  924. ds = dsa_switch_alloc(base, DSA_MAX_PORTS);
  925. if (!ds)
  926. return NULL;
  927. swdev = devm_kzalloc(base, sizeof(*swdev), GFP_KERNEL);
  928. if (!swdev)
  929. return NULL;
  930. ds->priv = swdev;
  931. swdev->dev = base;
  932. swdev->ds = ds;
  933. swdev->priv = priv;
  934. swdev->ops = ops;
  935. return swdev;
  936. }
  937. EXPORT_SYMBOL(ksz_switch_alloc);
  938. int ksz_switch_detect(struct ksz_device *dev)
  939. {
  940. u8 data8;
  941. u32 id32;
  942. int ret;
  943. /* turn off SPI DO Edge select */
  944. ret = ksz_read8(dev, REG_SW_GLOBAL_SERIAL_CTRL_0, &data8);
  945. if (ret)
  946. return ret;
  947. data8 &= ~SPI_AUTO_EDGE_DETECTION;
  948. ret = ksz_write8(dev, REG_SW_GLOBAL_SERIAL_CTRL_0, data8);
  949. if (ret)
  950. return ret;
  951. /* read chip id */
  952. ret = ksz_read32(dev, REG_CHIP_ID0__1, &id32);
  953. if (ret)
  954. return ret;
  955. dev->chip_id = id32;
  956. return 0;
  957. }
  958. EXPORT_SYMBOL(ksz_switch_detect);
  959. int ksz_switch_register(struct ksz_device *dev)
  960. {
  961. int ret;
  962. if (dev->pdata)
  963. dev->chip_id = dev->pdata->chip_id;
  964. mutex_init(&dev->reg_mutex);
  965. mutex_init(&dev->stats_mutex);
  966. mutex_init(&dev->alu_mutex);
  967. mutex_init(&dev->vlan_mutex);
  968. if (ksz_switch_detect(dev))
  969. return -EINVAL;
  970. ret = ksz_switch_init(dev);
  971. if (ret)
  972. return ret;
  973. return dsa_register_switch(dev->ds);
  974. }
  975. EXPORT_SYMBOL(ksz_switch_register);
  976. void ksz_switch_remove(struct ksz_device *dev)
  977. {
  978. dsa_unregister_switch(dev->ds);
  979. }
  980. EXPORT_SYMBOL(ksz_switch_remove);
  981. MODULE_AUTHOR("Woojung Huh <Woojung.Huh@microchip.com>");
  982. MODULE_DESCRIPTION("Microchip KSZ Series Switch DSA Driver");
  983. MODULE_LICENSE("GPL");