chip.h 13.9 KB
Newer Older
1
/*
2
 * Marvell 88E6xxx Ethernet switch single-chip definition
3
 *
4 5 6 7 8 9 10 11
 * Copyright (c) 2008 Marvell Semiconductor
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 */

12 13
#ifndef _MV88E6XXX_CHIP_H
#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 22 23 24
#ifndef UINT64_MAX
#define UINT64_MAX		(u64)(~((u64)0))
#endif

25 26 27 28 29 30 31 32 33 34
#define SMI_CMD			0x00
#define SMI_CMD_BUSY		BIT(15)
#define SMI_CMD_CLAUSE_22	BIT(12)
#define SMI_CMD_OP_22_WRITE	((1 << 10) | SMI_CMD_BUSY | SMI_CMD_CLAUSE_22)
#define SMI_CMD_OP_22_READ	((2 << 10) | SMI_CMD_BUSY | SMI_CMD_CLAUSE_22)
#define SMI_CMD_OP_45_WRITE_ADDR	((0 << 10) | SMI_CMD_BUSY)
#define SMI_CMD_OP_45_WRITE_DATA	((1 << 10) | SMI_CMD_BUSY)
#define SMI_CMD_OP_45_READ_DATA		((2 << 10) | SMI_CMD_BUSY)
#define SMI_CMD_OP_45_READ_DATA_INC	((3 << 10) | SMI_CMD_BUSY)
#define SMI_DATA		0x01
35

36 37
#define MV88E6XXX_N_FID		4096

38 39 40 41
/* PVT limits for 4-bit port and 5-bit switch */
#define MV88E6XXX_MAX_PVT_SWITCHES	32
#define MV88E6XXX_MAX_PVT_PORTS		16

42 43 44 45 46 47 48
enum mv88e6xxx_egress_mode {
	MV88E6XXX_EGRESS_MODE_UNMODIFIED,
	MV88E6XXX_EGRESS_MODE_UNTAGGED,
	MV88E6XXX_EGRESS_MODE_TAGGED,
	MV88E6XXX_EGRESS_MODE_ETHERTYPE,
};

49 50 51 52 53 54 55
enum mv88e6xxx_frame_mode {
	MV88E6XXX_FRAME_MODE_NORMAL,
	MV88E6XXX_FRAME_MODE_DSA,
	MV88E6XXX_FRAME_MODE_PROVIDER,
	MV88E6XXX_FRAME_MODE_ETHERTYPE,
};

56 57 58 59
/* List of supported models */
enum mv88e6xxx_model {
	MV88E6085,
	MV88E6095,
60
	MV88E6097,
61 62
	MV88E6123,
	MV88E6131,
63
	MV88E6141,
64 65 66 67 68 69 70
	MV88E6161,
	MV88E6165,
	MV88E6171,
	MV88E6172,
	MV88E6175,
	MV88E6176,
	MV88E6185,
71 72 73
	MV88E6190,
	MV88E6190X,
	MV88E6191,
74
	MV88E6240,
75
	MV88E6290,
76 77
	MV88E6320,
	MV88E6321,
78
	MV88E6341,
79 80 81
	MV88E6350,
	MV88E6351,
	MV88E6352,
82 83
	MV88E6390,
	MV88E6390X,
84 85
};

86 87 88 89 90 91 92 93
enum mv88e6xxx_family {
	MV88E6XXX_FAMILY_NONE,
	MV88E6XXX_FAMILY_6065,	/* 6031 6035 6061 6065 */
	MV88E6XXX_FAMILY_6095,	/* 6092 6095 */
	MV88E6XXX_FAMILY_6097,	/* 6046 6085 6096 6097 */
	MV88E6XXX_FAMILY_6165,	/* 6123 6161 6165 */
	MV88E6XXX_FAMILY_6185,	/* 6108 6121 6122 6131 6152 6155 6182 6185 */
	MV88E6XXX_FAMILY_6320,	/* 6320 6321 */
94
	MV88E6XXX_FAMILY_6341,	/* 6141 6341 */
95 96
	MV88E6XXX_FAMILY_6351,	/* 6171 6175 6350 6351 */
	MV88E6XXX_FAMILY_6352,	/* 6172 6176 6240 6352 */
97
	MV88E6XXX_FAMILY_6390,  /* 6190 6190X 6191 6290 6390 6390X */
98 99
};

