blob: 8e215ebc8d3495c851cdd95df97002d6902698cc [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
22#define ATU_CMD_FLUSH_NONSTATIC_FID (ATU_BUSY | 0x6000)
23
24/* port states */
25
26#define PSTATE_MASK 0x03
27#define PSTATE_DISABLED 0x00
28#define PSTATE_BLOCKING 0x01
29#define PSTATE_LEARNING 0x02
30#define PSTATE_FORWARDING 0x03
31
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000032struct mv88e6xxx_priv_state {
Barry Grussling3675c8d2013-01-08 16:05:53 +000033 /* When using multi-chip addressing, this mutex protects
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000034 * access to the indirect access registers. (In single-chip
35 * mode, this mutex is effectively useless.)
36 */
37 struct mutex smi_mutex;
38
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000039#ifdef CONFIG_NET_DSA_MV88E6XXX_NEED_PPU
Barry Grussling3675c8d2013-01-08 16:05:53 +000040 /* Handles automatic disabling and re-enabling of the PHY
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000041 * polling unit.
42 */
43 struct mutex ppu_mutex;
44 int ppu_disabled;
45 struct work_struct ppu_work;
46 struct timer_list ppu_timer;
47#endif
48
Barry Grussling3675c8d2013-01-08 16:05:53 +000049 /* This mutex serialises access to the statistics unit.
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000050 * Hold this mutex over snapshot + dump sequences.
51 */
52 struct mutex stats_mutex;
Peter Korsgaardec80bfc2011-04-05 03:03:56 +000053
Guenter Roeck3ad50cc2014-10-29 10:44:56 -070054 /* This mutex serializes phy access for chips with
55 * indirect phy addressing. It is unused for chips
56 * with direct phy access.
57 */
58 struct mutex phy_mutex;
59
Guenter Roeck33b43df2014-10-29 10:45:03 -070060 /* This mutex serializes eeprom access for chips with
61 * eeprom support.
62 */
63 struct mutex eeprom_mutex;
64
Peter Korsgaardec80bfc2011-04-05 03:03:56 +000065 int id; /* switch product id */
Guenter Roeckfacd95b2015-03-26 18:36:35 -070066
67 /* hw bridging */
68
69 u32 fid_mask;
70 u8 fid[DSA_MAX_PORTS];
71 u16 bridge_mask[DSA_MAX_PORTS];
72
73 unsigned long port_state_update_mask;
74 u8 port_state[DSA_MAX_PORTS];
75
76 struct work_struct bridge_work;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000077};
78
79struct mv88e6xxx_hw_stat {
80 char string[ETH_GSTRING_LEN];
81 int sizeof_stat;
82 int reg;
83};
84
Guenter Roeckd827e882015-03-26 18:36:29 -070085int mv88e6xxx_setup_port_common(struct dsa_switch *ds, int port);
Guenter Roeckacdaffc2015-03-26 18:36:28 -070086int mv88e6xxx_setup_common(struct dsa_switch *ds);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000087int __mv88e6xxx_reg_read(struct mii_bus *bus, int sw_addr, int addr, int reg);
88int mv88e6xxx_reg_read(struct dsa_switch *ds, int addr, int reg);
89int __mv88e6xxx_reg_write(struct mii_bus *bus, int sw_addr, int addr,
Barry Grussling85686582013-01-08 16:05:56 +000090 int reg, u16 val);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000091int mv88e6xxx_reg_write(struct dsa_switch *ds, int addr, int reg, u16 val);
92int mv88e6xxx_config_prio(struct dsa_switch *ds);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000093int mv88e6xxx_set_addr_direct(struct dsa_switch *ds, u8 *addr);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000094int mv88e6xxx_set_addr_indirect(struct dsa_switch *ds, u8 *addr);
95int mv88e6xxx_phy_read(struct dsa_switch *ds, int addr, int regnum);
96int mv88e6xxx_phy_write(struct dsa_switch *ds, int addr, int regnum, u16 val);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000097void mv88e6xxx_ppu_state_init(struct dsa_switch *ds);
98int mv88e6xxx_phy_read_ppu(struct dsa_switch *ds, int addr, int regnum);
99int mv88e6xxx_phy_write_ppu(struct dsa_switch *ds, int addr,
100 int regnum, u16 val);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000101void mv88e6xxx_poll_link(struct dsa_switch *ds);
102void mv88e6xxx_get_strings(struct dsa_switch *ds,
103 int nr_stats, struct mv88e6xxx_hw_stat *stats,
104 int port, uint8_t *data);
105void mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds,
106 int nr_stats, struct mv88e6xxx_hw_stat *stats,
107 int port, uint64_t *data);
Guenter Roecka1ab91f2014-10-29 10:45:05 -0700108int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port);
109void mv88e6xxx_get_regs(struct dsa_switch *ds, int port,
110 struct ethtool_regs *regs, void *_p);
Andrew Lunneaa23762014-11-15 22:24:51 +0100111int mv88e6xxx_get_temp(struct dsa_switch *ds, int *temp);
Andrew Lunnf3044682015-02-14 19:17:50 +0100112int mv88e6xxx_phy_wait(struct dsa_switch *ds);
113int mv88e6xxx_eeprom_load_wait(struct dsa_switch *ds);
114int mv88e6xxx_eeprom_busy_wait(struct dsa_switch *ds);
115int mv88e6xxx_phy_read_indirect(struct dsa_switch *ds, int addr, int regnum);
116int mv88e6xxx_phy_write_indirect(struct dsa_switch *ds, int addr, int regnum,
117 u16 val);
Guenter Roeck11b3b452015-03-06 22:23:51 -0800118int mv88e6xxx_get_eee(struct dsa_switch *ds, int port, struct ethtool_eee *e);
119int mv88e6xxx_set_eee(struct dsa_switch *ds, int port,
120 struct phy_device *phydev, struct ethtool_eee *e);
Guenter Roeckfacd95b2015-03-26 18:36:35 -0700121int mv88e6xxx_join_bridge(struct dsa_switch *ds, int port, u32 br_port_mask);
122int mv88e6xxx_leave_bridge(struct dsa_switch *ds, int port, u32 br_port_mask);
123int mv88e6xxx_port_stp_update(struct dsa_switch *ds, int port, u8 state);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000124
Ben Hutchings98e67302011-11-25 14:36:19 +0000125extern struct dsa_switch_driver mv88e6131_switch_driver;
126extern struct dsa_switch_driver mv88e6123_61_65_switch_driver;
Guenter Roeck3ad50cc2014-10-29 10:44:56 -0700127extern struct dsa_switch_driver mv88e6352_switch_driver;
Andrew Lunn42f27252014-09-12 23:58:44 +0200128extern struct dsa_switch_driver mv88e6171_switch_driver;
Ben Hutchings98e67302011-11-25 14:36:19 +0000129
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000130#define REG_READ(addr, reg) \
131 ({ \
132 int __ret; \
133 \
134 __ret = mv88e6xxx_reg_read(ds, addr, reg); \
135 if (__ret < 0) \
136 return __ret; \
137 __ret; \
138 })
139
140#define REG_WRITE(addr, reg, val) \
141 ({ \
142 int __ret; \
143 \
144 __ret = mv88e6xxx_reg_write(ds, addr, reg, val); \
145 if (__ret < 0) \
146 return __ret; \
147 })
148
149
150
151#endif