dasd_erp.c 5.1 KB

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