Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | */ |
| 15 | |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame^] | 16 | #define KMSG_COMPONENT "dasd" |
| 17 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <linux/ctype.h> |
| 19 | #include <linux/init.h> |
Rusty Russell | 8d3b33f | 2006-03-25 03:07:05 -0800 | [diff] [blame] | 20 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | |
| 22 | #include <asm/debug.h> |
| 23 | #include <asm/uaccess.h> |
Peter Oberparleiter | 7039d3a | 2007-04-27 16:01:48 +0200 | [diff] [blame] | 24 | #include <asm/ipl.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | |
| 26 | /* This is ugly... */ |
| 27 | #define PRINTK_HEADER "dasd_devmap:" |
Kay Sievers | 98df67b | 2008-12-25 13:38:55 +0100 | [diff] [blame] | 28 | #define DASD_BUS_ID_SIZE 20 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | |
| 30 | #include "dasd_int.h" |
| 31 | |
Christoph Lameter | e18b890 | 2006-12-06 20:33:20 -0800 | [diff] [blame] | 32 | struct kmem_cache *dasd_page_cache; |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 33 | EXPORT_SYMBOL_GPL(dasd_page_cache); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | |
| 35 | /* |
| 36 | * dasd_devmap_t is used to store the features and the relation |
| 37 | * between device number and device index. To find a dasd_devmap_t |
| 38 | * that corresponds to a device number of a device index each |
| 39 | * dasd_devmap_t is added to two linked lists, one to search by |
| 40 | * the device number and one to search by the device index. As |
| 41 | * soon as big minor numbers are available the device index list |
| 42 | * can be removed since the device number will then be identical |
| 43 | * to the device index. |
| 44 | */ |
| 45 | struct dasd_devmap { |
| 46 | struct list_head list; |
Kay Sievers | 98df67b | 2008-12-25 13:38:55 +0100 | [diff] [blame] | 47 | char bus_id[DASD_BUS_ID_SIZE]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | unsigned int devindex; |
| 49 | unsigned short features; |
| 50 | struct dasd_device *device; |
Horst Hummel | 3d05259 | 2006-04-27 18:40:28 -0700 | [diff] [blame] | 51 | struct dasd_uid uid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
| 68 | int dasd_probeonly = 0; /* is true, when probeonly mode is active */ |
| 69 | int dasd_autodetect = 0; /* is true, when autodetection is active */ |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 70 | int dasd_nopav = 0; /* is true, when PAV is disabled */ |
| 71 | EXPORT_SYMBOL_GPL(dasd_nopav); |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 72 | int dasd_nofcx; /* disable High Performance Ficon */ |
| 73 | EXPORT_SYMBOL_GPL(dasd_nofcx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | |
| 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 | */ |
| 80 | static char *dasd[256]; |
Rusty Russell | 8d3b33f | 2006-03-25 03:07:05 -0800 | [diff] [blame] | 81 | module_param_array(dasd, charp, NULL, 0); |
| 82 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | /* |
Horst Hummel | d0710c7 | 2006-08-10 15:45:16 +0200 | [diff] [blame] | 84 | * Single spinlock to protect devmap and servermap structures and lists. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | */ |
| 86 | static DEFINE_SPINLOCK(dasd_devmap_lock); |
| 87 | |
| 88 | /* |
| 89 | * Hash lists for devmap structures. |
| 90 | */ |
| 91 | static struct list_head dasd_hashlists[256]; |
| 92 | int dasd_max_devindex; |
| 93 | |
Cornelia Huck | 69f90f6 | 2008-05-15 16:52:34 +0200 | [diff] [blame] | 94 | static struct dasd_devmap *dasd_add_busid(const char *, int); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | |
| 96 | static inline int |
Cornelia Huck | 69f90f6 | 2008-05-15 16:52:34 +0200 | [diff] [blame] | 97 | dasd_hash_busid(const char *bus_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | { |
| 99 | int hash, i; |
| 100 | |
| 101 | hash = 0; |
Kay Sievers | 98df67b | 2008-12-25 13:38:55 +0100 | [diff] [blame] | 102 | for (i = 0; (i < DASD_BUS_ID_SIZE) && *bus_id; i++, bus_id++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | 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 | */ |
| 113 | static int __init |
| 114 | dasd_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 Oberparleiter | 7039d3a | 2007-04-27 16:01:48 +0200 | [diff] [blame] | 126 | #define DASD_IPLDEV "ipldev" |
| 127 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | /* |
| 129 | * Read a device busid/devno from a string. |
| 130 | */ |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 131 | static int |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame^] | 132 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | dasd_busid(char **str, int *id0, int *id1, int *devno) |
| 134 | { |
| 135 | int val, old_style; |
Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame] | 136 | |
Peter Oberparleiter | 7039d3a | 2007-04-27 16:01:48 +0200 | [diff] [blame] | 137 | /* Interpret ipldev busid */ |
| 138 | if (strncmp(DASD_IPLDEV, *str, strlen(DASD_IPLDEV)) == 0) { |
| 139 | if (ipl_info.type != IPL_TYPE_CCW) { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame^] | 140 | pr_err("The IPL device is not a CCW device\n"); |
Peter Oberparleiter | 7039d3a | 2007-04-27 16:01:48 +0200 | [diff] [blame] | 141 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | /* 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 Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 191 | static int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | dasd_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 Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame] | 205 | for (len = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | 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 Hummel | 9575bf2 | 2006-12-08 15:54:15 +0100 | [diff] [blame] | 211 | else if (len == 6 && !strncmp(str, "erplog", 6)) |
| 212 | features |= DASD_FEATURE_ERPLOG; |
Holger Smolinski | 13de227 | 2009-01-09 12:14:51 +0100 | [diff] [blame] | 213 | else if (len == 8 && !strncmp(str, "failfast", 8)) |
| 214 | features |= DASD_FEATURE_FAILFAST; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | else { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame^] | 216 | pr_warning("%*s is not a supported device option\n", |
| 217 | len, str); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | rc = -EINVAL; |
| 219 | } |
| 220 | str += len; |
| 221 | if (*str != ':') |
| 222 | break; |
| 223 | str++; |
| 224 | } |
| 225 | if (*str != ')') { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame^] | 226 | pr_warning("A closing parenthesis ')' is missing in the " |
| 227 | "dasd= parameter\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | 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 | */ |
| 243 | static char * |
| 244 | dasd_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 Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 257 | if (strncmp("autodetect", parsestring, length) == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | dasd_autodetect = 1; |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame^] | 259 | pr_info("The autodetection mode has been activated\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | return residual_str; |
| 261 | } |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 262 | if (strncmp("probeonly", parsestring, length) == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | dasd_probeonly = 1; |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame^] | 264 | pr_info("The probeonly mode has been activated\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | return residual_str; |
| 266 | } |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 267 | if (strncmp("nopav", parsestring, length) == 0) { |
Peter Oberparleiter | dcd707b | 2006-09-20 15:59:52 +0200 | [diff] [blame] | 268 | if (MACHINE_IS_VM) |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame^] | 269 | pr_info("'nopav' is not supported on z/VM\n"); |
Peter Oberparleiter | dcd707b | 2006-09-20 15:59:52 +0200 | [diff] [blame] | 270 | else { |
| 271 | dasd_nopav = 1; |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame^] | 272 | pr_info("PAV support has be deactivated\n"); |
Peter Oberparleiter | dcd707b | 2006-09-20 15:59:52 +0200 | [diff] [blame] | 273 | } |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 274 | return residual_str; |
| 275 | } |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 276 | if (strncmp("nofcx", parsestring, length) == 0) { |
| 277 | dasd_nofcx = 1; |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame^] | 278 | pr_info("High Performance FICON support has been " |
| 279 | "deactivated\n"); |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 280 | return residual_str; |
| 281 | } |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 282 | if (strncmp("fixedbuffers", parsestring, length) == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | if (dasd_page_cache) |
| 284 | return residual_str; |
| 285 | dasd_page_cache = |
Heiko Carstens | 2f6c55f | 2006-08-16 13:49:27 +0200 | [diff] [blame] | 286 | kmem_cache_create("dasd_page_cache", PAGE_SIZE, |
| 287 | PAGE_SIZE, SLAB_CACHE_DMA, |
Paul Mundt | 20c2df8 | 2007-07-20 10:11:58 +0900 | [diff] [blame] | 288 | NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | if (!dasd_page_cache) |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame^] | 290 | DBF_EVENT(DBF_WARNING, "%s", "Failed to create slab, " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | "fixed buffer mode disabled."); |
| 292 | else |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame^] | 293 | DBF_EVENT(DBF_INFO, "%s", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | "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 | */ |
| 307 | static char * |
| 308 | dasd_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 Sievers | 98df67b | 2008-12-25 13:38:55 +0100 | [diff] [blame] | 314 | char bus_id[DASD_BUS_ID_SIZE+1], *str; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | |
| 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 Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame^] | 331 | pr_err("%s is not a valid device range\n", parsestring); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | return ERR_PTR(rc); |
| 333 | } |
| 334 | features = dasd_feature_list(str, &str); |
| 335 | if (features < 0) |
| 336 | return ERR_PTR(-EINVAL); |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 337 | /* each device in dasd= parameter should be set initially online */ |
| 338 | features |= DASD_FEATURE_INITIAL_ONLINE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | 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 Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame^] | 350 | pr_warning("The dasd= parameter value %s has an invalid ending\n", |
| 351 | str); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | return ERR_PTR(-EINVAL); |
| 353 | } |
| 354 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 355 | static char * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | dasd_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 | */ |
| 373 | int |
| 374 | dasd_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 Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame] | 404 | * devices. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | */ |
| 406 | static struct dasd_devmap * |
Cornelia Huck | 69f90f6 | 2008-05-15 16:52:34 +0200 | [diff] [blame] | 407 | dasd_add_busid(const char *bus_id, int features) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | { |
| 409 | struct dasd_devmap *devmap, *new, *tmp; |
| 410 | int hash; |
| 411 | |
| 412 | new = (struct dasd_devmap *) |
Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame] | 413 | kzalloc(sizeof(struct dasd_devmap), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | if (!new) |
| 415 | return ERR_PTR(-ENOMEM); |
| 416 | spin_lock(&dasd_devmap_lock); |
Heiko Carstens | d2c993d | 2006-07-12 16:41:55 +0200 | [diff] [blame] | 417 | devmap = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | hash = dasd_hash_busid(bus_id); |
| 419 | list_for_each_entry(tmp, &dasd_hashlists[hash], list) |
Kay Sievers | 98df67b | 2008-12-25 13:38:55 +0100 | [diff] [blame] | 420 | if (strncmp(tmp->bus_id, bus_id, DASD_BUS_ID_SIZE) == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | devmap = tmp; |
| 422 | break; |
| 423 | } |
| 424 | if (!devmap) { |
| 425 | /* This bus_id is new. */ |
| 426 | new->devindex = dasd_max_devindex++; |
Kay Sievers | 98df67b | 2008-12-25 13:38:55 +0100 | [diff] [blame] | 427 | strncpy(new->bus_id, bus_id, DASD_BUS_ID_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | new->features = features; |
Heiko Carstens | d2c993d | 2006-07-12 16:41:55 +0200 | [diff] [blame] | 429 | new->device = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | list_add(&new->list, &dasd_hashlists[hash]); |
| 431 | devmap = new; |
Heiko Carstens | d2c993d | 2006-07-12 16:41:55 +0200 | [diff] [blame] | 432 | new = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | } |
| 434 | spin_unlock(&dasd_devmap_lock); |
Jesper Juhl | 17fd682 | 2005-11-07 01:01:30 -0800 | [diff] [blame] | 435 | kfree(new); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | return devmap; |
| 437 | } |
| 438 | |
| 439 | /* |
| 440 | * Find devmap for device with given bus_id. |
| 441 | */ |
| 442 | static struct dasd_devmap * |
Cornelia Huck | 69f90f6 | 2008-05-15 16:52:34 +0200 | [diff] [blame] | 443 | dasd_find_busid(const char *bus_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | { |
| 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 Sievers | 98df67b | 2008-12-25 13:38:55 +0100 | [diff] [blame] | 452 | if (strncmp(tmp->bus_id, bus_id, DASD_BUS_ID_SIZE) == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | 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 | */ |
| 464 | int |
Cornelia Huck | 69f90f6 | 2008-05-15 16:52:34 +0200 | [diff] [blame] | 465 | dasd_busid_known(const char *bus_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | { |
| 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 | */ |
| 474 | static void |
| 475 | dasd_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 Sesterhenn | 606f442 | 2006-03-26 18:33:07 +0200 | [diff] [blame] | 483 | BUG_ON(devmap->device != NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | 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 | */ |
| 494 | struct dasd_device * |
| 495 | dasd_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 Carstens | d2c993d | 2006-07-12 16:41:55 +0200 | [diff] [blame] | 502 | devmap = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | 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 | */ |
| 523 | static struct dasd_devmap * |
| 524 | dasd_devmap_from_cdev(struct ccw_device *cdev) |
| 525 | { |
| 526 | struct dasd_devmap *devmap; |
| 527 | |
Kay Sievers | 2a0217d | 2008-10-10 21:33:09 +0200 | [diff] [blame] | 528 | devmap = dasd_find_busid(dev_name(&cdev->dev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | if (IS_ERR(devmap)) |
Kay Sievers | 2a0217d | 2008-10-10 21:33:09 +0200 | [diff] [blame] | 530 | devmap = dasd_add_busid(dev_name(&cdev->dev), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | DASD_FEATURE_DEFAULT); |
| 532 | return devmap; |
| 533 | } |
| 534 | |
| 535 | /* |
| 536 | * Create a dasd device structure for cdev. |
| 537 | */ |
| 538 | struct dasd_device * |
| 539 | dasd_create_device(struct ccw_device *cdev) |
| 540 | { |
| 541 | struct dasd_devmap *devmap; |
| 542 | struct dasd_device *device; |
Martin Schwidefsky | a00bfd7 | 2006-09-20 15:59:05 +0200 | [diff] [blame] | 543 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | int rc; |
| 545 | |
| 546 | devmap = dasd_devmap_from_cdev(cdev); |
| 547 | if (IS_ERR(devmap)) |
| 548 | return (void *) devmap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | |
| 550 | device = dasd_alloc_device(); |
| 551 | if (IS_ERR(device)) |
| 552 | return device; |
Martin Schwidefsky | a00bfd7 | 2006-09-20 15:59:05 +0200 | [diff] [blame] | 553 | atomic_set(&device->ref_count, 3); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | |
| 555 | spin_lock(&dasd_devmap_lock); |
| 556 | if (!devmap->device) { |
| 557 | devmap->device = device; |
| 558 | device->devindex = devmap->devindex; |
Horst Hummel | c6eb7b7 | 2005-09-03 15:57:58 -0700 | [diff] [blame] | 559 | device->features = devmap->features; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | 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 Schwidefsky | a00bfd7 | 2006-09-20 15:59:05 +0200 | [diff] [blame] | 572 | |
| 573 | spin_lock_irqsave(get_ccwdev_lock(cdev), flags); |
Cornelia Huck | faf16aa | 2008-12-25 13:38:52 +0100 | [diff] [blame] | 574 | dev_set_drvdata(&cdev->dev, device); |
Martin Schwidefsky | a00bfd7 | 2006-09-20 15:59:05 +0200 | [diff] [blame] | 575 | spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags); |
| 576 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | return device; |
| 578 | } |
| 579 | |
| 580 | /* |
| 581 | * Wait queue for dasd_delete_device waits. |
| 582 | */ |
| 583 | static DECLARE_WAIT_QUEUE_HEAD(dasd_delete_wq); |
| 584 | |
| 585 | /* |
| 586 | * Remove a dasd device structure. The passed referenced |
| 587 | * is destroyed. |
| 588 | */ |
| 589 | void |
| 590 | dasd_delete_device(struct dasd_device *device) |
| 591 | { |
| 592 | struct ccw_device *cdev; |
| 593 | struct dasd_devmap *devmap; |
Martin Schwidefsky | a00bfd7 | 2006-09-20 15:59:05 +0200 | [diff] [blame] | 594 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | |
| 596 | /* First remove device pointer from devmap. */ |
Kay Sievers | 2a0217d | 2008-10-10 21:33:09 +0200 | [diff] [blame] | 597 | devmap = dasd_find_busid(dev_name(&device->cdev->dev)); |
Eric Sesterhenn | 606f442 | 2006-03-26 18:33:07 +0200 | [diff] [blame] | 598 | BUG_ON(IS_ERR(devmap)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | 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 Schwidefsky | a00bfd7 | 2006-09-20 15:59:05 +0200 | [diff] [blame] | 608 | /* Disconnect dasd_device structure from ccw_device structure. */ |
| 609 | spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags); |
Cornelia Huck | faf16aa | 2008-12-25 13:38:52 +0100 | [diff] [blame] | 610 | dev_set_drvdata(&device->cdev->dev, NULL); |
Martin Schwidefsky | a00bfd7 | 2006-09-20 15:59:05 +0200 | [diff] [blame] | 611 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | /* 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 | */ |
| 637 | void |
| 638 | dasd_put_device_wake(struct dasd_device *device) |
| 639 | { |
| 640 | wake_up(&dasd_delete_wq); |
| 641 | } |
| 642 | |
| 643 | /* |
| 644 | * Return dasd_device structure associated with cdev. |
Martin Schwidefsky | a00bfd7 | 2006-09-20 15:59:05 +0200 | [diff] [blame] | 645 | * This function needs to be called with the ccw device |
| 646 | * lock held. It can be used from interrupt context. |
| 647 | */ |
| 648 | struct dasd_device * |
| 649 | dasd_device_from_cdev_locked(struct ccw_device *cdev) |
| 650 | { |
Cornelia Huck | faf16aa | 2008-12-25 13:38:52 +0100 | [diff] [blame] | 651 | struct dasd_device *device = dev_get_drvdata(&cdev->dev); |
Martin Schwidefsky | a00bfd7 | 2006-09-20 15:59:05 +0200 | [diff] [blame] | 652 | |
| 653 | if (!device) |
| 654 | return ERR_PTR(-ENODEV); |
| 655 | dasd_get_device(device); |
| 656 | return device; |
| 657 | } |
| 658 | |
| 659 | /* |
| 660 | * Return dasd_device structure associated with cdev. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | */ |
| 662 | struct dasd_device * |
| 663 | dasd_device_from_cdev(struct ccw_device *cdev) |
| 664 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 665 | struct dasd_device *device; |
Martin Schwidefsky | a00bfd7 | 2006-09-20 15:59:05 +0200 | [diff] [blame] | 666 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | |
Martin Schwidefsky | a00bfd7 | 2006-09-20 15:59:05 +0200 | [diff] [blame] | 668 | spin_lock_irqsave(get_ccwdev_lock(cdev), flags); |
| 669 | device = dasd_device_from_cdev_locked(cdev); |
| 670 | spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 671 | return device; |
| 672 | } |
| 673 | |
| 674 | /* |
| 675 | * SECTION: files in sysfs |
| 676 | */ |
| 677 | |
| 678 | /* |
Holger Smolinski | 13de227 | 2009-01-09 12:14:51 +0100 | [diff] [blame] | 679 | * failfast controls the behaviour, if no path is available |
| 680 | */ |
| 681 | static ssize_t dasd_ff_show(struct device *dev, struct device_attribute *attr, |
| 682 | char *buf) |
| 683 | { |
| 684 | struct dasd_devmap *devmap; |
| 685 | int ff_flag; |
| 686 | |
Cornelia Huck | ca0b4b7 | 2009-02-11 10:37:30 +0100 | [diff] [blame] | 687 | devmap = dasd_find_busid(dev_name(dev)); |
Holger Smolinski | 13de227 | 2009-01-09 12:14:51 +0100 | [diff] [blame] | 688 | if (!IS_ERR(devmap)) |
| 689 | ff_flag = (devmap->features & DASD_FEATURE_FAILFAST) != 0; |
| 690 | else |
| 691 | ff_flag = (DASD_FEATURE_DEFAULT & DASD_FEATURE_FAILFAST) != 0; |
| 692 | return snprintf(buf, PAGE_SIZE, ff_flag ? "1\n" : "0\n"); |
| 693 | } |
| 694 | |
| 695 | static ssize_t dasd_ff_store(struct device *dev, struct device_attribute *attr, |
| 696 | const char *buf, size_t count) |
| 697 | { |
| 698 | struct dasd_devmap *devmap; |
| 699 | int val; |
| 700 | char *endp; |
| 701 | |
| 702 | devmap = dasd_devmap_from_cdev(to_ccwdev(dev)); |
| 703 | if (IS_ERR(devmap)) |
| 704 | return PTR_ERR(devmap); |
| 705 | |
| 706 | val = simple_strtoul(buf, &endp, 0); |
| 707 | if (((endp + 1) < (buf + count)) || (val > 1)) |
| 708 | return -EINVAL; |
| 709 | |
| 710 | spin_lock(&dasd_devmap_lock); |
| 711 | if (val) |
| 712 | devmap->features |= DASD_FEATURE_FAILFAST; |
| 713 | else |
| 714 | devmap->features &= ~DASD_FEATURE_FAILFAST; |
| 715 | if (devmap->device) |
| 716 | devmap->device->features = devmap->features; |
| 717 | spin_unlock(&dasd_devmap_lock); |
| 718 | return count; |
| 719 | } |
| 720 | |
| 721 | static DEVICE_ATTR(failfast, 0644, dasd_ff_show, dasd_ff_store); |
| 722 | |
| 723 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 724 | * readonly controls the readonly status of a dasd |
| 725 | */ |
| 726 | static ssize_t |
Yani Ioannou | e404e27 | 2005-05-17 06:42:58 -0400 | [diff] [blame] | 727 | dasd_ro_show(struct device *dev, struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 728 | { |
| 729 | struct dasd_devmap *devmap; |
| 730 | int ro_flag; |
| 731 | |
Kay Sievers | 2a0217d | 2008-10-10 21:33:09 +0200 | [diff] [blame] | 732 | devmap = dasd_find_busid(dev_name(dev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | if (!IS_ERR(devmap)) |
| 734 | ro_flag = (devmap->features & DASD_FEATURE_READONLY) != 0; |
| 735 | else |
| 736 | ro_flag = (DASD_FEATURE_DEFAULT & DASD_FEATURE_READONLY) != 0; |
| 737 | return snprintf(buf, PAGE_SIZE, ro_flag ? "1\n" : "0\n"); |
| 738 | } |
| 739 | |
| 740 | static ssize_t |
Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame] | 741 | dasd_ro_store(struct device *dev, struct device_attribute *attr, |
| 742 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 743 | { |
| 744 | struct dasd_devmap *devmap; |
Horst Hummel | 01376f4 | 2006-12-04 15:39:50 +0100 | [diff] [blame] | 745 | int val; |
| 746 | char *endp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 | |
| 748 | devmap = dasd_devmap_from_cdev(to_ccwdev(dev)); |
| 749 | if (IS_ERR(devmap)) |
| 750 | return PTR_ERR(devmap); |
Horst Hummel | 01376f4 | 2006-12-04 15:39:50 +0100 | [diff] [blame] | 751 | |
| 752 | val = simple_strtoul(buf, &endp, 0); |
| 753 | if (((endp + 1) < (buf + count)) || (val > 1)) |
| 754 | return -EINVAL; |
| 755 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | spin_lock(&dasd_devmap_lock); |
Horst Hummel | 01376f4 | 2006-12-04 15:39:50 +0100 | [diff] [blame] | 757 | if (val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 758 | devmap->features |= DASD_FEATURE_READONLY; |
| 759 | else |
| 760 | devmap->features &= ~DASD_FEATURE_READONLY; |
Horst Hummel | c6eb7b7 | 2005-09-03 15:57:58 -0700 | [diff] [blame] | 761 | if (devmap->device) |
| 762 | devmap->device->features = devmap->features; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 763 | if (devmap->device && devmap->device->block |
| 764 | && devmap->device->block->gdp) |
| 765 | set_disk_ro(devmap->device->block->gdp, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 | spin_unlock(&dasd_devmap_lock); |
| 767 | return count; |
| 768 | } |
| 769 | |
| 770 | static DEVICE_ATTR(readonly, 0644, dasd_ro_show, dasd_ro_store); |
Horst Hummel | 9575bf2 | 2006-12-08 15:54:15 +0100 | [diff] [blame] | 771 | /* |
| 772 | * erplog controls the logging of ERP related data |
| 773 | * (e.g. failing channel programs). |
| 774 | */ |
| 775 | static ssize_t |
| 776 | dasd_erplog_show(struct device *dev, struct device_attribute *attr, char *buf) |
| 777 | { |
| 778 | struct dasd_devmap *devmap; |
| 779 | int erplog; |
| 780 | |
Kay Sievers | 2a0217d | 2008-10-10 21:33:09 +0200 | [diff] [blame] | 781 | devmap = dasd_find_busid(dev_name(dev)); |
Horst Hummel | 9575bf2 | 2006-12-08 15:54:15 +0100 | [diff] [blame] | 782 | if (!IS_ERR(devmap)) |
| 783 | erplog = (devmap->features & DASD_FEATURE_ERPLOG) != 0; |
| 784 | else |
| 785 | erplog = (DASD_FEATURE_DEFAULT & DASD_FEATURE_ERPLOG) != 0; |
| 786 | return snprintf(buf, PAGE_SIZE, erplog ? "1\n" : "0\n"); |
| 787 | } |
| 788 | |
| 789 | static ssize_t |
| 790 | dasd_erplog_store(struct device *dev, struct device_attribute *attr, |
| 791 | const char *buf, size_t count) |
| 792 | { |
| 793 | struct dasd_devmap *devmap; |
| 794 | int val; |
| 795 | char *endp; |
| 796 | |
| 797 | devmap = dasd_devmap_from_cdev(to_ccwdev(dev)); |
| 798 | if (IS_ERR(devmap)) |
| 799 | return PTR_ERR(devmap); |
| 800 | |
| 801 | val = simple_strtoul(buf, &endp, 0); |
| 802 | if (((endp + 1) < (buf + count)) || (val > 1)) |
| 803 | return -EINVAL; |
| 804 | |
| 805 | spin_lock(&dasd_devmap_lock); |
| 806 | if (val) |
| 807 | devmap->features |= DASD_FEATURE_ERPLOG; |
| 808 | else |
| 809 | devmap->features &= ~DASD_FEATURE_ERPLOG; |
| 810 | if (devmap->device) |
| 811 | devmap->device->features = devmap->features; |
| 812 | spin_unlock(&dasd_devmap_lock); |
| 813 | return count; |
| 814 | } |
| 815 | |
| 816 | static DEVICE_ATTR(erplog, 0644, dasd_erplog_show, dasd_erplog_store); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 | |
| 818 | /* |
| 819 | * use_diag controls whether the driver should use diag rather than ssch |
| 820 | * to talk to the device |
| 821 | */ |
Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame] | 822 | static ssize_t |
Yani Ioannou | e404e27 | 2005-05-17 06:42:58 -0400 | [diff] [blame] | 823 | dasd_use_diag_show(struct device *dev, struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 824 | { |
| 825 | struct dasd_devmap *devmap; |
| 826 | int use_diag; |
| 827 | |
Kay Sievers | 2a0217d | 2008-10-10 21:33:09 +0200 | [diff] [blame] | 828 | devmap = dasd_find_busid(dev_name(dev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 829 | if (!IS_ERR(devmap)) |
| 830 | use_diag = (devmap->features & DASD_FEATURE_USEDIAG) != 0; |
| 831 | else |
| 832 | use_diag = (DASD_FEATURE_DEFAULT & DASD_FEATURE_USEDIAG) != 0; |
| 833 | return sprintf(buf, use_diag ? "1\n" : "0\n"); |
| 834 | } |
| 835 | |
| 836 | static ssize_t |
Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame] | 837 | dasd_use_diag_store(struct device *dev, struct device_attribute *attr, |
| 838 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 839 | { |
| 840 | struct dasd_devmap *devmap; |
| 841 | ssize_t rc; |
Horst Hummel | 01376f4 | 2006-12-04 15:39:50 +0100 | [diff] [blame] | 842 | int val; |
| 843 | char *endp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 844 | |
| 845 | devmap = dasd_devmap_from_cdev(to_ccwdev(dev)); |
| 846 | if (IS_ERR(devmap)) |
| 847 | return PTR_ERR(devmap); |
Horst Hummel | 01376f4 | 2006-12-04 15:39:50 +0100 | [diff] [blame] | 848 | |
| 849 | val = simple_strtoul(buf, &endp, 0); |
| 850 | if (((endp + 1) < (buf + count)) || (val > 1)) |
| 851 | return -EINVAL; |
| 852 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 853 | spin_lock(&dasd_devmap_lock); |
| 854 | /* Changing diag discipline flag is only allowed in offline state. */ |
| 855 | rc = count; |
| 856 | if (!devmap->device) { |
Horst Hummel | 01376f4 | 2006-12-04 15:39:50 +0100 | [diff] [blame] | 857 | if (val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 858 | devmap->features |= DASD_FEATURE_USEDIAG; |
| 859 | else |
| 860 | devmap->features &= ~DASD_FEATURE_USEDIAG; |
| 861 | } else |
| 862 | rc = -EPERM; |
| 863 | spin_unlock(&dasd_devmap_lock); |
| 864 | return rc; |
| 865 | } |
| 866 | |
Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame] | 867 | static DEVICE_ATTR(use_diag, 0644, dasd_use_diag_show, dasd_use_diag_store); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 868 | |
| 869 | static ssize_t |
Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame] | 870 | dasd_discipline_show(struct device *dev, struct device_attribute *attr, |
| 871 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 872 | { |
Martin Schwidefsky | a00bfd7 | 2006-09-20 15:59:05 +0200 | [diff] [blame] | 873 | struct dasd_device *device; |
| 874 | ssize_t len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 875 | |
Martin Schwidefsky | a00bfd7 | 2006-09-20 15:59:05 +0200 | [diff] [blame] | 876 | device = dasd_device_from_cdev(to_ccwdev(dev)); |
| 877 | if (!IS_ERR(device) && device->discipline) { |
| 878 | len = snprintf(buf, PAGE_SIZE, "%s\n", |
| 879 | device->discipline->name); |
| 880 | dasd_put_device(device); |
| 881 | } else |
| 882 | len = snprintf(buf, PAGE_SIZE, "none\n"); |
| 883 | return len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 884 | } |
| 885 | |
| 886 | static DEVICE_ATTR(discipline, 0444, dasd_discipline_show, NULL); |
| 887 | |
Horst Hummel | 3d05259 | 2006-04-27 18:40:28 -0700 | [diff] [blame] | 888 | static ssize_t |
Horst Hummel | 4dfd5c4 | 2007-04-27 16:01:47 +0200 | [diff] [blame] | 889 | dasd_device_status_show(struct device *dev, struct device_attribute *attr, |
| 890 | char *buf) |
| 891 | { |
| 892 | struct dasd_device *device; |
| 893 | ssize_t len; |
| 894 | |
| 895 | device = dasd_device_from_cdev(to_ccwdev(dev)); |
| 896 | if (!IS_ERR(device)) { |
| 897 | switch (device->state) { |
| 898 | case DASD_STATE_NEW: |
| 899 | len = snprintf(buf, PAGE_SIZE, "new\n"); |
| 900 | break; |
| 901 | case DASD_STATE_KNOWN: |
| 902 | len = snprintf(buf, PAGE_SIZE, "detected\n"); |
| 903 | break; |
| 904 | case DASD_STATE_BASIC: |
| 905 | len = snprintf(buf, PAGE_SIZE, "basic\n"); |
| 906 | break; |
| 907 | case DASD_STATE_UNFMT: |
| 908 | len = snprintf(buf, PAGE_SIZE, "unformatted\n"); |
| 909 | break; |
| 910 | case DASD_STATE_READY: |
| 911 | len = snprintf(buf, PAGE_SIZE, "ready\n"); |
| 912 | break; |
| 913 | case DASD_STATE_ONLINE: |
| 914 | len = snprintf(buf, PAGE_SIZE, "online\n"); |
| 915 | break; |
| 916 | default: |
| 917 | len = snprintf(buf, PAGE_SIZE, "no stat\n"); |
| 918 | break; |
| 919 | } |
| 920 | dasd_put_device(device); |
| 921 | } else |
| 922 | len = snprintf(buf, PAGE_SIZE, "unknown\n"); |
| 923 | return len; |
| 924 | } |
| 925 | |
| 926 | static DEVICE_ATTR(status, 0444, dasd_device_status_show, NULL); |
| 927 | |
| 928 | static ssize_t |
Horst Hummel | 3d05259 | 2006-04-27 18:40:28 -0700 | [diff] [blame] | 929 | dasd_alias_show(struct device *dev, struct device_attribute *attr, char *buf) |
| 930 | { |
| 931 | struct dasd_devmap *devmap; |
| 932 | int alias; |
| 933 | |
Kay Sievers | 2a0217d | 2008-10-10 21:33:09 +0200 | [diff] [blame] | 934 | devmap = dasd_find_busid(dev_name(dev)); |
Horst Hummel | 3d05259 | 2006-04-27 18:40:28 -0700 | [diff] [blame] | 935 | spin_lock(&dasd_devmap_lock); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 936 | if (IS_ERR(devmap) || strlen(devmap->uid.vendor) == 0) { |
| 937 | spin_unlock(&dasd_devmap_lock); |
| 938 | return sprintf(buf, "0\n"); |
| 939 | } |
| 940 | if (devmap->uid.type == UA_BASE_PAV_ALIAS || |
| 941 | devmap->uid.type == UA_HYPER_PAV_ALIAS) |
| 942 | alias = 1; |
Horst Hummel | 3d05259 | 2006-04-27 18:40:28 -0700 | [diff] [blame] | 943 | else |
| 944 | alias = 0; |
| 945 | spin_unlock(&dasd_devmap_lock); |
Horst Hummel | 3d05259 | 2006-04-27 18:40:28 -0700 | [diff] [blame] | 946 | return sprintf(buf, alias ? "1\n" : "0\n"); |
| 947 | } |
| 948 | |
| 949 | static DEVICE_ATTR(alias, 0444, dasd_alias_show, NULL); |
| 950 | |
| 951 | static ssize_t |
| 952 | dasd_vendor_show(struct device *dev, struct device_attribute *attr, char *buf) |
| 953 | { |
| 954 | struct dasd_devmap *devmap; |
| 955 | char *vendor; |
| 956 | |
Kay Sievers | 2a0217d | 2008-10-10 21:33:09 +0200 | [diff] [blame] | 957 | devmap = dasd_find_busid(dev_name(dev)); |
Horst Hummel | 3d05259 | 2006-04-27 18:40:28 -0700 | [diff] [blame] | 958 | spin_lock(&dasd_devmap_lock); |
| 959 | if (!IS_ERR(devmap) && strlen(devmap->uid.vendor) > 0) |
| 960 | vendor = devmap->uid.vendor; |
| 961 | else |
| 962 | vendor = ""; |
| 963 | spin_unlock(&dasd_devmap_lock); |
| 964 | |
| 965 | return snprintf(buf, PAGE_SIZE, "%s\n", vendor); |
| 966 | } |
| 967 | |
| 968 | static DEVICE_ATTR(vendor, 0444, dasd_vendor_show, NULL); |
| 969 | |
| 970 | #define UID_STRLEN ( /* vendor */ 3 + 1 + /* serial */ 14 + 1 +\ |
Stefan Weinhuber | 4abb08c | 2008-08-01 16:39:09 +0200 | [diff] [blame] | 971 | /* SSID */ 4 + 1 + /* unit addr */ 2 + 1 +\ |
| 972 | /* vduit */ 32 + 1) |
Horst Hummel | 3d05259 | 2006-04-27 18:40:28 -0700 | [diff] [blame] | 973 | |
| 974 | static ssize_t |
| 975 | dasd_uid_show(struct device *dev, struct device_attribute *attr, char *buf) |
| 976 | { |
| 977 | struct dasd_devmap *devmap; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 978 | char uid_string[UID_STRLEN]; |
| 979 | char ua_string[3]; |
| 980 | struct dasd_uid *uid; |
Horst Hummel | 3d05259 | 2006-04-27 18:40:28 -0700 | [diff] [blame] | 981 | |
Kay Sievers | 2a0217d | 2008-10-10 21:33:09 +0200 | [diff] [blame] | 982 | devmap = dasd_find_busid(dev_name(dev)); |
Horst Hummel | 3d05259 | 2006-04-27 18:40:28 -0700 | [diff] [blame] | 983 | spin_lock(&dasd_devmap_lock); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 984 | if (IS_ERR(devmap) || strlen(devmap->uid.vendor) == 0) { |
| 985 | spin_unlock(&dasd_devmap_lock); |
| 986 | return sprintf(buf, "\n"); |
| 987 | } |
| 988 | uid = &devmap->uid; |
| 989 | switch (uid->type) { |
| 990 | case UA_BASE_DEVICE: |
| 991 | sprintf(ua_string, "%02x", uid->real_unit_addr); |
| 992 | break; |
| 993 | case UA_BASE_PAV_ALIAS: |
| 994 | sprintf(ua_string, "%02x", uid->base_unit_addr); |
| 995 | break; |
| 996 | case UA_HYPER_PAV_ALIAS: |
| 997 | sprintf(ua_string, "xx"); |
| 998 | break; |
| 999 | default: |
| 1000 | /* should not happen, treat like base device */ |
| 1001 | sprintf(ua_string, "%02x", uid->real_unit_addr); |
| 1002 | break; |
| 1003 | } |
Stefan Weinhuber | 4abb08c | 2008-08-01 16:39:09 +0200 | [diff] [blame] | 1004 | if (strlen(uid->vduit) > 0) |
| 1005 | snprintf(uid_string, sizeof(uid_string), |
| 1006 | "%s.%s.%04x.%s.%s", |
| 1007 | uid->vendor, uid->serial, |
| 1008 | uid->ssid, ua_string, |
| 1009 | uid->vduit); |
| 1010 | else |
| 1011 | snprintf(uid_string, sizeof(uid_string), |
| 1012 | "%s.%s.%04x.%s", |
| 1013 | uid->vendor, uid->serial, |
| 1014 | uid->ssid, ua_string); |
Horst Hummel | 3d05259 | 2006-04-27 18:40:28 -0700 | [diff] [blame] | 1015 | spin_unlock(&dasd_devmap_lock); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1016 | return snprintf(buf, PAGE_SIZE, "%s\n", uid_string); |
Horst Hummel | 3d05259 | 2006-04-27 18:40:28 -0700 | [diff] [blame] | 1017 | } |
| 1018 | |
| 1019 | static DEVICE_ATTR(uid, 0444, dasd_uid_show, NULL); |
| 1020 | |
Stefan Weinhuber | 20c6446 | 2006-03-24 03:15:25 -0800 | [diff] [blame] | 1021 | /* |
| 1022 | * extended error-reporting |
| 1023 | */ |
| 1024 | static ssize_t |
| 1025 | dasd_eer_show(struct device *dev, struct device_attribute *attr, char *buf) |
| 1026 | { |
| 1027 | struct dasd_devmap *devmap; |
| 1028 | int eer_flag; |
| 1029 | |
Kay Sievers | 2a0217d | 2008-10-10 21:33:09 +0200 | [diff] [blame] | 1030 | devmap = dasd_find_busid(dev_name(dev)); |
Stefan Weinhuber | 20c6446 | 2006-03-24 03:15:25 -0800 | [diff] [blame] | 1031 | if (!IS_ERR(devmap) && devmap->device) |
| 1032 | eer_flag = dasd_eer_enabled(devmap->device); |
| 1033 | else |
| 1034 | eer_flag = 0; |
| 1035 | return snprintf(buf, PAGE_SIZE, eer_flag ? "1\n" : "0\n"); |
| 1036 | } |
| 1037 | |
| 1038 | static ssize_t |
| 1039 | dasd_eer_store(struct device *dev, struct device_attribute *attr, |
| 1040 | const char *buf, size_t count) |
| 1041 | { |
| 1042 | struct dasd_devmap *devmap; |
Horst Hummel | 01376f4 | 2006-12-04 15:39:50 +0100 | [diff] [blame] | 1043 | int val, rc; |
| 1044 | char *endp; |
Stefan Weinhuber | 20c6446 | 2006-03-24 03:15:25 -0800 | [diff] [blame] | 1045 | |
| 1046 | devmap = dasd_devmap_from_cdev(to_ccwdev(dev)); |
| 1047 | if (IS_ERR(devmap)) |
| 1048 | return PTR_ERR(devmap); |
| 1049 | if (!devmap->device) |
Horst Hummel | 01376f4 | 2006-12-04 15:39:50 +0100 | [diff] [blame] | 1050 | return -ENODEV; |
| 1051 | |
| 1052 | val = simple_strtoul(buf, &endp, 0); |
| 1053 | if (((endp + 1) < (buf + count)) || (val > 1)) |
| 1054 | return -EINVAL; |
| 1055 | |
Horst Hummel | 645c98c | 2006-12-04 15:40:18 +0100 | [diff] [blame] | 1056 | if (val) { |
Stefan Weinhuber | 20c6446 | 2006-03-24 03:15:25 -0800 | [diff] [blame] | 1057 | rc = dasd_eer_enable(devmap->device); |
Horst Hummel | 645c98c | 2006-12-04 15:40:18 +0100 | [diff] [blame] | 1058 | if (rc) |
| 1059 | return rc; |
| 1060 | } else |
Stefan Weinhuber | 20c6446 | 2006-03-24 03:15:25 -0800 | [diff] [blame] | 1061 | dasd_eer_disable(devmap->device); |
Horst Hummel | 645c98c | 2006-12-04 15:40:18 +0100 | [diff] [blame] | 1062 | return count; |
Stefan Weinhuber | 20c6446 | 2006-03-24 03:15:25 -0800 | [diff] [blame] | 1063 | } |
| 1064 | |
| 1065 | static DEVICE_ATTR(eer_enabled, 0644, dasd_eer_show, dasd_eer_store); |
| 1066 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1067 | static struct attribute * dasd_attrs[] = { |
| 1068 | &dev_attr_readonly.attr, |
| 1069 | &dev_attr_discipline.attr, |
Horst Hummel | 4dfd5c4 | 2007-04-27 16:01:47 +0200 | [diff] [blame] | 1070 | &dev_attr_status.attr, |
Horst Hummel | 3d05259 | 2006-04-27 18:40:28 -0700 | [diff] [blame] | 1071 | &dev_attr_alias.attr, |
| 1072 | &dev_attr_vendor.attr, |
| 1073 | &dev_attr_uid.attr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1074 | &dev_attr_use_diag.attr, |
Stefan Weinhuber | 20c6446 | 2006-03-24 03:15:25 -0800 | [diff] [blame] | 1075 | &dev_attr_eer_enabled.attr, |
Horst Hummel | 9575bf2 | 2006-12-08 15:54:15 +0100 | [diff] [blame] | 1076 | &dev_attr_erplog.attr, |
Holger Smolinski | 13de227 | 2009-01-09 12:14:51 +0100 | [diff] [blame] | 1077 | &dev_attr_failfast.attr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1078 | NULL, |
| 1079 | }; |
| 1080 | |
| 1081 | static struct attribute_group dasd_attr_group = { |
| 1082 | .attrs = dasd_attrs, |
| 1083 | }; |
| 1084 | |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 1085 | /* |
Horst Hummel | 3d05259 | 2006-04-27 18:40:28 -0700 | [diff] [blame] | 1086 | * Return copy of the device unique identifier. |
| 1087 | */ |
| 1088 | int |
| 1089 | dasd_get_uid(struct ccw_device *cdev, struct dasd_uid *uid) |
| 1090 | { |
| 1091 | struct dasd_devmap *devmap; |
| 1092 | |
Kay Sievers | 2a0217d | 2008-10-10 21:33:09 +0200 | [diff] [blame] | 1093 | devmap = dasd_find_busid(dev_name(&cdev->dev)); |
Horst Hummel | 3d05259 | 2006-04-27 18:40:28 -0700 | [diff] [blame] | 1094 | if (IS_ERR(devmap)) |
| 1095 | return PTR_ERR(devmap); |
| 1096 | spin_lock(&dasd_devmap_lock); |
| 1097 | *uid = devmap->uid; |
| 1098 | spin_unlock(&dasd_devmap_lock); |
| 1099 | return 0; |
| 1100 | } |
| 1101 | |
| 1102 | /* |
| 1103 | * Register the given device unique identifier into devmap struct. |
Peter Oberparleiter | b18a60e | 2006-08-16 13:49:33 +0200 | [diff] [blame] | 1104 | * In addition check if the related storage server subsystem ID is already |
| 1105 | * contained in the dasd_server_ssid_list. If subsystem ID is not contained, |
| 1106 | * create new entry. |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 1107 | * Return 0 if server was already in serverlist, |
| 1108 | * 1 if the server was added successful |
| 1109 | * <0 in case of error. |
Horst Hummel | 3d05259 | 2006-04-27 18:40:28 -0700 | [diff] [blame] | 1110 | */ |
| 1111 | int |
| 1112 | dasd_set_uid(struct ccw_device *cdev, struct dasd_uid *uid) |
| 1113 | { |
| 1114 | struct dasd_devmap *devmap; |
| 1115 | |
Kay Sievers | 2a0217d | 2008-10-10 21:33:09 +0200 | [diff] [blame] | 1116 | devmap = dasd_find_busid(dev_name(&cdev->dev)); |
Horst Hummel | 3d05259 | 2006-04-27 18:40:28 -0700 | [diff] [blame] | 1117 | if (IS_ERR(devmap)) |
| 1118 | return PTR_ERR(devmap); |
Horst Hummel | d0710c7 | 2006-08-10 15:45:16 +0200 | [diff] [blame] | 1119 | |
Horst Hummel | 3d05259 | 2006-04-27 18:40:28 -0700 | [diff] [blame] | 1120 | spin_lock(&dasd_devmap_lock); |
| 1121 | devmap->uid = *uid; |
| 1122 | spin_unlock(&dasd_devmap_lock); |
Horst Hummel | d0710c7 | 2006-08-10 15:45:16 +0200 | [diff] [blame] | 1123 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1124 | return 0; |
Horst Hummel | 3d05259 | 2006-04-27 18:40:28 -0700 | [diff] [blame] | 1125 | } |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 1126 | EXPORT_SYMBOL_GPL(dasd_set_uid); |
Horst Hummel | 3d05259 | 2006-04-27 18:40:28 -0700 | [diff] [blame] | 1127 | |
Horst Hummel | f24acd4 | 2005-05-01 08:58:59 -0700 | [diff] [blame] | 1128 | /* |
| 1129 | * Return value of the specified feature. |
| 1130 | */ |
| 1131 | int |
| 1132 | dasd_get_feature(struct ccw_device *cdev, int feature) |
| 1133 | { |
| 1134 | struct dasd_devmap *devmap; |
| 1135 | |
Kay Sievers | 2a0217d | 2008-10-10 21:33:09 +0200 | [diff] [blame] | 1136 | devmap = dasd_find_busid(dev_name(&cdev->dev)); |
Horst Hummel | f24acd4 | 2005-05-01 08:58:59 -0700 | [diff] [blame] | 1137 | if (IS_ERR(devmap)) |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 1138 | return PTR_ERR(devmap); |
Horst Hummel | f24acd4 | 2005-05-01 08:58:59 -0700 | [diff] [blame] | 1139 | |
| 1140 | return ((devmap->features & feature) != 0); |
| 1141 | } |
| 1142 | |
| 1143 | /* |
| 1144 | * Set / reset given feature. |
| 1145 | * Flag indicates wether to set (!=0) or the reset (=0) the feature. |
| 1146 | */ |
| 1147 | int |
| 1148 | dasd_set_feature(struct ccw_device *cdev, int feature, int flag) |
| 1149 | { |
| 1150 | struct dasd_devmap *devmap; |
| 1151 | |
Kay Sievers | 2a0217d | 2008-10-10 21:33:09 +0200 | [diff] [blame] | 1152 | devmap = dasd_find_busid(dev_name(&cdev->dev)); |
Horst Hummel | f24acd4 | 2005-05-01 08:58:59 -0700 | [diff] [blame] | 1153 | if (IS_ERR(devmap)) |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 1154 | return PTR_ERR(devmap); |
Horst Hummel | f24acd4 | 2005-05-01 08:58:59 -0700 | [diff] [blame] | 1155 | |
| 1156 | spin_lock(&dasd_devmap_lock); |
| 1157 | if (flag) |
| 1158 | devmap->features |= feature; |
| 1159 | else |
| 1160 | devmap->features &= ~feature; |
Horst Hummel | c6eb7b7 | 2005-09-03 15:57:58 -0700 | [diff] [blame] | 1161 | if (devmap->device) |
| 1162 | devmap->device->features = devmap->features; |
Horst Hummel | f24acd4 | 2005-05-01 08:58:59 -0700 | [diff] [blame] | 1163 | spin_unlock(&dasd_devmap_lock); |
| 1164 | return 0; |
| 1165 | } |
| 1166 | |
| 1167 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1168 | int |
| 1169 | dasd_add_sysfs_files(struct ccw_device *cdev) |
| 1170 | { |
| 1171 | return sysfs_create_group(&cdev->dev.kobj, &dasd_attr_group); |
| 1172 | } |
| 1173 | |
| 1174 | void |
| 1175 | dasd_remove_sysfs_files(struct ccw_device *cdev) |
| 1176 | { |
| 1177 | sysfs_remove_group(&cdev->dev.kobj, &dasd_attr_group); |
| 1178 | } |
| 1179 | |
| 1180 | |
| 1181 | int |
| 1182 | dasd_devmap_init(void) |
| 1183 | { |
| 1184 | int i; |
| 1185 | |
| 1186 | /* Initialize devmap structures. */ |
| 1187 | dasd_max_devindex = 0; |
| 1188 | for (i = 0; i < 256; i++) |
| 1189 | INIT_LIST_HEAD(&dasd_hashlists[i]); |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 1190 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1191 | } |
| 1192 | |
| 1193 | void |
| 1194 | dasd_devmap_exit(void) |
| 1195 | { |
| 1196 | dasd_forget_ranges(); |
| 1197 | } |