Skip to content

Commit cd84ff4

Browse files
ecree-solarflaredavem330
authored andcommitted
sfc: Use ether_addr_copy and eth_broadcast_addr
Faster than memcpy/memset on some architectures. Signed-off-by: Edward Cree <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 1943364 commit cd84ff4

File tree

9 files changed

+37
-39
lines changed

9 files changed

+37
-39
lines changed

drivers/net/ethernet/sfc/ef10.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ static int efx_ef10_get_mac_address(struct efx_nic *efx, u8 *mac_address)
162162
if (outlen < MC_CMD_GET_MAC_ADDRESSES_OUT_LEN)
163163
return -EIO;
164164

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));
167167
return 0;
168168
}
169169

@@ -3145,12 +3145,10 @@ static void efx_ef10_filter_sync_rx_mode(struct efx_nic *efx)
31453145
table->dev_uc_count = -1;
31463146
} else {
31473147
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);
31503149
i = 1;
31513150
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);
31543152
i++;
31553153
}
31563154
}
@@ -3162,8 +3160,7 @@ static void efx_ef10_filter_sync_rx_mode(struct efx_nic *efx)
31623160
eth_broadcast_addr(table->dev_mc_list[0].addr);
31633161
i = 1;
31643162
netdev_for_each_mc_addr(mc, net_dev) {
3165-
memcpy(table->dev_mc_list[i].addr,
3166-
mc->addr, ETH_ALEN);
3163+
ether_addr_copy(table->dev_mc_list[i].addr, mc->addr);
31673164
i++;
31683165
}
31693166
}

drivers/net/ethernet/sfc/efx.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,7 +1012,7 @@ static int efx_probe_port(struct efx_nic *efx)
10121012
return rc;
10131013

10141014
/* 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);
10161016

10171017
return 0;
10181018
}
@@ -2120,7 +2120,7 @@ static int efx_set_mac_address(struct net_device *net_dev, void *data)
21202120
return -EADDRNOTAVAIL;
21212121
}
21222122

2123-
memcpy(net_dev->dev_addr, new_addr, net_dev->addr_len);
2123+
ether_addr_copy(net_dev->dev_addr, new_addr);
21242124
efx_sriov_mac_address_changed(efx);
21252125

21262126
/* Reconfigure the MAC */

drivers/net/ethernet/sfc/ethtool.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,7 @@ static int efx_ethtool_reset(struct net_device *net_dev, u32 *flags)
727727
}
728728

