2 * switch.h: Switch configuration API
4 * Copyright (C) 2008 Felix Fietkau <nbd@openwrt.org>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 #ifndef _LINUX_SWITCH_H
17 #define _LINUX_SWITCH_H
19 #include <net/genetlink.h>
20 #include <uapi/linux/switch.h>
26 struct switch_attrlist
;
27 struct switch_led_trigger
;
29 int register_switch(struct switch_dev
*dev
, struct net_device
*netdev
);
30 void unregister_switch(struct switch_dev
*dev
);
33 * struct switch_attrlist - attribute list
35 * @n_attr: number of attributes
36 * @attr: pointer to the attributes array
38 struct switch_attrlist
{
40 const struct switch_attr
*attr
;
43 enum switch_port_speed
{
44 SWITCH_PORT_SPEED_UNKNOWN
= 0,
45 SWITCH_PORT_SPEED_10
= 10,
46 SWITCH_PORT_SPEED_100
= 100,
47 SWITCH_PORT_SPEED_1000
= 1000,
50 struct switch_port_link
{
56 enum switch_port_speed speed
;
59 struct switch_port_stats
{
60 unsigned long tx_bytes
;
61 unsigned long rx_bytes
;
65 * struct switch_dev_ops - switch driver operations
67 * @attr_global: global switch attribute list
68 * @attr_port: port attribute list
69 * @attr_vlan: vlan attribute list
73 * @get_vlan_ports: read the port list of a VLAN
74 * @set_vlan_ports: set the port list of a VLAN
76 * @get_port_pvid: get the primary VLAN ID of a port
77 * @set_port_pvid: set the primary VLAN ID of a port
79 * @apply_config: apply all changed settings to the switch
80 * @reset_switch: resetting the switch
82 struct switch_dev_ops
{
83 struct switch_attrlist attr_global
, attr_port
, attr_vlan
;
85 int (*get_vlan_ports
)(struct switch_dev
*dev
, struct switch_val
*val
);
86 int (*set_vlan_ports
)(struct switch_dev
*dev
, struct switch_val
*val
);
88 int (*get_port_pvid
)(struct switch_dev
*dev
, int port
, int *val
);
89 int (*set_port_pvid
)(struct switch_dev
*dev
, int port
, int val
);
91 int (*apply_config
)(struct switch_dev
*dev
);
92 int (*reset_switch
)(struct switch_dev
*dev
);
94 int (*get_port_link
)(struct switch_dev
*dev
, int port
,
95 struct switch_port_link
*link
);
96 int (*get_port_stats
)(struct switch_dev
*dev
, int port
,
97 struct switch_port_stats
*stats
);
101 struct device_node
*of_node
;
102 const struct switch_dev_ops
*ops
;
103 /* will be automatically filled */
104 char devname
[IFNAMSIZ
];
107 /* NB: either alias or netdev must be set */
109 struct net_device
*netdev
;
115 /* the following fields are internal for swconfig */
117 struct list_head dev_list
;
118 unsigned long def_global
, def_port
, def_vlan
;
120 struct mutex sw_mutex
;
121 struct switch_port
*portbuf
;
122 struct switch_portmap
*portmap
;
126 #ifdef CONFIG_SWCONFIG_LEDS
127 struct switch_led_trigger
*led_trigger
;
136 struct switch_portmap
{
142 const struct switch_attr
*attr
;
148 struct switch_port
*ports
;
156 const char *description
;
158 int (*set
)(struct switch_dev
*dev
, const struct switch_attr
*attr
, struct switch_val
*val
);
159 int (*get
)(struct switch_dev
*dev
, const struct switch_attr
*attr
, struct switch_val
*val
);
161 /* for driver internal use */
167 #endif /* _LINUX_SWITCH_H */