Ed Cashin | fea05a2 | 2012-10-04 17:16:38 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2012 Coraid, Inc. See COPYING for GPL terms. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
| 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. Miller | e9bb8fb | 2008-09-21 22:36:49 -0700 | [diff] [blame] | 10 | #include <linux/skbuff.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include "aoe.h" |
| 12 | |
| 13 | MODULE_LICENSE("GPL"); |
| 14 | MODULE_AUTHOR("Sam Hopkins <sah@coraid.com>"); |
Ed L. Cashin | 02edb05 | 2006-01-19 13:46:29 -0500 | [diff] [blame] | 15 | MODULE_DESCRIPTION("AoE block/char driver for 2.6.2 and newer 2.6 kernels"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | MODULE_VERSION(VERSION); |
| 17 | |
| 18 | enum { TINIT, TRUN, TKILL }; |
| 19 | |
| 20 | static void |
| 21 | discover_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 | |
| 57 | static void |
| 58 | aoe_exit(void) |
| 59 | { |
| 60 | discover_timer(TKILL); |
| 61 | |
| 62 | aoenet_exit(); |
| 63 | unregister_blkdev(AOE_MAJOR, DEVICE_NAME); |
Ed Cashin | 896831f | 2012-10-04 17:16:21 -0700 | [diff] [blame] | 64 | aoecmd_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | aoechr_exit(); |
| 66 | aoedev_exit(); |
| 67 | aoeblk_exit(); /* free cache after de-allocating bufs */ |
| 68 | } |
| 69 | |
| 70 | static int __init |
| 71 | aoe_init(void) |
| 72 | { |
| 73 | int ret; |
| 74 | |
| 75 | ret = aoedev_init(); |
| 76 | if (ret) |
| 77 | return ret; |
| 78 | ret = aoechr_init(); |
| 79 | if (ret) |
| 80 | goto chr_fail; |
| 81 | ret = aoeblk_init(); |
| 82 | if (ret) |
| 83 | goto blk_fail; |
| 84 | ret = aoenet_init(); |
| 85 | if (ret) |
| 86 | goto net_fail; |
Ed Cashin | 896831f | 2012-10-04 17:16:21 -0700 | [diff] [blame] | 87 | ret = aoecmd_init(); |
| 88 | if (ret) |
| 89 | goto cmd_fail; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | ret = register_blkdev(AOE_MAJOR, DEVICE_NAME); |
| 91 | if (ret < 0) { |
Ed L. Cashin | a12c93f | 2006-09-20 14:36:51 -0400 | [diff] [blame] | 92 | printk(KERN_ERR "aoe: can't register major\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | goto blkreg_fail; |
| 94 | } |
Ed L. Cashin | a12c93f | 2006-09-20 14:36:51 -0400 | [diff] [blame] | 95 | printk(KERN_INFO "aoe: AoE v%s initialised.\n", VERSION); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | discover_timer(TINIT); |
| 97 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | blkreg_fail: |
Ed Cashin | 896831f | 2012-10-04 17:16:21 -0700 | [diff] [blame] | 99 | aoecmd_exit(); |
| 100 | cmd_fail: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | aoenet_exit(); |
| 102 | net_fail: |
| 103 | aoeblk_exit(); |
| 104 | blk_fail: |
| 105 | aoechr_exit(); |
| 106 | chr_fail: |
| 107 | aoedev_exit(); |
Ed Cashin | a04b41c | 2012-12-17 16:03:39 -0800 | [diff] [blame] | 108 | |
Ed L. Cashin | a12c93f | 2006-09-20 14:36:51 -0400 | [diff] [blame] | 109 | printk(KERN_INFO "aoe: initialisation failure.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | return ret; |
| 111 | } |
| 112 | |
| 113 | module_init(aoe_init); |
| 114 | module_exit(aoe_exit); |
| 115 | |