ibmvscsi_tgt.h 11 KB

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