team_mode_loadbalance.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668
  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 (rcu_access_pointer(pm->port) == port) {
  82. RCU_INIT_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(rcu_access_pointer(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. lb_select_tx_port_func_t *func;
  261. char *name;
  262. func = rcu_access_pointer(lb_priv->select_tx_port_func);
  263. name = lb_select_tx_port_get_name(func);
  264. BUG_ON(!name);
  265. ctx->data.str_val = name;
  266. return 0;
  267. }
  268. static int lb_tx_method_set(struct team *team, struct team_gsetter_ctx *ctx)
  269. {
  270. struct lb_priv *lb_priv = get_lb_priv(team);
  271. lb_select_tx_port_func_t *func;
  272. func = lb_select_tx_port_get_func(ctx->data.str_val);
  273. if (!func)
  274. return -EINVAL;
  275. rcu_assign_pointer(lb_priv->select_tx_port_func, func);
  276. return 0;
  277. }
  278. static int lb_tx_hash_to_port_mapping_init(struct team *team,
  279. struct team_option_inst_info *info)
  280. {
  281. struct lb_priv *lb_priv = get_lb_priv(team);
  282. unsigned char hash = info->array_index;
  283. LB_HTPM_OPT_INST_INFO_BY_HASH(lb_priv, hash) = info;
  284. return 0;
  285. }
  286. static int lb_tx_hash_to_port_mapping_get(struct team *team,
  287. struct team_gsetter_ctx *ctx)
  288. {
  289. struct lb_priv *lb_priv = get_lb_priv(team);
  290. struct team_port *port;
  291. unsigned char hash = ctx->info->array_index;
  292. port = LB_HTPM_PORT_BY_HASH(lb_priv, hash);
  293. ctx->data.u32_val = port ? port->dev->ifindex : 0;
  294. return 0;
  295. }
  296. static int lb_tx_hash_to_port_mapping_set(struct team *team,
  297. struct team_gsetter_ctx *ctx)
  298. {
  299. struct lb_priv *lb_priv = get_lb_priv(team);
  300. struct team_port *port;
  301. unsigned char hash = ctx->info->array_index;
  302. list_for_each_entry(port, &team->port_list, list) {
  303. if (ctx->data.u32_val == port->dev->ifindex) {
  304. rcu_assign_pointer(LB_HTPM_PORT_BY_HASH(lb_priv, hash),
  305. port);
  306. return 0;
  307. }
  308. }
  309. return -ENODEV;
  310. }
  311. static int lb_hash_stats_init(struct team *team,
  312. struct team_option_inst_info *info)
  313. {
  314. struct lb_priv *lb_priv = get_lb_priv(team);
  315. unsigned char hash = info->array_index;
  316. lb_priv->ex->stats.info[hash].opt_inst_info = info;
  317. return 0;
  318. }
  319. static int lb_hash_stats_get(struct team *team, struct team_gsetter_ctx *ctx)
  320. {
  321. struct lb_priv *lb_priv = get_lb_priv(team);
  322. unsigned char hash = ctx->info->array_index;
  323. ctx->data.bin_val.ptr = &lb_priv->ex->stats.info[hash].stats;
  324. ctx->data.bin_val.len = sizeof(struct lb_stats);
  325. return 0;
  326. }
  327. static int lb_port_stats_init(struct team *team,
  328. struct team_option_inst_info *info)
  329. {
  330. struct team_port *port = info->port;
  331. struct lb_port_priv *lb_port_priv = get_lb_port_priv(port);
  332. lb_port_priv->stats_info.opt_inst_info = info;
  333. return 0;
  334. }
  335. static int lb_port_stats_get(struct team *team, struct team_gsetter_ctx *ctx)
  336. {
  337. struct team_port *port = ctx->info->port;
  338. struct lb_port_priv *lb_port_priv = get_lb_port_priv(port);
  339. ctx->data.bin_val.ptr = &lb_port_priv->stats_info.stats;
  340. ctx->data.bin_val.len = sizeof(struct lb_stats);
  341. return 0;
  342. }
  343. static void __lb_stats_info_refresh_prepare(struct lb_stats_info *s_info)
  344. {
  345. memcpy(&s_info->last_stats, &s_info->stats, sizeof(struct lb_stats));
  346. memset(&s_info->stats, 0, sizeof(struct lb_stats));
  347. }
  348. static bool __lb_stats_info_refresh_check(struct lb_stats_info *s_info,
  349. struct team *team)
  350. {
  351. if (memcmp(&s_info->last_stats, &s_info->stats,
  352. sizeof(struct lb_stats))) {
  353. team_option_inst_set_change(s_info->opt_inst_info);
  354. return true;
  355. }
  356. return false;
  357. }
  358. static void __lb_one_cpu_stats_add(struct lb_stats *acc_stats,
  359. struct lb_stats *cpu_stats,
  360. struct u64_stats_sync *syncp)
  361. {
  362. unsigned int start;
  363. struct lb_stats tmp;
  364. do {
  365. start = u64_stats_fetch_begin_bh(syncp);
  366. tmp.tx_bytes = cpu_stats->tx_bytes;
  367. } while (u64_stats_fetch_retry_bh(syncp, start));
  368. acc_stats->tx_bytes += tmp.tx_bytes;
  369. }
  370. static void lb_stats_refresh(struct work_struct *work)
  371. {
  372. struct team *team;
  373. struct lb_priv *lb_priv;
  374. struct lb_priv_ex *lb_priv_ex;
  375. struct lb_pcpu_stats *pcpu_stats;
  376. struct lb_stats *stats;
  377. struct lb_stats_info *s_info;
  378. struct team_port *port;
  379. bool changed = false;
  380. int i;
  381. int j;
  382. lb_priv_ex = container_of(work, struct lb_priv_ex,
  383. stats.refresh_dw.work);
  384. team = lb_priv_ex->team;
  385. lb_priv = get_lb_priv(team);
  386. if (!mutex_trylock(&team->lock)) {
  387. schedule_delayed_work(&lb_priv_ex->stats.refresh_dw, 0);
  388. return;
  389. }
  390. for (j = 0; j < LB_TX_HASHTABLE_SIZE; j++) {
  391. s_info = &lb_priv->ex->stats.info[j];
  392. __lb_stats_info_refresh_prepare(s_info);
  393. for_each_possible_cpu(i) {
  394. pcpu_stats = per_cpu_ptr(lb_priv->pcpu_stats, i);
  395. stats = &pcpu_stats->hash_stats[j];
  396. __lb_one_cpu_stats_add(&s_info->stats, stats,
  397. &pcpu_stats->syncp);
  398. }
  399. changed |= __lb_stats_info_refresh_check(s_info, team);
  400. }
  401. list_for_each_entry(port, &team->port_list, list) {
  402. struct lb_port_priv *lb_port_priv = get_lb_port_priv(port);
  403. s_info = &lb_port_priv->stats_info;
  404. __lb_stats_info_refresh_prepare(s_info);
  405. for_each_possible_cpu(i) {
  406. pcpu_stats = per_cpu_ptr(lb_priv->pcpu_stats, i);
  407. stats = per_cpu_ptr(lb_port_priv->pcpu_stats, i);
  408. __lb_one_cpu_stats_add(&s_info->stats, stats,
  409. &pcpu_stats->syncp);
  410. }
  411. changed |= __lb_stats_info_refresh_check(s_info, team);
  412. }
  413. if (changed)
  414. team_options_change_check(team);
  415. schedule_delayed_work(&lb_priv_ex->stats.refresh_dw,
  416. (lb_priv_ex->stats.refresh_interval * HZ) / 10);
  417. mutex_unlock(&team->lock);
  418. }
  419. static int lb_stats_refresh_interval_get(struct team *team,
  420. struct team_gsetter_ctx *ctx)
  421. {
  422. struct lb_priv *lb_priv = get_lb_priv(team);
  423. ctx->data.u32_val = lb_priv->ex->stats.refresh_interval;
  424. return 0;
  425. }
  426. static int lb_stats_refresh_interval_set(struct team *team,
  427. struct team_gsetter_ctx *ctx)
  428. {
  429. struct lb_priv *lb_priv = get_lb_priv(team);
  430. unsigned int interval;
  431. interval = ctx->data.u32_val;
  432. if (lb_priv->ex->stats.refresh_interval == interval)
  433. return 0;
  434. lb_priv->ex->stats.refresh_interval = interval;
  435. if (interval)
  436. schedule_delayed_work(&lb_priv->ex->stats.refresh_dw, 0);
  437. else
  438. cancel_delayed_work(&lb_priv->ex->stats.refresh_dw);
  439. return 0;
  440. }
  441. static const struct team_option lb_options[] = {
  442. {
  443. .name = "bpf_hash_func",
  444. .type = TEAM_OPTION_TYPE_BINARY,
  445. .getter = lb_bpf_func_get,
  446. .setter = lb_bpf_func_set,
  447. },
  448. {
  449. .name = "lb_tx_method",
  450. .type = TEAM_OPTION_TYPE_STRING,
  451. .getter = lb_tx_method_get,
  452. .setter = lb_tx_method_set,
  453. },
  454. {
  455. .name = "lb_tx_hash_to_port_mapping",
  456. .array_size = LB_TX_HASHTABLE_SIZE,
  457. .type = TEAM_OPTION_TYPE_U32,
  458. .init = lb_tx_hash_to_port_mapping_init,
  459. .getter = lb_tx_hash_to_port_mapping_get,
  460. .setter = lb_tx_hash_to_port_mapping_set,
  461. },
  462. {
  463. .name = "lb_hash_stats",
  464. .array_size = LB_TX_HASHTABLE_SIZE,
  465. .type = TEAM_OPTION_TYPE_BINARY,
  466. .init = lb_hash_stats_init,
  467. .getter = lb_hash_stats_get,
  468. },
  469. {
  470. .name = "lb_port_stats",
  471. .per_port = true,
  472. .type = TEAM_OPTION_TYPE_BINARY,
  473. .init = lb_port_stats_init,
  474. .getter = lb_port_stats_get,
  475. },
  476. {
  477. .name = "lb_stats_refresh_interval",
  478. .type = TEAM_OPTION_TYPE_U32,
  479. .getter = lb_stats_refresh_interval_get,
  480. .setter = lb_stats_refresh_interval_set,
  481. },
  482. };
  483. static int lb_init(struct team *team)
  484. {
  485. struct lb_priv *lb_priv = get_lb_priv(team);
  486. lb_select_tx_port_func_t *func;
  487. int err;
  488. /* set default tx port selector */
  489. func = lb_select_tx_port_get_func("hash");
  490. BUG_ON(!func);
  491. rcu_assign_pointer(lb_priv->select_tx_port_func, func);
  492. lb_priv->ex = kzalloc(sizeof(*lb_priv->ex), GFP_KERNEL);
  493. if (!lb_priv->ex)
  494. return -ENOMEM;
  495. lb_priv->ex->team = team;
  496. lb_priv->pcpu_stats = alloc_percpu(struct lb_pcpu_stats);
  497. if (!lb_priv->pcpu_stats) {
  498. err = -ENOMEM;
  499. goto err_alloc_pcpu_stats;
  500. }
  501. INIT_DELAYED_WORK(&lb_priv->ex->stats.refresh_dw, lb_stats_refresh);
  502. err = team_options_register(team, lb_options, ARRAY_SIZE(lb_options));
  503. if (err)
  504. goto err_options_register;
  505. return 0;
  506. err_options_register:
  507. free_percpu(lb_priv->pcpu_stats);
  508. err_alloc_pcpu_stats:
  509. kfree(lb_priv->ex);
  510. return err;
  511. }
  512. static void lb_exit(struct team *team)
  513. {
  514. struct lb_priv *lb_priv = get_lb_priv(team);
  515. team_options_unregister(team, lb_options,
  516. ARRAY_SIZE(lb_options));
  517. cancel_delayed_work_sync(&lb_priv->ex->stats.refresh_dw);
  518. free_percpu(lb_priv->pcpu_stats);
  519. kfree(lb_priv->ex);
  520. }
  521. static int lb_port_enter(struct team *team, struct team_port *port)
  522. {
  523. struct lb_port_priv *lb_port_priv = get_lb_port_priv(port);
  524. lb_port_priv->pcpu_stats = alloc_percpu(struct lb_stats);
  525. if (!lb_port_priv->pcpu_stats)
  526. return -ENOMEM;
  527. return 0;
  528. }
  529. static void lb_port_leave(struct team *team, struct team_port *port)
  530. {
  531. struct lb_port_priv *lb_port_priv = get_lb_port_priv(port);
  532. free_percpu(lb_port_priv->pcpu_stats);
  533. }
  534. static void lb_port_disabled(struct team *team, struct team_port *port)
  535. {
  536. lb_tx_hash_to_port_mapping_null_port(team, port);
  537. }
  538. static const struct team_mode_ops lb_mode_ops = {
  539. .init = lb_init,
  540. .exit = lb_exit,
  541. .port_enter = lb_port_enter,
  542. .port_leave = lb_port_leave,
  543. .port_disabled = lb_port_disabled,
  544. .transmit = lb_transmit,
  545. };
  546. static const struct team_mode lb_mode = {
  547. .kind = "loadbalance",
  548. .owner = THIS_MODULE,
  549. .priv_size = sizeof(struct lb_priv),
  550. .port_priv_size = sizeof(struct lb_port_priv),
  551. .ops = &lb_mode_ops,
  552. };
  553. static int __init lb_init_module(void)
  554. {
  555. return team_mode_register(&lb_mode);
  556. }
  557. static void __exit lb_cleanup_module(void)
  558. {
  559. team_mode_unregister(&lb_mode);
  560. }
  561. module_init(lb_init_module);
  562. module_exit(lb_cleanup_module);
  563. MODULE_LICENSE("GPL v2");
  564. MODULE_AUTHOR("Jiri Pirko <jpirko@redhat.com>");
  565. MODULE_DESCRIPTION("Load-balancing mode for team");
  566. MODULE_ALIAS("team-mode-loadbalance");