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
105struct switch_attrlist {
106    /* filled in by the driver */
107    int n_attr;
108    const struct switch_attr *attr;
109};
110
111
112struct switch_dev {
113    int id;
114    void *priv;
115    const char *name;
116
117    /* NB: either devname or netdev must be set */
118    const char *devname;
119    struct net_device *netdev;
120
121    int ports;
122    int vlans;
123    int cpu_port;
124    struct switch_attrlist attr_global, attr_port, attr_vlan;
125
126    spinlock_t lock;
127    struct switch_port *portbuf;
128    struct list_head dev_list;
129    unsigned long def_global, def_port, def_vlan;
130
131    int (*get_vlan_ports)(struct switch_dev *dev, struct switch_val *val);
132    int (*set_vlan_ports)(struct switch_dev *dev, struct switch_val *val);
133    int (*get_port_pvid)(struct switch_dev *dev, int port, int *val);
134    int (*set_port_pvid)(struct switch_dev *dev, int port, int val);
135    int (*apply_config)(struct switch_dev *dev);
136    int (*reset_switch)(struct switch_dev *dev);
137};
138
139struct switch_port {
140    u32 id;
141    u32 flags;
142};
143
144struct switch_val {
145    const struct switch_attr *attr;
146    int port_vlan;
147    int len;
148    union {
149        const char *s;
150        u32 i;
151        struct switch_port *ports;
152    } value;
153};
154
155struct switch_attr {
156    int disabled;
157    int type;
158    const char *name;
159    const char *description;
160
161    int (*set)(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val);
162    int (*get)(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val);
163
164    /* for driver internal use */
165    int id;
166    int ofs;
167    int max;
168};
169
170#endif
171
172#endif
173

Archive Download this file



interactive