chip.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555
  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/kthread.h>
  17. #include <linux/phy.h>
  18. #include <linux/ptp_clock_kernel.h>
  19. #include <linux/timecounter.h>
  20. #include <net/dsa.h>
  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. #define MV88E6XXX_MAX_GPIO 16
  36. enum mv88e6xxx_egress_mode {
  37. MV88E6XXX_EGRESS_MODE_UNMODIFIED,
  38. MV88E6XXX_EGRESS_MODE_UNTAGGED,
  39. MV88E6XXX_EGRESS_MODE_TAGGED,
  40. MV88E6XXX_EGRESS_MODE_ETHERTYPE,
  41. };
  42. enum mv88e6xxx_frame_mode {
  43. MV88E6XXX_FRAME_MODE_NORMAL,
  44. MV88E6XXX_FRAME_MODE_DSA,
  45. MV88E6XXX_FRAME_MODE_PROVIDER,
  46. MV88E6XXX_FRAME_MODE_ETHERTYPE,
  47. };
  48. /* List of supported models */
  49. enum mv88e6xxx_model {
  50. MV88E6085,
  51. MV88E6095,
  52. MV88E6097,
  53. MV88E6123,
  54. MV88E6131,
  55. MV88E6141,
  56. MV88E6161,
  57. MV88E6165,
  58. MV88E6171,
  59. MV88E6172,
  60. MV88E6175,
  61. MV88E6176,
  62. MV88E6185,
  63. MV88E6190,
  64. MV88E6190X,
  65. MV88E6191,
  66. MV88E6240,
  67. MV88E6290,
  68. MV88E6320,
  69. MV88E6321,
  70. MV88E6341,
  71. MV88E6350,
  72. MV88E6351,
  73. MV88E6352,
  74. MV88E6390,
  75. MV88E6390X,
  76. };
  77. enum mv88e6xxx_family {
  78. MV88E6XXX_FAMILY_NONE,
  79. MV88E6XXX_FAMILY_6065, /* 6031 6035 6061 6065 */
  80. MV88E6XXX_FAMILY_6095, /* 6092 6095 */
  81. MV88E6XXX_FAMILY_6097, /* 6046 6085 6096 6097 */
  82. MV88E6XXX_FAMILY_6165, /* 6123 6161 6165 */
  83. MV88E6XXX_FAMILY_6185, /* 6108 6121 6122 6131 6152 6155 6182 6185 */
  84. MV88E6XXX_FAMILY_6320, /* 6320 6321 */
  85. MV88E6XXX_FAMILY_6341, /* 6141 6341 */
  86. MV88E6XXX_FAMILY_6351, /* 6171 6175 6350 6351 */
  87. MV88E6XXX_FAMILY_6352, /* 6172 6176 6240 6352 */
  88. MV88E6XXX_FAMILY_6390, /* 6190 6190X 6191 6290 6390 6390X */
  89. };
  90. struct mv88e6xxx_ops;
  91. struct mv88e6xxx_info {
  92. enum mv88e6xxx_family family;
  93. u16 prod_num;
  94. const char *name;
  95. unsigned int num_databases;
  96. unsigned int num_ports;
  97. unsigned int num_internal_phys;
  98. unsigned int num_gpio;
  99. unsigned int max_vid;
  100. unsigned int port_base_addr;
  101. unsigned int phy_base_addr;
  102. unsigned int global1_addr;
  103. unsigned int global2_addr;
  104. unsigned int age_time_coeff;
  105. unsigned int g1_irqs;
  106. unsigned int g2_irqs;
  107. bool pvt;
  108. /* Multi-chip Addressing Mode.
  109. * Some chips respond to only 2 registers of its own SMI device address
  110. * when it is non-zero, and use indirect access to internal registers.
  111. */
  112. bool multi_chip;
  113. enum dsa_tag_protocol tag_protocol;
  114. /* Mask for FromPort and ToPort value of PortVec used in ATU Move
  115. * operation. 0 means that the ATU Move operation is not supported.
  116. */
  117. u8 atu_move_port_mask;
  118. const struct mv88e6xxx_ops *ops;
  119. /* Supports PTP */
  120. bool ptp_support;
  121. };
  122. struct mv88e6xxx_atu_entry {
  123. u8 state;
  124. bool trunk;
  125. u16 portvec;
  126. u8 mac[ETH_ALEN];
  127. };
  128. struct mv88e6xxx_vtu_entry {
  129. u16 vid;
  130. u16 fid;
  131. u8 sid;
  132. bool valid;
  133. u8 member[DSA_MAX_PORTS];
  134. u8 state[DSA_MAX_PORTS];
  135. };
  136. struct mv88e6xxx_bus_ops;
  137. struct mv88e6xxx_irq_ops;
  138. struct mv88e6xxx_gpio_ops;
  139. struct mv88e6xxx_avb_ops;
  140. struct mv88e6xxx_ptp_ops;
  141. struct mv88e6xxx_irq {
  142. u16 masked;
  143. struct irq_chip chip;
  144. struct irq_domain *domain;
  145. unsigned int nirqs;
  146. };
  147. /* state flags for mv88e6xxx_port_hwtstamp::state */
  148. enum {
  149. MV88E6XXX_HWTSTAMP_ENABLED,
  150. MV88E6XXX_HWTSTAMP_TX_IN_PROGRESS,
  151. };
  152. struct mv88e6xxx_port_hwtstamp {
  153. /* Port index */
  154. int port_id;
  155. /* Timestamping state */
  156. unsigned long state;
  157. /* Resources for receive timestamping */
  158. struct sk_buff_head rx_queue;
  159. struct sk_buff_head rx_queue2;
  160. /* Resources for transmit timestamping */
  161. unsigned long tx_tstamp_start;
  162. struct sk_buff *tx_skb;
  163. u16 tx_seq_id;
  164. /* Current timestamp configuration */
  165. struct hwtstamp_config tstamp_config;
  166. };
  167. struct mv88e6xxx_port {
  168. u64 serdes_stats[2];
  169. u64 atu_member_violation;
  170. u64 atu_miss_violation;
  171. u64 atu_full_violation;
  172. u64 vtu_member_violation;
  173. u64 vtu_miss_violation;
  174. };
  175. struct mv88e6xxx_chip {
  176. const struct mv88e6xxx_info *info;
  177. /* The dsa_switch this private structure is related to */
  178. struct dsa_switch *ds;
  179. /* The device this structure is associated to */
  180. struct device *dev;
  181. /* This mutex protects the access to the switch registers */
  182. struct mutex reg_lock;
  183. /* The MII bus and the address on the bus that is used to
  184. * communication with the switch
  185. */
  186. const struct mv88e6xxx_bus_ops *smi_ops;
  187. struct mii_bus *bus;
  188. int sw_addr;
  189. /* Handles automatic disabling and re-enabling of the PHY
  190. * polling unit.
  191. */
  192. const struct mv88e6xxx_bus_ops *phy_ops;
  193. struct mutex ppu_mutex;
  194. int ppu_disabled;
  195. struct work_struct ppu_work;
  196. struct timer_list ppu_timer;
  197. /* This mutex serialises access to the statistics unit.
  198. * Hold this mutex over snapshot + dump sequences.
  199. */
  200. struct mutex stats_mutex;
  201. /* A switch may have a GPIO line tied to its reset pin. Parse
  202. * this from the device tree, and use it before performing
  203. * switch soft reset.
  204. */
  205. struct gpio_desc *reset;
  206. /* set to size of eeprom if supported by the switch */
  207. u32 eeprom_len;
  208. /* List of mdio busses */
  209. struct list_head mdios;
  210. /* There can be two interrupt controllers, which are chained
  211. * off a GPIO as interrupt source
  212. */
  213. struct mv88e6xxx_irq g1_irq;
  214. struct mv88e6xxx_irq g2_irq;
  215. int irq;
  216. int device_irq;
  217. int watchdog_irq;
  218. int atu_prob_irq;
  219. int vtu_prob_irq;
  220. struct kthread_worker *kworker;
  221. struct kthread_delayed_work irq_poll_work;
  222. /* GPIO resources */
  223. u8 gpio_data[2];
  224. /* This cyclecounter abstracts the switch PTP time.
  225. * reg_lock must be held for any operation that read()s.
  226. */
  227. struct cyclecounter tstamp_cc;
  228. struct timecounter tstamp_tc;
  229. struct delayed_work overflow_work;
  230. struct ptp_clock *ptp_clock;
  231. struct ptp_clock_info ptp_clock_info;
  232. struct delayed_work tai_event_work;
  233. struct ptp_pin_desc pin_config[MV88E6XXX_MAX_GPIO];
  234. u16 trig_config;
  235. u16 evcap_config;
  236. u16 enable_count;
  237. /* Per-port timestamping resources. */
  238. struct mv88e6xxx_port_hwtstamp port_hwtstamp[DSA_MAX_PORTS];
  239. /* Array of port structures. */
  240. struct mv88e6xxx_port ports[DSA_MAX_PORTS];
  241. };
  242. struct mv88e6xxx_bus_ops {
  243. int (*read)(struct mv88e6xxx_chip *chip, int addr, int reg, u16 *val);
  244. int (*write)(struct mv88e6xxx_chip *chip, int addr, int reg, u16 val);
  245. };
  246. struct mv88e6xxx_mdio_bus {
  247. struct mii_bus *bus;
  248. struct mv88e6xxx_chip *chip;
  249. struct list_head list;
  250. bool external;
  251. };
  252. struct mv88e6xxx_ops {
  253. int (*ieee_pri_map)(struct mv88e6xxx_chip *chip);
  254. int (*ip_pri_map)(struct mv88e6xxx_chip *chip);
  255. /* Ingress Rate Limit unit (IRL) operations */
  256. int (*irl_init_all)(struct mv88e6xxx_chip *chip, int port);
  257. int (*get_eeprom)(struct mv88e6xxx_chip *chip,
  258. struct ethtool_eeprom *eeprom, u8 *data);
  259. int (*set_eeprom)(struct mv88e6xxx_chip *chip,
  260. struct ethtool_eeprom *eeprom, u8 *data);
  261. int (*set_switch_mac)(struct mv88e6xxx_chip *chip, u8 *addr);
  262. int (*phy_read)(struct mv88e6xxx_chip *chip,
  263. struct mii_bus *bus,
  264. int addr, int reg, u16 *val);
  265. int (*phy_write)(struct mv88e6xxx_chip *chip,
  266. struct mii_bus *bus,
  267. int addr, int reg, u16 val);
  268. /* Priority Override Table operations */
  269. int (*pot_clear)(struct mv88e6xxx_chip *chip);
  270. /* PHY Polling Unit (PPU) operations */
  271. int (*ppu_enable)(struct mv88e6xxx_chip *chip);
  272. int (*ppu_disable)(struct mv88e6xxx_chip *chip);
  273. /* Switch Software Reset */
  274. int (*reset)(struct mv88e6xxx_chip *chip);
  275. /* RGMII Receive/Transmit Timing Control
  276. * Add delay on PHY_INTERFACE_MODE_RGMII_*ID, no delay otherwise.
  277. */
  278. int (*port_set_rgmii_delay)(struct mv88e6xxx_chip *chip, int port,
  279. phy_interface_t mode);
  280. #define LINK_FORCED_DOWN 0
  281. #define LINK_FORCED_UP 1
  282. #define LINK_UNFORCED -2
  283. /* Port's MAC link state
  284. * Use LINK_FORCED_UP or LINK_FORCED_DOWN to force link up or down,
  285. * or LINK_UNFORCED for normal link detection.
  286. */
  287. int (*port_set_link)(struct mv88e6xxx_chip *chip, int port, int link);
  288. #define DUPLEX_UNFORCED -2
  289. /* Port's MAC duplex mode
  290. *
  291. * Use DUPLEX_HALF or DUPLEX_FULL to force half or full duplex,
  292. * or DUPLEX_UNFORCED for normal duplex detection.
  293. */
  294. int (*port_set_duplex)(struct mv88e6xxx_chip *chip, int port, int dup);
  295. #define SPEED_MAX INT_MAX
  296. #define SPEED_UNFORCED -2
  297. /* Port's MAC speed (in Mbps)
  298. *
  299. * Depending on the chip, 10, 100, 200, 1000, 2500, 10000 are valid.
  300. * Use SPEED_UNFORCED for normal detection, SPEED_MAX for max value.
  301. */
  302. int (*port_set_speed)(struct mv88e6xxx_chip *chip, int port, int speed);
  303. int (*port_tag_remap)(struct mv88e6xxx_chip *chip, int port);
  304. int (*port_set_frame_mode)(struct mv88e6xxx_chip *chip, int port,
  305. enum mv88e6xxx_frame_mode mode);
  306. int (*port_set_egress_floods)(struct mv88e6xxx_chip *chip, int port,
  307. bool unicast, bool multicast);
  308. int (*port_set_ether_type)(struct mv88e6xxx_chip *chip, int port,
  309. u16 etype);
  310. int (*port_set_jumbo_size)(struct mv88e6xxx_chip *chip, int port,
  311. size_t size);
  312. int (*port_egress_rate_limiting)(struct mv88e6xxx_chip *chip, int port);
  313. int (*port_pause_limit)(struct mv88e6xxx_chip *chip, int port, u8 in,
  314. u8 out);
  315. int (*port_disable_learn_limit)(struct mv88e6xxx_chip *chip, int port);
  316. int (*port_disable_pri_override)(struct mv88e6xxx_chip *chip, int port);
  317. /* CMODE control what PHY mode the MAC will use, eg. SGMII, RGMII, etc.
  318. * Some chips allow this to be configured on specific ports.
  319. */
  320. int (*port_set_cmode)(struct mv88e6xxx_chip *chip, int port,
  321. phy_interface_t mode);
  322. /* Some devices have a per port register indicating what is
  323. * the upstream port this port should forward to.
  324. */
  325. int (*port_set_upstream_port)(struct mv88e6xxx_chip *chip, int port,
  326. int upstream_port);
  327. /* Snapshot the statistics for a port. The statistics can then
  328. * be read back a leisure but still with a consistent view.
  329. */
  330. int (*stats_snapshot)(struct mv88e6xxx_chip *chip, int port);
  331. /* Set the histogram mode for statistics, when the control registers
  332. * are separated out of the STATS_OP register.
  333. */
  334. int (*stats_set_histogram)(struct mv88e6xxx_chip *chip);
  335. /* Return the number of strings describing statistics */
  336. int (*stats_get_sset_count)(struct mv88e6xxx_chip *chip);
  337. int (*stats_get_strings)(struct mv88e6xxx_chip *chip, uint8_t *data);
  338. int (*stats_get_stats)(struct mv88e6xxx_chip *chip, int port,
  339. uint64_t *data);
  340. int (*set_cpu_port)(struct mv88e6xxx_chip *chip, int port);
  341. int (*set_egress_port)(struct mv88e6xxx_chip *chip, int port);
  342. #define MV88E6XXX_CASCADE_PORT_NONE 0xe
  343. #define MV88E6XXX_CASCADE_PORT_MULTIPLE 0xf
  344. int (*set_cascade_port)(struct mv88e6xxx_chip *chip, int port);
  345. const struct mv88e6xxx_irq_ops *watchdog_ops;
  346. int (*mgmt_rsvd2cpu)(struct mv88e6xxx_chip *chip);
  347. /* Power on/off a SERDES interface */
  348. int (*serdes_power)(struct mv88e6xxx_chip *chip, int port, bool on);
  349. /* Statistics from the SERDES interface */
  350. int (*serdes_get_sset_count)(struct mv88e6xxx_chip *chip, int port);
  351. int (*serdes_get_strings)(struct mv88e6xxx_chip *chip, int port,
  352. uint8_t *data);
  353. int (*serdes_get_stats)(struct mv88e6xxx_chip *chip, int port,
  354. uint64_t *data);
  355. /* VLAN Translation Unit operations */
  356. int (*vtu_getnext)(struct mv88e6xxx_chip *chip,
  357. struct mv88e6xxx_vtu_entry *entry);
  358. int (*vtu_loadpurge)(struct mv88e6xxx_chip *chip,
  359. struct mv88e6xxx_vtu_entry *entry);
  360. /* GPIO operations */
  361. const struct mv88e6xxx_gpio_ops *gpio_ops;
  362. /* Interface to the AVB/PTP registers */
  363. const struct mv88e6xxx_avb_ops *avb_ops;
  364. /* Remote Management Unit operations */
  365. int (*rmu_disable)(struct mv88e6xxx_chip *chip);
  366. /* Precision Time Protocol operations */
  367. const struct mv88e6xxx_ptp_ops *ptp_ops;
  368. };
  369. struct mv88e6xxx_irq_ops {
  370. /* Action to be performed when the interrupt happens */
  371. int (*irq_action)(struct mv88e6xxx_chip *chip, int irq);
  372. /* Setup the hardware to generate the interrupt */
  373. int (*irq_setup)(struct mv88e6xxx_chip *chip);
  374. /* Reset the hardware to stop generating the interrupt */
  375. void (*irq_free)(struct mv88e6xxx_chip *chip);
  376. };
  377. struct mv88e6xxx_gpio_ops {
  378. /* Get/set data on GPIO pin */
  379. int (*get_data)(struct mv88e6xxx_chip *chip, unsigned int pin);
  380. int (*set_data)(struct mv88e6xxx_chip *chip, unsigned int pin,
  381. int value);
  382. /* get/set GPIO direction */
  383. int (*get_dir)(struct mv88e6xxx_chip *chip, unsigned int pin);
  384. int (*set_dir)(struct mv88e6xxx_chip *chip, unsigned int pin,
  385. bool input);
  386. /* get/set GPIO pin control */
  387. int (*get_pctl)(struct mv88e6xxx_chip *chip, unsigned int pin,
  388. int *func);
  389. int (*set_pctl)(struct mv88e6xxx_chip *chip, unsigned int pin,
  390. int func);
  391. };
  392. struct mv88e6xxx_avb_ops {
  393. /* Access port-scoped Precision Time Protocol registers */
  394. int (*port_ptp_read)(struct mv88e6xxx_chip *chip, int port, int addr,
  395. u16 *data, int len);
  396. int (*port_ptp_write)(struct mv88e6xxx_chip *chip, int port, int addr,
  397. u16 data);
  398. /* Access global Precision Time Protocol registers */
  399. int (*ptp_read)(struct mv88e6xxx_chip *chip, int addr, u16 *data,
  400. int len);
  401. int (*ptp_write)(struct mv88e6xxx_chip *chip, int addr, u16 data);
  402. /* Access global Time Application Interface registers */
  403. int (*tai_read)(struct mv88e6xxx_chip *chip, int addr, u16 *data,
  404. int len);
  405. int (*tai_write)(struct mv88e6xxx_chip *chip, int addr, u16 data);
  406. };
  407. struct mv88e6xxx_ptp_ops {
  408. u64 (*clock_read)(const struct cyclecounter *cc);
  409. int (*ptp_enable)(struct ptp_clock_info *ptp,
  410. struct ptp_clock_request *rq, int on);
  411. int (*ptp_verify)(struct ptp_clock_info *ptp, unsigned int pin,
  412. enum ptp_pin_function func, unsigned int chan);
  413. void (*event_work)(struct work_struct *ugly);
  414. int (*port_enable)(struct mv88e6xxx_chip *chip, int port);
  415. int (*port_disable)(struct mv88e6xxx_chip *chip, int port);
  416. int (*global_enable)(struct mv88e6xxx_chip *chip);
  417. int (*global_disable)(struct mv88e6xxx_chip *chip);
  418. int n_ext_ts;
  419. int arr0_sts_reg;
  420. int arr1_sts_reg;
  421. int dep_sts_reg;
  422. u32 rx_filters;
  423. };
  424. #define STATS_TYPE_PORT BIT(0)
  425. #define STATS_TYPE_BANK0 BIT(1)
  426. #define STATS_TYPE_BANK1 BIT(2)
  427. struct mv88e6xxx_hw_stat {
  428. char string[ETH_GSTRING_LEN];
  429. size_t size;
  430. int reg;
  431. int type;
  432. };
  433. static inline bool mv88e6xxx_has_pvt(struct mv88e6xxx_chip *chip)
  434. {
  435. return chip->info->pvt;
  436. }
  437. static inline unsigned int mv88e6xxx_num_databases(struct mv88e6xxx_chip *chip)
  438. {
  439. return chip->info->num_databases;
  440. }
  441. static inline unsigned int mv88e6xxx_num_ports(struct mv88e6xxx_chip *chip)
  442. {
  443. return chip->info->num_ports;
  444. }
  445. static inline u16 mv88e6xxx_port_mask(struct mv88e6xxx_chip *chip)
  446. {
  447. return GENMASK(mv88e6xxx_num_ports(chip) - 1, 0);
  448. }
  449. static inline unsigned int mv88e6xxx_num_gpio(struct mv88e6xxx_chip *chip)
  450. {
  451. return chip->info->num_gpio;
  452. }
  453. int mv88e6xxx_read(struct mv88e6xxx_chip *chip, int addr, int reg, u16 *val);
  454. int mv88e6xxx_write(struct mv88e6xxx_chip *chip, int addr, int reg, u16 val);
  455. int mv88e6xxx_update(struct mv88e6xxx_chip *chip, int addr, int reg,
  456. u16 update);
  457. int mv88e6xxx_wait(struct mv88e6xxx_chip *chip, int addr, int reg, u16 mask);
  458. struct mii_bus *mv88e6xxx_default_mdio_bus(struct mv88e6xxx_chip *chip);
  459. #endif /* _MV88E6XXX_CHIP_H */