2 * S/390 common I/O routines -- blacklisting of specific devices
4 * Copyright IBM Corp. 1999, 2013
5 * Author(s): Ingo Adlung (adlung@de.ibm.com)
6 * Cornelia Huck (cornelia.huck@de.ibm.com)
7 * Arnd Bergmann (arndb@de.ibm.com)
10 #define KMSG_COMPONENT "cio"
11 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
13 #include <linux/init.h>
14 #include <linux/vmalloc.h>
15 #include <linux/proc_fs.h>
16 #include <linux/seq_file.h>
17 #include <linux/ctype.h>
18 #include <linux/device.h>
20 #include <asm/uaccess.h>
24 #include "blacklist.h"
26 #include "cio_debug.h"
31 * "Blacklisting" of certain devices:
32 * Device numbers given in the commandline as cio_ignore=... won't be known
35 * These can be single devices or ranges of devices
38 /* 65536 bits for each set to indicate if a devno is blacklisted or not */
39 #define __BL_DEV_WORDS ((__MAX_SUBCHANNEL + (8*sizeof(long) - 1)) / \
41 static unsigned long bl_dev
[__MAX_SSID
+ 1][__BL_DEV_WORDS
];
42 typedef enum {add
, free
} range_action
;
45 * Function: blacklist_range
46 * (Un-)blacklist the devices from-to
48 static int blacklist_range(range_action action
, unsigned int from_ssid
,
49 unsigned int to_ssid
, unsigned int from
,
50 unsigned int to
, int msgtrigger
)
52 if ((from_ssid
> to_ssid
) || ((from_ssid
== to_ssid
) && (from
> to
))) {
54 pr_warn("0.%x.%04x to 0.%x.%04x is not a valid range for cio_ignore\n",
55 from_ssid
, from
, to_ssid
, to
);
60 while ((from_ssid
< to_ssid
) || ((from_ssid
== to_ssid
) &&
63 set_bit(from
, bl_dev
[from_ssid
]);
65 clear_bit(from
, bl_dev
[from_ssid
]);
67 if (from
> __MAX_SUBCHANNEL
) {
76 static int pure_hex(char **cp
, unsigned int *val
, int min_digit
,
77 int max_digit
, int max_val
)
84 while (diff
<= max_digit
) {
85 int value
= hex_to_bin(**cp
);
89 *val
= *val
* 16 + value
;
94 if ((diff
< min_digit
) || (diff
> max_digit
) || (*val
> max_val
))
100 static int parse_busid(char *str
, unsigned int *cssid
, unsigned int *ssid
,
101 unsigned int *devno
, int msgtrigger
)
113 val
= simple_strtoul(str
, &str_work
, 16);
115 if (*str_work
== '\0') {
116 if (val
<= __MAX_SUBCHANNEL
) {
127 ret
= pure_hex(&str_work
, cssid
, 1, 2, __MAX_CSSID
);
128 if (ret
|| (str_work
[0] != '.'))
131 ret
= pure_hex(&str_work
, ssid
, 1, 1, __MAX_SSID
);
132 if (ret
|| (str_work
[0] != '.'))
135 ret
= pure_hex(&str_work
, devno
, 4, 4, __MAX_SUBCHANNEL
);
136 if (ret
|| (str_work
[0] != '\0'))
141 if (rc
&& msgtrigger
)
142 pr_warn("%s is not a valid device for the cio_ignore kernel parameter\n",
148 static int blacklist_parse_parameters(char *str
, range_action action
,
151 unsigned int from_cssid
, to_cssid
, from_ssid
, to_ssid
, from
, to
;
158 while ((parm
= strsep(&str
, ","))) {
168 if (strcmp(parm
, "all") == 0) {
172 to_cssid
= __MAX_CSSID
;
173 to_ssid
= __MAX_SSID
;
174 to
= __MAX_SUBCHANNEL
;
175 } else if (strcmp(parm
, "ipldev") == 0) {
176 if (ipl_info
.type
== IPL_TYPE_CCW
) {
178 from_ssid
= ipl_info
.data
.ccw
.dev_id
.ssid
;
179 from
= ipl_info
.data
.ccw
.dev_id
.devno
;
180 } else if (ipl_info
.type
== IPL_TYPE_FCP
||
181 ipl_info
.type
== IPL_TYPE_FCP_DUMP
) {
183 from_ssid
= ipl_info
.data
.fcp
.dev_id
.ssid
;
184 from
= ipl_info
.data
.fcp
.dev_id
.devno
;
188 to_cssid
= from_cssid
;
191 } else if (strcmp(parm
, "condev") == 0) {
192 if (console_devno
== -1)
195 from_cssid
= to_cssid
= 0;
196 from_ssid
= to_ssid
= 0;
197 from
= to
= console_devno
;
199 rc
= parse_busid(strsep(&parm
, "-"), &from_cssid
,
200 &from_ssid
, &from
, msgtrigger
);
203 rc
= parse_busid(parm
, &to_cssid
,
207 to_cssid
= from_cssid
;
214 rc
= blacklist_range(ra
, from_ssid
, to_ssid
, from
, to
,
226 blacklist_setup (char *str
)
228 CIO_MSG_EVENT(6, "Reading blacklist parameters\n");
229 if (blacklist_parse_parameters(str
, add
, 1))
234 __setup ("cio_ignore=", blacklist_setup
);
236 /* Checking if devices are blacklisted */
239 * Function: is_blacklisted
240 * Returns 1 if the given devicenumber can be found in the blacklist,
242 * Used by validate_subchannel()
245 is_blacklisted (int ssid
, int devno
)
247 return test_bit (devno
, bl_dev
[ssid
]);
250 #ifdef CONFIG_PROC_FS
252 * Function: blacklist_parse_proc_parameters
253 * parse the stuff which is piped to /proc/cio_ignore
255 static int blacklist_parse_proc_parameters(char *buf
)
260 parm
= strsep(&buf
, " ");
262 if (strcmp("free", parm
) == 0) {
263 rc
= blacklist_parse_parameters(buf
, free
, 0);
264 css_schedule_eval_all_unreg(0);
265 } else if (strcmp("add", parm
) == 0)
266 rc
= blacklist_parse_parameters(buf
, add
, 0);
267 else if (strcmp("purge", parm
) == 0)
268 return ccw_purge_blacklisted();
276 /* Iterator struct for all devices. */
284 cio_ignore_proc_seq_start(struct seq_file
*s
, loff_t
*offset
)
286 struct ccwdev_iter
*iter
= s
->private;
288 if (*offset
>= (__MAX_SUBCHANNEL
+ 1) * (__MAX_SSID
+ 1))
290 memset(iter
, 0, sizeof(*iter
));
291 iter
->ssid
= *offset
/ (__MAX_SUBCHANNEL
+ 1);
292 iter
->devno
= *offset
% (__MAX_SUBCHANNEL
+ 1);
297 cio_ignore_proc_seq_stop(struct seq_file
*s
, void *it
)
302 cio_ignore_proc_seq_next(struct seq_file
*s
, void *it
, loff_t
*offset
)
304 struct ccwdev_iter
*iter
;
306 if (*offset
>= (__MAX_SUBCHANNEL
+ 1) * (__MAX_SSID
+ 1))
309 if (iter
->devno
== __MAX_SUBCHANNEL
) {
312 if (iter
->ssid
> __MAX_SSID
)
321 cio_ignore_proc_seq_show(struct seq_file
*s
, void *it
)
323 struct ccwdev_iter
*iter
;
326 if (!is_blacklisted(iter
->ssid
, iter
->devno
))
327 /* Not blacklisted, nothing to output. */
329 if (!iter
->in_range
) {
330 /* First device in range. */
331 if ((iter
->devno
== __MAX_SUBCHANNEL
) ||
332 !is_blacklisted(iter
->ssid
, iter
->devno
+ 1)) {
333 /* Singular device. */
334 seq_printf(s
, "0.%x.%04x\n", iter
->ssid
, iter
->devno
);
338 seq_printf(s
, "0.%x.%04x-", iter
->ssid
, iter
->devno
);
341 if ((iter
->devno
== __MAX_SUBCHANNEL
) ||
342 !is_blacklisted(iter
->ssid
, iter
->devno
+ 1)) {
343 /* Last device in range. */
345 seq_printf(s
, "0.%x.%04x\n", iter
->ssid
, iter
->devno
);
351 cio_ignore_write(struct file
*file
, const char __user
*user_buf
,
352 size_t user_len
, loff_t
*offset
)
359 if (user_len
> 65536)
361 buf
= vzalloc(user_len
+ 1); /* maybe better use the stack? */
365 if (strncpy_from_user (buf
, user_buf
, user_len
) < 0) {
371 while ((i
>= 0) && (isspace(buf
[i
]) || (buf
[i
] == 0))) {
375 ret
= blacklist_parse_proc_parameters(buf
);
386 static const struct seq_operations cio_ignore_proc_seq_ops
= {
387 .start
= cio_ignore_proc_seq_start
,
388 .stop
= cio_ignore_proc_seq_stop
,
389 .next
= cio_ignore_proc_seq_next
,
390 .show
= cio_ignore_proc_seq_show
,
394 cio_ignore_proc_open(struct inode
*inode
, struct file
*file
)
396 return seq_open_private(file
, &cio_ignore_proc_seq_ops
,
397 sizeof(struct ccwdev_iter
));
400 static const struct file_operations cio_ignore_proc_fops
= {
401 .open
= cio_ignore_proc_open
,
404 .release
= seq_release_private
,
405 .write
= cio_ignore_write
,
409 cio_ignore_proc_init (void)
411 struct proc_dir_entry
*entry
;
413 entry
= proc_create("cio_ignore", S_IFREG
| S_IRUGO
| S_IWUSR
, NULL
,
414 &cio_ignore_proc_fops
);
420 __initcall (cio_ignore_proc_init
);
422 #endif /* CONFIG_PROC_FS */