dasd_erp.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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/config.h>
  12. #include <linux/ctype.h>
  13. #include <linux/init.h>
  14. #include <asm/debug.h>
  15. #include <asm/ebcdic.h>
  16. #include <asm/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. if ( magic == NULL || datasize > PAGE_SIZE ||
  30. (cplength*sizeof(struct ccw1)) > PAGE_SIZE)
  31. BUG();
  32. size = (sizeof(struct dasd_ccw_req) + 7L) & -8L;
  33. if (cplength > 0)
  34. size += cplength * sizeof(struct ccw1);
  35. if (datasize > 0)
  36. size += datasize;
  37. spin_lock_irqsave(&device->mem_lock, flags);
  38. cqr = (struct dasd_ccw_req *)
  39. dasd_alloc_chunk(&device->erp_chunks, size);
  40. spin_unlock_irqrestore(&device->mem_lock, flags);
  41. if (cqr == NULL)
  42. return ERR_PTR(-ENOMEM);
  43. memset(cqr, 0, sizeof(struct dasd_ccw_req));
  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->device;
  79. /* just retry - there is nothing to save ... I got no sense data.... */
  80. if (cqr->retries > 0) {
  81. DEV_MESSAGE (KERN_DEBUG, device,
  82. "default ERP called (%i retries left)",
  83. cqr->retries);
  84. cqr->lpm = LPM_ANYPATH;
  85. cqr->status = DASD_CQR_QUEUED;
  86. } else {
  87. DEV_MESSAGE (KERN_WARNING, device, "%s",
  88. "default ERP called (NO retry left)");
  89. cqr->status = DASD_CQR_FAILED;
  90. cqr->stopclk = get_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 *
  109. dasd_default_erp_postaction(struct dasd_ccw_req * cqr)
  110. {
  111. struct dasd_device *device;
  112. int success;
  113. if (cqr->refers == NULL || cqr->function == NULL)
  114. BUG();
  115. device = cqr->device;
  116. success = cqr->status == DASD_CQR_DONE;
  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 device queue */
  122. list_del(&cqr->list);
  123. /* free the finished erp request */
  124. dasd_free_erp_request(cqr, device);
  125. cqr = refers;
  126. }
  127. /* set corresponding status to original cqr */
  128. if (success)
  129. cqr->status = DASD_CQR_DONE;
  130. else {
  131. cqr->status = DASD_CQR_FAILED;
  132. cqr->stopclk = get_clock();
  133. }
  134. return cqr;
  135. } /* end default_erp_postaction */
  136. /*
  137. * Print the hex dump of the memory used by a request. This includes
  138. * all error recovery ccws that have been chained in from of the
  139. * real request.
  140. */
  141. static inline void
  142. hex_dump_memory(struct dasd_device *device, void *data, int len)
  143. {
  144. int *pint;
  145. pint = (int *) data;
  146. while (len > 0) {
  147. DEV_MESSAGE(KERN_ERR, device, "%p: %08x %08x %08x %08x",
  148. pint, pint[0], pint[1], pint[2], pint[3]);
  149. pint += 4;
  150. len -= 16;
  151. }
  152. }
  153. void
  154. dasd_log_sense(struct dasd_ccw_req *cqr, struct irb *irb)
  155. {
  156. struct dasd_device *device;
  157. device = cqr->device;
  158. /* dump sense data */
  159. if (device->discipline && device->discipline->dump_sense)
  160. device->discipline->dump_sense(device, cqr, irb);
  161. }
  162. void
  163. dasd_log_ccw(struct dasd_ccw_req * cqr, int caller, __u32 cpa)
  164. {
  165. struct dasd_device *device;
  166. struct dasd_ccw_req *lcqr;
  167. struct ccw1 *ccw;
  168. int cplength;
  169. device = cqr->device;
  170. /* log the channel program */
  171. for (lcqr = cqr; lcqr != NULL; lcqr = lcqr->refers) {
  172. DEV_MESSAGE(KERN_ERR, device,
  173. "(%s) ERP chain report for req: %p",
  174. caller == 0 ? "EXAMINE" : "ACTION", lcqr);
  175. hex_dump_memory(device, lcqr, sizeof(struct dasd_ccw_req));
  176. cplength = 1;
  177. ccw = lcqr->cpaddr;
  178. while (ccw++->flags & (CCW_FLAG_DC | CCW_FLAG_CC))
  179. cplength++;
  180. if (cplength > 40) { /* log only parts of the CP */
  181. DEV_MESSAGE(KERN_ERR, device, "%s",
  182. "Start of channel program:");
  183. hex_dump_memory(device, lcqr->cpaddr,
  184. 40*sizeof(struct ccw1));
  185. DEV_MESSAGE(KERN_ERR, device, "%s",
  186. "End of channel program:");
  187. hex_dump_memory(device, lcqr->cpaddr + cplength - 10,
  188. 10*sizeof(struct ccw1));
  189. } else { /* log the whole CP */
  190. DEV_MESSAGE(KERN_ERR, device, "%s",
  191. "Channel program (complete):");
  192. hex_dump_memory(device, lcqr->cpaddr,
  193. cplength*sizeof(struct ccw1));
  194. }
  195. if (lcqr != cqr)
  196. continue;
  197. /*
  198. * Log bytes arround failed CCW but only if we did
  199. * not log the whole CP of the CCW is outside the
  200. * logged CP.
  201. */
  202. if (cplength > 40 ||
  203. ((addr_t) cpa < (addr_t) lcqr->cpaddr &&
  204. (addr_t) cpa > (addr_t) (lcqr->cpaddr + cplength + 4))) {
  205. DEV_MESSAGE(KERN_ERR, device,
  206. "Failed CCW (%p) (area):",
  207. (void *) (long) cpa);
  208. hex_dump_memory(device, cqr->cpaddr - 10,
  209. 20*sizeof(struct ccw1));
  210. }
  211. }
  212. } /* end log_erp_chain */
  213. EXPORT_SYMBOL(dasd_default_erp_action);
  214. EXPORT_SYMBOL(dasd_default_erp_postaction);
  215. EXPORT_SYMBOL(dasd_alloc_erp_request);
  216. EXPORT_SYMBOL(dasd_free_erp_request);
  217. EXPORT_SYMBOL(dasd_log_sense);
  218. EXPORT_SYMBOL(dasd_log_ccw);