Root/target/linux/generic-2.6/files/include/linux/switch.h

1/*
2 * switch.h: Switch configuration API
3 *
4 * Copyright (C) 2008 Felix Fietkau <nbd@openwrt.org>
5 *
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.
10 *
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.
15 */
16
17#ifndef __LINUX_SWITCH_H
18#define __LINUX_SWITCH_H
19
20#include <linux/types.h>
21#include <linux/netdevice.h>
22#include <linux/netlink.h>
23#include <linux/genetlink.h>
24#ifndef __KERNEL__
25#include <netlink/netlink.h>
26#include <netlink/genl/genl.h>
27#include <netlink/genl/ctrl.h>
28#else
29#include <net/genetlink.h>
30#endif
31
32/* main attributes */
33enum {
34    SWITCH_ATTR_UNSPEC,
35    /* global */
36    SWITCH_ATTR_TYPE,
37    /* device */
38    SWITCH_ATTR_ID,
39    SWITCH_ATTR_NAME,
40    SWITCH_ATTR_DEV_NAME,
41    SWITCH_ATTR_VLANS,
42    SWITCH_ATTR_PORTS,
43    SWITCH_ATTR_CPU_PORT,
44    /* attributes */
45    SWITCH_ATTR_OP_ID,
46    SWITCH_ATTR_OP_TYPE,
47    SWITCH_ATTR_OP_NAME,
48    SWITCH_ATTR_OP_PORT,
49    SWITCH_ATTR_OP_VLAN,
50    SWITCH_ATTR_OP_VALUE_INT,
51    SWITCH_ATTR_OP_VALUE_STR,
52    SWITCH_ATTR_OP_VALUE_PORTS,
53    SWITCH_ATTR_OP_DESCRIPTION,
54    /* port lists */
55    SWITCH_ATTR_PORT,
56    SWITCH_ATTR_MAX
57};
58
59/* commands */
60enum {
61    SWITCH_CMD_UNSPEC,
62    SWITCH_CMD_GET_SWITCH,
63    SWITCH_CMD_NEW_ATTR,
64    SWITCH_CMD_LIST_GLOBAL,
65    SWITCH_CMD_GET_GLOBAL,
66    SWITCH_CMD_SET_GLOBAL,
67    SWITCH_CMD_LIST_PORT,
68    SWITCH_CMD_GET_PORT,
69    SWITCH_CMD_SET_PORT,
70    SWITCH_CMD_LIST_VLAN,
71    SWITCH_CMD_GET_VLAN,
72    SWITCH_CMD_SET_VLAN
73};
74
75/* data types */
76enum switch_val_type {
77    SWITCH_TYPE_UNSPEC,
78    SWITCH_TYPE_INT,
79    SWITCH_TYPE_STRING,
80    SWITCH_TYPE_PORTS,
81    SWITCH_TYPE_NOVAL,
82};
83
84/* port nested attributes */
85enum {
86    SWITCH_PORT_UNSPEC,
87    SWITCH_PORT_ID,
88    SWITCH_PORT_FLAG_TAGGED,
89    SWITCH_PORT_ATTR_MAX
90};
91
92#define SWITCH_ATTR_DEFAULTS_OFFSET 0x1000
93
94#ifdef __KERNEL__
95
96struct switch_dev;
97struct switch_op;
98struct switch_val;
99struct switch_attr;
100struct switch_attrlist;
101
102int register_switch(struct switch_dev *dev, struct net_device *netdev);
103void unregister_switch(struct switch_dev *dev);
104
105/**
106 * struct switch_attrlist - attribute list
107 *
108 * @n_attr: number of attributes
109 * @attr: pointer to the attributes array
110 */
111struct switch_attrlist {
112    int n_attr;
113    const struct switch_attr *attr;
114};
115
116/**
117 * struct switch_dev_ops - switch driver operations
118 *
119 * @attr_global: global switch attribute list
120 * @attr_port: port attribute list
121 * @attr_vlan: vlan attribute list
122 *
123 * Callbacks:
124 *
125 * @get_vlan_ports: read the port list of a VLAN
126 * @set_vlan_ports: set the port list of a VLAN
127 *
128 * @get_port_pvid: get the primary VLAN ID of a port
129 * @set_port_pvid: set the primary VLAN ID of a port
130 *
131 * @apply_config: apply all changed settings to the switch
132 * @reset_switch: resetting the switch
133 */
134struct switch_dev_ops {
135    struct switch_attrlist attr_global, attr_port, attr_vlan;
136
137    int (*get_vlan_ports)(struct switch_dev *dev, struct switch_val *val);
138    int (*set_vlan_ports)(struct switch_dev *dev, struct switch_val *val);
139
140    int (*get_port_pvid)(struct switch_dev *dev, int port, int *val);
141    int (*set_port_pvid)(struct switch_dev *dev, int port, int val);
142
143    int (*apply_config)(struct switch_dev *dev);
144    int (*reset_switch)(struct switch_dev *dev);
145};
146
147struct switch_dev {
148    const struct switch_dev_ops *ops;
149    const char *name;
150
151    /* NB: either devname or netdev must be set */
152    const char *devname;
153    struct net_device *netdev;
154
155    int ports;
156    int vlans;
157    int cpu_port;
158
159    /* the following fields are internal for swconfig */
160    int id;
161    struct list_head dev_list;
162    unsigned long def_global, def_port, def_vlan;
163
164    spinlock_t lock;
165    struct switch_port *portbuf;
166};
167
168struct switch_port {
169    u32 id;
170    u32 flags;
171};
172
173struct switch_val {
174    const struct switch_attr *attr;
175    int port_vlan;
176    int len;
177    union {
178        const char *s;
179        u32 i;
180        struct switch_port *ports;
181    } value;
182};
183
184struct switch_attr {
185    int disabled;
186    int type;
187    const char *name;
188    const char *description;
189
190    int (*set)(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val);
191    int (*get)(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val);
192
193    /* for driver internal use */
194    int id;
195    int ofs;
196    int max;
197};
198
199#endif
200
201#endif
202

Archive Download this file



interactive