1 // SPDX-License-Identifier: GPL-2.0 2 /* 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 9 * 10 */ 11 12 #include <linux/export.h> 13 #include <linux/ctype.h> 14 #include <linux/init.h> 15 16 #include <asm/debug.h> 17 #include <asm/ebcdic.h> 18 #include <linux/uaccess.h> 19 20 #include "dasd_int.h" 21 22 struct dasd_ccw_req * 23 dasd_alloc_erp_request(unsigned int magic, int cplength, int datasize, 24 struct dasd_device * device) 25 { 26 unsigned long flags; 27 struct dasd_ccw_req *cqr; 28 char *data; 29 int size; 30 31 /* Sanity checks */ 32 BUG_ON(datasize > PAGE_SIZE || 33 (cplength*sizeof(struct ccw1)) > PAGE_SIZE); 34 35 size = (sizeof(struct dasd_ccw_req) + 7L) & -8L; 36 if (cplength > 0) 37 size += cplength * sizeof(struct ccw1); 38 if (datasize > 0) 39 size += datasize; 40 spin_lock_irqsave(&device->mem_lock, flags); 41 cqr = (struct dasd_ccw_req *) 42 dasd_alloc_chunk(&device->erp_chunks, size); 43 spin_unlock_irqrestore(&device->mem_lock, flags); 44 if (cqr == NULL) 45 return ERR_PTR(-ENOMEM); 46 memset(cqr, 0, sizeof(struct dasd_ccw_req)); 47 INIT_LIST_HEAD(&cqr->devlist); 48 INIT_LIST_HEAD(&cqr->blocklist); 49 data = (char *) cqr + ((sizeof(struct dasd_ccw_req) + 7L) & -8L); 50 cqr->cpaddr = NULL; 51 if (cplength > 0) { 52 cqr->cpaddr = (struct ccw1 *) data; 53 data += cplength*sizeof(struct ccw1); 54 memset(cqr->cpaddr, 0, cplength*sizeof(struct ccw1)); 55 } 56 cqr->data = NULL; 57 if (datasize > 0) { 58 cqr->data = data; 59 memset(cqr->data, 0, datasize); 60 } 61 cqr->magic = magic; 62 ASCEBC((char *) &cqr->magic, 4); 63 set_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags); 64 dasd_get_device(device); 65 return cqr; 66 } 67 68 void 69 dasd_free_erp_request(struct dasd_ccw_req *cqr, struct dasd_device * device) 70 { 71 unsigned long flags; 72 73 spin_lock_irqsave(&device->mem_lock, flags); 74 dasd_free_chunk(&device->erp_chunks, cqr); 75 spin_unlock_irqrestore(&device->mem_lock, flags); 76 atomic_dec(&device->ref_count); 77 } 78 79 80 /* 81 * dasd_default_erp_action just retries the current cqr 82 */ 83 struct dasd_ccw_req * 84 dasd_default_erp_action(struct dasd_ccw_req *cqr) 85 { 86 struct dasd_device *device; 87 88 device = cqr->startdev; 89 90 /* just retry - there is nothing to save ... I got no sense data.... */ 91 if (cqr->retries > 0) { 92 DBF_DEV_EVENT(DBF_DEBUG, device, 93 "default ERP called (%i retries left)", 94 cqr->retries); 95 if (!test_bit(DASD_CQR_VERIFY_PATH, &cqr->flags)) 96 cqr->lpm = dasd_path_get_opm(device); 97 cqr->status = DASD_CQR_FILLED; 98 } else { 99 pr_err("%s: default ERP has run out of retries and failed\n", 100 dev_name(&device->cdev->dev)); 101 cqr->status = DASD_CQR_FAILED; 102 cqr->stopclk = get_tod_clock(); 103 } 104 return cqr; 105 } /* end dasd_default_erp_action */ 106 107 /* 108 * DESCRIPTION 109 * Frees all ERPs of the current ERP Chain and set the status 110 * of the original CQR either to DASD_CQR_DONE if ERP was successful 111 * or to DASD_CQR_FAILED if ERP was NOT successful. 112 * NOTE: This function is only called if no discipline postaction 113 * is available 114 * 115 * PARAMETER 116 * erp current erp_head 117 * 118 * RETURN VALUES 119 * cqr pointer to the original CQR 120 */ 121 struct dasd_ccw_req *dasd_default_erp_postaction(struct dasd_ccw_req *cqr) 122 { 123 int success, aborted; 124 unsigned long startclk, stopclk; 125 struct dasd_device *startdev; 126 unsigned int proc_bytes; 127 128 BUG_ON(cqr->refers == NULL || cqr->function == NULL); 129 130 success = cqr->status == DASD_CQR_DONE; 131 aborted = cqr->status == DASD_CQR_ABORTED; 132 startclk = cqr->startclk; 133 stopclk = cqr->stopclk; 134 startdev = cqr->startdev; 135 proc_bytes = cqr->proc_bytes; 136 137 /* free all ERPs - but NOT the original cqr */ 138 while (cqr->refers != NULL) { 139 struct dasd_ccw_req *refers; 140 141 refers = cqr->refers; 142 /* remove the request from the block queue */ 143 list_del(&cqr->blocklist); 144 /* free the finished erp request */ 145 dasd_free_erp_request(cqr, cqr->memdev); 146 cqr = refers; 147 } 148 149 /* set corresponding status to original cqr */ 150 cqr->startclk = startclk; 151 cqr->stopclk = stopclk; 152 cqr->startdev = startdev; 153 cqr->proc_bytes = proc_bytes; 154 if (aborted) 155 /* base request is owned by the ESE format replacement CQR */ 156 cqr->status = DASD_CQR_ABORTED; 157 else if (success) 158 cqr->status = DASD_CQR_DONE; 159 else { 160 cqr->status = DASD_CQR_FAILED; 161 cqr->stopclk = get_tod_clock(); 162 } 163 164 return cqr; 165 166 } /* end default_erp_postaction */ 167 168 void 169 dasd_log_sense(struct dasd_ccw_req *cqr, struct irb *irb) 170 { 171 struct dasd_device *device; 172 173 device = cqr->startdev; 174 if (cqr->intrc == -ETIMEDOUT) { 175 dev_err(&device->cdev->dev, 176 "A timeout error occurred for cqr %px\n", cqr); 177 return; 178 } 179 if (cqr->intrc == -ENOLINK) { 180 dev_err(&device->cdev->dev, 181 "A transport error occurred for cqr %px\n", cqr); 182 return; 183 } 184 /* dump sense data */ 185 if (device->discipline && device->discipline->dump_sense) 186 device->discipline->dump_sense(device, cqr, irb); 187 } 188 189 void 190 dasd_log_sense_dbf(struct dasd_ccw_req *cqr, struct irb *irb) 191 { 192 struct dasd_device *device; 193 194 device = cqr->startdev; 195 /* dump sense data to s390 debugfeature*/ 196 if (device->discipline && device->discipline->dump_sense_dbf) 197 device->discipline->dump_sense_dbf(device, irb, "log"); 198 } 199 EXPORT_SYMBOL(dasd_log_sense_dbf); 200 201 EXPORT_SYMBOL(dasd_default_erp_action); 202 EXPORT_SYMBOL(dasd_default_erp_postaction); 203 EXPORT_SYMBOL(dasd_alloc_erp_request); 204 EXPORT_SYMBOL(dasd_free_erp_request); 205 EXPORT_SYMBOL(dasd_log_sense); 206 207