aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/s390/cio
diff options
context:
space:
mode:
authorPeter Oberparleiter <peter.oberparleiter@de.ibm.com>2007-04-27 10:01:31 -0400
committerMartin Schwidefsky <schwidefsky@de.ibm.com>2007-04-27 10:01:39 -0400
commite5854a5839fa426a7873f038080f63587de5f1f1 (patch)
treec0a3705df925e652ff0694a47e7acb98e5f7d7bd /drivers/s390/cio
parentf5ba6c863617c15d22cce5f8666ff4c832773025 (diff)
[S390] cio: Channel-path configure function.
Add a new attribute to the channel-path sysfs directory through which channel-path configure operations can be triggered. Also listen for hardware events requesting channel-path configure operations and process them accordingly. Signed-off-by: Peter Oberparleiter <peter.oberparleiter@de.ibm.com> Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com> Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>
Diffstat (limited to 'drivers/s390/cio')
-rw-r--r--drivers/s390/cio/chp.c250
-rw-r--r--drivers/s390/cio/chp.h20
-rw-r--r--drivers/s390/cio/chpid.h51
-rw-r--r--drivers/s390/cio/chsc.c44
-rw-r--r--drivers/s390/cio/chsc.h2
-rw-r--r--drivers/s390/cio/cio.c1
-rw-r--r--drivers/s390/cio/cio.h1
-rw-r--r--drivers/s390/cio/css.h4
-rw-r--r--drivers/s390/cio/device_fsm.c2
-rw-r--r--drivers/s390/cio/device_ops.c2
-rw-r--r--drivers/s390/cio/ioasm.h2
11 files changed, 318 insertions, 61 deletions
diff --git a/drivers/s390/cio/chp.c b/drivers/s390/cio/chp.c
index 8a5839147f8a..0e92c8c89860 100644
--- a/drivers/s390/cio/chp.c
+++ b/drivers/s390/cio/chp.c
@@ -10,9 +10,14 @@
10#include <linux/bug.h> 10#include <linux/bug.h>
11#include <linux/workqueue.h> 11#include <linux/workqueue.h>
12#include <linux/spinlock.h> 12#include <linux/spinlock.h>
13#include <linux/init.h>
14#include <linux/jiffies.h>
15#include <linux/wait.h>
16#include <linux/mutex.h>
13#include <asm/errno.h> 17#include <asm/errno.h>
18#include <asm/chpid.h>
19#include <asm/sclp.h>
14 20
15#include "chpid.h"
16#include "cio.h" 21#include "cio.h"
17#include "css.h" 22#include "css.h"
18#include "ioasm.h" 23#include "ioasm.h"
@@ -20,6 +25,32 @@
20#include "chp.h" 25#include "chp.h"
21 26
22#define to_channelpath(device) container_of(device, struct channel_path, dev) 27#define to_channelpath(device) container_of(device, struct channel_path, dev)
28#define CHP_INFO_UPDATE_INTERVAL 1*HZ
29
30enum cfg_task_t {
31 cfg_none,
32 cfg_configure,
33 cfg_deconfigure
34};
35
36/* Map for pending configure tasks. */
37static enum cfg_task_t chp_cfg_task[__MAX_CSSID + 1][__MAX_CHPID + 1];
38static DEFINE_MUTEX(cfg_lock);
39static int cfg_busy;
40
41/* Map for channel-path status. */
42static struct sclp_chp_info chp_info;
43static DEFINE_MUTEX(info_lock);
44
45/* Time after which channel-path status may be outdated. */
46static unsigned long chp_info_expires;
47
48/* Workqueue to perform pending configure tasks. */
49static struct workqueue_struct *chp_wq;
50static struct work_struct cfg_work;
51
52/* Wait queue for configure completion events. */
53static wait_queue_head_t cfg_wait_queue;
23 54
24/* Return channel_path struct for given chpid. */ 55/* Return channel_path struct for given chpid. */
25static inline struct channel_path *chpid_to_chp(struct chp_id chpid) 56static inline struct channel_path *chpid_to_chp(struct chp_id chpid)
@@ -251,6 +282,43 @@ static ssize_t chp_status_write(struct device *dev,
251 282
252static DEVICE_ATTR(status, 0644, chp_status_show, chp_status_write); 283static DEVICE_ATTR(status, 0644, chp_status_show, chp_status_write);
253 284
285static ssize_t chp_configure_show(struct device *dev,
286 struct device_attribute *attr, char *buf)
287{
288 struct channel_path *cp;
289 int status;
290
291 cp = container_of(dev, struct channel_path, dev);
292 status = chp_info_get_status(cp->chpid);
293 if (status < 0)
294 return status;
295
296 return snprintf(buf, PAGE_SIZE, "%d\n", status);
297}
298
299static int cfg_wait_idle(void);
300
301static ssize_t chp_configure_write(struct device *dev,
302 struct device_attribute *attr,
303 const char *buf, size_t count)
304{
305 struct channel_path *cp;
306 int val;
307 char delim;
308
309 if (sscanf(buf, "%d %c", &val, &delim) != 1)
310 return -EINVAL;
311 if (val != 0 && val != 1)
312 return -EINVAL;
313 cp = container_of(dev, struct channel_path, dev);
314 chp_cfg_schedule(cp->chpid, val);
315 cfg_wait_idle();
316
317 return count;
318}
319
320static DEVICE_ATTR(configure, 0644, chp_configure_show, chp_configure_write);
321
254static ssize_t chp_type_show(struct device *dev, struct device_attribute *attr, 322static ssize_t chp_type_show(struct device *dev, struct device_attribute *attr,
255 char *buf) 323 char *buf)
256{ 324{
@@ -293,6 +361,7 @@ static DEVICE_ATTR(shared, 0444, chp_shared_show, NULL);
293 361
294static struct attribute * chp_attrs[] = { 362static struct attribute * chp_attrs[] = {
295 &dev_attr_status.attr, 363 &dev_attr_status.attr,
364 &dev_attr_configure.attr,
296 &dev_attr_type.attr, 365 &dev_attr_type.attr,
297 &dev_attr_cmg.attr, 366 &dev_attr_cmg.attr,
298 &dev_attr_shared.attr, 367 &dev_attr_shared.attr,
@@ -323,6 +392,8 @@ int chp_new(struct chp_id chpid)
323 struct channel_path *chp; 392 struct channel_path *chp;
324 int ret; 393 int ret;
325 394
395 if (chp_is_registered(chpid))
396 return 0;
326 chp = kzalloc(sizeof(struct channel_path), GFP_KERNEL); 397 chp = kzalloc(sizeof(struct channel_path), GFP_KERNEL);
327 if (!chp) 398 if (!chp)
328 return -ENOMEM; 399 return -ENOMEM;
@@ -435,3 +506,180 @@ int chp_process_crw(int id, int status)
435 return 0; 506 return 0;
436 } 507 }
437} 508}
509
510static inline int info_bit_num(struct chp_id id)
511{
512 return id.id + id.cssid * (__MAX_CHPID + 1);
513}
514
515/* Force chp_info refresh on next call to info_validate(). */
516static void info_expire(void)
517{
518 mutex_lock(&info_lock);
519 chp_info_expires = jiffies - 1;
520 mutex_unlock(&info_lock);
521}
522
523/* Ensure that chp_info is up-to-date. */
524static int info_update(void)
525{
526 int rc;
527
528 mutex_lock(&info_lock);
529 rc = 0;
530 if (time_after(jiffies, chp_info_expires)) {
531 /* Data is too old, update. */
532 rc = sclp_chp_read_info(&chp_info);
533 chp_info_expires = jiffies + CHP_INFO_UPDATE_INTERVAL ;
534 }
535 mutex_unlock(&info_lock);
536
537 return rc;
538}
539
540/**
541 * chp_info_get_status - retrieve configure status of a channel-path
542 * @chpid: channel-path ID
543 *
544 * On success, return 0 for standby, 1 for configured, 2 for reserved,
545 * 3 for not recognized. Return negative error code on error.
546 */
547int chp_info_get_status(struct chp_id chpid)
548{
549 int rc;
550 int bit;
551
552 rc = info_update();
553 if (rc)
554 return rc;
555
556 bit = info_bit_num(chpid);
557 mutex_lock(&info_lock);
558 if (!chp_test_bit(chp_info.recognized, bit))
559 rc = CHP_STATUS_NOT_RECOGNIZED;
560 else if (chp_test_bit(chp_info.configured, bit))
561 rc = CHP_STATUS_CONFIGURED;
562 else if (chp_test_bit(chp_info.standby, bit))
563 rc = CHP_STATUS_STANDBY;
564 else
565 rc = CHP_STATUS_RESERVED;
566 mutex_unlock(&info_lock);
567
568 return rc;
569}
570
571/* Return configure task for chpid. */
572static enum cfg_task_t cfg_get_task(struct chp_id chpid)
573{
574 return chp_cfg_task[chpid.cssid][chpid.id];
575}
576
577/* Set configure task for chpid. */
578static void cfg_set_task(struct chp_id chpid, enum cfg_task_t cfg)
579{
580 chp_cfg_task[chpid.cssid][chpid.id] = cfg;
581}
582
583/* Perform one configure/deconfigure request. Reschedule work function until
584 * last request. */
585static void cfg_func(struct work_struct *work)
586{
587 struct chp_id chpid;
588 enum cfg_task_t t;
589
590 mutex_lock(&cfg_lock);
591 t = cfg_none;
592 chp_id_for_each(&chpid) {
593 t = cfg_get_task(chpid);
594 if (t != cfg_none) {
595 cfg_set_task(chpid, cfg_none);
596 break;
597 }
598 }
599 mutex_unlock(&cfg_lock);
600
601 switch (t) {
602 case cfg_configure:
603 sclp_chp_configure(chpid);
604 info_expire();
605 chsc_chp_online(chpid);
606 break;
607 case cfg_deconfigure:
608 sclp_chp_deconfigure(chpid);
609 info_expire();
610 chsc_chp_offline(chpid);
611 break;
612 case cfg_none:
613 /* Get updated information after last change. */
614 info_update();
615 mutex_lock(&cfg_lock);
616 cfg_busy = 0;
617 mutex_unlock(&cfg_lock);
618 wake_up_interruptible(&cfg_wait_queue);
619 return;
620 }
621 queue_work(chp_wq, &cfg_work);
622}
623
624/**
625 * chp_cfg_schedule - schedule chpid configuration request
626 * @chpid - channel-path ID
627 * @configure - Non-zero for configure, zero for deconfigure
628 *
629 * Schedule a channel-path configuration/deconfiguration request.
630 */
631void chp_cfg_schedule(struct chp_id chpid, int configure)
632{
633 CIO_MSG_EVENT(2, "chp_cfg_sched%x.%02x=%d\n", chpid.cssid, chpid.id,
634 configure);
635 mutex_lock(&cfg_lock);
636 cfg_set_task(chpid, configure ? cfg_configure : cfg_deconfigure);
637 cfg_busy = 1;
638 mutex_unlock(&cfg_lock);
639 queue_work(chp_wq, &cfg_work);
640}
641
642/**
643 * chp_cfg_cancel_deconfigure - cancel chpid deconfiguration request
644 * @chpid - channel-path ID
645 *
646 * Cancel an active channel-path deconfiguration request if it has not yet
647 * been performed.
648 */
649void chp_cfg_cancel_deconfigure(struct chp_id chpid)
650{
651 CIO_MSG_EVENT(2, "chp_cfg_cancel:%x.%02x\n", chpid.cssid, chpid.id);
652 mutex_lock(&cfg_lock);
653 if (cfg_get_task(chpid) == cfg_deconfigure)
654 cfg_set_task(chpid, cfg_none);
655 mutex_unlock(&cfg_lock);
656}
657
658static int cfg_wait_idle(void)
659{
660 if (wait_event_interruptible(cfg_wait_queue, !cfg_busy))
661 return -ERESTARTSYS;
662 return 0;
663}
664
665static int __init chp_init(void)
666{
667 struct chp_id chpid;
668
669 chp_wq = create_singlethread_workqueue("cio_chp");
670 if (!chp_wq)
671 return -ENOMEM;
672 INIT_WORK(&cfg_work, cfg_func);
673 init_waitqueue_head(&cfg_wait_queue);
674 if (info_update())
675 return 0;
676 /* Register available channel-paths. */
677 chp_id_for_each(&chpid) {
678 if (chp_info_get_status(chpid) != CHP_STATUS_NOT_RECOGNIZED)
679 chp_new(chpid);
680 }
681
682 return 0;
683}
684
685subsys_initcall(chp_init);
diff --git a/drivers/s390/cio/chp.h b/drivers/s390/cio/chp.h
index ac2b1a9c3bc2..862af69d9707 100644
--- a/drivers/s390/cio/chp.h
+++ b/drivers/s390/cio/chp.h
@@ -10,10 +10,23 @@
10 10
11#include <linux/types.h> 11#include <linux/types.h>
12#include <linux/device.h> 12#include <linux/device.h>
13 13#include <asm/chpid.h>
14#include "chpid.h"
15#include "chsc.h" 14#include "chsc.h"
16 15
16#define CHP_STATUS_STANDBY 0
17#define CHP_STATUS_CONFIGURED 1
18#define CHP_STATUS_RESERVED 2
19#define CHP_STATUS_NOT_RECOGNIZED 3
20
21static inline int chp_test_bit(u8 *bitmap, int num)
22{
23 int byte = num >> 3;
24 int mask = 128 >> (num & 7);
25
26 return (bitmap[byte] & mask) ? 1 : 0;
27}
28
29
17struct channel_path { 30struct channel_path {
18 struct chp_id chpid; 31 struct chp_id chpid;
19 int state; 32 int state;
@@ -33,5 +46,8 @@ int chp_process_crw(int id, int available);
33void chp_remove_cmg_attr(struct channel_path *chp); 46void chp_remove_cmg_attr(struct channel_path *chp);
34int chp_add_cmg_attr(struct channel_path *chp); 47int chp_add_cmg_attr(struct channel_path *chp);
35int chp_new(struct chp_id chpid); 48int chp_new(struct chp_id chpid);
49void chp_cfg_schedule(struct chp_id chpid, int configure);
50void chp_cfg_cancel_deconfigure(struct chp_id chpid);
51int chp_info_get_status(struct chp_id chpid);
36 52
37#endif /* S390_CHP_H */ 53#endif /* S390_CHP_H */
diff --git a/drivers/s390/cio/chpid.h b/drivers/s390/cio/chpid.h
deleted file mode 100644
index 44cc00ed9b59..000000000000
--- a/drivers/s390/cio/chpid.h
+++ /dev/null
@@ -1,51 +0,0 @@
1/*
2 * drivers/s390/cio/chpid.h
3 *
4 * Copyright IBM Corp. 2007
5 * Author(s): Peter Oberparleiter <peter.oberparleiter@de.ibm.com>
6 */
7
8#ifndef S390_CHP_ID_H
9#define S390_CHP_ID_H S390_CHP_ID_H
10
11#include <linux/string.h>
12#include <asm/types.h>
13#include "css.h"
14
15struct chp_id {
16 u8 reserved1;
17 u8 cssid;
18 u8 reserved2;
19 u8 id;
20} __attribute__((packed));
21
22static inline void chp_id_init(struct chp_id *chpid)
23{
24 memset(chpid, 0, sizeof(struct chp_id));
25}
26
27static inline int chp_id_is_equal(struct chp_id *a, struct chp_id *b)
28{
29 return (a->id == b->id) && (a->cssid == b->cssid);
30}
31
32static inline void chp_id_next(struct chp_id *chpid)
33{
34 if (chpid->id < __MAX_CHPID)
35 chpid->id++;
36 else {
37 chpid->id = 0;
38 chpid->cssid++;
39 }
40}
41
42static inline int chp_id_is_valid(struct chp_id *chpid)
43{
44 return (chpid->cssid <= __MAX_CSSID);
45}
46
47
48#define chp_id_for_each(c) \
49 for (chp_id_init(c); chp_id_is_valid(c); chp_id_next(c))
50
51#endif /* S390_CHP_ID_H */
diff --git a/drivers/s390/cio/chsc.c b/drivers/s390/cio/chsc.c
index d99f525eac08..3dec460bba27 100644
--- a/drivers/s390/cio/chsc.c
+++ b/drivers/s390/cio/chsc.c
@@ -15,12 +15,12 @@
15#include <linux/device.h> 15#include <linux/device.h>
16 16
17#include <asm/cio.h> 17#include <asm/cio.h>
18#include <asm/chpid.h>
18 19
19#include "css.h" 20#include "css.h"
20#include "cio.h" 21#include "cio.h"
21#include "cio_debug.h" 22#include "cio_debug.h"
22#include "ioasm.h" 23#include "ioasm.h"
23#include "chpid.h"
24#include "chp.h" 24#include "chp.h"
25#include "chsc.h" 25#include "chsc.h"
26 26
@@ -498,6 +498,45 @@ static int chsc_process_sei_res_acc(struct chsc_sei_area *sei_area)
498 return rc; 498 return rc;
499} 499}
500 500
501struct chp_config_data {
502 u8 map[32];
503 u8 op;
504 u8 pc;
505};
506
507static int chsc_process_sei_chp_config(struct chsc_sei_area *sei_area)
508{
509 struct chp_config_data *data;
510 struct chp_id chpid;
511 int num;
512
513 CIO_CRW_EVENT(4, "chsc: channel-path-configuration notification\n");
514 if (sei_area->rs != 0)
515 return 0;
516 data = (struct chp_config_data *) &(sei_area->ccdf);
517 chp_id_init(&chpid);
518 for (num = 0; num <= __MAX_CHPID; num++) {
519 if (!chp_test_bit(data->map, num))
520 continue;
521 chpid.id = num;
522 printk(KERN_WARNING "cio: processing configure event %d for "
523 "chpid %x.%02x\n", data->op, chpid.cssid, chpid.id);
524 switch (data->op) {
525 case 0:
526 chp_cfg_schedule(chpid, 1);
527 break;
528 case 1:
529 chp_cfg_schedule(chpid, 0);
530 break;
531 case 2:
532 chp_cfg_cancel_deconfigure(chpid);
533 break;
534 }
535 }
536
537 return 0;
538}
539
501static int chsc_process_sei(struct chsc_sei_area *sei_area) 540static int chsc_process_sei(struct chsc_sei_area *sei_area)
502{ 541{
503 int rc; 542 int rc;
@@ -514,6 +553,9 @@ static int chsc_process_sei(struct chsc_sei_area *sei_area)
514 case 2: /* i/o resource accessibiliy */ 553 case 2: /* i/o resource accessibiliy */
515 rc = chsc_process_sei_res_acc(sei_area); 554 rc = chsc_process_sei_res_acc(sei_area);
516 break; 555 break;
556 case 8: /* channel-path-configuration notification */
557 rc = chsc_process_sei_chp_config(sei_area);
558 break;
517 default: /* other stuff */ 559 default: /* other stuff */
518 CIO_CRW_EVENT(4, "chsc: unhandled sei content code %d\n", 560 CIO_CRW_EVENT(4, "chsc: unhandled sei content code %d\n",
519 sei_area->cc); 561 sei_area->cc);
diff --git a/drivers/s390/cio/chsc.h b/drivers/s390/cio/chsc.h
index 0e40defc6087..322586f27cc0 100644
--- a/drivers/s390/cio/chsc.h
+++ b/drivers/s390/cio/chsc.h
@@ -3,7 +3,7 @@
3 3
4#include <linux/types.h> 4#include <linux/types.h>
5#include <linux/device.h> 5#include <linux/device.h>
6#include "chpid.h" 6#include <asm/chpid.h>
7 7
8#define CHSC_SDA_OC_MSS 0x2 8#define CHSC_SDA_OC_MSS 0x2
9 9
diff --git a/drivers/s390/cio/cio.c b/drivers/s390/cio/cio.c
index 7dd0649c95d1..ea1defba5693 100644
--- a/drivers/s390/cio/cio.c
+++ b/drivers/s390/cio/cio.c
@@ -22,6 +22,7 @@
22#include <asm/setup.h> 22#include <asm/setup.h>
23#include <asm/reset.h> 23#include <asm/reset.h>
24#include <asm/ipl.h> 24#include <asm/ipl.h>
25#include <asm/chpid.h>
25#include "airq.h" 26#include "airq.h"
26#include "cio.h" 27#include "cio.h"
27#include "css.h" 28#include "css.h"
diff --git a/drivers/s390/cio/cio.h b/drivers/s390/cio/cio.h
index 35154a210357..e62ab5c52863 100644
--- a/drivers/s390/cio/cio.h
+++ b/drivers/s390/cio/cio.h
@@ -3,6 +3,7 @@
3 3
4#include "schid.h" 4#include "schid.h"
5#include <linux/mutex.h> 5#include <linux/mutex.h>
6#include <linux/device.h>
6 7
7/* 8/*
8 * where we put the ssd info 9 * where we put the ssd info
diff --git a/drivers/s390/cio/css.h b/drivers/s390/cio/css.h
index 4319e1ced791..b2b1a265c602 100644
--- a/drivers/s390/cio/css.h
+++ b/drivers/s390/cio/css.h
@@ -5,8 +5,10 @@
5#include <linux/wait.h> 5#include <linux/wait.h>
6#include <linux/workqueue.h> 6#include <linux/workqueue.h>
7#include <linux/device.h> 7#include <linux/device.h>
8#include <linux/types.h>
8 9
9#include <asm/cio.h> 10#include <asm/cio.h>
11#include <asm/chpid.h>
10 12
11#include "schid.h" 13#include "schid.h"
12 14
@@ -149,8 +151,6 @@ extern void css_reiterate_subchannels(void);
149 151
150#define __MAX_SUBCHANNEL 65535 152#define __MAX_SUBCHANNEL 65535
151#define __MAX_SSID 3 153#define __MAX_SSID 3
152#define __MAX_CHPID 255
153#define __MAX_CSSID 0
154 154
155struct channel_subsystem { 155struct channel_subsystem {
156 u8 cssid; 156 u8 cssid;
diff --git a/drivers/s390/cio/device_fsm.c b/drivers/s390/cio/device_fsm.c
index db3d1b990f58..d6226881d0df 100644
--- a/drivers/s390/cio/device_fsm.c
+++ b/drivers/s390/cio/device_fsm.c
@@ -15,6 +15,7 @@
15 15
16#include <asm/ccwdev.h> 16#include <asm/ccwdev.h>
17#include <asm/cio.h> 17#include <asm/cio.h>
18#include <asm/chpid.h>
18 19
19#include "cio.h" 20#include "cio.h"
20#include "cio_debug.h" 21#include "cio_debug.h"
@@ -22,7 +23,6 @@
22#include "device.h" 23#include "device.h"
23#include "chsc.h" 24#include "chsc.h"
24#include "ioasm.h" 25#include "ioasm.h"
25#include "chpid.h"
26#include "chp.h" 26#include "chp.h"
27 27
28int 28int
diff --git a/drivers/s390/cio/device_ops.c b/drivers/s390/cio/device_ops.c
index d819ae2ee9ae..16f59fcb66b1 100644
--- a/drivers/s390/cio/device_ops.c
+++ b/drivers/s390/cio/device_ops.c
@@ -16,13 +16,13 @@
16 16
17#include <asm/ccwdev.h> 17#include <asm/ccwdev.h>
18#include <asm/idals.h> 18#include <asm/idals.h>
19#include <asm/chpid.h>
19 20
20#include "cio.h" 21#include "cio.h"
21#include "cio_debug.h" 22#include "cio_debug.h"
22#include "css.h" 23#include "css.h"
23#include "chsc.h" 24#include "chsc.h"
24#include "device.h" 25#include "device.h"
25#include "chpid.h"
26#include "chp.h" 26#include "chp.h"
27 27
28int ccw_device_set_options_mask(struct ccw_device *cdev, unsigned long flags) 28int ccw_device_set_options_mask(struct ccw_device *cdev, unsigned long flags)
diff --git a/drivers/s390/cio/ioasm.h b/drivers/s390/cio/ioasm.h
index 78c7db6daa84..7153dd959082 100644
--- a/drivers/s390/cio/ioasm.h
+++ b/drivers/s390/cio/ioasm.h
@@ -1,8 +1,8 @@
1#ifndef S390_CIO_IOASM_H 1#ifndef S390_CIO_IOASM_H
2#define S390_CIO_IOASM_H 2#define S390_CIO_IOASM_H
3 3
4#include <asm/chpid.h>
4#include "schid.h" 5#include "schid.h"
5#include "chpid.h"
6 6
7/* 7/*
8 * TPI info structure 8 * TPI info structure