100
enum mv88e6xxx_cap {
101 102 103 104
	/* Energy Efficient Ethernet.
	 */
	MV88E6XXX_CAP_EEE,

105 106 107 108 109 110 111
	/* Multi-chip Addressing Mode.
	 * Some chips respond to only 2 registers of its own SMI device address
	 * when it is non-zero, and use indirect access to internal registers.
	 */
	MV88E6XXX_CAP_SMI_CMD,		/* (0x00) SMI Command */
	MV88E6XXX_CAP_SMI_DATA,		/* (0x01) SMI Data */

112 113 114 115
	/* Switch Global 2 Registers.
	 * The device contains a second set of global 16-bit registers.
	 */
	MV88E6XXX_CAP_GLOBAL2,
116
	MV88E6XXX_CAP_G2_INT,		/* (0x00) Interrupt Status */
117 118
	MV88E6XXX_CAP_G2_MGMT_EN_2X,	/* (0x02) MGMT Enable Register 2x */
	MV88E6XXX_CAP_G2_MGMT_EN_0X,	/* (0x03) MGMT Enable Register 0x */
119
	MV88E6XXX_CAP_G2_POT,		/* (0x0f) Priority Override Table */
120 121 122
};

/* Bitmask of capabilities */
123 124 125 126 127 128
#define MV88E6XXX_FLAG_EEE		BIT_ULL(MV88E6XXX_CAP_EEE)

#define MV88E6XXX_FLAG_SMI_CMD		BIT_ULL(MV88E6XXX_CAP_SMI_CMD)
#define MV88E6XXX_FLAG_SMI_DATA		BIT_ULL(MV88E6XXX_CAP_SMI_DATA)

#define MV88E6XXX_FLAG_GLOBAL2		BIT_ULL(MV88E6XXX_CAP_GLOBAL2)
129
#define MV88E6XXX_FLAG_G2_INT		BIT_ULL(MV88E6XXX_CAP_G2_INT)
130 131 132 133
#define MV88E6XXX_FLAG_G2_MGMT_EN_2X	BIT_ULL(MV88E6XXX_CAP_G2_MGMT_EN_2X)
#define MV88E6XXX_FLAG_G2_MGMT_EN_0X	BIT_ULL(MV88E6XXX_CAP_G2_MGMT_EN_0X)
#define MV88E6XXX_FLAG_G2_POT		BIT_ULL(MV88E6XXX_CAP_G2_POT)

134 135 136 137 138
/* Multi-chip Addressing Mode */
#define MV88E6XXX_FLAGS_MULTI_CHIP	\
	(MV88E6XXX_FLAG_SMI_CMD |	\
	 MV88E6XXX_FLAG_SMI_DATA)

139
#define MV88E6XXX_FLAGS_FAMILY_6095	\
140
	(MV88E6XXX_FLAG_GLOBAL2 |	\
141
	 MV88E6XXX_FLAG_G2_MGMT_EN_0X |	\
142
	 MV88E6XXX_FLAGS_MULTI_CHIP)
143 144

#define MV88E6XXX_FLAGS_FAMILY_6097	\
145
	(MV88E6XXX_FLAG_GLOBAL2 |	\
146
	 MV88E6XXX_FLAG_G2_INT |        \
147 148
	 MV88E6XXX_FLAG_G2_MGMT_EN_2X |	\
	 MV88E6XXX_FLAG_G2_MGMT_EN_0X |	\
149
	 MV88E6XXX_FLAG_G2_POT |	\
150
	 MV88E6XXX_FLAGS_MULTI_CHIP)
151

