2 * drivers/s390/cio/blacklist.c
3 * S/390 common I/O routines -- blacklisting of specific devices
5 * Copyright (C) 1999-2002 IBM Deutschland Entwicklung GmbH,
7 * Author(s): Ingo Adlung (adlung@de.ibm.com)
8 * Cornelia Huck (cornelia.huck@de.ibm.com)
9 * Arnd Bergmann (arndb@de.ibm.com)
12 #define KMSG_COMPONENT "cio"
13 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
15 #include <linux/init.h>
16 #include <linux/vmalloc.h>
17 #include <linux/proc_fs.h>
18 #include <linux/seq_file.h>
19 #include <linux/ctype.h>
20 #include <linux/device.h>
23 #include <asm/uaccess.h>
25 #include "blacklist.h"
27 #include "cio_debug.h"
32 * "Blacklisting" of certain devices:
33 * Device numbers given in the commandline as cio_ignore=... won't be known
36 * These can be single devices or ranges of devices
39 /* 65536 bits for each set to indicate if a devno is blacklisted or not */
40 #define __BL_DEV_WORDS ((__MAX_SUBCHANNEL + (8*sizeof(long) - 1)) / \
42 static unsigned long bl_dev[__MAX_SSID + 1][__BL_DEV_WORDS];
43 typedef enum {add, free} range_action;
46 * Function: blacklist_range
47 * (Un-)blacklist the devices from-to
49 static int blacklist_range(range_action action, unsigned int from_ssid,
50 unsigned int to_ssid, unsigned int from,
51 unsigned int to, int msgtrigger)
53 if ((from_ssid > to_ssid) || ((from_ssid == to_ssid) && (from > to))) {
55 pr_warning("0.%x.%04x to 0.%x.%04x is not a valid "
56 "range for cio_ignore\n", from_ssid, from,
62 while ((from_ssid < to_ssid) || ((from_ssid == to_ssid) &&
65 set_bit(from, bl_dev[from_ssid]);
67 clear_bit(from, bl_dev[from_ssid]);
69 if (from > __MAX_SUBCHANNEL) {
78 static int pure_hex(char **cp, unsigned int *val, int min_digit,
79 int max_digit, int max_val)
87 while (isxdigit(**cp) && (diff <= max_digit)) {
92 value = tolower(**cp) - 'a' + 10;
93 *val = *val * 16 + value;
98 if ((diff < min_digit) || (diff > max_digit) || (*val > max_val))
104 static int parse_busid(char *str, unsigned int *cssid, unsigned int *ssid,
105 unsigned int *devno, int msgtrigger)
117 val = simple_strtoul(str, &str_work, 16);
119 if (*str_work == '\0') {
120 if (val <= __MAX_SUBCHANNEL) {
131 ret = pure_hex(&str_work, cssid, 1, 2, __MAX_CSSID);
132 if (ret || (str_work[0] != '.'))
135 ret = pure_hex(&str_work, ssid, 1, 1, __MAX_SSID);
136 if (ret || (str_work[0] != '.'))
139 ret = pure_hex(&str_work, devno, 4, 4, __MAX_SUBCHANNEL);
140 if (ret || (str_work[0] != '\0'))
145 if (rc && msgtrigger)
146 pr_warning("%s is not a valid device for the cio_ignore "
147 "kernel parameter\n", str);
152 static int blacklist_parse_parameters(char *str, range_action action,
155 unsigned int from_cssid, to_cssid, from_ssid, to_ssid, from, to;
162 while ((parm = strsep(&str, ","))) {
172 if (strcmp(parm, "all") == 0) {
176 to_cssid = __MAX_CSSID;
177 to_ssid = __MAX_SSID;
178 to = __MAX_SUBCHANNEL;
180 rc = parse_busid(strsep(&parm, "-"), &from_cssid,
181 &from_ssid, &from, msgtrigger);
184 rc = parse_busid(parm, &to_cssid,
188 to_cssid = from_cssid;
195 rc = blacklist_range(ra, from_ssid, to_ssid, from, to,
207 blacklist_setup (char *str)
209 CIO_MSG_EVENT(6, "Reading blacklist parameters\n");
210 if (blacklist_parse_parameters(str, add, 1))
215 __setup ("cio_ignore=", blacklist_setup);
217 /* Checking if devices are blacklisted */
220 * Function: is_blacklisted
221 * Returns 1 if the given devicenumber can be found in the blacklist,
223 * Used by validate_subchannel()
226 is_blacklisted (int ssid, int devno)
228 return test_bit (devno, bl_dev[ssid]);
231 #ifdef CONFIG_PROC_FS
233 * Function: blacklist_parse_proc_parameters
234 * parse the stuff which is piped to /proc/cio_ignore
236 static int blacklist_parse_proc_parameters(char *buf)
241 parm = strsep(&buf, " ");
243 if (strcmp("free", parm) == 0)
244 rc = blacklist_parse_parameters(buf, free, 0);
245 else if (strcmp("add", parm) == 0)
246 rc = blacklist_parse_parameters(buf, add, 0);
247 else if (strcmp("purge", parm) == 0)
248 return ccw_purge_blacklisted();
252 css_schedule_reprobe();
257 /* Iterator struct for all devices. */
265 cio_ignore_proc_seq_start(struct seq_file *s, loff_t *offset)
267 struct ccwdev_iter *iter = s->private;
269 if (*offset >= (__MAX_SUBCHANNEL + 1) * (__MAX_SSID + 1))
271 memset(iter, 0, sizeof(*iter));
272 iter->ssid = *offset / (__MAX_SUBCHANNEL + 1);
273 iter->devno = *offset % (__MAX_SUBCHANNEL + 1);
278 cio_ignore_proc_seq_stop(struct seq_file *s, void *it)
283 cio_ignore_proc_seq_next(struct seq_file *s, void *it, loff_t *offset)
285 struct ccwdev_iter *iter;
287 if (*offset >= (__MAX_SUBCHANNEL + 1) * (__MAX_SSID + 1))
290 if (iter->devno == __MAX_SUBCHANNEL) {
293 if (iter->ssid > __MAX_SSID)
302 cio_ignore_proc_seq_show(struct seq_file *s, void *it)
304 struct ccwdev_iter *iter;
307 if (!is_blacklisted(iter->ssid, iter->devno))
308 /* Not blacklisted, nothing to output. */
310 if (!iter->in_range) {
311 /* First device in range. */
312 if ((iter->devno == __MAX_SUBCHANNEL) ||
313 !is_blacklisted(iter->ssid, iter->devno + 1))
314 /* Singular device. */
315 return seq_printf(s, "0.%x.%04x\n",
316 iter->ssid, iter->devno);
318 return seq_printf(s, "0.%x.%04x-", iter->ssid, iter->devno);
320 if ((iter->devno == __MAX_SUBCHANNEL) ||
321 !is_blacklisted(iter->ssid, iter->devno + 1)) {
322 /* Last device in range. */
324 return seq_printf(s, "0.%x.%04x\n", iter->ssid, iter->devno);
330 cio_ignore_write(struct file *file, const char __user *user_buf,
331 size_t user_len, loff_t *offset)
338 if (user_len > 65536)
340 buf = vmalloc (user_len + 1); /* maybe better use the stack? */
343 memset(buf, 0, user_len + 1);
345 if (strncpy_from_user (buf, user_buf, user_len) < 0) {
351 while ((i >= 0) && (isspace(buf[i]) || (buf[i] == 0))) {
355 ret = blacklist_parse_proc_parameters(buf);
366 static const struct seq_operations cio_ignore_proc_seq_ops = {
367 .start = cio_ignore_proc_seq_start,
368 .stop = cio_ignore_proc_seq_stop,
369 .next = cio_ignore_proc_seq_next,
370 .show = cio_ignore_proc_seq_show,
374 cio_ignore_proc_open(struct inode *inode, struct file *file)
376 return seq_open_private(file, &cio_ignore_proc_seq_ops,
377 sizeof(struct ccwdev_iter));
380 static const struct file_operations cio_ignore_proc_fops = {
381 .open = cio_ignore_proc_open,
384 .release = seq_release_private,
385 .write = cio_ignore_write,
389 cio_ignore_proc_init (void)
391 struct proc_dir_entry *entry;
393 entry = proc_create("cio_ignore", S_IFREG | S_IRUGO | S_IWUSR, NULL,
394 &cio_ignore_proc_fops);
400 __initcall (cio_ignore_proc_init);
402 #endif /* CONFIG_PROC_FS */