mv88e6123_61_65.c 11 KB

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