Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

sfc: Use ether_addr_copy and eth_broadcast_addr

Faster than memcpy/memset on some architectures.

Signed-off-by: Edward Cree <ecree@solarflare.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Edward Cree and committed by
David S. Miller
cd84ff4d 19433646

+37 -39
+5 -8
drivers/net/ethernet/sfc/ef10.c
··· 162 162 if (outlen < MC_CMD_GET_MAC_ADDRESSES_OUT_LEN) 163 163 return -EIO; 164 164 165 - memcpy(mac_address, 166 - MCDI_PTR(outbuf, GET_MAC_ADDRESSES_OUT_MAC_ADDR_BASE), ETH_ALEN); 165 + ether_addr_copy(mac_address, 166 + MCDI_PTR(outbuf, GET_MAC_ADDRESSES_OUT_MAC_ADDR_BASE)); 167 167 return 0; 168 168 } 169 169 ··· 3145 3145 table->dev_uc_count = -1; 3146 3146 } else { 3147 3147 table->dev_uc_count = 1 + netdev_uc_count(net_dev); 3148 - memcpy(table->dev_uc_list[0].addr, net_dev->dev_addr, 3149 - ETH_ALEN); 3148 + ether_addr_copy(table->dev_uc_list[0].addr, net_dev->dev_addr); 3150 3149 i = 1; 3151 3150 netdev_for_each_uc_addr(uc, net_dev) { 3152 - memcpy(table->dev_uc_list[i].addr, 3153 - uc->addr, ETH_ALEN); 3151 + ether_addr_copy(table->dev_uc_list[i].addr, uc->addr); 3154 3152 i++; 3155 3153 } 3156 3154 } ··· 3160 3162 eth_broadcast_addr(table->dev_mc_list[0].addr); 3161 3163 i = 1; 3162 3164 netdev_for_each_mc_addr(mc, net_dev) { 3163 - memcpy(table->dev_mc_list[i].addr, 3164 - mc->addr, ETH_ALEN); 3165 + ether_addr_copy(table->dev_mc_list[i].addr, mc->addr); 3165 3166 i++; 3166 3167 } 3167 3168 }
+2 -2
drivers/net/ethernet/sfc/efx.c
··· 1012 1012 return rc; 1013 1013 1014 1014 /* Initialise MAC address to permanent address */ 1015 - memcpy(efx->net_dev->dev_addr, efx->net_dev->perm_addr, ETH_ALEN); 1015 + ether_addr_copy(efx->net_dev->dev_addr, efx->net_dev->perm_addr); 1016 1016 1017 1017 return 0; 1018 1018 } ··· 2120 2120 return -EADDRNOTAVAIL; 2121 2121 } 2122 2122 2123 - memcpy(net_dev->dev_addr, new_addr, net_dev->addr_len); 2123 + ether_addr_copy(net_dev->dev_addr, new_addr); 2124 2124 efx_sriov_mac_address_changed(efx); 2125 2125 2126 2126 /* Reconfigure the MAC */
+9 -9
drivers/net/ethernet/sfc/ethtool.c
··· 727 727 } 728 728 729 729 /* MAC address mask including only I/G bit */ 730 - static const u8 mac_addr_ig_mask[ETH_ALEN] = { 0x01, 0, 0, 0, 0, 0 }; 730 + static const u8 mac_addr_ig_mask[ETH_ALEN] __aligned(2) = {0x01, 0, 0, 0, 0, 0}; 731 731 732 732 #define IP4_ADDR_FULL_MASK ((__force __be32)~0) 733 733 #define PORT_FULL_MASK ((__force __be16)~0) ··· 787 787 rule->flow_type = ETHER_FLOW; 788 788 if (spec.match_flags & 789 789 (EFX_FILTER_MATCH_LOC_MAC | EFX_FILTER_MATCH_LOC_MAC_IG)) { 790 - memcpy(mac_entry->h_dest, spec.loc_mac, ETH_ALEN); 790 + ether_addr_copy(mac_entry->h_dest, spec.loc_mac); 791 791 if (spec.match_flags & EFX_FILTER_MATCH_LOC_MAC) 792 - memset(mac_mask->h_dest, ~0, ETH_ALEN); 792 + eth_broadcast_addr(mac_mask->h_dest); 793 793 else 794 - memcpy(mac_mask->h_dest, mac_addr_ig_mask, 795 - ETH_ALEN); 794 + ether_addr_copy(mac_mask->h_dest, 795 + mac_addr_ig_mask); 796 796 } 797 797 if (spec.match_flags & EFX_FILTER_MATCH_REM_MAC) { 798 - memcpy(mac_entry->h_source, spec.rem_mac, ETH_ALEN); 799 - memset(mac_mask->h_source, ~0, ETH_ALEN); 798 + ether_addr_copy(mac_entry->h_source, spec.rem_mac); 799 + eth_broadcast_addr(mac_mask->h_source); 800 800 } 801 801 if (spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE) { 802 802 mac_entry->h_proto = spec.ether_type; ··· 968 968 spec.match_flags |= EFX_FILTER_MATCH_LOC_MAC; 969 969 else 970 970 return -EINVAL; 971 - memcpy(spec.loc_mac, mac_entry->h_dest, ETH_ALEN); 971 + ether_addr_copy(spec.loc_mac, mac_entry->h_dest); 972 972 } 973 973 if (!is_zero_ether_addr(mac_mask->h_source)) { 974 974 if (!is_broadcast_ether_addr(mac_mask->h_source)) 975 975 return -EINVAL; 976 976 spec.match_flags |= EFX_FILTER_MATCH_REM_MAC; 977 - memcpy(spec.rem_mac, mac_entry->h_source, ETH_ALEN); 977 + ether_addr_copy(spec.rem_mac, mac_entry->h_source); 978 978 } 979 979 if (mac_mask->h_proto) { 980 980 if (mac_mask->h_proto != ETHER_TYPE_FULL_MASK)
+1 -1
drivers/net/ethernet/sfc/falcon.c
··· 2183 2183 } 2184 2184 2185 2185 /* Read the MAC addresses */ 2186 - memcpy(efx->net_dev->perm_addr, nvconfig->mac_address[0], ETH_ALEN); 2186 + ether_addr_copy(efx->net_dev->perm_addr, nvconfig->mac_address[0]); 2187 2187 2188 2188 netif_dbg(efx, probe, efx->net_dev, "PHY is %d phy_id %d\n", 2189 2189 efx->phy_type, efx->mdio.prtad);
+1 -1
drivers/net/ethernet/sfc/filter.h
··· 243 243 } 244 244 if (addr != NULL) { 245 245 spec->match_flags |= EFX_FILTER_MATCH_LOC_MAC; 246 - memcpy(spec->loc_mac, addr, ETH_ALEN); 246 + ether_addr_copy(spec->loc_mac, addr); 247 247 } 248 248 return 0; 249 249 }
+8 -6
drivers/net/ethernet/sfc/mcdi.c
··· 1187 1187 int rc; 1188 1188 1189 1189 BUILD_BUG_ON(MC_CMD_GET_BOARD_CFG_IN_LEN != 0); 1190 + /* we need __aligned(2) for ether_addr_copy */ 1191 + BUILD_BUG_ON(MC_CMD_GET_BOARD_CFG_OUT_MAC_ADDR_BASE_PORT0_OFST & 1); 1192 + BUILD_BUG_ON(MC_CMD_GET_BOARD_CFG_OUT_MAC_ADDR_BASE_PORT1_OFST & 1); 1190 1193 1191 1194 rc = efx_mcdi_rpc(efx, MC_CMD_GET_BOARD_CFG, NULL, 0, 1192 1195 outbuf, sizeof(outbuf), &outlen); ··· 1202 1199 } 1203 1200 1204 1201 if (mac_address) 1205 - memcpy(mac_address, 1206 - port_num ? 1207 - MCDI_PTR(outbuf, GET_BOARD_CFG_OUT_MAC_ADDR_BASE_PORT1) : 1208 - MCDI_PTR(outbuf, GET_BOARD_CFG_OUT_MAC_ADDR_BASE_PORT0), 1209 - ETH_ALEN); 1202 + ether_addr_copy(mac_address, 1203 + port_num ? 1204 + MCDI_PTR(outbuf, GET_BOARD_CFG_OUT_MAC_ADDR_BASE_PORT1) : 1205 + MCDI_PTR(outbuf, GET_BOARD_CFG_OUT_MAC_ADDR_BASE_PORT0)); 1210 1206 if (fw_subtype_list) { 1211 1207 for (i = 0; 1212 1208 i < MCDI_VAR_ARRAY_LEN(outlen, ··· 1534 1532 MCDI_SET_DWORD(inbuf, WOL_FILTER_SET_IN_WOL_TYPE, type); 1535 1533 MCDI_SET_DWORD(inbuf, WOL_FILTER_SET_IN_FILTER_MODE, 1536 1534 MC_CMD_FILTER_MODE_SIMPLE); 1537 - memcpy(MCDI_PTR(inbuf, WOL_FILTER_SET_IN_MAGIC_MAC), mac, ETH_ALEN); 1535 + ether_addr_copy(MCDI_PTR(inbuf, WOL_FILTER_SET_IN_MAGIC_MAC), mac); 1538 1536 1539 1537 rc = efx_mcdi_rpc(efx, MC_CMD_WOL_FILTER_SET, inbuf, sizeof(inbuf), 1540 1538 outbuf, sizeof(outbuf), &outlen);
+2 -2
drivers/net/ethernet/sfc/mcdi_port.c
··· 854 854 855 855 BUILD_BUG_ON(MC_CMD_SET_MAC_OUT_LEN != 0); 856 856 857 - memcpy(MCDI_PTR(cmdbytes, SET_MAC_IN_ADDR), 858 - efx->net_dev->dev_addr, ETH_ALEN); 857 + ether_addr_copy(MCDI_PTR(cmdbytes, SET_MAC_IN_ADDR), 858 + efx->net_dev->dev_addr); 859 859 860 860 MCDI_SET_DWORD(cmdbytes, SET_MAC_IN_MTU, 861 861 EFX_MAX_FRAME_LEN(efx->net_dev->mtu));
+3 -3
drivers/net/ethernet/sfc/selftest.c
··· 50 50 } __packed; 51 51 52 52 /* Loopback test source MAC address */ 53 - static const unsigned char payload_source[ETH_ALEN] = { 53 + static const u8 payload_source[ETH_ALEN] __aligned(2) = { 54 54 0x00, 0x0f, 0x53, 0x1b, 0x1b, 0x1b, 55 55 }; 56 56 ··· 366 366 struct efx_loopback_payload *payload = &state->payload; 367 367 368 368 /* Initialise the layerII header */ 369 - memcpy(&payload->header.h_dest, net_dev->dev_addr, ETH_ALEN); 370 - memcpy(&payload->header.h_source, &payload_source, ETH_ALEN); 369 + ether_addr_copy((u8 *)&payload->header.h_dest, net_dev->dev_addr); 370 + ether_addr_copy((u8 *)&payload->header.h_source, payload_source); 371 371 payload->header.h_proto = htons(ETH_P_IP); 372 372 373 373 /* saddr set later and used as incrementing count */
+6 -7
drivers/net/ethernet/sfc/siena_sriov.c
··· 1095 1095 1096 1096 /* Fill the remaining addresses */ 1097 1097 list_for_each_entry(local_addr, &efx->local_addr_list, link) { 1098 - memcpy(peer->mac_addr, local_addr->addr, ETH_ALEN); 1098 + ether_addr_copy(peer->mac_addr, local_addr->addr); 1099 1099 peer->tci = 0; 1100 1100 ++peer; 1101 1101 ++peer_count; ··· 1303 1303 goto fail_vfs; 1304 1304 1305 1305 rtnl_lock(); 1306 - memcpy(vfdi_status->peers[0].mac_addr, 1307 - net_dev->dev_addr, ETH_ALEN); 1306 + ether_addr_copy(vfdi_status->peers[0].mac_addr, net_dev->dev_addr); 1308 1307 efx->vf_init_count = efx->vf_count; 1309 1308 rtnl_unlock(); 1310 1309 ··· 1451 1452 1452 1453 if (!efx->vf_init_count) 1453 1454 return; 1454 - memcpy(vfdi_status->peers[0].mac_addr, 1455 - efx->net_dev->dev_addr, ETH_ALEN); 1455 + ether_addr_copy(vfdi_status->peers[0].mac_addr, 1456 + efx->net_dev->dev_addr); 1456 1457 queue_work(vfdi_workqueue, &efx->peer_work); 1457 1458 } 1458 1459 ··· 1569 1570 vf = efx->vf + vf_i; 1570 1571 1571 1572 mutex_lock(&vf->status_lock); 1572 - memcpy(vf->addr.mac_addr, mac, ETH_ALEN); 1573 + ether_addr_copy(vf->addr.mac_addr, mac); 1573 1574 __efx_sriov_update_vf_addr(vf); 1574 1575 mutex_unlock(&vf->status_lock); 1575 1576 ··· 1632 1633 vf = efx->vf + vf_i; 1633 1634 1634 1635 ivi->vf = vf_i; 1635 - memcpy(ivi->mac, vf->addr.mac_addr, ETH_ALEN); 1636 + ether_addr_copy(ivi->mac, vf->addr.mac_addr); 1636 1637 ivi->tx_rate = 0; 1637 1638 tci = ntohs(vf->addr.tci); 1638 1639 ivi->vlan = tci & VLAN_VID_MASK;