sclp_sdias.c 7.0 KB

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