Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | */ |
| 11 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include <linux/ctype.h> |
| 13 | #include <linux/init.h> |
| 14 | |
| 15 | #include <asm/debug.h> |
| 16 | #include <asm/ebcdic.h> |
| 17 | #include <asm/uaccess.h> |
| 18 | |
| 19 | /* This is ugly... */ |
| 20 | #define PRINTK_HEADER "dasd_erp:" |
| 21 | |
| 22 | #include "dasd_int.h" |
| 23 | |
| 24 | struct dasd_ccw_req * |
| 25 | dasd_alloc_erp_request(char *magic, int cplength, int datasize, |
| 26 | struct dasd_device * device) |
| 27 | { |
| 28 | unsigned long flags; |
| 29 | struct dasd_ccw_req *cqr; |
| 30 | char *data; |
| 31 | int size; |
| 32 | |
| 33 | /* Sanity checks */ |
Eric Sesterhenn | e048a8a | 2006-04-01 01:27:08 +0200 | [diff] [blame] | 34 | BUG_ON( magic == NULL || datasize > PAGE_SIZE || |
| 35 | (cplength*sizeof(struct ccw1)) > PAGE_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | |
| 37 | size = (sizeof(struct dasd_ccw_req) + 7L) & -8L; |
| 38 | if (cplength > 0) |
| 39 | size += cplength * sizeof(struct ccw1); |
| 40 | if (datasize > 0) |
| 41 | size += datasize; |
| 42 | spin_lock_irqsave(&device->mem_lock, flags); |
| 43 | cqr = (struct dasd_ccw_req *) |
| 44 | dasd_alloc_chunk(&device->erp_chunks, size); |
| 45 | spin_unlock_irqrestore(&device->mem_lock, flags); |
| 46 | if (cqr == NULL) |
| 47 | return ERR_PTR(-ENOMEM); |
| 48 | memset(cqr, 0, sizeof(struct dasd_ccw_req)); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame^] | 49 | INIT_LIST_HEAD(&cqr->devlist); |
| 50 | INIT_LIST_HEAD(&cqr->blocklist); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | data = (char *) cqr + ((sizeof(struct dasd_ccw_req) + 7L) & -8L); |
| 52 | cqr->cpaddr = NULL; |
| 53 | if (cplength > 0) { |
| 54 | cqr->cpaddr = (struct ccw1 *) data; |
| 55 | data += cplength*sizeof(struct ccw1); |
| 56 | memset(cqr->cpaddr, 0, cplength*sizeof(struct ccw1)); |
| 57 | } |
| 58 | cqr->data = NULL; |
| 59 | if (datasize > 0) { |
| 60 | cqr->data = data; |
| 61 | memset(cqr->data, 0, datasize); |
| 62 | } |
| 63 | strncpy((char *) &cqr->magic, magic, 4); |
| 64 | ASCEBC((char *) &cqr->magic, 4); |
| 65 | set_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags); |
| 66 | dasd_get_device(device); |
| 67 | return cqr; |
| 68 | } |
| 69 | |
| 70 | void |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame^] | 71 | 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] | 72 | { |
| 73 | unsigned long flags; |
| 74 | |
| 75 | spin_lock_irqsave(&device->mem_lock, flags); |
| 76 | dasd_free_chunk(&device->erp_chunks, cqr); |
| 77 | spin_unlock_irqrestore(&device->mem_lock, flags); |
| 78 | atomic_dec(&device->ref_count); |
| 79 | } |
| 80 | |
| 81 | |
| 82 | /* |
| 83 | * dasd_default_erp_action just retries the current cqr |
| 84 | */ |
| 85 | struct dasd_ccw_req * |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame^] | 86 | dasd_default_erp_action(struct dasd_ccw_req *cqr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | { |
| 88 | struct dasd_device *device; |
| 89 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame^] | 90 | device = cqr->startdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | |
| 92 | /* just retry - there is nothing to save ... I got no sense data.... */ |
| 93 | if (cqr->retries > 0) { |
Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame] | 94 | DEV_MESSAGE (KERN_DEBUG, device, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | "default ERP called (%i retries left)", |
| 96 | cqr->retries); |
| 97 | cqr->lpm = LPM_ANYPATH; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame^] | 98 | cqr->status = DASD_CQR_FILLED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | } else { |
| 100 | DEV_MESSAGE (KERN_WARNING, device, "%s", |
| 101 | "default ERP called (NO retry left)"); |
| 102 | cqr->status = DASD_CQR_FAILED; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame^] | 103 | cqr->stopclk = get_clock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | } |
| 105 | return cqr; |
| 106 | } /* end dasd_default_erp_action */ |
| 107 | |
| 108 | /* |
| 109 | * DESCRIPTION |
| 110 | * Frees all ERPs of the current ERP Chain and set the status |
| 111 | * of the original CQR either to DASD_CQR_DONE if ERP was successful |
| 112 | * or to DASD_CQR_FAILED if ERP was NOT successful. |
| 113 | * NOTE: This function is only called if no discipline postaction |
| 114 | * is available |
| 115 | * |
| 116 | * PARAMETER |
| 117 | * erp current erp_head |
| 118 | * |
| 119 | * RETURN VALUES |
| 120 | * cqr pointer to the original CQR |
| 121 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame^] | 122 | 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] | 123 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | int success; |
| 125 | |
Eric Sesterhenn | e048a8a | 2006-04-01 01:27:08 +0200 | [diff] [blame] | 126 | BUG_ON(cqr->refers == NULL || cqr->function == NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | success = cqr->status == DASD_CQR_DONE; |
| 129 | |
| 130 | /* free all ERPs - but NOT the original cqr */ |
| 131 | while (cqr->refers != NULL) { |
| 132 | struct dasd_ccw_req *refers; |
| 133 | |
| 134 | refers = cqr->refers; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame^] | 135 | /* remove the request from the block queue */ |
| 136 | list_del(&cqr->blocklist); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | /* free the finished erp request */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame^] | 138 | dasd_free_erp_request(cqr, cqr->memdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | cqr = refers; |
| 140 | } |
| 141 | |
| 142 | /* set corresponding status to original cqr */ |
| 143 | if (success) |
| 144 | cqr->status = DASD_CQR_DONE; |
| 145 | else { |
| 146 | cqr->status = DASD_CQR_FAILED; |
| 147 | cqr->stopclk = get_clock(); |
| 148 | } |
| 149 | |
| 150 | return cqr; |
| 151 | |
| 152 | } /* end default_erp_postaction */ |
| 153 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | void |
| 155 | dasd_log_sense(struct dasd_ccw_req *cqr, struct irb *irb) |
| 156 | { |
| 157 | struct dasd_device *device; |
| 158 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame^] | 159 | device = cqr->startdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | /* dump sense data */ |
| 161 | if (device->discipline && device->discipline->dump_sense) |
| 162 | device->discipline->dump_sense(device, cqr, irb); |
| 163 | } |
| 164 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | EXPORT_SYMBOL(dasd_default_erp_action); |
| 166 | EXPORT_SYMBOL(dasd_default_erp_postaction); |
| 167 | EXPORT_SYMBOL(dasd_alloc_erp_request); |
| 168 | EXPORT_SYMBOL(dasd_free_erp_request); |
| 169 | EXPORT_SYMBOL(dasd_log_sense); |