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"
 
  29  * "Blacklisting" of certain devices:
 
  30  * Device numbers given in the commandline as cio_ignore=... won't be known
 
  33  * These can be single devices or ranges of devices
 
  36 /* 65536 bits for each set to indicate if a devno is blacklisted or not */
 
  37 #define __BL_DEV_WORDS ((__MAX_SUBCHANNEL + (8*sizeof(long) - 1)) / \
 
  39 static unsigned long bl_dev[__MAX_SSID + 1][__BL_DEV_WORDS];
 
  40 typedef enum {add, free} range_action;
 
  43  * Function: blacklist_range
 
  44  * (Un-)blacklist the devices from-to
 
  47 blacklist_range (range_action action, unsigned int from, unsigned int to,
 
  53         if (from > to || to > __MAX_SUBCHANNEL || ssid > __MAX_SSID) {
 
  54                 printk (KERN_WARNING "Invalid blacklist range "
 
  55                         "0.%x.%04x to 0.%x.%04x, skipping\n",
 
  56                         ssid, from, ssid, to);
 
  59         for (; from <= to; from++) {
 
  61                         set_bit (from, bl_dev[ssid]);
 
  63                         clear_bit (from, bl_dev[ssid]);
 
  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 *ssid, 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_ssid, to_ssid;
 
 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) {
 
 149                         for (j=0; j <= __MAX_SSID; j++)
 
 150                                 blacklist_range(ra, 0, __MAX_SUBCHANNEL, j);
 
 154                         rc = blacklist_busid(&str, &from_id0,
 
 163                                 rc = blacklist_busid(&str, &to_id0,
 
 169                                 printk(KERN_WARNING "invalid cio_ignore "
 
 171                                         strsep(&str, ",\n"));
 
 174                         if ((from_id0 != to_id0) ||
 
 175                             (from_ssid != to_ssid)) {
 
 176                                 printk(KERN_WARNING "invalid cio_ignore range "
 
 177                                         "%x.%x.%04x-%x.%x.%04x\n",
 
 178                                         from_id0, from_ssid, from,
 
 179                                         to_id0, to_ssid, to);
 
 182                         pr_debug("blacklist_setup: adding range "
 
 183                                  "from %x.%x.%04x to %x.%x.%04x\n",
 
 184                                  from_id0, from_ssid, from, to_id0, to_ssid, to);
 
 185                         blacklist_range (ra, from, to, to_ssid);
 
 191 /* Parsing the commandline for blacklist parameters, e.g. to blacklist
 
 192  * bus ids 0.0.1234, 0.0.1235 and 0.0.1236, you could use any of:
 
 193  * - cio_ignore=1234-1236
 
 194  * - cio_ignore=0x1234-0x1235,1236
 
 195  * - cio_ignore=0x1234,1235-1236
 
 196  * - cio_ignore=1236 cio_ignore=1234-0x1236
 
 197  * - cio_ignore=1234 cio_ignore=1236 cio_ignore=0x1235
 
 198  * - cio_ignore=0.0.1234-0.0.1236
 
 199  * - cio_ignore=0.0.1234,0x1235,1236
 
 203 blacklist_setup (char *str)
 
 205         CIO_MSG_EVENT(6, "Reading blacklist parameters\n");
 
 206         return blacklist_parse_parameters (str, add);
 
 209 __setup ("cio_ignore=", blacklist_setup);
 
 211 /* Checking if devices are blacklisted */
 
 214  * Function: is_blacklisted
 
 215  * Returns 1 if the given devicenumber can be found in the blacklist,
 
 217  * Used by validate_subchannel()
 
 220 is_blacklisted (int ssid, int devno)
 
 222         return test_bit (devno, bl_dev[ssid]);
 
 225 #ifdef CONFIG_PROC_FS
 
 227  * Function: blacklist_parse_proc_parameters
 
 228  * parse the stuff which is piped to /proc/cio_ignore
 
 231 blacklist_parse_proc_parameters (char *buf)
 
 233         if (strncmp (buf, "free ", 5) == 0) {
 
 234                 blacklist_parse_parameters (buf + 5, free);
 
 235         } else if (strncmp (buf, "add ", 4) == 0) {
 
 237                  * We don't need to check for known devices since
 
 238                  * css_probe_device will handle this correctly. 
 
 240                 blacklist_parse_parameters (buf + 4, add);
 
 242                 printk (KERN_WARNING "cio_ignore: Parse error; \n"
 
 243                         KERN_WARNING "try using 'free all|<devno-range>,"
 
 244                                      "<devno-range>,...'\n"
 
 245                         KERN_WARNING "or 'add <devno-range>,"
 
 246                                      "<devno-range>,...'\n");
 
 250         css_schedule_reprobe();
 
 253 /* Iterator struct for all devices. */
 
 261 cio_ignore_proc_seq_start(struct seq_file *s, loff_t *offset)
 
 263         struct ccwdev_iter *iter;
 
 265         if (*offset >= (__MAX_SUBCHANNEL + 1) * (__MAX_SSID + 1))
 
 267         iter = kzalloc(sizeof(struct ccwdev_iter), GFP_KERNEL);
 
 269                 return ERR_PTR(-ENOMEM);
 
 270         iter->ssid = *offset / (__MAX_SUBCHANNEL + 1);
 
 271         iter->devno = *offset % (__MAX_SUBCHANNEL + 1);
 
 276 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)
 
 337         if (user_len > 65536)
 
 339         buf = vmalloc (user_len + 1); /* maybe better use the stack? */
 
 342         if (strncpy_from_user (buf, user_buf, user_len) < 0) {
 
 346         buf[user_len] = '\0';
 
 348         blacklist_parse_proc_parameters (buf);
 
 354 static struct seq_operations cio_ignore_proc_seq_ops = {
 
 355         .start = cio_ignore_proc_seq_start,
 
 356         .stop  = cio_ignore_proc_seq_stop,
 
 357         .next  = cio_ignore_proc_seq_next,
 
 358         .show  = cio_ignore_proc_seq_show,
 
 362 cio_ignore_proc_open(struct inode *inode, struct file *file)
 
 364         return seq_open(file, &cio_ignore_proc_seq_ops);
 
 367 static struct file_operations cio_ignore_proc_fops = {
 
 368         .open    = cio_ignore_proc_open,
 
 371         .release = seq_release,
 
 372         .write   = cio_ignore_write,
 
 376 cio_ignore_proc_init (void)
 
 378         struct proc_dir_entry *entry;
 
 380         entry = create_proc_entry ("cio_ignore", S_IFREG | S_IRUGO | S_IWUSR,
 
 385         entry->proc_fops = &cio_ignore_proc_fops;
 
 390 __initcall (cio_ignore_proc_init);
 
 392 #endif /* CONFIG_PROC_FS */