]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * drivers/s390/cio/blacklist.c | |
3 | * S/390 common I/O routines -- blacklisting of specific devices | |
d176795b | 4 | * $Revision: 1.35 $ |
1da177e4 LT |
5 | * |
6 | * Copyright (C) 1999-2002 IBM Deutschland Entwicklung GmbH, | |
7 | * IBM Corporation | |
8 | * Author(s): Ingo Adlung ([email protected]) | |
9 | * Cornelia Huck ([email protected]) | |
10 | * Arnd Bergmann ([email protected]) | |
11 | */ | |
12 | ||
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> | |
678a395b | 18 | #include <linux/seq_file.h> |
1da177e4 LT |
19 | #include <linux/ctype.h> |
20 | #include <linux/device.h> | |
21 | ||
22 | #include <asm/cio.h> | |
23 | #include <asm/uaccess.h> | |
24 | ||
25 | #include "blacklist.h" | |
26 | #include "cio.h" | |
27 | #include "cio_debug.h" | |
28 | #include "css.h" | |
29 | ||
30 | /* | |
31 | * "Blacklisting" of certain devices: | |
32 | * Device numbers given in the commandline as cio_ignore=... won't be known | |
33 | * to Linux. | |
34 | * | |
35 | * These can be single devices or ranges of devices | |
36 | */ | |
37 | ||
38 | /* 65536 bits to indicate if a devno is blacklisted or not */ | |
a8237fc4 | 39 | #define __BL_DEV_WORDS ((__MAX_SUBCHANNEL + (8*sizeof(long) - 1)) / \ |
1da177e4 LT |
40 | (8*sizeof(long))) |
41 | static unsigned long bl_dev[__BL_DEV_WORDS]; | |
42 | typedef enum {add, free} range_action; | |
43 | ||
44 | /* | |
45 | * Function: blacklist_range | |
46 | * (Un-)blacklist the devices from-to | |
47 | */ | |
48 | static inline void | |
49 | blacklist_range (range_action action, unsigned int from, unsigned int to) | |
50 | { | |
51 | if (!to) | |
52 | to = from; | |
53 | ||
a8237fc4 | 54 | if (from > to || to > __MAX_SUBCHANNEL) { |
1da177e4 LT |
55 | printk (KERN_WARNING "Invalid blacklist range " |
56 | "0x%04x to 0x%04x, skipping\n", from, to); | |
57 | return; | |
58 | } | |
59 | for (; from <= to; from++) { | |
60 | if (action == add) | |
61 | set_bit (from, bl_dev); | |
62 | else | |
63 | clear_bit (from, bl_dev); | |
64 | } | |
65 | } | |
66 | ||
67 | /* | |
68 | * Function: blacklist_busid | |
69 | * Get devno/busid from given string. | |
70 | * Shamelessly grabbed from dasd_devmap.c. | |
71 | */ | |
72 | static inline int | |
73 | blacklist_busid(char **str, int *id0, int *id1, int *devno) | |
74 | { | |
75 | int val, old_style; | |
76 | char *sav; | |
77 | ||
78 | sav = *str; | |
79 | ||
80 | /* check for leading '0x' */ | |
81 | old_style = 0; | |
82 | if ((*str)[0] == '0' && (*str)[1] == 'x') { | |
83 | *str += 2; | |
84 | old_style = 1; | |
85 | } | |
86 | if (!isxdigit((*str)[0])) /* We require at least one hex digit */ | |
87 | goto confused; | |
88 | val = simple_strtoul(*str, str, 16); | |
89 | if (old_style || (*str)[0] != '.') { | |
90 | *id0 = *id1 = 0; | |
91 | if (val < 0 || val > 0xffff) | |
92 | goto confused; | |
93 | *devno = val; | |
94 | if ((*str)[0] != ',' && (*str)[0] != '-' && | |
95 | (*str)[0] != '\n' && (*str)[0] != '\0') | |
96 | goto confused; | |
97 | return 0; | |
98 | } | |
99 | /* New style x.y.z busid */ | |
100 | if (val < 0 || val > 0xff) | |
101 | goto confused; | |
102 | *id0 = val; | |
103 | (*str)++; | |
104 | if (!isxdigit((*str)[0])) /* We require at least one hex digit */ | |
105 | goto confused; | |
106 | val = simple_strtoul(*str, str, 16); | |
107 | if (val < 0 || val > 0xff || (*str)++[0] != '.') | |
108 | goto confused; | |
109 | *id1 = val; | |
110 | if (!isxdigit((*str)[0])) /* We require at least one hex digit */ | |
111 | goto confused; | |
112 | val = simple_strtoul(*str, str, 16); | |
113 | if (val < 0 || val > 0xffff) | |
114 | goto confused; | |
115 | *devno = val; | |
116 | if ((*str)[0] != ',' && (*str)[0] != '-' && | |
117 | (*str)[0] != '\n' && (*str)[0] != '\0') | |
118 | goto confused; | |
119 | return 0; | |
120 | confused: | |
121 | strsep(str, ",\n"); | |
122 | printk(KERN_WARNING "Invalid cio_ignore parameter '%s'\n", sav); | |
123 | return 1; | |
124 | } | |
125 | ||
126 | static inline int | |
127 | blacklist_parse_parameters (char *str, range_action action) | |
128 | { | |
129 | unsigned int from, to, from_id0, to_id0, from_id1, to_id1; | |
130 | ||
131 | while (*str != 0 && *str != '\n') { | |
132 | range_action ra = action; | |
133 | while(*str == ',') | |
134 | str++; | |
135 | if (*str == '!') { | |
136 | ra = !action; | |
137 | ++str; | |
138 | } | |
139 | ||
140 | /* | |
141 | * Since we have to parse the proc commands and the | |
142 | * kernel arguments we have to check four cases | |
143 | */ | |
144 | if (strncmp(str,"all,",4) == 0 || strcmp(str,"all") == 0 || | |
145 | strncmp(str,"all\n",4) == 0 || strncmp(str,"all ",4) == 0) { | |
146 | from = 0; | |
a8237fc4 | 147 | to = __MAX_SUBCHANNEL; |
1da177e4 LT |
148 | str += 3; |
149 | } else { | |
150 | int rc; | |
151 | ||
152 | rc = blacklist_busid(&str, &from_id0, | |
153 | &from_id1, &from); | |
154 | if (rc) | |
155 | continue; | |
156 | to = from; | |
157 | to_id0 = from_id0; | |
158 | to_id1 = from_id1; | |
159 | if (*str == '-') { | |
160 | str++; | |
161 | rc = blacklist_busid(&str, &to_id0, | |
162 | &to_id1, &to); | |
163 | if (rc) | |
164 | continue; | |
165 | } | |
166 | if (*str == '-') { | |
167 | printk(KERN_WARNING "invalid cio_ignore " | |
168 | "parameter '%s'\n", | |
169 | strsep(&str, ",\n")); | |
170 | continue; | |
171 | } | |
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, | |
176 | to_id0, to_id1, to); | |
177 | continue; | |
178 | } | |
179 | } | |
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); | |
184 | } | |
185 | return 1; | |
186 | } | |
187 | ||
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 | |
197 | * - ... | |
198 | */ | |
199 | static int __init | |
200 | blacklist_setup (char *str) | |
201 | { | |
202 | CIO_MSG_EVENT(6, "Reading blacklist parameters\n"); | |
203 | return blacklist_parse_parameters (str, add); | |
204 | } | |
205 | ||
206 | __setup ("cio_ignore=", blacklist_setup); | |
207 | ||
208 | /* Checking if devices are blacklisted */ | |
209 | ||
210 | /* | |
211 | * Function: is_blacklisted | |
212 | * Returns 1 if the given devicenumber can be found in the blacklist, | |
213 | * otherwise 0. | |
214 | * Used by validate_subchannel() | |
215 | */ | |
216 | int | |
217 | is_blacklisted (int devno) | |
218 | { | |
219 | return test_bit (devno, bl_dev); | |
220 | } | |
221 | ||
222 | #ifdef CONFIG_PROC_FS | |
f97a56fb CH |
223 | static int |
224 | __s390_redo_validation(struct subchannel_id schid, void *data) | |
225 | { | |
226 | int ret; | |
227 | struct subchannel *sch; | |
228 | ||
229 | sch = get_subchannel_by_schid(schid); | |
230 | if (sch) { | |
231 | /* Already known. */ | |
232 | put_device(&sch->dev); | |
233 | return 0; | |
234 | } | |
235 | ret = css_probe_device(schid); | |
236 | if (ret == -ENXIO) | |
237 | return ret; /* We're through. */ | |
238 | if (ret == -ENOMEM) | |
239 | /* Stop validation for now. Bad, but no need for a panic. */ | |
240 | return ret; | |
241 | return 0; | |
242 | } | |
243 | ||
1da177e4 LT |
244 | /* |
245 | * Function: s390_redo_validation | |
246 | * Look for no longer blacklisted devices | |
247 | * FIXME: there must be a better way to do this */ | |
248 | static inline void | |
249 | s390_redo_validation (void) | |
250 | { | |
1da177e4 | 251 | CIO_TRACE_EVENT (0, "redoval"); |
1da177e4 | 252 | |
f97a56fb | 253 | for_each_subchannel(__s390_redo_validation, NULL); |
1da177e4 LT |
254 | } |
255 | ||
256 | /* | |
257 | * Function: blacklist_parse_proc_parameters | |
258 | * parse the stuff which is piped to /proc/cio_ignore | |
259 | */ | |
260 | static inline void | |
261 | blacklist_parse_proc_parameters (char *buf) | |
262 | { | |
263 | if (strncmp (buf, "free ", 5) == 0) { | |
264 | blacklist_parse_parameters (buf + 5, free); | |
265 | } else if (strncmp (buf, "add ", 4) == 0) { | |
266 | /* | |
267 | * We don't need to check for known devices since | |
268 | * css_probe_device will handle this correctly. | |
269 | */ | |
270 | blacklist_parse_parameters (buf + 4, add); | |
271 | } else { | |
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"); | |
277 | return; | |
278 | } | |
279 | ||
280 | s390_redo_validation (); | |
281 | } | |
282 | ||
678a395b CH |
283 | /* Iterator struct for all devices. */ |
284 | struct ccwdev_iter { | |
285 | int devno; | |
286 | int in_range; | |
287 | }; | |
288 | ||
289 | static void * | |
290 | cio_ignore_proc_seq_start(struct seq_file *s, loff_t *offset) | |
1da177e4 | 291 | { |
678a395b CH |
292 | struct ccwdev_iter *iter; |
293 | ||
294 | if (*offset > __MAX_SUBCHANNEL) | |
295 | return NULL; | |
296 | iter = kmalloc(sizeof(struct ccwdev_iter), GFP_KERNEL); | |
297 | if (!iter) | |
298 | return ERR_PTR(-ENOMEM); | |
299 | memset(iter, 0, sizeof(struct ccwdev_iter)); | |
300 | iter->devno = *offset; | |
301 | return iter; | |
302 | } | |
303 | ||
304 | static void | |
305 | cio_ignore_proc_seq_stop(struct seq_file *s, void *it) | |
306 | { | |
307 | if (!IS_ERR(it)) | |
308 | kfree(it); | |
309 | } | |
1da177e4 | 310 | |
678a395b CH |
311 | static void * |
312 | cio_ignore_proc_seq_next(struct seq_file *s, void *it, loff_t *offset) | |
313 | { | |
314 | struct ccwdev_iter *iter; | |
315 | ||
316 | if (*offset > __MAX_SUBCHANNEL) | |
317 | return NULL; | |
318 | iter = (struct ccwdev_iter *)it; | |
319 | iter->devno++; | |
320 | (*offset)++; | |
321 | return iter; | |
1da177e4 LT |
322 | } |
323 | ||
678a395b CH |
324 | static int |
325 | cio_ignore_proc_seq_show(struct seq_file *s, void *it) | |
326 | { | |
327 | struct ccwdev_iter *iter; | |
328 | ||
329 | iter = (struct ccwdev_iter *)it; | |
330 | if (!is_blacklisted(iter->devno)) | |
331 | /* Not blacklisted, nothing to output. */ | |
332 | return 0; | |
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); | |
339 | iter->in_range = 1; | |
340 | return seq_printf(s, "0.0.%04x-", iter->devno); | |
341 | } | |
342 | if ((iter->devno == __MAX_SUBCHANNEL) || | |
343 | !is_blacklisted(iter->devno + 1)) { | |
344 | /* Last device in range. */ | |
345 | iter->in_range = 0; | |
346 | return seq_printf(s, "0.0.%04x\n", iter->devno); | |
347 | } | |
348 | return 0; | |
349 | } | |
350 | ||
351 | static ssize_t | |
352 | cio_ignore_write(struct file *file, const char __user *user_buf, | |
353 | size_t user_len, loff_t *offset) | |
1da177e4 LT |
354 | { |
355 | char *buf; | |
356 | ||
678a395b CH |
357 | if (*offset) |
358 | return -EINVAL; | |
1da177e4 LT |
359 | if (user_len > 65536) |
360 | user_len = 65536; | |
361 | buf = vmalloc (user_len + 1); /* maybe better use the stack? */ | |
362 | if (buf == NULL) | |
363 | return -ENOMEM; | |
364 | if (strncpy_from_user (buf, user_buf, user_len) < 0) { | |
365 | vfree (buf); | |
366 | return -EFAULT; | |
367 | } | |
368 | buf[user_len] = '\0'; | |
369 | ||
370 | blacklist_parse_proc_parameters (buf); | |
371 | ||
372 | vfree (buf); | |
373 | return user_len; | |
374 | } | |
375 | ||
678a395b CH |
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, | |
381 | }; | |
382 | ||
383 | static int | |
384 | cio_ignore_proc_open(struct inode *inode, struct file *file) | |
385 | { | |
386 | return seq_open(file, &cio_ignore_proc_seq_ops); | |
387 | } | |
388 | ||
389 | static struct file_operations cio_ignore_proc_fops = { | |
390 | .open = cio_ignore_proc_open, | |
391 | .read = seq_read, | |
392 | .llseek = seq_lseek, | |
393 | .release = seq_release, | |
394 | .write = cio_ignore_write, | |
395 | }; | |
396 | ||
1da177e4 LT |
397 | static int |
398 | cio_ignore_proc_init (void) | |
399 | { | |
400 | struct proc_dir_entry *entry; | |
401 | ||
402 | entry = create_proc_entry ("cio_ignore", S_IFREG | S_IRUGO | S_IWUSR, | |
403 | &proc_root); | |
404 | if (!entry) | |
405 | return 0; | |
406 | ||
678a395b | 407 | entry->proc_fops = &cio_ignore_proc_fops; |
1da177e4 LT |
408 | |
409 | return 1; | |
410 | } | |
411 | ||
412 | __initcall (cio_ignore_proc_init); | |
413 | ||
414 | #endif /* CONFIG_PROC_FS */ |