dasd_erp.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Author(s)......: Holger Smolinski <Holger.Smolinski@de.ibm.com>
  4. * Horst Hummel <Horst.Hummel@de.ibm.com>
  5. * Carsten Otte <Cotte@de.ibm.com>
  6. * Martin Schwidefsky <schwidefsky@de.ibm.com>
  7. * Bugreports.to..: <Linux390@de.ibm.com>
  8. * Copyright IBM Corp. 1999, 2001
  9. *
  10. */
  11. #include <linux/export.h>
  12. #include <linux/ctype.h>
  13. #include <linux/init.h>
  14. #include <asm/debug.h>
  15. #include <asm/ebcdic.h>
  16. #include <linux/uaccess.h>
  17. #include "dasd_int.h"
  18. struct dasd_ccw_req *
  19. dasd_alloc_erp_request(unsigned int magic, int cplength, int datasize,
  20. struct dasd_device * device)
  21. {
  22. unsigned long flags;
  23. struct dasd_ccw_req *cqr;
  24. char *data;
  25. int size;
  26. /* Sanity checks */
  27. BUG_ON(datasize > PAGE_SIZE ||
  28. (cplength*sizeof(struct ccw1)) > PAGE_SIZE);
  29. size = (sizeof(struct dasd_ccw_req) + 7L) & -8L;
  30. if (cplength > 0)
  31. size += cplength * sizeof(struct ccw1);
  32. if (datasize > 0)
  33. size += datasize;
  34. spin_lock_irqsave(&device->mem_lock, flags);
  35. cqr = (struct dasd_ccw_req *)
  36. dasd_alloc_chunk(&device->erp_chunks, size);
  37. spin_unlock_irqrestore(&device->mem_lock, flags);
  38. if (cqr == NULL)
  39. return ERR_PTR(-ENOMEM);
  40. memset(cqr, 0, sizeof(struct dasd_ccw_req));
  41. INIT_LIST_HEAD(&cqr->devlist);
  42. INIT_LIST_HEAD(&cqr->blocklist);
  43. data = (char *) cqr + ((sizeof(struct dasd_ccw_req) + 7L) & -8L);
  44. cqr->cpaddr = NULL;
  45. if (cplength > 0) {
  46. cqr->cpaddr = (struct ccw1 *) data;
  47. data += cplength*sizeof(struct ccw1);
  48. memset(cqr->cpaddr, 0, cplength*sizeof(struct ccw1));
  49. }
  50. cqr->data = NULL;
  51. if (datasize > 0) {
  52. cqr->data = data;
  53. memset(cqr->data, 0, datasize);
  54. }
  55. cqr->magic = magic;
  56. ASCEBC((char *) &cqr->magic, 4);
  57. set_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
  58. dasd_get_device(device);
  59. return cqr;
  60. }
  61. void
  62. dasd_free_erp_request(struct dasd_ccw_req *cqr, struct dasd_device * device)
  63. {
  64. unsigned long flags;
  65. spin_lock_irqsave(&device->mem_lock, flags);
  66. dasd_free_chunk(&device->erp_chunks, cqr);
  67. spin_unlock_irqrestore(&device->mem_lock, flags);
  68. atomic_dec(&device->ref_count);
  69. }
  70. /*
  71. * dasd_default_erp_action just retries the current cqr
  72. */
  73. struct dasd_ccw_req *
  74. dasd_default_erp_action(struct dasd_ccw_req *cqr)
  75. {
  76. struct dasd_device *device;
  77. device = cqr->startdev;
  78. /* just retry - there is nothing to save ... I got no sense data.... */
  79. if (cqr->retries > 0) {
  80. DBF_DEV_EVENT(DBF_DEBUG, device,
  81. "default ERP called (%i retries left)",
  82. cqr->retries);
  83. if (!test_bit(DASD_CQR_VERIFY_PATH, &cqr->flags))
  84. cqr->lpm = dasd_path_get_opm(device);
  85. cqr->status = DASD_CQR_FILLED;
  86. } else {
  87. pr_err("%s: default ERP has run out of retries and failed\n",
  88. dev_name(&device->cdev->dev));
  89. cqr->status = DASD_CQR_FAILED;
  90. cqr->stopclk = get_tod_clock();
  91. }
  92. return cqr;
  93. } /* end dasd_default_erp_action */
  94. /*
  95. * DESCRIPTION
  96. * Frees all ERPs of the current ERP Chain and set the status
  97. * of the original CQR either to DASD_CQR_DONE if ERP was successful
  98. * or to DASD_CQR_FAILED if ERP was NOT successful.
  99. * NOTE: This function is only called if no discipline postaction
  100. * is available
  101. *
  102. * PARAMETER
  103. * erp current erp_head
  104. *
  105. * RETURN VALUES
  106. * cqr pointer to the original CQR
  107. */
  108. struct dasd_ccw_req *dasd_default_erp_postaction(struct dasd_ccw_req *cqr)
  109. {
  110. int success;
  111. unsigned long startclk, stopclk;
  112. struct dasd_device *startdev;
  113. BUG_ON(cqr->refers == NULL || cqr->function == NULL);
  114. success = cqr->status == DASD_CQR_DONE;
  115. startclk = cqr->startclk;
  116. stopclk = cqr->stopclk;
  117. startdev = cqr->startdev;
  118. /* free all ERPs - but NOT the original cqr */
  119. while (cqr->refers != NULL) {
  120. struct dasd_ccw_req *refers;
  121. refers = cqr->refers;
  122. /* remove the request from the block queue */
  123. list_del(&cqr->blocklist);
  124. /* free the finished erp request */
  125. dasd_free_erp_request(cqr, cqr->memdev);
  126. cqr = refers;
  127. }
  128. /* set corresponding status to original cqr */
  129. cqr->startclk = startclk;
  130. cqr->stopclk = stopclk;
  131. cqr->startdev = startdev;
  132. if (success)
  133. cqr->status = DASD_CQR_DONE;
  134. else {
  135. cqr->status = DASD_CQR_FAILED;
  136. cqr->stopclk = get_tod_clock();
  137. }
  138. return cqr;
  139. } /* end default_erp_postaction */
  140. void
  141. dasd_log_sense(struct dasd_ccw_req *cqr, struct irb *irb)
  142. {
  143. struct dasd_device *device;
  144. device = cqr->startdev;
  145. if (cqr->intrc == -ETIMEDOUT) {
  146. dev_err(&device->cdev->dev,
  147. "A timeout error occurred for cqr %px\n", cqr);
  148. return;
  149. }
  150. if (cqr->intrc == -ENOLINK) {
  151. dev_err(&device->cdev->dev,
  152. "A transport error occurred for cqr %px\n", cqr);
  153. return;
  154. }
  155. /* dump sense data */
  156. if (device->discipline && device->discipline->dump_sense)
  157. device->discipline->dump_sense(device, cqr, irb);
  158. }
  159. void
  160. dasd_log_sense_dbf(struct dasd_ccw_req *cqr, struct irb *irb)
  161. {
  162. struct dasd_device *device;
  163. device = cqr->startdev;
  164. /* dump sense data to s390 debugfeature*/
  165. if (device->discipline && device->discipline->dump_sense_dbf)
  166. device->discipline->dump_sense_dbf(device, irb, "log");
  167. }
  168. EXPORT_SYMBOL(dasd_log_sense_dbf);
  169. EXPORT_SYMBOL(dasd_default_erp_action);
  170. EXPORT_SYMBOL(dasd_default_erp_postaction);
  171. EXPORT_SYMBOL(dasd_alloc_erp_request);
  172. EXPORT_SYMBOL(dasd_free_erp_request);
  173. EXPORT_SYMBOL(dasd_log_sense);