dasd_erp.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. /*
  2. * File...........: linux/drivers/s390/block/dasd.c
  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. * (C) IBM Corporation, IBM Deutschland Entwicklung GmbH, 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 <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. 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. strncpy((char *) &cqr->magic, magic, 4);
  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->device;
  77. /* just retry - there is nothing to save ... I got no sense data.... */
  78. if (cqr->retries > 0) {
  79. DEV_MESSAGE (KERN_DEBUG, device,
  80. "default ERP called (%i retries left)",
  81. cqr->retries);
  82. cqr->lpm = LPM_ANYPATH;
  83. cqr->status = DASD_CQR_QUEUED;
  84. } else {
  85. DEV_MESSAGE (KERN_WARNING, device, "%s",
  86. "default ERP called (NO retry left)");
  87. cqr->status = DASD_CQR_FAILED;
  88. cqr->stopclk = get_clock ();
  89. }
  90. return cqr;
  91. } /* end dasd_default_erp_action */
  92. /*
  93. * DESCRIPTION
  94. * Frees all ERPs of the current ERP Chain and set the status
  95. * of the original CQR either to DASD_CQR_DONE if ERP was successful
  96. * or to DASD_CQR_FAILED if ERP was NOT successful.
  97. * NOTE: This function is only called if no discipline postaction
  98. * is available
  99. *
  100. * PARAMETER
  101. * erp current erp_head
  102. *
  103. * RETURN VALUES
  104. * cqr pointer to the original CQR
  105. */
  106. struct dasd_ccw_req *
  107. dasd_default_erp_postaction(struct dasd_ccw_req * cqr)
  108. {
  109. struct dasd_device *device;
  110. int success;
  111. BUG_ON(cqr->refers == NULL || cqr->function == NULL);
  112. device = cqr->device;
  113. success = cqr->status == DASD_CQR_DONE;
  114. /* free all ERPs - but NOT the original cqr */
  115. while (cqr->refers != NULL) {
  116. struct dasd_ccw_req *refers;
  117. refers = cqr->refers;
  118. /* remove the request from the device queue */
  119. list_del(&cqr->list);
  120. /* free the finished erp request */
  121. dasd_free_erp_request(cqr, device);
  122. cqr = refers;
  123. }
  124. /* set corresponding status to original cqr */
  125. if (success)
  126. cqr->status = DASD_CQR_DONE;
  127. else {
  128. cqr->status = DASD_CQR_FAILED;
  129. cqr->stopclk = get_clock();
  130. }
  131. return cqr;
  132. } /* end default_erp_postaction */
  133. /*
  134. * Print the hex dump of the memory used by a request. This includes
  135. * all error recovery ccws that have been chained in from of the
  136. * real request.
  137. */
  138. static inline void
  139. hex_dump_memory(struct dasd_device *device, void *data, int len)
  140. {
  141. int *pint;
  142. pint = (int *) data;
  143. while (len > 0) {
  144. DEV_MESSAGE(KERN_ERR, device, "%p: %08x %08x %08x %08x",
  145. pint, pint[0], pint[1], pint[2], pint[3]);
  146. pint += 4;
  147. len -= 16;
  148. }
  149. }
  150. void
  151. dasd_log_sense(struct dasd_ccw_req *cqr, struct irb *irb)
  152. {
  153. struct dasd_device *device;
  154. device = cqr->device;
  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_ccw(struct dasd_ccw_req * cqr, int caller, __u32 cpa)
  161. {
  162. struct dasd_device *device;
  163. struct dasd_ccw_req *lcqr;
  164. struct ccw1 *ccw;
  165. int cplength;
  166. device = cqr->device;
  167. /* log the channel program */
  168. for (lcqr = cqr; lcqr != NULL; lcqr = lcqr->refers) {
  169. DEV_MESSAGE(KERN_ERR, device,
  170. "(%s) ERP chain report for req: %p",
  171. caller == 0 ? "EXAMINE" : "ACTION", lcqr);
  172. hex_dump_memory(device, lcqr, sizeof(struct dasd_ccw_req));
  173. cplength = 1;
  174. ccw = lcqr->cpaddr;
  175. while (ccw++->flags & (CCW_FLAG_DC | CCW_FLAG_CC))
  176. cplength++;
  177. if (cplength > 40) { /* log only parts of the CP */
  178. DEV_MESSAGE(KERN_ERR, device, "%s",
  179. "Start of channel program:");
  180. hex_dump_memory(device, lcqr->cpaddr,
  181. 40*sizeof(struct ccw1));
  182. DEV_MESSAGE(KERN_ERR, device, "%s",
  183. "End of channel program:");
  184. hex_dump_memory(device, lcqr->cpaddr + cplength - 10,
  185. 10*sizeof(struct ccw1));
  186. } else { /* log the whole CP */
  187. DEV_MESSAGE(KERN_ERR, device, "%s",
  188. "Channel program (complete):");
  189. hex_dump_memory(device, lcqr->cpaddr,
  190. cplength*sizeof(struct ccw1));
  191. }
  192. if (lcqr != cqr)
  193. continue;
  194. /*
  195. * Log bytes arround failed CCW but only if we did
  196. * not log the whole CP of the CCW is outside the
  197. * logged CP.
  198. */
  199. if (cplength > 40 ||
  200. ((addr_t) cpa < (addr_t) lcqr->cpaddr &&
  201. (addr_t) cpa > (addr_t) (lcqr->cpaddr + cplength + 4))) {
  202. DEV_MESSAGE(KERN_ERR, device,
  203. "Failed CCW (%p) (area):",
  204. (void *) (long) cpa);
  205. hex_dump_memory(device, cqr->cpaddr - 10,
  206. 20*sizeof(struct ccw1));
  207. }
  208. }
  209. } /* end log_erp_chain */
  210. EXPORT_SYMBOL(dasd_default_erp_action);
  211. EXPORT_SYMBOL(dasd_default_erp_postaction);
  212. EXPORT_SYMBOL(dasd_alloc_erp_request);
  213. EXPORT_SYMBOL(dasd_free_erp_request);
  214. EXPORT_SYMBOL(dasd_log_sense);
  215. EXPORT_SYMBOL(dasd_log_ccw);