Blame view
include/linux/if_team.h
7.49 KB
3d249d4ca
|
1 2 3 4 5 6 7 8 9 |
/* * include/linux/if_team.h - Network team device driver header * Copyright (c) 2011 Jiri Pirko <jpirko@redhat.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. */ |
3d249d4ca
|
10 11 |
#ifndef _LINUX_IF_TEAM_H_ #define _LINUX_IF_TEAM_H_ |
bd2d0837a
|
12 |
#include <linux/netpoll.h> |
6c85f2bdd
|
13 |
#include <net/sch_generic.h> |
fc423ff00
|
14 |
#include <linux/types.h> |
607ca46e9
|
15 |
#include <uapi/linux/if_team.h> |
bd2d0837a
|
16 |
|
3d249d4ca
|
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
struct team_pcpu_stats { u64 rx_packets; u64 rx_bytes; u64 rx_multicast; u64 tx_packets; u64 tx_bytes; struct u64_stats_sync syncp; u32 rx_dropped; u32 tx_dropped; }; struct team; struct team_port { struct net_device *dev; |
19a0b58e5
|
32 |
struct hlist_node hlist; /* node in enabled ports hash list */ |
3d249d4ca
|
33 34 |
struct list_head list; /* node in ordinary list */ struct team *team; |
19a0b58e5
|
35 |
int index; /* index of enabled port. If disabled, it's set to -1 */ |
3d249d4ca
|
36 |
|
71472ec12
|
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
bool linkup; /* either state.linkup or user.linkup */ struct { bool linkup; u32 speed; u8 duplex; } state; /* Values set by userspace */ struct { bool linkup; bool linkup_enabled; } user; /* Custom gennetlink interface related flags */ bool changed; bool removed; |
3d249d4ca
|
54 55 56 57 58 59 60 61 |
/* * A place for storing original values of the device before it * become a port. */ struct { unsigned char dev_addr[MAX_ADDR_LEN]; unsigned int mtu; } orig; |
bd2d0837a
|
62 63 64 |
#ifdef CONFIG_NET_POLL_CONTROLLER struct netpoll *np; #endif |
a86fc6b7d
|
65 |
s32 priority; /* lower number ~ higher priority */ |
8ff5105a2
|
66 67 |
u16 queue_id; struct list_head qom_list; /* node in queue override mapping list */ |
d80b35bea
|
68 |
struct rcu_head rcu; |
5149ee583
|
69 |
long mode_priv[0]; |
3d249d4ca
|
70 |
}; |
68c450426
|
71 72 73 74 75 76 77 78 79 |
static inline bool team_port_enabled(struct team_port *port) { return port->index != -1; } static inline bool team_port_txable(struct team_port *port) { return port->linkup && team_port_enabled(port); } |
52a4fd778
|
80 |
|
bd2d0837a
|
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
#ifdef CONFIG_NET_POLL_CONTROLLER static inline void team_netpoll_send_skb(struct team_port *port, struct sk_buff *skb) { struct netpoll *np = port->np; if (np) netpoll_send_skb(np, skb); } #else static inline void team_netpoll_send_skb(struct team_port *port, struct sk_buff *skb) { } #endif |
3d249d4ca
|
96 97 98 99 100 101 102 103 104 |
struct team_mode_ops { int (*init)(struct team *team); void (*exit)(struct team *team); rx_handler_result_t (*receive)(struct team *team, struct team_port *port, struct sk_buff *skb); bool (*transmit)(struct team *team, struct sk_buff *skb); int (*port_enter)(struct team *team, struct team_port *port); void (*port_leave)(struct team *team, struct team_port *port); |
1d76efe15
|
105 |
void (*port_change_dev_addr)(struct team *team, struct team_port *port); |
4bccfd17e
|
106 107 |
void (*port_enabled)(struct team *team, struct team_port *port); void (*port_disabled)(struct team *team, struct team_port *port); |
3d249d4ca
|
108 |
}; |
acbba0d0f
|
109 110 111 |
extern int team_modeop_port_enter(struct team *team, struct team_port *port); extern void team_modeop_port_change_dev_addr(struct team *team, struct team_port *port); |
3d249d4ca
|
112 113 114 |
enum team_option_type { TEAM_OPTION_TYPE_U32, TEAM_OPTION_TYPE_STRING, |
2615598fc
|
115 |
TEAM_OPTION_TYPE_BINARY, |
14f066bab
|
116 |
TEAM_OPTION_TYPE_BOOL, |
69821638b
|
117 |
TEAM_OPTION_TYPE_S32, |
3d249d4ca
|
118 |
}; |
85d59a872
|
119 120 121 122 |
struct team_option_inst_info { u32 array_index; struct team_port *port; /* != NULL if per-port */ }; |
80f7c6683
|
123 124 125 126 127 128 129 130 |
struct team_gsetter_ctx { union { u32 u32_val; const char *str_val; struct { const void *ptr; u32 len; } bin_val; |
14f066bab
|
131 |
bool bool_val; |
69821638b
|
132 |
s32 s32_val; |
80f7c6683
|
133 |
} data; |
85d59a872
|
134 |
struct team_option_inst_info *info; |
80f7c6683
|
135 |
}; |
3d249d4ca
|
136 137 138 |
struct team_option { struct list_head list; const char *name; |
80f7c6683
|
139 |
bool per_port; |
b13033262
|
140 |
unsigned int array_size; /* != 0 means the option is array */ |
3d249d4ca
|
141 |
enum team_option_type type; |
85d59a872
|
142 |
int (*init)(struct team *team, struct team_option_inst_info *info); |
80f7c6683
|
143 144 |
int (*getter)(struct team *team, struct team_gsetter_ctx *ctx); int (*setter)(struct team *team, struct team_gsetter_ctx *ctx); |
3d249d4ca
|
145 |
}; |
0f1aad2b7
|
146 147 |
extern void team_option_inst_set_change(struct team_option_inst_info *opt_inst_info); extern void team_options_change_check(struct team *team); |
3d249d4ca
|
148 |
struct team_mode { |
3d249d4ca
|
149 150 151 |
const char *kind; struct module *owner; size_t priv_size; |
5149ee583
|
152 |
size_t port_priv_size; |
3d249d4ca
|
153 154 155 156 157 158 159 160 161 162 163 164 |
const struct team_mode_ops *ops; }; #define TEAM_PORT_HASHBITS 4 #define TEAM_PORT_HASHENTRIES (1 << TEAM_PORT_HASHBITS) #define TEAM_MODE_PRIV_LONGS 4 #define TEAM_MODE_PRIV_SIZE (sizeof(long) * TEAM_MODE_PRIV_LONGS) struct team { struct net_device *dev; /* associated netdevice */ struct team_pcpu_stats __percpu *pcpu_stats; |
61dc3461b
|
165 |
struct mutex lock; /* used for overall locking, e.g. port lists write */ |
3d249d4ca
|
166 167 |
/* |
19a0b58e5
|
168 |
* List of enabled ports and their count |
3d249d4ca
|
169 |
*/ |
19a0b58e5
|
170 171 172 173 |
int en_port_count; struct hlist_head en_port_hlist[TEAM_PORT_HASHENTRIES]; struct list_head port_list; /* list of all ports */ |
3d249d4ca
|
174 175 |
struct list_head option_list; |
80f7c6683
|
176 |
struct list_head option_inst_list; /* list of option instances */ |
3d249d4ca
|
177 178 179 |
const struct team_mode *mode; struct team_mode_ops ops; |
e185483e6
|
180 |
bool user_carrier_enabled; |
8ff5105a2
|
181 182 |
bool queue_override_enabled; struct list_head *qom_lists; /* array of queue override mapping lists */ |
fc423ff00
|
183 184 185 186 187 188 |
struct { unsigned int count; unsigned int interval; /* in ms */ atomic_t count_pending; struct delayed_work dw; } notify_peers; |
492b200ef
|
189 190 191 192 193 194 |
struct { unsigned int count; unsigned int interval; /* in ms */ atomic_t count_pending; struct delayed_work dw; } mcast_rejoin; |
3d249d4ca
|
195 196 |
long mode_priv[TEAM_MODE_PRIV_LONGS]; }; |
e15c3c229
|
197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
static inline int team_dev_queue_xmit(struct team *team, struct team_port *port, struct sk_buff *skb) { BUILD_BUG_ON(sizeof(skb->queue_mapping) != sizeof(qdisc_skb_cb(skb)->slave_dev_queue_mapping)); skb_set_queue_mapping(skb, qdisc_skb_cb(skb)->slave_dev_queue_mapping); skb->dev = port->dev; if (unlikely(netpoll_tx_running(team->dev))) { team_netpoll_send_skb(port, skb); return 0; } return dev_queue_xmit(skb); } |
3d249d4ca
|
211 212 213 |
static inline struct hlist_head *team_port_index_hash(struct team *team, int port_index) { |
19a0b58e5
|
214 |
return &team->en_port_hlist[port_index & (TEAM_PORT_HASHENTRIES - 1)]; |
3d249d4ca
|
215 216 217 218 219 |
} static inline struct team_port *team_get_port_by_index(struct team *team, int port_index) { |
3d249d4ca
|
220 221 |
struct team_port *port; struct hlist_head *head = team_port_index_hash(team, port_index); |
b67bfe0d4
|
222 |
hlist_for_each_entry(port, head, hlist) |
3d249d4ca
|
223 224 225 226 |
if (port->index == port_index) return port; return NULL; } |
735d381fa
|
227 228 229 230 231 232 233 234 235 |
static inline int team_num_to_port_index(struct team *team, int num) { int en_port_count = ACCESS_ONCE(team->en_port_count); if (unlikely(!en_port_count)) return 0; return num % en_port_count; } |
3d249d4ca
|
236 237 238 |
static inline struct team_port *team_get_port_by_index_rcu(struct team *team, int port_index) { |
3d249d4ca
|
239 240 |
struct team_port *port; struct hlist_head *head = team_port_index_hash(team, port_index); |
b67bfe0d4
|
241 |
hlist_for_each_entry_rcu(port, head, hlist) |
3d249d4ca
|
242 243 244 245 |
if (port->index == port_index) return port; return NULL; } |
753f99391
|
246 247 248 249 250 251 252 253 254 |
static inline struct team_port * team_get_first_port_txable_rcu(struct team *team, struct team_port *port) { struct team_port *cur; if (likely(team_port_txable(port))) return port; cur = port; list_for_each_entry_continue_rcu(cur, &team->port_list, list) |
b79462a8b
|
255 |
if (team_port_txable(cur)) |
753f99391
|
256 257 258 259 |
return cur; list_for_each_entry_rcu(cur, &team->port_list, list) { if (cur == port) break; |
b79462a8b
|
260 |
if (team_port_txable(cur)) |
753f99391
|
261 262 263 264 |
return cur; } return NULL; } |
358b83829
|
265 266 267 |
extern int team_options_register(struct team *team, const struct team_option *option, size_t option_count); |
3d249d4ca
|
268 |
extern void team_options_unregister(struct team *team, |
358b83829
|
269 |
const struct team_option *option, |
3d249d4ca
|
270 |
size_t option_count); |
0402788a6
|
271 272 |
extern int team_mode_register(const struct team_mode *mode); extern void team_mode_unregister(const struct team_mode *mode); |
3d249d4ca
|
273 |
|
6c85f2bdd
|
274 275 |
#define TEAM_DEFAULT_NUM_TX_QUEUES 16 #define TEAM_DEFAULT_NUM_RX_QUEUES 16 |
3d249d4ca
|
276 |
#endif /* _LINUX_IF_TEAM_H_ */ |