sfc: Reduce the size of struct efx_tx_buffer
[deliverable/linux.git] / drivers / net / sfc / selftest.c
index cbda15946e8f57585aa8cda81a39ed5e106c3b50..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;
@@ -290,10 +294,11 @@ void efx_loopback_rx_packet(struct efx_nic *efx,
 
        payload = &state->payload;
        
-       received = (struct efx_loopback_payload *)(char *) buf_ptr;
+       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;
@@ -424,10 +429,10 @@ static int efx_tx_loopback(struct efx_tx_queue *tx_queue)
                 * interrupt handler. */
                smp_wmb();
 
-               if (NET_DEV_REGISTERED(efx))
+               if (efx_dev_registered(efx))
                        netif_tx_lock_bh(efx->net_dev);
                rc = efx_xmit(efx, tx_queue, skb);
-               if (NET_DEV_REGISTERED(efx))
+               if (efx_dev_registered(efx))
                        netif_tx_unlock_bh(efx->net_dev);
 
                if (rc != NETDEV_TX_OK) {
@@ -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;
@@ -453,7 +472,7 @@ static int efx_rx_loopback(struct efx_tx_queue *tx_queue,
        int tx_done = 0, rx_good, rx_bad;
        int i, rc = 0;
 
-       if (NET_DEV_REGISTERED(efx))
+       if (efx_dev_registered(efx))
                netif_tx_lock_bh(efx->net_dev);
 
        /* Count the number of tx completions, and decrement the refcnt. Any
@@ -465,7 +484,7 @@ static int efx_rx_loopback(struct efx_tx_queue *tx_queue,
                dev_kfree_skb_any(skb);
        }
 
-       if (NET_DEV_REGISTERED(efx))
+       if (efx_dev_registered(efx))
                netif_tx_unlock_bh(efx->net_dev);
 
        /* Check TX completion and received packet counts */
@@ -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 */
@@ -517,6 +535,8 @@ efx_test_loopback(struct efx_tx_queue *tx_queue,
                state->packet_count = min(1 << (i << 2), state->packet_count);
                state->skbs = kzalloc(sizeof(state->skbs[0]) *
                                      state->packet_count, GFP_KERNEL);
+               if (!state->skbs)
+                       return -ENOMEM;
                state->flush = 0;
 
                EFX_LOG(efx, "TX queue %d testing %s loopback with %d "
@@ -524,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;
                }
        }
 
@@ -548,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,
@@ -559,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");
@@ -632,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;
                }
@@ -659,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;
 }
 
@@ -684,23 +705,19 @@ 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
         * "flushing" so all inflight packets are dropped */
        BUG_ON(efx->loopback_selftest);
        state->flush = 1;
-       efx->loopback_selftest = (void *)state;
+       efx->loopback_selftest = state;
 
        rc = efx_test_loopbacks(efx, tests, loopback_modes);
 
@@ -708,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.027633 seconds and 5 git commands to generate.