aoe.h 5.4 KB
Newer Older
E
Ed L. Cashin 已提交
1
/* Copyright (c) 2007 Coraid, Inc.  See COPYING for GPL terms. */
2
#define VERSION "47"
L
Linus Torvalds 已提交
3 4
#define AOE_MAJOR 152
#define DEVICE_NAME "aoe"
5 6 7 8

/* set AOE_PARTITIONS to 1 to use whole-disks only
 * default is 16, which is 15 partitions plus the whole disk
 */
L
Linus Torvalds 已提交
9
#ifndef AOE_PARTITIONS
10
#define AOE_PARTITIONS (16)
L
Linus Torvalds 已提交
11
#endif
12

13 14 15
#define SYSMINOR(aoemajor, aoeminor) ((aoemajor) * NPERSHELF + (aoeminor))
#define AOEMAJOR(sysminor) ((sysminor) / NPERSHELF)
#define AOEMINOR(sysminor) ((sysminor) % NPERSHELF)
L
Linus Torvalds 已提交
16 17 18 19 20
#define WHITESPACE " \t\v\f\n"

enum {
	AOECMD_ATA,
	AOECMD_CFG,
21
	AOECMD_VEND_MIN = 0xf0,
L
Linus Torvalds 已提交
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42

	AOEFL_RSP = (1<<3),
	AOEFL_ERR = (1<<2),

	AOEAFL_EXT = (1<<6),
	AOEAFL_DEV = (1<<4),
	AOEAFL_ASYNC = (1<<1),
	AOEAFL_WRITE = (1<<0),

	AOECCMD_READ = 0,
	AOECCMD_TEST,
	AOECCMD_PTEST,
	AOECCMD_SET,
	AOECCMD_FSET,

	AOE_HVER = 0x10,
};

struct aoe_hdr {
	unsigned char dst[6];
	unsigned char src[6];
43
	__be16 type;
L
Linus Torvalds 已提交
44 45
	unsigned char verfl;
	unsigned char err;
46
	__be16 major;
L
Linus Torvalds 已提交
47 48
	unsigned char minor;
	unsigned char cmd;
49
	__be32 tag;
L
Linus Torvalds 已提交
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
};

struct aoe_atahdr {
	unsigned char aflags;
	unsigned char errfeat;
	unsigned char scnt;
	unsigned char cmdstat;
	unsigned char lba0;
	unsigned char lba1;
	unsigned char lba2;
	unsigned char lba3;
	unsigned char lba4;
	unsigned char lba5;
	unsigned char res[2];
};

struct aoe_cfghdr {
67 68
	__be16 bufcnt;
	__be16 fwver;
E
Ed L. Cashin 已提交
69
	unsigned char scnt;
L
Linus Torvalds 已提交
70 71 72 73 74 75 76 77 78
	unsigned char aoeccmd;
	unsigned char cslen[2];
};

enum {
	DEVFL_UP = 1,	/* device is installed in system and ready for AoE->ATA commands */
	DEVFL_TKILL = (1<<1),	/* flag for timer to know when to kill self */
	DEVFL_EXT = (1<<2),	/* device accepts lba48 commands */
	DEVFL_CLOSEWAIT = (1<<3), /* device is waiting for all closes to revalidate */
79
	DEVFL_GDALLOC = (1<<4),	/* need to alloc gendisk */
80
	DEVFL_KICKME = (1<<5),	/* slow polling network card catch */
81
	DEVFL_NEWSIZE = (1<<6),	/* need to update dev size in block layer */
L
Linus Torvalds 已提交
82 83 84 85 86

	BUFFL_FAIL = 1,
};

enum {
E
Ed L. Cashin 已提交
87
	DEFAULTBCNT = 2 * 512,	/* 2 sectors */
88
	NPERSHELF = 16,		/* number of slots per shelf address */
L
Linus Torvalds 已提交
89
	FREETAG = -1,
90 91 92
	MIN_BUFS = 16,
	NTARGETS = 8,
	NAOEIFS = 8,
93
	NSKBPOOLMAX = 256,
94
	NFACTIVE = 17,
95 96 97 98 99

	TIMERTICK = HZ / 10,
	MINTIMER = HZ >> 2,
	MAXTIMER = HZ << 1,
	HELPWAIT = 20,
L
Linus Torvalds 已提交
100 101 102 103 104 105 106 107 108
};

struct buf {
	ulong nframesout;
	ulong resid;
	ulong bv_resid;
	sector_t sector;
	struct bio *bio;
	struct bio_vec *bv;
109
	struct request *rq;
L
Linus Torvalds 已提交
110 111 112
};

struct frame {
113 114
	struct list_head head;
	u32 tag;
L
Linus Torvalds 已提交
115
	ulong waited;
116
	struct aoetgt *t;		/* parent target I belong to */
E
Ed L. Cashin 已提交
117
	sector_t lba;
118 119
	struct sk_buff *skb;		/* command skb freed on module exit */
	struct sk_buff *r_skb;		/* response skb for async processing */
120
	struct buf *buf;
121
	struct bio_vec *bv;
122
	ulong bcnt;
123
	ulong bv_off;
L
Linus Torvalds 已提交
124 125
};

