~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/include/net/dsa.h

Version: ~ [ linux-5.15-rc5 ] ~ [ linux-5.14.11 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.72 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.152 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.210 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.250 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.286 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.288 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.18.140 ] ~ [ linux-3.16.85 ] ~ [ linux-3.14.79 ] ~ [ linux-3.12.74 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

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

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp