sclp_sdias.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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. sclp_req_done = 1;
  60. wake_up(&sdias_wq); /* Inform caller, that request is complete */
  61. TRACE("callback done\n");
  62. }
  63. static int sdias_sclp_send(struct sclp_req *req)
  64. {
  65. int retries;
  66. int rc;
  67. for (retries = SDIAS_RETRIES; retries; retries--) {
  68. sclp_req_done = 0;
  69. TRACE("add request\n");
  70. rc = sclp_add_request(req);
  71. if (rc) {
  72. /* not initiated, wait some time and retry */
  73. set_current_state(TASK_INTERRUPTIBLE);
  74. TRACE("add request failed: rc = %i\n",rc);
  75. schedule_timeout(SDIAS_SLEEP_TICKS);
  76. continue;
  77. }
  78. /* initiated, wait for completion of service call */
  79. wait_event(sdias_wq, (sclp_req_done == 1));
  80. if (req->status == SCLP_REQ_FAILED) {
  81. TRACE("sclp request failed\n");
  82. rc = -EIO;
  83. continue;
  84. }
  85. TRACE("request done\n");
  86. break;
  87. }
  88. return rc;
  89. }
  90. /*
  91. * Get number of blocks (4K) available in the HSA
  92. */
  93. int sclp_sdias_blk_count(void)
  94. {
  95. struct sclp_req request;
  96. int rc;
  97. mutex_lock(&sdias_mutex);
  98. memset(&sccb, 0, sizeof(sccb));
  99. memset(&request, 0, sizeof(request));
  100. sccb.hdr.length = sizeof(sccb);
  101. sccb.evbuf.hdr.length = sizeof(struct sdias_evbuf);
  102. sccb.evbuf.hdr.type = EVTYP_SDIAS;
  103. sccb.evbuf.event_qual = EQ_SIZE;
  104. sccb.evbuf.data_id = DI_FCP_DUMP;
  105. sccb.evbuf.event_id = 4712;
  106. sccb.evbuf.dbs = 1;
  107. request.sccb = &sccb;
  108. request.command = SCLP_CMDW_WRITE_EVENT_DATA;
  109. request.status = SCLP_REQ_FILLED;
  110. request.callback = sdias_callback;
  111. rc = sdias_sclp_send(&request);
  112. if (rc) {
  113. pr_err("sclp_send failed for get_nr_blocks\n");
  114. goto out;
  115. }
  116. if (sccb.hdr.response_code != 0x0020) {
  117. TRACE("send failed: %x\n", sccb.hdr.response_code);
  118. rc = -EIO;
  119. goto out;
  120. }
  121. switch (sccb.evbuf.event_status) {
  122. case 0:
  123. rc = sccb.evbuf.blk_cnt;
  124. break;
  125. default:
  126. pr_err("SCLP error: %x\n",
  127. sccb.evbuf.event_status);
  128. rc = -EIO;
  129. goto out;
  130. }
  131. TRACE("%i blocks\n", rc);
  132. out:
  133. mutex_unlock(&sdias_mutex);
  134. return rc;
  135. }
  136. /*
  137. * Copy from HSA to absolute storage (not reentrant):
  138. *
  139. * @dest : Address of buffer where data should be copied
  140. * @start_blk: Start Block (beginning with 1)
  141. * @nr_blks : Number of 4K blocks to copy
  142. *
  143. * Return Value: 0 : Requested 'number' of blocks of data copied
  144. * <0: ERROR - negative event status
  145. */
  146. int sclp_sdias_copy(void *dest, int start_blk, int nr_blks)
  147. {
  148. struct sclp_req request;
  149. int rc;
  150. mutex_lock(&sdias_mutex);
  151. memset(&sccb, 0, sizeof(sccb));
  152. memset(&request, 0, sizeof(request));
  153. sccb.hdr.length = sizeof(sccb);
  154. sccb.evbuf.hdr.length = sizeof(struct sdias_evbuf);
  155. sccb.evbuf.hdr.type = EVTYP_SDIAS;
  156. sccb.evbuf.hdr.flags = 0;
  157. sccb.evbuf.event_qual = EQ_STORE_DATA;
  158. sccb.evbuf.data_id = DI_FCP_DUMP;
  159. sccb.evbuf.event_id = 4712;
  160. #ifdef __s390x__
  161. sccb.evbuf.asa_size = ASA_SIZE_64;
  162. #else
  163. sccb.evbuf.asa_size = ASA_SIZE_32;
  164. #endif
  165. sccb.evbuf.event_status = 0;
  166. sccb.evbuf.blk_cnt = nr_blks;
  167. sccb.evbuf.asa = (unsigned long)dest;
  168. sccb.evbuf.fbn = start_blk;
  169. sccb.evbuf.lbn = 0;
  170. sccb.evbuf.dbs = 1;
  171. request.sccb = &sccb;
  172. request.command = SCLP_CMDW_WRITE_EVENT_DATA;
  173. request.status = SCLP_REQ_FILLED;
  174. request.callback = sdias_callback;
  175. rc = sdias_sclp_send(&request);
  176. if (rc) {
  177. pr_err("sclp_send failed: %x\n", rc);
  178. goto out;
  179. }
  180. if (sccb.hdr.response_code != 0x0020) {
  181. TRACE("copy failed: %x\n", sccb.hdr.response_code);
  182. rc = -EIO;
  183. goto out;
  184. }
  185. switch (sccb.evbuf.event_status) {
  186. case EVSTATE_ALL_STORED:
  187. TRACE("all stored\n");
  188. case EVSTATE_PART_STORED:
  189. TRACE("part stored: %i\n", sccb.evbuf.blk_cnt);
  190. break;
  191. case EVSTATE_NO_DATA:
  192. TRACE("no data\n");
  193. default:
  194. pr_err("Error from SCLP while copying hsa. "
  195. "Event status = %x\n",
  196. sccb.evbuf.event_status);
  197. rc = -EIO;
  198. }
  199. out:
  200. mutex_unlock(&sdias_mutex);
  201. return rc;
  202. }
  203. int __init sclp_sdias_init(void)
  204. {
  205. int rc;
  206. if (ipl_info.type != IPL_TYPE_FCP_DUMP)
  207. return 0;
  208. sdias_dbf = debug_register("dump_sdias", 4, 1, 4 * sizeof(long));
  209. debug_register_view(sdias_dbf, &debug_sprintf_view);
  210. debug_set_level(sdias_dbf, 6);
  211. rc = sclp_register(&sclp_sdias_register);
  212. if (rc)
  213. return rc;
  214. init_waitqueue_head(&sdias_wq);
  215. TRACE("init done\n");
  216. return 0;
  217. }
  218. void __exit sclp_sdias_exit(void)
  219. {
  220. debug_unregister(sdias_dbf);
  221. sclp_unregister(&sclp_sdias_register);
  222. }