aoe.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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. };
  72. enum {
  73. DEFAULTBCNT = 2 * 512, /* 2 sectors */
  74. MIN_BUFS = 16,
  75. NTARGETS = 4,
  76. NAOEIFS = 8,
  77. NSKBPOOLMAX = 256,
  78. NFACTIVE = 61,
  79. TIMERTICK = HZ / 10,
  80. RTTSCALE = 8,
  81. RTTDSCALE = 3,
  82. RTTAVG_INIT = USEC_PER_SEC / 4 << RTTSCALE,
  83. RTTDEV_INIT = RTTAVG_INIT / 4,
  84. HARD_SCORN_SECS = 10, /* try another remote port after this */
  85. MAX_TAINT = 1000, /* cap on aoetgt taint */
  86. };
  87. struct aoe_req {
  88. unsigned long nr_bios;
  89. };
  90. struct buf {
  91. ulong nframesout;
  92. struct bio *bio;
  93. struct bvec_iter iter;
  94. struct request *rq;
  95. };
  96. enum frame_flags {
  97. FFL_PROBE = 1,
  98. };
  99. struct frame {
  100. struct list_head head;
  101. u32 tag;
  102. ktime_t sent; /* high-res time packet was sent */
  103. ulong waited;
  104. ulong waited_total;
  105. struct aoetgt *t; /* parent target I belong to */
  106. struct sk_buff *skb; /* command skb freed on module exit */
  107. struct sk_buff *r_skb; /* response skb for async processing */
  108. struct buf *buf;
  109. struct bvec_iter iter;
  110. char flags;
  111. };
  112. struct aoeif {
  113. struct net_device *nd;
  114. ulong lost;
  115. int bcnt;
  116. };
  117. struct aoetgt {
  118. unsigned char addr[6];
  119. ushort nframes; /* cap on frames to use */
  120. struct aoedev *d; /* parent device I belong to */
  121. struct list_head ffree; /* list of free frames */
  122. struct aoeif ifs[NAOEIFS];
  123. struct aoeif *ifp; /* current aoeif in use */
  124. ushort nout; /* number of AoE commands outstanding */
  125. ushort maxout; /* current value for max outstanding */
  126. ushort next_cwnd; /* incr maxout after decrementing to zero */
  127. ushort ssthresh; /* slow start threshold */
  128. ulong falloc; /* number of allocated frames */
  129. int taint; /* how much we want to avoid this aoetgt */
  130. int minbcnt;
  131. int wpkts, rpkts;
  132. char nout_probes;
  133. };
  134. struct aoedev {
  135. struct aoedev *next;
  136. ulong sysminor;
  137. ulong aoemajor;
  138. u32 rttavg; /* scaled AoE round trip time average */
  139. u32 rttdev; /* scaled round trip time mean deviation */
  140. u16 aoeminor;
  141. u16 flags;
  142. u16 nopen; /* (bd_openers isn't available without sleeping) */
  143. u16 fw_ver; /* version of blade's firmware */
  144. u16 lasttag; /* last tag sent */
  145. u16 useme;
  146. ulong ref;
  147. struct work_struct work;/* disk create work struct */
  148. struct gendisk *gd;
  149. struct dentry *debugfs;
  150. struct request_queue *blkq;
  151. struct list_head rq_list;
  152. struct blk_mq_tag_set tag_set;
  153. struct hd_geometry geo;
  154. sector_t ssize;
  155. struct timer_list timer;
  156. spinlock_t lock;
  157. struct sk_buff_head skbpool;
  158. mempool_t *bufpool; /* for deadlock-free Buf allocation */
  159. struct { /* pointers to work in progress */
  160. struct buf *buf;
  161. struct bio *nxbio;
  162. struct request *rq;
  163. } ip;
  164. ulong maxbcnt;
  165. struct list_head factive[NFACTIVE]; /* hash of active frames */
  166. struct list_head rexmitq; /* deferred retransmissions */
  167. struct aoetgt **targets;
  168. ulong ntargets; /* number of allocated aoetgt pointers */
  169. struct aoetgt **tgt; /* target in use when working */
  170. ulong kicked;
  171. char ident[512];
  172. };
  173. /* kthread tracking */
  174. struct ktstate {
  175. struct completion rendez;
  176. struct task_struct *task;
  177. wait_queue_head_t *waitq;
  178. int (*fn) (int);
  179. char name[12];
  180. spinlock_t *lock;
  181. int id;
  182. int active;
  183. };
  184. int aoeblk_init(void);
  185. void aoeblk_exit(void);
  186. void aoeblk_gdalloc(void *);
  187. void aoedisk_rm_debugfs(struct aoedev *d);
  188. int aoechr_init(void);
  189. void aoechr_exit(void);
  190. void aoechr_error(char *);
  191. void aoecmd_work(struct aoedev *d);
  192. void aoecmd_cfg(ushort aoemajor, unsigned char aoeminor);
  193. struct sk_buff *aoecmd_ata_rsp(struct sk_buff *);
  194. void aoecmd_cfg_rsp(struct sk_buff *);
  195. void aoecmd_sleepwork(struct work_struct *);
  196. void aoecmd_wreset(struct aoetgt *t);
  197. void aoecmd_cleanslate(struct aoedev *);
  198. void aoecmd_exit(void);
  199. int aoecmd_init(void);
  200. struct sk_buff *aoecmd_ata_id(struct aoedev *);
  201. void aoe_freetframe(struct frame *);
  202. void aoe_flush_iocq(void);
  203. void aoe_flush_iocq_by_index(int);
  204. void aoe_end_request(struct aoedev *, struct request *, int);
  205. int aoe_ktstart(struct ktstate *k);
  206. void aoe_ktstop(struct ktstate *k);
  207. int aoedev_init(void);
  208. void aoedev_exit(void);
  209. struct aoedev *aoedev_by_aoeaddr(ulong maj, int min, int do_alloc);
  210. void aoedev_downdev(struct aoedev *d);
  211. int aoedev_flush(const char __user *str, size_t size);
  212. void aoe_failbuf(struct aoedev *, struct buf *);
  213. void aoedev_put(struct aoedev *);
  214. int aoenet_init(void);
  215. void aoenet_exit(void);
  216. void aoenet_xmit(struct sk_buff_head *);
  217. int is_aoe_netif(struct net_device *ifp);
  218. int set_aoe_iflist(const char __user *str, size_t size);
  219. extern struct workqueue_struct *aoe_wq;