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