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.
17 #ifndef __LINUX_SWITCH_H
18 #define __LINUX_SWITCH_H
20 #include <linux/types.h>
21 #include <linux/netdevice.h>
22 #include <linux/netlink.h>
23 #include <linux/genetlink.h>
25 #include <netlink/netlink.h>
26 #include <netlink/genl/genl.h>
27 #include <netlink/genl/ctrl.h>
29 #include <net/genetlink.h>
51 SWITCH_ATTR_OP_VALUE_INT
,
52 SWITCH_ATTR_OP_VALUE_STR
,
53 SWITCH_ATTR_OP_VALUE_PORTS
,
54 SWITCH_ATTR_OP_DESCRIPTION
,
63 SWITCH_CMD_GET_SWITCH
,
65 SWITCH_CMD_LIST_GLOBAL
,
66 SWITCH_CMD_GET_GLOBAL
,
67 SWITCH_CMD_SET_GLOBAL
,
77 enum switch_val_type
{
85 /* port nested attributes */
89 SWITCH_PORT_FLAG_TAGGED
,
93 #define SWITCH_ATTR_DEFAULTS_OFFSET 0x1000
101 struct switch_attrlist
;
103 int register_switch(struct switch_dev
*dev
, struct net_device
*netdev
);
104 void unregister_switch(struct switch_dev
*dev
);
107 * struct switch_attrlist - attribute list
109 * @n_attr: number of attributes
110 * @attr: pointer to the attributes array
112 struct switch_attrlist
{
114 const struct switch_attr
*attr
;
117 enum switch_port_speed
{
118 SWITCH_PORT_SPEED_UNKNOWN
= 0,
119 SWITCH_PORT_SPEED_10
= 10,
120 SWITCH_PORT_SPEED_100
= 100,
121 SWITCH_PORT_SPEED_1000
= 1000,
124 struct switch_port_link
{
130 enum switch_port_speed speed
;
133 struct switch_port_stats
{
134 unsigned long tx_bytes
;
135 unsigned long rx_bytes
;
139 * struct switch_dev_ops - switch driver operations
141 * @attr_global: global switch attribute list
142 * @attr_port: port attribute list
143 * @attr_vlan: vlan attribute list
147 * @get_vlan_ports: read the port list of a VLAN
148 * @set_vlan_ports: set the port list of a VLAN
150 * @get_port_pvid: get the primary VLAN ID of a port
151 * @set_port_pvid: set the primary VLAN ID of a port
153 * @apply_config: apply all changed settings to the switch
154 * @reset_switch: resetting the switch
156 struct switch_dev_ops
{
157 struct switch_attrlist attr_global
, attr_port
, attr_vlan
;
159 int (*get_vlan_ports
)(struct switch_dev
*dev
, struct switch_val
*val
);
160 int (*set_vlan_ports
)(struct switch_dev
*dev
, struct switch_val
*val
);
162 int (*get_port_pvid
)(struct switch_dev
*dev
, int port
, int *val
);
163 int (*set_port_pvid
)(struct switch_dev
*dev
, int port
, int val
);
165 int (*apply_config
)(struct switch_dev
*dev
);
166 int (*reset_switch
)(struct switch_dev
*dev
);
168 int (*get_port_link
)(struct switch_dev
*dev
, int port
,
169 struct switch_port_link
*link
);
170 int (*get_port_stats
)(struct switch_dev
*dev
, int port
,
171 struct switch_port_stats
*stats
);
175 const struct switch_dev_ops
*ops
;
176 /* will be automatically filled */
177 char devname
[IFNAMSIZ
];
180 /* NB: either alias or netdev must be set */
182 struct net_device
*netdev
;
188 /* the following fields are internal for swconfig */
190 struct list_head dev_list
;
191 unsigned long def_global
, def_port
, def_vlan
;
194 struct switch_port
*portbuf
;
203 const struct switch_attr
*attr
;
209 struct switch_port
*ports
;
217 const char *description
;
219 int (*set
)(struct switch_dev
*dev
, const struct switch_attr
*attr
, struct switch_val
*val
);
220 int (*get
)(struct switch_dev
*dev
, const struct switch_attr
*attr
, struct switch_val
*val
);
222 /* for driver internal use */