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/init.h>
13 #include <linux/vmalloc.h>
14 #include <linux/slab.h>
15 #include <linux/proc_fs.h>
16 #include <linux/seq_file.h>
17 #include <linux/ctype.h>
18 #include <linux/device.h>
21 #include <asm/uaccess.h>
23 #include "blacklist.h"
25 #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
47 static int blacklist_range(range_action action, unsigned int from_ssid,
48 unsigned int to_ssid, unsigned int from,
49 unsigned int to, int msgtrigger)
51 if ((from_ssid > to_ssid) || ((from_ssid == to_ssid) && (from > to))) {
53 printk(KERN_WARNING "cio: Invalid cio_ignore range "
54 "0.%x.%04x-0.%x.%04x\n", from_ssid, from,
59 while ((from_ssid < to_ssid) || ((from_ssid == to_ssid) &&
62 set_bit(from, bl_dev[from_ssid]);
64 clear_bit(from, bl_dev[from_ssid]);
66 if (from > __MAX_SUBCHANNEL) {
75 static int pure_hex(char **cp, unsigned int *val, int min_digit,
76 int max_digit, int max_val)
84 while (isxdigit(**cp) && (diff <= max_digit)) {
89 value = tolower(**cp) - 'a' + 10;
90 *val = *val * 16 + value;
95 if ((diff < min_digit) || (diff > max_digit) || (*val > max_val))
101 static int parse_busid(char *str, unsigned int *cssid, unsigned int *ssid,
102 unsigned int *devno, int msgtrigger)
114 val = simple_strtoul(str, &str_work, 16);
116 if (*str_work == '\0') {
117 if (val <= __MAX_SUBCHANNEL) {
128 ret = pure_hex(&str_work, cssid, 1, 2, __MAX_CSSID);
129 if (ret || (str_work[0] != '.'))
132 ret = pure_hex(&str_work, ssid, 1, 1, __MAX_SSID);
133 if (ret || (str_work[0] != '.'))
136 ret = pure_hex(&str_work, devno, 4, 4, __MAX_SUBCHANNEL);
137 if (ret || (str_work[0] != '\0'))
142 if (rc && msgtrigger)
143 printk(KERN_WARNING "cio: Invalid cio_ignore device '%s'\n",
149 static int blacklist_parse_parameters(char *str, range_action action,
152 unsigned int from_cssid, to_cssid, from_ssid, to_ssid, from, to;
159 while ((parm = strsep(&str, ","))) {
169 if (strcmp(parm, "all") == 0) {
173 to_cssid = __MAX_CSSID;
174 to_ssid = __MAX_SSID;
175 to = __MAX_SUBCHANNEL;
177 rc = parse_busid(strsep(&parm, "-"), &from_cssid,
178 &from_ssid, &from, msgtrigger);
181 rc = parse_busid(parm, &to_cssid,
185 to_cssid = from_cssid;
192 rc = blacklist_range(ra, from_ssid, to_ssid, from, to,
204 blacklist_setup (char *str)
206 CIO_MSG_EVENT(6, "Reading blacklist parameters\n");
207 if (blacklist_parse_parameters(str, add, 1))
212 __setup ("cio_ignore=", blacklist_setup);
214 /* Checking if devices are blacklisted */
217 * Function: is_blacklisted
218 * Returns 1 if the given devicenumber can be found in the blacklist,
220 * Used by validate_subchannel()
223 is_blacklisted (int ssid, int devno)
225 return test_bit (devno, bl_dev[ssid]);
228 #ifdef CONFIG_PROC_FS
230 * Function: blacklist_parse_proc_parameters
231 * parse the stuff which is piped to /proc/cio_ignore
233 static int blacklist_parse_proc_parameters(char *buf)
238 parm = strsep(&buf, " ");
240 if (strcmp("free", parm) == 0)
241 rc = blacklist_parse_parameters(buf, free, 0);
242 else if (strcmp("add", parm) == 0)
243 rc = blacklist_parse_parameters(buf, add, 0);
244 else if (strcmp("purge", parm) == 0)
245 return ccw_purge_blacklisted();
249 css_schedule_reprobe();
254 /* Iterator struct for all devices. */
262 cio_ignore_proc_seq_start(struct seq_file *s, loff_t *offset)
264 struct ccwdev_iter *iter;
266 if (*offset >= (__MAX_SUBCHANNEL + 1) * (__MAX_SSID + 1))
268 iter = kzalloc(sizeof(struct ccwdev_iter), GFP_KERNEL);
270 return ERR_PTR(-ENOMEM);
271 iter->ssid = *offset / (__MAX_SUBCHANNEL + 1);
272 iter->devno = *offset % (__MAX_SUBCHANNEL + 1);
277 cio_ignore_proc_seq_stop(struct seq_file *s, void *it)
284 cio_ignore_proc_seq_next(struct seq_file *s, void *it, loff_t *offset)
286 struct ccwdev_iter *iter;
288 if (*offset >= (__MAX_SUBCHANNEL + 1) * (__MAX_SSID + 1))
291 if (iter->devno == __MAX_SUBCHANNEL) {
294 if (iter->ssid > __MAX_SSID)
303 cio_ignore_proc_seq_show(struct seq_file *s, void *it)
305 struct ccwdev_iter *iter;
308 if (!is_blacklisted(iter->ssid, iter->devno))
309 /* Not blacklisted, nothing to output. */
311 if (!iter->in_range) {
312 /* First device in range. */
313 if ((iter->devno == __MAX_SUBCHANNEL) ||
314 !is_blacklisted(iter->ssid, iter->devno + 1))
315 /* Singular device. */
316 return seq_printf(s, "0.%x.%04x\n",
317 iter->ssid, iter->devno);
319 return seq_printf(s, "0.%x.%04x-", iter->ssid, iter->devno);
321 if ((iter->devno == __MAX_SUBCHANNEL) ||
322 !is_blacklisted(iter->ssid, iter->devno + 1)) {
323 /* Last device in range. */
325 return seq_printf(s, "0.%x.%04x\n", iter->ssid, iter->devno);
331 cio_ignore_write(struct file *file, const char __user *user_buf,
332 size_t user_len, loff_t *offset)
340 if (user_len > 65536)
342 buf = vmalloc (user_len + 1); /* maybe better use the stack? */
345 memset(buf, 0, user_len + 1);
347 if (strncpy_from_user (buf, user_buf, user_len) < 0) {
353 while ((i >= 0) && (isspace(buf[i]) || (buf[i] == 0))) {
357 ret = blacklist_parse_proc_parameters(buf);
368 static const struct seq_operations cio_ignore_proc_seq_ops = {
369 .start = cio_ignore_proc_seq_start,
370 .stop = cio_ignore_proc_seq_stop,
371 .next = cio_ignore_proc_seq_next,
372 .show = cio_ignore_proc_seq_show,
376 cio_ignore_proc_open(struct inode *inode, struct file *file)
378 return seq_open(file, &cio_ignore_proc_seq_ops);
381 static const struct file_operations cio_ignore_proc_fops = {
382 .open = cio_ignore_proc_open,
385 .release = seq_release,
386 .write = cio_ignore_write,
390 cio_ignore_proc_init (void)
392 struct proc_dir_entry *entry;
394 entry = proc_create("cio_ignore", S_IFREG | S_IRUGO | S_IWUSR, NULL,
395 &cio_ignore_proc_fops);
401 __initcall (cio_ignore_proc_init);
403 #endif /* CONFIG_PROC_FS */