blob: aaf239aba7260ddfc562e84b60c3883d9031733d [file] [log] [blame]
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001/*
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
11#ifndef __MV88E6XXX_H
12#define __MV88E6XXX_H
13
14#define REG_PORT(p) (0x10 + (p))
15#define REG_GLOBAL 0x1b
16#define REG_GLOBAL2 0x1c
17
Guenter Roeckfacd95b2015-03-26 18:36:35 -070018/* ATU commands */
19
20#define ATU_BUSY 0x8000
21
Guenter Roeckdefb05b2015-03-26 18:36:38 -070022#define ATU_CMD_LOAD_FID (ATU_BUSY | 0x3000)
23#define ATU_CMD_GETNEXT_FID (ATU_BUSY | 0x4000)
Guenter Roeckfacd95b2015-03-26 18:36:35 -070024#define ATU_CMD_FLUSH_NONSTATIC_FID (ATU_BUSY | 0x6000)
25
26/* port states */
27
28#define PSTATE_MASK 0x03
29#define PSTATE_DISABLED 0x00
30#define PSTATE_BLOCKING 0x01
31#define PSTATE_LEARNING 0x02
32#define PSTATE_FORWARDING 0x03
33
Guenter Roeckdefb05b2015-03-26 18:36:38 -070034/* FDB states */
35
36#define FDB_STATE_MASK 0x0f
37
38#define FDB_STATE_UNUSED 0x00
39#define FDB_STATE_MC_STATIC 0x07 /* static multicast */
40#define FDB_STATE_STATIC 0x0e /* static unicast */
41
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000042struct mv88e6xxx_priv_state {
Barry Grussling3675c8d2013-01-08 16:05:53 +000043 /* When using multi-chip addressing, this mutex protects
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000044 * access to the indirect access registers. (In single-chip
45 * mode, this mutex is effectively useless.)
46 */
47 struct mutex smi_mutex;
48
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000049#ifdef CONFIG_NET_DSA_MV88E6XXX_NEED_PPU
Barry Grussling3675c8d2013-01-08 16:05:53 +000050 /* Handles automatic disabling and re-enabling of the PHY
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000051 * polling unit.
52 */
53 struct mutex ppu_mutex;
54 int ppu_disabled;
55 struct work_struct ppu_work;
56 struct timer_list ppu_timer;
57#endif
58
Barry Grussling3675c8d2013-01-08 16:05:53 +000059 /* This mutex serialises access to the statistics unit.
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000060 * Hold this mutex over snapshot + dump sequences.
61 */
62 struct mutex stats_mutex;
Peter Korsgaardec80bfc2011-04-05 03:03:56 +000063
Guenter Roeck3ad50cc2014-10-29 10:44:56 -070064 /* This mutex serializes phy access for chips with
65 * indirect phy addressing. It is unused for chips
66 * with direct phy access.
67 */
68 struct mutex phy_mutex;
69
Guenter Roeck33b43df2014-10-29 10:45:03 -070070 /* This mutex serializes eeprom access for chips with
71 * eeprom support.
72 */
73 struct mutex eeprom_mutex;
74
Peter Korsgaardec80bfc2011-04-05 03:03:56 +000075 int id; /* switch product id */
Guenter Roeckfacd95b2015-03-26 18:36:35 -070076
77 /* hw bridging */
78
79 u32 fid_mask;
80 u8 fid[DSA_MAX_PORTS];
81 u16 bridge_mask[DSA_MAX_PORTS];
82
83 unsigned long port_state_update_mask;
84 u8 port_state[DSA_MAX_PORTS];
85
86 struct work_struct bridge_work;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000087};
88
89struct mv88e6xxx_hw_stat {
90 char string[ETH_GSTRING_LEN];
91 int sizeof_stat;
92 int reg;
93};
94
Guenter Roeckd827e882015-03-26 18:36:29 -070095int mv88e6xxx_setup_port_common(struct dsa_switch *ds, int port);
Guenter Roeckacdaffc2015-03-26 18:36:28 -070096int mv88e6xxx_setup_common(struct dsa_switch *ds);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000097int __mv88e6xxx_reg_read(struct mii_bus *bus, int sw_addr, int addr, int reg);
98int mv88e6xxx_reg_read(struct dsa_switch *ds, int addr, int reg);
99int __mv88e6xxx_reg_write(struct mii_bus *bus, int sw_addr, int addr,
Barry Grussling85686582013-01-08 16:05:56 +0000100 int reg, u16 val);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000101int mv88e6xxx_reg_write(struct dsa_switch *ds, int addr, int reg, u16 val);
102int mv88e6xxx_config_prio(struct dsa_switch *ds);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000103int mv88e6xxx_set_addr_direct(struct dsa_switch *ds, u8 *addr);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000104int mv88e6xxx_set_addr_indirect(struct dsa_switch *ds, u8 *addr);
105int mv88e6xxx_phy_read(struct dsa_switch *ds, int addr, int regnum);
106int mv88e6xxx_phy_write(struct dsa_switch *ds, int addr, int regnum, u16 val);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000107void mv88e6xxx_ppu_state_init(struct dsa_switch *ds);
108int mv88e6xxx_phy_read_ppu(struct dsa_switch *ds, int addr, int regnum);
109int mv88e6xxx_phy_write_ppu(struct dsa_switch *ds, int addr,
110 int regnum, u16 val);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000111void mv88e6xxx_poll_link(struct dsa_switch *ds);
112void mv88e6xxx_get_strings(struct dsa_switch *ds,
113 int nr_stats, struct mv88e6xxx_hw_stat *stats,
114 int port, uint8_t *data);
115void mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds,
116 int nr_stats, struct mv88e6xxx_hw_stat *stats,
117 int port, uint64_t *data);
Guenter Roecka1ab91f2014-10-29 10:45:05 -0700118int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port);
119void mv88e6xxx_get_regs(struct dsa_switch *ds, int port,
120 struct ethtool_regs *regs, void *_p);
Andrew Lunneaa23762014-11-15 22:24:51 +0100121int mv88e6xxx_get_temp(struct dsa_switch *ds, int *temp);
Andrew Lunnf3044682015-02-14 19:17:50 +0100122int mv88e6xxx_phy_wait(struct dsa_switch *ds);
123int mv88e6xxx_eeprom_load_wait(struct dsa_switch *ds);
124int mv88e6xxx_eeprom_busy_wait(struct dsa_switch *ds);
125int mv88e6xxx_phy_read_indirect(struct dsa_switch *ds, int addr, int regnum);
126int mv88e6xxx_phy_write_indirect(struct dsa_switch *ds, int addr, int regnum,
127 u16 val);
Guenter Roeck11b3b452015-03-06 22:23:51 -0800128int mv88e6xxx_get_eee(struct dsa_switch *ds, int port, struct ethtool_eee *e);
129int mv88e6xxx_set_eee(struct dsa_switch *ds, int port,
130 struct phy_device *phydev, struct ethtool_eee *e);
Guenter Roeckfacd95b2015-03-26 18:36:35 -0700131int mv88e6xxx_join_bridge(struct dsa_switch *ds, int port, u32 br_port_mask);
132int mv88e6xxx_leave_bridge(struct dsa_switch *ds, int port, u32 br_port_mask);
133int mv88e6xxx_port_stp_update(struct dsa_switch *ds, int port, u8 state);
Guenter Roeckdefb05b2015-03-26 18:36:38 -0700134int mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
135 const unsigned char *addr, u16 vid);
136int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
137 const unsigned char *addr, u16 vid);
138int mv88e6xxx_port_fdb_getnext(struct dsa_switch *ds, int port,
139 unsigned char *addr, bool *is_static);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000140
Ben Hutchings98e67302011-11-25 14:36:19 +0000141extern struct dsa_switch_driver mv88e6131_switch_driver;
142extern struct dsa_switch_driver mv88e6123_61_65_switch_driver;
Guenter Roeck3ad50cc2014-10-29 10:44:56 -0700143extern struct dsa_switch_driver mv88e6352_switch_driver;
Andrew Lunn42f27252014-09-12 23:58:44 +0200144extern struct dsa_switch_driver mv88e6171_switch_driver;
Ben Hutchings98e67302011-11-25 14:36:19 +0000145
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000146#define REG_READ(addr, reg) \
147 ({ \
148 int __ret; \
149 \
150 __ret = mv88e6xxx_reg_read(ds, addr, reg); \
151 if (__ret < 0) \
152 return __ret; \
153 __ret; \
154 })
155
156#define REG_WRITE(addr, reg, val) \
157 ({ \
158 int __ret; \
159 \
160 __ret = mv88e6xxx_reg_write(ds, addr, reg, val); \
161 if (__ret < 0) \
162 return __ret; \
163 })
164
165
166
167#endif