152
#define MV88E6XXX_FLAGS_FAMILY_6165	\
153
	(MV88E6XXX_FLAG_GLOBAL2 |	\
154
	 MV88E6XXX_FLAG_G2_INT |	\
155 156
	 MV88E6XXX_FLAG_G2_MGMT_EN_2X |	\
	 MV88E6XXX_FLAG_G2_MGMT_EN_0X |	\
157
	 MV88E6XXX_FLAG_G2_POT |	\
158
	 MV88E6XXX_FLAGS_MULTI_CHIP)
159

160
#define MV88E6XXX_FLAGS_FAMILY_6185	\
161
	(MV88E6XXX_FLAG_GLOBAL2 |	\
162
	 MV88E6XXX_FLAG_G2_MGMT_EN_0X |	\
163
	 MV88E6XXX_FLAGS_MULTI_CHIP)
164

165
#define MV88E6XXX_FLAGS_FAMILY_6320	\
166
	(MV88E6XXX_FLAG_EEE |		\
167
	 MV88E6XXX_FLAG_GLOBAL2 |	\
168 169
	 MV88E6XXX_FLAG_G2_MGMT_EN_2X |	\
	 MV88E6XXX_FLAG_G2_MGMT_EN_0X |	\
170
	 MV88E6XXX_FLAG_G2_POT |	\
171
	 MV88E6XXX_FLAGS_MULTI_CHIP)
172

173 174 175 176 177
#define MV88E6XXX_FLAGS_FAMILY_6341	\
	(MV88E6XXX_FLAG_EEE |		\
	 MV88E6XXX_FLAG_GLOBAL2 |	\
	 MV88E6XXX_FLAG_G2_INT |	\
	 MV88E6XXX_FLAG_G2_POT |	\
178
	 MV88E6XXX_FLAGS_MULTI_CHIP)
179

180
#define MV88E6XXX_FLAGS_FAMILY_6351	\
181
	(MV88E6XXX_FLAG_GLOBAL2 |	\
182
	 MV88E6XXX_FLAG_G2_INT |	\
183 184
	 MV88E6XXX_FLAG_G2_MGMT_EN_2X |	\
	 MV88E6XXX_FLAG_G2_MGMT_EN_0X |	\
185
	 MV88E6XXX_FLAG_G2_POT |	\
186
	 MV88E6XXX_FLAGS_MULTI_CHIP)
187

188
#define MV88E6XXX_FLAGS_FAMILY_6352	\
189
	(MV88E6XXX_FLAG_EEE |		\
190
	 MV88E6XXX_FLAG_GLOBAL2 |	\
191
	 MV88E6XXX_FLAG_G2_INT |	\
192 193
	 MV88E6XXX_FLAG_G2_MGMT_EN_2X |	\
	 MV88E6XXX_FLAG_G2_MGMT_EN_0X |	\
194
	 MV88E6XXX_FLAG_G2_POT |	\
195
	 MV88E6XXX_FLAGS_MULTI_CHIP)
196

197 198 199
#define MV88E6XXX_FLAGS_FAMILY_6390	\
	(MV88E6XXX_FLAG_EEE |		\
	 MV88E6XXX_FLAG_GLOBAL2 |	\
200
	 MV88E6XXX_FLAG_G2_INT |        \
201
	 MV88E6XXX_FLAGS_MULTI_CHIP)
202

203 204
struct mv88e6xxx_ops;

205
struct mv88e6xxx_info {
206
	enum mv88e6xxx_family family;
207 208
	u16 prod_num;
	const char *name;
209
	unsigned int num_databases;
210
	unsigned int num_ports;
211
	unsigned int max_vid;
212
	unsigned int port_base_addr;
213
	unsigned int global1_addr;
214
	unsigned int age_time_coeff;
215
	unsigned int g1_irqs;
216
	bool pvt;
217
	enum dsa_tag_protocol tag_protocol;
218
	unsigned long long flags;
219 220 221 222 223

