^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * drivers/net/team/team.c - Network team device driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (c) 2011 Jiri Pirko <jpirko@redhat.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/rcupdate.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/ctype.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/notifier.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/netpoll.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/if_vlan.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/if_arp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/socket.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/etherdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/rtnetlink.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <net/rtnetlink.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <net/genetlink.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <net/netlink.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <net/sch_generic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <generated/utsrelease.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <linux/if_team.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #define DRV_NAME "team"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) /**********
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) * Helpers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) **********/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) static struct team_port *team_port_get_rtnl(const struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) struct team_port *port = rtnl_dereference(dev->rx_handler_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) return netif_is_team_port(dev) ? port : NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) * Since the ability to change device address for open port device is tested in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) * team_port_add, this function can be called without control of return value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) static int __set_port_dev_addr(struct net_device *port_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) const unsigned char *dev_addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) struct sockaddr_storage addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) memcpy(addr.__data, dev_addr, port_dev->addr_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) addr.ss_family = port_dev->type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) return dev_set_mac_address(port_dev, (struct sockaddr *)&addr, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) static int team_port_set_orig_dev_addr(struct team_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) return __set_port_dev_addr(port->dev, port->orig.dev_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) static int team_port_set_team_dev_addr(struct team *team,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) struct team_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) return __set_port_dev_addr(port->dev, team->dev->dev_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) int team_modeop_port_enter(struct team *team, struct team_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) return team_port_set_team_dev_addr(team, port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) EXPORT_SYMBOL(team_modeop_port_enter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) void team_modeop_port_change_dev_addr(struct team *team,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) struct team_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) team_port_set_team_dev_addr(team, port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) EXPORT_SYMBOL(team_modeop_port_change_dev_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) static void team_lower_state_changed(struct team_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) struct netdev_lag_lower_state_info info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) info.link_up = port->linkup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) info.tx_enabled = team_port_enabled(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) netdev_lower_state_changed(port->dev, &info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) static void team_refresh_port_linkup(struct team_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) bool new_linkup = port->user.linkup_enabled ? port->user.linkup :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) port->state.linkup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) if (port->linkup != new_linkup) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) port->linkup = new_linkup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) team_lower_state_changed(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) /*******************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) * Options handling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) *******************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) struct team_option_inst { /* One for each option instance */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) struct list_head list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) struct list_head tmp_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) struct team_option *option;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) struct team_option_inst_info info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) bool changed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) bool removed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) static struct team_option *__team_find_option(struct team *team,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) const char *opt_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) struct team_option *option;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) list_for_each_entry(option, &team->option_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) if (strcmp(option->name, opt_name) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) return option;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) static void __team_option_inst_del(struct team_option_inst *opt_inst)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) list_del(&opt_inst->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) kfree(opt_inst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) static void __team_option_inst_del_option(struct team *team,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) struct team_option *option)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) struct team_option_inst *opt_inst, *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) list_for_each_entry_safe(opt_inst, tmp, &team->option_inst_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) if (opt_inst->option == option)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) __team_option_inst_del(opt_inst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) static int __team_option_inst_add(struct team *team, struct team_option *option,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) struct team_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) struct team_option_inst *opt_inst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) unsigned int array_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) array_size = option->array_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) if (!array_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) array_size = 1; /* No array but still need one instance */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) for (i = 0; i < array_size; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) opt_inst = kmalloc(sizeof(*opt_inst), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) if (!opt_inst)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) opt_inst->option = option;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) opt_inst->info.port = port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) opt_inst->info.array_index = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) opt_inst->changed = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) opt_inst->removed = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) list_add_tail(&opt_inst->list, &team->option_inst_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) if (option->init) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) err = option->init(team, &opt_inst->info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) static int __team_option_inst_add_option(struct team *team,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) struct team_option *option)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) if (!option->per_port) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) err = __team_option_inst_add(team, option, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) goto inst_del_option;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) inst_del_option:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) __team_option_inst_del_option(team, option);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) static void __team_option_inst_mark_removed_option(struct team *team,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) struct team_option *option)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) struct team_option_inst *opt_inst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) list_for_each_entry(opt_inst, &team->option_inst_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) if (opt_inst->option == option) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) opt_inst->changed = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) opt_inst->removed = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) static void __team_option_inst_del_port(struct team *team,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) struct team_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) struct team_option_inst *opt_inst, *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) list_for_each_entry_safe(opt_inst, tmp, &team->option_inst_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) if (opt_inst->option->per_port &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) opt_inst->info.port == port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) __team_option_inst_del(opt_inst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) static int __team_option_inst_add_port(struct team *team,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) struct team_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) struct team_option *option;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) list_for_each_entry(option, &team->option_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) if (!option->per_port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) err = __team_option_inst_add(team, option, port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) goto inst_del_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) inst_del_port:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) __team_option_inst_del_port(team, port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) static void __team_option_inst_mark_removed_port(struct team *team,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) struct team_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) struct team_option_inst *opt_inst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) list_for_each_entry(opt_inst, &team->option_inst_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) if (opt_inst->info.port == port) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) opt_inst->changed = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) opt_inst->removed = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) static int __team_options_register(struct team *team,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) const struct team_option *option,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) size_t option_count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) struct team_option **dst_opts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) dst_opts = kcalloc(option_count, sizeof(struct team_option *),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) if (!dst_opts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) for (i = 0; i < option_count; i++, option++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) if (__team_find_option(team, option->name)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) err = -EEXIST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) goto alloc_rollback;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) dst_opts[i] = kmemdup(option, sizeof(*option), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) if (!dst_opts[i]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) goto alloc_rollback;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) for (i = 0; i < option_count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) err = __team_option_inst_add_option(team, dst_opts[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) goto inst_rollback;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) list_add_tail(&dst_opts[i]->list, &team->option_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) kfree(dst_opts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) inst_rollback:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) for (i--; i >= 0; i--)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) __team_option_inst_del_option(team, dst_opts[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) i = option_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) alloc_rollback:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) for (i--; i >= 0; i--)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) kfree(dst_opts[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) kfree(dst_opts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) static void __team_options_mark_removed(struct team *team,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) const struct team_option *option,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) size_t option_count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) for (i = 0; i < option_count; i++, option++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) struct team_option *del_opt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) del_opt = __team_find_option(team, option->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) if (del_opt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) __team_option_inst_mark_removed_option(team, del_opt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) static void __team_options_unregister(struct team *team,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) const struct team_option *option,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) size_t option_count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) for (i = 0; i < option_count; i++, option++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) struct team_option *del_opt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) del_opt = __team_find_option(team, option->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) if (del_opt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) __team_option_inst_del_option(team, del_opt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) list_del(&del_opt->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) kfree(del_opt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) static void __team_options_change_check(struct team *team);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) int team_options_register(struct team *team,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) const struct team_option *option,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) size_t option_count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) err = __team_options_register(team, option, option_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) __team_options_change_check(team);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) EXPORT_SYMBOL(team_options_register);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) void team_options_unregister(struct team *team,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) const struct team_option *option,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) size_t option_count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) __team_options_mark_removed(team, option, option_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) __team_options_change_check(team);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) __team_options_unregister(team, option, option_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) EXPORT_SYMBOL(team_options_unregister);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) static int team_option_get(struct team *team,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) struct team_option_inst *opt_inst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) struct team_gsetter_ctx *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) if (!opt_inst->option->getter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) return opt_inst->option->getter(team, ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) static int team_option_set(struct team *team,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) struct team_option_inst *opt_inst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) struct team_gsetter_ctx *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) if (!opt_inst->option->setter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) return opt_inst->option->setter(team, ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) void team_option_inst_set_change(struct team_option_inst_info *opt_inst_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) struct team_option_inst *opt_inst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) opt_inst = container_of(opt_inst_info, struct team_option_inst, info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) opt_inst->changed = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) EXPORT_SYMBOL(team_option_inst_set_change);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) void team_options_change_check(struct team *team)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) __team_options_change_check(team);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) EXPORT_SYMBOL(team_options_change_check);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) /****************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) * Mode handling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) ****************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) static LIST_HEAD(mode_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) static DEFINE_SPINLOCK(mode_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) struct team_mode_item {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) struct list_head list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) const struct team_mode *mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) static struct team_mode_item *__find_mode(const char *kind)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) struct team_mode_item *mitem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) list_for_each_entry(mitem, &mode_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) if (strcmp(mitem->mode->kind, kind) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) return mitem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) static bool is_good_mode_name(const char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) while (*name != '\0') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) if (!isalpha(*name) && !isdigit(*name) && *name != '_')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) name++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) int team_mode_register(const struct team_mode *mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) struct team_mode_item *mitem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) if (!is_good_mode_name(mode->kind) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) mode->priv_size > TEAM_MODE_PRIV_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) mitem = kmalloc(sizeof(*mitem), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) if (!mitem)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) spin_lock(&mode_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) if (__find_mode(mode->kind)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) err = -EEXIST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) kfree(mitem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) goto unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) mitem->mode = mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) list_add_tail(&mitem->list, &mode_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) spin_unlock(&mode_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) EXPORT_SYMBOL(team_mode_register);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) void team_mode_unregister(const struct team_mode *mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) struct team_mode_item *mitem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) spin_lock(&mode_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) mitem = __find_mode(mode->kind);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) if (mitem) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) list_del_init(&mitem->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) kfree(mitem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) spin_unlock(&mode_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) EXPORT_SYMBOL(team_mode_unregister);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) static const struct team_mode *team_mode_get(const char *kind)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) struct team_mode_item *mitem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) const struct team_mode *mode = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) if (!try_module_get(THIS_MODULE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) spin_lock(&mode_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) mitem = __find_mode(kind);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) if (!mitem) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) spin_unlock(&mode_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) request_module("team-mode-%s", kind);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) spin_lock(&mode_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) mitem = __find_mode(kind);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) if (mitem) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) mode = mitem->mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) if (!try_module_get(mode->owner))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) mode = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) spin_unlock(&mode_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) module_put(THIS_MODULE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) return mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) static void team_mode_put(const struct team_mode *mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) module_put(mode->owner);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) static bool team_dummy_transmit(struct team *team, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) dev_kfree_skb_any(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) static rx_handler_result_t team_dummy_receive(struct team *team,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) struct team_port *port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) return RX_HANDLER_ANOTHER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) static const struct team_mode __team_no_mode = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) .kind = "*NOMODE*",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) static bool team_is_mode_set(struct team *team)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) return team->mode != &__team_no_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) static void team_set_no_mode(struct team *team)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) team->user_carrier_enabled = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) team->mode = &__team_no_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) static void team_adjust_ops(struct team *team)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) * To avoid checks in rx/tx skb paths, ensure here that non-null and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) * correct ops are always set.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) if (!team->en_port_count || !team_is_mode_set(team) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) !team->mode->ops->transmit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) team->ops.transmit = team_dummy_transmit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) team->ops.transmit = team->mode->ops->transmit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) if (!team->en_port_count || !team_is_mode_set(team) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) !team->mode->ops->receive)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) team->ops.receive = team_dummy_receive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) team->ops.receive = team->mode->ops->receive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) * We can benefit from the fact that it's ensured no port is present
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) * at the time of mode change. Therefore no packets are in fly so there's no
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) * need to set mode operations in any special way.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) static int __team_change_mode(struct team *team,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) const struct team_mode *new_mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) /* Check if mode was previously set and do cleanup if so */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) if (team_is_mode_set(team)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) void (*exit_op)(struct team *team) = team->ops.exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) /* Clear ops area so no callback is called any longer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) memset(&team->ops, 0, sizeof(struct team_mode_ops));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) team_adjust_ops(team);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) if (exit_op)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) exit_op(team);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) team_mode_put(team->mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) team_set_no_mode(team);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) /* zero private data area */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) memset(&team->mode_priv, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) sizeof(struct team) - offsetof(struct team, mode_priv));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) if (!new_mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) if (new_mode->ops->init) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) err = new_mode->ops->init(team);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) team->mode = new_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) memcpy(&team->ops, new_mode->ops, sizeof(struct team_mode_ops));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) team_adjust_ops(team);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) static int team_change_mode(struct team *team, const char *kind)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) const struct team_mode *new_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) struct net_device *dev = team->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) if (!list_empty(&team->port_list)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) netdev_err(dev, "No ports can be present during mode change\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) if (team_is_mode_set(team) && strcmp(team->mode->kind, kind) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) netdev_err(dev, "Unable to change to the same mode the team is in\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) new_mode = team_mode_get(kind);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) if (!new_mode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) netdev_err(dev, "Mode \"%s\" not found\n", kind);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) err = __team_change_mode(team, new_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) netdev_err(dev, "Failed to change to mode \"%s\"\n", kind);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) team_mode_put(new_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) netdev_info(dev, "Mode changed to \"%s\"\n", kind);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) /*********************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) * Peers notification
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) *********************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) static void team_notify_peers_work(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) struct team *team;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) int val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) team = container_of(work, struct team, notify_peers.dw.work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) if (!rtnl_trylock()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) schedule_delayed_work(&team->notify_peers.dw, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) val = atomic_dec_if_positive(&team->notify_peers.count_pending);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) if (val < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) rtnl_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) call_netdevice_notifiers(NETDEV_NOTIFY_PEERS, team->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) rtnl_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) if (val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) schedule_delayed_work(&team->notify_peers.dw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) msecs_to_jiffies(team->notify_peers.interval));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) static void team_notify_peers(struct team *team)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) if (!team->notify_peers.count || !netif_running(team->dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) atomic_add(team->notify_peers.count, &team->notify_peers.count_pending);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) schedule_delayed_work(&team->notify_peers.dw, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) static void team_notify_peers_init(struct team *team)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) INIT_DELAYED_WORK(&team->notify_peers.dw, team_notify_peers_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) static void team_notify_peers_fini(struct team *team)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) cancel_delayed_work_sync(&team->notify_peers.dw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) /*******************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) * Send multicast group rejoins
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) *******************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) static void team_mcast_rejoin_work(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) struct team *team;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) int val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) team = container_of(work, struct team, mcast_rejoin.dw.work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) if (!rtnl_trylock()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) schedule_delayed_work(&team->mcast_rejoin.dw, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) val = atomic_dec_if_positive(&team->mcast_rejoin.count_pending);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) if (val < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) rtnl_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) call_netdevice_notifiers(NETDEV_RESEND_IGMP, team->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) rtnl_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) if (val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) schedule_delayed_work(&team->mcast_rejoin.dw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) msecs_to_jiffies(team->mcast_rejoin.interval));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) static void team_mcast_rejoin(struct team *team)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) if (!team->mcast_rejoin.count || !netif_running(team->dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) atomic_add(team->mcast_rejoin.count, &team->mcast_rejoin.count_pending);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) schedule_delayed_work(&team->mcast_rejoin.dw, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) static void team_mcast_rejoin_init(struct team *team)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) INIT_DELAYED_WORK(&team->mcast_rejoin.dw, team_mcast_rejoin_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) static void team_mcast_rejoin_fini(struct team *team)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) cancel_delayed_work_sync(&team->mcast_rejoin.dw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) /************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) * Rx path frame handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) ************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) /* note: already called with rcu_read_lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) static rx_handler_result_t team_handle_frame(struct sk_buff **pskb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) struct sk_buff *skb = *pskb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) struct team_port *port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) struct team *team;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) rx_handler_result_t res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) skb = skb_share_check(skb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) return RX_HANDLER_CONSUMED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) *pskb = skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) port = team_port_get_rcu(skb->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) team = port->team;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) if (!team_port_enabled(port)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) /* allow exact match delivery for disabled ports */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) res = RX_HANDLER_EXACT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) res = team->ops.receive(team, port, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) if (res == RX_HANDLER_ANOTHER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) struct team_pcpu_stats *pcpu_stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) pcpu_stats = this_cpu_ptr(team->pcpu_stats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) u64_stats_update_begin(&pcpu_stats->syncp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) pcpu_stats->rx_packets++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) pcpu_stats->rx_bytes += skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) if (skb->pkt_type == PACKET_MULTICAST)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) pcpu_stats->rx_multicast++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) u64_stats_update_end(&pcpu_stats->syncp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) skb->dev = team->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) } else if (res == RX_HANDLER_EXACT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) this_cpu_inc(team->pcpu_stats->rx_nohandler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) this_cpu_inc(team->pcpu_stats->rx_dropped);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) /*************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) * Multiqueue Tx port select override
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) *************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) static int team_queue_override_init(struct team *team)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) struct list_head *listarr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) unsigned int queue_cnt = team->dev->num_tx_queues - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) if (!queue_cnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) listarr = kmalloc_array(queue_cnt, sizeof(struct list_head),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) if (!listarr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) team->qom_lists = listarr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) for (i = 0; i < queue_cnt; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) INIT_LIST_HEAD(listarr++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) static void team_queue_override_fini(struct team *team)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) kfree(team->qom_lists);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) static struct list_head *__team_get_qom_list(struct team *team, u16 queue_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) return &team->qom_lists[queue_id - 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) * note: already called with rcu_read_lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) static bool team_queue_override_transmit(struct team *team, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) struct list_head *qom_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) struct team_port *port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) if (!team->queue_override_enabled || !skb->queue_mapping)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) qom_list = __team_get_qom_list(team, skb->queue_mapping);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) list_for_each_entry_rcu(port, qom_list, qom_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) if (!team_dev_queue_xmit(team, port, skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) static void __team_queue_override_port_del(struct team *team,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) struct team_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) if (!port->queue_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) list_del_rcu(&port->qom_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) static bool team_queue_override_port_has_gt_prio_than(struct team_port *port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) struct team_port *cur)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) if (port->priority < cur->priority)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) if (port->priority > cur->priority)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) if (port->index < cur->index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) static void __team_queue_override_port_add(struct team *team,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) struct team_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) struct team_port *cur;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) struct list_head *qom_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) struct list_head *node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) if (!port->queue_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) qom_list = __team_get_qom_list(team, port->queue_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) node = qom_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) list_for_each_entry(cur, qom_list, qom_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) if (team_queue_override_port_has_gt_prio_than(port, cur))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) node = &cur->qom_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) list_add_tail_rcu(&port->qom_list, node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) static void __team_queue_override_enabled_check(struct team *team)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) struct team_port *port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) bool enabled = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) list_for_each_entry(port, &team->port_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) if (port->queue_id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) enabled = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) if (enabled == team->queue_override_enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) netdev_dbg(team->dev, "%s queue override\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) enabled ? "Enabling" : "Disabling");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) team->queue_override_enabled = enabled;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) static void team_queue_override_port_prio_changed(struct team *team,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) struct team_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) if (!port->queue_id || team_port_enabled(port))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) __team_queue_override_port_del(team, port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) __team_queue_override_port_add(team, port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) __team_queue_override_enabled_check(team);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) static void team_queue_override_port_change_queue_id(struct team *team,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) struct team_port *port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) u16 new_queue_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) if (team_port_enabled(port)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) __team_queue_override_port_del(team, port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) port->queue_id = new_queue_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) __team_queue_override_port_add(team, port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) __team_queue_override_enabled_check(team);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) port->queue_id = new_queue_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) static void team_queue_override_port_add(struct team *team,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) struct team_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) __team_queue_override_port_add(team, port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) __team_queue_override_enabled_check(team);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) static void team_queue_override_port_del(struct team *team,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) struct team_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) __team_queue_override_port_del(team, port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) __team_queue_override_enabled_check(team);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) /****************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) * Port handling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) ****************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) static bool team_port_find(const struct team *team,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) const struct team_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) struct team_port *cur;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) list_for_each_entry(cur, &team->port_list, list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) if (cur == port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) * Enable/disable port by adding to enabled port hashlist and setting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) * port->index (Might be racy so reader could see incorrect ifindex when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) * processing a flying packet, but that is not a problem). Write guarded
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) * by team->lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) static void team_port_enable(struct team *team,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) struct team_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) if (team_port_enabled(port))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) port->index = team->en_port_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) hlist_add_head_rcu(&port->hlist,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) team_port_index_hash(team, port->index));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) team_adjust_ops(team);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) team_queue_override_port_add(team, port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) if (team->ops.port_enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) team->ops.port_enabled(team, port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) team_notify_peers(team);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) team_mcast_rejoin(team);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) team_lower_state_changed(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) static void __reconstruct_port_hlist(struct team *team, int rm_index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) struct team_port *port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) for (i = rm_index + 1; i < team->en_port_count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) port = team_get_port_by_index(team, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) hlist_del_rcu(&port->hlist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) port->index--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) hlist_add_head_rcu(&port->hlist,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) team_port_index_hash(team, port->index));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) static void team_port_disable(struct team *team,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) struct team_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) if (!team_port_enabled(port))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) if (team->ops.port_disabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) team->ops.port_disabled(team, port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) hlist_del_rcu(&port->hlist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) __reconstruct_port_hlist(team, port->index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) port->index = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) team->en_port_count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) team_queue_override_port_del(team, port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) team_adjust_ops(team);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) team_lower_state_changed(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) #define TEAM_VLAN_FEATURES (NETIF_F_HW_CSUM | NETIF_F_SG | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) NETIF_F_FRAGLIST | NETIF_F_ALL_TSO | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) NETIF_F_HIGHDMA | NETIF_F_LRO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) #define TEAM_ENC_FEATURES (NETIF_F_HW_CSUM | NETIF_F_SG | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) NETIF_F_RXCSUM | NETIF_F_ALL_TSO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) static void __team_compute_features(struct team *team)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) struct team_port *port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) netdev_features_t vlan_features = TEAM_VLAN_FEATURES &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) NETIF_F_ALL_FOR_ALL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) netdev_features_t enc_features = TEAM_ENC_FEATURES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) unsigned short max_hard_header_len = ETH_HLEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) unsigned int dst_release_flag = IFF_XMIT_DST_RELEASE |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) IFF_XMIT_DST_RELEASE_PERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) list_for_each_entry_rcu(port, &team->port_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) vlan_features = netdev_increment_features(vlan_features,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) port->dev->vlan_features,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) TEAM_VLAN_FEATURES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) enc_features =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) netdev_increment_features(enc_features,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) port->dev->hw_enc_features,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) TEAM_ENC_FEATURES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) dst_release_flag &= port->dev->priv_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) if (port->dev->hard_header_len > max_hard_header_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) max_hard_header_len = port->dev->hard_header_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) team->dev->vlan_features = vlan_features;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) team->dev->hw_enc_features = enc_features | NETIF_F_GSO_ENCAP_ALL |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) NETIF_F_HW_VLAN_CTAG_TX |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) NETIF_F_HW_VLAN_STAG_TX |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) NETIF_F_GSO_UDP_L4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) team->dev->hard_header_len = max_hard_header_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) team->dev->priv_flags &= ~IFF_XMIT_DST_RELEASE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) if (dst_release_flag == (IFF_XMIT_DST_RELEASE | IFF_XMIT_DST_RELEASE_PERM))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) team->dev->priv_flags |= IFF_XMIT_DST_RELEASE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) static void team_compute_features(struct team *team)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) __team_compute_features(team);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) netdev_change_features(team->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) static int team_port_enter(struct team *team, struct team_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) dev_hold(team->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) if (team->ops.port_enter) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) err = team->ops.port_enter(team, port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) netdev_err(team->dev, "Device %s failed to enter team mode\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) port->dev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) goto err_port_enter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) err_port_enter:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) dev_put(team->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) static void team_port_leave(struct team *team, struct team_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) if (team->ops.port_leave)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) team->ops.port_leave(team, port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) dev_put(team->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) #ifdef CONFIG_NET_POLL_CONTROLLER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) static int __team_port_enable_netpoll(struct team_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) struct netpoll *np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) np = kzalloc(sizeof(*np), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) if (!np)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) err = __netpoll_setup(np, port->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) kfree(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) port->np = np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) static int team_port_enable_netpoll(struct team_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) if (!port->team->dev->npinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) return __team_port_enable_netpoll(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) static void team_port_disable_netpoll(struct team_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) struct netpoll *np = port->np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) if (!np)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) port->np = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) __netpoll_free(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) static int team_port_enable_netpoll(struct team_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) static void team_port_disable_netpoll(struct team_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) static int team_upper_dev_link(struct team *team, struct team_port *port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) struct netdev_lag_upper_info lag_upper_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) lag_upper_info.tx_type = team->mode->lag_tx_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) lag_upper_info.hash_type = NETDEV_LAG_HASH_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) err = netdev_master_upper_dev_link(port->dev, team->dev, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) &lag_upper_info, extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) port->dev->priv_flags |= IFF_TEAM_PORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) static void team_upper_dev_unlink(struct team *team, struct team_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) netdev_upper_dev_unlink(port->dev, team->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) port->dev->priv_flags &= ~IFF_TEAM_PORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) static void __team_port_change_port_added(struct team_port *port, bool linkup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) static int team_dev_type_check_change(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) struct net_device *port_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) static int team_port_add(struct team *team, struct net_device *port_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) struct net_device *dev = team->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) struct team_port *port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) char *portname = port_dev->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) if (port_dev->flags & IFF_LOOPBACK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) NL_SET_ERR_MSG(extack, "Loopback device can't be added as a team port");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) netdev_err(dev, "Device %s is loopback device. Loopback devices can't be added as a team port\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) portname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) if (netif_is_team_port(port_dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) NL_SET_ERR_MSG(extack, "Device is already a port of a team device");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) netdev_err(dev, "Device %s is already a port "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) "of a team device\n", portname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) if (dev == port_dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) NL_SET_ERR_MSG(extack, "Cannot enslave team device to itself");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) netdev_err(dev, "Cannot enslave team device to itself\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) if (netdev_has_upper_dev(dev, port_dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) NL_SET_ERR_MSG(extack, "Device is already an upper device of the team interface");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) netdev_err(dev, "Device %s is already an upper device of the team interface\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) portname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) if (port_dev->features & NETIF_F_VLAN_CHALLENGED &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) vlan_uses_dev(dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) NL_SET_ERR_MSG(extack, "Device is VLAN challenged and team device has VLAN set up");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) netdev_err(dev, "Device %s is VLAN challenged and team device has VLAN set up\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) portname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) err = team_dev_type_check_change(dev, port_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) if (port_dev->flags & IFF_UP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) NL_SET_ERR_MSG(extack, "Device is up. Set it down before adding it as a team port");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) netdev_err(dev, "Device %s is up. Set it down before adding it as a team port\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) portname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) port = kzalloc(sizeof(struct team_port) + team->mode->port_priv_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) if (!port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) port->dev = port_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) port->team = team;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) INIT_LIST_HEAD(&port->qom_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) port->orig.mtu = port_dev->mtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) err = dev_set_mtu(port_dev, dev->mtu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) netdev_dbg(dev, "Error %d calling dev_set_mtu\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) goto err_set_mtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) memcpy(port->orig.dev_addr, port_dev->dev_addr, port_dev->addr_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) err = team_port_enter(team, port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) netdev_err(dev, "Device %s failed to enter team mode\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) portname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) goto err_port_enter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) err = dev_open(port_dev, extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) netdev_dbg(dev, "Device %s opening failed\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) portname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) goto err_dev_open;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) err = vlan_vids_add_by_dev(port_dev, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) netdev_err(dev, "Failed to add vlan ids to device %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) portname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) goto err_vids_add;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) err = team_port_enable_netpoll(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) netdev_err(dev, "Failed to enable netpoll on device %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) portname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) goto err_enable_netpoll;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) if (!(dev->features & NETIF_F_LRO))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) dev_disable_lro(port_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) err = netdev_rx_handler_register(port_dev, team_handle_frame,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) netdev_err(dev, "Device %s failed to register rx_handler\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) portname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) goto err_handler_register;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) err = team_upper_dev_link(team, port, extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) netdev_err(dev, "Device %s failed to set upper link\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) portname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) goto err_set_upper_link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) err = __team_option_inst_add_port(team, port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) netdev_err(dev, "Device %s failed to add per-port options\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) portname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) goto err_option_port_add;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) /* set promiscuity level to new slave */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) if (dev->flags & IFF_PROMISC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) err = dev_set_promiscuity(port_dev, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) goto err_set_slave_promisc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) /* set allmulti level to new slave */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) if (dev->flags & IFF_ALLMULTI) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) err = dev_set_allmulti(port_dev, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) if (dev->flags & IFF_PROMISC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) dev_set_promiscuity(port_dev, -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) goto err_set_slave_promisc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) netif_addr_lock_bh(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) dev_uc_sync_multiple(port_dev, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) dev_mc_sync_multiple(port_dev, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) netif_addr_unlock_bh(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) port->index = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) list_add_tail_rcu(&port->list, &team->port_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) team_port_enable(team, port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) __team_compute_features(team);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) __team_port_change_port_added(port, !!netif_oper_up(port_dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) __team_options_change_check(team);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) netdev_info(dev, "Port device %s added\n", portname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) err_set_slave_promisc:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) __team_option_inst_del_port(team, port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) err_option_port_add:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) team_upper_dev_unlink(team, port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) err_set_upper_link:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) netdev_rx_handler_unregister(port_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) err_handler_register:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) team_port_disable_netpoll(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) err_enable_netpoll:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) vlan_vids_del_by_dev(port_dev, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) err_vids_add:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) dev_close(port_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) err_dev_open:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) team_port_leave(team, port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) team_port_set_orig_dev_addr(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) err_port_enter:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) dev_set_mtu(port_dev, port->orig.mtu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) err_set_mtu:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) kfree(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) static void __team_port_change_port_removed(struct team_port *port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) static int team_port_del(struct team *team, struct net_device *port_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) struct net_device *dev = team->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) struct team_port *port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) char *portname = port_dev->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) port = team_port_get_rtnl(port_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) if (!port || !team_port_find(team, port)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) netdev_err(dev, "Device %s does not act as a port of this team\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) portname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) team_port_disable(team, port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) list_del_rcu(&port->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) if (dev->flags & IFF_PROMISC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) dev_set_promiscuity(port_dev, -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) if (dev->flags & IFF_ALLMULTI)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) dev_set_allmulti(port_dev, -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) team_upper_dev_unlink(team, port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) netdev_rx_handler_unregister(port_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) team_port_disable_netpoll(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) vlan_vids_del_by_dev(port_dev, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) dev_uc_unsync(port_dev, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) dev_mc_unsync(port_dev, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) dev_close(port_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) team_port_leave(team, port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) __team_option_inst_mark_removed_port(team, port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) __team_options_change_check(team);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) __team_option_inst_del_port(team, port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) __team_port_change_port_removed(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) team_port_set_orig_dev_addr(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) dev_set_mtu(port_dev, port->orig.mtu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) kfree_rcu(port, rcu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) netdev_info(dev, "Port device %s removed\n", portname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) __team_compute_features(team);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) /*****************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) * Net device ops
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) *****************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) static int team_mode_option_get(struct team *team, struct team_gsetter_ctx *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) ctx->data.str_val = team->mode->kind;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) static int team_mode_option_set(struct team *team, struct team_gsetter_ctx *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) return team_change_mode(team, ctx->data.str_val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) static int team_notify_peers_count_get(struct team *team,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) struct team_gsetter_ctx *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) ctx->data.u32_val = team->notify_peers.count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) static int team_notify_peers_count_set(struct team *team,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) struct team_gsetter_ctx *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) team->notify_peers.count = ctx->data.u32_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) static int team_notify_peers_interval_get(struct team *team,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) struct team_gsetter_ctx *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) ctx->data.u32_val = team->notify_peers.interval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) static int team_notify_peers_interval_set(struct team *team,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) struct team_gsetter_ctx *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) team->notify_peers.interval = ctx->data.u32_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) static int team_mcast_rejoin_count_get(struct team *team,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) struct team_gsetter_ctx *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) ctx->data.u32_val = team->mcast_rejoin.count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) static int team_mcast_rejoin_count_set(struct team *team,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) struct team_gsetter_ctx *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) team->mcast_rejoin.count = ctx->data.u32_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) static int team_mcast_rejoin_interval_get(struct team *team,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) struct team_gsetter_ctx *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) ctx->data.u32_val = team->mcast_rejoin.interval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) static int team_mcast_rejoin_interval_set(struct team *team,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) struct team_gsetter_ctx *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) team->mcast_rejoin.interval = ctx->data.u32_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) static int team_port_en_option_get(struct team *team,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) struct team_gsetter_ctx *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) struct team_port *port = ctx->info->port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) ctx->data.bool_val = team_port_enabled(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) static int team_port_en_option_set(struct team *team,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) struct team_gsetter_ctx *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) struct team_port *port = ctx->info->port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) if (ctx->data.bool_val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) team_port_enable(team, port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) team_port_disable(team, port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) static int team_user_linkup_option_get(struct team *team,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) struct team_gsetter_ctx *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) struct team_port *port = ctx->info->port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) ctx->data.bool_val = port->user.linkup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) static void __team_carrier_check(struct team *team);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) static int team_user_linkup_option_set(struct team *team,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) struct team_gsetter_ctx *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) struct team_port *port = ctx->info->port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) port->user.linkup = ctx->data.bool_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) team_refresh_port_linkup(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) __team_carrier_check(port->team);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) static int team_user_linkup_en_option_get(struct team *team,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) struct team_gsetter_ctx *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) struct team_port *port = ctx->info->port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) ctx->data.bool_val = port->user.linkup_enabled;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) static int team_user_linkup_en_option_set(struct team *team,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) struct team_gsetter_ctx *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) struct team_port *port = ctx->info->port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) port->user.linkup_enabled = ctx->data.bool_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) team_refresh_port_linkup(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) __team_carrier_check(port->team);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) static int team_priority_option_get(struct team *team,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) struct team_gsetter_ctx *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) struct team_port *port = ctx->info->port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) ctx->data.s32_val = port->priority;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) static int team_priority_option_set(struct team *team,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) struct team_gsetter_ctx *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) struct team_port *port = ctx->info->port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) s32 priority = ctx->data.s32_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) if (port->priority == priority)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) port->priority = priority;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) team_queue_override_port_prio_changed(team, port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) static int team_queue_id_option_get(struct team *team,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) struct team_gsetter_ctx *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) struct team_port *port = ctx->info->port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) ctx->data.u32_val = port->queue_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) static int team_queue_id_option_set(struct team *team,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) struct team_gsetter_ctx *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) struct team_port *port = ctx->info->port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) u16 new_queue_id = ctx->data.u32_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) if (port->queue_id == new_queue_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) if (new_queue_id >= team->dev->real_num_tx_queues)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) team_queue_override_port_change_queue_id(team, port, new_queue_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) static const struct team_option team_options[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) .name = "mode",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) .type = TEAM_OPTION_TYPE_STRING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) .getter = team_mode_option_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) .setter = team_mode_option_set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) .name = "notify_peers_count",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) .type = TEAM_OPTION_TYPE_U32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) .getter = team_notify_peers_count_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) .setter = team_notify_peers_count_set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) .name = "notify_peers_interval",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) .type = TEAM_OPTION_TYPE_U32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) .getter = team_notify_peers_interval_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) .setter = team_notify_peers_interval_set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) .name = "mcast_rejoin_count",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) .type = TEAM_OPTION_TYPE_U32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) .getter = team_mcast_rejoin_count_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) .setter = team_mcast_rejoin_count_set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) .name = "mcast_rejoin_interval",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) .type = TEAM_OPTION_TYPE_U32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) .getter = team_mcast_rejoin_interval_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575) .setter = team_mcast_rejoin_interval_set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) .name = "enabled",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) .type = TEAM_OPTION_TYPE_BOOL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) .per_port = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) .getter = team_port_en_option_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) .setter = team_port_en_option_set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585) .name = "user_linkup",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) .type = TEAM_OPTION_TYPE_BOOL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) .per_port = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) .getter = team_user_linkup_option_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) .setter = team_user_linkup_option_set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592) .name = "user_linkup_enabled",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) .type = TEAM_OPTION_TYPE_BOOL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) .per_port = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) .getter = team_user_linkup_en_option_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596) .setter = team_user_linkup_en_option_set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) .name = "priority",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) .type = TEAM_OPTION_TYPE_S32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) .per_port = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) .getter = team_priority_option_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) .setter = team_priority_option_set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) .name = "queue_id",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607) .type = TEAM_OPTION_TYPE_U32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) .per_port = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) .getter = team_queue_id_option_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) .setter = team_queue_id_option_set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615) static int team_init(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617) struct team *team = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) team->dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622) team_set_no_mode(team);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) team->pcpu_stats = netdev_alloc_pcpu_stats(struct team_pcpu_stats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625) if (!team->pcpu_stats)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) for (i = 0; i < TEAM_PORT_HASHENTRIES; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) INIT_HLIST_HEAD(&team->en_port_hlist[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) INIT_LIST_HEAD(&team->port_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) err = team_queue_override_init(team);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) goto err_team_queue_override_init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635) team_adjust_ops(team);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) INIT_LIST_HEAD(&team->option_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) INIT_LIST_HEAD(&team->option_inst_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640) team_notify_peers_init(team);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641) team_mcast_rejoin_init(team);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643) err = team_options_register(team, team_options, ARRAY_SIZE(team_options));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) goto err_options_register;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) netif_carrier_off(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648) lockdep_register_key(&team->team_lock_key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) __mutex_init(&team->lock, "team->team_lock_key", &team->team_lock_key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) netdev_lockdep_set_classes(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) err_options_register:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655) team_mcast_rejoin_fini(team);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) team_notify_peers_fini(team);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657) team_queue_override_fini(team);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658) err_team_queue_override_init:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) free_percpu(team->pcpu_stats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664) static void team_uninit(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) struct team *team = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) struct team_port *port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668) struct team_port *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670) mutex_lock(&team->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671) list_for_each_entry_safe(port, tmp, &team->port_list, list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672) team_port_del(team, port->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) __team_change_mode(team, NULL); /* cleanup */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) __team_options_unregister(team, team_options, ARRAY_SIZE(team_options));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) team_mcast_rejoin_fini(team);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) team_notify_peers_fini(team);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678) team_queue_override_fini(team);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) mutex_unlock(&team->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) netdev_change_features(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681) lockdep_unregister_key(&team->team_lock_key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684) static void team_destructor(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686) struct team *team = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688) free_percpu(team->pcpu_stats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691) static int team_open(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696) static int team_close(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702) * note: already called with rcu_read_lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704) static netdev_tx_t team_xmit(struct sk_buff *skb, struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) struct team *team = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707) bool tx_success;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708) unsigned int len = skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710) tx_success = team_queue_override_transmit(team, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711) if (!tx_success)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) tx_success = team->ops.transmit(team, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713) if (tx_success) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714) struct team_pcpu_stats *pcpu_stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716) pcpu_stats = this_cpu_ptr(team->pcpu_stats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717) u64_stats_update_begin(&pcpu_stats->syncp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718) pcpu_stats->tx_packets++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719) pcpu_stats->tx_bytes += len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720) u64_stats_update_end(&pcpu_stats->syncp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722) this_cpu_inc(team->pcpu_stats->tx_dropped);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725) return NETDEV_TX_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728) static u16 team_select_queue(struct net_device *dev, struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729) struct net_device *sb_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732) * This helper function exists to help dev_pick_tx get the correct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733) * destination queue. Using a helper function skips a call to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734) * skb_tx_hash and will put the skbs in the queue we expect on their
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735) * way down to the team driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737) u16 txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740) * Save the original txq to restore before passing to the driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742) qdisc_skb_cb(skb)->slave_dev_queue_mapping = skb->queue_mapping;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744) if (unlikely(txq >= dev->real_num_tx_queues)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746) txq -= dev->real_num_tx_queues;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747) } while (txq >= dev->real_num_tx_queues);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749) return txq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752) static void team_change_rx_flags(struct net_device *dev, int change)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754) struct team *team = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755) struct team_port *port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756) int inc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759) list_for_each_entry_rcu(port, &team->port_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760) if (change & IFF_PROMISC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761) inc = dev->flags & IFF_PROMISC ? 1 : -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762) dev_set_promiscuity(port->dev, inc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764) if (change & IFF_ALLMULTI) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765) inc = dev->flags & IFF_ALLMULTI ? 1 : -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766) dev_set_allmulti(port->dev, inc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772) static void team_set_rx_mode(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774) struct team *team = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775) struct team_port *port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778) list_for_each_entry_rcu(port, &team->port_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779) dev_uc_sync_multiple(port->dev, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780) dev_mc_sync_multiple(port->dev, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785) static int team_set_mac_address(struct net_device *dev, void *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787) struct sockaddr *addr = p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788) struct team *team = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789) struct team_port *port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791) if (dev->type == ARPHRD_ETHER && !is_valid_ether_addr(addr->sa_data))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792) return -EADDRNOTAVAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793) memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794) mutex_lock(&team->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795) list_for_each_entry(port, &team->port_list, list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796) if (team->ops.port_change_dev_addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797) team->ops.port_change_dev_addr(team, port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798) mutex_unlock(&team->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802) static int team_change_mtu(struct net_device *dev, int new_mtu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804) struct team *team = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805) struct team_port *port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809) * Alhough this is reader, it's guarded by team lock. It's not possible
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810) * to traverse list in reverse under rcu_read_lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1811) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1812) mutex_lock(&team->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1813) team->port_mtu_change_allowed = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1814) list_for_each_entry(port, &team->port_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1815) err = dev_set_mtu(port->dev, new_mtu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1816) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1817) netdev_err(dev, "Device %s failed to change mtu",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1818) port->dev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1819) goto unwind;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1820) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1821) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1822) team->port_mtu_change_allowed = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1823) mutex_unlock(&team->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1824)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1825) dev->mtu = new_mtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1826)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1827) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1828)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1829) unwind:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1830) list_for_each_entry_continue_reverse(port, &team->port_list, list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1831) dev_set_mtu(port->dev, dev->mtu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1832) team->port_mtu_change_allowed = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1833) mutex_unlock(&team->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1834)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1835) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1836) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1837)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1838) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1839) team_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1840) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1841) struct team *team = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1842) struct team_pcpu_stats *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1843) u64 rx_packets, rx_bytes, rx_multicast, tx_packets, tx_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1844) u32 rx_dropped = 0, tx_dropped = 0, rx_nohandler = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1845) unsigned int start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1846) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1847)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1848) for_each_possible_cpu(i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1849) p = per_cpu_ptr(team->pcpu_stats, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1850) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1851) start = u64_stats_fetch_begin_irq(&p->syncp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1852) rx_packets = p->rx_packets;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1853) rx_bytes = p->rx_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1854) rx_multicast = p->rx_multicast;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1855) tx_packets = p->tx_packets;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1856) tx_bytes = p->tx_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1857) } while (u64_stats_fetch_retry_irq(&p->syncp, start));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1858)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1859) stats->rx_packets += rx_packets;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1860) stats->rx_bytes += rx_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1861) stats->multicast += rx_multicast;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1862) stats->tx_packets += tx_packets;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1863) stats->tx_bytes += tx_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1864) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1865) * rx_dropped, tx_dropped & rx_nohandler are u32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1866) * updated without syncp protection.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1867) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1868) rx_dropped += p->rx_dropped;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1869) tx_dropped += p->tx_dropped;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1870) rx_nohandler += p->rx_nohandler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1871) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1872) stats->rx_dropped = rx_dropped;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1873) stats->tx_dropped = tx_dropped;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1874) stats->rx_nohandler = rx_nohandler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1875) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1876)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1877) static int team_vlan_rx_add_vid(struct net_device *dev, __be16 proto, u16 vid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1878) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1879) struct team *team = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1880) struct team_port *port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1881) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1882)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1883) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1884) * Alhough this is reader, it's guarded by team lock. It's not possible
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1885) * to traverse list in reverse under rcu_read_lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1886) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1887) mutex_lock(&team->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1888) list_for_each_entry(port, &team->port_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1889) err = vlan_vid_add(port->dev, proto, vid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1890) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1891) goto unwind;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1892) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1893) mutex_unlock(&team->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1894)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1895) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1896)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1897) unwind:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1898) list_for_each_entry_continue_reverse(port, &team->port_list, list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1899) vlan_vid_del(port->dev, proto, vid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1900) mutex_unlock(&team->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1901)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1902) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1903) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1904)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1905) static int team_vlan_rx_kill_vid(struct net_device *dev, __be16 proto, u16 vid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1906) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1907) struct team *team = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1908) struct team_port *port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1909)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1910) mutex_lock(&team->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1911) list_for_each_entry(port, &team->port_list, list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1912) vlan_vid_del(port->dev, proto, vid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1913) mutex_unlock(&team->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1914)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1915) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1916) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1917)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1918) #ifdef CONFIG_NET_POLL_CONTROLLER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1919) static void team_poll_controller(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1920) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1921) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1922)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1923) static void __team_netpoll_cleanup(struct team *team)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1924) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1925) struct team_port *port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1926)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1927) list_for_each_entry(port, &team->port_list, list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1928) team_port_disable_netpoll(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1929) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1930)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1931) static void team_netpoll_cleanup(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1932) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1933) struct team *team = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1934)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1935) mutex_lock(&team->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1936) __team_netpoll_cleanup(team);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1937) mutex_unlock(&team->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1938) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1939)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1940) static int team_netpoll_setup(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1941) struct netpoll_info *npifo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1942) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1943) struct team *team = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1944) struct team_port *port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1945) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1946)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1947) mutex_lock(&team->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1948) list_for_each_entry(port, &team->port_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1949) err = __team_port_enable_netpoll(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1950) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1951) __team_netpoll_cleanup(team);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1952) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1953) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1954) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1955) mutex_unlock(&team->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1956) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1957) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1958) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1959)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1960) static int team_add_slave(struct net_device *dev, struct net_device *port_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1961) struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1962) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1963) struct team *team = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1964) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1965)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1966) mutex_lock(&team->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1967) err = team_port_add(team, port_dev, extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1968) mutex_unlock(&team->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1969)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1970) if (!err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1971) netdev_change_features(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1972)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1973) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1974) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1975)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1976) static int team_del_slave(struct net_device *dev, struct net_device *port_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1977) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1978) struct team *team = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1979) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1980)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1981) mutex_lock(&team->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1982) err = team_port_del(team, port_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1983) mutex_unlock(&team->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1984)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1985) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1986) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1987)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1988) if (netif_is_team_master(port_dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1989) lockdep_unregister_key(&team->team_lock_key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1990) lockdep_register_key(&team->team_lock_key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1991) lockdep_set_class(&team->lock, &team->team_lock_key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1992) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1993) netdev_change_features(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1994)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1995) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1996) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1997)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1998) static netdev_features_t team_fix_features(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1999) netdev_features_t features)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2000) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2001) struct team_port *port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2002) struct team *team = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2003) netdev_features_t mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2004)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2005) mask = features;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2006) features &= ~NETIF_F_ONE_FOR_ALL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2007) features |= NETIF_F_ALL_FOR_ALL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2008)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2009) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2010) list_for_each_entry_rcu(port, &team->port_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2011) features = netdev_increment_features(features,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2012) port->dev->features,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2013) mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2014) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2015) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2016)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2017) features = netdev_add_tso_features(features, mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2018)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2019) return features;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2020) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2021)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2022) static int team_change_carrier(struct net_device *dev, bool new_carrier)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2023) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2024) struct team *team = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2025)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2026) team->user_carrier_enabled = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2027)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2028) if (new_carrier)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2029) netif_carrier_on(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2030) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2031) netif_carrier_off(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2032) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2033) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2034)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2035) static const struct net_device_ops team_netdev_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2036) .ndo_init = team_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2037) .ndo_uninit = team_uninit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2038) .ndo_open = team_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2039) .ndo_stop = team_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2040) .ndo_start_xmit = team_xmit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2041) .ndo_select_queue = team_select_queue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2042) .ndo_change_rx_flags = team_change_rx_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2043) .ndo_set_rx_mode = team_set_rx_mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2044) .ndo_set_mac_address = team_set_mac_address,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2045) .ndo_change_mtu = team_change_mtu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2046) .ndo_get_stats64 = team_get_stats64,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2047) .ndo_vlan_rx_add_vid = team_vlan_rx_add_vid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2048) .ndo_vlan_rx_kill_vid = team_vlan_rx_kill_vid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2049) #ifdef CONFIG_NET_POLL_CONTROLLER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2050) .ndo_poll_controller = team_poll_controller,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2051) .ndo_netpoll_setup = team_netpoll_setup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2052) .ndo_netpoll_cleanup = team_netpoll_cleanup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2053) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2054) .ndo_add_slave = team_add_slave,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2055) .ndo_del_slave = team_del_slave,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2056) .ndo_fix_features = team_fix_features,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2057) .ndo_change_carrier = team_change_carrier,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2058) .ndo_features_check = passthru_features_check,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2059) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2060)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2061) /***********************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2062) * ethtool interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2063) ***********************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2064)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2065) static void team_ethtool_get_drvinfo(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2066) struct ethtool_drvinfo *drvinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2067) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2068) strlcpy(drvinfo->driver, DRV_NAME, sizeof(drvinfo->driver));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2069) strlcpy(drvinfo->version, UTS_RELEASE, sizeof(drvinfo->version));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2070) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2071)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2072) static int team_ethtool_get_link_ksettings(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2073) struct ethtool_link_ksettings *cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2074) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2075) struct team *team= netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2076) unsigned long speed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2077) struct team_port *port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2078)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2079) cmd->base.duplex = DUPLEX_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2080) cmd->base.port = PORT_OTHER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2081)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2082) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2083) list_for_each_entry_rcu(port, &team->port_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2084) if (team_port_txable(port)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2085) if (port->state.speed != SPEED_UNKNOWN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2086) speed += port->state.speed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2087) if (cmd->base.duplex == DUPLEX_UNKNOWN &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2088) port->state.duplex != DUPLEX_UNKNOWN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2089) cmd->base.duplex = port->state.duplex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2090) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2091) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2092) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2093)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2094) cmd->base.speed = speed ? : SPEED_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2095)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2096) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2097) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2098)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2099) static const struct ethtool_ops team_ethtool_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2100) .get_drvinfo = team_ethtool_get_drvinfo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2101) .get_link = ethtool_op_get_link,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2102) .get_link_ksettings = team_ethtool_get_link_ksettings,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2103) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2105) /***********************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2106) * rt netlink interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2107) ***********************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2109) static void team_setup_by_port(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2110) struct net_device *port_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2111) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2112) dev->header_ops = port_dev->header_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2113) dev->type = port_dev->type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2114) dev->hard_header_len = port_dev->hard_header_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2115) dev->needed_headroom = port_dev->needed_headroom;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2116) dev->addr_len = port_dev->addr_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2117) dev->mtu = port_dev->mtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2118) memcpy(dev->broadcast, port_dev->broadcast, port_dev->addr_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2119) eth_hw_addr_inherit(dev, port_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2120) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2122) static int team_dev_type_check_change(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2123) struct net_device *port_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2124) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2125) struct team *team = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2126) char *portname = port_dev->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2127) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2129) if (dev->type == port_dev->type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2130) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2131) if (!list_empty(&team->port_list)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2132) netdev_err(dev, "Device %s is of different type\n", portname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2133) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2134) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2135) err = call_netdevice_notifiers(NETDEV_PRE_TYPE_CHANGE, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2136) err = notifier_to_errno(err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2137) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2138) netdev_err(dev, "Refused to change device type\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2139) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2140) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2141) dev_uc_flush(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2142) dev_mc_flush(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2143) team_setup_by_port(dev, port_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2144) call_netdevice_notifiers(NETDEV_POST_TYPE_CHANGE, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2145) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2146) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2148) static void team_setup(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2149) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2150) ether_setup(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2151) dev->max_mtu = ETH_MAX_MTU;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2153) dev->netdev_ops = &team_netdev_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2154) dev->ethtool_ops = &team_ethtool_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2155) dev->needs_free_netdev = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2156) dev->priv_destructor = team_destructor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2157) dev->priv_flags &= ~(IFF_XMIT_DST_RELEASE | IFF_TX_SKB_SHARING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2158) dev->priv_flags |= IFF_NO_QUEUE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2159) dev->priv_flags |= IFF_TEAM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2161) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2162) * Indicate we support unicast address filtering. That way core won't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2163) * bring us to promisc mode in case a unicast addr is added.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2164) * Let this up to underlay drivers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2165) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2166) dev->priv_flags |= IFF_UNICAST_FLT | IFF_LIVE_ADDR_CHANGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2168) dev->features |= NETIF_F_LLTX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2169) dev->features |= NETIF_F_GRO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2171) /* Don't allow team devices to change network namespaces. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2172) dev->features |= NETIF_F_NETNS_LOCAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2174) dev->hw_features = TEAM_VLAN_FEATURES |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2175) NETIF_F_HW_VLAN_CTAG_RX |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2176) NETIF_F_HW_VLAN_CTAG_FILTER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2178) dev->hw_features |= NETIF_F_GSO_ENCAP_ALL | NETIF_F_GSO_UDP_L4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2179) dev->features |= dev->hw_features;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2180) dev->features |= NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_STAG_TX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2181) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2183) static int team_newlink(struct net *src_net, struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2184) struct nlattr *tb[], struct nlattr *data[],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2185) struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2186) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2187) if (tb[IFLA_ADDRESS] == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2188) eth_hw_addr_random(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2190) return register_netdevice(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2191) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2193) static int team_validate(struct nlattr *tb[], struct nlattr *data[],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2194) struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2195) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2196) if (tb[IFLA_ADDRESS]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2197) if (nla_len(tb[IFLA_ADDRESS]) != ETH_ALEN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2198) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2199) if (!is_valid_ether_addr(nla_data(tb[IFLA_ADDRESS])))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2200) return -EADDRNOTAVAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2201) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2202) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2203) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2205) static unsigned int team_get_num_tx_queues(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2206) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2207) return TEAM_DEFAULT_NUM_TX_QUEUES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2208) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2210) static unsigned int team_get_num_rx_queues(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2211) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2212) return TEAM_DEFAULT_NUM_RX_QUEUES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2213) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2215) static struct rtnl_link_ops team_link_ops __read_mostly = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2216) .kind = DRV_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2217) .priv_size = sizeof(struct team),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2218) .setup = team_setup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2219) .newlink = team_newlink,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2220) .validate = team_validate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2221) .get_num_tx_queues = team_get_num_tx_queues,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2222) .get_num_rx_queues = team_get_num_rx_queues,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2223) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2226) /***********************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2227) * Generic netlink custom interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2228) ***********************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2230) static struct genl_family team_nl_family;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2232) static const struct nla_policy team_nl_policy[TEAM_ATTR_MAX + 1] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2233) [TEAM_ATTR_UNSPEC] = { .type = NLA_UNSPEC, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2234) [TEAM_ATTR_TEAM_IFINDEX] = { .type = NLA_U32 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2235) [TEAM_ATTR_LIST_OPTION] = { .type = NLA_NESTED },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2236) [TEAM_ATTR_LIST_PORT] = { .type = NLA_NESTED },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2237) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2239) static const struct nla_policy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2240) team_nl_option_policy[TEAM_ATTR_OPTION_MAX + 1] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2241) [TEAM_ATTR_OPTION_UNSPEC] = { .type = NLA_UNSPEC, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2242) [TEAM_ATTR_OPTION_NAME] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2243) .type = NLA_STRING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2244) .len = TEAM_STRING_MAX_LEN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2245) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2246) [TEAM_ATTR_OPTION_CHANGED] = { .type = NLA_FLAG },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2247) [TEAM_ATTR_OPTION_TYPE] = { .type = NLA_U8 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2248) [TEAM_ATTR_OPTION_DATA] = { .type = NLA_BINARY },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2249) [TEAM_ATTR_OPTION_PORT_IFINDEX] = { .type = NLA_U32 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2250) [TEAM_ATTR_OPTION_ARRAY_INDEX] = { .type = NLA_U32 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2251) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2253) static int team_nl_cmd_noop(struct sk_buff *skb, struct genl_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2254) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2255) struct sk_buff *msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2256) void *hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2257) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2259) msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2260) if (!msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2261) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2263) hdr = genlmsg_put(msg, info->snd_portid, info->snd_seq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2264) &team_nl_family, 0, TEAM_CMD_NOOP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2265) if (!hdr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2266) err = -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2267) goto err_msg_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2268) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2270) genlmsg_end(msg, hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2272) return genlmsg_unicast(genl_info_net(info), msg, info->snd_portid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2273)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2274) err_msg_put:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2275) nlmsg_free(msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2277) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2278) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2280) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2281) * Netlink cmd functions should be locked by following two functions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2282) * Since dev gets held here, that ensures dev won't disappear in between.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2283) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2284) static struct team *team_nl_team_get(struct genl_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2285) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2286) struct net *net = genl_info_net(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2287) int ifindex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2288) struct net_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2289) struct team *team;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2290)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2291) if (!info->attrs[TEAM_ATTR_TEAM_IFINDEX])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2292) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2294) ifindex = nla_get_u32(info->attrs[TEAM_ATTR_TEAM_IFINDEX]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2295) dev = dev_get_by_index(net, ifindex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2296) if (!dev || dev->netdev_ops != &team_netdev_ops) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2297) if (dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2298) dev_put(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2299) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2300) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2301)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2302) team = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2303) mutex_lock(&team->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2304) return team;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2305) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2306)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2307) static void team_nl_team_put(struct team *team)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2308) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2309) mutex_unlock(&team->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2310) dev_put(team->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2311) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2312)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2313) typedef int team_nl_send_func_t(struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2314) struct team *team, u32 portid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2316) static int team_nl_send_unicast(struct sk_buff *skb, struct team *team, u32 portid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2317) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2318) return genlmsg_unicast(dev_net(team->dev), skb, portid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2319) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2320)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2321) static int team_nl_fill_one_option_get(struct sk_buff *skb, struct team *team,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2322) struct team_option_inst *opt_inst)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2323) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2324) struct nlattr *option_item;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2325) struct team_option *option = opt_inst->option;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2326) struct team_option_inst_info *opt_inst_info = &opt_inst->info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2327) struct team_gsetter_ctx ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2328) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2329)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2330) ctx.info = opt_inst_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2331) err = team_option_get(team, opt_inst, &ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2332) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2333) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2334)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2335) option_item = nla_nest_start_noflag(skb, TEAM_ATTR_ITEM_OPTION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2336) if (!option_item)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2337) return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2338)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2339) if (nla_put_string(skb, TEAM_ATTR_OPTION_NAME, option->name))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2340) goto nest_cancel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2341) if (opt_inst_info->port &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2342) nla_put_u32(skb, TEAM_ATTR_OPTION_PORT_IFINDEX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2343) opt_inst_info->port->dev->ifindex))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2344) goto nest_cancel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2345) if (opt_inst->option->array_size &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2346) nla_put_u32(skb, TEAM_ATTR_OPTION_ARRAY_INDEX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2347) opt_inst_info->array_index))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2348) goto nest_cancel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2349)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2350) switch (option->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2351) case TEAM_OPTION_TYPE_U32:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2352) if (nla_put_u8(skb, TEAM_ATTR_OPTION_TYPE, NLA_U32))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2353) goto nest_cancel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2354) if (nla_put_u32(skb, TEAM_ATTR_OPTION_DATA, ctx.data.u32_val))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2355) goto nest_cancel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2356) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2357) case TEAM_OPTION_TYPE_STRING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2358) if (nla_put_u8(skb, TEAM_ATTR_OPTION_TYPE, NLA_STRING))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2359) goto nest_cancel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2360) if (nla_put_string(skb, TEAM_ATTR_OPTION_DATA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2361) ctx.data.str_val))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2362) goto nest_cancel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2363) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2364) case TEAM_OPTION_TYPE_BINARY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2365) if (nla_put_u8(skb, TEAM_ATTR_OPTION_TYPE, NLA_BINARY))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2366) goto nest_cancel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2367) if (nla_put(skb, TEAM_ATTR_OPTION_DATA, ctx.data.bin_val.len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2368) ctx.data.bin_val.ptr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2369) goto nest_cancel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2370) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2371) case TEAM_OPTION_TYPE_BOOL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2372) if (nla_put_u8(skb, TEAM_ATTR_OPTION_TYPE, NLA_FLAG))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2373) goto nest_cancel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2374) if (ctx.data.bool_val &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2375) nla_put_flag(skb, TEAM_ATTR_OPTION_DATA))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2376) goto nest_cancel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2377) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2378) case TEAM_OPTION_TYPE_S32:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2379) if (nla_put_u8(skb, TEAM_ATTR_OPTION_TYPE, NLA_S32))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2380) goto nest_cancel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2381) if (nla_put_s32(skb, TEAM_ATTR_OPTION_DATA, ctx.data.s32_val))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2382) goto nest_cancel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2383) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2384) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2385) BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2386) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2387) if (opt_inst->removed && nla_put_flag(skb, TEAM_ATTR_OPTION_REMOVED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2388) goto nest_cancel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2389) if (opt_inst->changed) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2390) if (nla_put_flag(skb, TEAM_ATTR_OPTION_CHANGED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2391) goto nest_cancel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2392) opt_inst->changed = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2393) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2394) nla_nest_end(skb, option_item);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2395) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2396)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2397) nest_cancel:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2398) nla_nest_cancel(skb, option_item);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2399) return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2400) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2401)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2402) static int __send_and_alloc_skb(struct sk_buff **pskb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2403) struct team *team, u32 portid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2404) team_nl_send_func_t *send_func)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2405) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2406) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2407)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2408) if (*pskb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2409) err = send_func(*pskb, team, portid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2410) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2411) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2412) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2413) *pskb = genlmsg_new(GENLMSG_DEFAULT_SIZE, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2414) if (!*pskb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2415) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2416) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2417) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2418)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2419) static int team_nl_send_options_get(struct team *team, u32 portid, u32 seq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2420) int flags, team_nl_send_func_t *send_func,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2421) struct list_head *sel_opt_inst_list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2422) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2423) struct nlattr *option_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2424) struct nlmsghdr *nlh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2425) void *hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2426) struct team_option_inst *opt_inst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2427) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2428) struct sk_buff *skb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2429) bool incomplete;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2430) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2431)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2432) opt_inst = list_first_entry(sel_opt_inst_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2433) struct team_option_inst, tmp_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2434)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2435) start_again:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2436) err = __send_and_alloc_skb(&skb, team, portid, send_func);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2437) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2438) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2439)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2440) hdr = genlmsg_put(skb, portid, seq, &team_nl_family, flags | NLM_F_MULTI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2441) TEAM_CMD_OPTIONS_GET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2442) if (!hdr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2443) nlmsg_free(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2444) return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2445) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2446)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2447) if (nla_put_u32(skb, TEAM_ATTR_TEAM_IFINDEX, team->dev->ifindex))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2448) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2449) option_list = nla_nest_start_noflag(skb, TEAM_ATTR_LIST_OPTION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2450) if (!option_list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2451) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2452)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2453) i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2454) incomplete = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2455) list_for_each_entry_from(opt_inst, sel_opt_inst_list, tmp_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2456) err = team_nl_fill_one_option_get(skb, team, opt_inst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2457) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2458) if (err == -EMSGSIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2459) if (!i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2460) goto errout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2461) incomplete = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2462) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2463) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2464) goto errout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2465) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2466) i++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2467) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2468)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2469) nla_nest_end(skb, option_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2470) genlmsg_end(skb, hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2471) if (incomplete)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2472) goto start_again;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2473)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2474) send_done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2475) nlh = nlmsg_put(skb, portid, seq, NLMSG_DONE, 0, flags | NLM_F_MULTI);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2476) if (!nlh) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2477) err = __send_and_alloc_skb(&skb, team, portid, send_func);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2478) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2479) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2480) goto send_done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2481) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2482)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2483) return send_func(skb, team, portid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2484)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2485) nla_put_failure:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2486) err = -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2487) errout:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2488) nlmsg_free(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2489) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2490) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2491)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2492) static int team_nl_cmd_options_get(struct sk_buff *skb, struct genl_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2493) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2494) struct team *team;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2495) struct team_option_inst *opt_inst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2496) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2497) LIST_HEAD(sel_opt_inst_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2498)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2499) team = team_nl_team_get(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2500) if (!team)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2501) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2502)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2503) list_for_each_entry(opt_inst, &team->option_inst_list, list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2504) list_add_tail(&opt_inst->tmp_list, &sel_opt_inst_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2505) err = team_nl_send_options_get(team, info->snd_portid, info->snd_seq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2506) NLM_F_ACK, team_nl_send_unicast,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2507) &sel_opt_inst_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2508)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2509) team_nl_team_put(team);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2510)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2511) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2512) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2513)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2514) static int team_nl_send_event_options_get(struct team *team,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2515) struct list_head *sel_opt_inst_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2516)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2517) static int team_nl_cmd_options_set(struct sk_buff *skb, struct genl_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2518) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2519) struct team *team;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2520) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2521) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2522) struct nlattr *nl_option;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2523)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2524) rtnl_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2525)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2526) team = team_nl_team_get(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2527) if (!team) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2528) err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2529) goto rtnl_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2530) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2531)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2532) err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2533) if (!info->attrs[TEAM_ATTR_LIST_OPTION]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2534) err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2535) goto team_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2536) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2537)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2538) nla_for_each_nested(nl_option, info->attrs[TEAM_ATTR_LIST_OPTION], i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2539) struct nlattr *opt_attrs[TEAM_ATTR_OPTION_MAX + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2540) struct nlattr *attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2541) struct nlattr *attr_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2542) LIST_HEAD(opt_inst_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2543) enum team_option_type opt_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2544) int opt_port_ifindex = 0; /* != 0 for per-port options */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2545) u32 opt_array_index = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2546) bool opt_is_array = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2547) struct team_option_inst *opt_inst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2548) char *opt_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2549) bool opt_found = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2550)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2551) if (nla_type(nl_option) != TEAM_ATTR_ITEM_OPTION) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2552) err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2553) goto team_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2554) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2555) err = nla_parse_nested_deprecated(opt_attrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2556) TEAM_ATTR_OPTION_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2557) nl_option,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2558) team_nl_option_policy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2559) info->extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2560) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2561) goto team_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2562) if (!opt_attrs[TEAM_ATTR_OPTION_NAME] ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2563) !opt_attrs[TEAM_ATTR_OPTION_TYPE]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2564) err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2565) goto team_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2566) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2567) switch (nla_get_u8(opt_attrs[TEAM_ATTR_OPTION_TYPE])) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2568) case NLA_U32:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2569) opt_type = TEAM_OPTION_TYPE_U32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2570) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2571) case NLA_STRING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2572) opt_type = TEAM_OPTION_TYPE_STRING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2573) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2574) case NLA_BINARY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2575) opt_type = TEAM_OPTION_TYPE_BINARY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2576) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2577) case NLA_FLAG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2578) opt_type = TEAM_OPTION_TYPE_BOOL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2579) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2580) case NLA_S32:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2581) opt_type = TEAM_OPTION_TYPE_S32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2582) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2583) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2584) goto team_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2585) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2586)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2587) attr_data = opt_attrs[TEAM_ATTR_OPTION_DATA];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2588) if (opt_type != TEAM_OPTION_TYPE_BOOL && !attr_data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2589) err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2590) goto team_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2591) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2592)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2593) opt_name = nla_data(opt_attrs[TEAM_ATTR_OPTION_NAME]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2594) attr = opt_attrs[TEAM_ATTR_OPTION_PORT_IFINDEX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2595) if (attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2596) opt_port_ifindex = nla_get_u32(attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2597)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2598) attr = opt_attrs[TEAM_ATTR_OPTION_ARRAY_INDEX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2599) if (attr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2600) opt_is_array = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2601) opt_array_index = nla_get_u32(attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2602) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2603)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2604) list_for_each_entry(opt_inst, &team->option_inst_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2605) struct team_option *option = opt_inst->option;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2606) struct team_gsetter_ctx ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2607) struct team_option_inst_info *opt_inst_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2608) int tmp_ifindex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2609)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2610) opt_inst_info = &opt_inst->info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2611) tmp_ifindex = opt_inst_info->port ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2612) opt_inst_info->port->dev->ifindex : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2613) if (option->type != opt_type ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2614) strcmp(option->name, opt_name) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2615) tmp_ifindex != opt_port_ifindex ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2616) (option->array_size && !opt_is_array) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2617) opt_inst_info->array_index != opt_array_index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2618) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2619) opt_found = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2620) ctx.info = opt_inst_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2621) switch (opt_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2622) case TEAM_OPTION_TYPE_U32:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2623) ctx.data.u32_val = nla_get_u32(attr_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2624) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2625) case TEAM_OPTION_TYPE_STRING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2626) if (nla_len(attr_data) > TEAM_STRING_MAX_LEN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2627) err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2628) goto team_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2629) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2630) ctx.data.str_val = nla_data(attr_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2631) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2632) case TEAM_OPTION_TYPE_BINARY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2633) ctx.data.bin_val.len = nla_len(attr_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2634) ctx.data.bin_val.ptr = nla_data(attr_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2635) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2636) case TEAM_OPTION_TYPE_BOOL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2637) ctx.data.bool_val = attr_data ? true : false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2638) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2639) case TEAM_OPTION_TYPE_S32:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2640) ctx.data.s32_val = nla_get_s32(attr_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2641) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2642) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2643) BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2644) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2645) err = team_option_set(team, opt_inst, &ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2646) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2647) goto team_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2648) opt_inst->changed = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2649) list_add(&opt_inst->tmp_list, &opt_inst_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2650) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2651) if (!opt_found) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2652) err = -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2653) goto team_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2654) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2655)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2656) err = team_nl_send_event_options_get(team, &opt_inst_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2657) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2658) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2659) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2660)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2661) team_put:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2662) team_nl_team_put(team);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2663) rtnl_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2664) rtnl_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2665) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2666) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2667)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2668) static int team_nl_fill_one_port_get(struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2669) struct team_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2670) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2671) struct nlattr *port_item;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2672)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2673) port_item = nla_nest_start_noflag(skb, TEAM_ATTR_ITEM_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2674) if (!port_item)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2675) goto nest_cancel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2676) if (nla_put_u32(skb, TEAM_ATTR_PORT_IFINDEX, port->dev->ifindex))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2677) goto nest_cancel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2678) if (port->changed) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2679) if (nla_put_flag(skb, TEAM_ATTR_PORT_CHANGED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2680) goto nest_cancel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2681) port->changed = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2682) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2683) if ((port->removed &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2684) nla_put_flag(skb, TEAM_ATTR_PORT_REMOVED)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2685) (port->state.linkup &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2686) nla_put_flag(skb, TEAM_ATTR_PORT_LINKUP)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2687) nla_put_u32(skb, TEAM_ATTR_PORT_SPEED, port->state.speed) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2688) nla_put_u8(skb, TEAM_ATTR_PORT_DUPLEX, port->state.duplex))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2689) goto nest_cancel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2690) nla_nest_end(skb, port_item);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2691) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2692)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2693) nest_cancel:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2694) nla_nest_cancel(skb, port_item);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2695) return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2696) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2697)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2698) static int team_nl_send_port_list_get(struct team *team, u32 portid, u32 seq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2699) int flags, team_nl_send_func_t *send_func,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2700) struct team_port *one_port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2701) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2702) struct nlattr *port_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2703) struct nlmsghdr *nlh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2704) void *hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2705) struct team_port *port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2706) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2707) struct sk_buff *skb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2708) bool incomplete;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2709) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2710)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2711) port = list_first_entry_or_null(&team->port_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2712) struct team_port, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2713)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2714) start_again:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2715) err = __send_and_alloc_skb(&skb, team, portid, send_func);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2716) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2717) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2718)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2719) hdr = genlmsg_put(skb, portid, seq, &team_nl_family, flags | NLM_F_MULTI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2720) TEAM_CMD_PORT_LIST_GET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2721) if (!hdr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2722) nlmsg_free(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2723) return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2724) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2725)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2726) if (nla_put_u32(skb, TEAM_ATTR_TEAM_IFINDEX, team->dev->ifindex))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2727) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2728) port_list = nla_nest_start_noflag(skb, TEAM_ATTR_LIST_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2729) if (!port_list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2730) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2731)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2732) i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2733) incomplete = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2734)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2735) /* If one port is selected, called wants to send port list containing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2736) * only this port. Otherwise go through all listed ports and send all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2737) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2738) if (one_port) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2739) err = team_nl_fill_one_port_get(skb, one_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2740) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2741) goto errout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2742) } else if (port) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2743) list_for_each_entry_from(port, &team->port_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2744) err = team_nl_fill_one_port_get(skb, port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2745) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2746) if (err == -EMSGSIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2747) if (!i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2748) goto errout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2749) incomplete = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2750) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2751) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2752) goto errout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2753) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2754) i++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2755) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2756) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2757)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2758) nla_nest_end(skb, port_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2759) genlmsg_end(skb, hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2760) if (incomplete)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2761) goto start_again;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2762)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2763) send_done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2764) nlh = nlmsg_put(skb, portid, seq, NLMSG_DONE, 0, flags | NLM_F_MULTI);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2765) if (!nlh) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2766) err = __send_and_alloc_skb(&skb, team, portid, send_func);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2767) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2768) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2769) goto send_done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2770) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2771)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2772) return send_func(skb, team, portid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2773)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2774) nla_put_failure:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2775) err = -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2776) errout:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2777) nlmsg_free(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2778) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2779) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2780)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2781) static int team_nl_cmd_port_list_get(struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2782) struct genl_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2783) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2784) struct team *team;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2785) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2786)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2787) team = team_nl_team_get(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2788) if (!team)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2789) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2790)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2791) err = team_nl_send_port_list_get(team, info->snd_portid, info->snd_seq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2792) NLM_F_ACK, team_nl_send_unicast, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2793)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2794) team_nl_team_put(team);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2795)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2796) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2797) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2798)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2799) static const struct genl_small_ops team_nl_ops[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2800) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2801) .cmd = TEAM_CMD_NOOP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2802) .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2803) .doit = team_nl_cmd_noop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2804) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2805) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2806) .cmd = TEAM_CMD_OPTIONS_SET,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2807) .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2808) .doit = team_nl_cmd_options_set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2809) .flags = GENL_ADMIN_PERM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2810) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2811) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2812) .cmd = TEAM_CMD_OPTIONS_GET,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2813) .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2814) .doit = team_nl_cmd_options_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2815) .flags = GENL_ADMIN_PERM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2816) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2817) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2818) .cmd = TEAM_CMD_PORT_LIST_GET,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2819) .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2820) .doit = team_nl_cmd_port_list_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2821) .flags = GENL_ADMIN_PERM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2822) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2823) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2824)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2825) static const struct genl_multicast_group team_nl_mcgrps[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2826) { .name = TEAM_GENL_CHANGE_EVENT_MC_GRP_NAME, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2827) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2828)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2829) static struct genl_family team_nl_family __ro_after_init = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2830) .name = TEAM_GENL_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2831) .version = TEAM_GENL_VERSION,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2832) .maxattr = TEAM_ATTR_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2833) .policy = team_nl_policy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2834) .netnsok = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2835) .module = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2836) .small_ops = team_nl_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2837) .n_small_ops = ARRAY_SIZE(team_nl_ops),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2838) .mcgrps = team_nl_mcgrps,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2839) .n_mcgrps = ARRAY_SIZE(team_nl_mcgrps),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2840) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2841)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2842) static int team_nl_send_multicast(struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2843) struct team *team, u32 portid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2844) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2845) return genlmsg_multicast_netns(&team_nl_family, dev_net(team->dev),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2846) skb, 0, 0, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2847) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2848)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2849) static int team_nl_send_event_options_get(struct team *team,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2850) struct list_head *sel_opt_inst_list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2851) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2852) return team_nl_send_options_get(team, 0, 0, 0, team_nl_send_multicast,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2853) sel_opt_inst_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2854) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2855)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2856) static int team_nl_send_event_port_get(struct team *team,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2857) struct team_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2858) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2859) return team_nl_send_port_list_get(team, 0, 0, 0, team_nl_send_multicast,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2860) port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2861) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2862)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2863) static int __init team_nl_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2864) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2865) return genl_register_family(&team_nl_family);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2866) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2867)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2868) static void team_nl_fini(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2869) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2870) genl_unregister_family(&team_nl_family);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2871) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2872)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2873)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2874) /******************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2875) * Change checkers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2876) ******************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2877)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2878) static void __team_options_change_check(struct team *team)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2879) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2880) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2881) struct team_option_inst *opt_inst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2882) LIST_HEAD(sel_opt_inst_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2883)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2884) list_for_each_entry(opt_inst, &team->option_inst_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2885) if (opt_inst->changed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2886) list_add_tail(&opt_inst->tmp_list, &sel_opt_inst_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2887) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2888) err = team_nl_send_event_options_get(team, &sel_opt_inst_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2889) if (err && err != -ESRCH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2890) netdev_warn(team->dev, "Failed to send options change via netlink (err %d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2891) err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2892) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2893)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2894) /* rtnl lock is held */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2895)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2896) static void __team_port_change_send(struct team_port *port, bool linkup)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2897) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2898) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2899)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2900) port->changed = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2901) port->state.linkup = linkup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2902) team_refresh_port_linkup(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2903) if (linkup) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2904) struct ethtool_link_ksettings ecmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2905)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2906) err = __ethtool_get_link_ksettings(port->dev, &ecmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2907) if (!err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2908) port->state.speed = ecmd.base.speed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2909) port->state.duplex = ecmd.base.duplex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2910) goto send_event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2911) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2912) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2913) port->state.speed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2914) port->state.duplex = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2915)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2916) send_event:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2917) err = team_nl_send_event_port_get(port->team, port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2918) if (err && err != -ESRCH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2919) netdev_warn(port->team->dev, "Failed to send port change of device %s via netlink (err %d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2920) port->dev->name, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2921)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2922) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2923)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2924) static void __team_carrier_check(struct team *team)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2925) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2926) struct team_port *port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2927) bool team_linkup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2928)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2929) if (team->user_carrier_enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2930) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2931)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2932) team_linkup = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2933) list_for_each_entry(port, &team->port_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2934) if (port->linkup) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2935) team_linkup = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2936) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2937) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2938) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2939)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2940) if (team_linkup)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2941) netif_carrier_on(team->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2942) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2943) netif_carrier_off(team->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2944) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2945)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2946) static void __team_port_change_check(struct team_port *port, bool linkup)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2947) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2948) if (port->state.linkup != linkup)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2949) __team_port_change_send(port, linkup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2950) __team_carrier_check(port->team);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2951) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2952)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2953) static void __team_port_change_port_added(struct team_port *port, bool linkup)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2954) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2955) __team_port_change_send(port, linkup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2956) __team_carrier_check(port->team);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2957) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2958)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2959) static void __team_port_change_port_removed(struct team_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2960) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2961) port->removed = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2962) __team_port_change_send(port, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2963) __team_carrier_check(port->team);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2964) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2965)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2966) static void team_port_change_check(struct team_port *port, bool linkup)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2967) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2968) struct team *team = port->team;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2969)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2970) mutex_lock(&team->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2971) __team_port_change_check(port, linkup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2972) mutex_unlock(&team->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2973) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2974)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2975)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2976) /************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2977) * Net device notifier event handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2978) ************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2979)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2980) static int team_device_event(struct notifier_block *unused,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2981) unsigned long event, void *ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2982) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2983) struct net_device *dev = netdev_notifier_info_to_dev(ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2984) struct team_port *port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2985)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2986) port = team_port_get_rtnl(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2987) if (!port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2988) return NOTIFY_DONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2989)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2990) switch (event) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2991) case NETDEV_UP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2992) if (netif_oper_up(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2993) team_port_change_check(port, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2994) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2995) case NETDEV_DOWN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2996) team_port_change_check(port, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2997) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2998) case NETDEV_CHANGE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2999) if (netif_running(port->dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3000) team_port_change_check(port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3001) !!netif_oper_up(port->dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3002) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3003) case NETDEV_UNREGISTER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3004) team_del_slave(port->team->dev, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3005) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3006) case NETDEV_FEAT_CHANGE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3007) team_compute_features(port->team);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3008) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3009) case NETDEV_PRECHANGEMTU:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3010) /* Forbid to change mtu of underlaying device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3011) if (!port->team->port_mtu_change_allowed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3012) return NOTIFY_BAD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3013) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3014) case NETDEV_PRE_TYPE_CHANGE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3015) /* Forbid to change type of underlaying device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3016) return NOTIFY_BAD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3017) case NETDEV_RESEND_IGMP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3018) /* Propagate to master device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3019) call_netdevice_notifiers(event, port->team->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3020) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3021) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3022) return NOTIFY_DONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3023) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3024)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3025) static struct notifier_block team_notifier_block __read_mostly = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3026) .notifier_call = team_device_event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3027) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3028)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3029)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3030) /***********************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3031) * Module init and exit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3032) ***********************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3033)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3034) static int __init team_module_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3035) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3036) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3037)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3038) register_netdevice_notifier(&team_notifier_block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3039)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3040) err = rtnl_link_register(&team_link_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3041) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3042) goto err_rtnl_reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3043)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3044) err = team_nl_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3045) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3046) goto err_nl_init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3047)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3048) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3049)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3050) err_nl_init:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3051) rtnl_link_unregister(&team_link_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3052)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3053) err_rtnl_reg:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3054) unregister_netdevice_notifier(&team_notifier_block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3055)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3056) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3057) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3058)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3059) static void __exit team_module_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3060) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3061) team_nl_fini();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3062) rtnl_link_unregister(&team_link_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3063) unregister_netdevice_notifier(&team_notifier_block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3064) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3065)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3066) module_init(team_module_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3067) module_exit(team_module_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3068)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3069) MODULE_LICENSE("GPL v2");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3070) MODULE_AUTHOR("Jiri Pirko <jpirko@redhat.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3071) MODULE_DESCRIPTION("Ethernet team device driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3072) MODULE_ALIAS_RTNL_LINK(DRV_NAME);