sclp_ftp.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. /*
  2. * SCLP Event Type (ET) 7 - Diagnostic Test FTP Services, useable on LPAR
  3. *
  4. * Copyright IBM Corp. 2013
  5. * Author(s): Ralf Hoppe (rhoppe@de.ibm.com)
  6. *
  7. */
  8. #define KMSG_COMPONENT "hmcdrv"
  9. #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
  10. #include <linux/kernel.h>
  11. #include <linux/mm.h>
  12. #include <linux/slab.h>
  13. #include <linux/io.h>
  14. #include <linux/wait.h>
  15. #include <linux/string.h>
  16. #include <linux/jiffies.h>
  17. #include <asm/sysinfo.h>
  18. #include <asm/ebcdic.h>
  19. #include "sclp.h"
  20. #include "sclp_diag.h"
  21. #include "sclp_ftp.h"
  22. static DECLARE_COMPLETION(sclp_ftp_rx_complete);
  23. static u8 sclp_ftp_ldflg;
  24. static u64 sclp_ftp_fsize;
  25. static u64 sclp_ftp_length;
  26. /**
  27. * sclp_ftp_txcb() - Diagnostic Test FTP services SCLP command callback
  28. */
  29. static void sclp_ftp_txcb(struct sclp_req *req, void *data)
  30. {
  31. struct completion *completion = data;
  32. #ifdef DEBUG
  33. pr_debug("SCLP (ET7) TX-IRQ, SCCB @ 0x%p: %*phN\n",
  34. req->sccb, 24, req->sccb);
  35. #endif
  36. complete(completion);
  37. }
  38. /**
  39. * sclp_ftp_rxcb() - Diagnostic Test FTP services receiver event callback
  40. */
  41. static void sclp_ftp_rxcb(struct evbuf_header *evbuf)
  42. {
  43. struct sclp_diag_evbuf *diag = (struct sclp_diag_evbuf *) evbuf;
  44. /*
  45. * Check for Diagnostic Test FTP Service
  46. */
  47. if (evbuf->type != EVTYP_DIAG_TEST ||
  48. diag->route != SCLP_DIAG_FTP_ROUTE ||
  49. diag->mdd.ftp.pcx != SCLP_DIAG_FTP_XPCX ||
  50. evbuf->length < SCLP_DIAG_FTP_EVBUF_LEN)
  51. return;
  52. #ifdef DEBUG
  53. pr_debug("SCLP (ET7) RX-IRQ, Event @ 0x%p: %*phN\n",
  54. evbuf, 24, evbuf);
  55. #endif
  56. /*
  57. * Because the event buffer is located in a page which is owned
  58. * by the SCLP core, all data of interest must be copied. The
  59. * error indication is in 'sclp_ftp_ldflg'
  60. */
  61. sclp_ftp_ldflg = diag->mdd.ftp.ldflg;
  62. sclp_ftp_fsize = diag->mdd.ftp.fsize;
  63. sclp_ftp_length = diag->mdd.ftp.length;
  64. complete(&sclp_ftp_rx_complete);
  65. }
  66. /**
  67. * sclp_ftp_et7() - start a Diagnostic Test FTP Service SCLP request
  68. * @ftp: pointer to FTP descriptor
  69. *
  70. * Return: 0 on success, else a (negative) error code
  71. */
  72. static int sclp_ftp_et7(const struct hmcdrv_ftp_cmdspec *ftp)
  73. {
  74. struct completion completion;
  75. struct sclp_diag_sccb *sccb;
  76. struct sclp_req *req;
  77. size_t len;
  78. int rc;
  79. req = kzalloc(sizeof(*req), GFP_KERNEL);
  80. sccb = (void *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
  81. if (!req || !sccb) {
  82. rc = -ENOMEM;
  83. goto out_free;
  84. }
  85. sccb->hdr.length = SCLP_DIAG_FTP_EVBUF_LEN +
  86. sizeof(struct sccb_header);
  87. sccb->evbuf.hdr.type = EVTYP_DIAG_TEST;
  88. sccb->evbuf.hdr.length = SCLP_DIAG_FTP_EVBUF_LEN;
  89. sccb->evbuf.hdr.flags = 0; /* clear processed-buffer */
  90. sccb->evbuf.route = SCLP_DIAG_FTP_ROUTE;
  91. sccb->evbuf.mdd.ftp.pcx = SCLP_DIAG_FTP_XPCX;
  92. sccb->evbuf.mdd.ftp.srcflg = 0;
  93. sccb->evbuf.mdd.ftp.pgsize = 0;
  94. sccb->evbuf.mdd.ftp.asce = _ASCE_REAL_SPACE;
  95. sccb->evbuf.mdd.ftp.ldflg = SCLP_DIAG_FTP_LDFAIL;
  96. sccb->evbuf.mdd.ftp.fsize = 0;
  97. sccb->evbuf.mdd.ftp.cmd = ftp->id;
  98. sccb->evbuf.mdd.ftp.offset = ftp->ofs;
  99. sccb->evbuf.mdd.ftp.length = ftp->len;
  100. sccb->evbuf.mdd.ftp.bufaddr = virt_to_phys(ftp->buf);
  101. len = strlcpy(sccb->evbuf.mdd.ftp.fident, ftp->fname,
  102. HMCDRV_FTP_FIDENT_MAX);
  103. if (len >= HMCDRV_FTP_FIDENT_MAX) {
  104. rc = -EINVAL;
  105. goto out_free;
  106. }
  107. req->command = SCLP_CMDW_WRITE_EVENT_DATA;
  108. req->sccb = sccb;
  109. req->status = SCLP_REQ_FILLED;
  110. req->callback = sclp_ftp_txcb;
  111. req->callback_data = &completion;
  112. init_completion(&completion);
  113. rc = sclp_add_request(req);
  114. if (rc)
  115. goto out_free;
  116. /* Wait for end of ftp sclp command. */
  117. wait_for_completion(&completion);
  118. #ifdef DEBUG
  119. pr_debug("status of SCLP (ET7) request is 0x%04x (0x%02x)\n",
  120. sccb->hdr.response_code, sccb->evbuf.hdr.flags);
  121. #endif
  122. /*
  123. * Check if sclp accepted the request. The data transfer runs
  124. * asynchronously and the completion is indicated with an
  125. * sclp ET7 event.
  126. */
  127. if (req->status != SCLP_REQ_DONE ||
  128. (sccb->evbuf.hdr.flags & 0x80) == 0 || /* processed-buffer */
  129. (sccb->hdr.response_code & 0xffU) != 0x20U) {
  130. rc = -EIO;
  131. }
  132. out_free:
  133. free_page((unsigned long) sccb);
  134. kfree(req);
  135. return rc;
  136. }
  137. /**
  138. * sclp_ftp_cmd() - executes a HMC related SCLP Diagnose (ET7) FTP command
  139. * @ftp: pointer to FTP command specification
  140. * @fsize: return of file size (or NULL if undesirable)
  141. *
  142. * Attention: Notice that this function is not reentrant - so the caller
  143. * must ensure locking.
  144. *
  145. * Return: number of bytes read/written or a (negative) error code
  146. */
  147. ssize_t sclp_ftp_cmd(const struct hmcdrv_ftp_cmdspec *ftp, size_t *fsize)
  148. {
  149. ssize_t len;
  150. #ifdef DEBUG
  151. unsigned long start_jiffies;
  152. pr_debug("starting SCLP (ET7), cmd %d for '%s' at %lld with %zd bytes\n",
  153. ftp->id, ftp->fname, (long long) ftp->ofs, ftp->len);
  154. start_jiffies = jiffies;
  155. #endif
  156. init_completion(&sclp_ftp_rx_complete);
  157. /* Start ftp sclp command. */
  158. len = sclp_ftp_et7(ftp);
  159. if (len)
  160. goto out_unlock;
  161. /*
  162. * There is no way to cancel the sclp ET7 request, the code
  163. * needs to wait unconditionally until the transfer is complete.
  164. */
  165. wait_for_completion(&sclp_ftp_rx_complete);
  166. #ifdef DEBUG
  167. pr_debug("completed SCLP (ET7) request after %lu ms (all)\n",
  168. (jiffies - start_jiffies) * 1000 / HZ);
  169. pr_debug("return code of SCLP (ET7) FTP Service is 0x%02x, with %lld/%lld bytes\n",
  170. sclp_ftp_ldflg, sclp_ftp_length, sclp_ftp_fsize);
  171. #endif
  172. switch (sclp_ftp_ldflg) {
  173. case SCLP_DIAG_FTP_OK:
  174. len = sclp_ftp_length;
  175. if (fsize)
  176. *fsize = sclp_ftp_fsize;
  177. break;
  178. case SCLP_DIAG_FTP_LDNPERM:
  179. len = -EPERM;
  180. break;
  181. case SCLP_DIAG_FTP_LDRUNS:
  182. len = -EBUSY;
  183. break;
  184. case SCLP_DIAG_FTP_LDFAIL:
  185. len = -ENOENT;
  186. break;
  187. default:
  188. len = -EIO;
  189. break;
  190. }
  191. out_unlock:
  192. return len;
  193. }
  194. /*
  195. * ET7 event listener
  196. */
  197. static struct sclp_register sclp_ftp_event = {
  198. .send_mask = EVTYP_DIAG_TEST_MASK, /* want tx events */
  199. .receive_mask = EVTYP_DIAG_TEST_MASK, /* want rx events */
  200. .receiver_fn = sclp_ftp_rxcb, /* async callback (rx) */
  201. .state_change_fn = NULL,
  202. .pm_event_fn = NULL,
  203. };
  204. /**
  205. * sclp_ftp_startup() - startup of FTP services, when running on LPAR
  206. */
  207. int sclp_ftp_startup(void)
  208. {
  209. #ifdef DEBUG
  210. unsigned long info;
  211. #endif
  212. int rc;
  213. rc = sclp_register(&sclp_ftp_event);
  214. if (rc)
  215. return rc;
  216. #ifdef DEBUG
  217. info = get_zeroed_page(GFP_KERNEL);
  218. if (info != 0) {
  219. struct sysinfo_2_2_2 *info222 = (struct sysinfo_2_2_2 *)info;
  220. if (!stsi(info222, 2, 2, 2)) { /* get SYSIB 2.2.2 */
  221. info222->name[sizeof(info222->name) - 1] = '\0';
  222. EBCASC_500(info222->name, sizeof(info222->name) - 1);
  223. pr_debug("SCLP (ET7) FTP Service working on LPAR %u (%s)\n",
  224. info222->lpar_number, info222->name);
  225. }
  226. free_page(info);
  227. }
  228. #endif /* DEBUG */
  229. return 0;
  230. }
  231. /**
  232. * sclp_ftp_shutdown() - shutdown of FTP services, when running on LPAR
  233. */
  234. void sclp_ftp_shutdown(void)
  235. {
  236. sclp_unregister(&sclp_ftp_event);
  237. }