1 // SPDX-License-Identifier: GPL-2.0
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 * Copyright IBM Corp. 1999, 2001
12 #include <linux/ctype.h>
13 #include <linux/init.h>
15 #include <asm/debug.h>
16 #include <asm/ebcdic.h>
17 #include <linux/uaccess.h>
22 dasd_alloc_erp_request(unsigned int magic
, int cplength
, int datasize
,
23 struct dasd_device
* device
)
26 struct dasd_ccw_req
*cqr
;
31 BUG_ON(datasize
> PAGE_SIZE
||
32 (cplength
*sizeof(struct ccw1
)) > PAGE_SIZE
);
34 size
= (sizeof(struct dasd_ccw_req
) + 7L) & -8L;
36 size
+= cplength
* sizeof(struct ccw1
);
39 spin_lock_irqsave(&device
->mem_lock
, flags
);
40 cqr
= (struct dasd_ccw_req
*)
41 dasd_alloc_chunk(&device
->erp_chunks
, size
);
42 spin_unlock_irqrestore(&device
->mem_lock
, flags
);
44 return ERR_PTR(-ENOMEM
);
45 memset(cqr
, 0, sizeof(struct dasd_ccw_req
));
46 INIT_LIST_HEAD(&cqr
->devlist
);
47 INIT_LIST_HEAD(&cqr
->blocklist
);
48 data
= (char *) cqr
+ ((sizeof(struct dasd_ccw_req
) + 7L) & -8L);
51 cqr
->cpaddr
= (struct ccw1
*) data
;
52 data
+= cplength
*sizeof(struct ccw1
);
53 memset(cqr
->cpaddr
, 0, cplength
*sizeof(struct ccw1
));
58 memset(cqr
->data
, 0, datasize
);
61 ASCEBC((char *) &cqr
->magic
, 4);
62 set_bit(DASD_CQR_FLAGS_USE_ERP
, &cqr
->flags
);
63 dasd_get_device(device
);
68 dasd_free_erp_request(struct dasd_ccw_req
*cqr
, struct dasd_device
* device
)
72 spin_lock_irqsave(&device
->mem_lock
, flags
);
73 dasd_free_chunk(&device
->erp_chunks
, cqr
);
74 spin_unlock_irqrestore(&device
->mem_lock
, flags
);
75 atomic_dec(&device
->ref_count
);
80 * dasd_default_erp_action just retries the current cqr
83 dasd_default_erp_action(struct dasd_ccw_req
*cqr
)
85 struct dasd_device
*device
;
87 device
= cqr
->startdev
;
89 /* just retry - there is nothing to save ... I got no sense data.... */
90 if (cqr
->retries
> 0) {
91 DBF_DEV_EVENT(DBF_DEBUG
, device
,
92 "default ERP called (%i retries left)",
94 if (!test_bit(DASD_CQR_VERIFY_PATH
, &cqr
->flags
))
95 cqr
->lpm
= dasd_path_get_opm(device
);
96 cqr
->status
= DASD_CQR_FILLED
;
98 pr_err("%s: default ERP has run out of retries and failed\n",
99 dev_name(&device
->cdev
->dev
));
100 cqr
->status
= DASD_CQR_FAILED
;
101 cqr
->stopclk
= get_tod_clock();
104 } /* end dasd_default_erp_action */
108 * Frees all ERPs of the current ERP Chain and set the status
109 * of the original CQR either to DASD_CQR_DONE if ERP was successful
110 * or to DASD_CQR_FAILED if ERP was NOT successful.
111 * NOTE: This function is only called if no discipline postaction
115 * erp current erp_head
118 * cqr pointer to the original CQR
120 struct dasd_ccw_req
*dasd_default_erp_postaction(struct dasd_ccw_req
*cqr
)
123 unsigned long startclk
, stopclk
;
124 struct dasd_device
*startdev
;
126 BUG_ON(cqr
->refers
== NULL
|| cqr
->function
== NULL
);
128 success
= cqr
->status
== DASD_CQR_DONE
;
129 startclk
= cqr
->startclk
;
130 stopclk
= cqr
->stopclk
;
131 startdev
= cqr
->startdev
;
133 /* free all ERPs - but NOT the original cqr */
134 while (cqr
->refers
!= NULL
) {
135 struct dasd_ccw_req
*refers
;
137 refers
= cqr
->refers
;
138 /* remove the request from the block queue */
139 list_del(&cqr
->blocklist
);
140 /* free the finished erp request */
141 dasd_free_erp_request(cqr
, cqr
->memdev
);
145 /* set corresponding status to original cqr */
146 cqr
->startclk
= startclk
;
147 cqr
->stopclk
= stopclk
;
148 cqr
->startdev
= startdev
;
150 cqr
->status
= DASD_CQR_DONE
;
152 cqr
->status
= DASD_CQR_FAILED
;
153 cqr
->stopclk
= get_tod_clock();
158 } /* end default_erp_postaction */
161 dasd_log_sense(struct dasd_ccw_req
*cqr
, struct irb
*irb
)
163 struct dasd_device
*device
;
165 device
= cqr
->startdev
;
166 if (cqr
->intrc
== -ETIMEDOUT
) {
167 dev_err(&device
->cdev
->dev
,
168 "A timeout error occurred for cqr %px\n", cqr
);
171 if (cqr
->intrc
== -ENOLINK
) {
172 dev_err(&device
->cdev
->dev
,
173 "A transport error occurred for cqr %px\n", cqr
);
176 /* dump sense data */
177 if (device
->discipline
&& device
->discipline
->dump_sense
)
178 device
->discipline
->dump_sense(device
, cqr
, irb
);
182 dasd_log_sense_dbf(struct dasd_ccw_req
*cqr
, struct irb
*irb
)
184 struct dasd_device
*device
;
186 device
= cqr
->startdev
;
187 /* dump sense data to s390 debugfeature*/
188 if (device
->discipline
&& device
->discipline
->dump_sense_dbf
)
189 device
->discipline
->dump_sense_dbf(device
, irb
, "log");
191 EXPORT_SYMBOL(dasd_log_sense_dbf
);
193 EXPORT_SYMBOL(dasd_default_erp_action
);
194 EXPORT_SYMBOL(dasd_default_erp_postaction
);
195 EXPORT_SYMBOL(dasd_alloc_erp_request
);
196 EXPORT_SYMBOL(dasd_free_erp_request
);
197 EXPORT_SYMBOL(dasd_log_sense
);