blob: eff9c812c5c2befa559e1281fd2a1cb152451659 [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;
Horst Hummel3d052592006-04-27 18:40:28 -070052 struct dasd_uid uid;
Linus Torvalds1da177e2005-04-16 15:20:36 -070053};
54
55/*
56 * Parameter parsing functions for dasd= parameter. The syntax is:
57 * <devno> : (0x)?[0-9a-fA-F]+
58 * <busid> : [0-0a-f]\.[0-9a-f]\.(0x)?[0-9a-fA-F]+
59 * <feature> : ro
60 * <feature_list> : \(<feature>(:<feature>)*\)
61 * <devno-range> : <devno>(-<devno>)?<feature_list>?
62 * <busid-range> : <busid>(-<busid>)?<feature_list>?
63 * <devices> : <devno-range>|<busid-range>
64 * <dasd_module> : dasd_diag_mod|dasd_eckd_mod|dasd_fba_mod
65 *
66 * <dasd> : autodetect|probeonly|<devices>(,<devices>)*
67 */
68
69int dasd_probeonly = 0; /* is true, when probeonly mode is active */
70int dasd_autodetect = 0; /* is true, when autodetection is active */
Horst Hummel40545572006-06-29 15:08:18 +020071int dasd_nopav = 0; /* is true, when PAV is disabled */
72EXPORT_SYMBOL_GPL(dasd_nopav);
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +010073int dasd_nofcx; /* disable High Performance Ficon */
74EXPORT_SYMBOL_GPL(dasd_nofcx);
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
76/*
77 * char *dasd[] is intended to hold the ranges supplied by the dasd= statement
78 * it is named 'dasd' to directly be filled by insmod with the comma separated
79 * strings when running as a module.
80 */
81static char *dasd[256];
Rusty Russell8d3b33f2006-03-25 03:07:05 -080082module_param_array(dasd, charp, NULL, 0);
83
Linus Torvalds1da177e2005-04-16 15:20:36 -070084/*
Horst Hummeld0710c72006-08-10 15:45:16 +020085 * Single spinlock to protect devmap and servermap structures and lists.
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 */
87static DEFINE_SPINLOCK(dasd_devmap_lock);
88
89/*
90 * Hash lists for devmap structures.
91 */
92static struct list_head dasd_hashlists[256];
93int dasd_max_devindex;
94
Cornelia Huck69f90f62008-05-15 16:52:34 +020095static struct dasd_devmap *dasd_add_busid(const char *, int);
Linus Torvalds1da177e2005-04-16 15:20:36 -070096
97static inline int
Cornelia Huck69f90f62008-05-15 16:52:34 +020098dasd_hash_busid(const char *bus_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -070099{
100 int hash, i;
101
102 hash = 0;
Kay Sievers98df67b2008-12-25 13:38:55 +0100103 for (i = 0; (i < DASD_BUS_ID_SIZE) && *bus_id; i++, bus_id++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 hash += *bus_id;
105 return hash & 0xff;
106}
107
108#ifndef MODULE
109/*
110 * The parameter parsing functions for builtin-drivers are called
111 * before kmalloc works. Store the pointers to the parameters strings
112 * into dasd[] for later processing.
113 */
114static int __init
115dasd_call_setup(char *str)
116{
117 static int count = 0;
118
119 if (count < 256)
120 dasd[count++] = str;
121 return 1;
122}
123
124__setup ("dasd=", dasd_call_setup);
125#endif /* #ifndef MODULE */
126
Peter Oberparleiter7039d3a2007-04-27 16:01:48 +0200127#define DASD_IPLDEV "ipldev"
128
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129/*
130 * Read a device busid/devno from a string.
131 */
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100132static int
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100133
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134dasd_busid(char **str, int *id0, int *id1, int *devno)
135{
136 int val, old_style;
Horst Hummel138c0142006-06-29 14:58:12 +0200137
Peter Oberparleiter7039d3a2007-04-27 16:01:48 +0200138 /* Interpret ipldev busid */
139 if (strncmp(DASD_IPLDEV, *str, strlen(DASD_IPLDEV)) == 0) {
140 if (ipl_info.type != IPL_TYPE_CCW) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100141 pr_err("The IPL device is not a CCW device\n");
Peter Oberparleiter7039d3a2007-04-27 16:01:48 +0200142 return -EINVAL;
143 }
144 *id0 = 0;
145 *id1 = ipl_info.data.ccw.dev_id.ssid;
146 *devno = ipl_info.data.ccw.dev_id.devno;
147 *str += strlen(DASD_IPLDEV);
148
149 return 0;
150 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 /* check for leading '0x' */
152 old_style = 0;
153 if ((*str)[0] == '0' && (*str)[1] == 'x') {
154 *str += 2;
155 old_style = 1;
156 }
157 if (!isxdigit((*str)[0])) /* We require at least one hex digit */
158 return -EINVAL;
159 val = simple_strtoul(*str, str, 16);
160 if (old_style || (*str)[0] != '.') {
161 *id0 = *id1 = 0;
162 if (val < 0 || val > 0xffff)
163 return -EINVAL;
164 *devno = val;
165 return 0;
166 }
167 /* New style x.y.z busid */
168 if (val < 0 || val > 0xff)
169 return -EINVAL;
170 *id0 = val;
171 (*str)++;
172 if (!isxdigit((*str)[0])) /* We require at least one hex digit */
173 return -EINVAL;
174 val = simple_strtoul(*str, str, 16);
175 if (val < 0 || val > 0xff || (*str)++[0] != '.')
176 return -EINVAL;
177 *id1 = val;
178 if (!isxdigit((*str)[0])) /* We require at least one hex digit */
179 return -EINVAL;
180 val = simple_strtoul(*str, str, 16);
181 if (val < 0 || val > 0xffff)
182 return -EINVAL;
183 *devno = val;
184 return 0;
185}
186
187/*
188 * Read colon separated list of dasd features. Currently there is
189 * only one: "ro" for read-only devices. The default feature set
190 * is empty (value 0).
191 */
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100192static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193dasd_feature_list(char *str, char **endp)
194{
195 int features, len, rc;
196
197 rc = 0;
198 if (*str != '(') {
199 *endp = str;
200 return DASD_FEATURE_DEFAULT;
201 }
202 str++;
203 features = 0;
204
205 while (1) {
Horst Hummel138c0142006-06-29 14:58:12 +0200206 for (len = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 str[len] && str[len] != ':' && str[len] != ')'; len++);
208 if (len == 2 && !strncmp(str, "ro", 2))
209 features |= DASD_FEATURE_READONLY;
210 else if (len == 4 && !strncmp(str, "diag", 4))
211 features |= DASD_FEATURE_USEDIAG;
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
304 * successfull, create the matching dasd_devmap entries and return a pointer
305 * 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}
643
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
939static ssize_t
Horst Hummel3d052592006-04-27 18:40:28 -0700940dasd_alias_show(struct device *dev, struct device_attribute *attr, char *buf)
941{
942 struct dasd_devmap *devmap;
943 int alias;
944
Kay Sievers2a0217d2008-10-10 21:33:09 +0200945 devmap = dasd_find_busid(dev_name(dev));
Horst Hummel3d052592006-04-27 18:40:28 -0700946 spin_lock(&dasd_devmap_lock);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100947 if (IS_ERR(devmap) || strlen(devmap->uid.vendor) == 0) {
948 spin_unlock(&dasd_devmap_lock);
949 return sprintf(buf, "0\n");
950 }
951 if (devmap->uid.type == UA_BASE_PAV_ALIAS ||
952 devmap->uid.type == UA_HYPER_PAV_ALIAS)
953 alias = 1;
Horst Hummel3d052592006-04-27 18:40:28 -0700954 else
955 alias = 0;
956 spin_unlock(&dasd_devmap_lock);
Horst Hummel3d052592006-04-27 18:40:28 -0700957 return sprintf(buf, alias ? "1\n" : "0\n");
958}
959
960static DEVICE_ATTR(alias, 0444, dasd_alias_show, NULL);
961
962static ssize_t
963dasd_vendor_show(struct device *dev, struct device_attribute *attr, char *buf)
964{
965 struct dasd_devmap *devmap;
966 char *vendor;
967
Kay Sievers2a0217d2008-10-10 21:33:09 +0200968 devmap = dasd_find_busid(dev_name(dev));
Horst Hummel3d052592006-04-27 18:40:28 -0700969 spin_lock(&dasd_devmap_lock);
970 if (!IS_ERR(devmap) && strlen(devmap->uid.vendor) > 0)
971 vendor = devmap->uid.vendor;
972 else
973 vendor = "";
974 spin_unlock(&dasd_devmap_lock);
975
976 return snprintf(buf, PAGE_SIZE, "%s\n", vendor);
977}
978
979static DEVICE_ATTR(vendor, 0444, dasd_vendor_show, NULL);
980
981#define UID_STRLEN ( /* vendor */ 3 + 1 + /* serial */ 14 + 1 +\
Stefan Weinhuber4abb08c2008-08-01 16:39:09 +0200982 /* SSID */ 4 + 1 + /* unit addr */ 2 + 1 +\
983 /* vduit */ 32 + 1)
Horst Hummel3d052592006-04-27 18:40:28 -0700984
985static ssize_t
986dasd_uid_show(struct device *dev, struct device_attribute *attr, char *buf)
987{
988 struct dasd_devmap *devmap;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100989 char uid_string[UID_STRLEN];
990 char ua_string[3];
991 struct dasd_uid *uid;
Horst Hummel3d052592006-04-27 18:40:28 -0700992
Kay Sievers2a0217d2008-10-10 21:33:09 +0200993 devmap = dasd_find_busid(dev_name(dev));
Horst Hummel3d052592006-04-27 18:40:28 -0700994 spin_lock(&dasd_devmap_lock);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100995 if (IS_ERR(devmap) || strlen(devmap->uid.vendor) == 0) {
996 spin_unlock(&dasd_devmap_lock);
997 return sprintf(buf, "\n");
998 }
999 uid = &devmap->uid;
1000 switch (uid->type) {
1001 case UA_BASE_DEVICE:
1002 sprintf(ua_string, "%02x", uid->real_unit_addr);
1003 break;
1004 case UA_BASE_PAV_ALIAS:
1005 sprintf(ua_string, "%02x", uid->base_unit_addr);
1006 break;
1007 case UA_HYPER_PAV_ALIAS:
1008 sprintf(ua_string, "xx");
1009 break;
1010 default:
1011 /* should not happen, treat like base device */
1012 sprintf(ua_string, "%02x", uid->real_unit_addr);
1013 break;
1014 }
Stefan Weinhuber4abb08c2008-08-01 16:39:09 +02001015 if (strlen(uid->vduit) > 0)
1016 snprintf(uid_string, sizeof(uid_string),
1017 "%s.%s.%04x.%s.%s",
1018 uid->vendor, uid->serial,
1019 uid->ssid, ua_string,
1020 uid->vduit);
1021 else
1022 snprintf(uid_string, sizeof(uid_string),
1023 "%s.%s.%04x.%s",
1024 uid->vendor, uid->serial,
1025 uid->ssid, ua_string);
Horst Hummel3d052592006-04-27 18:40:28 -07001026 spin_unlock(&dasd_devmap_lock);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001027 return snprintf(buf, PAGE_SIZE, "%s\n", uid_string);
Horst Hummel3d052592006-04-27 18:40:28 -07001028}
1029
1030static DEVICE_ATTR(uid, 0444, dasd_uid_show, NULL);
1031
Stefan Weinhuber20c64462006-03-24 03:15:25 -08001032/*
1033 * extended error-reporting
1034 */
1035static ssize_t
1036dasd_eer_show(struct device *dev, struct device_attribute *attr, char *buf)
1037{
1038 struct dasd_devmap *devmap;
1039 int eer_flag;
1040
Kay Sievers2a0217d2008-10-10 21:33:09 +02001041 devmap = dasd_find_busid(dev_name(dev));
Stefan Weinhuber20c64462006-03-24 03:15:25 -08001042 if (!IS_ERR(devmap) && devmap->device)
1043 eer_flag = dasd_eer_enabled(devmap->device);
1044 else
1045 eer_flag = 0;
1046 return snprintf(buf, PAGE_SIZE, eer_flag ? "1\n" : "0\n");
1047}
1048
1049static ssize_t
1050dasd_eer_store(struct device *dev, struct device_attribute *attr,
1051 const char *buf, size_t count)
1052{
1053 struct dasd_devmap *devmap;
Horst Hummel01376f42006-12-04 15:39:50 +01001054 int val, rc;
1055 char *endp;
Stefan Weinhuber20c64462006-03-24 03:15:25 -08001056
1057 devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
1058 if (IS_ERR(devmap))
1059 return PTR_ERR(devmap);
1060 if (!devmap->device)
Horst Hummel01376f42006-12-04 15:39:50 +01001061 return -ENODEV;
1062
1063 val = simple_strtoul(buf, &endp, 0);
1064 if (((endp + 1) < (buf + count)) || (val > 1))
1065 return -EINVAL;
1066
Horst Hummel645c98c2006-12-04 15:40:18 +01001067 if (val) {
Stefan Weinhuber20c64462006-03-24 03:15:25 -08001068 rc = dasd_eer_enable(devmap->device);
Horst Hummel645c98c2006-12-04 15:40:18 +01001069 if (rc)
1070 return rc;
1071 } else
Stefan Weinhuber20c64462006-03-24 03:15:25 -08001072 dasd_eer_disable(devmap->device);
Horst Hummel645c98c2006-12-04 15:40:18 +01001073 return count;
Stefan Weinhuber20c64462006-03-24 03:15:25 -08001074}
1075
1076static DEVICE_ATTR(eer_enabled, 0644, dasd_eer_show, dasd_eer_store);
1077
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078static struct attribute * dasd_attrs[] = {
1079 &dev_attr_readonly.attr,
1080 &dev_attr_discipline.attr,
Horst Hummel4dfd5c42007-04-27 16:01:47 +02001081 &dev_attr_status.attr,
Horst Hummel3d052592006-04-27 18:40:28 -07001082 &dev_attr_alias.attr,
1083 &dev_attr_vendor.attr,
1084 &dev_attr_uid.attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085 &dev_attr_use_diag.attr,
Stefan Weinhuber20c64462006-03-24 03:15:25 -08001086 &dev_attr_eer_enabled.attr,
Horst Hummel9575bf22006-12-08 15:54:15 +01001087 &dev_attr_erplog.attr,
Holger Smolinski13de2272009-01-09 12:14:51 +01001088 &dev_attr_failfast.attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089 NULL,
1090};
1091
1092static struct attribute_group dasd_attr_group = {
1093 .attrs = dasd_attrs,
1094};
1095
Horst Hummel40545572006-06-29 15:08:18 +02001096/*
Horst Hummel3d052592006-04-27 18:40:28 -07001097 * Return copy of the device unique identifier.
1098 */
1099int
1100dasd_get_uid(struct ccw_device *cdev, struct dasd_uid *uid)
1101{
1102 struct dasd_devmap *devmap;
1103
Kay Sievers2a0217d2008-10-10 21:33:09 +02001104 devmap = dasd_find_busid(dev_name(&cdev->dev));
Horst Hummel3d052592006-04-27 18:40:28 -07001105 if (IS_ERR(devmap))
1106 return PTR_ERR(devmap);
1107 spin_lock(&dasd_devmap_lock);
1108 *uid = devmap->uid;
1109 spin_unlock(&dasd_devmap_lock);
1110 return 0;
1111}
Stefan Haberlandd41dd122009-06-16 10:30:25 +02001112EXPORT_SYMBOL_GPL(dasd_get_uid);
Horst Hummel3d052592006-04-27 18:40:28 -07001113
1114/*
1115 * Register the given device unique identifier into devmap struct.
Peter Oberparleiterb18a60e2006-08-16 13:49:33 +02001116 * In addition check if the related storage server subsystem ID is already
1117 * contained in the dasd_server_ssid_list. If subsystem ID is not contained,
1118 * create new entry.
Horst Hummel40545572006-06-29 15:08:18 +02001119 * Return 0 if server was already in serverlist,
1120 * 1 if the server was added successful
1121 * <0 in case of error.
Horst Hummel3d052592006-04-27 18:40:28 -07001122 */
1123int
1124dasd_set_uid(struct ccw_device *cdev, struct dasd_uid *uid)
1125{
1126 struct dasd_devmap *devmap;
1127
Kay Sievers2a0217d2008-10-10 21:33:09 +02001128 devmap = dasd_find_busid(dev_name(&cdev->dev));
Horst Hummel3d052592006-04-27 18:40:28 -07001129 if (IS_ERR(devmap))
1130 return PTR_ERR(devmap);
Horst Hummeld0710c72006-08-10 15:45:16 +02001131
Horst Hummel3d052592006-04-27 18:40:28 -07001132 spin_lock(&dasd_devmap_lock);
1133 devmap->uid = *uid;
1134 spin_unlock(&dasd_devmap_lock);
Horst Hummeld0710c72006-08-10 15:45:16 +02001135
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001136 return 0;
Horst Hummel3d052592006-04-27 18:40:28 -07001137}
Horst Hummel40545572006-06-29 15:08:18 +02001138EXPORT_SYMBOL_GPL(dasd_set_uid);
Horst Hummel3d052592006-04-27 18:40:28 -07001139
Horst Hummelf24acd42005-05-01 08:58:59 -07001140/*
1141 * Return value of the specified feature.
1142 */
1143int
1144dasd_get_feature(struct ccw_device *cdev, int feature)
1145{
1146 struct dasd_devmap *devmap;
1147
Kay Sievers2a0217d2008-10-10 21:33:09 +02001148 devmap = dasd_find_busid(dev_name(&cdev->dev));
Horst Hummelf24acd42005-05-01 08:58:59 -07001149 if (IS_ERR(devmap))
Horst Hummel40545572006-06-29 15:08:18 +02001150 return PTR_ERR(devmap);
Horst Hummelf24acd42005-05-01 08:58:59 -07001151
1152 return ((devmap->features & feature) != 0);
1153}
1154
1155/*
1156 * Set / reset given feature.
1157 * Flag indicates wether to set (!=0) or the reset (=0) the feature.
1158 */
1159int
1160dasd_set_feature(struct ccw_device *cdev, int feature, int flag)
1161{
1162 struct dasd_devmap *devmap;
1163
Kay Sievers2a0217d2008-10-10 21:33:09 +02001164 devmap = dasd_find_busid(dev_name(&cdev->dev));
Horst Hummelf24acd42005-05-01 08:58:59 -07001165 if (IS_ERR(devmap))
Horst Hummel40545572006-06-29 15:08:18 +02001166 return PTR_ERR(devmap);
Horst Hummelf24acd42005-05-01 08:58:59 -07001167
1168 spin_lock(&dasd_devmap_lock);
1169 if (flag)
1170 devmap->features |= feature;
1171 else
1172 devmap->features &= ~feature;
Horst Hummelc6eb7b72005-09-03 15:57:58 -07001173 if (devmap->device)
1174 devmap->device->features = devmap->features;
Horst Hummelf24acd42005-05-01 08:58:59 -07001175 spin_unlock(&dasd_devmap_lock);
1176 return 0;
1177}
1178
1179
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180int
1181dasd_add_sysfs_files(struct ccw_device *cdev)
1182{
1183 return sysfs_create_group(&cdev->dev.kobj, &dasd_attr_group);
1184}
1185
1186void
1187dasd_remove_sysfs_files(struct ccw_device *cdev)
1188{
1189 sysfs_remove_group(&cdev->dev.kobj, &dasd_attr_group);
1190}
1191
1192
1193int
1194dasd_devmap_init(void)
1195{
1196 int i;
1197
1198 /* Initialize devmap structures. */
1199 dasd_max_devindex = 0;
1200 for (i = 0; i < 256; i++)
1201 INIT_LIST_HEAD(&dasd_hashlists[i]);
Horst Hummel40545572006-06-29 15:08:18 +02001202 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203}
1204
1205void
1206dasd_devmap_exit(void)
1207{
1208 dasd_forget_ranges();
1209}