Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 1 | /* |
| 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 Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame^] | 18 | /* 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 Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 32 | struct mv88e6xxx_priv_state { |
Barry Grussling | 3675c8d | 2013-01-08 16:05:53 +0000 | [diff] [blame] | 33 | /* When using multi-chip addressing, this mutex protects |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 34 | * access to the indirect access registers. (In single-chip |
| 35 | * mode, this mutex is effectively useless.) |
| 36 | */ |
| 37 | struct mutex smi_mutex; |
| 38 | |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 39 | #ifdef CONFIG_NET_DSA_MV88E6XXX_NEED_PPU |
Barry Grussling | 3675c8d | 2013-01-08 16:05:53 +0000 | [diff] [blame] | 40 | /* Handles automatic disabling and re-enabling of the PHY |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 41 | * 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 Grussling | 3675c8d | 2013-01-08 16:05:53 +0000 | [diff] [blame] | 49 | /* This mutex serialises access to the statistics unit. |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 50 | * Hold this mutex over snapshot + dump sequences. |
| 51 | */ |
| 52 | struct mutex stats_mutex; |
Peter Korsgaard | ec80bfc | 2011-04-05 03:03:56 +0000 | [diff] [blame] | 53 | |
Guenter Roeck | 3ad50cc | 2014-10-29 10:44:56 -0700 | [diff] [blame] | 54 | /* 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 Roeck | 33b43df | 2014-10-29 10:45:03 -0700 | [diff] [blame] | 60 | /* This mutex serializes eeprom access for chips with |
| 61 | * eeprom support. |
| 62 | */ |
| 63 | struct mutex eeprom_mutex; |
| 64 | |
Peter Korsgaard | ec80bfc | 2011-04-05 03:03:56 +0000 | [diff] [blame] | 65 | int id; /* switch product id */ |
Guenter Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame^] | 66 | |
| 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 Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 77 | }; |
| 78 | |
| 79 | struct mv88e6xxx_hw_stat { |
| 80 | char string[ETH_GSTRING_LEN]; |
| 81 | int sizeof_stat; |
| 82 | int reg; |
| 83 | }; |
| 84 | |
Guenter Roeck | d827e88 | 2015-03-26 18:36:29 -0700 | [diff] [blame] | 85 | int mv88e6xxx_setup_port_common(struct dsa_switch *ds, int port); |
Guenter Roeck | acdaffc | 2015-03-26 18:36:28 -0700 | [diff] [blame] | 86 | int mv88e6xxx_setup_common(struct dsa_switch *ds); |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 87 | int __mv88e6xxx_reg_read(struct mii_bus *bus, int sw_addr, int addr, int reg); |
| 88 | int mv88e6xxx_reg_read(struct dsa_switch *ds, int addr, int reg); |
| 89 | int __mv88e6xxx_reg_write(struct mii_bus *bus, int sw_addr, int addr, |
Barry Grussling | 8568658 | 2013-01-08 16:05:56 +0000 | [diff] [blame] | 90 | int reg, u16 val); |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 91 | int mv88e6xxx_reg_write(struct dsa_switch *ds, int addr, int reg, u16 val); |
| 92 | int mv88e6xxx_config_prio(struct dsa_switch *ds); |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 93 | int mv88e6xxx_set_addr_direct(struct dsa_switch *ds, u8 *addr); |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 94 | int mv88e6xxx_set_addr_indirect(struct dsa_switch *ds, u8 *addr); |
| 95 | int mv88e6xxx_phy_read(struct dsa_switch *ds, int addr, int regnum); |
| 96 | int mv88e6xxx_phy_write(struct dsa_switch *ds, int addr, int regnum, u16 val); |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 97 | void mv88e6xxx_ppu_state_init(struct dsa_switch *ds); |
| 98 | int mv88e6xxx_phy_read_ppu(struct dsa_switch *ds, int addr, int regnum); |
| 99 | int mv88e6xxx_phy_write_ppu(struct dsa_switch *ds, int addr, |
| 100 | int regnum, u16 val); |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 101 | void mv88e6xxx_poll_link(struct dsa_switch *ds); |
| 102 | void mv88e6xxx_get_strings(struct dsa_switch *ds, |
| 103 | int nr_stats, struct mv88e6xxx_hw_stat *stats, |
| 104 | int port, uint8_t *data); |
| 105 | void mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds, |
| 106 | int nr_stats, struct mv88e6xxx_hw_stat *stats, |
| 107 | int port, uint64_t *data); |
Guenter Roeck | a1ab91f | 2014-10-29 10:45:05 -0700 | [diff] [blame] | 108 | int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port); |
| 109 | void mv88e6xxx_get_regs(struct dsa_switch *ds, int port, |
| 110 | struct ethtool_regs *regs, void *_p); |
Andrew Lunn | eaa2376 | 2014-11-15 22:24:51 +0100 | [diff] [blame] | 111 | int mv88e6xxx_get_temp(struct dsa_switch *ds, int *temp); |
Andrew Lunn | f304468 | 2015-02-14 19:17:50 +0100 | [diff] [blame] | 112 | int mv88e6xxx_phy_wait(struct dsa_switch *ds); |
| 113 | int mv88e6xxx_eeprom_load_wait(struct dsa_switch *ds); |
| 114 | int mv88e6xxx_eeprom_busy_wait(struct dsa_switch *ds); |
| 115 | int mv88e6xxx_phy_read_indirect(struct dsa_switch *ds, int addr, int regnum); |
| 116 | int mv88e6xxx_phy_write_indirect(struct dsa_switch *ds, int addr, int regnum, |
| 117 | u16 val); |
Guenter Roeck | 11b3b45 | 2015-03-06 22:23:51 -0800 | [diff] [blame] | 118 | int mv88e6xxx_get_eee(struct dsa_switch *ds, int port, struct ethtool_eee *e); |
| 119 | int mv88e6xxx_set_eee(struct dsa_switch *ds, int port, |
| 120 | struct phy_device *phydev, struct ethtool_eee *e); |
Guenter Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame^] | 121 | int mv88e6xxx_join_bridge(struct dsa_switch *ds, int port, u32 br_port_mask); |
| 122 | int mv88e6xxx_leave_bridge(struct dsa_switch *ds, int port, u32 br_port_mask); |
| 123 | int mv88e6xxx_port_stp_update(struct dsa_switch *ds, int port, u8 state); |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 124 | |
Ben Hutchings | 98e6730 | 2011-11-25 14:36:19 +0000 | [diff] [blame] | 125 | extern struct dsa_switch_driver mv88e6131_switch_driver; |
| 126 | extern struct dsa_switch_driver mv88e6123_61_65_switch_driver; |
Guenter Roeck | 3ad50cc | 2014-10-29 10:44:56 -0700 | [diff] [blame] | 127 | extern struct dsa_switch_driver mv88e6352_switch_driver; |
Andrew Lunn | 42f2725 | 2014-09-12 23:58:44 +0200 | [diff] [blame] | 128 | extern struct dsa_switch_driver mv88e6171_switch_driver; |
Ben Hutchings | 98e6730 | 2011-11-25 14:36:19 +0000 | [diff] [blame] | 129 | |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 130 | #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 |