	/* Mask for FromPort and ToPort value of PortVec used in ATU Move
	 * operation. 0 means that the ATU Move operation is not supported.
	 */
	u8 atu_move_port_mask;
224
	const struct mv88e6xxx_ops *ops;
225 226
};

227 228 229
struct mv88e6xxx_atu_entry {
	u8	state;
	bool	trunk;
230
	u16	portvec;
231 232 233
	u8	mac[ETH_ALEN];
};

234
struct mv88e6xxx_vtu_entry {
235 236 237 238
	u16	vid;
	u16	fid;
	u8	sid;
	bool	valid;
239 240
	u8	member[DSA_MAX_PORTS];
	u8	state[DSA_MAX_PORTS];
241 242
};

243
struct mv88e6xxx_bus_ops;
244
struct mv88e6xxx_irq_ops;
245

246 247 248 249 250 251 252
struct mv88e6xxx_irq {
	u16 masked;
	struct irq_chip chip;
	struct irq_domain *domain;
	unsigned int nirqs;
};

253
struct mv88e6xxx_chip {
254 255
	const struct mv88e6xxx_info *info;

256 257 258
	/* The dsa_switch this private structure is related to */
	struct dsa_switch *ds;

259 260 261
	/* The device this structure is associated to */
	struct device *dev;

262 263
	/* This mutex protects the access to the switch registers */
	struct mutex reg_lock;
264

265 266 267
	/* The MII bus and the address on the bus that is used to
	 * communication with the switch
	 */
268
	const struct mv88e6xxx_bus_ops *smi_ops;
269 270 271
	struct mii_bus *bus;
	int sw_addr;

272
	/* Handles automatic disabling and re-enabling of the PHY
273 274
	 * polling unit.
	 */
275
	const struct mv88e6xxx_bus_ops *phy_ops;
276 277 278 279 280
	struct mutex		ppu_mutex;
	int			ppu_disabled;
	struct work_struct	ppu_work;
	struct timer_list	ppu_timer;

281
	/* This mutex serialises access to the statistics unit.
282 283 284
	 * Hold this mutex over snapshot + dump sequences.
	 */
	struct mutex	stats_mutex;
285

286 287 288 289 290
	/* A switch may have a GPIO line tied to its reset pin. Parse
	 * this from the device tree, and use it before performing
	 * switch soft reset.
	 */
	struct gpio_desc *reset;
291 292 293

	/* set to size of eeprom if supported by the switch */
	int		eeprom_len;
294

295 296
	/* List of mdio busses */
	struct list_head mdios;
297 298 299 300 301 302 303

	/* There can be two interrupt controllers, which are chained
	 * off a GPIO as interrupt source
	 */
	struct mv88e6xxx_irq g1_irq;
	struct mv88e6xxx_irq g2_irq;
	int irq;
304
	int device_irq;
305
	int watchdog_irq;
306 307
};

308
struct mv88e6xxx_bus_ops {
309 310
	int (*read)(struct mv88e6xxx_chip *chip, int addr, int reg, u16 *val);
	int (*write)(struct mv88e6xxx_chip *chip, int addr, int reg, u16 val);
311 312
};

313
struct mv88e6xxx_mdio_bus {
314
	struct mii_bus *bus;
315
	struct mv88e6xxx_chip *chip;
316 317
	struct list_head list;
	bool external;
318 319
};