126 127 128 129 130 131 132 133 134 135
struct aoeif {
	struct net_device *nd;
	unsigned char lost;
	unsigned char lostjumbo;
	ushort maxbcnt;
};

struct aoetgt {
	unsigned char addr[6];
	ushort nframes;
136 137 138
	struct aoedev *d;			/* parent device I belong to */
	struct list_head factive[NFACTIVE];	/* hash of active frames */
	struct list_head ffree;			/* list of free frames */
139 140 141 142 143 144
	struct aoeif ifs[NAOEIFS];
	struct aoeif *ifp;	/* current aoeif in use */
	ushort nout;
	ushort maxout;
	u16 lasttag;		/* last tag sent */
	u16 useme;
145
	ulong falloc;
146 147 148 149
	ulong lastwadj;		/* last window adjustment */
	int wpkts, rpkts;
};

L
Linus Torvalds 已提交
150 151 152 153
struct aoedev {
	struct aoedev *next;
	ulong sysminor;
	ulong aoemajor;
154 155
	u16 aoeminor;
	u16 flags;
156 157 158
	u16 nopen;		/* (bd_openers isn't available without sleeping) */
	u16 rttavg;		/* round trip average of requests/responses */
	u16 mintimer;
L
Linus Torvalds 已提交
159
	u16 fw_ver;		/* version of blade's firmware */
160
	ulong ref;
L
Linus Torvalds 已提交
161 162
	struct work_struct work;/* disk create work struct */
	struct gendisk *gd;
163
	struct request_queue *blkq;
L
Linus Torvalds 已提交
164 165 166 167
	struct hd_geometry geo; 
	sector_t ssize;
	struct timer_list timer;
	spinlock_t lock;
168
	struct sk_buff_head skbpool;
L
Linus Torvalds 已提交
169
	mempool_t *bufpool;	/* for deadlock-free Buf allocation */
170 171 172 173 174
	struct {		/* pointers to work in progress */
		struct buf *buf;
		struct bio *nxbio;
		struct request *rq;
	} ip;
175 176
	struct aoetgt *targets[NTARGETS];
	struct aoetgt **tgt;	/* target in use when working */
177 178 179
	struct aoetgt *htgt;	/* target needing rexmit assistance */
	ulong ntargets;
	ulong kicked;
L
Linus Torvalds 已提交
180 181
};

182 183 184 185 186 187 188 189 190
/* kthread tracking */
struct ktstate {
	struct completion rendez;
	struct task_struct *task;
	wait_queue_head_t *waitq;
	int (*fn) (void);
	char *name;
	spinlock_t *lock;
};
L
Linus Torvalds 已提交
191 192 193 194 195 196 197 198 199 200 201

int aoeblk_init(void);
void aoeblk_exit(void);
void aoeblk_gdalloc(void *);
void aoedisk_rm_sysfs(struct aoedev *d);

int aoechr_init(void);
void aoechr_exit(void);
void aoechr_error(char *);

void aoecmd_work(struct aoedev *d);
202
void aoecmd_cfg(ushort aoemajor, unsigned char aoeminor);
203
struct sk_buff *aoecmd_ata_rsp(struct sk_buff *);
L
Linus Torvalds 已提交
204
void aoecmd_cfg_rsp(struct sk_buff *);
D
David Howells 已提交
205
void aoecmd_sleepwork(struct work_struct *);
206
void aoecmd_cleanslate(struct aoedev *);
207 208
void aoecmd_exit(void);
int aoecmd_init(void);
209
struct sk_buff *aoecmd_ata_id(struct aoedev *);
210
void aoe_freetframe(struct frame *);
211 212
void aoe_flush_iocq(void);
void aoe_end_request(struct aoedev *, struct request *, int);
213 214
int aoe_ktstart(struct ktstate *k);
void aoe_ktstop(struct ktstate *k);
L
Linus Torvalds 已提交
215 216 217

int aoedev_init(void);
void aoedev_exit(void);
218
struct aoedev *aoedev_by_aoeaddr(int maj, int min);
219
struct aoedev *aoedev_by_sysminor_m(ulong sysminor);
L
Linus Torvalds 已提交
220
void aoedev_downdev(struct aoedev *d);
221
int aoedev_flush(const char __user *str, size_t size);
222 223
void aoe_failbuf(struct aoedev *, struct buf *);
void aoedev_put(struct aoedev *);
L
Linus Torvalds 已提交
224 225 226

int aoenet_init(void);
void aoenet_exit(void);
227
void aoenet_xmit(struct sk_buff_head *);
L
Linus Torvalds 已提交
228 229 230
int is_aoe_netif(struct net_device *ifp);
int set_aoe_iflist(const char __user *str, size_t size);