Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * Author(s)......: Holger Smolinski <Holger.Smolinski@de.ibm.com> |
| 3 | * Horst Hummel <Horst.Hummel@de.ibm.com> |
| 4 | * Carsten Otte <Cotte@de.ibm.com> |
| 5 | * Martin Schwidefsky <schwidefsky@de.ibm.com> |
| 6 | * Bugreports.to..: <Linux390@de.ibm.com> |
Heiko Carstens | a53c8fa | 2012-07-20 11:15:04 +0200 | [diff] [blame] | 7 | * Copyright IBM Corp. 1999, 2001 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | */ |
| 10 | |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 11 | #define KMSG_COMPONENT "dasd" |
| 12 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
| 25 | struct dasd_ccw_req * |
| 26 | dasd_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 */ |
Eric Sesterhenn | e048a8a | 2006-04-01 01:27:08 +0200 | [diff] [blame] | 35 | BUG_ON( magic == NULL || datasize > PAGE_SIZE || |
| 36 | (cplength*sizeof(struct ccw1)) > PAGE_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | |
| 38 | size = (sizeof(struct dasd_ccw_req) + 7L) & -8L; |
| 39 | if (cplength > 0) |
| 40 | size += cplength * sizeof(struct ccw1); |
| 41 | if (datasize > 0) |
| 42 | size += datasize; |
| 43 | spin_lock_irqsave(&device->mem_lock, flags); |
| 44 | cqr = (struct dasd_ccw_req *) |
| 45 | dasd_alloc_chunk(&device->erp_chunks, size); |
| 46 | spin_unlock_irqrestore(&device->mem_lock, flags); |
| 47 | if (cqr == NULL) |
| 48 | return ERR_PTR(-ENOMEM); |
| 49 | memset(cqr, 0, sizeof(struct dasd_ccw_req)); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 50 | INIT_LIST_HEAD(&cqr->devlist); |
| 51 | INIT_LIST_HEAD(&cqr->blocklist); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | data = (char *) cqr + ((sizeof(struct dasd_ccw_req) + 7L) & -8L); |
| 53 | cqr->cpaddr = NULL; |
| 54 | if (cplength > 0) { |
| 55 | cqr->cpaddr = (struct ccw1 *) data; |
| 56 | data += cplength*sizeof(struct ccw1); |
| 57 | memset(cqr->cpaddr, 0, cplength*sizeof(struct ccw1)); |
| 58 | } |
| 59 | cqr->data = NULL; |
| 60 | if (datasize > 0) { |
| 61 | cqr->data = data; |
| 62 | memset(cqr->data, 0, datasize); |
| 63 | } |
| 64 | strncpy((char *) &cqr->magic, magic, 4); |
| 65 | ASCEBC((char *) &cqr->magic, 4); |
| 66 | set_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags); |
| 67 | dasd_get_device(device); |
| 68 | return cqr; |
| 69 | } |
| 70 | |
| 71 | void |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 72 | 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] | 73 | { |
| 74 | unsigned long flags; |
| 75 | |
| 76 | spin_lock_irqsave(&device->mem_lock, flags); |
| 77 | dasd_free_chunk(&device->erp_chunks, cqr); |
| 78 | spin_unlock_irqrestore(&device->mem_lock, flags); |
| 79 | atomic_dec(&device->ref_count); |
| 80 | } |
| 81 | |
| 82 | |
| 83 | /* |
| 84 | * dasd_default_erp_action just retries the current cqr |
| 85 | */ |
| 86 | struct dasd_ccw_req * |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 87 | dasd_default_erp_action(struct dasd_ccw_req *cqr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | { |
| 89 | struct dasd_device *device; |
| 90 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 91 | device = cqr->startdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | |
| 93 | /* just retry - there is nothing to save ... I got no sense data.... */ |
| 94 | if (cqr->retries > 0) { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 95 | DBF_DEV_EVENT(DBF_DEBUG, device, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | "default ERP called (%i retries left)", |
| 97 | cqr->retries); |
Stefan Weinhuber | a4d26c6 | 2011-01-05 12:48:03 +0100 | [diff] [blame] | 98 | if (!test_bit(DASD_CQR_VERIFY_PATH, &cqr->flags)) |
| 99 | cqr->lpm = device->path_data.opm; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 100 | cqr->status = DASD_CQR_FILLED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | } else { |
Stefan Haberland | ca99dab | 2009-09-11 10:28:30 +0200 | [diff] [blame] | 102 | pr_err("%s: default ERP has run out of retries and failed\n", |
| 103 | dev_name(&device->cdev->dev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | cqr->status = DASD_CQR_FAILED; |
Heiko Carstens | 1aae056 | 2013-01-30 09:49:40 +0100 | [diff] [blame] | 105 | cqr->stopclk = get_tod_clock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | } |
| 107 | return cqr; |
| 108 | } /* end dasd_default_erp_action */ |
| 109 | |
| 110 | /* |
| 111 | * DESCRIPTION |
| 112 | * Frees all ERPs of the current ERP Chain and set the status |
| 113 | * of the original CQR either to DASD_CQR_DONE if ERP was successful |
| 114 | * or to DASD_CQR_FAILED if ERP was NOT successful. |
| 115 | * NOTE: This function is only called if no discipline postaction |
| 116 | * is available |
| 117 | * |
| 118 | * PARAMETER |
| 119 | * erp current erp_head |
| 120 | * |
| 121 | * RETURN VALUES |
| 122 | * cqr pointer to the original CQR |
| 123 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 124 | 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] | 125 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | int success; |
Stefan Weinhuber | fbd7003 | 2013-08-27 13:52:17 +0200 | [diff] [blame] | 127 | unsigned long long startclk, stopclk; |
| 128 | struct dasd_device *startdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | |
Eric Sesterhenn | e048a8a | 2006-04-01 01:27:08 +0200 | [diff] [blame] | 130 | BUG_ON(cqr->refers == NULL || cqr->function == NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | success = cqr->status == DASD_CQR_DONE; |
Stefan Weinhuber | fbd7003 | 2013-08-27 13:52:17 +0200 | [diff] [blame] | 133 | startclk = cqr->startclk; |
| 134 | stopclk = cqr->stopclk; |
| 135 | startdev = cqr->startdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 142 | /* remove the request from the block queue */ |
| 143 | list_del(&cqr->blocklist); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | /* free the finished erp request */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 145 | dasd_free_erp_request(cqr, cqr->memdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | cqr = refers; |
| 147 | } |
| 148 | |
| 149 | /* set corresponding status to original cqr */ |
Stefan Weinhuber | fbd7003 | 2013-08-27 13:52:17 +0200 | [diff] [blame] | 150 | cqr->startclk = startclk; |
| 151 | cqr->stopclk = stopclk; |
| 152 | cqr->startdev = startdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | if (success) |
| 154 | cqr->status = DASD_CQR_DONE; |
| 155 | else { |
| 156 | cqr->status = DASD_CQR_FAILED; |
Heiko Carstens | 1aae056 | 2013-01-30 09:49:40 +0100 | [diff] [blame] | 157 | cqr->stopclk = get_tod_clock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | return cqr; |
| 161 | |
| 162 | } /* end default_erp_postaction */ |
| 163 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | void |
| 165 | dasd_log_sense(struct dasd_ccw_req *cqr, struct irb *irb) |
| 166 | { |
| 167 | struct dasd_device *device; |
| 168 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 169 | device = cqr->startdev; |
Hannes Reinecke | f6f8034 | 2013-01-30 09:26:15 +0000 | [diff] [blame] | 170 | if (cqr->intrc == -ETIMEDOUT) { |
Stefan Weinhuber | 0ea46b0 | 2013-06-14 10:24:25 +0200 | [diff] [blame] | 171 | dev_err(&device->cdev->dev, |
| 172 | "A timeout error occurred for cqr %p", cqr); |
Hannes Reinecke | f6f8034 | 2013-01-30 09:26:15 +0000 | [diff] [blame] | 173 | return; |
| 174 | } |
| 175 | if (cqr->intrc == -ENOLINK) { |
Stefan Weinhuber | 0ea46b0 | 2013-06-14 10:24:25 +0200 | [diff] [blame] | 176 | dev_err(&device->cdev->dev, |
| 177 | "A transport error occurred for cqr %p", cqr); |
Hannes Reinecke | f6f8034 | 2013-01-30 09:26:15 +0000 | [diff] [blame] | 178 | return; |
| 179 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | /* dump sense data */ |
| 181 | if (device->discipline && device->discipline->dump_sense) |
| 182 | device->discipline->dump_sense(device, cqr, irb); |
| 183 | } |
| 184 | |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 185 | void |
| 186 | dasd_log_sense_dbf(struct dasd_ccw_req *cqr, struct irb *irb) |
| 187 | { |
| 188 | struct dasd_device *device; |
| 189 | |
| 190 | device = cqr->startdev; |
| 191 | /* dump sense data to s390 debugfeature*/ |
| 192 | if (device->discipline && device->discipline->dump_sense_dbf) |
Stefan Haberland | aeec92c | 2009-07-07 16:37:06 +0200 | [diff] [blame] | 193 | device->discipline->dump_sense_dbf(device, irb, "log"); |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 194 | } |
| 195 | EXPORT_SYMBOL(dasd_log_sense_dbf); |
| 196 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | EXPORT_SYMBOL(dasd_default_erp_action); |
| 198 | EXPORT_SYMBOL(dasd_default_erp_postaction); |
| 199 | EXPORT_SYMBOL(dasd_alloc_erp_request); |
| 200 | EXPORT_SYMBOL(dasd_free_erp_request); |
| 201 | EXPORT_SYMBOL(dasd_log_sense); |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 202 | |