320
struct mv88e6xxx_ops {
321 322 323
	/* Ingress Rate Limit unit (IRL) operations */
	int (*irl_init_all)(struct mv88e6xxx_chip *chip, int port);

324 325 326 327 328
	int (*get_eeprom)(struct mv88e6xxx_chip *chip,
			  struct ethtool_eeprom *eeprom, u8 *data);
	int (*set_eeprom)(struct mv88e6xxx_chip *chip,
			  struct ethtool_eeprom *eeprom, u8 *data);

329 330
	int (*set_switch_mac)(struct mv88e6xxx_chip *chip, u8 *addr);

331 332 333 334 335 336
	int (*phy_read)(struct mv88e6xxx_chip *chip,
			struct mii_bus *bus,
			int addr, int reg, u16 *val);
	int (*phy_write)(struct mv88e6xxx_chip *chip,
			 struct mii_bus *bus,
			 int addr, int reg, u16 val);
337

338 339 340 341
	/* PHY Polling Unit (PPU) operations */
	int (*ppu_enable)(struct mv88e6xxx_chip *chip);
	int (*ppu_disable)(struct mv88e6xxx_chip *chip);

342 343 344
	/* Switch Software Reset */
	int (*reset)(struct mv88e6xxx_chip *chip);

345 346 347 348 349 350
	/* RGMII Receive/Transmit Timing Control
	 * Add delay on PHY_INTERFACE_MODE_RGMII_*ID, no delay otherwise.
	 */
	int (*port_set_rgmii_delay)(struct mv88e6xxx_chip *chip, int port,
				    phy_interface_t mode);

351 352 353 354 355 356 357 358 359
#define LINK_FORCED_DOWN	0
#define LINK_FORCED_UP		1
#define LINK_UNFORCED		-2

	/* Port's MAC link state
	 * Use LINK_FORCED_UP or LINK_FORCED_DOWN to force link up or down,
	 * or LINK_UNFORCED for normal link detection.
	 */
	int (*port_set_link)(struct mv88e6xxx_chip *chip, int port, int link);
360 361 362 363 364 365 366 367 368

#define DUPLEX_UNFORCED		-2

	/* Port's MAC duplex mode
	 *
	 * Use DUPLEX_HALF or DUPLEX_FULL to force half or full duplex,
	 * or DUPLEX_UNFORCED for normal duplex detection.
	 */
	int (*port_set_duplex)(struct mv88e6xxx_chip *chip, int port, int dup);
369 370 371 372 373 374 375 376 377 378

#define SPEED_MAX		INT_MAX
#define SPEED_UNFORCED		-2

	/* Port's MAC speed (in Mbps)
	 *
	 * Depending on the chip, 10, 100, 200, 1000, 2500, 10000 are valid.
	 * Use SPEED_UNFORCED for normal detection, SPEED_MAX for max value.
	 */
	int (*port_set_speed)(struct mv88e6xxx_chip *chip, int port, int speed);
379

380 381
	int (*port_tag_remap)(struct mv88e6xxx_chip *chip, int port);

382 383
	int (*port_set_frame_mode)(struct mv88e6xxx_chip *chip, int port,
				   enum mv88e6xxx_frame_mode mode);
384 385
	int (*port_set_egress_floods)(struct mv88e6xxx_chip *chip, int port,
				      bool unicast, bool multicast);
386 387
	int (*port_set_ether_type)(struct mv88e6xxx_chip *chip, int port,
				   u16 etype);
388 389
	int (*port_set_jumbo_size)(struct mv88e6xxx_chip *chip, int port,
				   size_t size);
390

391
	int (*port_egress_rate_limiting)(struct mv88e6xxx_chip *chip, int port);
392 393
	int (*port_pause_limit)(struct mv88e6xxx_chip *chip, int port, u8 in,
				u8 out);
394
	int (*port_disable_learn_limit)(struct mv88e6xxx_chip *chip, int port);
395
	int (*port_disable_pri_override)(struct mv88e6xxx_chip *chip, int port);
396

397 398 399 400 401 402
	/* CMODE control what PHY mode the MAC will use, eg. SGMII, RGMII, etc.
	 * Some chips allow this to be configured on specific ports.
	 */
	int (*port_set_cmode)(struct mv88e6xxx_chip *chip, int port,
			      phy_interface_t mode);

403 404 405 406 407 408
	/* Some devices have a per port register indicating what is
	 * the upstream port this port should forward to.
	 */
	int (*port_set_upstream_port)(struct mv88e6xxx_chip *chip, int port,
				      int upstream_port);

409 410 411 412
	/* Snapshot the statistics for a port. The statistics can then
	 * be read back a leisure but still with a consistent view.
	 */
	int (*stats_snapshot)(struct mv88e6xxx_chip *chip, int port);
413 414 415 416 417