729729
/* 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};
731731

732732
#define IP4_ADDR_FULL_MASK ((__force __be32)~0)
733733
#define PORT_FULL_MASK ((__force __be16)~0)
@@ -787,16 +787,16 @@ static int efx_ethtool_get_class_rule(struct efx_nic *efx,
787787
rule->flow_type = ETHER_FLOW;
788788
if (spec.match_flags &
789789
(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);
791791
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);
793793
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);
796796
}
797797
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);
800800
}
801801
if (spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE) {
802802
mac_entry->h_proto = spec.ether_type;
@@ -968,13 +968,13 @@ static int efx_ethtool_set_class_rule(struct efx_nic *efx,
968968
spec.match_flags |= EFX_FILTER_MATCH_LOC_MAC;
969969
else
970970
return -EINVAL;
971-
memcpy(spec.loc_mac, mac_entry->h_dest, ETH_ALEN);
971+
ether_addr_copy(spec.loc_mac, mac_entry->h_dest);
972972
}
973973
if (!is_zero_ether_addr(mac_mask->h_source)) {
974974
if (!is_broadcast_ether_addr(mac_mask->h_source))
975975
return -EINVAL;
976976
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);
978978
}
979979
if (mac_mask->h_proto) {
980980
if (mac_mask->h_proto != ETHER_TYPE_FULL_MASK)

drivers/net/ethernet/sfc/falcon.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2183,7 +2183,7 @@ static int falcon_probe_nvconfig(struct efx_nic *efx)
21832183
}
21842184

21852185
/* 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]);
21872187

21882188
netif_dbg(efx, probe, efx->net_dev, "PHY is %d phy_id %d\n",
21892189
efx->phy_type, efx->mdio.prtad);

drivers/net/ethernet/sfc/filter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ static inline int efx_filter_set_eth_local(struct efx_filter_spec *spec,
243243
}
244244
if (addr != NULL) {
245245
spec->match_flags |= EFX_FILTER_MATCH_LOC_MAC;
246-
memcpy(spec->loc_mac, addr, ETH_ALEN);
246+
ether_addr_copy(spec->loc_mac, addr);
247247
}
248248
return 0;
249249
}

drivers/net/ethernet/sfc/mcdi.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,6 +1187,9 @@ int efx_mcdi_get_board_cfg(struct efx_nic *efx, u8 *mac_address,
11871187
int rc;
11881188

11891189
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);
11901193

11911194
rc = efx_mcdi_rpc(efx, MC_CMD_GET_BOARD_CFG, NULL, 0,
11921195
outbuf, sizeof(outbuf), &outlen);
@@ -1199,11 +1202,10 @@ int efx_mcdi_get_board_cfg(struct efx_nic *efx, u8 *mac_address,
11991202
}
12001203

12011204
if (mac_address)
1202-
memcpy(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),
1206-
ETH_ALEN);
1205+
ether_addr_copy(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));
12071209
if (fw_subtype_list) {
12081210
for (i = 0;
12091211
i < MCDI_VAR_ARRAY_LEN(outlen,
@@ -1532,7 +1534,7 @@ static int efx_mcdi_wol_filter_set(struct efx_nic *efx, u32 type,
15321534
MCDI_SET_DWORD(inbuf, WOL_FILTER_SET_IN_WOL_TYPE, type);
15331535
MCDI_SET_DWORD(inbuf, WOL_FILTER_SET_IN_FILTER_MODE,
15341536
MC_CMD_FILTER_MODE_SIMPLE);
1535-
memcpy(MCDI_PTR(inbuf, WOL_FILTER_SET_IN_MAGIC_MAC), mac, ETH_ALEN);
1537+
ether_addr_copy(MCDI_PTR(inbuf, WOL_FILTER_SET_IN_MAGIC_MAC), mac);
15361538

15371539
rc = efx_mcdi_rpc(efx, MC_CMD_WOL_FILTER_SET, inbuf, sizeof(inbuf),
15381540
outbuf, sizeof(outbuf), &outlen);

drivers/net/ethernet/sfc/mcdi_port.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -854,8 +854,8 @@ int efx_mcdi_set_mac(struct efx_nic *efx)
854854

855855
BUILD_BUG_ON(MC_CMD_SET_MAC_OUT_LEN != 0);
856856

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);
859859

860860
MCDI_SET_DWORD(cmdbytes, SET_MAC_IN_MTU,
861861
EFX_MAX_FRAME_LEN(efx->net_dev->mtu));

drivers/net/ethernet/sfc/selftest.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ struct efx_loopback_payload {
5050
} __packed;
5151

5252
/* Loopback test source MAC address */
53-
static const unsigned char payload_source[ETH_ALEN] = {
53+
static const u8 payload_source[ETH_ALEN] __aligned(2) = {
5454
0x00, 0x0f, 0x53, 0x1b, 0x1b, 0x1b,
5555
};
5656

@@ -366,8 +366,8 @@ static void efx_iterate_state(struct efx_nic *efx)
366366
struct efx_loopback_payload *payload = &state->payload;
367367

368368
/* 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);
371371
payload->header.h_proto = htons(ETH_P_IP);
372372

373373
/* saddr set later and used as incrementing count */

drivers/net/ethernet/sfc/siena_sriov.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,7 +1095,7 @@ static void efx_sriov_peer_work(struct work_struct *data)
10951095

10961096
/* Fill the remaining addresses */
10971097
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);
10991099
peer->tci = 0;
11001100
++peer;
11011101
++peer_count;
@@ -1303,8 +1303,7 @@ int efx_sriov_init(struct efx_nic *efx)
13031303
goto fail_vfs;
13041304

13051305
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);
13081307
efx->vf_init_count = efx->vf_count;
13091308
rtnl_unlock();
13101309

@@ -1452,8 +1451,8 @@ void efx_sriov_mac_address_changed(struct efx_nic *efx)
14521451

14531452
if (!efx->vf_init_count)
14541453
return;
1455-
memcpy(vfdi_status->peers[0].mac_addr,
1456-
efx->net_dev->dev_addr, ETH_ALEN);
1454+
ether_addr_copy(vfdi_status->peers[0].mac_addr,
1455+
efx->net_dev->dev_addr);
14571456
queue_work(vfdi_workqueue, &efx->peer_work);
14581457
}
14591458

@@ -1570,7 +1569,7 @@ int efx_sriov_set_vf_mac(struct net_device *net_dev, int vf_i, u8 *mac)
15701569
vf = efx->vf + vf_i;
15711570

15721571
mutex_lock(&vf->status_lock);
1573-
memcpy(vf->addr.mac_addr, mac, ETH_ALEN);
1572+
ether_addr_copy(vf->addr.mac_addr, mac);
15741573
__efx_sriov_update_vf_addr(vf);
15751574
mutex_unlock(&vf->status_lock);
15761575

@@ -1633,7 +1632,7 @@ int efx_sriov_get_vf_config(struct net_device *net_dev, int vf_i,
16331632
vf = efx->vf + vf_i;
16341633

16351634
ivi->vf = vf_i;
1636-
memcpy(ivi->mac, vf->addr.mac_addr, ETH_ALEN);
1635+
ether_addr_copy(ivi->mac, vf->addr.mac_addr);
16371636
ivi->tx_rate = 0;
16381637
tci = ntohs(vf->addr.tci);
16391638
ivi->vlan = tci & VLAN_VID_MASK;

0 commit comments

Comments
 (0)