blob: 8fd71ab02ef055df625a0182cff83bd795459b66 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 */
11
12#include <linux/config.h>
13#include <linux/ctype.h>
14#include <linux/init.h>
15
16#include <asm/debug.h>
17#include <asm/ebcdic.h>
18#include <asm/uaccess.h>
19
20/* This is ugly... */
21#define PRINTK_HEADER "dasd_erp:"
22
23#include "dasd_int.h"
24
25struct dasd_ccw_req *
26dasd_alloc_erp_request(char *magic, int cplength, int datasize,
27 struct dasd_device * device)
28{
29 unsigned long flags;
30 struct dasd_ccw_req *cqr;
31 char *data;
32 int size;
33
34 /* Sanity checks */
35 if ( magic == NULL || datasize > PAGE_SIZE ||
36 (cplength*sizeof(struct ccw1)) > PAGE_SIZE)
37 BUG();
38
39 size = (sizeof(struct dasd_ccw_req) + 7L) & -8L;
40 if (cplength > 0)
41 size += cplength * sizeof(struct ccw1);
42 if (datasize > 0)
43 size += datasize;
44 spin_lock_irqsave(&device->mem_lock, flags);
45 cqr = (struct dasd_ccw_req *)
46 dasd_alloc_chunk(&device->erp_chunks, size);
47 spin_unlock_irqrestore(&device->mem_lock, flags);
48 if (cqr == NULL)
49 return ERR_PTR(-ENOMEM);
50 memset(cqr, 0, sizeof(struct dasd_ccw_req));
51 data = (char *) cqr + ((sizeof(struct dasd_ccw_req) + 7L) & -8L);
52 cqr->cpaddr = NULL;
53 if (cplength > 0) {
54 cqr->cpaddr = (struct ccw1 *) data;
55 data += cplength*sizeof(struct ccw1);
56 memset(cqr->cpaddr, 0, cplength*sizeof(struct ccw1));
57 }
58 cqr->data = NULL;
59 if (datasize > 0) {
60 cqr->data = data;
61 memset(cqr->data, 0, datasize);
62 }
63 strncpy((char *) &cqr->magic, magic, 4);
64 ASCEBC((char *) &cqr->magic, 4);
65 set_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
66 dasd_get_device(device);
67 return cqr;
68}
69
70void
71dasd_free_erp_request(struct dasd_ccw_req * cqr, struct dasd_device * device)
72{
73 unsigned long flags;
74
75 spin_lock_irqsave(&device->mem_lock, flags);
76 dasd_free_chunk(&device->erp_chunks, cqr);
77 spin_unlock_irqrestore(&device->mem_lock, flags);
78 atomic_dec(&device->ref_count);
79}
80
81
82/*
83 * dasd_default_erp_action just retries the current cqr
84 */
85struct dasd_ccw_req *
86dasd_default_erp_action(struct dasd_ccw_req * cqr)
87{
88 struct dasd_device *device;
89
90 device = cqr->device;
91
92 /* just retry - there is nothing to save ... I got no sense data.... */
93 if (cqr->retries > 0) {
94 DEV_MESSAGE (KERN_DEBUG, device,
95 "default ERP called (%i retries left)",
96 cqr->retries);
97 cqr->lpm = LPM_ANYPATH;
98 cqr->status = DASD_CQR_QUEUED;
99 } else {
100 DEV_MESSAGE (KERN_WARNING, device, "%s",
101 "default ERP called (NO retry left)");
102 cqr->status = DASD_CQR_FAILED;
103 cqr->stopclk = get_clock ();
104 }
105 return cqr;
106} /* end dasd_default_erp_action */
107
108/*
109 * DESCRIPTION
110 * Frees all ERPs of the current ERP Chain and set the status
111 * of the original CQR either to DASD_CQR_DONE if ERP was successful
112 * or to DASD_CQR_FAILED if ERP was NOT successful.
113 * NOTE: This function is only called if no discipline postaction
114 * is available
115 *
116 * PARAMETER
117 * erp current erp_head
118 *
119 * RETURN VALUES
120 * cqr pointer to the original CQR
121 */
122struct dasd_ccw_req *
123dasd_default_erp_postaction(struct dasd_ccw_req * cqr)
124{
125 struct dasd_device *device;
126 int success;
127
128 if (cqr->refers == NULL || cqr->function == NULL)
129 BUG();
130
131 device = cqr->device;
132 success = cqr->status == DASD_CQR_DONE;
133
134 /* free all ERPs - but NOT the original cqr */
135 while (cqr->refers != NULL) {
136 struct dasd_ccw_req *refers;
137
138 refers = cqr->refers;
139 /* remove the request from the device queue */
140 list_del(&cqr->list);
141 /* free the finished erp request */
142 dasd_free_erp_request(cqr, device);
143 cqr = refers;
144 }
145
146 /* set corresponding status to original cqr */
147 if (success)
148 cqr->status = DASD_CQR_DONE;
149 else {
150 cqr->status = DASD_CQR_FAILED;
151 cqr->stopclk = get_clock();
152 }
153
154 return cqr;
155
156} /* end default_erp_postaction */
157
158/*
159 * Print the hex dump of the memory used by a request. This includes
160 * all error recovery ccws that have been chained in from of the
161 * real request.
162 */
163static inline void
164hex_dump_memory(struct dasd_device *device, void *data, int len)
165{
166 int *pint;
167
168 pint = (int *) data;
169 while (len > 0) {
170 DEV_MESSAGE(KERN_ERR, device, "%p: %08x %08x %08x %08x",
171 pint, pint[0], pint[1], pint[2], pint[3]);
172 pint += 4;
173 len -= 16;
174 }
175}
176
177void
178dasd_log_sense(struct dasd_ccw_req *cqr, struct irb *irb)
179{
180 struct dasd_device *device;
181
182 device = cqr->device;
183 /* dump sense data */
184 if (device->discipline && device->discipline->dump_sense)
185 device->discipline->dump_sense(device, cqr, irb);
186}
187
188void
189dasd_log_ccw(struct dasd_ccw_req * cqr, int caller, __u32 cpa)
190{
191 struct dasd_device *device;
192 struct dasd_ccw_req *lcqr;
193 struct ccw1 *ccw;
194 int cplength;
195
196 device = cqr->device;
197 /* log the channel program */
198 for (lcqr = cqr; lcqr != NULL; lcqr = lcqr->refers) {
199 DEV_MESSAGE(KERN_ERR, device,
200 "(%s) ERP chain report for req: %p",
201 caller == 0 ? "EXAMINE" : "ACTION", lcqr);
202 hex_dump_memory(device, lcqr, sizeof(struct dasd_ccw_req));
203
204 cplength = 1;
205 ccw = lcqr->cpaddr;
206 while (ccw++->flags & (CCW_FLAG_DC | CCW_FLAG_CC))
207 cplength++;
208
209 if (cplength > 40) { /* log only parts of the CP */
210 DEV_MESSAGE(KERN_ERR, device, "%s",
211 "Start of channel program:");
212 hex_dump_memory(device, lcqr->cpaddr,
213 40*sizeof(struct ccw1));
214
215 DEV_MESSAGE(KERN_ERR, device, "%s",
216 "End of channel program:");
217 hex_dump_memory(device, lcqr->cpaddr + cplength - 10,
218 10*sizeof(struct ccw1));
219 } else { /* log the whole CP */
220 DEV_MESSAGE(KERN_ERR, device, "%s",
221 "Channel program (complete):");
222 hex_dump_memory(device, lcqr->cpaddr,
223 cplength*sizeof(struct ccw1));
224 }
225
226 if (lcqr != cqr)
227 continue;
228
229 /*
230 * Log bytes arround failed CCW but only if we did
231 * not log the whole CP of the CCW is outside the
232 * logged CP.
233 */
234 if (cplength > 40 ||
235 ((addr_t) cpa < (addr_t) lcqr->cpaddr &&
236 (addr_t) cpa > (addr_t) (lcqr->cpaddr + cplength + 4))) {
237
238 DEV_MESSAGE(KERN_ERR, device,
239 "Failed CCW (%p) (area):",
240 (void *) (long) cpa);
241 hex_dump_memory(device, cqr->cpaddr - 10,
242 20*sizeof(struct ccw1));
243 }
244 }
245
246} /* end log_erp_chain */
247
248EXPORT_SYMBOL(dasd_default_erp_action);
249EXPORT_SYMBOL(dasd_default_erp_postaction);
250EXPORT_SYMBOL(dasd_alloc_erp_request);
251EXPORT_SYMBOL(dasd_free_erp_request);
252EXPORT_SYMBOL(dasd_log_sense);
253EXPORT_SYMBOL(dasd_log_ccw);