1 // SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) 2 /* Copyright (C) 2018 Netronome Systems, Inc. */ 3 4 #include "main.h" 5 6 /* LAG group config flags. */ 7 #define NFP_FL_LAG_LAST BIT(1) 8 #define NFP_FL_LAG_FIRST BIT(2) 9 #define NFP_FL_LAG_DATA BIT(3) 10 #define NFP_FL_LAG_XON BIT(4) 11 #define NFP_FL_LAG_SYNC BIT(5) 12 #define NFP_FL_LAG_SWITCH BIT(6) 13 #define NFP_FL_LAG_RESET BIT(7) 14 15 /* LAG port state flags. */ 16 #define NFP_PORT_LAG_LINK_UP BIT(0) 17 #define NFP_PORT_LAG_TX_ENABLED BIT(1) 18 #define NFP_PORT_LAG_CHANGED BIT(2) 19 20 enum nfp_fl_lag_batch { 21 NFP_FL_LAG_BATCH_FIRST, 22 NFP_FL_LAG_BATCH_MEMBER, 23 NFP_FL_LAG_BATCH_FINISHED 24 }; 25 26 /** 27 * struct nfp_flower_cmsg_lag_config - control message payload for LAG config 28 * @ctrl_flags: Configuration flags 29 * @reserved: Reserved for future use 30 * @ttl: Time to live of packet - host always sets to 0xff 31 * @pkt_number: Config message packet number - increment for each message 32 * @batch_ver: Batch version of messages - increment for each batch of messages 33 * @group_id: Group ID applicable 34 * @group_inst: Group instance number - increment when group is reused 35 * @members: Array of 32-bit words listing all active group members 36 */ 37 struct nfp_flower_cmsg_lag_config { 38 u8 ctrl_flags; 39 u8 reserved[2]; 40 u8 ttl; 41 __be32 pkt_number; 42 __be32 batch_ver; 43 __be32 group_id; 44 __be32 group_inst; 45 __be32 members[]; 46 }; 47 48 /** 49 * struct nfp_fl_lag_group - list entry for each LAG group 50 * @group_id: Assigned group ID for host/kernel sync 51 * @group_inst: Group instance in case of ID reuse 52 * @list: List entry 53 * @master_ndev: Group master Netdev 54 * @dirty: Marked if the group needs synced to HW 55 * @offloaded: Marked if the group is currently offloaded to NIC 56 * @to_remove: Marked if the group should be removed from NIC 57 * @to_destroy: Marked if the group should be removed from driver 58 * @slave_cnt: Number of slaves in group 59 */ 60 struct nfp_fl_lag_group { 61 unsigned int group_id; 62 u8 group_inst; 63 struct list_head list; 64 struct net_device *master_ndev; 65 bool dirty; 66 bool offloaded; 67 bool to_remove; 68 bool to_destroy; 69 unsigned int slave_cnt; 70 }; 71 72 #define NFP_FL_LAG_PKT_NUMBER_MASK GENMASK(30, 0) 73 #define NFP_FL_LAG_VERSION_MASK GENMASK(22, 0) 74 #define NFP_FL_LAG_HOST_TTL 0xff 75 76 /* Use this ID with zero members to ack a batch config */ 77 #define NFP_FL_LAG_SYNC_ID 0 78 #define NFP_FL_LAG_GROUP_MIN 1 /* ID 0 reserved */ 79 #define NFP_FL_LAG_GROUP_MAX 32 /* IDs 1 to 31 are valid */ 80 81 /* wait for more config */ 82 #define NFP_FL_LAG_DELAY (msecs_to_jiffies(2)) 83 84 #define NFP_FL_LAG_RETRANS_LIMIT 100 /* max retrans cmsgs to store */ 85 86 static unsigned int nfp_fl_get_next_pkt_number(struct nfp_fl_lag *lag) 87 { 88 lag->pkt_num++; 89 lag->pkt_num &= NFP_FL_LAG_PKT_NUMBER_MASK; 90 91 return lag->pkt_num; 92 } 93 94 static void nfp_fl_increment_version(struct nfp_fl_lag *lag) 95 { 96 /* LSB is not considered by firmware so add 2 for each increment. */ 97 lag->batch_ver += 2; 98 lag->batch_ver &= NFP_FL_LAG_VERSION_MASK; 99 100 /* Zero is reserved by firmware. */ 101 if (!lag->batch_ver) 102 lag->batch_ver += 2; 103 } 104 105 static struct nfp_fl_lag_group * 106 nfp_fl_lag_group_create(struct nfp_fl_lag *lag, struct net_device *master) 107 { 108 struct nfp_fl_lag_group *group; 109 struct nfp_flower_priv *priv; 110 int id; 111 112 priv = container_of(lag, struct nfp_flower_priv, nfp_lag); 113 114 id = ida_simple_get(&lag->ida_handle, NFP_FL_LAG_GROUP_MIN, 115 NFP_FL_LAG_GROUP_MAX, GFP_KERNEL); 116 if (id < 0) { 117 nfp_flower_cmsg_warn(priv->app, 118 "No more bonding groups available\n"); 119 return ERR_PTR(id); 120 } 121 122 group = kmalloc(sizeof(*group), GFP_KERNEL); 123 if (!group) { 124 ida_simple_remove(&lag->ida_handle, id); 125 return ERR_PTR(-ENOMEM); 126 } 127 128 group->group_id = id; 129 group->master_ndev = master; 130 group->dirty = true; 131 group->offloaded = false; 132 group->to_remove = false; 133 group->to_destroy = false; 134 group->slave_cnt = 0; 135 group->group_inst = ++lag->global_inst; 136 list_add_tail(&group->list, &lag->group_list); 137 138 return group; 139 } 140 141 static struct nfp_fl_lag_group * 142 nfp_fl_lag_find_group_for_master_with_lag(struct nfp_fl_lag *lag, 143 struct net_device *master) 144 { 145 struct nfp_fl_lag_group *entry; 146 147 if (!master) 148 return NULL; 149 150 list_for_each_entry(entry, &lag->group_list, list) 151 if (entry->master_ndev == master) 152 return entry; 153 154 return NULL; 155 } 156 157 static int nfp_fl_lag_get_group_info(struct nfp_app *app, 158 struct net_device *netdev, 159 __be16 *group_id, 160 u8 *batch_ver, 161 u8 *group_inst) 162 { 163 struct nfp_flower_priv *priv = app->priv; 164 struct nfp_fl_lag_group *group = NULL; 165 __be32 temp_vers; 166 167 mutex_lock(&priv->nfp_lag.lock); 168 group = nfp_fl_lag_find_group_for_master_with_lag(&priv->nfp_lag, 169 netdev); 170 if (!group) { 171 mutex_unlock(&priv->nfp_lag.lock); 172 return -ENOENT; 173 } 174 175 if (group_id) 176 *group_id = cpu_to_be16(group->group_id); 177 178 if (batch_ver) { 179 temp_vers = cpu_to_be32(priv->nfp_lag.batch_ver << 180 NFP_FL_PRE_LAG_VER_OFF); 181 memcpy(batch_ver, &temp_vers, 3); 182 } 183 184 if (group_inst) 185 *group_inst = group->group_inst; 186 187 mutex_unlock(&priv->nfp_lag.lock); 188 189 return 0; 190 } 191 192 int nfp_flower_lag_populate_pre_action(struct nfp_app *app, 193 struct net_device *master, 194 struct nfp_fl_pre_lag *pre_act, 195 struct netlink_ext_ack *extack) 196 { 197 if (nfp_fl_lag_get_group_info(app, master, &pre_act->group_id, 198 pre_act->lag_version, 199 &pre_act->instance)) { 200 NL_SET_ERR_MSG_MOD(extack, "invalid entry: group does not exist for LAG action"); 201 return -ENOENT; 202 } 203 204 return 0; 205 } 206 207 void nfp_flower_lag_get_info_from_netdev(struct nfp_app *app, 208 struct net_device *netdev, 209 struct nfp_tun_neigh_lag *lag) 210 { 211 nfp_fl_lag_get_group_info(app, netdev, NULL, 212 lag->lag_version, &lag->lag_instance); 213 } 214 215 int nfp_flower_lag_get_output_id(struct nfp_app *app, struct net_device *master) 216 { 217 struct nfp_flower_priv *priv = app->priv; 218 struct nfp_fl_lag_group *group = NULL; 219 int group_id = -ENOENT; 220 221 mutex_lock(&priv->nfp_lag.lock); 222 group = nfp_fl_lag_find_group_for_master_with_lag(&priv->nfp_lag, 223 master); 224 if (group) 225 group_id = group->group_id; 226 mutex_unlock(&priv->nfp_lag.lock); 227 228 return group_id; 229 } 230 231 static int 232 nfp_fl_lag_config_group(struct nfp_fl_lag *lag, struct nfp_fl_lag_group *group, 233 struct net_device **active_members, 234 unsigned int member_cnt, enum nfp_fl_lag_batch *batch) 235 { 236 struct nfp_flower_cmsg_lag_config *cmsg_payload; 237 struct nfp_flower_priv *priv; 238 unsigned long int flags; 239 unsigned int size, i; 240 struct sk_buff *skb; 241 242 priv = container_of(lag, struct nfp_flower_priv, nfp_lag); 243 size = sizeof(*cmsg_payload) + sizeof(__be32) * member_cnt; 244 skb = nfp_flower_cmsg_alloc(priv->app, size, 245 NFP_FLOWER_CMSG_TYPE_LAG_CONFIG, 246 GFP_KERNEL); 247 if (!skb) 248 return -ENOMEM; 249 250 cmsg_payload = nfp_flower_cmsg_get_data(skb); 251 flags = 0; 252 253 /* Increment batch version for each new batch of config messages. */ 254 if (*batch == NFP_FL_LAG_BATCH_FIRST) { 255 flags |= NFP_FL_LAG_FIRST; 256 nfp_fl_increment_version(lag); 257 *batch = NFP_FL_LAG_BATCH_MEMBER; 258 } 259 260 /* If it is a reset msg then it is also the end of the batch. */ 261 if (lag->rst_cfg) { 262 flags |= NFP_FL_LAG_RESET; 263 *batch = NFP_FL_LAG_BATCH_FINISHED; 264 } 265 266 /* To signal the end of a batch, both the switch and last flags are set 267 * and the reserved SYNC group ID is used. 268 */ 269 if (*batch == NFP_FL_LAG_BATCH_FINISHED) { 270 flags |= NFP_FL_LAG_SWITCH | NFP_FL_LAG_LAST; 271 lag->rst_cfg = false; 272 cmsg_payload->group_id = cpu_to_be32(NFP_FL_LAG_SYNC_ID); 273 cmsg_payload->group_inst = 0; 274 } else { 275 cmsg_payload->group_id = cpu_to_be32(group->group_id); 276 cmsg_payload->group_inst = cpu_to_be32(group->group_inst); 277 } 278 279 cmsg_payload->reserved[0] = 0; 280 cmsg_payload->reserved[1] = 0; 281 cmsg_payload->ttl = NFP_FL_LAG_HOST_TTL; 282 cmsg_payload->ctrl_flags = flags; 283 cmsg_payload->batch_ver = cpu_to_be32(lag->batch_ver); 284 cmsg_payload->pkt_number = cpu_to_be32(nfp_fl_get_next_pkt_number(lag)); 285 286 for (i = 0; i < member_cnt; i++) 287 cmsg_payload->members[i] = 288 cpu_to_be32(nfp_repr_get_port_id(active_members[i])); 289 290 nfp_ctrl_tx(priv->app->ctrl, skb); 291 return 0; 292 } 293 294 static void nfp_fl_lag_do_work(struct work_struct *work) 295 { 296 enum nfp_fl_lag_batch batch = NFP_FL_LAG_BATCH_FIRST; 297 struct nfp_fl_lag_group *entry, *storage; 298 struct delayed_work *delayed_work; 299 struct nfp_flower_priv *priv; 300 struct nfp_fl_lag *lag; 301 int err; 302 303 delayed_work = to_delayed_work(work); 304 lag = container_of(delayed_work, struct nfp_fl_lag, work); 305 priv = container_of(lag, struct nfp_flower_priv, nfp_lag); 306 307 mutex_lock(&lag->lock); 308 list_for_each_entry_safe(entry, storage, &lag->group_list, list) { 309 struct net_device *iter_netdev, **acti_netdevs; 310 struct nfp_flower_repr_priv *repr_priv; 311 int active_count = 0, slaves = 0; 312 struct nfp_repr *repr; 313 unsigned long *flags; 314 315 if (entry->to_remove) { 316 /* Active count of 0 deletes group on hw. */ 317 err = nfp_fl_lag_config_group(lag, entry, NULL, 0, 318 &batch); 319 if (!err) { 320 entry->to_remove = false; 321 entry->offloaded = false; 322 } else { 323 nfp_flower_cmsg_warn(priv->app, 324 "group delete failed\n"); 325 schedule_delayed_work(&lag->work, 326 NFP_FL_LAG_DELAY); 327 continue; 328 } 329 330 if (entry->to_destroy) { 331 ida_simple_remove(&lag->ida_handle, 332 entry->group_id); 333 list_del(&entry->list); 334 kfree(entry); 335 } 336 continue; 337 } 338 339 acti_netdevs = kmalloc_array(entry->slave_cnt, 340 sizeof(*acti_netdevs), GFP_KERNEL); 341 if (!acti_netdevs) { 342 schedule_delayed_work(&lag->work, 343 NFP_FL_LAG_DELAY); 344 continue; 345 } 346 347 /* Include sanity check in the loop. It may be that a bond has 348 * changed between processing the last notification and the 349 * work queue triggering. If the number of slaves has changed 350 * or it now contains netdevs that cannot be offloaded, ignore 351 * the group until pending notifications are processed. 352 */ 353 rcu_read_lock(); 354 for_each_netdev_in_bond_rcu(entry->master_ndev, iter_netdev) { 355 if (!nfp_netdev_is_nfp_repr(iter_netdev)) { 356 slaves = 0; 357 break; 358 } 359 360 repr = netdev_priv(iter_netdev); 361 362 if (repr->app != priv->app) { 363 slaves = 0; 364 break; 365 } 366 367 slaves++; 368 if (slaves > entry->slave_cnt) 369 break; 370 371 /* Check the ports for state changes. */ 372 repr_priv = repr->app_priv; 373 flags = &repr_priv->lag_port_flags; 374 375 if (*flags & NFP_PORT_LAG_CHANGED) { 376 *flags &= ~NFP_PORT_LAG_CHANGED; 377 entry->dirty = true; 378 } 379 380 if ((*flags & NFP_PORT_LAG_TX_ENABLED) && 381 (*flags & NFP_PORT_LAG_LINK_UP)) 382 acti_netdevs[active_count++] = iter_netdev; 383 } 384 rcu_read_unlock(); 385 386 if (slaves != entry->slave_cnt || !entry->dirty) { 387 kfree(acti_netdevs); 388 continue; 389 } 390 391 err = nfp_fl_lag_config_group(lag, entry, acti_netdevs, 392 active_count, &batch); 393 if (!err) { 394 entry->offloaded = true; 395 entry->dirty = false; 396 } else { 397 nfp_flower_cmsg_warn(priv->app, 398 "group offload failed\n"); 399 schedule_delayed_work(&lag->work, NFP_FL_LAG_DELAY); 400 } 401 402 kfree(acti_netdevs); 403 } 404 405 /* End the config batch if at least one packet has been batched. */ 406 if (batch == NFP_FL_LAG_BATCH_MEMBER) { 407 batch = NFP_FL_LAG_BATCH_FINISHED; 408 err = nfp_fl_lag_config_group(lag, NULL, NULL, 0, &batch); 409 if (err) 410 nfp_flower_cmsg_warn(priv->app, 411 "group batch end cmsg failed\n"); 412 } 413 414 mutex_unlock(&lag->lock); 415 } 416 417 static int 418 nfp_fl_lag_put_unprocessed(struct nfp_fl_lag *lag, struct sk_buff *skb) 419 { 420 struct nfp_flower_cmsg_lag_config *cmsg_payload; 421 422 cmsg_payload = nfp_flower_cmsg_get_data(skb); 423 if (be32_to_cpu(cmsg_payload->group_id) >= NFP_FL_LAG_GROUP_MAX) 424 return -EINVAL; 425 426 /* Drop cmsg retrans if storage limit is exceeded to prevent 427 * overloading. If the fw notices that expected messages have not been 428 * received in a given time block, it will request a full resync. 429 */ 430 if (skb_queue_len(&lag->retrans_skbs) >= NFP_FL_LAG_RETRANS_LIMIT) 431 return -ENOSPC; 432 433 __skb_queue_tail(&lag->retrans_skbs, skb); 434 435 return 0; 436 } 437 438 static void nfp_fl_send_unprocessed(struct nfp_fl_lag *lag) 439 { 440 struct nfp_flower_priv *priv; 441 struct sk_buff *skb; 442 443 priv = container_of(lag, struct nfp_flower_priv, nfp_lag); 444 445 while ((skb = __skb_dequeue(&lag->retrans_skbs))) 446 nfp_ctrl_tx(priv->app->ctrl, skb); 447 } 448 449 bool nfp_flower_lag_unprocessed_msg(struct nfp_app *app, struct sk_buff *skb) 450 { 451 struct nfp_flower_cmsg_lag_config *cmsg_payload; 452 struct nfp_flower_priv *priv = app->priv; 453 struct nfp_fl_lag_group *group_entry; 454 unsigned long int flags; 455 bool store_skb = false; 456 int err; 457 458 cmsg_payload = nfp_flower_cmsg_get_data(skb); 459 flags = cmsg_payload->ctrl_flags; 460 461 /* Note the intentional fall through below. If DATA and XON are both 462 * set, the message will stored and sent again with the rest of the 463 * unprocessed messages list. 464 */ 465 466 /* Store */ 467 if (flags & NFP_FL_LAG_DATA) 468 if (!nfp_fl_lag_put_unprocessed(&priv->nfp_lag, skb)) 469 store_skb = true; 470 471 /* Send stored */ 472 if (flags & NFP_FL_LAG_XON) 473 nfp_fl_send_unprocessed(&priv->nfp_lag); 474 475 /* Resend all */ 476 if (flags & NFP_FL_LAG_SYNC) { 477 /* To resend all config: 478 * 1) Clear all unprocessed messages 479 * 2) Mark all groups dirty 480 * 3) Reset NFP group config 481 * 4) Schedule a LAG config update 482 */ 483 484 __skb_queue_purge(&priv->nfp_lag.retrans_skbs); 485 486 mutex_lock(&priv->nfp_lag.lock); 487 list_for_each_entry(group_entry, &priv->nfp_lag.group_list, 488 list) 489 group_entry->dirty = true; 490 491 err = nfp_flower_lag_reset(&priv->nfp_lag); 492 if (err) 493 nfp_flower_cmsg_warn(priv->app, 494 "mem err in group reset msg\n"); 495 mutex_unlock(&priv->nfp_lag.lock); 496 497 schedule_delayed_work(&priv->nfp_lag.work, 0); 498 } 499 500 return store_skb; 501 } 502 503 static void 504 nfp_fl_lag_schedule_group_remove(struct nfp_fl_lag *lag, 505 struct nfp_fl_lag_group *group) 506 { 507 group->to_remove = true; 508 509 schedule_delayed_work(&lag->work, NFP_FL_LAG_DELAY); 510 } 511 512 static void 513 nfp_fl_lag_schedule_group_delete(struct nfp_fl_lag *lag, 514 struct net_device *master) 515 { 516 struct nfp_fl_lag_group *group; 517 struct nfp_flower_priv *priv; 518 519 priv = container_of(lag, struct nfp_flower_priv, nfp_lag); 520 521 if (!netif_is_bond_master(master)) 522 return; 523 524 mutex_lock(&lag->lock); 525 group = nfp_fl_lag_find_group_for_master_with_lag(lag, master); 526 if (!group) { 527 mutex_unlock(&lag->lock); 528 nfp_warn(priv->app->cpp, "untracked bond got unregistered %s\n", 529 netdev_name(master)); 530 return; 531 } 532 533 group->to_remove = true; 534 group->to_destroy = true; 535 mutex_unlock(&lag->lock); 536 537 schedule_delayed_work(&lag->work, NFP_FL_LAG_DELAY); 538 } 539 540 static int 541 nfp_fl_lag_changeupper_event(struct nfp_fl_lag *lag, 542 struct netdev_notifier_changeupper_info *info) 543 { 544 struct net_device *upper = info->upper_dev, *iter_netdev; 545 struct netdev_lag_upper_info *lag_upper_info; 546 struct nfp_fl_lag_group *group; 547 struct nfp_flower_priv *priv; 548 unsigned int slave_count = 0; 549 bool can_offload = true; 550 struct nfp_repr *repr; 551 552 if (!netif_is_lag_master(upper)) 553 return 0; 554 555 priv = container_of(lag, struct nfp_flower_priv, nfp_lag); 556 557 rcu_read_lock(); 558 for_each_netdev_in_bond_rcu(upper, iter_netdev) { 559 if (!nfp_netdev_is_nfp_repr(iter_netdev)) { 560 can_offload = false; 561 break; 562 } 563 repr = netdev_priv(iter_netdev); 564 565 /* Ensure all ports are created by the same app/on same card. */ 566 if (repr->app != priv->app) { 567 can_offload = false; 568 break; 569 } 570 571 slave_count++; 572 } 573 rcu_read_unlock(); 574 575 lag_upper_info = info->upper_info; 576 577 /* Firmware supports active/backup and L3/L4 hash bonds. */ 578 if (lag_upper_info && 579 lag_upper_info->tx_type != NETDEV_LAG_TX_TYPE_ACTIVEBACKUP && 580 (lag_upper_info->tx_type != NETDEV_LAG_TX_TYPE_HASH || 581 (lag_upper_info->hash_type != NETDEV_LAG_HASH_L34 && 582 lag_upper_info->hash_type != NETDEV_LAG_HASH_E34 && 583 lag_upper_info->hash_type != NETDEV_LAG_HASH_UNKNOWN))) { 584 can_offload = false; 585 nfp_flower_cmsg_warn(priv->app, 586 "Unable to offload tx_type %u hash %u\n", 587 lag_upper_info->tx_type, 588 lag_upper_info->hash_type); 589 } 590 591 mutex_lock(&lag->lock); 592 group = nfp_fl_lag_find_group_for_master_with_lag(lag, upper); 593 594 if (slave_count == 0 || !can_offload) { 595 /* Cannot offload the group - remove if previously offloaded. */ 596 if (group && group->offloaded) 597 nfp_fl_lag_schedule_group_remove(lag, group); 598 599 mutex_unlock(&lag->lock); 600 return 0; 601 } 602 603 if (!group) { 604 group = nfp_fl_lag_group_create(lag, upper); 605 if (IS_ERR(group)) { 606 mutex_unlock(&lag->lock); 607 return PTR_ERR(group); 608 } 609 } 610 611 group->dirty = true; 612 group->slave_cnt = slave_count; 613 614 /* Group may have been on queue for removal but is now offloadable. */ 615 group->to_remove = false; 616 mutex_unlock(&lag->lock); 617 618 schedule_delayed_work(&lag->work, NFP_FL_LAG_DELAY); 619 return 0; 620 } 621 622 static void 623 nfp_fl_lag_changels_event(struct nfp_fl_lag *lag, struct net_device *netdev, 624 struct netdev_notifier_changelowerstate_info *info) 625 { 626 struct netdev_lag_lower_state_info *lag_lower_info; 627 struct nfp_flower_repr_priv *repr_priv; 628 struct nfp_flower_priv *priv; 629 struct nfp_repr *repr; 630 unsigned long *flags; 631 632 if (!netif_is_lag_port(netdev) || !nfp_netdev_is_nfp_repr(netdev)) 633 return; 634 635 lag_lower_info = info->lower_state_info; 636 if (!lag_lower_info) 637 return; 638 639 priv = container_of(lag, struct nfp_flower_priv, nfp_lag); 640 repr = netdev_priv(netdev); 641 642 /* Verify that the repr is associated with this app. */ 643 if (repr->app != priv->app) 644 return; 645 646 repr_priv = repr->app_priv; 647 flags = &repr_priv->lag_port_flags; 648 649 mutex_lock(&lag->lock); 650 if (lag_lower_info->link_up) 651 *flags |= NFP_PORT_LAG_LINK_UP; 652 else 653 *flags &= ~NFP_PORT_LAG_LINK_UP; 654 655 if (lag_lower_info->tx_enabled) 656 *flags |= NFP_PORT_LAG_TX_ENABLED; 657 else 658 *flags &= ~NFP_PORT_LAG_TX_ENABLED; 659 660 *flags |= NFP_PORT_LAG_CHANGED; 661 mutex_unlock(&lag->lock); 662 663 schedule_delayed_work(&lag->work, NFP_FL_LAG_DELAY); 664 } 665 666 int nfp_flower_lag_netdev_event(struct nfp_flower_priv *priv, 667 struct net_device *netdev, 668 unsigned long event, void *ptr) 669 { 670 struct nfp_fl_lag *lag = &priv->nfp_lag; 671 int err; 672 673 switch (event) { 674 case NETDEV_CHANGEUPPER: 675 err = nfp_fl_lag_changeupper_event(lag, ptr); 676 if (err) 677 return NOTIFY_BAD; 678 return NOTIFY_OK; 679 case NETDEV_CHANGELOWERSTATE: 680 nfp_fl_lag_changels_event(lag, netdev, ptr); 681 return NOTIFY_OK; 682 case NETDEV_UNREGISTER: 683 nfp_fl_lag_schedule_group_delete(lag, netdev); 684 return NOTIFY_OK; 685 } 686 687 return NOTIFY_DONE; 688 } 689 690 int nfp_flower_lag_reset(struct nfp_fl_lag *lag) 691 { 692 enum nfp_fl_lag_batch batch = NFP_FL_LAG_BATCH_FIRST; 693 694 lag->rst_cfg = true; 695 return nfp_fl_lag_config_group(lag, NULL, NULL, 0, &batch); 696 } 697 698 void nfp_flower_lag_init(struct nfp_fl_lag *lag) 699 { 700 INIT_DELAYED_WORK(&lag->work, nfp_fl_lag_do_work); 701 INIT_LIST_HEAD(&lag->group_list); 702 mutex_init(&lag->lock); 703 ida_init(&lag->ida_handle); 704 705 __skb_queue_head_init(&lag->retrans_skbs); 706 707 /* 0 is a reserved batch version so increment to first valid value. */ 708 nfp_fl_increment_version(lag); 709 } 710 711 void nfp_flower_lag_cleanup(struct nfp_fl_lag *lag) 712 { 713 struct nfp_fl_lag_group *entry, *storage; 714 715 cancel_delayed_work_sync(&lag->work); 716 717 __skb_queue_purge(&lag->retrans_skbs); 718 719 /* Remove all groups. */ 720 mutex_lock(&lag->lock); 721 list_for_each_entry_safe(entry, storage, &lag->group_list, list) { 722 list_del(&entry->list); 723 kfree(entry); 724 } 725 mutex_unlock(&lag->lock); 726 mutex_destroy(&lag->lock); 727 ida_destroy(&lag->ida_handle); 728 } 729