5182b2fd1481d984c239f556791a28bc744c0d5f
[dpdk.git] / lib / librte_eal / linuxapp / kni / kni_net.c
1 /*-
2  * GPL LICENSE SUMMARY
3  *
4  *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
5  *
6  *   This program is free software; you can redistribute it and/or modify
7  *   it under the terms of version 2 of the GNU General Public License as
8  *   published by the Free Software Foundation.
9  *
10  *   This program is distributed in the hope that it will be useful, but
11  *   WITHOUT ANY WARRANTY; without even the implied warranty of
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  *   General Public License for more details.
14  *
15  *   You should have received a copy of the GNU General Public License
16  *   along with this program; if not, write to the Free Software
17  *   Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18  *   The full GNU General Public License is included in this distribution
19  *   in the file called LICENSE.GPL.
20  *
21  *   Contact Information:
22  *   Intel Corporation
23  */
24
25 /*
26  * This code is inspired from the book "Linux Device Drivers" by
27  * Alessandro Rubini and Jonathan Corbet, published by O'Reilly & Associates
28  */
29
30 #include <linux/device.h>
31 #include <linux/module.h>
32 #include <linux/version.h>
33 #include <linux/netdevice.h>
34 #include <linux/etherdevice.h> /* eth_type_trans */
35 #include <linux/skbuff.h>
36 #include <linux/kthread.h>
37 #include <linux/delay.h>
38
39 #include <exec-env/rte_kni_common.h>
40 #include <kni_fifo.h>
41
42 #include "compat.h"
43 #include "kni_dev.h"
44
45 #define WD_TIMEOUT 5 /*jiffies */
46
47 #define KNI_WAIT_RESPONSE_TIMEOUT 300 /* 3 seconds */
48
49 /* typedef for rx function */
50 typedef void (*kni_net_rx_t)(struct kni_dev *kni);
51
52 static int kni_net_tx(struct sk_buff *skb, struct net_device *dev);
53 static void kni_net_rx_normal(struct kni_dev *kni);
54 static void kni_net_rx_lo_fifo(struct kni_dev *kni);
55 static void kni_net_rx_lo_fifo_skb(struct kni_dev *kni);
56 static int kni_net_process_request(struct kni_dev *kni,
57                         struct rte_kni_request *req);
58
59 /* kni rx function pointer, with default to normal rx */
60 static kni_net_rx_t kni_net_rx_func = kni_net_rx_normal;
61
62 /* physical address to kernel virtual address */
63 static void *
64 pa2kva(void *pa)
65 {
66         return phys_to_virt((unsigned long)pa);
67 }
68
69 /* physical address to virtual address */
70 static void *
71 pa2va(void *pa, struct rte_kni_mbuf *m)
72 {
73         void *va;
74
75         va = (void *)((unsigned long)pa +
76                         (unsigned long)m->buf_addr -
77                         (unsigned long)m->buf_physaddr);
78         return va;
79 }
80
81 /* mbuf data kernel virtual address from mbuf kernel virtual address */
82 static void *
83 kva2data_kva(struct rte_kni_mbuf *m)
84 {
85         return phys_to_virt(m->buf_physaddr + m->data_off);
86 }
87
88 /* virtual address to physical address */
89 static void *
90 va2pa(void *va, struct rte_kni_mbuf *m)
91 {
92         void *pa;
93
94         pa = (void *)((unsigned long)va -
95                         ((unsigned long)m->buf_addr -
96                          (unsigned long)m->buf_physaddr));
97         return pa;
98 }
99
100 /*
101  * Open and close
102  */
103 static int
104 kni_net_open(struct net_device *dev)
105 {
106         int ret;
107         struct rte_kni_request req;
108         struct kni_dev *kni = netdev_priv(dev);
109
110         netif_start_queue(dev);
111
112         memset(&req, 0, sizeof(req));
113         req.req_id = RTE_KNI_REQ_CFG_NETWORK_IF;
114
115         /* Setting if_up to non-zero means up */
116         req.if_up = 1;
117         ret = kni_net_process_request(kni, &req);
118
119         return (ret == 0) ? req.result : ret;
120 }
121
122 static int
123 kni_net_release(struct net_device *dev)
124 {
125         int ret;
126         struct rte_kni_request req;
127         struct kni_dev *kni = netdev_priv(dev);
128
129         netif_stop_queue(dev); /* can't transmit any more */
130
131         memset(&req, 0, sizeof(req));
132         req.req_id = RTE_KNI_REQ_CFG_NETWORK_IF;
133
134         /* Setting if_up to 0 means down */
135         req.if_up = 0;
136         ret = kni_net_process_request(kni, &req);
137
138         return (ret == 0) ? req.result : ret;
139 }
140
141 /*
142  * Configuration changes (passed on by ifconfig)
143  */
144 static int
145 kni_net_config(struct net_device *dev, struct ifmap *map)
146 {
147         if (dev->flags & IFF_UP) /* can't act on a running interface */
148                 return -EBUSY;
149
150         /* ignore other fields */
151         return 0;
152 }
153
154 /*
155  * RX: normal working mode
156  */
157 static void
158 kni_net_rx_normal(struct kni_dev *kni)
159 {
160         unsigned int ret;
161         uint32_t len;
162         unsigned int i, num_rx, num_fq;
163         struct rte_kni_mbuf *kva;
164         void *data_kva;
165         struct sk_buff *skb;
166         struct net_device *dev = kni->net_dev;
167
168         /* Get the number of free entries in free_q */
169         num_fq = kni_fifo_free_count(kni->free_q);
170         if (num_fq == 0) {
171                 /* No room on the free_q, bail out */
172                 return;
173         }
174
175         /* Calculate the number of entries to dequeue from rx_q */
176         num_rx = min_t(unsigned int, num_fq, MBUF_BURST_SZ);
177
178         /* Burst dequeue from rx_q */
179         num_rx = kni_fifo_get(kni->rx_q, kni->pa, num_rx);
180         if (num_rx == 0)
181                 return;
182
183         /* Transfer received packets to netif */
184         for (i = 0; i < num_rx; i++) {
185                 kva = pa2kva(kni->pa[i]);
186                 len = kva->pkt_len;
187                 data_kva = kva2data_kva(kva);
188                 kni->va[i] = pa2va(kni->pa[i], kva);
189
190                 skb = dev_alloc_skb(len + 2);
191                 if (!skb) {
192                         /* Update statistics */
193                         kni->stats.rx_dropped++;
194                         continue;
195                 }
196
197                 /* Align IP on 16B boundary */
198                 skb_reserve(skb, 2);
199
200                 if (kva->nb_segs == 1) {
201                         memcpy(skb_put(skb, len), data_kva, len);
202                 } else {
203                         int nb_segs;
204                         int kva_nb_segs = kva->nb_segs;
205
206                         for (nb_segs = 0; nb_segs < kva_nb_segs; nb_segs++) {
207                                 memcpy(skb_put(skb, kva->data_len),
208                                         data_kva, kva->data_len);
209
210                                 if (!kva->next)
211                                         break;
212
213                                 kva = pa2kva(va2pa(kva->next, kva));
214                                 data_kva = kva2data_kva(kva);
215                         }
216                 }
217
218                 skb->dev = dev;
219                 skb->protocol = eth_type_trans(skb, dev);
220                 skb->ip_summed = CHECKSUM_UNNECESSARY;
221
222                 /* Call netif interface */
223                 netif_rx_ni(skb);
224
225                 /* Update statistics */
226                 kni->stats.rx_bytes += len;
227                 kni->stats.rx_packets++;
228         }
229
230         /* Burst enqueue mbufs into free_q */
231         ret = kni_fifo_put(kni->free_q, kni->va, num_rx);
232         if (ret != num_rx)
233                 /* Failing should not happen */
234                 pr_err("Fail to enqueue entries into free_q\n");
235 }
236
237 /*
238  * RX: loopback with enqueue/dequeue fifos.
239  */
240 static void
241 kni_net_rx_lo_fifo(struct kni_dev *kni)
242 {
243         unsigned int ret;
244         uint32_t len;
245         unsigned int i, num, num_rq, num_tq, num_aq, num_fq;
246         struct rte_kni_mbuf *kva;
247         void *data_kva;
248         struct rte_kni_mbuf *alloc_kva;
249         void *alloc_data_kva;
250
251         /* Get the number of entries in rx_q */
252         num_rq = kni_fifo_count(kni->rx_q);
253
254         /* Get the number of free entrie in tx_q */
255         num_tq = kni_fifo_free_count(kni->tx_q);
256
257         /* Get the number of entries in alloc_q */
258         num_aq = kni_fifo_count(kni->alloc_q);
259
260         /* Get the number of free entries in free_q */
261         num_fq = kni_fifo_free_count(kni->free_q);
262
263         /* Calculate the number of entries to be dequeued from rx_q */
264         num = min(num_rq, num_tq);
265         num = min(num, num_aq);
266         num = min(num, num_fq);
267         num = min_t(unsigned int, num, MBUF_BURST_SZ);
268
269         /* Return if no entry to dequeue from rx_q */
270         if (num == 0)
271                 return;
272
273         /* Burst dequeue from rx_q */
274         ret = kni_fifo_get(kni->rx_q, kni->pa, num);
275         if (ret == 0)
276                 return; /* Failing should not happen */
277
278         /* Dequeue entries from alloc_q */
279         ret = kni_fifo_get(kni->alloc_q, kni->alloc_pa, num);
280         if (ret) {
281                 num = ret;
282                 /* Copy mbufs */
283                 for (i = 0; i < num; i++) {
284                         kva = pa2kva(kni->pa[i]);
285                         len = kva->pkt_len;
286                         data_kva = kva2data_kva(kva);
287                         kni->va[i] = pa2va(kni->pa[i], kva);
288
289                         alloc_kva = pa2kva(kni->alloc_pa[i]);
290                         alloc_data_kva = kva2data_kva(alloc_kva);
291                         kni->alloc_va[i] = pa2va(kni->alloc_pa[i], alloc_kva);
292
293                         memcpy(alloc_data_kva, data_kva, len);
294                         alloc_kva->pkt_len = len;
295                         alloc_kva->data_len = len;
296
297                         kni->stats.tx_bytes += len;
298                         kni->stats.rx_bytes += len;
299                 }
300
301                 /* Burst enqueue mbufs into tx_q */
302                 ret = kni_fifo_put(kni->tx_q, kni->alloc_va, num);
303                 if (ret != num)
304                         /* Failing should not happen */
305                         pr_err("Fail to enqueue mbufs into tx_q\n");
306         }
307
308         /* Burst enqueue mbufs into free_q */
309         ret = kni_fifo_put(kni->free_q, kni->va, num);
310         if (ret != num)
311                 /* Failing should not happen */
312                 pr_err("Fail to enqueue mbufs into free_q\n");
313
314         /**
315          * Update statistic, and enqueue/dequeue failure is impossible,
316          * as all queues are checked at first.
317          */
318         kni->stats.tx_packets += num;
319         kni->stats.rx_packets += num;
320 }
321
322 /*
323  * RX: loopback with enqueue/dequeue fifos and sk buffer copies.
324  */
325 static void
326 kni_net_rx_lo_fifo_skb(struct kni_dev *kni)
327 {
328         unsigned int ret;
329         uint32_t len;
330         unsigned int i, num_rq, num_fq, num;
331         struct rte_kni_mbuf *kva;
332         void *data_kva;
333         struct sk_buff *skb;
334         struct net_device *dev = kni->net_dev;
335
336         /* Get the number of entries in rx_q */
337         num_rq = kni_fifo_count(kni->rx_q);
338
339         /* Get the number of free entries in free_q */
340         num_fq = kni_fifo_free_count(kni->free_q);
341
342         /* Calculate the number of entries to dequeue from rx_q */
343         num = min(num_rq, num_fq);
344         num = min_t(unsigned int, num, MBUF_BURST_SZ);
345
346         /* Return if no entry to dequeue from rx_q */
347         if (num == 0)
348                 return;
349
350         /* Burst dequeue mbufs from rx_q */
351         ret = kni_fifo_get(kni->rx_q, kni->pa, num);
352         if (ret == 0)
353                 return;
354
355         /* Copy mbufs to sk buffer and then call tx interface */
356         for (i = 0; i < num; i++) {
357                 kva = pa2kva(kni->pa[i]);
358                 len = kva->pkt_len;
359                 data_kva = kva2data_kva(kva);
360                 kni->va[i] = pa2va(kni->pa[i], kva);
361
362                 skb = dev_alloc_skb(len + 2);
363                 if (skb) {
364                         /* Align IP on 16B boundary */
365                         skb_reserve(skb, 2);
366                         memcpy(skb_put(skb, len), data_kva, len);
367                         skb->dev = dev;
368                         skb->ip_summed = CHECKSUM_UNNECESSARY;
369                         dev_kfree_skb(skb);
370                 }
371
372                 /* Simulate real usage, allocate/copy skb twice */
373                 skb = dev_alloc_skb(len + 2);
374                 if (skb == NULL) {
375                         kni->stats.rx_dropped++;
376                         continue;
377                 }
378
379                 /* Align IP on 16B boundary */
380                 skb_reserve(skb, 2);
381
382                 if (kva->nb_segs == 1) {
383                         memcpy(skb_put(skb, len), data_kva, len);
384                 } else {
385                         int nb_segs;
386                         int kva_nb_segs = kva->nb_segs;
387
388                         for (nb_segs = 0; nb_segs < kva_nb_segs; nb_segs++) {
389                                 memcpy(skb_put(skb, kva->data_len),
390                                         data_kva, kva->data_len);
391
392                                 if (!kva->next)
393                                         break;
394
395                                 kva = pa2kva(va2pa(kva->next, kva));
396                                 data_kva = kva2data_kva(kva);
397                         }
398                 }
399
400                 skb->dev = dev;
401                 skb->ip_summed = CHECKSUM_UNNECESSARY;
402
403                 kni->stats.rx_bytes += len;
404                 kni->stats.rx_packets++;
405
406                 /* call tx interface */
407                 kni_net_tx(skb, dev);
408         }
409
410         /* enqueue all the mbufs from rx_q into free_q */
411         ret = kni_fifo_put(kni->free_q, kni->va, num);
412         if (ret != num)
413                 /* Failing should not happen */
414                 pr_err("Fail to enqueue mbufs into free_q\n");
415 }
416
417 /* rx interface */
418 void
419 kni_net_rx(struct kni_dev *kni)
420 {
421         /**
422          * It doesn't need to check if it is NULL pointer,
423          * as it has a default value
424          */
425         (*kni_net_rx_func)(kni);
426 }
427
428 /*
429  * Transmit a packet (called by the kernel)
430  */
431 #ifdef RTE_KNI_VHOST
432 static int
433 kni_net_tx(struct sk_buff *skb, struct net_device *dev)
434 {
435         struct kni_dev *kni = netdev_priv(dev);
436
437         dev_kfree_skb(skb);
438         kni->stats.tx_dropped++;
439
440         return NETDEV_TX_OK;
441 }
442 #else
443 static int
444 kni_net_tx(struct sk_buff *skb, struct net_device *dev)
445 {
446         int len = 0;
447         unsigned int ret;
448         struct kni_dev *kni = netdev_priv(dev);
449         struct rte_kni_mbuf *pkt_kva = NULL;
450         void *pkt_pa = NULL;
451         void *pkt_va = NULL;
452
453         /* save the timestamp */
454 #ifdef HAVE_TRANS_START_HELPER
455         netif_trans_update(dev);
456 #else
457         dev->trans_start = jiffies;
458 #endif
459
460         /* Check if the length of skb is less than mbuf size */
461         if (skb->len > kni->mbuf_size)
462                 goto drop;
463
464         /**
465          * Check if it has at least one free entry in tx_q and
466          * one entry in alloc_q.
467          */
468         if (kni_fifo_free_count(kni->tx_q) == 0 ||
469                         kni_fifo_count(kni->alloc_q) == 0) {
470                 /**
471                  * If no free entry in tx_q or no entry in alloc_q,
472                  * drops skb and goes out.
473                  */
474                 goto drop;
475         }
476
477         /* dequeue a mbuf from alloc_q */
478         ret = kni_fifo_get(kni->alloc_q, &pkt_pa, 1);
479         if (likely(ret == 1)) {
480                 void *data_kva;
481
482                 pkt_kva = pa2kva(pkt_pa);
483                 data_kva = kva2data_kva(pkt_kva);
484                 pkt_va = pa2va(pkt_pa, pkt_kva);
485
486                 len = skb->len;
487                 memcpy(data_kva, skb->data, len);
488                 if (unlikely(len < ETH_ZLEN)) {
489                         memset(data_kva + len, 0, ETH_ZLEN - len);
490                         len = ETH_ZLEN;
491                 }
492                 pkt_kva->pkt_len = len;
493                 pkt_kva->data_len = len;
494
495                 /* enqueue mbuf into tx_q */
496                 ret = kni_fifo_put(kni->tx_q, &pkt_va, 1);
497                 if (unlikely(ret != 1)) {
498                         /* Failing should not happen */
499                         pr_err("Fail to enqueue mbuf into tx_q\n");
500                         goto drop;
501                 }
502         } else {
503                 /* Failing should not happen */
504                 pr_err("Fail to dequeue mbuf from alloc_q\n");
505                 goto drop;
506         }
507
508         /* Free skb and update statistics */
509         dev_kfree_skb(skb);
510         kni->stats.tx_bytes += len;
511         kni->stats.tx_packets++;
512
513         return NETDEV_TX_OK;
514
515 drop:
516         /* Free skb and update statistics */
517         dev_kfree_skb(skb);
518         kni->stats.tx_dropped++;
519
520         return NETDEV_TX_OK;
521 }
522 #endif
523
524 /*
525  * Deal with a transmit timeout.
526  */
527 static void
528 kni_net_tx_timeout(struct net_device *dev)
529 {
530         struct kni_dev *kni = netdev_priv(dev);
531
532         KNI_DBG("Transmit timeout at %ld, latency %ld\n", jiffies,
533                         jiffies - dev_trans_start(dev));
534
535         kni->stats.tx_errors++;
536         netif_wake_queue(dev);
537 }
538
539 /*
540  * Ioctl commands
541  */
542 static int
543 kni_net_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
544 {
545         KNI_DBG("kni_net_ioctl %d\n",
546                 ((struct kni_dev *)netdev_priv(dev))->group_id);
547
548         return 0;
549 }
550
551 static void
552 kni_net_set_rx_mode(struct net_device *dev)
553 {
554 }
555
556 static int
557 kni_net_change_mtu(struct net_device *dev, int new_mtu)
558 {
559         int ret;
560         struct rte_kni_request req;
561         struct kni_dev *kni = netdev_priv(dev);
562
563         KNI_DBG("kni_net_change_mtu new mtu %d to be set\n", new_mtu);
564
565         memset(&req, 0, sizeof(req));
566         req.req_id = RTE_KNI_REQ_CHANGE_MTU;
567         req.new_mtu = new_mtu;
568         ret = kni_net_process_request(kni, &req);
569         if (ret == 0 && req.result == 0)
570                 dev->mtu = new_mtu;
571
572         return (ret == 0) ? req.result : ret;
573 }
574
575 /*
576  * Checks if the user space application provided the resp message
577  */
578 void
579 kni_net_poll_resp(struct kni_dev *kni)
580 {
581         if (kni_fifo_count(kni->resp_q))
582                 wake_up_interruptible(&kni->wq);
583 }
584
585 /*
586  * It can be called to process the request.
587  */
588 static int
589 kni_net_process_request(struct kni_dev *kni, struct rte_kni_request *req)
590 {
591         int ret = -1;
592         void *resp_va;
593         unsigned int num;
594         int ret_val;
595
596         if (!kni || !req) {
597                 pr_err("No kni instance or request\n");
598                 return -EINVAL;
599         }
600
601         mutex_lock(&kni->sync_lock);
602
603         /* Construct data */
604         memcpy(kni->sync_kva, req, sizeof(struct rte_kni_request));
605         num = kni_fifo_put(kni->req_q, &kni->sync_va, 1);
606         if (num < 1) {
607                 pr_err("Cannot send to req_q\n");
608                 ret = -EBUSY;
609                 goto fail;
610         }
611
612         ret_val = wait_event_interruptible_timeout(kni->wq,
613                         kni_fifo_count(kni->resp_q), 3 * HZ);
614         if (signal_pending(current) || ret_val <= 0) {
615                 ret = -ETIME;
616                 goto fail;
617         }
618         num = kni_fifo_get(kni->resp_q, (void **)&resp_va, 1);
619         if (num != 1 || resp_va != kni->sync_va) {
620                 /* This should never happen */
621                 pr_err("No data in resp_q\n");
622                 ret = -ENODATA;
623                 goto fail;
624         }
625
626         memcpy(req, kni->sync_kva, sizeof(struct rte_kni_request));
627         ret = 0;
628
629 fail:
630         mutex_unlock(&kni->sync_lock);
631         return ret;
632 }
633
634 /*
635  * Return statistics to the caller
636  */
637 static struct net_device_stats *
638 kni_net_stats(struct net_device *dev)
639 {
640         struct kni_dev *kni = netdev_priv(dev);
641
642         return &kni->stats;
643 }
644
645 /*
646  *  Fill the eth header
647  */
648 static int
649 kni_net_header(struct sk_buff *skb, struct net_device *dev,
650                 unsigned short type, const void *daddr,
651                 const void *saddr, unsigned int len)
652 {
653         struct ethhdr *eth = (struct ethhdr *) skb_push(skb, ETH_HLEN);
654
655         memcpy(eth->h_source, saddr ? saddr : dev->dev_addr, dev->addr_len);
656         memcpy(eth->h_dest,   daddr ? daddr : dev->dev_addr, dev->addr_len);
657         eth->h_proto = htons(type);
658
659         return dev->hard_header_len;
660 }
661
662 /*
663  * Re-fill the eth header
664  */
665 #ifdef HAVE_REBUILD_HEADER
666 static int
667 kni_net_rebuild_header(struct sk_buff *skb)
668 {
669         struct net_device *dev = skb->dev;
670         struct ethhdr *eth = (struct ethhdr *) skb->data;
671
672         memcpy(eth->h_source, dev->dev_addr, dev->addr_len);
673         memcpy(eth->h_dest, dev->dev_addr, dev->addr_len);
674
675         return 0;
676 }
677 #endif /* < 4.1.0  */
678
679 /**
680  * kni_net_set_mac - Change the Ethernet Address of the KNI NIC
681  * @netdev: network interface device structure
682  * @p: pointer to an address structure
683  *
684  * Returns 0 on success, negative on failure
685  **/
686 static int
687 kni_net_set_mac(struct net_device *netdev, void *p)
688 {
689         struct sockaddr *addr = p;
690
691         if (!is_valid_ether_addr((unsigned char *)(addr->sa_data)))
692                 return -EADDRNOTAVAIL;
693         memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
694         return 0;
695 }
696
697 #ifdef HAVE_CHANGE_CARRIER_CB
698 static int
699 kni_net_change_carrier(struct net_device *dev, bool new_carrier)
700 {
701         if (new_carrier)
702                 netif_carrier_on(dev);
703         else
704                 netif_carrier_off(dev);
705         return 0;
706 }
707 #endif
708
709 static const struct header_ops kni_net_header_ops = {
710         .create  = kni_net_header,
711 #ifdef HAVE_REBUILD_HEADER
712         .rebuild = kni_net_rebuild_header,
713 #endif /* < 4.1.0  */
714         .cache   = NULL,  /* disable caching */
715 };
716
717 static const struct net_device_ops kni_net_netdev_ops = {
718         .ndo_open = kni_net_open,
719         .ndo_stop = kni_net_release,
720         .ndo_set_config = kni_net_config,
721         .ndo_start_xmit = kni_net_tx,
722         .ndo_change_mtu = kni_net_change_mtu,
723         .ndo_do_ioctl = kni_net_ioctl,
724         .ndo_set_rx_mode = kni_net_set_rx_mode,
725         .ndo_get_stats = kni_net_stats,
726         .ndo_tx_timeout = kni_net_tx_timeout,
727         .ndo_set_mac_address = kni_net_set_mac,
728 #ifdef HAVE_CHANGE_CARRIER_CB
729         .ndo_change_carrier = kni_net_change_carrier,
730 #endif
731 };
732
733 void
734 kni_net_init(struct net_device *dev)
735 {
736         struct kni_dev *kni = netdev_priv(dev);
737
738         KNI_DBG("kni_net_init\n");
739
740         init_waitqueue_head(&kni->wq);
741         mutex_init(&kni->sync_lock);
742
743         ether_setup(dev); /* assign some of the fields */
744         dev->netdev_ops      = &kni_net_netdev_ops;
745         dev->header_ops      = &kni_net_header_ops;
746         dev->watchdog_timeo = WD_TIMEOUT;
747 }
748
749 void
750 kni_net_config_lo_mode(char *lo_str)
751 {
752         if (!lo_str) {
753                 pr_debug("loopback disabled");
754                 return;
755         }
756
757         if (!strcmp(lo_str, "lo_mode_none"))
758                 pr_debug("loopback disabled");
759         else if (!strcmp(lo_str, "lo_mode_fifo")) {
760                 pr_debug("loopback mode=lo_mode_fifo enabled");
761                 kni_net_rx_func = kni_net_rx_lo_fifo;
762         } else if (!strcmp(lo_str, "lo_mode_fifo_skb")) {
763                 pr_debug("loopback mode=lo_mode_fifo_skb enabled");
764                 kni_net_rx_func = kni_net_rx_lo_fifo_skb;
765         } else
766                 pr_debug("Incognizant parameter, loopback disabled");
767 }