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 #include <linux/config.h>
13 #include <linux/init.h>
14 #include <linux/vmalloc.h>
15 #include <linux/slab.h>
16 #include <linux/proc_fs.h>
17 #include <linux/seq_file.h>
18 #include <linux/ctype.h>
19 #include <linux/device.h>
22 #include <asm/uaccess.h>
24 #include "blacklist.h"
26 #include "cio_debug.h"
30 * "Blacklisting" of certain devices:
31 * Device numbers given in the commandline as cio_ignore=... won't be known
34 * These can be single devices or ranges of devices
37 /* 65536 bits for each set to indicate if a devno is blacklisted or not */
38 #define __BL_DEV_WORDS ((__MAX_SUBCHANNEL + (8*sizeof(long) - 1)) / \
40 static unsigned long bl_dev[__MAX_SSID + 1][__BL_DEV_WORDS];
41 typedef enum {add, free} range_action;
44 * Function: blacklist_range
45 * (Un-)blacklist the devices from-to
48 blacklist_range (range_action action, unsigned int from, unsigned int to,
54 if (from > to || to > __MAX_SUBCHANNEL || ssid > __MAX_SSID) {
55 printk (KERN_WARNING "Invalid blacklist range "
56 "0.%x.%04x to 0.%x.%04x, skipping\n",
57 ssid, from, ssid, to);
60 for (; from <= to; from++) {
62 set_bit (from, bl_dev[ssid]);
64 clear_bit (from, bl_dev[ssid]);
69 * Function: blacklist_busid
70 * Get devno/busid from given string.
71 * Shamelessly grabbed from dasd_devmap.c.
74 blacklist_busid(char **str, int *id0, int *ssid, int *devno)
81 /* check for leading '0x' */
83 if ((*str)[0] == '0' && (*str)[1] == 'x') {
87 if (!isxdigit((*str)[0])) /* We require at least one hex digit */
89 val = simple_strtoul(*str, str, 16);
90 if (old_style || (*str)[0] != '.') {
92 if (val < 0 || val > 0xffff)
95 if ((*str)[0] != ',' && (*str)[0] != '-' &&
96 (*str)[0] != '\n' && (*str)[0] != '\0')
100 /* New style x.y.z busid */
101 if (val < 0 || val > 0xff)
105 if (!isxdigit((*str)[0])) /* We require at least one hex digit */
107 val = simple_strtoul(*str, str, 16);
108 if (val < 0 || val > 0xff || (*str)++[0] != '.')
111 if (!isxdigit((*str)[0])) /* We require at least one hex digit */
113 val = simple_strtoul(*str, str, 16);
114 if (val < 0 || val > 0xffff)
117 if ((*str)[0] != ',' && (*str)[0] != '-' &&
118 (*str)[0] != '\n' && (*str)[0] != '\0')
123 printk(KERN_WARNING "Invalid cio_ignore parameter '%s'\n", sav);
128 blacklist_parse_parameters (char *str, range_action action)
130 unsigned int from, to, from_id0, to_id0, from_ssid, to_ssid;
132 while (*str != 0 && *str != '\n') {
133 range_action ra = action;
142 * Since we have to parse the proc commands and the
143 * kernel arguments we have to check four cases
145 if (strncmp(str,"all,",4) == 0 || strcmp(str,"all") == 0 ||
146 strncmp(str,"all\n",4) == 0 || strncmp(str,"all ",4) == 0) {
150 for (j=0; j <= __MAX_SSID; j++)
151 blacklist_range(ra, 0, __MAX_SUBCHANNEL, j);
155 rc = blacklist_busid(&str, &from_id0,
164 rc = blacklist_busid(&str, &to_id0,
170 printk(KERN_WARNING "invalid cio_ignore "
172 strsep(&str, ",\n"));
175 if ((from_id0 != to_id0) ||
176 (from_ssid != to_ssid)) {
177 printk(KERN_WARNING "invalid cio_ignore range "
178 "%x.%x.%04x-%x.%x.%04x\n",
179 from_id0, from_ssid, from,
180 to_id0, to_ssid, to);
183 pr_debug("blacklist_setup: adding range "
184 "from %x.%x.%04x to %x.%x.%04x\n",
185 from_id0, from_ssid, from, to_id0, to_ssid, to);
186 blacklist_range (ra, from, to, to_ssid);
192 /* Parsing the commandline for blacklist parameters, e.g. to blacklist
193 * bus ids 0.0.1234, 0.0.1235 and 0.0.1236, you could use any of:
194 * - cio_ignore=1234-1236
195 * - cio_ignore=0x1234-0x1235,1236
196 * - cio_ignore=0x1234,1235-1236
197 * - cio_ignore=1236 cio_ignore=1234-0x1236
198 * - cio_ignore=1234 cio_ignore=1236 cio_ignore=0x1235
199 * - cio_ignore=0.0.1234-0.0.1236
200 * - cio_ignore=0.0.1234,0x1235,1236
204 blacklist_setup (char *str)
206 CIO_MSG_EVENT(6, "Reading blacklist parameters\n");
207 return blacklist_parse_parameters (str, add);
210 __setup ("cio_ignore=", blacklist_setup);
212 /* Checking if devices are blacklisted */
215 * Function: is_blacklisted
216 * Returns 1 if the given devicenumber can be found in the blacklist,
218 * Used by validate_subchannel()
221 is_blacklisted (int ssid, int devno)
223 return test_bit (devno, bl_dev[ssid]);
226 #ifdef CONFIG_PROC_FS
228 __s390_redo_validation(struct subchannel_id schid, void *data)
231 struct subchannel *sch;
233 sch = get_subchannel_by_schid(schid);
236 put_device(&sch->dev);
239 ret = css_probe_device(schid);
241 return ret; /* We're through. */
243 /* Stop validation for now. Bad, but no need for a panic. */
249 * Function: s390_redo_validation
250 * Look for no longer blacklisted devices
251 * FIXME: there must be a better way to do this */
253 s390_redo_validation (void)
255 CIO_TRACE_EVENT (0, "redoval");
257 for_each_subchannel(__s390_redo_validation, NULL);
261 * Function: blacklist_parse_proc_parameters
262 * parse the stuff which is piped to /proc/cio_ignore
265 blacklist_parse_proc_parameters (char *buf)
267 if (strncmp (buf, "free ", 5) == 0) {
268 blacklist_parse_parameters (buf + 5, free);
269 } else if (strncmp (buf, "add ", 4) == 0) {
271 * We don't need to check for known devices since
272 * css_probe_device will handle this correctly.
274 blacklist_parse_parameters (buf + 4, add);
276 printk (KERN_WARNING "cio_ignore: Parse error; \n"
277 KERN_WARNING "try using 'free all|<devno-range>,"
278 "<devno-range>,...'\n"
279 KERN_WARNING "or 'add <devno-range>,"
280 "<devno-range>,...'\n");
284 s390_redo_validation ();
287 /* Iterator struct for all devices. */
295 cio_ignore_proc_seq_start(struct seq_file *s, loff_t *offset)
297 struct ccwdev_iter *iter;
299 if (*offset >= (__MAX_SUBCHANNEL + 1) * (__MAX_SSID + 1))
301 iter = kzalloc(sizeof(struct ccwdev_iter), GFP_KERNEL);
303 return ERR_PTR(-ENOMEM);
304 iter->ssid = *offset / (__MAX_SUBCHANNEL + 1);
305 iter->devno = *offset % (__MAX_SUBCHANNEL + 1);
310 cio_ignore_proc_seq_stop(struct seq_file *s, void *it)
317 cio_ignore_proc_seq_next(struct seq_file *s, void *it, loff_t *offset)
319 struct ccwdev_iter *iter;
321 if (*offset >= (__MAX_SUBCHANNEL + 1) * (__MAX_SSID + 1))
324 if (iter->devno == __MAX_SUBCHANNEL) {
327 if (iter->ssid > __MAX_SSID)
336 cio_ignore_proc_seq_show(struct seq_file *s, void *it)
338 struct ccwdev_iter *iter;
341 if (!is_blacklisted(iter->ssid, iter->devno))
342 /* Not blacklisted, nothing to output. */
344 if (!iter->in_range) {
345 /* First device in range. */
346 if ((iter->devno == __MAX_SUBCHANNEL) ||
347 !is_blacklisted(iter->ssid, iter->devno + 1))
348 /* Singular device. */
349 return seq_printf(s, "0.%x.%04x\n",
350 iter->ssid, iter->devno);
352 return seq_printf(s, "0.%x.%04x-", iter->ssid, iter->devno);
354 if ((iter->devno == __MAX_SUBCHANNEL) ||
355 !is_blacklisted(iter->ssid, iter->devno + 1)) {
356 /* Last device in range. */
358 return seq_printf(s, "0.%x.%04x\n", iter->ssid, iter->devno);
364 cio_ignore_write(struct file *file, const char __user *user_buf,
365 size_t user_len, loff_t *offset)
371 if (user_len > 65536)
373 buf = vmalloc (user_len + 1); /* maybe better use the stack? */
376 if (strncpy_from_user (buf, user_buf, user_len) < 0) {
380 buf[user_len] = '\0';
382 blacklist_parse_proc_parameters (buf);
388 static struct seq_operations cio_ignore_proc_seq_ops = {
389 .start = cio_ignore_proc_seq_start,
390 .stop = cio_ignore_proc_seq_stop,
391 .next = cio_ignore_proc_seq_next,
392 .show = cio_ignore_proc_seq_show,
396 cio_ignore_proc_open(struct inode *inode, struct file *file)
398 return seq_open(file, &cio_ignore_proc_seq_ops);
401 static struct file_operations cio_ignore_proc_fops = {
402 .open = cio_ignore_proc_open,
405 .release = seq_release,
406 .write = cio_ignore_write,
410 cio_ignore_proc_init (void)
412 struct proc_dir_entry *entry;
414 entry = create_proc_entry ("cio_ignore", S_IFREG | S_IRUGO | S_IWUSR,
419 entry->proc_fops = &cio_ignore_proc_fops;
424 __initcall (cio_ignore_proc_init);
426 #endif /* CONFIG_PROC_FS */