sfc: Reduce the size of struct efx_tx_buffer
[deliverable/linux.git] / drivers / net / sfc / selftest.c
index 3b2de9fe7f27ee6607a3cdc17cf8a443285287c5..53fa4edf486c6ba0770096dcc52aebc2b6021898 100644 (file)
@@ -63,6 +63,10 @@ struct efx_selftest_state {
        int flush;
        int packet_count;
        struct sk_buff **skbs;
+
+       /* Checksums are being offloaded */
+       int offload_csum;
+
        atomic_t rx_good;
        atomic_t rx_bad;
        struct efx_loopback_payload payload;
@@ -292,8 +296,9 @@ void efx_loopback_rx_packet(struct efx_nic *efx,
        
        received = (struct efx_loopback_payload *) buf_ptr;
        received->ip.saddr = payload->ip.saddr;
-       received->ip.check = payload->ip.check;
-       
+       if (state->offload_csum)
+               received->ip.check = payload->ip.check;
+
        /* Check that header exists */
        if (pkt_len < sizeof(received->header)) {
                EFX_ERR(efx, "saw runt RX packet (length %d) in %s loopback "
@@ -395,7 +400,7 @@ static void efx_iterate_state(struct efx_nic *efx)
        smp_wmb();
 }
 
-static int efx_tx_loopback(struct efx_tx_queue *tx_queue)
+static int efx_begin_loopback(struct efx_tx_queue *tx_queue)
 {
        struct efx_nic *efx = tx_queue->efx;
        struct efx_selftest_state *state = efx->loopback_selftest;
@@ -444,8 +449,22 @@ static int efx_tx_loopback(struct efx_tx_queue *tx_queue)
        return 0;
 }
 
-static int efx_rx_loopback(struct efx_tx_queue *tx_queue,
-                          struct efx_loopback_self_tests *lb_tests)
+static int efx_poll_loopback(struct efx_nic *efx)
+{
+       struct efx_selftest_state *state = efx->loopback_selftest;
+       struct efx_channel *channel;
+
+       /* NAPI polling is not enabled, so process channels
+        * synchronously */
+       efx_for_each_channel_with_interrupt(channel, efx) {
+               if (channel->work_pending)
+                       efx_process_channel_now(channel);
+       }
+       return atomic_read(&state->rx_good) == state->packet_count;
+}
+
+static int efx_end_loopback(struct efx_tx_queue *tx_queue,
+                           struct efx_loopback_self_tests *lb_tests)
 {
        struct efx_nic *efx = tx_queue->efx;
        struct efx_selftest_state *state = efx->loopback_selftest;
@@ -508,8 +527,7 @@ efx_test_loopback(struct efx_tx_queue *tx_queue,
 {
        struct efx_nic *efx = tx_queue->efx;
        struct efx_selftest_state *state = efx->loopback_selftest;
-       struct efx_channel *channel;
-       int i, rc = 0;
+       int i, begin_rc, end_rc;
 
        for (i = 0; i < loopback_test_level; i++) {
                /* Determine how many packets to send */
@@ -526,23 +544,24 @@ efx_test_loopback(struct efx_tx_queue *tx_queue,
                        state->packet_count);
 
                efx_iterate_state(efx);
-               rc = efx_tx_loopback(tx_queue);
-               
-               /* NAPI polling is not enabled, so process channels synchronously */
-               schedule_timeout_uninterruptible(HZ / 50);
-               efx_for_each_channel_with_interrupt(channel, efx) {
-                       if (channel->work_pending)
-                               efx_process_channel_now(channel);
+               begin_rc = efx_begin_loopback(tx_queue);
+
+               /* This will normally complete very quickly, but be
+                * prepared to wait up to 100 ms. */
+               msleep(1);
+               if (!efx_poll_loopback(efx)) {
+                       msleep(100);
+                       efx_poll_loopback(efx);
                }
 
-               rc |= efx_rx_loopback(tx_queue, lb_tests);
+               end_rc = efx_end_loopback(tx_queue, lb_tests);
                kfree(state->skbs);
 
-               if (rc) {
+               if (begin_rc || end_rc) {
                        /* Wait a while to ensure there are no packets
                         * floating around after a failure. */
                        schedule_timeout_uninterruptible(HZ / 10);
-                       return rc;
+                       return begin_rc ? begin_rc : end_rc;
                }
        }
 
@@ -550,7 +569,7 @@ efx_test_loopback(struct efx_tx_queue *tx_queue,
                "of %d packets\n", tx_queue->queue, LOOPBACK_MODE(efx),
                state->packet_count);
 
-       return rc;
+       return 0;
 }
 
 static int efx_test_loopbacks(struct efx_nic *efx,
@@ -561,8 +580,8 @@ static int efx_test_loopbacks(struct efx_nic *efx,
        struct ethtool_cmd ecmd, ecmd_loopback;
        struct efx_tx_queue *tx_queue;
        enum efx_loopback_mode old_mode, mode;
-       int count, rc = 0, link_up;
-       
+       int count, rc, link_up;
+
        rc = efx_ethtool_get_settings(efx->net_dev, &ecmd);
        if (rc) {
                EFX_ERR(efx, "could not get GMII settings\n");
@@ -634,8 +653,10 @@ static int efx_test_loopbacks(struct efx_nic *efx,
 
                /* Test every TX queue */
                efx_for_each_tx_queue(tx_queue, efx) {
-                       rc |= efx_test_loopback(tx_queue,
-                                               &tests->loopback[mode]);
+                       state->offload_csum = (tx_queue->queue ==
+                                              EFX_TX_QUEUE_OFFLOAD_CSUM);
+                       rc = efx_test_loopback(tx_queue,
+                                              &tests->loopback[mode]);
                        if (rc)
                                goto out;
                }
@@ -661,22 +682,20 @@ static int efx_test_loopbacks(struct efx_nic *efx,
 int efx_online_test(struct efx_nic *efx, struct efx_self_tests *tests)
 {
        struct efx_channel *channel;
-       int rc = 0;
+       int rc;
 
-       EFX_LOG(efx, "performing online self-tests\n");
-
-       rc |= efx_test_interrupts(efx, tests);
+       rc = efx_test_interrupts(efx, tests);
+       if (rc)
+               return rc;
        efx_for_each_channel(channel, efx) {
                if (channel->has_interrupt)
-                       rc |= efx_test_eventq_irq(channel, tests);
+                       rc = efx_test_eventq_irq(channel, tests);
                else
-                       rc |= efx_test_eventq(channel, tests);
+                       rc = efx_test_eventq(channel, tests);
+               if (rc)
+                       return rc;
        }
-       rc |= efx_test_phy(efx, tests);
-
-       if (rc)
-               EFX_ERR(efx, "failed online self-tests\n");
-
+       rc = efx_test_phy(efx, tests);
        return rc;
 }
 
@@ -686,16 +705,12 @@ int efx_offline_test(struct efx_nic *efx,
                     struct efx_self_tests *tests, unsigned int loopback_modes)
 {
        struct efx_selftest_state *state;
-       int rc = 0;
-
-       EFX_LOG(efx, "performing offline self-tests\n");
+       int rc;
 
        /* Create a selftest_state structure to hold state for the test */
        state = kzalloc(sizeof(*state), GFP_KERNEL);
-       if (state == NULL) {
-               rc = -ENOMEM;
-               goto out;
-       }
+       if (state == NULL)
+               return -ENOMEM;
 
        /* Set the port loopback_selftest member. From this point on
         * all received packets will be dropped. Mark the state as
@@ -710,10 +725,6 @@ int efx_offline_test(struct efx_nic *efx,
        wmb();
        kfree(state);
 
- out:
-       if (rc)
-               EFX_ERR(efx, "failed offline self-tests\n");
-
        return rc;
 }
 
This page took 0.033422 seconds and 5 git commands to generate.