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