mv88e6171.c 4.7 KB
Newer Older
1
/* net/dsa/mv88e6171.c - Marvell 88e6171 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 21 22
static const struct mv88e6xxx_info mv88e6171_table[] = {
	{
		.prod_num = PORT_SWITCH_ID_PROD_NUM_6171,
23
		.family = MV88E6XXX_FAMILY_6351,
24
		.name = "Marvell 88E6171",
25
		.num_databases = 4096,
26
		.num_ports = 7,
27
		.flags = MV88E6XXX_FLAGS_FAMILY_6351,
28 29
	}, {
		.prod_num = PORT_SWITCH_ID_PROD_NUM_6175,
30
		.family = MV88E6XXX_FAMILY_6351,
31
		.name = "Marvell 88E6175",
32
		.num_databases = 4096,
33
		.num_ports = 7,
34
		.flags = MV88E6XXX_FLAGS_FAMILY_6351,
35 36
	}, {
		.prod_num = PORT_SWITCH_ID_PROD_NUM_6350,
37
		.family = MV88E6XXX_FAMILY_6351,
38
		.name = "Marvell 88E6350",
39
		.num_databases = 4096,
40
		.num_ports = 7,
41
		.flags = MV88E6XXX_FLAGS_FAMILY_6351,
42 43
	}, {
		.prod_num = PORT_SWITCH_ID_PROD_NUM_6351,
44
		.family = MV88E6XXX_FAMILY_6351,
45
		.name = "Marvell 88E6351",
46
		.num_databases = 4096,
47
		.num_ports = 7,
48
		.flags = MV88E6XXX_FLAGS_FAMILY_6351,
49
	}
50 51
};

V
Vivien Didelot 已提交
52 53 54
static const char *mv88e6171_drv_probe(struct device *dsa_dev,
				       struct device *host_dev, int sw_addr,
				       void **priv)
55
{
56 57 58
	return mv88e6xxx_drv_probe(dsa_dev, host_dev, sw_addr, priv,
				   mv88e6171_table,
				   ARRAY_SIZE(mv88e6171_table));
59 60 61 62
}

static int mv88e6171_setup_global(struct dsa_switch *ds)
{
63
	struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
64
	u32 upstream_port = dsa_upstream_port(ds);
65
	int ret;
66
	u32 reg;
67 68 69 70

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

72 73
	/* Discard packets with excessive collisions, mask all
	 * interrupt sources, enable PPU.
74
	 */
75
	ret = mv88e6xxx_reg_write(ps, REG_GLOBAL, GLOBAL_CONTROL,
76 77 78 79
				  GLOBAL_CONTROL_PPU_ENABLE |
				  GLOBAL_CONTROL_DISCARD_EXCESS);
	if (ret)
		return ret;
80 81 82 83 84

	/* Configure the upstream port, and configure the upstream
	 * port as the port to which ingress and egress monitor frames
	 * are to be sent.
	 */
85 86 87 88
	reg = 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;
89
	ret = mv88e6xxx_reg_write(ps, REG_GLOBAL, GLOBAL_MONITOR_CONTROL, reg);
90 91
	if (ret)
		return ret;
92 93 94 95

	/* Disable remote management for now, and set the switch's
	 * DSA device number.
	 */
96
	return mv88e6xxx_reg_write(ps, REG_GLOBAL, GLOBAL_CONTROL_2,
97
				   ds->index & 0x1f);
98 99 100 101
}

static int mv88e6171_setup(struct dsa_switch *ds)
{
102
	struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
103 104
	int ret;

105 106 107
	ps->ds = ds;

	ret = mv88e6xxx_setup_common(ps);
108 109
	if (ret < 0)
		return ret;
110

111
	ret = mv88e6xxx_switch_reset(ps, true);
112 113 114 115 116 117 118
	if (ret < 0)
		return ret;

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

119
	return mv88e6xxx_setup_ports(ds);
120 121 122
}

struct dsa_switch_driver mv88e6171_switch_driver = {
123
	.tag_protocol		= DSA_TAG_PROTO_EDSA,
124
	.probe			= mv88e6171_drv_probe,
125 126
	.setup			= mv88e6171_setup,
	.set_addr		= mv88e6xxx_set_addr_indirect,
127 128
	.phy_read		= mv88e6xxx_phy_read,
	.phy_write		= mv88e6xxx_phy_write,
129 130 131
	.get_strings		= mv88e6xxx_get_strings,
	.get_ethtool_stats	= mv88e6xxx_get_ethtool_stats,
	.get_sset_count		= mv88e6xxx_get_sset_count,
132
	.adjust_link		= mv88e6xxx_adjust_link,
133 134
#ifdef CONFIG_NET_DSA_HWMON
	.get_temp               = mv88e6xxx_get_temp,
135 136 137
	.get_temp_limit		= mv88e6xxx_get_temp_limit,
	.set_temp_limit		= mv88e6xxx_set_temp_limit,
	.get_temp_alarm		= mv88e6xxx_get_temp_alarm,
138
#endif
139 140
	.get_eeprom		= mv88e6xxx_get_eeprom,
	.set_eeprom		= mv88e6xxx_set_eeprom,
141 142
	.get_regs_len		= mv88e6xxx_get_regs_len,
	.get_regs		= mv88e6xxx_get_regs,
143 144
	.port_bridge_join	= mv88e6xxx_port_bridge_join,
	.port_bridge_leave	= mv88e6xxx_port_bridge_leave,
145
	.port_stp_state_set	= mv88e6xxx_port_stp_state_set,
146
	.port_vlan_filtering	= mv88e6xxx_port_vlan_filtering,
147
	.port_vlan_prepare	= mv88e6xxx_port_vlan_prepare,
148 149
	.port_vlan_add		= mv88e6xxx_port_vlan_add,
	.port_vlan_del		= mv88e6xxx_port_vlan_del,
150
	.port_vlan_dump		= mv88e6xxx_port_vlan_dump,
V
Vivien Didelot 已提交
151
	.port_fdb_prepare	= mv88e6xxx_port_fdb_prepare,
152 153
	.port_fdb_add		= mv88e6xxx_port_fdb_add,
	.port_fdb_del		= mv88e6xxx_port_fdb_del,
154
	.port_fdb_dump		= mv88e6xxx_port_fdb_dump,
155 156 157
};

MODULE_ALIAS("platform:mv88e6171");
158 159 160
MODULE_ALIAS("platform:mv88e6175");
MODULE_ALIAS("platform:mv88e6350");
MODULE_ALIAS("platform:mv88e6351");