	/* Set the histogram mode for statistics, when the control registers
	 * are separated out of the STATS_OP register.
	 */
	int (*stats_set_histogram)(struct mv88e6xxx_chip *chip);
418

419 420 421
	/* Return the number of strings describing statistics */
	int (*stats_get_sset_count)(struct mv88e6xxx_chip *chip);
	void (*stats_get_strings)(struct mv88e6xxx_chip *chip,  uint8_t *data);
422 423
	void (*stats_get_stats)(struct mv88e6xxx_chip *chip,  int port,
				uint64_t *data);
424 425
	int (*set_cpu_port)(struct mv88e6xxx_chip *chip, int port);
	int (*set_egress_port)(struct mv88e6xxx_chip *chip, int port);
426
	const struct mv88e6xxx_irq_ops *watchdog_ops;
427 428 429

	/* Can be either in g1 or g2, so don't use a prefix */
	int (*mgmt_rsvd2cpu)(struct mv88e6xxx_chip *chip);
430

431 432 433
	/* Power on/off a SERDES interface */
	int (*serdes_power)(struct mv88e6xxx_chip *chip, int port, bool on);

434 435 436
	/* VLAN Translation Unit operations */
	int (*vtu_getnext)(struct mv88e6xxx_chip *chip,
			   struct mv88e6xxx_vtu_entry *entry);
437 438
	int (*vtu_loadpurge)(struct mv88e6xxx_chip *chip,
			     struct mv88e6xxx_vtu_entry *entry);
439 440
};

441 442 443 444 445 446 447 448 449
struct mv88e6xxx_irq_ops {
	/* Action to be performed when the interrupt happens */
	int (*irq_action)(struct mv88e6xxx_chip *chip, int irq);
	/* Setup the hardware to generate the interrupt */
	int (*irq_setup)(struct mv88e6xxx_chip *chip);
	/* Reset the hardware to stop generating the interrupt */
	void (*irq_free)(struct mv88e6xxx_chip *chip);
};

450 451 452 453
#define STATS_TYPE_PORT		BIT(0)
#define STATS_TYPE_BANK0	BIT(1)
#define STATS_TYPE_BANK1	BIT(2)

454 455 456 457
struct mv88e6xxx_hw_stat {
	char string[ETH_GSTRING_LEN];
	int sizeof_stat;
	int reg;
458
	int type;
459 460
};

461
static inline bool mv88e6xxx_has(struct mv88e6xxx_chip *chip,
462 463
				 unsigned long flags)
{
464
	return (chip->info->flags & flags) == flags;
465 466
}

467 468 469 470 471
static inline bool mv88e6xxx_has_pvt(struct mv88e6xxx_chip *chip)
{
	return chip->info->pvt;
}

472 473 474 475 476
static inline unsigned int mv88e6xxx_num_databases(struct mv88e6xxx_chip *chip)
{
	return chip->info->num_databases;
}

477 478 479 480 481
static inline unsigned int mv88e6xxx_num_ports(struct mv88e6xxx_chip *chip)
{
	return chip->info->num_ports;
}

482 483 484 485 486
static inline u16 mv88e6xxx_port_mask(struct mv88e6xxx_chip *chip)
{
	return GENMASK(mv88e6xxx_num_ports(chip) - 1, 0);
}

487 488 489 490 491
int mv88e6xxx_read(struct mv88e6xxx_chip *chip, int addr, int reg, u16 *val);
int mv88e6xxx_write(struct mv88e6xxx_chip *chip, int addr, int reg, u16 val);
int mv88e6xxx_update(struct mv88e6xxx_chip *chip, int addr, int reg,
		     u16 update);
int mv88e6xxx_wait(struct mv88e6xxx_chip *chip, int addr, int reg, u16 mask);
492
struct mii_bus *mv88e6xxx_default_mdio_bus(struct mv88e6xxx_chip *chip);
493 494

#endif /* _MV88E6XXX_CHIP_H */