diff options
author | dingtianhong <dingtianhong@huawei.com> | 2014-01-01 20:12:54 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2014-01-01 22:58:15 -0500 |
commit | 815117adaf5b87155a73d2b4b9c556977bad51cb (patch) | |
tree | 7dd00b30af601f17cbf9e359c071c5fcaace0bfb /drivers | |
parent | 4b903e30bb24db592f3d52b9dd80744c3556705c (diff) |
bonding: use ether_addr_equal_unaligned for bond addr compare
Use possibly more efficient ether_addr_equal_64bits
to instead of memcmp.
Modify the MAC_ADDR_COMPARE to MAC_ADDR_EQUAL, this looks more
appropriate.
The comments for the bond 3ad is too old, cleanup some errors
and warming.
Suggested-by: Joe Perches <joe@perches.com>
Signed-off-by: Ding Tianhong <dingtianhong@huawei.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/net/bonding/bond_3ad.c | 62 |
1 files changed, 33 insertions, 29 deletions
diff --git a/drivers/net/bonding/bond_3ad.c b/drivers/net/bonding/bond_3ad.c index 58c2249a3324..5393e1ed8d4e 100644 --- a/drivers/net/bonding/bond_3ad.c +++ b/drivers/net/bonding/bond_3ad.c | |||
@@ -90,8 +90,9 @@ | |||
90 | #define AD_LINK_SPEED_BITMASK_10000MBPS 0x10 | 90 | #define AD_LINK_SPEED_BITMASK_10000MBPS 0x10 |
91 | //endalloun | 91 | //endalloun |
92 | 92 | ||
93 | // compare MAC addresses | 93 | /* compare MAC addresses */ |
94 | #define MAC_ADDRESS_COMPARE(A, B) memcmp(A, B, ETH_ALEN) | 94 | #define MAC_ADDRESS_EQUAL(A, B) \ |
95 | ether_addr_equal_64bits((const u8 *)A, (const u8 *)B) | ||
95 | 96 | ||
96 | static struct mac_addr null_mac_addr = { { 0, 0, 0, 0, 0, 0 } }; | 97 | static struct mac_addr null_mac_addr = { { 0, 0, 0, 0, 0, 0 } }; |
97 | static u16 ad_ticks_per_sec; | 98 | static u16 ad_ticks_per_sec; |
@@ -417,17 +418,18 @@ static u16 __ad_timer_to_ticks(u16 timer_type, u16 par) | |||
417 | */ | 418 | */ |
418 | static void __choose_matched(struct lacpdu *lacpdu, struct port *port) | 419 | static void __choose_matched(struct lacpdu *lacpdu, struct port *port) |
419 | { | 420 | { |
420 | // check if all parameters are alike | 421 | /* check if all parameters are alike |
422 | * or this is individual link(aggregation == FALSE) | ||
423 | * then update the state machine Matched variable. | ||
424 | */ | ||
421 | if (((ntohs(lacpdu->partner_port) == port->actor_port_number) && | 425 | if (((ntohs(lacpdu->partner_port) == port->actor_port_number) && |
422 | (ntohs(lacpdu->partner_port_priority) == port->actor_port_priority) && | 426 | (ntohs(lacpdu->partner_port_priority) == port->actor_port_priority) && |
423 | !MAC_ADDRESS_COMPARE(&(lacpdu->partner_system), &(port->actor_system)) && | 427 | MAC_ADDRESS_EQUAL(&(lacpdu->partner_system), &(port->actor_system)) && |
424 | (ntohs(lacpdu->partner_system_priority) == port->actor_system_priority) && | 428 | (ntohs(lacpdu->partner_system_priority) == port->actor_system_priority) && |
425 | (ntohs(lacpdu->partner_key) == port->actor_oper_port_key) && | 429 | (ntohs(lacpdu->partner_key) == port->actor_oper_port_key) && |
426 | ((lacpdu->partner_state & AD_STATE_AGGREGATION) == (port->actor_oper_port_state & AD_STATE_AGGREGATION))) || | 430 | ((lacpdu->partner_state & AD_STATE_AGGREGATION) == (port->actor_oper_port_state & AD_STATE_AGGREGATION))) || |
427 | // or this is individual link(aggregation == FALSE) | ||
428 | ((lacpdu->actor_state & AD_STATE_AGGREGATION) == 0) | 431 | ((lacpdu->actor_state & AD_STATE_AGGREGATION) == 0) |
429 | ) { | 432 | ) { |
430 | // update the state machine Matched variable | ||
431 | port->sm_vars |= AD_PORT_MATCHED; | 433 | port->sm_vars |= AD_PORT_MATCHED; |
432 | } else { | 434 | } else { |
433 | port->sm_vars &= ~AD_PORT_MATCHED; | 435 | port->sm_vars &= ~AD_PORT_MATCHED; |
@@ -507,14 +509,15 @@ static void __update_selected(struct lacpdu *lacpdu, struct port *port) | |||
507 | if (lacpdu && port) { | 509 | if (lacpdu && port) { |
508 | const struct port_params *partner = &port->partner_oper; | 510 | const struct port_params *partner = &port->partner_oper; |
509 | 511 | ||
510 | // check if any parameter is different | 512 | /* check if any parameter is different then |
513 | * update the state machine selected variable. | ||
514 | */ | ||
511 | if (ntohs(lacpdu->actor_port) != partner->port_number || | 515 | if (ntohs(lacpdu->actor_port) != partner->port_number || |
512 | ntohs(lacpdu->actor_port_priority) != partner->port_priority || | 516 | ntohs(lacpdu->actor_port_priority) != partner->port_priority || |
513 | MAC_ADDRESS_COMPARE(&lacpdu->actor_system, &partner->system) || | 517 | !MAC_ADDRESS_EQUAL(&lacpdu->actor_system, &partner->system) || |
514 | ntohs(lacpdu->actor_system_priority) != partner->system_priority || | 518 | ntohs(lacpdu->actor_system_priority) != partner->system_priority || |
515 | ntohs(lacpdu->actor_key) != partner->key || | 519 | ntohs(lacpdu->actor_key) != partner->key || |
516 | (lacpdu->actor_state & AD_STATE_AGGREGATION) != (partner->port_state & AD_STATE_AGGREGATION)) { | 520 | (lacpdu->actor_state & AD_STATE_AGGREGATION) != (partner->port_state & AD_STATE_AGGREGATION)) { |
517 | // update the state machine Selected variable | ||
518 | port->sm_vars &= ~AD_PORT_SELECTED; | 521 | port->sm_vars &= ~AD_PORT_SELECTED; |
519 | } | 522 | } |
520 | } | 523 | } |
@@ -538,15 +541,16 @@ static void __update_default_selected(struct port *port) | |||
538 | const struct port_params *admin = &port->partner_admin; | 541 | const struct port_params *admin = &port->partner_admin; |
539 | const struct port_params *oper = &port->partner_oper; | 542 | const struct port_params *oper = &port->partner_oper; |
540 | 543 | ||
541 | // check if any parameter is different | 544 | /* check if any parameter is different then |
545 | * update the state machine selected variable. | ||
546 | */ | ||
542 | if (admin->port_number != oper->port_number || | 547 | if (admin->port_number != oper->port_number || |
543 | admin->port_priority != oper->port_priority || | 548 | admin->port_priority != oper->port_priority || |
544 | MAC_ADDRESS_COMPARE(&admin->system, &oper->system) || | 549 | !MAC_ADDRESS_EQUAL(&admin->system, &oper->system) || |
545 | admin->system_priority != oper->system_priority || | 550 | admin->system_priority != oper->system_priority || |
546 | admin->key != oper->key || | 551 | admin->key != oper->key || |
547 | (admin->port_state & AD_STATE_AGGREGATION) | 552 | (admin->port_state & AD_STATE_AGGREGATION) |
548 | != (oper->port_state & AD_STATE_AGGREGATION)) { | 553 | != (oper->port_state & AD_STATE_AGGREGATION)) { |
549 | // update the state machine Selected variable | ||
550 | port->sm_vars &= ~AD_PORT_SELECTED; | 554 | port->sm_vars &= ~AD_PORT_SELECTED; |
551 | } | 555 | } |
552 | } | 556 | } |
@@ -566,12 +570,14 @@ static void __update_default_selected(struct port *port) | |||
566 | */ | 570 | */ |
567 | static void __update_ntt(struct lacpdu *lacpdu, struct port *port) | 571 | static void __update_ntt(struct lacpdu *lacpdu, struct port *port) |
568 | { | 572 | { |
569 | // validate lacpdu and port | 573 | /* validate lacpdu and port */ |
570 | if (lacpdu && port) { | 574 | if (lacpdu && port) { |
571 | // check if any parameter is different | 575 | /* check if any parameter is different then |
576 | * update the port->ntt. | ||
577 | */ | ||
572 | if ((ntohs(lacpdu->partner_port) != port->actor_port_number) || | 578 | if ((ntohs(lacpdu->partner_port) != port->actor_port_number) || |
573 | (ntohs(lacpdu->partner_port_priority) != port->actor_port_priority) || | 579 | (ntohs(lacpdu->partner_port_priority) != port->actor_port_priority) || |
574 | MAC_ADDRESS_COMPARE(&(lacpdu->partner_system), &(port->actor_system)) || | 580 | !MAC_ADDRESS_EQUAL(&(lacpdu->partner_system), &(port->actor_system)) || |
575 | (ntohs(lacpdu->partner_system_priority) != port->actor_system_priority) || | 581 | (ntohs(lacpdu->partner_system_priority) != port->actor_system_priority) || |
576 | (ntohs(lacpdu->partner_key) != port->actor_oper_port_key) || | 582 | (ntohs(lacpdu->partner_key) != port->actor_oper_port_key) || |
577 | ((lacpdu->partner_state & AD_STATE_LACP_ACTIVITY) != (port->actor_oper_port_state & AD_STATE_LACP_ACTIVITY)) || | 583 | ((lacpdu->partner_state & AD_STATE_LACP_ACTIVITY) != (port->actor_oper_port_state & AD_STATE_LACP_ACTIVITY)) || |
@@ -579,7 +585,6 @@ static void __update_ntt(struct lacpdu *lacpdu, struct port *port) | |||
579 | ((lacpdu->partner_state & AD_STATE_SYNCHRONIZATION) != (port->actor_oper_port_state & AD_STATE_SYNCHRONIZATION)) || | 585 | ((lacpdu->partner_state & AD_STATE_SYNCHRONIZATION) != (port->actor_oper_port_state & AD_STATE_SYNCHRONIZATION)) || |
580 | ((lacpdu->partner_state & AD_STATE_AGGREGATION) != (port->actor_oper_port_state & AD_STATE_AGGREGATION)) | 586 | ((lacpdu->partner_state & AD_STATE_AGGREGATION) != (port->actor_oper_port_state & AD_STATE_AGGREGATION)) |
581 | ) { | 587 | ) { |
582 | |||
583 | port->ntt = true; | 588 | port->ntt = true; |
584 | } | 589 | } |
585 | } | 590 | } |
@@ -1076,9 +1081,8 @@ static void ad_rx_machine(struct lacpdu *lacpdu, struct port *port) | |||
1076 | port->actor_oper_port_state &= ~AD_STATE_EXPIRED; | 1081 | port->actor_oper_port_state &= ~AD_STATE_EXPIRED; |
1077 | break; | 1082 | break; |
1078 | case AD_RX_CURRENT: | 1083 | case AD_RX_CURRENT: |
1079 | // detect loopback situation | 1084 | /* detect loopback situation */ |
1080 | if (!MAC_ADDRESS_COMPARE(&(lacpdu->actor_system), &(port->actor_system))) { | 1085 | if (MAC_ADDRESS_EQUAL(&(lacpdu->actor_system), &(port->actor_system))) { |
1081 | // INFO_RECEIVED_LOOPBACK_FRAMES | ||
1082 | pr_err("%s: An illegal loopback occurred on adapter (%s).\n" | 1086 | pr_err("%s: An illegal loopback occurred on adapter (%s).\n" |
1083 | "Check the configuration to verify that all adapters are connected to 802.3ad compliant switch ports\n", | 1087 | "Check the configuration to verify that all adapters are connected to 802.3ad compliant switch ports\n", |
1084 | port->slave->bond->dev->name, port->slave->dev->name); | 1088 | port->slave->bond->dev->name, port->slave->dev->name); |
@@ -1090,7 +1094,7 @@ static void ad_rx_machine(struct lacpdu *lacpdu, struct port *port) | |||
1090 | port->sm_rx_timer_counter = __ad_timer_to_ticks(AD_CURRENT_WHILE_TIMER, (u16)(port->actor_oper_port_state & AD_STATE_LACP_TIMEOUT)); | 1094 | port->sm_rx_timer_counter = __ad_timer_to_ticks(AD_CURRENT_WHILE_TIMER, (u16)(port->actor_oper_port_state & AD_STATE_LACP_TIMEOUT)); |
1091 | port->actor_oper_port_state &= ~AD_STATE_EXPIRED; | 1095 | port->actor_oper_port_state &= ~AD_STATE_EXPIRED; |
1092 | break; | 1096 | break; |
1093 | default: //to silence the compiler | 1097 | default: /* to silence the compiler */ |
1094 | break; | 1098 | break; |
1095 | } | 1099 | } |
1096 | } | 1100 | } |
@@ -1281,17 +1285,17 @@ static void ad_port_selection_logic(struct port *port) | |||
1281 | free_aggregator = aggregator; | 1285 | free_aggregator = aggregator; |
1282 | continue; | 1286 | continue; |
1283 | } | 1287 | } |
1284 | // check if current aggregator suits us | 1288 | /* check if current aggregator suits us */ |
1285 | if (((aggregator->actor_oper_aggregator_key == port->actor_oper_port_key) && // if all parameters match AND | 1289 | if (((aggregator->actor_oper_aggregator_key == port->actor_oper_port_key) && /* if all parameters match AND */ |
1286 | !MAC_ADDRESS_COMPARE(&(aggregator->partner_system), &(port->partner_oper.system)) && | 1290 | MAC_ADDRESS_EQUAL(&(aggregator->partner_system), &(port->partner_oper.system)) && |
1287 | (aggregator->partner_system_priority == port->partner_oper.system_priority) && | 1291 | (aggregator->partner_system_priority == port->partner_oper.system_priority) && |
1288 | (aggregator->partner_oper_aggregator_key == port->partner_oper.key) | 1292 | (aggregator->partner_oper_aggregator_key == port->partner_oper.key) |
1289 | ) && | 1293 | ) && |
1290 | ((MAC_ADDRESS_COMPARE(&(port->partner_oper.system), &(null_mac_addr)) && // partner answers | 1294 | ((!MAC_ADDRESS_EQUAL(&(port->partner_oper.system), &(null_mac_addr)) && /* partner answers */ |
1291 | !aggregator->is_individual) // but is not individual OR | 1295 | !aggregator->is_individual) /* but is not individual OR */ |
1292 | ) | 1296 | ) |
1293 | ) { | 1297 | ) { |
1294 | // attach to the founded aggregator | 1298 | /* attach to the founded aggregator */ |
1295 | port->aggregator = aggregator; | 1299 | port->aggregator = aggregator; |
1296 | port->actor_port_aggregator_identifier = | 1300 | port->actor_port_aggregator_identifier = |
1297 | port->aggregator->aggregator_identifier; | 1301 | port->aggregator->aggregator_identifier; |
@@ -1705,7 +1709,7 @@ static void ad_enable_collecting_distributing(struct port *port) | |||
1705 | */ | 1709 | */ |
1706 | static void ad_disable_collecting_distributing(struct port *port) | 1710 | static void ad_disable_collecting_distributing(struct port *port) |
1707 | { | 1711 | { |
1708 | if (port->aggregator && MAC_ADDRESS_COMPARE(&(port->aggregator->partner_system), &(null_mac_addr))) { | 1712 | if (port->aggregator && !MAC_ADDRESS_EQUAL(&(port->aggregator->partner_system), &(null_mac_addr))) { |
1709 | pr_debug("Disabling port %d(LAG %d)\n", | 1713 | pr_debug("Disabling port %d(LAG %d)\n", |
1710 | port->actor_port_number, | 1714 | port->actor_port_number, |
1711 | port->aggregator->aggregator_identifier); | 1715 | port->aggregator->aggregator_identifier); |
@@ -1826,8 +1830,8 @@ static u16 aggregator_identifier; | |||
1826 | */ | 1830 | */ |
1827 | void bond_3ad_initialize(struct bonding *bond, u16 tick_resolution) | 1831 | void bond_3ad_initialize(struct bonding *bond, u16 tick_resolution) |
1828 | { | 1832 | { |
1829 | // check that the bond is not initialized yet | 1833 | /* check that the bond is not initialized yet */ |
1830 | if (MAC_ADDRESS_COMPARE(&(BOND_AD_INFO(bond).system.sys_mac_addr), | 1834 | if (!MAC_ADDRESS_EQUAL(&(BOND_AD_INFO(bond).system.sys_mac_addr), |
1831 | bond->dev->dev_addr)) { | 1835 | bond->dev->dev_addr)) { |
1832 | 1836 | ||
1833 | aggregator_identifier = 0; | 1837 | aggregator_identifier = 0; |