linux/drivers/net/team/team_mode_loadbalance.c
<<
>>
Prefs
   1/*
   2 * drivers/net/team/team_mode_loadbalance.c - Load-balancing mode for team
   3 * Copyright (c) 2012 Jiri Pirko <jpirko@redhat.com>
   4 *
   5 * This program is free software; you can redistribute it and/or modify
   6 * it under the terms of the GNU General Public License as published by
   7 * the Free Software Foundation; either version 2 of the License, or
   8 * (at your option) any later version.
   9 */
  10
  11#include <linux/kernel.h>
  12#include <linux/types.h>
  13#include <linux/module.h>
  14#include <linux/init.h>
  15#include <linux/errno.h>
  16#include <linux/netdevice.h>
  17#include <linux/etherdevice.h>
  18#include <linux/filter.h>
  19#include <linux/if_team.h>
  20
  21static rx_handler_result_t lb_receive(struct team *team, struct team_port *port,
  22                                      struct sk_buff *skb)
  23{
  24        if (unlikely(skb->protocol == htons(ETH_P_SLOW))) {
  25                /* LACPDU packets should go to exact delivery */
  26                const unsigned char *dest = eth_hdr(skb)->h_dest;
  27
  28                if (is_link_local_ether_addr(dest) && dest[5] == 0x02)
  29                        return RX_HANDLER_EXACT;
  30        }
  31        return RX_HANDLER_ANOTHER;
  32}
  33
  34struct lb_priv;
  35
  36typedef struct team_port *lb_select_tx_port_func_t(struct team *,
  37                                                   struct lb_priv *,
  38                                                   struct sk_buff *,
  39                                                   unsigned char);
  40
  41#define LB_TX_HASHTABLE_SIZE 256 /* hash is a char */
  42
  43struct lb_stats {
  44        u64 tx_bytes;
  45};
  46
  47struct lb_pcpu_stats {
  48        struct lb_stats hash_stats[LB_TX_HASHTABLE_SIZE];
  49        struct u64_stats_sync syncp;
  50};
  51
  52struct lb_stats_info {
  53        struct lb_stats stats;
  54        struct lb_stats last_stats;
  55        struct team_option_inst_info *opt_inst_info;
  56};
  57
  58struct lb_port_mapping {
  59        struct team_port __rcu *port;
  60        struct team_option_inst_info *opt_inst_info;
  61};
  62
  63struct lb_priv_ex {
  64        struct team *team;
  65        struct lb_port_mapping tx_hash_to_port_mapping[LB_TX_HASHTABLE_SIZE];
  66        struct sock_fprog *orig_fprog;
  67        struct {
  68                unsigned int refresh_interval; /* in tenths of second */
  69                struct delayed_work refresh_dw;
  70                struct lb_stats_info info[LB_TX_HASHTABLE_SIZE];
  71        } stats;
  72};
  73
  74struct lb_priv {
  75        struct sk_filter __rcu *fp;
  76        lb_select_tx_port_func_t __rcu *select_tx_port_func;
  77        struct lb_pcpu_stats __percpu *pcpu_stats;
  78        struct lb_priv_ex *ex; /* priv extension */
  79};
  80
  81static struct lb_priv *get_lb_priv(struct team *team)
  82{
  83        return (struct lb_priv *) &team->mode_priv;
  84}
  85
  86struct lb_port_priv {
  87        struct lb_stats __percpu *pcpu_stats;
  88        struct lb_stats_info stats_info;
  89};
  90
  91static struct lb_port_priv *get_lb_port_priv(struct team_port *port)
  92{
  93        return (struct lb_port_priv *) &port->mode_priv;
  94}
  95
  96#define LB_HTPM_PORT_BY_HASH(lp_priv, hash) \
  97        (lb_priv)->ex->tx_hash_to_port_mapping[hash].port
  98
  99#define LB_HTPM_OPT_INST_INFO_BY_HASH(lp_priv, hash) \
 100        (lb_priv)->ex->tx_hash_to_port_mapping[hash].opt_inst_info
 101
 102static void lb_tx_hash_to_port_mapping_null_port(struct team *team,
 103                                                 struct team_port *port)
 104{
 105        struct lb_priv *lb_priv = get_lb_priv(team);
 106        bool changed = false;
 107        int i;
 108
 109        for (i = 0; i < LB_TX_HASHTABLE_SIZE; i++) {
 110                struct lb_port_mapping *pm;
 111
 112                pm = &lb_priv->ex->tx_hash_to_port_mapping[i];
 113                if (rcu_access_pointer(pm->port) == port) {
 114                        RCU_INIT_POINTER(pm->port, NULL);
 115                        team_option_inst_set_change(pm->opt_inst_info);
 116                        changed = true;
 117                }
 118        }
 119        if (changed)
 120                team_options_change_check(team);
 121}
 122
 123/* Basic tx selection based solely by hash */
 124static struct team_port *lb_hash_select_tx_port(struct team *team,
 125                                                struct lb_priv *lb_priv,
 126                                                struct sk_buff *skb,
 127                                                unsigned char hash)
 128{
 129        int port_index = team_num_to_port_index(team, hash);
 130
 131        return team_get_port_by_index_rcu(team, port_index);
 132}
 133
 134/* Hash to port mapping select tx port */
 135static struct team_port *lb_htpm_select_tx_port(struct team *team,
 136                                                struct lb_priv *lb_priv,
 137                                                struct sk_buff *skb,
 138                                                unsigned char hash)
 139{
 140        return rcu_dereference_bh(LB_HTPM_PORT_BY_HASH(lb_priv, hash));
 141}
 142
 143struct lb_select_tx_port {
 144        char *name;
 145        lb_select_tx_port_func_t *func;
 146};
 147
 148static const struct lb_select_tx_port lb_select_tx_port_list[] = {
 149        {
 150                .name = "hash",
 151                .func = lb_hash_select_tx_port,
 152        },
 153        {
 154                .name = "hash_to_port_mapping",
 155                .func = lb_htpm_select_tx_port,
 156        },
 157};
 158#define LB_SELECT_TX_PORT_LIST_COUNT ARRAY_SIZE(lb_select_tx_port_list)
 159
 160static char *lb_select_tx_port_get_name(lb_select_tx_port_func_t *func)
 161{
 162        int i;
 163
 164        for (i = 0; i < LB_SELECT_TX_PORT_LIST_COUNT; i++) {
 165                const struct lb_select_tx_port *item;
 166
 167                item = &lb_select_tx_port_list[i];
 168                if (item->func == func)
 169                        return item->name;
 170        }
 171        return NULL;
 172}
 173
 174static lb_select_tx_port_func_t *lb_select_tx_port_get_func(const char *name)
 175{
 176        int i;
 177
 178        for (i = 0; i < LB_SELECT_TX_PORT_LIST_COUNT; i++) {
 179                const struct lb_select_tx_port *item;
 180
 181                item = &lb_select_tx_port_list[i];
 182                if (!strcmp(item->name, name))
 183                        return item->func;
 184        }
 185        return NULL;
 186}
 187
 188static unsigned int lb_get_skb_hash(struct lb_priv *lb_priv,
 189                                    struct sk_buff *skb)
 190{
 191        struct sk_filter *fp;
 192        uint32_t lhash;
 193        unsigned char *c;
 194
 195        fp = rcu_dereference_bh(lb_priv->fp);
 196        if (unlikely(!fp))
 197                return 0;
 198        lhash = SK_RUN_FILTER(fp, skb);
 199        c = (char *) &lhash;
 200        return c[0] ^ c[1] ^ c[2] ^ c[3];
 201}
 202
 203static void lb_update_tx_stats(unsigned int tx_bytes, struct lb_priv *lb_priv,
 204                               struct lb_port_priv *lb_port_priv,
 205                               unsigned char hash)
 206{
 207        struct lb_pcpu_stats *pcpu_stats;
 208        struct lb_stats *port_stats;
 209        struct lb_stats *hash_stats;
 210
 211        pcpu_stats = this_cpu_ptr(lb_priv->pcpu_stats);
 212        port_stats = this_cpu_ptr(lb_port_priv->pcpu_stats);
 213        hash_stats = &pcpu_stats->hash_stats[hash];
 214        u64_stats_update_begin(&pcpu_stats->syncp);
 215        port_stats->tx_bytes += tx_bytes;
 216        hash_stats->tx_bytes += tx_bytes;
 217        u64_stats_update_end(&pcpu_stats->syncp);
 218}
 219
 220static bool lb_transmit(struct team *team, struct sk_buff *skb)
 221{
 222        struct lb_priv *lb_priv = get_lb_priv(team);
 223        lb_select_tx_port_func_t *select_tx_port_func;
 224        struct team_port *port;
 225        unsigned char hash;
 226        unsigned int tx_bytes = skb->len;
 227
 228        hash = lb_get_skb_hash(lb_priv, skb);
 229        select_tx_port_func = rcu_dereference_bh(lb_priv->select_tx_port_func);
 230        port = select_tx_port_func(team, lb_priv, skb, hash);
 231        if (unlikely(!port))
 232                goto drop;
 233        if (team_dev_queue_xmit(team, port, skb))
 234                return false;
 235        lb_update_tx_stats(tx_bytes, lb_priv, get_lb_port_priv(port), hash);
 236        return true;
 237
 238drop:
 239        dev_kfree_skb_any(skb);
 240        return false;
 241}
 242
 243static int lb_bpf_func_get(struct team *team, struct team_gsetter_ctx *ctx)
 244{
 245        struct lb_priv *lb_priv = get_lb_priv(team);
 246
 247        if (!lb_priv->ex->orig_fprog) {
 248                ctx->data.bin_val.len = 0;
 249                ctx->data.bin_val.ptr = NULL;
 250                return 0;
 251        }
 252        ctx->data.bin_val.len = lb_priv->ex->orig_fprog->len *
 253                                sizeof(struct sock_filter);
 254        ctx->data.bin_val.ptr = lb_priv->ex->orig_fprog->filter;
 255        return 0;
 256}
 257
 258static int __fprog_create(struct sock_fprog **pfprog, u32 data_len,
 259                          const void *data)
 260{
 261        struct sock_fprog *fprog;
 262        struct sock_filter *filter = (struct sock_filter *) data;
 263
 264        if (data_len % sizeof(struct sock_filter))
 265                return -EINVAL;
 266        fprog = kmalloc(sizeof(*fprog), GFP_KERNEL);
 267        if (!fprog)
 268                return -ENOMEM;
 269        fprog->filter = kmemdup(filter, data_len, GFP_KERNEL);
 270        if (!fprog->filter) {
 271                kfree(fprog);
 272                return -ENOMEM;
 273        }
 274        fprog->len = data_len / sizeof(struct sock_filter);
 275        *pfprog = fprog;
 276        return 0;
 277}
 278
 279static void __fprog_destroy(struct sock_fprog *fprog)
 280{
 281        kfree(fprog->filter);
 282        kfree(fprog);
 283}
 284
 285static int lb_bpf_func_set(struct team *team, struct team_gsetter_ctx *ctx)
 286{
 287        struct lb_priv *lb_priv = get_lb_priv(team);
 288        struct sk_filter *fp = NULL;
 289        struct sk_filter *orig_fp;
 290        struct sock_fprog *fprog = NULL;
 291        int err;
 292
 293        if (ctx->data.bin_val.len) {
 294                err = __fprog_create(&fprog, ctx->data.bin_val.len,
 295                                     ctx->data.bin_val.ptr);
 296                if (err)
 297                        return err;
 298                err = sk_unattached_filter_create(&fp, fprog);
 299                if (err) {
 300                        __fprog_destroy(fprog);
 301                        return err;
 302                }
 303        }
 304
 305        if (lb_priv->ex->orig_fprog) {
 306                /* Clear old filter data */
 307                __fprog_destroy(lb_priv->ex->orig_fprog);
 308                orig_fp = rcu_dereference_protected(lb_priv->fp,
 309                                                lockdep_is_held(&team->lock));
 310                sk_unattached_filter_destroy(orig_fp);
 311        }
 312
 313        rcu_assign_pointer(lb_priv->fp, fp);
 314        lb_priv->ex->orig_fprog = fprog;
 315        return 0;
 316}
 317
 318static int lb_tx_method_get(struct team *team, struct team_gsetter_ctx *ctx)
 319{
 320        struct lb_priv *lb_priv = get_lb_priv(team);
 321        lb_select_tx_port_func_t *func;
 322        char *name;
 323
 324        func = rcu_dereference_protected(lb_priv->select_tx_port_func,
 325                                         lockdep_is_held(&team->lock));
 326        name = lb_select_tx_port_get_name(func);
 327        BUG_ON(!name);
 328        ctx->data.str_val = name;
 329        return 0;
 330}
 331
 332static int lb_tx_method_set(struct team *team, struct team_gsetter_ctx *ctx)
 333{
 334        struct lb_priv *lb_priv = get_lb_priv(team);
 335        lb_select_tx_port_func_t *func;
 336
 337        func = lb_select_tx_port_get_func(ctx->data.str_val);
 338        if (!func)
 339                return -EINVAL;
 340        rcu_assign_pointer(lb_priv->select_tx_port_func, func);
 341        return 0;
 342}
 343
 344static int lb_tx_hash_to_port_mapping_init(struct team *team,
 345                                           struct team_option_inst_info *info)
 346{
 347        struct lb_priv *lb_priv = get_lb_priv(team);
 348        unsigned char hash = info->array_index;
 349
 350        LB_HTPM_OPT_INST_INFO_BY_HASH(lb_priv, hash) = info;
 351        return 0;
 352}
 353
 354static int lb_tx_hash_to_port_mapping_get(struct team *team,
 355                                          struct team_gsetter_ctx *ctx)
 356{
 357        struct lb_priv *lb_priv = get_lb_priv(team);
 358        struct team_port *port;
 359        unsigned char hash = ctx->info->array_index;
 360
 361        port = LB_HTPM_PORT_BY_HASH(lb_priv, hash);
 362        ctx->data.u32_val = port ? port->dev->ifindex : 0;
 363        return 0;
 364}
 365
 366static int lb_tx_hash_to_port_mapping_set(struct team *team,
 367                                          struct team_gsetter_ctx *ctx)
 368{
 369        struct lb_priv *lb_priv = get_lb_priv(team);
 370        struct team_port *port;
 371        unsigned char hash = ctx->info->array_index;
 372
 373        list_for_each_entry(port, &team->port_list, list) {
 374                if (ctx->data.u32_val == port->dev->ifindex &&
 375                    team_port_enabled(port)) {
 376                        rcu_assign_pointer(LB_HTPM_PORT_BY_HASH(lb_priv, hash),
 377                                           port);
 378                        return 0;
 379                }
 380        }
 381        return -ENODEV;
 382}
 383
 384static int lb_hash_stats_init(struct team *team,
 385                              struct team_option_inst_info *info)
 386{
 387        struct lb_priv *lb_priv = get_lb_priv(team);
 388        unsigned char hash = info->array_index;
 389
 390        lb_priv->ex->stats.info[hash].opt_inst_info = info;
 391        return 0;
 392}
 393
 394static int lb_hash_stats_get(struct team *team, struct team_gsetter_ctx *ctx)
 395{
 396        struct lb_priv *lb_priv = get_lb_priv(team);
 397        unsigned char hash = ctx->info->array_index;
 398
 399        ctx->data.bin_val.ptr = &lb_priv->ex->stats.info[hash].stats;
 400        ctx->data.bin_val.len = sizeof(struct lb_stats);
 401        return 0;
 402}
 403
 404static int lb_port_stats_init(struct team *team,
 405                              struct team_option_inst_info *info)
 406{
 407        struct team_port *port = info->port;
 408        struct lb_port_priv *lb_port_priv = get_lb_port_priv(port);
 409
 410        lb_port_priv->stats_info.opt_inst_info = info;
 411        return 0;
 412}
 413
 414static int lb_port_stats_get(struct team *team, struct team_gsetter_ctx *ctx)
 415{
 416        struct team_port *port = ctx->info->port;
 417        struct lb_port_priv *lb_port_priv = get_lb_port_priv(port);
 418
 419        ctx->data.bin_val.ptr = &lb_port_priv->stats_info.stats;
 420        ctx->data.bin_val.len = sizeof(struct lb_stats);
 421        return 0;
 422}
 423
 424static void __lb_stats_info_refresh_prepare(struct lb_stats_info *s_info)
 425{
 426        memcpy(&s_info->last_stats, &s_info->stats, sizeof(struct lb_stats));
 427        memset(&s_info->stats, 0, sizeof(struct lb_stats));
 428}
 429
 430static bool __lb_stats_info_refresh_check(struct lb_stats_info *s_info,
 431                                          struct team *team)
 432{
 433        if (memcmp(&s_info->last_stats, &s_info->stats,
 434            sizeof(struct lb_stats))) {
 435                team_option_inst_set_change(s_info->opt_inst_info);
 436                return true;
 437        }
 438        return false;
 439}
 440
 441static void __lb_one_cpu_stats_add(struct lb_stats *acc_stats,
 442                                   struct lb_stats *cpu_stats,
 443                                   struct u64_stats_sync *syncp)
 444{
 445        unsigned int start;
 446        struct lb_stats tmp;
 447
 448        do {
 449                start = u64_stats_fetch_begin_irq(syncp);
 450                tmp.tx_bytes = cpu_stats->tx_bytes;
 451        } while (u64_stats_fetch_retry_irq(syncp, start));
 452        acc_stats->tx_bytes += tmp.tx_bytes;
 453}
 454
 455static void lb_stats_refresh(struct work_struct *work)
 456{
 457        struct team *team;
 458        struct lb_priv *lb_priv;
 459        struct lb_priv_ex *lb_priv_ex;
 460        struct lb_pcpu_stats *pcpu_stats;
 461        struct lb_stats *stats;
 462        struct lb_stats_info *s_info;
 463        struct team_port *port;
 464        bool changed = false;
 465        int i;
 466        int j;
 467
 468        lb_priv_ex = container_of(work, struct lb_priv_ex,
 469                                  stats.refresh_dw.work);
 470
 471        team = lb_priv_ex->team;
 472        lb_priv = get_lb_priv(team);
 473
 474        if (!mutex_trylock(&team->lock)) {
 475                schedule_delayed_work(&lb_priv_ex->stats.refresh_dw, 0);
 476                return;
 477        }
 478
 479        for (j = 0; j < LB_TX_HASHTABLE_SIZE; j++) {
 480                s_info = &lb_priv->ex->stats.info[j];
 481                __lb_stats_info_refresh_prepare(s_info);
 482                for_each_possible_cpu(i) {
 483                        pcpu_stats = per_cpu_ptr(lb_priv->pcpu_stats, i);
 484                        stats = &pcpu_stats->hash_stats[j];
 485                        __lb_one_cpu_stats_add(&s_info->stats, stats,
 486                                               &pcpu_stats->syncp);
 487                }
 488                changed |= __lb_stats_info_refresh_check(s_info, team);
 489        }
 490
 491        list_for_each_entry(port, &team->port_list, list) {
 492                struct lb_port_priv *lb_port_priv = get_lb_port_priv(port);
 493
 494                s_info = &lb_port_priv->stats_info;
 495                __lb_stats_info_refresh_prepare(s_info);
 496                for_each_possible_cpu(i) {
 497                        pcpu_stats = per_cpu_ptr(lb_priv->pcpu_stats, i);
 498                        stats = per_cpu_ptr(lb_port_priv->pcpu_stats, i);
 499                        __lb_one_cpu_stats_add(&s_info->stats, stats,
 500                                               &pcpu_stats->syncp);
 501                }
 502                changed |= __lb_stats_info_refresh_check(s_info, team);
 503        }
 504
 505        if (changed)
 506                team_options_change_check(team);
 507
 508        schedule_delayed_work(&lb_priv_ex->stats.refresh_dw,
 509                              (lb_priv_ex->stats.refresh_interval * HZ) / 10);
 510
 511        mutex_unlock(&team->lock);
 512}
 513
 514static int lb_stats_refresh_interval_get(struct team *team,
 515                                         struct team_gsetter_ctx *ctx)
 516{
 517        struct lb_priv *lb_priv = get_lb_priv(team);
 518
 519        ctx->data.u32_val = lb_priv->ex->stats.refresh_interval;
 520        return 0;
 521}
 522
 523static int lb_stats_refresh_interval_set(struct team *team,
 524                                         struct team_gsetter_ctx *ctx)
 525{
 526        struct lb_priv *lb_priv = get_lb_priv(team);
 527        unsigned int interval;
 528
 529        interval = ctx->data.u32_val;
 530        if (lb_priv->ex->stats.refresh_interval == interval)
 531                return 0;
 532        lb_priv->ex->stats.refresh_interval = interval;
 533        if (interval)
 534                schedule_delayed_work(&lb_priv->ex->stats.refresh_dw, 0);
 535        else
 536                cancel_delayed_work(&lb_priv->ex->stats.refresh_dw);
 537        return 0;
 538}
 539
 540static const struct team_option lb_options[] = {
 541        {
 542                .name = "bpf_hash_func",
 543                .type = TEAM_OPTION_TYPE_BINARY,
 544                .getter = lb_bpf_func_get,
 545                .setter = lb_bpf_func_set,
 546        },
 547        {
 548                .name = "lb_tx_method",
 549                .type = TEAM_OPTION_TYPE_STRING,
 550                .getter = lb_tx_method_get,
 551                .setter = lb_tx_method_set,
 552        },
 553        {
 554                .name = "lb_tx_hash_to_port_mapping",
 555                .array_size = LB_TX_HASHTABLE_SIZE,
 556                .type = TEAM_OPTION_TYPE_U32,
 557                .init = lb_tx_hash_to_port_mapping_init,
 558                .getter = lb_tx_hash_to_port_mapping_get,
 559                .setter = lb_tx_hash_to_port_mapping_set,
 560        },
 561        {
 562                .name = "lb_hash_stats",
 563                .array_size = LB_TX_HASHTABLE_SIZE,
 564                .type = TEAM_OPTION_TYPE_BINARY,
 565                .init = lb_hash_stats_init,
 566                .getter = lb_hash_stats_get,
 567        },
 568        {
 569                .name = "lb_port_stats",
 570                .per_port = true,
 571                .type = TEAM_OPTION_TYPE_BINARY,
 572                .init = lb_port_stats_init,
 573                .getter = lb_port_stats_get,
 574        },
 575        {
 576                .name = "lb_stats_refresh_interval",
 577                .type = TEAM_OPTION_TYPE_U32,
 578                .getter = lb_stats_refresh_interval_get,
 579                .setter = lb_stats_refresh_interval_set,
 580        },
 581};
 582
 583static int lb_init(struct team *team)
 584{
 585        struct lb_priv *lb_priv = get_lb_priv(team);
 586        lb_select_tx_port_func_t *func;
 587        int err;
 588
 589        /* set default tx port selector */
 590        func = lb_select_tx_port_get_func("hash");
 591        BUG_ON(!func);
 592        rcu_assign_pointer(lb_priv->select_tx_port_func, func);
 593
 594        lb_priv->ex = kzalloc(sizeof(*lb_priv->ex), GFP_KERNEL);
 595        if (!lb_priv->ex)
 596                return -ENOMEM;
 597        lb_priv->ex->team = team;
 598
 599        lb_priv->pcpu_stats = alloc_percpu(struct lb_pcpu_stats);
 600        if (!lb_priv->pcpu_stats) {
 601                err = -ENOMEM;
 602                goto err_alloc_pcpu_stats;
 603        }
 604
 605        INIT_DELAYED_WORK(&lb_priv->ex->stats.refresh_dw, lb_stats_refresh);
 606
 607        err = team_options_register(team, lb_options, ARRAY_SIZE(lb_options));
 608        if (err)
 609                goto err_options_register;
 610        return 0;
 611
 612err_options_register:
 613        free_percpu(lb_priv->pcpu_stats);
 614err_alloc_pcpu_stats:
 615        kfree(lb_priv->ex);
 616        return err;
 617}
 618
 619static void lb_exit(struct team *team)
 620{
 621        struct lb_priv *lb_priv = get_lb_priv(team);
 622
 623        team_options_unregister(team, lb_options,
 624                                ARRAY_SIZE(lb_options));
 625        cancel_delayed_work_sync(&lb_priv->ex->stats.refresh_dw);
 626        free_percpu(lb_priv->pcpu_stats);
 627        kfree(lb_priv->ex);
 628}
 629
 630static int lb_port_enter(struct team *team, struct team_port *port)
 631{
 632        struct lb_port_priv *lb_port_priv = get_lb_port_priv(port);
 633
 634        lb_port_priv->pcpu_stats = alloc_percpu(struct lb_stats);
 635        if (!lb_port_priv->pcpu_stats)
 636                return -ENOMEM;
 637        return 0;
 638}
 639
 640static void lb_port_leave(struct team *team, struct team_port *port)
 641{
 642        struct lb_port_priv *lb_port_priv = get_lb_port_priv(port);
 643
 644        free_percpu(lb_port_priv->pcpu_stats);
 645}
 646
 647static void lb_port_disabled(struct team *team, struct team_port *port)
 648{
 649        lb_tx_hash_to_port_mapping_null_port(team, port);
 650}
 651
 652static const struct team_mode_ops lb_mode_ops = {
 653        .init                   = lb_init,
 654        .exit                   = lb_exit,
 655        .port_enter             = lb_port_enter,
 656        .port_leave             = lb_port_leave,
 657        .port_disabled          = lb_port_disabled,
 658        .receive                = lb_receive,
 659        .transmit               = lb_transmit,
 660};
 661
 662static const struct team_mode lb_mode = {
 663        .kind           = "loadbalance",
 664        .owner          = THIS_MODULE,
 665        .priv_size      = sizeof(struct lb_priv),
 666        .port_priv_size = sizeof(struct lb_port_priv),
 667        .ops            = &lb_mode_ops,
 668        .lag_tx_type    = NETDEV_LAG_TX_TYPE_HASH,
 669};
 670
 671static int __init lb_init_module(void)
 672{
 673        return team_mode_register(&lb_mode);
 674}
 675
 676static void __exit lb_cleanup_module(void)
 677{
 678        team_mode_unregister(&lb_mode);
 679}
 680
 681module_init(lb_init_module);
 682module_exit(lb_cleanup_module);
 683
 684MODULE_LICENSE("GPL v2");
 685MODULE_AUTHOR("Jiri Pirko <jpirko@redhat.com>");
 686MODULE_DESCRIPTION("Load-balancing mode for team");
 687MODULE_ALIAS("team-mode-loadbalance");
 688