blob: cfe0c087fe5cc915859265bb59016076e120d84c [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;
55 default:
56 return -EIO;
57 }
58}
Cornelia Huckdae39842008-07-17 17:16:47 +020059EXPORT_SYMBOL_GPL(chsc_error_from_response);
Cornelia Huckb9c9a212008-02-05 16:50:34 +010060
Peter Oberparleiter7ad6a242007-04-27 16:01:35 +020061struct chsc_ssd_area {
62 struct chsc_header request;
63 u16 :10;
64 u16 ssid:2;
65 u16 :4;
66 u16 f_sch; /* first subchannel */
67 u16 :16;
68 u16 l_sch; /* last subchannel */
69 u32 :32;
70 struct chsc_header response;
71 u32 :32;
72 u8 sch_valid : 1;
73 u8 dev_valid : 1;
74 u8 st : 3; /* subchannel type */
75 u8 zeroes : 3;
76 u8 unit_addr; /* unit address */
77 u16 devno; /* device number */
78 u8 path_mask;
79 u8 fla_valid_mask;
80 u16 sch; /* subchannel */
81 u8 chpid[8]; /* chpids 0-7 */
82 u16 fla[8]; /* full link addresses 0-7 */
83} __attribute__ ((packed));
84
85int chsc_get_ssd_info(struct subchannel_id schid, struct chsc_ssd_info *ssd)
Linus Torvalds1da177e2005-04-16 15:20:36 -070086{
Peter Oberparleiter7ad6a242007-04-27 16:01:35 +020087 struct chsc_ssd_area *ssd_area;
88 int ccode;
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 int ret;
Peter Oberparleiter7ad6a242007-04-27 16:01:35 +020090 int i;
91 int mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -070092
Sebastian Ott34196f82010-10-25 16:10:29 +020093 spin_lock_irq(&chsc_page_lock);
94 memset(chsc_page, 0, PAGE_SIZE);
95 ssd_area = chsc_page;
Peter Oberparleiter7ad6a242007-04-27 16:01:35 +020096 ssd_area->request.length = 0x0010;
97 ssd_area->request.code = 0x0004;
98 ssd_area->ssid = schid.ssid;
99 ssd_area->f_sch = schid.sch_no;
100 ssd_area->l_sch = schid.sch_no;
Peter Oberparleiterf86635f2007-04-27 16:01:26 +0200101
Peter Oberparleiter7ad6a242007-04-27 16:01:35 +0200102 ccode = chsc(ssd_area);
103 /* Check response. */
104 if (ccode > 0) {
105 ret = (ccode == 3) ? -ENODEV : -EBUSY;
Sebastian Ott34196f82010-10-25 16:10:29 +0200106 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 }
Cornelia Huckb9c9a212008-02-05 16:50:34 +0100108 ret = chsc_error_from_response(ssd_area->response.code);
109 if (ret != 0) {
Peter Oberparleiter7ad6a242007-04-27 16:01:35 +0200110 CIO_MSG_EVENT(2, "chsc: ssd failed for 0.%x.%04x (rc=%04x)\n",
111 schid.ssid, schid.sch_no,
112 ssd_area->response.code);
Sebastian Ott34196f82010-10-25 16:10:29 +0200113 goto out;
Peter Oberparleiter7ad6a242007-04-27 16:01:35 +0200114 }
115 if (!ssd_area->sch_valid) {
116 ret = -ENODEV;
Sebastian Ott34196f82010-10-25 16:10:29 +0200117 goto out;
Peter Oberparleiter7ad6a242007-04-27 16:01:35 +0200118 }
119 /* Copy data */
120 ret = 0;
121 memset(ssd, 0, sizeof(struct chsc_ssd_info));
Cornelia Huckb279a4f2008-01-26 14:10:45 +0100122 if ((ssd_area->st != SUBCHANNEL_TYPE_IO) &&
123 (ssd_area->st != SUBCHANNEL_TYPE_MSG))
Sebastian Ott34196f82010-10-25 16:10:29 +0200124 goto out;
Peter Oberparleiter7ad6a242007-04-27 16:01:35 +0200125 ssd->path_mask = ssd_area->path_mask;
126 ssd->fla_valid_mask = ssd_area->fla_valid_mask;
127 for (i = 0; i < 8; i++) {
128 mask = 0x80 >> i;
129 if (ssd_area->path_mask & mask) {
130 chp_id_init(&ssd->chpid[i]);
131 ssd->chpid[i].id = ssd_area->chpid[i];
132 }
133 if (ssd_area->fla_valid_mask & mask)
134 ssd->fla[i] = ssd_area->fla[i];
135 }
Sebastian Ott34196f82010-10-25 16:10:29 +0200136out:
137 spin_unlock_irq(&chsc_page_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 return ret;
139}
140
Peter Oberparleitere82a1562008-01-26 14:10:48 +0100141static int s390_subchannel_remove_chpid(struct subchannel *sch, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142{
Cornelia Huck2ec22982006-12-08 15:54:26 +0100143 spin_lock_irq(sch->lock);
Cornelia Huckc820de32008-07-14 09:58:45 +0200144 if (sch->driver && sch->driver->chp_event)
145 if (sch->driver->chp_event(sch, data, CHP_OFFLINE) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 goto out_unreg;
Cornelia Huck2ec22982006-12-08 15:54:26 +0100147 spin_unlock_irq(sch->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 return 0;
Stefan Bader387b7342007-04-27 16:01:33 +0200149
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150out_unreg:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 sch->lpm = 0;
Stefan Bader387b7342007-04-27 16:01:33 +0200152 spin_unlock_irq(sch->lock);
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200153 css_schedule_eval(sch->schid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 return 0;
155}
156
Peter Oberparleitere6b6e102007-04-27 16:01:28 +0200157void chsc_chp_offline(struct chp_id chpid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158{
159 char dbf_txt[15];
Cornelia Huck99611f82008-07-14 09:59:02 +0200160 struct chp_link link;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161
Peter Oberparleiterf86635f2007-04-27 16:01:26 +0200162 sprintf(dbf_txt, "chpr%x.%02x", chpid.cssid, chpid.id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 CIO_TRACE_EVENT(2, dbf_txt);
164
Peter Oberparleitere6b6e102007-04-27 16:01:28 +0200165 if (chp_get_status(chpid) <= 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 return;
Cornelia Huck99611f82008-07-14 09:59:02 +0200167 memset(&link, 0, sizeof(struct chp_link));
168 link.chpid = chpid;
Cornelia Huck22806dc2008-04-17 07:45:59 +0200169 /* Wait until previous actions have settled. */
170 css_wait_for_slow_path();
Cornelia Huck99611f82008-07-14 09:59:02 +0200171 for_each_subchannel_staged(s390_subchannel_remove_chpid, NULL, &link);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172}
173
Peter Oberparleitere82a1562008-01-26 14:10:48 +0100174static int s390_process_res_acc_new_sch(struct subchannel_id schid, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175{
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800176 struct schib schib;
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800177 /*
178 * We don't know the device yet, but since a path
179 * may be available now to the device we'll have
180 * to do recognition again.
181 * Since we don't have any idea about which chpid
182 * that beast may be on we'll have to do a stsch
183 * on all devices, grr...
184 */
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800185 if (stsch_err(schid, &schib))
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800186 /* We're through */
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200187 return -ENXIO;
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800188
189 /* Put it on the slow path. */
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200190 css_schedule_eval(schid);
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800191 return 0;
192}
193
Peter Oberparleitere82a1562008-01-26 14:10:48 +0100194static int __s390_process_res_acc(struct subchannel *sch, void *data)
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800195{
Cornelia Huck2ec22982006-12-08 15:54:26 +0100196 spin_lock_irq(sch->lock);
Cornelia Huckc820de32008-07-14 09:58:45 +0200197 if (sch->driver && sch->driver->chp_event)
198 sch->driver->chp_event(sch, data, CHP_ONLINE);
Cornelia Huck2ec22982006-12-08 15:54:26 +0100199 spin_unlock_irq(sch->lock);
Peter Oberparleitere82a1562008-01-26 14:10:48 +0100200
Peter Oberparleiterdd9963f2006-09-20 15:59:54 +0200201 return 0;
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800202}
203
Cornelia Huck99611f82008-07-14 09:59:02 +0200204static void s390_process_res_acc(struct chp_link *link)
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800205{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 char dbf_txt[15];
207
Cornelia Huck99611f82008-07-14 09:59:02 +0200208 sprintf(dbf_txt, "accpr%x.%02x", link->chpid.cssid,
209 link->chpid.id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 CIO_TRACE_EVENT( 2, dbf_txt);
Cornelia Huck99611f82008-07-14 09:59:02 +0200211 if (link->fla != 0) {
212 sprintf(dbf_txt, "fla%x", link->fla);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 CIO_TRACE_EVENT( 2, dbf_txt);
214 }
Cornelia Huck22806dc2008-04-17 07:45:59 +0200215 /* Wait until previous actions have settled. */
216 css_wait_for_slow_path();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 /*
218 * I/O resources may have become accessible.
219 * Scan through all subchannels that may be concerned and
220 * do a validation on those.
221 * The more information we have (info), the less scanning
222 * will we have to do.
223 */
Peter Oberparleitere82a1562008-01-26 14:10:48 +0100224 for_each_subchannel_staged(__s390_process_res_acc,
Cornelia Huck99611f82008-07-14 09:59:02 +0200225 s390_process_res_acc_new_sch, link);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226}
227
228static int
229__get_chpid_from_lir(void *data)
230{
231 struct lir {
232 u8 iq;
233 u8 ic;
234 u16 sci;
235 /* incident-node descriptor */
236 u32 indesc[28];
237 /* attached-node descriptor */
238 u32 andesc[28];
239 /* incident-specific information */
240 u32 isinfo[28];
Peter Oberparleiter0f008aa2007-02-05 21:17:40 +0100241 } __attribute__ ((packed)) *lir;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242
Cornelia Huck12975ae2006-10-11 15:31:47 +0200243 lir = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 if (!(lir->iq&0x80))
245 /* NULL link incident record */
246 return -EINVAL;
247 if (!(lir->indesc[0]&0xc0000000))
248 /* node descriptor not valid */
249 return -EINVAL;
250 if (!(lir->indesc[0]&0x10000000))
251 /* don't handle device-type nodes - FIXME */
252 return -EINVAL;
253 /* Byte 3 contains the chpid. Could also be CTCA, but we don't care */
254
255 return (u16) (lir->indesc[0]&0x000000ff);
256}
257
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100258struct chsc_sei_area {
259 struct chsc_header request;
260 u32 reserved1;
261 u32 reserved2;
262 u32 reserved3;
263 struct chsc_header response;
264 u32 reserved4;
265 u8 flags;
266 u8 vf; /* validity flags */
267 u8 rs; /* reporting source */
268 u8 cc; /* content code */
269 u16 fla; /* full link address */
270 u16 rsid; /* reporting source id */
271 u32 reserved5;
272 u32 reserved6;
273 u8 ccdf[4096 - 16 - 24]; /* content-code dependent field */
274 /* ccdf has to be big enough for a link-incident record */
275} __attribute__ ((packed));
276
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200277static void chsc_process_sei_link_incident(struct chsc_sei_area *sei_area)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278{
Peter Oberparleiterf86635f2007-04-27 16:01:26 +0200279 struct chp_id chpid;
280 int id;
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100281
282 CIO_CRW_EVENT(4, "chsc: link incident (rs=%02x, rs_id=%04x)\n",
283 sei_area->rs, sei_area->rsid);
284 if (sei_area->rs != 4)
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200285 return;
Peter Oberparleiterf86635f2007-04-27 16:01:26 +0200286 id = __get_chpid_from_lir(sei_area->ccdf);
287 if (id < 0)
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100288 CIO_CRW_EVENT(4, "chsc: link incident - invalid LIR\n");
Peter Oberparleiterf86635f2007-04-27 16:01:26 +0200289 else {
290 chp_id_init(&chpid);
291 chpid.id = id;
Peter Oberparleitere6b6e102007-04-27 16:01:28 +0200292 chsc_chp_offline(chpid);
Peter Oberparleiterf86635f2007-04-27 16:01:26 +0200293 }
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100294}
295
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200296static void chsc_process_sei_res_acc(struct chsc_sei_area *sei_area)
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100297{
Cornelia Huck99611f82008-07-14 09:59:02 +0200298 struct chp_link link;
Peter Oberparleiterf86635f2007-04-27 16:01:26 +0200299 struct chp_id chpid;
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100300 int status;
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100301
302 CIO_CRW_EVENT(4, "chsc: resource accessibility event (rs=%02x, "
303 "rs_id=%04x)\n", sei_area->rs, sei_area->rsid);
304 if (sei_area->rs != 4)
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200305 return;
Peter Oberparleiterf86635f2007-04-27 16:01:26 +0200306 chp_id_init(&chpid);
307 chpid.id = sei_area->rsid;
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100308 /* allocate a new channel path structure, if needed */
Peter Oberparleitere6b6e102007-04-27 16:01:28 +0200309 status = chp_get_status(chpid);
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100310 if (status < 0)
Peter Oberparleitere6b6e102007-04-27 16:01:28 +0200311 chp_new(chpid);
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100312 else if (!status)
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200313 return;
Cornelia Huck99611f82008-07-14 09:59:02 +0200314 memset(&link, 0, sizeof(struct chp_link));
315 link.chpid = chpid;
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100316 if ((sei_area->vf & 0xc0) != 0) {
Cornelia Huck99611f82008-07-14 09:59:02 +0200317 link.fla = sei_area->fla;
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100318 if ((sei_area->vf & 0xc0) == 0xc0)
319 /* full link address */
Cornelia Huck99611f82008-07-14 09:59:02 +0200320 link.fla_mask = 0xffff;
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100321 else
322 /* link address */
Cornelia Huck99611f82008-07-14 09:59:02 +0200323 link.fla_mask = 0xff00;
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100324 }
Cornelia Huck99611f82008-07-14 09:59:02 +0200325 s390_process_res_acc(&link);
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100326}
327
Sebastian Ottfca894ed2011-05-23 10:24:41 +0200328static void chsc_process_sei_chp_avail(struct chsc_sei_area *sei_area)
329{
330 struct channel_path *chp;
331 struct chp_id chpid;
332 u8 *data;
333 int num;
334
335 CIO_CRW_EVENT(4, "chsc: channel path availability information\n");
336 if (sei_area->rs != 0)
337 return;
338 data = sei_area->ccdf;
339 chp_id_init(&chpid);
340 for (num = 0; num <= __MAX_CHPID; num++) {
341 if (!chp_test_bit(data, num))
342 continue;
343 chpid.id = num;
344
345 CIO_CRW_EVENT(4, "Update information for channel path "
346 "%x.%02x\n", chpid.cssid, chpid.id);
347 chp = chpid_to_chp(chpid);
348 if (!chp) {
349 chp_new(chpid);
350 continue;
351 }
352 mutex_lock(&chp->lock);
353 chsc_determine_base_channel_path_desc(chpid, &chp->desc);
354 mutex_unlock(&chp->lock);
355 }
356}
357
Peter Oberparleitere5854a52007-04-27 16:01:31 +0200358struct chp_config_data {
359 u8 map[32];
360 u8 op;
361 u8 pc;
362};
363
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200364static void chsc_process_sei_chp_config(struct chsc_sei_area *sei_area)
Peter Oberparleitere5854a52007-04-27 16:01:31 +0200365{
366 struct chp_config_data *data;
367 struct chp_id chpid;
368 int num;
Michael Ernste6d5a422008-12-25 13:39:36 +0100369 char *events[3] = {"configure", "deconfigure", "cancel deconfigure"};
Peter Oberparleitere5854a52007-04-27 16:01:31 +0200370
371 CIO_CRW_EVENT(4, "chsc: channel-path-configuration notification\n");
372 if (sei_area->rs != 0)
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200373 return;
Peter Oberparleitere5854a52007-04-27 16:01:31 +0200374 data = (struct chp_config_data *) &(sei_area->ccdf);
375 chp_id_init(&chpid);
376 for (num = 0; num <= __MAX_CHPID; num++) {
377 if (!chp_test_bit(data->map, num))
378 continue;
379 chpid.id = num;
Michael Ernste6d5a422008-12-25 13:39:36 +0100380 pr_notice("Processing %s for channel path %x.%02x\n",
381 events[data->op], chpid.cssid, chpid.id);
Peter Oberparleitere5854a52007-04-27 16:01:31 +0200382 switch (data->op) {
383 case 0:
384 chp_cfg_schedule(chpid, 1);
385 break;
386 case 1:
387 chp_cfg_schedule(chpid, 0);
388 break;
389 case 2:
390 chp_cfg_cancel_deconfigure(chpid);
391 break;
392 }
393 }
Peter Oberparleitere5854a52007-04-27 16:01:31 +0200394}
395
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200396static void chsc_process_sei(struct chsc_sei_area *sei_area)
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100397{
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100398 /* Check if we might have lost some information. */
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200399 if (sei_area->flags & 0x40) {
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100400 CIO_CRW_EVENT(2, "chsc: event overflow\n");
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200401 css_schedule_eval_all();
402 }
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100403 /* which kind of information was stored? */
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100404 switch (sei_area->cc) {
405 case 1: /* link incident*/
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200406 chsc_process_sei_link_incident(sei_area);
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100407 break;
Sebastian Ottfca894ed2011-05-23 10:24:41 +0200408 case 2: /* i/o resource accessibility */
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200409 chsc_process_sei_res_acc(sei_area);
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100410 break;
Sebastian Ottfca894ed2011-05-23 10:24:41 +0200411 case 7: /* channel-path-availability information */
412 chsc_process_sei_chp_avail(sei_area);
413 break;
Peter Oberparleitere5854a52007-04-27 16:01:31 +0200414 case 8: /* channel-path-configuration notification */
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200415 chsc_process_sei_chp_config(sei_area);
Peter Oberparleitere5854a52007-04-27 16:01:31 +0200416 break;
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100417 default: /* other stuff */
418 CIO_CRW_EVENT(4, "chsc: unhandled sei content code %d\n",
419 sei_area->cc);
420 break;
421 }
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100422}
423
Cornelia Huckc1156182008-07-14 09:58:46 +0200424static void chsc_process_crw(struct crw *crw0, struct crw *crw1, int overflow)
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100425{
426 struct chsc_sei_area *sei_area;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427
Cornelia Huckc1156182008-07-14 09:58:46 +0200428 if (overflow) {
429 css_schedule_eval_all();
430 return;
431 }
432 CIO_CRW_EVENT(2, "CRW reports slct=%d, oflw=%d, "
433 "chn=%d, rsc=%X, anc=%d, erc=%X, rsid=%X\n",
434 crw0->slct, crw0->oflw, crw0->chn, crw0->rsc, crw0->anc,
435 crw0->erc, crw0->rsid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 if (!sei_page)
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200437 return;
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100438 /* Access to sei_page is serialized through machine check handler
439 * thread, so no need for locking. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 sei_area = sei_page;
441
Cornelia Huckc1156182008-07-14 09:58:46 +0200442 CIO_TRACE_EVENT(2, "prcss");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 do {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 memset(sei_area, 0, sizeof(*sei_area));
Cornelia Huck495a5b42006-03-24 03:15:14 -0800445 sei_area->request.length = 0x0010;
446 sei_area->request.code = 0x000e;
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100447 if (chsc(sei_area))
448 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100450 if (sei_area->response.code == 0x0001) {
451 CIO_CRW_EVENT(4, "chsc: sei successful\n");
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200452 chsc_process_sei(sei_area);
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100453 } else {
454 CIO_CRW_EVENT(2, "chsc: sei failed (rc=%04x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 sei_area->response.code);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 break;
457 }
458 } while (sei_area->flags & 0x80);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459}
460
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200461void chsc_chp_online(struct chp_id chpid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 char dbf_txt[15];
Cornelia Huck99611f82008-07-14 09:59:02 +0200464 struct chp_link link;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465
Peter Oberparleiterf86635f2007-04-27 16:01:26 +0200466 sprintf(dbf_txt, "cadd%x.%02x", chpid.cssid, chpid.id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 CIO_TRACE_EVENT(2, dbf_txt);
468
Cornelia Huck22806dc2008-04-17 07:45:59 +0200469 if (chp_get_status(chpid) != 0) {
Cornelia Huck99611f82008-07-14 09:59:02 +0200470 memset(&link, 0, sizeof(struct chp_link));
471 link.chpid = chpid;
Cornelia Huck22806dc2008-04-17 07:45:59 +0200472 /* Wait until previous actions have settled. */
473 css_wait_for_slow_path();
Cornelia Huckc820de32008-07-14 09:58:45 +0200474 for_each_subchannel_staged(__s390_process_res_acc, NULL,
Cornelia Huck99611f82008-07-14 09:59:02 +0200475 &link);
Cornelia Huck22806dc2008-04-17 07:45:59 +0200476 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477}
478
Peter Oberparleiterf86635f2007-04-27 16:01:26 +0200479static void __s390_subchannel_vary_chpid(struct subchannel *sch,
480 struct chp_id chpid, int on)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 unsigned long flags;
Cornelia Huck99611f82008-07-14 09:59:02 +0200483 struct chp_link link;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484
Cornelia Huck99611f82008-07-14 09:59:02 +0200485 memset(&link, 0, sizeof(struct chp_link));
486 link.chpid = chpid;
Cornelia Huck2ec22982006-12-08 15:54:26 +0100487 spin_lock_irqsave(sch->lock, flags);
Cornelia Huckc820de32008-07-14 09:58:45 +0200488 if (sch->driver && sch->driver->chp_event)
Cornelia Huck99611f82008-07-14 09:59:02 +0200489 sch->driver->chp_event(sch, &link,
Cornelia Huckc820de32008-07-14 09:58:45 +0200490 on ? CHP_VARY_ON : CHP_VARY_OFF);
Cornelia Huck2ec22982006-12-08 15:54:26 +0100491 spin_unlock_irqrestore(sch->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492}
493
Peter Oberparleitere82a1562008-01-26 14:10:48 +0100494static int s390_subchannel_vary_chpid_off(struct subchannel *sch, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495{
Peter Oberparleitere82a1562008-01-26 14:10:48 +0100496 struct chp_id *chpid = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497
498 __s390_subchannel_vary_chpid(sch, *chpid, 0);
499 return 0;
500}
501
Peter Oberparleitere82a1562008-01-26 14:10:48 +0100502static int s390_subchannel_vary_chpid_on(struct subchannel *sch, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503{
Peter Oberparleitere82a1562008-01-26 14:10:48 +0100504 struct chp_id *chpid = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505
506 __s390_subchannel_vary_chpid(sch, *chpid, 1);
507 return 0;
508}
509
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800510static int
511__s390_vary_chpid_on(struct subchannel_id schid, void *data)
512{
513 struct schib schib;
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800514
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800515 if (stsch_err(schid, &schib))
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800516 /* We're through */
517 return -ENXIO;
518 /* Put it on the slow path. */
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200519 css_schedule_eval(schid);
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800520 return 0;
521}
522
Peter Oberparleitere6b6e102007-04-27 16:01:28 +0200523/**
524 * chsc_chp_vary - propagate channel-path vary operation to subchannels
525 * @chpid: channl-path ID
526 * @on: non-zero for vary online, zero for vary offline
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 */
Peter Oberparleitere6b6e102007-04-27 16:01:28 +0200528int chsc_chp_vary(struct chp_id chpid, int on)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529{
Sebastian Ottc38a90a2010-10-25 16:10:31 +0200530 struct channel_path *chp = chpid_to_chp(chpid);
Cornelia Huck99611f82008-07-14 09:59:02 +0200531
Cornelia Huck22806dc2008-04-17 07:45:59 +0200532 /* Wait until previous actions have settled. */
533 css_wait_for_slow_path();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 /*
535 * Redo PathVerification on the devices the chpid connects to
536 */
Sebastian Ottc38a90a2010-10-25 16:10:31 +0200537 if (on) {
538 /* Try to update the channel path descritor. */
539 chsc_determine_base_channel_path_desc(chpid, &chp->desc);
Peter Oberparleitere82a1562008-01-26 14:10:48 +0100540 for_each_subchannel_staged(s390_subchannel_vary_chpid_on,
Sebastian Ott3b484ec2011-12-01 13:32:22 +0100541 __s390_vary_chpid_on, &chpid);
Sebastian Ottc38a90a2010-10-25 16:10:31 +0200542 } else
Peter Oberparleitere82a1562008-01-26 14:10:48 +0100543 for_each_subchannel_staged(s390_subchannel_vary_chpid_off,
Sebastian Ott3b484ec2011-12-01 13:32:22 +0100544 NULL, &chpid);
Peter Oberparleitere82a1562008-01-26 14:10:48 +0100545
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 return 0;
547}
548
Cornelia Huck495a5b42006-03-24 03:15:14 -0800549static void
550chsc_remove_cmg_attr(struct channel_subsystem *css)
551{
552 int i;
553
554 for (i = 0; i <= __MAX_CHPID; i++) {
555 if (!css->chps[i])
556 continue;
Peter Oberparleitere6b6e102007-04-27 16:01:28 +0200557 chp_remove_cmg_attr(css->chps[i]);
Cornelia Huck495a5b42006-03-24 03:15:14 -0800558 }
559}
560
561static int
562chsc_add_cmg_attr(struct channel_subsystem *css)
563{
564 int i, ret;
565
566 ret = 0;
567 for (i = 0; i <= __MAX_CHPID; i++) {
568 if (!css->chps[i])
569 continue;
Peter Oberparleitere6b6e102007-04-27 16:01:28 +0200570 ret = chp_add_cmg_attr(css->chps[i]);
Cornelia Huck495a5b42006-03-24 03:15:14 -0800571 if (ret)
572 goto cleanup;
573 }
574 return ret;
575cleanup:
576 for (--i; i >= 0; 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 return ret;
582}
583
Sebastian Ott34196f82010-10-25 16:10:29 +0200584int __chsc_do_secm(struct channel_subsystem *css, int enable)
Cornelia Huck495a5b42006-03-24 03:15:14 -0800585{
586 struct {
587 struct chsc_header request;
588 u32 operation_code : 2;
589 u32 : 30;
590 u32 key : 4;
591 u32 : 28;
592 u32 zeroes1;
593 u32 cub_addr1;
594 u32 zeroes2;
595 u32 cub_addr2;
596 u32 reserved[13];
597 struct chsc_header response;
598 u32 status : 8;
599 u32 : 4;
600 u32 fmt : 4;
601 u32 : 16;
Peter Oberparleiter0f008aa2007-02-05 21:17:40 +0100602 } __attribute__ ((packed)) *secm_area;
Cornelia Huck495a5b42006-03-24 03:15:14 -0800603 int ret, ccode;
604
Sebastian Ott34196f82010-10-25 16:10:29 +0200605 spin_lock_irq(&chsc_page_lock);
606 memset(chsc_page, 0, PAGE_SIZE);
607 secm_area = chsc_page;
Cornelia Huck495a5b42006-03-24 03:15:14 -0800608 secm_area->request.length = 0x0050;
609 secm_area->request.code = 0x0016;
610
Heiko Carstensd1bf8592010-02-26 22:37:30 +0100611 secm_area->key = PAGE_DEFAULT_KEY >> 4;
Cornelia Huck495a5b42006-03-24 03:15:14 -0800612 secm_area->cub_addr1 = (u64)(unsigned long)css->cub_addr1;
613 secm_area->cub_addr2 = (u64)(unsigned long)css->cub_addr2;
614
615 secm_area->operation_code = enable ? 0 : 1;
616
617 ccode = chsc(secm_area);
Sebastian Ott34196f82010-10-25 16:10:29 +0200618 if (ccode > 0) {
619 ret = (ccode == 3) ? -ENODEV : -EBUSY;
620 goto out;
621 }
Cornelia Huck495a5b42006-03-24 03:15:14 -0800622
623 switch (secm_area->response.code) {
Cornelia Huckb9c9a212008-02-05 16:50:34 +0100624 case 0x0102:
625 case 0x0103:
Cornelia Huck495a5b42006-03-24 03:15:14 -0800626 ret = -EINVAL;
Sebastian Ott17e7d872009-03-26 15:24:17 +0100627 break;
Cornelia Huck495a5b42006-03-24 03:15:14 -0800628 default:
Cornelia Huckb9c9a212008-02-05 16:50:34 +0100629 ret = chsc_error_from_response(secm_area->response.code);
Cornelia Huck495a5b42006-03-24 03:15:14 -0800630 }
Cornelia Huckb9c9a212008-02-05 16:50:34 +0100631 if (ret != 0)
632 CIO_CRW_EVENT(2, "chsc: secm failed (rc=%04x)\n",
633 secm_area->response.code);
Sebastian Ott34196f82010-10-25 16:10:29 +0200634out:
635 spin_unlock_irq(&chsc_page_lock);
Cornelia Huck495a5b42006-03-24 03:15:14 -0800636 return ret;
637}
638
639int
640chsc_secm(struct channel_subsystem *css, int enable)
641{
Cornelia Huck495a5b42006-03-24 03:15:14 -0800642 int ret;
643
Cornelia Huck495a5b42006-03-24 03:15:14 -0800644 if (enable && !css->cm_enabled) {
645 css->cub_addr1 = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
646 css->cub_addr2 = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
647 if (!css->cub_addr1 || !css->cub_addr2) {
648 free_page((unsigned long)css->cub_addr1);
649 free_page((unsigned long)css->cub_addr2);
Cornelia Huck495a5b42006-03-24 03:15:14 -0800650 return -ENOMEM;
651 }
652 }
Sebastian Ott34196f82010-10-25 16:10:29 +0200653 ret = __chsc_do_secm(css, enable);
Cornelia Huck495a5b42006-03-24 03:15:14 -0800654 if (!ret) {
655 css->cm_enabled = enable;
656 if (css->cm_enabled) {
657 ret = chsc_add_cmg_attr(css);
658 if (ret) {
Sebastian Ott34196f82010-10-25 16:10:29 +0200659 __chsc_do_secm(css, 0);
Cornelia Huck495a5b42006-03-24 03:15:14 -0800660 css->cm_enabled = 0;
661 }
662 } else
663 chsc_remove_cmg_attr(css);
664 }
Cornelia Huck8c4941c2007-04-27 16:01:38 +0200665 if (!css->cm_enabled) {
Cornelia Huck495a5b42006-03-24 03:15:14 -0800666 free_page((unsigned long)css->cub_addr1);
667 free_page((unsigned long)css->cub_addr2);
668 }
Cornelia Huck495a5b42006-03-24 03:15:14 -0800669 return ret;
670}
671
Cornelia Huck9d92a7e2008-07-14 09:59:05 +0200672int chsc_determine_channel_path_desc(struct chp_id chpid, int fmt, int rfmt,
Sebastian Ott906c9762010-10-25 16:10:30 +0200673 int c, int m, void *page)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674{
Sebastian Ott906c9762010-10-25 16:10:30 +0200675 struct chsc_scpd *scpd_area;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 int ccode, ret;
677
Cornelia Huck9d92a7e2008-07-14 09:59:05 +0200678 if ((rfmt == 1) && !css_general_characteristics.fcs)
679 return -EINVAL;
680 if ((rfmt == 2) && !css_general_characteristics.cib)
681 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682
Sebastian Ott906c9762010-10-25 16:10:30 +0200683 memset(page, 0, PAGE_SIZE);
684 scpd_area = page;
Cornelia Huck495a5b42006-03-24 03:15:14 -0800685 scpd_area->request.length = 0x0010;
686 scpd_area->request.code = 0x0002;
Cornelia Huck9d92a7e2008-07-14 09:59:05 +0200687 scpd_area->cssid = chpid.cssid;
Peter Oberparleiterf86635f2007-04-27 16:01:26 +0200688 scpd_area->first_chpid = chpid.id;
689 scpd_area->last_chpid = chpid.id;
Cornelia Huck9d92a7e2008-07-14 09:59:05 +0200690 scpd_area->m = m;
691 scpd_area->c = c;
692 scpd_area->fmt = fmt;
693 scpd_area->rfmt = rfmt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694
695 ccode = chsc(scpd_area);
Sebastian Ott906c9762010-10-25 16:10:30 +0200696 if (ccode > 0)
697 return (ccode == 3) ? -ENODEV : -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698
Cornelia Huckb9c9a212008-02-05 16:50:34 +0100699 ret = chsc_error_from_response(scpd_area->response.code);
Sebastian Ott906c9762010-10-25 16:10:30 +0200700 if (ret)
Cornelia Huckb9c9a212008-02-05 16:50:34 +0100701 CIO_CRW_EVENT(2, "chsc: scpd failed (rc=%04x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 scpd_area->response.code);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 return ret;
704}
Cornelia Huck9d92a7e2008-07-14 09:59:05 +0200705EXPORT_SYMBOL_GPL(chsc_determine_channel_path_desc);
706
707int chsc_determine_base_channel_path_desc(struct chp_id chpid,
708 struct channel_path_desc *desc)
709{
710 struct chsc_response_struct *chsc_resp;
Sebastian Ott906c9762010-10-25 16:10:30 +0200711 struct chsc_scpd *scpd_area;
Sebastian Ott62da1772010-10-25 16:10:32 +0200712 unsigned long flags;
Cornelia Huck9d92a7e2008-07-14 09:59:05 +0200713 int ret;
714
Sebastian Ott62da1772010-10-25 16:10:32 +0200715 spin_lock_irqsave(&chsc_page_lock, flags);
Sebastian Ott906c9762010-10-25 16:10:30 +0200716 scpd_area = chsc_page;
717 ret = chsc_determine_channel_path_desc(chpid, 0, 0, 0, 0, scpd_area);
Cornelia Huck9d92a7e2008-07-14 09:59:05 +0200718 if (ret)
Sebastian Ott906c9762010-10-25 16:10:30 +0200719 goto out;
720 chsc_resp = (void *)&scpd_area->response;
Sebastian Ott878c4952010-07-19 09:22:37 +0200721 memcpy(desc, &chsc_resp->data, sizeof(*desc));
Sebastian Ott906c9762010-10-25 16:10:30 +0200722out:
Sebastian Ott62da1772010-10-25 16:10:32 +0200723 spin_unlock_irqrestore(&chsc_page_lock, flags);
Cornelia Huck9d92a7e2008-07-14 09:59:05 +0200724 return ret;
725}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726
Sebastian Ottce322cc2011-01-05 12:47:56 +0100727int chsc_determine_fmt1_channel_path_desc(struct chp_id chpid,
728 struct channel_path_desc_fmt1 *desc)
729{
730 struct chsc_response_struct *chsc_resp;
731 struct chsc_scpd *scpd_area;
732 int ret;
733
734 spin_lock_irq(&chsc_page_lock);
735 scpd_area = chsc_page;
736 ret = chsc_determine_channel_path_desc(chpid, 0, 0, 1, 0, scpd_area);
737 if (ret)
738 goto out;
739 chsc_resp = (void *)&scpd_area->response;
740 memcpy(desc, &chsc_resp->data, sizeof(*desc));
741out:
742 spin_unlock_irq(&chsc_page_lock);
743 return ret;
744}
745
Cornelia Huck495a5b42006-03-24 03:15:14 -0800746static void
747chsc_initialize_cmg_chars(struct channel_path *chp, u8 cmcv,
748 struct cmg_chars *chars)
749{
Sebastian Ott34196f82010-10-25 16:10:29 +0200750 struct cmg_chars *cmg_chars;
751 int i, mask;
Cornelia Huck495a5b42006-03-24 03:15:14 -0800752
Sebastian Ott34196f82010-10-25 16:10:29 +0200753 cmg_chars = chp->cmg_chars;
754 for (i = 0; i < NR_MEASUREMENT_CHARS; i++) {
755 mask = 0x80 >> (i + 3);
756 if (cmcv & mask)
757 cmg_chars->values[i] = chars->values[i];
758 else
759 cmg_chars->values[i] = 0;
Cornelia Huck495a5b42006-03-24 03:15:14 -0800760 }
761}
762
Peter Oberparleitere6b6e102007-04-27 16:01:28 +0200763int chsc_get_channel_measurement_chars(struct channel_path *chp)
Cornelia Huck495a5b42006-03-24 03:15:14 -0800764{
Sebastian Ott34196f82010-10-25 16:10:29 +0200765 struct cmg_chars *cmg_chars;
Cornelia Huck495a5b42006-03-24 03:15:14 -0800766 int ccode, ret;
767
768 struct {
769 struct chsc_header request;
770 u32 : 24;
771 u32 first_chpid : 8;
772 u32 : 24;
773 u32 last_chpid : 8;
774 u32 zeroes1;
775 struct chsc_header response;
776 u32 zeroes2;
777 u32 not_valid : 1;
778 u32 shared : 1;
779 u32 : 22;
780 u32 chpid : 8;
781 u32 cmcv : 5;
782 u32 : 11;
783 u32 cmgq : 8;
784 u32 cmg : 8;
785 u32 zeroes3;
786 u32 data[NR_MEASUREMENT_CHARS];
Peter Oberparleiter0f008aa2007-02-05 21:17:40 +0100787 } __attribute__ ((packed)) *scmc_area;
Cornelia Huck495a5b42006-03-24 03:15:14 -0800788
Sebastian Ott34196f82010-10-25 16:10:29 +0200789 chp->cmg_chars = NULL;
790 cmg_chars = kmalloc(sizeof(*cmg_chars), GFP_KERNEL);
791 if (!cmg_chars)
Cornelia Huck495a5b42006-03-24 03:15:14 -0800792 return -ENOMEM;
793
Sebastian Ott34196f82010-10-25 16:10:29 +0200794 spin_lock_irq(&chsc_page_lock);
795 memset(chsc_page, 0, PAGE_SIZE);
796 scmc_area = chsc_page;
Cornelia Huck495a5b42006-03-24 03:15:14 -0800797 scmc_area->request.length = 0x0010;
798 scmc_area->request.code = 0x0022;
Peter Oberparleiterf86635f2007-04-27 16:01:26 +0200799 scmc_area->first_chpid = chp->chpid.id;
800 scmc_area->last_chpid = chp->chpid.id;
Cornelia Huck495a5b42006-03-24 03:15:14 -0800801
802 ccode = chsc(scmc_area);
803 if (ccode > 0) {
804 ret = (ccode == 3) ? -ENODEV : -EBUSY;
805 goto out;
806 }
807
Cornelia Huckb9c9a212008-02-05 16:50:34 +0100808 ret = chsc_error_from_response(scmc_area->response.code);
Sebastian Ott34196f82010-10-25 16:10:29 +0200809 if (ret) {
Cornelia Huckb9c9a212008-02-05 16:50:34 +0100810 CIO_CRW_EVENT(2, "chsc: scmc failed (rc=%04x)\n",
Cornelia Huck495a5b42006-03-24 03:15:14 -0800811 scmc_area->response.code);
Sebastian Ott34196f82010-10-25 16:10:29 +0200812 goto out;
Cornelia Huck495a5b42006-03-24 03:15:14 -0800813 }
Sebastian Ott34196f82010-10-25 16:10:29 +0200814 if (scmc_area->not_valid) {
815 chp->cmg = -1;
816 chp->shared = -1;
817 goto out;
818 }
819 chp->cmg = scmc_area->cmg;
820 chp->shared = scmc_area->shared;
821 if (chp->cmg != 2 && chp->cmg != 3) {
822 /* No cmg-dependent data. */
823 goto out;
824 }
825 chp->cmg_chars = cmg_chars;
826 chsc_initialize_cmg_chars(chp, scmc_area->cmcv,
827 (struct cmg_chars *) &scmc_area->data);
Cornelia Huck495a5b42006-03-24 03:15:14 -0800828out:
Sebastian Ott34196f82010-10-25 16:10:29 +0200829 spin_unlock_irq(&chsc_page_lock);
830 if (!chp->cmg_chars)
831 kfree(cmg_chars);
832
Cornelia Huck495a5b42006-03-24 03:15:14 -0800833 return ret;
834}
835
Sebastian Ott34aec072010-10-25 16:10:28 +0200836int __init chsc_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837{
Cornelia Huckc1156182008-07-14 09:58:46 +0200838 int ret;
839
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840 sei_page = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
Sebastian Ott34196f82010-10-25 16:10:29 +0200841 chsc_page = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
842 if (!sei_page || !chsc_page) {
843 ret = -ENOMEM;
844 goto out_err;
Cornelia Huckc1156182008-07-14 09:58:46 +0200845 }
Heiko Carstensf5daba12009-03-26 15:24:01 +0100846 ret = crw_register_handler(CRW_RSC_CSS, chsc_process_crw);
Cornelia Huckc1156182008-07-14 09:58:46 +0200847 if (ret)
Sebastian Ott34196f82010-10-25 16:10:29 +0200848 goto out_err;
849 return ret;
850out_err:
851 free_page((unsigned long)chsc_page);
852 free_page((unsigned long)sei_page);
Cornelia Huckc1156182008-07-14 09:58:46 +0200853 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854}
855
Sebastian Ott34aec072010-10-25 16:10:28 +0200856void __init chsc_init_cleanup(void)
Cornelia Huck4434a382007-07-27 12:29:21 +0200857{
Heiko Carstensf5daba12009-03-26 15:24:01 +0100858 crw_unregister_handler(CRW_RSC_CSS);
Sebastian Ott34196f82010-10-25 16:10:29 +0200859 free_page((unsigned long)chsc_page);
Sebastian Ott34aec072010-10-25 16:10:28 +0200860 free_page((unsigned long)sei_page);
Cornelia Huck4434a382007-07-27 12:29:21 +0200861}
862
Sebastian Ott818c2722010-04-22 17:17:03 +0200863int chsc_enable_facility(int operation_code)
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800864{
Sebastian Ott34196f82010-10-25 16:10:29 +0200865 unsigned long flags;
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800866 int ret;
Sebastian Ott34196f82010-10-25 16:10:29 +0200867 struct {
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800868 struct chsc_header request;
869 u8 reserved1:4;
870 u8 format:4;
871 u8 reserved2;
872 u16 operation_code;
873 u32 reserved3;
874 u32 reserved4;
875 u32 operation_data_area[252];
876 struct chsc_header response;
877 u32 reserved5:4;
878 u32 format2:4;
879 u32 reserved6:24;
Sebastian Ott34196f82010-10-25 16:10:29 +0200880 } __attribute__ ((packed)) *sda_area;
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800881
Sebastian Ott34196f82010-10-25 16:10:29 +0200882 spin_lock_irqsave(&chsc_page_lock, flags);
883 memset(chsc_page, 0, PAGE_SIZE);
884 sda_area = chsc_page;
885 sda_area->request.length = 0x0400;
886 sda_area->request.code = 0x0031;
887 sda_area->operation_code = operation_code;
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800888
Sebastian Ott34196f82010-10-25 16:10:29 +0200889 ret = chsc(sda_area);
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800890 if (ret > 0) {
891 ret = (ret == 3) ? -ENODEV : -EBUSY;
892 goto out;
893 }
Cornelia Huckb9c9a212008-02-05 16:50:34 +0100894
Sebastian Ott34196f82010-10-25 16:10:29 +0200895 switch (sda_area->response.code) {
Cornelia Huckb9c9a212008-02-05 16:50:34 +0100896 case 0x0101:
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800897 ret = -EOPNOTSUPP;
898 break;
Cornelia Huckb9c9a212008-02-05 16:50:34 +0100899 default:
Sebastian Ott34196f82010-10-25 16:10:29 +0200900 ret = chsc_error_from_response(sda_area->response.code);
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800901 }
Cornelia Huckb9c9a212008-02-05 16:50:34 +0100902 if (ret != 0)
903 CIO_CRW_EVENT(2, "chsc: sda (oc=%x) failed (rc=%04x)\n",
Sebastian Ott34196f82010-10-25 16:10:29 +0200904 operation_code, sda_area->response.code);
905out:
906 spin_unlock_irqrestore(&chsc_page_lock, flags);
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800907 return ret;
908}
909
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910struct css_general_char css_general_characteristics;
911struct css_chsc_char css_chsc_characteristics;
912
913int __init
914chsc_determine_css_characteristics(void)
915{
916 int result;
917 struct {
918 struct chsc_header request;
919 u32 reserved1;
920 u32 reserved2;
921 u32 reserved3;
922 struct chsc_header response;
923 u32 reserved4;
924 u32 general_char[510];
Sebastian Ott34aec072010-10-25 16:10:28 +0200925 u32 chsc_char[508];
Peter Oberparleiter0f008aa2007-02-05 21:17:40 +0100926 } __attribute__ ((packed)) *scsc_area;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927
Sebastian Ott34196f82010-10-25 16:10:29 +0200928 spin_lock_irq(&chsc_page_lock);
929 memset(chsc_page, 0, PAGE_SIZE);
930 scsc_area = chsc_page;
Cornelia Huck495a5b42006-03-24 03:15:14 -0800931 scsc_area->request.length = 0x0010;
932 scsc_area->request.code = 0x0010;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933
934 result = chsc(scsc_area);
935 if (result) {
Cornelia Huckb9c9a212008-02-05 16:50:34 +0100936 result = (result == 3) ? -ENODEV : -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937 goto exit;
938 }
939
Cornelia Huckb9c9a212008-02-05 16:50:34 +0100940 result = chsc_error_from_response(scsc_area->response.code);
941 if (result == 0) {
942 memcpy(&css_general_characteristics, scsc_area->general_char,
943 sizeof(css_general_characteristics));
944 memcpy(&css_chsc_characteristics, scsc_area->chsc_char,
945 sizeof(css_chsc_characteristics));
946 } else
947 CIO_CRW_EVENT(2, "chsc: scsc failed (rc=%04x)\n",
948 scsc_area->response.code);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949exit:
Sebastian Ott34196f82010-10-25 16:10:29 +0200950 spin_unlock_irq(&chsc_page_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951 return result;
952}
953
954EXPORT_SYMBOL_GPL(css_general_characteristics);
955EXPORT_SYMBOL_GPL(css_chsc_characteristics);
Martin Schwidefskyd2fec592008-07-14 09:58:56 +0200956
957int chsc_sstpc(void *page, unsigned int op, u16 ctrl)
958{
959 struct {
960 struct chsc_header request;
961 unsigned int rsvd0;
962 unsigned int op : 8;
963 unsigned int rsvd1 : 8;
964 unsigned int ctrl : 16;
965 unsigned int rsvd2[5];
966 struct chsc_header response;
967 unsigned int rsvd3[7];
968 } __attribute__ ((packed)) *rr;
969 int rc;
970
971 memset(page, 0, PAGE_SIZE);
972 rr = page;
973 rr->request.length = 0x0020;
974 rr->request.code = 0x0033;
975 rr->op = op;
976 rr->ctrl = ctrl;
977 rc = chsc(rr);
978 if (rc)
979 return -EIO;
980 rc = (rr->response.code == 0x0001) ? 0 : -EIO;
981 return rc;
982}
983
984int chsc_sstpi(void *page, void *result, size_t size)
985{
986 struct {
987 struct chsc_header request;
988 unsigned int rsvd0[3];
989 struct chsc_header response;
990 char data[size];
991 } __attribute__ ((packed)) *rr;
992 int rc;
993
994 memset(page, 0, PAGE_SIZE);
995 rr = page;
996 rr->request.length = 0x0010;
997 rr->request.code = 0x0038;
998 rc = chsc(rr);
999 if (rc)
1000 return -EIO;
1001 memcpy(result, &rr->data, size);
1002 return (rr->response.code == 0x0001) ? 0 : -EIO;
1003}
1004
Michael Ernstfd0457a2010-08-09 18:12:50 +02001005int chsc_siosl(struct subchannel_id schid)
1006{
Sebastian Ott34196f82010-10-25 16:10:29 +02001007 struct {
1008 struct chsc_header request;
1009 u32 word1;
1010 struct subchannel_id sid;
1011 u32 word3;
1012 struct chsc_header response;
1013 u32 word[11];
1014 } __attribute__ ((packed)) *siosl_area;
Michael Ernstfd0457a2010-08-09 18:12:50 +02001015 unsigned long flags;
1016 int ccode;
1017 int rc;
1018
Sebastian Ott34196f82010-10-25 16:10:29 +02001019 spin_lock_irqsave(&chsc_page_lock, flags);
1020 memset(chsc_page, 0, PAGE_SIZE);
1021 siosl_area = chsc_page;
1022 siosl_area->request.length = 0x0010;
1023 siosl_area->request.code = 0x0046;
1024 siosl_area->word1 = 0x80000000;
1025 siosl_area->sid = schid;
Michael Ernstfd0457a2010-08-09 18:12:50 +02001026
Sebastian Ott34196f82010-10-25 16:10:29 +02001027 ccode = chsc(siosl_area);
Michael Ernstfd0457a2010-08-09 18:12:50 +02001028 if (ccode > 0) {
1029 if (ccode == 3)
1030 rc = -ENODEV;
1031 else
1032 rc = -EBUSY;
1033 CIO_MSG_EVENT(2, "chsc: chsc failed for 0.%x.%04x (ccode=%d)\n",
1034 schid.ssid, schid.sch_no, ccode);
1035 goto out;
1036 }
Sebastian Ott34196f82010-10-25 16:10:29 +02001037 rc = chsc_error_from_response(siosl_area->response.code);
Michael Ernstfd0457a2010-08-09 18:12:50 +02001038 if (rc)
1039 CIO_MSG_EVENT(2, "chsc: siosl failed for 0.%x.%04x (rc=%04x)\n",
1040 schid.ssid, schid.sch_no,
Sebastian Ott34196f82010-10-25 16:10:29 +02001041 siosl_area->response.code);
Michael Ernstfd0457a2010-08-09 18:12:50 +02001042 else
1043 CIO_MSG_EVENT(4, "chsc: siosl succeeded for 0.%x.%04x\n",
1044 schid.ssid, schid.sch_no);
1045out:
Sebastian Ott34196f82010-10-25 16:10:29 +02001046 spin_unlock_irqrestore(&chsc_page_lock, flags);
Michael Ernstfd0457a2010-08-09 18:12:50 +02001047 return rc;
1048}
1049EXPORT_SYMBOL_GPL(chsc_siosl);