blob: 4d51a7c4eb8b8af56b8a8cf2089a494079bea5bc [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
Sebastian Ott40ff4cc2012-08-28 16:47:02 +0200401static void chsc_process_sei_scm_change(struct chsc_sei_area *sei_area)
402{
403 int ret;
404
405 CIO_CRW_EVENT(4, "chsc: scm change notification\n");
406 if (sei_area->rs != 7)
407 return;
408
409 ret = scm_update_information();
410 if (ret)
411 CIO_CRW_EVENT(0, "chsc: updating change notification"
412 " failed (rc=%d).\n", ret);
413}
414
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200415static void chsc_process_sei(struct chsc_sei_area *sei_area)
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100416{
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100417 /* Check if we might have lost some information. */
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200418 if (sei_area->flags & 0x40) {
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100419 CIO_CRW_EVENT(2, "chsc: event overflow\n");
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200420 css_schedule_eval_all();
421 }
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100422 /* which kind of information was stored? */
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100423 switch (sei_area->cc) {
424 case 1: /* link incident*/
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200425 chsc_process_sei_link_incident(sei_area);
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100426 break;
Sebastian Ottfca894ed2011-05-23 10:24:41 +0200427 case 2: /* i/o resource accessibility */
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200428 chsc_process_sei_res_acc(sei_area);
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100429 break;
Sebastian Ottfca894ed2011-05-23 10:24:41 +0200430 case 7: /* channel-path-availability information */
431 chsc_process_sei_chp_avail(sei_area);
432 break;
Peter Oberparleitere5854a52007-04-27 16:01:31 +0200433 case 8: /* channel-path-configuration notification */
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200434 chsc_process_sei_chp_config(sei_area);
Peter Oberparleitere5854a52007-04-27 16:01:31 +0200435 break;
Sebastian Ott40ff4cc2012-08-28 16:47:02 +0200436 case 12: /* scm change notification */
437 chsc_process_sei_scm_change(sei_area);
438 break;
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100439 default: /* other stuff */
440 CIO_CRW_EVENT(4, "chsc: unhandled sei content code %d\n",
441 sei_area->cc);
442 break;
443 }
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100444}
445
Cornelia Huckc1156182008-07-14 09:58:46 +0200446static void chsc_process_crw(struct crw *crw0, struct crw *crw1, int overflow)
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100447{
448 struct chsc_sei_area *sei_area;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449
Cornelia Huckc1156182008-07-14 09:58:46 +0200450 if (overflow) {
451 css_schedule_eval_all();
452 return;
453 }
454 CIO_CRW_EVENT(2, "CRW reports slct=%d, oflw=%d, "
455 "chn=%d, rsc=%X, anc=%d, erc=%X, rsid=%X\n",
456 crw0->slct, crw0->oflw, crw0->chn, crw0->rsc, crw0->anc,
457 crw0->erc, crw0->rsid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 if (!sei_page)
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200459 return;
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100460 /* Access to sei_page is serialized through machine check handler
461 * thread, so no need for locking. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 sei_area = sei_page;
463
Cornelia Huckc1156182008-07-14 09:58:46 +0200464 CIO_TRACE_EVENT(2, "prcss");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 do {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 memset(sei_area, 0, sizeof(*sei_area));
Cornelia Huck495a5b42006-03-24 03:15:14 -0800467 sei_area->request.length = 0x0010;
468 sei_area->request.code = 0x000e;
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100469 if (chsc(sei_area))
470 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100472 if (sei_area->response.code == 0x0001) {
473 CIO_CRW_EVENT(4, "chsc: sei successful\n");
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200474 chsc_process_sei(sei_area);
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100475 } else {
476 CIO_CRW_EVENT(2, "chsc: sei failed (rc=%04x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 sei_area->response.code);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 break;
479 }
480 } while (sei_area->flags & 0x80);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481}
482
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200483void chsc_chp_online(struct chp_id chpid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 char dbf_txt[15];
Cornelia Huck99611f82008-07-14 09:59:02 +0200486 struct chp_link link;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487
Peter Oberparleiterf86635f2007-04-27 16:01:26 +0200488 sprintf(dbf_txt, "cadd%x.%02x", chpid.cssid, chpid.id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 CIO_TRACE_EVENT(2, dbf_txt);
490
Cornelia Huck22806dc2008-04-17 07:45:59 +0200491 if (chp_get_status(chpid) != 0) {
Cornelia Huck99611f82008-07-14 09:59:02 +0200492 memset(&link, 0, sizeof(struct chp_link));
493 link.chpid = chpid;
Cornelia Huck22806dc2008-04-17 07:45:59 +0200494 /* Wait until previous actions have settled. */
495 css_wait_for_slow_path();
Cornelia Huckc820de32008-07-14 09:58:45 +0200496 for_each_subchannel_staged(__s390_process_res_acc, NULL,
Cornelia Huck99611f82008-07-14 09:59:02 +0200497 &link);
Cornelia Huck22806dc2008-04-17 07:45:59 +0200498 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499}
500
Peter Oberparleiterf86635f2007-04-27 16:01:26 +0200501static void __s390_subchannel_vary_chpid(struct subchannel *sch,
502 struct chp_id chpid, int on)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 unsigned long flags;
Cornelia Huck99611f82008-07-14 09:59:02 +0200505 struct chp_link link;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506
Cornelia Huck99611f82008-07-14 09:59:02 +0200507 memset(&link, 0, sizeof(struct chp_link));
508 link.chpid = chpid;
Cornelia Huck2ec22982006-12-08 15:54:26 +0100509 spin_lock_irqsave(sch->lock, flags);
Cornelia Huckc820de32008-07-14 09:58:45 +0200510 if (sch->driver && sch->driver->chp_event)
Cornelia Huck99611f82008-07-14 09:59:02 +0200511 sch->driver->chp_event(sch, &link,
Cornelia Huckc820de32008-07-14 09:58:45 +0200512 on ? CHP_VARY_ON : CHP_VARY_OFF);
Cornelia Huck2ec22982006-12-08 15:54:26 +0100513 spin_unlock_irqrestore(sch->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514}
515
Peter Oberparleitere82a1562008-01-26 14:10:48 +0100516static int s390_subchannel_vary_chpid_off(struct subchannel *sch, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517{
Peter Oberparleitere82a1562008-01-26 14:10:48 +0100518 struct chp_id *chpid = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519
520 __s390_subchannel_vary_chpid(sch, *chpid, 0);
521 return 0;
522}
523
Peter Oberparleitere82a1562008-01-26 14:10:48 +0100524static int s390_subchannel_vary_chpid_on(struct subchannel *sch, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525{
Peter Oberparleitere82a1562008-01-26 14:10:48 +0100526 struct chp_id *chpid = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527
528 __s390_subchannel_vary_chpid(sch, *chpid, 1);
529 return 0;
530}
531
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800532static int
533__s390_vary_chpid_on(struct subchannel_id schid, void *data)
534{
535 struct schib schib;
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800536
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800537 if (stsch_err(schid, &schib))
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800538 /* We're through */
539 return -ENXIO;
540 /* Put it on the slow path. */
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200541 css_schedule_eval(schid);
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800542 return 0;
543}
544
Peter Oberparleitere6b6e102007-04-27 16:01:28 +0200545/**
546 * chsc_chp_vary - propagate channel-path vary operation to subchannels
547 * @chpid: channl-path ID
548 * @on: non-zero for vary online, zero for vary offline
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 */
Peter Oberparleitere6b6e102007-04-27 16:01:28 +0200550int chsc_chp_vary(struct chp_id chpid, int on)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551{
Sebastian Ottc38a90a2010-10-25 16:10:31 +0200552 struct channel_path *chp = chpid_to_chp(chpid);
Cornelia Huck99611f82008-07-14 09:59:02 +0200553
Cornelia Huck22806dc2008-04-17 07:45:59 +0200554 /* Wait until previous actions have settled. */
555 css_wait_for_slow_path();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 /*
557 * Redo PathVerification on the devices the chpid connects to
558 */
Sebastian Ottc38a90a2010-10-25 16:10:31 +0200559 if (on) {
560 /* Try to update the channel path descritor. */
561 chsc_determine_base_channel_path_desc(chpid, &chp->desc);
Peter Oberparleitere82a1562008-01-26 14:10:48 +0100562 for_each_subchannel_staged(s390_subchannel_vary_chpid_on,
Sebastian Ott3b484ec2011-12-01 13:32:22 +0100563 __s390_vary_chpid_on, &chpid);
Sebastian Ottc38a90a2010-10-25 16:10:31 +0200564 } else
Peter Oberparleitere82a1562008-01-26 14:10:48 +0100565 for_each_subchannel_staged(s390_subchannel_vary_chpid_off,
Sebastian Ott3b484ec2011-12-01 13:32:22 +0100566 NULL, &chpid);
Peter Oberparleitere82a1562008-01-26 14:10:48 +0100567
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 return 0;
569}
570
Cornelia Huck495a5b42006-03-24 03:15:14 -0800571static void
572chsc_remove_cmg_attr(struct channel_subsystem *css)
573{
574 int i;
575
576 for (i = 0; i <= __MAX_CHPID; i++) {
577 if (!css->chps[i])
578 continue;
Peter Oberparleitere6b6e102007-04-27 16:01:28 +0200579 chp_remove_cmg_attr(css->chps[i]);
Cornelia Huck495a5b42006-03-24 03:15:14 -0800580 }
581}
582
583static int
584chsc_add_cmg_attr(struct channel_subsystem *css)
585{
586 int i, ret;
587
588 ret = 0;
589 for (i = 0; i <= __MAX_CHPID; i++) {
590 if (!css->chps[i])
591 continue;
Peter Oberparleitere6b6e102007-04-27 16:01:28 +0200592 ret = chp_add_cmg_attr(css->chps[i]);
Cornelia Huck495a5b42006-03-24 03:15:14 -0800593 if (ret)
594 goto cleanup;
595 }
596 return ret;
597cleanup:
598 for (--i; i >= 0; i--) {
599 if (!css->chps[i])
600 continue;
Peter Oberparleitere6b6e102007-04-27 16:01:28 +0200601 chp_remove_cmg_attr(css->chps[i]);
Cornelia Huck495a5b42006-03-24 03:15:14 -0800602 }
603 return ret;
604}
605
Sebastian Ott34196f82010-10-25 16:10:29 +0200606int __chsc_do_secm(struct channel_subsystem *css, int enable)
Cornelia Huck495a5b42006-03-24 03:15:14 -0800607{
608 struct {
609 struct chsc_header request;
610 u32 operation_code : 2;
611 u32 : 30;
612 u32 key : 4;
613 u32 : 28;
614 u32 zeroes1;
615 u32 cub_addr1;
616 u32 zeroes2;
617 u32 cub_addr2;
618 u32 reserved[13];
619 struct chsc_header response;
620 u32 status : 8;
621 u32 : 4;
622 u32 fmt : 4;
623 u32 : 16;
Peter Oberparleiter0f008aa2007-02-05 21:17:40 +0100624 } __attribute__ ((packed)) *secm_area;
Cornelia Huck495a5b42006-03-24 03:15:14 -0800625 int ret, ccode;
626
Sebastian Ott34196f82010-10-25 16:10:29 +0200627 spin_lock_irq(&chsc_page_lock);
628 memset(chsc_page, 0, PAGE_SIZE);
629 secm_area = chsc_page;
Cornelia Huck495a5b42006-03-24 03:15:14 -0800630 secm_area->request.length = 0x0050;
631 secm_area->request.code = 0x0016;
632
Heiko Carstensd1bf8592010-02-26 22:37:30 +0100633 secm_area->key = PAGE_DEFAULT_KEY >> 4;
Cornelia Huck495a5b42006-03-24 03:15:14 -0800634 secm_area->cub_addr1 = (u64)(unsigned long)css->cub_addr1;
635 secm_area->cub_addr2 = (u64)(unsigned long)css->cub_addr2;
636
637 secm_area->operation_code = enable ? 0 : 1;
638
639 ccode = chsc(secm_area);
Sebastian Ott34196f82010-10-25 16:10:29 +0200640 if (ccode > 0) {
641 ret = (ccode == 3) ? -ENODEV : -EBUSY;
642 goto out;
643 }
Cornelia Huck495a5b42006-03-24 03:15:14 -0800644
645 switch (secm_area->response.code) {
Cornelia Huckb9c9a212008-02-05 16:50:34 +0100646 case 0x0102:
647 case 0x0103:
Cornelia Huck495a5b42006-03-24 03:15:14 -0800648 ret = -EINVAL;
Sebastian Ott17e7d872009-03-26 15:24:17 +0100649 break;
Cornelia Huck495a5b42006-03-24 03:15:14 -0800650 default:
Cornelia Huckb9c9a212008-02-05 16:50:34 +0100651 ret = chsc_error_from_response(secm_area->response.code);
Cornelia Huck495a5b42006-03-24 03:15:14 -0800652 }
Cornelia Huckb9c9a212008-02-05 16:50:34 +0100653 if (ret != 0)
654 CIO_CRW_EVENT(2, "chsc: secm failed (rc=%04x)\n",
655 secm_area->response.code);
Sebastian Ott34196f82010-10-25 16:10:29 +0200656out:
657 spin_unlock_irq(&chsc_page_lock);
Cornelia Huck495a5b42006-03-24 03:15:14 -0800658 return ret;
659}
660
661int
662chsc_secm(struct channel_subsystem *css, int enable)
663{
Cornelia Huck495a5b42006-03-24 03:15:14 -0800664 int ret;
665
Cornelia Huck495a5b42006-03-24 03:15:14 -0800666 if (enable && !css->cm_enabled) {
667 css->cub_addr1 = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
668 css->cub_addr2 = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
669 if (!css->cub_addr1 || !css->cub_addr2) {
670 free_page((unsigned long)css->cub_addr1);
671 free_page((unsigned long)css->cub_addr2);
Cornelia Huck495a5b42006-03-24 03:15:14 -0800672 return -ENOMEM;
673 }
674 }
Sebastian Ott34196f82010-10-25 16:10:29 +0200675 ret = __chsc_do_secm(css, enable);
Cornelia Huck495a5b42006-03-24 03:15:14 -0800676 if (!ret) {
677 css->cm_enabled = enable;
678 if (css->cm_enabled) {
679 ret = chsc_add_cmg_attr(css);
680 if (ret) {
Sebastian Ott34196f82010-10-25 16:10:29 +0200681 __chsc_do_secm(css, 0);
Cornelia Huck495a5b42006-03-24 03:15:14 -0800682 css->cm_enabled = 0;
683 }
684 } else
685 chsc_remove_cmg_attr(css);
686 }
Cornelia Huck8c4941c2007-04-27 16:01:38 +0200687 if (!css->cm_enabled) {
Cornelia Huck495a5b42006-03-24 03:15:14 -0800688 free_page((unsigned long)css->cub_addr1);
689 free_page((unsigned long)css->cub_addr2);
690 }
Cornelia Huck495a5b42006-03-24 03:15:14 -0800691 return ret;
692}
693
Cornelia Huck9d92a7e2008-07-14 09:59:05 +0200694int chsc_determine_channel_path_desc(struct chp_id chpid, int fmt, int rfmt,
Sebastian Ott906c9762010-10-25 16:10:30 +0200695 int c, int m, void *page)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696{
Sebastian Ott906c9762010-10-25 16:10:30 +0200697 struct chsc_scpd *scpd_area;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 int ccode, ret;
699
Cornelia Huck9d92a7e2008-07-14 09:59:05 +0200700 if ((rfmt == 1) && !css_general_characteristics.fcs)
701 return -EINVAL;
702 if ((rfmt == 2) && !css_general_characteristics.cib)
703 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704
Sebastian Ott906c9762010-10-25 16:10:30 +0200705 memset(page, 0, PAGE_SIZE);
706 scpd_area = page;
Cornelia Huck495a5b42006-03-24 03:15:14 -0800707 scpd_area->request.length = 0x0010;
708 scpd_area->request.code = 0x0002;
Cornelia Huck9d92a7e2008-07-14 09:59:05 +0200709 scpd_area->cssid = chpid.cssid;
Peter Oberparleiterf86635f2007-04-27 16:01:26 +0200710 scpd_area->first_chpid = chpid.id;
711 scpd_area->last_chpid = chpid.id;
Cornelia Huck9d92a7e2008-07-14 09:59:05 +0200712 scpd_area->m = m;
713 scpd_area->c = c;
714 scpd_area->fmt = fmt;
715 scpd_area->rfmt = rfmt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716
717 ccode = chsc(scpd_area);
Sebastian Ott906c9762010-10-25 16:10:30 +0200718 if (ccode > 0)
719 return (ccode == 3) ? -ENODEV : -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720
Cornelia Huckb9c9a212008-02-05 16:50:34 +0100721 ret = chsc_error_from_response(scpd_area->response.code);
Sebastian Ott906c9762010-10-25 16:10:30 +0200722 if (ret)
Cornelia Huckb9c9a212008-02-05 16:50:34 +0100723 CIO_CRW_EVENT(2, "chsc: scpd failed (rc=%04x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724 scpd_area->response.code);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 return ret;
726}
Cornelia Huck9d92a7e2008-07-14 09:59:05 +0200727EXPORT_SYMBOL_GPL(chsc_determine_channel_path_desc);
728
729int chsc_determine_base_channel_path_desc(struct chp_id chpid,
730 struct channel_path_desc *desc)
731{
732 struct chsc_response_struct *chsc_resp;
Sebastian Ott906c9762010-10-25 16:10:30 +0200733 struct chsc_scpd *scpd_area;
Sebastian Ott62da1772010-10-25 16:10:32 +0200734 unsigned long flags;
Cornelia Huck9d92a7e2008-07-14 09:59:05 +0200735 int ret;
736
Sebastian Ott62da1772010-10-25 16:10:32 +0200737 spin_lock_irqsave(&chsc_page_lock, flags);
Sebastian Ott906c9762010-10-25 16:10:30 +0200738 scpd_area = chsc_page;
739 ret = chsc_determine_channel_path_desc(chpid, 0, 0, 0, 0, scpd_area);
Cornelia Huck9d92a7e2008-07-14 09:59:05 +0200740 if (ret)
Sebastian Ott906c9762010-10-25 16:10:30 +0200741 goto out;
742 chsc_resp = (void *)&scpd_area->response;
Sebastian Ott878c4952010-07-19 09:22:37 +0200743 memcpy(desc, &chsc_resp->data, sizeof(*desc));
Sebastian Ott906c9762010-10-25 16:10:30 +0200744out:
Sebastian Ott62da1772010-10-25 16:10:32 +0200745 spin_unlock_irqrestore(&chsc_page_lock, flags);
Cornelia Huck9d92a7e2008-07-14 09:59:05 +0200746 return ret;
747}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748
Sebastian Ottce322cc2011-01-05 12:47:56 +0100749int chsc_determine_fmt1_channel_path_desc(struct chp_id chpid,
750 struct channel_path_desc_fmt1 *desc)
751{
752 struct chsc_response_struct *chsc_resp;
753 struct chsc_scpd *scpd_area;
754 int ret;
755
756 spin_lock_irq(&chsc_page_lock);
757 scpd_area = chsc_page;
758 ret = chsc_determine_channel_path_desc(chpid, 0, 0, 1, 0, scpd_area);
759 if (ret)
760 goto out;
761 chsc_resp = (void *)&scpd_area->response;
762 memcpy(desc, &chsc_resp->data, sizeof(*desc));
763out:
764 spin_unlock_irq(&chsc_page_lock);
765 return ret;
766}
767
Cornelia Huck495a5b42006-03-24 03:15:14 -0800768static void
769chsc_initialize_cmg_chars(struct channel_path *chp, u8 cmcv,
770 struct cmg_chars *chars)
771{
Sebastian Ott34196f82010-10-25 16:10:29 +0200772 struct cmg_chars *cmg_chars;
773 int i, mask;
Cornelia Huck495a5b42006-03-24 03:15:14 -0800774
Sebastian Ott34196f82010-10-25 16:10:29 +0200775 cmg_chars = chp->cmg_chars;
776 for (i = 0; i < NR_MEASUREMENT_CHARS; i++) {
777 mask = 0x80 >> (i + 3);
778 if (cmcv & mask)
779 cmg_chars->values[i] = chars->values[i];
780 else
781 cmg_chars->values[i] = 0;
Cornelia Huck495a5b42006-03-24 03:15:14 -0800782 }
783}
784
Peter Oberparleitere6b6e102007-04-27 16:01:28 +0200785int chsc_get_channel_measurement_chars(struct channel_path *chp)
Cornelia Huck495a5b42006-03-24 03:15:14 -0800786{
Sebastian Ott34196f82010-10-25 16:10:29 +0200787 struct cmg_chars *cmg_chars;
Cornelia Huck495a5b42006-03-24 03:15:14 -0800788 int ccode, ret;
789
790 struct {
791 struct chsc_header request;
792 u32 : 24;
793 u32 first_chpid : 8;
794 u32 : 24;
795 u32 last_chpid : 8;
796 u32 zeroes1;
797 struct chsc_header response;
798 u32 zeroes2;
799 u32 not_valid : 1;
800 u32 shared : 1;
801 u32 : 22;
802 u32 chpid : 8;
803 u32 cmcv : 5;
804 u32 : 11;
805 u32 cmgq : 8;
806 u32 cmg : 8;
807 u32 zeroes3;
808 u32 data[NR_MEASUREMENT_CHARS];
Peter Oberparleiter0f008aa2007-02-05 21:17:40 +0100809 } __attribute__ ((packed)) *scmc_area;
Cornelia Huck495a5b42006-03-24 03:15:14 -0800810
Sebastian Ott34196f82010-10-25 16:10:29 +0200811 chp->cmg_chars = NULL;
812 cmg_chars = kmalloc(sizeof(*cmg_chars), GFP_KERNEL);
813 if (!cmg_chars)
Cornelia Huck495a5b42006-03-24 03:15:14 -0800814 return -ENOMEM;
815
Sebastian Ott34196f82010-10-25 16:10:29 +0200816 spin_lock_irq(&chsc_page_lock);
817 memset(chsc_page, 0, PAGE_SIZE);
818 scmc_area = chsc_page;
Cornelia Huck495a5b42006-03-24 03:15:14 -0800819 scmc_area->request.length = 0x0010;
820 scmc_area->request.code = 0x0022;
Peter Oberparleiterf86635f2007-04-27 16:01:26 +0200821 scmc_area->first_chpid = chp->chpid.id;
822 scmc_area->last_chpid = chp->chpid.id;
Cornelia Huck495a5b42006-03-24 03:15:14 -0800823
824 ccode = chsc(scmc_area);
825 if (ccode > 0) {
826 ret = (ccode == 3) ? -ENODEV : -EBUSY;
827 goto out;
828 }
829
Cornelia Huckb9c9a212008-02-05 16:50:34 +0100830 ret = chsc_error_from_response(scmc_area->response.code);
Sebastian Ott34196f82010-10-25 16:10:29 +0200831 if (ret) {
Cornelia Huckb9c9a212008-02-05 16:50:34 +0100832 CIO_CRW_EVENT(2, "chsc: scmc failed (rc=%04x)\n",
Cornelia Huck495a5b42006-03-24 03:15:14 -0800833 scmc_area->response.code);
Sebastian Ott34196f82010-10-25 16:10:29 +0200834 goto out;
Cornelia Huck495a5b42006-03-24 03:15:14 -0800835 }
Sebastian Ott34196f82010-10-25 16:10:29 +0200836 if (scmc_area->not_valid) {
837 chp->cmg = -1;
838 chp->shared = -1;
839 goto out;
840 }
841 chp->cmg = scmc_area->cmg;
842 chp->shared = scmc_area->shared;
843 if (chp->cmg != 2 && chp->cmg != 3) {
844 /* No cmg-dependent data. */
845 goto out;
846 }
847 chp->cmg_chars = cmg_chars;
848 chsc_initialize_cmg_chars(chp, scmc_area->cmcv,
849 (struct cmg_chars *) &scmc_area->data);
Cornelia Huck495a5b42006-03-24 03:15:14 -0800850out:
Sebastian Ott34196f82010-10-25 16:10:29 +0200851 spin_unlock_irq(&chsc_page_lock);
852 if (!chp->cmg_chars)
853 kfree(cmg_chars);
854
Cornelia Huck495a5b42006-03-24 03:15:14 -0800855 return ret;
856}
857
Sebastian Ott34aec072010-10-25 16:10:28 +0200858int __init chsc_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859{
Cornelia Huckc1156182008-07-14 09:58:46 +0200860 int ret;
861
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 sei_page = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
Sebastian Ott34196f82010-10-25 16:10:29 +0200863 chsc_page = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
864 if (!sei_page || !chsc_page) {
865 ret = -ENOMEM;
866 goto out_err;
Cornelia Huckc1156182008-07-14 09:58:46 +0200867 }
Heiko Carstensf5daba12009-03-26 15:24:01 +0100868 ret = crw_register_handler(CRW_RSC_CSS, chsc_process_crw);
Cornelia Huckc1156182008-07-14 09:58:46 +0200869 if (ret)
Sebastian Ott34196f82010-10-25 16:10:29 +0200870 goto out_err;
871 return ret;
872out_err:
873 free_page((unsigned long)chsc_page);
874 free_page((unsigned long)sei_page);
Cornelia Huckc1156182008-07-14 09:58:46 +0200875 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876}
877
Sebastian Ott34aec072010-10-25 16:10:28 +0200878void __init chsc_init_cleanup(void)
Cornelia Huck4434a382007-07-27 12:29:21 +0200879{
Heiko Carstensf5daba12009-03-26 15:24:01 +0100880 crw_unregister_handler(CRW_RSC_CSS);
Sebastian Ott34196f82010-10-25 16:10:29 +0200881 free_page((unsigned long)chsc_page);
Sebastian Ott34aec072010-10-25 16:10:28 +0200882 free_page((unsigned long)sei_page);
Cornelia Huck4434a382007-07-27 12:29:21 +0200883}
884
Sebastian Ott818c2722010-04-22 17:17:03 +0200885int chsc_enable_facility(int operation_code)
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800886{
Sebastian Ott34196f82010-10-25 16:10:29 +0200887 unsigned long flags;
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800888 int ret;
Sebastian Ott34196f82010-10-25 16:10:29 +0200889 struct {
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800890 struct chsc_header request;
891 u8 reserved1:4;
892 u8 format:4;
893 u8 reserved2;
894 u16 operation_code;
895 u32 reserved3;
896 u32 reserved4;
897 u32 operation_data_area[252];
898 struct chsc_header response;
899 u32 reserved5:4;
900 u32 format2:4;
901 u32 reserved6:24;
Sebastian Ott34196f82010-10-25 16:10:29 +0200902 } __attribute__ ((packed)) *sda_area;
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800903
Sebastian Ott34196f82010-10-25 16:10:29 +0200904 spin_lock_irqsave(&chsc_page_lock, flags);
905 memset(chsc_page, 0, PAGE_SIZE);
906 sda_area = chsc_page;
907 sda_area->request.length = 0x0400;
908 sda_area->request.code = 0x0031;
909 sda_area->operation_code = operation_code;
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800910
Sebastian Ott34196f82010-10-25 16:10:29 +0200911 ret = chsc(sda_area);
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800912 if (ret > 0) {
913 ret = (ret == 3) ? -ENODEV : -EBUSY;
914 goto out;
915 }
Cornelia Huckb9c9a212008-02-05 16:50:34 +0100916
Sebastian Ott34196f82010-10-25 16:10:29 +0200917 switch (sda_area->response.code) {
Cornelia Huckb9c9a212008-02-05 16:50:34 +0100918 case 0x0101:
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800919 ret = -EOPNOTSUPP;
920 break;
Cornelia Huckb9c9a212008-02-05 16:50:34 +0100921 default:
Sebastian Ott34196f82010-10-25 16:10:29 +0200922 ret = chsc_error_from_response(sda_area->response.code);
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800923 }
Cornelia Huckb9c9a212008-02-05 16:50:34 +0100924 if (ret != 0)
925 CIO_CRW_EVENT(2, "chsc: sda (oc=%x) failed (rc=%04x)\n",
Sebastian Ott34196f82010-10-25 16:10:29 +0200926 operation_code, sda_area->response.code);
927out:
928 spin_unlock_irqrestore(&chsc_page_lock, flags);
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800929 return ret;
930}
931
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932struct css_general_char css_general_characteristics;
933struct css_chsc_char css_chsc_characteristics;
934
935int __init
936chsc_determine_css_characteristics(void)
937{
938 int result;
939 struct {
940 struct chsc_header request;
941 u32 reserved1;
942 u32 reserved2;
943 u32 reserved3;
944 struct chsc_header response;
945 u32 reserved4;
946 u32 general_char[510];
Sebastian Ott34aec072010-10-25 16:10:28 +0200947 u32 chsc_char[508];
Peter Oberparleiter0f008aa2007-02-05 21:17:40 +0100948 } __attribute__ ((packed)) *scsc_area;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949
Sebastian Ott34196f82010-10-25 16:10:29 +0200950 spin_lock_irq(&chsc_page_lock);
951 memset(chsc_page, 0, PAGE_SIZE);
952 scsc_area = chsc_page;
Cornelia Huck495a5b42006-03-24 03:15:14 -0800953 scsc_area->request.length = 0x0010;
954 scsc_area->request.code = 0x0010;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955
956 result = chsc(scsc_area);
957 if (result) {
Cornelia Huckb9c9a212008-02-05 16:50:34 +0100958 result = (result == 3) ? -ENODEV : -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959 goto exit;
960 }
961
Cornelia Huckb9c9a212008-02-05 16:50:34 +0100962 result = chsc_error_from_response(scsc_area->response.code);
963 if (result == 0) {
964 memcpy(&css_general_characteristics, scsc_area->general_char,
965 sizeof(css_general_characteristics));
966 memcpy(&css_chsc_characteristics, scsc_area->chsc_char,
967 sizeof(css_chsc_characteristics));
968 } else
969 CIO_CRW_EVENT(2, "chsc: scsc failed (rc=%04x)\n",
970 scsc_area->response.code);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971exit:
Sebastian Ott34196f82010-10-25 16:10:29 +0200972 spin_unlock_irq(&chsc_page_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973 return result;
974}
975
976EXPORT_SYMBOL_GPL(css_general_characteristics);
977EXPORT_SYMBOL_GPL(css_chsc_characteristics);
Martin Schwidefskyd2fec592008-07-14 09:58:56 +0200978
979int chsc_sstpc(void *page, unsigned int op, u16 ctrl)
980{
981 struct {
982 struct chsc_header request;
983 unsigned int rsvd0;
984 unsigned int op : 8;
985 unsigned int rsvd1 : 8;
986 unsigned int ctrl : 16;
987 unsigned int rsvd2[5];
988 struct chsc_header response;
989 unsigned int rsvd3[7];
990 } __attribute__ ((packed)) *rr;
991 int rc;
992
993 memset(page, 0, PAGE_SIZE);
994 rr = page;
995 rr->request.length = 0x0020;
996 rr->request.code = 0x0033;
997 rr->op = op;
998 rr->ctrl = ctrl;
999 rc = chsc(rr);
1000 if (rc)
1001 return -EIO;
1002 rc = (rr->response.code == 0x0001) ? 0 : -EIO;
1003 return rc;
1004}
1005
1006int chsc_sstpi(void *page, void *result, size_t size)
1007{
1008 struct {
1009 struct chsc_header request;
1010 unsigned int rsvd0[3];
1011 struct chsc_header response;
1012 char data[size];
1013 } __attribute__ ((packed)) *rr;
1014 int rc;
1015
1016 memset(page, 0, PAGE_SIZE);
1017 rr = page;
1018 rr->request.length = 0x0010;
1019 rr->request.code = 0x0038;
1020 rc = chsc(rr);
1021 if (rc)
1022 return -EIO;
1023 memcpy(result, &rr->data, size);
1024 return (rr->response.code == 0x0001) ? 0 : -EIO;
1025}
1026
Michael Ernstfd0457a2010-08-09 18:12:50 +02001027int chsc_siosl(struct subchannel_id schid)
1028{
Sebastian Ott34196f82010-10-25 16:10:29 +02001029 struct {
1030 struct chsc_header request;
1031 u32 word1;
1032 struct subchannel_id sid;
1033 u32 word3;
1034 struct chsc_header response;
1035 u32 word[11];
1036 } __attribute__ ((packed)) *siosl_area;
Michael Ernstfd0457a2010-08-09 18:12:50 +02001037 unsigned long flags;
1038 int ccode;
1039 int rc;
1040
Sebastian Ott34196f82010-10-25 16:10:29 +02001041 spin_lock_irqsave(&chsc_page_lock, flags);
1042 memset(chsc_page, 0, PAGE_SIZE);
1043 siosl_area = chsc_page;
1044 siosl_area->request.length = 0x0010;
1045 siosl_area->request.code = 0x0046;
1046 siosl_area->word1 = 0x80000000;
1047 siosl_area->sid = schid;
Michael Ernstfd0457a2010-08-09 18:12:50 +02001048
Sebastian Ott34196f82010-10-25 16:10:29 +02001049 ccode = chsc(siosl_area);
Michael Ernstfd0457a2010-08-09 18:12:50 +02001050 if (ccode > 0) {
1051 if (ccode == 3)
1052 rc = -ENODEV;
1053 else
1054 rc = -EBUSY;
1055 CIO_MSG_EVENT(2, "chsc: chsc failed for 0.%x.%04x (ccode=%d)\n",
1056 schid.ssid, schid.sch_no, ccode);
1057 goto out;
1058 }
Sebastian Ott34196f82010-10-25 16:10:29 +02001059 rc = chsc_error_from_response(siosl_area->response.code);
Michael Ernstfd0457a2010-08-09 18:12:50 +02001060 if (rc)
1061 CIO_MSG_EVENT(2, "chsc: siosl failed for 0.%x.%04x (rc=%04x)\n",
1062 schid.ssid, schid.sch_no,
Sebastian Ott34196f82010-10-25 16:10:29 +02001063 siosl_area->response.code);
Michael Ernstfd0457a2010-08-09 18:12:50 +02001064 else
1065 CIO_MSG_EVENT(4, "chsc: siosl succeeded for 0.%x.%04x\n",
1066 schid.ssid, schid.sch_no);
1067out:
Sebastian Ott34196f82010-10-25 16:10:29 +02001068 spin_unlock_irqrestore(&chsc_page_lock, flags);
Michael Ernstfd0457a2010-08-09 18:12:50 +02001069 return rc;
1070}
1071EXPORT_SYMBOL_GPL(chsc_siosl);
Sebastian Ott184b08a2012-08-28 16:45:42 +02001072
1073/**
1074 * chsc_scm_info() - store SCM information (SSI)
1075 * @scm_area: request and response block for SSI
1076 * @token: continuation token
1077 *
1078 * Returns 0 on success.
1079 */
1080int chsc_scm_info(struct chsc_scm_info *scm_area, u64 token)
1081{
1082 int ccode, ret;
1083
1084 memset(scm_area, 0, sizeof(*scm_area));
1085 scm_area->request.length = 0x0020;
1086 scm_area->request.code = 0x004C;
1087 scm_area->reqtok = token;
1088
1089 ccode = chsc(scm_area);
1090 if (ccode > 0) {
1091 ret = (ccode == 3) ? -ENODEV : -EBUSY;
1092 goto out;
1093 }
1094 ret = chsc_error_from_response(scm_area->response.code);
1095 if (ret != 0)
1096 CIO_MSG_EVENT(2, "chsc: scm info failed (rc=%04x)\n",
1097 scm_area->response.code);
1098out:
1099 return ret;
1100}
1101EXPORT_SYMBOL_GPL(chsc_scm_info);