2 * net/dsa/dsa_priv.h - Hardware switch handling
3 * Copyright (c) 2008-2009 Marvell Semiconductor
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.
14 #include <linux/list.h>
15 #include <linux/phy.h>
16 #include <linux/timer.h>
17 #include <linux/workqueue.h>
22 * Parent switch tree, and switch index.
24 struct dsa_switch_tree
*dst
;
28 * Configuration data for this switch.
30 struct dsa_chip_data
*pd
;
33 * The used switch driver.
35 struct dsa_switch_driver
*drv
;
38 * Reference to mii bus to use.
40 struct mii_bus
*master_mii_bus
;
43 * Slave mii_bus and devices for the individual ports.
47 struct mii_bus
*slave_mii_bus
;
48 struct net_device
*ports
[DSA_MAX_PORTS
];
51 struct dsa_switch_tree
{
53 * Configuration data for the platform device that owns
54 * this dsa switch tree instance.
56 struct dsa_platform_data
*pd
;
59 * Reference to network device to use, and which tagging
62 struct net_device
*master_netdev
;
66 * The switch and port to which the CPU is attached.
75 struct work_struct link_poll_work
;
76 struct timer_list link_poll_timer
;
79 * Data for the individual switch chips.
81 struct dsa_switch
*ds
[DSA_MAX_SWITCHES
];
84 static inline bool dsa_is_cpu_port(struct dsa_switch
*ds
, int p
)
86 return !!(ds
->index
== ds
->dst
->cpu_switch
&& p
== ds
->dst
->cpu_port
);
89 static inline u8
dsa_upstream_port(struct dsa_switch
*ds
)
91 struct dsa_switch_tree
*dst
= ds
->dst
;
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.
99 if (dst
->cpu_switch
== ds
->index
)
100 return dst
->cpu_port
;
102 return ds
->pd
->rtable
[dst
->cpu_switch
];
105 struct dsa_slave_priv
{
107 * The linux network interface corresponding to this
110 struct net_device
*dev
;
113 * Which switch this port is a part of, and the port index
116 struct dsa_switch
*parent
;
120 * The phylib phy_device pointer for the PHY connected
123 struct phy_device
*phy
;
126 struct dsa_switch_driver
{
127 struct list_head list
;
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
);
140 * Access to the switch's PHY registers.
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
);
147 * Link state polling and IRQ handling.
149 void (*poll_link
)(struct dsa_switch
*ds
);
152 * ethtool hardware statistics.
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
);
161 extern char dsa_driver_version
[];
162 void register_switch_driver(struct dsa_switch_driver
*type
);
163 void unregister_switch_driver(struct dsa_switch_driver
*type
);
166 void dsa_slave_mii_bus_init(struct dsa_switch
*ds
);
167 struct net_device
*dsa_slave_create(struct dsa_switch
*ds
,
168 struct device
*parent
,
169 int port
, char *name
);
172 netdev_tx_t
dsa_xmit(struct sk_buff
*skb
, struct net_device
*dev
);
175 netdev_tx_t
edsa_xmit(struct sk_buff
*skb
, struct net_device
*dev
);
178 netdev_tx_t
trailer_xmit(struct sk_buff
*skb
, struct net_device
*dev
);