Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
Heiko Carstens | a53c8fa | 2012-07-20 11:15:04 +0200 | [diff] [blame] | 8 | * Copyright IBM Corp. 1999, 2001 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | */ |
| 11 | |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 12 | #define KMSG_COMPONENT "dasd" |
| 13 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <linux/ctype.h> |
| 15 | #include <linux/init.h> |
| 16 | |
| 17 | #include <asm/debug.h> |
| 18 | #include <asm/ebcdic.h> |
Linus Torvalds | 7c0f6ba | 2016-12-24 11:46:01 -0800 | [diff] [blame] | 19 | #include <linux/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | |
| 21 | /* This is ugly... */ |
| 22 | #define PRINTK_HEADER "dasd_erp:" |
| 23 | |
| 24 | #include "dasd_int.h" |
| 25 | |
| 26 | struct dasd_ccw_req * |
| 27 | dasd_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 Sesterhenn | e048a8a | 2006-04-01 01:27:08 +0200 | [diff] [blame] | 36 | BUG_ON( magic == NULL || datasize > PAGE_SIZE || |
| 37 | (cplength*sizeof(struct ccw1)) > PAGE_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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)); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 51 | INIT_LIST_HEAD(&cqr->devlist); |
| 52 | INIT_LIST_HEAD(&cqr->blocklist); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | 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 | |
| 72 | void |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 73 | dasd_free_erp_request(struct dasd_ccw_req *cqr, struct dasd_device * device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | { |
| 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 | */ |
| 87 | struct dasd_ccw_req * |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 88 | dasd_default_erp_action(struct dasd_ccw_req *cqr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | { |
| 90 | struct dasd_device *device; |
| 91 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 92 | device = cqr->startdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | |
| 94 | /* just retry - there is nothing to save ... I got no sense data.... */ |
| 95 | if (cqr->retries > 0) { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 96 | DBF_DEV_EVENT(DBF_DEBUG, device, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | "default ERP called (%i retries left)", |
| 98 | cqr->retries); |
Stefan Weinhuber | a4d26c6 | 2011-01-05 12:48:03 +0100 | [diff] [blame] | 99 | if (!test_bit(DASD_CQR_VERIFY_PATH, &cqr->flags)) |
Stefan Haberland | c934615 | 2016-08-08 15:53:54 +0200 | [diff] [blame] | 100 | cqr->lpm = dasd_path_get_opm(device); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 101 | cqr->status = DASD_CQR_FILLED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | } else { |
Stefan Haberland | ca99dab | 2009-09-11 10:28:30 +0200 | [diff] [blame] | 103 | pr_err("%s: default ERP has run out of retries and failed\n", |
| 104 | dev_name(&device->cdev->dev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | cqr->status = DASD_CQR_FAILED; |
Heiko Carstens | 1aae056 | 2013-01-30 09:49:40 +0100 | [diff] [blame] | 106 | cqr->stopclk = get_tod_clock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | } |
| 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 Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 125 | struct dasd_ccw_req *dasd_default_erp_postaction(struct dasd_ccw_req *cqr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | int success; |
Jan Höppner | 7bf76f01 | 2017-08-15 16:40:18 +0200 | [diff] [blame] | 128 | unsigned long startclk, stopclk; |
Stefan Weinhuber | fbd7003 | 2013-08-27 13:52:17 +0200 | [diff] [blame] | 129 | struct dasd_device *startdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | |
Eric Sesterhenn | e048a8a | 2006-04-01 01:27:08 +0200 | [diff] [blame] | 131 | BUG_ON(cqr->refers == NULL || cqr->function == NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | success = cqr->status == DASD_CQR_DONE; |
Stefan Weinhuber | fbd7003 | 2013-08-27 13:52:17 +0200 | [diff] [blame] | 134 | startclk = cqr->startclk; |
| 135 | stopclk = cqr->stopclk; |
| 136 | startdev = cqr->startdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | |
| 138 | /* free all ERPs - but NOT the original cqr */ |
| 139 | while (cqr->refers != NULL) { |
| 140 | struct dasd_ccw_req *refers; |
| 141 | |
| 142 | refers = cqr->refers; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 143 | /* remove the request from the block queue */ |
| 144 | list_del(&cqr->blocklist); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | /* free the finished erp request */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 146 | dasd_free_erp_request(cqr, cqr->memdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | cqr = refers; |
| 148 | } |
| 149 | |
| 150 | /* set corresponding status to original cqr */ |
Stefan Weinhuber | fbd7003 | 2013-08-27 13:52:17 +0200 | [diff] [blame] | 151 | cqr->startclk = startclk; |
| 152 | cqr->stopclk = stopclk; |
| 153 | cqr->startdev = startdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | if (success) |
| 155 | cqr->status = DASD_CQR_DONE; |
| 156 | else { |
| 157 | cqr->status = DASD_CQR_FAILED; |
Heiko Carstens | 1aae056 | 2013-01-30 09:49:40 +0100 | [diff] [blame] | 158 | cqr->stopclk = get_tod_clock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | return cqr; |
| 162 | |
| 163 | } /* end default_erp_postaction */ |
| 164 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | void |
| 166 | dasd_log_sense(struct dasd_ccw_req *cqr, struct irb *irb) |
| 167 | { |
| 168 | struct dasd_device *device; |
| 169 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 170 | device = cqr->startdev; |
Hannes Reinecke | f6f8034 | 2013-01-30 09:26:15 +0000 | [diff] [blame] | 171 | if (cqr->intrc == -ETIMEDOUT) { |
Stefan Weinhuber | 0ea46b0 | 2013-06-14 10:24:25 +0200 | [diff] [blame] | 172 | dev_err(&device->cdev->dev, |
Colin Ian King | 871f8bf | 2016-09-27 12:13:18 -0700 | [diff] [blame] | 173 | "A timeout error occurred for cqr %p\n", cqr); |
Hannes Reinecke | f6f8034 | 2013-01-30 09:26:15 +0000 | [diff] [blame] | 174 | return; |
| 175 | } |
| 176 | if (cqr->intrc == -ENOLINK) { |
Stefan Weinhuber | 0ea46b0 | 2013-06-14 10:24:25 +0200 | [diff] [blame] | 177 | dev_err(&device->cdev->dev, |
Colin Ian King | 871f8bf | 2016-09-27 12:13:18 -0700 | [diff] [blame] | 178 | "A transport error occurred for cqr %p\n", cqr); |
Hannes Reinecke | f6f8034 | 2013-01-30 09:26:15 +0000 | [diff] [blame] | 179 | return; |
| 180 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | /* dump sense data */ |
| 182 | if (device->discipline && device->discipline->dump_sense) |
| 183 | device->discipline->dump_sense(device, cqr, irb); |
| 184 | } |
| 185 | |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 186 | void |
| 187 | dasd_log_sense_dbf(struct dasd_ccw_req *cqr, struct irb *irb) |
| 188 | { |
| 189 | struct dasd_device *device; |
| 190 | |
| 191 | device = cqr->startdev; |
| 192 | /* dump sense data to s390 debugfeature*/ |
| 193 | if (device->discipline && device->discipline->dump_sense_dbf) |
Stefan Haberland | aeec92c | 2009-07-07 16:37:06 +0200 | [diff] [blame] | 194 | device->discipline->dump_sense_dbf(device, irb, "log"); |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 195 | } |
| 196 | EXPORT_SYMBOL(dasd_log_sense_dbf); |
| 197 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | EXPORT_SYMBOL(dasd_default_erp_action); |
| 199 | EXPORT_SYMBOL(dasd_default_erp_postaction); |
| 200 | EXPORT_SYMBOL(dasd_alloc_erp_request); |
| 201 | EXPORT_SYMBOL(dasd_free_erp_request); |
| 202 | EXPORT_SYMBOL(dasd_log_sense); |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 203 | |