2 * drivers/s390/cio/blacklist.c
3 * S/390 common I/O routines -- blacklisting of specific devices
6 * Copyright (C) 1999-2002 IBM Deutschland Entwicklung GmbH,
8 * Author(s): Ingo Adlung (adlung@de.ibm.com)
9 * Cornelia Huck (cohuck@de.ibm.com)
10 * Arnd Bergmann (arndb@de.ibm.com)
13 #include <linux/config.h>
14 #include <linux/init.h>
15 #include <linux/vmalloc.h>
16 #include <linux/slab.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"
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 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[__BL_DEV_WORDS];
42 typedef enum {add, free} range_action;
45 * Function: blacklist_range
46 * (Un-)blacklist the devices from-to
49 blacklist_range (range_action action, unsigned int from, unsigned int to)
54 if (from > to || to > __MAX_SUBCHANNEL) {
55 printk (KERN_WARNING "Invalid blacklist range "
56 "0x%04x to 0x%04x, skipping\n", from, to);
59 for (; from <= to; from++) {
61 set_bit (from, bl_dev);
63 clear_bit (from, bl_dev);
68 * Function: blacklist_busid
69 * Get devno/busid from given string.
70 * Shamelessly grabbed from dasd_devmap.c.
73 blacklist_busid(char **str, int *id0, int *id1, int *devno)
80 /* check for leading '0x' */
82 if ((*str)[0] == '0' && (*str)[1] == 'x') {
86 if (!isxdigit((*str)[0])) /* We require at least one hex digit */
88 val = simple_strtoul(*str, str, 16);
89 if (old_style || (*str)[0] != '.') {
91 if (val < 0 || val > 0xffff)
94 if ((*str)[0] != ',' && (*str)[0] != '-' &&
95 (*str)[0] != '\n' && (*str)[0] != '\0')
99 /* New style x.y.z busid */
100 if (val < 0 || val > 0xff)
104 if (!isxdigit((*str)[0])) /* We require at least one hex digit */
106 val = simple_strtoul(*str, str, 16);
107 if (val < 0 || val > 0xff || (*str)++[0] != '.')
110 if (!isxdigit((*str)[0])) /* We require at least one hex digit */
112 val = simple_strtoul(*str, str, 16);
113 if (val < 0 || val > 0xffff)
116 if ((*str)[0] != ',' && (*str)[0] != '-' &&
117 (*str)[0] != '\n' && (*str)[0] != '\0')
122 printk(KERN_WARNING "Invalid cio_ignore parameter '%s'\n", sav);
127 blacklist_parse_parameters (char *str, range_action action)
129 unsigned int from, to, from_id0, to_id0, from_id1, to_id1;
131 while (*str != 0 && *str != '\n') {
132 range_action ra = action;
141 * Since we have to parse the proc commands and the
142 * kernel arguments we have to check four cases
144 if (strncmp(str,"all,",4) == 0 || strcmp(str,"all") == 0 ||
145 strncmp(str,"all\n",4) == 0 || strncmp(str,"all ",4) == 0) {
147 to = __MAX_SUBCHANNEL;
152 rc = blacklist_busid(&str, &from_id0,
161 rc = blacklist_busid(&str, &to_id0,
167 printk(KERN_WARNING "invalid cio_ignore "
169 strsep(&str, ",\n"));
172 if ((from_id0 != to_id0) || (from_id1 != to_id1)) {
173 printk(KERN_WARNING "invalid cio_ignore range "
174 "%x.%x.%04x-%x.%x.%04x\n",
175 from_id0, from_id1, from,
180 /* FIXME: ignoring id0 and id1 here. */
181 pr_debug("blacklist_setup: adding range "
182 "from 0.0.%04x to 0.0.%04x\n", from, to);
183 blacklist_range (ra, from, to);
188 /* Parsing the commandline for blacklist parameters, e.g. to blacklist
189 * bus ids 0.0.1234, 0.0.1235 and 0.0.1236, you could use any of:
190 * - cio_ignore=1234-1236
191 * - cio_ignore=0x1234-0x1235,1236
192 * - cio_ignore=0x1234,1235-1236
193 * - cio_ignore=1236 cio_ignore=1234-0x1236
194 * - cio_ignore=1234 cio_ignore=1236 cio_ignore=0x1235
195 * - cio_ignore=0.0.1234-0.0.1236
196 * - cio_ignore=0.0.1234,0x1235,1236
200 blacklist_setup (char *str)
202 CIO_MSG_EVENT(6, "Reading blacklist parameters\n");
203 return blacklist_parse_parameters (str, add);
206 __setup ("cio_ignore=", blacklist_setup);
208 /* Checking if devices are blacklisted */
211 * Function: is_blacklisted
212 * Returns 1 if the given devicenumber can be found in the blacklist,
214 * Used by validate_subchannel()
217 is_blacklisted (int devno)
219 return test_bit (devno, bl_dev);
222 #ifdef CONFIG_PROC_FS
224 __s390_redo_validation(struct subchannel_id schid, void *data)
227 struct subchannel *sch;
229 sch = get_subchannel_by_schid(schid);
232 put_device(&sch->dev);
235 ret = css_probe_device(schid);
237 return ret; /* We're through. */
239 /* Stop validation for now. Bad, but no need for a panic. */
245 * Function: s390_redo_validation
246 * Look for no longer blacklisted devices
247 * FIXME: there must be a better way to do this */
249 s390_redo_validation (void)
251 CIO_TRACE_EVENT (0, "redoval");
253 for_each_subchannel(__s390_redo_validation, NULL);
257 * Function: blacklist_parse_proc_parameters
258 * parse the stuff which is piped to /proc/cio_ignore
261 blacklist_parse_proc_parameters (char *buf)
263 if (strncmp (buf, "free ", 5) == 0) {
264 blacklist_parse_parameters (buf + 5, free);
265 } else if (strncmp (buf, "add ", 4) == 0) {
267 * We don't need to check for known devices since
268 * css_probe_device will handle this correctly.
270 blacklist_parse_parameters (buf + 4, add);
272 printk (KERN_WARNING "cio_ignore: Parse error; \n"
273 KERN_WARNING "try using 'free all|<devno-range>,"
274 "<devno-range>,...'\n"
275 KERN_WARNING "or 'add <devno-range>,"
276 "<devno-range>,...'\n");
280 s390_redo_validation ();
283 /* Iterator struct for all devices. */
290 cio_ignore_proc_seq_start(struct seq_file *s, loff_t *offset)
292 struct ccwdev_iter *iter;
294 if (*offset > __MAX_SUBCHANNEL)
296 iter = kmalloc(sizeof(struct ccwdev_iter), GFP_KERNEL);
298 return ERR_PTR(-ENOMEM);
299 memset(iter, 0, sizeof(struct ccwdev_iter));
300 iter->devno = *offset;
305 cio_ignore_proc_seq_stop(struct seq_file *s, void *it)
312 cio_ignore_proc_seq_next(struct seq_file *s, void *it, loff_t *offset)
314 struct ccwdev_iter *iter;
316 if (*offset > __MAX_SUBCHANNEL)
318 iter = (struct ccwdev_iter *)it;
325 cio_ignore_proc_seq_show(struct seq_file *s, void *it)
327 struct ccwdev_iter *iter;
329 iter = (struct ccwdev_iter *)it;
330 if (!is_blacklisted(iter->devno))
331 /* Not blacklisted, nothing to output. */
333 if (!iter->in_range) {
334 /* First device in range. */
335 if ((iter->devno == __MAX_SUBCHANNEL) ||
336 !is_blacklisted(iter->devno + 1))
337 /* Singular device. */
338 return seq_printf(s, "0.0.%04x\n", iter->devno);
340 return seq_printf(s, "0.0.%04x-", iter->devno);
342 if ((iter->devno == __MAX_SUBCHANNEL) ||
343 !is_blacklisted(iter->devno + 1)) {
344 /* Last device in range. */
346 return seq_printf(s, "0.0.%04x\n", iter->devno);
352 cio_ignore_write(struct file *file, const char __user *user_buf,
353 size_t user_len, loff_t *offset)
359 if (user_len > 65536)
361 buf = vmalloc (user_len + 1); /* maybe better use the stack? */
364 if (strncpy_from_user (buf, user_buf, user_len) < 0) {
368 buf[user_len] = '\0';
370 blacklist_parse_proc_parameters (buf);
376 static struct seq_operations cio_ignore_proc_seq_ops = {
377 .start = cio_ignore_proc_seq_start,
378 .stop = cio_ignore_proc_seq_stop,
379 .next = cio_ignore_proc_seq_next,
380 .show = cio_ignore_proc_seq_show,
384 cio_ignore_proc_open(struct inode *inode, struct file *file)
386 return seq_open(file, &cio_ignore_proc_seq_ops);
389 static struct file_operations cio_ignore_proc_fops = {
390 .open = cio_ignore_proc_open,
393 .release = seq_release,
394 .write = cio_ignore_write,
398 cio_ignore_proc_init (void)
400 struct proc_dir_entry *entry;
402 entry = create_proc_entry ("cio_ignore", S_IFREG | S_IRUGO | S_IWUSR,
407 entry->proc_fops = &cio_ignore_proc_fops;
412 __initcall (cio_ignore_proc_init);
414 #endif /* CONFIG_PROC_FS */