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