blob: b7f4b52c5a9a7315ff1b24365acc40b6258f0ac0 [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 *
5 * Copyright (C) 2002 IBM Deutschland Entwicklung GmbH,
6 * IBM Corporation
7 * Author(s): Arnd Bergmann (arndb@de.ibm.com)
Cornelia Huck4ce3b302006-01-14 13:21:04 -08008 * Cornelia Huck (cornelia.huck@de.ibm.com)
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 */
10#include <linux/module.h>
11#include <linux/init.h>
12#include <linux/device.h>
13#include <linux/slab.h>
14#include <linux/errno.h>
15#include <linux/list.h>
Cornelia Hucka55360d2007-10-12 16:11:20 +020016#include <linux/reboot.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
18#include "css.h"
19#include "cio.h"
20#include "cio_debug.h"
21#include "ioasm.h"
22#include "chsc.h"
Peter Oberparleiter40154b82006-06-29 14:57:03 +020023#include "device.h"
Peter Oberparleiter83b33702007-04-27 16:01:34 +020024#include "idset.h"
Peter Oberparleiter7ad6a242007-04-27 16:01:35 +020025#include "chp.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
Linus Torvalds1da177e2005-04-16 15:20:36 -070027int css_init_done = 0;
Peter Oberparleiter40154b82006-06-29 14:57:03 +020028static int need_reprobe = 0;
Cornelia Huckfb6958a2006-01-06 00:19:25 -080029static int max_ssid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
Cornelia Huck7c9f4e32007-10-12 16:11:13 +020031struct channel_subsystem *channel_subsystems[__MAX_CSSID + 1];
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
Cornelia Hucka28c6942006-01-06 00:19:23 -080033int css_characteristics_avail = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
Heiko Carstens4d284ca2007-02-05 21:18:53 +010035int
Cornelia Huckf97a56f2006-01-06 00:19:22 -080036for_each_subchannel(int(*fn)(struct subchannel_id, void *), void *data)
37{
38 struct subchannel_id schid;
39 int ret;
40
41 init_subchannel_id(&schid);
42 ret = -ENODEV;
43 do {
Cornelia Huckfb6958a2006-01-06 00:19:25 -080044 do {
45 ret = fn(schid, data);
46 if (ret)
47 break;
48 } while (schid.sch_no++ < __MAX_SUBCHANNEL);
49 schid.sch_no = 0;
50 } while (schid.ssid++ < max_ssid);
Cornelia Huckf97a56f2006-01-06 00:19:22 -080051 return ret;
52}
53
Peter Oberparleitere82a1562008-01-26 14:10:48 +010054struct cb_data {
55 void *data;
56 struct idset *set;
57 int (*fn_known_sch)(struct subchannel *, void *);
58 int (*fn_unknown_sch)(struct subchannel_id, void *);
59};
60
61static int call_fn_known_sch(struct device *dev, void *data)
62{
63 struct subchannel *sch = to_subchannel(dev);
64 struct cb_data *cb = data;
65 int rc = 0;
66
67 idset_sch_del(cb->set, sch->schid);
68 if (cb->fn_known_sch)
69 rc = cb->fn_known_sch(sch, cb->data);
70 return rc;
71}
72
73static int call_fn_unknown_sch(struct subchannel_id schid, void *data)
74{
75 struct cb_data *cb = data;
76 int rc = 0;
77
78 if (idset_sch_contains(cb->set, schid))
79 rc = cb->fn_unknown_sch(schid, cb->data);
80 return rc;
81}
82
83int for_each_subchannel_staged(int (*fn_known)(struct subchannel *, void *),
84 int (*fn_unknown)(struct subchannel_id,
85 void *), void *data)
86{
87 struct cb_data cb;
88 int rc;
89
90 cb.set = idset_sch_new();
91 if (!cb.set)
92 return -ENOMEM;
93 idset_fill(cb.set);
94 cb.data = data;
95 cb.fn_known_sch = fn_known;
96 cb.fn_unknown_sch = fn_unknown;
97 /* Process registered subchannels. */
98 rc = bus_for_each_dev(&css_bus_type, NULL, &cb, call_fn_known_sch);
99 if (rc)
100 goto out;
101 /* Process unregistered subchannels. */
102 if (fn_unknown)
103 rc = for_each_subchannel(call_fn_unknown_sch, &cb);
104out:
105 idset_free(cb.set);
106
107 return rc;
108}
109
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110static struct subchannel *
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800111css_alloc_subchannel(struct subchannel_id schid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112{
113 struct subchannel *sch;
114 int ret;
115
116 sch = kmalloc (sizeof (*sch), GFP_KERNEL | GFP_DMA);
117 if (sch == NULL)
118 return ERR_PTR(-ENOMEM);
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800119 ret = cio_validate_subchannel (sch, schid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 if (ret < 0) {
121 kfree(sch);
122 return ERR_PTR(ret);
123 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 return sch;
125}
126
127static void
128css_free_subchannel(struct subchannel *sch)
129{
130 if (sch) {
131 /* Reset intparm to zeroes. */
132 sch->schib.pmcw.intparm = 0;
133 cio_modify(sch);
Cornelia Huck2ec22982006-12-08 15:54:26 +0100134 kfree(sch->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 kfree(sch);
136 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137}
138
139static void
140css_subchannel_release(struct device *dev)
141{
142 struct subchannel *sch;
143
144 sch = to_subchannel(dev);
Cornelia Huck2ec22982006-12-08 15:54:26 +0100145 if (!cio_is_console(sch->schid)) {
146 kfree(sch->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 kfree(sch);
Cornelia Huck2ec22982006-12-08 15:54:26 +0100148 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149}
150
Cornelia Huck07c6a332007-07-27 12:29:10 +0200151static int css_sch_device_register(struct subchannel *sch)
Cornelia Huck6ab48792006-07-12 16:39:50 +0200152{
153 int ret;
154
155 mutex_lock(&sch->reg_mutex);
156 ret = device_register(&sch->dev);
157 mutex_unlock(&sch->reg_mutex);
158 return ret;
159}
160
161void css_sch_device_unregister(struct subchannel *sch)
162{
163 mutex_lock(&sch->reg_mutex);
164 device_unregister(&sch->dev);
165 mutex_unlock(&sch->reg_mutex);
166}
167
Peter Oberparleiter7ad6a242007-04-27 16:01:35 +0200168static void ssd_from_pmcw(struct chsc_ssd_info *ssd, struct pmcw *pmcw)
169{
170 int i;
171 int mask;
172
173 memset(ssd, 0, sizeof(struct chsc_ssd_info));
174 ssd->path_mask = pmcw->pim;
175 for (i = 0; i < 8; i++) {
176 mask = 0x80 >> i;
177 if (pmcw->pim & mask) {
178 chp_id_init(&ssd->chpid[i]);
179 ssd->chpid[i].id = pmcw->chpid[i];
180 }
181 }
182}
183
184static void ssd_register_chpids(struct chsc_ssd_info *ssd)
185{
186 int i;
187 int mask;
188
189 for (i = 0; i < 8; i++) {
190 mask = 0x80 >> i;
191 if (ssd->path_mask & mask)
192 if (!chp_is_registered(ssd->chpid[i]))
193 chp_new(ssd->chpid[i]);
194 }
195}
196
197void css_update_ssd_info(struct subchannel *sch)
198{
199 int ret;
200
201 if (cio_is_console(sch->schid)) {
202 /* Console is initialized too early for functions requiring
203 * memory allocation. */
204 ssd_from_pmcw(&sch->ssd_info, &sch->schib.pmcw);
205 } else {
206 ret = chsc_get_ssd_info(sch->schid, &sch->ssd_info);
207 if (ret)
208 ssd_from_pmcw(&sch->ssd_info, &sch->schib.pmcw);
209 ssd_register_chpids(&sch->ssd_info);
210 }
211}
212
213static int css_register_subchannel(struct subchannel *sch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214{
215 int ret;
216
217 /* Initialize the subchannel structure */
Cornelia Huck7c9f4e32007-10-12 16:11:13 +0200218 sch->dev.parent = &channel_subsystems[0]->device;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 sch->dev.bus = &css_bus_type;
220 sch->dev.release = &css_subchannel_release;
Cornelia Huck529192f2006-12-08 15:55:57 +0100221 sch->dev.groups = subch_attr_groups;
Cornelia Huck5bf04b22007-10-22 12:52:41 +0200222 /*
223 * We don't want to generate uevents for I/O subchannels that don't
224 * have a working ccw device behind them since they will be
225 * unregistered before they can be used anyway, so we delay the add
226 * uevent until after device recognition was successful.
227 */
228 if (!cio_is_console(sch->schid))
229 /* Console is special, no need to suppress. */
230 sch->dev.uevent_suppress = 1;
Peter Oberparleiter7ad6a242007-04-27 16:01:35 +0200231 css_update_ssd_info(sch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 /* make it known to the system */
Cornelia Huck6ab48792006-07-12 16:39:50 +0200233 ret = css_sch_device_register(sch);
Cornelia Huck7674da72006-12-08 15:54:21 +0100234 if (ret) {
Cornelia Hucke556bbb2007-07-27 12:29:19 +0200235 CIO_MSG_EVENT(0, "Could not register sch 0.%x.%04x: %d\n",
236 sch->schid.ssid, sch->schid.sch_no, ret);
Cornelia Huck7674da72006-12-08 15:54:21 +0100237 return ret;
238 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 return ret;
240}
241
Cornelia Huckf7e5d672007-05-10 15:45:43 +0200242static int css_probe_device(struct subchannel_id schid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243{
244 int ret;
245 struct subchannel *sch;
246
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800247 sch = css_alloc_subchannel(schid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 if (IS_ERR(sch))
249 return PTR_ERR(sch);
250 ret = css_register_subchannel(sch);
251 if (ret)
252 css_free_subchannel(sch);
253 return ret;
254}
255
Cornelia Huckb0744bd2005-06-25 14:55:27 -0700256static int
257check_subchannel(struct device * dev, void * data)
258{
259 struct subchannel *sch;
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800260 struct subchannel_id *schid = data;
Cornelia Huckb0744bd2005-06-25 14:55:27 -0700261
262 sch = to_subchannel(dev);
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800263 return schid_equal(&sch->schid, schid);
Cornelia Huckb0744bd2005-06-25 14:55:27 -0700264}
265
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266struct subchannel *
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800267get_subchannel_by_schid(struct subchannel_id schid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 struct device *dev;
270
Cornelia Huckb0744bd2005-06-25 14:55:27 -0700271 dev = bus_find_device(&css_bus_type, NULL,
Cornelia Huck12975ae2006-10-11 15:31:47 +0200272 &schid, check_subchannel);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273
Cornelia Huckb0744bd2005-06-25 14:55:27 -0700274 return dev ? to_subchannel(dev) : NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275}
276
Cornelia Huckb279a4f2008-01-26 14:10:45 +0100277/**
278 * css_sch_is_valid() - check if a subchannel is valid
279 * @schib: subchannel information block for the subchannel
280 */
281int css_sch_is_valid(struct schib *schib)
282{
283 if ((schib->pmcw.st == SUBCHANNEL_TYPE_IO) && !schib->pmcw.dnv)
284 return 0;
285 return 1;
286}
287EXPORT_SYMBOL_GPL(css_sch_is_valid);
288
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100289static int css_get_subchannel_status(struct subchannel *sch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290{
291 struct schib schib;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292
Cornelia Huckb279a4f2008-01-26 14:10:45 +0100293 if (stsch(sch->schid, &schib))
294 return CIO_GONE;
295 if (!css_sch_is_valid(&schib))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 return CIO_GONE;
Peter Oberparleiter564337f2006-09-20 16:00:01 +0200297 if (sch->schib.pmcw.dnv && (schib.pmcw.dev != sch->schib.pmcw.dev))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 return CIO_REVALIDATE;
Peter Oberparleiter564337f2006-09-20 16:00:01 +0200299 if (!sch->lpm)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 return CIO_NO_PATH;
301 return CIO_OPER;
302}
Peter Oberparleiter564337f2006-09-20 16:00:01 +0200303
304static int css_evaluate_known_subchannel(struct subchannel *sch, int slow)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305{
306 int event, ret, disc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 unsigned long flags;
Peter Oberparleiter564337f2006-09-20 16:00:01 +0200308 enum { NONE, UNREGISTER, UNREGISTER_PROBE, REPROBE } action;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309
Cornelia Huck2ec22982006-12-08 15:54:26 +0100310 spin_lock_irqsave(sch->lock, flags);
Peter Oberparleiter564337f2006-09-20 16:00:01 +0200311 disc = device_is_disconnected(sch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 if (disc && slow) {
Peter Oberparleiter564337f2006-09-20 16:00:01 +0200313 /* Disconnected devices are evaluated directly only.*/
Cornelia Huck2ec22982006-12-08 15:54:26 +0100314 spin_unlock_irqrestore(sch->lock, flags);
Peter Oberparleiter564337f2006-09-20 16:00:01 +0200315 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 }
Peter Oberparleiter564337f2006-09-20 16:00:01 +0200317 /* No interrupt after machine check - kill pending timers. */
318 device_kill_pending_timer(sch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 if (!disc && !slow) {
Peter Oberparleiter564337f2006-09-20 16:00:01 +0200320 /* Non-disconnected devices are evaluated on the slow path. */
Cornelia Huck2ec22982006-12-08 15:54:26 +0100321 spin_unlock_irqrestore(sch->lock, flags);
Peter Oberparleiter564337f2006-09-20 16:00:01 +0200322 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 }
Peter Oberparleiter564337f2006-09-20 16:00:01 +0200324 event = css_get_subchannel_status(sch);
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800325 CIO_MSG_EVENT(4, "Evaluating schid 0.%x.%04x, event %d, %s, %s path.\n",
Peter Oberparleiter564337f2006-09-20 16:00:01 +0200326 sch->schid.ssid, sch->schid.sch_no, event,
327 disc ? "disconnected" : "normal",
328 slow ? "slow" : "fast");
329 /* Analyze subchannel status. */
330 action = NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 switch (event) {
332 case CIO_NO_PATH:
Peter Oberparleiter564337f2006-09-20 16:00:01 +0200333 if (disc) {
334 /* Check if paths have become available. */
335 action = REPROBE;
336 break;
337 }
338 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 case CIO_GONE:
Peter Oberparleiter564337f2006-09-20 16:00:01 +0200340 /* Prevent unwanted effects when opening lock. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 cio_disable_subchannel(sch);
Peter Oberparleiter564337f2006-09-20 16:00:01 +0200342 device_set_disconnected(sch);
343 /* Ask driver what to do with device. */
344 action = UNREGISTER;
345 if (sch->driver && sch->driver->notify) {
Cornelia Huck2ec22982006-12-08 15:54:26 +0100346 spin_unlock_irqrestore(sch->lock, flags);
Cornelia Huck602b20f2008-01-26 14:10:39 +0100347 ret = sch->driver->notify(sch, event);
Cornelia Huck2ec22982006-12-08 15:54:26 +0100348 spin_lock_irqsave(sch->lock, flags);
Peter Oberparleiter564337f2006-09-20 16:00:01 +0200349 if (ret)
350 action = NONE;
351 }
352 break;
353 case CIO_REVALIDATE:
354 /* Device will be removed, so no notify necessary. */
355 if (disc)
356 /* Reprobe because immediate unregister might block. */
357 action = REPROBE;
358 else
359 action = UNREGISTER_PROBE;
360 break;
361 case CIO_OPER:
362 if (disc)
363 /* Get device operational again. */
364 action = REPROBE;
365 break;
366 }
367 /* Perform action. */
368 ret = 0;
369 switch (action) {
370 case UNREGISTER:
371 case UNREGISTER_PROBE:
372 /* Unregister device (will use subchannel lock). */
Cornelia Huck2ec22982006-12-08 15:54:26 +0100373 spin_unlock_irqrestore(sch->lock, flags);
Cornelia Huck6ab48792006-07-12 16:39:50 +0200374 css_sch_device_unregister(sch);
Cornelia Huck2ec22982006-12-08 15:54:26 +0100375 spin_lock_irqsave(sch->lock, flags);
Peter Oberparleiter564337f2006-09-20 16:00:01 +0200376
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 /* Reset intparm to zeroes. */
378 sch->schib.pmcw.intparm = 0;
379 cio_modify(sch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 break;
Peter Oberparleiter564337f2006-09-20 16:00:01 +0200381 case REPROBE:
382 device_trigger_reprobe(sch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 break;
384 default:
Peter Oberparleiter564337f2006-09-20 16:00:01 +0200385 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 }
Cornelia Huck2ec22982006-12-08 15:54:26 +0100387 spin_unlock_irqrestore(sch->lock, flags);
Cornelia Huckc2b14492006-10-27 12:39:17 +0200388 /* Probe if necessary. */
389 if (action == UNREGISTER_PROBE)
390 ret = css_probe_device(sch->schid);
Peter Oberparleiter564337f2006-09-20 16:00:01 +0200391
392 return ret;
393}
394
395static int css_evaluate_new_subchannel(struct subchannel_id schid, int slow)
396{
397 struct schib schib;
398
399 if (!slow) {
400 /* Will be done on the slow path. */
401 return -EAGAIN;
402 }
Cornelia Huckb279a4f2008-01-26 14:10:45 +0100403 if (stsch_err(schid, &schib) || !css_sch_is_valid(&schib)) {
Peter Oberparleiter564337f2006-09-20 16:00:01 +0200404 /* Unusable - ignore. */
405 return 0;
406 }
407 CIO_MSG_EVENT(4, "Evaluating schid 0.%x.%04x, event %d, unknown, "
408 "slow path.\n", schid.ssid, schid.sch_no, CIO_OPER);
409
410 return css_probe_device(schid);
411}
412
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200413static void css_evaluate_subchannel(struct subchannel_id schid, int slow)
Peter Oberparleiter564337f2006-09-20 16:00:01 +0200414{
415 struct subchannel *sch;
416 int ret;
417
418 sch = get_subchannel_by_schid(schid);
419 if (sch) {
420 ret = css_evaluate_known_subchannel(sch, slow);
421 put_device(&sch->dev);
422 } else
423 ret = css_evaluate_new_subchannel(schid, slow);
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200424 if (ret == -EAGAIN)
425 css_schedule_eval(schid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426}
427
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200428static struct idset *slow_subchannel_set;
429static spinlock_t slow_subchannel_lock;
430
431static int __init slow_subchannel_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432{
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200433 spin_lock_init(&slow_subchannel_lock);
434 slow_subchannel_set = idset_sch_new();
435 if (!slow_subchannel_set) {
Cornelia Hucke556bbb2007-07-27 12:29:19 +0200436 CIO_MSG_EVENT(0, "could not allocate slow subchannel set\n");
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200437 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 }
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200439 return 0;
440}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441
Peter Oberparleitere82a1562008-01-26 14:10:48 +0100442static int slow_eval_known_fn(struct subchannel *sch, void *data)
443{
444 int eval;
445 int rc;
446
447 spin_lock_irq(&slow_subchannel_lock);
448 eval = idset_sch_contains(slow_subchannel_set, sch->schid);
449 idset_sch_del(slow_subchannel_set, sch->schid);
450 spin_unlock_irq(&slow_subchannel_lock);
451 if (eval) {
452 rc = css_evaluate_known_subchannel(sch, 1);
453 if (rc == -EAGAIN)
454 css_schedule_eval(sch->schid);
455 }
456 return 0;
457}
458
459static int slow_eval_unknown_fn(struct subchannel_id schid, void *data)
460{
461 int eval;
462 int rc = 0;
463
464 spin_lock_irq(&slow_subchannel_lock);
465 eval = idset_sch_contains(slow_subchannel_set, schid);
466 idset_sch_del(slow_subchannel_set, schid);
467 spin_unlock_irq(&slow_subchannel_lock);
468 if (eval) {
469 rc = css_evaluate_new_subchannel(schid, 1);
470 switch (rc) {
471 case -EAGAIN:
472 css_schedule_eval(schid);
473 rc = 0;
474 break;
475 case -ENXIO:
476 case -ENOMEM:
477 case -EIO:
478 /* These should abort looping */
479 break;
480 default:
481 rc = 0;
482 }
483 }
484 return rc;
485}
486
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200487static void css_slow_path_func(struct work_struct *unused)
488{
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200489 CIO_TRACE_EVENT(4, "slowpath");
Peter Oberparleitere82a1562008-01-26 14:10:48 +0100490 for_each_subchannel_staged(slow_eval_known_fn, slow_eval_unknown_fn,
491 NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492}
493
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200494static DECLARE_WORK(slow_path_work, css_slow_path_func);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495struct workqueue_struct *slow_path_wq;
496
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200497void css_schedule_eval(struct subchannel_id schid)
498{
499 unsigned long flags;
500
501 spin_lock_irqsave(&slow_subchannel_lock, flags);
502 idset_sch_add(slow_subchannel_set, schid);
503 queue_work(slow_path_wq, &slow_path_work);
504 spin_unlock_irqrestore(&slow_subchannel_lock, flags);
505}
506
507void css_schedule_eval_all(void)
508{
509 unsigned long flags;
510
511 spin_lock_irqsave(&slow_subchannel_lock, flags);
512 idset_fill(slow_subchannel_set);
513 queue_work(slow_path_wq, &slow_path_work);
514 spin_unlock_irqrestore(&slow_subchannel_lock, flags);
515}
516
Cornelia Huck22806dc2008-04-17 07:45:59 +0200517void css_wait_for_slow_path(void)
518{
519 flush_workqueue(ccw_device_notify_work);
520 flush_workqueue(slow_path_wq);
521}
522
Peter Oberparleiter40154b82006-06-29 14:57:03 +0200523/* Reprobe subchannel if unregistered. */
524static int reprobe_subchannel(struct subchannel_id schid, void *data)
525{
Peter Oberparleiter40154b82006-06-29 14:57:03 +0200526 int ret;
527
Cornelia Hucke556bbb2007-07-27 12:29:19 +0200528 CIO_MSG_EVENT(6, "cio: reprobe 0.%x.%04x\n",
529 schid.ssid, schid.sch_no);
Peter Oberparleiter40154b82006-06-29 14:57:03 +0200530 if (need_reprobe)
531 return -EAGAIN;
532
Peter Oberparleiter40154b82006-06-29 14:57:03 +0200533 ret = css_probe_device(schid);
534 switch (ret) {
535 case 0:
536 break;
537 case -ENXIO:
538 case -ENOMEM:
Peter Oberparleiter671756162007-12-04 16:09:02 +0100539 case -EIO:
Peter Oberparleiter40154b82006-06-29 14:57:03 +0200540 /* These should abort looping */
541 break;
542 default:
543 ret = 0;
544 }
545
546 return ret;
547}
548
549/* Work function used to reprobe all unregistered subchannels. */
Al Viro4927b3f2006-12-06 19:18:20 +0000550static void reprobe_all(struct work_struct *unused)
Peter Oberparleiter40154b82006-06-29 14:57:03 +0200551{
552 int ret;
553
Michael Ernst139b83d2008-05-07 09:22:54 +0200554 CIO_MSG_EVENT(4, "reprobe start\n");
Peter Oberparleiter40154b82006-06-29 14:57:03 +0200555
556 need_reprobe = 0;
557 /* Make sure initial subchannel scan is done. */
558 wait_event(ccw_device_init_wq,
559 atomic_read(&ccw_device_init_count) == 0);
Peter Oberparleitere82a1562008-01-26 14:10:48 +0100560 ret = for_each_subchannel_staged(NULL, reprobe_subchannel, NULL);
Peter Oberparleiter40154b82006-06-29 14:57:03 +0200561
Michael Ernst139b83d2008-05-07 09:22:54 +0200562 CIO_MSG_EVENT(4, "reprobe done (rc=%d, need_reprobe=%d)\n", ret,
Peter Oberparleiter40154b82006-06-29 14:57:03 +0200563 need_reprobe);
564}
565
Heiko Carstens2b67fc42007-02-05 21:16:47 +0100566static DECLARE_WORK(css_reprobe_work, reprobe_all);
Peter Oberparleiter40154b82006-06-29 14:57:03 +0200567
568/* Schedule reprobing of all unregistered subchannels. */
569void css_schedule_reprobe(void)
570{
571 need_reprobe = 1;
Cornelia Huckc5d4a992007-11-20 11:13:41 +0100572 queue_work(slow_path_wq, &css_reprobe_work);
Peter Oberparleiter40154b82006-06-29 14:57:03 +0200573}
574
575EXPORT_SYMBOL_GPL(css_schedule_reprobe);
576
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 * Called from the machine check handler for subchannel report words.
579 */
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200580void css_process_crw(int rsid1, int rsid2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581{
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800582 struct subchannel_id mchk_schid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800584 CIO_CRW_EVENT(2, "source is subchannel %04X, subsystem id %x\n",
585 rsid1, rsid2);
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800586 init_subchannel_id(&mchk_schid);
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800587 mchk_schid.sch_no = rsid1;
588 if (rsid2 != 0)
589 mchk_schid.ssid = (rsid2 >> 8) & 3;
590
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 /*
592 * Since we are always presented with IPI in the CRW, we have to
593 * use stsch() to find out if the subchannel in question has come
594 * or gone.
595 */
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200596 css_evaluate_subchannel(mchk_schid, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597}
598
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800599static int __init
600__init_channel_subsystem(struct subchannel_id schid, void *data)
601{
602 struct subchannel *sch;
603 int ret;
604
605 if (cio_is_console(schid))
606 sch = cio_get_console_subchannel();
607 else {
608 sch = css_alloc_subchannel(schid);
609 if (IS_ERR(sch))
610 ret = PTR_ERR(sch);
611 else
612 ret = 0;
613 switch (ret) {
614 case 0:
615 break;
616 case -ENOMEM:
617 panic("Out of memory in init_channel_subsystem\n");
618 /* -ENXIO: no more subchannels. */
619 case -ENXIO:
620 return ret;
Greg Smithe843e282006-03-14 19:50:17 -0800621 /* -EIO: this subchannel set not supported. */
622 case -EIO:
623 return ret;
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800624 default:
625 return 0;
626 }
627 }
628 /*
629 * We register ALL valid subchannels in ioinfo, even those
630 * that have been present before init_channel_subsystem.
631 * These subchannels can't have been registered yet (kmalloc
632 * not working) so we do it now. This is true e.g. for the
633 * console subchannel.
634 */
635 css_register_subchannel(sch);
636 return 0;
637}
638
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639static void __init
Cornelia Hucka28c6942006-01-06 00:19:23 -0800640css_generate_pgid(struct channel_subsystem *css, u32 tod_high)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641{
Cornelia Hucka28c6942006-01-06 00:19:23 -0800642 if (css_characteristics_avail && css_general_characteristics.mcss) {
643 css->global_pgid.pgid_high.ext_cssid.version = 0x80;
644 css->global_pgid.pgid_high.ext_cssid.cssid = css->cssid;
645 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646#ifdef CONFIG_SMP
Cornelia Hucka28c6942006-01-06 00:19:23 -0800647 css->global_pgid.pgid_high.cpu_addr = hard_smp_processor_id();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648#else
Cornelia Hucka28c6942006-01-06 00:19:23 -0800649 css->global_pgid.pgid_high.cpu_addr = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650#endif
651 }
Cornelia Hucka28c6942006-01-06 00:19:23 -0800652 css->global_pgid.cpu_id = ((cpuid_t *) __LC_CPUID)->ident;
653 css->global_pgid.cpu_model = ((cpuid_t *) __LC_CPUID)->machine;
654 css->global_pgid.tod_high = tod_high;
655
656}
657
Cornelia Huck3b793062006-01-06 00:19:26 -0800658static void
659channel_subsystem_release(struct device *dev)
660{
661 struct channel_subsystem *css;
662
663 css = to_css(dev);
Cornelia Huck495a5b42006-03-24 03:15:14 -0800664 mutex_destroy(&css->mutex);
Cornelia Huck3b793062006-01-06 00:19:26 -0800665 kfree(css);
666}
667
Cornelia Huck495a5b42006-03-24 03:15:14 -0800668static ssize_t
669css_cm_enable_show(struct device *dev, struct device_attribute *attr,
670 char *buf)
671{
672 struct channel_subsystem *css = to_css(dev);
Michael Ernst8284fb192008-04-17 07:46:01 +0200673 int ret;
Cornelia Huck495a5b42006-03-24 03:15:14 -0800674
675 if (!css)
676 return 0;
Michael Ernst8284fb192008-04-17 07:46:01 +0200677 mutex_lock(&css->mutex);
678 ret = sprintf(buf, "%x\n", css->cm_enabled);
679 mutex_unlock(&css->mutex);
680 return ret;
Cornelia Huck495a5b42006-03-24 03:15:14 -0800681}
682
683static ssize_t
684css_cm_enable_store(struct device *dev, struct device_attribute *attr,
685 const char *buf, size_t count)
686{
687 struct channel_subsystem *css = to_css(dev);
688 int ret;
Cornelia Huck2f972202008-04-30 13:38:33 +0200689 unsigned long val;
Cornelia Huck495a5b42006-03-24 03:15:14 -0800690
Cornelia Huck2f972202008-04-30 13:38:33 +0200691 ret = strict_strtoul(buf, 16, &val);
692 if (ret)
693 return ret;
Michael Ernst8284fb192008-04-17 07:46:01 +0200694 mutex_lock(&css->mutex);
Cornelia Huck2f972202008-04-30 13:38:33 +0200695 switch (val) {
696 case 0:
Cornelia Huck495a5b42006-03-24 03:15:14 -0800697 ret = css->cm_enabled ? chsc_secm(css, 0) : 0;
698 break;
Cornelia Huck2f972202008-04-30 13:38:33 +0200699 case 1:
Cornelia Huck495a5b42006-03-24 03:15:14 -0800700 ret = css->cm_enabled ? 0 : chsc_secm(css, 1);
701 break;
702 default:
703 ret = -EINVAL;
704 }
Michael Ernst8284fb192008-04-17 07:46:01 +0200705 mutex_unlock(&css->mutex);
Cornelia Huck495a5b42006-03-24 03:15:14 -0800706 return ret < 0 ? ret : count;
707}
708
709static DEVICE_ATTR(cm_enable, 0644, css_cm_enable_show, css_cm_enable_store);
710
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100711static int __init setup_css(int nr)
Cornelia Hucka28c6942006-01-06 00:19:23 -0800712{
713 u32 tod_high;
Cornelia Huckd7b5a4c92006-12-08 15:54:28 +0100714 int ret;
Cornelia Huck7c9f4e32007-10-12 16:11:13 +0200715 struct channel_subsystem *css;
Cornelia Hucka28c6942006-01-06 00:19:23 -0800716
Cornelia Huck7c9f4e32007-10-12 16:11:13 +0200717 css = channel_subsystems[nr];
718 memset(css, 0, sizeof(struct channel_subsystem));
719 css->pseudo_subchannel =
720 kzalloc(sizeof(*css->pseudo_subchannel), GFP_KERNEL);
721 if (!css->pseudo_subchannel)
Cornelia Huckd7b5a4c92006-12-08 15:54:28 +0100722 return -ENOMEM;
Cornelia Huck7c9f4e32007-10-12 16:11:13 +0200723 css->pseudo_subchannel->dev.parent = &css->device;
724 css->pseudo_subchannel->dev.release = css_subchannel_release;
725 sprintf(css->pseudo_subchannel->dev.bus_id, "defunct");
726 ret = cio_create_sch_lock(css->pseudo_subchannel);
Cornelia Huckd7b5a4c92006-12-08 15:54:28 +0100727 if (ret) {
Cornelia Huck7c9f4e32007-10-12 16:11:13 +0200728 kfree(css->pseudo_subchannel);
Cornelia Huckd7b5a4c92006-12-08 15:54:28 +0100729 return ret;
730 }
Cornelia Huck7c9f4e32007-10-12 16:11:13 +0200731 mutex_init(&css->mutex);
732 css->valid = 1;
733 css->cssid = nr;
734 sprintf(css->device.bus_id, "css%x", nr);
735 css->device.release = channel_subsystem_release;
Cornelia Hucka28c6942006-01-06 00:19:23 -0800736 tod_high = (u32) (get_clock() >> 32);
Cornelia Huck7c9f4e32007-10-12 16:11:13 +0200737 css_generate_pgid(css, tod_high);
Cornelia Huckd7b5a4c92006-12-08 15:54:28 +0100738 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739}
740
Cornelia Hucka55360d2007-10-12 16:11:20 +0200741static int css_reboot_event(struct notifier_block *this,
742 unsigned long event,
743 void *ptr)
744{
745 int ret, i;
746
747 ret = NOTIFY_DONE;
748 for (i = 0; i <= __MAX_CSSID; i++) {
749 struct channel_subsystem *css;
750
751 css = channel_subsystems[i];
Michael Ernst8284fb192008-04-17 07:46:01 +0200752 mutex_lock(&css->mutex);
Cornelia Hucka55360d2007-10-12 16:11:20 +0200753 if (css->cm_enabled)
754 if (chsc_secm(css, 0))
755 ret = NOTIFY_BAD;
Michael Ernst8284fb192008-04-17 07:46:01 +0200756 mutex_unlock(&css->mutex);
Cornelia Hucka55360d2007-10-12 16:11:20 +0200757 }
758
759 return ret;
760}
761
762static struct notifier_block css_reboot_notifier = {
763 .notifier_call = css_reboot_event,
764};
765
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766/*
767 * Now that the driver core is running, we can setup our channel subsystem.
768 * The struct subchannel's are created during probing (except for the
769 * static console subchannel).
770 */
771static int __init
772init_channel_subsystem (void)
773{
Cornelia Hucka28c6942006-01-06 00:19:23 -0800774 int ret, i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775
Cornelia Huck4434a382007-07-27 12:29:21 +0200776 ret = chsc_determine_css_characteristics();
777 if (ret == -ENOMEM)
778 goto out; /* No need to continue. */
779 if (ret == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780 css_characteristics_avail = 1;
781
Cornelia Huck4434a382007-07-27 12:29:21 +0200782 ret = chsc_alloc_sei_area();
783 if (ret)
784 goto out;
785
786 ret = slow_subchannel_init();
787 if (ret)
788 goto out;
789
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790 if ((ret = bus_register(&css_bus_type)))
791 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800793 /* Try to enable MSS. */
794 ret = chsc_enable_facility(CHSC_SDA_OC_MSS);
795 switch (ret) {
796 case 0: /* Success. */
797 max_ssid = __MAX_SSID;
798 break;
799 case -ENOMEM:
800 goto out_bus;
801 default:
802 max_ssid = 0;
803 }
Cornelia Hucka28c6942006-01-06 00:19:23 -0800804 /* Setup css structure. */
805 for (i = 0; i <= __MAX_CSSID; i++) {
Cornelia Huck7c9f4e32007-10-12 16:11:13 +0200806 struct channel_subsystem *css;
807
808 css = kmalloc(sizeof(struct channel_subsystem), GFP_KERNEL);
809 if (!css) {
Cornelia Hucka28c6942006-01-06 00:19:23 -0800810 ret = -ENOMEM;
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800811 goto out_unregister;
Cornelia Hucka28c6942006-01-06 00:19:23 -0800812 }
Cornelia Huck7c9f4e32007-10-12 16:11:13 +0200813 channel_subsystems[i] = css;
Cornelia Huckd7b5a4c92006-12-08 15:54:28 +0100814 ret = setup_css(i);
Cornelia Hucka28c6942006-01-06 00:19:23 -0800815 if (ret)
816 goto out_free;
Cornelia Huck7c9f4e32007-10-12 16:11:13 +0200817 ret = device_register(&css->device);
Cornelia Huckd7b5a4c92006-12-08 15:54:28 +0100818 if (ret)
819 goto out_free_all;
Cornelia Huck7e560812006-07-12 16:40:19 +0200820 if (css_characteristics_avail &&
821 css_chsc_characteristics.secm) {
Cornelia Huck7c9f4e32007-10-12 16:11:13 +0200822 ret = device_create_file(&css->device,
Cornelia Huck7e560812006-07-12 16:40:19 +0200823 &dev_attr_cm_enable);
824 if (ret)
825 goto out_device;
826 }
Cornelia Huck7c9f4e32007-10-12 16:11:13 +0200827 ret = device_register(&css->pseudo_subchannel->dev);
Cornelia Huckd7b5a4c92006-12-08 15:54:28 +0100828 if (ret)
829 goto out_file;
Cornelia Hucka28c6942006-01-06 00:19:23 -0800830 }
Cornelia Hucka55360d2007-10-12 16:11:20 +0200831 ret = register_reboot_notifier(&css_reboot_notifier);
832 if (ret)
833 goto out_pseudo;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834 css_init_done = 1;
835
836 ctl_set_bit(6, 28);
837
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800838 for_each_subchannel(__init_channel_subsystem, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839 return 0;
Cornelia Hucka55360d2007-10-12 16:11:20 +0200840out_pseudo:
841 device_unregister(&channel_subsystems[i]->pseudo_subchannel->dev);
Cornelia Huckd7b5a4c92006-12-08 15:54:28 +0100842out_file:
Cornelia Huck7c9f4e32007-10-12 16:11:13 +0200843 device_remove_file(&channel_subsystems[i]->device,
844 &dev_attr_cm_enable);
Cornelia Huck7e560812006-07-12 16:40:19 +0200845out_device:
Cornelia Huck7c9f4e32007-10-12 16:11:13 +0200846 device_unregister(&channel_subsystems[i]->device);
Cornelia Huckd7b5a4c92006-12-08 15:54:28 +0100847out_free_all:
Cornelia Huck7c9f4e32007-10-12 16:11:13 +0200848 kfree(channel_subsystems[i]->pseudo_subchannel->lock);
849 kfree(channel_subsystems[i]->pseudo_subchannel);
Cornelia Hucka28c6942006-01-06 00:19:23 -0800850out_free:
Cornelia Huck7c9f4e32007-10-12 16:11:13 +0200851 kfree(channel_subsystems[i]);
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800852out_unregister:
Cornelia Hucka28c6942006-01-06 00:19:23 -0800853 while (i > 0) {
Cornelia Huck7c9f4e32007-10-12 16:11:13 +0200854 struct channel_subsystem *css;
855
Cornelia Hucka28c6942006-01-06 00:19:23 -0800856 i--;
Cornelia Huck7c9f4e32007-10-12 16:11:13 +0200857 css = channel_subsystems[i];
858 device_unregister(&css->pseudo_subchannel->dev);
Cornelia Huck495a5b42006-03-24 03:15:14 -0800859 if (css_characteristics_avail && css_chsc_characteristics.secm)
Cornelia Huck7c9f4e32007-10-12 16:11:13 +0200860 device_remove_file(&css->device,
Cornelia Huck495a5b42006-03-24 03:15:14 -0800861 &dev_attr_cm_enable);
Cornelia Huck7c9f4e32007-10-12 16:11:13 +0200862 device_unregister(&css->device);
Cornelia Hucka28c6942006-01-06 00:19:23 -0800863 }
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800864out_bus:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865 bus_unregister(&css_bus_type);
866out:
Cornelia Huck4434a382007-07-27 12:29:21 +0200867 chsc_free_sei_area();
868 kfree(slow_subchannel_set);
869 printk(KERN_WARNING"cio: failed to initialize css driver (%d)!\n",
870 ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871 return ret;
872}
873
Cornelia Huckd7b5a4c92006-12-08 15:54:28 +0100874int sch_is_pseudo_sch(struct subchannel *sch)
875{
876 return sch == to_css(sch->dev.parent)->pseudo_subchannel;
877}
878
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879/*
880 * find a driver for a subchannel. They identify by the subchannel
881 * type with the exception that the console subchannel driver has its own
882 * subchannel type although the device is an i/o subchannel
883 */
884static int
885css_bus_match (struct device *dev, struct device_driver *drv)
886{
Cornelia Huck084325d2008-01-26 14:10:38 +0100887 struct subchannel *sch = to_subchannel(dev);
888 struct css_driver *driver = to_cssdriver(drv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889
890 if (sch->st == driver->subchannel_type)
891 return 1;
892
893 return 0;
894}
895
Cornelia Huck98c13c22008-01-26 14:10:40 +0100896static int css_probe(struct device *dev)
Cornelia Huck8bbace72006-01-11 10:56:22 +0100897{
898 struct subchannel *sch;
Cornelia Huck98c13c22008-01-26 14:10:40 +0100899 int ret;
Cornelia Huck8bbace72006-01-11 10:56:22 +0100900
901 sch = to_subchannel(dev);
Cornelia Huck084325d2008-01-26 14:10:38 +0100902 sch->driver = to_cssdriver(dev->driver);
Cornelia Huck98c13c22008-01-26 14:10:40 +0100903 ret = sch->driver->probe ? sch->driver->probe(sch) : 0;
904 if (ret)
905 sch->driver = NULL;
906 return ret;
Cornelia Huck8bbace72006-01-11 10:56:22 +0100907}
908
Cornelia Huck98c13c22008-01-26 14:10:40 +0100909static int css_remove(struct device *dev)
910{
911 struct subchannel *sch;
912 int ret;
913
914 sch = to_subchannel(dev);
915 ret = sch->driver->remove ? sch->driver->remove(sch) : 0;
916 sch->driver = NULL;
917 return ret;
918}
919
920static void css_shutdown(struct device *dev)
Cornelia Huck8bbace72006-01-11 10:56:22 +0100921{
922 struct subchannel *sch;
923
924 sch = to_subchannel(dev);
Cornelia Huck98c13c22008-01-26 14:10:40 +0100925 if (sch->driver && sch->driver->shutdown)
Cornelia Huck8bbace72006-01-11 10:56:22 +0100926 sch->driver->shutdown(sch);
927}
928
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929struct bus_type css_bus_type = {
Cornelia Huck8bbace72006-01-11 10:56:22 +0100930 .name = "css",
931 .match = css_bus_match,
932 .probe = css_probe,
933 .remove = css_remove,
934 .shutdown = css_shutdown,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935};
936
Cornelia Huck25b7bb52008-01-26 14:10:41 +0100937/**
938 * css_driver_register - register a css driver
939 * @cdrv: css driver to register
940 *
941 * This is mainly a wrapper around driver_register that sets name
942 * and bus_type in the embedded struct device_driver correctly.
943 */
944int css_driver_register(struct css_driver *cdrv)
945{
946 cdrv->drv.name = cdrv->name;
947 cdrv->drv.bus = &css_bus_type;
Cornelia Huck4beee642008-01-26 14:10:47 +0100948 cdrv->drv.owner = cdrv->owner;
Cornelia Huck25b7bb52008-01-26 14:10:41 +0100949 return driver_register(&cdrv->drv);
950}
951EXPORT_SYMBOL_GPL(css_driver_register);
952
953/**
954 * css_driver_unregister - unregister a css driver
955 * @cdrv: css driver to unregister
956 *
957 * This is a wrapper around driver_unregister.
958 */
959void css_driver_unregister(struct css_driver *cdrv)
960{
961 driver_unregister(&cdrv->drv);
962}
963EXPORT_SYMBOL_GPL(css_driver_unregister);
964
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965subsys_initcall(init_channel_subsystem);
966
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967MODULE_LICENSE("GPL");
968EXPORT_SYMBOL(css_bus_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969EXPORT_SYMBOL_GPL(css_characteristics_avail);