blob: 0eafe2e421e7dfadccdcb0f087ab80605ccd4d24 [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
Stefan Haberlandfc19f382009-03-26 15:23:49 +010012#define KMSG_COMPONENT "dasd"
13
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/ctype.h>
15#include <linux/init.h>
16
17#include <asm/debug.h>
18#include <asm/ebcdic.h>
19#include <asm/uaccess.h>
20
21/* This is ugly... */
22#define PRINTK_HEADER "dasd_erp:"
23
24#include "dasd_int.h"
25
26struct dasd_ccw_req *
27dasd_alloc_erp_request(char *magic, int cplength, int datasize,
28 struct dasd_device * device)
29{
30 unsigned long flags;
31 struct dasd_ccw_req *cqr;
32 char *data;
33 int size;
34
35 /* Sanity checks */
Eric Sesterhenne048a8a2006-04-01 01:27:08 +020036 BUG_ON( magic == NULL || datasize > PAGE_SIZE ||
37 (cplength*sizeof(struct ccw1)) > PAGE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
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));
Stefan Weinhuber8e09f212008-01-26 14:11:23 +010051 INIT_LIST_HEAD(&cqr->devlist);
52 INIT_LIST_HEAD(&cqr->blocklist);
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 data = (char *) cqr + ((sizeof(struct dasd_ccw_req) + 7L) & -8L);
54 cqr->cpaddr = NULL;
55 if (cplength > 0) {
56 cqr->cpaddr = (struct ccw1 *) data;
57 data += cplength*sizeof(struct ccw1);
58 memset(cqr->cpaddr, 0, cplength*sizeof(struct ccw1));
59 }
60 cqr->data = NULL;
61 if (datasize > 0) {
62 cqr->data = data;
63 memset(cqr->data, 0, datasize);
64 }
65 strncpy((char *) &cqr->magic, magic, 4);
66 ASCEBC((char *) &cqr->magic, 4);
67 set_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
68 dasd_get_device(device);
69 return cqr;
70}
71
72void
Stefan Weinhuber8e09f212008-01-26 14:11:23 +010073dasd_free_erp_request(struct dasd_ccw_req *cqr, struct dasd_device * device)
Linus Torvalds1da177e2005-04-16 15:20:36 -070074{
75 unsigned long flags;
76
77 spin_lock_irqsave(&device->mem_lock, flags);
78 dasd_free_chunk(&device->erp_chunks, cqr);
79 spin_unlock_irqrestore(&device->mem_lock, flags);
80 atomic_dec(&device->ref_count);
81}
82
83
84/*
85 * dasd_default_erp_action just retries the current cqr
86 */
87struct dasd_ccw_req *
Stefan Weinhuber8e09f212008-01-26 14:11:23 +010088dasd_default_erp_action(struct dasd_ccw_req *cqr)
Linus Torvalds1da177e2005-04-16 15:20:36 -070089{
90 struct dasd_device *device;
91
Stefan Weinhuber8e09f212008-01-26 14:11:23 +010092 device = cqr->startdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -070093
94 /* just retry - there is nothing to save ... I got no sense data.... */
95 if (cqr->retries > 0) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +010096 DBF_DEV_EVENT(DBF_DEBUG, device,
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 "default ERP called (%i retries left)",
98 cqr->retries);
Stefan Weinhubera4d26c62011-01-05 12:48:03 +010099 if (!test_bit(DASD_CQR_VERIFY_PATH, &cqr->flags))
100 cqr->lpm = device->path_data.opm;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100101 cqr->status = DASD_CQR_FILLED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 } else {
Stefan Haberlandca99dab2009-09-11 10:28:30 +0200103 pr_err("%s: default ERP has run out of retries and failed\n",
104 dev_name(&device->cdev->dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 cqr->status = DASD_CQR_FAILED;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100106 cqr->stopclk = get_clock();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 }
108 return cqr;
109} /* end dasd_default_erp_action */
110
111/*
112 * DESCRIPTION
113 * Frees all ERPs of the current ERP Chain and set the status
114 * of the original CQR either to DASD_CQR_DONE if ERP was successful
115 * or to DASD_CQR_FAILED if ERP was NOT successful.
116 * NOTE: This function is only called if no discipline postaction
117 * is available
118 *
119 * PARAMETER
120 * erp current erp_head
121 *
122 * RETURN VALUES
123 * cqr pointer to the original CQR
124 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100125struct dasd_ccw_req *dasd_default_erp_postaction(struct dasd_ccw_req *cqr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 int success;
128
Eric Sesterhenne048a8a2006-04-01 01:27:08 +0200129 BUG_ON(cqr->refers == NULL || cqr->function == NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 success = cqr->status == DASD_CQR_DONE;
132
133 /* free all ERPs - but NOT the original cqr */
134 while (cqr->refers != NULL) {
135 struct dasd_ccw_req *refers;
136
137 refers = cqr->refers;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100138 /* remove the request from the block queue */
139 list_del(&cqr->blocklist);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 /* free the finished erp request */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100141 dasd_free_erp_request(cqr, cqr->memdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 cqr = refers;
143 }
144
145 /* set corresponding status to original cqr */
146 if (success)
147 cqr->status = DASD_CQR_DONE;
148 else {
149 cqr->status = DASD_CQR_FAILED;
150 cqr->stopclk = get_clock();
151 }
152
153 return cqr;
154
155} /* end default_erp_postaction */
156
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157void
158dasd_log_sense(struct dasd_ccw_req *cqr, struct irb *irb)
159{
160 struct dasd_device *device;
161
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100162 device = cqr->startdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 /* dump sense data */
164 if (device->discipline && device->discipline->dump_sense)
165 device->discipline->dump_sense(device, cqr, irb);
166}
167
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100168void
169dasd_log_sense_dbf(struct dasd_ccw_req *cqr, struct irb *irb)
170{
171 struct dasd_device *device;
172
173 device = cqr->startdev;
174 /* dump sense data to s390 debugfeature*/
175 if (device->discipline && device->discipline->dump_sense_dbf)
Stefan Haberlandaeec92c2009-07-07 16:37:06 +0200176 device->discipline->dump_sense_dbf(device, irb, "log");
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100177}
178EXPORT_SYMBOL(dasd_log_sense_dbf);
179
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180EXPORT_SYMBOL(dasd_default_erp_action);
181EXPORT_SYMBOL(dasd_default_erp_postaction);
182EXPORT_SYMBOL(dasd_alloc_erp_request);
183EXPORT_SYMBOL(dasd_free_erp_request);
184EXPORT_SYMBOL(dasd_log_sense);
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100185