team_mode_loadbalance.c 16 KB

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