mirror of
https://github.com/torvalds/linux.git
synced 2024-11-15 00:21:59 +00:00
sfc: siena: use padding to fix alignment in loopback test
Add two bytes of padding to the start of struct efx_loopback_payload, which are not sent on the wire. This ensures the 'ip' member is 4-byte aligned, preventing the following W=1 warning: net/ethernet/sfc/siena/selftest.c:46:15: error: field ip within 'struct efx_loopback_payload' is less aligned than 'struct iphdr' and is usually due to 'struct efx_loopback_payload' being packed, which can lead to unaligned accesses [-Werror,-Wunaligned-access] struct iphdr ip; Reported-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Edward Cree <ecree.xilinx@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
cf60ed4696
commit
30c24dd87f
@ -42,12 +42,16 @@
|
|||||||
* Falcon only performs RSS on TCP/UDP packets.
|
* Falcon only performs RSS on TCP/UDP packets.
|
||||||
*/
|
*/
|
||||||
struct efx_loopback_payload {
|
struct efx_loopback_payload {
|
||||||
|
char pad[2]; /* Ensures ip is 4-byte aligned */
|
||||||
struct ethhdr header;
|
struct ethhdr header;
|
||||||
struct iphdr ip;
|
struct iphdr ip;
|
||||||
struct udphdr udp;
|
struct udphdr udp;
|
||||||
__be16 iteration;
|
__be16 iteration;
|
||||||
char msg[64];
|
char msg[64];
|
||||||
} __packed;
|
} __packed __aligned(4);
|
||||||
|
#define EFX_LOOPBACK_PAYLOAD_LEN (sizeof(struct efx_loopback_payload) - \
|
||||||
|
offsetof(struct efx_loopback_payload, \
|
||||||
|
header))
|
||||||
|
|
||||||
/* Loopback test source MAC address */
|
/* Loopback test source MAC address */
|
||||||
static const u8 payload_source[ETH_ALEN] __aligned(2) = {
|
static const u8 payload_source[ETH_ALEN] __aligned(2) = {
|
||||||
@ -282,7 +286,7 @@ void efx_siena_loopback_rx_packet(struct efx_nic *efx,
|
|||||||
const char *buf_ptr, int pkt_len)
|
const char *buf_ptr, int pkt_len)
|
||||||
{
|
{
|
||||||
struct efx_loopback_state *state = efx->loopback_selftest;
|
struct efx_loopback_state *state = efx->loopback_selftest;
|
||||||
struct efx_loopback_payload *received;
|
struct efx_loopback_payload received;
|
||||||
struct efx_loopback_payload *payload;
|
struct efx_loopback_payload *payload;
|
||||||
|
|
||||||
BUG_ON(!buf_ptr);
|
BUG_ON(!buf_ptr);
|
||||||
@ -293,13 +297,14 @@ void efx_siena_loopback_rx_packet(struct efx_nic *efx,
|
|||||||
|
|
||||||
payload = &state->payload;
|
payload = &state->payload;
|
||||||
|
|
||||||
received = (struct efx_loopback_payload *) buf_ptr;
|
memcpy(&received.header, buf_ptr,
|
||||||
received->ip.saddr = payload->ip.saddr;
|
min_t(int, pkt_len, EFX_LOOPBACK_PAYLOAD_LEN));
|
||||||
|
received.ip.saddr = payload->ip.saddr;
|
||||||
if (state->offload_csum)
|
if (state->offload_csum)
|
||||||
received->ip.check = payload->ip.check;
|
received.ip.check = payload->ip.check;
|
||||||
|
|
||||||
/* Check that header exists */
|
/* Check that header exists */
|
||||||
if (pkt_len < sizeof(received->header)) {
|
if (pkt_len < sizeof(received.header)) {
|
||||||
netif_err(efx, drv, efx->net_dev,
|
netif_err(efx, drv, efx->net_dev,
|
||||||
"saw runt RX packet (length %d) in %s loopback "
|
"saw runt RX packet (length %d) in %s loopback "
|
||||||
"test\n", pkt_len, LOOPBACK_MODE(efx));
|
"test\n", pkt_len, LOOPBACK_MODE(efx));
|
||||||
@ -307,7 +312,7 @@ void efx_siena_loopback_rx_packet(struct efx_nic *efx,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Check that the ethernet header exists */
|
/* Check that the ethernet header exists */
|
||||||
if (memcmp(&received->header, &payload->header, ETH_HLEN) != 0) {
|
if (memcmp(&received.header, &payload->header, ETH_HLEN) != 0) {
|
||||||
netif_err(efx, drv, efx->net_dev,
|
netif_err(efx, drv, efx->net_dev,
|
||||||
"saw non-loopback RX packet in %s loopback test\n",
|
"saw non-loopback RX packet in %s loopback test\n",
|
||||||
LOOPBACK_MODE(efx));
|
LOOPBACK_MODE(efx));
|
||||||
@ -315,16 +320,16 @@ void efx_siena_loopback_rx_packet(struct efx_nic *efx,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Check packet length */
|
/* Check packet length */
|
||||||
if (pkt_len != sizeof(*payload)) {
|
if (pkt_len != EFX_LOOPBACK_PAYLOAD_LEN) {
|
||||||
netif_err(efx, drv, efx->net_dev,
|
netif_err(efx, drv, efx->net_dev,
|
||||||
"saw incorrect RX packet length %d (wanted %d) in "
|
"saw incorrect RX packet length %d (wanted %d) in "
|
||||||
"%s loopback test\n", pkt_len, (int)sizeof(*payload),
|
"%s loopback test\n", pkt_len,
|
||||||
LOOPBACK_MODE(efx));
|
(int)EFX_LOOPBACK_PAYLOAD_LEN, LOOPBACK_MODE(efx));
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check that IP header matches */
|
/* Check that IP header matches */
|
||||||
if (memcmp(&received->ip, &payload->ip, sizeof(payload->ip)) != 0) {
|
if (memcmp(&received.ip, &payload->ip, sizeof(payload->ip)) != 0) {
|
||||||
netif_err(efx, drv, efx->net_dev,
|
netif_err(efx, drv, efx->net_dev,
|
||||||
"saw corrupted IP header in %s loopback test\n",
|
"saw corrupted IP header in %s loopback test\n",
|
||||||
LOOPBACK_MODE(efx));
|
LOOPBACK_MODE(efx));
|
||||||
@ -332,7 +337,7 @@ void efx_siena_loopback_rx_packet(struct efx_nic *efx,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Check that msg and padding matches */
|
/* Check that msg and padding matches */
|
||||||
if (memcmp(&received->msg, &payload->msg, sizeof(received->msg)) != 0) {
|
if (memcmp(&received.msg, &payload->msg, sizeof(received.msg)) != 0) {
|
||||||
netif_err(efx, drv, efx->net_dev,
|
netif_err(efx, drv, efx->net_dev,
|
||||||
"saw corrupted RX packet in %s loopback test\n",
|
"saw corrupted RX packet in %s loopback test\n",
|
||||||
LOOPBACK_MODE(efx));
|
LOOPBACK_MODE(efx));
|
||||||
@ -340,10 +345,10 @@ void efx_siena_loopback_rx_packet(struct efx_nic *efx,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Check that iteration matches */
|
/* Check that iteration matches */
|
||||||
if (received->iteration != payload->iteration) {
|
if (received.iteration != payload->iteration) {
|
||||||
netif_err(efx, drv, efx->net_dev,
|
netif_err(efx, drv, efx->net_dev,
|
||||||
"saw RX packet from iteration %d (wanted %d) in "
|
"saw RX packet from iteration %d (wanted %d) in "
|
||||||
"%s loopback test\n", ntohs(received->iteration),
|
"%s loopback test\n", ntohs(received.iteration),
|
||||||
ntohs(payload->iteration), LOOPBACK_MODE(efx));
|
ntohs(payload->iteration), LOOPBACK_MODE(efx));
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
@ -363,7 +368,8 @@ void efx_siena_loopback_rx_packet(struct efx_nic *efx,
|
|||||||
buf_ptr, pkt_len, 0);
|
buf_ptr, pkt_len, 0);
|
||||||
netif_err(efx, drv, efx->net_dev, "expected packet:\n");
|
netif_err(efx, drv, efx->net_dev, "expected packet:\n");
|
||||||
print_hex_dump(KERN_ERR, "", DUMP_PREFIX_OFFSET, 0x10, 1,
|
print_hex_dump(KERN_ERR, "", DUMP_PREFIX_OFFSET, 0x10, 1,
|
||||||
&state->payload, sizeof(state->payload), 0);
|
&state->payload.header, EFX_LOOPBACK_PAYLOAD_LEN,
|
||||||
|
0);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
atomic_inc(&state->rx_bad);
|
atomic_inc(&state->rx_bad);
|
||||||
@ -385,14 +391,15 @@ static void efx_iterate_state(struct efx_nic *efx)
|
|||||||
payload->ip.daddr = htonl(INADDR_LOOPBACK);
|
payload->ip.daddr = htonl(INADDR_LOOPBACK);
|
||||||
payload->ip.ihl = 5;
|
payload->ip.ihl = 5;
|
||||||
payload->ip.check = (__force __sum16) htons(0xdead);
|
payload->ip.check = (__force __sum16) htons(0xdead);
|
||||||
payload->ip.tot_len = htons(sizeof(*payload) - sizeof(struct ethhdr));
|
payload->ip.tot_len = htons(sizeof(*payload) -
|
||||||
|
offsetof(struct efx_loopback_payload, ip));
|
||||||
payload->ip.version = IPVERSION;
|
payload->ip.version = IPVERSION;
|
||||||
payload->ip.protocol = IPPROTO_UDP;
|
payload->ip.protocol = IPPROTO_UDP;
|
||||||
|
|
||||||
/* Initialise udp header */
|
/* Initialise udp header */
|
||||||
payload->udp.source = 0;
|
payload->udp.source = 0;
|
||||||
payload->udp.len = htons(sizeof(*payload) - sizeof(struct ethhdr) -
|
payload->udp.len = htons(sizeof(*payload) -
|
||||||
sizeof(struct iphdr));
|
offsetof(struct efx_loopback_payload, udp));
|
||||||
payload->udp.check = 0; /* checksum ignored */
|
payload->udp.check = 0; /* checksum ignored */
|
||||||
|
|
||||||
/* Fill out payload */
|
/* Fill out payload */
|
||||||
@ -418,7 +425,7 @@ static int efx_begin_loopback(struct efx_tx_queue *tx_queue)
|
|||||||
for (i = 0; i < state->packet_count; i++) {
|
for (i = 0; i < state->packet_count; i++) {
|
||||||
/* Allocate an skb, holding an extra reference for
|
/* Allocate an skb, holding an extra reference for
|
||||||
* transmit completion counting */
|
* transmit completion counting */
|
||||||
skb = alloc_skb(sizeof(state->payload), GFP_KERNEL);
|
skb = alloc_skb(EFX_LOOPBACK_PAYLOAD_LEN, GFP_KERNEL);
|
||||||
if (!skb)
|
if (!skb)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
state->skbs[i] = skb;
|
state->skbs[i] = skb;
|
||||||
@ -429,6 +436,8 @@ static int efx_begin_loopback(struct efx_tx_queue *tx_queue)
|
|||||||
payload = skb_put(skb, sizeof(state->payload));
|
payload = skb_put(skb, sizeof(state->payload));
|
||||||
memcpy(payload, &state->payload, sizeof(state->payload));
|
memcpy(payload, &state->payload, sizeof(state->payload));
|
||||||
payload->ip.saddr = htonl(INADDR_LOOPBACK | (i << 2));
|
payload->ip.saddr = htonl(INADDR_LOOPBACK | (i << 2));
|
||||||
|
/* Strip off the leading padding */
|
||||||
|
skb_pull(skb, offsetof(struct efx_loopback_payload, header));
|
||||||
|
|
||||||
/* Ensure everything we've written is visible to the
|
/* Ensure everything we've written is visible to the
|
||||||
* interrupt handler. */
|
* interrupt handler. */
|
||||||
|
Loading…
Reference in New Issue
Block a user