/kern_oII/net/dsa/mv88e6123_61_65.c

http://omnia2droid.googlecode.com/ · C · 447 lines · 224 code · 64 blank · 159 comment · 37 complexity · dbddb839f366d7ee1e5eec378b8dab5d MD5 · raw file

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