sclp_sdias.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. /*
  2. * Sclp "store data in absolut storage"
  3. *
  4. * Copyright IBM Corp. 2003,2007
  5. * Author(s): Michael Holzheu
  6. */
  7. #define KMSG_COMPONENT "sclp_sdias"
  8. #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
  9. #include <linux/sched.h>
  10. #include <asm/sclp.h>
  11. #include <asm/debug.h>
  12. #include <asm/ipl.h>
  13. #include "sclp.h"
  14. #include "sclp_rw.h"
  15. #define TRACE(x...) debug_sprintf_event(sdias_dbf, 1, x)
  16. #define SDIAS_RETRIES 300
  17. #define SDIAS_SLEEP_TICKS 50
  18. #define EQ_STORE_DATA 0x0
  19. #define EQ_SIZE 0x1
  20. #define DI_FCP_DUMP 0x0
  21. #define ASA_SIZE_32 0x0
  22. #define ASA_SIZE_64 0x1
  23. #define EVSTATE_ALL_STORED 0x0
  24. #define EVSTATE_NO_DATA 0x3
  25. #define EVSTATE_PART_STORED 0x10
  26. static struct debug_info *sdias_dbf;
  27. static struct sclp_register sclp_sdias_register = {
  28. .send_mask = EVTYP_SDIAS_MASK,
  29. };
  30. struct sdias_evbuf {
  31. struct evbuf_header hdr;
  32. u8 event_qual;
  33. u8 data_id;
  34. u64 reserved2;
  35. u32 event_id;
  36. u16 reserved3;
  37. u8 asa_size;
  38. u8 event_status;
  39. u32 reserved4;
  40. u32 blk_cnt;
  41. u64 asa;
  42. u32 reserved5;
  43. u32 fbn;
  44. u32 reserved6;
  45. u32 lbn;
  46. u16 reserved7;
  47. u16 dbs;
  48. } __attribute__((packed));
  49. struct sdias_sccb {
  50. struct sccb_header hdr;
  51. struct sdias_evbuf evbuf;
  52. } __attribute__((packed));
  53. static struct sdias_sccb sccb __attribute__((aligned(4096)));
  54. static int sclp_req_done;
  55. static wait_queue_head_t sdias_wq;
  56. static DEFINE_MUTEX(sdias_mutex);
  57. static void sdias_callback(struct sclp_req *request, void *data)
  58. {
  59. struct sdias_sccb *cbsccb;
  60. cbsccb = (struct sdias_sccb *) request->sccb;
  61. sclp_req_done = 1;
  62. wake_up(&sdias_wq); /* Inform caller, that request is complete */
  63. TRACE("callback done\n");
  64. }
  65. static int sdias_sclp_send(struct sclp_req *req)
  66. {
  67. int retries;
  68. int rc;
  69. for (retries = SDIAS_RETRIES; retries; retries--) {
  70. sclp_req_done = 0;
  71. TRACE("add request\n");
  72. rc = sclp_add_request(req);
  73. if (rc) {
  74. /* not initiated, wait some time and retry */
  75. set_current_state(TASK_INTERRUPTIBLE);
  76. TRACE("add request failed: rc = %i\n",rc);
  77. schedule_timeout(SDIAS_SLEEP_TICKS);
  78. continue;
  79. }
  80. /* initiated, wait for completion of service call */
  81. wait_event(sdias_wq, (sclp_req_done == 1));
  82. if (req->status == SCLP_REQ_FAILED) {
  83. TRACE("sclp request failed\n");
  84. rc = -EIO;
  85. continue;
  86. }
  87. TRACE("request done\n");
  88. break;
  89. }
  90. return rc;
  91. }
  92. /*
  93. * Get number of blocks (4K) available in the HSA
  94. */
  95. int sclp_sdias_blk_count(void)
  96. {
  97. struct sclp_req request;
  98. int rc;
  99. mutex_lock(&sdias_mutex);
  100. memset(&sccb, 0, sizeof(sccb));
  101. memset(&request, 0, sizeof(request));
  102. sccb.hdr.length = sizeof(sccb);
  103. sccb.evbuf.hdr.length = sizeof(struct sdias_evbuf);
  104. sccb.evbuf.hdr.type = EVTYP_SDIAS;
  105. sccb.evbuf.event_qual = EQ_SIZE;
  106. sccb.evbuf.data_id = DI_FCP_DUMP;
  107. sccb.evbuf.event_id = 4712;
  108. sccb.evbuf.dbs = 1;
  109. request.sccb = &sccb;
  110. request.command = SCLP_CMDW_WRITE_EVENT_DATA;
  111. request.status = SCLP_REQ_FILLED;
  112. request.callback = sdias_callback;
  113. rc = sdias_sclp_send(&request);
  114. if (rc) {
  115. pr_err("sclp_send failed for get_nr_blocks\n");
  116. goto out;
  117. }
  118. if (sccb.hdr.response_code != 0x0020) {
  119. TRACE("send failed: %x\n", sccb.hdr.response_code);
  120. rc = -EIO;
  121. goto out;
  122. }
  123. switch (sccb.evbuf.event_status) {
  124. case 0:
  125. rc = sccb.evbuf.blk_cnt;
  126. break;
  127. default:
  128. pr_err("SCLP error: %x\n",
  129. sccb.evbuf.event_status);
  130. rc = -EIO;
  131. goto out;
  132. }
  133. TRACE("%i blocks\n", rc);
  134. out:
  135. mutex_unlock(&sdias_mutex);
  136. return rc;
  137. }
  138. /*
  139. * Copy from HSA to absolute storage (not reentrant):
  140. *
  141. * @dest : Address of buffer where data should be copied
  142. * @start_blk: Start Block (beginning with 1)
  143. * @nr_blks : Number of 4K blocks to copy
  144. *
  145. * Return Value: 0 : Requested 'number' of blocks of data copied
  146. * <0: ERROR - negative event status
  147. */
  148. int sclp_sdias_copy(void *dest, int start_blk, int nr_blks)
  149. {
  150. struct sclp_req request;
  151. int rc;
  152. mutex_lock(&sdias_mutex);
  153. memset(&sccb, 0, sizeof(sccb));
  154. memset(&request, 0, sizeof(request));
  155. sccb.hdr.length = sizeof(sccb);
  156. sccb.evbuf.hdr.length = sizeof(struct sdias_evbuf);
  157. sccb.evbuf.hdr.type = EVTYP_SDIAS;
  158. sccb.evbuf.hdr.flags = 0;
  159. sccb.evbuf.event_qual = EQ_STORE_DATA;
  160. sccb.evbuf.data_id = DI_FCP_DUMP;
  161. sccb.evbuf.event_id = 4712;
  162. #ifdef __s390x__
  163. sccb.evbuf.asa_size = ASA_SIZE_64;
  164. #else
  165. sccb.evbuf.asa_size = ASA_SIZE_32;
  166. #endif
  167. sccb.evbuf.event_status = 0;
  168. sccb.evbuf.blk_cnt = nr_blks;
  169. sccb.evbuf.asa = (unsigned long)dest;
  170. sccb.evbuf.fbn = start_blk;
  171. sccb.evbuf.lbn = 0;
  172. sccb.evbuf.dbs = 1;
  173. request.sccb = &sccb;
  174. request.command = SCLP_CMDW_WRITE_EVENT_DATA;
  175. request.status = SCLP_REQ_FILLED;
  176. request.callback = sdias_callback;
  177. rc = sdias_sclp_send(&request);
  178. if (rc) {
  179. pr_err("sclp_send failed: %x\n", rc);
  180. goto out;
  181. }
  182. if (sccb.hdr.response_code != 0x0020) {
  183. TRACE("copy failed: %x\n", sccb.hdr.response_code);
  184. rc = -EIO;
  185. goto out;
  186. }
  187. switch (sccb.evbuf.event_status) {
  188. case EVSTATE_ALL_STORED:
  189. TRACE("all stored\n");
  190. case EVSTATE_PART_STORED:
  191. TRACE("part stored: %i\n", sccb.evbuf.blk_cnt);
  192. break;
  193. case EVSTATE_NO_DATA:
  194. TRACE("no data\n");
  195. default:
  196. pr_err("Error from SCLP while copying hsa. "
  197. "Event status = %x\n",
  198. sccb.evbuf.event_status);
  199. rc = -EIO;
  200. }
  201. out:
  202. mutex_unlock(&sdias_mutex);
  203. return rc;
  204. }
  205. int __init sclp_sdias_init(void)
  206. {
  207. int rc;
  208. if (ipl_info.type != IPL_TYPE_FCP_DUMP)
  209. return 0;
  210. sdias_dbf = debug_register("dump_sdias", 4, 1, 4 * sizeof(long));
  211. debug_register_view(sdias_dbf, &debug_sprintf_view);
  212. debug_set_level(sdias_dbf, 6);
  213. rc = sclp_register(&sclp_sdias_register);
  214. if (rc)
  215. return rc;
  216. init_waitqueue_head(&sdias_wq);
  217. TRACE("init done\n");
  218. return 0;
  219. }
  220. void __exit sclp_sdias_exit(void)
  221. {
  222. debug_unregister(sdias_dbf);
  223. sclp_unregister(&sclp_sdias_register);
  224. }