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/slab.h>
18 #include <linux/proc_fs.h>
19 #include <linux/seq_file.h>
20 #include <linux/ctype.h>
21 #include <linux/device.h>
24 #include <asm/uaccess.h>
26 #include "blacklist.h"
28 #include "cio_debug.h"
33 * "Blacklisting" of certain devices:
34 * Device numbers given in the commandline as cio_ignore=... won't be known
37 * These can be single devices or ranges of devices
40 /* 65536 bits for each set to indicate if a devno is blacklisted or not */
41 #define __BL_DEV_WORDS ((__MAX_SUBCHANNEL + (8*sizeof(long) - 1)) / \
43 static unsigned long bl_dev[__MAX_SSID + 1][__BL_DEV_WORDS];
44 typedef enum {add, free} range_action;
47 * Function: blacklist_range
48 * (Un-)blacklist the devices from-to
50 static int blacklist_range(range_action action, unsigned int from_ssid,
51 unsigned int to_ssid, unsigned int from,
52 unsigned int to, int msgtrigger)
54 if ((from_ssid > to_ssid) || ((from_ssid == to_ssid) && (from > to))) {
56 pr_warning("0.%x.%04x to 0.%x.%04x is not a valid "
57 "range for cio_ignore\n", from_ssid, from,
63 while ((from_ssid < to_ssid) || ((from_ssid == to_ssid) &&
66 set_bit(from, bl_dev[from_ssid]);
68 clear_bit(from, bl_dev[from_ssid]);
70 if (from > __MAX_SUBCHANNEL) {
79 static int pure_hex(char **cp, unsigned int *val, int min_digit,
80 int max_digit, int max_val)
88 while (isxdigit(**cp) && (diff <= max_digit)) {
93 value = tolower(**cp) - 'a' + 10;
94 *val = *val * 16 + value;
99 if ((diff < min_digit) || (diff > max_digit) || (*val > max_val))
105 static int parse_busid(char *str, unsigned int *cssid, unsigned int *ssid,
106 unsigned int *devno, int msgtrigger)
118 val = simple_strtoul(str, &str_work, 16);
120 if (*str_work == '\0') {
121 if (val <= __MAX_SUBCHANNEL) {
132 ret = pure_hex(&str_work, cssid, 1, 2, __MAX_CSSID);
133 if (ret || (str_work[0] != '.'))
136 ret = pure_hex(&str_work, ssid, 1, 1, __MAX_SSID);
137 if (ret || (str_work[0] != '.'))
140 ret = pure_hex(&str_work, devno, 4, 4, __MAX_SUBCHANNEL);
141 if (ret || (str_work[0] != '\0'))
146 if (rc && msgtrigger)
147 pr_warning("%s is not a valid device for the cio_ignore "
148 "kernel parameter\n", str);
153 static int blacklist_parse_parameters(char *str, range_action action,
156 unsigned int from_cssid, to_cssid, from_ssid, to_ssid, from, to;
163 while ((parm = strsep(&str, ","))) {
173 if (strcmp(parm, "all") == 0) {
177 to_cssid = __MAX_CSSID;
178 to_ssid = __MAX_SSID;
179 to = __MAX_SUBCHANNEL;
181 rc = parse_busid(strsep(&parm, "-"), &from_cssid,
182 &from_ssid, &from, msgtrigger);
185 rc = parse_busid(parm, &to_cssid,
189 to_cssid = from_cssid;
196 rc = blacklist_range(ra, from_ssid, to_ssid, from, to,
208 blacklist_setup (char *str)
210 CIO_MSG_EVENT(6, "Reading blacklist parameters\n");
211 if (blacklist_parse_parameters(str, add, 1))
216 __setup ("cio_ignore=", blacklist_setup);
218 /* Checking if devices are blacklisted */
221 * Function: is_blacklisted
222 * Returns 1 if the given devicenumber can be found in the blacklist,
224 * Used by validate_subchannel()
227 is_blacklisted (int ssid, int devno)
229 return test_bit (devno, bl_dev[ssid]);
232 #ifdef CONFIG_PROC_FS
234 * Function: blacklist_parse_proc_parameters
235 * parse the stuff which is piped to /proc/cio_ignore
237 static int blacklist_parse_proc_parameters(char *buf)
242 parm = strsep(&buf, " ");
244 if (strcmp("free", parm) == 0)
245 rc = blacklist_parse_parameters(buf, free, 0);
246 else if (strcmp("add", parm) == 0)
247 rc = blacklist_parse_parameters(buf, add, 0);
248 else if (strcmp("purge", parm) == 0)
249 return ccw_purge_blacklisted();
253 css_schedule_reprobe();
258 /* Iterator struct for all devices. */
266 cio_ignore_proc_seq_start(struct seq_file *s, loff_t *offset)
268 struct ccwdev_iter *iter;
270 if (*offset >= (__MAX_SUBCHANNEL + 1) * (__MAX_SSID + 1))
272 iter = kzalloc(sizeof(struct ccwdev_iter), GFP_KERNEL);
274 return ERR_PTR(-ENOMEM);
275 iter->ssid = *offset / (__MAX_SUBCHANNEL + 1);
276 iter->devno = *offset % (__MAX_SUBCHANNEL + 1);
281 cio_ignore_proc_seq_stop(struct seq_file *s, void *it)
288 cio_ignore_proc_seq_next(struct seq_file *s, void *it, loff_t *offset)
290 struct ccwdev_iter *iter;
292 if (*offset >= (__MAX_SUBCHANNEL + 1) * (__MAX_SSID + 1))
295 if (iter->devno == __MAX_SUBCHANNEL) {
298 if (iter->ssid > __MAX_SSID)
307 cio_ignore_proc_seq_show(struct seq_file *s, void *it)
309 struct ccwdev_iter *iter;
312 if (!is_blacklisted(iter->ssid, iter->devno))
313 /* Not blacklisted, nothing to output. */
315 if (!iter->in_range) {
316 /* First device in range. */
317 if ((iter->devno == __MAX_SUBCHANNEL) ||
318 !is_blacklisted(iter->ssid, iter->devno + 1))
319 /* Singular device. */
320 return seq_printf(s, "0.%x.%04x\n",
321 iter->ssid, iter->devno);
323 return seq_printf(s, "0.%x.%04x-", iter->ssid, iter->devno);
325 if ((iter->devno == __MAX_SUBCHANNEL) ||
326 !is_blacklisted(iter->ssid, iter->devno + 1)) {
327 /* Last device in range. */
329 return seq_printf(s, "0.%x.%04x\n", iter->ssid, iter->devno);
335 cio_ignore_write(struct file *file, const char __user *user_buf,
336 size_t user_len, loff_t *offset)
343 if (user_len > 65536)
345 buf = vmalloc (user_len + 1); /* maybe better use the stack? */
348 memset(buf, 0, user_len + 1);
350 if (strncpy_from_user (buf, user_buf, user_len) < 0) {
356 while ((i >= 0) && (isspace(buf[i]) || (buf[i] == 0))) {
360 ret = blacklist_parse_proc_parameters(buf);
371 static const struct seq_operations cio_ignore_proc_seq_ops = {
372 .start = cio_ignore_proc_seq_start,
373 .stop = cio_ignore_proc_seq_stop,
374 .next = cio_ignore_proc_seq_next,
375 .show = cio_ignore_proc_seq_show,
379 cio_ignore_proc_open(struct inode *inode, struct file *file)
381 return seq_open(file, &cio_ignore_proc_seq_ops);
384 static const struct file_operations cio_ignore_proc_fops = {
385 .open = cio_ignore_proc_open,
388 .release = seq_release,
389 .write = cio_ignore_write,
393 cio_ignore_proc_init (void)
395 struct proc_dir_entry *entry;
397 entry = proc_create("cio_ignore", S_IFREG | S_IRUGO | S_IWUSR, NULL,
398 &cio_ignore_proc_fops);
404 __initcall (cio_ignore_proc_init);
406 #endif /* CONFIG_PROC_FS */