blob: 1f2e424596af282b4937fd93fa30407930d5f2b4 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * drivers/s390/cio/css.c
3 * driver for channel subsystem
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Cornelia Huck7e9db9e2008-07-14 09:58:44 +02005 * Copyright IBM Corp. 2002,2008
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 * Author(s): Arnd Bergmann (arndb@de.ibm.com)
Cornelia Huck4ce3b302006-01-14 13:21:04 -08007 * Cornelia Huck (cornelia.huck@de.ibm.com)
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 */
Michael Ernste6d5a422008-12-25 13:39:36 +01009
10#define KMSG_COMPONENT "cio"
11#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
12
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <linux/module.h>
14#include <linux/init.h>
15#include <linux/device.h>
16#include <linux/slab.h>
17#include <linux/errno.h>
18#include <linux/list.h>
Cornelia Hucka55360d2007-10-12 16:11:20 +020019#include <linux/reboot.h>
Cornelia Huck3a3fc292008-07-14 09:58:58 +020020#include <asm/isc.h>
Heiko Carstensf5daba12009-03-26 15:24:01 +010021#include <asm/crw.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022
23#include "css.h"
24#include "cio.h"
25#include "cio_debug.h"
26#include "ioasm.h"
27#include "chsc.h"
Peter Oberparleiter40154b82006-06-29 14:57:03 +020028#include "device.h"
Peter Oberparleiter83b33702007-04-27 16:01:34 +020029#include "idset.h"
Peter Oberparleiter7ad6a242007-04-27 16:01:35 +020030#include "chp.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
Linus Torvalds1da177e2005-04-16 15:20:36 -070032int css_init_done = 0;
Peter Oberparleiter40154b82006-06-29 14:57:03 +020033static int need_reprobe = 0;
Cornelia Huckfb6958a2006-01-06 00:19:25 -080034static int max_ssid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
Cornelia Huck7c9f4e32007-10-12 16:11:13 +020036struct channel_subsystem *channel_subsystems[__MAX_CSSID + 1];
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
Heiko Carstens4d284ca2007-02-05 21:18:53 +010038int
Cornelia Huckf97a56f2006-01-06 00:19:22 -080039for_each_subchannel(int(*fn)(struct subchannel_id, void *), void *data)
40{
41 struct subchannel_id schid;
42 int ret;
43
44 init_subchannel_id(&schid);
45 ret = -ENODEV;
46 do {
Cornelia Huckfb6958a2006-01-06 00:19:25 -080047 do {
48 ret = fn(schid, data);
49 if (ret)
50 break;
51 } while (schid.sch_no++ < __MAX_SUBCHANNEL);
52 schid.sch_no = 0;
53 } while (schid.ssid++ < max_ssid);
Cornelia Huckf97a56f2006-01-06 00:19:22 -080054 return ret;
55}
56
Peter Oberparleitere82a1562008-01-26 14:10:48 +010057struct cb_data {
58 void *data;
59 struct idset *set;
60 int (*fn_known_sch)(struct subchannel *, void *);
61 int (*fn_unknown_sch)(struct subchannel_id, void *);
62};
63
64static int call_fn_known_sch(struct device *dev, void *data)
65{
66 struct subchannel *sch = to_subchannel(dev);
67 struct cb_data *cb = data;
68 int rc = 0;
69
70 idset_sch_del(cb->set, sch->schid);
71 if (cb->fn_known_sch)
72 rc = cb->fn_known_sch(sch, cb->data);
73 return rc;
74}
75
76static int call_fn_unknown_sch(struct subchannel_id schid, void *data)
77{
78 struct cb_data *cb = data;
79 int rc = 0;
80
81 if (idset_sch_contains(cb->set, schid))
82 rc = cb->fn_unknown_sch(schid, cb->data);
83 return rc;
84}
85
Sebastian Ott90ac24a2009-03-26 15:24:11 +010086static int call_fn_all_sch(struct subchannel_id schid, void *data)
87{
88 struct cb_data *cb = data;
89 struct subchannel *sch;
90 int rc = 0;
91
92 sch = get_subchannel_by_schid(schid);
93 if (sch) {
94 if (cb->fn_known_sch)
95 rc = cb->fn_known_sch(sch, cb->data);
96 put_device(&sch->dev);
97 } else {
98 if (cb->fn_unknown_sch)
99 rc = cb->fn_unknown_sch(schid, cb->data);
100 }
101
102 return rc;
103}
104
Peter Oberparleitere82a1562008-01-26 14:10:48 +0100105int for_each_subchannel_staged(int (*fn_known)(struct subchannel *, void *),
106 int (*fn_unknown)(struct subchannel_id,
107 void *), void *data)
108{
109 struct cb_data cb;
110 int rc;
111
Peter Oberparleitere82a1562008-01-26 14:10:48 +0100112 cb.data = data;
113 cb.fn_known_sch = fn_known;
114 cb.fn_unknown_sch = fn_unknown;
Sebastian Ott90ac24a2009-03-26 15:24:11 +0100115
116 cb.set = idset_sch_new();
117 if (!cb.set)
118 /* fall back to brute force scanning in case of oom */
119 return for_each_subchannel(call_fn_all_sch, &cb);
120
121 idset_fill(cb.set);
122
Peter Oberparleitere82a1562008-01-26 14:10:48 +0100123 /* Process registered subchannels. */
124 rc = bus_for_each_dev(&css_bus_type, NULL, &cb, call_fn_known_sch);
125 if (rc)
126 goto out;
127 /* Process unregistered subchannels. */
128 if (fn_unknown)
129 rc = for_each_subchannel(call_fn_unknown_sch, &cb);
130out:
131 idset_free(cb.set);
132
133 return rc;
134}
135
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136static struct subchannel *
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800137css_alloc_subchannel(struct subchannel_id schid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138{
139 struct subchannel *sch;
140 int ret;
141
142 sch = kmalloc (sizeof (*sch), GFP_KERNEL | GFP_DMA);
143 if (sch == NULL)
144 return ERR_PTR(-ENOMEM);
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800145 ret = cio_validate_subchannel (sch, schid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 if (ret < 0) {
147 kfree(sch);
148 return ERR_PTR(ret);
149 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 return sch;
151}
152
153static void
154css_free_subchannel(struct subchannel *sch)
155{
156 if (sch) {
157 /* Reset intparm to zeroes. */
Sebastian Ott13952ec2008-12-25 13:39:13 +0100158 sch->config.intparm = 0;
159 cio_commit_config(sch);
Cornelia Huck2ec22982006-12-08 15:54:26 +0100160 kfree(sch->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 kfree(sch);
162 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163}
164
165static void
166css_subchannel_release(struct device *dev)
167{
168 struct subchannel *sch;
169
170 sch = to_subchannel(dev);
Cornelia Huck2ec22982006-12-08 15:54:26 +0100171 if (!cio_is_console(sch->schid)) {
172 kfree(sch->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 kfree(sch);
Cornelia Huck2ec22982006-12-08 15:54:26 +0100174 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175}
176
Cornelia Huck07c6a332007-07-27 12:29:10 +0200177static int css_sch_device_register(struct subchannel *sch)
Cornelia Huck6ab48792006-07-12 16:39:50 +0200178{
179 int ret;
180
181 mutex_lock(&sch->reg_mutex);
182 ret = device_register(&sch->dev);
183 mutex_unlock(&sch->reg_mutex);
184 return ret;
185}
186
Cornelia Huck44a1c192008-07-14 09:58:47 +0200187/**
188 * css_sch_device_unregister - unregister a subchannel
189 * @sch: subchannel to be unregistered
190 */
Cornelia Huck6ab48792006-07-12 16:39:50 +0200191void css_sch_device_unregister(struct subchannel *sch)
192{
193 mutex_lock(&sch->reg_mutex);
Sebastian Ottef60cd12008-07-14 09:59:20 +0200194 if (device_is_registered(&sch->dev))
195 device_unregister(&sch->dev);
Cornelia Huck6ab48792006-07-12 16:39:50 +0200196 mutex_unlock(&sch->reg_mutex);
197}
Cornelia Huck44a1c192008-07-14 09:58:47 +0200198EXPORT_SYMBOL_GPL(css_sch_device_unregister);
Cornelia Huck6ab48792006-07-12 16:39:50 +0200199
Peter Oberparleiter7ad6a242007-04-27 16:01:35 +0200200static void ssd_from_pmcw(struct chsc_ssd_info *ssd, struct pmcw *pmcw)
201{
202 int i;
203 int mask;
204
205 memset(ssd, 0, sizeof(struct chsc_ssd_info));
206 ssd->path_mask = pmcw->pim;
207 for (i = 0; i < 8; i++) {
208 mask = 0x80 >> i;
209 if (pmcw->pim & mask) {
210 chp_id_init(&ssd->chpid[i]);
211 ssd->chpid[i].id = pmcw->chpid[i];
212 }
213 }
214}
215
216static void ssd_register_chpids(struct chsc_ssd_info *ssd)
217{
218 int i;
219 int mask;
220
221 for (i = 0; i < 8; i++) {
222 mask = 0x80 >> i;
223 if (ssd->path_mask & mask)
224 if (!chp_is_registered(ssd->chpid[i]))
225 chp_new(ssd->chpid[i]);
226 }
227}
228
229void css_update_ssd_info(struct subchannel *sch)
230{
231 int ret;
232
233 if (cio_is_console(sch->schid)) {
234 /* Console is initialized too early for functions requiring
235 * memory allocation. */
236 ssd_from_pmcw(&sch->ssd_info, &sch->schib.pmcw);
237 } else {
238 ret = chsc_get_ssd_info(sch->schid, &sch->ssd_info);
239 if (ret)
240 ssd_from_pmcw(&sch->ssd_info, &sch->schib.pmcw);
241 ssd_register_chpids(&sch->ssd_info);
242 }
243}
244
Cornelia Huck7e9db9e2008-07-14 09:58:44 +0200245static ssize_t type_show(struct device *dev, struct device_attribute *attr,
246 char *buf)
247{
248 struct subchannel *sch = to_subchannel(dev);
249
250 return sprintf(buf, "%01x\n", sch->st);
251}
252
253static DEVICE_ATTR(type, 0444, type_show, NULL);
254
255static ssize_t modalias_show(struct device *dev, struct device_attribute *attr,
256 char *buf)
257{
258 struct subchannel *sch = to_subchannel(dev);
259
260 return sprintf(buf, "css:t%01X\n", sch->st);
261}
262
263static DEVICE_ATTR(modalias, 0444, modalias_show, NULL);
264
265static struct attribute *subch_attrs[] = {
266 &dev_attr_type.attr,
267 &dev_attr_modalias.attr,
268 NULL,
269};
270
271static struct attribute_group subch_attr_group = {
272 .attrs = subch_attrs,
273};
274
275static struct attribute_group *default_subch_attr_groups[] = {
276 &subch_attr_group,
277 NULL,
278};
279
Peter Oberparleiter7ad6a242007-04-27 16:01:35 +0200280static int css_register_subchannel(struct subchannel *sch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281{
282 int ret;
283
284 /* Initialize the subchannel structure */
Cornelia Huck7c9f4e32007-10-12 16:11:13 +0200285 sch->dev.parent = &channel_subsystems[0]->device;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 sch->dev.bus = &css_bus_type;
287 sch->dev.release = &css_subchannel_release;
Cornelia Huck7e9db9e2008-07-14 09:58:44 +0200288 sch->dev.groups = default_subch_attr_groups;
Cornelia Huck5bf04b22007-10-22 12:52:41 +0200289 /*
290 * We don't want to generate uevents for I/O subchannels that don't
291 * have a working ccw device behind them since they will be
292 * unregistered before they can be used anyway, so we delay the add
293 * uevent until after device recognition was successful.
Cornelia Huck7e9db9e2008-07-14 09:58:44 +0200294 * Note that we suppress the uevent for all subchannel types;
295 * the subchannel driver can decide itself when it wants to inform
296 * userspace of its existence.
Cornelia Huck5bf04b22007-10-22 12:52:41 +0200297 */
Cornelia Huck7e9db9e2008-07-14 09:58:44 +0200298 sch->dev.uevent_suppress = 1;
Peter Oberparleiter7ad6a242007-04-27 16:01:35 +0200299 css_update_ssd_info(sch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 /* make it known to the system */
Cornelia Huck6ab48792006-07-12 16:39:50 +0200301 ret = css_sch_device_register(sch);
Cornelia Huck7674da72006-12-08 15:54:21 +0100302 if (ret) {
Cornelia Hucke556bbb2007-07-27 12:29:19 +0200303 CIO_MSG_EVENT(0, "Could not register sch 0.%x.%04x: %d\n",
304 sch->schid.ssid, sch->schid.sch_no, ret);
Cornelia Huck7674da72006-12-08 15:54:21 +0100305 return ret;
306 }
Cornelia Huck7e9db9e2008-07-14 09:58:44 +0200307 if (!sch->driver) {
308 /*
309 * No driver matched. Generate the uevent now so that
310 * a fitting driver module may be loaded based on the
311 * modalias.
312 */
313 sch->dev.uevent_suppress = 0;
314 kobject_uevent(&sch->dev.kobj, KOBJ_ADD);
315 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 return ret;
317}
318
Cornelia Huckc820de32008-07-14 09:58:45 +0200319int css_probe_device(struct subchannel_id schid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320{
321 int ret;
322 struct subchannel *sch;
323
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800324 sch = css_alloc_subchannel(schid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 if (IS_ERR(sch))
326 return PTR_ERR(sch);
327 ret = css_register_subchannel(sch);
328 if (ret)
329 css_free_subchannel(sch);
330 return ret;
331}
332
Cornelia Huckb0744bd2005-06-25 14:55:27 -0700333static int
334check_subchannel(struct device * dev, void * data)
335{
336 struct subchannel *sch;
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800337 struct subchannel_id *schid = data;
Cornelia Huckb0744bd2005-06-25 14:55:27 -0700338
339 sch = to_subchannel(dev);
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800340 return schid_equal(&sch->schid, schid);
Cornelia Huckb0744bd2005-06-25 14:55:27 -0700341}
342
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343struct subchannel *
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800344get_subchannel_by_schid(struct subchannel_id schid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 struct device *dev;
347
Cornelia Huckb0744bd2005-06-25 14:55:27 -0700348 dev = bus_find_device(&css_bus_type, NULL,
Cornelia Huck12975ae2006-10-11 15:31:47 +0200349 &schid, check_subchannel);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350
Cornelia Huckb0744bd2005-06-25 14:55:27 -0700351 return dev ? to_subchannel(dev) : NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352}
353
Cornelia Huckb279a4f2008-01-26 14:10:45 +0100354/**
355 * css_sch_is_valid() - check if a subchannel is valid
356 * @schib: subchannel information block for the subchannel
357 */
358int css_sch_is_valid(struct schib *schib)
359{
360 if ((schib->pmcw.st == SUBCHANNEL_TYPE_IO) && !schib->pmcw.dnv)
361 return 0;
Cornelia Huckb3a686f2008-07-14 09:58:48 +0200362 if ((schib->pmcw.st == SUBCHANNEL_TYPE_MSG) && !schib->pmcw.w)
363 return 0;
Cornelia Huckb279a4f2008-01-26 14:10:45 +0100364 return 1;
365}
366EXPORT_SYMBOL_GPL(css_sch_is_valid);
367
Peter Oberparleiter564337f2006-09-20 16:00:01 +0200368static int css_evaluate_new_subchannel(struct subchannel_id schid, int slow)
369{
370 struct schib schib;
371
372 if (!slow) {
373 /* Will be done on the slow path. */
374 return -EAGAIN;
375 }
Cornelia Huckb279a4f2008-01-26 14:10:45 +0100376 if (stsch_err(schid, &schib) || !css_sch_is_valid(&schib)) {
Peter Oberparleiter564337f2006-09-20 16:00:01 +0200377 /* Unusable - ignore. */
378 return 0;
379 }
380 CIO_MSG_EVENT(4, "Evaluating schid 0.%x.%04x, event %d, unknown, "
381 "slow path.\n", schid.ssid, schid.sch_no, CIO_OPER);
382
383 return css_probe_device(schid);
384}
385
Cornelia Huckc820de32008-07-14 09:58:45 +0200386static int css_evaluate_known_subchannel(struct subchannel *sch, int slow)
387{
388 int ret = 0;
389
390 if (sch->driver) {
391 if (sch->driver->sch_event)
392 ret = sch->driver->sch_event(sch, slow);
393 else
394 dev_dbg(&sch->dev,
395 "Got subchannel machine check but "
396 "no sch_event handler provided.\n");
397 }
398 return ret;
399}
400
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200401static void css_evaluate_subchannel(struct subchannel_id schid, int slow)
Peter Oberparleiter564337f2006-09-20 16:00:01 +0200402{
403 struct subchannel *sch;
404 int ret;
405
406 sch = get_subchannel_by_schid(schid);
407 if (sch) {
408 ret = css_evaluate_known_subchannel(sch, slow);
409 put_device(&sch->dev);
410 } else
411 ret = css_evaluate_new_subchannel(schid, slow);
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200412 if (ret == -EAGAIN)
413 css_schedule_eval(schid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414}
415
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200416static struct idset *slow_subchannel_set;
417static spinlock_t slow_subchannel_lock;
418
419static int __init slow_subchannel_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420{
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200421 spin_lock_init(&slow_subchannel_lock);
422 slow_subchannel_set = idset_sch_new();
423 if (!slow_subchannel_set) {
Cornelia Hucke556bbb2007-07-27 12:29:19 +0200424 CIO_MSG_EVENT(0, "could not allocate slow subchannel set\n");
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200425 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 }
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200427 return 0;
428}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429
Peter Oberparleitere82a1562008-01-26 14:10:48 +0100430static int slow_eval_known_fn(struct subchannel *sch, void *data)
431{
432 int eval;
433 int rc;
434
435 spin_lock_irq(&slow_subchannel_lock);
436 eval = idset_sch_contains(slow_subchannel_set, sch->schid);
437 idset_sch_del(slow_subchannel_set, sch->schid);
438 spin_unlock_irq(&slow_subchannel_lock);
439 if (eval) {
440 rc = css_evaluate_known_subchannel(sch, 1);
441 if (rc == -EAGAIN)
442 css_schedule_eval(sch->schid);
443 }
444 return 0;
445}
446
447static int slow_eval_unknown_fn(struct subchannel_id schid, void *data)
448{
449 int eval;
450 int rc = 0;
451
452 spin_lock_irq(&slow_subchannel_lock);
453 eval = idset_sch_contains(slow_subchannel_set, schid);
454 idset_sch_del(slow_subchannel_set, schid);
455 spin_unlock_irq(&slow_subchannel_lock);
456 if (eval) {
457 rc = css_evaluate_new_subchannel(schid, 1);
458 switch (rc) {
459 case -EAGAIN:
460 css_schedule_eval(schid);
461 rc = 0;
462 break;
463 case -ENXIO:
464 case -ENOMEM:
465 case -EIO:
466 /* These should abort looping */
467 break;
468 default:
469 rc = 0;
470 }
471 }
472 return rc;
473}
474
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200475static void css_slow_path_func(struct work_struct *unused)
476{
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200477 CIO_TRACE_EVENT(4, "slowpath");
Peter Oberparleitere82a1562008-01-26 14:10:48 +0100478 for_each_subchannel_staged(slow_eval_known_fn, slow_eval_unknown_fn,
479 NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480}
481
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200482static DECLARE_WORK(slow_path_work, css_slow_path_func);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483struct workqueue_struct *slow_path_wq;
484
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200485void css_schedule_eval(struct subchannel_id schid)
486{
487 unsigned long flags;
488
489 spin_lock_irqsave(&slow_subchannel_lock, flags);
490 idset_sch_add(slow_subchannel_set, schid);
491 queue_work(slow_path_wq, &slow_path_work);
492 spin_unlock_irqrestore(&slow_subchannel_lock, flags);
493}
494
495void css_schedule_eval_all(void)
496{
497 unsigned long flags;
498
499 spin_lock_irqsave(&slow_subchannel_lock, flags);
500 idset_fill(slow_subchannel_set);
501 queue_work(slow_path_wq, &slow_path_work);
502 spin_unlock_irqrestore(&slow_subchannel_lock, flags);
503}
504
Cornelia Huck22806dc2008-04-17 07:45:59 +0200505void css_wait_for_slow_path(void)
506{
Cornelia Huck22806dc2008-04-17 07:45:59 +0200507 flush_workqueue(slow_path_wq);
508}
509
Peter Oberparleiter40154b82006-06-29 14:57:03 +0200510/* Reprobe subchannel if unregistered. */
511static int reprobe_subchannel(struct subchannel_id schid, void *data)
512{
Peter Oberparleiter40154b82006-06-29 14:57:03 +0200513 int ret;
514
Cornelia Hucke556bbb2007-07-27 12:29:19 +0200515 CIO_MSG_EVENT(6, "cio: reprobe 0.%x.%04x\n",
516 schid.ssid, schid.sch_no);
Peter Oberparleiter40154b82006-06-29 14:57:03 +0200517 if (need_reprobe)
518 return -EAGAIN;
519
Peter Oberparleiter40154b82006-06-29 14:57:03 +0200520 ret = css_probe_device(schid);
521 switch (ret) {
522 case 0:
523 break;
524 case -ENXIO:
525 case -ENOMEM:
Peter Oberparleiter671756162007-12-04 16:09:02 +0100526 case -EIO:
Peter Oberparleiter40154b82006-06-29 14:57:03 +0200527 /* These should abort looping */
528 break;
529 default:
530 ret = 0;
531 }
532
533 return ret;
534}
535
536/* Work function used to reprobe all unregistered subchannels. */
Al Viro4927b3f2006-12-06 19:18:20 +0000537static void reprobe_all(struct work_struct *unused)
Peter Oberparleiter40154b82006-06-29 14:57:03 +0200538{
539 int ret;
540
Michael Ernst139b83d2008-05-07 09:22:54 +0200541 CIO_MSG_EVENT(4, "reprobe start\n");
Peter Oberparleiter40154b82006-06-29 14:57:03 +0200542
543 need_reprobe = 0;
544 /* Make sure initial subchannel scan is done. */
545 wait_event(ccw_device_init_wq,
546 atomic_read(&ccw_device_init_count) == 0);
Peter Oberparleitere82a1562008-01-26 14:10:48 +0100547 ret = for_each_subchannel_staged(NULL, reprobe_subchannel, NULL);
Peter Oberparleiter40154b82006-06-29 14:57:03 +0200548
Michael Ernst139b83d2008-05-07 09:22:54 +0200549 CIO_MSG_EVENT(4, "reprobe done (rc=%d, need_reprobe=%d)\n", ret,
Peter Oberparleiter40154b82006-06-29 14:57:03 +0200550 need_reprobe);
551}
552
Heiko Carstens2b67fc42007-02-05 21:16:47 +0100553static DECLARE_WORK(css_reprobe_work, reprobe_all);
Peter Oberparleiter40154b82006-06-29 14:57:03 +0200554
555/* Schedule reprobing of all unregistered subchannels. */
556void css_schedule_reprobe(void)
557{
558 need_reprobe = 1;
Cornelia Huckc5d4a992007-11-20 11:13:41 +0100559 queue_work(slow_path_wq, &css_reprobe_work);
Peter Oberparleiter40154b82006-06-29 14:57:03 +0200560}
561
562EXPORT_SYMBOL_GPL(css_schedule_reprobe);
563
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 * Called from the machine check handler for subchannel report words.
566 */
Cornelia Huckc1156182008-07-14 09:58:46 +0200567static void css_process_crw(struct crw *crw0, struct crw *crw1, int overflow)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568{
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800569 struct subchannel_id mchk_schid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570
Cornelia Huckc1156182008-07-14 09:58:46 +0200571 if (overflow) {
572 css_schedule_eval_all();
573 return;
574 }
575 CIO_CRW_EVENT(2, "CRW0 reports slct=%d, oflw=%d, "
576 "chn=%d, rsc=%X, anc=%d, erc=%X, rsid=%X\n",
577 crw0->slct, crw0->oflw, crw0->chn, crw0->rsc, crw0->anc,
578 crw0->erc, crw0->rsid);
579 if (crw1)
580 CIO_CRW_EVENT(2, "CRW1 reports slct=%d, oflw=%d, "
581 "chn=%d, rsc=%X, anc=%d, erc=%X, rsid=%X\n",
582 crw1->slct, crw1->oflw, crw1->chn, crw1->rsc,
583 crw1->anc, crw1->erc, crw1->rsid);
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800584 init_subchannel_id(&mchk_schid);
Cornelia Huckc1156182008-07-14 09:58:46 +0200585 mchk_schid.sch_no = crw0->rsid;
586 if (crw1)
587 mchk_schid.ssid = (crw1->rsid >> 8) & 3;
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800588
Cornelia Huckc1156182008-07-14 09:58:46 +0200589 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 * Since we are always presented with IPI in the CRW, we have to
591 * use stsch() to find out if the subchannel in question has come
592 * or gone.
593 */
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200594 css_evaluate_subchannel(mchk_schid, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595}
596
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800597static int __init
598__init_channel_subsystem(struct subchannel_id schid, void *data)
599{
600 struct subchannel *sch;
601 int ret;
602
603 if (cio_is_console(schid))
604 sch = cio_get_console_subchannel();
605 else {
606 sch = css_alloc_subchannel(schid);
607 if (IS_ERR(sch))
608 ret = PTR_ERR(sch);
609 else
610 ret = 0;
611 switch (ret) {
612 case 0:
613 break;
614 case -ENOMEM:
615 panic("Out of memory in init_channel_subsystem\n");
616 /* -ENXIO: no more subchannels. */
617 case -ENXIO:
618 return ret;
Greg Smithe843e282006-03-14 19:50:17 -0800619 /* -EIO: this subchannel set not supported. */
620 case -EIO:
621 return ret;
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800622 default:
623 return 0;
624 }
625 }
626 /*
627 * We register ALL valid subchannels in ioinfo, even those
628 * that have been present before init_channel_subsystem.
629 * These subchannels can't have been registered yet (kmalloc
630 * not working) so we do it now. This is true e.g. for the
631 * console subchannel.
632 */
633 css_register_subchannel(sch);
634 return 0;
635}
636
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637static void __init
Cornelia Hucka28c6942006-01-06 00:19:23 -0800638css_generate_pgid(struct channel_subsystem *css, u32 tod_high)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639{
Cornelia Huck75784c02008-07-14 09:58:57 +0200640 if (css_general_characteristics.mcss) {
Cornelia Hucka28c6942006-01-06 00:19:23 -0800641 css->global_pgid.pgid_high.ext_cssid.version = 0x80;
642 css->global_pgid.pgid_high.ext_cssid.cssid = css->cssid;
643 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644#ifdef CONFIG_SMP
Cornelia Hucka28c6942006-01-06 00:19:23 -0800645 css->global_pgid.pgid_high.cpu_addr = hard_smp_processor_id();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646#else
Cornelia Hucka28c6942006-01-06 00:19:23 -0800647 css->global_pgid.pgid_high.cpu_addr = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648#endif
649 }
Cornelia Hucka28c6942006-01-06 00:19:23 -0800650 css->global_pgid.cpu_id = ((cpuid_t *) __LC_CPUID)->ident;
651 css->global_pgid.cpu_model = ((cpuid_t *) __LC_CPUID)->machine;
652 css->global_pgid.tod_high = tod_high;
653
654}
655
Cornelia Huck3b793062006-01-06 00:19:26 -0800656static void
657channel_subsystem_release(struct device *dev)
658{
659 struct channel_subsystem *css;
660
661 css = to_css(dev);
Cornelia Huck495a5b42006-03-24 03:15:14 -0800662 mutex_destroy(&css->mutex);
Cornelia Hucka2164b82008-09-09 12:38:57 +0200663 if (css->pseudo_subchannel) {
664 /* Implies that it has been generated but never registered. */
665 css_subchannel_release(&css->pseudo_subchannel->dev);
666 css->pseudo_subchannel = NULL;
667 }
Cornelia Huck3b793062006-01-06 00:19:26 -0800668 kfree(css);
669}
670
Cornelia Huck495a5b42006-03-24 03:15:14 -0800671static ssize_t
672css_cm_enable_show(struct device *dev, struct device_attribute *attr,
673 char *buf)
674{
675 struct channel_subsystem *css = to_css(dev);
Michael Ernst8284fb192008-04-17 07:46:01 +0200676 int ret;
Cornelia Huck495a5b42006-03-24 03:15:14 -0800677
678 if (!css)
679 return 0;
Michael Ernst8284fb192008-04-17 07:46:01 +0200680 mutex_lock(&css->mutex);
681 ret = sprintf(buf, "%x\n", css->cm_enabled);
682 mutex_unlock(&css->mutex);
683 return ret;
Cornelia Huck495a5b42006-03-24 03:15:14 -0800684}
685
686static ssize_t
687css_cm_enable_store(struct device *dev, struct device_attribute *attr,
688 const char *buf, size_t count)
689{
690 struct channel_subsystem *css = to_css(dev);
691 int ret;
Cornelia Huck2f972202008-04-30 13:38:33 +0200692 unsigned long val;
Cornelia Huck495a5b42006-03-24 03:15:14 -0800693
Cornelia Huck2f972202008-04-30 13:38:33 +0200694 ret = strict_strtoul(buf, 16, &val);
695 if (ret)
696 return ret;
Michael Ernst8284fb192008-04-17 07:46:01 +0200697 mutex_lock(&css->mutex);
Cornelia Huck2f972202008-04-30 13:38:33 +0200698 switch (val) {
699 case 0:
Cornelia Huck495a5b42006-03-24 03:15:14 -0800700 ret = css->cm_enabled ? chsc_secm(css, 0) : 0;
701 break;
Cornelia Huck2f972202008-04-30 13:38:33 +0200702 case 1:
Cornelia Huck495a5b42006-03-24 03:15:14 -0800703 ret = css->cm_enabled ? 0 : chsc_secm(css, 1);
704 break;
705 default:
706 ret = -EINVAL;
707 }
Michael Ernst8284fb192008-04-17 07:46:01 +0200708 mutex_unlock(&css->mutex);
Cornelia Huck495a5b42006-03-24 03:15:14 -0800709 return ret < 0 ? ret : count;
710}
711
712static DEVICE_ATTR(cm_enable, 0644, css_cm_enable_show, css_cm_enable_store);
713
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100714static int __init setup_css(int nr)
Cornelia Hucka28c6942006-01-06 00:19:23 -0800715{
716 u32 tod_high;
Cornelia Huckd7b5a4c92006-12-08 15:54:28 +0100717 int ret;
Cornelia Huck7c9f4e32007-10-12 16:11:13 +0200718 struct channel_subsystem *css;
Cornelia Hucka28c6942006-01-06 00:19:23 -0800719
Cornelia Huck7c9f4e32007-10-12 16:11:13 +0200720 css = channel_subsystems[nr];
721 memset(css, 0, sizeof(struct channel_subsystem));
722 css->pseudo_subchannel =
723 kzalloc(sizeof(*css->pseudo_subchannel), GFP_KERNEL);
724 if (!css->pseudo_subchannel)
Cornelia Huckd7b5a4c92006-12-08 15:54:28 +0100725 return -ENOMEM;
Cornelia Huck7c9f4e32007-10-12 16:11:13 +0200726 css->pseudo_subchannel->dev.parent = &css->device;
727 css->pseudo_subchannel->dev.release = css_subchannel_release;
Cornelia Huck1bf5b282008-10-10 21:33:10 +0200728 dev_set_name(&css->pseudo_subchannel->dev, "defunct");
Cornelia Huck7c9f4e32007-10-12 16:11:13 +0200729 ret = cio_create_sch_lock(css->pseudo_subchannel);
Cornelia Huckd7b5a4c92006-12-08 15:54:28 +0100730 if (ret) {
Cornelia Huck7c9f4e32007-10-12 16:11:13 +0200731 kfree(css->pseudo_subchannel);
Cornelia Huckd7b5a4c92006-12-08 15:54:28 +0100732 return ret;
733 }
Cornelia Huck7c9f4e32007-10-12 16:11:13 +0200734 mutex_init(&css->mutex);
735 css->valid = 1;
736 css->cssid = nr;
Cornelia Huck1bf5b282008-10-10 21:33:10 +0200737 dev_set_name(&css->device, "css%x", nr);
Cornelia Huck7c9f4e32007-10-12 16:11:13 +0200738 css->device.release = channel_subsystem_release;
Cornelia Hucka28c6942006-01-06 00:19:23 -0800739 tod_high = (u32) (get_clock() >> 32);
Cornelia Huck7c9f4e32007-10-12 16:11:13 +0200740 css_generate_pgid(css, tod_high);
Cornelia Huckd7b5a4c92006-12-08 15:54:28 +0100741 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742}
743
Cornelia Hucka55360d2007-10-12 16:11:20 +0200744static int css_reboot_event(struct notifier_block *this,
745 unsigned long event,
746 void *ptr)
747{
748 int ret, i;
749
750 ret = NOTIFY_DONE;
751 for (i = 0; i <= __MAX_CSSID; i++) {
752 struct channel_subsystem *css;
753
754 css = channel_subsystems[i];
Michael Ernst8284fb192008-04-17 07:46:01 +0200755 mutex_lock(&css->mutex);
Cornelia Hucka55360d2007-10-12 16:11:20 +0200756 if (css->cm_enabled)
757 if (chsc_secm(css, 0))
758 ret = NOTIFY_BAD;
Michael Ernst8284fb192008-04-17 07:46:01 +0200759 mutex_unlock(&css->mutex);
Cornelia Hucka55360d2007-10-12 16:11:20 +0200760 }
761
762 return ret;
763}
764
765static struct notifier_block css_reboot_notifier = {
766 .notifier_call = css_reboot_event,
767};
768
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769/*
770 * Now that the driver core is running, we can setup our channel subsystem.
771 * The struct subchannel's are created during probing (except for the
772 * static console subchannel).
773 */
774static int __init
775init_channel_subsystem (void)
776{
Cornelia Hucka28c6942006-01-06 00:19:23 -0800777 int ret, i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778
Cornelia Huck4434a382007-07-27 12:29:21 +0200779 ret = chsc_determine_css_characteristics();
780 if (ret == -ENOMEM)
781 goto out; /* No need to continue. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782
Cornelia Huck4434a382007-07-27 12:29:21 +0200783 ret = chsc_alloc_sei_area();
784 if (ret)
785 goto out;
786
787 ret = slow_subchannel_init();
788 if (ret)
789 goto out;
790
Heiko Carstensf5daba12009-03-26 15:24:01 +0100791 ret = crw_register_handler(CRW_RSC_SCH, css_process_crw);
Cornelia Huckc1156182008-07-14 09:58:46 +0200792 if (ret)
793 goto out;
794
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795 if ((ret = bus_register(&css_bus_type)))
796 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800798 /* Try to enable MSS. */
799 ret = chsc_enable_facility(CHSC_SDA_OC_MSS);
800 switch (ret) {
801 case 0: /* Success. */
802 max_ssid = __MAX_SSID;
803 break;
804 case -ENOMEM:
805 goto out_bus;
806 default:
807 max_ssid = 0;
808 }
Cornelia Hucka28c6942006-01-06 00:19:23 -0800809 /* Setup css structure. */
810 for (i = 0; i <= __MAX_CSSID; i++) {
Cornelia Huck7c9f4e32007-10-12 16:11:13 +0200811 struct channel_subsystem *css;
812
813 css = kmalloc(sizeof(struct channel_subsystem), GFP_KERNEL);
814 if (!css) {
Cornelia Hucka28c6942006-01-06 00:19:23 -0800815 ret = -ENOMEM;
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800816 goto out_unregister;
Cornelia Hucka28c6942006-01-06 00:19:23 -0800817 }
Cornelia Huck7c9f4e32007-10-12 16:11:13 +0200818 channel_subsystems[i] = css;
Cornelia Huckd7b5a4c92006-12-08 15:54:28 +0100819 ret = setup_css(i);
Cornelia Hucka2164b82008-09-09 12:38:57 +0200820 if (ret) {
821 kfree(channel_subsystems[i]);
822 goto out_unregister;
823 }
Cornelia Huck7c9f4e32007-10-12 16:11:13 +0200824 ret = device_register(&css->device);
Cornelia Hucka2164b82008-09-09 12:38:57 +0200825 if (ret) {
826 put_device(&css->device);
827 goto out_unregister;
828 }
Cornelia Huck75784c02008-07-14 09:58:57 +0200829 if (css_chsc_characteristics.secm) {
Cornelia Huck7c9f4e32007-10-12 16:11:13 +0200830 ret = device_create_file(&css->device,
Cornelia Huck7e560812006-07-12 16:40:19 +0200831 &dev_attr_cm_enable);
832 if (ret)
833 goto out_device;
834 }
Cornelia Huck7c9f4e32007-10-12 16:11:13 +0200835 ret = device_register(&css->pseudo_subchannel->dev);
Cornelia Huckd7b5a4c92006-12-08 15:54:28 +0100836 if (ret)
837 goto out_file;
Cornelia Hucka28c6942006-01-06 00:19:23 -0800838 }
Cornelia Hucka55360d2007-10-12 16:11:20 +0200839 ret = register_reboot_notifier(&css_reboot_notifier);
840 if (ret)
Cornelia Hucka2164b82008-09-09 12:38:57 +0200841 goto out_unregister;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842 css_init_done = 1;
843
Cornelia Huck3a3fc292008-07-14 09:58:58 +0200844 /* Enable default isc for I/O subchannels. */
Cornelia Huck6ef556cc2008-07-14 09:59:01 +0200845 isc_register(IO_SCH_ISC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800847 for_each_subchannel(__init_channel_subsystem, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848 return 0;
Cornelia Huckd7b5a4c92006-12-08 15:54:28 +0100849out_file:
Cornelia Hucka2164b82008-09-09 12:38:57 +0200850 if (css_chsc_characteristics.secm)
851 device_remove_file(&channel_subsystems[i]->device,
852 &dev_attr_cm_enable);
Cornelia Huck7e560812006-07-12 16:40:19 +0200853out_device:
Cornelia Huck7c9f4e32007-10-12 16:11:13 +0200854 device_unregister(&channel_subsystems[i]->device);
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800855out_unregister:
Cornelia Hucka28c6942006-01-06 00:19:23 -0800856 while (i > 0) {
Cornelia Huck7c9f4e32007-10-12 16:11:13 +0200857 struct channel_subsystem *css;
858
Cornelia Hucka28c6942006-01-06 00:19:23 -0800859 i--;
Cornelia Huck7c9f4e32007-10-12 16:11:13 +0200860 css = channel_subsystems[i];
861 device_unregister(&css->pseudo_subchannel->dev);
Cornelia Hucka2164b82008-09-09 12:38:57 +0200862 css->pseudo_subchannel = NULL;
Cornelia Huck75784c02008-07-14 09:58:57 +0200863 if (css_chsc_characteristics.secm)
Cornelia Huck7c9f4e32007-10-12 16:11:13 +0200864 device_remove_file(&css->device,
Cornelia Huck495a5b42006-03-24 03:15:14 -0800865 &dev_attr_cm_enable);
Cornelia Huck7c9f4e32007-10-12 16:11:13 +0200866 device_unregister(&css->device);
Cornelia Hucka28c6942006-01-06 00:19:23 -0800867 }
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800868out_bus:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869 bus_unregister(&css_bus_type);
870out:
Heiko Carstensf5daba12009-03-26 15:24:01 +0100871 crw_unregister_handler(CRW_RSC_CSS);
Cornelia Huck4434a382007-07-27 12:29:21 +0200872 chsc_free_sei_area();
873 kfree(slow_subchannel_set);
Michael Ernste6d5a422008-12-25 13:39:36 +0100874 pr_alert("The CSS device driver initialization failed with "
875 "errno=%d\n", ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876 return ret;
877}
878
Cornelia Huckd7b5a4c92006-12-08 15:54:28 +0100879int sch_is_pseudo_sch(struct subchannel *sch)
880{
881 return sch == to_css(sch->dev.parent)->pseudo_subchannel;
882}
883
Cornelia Huckf08adc02008-07-14 09:59:03 +0200884static int css_bus_match(struct device *dev, struct device_driver *drv)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885{
Cornelia Huck084325d2008-01-26 14:10:38 +0100886 struct subchannel *sch = to_subchannel(dev);
887 struct css_driver *driver = to_cssdriver(drv);
Cornelia Huckf08adc02008-07-14 09:59:03 +0200888 struct css_device_id *id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889
Cornelia Huckf08adc02008-07-14 09:59:03 +0200890 for (id = driver->subchannel_type; id->match_flags; id++) {
891 if (sch->st == id->type)
892 return 1;
893 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894
895 return 0;
896}
897
Cornelia Huck98c13c22008-01-26 14:10:40 +0100898static int css_probe(struct device *dev)
Cornelia Huck8bbace72006-01-11 10:56:22 +0100899{
900 struct subchannel *sch;
Cornelia Huck98c13c22008-01-26 14:10:40 +0100901 int ret;
Cornelia Huck8bbace72006-01-11 10:56:22 +0100902
903 sch = to_subchannel(dev);
Cornelia Huck084325d2008-01-26 14:10:38 +0100904 sch->driver = to_cssdriver(dev->driver);
Cornelia Huck98c13c22008-01-26 14:10:40 +0100905 ret = sch->driver->probe ? sch->driver->probe(sch) : 0;
906 if (ret)
907 sch->driver = NULL;
908 return ret;
Cornelia Huck8bbace72006-01-11 10:56:22 +0100909}
910
Cornelia Huck98c13c22008-01-26 14:10:40 +0100911static int css_remove(struct device *dev)
912{
913 struct subchannel *sch;
914 int ret;
915
916 sch = to_subchannel(dev);
917 ret = sch->driver->remove ? sch->driver->remove(sch) : 0;
918 sch->driver = NULL;
919 return ret;
920}
921
922static void css_shutdown(struct device *dev)
Cornelia Huck8bbace72006-01-11 10:56:22 +0100923{
924 struct subchannel *sch;
925
926 sch = to_subchannel(dev);
Cornelia Huck98c13c22008-01-26 14:10:40 +0100927 if (sch->driver && sch->driver->shutdown)
Cornelia Huck8bbace72006-01-11 10:56:22 +0100928 sch->driver->shutdown(sch);
929}
930
Cornelia Huck7e9db9e2008-07-14 09:58:44 +0200931static int css_uevent(struct device *dev, struct kobj_uevent_env *env)
932{
933 struct subchannel *sch = to_subchannel(dev);
934 int ret;
935
936 ret = add_uevent_var(env, "ST=%01X", sch->st);
937 if (ret)
938 return ret;
939 ret = add_uevent_var(env, "MODALIAS=css:t%01X", sch->st);
940 return ret;
941}
942
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943struct bus_type css_bus_type = {
Cornelia Huck8bbace72006-01-11 10:56:22 +0100944 .name = "css",
945 .match = css_bus_match,
946 .probe = css_probe,
947 .remove = css_remove,
948 .shutdown = css_shutdown,
Cornelia Huck7e9db9e2008-07-14 09:58:44 +0200949 .uevent = css_uevent,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950};
951
Cornelia Huck25b7bb52008-01-26 14:10:41 +0100952/**
953 * css_driver_register - register a css driver
954 * @cdrv: css driver to register
955 *
956 * This is mainly a wrapper around driver_register that sets name
957 * and bus_type in the embedded struct device_driver correctly.
958 */
959int css_driver_register(struct css_driver *cdrv)
960{
961 cdrv->drv.name = cdrv->name;
962 cdrv->drv.bus = &css_bus_type;
Cornelia Huck4beee642008-01-26 14:10:47 +0100963 cdrv->drv.owner = cdrv->owner;
Cornelia Huck25b7bb52008-01-26 14:10:41 +0100964 return driver_register(&cdrv->drv);
965}
966EXPORT_SYMBOL_GPL(css_driver_register);
967
968/**
969 * css_driver_unregister - unregister a css driver
970 * @cdrv: css driver to unregister
971 *
972 * This is a wrapper around driver_unregister.
973 */
974void css_driver_unregister(struct css_driver *cdrv)
975{
976 driver_unregister(&cdrv->drv);
977}
978EXPORT_SYMBOL_GPL(css_driver_unregister);
979
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980subsys_initcall(init_channel_subsystem);
981
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982MODULE_LICENSE("GPL");
983EXPORT_SYMBOL(css_bus_type);