mv88e6131.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  1. /*
  2. * net/dsa/mv88e6131.c - Marvell 88e6095/6095f/6131 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 "dsa_priv.h"
  14. #include "mv88e6xxx.h"
  15. /*
  16. * Switch product IDs
  17. */
  18. #define ID_6085 0x04a0
  19. #define ID_6095 0x0950
  20. #define ID_6131 0x1060
  21. static char *mv88e6131_probe(struct mii_bus *bus, int sw_addr)
  22. {
  23. int ret;
  24. ret = __mv88e6xxx_reg_read(bus, sw_addr, REG_PORT(0), 0x03);
  25. if (ret >= 0) {
  26. ret &= 0xfff0;
  27. if (ret == ID_6085)
  28. return "Marvell 88E6085";
  29. if (ret == ID_6095)
  30. return "Marvell 88E6095/88E6095F";
  31. if (ret == ID_6131)
  32. return "Marvell 88E6131";
  33. }
  34. return NULL;
  35. }
  36. static int mv88e6131_switch_reset(struct dsa_switch *ds)
  37. {
  38. int i;
  39. int ret;
  40. /*
  41. * Set all ports to the disabled state.
  42. */
  43. for (i = 0; i < 11; i++) {
  44. ret = REG_READ(REG_PORT(i), 0x04);
  45. REG_WRITE(REG_PORT(i), 0x04, ret & 0xfffc);
  46. }
  47. /*
  48. * Wait for transmit queues to drain.
  49. */
  50. msleep(2);
  51. /*
  52. * Reset the switch.
  53. */
  54. REG_WRITE(REG_GLOBAL, 0x04, 0xc400);
  55. /*
  56. * Wait up to one second for reset to complete.
  57. */
  58. for (i = 0; i < 1000; i++) {
  59. ret = REG_READ(REG_GLOBAL, 0x00);
  60. if ((ret & 0xc800) == 0xc800)
  61. break;
  62. msleep(1);
  63. }
  64. if (i == 1000)
  65. return -ETIMEDOUT;
  66. return 0;
  67. }
  68. static int mv88e6131_setup_global(struct dsa_switch *ds)
  69. {
  70. int ret;
  71. int i;
  72. /*
  73. * Enable the PHY polling unit, don't discard packets with
  74. * excessive collisions, use a weighted fair queueing scheme
  75. * to arbitrate between packet queues, set the maximum frame
  76. * size to 1632, and mask all interrupt sources.
  77. */
  78. REG_WRITE(REG_GLOBAL, 0x04, 0x4400);
  79. /*
  80. * Set the default address aging time to 5 minutes, and
  81. * enable address learn messages to be sent to all message
  82. * ports.
  83. */
  84. REG_WRITE(REG_GLOBAL, 0x0a, 0x0148);
  85. /*
  86. * Configure the priority mapping registers.
  87. */
  88. ret = mv88e6xxx_config_prio(ds);
  89. if (ret < 0)
  90. return ret;
  91. /*
  92. * Set the VLAN ethertype to 0x8100.
  93. */
  94. REG_WRITE(REG_GLOBAL, 0x19, 0x8100);
  95. /*
  96. * Disable ARP mirroring, and configure the upstream port as
  97. * the port to which ingress and egress monitor frames are to
  98. * be sent.
  99. */
  100. REG_WRITE(REG_GLOBAL, 0x1a, (dsa_upstream_port(ds) * 0x1100) | 0x00f0);
  101. /*
  102. * Disable cascade port functionality, and set the switch's
  103. * DSA device number.
  104. */
  105. REG_WRITE(REG_GLOBAL, 0x1c, 0xe000 | (ds->index & 0x1f));
  106. /*
  107. * Send all frames with destination addresses matching
  108. * 01:80:c2:00:00:0x to the CPU port.
  109. */
  110. REG_WRITE(REG_GLOBAL2, 0x03, 0xffff);
  111. /*
  112. * Ignore removed tag data on doubly tagged packets, disable
  113. * flow control messages, force flow control priority to the
  114. * highest, and send all special multicast frames to the CPU
  115. * port at the highest priority.
  116. */
  117. REG_WRITE(REG_GLOBAL2, 0x05, 0x00ff);
  118. /*
  119. * Program the DSA routing table.
  120. */
  121. for (i = 0; i < 32; i++) {
  122. int nexthop;
  123. nexthop = 0x1f;
  124. if (i != ds->index && i < ds->dst->pd->nr_chips)
  125. nexthop = ds->pd->rtable[i] & 0x1f;
  126. REG_WRITE(REG_GLOBAL2, 0x06, 0x8000 | (i << 8) | nexthop);
  127. }
  128. /*
  129. * Clear all trunk masks.
  130. */
  131. for (i = 0; i < 8; i++)
  132. REG_WRITE(REG_GLOBAL2, 0x07, 0x8000 | (i << 12) | 0x7ff);
  133. /*
  134. * Clear all trunk mappings.
  135. */
  136. for (i = 0; i < 16; i++)
  137. REG_WRITE(REG_GLOBAL2, 0x08, 0x8000 | (i << 11));
  138. /*
  139. * Force the priority of IGMP/MLD snoop frames and ARP frames
  140. * to the highest setting.
  141. */
  142. REG_WRITE(REG_GLOBAL2, 0x0f, 0x00ff);
  143. return 0;
  144. }
  145. static int mv88e6131_setup_port(struct dsa_switch *ds, int p)
  146. {
  147. struct mv88e6xxx_priv_state *ps = (void *)(ds + 1);
  148. int addr = REG_PORT(p);
  149. u16 val;
  150. /*
  151. * MAC Forcing register: don't force link, speed, duplex
  152. * or flow control state to any particular values on physical
  153. * ports, but force the CPU port and all DSA ports to 1000 Mb/s
  154. * (100 Mb/s on 6085) full duplex.
  155. */
  156. if (dsa_is_cpu_port(ds, p) || ds->dsa_port_mask & (1 << p))
  157. if (ps->id == ID_6085)
  158. REG_WRITE(addr, 0x01, 0x003d); /* 100 Mb/s */
  159. else
  160. REG_WRITE(addr, 0x01, 0x003e); /* 1000 Mb/s */
  161. else
  162. REG_WRITE(addr, 0x01, 0x0003);
  163. /*
  164. * Port Control: disable Core Tag, disable Drop-on-Lock,
  165. * transmit frames unmodified, disable Header mode,
  166. * enable IGMP/MLD snoop, disable DoubleTag, disable VLAN
  167. * tunneling, determine priority by looking at 802.1p and
  168. * IP priority fields (IP prio has precedence), and set STP
  169. * state to Forwarding.
  170. *
  171. * If this is the upstream port for this switch, enable
  172. * forwarding of unknown unicasts, and enable DSA tagging
  173. * mode.
  174. *
  175. * If this is the link to another switch, use DSA tagging
  176. * mode, but do not enable forwarding of unknown unicasts.
  177. */
  178. val = 0x0433;
  179. if (p == dsa_upstream_port(ds)) {
  180. val |= 0x0104;
  181. /*
  182. * On 6085, unknown multicast forward is controlled
  183. * here rather than in Port Control 2 register.
  184. */
  185. if (ps->id == ID_6085)
  186. val |= 0x0008;
  187. }
  188. if (ds->dsa_port_mask & (1 << p))
  189. val |= 0x0100;
  190. REG_WRITE(addr, 0x04, val);
  191. /*
  192. * Port Control 1: disable trunking. Also, if this is the
  193. * CPU port, enable learn messages to be sent to this port.
  194. */
  195. REG_WRITE(addr, 0x05, dsa_is_cpu_port(ds, p) ? 0x8000 : 0x0000);
  196. /*
  197. * Port based VLAN map: give each port its own address
  198. * database, allow the CPU port to talk to each of the 'real'
  199. * ports, and allow each of the 'real' ports to only talk to
  200. * the upstream port.
  201. */
  202. val = (p & 0xf) << 12;
  203. if (dsa_is_cpu_port(ds, p))
  204. val |= ds->phys_port_mask;
  205. else
  206. val |= 1 << dsa_upstream_port(ds);
  207. REG_WRITE(addr, 0x06, val);
  208. /*
  209. * Default VLAN ID and priority: don't set a default VLAN
  210. * ID, and set the default packet priority to zero.
  211. */
  212. REG_WRITE(addr, 0x07, 0x0000);
  213. /*
  214. * Port Control 2: don't force a good FCS, don't use
  215. * VLAN-based, source address-based or destination
  216. * address-based priority overrides, don't let the switch
  217. * add or strip 802.1q tags, don't discard tagged or
  218. * untagged frames on this port, do a destination address
  219. * lookup on received packets as usual, don't send a copy
  220. * of all transmitted/received frames on this port to the
  221. * CPU, and configure the upstream port number.
  222. *
  223. * If this is the upstream port for this switch, enable
  224. * forwarding of unknown multicast addresses.
  225. */
  226. if (ps->id == ID_6085)
  227. /*
  228. * on 6085, bits 3:0 are reserved, bit 6 control ARP
  229. * mirroring, and multicast forward is handled in
  230. * Port Control register.
  231. */
  232. REG_WRITE(addr, 0x08, 0x0080);
  233. else {
  234. val = 0x0080 | dsa_upstream_port(ds);
  235. if (p == dsa_upstream_port(ds))
  236. val |= 0x0040;
  237. REG_WRITE(addr, 0x08, val);
  238. }
  239. /*
  240. * Rate Control: disable ingress rate limiting.
  241. */
  242. REG_WRITE(addr, 0x09, 0x0000);
  243. /*
  244. * Rate Control 2: disable egress rate limiting.
  245. */
  246. REG_WRITE(addr, 0x0a, 0x0000);
  247. /*
  248. * Port Association Vector: when learning source addresses
  249. * of packets, add the address to the address database using
  250. * a port bitmap that has only the bit for this port set and
  251. * the other bits clear.
  252. */
  253. REG_WRITE(addr, 0x0b, 1 << p);
  254. /*
  255. * Tag Remap: use an identity 802.1p prio -> switch prio
  256. * mapping.
  257. */
  258. REG_WRITE(addr, 0x18, 0x3210);
  259. /*
  260. * Tag Remap 2: use an identity 802.1p prio -> switch prio
  261. * mapping.
  262. */
  263. REG_WRITE(addr, 0x19, 0x7654);
  264. return 0;
  265. }
  266. static int mv88e6131_setup(struct dsa_switch *ds)
  267. {
  268. struct mv88e6xxx_priv_state *ps = (void *)(ds + 1);
  269. int i;
  270. int ret;
  271. mutex_init(&ps->smi_mutex);
  272. mv88e6xxx_ppu_state_init(ds);
  273. mutex_init(&ps->stats_mutex);
  274. ps->id = REG_READ(REG_PORT(0), 0x03) & 0xfff0;
  275. ret = mv88e6131_switch_reset(ds);
  276. if (ret < 0)
  277. return ret;
  278. /* @@@ initialise vtu and atu */
  279. ret = mv88e6131_setup_global(ds);
  280. if (ret < 0)
  281. return ret;
  282. for (i = 0; i < 11; i++) {
  283. ret = mv88e6131_setup_port(ds, i);
  284. if (ret < 0)
  285. return ret;
  286. }
  287. return 0;
  288. }
  289. static int mv88e6131_port_to_phy_addr(int port)
  290. {
  291. if (port >= 0 && port <= 11)
  292. return port;
  293. return -1;
  294. }
  295. static int
  296. mv88e6131_phy_read(struct dsa_switch *ds, int port, int regnum)
  297. {
  298. int addr = mv88e6131_port_to_phy_addr(port);
  299. return mv88e6xxx_phy_read_ppu(ds, addr, regnum);
  300. }
  301. static int
  302. mv88e6131_phy_write(struct dsa_switch *ds,
  303. int port, int regnum, u16 val)
  304. {
  305. int addr = mv88e6131_port_to_phy_addr(port);
  306. return mv88e6xxx_phy_write_ppu(ds, addr, regnum, val);
  307. }
  308. static struct mv88e6xxx_hw_stat mv88e6131_hw_stats[] = {
  309. { "in_good_octets", 8, 0x00, },
  310. { "in_bad_octets", 4, 0x02, },
  311. { "in_unicast", 4, 0x04, },
  312. { "in_broadcasts", 4, 0x06, },
  313. { "in_multicasts", 4, 0x07, },
  314. { "in_pause", 4, 0x16, },
  315. { "in_undersize", 4, 0x18, },
  316. { "in_fragments", 4, 0x19, },
  317. { "in_oversize", 4, 0x1a, },
  318. { "in_jabber", 4, 0x1b, },
  319. { "in_rx_error", 4, 0x1c, },
  320. { "in_fcs_error", 4, 0x1d, },
  321. { "out_octets", 8, 0x0e, },
  322. { "out_unicast", 4, 0x10, },
  323. { "out_broadcasts", 4, 0x13, },
  324. { "out_multicasts", 4, 0x12, },
  325. { "out_pause", 4, 0x15, },
  326. { "excessive", 4, 0x11, },
  327. { "collisions", 4, 0x1e, },
  328. { "deferred", 4, 0x05, },
  329. { "single", 4, 0x14, },
  330. { "multiple", 4, 0x17, },
  331. { "out_fcs_error", 4, 0x03, },
  332. { "late", 4, 0x1f, },
  333. { "hist_64bytes", 4, 0x08, },
  334. { "hist_65_127bytes", 4, 0x09, },
  335. { "hist_128_255bytes", 4, 0x0a, },
  336. { "hist_256_511bytes", 4, 0x0b, },
  337. { "hist_512_1023bytes", 4, 0x0c, },
  338. { "hist_1024_max_bytes", 4, 0x0d, },
  339. };
  340. static void
  341. mv88e6131_get_strings(struct dsa_switch *ds, int port, uint8_t *data)
  342. {
  343. mv88e6xxx_get_strings(ds, ARRAY_SIZE(mv88e6131_hw_stats),
  344. mv88e6131_hw_stats, port, data);
  345. }
  346. static void
  347. mv88e6131_get_ethtool_stats(struct dsa_switch *ds,
  348. int port, uint64_t *data)
  349. {
  350. mv88e6xxx_get_ethtool_stats(ds, ARRAY_SIZE(mv88e6131_hw_stats),
  351. mv88e6131_hw_stats, port, data);
  352. }
  353. static int mv88e6131_get_sset_count(struct dsa_switch *ds)
  354. {
  355. return ARRAY_SIZE(mv88e6131_hw_stats);
  356. }
  357. static struct dsa_switch_driver mv88e6131_switch_driver = {
  358. .tag_protocol = cpu_to_be16(ETH_P_DSA),
  359. .priv_size = sizeof(struct mv88e6xxx_priv_state),
  360. .probe = mv88e6131_probe,
  361. .setup = mv88e6131_setup,
  362. .set_addr = mv88e6xxx_set_addr_direct,
  363. .phy_read = mv88e6131_phy_read,
  364. .phy_write = mv88e6131_phy_write,
  365. .poll_link = mv88e6xxx_poll_link,
  366. .get_strings = mv88e6131_get_strings,
  367. .get_ethtool_stats = mv88e6131_get_ethtool_stats,
  368. .get_sset_count = mv88e6131_get_sset_count,
  369. };
  370. static int __init mv88e6131_init(void)
  371. {
  372. register_switch_driver(&mv88e6131_switch_driver);
  373. return 0;
  374. }
  375. module_init(mv88e6131_init);
  376. static void __exit mv88e6131_cleanup(void)
  377. {
  378. unregister_switch_driver(&mv88e6131_switch_driver);
  379. }
  380. module_exit(mv88e6131_cleanup);