Linux Audio

Check our new training course

Embedded Linux training

Mar 10-20, 2025, special US time zones
Register
Loading...
v3.1
  1/*
  2 * net/dsa/dsa_priv.h - Hardware switch handling
  3 * Copyright (c) 2008-2009 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 __DSA_PRIV_H
 12#define __DSA_PRIV_H
 13
 14#include <linux/list.h>
 15#include <linux/phy.h>
 16#include <linux/timer.h>
 17#include <linux/workqueue.h>
 18#include <net/dsa.h>
 19
 20struct dsa_switch {
 21	/*
 22	 * Parent switch tree, and switch index.
 23	 */
 24	struct dsa_switch_tree	*dst;
 25	int			index;
 26
 27	/*
 28	 * Configuration data for this switch.
 29	 */
 30	struct dsa_chip_data	*pd;
 31
 32	/*
 33	 * The used switch driver.
 34	 */
 35	struct dsa_switch_driver	*drv;
 36
 37	/*
 38	 * Reference to mii bus to use.
 39	 */
 40	struct mii_bus		*master_mii_bus;
 41
 42	/*
 43	 * Slave mii_bus and devices for the individual ports.
 44	 */
 45	u32			dsa_port_mask;
 46	u32			phys_port_mask;
 47	struct mii_bus		*slave_mii_bus;
 48	struct net_device	*ports[DSA_MAX_PORTS];
 49};
 50
 51struct dsa_switch_tree {
 52	/*
 53	 * Configuration data for the platform device that owns
 54	 * this dsa switch tree instance.
 55	 */
 56	struct dsa_platform_data	*pd;
 57
 58	/*
 59	 * Reference to network device to use, and which tagging
 60	 * protocol to use.
 61	 */
 62	struct net_device	*master_netdev;
 63	__be16			tag_protocol;
 64
 65	/*
 66	 * The switch and port to which the CPU is attached.
 67	 */
 68	s8			cpu_switch;
 69	s8			cpu_port;
 70
 71	/*
 72	 * Link state polling.
 73	 */
 74	int			link_poll_needed;
 75	struct work_struct	link_poll_work;
 76	struct timer_list	link_poll_timer;
 77
 78	/*
 79	 * Data for the individual switch chips.
 80	 */
 81	struct dsa_switch	*ds[DSA_MAX_SWITCHES];
 82};
 83
 84static inline bool dsa_is_cpu_port(struct dsa_switch *ds, int p)
 85{
 86	return !!(ds->index == ds->dst->cpu_switch && p == ds->dst->cpu_port);
 87}
 88
 89static inline u8 dsa_upstream_port(struct dsa_switch *ds)
 90{
 91	struct dsa_switch_tree *dst = ds->dst;
 92
 93	/*
 94	 * If this is the root switch (i.e. the switch that connects
 95	 * to the CPU), return the cpu port number on this switch.
 96	 * Else return the (DSA) port number that connects to the
 97	 * switch that is one hop closer to the cpu.
 98	 */
 99	if (dst->cpu_switch == ds->index)
100		return dst->cpu_port;
101	else
102		return ds->pd->rtable[dst->cpu_switch];
103}
104
105struct dsa_slave_priv {
106	/*
107	 * The linux network interface corresponding to this
108	 * switch port.
109	 */
110	struct net_device	*dev;
111
112	/*
113	 * Which switch this port is a part of, and the port index
114	 * for this port.
115	 */
116	struct dsa_switch	*parent;
117	u8			port;
118
119	/*
120	 * The phylib phy_device pointer for the PHY connected
121	 * to this port.
122	 */
123	struct phy_device	*phy;
124};
125
126struct dsa_switch_driver {
127	struct list_head	list;
128
129	__be16			tag_protocol;
130	int			priv_size;
131
132	/*
133	 * Probing and setup.
134	 */
135	char	*(*probe)(struct mii_bus *bus, int sw_addr);
136	int	(*setup)(struct dsa_switch *ds);
137	int	(*set_addr)(struct dsa_switch *ds, u8 *addr);
138
139	/*
140	 * Access to the switch's PHY registers.
141	 */
142	int	(*phy_read)(struct dsa_switch *ds, int port, int regnum);
143	int	(*phy_write)(struct dsa_switch *ds, int port,
144			     int regnum, u16 val);
145
146	/*
147	 * Link state polling and IRQ handling.
148	 */
149	void	(*poll_link)(struct dsa_switch *ds);
150
151	/*
152	 * ethtool hardware statistics.
153	 */
154	void	(*get_strings)(struct dsa_switch *ds, int port, uint8_t *data);
155	void	(*get_ethtool_stats)(struct dsa_switch *ds,
156				     int port, uint64_t *data);
157	int	(*get_sset_count)(struct dsa_switch *ds);
158};
159
160/* dsa.c */
161extern char dsa_driver_version[];
162void register_switch_driver(struct dsa_switch_driver *type);
163void unregister_switch_driver(struct dsa_switch_driver *type);
 
 
 
 
164
165/* slave.c */
 
