blob: 15a1a70cace90f6eae0dc6a9466970df293e4132 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * Author(s)......: Holger Smolinski <Holger.Smolinski@de.ibm.com>
3 * Horst Hummel <Horst.Hummel@de.ibm.com>
4 * Carsten Otte <Cotte@de.ibm.com>
5 * Martin Schwidefsky <schwidefsky@de.ibm.com>
6 * Bugreports.to..: <Linux390@de.ibm.com>
Heiko Carstensa53c8fa2012-07-20 11:15:04 +02007 * Copyright IBM Corp. 1999,2001
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 *
9 * Device mapping and dasd= parameter parsing functions. All devmap
10 * functions may not be called from interrupt context. In particular
11 * dasd_get_device is a no-no from interrupt context.
12 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 */
14
Stefan Haberlandfc19f382009-03-26 15:23:49 +010015#define KMSG_COMPONENT "dasd"
16
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <linux/ctype.h>
18#include <linux/init.h>
Rusty Russell8d3b33f2006-03-25 03:07:05 -080019#include <linux/module.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090020#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
22#include <asm/debug.h>
23#include <asm/uaccess.h>
Peter Oberparleiter7039d3a2007-04-27 16:01:48 +020024#include <asm/ipl.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025
26/* This is ugly... */
27#define PRINTK_HEADER "dasd_devmap:"
Kay Sievers98df67b2008-12-25 13:38:55 +010028#define DASD_BUS_ID_SIZE 20
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
30#include "dasd_int.h"
31
Christoph Lametere18b8902006-12-06 20:33:20 -080032struct kmem_cache *dasd_page_cache;
Horst Hummel40545572006-06-29 15:08:18 +020033EXPORT_SYMBOL_GPL(dasd_page_cache);
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
35/*
36 * dasd_devmap_t is used to store the features and the relation
37 * between device number and device index. To find a dasd_devmap_t
38 * that corresponds to a device number of a device index each
39 * dasd_devmap_t is added to two linked lists, one to search by
40 * the device number and one to search by the device index. As
41 * soon as big minor numbers are available the device index list
42 * can be removed since the device number will then be identical
43 * to the device index.
44 */
45struct dasd_devmap {
46 struct list_head list;
Kay Sievers98df67b2008-12-25 13:38:55 +010047 char bus_id[DASD_BUS_ID_SIZE];
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 unsigned int devindex;
49 unsigned short features;
50 struct dasd_device *device;
51};
52
53/*
54 * Parameter parsing functions for dasd= parameter. The syntax is:
55 * <devno> : (0x)?[0-9a-fA-F]+
56 * <busid> : [0-0a-f]\.[0-9a-f]\.(0x)?[0-9a-fA-F]+
57 * <feature> : ro
58 * <feature_list> : \(<feature>(:<feature>)*\)
59 * <devno-range> : <devno>(-<devno>)?<feature_list>?
60 * <busid-range> : <busid>(-<busid>)?<feature_list>?
61 * <devices> : <devno-range>|<busid-range>
62 * <dasd_module> : dasd_diag_mod|dasd_eckd_mod|dasd_fba_mod
63 *
64 * <dasd> : autodetect|probeonly|<devices>(,<devices>)*
65 */
66
67int dasd_probeonly = 0; /* is true, when probeonly mode is active */
68int dasd_autodetect = 0; /* is true, when autodetection is active */
Horst Hummel40545572006-06-29 15:08:18 +020069int dasd_nopav = 0; /* is true, when PAV is disabled */
70EXPORT_SYMBOL_GPL(dasd_nopav);
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +010071int dasd_nofcx; /* disable High Performance Ficon */
72EXPORT_SYMBOL_GPL(dasd_nofcx);
Linus Torvalds1da177e2005-04-16 15:20:36 -070073
74/*
75 * char *dasd[] is intended to hold the ranges supplied by the dasd= statement
76 * it is named 'dasd' to directly be filled by insmod with the comma separated
77 * strings when running as a module.
78 */
79static char *dasd[256];
Peter Oberparleiter3b126932014-08-20 15:35:44 +020080module_param_array(dasd, charp, NULL, S_IRUGO);
Rusty Russell8d3b33f2006-03-25 03:07:05 -080081
Linus Torvalds1da177e2005-04-16 15:20:36 -070082/*
Horst Hummeld0710c72006-08-10 15:45:16 +020083 * Single spinlock to protect devmap and servermap structures and lists.
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 */
85static DEFINE_SPINLOCK(dasd_devmap_lock);
86
87/*
88 * Hash lists for devmap structures.
89 */
90static struct list_head dasd_hashlists[256];
91int dasd_max_devindex;
92
Cornelia Huck69f90f62008-05-15 16:52:34 +020093static struct dasd_devmap *dasd_add_busid(const char *, int);
Linus Torvalds1da177e2005-04-16 15:20:36 -070094
95static inline int
Cornelia Huck69f90f62008-05-15 16:52:34 +020096dasd_hash_busid(const char *bus_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -070097{
98 int hash, i;
99
100 hash = 0;
Kay Sievers98df67b2008-12-25 13:38:55 +0100101 for (i = 0; (i < DASD_BUS_ID_SIZE) && *bus_id; i++, bus_id++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 hash += *bus_id;
103 return hash & 0xff;
104}
105
106#ifndef MODULE
107/*
108 * The parameter parsing functions for builtin-drivers are called
109 * before kmalloc works. Store the pointers to the parameters strings
110 * into dasd[] for later processing.
111 */
112static int __init
113dasd_call_setup(char *str)
114{
115 static int count = 0;
116
117 if (count < 256)
118 dasd[count++] = str;
119 return 1;
120}
121
122__setup ("dasd=", dasd_call_setup);
123#endif /* #ifndef MODULE */
124
Peter Oberparleiter7039d3a2007-04-27 16:01:48 +0200125#define DASD_IPLDEV "ipldev"
126
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127/*
128 * Read a device busid/devno from a string.
129 */
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100130static int
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100131
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132dasd_busid(char **str, int *id0, int *id1, int *devno)
133{
134 int val, old_style;
Horst Hummel138c0142006-06-29 14:58:12 +0200135
Peter Oberparleiter7039d3a2007-04-27 16:01:48 +0200136 /* Interpret ipldev busid */
137 if (strncmp(DASD_IPLDEV, *str, strlen(DASD_IPLDEV)) == 0) {
138 if (ipl_info.type != IPL_TYPE_CCW) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100139 pr_err("The IPL device is not a CCW device\n");
Peter Oberparleiter7039d3a2007-04-27 16:01:48 +0200140 return -EINVAL;
141 }
142 *id0 = 0;
143 *id1 = ipl_info.data.ccw.dev_id.ssid;
144 *devno = ipl_info.data.ccw.dev_id.devno;
145 *str += strlen(DASD_IPLDEV);
146
147 return 0;
148 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 /* check for leading '0x' */
150 old_style = 0;
151 if ((*str)[0] == '0' && (*str)[1] == 'x') {
152 *str += 2;
153 old_style = 1;
154 }
155 if (!isxdigit((*str)[0])) /* We require at least one hex digit */
156 return -EINVAL;
157 val = simple_strtoul(*str, str, 16);
158 if (old_style || (*str)[0] != '.') {
159 *id0 = *id1 = 0;
160 if (val < 0 || val > 0xffff)
161 return -EINVAL;
162 *devno = val;
163 return 0;
164 }
165 /* New style x.y.z busid */
166 if (val < 0 || val > 0xff)
167 return -EINVAL;
168 *id0 = val;
169 (*str)++;
170 if (!isxdigit((*str)[0])) /* We require at least one hex digit */
171 return -EINVAL;
172 val = simple_strtoul(*str, str, 16);
173 if (val < 0 || val > 0xff || (*str)++[0] != '.')
174 return -EINVAL;
175 *id1 = val;
176 if (!isxdigit((*str)[0])) /* We require at least one hex digit */
177 return -EINVAL;
178 val = simple_strtoul(*str, str, 16);
179 if (val < 0 || val > 0xffff)
180 return -EINVAL;
181 *devno = val;
182 return 0;
183}
184
185/*
186 * Read colon separated list of dasd features. Currently there is
187 * only one: "ro" for read-only devices. The default feature set
188 * is empty (value 0).
189 */
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100190static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191dasd_feature_list(char *str, char **endp)
192{
193 int features, len, rc;
194
195 rc = 0;
196 if (*str != '(') {
197 *endp = str;
198 return DASD_FEATURE_DEFAULT;
199 }
200 str++;
201 features = 0;
202
203 while (1) {
Horst Hummel138c0142006-06-29 14:58:12 +0200204 for (len = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 str[len] && str[len] != ':' && str[len] != ')'; len++);
206 if (len == 2 && !strncmp(str, "ro", 2))
207 features |= DASD_FEATURE_READONLY;
208 else if (len == 4 && !strncmp(str, "diag", 4))
209 features |= DASD_FEATURE_USEDIAG;
Stefan Haberlande4dbb0f2011-01-05 12:48:06 +0100210 else if (len == 3 && !strncmp(str, "raw", 3))
211 features |= DASD_FEATURE_USERAW;
Horst Hummel9575bf22006-12-08 15:54:15 +0100212 else if (len == 6 && !strncmp(str, "erplog", 6))
213 features |= DASD_FEATURE_ERPLOG;
Holger Smolinski13de2272009-01-09 12:14:51 +0100214 else if (len == 8 && !strncmp(str, "failfast", 8))
215 features |= DASD_FEATURE_FAILFAST;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 else {
Joe Perchesbaebc702016-03-03 20:49:57 -0800217 pr_warn("%*s is not a supported device option\n",
218 len, str);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 rc = -EINVAL;
220 }
221 str += len;
222 if (*str != ':')
223 break;
224 str++;
225 }
226 if (*str != ')') {
Joe Perchesbaebc702016-03-03 20:49:57 -0800227 pr_warn("A closing parenthesis ')' is missing in the dasd= parameter\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 rc = -EINVAL;
229 } else
230 str++;
231 *endp = str;
232 if (rc != 0)
233 return rc;
234 return features;
235}
236
237/*
238 * Try to match the first element on the comma separated parse string
239 * with one of the known keywords. If a keyword is found, take the approprate
240 * action and return a pointer to the residual string. If the first element
241 * could not be matched to any keyword then return an error code.
242 */
243static char *
244dasd_parse_keyword( char *parsestring ) {
245
246 char *nextcomma, *residual_str;
247 int length;
248
249 nextcomma = strchr(parsestring,',');
250 if (nextcomma) {
251 length = nextcomma - parsestring;
252 residual_str = nextcomma + 1;
253 } else {
254 length = strlen(parsestring);
255 residual_str = parsestring + length;
256 }
Horst Hummel40545572006-06-29 15:08:18 +0200257 if (strncmp("autodetect", parsestring, length) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 dasd_autodetect = 1;
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100259 pr_info("The autodetection mode has been activated\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 return residual_str;
261 }
Horst Hummel40545572006-06-29 15:08:18 +0200262 if (strncmp("probeonly", parsestring, length) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 dasd_probeonly = 1;
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100264 pr_info("The probeonly mode has been activated\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 return residual_str;
266 }
Horst Hummel40545572006-06-29 15:08:18 +0200267 if (strncmp("nopav", parsestring, length) == 0) {
Peter Oberparleiterdcd707b2006-09-20 15:59:52 +0200268 if (MACHINE_IS_VM)
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100269 pr_info("'nopav' is not supported on z/VM\n");
Peter Oberparleiterdcd707b2006-09-20 15:59:52 +0200270 else {
271 dasd_nopav = 1;
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100272 pr_info("PAV support has be deactivated\n");
Peter Oberparleiterdcd707b2006-09-20 15:59:52 +0200273 }
Horst Hummel40545572006-06-29 15:08:18 +0200274 return residual_str;
275 }
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +0100276 if (strncmp("nofcx", parsestring, length) == 0) {
277 dasd_nofcx = 1;
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100278 pr_info("High Performance FICON support has been "
279 "deactivated\n");
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +0100280 return residual_str;
281 }
Horst Hummel40545572006-06-29 15:08:18 +0200282 if (strncmp("fixedbuffers", parsestring, length) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 if (dasd_page_cache)
284 return residual_str;
285 dasd_page_cache =
Heiko Carstens2f6c55f2006-08-16 13:49:27 +0200286 kmem_cache_create("dasd_page_cache", PAGE_SIZE,
287 PAGE_SIZE, SLAB_CACHE_DMA,
Paul Mundt20c2df82007-07-20 10:11:58 +0900288 NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 if (!dasd_page_cache)
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100290 DBF_EVENT(DBF_WARNING, "%s", "Failed to create slab, "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 "fixed buffer mode disabled.");
292 else
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100293 DBF_EVENT(DBF_INFO, "%s",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 "turning on fixed buffer mode");
295 return residual_str;
296 }
297 return ERR_PTR(-EINVAL);
298}
299
300/*
301 * Try to interprete the first element on the comma separated parse string
302 * as a device number or a range of devices. If the interpretation is
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300303 * successful, create the matching dasd_devmap entries and return a pointer
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 * to the residual string.
305 * If interpretation fails or in case of an error, return an error code.
306 */
307static char *
308dasd_parse_range( char *parsestring ) {
309
310 struct dasd_devmap *devmap;
311 int from, from_id0, from_id1;
312 int to, to_id0, to_id1;
313 int features, rc;
Kay Sievers98df67b2008-12-25 13:38:55 +0100314 char bus_id[DASD_BUS_ID_SIZE+1], *str;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315
316 str = parsestring;
317 rc = dasd_busid(&str, &from_id0, &from_id1, &from);
318 if (rc == 0) {
319 to = from;
320 to_id0 = from_id0;
321 to_id1 = from_id1;
322 if (*str == '-') {
323 str++;
324 rc = dasd_busid(&str, &to_id0, &to_id1, &to);
325 }
326 }
327 if (rc == 0 &&
328 (from_id0 != to_id0 || from_id1 != to_id1 || from > to))
329 rc = -EINVAL;
330 if (rc) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100331 pr_err("%s is not a valid device range\n", parsestring);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 return ERR_PTR(rc);
333 }
334 features = dasd_feature_list(str, &str);
335 if (features < 0)
336 return ERR_PTR(-EINVAL);
Horst Hummel40545572006-06-29 15:08:18 +0200337 /* each device in dasd= parameter should be set initially online */
338 features |= DASD_FEATURE_INITIAL_ONLINE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 while (from <= to) {
340 sprintf(bus_id, "%01x.%01x.%04x",
341 from_id0, from_id1, from++);
342 devmap = dasd_add_busid(bus_id, features);
343 if (IS_ERR(devmap))
344 return (char *)devmap;
345 }
346 if (*str == ',')
347 return str + 1;
348 if (*str == '\0')
349 return str;
Joe Perchesbaebc702016-03-03 20:49:57 -0800350 pr_warn("The dasd= parameter value %s has an invalid ending\n", str);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 return ERR_PTR(-EINVAL);
352}
353
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100354static char *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355dasd_parse_next_element( char *parsestring ) {
356 char * residual_str;
357 residual_str = dasd_parse_keyword(parsestring);
358 if (!IS_ERR(residual_str))
359 return residual_str;
360 residual_str = dasd_parse_range(parsestring);
361 return residual_str;
362}
363
364/*
365 * Parse parameters stored in dasd[]
366 * The 'dasd=...' parameter allows to specify a comma separated list of
367 * keywords and device ranges. When the dasd driver is build into the kernel,
368 * the complete list will be stored as one element of the dasd[] array.
369 * When the dasd driver is build as a module, then the list is broken into
370 * it's elements and each dasd[] entry contains one element.
371 */
372int
373dasd_parse(void)
374{
375 int rc, i;
376 char *parsestring;
377
378 rc = 0;
379 for (i = 0; i < 256; i++) {
380 if (dasd[i] == NULL)
381 break;
382 parsestring = dasd[i];
383 /* loop over the comma separated list in the parsestring */
384 while (*parsestring) {
385 parsestring = dasd_parse_next_element(parsestring);
386 if(IS_ERR(parsestring)) {
387 rc = PTR_ERR(parsestring);
388 break;
389 }
390 }
391 if (rc) {
392 DBF_EVENT(DBF_ALERT, "%s", "invalid range found");
393 break;
394 }
395 }
396 return rc;
397}
398
399/*
400 * Add a devmap for the device specified by busid. It is possible that
401 * the devmap already exists (dasd= parameter). The order of the devices
402 * added through this function will define the kdevs for the individual
Horst Hummel138c0142006-06-29 14:58:12 +0200403 * devices.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 */
405static struct dasd_devmap *
Cornelia Huck69f90f62008-05-15 16:52:34 +0200406dasd_add_busid(const char *bus_id, int features)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407{
408 struct dasd_devmap *devmap, *new, *tmp;
409 int hash;
410
Zhang Yanfei006485d2013-03-12 13:18:47 +0800411 new = kzalloc(sizeof(struct dasd_devmap), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 if (!new)
413 return ERR_PTR(-ENOMEM);
414 spin_lock(&dasd_devmap_lock);
Heiko Carstensd2c993d2006-07-12 16:41:55 +0200415 devmap = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 hash = dasd_hash_busid(bus_id);
417 list_for_each_entry(tmp, &dasd_hashlists[hash], list)
Kay Sievers98df67b2008-12-25 13:38:55 +0100418 if (strncmp(tmp->bus_id, bus_id, DASD_BUS_ID_SIZE) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 devmap = tmp;
420 break;
421 }
422 if (!devmap) {
423 /* This bus_id is new. */
424 new->devindex = dasd_max_devindex++;
Kay Sievers98df67b2008-12-25 13:38:55 +0100425 strncpy(new->bus_id, bus_id, DASD_BUS_ID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 new->features = features;
Heiko Carstensd2c993d2006-07-12 16:41:55 +0200427 new->device = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 list_add(&new->list, &dasd_hashlists[hash]);
429 devmap = new;
Heiko Carstensd2c993d2006-07-12 16:41:55 +0200430 new = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 }
432 spin_unlock(&dasd_devmap_lock);
Jesper Juhl17fd6822005-11-07 01:01:30 -0800433 kfree(new);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 return devmap;
435}
436
437/*
438 * Find devmap for device with given bus_id.
439 */
440static struct dasd_devmap *
Cornelia Huck69f90f62008-05-15 16:52:34 +0200441dasd_find_busid(const char *bus_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442{
443 struct dasd_devmap *devmap, *tmp;
444 int hash;
445
446 spin_lock(&dasd_devmap_lock);
447 devmap = ERR_PTR(-ENODEV);
448 hash = dasd_hash_busid(bus_id);
449 list_for_each_entry(tmp, &dasd_hashlists[hash], list) {
Kay Sievers98df67b2008-12-25 13:38:55 +0100450 if (strncmp(tmp->bus_id, bus_id, DASD_BUS_ID_SIZE) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 devmap = tmp;
452 break;
453 }
454 }
455 spin_unlock(&dasd_devmap_lock);
456 return devmap;
457}
458
459/*
460 * Check if busid has been added to the list of dasd ranges.
461 */
462int
Cornelia Huck69f90f62008-05-15 16:52:34 +0200463dasd_busid_known(const char *bus_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464{
465 return IS_ERR(dasd_find_busid(bus_id)) ? -ENOENT : 0;
466}
467
468/*
469 * Forget all about the device numbers added so far.
470 * This may only be called at module unload or system shutdown.
471 */
472static void
473dasd_forget_ranges(void)
474{
475 struct dasd_devmap *devmap, *n;
476 int i;
477
478 spin_lock(&dasd_devmap_lock);
479 for (i = 0; i < 256; i++) {
480 list_for_each_entry_safe(devmap, n, &dasd_hashlists[i], list) {
Eric Sesterhenn606f4422006-03-26 18:33:07 +0200481 BUG_ON(devmap->device != NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 list_del(&devmap->list);
483 kfree(devmap);
484 }
485 }
486 spin_unlock(&dasd_devmap_lock);
487}
488
489/*
490 * Find the device struct by its device index.
491 */
492struct dasd_device *
493dasd_device_from_devindex(int devindex)
494{
495 struct dasd_devmap *devmap, *tmp;
496 struct dasd_device *device;
497 int i;
498
499 spin_lock(&dasd_devmap_lock);
Heiko Carstensd2c993d2006-07-12 16:41:55 +0200500 devmap = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 for (i = 0; (i < 256) && !devmap; i++)
502 list_for_each_entry(tmp, &dasd_hashlists[i], list)
503 if (tmp->devindex == devindex) {
504 /* Found the devmap for the device. */
505 devmap = tmp;
506 break;
507 }
508 if (devmap && devmap->device) {
509 device = devmap->device;
510 dasd_get_device(device);
511 } else
512 device = ERR_PTR(-ENODEV);
513 spin_unlock(&dasd_devmap_lock);
514 return device;
515}
516
517/*
518 * Return devmap for cdev. If no devmap exists yet, create one and
519 * connect it to the cdev.
520 */
521static struct dasd_devmap *
522dasd_devmap_from_cdev(struct ccw_device *cdev)
523{
524 struct dasd_devmap *devmap;
525
Kay Sievers2a0217d2008-10-10 21:33:09 +0200526 devmap = dasd_find_busid(dev_name(&cdev->dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 if (IS_ERR(devmap))
Kay Sievers2a0217d2008-10-10 21:33:09 +0200528 devmap = dasd_add_busid(dev_name(&cdev->dev),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 DASD_FEATURE_DEFAULT);
530 return devmap;
531}
532
533/*
534 * Create a dasd device structure for cdev.
535 */
536struct dasd_device *
537dasd_create_device(struct ccw_device *cdev)
538{
539 struct dasd_devmap *devmap;
540 struct dasd_device *device;
Martin Schwidefskya00bfd72006-09-20 15:59:05 +0200541 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 int rc;
543
544 devmap = dasd_devmap_from_cdev(cdev);
545 if (IS_ERR(devmap))
546 return (void *) devmap;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547
548 device = dasd_alloc_device();
549 if (IS_ERR(device))
550 return device;
Martin Schwidefskya00bfd72006-09-20 15:59:05 +0200551 atomic_set(&device->ref_count, 3);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552
553 spin_lock(&dasd_devmap_lock);
554 if (!devmap->device) {
555 devmap->device = device;
556 device->devindex = devmap->devindex;
Horst Hummelc6eb7b72005-09-03 15:57:58 -0700557 device->features = devmap->features;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 get_device(&cdev->dev);
559 device->cdev = cdev;
560 rc = 0;
561 } else
562 /* Someone else was faster. */
563 rc = -EBUSY;
564 spin_unlock(&dasd_devmap_lock);
565
566 if (rc) {
567 dasd_free_device(device);
568 return ERR_PTR(rc);
569 }
Martin Schwidefskya00bfd72006-09-20 15:59:05 +0200570
571 spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
Cornelia Huckfaf16aa2008-12-25 13:38:52 +0100572 dev_set_drvdata(&cdev->dev, device);
Martin Schwidefskya00bfd72006-09-20 15:59:05 +0200573 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
574
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 return device;
576}
577
578/*
579 * Wait queue for dasd_delete_device waits.
580 */
581static DECLARE_WAIT_QUEUE_HEAD(dasd_delete_wq);
582
583/*
584 * Remove a dasd device structure. The passed referenced
585 * is destroyed.
586 */
587void
588dasd_delete_device(struct dasd_device *device)
589{
590 struct ccw_device *cdev;
591 struct dasd_devmap *devmap;
Martin Schwidefskya00bfd72006-09-20 15:59:05 +0200592 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593
594 /* First remove device pointer from devmap. */
Kay Sievers2a0217d2008-10-10 21:33:09 +0200595 devmap = dasd_find_busid(dev_name(&device->cdev->dev));
Eric Sesterhenn606f4422006-03-26 18:33:07 +0200596 BUG_ON(IS_ERR(devmap));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 spin_lock(&dasd_devmap_lock);
598 if (devmap->device != device) {
599 spin_unlock(&dasd_devmap_lock);
600 dasd_put_device(device);
601 return;
602 }
603 devmap->device = NULL;
604 spin_unlock(&dasd_devmap_lock);
605
Martin Schwidefskya00bfd72006-09-20 15:59:05 +0200606 /* Disconnect dasd_device structure from ccw_device structure. */
607 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
Cornelia Huckfaf16aa2008-12-25 13:38:52 +0100608 dev_set_drvdata(&device->cdev->dev, NULL);
Martin Schwidefskya00bfd72006-09-20 15:59:05 +0200609 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
610
611 /*
612 * Drop ref_count by 3, one for the devmap reference, one for
613 * the cdev reference and one for the passed reference.
614 */
615 atomic_sub(3, &device->ref_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616
617 /* Wait for reference counter to drop to zero. */
618 wait_event(dasd_delete_wq, atomic_read(&device->ref_count) == 0);
619
Stefan Haberlandc020d722016-09-20 10:42:38 +0200620 dasd_generic_free_discipline(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 /* Disconnect dasd_device structure from ccw_device structure. */
622 cdev = device->cdev;
623 device->cdev = NULL;
624
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 /* Put ccw_device structure. */
626 put_device(&cdev->dev);
627
628 /* Now the device structure can be freed. */
629 dasd_free_device(device);
630}
631
632/*
633 * Reference counter dropped to zero. Wake up waiter
634 * in dasd_delete_device.
635 */
636void
637dasd_put_device_wake(struct dasd_device *device)
638{
639 wake_up(&dasd_delete_wq);
640}
Stefan Weinhubera4d26c62011-01-05 12:48:03 +0100641EXPORT_SYMBOL_GPL(dasd_put_device_wake);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642
643/*
644 * Return dasd_device structure associated with cdev.
Martin Schwidefskya00bfd72006-09-20 15:59:05 +0200645 * This function needs to be called with the ccw device
646 * lock held. It can be used from interrupt context.
647 */
648struct dasd_device *
649dasd_device_from_cdev_locked(struct ccw_device *cdev)
650{
Cornelia Huckfaf16aa2008-12-25 13:38:52 +0100651 struct dasd_device *device = dev_get_drvdata(&cdev->dev);
Martin Schwidefskya00bfd72006-09-20 15:59:05 +0200652
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 Torvalds1da177e2005-04-16 15:20:36 -0700661 */
662struct dasd_device *
663dasd_device_from_cdev(struct ccw_device *cdev)
664{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 struct dasd_device *device;
Martin Schwidefskya00bfd72006-09-20 15:59:05 +0200666 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667
Martin Schwidefskya00bfd72006-09-20 15:59:05 +0200668 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 Torvalds1da177e2005-04-16 15:20:36 -0700671 return device;
672}
673
Stefan Weinhuber65f8da42011-04-20 10:15:30 +0200674void dasd_add_link_to_gendisk(struct gendisk *gdp, struct dasd_device *device)
675{
676 struct dasd_devmap *devmap;
677
678 devmap = dasd_find_busid(dev_name(&device->cdev->dev));
679 if (IS_ERR(devmap))
680 return;
681 spin_lock(&dasd_devmap_lock);
682 gdp->private_data = devmap;
683 spin_unlock(&dasd_devmap_lock);
684}
685
686struct dasd_device *dasd_device_from_gendisk(struct gendisk *gdp)
687{
688 struct dasd_device *device;
689 struct dasd_devmap *devmap;
690
691 if (!gdp->private_data)
692 return NULL;
693 device = NULL;
694 spin_lock(&dasd_devmap_lock);
695 devmap = gdp->private_data;
696 if (devmap && devmap->device) {
697 device = devmap->device;
698 dasd_get_device(device);
699 }
700 spin_unlock(&dasd_devmap_lock);
701 return device;
702}
703
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704/*
705 * SECTION: files in sysfs
706 */
707
708/*
Holger Smolinski13de2272009-01-09 12:14:51 +0100709 * failfast controls the behaviour, if no path is available
710 */
711static ssize_t dasd_ff_show(struct device *dev, struct device_attribute *attr,
712 char *buf)
713{
714 struct dasd_devmap *devmap;
715 int ff_flag;
716
Cornelia Huckca0b4b72009-02-11 10:37:30 +0100717 devmap = dasd_find_busid(dev_name(dev));
Holger Smolinski13de2272009-01-09 12:14:51 +0100718 if (!IS_ERR(devmap))
719 ff_flag = (devmap->features & DASD_FEATURE_FAILFAST) != 0;
720 else
721 ff_flag = (DASD_FEATURE_DEFAULT & DASD_FEATURE_FAILFAST) != 0;
722 return snprintf(buf, PAGE_SIZE, ff_flag ? "1\n" : "0\n");
723}
724
725static ssize_t dasd_ff_store(struct device *dev, struct device_attribute *attr,
726 const char *buf, size_t count)
727{
728 struct dasd_devmap *devmap;
729 int val;
730 char *endp;
731
732 devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
733 if (IS_ERR(devmap))
734 return PTR_ERR(devmap);
735
736 val = simple_strtoul(buf, &endp, 0);
737 if (((endp + 1) < (buf + count)) || (val > 1))
738 return -EINVAL;
739
740 spin_lock(&dasd_devmap_lock);
741 if (val)
742 devmap->features |= DASD_FEATURE_FAILFAST;
743 else
744 devmap->features &= ~DASD_FEATURE_FAILFAST;
745 if (devmap->device)
746 devmap->device->features = devmap->features;
747 spin_unlock(&dasd_devmap_lock);
748 return count;
749}
750
751static DEVICE_ATTR(failfast, 0644, dasd_ff_show, dasd_ff_store);
752
753/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754 * readonly controls the readonly status of a dasd
755 */
756static ssize_t
Yani Ioannoue404e272005-05-17 06:42:58 -0400757dasd_ro_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758{
759 struct dasd_devmap *devmap;
760 int ro_flag;
761
Kay Sievers2a0217d2008-10-10 21:33:09 +0200762 devmap = dasd_find_busid(dev_name(dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763 if (!IS_ERR(devmap))
764 ro_flag = (devmap->features & DASD_FEATURE_READONLY) != 0;
765 else
766 ro_flag = (DASD_FEATURE_DEFAULT & DASD_FEATURE_READONLY) != 0;
767 return snprintf(buf, PAGE_SIZE, ro_flag ? "1\n" : "0\n");
768}
769
770static ssize_t
Horst Hummel138c0142006-06-29 14:58:12 +0200771dasd_ro_store(struct device *dev, struct device_attribute *attr,
772 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773{
774 struct dasd_devmap *devmap;
Stefan Weinhuber33b62a32010-03-08 12:26:24 +0100775 struct dasd_device *device;
Horst Hummel01376f42006-12-04 15:39:50 +0100776 int val;
777 char *endp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778
779 devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
780 if (IS_ERR(devmap))
781 return PTR_ERR(devmap);
Horst Hummel01376f42006-12-04 15:39:50 +0100782
783 val = simple_strtoul(buf, &endp, 0);
784 if (((endp + 1) < (buf + count)) || (val > 1))
785 return -EINVAL;
786
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787 spin_lock(&dasd_devmap_lock);
Horst Hummel01376f42006-12-04 15:39:50 +0100788 if (val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789 devmap->features |= DASD_FEATURE_READONLY;
790 else
791 devmap->features &= ~DASD_FEATURE_READONLY;
Stefan Weinhuber33b62a32010-03-08 12:26:24 +0100792 device = devmap->device;
793 if (device) {
794 device->features = devmap->features;
795 val = val || test_bit(DASD_FLAG_DEVICE_RO, &device->flags);
796 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797 spin_unlock(&dasd_devmap_lock);
Stefan Weinhuber33b62a32010-03-08 12:26:24 +0100798 if (device && device->block && device->block->gdp)
799 set_disk_ro(device->block->gdp, val);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800 return count;
801}
802
803static DEVICE_ATTR(readonly, 0644, dasd_ro_show, dasd_ro_store);
Horst Hummel9575bf22006-12-08 15:54:15 +0100804/*
805 * erplog controls the logging of ERP related data
806 * (e.g. failing channel programs).
807 */
808static ssize_t
809dasd_erplog_show(struct device *dev, struct device_attribute *attr, char *buf)
810{
811 struct dasd_devmap *devmap;
812 int erplog;
813
Kay Sievers2a0217d2008-10-10 21:33:09 +0200814 devmap = dasd_find_busid(dev_name(dev));
Horst Hummel9575bf22006-12-08 15:54:15 +0100815 if (!IS_ERR(devmap))
816 erplog = (devmap->features & DASD_FEATURE_ERPLOG) != 0;
817 else
818 erplog = (DASD_FEATURE_DEFAULT & DASD_FEATURE_ERPLOG) != 0;
819 return snprintf(buf, PAGE_SIZE, erplog ? "1\n" : "0\n");
820}
821
822static ssize_t
823dasd_erplog_store(struct device *dev, struct device_attribute *attr,
824 const char *buf, size_t count)
825{
826 struct dasd_devmap *devmap;
827 int val;
828 char *endp;
829
830 devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
831 if (IS_ERR(devmap))
832 return PTR_ERR(devmap);
833
834 val = simple_strtoul(buf, &endp, 0);
835 if (((endp + 1) < (buf + count)) || (val > 1))
836 return -EINVAL;
837
838 spin_lock(&dasd_devmap_lock);
839 if (val)
840 devmap->features |= DASD_FEATURE_ERPLOG;
841 else
842 devmap->features &= ~DASD_FEATURE_ERPLOG;
843 if (devmap->device)
844 devmap->device->features = devmap->features;
845 spin_unlock(&dasd_devmap_lock);
846 return count;
847}
848
849static DEVICE_ATTR(erplog, 0644, dasd_erplog_show, dasd_erplog_store);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850
851/*
852 * use_diag controls whether the driver should use diag rather than ssch
853 * to talk to the device
854 */
Horst Hummel138c0142006-06-29 14:58:12 +0200855static ssize_t
Yani Ioannoue404e272005-05-17 06:42:58 -0400856dasd_use_diag_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857{
858 struct dasd_devmap *devmap;
859 int use_diag;
860
Kay Sievers2a0217d2008-10-10 21:33:09 +0200861 devmap = dasd_find_busid(dev_name(dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 if (!IS_ERR(devmap))
863 use_diag = (devmap->features & DASD_FEATURE_USEDIAG) != 0;
864 else
865 use_diag = (DASD_FEATURE_DEFAULT & DASD_FEATURE_USEDIAG) != 0;
866 return sprintf(buf, use_diag ? "1\n" : "0\n");
867}
868
869static ssize_t
Horst Hummel138c0142006-06-29 14:58:12 +0200870dasd_use_diag_store(struct device *dev, struct device_attribute *attr,
871 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872{
873 struct dasd_devmap *devmap;
874 ssize_t rc;
Horst Hummel01376f42006-12-04 15:39:50 +0100875 int val;
876 char *endp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877
878 devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
879 if (IS_ERR(devmap))
880 return PTR_ERR(devmap);
Horst Hummel01376f42006-12-04 15:39:50 +0100881
882 val = simple_strtoul(buf, &endp, 0);
883 if (((endp + 1) < (buf + count)) || (val > 1))
884 return -EINVAL;
885
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886 spin_lock(&dasd_devmap_lock);
887 /* Changing diag discipline flag is only allowed in offline state. */
888 rc = count;
Stefan Haberlande4dbb0f2011-01-05 12:48:06 +0100889 if (!devmap->device && !(devmap->features & DASD_FEATURE_USERAW)) {
Horst Hummel01376f42006-12-04 15:39:50 +0100890 if (val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891 devmap->features |= DASD_FEATURE_USEDIAG;
892 else
893 devmap->features &= ~DASD_FEATURE_USEDIAG;
894 } else
895 rc = -EPERM;
896 spin_unlock(&dasd_devmap_lock);
897 return rc;
898}
899
Horst Hummel138c0142006-06-29 14:58:12 +0200900static DEVICE_ATTR(use_diag, 0644, dasd_use_diag_show, dasd_use_diag_store);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901
Stefan Haberlande4dbb0f2011-01-05 12:48:06 +0100902/*
903 * use_raw controls whether the driver should give access to raw eckd data or
904 * operate in standard mode
905 */
906static ssize_t
907dasd_use_raw_show(struct device *dev, struct device_attribute *attr, char *buf)
908{
909 struct dasd_devmap *devmap;
910 int use_raw;
911
912 devmap = dasd_find_busid(dev_name(dev));
913 if (!IS_ERR(devmap))
914 use_raw = (devmap->features & DASD_FEATURE_USERAW) != 0;
915 else
916 use_raw = (DASD_FEATURE_DEFAULT & DASD_FEATURE_USERAW) != 0;
917 return sprintf(buf, use_raw ? "1\n" : "0\n");
918}
919
920static ssize_t
921dasd_use_raw_store(struct device *dev, struct device_attribute *attr,
922 const char *buf, size_t count)
923{
924 struct dasd_devmap *devmap;
925 ssize_t rc;
926 unsigned long val;
927
928 devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
929 if (IS_ERR(devmap))
930 return PTR_ERR(devmap);
931
Jingoo Han01787222013-07-22 10:18:15 +0900932 if ((kstrtoul(buf, 10, &val) != 0) || val > 1)
Stefan Haberlande4dbb0f2011-01-05 12:48:06 +0100933 return -EINVAL;
934
935 spin_lock(&dasd_devmap_lock);
936 /* Changing diag discipline flag is only allowed in offline state. */
937 rc = count;
938 if (!devmap->device && !(devmap->features & DASD_FEATURE_USEDIAG)) {
939 if (val)
940 devmap->features |= DASD_FEATURE_USERAW;
941 else
942 devmap->features &= ~DASD_FEATURE_USERAW;
943 } else
944 rc = -EPERM;
945 spin_unlock(&dasd_devmap_lock);
946 return rc;
947}
948
949static DEVICE_ATTR(raw_track_access, 0644, dasd_use_raw_show,
950 dasd_use_raw_store);
951
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952static ssize_t
Stefan Haberlandd07dc5d2012-11-28 13:43:38 +0100953dasd_safe_offline_store(struct device *dev, struct device_attribute *attr,
954 const char *buf, size_t count)
955{
956 struct ccw_device *cdev = to_ccwdev(dev);
957 struct dasd_device *device;
958 int rc;
959
960 device = dasd_device_from_cdev(cdev);
961 if (IS_ERR(device)) {
962 rc = PTR_ERR(device);
963 goto out;
964 }
965
966 if (test_bit(DASD_FLAG_OFFLINE, &device->flags) ||
967 test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
968 /* Already doing offline processing */
969 dasd_put_device(device);
970 rc = -EBUSY;
971 goto out;
972 }
973
974 set_bit(DASD_FLAG_SAFE_OFFLINE, &device->flags);
975 dasd_put_device(device);
976
977 rc = ccw_device_set_offline(cdev);
978
979out:
980 return rc ? rc : count;
981}
982
983static DEVICE_ATTR(safe_offline, 0200, NULL, dasd_safe_offline_store);
984
985static ssize_t
Stefan Haberland5a3b7b12016-03-18 09:42:13 +0100986dasd_access_show(struct device *dev, struct device_attribute *attr,
987 char *buf)
988{
989 struct ccw_device *cdev = to_ccwdev(dev);
990 struct dasd_device *device;
991 int count;
992
993 device = dasd_device_from_cdev(cdev);
994 if (IS_ERR(device))
995 return PTR_ERR(device);
996
997 if (device->discipline->host_access_count)
998 count = device->discipline->host_access_count(device);
999 else
1000 count = -EOPNOTSUPP;
1001
1002 dasd_put_device(device);
1003 if (count < 0)
1004 return count;
1005
1006 return sprintf(buf, "%d\n", count);
1007}
1008
1009static DEVICE_ATTR(host_access_count, 0444, dasd_access_show, NULL);
1010
1011static ssize_t
Horst Hummel138c0142006-06-29 14:58:12 +02001012dasd_discipline_show(struct device *dev, struct device_attribute *attr,
1013 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014{
Martin Schwidefskya00bfd72006-09-20 15:59:05 +02001015 struct dasd_device *device;
1016 ssize_t len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017
Martin Schwidefskya00bfd72006-09-20 15:59:05 +02001018 device = dasd_device_from_cdev(to_ccwdev(dev));
Stefan Haberland589c74d2010-02-26 22:37:47 +01001019 if (IS_ERR(device))
1020 goto out;
1021 else if (!device->discipline) {
1022 dasd_put_device(device);
1023 goto out;
1024 } else {
Martin Schwidefskya00bfd72006-09-20 15:59:05 +02001025 len = snprintf(buf, PAGE_SIZE, "%s\n",
1026 device->discipline->name);
1027 dasd_put_device(device);
Stefan Haberland589c74d2010-02-26 22:37:47 +01001028 return len;
1029 }
1030out:
1031 len = snprintf(buf, PAGE_SIZE, "none\n");
Martin Schwidefskya00bfd72006-09-20 15:59:05 +02001032 return len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033}
1034
1035static DEVICE_ATTR(discipline, 0444, dasd_discipline_show, NULL);
1036
Horst Hummel3d052592006-04-27 18:40:28 -07001037static ssize_t
Horst Hummel4dfd5c42007-04-27 16:01:47 +02001038dasd_device_status_show(struct device *dev, struct device_attribute *attr,
1039 char *buf)
1040{
1041 struct dasd_device *device;
1042 ssize_t len;
1043
1044 device = dasd_device_from_cdev(to_ccwdev(dev));
1045 if (!IS_ERR(device)) {
1046 switch (device->state) {
1047 case DASD_STATE_NEW:
1048 len = snprintf(buf, PAGE_SIZE, "new\n");
1049 break;
1050 case DASD_STATE_KNOWN:
1051 len = snprintf(buf, PAGE_SIZE, "detected\n");
1052 break;
1053 case DASD_STATE_BASIC:
1054 len = snprintf(buf, PAGE_SIZE, "basic\n");
1055 break;
1056 case DASD_STATE_UNFMT:
1057 len = snprintf(buf, PAGE_SIZE, "unformatted\n");
1058 break;
1059 case DASD_STATE_READY:
1060 len = snprintf(buf, PAGE_SIZE, "ready\n");
1061 break;
1062 case DASD_STATE_ONLINE:
1063 len = snprintf(buf, PAGE_SIZE, "online\n");
1064 break;
1065 default:
1066 len = snprintf(buf, PAGE_SIZE, "no stat\n");
1067 break;
1068 }
1069 dasd_put_device(device);
1070 } else
1071 len = snprintf(buf, PAGE_SIZE, "unknown\n");
1072 return len;
1073}
1074
1075static DEVICE_ATTR(status, 0444, dasd_device_status_show, NULL);
1076
Stefan Haberland2dedf0d2010-05-17 10:00:11 +02001077static ssize_t dasd_alias_show(struct device *dev,
1078 struct device_attribute *attr, char *buf)
Horst Hummel3d052592006-04-27 18:40:28 -07001079{
Stefan Haberland2dedf0d2010-05-17 10:00:11 +02001080 struct dasd_device *device;
1081 struct dasd_uid uid;
Horst Hummel3d052592006-04-27 18:40:28 -07001082
Stefan Haberland2dedf0d2010-05-17 10:00:11 +02001083 device = dasd_device_from_cdev(to_ccwdev(dev));
1084 if (IS_ERR(device))
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001085 return sprintf(buf, "0\n");
Stefan Haberland2dedf0d2010-05-17 10:00:11 +02001086
1087 if (device->discipline && device->discipline->get_uid &&
1088 !device->discipline->get_uid(device, &uid)) {
1089 if (uid.type == UA_BASE_PAV_ALIAS ||
Stefan Haberland0abccf72010-07-19 09:22:36 +02001090 uid.type == UA_HYPER_PAV_ALIAS) {
1091 dasd_put_device(device);
Stefan Haberland2dedf0d2010-05-17 10:00:11 +02001092 return sprintf(buf, "1\n");
Stefan Haberland0abccf72010-07-19 09:22:36 +02001093 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001094 }
Stefan Haberland2dedf0d2010-05-17 10:00:11 +02001095 dasd_put_device(device);
1096
1097 return sprintf(buf, "0\n");
Horst Hummel3d052592006-04-27 18:40:28 -07001098}
1099
1100static DEVICE_ATTR(alias, 0444, dasd_alias_show, NULL);
1101
Stefan Haberland2dedf0d2010-05-17 10:00:11 +02001102static ssize_t dasd_vendor_show(struct device *dev,
1103 struct device_attribute *attr, char *buf)
Horst Hummel3d052592006-04-27 18:40:28 -07001104{
Stefan Haberland2dedf0d2010-05-17 10:00:11 +02001105 struct dasd_device *device;
1106 struct dasd_uid uid;
Horst Hummel3d052592006-04-27 18:40:28 -07001107 char *vendor;
1108
Stefan Haberland2dedf0d2010-05-17 10:00:11 +02001109 device = dasd_device_from_cdev(to_ccwdev(dev));
1110 vendor = "";
1111 if (IS_ERR(device))
1112 return snprintf(buf, PAGE_SIZE, "%s\n", vendor);
1113
1114 if (device->discipline && device->discipline->get_uid &&
1115 !device->discipline->get_uid(device, &uid))
1116 vendor = uid.vendor;
1117
1118 dasd_put_device(device);
Horst Hummel3d052592006-04-27 18:40:28 -07001119
1120 return snprintf(buf, PAGE_SIZE, "%s\n", vendor);
1121}
1122
1123static DEVICE_ATTR(vendor, 0444, dasd_vendor_show, NULL);
1124
1125#define UID_STRLEN ( /* vendor */ 3 + 1 + /* serial */ 14 + 1 +\
Stefan Weinhuber4abb08c2008-08-01 16:39:09 +02001126 /* SSID */ 4 + 1 + /* unit addr */ 2 + 1 +\
1127 /* vduit */ 32 + 1)
Horst Hummel3d052592006-04-27 18:40:28 -07001128
1129static ssize_t
1130dasd_uid_show(struct device *dev, struct device_attribute *attr, char *buf)
1131{
Stefan Haberland2dedf0d2010-05-17 10:00:11 +02001132 struct dasd_device *device;
1133 struct dasd_uid uid;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001134 char uid_string[UID_STRLEN];
1135 char ua_string[3];
Horst Hummel3d052592006-04-27 18:40:28 -07001136
Stefan Haberland2dedf0d2010-05-17 10:00:11 +02001137 device = dasd_device_from_cdev(to_ccwdev(dev));
1138 uid_string[0] = 0;
1139 if (IS_ERR(device))
1140 return snprintf(buf, PAGE_SIZE, "%s\n", uid_string);
1141
1142 if (device->discipline && device->discipline->get_uid &&
1143 !device->discipline->get_uid(device, &uid)) {
1144 switch (uid.type) {
1145 case UA_BASE_DEVICE:
1146 snprintf(ua_string, sizeof(ua_string), "%02x",
1147 uid.real_unit_addr);
1148 break;
1149 case UA_BASE_PAV_ALIAS:
1150 snprintf(ua_string, sizeof(ua_string), "%02x",
1151 uid.base_unit_addr);
1152 break;
1153 case UA_HYPER_PAV_ALIAS:
1154 snprintf(ua_string, sizeof(ua_string), "xx");
1155 break;
1156 default:
1157 /* should not happen, treat like base device */
1158 snprintf(ua_string, sizeof(ua_string), "%02x",
1159 uid.real_unit_addr);
1160 break;
1161 }
1162
1163 if (strlen(uid.vduit) > 0)
1164 snprintf(uid_string, sizeof(uid_string),
1165 "%s.%s.%04x.%s.%s",
1166 uid.vendor, uid.serial, uid.ssid, ua_string,
1167 uid.vduit);
1168 else
1169 snprintf(uid_string, sizeof(uid_string),
1170 "%s.%s.%04x.%s",
1171 uid.vendor, uid.serial, uid.ssid, ua_string);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001172 }
Stefan Haberland2dedf0d2010-05-17 10:00:11 +02001173 dasd_put_device(device);
1174
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001175 return snprintf(buf, PAGE_SIZE, "%s\n", uid_string);
Horst Hummel3d052592006-04-27 18:40:28 -07001176}
Horst Hummel3d052592006-04-27 18:40:28 -07001177static DEVICE_ATTR(uid, 0444, dasd_uid_show, NULL);
1178
Stefan Weinhuber20c64462006-03-24 03:15:25 -08001179/*
1180 * extended error-reporting
1181 */
1182static ssize_t
1183dasd_eer_show(struct device *dev, struct device_attribute *attr, char *buf)
1184{
1185 struct dasd_devmap *devmap;
1186 int eer_flag;
1187
Kay Sievers2a0217d2008-10-10 21:33:09 +02001188 devmap = dasd_find_busid(dev_name(dev));
Stefan Weinhuber20c64462006-03-24 03:15:25 -08001189 if (!IS_ERR(devmap) && devmap->device)
1190 eer_flag = dasd_eer_enabled(devmap->device);
1191 else
1192 eer_flag = 0;
1193 return snprintf(buf, PAGE_SIZE, eer_flag ? "1\n" : "0\n");
1194}
1195
1196static ssize_t
1197dasd_eer_store(struct device *dev, struct device_attribute *attr,
1198 const char *buf, size_t count)
1199{
1200 struct dasd_devmap *devmap;
Horst Hummel01376f42006-12-04 15:39:50 +01001201 int val, rc;
1202 char *endp;
Stefan Weinhuber20c64462006-03-24 03:15:25 -08001203
1204 devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
1205 if (IS_ERR(devmap))
1206 return PTR_ERR(devmap);
1207 if (!devmap->device)
Horst Hummel01376f42006-12-04 15:39:50 +01001208 return -ENODEV;
1209
1210 val = simple_strtoul(buf, &endp, 0);
1211 if (((endp + 1) < (buf + count)) || (val > 1))
1212 return -EINVAL;
1213
Horst Hummel645c98c2006-12-04 15:40:18 +01001214 if (val) {
Stefan Weinhuber20c64462006-03-24 03:15:25 -08001215 rc = dasd_eer_enable(devmap->device);
Horst Hummel645c98c2006-12-04 15:40:18 +01001216 if (rc)
1217 return rc;
1218 } else
Stefan Weinhuber20c64462006-03-24 03:15:25 -08001219 dasd_eer_disable(devmap->device);
Horst Hummel645c98c2006-12-04 15:40:18 +01001220 return count;
Stefan Weinhuber20c64462006-03-24 03:15:25 -08001221}
1222
1223static DEVICE_ATTR(eer_enabled, 0644, dasd_eer_show, dasd_eer_store);
1224
Stefan Haberland7c8faa82010-08-09 18:13:00 +02001225/*
1226 * expiration time for default requests
1227 */
1228static ssize_t
1229dasd_expires_show(struct device *dev, struct device_attribute *attr, char *buf)
1230{
1231 struct dasd_device *device;
1232 int len;
1233
1234 device = dasd_device_from_cdev(to_ccwdev(dev));
1235 if (IS_ERR(device))
1236 return -ENODEV;
1237 len = snprintf(buf, PAGE_SIZE, "%lu\n", device->default_expires);
1238 dasd_put_device(device);
1239 return len;
1240}
1241
1242static ssize_t
1243dasd_expires_store(struct device *dev, struct device_attribute *attr,
1244 const char *buf, size_t count)
1245{
1246 struct dasd_device *device;
1247 unsigned long val;
1248
1249 device = dasd_device_from_cdev(to_ccwdev(dev));
1250 if (IS_ERR(device))
1251 return -ENODEV;
1252
Jingoo Han01787222013-07-22 10:18:15 +09001253 if ((kstrtoul(buf, 10, &val) != 0) ||
Stefan Haberland7c8faa82010-08-09 18:13:00 +02001254 (val > DASD_EXPIRES_MAX) || val == 0) {
1255 dasd_put_device(device);
1256 return -EINVAL;
1257 }
1258
1259 if (val)
1260 device->default_expires = val;
1261
1262 dasd_put_device(device);
1263 return count;
1264}
1265
1266static DEVICE_ATTR(expires, 0644, dasd_expires_show, dasd_expires_store);
1267
Hannes Reinecke1f1ee9a2013-01-30 09:26:12 +00001268static ssize_t
1269dasd_retries_show(struct device *dev, struct device_attribute *attr, char *buf)
1270{
1271 struct dasd_device *device;
1272 int len;
1273
1274 device = dasd_device_from_cdev(to_ccwdev(dev));
1275 if (IS_ERR(device))
1276 return -ENODEV;
1277 len = snprintf(buf, PAGE_SIZE, "%lu\n", device->default_retries);
1278 dasd_put_device(device);
1279 return len;
1280}
1281
1282static ssize_t
1283dasd_retries_store(struct device *dev, struct device_attribute *attr,
1284 const char *buf, size_t count)
1285{
1286 struct dasd_device *device;
1287 unsigned long val;
1288
1289 device = dasd_device_from_cdev(to_ccwdev(dev));
1290 if (IS_ERR(device))
1291 return -ENODEV;
1292
Jingoo Han01787222013-07-22 10:18:15 +09001293 if ((kstrtoul(buf, 10, &val) != 0) ||
Hannes Reinecke1f1ee9a2013-01-30 09:26:12 +00001294 (val > DASD_RETRIES_MAX)) {
1295 dasd_put_device(device);
1296 return -EINVAL;
1297 }
1298
1299 if (val)
1300 device->default_retries = val;
1301
1302 dasd_put_device(device);
1303 return count;
1304}
1305
1306static DEVICE_ATTR(retries, 0644, dasd_retries_show, dasd_retries_store);
1307
Hannes Reinecke3d71ad32013-01-30 09:26:18 +00001308static ssize_t
1309dasd_timeout_show(struct device *dev, struct device_attribute *attr,
1310 char *buf)
1311{
1312 struct dasd_device *device;
1313 int len;
1314
1315 device = dasd_device_from_cdev(to_ccwdev(dev));
1316 if (IS_ERR(device))
1317 return -ENODEV;
1318 len = snprintf(buf, PAGE_SIZE, "%lu\n", device->blk_timeout);
1319 dasd_put_device(device);
1320 return len;
1321}
1322
1323static ssize_t
1324dasd_timeout_store(struct device *dev, struct device_attribute *attr,
1325 const char *buf, size_t count)
1326{
1327 struct dasd_device *device;
1328 struct request_queue *q;
1329 unsigned long val, flags;
1330
1331 device = dasd_device_from_cdev(to_ccwdev(dev));
1332 if (IS_ERR(device) || !device->block)
1333 return -ENODEV;
1334
Jingoo Han01787222013-07-22 10:18:15 +09001335 if ((kstrtoul(buf, 10, &val) != 0) ||
Hannes Reinecke3d71ad32013-01-30 09:26:18 +00001336 val > UINT_MAX / HZ) {
1337 dasd_put_device(device);
1338 return -EINVAL;
1339 }
1340 q = device->block->request_queue;
1341 if (!q) {
1342 dasd_put_device(device);
1343 return -ENODEV;
1344 }
1345 spin_lock_irqsave(&device->block->request_queue_lock, flags);
1346 if (!val)
1347 blk_queue_rq_timed_out(q, NULL);
1348 else
1349 blk_queue_rq_timed_out(q, dasd_times_out);
1350
1351 device->blk_timeout = val;
1352
1353 blk_queue_rq_timeout(q, device->blk_timeout * HZ);
1354 spin_unlock_irqrestore(&device->block->request_queue_lock, flags);
1355
1356 dasd_put_device(device);
1357 return count;
1358}
1359
1360static DEVICE_ATTR(timeout, 0644,
1361 dasd_timeout_show, dasd_timeout_store);
1362
Stefan Weinhuber5a27e602011-01-05 12:48:04 +01001363static ssize_t dasd_reservation_policy_show(struct device *dev,
1364 struct device_attribute *attr,
1365 char *buf)
1366{
1367 struct dasd_devmap *devmap;
1368 int rc = 0;
1369
1370 devmap = dasd_find_busid(dev_name(dev));
1371 if (IS_ERR(devmap)) {
1372 rc = snprintf(buf, PAGE_SIZE, "ignore\n");
1373 } else {
1374 spin_lock(&dasd_devmap_lock);
1375 if (devmap->features & DASD_FEATURE_FAILONSLCK)
1376 rc = snprintf(buf, PAGE_SIZE, "fail\n");
1377 else
1378 rc = snprintf(buf, PAGE_SIZE, "ignore\n");
1379 spin_unlock(&dasd_devmap_lock);
1380 }
1381 return rc;
1382}
1383
1384static ssize_t dasd_reservation_policy_store(struct device *dev,
1385 struct device_attribute *attr,
1386 const char *buf, size_t count)
1387{
1388 struct dasd_devmap *devmap;
1389 int rc;
1390
1391 devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
1392 if (IS_ERR(devmap))
1393 return PTR_ERR(devmap);
1394 rc = 0;
1395 spin_lock(&dasd_devmap_lock);
1396 if (sysfs_streq("ignore", buf))
1397 devmap->features &= ~DASD_FEATURE_FAILONSLCK;
1398 else if (sysfs_streq("fail", buf))
1399 devmap->features |= DASD_FEATURE_FAILONSLCK;
1400 else
1401 rc = -EINVAL;
1402 if (devmap->device)
1403 devmap->device->features = devmap->features;
1404 spin_unlock(&dasd_devmap_lock);
1405 if (rc)
1406 return rc;
1407 else
1408 return count;
1409}
1410
1411static DEVICE_ATTR(reservation_policy, 0644,
1412 dasd_reservation_policy_show, dasd_reservation_policy_store);
1413
1414static ssize_t dasd_reservation_state_show(struct device *dev,
1415 struct device_attribute *attr,
1416 char *buf)
1417{
1418 struct dasd_device *device;
1419 int rc = 0;
1420
1421 device = dasd_device_from_cdev(to_ccwdev(dev));
1422 if (IS_ERR(device))
1423 return snprintf(buf, PAGE_SIZE, "none\n");
1424
1425 if (test_bit(DASD_FLAG_IS_RESERVED, &device->flags))
1426 rc = snprintf(buf, PAGE_SIZE, "reserved\n");
1427 else if (test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags))
1428 rc = snprintf(buf, PAGE_SIZE, "lost\n");
1429 else
1430 rc = snprintf(buf, PAGE_SIZE, "none\n");
1431 dasd_put_device(device);
1432 return rc;
1433}
1434
1435static ssize_t dasd_reservation_state_store(struct device *dev,
1436 struct device_attribute *attr,
1437 const char *buf, size_t count)
1438{
1439 struct dasd_device *device;
1440 int rc = 0;
1441
1442 device = dasd_device_from_cdev(to_ccwdev(dev));
1443 if (IS_ERR(device))
1444 return -ENODEV;
1445 if (sysfs_streq("reset", buf))
1446 clear_bit(DASD_FLAG_LOCK_STOLEN, &device->flags);
1447 else
1448 rc = -EINVAL;
1449 dasd_put_device(device);
1450
1451 if (rc)
1452 return rc;
1453 else
1454 return count;
1455}
1456
1457static DEVICE_ATTR(last_known_reservation_state, 0644,
1458 dasd_reservation_state_show, dasd_reservation_state_store);
1459
Stefan Haberland5db84402014-10-01 14:39:47 +02001460static ssize_t dasd_pm_show(struct device *dev,
1461 struct device_attribute *attr, char *buf)
1462{
1463 struct dasd_device *device;
1464 u8 opm, nppm, cablepm, cuirpm, hpfpm;
1465
1466 device = dasd_device_from_cdev(to_ccwdev(dev));
1467 if (IS_ERR(device))
1468 return sprintf(buf, "0\n");
1469
1470 opm = device->path_data.opm;
1471 nppm = device->path_data.npm;
1472 cablepm = device->path_data.cablepm;
1473 cuirpm = device->path_data.cuirpm;
1474 hpfpm = device->path_data.hpfpm;
1475 dasd_put_device(device);
1476
1477 return sprintf(buf, "%02x %02x %02x %02x %02x\n", opm, nppm,
1478 cablepm, cuirpm, hpfpm);
1479}
1480
1481static DEVICE_ATTR(path_masks, 0444, dasd_pm_show, NULL);
1482
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483static struct attribute * dasd_attrs[] = {
1484 &dev_attr_readonly.attr,
1485 &dev_attr_discipline.attr,
Horst Hummel4dfd5c42007-04-27 16:01:47 +02001486 &dev_attr_status.attr,
Horst Hummel3d052592006-04-27 18:40:28 -07001487 &dev_attr_alias.attr,
1488 &dev_attr_vendor.attr,
1489 &dev_attr_uid.attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490 &dev_attr_use_diag.attr,
Stefan Haberlande4dbb0f2011-01-05 12:48:06 +01001491 &dev_attr_raw_track_access.attr,
Stefan Weinhuber20c64462006-03-24 03:15:25 -08001492 &dev_attr_eer_enabled.attr,
Horst Hummel9575bf22006-12-08 15:54:15 +01001493 &dev_attr_erplog.attr,
Holger Smolinski13de2272009-01-09 12:14:51 +01001494 &dev_attr_failfast.attr,
Stefan Haberland7c8faa82010-08-09 18:13:00 +02001495 &dev_attr_expires.attr,
Hannes Reinecke1f1ee9a2013-01-30 09:26:12 +00001496 &dev_attr_retries.attr,
Hannes Reinecke3d71ad32013-01-30 09:26:18 +00001497 &dev_attr_timeout.attr,
Stefan Weinhuber5a27e602011-01-05 12:48:04 +01001498 &dev_attr_reservation_policy.attr,
1499 &dev_attr_last_known_reservation_state.attr,
Stefan Haberlandd07dc5d2012-11-28 13:43:38 +01001500 &dev_attr_safe_offline.attr,
Stefan Haberland5a3b7b12016-03-18 09:42:13 +01001501 &dev_attr_host_access_count.attr,
Stefan Haberland5db84402014-10-01 14:39:47 +02001502 &dev_attr_path_masks.attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503 NULL,
1504};
1505
1506static struct attribute_group dasd_attr_group = {
1507 .attrs = dasd_attrs,
1508};
1509
Horst Hummel40545572006-06-29 15:08:18 +02001510/*
Horst Hummelf24acd42005-05-01 08:58:59 -07001511 * Return value of the specified feature.
1512 */
1513int
1514dasd_get_feature(struct ccw_device *cdev, int feature)
1515{
1516 struct dasd_devmap *devmap;
1517
Kay Sievers2a0217d2008-10-10 21:33:09 +02001518 devmap = dasd_find_busid(dev_name(&cdev->dev));
Horst Hummelf24acd42005-05-01 08:58:59 -07001519 if (IS_ERR(devmap))
Horst Hummel40545572006-06-29 15:08:18 +02001520 return PTR_ERR(devmap);
Horst Hummelf24acd42005-05-01 08:58:59 -07001521
1522 return ((devmap->features & feature) != 0);
1523}
1524
1525/*
1526 * Set / reset given feature.
Adam Buchbinder48fc7f72012-09-19 21:48:00 -04001527 * Flag indicates whether to set (!=0) or the reset (=0) the feature.
Horst Hummelf24acd42005-05-01 08:58:59 -07001528 */
1529int
1530dasd_set_feature(struct ccw_device *cdev, int feature, int flag)
1531{
1532 struct dasd_devmap *devmap;
1533
Kay Sievers2a0217d2008-10-10 21:33:09 +02001534 devmap = dasd_find_busid(dev_name(&cdev->dev));
Horst Hummelf24acd42005-05-01 08:58:59 -07001535 if (IS_ERR(devmap))
Horst Hummel40545572006-06-29 15:08:18 +02001536 return PTR_ERR(devmap);
Horst Hummelf24acd42005-05-01 08:58:59 -07001537
1538 spin_lock(&dasd_devmap_lock);
1539 if (flag)
1540 devmap->features |= feature;
1541 else
1542 devmap->features &= ~feature;
Horst Hummelc6eb7b72005-09-03 15:57:58 -07001543 if (devmap->device)
1544 devmap->device->features = devmap->features;
Horst Hummelf24acd42005-05-01 08:58:59 -07001545 spin_unlock(&dasd_devmap_lock);
1546 return 0;
1547}
1548
1549
Linus Torvalds1da177e2005-04-16 15:20:36 -07001550int
1551dasd_add_sysfs_files(struct ccw_device *cdev)
1552{
1553 return sysfs_create_group(&cdev->dev.kobj, &dasd_attr_group);
1554}
1555
1556void
1557dasd_remove_sysfs_files(struct ccw_device *cdev)
1558{
1559 sysfs_remove_group(&cdev->dev.kobj, &dasd_attr_group);
1560}
1561
1562
1563int
1564dasd_devmap_init(void)
1565{
1566 int i;
1567
1568 /* Initialize devmap structures. */
1569 dasd_max_devindex = 0;
1570 for (i = 0; i < 256; i++)
1571 INIT_LIST_HEAD(&dasd_hashlists[i]);
Horst Hummel40545572006-06-29 15:08:18 +02001572 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001573}
1574
1575void
1576dasd_devmap_exit(void)
1577{
1578 dasd_forget_ranges();
1579}