Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 1 | /* |
| 2 | * include/net/dsa.h - Driver for Distributed Switch Architecture switch chips |
Lennert Buytenhek | e84665c | 2009-03-20 09:52:09 +0000 | [diff] [blame] | 3 | * Copyright (c) 2008-2009 Marvell Semiconductor |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 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 __LINUX_NET_DSA_H |
| 12 | #define __LINUX_NET_DSA_H |
| 13 | |
Ben Hutchings | c8f0b86 | 2011-11-27 17:06:08 +0000 | [diff] [blame^] | 14 | #include <linux/list.h> |
Ben Hutchings | cf50dcc | 2011-11-25 14:32:52 +0000 | [diff] [blame] | 15 | #include <linux/timer.h> |
| 16 | #include <linux/workqueue.h> |
| 17 | |
Lennert Buytenhek | e84665c | 2009-03-20 09:52:09 +0000 | [diff] [blame] | 18 | #define DSA_MAX_SWITCHES 4 |
| 19 | #define DSA_MAX_PORTS 12 |
| 20 | |
| 21 | struct dsa_chip_data { |
| 22 | /* |
| 23 | * How to access the switch configuration registers. |
| 24 | */ |
| 25 | struct device *mii_bus; |
| 26 | int sw_addr; |
| 27 | |
| 28 | /* |
| 29 | * The names of the switch's ports. Use "cpu" to |
| 30 | * designate the switch port that the cpu is connected to, |
| 31 | * "dsa" to indicate that this port is a DSA link to |
| 32 | * another switch, NULL to indicate the port is unused, |
| 33 | * or any other string to indicate this is a physical port. |
| 34 | */ |
| 35 | char *port_names[DSA_MAX_PORTS]; |
| 36 | |
| 37 | /* |
| 38 | * An array (with nr_chips elements) of which element [a] |
| 39 | * indicates which port on this switch should be used to |
| 40 | * send packets to that are destined for switch a. Can be |
| 41 | * NULL if there is only one switch chip. |
| 42 | */ |
| 43 | s8 *rtable; |
| 44 | }; |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 45 | |
| 46 | struct dsa_platform_data { |
| 47 | /* |
| 48 | * Reference to a Linux network interface that connects |
Lennert Buytenhek | e84665c | 2009-03-20 09:52:09 +0000 | [diff] [blame] | 49 | * to the root switch chip of the tree. |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 50 | */ |
| 51 | struct device *netdev; |
| 52 | |
| 53 | /* |
Lennert Buytenhek | e84665c | 2009-03-20 09:52:09 +0000 | [diff] [blame] | 54 | * Info structs describing each of the switch chips |
| 55 | * connected via this network interface. |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 56 | */ |
Lennert Buytenhek | e84665c | 2009-03-20 09:52:09 +0000 | [diff] [blame] | 57 | int nr_chips; |
| 58 | struct dsa_chip_data *chip; |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 59 | }; |
| 60 | |
Ben Hutchings | cf50dcc | 2011-11-25 14:32:52 +0000 | [diff] [blame] | 61 | struct dsa_switch_tree { |
| 62 | /* |
| 63 | * Configuration data for the platform device that owns |
| 64 | * this dsa switch tree instance. |
| 65 | */ |
| 66 | struct dsa_platform_data *pd; |
Lennert Buytenhek | cf85d08 | 2008-10-07 13:45:02 +0000 | [diff] [blame] | 67 | |
Ben Hutchings | cf50dcc | 2011-11-25 14:32:52 +0000 | [diff] [blame] | 68 | /* |
| 69 | * Reference to network device to use, and which tagging |
| 70 | * protocol to use. |
| 71 | */ |
| 72 | struct net_device *master_netdev; |
| 73 | __be16 tag_protocol; |
| 74 | |
| 75 | /* |
| 76 | * The switch and port to which the CPU is attached. |
| 77 | */ |
| 78 | s8 cpu_switch; |
| 79 | s8 cpu_port; |
| 80 | |
| 81 | /* |
| 82 | * Link state polling. |
| 83 | */ |
| 84 | int link_poll_needed; |
| 85 | struct work_struct link_poll_work; |
| 86 | struct timer_list link_poll_timer; |
| 87 | |
| 88 | /* |
| 89 | * Data for the individual switch chips. |
| 90 | */ |
| 91 | struct dsa_switch *ds[DSA_MAX_SWITCHES]; |
| 92 | }; |
| 93 | |
Ben Hutchings | c8f0b86 | 2011-11-27 17:06:08 +0000 | [diff] [blame^] | 94 | struct dsa_switch { |
| 95 | /* |
| 96 | * Parent switch tree, and switch index. |
| 97 | */ |
| 98 | struct dsa_switch_tree *dst; |
| 99 | int index; |
| 100 | |
| 101 | /* |
| 102 | * Configuration data for this switch. |
| 103 | */ |
| 104 | struct dsa_chip_data *pd; |
| 105 | |
| 106 | /* |
| 107 | * The used switch driver. |
| 108 | */ |
| 109 | struct dsa_switch_driver *drv; |
| 110 | |
| 111 | /* |
| 112 | * Reference to mii bus to use. |
| 113 | */ |
| 114 | struct mii_bus *master_mii_bus; |
| 115 | |
| 116 | /* |
| 117 | * Slave mii_bus and devices for the individual ports. |
| 118 | */ |
| 119 | u32 dsa_port_mask; |
| 120 | u32 phys_port_mask; |
| 121 | struct mii_bus *slave_mii_bus; |
| 122 | struct net_device *ports[DSA_MAX_PORTS]; |
| 123 | }; |
| 124 | |
| 125 | static inline bool dsa_is_cpu_port(struct dsa_switch *ds, int p) |
| 126 | { |
| 127 | return !!(ds->index == ds->dst->cpu_switch && p == ds->dst->cpu_port); |
| 128 | } |
| 129 | |
| 130 | static inline u8 dsa_upstream_port(struct dsa_switch *ds) |
| 131 | { |
| 132 | struct dsa_switch_tree *dst = ds->dst; |
| 133 | |
| 134 | /* |
| 135 | * If this is the root switch (i.e. the switch that connects |
| 136 | * to the CPU), return the cpu port number on this switch. |
| 137 | * Else return the (DSA) port number that connects to the |
| 138 | * switch that is one hop closer to the cpu. |
| 139 | */ |
| 140 | if (dst->cpu_switch == ds->index) |
| 141 | return dst->cpu_port; |
| 142 | else |
| 143 | return ds->pd->rtable[dst->cpu_switch]; |
| 144 | } |
| 145 | |
| 146 | struct dsa_switch_driver { |
| 147 | struct list_head list; |
| 148 | |
| 149 | __be16 tag_protocol; |
| 150 | int priv_size; |
| 151 | |
| 152 | /* |
| 153 | * Probing and setup. |
| 154 | */ |
| 155 | char *(*probe)(struct mii_bus *bus, int sw_addr); |
| 156 | int (*setup)(struct dsa_switch *ds); |
| 157 | int (*set_addr)(struct dsa_switch *ds, u8 *addr); |
| 158 | |
| 159 | /* |
| 160 | * Access to the switch's PHY registers. |
| 161 | */ |
| 162 | int (*phy_read)(struct dsa_switch *ds, int port, int regnum); |
| 163 | int (*phy_write)(struct dsa_switch *ds, int port, |
| 164 | int regnum, u16 val); |
| 165 | |
| 166 | /* |
| 167 | * Link state polling and IRQ handling. |
| 168 | */ |
| 169 | void (*poll_link)(struct dsa_switch *ds); |
| 170 | |
| 171 | /* |
| 172 | * ethtool hardware statistics. |
| 173 | */ |
| 174 | void (*get_strings)(struct dsa_switch *ds, int port, uint8_t *data); |
| 175 | void (*get_ethtool_stats)(struct dsa_switch *ds, |
| 176 | int port, uint64_t *data); |
| 177 | int (*get_sset_count)(struct dsa_switch *ds); |
| 178 | }; |
| 179 | |
| 180 | void register_switch_driver(struct dsa_switch_driver *type); |
| 181 | void unregister_switch_driver(struct dsa_switch_driver *type); |
| 182 | |
Ben Hutchings | cf50dcc | 2011-11-25 14:32:52 +0000 | [diff] [blame] | 183 | /* |
| 184 | * The original DSA tag format and some other tag formats have no |
| 185 | * ethertype, which means that we need to add a little hack to the |
| 186 | * networking receive path to make sure that received frames get |
| 187 | * the right ->protocol assigned to them when one of those tag |
| 188 | * formats is in use. |
| 189 | */ |
| 190 | static inline bool dsa_uses_dsa_tags(struct dsa_switch_tree *dst) |
| 191 | { |
| 192 | return !!(dst->tag_protocol == htons(ETH_P_DSA)); |
| 193 | } |
| 194 | |
| 195 | static inline bool dsa_uses_trailer_tags(struct dsa_switch_tree *dst) |
| 196 | { |
| 197 | return !!(dst->tag_protocol == htons(ETH_P_TRAILER)); |
| 198 | } |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 199 | |
| 200 | #endif |