blob: c196827c228fb9f3ce79412e7422051f2307d14d [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * 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 Carstensa53c8fa2012-07-20 11:15:04 +02007 * Copyright IBM Corp. 1999,2001
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 *
9 * Device mapping and dasd= parameter parsing functions. All devmap
10 * functions may not be called from interrupt context. In particular
11 * dasd_get_device is a no-no from interrupt context.
12 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 */
14
Stefan Haberlandfc19f382009-03-26 15:23:49 +010015#define KMSG_COMPONENT "dasd"
16
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <linux/ctype.h>
18#include <linux/init.h>
Rusty Russell8d3b33f2006-03-25 03:07:05 -080019#include <linux/module.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090020#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
22#include <asm/debug.h>
23#include <asm/uaccess.h>
Peter Oberparleiter7039d3a2007-04-27 16:01:48 +020024#include <asm/ipl.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025
26/* This is ugly... */
27#define PRINTK_HEADER "dasd_devmap:"
Kay Sievers98df67b2008-12-25 13:38:55 +010028#define DASD_BUS_ID_SIZE 20
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
30#include "dasd_int.h"
31
Christoph Lametere18b8902006-12-06 20:33:20 -080032struct kmem_cache *dasd_page_cache;
Horst Hummel40545572006-06-29 15:08:18 +020033EXPORT_SYMBOL_GPL(dasd_page_cache);
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
35/*
36 * dasd_devmap_t is used to store the features and the relation
37 * between device number and device index. To find a dasd_devmap_t
38 * that corresponds to a device number of a device index each
39 * dasd_devmap_t is added to two linked lists, one to search by
40 * the device number and one to search by the device index. As
41 * soon as big minor numbers are available the device index list
42 * can be removed since the device number will then be identical
43 * to the device index.
44 */
45struct dasd_devmap {
46 struct list_head list;
Kay Sievers98df67b2008-12-25 13:38:55 +010047 char bus_id[DASD_BUS_ID_SIZE];
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 unsigned int devindex;
49 unsigned short features;
50 struct dasd_device *device;
51};
52
53/*
54 * Parameter parsing functions for dasd= parameter. The syntax is:
55 * <devno> : (0x)?[0-9a-fA-F]+
56 * <busid> : [0-0a-f]\.[0-9a-f]\.(0x)?[0-9a-fA-F]+
57 * <feature> : ro
58 * <feature_list> : \(<feature>(:<feature>)*\)
59 * <devno-range> : <devno>(-<devno>)?<feature_list>?
60 * <busid-range> : <busid>(-<busid>)?<feature_list>?
61 * <devices> : <devno-range>|<busid-range>
62 * <dasd_module> : dasd_diag_mod|dasd_eckd_mod|dasd_fba_mod
63 *
64 * <dasd> : autodetect|probeonly|<devices>(,<devices>)*
65 */
66
67int dasd_probeonly = 0; /* is true, when probeonly mode is active */
68int dasd_autodetect = 0; /* is true, when autodetection is active */
Horst Hummel40545572006-06-29 15:08:18 +020069int dasd_nopav = 0; /* is true, when PAV is disabled */
70EXPORT_SYMBOL_GPL(dasd_nopav);
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +010071int dasd_nofcx; /* disable High Performance Ficon */
72EXPORT_SYMBOL_GPL(dasd_nofcx);
Linus Torvalds1da177e2005-04-16 15:20:36 -070073
74/*
75 * char *dasd[] is intended to hold the ranges supplied by the dasd= statement
76 * it is named 'dasd' to directly be filled by insmod with the comma separated
77 * strings when running as a module.
78 */
79static char *dasd[256];
Rusty Russell8d3b33f2006-03-25 03:07:05 -080080module_param_array(dasd, charp, NULL, 0);
81
Linus Torvalds1da177e2005-04-16 15:20:36 -070082/*
Horst Hummeld0710c72006-08-10 15:45:16 +020083 * Single spinlock to protect devmap and servermap structures and lists.
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 */
85static DEFINE_SPINLOCK(dasd_devmap_lock);
86
87/*
88 * Hash lists for devmap structures.
89 */
90static struct list_head dasd_hashlists[256];
91int dasd_max_devindex;
92
Cornelia Huck69f90f62008-05-15 16:52:34 +020093static struct dasd_devmap *dasd_add_busid(const char *, int);
Linus Torvalds1da177e2005-04-16 15:20:36 -070094
95static inline int
Cornelia Huck69f90f62008-05-15 16:52:34 +020096dasd_hash_busid(const char *bus_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -070097{
98 int hash, i;
99
100 hash = 0;
Kay Sievers98df67b2008-12-25 13:38:55 +0100101 for (i = 0; (i < DASD_BUS_ID_SIZE) && *bus_id; i++, bus_id++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 hash += *bus_id;
103 return hash & 0xff;
104}
105
106#ifndef MODULE
107/*
108 * The parameter parsing functions for builtin-drivers are called
109 * before kmalloc works. Store the pointers to the parameters strings
110 * into dasd[] for later processing.
111 */
112static int __init
113dasd_call_setup(char *str)
114{
115 static int count = 0;
116
117 if (count < 256)
118 dasd[count++] = str;
119 return 1;
120}
121
122__setup ("dasd=", dasd_call_setup);
123#endif /* #ifndef MODULE */
124
Peter Oberparleiter7039d3a2007-04-27 16:01:48 +0200125#define DASD_IPLDEV "ipldev"
126
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127/*
128 * Read a device busid/devno from a string.
129 */
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100130static int
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100131
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132dasd_busid(char **str, int *id0, int *id1, int *devno)
133{
134 int val, old_style;
Horst Hummel138c0142006-06-29 14:58:12 +0200135
Peter Oberparleiter7039d3a2007-04-27 16:01:48 +0200136 /* Interpret ipldev busid */
137 if (strncmp(DASD_IPLDEV, *str, strlen(DASD_IPLDEV)) == 0) {
138 if (ipl_info.type != IPL_TYPE_CCW) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100139 pr_err("The IPL device is not a CCW device\n");
Peter Oberparleiter7039d3a2007-04-27 16:01:48 +0200140 return -EINVAL;
141 }
142 *id0 = 0;
143 *id1 = ipl_info.data.ccw.dev_id.ssid;
144 *devno = ipl_info.data.ccw.dev_id.devno;
145 *str += strlen(DASD_IPLDEV);
146
147 return 0;
148 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 /* check for leading '0x' */
150 old_style = 0;
151 if ((*str)[0] == '0' && (*str)[1] == 'x') {
152 *str += 2;
153 old_style = 1;
154 }
155 if (!isxdigit((*str)[0])) /* We require at least one hex digit */
156 return -EINVAL;
157 val = simple_strtoul(*str, str, 16);
158 if (old_style || (*str)[0] != '.') {
159 *id0 = *id1 = 0;
160 if (val < 0 || val > 0xffff)
161 return -EINVAL;
162 *devno = val;
163 return 0;
164 }
165 /* New style x.y.z busid */
166 if (val < 0 || val > 0xff)
167 return -EINVAL;
168 *id0 = val;
169 (*str)++;
170 if (!isxdigit((*str)[0])) /* We require at least one hex digit */
171 return -EINVAL;
172 val = simple_strtoul(*str, str, 16);
173 if (val < 0 || val > 0xff || (*str)++[0] != '.')
174 return -EINVAL;
175 *id1 = val;
176 if (!isxdigit((*str)[0])) /* We require at least one hex digit */
177 return -EINVAL;
178 val = simple_strtoul(*str, str, 16);
179 if (val < 0 || val > 0xffff)
180 return -EINVAL;
181 *devno = val;
182 return 0;
183}
184
185/*
186 * Read colon separated list of dasd features. Currently there is
187 * only one: "ro" for read-only devices. The default feature set
188 * is empty (value 0).
189 */
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100190static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191dasd_feature_list(char *str, char **endp)
192{
193 int features, len, rc;
194
195 rc = 0;
196 if (*str != '(') {
197 *endp = str;
198 return DASD_FEATURE_DEFAULT;
199 }
200 str++;
201 features = 0;
202
203 while (1) {
Horst Hummel138c0142006-06-29 14:58:12 +0200204 for (len = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 str[len] && str[len] != ':' && str[len] != ')'; len++);
206 if (len == 2 && !strncmp(str, "ro", 2))
207 features |= DASD_FEATURE_READONLY;
208 else if (len == 4 && !strncmp(str, "diag", 4))
209 features |= DASD_FEATURE_USEDIAG;
Stefan Haberlande4dbb0f2011-01-05 12:48:06 +0100210 else if (len == 3 && !strncmp(str, "raw", 3))
211 features |= DASD_FEATURE_USERAW;
Horst Hummel9575bf22006-12-08 15:54:15 +0100212 else if (len == 6 && !strncmp(str, "erplog", 6))
213 features |= DASD_FEATURE_ERPLOG;
Holger Smolinski13de2272009-01-09 12:14:51 +0100214 else if (len == 8 && !strncmp(str, "failfast", 8))
215 features |= DASD_FEATURE_FAILFAST;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 else {
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100217 pr_warning("%*s is not a supported device option\n",
218 len, str);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 rc = -EINVAL;
220 }
221 str += len;
222 if (*str != ':')
223 break;
224 str++;
225 }
226 if (*str != ')') {
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100227 pr_warning("A closing parenthesis ')' is missing in the "
228 "dasd= parameter\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 rc = -EINVAL;
230 } else
231 str++;
232 *endp = str;
233 if (rc != 0)
234 return rc;
235 return features;
236}
237
238/*
239 * Try to match the first element on the comma separated parse string
240 * with one of the known keywords. If a keyword is found, take the approprate
241 * action and return a pointer to the residual string. If the first element
242 * could not be matched to any keyword then return an error code.
243 */
244static char *
245dasd_parse_keyword( char *parsestring ) {
246
247 char *nextcomma, *residual_str;
248 int length;
249
250 nextcomma = strchr(parsestring,',');
251 if (nextcomma) {
252 length = nextcomma - parsestring;
253 residual_str = nextcomma + 1;
254 } else {
255 length = strlen(parsestring);
256 residual_str = parsestring + length;
257 }
Horst Hummel40545572006-06-29 15:08:18 +0200258 if (strncmp("autodetect", parsestring, length) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 dasd_autodetect = 1;
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100260 pr_info("The autodetection mode has been activated\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 return residual_str;
262 }
Horst Hummel40545572006-06-29 15:08:18 +0200263 if (strncmp("probeonly", parsestring, length) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 dasd_probeonly = 1;
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100265 pr_info("The probeonly mode has been activated\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 return residual_str;
267 }
Horst Hummel40545572006-06-29 15:08:18 +0200268 if (strncmp("nopav", parsestring, length) == 0) {
Peter Oberparleiterdcd707b2006-09-20 15:59:52 +0200269 if (MACHINE_IS_VM)
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100270 pr_info("'nopav' is not supported on z/VM\n");
Peter Oberparleiterdcd707b2006-09-20 15:59:52 +0200271 else {
272 dasd_nopav = 1;
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100273 pr_info("PAV support has be deactivated\n");
Peter Oberparleiterdcd707b2006-09-20 15:59:52 +0200274 }
Horst Hummel40545572006-06-29 15:08:18 +0200275 return residual_str;
276 }
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +0100277 if (strncmp("nofcx", parsestring, length) == 0) {
278 dasd_nofcx = 1;
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100279 pr_info("High Performance FICON support has been "
280 "deactivated\n");
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +0100281 return residual_str;
282 }
Horst Hummel40545572006-06-29 15:08:18 +0200283 if (strncmp("fixedbuffers", parsestring, length) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 if (dasd_page_cache)
285 return residual_str;
286 dasd_page_cache =
Heiko Carstens2f6c55f2006-08-16 13:49:27 +0200287 kmem_cache_create("dasd_page_cache", PAGE_SIZE,
288 PAGE_SIZE, SLAB_CACHE_DMA,
Paul Mundt20c2df82007-07-20 10:11:58 +0900289 NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 if (!dasd_page_cache)
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100291 DBF_EVENT(DBF_WARNING, "%s", "Failed to create slab, "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 "fixed buffer mode disabled.");
293 else
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100294 DBF_EVENT(DBF_INFO, "%s",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 "turning on fixed buffer mode");
296 return residual_str;
297 }
298 return ERR_PTR(-EINVAL);
299}
300
301/*
302 * Try to interprete the first element on the comma separated parse string
303 * as a device number or a range of devices. If the interpretation is
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300304 * successful, create the matching dasd_devmap entries and return a pointer
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 * to the residual string.
306 * If interpretation fails or in case of an error, return an error code.
307 */
308static char *
309dasd_parse_range( char *parsestring ) {
310
311 struct dasd_devmap *devmap;
312 int from, from_id0, from_id1;
313 int to, to_id0, to_id1;
314 int features, rc;
Kay Sievers98df67b2008-12-25 13:38:55 +0100315 char bus_id[DASD_BUS_ID_SIZE+1], *str;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316
317 str = parsestring;
318 rc = dasd_busid(&str, &from_id0, &from_id1, &from);
319 if (rc == 0) {
320 to = from;
321 to_id0 = from_id0;
322 to_id1 = from_id1;
323 if (*str == '-') {
324 str++;
325 rc = dasd_busid(&str, &to_id0, &to_id1, &to);
326 }
327 }
328 if (rc == 0 &&
329 (from_id0 != to_id0 || from_id1 != to_id1 || from > to))
330 rc = -EINVAL;
331 if (rc) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100332 pr_err("%s is not a valid device range\n", parsestring);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 return ERR_PTR(rc);
334 }
335 features = dasd_feature_list(str, &str);
336 if (features < 0)
337 return ERR_PTR(-EINVAL);
Horst Hummel40545572006-06-29 15:08:18 +0200338 /* each device in dasd= parameter should be set initially online */
339 features |= DASD_FEATURE_INITIAL_ONLINE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 while (from <= to) {
341 sprintf(bus_id, "%01x.%01x.%04x",
342 from_id0, from_id1, from++);
343 devmap = dasd_add_busid(bus_id, features);
344 if (IS_ERR(devmap))
345 return (char *)devmap;
346 }
347 if (*str == ',')
348 return str + 1;
349 if (*str == '\0')
350 return str;
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100351 pr_warning("The dasd= parameter value %s has an invalid ending\n",
352 str);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 return ERR_PTR(-EINVAL);
354}
355
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100356static char *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357dasd_parse_next_element( char *parsestring ) {
358 char * residual_str;
359 residual_str = dasd_parse_keyword(parsestring);
360 if (!IS_ERR(residual_str))
361 return residual_str;
362 residual_str = dasd_parse_range(parsestring);
363 return residual_str;
364}
365
366/*
367 * Parse parameters stored in dasd[]
368 * The 'dasd=...' parameter allows to specify a comma separated list of
369 * keywords and device ranges. When the dasd driver is build into the kernel,
370 * the complete list will be stored as one element of the dasd[] array.
371 * When the dasd driver is build as a module, then the list is broken into
372 * it's elements and each dasd[] entry contains one element.
373 */
374int
375dasd_parse(void)
376{
377 int rc, i;
378 char *parsestring;
379
380 rc = 0;
381 for (i = 0; i < 256; i++) {
382 if (dasd[i] == NULL)
383 break;
384 parsestring = dasd[i];
385 /* loop over the comma separated list in the parsestring */
386 while (*parsestring) {
387 parsestring = dasd_parse_next_element(parsestring);
388 if(IS_ERR(parsestring)) {
389 rc = PTR_ERR(parsestring);
390 break;
391 }
392 }
393 if (rc) {
394 DBF_EVENT(DBF_ALERT, "%s", "invalid range found");
395 break;
396 }
397 }
398 return rc;
399}
400
401/*
402 * Add a devmap for the device specified by busid. It is possible that
403 * the devmap already exists (dasd= parameter). The order of the devices
404 * added through this function will define the kdevs for the individual
Horst Hummel138c0142006-06-29 14:58:12 +0200405 * devices.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 */
407static struct dasd_devmap *
Cornelia Huck69f90f62008-05-15 16:52:34 +0200408dasd_add_busid(const char *bus_id, int features)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409{
410 struct dasd_devmap *devmap, *new, *tmp;
411 int hash;
412
413 new = (struct dasd_devmap *)
Horst Hummel138c0142006-06-29 14:58:12 +0200414 kzalloc(sizeof(struct dasd_devmap), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 if (!new)
416 return ERR_PTR(-ENOMEM);
417 spin_lock(&dasd_devmap_lock);
Heiko Carstensd2c993d2006-07-12 16:41:55 +0200418 devmap = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 hash = dasd_hash_busid(bus_id);
420 list_for_each_entry(tmp, &dasd_hashlists[hash], list)
Kay Sievers98df67b2008-12-25 13:38:55 +0100421 if (strncmp(tmp->bus_id, bus_id, DASD_BUS_ID_SIZE) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 devmap = tmp;
423 break;
424 }
425 if (!devmap) {
426 /* This bus_id is new. */
427 new->devindex = dasd_max_devindex++;
Kay Sievers98df67b2008-12-25 13:38:55 +0100428 strncpy(new->bus_id, bus_id, DASD_BUS_ID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 new->features = features;
Heiko Carstensd2c993d2006-07-12 16:41:55 +0200430 new->device = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 list_add(&new->list, &dasd_hashlists[hash]);
432 devmap = new;
Heiko Carstensd2c993d2006-07-12 16:41:55 +0200433 new = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 }
435 spin_unlock(&dasd_devmap_lock);
Jesper Juhl17fd6822005-11-07 01:01:30 -0800436 kfree(new);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 return devmap;
438}
439
440/*
441 * Find devmap for device with given bus_id.
442 */
443static struct dasd_devmap *
Cornelia Huck69f90f62008-05-15 16:52:34 +0200444dasd_find_busid(const char *bus_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445{
446 struct dasd_devmap *devmap, *tmp;
447 int hash;
448
449 spin_lock(&dasd_devmap_lock);
450 devmap = ERR_PTR(-ENODEV);
451 hash = dasd_hash_busid(bus_id);
452 list_for_each_entry(tmp, &dasd_hashlists[hash], list) {
Kay Sievers98df67b2008-12-25 13:38:55 +0100453 if (strncmp(tmp->bus_id, bus_id, DASD_BUS_ID_SIZE) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 devmap = tmp;
455 break;
456 }
457 }
458 spin_unlock(&dasd_devmap_lock);
459 return devmap;
460}
461
462/*
463 * Check if busid has been added to the list of dasd ranges.
464 */
465int
Cornelia Huck69f90f62008-05-15 16:52:34 +0200466dasd_busid_known(const char *bus_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467{
468 return IS_ERR(dasd_find_busid(bus_id)) ? -ENOENT : 0;
469}
470
471/*
472 * Forget all about the device numbers added so far.
473 * This may only be called at module unload or system shutdown.
474 */
475static void
476dasd_forget_ranges(void)
477{
478 struct dasd_devmap *devmap, *n;
479 int i;
480
481 spin_lock(&dasd_devmap_lock);
482 for (i = 0; i < 256; i++) {
483 list_for_each_entry_safe(devmap, n, &dasd_hashlists[i], list) {
Eric Sesterhenn606f4422006-03-26 18:33:07 +0200484 BUG_ON(devmap->device != NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 list_del(&devmap->list);
486 kfree(devmap);
487 }
488 }
489 spin_unlock(&dasd_devmap_lock);
490}
491
492/*
493 * Find the device struct by its device index.
494 */
495struct dasd_device *
496dasd_device_from_devindex(int devindex)
497{
498 struct dasd_devmap *devmap, *tmp;
499 struct dasd_device *device;
500 int i;
501
502 spin_lock(&dasd_devmap_lock);
Heiko Carstensd2c993d2006-07-12 16:41:55 +0200503 devmap = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 for (i = 0; (i < 256) && !devmap; i++)
505 list_for_each_entry(tmp, &dasd_hashlists[i], list)
506 if (tmp->devindex == devindex) {
507 /* Found the devmap for the device. */
508 devmap = tmp;
509 break;
510 }
511 if (devmap && devmap->device) {
512 device = devmap->device;
513 dasd_get_device(device);
514 } else
515 device = ERR_PTR(-ENODEV);
516 spin_unlock(&dasd_devmap_lock);
517 return device;
518}
519
520/*
521 * Return devmap for cdev. If no devmap exists yet, create one and
522 * connect it to the cdev.
523 */
524static struct dasd_devmap *
525dasd_devmap_from_cdev(struct ccw_device *cdev)
526{
527 struct dasd_devmap *devmap;
528
Kay Sievers2a0217d2008-10-10 21:33:09 +0200529 devmap = dasd_find_busid(dev_name(&cdev->dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 if (IS_ERR(devmap))
Kay Sievers2a0217d2008-10-10 21:33:09 +0200531 devmap = dasd_add_busid(dev_name(&cdev->dev),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 DASD_FEATURE_DEFAULT);
533 return devmap;
534}
535
536/*
537 * Create a dasd device structure for cdev.
538 */
539struct dasd_device *
540dasd_create_device(struct ccw_device *cdev)
541{
542 struct dasd_devmap *devmap;
543 struct dasd_device *device;
Martin Schwidefskya00bfd72006-09-20 15:59:05 +0200544 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 int rc;
546
547 devmap = dasd_devmap_from_cdev(cdev);
548 if (IS_ERR(devmap))
549 return (void *) devmap;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550
551 device = dasd_alloc_device();
552 if (IS_ERR(device))
553 return device;
Martin Schwidefskya00bfd72006-09-20 15:59:05 +0200554 atomic_set(&device->ref_count, 3);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555
556 spin_lock(&dasd_devmap_lock);
557 if (!devmap->device) {
558 devmap->device = device;
559 device->devindex = devmap->devindex;
Horst Hummelc6eb7b72005-09-03 15:57:58 -0700560 device->features = devmap->features;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 get_device(&cdev->dev);
562 device->cdev = cdev;
563 rc = 0;
564 } else
565 /* Someone else was faster. */
566 rc = -EBUSY;
567 spin_unlock(&dasd_devmap_lock);
568
569 if (rc) {
570 dasd_free_device(device);
571 return ERR_PTR(rc);
572 }
Martin Schwidefskya00bfd72006-09-20 15:59:05 +0200573
574 spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
Cornelia Huckfaf16aa2008-12-25 13:38:52 +0100575 dev_set_drvdata(&cdev->dev, device);
Martin Schwidefskya00bfd72006-09-20 15:59:05 +0200576 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
577
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 return device;
579}
580
581/*
582 * Wait queue for dasd_delete_device waits.
583 */
584static DECLARE_WAIT_QUEUE_HEAD(dasd_delete_wq);
585
586/*
587 * Remove a dasd device structure. The passed referenced
588 * is destroyed.
589 */
590void
591dasd_delete_device(struct dasd_device *device)
592{
593 struct ccw_device *cdev;
594 struct dasd_devmap *devmap;
Martin Schwidefskya00bfd72006-09-20 15:59:05 +0200595 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596
597 /* First remove device pointer from devmap. */
Kay Sievers2a0217d2008-10-10 21:33:09 +0200598 devmap = dasd_find_busid(dev_name(&device->cdev->dev));
Eric Sesterhenn606f4422006-03-26 18:33:07 +0200599 BUG_ON(IS_ERR(devmap));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 spin_lock(&dasd_devmap_lock);
601 if (devmap->device != device) {
602 spin_unlock(&dasd_devmap_lock);
603 dasd_put_device(device);
604 return;
605 }
606 devmap->device = NULL;
607 spin_unlock(&dasd_devmap_lock);
608
Martin Schwidefskya00bfd72006-09-20 15:59:05 +0200609 /* Disconnect dasd_device structure from ccw_device structure. */
610 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
Cornelia Huckfaf16aa2008-12-25 13:38:52 +0100611 dev_set_drvdata(&device->cdev->dev, NULL);
Martin Schwidefskya00bfd72006-09-20 15:59:05 +0200612 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
613
614 /*
615 * Drop ref_count by 3, one for the devmap reference, one for
616 * the cdev reference and one for the passed reference.
617 */
618 atomic_sub(3, &device->ref_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619
620 /* Wait for reference counter to drop to zero. */
621 wait_event(dasd_delete_wq, atomic_read(&device->ref_count) == 0);
622
623 /* Disconnect dasd_device structure from ccw_device structure. */
624 cdev = device->cdev;
625 device->cdev = NULL;
626
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 /* Put ccw_device structure. */
628 put_device(&cdev->dev);
629
630 /* Now the device structure can be freed. */
631 dasd_free_device(device);
632}
633
634/*
635 * Reference counter dropped to zero. Wake up waiter
636 * in dasd_delete_device.
637 */
638void
639dasd_put_device_wake(struct dasd_device *device)
640{
641 wake_up(&dasd_delete_wq);
642}
Stefan Weinhubera4d26c62011-01-05 12:48:03 +0100643EXPORT_SYMBOL_GPL(dasd_put_device_wake);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644
645/*
646 * Return dasd_device structure associated with cdev.
Martin Schwidefskya00bfd72006-09-20 15:59:05 +0200647 * This function needs to be called with the ccw device
648 * lock held. It can be used from interrupt context.
649 */
650struct dasd_device *
651dasd_device_from_cdev_locked(struct ccw_device *cdev)
652{
Cornelia Huckfaf16aa2008-12-25 13:38:52 +0100653 struct dasd_device *device = dev_get_drvdata(&cdev->dev);
Martin Schwidefskya00bfd72006-09-20 15:59:05 +0200654
655 if (!device)
656 return ERR_PTR(-ENODEV);
657 dasd_get_device(device);
658 return device;
659}
660
661/*
662 * Return dasd_device structure associated with cdev.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 */
664struct dasd_device *
665dasd_device_from_cdev(struct ccw_device *cdev)
666{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 struct dasd_device *device;
Martin Schwidefskya00bfd72006-09-20 15:59:05 +0200668 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669
Martin Schwidefskya00bfd72006-09-20 15:59:05 +0200670 spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
671 device = dasd_device_from_cdev_locked(cdev);
672 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 return device;
674}
675
Stefan Weinhuber65f8da42011-04-20 10:15:30 +0200676void dasd_add_link_to_gendisk(struct gendisk *gdp, struct dasd_device *device)
677{
678 struct dasd_devmap *devmap;
679
680 devmap = dasd_find_busid(dev_name(&device->cdev->dev));
681 if (IS_ERR(devmap))
682 return;
683 spin_lock(&dasd_devmap_lock);
684 gdp->private_data = devmap;
685 spin_unlock(&dasd_devmap_lock);
686}
687
688struct dasd_device *dasd_device_from_gendisk(struct gendisk *gdp)
689{
690 struct dasd_device *device;
691 struct dasd_devmap *devmap;
692
693 if (!gdp->private_data)
694 return NULL;
695 device = NULL;
696 spin_lock(&dasd_devmap_lock);
697 devmap = gdp->private_data;
698 if (devmap && devmap->device) {
699 device = devmap->device;
700 dasd_get_device(device);
701 }
702 spin_unlock(&dasd_devmap_lock);
703 return device;
704}
705
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706/*
707 * SECTION: files in sysfs
708 */
709
710/*
Holger Smolinski13de2272009-01-09 12:14:51 +0100711 * failfast controls the behaviour, if no path is available
712 */
713static ssize_t dasd_ff_show(struct device *dev, struct device_attribute *attr,
714 char *buf)
715{
716 struct dasd_devmap *devmap;
717 int ff_flag;
718
Cornelia Huckca0b4b72009-02-11 10:37:30 +0100719 devmap = dasd_find_busid(dev_name(dev));
Holger Smolinski13de2272009-01-09 12:14:51 +0100720 if (!IS_ERR(devmap))
721 ff_flag = (devmap->features & DASD_FEATURE_FAILFAST) != 0;
722 else
723 ff_flag = (DASD_FEATURE_DEFAULT & DASD_FEATURE_FAILFAST) != 0;
724 return snprintf(buf, PAGE_SIZE, ff_flag ? "1\n" : "0\n");
725}
726
727static ssize_t dasd_ff_store(struct device *dev, struct device_attribute *attr,
728 const char *buf, size_t count)
729{
730 struct dasd_devmap *devmap;
731 int val;
732 char *endp;
733
734 devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
735 if (IS_ERR(devmap))
736 return PTR_ERR(devmap);
737
738 val = simple_strtoul(buf, &endp, 0);
739 if (((endp + 1) < (buf + count)) || (val > 1))
740 return -EINVAL;
741
742 spin_lock(&dasd_devmap_lock);
743 if (val)
744 devmap->features |= DASD_FEATURE_FAILFAST;
745 else
746 devmap->features &= ~DASD_FEATURE_FAILFAST;
747 if (devmap->device)
748 devmap->device->features = devmap->features;
749 spin_unlock(&dasd_devmap_lock);
750 return count;
751}
752
753static DEVICE_ATTR(failfast, 0644, dasd_ff_show, dasd_ff_store);
754
755/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756 * readonly controls the readonly status of a dasd
757 */
758static ssize_t
Yani Ioannoue404e272005-05-17 06:42:58 -0400759dasd_ro_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760{
761 struct dasd_devmap *devmap;
762 int ro_flag;
763
Kay Sievers2a0217d2008-10-10 21:33:09 +0200764 devmap = dasd_find_busid(dev_name(dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765 if (!IS_ERR(devmap))
766 ro_flag = (devmap->features & DASD_FEATURE_READONLY) != 0;
767 else
768 ro_flag = (DASD_FEATURE_DEFAULT & DASD_FEATURE_READONLY) != 0;
769 return snprintf(buf, PAGE_SIZE, ro_flag ? "1\n" : "0\n");
770}
771
772static ssize_t
Horst Hummel138c0142006-06-29 14:58:12 +0200773dasd_ro_store(struct device *dev, struct device_attribute *attr,
774 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775{
776 struct dasd_devmap *devmap;
Stefan Weinhuber33b62a32010-03-08 12:26:24 +0100777 struct dasd_device *device;
Horst Hummel01376f42006-12-04 15:39:50 +0100778 int val;
779 char *endp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780
781 devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
782 if (IS_ERR(devmap))
783 return PTR_ERR(devmap);
Horst Hummel01376f42006-12-04 15:39:50 +0100784
785 val = simple_strtoul(buf, &endp, 0);
786 if (((endp + 1) < (buf + count)) || (val > 1))
787 return -EINVAL;
788
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789 spin_lock(&dasd_devmap_lock);
Horst Hummel01376f42006-12-04 15:39:50 +0100790 if (val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 devmap->features |= DASD_FEATURE_READONLY;
792 else
793 devmap->features &= ~DASD_FEATURE_READONLY;
Stefan Weinhuber33b62a32010-03-08 12:26:24 +0100794 device = devmap->device;
795 if (device) {
796 device->features = devmap->features;
797 val = val || test_bit(DASD_FLAG_DEVICE_RO, &device->flags);
798 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799 spin_unlock(&dasd_devmap_lock);
Stefan Weinhuber33b62a32010-03-08 12:26:24 +0100800 if (device && device->block && device->block->gdp)
801 set_disk_ro(device->block->gdp, val);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802 return count;
803}
804
805static DEVICE_ATTR(readonly, 0644, dasd_ro_show, dasd_ro_store);
Horst Hummel9575bf22006-12-08 15:54:15 +0100806/*
807 * erplog controls the logging of ERP related data
808 * (e.g. failing channel programs).
809 */
810static ssize_t
811dasd_erplog_show(struct device *dev, struct device_attribute *attr, char *buf)
812{
813 struct dasd_devmap *devmap;
814 int erplog;
815
Kay Sievers2a0217d2008-10-10 21:33:09 +0200816 devmap = dasd_find_busid(dev_name(dev));
Horst Hummel9575bf22006-12-08 15:54:15 +0100817 if (!IS_ERR(devmap))
818 erplog = (devmap->features & DASD_FEATURE_ERPLOG) != 0;
819 else
820 erplog = (DASD_FEATURE_DEFAULT & DASD_FEATURE_ERPLOG) != 0;
821 return snprintf(buf, PAGE_SIZE, erplog ? "1\n" : "0\n");
822}
823
824static ssize_t
825dasd_erplog_store(struct device *dev, struct device_attribute *attr,
826 const char *buf, size_t count)
827{
828 struct dasd_devmap *devmap;
829 int val;
830 char *endp;
831
832 devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
833 if (IS_ERR(devmap))
834 return PTR_ERR(devmap);
835
836 val = simple_strtoul(buf, &endp, 0);
837 if (((endp + 1) < (buf + count)) || (val > 1))
838 return -EINVAL;
839
840 spin_lock(&dasd_devmap_lock);
841 if (val)
842 devmap->features |= DASD_FEATURE_ERPLOG;
843 else
844 devmap->features &= ~DASD_FEATURE_ERPLOG;
845 if (devmap->device)
846 devmap->device->features = devmap->features;
847 spin_unlock(&dasd_devmap_lock);
848 return count;
849}
850
851static DEVICE_ATTR(erplog, 0644, dasd_erplog_show, dasd_erplog_store);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852
853/*
854 * use_diag controls whether the driver should use diag rather than ssch
855 * to talk to the device
856 */
Horst Hummel138c0142006-06-29 14:58:12 +0200857static ssize_t
Yani Ioannoue404e272005-05-17 06:42:58 -0400858dasd_use_diag_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859{
860 struct dasd_devmap *devmap;
861 int use_diag;
862
Kay Sievers2a0217d2008-10-10 21:33:09 +0200863 devmap = dasd_find_busid(dev_name(dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864 if (!IS_ERR(devmap))
865 use_diag = (devmap->features & DASD_FEATURE_USEDIAG) != 0;
866 else
867 use_diag = (DASD_FEATURE_DEFAULT & DASD_FEATURE_USEDIAG) != 0;
868 return sprintf(buf, use_diag ? "1\n" : "0\n");
869}
870
871static ssize_t
Horst Hummel138c0142006-06-29 14:58:12 +0200872dasd_use_diag_store(struct device *dev, struct device_attribute *attr,
873 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874{
875 struct dasd_devmap *devmap;
876 ssize_t rc;
Horst Hummel01376f42006-12-04 15:39:50 +0100877 int val;
878 char *endp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879
880 devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
881 if (IS_ERR(devmap))
882 return PTR_ERR(devmap);
Horst Hummel01376f42006-12-04 15:39:50 +0100883
884 val = simple_strtoul(buf, &endp, 0);
885 if (((endp + 1) < (buf + count)) || (val > 1))
886 return -EINVAL;
887
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888 spin_lock(&dasd_devmap_lock);
889 /* Changing diag discipline flag is only allowed in offline state. */
890 rc = count;
Stefan Haberlande4dbb0f2011-01-05 12:48:06 +0100891 if (!devmap->device && !(devmap->features & DASD_FEATURE_USERAW)) {
Horst Hummel01376f42006-12-04 15:39:50 +0100892 if (val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893 devmap->features |= DASD_FEATURE_USEDIAG;
894 else
895 devmap->features &= ~DASD_FEATURE_USEDIAG;
896 } else
897 rc = -EPERM;
898 spin_unlock(&dasd_devmap_lock);
899 return rc;
900}
901
Horst Hummel138c0142006-06-29 14:58:12 +0200902static DEVICE_ATTR(use_diag, 0644, dasd_use_diag_show, dasd_use_diag_store);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903
Stefan Haberlande4dbb0f2011-01-05 12:48:06 +0100904/*
905 * use_raw controls whether the driver should give access to raw eckd data or
906 * operate in standard mode
907 */
908static ssize_t
909dasd_use_raw_show(struct device *dev, struct device_attribute *attr, char *buf)
910{
911 struct dasd_devmap *devmap;
912 int use_raw;
913
914 devmap = dasd_find_busid(dev_name(dev));
915 if (!IS_ERR(devmap))
916 use_raw = (devmap->features & DASD_FEATURE_USERAW) != 0;
917 else
918 use_raw = (DASD_FEATURE_DEFAULT & DASD_FEATURE_USERAW) != 0;
919 return sprintf(buf, use_raw ? "1\n" : "0\n");
920}
921
922static ssize_t
923dasd_use_raw_store(struct device *dev, struct device_attribute *attr,
924 const char *buf, size_t count)
925{
926 struct dasd_devmap *devmap;
927 ssize_t rc;
928 unsigned long val;
929
930 devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
931 if (IS_ERR(devmap))
932 return PTR_ERR(devmap);
933
934 if ((strict_strtoul(buf, 10, &val) != 0) || val > 1)
935 return -EINVAL;
936
937 spin_lock(&dasd_devmap_lock);
938 /* Changing diag discipline flag is only allowed in offline state. */
939 rc = count;
940 if (!devmap->device && !(devmap->features & DASD_FEATURE_USEDIAG)) {
941 if (val)
942 devmap->features |= DASD_FEATURE_USERAW;
943 else
944 devmap->features &= ~DASD_FEATURE_USERAW;
945 } else
946 rc = -EPERM;
947 spin_unlock(&dasd_devmap_lock);
948 return rc;
949}
950
951static DEVICE_ATTR(raw_track_access, 0644, dasd_use_raw_show,
952 dasd_use_raw_store);
953
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954static ssize_t
Stefan Haberlandd07dc5d2012-11-28 13:43:38 +0100955dasd_safe_offline_store(struct device *dev, struct device_attribute *attr,
956 const char *buf, size_t count)
957{
958 struct ccw_device *cdev = to_ccwdev(dev);
959 struct dasd_device *device;
960 int rc;
961
962 device = dasd_device_from_cdev(cdev);
963 if (IS_ERR(device)) {
964 rc = PTR_ERR(device);
965 goto out;
966 }
967
968 if (test_bit(DASD_FLAG_OFFLINE, &device->flags) ||
969 test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
970 /* Already doing offline processing */
971 dasd_put_device(device);
972 rc = -EBUSY;
973 goto out;
974 }
975
976 set_bit(DASD_FLAG_SAFE_OFFLINE, &device->flags);
977 dasd_put_device(device);
978
979 rc = ccw_device_set_offline(cdev);
980
981out:
982 return rc ? rc : count;
983}
984
985static DEVICE_ATTR(safe_offline, 0200, NULL, dasd_safe_offline_store);
986
987static ssize_t
Horst Hummel138c0142006-06-29 14:58:12 +0200988dasd_discipline_show(struct device *dev, struct device_attribute *attr,
989 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990{
Martin Schwidefskya00bfd72006-09-20 15:59:05 +0200991 struct dasd_device *device;
992 ssize_t len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993
Martin Schwidefskya00bfd72006-09-20 15:59:05 +0200994 device = dasd_device_from_cdev(to_ccwdev(dev));
Stefan Haberland589c74d2010-02-26 22:37:47 +0100995 if (IS_ERR(device))
996 goto out;
997 else if (!device->discipline) {
998 dasd_put_device(device);
999 goto out;
1000 } else {
Martin Schwidefskya00bfd72006-09-20 15:59:05 +02001001 len = snprintf(buf, PAGE_SIZE, "%s\n",
1002 device->discipline->name);
1003 dasd_put_device(device);
Stefan Haberland589c74d2010-02-26 22:37:47 +01001004 return len;
1005 }
1006out:
1007 len = snprintf(buf, PAGE_SIZE, "none\n");
Martin Schwidefskya00bfd72006-09-20 15:59:05 +02001008 return len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009}
1010
1011static DEVICE_ATTR(discipline, 0444, dasd_discipline_show, NULL);
1012
Horst Hummel3d052592006-04-27 18:40:28 -07001013static ssize_t
Horst Hummel4dfd5c42007-04-27 16:01:47 +02001014dasd_device_status_show(struct device *dev, struct device_attribute *attr,
1015 char *buf)
1016{
1017 struct dasd_device *device;
1018 ssize_t len;
1019
1020 device = dasd_device_from_cdev(to_ccwdev(dev));
1021 if (!IS_ERR(device)) {
1022 switch (device->state) {
1023 case DASD_STATE_NEW:
1024 len = snprintf(buf, PAGE_SIZE, "new\n");
1025 break;
1026 case DASD_STATE_KNOWN:
1027 len = snprintf(buf, PAGE_SIZE, "detected\n");
1028 break;
1029 case DASD_STATE_BASIC:
1030 len = snprintf(buf, PAGE_SIZE, "basic\n");
1031 break;
1032 case DASD_STATE_UNFMT:
1033 len = snprintf(buf, PAGE_SIZE, "unformatted\n");
1034 break;
1035 case DASD_STATE_READY:
1036 len = snprintf(buf, PAGE_SIZE, "ready\n");
1037 break;
1038 case DASD_STATE_ONLINE:
1039 len = snprintf(buf, PAGE_SIZE, "online\n");
1040 break;
1041 default:
1042 len = snprintf(buf, PAGE_SIZE, "no stat\n");
1043 break;
1044 }
1045 dasd_put_device(device);
1046 } else
1047 len = snprintf(buf, PAGE_SIZE, "unknown\n");
1048 return len;
1049}
1050
1051static DEVICE_ATTR(status, 0444, dasd_device_status_show, NULL);
1052
Stefan Haberland2dedf0d2010-05-17 10:00:11 +02001053static ssize_t dasd_alias_show(struct device *dev,
1054 struct device_attribute *attr, char *buf)
Horst Hummel3d052592006-04-27 18:40:28 -07001055{
Stefan Haberland2dedf0d2010-05-17 10:00:11 +02001056 struct dasd_device *device;
1057 struct dasd_uid uid;
Horst Hummel3d052592006-04-27 18:40:28 -07001058
Stefan Haberland2dedf0d2010-05-17 10:00:11 +02001059 device = dasd_device_from_cdev(to_ccwdev(dev));
1060 if (IS_ERR(device))
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001061 return sprintf(buf, "0\n");
Stefan Haberland2dedf0d2010-05-17 10:00:11 +02001062
1063 if (device->discipline && device->discipline->get_uid &&
1064 !device->discipline->get_uid(device, &uid)) {
1065 if (uid.type == UA_BASE_PAV_ALIAS ||
Stefan Haberland0abccf72010-07-19 09:22:36 +02001066 uid.type == UA_HYPER_PAV_ALIAS) {
1067 dasd_put_device(device);
Stefan Haberland2dedf0d2010-05-17 10:00:11 +02001068 return sprintf(buf, "1\n");
Stefan Haberland0abccf72010-07-19 09:22:36 +02001069 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001070 }
Stefan Haberland2dedf0d2010-05-17 10:00:11 +02001071 dasd_put_device(device);
1072
1073 return sprintf(buf, "0\n");
Horst Hummel3d052592006-04-27 18:40:28 -07001074}
1075
1076static DEVICE_ATTR(alias, 0444, dasd_alias_show, NULL);
1077
Stefan Haberland2dedf0d2010-05-17 10:00:11 +02001078static ssize_t dasd_vendor_show(struct device *dev,
1079 struct device_attribute *attr, char *buf)
Horst Hummel3d052592006-04-27 18:40:28 -07001080{
Stefan Haberland2dedf0d2010-05-17 10:00:11 +02001081 struct dasd_device *device;
1082 struct dasd_uid uid;
Horst Hummel3d052592006-04-27 18:40:28 -07001083 char *vendor;
1084
Stefan Haberland2dedf0d2010-05-17 10:00:11 +02001085 device = dasd_device_from_cdev(to_ccwdev(dev));
1086 vendor = "";
1087 if (IS_ERR(device))
1088 return snprintf(buf, PAGE_SIZE, "%s\n", vendor);
1089
1090 if (device->discipline && device->discipline->get_uid &&
1091 !device->discipline->get_uid(device, &uid))
1092 vendor = uid.vendor;
1093
1094 dasd_put_device(device);
Horst Hummel3d052592006-04-27 18:40:28 -07001095
1096 return snprintf(buf, PAGE_SIZE, "%s\n", vendor);
1097}
1098
1099static DEVICE_ATTR(vendor, 0444, dasd_vendor_show, NULL);
1100
1101#define UID_STRLEN ( /* vendor */ 3 + 1 + /* serial */ 14 + 1 +\
Stefan Weinhuber4abb08c2008-08-01 16:39:09 +02001102 /* SSID */ 4 + 1 + /* unit addr */ 2 + 1 +\
1103 /* vduit */ 32 + 1)
Horst Hummel3d052592006-04-27 18:40:28 -07001104
1105static ssize_t
1106dasd_uid_show(struct device *dev, struct device_attribute *attr, char *buf)
1107{
Stefan Haberland2dedf0d2010-05-17 10:00:11 +02001108 struct dasd_device *device;
1109 struct dasd_uid uid;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001110 char uid_string[UID_STRLEN];
1111 char ua_string[3];
Horst Hummel3d052592006-04-27 18:40:28 -07001112
Stefan Haberland2dedf0d2010-05-17 10:00:11 +02001113 device = dasd_device_from_cdev(to_ccwdev(dev));
1114 uid_string[0] = 0;
1115 if (IS_ERR(device))
1116 return snprintf(buf, PAGE_SIZE, "%s\n", uid_string);
1117
1118 if (device->discipline && device->discipline->get_uid &&
1119 !device->discipline->get_uid(device, &uid)) {
1120 switch (uid.type) {
1121 case UA_BASE_DEVICE:
1122 snprintf(ua_string, sizeof(ua_string), "%02x",
1123 uid.real_unit_addr);
1124 break;
1125 case UA_BASE_PAV_ALIAS:
1126 snprintf(ua_string, sizeof(ua_string), "%02x",
1127 uid.base_unit_addr);
1128 break;
1129 case UA_HYPER_PAV_ALIAS:
1130 snprintf(ua_string, sizeof(ua_string), "xx");
1131 break;
1132 default:
1133 /* should not happen, treat like base device */
1134 snprintf(ua_string, sizeof(ua_string), "%02x",
1135 uid.real_unit_addr);
1136 break;
1137 }
1138
1139 if (strlen(uid.vduit) > 0)
1140 snprintf(uid_string, sizeof(uid_string),
1141 "%s.%s.%04x.%s.%s",
1142 uid.vendor, uid.serial, uid.ssid, ua_string,
1143 uid.vduit);
1144 else
1145 snprintf(uid_string, sizeof(uid_string),
1146 "%s.%s.%04x.%s",
1147 uid.vendor, uid.serial, uid.ssid, ua_string);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001148 }
Stefan Haberland2dedf0d2010-05-17 10:00:11 +02001149 dasd_put_device(device);
1150
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001151 return snprintf(buf, PAGE_SIZE, "%s\n", uid_string);
Horst Hummel3d052592006-04-27 18:40:28 -07001152}
Horst Hummel3d052592006-04-27 18:40:28 -07001153static DEVICE_ATTR(uid, 0444, dasd_uid_show, NULL);
1154
Stefan Weinhuber20c64462006-03-24 03:15:25 -08001155/*
1156 * extended error-reporting
1157 */
1158static ssize_t
1159dasd_eer_show(struct device *dev, struct device_attribute *attr, char *buf)
1160{
1161 struct dasd_devmap *devmap;
1162 int eer_flag;
1163
Kay Sievers2a0217d2008-10-10 21:33:09 +02001164 devmap = dasd_find_busid(dev_name(dev));
Stefan Weinhuber20c64462006-03-24 03:15:25 -08001165 if (!IS_ERR(devmap) && devmap->device)
1166 eer_flag = dasd_eer_enabled(devmap->device);
1167 else
1168 eer_flag = 0;
1169 return snprintf(buf, PAGE_SIZE, eer_flag ? "1\n" : "0\n");
1170}
1171
1172static ssize_t
1173dasd_eer_store(struct device *dev, struct device_attribute *attr,
1174 const char *buf, size_t count)
1175{
1176 struct dasd_devmap *devmap;
Horst Hummel01376f42006-12-04 15:39:50 +01001177 int val, rc;
1178 char *endp;
Stefan Weinhuber20c64462006-03-24 03:15:25 -08001179
1180 devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
1181 if (IS_ERR(devmap))
1182 return PTR_ERR(devmap);
1183 if (!devmap->device)
Horst Hummel01376f42006-12-04 15:39:50 +01001184 return -ENODEV;
1185
1186 val = simple_strtoul(buf, &endp, 0);
1187 if (((endp + 1) < (buf + count)) || (val > 1))
1188 return -EINVAL;
1189
Horst Hummel645c98c2006-12-04 15:40:18 +01001190 if (val) {
Stefan Weinhuber20c64462006-03-24 03:15:25 -08001191 rc = dasd_eer_enable(devmap->device);
Horst Hummel645c98c2006-12-04 15:40:18 +01001192 if (rc)
1193 return rc;
1194 } else
Stefan Weinhuber20c64462006-03-24 03:15:25 -08001195 dasd_eer_disable(devmap->device);
Horst Hummel645c98c2006-12-04 15:40:18 +01001196 return count;
Stefan Weinhuber20c64462006-03-24 03:15:25 -08001197}
1198
1199static DEVICE_ATTR(eer_enabled, 0644, dasd_eer_show, dasd_eer_store);
1200
Stefan Haberland7c8faa82010-08-09 18:13:00 +02001201/*
1202 * expiration time for default requests
1203 */
1204static ssize_t
1205dasd_expires_show(struct device *dev, struct device_attribute *attr, char *buf)
1206{
1207 struct dasd_device *device;
1208 int len;
1209
1210 device = dasd_device_from_cdev(to_ccwdev(dev));
1211 if (IS_ERR(device))
1212 return -ENODEV;
1213 len = snprintf(buf, PAGE_SIZE, "%lu\n", device->default_expires);
1214 dasd_put_device(device);
1215 return len;
1216}
1217
1218static ssize_t
1219dasd_expires_store(struct device *dev, struct device_attribute *attr,
1220 const char *buf, size_t count)
1221{
1222 struct dasd_device *device;
1223 unsigned long val;
1224
1225 device = dasd_device_from_cdev(to_ccwdev(dev));
1226 if (IS_ERR(device))
1227 return -ENODEV;
1228
1229 if ((strict_strtoul(buf, 10, &val) != 0) ||
1230 (val > DASD_EXPIRES_MAX) || val == 0) {
1231 dasd_put_device(device);
1232 return -EINVAL;
1233 }
1234
1235 if (val)
1236 device->default_expires = val;
1237
1238 dasd_put_device(device);
1239 return count;
1240}
1241
1242static DEVICE_ATTR(expires, 0644, dasd_expires_show, dasd_expires_store);
1243
Stefan Weinhuber5a27e602011-01-05 12:48:04 +01001244static ssize_t dasd_reservation_policy_show(struct device *dev,
1245 struct device_attribute *attr,
1246 char *buf)
1247{
1248 struct dasd_devmap *devmap;
1249 int rc = 0;
1250
1251 devmap = dasd_find_busid(dev_name(dev));
1252 if (IS_ERR(devmap)) {
1253 rc = snprintf(buf, PAGE_SIZE, "ignore\n");
1254 } else {
1255 spin_lock(&dasd_devmap_lock);
1256 if (devmap->features & DASD_FEATURE_FAILONSLCK)
1257 rc = snprintf(buf, PAGE_SIZE, "fail\n");
1258 else
1259 rc = snprintf(buf, PAGE_SIZE, "ignore\n");
1260 spin_unlock(&dasd_devmap_lock);
1261 }
1262 return rc;
1263}
1264
1265static ssize_t dasd_reservation_policy_store(struct device *dev,
1266 struct device_attribute *attr,
1267 const char *buf, size_t count)
1268{
1269 struct dasd_devmap *devmap;
1270 int rc;
1271
1272 devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
1273 if (IS_ERR(devmap))
1274 return PTR_ERR(devmap);
1275 rc = 0;
1276 spin_lock(&dasd_devmap_lock);
1277 if (sysfs_streq("ignore", buf))
1278 devmap->features &= ~DASD_FEATURE_FAILONSLCK;
1279 else if (sysfs_streq("fail", buf))
1280 devmap->features |= DASD_FEATURE_FAILONSLCK;
1281 else
1282 rc = -EINVAL;
1283 if (devmap->device)
1284 devmap->device->features = devmap->features;
1285 spin_unlock(&dasd_devmap_lock);
1286 if (rc)
1287 return rc;
1288 else
1289 return count;
1290}
1291
1292static DEVICE_ATTR(reservation_policy, 0644,
1293 dasd_reservation_policy_show, dasd_reservation_policy_store);
1294
1295static ssize_t dasd_reservation_state_show(struct device *dev,
1296 struct device_attribute *attr,
1297 char *buf)
1298{
1299 struct dasd_device *device;
1300 int rc = 0;
1301
1302 device = dasd_device_from_cdev(to_ccwdev(dev));
1303 if (IS_ERR(device))
1304 return snprintf(buf, PAGE_SIZE, "none\n");
1305
1306 if (test_bit(DASD_FLAG_IS_RESERVED, &device->flags))
1307 rc = snprintf(buf, PAGE_SIZE, "reserved\n");
1308 else if (test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags))
1309 rc = snprintf(buf, PAGE_SIZE, "lost\n");
1310 else
1311 rc = snprintf(buf, PAGE_SIZE, "none\n");
1312 dasd_put_device(device);
1313 return rc;
1314}
1315
1316static ssize_t dasd_reservation_state_store(struct device *dev,
1317 struct device_attribute *attr,
1318 const char *buf, size_t count)
1319{
1320 struct dasd_device *device;
1321 int rc = 0;
1322
1323 device = dasd_device_from_cdev(to_ccwdev(dev));
1324 if (IS_ERR(device))
1325 return -ENODEV;
1326 if (sysfs_streq("reset", buf))
1327 clear_bit(DASD_FLAG_LOCK_STOLEN, &device->flags);
1328 else
1329 rc = -EINVAL;
1330 dasd_put_device(device);
1331
1332 if (rc)
1333 return rc;
1334 else
1335 return count;
1336}
1337
1338static DEVICE_ATTR(last_known_reservation_state, 0644,
1339 dasd_reservation_state_show, dasd_reservation_state_store);
1340
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341static struct attribute * dasd_attrs[] = {
1342 &dev_attr_readonly.attr,
1343 &dev_attr_discipline.attr,
Horst Hummel4dfd5c42007-04-27 16:01:47 +02001344 &dev_attr_status.attr,
Horst Hummel3d052592006-04-27 18:40:28 -07001345 &dev_attr_alias.attr,
1346 &dev_attr_vendor.attr,
1347 &dev_attr_uid.attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348 &dev_attr_use_diag.attr,
Stefan Haberlande4dbb0f2011-01-05 12:48:06 +01001349 &dev_attr_raw_track_access.attr,
Stefan Weinhuber20c64462006-03-24 03:15:25 -08001350 &dev_attr_eer_enabled.attr,
Horst Hummel9575bf22006-12-08 15:54:15 +01001351 &dev_attr_erplog.attr,
Holger Smolinski13de2272009-01-09 12:14:51 +01001352 &dev_attr_failfast.attr,
Stefan Haberland7c8faa82010-08-09 18:13:00 +02001353 &dev_attr_expires.attr,
Stefan Weinhuber5a27e602011-01-05 12:48:04 +01001354 &dev_attr_reservation_policy.attr,
1355 &dev_attr_last_known_reservation_state.attr,
Stefan Haberlandd07dc5d2012-11-28 13:43:38 +01001356 &dev_attr_safe_offline.attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357 NULL,
1358};
1359
1360static struct attribute_group dasd_attr_group = {
1361 .attrs = dasd_attrs,
1362};
1363
Horst Hummel40545572006-06-29 15:08:18 +02001364/*
Horst Hummelf24acd42005-05-01 08:58:59 -07001365 * Return value of the specified feature.
1366 */
1367int
1368dasd_get_feature(struct ccw_device *cdev, int feature)
1369{
1370 struct dasd_devmap *devmap;
1371
Kay Sievers2a0217d2008-10-10 21:33:09 +02001372 devmap = dasd_find_busid(dev_name(&cdev->dev));
Horst Hummelf24acd42005-05-01 08:58:59 -07001373 if (IS_ERR(devmap))
Horst Hummel40545572006-06-29 15:08:18 +02001374 return PTR_ERR(devmap);
Horst Hummelf24acd42005-05-01 08:58:59 -07001375
1376 return ((devmap->features & feature) != 0);
1377}
1378
1379/*
1380 * Set / reset given feature.
Adam Buchbinder48fc7f72012-09-19 21:48:00 -04001381 * Flag indicates whether to set (!=0) or the reset (=0) the feature.
Horst Hummelf24acd42005-05-01 08:58:59 -07001382 */
1383int
1384dasd_set_feature(struct ccw_device *cdev, int feature, int flag)
1385{
1386 struct dasd_devmap *devmap;
1387
Kay Sievers2a0217d2008-10-10 21:33:09 +02001388 devmap = dasd_find_busid(dev_name(&cdev->dev));
Horst Hummelf24acd42005-05-01 08:58:59 -07001389 if (IS_ERR(devmap))
Horst Hummel40545572006-06-29 15:08:18 +02001390 return PTR_ERR(devmap);
Horst Hummelf24acd42005-05-01 08:58:59 -07001391
1392 spin_lock(&dasd_devmap_lock);
1393 if (flag)
1394 devmap->features |= feature;
1395 else
1396 devmap->features &= ~feature;
Horst Hummelc6eb7b72005-09-03 15:57:58 -07001397 if (devmap->device)
1398 devmap->device->features = devmap->features;
Horst Hummelf24acd42005-05-01 08:58:59 -07001399 spin_unlock(&dasd_devmap_lock);
1400 return 0;
1401}
1402
1403
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404int
1405dasd_add_sysfs_files(struct ccw_device *cdev)
1406{
1407 return sysfs_create_group(&cdev->dev.kobj, &dasd_attr_group);
1408}
1409
1410void
1411dasd_remove_sysfs_files(struct ccw_device *cdev)
1412{
1413 sysfs_remove_group(&cdev->dev.kobj, &dasd_attr_group);
1414}
1415
1416
1417int
1418dasd_devmap_init(void)
1419{
1420 int i;
1421
1422 /* Initialize devmap structures. */
1423 dasd_max_devindex = 0;
1424 for (i = 0; i < 256; i++)
1425 INIT_LIST_HEAD(&dasd_hashlists[i]);
Horst Hummel40545572006-06-29 15:08:18 +02001426 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427}
1428
1429void
1430dasd_devmap_exit(void)
1431{
1432 dasd_forget_ranges();
1433}