blob: 7b694f7da2de2529a0032ebc3a67b906d3be2fa4 [file] [log] [blame]
Ed Cashinfea05a22012-10-04 17:16:38 -07001/* Copyright (c) 2012 Coraid, Inc. See COPYING for GPL terms. */
Ed Cashin7392fbe2012-10-04 17:16:37 -07002#define VERSION "49"
Linus Torvalds1da177e2005-04-16 15:20:36 -07003#define AOE_MAJOR 152
4#define DEVICE_NAME "aoe"
ecashin@coraid.comfc458dc2005-04-18 22:00:17 -07005
6/* set AOE_PARTITIONS to 1 to use whole-disks only
7 * default is 16, which is 15 partitions plus the whole disk
8 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07009#ifndef AOE_PARTITIONS
Ed L Cashine39526e2005-08-19 16:54:43 -040010#define AOE_PARTITIONS (16)
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#endif
ecashin@coraid.comfc458dc2005-04-18 22:00:17 -070012
Ed L Cashine39526e2005-08-19 16:54:43 -040013#define SYSMINOR(aoemajor, aoeminor) ((aoemajor) * NPERSHELF + (aoeminor))
14#define AOEMAJOR(sysminor) ((sysminor) / NPERSHELF)
15#define AOEMINOR(sysminor) ((sysminor) % NPERSHELF)
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#define WHITESPACE " \t\v\f\n"
17
18enum {
19 AOECMD_ATA,
20 AOECMD_CFG,
Ed Cashinb6d6c512009-02-18 14:48:13 -080021 AOECMD_VEND_MIN = 0xf0,
Linus Torvalds1da177e2005-04-16 15:20:36 -070022
23 AOEFL_RSP = (1<<3),
24 AOEFL_ERR = (1<<2),
25
26 AOEAFL_EXT = (1<<6),
27 AOEAFL_DEV = (1<<4),
28 AOEAFL_ASYNC = (1<<1),
29 AOEAFL_WRITE = (1<<0),
30
31 AOECCMD_READ = 0,
32 AOECCMD_TEST,
33 AOECCMD_PTEST,
34 AOECCMD_SET,
35 AOECCMD_FSET,
36
37 AOE_HVER = 0x10,
38};
39
40struct aoe_hdr {
41 unsigned char dst[6];
42 unsigned char src[6];
ecashin@coraid.com63e9cc52005-04-18 22:00:20 -070043 __be16 type;
Linus Torvalds1da177e2005-04-16 15:20:36 -070044 unsigned char verfl;
45 unsigned char err;
ecashin@coraid.com63e9cc52005-04-18 22:00:20 -070046 __be16 major;
Linus Torvalds1da177e2005-04-16 15:20:36 -070047 unsigned char minor;
48 unsigned char cmd;
ecashin@coraid.com63e9cc52005-04-18 22:00:20 -070049 __be32 tag;
Linus Torvalds1da177e2005-04-16 15:20:36 -070050};
51
Ed Cashin0c966212012-10-04 17:16:40 -070052#define AOE_MAXSHELF (0xffff-1) /* one less than the broadcast shelf address */
53
Linus Torvalds1da177e2005-04-16 15:20:36 -070054struct aoe_atahdr {
55 unsigned char aflags;
56 unsigned char errfeat;
57 unsigned char scnt;
58 unsigned char cmdstat;
59 unsigned char lba0;
60 unsigned char lba1;
61 unsigned char lba2;
62 unsigned char lba3;
63 unsigned char lba4;
64 unsigned char lba5;
65 unsigned char res[2];
66};
67
68struct aoe_cfghdr {
ecashin@coraid.com63e9cc52005-04-18 22:00:20 -070069 __be16 bufcnt;
70 __be16 fwver;
Ed L. Cashin19bf2632006-09-20 14:36:49 -040071 unsigned char scnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 unsigned char aoeccmd;
73 unsigned char cslen[2];
74};
75
76enum {
77 DEVFL_UP = 1, /* device is installed in system and ready for AoE->ATA commands */
78 DEVFL_TKILL = (1<<1), /* flag for timer to know when to kill self */
79 DEVFL_EXT = (1<<2), /* device accepts lba48 commands */
Ed Cashinb21faa22012-10-04 17:16:35 -070080 DEVFL_GDALLOC = (1<<3), /* need to alloc gendisk */
81 DEVFL_KICKME = (1<<4), /* slow polling network card catch */
82 DEVFL_NEWSIZE = (1<<5), /* need to update dev size in block layer */
Linus Torvalds1da177e2005-04-16 15:20:36 -070083};
84
85enum {
Ed L. Cashin19bf2632006-09-20 14:36:49 -040086 DEFAULTBCNT = 2 * 512, /* 2 sectors */
Ed L Cashine39526e2005-08-19 16:54:43 -040087 NPERSHELF = 16, /* number of slots per shelf address */
Ed L. Cashin68e0d422008-02-08 04:20:00 -080088 MIN_BUFS = 16,
89 NTARGETS = 8,
90 NAOEIFS = 8,
Ed Cashin69cf2d852012-10-04 17:16:23 -070091 NSKBPOOLMAX = 256,
Ed Cashin64a80f52012-10-04 17:16:33 -070092 NFACTIVE = 61,
Ed L. Cashin68e0d422008-02-08 04:20:00 -080093
94 TIMERTICK = HZ / 10,
95 MINTIMER = HZ >> 2,
96 MAXTIMER = HZ << 1,
Linus Torvalds1da177e2005-04-16 15:20:36 -070097};
98
99struct buf {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 ulong nframesout;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 ulong resid;
102 ulong bv_resid;
103 sector_t sector;
104 struct bio *bio;
105 struct bio_vec *bv;
Ed Cashin69cf2d852012-10-04 17:16:23 -0700106 struct request *rq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107};
108
109struct frame {
Ed Cashin896831f2012-10-04 17:16:21 -0700110 struct list_head head;
111 u32 tag;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 ulong waited;
Ed Cashin896831f2012-10-04 17:16:21 -0700113 struct aoetgt *t; /* parent target I belong to */
Ed L. Cashin19bf2632006-09-20 14:36:49 -0400114 sector_t lba;
Ed Cashin896831f2012-10-04 17:16:21 -0700115 struct sk_buff *skb; /* command skb freed on module exit */
116 struct sk_buff *r_skb; /* response skb for async processing */
Ed Cashin69cf2d852012-10-04 17:16:23 -0700117 struct buf *buf;
Ed Cashin3d5b0602012-10-04 17:16:20 -0700118 struct bio_vec *bv;
Ed Cashin69cf2d852012-10-04 17:16:23 -0700119 ulong bcnt;
Ed Cashin3d5b0602012-10-04 17:16:20 -0700120 ulong bv_off;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121};
122
Ed L. Cashin68e0d422008-02-08 04:20:00 -0800123struct aoeif {
124 struct net_device *nd;
Ed Cashin3f0f0132012-10-04 17:16:27 -0700125 ulong lost;
126 int bcnt;
Ed L. Cashin68e0d422008-02-08 04:20:00 -0800127};
128
129struct aoetgt {
130 unsigned char addr[6];
131 ushort nframes;
Ed Cashin896831f2012-10-04 17:16:21 -0700132 struct aoedev *d; /* parent device I belong to */
Ed Cashin896831f2012-10-04 17:16:21 -0700133 struct list_head ffree; /* list of free frames */
Ed L. Cashin68e0d422008-02-08 04:20:00 -0800134 struct aoeif ifs[NAOEIFS];
135 struct aoeif *ifp; /* current aoeif in use */
136 ushort nout;
137 ushort maxout;
Ed Cashin896831f2012-10-04 17:16:21 -0700138 ulong falloc;
Ed L. Cashin68e0d422008-02-08 04:20:00 -0800139 ulong lastwadj; /* last window adjustment */
Ed Cashin3f0f0132012-10-04 17:16:27 -0700140 int minbcnt;
Ed L. Cashin68e0d422008-02-08 04:20:00 -0800141 int wpkts, rpkts;
142};
143
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144struct aoedev {
145 struct aoedev *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 ulong sysminor;
147 ulong aoemajor;
Ed L. Cashin68e0d422008-02-08 04:20:00 -0800148 u16 aoeminor;
149 u16 flags;
Ed L. Cashindced3a02006-09-20 14:36:49 -0400150 u16 nopen; /* (bd_openers isn't available without sleeping) */
Ed L. Cashindced3a02006-09-20 14:36:49 -0400151 u16 rttavg; /* round trip average of requests/responses */
152 u16 mintimer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 u16 fw_ver; /* version of blade's firmware */
Ed Cashin64a80f52012-10-04 17:16:33 -0700154 u16 lasttag; /* last tag sent */
155 u16 useme;
Ed Cashin69cf2d852012-10-04 17:16:23 -0700156 ulong ref;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 struct work_struct work;/* disk create work struct */
158 struct gendisk *gd;
Ed Cashin7135a71b2009-09-09 14:10:18 +0200159 struct request_queue *blkq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 struct hd_geometry geo;
161 sector_t ssize;
162 struct timer_list timer;
163 spinlock_t lock;
David S. Millere9bb8fb02008-09-21 22:36:49 -0700164 struct sk_buff_head skbpool;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 mempool_t *bufpool; /* for deadlock-free Buf allocation */
Ed Cashin69cf2d852012-10-04 17:16:23 -0700166 struct { /* pointers to work in progress */
167 struct buf *buf;
168 struct bio *nxbio;
169 struct request *rq;
170 } ip;
Ed Cashin3f0f0132012-10-04 17:16:27 -0700171 ulong maxbcnt;
Ed Cashin64a80f52012-10-04 17:16:33 -0700172 struct list_head factive[NFACTIVE]; /* hash of active frames */
Ed L. Cashin68e0d422008-02-08 04:20:00 -0800173 struct aoetgt *targets[NTARGETS];
174 struct aoetgt **tgt; /* target in use when working */
Ed Cashin896831f2012-10-04 17:16:21 -0700175 struct aoetgt *htgt; /* target needing rexmit assistance */
176 ulong ntargets;
177 ulong kicked;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178};
179
Ed Cashin896831f2012-10-04 17:16:21 -0700180/* kthread tracking */
181struct ktstate {
182 struct completion rendez;
183 struct task_struct *task;
184 wait_queue_head_t *waitq;
185 int (*fn) (void);
186 char *name;
187 spinlock_t *lock;
188};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189
190int aoeblk_init(void);
191void aoeblk_exit(void);
192void aoeblk_gdalloc(void *);
193void aoedisk_rm_sysfs(struct aoedev *d);
194
195int aoechr_init(void);
196void aoechr_exit(void);
197void aoechr_error(char *);
198
199void aoecmd_work(struct aoedev *d);
Ed L. Cashin3ae1c242006-01-19 13:46:19 -0500200void aoecmd_cfg(ushort aoemajor, unsigned char aoeminor);
Ed Cashin896831f2012-10-04 17:16:21 -0700201struct sk_buff *aoecmd_ata_rsp(struct sk_buff *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202void aoecmd_cfg_rsp(struct sk_buff *);
David Howellsc4028952006-11-22 14:57:56 +0000203void aoecmd_sleepwork(struct work_struct *);
Ed L. Cashin68e0d422008-02-08 04:20:00 -0800204void aoecmd_cleanslate(struct aoedev *);
Ed Cashin896831f2012-10-04 17:16:21 -0700205void aoecmd_exit(void);
206int aoecmd_init(void);
Ed L. Cashin68e0d422008-02-08 04:20:00 -0800207struct sk_buff *aoecmd_ata_id(struct aoedev *);
Ed Cashin896831f2012-10-04 17:16:21 -0700208void aoe_freetframe(struct frame *);
Ed Cashin69cf2d852012-10-04 17:16:23 -0700209void aoe_flush_iocq(void);
210void aoe_end_request(struct aoedev *, struct request *, int);
Ed Cashineb086ec2012-10-04 17:16:25 -0700211int aoe_ktstart(struct ktstate *k);
212void aoe_ktstop(struct ktstate *k);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213
214int aoedev_init(void);
215void aoedev_exit(void);
Ed Cashin0c966212012-10-04 17:16:40 -0700216struct aoedev *aoedev_by_aoeaddr(ulong maj, int min, int do_alloc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217void aoedev_downdev(struct aoedev *d);
Ed L. Cashin262bf542008-02-08 04:20:03 -0800218int aoedev_flush(const char __user *str, size_t size);
Ed Cashin69cf2d852012-10-04 17:16:23 -0700219void aoe_failbuf(struct aoedev *, struct buf *);
220void aoedev_put(struct aoedev *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221
222int aoenet_init(void);
223void aoenet_exit(void);
David S. Millere9bb8fb02008-09-21 22:36:49 -0700224void aoenet_xmit(struct sk_buff_head *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225int is_aoe_netif(struct net_device *ifp);
226int set_aoe_iflist(const char __user *str, size_t size);