Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 | /* * drivers/s390/cio/blacklist.c * S/390 common I/O routines -- blacklisting of specific devices * $Revision: 1.7 $ * * Copyright (C) 1999-2002 IBM Deutschland Entwicklung GmbH, * IBM Corporation * Author(s): Ingo Adlung (adlung@de.ibm.com) * Cornelia Huck (cohuck@de.ibm.com) * Arnd Bergmann (arndb@de.ibm.com) * ChangeLog: 11/04/2002 Arnd Bergmann Split s390io.c into multiple files, * see s390io.c for complete list of * changes. * 15/04/2002 Arnd Bergmann check ranges of user input * 18/04/2002 Arnd Bergmann remove bogus optimization and * now unnecessary locking * 19/04/2002 Arnd Bergmann cleanup parameter parsing */ #include <linux/config.h> #include <linux/init.h> #include <linux/vmalloc.h> #include <linux/slab.h> #include <linux/proc_fs.h> #include <linux/ctype.h> #include <asm/irq.h> #include <asm/s390dyn.h> #include <asm/uaccess.h> #include <asm/debug.h> #include "blacklist.h" #include "cio_debug.h" #include "ioinfo.h" #include "proc.h" #include "s390io.h" /* * "Blacklisting" of certain devices: * Device numbers given in the commandline as cio_ignore=... won't be known * to Linux. * * These can be single devices or ranges of devices */ #define max_devno (0xffffUL) static uint32_t bl_dev[(max_devno+1) / 32]; /* 65536 bits to indicate if a devno is blacklisted or not */ typedef enum {add, free} range_action; /* * Function: blacklist_range * (Un-)blacklist the devices from-to */ static inline void blacklist_range (range_action action, unsigned int from, unsigned int to) { if (!to) to = from; if ((from > to) || (to > max_devno)) { printk (KERN_WARNING "Invalid blacklist range " "0x%04x to 0x%04x, skipping\n", from, to); return; } for (; from <= to; from++) { (action == add) ? set_bit (from, &bl_dev) : clear_bit (from, &bl_dev); } } /* * function: blacklist_strtoul * Strip leading '0x' and interpret the values as Hex */ static inline int blacklist_strtoul (const char *str, char **stra) { if (*str == '0') { if (*(++str) == 'x') /* strip leading zero */ str++; /* strip leading x */ } return simple_strtoul (str, stra, 16); /* interpret anything as hex */ } static inline int blacklist_parse_parameters (char *str, range_action action) { unsigned int from, to; while (*str != 0 && *str != '\n') { if (!isxdigit(*str)) { printk(KERN_WARNING "blacklist_setup: error parsing " "\"%s\"\n", str); return 0; } from = blacklist_strtoul (str, &str); to = (*str == '-') ? blacklist_strtoul (str+1, &str) : from; printk (KERN_INFO "blacklist_setup: adding range " "from 0x%04x to 0x%04x\n", from, to); blacklist_range (action, from, to); if (*str == ',') str++; } return 1; } /* Parsing the commandline for blacklist parameters, e.g. to blacklist * device IDs 0x1234, 0x1235 and 0x1236, you could use any of: * - cio_ignore=1234-1236 * - cio_ignore=0x1234-0x1235,1236 * - cio_ignore=0x1234,1235-1236 * - cio_ignore=1236 cio_ignore=1234-0x1236 * - cio_ignore=1234 cio_ignore=1236 cio_ignore=0x1235 * - ... */ static int __init blacklist_setup (char *str) { CIO_MSG_EVENT(6, "Reading blacklist parameters\n"); return blacklist_parse_parameters (str, add); } __setup ("cio_ignore=", blacklist_setup); /* Checking if devices are blacklisted */ /* * Function: is_blacklisted * Returns 1 if the given devicenumber can be found in the blacklist, otherwise 0. * Used by s390_validate_subchannel() */ int is_blacklisted (int devno) { return test_bit (devno, &bl_dev); } #ifdef CONFIG_PROC_FS /* * Function: s390_redo_validation * Look for no longer blacklisted devices * FIXME: there must be a better way to do this */ static inline void s390_redo_validation (void) { int irq; CIO_TRACE_EVENT (0, "redoval"); for (irq=0; irq <= highest_subchannel; irq++) { if (ioinfo[irq] != INVALID_STORAGE_AREA || s390_validate_subchannel (irq, 0)) continue; /* this subchannel has just been unblacklisted, * so now try to get it working */ s390_device_recognition_irq (irq); if (ioinfo[irq]->ui.flags.oper) { devreg_t *pdevreg; pdevreg = s390_search_devreg (ioinfo[irq]); if (pdevreg && pdevreg->oper_func != NULL) pdevreg->oper_func (irq, pdevreg); } } } /* * Function: blacklist_parse_proc_parameters * parse the stuff which is piped to /proc/cio_ignore */ static inline void blacklist_parse_proc_parameters (char *buf) { if (strncmp (buf, "free ", 5) == 0) { if (strstr (buf + 5, "all")) blacklist_range (free, 0, max_devno); else blacklist_parse_parameters (buf + 5, free); } else if (strncmp (buf, "add ", 4) == 0) { /* FIXME: the old code was checking if the new bl'ed * devices are already known to the system so * s390_validate_subchannel would still give a working * status. is that necessary? */ blacklist_parse_parameters (buf + 4, add); } else { printk (KERN_WARNING "cio_ignore: Parse error; \n" KERN_WARNING "try using 'free all|<devno-range>," "<devno-range>,...'\n" KERN_WARNING "or 'add <devno-range>," "<devno-range>,...'\n"); return; } s390_redo_validation (); } static int cio_ignore_read (char *page, char **start, off_t off, int count, int *eof, void *data) { int len = 0; const unsigned int entry_size = 14; /* "0xABCD-0xEFGH\n" */ long devno = off; /* abuse the page variable * as counter, see fs/proc/generic.c */ while ((devno <= max_devno) && (len + entry_size < count)) { if (test_bit (devno, &bl_dev)) { len += sprintf(page + len, "0x%04lx", devno); devno++; if (test_bit (devno, &bl_dev)) { /* print range */ do { devno++; } while (test_bit (devno, &bl_dev)); len += sprintf(page + len, "-0x%04lx", devno-1); } len += sprintf(page + len, "\n"); } devno++; } if (devno <= max_devno) *eof = 1; *start = (char *) (devno - off); /* number of checked entries */ return len; } static int cio_ignore_write (struct file *file, const char *user_buf, unsigned long user_len, void *data) { char *buf = vmalloc (user_len + 1); /* maybe better use the stack? */ if (buf == NULL) return -ENOMEM; if (strncpy_from_user (buf, user_buf, user_len) < 0) { vfree (buf); return -EFAULT; } buf[user_len] = '\0'; #if 0 CIO_DEBUG(KERN_DEBUG, 2, "/proc/cio_ignore: '%s'\n", buf); #endif blacklist_parse_proc_parameters (buf); vfree (buf); return user_len; } static int cio_ignore_proc_init (void) { struct proc_dir_entry *entry; entry = create_proc_entry ("cio_ignore", S_IFREG | S_IRUGO | S_IWUSR, &proc_root); if (!entry) return 0; entry->read_proc = cio_ignore_read; entry->write_proc = cio_ignore_write; return 1; } __initcall (cio_ignore_proc_init); #endif /* CONFIG_PROC_FS */ |