From: Bobby Eshleman <[email protected]>

Add a -n flag to ncdevmem that skips hardware configuration (header
split, RSS, flow steering). This is needed when ncdevmem is run inside a
netkit namespace where hardware configuration is managed externally by
the test harness.

When -n is set, ncdevmem skips configure_headersplit(), configure_rss(),
and configure_flow_steering(). The calling environment is expected to
perform this setup prior to invoking ncdevmem.

This is used in subsequent patches of this series that bring up netkit
devmem TX testing. ncdevmem will only have access to the netkit inside
the namespace, and not the physical device. Therefore, in those tests,
the test harness itself does the physical device setup.

Signed-off-by: Bobby Eshleman <[email protected]>
---
 tools/testing/selftests/drivers/net/hw/ncdevmem.c | 58 +++++++++++++----------
 1 file changed, 34 insertions(+), 24 deletions(-)

diff --git a/tools/testing/selftests/drivers/net/hw/ncdevmem.c 
b/tools/testing/selftests/drivers/net/hw/ncdevmem.c
index e098d6534c3c..d96e8a3b5a65 100644
--- a/tools/testing/selftests/drivers/net/hw/ncdevmem.c
+++ b/tools/testing/selftests/drivers/net/hw/ncdevmem.c
@@ -93,6 +93,7 @@ static char *port;
 static size_t do_validation;
 static int start_queue = -1;
 static int num_queues = -1;
+static int skip_config;
 static char *ifname;
 static unsigned int ifindex;
 static unsigned int dmabuf_id;
@@ -828,7 +829,7 @@ static struct netdev_queue_id *create_queues(void)
 
 static int do_server(struct memory_buffer *mem)
 {
-       struct ethtool_rings_get_rsp *ring_config;
+       struct ethtool_rings_get_rsp *ring_config = NULL;
        char ctrl_data[sizeof(int) * 20000];
        size_t non_page_aligned_frags = 0;
        struct sockaddr_in6 client_addr;
@@ -851,27 +852,29 @@ static int do_server(struct memory_buffer *mem)
                return -1;
        }
 
-       ring_config = get_ring_config();
-       if (!ring_config) {
-               pr_err("Failed to get current ring configuration");
-               return -1;
-       }
+       if (!skip_config) {
+               ring_config = get_ring_config();
+               if (!ring_config) {
+                       pr_err("Failed to get current ring configuration");
+                       return -1;
+               }
 
-       if (configure_headersplit(ring_config, 1)) {
-               pr_err("Failed to enable TCP header split");
-               goto err_free_ring_config;
-       }
+               if (configure_headersplit(ring_config, 1)) {
+                       pr_err("Failed to enable TCP header split");
+                       goto err_free_ring_config;
+               }
 
-       /* Configure RSS to divert all traffic from our devmem queues */
-       if (configure_rss()) {
-               pr_err("Failed to configure rss");
-               goto err_reset_headersplit;
-       }
+               /* Configure RSS to divert all traffic from our devmem queues */
+               if (configure_rss()) {
+                       pr_err("Failed to configure rss");
+                       goto err_reset_headersplit;
+               }
 
-       /* Flow steer our devmem flows to start_queue */
-       if (configure_flow_steering(&server_sin)) {
-               pr_err("Failed to configure flow steering");
-               goto err_reset_rss;
+               /* Flow steer our devmem flows to start_queue */
+               if (configure_flow_steering(&server_sin)) {
+                       pr_err("Failed to configure flow steering");
+                       goto err_reset_rss;
+               }
        }
 
        if (bind_rx_queue(ifindex, mem->fd, create_queues(), num_queues, &ys)) {
@@ -1052,13 +1055,17 @@ static int do_server(struct memory_buffer *mem)
 err_unbind:
        ynl_sock_destroy(ys);
 err_reset_flow_steering:
-       reset_flow_steering();
+       if (!skip_config)
+               reset_flow_steering();
 err_reset_rss:
-       reset_rss();
+       if (!skip_config)
+               reset_rss();
 err_reset_headersplit:
-       restore_ring_config(ring_config);
+       if (!skip_config)
+               restore_ring_config(ring_config);
 err_free_ring_config:
-       ethtool_rings_get_rsp_free(ring_config);
+       if (!skip_config)
+               ethtool_rings_get_rsp_free(ring_config);
        return err;
 }
 
@@ -1404,7 +1411,7 @@ int main(int argc, char *argv[])
        int is_server = 0, opt;
        int ret, err = 1;
 
-       while ((opt = getopt(argc, argv, "Lls:c:p:v:q:t:f:z:")) != -1) {
+       while ((opt = getopt(argc, argv, "Lls:c:p:v:q:t:f:z:n")) != -1) {
                switch (opt) {
                case 'L':
                        fail_on_linear = true;
@@ -1436,6 +1443,9 @@ int main(int argc, char *argv[])
                case 'z':
                        max_chunk = atoi(optarg);
                        break;
+               case 'n':
+                       skip_config = 1;
+                       break;
                case '?':
                        fprintf(stderr, "unknown option: %c\n", optopt);
                        break;

-- 
2.52.0


Reply via email to