dasd_erp.c 6.5 KB

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