dasd_erp.c 5.2 KB

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