mv88e6171.c 4.3 KB
Newer Older
1
/* net/dsa/mv88e6171.c - Marvell 88e6171/8826172 switch chip support
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
 * Copyright (c) 2008-2009 Marvell Semiconductor
 * Copyright (c) 2014 Claudio Leite <leitec@staticky.com>
 *
 * 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.
 */

#include <linux/delay.h>
#include <linux/jiffies.h>
#include <linux/list.h>
#include <linux/module.h>
#include <linux/netdevice.h>
#include <linux/phy.h>
#include <net/dsa.h>
#include "mv88e6xxx.h"

20
static char *mv88e6171_probe(struct device *host_dev, int sw_addr)
21
{
22
	struct mii_bus *bus = dsa_host_dev_to_mii_bus(host_dev);
23 24
	int ret;

25 26 27
	if (bus == NULL)
		return NULL;

28
	ret = __mv88e6xxx_reg_read(bus, sw_addr, REG_PORT(0), PORT_SWITCH_ID);
29
	if (ret >= 0) {
30
		if ((ret & 0xfff0) == PORT_SWITCH_ID_6171)
31
			return "Marvell 88E6171";
32
		if ((ret & 0xfff0) == PORT_SWITCH_ID_6172)
33
			return "Marvell 88E6172";
34 35 36 37 38 39 40
	}

	return NULL;
}

static int mv88e6171_setup_global(struct dsa_switch *ds)
{
41
	u32 upstream_port = dsa_upstream_port(ds);
42
	int ret;
43 44 45 46

	ret = mv88e6xxx_setup_global(ds);
	if (ret)
		return ret;
47

48 49
	/* Discard packets with excessive collisions, mask all
	 * interrupt sources, enable PPU.
50
	 */
51 52
	REG_WRITE(REG_GLOBAL, GLOBAL_CONTROL,
		  GLOBAL_CONTROL_PPU_ENABLE | GLOBAL_CONTROL_DISCARD_EXCESS);
53 54 55 56 57

	/* Configure the upstream port, and configure the upstream
	 * port as the port to which ingress and egress monitor frames
	 * are to be sent.
	 */
58 59 60 61 62 63 64 65 66 67
	if (REG_READ(REG_PORT(0), PORT_SWITCH_ID) == PORT_SWITCH_ID_6171)
		REG_WRITE(REG_GLOBAL, GLOBAL_MONITOR_CONTROL,
			  upstream_port <<
			  GLOBAL_MONITOR_CONTROL_INGRESS_SHIFT |
			  upstream_port <<
			  GLOBAL_MONITOR_CONTROL_EGRESS_SHIFT |
			  upstream_port <<
			  GLOBAL_MONITOR_CONTROL_ARP_SHIFT |
			  upstream_port <<
			  GLOBAL_MONITOR_CONTROL_MIRROR_SHIFT);
68
	else
69 70 71 72 73 74 75
		REG_WRITE(REG_GLOBAL, GLOBAL_MONITOR_CONTROL,
			  upstream_port <<
			  GLOBAL_MONITOR_CONTROL_INGRESS_SHIFT |
			  upstream_port <<
			  GLOBAL_MONITOR_CONTROL_EGRESS_SHIFT |
			  upstream_port <<
			  GLOBAL_MONITOR_CONTROL_ARP_SHIFT);
76 77 78 79

	/* Disable remote management for now, and set the switch's
	 * DSA device number.
	 */
80
	REG_WRITE(REG_GLOBAL, GLOBAL_CONTROL_2, ds->index & 0x1f);
81 82 83 84 85 86

	return 0;
}

static int mv88e6171_setup(struct dsa_switch *ds)
{
87
	struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
88 89
	int ret;

90 91 92
	ret = mv88e6xxx_setup_common(ds);
	if (ret < 0)
		return ret;
93

94 95
	ps->num_ports = 7;

96
	ret = mv88e6xxx_switch_reset(ds, true);
97 98 99 100 101 102 103
	if (ret < 0)
		return ret;

	ret = mv88e6171_setup_global(ds);
	if (ret < 0)
		return ret;

104
	return mv88e6xxx_setup_ports(ds);
105 106
}

107 108 109 110 111
static int mv88e6171_get_eee(struct dsa_switch *ds, int port,
			     struct ethtool_eee *e)
{
	struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);

112
	if (ps->id == PORT_SWITCH_ID_6172)
113 114 115 116 117 118 119 120 121 122
		return mv88e6xxx_get_eee(ds, port, e);

	return -EOPNOTSUPP;
}

static int mv88e6171_set_eee(struct dsa_switch *ds, int port,
			     struct phy_device *phydev, struct ethtool_eee *e)
{
	struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);

123
	if (ps->id == PORT_SWITCH_ID_6172)
124 125 126 127 128
		return mv88e6xxx_set_eee(ds, port, phydev, e);

	return -EOPNOTSUPP;
}

129
struct dsa_switch_driver mv88e6171_switch_driver = {
130
	.tag_protocol		= DSA_TAG_PROTO_EDSA,
131 132 133 134
	.priv_size		= sizeof(struct mv88e6xxx_priv_state),
	.probe			= mv88e6171_probe,
	.setup			= mv88e6171_setup,
	.set_addr		= mv88e6xxx_set_addr_indirect,
135 136
	.phy_read		= mv88e6xxx_phy_read_indirect,
	.phy_write		= mv88e6xxx_phy_write_indirect,
137
	.poll_link		= mv88e6xxx_poll_link,
138 139 140
	.get_strings		= mv88e6xxx_get_strings,
	.get_ethtool_stats	= mv88e6xxx_get_ethtool_stats,
	.get_sset_count		= mv88e6xxx_get_sset_count,
141 142
	.set_eee		= mv88e6171_set_eee,
	.get_eee		= mv88e6171_get_eee,
143 144 145
#ifdef CONFIG_NET_DSA_HWMON
	.get_temp               = mv88e6xxx_get_temp,
#endif
146 147
	.get_regs_len		= mv88e6xxx_get_regs_len,
	.get_regs		= mv88e6xxx_get_regs,
148 149 150 151 152 153
	.port_join_bridge       = mv88e6xxx_join_bridge,
	.port_leave_bridge      = mv88e6xxx_leave_bridge,
	.port_stp_update        = mv88e6xxx_port_stp_update,
	.fdb_add		= mv88e6xxx_port_fdb_add,
	.fdb_del		= mv88e6xxx_port_fdb_del,
	.fdb_getnext		= mv88e6xxx_port_fdb_getnext,
154 155 156
};

MODULE_ALIAS("platform:mv88e6171");
157
MODULE_ALIAS("platform:mv88e6172");