blob: f7e8c70b343cdae4228d4d1dda8528d246b165f1 [file] [log] [blame]
Sjur Braendelandc72dfae2010-03-30 13:56:25 +00001/*
2 * CAIF Interface registration.
3 * Copyright (C) ST-Ericsson AB 2010
4 * Author: Sjur Brendeland/sjur.brandeland@stericsson.com
5 * License terms: GNU General Public License (GPL) version 2
6 *
7 * Borrowed heavily from file: pn_dev.c. Thanks to
8 * Remi Denis-Courmont <remi.denis-courmont@nokia.com>
9 * and Sakari Ailus <sakari.ailus@nokia.com>
10 */
11
Joe Perchesb31fa5b2010-09-05 21:31:11 +000012#define pr_fmt(fmt) KBUILD_MODNAME ":%s(): " fmt, __func__
13
Sjur Braendelandc72dfae2010-03-30 13:56:25 +000014#include <linux/kernel.h>
15#include <linux/if_arp.h>
16#include <linux/net.h>
17#include <linux/netdevice.h>
sjur.brandeland@stericsson.combd30ce42011-05-13 02:44:00 +000018#include <linux/mutex.h>
Paul Gortmaker3a9a2312011-05-27 09:12:25 -040019#include <linux/module.h>
Sjur Braendelandc72dfae2010-03-30 13:56:25 +000020#include <net/netns/generic.h>
21#include <net/net_namespace.h>
22#include <net/pkt_sched.h>
23#include <net/caif/caif_device.h>
Sjur Braendelandc72dfae2010-03-30 13:56:25 +000024#include <net/caif/caif_layer.h>
25#include <net/caif/cfpkt.h>
26#include <net/caif/cfcnfg.h>
sjur.brandeland@stericsson.com7c18d222011-11-30 09:22:47 +000027#include <net/caif/cfserl.h>
Sjur Braendelandc72dfae2010-03-30 13:56:25 +000028
29MODULE_LICENSE("GPL");
Sjur Braendelandc72dfae2010-03-30 13:56:25 +000030
31/* Used for local tracking of the CAIF net devices */
32struct caif_device_entry {
33 struct cflayer layer;
34 struct list_head list;
Sjur Braendelandc72dfae2010-03-30 13:56:25 +000035 struct net_device *netdev;
sjur.brandeland@stericsson.combd30ce42011-05-13 02:44:00 +000036 int __percpu *pcpu_refcnt;
Sjur Braendelandc72dfae2010-03-30 13:56:25 +000037};
38
39struct caif_device_entry_list {
40 struct list_head list;
41 /* Protects simulanous deletes in list */
sjur.brandeland@stericsson.combd30ce42011-05-13 02:44:00 +000042 struct mutex lock;
Sjur Braendelandc72dfae2010-03-30 13:56:25 +000043};
44
45struct caif_net {
sjur.brandeland@stericsson.combee925d2011-05-13 02:44:05 +000046 struct cfcnfg *cfg;
Sjur Braendelandc72dfae2010-03-30 13:56:25 +000047 struct caif_device_entry_list caifdevs;
48};
49
50static int caif_net_id;
sjur.brandeland@stericsson.combee925d2011-05-13 02:44:05 +000051
52struct cfcnfg *get_cfcnfg(struct net *net)
53{
54 struct caif_net *caifn;
55 BUG_ON(!net);
56 caifn = net_generic(net, caif_net_id);
sjur.brandeland@stericsson.com7c18d222011-11-30 09:22:47 +000057 if (!caifn)
58 return NULL;
sjur.brandeland@stericsson.combee925d2011-05-13 02:44:05 +000059 return caifn->cfg;
60}
61EXPORT_SYMBOL(get_cfcnfg);
Sjur Braendelandc72dfae2010-03-30 13:56:25 +000062
63static struct caif_device_entry_list *caif_device_list(struct net *net)
64{
65 struct caif_net *caifn;
66 BUG_ON(!net);
67 caifn = net_generic(net, caif_net_id);
sjur.brandeland@stericsson.com7c18d222011-11-30 09:22:47 +000068 if (!caifn)
69 return NULL;
Sjur Braendelandc72dfae2010-03-30 13:56:25 +000070 return &caifn->caifdevs;
71}
72
sjur.brandeland@stericsson.combd30ce42011-05-13 02:44:00 +000073static void caifd_put(struct caif_device_entry *e)
74{
75 irqsafe_cpu_dec(*e->pcpu_refcnt);
76}
77
78static void caifd_hold(struct caif_device_entry *e)
79{
80 irqsafe_cpu_inc(*e->pcpu_refcnt);
81}
82
83static int caifd_refcnt_read(struct caif_device_entry *e)
84{
85 int i, refcnt = 0;
86 for_each_possible_cpu(i)
87 refcnt += *per_cpu_ptr(e->pcpu_refcnt, i);
88 return refcnt;
89}
90
Sjur Braendelandc72dfae2010-03-30 13:56:25 +000091/* Allocate new CAIF device. */
92static struct caif_device_entry *caif_device_alloc(struct net_device *dev)
93{
94 struct caif_device_entry_list *caifdevs;
95 struct caif_device_entry *caifd;
sjur.brandeland@stericsson.combd30ce42011-05-13 02:44:00 +000096
Sjur Braendelandc72dfae2010-03-30 13:56:25 +000097 caifdevs = caif_device_list(dev_net(dev));
sjur.brandeland@stericsson.com7c18d222011-11-30 09:22:47 +000098 if (!caifdevs)
99 return NULL;
sjur.brandeland@stericsson.combd30ce42011-05-13 02:44:00 +0000100
Eric Dumazet4fb66b82011-09-02 02:19:23 +0000101 caifd = kzalloc(sizeof(*caifd), GFP_KERNEL);
Sjur Braendelandc72dfae2010-03-30 13:56:25 +0000102 if (!caifd)
103 return NULL;
sjur.brandeland@stericsson.combd30ce42011-05-13 02:44:00 +0000104 caifd->pcpu_refcnt = alloc_percpu(int);
Eric Dumazet4fb66b82011-09-02 02:19:23 +0000105 if (!caifd->pcpu_refcnt) {
106 kfree(caifd);
107 return NULL;
108 }
Sjur Braendelandc72dfae2010-03-30 13:56:25 +0000109 caifd->netdev = dev;
sjur.brandeland@stericsson.combd30ce42011-05-13 02:44:00 +0000110 dev_hold(dev);
Sjur Braendelandc72dfae2010-03-30 13:56:25 +0000111 return caifd;
112}
113
114static struct caif_device_entry *caif_get(struct net_device *dev)
115{
116 struct caif_device_entry_list *caifdevs =
117 caif_device_list(dev_net(dev));
118 struct caif_device_entry *caifd;
sjur.brandeland@stericsson.com7c18d222011-11-30 09:22:47 +0000119 if (!caifdevs)
120 return NULL;
121
sjur.brandeland@stericsson.combd30ce42011-05-13 02:44:00 +0000122 list_for_each_entry_rcu(caifd, &caifdevs->list, list) {
Sjur Braendelandc72dfae2010-03-30 13:56:25 +0000123 if (caifd->netdev == dev)
124 return caifd;
125 }
126 return NULL;
127}
128
Sjur Braendelandc72dfae2010-03-30 13:56:25 +0000129static int transmit(struct cflayer *layer, struct cfpkt *pkt)
130{
sjur.brandeland@stericsson.comc85c2952011-05-13 02:44:06 +0000131 int err;
Sjur Braendelandc72dfae2010-03-30 13:56:25 +0000132 struct caif_device_entry *caifd =
133 container_of(layer, struct caif_device_entry, layer);
Sjur Brændeland4dd820c2011-04-11 10:43:51 +0000134 struct sk_buff *skb;
135
Sjur Braendelandc72dfae2010-03-30 13:56:25 +0000136 skb = cfpkt_tonative(pkt);
137 skb->dev = caifd->netdev;
sjur.brandeland@stericsson.com7c18d222011-11-30 09:22:47 +0000138 skb_reset_network_header(skb);
139 skb->protocol = htons(ETH_P_CAIF);
Sjur Braendelandc72dfae2010-03-30 13:56:25 +0000140
sjur.brandeland@stericsson.comc85c2952011-05-13 02:44:06 +0000141 err = dev_queue_xmit(skb);
142 if (err > 0)
143 err = -EIO;
Sjur Braendelandc72dfae2010-03-30 13:56:25 +0000144
sjur.brandeland@stericsson.comc85c2952011-05-13 02:44:06 +0000145 return err;
Sjur Braendelandc72dfae2010-03-30 13:56:25 +0000146}
147
Sjur Braendelandc72dfae2010-03-30 13:56:25 +0000148/*
sjur.brandeland@stericsson.combd30ce42011-05-13 02:44:00 +0000149 * Stuff received packets into the CAIF stack.
Sjur Braendelandc72dfae2010-03-30 13:56:25 +0000150 * On error, returns non-zero and releases the skb.
151 */
152static int receive(struct sk_buff *skb, struct net_device *dev,
153 struct packet_type *pkttype, struct net_device *orig_dev)
154{
Sjur Braendelandc72dfae2010-03-30 13:56:25 +0000155 struct cfpkt *pkt;
156 struct caif_device_entry *caifd;
sjur.brandeland@stericsson.com69c867c2011-05-22 11:18:54 +0000157 int err;
sjur.brandeland@stericsson.combd30ce42011-05-13 02:44:00 +0000158
Sjur Braendelandc72dfae2010-03-30 13:56:25 +0000159 pkt = cfpkt_fromnative(CAIF_DIR_IN, skb);
sjur.brandeland@stericsson.combd30ce42011-05-13 02:44:00 +0000160
161 rcu_read_lock();
Sjur Braendelandc72dfae2010-03-30 13:56:25 +0000162 caifd = caif_get(dev);
Sjur Braendelandc72dfae2010-03-30 13:56:25 +0000163
sjur.brandeland@stericsson.combd30ce42011-05-13 02:44:00 +0000164 if (!caifd || !caifd->layer.up || !caifd->layer.up->receive ||
165 !netif_oper_up(caifd->netdev)) {
166 rcu_read_unlock();
167 kfree_skb(skb);
Sjur Braendelandc72dfae2010-03-30 13:56:25 +0000168 return NET_RX_DROP;
sjur.brandeland@stericsson.combd30ce42011-05-13 02:44:00 +0000169 }
Sjur Braendelandc72dfae2010-03-30 13:56:25 +0000170
sjur.brandeland@stericsson.combd30ce42011-05-13 02:44:00 +0000171 /* Hold reference to netdevice while using CAIF stack */
172 caifd_hold(caifd);
173 rcu_read_unlock();
174
sjur.brandeland@stericsson.com69c867c2011-05-22 11:18:54 +0000175 err = caifd->layer.up->receive(caifd->layer.up, pkt);
176
177 /* For -EILSEQ the packet is not freed so so it now */
178 if (err == -EILSEQ)
179 cfpkt_destroy(pkt);
sjur.brandeland@stericsson.combd30ce42011-05-13 02:44:00 +0000180
181 /* Release reference to stack upwards */
182 caifd_put(caifd);
sjur.brandeland@stericsson.com7c18d222011-11-30 09:22:47 +0000183
184 if (err != 0)
185 err = NET_RX_DROP;
186 return err;
Sjur Braendelandc72dfae2010-03-30 13:56:25 +0000187}
188
189static struct packet_type caif_packet_type __read_mostly = {
190 .type = cpu_to_be16(ETH_P_CAIF),
191 .func = receive,
192};
193
194static void dev_flowctrl(struct net_device *dev, int on)
195{
sjur.brandeland@stericsson.combd30ce42011-05-13 02:44:00 +0000196 struct caif_device_entry *caifd;
197
198 rcu_read_lock();
199
200 caifd = caif_get(dev);
201 if (!caifd || !caifd->layer.up || !caifd->layer.up->ctrlcmd) {
202 rcu_read_unlock();
Sjur Braendelandc72dfae2010-03-30 13:56:25 +0000203 return;
sjur.brandeland@stericsson.combd30ce42011-05-13 02:44:00 +0000204 }
205
206 caifd_hold(caifd);
207 rcu_read_unlock();
Sjur Braendelandc72dfae2010-03-30 13:56:25 +0000208
209 caifd->layer.up->ctrlcmd(caifd->layer.up,
210 on ?
211 _CAIF_CTRLCMD_PHYIF_FLOW_ON_IND :
212 _CAIF_CTRLCMD_PHYIF_FLOW_OFF_IND,
213 caifd->layer.id);
sjur.brandeland@stericsson.combd30ce42011-05-13 02:44:00 +0000214 caifd_put(caifd);
Sjur Braendelandc72dfae2010-03-30 13:56:25 +0000215}
216
sjur.brandeland@stericsson.com7c18d222011-11-30 09:22:47 +0000217void caif_enroll_dev(struct net_device *dev, struct caif_dev_common *caifdev,
218 struct cflayer *link_support, int head_room,
219 struct cflayer **layer, int (**rcv_func)(
220 struct sk_buff *, struct net_device *,
221 struct packet_type *, struct net_device *))
222{
223 struct caif_device_entry *caifd;
224 enum cfcnfg_phy_preference pref;
225 struct cfcnfg *cfg = get_cfcnfg(dev_net(dev));
226 struct caif_device_entry_list *caifdevs;
227
228 caifdevs = caif_device_list(dev_net(dev));
229 if (!cfg || !caifdevs)
230 return;
231 caifd = caif_device_alloc(dev);
232 if (!caifd)
233 return;
234 *layer = &caifd->layer;
235
236 switch (caifdev->link_select) {
237 case CAIF_LINK_HIGH_BANDW:
238 pref = CFPHYPREF_HIGH_BW;
239 break;
240 case CAIF_LINK_LOW_LATENCY:
241 pref = CFPHYPREF_LOW_LAT;
242 break;
243 default:
244 pref = CFPHYPREF_HIGH_BW;
245 break;
246 }
247 mutex_lock(&caifdevs->lock);
248 list_add_rcu(&caifd->list, &caifdevs->list);
249
250 strncpy(caifd->layer.name, dev->name,
251 sizeof(caifd->layer.name) - 1);
252 caifd->layer.name[sizeof(caifd->layer.name) - 1] = 0;
253 caifd->layer.transmit = transmit;
254 cfcnfg_add_phy_layer(cfg,
255 dev,
256 &caifd->layer,
257 pref,
258 link_support,
259 caifdev->use_fcs,
260 head_room);
261 mutex_unlock(&caifdevs->lock);
262 if (rcv_func)
263 *rcv_func = receive;
264}
265
Sjur Braendelandc72dfae2010-03-30 13:56:25 +0000266/* notify Caif of device events */
267static int caif_device_notify(struct notifier_block *me, unsigned long what,
268 void *arg)
269{
270 struct net_device *dev = arg;
271 struct caif_device_entry *caifd = NULL;
272 struct caif_dev_common *caifdev;
sjur.brandeland@stericsson.combee925d2011-05-13 02:44:05 +0000273 struct cfcnfg *cfg;
sjur.brandeland@stericsson.com7c18d222011-11-30 09:22:47 +0000274 struct cflayer *layer, *link_support;
275 int head_room = 0;
David Woodhouse08613e42011-10-24 21:25:21 +0000276 struct caif_device_entry_list *caifdevs;
Sjur Braendelandc72dfae2010-03-30 13:56:25 +0000277
sjur.brandeland@stericsson.combee925d2011-05-13 02:44:05 +0000278 cfg = get_cfcnfg(dev_net(dev));
sjur.brandeland@stericsson.com7c18d222011-11-30 09:22:47 +0000279 caifdevs = caif_device_list(dev_net(dev));
280 if (!cfg || !caifdevs)
sjur.brandeland@stericsson.combee925d2011-05-13 02:44:05 +0000281 return 0;
282
sjur.brandeland@stericsson.com7c18d222011-11-30 09:22:47 +0000283 caifd = caif_get(dev);
284 if (caifd == NULL && dev->type != ARPHRD_CAIF)
285 return 0;
David Woodhouse08613e42011-10-24 21:25:21 +0000286
Sjur Braendelandc72dfae2010-03-30 13:56:25 +0000287 switch (what) {
288 case NETDEV_REGISTER:
sjur.brandeland@stericsson.com7c18d222011-11-30 09:22:47 +0000289 if (caifd != NULL)
290 break;
sjur.brandeland@stericsson.combd30ce42011-05-13 02:44:00 +0000291
Sjur Braendelandc72dfae2010-03-30 13:56:25 +0000292 caifdev = netdev_priv(dev);
Sjur Braendelandc72dfae2010-03-30 13:56:25 +0000293
sjur.brandeland@stericsson.com7c18d222011-11-30 09:22:47 +0000294 link_support = NULL;
295 if (caifdev->use_frag) {
296 head_room = 1;
297 link_support = cfserl_create(dev->ifindex,
sjur.brandeland@stericsson.come977b4c2011-11-30 09:22:48 +0000298 caifdev->use_stx);
sjur.brandeland@stericsson.com7c18d222011-11-30 09:22:47 +0000299 if (!link_support) {
300 pr_warn("Out of memory\n");
301 break;
302 }
Sjur Braendelandc72dfae2010-03-30 13:56:25 +0000303 }
sjur.brandeland@stericsson.com7c18d222011-11-30 09:22:47 +0000304 caif_enroll_dev(dev, caifdev, link_support, head_room,
305 &layer, NULL);
306 caifdev->flowctrl = dev_flowctrl;
Sjur Braendelandc72dfae2010-03-30 13:56:25 +0000307 break;
308
sjur.brandeland@stericsson.combd30ce42011-05-13 02:44:00 +0000309 case NETDEV_UP:
310 rcu_read_lock();
311
Sjur Braendelandc72dfae2010-03-30 13:56:25 +0000312 caifd = caif_get(dev);
sjur.brandeland@stericsson.combd30ce42011-05-13 02:44:00 +0000313 if (caifd == NULL) {
314 rcu_read_unlock();
Sjur Braendelandc72dfae2010-03-30 13:56:25 +0000315 break;
sjur.brandeland@stericsson.combd30ce42011-05-13 02:44:00 +0000316 }
Sjur Braendelandc72dfae2010-03-30 13:56:25 +0000317
sjur.brandeland@stericsson.combd30ce42011-05-13 02:44:00 +0000318 cfcnfg_set_phy_state(cfg, &caifd->layer, true);
319 rcu_read_unlock();
Sjur Braendelandc72dfae2010-03-30 13:56:25 +0000320
Sjur Braendelandc72dfae2010-03-30 13:56:25 +0000321 break;
322
323 case NETDEV_DOWN:
sjur.brandeland@stericsson.combd30ce42011-05-13 02:44:00 +0000324 rcu_read_lock();
325
Sjur Braendelandc72dfae2010-03-30 13:56:25 +0000326 caifd = caif_get(dev);
sjur.brandeland@stericsson.combd30ce42011-05-13 02:44:00 +0000327 if (!caifd || !caifd->layer.up || !caifd->layer.up->ctrlcmd) {
328 rcu_read_unlock();
329 return -EINVAL;
330 }
331
332 cfcnfg_set_phy_state(cfg, &caifd->layer, false);
333 caifd_hold(caifd);
334 rcu_read_unlock();
335
336 caifd->layer.up->ctrlcmd(caifd->layer.up,
337 _CAIF_CTRLCMD_PHYIF_DOWN_IND,
338 caifd->layer.id);
339 caifd_put(caifd);
Sjur Braendelandc72dfae2010-03-30 13:56:25 +0000340 break;
341
342 case NETDEV_UNREGISTER:
sjur.brandeland@stericsson.combd30ce42011-05-13 02:44:00 +0000343 mutex_lock(&caifdevs->lock);
344
Sjur Braendelandc72dfae2010-03-30 13:56:25 +0000345 caifd = caif_get(dev);
sjur.brandeland@stericsson.combd30ce42011-05-13 02:44:00 +0000346 if (caifd == NULL) {
347 mutex_unlock(&caifdevs->lock);
André Carvalho de Matosf2527ec2010-11-01 11:52:47 +0000348 break;
sjur.brandeland@stericsson.combd30ce42011-05-13 02:44:00 +0000349 }
350 list_del_rcu(&caifd->list);
351
352 /*
353 * NETDEV_UNREGISTER is called repeatedly until all reference
354 * counts for the net-device are released. If references to
355 * caifd is taken, simply ignore NETDEV_UNREGISTER and wait for
356 * the next call to NETDEV_UNREGISTER.
357 *
358 * If any packets are in flight down the CAIF Stack,
359 * cfcnfg_del_phy_layer will return nonzero.
360 * If no packets are in flight, the CAIF Stack associated
361 * with the net-device un-registering is freed.
362 */
363
364 if (caifd_refcnt_read(caifd) != 0 ||
365 cfcnfg_del_phy_layer(cfg, &caifd->layer) != 0) {
366
367 pr_info("Wait for device inuse\n");
368 /* Enrole device if CAIF Stack is still in use */
369 list_add_rcu(&caifd->list, &caifdevs->list);
370 mutex_unlock(&caifdevs->lock);
371 break;
372 }
373
374 synchronize_rcu();
375 dev_put(caifd->netdev);
376 free_percpu(caifd->pcpu_refcnt);
377 kfree(caifd);
378
379 mutex_unlock(&caifdevs->lock);
Sjur Braendelandc72dfae2010-03-30 13:56:25 +0000380 break;
381 }
382 return 0;
383}
384
385static struct notifier_block caif_device_notifier = {
386 .notifier_call = caif_device_notify,
387 .priority = 0,
388};
389
Sjur Braendelandc72dfae2010-03-30 13:56:25 +0000390/* Per-namespace Caif devices handling */
391static int caif_init_net(struct net *net)
392{
393 struct caif_net *caifn = net_generic(net, caif_net_id);
sjur.brandeland@stericsson.combee925d2011-05-13 02:44:05 +0000394 BUG_ON(!caifn);
Sjur Braendelandc72dfae2010-03-30 13:56:25 +0000395 INIT_LIST_HEAD(&caifn->caifdevs.list);
sjur.brandeland@stericsson.combd30ce42011-05-13 02:44:00 +0000396 mutex_init(&caifn->caifdevs.lock);
sjur.brandeland@stericsson.combee925d2011-05-13 02:44:05 +0000397
398 caifn->cfg = cfcnfg_create();
399 if (!caifn->cfg) {
400 pr_warn("can't create cfcnfg\n");
401 return -ENOMEM;
402 }
403
Sjur Braendelandc72dfae2010-03-30 13:56:25 +0000404 return 0;
405}
406
407static void caif_exit_net(struct net *net)
408{
sjur.brandeland@stericsson.combd30ce42011-05-13 02:44:00 +0000409 struct caif_device_entry *caifd, *tmp;
410 struct caif_device_entry_list *caifdevs =
411 caif_device_list(net);
sjur.brandeland@stericsson.com7c18d222011-11-30 09:22:47 +0000412 struct cfcnfg *cfg = get_cfcnfg(net);
413
414 if (!cfg || !caifdevs)
415 return;
sjur.brandeland@stericsson.combd30ce42011-05-13 02:44:00 +0000416
Sjur Braendelandc72dfae2010-03-30 13:56:25 +0000417 rtnl_lock();
sjur.brandeland@stericsson.combd30ce42011-05-13 02:44:00 +0000418 mutex_lock(&caifdevs->lock);
419
420 list_for_each_entry_safe(caifd, tmp, &caifdevs->list, list) {
421 int i = 0;
422 list_del_rcu(&caifd->list);
423 cfcnfg_set_phy_state(cfg, &caifd->layer, false);
424
425 while (i < 10 &&
426 (caifd_refcnt_read(caifd) != 0 ||
427 cfcnfg_del_phy_layer(cfg, &caifd->layer) != 0)) {
428
429 pr_info("Wait for device inuse\n");
430 msleep(250);
431 i++;
432 }
433 synchronize_rcu();
434 dev_put(caifd->netdev);
435 free_percpu(caifd->pcpu_refcnt);
436 kfree(caifd);
Sjur Braendelandc72dfae2010-03-30 13:56:25 +0000437 }
sjur.brandeland@stericsson.combee925d2011-05-13 02:44:05 +0000438 cfcnfg_remove(cfg);
sjur.brandeland@stericsson.combd30ce42011-05-13 02:44:00 +0000439
440 mutex_unlock(&caifdevs->lock);
Sjur Braendelandc72dfae2010-03-30 13:56:25 +0000441 rtnl_unlock();
442}
443
444static struct pernet_operations caif_net_ops = {
445 .init = caif_init_net,
446 .exit = caif_exit_net,
447 .id = &caif_net_id,
448 .size = sizeof(struct caif_net),
449};
450
451/* Initialize Caif devices list */
452static int __init caif_device_init(void)
453{
454 int result;
sjur.brandeland@stericsson.combd30ce42011-05-13 02:44:00 +0000455
Sjur Braendelandc72dfae2010-03-30 13:56:25 +0000456 result = register_pernet_device(&caif_net_ops);
457
sjur.brandeland@stericsson.combee925d2011-05-13 02:44:05 +0000458 if (result)
Sjur Braendelandc72dfae2010-03-30 13:56:25 +0000459 return result;
sjur.brandeland@stericsson.combee925d2011-05-13 02:44:05 +0000460
Sjur Braendelandc72dfae2010-03-30 13:56:25 +0000461 register_netdevice_notifier(&caif_device_notifier);
sjur.brandeland@stericsson.combee925d2011-05-13 02:44:05 +0000462 dev_add_pack(&caif_packet_type);
Sjur Braendelandc72dfae2010-03-30 13:56:25 +0000463
464 return result;
Sjur Braendelandc72dfae2010-03-30 13:56:25 +0000465}
466
467static void __exit caif_device_exit(void)
468{
Sjur Braendelandc72dfae2010-03-30 13:56:25 +0000469 unregister_pernet_device(&caif_net_ops);
470 unregister_netdevice_notifier(&caif_device_notifier);
sjur.brandeland@stericsson.combee925d2011-05-13 02:44:05 +0000471 dev_remove_pack(&caif_packet_type);
Sjur Braendelandc72dfae2010-03-30 13:56:25 +0000472}
473
474module_init(caif_device_init);
475module_exit(caif_device_exit);