include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit...
[linux-2.6-block.git] / drivers / s390 / cio / chp.c
CommitLineData
e6b6e10a
PO
1/*
2 * drivers/s390/cio/chp.c
3 *
4 * Copyright IBM Corp. 1999,2007
5 * Author(s): Cornelia Huck (cornelia.huck@de.ibm.com)
6 * Arnd Bergmann (arndb@de.ibm.com)
7 * Peter Oberparleiter <peter.oberparleiter@de.ibm.com>
8 */
9
10#include <linux/bug.h>
11#include <linux/workqueue.h>
12#include <linux/spinlock.h>
e5854a58
PO
13#include <linux/init.h>
14#include <linux/jiffies.h>
15#include <linux/wait.h>
16#include <linux/mutex.h>
a0ea22c3 17#include <linux/errno.h>
5a0e3ad6 18#include <linux/slab.h>
e5854a58
PO
19#include <asm/chpid.h>
20#include <asm/sclp.h>
f5daba1d 21#include <asm/crw.h>
e6b6e10a 22
e6b6e10a
PO
23#include "cio.h"
24#include "css.h"
25#include "ioasm.h"
26#include "cio_debug.h"
27#include "chp.h"
28
29#define to_channelpath(device) container_of(device, struct channel_path, dev)
e5854a58
PO
30#define CHP_INFO_UPDATE_INTERVAL 1*HZ
31
32enum cfg_task_t {
33 cfg_none,
34 cfg_configure,
35 cfg_deconfigure
36};
37
38/* Map for pending configure tasks. */
39static enum cfg_task_t chp_cfg_task[__MAX_CSSID + 1][__MAX_CHPID + 1];
40static DEFINE_MUTEX(cfg_lock);
41static int cfg_busy;
42
43/* Map for channel-path status. */
44static struct sclp_chp_info chp_info;
45static DEFINE_MUTEX(info_lock);
46
47/* Time after which channel-path status may be outdated. */
48static unsigned long chp_info_expires;
49
50/* Workqueue to perform pending configure tasks. */
51static struct workqueue_struct *chp_wq;
52static struct work_struct cfg_work;
53
54/* Wait queue for configure completion events. */
55static wait_queue_head_t cfg_wait_queue;
e6b6e10a
PO
56
57/* Return channel_path struct for given chpid. */
58static inline struct channel_path *chpid_to_chp(struct chp_id chpid)
59{
7c9f4e3a 60 return channel_subsystems[chpid.cssid]->chps[chpid.id];
e6b6e10a
PO
61}
62
63/* Set vary state for given chpid. */
64static void set_chp_logically_online(struct chp_id chpid, int onoff)
65{
66 chpid_to_chp(chpid)->state = onoff;
67}
68
af901ca1 69/* On success return 0 if channel-path is varied offline, 1 if it is varied
e6b6e10a
PO
70 * online. Return -ENODEV if channel-path is not registered. */
71int chp_get_status(struct chp_id chpid)
72{
73 return (chpid_to_chp(chpid) ? chpid_to_chp(chpid)->state : -ENODEV);
74}
75
76/**
77 * chp_get_sch_opm - return opm for subchannel
78 * @sch: subchannel
79 *
80 * Calculate and return the operational path mask (opm) based on the chpids
81 * used by the subchannel and the status of the associated channel-paths.
82 */
83u8 chp_get_sch_opm(struct subchannel *sch)
84{
85 struct chp_id chpid;
86 int opm;
87 int i;
88
89 opm = 0;
90 chp_id_init(&chpid);
a0ea22c3 91 for (i = 0; i < 8; i++) {
e6b6e10a
PO
92 opm <<= 1;
93 chpid.id = sch->schib.pmcw.chpid[i];
94 if (chp_get_status(chpid) != 0)
95 opm |= 1;
96 }
97 return opm;
98}
44a1c19e 99EXPORT_SYMBOL_GPL(chp_get_sch_opm);
e6b6e10a
PO
100
101/**
102 * chp_is_registered - check if a channel-path is registered
103 * @chpid: channel-path ID
104 *
105 * Return non-zero if a channel-path with the given chpid is registered,
106 * zero otherwise.
107 */
108int chp_is_registered(struct chp_id chpid)
109{
110 return chpid_to_chp(chpid) != NULL;
111}
112
113/*
114 * Function: s390_vary_chpid
115 * Varies the specified chpid online or offline
116 */
117static int s390_vary_chpid(struct chp_id chpid, int on)
118{
119 char dbf_text[15];
120 int status;
121
122 sprintf(dbf_text, on?"varyon%x.%02x":"varyoff%x.%02x", chpid.cssid,
123 chpid.id);
a0ea22c3 124 CIO_TRACE_EVENT(2, dbf_text);
e6b6e10a
PO
125
126 status = chp_get_status(chpid);
c78aa6cb
ME
127 if (!on && !status)
128 return 0;
e6b6e10a
PO
129
130 set_chp_logically_online(chpid, on);
131 chsc_chp_vary(chpid, on);
132 return 0;
133}
134
135/*
136 * Channel measurement related functions
137 */
91a69029
ZR
138static ssize_t chp_measurement_chars_read(struct kobject *kobj,
139 struct bin_attribute *bin_attr,
140 char *buf, loff_t off, size_t count)
e6b6e10a
PO
141{
142 struct channel_path *chp;
364c8558 143 struct device *device;
e6b6e10a 144
364c8558
HC
145 device = container_of(kobj, struct device, kobj);
146 chp = to_channelpath(device);
e6b6e10a
PO
147 if (!chp->cmg_chars)
148 return 0;
149
d9cef21a
AM
150 return memory_read_from_buffer(buf, count, &off,
151 chp->cmg_chars, sizeof(struct cmg_chars));
e6b6e10a
PO
152}
153
154static struct bin_attribute chp_measurement_chars_attr = {
155 .attr = {
156 .name = "measurement_chars",
157 .mode = S_IRUSR,
e6b6e10a
PO
158 },
159 .size = sizeof(struct cmg_chars),
160 .read = chp_measurement_chars_read,
161};
162
163static void chp_measurement_copy_block(struct cmg_entry *buf,
164 struct channel_subsystem *css,
165 struct chp_id chpid)
166{
167 void *area;
168 struct cmg_entry *entry, reference_buf;
169 int idx;
170
171 if (chpid.id < 128) {
172 area = css->cub_addr1;
173 idx = chpid.id;
174 } else {
175 area = css->cub_addr2;
176 idx = chpid.id - 128;
177 }
178 entry = area + (idx * sizeof(struct cmg_entry));
179 do {
180 memcpy(buf, entry, sizeof(*entry));
181 memcpy(&reference_buf, entry, sizeof(*entry));
182 } while (reference_buf.values[0] != buf->values[0]);
183}
184
91a69029
ZR
185static ssize_t chp_measurement_read(struct kobject *kobj,
186 struct bin_attribute *bin_attr,
187 char *buf, loff_t off, size_t count)
e6b6e10a
PO
188{
189 struct channel_path *chp;
190 struct channel_subsystem *css;
364c8558 191 struct device *device;
e6b6e10a
PO
192 unsigned int size;
193
364c8558
HC
194 device = container_of(kobj, struct device, kobj);
195 chp = to_channelpath(device);
e6b6e10a
PO
196 css = to_css(chp->dev.parent);
197
198 size = sizeof(struct cmg_entry);
199
200 /* Only allow single reads. */
201 if (off || count < size)
202 return 0;
203 chp_measurement_copy_block((struct cmg_entry *)buf, css, chp->chpid);
204 count = size;
205 return count;
206}
207
208static struct bin_attribute chp_measurement_attr = {
209 .attr = {
210 .name = "measurement",
211 .mode = S_IRUSR,
e6b6e10a
PO
212 },
213 .size = sizeof(struct cmg_entry),
214 .read = chp_measurement_read,
215};
216
217void chp_remove_cmg_attr(struct channel_path *chp)
218{
219 device_remove_bin_file(&chp->dev, &chp_measurement_chars_attr);
220 device_remove_bin_file(&chp->dev, &chp_measurement_attr);
221}
222
223int chp_add_cmg_attr(struct channel_path *chp)
224{
225 int ret;
226
227 ret = device_create_bin_file(&chp->dev, &chp_measurement_chars_attr);
228 if (ret)
229 return ret;
230 ret = device_create_bin_file(&chp->dev, &chp_measurement_attr);
231 if (ret)
232 device_remove_bin_file(&chp->dev, &chp_measurement_chars_attr);
233 return ret;
234}
235
236/*
237 * Files for the channel path entries.
238 */
239static ssize_t chp_status_show(struct device *dev,
240 struct device_attribute *attr, char *buf)
241{
05469607 242 struct channel_path *chp = to_channelpath(dev);
e6b6e10a
PO
243
244 if (!chp)
245 return 0;
246 return (chp_get_status(chp->chpid) ? sprintf(buf, "online\n") :
247 sprintf(buf, "offline\n"));
248}
249
250static ssize_t chp_status_write(struct device *dev,
251 struct device_attribute *attr,
252 const char *buf, size_t count)
253{
05469607 254 struct channel_path *cp = to_channelpath(dev);
e6b6e10a
PO
255 char cmd[10];
256 int num_args;
257 int error;
258
259 num_args = sscanf(buf, "%5s", cmd);
260 if (!num_args)
261 return count;
262
263 if (!strnicmp(cmd, "on", 2) || !strcmp(cmd, "1"))
264 error = s390_vary_chpid(cp->chpid, 1);
265 else if (!strnicmp(cmd, "off", 3) || !strcmp(cmd, "0"))
266 error = s390_vary_chpid(cp->chpid, 0);
267 else
268 error = -EINVAL;
269
270 return error < 0 ? error : count;
271
272}
273
274static DEVICE_ATTR(status, 0644, chp_status_show, chp_status_write);
275
e5854a58
PO
276static ssize_t chp_configure_show(struct device *dev,
277 struct device_attribute *attr, char *buf)
278{
279 struct channel_path *cp;
280 int status;
281
05469607 282 cp = to_channelpath(dev);
e5854a58
PO
283 status = chp_info_get_status(cp->chpid);
284 if (status < 0)
285 return status;
286
287 return snprintf(buf, PAGE_SIZE, "%d\n", status);
288}
289
290static int cfg_wait_idle(void);
291
292static ssize_t chp_configure_write(struct device *dev,
293 struct device_attribute *attr,
294 const char *buf, size_t count)
295{
296 struct channel_path *cp;
297 int val;
298 char delim;
299
300 if (sscanf(buf, "%d %c", &val, &delim) != 1)
301 return -EINVAL;
302 if (val != 0 && val != 1)
303 return -EINVAL;
05469607 304 cp = to_channelpath(dev);
e5854a58
PO
305 chp_cfg_schedule(cp->chpid, val);
306 cfg_wait_idle();
307
308 return count;
309}
310
311static DEVICE_ATTR(configure, 0644, chp_configure_show, chp_configure_write);
312
e6b6e10a
PO
313static ssize_t chp_type_show(struct device *dev, struct device_attribute *attr,
314 char *buf)
315{
05469607 316 struct channel_path *chp = to_channelpath(dev);
e6b6e10a
PO
317
318 if (!chp)
319 return 0;
320 return sprintf(buf, "%x\n", chp->desc.desc);
321}
322
323static DEVICE_ATTR(type, 0444, chp_type_show, NULL);
324
325static ssize_t chp_cmg_show(struct device *dev, struct device_attribute *attr,
326 char *buf)
327{
328 struct channel_path *chp = to_channelpath(dev);
329
330 if (!chp)
331 return 0;
332 if (chp->cmg == -1) /* channel measurements not available */
333 return sprintf(buf, "unknown\n");
334 return sprintf(buf, "%x\n", chp->cmg);
335}
336
337static DEVICE_ATTR(cmg, 0444, chp_cmg_show, NULL);
338
339static ssize_t chp_shared_show(struct device *dev,
340 struct device_attribute *attr, char *buf)
341{
342 struct channel_path *chp = to_channelpath(dev);
343
344 if (!chp)
345 return 0;
346 if (chp->shared == -1) /* channel measurements not available */
347 return sprintf(buf, "unknown\n");
348 return sprintf(buf, "%x\n", chp->shared);
349}
350
351static DEVICE_ATTR(shared, 0444, chp_shared_show, NULL);
352
a0ea22c3 353static struct attribute *chp_attrs[] = {
e6b6e10a 354 &dev_attr_status.attr,
e5854a58 355 &dev_attr_configure.attr,
e6b6e10a
PO
356 &dev_attr_type.attr,
357 &dev_attr_cmg.attr,
358 &dev_attr_shared.attr,
359 NULL,
360};
361
362static struct attribute_group chp_attr_group = {
363 .attrs = chp_attrs,
364};
365
366static void chp_release(struct device *dev)
367{
368 struct channel_path *cp;
369
05469607 370 cp = to_channelpath(dev);
e6b6e10a
PO
371 kfree(cp);
372}
373
374/**
375 * chp_new - register a new channel-path
376 * @chpid - channel-path ID
377 *
378 * Create and register data structure representing new channel-path. Return
379 * zero on success, non-zero otherwise.
380 */
381int chp_new(struct chp_id chpid)
382{
383 struct channel_path *chp;
384 int ret;
385
e5854a58
PO
386 if (chp_is_registered(chpid))
387 return 0;
e6b6e10a
PO
388 chp = kzalloc(sizeof(struct channel_path), GFP_KERNEL);
389 if (!chp)
390 return -ENOMEM;
391
392 /* fill in status, etc. */
393 chp->chpid = chpid;
394 chp->state = 1;
7c9f4e3a 395 chp->dev.parent = &channel_subsystems[chpid.cssid]->device;
e6b6e10a 396 chp->dev.release = chp_release;
e6b6e10a
PO
397
398 /* Obtain channel path description and fill it in. */
9d92a7e1 399 ret = chsc_determine_base_channel_path_desc(chpid, &chp->desc);
e6b6e10a
PO
400 if (ret)
401 goto out_free;
c9182e0f
PO
402 if ((chp->desc.flags & 0x80) == 0) {
403 ret = -ENODEV;
404 goto out_free;
405 }
e6b6e10a 406 /* Get channel-measurement characteristics. */
75784c00 407 if (css_chsc_characteristics.scmc && css_chsc_characteristics.secm) {
e6b6e10a
PO
408 ret = chsc_get_channel_measurement_chars(chp);
409 if (ret)
410 goto out_free;
411 } else {
e6b6e10a
PO
412 chp->cmg = -1;
413 }
ec004407 414 dev_set_name(&chp->dev, "chp%x.%02x", chpid.cssid, chpid.id);
e6b6e10a
PO
415
416 /* make it known to the system */
417 ret = device_register(&chp->dev);
418 if (ret) {
e556bbbd
CH
419 CIO_MSG_EVENT(0, "Could not register chp%x.%02x: %d\n",
420 chpid.cssid, chpid.id, ret);
c6304933
SO
421 put_device(&chp->dev);
422 goto out;
e6b6e10a
PO
423 }
424 ret = sysfs_create_group(&chp->dev.kobj, &chp_attr_group);
425 if (ret) {
426 device_unregister(&chp->dev);
a2164b81 427 goto out;
e6b6e10a 428 }
7c9f4e3a
CH
429 mutex_lock(&channel_subsystems[chpid.cssid]->mutex);
430 if (channel_subsystems[chpid.cssid]->cm_enabled) {
e6b6e10a
PO
431 ret = chp_add_cmg_attr(chp);
432 if (ret) {
433 sysfs_remove_group(&chp->dev.kobj, &chp_attr_group);
434 device_unregister(&chp->dev);
7c9f4e3a 435 mutex_unlock(&channel_subsystems[chpid.cssid]->mutex);
a2164b81 436 goto out;
e6b6e10a
PO
437 }
438 }
7c9f4e3a
CH
439 channel_subsystems[chpid.cssid]->chps[chpid.id] = chp;
440 mutex_unlock(&channel_subsystems[chpid.cssid]->mutex);
a2164b81 441 goto out;
e6b6e10a
PO
442out_free:
443 kfree(chp);
a2164b81 444out:
e6b6e10a
PO
445 return ret;
446}
447
448/**
449 * chp_get_chp_desc - return newly allocated channel-path description
450 * @chpid: channel-path ID
451 *
452 * On success return a newly allocated copy of the channel-path description
453 * data associated with the given channel-path ID. Return %NULL on error.
454 */
455void *chp_get_chp_desc(struct chp_id chpid)
456{
457 struct channel_path *chp;
458 struct channel_path_desc *desc;
459
460 chp = chpid_to_chp(chpid);
461 if (!chp)
462 return NULL;
463 desc = kmalloc(sizeof(struct channel_path_desc), GFP_KERNEL);
464 if (!desc)
465 return NULL;
466 memcpy(desc, &chp->desc, sizeof(struct channel_path_desc));
467 return desc;
468}
469
470/**
471 * chp_process_crw - process channel-path status change
c1156189
CH
472 * @crw0: channel report-word to handler
473 * @crw1: second channel-report word (always NULL)
474 * @overflow: crw overflow indication
e6b6e10a
PO
475 *
476 * Handle channel-report-words indicating that the status of a channel-path
477 * has changed.
478 */
c1156189
CH
479static void chp_process_crw(struct crw *crw0, struct crw *crw1,
480 int overflow)
e6b6e10a
PO
481{
482 struct chp_id chpid;
483
c1156189
CH
484 if (overflow) {
485 css_schedule_eval_all();
486 return;
487 }
488 CIO_CRW_EVENT(2, "CRW reports slct=%d, oflw=%d, "
489 "chn=%d, rsc=%X, anc=%d, erc=%X, rsid=%X\n",
490 crw0->slct, crw0->oflw, crw0->chn, crw0->rsc, crw0->anc,
491 crw0->erc, crw0->rsid);
492 /*
493 * Check for solicited machine checks. These are
494 * created by reset channel path and need not be
495 * handled here.
496 */
497 if (crw0->slct) {
498 CIO_CRW_EVENT(2, "solicited machine check for "
499 "channel path %02X\n", crw0->rsid);
500 return;
501 }
e6b6e10a 502 chp_id_init(&chpid);
c1156189
CH
503 chpid.id = crw0->rsid;
504 switch (crw0->erc) {
505 case CRW_ERC_IPARM: /* Path has come. */
e6b6e10a
PO
506 if (!chp_is_registered(chpid))
507 chp_new(chpid);
83b3370c 508 chsc_chp_online(chpid);
c1156189
CH
509 break;
510 case CRW_ERC_PERRI: /* Path has gone. */
511 case CRW_ERC_PERRN:
e6b6e10a 512 chsc_chp_offline(chpid);
c1156189
CH
513 break;
514 default:
515 CIO_CRW_EVENT(2, "Don't know how to handle erc=%x\n",
516 crw0->erc);
517 }
e6b6e10a 518}
e5854a58 519
99611f87 520int chp_ssd_get_mask(struct chsc_ssd_info *ssd, struct chp_link *link)
c820de39
CH
521{
522 int i;
523 int mask;
524
525 for (i = 0; i < 8; i++) {
526 mask = 0x80 >> i;
527 if (!(ssd->path_mask & mask))
528 continue;
99611f87 529 if (!chp_id_is_equal(&ssd->chpid[i], &link->chpid))
c820de39
CH
530 continue;
531 if ((ssd->fla_valid_mask & mask) &&
99611f87 532 ((ssd->fla[i] & link->fla_mask) != link->fla))
c820de39
CH
533 continue;
534 return mask;
535 }
536 return 0;
537}
538EXPORT_SYMBOL_GPL(chp_ssd_get_mask);
539
e5854a58
PO
540static inline int info_bit_num(struct chp_id id)
541{
542 return id.id + id.cssid * (__MAX_CHPID + 1);
543}
544
545/* Force chp_info refresh on next call to info_validate(). */
546static void info_expire(void)
547{
548 mutex_lock(&info_lock);
549 chp_info_expires = jiffies - 1;
550 mutex_unlock(&info_lock);
551}
552
553/* Ensure that chp_info is up-to-date. */
554static int info_update(void)
555{
556 int rc;
557
558 mutex_lock(&info_lock);
559 rc = 0;
560 if (time_after(jiffies, chp_info_expires)) {
561 /* Data is too old, update. */
562 rc = sclp_chp_read_info(&chp_info);
563 chp_info_expires = jiffies + CHP_INFO_UPDATE_INTERVAL ;
564 }
565 mutex_unlock(&info_lock);
566
567 return rc;
568}
569
570/**
571 * chp_info_get_status - retrieve configure status of a channel-path
572 * @chpid: channel-path ID
573 *
574 * On success, return 0 for standby, 1 for configured, 2 for reserved,
575 * 3 for not recognized. Return negative error code on error.
576 */
577int chp_info_get_status(struct chp_id chpid)
578{
579 int rc;
580 int bit;
581
582 rc = info_update();
583 if (rc)
584 return rc;
585
586 bit = info_bit_num(chpid);
587 mutex_lock(&info_lock);
588 if (!chp_test_bit(chp_info.recognized, bit))
589 rc = CHP_STATUS_NOT_RECOGNIZED;
590 else if (chp_test_bit(chp_info.configured, bit))
591 rc = CHP_STATUS_CONFIGURED;
592 else if (chp_test_bit(chp_info.standby, bit))
593 rc = CHP_STATUS_STANDBY;
594 else
595 rc = CHP_STATUS_RESERVED;
596 mutex_unlock(&info_lock);
597
598 return rc;
599}
600
601/* Return configure task for chpid. */
602static enum cfg_task_t cfg_get_task(struct chp_id chpid)
603{
604 return chp_cfg_task[chpid.cssid][chpid.id];
605}
606
607/* Set configure task for chpid. */
608static void cfg_set_task(struct chp_id chpid, enum cfg_task_t cfg)
609{
610 chp_cfg_task[chpid.cssid][chpid.id] = cfg;
611}
612
613/* Perform one configure/deconfigure request. Reschedule work function until
614 * last request. */
615static void cfg_func(struct work_struct *work)
616{
617 struct chp_id chpid;
618 enum cfg_task_t t;
683c5418 619 int rc;
e5854a58
PO
620
621 mutex_lock(&cfg_lock);
622 t = cfg_none;
623 chp_id_for_each(&chpid) {
624 t = cfg_get_task(chpid);
625 if (t != cfg_none) {
626 cfg_set_task(chpid, cfg_none);
627 break;
628 }
629 }
630 mutex_unlock(&cfg_lock);
631
632 switch (t) {
633 case cfg_configure:
683c5418
PO
634 rc = sclp_chp_configure(chpid);
635 if (rc)
636 CIO_MSG_EVENT(2, "chp: sclp_chp_configure(%x.%02x)="
637 "%d\n", chpid.cssid, chpid.id, rc);
638 else {
639 info_expire();
640 chsc_chp_online(chpid);
641 }
e5854a58
PO
642 break;
643 case cfg_deconfigure:
683c5418
PO
644 rc = sclp_chp_deconfigure(chpid);
645 if (rc)
646 CIO_MSG_EVENT(2, "chp: sclp_chp_deconfigure(%x.%02x)="
647 "%d\n", chpid.cssid, chpid.id, rc);
648 else {
649 info_expire();
650 chsc_chp_offline(chpid);
651 }
e5854a58
PO
652 break;
653 case cfg_none:
654 /* Get updated information after last change. */
655 info_update();
656 mutex_lock(&cfg_lock);
657 cfg_busy = 0;
658 mutex_unlock(&cfg_lock);
659 wake_up_interruptible(&cfg_wait_queue);
660 return;
661 }
662 queue_work(chp_wq, &cfg_work);
663}
664
665/**
666 * chp_cfg_schedule - schedule chpid configuration request
667 * @chpid - channel-path ID
668 * @configure - Non-zero for configure, zero for deconfigure
669 *
670 * Schedule a channel-path configuration/deconfiguration request.
671 */
672void chp_cfg_schedule(struct chp_id chpid, int configure)
673{
674 CIO_MSG_EVENT(2, "chp_cfg_sched%x.%02x=%d\n", chpid.cssid, chpid.id,
675 configure);
676 mutex_lock(&cfg_lock);
677 cfg_set_task(chpid, configure ? cfg_configure : cfg_deconfigure);
678 cfg_busy = 1;
679 mutex_unlock(&cfg_lock);
680 queue_work(chp_wq, &cfg_work);
681}
682
683/**
684 * chp_cfg_cancel_deconfigure - cancel chpid deconfiguration request
685 * @chpid - channel-path ID
686 *
687 * Cancel an active channel-path deconfiguration request if it has not yet
688 * been performed.
689 */
690void chp_cfg_cancel_deconfigure(struct chp_id chpid)
691{
692 CIO_MSG_EVENT(2, "chp_cfg_cancel:%x.%02x\n", chpid.cssid, chpid.id);
693 mutex_lock(&cfg_lock);
694 if (cfg_get_task(chpid) == cfg_deconfigure)
695 cfg_set_task(chpid, cfg_none);
696 mutex_unlock(&cfg_lock);
697}
698
699static int cfg_wait_idle(void)
700{
701 if (wait_event_interruptible(cfg_wait_queue, !cfg_busy))
702 return -ERESTARTSYS;
703 return 0;
704}
705
706static int __init chp_init(void)
707{
708 struct chp_id chpid;
c1156189 709 int ret;
e5854a58 710
f5daba1d 711 ret = crw_register_handler(CRW_RSC_CPATH, chp_process_crw);
c1156189
CH
712 if (ret)
713 return ret;
e5854a58 714 chp_wq = create_singlethread_workqueue("cio_chp");
c1156189 715 if (!chp_wq) {
f5daba1d 716 crw_unregister_handler(CRW_RSC_CPATH);
e5854a58 717 return -ENOMEM;
c1156189 718 }
e5854a58
PO
719 INIT_WORK(&cfg_work, cfg_func);
720 init_waitqueue_head(&cfg_wait_queue);
721 if (info_update())
722 return 0;
723 /* Register available channel-paths. */
724 chp_id_for_each(&chpid) {
725 if (chp_info_get_status(chpid) != CHP_STATUS_NOT_RECOGNIZED)
726 chp_new(chpid);
727 }
728
729 return 0;
730}
731
732subsys_initcall(chp_init);