Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * S/390 common I/O routines -- blacklisting of specific devices |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * |
Sebastian Ott | 0e6c83d | 2013-04-30 17:16:17 +0200 | [diff] [blame] | 4 | * Copyright IBM Corp. 1999, 2013 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * Author(s): Ingo Adlung (adlung@de.ibm.com) |
Cornelia Huck | 4ce3b30 | 2006-01-14 13:21:04 -0800 | [diff] [blame] | 6 | * Cornelia Huck (cornelia.huck@de.ibm.com) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * Arnd Bergmann (arndb@de.ibm.com) |
| 8 | */ |
| 9 | |
Michael Ernst | e6d5a42 | 2008-12-25 13:39:36 +0100 | [diff] [blame] | 10 | #define KMSG_COMPONENT "cio" |
| 11 | #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt |
| 12 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <linux/init.h> |
| 14 | #include <linux/vmalloc.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <linux/proc_fs.h> |
Cornelia Huck | 678a395 | 2006-01-06 00:19:24 -0800 | [diff] [blame] | 16 | #include <linux/seq_file.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <linux/ctype.h> |
| 18 | #include <linux/device.h> |
| 19 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include <asm/uaccess.h> |
Sebastian Ott | 0e6c83d | 2013-04-30 17:16:17 +0200 | [diff] [blame] | 21 | #include <asm/cio.h> |
| 22 | #include <asm/ipl.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | |
| 24 | #include "blacklist.h" |
| 25 | #include "cio.h" |
| 26 | #include "cio_debug.h" |
| 27 | #include "css.h" |
Peter Oberparleiter | ecf5d9e | 2008-10-10 21:33:06 +0200 | [diff] [blame] | 28 | #include "device.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 38 | /* 65536 bits for each set to indicate if a devno is blacklisted or not */ |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 39 | #define __BL_DEV_WORDS ((__MAX_SUBCHANNEL + (8*sizeof(long) - 1)) / \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | (8*sizeof(long))) |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 41 | static unsigned long bl_dev[__MAX_SSID + 1][__BL_DEV_WORDS]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | typedef enum {add, free} range_action; |
| 43 | |
| 44 | /* |
| 45 | * Function: blacklist_range |
| 46 | * (Un-)blacklist the devices from-to |
| 47 | */ |
Michael Ernst | 5b89098 | 2008-05-07 09:22:55 +0200 | [diff] [blame] | 48 | static int blacklist_range(range_action action, unsigned int from_ssid, |
| 49 | unsigned int to_ssid, unsigned int from, |
| 50 | unsigned int to, int msgtrigger) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | { |
Michael Ernst | 5b89098 | 2008-05-07 09:22:55 +0200 | [diff] [blame] | 52 | if ((from_ssid > to_ssid) || ((from_ssid == to_ssid) && (from > to))) { |
| 53 | if (msgtrigger) |
Michael Ernst | e6d5a42 | 2008-12-25 13:39:36 +0100 | [diff] [blame] | 54 | pr_warning("0.%x.%04x to 0.%x.%04x is not a valid " |
| 55 | "range for cio_ignore\n", from_ssid, from, |
| 56 | to_ssid, to); |
| 57 | |
Michael Ernst | 5b89098 | 2008-05-07 09:22:55 +0200 | [diff] [blame] | 58 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | } |
Michael Ernst | 5b89098 | 2008-05-07 09:22:55 +0200 | [diff] [blame] | 60 | |
| 61 | while ((from_ssid < to_ssid) || ((from_ssid == to_ssid) && |
| 62 | (from <= to))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | if (action == add) |
Michael Ernst | 5b89098 | 2008-05-07 09:22:55 +0200 | [diff] [blame] | 64 | set_bit(from, bl_dev[from_ssid]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | else |
Michael Ernst | 5b89098 | 2008-05-07 09:22:55 +0200 | [diff] [blame] | 66 | clear_bit(from, bl_dev[from_ssid]); |
| 67 | from++; |
| 68 | if (from > __MAX_SUBCHANNEL) { |
| 69 | from_ssid++; |
| 70 | from = 0; |
| 71 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | } |
| 76 | |
Michael Ernst | 5b89098 | 2008-05-07 09:22:55 +0200 | [diff] [blame] | 77 | static int pure_hex(char **cp, unsigned int *val, int min_digit, |
| 78 | int max_digit, int max_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | { |
Michael Ernst | 5b89098 | 2008-05-07 09:22:55 +0200 | [diff] [blame] | 80 | int diff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | |
Michael Ernst | 5b89098 | 2008-05-07 09:22:55 +0200 | [diff] [blame] | 82 | diff = 0; |
| 83 | *val = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | |
Andy Shevchenko | f277707 | 2010-10-25 16:10:25 +0200 | [diff] [blame] | 85 | while (diff <= max_digit) { |
| 86 | int value = hex_to_bin(**cp); |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 87 | |
Andy Shevchenko | f277707 | 2010-10-25 16:10:25 +0200 | [diff] [blame] | 88 | if (value < 0) |
| 89 | break; |
Michael Ernst | 5b89098 | 2008-05-07 09:22:55 +0200 | [diff] [blame] | 90 | *val = *val * 16 + value; |
| 91 | (*cp)++; |
| 92 | diff++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | } |
Michael Ernst | 5b89098 | 2008-05-07 09:22:55 +0200 | [diff] [blame] | 94 | |
| 95 | if ((diff < min_digit) || (diff > max_digit) || (*val > max_val)) |
| 96 | return 1; |
| 97 | |
| 98 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | } |
| 100 | |
Cornelia Huck | 1282912 | 2008-06-10 10:03:19 +0200 | [diff] [blame] | 101 | static int parse_busid(char *str, unsigned int *cssid, unsigned int *ssid, |
| 102 | unsigned int *devno, int msgtrigger) |
Michael Ernst | 5b89098 | 2008-05-07 09:22:55 +0200 | [diff] [blame] | 103 | { |
| 104 | char *str_work; |
| 105 | int val, rc, ret; |
| 106 | |
| 107 | rc = 1; |
| 108 | |
| 109 | if (*str == '\0') |
| 110 | goto out; |
| 111 | |
| 112 | /* old style */ |
| 113 | str_work = str; |
| 114 | val = simple_strtoul(str, &str_work, 16); |
| 115 | |
| 116 | if (*str_work == '\0') { |
| 117 | if (val <= __MAX_SUBCHANNEL) { |
| 118 | *devno = val; |
| 119 | *ssid = 0; |
| 120 | *cssid = 0; |
| 121 | rc = 0; |
| 122 | } |
| 123 | goto out; |
| 124 | } |
| 125 | |
| 126 | /* new style */ |
| 127 | str_work = str; |
| 128 | ret = pure_hex(&str_work, cssid, 1, 2, __MAX_CSSID); |
| 129 | if (ret || (str_work[0] != '.')) |
| 130 | goto out; |
| 131 | str_work++; |
| 132 | ret = pure_hex(&str_work, ssid, 1, 1, __MAX_SSID); |
| 133 | if (ret || (str_work[0] != '.')) |
| 134 | goto out; |
| 135 | str_work++; |
| 136 | ret = pure_hex(&str_work, devno, 4, 4, __MAX_SUBCHANNEL); |
| 137 | if (ret || (str_work[0] != '\0')) |
| 138 | goto out; |
| 139 | |
| 140 | rc = 0; |
| 141 | out: |
| 142 | if (rc && msgtrigger) |
Michael Ernst | e6d5a42 | 2008-12-25 13:39:36 +0100 | [diff] [blame] | 143 | pr_warning("%s is not a valid device for the cio_ignore " |
| 144 | "kernel parameter\n", str); |
Michael Ernst | 5b89098 | 2008-05-07 09:22:55 +0200 | [diff] [blame] | 145 | |
| 146 | return rc; |
| 147 | } |
| 148 | |
| 149 | static int blacklist_parse_parameters(char *str, range_action action, |
| 150 | int msgtrigger) |
| 151 | { |
Cornelia Huck | 1282912 | 2008-06-10 10:03:19 +0200 | [diff] [blame] | 152 | unsigned int from_cssid, to_cssid, from_ssid, to_ssid, from, to; |
Michael Ernst | 5b89098 | 2008-05-07 09:22:55 +0200 | [diff] [blame] | 153 | int rc, totalrc; |
| 154 | char *parm; |
| 155 | range_action ra; |
| 156 | |
| 157 | totalrc = 0; |
| 158 | |
| 159 | while ((parm = strsep(&str, ","))) { |
| 160 | rc = 0; |
| 161 | ra = action; |
| 162 | if (*parm == '!') { |
| 163 | if (ra == add) |
| 164 | ra = free; |
| 165 | else |
| 166 | ra = add; |
| 167 | parm++; |
| 168 | } |
| 169 | if (strcmp(parm, "all") == 0) { |
| 170 | from_cssid = 0; |
| 171 | from_ssid = 0; |
| 172 | from = 0; |
| 173 | to_cssid = __MAX_CSSID; |
| 174 | to_ssid = __MAX_SSID; |
| 175 | to = __MAX_SUBCHANNEL; |
Sebastian Ott | 0e6c83d | 2013-04-30 17:16:17 +0200 | [diff] [blame] | 176 | } else if (strcmp(parm, "ipldev") == 0) { |
| 177 | if (ipl_info.type == IPL_TYPE_CCW) { |
| 178 | from_cssid = 0; |
| 179 | from_ssid = ipl_info.data.ccw.dev_id.ssid; |
| 180 | from = ipl_info.data.ccw.dev_id.devno; |
| 181 | } else if (ipl_info.type == IPL_TYPE_FCP || |
| 182 | ipl_info.type == IPL_TYPE_FCP_DUMP) { |
| 183 | from_cssid = 0; |
| 184 | from_ssid = ipl_info.data.fcp.dev_id.ssid; |
| 185 | from = ipl_info.data.fcp.dev_id.devno; |
| 186 | } else { |
| 187 | continue; |
| 188 | } |
| 189 | to_cssid = from_cssid; |
| 190 | to_ssid = from_ssid; |
| 191 | to = from; |
Sebastian Ott | d1eb16e | 2013-04-30 17:17:34 +0200 | [diff] [blame] | 192 | } else if (strcmp(parm, "condev") == 0) { |
| 193 | if (console_devno == -1) |
| 194 | continue; |
| 195 | |
| 196 | from_cssid = to_cssid = 0; |
| 197 | from_ssid = to_ssid = 0; |
| 198 | from = to = console_devno; |
Michael Ernst | 5b89098 | 2008-05-07 09:22:55 +0200 | [diff] [blame] | 199 | } else { |
| 200 | rc = parse_busid(strsep(&parm, "-"), &from_cssid, |
| 201 | &from_ssid, &from, msgtrigger); |
| 202 | if (!rc) { |
| 203 | if (parm != NULL) |
| 204 | rc = parse_busid(parm, &to_cssid, |
| 205 | &to_ssid, &to, |
| 206 | msgtrigger); |
| 207 | else { |
| 208 | to_cssid = from_cssid; |
| 209 | to_ssid = from_ssid; |
| 210 | to = from; |
| 211 | } |
| 212 | } |
| 213 | } |
| 214 | if (!rc) { |
| 215 | rc = blacklist_range(ra, from_ssid, to_ssid, from, to, |
| 216 | msgtrigger); |
| 217 | if (rc) |
Peter Oberparleiter | ecf5d9e | 2008-10-10 21:33:06 +0200 | [diff] [blame] | 218 | totalrc = -EINVAL; |
Michael Ernst | 5b89098 | 2008-05-07 09:22:55 +0200 | [diff] [blame] | 219 | } else |
Peter Oberparleiter | ecf5d9e | 2008-10-10 21:33:06 +0200 | [diff] [blame] | 220 | totalrc = -EINVAL; |
Michael Ernst | 5b89098 | 2008-05-07 09:22:55 +0200 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | return totalrc; |
| 224 | } |
| 225 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | static int __init |
| 227 | blacklist_setup (char *str) |
| 228 | { |
Michael Ernst | 5b89098 | 2008-05-07 09:22:55 +0200 | [diff] [blame] | 229 | CIO_MSG_EVENT(6, "Reading blacklist parameters\n"); |
| 230 | if (blacklist_parse_parameters(str, add, 1)) |
| 231 | return 0; |
| 232 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | __setup ("cio_ignore=", blacklist_setup); |
| 236 | |
| 237 | /* Checking if devices are blacklisted */ |
| 238 | |
| 239 | /* |
| 240 | * Function: is_blacklisted |
| 241 | * Returns 1 if the given devicenumber can be found in the blacklist, |
| 242 | * otherwise 0. |
| 243 | * Used by validate_subchannel() |
| 244 | */ |
| 245 | int |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 246 | is_blacklisted (int ssid, int devno) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | { |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 248 | return test_bit (devno, bl_dev[ssid]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | #ifdef CONFIG_PROC_FS |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | /* |
| 253 | * Function: blacklist_parse_proc_parameters |
| 254 | * parse the stuff which is piped to /proc/cio_ignore |
| 255 | */ |
Michael Ernst | 5b89098 | 2008-05-07 09:22:55 +0200 | [diff] [blame] | 256 | static int blacklist_parse_proc_parameters(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | { |
Michael Ernst | 5b89098 | 2008-05-07 09:22:55 +0200 | [diff] [blame] | 258 | int rc; |
| 259 | char *parm; |
| 260 | |
| 261 | parm = strsep(&buf, " "); |
| 262 | |
Peter Oberparleiter | e6b2551 | 2013-11-26 15:00:37 +0100 | [diff] [blame] | 263 | if (strcmp("free", parm) == 0) { |
Michael Ernst | 5b89098 | 2008-05-07 09:22:55 +0200 | [diff] [blame] | 264 | rc = blacklist_parse_parameters(buf, free, 0); |
Peter Oberparleiter | e6b2551 | 2013-11-26 15:00:37 +0100 | [diff] [blame] | 265 | css_schedule_eval_all_unreg(0); |
| 266 | } else if (strcmp("add", parm) == 0) |
Michael Ernst | 5b89098 | 2008-05-07 09:22:55 +0200 | [diff] [blame] | 267 | rc = blacklist_parse_parameters(buf, add, 0); |
Peter Oberparleiter | ecf5d9e | 2008-10-10 21:33:06 +0200 | [diff] [blame] | 268 | else if (strcmp("purge", parm) == 0) |
| 269 | return ccw_purge_blacklisted(); |
Michael Ernst | 5b89098 | 2008-05-07 09:22:55 +0200 | [diff] [blame] | 270 | else |
Peter Oberparleiter | ecf5d9e | 2008-10-10 21:33:06 +0200 | [diff] [blame] | 271 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | |
Michael Ernst | 5b89098 | 2008-05-07 09:22:55 +0200 | [diff] [blame] | 273 | |
| 274 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | } |
| 276 | |
Cornelia Huck | 678a395 | 2006-01-06 00:19:24 -0800 | [diff] [blame] | 277 | /* Iterator struct for all devices. */ |
| 278 | struct ccwdev_iter { |
| 279 | int devno; |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 280 | int ssid; |
Cornelia Huck | 678a395 | 2006-01-06 00:19:24 -0800 | [diff] [blame] | 281 | int in_range; |
| 282 | }; |
| 283 | |
| 284 | static void * |
| 285 | cio_ignore_proc_seq_start(struct seq_file *s, loff_t *offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | { |
Christian Borntraeger | 05d419b | 2009-10-06 10:34:00 +0200 | [diff] [blame] | 287 | struct ccwdev_iter *iter = s->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 289 | if (*offset >= (__MAX_SUBCHANNEL + 1) * (__MAX_SSID + 1)) |
Cornelia Huck | 678a395 | 2006-01-06 00:19:24 -0800 | [diff] [blame] | 290 | return NULL; |
Christian Borntraeger | 05d419b | 2009-10-06 10:34:00 +0200 | [diff] [blame] | 291 | memset(iter, 0, sizeof(*iter)); |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 292 | iter->ssid = *offset / (__MAX_SUBCHANNEL + 1); |
| 293 | iter->devno = *offset % (__MAX_SUBCHANNEL + 1); |
Cornelia Huck | 678a395 | 2006-01-06 00:19:24 -0800 | [diff] [blame] | 294 | return iter; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | } |
| 296 | |
Cornelia Huck | 678a395 | 2006-01-06 00:19:24 -0800 | [diff] [blame] | 297 | static void |
| 298 | cio_ignore_proc_seq_stop(struct seq_file *s, void *it) |
| 299 | { |
Cornelia Huck | 678a395 | 2006-01-06 00:19:24 -0800 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | static void * |
| 303 | cio_ignore_proc_seq_next(struct seq_file *s, void *it, loff_t *offset) |
| 304 | { |
| 305 | struct ccwdev_iter *iter; |
| 306 | |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 307 | if (*offset >= (__MAX_SUBCHANNEL + 1) * (__MAX_SSID + 1)) |
Cornelia Huck | 678a395 | 2006-01-06 00:19:24 -0800 | [diff] [blame] | 308 | return NULL; |
Cornelia Huck | 3b79306 | 2006-01-06 00:19:26 -0800 | [diff] [blame] | 309 | iter = it; |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 310 | if (iter->devno == __MAX_SUBCHANNEL) { |
| 311 | iter->devno = 0; |
| 312 | iter->ssid++; |
| 313 | if (iter->ssid > __MAX_SSID) |
| 314 | return NULL; |
| 315 | } else |
| 316 | iter->devno++; |
Cornelia Huck | 678a395 | 2006-01-06 00:19:24 -0800 | [diff] [blame] | 317 | (*offset)++; |
| 318 | return iter; |
| 319 | } |
| 320 | |
| 321 | static int |
| 322 | cio_ignore_proc_seq_show(struct seq_file *s, void *it) |
| 323 | { |
| 324 | struct ccwdev_iter *iter; |
| 325 | |
Cornelia Huck | 3b79306 | 2006-01-06 00:19:26 -0800 | [diff] [blame] | 326 | iter = it; |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 327 | if (!is_blacklisted(iter->ssid, iter->devno)) |
Cornelia Huck | 678a395 | 2006-01-06 00:19:24 -0800 | [diff] [blame] | 328 | /* Not blacklisted, nothing to output. */ |
| 329 | return 0; |
| 330 | if (!iter->in_range) { |
| 331 | /* First device in range. */ |
| 332 | if ((iter->devno == __MAX_SUBCHANNEL) || |
Joe Perches | c2f0b61 | 2015-04-15 16:18:14 -0700 | [diff] [blame] | 333 | !is_blacklisted(iter->ssid, iter->devno + 1)) { |
Cornelia Huck | 678a395 | 2006-01-06 00:19:24 -0800 | [diff] [blame] | 334 | /* Singular device. */ |
Joe Perches | c2f0b61 | 2015-04-15 16:18:14 -0700 | [diff] [blame] | 335 | seq_printf(s, "0.%x.%04x\n", iter->ssid, iter->devno); |
| 336 | return 0; |
| 337 | } |
Cornelia Huck | 678a395 | 2006-01-06 00:19:24 -0800 | [diff] [blame] | 338 | iter->in_range = 1; |
Joe Perches | c2f0b61 | 2015-04-15 16:18:14 -0700 | [diff] [blame] | 339 | seq_printf(s, "0.%x.%04x-", iter->ssid, iter->devno); |
| 340 | return 0; |
Cornelia Huck | 678a395 | 2006-01-06 00:19:24 -0800 | [diff] [blame] | 341 | } |
| 342 | if ((iter->devno == __MAX_SUBCHANNEL) || |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 343 | !is_blacklisted(iter->ssid, iter->devno + 1)) { |
Cornelia Huck | 678a395 | 2006-01-06 00:19:24 -0800 | [diff] [blame] | 344 | /* Last device in range. */ |
| 345 | iter->in_range = 0; |
Joe Perches | c2f0b61 | 2015-04-15 16:18:14 -0700 | [diff] [blame] | 346 | seq_printf(s, "0.%x.%04x\n", iter->ssid, iter->devno); |
Cornelia Huck | 678a395 | 2006-01-06 00:19:24 -0800 | [diff] [blame] | 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) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | { |
| 355 | char *buf; |
Sebastian Ott | 94cbc20 | 2009-03-26 15:24:16 +0100 | [diff] [blame] | 356 | ssize_t rc, ret, i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | |
Cornelia Huck | 678a395 | 2006-01-06 00:19:24 -0800 | [diff] [blame] | 358 | if (*offset) |
| 359 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | if (user_len > 65536) |
| 361 | user_len = 65536; |
Joe Perches | dc8a5c9 | 2011-05-28 10:36:21 -0700 | [diff] [blame] | 362 | buf = vzalloc(user_len + 1); /* maybe better use the stack? */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | if (buf == NULL) |
| 364 | return -ENOMEM; |
Michael Ernst | 5b89098 | 2008-05-07 09:22:55 +0200 | [diff] [blame] | 365 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | if (strncpy_from_user (buf, user_buf, user_len) < 0) { |
Michael Ernst | 5b89098 | 2008-05-07 09:22:55 +0200 | [diff] [blame] | 367 | rc = -EFAULT; |
| 368 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | |
Michael Ernst | 5b89098 | 2008-05-07 09:22:55 +0200 | [diff] [blame] | 371 | i = user_len - 1; |
| 372 | while ((i >= 0) && (isspace(buf[i]) || (buf[i] == 0))) { |
| 373 | buf[i] = '\0'; |
| 374 | i--; |
| 375 | } |
| 376 | ret = blacklist_parse_proc_parameters(buf); |
| 377 | if (ret) |
Peter Oberparleiter | ecf5d9e | 2008-10-10 21:33:06 +0200 | [diff] [blame] | 378 | rc = ret; |
Michael Ernst | 5b89098 | 2008-05-07 09:22:55 +0200 | [diff] [blame] | 379 | else |
| 380 | rc = user_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | |
Michael Ernst | 5b89098 | 2008-05-07 09:22:55 +0200 | [diff] [blame] | 382 | out_free: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | vfree (buf); |
Michael Ernst | 5b89098 | 2008-05-07 09:22:55 +0200 | [diff] [blame] | 384 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | } |
| 386 | |
Jan Engelhardt | 5c81cdb | 2008-01-26 14:11:29 +0100 | [diff] [blame] | 387 | static const struct seq_operations cio_ignore_proc_seq_ops = { |
Cornelia Huck | 678a395 | 2006-01-06 00:19:24 -0800 | [diff] [blame] | 388 | .start = cio_ignore_proc_seq_start, |
| 389 | .stop = cio_ignore_proc_seq_stop, |
| 390 | .next = cio_ignore_proc_seq_next, |
| 391 | .show = cio_ignore_proc_seq_show, |
| 392 | }; |
| 393 | |
| 394 | static int |
| 395 | cio_ignore_proc_open(struct inode *inode, struct file *file) |
| 396 | { |
Christian Borntraeger | 05d419b | 2009-10-06 10:34:00 +0200 | [diff] [blame] | 397 | return seq_open_private(file, &cio_ignore_proc_seq_ops, |
| 398 | sizeof(struct ccwdev_iter)); |
Cornelia Huck | 678a395 | 2006-01-06 00:19:24 -0800 | [diff] [blame] | 399 | } |
| 400 | |
Arjan van de Ven | d54b1fd | 2007-02-12 00:55:34 -0800 | [diff] [blame] | 401 | static const struct file_operations cio_ignore_proc_fops = { |
Cornelia Huck | 678a395 | 2006-01-06 00:19:24 -0800 | [diff] [blame] | 402 | .open = cio_ignore_proc_open, |
| 403 | .read = seq_read, |
| 404 | .llseek = seq_lseek, |
Christian Borntraeger | 05d419b | 2009-10-06 10:34:00 +0200 | [diff] [blame] | 405 | .release = seq_release_private, |
Cornelia Huck | 678a395 | 2006-01-06 00:19:24 -0800 | [diff] [blame] | 406 | .write = cio_ignore_write, |
| 407 | }; |
| 408 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | static int |
| 410 | cio_ignore_proc_init (void) |
| 411 | { |
| 412 | struct proc_dir_entry *entry; |
| 413 | |
Denis V. Lunev | 8b59400 | 2008-04-29 01:02:20 -0700 | [diff] [blame] | 414 | entry = proc_create("cio_ignore", S_IFREG | S_IRUGO | S_IWUSR, NULL, |
| 415 | &cio_ignore_proc_fops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | if (!entry) |
Cornelia Huck | a7fbf6b | 2006-04-10 22:53:45 -0700 | [diff] [blame] | 417 | return -ENOENT; |
Cornelia Huck | a7fbf6b | 2006-04-10 22:53:45 -0700 | [diff] [blame] | 418 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | } |
| 420 | |
| 421 | __initcall (cio_ignore_proc_init); |
| 422 | |
| 423 | #endif /* CONFIG_PROC_FS */ |