1 /* Copyright (c) 2013 Coraid, Inc. See COPYING for GPL terms. */ 2 #include <linux/blk-mq.h> 3 4 #define VERSION "85" 5 #define AOE_MAJOR 152 6 #define DEVICE_NAME "aoe" 7 8 /* set AOE_PARTITIONS to 1 to use whole-disks only 9 * default is 16, which is 15 partitions plus the whole disk 10 */ 11 #ifndef AOE_PARTITIONS 12 #define AOE_PARTITIONS (16) 13 #endif 14 15 #define WHITESPACE " \t\v\f\n," 16 17 enum { 18 AOECMD_ATA, 19 AOECMD_CFG, 20 AOECMD_VEND_MIN = 0xf0, 21 22 AOEFL_RSP = (1<<3), 23 AOEFL_ERR = (1<<2), 24 25 AOEAFL_EXT = (1<<6), 26 AOEAFL_DEV = (1<<4), 27 AOEAFL_ASYNC = (1<<1), 28 AOEAFL_WRITE = (1<<0), 29 30 AOECCMD_READ = 0, 31 AOECCMD_TEST, 32 AOECCMD_PTEST, 33 AOECCMD_SET, 34 AOECCMD_FSET, 35 36 AOE_HVER = 0x10, 37 }; 38 39 struct aoe_hdr { 40 unsigned char dst[6]; 41 unsigned char src[6]; 42 __be16 type; 43 unsigned char verfl; 44 unsigned char err; 45 __be16 major; 46 unsigned char minor; 47 unsigned char cmd; 48 __be32 tag; 49 }; 50 51 struct aoe_atahdr { 52 unsigned char aflags; 53 unsigned char errfeat; 54 unsigned char scnt; 55 unsigned char cmdstat; 56 unsigned char lba0; 57 unsigned char lba1; 58 unsigned char lba2; 59 unsigned char lba3; 60 unsigned char lba4; 61 unsigned char lba5; 62 unsigned char res[2]; 63 }; 64 65 struct aoe_cfghdr { 66 __be16 bufcnt; 67 __be16 fwver; 68 unsigned char scnt; 69 unsigned char aoeccmd; 70 unsigned char cslen[2]; 71 }; 72 73 enum { 74 DEVFL_UP = 1, /* device is installed in system and ready for AoE->ATA commands */ 75 DEVFL_TKILL = (1<<1), /* flag for timer to know when to kill self */ 76 DEVFL_EXT = (1<<2), /* device accepts lba48 commands */ 77 DEVFL_GDALLOC = (1<<3), /* need to alloc gendisk */ 78 DEVFL_GD_NOW = (1<<4), /* allocating gendisk */ 79 DEVFL_KICKME = (1<<5), /* slow polling network card catch */ 80 DEVFL_NEWSIZE = (1<<6), /* need to update dev size in block layer */ 81 DEVFL_FREEING = (1<<7), /* set when device is being cleaned up */ 82 DEVFL_FREED = (1<<8), /* device has been cleaned up */ 83 }; 84 85 enum { 86 DEFAULTBCNT = 2 * 512, /* 2 sectors */ 87 MIN_BUFS = 16, 88 NTARGETS = 4, 89 NAOEIFS = 8, 90 NSKBPOOLMAX = 256, 91 NFACTIVE = 61, 92 93 TIMERTICK = HZ / 10, 94 RTTSCALE = 8, 95 RTTDSCALE = 3, 96 RTTAVG_INIT = USEC_PER_SEC / 4 << RTTSCALE, 97 RTTDEV_INIT = RTTAVG_INIT / 4, 98 99 HARD_SCORN_SECS = 10, /* try another remote port after this */ 100 MAX_TAINT = 1000, /* cap on aoetgt taint */ 101 }; 102 103 struct buf { 104 ulong nframesout; 105 struct bio *bio; 106 struct bvec_iter iter; 107 struct request *rq; 108 }; 109 110 enum frame_flags { 111 FFL_PROBE = 1, 112 }; 113 114 struct frame { 115 struct list_head head; 116 u32 tag; 117 ktime_t sent; /* high-res time packet was sent */ 118 ulong waited; 119 ulong waited_total; 120 struct aoetgt *t; /* parent target I belong to */ 121 struct sk_buff *skb; /* command skb freed on module exit */ 122 struct sk_buff *r_skb; /* response skb for async processing */ 123 struct buf *buf; 124 struct bvec_iter iter; 125 char flags; 126 }; 127 128 struct aoeif { 129 struct net_device *nd; 130 ulong lost; 131 int bcnt; 132 }; 133 134 struct aoetgt { 135 unsigned char addr[6]; 136 ushort nframes; /* cap on frames to use */ 137 struct aoedev *d; /* parent device I belong to */ 138 struct list_head ffree; /* list of free frames */ 139 struct aoeif ifs[NAOEIFS]; 140 struct aoeif *ifp; /* current aoeif in use */ 141 ushort nout; /* number of AoE commands outstanding */ 142 ushort maxout; /* current value for max outstanding */ 143 ushort next_cwnd; /* incr maxout after decrementing to zero */ 144 ushort ssthresh; /* slow start threshold */ 145 ulong falloc; /* number of allocated frames */ 146 int taint; /* how much we want to avoid this aoetgt */ 147 int minbcnt; 148 int wpkts, rpkts; 149 char nout_probes; 150 }; 151 152 struct aoedev { 153 struct aoedev *next; 154 ulong sysminor; 155 ulong aoemajor; 156 u32 rttavg; /* scaled AoE round trip time average */ 157 u32 rttdev; /* scaled round trip time mean deviation */ 158 u16 aoeminor; 159 u16 flags; 160 u16 nopen; /* (bd_openers isn't available without sleeping) */ 161 u16 fw_ver; /* version of blade's firmware */ 162 u16 lasttag; /* last tag sent */ 163 u16 useme; 164 ulong ref; 165 struct work_struct work;/* disk create work struct */ 166 struct gendisk *gd; 167 struct dentry *debugfs; 168 struct request_queue *blkq; 169 struct list_head rq_list; 170 struct blk_mq_tag_set tag_set; 171 struct hd_geometry geo; 172 sector_t ssize; 173 struct timer_list timer; 174 spinlock_t lock; 175 struct sk_buff_head skbpool; 176 mempool_t *bufpool; /* for deadlock-free Buf allocation */ 177 struct { /* pointers to work in progress */ 178 struct buf *buf; 179 struct bio *nxbio; 180 struct request *rq; 181 } ip; 182 ulong maxbcnt; 183 struct list_head factive[NFACTIVE]; /* hash of active frames */ 184 struct list_head rexmitq; /* deferred retransmissions */ 185 struct aoetgt **targets; 186 ulong ntargets; /* number of allocated aoetgt pointers */ 187 struct aoetgt **tgt; /* target in use when working */ 188 ulong kicked; 189 char ident[512]; 190 }; 191 192 /* kthread tracking */ 193 struct ktstate { 194 struct completion rendez; 195 struct task_struct *task; 196 wait_queue_head_t *waitq; 197 int (*fn) (int); 198 char name[12]; 199 spinlock_t *lock; 200 int id; 201 int active; 202 }; 203 204 int aoeblk_init(void); 205 void aoeblk_exit(void); 206 void aoeblk_gdalloc(void *); 207 void aoedisk_rm_debugfs(struct aoedev *d); 208 209 int aoechr_init(void); 210 void aoechr_exit(void); 211 void aoechr_error(char *); 212 213 void aoecmd_work(struct aoedev *d); 214 void aoecmd_cfg(ushort aoemajor, unsigned char aoeminor); 215 struct sk_buff *aoecmd_ata_rsp(struct sk_buff *); 216 void aoecmd_cfg_rsp(struct sk_buff *); 217 void aoecmd_sleepwork(struct work_struct *); 218 void aoecmd_wreset(struct aoetgt *t); 219 void aoecmd_cleanslate(struct aoedev *); 220 void aoecmd_exit(void); 221 int aoecmd_init(void); 222 struct sk_buff *aoecmd_ata_id(struct aoedev *); 223 void aoe_freetframe(struct frame *); 224 void aoe_flush_iocq(void); 225 void aoe_flush_iocq_by_index(int); 226 void aoe_end_request(struct aoedev *, struct request *, int); 227 int aoe_ktstart(struct ktstate *k); 228 void aoe_ktstop(struct ktstate *k); 229 230 int aoedev_init(void); 231 void aoedev_exit(void); 232 struct aoedev *aoedev_by_aoeaddr(ulong maj, int min, int do_alloc); 233 void aoedev_downdev(struct aoedev *d); 234 int aoedev_flush(const char __user *str, size_t size); 235 void aoe_failbuf(struct aoedev *, struct buf *); 236 void aoedev_put(struct aoedev *); 237 238 int aoenet_init(void); 239 void aoenet_exit(void); 240 void aoenet_xmit(struct sk_buff_head *); 241 int is_aoe_netif(struct net_device *ifp); 242 int set_aoe_iflist(const char __user *str, size_t size); 243