blob: 7f83ad90e76fd9f4e971ec4d00826eea2e1cffe7 [file] [log] [blame]
Ed L. Cashin52e112b2008-02-08 04:20:09 -08001/* Copyright (c) 2007 Coraid, Inc. See COPYING for GPL terms. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * aoemain.c
4 * Module initialization routines, discover timer
5 */
6
7#include <linux/hdreg.h>
8#include <linux/blkdev.h>
9#include <linux/module.h>
David S. Millere9bb8fb2008-09-21 22:36:49 -070010#include <linux/skbuff.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#include "aoe.h"
12
13MODULE_LICENSE("GPL");
14MODULE_AUTHOR("Sam Hopkins <sah@coraid.com>");
Ed L. Cashin02edb052006-01-19 13:46:29 -050015MODULE_DESCRIPTION("AoE block/char driver for 2.6.2 and newer 2.6 kernels");
Linus Torvalds1da177e2005-04-16 15:20:36 -070016MODULE_VERSION(VERSION);
17
18enum { TINIT, TRUN, TKILL };
19
20static void
21discover_timer(ulong vp)
22{
23 static struct timer_list t;
24 static volatile ulong die;
25 static spinlock_t lock;
26 ulong flags;
27 enum { DTIMERTICK = HZ * 60 }; /* one minute */
28
29 switch (vp) {
30 case TINIT:
31 init_timer(&t);
32 spin_lock_init(&lock);
33 t.data = TRUN;
34 t.function = discover_timer;
35 die = 0;
36 case TRUN:
37 spin_lock_irqsave(&lock, flags);
38 if (!die) {
39 t.expires = jiffies + DTIMERTICK;
40 add_timer(&t);
41 }
42 spin_unlock_irqrestore(&lock, flags);
43
44 aoecmd_cfg(0xffff, 0xff);
45 return;
46 case TKILL:
47 spin_lock_irqsave(&lock, flags);
48 die = 1;
49 spin_unlock_irqrestore(&lock, flags);
50
51 del_timer_sync(&t);
52 default:
53 return;
54 }
55}
56
57static void
58aoe_exit(void)
59{
60 discover_timer(TKILL);
61
62 aoenet_exit();
63 unregister_blkdev(AOE_MAJOR, DEVICE_NAME);
64 aoechr_exit();
65 aoedev_exit();
66 aoeblk_exit(); /* free cache after de-allocating bufs */
67}
68
69static int __init
70aoe_init(void)
71{
72 int ret;
73
74 ret = aoedev_init();
75 if (ret)
76 return ret;
77 ret = aoechr_init();
78 if (ret)
79 goto chr_fail;
80 ret = aoeblk_init();
81 if (ret)
82 goto blk_fail;
83 ret = aoenet_init();
84 if (ret)
85 goto net_fail;
86 ret = register_blkdev(AOE_MAJOR, DEVICE_NAME);
87 if (ret < 0) {
Ed L. Cashina12c93f2006-09-20 14:36:51 -040088 printk(KERN_ERR "aoe: can't register major\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 goto blkreg_fail;
90 }
91
Ed L. Cashina12c93f2006-09-20 14:36:51 -040092 printk(KERN_INFO "aoe: AoE v%s initialised.\n", VERSION);
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 discover_timer(TINIT);
94 return 0;
95
96 blkreg_fail:
97 aoenet_exit();
98 net_fail:
99 aoeblk_exit();
100 blk_fail:
101 aoechr_exit();
102 chr_fail:
103 aoedev_exit();
104
Ed L. Cashina12c93f2006-09-20 14:36:51 -0400105 printk(KERN_INFO "aoe: initialisation failure.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 return ret;
107}
108
109module_init(aoe_init);
110module_exit(aoe_exit);
111