Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * Author(s)......: Holger Smolinski <Holger.Smolinski@de.ibm.com> |
| 3 | * Horst Hummel <Horst.Hummel@de.ibm.com> |
| 4 | * Carsten Otte <Cotte@de.ibm.com> |
| 5 | * Martin Schwidefsky <schwidefsky@de.ibm.com> |
| 6 | * Bugreports.to..: <Linux390@de.ibm.com> |
Heiko Carstens | a53c8fa | 2012-07-20 11:15:04 +0200 | [diff] [blame] | 7 | * Copyright IBM Corp. 1999,2001 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | * |
| 9 | * Device mapping and dasd= parameter parsing functions. All devmap |
| 10 | * functions may not be called from interrupt context. In particular |
| 11 | * dasd_get_device is a no-no from interrupt context. |
| 12 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | */ |
| 14 | |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 15 | #define KMSG_COMPONENT "dasd" |
| 16 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <linux/ctype.h> |
| 18 | #include <linux/init.h> |
Rusty Russell | 8d3b33f | 2006-03-25 03:07:05 -0800 | [diff] [blame] | 19 | #include <linux/module.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 20 | #include <linux/slab.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; |
| 51 | }; |
| 52 | |
| 53 | /* |
| 54 | * Parameter parsing functions for dasd= parameter. The syntax is: |
| 55 | * <devno> : (0x)?[0-9a-fA-F]+ |
| 56 | * <busid> : [0-0a-f]\.[0-9a-f]\.(0x)?[0-9a-fA-F]+ |
| 57 | * <feature> : ro |
| 58 | * <feature_list> : \(<feature>(:<feature>)*\) |
| 59 | * <devno-range> : <devno>(-<devno>)?<feature_list>? |
| 60 | * <busid-range> : <busid>(-<busid>)?<feature_list>? |
| 61 | * <devices> : <devno-range>|<busid-range> |
| 62 | * <dasd_module> : dasd_diag_mod|dasd_eckd_mod|dasd_fba_mod |
| 63 | * |
| 64 | * <dasd> : autodetect|probeonly|<devices>(,<devices>)* |
| 65 | */ |
| 66 | |
| 67 | int dasd_probeonly = 0; /* is true, when probeonly mode is active */ |
| 68 | int dasd_autodetect = 0; /* is true, when autodetection is active */ |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 69 | int dasd_nopav = 0; /* is true, when PAV is disabled */ |
| 70 | EXPORT_SYMBOL_GPL(dasd_nopav); |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 71 | int dasd_nofcx; /* disable High Performance Ficon */ |
| 72 | EXPORT_SYMBOL_GPL(dasd_nofcx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | |
| 74 | /* |
| 75 | * char *dasd[] is intended to hold the ranges supplied by the dasd= statement |
| 76 | * it is named 'dasd' to directly be filled by insmod with the comma separated |
| 77 | * strings when running as a module. |
| 78 | */ |
| 79 | static char *dasd[256]; |
Rusty Russell | 8d3b33f | 2006-03-25 03:07:05 -0800 | [diff] [blame] | 80 | module_param_array(dasd, charp, NULL, 0); |
| 81 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | /* |
Horst Hummel | d0710c7 | 2006-08-10 15:45:16 +0200 | [diff] [blame] | 83 | * Single spinlock to protect devmap and servermap structures and lists. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | */ |
| 85 | static DEFINE_SPINLOCK(dasd_devmap_lock); |
| 86 | |
| 87 | /* |
| 88 | * Hash lists for devmap structures. |
| 89 | */ |
| 90 | static struct list_head dasd_hashlists[256]; |
| 91 | int dasd_max_devindex; |
| 92 | |
Cornelia Huck | 69f90f6 | 2008-05-15 16:52:34 +0200 | [diff] [blame] | 93 | static struct dasd_devmap *dasd_add_busid(const char *, int); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | |
| 95 | static inline int |
Cornelia Huck | 69f90f6 | 2008-05-15 16:52:34 +0200 | [diff] [blame] | 96 | dasd_hash_busid(const char *bus_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | { |
| 98 | int hash, i; |
| 99 | |
| 100 | hash = 0; |
Kay Sievers | 98df67b | 2008-12-25 13:38:55 +0100 | [diff] [blame] | 101 | 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] | 102 | hash += *bus_id; |
| 103 | return hash & 0xff; |
| 104 | } |
| 105 | |
| 106 | #ifndef MODULE |
| 107 | /* |
| 108 | * The parameter parsing functions for builtin-drivers are called |
| 109 | * before kmalloc works. Store the pointers to the parameters strings |
| 110 | * into dasd[] for later processing. |
| 111 | */ |
| 112 | static int __init |
| 113 | dasd_call_setup(char *str) |
| 114 | { |
| 115 | static int count = 0; |
| 116 | |
| 117 | if (count < 256) |
| 118 | dasd[count++] = str; |
| 119 | return 1; |
| 120 | } |
| 121 | |
| 122 | __setup ("dasd=", dasd_call_setup); |
| 123 | #endif /* #ifndef MODULE */ |
| 124 | |
Peter Oberparleiter | 7039d3a | 2007-04-27 16:01:48 +0200 | [diff] [blame] | 125 | #define DASD_IPLDEV "ipldev" |
| 126 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | /* |
| 128 | * Read a device busid/devno from a string. |
| 129 | */ |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 130 | static int |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 131 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | dasd_busid(char **str, int *id0, int *id1, int *devno) |
| 133 | { |
| 134 | int val, old_style; |
Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame] | 135 | |
Peter Oberparleiter | 7039d3a | 2007-04-27 16:01:48 +0200 | [diff] [blame] | 136 | /* Interpret ipldev busid */ |
| 137 | if (strncmp(DASD_IPLDEV, *str, strlen(DASD_IPLDEV)) == 0) { |
| 138 | if (ipl_info.type != IPL_TYPE_CCW) { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 139 | pr_err("The IPL device is not a CCW device\n"); |
Peter Oberparleiter | 7039d3a | 2007-04-27 16:01:48 +0200 | [diff] [blame] | 140 | return -EINVAL; |
| 141 | } |
| 142 | *id0 = 0; |
| 143 | *id1 = ipl_info.data.ccw.dev_id.ssid; |
| 144 | *devno = ipl_info.data.ccw.dev_id.devno; |
| 145 | *str += strlen(DASD_IPLDEV); |
| 146 | |
| 147 | return 0; |
| 148 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | /* check for leading '0x' */ |
| 150 | old_style = 0; |
| 151 | if ((*str)[0] == '0' && (*str)[1] == 'x') { |
| 152 | *str += 2; |
| 153 | old_style = 1; |
| 154 | } |
| 155 | if (!isxdigit((*str)[0])) /* We require at least one hex digit */ |
| 156 | return -EINVAL; |
| 157 | val = simple_strtoul(*str, str, 16); |
| 158 | if (old_style || (*str)[0] != '.') { |
| 159 | *id0 = *id1 = 0; |
| 160 | if (val < 0 || val > 0xffff) |
| 161 | return -EINVAL; |
| 162 | *devno = val; |
| 163 | return 0; |
| 164 | } |
| 165 | /* New style x.y.z busid */ |
| 166 | if (val < 0 || val > 0xff) |
| 167 | return -EINVAL; |
| 168 | *id0 = val; |
| 169 | (*str)++; |
| 170 | if (!isxdigit((*str)[0])) /* We require at least one hex digit */ |
| 171 | return -EINVAL; |
| 172 | val = simple_strtoul(*str, str, 16); |
| 173 | if (val < 0 || val > 0xff || (*str)++[0] != '.') |
| 174 | return -EINVAL; |
| 175 | *id1 = val; |
| 176 | if (!isxdigit((*str)[0])) /* We require at least one hex digit */ |
| 177 | return -EINVAL; |
| 178 | val = simple_strtoul(*str, str, 16); |
| 179 | if (val < 0 || val > 0xffff) |
| 180 | return -EINVAL; |
| 181 | *devno = val; |
| 182 | return 0; |
| 183 | } |
| 184 | |
| 185 | /* |
| 186 | * Read colon separated list of dasd features. Currently there is |
| 187 | * only one: "ro" for read-only devices. The default feature set |
| 188 | * is empty (value 0). |
| 189 | */ |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 190 | static int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | dasd_feature_list(char *str, char **endp) |
| 192 | { |
| 193 | int features, len, rc; |
| 194 | |
| 195 | rc = 0; |
| 196 | if (*str != '(') { |
| 197 | *endp = str; |
| 198 | return DASD_FEATURE_DEFAULT; |
| 199 | } |
| 200 | str++; |
| 201 | features = 0; |
| 202 | |
| 203 | while (1) { |
Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame] | 204 | for (len = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | str[len] && str[len] != ':' && str[len] != ')'; len++); |
| 206 | if (len == 2 && !strncmp(str, "ro", 2)) |
| 207 | features |= DASD_FEATURE_READONLY; |
| 208 | else if (len == 4 && !strncmp(str, "diag", 4)) |
| 209 | features |= DASD_FEATURE_USEDIAG; |
Stefan Haberland | e4dbb0f | 2011-01-05 12:48:06 +0100 | [diff] [blame] | 210 | else if (len == 3 && !strncmp(str, "raw", 3)) |
| 211 | features |= DASD_FEATURE_USERAW; |
Horst Hummel | 9575bf2 | 2006-12-08 15:54:15 +0100 | [diff] [blame] | 212 | else if (len == 6 && !strncmp(str, "erplog", 6)) |
| 213 | features |= DASD_FEATURE_ERPLOG; |
Holger Smolinski | 13de227 | 2009-01-09 12:14:51 +0100 | [diff] [blame] | 214 | else if (len == 8 && !strncmp(str, "failfast", 8)) |
| 215 | features |= DASD_FEATURE_FAILFAST; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | else { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 217 | pr_warning("%*s is not a supported device option\n", |
| 218 | len, str); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | rc = -EINVAL; |
| 220 | } |
| 221 | str += len; |
| 222 | if (*str != ':') |
| 223 | break; |
| 224 | str++; |
| 225 | } |
| 226 | if (*str != ')') { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 227 | pr_warning("A closing parenthesis ')' is missing in the " |
| 228 | "dasd= parameter\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | 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 | */ |
| 244 | static char * |
| 245 | dasd_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 Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 258 | if (strncmp("autodetect", parsestring, length) == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | dasd_autodetect = 1; |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 260 | pr_info("The autodetection mode has been activated\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | return residual_str; |
| 262 | } |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 263 | if (strncmp("probeonly", parsestring, length) == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | dasd_probeonly = 1; |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 265 | pr_info("The probeonly mode has been activated\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | return residual_str; |
| 267 | } |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 268 | if (strncmp("nopav", parsestring, length) == 0) { |
Peter Oberparleiter | dcd707b | 2006-09-20 15:59:52 +0200 | [diff] [blame] | 269 | if (MACHINE_IS_VM) |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 270 | pr_info("'nopav' is not supported on z/VM\n"); |
Peter Oberparleiter | dcd707b | 2006-09-20 15:59:52 +0200 | [diff] [blame] | 271 | else { |
| 272 | dasd_nopav = 1; |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 273 | pr_info("PAV support has be deactivated\n"); |
Peter Oberparleiter | dcd707b | 2006-09-20 15:59:52 +0200 | [diff] [blame] | 274 | } |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 275 | return residual_str; |
| 276 | } |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 277 | if (strncmp("nofcx", parsestring, length) == 0) { |
| 278 | dasd_nofcx = 1; |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 279 | pr_info("High Performance FICON support has been " |
| 280 | "deactivated\n"); |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 281 | return residual_str; |
| 282 | } |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 283 | if (strncmp("fixedbuffers", parsestring, length) == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | if (dasd_page_cache) |
| 285 | return residual_str; |
| 286 | dasd_page_cache = |
Heiko Carstens | 2f6c55f | 2006-08-16 13:49:27 +0200 | [diff] [blame] | 287 | kmem_cache_create("dasd_page_cache", PAGE_SIZE, |
| 288 | PAGE_SIZE, SLAB_CACHE_DMA, |
Paul Mundt | 20c2df8 | 2007-07-20 10:11:58 +0900 | [diff] [blame] | 289 | NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | if (!dasd_page_cache) |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 291 | DBF_EVENT(DBF_WARNING, "%s", "Failed to create slab, " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | "fixed buffer mode disabled."); |
| 293 | else |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 294 | DBF_EVENT(DBF_INFO, "%s", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | "turning on fixed buffer mode"); |
| 296 | return residual_str; |
| 297 | } |
| 298 | return ERR_PTR(-EINVAL); |
| 299 | } |
| 300 | |
| 301 | /* |
| 302 | * Try to interprete the first element on the comma separated parse string |
| 303 | * as a device number or a range of devices. If the interpretation is |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 304 | * successful, create the matching dasd_devmap entries and return a pointer |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | * to the residual string. |
| 306 | * If interpretation fails or in case of an error, return an error code. |
| 307 | */ |
| 308 | static char * |
| 309 | dasd_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 Sievers | 98df67b | 2008-12-25 13:38:55 +0100 | [diff] [blame] | 315 | char bus_id[DASD_BUS_ID_SIZE+1], *str; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | |
| 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 Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 332 | pr_err("%s is not a valid device range\n", parsestring); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | return ERR_PTR(rc); |
| 334 | } |
| 335 | features = dasd_feature_list(str, &str); |
| 336 | if (features < 0) |
| 337 | return ERR_PTR(-EINVAL); |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 338 | /* each device in dasd= parameter should be set initially online */ |
| 339 | features |= DASD_FEATURE_INITIAL_ONLINE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | 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 Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 351 | pr_warning("The dasd= parameter value %s has an invalid ending\n", |
| 352 | str); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | return ERR_PTR(-EINVAL); |
| 354 | } |
| 355 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 356 | static char * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | dasd_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 | */ |
| 374 | int |
| 375 | dasd_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 Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame] | 405 | * devices. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | */ |
| 407 | static struct dasd_devmap * |
Cornelia Huck | 69f90f6 | 2008-05-15 16:52:34 +0200 | [diff] [blame] | 408 | dasd_add_busid(const char *bus_id, int features) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | { |
| 410 | struct dasd_devmap *devmap, *new, *tmp; |
| 411 | int hash; |
| 412 | |
Zhang Yanfei | 006485d | 2013-03-12 13:18:47 +0800 | [diff] [blame] | 413 | new = 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 | } |
Stefan Weinhuber | a4d26c6 | 2011-01-05 12:48:03 +0100 | [diff] [blame] | 642 | EXPORT_SYMBOL_GPL(dasd_put_device_wake); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | |
| 644 | /* |
| 645 | * Return dasd_device structure associated with cdev. |
Martin Schwidefsky | a00bfd7 | 2006-09-20 15:59:05 +0200 | [diff] [blame] | 646 | * This function needs to be called with the ccw device |
| 647 | * lock held. It can be used from interrupt context. |
| 648 | */ |
| 649 | struct dasd_device * |
| 650 | dasd_device_from_cdev_locked(struct ccw_device *cdev) |
| 651 | { |
Cornelia Huck | faf16aa | 2008-12-25 13:38:52 +0100 | [diff] [blame] | 652 | struct dasd_device *device = dev_get_drvdata(&cdev->dev); |
Martin Schwidefsky | a00bfd7 | 2006-09-20 15:59:05 +0200 | [diff] [blame] | 653 | |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | */ |
| 663 | struct dasd_device * |
| 664 | dasd_device_from_cdev(struct ccw_device *cdev) |
| 665 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | struct dasd_device *device; |
Martin Schwidefsky | a00bfd7 | 2006-09-20 15:59:05 +0200 | [diff] [blame] | 667 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | |
Martin Schwidefsky | a00bfd7 | 2006-09-20 15:59:05 +0200 | [diff] [blame] | 669 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | return device; |
| 673 | } |
| 674 | |
Stefan Weinhuber | 65f8da4 | 2011-04-20 10:15:30 +0200 | [diff] [blame] | 675 | void dasd_add_link_to_gendisk(struct gendisk *gdp, struct dasd_device *device) |
| 676 | { |
| 677 | struct dasd_devmap *devmap; |
| 678 | |
| 679 | devmap = dasd_find_busid(dev_name(&device->cdev->dev)); |
| 680 | if (IS_ERR(devmap)) |
| 681 | return; |
| 682 | spin_lock(&dasd_devmap_lock); |
| 683 | gdp->private_data = devmap; |
| 684 | spin_unlock(&dasd_devmap_lock); |
| 685 | } |
| 686 | |
| 687 | struct dasd_device *dasd_device_from_gendisk(struct gendisk *gdp) |
| 688 | { |
| 689 | struct dasd_device *device; |
| 690 | struct dasd_devmap *devmap; |
| 691 | |
| 692 | if (!gdp->private_data) |
| 693 | return NULL; |
| 694 | device = NULL; |
| 695 | spin_lock(&dasd_devmap_lock); |
| 696 | devmap = gdp->private_data; |
| 697 | if (devmap && devmap->device) { |
| 698 | device = devmap->device; |
| 699 | dasd_get_device(device); |
| 700 | } |
| 701 | spin_unlock(&dasd_devmap_lock); |
| 702 | return device; |
| 703 | } |
| 704 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | /* |
| 706 | * SECTION: files in sysfs |
| 707 | */ |
| 708 | |
| 709 | /* |
Holger Smolinski | 13de227 | 2009-01-09 12:14:51 +0100 | [diff] [blame] | 710 | * failfast controls the behaviour, if no path is available |
| 711 | */ |
| 712 | static ssize_t dasd_ff_show(struct device *dev, struct device_attribute *attr, |
| 713 | char *buf) |
| 714 | { |
| 715 | struct dasd_devmap *devmap; |
| 716 | int ff_flag; |
| 717 | |
Cornelia Huck | ca0b4b7 | 2009-02-11 10:37:30 +0100 | [diff] [blame] | 718 | devmap = dasd_find_busid(dev_name(dev)); |
Holger Smolinski | 13de227 | 2009-01-09 12:14:51 +0100 | [diff] [blame] | 719 | if (!IS_ERR(devmap)) |
| 720 | ff_flag = (devmap->features & DASD_FEATURE_FAILFAST) != 0; |
| 721 | else |
| 722 | ff_flag = (DASD_FEATURE_DEFAULT & DASD_FEATURE_FAILFAST) != 0; |
| 723 | return snprintf(buf, PAGE_SIZE, ff_flag ? "1\n" : "0\n"); |
| 724 | } |
| 725 | |
| 726 | static ssize_t dasd_ff_store(struct device *dev, struct device_attribute *attr, |
| 727 | const char *buf, size_t count) |
| 728 | { |
| 729 | struct dasd_devmap *devmap; |
| 730 | int val; |
| 731 | char *endp; |
| 732 | |
| 733 | devmap = dasd_devmap_from_cdev(to_ccwdev(dev)); |
| 734 | if (IS_ERR(devmap)) |
| 735 | return PTR_ERR(devmap); |
| 736 | |
| 737 | val = simple_strtoul(buf, &endp, 0); |
| 738 | if (((endp + 1) < (buf + count)) || (val > 1)) |
| 739 | return -EINVAL; |
| 740 | |
| 741 | spin_lock(&dasd_devmap_lock); |
| 742 | if (val) |
| 743 | devmap->features |= DASD_FEATURE_FAILFAST; |
| 744 | else |
| 745 | devmap->features &= ~DASD_FEATURE_FAILFAST; |
| 746 | if (devmap->device) |
| 747 | devmap->device->features = devmap->features; |
| 748 | spin_unlock(&dasd_devmap_lock); |
| 749 | return count; |
| 750 | } |
| 751 | |
| 752 | static DEVICE_ATTR(failfast, 0644, dasd_ff_show, dasd_ff_store); |
| 753 | |
| 754 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 755 | * readonly controls the readonly status of a dasd |
| 756 | */ |
| 757 | static ssize_t |
Yani Ioannou | e404e27 | 2005-05-17 06:42:58 -0400 | [diff] [blame] | 758 | dasd_ro_show(struct device *dev, struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 759 | { |
| 760 | struct dasd_devmap *devmap; |
| 761 | int ro_flag; |
| 762 | |
Kay Sievers | 2a0217d | 2008-10-10 21:33:09 +0200 | [diff] [blame] | 763 | devmap = dasd_find_busid(dev_name(dev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 | if (!IS_ERR(devmap)) |
| 765 | ro_flag = (devmap->features & DASD_FEATURE_READONLY) != 0; |
| 766 | else |
| 767 | ro_flag = (DASD_FEATURE_DEFAULT & DASD_FEATURE_READONLY) != 0; |
| 768 | return snprintf(buf, PAGE_SIZE, ro_flag ? "1\n" : "0\n"); |
| 769 | } |
| 770 | |
| 771 | static ssize_t |
Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame] | 772 | dasd_ro_store(struct device *dev, struct device_attribute *attr, |
| 773 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 774 | { |
| 775 | struct dasd_devmap *devmap; |
Stefan Weinhuber | 33b62a3 | 2010-03-08 12:26:24 +0100 | [diff] [blame] | 776 | struct dasd_device *device; |
Horst Hummel | 01376f4 | 2006-12-04 15:39:50 +0100 | [diff] [blame] | 777 | int val; |
| 778 | char *endp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 779 | |
| 780 | devmap = dasd_devmap_from_cdev(to_ccwdev(dev)); |
| 781 | if (IS_ERR(devmap)) |
| 782 | return PTR_ERR(devmap); |
Horst Hummel | 01376f4 | 2006-12-04 15:39:50 +0100 | [diff] [blame] | 783 | |
| 784 | val = simple_strtoul(buf, &endp, 0); |
| 785 | if (((endp + 1) < (buf + count)) || (val > 1)) |
| 786 | return -EINVAL; |
| 787 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 788 | spin_lock(&dasd_devmap_lock); |
Horst Hummel | 01376f4 | 2006-12-04 15:39:50 +0100 | [diff] [blame] | 789 | if (val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | devmap->features |= DASD_FEATURE_READONLY; |
| 791 | else |
| 792 | devmap->features &= ~DASD_FEATURE_READONLY; |
Stefan Weinhuber | 33b62a3 | 2010-03-08 12:26:24 +0100 | [diff] [blame] | 793 | device = devmap->device; |
| 794 | if (device) { |
| 795 | device->features = devmap->features; |
| 796 | val = val || test_bit(DASD_FLAG_DEVICE_RO, &device->flags); |
| 797 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | spin_unlock(&dasd_devmap_lock); |
Stefan Weinhuber | 33b62a3 | 2010-03-08 12:26:24 +0100 | [diff] [blame] | 799 | if (device && device->block && device->block->gdp) |
| 800 | set_disk_ro(device->block->gdp, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 801 | return count; |
| 802 | } |
| 803 | |
| 804 | static DEVICE_ATTR(readonly, 0644, dasd_ro_show, dasd_ro_store); |
Horst Hummel | 9575bf2 | 2006-12-08 15:54:15 +0100 | [diff] [blame] | 805 | /* |
| 806 | * erplog controls the logging of ERP related data |
| 807 | * (e.g. failing channel programs). |
| 808 | */ |
| 809 | static ssize_t |
| 810 | dasd_erplog_show(struct device *dev, struct device_attribute *attr, char *buf) |
| 811 | { |
| 812 | struct dasd_devmap *devmap; |
| 813 | int erplog; |
| 814 | |
Kay Sievers | 2a0217d | 2008-10-10 21:33:09 +0200 | [diff] [blame] | 815 | devmap = dasd_find_busid(dev_name(dev)); |
Horst Hummel | 9575bf2 | 2006-12-08 15:54:15 +0100 | [diff] [blame] | 816 | if (!IS_ERR(devmap)) |
| 817 | erplog = (devmap->features & DASD_FEATURE_ERPLOG) != 0; |
| 818 | else |
| 819 | erplog = (DASD_FEATURE_DEFAULT & DASD_FEATURE_ERPLOG) != 0; |
| 820 | return snprintf(buf, PAGE_SIZE, erplog ? "1\n" : "0\n"); |
| 821 | } |
| 822 | |
| 823 | static ssize_t |
| 824 | dasd_erplog_store(struct device *dev, struct device_attribute *attr, |
| 825 | const char *buf, size_t count) |
| 826 | { |
| 827 | struct dasd_devmap *devmap; |
| 828 | int val; |
| 829 | char *endp; |
| 830 | |
| 831 | devmap = dasd_devmap_from_cdev(to_ccwdev(dev)); |
| 832 | if (IS_ERR(devmap)) |
| 833 | return PTR_ERR(devmap); |
| 834 | |
| 835 | val = simple_strtoul(buf, &endp, 0); |
| 836 | if (((endp + 1) < (buf + count)) || (val > 1)) |
| 837 | return -EINVAL; |
| 838 | |
| 839 | spin_lock(&dasd_devmap_lock); |
| 840 | if (val) |
| 841 | devmap->features |= DASD_FEATURE_ERPLOG; |
| 842 | else |
| 843 | devmap->features &= ~DASD_FEATURE_ERPLOG; |
| 844 | if (devmap->device) |
| 845 | devmap->device->features = devmap->features; |
| 846 | spin_unlock(&dasd_devmap_lock); |
| 847 | return count; |
| 848 | } |
| 849 | |
| 850 | static DEVICE_ATTR(erplog, 0644, dasd_erplog_show, dasd_erplog_store); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 851 | |
| 852 | /* |
| 853 | * use_diag controls whether the driver should use diag rather than ssch |
| 854 | * to talk to the device |
| 855 | */ |
Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame] | 856 | static ssize_t |
Yani Ioannou | e404e27 | 2005-05-17 06:42:58 -0400 | [diff] [blame] | 857 | 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] | 858 | { |
| 859 | struct dasd_devmap *devmap; |
| 860 | int use_diag; |
| 861 | |
Kay Sievers | 2a0217d | 2008-10-10 21:33:09 +0200 | [diff] [blame] | 862 | devmap = dasd_find_busid(dev_name(dev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 863 | if (!IS_ERR(devmap)) |
| 864 | use_diag = (devmap->features & DASD_FEATURE_USEDIAG) != 0; |
| 865 | else |
| 866 | use_diag = (DASD_FEATURE_DEFAULT & DASD_FEATURE_USEDIAG) != 0; |
| 867 | return sprintf(buf, use_diag ? "1\n" : "0\n"); |
| 868 | } |
| 869 | |
| 870 | static ssize_t |
Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame] | 871 | dasd_use_diag_store(struct device *dev, struct device_attribute *attr, |
| 872 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 873 | { |
| 874 | struct dasd_devmap *devmap; |
| 875 | ssize_t rc; |
Horst Hummel | 01376f4 | 2006-12-04 15:39:50 +0100 | [diff] [blame] | 876 | int val; |
| 877 | char *endp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 878 | |
| 879 | devmap = dasd_devmap_from_cdev(to_ccwdev(dev)); |
| 880 | if (IS_ERR(devmap)) |
| 881 | return PTR_ERR(devmap); |
Horst Hummel | 01376f4 | 2006-12-04 15:39:50 +0100 | [diff] [blame] | 882 | |
| 883 | val = simple_strtoul(buf, &endp, 0); |
| 884 | if (((endp + 1) < (buf + count)) || (val > 1)) |
| 885 | return -EINVAL; |
| 886 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 887 | spin_lock(&dasd_devmap_lock); |
| 888 | /* Changing diag discipline flag is only allowed in offline state. */ |
| 889 | rc = count; |
Stefan Haberland | e4dbb0f | 2011-01-05 12:48:06 +0100 | [diff] [blame] | 890 | if (!devmap->device && !(devmap->features & DASD_FEATURE_USERAW)) { |
Horst Hummel | 01376f4 | 2006-12-04 15:39:50 +0100 | [diff] [blame] | 891 | if (val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 892 | devmap->features |= DASD_FEATURE_USEDIAG; |
| 893 | else |
| 894 | devmap->features &= ~DASD_FEATURE_USEDIAG; |
| 895 | } else |
| 896 | rc = -EPERM; |
| 897 | spin_unlock(&dasd_devmap_lock); |
| 898 | return rc; |
| 899 | } |
| 900 | |
Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame] | 901 | 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] | 902 | |
Stefan Haberland | e4dbb0f | 2011-01-05 12:48:06 +0100 | [diff] [blame] | 903 | /* |
| 904 | * use_raw controls whether the driver should give access to raw eckd data or |
| 905 | * operate in standard mode |
| 906 | */ |
| 907 | static ssize_t |
| 908 | dasd_use_raw_show(struct device *dev, struct device_attribute *attr, char *buf) |
| 909 | { |
| 910 | struct dasd_devmap *devmap; |
| 911 | int use_raw; |
| 912 | |
| 913 | devmap = dasd_find_busid(dev_name(dev)); |
| 914 | if (!IS_ERR(devmap)) |
| 915 | use_raw = (devmap->features & DASD_FEATURE_USERAW) != 0; |
| 916 | else |
| 917 | use_raw = (DASD_FEATURE_DEFAULT & DASD_FEATURE_USERAW) != 0; |
| 918 | return sprintf(buf, use_raw ? "1\n" : "0\n"); |
| 919 | } |
| 920 | |
| 921 | static ssize_t |
| 922 | dasd_use_raw_store(struct device *dev, struct device_attribute *attr, |
| 923 | const char *buf, size_t count) |
| 924 | { |
| 925 | struct dasd_devmap *devmap; |
| 926 | ssize_t rc; |
| 927 | unsigned long val; |
| 928 | |
| 929 | devmap = dasd_devmap_from_cdev(to_ccwdev(dev)); |
| 930 | if (IS_ERR(devmap)) |
| 931 | return PTR_ERR(devmap); |
| 932 | |
| 933 | if ((strict_strtoul(buf, 10, &val) != 0) || val > 1) |
| 934 | return -EINVAL; |
| 935 | |
| 936 | spin_lock(&dasd_devmap_lock); |
| 937 | /* Changing diag discipline flag is only allowed in offline state. */ |
| 938 | rc = count; |
| 939 | if (!devmap->device && !(devmap->features & DASD_FEATURE_USEDIAG)) { |
| 940 | if (val) |
| 941 | devmap->features |= DASD_FEATURE_USERAW; |
| 942 | else |
| 943 | devmap->features &= ~DASD_FEATURE_USERAW; |
| 944 | } else |
| 945 | rc = -EPERM; |
| 946 | spin_unlock(&dasd_devmap_lock); |
| 947 | return rc; |
| 948 | } |
| 949 | |
| 950 | static DEVICE_ATTR(raw_track_access, 0644, dasd_use_raw_show, |
| 951 | dasd_use_raw_store); |
| 952 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 953 | static ssize_t |
Stefan Haberland | d07dc5d | 2012-11-28 13:43:38 +0100 | [diff] [blame] | 954 | dasd_safe_offline_store(struct device *dev, struct device_attribute *attr, |
| 955 | const char *buf, size_t count) |
| 956 | { |
| 957 | struct ccw_device *cdev = to_ccwdev(dev); |
| 958 | struct dasd_device *device; |
| 959 | int rc; |
| 960 | |
| 961 | device = dasd_device_from_cdev(cdev); |
| 962 | if (IS_ERR(device)) { |
| 963 | rc = PTR_ERR(device); |
| 964 | goto out; |
| 965 | } |
| 966 | |
| 967 | if (test_bit(DASD_FLAG_OFFLINE, &device->flags) || |
| 968 | test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) { |
| 969 | /* Already doing offline processing */ |
| 970 | dasd_put_device(device); |
| 971 | rc = -EBUSY; |
| 972 | goto out; |
| 973 | } |
| 974 | |
| 975 | set_bit(DASD_FLAG_SAFE_OFFLINE, &device->flags); |
| 976 | dasd_put_device(device); |
| 977 | |
| 978 | rc = ccw_device_set_offline(cdev); |
| 979 | |
| 980 | out: |
| 981 | return rc ? rc : count; |
| 982 | } |
| 983 | |
| 984 | static DEVICE_ATTR(safe_offline, 0200, NULL, dasd_safe_offline_store); |
| 985 | |
| 986 | static ssize_t |
Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame] | 987 | dasd_discipline_show(struct device *dev, struct device_attribute *attr, |
| 988 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 989 | { |
Martin Schwidefsky | a00bfd7 | 2006-09-20 15:59:05 +0200 | [diff] [blame] | 990 | struct dasd_device *device; |
| 991 | ssize_t len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 992 | |
Martin Schwidefsky | a00bfd7 | 2006-09-20 15:59:05 +0200 | [diff] [blame] | 993 | device = dasd_device_from_cdev(to_ccwdev(dev)); |
Stefan Haberland | 589c74d | 2010-02-26 22:37:47 +0100 | [diff] [blame] | 994 | if (IS_ERR(device)) |
| 995 | goto out; |
| 996 | else if (!device->discipline) { |
| 997 | dasd_put_device(device); |
| 998 | goto out; |
| 999 | } else { |
Martin Schwidefsky | a00bfd7 | 2006-09-20 15:59:05 +0200 | [diff] [blame] | 1000 | len = snprintf(buf, PAGE_SIZE, "%s\n", |
| 1001 | device->discipline->name); |
| 1002 | dasd_put_device(device); |
Stefan Haberland | 589c74d | 2010-02-26 22:37:47 +0100 | [diff] [blame] | 1003 | return len; |
| 1004 | } |
| 1005 | out: |
| 1006 | len = snprintf(buf, PAGE_SIZE, "none\n"); |
Martin Schwidefsky | a00bfd7 | 2006-09-20 15:59:05 +0200 | [diff] [blame] | 1007 | return len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1008 | } |
| 1009 | |
| 1010 | static DEVICE_ATTR(discipline, 0444, dasd_discipline_show, NULL); |
| 1011 | |
Horst Hummel | 3d05259 | 2006-04-27 18:40:28 -0700 | [diff] [blame] | 1012 | static ssize_t |
Horst Hummel | 4dfd5c4 | 2007-04-27 16:01:47 +0200 | [diff] [blame] | 1013 | dasd_device_status_show(struct device *dev, struct device_attribute *attr, |
| 1014 | char *buf) |
| 1015 | { |
| 1016 | struct dasd_device *device; |
| 1017 | ssize_t len; |
| 1018 | |
| 1019 | device = dasd_device_from_cdev(to_ccwdev(dev)); |
| 1020 | if (!IS_ERR(device)) { |
| 1021 | switch (device->state) { |
| 1022 | case DASD_STATE_NEW: |
| 1023 | len = snprintf(buf, PAGE_SIZE, "new\n"); |
| 1024 | break; |
| 1025 | case DASD_STATE_KNOWN: |
| 1026 | len = snprintf(buf, PAGE_SIZE, "detected\n"); |
| 1027 | break; |
| 1028 | case DASD_STATE_BASIC: |
| 1029 | len = snprintf(buf, PAGE_SIZE, "basic\n"); |
| 1030 | break; |
| 1031 | case DASD_STATE_UNFMT: |
| 1032 | len = snprintf(buf, PAGE_SIZE, "unformatted\n"); |
| 1033 | break; |
| 1034 | case DASD_STATE_READY: |
| 1035 | len = snprintf(buf, PAGE_SIZE, "ready\n"); |
| 1036 | break; |
| 1037 | case DASD_STATE_ONLINE: |
| 1038 | len = snprintf(buf, PAGE_SIZE, "online\n"); |
| 1039 | break; |
| 1040 | default: |
| 1041 | len = snprintf(buf, PAGE_SIZE, "no stat\n"); |
| 1042 | break; |
| 1043 | } |
| 1044 | dasd_put_device(device); |
| 1045 | } else |
| 1046 | len = snprintf(buf, PAGE_SIZE, "unknown\n"); |
| 1047 | return len; |
| 1048 | } |
| 1049 | |
| 1050 | static DEVICE_ATTR(status, 0444, dasd_device_status_show, NULL); |
| 1051 | |
Stefan Haberland | 2dedf0d | 2010-05-17 10:00:11 +0200 | [diff] [blame] | 1052 | static ssize_t dasd_alias_show(struct device *dev, |
| 1053 | struct device_attribute *attr, char *buf) |
Horst Hummel | 3d05259 | 2006-04-27 18:40:28 -0700 | [diff] [blame] | 1054 | { |
Stefan Haberland | 2dedf0d | 2010-05-17 10:00:11 +0200 | [diff] [blame] | 1055 | struct dasd_device *device; |
| 1056 | struct dasd_uid uid; |
Horst Hummel | 3d05259 | 2006-04-27 18:40:28 -0700 | [diff] [blame] | 1057 | |
Stefan Haberland | 2dedf0d | 2010-05-17 10:00:11 +0200 | [diff] [blame] | 1058 | device = dasd_device_from_cdev(to_ccwdev(dev)); |
| 1059 | if (IS_ERR(device)) |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1060 | return sprintf(buf, "0\n"); |
Stefan Haberland | 2dedf0d | 2010-05-17 10:00:11 +0200 | [diff] [blame] | 1061 | |
| 1062 | if (device->discipline && device->discipline->get_uid && |
| 1063 | !device->discipline->get_uid(device, &uid)) { |
| 1064 | if (uid.type == UA_BASE_PAV_ALIAS || |
Stefan Haberland | 0abccf7 | 2010-07-19 09:22:36 +0200 | [diff] [blame] | 1065 | uid.type == UA_HYPER_PAV_ALIAS) { |
| 1066 | dasd_put_device(device); |
Stefan Haberland | 2dedf0d | 2010-05-17 10:00:11 +0200 | [diff] [blame] | 1067 | return sprintf(buf, "1\n"); |
Stefan Haberland | 0abccf7 | 2010-07-19 09:22:36 +0200 | [diff] [blame] | 1068 | } |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1069 | } |
Stefan Haberland | 2dedf0d | 2010-05-17 10:00:11 +0200 | [diff] [blame] | 1070 | dasd_put_device(device); |
| 1071 | |
| 1072 | return sprintf(buf, "0\n"); |
Horst Hummel | 3d05259 | 2006-04-27 18:40:28 -0700 | [diff] [blame] | 1073 | } |
| 1074 | |
| 1075 | static DEVICE_ATTR(alias, 0444, dasd_alias_show, NULL); |
| 1076 | |
Stefan Haberland | 2dedf0d | 2010-05-17 10:00:11 +0200 | [diff] [blame] | 1077 | static ssize_t dasd_vendor_show(struct device *dev, |
| 1078 | struct device_attribute *attr, char *buf) |
Horst Hummel | 3d05259 | 2006-04-27 18:40:28 -0700 | [diff] [blame] | 1079 | { |
Stefan Haberland | 2dedf0d | 2010-05-17 10:00:11 +0200 | [diff] [blame] | 1080 | struct dasd_device *device; |
| 1081 | struct dasd_uid uid; |
Horst Hummel | 3d05259 | 2006-04-27 18:40:28 -0700 | [diff] [blame] | 1082 | char *vendor; |
| 1083 | |
Stefan Haberland | 2dedf0d | 2010-05-17 10:00:11 +0200 | [diff] [blame] | 1084 | device = dasd_device_from_cdev(to_ccwdev(dev)); |
| 1085 | vendor = ""; |
| 1086 | if (IS_ERR(device)) |
| 1087 | return snprintf(buf, PAGE_SIZE, "%s\n", vendor); |
| 1088 | |
| 1089 | if (device->discipline && device->discipline->get_uid && |
| 1090 | !device->discipline->get_uid(device, &uid)) |
| 1091 | vendor = uid.vendor; |
| 1092 | |
| 1093 | dasd_put_device(device); |
Horst Hummel | 3d05259 | 2006-04-27 18:40:28 -0700 | [diff] [blame] | 1094 | |
| 1095 | return snprintf(buf, PAGE_SIZE, "%s\n", vendor); |
| 1096 | } |
| 1097 | |
| 1098 | static DEVICE_ATTR(vendor, 0444, dasd_vendor_show, NULL); |
| 1099 | |
| 1100 | #define UID_STRLEN ( /* vendor */ 3 + 1 + /* serial */ 14 + 1 +\ |
Stefan Weinhuber | 4abb08c | 2008-08-01 16:39:09 +0200 | [diff] [blame] | 1101 | /* SSID */ 4 + 1 + /* unit addr */ 2 + 1 +\ |
| 1102 | /* vduit */ 32 + 1) |
Horst Hummel | 3d05259 | 2006-04-27 18:40:28 -0700 | [diff] [blame] | 1103 | |
| 1104 | static ssize_t |
| 1105 | dasd_uid_show(struct device *dev, struct device_attribute *attr, char *buf) |
| 1106 | { |
Stefan Haberland | 2dedf0d | 2010-05-17 10:00:11 +0200 | [diff] [blame] | 1107 | struct dasd_device *device; |
| 1108 | struct dasd_uid uid; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1109 | char uid_string[UID_STRLEN]; |
| 1110 | char ua_string[3]; |
Horst Hummel | 3d05259 | 2006-04-27 18:40:28 -0700 | [diff] [blame] | 1111 | |
Stefan Haberland | 2dedf0d | 2010-05-17 10:00:11 +0200 | [diff] [blame] | 1112 | device = dasd_device_from_cdev(to_ccwdev(dev)); |
| 1113 | uid_string[0] = 0; |
| 1114 | if (IS_ERR(device)) |
| 1115 | return snprintf(buf, PAGE_SIZE, "%s\n", uid_string); |
| 1116 | |
| 1117 | if (device->discipline && device->discipline->get_uid && |
| 1118 | !device->discipline->get_uid(device, &uid)) { |
| 1119 | switch (uid.type) { |
| 1120 | case UA_BASE_DEVICE: |
| 1121 | snprintf(ua_string, sizeof(ua_string), "%02x", |
| 1122 | uid.real_unit_addr); |
| 1123 | break; |
| 1124 | case UA_BASE_PAV_ALIAS: |
| 1125 | snprintf(ua_string, sizeof(ua_string), "%02x", |
| 1126 | uid.base_unit_addr); |
| 1127 | break; |
| 1128 | case UA_HYPER_PAV_ALIAS: |
| 1129 | snprintf(ua_string, sizeof(ua_string), "xx"); |
| 1130 | break; |
| 1131 | default: |
| 1132 | /* should not happen, treat like base device */ |
| 1133 | snprintf(ua_string, sizeof(ua_string), "%02x", |
| 1134 | uid.real_unit_addr); |
| 1135 | break; |
| 1136 | } |
| 1137 | |
| 1138 | if (strlen(uid.vduit) > 0) |
| 1139 | snprintf(uid_string, sizeof(uid_string), |
| 1140 | "%s.%s.%04x.%s.%s", |
| 1141 | uid.vendor, uid.serial, uid.ssid, ua_string, |
| 1142 | uid.vduit); |
| 1143 | else |
| 1144 | snprintf(uid_string, sizeof(uid_string), |
| 1145 | "%s.%s.%04x.%s", |
| 1146 | uid.vendor, uid.serial, uid.ssid, ua_string); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1147 | } |
Stefan Haberland | 2dedf0d | 2010-05-17 10:00:11 +0200 | [diff] [blame] | 1148 | dasd_put_device(device); |
| 1149 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1150 | return snprintf(buf, PAGE_SIZE, "%s\n", uid_string); |
Horst Hummel | 3d05259 | 2006-04-27 18:40:28 -0700 | [diff] [blame] | 1151 | } |
Horst Hummel | 3d05259 | 2006-04-27 18:40:28 -0700 | [diff] [blame] | 1152 | static DEVICE_ATTR(uid, 0444, dasd_uid_show, NULL); |
| 1153 | |
Stefan Weinhuber | 20c6446 | 2006-03-24 03:15:25 -0800 | [diff] [blame] | 1154 | /* |
| 1155 | * extended error-reporting |
| 1156 | */ |
| 1157 | static ssize_t |
| 1158 | dasd_eer_show(struct device *dev, struct device_attribute *attr, char *buf) |
| 1159 | { |
| 1160 | struct dasd_devmap *devmap; |
| 1161 | int eer_flag; |
| 1162 | |
Kay Sievers | 2a0217d | 2008-10-10 21:33:09 +0200 | [diff] [blame] | 1163 | devmap = dasd_find_busid(dev_name(dev)); |
Stefan Weinhuber | 20c6446 | 2006-03-24 03:15:25 -0800 | [diff] [blame] | 1164 | if (!IS_ERR(devmap) && devmap->device) |
| 1165 | eer_flag = dasd_eer_enabled(devmap->device); |
| 1166 | else |
| 1167 | eer_flag = 0; |
| 1168 | return snprintf(buf, PAGE_SIZE, eer_flag ? "1\n" : "0\n"); |
| 1169 | } |
| 1170 | |
| 1171 | static ssize_t |
| 1172 | dasd_eer_store(struct device *dev, struct device_attribute *attr, |
| 1173 | const char *buf, size_t count) |
| 1174 | { |
| 1175 | struct dasd_devmap *devmap; |
Horst Hummel | 01376f4 | 2006-12-04 15:39:50 +0100 | [diff] [blame] | 1176 | int val, rc; |
| 1177 | char *endp; |
Stefan Weinhuber | 20c6446 | 2006-03-24 03:15:25 -0800 | [diff] [blame] | 1178 | |
| 1179 | devmap = dasd_devmap_from_cdev(to_ccwdev(dev)); |
| 1180 | if (IS_ERR(devmap)) |
| 1181 | return PTR_ERR(devmap); |
| 1182 | if (!devmap->device) |
Horst Hummel | 01376f4 | 2006-12-04 15:39:50 +0100 | [diff] [blame] | 1183 | return -ENODEV; |
| 1184 | |
| 1185 | val = simple_strtoul(buf, &endp, 0); |
| 1186 | if (((endp + 1) < (buf + count)) || (val > 1)) |
| 1187 | return -EINVAL; |
| 1188 | |
Horst Hummel | 645c98c | 2006-12-04 15:40:18 +0100 | [diff] [blame] | 1189 | if (val) { |
Stefan Weinhuber | 20c6446 | 2006-03-24 03:15:25 -0800 | [diff] [blame] | 1190 | rc = dasd_eer_enable(devmap->device); |
Horst Hummel | 645c98c | 2006-12-04 15:40:18 +0100 | [diff] [blame] | 1191 | if (rc) |
| 1192 | return rc; |
| 1193 | } else |
Stefan Weinhuber | 20c6446 | 2006-03-24 03:15:25 -0800 | [diff] [blame] | 1194 | dasd_eer_disable(devmap->device); |
Horst Hummel | 645c98c | 2006-12-04 15:40:18 +0100 | [diff] [blame] | 1195 | return count; |
Stefan Weinhuber | 20c6446 | 2006-03-24 03:15:25 -0800 | [diff] [blame] | 1196 | } |
| 1197 | |
| 1198 | static DEVICE_ATTR(eer_enabled, 0644, dasd_eer_show, dasd_eer_store); |
| 1199 | |
Stefan Haberland | 7c8faa8 | 2010-08-09 18:13:00 +0200 | [diff] [blame] | 1200 | /* |
| 1201 | * expiration time for default requests |
| 1202 | */ |
| 1203 | static ssize_t |
| 1204 | dasd_expires_show(struct device *dev, struct device_attribute *attr, char *buf) |
| 1205 | { |
| 1206 | struct dasd_device *device; |
| 1207 | int len; |
| 1208 | |
| 1209 | device = dasd_device_from_cdev(to_ccwdev(dev)); |
| 1210 | if (IS_ERR(device)) |
| 1211 | return -ENODEV; |
| 1212 | len = snprintf(buf, PAGE_SIZE, "%lu\n", device->default_expires); |
| 1213 | dasd_put_device(device); |
| 1214 | return len; |
| 1215 | } |
| 1216 | |
| 1217 | static ssize_t |
| 1218 | dasd_expires_store(struct device *dev, struct device_attribute *attr, |
| 1219 | const char *buf, size_t count) |
| 1220 | { |
| 1221 | struct dasd_device *device; |
| 1222 | unsigned long val; |
| 1223 | |
| 1224 | device = dasd_device_from_cdev(to_ccwdev(dev)); |
| 1225 | if (IS_ERR(device)) |
| 1226 | return -ENODEV; |
| 1227 | |
| 1228 | if ((strict_strtoul(buf, 10, &val) != 0) || |
| 1229 | (val > DASD_EXPIRES_MAX) || val == 0) { |
| 1230 | dasd_put_device(device); |
| 1231 | return -EINVAL; |
| 1232 | } |
| 1233 | |
| 1234 | if (val) |
| 1235 | device->default_expires = val; |
| 1236 | |
| 1237 | dasd_put_device(device); |
| 1238 | return count; |
| 1239 | } |
| 1240 | |
| 1241 | static DEVICE_ATTR(expires, 0644, dasd_expires_show, dasd_expires_store); |
| 1242 | |
Hannes Reinecke | 1f1ee9a | 2013-01-30 09:26:12 +0000 | [diff] [blame] | 1243 | static ssize_t |
| 1244 | dasd_retries_show(struct device *dev, struct device_attribute *attr, char *buf) |
| 1245 | { |
| 1246 | struct dasd_device *device; |
| 1247 | int len; |
| 1248 | |
| 1249 | device = dasd_device_from_cdev(to_ccwdev(dev)); |
| 1250 | if (IS_ERR(device)) |
| 1251 | return -ENODEV; |
| 1252 | len = snprintf(buf, PAGE_SIZE, "%lu\n", device->default_retries); |
| 1253 | dasd_put_device(device); |
| 1254 | return len; |
| 1255 | } |
| 1256 | |
| 1257 | static ssize_t |
| 1258 | dasd_retries_store(struct device *dev, struct device_attribute *attr, |
| 1259 | const char *buf, size_t count) |
| 1260 | { |
| 1261 | struct dasd_device *device; |
| 1262 | unsigned long val; |
| 1263 | |
| 1264 | device = dasd_device_from_cdev(to_ccwdev(dev)); |
| 1265 | if (IS_ERR(device)) |
| 1266 | return -ENODEV; |
| 1267 | |
| 1268 | if ((strict_strtoul(buf, 10, &val) != 0) || |
| 1269 | (val > DASD_RETRIES_MAX)) { |
| 1270 | dasd_put_device(device); |
| 1271 | return -EINVAL; |
| 1272 | } |
| 1273 | |
| 1274 | if (val) |
| 1275 | device->default_retries = val; |
| 1276 | |
| 1277 | dasd_put_device(device); |
| 1278 | return count; |
| 1279 | } |
| 1280 | |
| 1281 | static DEVICE_ATTR(retries, 0644, dasd_retries_show, dasd_retries_store); |
| 1282 | |
Hannes Reinecke | 3d71ad3 | 2013-01-30 09:26:18 +0000 | [diff] [blame^] | 1283 | static ssize_t |
| 1284 | dasd_timeout_show(struct device *dev, struct device_attribute *attr, |
| 1285 | char *buf) |
| 1286 | { |
| 1287 | struct dasd_device *device; |
| 1288 | int len; |
| 1289 | |
| 1290 | device = dasd_device_from_cdev(to_ccwdev(dev)); |
| 1291 | if (IS_ERR(device)) |
| 1292 | return -ENODEV; |
| 1293 | len = snprintf(buf, PAGE_SIZE, "%lu\n", device->blk_timeout); |
| 1294 | dasd_put_device(device); |
| 1295 | return len; |
| 1296 | } |
| 1297 | |
| 1298 | static ssize_t |
| 1299 | dasd_timeout_store(struct device *dev, struct device_attribute *attr, |
| 1300 | const char *buf, size_t count) |
| 1301 | { |
| 1302 | struct dasd_device *device; |
| 1303 | struct request_queue *q; |
| 1304 | unsigned long val, flags; |
| 1305 | |
| 1306 | device = dasd_device_from_cdev(to_ccwdev(dev)); |
| 1307 | if (IS_ERR(device) || !device->block) |
| 1308 | return -ENODEV; |
| 1309 | |
| 1310 | if ((strict_strtoul(buf, 10, &val) != 0) || |
| 1311 | val > UINT_MAX / HZ) { |
| 1312 | dasd_put_device(device); |
| 1313 | return -EINVAL; |
| 1314 | } |
| 1315 | q = device->block->request_queue; |
| 1316 | if (!q) { |
| 1317 | dasd_put_device(device); |
| 1318 | return -ENODEV; |
| 1319 | } |
| 1320 | spin_lock_irqsave(&device->block->request_queue_lock, flags); |
| 1321 | if (!val) |
| 1322 | blk_queue_rq_timed_out(q, NULL); |
| 1323 | else |
| 1324 | blk_queue_rq_timed_out(q, dasd_times_out); |
| 1325 | |
| 1326 | device->blk_timeout = val; |
| 1327 | |
| 1328 | blk_queue_rq_timeout(q, device->blk_timeout * HZ); |
| 1329 | spin_unlock_irqrestore(&device->block->request_queue_lock, flags); |
| 1330 | |
| 1331 | dasd_put_device(device); |
| 1332 | return count; |
| 1333 | } |
| 1334 | |
| 1335 | static DEVICE_ATTR(timeout, 0644, |
| 1336 | dasd_timeout_show, dasd_timeout_store); |
| 1337 | |
Stefan Weinhuber | 5a27e60 | 2011-01-05 12:48:04 +0100 | [diff] [blame] | 1338 | static ssize_t dasd_reservation_policy_show(struct device *dev, |
| 1339 | struct device_attribute *attr, |
| 1340 | char *buf) |
| 1341 | { |
| 1342 | struct dasd_devmap *devmap; |
| 1343 | int rc = 0; |
| 1344 | |
| 1345 | devmap = dasd_find_busid(dev_name(dev)); |
| 1346 | if (IS_ERR(devmap)) { |
| 1347 | rc = snprintf(buf, PAGE_SIZE, "ignore\n"); |
| 1348 | } else { |
| 1349 | spin_lock(&dasd_devmap_lock); |
| 1350 | if (devmap->features & DASD_FEATURE_FAILONSLCK) |
| 1351 | rc = snprintf(buf, PAGE_SIZE, "fail\n"); |
| 1352 | else |
| 1353 | rc = snprintf(buf, PAGE_SIZE, "ignore\n"); |
| 1354 | spin_unlock(&dasd_devmap_lock); |
| 1355 | } |
| 1356 | return rc; |
| 1357 | } |
| 1358 | |
| 1359 | static ssize_t dasd_reservation_policy_store(struct device *dev, |
| 1360 | struct device_attribute *attr, |
| 1361 | const char *buf, size_t count) |
| 1362 | { |
| 1363 | struct dasd_devmap *devmap; |
| 1364 | int rc; |
| 1365 | |
| 1366 | devmap = dasd_devmap_from_cdev(to_ccwdev(dev)); |
| 1367 | if (IS_ERR(devmap)) |
| 1368 | return PTR_ERR(devmap); |
| 1369 | rc = 0; |
| 1370 | spin_lock(&dasd_devmap_lock); |
| 1371 | if (sysfs_streq("ignore", buf)) |
| 1372 | devmap->features &= ~DASD_FEATURE_FAILONSLCK; |
| 1373 | else if (sysfs_streq("fail", buf)) |
| 1374 | devmap->features |= DASD_FEATURE_FAILONSLCK; |
| 1375 | else |
| 1376 | rc = -EINVAL; |
| 1377 | if (devmap->device) |
| 1378 | devmap->device->features = devmap->features; |
| 1379 | spin_unlock(&dasd_devmap_lock); |
| 1380 | if (rc) |
| 1381 | return rc; |
| 1382 | else |
| 1383 | return count; |
| 1384 | } |
| 1385 | |
| 1386 | static DEVICE_ATTR(reservation_policy, 0644, |
| 1387 | dasd_reservation_policy_show, dasd_reservation_policy_store); |
| 1388 | |
| 1389 | static ssize_t dasd_reservation_state_show(struct device *dev, |
| 1390 | struct device_attribute *attr, |
| 1391 | char *buf) |
| 1392 | { |
| 1393 | struct dasd_device *device; |
| 1394 | int rc = 0; |
| 1395 | |
| 1396 | device = dasd_device_from_cdev(to_ccwdev(dev)); |
| 1397 | if (IS_ERR(device)) |
| 1398 | return snprintf(buf, PAGE_SIZE, "none\n"); |
| 1399 | |
| 1400 | if (test_bit(DASD_FLAG_IS_RESERVED, &device->flags)) |
| 1401 | rc = snprintf(buf, PAGE_SIZE, "reserved\n"); |
| 1402 | else if (test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags)) |
| 1403 | rc = snprintf(buf, PAGE_SIZE, "lost\n"); |
| 1404 | else |
| 1405 | rc = snprintf(buf, PAGE_SIZE, "none\n"); |
| 1406 | dasd_put_device(device); |
| 1407 | return rc; |
| 1408 | } |
| 1409 | |
| 1410 | static ssize_t dasd_reservation_state_store(struct device *dev, |
| 1411 | struct device_attribute *attr, |
| 1412 | const char *buf, size_t count) |
| 1413 | { |
| 1414 | struct dasd_device *device; |
| 1415 | int rc = 0; |
| 1416 | |
| 1417 | device = dasd_device_from_cdev(to_ccwdev(dev)); |
| 1418 | if (IS_ERR(device)) |
| 1419 | return -ENODEV; |
| 1420 | if (sysfs_streq("reset", buf)) |
| 1421 | clear_bit(DASD_FLAG_LOCK_STOLEN, &device->flags); |
| 1422 | else |
| 1423 | rc = -EINVAL; |
| 1424 | dasd_put_device(device); |
| 1425 | |
| 1426 | if (rc) |
| 1427 | return rc; |
| 1428 | else |
| 1429 | return count; |
| 1430 | } |
| 1431 | |
| 1432 | static DEVICE_ATTR(last_known_reservation_state, 0644, |
| 1433 | dasd_reservation_state_show, dasd_reservation_state_store); |
| 1434 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1435 | static struct attribute * dasd_attrs[] = { |
| 1436 | &dev_attr_readonly.attr, |
| 1437 | &dev_attr_discipline.attr, |
Horst Hummel | 4dfd5c4 | 2007-04-27 16:01:47 +0200 | [diff] [blame] | 1438 | &dev_attr_status.attr, |
Horst Hummel | 3d05259 | 2006-04-27 18:40:28 -0700 | [diff] [blame] | 1439 | &dev_attr_alias.attr, |
| 1440 | &dev_attr_vendor.attr, |
| 1441 | &dev_attr_uid.attr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1442 | &dev_attr_use_diag.attr, |
Stefan Haberland | e4dbb0f | 2011-01-05 12:48:06 +0100 | [diff] [blame] | 1443 | &dev_attr_raw_track_access.attr, |
Stefan Weinhuber | 20c6446 | 2006-03-24 03:15:25 -0800 | [diff] [blame] | 1444 | &dev_attr_eer_enabled.attr, |
Horst Hummel | 9575bf2 | 2006-12-08 15:54:15 +0100 | [diff] [blame] | 1445 | &dev_attr_erplog.attr, |
Holger Smolinski | 13de227 | 2009-01-09 12:14:51 +0100 | [diff] [blame] | 1446 | &dev_attr_failfast.attr, |
Stefan Haberland | 7c8faa8 | 2010-08-09 18:13:00 +0200 | [diff] [blame] | 1447 | &dev_attr_expires.attr, |
Hannes Reinecke | 1f1ee9a | 2013-01-30 09:26:12 +0000 | [diff] [blame] | 1448 | &dev_attr_retries.attr, |
Hannes Reinecke | 3d71ad3 | 2013-01-30 09:26:18 +0000 | [diff] [blame^] | 1449 | &dev_attr_timeout.attr, |
Stefan Weinhuber | 5a27e60 | 2011-01-05 12:48:04 +0100 | [diff] [blame] | 1450 | &dev_attr_reservation_policy.attr, |
| 1451 | &dev_attr_last_known_reservation_state.attr, |
Stefan Haberland | d07dc5d | 2012-11-28 13:43:38 +0100 | [diff] [blame] | 1452 | &dev_attr_safe_offline.attr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1453 | NULL, |
| 1454 | }; |
| 1455 | |
| 1456 | static struct attribute_group dasd_attr_group = { |
| 1457 | .attrs = dasd_attrs, |
| 1458 | }; |
| 1459 | |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 1460 | /* |
Horst Hummel | f24acd4 | 2005-05-01 08:58:59 -0700 | [diff] [blame] | 1461 | * Return value of the specified feature. |
| 1462 | */ |
| 1463 | int |
| 1464 | dasd_get_feature(struct ccw_device *cdev, int feature) |
| 1465 | { |
| 1466 | struct dasd_devmap *devmap; |
| 1467 | |
Kay Sievers | 2a0217d | 2008-10-10 21:33:09 +0200 | [diff] [blame] | 1468 | devmap = dasd_find_busid(dev_name(&cdev->dev)); |
Horst Hummel | f24acd4 | 2005-05-01 08:58:59 -0700 | [diff] [blame] | 1469 | if (IS_ERR(devmap)) |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 1470 | return PTR_ERR(devmap); |
Horst Hummel | f24acd4 | 2005-05-01 08:58:59 -0700 | [diff] [blame] | 1471 | |
| 1472 | return ((devmap->features & feature) != 0); |
| 1473 | } |
| 1474 | |
| 1475 | /* |
| 1476 | * Set / reset given feature. |
Adam Buchbinder | 48fc7f7 | 2012-09-19 21:48:00 -0400 | [diff] [blame] | 1477 | * Flag indicates whether to set (!=0) or the reset (=0) the feature. |
Horst Hummel | f24acd4 | 2005-05-01 08:58:59 -0700 | [diff] [blame] | 1478 | */ |
| 1479 | int |
| 1480 | dasd_set_feature(struct ccw_device *cdev, int feature, int flag) |
| 1481 | { |
| 1482 | struct dasd_devmap *devmap; |
| 1483 | |
Kay Sievers | 2a0217d | 2008-10-10 21:33:09 +0200 | [diff] [blame] | 1484 | devmap = dasd_find_busid(dev_name(&cdev->dev)); |
Horst Hummel | f24acd4 | 2005-05-01 08:58:59 -0700 | [diff] [blame] | 1485 | if (IS_ERR(devmap)) |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 1486 | return PTR_ERR(devmap); |
Horst Hummel | f24acd4 | 2005-05-01 08:58:59 -0700 | [diff] [blame] | 1487 | |
| 1488 | spin_lock(&dasd_devmap_lock); |
| 1489 | if (flag) |
| 1490 | devmap->features |= feature; |
| 1491 | else |
| 1492 | devmap->features &= ~feature; |
Horst Hummel | c6eb7b7 | 2005-09-03 15:57:58 -0700 | [diff] [blame] | 1493 | if (devmap->device) |
| 1494 | devmap->device->features = devmap->features; |
Horst Hummel | f24acd4 | 2005-05-01 08:58:59 -0700 | [diff] [blame] | 1495 | spin_unlock(&dasd_devmap_lock); |
| 1496 | return 0; |
| 1497 | } |
| 1498 | |
| 1499 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1500 | int |
| 1501 | dasd_add_sysfs_files(struct ccw_device *cdev) |
| 1502 | { |
| 1503 | return sysfs_create_group(&cdev->dev.kobj, &dasd_attr_group); |
| 1504 | } |
| 1505 | |
| 1506 | void |
| 1507 | dasd_remove_sysfs_files(struct ccw_device *cdev) |
| 1508 | { |
| 1509 | sysfs_remove_group(&cdev->dev.kobj, &dasd_attr_group); |
| 1510 | } |
| 1511 | |
| 1512 | |
| 1513 | int |
| 1514 | dasd_devmap_init(void) |
| 1515 | { |
| 1516 | int i; |
| 1517 | |
| 1518 | /* Initialize devmap structures. */ |
| 1519 | dasd_max_devindex = 0; |
| 1520 | for (i = 0; i < 256; i++) |
| 1521 | INIT_LIST_HEAD(&dasd_hashlists[i]); |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 1522 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1523 | } |
| 1524 | |
| 1525 | void |
| 1526 | dasd_devmap_exit(void) |
| 1527 | { |
| 1528 | dasd_forget_ranges(); |
| 1529 | } |