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
13 #include <linux/config.h>
14 #include <linux/ctype.h>
15 #include <linux/init.h>
17 #include <asm/debug.h>
18 #include <asm/ebcdic.h>
19 #include <asm/uaccess.h>
22 #define PRINTK_HEADER "dasd_erp:"
27 dasd_alloc_erp_request(char *magic, int cplength, int datasize,
28 struct dasd_device * device)
31 struct dasd_ccw_req *cqr;
36 if ( magic == NULL || datasize > PAGE_SIZE ||
37 (cplength*sizeof(struct ccw1)) > PAGE_SIZE)
39 debug_text_event ( dasd_debug_area, 1, "ALLC");
40 debug_text_event ( dasd_debug_area, 1, magic);
41 debug_int_event ( dasd_debug_area, 1, cplength);
42 debug_int_event ( dasd_debug_area, 1, datasize);
44 size = (sizeof(struct dasd_ccw_req) + 7L) & -8L;
46 size += cplength * sizeof(struct ccw1);
49 spin_lock_irqsave(&device->mem_lock, flags);
50 cqr = (struct dasd_ccw_req *)
51 dasd_alloc_chunk(&device->erp_chunks, size);
52 spin_unlock_irqrestore(&device->mem_lock, flags);
54 return ERR_PTR(-ENOMEM);
55 memset(cqr, 0, sizeof(struct dasd_ccw_req));
56 data = (char *) cqr + ((sizeof(struct dasd_ccw_req) + 7L) & -8L);
59 cqr->cpaddr = (struct ccw1 *) data;
60 data += cplength*sizeof(struct ccw1);
61 memset(cqr->cpaddr, 0, cplength*sizeof(struct ccw1));
66 memset(cqr->data, 0, datasize);
68 strncpy((char *) &cqr->magic, magic, 4);
69 ASCEBC((char *) &cqr->magic, 4);
70 set_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
71 dasd_get_device(device);
76 dasd_free_erp_request(struct dasd_ccw_req * cqr, struct dasd_device * device)
80 debug_text_event(dasd_debug_area, 1, "FREE");
81 debug_int_event(dasd_debug_area, 1, (long) cqr);
82 spin_lock_irqsave(&device->mem_lock, flags);
83 dasd_free_chunk(&device->erp_chunks, cqr);
84 spin_unlock_irqrestore(&device->mem_lock, flags);
85 atomic_dec(&device->ref_count);
90 * dasd_default_erp_action just retries the current cqr
93 dasd_default_erp_action(struct dasd_ccw_req * cqr)
95 struct dasd_device *device;
99 /* just retry - there is nothing to save ... I got no sense data.... */
100 if (cqr->retries > 0) {
101 DEV_MESSAGE (KERN_DEBUG, device,
102 "default ERP called (%i retries left)",
104 cqr->status = DASD_CQR_QUEUED;
106 DEV_MESSAGE (KERN_WARNING, device, "%s",
107 "default ERP called (NO retry left)");
109 cqr->status = DASD_CQR_FAILED;
110 cqr->stopclk = get_clock ();
113 } /* end dasd_default_erp_action */
117 * Frees all ERPs of the current ERP Chain and set the status
118 * of the original CQR either to DASD_CQR_DONE if ERP was successful
119 * or to DASD_CQR_FAILED if ERP was NOT successful.
120 * NOTE: This function is only called if no discipline postaction
124 * erp current erp_head
127 * cqr pointer to the original CQR
129 struct dasd_ccw_req *
130 dasd_default_erp_postaction(struct dasd_ccw_req * cqr)
132 struct dasd_device *device;
135 if (cqr->refers == NULL || cqr->function == NULL)
138 device = cqr->device;
139 success = cqr->status == DASD_CQR_DONE;
141 /* free all ERPs - but NOT the original cqr */
142 while (cqr->refers != NULL) {
143 struct dasd_ccw_req *refers;
145 refers = cqr->refers;
146 /* remove the request from the device queue */
147 list_del(&cqr->list);
148 /* free the finished erp request */
149 dasd_free_erp_request(cqr, device);
153 /* set corresponding status to original cqr */
155 cqr->status = DASD_CQR_DONE;
157 cqr->status = DASD_CQR_FAILED;
158 cqr->stopclk = get_clock();
163 } /* end default_erp_postaction */
166 * Print the hex dump of the memory used by a request. This includes
167 * all error recovery ccws that have been chained in from of the
171 hex_dump_memory(struct dasd_device *device, void *data, int len)
177 DEV_MESSAGE(KERN_ERR, device, "%p: %08x %08x %08x %08x",
178 pint, pint[0], pint[1], pint[2], pint[3]);
185 dasd_log_sense(struct dasd_ccw_req *cqr, struct irb *irb)
187 struct dasd_device *device;
189 device = cqr->device;
190 /* dump sense data */
191 if (device->discipline && device->discipline->dump_sense)
192 device->discipline->dump_sense(device, cqr, irb);
196 dasd_log_ccw(struct dasd_ccw_req * cqr, int caller, __u32 cpa)
198 struct dasd_device *device;
199 struct dasd_ccw_req *lcqr;
203 device = cqr->device;
204 /* log the channel program */
205 for (lcqr = cqr; lcqr != NULL; lcqr = lcqr->refers) {
206 DEV_MESSAGE(KERN_ERR, device,
207 "(%s) ERP chain report for req: %p",
208 caller == 0 ? "EXAMINE" : "ACTION", lcqr);
209 hex_dump_memory(device, lcqr, sizeof(struct dasd_ccw_req));
213 while (ccw++->flags & (CCW_FLAG_DC | CCW_FLAG_CC))
216 if (cplength > 40) { /* log only parts of the CP */
217 DEV_MESSAGE(KERN_ERR, device, "%s",
218 "Start of channel program:");
219 hex_dump_memory(device, lcqr->cpaddr,
220 40*sizeof(struct ccw1));
222 DEV_MESSAGE(KERN_ERR, device, "%s",
223 "End of channel program:");
224 hex_dump_memory(device, lcqr->cpaddr + cplength - 10,
225 10*sizeof(struct ccw1));
226 } else { /* log the whole CP */
227 DEV_MESSAGE(KERN_ERR, device, "%s",
228 "Channel program (complete):");
229 hex_dump_memory(device, lcqr->cpaddr,
230 cplength*sizeof(struct ccw1));
237 * Log bytes arround failed CCW but only if we did
238 * not log the whole CP of the CCW is outside the
242 ((addr_t) cpa < (addr_t) lcqr->cpaddr &&
243 (addr_t) cpa > (addr_t) (lcqr->cpaddr + cplength + 4))) {
245 DEV_MESSAGE(KERN_ERR, device,
246 "Failed CCW (%p) (area):",
247 (void *) (long) cpa);
248 hex_dump_memory(device, cqr->cpaddr - 10,
249 20*sizeof(struct ccw1));
253 } /* end log_erp_chain */
255 EXPORT_SYMBOL(dasd_default_erp_action);
256 EXPORT_SYMBOL(dasd_default_erp_postaction);
257 EXPORT_SYMBOL(dasd_alloc_erp_request);
258 EXPORT_SYMBOL(dasd_free_erp_request);
259 EXPORT_SYMBOL(dasd_log_sense);
260 EXPORT_SYMBOL(dasd_log_ccw);