sclp_sdias.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. /*
  2. * SCLP "store data in absolute storage"
  3. *
  4. * Copyright IBM Corp. 2003, 2013
  5. * Author(s): Michael Holzheu
  6. */
  7. #define KMSG_COMPONENT "sclp_sdias"
  8. #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
  9. #include <linux/completion.h>
  10. #include <linux/sched.h>
  11. #include <asm/sclp.h>
  12. #include <asm/debug.h>
  13. #include <asm/ipl.h>
  14. #include "sclp_sdias.h"
  15. #include "sclp.h"
  16. #include "sclp_rw.h"
  17. #define TRACE(x...) debug_sprintf_event(sdias_dbf, 1, x)
  18. #define SDIAS_RETRIES 300
  19. static struct debug_info *sdias_dbf;
  20. static struct sclp_register sclp_sdias_register = {
  21. .send_mask = EVTYP_SDIAS_MASK,
  22. };
  23. static struct sdias_sccb sccb __attribute__((aligned(4096)));
  24. static struct sdias_evbuf sdias_evbuf;
  25. static DECLARE_COMPLETION(evbuf_accepted);
  26. static DECLARE_COMPLETION(evbuf_done);
  27. static DEFINE_MUTEX(sdias_mutex);
  28. /*
  29. * Called by SCLP base when read event data has been completed (async mode only)
  30. */
  31. static void sclp_sdias_receiver_fn(struct evbuf_header *evbuf)
  32. {
  33. memcpy(&sdias_evbuf, evbuf,
  34. min_t(unsigned long, sizeof(sdias_evbuf), evbuf->length));
  35. complete(&evbuf_done);
  36. TRACE("sclp_sdias_receiver_fn done\n");
  37. }
  38. /*
  39. * Called by SCLP base when sdias event has been accepted
  40. */
  41. static void sdias_callback(struct sclp_req *request, void *data)
  42. {
  43. complete(&evbuf_accepted);
  44. TRACE("callback done\n");
  45. }
  46. static int sdias_sclp_send(struct sclp_req *req)
  47. {
  48. int retries;
  49. int rc;
  50. for (retries = SDIAS_RETRIES; retries; retries--) {
  51. TRACE("add request\n");
  52. rc = sclp_add_request(req);
  53. if (rc) {
  54. /* not initiated, wait some time and retry */
  55. set_current_state(TASK_INTERRUPTIBLE);
  56. TRACE("add request failed: rc = %i\n",rc);
  57. schedule_timeout(msecs_to_jiffies(500));
  58. continue;
  59. }
  60. /* initiated, wait for completion of service call */
  61. wait_for_completion(&evbuf_accepted);
  62. if (req->status == SCLP_REQ_FAILED) {
  63. TRACE("sclp request failed\n");
  64. continue;
  65. }
  66. /* if not accepted, retry */
  67. if (!(sccb.evbuf.hdr.flags & 0x80)) {
  68. TRACE("sclp request failed: flags=%x\n",
  69. sccb.evbuf.hdr.flags);
  70. continue;
  71. }
  72. /*
  73. * for the sync interface the response is in the initial sccb
  74. */
  75. if (!sclp_sdias_register.receiver_fn) {
  76. memcpy(&sdias_evbuf, &sccb.evbuf, sizeof(sdias_evbuf));
  77. TRACE("sync request done\n");
  78. return 0;
  79. }
  80. /* otherwise we wait for completion */
  81. wait_for_completion(&evbuf_done);
  82. TRACE("request done\n");
  83. return 0;
  84. }
  85. return -EIO;
  86. }
  87. /*
  88. * Get number of blocks (4K) available in the HSA
  89. */
  90. int sclp_sdias_blk_count(void)
  91. {
  92. struct sclp_req request;
  93. int rc;
  94. mutex_lock(&sdias_mutex);
  95. memset(&sccb, 0, sizeof(sccb));
  96. memset(&request, 0, sizeof(request));
  97. sccb.hdr.length = sizeof(sccb);
  98. sccb.evbuf.hdr.length = sizeof(struct sdias_evbuf);
  99. sccb.evbuf.hdr.type = EVTYP_SDIAS;
  100. sccb.evbuf.event_qual = SDIAS_EQ_SIZE;
  101. sccb.evbuf.data_id = SDIAS_DI_FCP_DUMP;
  102. sccb.evbuf.event_id = 4712;
  103. sccb.evbuf.dbs = 1;
  104. request.sccb = &sccb;
  105. request.command = SCLP_CMDW_WRITE_EVENT_DATA;
  106. request.status = SCLP_REQ_FILLED;
  107. request.callback = sdias_callback;
  108. rc = sdias_sclp_send(&request);
  109. if (rc) {
  110. pr_err("sclp_send failed for get_nr_blocks\n");
  111. goto out;
  112. }
  113. if (sccb.hdr.response_code != 0x0020) {
  114. TRACE("send failed: %x\n", sccb.hdr.response_code);
  115. rc = -EIO;
  116. goto out;
  117. }
  118. switch (sdias_evbuf.event_status) {
  119. case 0:
  120. rc = sdias_evbuf.blk_cnt;
  121. break;
  122. default:
  123. pr_err("SCLP error: %x\n", sdias_evbuf.event_status);
  124. rc = -EIO;
  125. goto out;
  126. }
  127. TRACE("%i blocks\n", rc);
  128. out:
  129. mutex_unlock(&sdias_mutex);
  130. return rc;
  131. }
  132. /*
  133. * Copy from HSA to absolute storage (not reentrant):
  134. *
  135. * @dest : Address of buffer where data should be copied
  136. * @start_blk: Start Block (beginning with 1)
  137. * @nr_blks : Number of 4K blocks to copy
  138. *
  139. * Return Value: 0 : Requested 'number' of blocks of data copied
  140. * <0: ERROR - negative event status
  141. */
  142. int sclp_sdias_copy(void *dest, int start_blk, int nr_blks)
  143. {
  144. struct sclp_req request;
  145. int rc;
  146. mutex_lock(&sdias_mutex);
  147. memset(&sccb, 0, sizeof(sccb));
  148. memset(&request, 0, sizeof(request));
  149. sccb.hdr.length = sizeof(sccb);
  150. sccb.evbuf.hdr.length = sizeof(struct sdias_evbuf);
  151. sccb.evbuf.hdr.type = EVTYP_SDIAS;
  152. sccb.evbuf.hdr.flags = 0;
  153. sccb.evbuf.event_qual = SDIAS_EQ_STORE_DATA;
  154. sccb.evbuf.data_id = SDIAS_DI_FCP_DUMP;
  155. sccb.evbuf.event_id = 4712;
  156. sccb.evbuf.asa_size = SDIAS_ASA_SIZE_64;
  157. sccb.evbuf.event_status = 0;
  158. sccb.evbuf.blk_cnt = nr_blks;
  159. sccb.evbuf.asa = (unsigned long)dest;
  160. sccb.evbuf.fbn = start_blk;
  161. sccb.evbuf.lbn = 0;
  162. sccb.evbuf.dbs = 1;
  163. request.sccb = &sccb;
  164. request.command = SCLP_CMDW_WRITE_EVENT_DATA;
  165. request.status = SCLP_REQ_FILLED;
  166. request.callback = sdias_callback;
  167. rc = sdias_sclp_send(&request);
  168. if (rc) {
  169. pr_err("sclp_send failed: %x\n", rc);
  170. goto out;
  171. }
  172. if (sccb.hdr.response_code != 0x0020) {
  173. TRACE("copy failed: %x\n", sccb.hdr.response_code);
  174. rc = -EIO;
  175. goto out;
  176. }
  177. switch (sdias_evbuf.event_status) {
  178. case SDIAS_EVSTATE_ALL_STORED:
  179. TRACE("all stored\n");
  180. break;
  181. case SDIAS_EVSTATE_PART_STORED:
  182. TRACE("part stored: %i\n", sdias_evbuf.blk_cnt);
  183. break;
  184. case SDIAS_EVSTATE_NO_DATA:
  185. TRACE("no data\n");
  186. /* fall through */
  187. default:
  188. pr_err("Error from SCLP while copying hsa. Event status = %x\n",
  189. sdias_evbuf.event_status);
  190. rc = -EIO;
  191. }
  192. out:
  193. mutex_unlock(&sdias_mutex);
  194. return rc;
  195. }
  196. static int __init sclp_sdias_register_check(void)
  197. {
  198. int rc;
  199. rc = sclp_register(&sclp_sdias_register);
  200. if (rc)
  201. return rc;
  202. if (sclp_sdias_blk_count() == 0) {
  203. sclp_unregister(&sclp_sdias_register);
  204. return -ENODEV;
  205. }
  206. return 0;
  207. }
  208. static int __init sclp_sdias_init_sync(void)
  209. {
  210. TRACE("Try synchronous mode\n");
  211. sclp_sdias_register.receive_mask = 0;
  212. sclp_sdias_register.receiver_fn = NULL;
  213. return sclp_sdias_register_check();
  214. }
  215. static int __init sclp_sdias_init_async(void)
  216. {
  217. TRACE("Try asynchronous mode\n");
  218. sclp_sdias_register.receive_mask = EVTYP_SDIAS_MASK;
  219. sclp_sdias_register.receiver_fn = sclp_sdias_receiver_fn;
  220. return sclp_sdias_register_check();
  221. }
  222. int __init sclp_sdias_init(void)
  223. {
  224. if (ipl_info.type != IPL_TYPE_FCP_DUMP)
  225. return 0;
  226. sdias_dbf = debug_register("dump_sdias", 4, 1, 4 * sizeof(long));
  227. debug_register_view(sdias_dbf, &debug_sprintf_view);
  228. debug_set_level(sdias_dbf, 6);
  229. if (sclp_sdias_init_sync() == 0)
  230. goto out;
  231. if (sclp_sdias_init_async() == 0)
  232. goto out;
  233. TRACE("init failed\n");
  234. return -ENODEV;
  235. out:
  236. TRACE("init done\n");
  237. return 0;
  238. }
  239. void __exit sclp_sdias_exit(void)
  240. {
  241. debug_unregister(sdias_dbf);
  242. sclp_unregister(&sclp_sdias_register);
  243. }