166void dsa_slave_mii_bus_init(struct dsa_switch *ds);
167struct net_device *dsa_slave_create(struct dsa_switch *ds,
168				    struct device *parent,
169				    int port, char *name);
 
 
 
 
 
170
171/* tag_dsa.c */
172netdev_tx_t dsa_xmit(struct sk_buff *skb, struct net_device *dev);
173
174/* tag_edsa.c */
175netdev_tx_t edsa_xmit(struct sk_buff *skb, struct net_device *dev);
176
177/* tag_trailer.c */
178netdev_tx_t trailer_xmit(struct sk_buff *skb, struct net_device *dev);
 
 
 
179
 
 
180
181#endif
v4.10.11
 1/*
 2 * net/dsa/dsa_priv.h - Hardware switch handling
 3 * Copyright (c) 2008-2009 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 __DSA_PRIV_H
12#define __DSA_PRIV_H
13
 
14#include <linux/phy.h>
15#include <linux/netdevice.h>
16#include <linux/netpoll.h>
 
17
18struct dsa_device_ops {
19	struct sk_buff *(*xmit)(struct sk_buff *skb, struct net_device *dev);
20	int (*rcv)(struct sk_buff *skb, struct net_device *dev,
21		   struct packet_type *pt, struct net_device *orig_dev);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22};
23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24struct dsa_slave_priv {
25	struct sk_buff *	(*xmit)(struct sk_buff *skb,
26					struct net_device *dev);
 
 
 
27
28	/*
29	 * Which switch this port is a part of, and the port index
30	 * for this port.
31	 */
32	struct dsa_switch	*parent;
33	u8			port;
34
35	/*
36	 * The phylib phy_device pointer for the PHY connected
37	 * to this port.
38	 */
39	struct phy_device	*phy;
40	phy_interface_t		phy_interface;
41	int			old_link;
42	int			old_pause;
43	int			old_duplex;
44
45	struct net_device	*bridge_dev;
46#ifdef CONFIG_NET_POLL_CONTROLLER
47	struct netpoll		*netpoll;
48#endif
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49};
50
51/* dsa.c */
52extern char dsa_driver_version[];
53int dsa_cpu_dsa_setup(struct dsa_switch *ds, struct device *dev,
54		      struct device_node *port_dn, int port);
55void dsa_cpu_dsa_destroy(struct device_node *port_dn);
56const struct dsa_device_ops *dsa_resolve_tag_protocol(int tag_protocol);
57int dsa_cpu_port_ethtool_setup(struct dsa_switch *ds);
58void dsa_cpu_port_ethtool_restore(struct dsa_switch *ds);
59
60/* slave.c */
61extern const struct dsa_device_ops notag_netdev_ops;
62void dsa_slave_mii_bus_init(struct dsa_switch *ds);
63void dsa_cpu_port_ethtool_init(struct ethtool_ops *ops);
64int dsa_slave_create(struct dsa_switch *ds, struct device *parent,
65		     int port, const char *name);
66void dsa_slave_destroy(struct net_device *slave_dev);
67int dsa_slave_suspend(struct net_device *slave_dev);
68int dsa_slave_resume(struct net_device *slave_dev);
69int dsa_slave_netdevice_event(struct notifier_block *unused,
70			      unsigned long event, void *ptr);
71
72/* tag_dsa.c */
73extern const struct dsa_device_ops dsa_netdev_ops;
74
75/* tag_edsa.c */
76extern const struct dsa_device_ops edsa_netdev_ops;
77
78/* tag_trailer.c */
79extern const struct dsa_device_ops trailer_netdev_ops;
80
81/* tag_brcm.c */
82extern const struct dsa_device_ops brcm_netdev_ops;
83
84/* tag_qca.c */
85extern const struct dsa_device_ops qca_netdev_ops;
86
87#endif