mv88e6xxx.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. /*
  2. * net/dsa/mv88e6xxx.h - Marvell 88e6xxx switch chip support
  3. * Copyright (c) 2008 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. #ifndef __MV88E6XXX_H
  11. #define __MV88E6XXX_H
  12. #define SMI_CMD 0x00
  13. #define SMI_CMD_BUSY BIT(15)
  14. #define SMI_CMD_CLAUSE_22 BIT(12)
  15. #define SMI_CMD_OP_22_WRITE ((1 << 10) | SMI_CMD_BUSY | SMI_CMD_CLAUSE_22)
  16. #define SMI_CMD_OP_22_READ ((2 << 10) | SMI_CMD_BUSY | SMI_CMD_CLAUSE_22)
  17. #define SMI_CMD_OP_45_WRITE_ADDR ((0 << 10) | SMI_CMD_BUSY)
  18. #define SMI_CMD_OP_45_WRITE_DATA ((1 << 10) | SMI_CMD_BUSY)
  19. #define SMI_CMD_OP_45_READ_DATA ((2 << 10) | SMI_CMD_BUSY)
  20. #define SMI_CMD_OP_45_READ_DATA_INC ((3 << 10) | SMI_CMD_BUSY)
  21. #define SMI_DATA 0x01
  22. #define REG_PORT(p) (0x10 + (p))
  23. #define PORT_STATUS 0x00
  24. #define PORT_STATUS_PAUSE_EN BIT(15)
  25. #define PORT_STATUS_MY_PAUSE BIT(14)
  26. #define PORT_STATUS_HD_FLOW BIT(13)
  27. #define PORT_STATUS_PHY_DETECT BIT(12)
  28. #define PORT_STATUS_LINK BIT(11)
  29. #define PORT_STATUS_DUPLEX BIT(10)
  30. #define PORT_STATUS_SPEED_MASK 0x0300
  31. #define PORT_STATUS_SPEED_10 0x0000
  32. #define PORT_STATUS_SPEED_100 0x0100
  33. #define PORT_STATUS_SPEED_1000 0x0200
  34. #define PORT_STATUS_EEE BIT(6) /* 6352 */
  35. #define PORT_STATUS_AM_DIS BIT(6) /* 6165 */
  36. #define PORT_STATUS_MGMII BIT(6) /* 6185 */
  37. #define PORT_STATUS_TX_PAUSED BIT(5)
  38. #define PORT_STATUS_FLOW_CTRL BIT(4)
  39. #define PORT_PCS_CTRL 0x01
  40. #define PORT_SWITCH_ID 0x03
  41. #define PORT_SWITCH_ID_6085 0x04a0
  42. #define PORT_SWITCH_ID_6095 0x0950
  43. #define PORT_SWITCH_ID_6123 0x1210
  44. #define PORT_SWITCH_ID_6123_A1 0x1212
  45. #define PORT_SWITCH_ID_6123_A2 0x1213
  46. #define PORT_SWITCH_ID_6131 0x1060
  47. #define PORT_SWITCH_ID_6131_B2 0x1066
  48. #define PORT_SWITCH_ID_6152 0x1a40
  49. #define PORT_SWITCH_ID_6155 0x1a50
  50. #define PORT_SWITCH_ID_6161 0x1610
  51. #define PORT_SWITCH_ID_6161_A1 0x1612
  52. #define PORT_SWITCH_ID_6161_A2 0x1613
  53. #define PORT_SWITCH_ID_6165 0x1650
  54. #define PORT_SWITCH_ID_6165_A1 0x1652
  55. #define PORT_SWITCH_ID_6165_A2 0x1653
  56. #define PORT_SWITCH_ID_6171 0x1710
  57. #define PORT_SWITCH_ID_6172 0x1720
  58. #define PORT_SWITCH_ID_6176 0x1760
  59. #define PORT_SWITCH_ID_6182 0x1a60
  60. #define PORT_SWITCH_ID_6185 0x1a70
  61. #define PORT_SWITCH_ID_6352 0x3520
  62. #define PORT_SWITCH_ID_6352_A0 0x3521
  63. #define PORT_SWITCH_ID_6352_A1 0x3522
  64. #define PORT_CONTROL 0x04
  65. #define PORT_CONTROL_STATE_MASK 0x03
  66. #define PORT_CONTROL_STATE_DISABLED 0x00
  67. #define PORT_CONTROL_STATE_BLOCKING 0x01
  68. #define PORT_CONTROL_STATE_LEARNING 0x02
  69. #define PORT_CONTROL_STATE_FORWARDING 0x03
  70. #define PORT_CONTROL_1 0x05
  71. #define PORT_BASE_VLAN 0x06
  72. #define PORT_DEFAULT_VLAN 0x07
  73. #define PORT_CONTROL_2 0x08
  74. #define PORT_RATE_CONTROL 0x09
  75. #define PORT_RATE_CONTROL_2 0x0a
  76. #define PORT_ASSOC_VECTOR 0x0b
  77. #define PORT_IN_DISCARD_LO 0x10
  78. #define PORT_IN_DISCARD_HI 0x11
  79. #define PORT_IN_FILTERED 0x12
  80. #define PORT_OUT_FILTERED 0x13
  81. #define PORT_TAG_REGMAP_0123 0x19
  82. #define PORT_TAG_REGMAP_4567 0x1a
  83. #define REG_GLOBAL 0x1b
  84. #define GLOBAL_STATUS 0x00
  85. #define GLOBAL_STATUS_PPU_STATE BIT(15) /* 6351 and 6171 */
  86. /* Two bits for 6165, 6185 etc */
  87. #define GLOBAL_STATUS_PPU_MASK (0x3 << 14)
  88. #define GLOBAL_STATUS_PPU_DISABLED_RST (0x0 << 14)
  89. #define GLOBAL_STATUS_PPU_INITIALIZING (0x1 << 14)
  90. #define GLOBAL_STATUS_PPU_DISABLED (0x2 << 14)
  91. #define GLOBAL_STATUS_PPU_POLLING (0x3 << 14)
  92. #define GLOBAL_MAC_01 0x01
  93. #define GLOBAL_MAC_23 0x02
  94. #define GLOBAL_MAC_45 0x03
  95. #define GLOBAL_CONTROL 0x04
  96. #define GLOBAL_CONTROL_SW_RESET BIT(15)
  97. #define GLOBAL_CONTROL_PPU_ENABLE BIT(14)
  98. #define GLOBAL_CONTROL_DISCARD_EXCESS BIT(13) /* 6352 */
  99. #define GLOBAL_CONTROL_SCHED_PRIO BIT(11) /* 6152 */
  100. #define GLOBAL_CONTROL_MAX_FRAME_1632 BIT(10) /* 6152 */
  101. #define GLOBAL_CONTROL_RELOAD_EEPROM BIT(9) /* 6152 */
  102. #define GLOBAL_CONTROL_DEVICE_EN BIT(7)
  103. #define GLOBAL_CONTROL_STATS_DONE_EN BIT(6)
  104. #define GLOBAL_CONTROL_VTU_PROBLEM_EN BIT(5)
  105. #define GLOBAL_CONTROL_VTU_DONE_EN BIT(4)
  106. #define GLOBAL_CONTROL_ATU_PROBLEM_EN BIT(3)
  107. #define GLOBAL_CONTROL_ATU_DONE_EN BIT(2)
  108. #define GLOBAL_CONTROL_TCAM_EN BIT(1)
  109. #define GLOBAL_CONTROL_EEPROM_DONE_EN BIT(0)
  110. #define GLOBAL_VTU_OP 0x05
  111. #define GLOBAL_VTU_VID 0x06
  112. #define GLOBAL_VTU_DATA_0_3 0x07
  113. #define GLOBAL_VTU_DATA_4_7 0x08
  114. #define GLOBAL_VTU_DATA_8_11 0x09
  115. #define GLOBAL_ATU_CONTROL 0x0a
  116. #define GLOBAL_ATU_OP 0x0b
  117. #define GLOBAL_ATU_OP_BUSY BIT(15)
  118. #define GLOBAL_ATU_OP_NOP (0 << 12)
  119. #define GLOBAL_ATU_OP_FLUSH_ALL ((1 << 12) | GLOBAL_ATU_OP_BUSY)
  120. #define GLOBAL_ATU_OP_FLUSH_NON_STATIC ((2 << 12) | GLOBAL_ATU_OP_BUSY)
  121. #define GLOBAL_ATU_OP_LOAD_DB ((3 << 12) | GLOBAL_ATU_OP_BUSY)
  122. #define GLOBAL_ATU_OP_GET_NEXT_DB ((4 << 12) | GLOBAL_ATU_OP_BUSY)
  123. #define GLOBAL_ATU_OP_FLUSH_DB ((5 << 12) | GLOBAL_ATU_OP_BUSY)
  124. #define GLOBAL_ATU_OP_FLUSH_NON_STATIC_DB ((6 << 12) | GLOBAL_ATU_OP_BUSY)
  125. #define GLOBAL_ATU_OP_GET_CLR_VIOLATION ((7 << 12) | GLOBAL_ATU_OP_BUSY)
  126. #define GLOBAL_ATU_DATA 0x0c
  127. #define GLOBAL_ATU_DATA_STATE_MASK 0x0f
  128. #define GLOBAL_ATU_DATA_STATE_UNUSED 0x00
  129. #define GLOBAL_ATU_DATA_STATE_UC_MGMT 0x0d
  130. #define GLOBAL_ATU_DATA_STATE_UC_STATIC 0x0e
  131. #define GLOBAL_ATU_DATA_STATE_UC_PRIO_OVER 0x0f
  132. #define GLOBAL_ATU_DATA_STATE_MC_NONE_RATE 0x05
  133. #define GLOBAL_ATU_DATA_STATE_MC_STATIC 0x07
  134. #define GLOBAL_ATU_DATA_STATE_MC_MGMT 0x0e
  135. #define GLOBAL_ATU_DATA_STATE_MC_PRIO_OVER 0x0f
  136. #define GLOBAL_ATU_MAC_01 0x0d
  137. #define GLOBAL_ATU_MAC_23 0x0e
  138. #define GLOBAL_ATU_MAC_45 0x0f
  139. #define GLOBAL_IP_PRI_0 0x10
  140. #define GLOBAL_IP_PRI_1 0x11
  141. #define GLOBAL_IP_PRI_2 0x12
  142. #define GLOBAL_IP_PRI_3 0x13
  143. #define GLOBAL_IP_PRI_4 0x14
  144. #define GLOBAL_IP_PRI_5 0x15
  145. #define GLOBAL_IP_PRI_6 0x16
  146. #define GLOBAL_IP_PRI_7 0x17
  147. #define GLOBAL_IEEE_PRI 0x18
  148. #define GLOBAL_CORE_TAG_TYPE 0x19
  149. #define GLOBAL_MONITOR_CONTROL 0x1a
  150. #define GLOBAL_CONTROL_2 0x1c
  151. #define GLOBAL_STATS_OP 0x1d
  152. #define GLOBAL_STATS_OP_BUSY BIT(15)
  153. #define GLOBAL_STATS_OP_NOP (0 << 12)
  154. #define GLOBAL_STATS_OP_FLUSH_ALL ((1 << 12) | GLOBAL_STATS_OP_BUSY)
  155. #define GLOBAL_STATS_OP_FLUSH_PORT ((2 << 12) | GLOBAL_STATS_OP_BUSY)
  156. #define GLOBAL_STATS_OP_READ_CAPTURED ((4 << 12) | GLOBAL_STATS_OP_BUSY)
  157. #define GLOBAL_STATS_OP_CAPTURE_PORT ((5 << 12) | GLOBAL_STATS_OP_BUSY)
  158. #define GLOBAL_STATS_OP_HIST_RX ((1 << 10) | GLOBAL_STATS_OP_BUSY)
  159. #define GLOBAL_STATS_OP_HIST_TX ((2 << 10) | GLOBAL_STATS_OP_BUSY)
  160. #define GLOBAL_STATS_OP_HIST_RX_TX ((3 << 10) | GLOBAL_STATS_OP_BUSY)
  161. #define GLOBAL_STATS_COUNTER_32 0x1e
  162. #define GLOBAL_STATS_COUNTER_01 0x1f
  163. #define REG_GLOBAL2 0x1c
  164. #define GLOBAL2_INT_SOURCE 0x00
  165. #define GLOBAL2_INT_MASK 0x01
  166. #define GLOBAL2_MGMT_EN_2X 0x02
  167. #define GLOBAL2_MGMT_EN_0X 0x03
  168. #define GLOBAL2_FLOW_CONTROL 0x04
  169. #define GLOBAL2_SWITCH_MGMT 0x05
  170. #define GLOBAL2_DEVICE_MAPPING 0x06
  171. #define GLOBAL2_TRUNK_MASK 0x07
  172. #define GLOBAL2_TRUNK_MAPPING 0x08
  173. #define GLOBAL2_INGRESS_OP 0x09
  174. #define GLOBAL2_INGRESS_DATA 0x0a
  175. #define GLOBAL2_PVT_ADDR 0x0b
  176. #define GLOBAL2_PVT_DATA 0x0c
  177. #define GLOBAL2_SWITCH_MAC 0x0d
  178. #define GLOBAL2_SWITCH_MAC_BUSY BIT(15)
  179. #define GLOBAL2_ATU_STATS 0x0e
  180. #define GLOBAL2_PRIO_OVERRIDE 0x0f
  181. #define GLOBAL2_EEPROM_OP 0x14
  182. #define GLOBAL2_EEPROM_OP_BUSY BIT(15)
  183. #define GLOBAL2_EEPROM_OP_LOAD BIT(11)
  184. #define GLOBAL2_EEPROM_DATA 0x15
  185. #define GLOBAL2_PTP_AVB_OP 0x16
  186. #define GLOBAL2_PTP_AVB_DATA 0x17
  187. #define GLOBAL2_SMI_OP 0x18
  188. #define GLOBAL2_SMI_OP_BUSY BIT(15)
  189. #define GLOBAL2_SMI_OP_CLAUSE_22 BIT(12)
  190. #define GLOBAL2_SMI_OP_22_WRITE ((1 << 10) | GLOBAL2_SMI_OP_BUSY | \
  191. GLOBAL2_SMI_OP_CLAUSE_22)
  192. #define GLOBAL2_SMI_OP_22_READ ((2 << 10) | GLOBAL2_SMI_OP_BUSY | \
  193. GLOBAL2_SMI_OP_CLAUSE_22)
  194. #define GLOBAL2_SMI_OP_45_WRITE_ADDR ((0 << 10) | GLOBAL2_SMI_OP_BUSY)
  195. #define GLOBAL2_SMI_OP_45_WRITE_DATA ((1 << 10) | GLOBAL2_SMI_OP_BUSY)
  196. #define GLOBAL2_SMI_OP_45_READ_DATA ((2 << 10) | GLOBAL2_SMI_OP_BUSY)
  197. #define GLOBAL2_SMI_DATA 0x19
  198. #define GLOBAL2_SCRATCH_MISC 0x1a
  199. #define GLOBAL2_WDOG_CONTROL 0x1b
  200. #define GLOBAL2_QOS_WEIGHT 0x1c
  201. #define GLOBAL2_MISC 0x1d
  202. struct mv88e6xxx_priv_state {
  203. /* When using multi-chip addressing, this mutex protects
  204. * access to the indirect access registers. (In single-chip
  205. * mode, this mutex is effectively useless.)
  206. */
  207. struct mutex smi_mutex;
  208. #ifdef CONFIG_NET_DSA_MV88E6XXX_NEED_PPU
  209. /* Handles automatic disabling and re-enabling of the PHY
  210. * polling unit.
  211. */
  212. struct mutex ppu_mutex;
  213. int ppu_disabled;
  214. struct work_struct ppu_work;
  215. struct timer_list ppu_timer;
  216. #endif
  217. /* This mutex serialises access to the statistics unit.
  218. * Hold this mutex over snapshot + dump sequences.
  219. */
  220. struct mutex stats_mutex;
  221. /* This mutex serializes phy access for chips with
  222. * indirect phy addressing. It is unused for chips
  223. * with direct phy access.
  224. */
  225. struct mutex phy_mutex;
  226. /* This mutex serializes eeprom access for chips with
  227. * eeprom support.
  228. */
  229. struct mutex eeprom_mutex;
  230. int id; /* switch product id */
  231. int num_ports; /* number of switch ports */
  232. /* hw bridging */
  233. u32 fid_mask;
  234. u8 fid[DSA_MAX_PORTS];
  235. u16 bridge_mask[DSA_MAX_PORTS];
  236. unsigned long port_state_update_mask;
  237. u8 port_state[DSA_MAX_PORTS];
  238. struct work_struct bridge_work;
  239. };
  240. struct mv88e6xxx_hw_stat {
  241. char string[ETH_GSTRING_LEN];
  242. int sizeof_stat;
  243. int reg;
  244. };
  245. int mv88e6xxx_switch_reset(struct dsa_switch *ds, bool ppu_active);
  246. int mv88e6xxx_setup_port_common(struct dsa_switch *ds, int port);
  247. int mv88e6xxx_setup_common(struct dsa_switch *ds);
  248. int __mv88e6xxx_reg_read(struct mii_bus *bus, int sw_addr, int addr, int reg);
  249. int mv88e6xxx_reg_read(struct dsa_switch *ds, int addr, int reg);
  250. int __mv88e6xxx_reg_write(struct mii_bus *bus, int sw_addr, int addr,
  251. int reg, u16 val);
  252. int mv88e6xxx_reg_write(struct dsa_switch *ds, int addr, int reg, u16 val);
  253. int mv88e6xxx_config_prio(struct dsa_switch *ds);
  254. int mv88e6xxx_set_addr_direct(struct dsa_switch *ds, u8 *addr);
  255. int mv88e6xxx_set_addr_indirect(struct dsa_switch *ds, u8 *addr);
  256. int mv88e6xxx_phy_read(struct dsa_switch *ds, int port, int regnum);
  257. int mv88e6xxx_phy_write(struct dsa_switch *ds, int port, int regnum, u16 val);
  258. int mv88e6xxx_phy_read_indirect(struct dsa_switch *ds, int port, int regnum);
  259. int mv88e6xxx_phy_write_indirect(struct dsa_switch *ds, int port, int regnum,
  260. u16 val);
  261. void mv88e6xxx_ppu_state_init(struct dsa_switch *ds);
  262. int mv88e6xxx_phy_read_ppu(struct dsa_switch *ds, int addr, int regnum);
  263. int mv88e6xxx_phy_write_ppu(struct dsa_switch *ds, int addr,
  264. int regnum, u16 val);
  265. void mv88e6xxx_poll_link(struct dsa_switch *ds);
  266. void mv88e6xxx_get_strings(struct dsa_switch *ds, int port, uint8_t *data);
  267. void mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds, int port,
  268. uint64_t *data);
  269. int mv88e6xxx_get_sset_count(struct dsa_switch *ds);
  270. int mv88e6xxx_get_sset_count_basic(struct dsa_switch *ds);
  271. int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port);
  272. void mv88e6xxx_get_regs(struct dsa_switch *ds, int port,
  273. struct ethtool_regs *regs, void *_p);
  274. int mv88e6xxx_get_temp(struct dsa_switch *ds, int *temp);
  275. int mv88e6xxx_phy_wait(struct dsa_switch *ds);
  276. int mv88e6xxx_eeprom_load_wait(struct dsa_switch *ds);
  277. int mv88e6xxx_eeprom_busy_wait(struct dsa_switch *ds);
  278. int mv88e6xxx_phy_read_indirect(struct dsa_switch *ds, int addr, int regnum);
  279. int mv88e6xxx_phy_write_indirect(struct dsa_switch *ds, int addr, int regnum,
  280. u16 val);
  281. int mv88e6xxx_get_eee(struct dsa_switch *ds, int port, struct ethtool_eee *e);
  282. int mv88e6xxx_set_eee(struct dsa_switch *ds, int port,
  283. struct phy_device *phydev, struct ethtool_eee *e);
  284. int mv88e6xxx_join_bridge(struct dsa_switch *ds, int port, u32 br_port_mask);
  285. int mv88e6xxx_leave_bridge(struct dsa_switch *ds, int port, u32 br_port_mask);
  286. int mv88e6xxx_port_stp_update(struct dsa_switch *ds, int port, u8 state);
  287. int mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
  288. const unsigned char *addr, u16 vid);
  289. int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
  290. const unsigned char *addr, u16 vid);
  291. int mv88e6xxx_port_fdb_getnext(struct dsa_switch *ds, int port,
  292. unsigned char *addr, bool *is_static);
  293. int mv88e6xxx_phy_page_read(struct dsa_switch *ds, int port, int page, int reg);
  294. int mv88e6xxx_phy_page_write(struct dsa_switch *ds, int port, int page,
  295. int reg, int val);
  296. extern struct dsa_switch_driver mv88e6131_switch_driver;
  297. extern struct dsa_switch_driver mv88e6123_61_65_switch_driver;
  298. extern struct dsa_switch_driver mv88e6352_switch_driver;
  299. extern struct dsa_switch_driver mv88e6171_switch_driver;
  300. #define REG_READ(addr, reg) \
  301. ({ \
  302. int __ret; \
  303. \
  304. __ret = mv88e6xxx_reg_read(ds, addr, reg); \
  305. if (__ret < 0) \
  306. return __ret; \
  307. __ret; \
  308. })
  309. #define REG_WRITE(addr, reg, val) \
  310. ({ \
  311. int __ret; \
  312. \
  313. __ret = mv88e6xxx_reg_write(ds, addr, reg, val); \
  314. if (__ret < 0) \
  315. return __ret; \
  316. })
  317. #endif