chip.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. /*
  2. * Marvell 88E6xxx Ethernet switch single-chip definition
  3. *
  4. * Copyright (c) 2008 Marvell Semiconductor
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. */
  11. #ifndef _MV88E6XXX_CHIP_H
  12. #define _MV88E6XXX_CHIP_H
  13. #include <linux/if_vlan.h>
  14. #include <linux/irq.h>
  15. #include <linux/gpio/consumer.h>
  16. #include <linux/phy.h>
  17. #include <net/dsa.h>
  18. #ifndef UINT64_MAX
  19. #define UINT64_MAX (u64)(~((u64)0))
  20. #endif
  21. #define SMI_CMD 0x00
  22. #define SMI_CMD_BUSY BIT(15)
  23. #define SMI_CMD_CLAUSE_22 BIT(12)
  24. #define SMI_CMD_OP_22_WRITE ((1 << 10) | SMI_CMD_BUSY | SMI_CMD_CLAUSE_22)
  25. #define SMI_CMD_OP_22_READ ((2 << 10) | SMI_CMD_BUSY | SMI_CMD_CLAUSE_22)
  26. #define SMI_CMD_OP_45_WRITE_ADDR ((0 << 10) | SMI_CMD_BUSY)
  27. #define SMI_CMD_OP_45_WRITE_DATA ((1 << 10) | SMI_CMD_BUSY)
  28. #define SMI_CMD_OP_45_READ_DATA ((2 << 10) | SMI_CMD_BUSY)
  29. #define SMI_CMD_OP_45_READ_DATA_INC ((3 << 10) | SMI_CMD_BUSY)
  30. #define SMI_DATA 0x01
  31. #define MV88E6XXX_N_FID 4096
  32. /* PVT limits for 4-bit port and 5-bit switch */
  33. #define MV88E6XXX_MAX_PVT_SWITCHES 32
  34. #define MV88E6XXX_MAX_PVT_PORTS 16
  35. enum mv88e6xxx_egress_mode {
  36. MV88E6XXX_EGRESS_MODE_UNMODIFIED,
  37. MV88E6XXX_EGRESS_MODE_UNTAGGED,
  38. MV88E6XXX_EGRESS_MODE_TAGGED,
  39. MV88E6XXX_EGRESS_MODE_ETHERTYPE,
  40. };
  41. enum mv88e6xxx_frame_mode {
  42. MV88E6XXX_FRAME_MODE_NORMAL,
  43. MV88E6XXX_FRAME_MODE_DSA,
  44. MV88E6XXX_FRAME_MODE_PROVIDER,
  45. MV88E6XXX_FRAME_MODE_ETHERTYPE,
  46. };
  47. /* List of supported models */
  48. enum mv88e6xxx_model {
  49. MV88E6085,
  50. MV88E6095,
  51. MV88E6097,
  52. MV88E6123,
  53. MV88E6131,
  54. MV88E6141,
  55. MV88E6161,
  56. MV88E6165,
  57. MV88E6171,
  58. MV88E6172,
  59. MV88E6175,
  60. MV88E6176,
  61. MV88E6185,
  62. MV88E6190,
  63. MV88E6190X,
  64. MV88E6191,
  65. MV88E6240,
  66. MV88E6290,
  67. MV88E6320,
  68. MV88E6321,
  69. MV88E6341,
  70. MV88E6350,
  71. MV88E6351,
  72. MV88E6352,
  73. MV88E6390,
  74. MV88E6390X,
  75. };
  76. enum mv88e6xxx_family {
  77. MV88E6XXX_FAMILY_NONE,
  78. MV88E6XXX_FAMILY_6065, /* 6031 6035 6061 6065 */
  79. MV88E6XXX_FAMILY_6095, /* 6092 6095 */
  80. MV88E6XXX_FAMILY_6097, /* 6046 6085 6096 6097 */
  81. MV88E6XXX_FAMILY_6165, /* 6123 6161 6165 */
  82. MV88E6XXX_FAMILY_6185, /* 6108 6121 6122 6131 6152 6155 6182 6185 */
  83. MV88E6XXX_FAMILY_6320, /* 6320 6321 */
  84. MV88E6XXX_FAMILY_6341, /* 6141 6341 */
  85. MV88E6XXX_FAMILY_6351, /* 6171 6175 6350 6351 */
  86. MV88E6XXX_FAMILY_6352, /* 6172 6176 6240 6352 */
  87. MV88E6XXX_FAMILY_6390, /* 6190 6190X 6191 6290 6390 6390X */
  88. };
  89. struct mv88e6xxx_ops;
  90. struct mv88e6xxx_info {
  91. enum mv88e6xxx_family family;
  92. u16 prod_num;
  93. const char *name;
  94. unsigned int num_databases;
  95. unsigned int num_ports;
  96. unsigned int max_vid;
  97. unsigned int port_base_addr;
  98. unsigned int global1_addr;
  99. unsigned int global2_addr;
  100. unsigned int age_time_coeff;
  101. unsigned int g1_irqs;
  102. unsigned int g2_irqs;
  103. bool pvt;
  104. /* Multi-chip Addressing Mode.
  105. * Some chips respond to only 2 registers of its own SMI device address
  106. * when it is non-zero, and use indirect access to internal registers.
  107. */
  108. bool multi_chip;
  109. enum dsa_tag_protocol tag_protocol;
  110. /* Mask for FromPort and ToPort value of PortVec used in ATU Move
  111. * operation. 0 means that the ATU Move operation is not supported.
  112. */
  113. u8 atu_move_port_mask;
  114. const struct mv88e6xxx_ops *ops;
  115. };
  116. struct mv88e6xxx_atu_entry {
  117. u8 state;
  118. bool trunk;
  119. u16 portvec;
  120. u8 mac[ETH_ALEN];
  121. };
  122. struct mv88e6xxx_vtu_entry {
  123. u16 vid;
  124. u16 fid;
  125. u8 sid;
  126. bool valid;
  127. u8 member[DSA_MAX_PORTS];
  128. u8 state[DSA_MAX_PORTS];
  129. };
  130. struct mv88e6xxx_bus_ops;
  131. struct mv88e6xxx_irq_ops;
  132. struct mv88e6xxx_irq {
  133. u16 masked;
  134. struct irq_chip chip;
  135. struct irq_domain *domain;
  136. unsigned int nirqs;
  137. };
  138. struct mv88e6xxx_chip {
  139. const struct mv88e6xxx_info *info;
  140. /* The dsa_switch this private structure is related to */
  141. struct dsa_switch *ds;
  142. /* The device this structure is associated to */
  143. struct device *dev;
  144. /* This mutex protects the access to the switch registers */
  145. struct mutex reg_lock;
  146. /* The MII bus and the address on the bus that is used to
  147. * communication with the switch
  148. */
  149. const struct mv88e6xxx_bus_ops *smi_ops;
  150. struct mii_bus *bus;
  151. int sw_addr;
  152. /* Handles automatic disabling and re-enabling of the PHY
  153. * polling unit.
  154. */
  155. const struct mv88e6xxx_bus_ops *phy_ops;
  156. struct mutex ppu_mutex;
  157. int ppu_disabled;
  158. struct work_struct ppu_work;
  159. struct timer_list ppu_timer;
  160. /* This mutex serialises access to the statistics unit.
  161. * Hold this mutex over snapshot + dump sequences.
  162. */
  163. struct mutex stats_mutex;
  164. /* A switch may have a GPIO line tied to its reset pin. Parse
  165. * this from the device tree, and use it before performing
  166. * switch soft reset.
  167. */
  168. struct gpio_desc *reset;
  169. /* set to size of eeprom if supported by the switch */
  170. int eeprom_len;
  171. /* List of mdio busses */
  172. struct list_head mdios;
  173. /* There can be two interrupt controllers, which are chained
  174. * off a GPIO as interrupt source
  175. */
  176. struct mv88e6xxx_irq g1_irq;
  177. struct mv88e6xxx_irq g2_irq;
  178. int irq;
  179. int device_irq;
  180. int watchdog_irq;
  181. };
  182. struct mv88e6xxx_bus_ops {
  183. int (*read)(struct mv88e6xxx_chip *chip, int addr, int reg, u16 *val);
  184. int (*write)(struct mv88e6xxx_chip *chip, int addr, int reg, u16 val);
  185. };
  186. struct mv88e6xxx_mdio_bus {
  187. struct mii_bus *bus;
  188. struct mv88e6xxx_chip *chip;
  189. struct list_head list;
  190. bool external;
  191. };
  192. struct mv88e6xxx_ops {
  193. /* Ingress Rate Limit unit (IRL) operations */
  194. int (*irl_init_all)(struct mv88e6xxx_chip *chip, int port);
  195. int (*get_eeprom)(struct mv88e6xxx_chip *chip,
  196. struct ethtool_eeprom *eeprom, u8 *data);
  197. int (*set_eeprom)(struct mv88e6xxx_chip *chip,
  198. struct ethtool_eeprom *eeprom, u8 *data);
  199. int (*set_switch_mac)(struct mv88e6xxx_chip *chip, u8 *addr);
  200. int (*phy_read)(struct mv88e6xxx_chip *chip,
  201. struct mii_bus *bus,
  202. int addr, int reg, u16 *val);
  203. int (*phy_write)(struct mv88e6xxx_chip *chip,
  204. struct mii_bus *bus,
  205. int addr, int reg, u16 val);
  206. /* Priority Override Table operations */
  207. int (*pot_clear)(struct mv88e6xxx_chip *chip);
  208. /* PHY Polling Unit (PPU) operations */
  209. int (*ppu_enable)(struct mv88e6xxx_chip *chip);
  210. int (*ppu_disable)(struct mv88e6xxx_chip *chip);
  211. /* Switch Software Reset */
  212. int (*reset)(struct mv88e6xxx_chip *chip);
  213. /* RGMII Receive/Transmit Timing Control
  214. * Add delay on PHY_INTERFACE_MODE_RGMII_*ID, no delay otherwise.
  215. */
  216. int (*port_set_rgmii_delay)(struct mv88e6xxx_chip *chip, int port,
  217. phy_interface_t mode);
  218. #define LINK_FORCED_DOWN 0
  219. #define LINK_FORCED_UP 1
  220. #define LINK_UNFORCED -2
  221. /* Port's MAC link state
  222. * Use LINK_FORCED_UP or LINK_FORCED_DOWN to force link up or down,
  223. * or LINK_UNFORCED for normal link detection.
  224. */
  225. int (*port_set_link)(struct mv88e6xxx_chip *chip, int port, int link);
  226. #define DUPLEX_UNFORCED -2
  227. /* Port's MAC duplex mode
  228. *
  229. * Use DUPLEX_HALF or DUPLEX_FULL to force half or full duplex,
  230. * or DUPLEX_UNFORCED for normal duplex detection.
  231. */
  232. int (*port_set_duplex)(struct mv88e6xxx_chip *chip, int port, int dup);
  233. #define SPEED_MAX INT_MAX
  234. #define SPEED_UNFORCED -2
  235. /* Port's MAC speed (in Mbps)
  236. *
  237. * Depending on the chip, 10, 100, 200, 1000, 2500, 10000 are valid.
  238. * Use SPEED_UNFORCED for normal detection, SPEED_MAX for max value.
  239. */
  240. int (*port_set_speed)(struct mv88e6xxx_chip *chip, int port, int speed);
  241. int (*port_tag_remap)(struct mv88e6xxx_chip *chip, int port);
  242. int (*port_set_frame_mode)(struct mv88e6xxx_chip *chip, int port,
  243. enum mv88e6xxx_frame_mode mode);
  244. int (*port_set_egress_floods)(struct mv88e6xxx_chip *chip, int port,
  245. bool unicast, bool multicast);
  246. int (*port_set_ether_type)(struct mv88e6xxx_chip *chip, int port,
  247. u16 etype);
  248. int (*port_set_jumbo_size)(struct mv88e6xxx_chip *chip, int port,
  249. size_t size);
  250. int (*port_egress_rate_limiting)(struct mv88e6xxx_chip *chip, int port);
  251. int (*port_pause_limit)(struct mv88e6xxx_chip *chip, int port, u8 in,
  252. u8 out);
  253. int (*port_disable_learn_limit)(struct mv88e6xxx_chip *chip, int port);
  254. int (*port_disable_pri_override)(struct mv88e6xxx_chip *chip, int port);
  255. /* CMODE control what PHY mode the MAC will use, eg. SGMII, RGMII, etc.
  256. * Some chips allow this to be configured on specific ports.
  257. */
  258. int (*port_set_cmode)(struct mv88e6xxx_chip *chip, int port,
  259. phy_interface_t mode);
  260. /* Some devices have a per port register indicating what is
  261. * the upstream port this port should forward to.
  262. */
  263. int (*port_set_upstream_port)(struct mv88e6xxx_chip *chip, int port,
  264. int upstream_port);
  265. /* Snapshot the statistics for a port. The statistics can then
  266. * be read back a leisure but still with a consistent view.
  267. */
  268. int (*stats_snapshot)(struct mv88e6xxx_chip *chip, int port);
  269. /* Set the histogram mode for statistics, when the control registers
  270. * are separated out of the STATS_OP register.
  271. */
  272. int (*stats_set_histogram)(struct mv88e6xxx_chip *chip);
  273. /* Return the number of strings describing statistics */
  274. int (*stats_get_sset_count)(struct mv88e6xxx_chip *chip);
  275. void (*stats_get_strings)(struct mv88e6xxx_chip *chip, uint8_t *data);
  276. void (*stats_get_stats)(struct mv88e6xxx_chip *chip, int port,
  277. uint64_t *data);
  278. int (*set_cpu_port)(struct mv88e6xxx_chip *chip, int port);
  279. int (*set_egress_port)(struct mv88e6xxx_chip *chip, int port);
  280. const struct mv88e6xxx_irq_ops *watchdog_ops;
  281. int (*mgmt_rsvd2cpu)(struct mv88e6xxx_chip *chip);
  282. /* Power on/off a SERDES interface */
  283. int (*serdes_power)(struct mv88e6xxx_chip *chip, int port, bool on);
  284. /* VLAN Translation Unit operations */
  285. int (*vtu_getnext)(struct mv88e6xxx_chip *chip,
  286. struct mv88e6xxx_vtu_entry *entry);
  287. int (*vtu_loadpurge)(struct mv88e6xxx_chip *chip,
  288. struct mv88e6xxx_vtu_entry *entry);
  289. };
  290. struct mv88e6xxx_irq_ops {
  291. /* Action to be performed when the interrupt happens */
  292. int (*irq_action)(struct mv88e6xxx_chip *chip, int irq);
  293. /* Setup the hardware to generate the interrupt */
  294. int (*irq_setup)(struct mv88e6xxx_chip *chip);
  295. /* Reset the hardware to stop generating the interrupt */
  296. void (*irq_free)(struct mv88e6xxx_chip *chip);
  297. };
  298. #define STATS_TYPE_PORT BIT(0)
  299. #define STATS_TYPE_BANK0 BIT(1)
  300. #define STATS_TYPE_BANK1 BIT(2)
  301. struct mv88e6xxx_hw_stat {
  302. char string[ETH_GSTRING_LEN];
  303. int sizeof_stat;
  304. int reg;
  305. int type;
  306. };
  307. static inline bool mv88e6xxx_has_pvt(struct mv88e6xxx_chip *chip)
  308. {
  309. return chip->info->pvt;
  310. }
  311. static inline unsigned int mv88e6xxx_num_databases(struct mv88e6xxx_chip *chip)
  312. {
  313. return chip->info->num_databases;
  314. }
  315. static inline unsigned int mv88e6xxx_num_ports(struct mv88e6xxx_chip *chip)
  316. {
  317. return chip->info->num_ports;
  318. }
  319. static inline u16 mv88e6xxx_port_mask(struct mv88e6xxx_chip *chip)
  320. {
  321. return GENMASK(mv88e6xxx_num_ports(chip) - 1, 0);
  322. }
  323. int mv88e6xxx_read(struct mv88e6xxx_chip *chip, int addr, int reg, u16 *val);
  324. int mv88e6xxx_write(struct mv88e6xxx_chip *chip, int addr, int reg, u16 val);
  325. int mv88e6xxx_update(struct mv88e6xxx_chip *chip, int addr, int reg,
  326. u16 update);
  327. int mv88e6xxx_wait(struct mv88e6xxx_chip *chip, int addr, int reg, u16 mask);
  328. struct mii_bus *mv88e6xxx_default_mdio_bus(struct mv88e6xxx_chip *chip);
  329. #endif /* _MV88E6XXX_CHIP_H */