sclp_sdias.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. /*
  2. * Sclp "store data in absolut storage"
  3. *
  4. * Copyright IBM Corp. 2003,2007
  5. * Author(s): Michael Holzheu
  6. */
  7. #include <linux/sched.h>
  8. #include <asm/sclp.h>
  9. #include <asm/debug.h>
  10. #include <asm/ipl.h>
  11. #include "sclp.h"
  12. #include "sclp_rw.h"
  13. #define TRACE(x...) debug_sprintf_event(sdias_dbf, 1, x)
  14. #define ERROR_MSG(x...) printk ( KERN_ALERT "SDIAS: " x )
  15. #define SDIAS_RETRIES 300
  16. #define SDIAS_SLEEP_TICKS 50
  17. #define EQ_STORE_DATA 0x0
  18. #define EQ_SIZE 0x1
  19. #define DI_FCP_DUMP 0x0
  20. #define ASA_SIZE_32 0x0
  21. #define ASA_SIZE_64 0x1
  22. #define EVSTATE_ALL_STORED 0x0
  23. #define EVSTATE_NO_DATA 0x3
  24. #define EVSTATE_PART_STORED 0x10
  25. static struct debug_info *sdias_dbf;
  26. static struct sclp_register sclp_sdias_register = {
  27. .send_mask = EVTYP_SDIAS_MASK,
  28. };
  29. struct sdias_evbuf {
  30. struct evbuf_header hdr;
  31. u8 event_qual;
  32. u8 data_id;
  33. u64 reserved2;
  34. u32 event_id;
  35. u16 reserved3;
  36. u8 asa_size;
  37. u8 event_status;
  38. u32 reserved4;
  39. u32 blk_cnt;
  40. u64 asa;
  41. u32 reserved5;
  42. u32 fbn;
  43. u32 reserved6;
  44. u32 lbn;
  45. u16 reserved7;
  46. u16 dbs;
  47. } __attribute__((packed));
  48. struct sdias_sccb {
  49. struct sccb_header hdr;
  50. struct sdias_evbuf evbuf;
  51. } __attribute__((packed));
  52. static struct sdias_sccb sccb __attribute__((aligned(4096)));
  53. static int sclp_req_done;
  54. static wait_queue_head_t sdias_wq;
  55. static DEFINE_MUTEX(sdias_mutex);
  56. static void sdias_callback(struct sclp_req *request, void *data)
  57. {
  58. struct sdias_sccb *cbsccb;
  59. cbsccb = (struct sdias_sccb *) request->sccb;
  60. sclp_req_done = 1;
  61. wake_up(&sdias_wq); /* Inform caller, that request is complete */
  62. TRACE("callback done\n");
  63. }
  64. static int sdias_sclp_send(struct sclp_req *req)
  65. {
  66. int retries;
  67. int rc;
  68. for (retries = SDIAS_RETRIES; retries; retries--) {
  69. sclp_req_done = 0;
  70. TRACE("add request\n");
  71. rc = sclp_add_request(req);
  72. if (rc) {
  73. /* not initiated, wait some time and retry */
  74. set_current_state(TASK_INTERRUPTIBLE);
  75. TRACE("add request failed: rc = %i\n",rc);
  76. schedule_timeout(SDIAS_SLEEP_TICKS);
  77. continue;
  78. }
  79. /* initiated, wait for completion of service call */
  80. wait_event(sdias_wq, (sclp_req_done == 1));
  81. if (req->status == SCLP_REQ_FAILED) {
  82. TRACE("sclp request failed\n");
  83. rc = -EIO;
  84. continue;
  85. }
  86. TRACE("request done\n");
  87. break;
  88. }
  89. return rc;
  90. }
  91. /*
  92. * Get number of blocks (4K) available in the HSA
  93. */
  94. int sclp_sdias_blk_count(void)
  95. {
  96. struct sclp_req request;
  97. int rc;
  98. mutex_lock(&sdias_mutex);
  99. memset(&sccb, 0, sizeof(sccb));
  100. memset(&request, 0, sizeof(request));
  101. sccb.hdr.length = sizeof(sccb);
  102. sccb.evbuf.hdr.length = sizeof(struct sdias_evbuf);
  103. sccb.evbuf.hdr.type = EVTYP_SDIAS;
  104. sccb.evbuf.event_qual = EQ_SIZE;
  105. sccb.evbuf.data_id = DI_FCP_DUMP;
  106. sccb.evbuf.event_id = 4712;
  107. sccb.evbuf.dbs = 1;
  108. request.sccb = &sccb;
  109. request.command = SCLP_CMDW_WRITE_EVENT_DATA;
  110. request.status = SCLP_REQ_FILLED;
  111. request.callback = sdias_callback;
  112. rc = sdias_sclp_send(&request);
  113. if (rc) {
  114. ERROR_MSG("sclp_send failed for get_nr_blocks\n");
  115. goto out;
  116. }
  117. if (sccb.hdr.response_code != 0x0020) {
  118. TRACE("send failed: %x\n", sccb.hdr.response_code);
  119. rc = -EIO;
  120. goto out;
  121. }
  122. switch (sccb.evbuf.event_status) {
  123. case 0:
  124. rc = sccb.evbuf.blk_cnt;
  125. break;
  126. default:
  127. ERROR_MSG("SCLP error: %x\n", 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. ERROR_MSG("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. ERROR_MSG("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. }