mv88e6123_61_65.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  1. /*
  2. * net/dsa/mv88e6123_61_65.c - Marvell 88e6123/6161/6165 switch chip support
  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/netdevice.h>
  12. #include <linux/phy.h>
  13. #include <net/dsa.h>
  14. #include "mv88e6xxx.h"
  15. static char *mv88e6123_61_65_probe(struct mii_bus *bus, int sw_addr)
  16. {
  17. int ret;
  18. ret = __mv88e6xxx_reg_read(bus, sw_addr, REG_PORT(0), 0x03);
  19. if (ret >= 0) {
  20. if (ret == 0x1212)
  21. return "Marvell 88E6123 (A1)";
  22. if (ret == 0x1213)
  23. return "Marvell 88E6123 (A2)";
  24. if ((ret & 0xfff0) == 0x1210)
  25. return "Marvell 88E6123";
  26. if (ret == 0x1612)
  27. return "Marvell 88E6161 (A1)";
  28. if (ret == 0x1613)
  29. return "Marvell 88E6161 (A2)";
  30. if ((ret & 0xfff0) == 0x1610)
  31. return "Marvell 88E6161";
  32. if (ret == 0x1652)
  33. return "Marvell 88E6165 (A1)";
  34. if (ret == 0x1653)
  35. return "Marvell 88e6165 (A2)";
  36. if ((ret & 0xfff0) == 0x1650)
  37. return "Marvell 88E6165";
  38. }
  39. return NULL;
  40. }
  41. static int mv88e6123_61_65_switch_reset(struct dsa_switch *ds)
  42. {
  43. int i;
  44. int ret;
  45. /*
  46. * Set all ports to the disabled state.
  47. */
  48. for (i = 0; i < 8; i++) {
  49. ret = REG_READ(REG_PORT(i), 0x04);
  50. REG_WRITE(REG_PORT(i), 0x04, ret & 0xfffc);
  51. }
  52. /*
  53. * Wait for transmit queues to drain.
  54. */
  55. msleep(2);
  56. /*
  57. * Reset the switch.
  58. */
  59. REG_WRITE(REG_GLOBAL, 0x04, 0xc400);
  60. /*
  61. * Wait up to one second for reset to complete.
  62. */
  63. for (i = 0; i < 1000; i++) {
  64. ret = REG_READ(REG_GLOBAL, 0x00);
  65. if ((ret & 0xc800) == 0xc800)
  66. break;
  67. msleep(1);
  68. }
  69. if (i == 1000)
  70. return -ETIMEDOUT;
  71. return 0;
  72. }
  73. static int mv88e6123_61_65_setup_global(struct dsa_switch *ds)
  74. {
  75. int ret;
  76. int i;
  77. /*
  78. * Disable the PHY polling unit (since there won't be any
  79. * external PHYs to poll), don't discard packets with
  80. * excessive collisions, and mask all interrupt sources.
  81. */
  82. REG_WRITE(REG_GLOBAL, 0x04, 0x0000);
  83. /*
  84. * Set the default address aging time to 5 minutes, and
  85. * enable address learn messages to be sent to all message
  86. * ports.
  87. */
  88. REG_WRITE(REG_GLOBAL, 0x0a, 0x0148);
  89. /*
  90. * Configure the priority mapping registers.
  91. */
  92. ret = mv88e6xxx_config_prio(ds);
  93. if (ret < 0)
  94. return ret;
  95. /*
  96. * Configure the upstream port, and configure the upstream
  97. * port as the port to which ingress and egress monitor frames
  98. * are to be sent.
  99. */
  100. REG_WRITE(REG_GLOBAL, 0x1a, (dsa_upstream_port(ds) * 0x1110));
  101. /*
  102. * Disable remote management for now, and set the switch's
  103. * DSA device number.
  104. */
  105. REG_WRITE(REG_GLOBAL, 0x1c, ds->index & 0x1f);
  106. /*
  107. * Send all frames with destination addresses matching
  108. * 01:80:c2:00:00:2x to the CPU port.
  109. */
  110. REG_WRITE(REG_GLOBAL2, 0x02, 0xffff);
  111. /*
  112. * Send all frames with destination addresses matching
  113. * 01:80:c2:00:00:0x to the CPU port.
  114. */
  115. REG_WRITE(REG_GLOBAL2, 0x03, 0xffff);
  116. /*
  117. * Disable the loopback filter, disable flow control
  118. * messages, disable flood broadcast override, disable
  119. * removing of provider tags, disable ATU age violation
  120. * interrupts, disable tag flow control, force flow
  121. * control priority to the highest, and send all special
  122. * multicast frames to the CPU at the highest priority.
  123. */
  124. REG_WRITE(REG_GLOBAL2, 0x05, 0x00ff);
  125. /*
  126. * Program the DSA routing table.
  127. */
  128. for (i = 0; i < 32; i++) {
  129. int nexthop;
  130. nexthop = 0x1f;
  131. if (i != ds->index && i < ds->dst->pd->nr_chips)
  132. nexthop = ds->pd->rtable[i] & 0x1f;
  133. REG_WRITE(REG_GLOBAL2, 0x06, 0x8000 | (i << 8) | nexthop);
  134. }
  135. /*
  136. * Clear all trunk masks.
  137. */
  138. for (i = 0; i < 8; i++)
  139. REG_WRITE(REG_GLOBAL2, 0x07, 0x8000 | (i << 12) | 0xff);
  140. /*
  141. * Clear all trunk mappings.
  142. */
  143. for (i = 0; i < 16; i++)
  144. REG_WRITE(REG_GLOBAL2, 0x08, 0x8000 | (i << 11));
  145. /*
  146. * Disable ingress rate limiting by resetting all ingress
  147. * rate limit registers to their initial state.
  148. */
  149. for (i = 0; i < 6; i++)
  150. REG_WRITE(REG_GLOBAL2, 0x09, 0x9000 | (i << 8));
  151. /*
  152. * Initialise cross-chip port VLAN table to reset defaults.
  153. */
  154. REG_WRITE(REG_GLOBAL2, 0x0b, 0x9000);
  155. /*
  156. * Clear the priority override table.
  157. */
  158. for (i = 0; i < 16; i++)
  159. REG_WRITE(REG_GLOBAL2, 0x0f, 0x8000 | (i << 8));
  160. /* @@@ initialise AVB (22/23) watchdog (27) sdet (29) registers */
  161. return 0;
  162. }
  163. static int mv88e6123_61_65_setup_port(struct dsa_switch *ds, int p)
  164. {
  165. int addr = REG_PORT(p);
  166. u16 val;
  167. /*
  168. * MAC Forcing register: don't force link, speed, duplex
  169. * or flow control state to any particular values on physical
  170. * ports, but force the CPU port and all DSA ports to 1000 Mb/s
  171. * full duplex.
  172. */
  173. if (dsa_is_cpu_port(ds, p) || ds->dsa_port_mask & (1 << p))
  174. REG_WRITE(addr, 0x01, 0x003e);
  175. else
  176. REG_WRITE(addr, 0x01, 0x0003);
  177. /*
  178. * Do not limit the period of time that this port can be
  179. * paused for by the remote end or the period of time that
  180. * this port can pause the remote end.
  181. */
  182. REG_WRITE(addr, 0x02, 0x0000);
  183. /*
  184. * Port Control: disable Drop-on-Unlock, disable Drop-on-Lock,
  185. * disable Header mode, enable IGMP/MLD snooping, disable VLAN
  186. * tunneling, determine priority by looking at 802.1p and IP
  187. * priority fields (IP prio has precedence), and set STP state
  188. * to Forwarding.
  189. *
  190. * If this is the CPU link, use DSA or EDSA tagging depending
  191. * on which tagging mode was configured.
  192. *
  193. * If this is a link to another switch, use DSA tagging mode.
  194. *
  195. * If this is the upstream port for this switch, enable
  196. * forwarding of unknown unicasts and multicasts.
  197. */
  198. val = 0x0433;
  199. if (dsa_is_cpu_port(ds, p)) {
  200. if (ds->dst->tag_protocol == htons(ETH_P_EDSA))
  201. val |= 0x3300;
  202. else
  203. val |= 0x0100;
  204. }
  205. if (ds->dsa_port_mask & (1 << p))
  206. val |= 0x0100;
  207. if (p == dsa_upstream_port(ds))
  208. val |= 0x000c;
  209. REG_WRITE(addr, 0x04, val);
  210. /*
  211. * Port Control 1: disable trunking. Also, if this is the
  212. * CPU port, enable learn messages to be sent to this port.
  213. */
  214. REG_WRITE(addr, 0x05, dsa_is_cpu_port(ds, p) ? 0x8000 : 0x0000);
  215. /*
  216. * Port based VLAN map: give each port its own address
  217. * database, allow the CPU port to talk to each of the 'real'
  218. * ports, and allow each of the 'real' ports to only talk to
  219. * the upstream port.
  220. */
  221. val = (p & 0xf) << 12;
  222. if (dsa_is_cpu_port(ds, p))
  223. val |= ds->phys_port_mask;
  224. else
  225. val |= 1 << dsa_upstream_port(ds);
  226. REG_WRITE(addr, 0x06, val);
  227. /*
  228. * Default VLAN ID and priority: don't set a default VLAN
  229. * ID, and set the default packet priority to zero.
  230. */
  231. REG_WRITE(addr, 0x07, 0x0000);
  232. /*
  233. * Port Control 2: don't force a good FCS, set the maximum
  234. * frame size to 10240 bytes, don't let the switch add or
  235. * strip 802.1q tags, don't discard tagged or untagged frames
  236. * on this port, do a destination address lookup on all
  237. * received packets as usual, disable ARP mirroring and don't
  238. * send a copy of all transmitted/received frames on this port
  239. * to the CPU.
  240. */
  241. REG_WRITE(addr, 0x08, 0x2080);
  242. /*
  243. * Egress rate control: disable egress rate control.
  244. */
  245. REG_WRITE(addr, 0x09, 0x0001);
  246. /*
  247. * Egress rate control 2: disable egress rate control.
  248. */
  249. REG_WRITE(addr, 0x0a, 0x0000);
  250. /*
  251. * Port Association Vector: when learning source addresses
  252. * of packets, add the address to the address database using
  253. * a port bitmap that has only the bit for this port set and
  254. * the other bits clear.
  255. */
  256. REG_WRITE(addr, 0x0b, 1 << p);
  257. /*
  258. * Port ATU control: disable limiting the number of address
  259. * database entries that this port is allowed to use.
  260. */
  261. REG_WRITE(addr, 0x0c, 0x0000);
  262. /*
  263. * Priorit Override: disable DA, SA and VTU priority override.
  264. */
  265. REG_WRITE(addr, 0x0d, 0x0000);
  266. /*
  267. * Port Ethertype: use the Ethertype DSA Ethertype value.
  268. */
  269. REG_WRITE(addr, 0x0f, ETH_P_EDSA);
  270. /*
  271. * Tag Remap: use an identity 802.1p prio -> switch prio
  272. * mapping.
  273. */
  274. REG_WRITE(addr, 0x18, 0x3210);
  275. /*
  276. * Tag Remap 2: use an identity 802.1p prio -> switch prio
  277. * mapping.
  278. */
  279. REG_WRITE(addr, 0x19, 0x7654);
  280. return 0;
  281. }
  282. static int mv88e6123_61_65_setup(struct dsa_switch *ds)
  283. {
  284. struct mv88e6xxx_priv_state *ps = (void *)(ds + 1);
  285. int i;
  286. int ret;
  287. mutex_init(&ps->smi_mutex);
  288. mutex_init(&ps->stats_mutex);
  289. ret = mv88e6123_61_65_switch_reset(ds);
  290. if (ret < 0)
  291. return ret;
  292. /* @@@ initialise vtu and atu */
  293. ret = mv88e6123_61_65_setup_global(ds);
  294. if (ret < 0)
  295. return ret;
  296. for (i = 0; i < 6; i++) {
  297. ret = mv88e6123_61_65_setup_port(ds, i);
  298. if (ret < 0)
  299. return ret;
  300. }
  301. return 0;
  302. }
  303. static int mv88e6123_61_65_port_to_phy_addr(int port)
  304. {
  305. if (port >= 0 && port <= 4)
  306. return port;
  307. return -1;
  308. }
  309. static int
  310. mv88e6123_61_65_phy_read(struct dsa_switch *ds, int port, int regnum)
  311. {
  312. int addr = mv88e6123_61_65_port_to_phy_addr(port);
  313. return mv88e6xxx_phy_read(ds, addr, regnum);
  314. }
  315. static int
  316. mv88e6123_61_65_phy_write(struct dsa_switch *ds,
  317. int port, int regnum, u16 val)
  318. {
  319. int addr = mv88e6123_61_65_port_to_phy_addr(port);
  320. return mv88e6xxx_phy_write(ds, addr, regnum, val);
  321. }
  322. static struct mv88e6xxx_hw_stat mv88e6123_61_65_hw_stats[] = {
  323. { "in_good_octets", 8, 0x00, },
  324. { "in_bad_octets", 4, 0x02, },
  325. { "in_unicast", 4, 0x04, },
  326. { "in_broadcasts", 4, 0x06, },
  327. { "in_multicasts", 4, 0x07, },
  328. { "in_pause", 4, 0x16, },
  329. { "in_undersize", 4, 0x18, },
  330. { "in_fragments", 4, 0x19, },
  331. { "in_oversize", 4, 0x1a, },
  332. { "in_jabber", 4, 0x1b, },
  333. { "in_rx_error", 4, 0x1c, },
  334. { "in_fcs_error", 4, 0x1d, },
  335. { "out_octets", 8, 0x0e, },
  336. { "out_unicast", 4, 0x10, },
  337. { "out_broadcasts", 4, 0x13, },
  338. { "out_multicasts", 4, 0x12, },
  339. { "out_pause", 4, 0x15, },
  340. { "excessive", 4, 0x11, },
  341. { "collisions", 4, 0x1e, },
  342. { "deferred", 4, 0x05, },
  343. { "single", 4, 0x14, },
  344. { "multiple", 4, 0x17, },
  345. { "out_fcs_error", 4, 0x03, },
  346. { "late", 4, 0x1f, },
  347. { "hist_64bytes", 4, 0x08, },
  348. { "hist_65_127bytes", 4, 0x09, },
  349. { "hist_128_255bytes", 4, 0x0a, },
  350. { "hist_256_511bytes", 4, 0x0b, },
  351. { "hist_512_1023bytes", 4, 0x0c, },
  352. { "hist_1024_max_bytes", 4, 0x0d, },
  353. };
  354. static void
  355. mv88e6123_61_65_get_strings(struct dsa_switch *ds, int port, uint8_t *data)
  356. {
  357. mv88e6xxx_get_strings(ds, ARRAY_SIZE(mv88e6123_61_65_hw_stats),
  358. mv88e6123_61_65_hw_stats, port, data);
  359. }
  360. static void
  361. mv88e6123_61_65_get_ethtool_stats(struct dsa_switch *ds,
  362. int port, uint64_t *data)
  363. {
  364. mv88e6xxx_get_ethtool_stats(ds, ARRAY_SIZE(mv88e6123_61_65_hw_stats),
  365. mv88e6123_61_65_hw_stats, port, data);
  366. }
  367. static int mv88e6123_61_65_get_sset_count(struct dsa_switch *ds)
  368. {
  369. return ARRAY_SIZE(mv88e6123_61_65_hw_stats);
  370. }
  371. struct dsa_switch_driver mv88e6123_61_65_switch_driver = {
  372. .tag_protocol = cpu_to_be16(ETH_P_EDSA),
  373. .priv_size = sizeof(struct mv88e6xxx_priv_state),
  374. .probe = mv88e6123_61_65_probe,
  375. .setup = mv88e6123_61_65_setup,
  376. .set_addr = mv88e6xxx_set_addr_indirect,
  377. .phy_read = mv88e6123_61_65_phy_read,
  378. .phy_write = mv88e6123_61_65_phy_write,
  379. .poll_link = mv88e6xxx_poll_link,
  380. .get_strings = mv88e6123_61_65_get_strings,
  381. .get_ethtool_stats = mv88e6123_61_65_get_ethtool_stats,
  382. .get_sset_count = mv88e6123_61_65_get_sset_count,
  383. };
  384. MODULE_ALIAS("platform:mv88e6123");
  385. MODULE_ALIAS("platform:mv88e6161");
  386. MODULE_ALIAS("platform:mv88e6165");