1 // SPDX-License-Identifier: GPL-2.0-or-later 2 /* 3 * Copyright(c) 1999 - 2004 Intel Corporation. All rights reserved. 4 */ 5 6 #include <linux/skbuff.h> 7 #include <linux/if_ether.h> 8 #include <linux/netdevice.h> 9 #include <linux/spinlock.h> 10 #include <linux/ethtool.h> 11 #include <linux/etherdevice.h> 12 #include <linux/if_bonding.h> 13 #include <linux/pkt_sched.h> 14 #include <net/net_namespace.h> 15 #include <net/bonding.h> 16 #include <net/bond_3ad.h> 17 #include <net/netlink.h> 18 19 /* General definitions */ 20 #define AD_SHORT_TIMEOUT 1 21 #define AD_LONG_TIMEOUT 0 22 #define AD_STANDBY 0x2 23 #define AD_MAX_TX_IN_SECOND 3 24 #define AD_COLLECTOR_MAX_DELAY 0 25 26 /* Timer definitions (43.4.4 in the 802.3ad standard) */ 27 #define AD_FAST_PERIODIC_TIME 1 28 #define AD_SLOW_PERIODIC_TIME 30 29 #define AD_SHORT_TIMEOUT_TIME (3*AD_FAST_PERIODIC_TIME) 30 #define AD_LONG_TIMEOUT_TIME (3*AD_SLOW_PERIODIC_TIME) 31 #define AD_CHURN_DETECTION_TIME 60 32 #define AD_AGGREGATE_WAIT_TIME 2 33 34 /* Port Variables definitions used by the State Machines (43.4.7 in the 35 * 802.3ad standard) 36 */ 37 #define AD_PORT_BEGIN 0x1 38 #define AD_PORT_LACP_ENABLED 0x2 39 #define AD_PORT_ACTOR_CHURN 0x4 40 #define AD_PORT_PARTNER_CHURN 0x8 41 #define AD_PORT_READY 0x10 42 #define AD_PORT_READY_N 0x20 43 #define AD_PORT_MATCHED 0x40 44 #define AD_PORT_STANDBY 0x80 45 #define AD_PORT_SELECTED 0x100 46 #define AD_PORT_MOVED 0x200 47 #define AD_PORT_CHURNED (AD_PORT_ACTOR_CHURN | AD_PORT_PARTNER_CHURN) 48 49 /* Port Key definitions 50 * key is determined according to the link speed, duplex and 51 * user key (which is yet not supported) 52 * -------------------------------------------------------------- 53 * Port key | User key (10 bits) | Speed (5 bits) | Duplex| 54 * -------------------------------------------------------------- 55 * |15 6|5 1|0 56 */ 57 #define AD_DUPLEX_KEY_MASKS 0x1 58 #define AD_SPEED_KEY_MASKS 0x3E 59 #define AD_USER_KEY_MASKS 0xFFC0 60 61 enum ad_link_speed_type { 62 AD_LINK_SPEED_1MBPS = 1, 63 AD_LINK_SPEED_10MBPS, 64 AD_LINK_SPEED_100MBPS, 65 AD_LINK_SPEED_1000MBPS, 66 AD_LINK_SPEED_2500MBPS, 67 AD_LINK_SPEED_5000MBPS, 68 AD_LINK_SPEED_10000MBPS, 69 AD_LINK_SPEED_14000MBPS, 70 AD_LINK_SPEED_20000MBPS, 71 AD_LINK_SPEED_25000MBPS, 72 AD_LINK_SPEED_40000MBPS, 73 AD_LINK_SPEED_50000MBPS, 74 AD_LINK_SPEED_56000MBPS, 75 AD_LINK_SPEED_80000MBPS, 76 AD_LINK_SPEED_100000MBPS, 77 AD_LINK_SPEED_200000MBPS, 78 AD_LINK_SPEED_400000MBPS, 79 AD_LINK_SPEED_800000MBPS, 80 AD_LINK_SPEED_1600000MBPS, 81 }; 82 83 /* compare MAC addresses */ 84 #define MAC_ADDRESS_EQUAL(A, B) \ 85 ether_addr_equal_64bits((const u8 *)A, (const u8 *)B) 86 87 static const u16 ad_ticks_per_sec = 1000 / AD_TIMER_INTERVAL; 88 static const int ad_delta_in_ticks = (AD_TIMER_INTERVAL * HZ) / 1000; 89 90 const u8 lacpdu_mcast_addr[ETH_ALEN + 2] __long_aligned = { 91 0x01, 0x80, 0xC2, 0x00, 0x00, 0x02 92 }; 93 94 /* ================= main 802.3ad protocol functions ================== */ 95 static int ad_lacpdu_send(struct port *port); 96 static int ad_marker_send(struct port *port, struct bond_marker *marker); 97 static void ad_mux_machine(struct port *port, bool *update_slave_arr); 98 static void ad_rx_machine(struct lacpdu *lacpdu, struct port *port); 99 static void ad_tx_machine(struct port *port); 100 static void ad_periodic_machine(struct port *port); 101 static void ad_port_selection_logic(struct port *port, bool *update_slave_arr); 102 static void ad_agg_selection_logic(struct aggregator *aggregator, 103 bool *update_slave_arr); 104 static void ad_clear_agg(struct aggregator *aggregator); 105 static void ad_initialize_agg(struct aggregator *aggregator); 106 static void ad_initialize_port(struct port *port, const struct bond_params *bond_params); 107 static void ad_enable_collecting(struct port *port); 108 static void ad_disable_distributing(struct port *port, 109 bool *update_slave_arr); 110 static void ad_enable_collecting_distributing(struct port *port, 111 bool *update_slave_arr); 112 static void ad_disable_collecting_distributing(struct port *port, 113 bool *update_slave_arr); 114 static void ad_marker_info_received(struct bond_marker *marker_info, 115 struct port *port); 116 static void ad_marker_response_received(struct bond_marker *marker, 117 struct port *port); 118 static void ad_update_actor_keys(struct port *port, bool reset); 119 120 121 /* ================= api to bonding and kernel code ================== */ 122 123 /** 124 * __get_bond_by_port - get the port's bonding struct 125 * @port: the port we're looking at 126 * 127 * Return @port's bonding struct, or %NULL if it can't be found. 128 */ 129 static inline struct bonding *__get_bond_by_port(struct port *port) 130 { 131 if (port->slave == NULL) 132 return NULL; 133 134 return bond_get_bond_by_slave(port->slave); 135 } 136 137 /** 138 * __get_first_agg - get the first aggregator in the bond 139 * @port: the port we're looking at 140 * 141 * Return the aggregator of the first slave in @bond, or %NULL if it can't be 142 * found. 143 * The caller must hold RCU or RTNL lock. 144 */ 145 static inline struct aggregator *__get_first_agg(struct port *port) 146 { 147 struct bonding *bond = __get_bond_by_port(port); 148 struct slave *first_slave; 149 struct aggregator *agg; 150 151 /* If there's no bond for this port, or bond has no slaves */ 152 if (bond == NULL) 153 return NULL; 154 155 rcu_read_lock(); 156 first_slave = bond_first_slave_rcu(bond); 157 agg = first_slave ? &(SLAVE_AD_INFO(first_slave)->aggregator) : NULL; 158 rcu_read_unlock(); 159 160 return agg; 161 } 162 163 /** 164 * __agg_has_partner - see if we have a partner 165 * @agg: the agregator we're looking at 166 * 167 * Return nonzero if aggregator has a partner (denoted by a non-zero ether 168 * address for the partner). Return 0 if not. 169 */ 170 static inline int __agg_has_partner(struct aggregator *agg) 171 { 172 return !is_zero_ether_addr(agg->partner_system.mac_addr_value); 173 } 174 175 /** 176 * __disable_distributing_port - disable the port's slave for distributing. 177 * Port will still be able to collect. 178 * @port: the port we're looking at 179 * 180 * This will disable only distributing on the port's slave. 181 */ 182 static void __disable_distributing_port(struct port *port) 183 { 184 bond_set_slave_tx_disabled_flags(port->slave, BOND_SLAVE_NOTIFY_LATER); 185 } 186 187 /** 188 * __enable_collecting_port - enable the port's slave for collecting, 189 * if it's up 190 * @port: the port we're looking at 191 * 192 * This will enable only collecting on the port's slave. 193 */ 194 static void __enable_collecting_port(struct port *port) 195 { 196 struct slave *slave = port->slave; 197 198 if (slave->link == BOND_LINK_UP && bond_slave_is_up(slave)) 199 bond_set_slave_rx_enabled_flags(slave, BOND_SLAVE_NOTIFY_LATER); 200 } 201 202 /** 203 * __disable_port - disable the port's slave 204 * @port: the port we're looking at 205 * 206 * This will disable both collecting and distributing on the port's slave. 207 */ 208 static inline void __disable_port(struct port *port) 209 { 210 bond_set_slave_inactive_flags(port->slave, BOND_SLAVE_NOTIFY_LATER); 211 } 212 213 /** 214 * __enable_port - enable the port's slave, if it's up 215 * @port: the port we're looking at 216 * 217 * This will enable both collecting and distributing on the port's slave. 218 */ 219 static inline void __enable_port(struct port *port) 220 { 221 struct slave *slave = port->slave; 222 223 if ((slave->link == BOND_LINK_UP) && bond_slave_is_up(slave)) 224 bond_set_slave_active_flags(slave, BOND_SLAVE_NOTIFY_LATER); 225 } 226 227 /** 228 * __port_move_to_attached_state - check if port should transition back to attached 229 * state. 230 * @port: the port we're looking at 231 */ 232 static bool __port_move_to_attached_state(struct port *port) 233 { 234 if (!(port->sm_vars & AD_PORT_SELECTED) || 235 (port->sm_vars & AD_PORT_STANDBY) || 236 !(port->partner_oper.port_state & LACP_STATE_SYNCHRONIZATION) || 237 !(port->actor_oper_port_state & LACP_STATE_SYNCHRONIZATION)) 238 port->sm_mux_state = AD_MUX_ATTACHED; 239 240 return port->sm_mux_state == AD_MUX_ATTACHED; 241 } 242 243 /** 244 * __port_is_collecting_distributing - check if the port's slave is in the 245 * combined collecting/distributing state 246 * @port: the port we're looking at 247 */ 248 static int __port_is_collecting_distributing(struct port *port) 249 { 250 return bond_is_active_slave(port->slave); 251 } 252 253 /** 254 * __get_agg_selection_mode - get the aggregator selection mode 255 * @port: the port we're looking at 256 * 257 * Get the aggregator selection mode. Can be %STABLE, %BANDWIDTH or %COUNT. 258 */ 259 static inline u32 __get_agg_selection_mode(struct port *port) 260 { 261 struct bonding *bond = __get_bond_by_port(port); 262 263 if (bond == NULL) 264 return BOND_AD_STABLE; 265 266 return bond->params.ad_select; 267 } 268 269 /** 270 * __check_agg_selection_timer - check if the selection timer has expired 271 * @port: the port we're looking at 272 */ 273 static inline int __check_agg_selection_timer(struct port *port) 274 { 275 struct bonding *bond = __get_bond_by_port(port); 276 277 if (bond == NULL) 278 return 0; 279 280 return atomic_read(&BOND_AD_INFO(bond).agg_select_timer) ? 1 : 0; 281 } 282 283 /** 284 * __get_link_speed - get a port's speed 285 * @port: the port we're looking at 286 * 287 * Return @port's speed in 802.3ad enum format. i.e. one of: 288 * 0, 289 * %AD_LINK_SPEED_10MBPS, 290 * %AD_LINK_SPEED_100MBPS, 291 * %AD_LINK_SPEED_1000MBPS, 292 * %AD_LINK_SPEED_2500MBPS, 293 * %AD_LINK_SPEED_5000MBPS, 294 * %AD_LINK_SPEED_10000MBPS 295 * %AD_LINK_SPEED_14000MBPS, 296 * %AD_LINK_SPEED_20000MBPS 297 * %AD_LINK_SPEED_25000MBPS 298 * %AD_LINK_SPEED_40000MBPS 299 * %AD_LINK_SPEED_50000MBPS 300 * %AD_LINK_SPEED_56000MBPS 301 * %AD_LINK_SPEED_80000MBPS 302 * %AD_LINK_SPEED_100000MBPS 303 * %AD_LINK_SPEED_200000MBPS 304 * %AD_LINK_SPEED_400000MBPS 305 * %AD_LINK_SPEED_800000MBPS 306 * %AD_LINK_SPEED_1600000MBPS 307 */ 308 static u16 __get_link_speed(struct port *port) 309 { 310 struct slave *slave = port->slave; 311 u16 speed; 312 313 /* this if covers only a special case: when the configuration starts 314 * with link down, it sets the speed to 0. 315 * This is done in spite of the fact that the e100 driver reports 0 316 * to be compatible with MVT in the future. 317 */ 318 if (slave->link != BOND_LINK_UP) 319 speed = 0; 320 else { 321 switch (slave->speed) { 322 case SPEED_10: 323 speed = AD_LINK_SPEED_10MBPS; 324 break; 325 326 case SPEED_100: 327 speed = AD_LINK_SPEED_100MBPS; 328 break; 329 330 case SPEED_1000: 331 speed = AD_LINK_SPEED_1000MBPS; 332 break; 333 334 case SPEED_2500: 335 speed = AD_LINK_SPEED_2500MBPS; 336 break; 337 338 case SPEED_5000: 339 speed = AD_LINK_SPEED_5000MBPS; 340 break; 341 342 case SPEED_10000: 343 speed = AD_LINK_SPEED_10000MBPS; 344 break; 345 346 case SPEED_14000: 347 speed = AD_LINK_SPEED_14000MBPS; 348 break; 349 350 case SPEED_20000: 351 speed = AD_LINK_SPEED_20000MBPS; 352 break; 353 354 case SPEED_25000: 355 speed = AD_LINK_SPEED_25000MBPS; 356 break; 357 358 case SPEED_40000: 359 speed = AD_LINK_SPEED_40000MBPS; 360 break; 361 362 case SPEED_50000: 363 speed = AD_LINK_SPEED_50000MBPS; 364 break; 365 366 case SPEED_56000: 367 speed = AD_LINK_SPEED_56000MBPS; 368 break; 369 370 case SPEED_80000: 371 speed = AD_LINK_SPEED_80000MBPS; 372 break; 373 374 case SPEED_100000: 375 speed = AD_LINK_SPEED_100000MBPS; 376 break; 377 378 case SPEED_200000: 379 speed = AD_LINK_SPEED_200000MBPS; 380 break; 381 382 case SPEED_400000: 383 speed = AD_LINK_SPEED_400000MBPS; 384 break; 385 386 case SPEED_800000: 387 speed = AD_LINK_SPEED_800000MBPS; 388 break; 389 390 case SPEED_1600000: 391 speed = AD_LINK_SPEED_1600000MBPS; 392 break; 393 394 default: 395 /* unknown speed value from ethtool. shouldn't happen */ 396 if (slave->speed != SPEED_UNKNOWN) 397 pr_err_once("%s: (slave %s): unknown ethtool speed (%d) for port %d (set it to 0)\n", 398 slave->bond->dev->name, 399 slave->dev->name, slave->speed, 400 port->actor_port_number); 401 speed = 0; 402 break; 403 } 404 } 405 406 slave_dbg(slave->bond->dev, slave->dev, "Port %d Received link speed %d update from adapter\n", 407 port->actor_port_number, speed); 408 return speed; 409 } 410 411 /** 412 * __get_duplex - get a port's duplex 413 * @port: the port we're looking at 414 * 415 * Return @port's duplex in 802.3ad bitmask format. i.e.: 416 * 0x01 if in full duplex 417 * 0x00 otherwise 418 */ 419 static u8 __get_duplex(struct port *port) 420 { 421 struct slave *slave = port->slave; 422 u8 retval = 0x0; 423 424 /* handling a special case: when the configuration starts with 425 * link down, it sets the duplex to 0. 426 */ 427 if (slave->link == BOND_LINK_UP) { 428 switch (slave->duplex) { 429 case DUPLEX_FULL: 430 retval = 0x1; 431 slave_dbg(slave->bond->dev, slave->dev, "Port %d Received status full duplex update from adapter\n", 432 port->actor_port_number); 433 break; 434 case DUPLEX_HALF: 435 default: 436 retval = 0x0; 437 slave_dbg(slave->bond->dev, slave->dev, "Port %d Received status NOT full duplex update from adapter\n", 438 port->actor_port_number); 439 break; 440 } 441 } 442 return retval; 443 } 444 445 static void __ad_actor_update_port(struct port *port) 446 { 447 const struct bonding *bond = bond_get_bond_by_slave(port->slave); 448 449 port->actor_system = BOND_AD_INFO(bond).system.sys_mac_addr; 450 port->actor_system_priority = BOND_AD_INFO(bond).system.sys_priority; 451 port->actor_port_priority = SLAVE_AD_INFO(port->slave)->port_priority; 452 } 453 454 /* Conversions */ 455 456 /** 457 * __ad_timer_to_ticks - convert a given timer type to AD module ticks 458 * @timer_type: which timer to operate 459 * @par: timer parameter. see below 460 * 461 * If @timer_type is %current_while_timer, @par indicates long/short timer. 462 * If @timer_type is %periodic_timer, @par is one of %FAST_PERIODIC_TIME, 463 * %SLOW_PERIODIC_TIME. 464 */ 465 static u16 __ad_timer_to_ticks(u16 timer_type, u16 par) 466 { 467 u16 retval = 0; /* to silence the compiler */ 468 469 switch (timer_type) { 470 case AD_CURRENT_WHILE_TIMER: /* for rx machine usage */ 471 if (par) 472 retval = (AD_SHORT_TIMEOUT_TIME*ad_ticks_per_sec); 473 else 474 retval = (AD_LONG_TIMEOUT_TIME*ad_ticks_per_sec); 475 break; 476 case AD_ACTOR_CHURN_TIMER: /* for local churn machine */ 477 retval = (AD_CHURN_DETECTION_TIME*ad_ticks_per_sec); 478 break; 479 case AD_PERIODIC_TIMER: /* for periodic machine */ 480 retval = (par*ad_ticks_per_sec); /* long timeout */ 481 break; 482 case AD_PARTNER_CHURN_TIMER: /* for remote churn machine */ 483 retval = (AD_CHURN_DETECTION_TIME*ad_ticks_per_sec); 484 break; 485 case AD_WAIT_WHILE_TIMER: /* for selection machine */ 486 retval = (AD_AGGREGATE_WAIT_TIME*ad_ticks_per_sec); 487 break; 488 } 489 490 return retval; 491 } 492 493 494 /* ================= ad_rx_machine helper functions ================== */ 495 496 /** 497 * __choose_matched - update a port's matched variable from a received lacpdu 498 * @lacpdu: the lacpdu we've received 499 * @port: the port we're looking at 500 * 501 * Update the value of the matched variable, using parameter values from a 502 * newly received lacpdu. Parameter values for the partner carried in the 503 * received PDU are compared with the corresponding operational parameter 504 * values for the actor. Matched is set to TRUE if all of these parameters 505 * match and the PDU parameter partner_state.aggregation has the same value as 506 * actor_oper_port_state.aggregation and lacp will actively maintain the link 507 * in the aggregation. Matched is also set to TRUE if the value of 508 * actor_state.aggregation in the received PDU is set to FALSE, i.e., indicates 509 * an individual link and lacp will actively maintain the link. Otherwise, 510 * matched is set to FALSE. LACP is considered to be actively maintaining the 511 * link if either the PDU's actor_state.lacp_activity variable is TRUE or both 512 * the actor's actor_oper_port_state.lacp_activity and the PDU's 513 * partner_state.lacp_activity variables are TRUE. 514 * 515 * Note: the AD_PORT_MATCHED "variable" is not specified by 802.3ad; it is 516 * used here to implement the language from 802.3ad 43.4.9 that requires 517 * recordPDU to "match" the LACPDU parameters to the stored values. 518 */ 519 static void __choose_matched(struct lacpdu *lacpdu, struct port *port) 520 { 521 /* check if all parameters are alike 522 * or this is individual link(aggregation == FALSE) 523 * then update the state machine Matched variable. 524 */ 525 if (((ntohs(lacpdu->partner_port) == port->actor_port_number) && 526 (ntohs(lacpdu->partner_port_priority) == port->actor_port_priority) && 527 MAC_ADDRESS_EQUAL(&(lacpdu->partner_system), &(port->actor_system)) && 528 (ntohs(lacpdu->partner_system_priority) == port->actor_system_priority) && 529 (ntohs(lacpdu->partner_key) == port->actor_oper_port_key) && 530 ((lacpdu->partner_state & LACP_STATE_AGGREGATION) == (port->actor_oper_port_state & LACP_STATE_AGGREGATION))) || 531 ((lacpdu->actor_state & LACP_STATE_AGGREGATION) == 0) 532 ) { 533 port->sm_vars |= AD_PORT_MATCHED; 534 } else { 535 port->sm_vars &= ~AD_PORT_MATCHED; 536 } 537 } 538 539 /** 540 * __record_pdu - record parameters from a received lacpdu 541 * @lacpdu: the lacpdu we've received 542 * @port: the port we're looking at 543 * 544 * Record the parameter values for the Actor carried in a received lacpdu as 545 * the current partner operational parameter values and sets 546 * actor_oper_port_state.defaulted to FALSE. 547 */ 548 static void __record_pdu(struct lacpdu *lacpdu, struct port *port) 549 { 550 if (lacpdu && port) { 551 struct port_params *partner = &port->partner_oper; 552 553 __choose_matched(lacpdu, port); 554 /* record the new parameter values for the partner 555 * operational 556 */ 557 partner->port_number = ntohs(lacpdu->actor_port); 558 partner->port_priority = ntohs(lacpdu->actor_port_priority); 559 partner->system = lacpdu->actor_system; 560 partner->system_priority = ntohs(lacpdu->actor_system_priority); 561 partner->key = ntohs(lacpdu->actor_key); 562 partner->port_state = lacpdu->actor_state; 563 564 /* set actor_oper_port_state.defaulted to FALSE */ 565 port->actor_oper_port_state &= ~LACP_STATE_DEFAULTED; 566 567 /* set the partner sync. to on if the partner is sync, 568 * and the port is matched 569 */ 570 if ((port->sm_vars & AD_PORT_MATCHED) && 571 (lacpdu->actor_state & LACP_STATE_SYNCHRONIZATION)) { 572 partner->port_state |= LACP_STATE_SYNCHRONIZATION; 573 slave_dbg(port->slave->bond->dev, port->slave->dev, 574 "partner sync=1\n"); 575 } else { 576 partner->port_state &= ~LACP_STATE_SYNCHRONIZATION; 577 slave_dbg(port->slave->bond->dev, port->slave->dev, 578 "partner sync=0\n"); 579 } 580 } 581 } 582 583 /** 584 * __record_default - record default parameters 585 * @port: the port we're looking at 586 * 587 * This function records the default parameter values for the partner carried 588 * in the Partner Admin parameters as the current partner operational parameter 589 * values and sets actor_oper_port_state.defaulted to TRUE. 590 */ 591 static void __record_default(struct port *port) 592 { 593 if (port) { 594 /* record the partner admin parameters */ 595 memcpy(&port->partner_oper, &port->partner_admin, 596 sizeof(struct port_params)); 597 598 /* set actor_oper_port_state.defaulted to true */ 599 port->actor_oper_port_state |= LACP_STATE_DEFAULTED; 600 } 601 } 602 603 /** 604 * __update_selected - update a port's Selected variable from a received lacpdu 605 * @lacpdu: the lacpdu we've received 606 * @port: the port we're looking at 607 * 608 * Update the value of the selected variable, using parameter values from a 609 * newly received lacpdu. The parameter values for the Actor carried in the 610 * received PDU are compared with the corresponding operational parameter 611 * values for the ports partner. If one or more of the comparisons shows that 612 * the value(s) received in the PDU differ from the current operational values, 613 * then selected is set to FALSE and actor_oper_port_state.synchronization is 614 * set to out_of_sync. Otherwise, selected remains unchanged. 615 */ 616 static void __update_selected(struct lacpdu *lacpdu, struct port *port) 617 { 618 if (lacpdu && port) { 619 const struct port_params *partner = &port->partner_oper; 620 621 /* check if any parameter is different then 622 * update the state machine selected variable. 623 */ 624 if (ntohs(lacpdu->actor_port) != partner->port_number || 625 ntohs(lacpdu->actor_port_priority) != partner->port_priority || 626 !MAC_ADDRESS_EQUAL(&lacpdu->actor_system, &partner->system) || 627 ntohs(lacpdu->actor_system_priority) != partner->system_priority || 628 ntohs(lacpdu->actor_key) != partner->key || 629 (lacpdu->actor_state & LACP_STATE_AGGREGATION) != (partner->port_state & LACP_STATE_AGGREGATION)) { 630 port->sm_vars &= ~AD_PORT_SELECTED; 631 } 632 } 633 } 634 635 /** 636 * __update_default_selected - update a port's Selected variable from Partner 637 * @port: the port we're looking at 638 * 639 * This function updates the value of the selected variable, using the partner 640 * administrative parameter values. The administrative values are compared with 641 * the corresponding operational parameter values for the partner. If one or 642 * more of the comparisons shows that the administrative value(s) differ from 643 * the current operational values, then Selected is set to FALSE and 644 * actor_oper_port_state.synchronization is set to OUT_OF_SYNC. Otherwise, 645 * Selected remains unchanged. 646 */ 647 static void __update_default_selected(struct port *port) 648 { 649 if (port) { 650 const struct port_params *admin = &port->partner_admin; 651 const struct port_params *oper = &port->partner_oper; 652 653 /* check if any parameter is different then 654 * update the state machine selected variable. 655 */ 656 if (admin->port_number != oper->port_number || 657 admin->port_priority != oper->port_priority || 658 !MAC_ADDRESS_EQUAL(&admin->system, &oper->system) || 659 admin->system_priority != oper->system_priority || 660 admin->key != oper->key || 661 (admin->port_state & LACP_STATE_AGGREGATION) 662 != (oper->port_state & LACP_STATE_AGGREGATION)) { 663 port->sm_vars &= ~AD_PORT_SELECTED; 664 } 665 } 666 } 667 668 /** 669 * __update_ntt - update a port's ntt variable from a received lacpdu 670 * @lacpdu: the lacpdu we've received 671 * @port: the port we're looking at 672 * 673 * Updates the value of the ntt variable, using parameter values from a newly 674 * received lacpdu. The parameter values for the partner carried in the 675 * received PDU are compared with the corresponding operational parameter 676 * values for the Actor. If one or more of the comparisons shows that the 677 * value(s) received in the PDU differ from the current operational values, 678 * then ntt is set to TRUE. Otherwise, ntt remains unchanged. 679 */ 680 static void __update_ntt(struct lacpdu *lacpdu, struct port *port) 681 { 682 /* validate lacpdu and port */ 683 if (lacpdu && port) { 684 /* check if any parameter is different then 685 * update the port->ntt. 686 */ 687 if ((ntohs(lacpdu->partner_port) != port->actor_port_number) || 688 (ntohs(lacpdu->partner_port_priority) != port->actor_port_priority) || 689 !MAC_ADDRESS_EQUAL(&(lacpdu->partner_system), &(port->actor_system)) || 690 (ntohs(lacpdu->partner_system_priority) != port->actor_system_priority) || 691 (ntohs(lacpdu->partner_key) != port->actor_oper_port_key) || 692 ((lacpdu->partner_state & LACP_STATE_LACP_ACTIVITY) != (port->actor_oper_port_state & LACP_STATE_LACP_ACTIVITY)) || 693 ((lacpdu->partner_state & LACP_STATE_LACP_TIMEOUT) != (port->actor_oper_port_state & LACP_STATE_LACP_TIMEOUT)) || 694 ((lacpdu->partner_state & LACP_STATE_SYNCHRONIZATION) != (port->actor_oper_port_state & LACP_STATE_SYNCHRONIZATION)) || 695 ((lacpdu->partner_state & LACP_STATE_AGGREGATION) != (port->actor_oper_port_state & LACP_STATE_AGGREGATION)) 696 ) { 697 port->ntt = true; 698 } 699 } 700 } 701 702 /** 703 * __agg_ports_are_ready - check if all ports in an aggregator are ready 704 * @aggregator: the aggregator we're looking at 705 * 706 */ 707 static int __agg_ports_are_ready(struct aggregator *aggregator) 708 { 709 struct port *port; 710 int retval = 1; 711 712 if (aggregator) { 713 /* scan all ports in this aggregator to verfy if they are 714 * all ready. 715 */ 716 for (port = aggregator->lag_ports; 717 port; 718 port = port->next_port_in_aggregator) { 719 if (!(port->sm_vars & AD_PORT_READY_N)) { 720 retval = 0; 721 break; 722 } 723 } 724 } 725 726 return retval; 727 } 728 729 /** 730 * __set_agg_ports_ready - set value of Ready bit in all ports of an aggregator 731 * @aggregator: the aggregator we're looking at 732 * @val: Should the ports' ready bit be set on or off 733 * 734 */ 735 static void __set_agg_ports_ready(struct aggregator *aggregator, int val) 736 { 737 struct port *port; 738 739 for (port = aggregator->lag_ports; port; 740 port = port->next_port_in_aggregator) { 741 if (val) 742 port->sm_vars |= AD_PORT_READY; 743 else 744 port->sm_vars &= ~AD_PORT_READY; 745 } 746 } 747 748 static int __agg_usable_ports(struct aggregator *agg) 749 { 750 struct port *port; 751 int valid = 0; 752 753 for (port = agg->lag_ports; port; 754 port = port->next_port_in_aggregator) { 755 if (port->actor_oper_port_state & LACP_STATE_COLLECTING && 756 port->actor_oper_port_state & LACP_STATE_DISTRIBUTING) 757 valid++; 758 } 759 760 return valid; 761 } 762 763 static int __agg_active_ports(const struct aggregator *agg) 764 { 765 const struct port *port; 766 int active = 0; 767 768 for (port = agg->lag_ports; port; 769 port = port->next_port_in_aggregator) { 770 if (READ_ONCE(port->is_enabled)) 771 active++; 772 } 773 774 return active; 775 } 776 777 static unsigned int __agg_ports_priority(const struct aggregator *agg) 778 { 779 struct port *port = agg->lag_ports; 780 unsigned int prio = 0; 781 782 for (; port; port = port->next_port_in_aggregator) 783 if (port->is_enabled) 784 prio += port->actor_port_priority; 785 786 return prio; 787 } 788 789 /** 790 * __get_agg_bandwidth - get the total bandwidth of an aggregator 791 * @aggregator: the aggregator we're looking at 792 * 793 */ 794 static u32 __get_agg_bandwidth(struct aggregator *aggregator) 795 { 796 int nports = __agg_active_ports(aggregator); 797 u32 bandwidth = 0; 798 799 if (nports) { 800 switch (__get_link_speed(aggregator->lag_ports)) { 801 case AD_LINK_SPEED_1MBPS: 802 bandwidth = nports; 803 break; 804 case AD_LINK_SPEED_10MBPS: 805 bandwidth = nports * 10; 806 break; 807 case AD_LINK_SPEED_100MBPS: 808 bandwidth = nports * 100; 809 break; 810 case AD_LINK_SPEED_1000MBPS: 811 bandwidth = nports * 1000; 812 break; 813 case AD_LINK_SPEED_2500MBPS: 814 bandwidth = nports * 2500; 815 break; 816 case AD_LINK_SPEED_5000MBPS: 817 bandwidth = nports * 5000; 818 break; 819 case AD_LINK_SPEED_10000MBPS: 820 bandwidth = nports * 10000; 821 break; 822 case AD_LINK_SPEED_14000MBPS: 823 bandwidth = nports * 14000; 824 break; 825 case AD_LINK_SPEED_20000MBPS: 826 bandwidth = nports * 20000; 827 break; 828 case AD_LINK_SPEED_25000MBPS: 829 bandwidth = nports * 25000; 830 break; 831 case AD_LINK_SPEED_40000MBPS: 832 bandwidth = nports * 40000; 833 break; 834 case AD_LINK_SPEED_50000MBPS: 835 bandwidth = nports * 50000; 836 break; 837 case AD_LINK_SPEED_56000MBPS: 838 bandwidth = nports * 56000; 839 break; 840 case AD_LINK_SPEED_80000MBPS: 841 bandwidth = nports * 80000; 842 break; 843 case AD_LINK_SPEED_100000MBPS: 844 bandwidth = nports * 100000; 845 break; 846 case AD_LINK_SPEED_200000MBPS: 847 bandwidth = nports * 200000; 848 break; 849 case AD_LINK_SPEED_400000MBPS: 850 bandwidth = nports * 400000; 851 break; 852 case AD_LINK_SPEED_800000MBPS: 853 bandwidth = nports * 800000; 854 break; 855 case AD_LINK_SPEED_1600000MBPS: 856 bandwidth = nports * 1600000; 857 break; 858 default: 859 bandwidth = 0; /* to silence the compiler */ 860 } 861 } 862 return bandwidth; 863 } 864 865 /** 866 * __get_active_agg - get the current active aggregator 867 * @aggregator: the aggregator we're looking at 868 * 869 * Caller must hold RCU lock. 870 */ 871 static struct aggregator *__get_active_agg(struct aggregator *aggregator) 872 { 873 struct bonding *bond = aggregator->slave->bond; 874 struct list_head *iter; 875 struct slave *slave; 876 877 bond_for_each_slave_rcu(bond, slave, iter) 878 if (SLAVE_AD_INFO(slave)->aggregator.is_active) 879 return &(SLAVE_AD_INFO(slave)->aggregator); 880 881 return NULL; 882 } 883 884 /** 885 * __update_lacpdu_from_port - update a port's lacpdu fields 886 * @port: the port we're looking at 887 */ 888 static inline void __update_lacpdu_from_port(struct port *port) 889 { 890 struct lacpdu *lacpdu = &port->lacpdu; 891 const struct port_params *partner = &port->partner_oper; 892 893 /* update current actual Actor parameters 894 * lacpdu->subtype initialized 895 * lacpdu->version_number initialized 896 * lacpdu->tlv_type_actor_info initialized 897 * lacpdu->actor_information_length initialized 898 */ 899 900 lacpdu->actor_system_priority = htons(port->actor_system_priority); 901 lacpdu->actor_system = port->actor_system; 902 lacpdu->actor_key = htons(port->actor_oper_port_key); 903 lacpdu->actor_port_priority = htons(port->actor_port_priority); 904 lacpdu->actor_port = htons(port->actor_port_number); 905 lacpdu->actor_state = port->actor_oper_port_state; 906 slave_dbg(port->slave->bond->dev, port->slave->dev, 907 "update lacpdu: actor port state %x\n", 908 port->actor_oper_port_state); 909 910 /* lacpdu->reserved_3_1 initialized 911 * lacpdu->tlv_type_partner_info initialized 912 * lacpdu->partner_information_length initialized 913 */ 914 915 lacpdu->partner_system_priority = htons(partner->system_priority); 916 lacpdu->partner_system = partner->system; 917 lacpdu->partner_key = htons(partner->key); 918 lacpdu->partner_port_priority = htons(partner->port_priority); 919 lacpdu->partner_port = htons(partner->port_number); 920 lacpdu->partner_state = partner->port_state; 921 922 /* lacpdu->reserved_3_2 initialized 923 * lacpdu->tlv_type_collector_info initialized 924 * lacpdu->collector_information_length initialized 925 * collector_max_delay initialized 926 * reserved_12[12] initialized 927 * tlv_type_terminator initialized 928 * terminator_length initialized 929 * reserved_50[50] initialized 930 */ 931 } 932 933 /* ================= main 802.3ad protocol code ========================= */ 934 935 /** 936 * ad_lacpdu_send - send out a lacpdu packet on a given port 937 * @port: the port we're looking at 938 * 939 * Returns: 0 on success 940 * < 0 on error 941 */ 942 static int ad_lacpdu_send(struct port *port) 943 { 944 struct slave *slave = port->slave; 945 struct sk_buff *skb; 946 struct lacpdu_header *lacpdu_header; 947 int length = sizeof(struct lacpdu_header); 948 949 skb = dev_alloc_skb(length); 950 if (!skb) 951 return -ENOMEM; 952 953 atomic64_inc(&SLAVE_AD_INFO(slave)->stats.lacpdu_tx); 954 atomic64_inc(&BOND_AD_INFO(slave->bond).stats.lacpdu_tx); 955 956 skb->dev = slave->dev; 957 skb_reset_mac_header(skb); 958 skb->network_header = skb->mac_header + ETH_HLEN; 959 skb->protocol = PKT_TYPE_LACPDU; 960 skb->priority = TC_PRIO_CONTROL; 961 962 lacpdu_header = skb_put(skb, length); 963 964 ether_addr_copy(lacpdu_header->hdr.h_dest, lacpdu_mcast_addr); 965 /* Note: source address is set to be the member's PERMANENT address, 966 * because we use it to identify loopback lacpdus in receive. 967 */ 968 ether_addr_copy(lacpdu_header->hdr.h_source, slave->perm_hwaddr); 969 lacpdu_header->hdr.h_proto = PKT_TYPE_LACPDU; 970 971 lacpdu_header->lacpdu = port->lacpdu; 972 973 dev_queue_xmit(skb); 974 975 return 0; 976 } 977 978 /** 979 * ad_marker_send - send marker information/response on a given port 980 * @port: the port we're looking at 981 * @marker: marker data to send 982 * 983 * Returns: 0 on success 984 * < 0 on error 985 */ 986 static int ad_marker_send(struct port *port, struct bond_marker *marker) 987 { 988 struct slave *slave = port->slave; 989 struct sk_buff *skb; 990 struct bond_marker_header *marker_header; 991 int length = sizeof(struct bond_marker_header); 992 993 skb = dev_alloc_skb(length + 16); 994 if (!skb) 995 return -ENOMEM; 996 997 switch (marker->tlv_type) { 998 case AD_MARKER_INFORMATION_SUBTYPE: 999 atomic64_inc(&SLAVE_AD_INFO(slave)->stats.marker_tx); 1000 atomic64_inc(&BOND_AD_INFO(slave->bond).stats.marker_tx); 1001 break; 1002 case AD_MARKER_RESPONSE_SUBTYPE: 1003 atomic64_inc(&SLAVE_AD_INFO(slave)->stats.marker_resp_tx); 1004 atomic64_inc(&BOND_AD_INFO(slave->bond).stats.marker_resp_tx); 1005 break; 1006 } 1007 1008 skb_reserve(skb, 16); 1009 1010 skb->dev = slave->dev; 1011 skb_reset_mac_header(skb); 1012 skb->network_header = skb->mac_header + ETH_HLEN; 1013 skb->protocol = PKT_TYPE_LACPDU; 1014 1015 marker_header = skb_put(skb, length); 1016 1017 ether_addr_copy(marker_header->hdr.h_dest, lacpdu_mcast_addr); 1018 /* Note: source address is set to be the member's PERMANENT address, 1019 * because we use it to identify loopback MARKERs in receive. 1020 */ 1021 ether_addr_copy(marker_header->hdr.h_source, slave->perm_hwaddr); 1022 marker_header->hdr.h_proto = PKT_TYPE_LACPDU; 1023 1024 marker_header->marker = *marker; 1025 1026 dev_queue_xmit(skb); 1027 1028 return 0; 1029 } 1030 1031 static void ad_cond_set_peer_notif(struct port *port) 1032 { 1033 struct bonding *bond = port->slave->bond; 1034 1035 if (bond->params.broadcast_neighbor) 1036 bond_peer_notify_work_rearm(bond, 0); 1037 } 1038 1039 /** 1040 * ad_mux_machine - handle a port's mux state machine 1041 * @port: the port we're looking at 1042 * @update_slave_arr: Does slave array need update? 1043 */ 1044 static void ad_mux_machine(struct port *port, bool *update_slave_arr) 1045 { 1046 struct bonding *bond = __get_bond_by_port(port); 1047 struct aggregator *aggregator; 1048 mux_states_t last_state; 1049 1050 /* keep current State Machine state to compare later if it was 1051 * changed 1052 */ 1053 last_state = port->sm_mux_state; 1054 1055 aggregator = rcu_dereference(port->aggregator); 1056 if (port->sm_vars & AD_PORT_BEGIN) { 1057 port->sm_mux_state = AD_MUX_DETACHED; 1058 } else { 1059 switch (port->sm_mux_state) { 1060 case AD_MUX_DETACHED: 1061 if ((port->sm_vars & AD_PORT_SELECTED) 1062 || (port->sm_vars & AD_PORT_STANDBY)) 1063 /* if SELECTED or STANDBY */ 1064 port->sm_mux_state = AD_MUX_WAITING; 1065 break; 1066 case AD_MUX_WAITING: 1067 /* if SELECTED == FALSE return to DETACH state */ 1068 if (!(port->sm_vars & AD_PORT_SELECTED)) { 1069 port->sm_vars &= ~AD_PORT_READY_N; 1070 /* in order to withhold the Selection Logic to 1071 * check all ports READY_N value every callback 1072 * cycle to update ready variable, we check 1073 * READY_N and update READY here 1074 */ 1075 __set_agg_ports_ready(aggregator, __agg_ports_are_ready(aggregator)); 1076 port->sm_mux_state = AD_MUX_DETACHED; 1077 break; 1078 } 1079 1080 /* check if the wait_while_timer expired */ 1081 if (port->sm_mux_timer_counter 1082 && !(--port->sm_mux_timer_counter)) 1083 port->sm_vars |= AD_PORT_READY_N; 1084 1085 /* in order to withhold the selection logic to check 1086 * all ports READY_N value every callback cycle to 1087 * update ready variable, we check READY_N and update 1088 * READY here 1089 */ 1090 __set_agg_ports_ready(aggregator, __agg_ports_are_ready(aggregator)); 1091 1092 /* if the wait_while_timer expired, and the port is 1093 * in READY state, move to ATTACHED state 1094 */ 1095 if ((port->sm_vars & AD_PORT_READY) 1096 && !port->sm_mux_timer_counter) 1097 port->sm_mux_state = AD_MUX_ATTACHED; 1098 break; 1099 case AD_MUX_ATTACHED: 1100 /* check also if agg_select_timer expired (so the 1101 * edable port will take place only after this timer) 1102 */ 1103 if ((port->sm_vars & AD_PORT_SELECTED) && 1104 (port->partner_oper.port_state & LACP_STATE_SYNCHRONIZATION) && 1105 !__check_agg_selection_timer(port)) { 1106 if (aggregator->is_active) { 1107 int state = AD_MUX_COLLECTING_DISTRIBUTING; 1108 1109 if (!bond->params.coupled_control) 1110 state = AD_MUX_COLLECTING; 1111 port->sm_mux_state = state; 1112 } 1113 } else if (!(port->sm_vars & AD_PORT_SELECTED) || 1114 (port->sm_vars & AD_PORT_STANDBY)) { 1115 /* if UNSELECTED or STANDBY */ 1116 port->sm_vars &= ~AD_PORT_READY_N; 1117 /* in order to withhold the selection logic to 1118 * check all ports READY_N value every callback 1119 * cycle to update ready variable, we check 1120 * READY_N and update READY here 1121 */ 1122 __set_agg_ports_ready(aggregator, __agg_ports_are_ready(aggregator)); 1123 port->sm_mux_state = AD_MUX_DETACHED; 1124 } else if (aggregator->is_active) { 1125 port->actor_oper_port_state |= 1126 LACP_STATE_SYNCHRONIZATION; 1127 } 1128 break; 1129 case AD_MUX_COLLECTING_DISTRIBUTING: 1130 if (!__port_move_to_attached_state(port)) { 1131 /* if port state hasn't changed make 1132 * sure that a collecting distributing 1133 * port in an active aggregator is enabled 1134 */ 1135 if (aggregator->is_active && 1136 !__port_is_collecting_distributing(port)) { 1137 __enable_port(port); 1138 *update_slave_arr = true; 1139 } 1140 } 1141 break; 1142 case AD_MUX_COLLECTING: 1143 if (!__port_move_to_attached_state(port)) { 1144 if ((port->sm_vars & AD_PORT_SELECTED) && 1145 (port->partner_oper.port_state & LACP_STATE_SYNCHRONIZATION) && 1146 (port->partner_oper.port_state & LACP_STATE_COLLECTING)) { 1147 port->sm_mux_state = AD_MUX_DISTRIBUTING; 1148 } else { 1149 /* If port state hasn't changed, make sure that a collecting 1150 * port is enabled for an active aggregator. 1151 */ 1152 struct slave *slave = port->slave; 1153 1154 if (aggregator->is_active && 1155 bond_is_slave_rx_disabled(slave)) { 1156 ad_enable_collecting(port); 1157 *update_slave_arr = true; 1158 } 1159 } 1160 } 1161 break; 1162 case AD_MUX_DISTRIBUTING: 1163 if (!(port->sm_vars & AD_PORT_SELECTED) || 1164 (port->sm_vars & AD_PORT_STANDBY) || 1165 !(port->partner_oper.port_state & LACP_STATE_COLLECTING) || 1166 !(port->partner_oper.port_state & LACP_STATE_SYNCHRONIZATION) || 1167 !(port->actor_oper_port_state & LACP_STATE_SYNCHRONIZATION)) { 1168 port->sm_mux_state = AD_MUX_COLLECTING; 1169 } else { 1170 /* if port state hasn't changed make 1171 * sure that a collecting distributing 1172 * port in an active aggregator is enabled 1173 */ 1174 if (aggregator && 1175 aggregator->is_active && 1176 !__port_is_collecting_distributing(port)) { 1177 __enable_port(port); 1178 *update_slave_arr = true; 1179 } 1180 } 1181 break; 1182 default: 1183 break; 1184 } 1185 } 1186 1187 /* check if the state machine was changed */ 1188 if (port->sm_mux_state != last_state) { 1189 slave_dbg(port->slave->bond->dev, port->slave->dev, 1190 "Mux Machine: Port=%d, Last State=%d, Curr State=%d\n", 1191 port->actor_port_number, 1192 last_state, 1193 port->sm_mux_state); 1194 switch (port->sm_mux_state) { 1195 case AD_MUX_DETACHED: 1196 port->actor_oper_port_state &= ~LACP_STATE_SYNCHRONIZATION; 1197 port->actor_oper_port_state &= ~LACP_STATE_COLLECTING; 1198 port->actor_oper_port_state &= ~LACP_STATE_DISTRIBUTING; 1199 ad_disable_collecting_distributing(port, 1200 update_slave_arr); 1201 port->ntt = true; 1202 break; 1203 case AD_MUX_WAITING: 1204 port->sm_mux_timer_counter = __ad_timer_to_ticks(AD_WAIT_WHILE_TIMER, 0); 1205 break; 1206 case AD_MUX_ATTACHED: 1207 if (aggregator->is_active) 1208 port->actor_oper_port_state |= 1209 LACP_STATE_SYNCHRONIZATION; 1210 else 1211 port->actor_oper_port_state &= 1212 ~LACP_STATE_SYNCHRONIZATION; 1213 port->actor_oper_port_state &= ~LACP_STATE_COLLECTING; 1214 port->actor_oper_port_state &= ~LACP_STATE_DISTRIBUTING; 1215 ad_disable_collecting_distributing(port, 1216 update_slave_arr); 1217 port->ntt = true; 1218 break; 1219 case AD_MUX_COLLECTING_DISTRIBUTING: 1220 port->actor_oper_port_state |= LACP_STATE_COLLECTING; 1221 port->actor_oper_port_state |= LACP_STATE_DISTRIBUTING; 1222 port->actor_oper_port_state |= LACP_STATE_SYNCHRONIZATION; 1223 ad_enable_collecting_distributing(port, 1224 update_slave_arr); 1225 port->ntt = true; 1226 break; 1227 case AD_MUX_COLLECTING: 1228 port->actor_oper_port_state |= LACP_STATE_COLLECTING; 1229 port->actor_oper_port_state &= ~LACP_STATE_DISTRIBUTING; 1230 port->actor_oper_port_state |= LACP_STATE_SYNCHRONIZATION; 1231 ad_enable_collecting(port); 1232 ad_disable_distributing(port, update_slave_arr); 1233 port->ntt = true; 1234 break; 1235 case AD_MUX_DISTRIBUTING: 1236 port->actor_oper_port_state |= LACP_STATE_DISTRIBUTING; 1237 port->actor_oper_port_state |= LACP_STATE_SYNCHRONIZATION; 1238 ad_enable_collecting_distributing(port, 1239 update_slave_arr); 1240 break; 1241 default: 1242 break; 1243 } 1244 } 1245 } 1246 1247 /** 1248 * ad_rx_machine - handle a port's rx State Machine 1249 * @lacpdu: the lacpdu we've received 1250 * @port: the port we're looking at 1251 * 1252 * If lacpdu arrived, stop previous timer (if exists) and set the next state as 1253 * CURRENT. If timer expired set the state machine in the proper state. 1254 * In other cases, this function checks if we need to switch to other state. 1255 */ 1256 static void ad_rx_machine(struct lacpdu *lacpdu, struct port *port) 1257 { 1258 rx_states_t last_state; 1259 1260 /* keep current State Machine state to compare later if it was 1261 * changed 1262 */ 1263 last_state = port->sm_rx_state; 1264 1265 if (lacpdu) { 1266 atomic64_inc(&SLAVE_AD_INFO(port->slave)->stats.lacpdu_rx); 1267 atomic64_inc(&BOND_AD_INFO(port->slave->bond).stats.lacpdu_rx); 1268 } 1269 /* check if state machine should change state */ 1270 1271 /* first, check if port was reinitialized */ 1272 if (port->sm_vars & AD_PORT_BEGIN) { 1273 port->sm_rx_state = AD_RX_INITIALIZE; 1274 port->sm_vars |= AD_PORT_CHURNED; 1275 /* check if port is not enabled */ 1276 } else if (!(port->sm_vars & AD_PORT_BEGIN) && !port->is_enabled) 1277 port->sm_rx_state = AD_RX_PORT_DISABLED; 1278 /* check if new lacpdu arrived */ 1279 else if (lacpdu && ((port->sm_rx_state == AD_RX_EXPIRED) || 1280 (port->sm_rx_state == AD_RX_DEFAULTED) || 1281 (port->sm_rx_state == AD_RX_CURRENT))) { 1282 if (port->sm_rx_state != AD_RX_CURRENT) 1283 port->sm_vars |= AD_PORT_CHURNED; 1284 port->sm_rx_timer_counter = 0; 1285 port->sm_rx_state = AD_RX_CURRENT; 1286 } else { 1287 /* if timer is on, and if it is expired */ 1288 if (port->sm_rx_timer_counter && 1289 !(--port->sm_rx_timer_counter)) { 1290 switch (port->sm_rx_state) { 1291 case AD_RX_EXPIRED: 1292 port->sm_rx_state = AD_RX_DEFAULTED; 1293 break; 1294 case AD_RX_CURRENT: 1295 port->sm_rx_state = AD_RX_EXPIRED; 1296 break; 1297 default: 1298 break; 1299 } 1300 } else { 1301 /* if no lacpdu arrived and no timer is on */ 1302 switch (port->sm_rx_state) { 1303 case AD_RX_PORT_DISABLED: 1304 if (port->is_enabled && 1305 (port->sm_vars & AD_PORT_LACP_ENABLED)) 1306 port->sm_rx_state = AD_RX_EXPIRED; 1307 else if (port->is_enabled 1308 && ((port->sm_vars 1309 & AD_PORT_LACP_ENABLED) == 0)) 1310 port->sm_rx_state = AD_RX_LACP_DISABLED; 1311 break; 1312 default: 1313 break; 1314 1315 } 1316 } 1317 } 1318 1319 /* check if the State machine was changed or new lacpdu arrived */ 1320 if ((port->sm_rx_state != last_state) || (lacpdu)) { 1321 slave_dbg(port->slave->bond->dev, port->slave->dev, 1322 "Rx Machine: Port=%d, Last State=%d, Curr State=%d\n", 1323 port->actor_port_number, 1324 last_state, 1325 port->sm_rx_state); 1326 switch (port->sm_rx_state) { 1327 case AD_RX_INITIALIZE: 1328 if (!(port->actor_oper_port_key & AD_DUPLEX_KEY_MASKS)) 1329 port->sm_vars &= ~AD_PORT_LACP_ENABLED; 1330 else 1331 port->sm_vars |= AD_PORT_LACP_ENABLED; 1332 port->sm_vars &= ~AD_PORT_SELECTED; 1333 __record_default(port); 1334 port->actor_oper_port_state &= ~LACP_STATE_EXPIRED; 1335 port->sm_rx_state = AD_RX_PORT_DISABLED; 1336 1337 fallthrough; 1338 case AD_RX_PORT_DISABLED: 1339 port->sm_vars &= ~AD_PORT_MATCHED; 1340 port->partner_oper.port_state &= ~LACP_STATE_SYNCHRONIZATION; 1341 break; 1342 case AD_RX_LACP_DISABLED: 1343 port->sm_vars &= ~AD_PORT_SELECTED; 1344 __record_default(port); 1345 port->partner_oper.port_state &= ~LACP_STATE_AGGREGATION; 1346 port->sm_vars |= AD_PORT_MATCHED; 1347 port->actor_oper_port_state &= ~LACP_STATE_EXPIRED; 1348 break; 1349 case AD_RX_EXPIRED: 1350 /* Reset of the Synchronization flag (Standard 43.4.12) 1351 * This reset cause to disable this port in the 1352 * COLLECTING_DISTRIBUTING state of the mux machine in 1353 * case of EXPIRED even if LINK_DOWN didn't arrive for 1354 * the port. 1355 */ 1356 port->sm_vars &= ~AD_PORT_MATCHED; 1357 /* Based on IEEE 8021AX-2014, Figure 6-18 - Receive 1358 * machine state diagram, the statue should be 1359 * Partner_Oper_Port_State.Synchronization = FALSE; 1360 * Partner_Oper_Port_State.LACP_Timeout = Short Timeout; 1361 * start current_while_timer(Short Timeout); 1362 * Actor_Oper_Port_State.Expired = TRUE; 1363 */ 1364 port->partner_oper.port_state &= ~LACP_STATE_SYNCHRONIZATION; 1365 port->partner_oper.port_state |= LACP_STATE_LACP_TIMEOUT; 1366 port->sm_rx_timer_counter = __ad_timer_to_ticks(AD_CURRENT_WHILE_TIMER, (u16)(AD_SHORT_TIMEOUT)); 1367 port->actor_oper_port_state |= LACP_STATE_EXPIRED; 1368 port->sm_vars |= AD_PORT_CHURNED; 1369 break; 1370 case AD_RX_DEFAULTED: 1371 __update_default_selected(port); 1372 __record_default(port); 1373 port->sm_vars |= AD_PORT_MATCHED; 1374 port->actor_oper_port_state &= ~LACP_STATE_EXPIRED; 1375 break; 1376 case AD_RX_CURRENT: 1377 /* detect loopback situation */ 1378 if (MAC_ADDRESS_EQUAL(&(lacpdu->actor_system), 1379 &(port->actor_system))) { 1380 slave_err(port->slave->bond->dev, port->slave->dev, "An illegal loopback occurred on slave\n" 1381 "Check the configuration to verify that all adapters are connected to 802.3ad compliant switch ports\n"); 1382 return; 1383 } 1384 __update_selected(lacpdu, port); 1385 __update_ntt(lacpdu, port); 1386 __record_pdu(lacpdu, port); 1387 port->sm_rx_timer_counter = __ad_timer_to_ticks(AD_CURRENT_WHILE_TIMER, (u16)(port->actor_oper_port_state & LACP_STATE_LACP_TIMEOUT)); 1388 port->actor_oper_port_state &= ~LACP_STATE_EXPIRED; 1389 break; 1390 default: 1391 break; 1392 } 1393 } 1394 } 1395 1396 /** 1397 * ad_churn_machine - handle port churn's state machine 1398 * @port: the port we're looking at 1399 * 1400 */ 1401 static void ad_churn_machine(struct port *port) 1402 { 1403 if (port->sm_vars & AD_PORT_CHURNED) { 1404 port->sm_vars &= ~AD_PORT_CHURNED; 1405 WRITE_ONCE(port->sm_churn_actor_state, AD_CHURN_MONITOR); 1406 WRITE_ONCE(port->sm_churn_partner_state, AD_CHURN_MONITOR); 1407 port->sm_churn_actor_timer_counter = 1408 __ad_timer_to_ticks(AD_ACTOR_CHURN_TIMER, 0); 1409 port->sm_churn_partner_timer_counter = 1410 __ad_timer_to_ticks(AD_PARTNER_CHURN_TIMER, 0); 1411 return; 1412 } 1413 if (port->sm_churn_actor_timer_counter && 1414 !(--port->sm_churn_actor_timer_counter) && 1415 port->sm_churn_actor_state == AD_CHURN_MONITOR) { 1416 if (port->actor_oper_port_state & LACP_STATE_SYNCHRONIZATION) { 1417 WRITE_ONCE(port->sm_churn_actor_state, AD_NO_CHURN); 1418 } else { 1419 WRITE_ONCE(port->churn_actor_count, 1420 port->churn_actor_count + 1); 1421 WRITE_ONCE(port->sm_churn_actor_state, AD_CHURN); 1422 } 1423 } 1424 if (port->sm_churn_partner_timer_counter && 1425 !(--port->sm_churn_partner_timer_counter) && 1426 port->sm_churn_partner_state == AD_CHURN_MONITOR) { 1427 if (port->partner_oper.port_state & LACP_STATE_SYNCHRONIZATION) { 1428 WRITE_ONCE(port->sm_churn_partner_state, AD_NO_CHURN); 1429 } else { 1430 WRITE_ONCE(port->churn_partner_count, 1431 port->churn_partner_count + 1); 1432 WRITE_ONCE(port->sm_churn_partner_state, AD_CHURN); 1433 } 1434 } 1435 } 1436 1437 /** 1438 * ad_tx_machine - handle a port's tx state machine 1439 * @port: the port we're looking at 1440 */ 1441 static void ad_tx_machine(struct port *port) 1442 { 1443 /* check if tx timer expired, to verify that we do not send more than 1444 * 3 packets per second 1445 */ 1446 if (!port->sm_tx_timer_counter || !(--port->sm_tx_timer_counter)) { 1447 /* check if there is something to send */ 1448 if (port->ntt && (port->sm_vars & AD_PORT_LACP_ENABLED)) { 1449 __update_lacpdu_from_port(port); 1450 1451 if (ad_lacpdu_send(port) >= 0) { 1452 slave_dbg(port->slave->bond->dev, 1453 port->slave->dev, 1454 "Sent LACPDU on port %d\n", 1455 port->actor_port_number); 1456 1457 /* mark ntt as false, so it will not be sent 1458 * again until demanded 1459 */ 1460 port->ntt = false; 1461 1462 /* restart tx timer(to verify that we will not 1463 * exceed AD_MAX_TX_IN_SECOND 1464 */ 1465 port->sm_tx_timer_counter = ad_ticks_per_sec / AD_MAX_TX_IN_SECOND; 1466 } 1467 } 1468 } 1469 } 1470 1471 /** 1472 * ad_periodic_machine - handle a port's periodic state machine 1473 * @port: the port we're looking at 1474 * 1475 * Turn ntt flag on priodically to perform periodic transmission of lacpdu's. 1476 */ 1477 static void ad_periodic_machine(struct port *port) 1478 { 1479 periodic_states_t last_state; 1480 1481 /* keep current state machine state to compare later if it was changed */ 1482 last_state = port->sm_periodic_state; 1483 1484 /* check if port was reinitialized */ 1485 if (((port->sm_vars & AD_PORT_BEGIN) || !(port->sm_vars & AD_PORT_LACP_ENABLED) || !port->is_enabled) || 1486 (!(port->actor_oper_port_state & LACP_STATE_LACP_ACTIVITY) && !(port->partner_oper.port_state & LACP_STATE_LACP_ACTIVITY))) { 1487 port->sm_periodic_state = AD_NO_PERIODIC; 1488 } 1489 /* check if state machine should change state */ 1490 else if (port->sm_periodic_timer_counter) { 1491 /* check if periodic state machine expired */ 1492 if (!(--port->sm_periodic_timer_counter)) { 1493 /* if expired then do tx */ 1494 port->sm_periodic_state = AD_PERIODIC_TX; 1495 } else { 1496 /* If not expired, check if there is some new timeout 1497 * parameter from the partner state 1498 */ 1499 switch (port->sm_periodic_state) { 1500 case AD_FAST_PERIODIC: 1501 if (!(port->partner_oper.port_state 1502 & LACP_STATE_LACP_TIMEOUT)) 1503 port->sm_periodic_state = AD_SLOW_PERIODIC; 1504 break; 1505 case AD_SLOW_PERIODIC: 1506 if ((port->partner_oper.port_state & LACP_STATE_LACP_TIMEOUT)) { 1507 port->sm_periodic_timer_counter = 0; 1508 port->sm_periodic_state = AD_PERIODIC_TX; 1509 } 1510 break; 1511 default: 1512 break; 1513 } 1514 } 1515 } else { 1516 switch (port->sm_periodic_state) { 1517 case AD_NO_PERIODIC: 1518 port->sm_periodic_state = AD_FAST_PERIODIC; 1519 break; 1520 case AD_PERIODIC_TX: 1521 if (!(port->partner_oper.port_state & 1522 LACP_STATE_LACP_TIMEOUT)) 1523 port->sm_periodic_state = AD_SLOW_PERIODIC; 1524 else 1525 port->sm_periodic_state = AD_FAST_PERIODIC; 1526 break; 1527 default: 1528 break; 1529 } 1530 } 1531 1532 /* check if the state machine was changed */ 1533 if (port->sm_periodic_state != last_state) { 1534 slave_dbg(port->slave->bond->dev, port->slave->dev, 1535 "Periodic Machine: Port=%d, Last State=%d, Curr State=%d\n", 1536 port->actor_port_number, last_state, 1537 port->sm_periodic_state); 1538 switch (port->sm_periodic_state) { 1539 case AD_NO_PERIODIC: 1540 port->sm_periodic_timer_counter = 0; 1541 break; 1542 case AD_FAST_PERIODIC: 1543 /* decrement 1 tick we lost in the PERIODIC_TX cycle */ 1544 port->sm_periodic_timer_counter = __ad_timer_to_ticks(AD_PERIODIC_TIMER, (u16)(AD_FAST_PERIODIC_TIME))-1; 1545 break; 1546 case AD_SLOW_PERIODIC: 1547 /* decrement 1 tick we lost in the PERIODIC_TX cycle */ 1548 port->sm_periodic_timer_counter = __ad_timer_to_ticks(AD_PERIODIC_TIMER, (u16)(AD_SLOW_PERIODIC_TIME))-1; 1549 break; 1550 case AD_PERIODIC_TX: 1551 port->ntt = true; 1552 break; 1553 default: 1554 break; 1555 } 1556 } 1557 } 1558 1559 /** 1560 * ad_port_selection_logic - select aggregation groups 1561 * @port: the port we're looking at 1562 * @update_slave_arr: Does slave array need update? 1563 * 1564 * Select aggregation groups, and assign each port for it's aggregetor. The 1565 * selection logic is called in the inititalization (after all the handshkes), 1566 * and after every lacpdu receive (if selected is off). 1567 */ 1568 static void ad_port_selection_logic(struct port *port, bool *update_slave_arr) 1569 { 1570 struct aggregator *aggregator, *free_aggregator = NULL, *temp_aggregator; 1571 struct port *last_port = NULL, *curr_port; 1572 struct list_head *iter; 1573 struct bonding *bond; 1574 struct slave *slave; 1575 int found = 0; 1576 1577 /* if the port is already Selected, do nothing */ 1578 if (port->sm_vars & AD_PORT_SELECTED) 1579 return; 1580 1581 bond = __get_bond_by_port(port); 1582 1583 /* if the port is connected to other aggregator, detach it */ 1584 temp_aggregator = rcu_dereference(port->aggregator); 1585 if (temp_aggregator) { 1586 /* detach the port from its former aggregator */ 1587 for (curr_port = temp_aggregator->lag_ports; curr_port; 1588 last_port = curr_port, 1589 curr_port = curr_port->next_port_in_aggregator) { 1590 if (curr_port == port) { 1591 temp_aggregator->num_of_ports--; 1592 /* if it is the first port attached to the 1593 * aggregator 1594 */ 1595 if (!last_port) { 1596 temp_aggregator->lag_ports = 1597 port->next_port_in_aggregator; 1598 } else { 1599 /* not the first port attached to the 1600 * aggregator 1601 */ 1602 last_port->next_port_in_aggregator = 1603 port->next_port_in_aggregator; 1604 } 1605 1606 /* clear the port's relations to this 1607 * aggregator 1608 */ 1609 RCU_INIT_POINTER(port->aggregator, NULL); 1610 port->next_port_in_aggregator = NULL; 1611 port->actor_port_aggregator_identifier = 0; 1612 1613 slave_dbg(bond->dev, port->slave->dev, "Port %d left LAG %d\n", 1614 port->actor_port_number, 1615 temp_aggregator->aggregator_identifier); 1616 /* if the aggregator is empty, clear its 1617 * parameters, and set it ready to be attached 1618 */ 1619 if (!temp_aggregator->lag_ports) 1620 ad_clear_agg(temp_aggregator); 1621 break; 1622 } 1623 } 1624 if (!curr_port) { 1625 /* meaning: the port was related to an aggregator 1626 * but was not on the aggregator port list 1627 */ 1628 net_warn_ratelimited("%s: (slave %s): Warning: Port %d was related to aggregator %d but was not on its port list\n", 1629 port->slave->bond->dev->name, 1630 port->slave->dev->name, 1631 port->actor_port_number, 1632 temp_aggregator->aggregator_identifier); 1633 } 1634 } 1635 /* search on all aggregators for a suitable aggregator for this port */ 1636 bond_for_each_slave(bond, slave, iter) { 1637 aggregator = &(SLAVE_AD_INFO(slave)->aggregator); 1638 1639 /* keep a free aggregator for later use(if needed) */ 1640 if (!aggregator->lag_ports) { 1641 if (!free_aggregator) 1642 free_aggregator = aggregator; 1643 continue; 1644 } 1645 /* check if current aggregator suits us */ 1646 if (((aggregator->actor_oper_aggregator_key == port->actor_oper_port_key) && /* if all parameters match AND */ 1647 MAC_ADDRESS_EQUAL(&(aggregator->partner_system), &(port->partner_oper.system)) && 1648 (aggregator->partner_system_priority == port->partner_oper.system_priority) && 1649 (aggregator->partner_oper_aggregator_key == port->partner_oper.key) 1650 ) && 1651 ((__agg_has_partner(aggregator) && /* partner answers */ 1652 !aggregator->is_individual) /* but is not individual OR */ 1653 ) 1654 ) { 1655 /* attach to the founded aggregator */ 1656 rcu_assign_pointer(port->aggregator, aggregator); 1657 port->actor_port_aggregator_identifier = 1658 aggregator->aggregator_identifier; 1659 port->next_port_in_aggregator = aggregator->lag_ports; 1660 aggregator->num_of_ports++; 1661 aggregator->lag_ports = port; 1662 slave_dbg(bond->dev, slave->dev, "Port %d joined LAG %d (existing LAG)\n", 1663 port->actor_port_number, 1664 aggregator->aggregator_identifier); 1665 1666 /* mark this port as selected */ 1667 port->sm_vars |= AD_PORT_SELECTED; 1668 found = 1; 1669 break; 1670 } 1671 } 1672 1673 /* the port couldn't find an aggregator - attach it to a new 1674 * aggregator 1675 */ 1676 if (!found) { 1677 if (free_aggregator) { 1678 /* assign port a new aggregator */ 1679 port->actor_port_aggregator_identifier = 1680 free_aggregator->aggregator_identifier; 1681 1682 /* update the new aggregator's parameters 1683 * if port was responsed from the end-user 1684 */ 1685 if (port->actor_oper_port_key & AD_DUPLEX_KEY_MASKS) 1686 /* if port is full duplex */ 1687 free_aggregator->is_individual = false; 1688 else 1689 free_aggregator->is_individual = true; 1690 1691 free_aggregator->actor_admin_aggregator_key = 1692 port->actor_admin_port_key; 1693 free_aggregator->actor_oper_aggregator_key = 1694 port->actor_oper_port_key; 1695 free_aggregator->partner_system = 1696 port->partner_oper.system; 1697 free_aggregator->partner_system_priority = 1698 port->partner_oper.system_priority; 1699 free_aggregator->partner_oper_aggregator_key = port->partner_oper.key; 1700 free_aggregator->receive_state = 1; 1701 free_aggregator->transmit_state = 1; 1702 free_aggregator->lag_ports = port; 1703 free_aggregator->num_of_ports++; 1704 1705 rcu_assign_pointer(port->aggregator, free_aggregator); 1706 1707 /* mark this port as selected */ 1708 port->sm_vars |= AD_PORT_SELECTED; 1709 1710 slave_dbg(bond->dev, port->slave->dev, "Port %d joined LAG %d (new LAG)\n", 1711 port->actor_port_number, 1712 free_aggregator->aggregator_identifier); 1713 } else { 1714 slave_err(bond->dev, port->slave->dev, 1715 "Port %d did not find a suitable aggregator\n", 1716 port->actor_port_number); 1717 return; 1718 } 1719 } 1720 /* if all aggregator's ports are READY_N == TRUE, set ready=TRUE 1721 * in all aggregator's ports, else set ready=FALSE in all 1722 * aggregator's ports 1723 */ 1724 aggregator = rcu_dereference(port->aggregator); 1725 __set_agg_ports_ready(aggregator, __agg_ports_are_ready(aggregator)); 1726 1727 ad_agg_selection_logic(__get_first_agg(port), update_slave_arr); 1728 1729 if (!aggregator->is_active) 1730 port->actor_oper_port_state &= ~LACP_STATE_SYNCHRONIZATION; 1731 } 1732 1733 /* Decide if "agg" is a better choice for the new active aggregator that 1734 * the current best, according to the ad_select policy. 1735 */ 1736 static struct aggregator *ad_agg_selection_test(struct aggregator *best, 1737 struct aggregator *curr) 1738 { 1739 /* 0. If no best, select current. 1740 * 1741 * 1. If the current agg is not individual, and the best is 1742 * individual, select current. 1743 * 1744 * 2. If current agg is individual and the best is not, keep best. 1745 * 1746 * 3. Therefore, current and best are both individual or both not 1747 * individual, so: 1748 * 1749 * 3a. If current agg partner replied, and best agg partner did not, 1750 * select current. 1751 * 1752 * 3b. If current agg partner did not reply and best agg partner 1753 * did reply, keep best. 1754 * 1755 * 4. Therefore, current and best both have partner replies or 1756 * both do not, so perform selection policy: 1757 * 1758 * BOND_AD_PRIO: Select by total priority of ports. If priority 1759 * is equal, select by count. 1760 * 1761 * BOND_AD_COUNT: Select by count of ports. If count is equal, 1762 * select by bandwidth. 1763 * 1764 * BOND_AD_STABLE, BOND_AD_BANDWIDTH: Select by bandwidth. 1765 */ 1766 if (!best) 1767 return curr; 1768 1769 if (!curr->is_individual && best->is_individual) 1770 return curr; 1771 1772 if (curr->is_individual && !best->is_individual) 1773 return best; 1774 1775 if (__agg_has_partner(curr) && !__agg_has_partner(best)) 1776 return curr; 1777 1778 if (!__agg_has_partner(curr) && __agg_has_partner(best)) 1779 return best; 1780 1781 switch (__get_agg_selection_mode(curr->lag_ports)) { 1782 case BOND_AD_PRIO: 1783 if (__agg_ports_priority(curr) > __agg_ports_priority(best)) 1784 return curr; 1785 1786 if (__agg_ports_priority(curr) < __agg_ports_priority(best)) 1787 return best; 1788 1789 fallthrough; 1790 case BOND_AD_COUNT: 1791 if (__agg_active_ports(curr) > __agg_active_ports(best)) 1792 return curr; 1793 1794 if (__agg_active_ports(curr) < __agg_active_ports(best)) 1795 return best; 1796 1797 fallthrough; 1798 case BOND_AD_STABLE: 1799 case BOND_AD_BANDWIDTH: 1800 if (__get_agg_bandwidth(curr) > __get_agg_bandwidth(best)) 1801 return curr; 1802 1803 break; 1804 1805 default: 1806 net_warn_ratelimited("%s: (slave %s): Impossible agg select mode %d\n", 1807 curr->slave->bond->dev->name, 1808 curr->slave->dev->name, 1809 __get_agg_selection_mode(curr->lag_ports)); 1810 break; 1811 } 1812 1813 return best; 1814 } 1815 1816 static int agg_device_up(const struct aggregator *agg) 1817 { 1818 struct port *port = agg->lag_ports; 1819 1820 if (!port) 1821 return 0; 1822 1823 for (port = agg->lag_ports; port; 1824 port = port->next_port_in_aggregator) { 1825 if (netif_running(port->slave->dev) && 1826 netif_carrier_ok(port->slave->dev)) 1827 return 1; 1828 } 1829 1830 return 0; 1831 } 1832 1833 /** 1834 * ad_agg_selection_logic - select an aggregation group for a team 1835 * @agg: the aggregator we're looking at 1836 * @update_slave_arr: Does slave array need update? 1837 * 1838 * It is assumed that only one aggregator may be selected for a team. 1839 * 1840 * The logic of this function is to select the aggregator according to 1841 * the ad_select policy: 1842 * 1843 * BOND_AD_STABLE: select the aggregator with the most ports attached to 1844 * it, and to reselect the active aggregator only if the previous 1845 * aggregator has no more ports related to it. 1846 * 1847 * BOND_AD_BANDWIDTH: select the aggregator with the highest total 1848 * bandwidth, and reselect whenever a link state change takes place or the 1849 * set of slaves in the bond changes. 1850 * 1851 * BOND_AD_COUNT: select the aggregator with largest number of ports 1852 * (slaves), and reselect whenever a link state change takes place or the 1853 * set of slaves in the bond changes. 1854 * 1855 * BOND_AD_PRIO: select the aggregator with highest total priority of ports 1856 * (slaves), and reselect whenever a link state change takes place or the 1857 * set of slaves in the bond changes. 1858 * 1859 * FIXME: this function MUST be called with the first agg in the bond, or 1860 * __get_active_agg() won't work correctly. This function should be better 1861 * called with the bond itself, and retrieve the first agg from it. 1862 */ 1863 static void ad_agg_selection_logic(struct aggregator *agg, 1864 bool *update_slave_arr) 1865 { 1866 struct aggregator *best, *active, *origin; 1867 struct bonding *bond = agg->slave->bond; 1868 struct list_head *iter; 1869 struct slave *slave; 1870 struct port *port; 1871 1872 rcu_read_lock(); 1873 origin = agg; 1874 active = __get_active_agg(agg); 1875 best = (active && agg_device_up(active)) ? active : NULL; 1876 1877 bond_for_each_slave_rcu(bond, slave, iter) { 1878 agg = &(SLAVE_AD_INFO(slave)->aggregator); 1879 1880 agg->is_active = 0; 1881 1882 if (__agg_active_ports(agg) && agg_device_up(agg)) 1883 best = ad_agg_selection_test(best, agg); 1884 } 1885 1886 if (best && 1887 __get_agg_selection_mode(best->lag_ports) == BOND_AD_STABLE) { 1888 /* For the STABLE policy, don't replace the old active 1889 * aggregator if it's still active (it has an answering 1890 * partner) or if both the best and active don't have an 1891 * answering partner. 1892 */ 1893 if (active && active->lag_ports && 1894 __agg_active_ports(active) && 1895 (__agg_has_partner(active) || 1896 (!__agg_has_partner(active) && 1897 !__agg_has_partner(best)))) { 1898 if (!(!active->actor_oper_aggregator_key && 1899 best->actor_oper_aggregator_key)) { 1900 best = NULL; 1901 active->is_active = 1; 1902 } 1903 } 1904 } 1905 1906 if (best && (best == active)) { 1907 best = NULL; 1908 active->is_active = 1; 1909 } 1910 1911 /* if there is new best aggregator, activate it */ 1912 if (best) { 1913 netdev_dbg(bond->dev, "(slave %s): best Agg=%d; P=%d; a k=%d; p k=%d; Ind=%d; Act=%d\n", 1914 best->slave ? best->slave->dev->name : "NULL", 1915 best->aggregator_identifier, best->num_of_ports, 1916 best->actor_oper_aggregator_key, 1917 best->partner_oper_aggregator_key, 1918 best->is_individual, best->is_active); 1919 netdev_dbg(bond->dev, "(slave %s): best ports %p slave %p\n", 1920 best->slave ? best->slave->dev->name : "NULL", 1921 best->lag_ports, best->slave); 1922 1923 bond_for_each_slave_rcu(bond, slave, iter) { 1924 agg = &(SLAVE_AD_INFO(slave)->aggregator); 1925 1926 slave_dbg(bond->dev, slave->dev, "Agg=%d; P=%d; a k=%d; p k=%d; Ind=%d; Act=%d\n", 1927 agg->aggregator_identifier, agg->num_of_ports, 1928 agg->actor_oper_aggregator_key, 1929 agg->partner_oper_aggregator_key, 1930 agg->is_individual, agg->is_active); 1931 } 1932 1933 /* check if any partner replies */ 1934 if (best->is_individual) 1935 net_warn_ratelimited("%s: Warning: No 802.3ad response from the link partner for any adapters in the bond\n", 1936 bond->dev->name); 1937 1938 best->is_active = 1; 1939 netdev_dbg(bond->dev, "(slave %s): LAG %d chosen as the active LAG\n", 1940 best->slave ? best->slave->dev->name : "NULL", 1941 best->aggregator_identifier); 1942 netdev_dbg(bond->dev, "(slave %s): Agg=%d; P=%d; a k=%d; p k=%d; Ind=%d; Act=%d\n", 1943 best->slave ? best->slave->dev->name : "NULL", 1944 best->aggregator_identifier, best->num_of_ports, 1945 best->actor_oper_aggregator_key, 1946 best->partner_oper_aggregator_key, 1947 best->is_individual, best->is_active); 1948 1949 /* disable the ports that were related to the former 1950 * active_aggregator 1951 */ 1952 if (active) { 1953 for (port = active->lag_ports; port; 1954 port = port->next_port_in_aggregator) { 1955 __disable_port(port); 1956 } 1957 } 1958 /* Slave array needs update. */ 1959 *update_slave_arr = true; 1960 } 1961 1962 /* if the selected aggregator is of join individuals 1963 * (partner_system is NULL), enable their ports 1964 */ 1965 active = __get_active_agg(origin); 1966 1967 if (active) { 1968 if (!__agg_has_partner(active)) { 1969 for (port = active->lag_ports; port; 1970 port = port->next_port_in_aggregator) { 1971 __enable_port(port); 1972 } 1973 *update_slave_arr = true; 1974 } 1975 } 1976 1977 rcu_read_unlock(); 1978 1979 bond_3ad_set_carrier(bond); 1980 } 1981 1982 /** 1983 * ad_clear_agg - clear a given aggregator's parameters 1984 * @aggregator: the aggregator we're looking at 1985 */ 1986 static void ad_clear_agg(struct aggregator *aggregator) 1987 { 1988 if (aggregator) { 1989 aggregator->is_individual = false; 1990 aggregator->actor_admin_aggregator_key = 0; 1991 aggregator->actor_oper_aggregator_key = 0; 1992 eth_zero_addr(aggregator->partner_system.mac_addr_value); 1993 aggregator->partner_system_priority = 0; 1994 aggregator->partner_oper_aggregator_key = 0; 1995 aggregator->receive_state = 0; 1996 aggregator->transmit_state = 0; 1997 aggregator->lag_ports = NULL; 1998 aggregator->is_active = 0; 1999 aggregator->num_of_ports = 0; 2000 pr_debug("%s: LAG %d was cleared\n", 2001 aggregator->slave ? 2002 aggregator->slave->dev->name : "NULL", 2003 aggregator->aggregator_identifier); 2004 } 2005 } 2006 2007 /** 2008 * ad_initialize_agg - initialize a given aggregator's parameters 2009 * @aggregator: the aggregator we're looking at 2010 */ 2011 static void ad_initialize_agg(struct aggregator *aggregator) 2012 { 2013 if (aggregator) { 2014 ad_clear_agg(aggregator); 2015 2016 eth_zero_addr(aggregator->aggregator_mac_address.mac_addr_value); 2017 aggregator->aggregator_identifier = 0; 2018 aggregator->slave = NULL; 2019 } 2020 } 2021 2022 /** 2023 * ad_initialize_port - initialize a given port's parameters 2024 * @port: the port we're looking at 2025 * @bond_params: bond parameters we will use 2026 */ 2027 static void ad_initialize_port(struct port *port, const struct bond_params *bond_params) 2028 { 2029 static const struct port_params tmpl = { 2030 .system_priority = 0xffff, 2031 .key = 1, 2032 .port_number = 1, 2033 .port_priority = 0xff, 2034 .port_state = 0, 2035 }; 2036 static const struct lacpdu lacpdu = { 2037 .subtype = 0x01, 2038 .version_number = 0x01, 2039 .tlv_type_actor_info = 0x01, 2040 .actor_information_length = 0x14, 2041 .tlv_type_partner_info = 0x02, 2042 .partner_information_length = 0x14, 2043 .tlv_type_collector_info = 0x03, 2044 .collector_information_length = 0x10, 2045 .collector_max_delay = htons(AD_COLLECTOR_MAX_DELAY), 2046 }; 2047 2048 if (port) { 2049 port->actor_port_priority = 0xff; 2050 port->actor_port_aggregator_identifier = 0; 2051 port->ntt = false; 2052 port->actor_admin_port_state = LACP_STATE_AGGREGATION; 2053 port->actor_oper_port_state = LACP_STATE_AGGREGATION; 2054 if (bond_params->lacp_active) { 2055 port->actor_admin_port_state |= LACP_STATE_LACP_ACTIVITY; 2056 port->actor_oper_port_state |= LACP_STATE_LACP_ACTIVITY; 2057 } 2058 2059 if (bond_params->lacp_fast) 2060 port->actor_oper_port_state |= LACP_STATE_LACP_TIMEOUT; 2061 2062 memcpy(&port->partner_admin, &tmpl, sizeof(tmpl)); 2063 memcpy(&port->partner_oper, &tmpl, sizeof(tmpl)); 2064 2065 port->is_enabled = true; 2066 /* private parameters */ 2067 port->sm_vars = AD_PORT_BEGIN | AD_PORT_LACP_ENABLED; 2068 port->sm_rx_state = 0; 2069 port->sm_rx_timer_counter = 0; 2070 port->sm_periodic_state = 0; 2071 port->sm_periodic_timer_counter = 0; 2072 port->sm_mux_state = 0; 2073 port->sm_mux_timer_counter = 0; 2074 port->aggregator = NULL; 2075 port->next_port_in_aggregator = NULL; 2076 port->transaction_id = 0; 2077 2078 port->sm_churn_actor_timer_counter = 0; 2079 port->sm_churn_actor_state = 0; 2080 port->churn_actor_count = 0; 2081 port->sm_churn_partner_timer_counter = 0; 2082 port->sm_churn_partner_state = 0; 2083 port->churn_partner_count = 0; 2084 2085 memcpy(&port->lacpdu, &lacpdu, sizeof(lacpdu)); 2086 } 2087 } 2088 2089 /** 2090 * ad_enable_collecting - enable a port's receive 2091 * @port: the port we're looking at 2092 * 2093 * Enable @port if it's in an active aggregator 2094 */ 2095 static void ad_enable_collecting(struct port *port) 2096 { 2097 struct aggregator *aggregator = rcu_dereference(port->aggregator); 2098 2099 if (aggregator->is_active) { 2100 struct slave *slave = port->slave; 2101 2102 slave_dbg(slave->bond->dev, slave->dev, 2103 "Enabling collecting on port %d (LAG %d)\n", 2104 port->actor_port_number, 2105 aggregator->aggregator_identifier); 2106 __enable_collecting_port(port); 2107 } 2108 } 2109 2110 /** 2111 * ad_disable_distributing - disable a port's transmit 2112 * @port: the port we're looking at 2113 * @update_slave_arr: Does slave array need update? 2114 */ 2115 static void ad_disable_distributing(struct port *port, bool *update_slave_arr) 2116 { 2117 struct aggregator *aggregator = rcu_dereference(port->aggregator); 2118 2119 if (aggregator && __agg_has_partner(aggregator)) { 2120 slave_dbg(port->slave->bond->dev, port->slave->dev, 2121 "Disabling distributing on port %d (LAG %d)\n", 2122 port->actor_port_number, 2123 aggregator->aggregator_identifier); 2124 __disable_distributing_port(port); 2125 bond_3ad_set_carrier(port->slave->bond); 2126 /* Slave array needs an update */ 2127 *update_slave_arr = true; 2128 } 2129 } 2130 2131 /** 2132 * ad_enable_collecting_distributing - enable a port's transmit/receive 2133 * @port: the port we're looking at 2134 * @update_slave_arr: Does slave array need update? 2135 * 2136 * Enable @port if it's in an active aggregator 2137 */ 2138 static void ad_enable_collecting_distributing(struct port *port, 2139 bool *update_slave_arr) 2140 { 2141 struct aggregator *aggregator = rcu_dereference(port->aggregator); 2142 2143 if (aggregator->is_active) { 2144 slave_dbg(port->slave->bond->dev, port->slave->dev, 2145 "Enabling port %d (LAG %d)\n", 2146 port->actor_port_number, 2147 aggregator->aggregator_identifier); 2148 __enable_port(port); 2149 bond_3ad_set_carrier(port->slave->bond); 2150 /* Slave array needs update */ 2151 *update_slave_arr = true; 2152 /* Should notify peers if possible */ 2153 ad_cond_set_peer_notif(port); 2154 } 2155 } 2156 2157 /** 2158 * ad_disable_collecting_distributing - disable a port's transmit/receive 2159 * @port: the port we're looking at 2160 * @update_slave_arr: Does slave array need update? 2161 */ 2162 static void ad_disable_collecting_distributing(struct port *port, 2163 bool *update_slave_arr) 2164 { 2165 struct aggregator *aggregator = rcu_dereference(port->aggregator); 2166 2167 if (aggregator && __agg_has_partner(aggregator)) { 2168 slave_dbg(port->slave->bond->dev, port->slave->dev, 2169 "Disabling port %d (LAG %d)\n", 2170 port->actor_port_number, 2171 aggregator->aggregator_identifier); 2172 __disable_port(port); 2173 bond_3ad_set_carrier(port->slave->bond); 2174 /* Slave array needs an update */ 2175 *update_slave_arr = true; 2176 } 2177 } 2178 2179 /** 2180 * ad_marker_info_received - handle receive of a Marker information frame 2181 * @marker_info: Marker info received 2182 * @port: the port we're looking at 2183 */ 2184 static void ad_marker_info_received(struct bond_marker *marker_info, 2185 struct port *port) 2186 { 2187 struct bond_marker marker; 2188 2189 atomic64_inc(&SLAVE_AD_INFO(port->slave)->stats.marker_rx); 2190 atomic64_inc(&BOND_AD_INFO(port->slave->bond).stats.marker_rx); 2191 2192 /* copy the received marker data to the response marker */ 2193 memcpy(&marker, marker_info, sizeof(struct bond_marker)); 2194 /* change the marker subtype to marker response */ 2195 marker.tlv_type = AD_MARKER_RESPONSE_SUBTYPE; 2196 2197 /* send the marker response */ 2198 if (ad_marker_send(port, &marker) >= 0) 2199 slave_dbg(port->slave->bond->dev, port->slave->dev, 2200 "Sent Marker Response on port %d\n", 2201 port->actor_port_number); 2202 } 2203 2204 /** 2205 * ad_marker_response_received - handle receive of a marker response frame 2206 * @marker: marker PDU received 2207 * @port: the port we're looking at 2208 * 2209 * This function does nothing since we decided not to implement send and handle 2210 * response for marker PDU's, in this stage, but only to respond to marker 2211 * information. 2212 */ 2213 static void ad_marker_response_received(struct bond_marker *marker, 2214 struct port *port) 2215 { 2216 atomic64_inc(&SLAVE_AD_INFO(port->slave)->stats.marker_resp_rx); 2217 atomic64_inc(&BOND_AD_INFO(port->slave->bond).stats.marker_resp_rx); 2218 2219 /* DO NOTHING, SINCE WE DECIDED NOT TO IMPLEMENT THIS FEATURE FOR NOW */ 2220 } 2221 2222 /* ========= AD exported functions to the main bonding code ========= */ 2223 2224 /* Check aggregators status in team every T seconds */ 2225 #define AD_AGGREGATOR_SELECTION_TIMER 8 2226 2227 /** 2228 * bond_3ad_initiate_agg_selection - initate aggregator selection 2229 * @bond: bonding struct 2230 * @timeout: timeout value to set 2231 * 2232 * Set the aggregation selection timer, to initiate an agg selection in 2233 * the very near future. Called during first initialization, and during 2234 * any down to up transitions of the bond. 2235 */ 2236 void bond_3ad_initiate_agg_selection(struct bonding *bond, int timeout) 2237 { 2238 atomic_set(&BOND_AD_INFO(bond).agg_select_timer, timeout); 2239 } 2240 2241 /** 2242 * bond_3ad_initialize - initialize a bond's 802.3ad parameters and structures 2243 * @bond: bonding struct to work on 2244 * 2245 * Can be called only after the mac address of the bond is set. 2246 */ 2247 void bond_3ad_initialize(struct bonding *bond) 2248 { 2249 BOND_AD_INFO(bond).aggregator_identifier = 0; 2250 BOND_AD_INFO(bond).system.sys_priority = 2251 bond->params.ad_actor_sys_prio; 2252 if (is_zero_ether_addr(bond->params.ad_actor_system)) 2253 BOND_AD_INFO(bond).system.sys_mac_addr = 2254 *((struct mac_addr *)bond->dev->dev_addr); 2255 else 2256 BOND_AD_INFO(bond).system.sys_mac_addr = 2257 *((struct mac_addr *)bond->params.ad_actor_system); 2258 2259 bond_3ad_initiate_agg_selection(bond, 2260 AD_AGGREGATOR_SELECTION_TIMER * 2261 ad_ticks_per_sec); 2262 } 2263 2264 /** 2265 * bond_3ad_bind_slave - initialize a slave's port 2266 * @slave: slave struct to work on 2267 * 2268 * Returns: 0 on success 2269 * < 0 on error 2270 */ 2271 void bond_3ad_bind_slave(struct slave *slave) 2272 { 2273 struct bonding *bond = bond_get_bond_by_slave(slave); 2274 struct port *port; 2275 struct aggregator *aggregator; 2276 2277 /* check that the slave has not been initialized yet. */ 2278 if (SLAVE_AD_INFO(slave)->port.slave != slave) { 2279 2280 /* port initialization */ 2281 port = &(SLAVE_AD_INFO(slave)->port); 2282 2283 ad_initialize_port(port, &bond->params); 2284 2285 /* Port priority is initialized. Update it to slave's ad info */ 2286 SLAVE_AD_INFO(slave)->port_priority = port->actor_port_priority; 2287 2288 port->slave = slave; 2289 port->actor_port_number = SLAVE_AD_INFO(slave)->id; 2290 /* key is determined according to the link speed, duplex and 2291 * user key 2292 */ 2293 port->actor_admin_port_key = bond->params.ad_user_port_key << 6; 2294 ad_update_actor_keys(port, false); 2295 /* actor system is the bond's system */ 2296 __ad_actor_update_port(port); 2297 /* tx timer(to verify that no more than MAX_TX_IN_SECOND 2298 * lacpdu's are sent in one second) 2299 */ 2300 port->sm_tx_timer_counter = ad_ticks_per_sec/AD_MAX_TX_IN_SECOND; 2301 2302 __disable_port(port); 2303 2304 /* aggregator initialization */ 2305 aggregator = &(SLAVE_AD_INFO(slave)->aggregator); 2306 2307 ad_initialize_agg(aggregator); 2308 2309 aggregator->aggregator_mac_address = *((struct mac_addr *)bond->dev->dev_addr); 2310 aggregator->aggregator_identifier = ++BOND_AD_INFO(bond).aggregator_identifier; 2311 aggregator->slave = slave; 2312 aggregator->is_active = 0; 2313 aggregator->num_of_ports = 0; 2314 } 2315 } 2316 2317 /** 2318 * bond_3ad_unbind_slave - deinitialize a slave's port 2319 * @slave: slave struct to work on 2320 * 2321 * Search for the aggregator that is related to this port, remove the 2322 * aggregator and assign another aggregator for other port related to it 2323 * (if any), and remove the port. 2324 */ 2325 void bond_3ad_unbind_slave(struct slave *slave) 2326 { 2327 struct port *port, *prev_port, *temp_port; 2328 struct aggregator *aggregator, *new_aggregator, *temp_aggregator; 2329 int select_new_active_agg = 0; 2330 struct bonding *bond = slave->bond; 2331 struct slave *slave_iter; 2332 struct list_head *iter; 2333 bool dummy_slave_update; /* Ignore this value as caller updates array */ 2334 2335 /* Sync against bond_3ad_state_machine_handler() */ 2336 spin_lock_bh(&bond->mode_lock); 2337 aggregator = &(SLAVE_AD_INFO(slave)->aggregator); 2338 port = &(SLAVE_AD_INFO(slave)->port); 2339 2340 /* if slave is null, the whole port is not initialized */ 2341 if (!port->slave) { 2342 slave_warn(bond->dev, slave->dev, "Trying to unbind an uninitialized port\n"); 2343 goto out; 2344 } 2345 2346 slave_dbg(bond->dev, slave->dev, "Unbinding Link Aggregation Group %d\n", 2347 aggregator->aggregator_identifier); 2348 2349 /* Tell the partner that this port is not suitable for aggregation */ 2350 port->actor_oper_port_state &= ~LACP_STATE_SYNCHRONIZATION; 2351 port->actor_oper_port_state &= ~LACP_STATE_COLLECTING; 2352 port->actor_oper_port_state &= ~LACP_STATE_DISTRIBUTING; 2353 port->actor_oper_port_state &= ~LACP_STATE_AGGREGATION; 2354 __update_lacpdu_from_port(port); 2355 ad_lacpdu_send(port); 2356 2357 /* check if this aggregator is occupied */ 2358 if (aggregator->lag_ports) { 2359 /* check if there are other ports related to this aggregator 2360 * except the port related to this slave(thats ensure us that 2361 * there is a reason to search for new aggregator, and that we 2362 * will find one 2363 */ 2364 if ((aggregator->lag_ports != port) || 2365 (aggregator->lag_ports->next_port_in_aggregator)) { 2366 /* find new aggregator for the related port(s) */ 2367 bond_for_each_slave(bond, slave_iter, iter) { 2368 new_aggregator = &(SLAVE_AD_INFO(slave_iter)->aggregator); 2369 /* if the new aggregator is empty, or it is 2370 * connected to our port only 2371 */ 2372 if (!new_aggregator->lag_ports || 2373 ((new_aggregator->lag_ports == port) && 2374 !new_aggregator->lag_ports->next_port_in_aggregator)) 2375 break; 2376 } 2377 if (!slave_iter) 2378 new_aggregator = NULL; 2379 2380 /* if new aggregator found, copy the aggregator's 2381 * parameters and connect the related lag_ports to the 2382 * new aggregator 2383 */ 2384 if ((new_aggregator) && ((!new_aggregator->lag_ports) || ((new_aggregator->lag_ports == port) && !new_aggregator->lag_ports->next_port_in_aggregator))) { 2385 slave_dbg(bond->dev, slave->dev, "Some port(s) related to LAG %d - replacing with LAG %d\n", 2386 aggregator->aggregator_identifier, 2387 new_aggregator->aggregator_identifier); 2388 2389 if ((new_aggregator->lag_ports == port) && 2390 new_aggregator->is_active) { 2391 slave_info(bond->dev, slave->dev, "Removing an active aggregator\n"); 2392 select_new_active_agg = 1; 2393 } 2394 2395 new_aggregator->is_individual = aggregator->is_individual; 2396 new_aggregator->actor_admin_aggregator_key = aggregator->actor_admin_aggregator_key; 2397 new_aggregator->actor_oper_aggregator_key = aggregator->actor_oper_aggregator_key; 2398 new_aggregator->partner_system = aggregator->partner_system; 2399 new_aggregator->partner_system_priority = aggregator->partner_system_priority; 2400 new_aggregator->partner_oper_aggregator_key = aggregator->partner_oper_aggregator_key; 2401 new_aggregator->receive_state = aggregator->receive_state; 2402 new_aggregator->transmit_state = aggregator->transmit_state; 2403 new_aggregator->lag_ports = aggregator->lag_ports; 2404 new_aggregator->is_active = aggregator->is_active; 2405 new_aggregator->num_of_ports = aggregator->num_of_ports; 2406 2407 /* update the information that is written on 2408 * the ports about the aggregator 2409 */ 2410 for (temp_port = aggregator->lag_ports; temp_port; 2411 temp_port = temp_port->next_port_in_aggregator) { 2412 rcu_assign_pointer(temp_port->aggregator, new_aggregator); 2413 temp_port->actor_port_aggregator_identifier = new_aggregator->aggregator_identifier; 2414 } 2415 2416 ad_clear_agg(aggregator); 2417 2418 if (select_new_active_agg) 2419 ad_agg_selection_logic(__get_first_agg(port), 2420 &dummy_slave_update); 2421 } else { 2422 slave_warn(bond->dev, slave->dev, "unbinding aggregator, and could not find a new aggregator for its ports\n"); 2423 } 2424 } else { 2425 /* in case that the only port related to this 2426 * aggregator is the one we want to remove 2427 */ 2428 select_new_active_agg = aggregator->is_active; 2429 ad_clear_agg(aggregator); 2430 if (select_new_active_agg) { 2431 slave_info(bond->dev, slave->dev, "Removing an active aggregator\n"); 2432 /* select new active aggregator */ 2433 temp_aggregator = __get_first_agg(port); 2434 if (temp_aggregator) 2435 ad_agg_selection_logic(temp_aggregator, 2436 &dummy_slave_update); 2437 } 2438 } 2439 } 2440 2441 slave_dbg(bond->dev, slave->dev, "Unbinding port %d\n", port->actor_port_number); 2442 2443 /* find the aggregator that this port is connected to */ 2444 bond_for_each_slave(bond, slave_iter, iter) { 2445 temp_aggregator = &(SLAVE_AD_INFO(slave_iter)->aggregator); 2446 prev_port = NULL; 2447 /* search the port in the aggregator's related ports */ 2448 for (temp_port = temp_aggregator->lag_ports; temp_port; 2449 prev_port = temp_port, 2450 temp_port = temp_port->next_port_in_aggregator) { 2451 if (temp_port == port) { 2452 /* the aggregator found - detach the port from 2453 * this aggregator 2454 */ 2455 if (prev_port) 2456 prev_port->next_port_in_aggregator = temp_port->next_port_in_aggregator; 2457 else 2458 temp_aggregator->lag_ports = temp_port->next_port_in_aggregator; 2459 temp_aggregator->num_of_ports--; 2460 if (__agg_active_ports(temp_aggregator) == 0) { 2461 select_new_active_agg = temp_aggregator->is_active; 2462 if (temp_aggregator->num_of_ports == 0) 2463 ad_clear_agg(temp_aggregator); 2464 if (select_new_active_agg) { 2465 slave_info(bond->dev, slave->dev, "Removing an active aggregator\n"); 2466 /* select new active aggregator */ 2467 ad_agg_selection_logic(__get_first_agg(port), 2468 &dummy_slave_update); 2469 } 2470 } 2471 break; 2472 } 2473 } 2474 } 2475 port->slave = NULL; 2476 2477 out: 2478 spin_unlock_bh(&bond->mode_lock); 2479 } 2480 2481 /** 2482 * bond_3ad_update_ad_actor_settings - reflect change of actor settings to ports 2483 * @bond: bonding struct to work on 2484 * 2485 * If an ad_actor setting gets changed we need to update the individual port 2486 * settings so the bond device will use the new values when it gets upped. 2487 */ 2488 void bond_3ad_update_ad_actor_settings(struct bonding *bond) 2489 { 2490 struct list_head *iter; 2491 struct slave *slave; 2492 2493 ASSERT_RTNL(); 2494 2495 BOND_AD_INFO(bond).system.sys_priority = bond->params.ad_actor_sys_prio; 2496 if (is_zero_ether_addr(bond->params.ad_actor_system)) 2497 BOND_AD_INFO(bond).system.sys_mac_addr = 2498 *((struct mac_addr *)bond->dev->dev_addr); 2499 else 2500 BOND_AD_INFO(bond).system.sys_mac_addr = 2501 *((struct mac_addr *)bond->params.ad_actor_system); 2502 2503 spin_lock_bh(&bond->mode_lock); 2504 bond_for_each_slave(bond, slave, iter) { 2505 struct port *port = &(SLAVE_AD_INFO(slave))->port; 2506 2507 __ad_actor_update_port(port); 2508 port->ntt = true; 2509 } 2510 spin_unlock_bh(&bond->mode_lock); 2511 } 2512 2513 /** 2514 * bond_agg_timer_advance - advance agg_select_timer 2515 * @bond: bonding structure 2516 * 2517 * Return true when agg_select_timer reaches 0. 2518 */ 2519 static bool bond_agg_timer_advance(struct bonding *bond) 2520 { 2521 int val, nval; 2522 2523 while (1) { 2524 val = atomic_read(&BOND_AD_INFO(bond).agg_select_timer); 2525 if (!val) 2526 return false; 2527 nval = val - 1; 2528 if (atomic_cmpxchg(&BOND_AD_INFO(bond).agg_select_timer, 2529 val, nval) == val) 2530 break; 2531 } 2532 return nval == 0; 2533 } 2534 2535 /** 2536 * bond_3ad_state_machine_handler - handle state machines timeout 2537 * @work: work context to fetch bonding struct to work on from 2538 * 2539 * The state machine handling concept in this module is to check every tick 2540 * which state machine should operate any function. The execution order is 2541 * round robin, so when we have an interaction between state machines, the 2542 * reply of one to each other might be delayed until next tick. 2543 * 2544 * This function also complete the initialization when the agg_select_timer 2545 * times out, and it selects an aggregator for the ports that are yet not 2546 * related to any aggregator, and selects the active aggregator for a bond. 2547 */ 2548 void bond_3ad_state_machine_handler(struct work_struct *work) 2549 { 2550 struct bonding *bond = container_of(work, struct bonding, 2551 ad_work.work); 2552 struct aggregator *aggregator; 2553 struct list_head *iter; 2554 struct slave *slave; 2555 struct port *port; 2556 bool should_notify_rtnl = BOND_SLAVE_NOTIFY_LATER; 2557 bool update_slave_arr = false; 2558 2559 /* Lock to protect data accessed by all (e.g., port->sm_vars) and 2560 * against running with bond_3ad_unbind_slave. ad_rx_machine may run 2561 * concurrently due to incoming LACPDU as well. 2562 */ 2563 spin_lock_bh(&bond->mode_lock); 2564 rcu_read_lock(); 2565 2566 /* check if there are any slaves */ 2567 if (!bond_has_slaves(bond)) 2568 goto re_arm; 2569 2570 if (bond_agg_timer_advance(bond)) { 2571 slave = bond_first_slave_rcu(bond); 2572 port = slave ? &(SLAVE_AD_INFO(slave)->port) : NULL; 2573 2574 /* select the active aggregator for the bond */ 2575 if (port) { 2576 if (!port->slave) { 2577 net_warn_ratelimited("%s: Warning: bond's first port is uninitialized\n", 2578 bond->dev->name); 2579 goto re_arm; 2580 } 2581 2582 aggregator = __get_first_agg(port); 2583 ad_agg_selection_logic(aggregator, &update_slave_arr); 2584 } 2585 bond_3ad_set_carrier(bond); 2586 } 2587 2588 /* for each port run the state machines */ 2589 bond_for_each_slave_rcu(bond, slave, iter) { 2590 port = &(SLAVE_AD_INFO(slave)->port); 2591 if (!port->slave) { 2592 net_warn_ratelimited("%s: Warning: Found an uninitialized port\n", 2593 bond->dev->name); 2594 goto re_arm; 2595 } 2596 2597 ad_rx_machine(NULL, port); 2598 ad_periodic_machine(port); 2599 ad_port_selection_logic(port, &update_slave_arr); 2600 ad_mux_machine(port, &update_slave_arr); 2601 ad_tx_machine(port); 2602 ad_churn_machine(port); 2603 2604 /* turn off the BEGIN bit, since we already handled it */ 2605 if (port->sm_vars & AD_PORT_BEGIN) 2606 port->sm_vars &= ~AD_PORT_BEGIN; 2607 } 2608 2609 re_arm: 2610 bond_for_each_slave_rcu(bond, slave, iter) { 2611 if (slave->should_notify) { 2612 should_notify_rtnl = BOND_SLAVE_NOTIFY_NOW; 2613 break; 2614 } 2615 } 2616 rcu_read_unlock(); 2617 spin_unlock_bh(&bond->mode_lock); 2618 2619 if (update_slave_arr) 2620 bond_slave_arr_work_rearm(bond, 0); 2621 2622 if (should_notify_rtnl && rtnl_trylock()) { 2623 bond_slave_state_notify(bond); 2624 rtnl_unlock(); 2625 } 2626 queue_delayed_work(bond->wq, &bond->ad_work, ad_delta_in_ticks); 2627 } 2628 2629 /** 2630 * bond_3ad_rx_indication - handle a received frame 2631 * @lacpdu: received lacpdu 2632 * @slave: slave struct to work on 2633 * 2634 * It is assumed that frames that were sent on this NIC don't returned as new 2635 * received frames (loopback). Since only the payload is given to this 2636 * function, it check for loopback. 2637 */ 2638 static int bond_3ad_rx_indication(struct lacpdu *lacpdu, struct slave *slave) 2639 { 2640 struct bonding *bond = slave->bond; 2641 int ret = RX_HANDLER_ANOTHER; 2642 struct bond_marker *marker; 2643 struct port *port; 2644 atomic64_t *stat; 2645 2646 port = &(SLAVE_AD_INFO(slave)->port); 2647 if (!port->slave) { 2648 net_warn_ratelimited("%s: Warning: port of slave %s is uninitialized\n", 2649 slave->dev->name, slave->bond->dev->name); 2650 return ret; 2651 } 2652 2653 switch (lacpdu->subtype) { 2654 case AD_TYPE_LACPDU: 2655 ret = RX_HANDLER_CONSUMED; 2656 slave_dbg(slave->bond->dev, slave->dev, 2657 "Received LACPDU on port %d\n", 2658 port->actor_port_number); 2659 /* Protect against concurrent state machines */ 2660 spin_lock(&slave->bond->mode_lock); 2661 ad_rx_machine(lacpdu, port); 2662 spin_unlock(&slave->bond->mode_lock); 2663 break; 2664 case AD_TYPE_MARKER: 2665 ret = RX_HANDLER_CONSUMED; 2666 /* No need to convert fields to Little Endian since we 2667 * don't use the marker's fields. 2668 */ 2669 marker = (struct bond_marker *)lacpdu; 2670 switch (marker->tlv_type) { 2671 case AD_MARKER_INFORMATION_SUBTYPE: 2672 slave_dbg(slave->bond->dev, slave->dev, "Received Marker Information on port %d\n", 2673 port->actor_port_number); 2674 ad_marker_info_received(marker, port); 2675 break; 2676 case AD_MARKER_RESPONSE_SUBTYPE: 2677 slave_dbg(slave->bond->dev, slave->dev, "Received Marker Response on port %d\n", 2678 port->actor_port_number); 2679 ad_marker_response_received(marker, port); 2680 break; 2681 default: 2682 slave_dbg(slave->bond->dev, slave->dev, "Received an unknown Marker subtype on port %d\n", 2683 port->actor_port_number); 2684 stat = &SLAVE_AD_INFO(slave)->stats.marker_unknown_rx; 2685 atomic64_inc(stat); 2686 stat = &BOND_AD_INFO(bond).stats.marker_unknown_rx; 2687 atomic64_inc(stat); 2688 } 2689 break; 2690 default: 2691 atomic64_inc(&SLAVE_AD_INFO(slave)->stats.lacpdu_unknown_rx); 2692 atomic64_inc(&BOND_AD_INFO(bond).stats.lacpdu_unknown_rx); 2693 } 2694 2695 return ret; 2696 } 2697 2698 /** 2699 * ad_update_actor_keys - Update the oper / admin keys for a port based on 2700 * its current speed and duplex settings. 2701 * 2702 * @port: the port we'are looking at 2703 * @reset: Boolean to just reset the speed and the duplex part of the key 2704 * 2705 * The logic to change the oper / admin keys is: 2706 * (a) A full duplex port can participate in LACP with partner. 2707 * (b) When the speed is changed, LACP need to be reinitiated. 2708 */ 2709 static void ad_update_actor_keys(struct port *port, bool reset) 2710 { 2711 u8 duplex = 0; 2712 u16 ospeed = 0, speed = 0; 2713 u16 old_oper_key = port->actor_oper_port_key; 2714 2715 port->actor_admin_port_key &= ~(AD_SPEED_KEY_MASKS|AD_DUPLEX_KEY_MASKS); 2716 if (!reset) { 2717 speed = __get_link_speed(port); 2718 ospeed = (old_oper_key & AD_SPEED_KEY_MASKS) >> 1; 2719 duplex = __get_duplex(port); 2720 port->actor_admin_port_key |= (speed << 1) | duplex; 2721 } 2722 port->actor_oper_port_key = port->actor_admin_port_key; 2723 2724 if (old_oper_key != port->actor_oper_port_key) { 2725 /* Only 'duplex' port participates in LACP */ 2726 if (duplex) 2727 port->sm_vars |= AD_PORT_LACP_ENABLED; 2728 else 2729 port->sm_vars &= ~AD_PORT_LACP_ENABLED; 2730 2731 if (!reset) { 2732 if (!speed) { 2733 slave_err(port->slave->bond->dev, 2734 port->slave->dev, 2735 "speed changed to 0 on port %d\n", 2736 port->actor_port_number); 2737 } else if (duplex && ospeed != speed) { 2738 /* Speed change restarts LACP state-machine */ 2739 port->sm_vars |= AD_PORT_BEGIN; 2740 } 2741 } 2742 } 2743 } 2744 2745 /** 2746 * bond_3ad_adapter_speed_duplex_changed - handle a slave's speed / duplex 2747 * change indication 2748 * 2749 * @slave: slave struct to work on 2750 * 2751 * Handle reselection of aggregator (if needed) for this port. 2752 */ 2753 void bond_3ad_adapter_speed_duplex_changed(struct slave *slave) 2754 { 2755 struct port *port; 2756 2757 port = &(SLAVE_AD_INFO(slave)->port); 2758 2759 /* if slave is null, the whole port is not initialized */ 2760 if (!port->slave) { 2761 slave_warn(slave->bond->dev, slave->dev, 2762 "speed/duplex changed for uninitialized port\n"); 2763 return; 2764 } 2765 2766 spin_lock_bh(&slave->bond->mode_lock); 2767 ad_update_actor_keys(port, false); 2768 spin_unlock_bh(&slave->bond->mode_lock); 2769 slave_dbg(slave->bond->dev, slave->dev, "Port %d changed speed/duplex\n", 2770 port->actor_port_number); 2771 } 2772 2773 /** 2774 * bond_3ad_handle_link_change - handle a slave's link status change indication 2775 * @slave: slave struct to work on 2776 * @link: whether the link is now up or down 2777 * 2778 * Handle reselection of aggregator (if needed) for this port. 2779 */ 2780 void bond_3ad_handle_link_change(struct slave *slave, char link) 2781 { 2782 struct aggregator *agg; 2783 struct port *port; 2784 bool dummy; 2785 2786 port = &(SLAVE_AD_INFO(slave)->port); 2787 2788 /* if slave is null, the whole port is not initialized */ 2789 if (!port->slave) { 2790 slave_warn(slave->bond->dev, slave->dev, "link status changed for uninitialized port\n"); 2791 return; 2792 } 2793 2794 spin_lock_bh(&slave->bond->mode_lock); 2795 /* on link down we are zeroing duplex and speed since 2796 * some of the adaptors(ce1000.lan) report full duplex/speed 2797 * instead of N/A(duplex) / 0(speed). 2798 * 2799 * on link up we are forcing recheck on the duplex and speed since 2800 * some of he adaptors(ce1000.lan) report. 2801 */ 2802 if (link == BOND_LINK_UP) { 2803 WRITE_ONCE(port->is_enabled, true); 2804 ad_update_actor_keys(port, false); 2805 } else { 2806 /* link has failed */ 2807 WRITE_ONCE(port->is_enabled, false); 2808 ad_update_actor_keys(port, true); 2809 } 2810 agg = __get_first_agg(port); 2811 ad_agg_selection_logic(agg, &dummy); 2812 2813 spin_unlock_bh(&slave->bond->mode_lock); 2814 2815 slave_dbg(slave->bond->dev, slave->dev, "Port %d changed link status to %s\n", 2816 port->actor_port_number, 2817 link == BOND_LINK_UP ? "UP" : "DOWN"); 2818 2819 /* RTNL is held and mode_lock is released so it's safe 2820 * to update slave_array here. 2821 */ 2822 bond_update_slave_arr(slave->bond, NULL); 2823 } 2824 2825 /** 2826 * bond_3ad_set_carrier - set link state for bonding master 2827 * @bond: bonding structure 2828 * 2829 * if we have an active aggregator, we're up, if not, we're down. 2830 * Presumes that we cannot have an active aggregator if there are 2831 * no slaves with link up. 2832 * 2833 * This behavior complies with IEEE 802.3 section 43.3.9. 2834 * 2835 * Called by bond_set_carrier(). Return zero if carrier state does not 2836 * change, nonzero if it does. 2837 */ 2838 int bond_3ad_set_carrier(struct bonding *bond) 2839 { 2840 struct aggregator *active; 2841 struct slave *first_slave; 2842 int ret = 1; 2843 2844 rcu_read_lock(); 2845 first_slave = bond_first_slave_rcu(bond); 2846 if (!first_slave) { 2847 ret = 0; 2848 goto out; 2849 } 2850 active = __get_active_agg(&(SLAVE_AD_INFO(first_slave)->aggregator)); 2851 if (active) { 2852 /* are enough slaves available to consider link up? */ 2853 if ((bond->params.lacp_strict ? __agg_usable_ports(active) 2854 : __agg_active_ports(active)) < 2855 bond->params.min_links) { 2856 if (netif_carrier_ok(bond->dev)) { 2857 netif_carrier_off(bond->dev); 2858 goto out; 2859 } 2860 } else if (!netif_carrier_ok(bond->dev)) { 2861 netif_carrier_on(bond->dev); 2862 goto out; 2863 } 2864 } else if (netif_carrier_ok(bond->dev)) { 2865 netif_carrier_off(bond->dev); 2866 } 2867 out: 2868 rcu_read_unlock(); 2869 return ret; 2870 } 2871 2872 /** 2873 * __bond_3ad_get_active_agg_info - get information of the active aggregator 2874 * @bond: bonding struct to work on 2875 * @ad_info: ad_info struct to fill with the bond's info 2876 * 2877 * Returns: 0 on success 2878 * < 0 on error 2879 */ 2880 int __bond_3ad_get_active_agg_info(const struct bonding *bond, 2881 struct ad_info *ad_info) 2882 { 2883 const struct aggregator *aggregator = NULL, *tmp; 2884 struct ad_slave_info *ad_slave_info; 2885 const struct port *port; 2886 struct list_head *iter; 2887 struct slave *slave; 2888 2889 bond_for_each_slave_rcu(bond, slave, iter) { 2890 ad_slave_info = SLAVE_AD_INFO(slave); 2891 if (!ad_slave_info) 2892 continue; 2893 port = &ad_slave_info->port; 2894 tmp = rcu_dereference(port->aggregator); 2895 if (tmp && tmp->is_active) { 2896 aggregator = tmp; 2897 break; 2898 } 2899 } 2900 2901 if (!aggregator) 2902 return -1; 2903 2904 ad_info->aggregator_id = aggregator->aggregator_identifier; 2905 ad_info->ports = __agg_active_ports(aggregator); 2906 ad_info->actor_key = aggregator->actor_oper_aggregator_key; 2907 ad_info->partner_key = aggregator->partner_oper_aggregator_key; 2908 ether_addr_copy(ad_info->partner_system, 2909 aggregator->partner_system.mac_addr_value); 2910 return 0; 2911 } 2912 2913 int bond_3ad_get_active_agg_info(const struct bonding *bond, struct ad_info *ad_info) 2914 { 2915 int ret; 2916 2917 rcu_read_lock(); 2918 ret = __bond_3ad_get_active_agg_info(bond, ad_info); 2919 rcu_read_unlock(); 2920 2921 return ret; 2922 } 2923 2924 int bond_3ad_lacpdu_recv(const struct sk_buff *skb, struct bonding *bond, 2925 struct slave *slave) 2926 { 2927 struct lacpdu *lacpdu, _lacpdu; 2928 2929 if (skb->protocol != PKT_TYPE_LACPDU) 2930 return RX_HANDLER_ANOTHER; 2931 2932 if (!MAC_ADDRESS_EQUAL(eth_hdr(skb)->h_dest, lacpdu_mcast_addr)) 2933 return RX_HANDLER_ANOTHER; 2934 2935 lacpdu = skb_header_pointer(skb, 0, sizeof(_lacpdu), &_lacpdu); 2936 if (!lacpdu) { 2937 atomic64_inc(&SLAVE_AD_INFO(slave)->stats.lacpdu_illegal_rx); 2938 atomic64_inc(&BOND_AD_INFO(bond).stats.lacpdu_illegal_rx); 2939 return RX_HANDLER_ANOTHER; 2940 } 2941 2942 return bond_3ad_rx_indication(lacpdu, slave); 2943 } 2944 2945 /** 2946 * bond_3ad_update_lacp_rate - change the lacp rate 2947 * @bond: bonding struct 2948 * 2949 * When modify lacp_rate parameter via sysfs, 2950 * update actor_oper_port_state of each port. 2951 * 2952 * Hold bond->mode_lock, 2953 * so we can modify port->actor_oper_port_state, 2954 * no matter bond is up or down. 2955 */ 2956 void bond_3ad_update_lacp_rate(struct bonding *bond) 2957 { 2958 struct port *port = NULL; 2959 struct list_head *iter; 2960 struct slave *slave; 2961 int lacp_fast; 2962 2963 lacp_fast = bond->params.lacp_fast; 2964 spin_lock_bh(&bond->mode_lock); 2965 bond_for_each_slave(bond, slave, iter) { 2966 port = &(SLAVE_AD_INFO(slave)->port); 2967 if (lacp_fast) 2968 port->actor_oper_port_state |= LACP_STATE_LACP_TIMEOUT; 2969 else 2970 port->actor_oper_port_state &= ~LACP_STATE_LACP_TIMEOUT; 2971 } 2972 spin_unlock_bh(&bond->mode_lock); 2973 } 2974 2975 /** 2976 * bond_3ad_update_lacp_active - change the lacp active 2977 * @bond: bonding struct 2978 * 2979 * Update actor_oper_port_state when lacp_active is modified. 2980 */ 2981 void bond_3ad_update_lacp_active(struct bonding *bond) 2982 { 2983 struct port *port = NULL; 2984 struct list_head *iter; 2985 struct slave *slave; 2986 int lacp_active; 2987 2988 lacp_active = bond->params.lacp_active; 2989 spin_lock_bh(&bond->mode_lock); 2990 bond_for_each_slave(bond, slave, iter) { 2991 port = &(SLAVE_AD_INFO(slave)->port); 2992 if (lacp_active) 2993 port->actor_oper_port_state |= LACP_STATE_LACP_ACTIVITY; 2994 else 2995 port->actor_oper_port_state &= ~LACP_STATE_LACP_ACTIVITY; 2996 } 2997 spin_unlock_bh(&bond->mode_lock); 2998 } 2999 3000 size_t bond_3ad_stats_size(void) 3001 { 3002 return nla_total_size_64bit(sizeof(u64)) + /* BOND_3AD_STAT_LACPDU_RX */ 3003 nla_total_size_64bit(sizeof(u64)) + /* BOND_3AD_STAT_LACPDU_TX */ 3004 nla_total_size_64bit(sizeof(u64)) + /* BOND_3AD_STAT_LACPDU_UNKNOWN_RX */ 3005 nla_total_size_64bit(sizeof(u64)) + /* BOND_3AD_STAT_LACPDU_ILLEGAL_RX */ 3006 nla_total_size_64bit(sizeof(u64)) + /* BOND_3AD_STAT_MARKER_RX */ 3007 nla_total_size_64bit(sizeof(u64)) + /* BOND_3AD_STAT_MARKER_TX */ 3008 nla_total_size_64bit(sizeof(u64)) + /* BOND_3AD_STAT_MARKER_RESP_RX */ 3009 nla_total_size_64bit(sizeof(u64)) + /* BOND_3AD_STAT_MARKER_RESP_TX */ 3010 nla_total_size_64bit(sizeof(u64)); /* BOND_3AD_STAT_MARKER_UNKNOWN_RX */ 3011 } 3012 3013 int bond_3ad_stats_fill(struct sk_buff *skb, struct bond_3ad_stats *stats) 3014 { 3015 u64 val; 3016 3017 val = atomic64_read(&stats->lacpdu_rx); 3018 if (nla_put_u64_64bit(skb, BOND_3AD_STAT_LACPDU_RX, val, 3019 BOND_3AD_STAT_PAD)) 3020 return -EMSGSIZE; 3021 val = atomic64_read(&stats->lacpdu_tx); 3022 if (nla_put_u64_64bit(skb, BOND_3AD_STAT_LACPDU_TX, val, 3023 BOND_3AD_STAT_PAD)) 3024 return -EMSGSIZE; 3025 val = atomic64_read(&stats->lacpdu_unknown_rx); 3026 if (nla_put_u64_64bit(skb, BOND_3AD_STAT_LACPDU_UNKNOWN_RX, val, 3027 BOND_3AD_STAT_PAD)) 3028 return -EMSGSIZE; 3029 val = atomic64_read(&stats->lacpdu_illegal_rx); 3030 if (nla_put_u64_64bit(skb, BOND_3AD_STAT_LACPDU_ILLEGAL_RX, val, 3031 BOND_3AD_STAT_PAD)) 3032 return -EMSGSIZE; 3033 3034 val = atomic64_read(&stats->marker_rx); 3035 if (nla_put_u64_64bit(skb, BOND_3AD_STAT_MARKER_RX, val, 3036 BOND_3AD_STAT_PAD)) 3037 return -EMSGSIZE; 3038 val = atomic64_read(&stats->marker_tx); 3039 if (nla_put_u64_64bit(skb, BOND_3AD_STAT_MARKER_TX, val, 3040 BOND_3AD_STAT_PAD)) 3041 return -EMSGSIZE; 3042 val = atomic64_read(&stats->marker_resp_rx); 3043 if (nla_put_u64_64bit(skb, BOND_3AD_STAT_MARKER_RESP_RX, val, 3044 BOND_3AD_STAT_PAD)) 3045 return -EMSGSIZE; 3046 val = atomic64_read(&stats->marker_resp_tx); 3047 if (nla_put_u64_64bit(skb, BOND_3AD_STAT_MARKER_RESP_TX, val, 3048 BOND_3AD_STAT_PAD)) 3049 return -EMSGSIZE; 3050 val = atomic64_read(&stats->marker_unknown_rx); 3051 if (nla_put_u64_64bit(skb, BOND_3AD_STAT_MARKER_UNKNOWN_RX, val, 3052 BOND_3AD_STAT_PAD)) 3053 return -EMSGSIZE; 3054 3055 return 0; 3056 } 3057