blob: a09deea5d687f26ec4ce464e2cc608540ad6606f [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>
16
17#include "css.h"
18#include "cio.h"
19#include "cio_debug.h"
20#include "ioasm.h"
21#include "chsc.h"
Peter Oberparleiter40154b82006-06-29 14:57:03 +020022#include "device.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070023
Linus Torvalds1da177e2005-04-16 15:20:36 -070024int need_rescan = 0;
25int css_init_done = 0;
Peter Oberparleiter40154b82006-06-29 14:57:03 +020026static int need_reprobe = 0;
Cornelia Huckfb6958a2006-01-06 00:19:25 -080027static int max_ssid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
Cornelia Hucka28c6942006-01-06 00:19:23 -080029struct channel_subsystem *css[__MAX_CSSID + 1];
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
Cornelia Hucka28c6942006-01-06 00:19:23 -080031int css_characteristics_avail = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
Cornelia Huckf97a56f2006-01-06 00:19:22 -080033inline int
34for_each_subchannel(int(*fn)(struct subchannel_id, void *), void *data)
35{
36 struct subchannel_id schid;
37 int ret;
38
39 init_subchannel_id(&schid);
40 ret = -ENODEV;
41 do {
Cornelia Huckfb6958a2006-01-06 00:19:25 -080042 do {
43 ret = fn(schid, data);
44 if (ret)
45 break;
46 } while (schid.sch_no++ < __MAX_SUBCHANNEL);
47 schid.sch_no = 0;
48 } while (schid.ssid++ < max_ssid);
Cornelia Huckf97a56f2006-01-06 00:19:22 -080049 return ret;
50}
51
Linus Torvalds1da177e2005-04-16 15:20:36 -070052static struct subchannel *
Cornelia Hucka8237fc2006-01-06 00:19:21 -080053css_alloc_subchannel(struct subchannel_id schid)
Linus Torvalds1da177e2005-04-16 15:20:36 -070054{
55 struct subchannel *sch;
56 int ret;
57
58 sch = kmalloc (sizeof (*sch), GFP_KERNEL | GFP_DMA);
59 if (sch == NULL)
60 return ERR_PTR(-ENOMEM);
Cornelia Hucka8237fc2006-01-06 00:19:21 -080061 ret = cio_validate_subchannel (sch, schid);
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 if (ret < 0) {
63 kfree(sch);
64 return ERR_PTR(ret);
65 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
67 if (sch->st != SUBCHANNEL_TYPE_IO) {
68 /* For now we ignore all non-io subchannels. */
69 kfree(sch);
70 return ERR_PTR(-EINVAL);
71 }
72
73 /*
74 * Set intparm to subchannel address.
75 * This is fine even on 64bit since the subchannel is always located
76 * under 2G.
77 */
78 sch->schib.pmcw.intparm = (__u32)(unsigned long)sch;
79 ret = cio_modify(sch);
80 if (ret) {
81 kfree(sch);
82 return ERR_PTR(ret);
83 }
84 return sch;
85}
86
87static void
88css_free_subchannel(struct subchannel *sch)
89{
90 if (sch) {
91 /* Reset intparm to zeroes. */
92 sch->schib.pmcw.intparm = 0;
93 cio_modify(sch);
94 kfree(sch);
95 }
96
97}
98
99static void
100css_subchannel_release(struct device *dev)
101{
102 struct subchannel *sch;
103
104 sch = to_subchannel(dev);
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800105 if (!cio_is_console(sch->schid))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 kfree(sch);
107}
108
109extern int css_get_ssd_info(struct subchannel *sch);
110
Cornelia Huck6ab48792006-07-12 16:39:50 +0200111
112int css_sch_device_register(struct subchannel *sch)
113{
114 int ret;
115
116 mutex_lock(&sch->reg_mutex);
117 ret = device_register(&sch->dev);
118 mutex_unlock(&sch->reg_mutex);
119 return ret;
120}
121
122void css_sch_device_unregister(struct subchannel *sch)
123{
124 mutex_lock(&sch->reg_mutex);
125 device_unregister(&sch->dev);
126 mutex_unlock(&sch->reg_mutex);
127}
128
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129static int
130css_register_subchannel(struct subchannel *sch)
131{
132 int ret;
133
134 /* Initialize the subchannel structure */
Cornelia Hucka28c6942006-01-06 00:19:23 -0800135 sch->dev.parent = &css[0]->device;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 sch->dev.bus = &css_bus_type;
137 sch->dev.release = &css_subchannel_release;
138
139 /* make it known to the system */
Cornelia Huck6ab48792006-07-12 16:39:50 +0200140 ret = css_sch_device_register(sch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 if (ret)
142 printk (KERN_WARNING "%s: could not register %s\n",
143 __func__, sch->dev.bus_id);
144 else
145 css_get_ssd_info(sch);
146 return ret;
147}
148
149int
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800150css_probe_device(struct subchannel_id schid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151{
152 int ret;
153 struct subchannel *sch;
154
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800155 sch = css_alloc_subchannel(schid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 if (IS_ERR(sch))
157 return PTR_ERR(sch);
158 ret = css_register_subchannel(sch);
159 if (ret)
160 css_free_subchannel(sch);
161 return ret;
162}
163
Cornelia Huckb0744bd2005-06-25 14:55:27 -0700164static int
165check_subchannel(struct device * dev, void * data)
166{
167 struct subchannel *sch;
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800168 struct subchannel_id *schid = data;
Cornelia Huckb0744bd2005-06-25 14:55:27 -0700169
170 sch = to_subchannel(dev);
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800171 return schid_equal(&sch->schid, schid);
Cornelia Huckb0744bd2005-06-25 14:55:27 -0700172}
173
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174struct subchannel *
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800175get_subchannel_by_schid(struct subchannel_id schid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 struct device *dev;
178
Cornelia Huckb0744bd2005-06-25 14:55:27 -0700179 dev = bus_find_device(&css_bus_type, NULL,
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800180 (void *)&schid, check_subchannel);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181
Cornelia Huckb0744bd2005-06-25 14:55:27 -0700182 return dev ? to_subchannel(dev) : NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183}
184
Cornelia Huckb0744bd2005-06-25 14:55:27 -0700185
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186static inline int
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800187css_get_subchannel_status(struct subchannel *sch, struct subchannel_id schid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188{
189 struct schib schib;
190 int cc;
191
192 cc = stsch(schid, &schib);
193 if (cc)
194 return CIO_GONE;
195 if (!schib.pmcw.dnv)
196 return CIO_GONE;
197 if (sch && sch->schib.pmcw.dnv &&
198 (schib.pmcw.dev != sch->schib.pmcw.dev))
199 return CIO_REVALIDATE;
200 if (sch && !sch->lpm)
201 return CIO_NO_PATH;
202 return CIO_OPER;
203}
204
205static int
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800206css_evaluate_subchannel(struct subchannel_id schid, int slow)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207{
208 int event, ret, disc;
209 struct subchannel *sch;
210 unsigned long flags;
211
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800212 sch = get_subchannel_by_schid(schid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 disc = sch ? device_is_disconnected(sch) : 0;
214 if (disc && slow) {
215 if (sch)
216 put_device(&sch->dev);
217 return 0; /* Already processed. */
218 }
219 /*
220 * We've got a machine check, so running I/O won't get an interrupt.
221 * Kill any pending timers.
222 */
223 if (sch)
224 device_kill_pending_timer(sch);
225 if (!disc && !slow) {
226 if (sch)
227 put_device(&sch->dev);
228 return -EAGAIN; /* Will be done on the slow path. */
229 }
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800230 event = css_get_subchannel_status(sch, schid);
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800231 CIO_MSG_EVENT(4, "Evaluating schid 0.%x.%04x, event %d, %s, %s path.\n",
232 schid.ssid, schid.sch_no, event,
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800233 sch?(disc?"disconnected":"normal"):"unknown",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 slow?"slow":"fast");
235 switch (event) {
236 case CIO_NO_PATH:
237 case CIO_GONE:
238 if (!sch) {
239 /* Never used this subchannel. Ignore. */
240 ret = 0;
241 break;
242 }
243 if (disc && (event == CIO_NO_PATH)) {
244 /*
245 * Uargh, hack again. Because we don't get a machine
246 * check on configure on, our path bookkeeping can
247 * be out of date here (it's fine while we only do
248 * logical varying or get chsc machine checks). We
249 * need to force reprobing or we might miss devices
250 * coming operational again. It won't do harm in real
251 * no path situations.
252 */
253 spin_lock_irqsave(&sch->lock, flags);
254 device_trigger_reprobe(sch);
255 spin_unlock_irqrestore(&sch->lock, flags);
256 ret = 0;
257 break;
258 }
259 if (sch->driver && sch->driver->notify &&
260 sch->driver->notify(&sch->dev, event)) {
261 cio_disable_subchannel(sch);
262 device_set_disconnected(sch);
263 ret = 0;
264 break;
265 }
266 /*
267 * Unregister subchannel.
268 * The device will be killed automatically.
269 */
270 cio_disable_subchannel(sch);
Cornelia Huck6ab48792006-07-12 16:39:50 +0200271 css_sch_device_unregister(sch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 /* Reset intparm to zeroes. */
273 sch->schib.pmcw.intparm = 0;
274 cio_modify(sch);
275 put_device(&sch->dev);
276 ret = 0;
277 break;
278 case CIO_REVALIDATE:
279 /*
280 * Revalidation machine check. Sick.
281 * We don't notify the driver since we have to throw the device
282 * away in any case.
283 */
284 if (!disc) {
Cornelia Huck6ab48792006-07-12 16:39:50 +0200285 css_sch_device_unregister(sch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 /* Reset intparm to zeroes. */
287 sch->schib.pmcw.intparm = 0;
288 cio_modify(sch);
289 put_device(&sch->dev);
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800290 ret = css_probe_device(schid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 } else {
292 /*
293 * We can't immediately deregister the disconnected
294 * device since it might block.
295 */
296 spin_lock_irqsave(&sch->lock, flags);
297 device_trigger_reprobe(sch);
298 spin_unlock_irqrestore(&sch->lock, flags);
299 ret = 0;
300 }
301 break;
302 case CIO_OPER:
303 if (disc) {
304 spin_lock_irqsave(&sch->lock, flags);
305 /* Get device operational again. */
306 device_trigger_reprobe(sch);
307 spin_unlock_irqrestore(&sch->lock, flags);
308 }
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800309 ret = sch ? 0 : css_probe_device(schid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 break;
311 default:
312 BUG();
313 ret = 0;
314 }
315 return ret;
316}
317
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800318static int
319css_rescan_devices(struct subchannel_id schid, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320{
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800321 return css_evaluate_subchannel(schid, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322}
323
324struct slow_subchannel {
325 struct list_head slow_list;
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800326 struct subchannel_id schid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327};
328
329static LIST_HEAD(slow_subchannels_head);
330static DEFINE_SPINLOCK(slow_subchannel_lock);
331
332static void
333css_trigger_slow_path(void)
334{
335 CIO_TRACE_EVENT(4, "slowpath");
336
337 if (need_rescan) {
338 need_rescan = 0;
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800339 for_each_subchannel(css_rescan_devices, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 return;
341 }
342
343 spin_lock_irq(&slow_subchannel_lock);
344 while (!list_empty(&slow_subchannels_head)) {
345 struct slow_subchannel *slow_sch =
346 list_entry(slow_subchannels_head.next,
347 struct slow_subchannel, slow_list);
348
349 list_del_init(slow_subchannels_head.next);
350 spin_unlock_irq(&slow_subchannel_lock);
351 css_evaluate_subchannel(slow_sch->schid, 1);
352 spin_lock_irq(&slow_subchannel_lock);
353 kfree(slow_sch);
354 }
355 spin_unlock_irq(&slow_subchannel_lock);
356}
357
358typedef void (*workfunc)(void *);
359DECLARE_WORK(slow_path_work, (workfunc)css_trigger_slow_path, NULL);
360struct workqueue_struct *slow_path_wq;
361
Peter Oberparleiter40154b82006-06-29 14:57:03 +0200362/* Reprobe subchannel if unregistered. */
363static int reprobe_subchannel(struct subchannel_id schid, void *data)
364{
365 struct subchannel *sch;
366 int ret;
367
368 CIO_DEBUG(KERN_INFO, 6, "cio: reprobe 0.%x.%04x\n",
369 schid.ssid, schid.sch_no);
370 if (need_reprobe)
371 return -EAGAIN;
372
373 sch = get_subchannel_by_schid(schid);
374 if (sch) {
375 /* Already known. */
376 put_device(&sch->dev);
377 return 0;
378 }
379
380 ret = css_probe_device(schid);
381 switch (ret) {
382 case 0:
383 break;
384 case -ENXIO:
385 case -ENOMEM:
386 /* These should abort looping */
387 break;
388 default:
389 ret = 0;
390 }
391
392 return ret;
393}
394
395/* Work function used to reprobe all unregistered subchannels. */
396static void reprobe_all(void *data)
397{
398 int ret;
399
400 CIO_MSG_EVENT(2, "reprobe start\n");
401
402 need_reprobe = 0;
403 /* Make sure initial subchannel scan is done. */
404 wait_event(ccw_device_init_wq,
405 atomic_read(&ccw_device_init_count) == 0);
406 ret = for_each_subchannel(reprobe_subchannel, NULL);
407
408 CIO_MSG_EVENT(2, "reprobe done (rc=%d, need_reprobe=%d)\n", ret,
409 need_reprobe);
410}
411
412DECLARE_WORK(css_reprobe_work, reprobe_all, NULL);
413
414/* Schedule reprobing of all unregistered subchannels. */
415void css_schedule_reprobe(void)
416{
417 need_reprobe = 1;
418 queue_work(ccw_device_work, &css_reprobe_work);
419}
420
421EXPORT_SYMBOL_GPL(css_schedule_reprobe);
422
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423/*
424 * Rescan for new devices. FIXME: This is slow.
425 * This function is called when we have lost CRWs due to overflows and we have
426 * to do subchannel housekeeping.
427 */
428void
429css_reiterate_subchannels(void)
430{
431 css_clear_subchannel_slow_list();
432 need_rescan = 1;
433}
434
435/*
436 * Called from the machine check handler for subchannel report words.
437 */
438int
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800439css_process_crw(int rsid1, int rsid2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440{
441 int ret;
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800442 struct subchannel_id mchk_schid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800444 CIO_CRW_EVENT(2, "source is subchannel %04X, subsystem id %x\n",
445 rsid1, rsid2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446
447 if (need_rescan)
448 /* We need to iterate all subchannels anyway. */
449 return -EAGAIN;
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800450
451 init_subchannel_id(&mchk_schid);
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800452 mchk_schid.sch_no = rsid1;
453 if (rsid2 != 0)
454 mchk_schid.ssid = (rsid2 >> 8) & 3;
455
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 /*
457 * Since we are always presented with IPI in the CRW, we have to
458 * use stsch() to find out if the subchannel in question has come
459 * or gone.
460 */
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800461 ret = css_evaluate_subchannel(mchk_schid, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 if (ret == -EAGAIN) {
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800463 if (css_enqueue_subchannel_slow(mchk_schid)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 css_clear_subchannel_slow_list();
465 need_rescan = 1;
466 }
467 }
468 return ret;
469}
470
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800471static int __init
472__init_channel_subsystem(struct subchannel_id schid, void *data)
473{
474 struct subchannel *sch;
475 int ret;
476
477 if (cio_is_console(schid))
478 sch = cio_get_console_subchannel();
479 else {
480 sch = css_alloc_subchannel(schid);
481 if (IS_ERR(sch))
482 ret = PTR_ERR(sch);
483 else
484 ret = 0;
485 switch (ret) {
486 case 0:
487 break;
488 case -ENOMEM:
489 panic("Out of memory in init_channel_subsystem\n");
490 /* -ENXIO: no more subchannels. */
491 case -ENXIO:
492 return ret;
Greg Smithe843e282006-03-14 19:50:17 -0800493 /* -EIO: this subchannel set not supported. */
494 case -EIO:
495 return ret;
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800496 default:
497 return 0;
498 }
499 }
500 /*
501 * We register ALL valid subchannels in ioinfo, even those
502 * that have been present before init_channel_subsystem.
503 * These subchannels can't have been registered yet (kmalloc
504 * not working) so we do it now. This is true e.g. for the
505 * console subchannel.
506 */
507 css_register_subchannel(sch);
508 return 0;
509}
510
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511static void __init
Cornelia Hucka28c6942006-01-06 00:19:23 -0800512css_generate_pgid(struct channel_subsystem *css, u32 tod_high)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513{
Cornelia Hucka28c6942006-01-06 00:19:23 -0800514 if (css_characteristics_avail && css_general_characteristics.mcss) {
515 css->global_pgid.pgid_high.ext_cssid.version = 0x80;
516 css->global_pgid.pgid_high.ext_cssid.cssid = css->cssid;
517 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518#ifdef CONFIG_SMP
Cornelia Hucka28c6942006-01-06 00:19:23 -0800519 css->global_pgid.pgid_high.cpu_addr = hard_smp_processor_id();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520#else
Cornelia Hucka28c6942006-01-06 00:19:23 -0800521 css->global_pgid.pgid_high.cpu_addr = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522#endif
523 }
Cornelia Hucka28c6942006-01-06 00:19:23 -0800524 css->global_pgid.cpu_id = ((cpuid_t *) __LC_CPUID)->ident;
525 css->global_pgid.cpu_model = ((cpuid_t *) __LC_CPUID)->machine;
526 css->global_pgid.tod_high = tod_high;
527
528}
529
Cornelia Huck3b793062006-01-06 00:19:26 -0800530static void
531channel_subsystem_release(struct device *dev)
532{
533 struct channel_subsystem *css;
534
535 css = to_css(dev);
Cornelia Huck495a5b42006-03-24 03:15:14 -0800536 mutex_destroy(&css->mutex);
Cornelia Huck3b793062006-01-06 00:19:26 -0800537 kfree(css);
538}
539
Cornelia Huck495a5b42006-03-24 03:15:14 -0800540static ssize_t
541css_cm_enable_show(struct device *dev, struct device_attribute *attr,
542 char *buf)
543{
544 struct channel_subsystem *css = to_css(dev);
545
546 if (!css)
547 return 0;
548 return sprintf(buf, "%x\n", css->cm_enabled);
549}
550
551static ssize_t
552css_cm_enable_store(struct device *dev, struct device_attribute *attr,
553 const char *buf, size_t count)
554{
555 struct channel_subsystem *css = to_css(dev);
556 int ret;
557
558 switch (buf[0]) {
559 case '0':
560 ret = css->cm_enabled ? chsc_secm(css, 0) : 0;
561 break;
562 case '1':
563 ret = css->cm_enabled ? 0 : chsc_secm(css, 1);
564 break;
565 default:
566 ret = -EINVAL;
567 }
568 return ret < 0 ? ret : count;
569}
570
571static DEVICE_ATTR(cm_enable, 0644, css_cm_enable_show, css_cm_enable_store);
572
Cornelia Hucka28c6942006-01-06 00:19:23 -0800573static inline void __init
574setup_css(int nr)
575{
576 u32 tod_high;
577
578 memset(css[nr], 0, sizeof(struct channel_subsystem));
Cornelia Huck495a5b42006-03-24 03:15:14 -0800579 mutex_init(&css[nr]->mutex);
Cornelia Hucka28c6942006-01-06 00:19:23 -0800580 css[nr]->valid = 1;
581 css[nr]->cssid = nr;
582 sprintf(css[nr]->device.bus_id, "css%x", nr);
Cornelia Huck3b793062006-01-06 00:19:26 -0800583 css[nr]->device.release = channel_subsystem_release;
Cornelia Hucka28c6942006-01-06 00:19:23 -0800584 tod_high = (u32) (get_clock() >> 32);
585 css_generate_pgid(css[nr], tod_high);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586}
587
588/*
589 * Now that the driver core is running, we can setup our channel subsystem.
590 * The struct subchannel's are created during probing (except for the
591 * static console subchannel).
592 */
593static int __init
594init_channel_subsystem (void)
595{
Cornelia Hucka28c6942006-01-06 00:19:23 -0800596 int ret, i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597
598 if (chsc_determine_css_characteristics() == 0)
599 css_characteristics_avail = 1;
600
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 if ((ret = bus_register(&css_bus_type)))
602 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800604 /* Try to enable MSS. */
605 ret = chsc_enable_facility(CHSC_SDA_OC_MSS);
606 switch (ret) {
607 case 0: /* Success. */
608 max_ssid = __MAX_SSID;
609 break;
610 case -ENOMEM:
611 goto out_bus;
612 default:
613 max_ssid = 0;
614 }
Cornelia Hucka28c6942006-01-06 00:19:23 -0800615 /* Setup css structure. */
616 for (i = 0; i <= __MAX_CSSID; i++) {
617 css[i] = kmalloc(sizeof(struct channel_subsystem), GFP_KERNEL);
618 if (!css[i]) {
619 ret = -ENOMEM;
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800620 goto out_unregister;
Cornelia Hucka28c6942006-01-06 00:19:23 -0800621 }
622 setup_css(i);
623 ret = device_register(&css[i]->device);
624 if (ret)
625 goto out_free;
Cornelia Huck495a5b42006-03-24 03:15:14 -0800626 if (css_characteristics_avail && css_chsc_characteristics.secm)
627 device_create_file(&css[i]->device,
628 &dev_attr_cm_enable);
Cornelia Hucka28c6942006-01-06 00:19:23 -0800629 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 css_init_done = 1;
631
632 ctl_set_bit(6, 28);
633
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800634 for_each_subchannel(__init_channel_subsystem, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 return 0;
Cornelia Hucka28c6942006-01-06 00:19:23 -0800636out_free:
637 kfree(css[i]);
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800638out_unregister:
Cornelia Hucka28c6942006-01-06 00:19:23 -0800639 while (i > 0) {
640 i--;
Cornelia Huck495a5b42006-03-24 03:15:14 -0800641 if (css_characteristics_avail && css_chsc_characteristics.secm)
642 device_remove_file(&css[i]->device,
643 &dev_attr_cm_enable);
Cornelia Hucka28c6942006-01-06 00:19:23 -0800644 device_unregister(&css[i]->device);
645 }
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800646out_bus:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 bus_unregister(&css_bus_type);
648out:
649 return ret;
650}
651
652/*
653 * find a driver for a subchannel. They identify by the subchannel
654 * type with the exception that the console subchannel driver has its own
655 * subchannel type although the device is an i/o subchannel
656 */
657static int
658css_bus_match (struct device *dev, struct device_driver *drv)
659{
660 struct subchannel *sch = container_of (dev, struct subchannel, dev);
661 struct css_driver *driver = container_of (drv, struct css_driver, drv);
662
663 if (sch->st == driver->subchannel_type)
664 return 1;
665
666 return 0;
667}
668
Cornelia Huck8bbace72006-01-11 10:56:22 +0100669static int
670css_probe (struct device *dev)
671{
672 struct subchannel *sch;
673
674 sch = to_subchannel(dev);
675 sch->driver = container_of (dev->driver, struct css_driver, drv);
676 return (sch->driver->probe ? sch->driver->probe(sch) : 0);
677}
678
679static int
680css_remove (struct device *dev)
681{
682 struct subchannel *sch;
683
684 sch = to_subchannel(dev);
685 return (sch->driver->remove ? sch->driver->remove(sch) : 0);
686}
687
688static void
689css_shutdown (struct device *dev)
690{
691 struct subchannel *sch;
692
693 sch = to_subchannel(dev);
694 if (sch->driver->shutdown)
695 sch->driver->shutdown(sch);
696}
697
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698struct bus_type css_bus_type = {
Cornelia Huck8bbace72006-01-11 10:56:22 +0100699 .name = "css",
700 .match = css_bus_match,
701 .probe = css_probe,
702 .remove = css_remove,
703 .shutdown = css_shutdown,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704};
705
706subsys_initcall(init_channel_subsystem);
707
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708int
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800709css_enqueue_subchannel_slow(struct subchannel_id schid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710{
711 struct slow_subchannel *new_slow_sch;
712 unsigned long flags;
713
Eric Sesterhenn88abaab2006-03-24 03:15:31 -0800714 new_slow_sch = kzalloc(sizeof(struct slow_subchannel), GFP_ATOMIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715 if (!new_slow_sch)
716 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 new_slow_sch->schid = schid;
718 spin_lock_irqsave(&slow_subchannel_lock, flags);
719 list_add_tail(&new_slow_sch->slow_list, &slow_subchannels_head);
720 spin_unlock_irqrestore(&slow_subchannel_lock, flags);
721 return 0;
722}
723
724void
725css_clear_subchannel_slow_list(void)
726{
727 unsigned long flags;
728
729 spin_lock_irqsave(&slow_subchannel_lock, flags);
730 while (!list_empty(&slow_subchannels_head)) {
731 struct slow_subchannel *slow_sch =
732 list_entry(slow_subchannels_head.next,
733 struct slow_subchannel, slow_list);
734
735 list_del_init(slow_subchannels_head.next);
736 kfree(slow_sch);
737 }
738 spin_unlock_irqrestore(&slow_subchannel_lock, flags);
739}
740
741
742
743int
744css_slow_subchannels_exist(void)
745{
746 return (!list_empty(&slow_subchannels_head));
747}
748
749MODULE_LICENSE("GPL");
750EXPORT_SYMBOL(css_bus_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751EXPORT_SYMBOL_GPL(css_characteristics_avail);