mv88e6131.c 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  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/delay.h>
  11. #include <linux/jiffies.h>
  12. #include <linux/list.h>
  13. #include <linux/module.h>
  14. #include <linux/netdevice.h>
  15. #include <linux/phy.h>
  16. #include <net/dsa.h>
  17. #include "mv88e6xxx.h"
  18. static char *mv88e6131_probe(struct device *host_dev, int sw_addr)
  19. {
  20. struct mii_bus *bus = dsa_host_dev_to_mii_bus(host_dev);
  21. int ret;
  22. if (bus == NULL)
  23. return NULL;
  24. ret = __mv88e6xxx_reg_read(bus, sw_addr, REG_PORT(0), PORT_SWITCH_ID);
  25. if (ret >= 0) {
  26. int ret_masked = ret & 0xfff0;
  27. if (ret_masked == PORT_SWITCH_ID_6085)
  28. return "Marvell 88E6085";
  29. if (ret_masked == PORT_SWITCH_ID_6095)
  30. return "Marvell 88E6095/88E6095F";
  31. if (ret == PORT_SWITCH_ID_6131_B2)
  32. return "Marvell 88E6131 (B2)";
  33. if (ret_masked == PORT_SWITCH_ID_6131)
  34. return "Marvell 88E6131";
  35. }
  36. return NULL;
  37. }
  38. static int mv88e6131_setup_global(struct dsa_switch *ds)
  39. {
  40. int ret;
  41. int i;
  42. /* Enable the PHY polling unit, don't discard packets with
  43. * excessive collisions, use a weighted fair queueing scheme
  44. * to arbitrate between packet queues, set the maximum frame
  45. * size to 1632, and mask all interrupt sources.
  46. */
  47. REG_WRITE(REG_GLOBAL, 0x04, 0x4400);
  48. /* Set the default address aging time to 5 minutes, and
  49. * enable address learn messages to be sent to all message
  50. * ports.
  51. */
  52. REG_WRITE(REG_GLOBAL, 0x0a, 0x0148);
  53. /* Configure the priority mapping registers. */
  54. ret = mv88e6xxx_config_prio(ds);
  55. if (ret < 0)
  56. return ret;
  57. /* Set the VLAN ethertype to 0x8100. */
  58. REG_WRITE(REG_GLOBAL, 0x19, 0x8100);
  59. /* Disable ARP mirroring, and configure the upstream port as
  60. * the port to which ingress and egress monitor frames are to
  61. * be sent.
  62. */
  63. REG_WRITE(REG_GLOBAL, 0x1a, (dsa_upstream_port(ds) * 0x1100) | 0x00f0);
  64. /* Disable cascade port functionality unless this device
  65. * is used in a cascade configuration, and set the switch's
  66. * DSA device number.
  67. */
  68. if (ds->dst->pd->nr_chips > 1)
  69. REG_WRITE(REG_GLOBAL, 0x1c, 0xf000 | (ds->index & 0x1f));
  70. else
  71. REG_WRITE(REG_GLOBAL, 0x1c, 0xe000 | (ds->index & 0x1f));
  72. /* Send all frames with destination addresses matching
  73. * 01:80:c2:00:00:0x to the CPU port.
  74. */
  75. REG_WRITE(REG_GLOBAL2, 0x03, 0xffff);
  76. /* Ignore removed tag data on doubly tagged packets, disable
  77. * flow control messages, force flow control priority to the
  78. * highest, and send all special multicast frames to the CPU
  79. * port at the highest priority.
  80. */
  81. REG_WRITE(REG_GLOBAL2, 0x05, 0x00ff);
  82. /* Program the DSA routing table. */
  83. for (i = 0; i < 32; i++) {
  84. int nexthop;
  85. nexthop = 0x1f;
  86. if (ds->pd->rtable &&
  87. i != ds->index && i < ds->dst->pd->nr_chips)
  88. nexthop = ds->pd->rtable[i] & 0x1f;
  89. REG_WRITE(REG_GLOBAL2, 0x06, 0x8000 | (i << 8) | nexthop);
  90. }
  91. /* Clear all trunk masks. */
  92. for (i = 0; i < 8; i++)
  93. REG_WRITE(REG_GLOBAL2, 0x07, 0x8000 | (i << 12) | 0x7ff);
  94. /* Clear all trunk mappings. */
  95. for (i = 0; i < 16; i++)
  96. REG_WRITE(REG_GLOBAL2, 0x08, 0x8000 | (i << 11));
  97. /* Force the priority of IGMP/MLD snoop frames and ARP frames
  98. * to the highest setting.
  99. */
  100. REG_WRITE(REG_GLOBAL2, 0x0f, 0x00ff);
  101. return 0;
  102. }
  103. static int mv88e6131_setup_port(struct dsa_switch *ds, int p)
  104. {
  105. struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
  106. int addr = REG_PORT(p);
  107. u16 val;
  108. /* MAC Forcing register: don't force link, speed, duplex
  109. * or flow control state to any particular values on physical
  110. * ports, but force the CPU port and all DSA ports to 1000 Mb/s
  111. * (100 Mb/s on 6085) full duplex.
  112. */
  113. if (dsa_is_cpu_port(ds, p) || ds->dsa_port_mask & (1 << p))
  114. if (ps->id == PORT_SWITCH_ID_6085)
  115. REG_WRITE(addr, 0x01, 0x003d); /* 100 Mb/s */
  116. else
  117. REG_WRITE(addr, 0x01, 0x003e); /* 1000 Mb/s */
  118. else
  119. REG_WRITE(addr, 0x01, 0x0003);
  120. /* Port Control: disable Core Tag, disable Drop-on-Lock,
  121. * transmit frames unmodified, disable Header mode,
  122. * enable IGMP/MLD snoop, disable DoubleTag, disable VLAN
  123. * tunneling, determine priority by looking at 802.1p and
  124. * IP priority fields (IP prio has precedence), and set STP
  125. * state to Forwarding.
  126. *
  127. * If this is the upstream port for this switch, enable
  128. * forwarding of unknown unicasts, and enable DSA tagging
  129. * mode.
  130. *
  131. * If this is the link to another switch, use DSA tagging
  132. * mode, but do not enable forwarding of unknown unicasts.
  133. */
  134. val = 0x0433;
  135. if (p == dsa_upstream_port(ds)) {
  136. val |= 0x0104;
  137. /* On 6085, unknown multicast forward is controlled
  138. * here rather than in Port Control 2 register.
  139. */
  140. if (ps->id == PORT_SWITCH_ID_6085)
  141. val |= 0x0008;
  142. }
  143. if (ds->dsa_port_mask & (1 << p))
  144. val |= 0x0100;
  145. REG_WRITE(addr, 0x04, val);
  146. /* Port Control 2: don't force a good FCS, don't use
  147. * VLAN-based, source address-based or destination
  148. * address-based priority overrides, don't let the switch
  149. * add or strip 802.1q tags, don't discard tagged or
  150. * untagged frames on this port, do a destination address
  151. * lookup on received packets as usual, don't send a copy
  152. * of all transmitted/received frames on this port to the
  153. * CPU, and configure the upstream port number.
  154. *
  155. * If this is the upstream port for this switch, enable
  156. * forwarding of unknown multicast addresses.
  157. */
  158. if (ps->id == PORT_SWITCH_ID_6085)
  159. /* on 6085, bits 3:0 are reserved, bit 6 control ARP
  160. * mirroring, and multicast forward is handled in
  161. * Port Control register.
  162. */
  163. REG_WRITE(addr, 0x08, 0x0080);
  164. else {
  165. val = 0x0080 | dsa_upstream_port(ds);
  166. if (p == dsa_upstream_port(ds))
  167. val |= 0x0040;
  168. REG_WRITE(addr, 0x08, val);
  169. }
  170. /* Rate Control: disable ingress rate limiting. */
  171. REG_WRITE(addr, 0x09, 0x0000);
  172. /* Rate Control 2: disable egress rate limiting. */
  173. REG_WRITE(addr, 0x0a, 0x0000);
  174. /* Port Association Vector: when learning source addresses
  175. * of packets, add the address to the address database using
  176. * a port bitmap that has only the bit for this port set and
  177. * the other bits clear.
  178. */
  179. REG_WRITE(addr, 0x0b, 1 << p);
  180. /* Tag Remap: use an identity 802.1p prio -> switch prio
  181. * mapping.
  182. */
  183. REG_WRITE(addr, 0x18, 0x3210);
  184. /* Tag Remap 2: use an identity 802.1p prio -> switch prio
  185. * mapping.
  186. */
  187. REG_WRITE(addr, 0x19, 0x7654);
  188. return mv88e6xxx_setup_port_common(ds, p);
  189. }
  190. static int mv88e6131_setup(struct dsa_switch *ds)
  191. {
  192. struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
  193. int i;
  194. int ret;
  195. ret = mv88e6xxx_setup_common(ds);
  196. if (ret < 0)
  197. return ret;
  198. mv88e6xxx_ppu_state_init(ds);
  199. switch (ps->id) {
  200. case PORT_SWITCH_ID_6085:
  201. ps->num_ports = 10;
  202. break;
  203. case PORT_SWITCH_ID_6095:
  204. ps->num_ports = 11;
  205. break;
  206. case PORT_SWITCH_ID_6131:
  207. case PORT_SWITCH_ID_6131_B2:
  208. ps->num_ports = 8;
  209. break;
  210. default:
  211. return -ENODEV;
  212. }
  213. ret = mv88e6xxx_switch_reset(ds, false);
  214. if (ret < 0)
  215. return ret;
  216. /* @@@ initialise vtu and atu */
  217. ret = mv88e6131_setup_global(ds);
  218. if (ret < 0)
  219. return ret;
  220. for (i = 0; i < ps->num_ports; i++) {
  221. ret = mv88e6131_setup_port(ds, i);
  222. if (ret < 0)
  223. return ret;
  224. }
  225. return 0;
  226. }
  227. static int mv88e6131_port_to_phy_addr(struct dsa_switch *ds, int port)
  228. {
  229. struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
  230. if (port >= 0 && port < ps->num_ports)
  231. return port;
  232. return -EINVAL;
  233. }
  234. static int
  235. mv88e6131_phy_read(struct dsa_switch *ds, int port, int regnum)
  236. {
  237. int addr = mv88e6131_port_to_phy_addr(ds, port);
  238. if (addr < 0)
  239. return addr;
  240. return mv88e6xxx_phy_read_ppu(ds, addr, regnum);
  241. }
  242. static int
  243. mv88e6131_phy_write(struct dsa_switch *ds,
  244. int port, int regnum, u16 val)
  245. {
  246. int addr = mv88e6131_port_to_phy_addr(ds, port);
  247. if (addr < 0)
  248. return addr;
  249. return mv88e6xxx_phy_write_ppu(ds, addr, regnum, val);
  250. }
  251. struct dsa_switch_driver mv88e6131_switch_driver = {
  252. .tag_protocol = DSA_TAG_PROTO_DSA,
  253. .priv_size = sizeof(struct mv88e6xxx_priv_state),
  254. .probe = mv88e6131_probe,
  255. .setup = mv88e6131_setup,
  256. .set_addr = mv88e6xxx_set_addr_direct,
  257. .phy_read = mv88e6131_phy_read,
  258. .phy_write = mv88e6131_phy_write,
  259. .poll_link = mv88e6xxx_poll_link,
  260. .get_strings = mv88e6xxx_get_strings,
  261. .get_ethtool_stats = mv88e6xxx_get_ethtool_stats,
  262. .get_sset_count = mv88e6xxx_get_sset_count,
  263. };
  264. MODULE_ALIAS("platform:mv88e6085");
  265. MODULE_ALIAS("platform:mv88e6095");
  266. MODULE_ALIAS("platform:mv88e6095f");
  267. MODULE_ALIAS("platform:mv88e6131");