Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
dasd_erp.c
Go to the documentation of this file.
1 /*
2  * Author(s)......: Holger Smolinski <[email protected]>
3  * Horst Hummel <[email protected]>
4  * Carsten Otte <[email protected]>
5  * Martin Schwidefsky <[email protected]>
6  * Bugreports.to..: <[email protected]>
7  * Copyright IBM Corp. 1999, 2001
8  *
9  */
10 
11 #define KMSG_COMPONENT "dasd"
12 
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 */
35  BUG_ON( magic == NULL || datasize > PAGE_SIZE ||
36  (cplength*sizeof(struct ccw1)) > PAGE_SIZE);
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));
50  INIT_LIST_HEAD(&cqr->devlist);
51  INIT_LIST_HEAD(&cqr->blocklist);
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);
67  dasd_get_device(device);
68  return cqr;
69 }
70 
71 void
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 *
88 {
89  struct dasd_device *device;
90 
91  device = cqr->startdev;
92 
93  /* just retry - there is nothing to save ... I got no sense data.... */
94  if (cqr->retries > 0) {
95  DBF_DEV_EVENT(DBF_DEBUG, device,
96  "default ERP called (%i retries left)",
97  cqr->retries);
98  if (!test_bit(DASD_CQR_VERIFY_PATH, &cqr->flags))
99  cqr->lpm = device->path_data.opm;
100  cqr->status = DASD_CQR_FILLED;
101  } else {
102  pr_err("%s: default ERP has run out of retries and failed\n",
103  dev_name(&device->cdev->dev));
104  cqr->status = DASD_CQR_FAILED;
105  cqr->stopclk = get_clock();
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  */
125 {
126  int success;
127 
128  BUG_ON(cqr->refers == NULL || cqr->function == NULL);
129 
130  success = cqr->status == DASD_CQR_DONE;
131 
132  /* free all ERPs - but NOT the original cqr */
133  while (cqr->refers != NULL) {
134  struct dasd_ccw_req *refers;
135 
136  refers = cqr->refers;
137  /* remove the request from the block queue */
138  list_del(&cqr->blocklist);
139  /* free the finished erp request */
140  dasd_free_erp_request(cqr, cqr->memdev);
141  cqr = refers;
142  }
143 
144  /* set corresponding status to original cqr */
145  if (success)
146  cqr->status = DASD_CQR_DONE;
147  else {
148  cqr->status = DASD_CQR_FAILED;
149  cqr->stopclk = get_clock();
150  }
151 
152  return cqr;
153 
154 } /* end default_erp_postaction */
155 
156 void
158 {
159  struct dasd_device *device;
160 
161  device = cqr->startdev;
162  /* dump sense data */
163  if (device->discipline && device->discipline->dump_sense)
164  device->discipline->dump_sense(device, cqr, irb);
165 }
166 
167 void
169 {
170  struct dasd_device *device;
171 
172  device = cqr->startdev;
173  /* dump sense data to s390 debugfeature*/
174  if (device->discipline && device->discipline->dump_sense_dbf)
175  device->discipline->dump_sense_dbf(device, irb, "log");
176 }
178 
184