Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / drivers / s390 / cio / chp.c
blobcba2d048a96b3cb0cc79080ef4c771b0f7d5bc34
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright IBM Corp. 1999, 2010
4 * Author(s): Cornelia Huck (cornelia.huck@de.ibm.com)
5 * Arnd Bergmann (arndb@de.ibm.com)
6 * Peter Oberparleiter <peter.oberparleiter@de.ibm.com>
7 */
9 #include <linux/bug.h>
10 #include <linux/workqueue.h>
11 #include <linux/spinlock.h>
12 #include <linux/export.h>
13 #include <linux/sched.h>
14 #include <linux/init.h>
15 #include <linux/jiffies.h>
16 #include <linux/wait.h>
17 #include <linux/mutex.h>
18 #include <linux/errno.h>
19 #include <linux/slab.h>
20 #include <asm/chpid.h>
21 #include <asm/sclp.h>
22 #include <asm/crw.h>
24 #include "cio.h"
25 #include "css.h"
26 #include "ioasm.h"
27 #include "cio_debug.h"
28 #include "chp.h"
30 #define to_channelpath(device) container_of(device, struct channel_path, dev)
31 #define CHP_INFO_UPDATE_INTERVAL 1*HZ
33 enum cfg_task_t {
34 cfg_none,
35 cfg_configure,
36 cfg_deconfigure
39 /* Map for pending configure tasks. */
40 static enum cfg_task_t chp_cfg_task[__MAX_CSSID + 1][__MAX_CHPID + 1];
41 static DEFINE_SPINLOCK(cfg_lock);
43 /* Map for channel-path status. */
44 static struct sclp_chp_info chp_info;
45 static DEFINE_MUTEX(info_lock);
47 /* Time after which channel-path status may be outdated. */
48 static unsigned long chp_info_expires;
50 static struct work_struct cfg_work;
52 /* Wait queue for configure completion events. */
53 static DECLARE_WAIT_QUEUE_HEAD(cfg_wait_queue);
55 /* Set vary state for given chpid. */
56 static void set_chp_logically_online(struct chp_id chpid, int onoff)
58 chpid_to_chp(chpid)->state = onoff;
61 /* On success return 0 if channel-path is varied offline, 1 if it is varied
62 * online. Return -ENODEV if channel-path is not registered. */
63 int chp_get_status(struct chp_id chpid)
65 return (chpid_to_chp(chpid) ? chpid_to_chp(chpid)->state : -ENODEV);
68 /**
69 * chp_get_sch_opm - return opm for subchannel
70 * @sch: subchannel
72 * Calculate and return the operational path mask (opm) based on the chpids
73 * used by the subchannel and the status of the associated channel-paths.
75 u8 chp_get_sch_opm(struct subchannel *sch)
77 struct chp_id chpid;
78 int opm;
79 int i;
81 opm = 0;
82 chp_id_init(&chpid);
83 for (i = 0; i < 8; i++) {
84 opm <<= 1;
85 chpid.id = sch->schib.pmcw.chpid[i];
86 if (chp_get_status(chpid) != 0)
87 opm |= 1;
89 return opm;
91 EXPORT_SYMBOL_GPL(chp_get_sch_opm);
93 /**
94 * chp_is_registered - check if a channel-path is registered
95 * @chpid: channel-path ID
97 * Return non-zero if a channel-path with the given chpid is registered,
98 * zero otherwise.
100 int chp_is_registered(struct chp_id chpid)
102 return chpid_to_chp(chpid) != NULL;
106 * Function: s390_vary_chpid
107 * Varies the specified chpid online or offline
109 static int s390_vary_chpid(struct chp_id chpid, int on)
111 char dbf_text[15];
112 int status;
114 sprintf(dbf_text, on?"varyon%x.%02x":"varyoff%x.%02x", chpid.cssid,
115 chpid.id);
116 CIO_TRACE_EVENT(2, dbf_text);
118 status = chp_get_status(chpid);
119 if (!on && !status)
120 return 0;
122 set_chp_logically_online(chpid, on);
123 chsc_chp_vary(chpid, on);
124 return 0;
128 * Channel measurement related functions
130 static ssize_t measurement_chars_read(struct file *filp, struct kobject *kobj,
131 struct bin_attribute *bin_attr,
132 char *buf, loff_t off, size_t count)
134 struct channel_path *chp;
135 struct device *device;
137 device = kobj_to_dev(kobj);
138 chp = to_channelpath(device);
139 if (chp->cmg == -1)
140 return 0;
142 return memory_read_from_buffer(buf, count, &off, &chp->cmg_chars,
143 sizeof(chp->cmg_chars));
145 static BIN_ATTR_ADMIN_RO(measurement_chars, sizeof(struct cmg_chars));
147 static ssize_t measurement_chars_full_read(struct file *filp,
148 struct kobject *kobj,
149 struct bin_attribute *bin_attr,
150 char *buf, loff_t off, size_t count)
152 struct channel_path *chp = to_channelpath(kobj_to_dev(kobj));
154 return memory_read_from_buffer(buf, count, &off, &chp->cmcb,
155 sizeof(chp->cmcb));
157 static BIN_ATTR_ADMIN_RO(measurement_chars_full, sizeof(struct cmg_cmcb));
159 static ssize_t chp_measurement_copy_block(void *buf, loff_t off, size_t count,
160 struct kobject *kobj, bool extended)
162 struct channel_path *chp;
163 struct channel_subsystem *css;
164 struct device *device;
165 unsigned int size;
166 void *area, *entry;
167 int id, idx;
169 device = kobj_to_dev(kobj);
170 chp = to_channelpath(device);
171 css = to_css(chp->dev.parent);
172 id = chp->chpid.id;
174 if (extended) {
175 /* Check if extended measurement data is available. */
176 if (!chp->extended)
177 return 0;
179 size = sizeof(struct cmg_ext_entry);
180 area = css->ecub[id / CSS_ECUES_PER_PAGE];
181 idx = id % CSS_ECUES_PER_PAGE;
182 } else {
183 size = sizeof(struct cmg_entry);
184 area = css->cub[id / CSS_CUES_PER_PAGE];
185 idx = id % CSS_CUES_PER_PAGE;
187 entry = area + (idx * size);
189 /* Only allow single reads. */
190 if (off || count < size)
191 return 0;
193 memcpy(buf, entry, size);
195 return size;
198 static ssize_t measurement_read(struct file *filp, struct kobject *kobj,
199 struct bin_attribute *bin_attr,
200 char *buf, loff_t off, size_t count)
202 return chp_measurement_copy_block(buf, off, count, kobj, false);
204 static BIN_ATTR_ADMIN_RO(measurement, sizeof(struct cmg_entry));
206 static ssize_t ext_measurement_read(struct file *filp, struct kobject *kobj,
207 struct bin_attribute *bin_attr,
208 char *buf, loff_t off, size_t count)
210 return chp_measurement_copy_block(buf, off, count, kobj, true);
212 static BIN_ATTR_ADMIN_RO(ext_measurement, sizeof(struct cmg_ext_entry));
214 static struct bin_attribute *measurement_attrs[] = {
215 &bin_attr_measurement_chars,
216 &bin_attr_measurement_chars_full,
217 &bin_attr_measurement,
218 &bin_attr_ext_measurement,
219 NULL,
221 BIN_ATTRIBUTE_GROUPS(measurement);
223 void chp_remove_cmg_attr(struct channel_path *chp)
225 device_remove_groups(&chp->dev, measurement_groups);
228 int chp_add_cmg_attr(struct channel_path *chp)
230 return device_add_groups(&chp->dev, measurement_groups);
234 * Files for the channel path entries.
236 static ssize_t chp_status_show(struct device *dev,
237 struct device_attribute *attr, char *buf)
239 struct channel_path *chp = to_channelpath(dev);
240 int status;
242 mutex_lock(&chp->lock);
243 status = chp->state;
244 mutex_unlock(&chp->lock);
246 return status ? sysfs_emit(buf, "online\n") : sysfs_emit(buf, "offline\n");
249 static ssize_t chp_status_write(struct device *dev,
250 struct device_attribute *attr,
251 const char *buf, size_t count)
253 struct channel_path *cp = to_channelpath(dev);
254 char cmd[10];
255 int num_args;
256 int error;
258 num_args = sscanf(buf, "%5s", cmd);
259 if (!num_args)
260 return count;
262 /* Wait until previous actions have settled. */
263 css_wait_for_slow_path();
265 if (!strncasecmp(cmd, "on", 2) || !strcmp(cmd, "1")) {
266 mutex_lock(&cp->lock);
267 error = s390_vary_chpid(cp->chpid, 1);
268 mutex_unlock(&cp->lock);
269 } else if (!strncasecmp(cmd, "off", 3) || !strcmp(cmd, "0")) {
270 mutex_lock(&cp->lock);
271 error = s390_vary_chpid(cp->chpid, 0);
272 mutex_unlock(&cp->lock);
273 } else
274 error = -EINVAL;
276 return error < 0 ? error : count;
279 static DEVICE_ATTR(status, 0644, chp_status_show, chp_status_write);
281 static ssize_t chp_configure_show(struct device *dev,
282 struct device_attribute *attr, char *buf)
284 struct channel_path *cp;
285 int status;
287 cp = to_channelpath(dev);
288 status = chp_info_get_status(cp->chpid);
289 if (status < 0)
290 return status;
292 return sysfs_emit(buf, "%d\n", status);
295 static int cfg_wait_idle(void);
297 static ssize_t chp_configure_write(struct device *dev,
298 struct device_attribute *attr,
299 const char *buf, size_t count)
301 struct channel_path *cp;
302 int val;
303 char delim;
305 if (sscanf(buf, "%d %c", &val, &delim) != 1)
306 return -EINVAL;
307 if (val != 0 && val != 1)
308 return -EINVAL;
309 cp = to_channelpath(dev);
310 chp_cfg_schedule(cp->chpid, val);
311 cfg_wait_idle();
313 return count;
316 static DEVICE_ATTR(configure, 0644, chp_configure_show, chp_configure_write);
318 static ssize_t chp_type_show(struct device *dev, struct device_attribute *attr,
319 char *buf)
321 struct channel_path *chp = to_channelpath(dev);
322 u8 type;
324 mutex_lock(&chp->lock);
325 type = chp->desc.desc;
326 mutex_unlock(&chp->lock);
327 return sysfs_emit(buf, "%x\n", type);
330 static DEVICE_ATTR(type, 0444, chp_type_show, NULL);
332 static ssize_t chp_cmg_show(struct device *dev, struct device_attribute *attr,
333 char *buf)
335 struct channel_path *chp = to_channelpath(dev);
337 if (!chp)
338 return 0;
339 if (chp->cmg == -1) /* channel measurements not available */
340 return sysfs_emit(buf, "unknown\n");
341 return sysfs_emit(buf, "%d\n", chp->cmg);
344 static DEVICE_ATTR(cmg, 0444, chp_cmg_show, NULL);
346 static ssize_t chp_shared_show(struct device *dev,
347 struct device_attribute *attr, char *buf)
349 struct channel_path *chp = to_channelpath(dev);
351 if (!chp)
352 return 0;
353 if (chp->shared == -1) /* channel measurements not available */
354 return sysfs_emit(buf, "unknown\n");
355 return sysfs_emit(buf, "%x\n", chp->shared);
358 static DEVICE_ATTR(shared, 0444, chp_shared_show, NULL);
360 static ssize_t chp_chid_show(struct device *dev, struct device_attribute *attr,
361 char *buf)
363 struct channel_path *chp = to_channelpath(dev);
364 ssize_t rc;
366 mutex_lock(&chp->lock);
367 if (chp->desc_fmt1.flags & 0x10)
368 rc = sysfs_emit(buf, "%04x\n", chp->desc_fmt1.chid);
369 else
370 rc = 0;
371 mutex_unlock(&chp->lock);
373 return rc;
375 static DEVICE_ATTR(chid, 0444, chp_chid_show, NULL);
377 static ssize_t chp_chid_external_show(struct device *dev,
378 struct device_attribute *attr, char *buf)
380 struct channel_path *chp = to_channelpath(dev);
381 ssize_t rc;
383 mutex_lock(&chp->lock);
384 if (chp->desc_fmt1.flags & 0x10)
385 rc = sysfs_emit(buf, "%x\n", chp->desc_fmt1.flags & 0x8 ? 1 : 0);
386 else
387 rc = 0;
388 mutex_unlock(&chp->lock);
390 return rc;
392 static DEVICE_ATTR(chid_external, 0444, chp_chid_external_show, NULL);
394 static ssize_t chp_esc_show(struct device *dev,
395 struct device_attribute *attr, char *buf)
397 struct channel_path *chp = to_channelpath(dev);
398 ssize_t rc;
400 mutex_lock(&chp->lock);
401 rc = sysfs_emit(buf, "%x\n", chp->desc_fmt1.esc);
402 mutex_unlock(&chp->lock);
404 return rc;
406 static DEVICE_ATTR(esc, 0444, chp_esc_show, NULL);
408 static char apply_max_suffix(unsigned long *value, unsigned long base)
410 static char suffixes[] = { 0, 'K', 'M', 'G', 'T' };
411 int i;
413 for (i = 0; i < ARRAY_SIZE(suffixes) - 1; i++) {
414 if (*value < base || *value % base != 0)
415 break;
416 *value /= base;
419 return suffixes[i];
422 static ssize_t speed_bps_show(struct device *dev,
423 struct device_attribute *attr, char *buf)
425 struct channel_path *chp = to_channelpath(dev);
426 unsigned long speed = chp->speed;
427 char suffix;
429 suffix = apply_max_suffix(&speed, 1000);
431 return suffix ? sysfs_emit(buf, "%lu%c\n", speed, suffix) :
432 sysfs_emit(buf, "%lu\n", speed);
435 static DEVICE_ATTR_RO(speed_bps);
437 static ssize_t util_string_read(struct file *filp, struct kobject *kobj,
438 struct bin_attribute *attr, char *buf,
439 loff_t off, size_t count)
441 struct channel_path *chp = to_channelpath(kobj_to_dev(kobj));
442 ssize_t rc;
444 mutex_lock(&chp->lock);
445 rc = memory_read_from_buffer(buf, count, &off, chp->desc_fmt3.util_str,
446 sizeof(chp->desc_fmt3.util_str));
447 mutex_unlock(&chp->lock);
449 return rc;
451 static BIN_ATTR_RO(util_string,
452 sizeof(((struct channel_path_desc_fmt3 *)0)->util_str));
454 static struct bin_attribute *chp_bin_attrs[] = {
455 &bin_attr_util_string,
456 NULL,
459 static struct attribute *chp_attrs[] = {
460 &dev_attr_status.attr,
461 &dev_attr_configure.attr,
462 &dev_attr_type.attr,
463 &dev_attr_cmg.attr,
464 &dev_attr_shared.attr,
465 &dev_attr_chid.attr,
466 &dev_attr_chid_external.attr,
467 &dev_attr_esc.attr,
468 &dev_attr_speed_bps.attr,
469 NULL,
471 static struct attribute_group chp_attr_group = {
472 .attrs = chp_attrs,
473 .bin_attrs = chp_bin_attrs,
475 static const struct attribute_group *chp_attr_groups[] = {
476 &chp_attr_group,
477 NULL,
480 static void chp_release(struct device *dev)
482 struct channel_path *cp;
484 cp = to_channelpath(dev);
485 kfree(cp);
489 * chp_update_desc - update channel-path description
490 * @chp: channel-path
492 * Update the channel-path description of the specified channel-path
493 * including channel measurement related information.
494 * Return zero on success, non-zero otherwise.
496 int chp_update_desc(struct channel_path *chp)
498 int rc;
500 rc = chsc_determine_fmt0_channel_path_desc(chp->chpid, &chp->desc);
501 if (rc)
502 return rc;
505 * Fetching the following data is optional. Not all machines or
506 * hypervisors implement the required chsc commands.
508 chsc_determine_fmt1_channel_path_desc(chp->chpid, &chp->desc_fmt1);
509 chsc_determine_fmt3_channel_path_desc(chp->chpid, &chp->desc_fmt3);
510 chsc_get_channel_measurement_chars(chp);
512 return 0;
516 * chp_new - register a new channel-path
517 * @chpid: channel-path ID
519 * Create and register data structure representing new channel-path. Return
520 * zero on success, non-zero otherwise.
522 int chp_new(struct chp_id chpid)
524 struct channel_subsystem *css = css_by_id(chpid.cssid);
525 struct channel_path *chp;
526 int ret = 0;
528 mutex_lock(&css->mutex);
529 if (chp_is_registered(chpid))
530 goto out;
532 chp = kzalloc(sizeof(struct channel_path), GFP_KERNEL);
533 if (!chp) {
534 ret = -ENOMEM;
535 goto out;
537 /* fill in status, etc. */
538 chp->chpid = chpid;
539 chp->state = 1;
540 chp->dev.parent = &css->device;
541 chp->dev.groups = chp_attr_groups;
542 chp->dev.release = chp_release;
543 mutex_init(&chp->lock);
545 /* Obtain channel path description and fill it in. */
546 ret = chp_update_desc(chp);
547 if (ret)
548 goto out_free;
549 if ((chp->desc.flags & 0x80) == 0) {
550 ret = -ENODEV;
551 goto out_free;
553 dev_set_name(&chp->dev, "chp%x.%02x", chpid.cssid, chpid.id);
555 /* make it known to the system */
556 ret = device_register(&chp->dev);
557 if (ret) {
558 CIO_MSG_EVENT(0, "Could not register chp%x.%02x: %d\n",
559 chpid.cssid, chpid.id, ret);
560 put_device(&chp->dev);
561 goto out;
564 if (css->cm_enabled) {
565 ret = chp_add_cmg_attr(chp);
566 if (ret) {
567 device_unregister(&chp->dev);
568 goto out;
571 css->chps[chpid.id] = chp;
572 goto out;
573 out_free:
574 kfree(chp);
575 out:
576 mutex_unlock(&css->mutex);
577 return ret;
581 * chp_get_chp_desc - return newly allocated channel-path description
582 * @chpid: channel-path ID
584 * On success return a newly allocated copy of the channel-path description
585 * data associated with the given channel-path ID. Return %NULL on error.
587 struct channel_path_desc_fmt0 *chp_get_chp_desc(struct chp_id chpid)
589 struct channel_path *chp;
590 struct channel_path_desc_fmt0 *desc;
592 chp = chpid_to_chp(chpid);
593 if (!chp)
594 return NULL;
595 desc = kmalloc(sizeof(*desc), GFP_KERNEL);
596 if (!desc)
597 return NULL;
599 mutex_lock(&chp->lock);
600 memcpy(desc, &chp->desc, sizeof(*desc));
601 mutex_unlock(&chp->lock);
602 return desc;
606 * chp_process_crw - process channel-path status change
607 * @crw0: channel report-word to handler
608 * @crw1: second channel-report word (always NULL)
609 * @overflow: crw overflow indication
611 * Handle channel-report-words indicating that the status of a channel-path
612 * has changed.
614 static void chp_process_crw(struct crw *crw0, struct crw *crw1,
615 int overflow)
617 struct chp_id chpid;
619 if (overflow) {
620 css_schedule_eval_all();
621 return;
623 CIO_CRW_EVENT(2, "CRW reports slct=%d, oflw=%d, "
624 "chn=%d, rsc=%X, anc=%d, erc=%X, rsid=%X\n",
625 crw0->slct, crw0->oflw, crw0->chn, crw0->rsc, crw0->anc,
626 crw0->erc, crw0->rsid);
628 * Check for solicited machine checks. These are
629 * created by reset channel path and need not be
630 * handled here.
632 if (crw0->slct) {
633 CIO_CRW_EVENT(2, "solicited machine check for "
634 "channel path %02X\n", crw0->rsid);
635 return;
637 chp_id_init(&chpid);
638 chpid.id = crw0->rsid;
639 switch (crw0->erc) {
640 case CRW_ERC_IPARM: /* Path has come. */
641 case CRW_ERC_INIT:
642 chp_new(chpid);
643 chsc_chp_online(chpid);
644 break;
645 case CRW_ERC_PERRI: /* Path has gone. */
646 case CRW_ERC_PERRN:
647 chsc_chp_offline(chpid);
648 break;
649 default:
650 CIO_CRW_EVENT(2, "Don't know how to handle erc=%x\n",
651 crw0->erc);
655 int chp_ssd_get_mask(struct chsc_ssd_info *ssd, struct chp_link *link)
657 int i;
658 int mask;
660 for (i = 0; i < 8; i++) {
661 mask = 0x80 >> i;
662 if (!(ssd->path_mask & mask))
663 continue;
664 if (!chp_id_is_equal(&ssd->chpid[i], &link->chpid))
665 continue;
666 if ((ssd->fla_valid_mask & mask) &&
667 ((ssd->fla[i] & link->fla_mask) != link->fla))
668 continue;
669 return mask;
671 return 0;
673 EXPORT_SYMBOL_GPL(chp_ssd_get_mask);
675 static inline int info_bit_num(struct chp_id id)
677 return id.id + id.cssid * (__MAX_CHPID + 1);
680 /* Force chp_info refresh on next call to info_validate(). */
681 static void info_expire(void)
683 mutex_lock(&info_lock);
684 chp_info_expires = jiffies - 1;
685 mutex_unlock(&info_lock);
688 /* Ensure that chp_info is up-to-date. */
689 static int info_update(void)
691 int rc;
693 mutex_lock(&info_lock);
694 rc = 0;
695 if (time_after(jiffies, chp_info_expires)) {
696 /* Data is too old, update. */
697 rc = sclp_chp_read_info(&chp_info);
698 chp_info_expires = jiffies + CHP_INFO_UPDATE_INTERVAL ;
700 mutex_unlock(&info_lock);
702 return rc;
706 * chp_info_get_status - retrieve configure status of a channel-path
707 * @chpid: channel-path ID
709 * On success, return 0 for standby, 1 for configured, 2 for reserved,
710 * 3 for not recognized. Return negative error code on error.
712 int chp_info_get_status(struct chp_id chpid)
714 int rc;
715 int bit;
717 rc = info_update();
718 if (rc)
719 return rc;
721 bit = info_bit_num(chpid);
722 mutex_lock(&info_lock);
723 if (!chp_test_bit(chp_info.recognized, bit))
724 rc = CHP_STATUS_NOT_RECOGNIZED;
725 else if (chp_test_bit(chp_info.configured, bit))
726 rc = CHP_STATUS_CONFIGURED;
727 else if (chp_test_bit(chp_info.standby, bit))
728 rc = CHP_STATUS_STANDBY;
729 else
730 rc = CHP_STATUS_RESERVED;
731 mutex_unlock(&info_lock);
733 return rc;
736 /* Return configure task for chpid. */
737 static enum cfg_task_t cfg_get_task(struct chp_id chpid)
739 return chp_cfg_task[chpid.cssid][chpid.id];
742 /* Set configure task for chpid. */
743 static void cfg_set_task(struct chp_id chpid, enum cfg_task_t cfg)
745 chp_cfg_task[chpid.cssid][chpid.id] = cfg;
748 /* Fetch the first configure task. Set chpid accordingly. */
749 static enum cfg_task_t chp_cfg_fetch_task(struct chp_id *chpid)
751 enum cfg_task_t t = cfg_none;
753 chp_id_for_each(chpid) {
754 t = cfg_get_task(*chpid);
755 if (t != cfg_none)
756 break;
759 return t;
762 /* Perform one configure/deconfigure request. Reschedule work function until
763 * last request. */
764 static void cfg_func(struct work_struct *work)
766 struct chp_id chpid;
767 enum cfg_task_t t;
768 int rc;
770 spin_lock(&cfg_lock);
771 t = chp_cfg_fetch_task(&chpid);
772 spin_unlock(&cfg_lock);
774 switch (t) {
775 case cfg_configure:
776 rc = sclp_chp_configure(chpid);
777 if (rc)
778 CIO_MSG_EVENT(2, "chp: sclp_chp_configure(%x.%02x)="
779 "%d\n", chpid.cssid, chpid.id, rc);
780 else {
781 info_expire();
782 chsc_chp_online(chpid);
784 break;
785 case cfg_deconfigure:
786 rc = sclp_chp_deconfigure(chpid);
787 if (rc)
788 CIO_MSG_EVENT(2, "chp: sclp_chp_deconfigure(%x.%02x)="
789 "%d\n", chpid.cssid, chpid.id, rc);
790 else {
791 info_expire();
792 chsc_chp_offline(chpid);
794 break;
795 case cfg_none:
796 /* Get updated information after last change. */
797 info_update();
798 wake_up_interruptible(&cfg_wait_queue);
799 return;
801 spin_lock(&cfg_lock);
802 if (t == cfg_get_task(chpid))
803 cfg_set_task(chpid, cfg_none);
804 spin_unlock(&cfg_lock);
805 schedule_work(&cfg_work);
809 * chp_cfg_schedule - schedule chpid configuration request
810 * @chpid: channel-path ID
811 * @configure: Non-zero for configure, zero for deconfigure
813 * Schedule a channel-path configuration/deconfiguration request.
815 void chp_cfg_schedule(struct chp_id chpid, int configure)
817 CIO_MSG_EVENT(2, "chp_cfg_sched%x.%02x=%d\n", chpid.cssid, chpid.id,
818 configure);
819 spin_lock(&cfg_lock);
820 cfg_set_task(chpid, configure ? cfg_configure : cfg_deconfigure);
821 spin_unlock(&cfg_lock);
822 schedule_work(&cfg_work);
826 * chp_cfg_cancel_deconfigure - cancel chpid deconfiguration request
827 * @chpid: channel-path ID
829 * Cancel an active channel-path deconfiguration request if it has not yet
830 * been performed.
832 void chp_cfg_cancel_deconfigure(struct chp_id chpid)
834 CIO_MSG_EVENT(2, "chp_cfg_cancel:%x.%02x\n", chpid.cssid, chpid.id);
835 spin_lock(&cfg_lock);
836 if (cfg_get_task(chpid) == cfg_deconfigure)
837 cfg_set_task(chpid, cfg_none);
838 spin_unlock(&cfg_lock);
841 static bool cfg_idle(void)
843 struct chp_id chpid;
844 enum cfg_task_t t;
846 spin_lock(&cfg_lock);
847 t = chp_cfg_fetch_task(&chpid);
848 spin_unlock(&cfg_lock);
850 return t == cfg_none;
853 static int cfg_wait_idle(void)
855 if (wait_event_interruptible(cfg_wait_queue, cfg_idle()))
856 return -ERESTARTSYS;
857 return 0;
860 static int __init chp_init(void)
862 struct chp_id chpid;
863 int state, ret;
865 ret = crw_register_handler(CRW_RSC_CPATH, chp_process_crw);
866 if (ret)
867 return ret;
868 INIT_WORK(&cfg_work, cfg_func);
869 if (info_update())
870 return 0;
871 /* Register available channel-paths. */
872 chp_id_for_each(&chpid) {
873 state = chp_info_get_status(chpid);
874 if (state == CHP_STATUS_CONFIGURED ||
875 state == CHP_STATUS_STANDBY)
876 chp_new(chpid);
879 return 0;
882 subsys_initcall(chp_init);