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