aoe.h 6.1 KB

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