mv88e6131.c 9.8 KB

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