ibmvscsi_tgt.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. /*******************************************************************************
  2. * IBM Virtual SCSI Target Driver
  3. * Copyright (C) 2003-2005 Dave Boutcher (boutcher@us.ibm.com) IBM Corp.
  4. * Santiago Leon (santil@us.ibm.com) IBM Corp.
  5. * Linda Xie (lxie@us.ibm.com) IBM Corp.
  6. *
  7. * Copyright (C) 2005-2011 FUJITA Tomonori <tomof@acm.org>
  8. * Copyright (C) 2010 Nicholas A. Bellinger <nab@kernel.org>
  9. * Copyright (C) 2016 Bryant G. Ly <bryantly@linux.vnet.ibm.com> IBM Corp.
  10. *
  11. * Authors: Bryant G. Ly <bryantly@linux.vnet.ibm.com>
  12. * Authors: Michael Cyr <mikecyr@linux.vnet.ibm.com>
  13. *
  14. * This program is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License as published by
  16. * the Free Software Foundation; either version 2 of the License, or
  17. * (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. ****************************************************************************/
  25. #ifndef __H_IBMVSCSI_TGT
  26. #define __H_IBMVSCSI_TGT
  27. #include "libsrp.h"
  28. #define SYS_ID_NAME_LEN 64
  29. #define PARTITION_NAMELEN 96
  30. #define IBMVSCSIS_NAMELEN 32
  31. #define MSG_HI 0
  32. #define MSG_LOW 1
  33. #define MAX_CMD_Q_PAGES 4
  34. #define CRQ_PER_PAGE (PAGE_SIZE / sizeof(struct viosrp_crq))
  35. /* in terms of number of elements */
  36. #define DEFAULT_CMD_Q_SIZE CRQ_PER_PAGE
  37. #define MAX_CMD_Q_SIZE (DEFAULT_CMD_Q_SIZE * MAX_CMD_Q_PAGES)
  38. #define SRP_VIOLATION 0x102 /* general error code */
  39. /*
  40. * SRP buffer formats defined as of 16.a supported by this driver.
  41. */
  42. #define SUPPORTED_FORMATS ((SRP_DATA_DESC_DIRECT << 1) | \
  43. (SRP_DATA_DESC_INDIRECT << 1))
  44. #define SCSI_LUN_ADDR_METHOD_FLAT 1
  45. struct dma_window {
  46. u32 liobn; /* Unique per vdevice */
  47. u64 tce_base; /* Physical location of the TCE table */
  48. u64 tce_size; /* Size of the TCE table in bytes */
  49. };
  50. struct target_dds {
  51. u64 unit_id; /* 64 bit will force alignment */
  52. #define NUM_DMA_WINDOWS 2
  53. #define LOCAL 0
  54. #define REMOTE 1
  55. struct dma_window window[NUM_DMA_WINDOWS];
  56. /* root node property "ibm,partition-no" */
  57. uint partition_num;
  58. char partition_name[PARTITION_NAMELEN];
  59. };
  60. #define MAX_NUM_PORTS 1
  61. #define MAX_H_COPY_RDMA (128 * 1024)
  62. #define MAX_EYE 64
  63. /* Return codes */
  64. #define ADAPT_SUCCESS 0L
  65. /* choose error codes that do not conflict with PHYP */
  66. #define ERROR -40L
  67. struct format_code {
  68. u8 reserved;
  69. u8 buffers;
  70. };
  71. struct client_info {
  72. #define SRP_VERSION "16.a"
  73. char srp_version[8];
  74. /* root node property ibm,partition-name */
  75. char partition_name[PARTITION_NAMELEN];
  76. /* root node property ibm,partition-no */
  77. u32 partition_number;
  78. /* initially 1 */
  79. u32 mad_version;
  80. u32 os_type;
  81. };
  82. /*
  83. * Changing this constant changes the number of seconds to wait before
  84. * considering the client will never service its queue again.
  85. */
  86. #define SECONDS_TO_CONSIDER_FAILED 30
  87. /*
  88. * These constants set the polling period used to determine if the client
  89. * has freed at least one element in the response queue.
  90. */
  91. #define WAIT_SECONDS 1
  92. #define WAIT_NANO_SECONDS 5000
  93. #define MAX_TIMER_POPS ((1000000 / WAIT_NANO_SECONDS) * \
  94. SECONDS_TO_CONSIDER_FAILED)
  95. /*
  96. * general purpose timer control block
  97. * which can be used for multiple functions
  98. */
  99. struct timer_cb {
  100. struct hrtimer timer;
  101. /*
  102. * how long has it been since the client
  103. * serviced the queue. The variable is incrmented
  104. * in the service_wait_q routine and cleared
  105. * in send messages
  106. */
  107. int timer_pops;
  108. /* the timer is started */
  109. bool started;
  110. };
  111. struct cmd_queue {
  112. /* kva */
  113. struct viosrp_crq *base_addr;
  114. dma_addr_t crq_token;
  115. /* used to maintain index */
  116. uint mask;
  117. /* current element */
  118. uint index;
  119. int size;
  120. };
  121. #define SCSOLNT_RESP_SHIFT 1
  122. #define UCSOLNT_RESP_SHIFT 2
  123. #define SCSOLNT BIT(SCSOLNT_RESP_SHIFT)
  124. #define UCSOLNT BIT(UCSOLNT_RESP_SHIFT)
  125. enum cmd_type {
  126. SCSI_CDB = 0x01,
  127. TASK_MANAGEMENT = 0x02,
  128. /* MAD or addressed to port 0 */
  129. ADAPTER_MAD = 0x04,
  130. UNSET_TYPE = 0x08,
  131. };
  132. struct iu_rsp {
  133. u8 format;
  134. u8 sol_not;
  135. u16 len;
  136. /* tag is just to help client identify cmd, so don't translate be/le */
  137. u64 tag;
  138. };
  139. struct ibmvscsis_cmd {
  140. struct list_head list;
  141. /* Used for TCM Core operations */
  142. struct se_cmd se_cmd;
  143. struct iu_entry *iue;
  144. struct iu_rsp rsp;
  145. struct work_struct work;
  146. struct scsi_info *adapter;
  147. struct ibmvscsis_cmd *abort_cmd;
  148. /* Sense buffer that will be mapped into outgoing status */
  149. unsigned char sense_buf[TRANSPORT_SENSE_BUFFER];
  150. u64 init_time;
  151. #define CMD_FAST_FAIL BIT(0)
  152. #define DELAY_SEND BIT(1)
  153. u32 flags;
  154. char type;
  155. };
  156. struct ibmvscsis_nexus {
  157. struct se_session *se_sess;
  158. };
  159. struct ibmvscsis_tport {
  160. /* SCSI protocol the tport is providing */
  161. u8 tport_proto_id;
  162. /* ASCII formatted WWPN for SRP Target port */
  163. char tport_name[IBMVSCSIS_NAMELEN];
  164. /* Returned by ibmvscsis_make_tport() */
  165. struct se_wwn tport_wwn;
  166. /* Returned by ibmvscsis_make_tpg() */
  167. struct se_portal_group se_tpg;
  168. /* ibmvscsis port target portal group tag for TCM */
  169. u16 tport_tpgt;
  170. /* Pointer to TCM session for I_T Nexus */
  171. struct ibmvscsis_nexus *ibmv_nexus;
  172. bool enabled;
  173. bool releasing;
  174. };
  175. struct scsi_info {
  176. struct list_head list;
  177. char eye[MAX_EYE];
  178. /* commands waiting for space on repsonse queue */
  179. struct list_head waiting_rsp;
  180. #define NO_QUEUE 0x00
  181. #define WAIT_ENABLED 0X01
  182. #define WAIT_CONNECTION 0x04
  183. /* have established a connection */
  184. #define CONNECTED 0x08
  185. /* at least one port is processing SRP IU */
  186. #define SRP_PROCESSING 0x10
  187. /* remove request received */
  188. #define UNCONFIGURING 0x20
  189. /* disconnect by letting adapter go idle, no error */
  190. #define WAIT_IDLE 0x40
  191. /* disconnecting to clear an error */
  192. #define ERR_DISCONNECT 0x80
  193. /* disconnect to clear error state, then come back up */
  194. #define ERR_DISCONNECT_RECONNECT 0x100
  195. /* disconnected after clearing an error */
  196. #define ERR_DISCONNECTED 0x200
  197. /* A series of errors caused unexpected errors */
  198. #define UNDEFINED 0x400
  199. u16 state;
  200. int fast_fail;
  201. struct target_dds dds;
  202. char *cmd_pool;
  203. /* list of free commands */
  204. struct list_head free_cmd;
  205. /* command elements ready for scheduler */
  206. struct list_head schedule_q;
  207. /* commands sent to TCM */
  208. struct list_head active_q;
  209. caddr_t *map_buf;
  210. /* ioba of map buffer */
  211. dma_addr_t map_ioba;
  212. /* allowable number of outstanding SRP requests */
  213. int request_limit;
  214. /* extra credit */
  215. int credit;
  216. /* outstanding transactions against credit limit */
  217. int debit;
  218. /* allow only one outstanding mad request */
  219. #define PROCESSING_MAD 0x00002
  220. /* Waiting to go idle */
  221. #define WAIT_FOR_IDLE 0x00004
  222. /* H_REG_CRQ called */
  223. #define CRQ_CLOSED 0x00010
  224. /* detected that client has failed */
  225. #define CLIENT_FAILED 0x00040
  226. /* detected that transport event occurred */
  227. #define TRANS_EVENT 0x00080
  228. /* don't attempt to send anything to the client */
  229. #define RESPONSE_Q_DOWN 0x00100
  230. /* request made to schedule disconnect handler */
  231. #define SCHEDULE_DISCONNECT 0x00400
  232. /* disconnect handler is scheduled */
  233. #define DISCONNECT_SCHEDULED 0x00800
  234. /* remove function is sleeping */
  235. #define CFG_SLEEPING 0x01000
  236. u32 flags;
  237. /* adapter lock */
  238. spinlock_t intr_lock;
  239. /* information needed to manage command queue */
  240. struct cmd_queue cmd_q;
  241. /* used in hcall to copy response back into srp buffer */
  242. u64 empty_iu_id;
  243. /* used in crq, to tag what iu the response is for */
  244. u64 empty_iu_tag;
  245. uint new_state;
  246. /* control block for the response queue timer */
  247. struct timer_cb rsp_q_timer;
  248. /* keep last client to enable proper accounting */
  249. struct client_info client_data;
  250. /* what can this client do */
  251. u32 client_cap;
  252. /*
  253. * The following two fields capture state and flag changes that
  254. * can occur when the lock is given up. In the orginal design,
  255. * the lock was held during calls into phyp;
  256. * however, phyp did not meet PAPR architecture. This is
  257. * a work around.
  258. */
  259. u16 phyp_acr_state;
  260. u32 phyp_acr_flags;
  261. struct workqueue_struct *work_q;
  262. struct completion wait_idle;
  263. struct completion unconfig;
  264. struct device dev;
  265. struct vio_dev *dma_dev;
  266. struct srp_target target;
  267. struct ibmvscsis_tport tport;
  268. struct tasklet_struct work_task;
  269. struct work_struct proc_work;
  270. };
  271. /*
  272. * Provide a constant that allows software to detect the adapter is
  273. * disconnecting from the client from one of several states.
  274. */
  275. #define IS_DISCONNECTING (UNCONFIGURING | ERR_DISCONNECT_RECONNECT | \
  276. ERR_DISCONNECT)
  277. /*
  278. * Provide a constant that can be used with interrupt handling that
  279. * essentially lets the interrupt handler know that all requests should
  280. * be thrown out,
  281. */
  282. #define DONT_PROCESS_STATE (IS_DISCONNECTING | UNDEFINED | \
  283. ERR_DISCONNECTED | WAIT_IDLE)
  284. /*
  285. * If any of these flag bits are set then do not allow the interrupt
  286. * handler to schedule the off level handler.
  287. */
  288. #define BLOCK (DISCONNECT_SCHEDULED)
  289. /* State and transition events that stop the interrupt handler */
  290. #define TARGET_STOP(VSCSI) (long)(((VSCSI)->state & DONT_PROCESS_STATE) | \
  291. ((VSCSI)->flags & BLOCK))
  292. /* flag bit that are not reset during disconnect */
  293. #define PRESERVE_FLAG_FIELDS 0
  294. #define vio_iu(IUE) ((union viosrp_iu *)((IUE)->sbuf->buf))
  295. #define READ_CMD(cdb) (((cdb)[0] & 0x1F) == 8)
  296. #define WRITE_CMD(cdb) (((cdb)[0] & 0x1F) == 0xA)
  297. #ifndef H_GET_PARTNER_INFO
  298. #define H_GET_PARTNER_INFO 0x0000000000000008LL
  299. #endif
  300. #define h_copy_rdma(l, sa, sb, da, db) \
  301. plpar_hcall_norets(H_COPY_RDMA, l, sa, sb, da, db)
  302. #define h_vioctl(u, o, a, u1, u2, u3, u4) \
  303. plpar_hcall_norets(H_VIOCTL, u, o, a, u1, u2)
  304. #define h_reg_crq(ua, tok, sz) \
  305. plpar_hcall_norets(H_REG_CRQ, ua, tok, sz)
  306. #define h_free_crq(ua) \
  307. plpar_hcall_norets(H_FREE_CRQ, ua)
  308. #define h_send_crq(ua, d1, d2) \
  309. plpar_hcall_norets(H_SEND_CRQ, ua, d1, d2)
  310. #endif