blob: a4df4968594ef03d4179f883a8318aad25be6b07 [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
18struct mv88e6xxx_priv_state {
Barry Grussling3675c8d2013-01-08 16:05:53 +000019 /* When using multi-chip addressing, this mutex protects
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000020 * access to the indirect access registers. (In single-chip
21 * mode, this mutex is effectively useless.)
22 */
23 struct mutex smi_mutex;
24
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000025#ifdef CONFIG_NET_DSA_MV88E6XXX_NEED_PPU
Barry Grussling3675c8d2013-01-08 16:05:53 +000026 /* Handles automatic disabling and re-enabling of the PHY
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000027 * polling unit.
28 */
29 struct mutex ppu_mutex;
30 int ppu_disabled;
31 struct work_struct ppu_work;
32 struct timer_list ppu_timer;
33#endif
34
Barry Grussling3675c8d2013-01-08 16:05:53 +000035 /* This mutex serialises access to the statistics unit.
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000036 * Hold this mutex over snapshot + dump sequences.
37 */
38 struct mutex stats_mutex;
Peter Korsgaardec80bfc2011-04-05 03:03:56 +000039
Guenter Roeck3ad50cc2014-10-29 10:44:56 -070040 /* This mutex serializes phy access for chips with
41 * indirect phy addressing. It is unused for chips
42 * with direct phy access.
43 */
44 struct mutex phy_mutex;
45
Guenter Roeck33b43df2014-10-29 10:45:03 -070046 /* This mutex serializes eeprom access for chips with
47 * eeprom support.
48 */
49 struct mutex eeprom_mutex;
50
Peter Korsgaardec80bfc2011-04-05 03:03:56 +000051 int id; /* switch product id */
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000052};
53
54struct mv88e6xxx_hw_stat {
55 char string[ETH_GSTRING_LEN];
56 int sizeof_stat;
57 int reg;
58};
59
Guenter Roeckd827e882015-03-26 18:36:29 -070060int mv88e6xxx_setup_port_common(struct dsa_switch *ds, int port);
Guenter Roeckacdaffc2015-03-26 18:36:28 -070061int mv88e6xxx_setup_common(struct dsa_switch *ds);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000062int __mv88e6xxx_reg_read(struct mii_bus *bus, int sw_addr, int addr, int reg);
63int mv88e6xxx_reg_read(struct dsa_switch *ds, int addr, int reg);
64int __mv88e6xxx_reg_write(struct mii_bus *bus, int sw_addr, int addr,
Barry Grussling85686582013-01-08 16:05:56 +000065 int reg, u16 val);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000066int mv88e6xxx_reg_write(struct dsa_switch *ds, int addr, int reg, u16 val);
67int mv88e6xxx_config_prio(struct dsa_switch *ds);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000068int mv88e6xxx_set_addr_direct(struct dsa_switch *ds, u8 *addr);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000069int mv88e6xxx_set_addr_indirect(struct dsa_switch *ds, u8 *addr);
70int mv88e6xxx_phy_read(struct dsa_switch *ds, int addr, int regnum);
71int mv88e6xxx_phy_write(struct dsa_switch *ds, int addr, int regnum, u16 val);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000072void mv88e6xxx_ppu_state_init(struct dsa_switch *ds);
73int mv88e6xxx_phy_read_ppu(struct dsa_switch *ds, int addr, int regnum);
74int mv88e6xxx_phy_write_ppu(struct dsa_switch *ds, int addr,
75 int regnum, u16 val);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000076void mv88e6xxx_poll_link(struct dsa_switch *ds);
77void mv88e6xxx_get_strings(struct dsa_switch *ds,
78 int nr_stats, struct mv88e6xxx_hw_stat *stats,
79 int port, uint8_t *data);
80void mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds,
81 int nr_stats, struct mv88e6xxx_hw_stat *stats,
82 int port, uint64_t *data);
Guenter Roecka1ab91f2014-10-29 10:45:05 -070083int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port);
84void mv88e6xxx_get_regs(struct dsa_switch *ds, int port,
85 struct ethtool_regs *regs, void *_p);
Andrew Lunneaa23762014-11-15 22:24:51 +010086int mv88e6xxx_get_temp(struct dsa_switch *ds, int *temp);
Andrew Lunnf3044682015-02-14 19:17:50 +010087int mv88e6xxx_phy_wait(struct dsa_switch *ds);
88int mv88e6xxx_eeprom_load_wait(struct dsa_switch *ds);
89int mv88e6xxx_eeprom_busy_wait(struct dsa_switch *ds);
90int mv88e6xxx_phy_read_indirect(struct dsa_switch *ds, int addr, int regnum);
91int mv88e6xxx_phy_write_indirect(struct dsa_switch *ds, int addr, int regnum,
92 u16 val);
Guenter Roeck11b3b452015-03-06 22:23:51 -080093int mv88e6xxx_get_eee(struct dsa_switch *ds, int port, struct ethtool_eee *e);
94int mv88e6xxx_set_eee(struct dsa_switch *ds, int port,
95 struct phy_device *phydev, struct ethtool_eee *e);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000096
Ben Hutchings98e67302011-11-25 14:36:19 +000097extern struct dsa_switch_driver mv88e6131_switch_driver;
98extern struct dsa_switch_driver mv88e6123_61_65_switch_driver;
Guenter Roeck3ad50cc2014-10-29 10:44:56 -070099extern struct dsa_switch_driver mv88e6352_switch_driver;
Andrew Lunn42f27252014-09-12 23:58:44 +0200100extern struct dsa_switch_driver mv88e6171_switch_driver;
Ben Hutchings98e67302011-11-25 14:36:19 +0000101
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000102#define REG_READ(addr, reg) \
103 ({ \
104 int __ret; \
105 \
106 __ret = mv88e6xxx_reg_read(ds, addr, reg); \
107 if (__ret < 0) \
108 return __ret; \
109 __ret; \
110 })
111
112#define REG_WRITE(addr, reg, val) \
113 ({ \
114 int __ret; \
115 \
116 __ret = mv88e6xxx_reg_write(ds, addr, reg, val); \
117 if (__ret < 0) \
118 return __ret; \
119 })
120
121
122
123#endif