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