[S390] cio: Remove cio_msg kernel parameter.
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / s390 / cio / blacklist.c
CommitLineData
1da177e4
LT
1/*
2 * drivers/s390/cio/blacklist.c
3 * S/390 common I/O routines -- blacklisting of specific devices
1da177e4
LT
4 *
5 * Copyright (C) 1999-2002 IBM Deutschland Entwicklung GmbH,
6 * IBM Corporation
7 * Author(s): Ingo Adlung (adlung@de.ibm.com)
4ce3b30c 8 * Cornelia Huck (cornelia.huck@de.ibm.com)
1da177e4
LT
9 * Arnd Bergmann (arndb@de.ibm.com)
10 */
11
1da177e4
LT
12#include <linux/init.h>
13#include <linux/vmalloc.h>
14#include <linux/slab.h>
15#include <linux/proc_fs.h>
678a395b 16#include <linux/seq_file.h>
1da177e4
LT
17#include <linux/ctype.h>
18#include <linux/device.h>
19
20#include <asm/cio.h>
21#include <asm/uaccess.h>
22
23#include "blacklist.h"
24#include "cio.h"
25#include "cio_debug.h"
26#include "css.h"
27
28/*
29 * "Blacklisting" of certain devices:
30 * Device numbers given in the commandline as cio_ignore=... won't be known
31 * to Linux.
32 *
33 * These can be single devices or ranges of devices
34 */
35
fb6958a5 36/* 65536 bits for each set to indicate if a devno is blacklisted or not */
a8237fc4 37#define __BL_DEV_WORDS ((__MAX_SUBCHANNEL + (8*sizeof(long) - 1)) / \
1da177e4 38 (8*sizeof(long)))
fb6958a5 39static unsigned long bl_dev[__MAX_SSID + 1][__BL_DEV_WORDS];
1da177e4
LT
40typedef enum {add, free} range_action;
41
42/*
43 * Function: blacklist_range
44 * (Un-)blacklist the devices from-to
45 */
4d284cac 46static void
fb6958a5
CH
47blacklist_range (range_action action, unsigned int from, unsigned int to,
48 unsigned int ssid)
1da177e4
LT
49{
50 if (!to)
51 to = from;
52
fb6958a5 53 if (from > to || to > __MAX_SUBCHANNEL || ssid > __MAX_SSID) {
e556bbbd 54 printk (KERN_WARNING "cio: Invalid blacklist range "
fb6958a5
CH
55 "0.%x.%04x to 0.%x.%04x, skipping\n",
56 ssid, from, ssid, to);
1da177e4
LT
57 return;
58 }
59 for (; from <= to; from++) {
60 if (action == add)
fb6958a5 61 set_bit (from, bl_dev[ssid]);
1da177e4 62 else
fb6958a5 63 clear_bit (from, bl_dev[ssid]);
1da177e4
LT
64 }
65}
66
67/*
68 * Function: blacklist_busid
69 * Get devno/busid from given string.
70 * Shamelessly grabbed from dasd_devmap.c.
71 */
4d284cac 72static int
fb6958a5 73blacklist_busid(char **str, int *id0, int *ssid, int *devno)
1da177e4
LT
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] != '.') {
fb6958a5 90 *id0 = *ssid = 0;
1da177e4
LT
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;
fb6958a5 109 *ssid = val;
1da177e4
LT
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;
120confused:
121 strsep(str, ",\n");
e556bbbd 122 printk(KERN_WARNING "cio: Invalid cio_ignore parameter '%s'\n", sav);
1da177e4
LT
123 return 1;
124}
125
4d284cac 126static int
1da177e4
LT
127blacklist_parse_parameters (char *str, range_action action)
128{
2b67fc46 129 int from, to, from_id0, to_id0, from_ssid, to_ssid;
1da177e4
LT
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) {
fb6958a5
CH
146 int j;
147
1da177e4 148 str += 3;
fb6958a5
CH
149 for (j=0; j <= __MAX_SSID; j++)
150 blacklist_range(ra, 0, __MAX_SUBCHANNEL, j);
1da177e4
LT
151 } else {
152 int rc;
153
154 rc = blacklist_busid(&str, &from_id0,
fb6958a5 155 &from_ssid, &from);
1da177e4
LT
156 if (rc)
157 continue;
158 to = from;
159 to_id0 = from_id0;
fb6958a5 160 to_ssid = from_ssid;
1da177e4
LT
161 if (*str == '-') {
162 str++;
163 rc = blacklist_busid(&str, &to_id0,
fb6958a5 164 &to_ssid, &to);
1da177e4
LT
165 if (rc)
166 continue;
167 }
168 if (*str == '-') {
e556bbbd 169 printk(KERN_WARNING "cio: invalid cio_ignore "
1da177e4
LT
170 "parameter '%s'\n",
171 strsep(&str, ",\n"));
172 continue;
173 }
fb6958a5
CH
174 if ((from_id0 != to_id0) ||
175 (from_ssid != to_ssid)) {
e556bbbd
CH
176 printk(KERN_WARNING "cio: invalid cio_ignore "
177 "range %x.%x.%04x-%x.%x.%04x\n",
178 from_id0, from_ssid, from,
179 to_id0, to_ssid, to);
1da177e4
LT
180 continue;
181 }
fb6958a5 182 blacklist_range (ra, from, to, to_ssid);
1da177e4 183 }
1da177e4
LT
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 */
199static int __init
200blacklist_setup (char *str)
201{
1da177e4
LT
202 return blacklist_parse_parameters (str, add);
203}
204
205__setup ("cio_ignore=", blacklist_setup);
206
207/* Checking if devices are blacklisted */
208
209/*
210 * Function: is_blacklisted
211 * Returns 1 if the given devicenumber can be found in the blacklist,
212 * otherwise 0.
213 * Used by validate_subchannel()
214 */
215int
fb6958a5 216is_blacklisted (int ssid, int devno)
1da177e4 217{
fb6958a5 218 return test_bit (devno, bl_dev[ssid]);
1da177e4
LT
219}
220
221#ifdef CONFIG_PROC_FS
1da177e4
LT
222/*
223 * Function: blacklist_parse_proc_parameters
224 * parse the stuff which is piped to /proc/cio_ignore
225 */
4d284cac 226static void
1da177e4
LT
227blacklist_parse_proc_parameters (char *buf)
228{
229 if (strncmp (buf, "free ", 5) == 0) {
230 blacklist_parse_parameters (buf + 5, free);
231 } else if (strncmp (buf, "add ", 4) == 0) {
232 /*
233 * We don't need to check for known devices since
234 * css_probe_device will handle this correctly.
235 */
236 blacklist_parse_parameters (buf + 4, add);
237 } else {
e556bbbd 238 printk (KERN_WARNING "cio: cio_ignore: Parse error; \n"
1da177e4
LT
239 KERN_WARNING "try using 'free all|<devno-range>,"
240 "<devno-range>,...'\n"
241 KERN_WARNING "or 'add <devno-range>,"
242 "<devno-range>,...'\n");
243 return;
244 }
245
40154b82 246 css_schedule_reprobe();
1da177e4
LT
247}
248
678a395b
CH
249/* Iterator struct for all devices. */
250struct ccwdev_iter {
251 int devno;
fb6958a5 252 int ssid;
678a395b
CH
253 int in_range;
254};
255
256static void *
257cio_ignore_proc_seq_start(struct seq_file *s, loff_t *offset)
1da177e4 258{
678a395b
CH
259 struct ccwdev_iter *iter;
260
fb6958a5 261 if (*offset >= (__MAX_SUBCHANNEL + 1) * (__MAX_SSID + 1))
678a395b 262 return NULL;
3b793060 263 iter = kzalloc(sizeof(struct ccwdev_iter), GFP_KERNEL);
678a395b
CH
264 if (!iter)
265 return ERR_PTR(-ENOMEM);
fb6958a5
CH
266 iter->ssid = *offset / (__MAX_SUBCHANNEL + 1);
267 iter->devno = *offset % (__MAX_SUBCHANNEL + 1);
678a395b
CH
268 return iter;
269}
270
271static void
272cio_ignore_proc_seq_stop(struct seq_file *s, void *it)
273{
274 if (!IS_ERR(it))
275 kfree(it);
276}
1da177e4 277
678a395b
CH
278static void *
279cio_ignore_proc_seq_next(struct seq_file *s, void *it, loff_t *offset)
280{
281 struct ccwdev_iter *iter;
282
fb6958a5 283 if (*offset >= (__MAX_SUBCHANNEL + 1) * (__MAX_SSID + 1))
678a395b 284 return NULL;
3b793060 285 iter = it;
fb6958a5
CH
286 if (iter->devno == __MAX_SUBCHANNEL) {
287 iter->devno = 0;
288 iter->ssid++;
289 if (iter->ssid > __MAX_SSID)
290 return NULL;
291 } else
292 iter->devno++;
678a395b
CH
293 (*offset)++;
294 return iter;
1da177e4
LT
295}
296
678a395b
CH
297static int
298cio_ignore_proc_seq_show(struct seq_file *s, void *it)
299{
300 struct ccwdev_iter *iter;
301
3b793060 302 iter = it;
fb6958a5 303 if (!is_blacklisted(iter->ssid, iter->devno))
678a395b
CH
304 /* Not blacklisted, nothing to output. */
305 return 0;
306 if (!iter->in_range) {
307 /* First device in range. */
308 if ((iter->devno == __MAX_SUBCHANNEL) ||
fb6958a5 309 !is_blacklisted(iter->ssid, iter->devno + 1))
678a395b 310 /* Singular device. */
fb6958a5
CH
311 return seq_printf(s, "0.%x.%04x\n",
312 iter->ssid, iter->devno);
678a395b 313 iter->in_range = 1;
fb6958a5 314 return seq_printf(s, "0.%x.%04x-", iter->ssid, iter->devno);
678a395b
CH
315 }
316 if ((iter->devno == __MAX_SUBCHANNEL) ||
fb6958a5 317 !is_blacklisted(iter->ssid, iter->devno + 1)) {
678a395b
CH
318 /* Last device in range. */
319 iter->in_range = 0;
fb6958a5 320 return seq_printf(s, "0.%x.%04x\n", iter->ssid, iter->devno);
678a395b
CH
321 }
322 return 0;
323}
324
325static ssize_t
326cio_ignore_write(struct file *file, const char __user *user_buf,
327 size_t user_len, loff_t *offset)
1da177e4
LT
328{
329 char *buf;
330
678a395b
CH
331 if (*offset)
332 return -EINVAL;
1da177e4
LT
333 if (user_len > 65536)
334 user_len = 65536;
335 buf = vmalloc (user_len + 1); /* maybe better use the stack? */
336 if (buf == NULL)
337 return -ENOMEM;
338 if (strncpy_from_user (buf, user_buf, user_len) < 0) {
339 vfree (buf);
340 return -EFAULT;
341 }
342 buf[user_len] = '\0';
343
344 blacklist_parse_proc_parameters (buf);
345
346 vfree (buf);
347 return user_len;
348}
349
5c81cdbe 350static const struct seq_operations cio_ignore_proc_seq_ops = {
678a395b
CH
351 .start = cio_ignore_proc_seq_start,
352 .stop = cio_ignore_proc_seq_stop,
353 .next = cio_ignore_proc_seq_next,
354 .show = cio_ignore_proc_seq_show,
355};
356
357static int
358cio_ignore_proc_open(struct inode *inode, struct file *file)
359{
360 return seq_open(file, &cio_ignore_proc_seq_ops);
361}
362
d54b1fdb 363static const struct file_operations cio_ignore_proc_fops = {
678a395b
CH
364 .open = cio_ignore_proc_open,
365 .read = seq_read,
366 .llseek = seq_lseek,
367 .release = seq_release,
368 .write = cio_ignore_write,
369};
370
1da177e4
LT
371static int
372cio_ignore_proc_init (void)
373{
374 struct proc_dir_entry *entry;
375
8b594007
DL
376 entry = proc_create("cio_ignore", S_IFREG | S_IRUGO | S_IWUSR, NULL,
377 &cio_ignore_proc_fops);
1da177e4 378 if (!entry)
a7fbf6bb 379 return -ENOENT;
a7fbf6bb 380 return 0;
1da177e4
LT
381}
382
383__initcall (cio_ignore_proc_init);
384
385#endif /* CONFIG_PROC_FS */