Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Sebastian Ott | dcbd16d | 2009-06-16 10:30:22 +0200 | [diff] [blame] | 2 | * driver for channel subsystem |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * |
Sebastian Ott | 34aec07 | 2010-10-25 16:10:28 +0200 | [diff] [blame] | 4 | * Copyright IBM Corp. 2002, 2010 |
Sebastian Ott | dcbd16d | 2009-06-16 10:30:22 +0200 | [diff] [blame] | 5 | * |
| 6 | * Author(s): Arnd Bergmann (arndb@de.ibm.com) |
| 7 | * Cornelia Huck (cornelia.huck@de.ibm.com) |
Paul Gortmaker | a00f761 | 2016-10-30 16:37:24 -0400 | [diff] [blame] | 8 | * |
| 9 | * License: GPL |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | */ |
Michael Ernst | e6d5a42 | 2008-12-25 13:39:36 +0100 | [diff] [blame] | 11 | |
| 12 | #define KMSG_COMPONENT "cio" |
| 13 | #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt |
| 14 | |
Paul Gortmaker | a00f761 | 2016-10-30 16:37:24 -0400 | [diff] [blame] | 15 | #include <linux/export.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #include <linux/init.h> |
| 17 | #include <linux/device.h> |
| 18 | #include <linux/slab.h> |
| 19 | #include <linux/errno.h> |
| 20 | #include <linux/list.h> |
Cornelia Huck | a55360d | 2007-10-12 16:11:20 +0200 | [diff] [blame] | 21 | #include <linux/reboot.h> |
Sebastian Ott | dcbd16d | 2009-06-16 10:30:22 +0200 | [diff] [blame] | 22 | #include <linux/suspend.h> |
Sebastian Ott | 879acca5 | 2010-02-26 22:37:25 +0100 | [diff] [blame] | 23 | #include <linux/proc_fs.h> |
Cornelia Huck | 3a3fc29 | 2008-07-14 09:58:58 +0200 | [diff] [blame] | 24 | #include <asm/isc.h> |
Heiko Carstens | f5daba1 | 2009-03-26 15:24:01 +0100 | [diff] [blame] | 25 | #include <asm/crw.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | |
| 27 | #include "css.h" |
| 28 | #include "cio.h" |
| 29 | #include "cio_debug.h" |
| 30 | #include "ioasm.h" |
| 31 | #include "chsc.h" |
Peter Oberparleiter | 40154b8 | 2006-06-29 14:57:03 +0200 | [diff] [blame] | 32 | #include "device.h" |
Peter Oberparleiter | 83b3370 | 2007-04-27 16:01:34 +0200 | [diff] [blame] | 33 | #include "idset.h" |
Peter Oberparleiter | 7ad6a24 | 2007-04-27 16:01:35 +0200 | [diff] [blame] | 34 | #include "chp.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | int css_init_done = 0; |
Sebastian Ott | b0a285d | 2009-09-22 22:58:37 +0200 | [diff] [blame] | 37 | int max_ssid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | |
Sebastian Ott | 98cc43a | 2016-11-08 14:28:03 +0100 | [diff] [blame] | 39 | #define MAX_CSS_IDX 0 |
| 40 | struct channel_subsystem *channel_subsystems[MAX_CSS_IDX + 1]; |
Sebastian Ott | 3041b6a | 2011-03-15 17:08:31 +0100 | [diff] [blame] | 41 | static struct bus_type css_bus_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 43 | int |
Cornelia Huck | f97a56f | 2006-01-06 00:19:22 -0800 | [diff] [blame] | 44 | for_each_subchannel(int(*fn)(struct subchannel_id, void *), void *data) |
| 45 | { |
| 46 | struct subchannel_id schid; |
| 47 | int ret; |
| 48 | |
| 49 | init_subchannel_id(&schid); |
Cornelia Huck | f97a56f | 2006-01-06 00:19:22 -0800 | [diff] [blame] | 50 | do { |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 51 | do { |
| 52 | ret = fn(schid, data); |
| 53 | if (ret) |
| 54 | break; |
| 55 | } while (schid.sch_no++ < __MAX_SUBCHANNEL); |
| 56 | schid.sch_no = 0; |
| 57 | } while (schid.ssid++ < max_ssid); |
Cornelia Huck | f97a56f | 2006-01-06 00:19:22 -0800 | [diff] [blame] | 58 | return ret; |
| 59 | } |
| 60 | |
Peter Oberparleiter | e82a156 | 2008-01-26 14:10:48 +0100 | [diff] [blame] | 61 | struct cb_data { |
| 62 | void *data; |
| 63 | struct idset *set; |
| 64 | int (*fn_known_sch)(struct subchannel *, void *); |
| 65 | int (*fn_unknown_sch)(struct subchannel_id, void *); |
| 66 | }; |
| 67 | |
| 68 | static int call_fn_known_sch(struct device *dev, void *data) |
| 69 | { |
| 70 | struct subchannel *sch = to_subchannel(dev); |
| 71 | struct cb_data *cb = data; |
| 72 | int rc = 0; |
| 73 | |
Peter Oberparleiter | 47d3067 | 2013-11-26 14:59:21 +0100 | [diff] [blame] | 74 | if (cb->set) |
| 75 | idset_sch_del(cb->set, sch->schid); |
Peter Oberparleiter | e82a156 | 2008-01-26 14:10:48 +0100 | [diff] [blame] | 76 | if (cb->fn_known_sch) |
| 77 | rc = cb->fn_known_sch(sch, cb->data); |
| 78 | return rc; |
| 79 | } |
| 80 | |
| 81 | static int call_fn_unknown_sch(struct subchannel_id schid, void *data) |
| 82 | { |
| 83 | struct cb_data *cb = data; |
| 84 | int rc = 0; |
| 85 | |
| 86 | if (idset_sch_contains(cb->set, schid)) |
| 87 | rc = cb->fn_unknown_sch(schid, cb->data); |
| 88 | return rc; |
| 89 | } |
| 90 | |
Sebastian Ott | 90ac24a | 2009-03-26 15:24:11 +0100 | [diff] [blame] | 91 | static int call_fn_all_sch(struct subchannel_id schid, void *data) |
| 92 | { |
| 93 | struct cb_data *cb = data; |
| 94 | struct subchannel *sch; |
| 95 | int rc = 0; |
| 96 | |
| 97 | sch = get_subchannel_by_schid(schid); |
| 98 | if (sch) { |
| 99 | if (cb->fn_known_sch) |
| 100 | rc = cb->fn_known_sch(sch, cb->data); |
| 101 | put_device(&sch->dev); |
| 102 | } else { |
| 103 | if (cb->fn_unknown_sch) |
| 104 | rc = cb->fn_unknown_sch(schid, cb->data); |
| 105 | } |
| 106 | |
| 107 | return rc; |
| 108 | } |
| 109 | |
Peter Oberparleiter | e82a156 | 2008-01-26 14:10:48 +0100 | [diff] [blame] | 110 | int for_each_subchannel_staged(int (*fn_known)(struct subchannel *, void *), |
| 111 | int (*fn_unknown)(struct subchannel_id, |
| 112 | void *), void *data) |
| 113 | { |
| 114 | struct cb_data cb; |
| 115 | int rc; |
| 116 | |
Peter Oberparleiter | e82a156 | 2008-01-26 14:10:48 +0100 | [diff] [blame] | 117 | cb.data = data; |
| 118 | cb.fn_known_sch = fn_known; |
| 119 | cb.fn_unknown_sch = fn_unknown; |
Sebastian Ott | 90ac24a | 2009-03-26 15:24:11 +0100 | [diff] [blame] | 120 | |
Peter Oberparleiter | 47d3067 | 2013-11-26 14:59:21 +0100 | [diff] [blame] | 121 | if (fn_known && !fn_unknown) { |
| 122 | /* Skip idset allocation in case of known-only loop. */ |
| 123 | cb.set = NULL; |
| 124 | return bus_for_each_dev(&css_bus_type, NULL, &cb, |
| 125 | call_fn_known_sch); |
| 126 | } |
| 127 | |
Sebastian Ott | 90ac24a | 2009-03-26 15:24:11 +0100 | [diff] [blame] | 128 | cb.set = idset_sch_new(); |
| 129 | if (!cb.set) |
| 130 | /* fall back to brute force scanning in case of oom */ |
| 131 | return for_each_subchannel(call_fn_all_sch, &cb); |
| 132 | |
| 133 | idset_fill(cb.set); |
| 134 | |
Peter Oberparleiter | e82a156 | 2008-01-26 14:10:48 +0100 | [diff] [blame] | 135 | /* Process registered subchannels. */ |
| 136 | rc = bus_for_each_dev(&css_bus_type, NULL, &cb, call_fn_known_sch); |
| 137 | if (rc) |
| 138 | goto out; |
| 139 | /* Process unregistered subchannels. */ |
| 140 | if (fn_unknown) |
| 141 | rc = for_each_subchannel(call_fn_unknown_sch, &cb); |
| 142 | out: |
| 143 | idset_free(cb.set); |
| 144 | |
| 145 | return rc; |
| 146 | } |
| 147 | |
Peter Oberparleiter | 390935a | 2009-12-07 12:51:18 +0100 | [diff] [blame] | 148 | static void css_sch_todo(struct work_struct *work); |
| 149 | |
Sebastian Ott | e5dcf00 | 2013-04-13 13:08:01 +0200 | [diff] [blame] | 150 | static int css_sch_create_locks(struct subchannel *sch) |
| 151 | { |
| 152 | sch->lock = kmalloc(sizeof(*sch->lock), GFP_KERNEL); |
| 153 | if (!sch->lock) |
| 154 | return -ENOMEM; |
| 155 | |
| 156 | spin_lock_init(sch->lock); |
| 157 | mutex_init(&sch->reg_mutex); |
| 158 | |
| 159 | return 0; |
| 160 | } |
| 161 | |
Sebastian Ott | c135ad1 | 2013-04-13 12:58:55 +0200 | [diff] [blame] | 162 | static void css_subchannel_release(struct device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | { |
Sebastian Ott | 863fc84 | 2013-04-13 13:01:50 +0200 | [diff] [blame] | 164 | struct subchannel *sch = to_subchannel(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | |
Sebastian Ott | 863fc84 | 2013-04-13 13:01:50 +0200 | [diff] [blame] | 166 | sch->config.intparm = 0; |
| 167 | cio_commit_config(sch); |
| 168 | kfree(sch->lock); |
| 169 | kfree(sch); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | } |
| 171 | |
Sebastian Ott | 863fc84 | 2013-04-13 13:01:50 +0200 | [diff] [blame] | 172 | struct subchannel *css_alloc_subchannel(struct subchannel_id schid) |
Sebastian Ott | c135ad1 | 2013-04-13 12:58:55 +0200 | [diff] [blame] | 173 | { |
| 174 | struct subchannel *sch; |
| 175 | int ret; |
| 176 | |
Sebastian Ott | e5dcf00 | 2013-04-13 13:08:01 +0200 | [diff] [blame] | 177 | sch = kzalloc(sizeof(*sch), GFP_KERNEL | GFP_DMA); |
| 178 | if (!sch) |
Sebastian Ott | c135ad1 | 2013-04-13 12:58:55 +0200 | [diff] [blame] | 179 | return ERR_PTR(-ENOMEM); |
Sebastian Ott | e5dcf00 | 2013-04-13 13:08:01 +0200 | [diff] [blame] | 180 | |
| 181 | ret = cio_validate_subchannel(sch, schid); |
| 182 | if (ret < 0) |
| 183 | goto err; |
| 184 | |
| 185 | ret = css_sch_create_locks(sch); |
| 186 | if (ret) |
| 187 | goto err; |
| 188 | |
Sebastian Ott | c135ad1 | 2013-04-13 12:58:55 +0200 | [diff] [blame] | 189 | INIT_WORK(&sch->todo_work, css_sch_todo); |
| 190 | sch->dev.release = &css_subchannel_release; |
| 191 | device_initialize(&sch->dev); |
| 192 | return sch; |
Sebastian Ott | e5dcf00 | 2013-04-13 13:08:01 +0200 | [diff] [blame] | 193 | |
| 194 | err: |
| 195 | kfree(sch); |
| 196 | return ERR_PTR(ret); |
Sebastian Ott | c135ad1 | 2013-04-13 12:58:55 +0200 | [diff] [blame] | 197 | } |
| 198 | |
Cornelia Huck | 07c6a33 | 2007-07-27 12:29:10 +0200 | [diff] [blame] | 199 | static int css_sch_device_register(struct subchannel *sch) |
Cornelia Huck | 6ab4879 | 2006-07-12 16:39:50 +0200 | [diff] [blame] | 200 | { |
| 201 | int ret; |
| 202 | |
| 203 | mutex_lock(&sch->reg_mutex); |
Sebastian Ott | 6ee4fec | 2009-09-11 10:28:25 +0200 | [diff] [blame] | 204 | dev_set_name(&sch->dev, "0.%x.%04x", sch->schid.ssid, |
| 205 | sch->schid.sch_no); |
Sebastian Ott | c135ad1 | 2013-04-13 12:58:55 +0200 | [diff] [blame] | 206 | ret = device_add(&sch->dev); |
Cornelia Huck | 6ab4879 | 2006-07-12 16:39:50 +0200 | [diff] [blame] | 207 | mutex_unlock(&sch->reg_mutex); |
| 208 | return ret; |
| 209 | } |
| 210 | |
Cornelia Huck | 44a1c19 | 2008-07-14 09:58:47 +0200 | [diff] [blame] | 211 | /** |
| 212 | * css_sch_device_unregister - unregister a subchannel |
| 213 | * @sch: subchannel to be unregistered |
| 214 | */ |
Cornelia Huck | 6ab4879 | 2006-07-12 16:39:50 +0200 | [diff] [blame] | 215 | void css_sch_device_unregister(struct subchannel *sch) |
| 216 | { |
| 217 | mutex_lock(&sch->reg_mutex); |
Sebastian Ott | ef60cd1 | 2008-07-14 09:59:20 +0200 | [diff] [blame] | 218 | if (device_is_registered(&sch->dev)) |
| 219 | device_unregister(&sch->dev); |
Cornelia Huck | 6ab4879 | 2006-07-12 16:39:50 +0200 | [diff] [blame] | 220 | mutex_unlock(&sch->reg_mutex); |
| 221 | } |
Cornelia Huck | 44a1c19 | 2008-07-14 09:58:47 +0200 | [diff] [blame] | 222 | EXPORT_SYMBOL_GPL(css_sch_device_unregister); |
Cornelia Huck | 6ab4879 | 2006-07-12 16:39:50 +0200 | [diff] [blame] | 223 | |
Peter Oberparleiter | 7ad6a24 | 2007-04-27 16:01:35 +0200 | [diff] [blame] | 224 | static void ssd_from_pmcw(struct chsc_ssd_info *ssd, struct pmcw *pmcw) |
| 225 | { |
| 226 | int i; |
| 227 | int mask; |
| 228 | |
| 229 | memset(ssd, 0, sizeof(struct chsc_ssd_info)); |
| 230 | ssd->path_mask = pmcw->pim; |
| 231 | for (i = 0; i < 8; i++) { |
| 232 | mask = 0x80 >> i; |
| 233 | if (pmcw->pim & mask) { |
| 234 | chp_id_init(&ssd->chpid[i]); |
| 235 | ssd->chpid[i].id = pmcw->chpid[i]; |
| 236 | } |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | static void ssd_register_chpids(struct chsc_ssd_info *ssd) |
| 241 | { |
| 242 | int i; |
| 243 | int mask; |
| 244 | |
| 245 | for (i = 0; i < 8; i++) { |
| 246 | mask = 0x80 >> i; |
| 247 | if (ssd->path_mask & mask) |
| 248 | if (!chp_is_registered(ssd->chpid[i])) |
| 249 | chp_new(ssd->chpid[i]); |
| 250 | } |
| 251 | } |
| 252 | |
| 253 | void css_update_ssd_info(struct subchannel *sch) |
| 254 | { |
| 255 | int ret; |
| 256 | |
Sebastian Ott | 14556b3 | 2013-04-13 13:03:54 +0200 | [diff] [blame] | 257 | ret = chsc_get_ssd_info(sch->schid, &sch->ssd_info); |
| 258 | if (ret) |
Peter Oberparleiter | 7ad6a24 | 2007-04-27 16:01:35 +0200 | [diff] [blame] | 259 | ssd_from_pmcw(&sch->ssd_info, &sch->schib.pmcw); |
Sebastian Ott | 14556b3 | 2013-04-13 13:03:54 +0200 | [diff] [blame] | 260 | |
| 261 | ssd_register_chpids(&sch->ssd_info); |
Peter Oberparleiter | 7ad6a24 | 2007-04-27 16:01:35 +0200 | [diff] [blame] | 262 | } |
| 263 | |
Cornelia Huck | 7e9db9e | 2008-07-14 09:58:44 +0200 | [diff] [blame] | 264 | static ssize_t type_show(struct device *dev, struct device_attribute *attr, |
| 265 | char *buf) |
| 266 | { |
| 267 | struct subchannel *sch = to_subchannel(dev); |
| 268 | |
| 269 | return sprintf(buf, "%01x\n", sch->st); |
| 270 | } |
| 271 | |
| 272 | static DEVICE_ATTR(type, 0444, type_show, NULL); |
| 273 | |
| 274 | static ssize_t modalias_show(struct device *dev, struct device_attribute *attr, |
| 275 | char *buf) |
| 276 | { |
| 277 | struct subchannel *sch = to_subchannel(dev); |
| 278 | |
| 279 | return sprintf(buf, "css:t%01X\n", sch->st); |
| 280 | } |
| 281 | |
| 282 | static DEVICE_ATTR(modalias, 0444, modalias_show, NULL); |
| 283 | |
| 284 | static struct attribute *subch_attrs[] = { |
| 285 | &dev_attr_type.attr, |
| 286 | &dev_attr_modalias.attr, |
| 287 | NULL, |
| 288 | }; |
| 289 | |
| 290 | static struct attribute_group subch_attr_group = { |
| 291 | .attrs = subch_attrs, |
| 292 | }; |
| 293 | |
David Brownell | a4dbd67 | 2009-06-24 10:06:31 -0700 | [diff] [blame] | 294 | static const struct attribute_group *default_subch_attr_groups[] = { |
Cornelia Huck | 7e9db9e | 2008-07-14 09:58:44 +0200 | [diff] [blame] | 295 | &subch_attr_group, |
| 296 | NULL, |
| 297 | }; |
| 298 | |
Sebastian Ott | 36f6237 | 2017-05-15 15:49:07 +0200 | [diff] [blame] | 299 | static ssize_t chpids_show(struct device *dev, |
| 300 | struct device_attribute *attr, |
| 301 | char *buf) |
| 302 | { |
| 303 | struct subchannel *sch = to_subchannel(dev); |
| 304 | struct chsc_ssd_info *ssd = &sch->ssd_info; |
| 305 | ssize_t ret = 0; |
| 306 | int mask; |
| 307 | int chp; |
| 308 | |
| 309 | for (chp = 0; chp < 8; chp++) { |
| 310 | mask = 0x80 >> chp; |
| 311 | if (ssd->path_mask & mask) |
| 312 | ret += sprintf(buf + ret, "%02x ", ssd->chpid[chp].id); |
| 313 | else |
| 314 | ret += sprintf(buf + ret, "00 "); |
| 315 | } |
| 316 | ret += sprintf(buf + ret, "\n"); |
| 317 | return ret; |
| 318 | } |
| 319 | static DEVICE_ATTR(chpids, 0444, chpids_show, NULL); |
| 320 | |
| 321 | static ssize_t pimpampom_show(struct device *dev, |
| 322 | struct device_attribute *attr, |
| 323 | char *buf) |
| 324 | { |
| 325 | struct subchannel *sch = to_subchannel(dev); |
| 326 | struct pmcw *pmcw = &sch->schib.pmcw; |
| 327 | |
| 328 | return sprintf(buf, "%02x %02x %02x\n", |
| 329 | pmcw->pim, pmcw->pam, pmcw->pom); |
| 330 | } |
| 331 | static DEVICE_ATTR(pimpampom, 0444, pimpampom_show, NULL); |
| 332 | |
| 333 | static struct attribute *io_subchannel_type_attrs[] = { |
| 334 | &dev_attr_chpids.attr, |
| 335 | &dev_attr_pimpampom.attr, |
| 336 | NULL, |
| 337 | }; |
| 338 | ATTRIBUTE_GROUPS(io_subchannel_type); |
| 339 | |
| 340 | static const struct device_type io_subchannel_type = { |
| 341 | .groups = io_subchannel_type_groups, |
| 342 | }; |
| 343 | |
Sebastian Ott | 14556b3 | 2013-04-13 13:03:54 +0200 | [diff] [blame] | 344 | int css_register_subchannel(struct subchannel *sch) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | { |
| 346 | int ret; |
| 347 | |
| 348 | /* Initialize the subchannel structure */ |
Cornelia Huck | 7c9f4e3 | 2007-10-12 16:11:13 +0200 | [diff] [blame] | 349 | sch->dev.parent = &channel_subsystems[0]->device; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | sch->dev.bus = &css_bus_type; |
Cornelia Huck | 7e9db9e | 2008-07-14 09:58:44 +0200 | [diff] [blame] | 351 | sch->dev.groups = default_subch_attr_groups; |
Sebastian Ott | 36f6237 | 2017-05-15 15:49:07 +0200 | [diff] [blame] | 352 | |
| 353 | if (sch->st == SUBCHANNEL_TYPE_IO) |
| 354 | sch->dev.type = &io_subchannel_type; |
| 355 | |
Cornelia Huck | 5bf04b2 | 2007-10-22 12:52:41 +0200 | [diff] [blame] | 356 | /* |
| 357 | * We don't want to generate uevents for I/O subchannels that don't |
| 358 | * have a working ccw device behind them since they will be |
| 359 | * unregistered before they can be used anyway, so we delay the add |
| 360 | * uevent until after device recognition was successful. |
Cornelia Huck | 7e9db9e | 2008-07-14 09:58:44 +0200 | [diff] [blame] | 361 | * Note that we suppress the uevent for all subchannel types; |
| 362 | * the subchannel driver can decide itself when it wants to inform |
| 363 | * userspace of its existence. |
Cornelia Huck | 5bf04b2 | 2007-10-22 12:52:41 +0200 | [diff] [blame] | 364 | */ |
Ming Lei | f67f129 | 2009-03-01 21:10:49 +0800 | [diff] [blame] | 365 | dev_set_uevent_suppress(&sch->dev, 1); |
Peter Oberparleiter | 7ad6a24 | 2007-04-27 16:01:35 +0200 | [diff] [blame] | 366 | css_update_ssd_info(sch); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | /* make it known to the system */ |
Cornelia Huck | 6ab4879 | 2006-07-12 16:39:50 +0200 | [diff] [blame] | 368 | ret = css_sch_device_register(sch); |
Cornelia Huck | 7674da7 | 2006-12-08 15:54:21 +0100 | [diff] [blame] | 369 | if (ret) { |
Cornelia Huck | e556bbb | 2007-07-27 12:29:19 +0200 | [diff] [blame] | 370 | CIO_MSG_EVENT(0, "Could not register sch 0.%x.%04x: %d\n", |
| 371 | sch->schid.ssid, sch->schid.sch_no, ret); |
Cornelia Huck | 7674da7 | 2006-12-08 15:54:21 +0100 | [diff] [blame] | 372 | return ret; |
| 373 | } |
Cornelia Huck | 7e9db9e | 2008-07-14 09:58:44 +0200 | [diff] [blame] | 374 | if (!sch->driver) { |
| 375 | /* |
| 376 | * No driver matched. Generate the uevent now so that |
| 377 | * a fitting driver module may be loaded based on the |
| 378 | * modalias. |
| 379 | */ |
Ming Lei | f67f129 | 2009-03-01 21:10:49 +0800 | [diff] [blame] | 380 | dev_set_uevent_suppress(&sch->dev, 0); |
Cornelia Huck | 7e9db9e | 2008-07-14 09:58:44 +0200 | [diff] [blame] | 381 | kobject_uevent(&sch->dev.kobj, KOBJ_ADD); |
| 382 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | return ret; |
| 384 | } |
| 385 | |
Sebastian Ott | 4e5ebd5 | 2013-04-13 13:04:49 +0200 | [diff] [blame] | 386 | static int css_probe_device(struct subchannel_id schid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | struct subchannel *sch; |
Sebastian Ott | 4e5ebd5 | 2013-04-13 13:04:49 +0200 | [diff] [blame] | 389 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | |
Sebastian Ott | 14556b3 | 2013-04-13 13:03:54 +0200 | [diff] [blame] | 391 | sch = css_alloc_subchannel(schid); |
| 392 | if (IS_ERR(sch)) |
| 393 | return PTR_ERR(sch); |
| 394 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | ret = css_register_subchannel(sch); |
Sebastian Ott | 863fc84 | 2013-04-13 13:01:50 +0200 | [diff] [blame] | 396 | if (ret) |
| 397 | put_device(&sch->dev); |
| 398 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | return ret; |
| 400 | } |
| 401 | |
Cornelia Huck | b0744bd | 2005-06-25 14:55:27 -0700 | [diff] [blame] | 402 | static int |
| 403 | check_subchannel(struct device * dev, void * data) |
| 404 | { |
| 405 | struct subchannel *sch; |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 406 | struct subchannel_id *schid = data; |
Cornelia Huck | b0744bd | 2005-06-25 14:55:27 -0700 | [diff] [blame] | 407 | |
| 408 | sch = to_subchannel(dev); |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 409 | return schid_equal(&sch->schid, schid); |
Cornelia Huck | b0744bd | 2005-06-25 14:55:27 -0700 | [diff] [blame] | 410 | } |
| 411 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | struct subchannel * |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 413 | get_subchannel_by_schid(struct subchannel_id schid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | struct device *dev; |
| 416 | |
Cornelia Huck | b0744bd | 2005-06-25 14:55:27 -0700 | [diff] [blame] | 417 | dev = bus_find_device(&css_bus_type, NULL, |
Cornelia Huck | 12975ae | 2006-10-11 15:31:47 +0200 | [diff] [blame] | 418 | &schid, check_subchannel); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | |
Cornelia Huck | b0744bd | 2005-06-25 14:55:27 -0700 | [diff] [blame] | 420 | return dev ? to_subchannel(dev) : NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | } |
| 422 | |
Cornelia Huck | b279a4f | 2008-01-26 14:10:45 +0100 | [diff] [blame] | 423 | /** |
| 424 | * css_sch_is_valid() - check if a subchannel is valid |
| 425 | * @schib: subchannel information block for the subchannel |
| 426 | */ |
| 427 | int css_sch_is_valid(struct schib *schib) |
| 428 | { |
| 429 | if ((schib->pmcw.st == SUBCHANNEL_TYPE_IO) && !schib->pmcw.dnv) |
| 430 | return 0; |
Cornelia Huck | b3a686f | 2008-07-14 09:58:48 +0200 | [diff] [blame] | 431 | if ((schib->pmcw.st == SUBCHANNEL_TYPE_MSG) && !schib->pmcw.w) |
| 432 | return 0; |
Cornelia Huck | b279a4f | 2008-01-26 14:10:45 +0100 | [diff] [blame] | 433 | return 1; |
| 434 | } |
| 435 | EXPORT_SYMBOL_GPL(css_sch_is_valid); |
| 436 | |
Peter Oberparleiter | 564337f | 2006-09-20 16:00:01 +0200 | [diff] [blame] | 437 | static int css_evaluate_new_subchannel(struct subchannel_id schid, int slow) |
| 438 | { |
| 439 | struct schib schib; |
| 440 | |
| 441 | if (!slow) { |
| 442 | /* Will be done on the slow path. */ |
| 443 | return -EAGAIN; |
| 444 | } |
Peter Oberparleiter | 62e65da | 2015-12-18 12:58:47 +0100 | [diff] [blame] | 445 | if (stsch(schid, &schib)) { |
Sebastian Ott | cec8546 | 2012-10-15 12:24:56 +0200 | [diff] [blame] | 446 | /* Subchannel is not provided. */ |
| 447 | return -ENXIO; |
| 448 | } |
| 449 | if (!css_sch_is_valid(&schib)) { |
Peter Oberparleiter | 564337f | 2006-09-20 16:00:01 +0200 | [diff] [blame] | 450 | /* Unusable - ignore. */ |
| 451 | return 0; |
| 452 | } |
Peter Oberparleiter | 5d6e6b6 | 2009-12-07 12:51:17 +0100 | [diff] [blame] | 453 | CIO_MSG_EVENT(4, "event: sch 0.%x.%04x, new\n", schid.ssid, |
| 454 | schid.sch_no); |
Peter Oberparleiter | 564337f | 2006-09-20 16:00:01 +0200 | [diff] [blame] | 455 | |
| 456 | return css_probe_device(schid); |
| 457 | } |
| 458 | |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 459 | static int css_evaluate_known_subchannel(struct subchannel *sch, int slow) |
| 460 | { |
| 461 | int ret = 0; |
| 462 | |
| 463 | if (sch->driver) { |
| 464 | if (sch->driver->sch_event) |
| 465 | ret = sch->driver->sch_event(sch, slow); |
| 466 | else |
| 467 | dev_dbg(&sch->dev, |
| 468 | "Got subchannel machine check but " |
| 469 | "no sch_event handler provided.\n"); |
| 470 | } |
Peter Oberparleiter | 5d6e6b6 | 2009-12-07 12:51:17 +0100 | [diff] [blame] | 471 | if (ret != 0 && ret != -EAGAIN) { |
| 472 | CIO_MSG_EVENT(2, "eval: sch 0.%x.%04x, rc=%d\n", |
| 473 | sch->schid.ssid, sch->schid.sch_no, ret); |
| 474 | } |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 475 | return ret; |
| 476 | } |
| 477 | |
Peter Oberparleiter | 83b3370 | 2007-04-27 16:01:34 +0200 | [diff] [blame] | 478 | static void css_evaluate_subchannel(struct subchannel_id schid, int slow) |
Peter Oberparleiter | 564337f | 2006-09-20 16:00:01 +0200 | [diff] [blame] | 479 | { |
| 480 | struct subchannel *sch; |
| 481 | int ret; |
| 482 | |
| 483 | sch = get_subchannel_by_schid(schid); |
| 484 | if (sch) { |
| 485 | ret = css_evaluate_known_subchannel(sch, slow); |
| 486 | put_device(&sch->dev); |
| 487 | } else |
| 488 | ret = css_evaluate_new_subchannel(schid, slow); |
Peter Oberparleiter | 83b3370 | 2007-04-27 16:01:34 +0200 | [diff] [blame] | 489 | if (ret == -EAGAIN) |
| 490 | css_schedule_eval(schid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | } |
| 492 | |
Sebastian Ott | 817e500 | 2011-12-01 13:32:19 +0100 | [diff] [blame] | 493 | /** |
| 494 | * css_sched_sch_todo - schedule a subchannel operation |
| 495 | * @sch: subchannel |
| 496 | * @todo: todo |
| 497 | * |
| 498 | * Schedule the operation identified by @todo to be performed on the slow path |
| 499 | * workqueue. Do nothing if another operation with higher priority is already |
| 500 | * scheduled. Needs to be called with subchannel lock held. |
| 501 | */ |
| 502 | void css_sched_sch_todo(struct subchannel *sch, enum sch_todo todo) |
| 503 | { |
| 504 | CIO_MSG_EVENT(4, "sch_todo: sched sch=0.%x.%04x todo=%d\n", |
| 505 | sch->schid.ssid, sch->schid.sch_no, todo); |
| 506 | if (sch->todo >= todo) |
| 507 | return; |
| 508 | /* Get workqueue ref. */ |
| 509 | if (!get_device(&sch->dev)) |
| 510 | return; |
| 511 | sch->todo = todo; |
| 512 | if (!queue_work(cio_work_q, &sch->todo_work)) { |
| 513 | /* Already queued, release workqueue ref. */ |
| 514 | put_device(&sch->dev); |
| 515 | } |
| 516 | } |
Sebastian Ott | 01c5e6d | 2012-08-28 16:42:37 +0200 | [diff] [blame] | 517 | EXPORT_SYMBOL_GPL(css_sched_sch_todo); |
Sebastian Ott | 817e500 | 2011-12-01 13:32:19 +0100 | [diff] [blame] | 518 | |
| 519 | static void css_sch_todo(struct work_struct *work) |
| 520 | { |
| 521 | struct subchannel *sch; |
| 522 | enum sch_todo todo; |
| 523 | int ret; |
| 524 | |
| 525 | sch = container_of(work, struct subchannel, todo_work); |
| 526 | /* Find out todo. */ |
| 527 | spin_lock_irq(sch->lock); |
| 528 | todo = sch->todo; |
| 529 | CIO_MSG_EVENT(4, "sch_todo: sch=0.%x.%04x, todo=%d\n", sch->schid.ssid, |
| 530 | sch->schid.sch_no, todo); |
| 531 | sch->todo = SCH_TODO_NOTHING; |
| 532 | spin_unlock_irq(sch->lock); |
| 533 | /* Perform todo. */ |
| 534 | switch (todo) { |
| 535 | case SCH_TODO_NOTHING: |
| 536 | break; |
| 537 | case SCH_TODO_EVAL: |
| 538 | ret = css_evaluate_known_subchannel(sch, 1); |
| 539 | if (ret == -EAGAIN) { |
| 540 | spin_lock_irq(sch->lock); |
| 541 | css_sched_sch_todo(sch, todo); |
| 542 | spin_unlock_irq(sch->lock); |
| 543 | } |
| 544 | break; |
| 545 | case SCH_TODO_UNREG: |
| 546 | css_sch_device_unregister(sch); |
| 547 | break; |
| 548 | } |
| 549 | /* Release workqueue ref. */ |
| 550 | put_device(&sch->dev); |
| 551 | } |
| 552 | |
Peter Oberparleiter | 83b3370 | 2007-04-27 16:01:34 +0200 | [diff] [blame] | 553 | static struct idset *slow_subchannel_set; |
| 554 | static spinlock_t slow_subchannel_lock; |
Sebastian Ott | 2553055 | 2009-09-22 22:58:34 +0200 | [diff] [blame] | 555 | static wait_queue_head_t css_eval_wq; |
| 556 | static atomic_t css_eval_scheduled; |
Peter Oberparleiter | 83b3370 | 2007-04-27 16:01:34 +0200 | [diff] [blame] | 557 | |
| 558 | static int __init slow_subchannel_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | { |
Peter Oberparleiter | 83b3370 | 2007-04-27 16:01:34 +0200 | [diff] [blame] | 560 | spin_lock_init(&slow_subchannel_lock); |
Sebastian Ott | 2553055 | 2009-09-22 22:58:34 +0200 | [diff] [blame] | 561 | atomic_set(&css_eval_scheduled, 0); |
| 562 | init_waitqueue_head(&css_eval_wq); |
Peter Oberparleiter | 83b3370 | 2007-04-27 16:01:34 +0200 | [diff] [blame] | 563 | slow_subchannel_set = idset_sch_new(); |
| 564 | if (!slow_subchannel_set) { |
Cornelia Huck | e556bbb | 2007-07-27 12:29:19 +0200 | [diff] [blame] | 565 | CIO_MSG_EVENT(0, "could not allocate slow subchannel set\n"); |
Peter Oberparleiter | 83b3370 | 2007-04-27 16:01:34 +0200 | [diff] [blame] | 566 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | } |
Peter Oberparleiter | 83b3370 | 2007-04-27 16:01:34 +0200 | [diff] [blame] | 568 | return 0; |
| 569 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | |
Peter Oberparleiter | e82a156 | 2008-01-26 14:10:48 +0100 | [diff] [blame] | 571 | static int slow_eval_known_fn(struct subchannel *sch, void *data) |
| 572 | { |
| 573 | int eval; |
| 574 | int rc; |
| 575 | |
| 576 | spin_lock_irq(&slow_subchannel_lock); |
| 577 | eval = idset_sch_contains(slow_subchannel_set, sch->schid); |
| 578 | idset_sch_del(slow_subchannel_set, sch->schid); |
| 579 | spin_unlock_irq(&slow_subchannel_lock); |
| 580 | if (eval) { |
| 581 | rc = css_evaluate_known_subchannel(sch, 1); |
| 582 | if (rc == -EAGAIN) |
| 583 | css_schedule_eval(sch->schid); |
| 584 | } |
| 585 | return 0; |
| 586 | } |
| 587 | |
| 588 | static int slow_eval_unknown_fn(struct subchannel_id schid, void *data) |
| 589 | { |
| 590 | int eval; |
| 591 | int rc = 0; |
| 592 | |
| 593 | spin_lock_irq(&slow_subchannel_lock); |
| 594 | eval = idset_sch_contains(slow_subchannel_set, schid); |
| 595 | idset_sch_del(slow_subchannel_set, schid); |
| 596 | spin_unlock_irq(&slow_subchannel_lock); |
| 597 | if (eval) { |
| 598 | rc = css_evaluate_new_subchannel(schid, 1); |
| 599 | switch (rc) { |
| 600 | case -EAGAIN: |
| 601 | css_schedule_eval(schid); |
| 602 | rc = 0; |
| 603 | break; |
| 604 | case -ENXIO: |
| 605 | case -ENOMEM: |
| 606 | case -EIO: |
| 607 | /* These should abort looping */ |
Sebastian Ott | eb072a7 | 2013-08-29 20:31:06 +0200 | [diff] [blame] | 608 | spin_lock_irq(&slow_subchannel_lock); |
Sebastian Ott | cec8546 | 2012-10-15 12:24:56 +0200 | [diff] [blame] | 609 | idset_sch_del_subseq(slow_subchannel_set, schid); |
Sebastian Ott | eb072a7 | 2013-08-29 20:31:06 +0200 | [diff] [blame] | 610 | spin_unlock_irq(&slow_subchannel_lock); |
Peter Oberparleiter | e82a156 | 2008-01-26 14:10:48 +0100 | [diff] [blame] | 611 | break; |
| 612 | default: |
| 613 | rc = 0; |
| 614 | } |
Peter Oberparleiter | b207f5a | 2013-11-26 14:57:13 +0100 | [diff] [blame] | 615 | /* Allow scheduling here since the containing loop might |
| 616 | * take a while. */ |
| 617 | cond_resched(); |
Peter Oberparleiter | e82a156 | 2008-01-26 14:10:48 +0100 | [diff] [blame] | 618 | } |
| 619 | return rc; |
| 620 | } |
| 621 | |
Peter Oberparleiter | 83b3370 | 2007-04-27 16:01:34 +0200 | [diff] [blame] | 622 | static void css_slow_path_func(struct work_struct *unused) |
| 623 | { |
Sebastian Ott | 2553055 | 2009-09-22 22:58:34 +0200 | [diff] [blame] | 624 | unsigned long flags; |
| 625 | |
Peter Oberparleiter | 83b3370 | 2007-04-27 16:01:34 +0200 | [diff] [blame] | 626 | CIO_TRACE_EVENT(4, "slowpath"); |
Peter Oberparleiter | e82a156 | 2008-01-26 14:10:48 +0100 | [diff] [blame] | 627 | for_each_subchannel_staged(slow_eval_known_fn, slow_eval_unknown_fn, |
| 628 | NULL); |
Sebastian Ott | 2553055 | 2009-09-22 22:58:34 +0200 | [diff] [blame] | 629 | spin_lock_irqsave(&slow_subchannel_lock, flags); |
| 630 | if (idset_is_empty(slow_subchannel_set)) { |
| 631 | atomic_set(&css_eval_scheduled, 0); |
| 632 | wake_up(&css_eval_wq); |
| 633 | } |
| 634 | spin_unlock_irqrestore(&slow_subchannel_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 | } |
| 636 | |
Peter Oberparleiter | 175746e | 2013-11-26 14:58:08 +0100 | [diff] [blame] | 637 | static DECLARE_DELAYED_WORK(slow_path_work, css_slow_path_func); |
Sebastian Ott | be5d382 | 2010-02-26 22:37:24 +0100 | [diff] [blame] | 638 | struct workqueue_struct *cio_work_q; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | |
Peter Oberparleiter | 83b3370 | 2007-04-27 16:01:34 +0200 | [diff] [blame] | 640 | void css_schedule_eval(struct subchannel_id schid) |
| 641 | { |
| 642 | unsigned long flags; |
| 643 | |
| 644 | spin_lock_irqsave(&slow_subchannel_lock, flags); |
| 645 | idset_sch_add(slow_subchannel_set, schid); |
Sebastian Ott | 2553055 | 2009-09-22 22:58:34 +0200 | [diff] [blame] | 646 | atomic_set(&css_eval_scheduled, 1); |
Peter Oberparleiter | 175746e | 2013-11-26 14:58:08 +0100 | [diff] [blame] | 647 | queue_delayed_work(cio_work_q, &slow_path_work, 0); |
Peter Oberparleiter | 83b3370 | 2007-04-27 16:01:34 +0200 | [diff] [blame] | 648 | spin_unlock_irqrestore(&slow_subchannel_lock, flags); |
| 649 | } |
| 650 | |
| 651 | void css_schedule_eval_all(void) |
| 652 | { |
| 653 | unsigned long flags; |
| 654 | |
| 655 | spin_lock_irqsave(&slow_subchannel_lock, flags); |
| 656 | idset_fill(slow_subchannel_set); |
Sebastian Ott | 2553055 | 2009-09-22 22:58:34 +0200 | [diff] [blame] | 657 | atomic_set(&css_eval_scheduled, 1); |
Peter Oberparleiter | 175746e | 2013-11-26 14:58:08 +0100 | [diff] [blame] | 658 | queue_delayed_work(cio_work_q, &slow_path_work, 0); |
Peter Oberparleiter | 83b3370 | 2007-04-27 16:01:34 +0200 | [diff] [blame] | 659 | spin_unlock_irqrestore(&slow_subchannel_lock, flags); |
| 660 | } |
| 661 | |
Sebastian Ott | 703e5c9 | 2009-09-22 22:58:38 +0200 | [diff] [blame] | 662 | static int __unset_registered(struct device *dev, void *data) |
| 663 | { |
| 664 | struct idset *set = data; |
| 665 | struct subchannel *sch = to_subchannel(dev); |
| 666 | |
| 667 | idset_sch_del(set, sch->schid); |
| 668 | return 0; |
| 669 | } |
| 670 | |
Peter Oberparleiter | 175746e | 2013-11-26 14:58:08 +0100 | [diff] [blame] | 671 | void css_schedule_eval_all_unreg(unsigned long delay) |
Sebastian Ott | 703e5c9 | 2009-09-22 22:58:38 +0200 | [diff] [blame] | 672 | { |
| 673 | unsigned long flags; |
| 674 | struct idset *unreg_set; |
| 675 | |
| 676 | /* Find unregistered subchannels. */ |
| 677 | unreg_set = idset_sch_new(); |
| 678 | if (!unreg_set) { |
| 679 | /* Fallback. */ |
| 680 | css_schedule_eval_all(); |
| 681 | return; |
| 682 | } |
| 683 | idset_fill(unreg_set); |
| 684 | bus_for_each_dev(&css_bus_type, NULL, unreg_set, __unset_registered); |
| 685 | /* Apply to slow_subchannel_set. */ |
| 686 | spin_lock_irqsave(&slow_subchannel_lock, flags); |
| 687 | idset_add_set(slow_subchannel_set, unreg_set); |
| 688 | atomic_set(&css_eval_scheduled, 1); |
Peter Oberparleiter | 175746e | 2013-11-26 14:58:08 +0100 | [diff] [blame] | 689 | queue_delayed_work(cio_work_q, &slow_path_work, delay); |
Sebastian Ott | 703e5c9 | 2009-09-22 22:58:38 +0200 | [diff] [blame] | 690 | spin_unlock_irqrestore(&slow_subchannel_lock, flags); |
| 691 | idset_free(unreg_set); |
| 692 | } |
| 693 | |
Cornelia Huck | 22806dc | 2008-04-17 07:45:59 +0200 | [diff] [blame] | 694 | void css_wait_for_slow_path(void) |
| 695 | { |
Sebastian Ott | be5d382 | 2010-02-26 22:37:24 +0100 | [diff] [blame] | 696 | flush_workqueue(cio_work_q); |
Cornelia Huck | 22806dc | 2008-04-17 07:45:59 +0200 | [diff] [blame] | 697 | } |
| 698 | |
Peter Oberparleiter | 40154b8 | 2006-06-29 14:57:03 +0200 | [diff] [blame] | 699 | /* Schedule reprobing of all unregistered subchannels. */ |
| 700 | void css_schedule_reprobe(void) |
| 701 | { |
Peter Oberparleiter | 175746e | 2013-11-26 14:58:08 +0100 | [diff] [blame] | 702 | /* Schedule with a delay to allow merging of subsequent calls. */ |
| 703 | css_schedule_eval_all_unreg(1 * HZ); |
Peter Oberparleiter | 40154b8 | 2006-06-29 14:57:03 +0200 | [diff] [blame] | 704 | } |
Peter Oberparleiter | 40154b8 | 2006-06-29 14:57:03 +0200 | [diff] [blame] | 705 | EXPORT_SYMBOL_GPL(css_schedule_reprobe); |
| 706 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | * Called from the machine check handler for subchannel report words. |
| 709 | */ |
Cornelia Huck | c115618 | 2008-07-14 09:58:46 +0200 | [diff] [blame] | 710 | static void css_process_crw(struct crw *crw0, struct crw *crw1, int overflow) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 711 | { |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 712 | struct subchannel_id mchk_schid; |
Sebastian Ott | 4bc4e96 | 2011-01-05 12:47:58 +0100 | [diff] [blame] | 713 | struct subchannel *sch; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 714 | |
Cornelia Huck | c115618 | 2008-07-14 09:58:46 +0200 | [diff] [blame] | 715 | if (overflow) { |
| 716 | css_schedule_eval_all(); |
| 717 | return; |
| 718 | } |
| 719 | CIO_CRW_EVENT(2, "CRW0 reports slct=%d, oflw=%d, " |
| 720 | "chn=%d, rsc=%X, anc=%d, erc=%X, rsid=%X\n", |
| 721 | crw0->slct, crw0->oflw, crw0->chn, crw0->rsc, crw0->anc, |
| 722 | crw0->erc, crw0->rsid); |
| 723 | if (crw1) |
| 724 | CIO_CRW_EVENT(2, "CRW1 reports slct=%d, oflw=%d, " |
| 725 | "chn=%d, rsc=%X, anc=%d, erc=%X, rsid=%X\n", |
| 726 | crw1->slct, crw1->oflw, crw1->chn, crw1->rsc, |
| 727 | crw1->anc, crw1->erc, crw1->rsid); |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 728 | init_subchannel_id(&mchk_schid); |
Cornelia Huck | c115618 | 2008-07-14 09:58:46 +0200 | [diff] [blame] | 729 | mchk_schid.sch_no = crw0->rsid; |
| 730 | if (crw1) |
Sebastian Ott | 8d7bfb4 | 2010-12-01 10:08:02 +0100 | [diff] [blame] | 731 | mchk_schid.ssid = (crw1->rsid >> 4) & 3; |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 732 | |
Sebastian Ott | 4bc4e96 | 2011-01-05 12:47:58 +0100 | [diff] [blame] | 733 | if (crw0->erc == CRW_ERC_PMOD) { |
| 734 | sch = get_subchannel_by_schid(mchk_schid); |
| 735 | if (sch) { |
| 736 | css_update_ssd_info(sch); |
| 737 | put_device(&sch->dev); |
| 738 | } |
| 739 | } |
Cornelia Huck | c115618 | 2008-07-14 09:58:46 +0200 | [diff] [blame] | 740 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 741 | * Since we are always presented with IPI in the CRW, we have to |
| 742 | * use stsch() to find out if the subchannel in question has come |
| 743 | * or gone. |
| 744 | */ |
Peter Oberparleiter | 83b3370 | 2007-04-27 16:01:34 +0200 | [diff] [blame] | 745 | css_evaluate_subchannel(mchk_schid, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 746 | } |
| 747 | |
| 748 | static void __init |
Cornelia Huck | a28c694 | 2006-01-06 00:19:23 -0800 | [diff] [blame] | 749 | css_generate_pgid(struct channel_subsystem *css, u32 tod_high) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 750 | { |
Martin Schwidefsky | 94038a9 | 2010-05-17 10:00:00 +0200 | [diff] [blame] | 751 | struct cpuid cpu_id; |
| 752 | |
Cornelia Huck | 75784c0 | 2008-07-14 09:58:57 +0200 | [diff] [blame] | 753 | if (css_general_characteristics.mcss) { |
Cornelia Huck | a28c694 | 2006-01-06 00:19:23 -0800 | [diff] [blame] | 754 | css->global_pgid.pgid_high.ext_cssid.version = 0x80; |
Sebastian Ott | e2e0de9 | 2016-06-17 19:45:23 +0200 | [diff] [blame] | 755 | css->global_pgid.pgid_high.ext_cssid.cssid = |
| 756 | (css->cssid < 0) ? 0 : css->cssid; |
Cornelia Huck | a28c694 | 2006-01-06 00:19:23 -0800 | [diff] [blame] | 757 | } else { |
Martin Schwidefsky | 7b46848 | 2009-03-26 15:24:42 +0100 | [diff] [blame] | 758 | css->global_pgid.pgid_high.cpu_addr = stap(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 759 | } |
Martin Schwidefsky | 94038a9 | 2010-05-17 10:00:00 +0200 | [diff] [blame] | 760 | get_cpu_id(&cpu_id); |
| 761 | css->global_pgid.cpu_id = cpu_id.ident; |
| 762 | css->global_pgid.cpu_model = cpu_id.machine; |
Cornelia Huck | a28c694 | 2006-01-06 00:19:23 -0800 | [diff] [blame] | 763 | css->global_pgid.tod_high = tod_high; |
Cornelia Huck | a28c694 | 2006-01-06 00:19:23 -0800 | [diff] [blame] | 764 | } |
| 765 | |
Sebastian Ott | 15a2044 | 2016-10-25 14:05:08 +0200 | [diff] [blame] | 766 | static void channel_subsystem_release(struct device *dev) |
Cornelia Huck | 3b79306 | 2006-01-06 00:19:26 -0800 | [diff] [blame] | 767 | { |
Sebastian Ott | 15a2044 | 2016-10-25 14:05:08 +0200 | [diff] [blame] | 768 | struct channel_subsystem *css = to_css(dev); |
Cornelia Huck | 3b79306 | 2006-01-06 00:19:26 -0800 | [diff] [blame] | 769 | |
Cornelia Huck | 495a5b4 | 2006-03-24 03:15:14 -0800 | [diff] [blame] | 770 | mutex_destroy(&css->mutex); |
Cornelia Huck | 3b79306 | 2006-01-06 00:19:26 -0800 | [diff] [blame] | 771 | kfree(css); |
| 772 | } |
| 773 | |
Sebastian Ott | 64dfdd4 | 2016-10-11 18:21:36 +0200 | [diff] [blame] | 774 | static ssize_t real_cssid_show(struct device *dev, struct device_attribute *a, |
| 775 | char *buf) |
| 776 | { |
| 777 | struct channel_subsystem *css = to_css(dev); |
| 778 | |
| 779 | if (css->cssid < 0) |
| 780 | return -EINVAL; |
| 781 | |
| 782 | return sprintf(buf, "%x\n", css->cssid); |
| 783 | } |
| 784 | static DEVICE_ATTR_RO(real_cssid); |
| 785 | |
Sebastian Ott | 6c701268 | 2016-10-11 16:37:43 +0200 | [diff] [blame] | 786 | static ssize_t cm_enable_show(struct device *dev, struct device_attribute *a, |
| 787 | char *buf) |
Cornelia Huck | 495a5b4 | 2006-03-24 03:15:14 -0800 | [diff] [blame] | 788 | { |
| 789 | struct channel_subsystem *css = to_css(dev); |
Michael Ernst | 8284fb19 | 2008-04-17 07:46:01 +0200 | [diff] [blame] | 790 | int ret; |
Cornelia Huck | 495a5b4 | 2006-03-24 03:15:14 -0800 | [diff] [blame] | 791 | |
Michael Ernst | 8284fb19 | 2008-04-17 07:46:01 +0200 | [diff] [blame] | 792 | mutex_lock(&css->mutex); |
| 793 | ret = sprintf(buf, "%x\n", css->cm_enabled); |
| 794 | mutex_unlock(&css->mutex); |
| 795 | return ret; |
Cornelia Huck | 495a5b4 | 2006-03-24 03:15:14 -0800 | [diff] [blame] | 796 | } |
| 797 | |
Sebastian Ott | 6c701268 | 2016-10-11 16:37:43 +0200 | [diff] [blame] | 798 | static ssize_t cm_enable_store(struct device *dev, struct device_attribute *a, |
| 799 | const char *buf, size_t count) |
Cornelia Huck | 495a5b4 | 2006-03-24 03:15:14 -0800 | [diff] [blame] | 800 | { |
| 801 | struct channel_subsystem *css = to_css(dev); |
Cornelia Huck | 2f97220 | 2008-04-30 13:38:33 +0200 | [diff] [blame] | 802 | unsigned long val; |
Sebastian Ott | 6c701268 | 2016-10-11 16:37:43 +0200 | [diff] [blame] | 803 | int ret; |
Cornelia Huck | 495a5b4 | 2006-03-24 03:15:14 -0800 | [diff] [blame] | 804 | |
Jingoo Han | 0178722 | 2013-07-22 10:18:15 +0900 | [diff] [blame] | 805 | ret = kstrtoul(buf, 16, &val); |
Cornelia Huck | 2f97220 | 2008-04-30 13:38:33 +0200 | [diff] [blame] | 806 | if (ret) |
| 807 | return ret; |
Michael Ernst | 8284fb19 | 2008-04-17 07:46:01 +0200 | [diff] [blame] | 808 | mutex_lock(&css->mutex); |
Cornelia Huck | 2f97220 | 2008-04-30 13:38:33 +0200 | [diff] [blame] | 809 | switch (val) { |
| 810 | case 0: |
Cornelia Huck | 495a5b4 | 2006-03-24 03:15:14 -0800 | [diff] [blame] | 811 | ret = css->cm_enabled ? chsc_secm(css, 0) : 0; |
| 812 | break; |
Cornelia Huck | 2f97220 | 2008-04-30 13:38:33 +0200 | [diff] [blame] | 813 | case 1: |
Cornelia Huck | 495a5b4 | 2006-03-24 03:15:14 -0800 | [diff] [blame] | 814 | ret = css->cm_enabled ? 0 : chsc_secm(css, 1); |
| 815 | break; |
| 816 | default: |
| 817 | ret = -EINVAL; |
| 818 | } |
Michael Ernst | 8284fb19 | 2008-04-17 07:46:01 +0200 | [diff] [blame] | 819 | mutex_unlock(&css->mutex); |
Cornelia Huck | 495a5b4 | 2006-03-24 03:15:14 -0800 | [diff] [blame] | 820 | return ret < 0 ? ret : count; |
| 821 | } |
Sebastian Ott | 6c701268 | 2016-10-11 16:37:43 +0200 | [diff] [blame] | 822 | static DEVICE_ATTR_RW(cm_enable); |
Cornelia Huck | 495a5b4 | 2006-03-24 03:15:14 -0800 | [diff] [blame] | 823 | |
Sebastian Ott | 6c701268 | 2016-10-11 16:37:43 +0200 | [diff] [blame] | 824 | static umode_t cm_enable_mode(struct kobject *kobj, struct attribute *attr, |
| 825 | int index) |
| 826 | { |
| 827 | return css_chsc_characteristics.secm ? attr->mode : 0; |
| 828 | } |
| 829 | |
Sebastian Ott | 64dfdd4 | 2016-10-11 18:21:36 +0200 | [diff] [blame] | 830 | static struct attribute *cssdev_attrs[] = { |
| 831 | &dev_attr_real_cssid.attr, |
| 832 | NULL, |
| 833 | }; |
| 834 | |
| 835 | static struct attribute_group cssdev_attr_group = { |
| 836 | .attrs = cssdev_attrs, |
| 837 | }; |
| 838 | |
Sebastian Ott | 6c701268 | 2016-10-11 16:37:43 +0200 | [diff] [blame] | 839 | static struct attribute *cssdev_cm_attrs[] = { |
| 840 | &dev_attr_cm_enable.attr, |
| 841 | NULL, |
| 842 | }; |
| 843 | |
| 844 | static struct attribute_group cssdev_cm_attr_group = { |
| 845 | .attrs = cssdev_cm_attrs, |
| 846 | .is_visible = cm_enable_mode, |
| 847 | }; |
| 848 | |
| 849 | static const struct attribute_group *cssdev_attr_groups[] = { |
Sebastian Ott | 64dfdd4 | 2016-10-11 18:21:36 +0200 | [diff] [blame] | 850 | &cssdev_attr_group, |
Sebastian Ott | 6c701268 | 2016-10-11 16:37:43 +0200 | [diff] [blame] | 851 | &cssdev_cm_attr_group, |
| 852 | NULL, |
| 853 | }; |
Cornelia Huck | 495a5b4 | 2006-03-24 03:15:14 -0800 | [diff] [blame] | 854 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 855 | static int __init setup_css(int nr) |
Cornelia Huck | a28c694 | 2006-01-06 00:19:23 -0800 | [diff] [blame] | 856 | { |
Cornelia Huck | 7c9f4e3 | 2007-10-12 16:11:13 +0200 | [diff] [blame] | 857 | struct channel_subsystem *css; |
Sebastian Ott | 15a2044 | 2016-10-25 14:05:08 +0200 | [diff] [blame] | 858 | int ret; |
Cornelia Huck | a28c694 | 2006-01-06 00:19:23 -0800 | [diff] [blame] | 859 | |
Sebastian Ott | 15a2044 | 2016-10-25 14:05:08 +0200 | [diff] [blame] | 860 | css = kzalloc(sizeof(*css), GFP_KERNEL); |
| 861 | if (!css) |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 862 | return -ENOMEM; |
Sebastian Ott | 15a2044 | 2016-10-25 14:05:08 +0200 | [diff] [blame] | 863 | |
| 864 | channel_subsystems[nr] = css; |
| 865 | dev_set_name(&css->device, "css%x", nr); |
| 866 | css->device.groups = cssdev_attr_groups; |
| 867 | css->device.release = channel_subsystem_release; |
| 868 | |
| 869 | mutex_init(&css->mutex); |
Sebastian Ott | 15a2044 | 2016-10-25 14:05:08 +0200 | [diff] [blame] | 870 | css->cssid = chsc_get_cssid(nr); |
| 871 | css_generate_pgid(css, (u32) (get_tod_clock() >> 32)); |
| 872 | |
| 873 | ret = device_register(&css->device); |
| 874 | if (ret) { |
| 875 | put_device(&css->device); |
| 876 | goto out_err; |
| 877 | } |
| 878 | |
| 879 | css->pseudo_subchannel = kzalloc(sizeof(*css->pseudo_subchannel), |
| 880 | GFP_KERNEL); |
| 881 | if (!css->pseudo_subchannel) { |
| 882 | device_unregister(&css->device); |
| 883 | ret = -ENOMEM; |
| 884 | goto out_err; |
| 885 | } |
| 886 | |
Cornelia Huck | 7c9f4e3 | 2007-10-12 16:11:13 +0200 | [diff] [blame] | 887 | css->pseudo_subchannel->dev.parent = &css->device; |
| 888 | css->pseudo_subchannel->dev.release = css_subchannel_release; |
Peter Oberparleiter | 5d6e6b6 | 2009-12-07 12:51:17 +0100 | [diff] [blame] | 889 | mutex_init(&css->pseudo_subchannel->reg_mutex); |
Sebastian Ott | e5dcf00 | 2013-04-13 13:08:01 +0200 | [diff] [blame] | 890 | ret = css_sch_create_locks(css->pseudo_subchannel); |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 891 | if (ret) { |
Cornelia Huck | 7c9f4e3 | 2007-10-12 16:11:13 +0200 | [diff] [blame] | 892 | kfree(css->pseudo_subchannel); |
Sebastian Ott | 15a2044 | 2016-10-25 14:05:08 +0200 | [diff] [blame] | 893 | device_unregister(&css->device); |
| 894 | goto out_err; |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 895 | } |
Sebastian Ott | e2e0de9 | 2016-06-17 19:45:23 +0200 | [diff] [blame] | 896 | |
Sebastian Ott | 15a2044 | 2016-10-25 14:05:08 +0200 | [diff] [blame] | 897 | dev_set_name(&css->pseudo_subchannel->dev, "defunct"); |
| 898 | ret = device_register(&css->pseudo_subchannel->dev); |
| 899 | if (ret) { |
| 900 | put_device(&css->pseudo_subchannel->dev); |
| 901 | device_unregister(&css->device); |
| 902 | goto out_err; |
| 903 | } |
| 904 | |
| 905 | return ret; |
| 906 | out_err: |
| 907 | channel_subsystems[nr] = NULL; |
| 908 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 909 | } |
| 910 | |
Cornelia Huck | a55360d | 2007-10-12 16:11:20 +0200 | [diff] [blame] | 911 | static int css_reboot_event(struct notifier_block *this, |
| 912 | unsigned long event, |
| 913 | void *ptr) |
| 914 | { |
Sebastian Ott | 98cc43a | 2016-11-08 14:28:03 +0100 | [diff] [blame] | 915 | struct channel_subsystem *css; |
| 916 | int ret; |
Cornelia Huck | a55360d | 2007-10-12 16:11:20 +0200 | [diff] [blame] | 917 | |
| 918 | ret = NOTIFY_DONE; |
Sebastian Ott | 98cc43a | 2016-11-08 14:28:03 +0100 | [diff] [blame] | 919 | for_each_css(css) { |
Michael Ernst | 8284fb19 | 2008-04-17 07:46:01 +0200 | [diff] [blame] | 920 | mutex_lock(&css->mutex); |
Cornelia Huck | a55360d | 2007-10-12 16:11:20 +0200 | [diff] [blame] | 921 | if (css->cm_enabled) |
| 922 | if (chsc_secm(css, 0)) |
| 923 | ret = NOTIFY_BAD; |
Michael Ernst | 8284fb19 | 2008-04-17 07:46:01 +0200 | [diff] [blame] | 924 | mutex_unlock(&css->mutex); |
Cornelia Huck | a55360d | 2007-10-12 16:11:20 +0200 | [diff] [blame] | 925 | } |
| 926 | |
| 927 | return ret; |
| 928 | } |
| 929 | |
| 930 | static struct notifier_block css_reboot_notifier = { |
| 931 | .notifier_call = css_reboot_event, |
| 932 | }; |
| 933 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 934 | /* |
Sebastian Ott | dcbd16d | 2009-06-16 10:30:22 +0200 | [diff] [blame] | 935 | * Since the css devices are neither on a bus nor have a class |
| 936 | * nor have a special device type, we cannot stop/restart channel |
| 937 | * path measurements via the normal suspend/resume callbacks, but have |
| 938 | * to use notifiers. |
| 939 | */ |
| 940 | static int css_power_event(struct notifier_block *this, unsigned long event, |
| 941 | void *ptr) |
| 942 | { |
Sebastian Ott | 98cc43a | 2016-11-08 14:28:03 +0100 | [diff] [blame] | 943 | struct channel_subsystem *css; |
| 944 | int ret; |
Sebastian Ott | dcbd16d | 2009-06-16 10:30:22 +0200 | [diff] [blame] | 945 | |
| 946 | switch (event) { |
| 947 | case PM_HIBERNATION_PREPARE: |
| 948 | case PM_SUSPEND_PREPARE: |
| 949 | ret = NOTIFY_DONE; |
Sebastian Ott | 98cc43a | 2016-11-08 14:28:03 +0100 | [diff] [blame] | 950 | for_each_css(css) { |
Sebastian Ott | dcbd16d | 2009-06-16 10:30:22 +0200 | [diff] [blame] | 951 | mutex_lock(&css->mutex); |
| 952 | if (!css->cm_enabled) { |
| 953 | mutex_unlock(&css->mutex); |
| 954 | continue; |
| 955 | } |
Akinobu Mita | f0c077a | 2011-07-08 20:53:36 +0200 | [diff] [blame] | 956 | ret = __chsc_do_secm(css, 0); |
| 957 | ret = notifier_from_errno(ret); |
Sebastian Ott | dcbd16d | 2009-06-16 10:30:22 +0200 | [diff] [blame] | 958 | mutex_unlock(&css->mutex); |
| 959 | } |
| 960 | break; |
| 961 | case PM_POST_HIBERNATION: |
| 962 | case PM_POST_SUSPEND: |
| 963 | ret = NOTIFY_DONE; |
Sebastian Ott | 98cc43a | 2016-11-08 14:28:03 +0100 | [diff] [blame] | 964 | for_each_css(css) { |
Sebastian Ott | dcbd16d | 2009-06-16 10:30:22 +0200 | [diff] [blame] | 965 | mutex_lock(&css->mutex); |
| 966 | if (!css->cm_enabled) { |
| 967 | mutex_unlock(&css->mutex); |
| 968 | continue; |
| 969 | } |
Akinobu Mita | f0c077a | 2011-07-08 20:53:36 +0200 | [diff] [blame] | 970 | ret = __chsc_do_secm(css, 1); |
| 971 | ret = notifier_from_errno(ret); |
Sebastian Ott | dcbd16d | 2009-06-16 10:30:22 +0200 | [diff] [blame] | 972 | mutex_unlock(&css->mutex); |
| 973 | } |
| 974 | /* search for subchannels, which appeared during hibernation */ |
| 975 | css_schedule_reprobe(); |
| 976 | break; |
| 977 | default: |
| 978 | ret = NOTIFY_DONE; |
| 979 | } |
| 980 | return ret; |
| 981 | |
| 982 | } |
| 983 | static struct notifier_block css_power_notifier = { |
| 984 | .notifier_call = css_power_event, |
| 985 | }; |
| 986 | |
| 987 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 988 | * Now that the driver core is running, we can setup our channel subsystem. |
Sebastian Ott | 14556b3 | 2013-04-13 13:03:54 +0200 | [diff] [blame] | 989 | * The struct subchannel's are created during probing. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 990 | */ |
Sebastian Ott | 2f17644 | 2009-09-22 22:58:33 +0200 | [diff] [blame] | 991 | static int __init css_bus_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 992 | { |
Cornelia Huck | a28c694 | 2006-01-06 00:19:23 -0800 | [diff] [blame] | 993 | int ret, i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 994 | |
Sebastian Ott | 34aec07 | 2010-10-25 16:10:28 +0200 | [diff] [blame] | 995 | ret = chsc_init(); |
| 996 | if (ret) |
| 997 | return ret; |
| 998 | |
Sebastian Ott | 34196f8 | 2010-10-25 16:10:29 +0200 | [diff] [blame] | 999 | chsc_determine_css_characteristics(); |
Sebastian Ott | b0a285d | 2009-09-22 22:58:37 +0200 | [diff] [blame] | 1000 | /* Try to enable MSS. */ |
| 1001 | ret = chsc_enable_facility(CHSC_SDA_OC_MSS); |
Sebastian Ott | 818c272 | 2010-04-22 17:17:03 +0200 | [diff] [blame] | 1002 | if (ret) |
Sebastian Ott | b0a285d | 2009-09-22 22:58:37 +0200 | [diff] [blame] | 1003 | max_ssid = 0; |
Sebastian Ott | 818c272 | 2010-04-22 17:17:03 +0200 | [diff] [blame] | 1004 | else /* Success. */ |
| 1005 | max_ssid = __MAX_SSID; |
Sebastian Ott | b0a285d | 2009-09-22 22:58:37 +0200 | [diff] [blame] | 1006 | |
Cornelia Huck | 4434a38 | 2007-07-27 12:29:21 +0200 | [diff] [blame] | 1007 | ret = slow_subchannel_init(); |
| 1008 | if (ret) |
| 1009 | goto out; |
| 1010 | |
Heiko Carstens | f5daba1 | 2009-03-26 15:24:01 +0100 | [diff] [blame] | 1011 | ret = crw_register_handler(CRW_RSC_SCH, css_process_crw); |
Cornelia Huck | c115618 | 2008-07-14 09:58:46 +0200 | [diff] [blame] | 1012 | if (ret) |
| 1013 | goto out; |
| 1014 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1015 | if ((ret = bus_register(&css_bus_type))) |
| 1016 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1017 | |
Cornelia Huck | a28c694 | 2006-01-06 00:19:23 -0800 | [diff] [blame] | 1018 | /* Setup css structure. */ |
Sebastian Ott | 98cc43a | 2016-11-08 14:28:03 +0100 | [diff] [blame] | 1019 | for (i = 0; i <= MAX_CSS_IDX; i++) { |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 1020 | ret = setup_css(i); |
Sebastian Ott | 15a2044 | 2016-10-25 14:05:08 +0200 | [diff] [blame] | 1021 | if (ret) |
Cornelia Huck | a2164b8 | 2008-09-09 12:38:57 +0200 | [diff] [blame] | 1022 | goto out_unregister; |
Cornelia Huck | a28c694 | 2006-01-06 00:19:23 -0800 | [diff] [blame] | 1023 | } |
Cornelia Huck | a55360d | 2007-10-12 16:11:20 +0200 | [diff] [blame] | 1024 | ret = register_reboot_notifier(&css_reboot_notifier); |
| 1025 | if (ret) |
Cornelia Huck | a2164b8 | 2008-09-09 12:38:57 +0200 | [diff] [blame] | 1026 | goto out_unregister; |
Sebastian Ott | dcbd16d | 2009-06-16 10:30:22 +0200 | [diff] [blame] | 1027 | ret = register_pm_notifier(&css_power_notifier); |
| 1028 | if (ret) { |
| 1029 | unregister_reboot_notifier(&css_reboot_notifier); |
| 1030 | goto out_unregister; |
| 1031 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1032 | css_init_done = 1; |
| 1033 | |
Cornelia Huck | 3a3fc29 | 2008-07-14 09:58:58 +0200 | [diff] [blame] | 1034 | /* Enable default isc for I/O subchannels. */ |
Cornelia Huck | 6ef556c | 2008-07-14 09:59:01 +0200 | [diff] [blame] | 1035 | isc_register(IO_SCH_ISC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1036 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1037 | return 0; |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 1038 | out_unregister: |
Sebastian Ott | 15a2044 | 2016-10-25 14:05:08 +0200 | [diff] [blame] | 1039 | while (i-- > 0) { |
| 1040 | struct channel_subsystem *css = channel_subsystems[i]; |
Cornelia Huck | 7c9f4e3 | 2007-10-12 16:11:13 +0200 | [diff] [blame] | 1041 | device_unregister(&css->pseudo_subchannel->dev); |
Cornelia Huck | 7c9f4e3 | 2007-10-12 16:11:13 +0200 | [diff] [blame] | 1042 | device_unregister(&css->device); |
Cornelia Huck | a28c694 | 2006-01-06 00:19:23 -0800 | [diff] [blame] | 1043 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1044 | bus_unregister(&css_bus_type); |
| 1045 | out: |
Sebastian Ott | 34aec07 | 2010-10-25 16:10:28 +0200 | [diff] [blame] | 1046 | crw_unregister_handler(CRW_RSC_SCH); |
Sebastian Ott | b827d1c8 | 2009-09-22 22:58:36 +0200 | [diff] [blame] | 1047 | idset_free(slow_subchannel_set); |
Sebastian Ott | 34aec07 | 2010-10-25 16:10:28 +0200 | [diff] [blame] | 1048 | chsc_init_cleanup(); |
Michael Ernst | e6d5a42 | 2008-12-25 13:39:36 +0100 | [diff] [blame] | 1049 | pr_alert("The CSS device driver initialization failed with " |
| 1050 | "errno=%d\n", ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1051 | return ret; |
| 1052 | } |
| 1053 | |
Sebastian Ott | 2f17644 | 2009-09-22 22:58:33 +0200 | [diff] [blame] | 1054 | static void __init css_bus_cleanup(void) |
| 1055 | { |
| 1056 | struct channel_subsystem *css; |
Sebastian Ott | 2f17644 | 2009-09-22 22:58:33 +0200 | [diff] [blame] | 1057 | |
Sebastian Ott | 98cc43a | 2016-11-08 14:28:03 +0100 | [diff] [blame] | 1058 | for_each_css(css) { |
Sebastian Ott | 2f17644 | 2009-09-22 22:58:33 +0200 | [diff] [blame] | 1059 | device_unregister(&css->pseudo_subchannel->dev); |
Sebastian Ott | 2f17644 | 2009-09-22 22:58:33 +0200 | [diff] [blame] | 1060 | device_unregister(&css->device); |
| 1061 | } |
| 1062 | bus_unregister(&css_bus_type); |
Sebastian Ott | 34aec07 | 2010-10-25 16:10:28 +0200 | [diff] [blame] | 1063 | crw_unregister_handler(CRW_RSC_SCH); |
Sebastian Ott | b827d1c8 | 2009-09-22 22:58:36 +0200 | [diff] [blame] | 1064 | idset_free(slow_subchannel_set); |
Sebastian Ott | 34aec07 | 2010-10-25 16:10:28 +0200 | [diff] [blame] | 1065 | chsc_init_cleanup(); |
Sebastian Ott | 2f17644 | 2009-09-22 22:58:33 +0200 | [diff] [blame] | 1066 | isc_unregister(IO_SCH_ISC); |
| 1067 | } |
| 1068 | |
| 1069 | static int __init channel_subsystem_init(void) |
| 1070 | { |
| 1071 | int ret; |
| 1072 | |
| 1073 | ret = css_bus_init(); |
| 1074 | if (ret) |
| 1075 | return ret; |
Sebastian Ott | be5d382 | 2010-02-26 22:37:24 +0100 | [diff] [blame] | 1076 | cio_work_q = create_singlethread_workqueue("cio"); |
| 1077 | if (!cio_work_q) { |
| 1078 | ret = -ENOMEM; |
| 1079 | goto out_bus; |
| 1080 | } |
Sebastian Ott | 2f17644 | 2009-09-22 22:58:33 +0200 | [diff] [blame] | 1081 | ret = io_subchannel_init(); |
| 1082 | if (ret) |
Sebastian Ott | be5d382 | 2010-02-26 22:37:24 +0100 | [diff] [blame] | 1083 | goto out_wq; |
Sebastian Ott | 2f17644 | 2009-09-22 22:58:33 +0200 | [diff] [blame] | 1084 | |
| 1085 | return ret; |
Sebastian Ott | be5d382 | 2010-02-26 22:37:24 +0100 | [diff] [blame] | 1086 | out_wq: |
| 1087 | destroy_workqueue(cio_work_q); |
| 1088 | out_bus: |
| 1089 | css_bus_cleanup(); |
| 1090 | return ret; |
Sebastian Ott | 2f17644 | 2009-09-22 22:58:33 +0200 | [diff] [blame] | 1091 | } |
| 1092 | subsys_initcall(channel_subsystem_init); |
| 1093 | |
Sebastian Ott | 8ea7f55 | 2009-09-22 22:58:35 +0200 | [diff] [blame] | 1094 | static int css_settle(struct device_driver *drv, void *unused) |
| 1095 | { |
| 1096 | struct css_driver *cssdrv = to_cssdriver(drv); |
| 1097 | |
| 1098 | if (cssdrv->settle) |
Sebastian Ott | b4c7072 | 2010-02-26 22:37:27 +0100 | [diff] [blame] | 1099 | return cssdrv->settle(); |
Sebastian Ott | 8ea7f55 | 2009-09-22 22:58:35 +0200 | [diff] [blame] | 1100 | return 0; |
| 1101 | } |
| 1102 | |
Sebastian Ott | 0d01bb8 | 2010-02-26 22:37:29 +0100 | [diff] [blame] | 1103 | int css_complete_work(void) |
Sebastian Ott | 879acca5 | 2010-02-26 22:37:25 +0100 | [diff] [blame] | 1104 | { |
| 1105 | int ret; |
| 1106 | |
| 1107 | /* Wait for the evaluation of subchannels to finish. */ |
Sebastian Ott | b4c7072 | 2010-02-26 22:37:27 +0100 | [diff] [blame] | 1108 | ret = wait_event_interruptible(css_eval_wq, |
| 1109 | atomic_read(&css_eval_scheduled) == 0); |
| 1110 | if (ret) |
| 1111 | return -EINTR; |
Sebastian Ott | 879acca5 | 2010-02-26 22:37:25 +0100 | [diff] [blame] | 1112 | flush_workqueue(cio_work_q); |
| 1113 | /* Wait for the subchannel type specific initialization to finish */ |
Sebastian Ott | b4c7072 | 2010-02-26 22:37:27 +0100 | [diff] [blame] | 1114 | return bus_for_each_drv(&css_bus_type, NULL, NULL, css_settle); |
Sebastian Ott | 879acca5 | 2010-02-26 22:37:25 +0100 | [diff] [blame] | 1115 | } |
| 1116 | |
| 1117 | |
Sebastian Ott | 2f17644 | 2009-09-22 22:58:33 +0200 | [diff] [blame] | 1118 | /* |
| 1119 | * Wait for the initialization of devices to finish, to make sure we are |
| 1120 | * done with our setup if the search for the root device starts. |
| 1121 | */ |
| 1122 | static int __init channel_subsystem_init_sync(void) |
| 1123 | { |
Sebastian Ott | 14556b3 | 2013-04-13 13:03:54 +0200 | [diff] [blame] | 1124 | /* Register subchannels which are already in use. */ |
| 1125 | cio_register_early_subchannels(); |
Sebastian Ott | 703e5c9 | 2009-09-22 22:58:38 +0200 | [diff] [blame] | 1126 | /* Start initial subchannel evaluation. */ |
| 1127 | css_schedule_eval_all(); |
Sebastian Ott | 879acca5 | 2010-02-26 22:37:25 +0100 | [diff] [blame] | 1128 | css_complete_work(); |
| 1129 | return 0; |
Sebastian Ott | 2f17644 | 2009-09-22 22:58:33 +0200 | [diff] [blame] | 1130 | } |
| 1131 | subsys_initcall_sync(channel_subsystem_init_sync); |
| 1132 | |
Sebastian Ott | 889ee95 | 2010-04-22 17:17:04 +0200 | [diff] [blame] | 1133 | void channel_subsystem_reinit(void) |
| 1134 | { |
Sebastian Ott | 62da177 | 2010-10-25 16:10:32 +0200 | [diff] [blame] | 1135 | struct channel_path *chp; |
| 1136 | struct chp_id chpid; |
| 1137 | |
Sebastian Ott | 889ee95 | 2010-04-22 17:17:04 +0200 | [diff] [blame] | 1138 | chsc_enable_facility(CHSC_SDA_OC_MSS); |
Sebastian Ott | 62da177 | 2010-10-25 16:10:32 +0200 | [diff] [blame] | 1139 | chp_id_for_each(&chpid) { |
| 1140 | chp = chpid_to_chp(chpid); |
Peter Oberparleiter | cce0eac | 2013-03-11 12:58:18 +0100 | [diff] [blame] | 1141 | if (chp) |
| 1142 | chp_update_desc(chp); |
Sebastian Ott | 62da177 | 2010-10-25 16:10:32 +0200 | [diff] [blame] | 1143 | } |
Sebastian Ott | ab97d21 | 2015-09-09 10:29:59 +0200 | [diff] [blame] | 1144 | cmf_reactivate(); |
Sebastian Ott | 889ee95 | 2010-04-22 17:17:04 +0200 | [diff] [blame] | 1145 | } |
| 1146 | |
Sebastian Ott | 879acca5 | 2010-02-26 22:37:25 +0100 | [diff] [blame] | 1147 | #ifdef CONFIG_PROC_FS |
| 1148 | static ssize_t cio_settle_write(struct file *file, const char __user *buf, |
| 1149 | size_t count, loff_t *ppos) |
| 1150 | { |
Sebastian Ott | b4c7072 | 2010-02-26 22:37:27 +0100 | [diff] [blame] | 1151 | int ret; |
| 1152 | |
Sebastian Ott | 879acca5 | 2010-02-26 22:37:25 +0100 | [diff] [blame] | 1153 | /* Handle pending CRW's. */ |
| 1154 | crw_wait_for_channel_report(); |
Sebastian Ott | b4c7072 | 2010-02-26 22:37:27 +0100 | [diff] [blame] | 1155 | ret = css_complete_work(); |
| 1156 | |
| 1157 | return ret ? ret : count; |
Sebastian Ott | 879acca5 | 2010-02-26 22:37:25 +0100 | [diff] [blame] | 1158 | } |
| 1159 | |
| 1160 | static const struct file_operations cio_settle_proc_fops = { |
Martin Schwidefsky | 58ea91c | 2010-05-17 10:00:07 +0200 | [diff] [blame] | 1161 | .open = nonseekable_open, |
Sebastian Ott | 879acca5 | 2010-02-26 22:37:25 +0100 | [diff] [blame] | 1162 | .write = cio_settle_write, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 1163 | .llseek = no_llseek, |
Sebastian Ott | 879acca5 | 2010-02-26 22:37:25 +0100 | [diff] [blame] | 1164 | }; |
| 1165 | |
| 1166 | static int __init cio_settle_init(void) |
| 1167 | { |
| 1168 | struct proc_dir_entry *entry; |
| 1169 | |
| 1170 | entry = proc_create("cio_settle", S_IWUSR, NULL, |
| 1171 | &cio_settle_proc_fops); |
| 1172 | if (!entry) |
| 1173 | return -ENOMEM; |
| 1174 | return 0; |
| 1175 | } |
| 1176 | device_initcall(cio_settle_init); |
| 1177 | #endif /*CONFIG_PROC_FS*/ |
| 1178 | |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 1179 | int sch_is_pseudo_sch(struct subchannel *sch) |
| 1180 | { |
| 1181 | return sch == to_css(sch->dev.parent)->pseudo_subchannel; |
| 1182 | } |
| 1183 | |
Cornelia Huck | f08adc0 | 2008-07-14 09:59:03 +0200 | [diff] [blame] | 1184 | static int css_bus_match(struct device *dev, struct device_driver *drv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1185 | { |
Cornelia Huck | 084325d | 2008-01-26 14:10:38 +0100 | [diff] [blame] | 1186 | struct subchannel *sch = to_subchannel(dev); |
| 1187 | struct css_driver *driver = to_cssdriver(drv); |
Cornelia Huck | f08adc0 | 2008-07-14 09:59:03 +0200 | [diff] [blame] | 1188 | struct css_device_id *id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1189 | |
Cornelia Huck | f08adc0 | 2008-07-14 09:59:03 +0200 | [diff] [blame] | 1190 | for (id = driver->subchannel_type; id->match_flags; id++) { |
| 1191 | if (sch->st == id->type) |
| 1192 | return 1; |
| 1193 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1194 | |
| 1195 | return 0; |
| 1196 | } |
| 1197 | |
Cornelia Huck | 98c13c2 | 2008-01-26 14:10:40 +0100 | [diff] [blame] | 1198 | static int css_probe(struct device *dev) |
Cornelia Huck | 8bbace7 | 2006-01-11 10:56:22 +0100 | [diff] [blame] | 1199 | { |
| 1200 | struct subchannel *sch; |
Cornelia Huck | 98c13c2 | 2008-01-26 14:10:40 +0100 | [diff] [blame] | 1201 | int ret; |
Cornelia Huck | 8bbace7 | 2006-01-11 10:56:22 +0100 | [diff] [blame] | 1202 | |
| 1203 | sch = to_subchannel(dev); |
Cornelia Huck | 084325d | 2008-01-26 14:10:38 +0100 | [diff] [blame] | 1204 | sch->driver = to_cssdriver(dev->driver); |
Cornelia Huck | 98c13c2 | 2008-01-26 14:10:40 +0100 | [diff] [blame] | 1205 | ret = sch->driver->probe ? sch->driver->probe(sch) : 0; |
| 1206 | if (ret) |
| 1207 | sch->driver = NULL; |
| 1208 | return ret; |
Cornelia Huck | 8bbace7 | 2006-01-11 10:56:22 +0100 | [diff] [blame] | 1209 | } |
| 1210 | |
Cornelia Huck | 98c13c2 | 2008-01-26 14:10:40 +0100 | [diff] [blame] | 1211 | static int css_remove(struct device *dev) |
| 1212 | { |
| 1213 | struct subchannel *sch; |
| 1214 | int ret; |
| 1215 | |
| 1216 | sch = to_subchannel(dev); |
| 1217 | ret = sch->driver->remove ? sch->driver->remove(sch) : 0; |
| 1218 | sch->driver = NULL; |
| 1219 | return ret; |
| 1220 | } |
| 1221 | |
| 1222 | static void css_shutdown(struct device *dev) |
Cornelia Huck | 8bbace7 | 2006-01-11 10:56:22 +0100 | [diff] [blame] | 1223 | { |
| 1224 | struct subchannel *sch; |
| 1225 | |
| 1226 | sch = to_subchannel(dev); |
Cornelia Huck | 98c13c2 | 2008-01-26 14:10:40 +0100 | [diff] [blame] | 1227 | if (sch->driver && sch->driver->shutdown) |
Cornelia Huck | 8bbace7 | 2006-01-11 10:56:22 +0100 | [diff] [blame] | 1228 | sch->driver->shutdown(sch); |
| 1229 | } |
| 1230 | |
Cornelia Huck | 7e9db9e | 2008-07-14 09:58:44 +0200 | [diff] [blame] | 1231 | static int css_uevent(struct device *dev, struct kobj_uevent_env *env) |
| 1232 | { |
| 1233 | struct subchannel *sch = to_subchannel(dev); |
| 1234 | int ret; |
| 1235 | |
| 1236 | ret = add_uevent_var(env, "ST=%01X", sch->st); |
| 1237 | if (ret) |
| 1238 | return ret; |
| 1239 | ret = add_uevent_var(env, "MODALIAS=css:t%01X", sch->st); |
| 1240 | return ret; |
| 1241 | } |
| 1242 | |
Sebastian Ott | dcbd16d | 2009-06-16 10:30:22 +0200 | [diff] [blame] | 1243 | static int css_pm_prepare(struct device *dev) |
| 1244 | { |
| 1245 | struct subchannel *sch = to_subchannel(dev); |
| 1246 | struct css_driver *drv; |
| 1247 | |
| 1248 | if (mutex_is_locked(&sch->reg_mutex)) |
| 1249 | return -EAGAIN; |
| 1250 | if (!sch->dev.driver) |
| 1251 | return 0; |
| 1252 | drv = to_cssdriver(sch->dev.driver); |
| 1253 | /* Notify drivers that they may not register children. */ |
| 1254 | return drv->prepare ? drv->prepare(sch) : 0; |
| 1255 | } |
| 1256 | |
| 1257 | static void css_pm_complete(struct device *dev) |
| 1258 | { |
| 1259 | struct subchannel *sch = to_subchannel(dev); |
| 1260 | struct css_driver *drv; |
| 1261 | |
| 1262 | if (!sch->dev.driver) |
| 1263 | return; |
| 1264 | drv = to_cssdriver(sch->dev.driver); |
| 1265 | if (drv->complete) |
| 1266 | drv->complete(sch); |
| 1267 | } |
| 1268 | |
| 1269 | static int css_pm_freeze(struct device *dev) |
| 1270 | { |
| 1271 | struct subchannel *sch = to_subchannel(dev); |
| 1272 | struct css_driver *drv; |
| 1273 | |
| 1274 | if (!sch->dev.driver) |
| 1275 | return 0; |
| 1276 | drv = to_cssdriver(sch->dev.driver); |
| 1277 | return drv->freeze ? drv->freeze(sch) : 0; |
| 1278 | } |
| 1279 | |
| 1280 | static int css_pm_thaw(struct device *dev) |
| 1281 | { |
| 1282 | struct subchannel *sch = to_subchannel(dev); |
| 1283 | struct css_driver *drv; |
| 1284 | |
| 1285 | if (!sch->dev.driver) |
| 1286 | return 0; |
| 1287 | drv = to_cssdriver(sch->dev.driver); |
| 1288 | return drv->thaw ? drv->thaw(sch) : 0; |
| 1289 | } |
| 1290 | |
| 1291 | static int css_pm_restore(struct device *dev) |
| 1292 | { |
| 1293 | struct subchannel *sch = to_subchannel(dev); |
| 1294 | struct css_driver *drv; |
| 1295 | |
Sebastian Ott | eb4f5d9 | 2010-10-25 16:10:33 +0200 | [diff] [blame] | 1296 | css_update_ssd_info(sch); |
Sebastian Ott | dcbd16d | 2009-06-16 10:30:22 +0200 | [diff] [blame] | 1297 | if (!sch->dev.driver) |
| 1298 | return 0; |
| 1299 | drv = to_cssdriver(sch->dev.driver); |
| 1300 | return drv->restore ? drv->restore(sch) : 0; |
| 1301 | } |
| 1302 | |
Alexey Dobriyan | 4714521 | 2009-12-14 18:00:08 -0800 | [diff] [blame] | 1303 | static const struct dev_pm_ops css_pm_ops = { |
Sebastian Ott | dcbd16d | 2009-06-16 10:30:22 +0200 | [diff] [blame] | 1304 | .prepare = css_pm_prepare, |
| 1305 | .complete = css_pm_complete, |
| 1306 | .freeze = css_pm_freeze, |
| 1307 | .thaw = css_pm_thaw, |
| 1308 | .restore = css_pm_restore, |
| 1309 | }; |
| 1310 | |
Sebastian Ott | 3041b6a | 2011-03-15 17:08:31 +0100 | [diff] [blame] | 1311 | static struct bus_type css_bus_type = { |
Cornelia Huck | 8bbace7 | 2006-01-11 10:56:22 +0100 | [diff] [blame] | 1312 | .name = "css", |
| 1313 | .match = css_bus_match, |
| 1314 | .probe = css_probe, |
| 1315 | .remove = css_remove, |
| 1316 | .shutdown = css_shutdown, |
Cornelia Huck | 7e9db9e | 2008-07-14 09:58:44 +0200 | [diff] [blame] | 1317 | .uevent = css_uevent, |
Sebastian Ott | dcbd16d | 2009-06-16 10:30:22 +0200 | [diff] [blame] | 1318 | .pm = &css_pm_ops, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1319 | }; |
| 1320 | |
Cornelia Huck | 25b7bb5 | 2008-01-26 14:10:41 +0100 | [diff] [blame] | 1321 | /** |
| 1322 | * css_driver_register - register a css driver |
| 1323 | * @cdrv: css driver to register |
| 1324 | * |
| 1325 | * This is mainly a wrapper around driver_register that sets name |
| 1326 | * and bus_type in the embedded struct device_driver correctly. |
| 1327 | */ |
| 1328 | int css_driver_register(struct css_driver *cdrv) |
| 1329 | { |
Cornelia Huck | 25b7bb5 | 2008-01-26 14:10:41 +0100 | [diff] [blame] | 1330 | cdrv->drv.bus = &css_bus_type; |
| 1331 | return driver_register(&cdrv->drv); |
| 1332 | } |
| 1333 | EXPORT_SYMBOL_GPL(css_driver_register); |
| 1334 | |
| 1335 | /** |
| 1336 | * css_driver_unregister - unregister a css driver |
| 1337 | * @cdrv: css driver to unregister |
| 1338 | * |
| 1339 | * This is a wrapper around driver_unregister. |
| 1340 | */ |
| 1341 | void css_driver_unregister(struct css_driver *cdrv) |
| 1342 | { |
| 1343 | driver_unregister(&cdrv->drv); |
| 1344 | } |
| 1345 | EXPORT_SYMBOL_GPL(css_driver_unregister); |