dasd_erp.c 5.3 KB

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