Jiri Pirko | 3d249d4 | 2011-11-11 22:16:48 +0000 | [diff] [blame] | 1 | /* |
| 2 | * include/linux/if_team.h - Network team device driver header |
| 3 | * Copyright (c) 2011 Jiri Pirko <jpirko@redhat.com> |
| 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_IF_TEAM_H_ |
| 12 | #define _LINUX_IF_TEAM_H_ |
| 13 | |
| 14 | #ifdef __KERNEL__ |
| 15 | |
| 16 | struct team_pcpu_stats { |
| 17 | u64 rx_packets; |
| 18 | u64 rx_bytes; |
| 19 | u64 rx_multicast; |
| 20 | u64 tx_packets; |
| 21 | u64 tx_bytes; |
| 22 | struct u64_stats_sync syncp; |
| 23 | u32 rx_dropped; |
| 24 | u32 tx_dropped; |
| 25 | }; |
| 26 | |
| 27 | struct team; |
| 28 | |
| 29 | struct team_port { |
| 30 | struct net_device *dev; |
| 31 | struct hlist_node hlist; /* node in hash list */ |
| 32 | struct list_head list; /* node in ordinary list */ |
| 33 | struct team *team; |
| 34 | int index; |
| 35 | |
| 36 | /* |
| 37 | * A place for storing original values of the device before it |
| 38 | * become a port. |
| 39 | */ |
| 40 | struct { |
| 41 | unsigned char dev_addr[MAX_ADDR_LEN]; |
| 42 | unsigned int mtu; |
| 43 | } orig; |
| 44 | |
| 45 | bool linkup; |
| 46 | u32 speed; |
| 47 | u8 duplex; |
| 48 | |
Jiri Pirko | b82b918 | 2012-01-24 05:16:00 +0000 | [diff] [blame] | 49 | /* Custom gennetlink interface related flags */ |
| 50 | bool changed; |
| 51 | bool removed; |
| 52 | |
Jiri Pirko | 3d249d4 | 2011-11-11 22:16:48 +0000 | [diff] [blame] | 53 | struct rcu_head rcu; |
| 54 | }; |
| 55 | |
| 56 | struct team_mode_ops { |
| 57 | int (*init)(struct team *team); |
| 58 | void (*exit)(struct team *team); |
| 59 | rx_handler_result_t (*receive)(struct team *team, |
| 60 | struct team_port *port, |
| 61 | struct sk_buff *skb); |
| 62 | bool (*transmit)(struct team *team, struct sk_buff *skb); |
| 63 | int (*port_enter)(struct team *team, struct team_port *port); |
| 64 | void (*port_leave)(struct team *team, struct team_port *port); |
| 65 | void (*port_change_mac)(struct team *team, struct team_port *port); |
| 66 | }; |
| 67 | |
| 68 | enum team_option_type { |
| 69 | TEAM_OPTION_TYPE_U32, |
| 70 | TEAM_OPTION_TYPE_STRING, |
Jiri Pirko | 2615598 | 2012-04-04 12:16:26 +0000 | [diff] [blame^] | 71 | TEAM_OPTION_TYPE_BINARY, |
Jiri Pirko | 3d249d4 | 2011-11-11 22:16:48 +0000 | [diff] [blame] | 72 | }; |
| 73 | |
| 74 | struct team_option { |
| 75 | struct list_head list; |
| 76 | const char *name; |
| 77 | enum team_option_type type; |
| 78 | int (*getter)(struct team *team, void *arg); |
| 79 | int (*setter)(struct team *team, void *arg); |
Jiri Pirko | b82b918 | 2012-01-24 05:16:00 +0000 | [diff] [blame] | 80 | |
| 81 | /* Custom gennetlink interface related flags */ |
| 82 | bool changed; |
| 83 | bool removed; |
Jiri Pirko | 3d249d4 | 2011-11-11 22:16:48 +0000 | [diff] [blame] | 84 | }; |
| 85 | |
Jiri Pirko | 2615598 | 2012-04-04 12:16:26 +0000 | [diff] [blame^] | 86 | struct team_option_binary { |
| 87 | u32 data_len; |
| 88 | void *data; |
| 89 | }; |
| 90 | |
| 91 | #define team_optarg_tbinary(arg) (*((struct team_option_binary **) arg)) |
| 92 | |
Jiri Pirko | 3d249d4 | 2011-11-11 22:16:48 +0000 | [diff] [blame] | 93 | struct team_mode { |
| 94 | struct list_head list; |
| 95 | const char *kind; |
| 96 | struct module *owner; |
| 97 | size_t priv_size; |
| 98 | const struct team_mode_ops *ops; |
| 99 | }; |
| 100 | |
| 101 | #define TEAM_PORT_HASHBITS 4 |
| 102 | #define TEAM_PORT_HASHENTRIES (1 << TEAM_PORT_HASHBITS) |
| 103 | |
| 104 | #define TEAM_MODE_PRIV_LONGS 4 |
| 105 | #define TEAM_MODE_PRIV_SIZE (sizeof(long) * TEAM_MODE_PRIV_LONGS) |
| 106 | |
| 107 | struct team { |
| 108 | struct net_device *dev; /* associated netdevice */ |
| 109 | struct team_pcpu_stats __percpu *pcpu_stats; |
| 110 | |
Jiri Pirko | 61dc346 | 2011-11-16 11:09:08 +0000 | [diff] [blame] | 111 | struct mutex lock; /* used for overall locking, e.g. port lists write */ |
Jiri Pirko | 3d249d4 | 2011-11-11 22:16:48 +0000 | [diff] [blame] | 112 | |
| 113 | /* |
| 114 | * port lists with port count |
| 115 | */ |
| 116 | int port_count; |
| 117 | struct hlist_head port_hlist[TEAM_PORT_HASHENTRIES]; |
| 118 | struct list_head port_list; |
| 119 | |
| 120 | struct list_head option_list; |
| 121 | |
| 122 | const struct team_mode *mode; |
| 123 | struct team_mode_ops ops; |
| 124 | long mode_priv[TEAM_MODE_PRIV_LONGS]; |
| 125 | }; |
| 126 | |
| 127 | static inline struct hlist_head *team_port_index_hash(struct team *team, |
| 128 | int port_index) |
| 129 | { |
| 130 | return &team->port_hlist[port_index & (TEAM_PORT_HASHENTRIES - 1)]; |
| 131 | } |
| 132 | |
| 133 | static inline struct team_port *team_get_port_by_index(struct team *team, |
| 134 | int port_index) |
| 135 | { |
| 136 | struct hlist_node *p; |
| 137 | struct team_port *port; |
| 138 | struct hlist_head *head = team_port_index_hash(team, port_index); |
| 139 | |
| 140 | hlist_for_each_entry(port, p, head, hlist) |
| 141 | if (port->index == port_index) |
| 142 | return port; |
| 143 | return NULL; |
| 144 | } |
| 145 | static inline struct team_port *team_get_port_by_index_rcu(struct team *team, |
| 146 | int port_index) |
| 147 | { |
| 148 | struct hlist_node *p; |
| 149 | struct team_port *port; |
| 150 | struct hlist_head *head = team_port_index_hash(team, port_index); |
| 151 | |
| 152 | hlist_for_each_entry_rcu(port, p, head, hlist) |
| 153 | if (port->index == port_index) |
| 154 | return port; |
| 155 | return NULL; |
| 156 | } |
| 157 | |
| 158 | extern int team_port_set_team_mac(struct team_port *port); |
Jiri Pirko | 358b838 | 2011-11-16 11:09:09 +0000 | [diff] [blame] | 159 | extern int team_options_register(struct team *team, |
| 160 | const struct team_option *option, |
| 161 | size_t option_count); |
Jiri Pirko | 3d249d4 | 2011-11-11 22:16:48 +0000 | [diff] [blame] | 162 | extern void team_options_unregister(struct team *team, |
Jiri Pirko | 358b838 | 2011-11-16 11:09:09 +0000 | [diff] [blame] | 163 | const struct team_option *option, |
Jiri Pirko | 3d249d4 | 2011-11-11 22:16:48 +0000 | [diff] [blame] | 164 | size_t option_count); |
| 165 | extern int team_mode_register(struct team_mode *mode); |
| 166 | extern int team_mode_unregister(struct team_mode *mode); |
| 167 | |
| 168 | #endif /* __KERNEL__ */ |
| 169 | |
| 170 | #define TEAM_STRING_MAX_LEN 32 |
| 171 | |
| 172 | /********************************** |
| 173 | * NETLINK_GENERIC netlink family. |
| 174 | **********************************/ |
| 175 | |
| 176 | enum { |
| 177 | TEAM_CMD_NOOP, |
| 178 | TEAM_CMD_OPTIONS_SET, |
| 179 | TEAM_CMD_OPTIONS_GET, |
| 180 | TEAM_CMD_PORT_LIST_GET, |
| 181 | |
| 182 | __TEAM_CMD_MAX, |
| 183 | TEAM_CMD_MAX = (__TEAM_CMD_MAX - 1), |
| 184 | }; |
| 185 | |
| 186 | enum { |
| 187 | TEAM_ATTR_UNSPEC, |
| 188 | TEAM_ATTR_TEAM_IFINDEX, /* u32 */ |
| 189 | TEAM_ATTR_LIST_OPTION, /* nest */ |
| 190 | TEAM_ATTR_LIST_PORT, /* nest */ |
| 191 | |
| 192 | __TEAM_ATTR_MAX, |
| 193 | TEAM_ATTR_MAX = __TEAM_ATTR_MAX - 1, |
| 194 | }; |
| 195 | |
| 196 | /* Nested layout of get/set msg: |
| 197 | * |
| 198 | * [TEAM_ATTR_LIST_OPTION] |
| 199 | * [TEAM_ATTR_ITEM_OPTION] |
| 200 | * [TEAM_ATTR_OPTION_*], ... |
| 201 | * [TEAM_ATTR_ITEM_OPTION] |
| 202 | * [TEAM_ATTR_OPTION_*], ... |
| 203 | * ... |
| 204 | * [TEAM_ATTR_LIST_PORT] |
| 205 | * [TEAM_ATTR_ITEM_PORT] |
| 206 | * [TEAM_ATTR_PORT_*], ... |
| 207 | * [TEAM_ATTR_ITEM_PORT] |
| 208 | * [TEAM_ATTR_PORT_*], ... |
| 209 | * ... |
| 210 | */ |
| 211 | |
| 212 | enum { |
| 213 | TEAM_ATTR_ITEM_OPTION_UNSPEC, |
| 214 | TEAM_ATTR_ITEM_OPTION, /* nest */ |
| 215 | |
| 216 | __TEAM_ATTR_ITEM_OPTION_MAX, |
| 217 | TEAM_ATTR_ITEM_OPTION_MAX = __TEAM_ATTR_ITEM_OPTION_MAX - 1, |
| 218 | }; |
| 219 | |
| 220 | enum { |
| 221 | TEAM_ATTR_OPTION_UNSPEC, |
| 222 | TEAM_ATTR_OPTION_NAME, /* string */ |
| 223 | TEAM_ATTR_OPTION_CHANGED, /* flag */ |
| 224 | TEAM_ATTR_OPTION_TYPE, /* u8 */ |
| 225 | TEAM_ATTR_OPTION_DATA, /* dynamic */ |
Jiri Pirko | b82b918 | 2012-01-24 05:16:00 +0000 | [diff] [blame] | 226 | TEAM_ATTR_OPTION_REMOVED, /* flag */ |
Jiri Pirko | 3d249d4 | 2011-11-11 22:16:48 +0000 | [diff] [blame] | 227 | |
| 228 | __TEAM_ATTR_OPTION_MAX, |
| 229 | TEAM_ATTR_OPTION_MAX = __TEAM_ATTR_OPTION_MAX - 1, |
| 230 | }; |
| 231 | |
| 232 | enum { |
| 233 | TEAM_ATTR_ITEM_PORT_UNSPEC, |
| 234 | TEAM_ATTR_ITEM_PORT, /* nest */ |
| 235 | |
| 236 | __TEAM_ATTR_ITEM_PORT_MAX, |
| 237 | TEAM_ATTR_ITEM_PORT_MAX = __TEAM_ATTR_ITEM_PORT_MAX - 1, |
| 238 | }; |
| 239 | |
| 240 | enum { |
| 241 | TEAM_ATTR_PORT_UNSPEC, |
| 242 | TEAM_ATTR_PORT_IFINDEX, /* u32 */ |
| 243 | TEAM_ATTR_PORT_CHANGED, /* flag */ |
| 244 | TEAM_ATTR_PORT_LINKUP, /* flag */ |
| 245 | TEAM_ATTR_PORT_SPEED, /* u32 */ |
| 246 | TEAM_ATTR_PORT_DUPLEX, /* u8 */ |
Jiri Pirko | b82b918 | 2012-01-24 05:16:00 +0000 | [diff] [blame] | 247 | TEAM_ATTR_PORT_REMOVED, /* flag */ |
Jiri Pirko | 3d249d4 | 2011-11-11 22:16:48 +0000 | [diff] [blame] | 248 | |
| 249 | __TEAM_ATTR_PORT_MAX, |
| 250 | TEAM_ATTR_PORT_MAX = __TEAM_ATTR_PORT_MAX - 1, |
| 251 | }; |
| 252 | |
| 253 | /* |
| 254 | * NETLINK_GENERIC related info |
| 255 | */ |
| 256 | #define TEAM_GENL_NAME "team" |
| 257 | #define TEAM_GENL_VERSION 0x1 |
| 258 | #define TEAM_GENL_CHANGE_EVENT_MC_GRP_NAME "change_event" |
| 259 | |
| 260 | #endif /* _LINUX_IF_TEAM_H_ */ |