blob: 121865385c057b3df143e1e8061d347347019993 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * S/390 common I/O routines -- channel subsystem call
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
Heiko Carstensa53c8fa2012-07-20 11:15:04 +02004 * Copyright IBM Corp. 1999, 2010
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 * Author(s): Ingo Adlung (adlung@de.ibm.com)
Cornelia Huck4ce3b302006-01-14 13:21:04 -08006 * Cornelia Huck (cornelia.huck@de.ibm.com)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 * Arnd Bergmann (arndb@de.ibm.com)
8 */
9
Michael Ernste6d5a422008-12-25 13:39:36 +010010#define KMSG_COMPONENT "cio"
11#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
12
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/slab.h>
15#include <linux/init.h>
16#include <linux/device.h>
17
18#include <asm/cio.h>
Peter Oberparleitere5854a52007-04-27 16:01:31 +020019#include <asm/chpid.h>
Cornelia Huck9d92a7e2008-07-14 09:59:05 +020020#include <asm/chsc.h>
Heiko Carstensf5daba12009-03-26 15:24:01 +010021#include <asm/crw.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022
23#include "css.h"
24#include "cio.h"
25#include "cio_debug.h"
26#include "ioasm.h"
Peter Oberparleitere6b6e102007-04-27 16:01:28 +020027#include "chp.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include "chsc.h"
29
Linus Torvalds1da177e2005-04-16 15:20:36 -070030static void *sei_page;
Sebastian Ott34196f82010-10-25 16:10:29 +020031static void *chsc_page;
32static DEFINE_SPINLOCK(chsc_page_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -070033
Cornelia Huckdae39842008-07-17 17:16:47 +020034/**
35 * chsc_error_from_response() - convert a chsc response to an error
36 * @response: chsc response code
37 *
38 * Returns an appropriate Linux error code for @response.
39 */
40int chsc_error_from_response(int response)
Cornelia Huckb9c9a212008-02-05 16:50:34 +010041{
42 switch (response) {
43 case 0x0001:
44 return 0;
45 case 0x0002:
46 case 0x0003:
47 case 0x0006:
48 case 0x0007:
49 case 0x0008:
50 case 0x000a:
Michael Ernstfd0457a2010-08-09 18:12:50 +020051 case 0x0104:
Cornelia Huckb9c9a212008-02-05 16:50:34 +010052 return -EINVAL;
53 case 0x0004:
54 return -EOPNOTSUPP;
Sebastian Ott184b08a2012-08-28 16:45:42 +020055 case 0x000b:
56 return -EBUSY;
57 case 0x0100:
58 case 0x0102:
59 return -ENOMEM;
Cornelia Huckb9c9a212008-02-05 16:50:34 +010060 default:
61 return -EIO;
62 }
63}
Cornelia Huckdae39842008-07-17 17:16:47 +020064EXPORT_SYMBOL_GPL(chsc_error_from_response);
Cornelia Huckb9c9a212008-02-05 16:50:34 +010065
Peter Oberparleiter7ad6a242007-04-27 16:01:35 +020066struct chsc_ssd_area {
67 struct chsc_header request;
68 u16 :10;
69 u16 ssid:2;
70 u16 :4;
71 u16 f_sch; /* first subchannel */
72 u16 :16;
73 u16 l_sch; /* last subchannel */
74 u32 :32;
75 struct chsc_header response;
76 u32 :32;
77 u8 sch_valid : 1;
78 u8 dev_valid : 1;
79 u8 st : 3; /* subchannel type */
80 u8 zeroes : 3;
81 u8 unit_addr; /* unit address */
82 u16 devno; /* device number */
83 u8 path_mask;
84 u8 fla_valid_mask;
85 u16 sch; /* subchannel */
86 u8 chpid[8]; /* chpids 0-7 */
87 u16 fla[8]; /* full link addresses 0-7 */
88} __attribute__ ((packed));
89
90int chsc_get_ssd_info(struct subchannel_id schid, struct chsc_ssd_info *ssd)
Linus Torvalds1da177e2005-04-16 15:20:36 -070091{
Peter Oberparleiter7ad6a242007-04-27 16:01:35 +020092 struct chsc_ssd_area *ssd_area;
93 int ccode;
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 int ret;
Peter Oberparleiter7ad6a242007-04-27 16:01:35 +020095 int i;
96 int mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -070097
Sebastian Ott34196f82010-10-25 16:10:29 +020098 spin_lock_irq(&chsc_page_lock);
99 memset(chsc_page, 0, PAGE_SIZE);
100 ssd_area = chsc_page;
Peter Oberparleiter7ad6a242007-04-27 16:01:35 +0200101 ssd_area->request.length = 0x0010;
102 ssd_area->request.code = 0x0004;
103 ssd_area->ssid = schid.ssid;
104 ssd_area->f_sch = schid.sch_no;
105 ssd_area->l_sch = schid.sch_no;
Peter Oberparleiterf86635f2007-04-27 16:01:26 +0200106
Peter Oberparleiter7ad6a242007-04-27 16:01:35 +0200107 ccode = chsc(ssd_area);
108 /* Check response. */
109 if (ccode > 0) {
110 ret = (ccode == 3) ? -ENODEV : -EBUSY;
Sebastian Ott34196f82010-10-25 16:10:29 +0200111 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 }
Cornelia Huckb9c9a212008-02-05 16:50:34 +0100113 ret = chsc_error_from_response(ssd_area->response.code);
114 if (ret != 0) {
Peter Oberparleiter7ad6a242007-04-27 16:01:35 +0200115 CIO_MSG_EVENT(2, "chsc: ssd failed for 0.%x.%04x (rc=%04x)\n",
116 schid.ssid, schid.sch_no,
117 ssd_area->response.code);
Sebastian Ott34196f82010-10-25 16:10:29 +0200118 goto out;
Peter Oberparleiter7ad6a242007-04-27 16:01:35 +0200119 }
120 if (!ssd_area->sch_valid) {
121 ret = -ENODEV;
Sebastian Ott34196f82010-10-25 16:10:29 +0200122 goto out;
Peter Oberparleiter7ad6a242007-04-27 16:01:35 +0200123 }
124 /* Copy data */
125 ret = 0;
126 memset(ssd, 0, sizeof(struct chsc_ssd_info));
Cornelia Huckb279a4f2008-01-26 14:10:45 +0100127 if ((ssd_area->st != SUBCHANNEL_TYPE_IO) &&
128 (ssd_area->st != SUBCHANNEL_TYPE_MSG))
Sebastian Ott34196f82010-10-25 16:10:29 +0200129 goto out;
Peter Oberparleiter7ad6a242007-04-27 16:01:35 +0200130 ssd->path_mask = ssd_area->path_mask;
131 ssd->fla_valid_mask = ssd_area->fla_valid_mask;
132 for (i = 0; i < 8; i++) {
133 mask = 0x80 >> i;
134 if (ssd_area->path_mask & mask) {
135 chp_id_init(&ssd->chpid[i]);
136 ssd->chpid[i].id = ssd_area->chpid[i];
137 }
138 if (ssd_area->fla_valid_mask & mask)
139 ssd->fla[i] = ssd_area->fla[i];
140 }
Sebastian Ott34196f82010-10-25 16:10:29 +0200141out:
142 spin_unlock_irq(&chsc_page_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 return ret;
144}
145
Peter Oberparleitere82a1562008-01-26 14:10:48 +0100146static int s390_subchannel_remove_chpid(struct subchannel *sch, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147{
Cornelia Huck2ec22982006-12-08 15:54:26 +0100148 spin_lock_irq(sch->lock);
Cornelia Huckc820de32008-07-14 09:58:45 +0200149 if (sch->driver && sch->driver->chp_event)
150 if (sch->driver->chp_event(sch, data, CHP_OFFLINE) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 goto out_unreg;
Cornelia Huck2ec22982006-12-08 15:54:26 +0100152 spin_unlock_irq(sch->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 return 0;
Stefan Bader387b7342007-04-27 16:01:33 +0200154
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155out_unreg:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 sch->lpm = 0;
Stefan Bader387b7342007-04-27 16:01:33 +0200157 spin_unlock_irq(sch->lock);
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200158 css_schedule_eval(sch->schid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 return 0;
160}
161
Peter Oberparleitere6b6e102007-04-27 16:01:28 +0200162void chsc_chp_offline(struct chp_id chpid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163{
164 char dbf_txt[15];
Cornelia Huck99611f82008-07-14 09:59:02 +0200165 struct chp_link link;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166
Peter Oberparleiterf86635f2007-04-27 16:01:26 +0200167 sprintf(dbf_txt, "chpr%x.%02x", chpid.cssid, chpid.id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 CIO_TRACE_EVENT(2, dbf_txt);
169
Peter Oberparleitere6b6e102007-04-27 16:01:28 +0200170 if (chp_get_status(chpid) <= 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 return;
Cornelia Huck99611f82008-07-14 09:59:02 +0200172 memset(&link, 0, sizeof(struct chp_link));
173 link.chpid = chpid;
Cornelia Huck22806dc2008-04-17 07:45:59 +0200174 /* Wait until previous actions have settled. */
175 css_wait_for_slow_path();
Cornelia Huck99611f82008-07-14 09:59:02 +0200176 for_each_subchannel_staged(s390_subchannel_remove_chpid, NULL, &link);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177}
178
Peter Oberparleitere82a1562008-01-26 14:10:48 +0100179static int s390_process_res_acc_new_sch(struct subchannel_id schid, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180{
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800181 struct schib schib;
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800182 /*
183 * We don't know the device yet, but since a path
184 * may be available now to the device we'll have
185 * to do recognition again.
186 * Since we don't have any idea about which chpid
187 * that beast may be on we'll have to do a stsch
188 * on all devices, grr...
189 */
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800190 if (stsch_err(schid, &schib))
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800191 /* We're through */
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200192 return -ENXIO;
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800193
194 /* Put it on the slow path. */
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200195 css_schedule_eval(schid);
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800196 return 0;
197}
198
Peter Oberparleitere82a1562008-01-26 14:10:48 +0100199static int __s390_process_res_acc(struct subchannel *sch, void *data)
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800200{
Cornelia Huck2ec22982006-12-08 15:54:26 +0100201 spin_lock_irq(sch->lock);
Cornelia Huckc820de32008-07-14 09:58:45 +0200202 if (sch->driver && sch->driver->chp_event)
203 sch->driver->chp_event(sch, data, CHP_ONLINE);
Cornelia Huck2ec22982006-12-08 15:54:26 +0100204 spin_unlock_irq(sch->lock);
Peter Oberparleitere82a1562008-01-26 14:10:48 +0100205
Peter Oberparleiterdd9963f2006-09-20 15:59:54 +0200206 return 0;
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800207}
208
Cornelia Huck99611f82008-07-14 09:59:02 +0200209static void s390_process_res_acc(struct chp_link *link)
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800210{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 char dbf_txt[15];
212
Cornelia Huck99611f82008-07-14 09:59:02 +0200213 sprintf(dbf_txt, "accpr%x.%02x", link->chpid.cssid,
214 link->chpid.id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 CIO_TRACE_EVENT( 2, dbf_txt);
Cornelia Huck99611f82008-07-14 09:59:02 +0200216 if (link->fla != 0) {
217 sprintf(dbf_txt, "fla%x", link->fla);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 CIO_TRACE_EVENT( 2, dbf_txt);
219 }
Cornelia Huck22806dc2008-04-17 07:45:59 +0200220 /* Wait until previous actions have settled. */
221 css_wait_for_slow_path();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 /*
223 * I/O resources may have become accessible.
224 * Scan through all subchannels that may be concerned and
225 * do a validation on those.
226 * The more information we have (info), the less scanning
227 * will we have to do.
228 */
Peter Oberparleitere82a1562008-01-26 14:10:48 +0100229 for_each_subchannel_staged(__s390_process_res_acc,
Cornelia Huck99611f82008-07-14 09:59:02 +0200230 s390_process_res_acc_new_sch, link);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231}
232
233static int
234__get_chpid_from_lir(void *data)
235{
236 struct lir {
237 u8 iq;
238 u8 ic;
239 u16 sci;
240 /* incident-node descriptor */
241 u32 indesc[28];
242 /* attached-node descriptor */
243 u32 andesc[28];
244 /* incident-specific information */
245 u32 isinfo[28];
Peter Oberparleiter0f008aa2007-02-05 21:17:40 +0100246 } __attribute__ ((packed)) *lir;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247
Cornelia Huck12975ae2006-10-11 15:31:47 +0200248 lir = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 if (!(lir->iq&0x80))
250 /* NULL link incident record */
251 return -EINVAL;
252 if (!(lir->indesc[0]&0xc0000000))
253 /* node descriptor not valid */
254 return -EINVAL;
255 if (!(lir->indesc[0]&0x10000000))
256 /* don't handle device-type nodes - FIXME */
257 return -EINVAL;
258 /* Byte 3 contains the chpid. Could also be CTCA, but we don't care */
259
260 return (u16) (lir->indesc[0]&0x000000ff);
261}
262
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100263struct chsc_sei_area {
264 struct chsc_header request;
265 u32 reserved1;
266 u32 reserved2;
267 u32 reserved3;
268 struct chsc_header response;
269 u32 reserved4;
270 u8 flags;
271 u8 vf; /* validity flags */
272 u8 rs; /* reporting source */
273 u8 cc; /* content code */
274 u16 fla; /* full link address */
275 u16 rsid; /* reporting source id */
276 u32 reserved5;
277 u32 reserved6;
278 u8 ccdf[4096 - 16 - 24]; /* content-code dependent field */
279 /* ccdf has to be big enough for a link-incident record */
280} __attribute__ ((packed));
281
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200282static void chsc_process_sei_link_incident(struct chsc_sei_area *sei_area)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283{
Peter Oberparleiterf86635f2007-04-27 16:01:26 +0200284 struct chp_id chpid;
285 int id;
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100286
287 CIO_CRW_EVENT(4, "chsc: link incident (rs=%02x, rs_id=%04x)\n",
288 sei_area->rs, sei_area->rsid);
289 if (sei_area->rs != 4)
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200290 return;
Peter Oberparleiterf86635f2007-04-27 16:01:26 +0200291 id = __get_chpid_from_lir(sei_area->ccdf);
292 if (id < 0)
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100293 CIO_CRW_EVENT(4, "chsc: link incident - invalid LIR\n");
Peter Oberparleiterf86635f2007-04-27 16:01:26 +0200294 else {
295 chp_id_init(&chpid);
296 chpid.id = id;
Peter Oberparleitere6b6e102007-04-27 16:01:28 +0200297 chsc_chp_offline(chpid);
Peter Oberparleiterf86635f2007-04-27 16:01:26 +0200298 }
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100299}
300
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200301static void chsc_process_sei_res_acc(struct chsc_sei_area *sei_area)
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100302{
Cornelia Huck99611f82008-07-14 09:59:02 +0200303 struct chp_link link;
Peter Oberparleiterf86635f2007-04-27 16:01:26 +0200304 struct chp_id chpid;
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100305 int status;
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100306
307 CIO_CRW_EVENT(4, "chsc: resource accessibility event (rs=%02x, "
308 "rs_id=%04x)\n", sei_area->rs, sei_area->rsid);
309 if (sei_area->rs != 4)
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200310 return;
Peter Oberparleiterf86635f2007-04-27 16:01:26 +0200311 chp_id_init(&chpid);
312 chpid.id = sei_area->rsid;
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100313 /* allocate a new channel path structure, if needed */
Peter Oberparleitere6b6e102007-04-27 16:01:28 +0200314 status = chp_get_status(chpid);
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100315 if (status < 0)
Peter Oberparleitere6b6e102007-04-27 16:01:28 +0200316 chp_new(chpid);
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100317 else if (!status)
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200318 return;
Cornelia Huck99611f82008-07-14 09:59:02 +0200319 memset(&link, 0, sizeof(struct chp_link));
320 link.chpid = chpid;
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100321 if ((sei_area->vf & 0xc0) != 0) {
Cornelia Huck99611f82008-07-14 09:59:02 +0200322 link.fla = sei_area->fla;
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100323 if ((sei_area->vf & 0xc0) == 0xc0)
324 /* full link address */
Cornelia Huck99611f82008-07-14 09:59:02 +0200325 link.fla_mask = 0xffff;
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100326 else
327 /* link address */
Cornelia Huck99611f82008-07-14 09:59:02 +0200328 link.fla_mask = 0xff00;
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100329 }
Cornelia Huck99611f82008-07-14 09:59:02 +0200330 s390_process_res_acc(&link);
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100331}
332
Sebastian Ottfca894ed2011-05-23 10:24:41 +0200333static void chsc_process_sei_chp_avail(struct chsc_sei_area *sei_area)
334{
335 struct channel_path *chp;
336 struct chp_id chpid;
337 u8 *data;
338 int num;
339
340 CIO_CRW_EVENT(4, "chsc: channel path availability information\n");
341 if (sei_area->rs != 0)
342 return;
343 data = sei_area->ccdf;
344 chp_id_init(&chpid);
345 for (num = 0; num <= __MAX_CHPID; num++) {
346 if (!chp_test_bit(data, num))
347 continue;
348 chpid.id = num;
349
350 CIO_CRW_EVENT(4, "Update information for channel path "
351 "%x.%02x\n", chpid.cssid, chpid.id);
352 chp = chpid_to_chp(chpid);
353 if (!chp) {
354 chp_new(chpid);
355 continue;
356 }
357 mutex_lock(&chp->lock);
358 chsc_determine_base_channel_path_desc(chpid, &chp->desc);
359 mutex_unlock(&chp->lock);
360 }
361}
362
Peter Oberparleitere5854a52007-04-27 16:01:31 +0200363struct chp_config_data {
364 u8 map[32];
365 u8 op;
366 u8 pc;
367};
368
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200369static void chsc_process_sei_chp_config(struct chsc_sei_area *sei_area)
Peter Oberparleitere5854a52007-04-27 16:01:31 +0200370{
371 struct chp_config_data *data;
372 struct chp_id chpid;
373 int num;
Michael Ernste6d5a422008-12-25 13:39:36 +0100374 char *events[3] = {"configure", "deconfigure", "cancel deconfigure"};
Peter Oberparleitere5854a52007-04-27 16:01:31 +0200375
376 CIO_CRW_EVENT(4, "chsc: channel-path-configuration notification\n");
377 if (sei_area->rs != 0)
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200378 return;
Peter Oberparleitere5854a52007-04-27 16:01:31 +0200379 data = (struct chp_config_data *) &(sei_area->ccdf);
380 chp_id_init(&chpid);
381 for (num = 0; num <= __MAX_CHPID; num++) {
382 if (!chp_test_bit(data->map, num))
383 continue;
384 chpid.id = num;
Michael Ernste6d5a422008-12-25 13:39:36 +0100385 pr_notice("Processing %s for channel path %x.%02x\n",
386 events[data->op], chpid.cssid, chpid.id);
Peter Oberparleitere5854a52007-04-27 16:01:31 +0200387 switch (data->op) {
388 case 0:
389 chp_cfg_schedule(chpid, 1);
390 break;
391 case 1:
392 chp_cfg_schedule(chpid, 0);
393 break;
394 case 2:
395 chp_cfg_cancel_deconfigure(chpid);
396 break;
397 }
398 }
Peter Oberparleitere5854a52007-04-27 16:01:31 +0200399}
400
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200401static void chsc_process_sei(struct chsc_sei_area *sei_area)
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100402{
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100403 /* Check if we might have lost some information. */
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200404 if (sei_area->flags & 0x40) {
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100405 CIO_CRW_EVENT(2, "chsc: event overflow\n");
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200406 css_schedule_eval_all();
407 }
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100408 /* which kind of information was stored? */
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100409 switch (sei_area->cc) {
410 case 1: /* link incident*/
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200411 chsc_process_sei_link_incident(sei_area);
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100412 break;
Sebastian Ottfca894ed2011-05-23 10:24:41 +0200413 case 2: /* i/o resource accessibility */
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200414 chsc_process_sei_res_acc(sei_area);
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100415 break;
Sebastian Ottfca894ed2011-05-23 10:24:41 +0200416 case 7: /* channel-path-availability information */
417 chsc_process_sei_chp_avail(sei_area);
418 break;
Peter Oberparleitere5854a52007-04-27 16:01:31 +0200419 case 8: /* channel-path-configuration notification */
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200420 chsc_process_sei_chp_config(sei_area);
Peter Oberparleitere5854a52007-04-27 16:01:31 +0200421 break;
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100422 default: /* other stuff */
423 CIO_CRW_EVENT(4, "chsc: unhandled sei content code %d\n",
424 sei_area->cc);
425 break;
426 }
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100427}
428
Cornelia Huckc1156182008-07-14 09:58:46 +0200429static void chsc_process_crw(struct crw *crw0, struct crw *crw1, int overflow)
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100430{
431 struct chsc_sei_area *sei_area;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432
Cornelia Huckc1156182008-07-14 09:58:46 +0200433 if (overflow) {
434 css_schedule_eval_all();
435 return;
436 }
437 CIO_CRW_EVENT(2, "CRW reports slct=%d, oflw=%d, "
438 "chn=%d, rsc=%X, anc=%d, erc=%X, rsid=%X\n",
439 crw0->slct, crw0->oflw, crw0->chn, crw0->rsc, crw0->anc,
440 crw0->erc, crw0->rsid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 if (!sei_page)
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200442 return;
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100443 /* Access to sei_page is serialized through machine check handler
444 * thread, so no need for locking. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 sei_area = sei_page;
446
Cornelia Huckc1156182008-07-14 09:58:46 +0200447 CIO_TRACE_EVENT(2, "prcss");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 do {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 memset(sei_area, 0, sizeof(*sei_area));
Cornelia Huck495a5b42006-03-24 03:15:14 -0800450 sei_area->request.length = 0x0010;
451 sei_area->request.code = 0x000e;
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100452 if (chsc(sei_area))
453 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100455 if (sei_area->response.code == 0x0001) {
456 CIO_CRW_EVENT(4, "chsc: sei successful\n");
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200457 chsc_process_sei(sei_area);
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100458 } else {
459 CIO_CRW_EVENT(2, "chsc: sei failed (rc=%04x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 sei_area->response.code);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 break;
462 }
463 } while (sei_area->flags & 0x80);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464}
465
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200466void chsc_chp_online(struct chp_id chpid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 char dbf_txt[15];
Cornelia Huck99611f82008-07-14 09:59:02 +0200469 struct chp_link link;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470
Peter Oberparleiterf86635f2007-04-27 16:01:26 +0200471 sprintf(dbf_txt, "cadd%x.%02x", chpid.cssid, chpid.id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 CIO_TRACE_EVENT(2, dbf_txt);
473
Cornelia Huck22806dc2008-04-17 07:45:59 +0200474 if (chp_get_status(chpid) != 0) {
Cornelia Huck99611f82008-07-14 09:59:02 +0200475 memset(&link, 0, sizeof(struct chp_link));
476 link.chpid = chpid;
Cornelia Huck22806dc2008-04-17 07:45:59 +0200477 /* Wait until previous actions have settled. */
478 css_wait_for_slow_path();
Cornelia Huckc820de32008-07-14 09:58:45 +0200479 for_each_subchannel_staged(__s390_process_res_acc, NULL,
Cornelia Huck99611f82008-07-14 09:59:02 +0200480 &link);
Cornelia Huck22806dc2008-04-17 07:45:59 +0200481 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482}
483
Peter Oberparleiterf86635f2007-04-27 16:01:26 +0200484static void __s390_subchannel_vary_chpid(struct subchannel *sch,
485 struct chp_id chpid, int on)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 unsigned long flags;
Cornelia Huck99611f82008-07-14 09:59:02 +0200488 struct chp_link link;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489
Cornelia Huck99611f82008-07-14 09:59:02 +0200490 memset(&link, 0, sizeof(struct chp_link));
491 link.chpid = chpid;
Cornelia Huck2ec22982006-12-08 15:54:26 +0100492 spin_lock_irqsave(sch->lock, flags);
Cornelia Huckc820de32008-07-14 09:58:45 +0200493 if (sch->driver && sch->driver->chp_event)
Cornelia Huck99611f82008-07-14 09:59:02 +0200494 sch->driver->chp_event(sch, &link,
Cornelia Huckc820de32008-07-14 09:58:45 +0200495 on ? CHP_VARY_ON : CHP_VARY_OFF);
Cornelia Huck2ec22982006-12-08 15:54:26 +0100496 spin_unlock_irqrestore(sch->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497}
498
Peter Oberparleitere82a1562008-01-26 14:10:48 +0100499static int s390_subchannel_vary_chpid_off(struct subchannel *sch, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500{
Peter Oberparleitere82a1562008-01-26 14:10:48 +0100501 struct chp_id *chpid = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502
503 __s390_subchannel_vary_chpid(sch, *chpid, 0);
504 return 0;
505}
506
Peter Oberparleitere82a1562008-01-26 14:10:48 +0100507static int s390_subchannel_vary_chpid_on(struct subchannel *sch, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508{
Peter Oberparleitere82a1562008-01-26 14:10:48 +0100509 struct chp_id *chpid = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510
511 __s390_subchannel_vary_chpid(sch, *chpid, 1);
512 return 0;
513}
514
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800515static int
516__s390_vary_chpid_on(struct subchannel_id schid, void *data)
517{
518 struct schib schib;
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800519
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800520 if (stsch_err(schid, &schib))
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800521 /* We're through */
522 return -ENXIO;
523 /* Put it on the slow path. */
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200524 css_schedule_eval(schid);
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800525 return 0;
526}
527
Peter Oberparleitere6b6e102007-04-27 16:01:28 +0200528/**
529 * chsc_chp_vary - propagate channel-path vary operation to subchannels
530 * @chpid: channl-path ID
531 * @on: non-zero for vary online, zero for vary offline
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 */
Peter Oberparleitere6b6e102007-04-27 16:01:28 +0200533int chsc_chp_vary(struct chp_id chpid, int on)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534{
Sebastian Ottc38a90a2010-10-25 16:10:31 +0200535 struct channel_path *chp = chpid_to_chp(chpid);
Cornelia Huck99611f82008-07-14 09:59:02 +0200536
Cornelia Huck22806dc2008-04-17 07:45:59 +0200537 /* Wait until previous actions have settled. */
538 css_wait_for_slow_path();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 /*
540 * Redo PathVerification on the devices the chpid connects to
541 */
Sebastian Ottc38a90a2010-10-25 16:10:31 +0200542 if (on) {
543 /* Try to update the channel path descritor. */
544 chsc_determine_base_channel_path_desc(chpid, &chp->desc);
Peter Oberparleitere82a1562008-01-26 14:10:48 +0100545 for_each_subchannel_staged(s390_subchannel_vary_chpid_on,
Sebastian Ott3b484ec2011-12-01 13:32:22 +0100546 __s390_vary_chpid_on, &chpid);
Sebastian Ottc38a90a2010-10-25 16:10:31 +0200547 } else
Peter Oberparleitere82a1562008-01-26 14:10:48 +0100548 for_each_subchannel_staged(s390_subchannel_vary_chpid_off,
Sebastian Ott3b484ec2011-12-01 13:32:22 +0100549 NULL, &chpid);
Peter Oberparleitere82a1562008-01-26 14:10:48 +0100550
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 return 0;
552}
553
Cornelia Huck495a5b42006-03-24 03:15:14 -0800554static void
555chsc_remove_cmg_attr(struct channel_subsystem *css)
556{
557 int i;
558
559 for (i = 0; i <= __MAX_CHPID; i++) {
560 if (!css->chps[i])
561 continue;
Peter Oberparleitere6b6e102007-04-27 16:01:28 +0200562 chp_remove_cmg_attr(css->chps[i]);
Cornelia Huck495a5b42006-03-24 03:15:14 -0800563 }
564}
565
566static int
567chsc_add_cmg_attr(struct channel_subsystem *css)
568{
569 int i, ret;
570
571 ret = 0;
572 for (i = 0; i <= __MAX_CHPID; i++) {
573 if (!css->chps[i])
574 continue;
Peter Oberparleitere6b6e102007-04-27 16:01:28 +0200575 ret = chp_add_cmg_attr(css->chps[i]);
Cornelia Huck495a5b42006-03-24 03:15:14 -0800576 if (ret)
577 goto cleanup;
578 }
579 return ret;
580cleanup:
581 for (--i; i >= 0; i--) {
582 if (!css->chps[i])
583 continue;
Peter Oberparleitere6b6e102007-04-27 16:01:28 +0200584 chp_remove_cmg_attr(css->chps[i]);
Cornelia Huck495a5b42006-03-24 03:15:14 -0800585 }
586 return ret;
587}
588
Sebastian Ott34196f82010-10-25 16:10:29 +0200589int __chsc_do_secm(struct channel_subsystem *css, int enable)
Cornelia Huck495a5b42006-03-24 03:15:14 -0800590{
591 struct {
592 struct chsc_header request;
593 u32 operation_code : 2;
594 u32 : 30;
595 u32 key : 4;
596 u32 : 28;
597 u32 zeroes1;
598 u32 cub_addr1;
599 u32 zeroes2;
600 u32 cub_addr2;
601 u32 reserved[13];
602 struct chsc_header response;
603 u32 status : 8;
604 u32 : 4;
605 u32 fmt : 4;
606 u32 : 16;
Peter Oberparleiter0f008aa2007-02-05 21:17:40 +0100607 } __attribute__ ((packed)) *secm_area;
Cornelia Huck495a5b42006-03-24 03:15:14 -0800608 int ret, ccode;
609
Sebastian Ott34196f82010-10-25 16:10:29 +0200610 spin_lock_irq(&chsc_page_lock);
611 memset(chsc_page, 0, PAGE_SIZE);
612 secm_area = chsc_page;
Cornelia Huck495a5b42006-03-24 03:15:14 -0800613 secm_area->request.length = 0x0050;
614 secm_area->request.code = 0x0016;
615
Heiko Carstensd1bf8592010-02-26 22:37:30 +0100616 secm_area->key = PAGE_DEFAULT_KEY >> 4;
Cornelia Huck495a5b42006-03-24 03:15:14 -0800617 secm_area->cub_addr1 = (u64)(unsigned long)css->cub_addr1;
618 secm_area->cub_addr2 = (u64)(unsigned long)css->cub_addr2;
619
620 secm_area->operation_code = enable ? 0 : 1;
621
622 ccode = chsc(secm_area);
Sebastian Ott34196f82010-10-25 16:10:29 +0200623 if (ccode > 0) {
624 ret = (ccode == 3) ? -ENODEV : -EBUSY;
625 goto out;
626 }
Cornelia Huck495a5b42006-03-24 03:15:14 -0800627
628 switch (secm_area->response.code) {
Cornelia Huckb9c9a212008-02-05 16:50:34 +0100629 case 0x0102:
630 case 0x0103:
Cornelia Huck495a5b42006-03-24 03:15:14 -0800631 ret = -EINVAL;
Sebastian Ott17e7d872009-03-26 15:24:17 +0100632 break;
Cornelia Huck495a5b42006-03-24 03:15:14 -0800633 default:
Cornelia Huckb9c9a212008-02-05 16:50:34 +0100634 ret = chsc_error_from_response(secm_area->response.code);
Cornelia Huck495a5b42006-03-24 03:15:14 -0800635 }
Cornelia Huckb9c9a212008-02-05 16:50:34 +0100636 if (ret != 0)
637 CIO_CRW_EVENT(2, "chsc: secm failed (rc=%04x)\n",
638 secm_area->response.code);
Sebastian Ott34196f82010-10-25 16:10:29 +0200639out:
640 spin_unlock_irq(&chsc_page_lock);
Cornelia Huck495a5b42006-03-24 03:15:14 -0800641 return ret;
642}
643
644int
645chsc_secm(struct channel_subsystem *css, int enable)
646{
Cornelia Huck495a5b42006-03-24 03:15:14 -0800647 int ret;
648
Cornelia Huck495a5b42006-03-24 03:15:14 -0800649 if (enable && !css->cm_enabled) {
650 css->cub_addr1 = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
651 css->cub_addr2 = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
652 if (!css->cub_addr1 || !css->cub_addr2) {
653 free_page((unsigned long)css->cub_addr1);
654 free_page((unsigned long)css->cub_addr2);
Cornelia Huck495a5b42006-03-24 03:15:14 -0800655 return -ENOMEM;
656 }
657 }
Sebastian Ott34196f82010-10-25 16:10:29 +0200658 ret = __chsc_do_secm(css, enable);
Cornelia Huck495a5b42006-03-24 03:15:14 -0800659 if (!ret) {
660 css->cm_enabled = enable;
661 if (css->cm_enabled) {
662 ret = chsc_add_cmg_attr(css);
663 if (ret) {
Sebastian Ott34196f82010-10-25 16:10:29 +0200664 __chsc_do_secm(css, 0);
Cornelia Huck495a5b42006-03-24 03:15:14 -0800665 css->cm_enabled = 0;
666 }
667 } else
668 chsc_remove_cmg_attr(css);
669 }
Cornelia Huck8c4941c2007-04-27 16:01:38 +0200670 if (!css->cm_enabled) {
Cornelia Huck495a5b42006-03-24 03:15:14 -0800671 free_page((unsigned long)css->cub_addr1);
672 free_page((unsigned long)css->cub_addr2);
673 }
Cornelia Huck495a5b42006-03-24 03:15:14 -0800674 return ret;
675}
676
Cornelia Huck9d92a7e2008-07-14 09:59:05 +0200677int chsc_determine_channel_path_desc(struct chp_id chpid, int fmt, int rfmt,
Sebastian Ott906c9762010-10-25 16:10:30 +0200678 int c, int m, void *page)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679{
Sebastian Ott906c9762010-10-25 16:10:30 +0200680 struct chsc_scpd *scpd_area;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 int ccode, ret;
682
Cornelia Huck9d92a7e2008-07-14 09:59:05 +0200683 if ((rfmt == 1) && !css_general_characteristics.fcs)
684 return -EINVAL;
685 if ((rfmt == 2) && !css_general_characteristics.cib)
686 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687
Sebastian Ott906c9762010-10-25 16:10:30 +0200688 memset(page, 0, PAGE_SIZE);
689 scpd_area = page;
Cornelia Huck495a5b42006-03-24 03:15:14 -0800690 scpd_area->request.length = 0x0010;
691 scpd_area->request.code = 0x0002;
Cornelia Huck9d92a7e2008-07-14 09:59:05 +0200692 scpd_area->cssid = chpid.cssid;
Peter Oberparleiterf86635f2007-04-27 16:01:26 +0200693 scpd_area->first_chpid = chpid.id;
694 scpd_area->last_chpid = chpid.id;
Cornelia Huck9d92a7e2008-07-14 09:59:05 +0200695 scpd_area->m = m;
696 scpd_area->c = c;
697 scpd_area->fmt = fmt;
698 scpd_area->rfmt = rfmt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699
700 ccode = chsc(scpd_area);
Sebastian Ott906c9762010-10-25 16:10:30 +0200701 if (ccode > 0)
702 return (ccode == 3) ? -ENODEV : -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703
Cornelia Huckb9c9a212008-02-05 16:50:34 +0100704 ret = chsc_error_from_response(scpd_area->response.code);
Sebastian Ott906c9762010-10-25 16:10:30 +0200705 if (ret)
Cornelia Huckb9c9a212008-02-05 16:50:34 +0100706 CIO_CRW_EVENT(2, "chsc: scpd failed (rc=%04x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 scpd_area->response.code);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 return ret;
709}
Cornelia Huck9d92a7e2008-07-14 09:59:05 +0200710EXPORT_SYMBOL_GPL(chsc_determine_channel_path_desc);
711
712int chsc_determine_base_channel_path_desc(struct chp_id chpid,
713 struct channel_path_desc *desc)
714{
715 struct chsc_response_struct *chsc_resp;
Sebastian Ott906c9762010-10-25 16:10:30 +0200716 struct chsc_scpd *scpd_area;
Sebastian Ott62da1772010-10-25 16:10:32 +0200717 unsigned long flags;
Cornelia Huck9d92a7e2008-07-14 09:59:05 +0200718 int ret;
719
Sebastian Ott62da1772010-10-25 16:10:32 +0200720 spin_lock_irqsave(&chsc_page_lock, flags);
Sebastian Ott906c9762010-10-25 16:10:30 +0200721 scpd_area = chsc_page;
722 ret = chsc_determine_channel_path_desc(chpid, 0, 0, 0, 0, scpd_area);
Cornelia Huck9d92a7e2008-07-14 09:59:05 +0200723 if (ret)
Sebastian Ott906c9762010-10-25 16:10:30 +0200724 goto out;
725 chsc_resp = (void *)&scpd_area->response;
Sebastian Ott878c4952010-07-19 09:22:37 +0200726 memcpy(desc, &chsc_resp->data, sizeof(*desc));
Sebastian Ott906c9762010-10-25 16:10:30 +0200727out:
Sebastian Ott62da1772010-10-25 16:10:32 +0200728 spin_unlock_irqrestore(&chsc_page_lock, flags);
Cornelia Huck9d92a7e2008-07-14 09:59:05 +0200729 return ret;
730}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731
Sebastian Ottce322cc2011-01-05 12:47:56 +0100732int chsc_determine_fmt1_channel_path_desc(struct chp_id chpid,
733 struct channel_path_desc_fmt1 *desc)
734{
735 struct chsc_response_struct *chsc_resp;
736 struct chsc_scpd *scpd_area;
737 int ret;
738
739 spin_lock_irq(&chsc_page_lock);
740 scpd_area = chsc_page;
741 ret = chsc_determine_channel_path_desc(chpid, 0, 0, 1, 0, scpd_area);
742 if (ret)
743 goto out;
744 chsc_resp = (void *)&scpd_area->response;
745 memcpy(desc, &chsc_resp->data, sizeof(*desc));
746out:
747 spin_unlock_irq(&chsc_page_lock);
748 return ret;
749}
750
Cornelia Huck495a5b42006-03-24 03:15:14 -0800751static void
752chsc_initialize_cmg_chars(struct channel_path *chp, u8 cmcv,
753 struct cmg_chars *chars)
754{
Sebastian Ott34196f82010-10-25 16:10:29 +0200755 struct cmg_chars *cmg_chars;
756 int i, mask;
Cornelia Huck495a5b42006-03-24 03:15:14 -0800757
Sebastian Ott34196f82010-10-25 16:10:29 +0200758 cmg_chars = chp->cmg_chars;
759 for (i = 0; i < NR_MEASUREMENT_CHARS; i++) {
760 mask = 0x80 >> (i + 3);
761 if (cmcv & mask)
762 cmg_chars->values[i] = chars->values[i];
763 else
764 cmg_chars->values[i] = 0;
Cornelia Huck495a5b42006-03-24 03:15:14 -0800765 }
766}
767
Peter Oberparleitere6b6e102007-04-27 16:01:28 +0200768int chsc_get_channel_measurement_chars(struct channel_path *chp)
Cornelia Huck495a5b42006-03-24 03:15:14 -0800769{
Sebastian Ott34196f82010-10-25 16:10:29 +0200770 struct cmg_chars *cmg_chars;
Cornelia Huck495a5b42006-03-24 03:15:14 -0800771 int ccode, ret;
772
773 struct {
774 struct chsc_header request;
775 u32 : 24;
776 u32 first_chpid : 8;
777 u32 : 24;
778 u32 last_chpid : 8;
779 u32 zeroes1;
780 struct chsc_header response;
781 u32 zeroes2;
782 u32 not_valid : 1;
783 u32 shared : 1;
784 u32 : 22;
785 u32 chpid : 8;
786 u32 cmcv : 5;
787 u32 : 11;
788 u32 cmgq : 8;
789 u32 cmg : 8;
790 u32 zeroes3;
791 u32 data[NR_MEASUREMENT_CHARS];
Peter Oberparleiter0f008aa2007-02-05 21:17:40 +0100792 } __attribute__ ((packed)) *scmc_area;
Cornelia Huck495a5b42006-03-24 03:15:14 -0800793
Sebastian Ott34196f82010-10-25 16:10:29 +0200794 chp->cmg_chars = NULL;
795 cmg_chars = kmalloc(sizeof(*cmg_chars), GFP_KERNEL);
796 if (!cmg_chars)
Cornelia Huck495a5b42006-03-24 03:15:14 -0800797 return -ENOMEM;
798
Sebastian Ott34196f82010-10-25 16:10:29 +0200799 spin_lock_irq(&chsc_page_lock);
800 memset(chsc_page, 0, PAGE_SIZE);
801 scmc_area = chsc_page;
Cornelia Huck495a5b42006-03-24 03:15:14 -0800802 scmc_area->request.length = 0x0010;
803 scmc_area->request.code = 0x0022;
Peter Oberparleiterf86635f2007-04-27 16:01:26 +0200804 scmc_area->first_chpid = chp->chpid.id;
805 scmc_area->last_chpid = chp->chpid.id;
Cornelia Huck495a5b42006-03-24 03:15:14 -0800806
807 ccode = chsc(scmc_area);
808 if (ccode > 0) {
809 ret = (ccode == 3) ? -ENODEV : -EBUSY;
810 goto out;
811 }
812
Cornelia Huckb9c9a212008-02-05 16:50:34 +0100813 ret = chsc_error_from_response(scmc_area->response.code);
Sebastian Ott34196f82010-10-25 16:10:29 +0200814 if (ret) {
Cornelia Huckb9c9a212008-02-05 16:50:34 +0100815 CIO_CRW_EVENT(2, "chsc: scmc failed (rc=%04x)\n",
Cornelia Huck495a5b42006-03-24 03:15:14 -0800816 scmc_area->response.code);
Sebastian Ott34196f82010-10-25 16:10:29 +0200817 goto out;
Cornelia Huck495a5b42006-03-24 03:15:14 -0800818 }
Sebastian Ott34196f82010-10-25 16:10:29 +0200819 if (scmc_area->not_valid) {
820 chp->cmg = -1;
821 chp->shared = -1;
822 goto out;
823 }
824 chp->cmg = scmc_area->cmg;
825 chp->shared = scmc_area->shared;
826 if (chp->cmg != 2 && chp->cmg != 3) {
827 /* No cmg-dependent data. */
828 goto out;
829 }
830 chp->cmg_chars = cmg_chars;
831 chsc_initialize_cmg_chars(chp, scmc_area->cmcv,
832 (struct cmg_chars *) &scmc_area->data);
Cornelia Huck495a5b42006-03-24 03:15:14 -0800833out:
Sebastian Ott34196f82010-10-25 16:10:29 +0200834 spin_unlock_irq(&chsc_page_lock);
835 if (!chp->cmg_chars)
836 kfree(cmg_chars);
837
Cornelia Huck495a5b42006-03-24 03:15:14 -0800838 return ret;
839}
840
Sebastian Ott34aec072010-10-25 16:10:28 +0200841int __init chsc_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842{
Cornelia Huckc1156182008-07-14 09:58:46 +0200843 int ret;
844
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845 sei_page = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
Sebastian Ott34196f82010-10-25 16:10:29 +0200846 chsc_page = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
847 if (!sei_page || !chsc_page) {
848 ret = -ENOMEM;
849 goto out_err;
Cornelia Huckc1156182008-07-14 09:58:46 +0200850 }
Heiko Carstensf5daba12009-03-26 15:24:01 +0100851 ret = crw_register_handler(CRW_RSC_CSS, chsc_process_crw);
Cornelia Huckc1156182008-07-14 09:58:46 +0200852 if (ret)
Sebastian Ott34196f82010-10-25 16:10:29 +0200853 goto out_err;
854 return ret;
855out_err:
856 free_page((unsigned long)chsc_page);
857 free_page((unsigned long)sei_page);
Cornelia Huckc1156182008-07-14 09:58:46 +0200858 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859}
860
Sebastian Ott34aec072010-10-25 16:10:28 +0200861void __init chsc_init_cleanup(void)
Cornelia Huck4434a382007-07-27 12:29:21 +0200862{
Heiko Carstensf5daba12009-03-26 15:24:01 +0100863 crw_unregister_handler(CRW_RSC_CSS);
Sebastian Ott34196f82010-10-25 16:10:29 +0200864 free_page((unsigned long)chsc_page);
Sebastian Ott34aec072010-10-25 16:10:28 +0200865 free_page((unsigned long)sei_page);
Cornelia Huck4434a382007-07-27 12:29:21 +0200866}
867
Sebastian Ott818c2722010-04-22 17:17:03 +0200868int chsc_enable_facility(int operation_code)
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800869{
Sebastian Ott34196f82010-10-25 16:10:29 +0200870 unsigned long flags;
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800871 int ret;
Sebastian Ott34196f82010-10-25 16:10:29 +0200872 struct {
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800873 struct chsc_header request;
874 u8 reserved1:4;
875 u8 format:4;
876 u8 reserved2;
877 u16 operation_code;
878 u32 reserved3;
879 u32 reserved4;
880 u32 operation_data_area[252];
881 struct chsc_header response;
882 u32 reserved5:4;
883 u32 format2:4;
884 u32 reserved6:24;
Sebastian Ott34196f82010-10-25 16:10:29 +0200885 } __attribute__ ((packed)) *sda_area;
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800886
Sebastian Ott34196f82010-10-25 16:10:29 +0200887 spin_lock_irqsave(&chsc_page_lock, flags);
888 memset(chsc_page, 0, PAGE_SIZE);
889 sda_area = chsc_page;
890 sda_area->request.length = 0x0400;
891 sda_area->request.code = 0x0031;
892 sda_area->operation_code = operation_code;
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800893
Sebastian Ott34196f82010-10-25 16:10:29 +0200894 ret = chsc(sda_area);
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800895 if (ret > 0) {
896 ret = (ret == 3) ? -ENODEV : -EBUSY;
897 goto out;
898 }
Cornelia Huckb9c9a212008-02-05 16:50:34 +0100899
Sebastian Ott34196f82010-10-25 16:10:29 +0200900 switch (sda_area->response.code) {
Cornelia Huckb9c9a212008-02-05 16:50:34 +0100901 case 0x0101:
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800902 ret = -EOPNOTSUPP;
903 break;
Cornelia Huckb9c9a212008-02-05 16:50:34 +0100904 default:
Sebastian Ott34196f82010-10-25 16:10:29 +0200905 ret = chsc_error_from_response(sda_area->response.code);
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800906 }
Cornelia Huckb9c9a212008-02-05 16:50:34 +0100907 if (ret != 0)
908 CIO_CRW_EVENT(2, "chsc: sda (oc=%x) failed (rc=%04x)\n",
Sebastian Ott34196f82010-10-25 16:10:29 +0200909 operation_code, sda_area->response.code);
910out:
911 spin_unlock_irqrestore(&chsc_page_lock, flags);
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800912 return ret;
913}
914
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915struct css_general_char css_general_characteristics;
916struct css_chsc_char css_chsc_characteristics;
917
918int __init
919chsc_determine_css_characteristics(void)
920{
921 int result;
922 struct {
923 struct chsc_header request;
924 u32 reserved1;
925 u32 reserved2;
926 u32 reserved3;
927 struct chsc_header response;
928 u32 reserved4;
929 u32 general_char[510];
Sebastian Ott34aec072010-10-25 16:10:28 +0200930 u32 chsc_char[508];
Peter Oberparleiter0f008aa2007-02-05 21:17:40 +0100931 } __attribute__ ((packed)) *scsc_area;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932
Sebastian Ott34196f82010-10-25 16:10:29 +0200933 spin_lock_irq(&chsc_page_lock);
934 memset(chsc_page, 0, PAGE_SIZE);
935 scsc_area = chsc_page;
Cornelia Huck495a5b42006-03-24 03:15:14 -0800936 scsc_area->request.length = 0x0010;
937 scsc_area->request.code = 0x0010;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938
939 result = chsc(scsc_area);
940 if (result) {
Cornelia Huckb9c9a212008-02-05 16:50:34 +0100941 result = (result == 3) ? -ENODEV : -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942 goto exit;
943 }
944
Cornelia Huckb9c9a212008-02-05 16:50:34 +0100945 result = chsc_error_from_response(scsc_area->response.code);
946 if (result == 0) {
947 memcpy(&css_general_characteristics, scsc_area->general_char,
948 sizeof(css_general_characteristics));
949 memcpy(&css_chsc_characteristics, scsc_area->chsc_char,
950 sizeof(css_chsc_characteristics));
951 } else
952 CIO_CRW_EVENT(2, "chsc: scsc failed (rc=%04x)\n",
953 scsc_area->response.code);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954exit:
Sebastian Ott34196f82010-10-25 16:10:29 +0200955 spin_unlock_irq(&chsc_page_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956 return result;
957}
958
959EXPORT_SYMBOL_GPL(css_general_characteristics);
960EXPORT_SYMBOL_GPL(css_chsc_characteristics);
Martin Schwidefskyd2fec592008-07-14 09:58:56 +0200961
962int chsc_sstpc(void *page, unsigned int op, u16 ctrl)
963{
964 struct {
965 struct chsc_header request;
966 unsigned int rsvd0;
967 unsigned int op : 8;
968 unsigned int rsvd1 : 8;
969 unsigned int ctrl : 16;
970 unsigned int rsvd2[5];
971 struct chsc_header response;
972 unsigned int rsvd3[7];
973 } __attribute__ ((packed)) *rr;
974 int rc;
975
976 memset(page, 0, PAGE_SIZE);
977 rr = page;
978 rr->request.length = 0x0020;
979 rr->request.code = 0x0033;
980 rr->op = op;
981 rr->ctrl = ctrl;
982 rc = chsc(rr);
983 if (rc)
984 return -EIO;
985 rc = (rr->response.code == 0x0001) ? 0 : -EIO;
986 return rc;
987}
988
989int chsc_sstpi(void *page, void *result, size_t size)
990{
991 struct {
992 struct chsc_header request;
993 unsigned int rsvd0[3];
994 struct chsc_header response;
995 char data[size];
996 } __attribute__ ((packed)) *rr;
997 int rc;
998
999 memset(page, 0, PAGE_SIZE);
1000 rr = page;
1001 rr->request.length = 0x0010;
1002 rr->request.code = 0x0038;
1003 rc = chsc(rr);
1004 if (rc)
1005 return -EIO;
1006 memcpy(result, &rr->data, size);
1007 return (rr->response.code == 0x0001) ? 0 : -EIO;
1008}
1009
Michael Ernstfd0457a2010-08-09 18:12:50 +02001010int chsc_siosl(struct subchannel_id schid)
1011{
Sebastian Ott34196f82010-10-25 16:10:29 +02001012 struct {
1013 struct chsc_header request;
1014 u32 word1;
1015 struct subchannel_id sid;
1016 u32 word3;
1017 struct chsc_header response;
1018 u32 word[11];
1019 } __attribute__ ((packed)) *siosl_area;
Michael Ernstfd0457a2010-08-09 18:12:50 +02001020 unsigned long flags;
1021 int ccode;
1022 int rc;
1023
Sebastian Ott34196f82010-10-25 16:10:29 +02001024 spin_lock_irqsave(&chsc_page_lock, flags);
1025 memset(chsc_page, 0, PAGE_SIZE);
1026 siosl_area = chsc_page;
1027 siosl_area->request.length = 0x0010;
1028 siosl_area->request.code = 0x0046;
1029 siosl_area->word1 = 0x80000000;
1030 siosl_area->sid = schid;
Michael Ernstfd0457a2010-08-09 18:12:50 +02001031
Sebastian Ott34196f82010-10-25 16:10:29 +02001032 ccode = chsc(siosl_area);
Michael Ernstfd0457a2010-08-09 18:12:50 +02001033 if (ccode > 0) {
1034 if (ccode == 3)
1035 rc = -ENODEV;
1036 else
1037 rc = -EBUSY;
1038 CIO_MSG_EVENT(2, "chsc: chsc failed for 0.%x.%04x (ccode=%d)\n",
1039 schid.ssid, schid.sch_no, ccode);
1040 goto out;
1041 }
Sebastian Ott34196f82010-10-25 16:10:29 +02001042 rc = chsc_error_from_response(siosl_area->response.code);
Michael Ernstfd0457a2010-08-09 18:12:50 +02001043 if (rc)
1044 CIO_MSG_EVENT(2, "chsc: siosl failed for 0.%x.%04x (rc=%04x)\n",
1045 schid.ssid, schid.sch_no,
Sebastian Ott34196f82010-10-25 16:10:29 +02001046 siosl_area->response.code);
Michael Ernstfd0457a2010-08-09 18:12:50 +02001047 else
1048 CIO_MSG_EVENT(4, "chsc: siosl succeeded for 0.%x.%04x\n",
1049 schid.ssid, schid.sch_no);
1050out:
Sebastian Ott34196f82010-10-25 16:10:29 +02001051 spin_unlock_irqrestore(&chsc_page_lock, flags);
Michael Ernstfd0457a2010-08-09 18:12:50 +02001052 return rc;
1053}
1054EXPORT_SYMBOL_GPL(chsc_siosl);
Sebastian Ott184b08a2012-08-28 16:45:42 +02001055
1056/**
1057 * chsc_scm_info() - store SCM information (SSI)
1058 * @scm_area: request and response block for SSI
1059 * @token: continuation token
1060 *
1061 * Returns 0 on success.
1062 */
1063int chsc_scm_info(struct chsc_scm_info *scm_area, u64 token)
1064{
1065 int ccode, ret;
1066
1067 memset(scm_area, 0, sizeof(*scm_area));
1068 scm_area->request.length = 0x0020;
1069 scm_area->request.code = 0x004C;
1070 scm_area->reqtok = token;
1071
1072 ccode = chsc(scm_area);
1073 if (ccode > 0) {
1074 ret = (ccode == 3) ? -ENODEV : -EBUSY;
1075 goto out;
1076 }
1077 ret = chsc_error_from_response(scm_area->response.code);
1078 if (ret != 0)
1079 CIO_MSG_EVENT(2, "chsc: scm info failed (rc=%04x)\n",
1080 scm_area->response.code);
1081out:
1082 return ret;
1083}
1084EXPORT_SYMBOL_GPL(chsc_scm_info);