net/ixgbe: move PCI device IDs from EAL
[dpdk.git] / lib / librte_eal / linuxapp / kni / kni_misc.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 #include <linux/version.h>
26 #include <linux/module.h>
27 #include <linux/miscdevice.h>
28 #include <linux/netdevice.h>
29 #include <linux/etherdevice.h>
30 #include <linux/pci.h>
31 #include <linux/kthread.h>
32 #include <linux/rwsem.h>
33 #include <linux/nsproxy.h>
34 #include <net/net_namespace.h>
35 #include <net/netns/generic.h>
36
37 #include <exec-env/rte_kni_common.h>
38
39 #include "compat.h"
40 #include "kni_dev.h"
41
42 MODULE_LICENSE("Dual BSD/GPL");
43 MODULE_AUTHOR("Intel Corporation");
44 MODULE_DESCRIPTION("Kernel Module for managing kni devices");
45
46 #define KNI_RX_LOOP_NUM 1000
47
48 #define KNI_MAX_DEVICES 32
49
50 extern void kni_net_rx(struct kni_dev *kni);
51 extern void kni_net_init(struct net_device *dev);
52 extern void kni_net_config_lo_mode(char *lo_str);
53 extern void kni_net_poll_resp(struct kni_dev *kni);
54 extern void kni_set_ethtool_ops(struct net_device *netdev);
55
56 extern int ixgbe_kni_probe(struct pci_dev *pdev, struct net_device **lad_dev);
57 extern void ixgbe_kni_remove(struct pci_dev *pdev);
58 extern struct pci_device_id ixgbe_pci_tbl[];
59 extern int igb_kni_probe(struct pci_dev *pdev, struct net_device **lad_dev);
60 extern void igb_kni_remove(struct pci_dev *pdev);
61
62 static int kni_open(struct inode *inode, struct file *file);
63 static int kni_release(struct inode *inode, struct file *file);
64 static int kni_ioctl(struct inode *inode, unsigned int ioctl_num,
65                                         unsigned long ioctl_param);
66 static int kni_compat_ioctl(struct inode *inode, unsigned int ioctl_num,
67                                                 unsigned long ioctl_param);
68 static int kni_dev_remove(struct kni_dev *dev);
69
70 static int __init kni_parse_kthread_mode(void);
71
72 /* KNI processing for single kernel thread mode */
73 static int kni_thread_single(void *unused);
74 /* KNI processing for multiple kernel thread mode */
75 static int kni_thread_multiple(void *param);
76
77 static struct file_operations kni_fops = {
78         .owner = THIS_MODULE,
79         .open = kni_open,
80         .release = kni_release,
81         .unlocked_ioctl = (void *)kni_ioctl,
82         .compat_ioctl = (void *)kni_compat_ioctl,
83 };
84
85 static struct miscdevice kni_misc = {
86         .minor = MISC_DYNAMIC_MINOR,
87         .name = KNI_DEVICE,
88         .fops = &kni_fops,
89 };
90
91 /* loopback mode */
92 static char *lo_mode = NULL;
93
94 /* Kernel thread mode */
95 static char *kthread_mode = NULL;
96 static unsigned multiple_kthread_on = 0;
97
98 #define KNI_DEV_IN_USE_BIT_NUM 0 /* Bit number for device in use */
99
100 static int kni_net_id;
101
102 struct kni_net {
103         unsigned long device_in_use; /* device in use flag */
104         struct task_struct *kni_kthread;
105         struct rw_semaphore kni_list_lock;
106         struct list_head kni_list_head;
107 };
108
109 static int __net_init kni_init_net(struct net *net)
110 {
111 #ifdef HAVE_SIMPLIFIED_PERNET_OPERATIONS
112         struct kni_net *knet = net_generic(net, kni_net_id);
113 #else
114         struct kni_net *knet;
115         int ret;
116
117         knet = kmalloc(sizeof(struct kni_net), GFP_KERNEL);
118         if (!knet) {
119                 ret = -ENOMEM;
120                 return ret;
121         }
122 #endif
123
124         /* Clear the bit of device in use */
125         clear_bit(KNI_DEV_IN_USE_BIT_NUM, &knet->device_in_use);
126
127         init_rwsem(&knet->kni_list_lock);
128         INIT_LIST_HEAD(&knet->kni_list_head);
129
130 #ifdef HAVE_SIMPLIFIED_PERNET_OPERATIONS
131         return 0;
132 #else
133         ret = net_assign_generic(net, kni_net_id, knet);
134         if (ret < 0)
135                 kfree(knet);
136
137         return ret;
138 #endif
139 }
140
141 static void __net_exit kni_exit_net(struct net *net)
142 {
143 #ifndef HAVE_SIMPLIFIED_PERNET_OPERATIONS
144         struct kni_net *knet = net_generic(net, kni_net_id);
145
146         kfree(knet);
147 #endif
148 }
149
150 static struct pernet_operations kni_net_ops = {
151         .init = kni_init_net,
152         .exit = kni_exit_net,
153 #ifdef HAVE_SIMPLIFIED_PERNET_OPERATIONS
154         .id   = &kni_net_id,
155         .size = sizeof(struct kni_net),
156 #endif
157 };
158
159 static int __init
160 kni_init(void)
161 {
162         int rc;
163
164         KNI_PRINT("######## DPDK kni module loading ########\n");
165
166         if (kni_parse_kthread_mode() < 0) {
167                 KNI_ERR("Invalid parameter for kthread_mode\n");
168                 return -EINVAL;
169         }
170
171 #ifdef HAVE_SIMPLIFIED_PERNET_OPERATIONS
172         rc = register_pernet_subsys(&kni_net_ops);
173 #else
174         rc = register_pernet_gen_subsys(&kni_net_id, &kni_net_ops);
175 #endif
176         if (rc)
177                 return -EPERM;
178
179         rc = misc_register(&kni_misc);
180         if (rc != 0) {
181                 KNI_ERR("Misc registration failed\n");
182                 goto out;
183         }
184
185         /* Configure the lo mode according to the input parameter */
186         kni_net_config_lo_mode(lo_mode);
187
188         KNI_PRINT("######## DPDK kni module loaded  ########\n");
189
190         return 0;
191
192 out:
193 #ifdef HAVE_SIMPLIFIED_PERNET_OPERATIONS
194         unregister_pernet_subsys(&kni_net_ops);
195 #else
196         register_pernet_gen_subsys(&kni_net_id, &kni_net_ops);
197 #endif
198         return rc;
199 }
200
201 static void __exit
202 kni_exit(void)
203 {
204         misc_deregister(&kni_misc);
205 #ifdef HAVE_SIMPLIFIED_PERNET_OPERATIONS
206         unregister_pernet_subsys(&kni_net_ops);
207 #else
208         register_pernet_gen_subsys(&kni_net_id, &kni_net_ops);
209 #endif
210         KNI_PRINT("####### DPDK kni module unloaded  #######\n");
211 }
212
213 static int __init
214 kni_parse_kthread_mode(void)
215 {
216         if (!kthread_mode)
217                 return 0;
218
219         if (strcmp(kthread_mode, "single") == 0)
220                 return 0;
221         else if (strcmp(kthread_mode, "multiple") == 0)
222                 multiple_kthread_on = 1;
223         else
224                 return -1;
225
226         return 0;
227 }
228
229 static int
230 kni_open(struct inode *inode, struct file *file)
231 {
232         struct net *net = current->nsproxy->net_ns;
233         struct kni_net *knet = net_generic(net, kni_net_id);
234
235         /* kni device can be opened by one user only per netns */
236         if (test_and_set_bit(KNI_DEV_IN_USE_BIT_NUM, &knet->device_in_use))
237                 return -EBUSY;
238
239         /* Create kernel thread for single mode */
240         if (multiple_kthread_on == 0) {
241                 KNI_PRINT("Single kernel thread for all KNI devices\n");
242                 /* Create kernel thread for RX */
243                 knet->kni_kthread = kthread_run(kni_thread_single, (void *)knet,
244                                                 "kni_single");
245                 if (IS_ERR(knet->kni_kthread)) {
246                         KNI_ERR("Unable to create kernel threaed\n");
247                         return PTR_ERR(knet->kni_kthread);
248                 }
249         } else
250                 KNI_PRINT("Multiple kernel thread mode enabled\n");
251
252         file->private_data = get_net(net);
253         KNI_PRINT("/dev/kni opened\n");
254
255         return 0;
256 }
257
258 static int
259 kni_release(struct inode *inode, struct file *file)
260 {
261         struct net *net = file->private_data;
262         struct kni_net *knet = net_generic(net, kni_net_id);
263         struct kni_dev *dev, *n;
264
265         /* Stop kernel thread for single mode */
266         if (multiple_kthread_on == 0) {
267                 /* Stop kernel thread */
268                 kthread_stop(knet->kni_kthread);
269                 knet->kni_kthread = NULL;
270         }
271
272         down_write(&knet->kni_list_lock);
273         list_for_each_entry_safe(dev, n, &knet->kni_list_head, list) {
274                 /* Stop kernel thread for multiple mode */
275                 if (multiple_kthread_on && dev->pthread != NULL) {
276                         kthread_stop(dev->pthread);
277                         dev->pthread = NULL;
278                 }
279
280 #ifdef RTE_KNI_VHOST
281                 kni_vhost_backend_release(dev);
282 #endif
283                 kni_dev_remove(dev);
284                 list_del(&dev->list);
285         }
286         up_write(&knet->kni_list_lock);
287
288         /* Clear the bit of device in use */
289         clear_bit(KNI_DEV_IN_USE_BIT_NUM, &knet->device_in_use);
290
291         put_net(net);
292         KNI_PRINT("/dev/kni closed\n");
293
294         return 0;
295 }
296
297 static int
298 kni_thread_single(void *data)
299 {
300         struct kni_net *knet = data;
301         int j;
302         struct kni_dev *dev;
303
304         while (!kthread_should_stop()) {
305                 down_read(&knet->kni_list_lock);
306                 for (j = 0; j < KNI_RX_LOOP_NUM; j++) {
307                         list_for_each_entry(dev, &knet->kni_list_head, list) {
308 #ifdef RTE_KNI_VHOST
309                                 kni_chk_vhost_rx(dev);
310 #else
311                                 kni_net_rx(dev);
312 #endif
313                                 kni_net_poll_resp(dev);
314                         }
315                 }
316                 up_read(&knet->kni_list_lock);
317 #ifdef RTE_KNI_PREEMPT_DEFAULT
318                 /* reschedule out for a while */
319                 schedule_timeout_interruptible(usecs_to_jiffies( \
320                                 KNI_KTHREAD_RESCHEDULE_INTERVAL));
321 #endif
322         }
323
324         return 0;
325 }
326
327 static int
328 kni_thread_multiple(void *param)
329 {
330         int j;
331         struct kni_dev *dev = (struct kni_dev *)param;
332
333         while (!kthread_should_stop()) {
334                 for (j = 0; j < KNI_RX_LOOP_NUM; j++) {
335 #ifdef RTE_KNI_VHOST
336                         kni_chk_vhost_rx(dev);
337 #else
338                         kni_net_rx(dev);
339 #endif
340                         kni_net_poll_resp(dev);
341                 }
342 #ifdef RTE_KNI_PREEMPT_DEFAULT
343                 schedule_timeout_interruptible(usecs_to_jiffies( \
344                                 KNI_KTHREAD_RESCHEDULE_INTERVAL));
345 #endif
346         }
347
348         return 0;
349 }
350
351 static int
352 kni_dev_remove(struct kni_dev *dev)
353 {
354         if (!dev)
355                 return -ENODEV;
356
357         if (pci_match_id(ixgbe_pci_tbl, dev->pci_dev))
358                 ixgbe_kni_remove(dev->pci_dev);
359
360         switch (dev->device_id) {
361         #define RTE_PCI_DEV_ID_DECL_IGB(vend, dev) case (dev):
362         #include <rte_pci_dev_ids.h>
363                 igb_kni_remove(dev->pci_dev);
364                 break;
365         default:
366                 break;
367         }
368
369         if (dev->net_dev) {
370                 unregister_netdev(dev->net_dev);
371                 free_netdev(dev->net_dev);
372         }
373
374         return 0;
375 }
376
377 static int
378 kni_check_param(struct kni_dev *kni, struct rte_kni_device_info *dev)
379 {
380         if (!kni || !dev)
381                 return -1;
382
383         /* Check if network name has been used */
384         if (!strncmp(kni->name, dev->name, RTE_KNI_NAMESIZE)) {
385                 KNI_ERR("KNI name %s duplicated\n", dev->name);
386                 return -1;
387         }
388
389         return 0;
390 }
391
392 static int
393 kni_ioctl_create(struct net *net,
394                 unsigned int ioctl_num, unsigned long ioctl_param)
395 {
396         struct kni_net *knet = net_generic(net, kni_net_id);
397         int ret;
398         struct rte_kni_device_info dev_info;
399         struct pci_dev *pci = NULL;
400         struct pci_dev *found_pci = NULL;
401         struct net_device *net_dev = NULL;
402         struct net_device *lad_dev = NULL;
403         struct kni_dev *kni, *dev, *n;
404
405         printk(KERN_INFO "KNI: Creating kni...\n");
406         /* Check the buffer size, to avoid warning */
407         if (_IOC_SIZE(ioctl_num) > sizeof(dev_info))
408                 return -EINVAL;
409
410         /* Copy kni info from user space */
411         ret = copy_from_user(&dev_info, (void *)ioctl_param, sizeof(dev_info));
412         if (ret) {
413                 KNI_ERR("copy_from_user in kni_ioctl_create");
414                 return -EIO;
415         }
416
417         /**
418          * Check if the cpu core id is valid for binding,
419          * for multiple kernel thread mode.
420          */
421         if (multiple_kthread_on && dev_info.force_bind &&
422                                 !cpu_online(dev_info.core_id)) {
423                 KNI_ERR("cpu %u is not online\n", dev_info.core_id);
424                 return -EINVAL;
425         }
426
427         /* Check if it has been created */
428         down_read(&knet->kni_list_lock);
429         list_for_each_entry_safe(dev, n, &knet->kni_list_head, list) {
430                 if (kni_check_param(dev, &dev_info) < 0) {
431                         up_read(&knet->kni_list_lock);
432                         return -EINVAL;
433                 }
434         }
435         up_read(&knet->kni_list_lock);
436
437         net_dev = alloc_netdev(sizeof(struct kni_dev), dev_info.name,
438 #ifdef NET_NAME_UNKNOWN
439                                                         NET_NAME_UNKNOWN,
440 #endif
441                                                         kni_net_init);
442         if (net_dev == NULL) {
443                 KNI_ERR("error allocating device \"%s\"\n", dev_info.name);
444                 return -EBUSY;
445         }
446
447         dev_net_set(net_dev, net);
448
449         kni = netdev_priv(net_dev);
450
451         kni->net_dev = net_dev;
452         kni->group_id = dev_info.group_id;
453         kni->core_id = dev_info.core_id;
454         strncpy(kni->name, dev_info.name, RTE_KNI_NAMESIZE);
455
456         /* Translate user space info into kernel space info */
457         kni->tx_q = phys_to_virt(dev_info.tx_phys);
458         kni->rx_q = phys_to_virt(dev_info.rx_phys);
459         kni->alloc_q = phys_to_virt(dev_info.alloc_phys);
460         kni->free_q = phys_to_virt(dev_info.free_phys);
461
462         kni->req_q = phys_to_virt(dev_info.req_phys);
463         kni->resp_q = phys_to_virt(dev_info.resp_phys);
464         kni->sync_va = dev_info.sync_va;
465         kni->sync_kva = phys_to_virt(dev_info.sync_phys);
466
467         kni->mbuf_kva = phys_to_virt(dev_info.mbuf_phys);
468         kni->mbuf_va = dev_info.mbuf_va;
469
470 #ifdef RTE_KNI_VHOST
471         kni->vhost_queue = NULL;
472         kni->vq_status = BE_STOP;
473 #endif
474         kni->mbuf_size = dev_info.mbuf_size;
475
476         KNI_PRINT("tx_phys:      0x%016llx, tx_q addr:      0x%p\n",
477                 (unsigned long long) dev_info.tx_phys, kni->tx_q);
478         KNI_PRINT("rx_phys:      0x%016llx, rx_q addr:      0x%p\n",
479                 (unsigned long long) dev_info.rx_phys, kni->rx_q);
480         KNI_PRINT("alloc_phys:   0x%016llx, alloc_q addr:   0x%p\n",
481                 (unsigned long long) dev_info.alloc_phys, kni->alloc_q);
482         KNI_PRINT("free_phys:    0x%016llx, free_q addr:    0x%p\n",
483                 (unsigned long long) dev_info.free_phys, kni->free_q);
484         KNI_PRINT("req_phys:     0x%016llx, req_q addr:     0x%p\n",
485                 (unsigned long long) dev_info.req_phys, kni->req_q);
486         KNI_PRINT("resp_phys:    0x%016llx, resp_q addr:    0x%p\n",
487                 (unsigned long long) dev_info.resp_phys, kni->resp_q);
488         KNI_PRINT("mbuf_phys:    0x%016llx, mbuf_kva:       0x%p\n",
489                 (unsigned long long) dev_info.mbuf_phys, kni->mbuf_kva);
490         KNI_PRINT("mbuf_va:      0x%p\n", dev_info.mbuf_va);
491         KNI_PRINT("mbuf_size:    %u\n", kni->mbuf_size);
492
493         KNI_DBG("PCI: %02x:%02x.%02x %04x:%04x\n",
494                                         dev_info.bus,
495                                         dev_info.devid,
496                                         dev_info.function,
497                                         dev_info.vendor_id,
498                                         dev_info.device_id);
499
500         pci = pci_get_device(dev_info.vendor_id, dev_info.device_id, NULL);
501
502         /* Support Ethtool */
503         while (pci) {
504                 KNI_PRINT("pci_bus: %02x:%02x:%02x \n",
505                                         pci->bus->number,
506                                         PCI_SLOT(pci->devfn),
507                                         PCI_FUNC(pci->devfn));
508
509                 if ((pci->bus->number == dev_info.bus) &&
510                         (PCI_SLOT(pci->devfn) == dev_info.devid) &&
511                         (PCI_FUNC(pci->devfn) == dev_info.function)) {
512                         found_pci = pci;
513
514                         if (pci_match_id(ixgbe_pci_tbl, found_pci))
515                                 ret = ixgbe_kni_probe(found_pci, &lad_dev);
516
517                         switch (dev_info.device_id) {
518                         #define RTE_PCI_DEV_ID_DECL_IGB(vend, dev) case (dev):
519                         #include <rte_pci_dev_ids.h>
520                                 ret = igb_kni_probe(found_pci, &lad_dev);
521                                 break;
522                         default:
523                                 ret = -1;
524                                 break;
525                         }
526
527                         KNI_DBG("PCI found: pci=0x%p, lad_dev=0x%p\n",
528                                                         pci, lad_dev);
529                         if (ret == 0) {
530                                 kni->lad_dev = lad_dev;
531                                 kni_set_ethtool_ops(kni->net_dev);
532                         } else {
533                                 KNI_ERR("Device not supported by ethtool");
534                                 kni->lad_dev = NULL;
535                         }
536
537                         kni->pci_dev = found_pci;
538                         kni->device_id = dev_info.device_id;
539                         break;
540                 }
541                 pci = pci_get_device(dev_info.vendor_id,
542                                 dev_info.device_id, pci);
543         }
544         if (pci)
545                 pci_dev_put(pci);
546
547         if (kni->lad_dev)
548                 memcpy(net_dev->dev_addr, kni->lad_dev->dev_addr, ETH_ALEN);
549         else
550                 /*
551                  * Generate random mac address. eth_random_addr() is the newer
552                  * version of generating mac address in linux kernel.
553                  */
554                 random_ether_addr(net_dev->dev_addr);
555
556         ret = register_netdev(net_dev);
557         if (ret) {
558                 KNI_ERR("error %i registering device \"%s\"\n",
559                                         ret, dev_info.name);
560                 kni_dev_remove(kni);
561                 return -ENODEV;
562         }
563
564 #ifdef RTE_KNI_VHOST
565         kni_vhost_init(kni);
566 #endif
567
568         /**
569          * Create a new kernel thread for multiple mode, set its core affinity,
570          * and finally wake it up.
571          */
572         if (multiple_kthread_on) {
573                 kni->pthread = kthread_create(kni_thread_multiple,
574                                               (void *)kni,
575                                               "kni_%s", kni->name);
576                 if (IS_ERR(kni->pthread)) {
577                         kni_dev_remove(kni);
578                         return -ECANCELED;
579                 }
580                 if (dev_info.force_bind)
581                         kthread_bind(kni->pthread, kni->core_id);
582                 wake_up_process(kni->pthread);
583         }
584
585         down_write(&knet->kni_list_lock);
586         list_add(&kni->list, &knet->kni_list_head);
587         up_write(&knet->kni_list_lock);
588
589         return 0;
590 }
591
592 static int
593 kni_ioctl_release(struct net *net,
594                 unsigned int ioctl_num, unsigned long ioctl_param)
595 {
596         struct kni_net *knet = net_generic(net, kni_net_id);
597         int ret = -EINVAL;
598         struct kni_dev *dev, *n;
599         struct rte_kni_device_info dev_info;
600
601         if (_IOC_SIZE(ioctl_num) > sizeof(dev_info))
602                         return -EINVAL;
603
604         ret = copy_from_user(&dev_info, (void *)ioctl_param, sizeof(dev_info));
605         if (ret) {
606                 KNI_ERR("copy_from_user in kni_ioctl_release");
607                 return -EIO;
608         }
609
610         /* Release the network device according to its name */
611         if (strlen(dev_info.name) == 0)
612                 return ret;
613
614         down_write(&knet->kni_list_lock);
615         list_for_each_entry_safe(dev, n, &knet->kni_list_head, list) {
616                 if (strncmp(dev->name, dev_info.name, RTE_KNI_NAMESIZE) != 0)
617                         continue;
618
619                 if (multiple_kthread_on && dev->pthread != NULL) {
620                         kthread_stop(dev->pthread);
621                         dev->pthread = NULL;
622                 }
623
624 #ifdef RTE_KNI_VHOST
625                 kni_vhost_backend_release(dev);
626 #endif
627                 kni_dev_remove(dev);
628                 list_del(&dev->list);
629                 ret = 0;
630                 break;
631         }
632         up_write(&knet->kni_list_lock);
633         printk(KERN_INFO "KNI: %s release kni named %s\n",
634                 (ret == 0 ? "Successfully" : "Unsuccessfully"), dev_info.name);
635
636         return ret;
637 }
638
639 static int
640 kni_ioctl(struct inode *inode,
641         unsigned int ioctl_num,
642         unsigned long ioctl_param)
643 {
644         int ret = -EINVAL;
645         struct net *net = current->nsproxy->net_ns;
646
647         KNI_DBG("IOCTL num=0x%0x param=0x%0lx\n", ioctl_num, ioctl_param);
648
649         /*
650          * Switch according to the ioctl called
651          */
652         switch (_IOC_NR(ioctl_num)) {
653         case _IOC_NR(RTE_KNI_IOCTL_TEST):
654                 /* For test only, not used */
655                 break;
656         case _IOC_NR(RTE_KNI_IOCTL_CREATE):
657                 ret = kni_ioctl_create(net, ioctl_num, ioctl_param);
658                 break;
659         case _IOC_NR(RTE_KNI_IOCTL_RELEASE):
660                 ret = kni_ioctl_release(net, ioctl_num, ioctl_param);
661                 break;
662         default:
663                 KNI_DBG("IOCTL default\n");
664                 break;
665         }
666
667         return ret;
668 }
669
670 static int
671 kni_compat_ioctl(struct inode *inode,
672                 unsigned int ioctl_num,
673                 unsigned long ioctl_param)
674 {
675         /* 32 bits app on 64 bits OS to be supported later */
676         KNI_PRINT("Not implemented.\n");
677
678         return -EINVAL;
679 }
680
681 module_init(kni_init);
682 module_exit(kni_exit);
683
684 module_param(lo_mode, charp, S_IRUGO | S_IWUSR);
685 MODULE_PARM_DESC(lo_mode,
686 "KNI loopback mode (default=lo_mode_none):\n"
687 "    lo_mode_none        Kernel loopback disabled\n"
688 "    lo_mode_fifo        Enable kernel loopback with fifo\n"
689 "    lo_mode_fifo_skb    Enable kernel loopback with fifo and skb buffer\n"
690 "\n"
691 );
692
693 module_param(kthread_mode, charp, S_IRUGO);
694 MODULE_PARM_DESC(kthread_mode,
695 "Kernel thread mode (default=single):\n"
696 "    single    Single kernel thread mode enabled.\n"
697 "    multiple  Multiple kernel thread mode enabled.\n"
698 "\n"
699 );