blob: d119d0d87e9bf68b784b615d60122ad63f8770d7 [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 *
Jan Glaubercbc0dd12012-11-29 14:34:48 +01004 * Copyright IBM Corp. 1999,2012
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>
Jan Glaubercbc0dd12012-11-29 14:34:48 +010017#include <linux/pci.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018
19#include <asm/cio.h>
Peter Oberparleitere5854a52007-04-27 16:01:31 +020020#include <asm/chpid.h>
Cornelia Huck9d92a7e2008-07-14 09:59:05 +020021#include <asm/chsc.h>
Heiko Carstensf5daba12009-03-26 15:24:01 +010022#include <asm/crw.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023
24#include "css.h"
25#include "cio.h"
26#include "cio_debug.h"
27#include "ioasm.h"
Peter Oberparleitere6b6e102007-04-27 16:01:28 +020028#include "chp.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include "chsc.h"
30
Linus Torvalds1da177e2005-04-16 15:20:36 -070031static void *sei_page;
Sebastian Ott34196f82010-10-25 16:10:29 +020032static void *chsc_page;
33static DEFINE_SPINLOCK(chsc_page_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
Cornelia Huckdae39842008-07-17 17:16:47 +020035/**
36 * chsc_error_from_response() - convert a chsc response to an error
37 * @response: chsc response code
38 *
39 * Returns an appropriate Linux error code for @response.
40 */
41int chsc_error_from_response(int response)
Cornelia Huckb9c9a212008-02-05 16:50:34 +010042{
43 switch (response) {
44 case 0x0001:
45 return 0;
46 case 0x0002:
47 case 0x0003:
48 case 0x0006:
49 case 0x0007:
50 case 0x0008:
51 case 0x000a:
Michael Ernstfd0457a2010-08-09 18:12:50 +020052 case 0x0104:
Cornelia Huckb9c9a212008-02-05 16:50:34 +010053 return -EINVAL;
54 case 0x0004:
55 return -EOPNOTSUPP;
Sebastian Ott184b08a2012-08-28 16:45:42 +020056 case 0x000b:
57 return -EBUSY;
58 case 0x0100:
59 case 0x0102:
60 return -ENOMEM;
Cornelia Huckb9c9a212008-02-05 16:50:34 +010061 default:
62 return -EIO;
63 }
64}
Cornelia Huckdae39842008-07-17 17:16:47 +020065EXPORT_SYMBOL_GPL(chsc_error_from_response);
Cornelia Huckb9c9a212008-02-05 16:50:34 +010066
Peter Oberparleiter7ad6a242007-04-27 16:01:35 +020067struct chsc_ssd_area {
68 struct chsc_header request;
69 u16 :10;
70 u16 ssid:2;
71 u16 :4;
72 u16 f_sch; /* first subchannel */
73 u16 :16;
74 u16 l_sch; /* last subchannel */
75 u32 :32;
76 struct chsc_header response;
77 u32 :32;
78 u8 sch_valid : 1;
79 u8 dev_valid : 1;
80 u8 st : 3; /* subchannel type */
81 u8 zeroes : 3;
82 u8 unit_addr; /* unit address */
83 u16 devno; /* device number */
84 u8 path_mask;
85 u8 fla_valid_mask;
86 u16 sch; /* subchannel */
87 u8 chpid[8]; /* chpids 0-7 */
88 u16 fla[8]; /* full link addresses 0-7 */
89} __attribute__ ((packed));
90
91int chsc_get_ssd_info(struct subchannel_id schid, struct chsc_ssd_info *ssd)
Linus Torvalds1da177e2005-04-16 15:20:36 -070092{
Peter Oberparleiter7ad6a242007-04-27 16:01:35 +020093 struct chsc_ssd_area *ssd_area;
94 int ccode;
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 int ret;
Peter Oberparleiter7ad6a242007-04-27 16:01:35 +020096 int i;
97 int mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -070098
Sebastian Ott34196f82010-10-25 16:10:29 +020099 spin_lock_irq(&chsc_page_lock);
100 memset(chsc_page, 0, PAGE_SIZE);
101 ssd_area = chsc_page;
Peter Oberparleiter7ad6a242007-04-27 16:01:35 +0200102 ssd_area->request.length = 0x0010;
103 ssd_area->request.code = 0x0004;
104 ssd_area->ssid = schid.ssid;
105 ssd_area->f_sch = schid.sch_no;
106 ssd_area->l_sch = schid.sch_no;
Peter Oberparleiterf86635f2007-04-27 16:01:26 +0200107
Peter Oberparleiter7ad6a242007-04-27 16:01:35 +0200108 ccode = chsc(ssd_area);
109 /* Check response. */
110 if (ccode > 0) {
111 ret = (ccode == 3) ? -ENODEV : -EBUSY;
Sebastian Ott34196f82010-10-25 16:10:29 +0200112 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 }
Cornelia Huckb9c9a212008-02-05 16:50:34 +0100114 ret = chsc_error_from_response(ssd_area->response.code);
115 if (ret != 0) {
Peter Oberparleiter7ad6a242007-04-27 16:01:35 +0200116 CIO_MSG_EVENT(2, "chsc: ssd failed for 0.%x.%04x (rc=%04x)\n",
117 schid.ssid, schid.sch_no,
118 ssd_area->response.code);
Sebastian Ott34196f82010-10-25 16:10:29 +0200119 goto out;
Peter Oberparleiter7ad6a242007-04-27 16:01:35 +0200120 }
121 if (!ssd_area->sch_valid) {
122 ret = -ENODEV;
Sebastian Ott34196f82010-10-25 16:10:29 +0200123 goto out;
Peter Oberparleiter7ad6a242007-04-27 16:01:35 +0200124 }
125 /* Copy data */
126 ret = 0;
127 memset(ssd, 0, sizeof(struct chsc_ssd_info));
Cornelia Huckb279a4f2008-01-26 14:10:45 +0100128 if ((ssd_area->st != SUBCHANNEL_TYPE_IO) &&
129 (ssd_area->st != SUBCHANNEL_TYPE_MSG))
Sebastian Ott34196f82010-10-25 16:10:29 +0200130 goto out;
Peter Oberparleiter7ad6a242007-04-27 16:01:35 +0200131 ssd->path_mask = ssd_area->path_mask;
132 ssd->fla_valid_mask = ssd_area->fla_valid_mask;
133 for (i = 0; i < 8; i++) {
134 mask = 0x80 >> i;
135 if (ssd_area->path_mask & mask) {
136 chp_id_init(&ssd->chpid[i]);
137 ssd->chpid[i].id = ssd_area->chpid[i];
138 }
139 if (ssd_area->fla_valid_mask & mask)
140 ssd->fla[i] = ssd_area->fla[i];
141 }
Sebastian Ott34196f82010-10-25 16:10:29 +0200142out:
143 spin_unlock_irq(&chsc_page_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 return ret;
145}
146
Sebastian Ottda5b6cb2013-06-05 18:58:35 +0200147/**
148 * chsc_ssqd() - store subchannel QDIO data (SSQD)
149 * @schid: id of the subchannel on which SSQD is performed
150 * @ssqd: request and response block for SSQD
151 *
152 * Returns 0 on success.
153 */
154int chsc_ssqd(struct subchannel_id schid, struct chsc_ssqd_area *ssqd)
155{
156 memset(ssqd, 0, sizeof(*ssqd));
157 ssqd->request.length = 0x0010;
158 ssqd->request.code = 0x0024;
159 ssqd->first_sch = schid.sch_no;
160 ssqd->last_sch = schid.sch_no;
161 ssqd->ssid = schid.ssid;
162
163 if (chsc(ssqd))
164 return -EIO;
165
166 return chsc_error_from_response(ssqd->response.code);
167}
168EXPORT_SYMBOL_GPL(chsc_ssqd);
169
Peter Oberparleitere82a1562008-01-26 14:10:48 +0100170static int s390_subchannel_remove_chpid(struct subchannel *sch, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171{
Cornelia Huck2ec22982006-12-08 15:54:26 +0100172 spin_lock_irq(sch->lock);
Cornelia Huckc820de32008-07-14 09:58:45 +0200173 if (sch->driver && sch->driver->chp_event)
174 if (sch->driver->chp_event(sch, data, CHP_OFFLINE) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 goto out_unreg;
Cornelia Huck2ec22982006-12-08 15:54:26 +0100176 spin_unlock_irq(sch->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 return 0;
Stefan Bader387b7342007-04-27 16:01:33 +0200178
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179out_unreg:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 sch->lpm = 0;
Stefan Bader387b7342007-04-27 16:01:33 +0200181 spin_unlock_irq(sch->lock);
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200182 css_schedule_eval(sch->schid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 return 0;
184}
185
Peter Oberparleitere6b6e102007-04-27 16:01:28 +0200186void chsc_chp_offline(struct chp_id chpid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187{
188 char dbf_txt[15];
Cornelia Huck99611f82008-07-14 09:59:02 +0200189 struct chp_link link;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190
Peter Oberparleiterf86635f2007-04-27 16:01:26 +0200191 sprintf(dbf_txt, "chpr%x.%02x", chpid.cssid, chpid.id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 CIO_TRACE_EVENT(2, dbf_txt);
193
Peter Oberparleitere6b6e102007-04-27 16:01:28 +0200194 if (chp_get_status(chpid) <= 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 return;
Cornelia Huck99611f82008-07-14 09:59:02 +0200196 memset(&link, 0, sizeof(struct chp_link));
197 link.chpid = chpid;
Cornelia Huck22806dc2008-04-17 07:45:59 +0200198 /* Wait until previous actions have settled. */
199 css_wait_for_slow_path();
Cornelia Huck99611f82008-07-14 09:59:02 +0200200 for_each_subchannel_staged(s390_subchannel_remove_chpid, NULL, &link);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201}
202
Peter Oberparleitere82a1562008-01-26 14:10:48 +0100203static int s390_process_res_acc_new_sch(struct subchannel_id schid, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204{
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800205 struct schib schib;
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800206 /*
207 * We don't know the device yet, but since a path
208 * may be available now to the device we'll have
209 * to do recognition again.
210 * Since we don't have any idea about which chpid
211 * that beast may be on we'll have to do a stsch
212 * on all devices, grr...
213 */
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800214 if (stsch_err(schid, &schib))
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800215 /* We're through */
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200216 return -ENXIO;
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800217
218 /* Put it on the slow path. */
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200219 css_schedule_eval(schid);
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800220 return 0;
221}
222
Peter Oberparleitere82a1562008-01-26 14:10:48 +0100223static int __s390_process_res_acc(struct subchannel *sch, void *data)
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800224{
Cornelia Huck2ec22982006-12-08 15:54:26 +0100225 spin_lock_irq(sch->lock);
Cornelia Huckc820de32008-07-14 09:58:45 +0200226 if (sch->driver && sch->driver->chp_event)
227 sch->driver->chp_event(sch, data, CHP_ONLINE);
Cornelia Huck2ec22982006-12-08 15:54:26 +0100228 spin_unlock_irq(sch->lock);
Peter Oberparleitere82a1562008-01-26 14:10:48 +0100229
Peter Oberparleiterdd9963f2006-09-20 15:59:54 +0200230 return 0;
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800231}
232
Cornelia Huck99611f82008-07-14 09:59:02 +0200233static void s390_process_res_acc(struct chp_link *link)
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800234{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 char dbf_txt[15];
236
Cornelia Huck99611f82008-07-14 09:59:02 +0200237 sprintf(dbf_txt, "accpr%x.%02x", link->chpid.cssid,
238 link->chpid.id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 CIO_TRACE_EVENT( 2, dbf_txt);
Cornelia Huck99611f82008-07-14 09:59:02 +0200240 if (link->fla != 0) {
241 sprintf(dbf_txt, "fla%x", link->fla);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 CIO_TRACE_EVENT( 2, dbf_txt);
243 }
Cornelia Huck22806dc2008-04-17 07:45:59 +0200244 /* Wait until previous actions have settled. */
245 css_wait_for_slow_path();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 /*
247 * I/O resources may have become accessible.
248 * Scan through all subchannels that may be concerned and
249 * do a validation on those.
250 * The more information we have (info), the less scanning
251 * will we have to do.
252 */
Peter Oberparleitere82a1562008-01-26 14:10:48 +0100253 for_each_subchannel_staged(__s390_process_res_acc,
Cornelia Huck99611f82008-07-14 09:59:02 +0200254 s390_process_res_acc_new_sch, link);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255}
256
257static int
258__get_chpid_from_lir(void *data)
259{
260 struct lir {
261 u8 iq;
262 u8 ic;
263 u16 sci;
264 /* incident-node descriptor */
265 u32 indesc[28];
266 /* attached-node descriptor */
267 u32 andesc[28];
268 /* incident-specific information */
269 u32 isinfo[28];
Peter Oberparleiter0f008aa2007-02-05 21:17:40 +0100270 } __attribute__ ((packed)) *lir;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271
Cornelia Huck12975ae2006-10-11 15:31:47 +0200272 lir = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 if (!(lir->iq&0x80))
274 /* NULL link incident record */
275 return -EINVAL;
276 if (!(lir->indesc[0]&0xc0000000))
277 /* node descriptor not valid */
278 return -EINVAL;
279 if (!(lir->indesc[0]&0x10000000))
280 /* don't handle device-type nodes - FIXME */
281 return -EINVAL;
282 /* Byte 3 contains the chpid. Could also be CTCA, but we don't care */
283
284 return (u16) (lir->indesc[0]&0x000000ff);
285}
286
Jan Glaubercbc0dd12012-11-29 14:34:48 +0100287struct chsc_sei_nt0_area {
288 u8 flags;
289 u8 vf; /* validity flags */
290 u8 rs; /* reporting source */
291 u8 cc; /* content code */
292 u16 fla; /* full link address */
293 u16 rsid; /* reporting source id */
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100294 u32 reserved1;
295 u32 reserved2;
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100296 /* ccdf has to be big enough for a link-incident record */
Jan Glaubercbc0dd12012-11-29 14:34:48 +0100297 u8 ccdf[PAGE_SIZE - 24 - 16]; /* content-code dependent field */
298} __packed;
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100299
Jan Glaubercbc0dd12012-11-29 14:34:48 +0100300struct chsc_sei_nt2_area {
301 u8 flags; /* p and v bit */
302 u8 reserved1;
303 u8 reserved2;
304 u8 cc; /* content code */
305 u32 reserved3[13];
306 u8 ccdf[PAGE_SIZE - 24 - 56]; /* content-code dependent field */
307} __packed;
308
Sebastian Ott509d97b2013-01-15 19:02:01 +0100309#define CHSC_SEI_NT0 (1ULL << 63)
Jan Glaubercbc0dd12012-11-29 14:34:48 +0100310#define CHSC_SEI_NT2 (1ULL << 61)
311
312struct chsc_sei {
313 struct chsc_header request;
314 u32 reserved1;
315 u64 ntsm; /* notification type mask */
316 struct chsc_header response;
Sebastian Ott509d97b2013-01-15 19:02:01 +0100317 u32 :24;
318 u8 nt;
Jan Glaubercbc0dd12012-11-29 14:34:48 +0100319 union {
320 struct chsc_sei_nt0_area nt0_area;
321 struct chsc_sei_nt2_area nt2_area;
322 u8 nt_area[PAGE_SIZE - 24];
323 } u;
324} __packed;
325
326static void chsc_process_sei_link_incident(struct chsc_sei_nt0_area *sei_area)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327{
Peter Oberparleiterf86635f2007-04-27 16:01:26 +0200328 struct chp_id chpid;
329 int id;
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100330
331 CIO_CRW_EVENT(4, "chsc: link incident (rs=%02x, rs_id=%04x)\n",
332 sei_area->rs, sei_area->rsid);
333 if (sei_area->rs != 4)
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200334 return;
Peter Oberparleiterf86635f2007-04-27 16:01:26 +0200335 id = __get_chpid_from_lir(sei_area->ccdf);
336 if (id < 0)
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100337 CIO_CRW_EVENT(4, "chsc: link incident - invalid LIR\n");
Peter Oberparleiterf86635f2007-04-27 16:01:26 +0200338 else {
339 chp_id_init(&chpid);
340 chpid.id = id;
Peter Oberparleitere6b6e102007-04-27 16:01:28 +0200341 chsc_chp_offline(chpid);
Peter Oberparleiterf86635f2007-04-27 16:01:26 +0200342 }
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100343}
344
Jan Glaubercbc0dd12012-11-29 14:34:48 +0100345static void chsc_process_sei_res_acc(struct chsc_sei_nt0_area *sei_area)
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100346{
Cornelia Huck99611f82008-07-14 09:59:02 +0200347 struct chp_link link;
Peter Oberparleiterf86635f2007-04-27 16:01:26 +0200348 struct chp_id chpid;
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100349 int status;
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100350
351 CIO_CRW_EVENT(4, "chsc: resource accessibility event (rs=%02x, "
352 "rs_id=%04x)\n", sei_area->rs, sei_area->rsid);
353 if (sei_area->rs != 4)
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200354 return;
Peter Oberparleiterf86635f2007-04-27 16:01:26 +0200355 chp_id_init(&chpid);
356 chpid.id = sei_area->rsid;
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100357 /* allocate a new channel path structure, if needed */
Peter Oberparleitere6b6e102007-04-27 16:01:28 +0200358 status = chp_get_status(chpid);
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100359 if (status < 0)
Peter Oberparleitere6b6e102007-04-27 16:01:28 +0200360 chp_new(chpid);
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100361 else if (!status)
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200362 return;
Cornelia Huck99611f82008-07-14 09:59:02 +0200363 memset(&link, 0, sizeof(struct chp_link));
364 link.chpid = chpid;
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100365 if ((sei_area->vf & 0xc0) != 0) {
Cornelia Huck99611f82008-07-14 09:59:02 +0200366 link.fla = sei_area->fla;
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100367 if ((sei_area->vf & 0xc0) == 0xc0)
368 /* full link address */
Cornelia Huck99611f82008-07-14 09:59:02 +0200369 link.fla_mask = 0xffff;
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100370 else
371 /* link address */
Cornelia Huck99611f82008-07-14 09:59:02 +0200372 link.fla_mask = 0xff00;
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100373 }
Cornelia Huck99611f82008-07-14 09:59:02 +0200374 s390_process_res_acc(&link);
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100375}
376
Jan Glaubercbc0dd12012-11-29 14:34:48 +0100377static void chsc_process_sei_chp_avail(struct chsc_sei_nt0_area *sei_area)
Sebastian Ottfca894ed2011-05-23 10:24:41 +0200378{
379 struct channel_path *chp;
380 struct chp_id chpid;
381 u8 *data;
382 int num;
383
384 CIO_CRW_EVENT(4, "chsc: channel path availability information\n");
385 if (sei_area->rs != 0)
386 return;
387 data = sei_area->ccdf;
388 chp_id_init(&chpid);
389 for (num = 0; num <= __MAX_CHPID; num++) {
390 if (!chp_test_bit(data, num))
391 continue;
392 chpid.id = num;
393
394 CIO_CRW_EVENT(4, "Update information for channel path "
395 "%x.%02x\n", chpid.cssid, chpid.id);
396 chp = chpid_to_chp(chpid);
397 if (!chp) {
398 chp_new(chpid);
399 continue;
400 }
401 mutex_lock(&chp->lock);
Peter Oberparleitercce0eac2013-03-11 12:58:18 +0100402 chp_update_desc(chp);
Sebastian Ottfca894ed2011-05-23 10:24:41 +0200403 mutex_unlock(&chp->lock);
404 }
405}
406
Peter Oberparleitere5854a52007-04-27 16:01:31 +0200407struct chp_config_data {
408 u8 map[32];
409 u8 op;
410 u8 pc;
411};
412
Jan Glaubercbc0dd12012-11-29 14:34:48 +0100413static void chsc_process_sei_chp_config(struct chsc_sei_nt0_area *sei_area)
Peter Oberparleitere5854a52007-04-27 16:01:31 +0200414{
415 struct chp_config_data *data;
416 struct chp_id chpid;
417 int num;
Michael Ernste6d5a422008-12-25 13:39:36 +0100418 char *events[3] = {"configure", "deconfigure", "cancel deconfigure"};
Peter Oberparleitere5854a52007-04-27 16:01:31 +0200419
420 CIO_CRW_EVENT(4, "chsc: channel-path-configuration notification\n");
421 if (sei_area->rs != 0)
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200422 return;
Peter Oberparleitere5854a52007-04-27 16:01:31 +0200423 data = (struct chp_config_data *) &(sei_area->ccdf);
424 chp_id_init(&chpid);
425 for (num = 0; num <= __MAX_CHPID; num++) {
426 if (!chp_test_bit(data->map, num))
427 continue;
428 chpid.id = num;
Michael Ernste6d5a422008-12-25 13:39:36 +0100429 pr_notice("Processing %s for channel path %x.%02x\n",
430 events[data->op], chpid.cssid, chpid.id);
Peter Oberparleitere5854a52007-04-27 16:01:31 +0200431 switch (data->op) {
432 case 0:
433 chp_cfg_schedule(chpid, 1);
434 break;
435 case 1:
436 chp_cfg_schedule(chpid, 0);
437 break;
438 case 2:
439 chp_cfg_cancel_deconfigure(chpid);
440 break;
441 }
442 }
Peter Oberparleitere5854a52007-04-27 16:01:31 +0200443}
444
Jan Glaubercbc0dd12012-11-29 14:34:48 +0100445static void chsc_process_sei_scm_change(struct chsc_sei_nt0_area *sei_area)
Sebastian Ott40ff4cc2012-08-28 16:47:02 +0200446{
447 int ret;
448
449 CIO_CRW_EVENT(4, "chsc: scm change notification\n");
450 if (sei_area->rs != 7)
451 return;
452
453 ret = scm_update_information();
454 if (ret)
455 CIO_CRW_EVENT(0, "chsc: updating change notification"
456 " failed (rc=%d).\n", ret);
457}
458
Sebastian Ottaebfa662013-02-28 12:07:55 +0100459static void chsc_process_sei_scm_avail(struct chsc_sei_nt0_area *sei_area)
460{
461 int ret;
462
463 CIO_CRW_EVENT(4, "chsc: scm available information\n");
464 if (sei_area->rs != 7)
465 return;
466
467 ret = scm_process_availability_information();
468 if (ret)
469 CIO_CRW_EVENT(0, "chsc: process availability information"
470 " failed (rc=%d).\n", ret);
471}
472
Jan Glaubercbc0dd12012-11-29 14:34:48 +0100473static void chsc_process_sei_nt2(struct chsc_sei_nt2_area *sei_area)
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100474{
Jan Glaubercbc0dd12012-11-29 14:34:48 +0100475 switch (sei_area->cc) {
476 case 1:
477 zpci_event_error(sei_area->ccdf);
478 break;
479 case 2:
480 zpci_event_availability(sei_area->ccdf);
481 break;
482 default:
Sebastian Ott9a17e972013-01-15 19:04:39 +0100483 CIO_CRW_EVENT(2, "chsc: sei nt2 unhandled cc=%d\n",
Jan Glaubercbc0dd12012-11-29 14:34:48 +0100484 sei_area->cc);
485 break;
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200486 }
Jan Glaubercbc0dd12012-11-29 14:34:48 +0100487}
488
489static void chsc_process_sei_nt0(struct chsc_sei_nt0_area *sei_area)
490{
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100491 /* which kind of information was stored? */
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100492 switch (sei_area->cc) {
493 case 1: /* link incident*/
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200494 chsc_process_sei_link_incident(sei_area);
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100495 break;
Sebastian Ottfca894ed2011-05-23 10:24:41 +0200496 case 2: /* i/o resource accessibility */
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200497 chsc_process_sei_res_acc(sei_area);
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100498 break;
Sebastian Ottfca894ed2011-05-23 10:24:41 +0200499 case 7: /* channel-path-availability information */
500 chsc_process_sei_chp_avail(sei_area);
501 break;
Peter Oberparleitere5854a52007-04-27 16:01:31 +0200502 case 8: /* channel-path-configuration notification */
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200503 chsc_process_sei_chp_config(sei_area);
Peter Oberparleitere5854a52007-04-27 16:01:31 +0200504 break;
Sebastian Ott40ff4cc2012-08-28 16:47:02 +0200505 case 12: /* scm change notification */
506 chsc_process_sei_scm_change(sei_area);
507 break;
Sebastian Ottaebfa662013-02-28 12:07:55 +0100508 case 14: /* scm available notification */
509 chsc_process_sei_scm_avail(sei_area);
510 break;
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100511 default: /* other stuff */
Sebastian Ott9a17e972013-01-15 19:04:39 +0100512 CIO_CRW_EVENT(2, "chsc: sei nt0 unhandled cc=%d\n",
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100513 sei_area->cc);
514 break;
515 }
Sebastian Ott9a17e972013-01-15 19:04:39 +0100516
517 /* Check if we might have lost some information. */
518 if (sei_area->flags & 0x40) {
519 CIO_CRW_EVENT(2, "chsc: event overflow\n");
520 css_schedule_eval_all();
521 }
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100522}
523
Sebastian Ott9a17e972013-01-15 19:04:39 +0100524static void chsc_process_event_information(struct chsc_sei *sei, u64 ntsm)
Jan Glaubercbc0dd12012-11-29 14:34:48 +0100525{
526 do {
527 memset(sei, 0, sizeof(*sei));
528 sei->request.length = 0x0010;
529 sei->request.code = 0x000e;
530 sei->ntsm = ntsm;
531
532 if (chsc(sei))
533 break;
534
Sebastian Ott9a17e972013-01-15 19:04:39 +0100535 if (sei->response.code != 0x0001) {
Jan Glaubercbc0dd12012-11-29 14:34:48 +0100536 CIO_CRW_EVENT(2, "chsc: sei failed (rc=%04x)\n",
537 sei->response.code);
538 break;
539 }
Jan Glaubercbc0dd12012-11-29 14:34:48 +0100540
Sebastian Ott9a17e972013-01-15 19:04:39 +0100541 CIO_CRW_EVENT(2, "chsc: sei successful (nt=%d)\n", sei->nt);
542 switch (sei->nt) {
543 case 0:
544 chsc_process_sei_nt0(&sei->u.nt0_area);
545 break;
546 case 2:
547 chsc_process_sei_nt2(&sei->u.nt2_area);
548 break;
549 default:
550 CIO_CRW_EVENT(2, "chsc: unhandled nt: %d\n", sei->nt);
551 break;
552 }
553 } while (sei->u.nt0_area.flags & 0x80);
Jan Glaubercbc0dd12012-11-29 14:34:48 +0100554}
555
Sebastian Ott9a17e972013-01-15 19:04:39 +0100556/*
557 * Handle channel subsystem related CRWs.
558 * Use store event information to find out what's going on.
559 *
560 * Note: Access to sei_page is serialized through machine check handler
561 * thread, so no need for locking.
562 */
Cornelia Huckc1156182008-07-14 09:58:46 +0200563static void chsc_process_crw(struct crw *crw0, struct crw *crw1, int overflow)
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100564{
Sebastian Ott9a17e972013-01-15 19:04:39 +0100565 struct chsc_sei *sei = sei_page;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566
Cornelia Huckc1156182008-07-14 09:58:46 +0200567 if (overflow) {
568 css_schedule_eval_all();
569 return;
570 }
571 CIO_CRW_EVENT(2, "CRW reports slct=%d, oflw=%d, "
572 "chn=%d, rsc=%X, anc=%d, erc=%X, rsid=%X\n",
573 crw0->slct, crw0->oflw, crw0->chn, crw0->rsc, crw0->anc,
574 crw0->erc, crw0->rsid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575
Cornelia Huckc1156182008-07-14 09:58:46 +0200576 CIO_TRACE_EVENT(2, "prcss");
Sebastian Ott9a17e972013-01-15 19:04:39 +0100577 chsc_process_event_information(sei, CHSC_SEI_NT0 | CHSC_SEI_NT2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578}
579
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200580void chsc_chp_online(struct chp_id chpid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 char dbf_txt[15];
Cornelia Huck99611f82008-07-14 09:59:02 +0200583 struct chp_link link;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584
Peter Oberparleiterf86635f2007-04-27 16:01:26 +0200585 sprintf(dbf_txt, "cadd%x.%02x", chpid.cssid, chpid.id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 CIO_TRACE_EVENT(2, dbf_txt);
587
Cornelia Huck22806dc2008-04-17 07:45:59 +0200588 if (chp_get_status(chpid) != 0) {
Cornelia Huck99611f82008-07-14 09:59:02 +0200589 memset(&link, 0, sizeof(struct chp_link));
590 link.chpid = chpid;
Cornelia Huck22806dc2008-04-17 07:45:59 +0200591 /* Wait until previous actions have settled. */
592 css_wait_for_slow_path();
Cornelia Huckc820de32008-07-14 09:58:45 +0200593 for_each_subchannel_staged(__s390_process_res_acc, NULL,
Cornelia Huck99611f82008-07-14 09:59:02 +0200594 &link);
Cornelia Huck22806dc2008-04-17 07:45:59 +0200595 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596}
597
Peter Oberparleiterf86635f2007-04-27 16:01:26 +0200598static void __s390_subchannel_vary_chpid(struct subchannel *sch,
599 struct chp_id chpid, int on)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 unsigned long flags;
Cornelia Huck99611f82008-07-14 09:59:02 +0200602 struct chp_link link;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603
Cornelia Huck99611f82008-07-14 09:59:02 +0200604 memset(&link, 0, sizeof(struct chp_link));
605 link.chpid = chpid;
Cornelia Huck2ec22982006-12-08 15:54:26 +0100606 spin_lock_irqsave(sch->lock, flags);
Cornelia Huckc820de32008-07-14 09:58:45 +0200607 if (sch->driver && sch->driver->chp_event)
Cornelia Huck99611f82008-07-14 09:59:02 +0200608 sch->driver->chp_event(sch, &link,
Cornelia Huckc820de32008-07-14 09:58:45 +0200609 on ? CHP_VARY_ON : CHP_VARY_OFF);
Cornelia Huck2ec22982006-12-08 15:54:26 +0100610 spin_unlock_irqrestore(sch->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611}
612
Peter Oberparleitere82a1562008-01-26 14:10:48 +0100613static int s390_subchannel_vary_chpid_off(struct subchannel *sch, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614{
Peter Oberparleitere82a1562008-01-26 14:10:48 +0100615 struct chp_id *chpid = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616
617 __s390_subchannel_vary_chpid(sch, *chpid, 0);
618 return 0;
619}
620
Peter Oberparleitere82a1562008-01-26 14:10:48 +0100621static int s390_subchannel_vary_chpid_on(struct subchannel *sch, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622{
Peter Oberparleitere82a1562008-01-26 14:10:48 +0100623 struct chp_id *chpid = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624
625 __s390_subchannel_vary_chpid(sch, *chpid, 1);
626 return 0;
627}
628
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800629static int
630__s390_vary_chpid_on(struct subchannel_id schid, void *data)
631{
632 struct schib schib;
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800633
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800634 if (stsch_err(schid, &schib))
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800635 /* We're through */
636 return -ENXIO;
637 /* Put it on the slow path. */
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200638 css_schedule_eval(schid);
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800639 return 0;
640}
641
Peter Oberparleitere6b6e102007-04-27 16:01:28 +0200642/**
643 * chsc_chp_vary - propagate channel-path vary operation to subchannels
644 * @chpid: channl-path ID
645 * @on: non-zero for vary online, zero for vary offline
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 */
Peter Oberparleitere6b6e102007-04-27 16:01:28 +0200647int chsc_chp_vary(struct chp_id chpid, int on)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648{
Sebastian Ottc38a90a2010-10-25 16:10:31 +0200649 struct channel_path *chp = chpid_to_chp(chpid);
Cornelia Huck99611f82008-07-14 09:59:02 +0200650
Cornelia Huck22806dc2008-04-17 07:45:59 +0200651 /* Wait until previous actions have settled. */
652 css_wait_for_slow_path();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 /*
654 * Redo PathVerification on the devices the chpid connects to
655 */
Sebastian Ottc38a90a2010-10-25 16:10:31 +0200656 if (on) {
Peter Oberparleitercce0eac2013-03-11 12:58:18 +0100657 /* Try to update the channel path description. */
658 chp_update_desc(chp);
Peter Oberparleitere82a1562008-01-26 14:10:48 +0100659 for_each_subchannel_staged(s390_subchannel_vary_chpid_on,
Sebastian Ott3b484ec2011-12-01 13:32:22 +0100660 __s390_vary_chpid_on, &chpid);
Sebastian Ottc38a90a2010-10-25 16:10:31 +0200661 } else
Peter Oberparleitere82a1562008-01-26 14:10:48 +0100662 for_each_subchannel_staged(s390_subchannel_vary_chpid_off,
Sebastian Ott3b484ec2011-12-01 13:32:22 +0100663 NULL, &chpid);
Peter Oberparleitere82a1562008-01-26 14:10:48 +0100664
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 return 0;
666}
667
Cornelia Huck495a5b42006-03-24 03:15:14 -0800668static void
669chsc_remove_cmg_attr(struct channel_subsystem *css)
670{
671 int i;
672
673 for (i = 0; i <= __MAX_CHPID; i++) {
674 if (!css->chps[i])
675 continue;
Peter Oberparleitere6b6e102007-04-27 16:01:28 +0200676 chp_remove_cmg_attr(css->chps[i]);
Cornelia Huck495a5b42006-03-24 03:15:14 -0800677 }
678}
679
680static int
681chsc_add_cmg_attr(struct channel_subsystem *css)
682{
683 int i, ret;
684
685 ret = 0;
686 for (i = 0; i <= __MAX_CHPID; i++) {
687 if (!css->chps[i])
688 continue;
Peter Oberparleitere6b6e102007-04-27 16:01:28 +0200689 ret = chp_add_cmg_attr(css->chps[i]);
Cornelia Huck495a5b42006-03-24 03:15:14 -0800690 if (ret)
691 goto cleanup;
692 }
693 return ret;
694cleanup:
695 for (--i; i >= 0; i--) {
696 if (!css->chps[i])
697 continue;
Peter Oberparleitere6b6e102007-04-27 16:01:28 +0200698 chp_remove_cmg_attr(css->chps[i]);
Cornelia Huck495a5b42006-03-24 03:15:14 -0800699 }
700 return ret;
701}
702
Sebastian Ott34196f82010-10-25 16:10:29 +0200703int __chsc_do_secm(struct channel_subsystem *css, int enable)
Cornelia Huck495a5b42006-03-24 03:15:14 -0800704{
705 struct {
706 struct chsc_header request;
707 u32 operation_code : 2;
708 u32 : 30;
709 u32 key : 4;
710 u32 : 28;
711 u32 zeroes1;
712 u32 cub_addr1;
713 u32 zeroes2;
714 u32 cub_addr2;
715 u32 reserved[13];
716 struct chsc_header response;
717 u32 status : 8;
718 u32 : 4;
719 u32 fmt : 4;
720 u32 : 16;
Peter Oberparleiter0f008aa2007-02-05 21:17:40 +0100721 } __attribute__ ((packed)) *secm_area;
Cornelia Huck495a5b42006-03-24 03:15:14 -0800722 int ret, ccode;
723
Sebastian Ott34196f82010-10-25 16:10:29 +0200724 spin_lock_irq(&chsc_page_lock);
725 memset(chsc_page, 0, PAGE_SIZE);
726 secm_area = chsc_page;
Cornelia Huck495a5b42006-03-24 03:15:14 -0800727 secm_area->request.length = 0x0050;
728 secm_area->request.code = 0x0016;
729
Heiko Carstensd1bf8592010-02-26 22:37:30 +0100730 secm_area->key = PAGE_DEFAULT_KEY >> 4;
Cornelia Huck495a5b42006-03-24 03:15:14 -0800731 secm_area->cub_addr1 = (u64)(unsigned long)css->cub_addr1;
732 secm_area->cub_addr2 = (u64)(unsigned long)css->cub_addr2;
733
734 secm_area->operation_code = enable ? 0 : 1;
735
736 ccode = chsc(secm_area);
Sebastian Ott34196f82010-10-25 16:10:29 +0200737 if (ccode > 0) {
738 ret = (ccode == 3) ? -ENODEV : -EBUSY;
739 goto out;
740 }
Cornelia Huck495a5b42006-03-24 03:15:14 -0800741
742 switch (secm_area->response.code) {
Cornelia Huckb9c9a212008-02-05 16:50:34 +0100743 case 0x0102:
744 case 0x0103:
Cornelia Huck495a5b42006-03-24 03:15:14 -0800745 ret = -EINVAL;
Sebastian Ott17e7d872009-03-26 15:24:17 +0100746 break;
Cornelia Huck495a5b42006-03-24 03:15:14 -0800747 default:
Cornelia Huckb9c9a212008-02-05 16:50:34 +0100748 ret = chsc_error_from_response(secm_area->response.code);
Cornelia Huck495a5b42006-03-24 03:15:14 -0800749 }
Cornelia Huckb9c9a212008-02-05 16:50:34 +0100750 if (ret != 0)
751 CIO_CRW_EVENT(2, "chsc: secm failed (rc=%04x)\n",
752 secm_area->response.code);
Sebastian Ott34196f82010-10-25 16:10:29 +0200753out:
754 spin_unlock_irq(&chsc_page_lock);
Cornelia Huck495a5b42006-03-24 03:15:14 -0800755 return ret;
756}
757
758int
759chsc_secm(struct channel_subsystem *css, int enable)
760{
Cornelia Huck495a5b42006-03-24 03:15:14 -0800761 int ret;
762
Cornelia Huck495a5b42006-03-24 03:15:14 -0800763 if (enable && !css->cm_enabled) {
764 css->cub_addr1 = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
765 css->cub_addr2 = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
766 if (!css->cub_addr1 || !css->cub_addr2) {
767 free_page((unsigned long)css->cub_addr1);
768 free_page((unsigned long)css->cub_addr2);
Cornelia Huck495a5b42006-03-24 03:15:14 -0800769 return -ENOMEM;
770 }
771 }
Sebastian Ott34196f82010-10-25 16:10:29 +0200772 ret = __chsc_do_secm(css, enable);
Cornelia Huck495a5b42006-03-24 03:15:14 -0800773 if (!ret) {
774 css->cm_enabled = enable;
775 if (css->cm_enabled) {
776 ret = chsc_add_cmg_attr(css);
777 if (ret) {
Sebastian Ott34196f82010-10-25 16:10:29 +0200778 __chsc_do_secm(css, 0);
Cornelia Huck495a5b42006-03-24 03:15:14 -0800779 css->cm_enabled = 0;
780 }
781 } else
782 chsc_remove_cmg_attr(css);
783 }
Cornelia Huck8c4941c2007-04-27 16:01:38 +0200784 if (!css->cm_enabled) {
Cornelia Huck495a5b42006-03-24 03:15:14 -0800785 free_page((unsigned long)css->cub_addr1);
786 free_page((unsigned long)css->cub_addr2);
787 }
Cornelia Huck495a5b42006-03-24 03:15:14 -0800788 return ret;
789}
790
Cornelia Huck9d92a7e2008-07-14 09:59:05 +0200791int chsc_determine_channel_path_desc(struct chp_id chpid, int fmt, int rfmt,
Sebastian Ott906c9762010-10-25 16:10:30 +0200792 int c, int m, void *page)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793{
Sebastian Ott906c9762010-10-25 16:10:30 +0200794 struct chsc_scpd *scpd_area;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795 int ccode, ret;
796
Cornelia Huck9d92a7e2008-07-14 09:59:05 +0200797 if ((rfmt == 1) && !css_general_characteristics.fcs)
798 return -EINVAL;
799 if ((rfmt == 2) && !css_general_characteristics.cib)
800 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801
Sebastian Ott906c9762010-10-25 16:10:30 +0200802 memset(page, 0, PAGE_SIZE);
803 scpd_area = page;
Cornelia Huck495a5b42006-03-24 03:15:14 -0800804 scpd_area->request.length = 0x0010;
805 scpd_area->request.code = 0x0002;
Cornelia Huck9d92a7e2008-07-14 09:59:05 +0200806 scpd_area->cssid = chpid.cssid;
Peter Oberparleiterf86635f2007-04-27 16:01:26 +0200807 scpd_area->first_chpid = chpid.id;
808 scpd_area->last_chpid = chpid.id;
Cornelia Huck9d92a7e2008-07-14 09:59:05 +0200809 scpd_area->m = m;
810 scpd_area->c = c;
811 scpd_area->fmt = fmt;
812 scpd_area->rfmt = rfmt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813
814 ccode = chsc(scpd_area);
Sebastian Ott906c9762010-10-25 16:10:30 +0200815 if (ccode > 0)
816 return (ccode == 3) ? -ENODEV : -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817
Cornelia Huckb9c9a212008-02-05 16:50:34 +0100818 ret = chsc_error_from_response(scpd_area->response.code);
Sebastian Ott906c9762010-10-25 16:10:30 +0200819 if (ret)
Cornelia Huckb9c9a212008-02-05 16:50:34 +0100820 CIO_CRW_EVENT(2, "chsc: scpd failed (rc=%04x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821 scpd_area->response.code);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822 return ret;
823}
Cornelia Huck9d92a7e2008-07-14 09:59:05 +0200824EXPORT_SYMBOL_GPL(chsc_determine_channel_path_desc);
825
826int chsc_determine_base_channel_path_desc(struct chp_id chpid,
827 struct channel_path_desc *desc)
828{
829 struct chsc_response_struct *chsc_resp;
Sebastian Ott906c9762010-10-25 16:10:30 +0200830 struct chsc_scpd *scpd_area;
Sebastian Ott62da1772010-10-25 16:10:32 +0200831 unsigned long flags;
Cornelia Huck9d92a7e2008-07-14 09:59:05 +0200832 int ret;
833
Sebastian Ott62da1772010-10-25 16:10:32 +0200834 spin_lock_irqsave(&chsc_page_lock, flags);
Sebastian Ott906c9762010-10-25 16:10:30 +0200835 scpd_area = chsc_page;
836 ret = chsc_determine_channel_path_desc(chpid, 0, 0, 0, 0, scpd_area);
Cornelia Huck9d92a7e2008-07-14 09:59:05 +0200837 if (ret)
Sebastian Ott906c9762010-10-25 16:10:30 +0200838 goto out;
839 chsc_resp = (void *)&scpd_area->response;
Sebastian Ott878c4952010-07-19 09:22:37 +0200840 memcpy(desc, &chsc_resp->data, sizeof(*desc));
Sebastian Ott906c9762010-10-25 16:10:30 +0200841out:
Sebastian Ott62da1772010-10-25 16:10:32 +0200842 spin_unlock_irqrestore(&chsc_page_lock, flags);
Cornelia Huck9d92a7e2008-07-14 09:59:05 +0200843 return ret;
844}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845
Sebastian Ottce322cc2011-01-05 12:47:56 +0100846int chsc_determine_fmt1_channel_path_desc(struct chp_id chpid,
847 struct channel_path_desc_fmt1 *desc)
848{
849 struct chsc_response_struct *chsc_resp;
850 struct chsc_scpd *scpd_area;
Peter Oberparleitercce0eac2013-03-11 12:58:18 +0100851 unsigned long flags;
Sebastian Ottce322cc2011-01-05 12:47:56 +0100852 int ret;
853
Peter Oberparleitercce0eac2013-03-11 12:58:18 +0100854 spin_lock_irqsave(&chsc_page_lock, flags);
Sebastian Ottce322cc2011-01-05 12:47:56 +0100855 scpd_area = chsc_page;
856 ret = chsc_determine_channel_path_desc(chpid, 0, 0, 1, 0, scpd_area);
857 if (ret)
858 goto out;
859 chsc_resp = (void *)&scpd_area->response;
860 memcpy(desc, &chsc_resp->data, sizeof(*desc));
861out:
Peter Oberparleitercce0eac2013-03-11 12:58:18 +0100862 spin_unlock_irqrestore(&chsc_page_lock, flags);
Sebastian Ottce322cc2011-01-05 12:47:56 +0100863 return ret;
864}
865
Cornelia Huck495a5b42006-03-24 03:15:14 -0800866static void
867chsc_initialize_cmg_chars(struct channel_path *chp, u8 cmcv,
868 struct cmg_chars *chars)
869{
Sebastian Ott34196f82010-10-25 16:10:29 +0200870 struct cmg_chars *cmg_chars;
871 int i, mask;
Cornelia Huck495a5b42006-03-24 03:15:14 -0800872
Sebastian Ott34196f82010-10-25 16:10:29 +0200873 cmg_chars = chp->cmg_chars;
874 for (i = 0; i < NR_MEASUREMENT_CHARS; i++) {
875 mask = 0x80 >> (i + 3);
876 if (cmcv & mask)
877 cmg_chars->values[i] = chars->values[i];
878 else
879 cmg_chars->values[i] = 0;
Cornelia Huck495a5b42006-03-24 03:15:14 -0800880 }
881}
882
Peter Oberparleitere6b6e102007-04-27 16:01:28 +0200883int chsc_get_channel_measurement_chars(struct channel_path *chp)
Cornelia Huck495a5b42006-03-24 03:15:14 -0800884{
Sebastian Ott34196f82010-10-25 16:10:29 +0200885 struct cmg_chars *cmg_chars;
Cornelia Huck495a5b42006-03-24 03:15:14 -0800886 int ccode, ret;
887
888 struct {
889 struct chsc_header request;
890 u32 : 24;
891 u32 first_chpid : 8;
892 u32 : 24;
893 u32 last_chpid : 8;
894 u32 zeroes1;
895 struct chsc_header response;
896 u32 zeroes2;
897 u32 not_valid : 1;
898 u32 shared : 1;
899 u32 : 22;
900 u32 chpid : 8;
901 u32 cmcv : 5;
902 u32 : 11;
903 u32 cmgq : 8;
904 u32 cmg : 8;
905 u32 zeroes3;
906 u32 data[NR_MEASUREMENT_CHARS];
Peter Oberparleiter0f008aa2007-02-05 21:17:40 +0100907 } __attribute__ ((packed)) *scmc_area;
Cornelia Huck495a5b42006-03-24 03:15:14 -0800908
Sebastian Ott34196f82010-10-25 16:10:29 +0200909 chp->cmg_chars = NULL;
910 cmg_chars = kmalloc(sizeof(*cmg_chars), GFP_KERNEL);
911 if (!cmg_chars)
Cornelia Huck495a5b42006-03-24 03:15:14 -0800912 return -ENOMEM;
913
Sebastian Ott34196f82010-10-25 16:10:29 +0200914 spin_lock_irq(&chsc_page_lock);
915 memset(chsc_page, 0, PAGE_SIZE);
916 scmc_area = chsc_page;
Cornelia Huck495a5b42006-03-24 03:15:14 -0800917 scmc_area->request.length = 0x0010;
918 scmc_area->request.code = 0x0022;
Peter Oberparleiterf86635f2007-04-27 16:01:26 +0200919 scmc_area->first_chpid = chp->chpid.id;
920 scmc_area->last_chpid = chp->chpid.id;
Cornelia Huck495a5b42006-03-24 03:15:14 -0800921
922 ccode = chsc(scmc_area);
923 if (ccode > 0) {
924 ret = (ccode == 3) ? -ENODEV : -EBUSY;
925 goto out;
926 }
927
Cornelia Huckb9c9a212008-02-05 16:50:34 +0100928 ret = chsc_error_from_response(scmc_area->response.code);
Sebastian Ott34196f82010-10-25 16:10:29 +0200929 if (ret) {
Cornelia Huckb9c9a212008-02-05 16:50:34 +0100930 CIO_CRW_EVENT(2, "chsc: scmc failed (rc=%04x)\n",
Cornelia Huck495a5b42006-03-24 03:15:14 -0800931 scmc_area->response.code);
Sebastian Ott34196f82010-10-25 16:10:29 +0200932 goto out;
Cornelia Huck495a5b42006-03-24 03:15:14 -0800933 }
Sebastian Ott34196f82010-10-25 16:10:29 +0200934 if (scmc_area->not_valid) {
935 chp->cmg = -1;
936 chp->shared = -1;
937 goto out;
938 }
939 chp->cmg = scmc_area->cmg;
940 chp->shared = scmc_area->shared;
941 if (chp->cmg != 2 && chp->cmg != 3) {
942 /* No cmg-dependent data. */
943 goto out;
944 }
945 chp->cmg_chars = cmg_chars;
946 chsc_initialize_cmg_chars(chp, scmc_area->cmcv,
947 (struct cmg_chars *) &scmc_area->data);
Cornelia Huck495a5b42006-03-24 03:15:14 -0800948out:
Sebastian Ott34196f82010-10-25 16:10:29 +0200949 spin_unlock_irq(&chsc_page_lock);
950 if (!chp->cmg_chars)
951 kfree(cmg_chars);
952
Cornelia Huck495a5b42006-03-24 03:15:14 -0800953 return ret;
954}
955
Sebastian Ott34aec072010-10-25 16:10:28 +0200956int __init chsc_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957{
Cornelia Huckc1156182008-07-14 09:58:46 +0200958 int ret;
959
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960 sei_page = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
Sebastian Ott34196f82010-10-25 16:10:29 +0200961 chsc_page = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
962 if (!sei_page || !chsc_page) {
963 ret = -ENOMEM;
964 goto out_err;
Cornelia Huckc1156182008-07-14 09:58:46 +0200965 }
Heiko Carstensf5daba12009-03-26 15:24:01 +0100966 ret = crw_register_handler(CRW_RSC_CSS, chsc_process_crw);
Cornelia Huckc1156182008-07-14 09:58:46 +0200967 if (ret)
Sebastian Ott34196f82010-10-25 16:10:29 +0200968 goto out_err;
969 return ret;
970out_err:
971 free_page((unsigned long)chsc_page);
972 free_page((unsigned long)sei_page);
Cornelia Huckc1156182008-07-14 09:58:46 +0200973 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974}
975
Sebastian Ott34aec072010-10-25 16:10:28 +0200976void __init chsc_init_cleanup(void)
Cornelia Huck4434a382007-07-27 12:29:21 +0200977{
Heiko Carstensf5daba12009-03-26 15:24:01 +0100978 crw_unregister_handler(CRW_RSC_CSS);
Sebastian Ott34196f82010-10-25 16:10:29 +0200979 free_page((unsigned long)chsc_page);
Sebastian Ott34aec072010-10-25 16:10:28 +0200980 free_page((unsigned long)sei_page);
Cornelia Huck4434a382007-07-27 12:29:21 +0200981}
982
Sebastian Ott818c2722010-04-22 17:17:03 +0200983int chsc_enable_facility(int operation_code)
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800984{
Sebastian Ott34196f82010-10-25 16:10:29 +0200985 unsigned long flags;
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800986 int ret;
Sebastian Ott34196f82010-10-25 16:10:29 +0200987 struct {
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800988 struct chsc_header request;
989 u8 reserved1:4;
990 u8 format:4;
991 u8 reserved2;
992 u16 operation_code;
993 u32 reserved3;
994 u32 reserved4;
995 u32 operation_data_area[252];
996 struct chsc_header response;
997 u32 reserved5:4;
998 u32 format2:4;
999 u32 reserved6:24;
Sebastian Ott34196f82010-10-25 16:10:29 +02001000 } __attribute__ ((packed)) *sda_area;
Cornelia Huckfb6958a2006-01-06 00:19:25 -08001001
Sebastian Ott34196f82010-10-25 16:10:29 +02001002 spin_lock_irqsave(&chsc_page_lock, flags);
1003 memset(chsc_page, 0, PAGE_SIZE);
1004 sda_area = chsc_page;
1005 sda_area->request.length = 0x0400;
1006 sda_area->request.code = 0x0031;
1007 sda_area->operation_code = operation_code;
Cornelia Huckfb6958a2006-01-06 00:19:25 -08001008
Sebastian Ott34196f82010-10-25 16:10:29 +02001009 ret = chsc(sda_area);
Cornelia Huckfb6958a2006-01-06 00:19:25 -08001010 if (ret > 0) {
1011 ret = (ret == 3) ? -ENODEV : -EBUSY;
1012 goto out;
1013 }
Cornelia Huckb9c9a212008-02-05 16:50:34 +01001014
Sebastian Ott34196f82010-10-25 16:10:29 +02001015 switch (sda_area->response.code) {
Cornelia Huckb9c9a212008-02-05 16:50:34 +01001016 case 0x0101:
Cornelia Huckfb6958a2006-01-06 00:19:25 -08001017 ret = -EOPNOTSUPP;
1018 break;
Cornelia Huckb9c9a212008-02-05 16:50:34 +01001019 default:
Sebastian Ott34196f82010-10-25 16:10:29 +02001020 ret = chsc_error_from_response(sda_area->response.code);
Cornelia Huckfb6958a2006-01-06 00:19:25 -08001021 }
Cornelia Huckb9c9a212008-02-05 16:50:34 +01001022 if (ret != 0)
1023 CIO_CRW_EVENT(2, "chsc: sda (oc=%x) failed (rc=%04x)\n",
Sebastian Ott34196f82010-10-25 16:10:29 +02001024 operation_code, sda_area->response.code);
1025out:
1026 spin_unlock_irqrestore(&chsc_page_lock, flags);
Cornelia Huckfb6958a2006-01-06 00:19:25 -08001027 return ret;
1028}
1029
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030struct css_general_char css_general_characteristics;
1031struct css_chsc_char css_chsc_characteristics;
1032
1033int __init
1034chsc_determine_css_characteristics(void)
1035{
1036 int result;
1037 struct {
1038 struct chsc_header request;
1039 u32 reserved1;
1040 u32 reserved2;
1041 u32 reserved3;
1042 struct chsc_header response;
1043 u32 reserved4;
1044 u32 general_char[510];
Sebastian Ott34aec072010-10-25 16:10:28 +02001045 u32 chsc_char[508];
Peter Oberparleiter0f008aa2007-02-05 21:17:40 +01001046 } __attribute__ ((packed)) *scsc_area;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047
Sebastian Ott34196f82010-10-25 16:10:29 +02001048 spin_lock_irq(&chsc_page_lock);
1049 memset(chsc_page, 0, PAGE_SIZE);
1050 scsc_area = chsc_page;
Cornelia Huck495a5b42006-03-24 03:15:14 -08001051 scsc_area->request.length = 0x0010;
1052 scsc_area->request.code = 0x0010;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053
1054 result = chsc(scsc_area);
1055 if (result) {
Cornelia Huckb9c9a212008-02-05 16:50:34 +01001056 result = (result == 3) ? -ENODEV : -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057 goto exit;
1058 }
1059
Cornelia Huckb9c9a212008-02-05 16:50:34 +01001060 result = chsc_error_from_response(scsc_area->response.code);
1061 if (result == 0) {
1062 memcpy(&css_general_characteristics, scsc_area->general_char,
1063 sizeof(css_general_characteristics));
1064 memcpy(&css_chsc_characteristics, scsc_area->chsc_char,
1065 sizeof(css_chsc_characteristics));
1066 } else
1067 CIO_CRW_EVENT(2, "chsc: scsc failed (rc=%04x)\n",
1068 scsc_area->response.code);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069exit:
Sebastian Ott34196f82010-10-25 16:10:29 +02001070 spin_unlock_irq(&chsc_page_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071 return result;
1072}
1073
1074EXPORT_SYMBOL_GPL(css_general_characteristics);
1075EXPORT_SYMBOL_GPL(css_chsc_characteristics);
Martin Schwidefskyd2fec592008-07-14 09:58:56 +02001076
1077int chsc_sstpc(void *page, unsigned int op, u16 ctrl)
1078{
1079 struct {
1080 struct chsc_header request;
1081 unsigned int rsvd0;
1082 unsigned int op : 8;
1083 unsigned int rsvd1 : 8;
1084 unsigned int ctrl : 16;
1085 unsigned int rsvd2[5];
1086 struct chsc_header response;
1087 unsigned int rsvd3[7];
1088 } __attribute__ ((packed)) *rr;
1089 int rc;
1090
1091 memset(page, 0, PAGE_SIZE);
1092 rr = page;
1093 rr->request.length = 0x0020;
1094 rr->request.code = 0x0033;
1095 rr->op = op;
1096 rr->ctrl = ctrl;
1097 rc = chsc(rr);
1098 if (rc)
1099 return -EIO;
1100 rc = (rr->response.code == 0x0001) ? 0 : -EIO;
1101 return rc;
1102}
1103
1104int chsc_sstpi(void *page, void *result, size_t size)
1105{
1106 struct {
1107 struct chsc_header request;
1108 unsigned int rsvd0[3];
1109 struct chsc_header response;
1110 char data[size];
1111 } __attribute__ ((packed)) *rr;
1112 int rc;
1113
1114 memset(page, 0, PAGE_SIZE);
1115 rr = page;
1116 rr->request.length = 0x0010;
1117 rr->request.code = 0x0038;
1118 rc = chsc(rr);
1119 if (rc)
1120 return -EIO;
1121 memcpy(result, &rr->data, size);
1122 return (rr->response.code == 0x0001) ? 0 : -EIO;
1123}
1124
Michael Ernstfd0457a2010-08-09 18:12:50 +02001125int chsc_siosl(struct subchannel_id schid)
1126{
Sebastian Ott34196f82010-10-25 16:10:29 +02001127 struct {
1128 struct chsc_header request;
1129 u32 word1;
1130 struct subchannel_id sid;
1131 u32 word3;
1132 struct chsc_header response;
1133 u32 word[11];
1134 } __attribute__ ((packed)) *siosl_area;
Michael Ernstfd0457a2010-08-09 18:12:50 +02001135 unsigned long flags;
1136 int ccode;
1137 int rc;
1138
Sebastian Ott34196f82010-10-25 16:10:29 +02001139 spin_lock_irqsave(&chsc_page_lock, flags);
1140 memset(chsc_page, 0, PAGE_SIZE);
1141 siosl_area = chsc_page;
1142 siosl_area->request.length = 0x0010;
1143 siosl_area->request.code = 0x0046;
1144 siosl_area->word1 = 0x80000000;
1145 siosl_area->sid = schid;
Michael Ernstfd0457a2010-08-09 18:12:50 +02001146
Sebastian Ott34196f82010-10-25 16:10:29 +02001147 ccode = chsc(siosl_area);
Michael Ernstfd0457a2010-08-09 18:12:50 +02001148 if (ccode > 0) {
1149 if (ccode == 3)
1150 rc = -ENODEV;
1151 else
1152 rc = -EBUSY;
1153 CIO_MSG_EVENT(2, "chsc: chsc failed for 0.%x.%04x (ccode=%d)\n",
1154 schid.ssid, schid.sch_no, ccode);
1155 goto out;
1156 }
Sebastian Ott34196f82010-10-25 16:10:29 +02001157 rc = chsc_error_from_response(siosl_area->response.code);
Michael Ernstfd0457a2010-08-09 18:12:50 +02001158 if (rc)
1159 CIO_MSG_EVENT(2, "chsc: siosl failed for 0.%x.%04x (rc=%04x)\n",
1160 schid.ssid, schid.sch_no,
Sebastian Ott34196f82010-10-25 16:10:29 +02001161 siosl_area->response.code);
Michael Ernstfd0457a2010-08-09 18:12:50 +02001162 else
1163 CIO_MSG_EVENT(4, "chsc: siosl succeeded for 0.%x.%04x\n",
1164 schid.ssid, schid.sch_no);
1165out:
Sebastian Ott34196f82010-10-25 16:10:29 +02001166 spin_unlock_irqrestore(&chsc_page_lock, flags);
Michael Ernstfd0457a2010-08-09 18:12:50 +02001167 return rc;
1168}
1169EXPORT_SYMBOL_GPL(chsc_siosl);
Sebastian Ott184b08a2012-08-28 16:45:42 +02001170
1171/**
1172 * chsc_scm_info() - store SCM information (SSI)
1173 * @scm_area: request and response block for SSI
1174 * @token: continuation token
1175 *
1176 * Returns 0 on success.
1177 */
1178int chsc_scm_info(struct chsc_scm_info *scm_area, u64 token)
1179{
1180 int ccode, ret;
1181
1182 memset(scm_area, 0, sizeof(*scm_area));
1183 scm_area->request.length = 0x0020;
1184 scm_area->request.code = 0x004C;
1185 scm_area->reqtok = token;
1186
1187 ccode = chsc(scm_area);
1188 if (ccode > 0) {
1189 ret = (ccode == 3) ? -ENODEV : -EBUSY;
1190 goto out;
1191 }
1192 ret = chsc_error_from_response(scm_area->response.code);
1193 if (ret != 0)
1194 CIO_MSG_EVENT(2, "chsc: scm info failed (rc=%04x)\n",
1195 scm_area->response.code);
1196out:
1197 return ret;
1198}
1199EXPORT_SYMBOL_GPL(chsc_scm_info);