summaryrefslogtreecommitdiff
path: root/drivers/net/ethernet/sfc/falcon/selftest.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/ethernet/sfc/falcon/selftest.c')
-rw-r--r--drivers/net/ethernet/sfc/falcon/selftest.c65
1 files changed, 37 insertions, 28 deletions
diff --git a/drivers/net/ethernet/sfc/falcon/selftest.c b/drivers/net/ethernet/sfc/falcon/selftest.c
index 55c0fbbc4fb8..c3dc88e6c26c 100644
--- a/drivers/net/ethernet/sfc/falcon/selftest.c
+++ b/drivers/net/ethernet/sfc/falcon/selftest.c
@@ -1,11 +1,8 @@
+// SPDX-License-Identifier: GPL-2.0-only
/****************************************************************************
* Driver for Solarflare network controllers and boards
* Copyright 2005-2006 Fen Systems Ltd.
* Copyright 2006-2012 Solarflare Communications Inc.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 as published
- * by the Free Software Foundation, incorporated herein by reference.
*/
#include <linux/netdevice.h>
@@ -42,12 +39,17 @@
* Falcon only performs RSS on TCP/UDP packets.
*/
struct ef4_loopback_payload {
- struct ethhdr header;
- struct iphdr ip;
- struct udphdr udp;
- __be16 iteration;
- char msg[64];
-} __packed;
+ char pad[2]; /* Ensures ip is 4-byte aligned */
+ struct_group_attr(packet, __packed,
+ struct ethhdr header;
+ struct iphdr ip;
+ struct udphdr udp;
+ __be16 iteration;
+ char msg[64];
+ );
+} __packed __aligned(4);
+#define EF4_LOOPBACK_PAYLOAD_LEN \
+ sizeof_field(struct ef4_loopback_payload, packet)
/* Loopback test source MAC address */
static const u8 payload_source[ETH_ALEN] __aligned(2) = {
@@ -68,7 +70,7 @@ static const char *const ef4_interrupt_mode_names[] = {
STRING_TABLE_LOOKUP(efx->interrupt_mode, ef4_interrupt_mode)
/**
- * ef4_loopback_state - persistent state during a loopback selftest
+ * struct ef4_loopback_state - persistent state during a loopback selftest
* @flush: Drop all packets in ef4_loopback_rx_packet
* @packet_count: Number of packets being used in this test
* @skbs: An array of skbs transmitted
@@ -287,7 +289,7 @@ void ef4_loopback_rx_packet(struct ef4_nic *efx,
const char *buf_ptr, int pkt_len)
{
struct ef4_loopback_state *state = efx->loopback_selftest;
- struct ef4_loopback_payload *received;
+ struct ef4_loopback_payload received;
struct ef4_loopback_payload *payload;
BUG_ON(!buf_ptr);
@@ -298,13 +300,14 @@ void ef4_loopback_rx_packet(struct ef4_nic *efx,
payload = &state->payload;
- received = (struct ef4_loopback_payload *) buf_ptr;
- received->ip.saddr = payload->ip.saddr;
+ memcpy(&received.packet, buf_ptr,
+ min_t(int, pkt_len, EF4_LOOPBACK_PAYLOAD_LEN));
+ received.ip.saddr = payload->ip.saddr;
if (state->offload_csum)
- received->ip.check = payload->ip.check;
+ received.ip.check = payload->ip.check;
/* Check that header exists */
- if (pkt_len < sizeof(received->header)) {
+ if (pkt_len < sizeof(received.header)) {
netif_err(efx, drv, efx->net_dev,
"saw runt RX packet (length %d) in %s loopback "
"test\n", pkt_len, LOOPBACK_MODE(efx));
@@ -312,7 +315,7 @@ void ef4_loopback_rx_packet(struct ef4_nic *efx,
}
/* 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,
"saw non-loopback RX packet in %s loopback test\n",
LOOPBACK_MODE(efx));
@@ -320,16 +323,16 @@ void ef4_loopback_rx_packet(struct ef4_nic *efx,
}
/* Check packet length */
- if (pkt_len != sizeof(*payload)) {
+ if (pkt_len != EF4_LOOPBACK_PAYLOAD_LEN) {
netif_err(efx, drv, efx->net_dev,
"saw incorrect RX packet length %d (wanted %d) in "
- "%s loopback test\n", pkt_len, (int)sizeof(*payload),
- LOOPBACK_MODE(efx));
+ "%s loopback test\n", pkt_len,
+ (int)EF4_LOOPBACK_PAYLOAD_LEN, LOOPBACK_MODE(efx));
goto err;
}
/* 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,
"saw corrupted IP header in %s loopback test\n",
LOOPBACK_MODE(efx));
@@ -337,7 +340,7 @@ void ef4_loopback_rx_packet(struct ef4_nic *efx,
}
/* 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,
"saw corrupted RX packet in %s loopback test\n",
LOOPBACK_MODE(efx));
@@ -345,10 +348,10 @@ void ef4_loopback_rx_packet(struct ef4_nic *efx,
}
/* Check that iteration matches */
- if (received->iteration != payload->iteration) {
+ if (received.iteration != payload->iteration) {
netif_err(efx, drv, efx->net_dev,
"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));
goto err;
}
@@ -368,7 +371,8 @@ void ef4_loopback_rx_packet(struct ef4_nic *efx,
buf_ptr, pkt_len, 0);
netif_err(efx, drv, efx->net_dev, "expected packet:\n");
print_hex_dump(KERN_ERR, "", DUMP_PREFIX_OFFSET, 0x10, 1,
- &state->payload, sizeof(state->payload), 0);
+ &state->payload.packet, EF4_LOOPBACK_PAYLOAD_LEN,
+ 0);
}
#endif
atomic_inc(&state->rx_bad);
@@ -390,14 +394,15 @@ static void ef4_iterate_state(struct ef4_nic *efx)
payload->ip.daddr = htonl(INADDR_LOOPBACK);
payload->ip.ihl = 5;
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 ef4_loopback_payload, ip));
payload->ip.version = IPVERSION;
payload->ip.protocol = IPPROTO_UDP;
/* Initialise udp header */
payload->udp.source = 0;
- payload->udp.len = htons(sizeof(*payload) - sizeof(struct ethhdr) -
- sizeof(struct iphdr));
+ payload->udp.len = htons(sizeof(*payload) -
+ offsetof(struct ef4_loopback_payload, udp));
payload->udp.check = 0; /* checksum ignored */
/* Fill out payload */
@@ -434,6 +439,10 @@ static int ef4_begin_loopback(struct ef4_tx_queue *tx_queue)
payload = skb_put(skb, sizeof(state->payload));
memcpy(payload, &state->payload, sizeof(state->payload));
payload->ip.saddr = htonl(INADDR_LOOPBACK | (i << 2));
+ /* Strip off the leading padding */
+ skb_pull(skb, offsetof(struct ef4_loopback_payload, header));
+ /* Strip off the trailing padding */
+ skb_trim(skb, EF4_LOOPBACK_PAYLOAD_LEN);
/* Ensure everything we've written is visible to the
* interrupt handler. */