blob: 47fc886924941a6b26464cd7f1a5e332ad30f16f [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * File...........: linux/drivers/s390/block/dasd_devmap.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 *
10 * Device mapping and dasd= parameter parsing functions. All devmap
11 * functions may not be called from interrupt context. In particular
12 * dasd_get_device is a no-no from interrupt context.
13 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070014 */
15
Stefan Haberlandfc19f382009-03-26 15:23:49 +010016#define KMSG_COMPONENT "dasd"
17
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <linux/ctype.h>
19#include <linux/init.h>
Rusty Russell8d3b33f2006-03-25 03:07:05 -080020#include <linux/module.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090021#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022
23#include <asm/debug.h>
24#include <asm/uaccess.h>
Peter Oberparleiter7039d3a2007-04-27 16:01:48 +020025#include <asm/ipl.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
27/* This is ugly... */
28#define PRINTK_HEADER "dasd_devmap:"
Kay Sievers98df67b2008-12-25 13:38:55 +010029#define DASD_BUS_ID_SIZE 20
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
31#include "dasd_int.h"
32
Christoph Lametere18b8902006-12-06 20:33:20 -080033struct kmem_cache *dasd_page_cache;
Horst Hummel40545572006-06-29 15:08:18 +020034EXPORT_SYMBOL_GPL(dasd_page_cache);
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
36/*
37 * dasd_devmap_t is used to store the features and the relation
38 * between device number and device index. To find a dasd_devmap_t
39 * that corresponds to a device number of a device index each
40 * dasd_devmap_t is added to two linked lists, one to search by
41 * the device number and one to search by the device index. As
42 * soon as big minor numbers are available the device index list
43 * can be removed since the device number will then be identical
44 * to the device index.
45 */
46struct dasd_devmap {
47 struct list_head list;
Kay Sievers98df67b2008-12-25 13:38:55 +010048 char bus_id[DASD_BUS_ID_SIZE];
Linus Torvalds1da177e2005-04-16 15:20:36 -070049 unsigned int devindex;
50 unsigned short features;
51 struct dasd_device *device;
52};
53
54/*
55 * Parameter parsing functions for dasd= parameter. The syntax is:
56 * <devno> : (0x)?[0-9a-fA-F]+
57 * <busid> : [0-0a-f]\.[0-9a-f]\.(0x)?[0-9a-fA-F]+
58 * <feature> : ro
59 * <feature_list> : \(<feature>(:<feature>)*\)
60 * <devno-range> : <devno>(-<devno>)?<feature_list>?
61 * <busid-range> : <busid>(-<busid>)?<feature_list>?
62 * <devices> : <devno-range>|<busid-range>
63 * <dasd_module> : dasd_diag_mod|dasd_eckd_mod|dasd_fba_mod
64 *
65 * <dasd> : autodetect|probeonly|<devices>(,<devices>)*
66 */
67
68int dasd_probeonly = 0; /* is true, when probeonly mode is active */
69int dasd_autodetect = 0; /* is true, when autodetection is active */
Horst Hummel40545572006-06-29 15:08:18 +020070int dasd_nopav = 0; /* is true, when PAV is disabled */
71EXPORT_SYMBOL_GPL(dasd_nopav);
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +010072int dasd_nofcx; /* disable High Performance Ficon */
73EXPORT_SYMBOL_GPL(dasd_nofcx);
Linus Torvalds1da177e2005-04-16 15:20:36 -070074
75/*
76 * char *dasd[] is intended to hold the ranges supplied by the dasd= statement
77 * it is named 'dasd' to directly be filled by insmod with the comma separated
78 * strings when running as a module.
79 */
80static char *dasd[256];
Rusty Russell8d3b33f2006-03-25 03:07:05 -080081module_param_array(dasd, charp, NULL, 0);
82
Linus Torvalds1da177e2005-04-16 15:20:36 -070083/*
Horst Hummeld0710c72006-08-10 15:45:16 +020084 * Single spinlock to protect devmap and servermap structures and lists.
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 */
86static DEFINE_SPINLOCK(dasd_devmap_lock);
87
88/*
89 * Hash lists for devmap structures.
90 */
91static struct list_head dasd_hashlists[256];
92int dasd_max_devindex;
93
Cornelia Huck69f90f62008-05-15 16:52:34 +020094static struct dasd_devmap *dasd_add_busid(const char *, int);
Linus Torvalds1da177e2005-04-16 15:20:36 -070095
96static inline int
Cornelia Huck69f90f62008-05-15 16:52:34 +020097dasd_hash_busid(const char *bus_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -070098{
99 int hash, i;
100
101 hash = 0;
Kay Sievers98df67b2008-12-25 13:38:55 +0100102 for (i = 0; (i < DASD_BUS_ID_SIZE) && *bus_id; i++, bus_id++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 hash += *bus_id;
104 return hash & 0xff;
105}
106
107#ifndef MODULE
108/*
109 * The parameter parsing functions for builtin-drivers are called
110 * before kmalloc works. Store the pointers to the parameters strings
111 * into dasd[] for later processing.
112 */
113static int __init
114dasd_call_setup(char *str)
115{
116 static int count = 0;
117
118 if (count < 256)
119 dasd[count++] = str;
120 return 1;
121}
122
123__setup ("dasd=", dasd_call_setup);
124#endif /* #ifndef MODULE */
125
Peter Oberparleiter7039d3a2007-04-27 16:01:48 +0200126#define DASD_IPLDEV "ipldev"
127
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128/*
129 * Read a device busid/devno from a string.
130 */
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100131static int
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100132
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133dasd_busid(char **str, int *id0, int *id1, int *devno)
134{
135 int val, old_style;
Horst Hummel138c0142006-06-29 14:58:12 +0200136
Peter Oberparleiter7039d3a2007-04-27 16:01:48 +0200137 /* Interpret ipldev busid */
138 if (strncmp(DASD_IPLDEV, *str, strlen(DASD_IPLDEV)) == 0) {
139 if (ipl_info.type != IPL_TYPE_CCW) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100140 pr_err("The IPL device is not a CCW device\n");
Peter Oberparleiter7039d3a2007-04-27 16:01:48 +0200141 return -EINVAL;
142 }
143 *id0 = 0;
144 *id1 = ipl_info.data.ccw.dev_id.ssid;
145 *devno = ipl_info.data.ccw.dev_id.devno;
146 *str += strlen(DASD_IPLDEV);
147
148 return 0;
149 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 /* check for leading '0x' */
151 old_style = 0;
152 if ((*str)[0] == '0' && (*str)[1] == 'x') {
153 *str += 2;
154 old_style = 1;
155 }
156 if (!isxdigit((*str)[0])) /* We require at least one hex digit */
157 return -EINVAL;
158 val = simple_strtoul(*str, str, 16);
159 if (old_style || (*str)[0] != '.') {
160 *id0 = *id1 = 0;
161 if (val < 0 || val > 0xffff)
162 return -EINVAL;
163 *devno = val;
164 return 0;
165 }
166 /* New style x.y.z busid */
167 if (val < 0 || val > 0xff)
168 return -EINVAL;
169 *id0 = val;
170 (*str)++;
171 if (!isxdigit((*str)[0])) /* We require at least one hex digit */
172 return -EINVAL;
173 val = simple_strtoul(*str, str, 16);
174 if (val < 0 || val > 0xff || (*str)++[0] != '.')
175 return -EINVAL;
176 *id1 = val;
177 if (!isxdigit((*str)[0])) /* We require at least one hex digit */
178 return -EINVAL;
179 val = simple_strtoul(*str, str, 16);
180 if (val < 0 || val > 0xffff)
181 return -EINVAL;
182 *devno = val;
183 return 0;
184}
185
186/*
187 * Read colon separated list of dasd features. Currently there is
188 * only one: "ro" for read-only devices. The default feature set
189 * is empty (value 0).
190 */
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100191static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192dasd_feature_list(char *str, char **endp)
193{
194 int features, len, rc;
195
196 rc = 0;
197 if (*str != '(') {
198 *endp = str;
199 return DASD_FEATURE_DEFAULT;
200 }
201 str++;
202 features = 0;
203
204 while (1) {
Horst Hummel138c0142006-06-29 14:58:12 +0200205 for (len = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 str[len] && str[len] != ':' && str[len] != ')'; len++);
207 if (len == 2 && !strncmp(str, "ro", 2))
208 features |= DASD_FEATURE_READONLY;
209 else if (len == 4 && !strncmp(str, "diag", 4))
210 features |= DASD_FEATURE_USEDIAG;
Horst Hummel9575bf22006-12-08 15:54:15 +0100211 else if (len == 6 && !strncmp(str, "erplog", 6))
212 features |= DASD_FEATURE_ERPLOG;
Holger Smolinski13de2272009-01-09 12:14:51 +0100213 else if (len == 8 && !strncmp(str, "failfast", 8))
214 features |= DASD_FEATURE_FAILFAST;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 else {
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100216 pr_warning("%*s is not a supported device option\n",
217 len, str);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 rc = -EINVAL;
219 }
220 str += len;
221 if (*str != ':')
222 break;
223 str++;
224 }
225 if (*str != ')') {
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100226 pr_warning("A closing parenthesis ')' is missing in the "
227 "dasd= parameter\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 rc = -EINVAL;
229 } else
230 str++;
231 *endp = str;
232 if (rc != 0)
233 return rc;
234 return features;
235}
236
237/*
238 * Try to match the first element on the comma separated parse string
239 * with one of the known keywords. If a keyword is found, take the approprate
240 * action and return a pointer to the residual string. If the first element
241 * could not be matched to any keyword then return an error code.
242 */
243static char *
244dasd_parse_keyword( char *parsestring ) {
245
246 char *nextcomma, *residual_str;
247 int length;
248
249 nextcomma = strchr(parsestring,',');
250 if (nextcomma) {
251 length = nextcomma - parsestring;
252 residual_str = nextcomma + 1;
253 } else {
254 length = strlen(parsestring);
255 residual_str = parsestring + length;
256 }
Horst Hummel40545572006-06-29 15:08:18 +0200257 if (strncmp("autodetect", parsestring, length) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 dasd_autodetect = 1;
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100259 pr_info("The autodetection mode has been activated\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 return residual_str;
261 }
Horst Hummel40545572006-06-29 15:08:18 +0200262 if (strncmp("probeonly", parsestring, length) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 dasd_probeonly = 1;
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100264 pr_info("The probeonly mode has been activated\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 return residual_str;
266 }
Horst Hummel40545572006-06-29 15:08:18 +0200267 if (strncmp("nopav", parsestring, length) == 0) {
Peter Oberparleiterdcd707b2006-09-20 15:59:52 +0200268 if (MACHINE_IS_VM)
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100269 pr_info("'nopav' is not supported on z/VM\n");
Peter Oberparleiterdcd707b2006-09-20 15:59:52 +0200270 else {
271 dasd_nopav = 1;
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100272 pr_info("PAV support has be deactivated\n");
Peter Oberparleiterdcd707b2006-09-20 15:59:52 +0200273 }
Horst Hummel40545572006-06-29 15:08:18 +0200274 return residual_str;
275 }
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +0100276 if (strncmp("nofcx", parsestring, length) == 0) {
277 dasd_nofcx = 1;
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100278 pr_info("High Performance FICON support has been "
279 "deactivated\n");
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +0100280 return residual_str;
281 }
Horst Hummel40545572006-06-29 15:08:18 +0200282 if (strncmp("fixedbuffers", parsestring, length) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 if (dasd_page_cache)
284 return residual_str;
285 dasd_page_cache =
Heiko Carstens2f6c55f2006-08-16 13:49:27 +0200286 kmem_cache_create("dasd_page_cache", PAGE_SIZE,
287 PAGE_SIZE, SLAB_CACHE_DMA,
Paul Mundt20c2df82007-07-20 10:11:58 +0900288 NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 if (!dasd_page_cache)
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100290 DBF_EVENT(DBF_WARNING, "%s", "Failed to create slab, "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 "fixed buffer mode disabled.");
292 else
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100293 DBF_EVENT(DBF_INFO, "%s",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 "turning on fixed buffer mode");
295 return residual_str;
296 }
297 return ERR_PTR(-EINVAL);
298}
299
300/*
301 * Try to interprete the first element on the comma separated parse string
302 * as a device number or a range of devices. If the interpretation is
303 * successfull, create the matching dasd_devmap entries and return a pointer
304 * to the residual string.
305 * If interpretation fails or in case of an error, return an error code.
306 */
307static char *
308dasd_parse_range( char *parsestring ) {
309
310 struct dasd_devmap *devmap;
311 int from, from_id0, from_id1;
312 int to, to_id0, to_id1;
313 int features, rc;
Kay Sievers98df67b2008-12-25 13:38:55 +0100314 char bus_id[DASD_BUS_ID_SIZE+1], *str;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315
316 str = parsestring;
317 rc = dasd_busid(&str, &from_id0, &from_id1, &from);
318 if (rc == 0) {
319 to = from;
320 to_id0 = from_id0;
321 to_id1 = from_id1;
322 if (*str == '-') {
323 str++;
324 rc = dasd_busid(&str, &to_id0, &to_id1, &to);
325 }
326 }
327 if (rc == 0 &&
328 (from_id0 != to_id0 || from_id1 != to_id1 || from > to))
329 rc = -EINVAL;
330 if (rc) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100331 pr_err("%s is not a valid device range\n", parsestring);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 return ERR_PTR(rc);
333 }
334 features = dasd_feature_list(str, &str);
335 if (features < 0)
336 return ERR_PTR(-EINVAL);
Horst Hummel40545572006-06-29 15:08:18 +0200337 /* each device in dasd= parameter should be set initially online */
338 features |= DASD_FEATURE_INITIAL_ONLINE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 while (from <= to) {
340 sprintf(bus_id, "%01x.%01x.%04x",
341 from_id0, from_id1, from++);
342 devmap = dasd_add_busid(bus_id, features);
343 if (IS_ERR(devmap))
344 return (char *)devmap;
345 }
346 if (*str == ',')
347 return str + 1;
348 if (*str == '\0')
349 return str;
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100350 pr_warning("The dasd= parameter value %s has an invalid ending\n",
351 str);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 return ERR_PTR(-EINVAL);
353}
354
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100355static char *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356dasd_parse_next_element( char *parsestring ) {
357 char * residual_str;
358 residual_str = dasd_parse_keyword(parsestring);
359 if (!IS_ERR(residual_str))
360 return residual_str;
361 residual_str = dasd_parse_range(parsestring);
362 return residual_str;
363}
364
365/*
366 * Parse parameters stored in dasd[]
367 * The 'dasd=...' parameter allows to specify a comma separated list of
368 * keywords and device ranges. When the dasd driver is build into the kernel,
369 * the complete list will be stored as one element of the dasd[] array.
370 * When the dasd driver is build as a module, then the list is broken into
371 * it's elements and each dasd[] entry contains one element.
372 */
373int
374dasd_parse(void)
375{
376 int rc, i;
377 char *parsestring;
378
379 rc = 0;
380 for (i = 0; i < 256; i++) {
381 if (dasd[i] == NULL)
382 break;
383 parsestring = dasd[i];
384 /* loop over the comma separated list in the parsestring */
385 while (*parsestring) {
386 parsestring = dasd_parse_next_element(parsestring);
387 if(IS_ERR(parsestring)) {
388 rc = PTR_ERR(parsestring);
389 break;
390 }
391 }
392 if (rc) {
393 DBF_EVENT(DBF_ALERT, "%s", "invalid range found");
394 break;
395 }
396 }
397 return rc;
398}
399
400/*
401 * Add a devmap for the device specified by busid. It is possible that
402 * the devmap already exists (dasd= parameter). The order of the devices
403 * added through this function will define the kdevs for the individual
Horst Hummel138c0142006-06-29 14:58:12 +0200404 * devices.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 */
406static struct dasd_devmap *
Cornelia Huck69f90f62008-05-15 16:52:34 +0200407dasd_add_busid(const char *bus_id, int features)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408{
409 struct dasd_devmap *devmap, *new, *tmp;
410 int hash;
411
412 new = (struct dasd_devmap *)
Horst Hummel138c0142006-06-29 14:58:12 +0200413 kzalloc(sizeof(struct dasd_devmap), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 if (!new)
415 return ERR_PTR(-ENOMEM);
416 spin_lock(&dasd_devmap_lock);
Heiko Carstensd2c993d2006-07-12 16:41:55 +0200417 devmap = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 hash = dasd_hash_busid(bus_id);
419 list_for_each_entry(tmp, &dasd_hashlists[hash], list)
Kay Sievers98df67b2008-12-25 13:38:55 +0100420 if (strncmp(tmp->bus_id, bus_id, DASD_BUS_ID_SIZE) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 devmap = tmp;
422 break;
423 }
424 if (!devmap) {
425 /* This bus_id is new. */
426 new->devindex = dasd_max_devindex++;
Kay Sievers98df67b2008-12-25 13:38:55 +0100427 strncpy(new->bus_id, bus_id, DASD_BUS_ID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 new->features = features;
Heiko Carstensd2c993d2006-07-12 16:41:55 +0200429 new->device = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 list_add(&new->list, &dasd_hashlists[hash]);
431 devmap = new;
Heiko Carstensd2c993d2006-07-12 16:41:55 +0200432 new = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 }
434 spin_unlock(&dasd_devmap_lock);
Jesper Juhl17fd6822005-11-07 01:01:30 -0800435 kfree(new);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 return devmap;
437}
438
439/*
440 * Find devmap for device with given bus_id.
441 */
442static struct dasd_devmap *
Cornelia Huck69f90f62008-05-15 16:52:34 +0200443dasd_find_busid(const char *bus_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444{
445 struct dasd_devmap *devmap, *tmp;
446 int hash;
447
448 spin_lock(&dasd_devmap_lock);
449 devmap = ERR_PTR(-ENODEV);
450 hash = dasd_hash_busid(bus_id);
451 list_for_each_entry(tmp, &dasd_hashlists[hash], list) {
Kay Sievers98df67b2008-12-25 13:38:55 +0100452 if (strncmp(tmp->bus_id, bus_id, DASD_BUS_ID_SIZE) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 devmap = tmp;
454 break;
455 }
456 }
457 spin_unlock(&dasd_devmap_lock);
458 return devmap;
459}
460
461/*
462 * Check if busid has been added to the list of dasd ranges.
463 */
464int
Cornelia Huck69f90f62008-05-15 16:52:34 +0200465dasd_busid_known(const char *bus_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466{
467 return IS_ERR(dasd_find_busid(bus_id)) ? -ENOENT : 0;
468}
469
470/*
471 * Forget all about the device numbers added so far.
472 * This may only be called at module unload or system shutdown.
473 */
474static void
475dasd_forget_ranges(void)
476{
477 struct dasd_devmap *devmap, *n;
478 int i;
479
480 spin_lock(&dasd_devmap_lock);
481 for (i = 0; i < 256; i++) {
482 list_for_each_entry_safe(devmap, n, &dasd_hashlists[i], list) {
Eric Sesterhenn606f4422006-03-26 18:33:07 +0200483 BUG_ON(devmap->device != NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 list_del(&devmap->list);
485 kfree(devmap);
486 }
487 }
488 spin_unlock(&dasd_devmap_lock);
489}
490
491/*
492 * Find the device struct by its device index.
493 */
494struct dasd_device *
495dasd_device_from_devindex(int devindex)
496{
497 struct dasd_devmap *devmap, *tmp;
498 struct dasd_device *device;
499 int i;
500
501 spin_lock(&dasd_devmap_lock);
Heiko Carstensd2c993d2006-07-12 16:41:55 +0200502 devmap = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 for (i = 0; (i < 256) && !devmap; i++)
504 list_for_each_entry(tmp, &dasd_hashlists[i], list)
505 if (tmp->devindex == devindex) {
506 /* Found the devmap for the device. */
507 devmap = tmp;
508 break;
509 }
510 if (devmap && devmap->device) {
511 device = devmap->device;
512 dasd_get_device(device);
513 } else
514 device = ERR_PTR(-ENODEV);
515 spin_unlock(&dasd_devmap_lock);
516 return device;
517}
518
519/*
520 * Return devmap for cdev. If no devmap exists yet, create one and
521 * connect it to the cdev.
522 */
523static struct dasd_devmap *
524dasd_devmap_from_cdev(struct ccw_device *cdev)
525{
526 struct dasd_devmap *devmap;
527
Kay Sievers2a0217d2008-10-10 21:33:09 +0200528 devmap = dasd_find_busid(dev_name(&cdev->dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 if (IS_ERR(devmap))
Kay Sievers2a0217d2008-10-10 21:33:09 +0200530 devmap = dasd_add_busid(dev_name(&cdev->dev),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 DASD_FEATURE_DEFAULT);
532 return devmap;
533}
534
535/*
536 * Create a dasd device structure for cdev.
537 */
538struct dasd_device *
539dasd_create_device(struct ccw_device *cdev)
540{
541 struct dasd_devmap *devmap;
542 struct dasd_device *device;
Martin Schwidefskya00bfd72006-09-20 15:59:05 +0200543 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 int rc;
545
546 devmap = dasd_devmap_from_cdev(cdev);
547 if (IS_ERR(devmap))
548 return (void *) devmap;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549
550 device = dasd_alloc_device();
551 if (IS_ERR(device))
552 return device;
Martin Schwidefskya00bfd72006-09-20 15:59:05 +0200553 atomic_set(&device->ref_count, 3);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554
555 spin_lock(&dasd_devmap_lock);
556 if (!devmap->device) {
557 devmap->device = device;
558 device->devindex = devmap->devindex;
Horst Hummelc6eb7b72005-09-03 15:57:58 -0700559 device->features = devmap->features;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 get_device(&cdev->dev);
561 device->cdev = cdev;
562 rc = 0;
563 } else
564 /* Someone else was faster. */
565 rc = -EBUSY;
566 spin_unlock(&dasd_devmap_lock);
567
568 if (rc) {
569 dasd_free_device(device);
570 return ERR_PTR(rc);
571 }
Martin Schwidefskya00bfd72006-09-20 15:59:05 +0200572
573 spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
Cornelia Huckfaf16aa2008-12-25 13:38:52 +0100574 dev_set_drvdata(&cdev->dev, device);
Martin Schwidefskya00bfd72006-09-20 15:59:05 +0200575 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
576
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 return device;
578}
579
580/*
581 * Wait queue for dasd_delete_device waits.
582 */
583static DECLARE_WAIT_QUEUE_HEAD(dasd_delete_wq);
584
585/*
586 * Remove a dasd device structure. The passed referenced
587 * is destroyed.
588 */
589void
590dasd_delete_device(struct dasd_device *device)
591{
592 struct ccw_device *cdev;
593 struct dasd_devmap *devmap;
Martin Schwidefskya00bfd72006-09-20 15:59:05 +0200594 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595
596 /* First remove device pointer from devmap. */
Kay Sievers2a0217d2008-10-10 21:33:09 +0200597 devmap = dasd_find_busid(dev_name(&device->cdev->dev));
Eric Sesterhenn606f4422006-03-26 18:33:07 +0200598 BUG_ON(IS_ERR(devmap));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 spin_lock(&dasd_devmap_lock);
600 if (devmap->device != device) {
601 spin_unlock(&dasd_devmap_lock);
602 dasd_put_device(device);
603 return;
604 }
605 devmap->device = NULL;
606 spin_unlock(&dasd_devmap_lock);
607
Martin Schwidefskya00bfd72006-09-20 15:59:05 +0200608 /* Disconnect dasd_device structure from ccw_device structure. */
609 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
Cornelia Huckfaf16aa2008-12-25 13:38:52 +0100610 dev_set_drvdata(&device->cdev->dev, NULL);
Martin Schwidefskya00bfd72006-09-20 15:59:05 +0200611 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
612
613 /*
614 * Drop ref_count by 3, one for the devmap reference, one for
615 * the cdev reference and one for the passed reference.
616 */
617 atomic_sub(3, &device->ref_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618
619 /* Wait for reference counter to drop to zero. */
620 wait_event(dasd_delete_wq, atomic_read(&device->ref_count) == 0);
621
622 /* Disconnect dasd_device structure from ccw_device structure. */
623 cdev = device->cdev;
624 device->cdev = NULL;
625
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 /* Put ccw_device structure. */
627 put_device(&cdev->dev);
628
629 /* Now the device structure can be freed. */
630 dasd_free_device(device);
631}
632
633/*
634 * Reference counter dropped to zero. Wake up waiter
635 * in dasd_delete_device.
636 */
637void
638dasd_put_device_wake(struct dasd_device *device)
639{
640 wake_up(&dasd_delete_wq);
641}
Stefan Weinhubera4d26c62011-01-05 12:48:03 +0100642EXPORT_SYMBOL_GPL(dasd_put_device_wake);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643
644/*
645 * Return dasd_device structure associated with cdev.
Martin Schwidefskya00bfd72006-09-20 15:59:05 +0200646 * This function needs to be called with the ccw device
647 * lock held. It can be used from interrupt context.
648 */
649struct dasd_device *
650dasd_device_from_cdev_locked(struct ccw_device *cdev)
651{
Cornelia Huckfaf16aa2008-12-25 13:38:52 +0100652 struct dasd_device *device = dev_get_drvdata(&cdev->dev);
Martin Schwidefskya00bfd72006-09-20 15:59:05 +0200653
654 if (!device)
655 return ERR_PTR(-ENODEV);
656 dasd_get_device(device);
657 return device;
658}
659
660/*
661 * Return dasd_device structure associated with cdev.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 */
663struct dasd_device *
664dasd_device_from_cdev(struct ccw_device *cdev)
665{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 struct dasd_device *device;
Martin Schwidefskya00bfd72006-09-20 15:59:05 +0200667 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668
Martin Schwidefskya00bfd72006-09-20 15:59:05 +0200669 spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
670 device = dasd_device_from_cdev_locked(cdev);
671 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672 return device;
673}
674
675/*
676 * SECTION: files in sysfs
677 */
678
679/*
Holger Smolinski13de2272009-01-09 12:14:51 +0100680 * failfast controls the behaviour, if no path is available
681 */
682static ssize_t dasd_ff_show(struct device *dev, struct device_attribute *attr,
683 char *buf)
684{
685 struct dasd_devmap *devmap;
686 int ff_flag;
687
Cornelia Huckca0b4b72009-02-11 10:37:30 +0100688 devmap = dasd_find_busid(dev_name(dev));
Holger Smolinski13de2272009-01-09 12:14:51 +0100689 if (!IS_ERR(devmap))
690 ff_flag = (devmap->features & DASD_FEATURE_FAILFAST) != 0;
691 else
692 ff_flag = (DASD_FEATURE_DEFAULT & DASD_FEATURE_FAILFAST) != 0;
693 return snprintf(buf, PAGE_SIZE, ff_flag ? "1\n" : "0\n");
694}
695
696static ssize_t dasd_ff_store(struct device *dev, struct device_attribute *attr,
697 const char *buf, size_t count)
698{
699 struct dasd_devmap *devmap;
700 int val;
701 char *endp;
702
703 devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
704 if (IS_ERR(devmap))
705 return PTR_ERR(devmap);
706
707 val = simple_strtoul(buf, &endp, 0);
708 if (((endp + 1) < (buf + count)) || (val > 1))
709 return -EINVAL;
710
711 spin_lock(&dasd_devmap_lock);
712 if (val)
713 devmap->features |= DASD_FEATURE_FAILFAST;
714 else
715 devmap->features &= ~DASD_FEATURE_FAILFAST;
716 if (devmap->device)
717 devmap->device->features = devmap->features;
718 spin_unlock(&dasd_devmap_lock);
719 return count;
720}
721
722static DEVICE_ATTR(failfast, 0644, dasd_ff_show, dasd_ff_store);
723
724/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 * readonly controls the readonly status of a dasd
726 */
727static ssize_t
Yani Ioannoue404e272005-05-17 06:42:58 -0400728dasd_ro_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729{
730 struct dasd_devmap *devmap;
731 int ro_flag;
732
Kay Sievers2a0217d2008-10-10 21:33:09 +0200733 devmap = dasd_find_busid(dev_name(dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734 if (!IS_ERR(devmap))
735 ro_flag = (devmap->features & DASD_FEATURE_READONLY) != 0;
736 else
737 ro_flag = (DASD_FEATURE_DEFAULT & DASD_FEATURE_READONLY) != 0;
738 return snprintf(buf, PAGE_SIZE, ro_flag ? "1\n" : "0\n");
739}
740
741static ssize_t
Horst Hummel138c0142006-06-29 14:58:12 +0200742dasd_ro_store(struct device *dev, struct device_attribute *attr,
743 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744{
745 struct dasd_devmap *devmap;
Stefan Weinhuber33b62a32010-03-08 12:26:24 +0100746 struct dasd_device *device;
Horst Hummel01376f42006-12-04 15:39:50 +0100747 int val;
748 char *endp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749
750 devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
751 if (IS_ERR(devmap))
752 return PTR_ERR(devmap);
Horst Hummel01376f42006-12-04 15:39:50 +0100753
754 val = simple_strtoul(buf, &endp, 0);
755 if (((endp + 1) < (buf + count)) || (val > 1))
756 return -EINVAL;
757
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758 spin_lock(&dasd_devmap_lock);
Horst Hummel01376f42006-12-04 15:39:50 +0100759 if (val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760 devmap->features |= DASD_FEATURE_READONLY;
761 else
762 devmap->features &= ~DASD_FEATURE_READONLY;
Stefan Weinhuber33b62a32010-03-08 12:26:24 +0100763 device = devmap->device;
764 if (device) {
765 device->features = devmap->features;
766 val = val || test_bit(DASD_FLAG_DEVICE_RO, &device->flags);
767 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768 spin_unlock(&dasd_devmap_lock);
Stefan Weinhuber33b62a32010-03-08 12:26:24 +0100769 if (device && device->block && device->block->gdp)
770 set_disk_ro(device->block->gdp, val);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771 return count;
772}
773
774static DEVICE_ATTR(readonly, 0644, dasd_ro_show, dasd_ro_store);
Horst Hummel9575bf22006-12-08 15:54:15 +0100775/*
776 * erplog controls the logging of ERP related data
777 * (e.g. failing channel programs).
778 */
779static ssize_t
780dasd_erplog_show(struct device *dev, struct device_attribute *attr, char *buf)
781{
782 struct dasd_devmap *devmap;
783 int erplog;
784
Kay Sievers2a0217d2008-10-10 21:33:09 +0200785 devmap = dasd_find_busid(dev_name(dev));
Horst Hummel9575bf22006-12-08 15:54:15 +0100786 if (!IS_ERR(devmap))
787 erplog = (devmap->features & DASD_FEATURE_ERPLOG) != 0;
788 else
789 erplog = (DASD_FEATURE_DEFAULT & DASD_FEATURE_ERPLOG) != 0;
790 return snprintf(buf, PAGE_SIZE, erplog ? "1\n" : "0\n");
791}
792
793static ssize_t
794dasd_erplog_store(struct device *dev, struct device_attribute *attr,
795 const char *buf, size_t count)
796{
797 struct dasd_devmap *devmap;
798 int val;
799 char *endp;
800
801 devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
802 if (IS_ERR(devmap))
803 return PTR_ERR(devmap);
804
805 val = simple_strtoul(buf, &endp, 0);
806 if (((endp + 1) < (buf + count)) || (val > 1))
807 return -EINVAL;
808
809 spin_lock(&dasd_devmap_lock);
810 if (val)
811 devmap->features |= DASD_FEATURE_ERPLOG;
812 else
813 devmap->features &= ~DASD_FEATURE_ERPLOG;
814 if (devmap->device)
815 devmap->device->features = devmap->features;
816 spin_unlock(&dasd_devmap_lock);
817 return count;
818}
819
820static DEVICE_ATTR(erplog, 0644, dasd_erplog_show, dasd_erplog_store);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821
822/*
823 * use_diag controls whether the driver should use diag rather than ssch
824 * to talk to the device
825 */
Horst Hummel138c0142006-06-29 14:58:12 +0200826static ssize_t
Yani Ioannoue404e272005-05-17 06:42:58 -0400827dasd_use_diag_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828{
829 struct dasd_devmap *devmap;
830 int use_diag;
831
Kay Sievers2a0217d2008-10-10 21:33:09 +0200832 devmap = dasd_find_busid(dev_name(dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833 if (!IS_ERR(devmap))
834 use_diag = (devmap->features & DASD_FEATURE_USEDIAG) != 0;
835 else
836 use_diag = (DASD_FEATURE_DEFAULT & DASD_FEATURE_USEDIAG) != 0;
837 return sprintf(buf, use_diag ? "1\n" : "0\n");
838}
839
840static ssize_t
Horst Hummel138c0142006-06-29 14:58:12 +0200841dasd_use_diag_store(struct device *dev, struct device_attribute *attr,
842 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843{
844 struct dasd_devmap *devmap;
845 ssize_t rc;
Horst Hummel01376f42006-12-04 15:39:50 +0100846 int val;
847 char *endp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848
849 devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
850 if (IS_ERR(devmap))
851 return PTR_ERR(devmap);
Horst Hummel01376f42006-12-04 15:39:50 +0100852
853 val = simple_strtoul(buf, &endp, 0);
854 if (((endp + 1) < (buf + count)) || (val > 1))
855 return -EINVAL;
856
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857 spin_lock(&dasd_devmap_lock);
858 /* Changing diag discipline flag is only allowed in offline state. */
859 rc = count;
860 if (!devmap->device) {
Horst Hummel01376f42006-12-04 15:39:50 +0100861 if (val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 devmap->features |= DASD_FEATURE_USEDIAG;
863 else
864 devmap->features &= ~DASD_FEATURE_USEDIAG;
865 } else
866 rc = -EPERM;
867 spin_unlock(&dasd_devmap_lock);
868 return rc;
869}
870
Horst Hummel138c0142006-06-29 14:58:12 +0200871static DEVICE_ATTR(use_diag, 0644, dasd_use_diag_show, dasd_use_diag_store);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872
873static ssize_t
Horst Hummel138c0142006-06-29 14:58:12 +0200874dasd_discipline_show(struct device *dev, struct device_attribute *attr,
875 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876{
Martin Schwidefskya00bfd72006-09-20 15:59:05 +0200877 struct dasd_device *device;
878 ssize_t len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879
Martin Schwidefskya00bfd72006-09-20 15:59:05 +0200880 device = dasd_device_from_cdev(to_ccwdev(dev));
Stefan Haberland589c74d2010-02-26 22:37:47 +0100881 if (IS_ERR(device))
882 goto out;
883 else if (!device->discipline) {
884 dasd_put_device(device);
885 goto out;
886 } else {
Martin Schwidefskya00bfd72006-09-20 15:59:05 +0200887 len = snprintf(buf, PAGE_SIZE, "%s\n",
888 device->discipline->name);
889 dasd_put_device(device);
Stefan Haberland589c74d2010-02-26 22:37:47 +0100890 return len;
891 }
892out:
893 len = snprintf(buf, PAGE_SIZE, "none\n");
Martin Schwidefskya00bfd72006-09-20 15:59:05 +0200894 return len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895}
896
897static DEVICE_ATTR(discipline, 0444, dasd_discipline_show, NULL);
898
Horst Hummel3d052592006-04-27 18:40:28 -0700899static ssize_t
Horst Hummel4dfd5c42007-04-27 16:01:47 +0200900dasd_device_status_show(struct device *dev, struct device_attribute *attr,
901 char *buf)
902{
903 struct dasd_device *device;
904 ssize_t len;
905
906 device = dasd_device_from_cdev(to_ccwdev(dev));
907 if (!IS_ERR(device)) {
908 switch (device->state) {
909 case DASD_STATE_NEW:
910 len = snprintf(buf, PAGE_SIZE, "new\n");
911 break;
912 case DASD_STATE_KNOWN:
913 len = snprintf(buf, PAGE_SIZE, "detected\n");
914 break;
915 case DASD_STATE_BASIC:
916 len = snprintf(buf, PAGE_SIZE, "basic\n");
917 break;
918 case DASD_STATE_UNFMT:
919 len = snprintf(buf, PAGE_SIZE, "unformatted\n");
920 break;
921 case DASD_STATE_READY:
922 len = snprintf(buf, PAGE_SIZE, "ready\n");
923 break;
924 case DASD_STATE_ONLINE:
925 len = snprintf(buf, PAGE_SIZE, "online\n");
926 break;
927 default:
928 len = snprintf(buf, PAGE_SIZE, "no stat\n");
929 break;
930 }
931 dasd_put_device(device);
932 } else
933 len = snprintf(buf, PAGE_SIZE, "unknown\n");
934 return len;
935}
936
937static DEVICE_ATTR(status, 0444, dasd_device_status_show, NULL);
938
Stefan Haberland2dedf0d2010-05-17 10:00:11 +0200939static ssize_t dasd_alias_show(struct device *dev,
940 struct device_attribute *attr, char *buf)
Horst Hummel3d052592006-04-27 18:40:28 -0700941{
Stefan Haberland2dedf0d2010-05-17 10:00:11 +0200942 struct dasd_device *device;
943 struct dasd_uid uid;
Horst Hummel3d052592006-04-27 18:40:28 -0700944
Stefan Haberland2dedf0d2010-05-17 10:00:11 +0200945 device = dasd_device_from_cdev(to_ccwdev(dev));
946 if (IS_ERR(device))
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100947 return sprintf(buf, "0\n");
Stefan Haberland2dedf0d2010-05-17 10:00:11 +0200948
949 if (device->discipline && device->discipline->get_uid &&
950 !device->discipline->get_uid(device, &uid)) {
951 if (uid.type == UA_BASE_PAV_ALIAS ||
Stefan Haberland0abccf72010-07-19 09:22:36 +0200952 uid.type == UA_HYPER_PAV_ALIAS) {
953 dasd_put_device(device);
Stefan Haberland2dedf0d2010-05-17 10:00:11 +0200954 return sprintf(buf, "1\n");
Stefan Haberland0abccf72010-07-19 09:22:36 +0200955 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100956 }
Stefan Haberland2dedf0d2010-05-17 10:00:11 +0200957 dasd_put_device(device);
958
959 return sprintf(buf, "0\n");
Horst Hummel3d052592006-04-27 18:40:28 -0700960}
961
962static DEVICE_ATTR(alias, 0444, dasd_alias_show, NULL);
963
Stefan Haberland2dedf0d2010-05-17 10:00:11 +0200964static ssize_t dasd_vendor_show(struct device *dev,
965 struct device_attribute *attr, char *buf)
Horst Hummel3d052592006-04-27 18:40:28 -0700966{
Stefan Haberland2dedf0d2010-05-17 10:00:11 +0200967 struct dasd_device *device;
968 struct dasd_uid uid;
Horst Hummel3d052592006-04-27 18:40:28 -0700969 char *vendor;
970
Stefan Haberland2dedf0d2010-05-17 10:00:11 +0200971 device = dasd_device_from_cdev(to_ccwdev(dev));
972 vendor = "";
973 if (IS_ERR(device))
974 return snprintf(buf, PAGE_SIZE, "%s\n", vendor);
975
976 if (device->discipline && device->discipline->get_uid &&
977 !device->discipline->get_uid(device, &uid))
978 vendor = uid.vendor;
979
980 dasd_put_device(device);
Horst Hummel3d052592006-04-27 18:40:28 -0700981
982 return snprintf(buf, PAGE_SIZE, "%s\n", vendor);
983}
984
985static DEVICE_ATTR(vendor, 0444, dasd_vendor_show, NULL);
986
987#define UID_STRLEN ( /* vendor */ 3 + 1 + /* serial */ 14 + 1 +\
Stefan Weinhuber4abb08c2008-08-01 16:39:09 +0200988 /* SSID */ 4 + 1 + /* unit addr */ 2 + 1 +\
989 /* vduit */ 32 + 1)
Horst Hummel3d052592006-04-27 18:40:28 -0700990
991static ssize_t
992dasd_uid_show(struct device *dev, struct device_attribute *attr, char *buf)
993{
Stefan Haberland2dedf0d2010-05-17 10:00:11 +0200994 struct dasd_device *device;
995 struct dasd_uid uid;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100996 char uid_string[UID_STRLEN];
997 char ua_string[3];
Horst Hummel3d052592006-04-27 18:40:28 -0700998
Stefan Haberland2dedf0d2010-05-17 10:00:11 +0200999 device = dasd_device_from_cdev(to_ccwdev(dev));
1000 uid_string[0] = 0;
1001 if (IS_ERR(device))
1002 return snprintf(buf, PAGE_SIZE, "%s\n", uid_string);
1003
1004 if (device->discipline && device->discipline->get_uid &&
1005 !device->discipline->get_uid(device, &uid)) {
1006 switch (uid.type) {
1007 case UA_BASE_DEVICE:
1008 snprintf(ua_string, sizeof(ua_string), "%02x",
1009 uid.real_unit_addr);
1010 break;
1011 case UA_BASE_PAV_ALIAS:
1012 snprintf(ua_string, sizeof(ua_string), "%02x",
1013 uid.base_unit_addr);
1014 break;
1015 case UA_HYPER_PAV_ALIAS:
1016 snprintf(ua_string, sizeof(ua_string), "xx");
1017 break;
1018 default:
1019 /* should not happen, treat like base device */
1020 snprintf(ua_string, sizeof(ua_string), "%02x",
1021 uid.real_unit_addr);
1022 break;
1023 }
1024
1025 if (strlen(uid.vduit) > 0)
1026 snprintf(uid_string, sizeof(uid_string),
1027 "%s.%s.%04x.%s.%s",
1028 uid.vendor, uid.serial, uid.ssid, ua_string,
1029 uid.vduit);
1030 else
1031 snprintf(uid_string, sizeof(uid_string),
1032 "%s.%s.%04x.%s",
1033 uid.vendor, uid.serial, uid.ssid, ua_string);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001034 }
Stefan Haberland2dedf0d2010-05-17 10:00:11 +02001035 dasd_put_device(device);
1036
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001037 return snprintf(buf, PAGE_SIZE, "%s\n", uid_string);
Horst Hummel3d052592006-04-27 18:40:28 -07001038}
Horst Hummel3d052592006-04-27 18:40:28 -07001039static DEVICE_ATTR(uid, 0444, dasd_uid_show, NULL);
1040
Stefan Weinhuber20c64462006-03-24 03:15:25 -08001041/*
1042 * extended error-reporting
1043 */
1044static ssize_t
1045dasd_eer_show(struct device *dev, struct device_attribute *attr, char *buf)
1046{
1047 struct dasd_devmap *devmap;
1048 int eer_flag;
1049
Kay Sievers2a0217d2008-10-10 21:33:09 +02001050 devmap = dasd_find_busid(dev_name(dev));
Stefan Weinhuber20c64462006-03-24 03:15:25 -08001051 if (!IS_ERR(devmap) && devmap->device)
1052 eer_flag = dasd_eer_enabled(devmap->device);
1053 else
1054 eer_flag = 0;
1055 return snprintf(buf, PAGE_SIZE, eer_flag ? "1\n" : "0\n");
1056}
1057
1058static ssize_t
1059dasd_eer_store(struct device *dev, struct device_attribute *attr,
1060 const char *buf, size_t count)
1061{
1062 struct dasd_devmap *devmap;
Horst Hummel01376f42006-12-04 15:39:50 +01001063 int val, rc;
1064 char *endp;
Stefan Weinhuber20c64462006-03-24 03:15:25 -08001065
1066 devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
1067 if (IS_ERR(devmap))
1068 return PTR_ERR(devmap);
1069 if (!devmap->device)
Horst Hummel01376f42006-12-04 15:39:50 +01001070 return -ENODEV;
1071
1072 val = simple_strtoul(buf, &endp, 0);
1073 if (((endp + 1) < (buf + count)) || (val > 1))
1074 return -EINVAL;
1075
Horst Hummel645c98c2006-12-04 15:40:18 +01001076 if (val) {
Stefan Weinhuber20c64462006-03-24 03:15:25 -08001077 rc = dasd_eer_enable(devmap->device);
Horst Hummel645c98c2006-12-04 15:40:18 +01001078 if (rc)
1079 return rc;
1080 } else
Stefan Weinhuber20c64462006-03-24 03:15:25 -08001081 dasd_eer_disable(devmap->device);
Horst Hummel645c98c2006-12-04 15:40:18 +01001082 return count;
Stefan Weinhuber20c64462006-03-24 03:15:25 -08001083}
1084
1085static DEVICE_ATTR(eer_enabled, 0644, dasd_eer_show, dasd_eer_store);
1086
Stefan Haberland7c8faa82010-08-09 18:13:00 +02001087/*
1088 * expiration time for default requests
1089 */
1090static ssize_t
1091dasd_expires_show(struct device *dev, struct device_attribute *attr, char *buf)
1092{
1093 struct dasd_device *device;
1094 int len;
1095
1096 device = dasd_device_from_cdev(to_ccwdev(dev));
1097 if (IS_ERR(device))
1098 return -ENODEV;
1099 len = snprintf(buf, PAGE_SIZE, "%lu\n", device->default_expires);
1100 dasd_put_device(device);
1101 return len;
1102}
1103
1104static ssize_t
1105dasd_expires_store(struct device *dev, struct device_attribute *attr,
1106 const char *buf, size_t count)
1107{
1108 struct dasd_device *device;
1109 unsigned long val;
1110
1111 device = dasd_device_from_cdev(to_ccwdev(dev));
1112 if (IS_ERR(device))
1113 return -ENODEV;
1114
1115 if ((strict_strtoul(buf, 10, &val) != 0) ||
1116 (val > DASD_EXPIRES_MAX) || val == 0) {
1117 dasd_put_device(device);
1118 return -EINVAL;
1119 }
1120
1121 if (val)
1122 device->default_expires = val;
1123
1124 dasd_put_device(device);
1125 return count;
1126}
1127
1128static DEVICE_ATTR(expires, 0644, dasd_expires_show, dasd_expires_store);
1129
Stefan Weinhuber5a27e602011-01-05 12:48:04 +01001130static ssize_t dasd_reservation_policy_show(struct device *dev,
1131 struct device_attribute *attr,
1132 char *buf)
1133{
1134 struct dasd_devmap *devmap;
1135 int rc = 0;
1136
1137 devmap = dasd_find_busid(dev_name(dev));
1138 if (IS_ERR(devmap)) {
1139 rc = snprintf(buf, PAGE_SIZE, "ignore\n");
1140 } else {
1141 spin_lock(&dasd_devmap_lock);
1142 if (devmap->features & DASD_FEATURE_FAILONSLCK)
1143 rc = snprintf(buf, PAGE_SIZE, "fail\n");
1144 else
1145 rc = snprintf(buf, PAGE_SIZE, "ignore\n");
1146 spin_unlock(&dasd_devmap_lock);
1147 }
1148 return rc;
1149}
1150
1151static ssize_t dasd_reservation_policy_store(struct device *dev,
1152 struct device_attribute *attr,
1153 const char *buf, size_t count)
1154{
1155 struct dasd_devmap *devmap;
1156 int rc;
1157
1158 devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
1159 if (IS_ERR(devmap))
1160 return PTR_ERR(devmap);
1161 rc = 0;
1162 spin_lock(&dasd_devmap_lock);
1163 if (sysfs_streq("ignore", buf))
1164 devmap->features &= ~DASD_FEATURE_FAILONSLCK;
1165 else if (sysfs_streq("fail", buf))
1166 devmap->features |= DASD_FEATURE_FAILONSLCK;
1167 else
1168 rc = -EINVAL;
1169 if (devmap->device)
1170 devmap->device->features = devmap->features;
1171 spin_unlock(&dasd_devmap_lock);
1172 if (rc)
1173 return rc;
1174 else
1175 return count;
1176}
1177
1178static DEVICE_ATTR(reservation_policy, 0644,
1179 dasd_reservation_policy_show, dasd_reservation_policy_store);
1180
1181static ssize_t dasd_reservation_state_show(struct device *dev,
1182 struct device_attribute *attr,
1183 char *buf)
1184{
1185 struct dasd_device *device;
1186 int rc = 0;
1187
1188 device = dasd_device_from_cdev(to_ccwdev(dev));
1189 if (IS_ERR(device))
1190 return snprintf(buf, PAGE_SIZE, "none\n");
1191
1192 if (test_bit(DASD_FLAG_IS_RESERVED, &device->flags))
1193 rc = snprintf(buf, PAGE_SIZE, "reserved\n");
1194 else if (test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags))
1195 rc = snprintf(buf, PAGE_SIZE, "lost\n");
1196 else
1197 rc = snprintf(buf, PAGE_SIZE, "none\n");
1198 dasd_put_device(device);
1199 return rc;
1200}
1201
1202static ssize_t dasd_reservation_state_store(struct device *dev,
1203 struct device_attribute *attr,
1204 const char *buf, size_t count)
1205{
1206 struct dasd_device *device;
1207 int rc = 0;
1208
1209 device = dasd_device_from_cdev(to_ccwdev(dev));
1210 if (IS_ERR(device))
1211 return -ENODEV;
1212 if (sysfs_streq("reset", buf))
1213 clear_bit(DASD_FLAG_LOCK_STOLEN, &device->flags);
1214 else
1215 rc = -EINVAL;
1216 dasd_put_device(device);
1217
1218 if (rc)
1219 return rc;
1220 else
1221 return count;
1222}
1223
1224static DEVICE_ATTR(last_known_reservation_state, 0644,
1225 dasd_reservation_state_show, dasd_reservation_state_store);
1226
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227static struct attribute * dasd_attrs[] = {
1228 &dev_attr_readonly.attr,
1229 &dev_attr_discipline.attr,
Horst Hummel4dfd5c42007-04-27 16:01:47 +02001230 &dev_attr_status.attr,
Horst Hummel3d052592006-04-27 18:40:28 -07001231 &dev_attr_alias.attr,
1232 &dev_attr_vendor.attr,
1233 &dev_attr_uid.attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234 &dev_attr_use_diag.attr,
Stefan Weinhuber20c64462006-03-24 03:15:25 -08001235 &dev_attr_eer_enabled.attr,
Horst Hummel9575bf22006-12-08 15:54:15 +01001236 &dev_attr_erplog.attr,
Holger Smolinski13de2272009-01-09 12:14:51 +01001237 &dev_attr_failfast.attr,
Stefan Haberland7c8faa82010-08-09 18:13:00 +02001238 &dev_attr_expires.attr,
Stefan Weinhuber5a27e602011-01-05 12:48:04 +01001239 &dev_attr_reservation_policy.attr,
1240 &dev_attr_last_known_reservation_state.attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241 NULL,
1242};
1243
1244static struct attribute_group dasd_attr_group = {
1245 .attrs = dasd_attrs,
1246};
1247
Horst Hummel40545572006-06-29 15:08:18 +02001248/*
Horst Hummelf24acd42005-05-01 08:58:59 -07001249 * Return value of the specified feature.
1250 */
1251int
1252dasd_get_feature(struct ccw_device *cdev, int feature)
1253{
1254 struct dasd_devmap *devmap;
1255
Kay Sievers2a0217d2008-10-10 21:33:09 +02001256 devmap = dasd_find_busid(dev_name(&cdev->dev));
Horst Hummelf24acd42005-05-01 08:58:59 -07001257 if (IS_ERR(devmap))
Horst Hummel40545572006-06-29 15:08:18 +02001258 return PTR_ERR(devmap);
Horst Hummelf24acd42005-05-01 08:58:59 -07001259
1260 return ((devmap->features & feature) != 0);
1261}
1262
1263/*
1264 * Set / reset given feature.
1265 * Flag indicates wether to set (!=0) or the reset (=0) the feature.
1266 */
1267int
1268dasd_set_feature(struct ccw_device *cdev, int feature, int flag)
1269{
1270 struct dasd_devmap *devmap;
1271
Kay Sievers2a0217d2008-10-10 21:33:09 +02001272 devmap = dasd_find_busid(dev_name(&cdev->dev));
Horst Hummelf24acd42005-05-01 08:58:59 -07001273 if (IS_ERR(devmap))
Horst Hummel40545572006-06-29 15:08:18 +02001274 return PTR_ERR(devmap);
Horst Hummelf24acd42005-05-01 08:58:59 -07001275
1276 spin_lock(&dasd_devmap_lock);
1277 if (flag)
1278 devmap->features |= feature;
1279 else
1280 devmap->features &= ~feature;
Horst Hummelc6eb7b72005-09-03 15:57:58 -07001281 if (devmap->device)
1282 devmap->device->features = devmap->features;
Horst Hummelf24acd42005-05-01 08:58:59 -07001283 spin_unlock(&dasd_devmap_lock);
1284 return 0;
1285}
1286
1287
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288int
1289dasd_add_sysfs_files(struct ccw_device *cdev)
1290{
1291 return sysfs_create_group(&cdev->dev.kobj, &dasd_attr_group);
1292}
1293
1294void
1295dasd_remove_sysfs_files(struct ccw_device *cdev)
1296{
1297 sysfs_remove_group(&cdev->dev.kobj, &dasd_attr_group);
1298}
1299
1300
1301int
1302dasd_devmap_init(void)
1303{
1304 int i;
1305
1306 /* Initialize devmap structures. */
1307 dasd_max_devindex = 0;
1308 for (i = 0; i < 256; i++)
1309 INIT_LIST_HEAD(&dasd_hashlists[i]);
Horst Hummel40545572006-06-29 15:08:18 +02001310 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311}
1312
1313void
1314dasd_devmap_exit(void)
1315{
1316 dasd_forget_ranges();
1317}