blob: 68e80e2734a4be89763ca466a48621911570bce4 [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
Peter Oberparleitere82a1562008-01-26 14:10:48 +0100147static int s390_subchannel_remove_chpid(struct subchannel *sch, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148{
Cornelia Huck2ec22982006-12-08 15:54:26 +0100149 spin_lock_irq(sch->lock);
Cornelia Huckc820de32008-07-14 09:58:45 +0200150 if (sch->driver && sch->driver->chp_event)
151 if (sch->driver->chp_event(sch, data, CHP_OFFLINE) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 goto out_unreg;
Cornelia Huck2ec22982006-12-08 15:54:26 +0100153 spin_unlock_irq(sch->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 return 0;
Stefan Bader387b7342007-04-27 16:01:33 +0200155
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156out_unreg:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 sch->lpm = 0;
Stefan Bader387b7342007-04-27 16:01:33 +0200158 spin_unlock_irq(sch->lock);
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200159 css_schedule_eval(sch->schid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 return 0;
161}
162
Peter Oberparleitere6b6e102007-04-27 16:01:28 +0200163void chsc_chp_offline(struct chp_id chpid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164{
165 char dbf_txt[15];
Cornelia Huck99611f82008-07-14 09:59:02 +0200166 struct chp_link link;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167
Peter Oberparleiterf86635f2007-04-27 16:01:26 +0200168 sprintf(dbf_txt, "chpr%x.%02x", chpid.cssid, chpid.id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 CIO_TRACE_EVENT(2, dbf_txt);
170
Peter Oberparleitere6b6e102007-04-27 16:01:28 +0200171 if (chp_get_status(chpid) <= 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 return;
Cornelia Huck99611f82008-07-14 09:59:02 +0200173 memset(&link, 0, sizeof(struct chp_link));
174 link.chpid = chpid;
Cornelia Huck22806dc2008-04-17 07:45:59 +0200175 /* Wait until previous actions have settled. */
176 css_wait_for_slow_path();
Cornelia Huck99611f82008-07-14 09:59:02 +0200177 for_each_subchannel_staged(s390_subchannel_remove_chpid, NULL, &link);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178}
179
Peter Oberparleitere82a1562008-01-26 14:10:48 +0100180static int s390_process_res_acc_new_sch(struct subchannel_id schid, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181{
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800182 struct schib schib;
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800183 /*
184 * We don't know the device yet, but since a path
185 * may be available now to the device we'll have
186 * to do recognition again.
187 * Since we don't have any idea about which chpid
188 * that beast may be on we'll have to do a stsch
189 * on all devices, grr...
190 */
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800191 if (stsch_err(schid, &schib))
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800192 /* We're through */
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200193 return -ENXIO;
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800194
195 /* Put it on the slow path. */
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200196 css_schedule_eval(schid);
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800197 return 0;
198}
199
Peter Oberparleitere82a1562008-01-26 14:10:48 +0100200static int __s390_process_res_acc(struct subchannel *sch, void *data)
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800201{
Cornelia Huck2ec22982006-12-08 15:54:26 +0100202 spin_lock_irq(sch->lock);
Cornelia Huckc820de32008-07-14 09:58:45 +0200203 if (sch->driver && sch->driver->chp_event)
204 sch->driver->chp_event(sch, data, CHP_ONLINE);
Cornelia Huck2ec22982006-12-08 15:54:26 +0100205 spin_unlock_irq(sch->lock);
Peter Oberparleitere82a1562008-01-26 14:10:48 +0100206
Peter Oberparleiterdd9963f2006-09-20 15:59:54 +0200207 return 0;
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800208}
209
Cornelia Huck99611f82008-07-14 09:59:02 +0200210static void s390_process_res_acc(struct chp_link *link)
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800211{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 char dbf_txt[15];
213
Cornelia Huck99611f82008-07-14 09:59:02 +0200214 sprintf(dbf_txt, "accpr%x.%02x", link->chpid.cssid,
215 link->chpid.id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 CIO_TRACE_EVENT( 2, dbf_txt);
Cornelia Huck99611f82008-07-14 09:59:02 +0200217 if (link->fla != 0) {
218 sprintf(dbf_txt, "fla%x", link->fla);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 CIO_TRACE_EVENT( 2, dbf_txt);
220 }
Cornelia Huck22806dc2008-04-17 07:45:59 +0200221 /* Wait until previous actions have settled. */
222 css_wait_for_slow_path();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 /*
224 * I/O resources may have become accessible.
225 * Scan through all subchannels that may be concerned and
226 * do a validation on those.
227 * The more information we have (info), the less scanning
228 * will we have to do.
229 */
Peter Oberparleitere82a1562008-01-26 14:10:48 +0100230 for_each_subchannel_staged(__s390_process_res_acc,
Cornelia Huck99611f82008-07-14 09:59:02 +0200231 s390_process_res_acc_new_sch, link);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232}
233
234static int
235__get_chpid_from_lir(void *data)
236{
237 struct lir {
238 u8 iq;
239 u8 ic;
240 u16 sci;
241 /* incident-node descriptor */
242 u32 indesc[28];
243 /* attached-node descriptor */
244 u32 andesc[28];
245 /* incident-specific information */
246 u32 isinfo[28];
Peter Oberparleiter0f008aa2007-02-05 21:17:40 +0100247 } __attribute__ ((packed)) *lir;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248
Cornelia Huck12975ae2006-10-11 15:31:47 +0200249 lir = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 if (!(lir->iq&0x80))
251 /* NULL link incident record */
252 return -EINVAL;
253 if (!(lir->indesc[0]&0xc0000000))
254 /* node descriptor not valid */
255 return -EINVAL;
256 if (!(lir->indesc[0]&0x10000000))
257 /* don't handle device-type nodes - FIXME */
258 return -EINVAL;
259 /* Byte 3 contains the chpid. Could also be CTCA, but we don't care */
260
261 return (u16) (lir->indesc[0]&0x000000ff);
262}
263
Jan Glaubercbc0dd12012-11-29 14:34:48 +0100264struct chsc_sei_nt0_area {
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 */
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100271 u32 reserved1;
272 u32 reserved2;
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100273 /* ccdf has to be big enough for a link-incident record */
Jan Glaubercbc0dd12012-11-29 14:34:48 +0100274 u8 ccdf[PAGE_SIZE - 24 - 16]; /* content-code dependent field */
275} __packed;
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100276
Jan Glaubercbc0dd12012-11-29 14:34:48 +0100277struct chsc_sei_nt2_area {
278 u8 flags; /* p and v bit */
279 u8 reserved1;
280 u8 reserved2;
281 u8 cc; /* content code */
282 u32 reserved3[13];
283 u8 ccdf[PAGE_SIZE - 24 - 56]; /* content-code dependent field */
284} __packed;
285
286#define CHSC_SEI_NT0 0ULL
287#define CHSC_SEI_NT2 (1ULL << 61)
288
289struct chsc_sei {
290 struct chsc_header request;
291 u32 reserved1;
292 u64 ntsm; /* notification type mask */
293 struct chsc_header response;
294 u32 reserved2;
295 union {
296 struct chsc_sei_nt0_area nt0_area;
297 struct chsc_sei_nt2_area nt2_area;
298 u8 nt_area[PAGE_SIZE - 24];
299 } u;
300} __packed;
301
302static void chsc_process_sei_link_incident(struct chsc_sei_nt0_area *sei_area)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303{
Peter Oberparleiterf86635f2007-04-27 16:01:26 +0200304 struct chp_id chpid;
305 int id;
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100306
307 CIO_CRW_EVENT(4, "chsc: link incident (rs=%02x, rs_id=%04x)\n",
308 sei_area->rs, sei_area->rsid);
309 if (sei_area->rs != 4)
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200310 return;
Peter Oberparleiterf86635f2007-04-27 16:01:26 +0200311 id = __get_chpid_from_lir(sei_area->ccdf);
312 if (id < 0)
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100313 CIO_CRW_EVENT(4, "chsc: link incident - invalid LIR\n");
Peter Oberparleiterf86635f2007-04-27 16:01:26 +0200314 else {
315 chp_id_init(&chpid);
316 chpid.id = id;
Peter Oberparleitere6b6e102007-04-27 16:01:28 +0200317 chsc_chp_offline(chpid);
Peter Oberparleiterf86635f2007-04-27 16:01:26 +0200318 }
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100319}
320
Jan Glaubercbc0dd12012-11-29 14:34:48 +0100321static void chsc_process_sei_res_acc(struct chsc_sei_nt0_area *sei_area)
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100322{
Cornelia Huck99611f82008-07-14 09:59:02 +0200323 struct chp_link link;
Peter Oberparleiterf86635f2007-04-27 16:01:26 +0200324 struct chp_id chpid;
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100325 int status;
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100326
327 CIO_CRW_EVENT(4, "chsc: resource accessibility event (rs=%02x, "
328 "rs_id=%04x)\n", sei_area->rs, sei_area->rsid);
329 if (sei_area->rs != 4)
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200330 return;
Peter Oberparleiterf86635f2007-04-27 16:01:26 +0200331 chp_id_init(&chpid);
332 chpid.id = sei_area->rsid;
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100333 /* allocate a new channel path structure, if needed */
Peter Oberparleitere6b6e102007-04-27 16:01:28 +0200334 status = chp_get_status(chpid);
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100335 if (status < 0)
Peter Oberparleitere6b6e102007-04-27 16:01:28 +0200336 chp_new(chpid);
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100337 else if (!status)
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200338 return;
Cornelia Huck99611f82008-07-14 09:59:02 +0200339 memset(&link, 0, sizeof(struct chp_link));
340 link.chpid = chpid;
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100341 if ((sei_area->vf & 0xc0) != 0) {
Cornelia Huck99611f82008-07-14 09:59:02 +0200342 link.fla = sei_area->fla;
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100343 if ((sei_area->vf & 0xc0) == 0xc0)
344 /* full link address */
Cornelia Huck99611f82008-07-14 09:59:02 +0200345 link.fla_mask = 0xffff;
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100346 else
347 /* link address */
Cornelia Huck99611f82008-07-14 09:59:02 +0200348 link.fla_mask = 0xff00;
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100349 }
Cornelia Huck99611f82008-07-14 09:59:02 +0200350 s390_process_res_acc(&link);
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100351}
352
Jan Glaubercbc0dd12012-11-29 14:34:48 +0100353static void chsc_process_sei_chp_avail(struct chsc_sei_nt0_area *sei_area)
Sebastian Ottfca894ed2011-05-23 10:24:41 +0200354{
355 struct channel_path *chp;
356 struct chp_id chpid;
357 u8 *data;
358 int num;
359
360 CIO_CRW_EVENT(4, "chsc: channel path availability information\n");
361 if (sei_area->rs != 0)
362 return;
363 data = sei_area->ccdf;
364 chp_id_init(&chpid);
365 for (num = 0; num <= __MAX_CHPID; num++) {
366 if (!chp_test_bit(data, num))
367 continue;
368 chpid.id = num;
369
370 CIO_CRW_EVENT(4, "Update information for channel path "
371 "%x.%02x\n", chpid.cssid, chpid.id);
372 chp = chpid_to_chp(chpid);
373 if (!chp) {
374 chp_new(chpid);
375 continue;
376 }
377 mutex_lock(&chp->lock);
378 chsc_determine_base_channel_path_desc(chpid, &chp->desc);
379 mutex_unlock(&chp->lock);
380 }
381}
382
Peter Oberparleitere5854a52007-04-27 16:01:31 +0200383struct chp_config_data {
384 u8 map[32];
385 u8 op;
386 u8 pc;
387};
388
Jan Glaubercbc0dd12012-11-29 14:34:48 +0100389static void chsc_process_sei_chp_config(struct chsc_sei_nt0_area *sei_area)
Peter Oberparleitere5854a52007-04-27 16:01:31 +0200390{
391 struct chp_config_data *data;
392 struct chp_id chpid;
393 int num;
Michael Ernste6d5a422008-12-25 13:39:36 +0100394 char *events[3] = {"configure", "deconfigure", "cancel deconfigure"};
Peter Oberparleitere5854a52007-04-27 16:01:31 +0200395
396 CIO_CRW_EVENT(4, "chsc: channel-path-configuration notification\n");
397 if (sei_area->rs != 0)
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200398 return;
Peter Oberparleitere5854a52007-04-27 16:01:31 +0200399 data = (struct chp_config_data *) &(sei_area->ccdf);
400 chp_id_init(&chpid);
401 for (num = 0; num <= __MAX_CHPID; num++) {
402 if (!chp_test_bit(data->map, num))
403 continue;
404 chpid.id = num;
Michael Ernste6d5a422008-12-25 13:39:36 +0100405 pr_notice("Processing %s for channel path %x.%02x\n",
406 events[data->op], chpid.cssid, chpid.id);
Peter Oberparleitere5854a52007-04-27 16:01:31 +0200407 switch (data->op) {
408 case 0:
409 chp_cfg_schedule(chpid, 1);
410 break;
411 case 1:
412 chp_cfg_schedule(chpid, 0);
413 break;
414 case 2:
415 chp_cfg_cancel_deconfigure(chpid);
416 break;
417 }
418 }
Peter Oberparleitere5854a52007-04-27 16:01:31 +0200419}
420
Jan Glaubercbc0dd12012-11-29 14:34:48 +0100421static void chsc_process_sei_scm_change(struct chsc_sei_nt0_area *sei_area)
Sebastian Ott40ff4cc2012-08-28 16:47:02 +0200422{
423 int ret;
424
425 CIO_CRW_EVENT(4, "chsc: scm change notification\n");
426 if (sei_area->rs != 7)
427 return;
428
429 ret = scm_update_information();
430 if (ret)
431 CIO_CRW_EVENT(0, "chsc: updating change notification"
432 " failed (rc=%d).\n", ret);
433}
434
Jan Glaubercbc0dd12012-11-29 14:34:48 +0100435static void chsc_process_sei_nt2(struct chsc_sei_nt2_area *sei_area)
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100436{
Jan Glaubercbc0dd12012-11-29 14:34:48 +0100437#ifdef CONFIG_PCI
438 switch (sei_area->cc) {
439 case 1:
440 zpci_event_error(sei_area->ccdf);
441 break;
442 case 2:
443 zpci_event_availability(sei_area->ccdf);
444 break;
445 default:
446 CIO_CRW_EVENT(2, "chsc: unhandled sei content code %d\n",
447 sei_area->cc);
448 break;
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200449 }
Jan Glaubercbc0dd12012-11-29 14:34:48 +0100450#endif
451}
452
453static void chsc_process_sei_nt0(struct chsc_sei_nt0_area *sei_area)
454{
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100455 /* which kind of information was stored? */
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100456 switch (sei_area->cc) {
457 case 1: /* link incident*/
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200458 chsc_process_sei_link_incident(sei_area);
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100459 break;
Sebastian Ottfca894ed2011-05-23 10:24:41 +0200460 case 2: /* i/o resource accessibility */
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200461 chsc_process_sei_res_acc(sei_area);
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100462 break;
Sebastian Ottfca894ed2011-05-23 10:24:41 +0200463 case 7: /* channel-path-availability information */
464 chsc_process_sei_chp_avail(sei_area);
465 break;
Peter Oberparleitere5854a52007-04-27 16:01:31 +0200466 case 8: /* channel-path-configuration notification */
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200467 chsc_process_sei_chp_config(sei_area);
Peter Oberparleitere5854a52007-04-27 16:01:31 +0200468 break;
Sebastian Ott40ff4cc2012-08-28 16:47:02 +0200469 case 12: /* scm change notification */
470 chsc_process_sei_scm_change(sei_area);
471 break;
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100472 default: /* other stuff */
473 CIO_CRW_EVENT(4, "chsc: unhandled sei content code %d\n",
474 sei_area->cc);
475 break;
476 }
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100477}
478
Jan Glaubercbc0dd12012-11-29 14:34:48 +0100479static int __chsc_process_crw(struct chsc_sei *sei, u64 ntsm)
480{
481 do {
482 memset(sei, 0, sizeof(*sei));
483 sei->request.length = 0x0010;
484 sei->request.code = 0x000e;
485 sei->ntsm = ntsm;
486
487 if (chsc(sei))
488 break;
489
490 if (sei->response.code == 0x0001) {
491 CIO_CRW_EVENT(2, "chsc: sei successful\n");
492
493 /* Check if we might have lost some information. */
494 if (sei->u.nt0_area.flags & 0x40) {
495 CIO_CRW_EVENT(2, "chsc: event overflow\n");
496 css_schedule_eval_all();
497 }
498
499 switch (sei->ntsm) {
500 case CHSC_SEI_NT0:
501 chsc_process_sei_nt0(&sei->u.nt0_area);
502 return 1;
503 case CHSC_SEI_NT2:
504 chsc_process_sei_nt2(&sei->u.nt2_area);
505 return 1;
506 default:
507 CIO_CRW_EVENT(2, "chsc: unhandled nt (nt=%08Lx)\n",
508 sei->ntsm);
509 return 0;
510 }
511 } else {
512 CIO_CRW_EVENT(2, "chsc: sei failed (rc=%04x)\n",
513 sei->response.code);
514 break;
515 }
516 } while (sei->u.nt0_area.flags & 0x80);
517
518 return 0;
519}
520
Cornelia Huckc1156182008-07-14 09:58:46 +0200521static void chsc_process_crw(struct crw *crw0, struct crw *crw1, int overflow)
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100522{
Jan Glaubercbc0dd12012-11-29 14:34:48 +0100523 struct chsc_sei *sei;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524
Cornelia Huckc1156182008-07-14 09:58:46 +0200525 if (overflow) {
526 css_schedule_eval_all();
527 return;
528 }
529 CIO_CRW_EVENT(2, "CRW reports slct=%d, oflw=%d, "
530 "chn=%d, rsc=%X, anc=%d, erc=%X, rsid=%X\n",
531 crw0->slct, crw0->oflw, crw0->chn, crw0->rsc, crw0->anc,
532 crw0->erc, crw0->rsid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 if (!sei_page)
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200534 return;
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100535 /* Access to sei_page is serialized through machine check handler
536 * thread, so no need for locking. */
Jan Glaubercbc0dd12012-11-29 14:34:48 +0100537 sei = sei_page;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538
Cornelia Huckc1156182008-07-14 09:58:46 +0200539 CIO_TRACE_EVENT(2, "prcss");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540
Jan Glaubercbc0dd12012-11-29 14:34:48 +0100541 /*
542 * The ntsm does not allow to select NT0 and NT2 together. We need to
543 * first check for NT2, than additionally for NT0...
544 */
545#ifdef CONFIG_PCI
546 if (!__chsc_process_crw(sei, CHSC_SEI_NT2))
547#endif
548 __chsc_process_crw(sei, CHSC_SEI_NT0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549}
550
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200551void chsc_chp_online(struct chp_id chpid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 char dbf_txt[15];
Cornelia Huck99611f82008-07-14 09:59:02 +0200554 struct chp_link link;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555
Peter Oberparleiterf86635f2007-04-27 16:01:26 +0200556 sprintf(dbf_txt, "cadd%x.%02x", chpid.cssid, chpid.id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 CIO_TRACE_EVENT(2, dbf_txt);
558
Cornelia Huck22806dc2008-04-17 07:45:59 +0200559 if (chp_get_status(chpid) != 0) {
Cornelia Huck99611f82008-07-14 09:59:02 +0200560 memset(&link, 0, sizeof(struct chp_link));
561 link.chpid = chpid;
Cornelia Huck22806dc2008-04-17 07:45:59 +0200562 /* Wait until previous actions have settled. */
563 css_wait_for_slow_path();
Cornelia Huckc820de32008-07-14 09:58:45 +0200564 for_each_subchannel_staged(__s390_process_res_acc, NULL,
Cornelia Huck99611f82008-07-14 09:59:02 +0200565 &link);
Cornelia Huck22806dc2008-04-17 07:45:59 +0200566 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567}
568
Peter Oberparleiterf86635f2007-04-27 16:01:26 +0200569static void __s390_subchannel_vary_chpid(struct subchannel *sch,
570 struct chp_id chpid, int on)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 unsigned long flags;
Cornelia Huck99611f82008-07-14 09:59:02 +0200573 struct chp_link link;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574
Cornelia Huck99611f82008-07-14 09:59:02 +0200575 memset(&link, 0, sizeof(struct chp_link));
576 link.chpid = chpid;
Cornelia Huck2ec22982006-12-08 15:54:26 +0100577 spin_lock_irqsave(sch->lock, flags);
Cornelia Huckc820de32008-07-14 09:58:45 +0200578 if (sch->driver && sch->driver->chp_event)
Cornelia Huck99611f82008-07-14 09:59:02 +0200579 sch->driver->chp_event(sch, &link,
Cornelia Huckc820de32008-07-14 09:58:45 +0200580 on ? CHP_VARY_ON : CHP_VARY_OFF);
Cornelia Huck2ec22982006-12-08 15:54:26 +0100581 spin_unlock_irqrestore(sch->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582}
583
Peter Oberparleitere82a1562008-01-26 14:10:48 +0100584static int s390_subchannel_vary_chpid_off(struct subchannel *sch, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585{
Peter Oberparleitere82a1562008-01-26 14:10:48 +0100586 struct chp_id *chpid = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587
588 __s390_subchannel_vary_chpid(sch, *chpid, 0);
589 return 0;
590}
591
Peter Oberparleitere82a1562008-01-26 14:10:48 +0100592static int s390_subchannel_vary_chpid_on(struct subchannel *sch, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593{
Peter Oberparleitere82a1562008-01-26 14:10:48 +0100594 struct chp_id *chpid = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595
596 __s390_subchannel_vary_chpid(sch, *chpid, 1);
597 return 0;
598}
599
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800600static int
601__s390_vary_chpid_on(struct subchannel_id schid, void *data)
602{
603 struct schib schib;
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800604
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800605 if (stsch_err(schid, &schib))
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800606 /* We're through */
607 return -ENXIO;
608 /* Put it on the slow path. */
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200609 css_schedule_eval(schid);
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800610 return 0;
611}
612
Peter Oberparleitere6b6e102007-04-27 16:01:28 +0200613/**
614 * chsc_chp_vary - propagate channel-path vary operation to subchannels
615 * @chpid: channl-path ID
616 * @on: non-zero for vary online, zero for vary offline
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 */
Peter Oberparleitere6b6e102007-04-27 16:01:28 +0200618int chsc_chp_vary(struct chp_id chpid, int on)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619{
Sebastian Ottc38a90a2010-10-25 16:10:31 +0200620 struct channel_path *chp = chpid_to_chp(chpid);
Cornelia Huck99611f82008-07-14 09:59:02 +0200621
Cornelia Huck22806dc2008-04-17 07:45:59 +0200622 /* Wait until previous actions have settled. */
623 css_wait_for_slow_path();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 /*
625 * Redo PathVerification on the devices the chpid connects to
626 */
Sebastian Ottc38a90a2010-10-25 16:10:31 +0200627 if (on) {
628 /* Try to update the channel path descritor. */
629 chsc_determine_base_channel_path_desc(chpid, &chp->desc);
Peter Oberparleitere82a1562008-01-26 14:10:48 +0100630 for_each_subchannel_staged(s390_subchannel_vary_chpid_on,
Sebastian Ott3b484ec2011-12-01 13:32:22 +0100631 __s390_vary_chpid_on, &chpid);
Sebastian Ottc38a90a2010-10-25 16:10:31 +0200632 } else
Peter Oberparleitere82a1562008-01-26 14:10:48 +0100633 for_each_subchannel_staged(s390_subchannel_vary_chpid_off,
Sebastian Ott3b484ec2011-12-01 13:32:22 +0100634 NULL, &chpid);
Peter Oberparleitere82a1562008-01-26 14:10:48 +0100635
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 return 0;
637}
638
Cornelia Huck495a5b42006-03-24 03:15:14 -0800639static void
640chsc_remove_cmg_attr(struct channel_subsystem *css)
641{
642 int i;
643
644 for (i = 0; i <= __MAX_CHPID; i++) {
645 if (!css->chps[i])
646 continue;
Peter Oberparleitere6b6e102007-04-27 16:01:28 +0200647 chp_remove_cmg_attr(css->chps[i]);
Cornelia Huck495a5b42006-03-24 03:15:14 -0800648 }
649}
650
651static int
652chsc_add_cmg_attr(struct channel_subsystem *css)
653{
654 int i, ret;
655
656 ret = 0;
657 for (i = 0; i <= __MAX_CHPID; i++) {
658 if (!css->chps[i])
659 continue;
Peter Oberparleitere6b6e102007-04-27 16:01:28 +0200660 ret = chp_add_cmg_attr(css->chps[i]);
Cornelia Huck495a5b42006-03-24 03:15:14 -0800661 if (ret)
662 goto cleanup;
663 }
664 return ret;
665cleanup:
666 for (--i; i >= 0; i--) {
667 if (!css->chps[i])
668 continue;
Peter Oberparleitere6b6e102007-04-27 16:01:28 +0200669 chp_remove_cmg_attr(css->chps[i]);
Cornelia Huck495a5b42006-03-24 03:15:14 -0800670 }
671 return ret;
672}
673
Sebastian Ott34196f82010-10-25 16:10:29 +0200674int __chsc_do_secm(struct channel_subsystem *css, int enable)
Cornelia Huck495a5b42006-03-24 03:15:14 -0800675{
676 struct {
677 struct chsc_header request;
678 u32 operation_code : 2;
679 u32 : 30;
680 u32 key : 4;
681 u32 : 28;
682 u32 zeroes1;
683 u32 cub_addr1;
684 u32 zeroes2;
685 u32 cub_addr2;
686 u32 reserved[13];
687 struct chsc_header response;
688 u32 status : 8;
689 u32 : 4;
690 u32 fmt : 4;
691 u32 : 16;
Peter Oberparleiter0f008aa2007-02-05 21:17:40 +0100692 } __attribute__ ((packed)) *secm_area;
Cornelia Huck495a5b42006-03-24 03:15:14 -0800693 int ret, ccode;
694
Sebastian Ott34196f82010-10-25 16:10:29 +0200695 spin_lock_irq(&chsc_page_lock);
696 memset(chsc_page, 0, PAGE_SIZE);
697 secm_area = chsc_page;
Cornelia Huck495a5b42006-03-24 03:15:14 -0800698 secm_area->request.length = 0x0050;
699 secm_area->request.code = 0x0016;
700
Heiko Carstensd1bf8592010-02-26 22:37:30 +0100701 secm_area->key = PAGE_DEFAULT_KEY >> 4;
Cornelia Huck495a5b42006-03-24 03:15:14 -0800702 secm_area->cub_addr1 = (u64)(unsigned long)css->cub_addr1;
703 secm_area->cub_addr2 = (u64)(unsigned long)css->cub_addr2;
704
705 secm_area->operation_code = enable ? 0 : 1;
706
707 ccode = chsc(secm_area);
Sebastian Ott34196f82010-10-25 16:10:29 +0200708 if (ccode > 0) {
709 ret = (ccode == 3) ? -ENODEV : -EBUSY;
710 goto out;
711 }
Cornelia Huck495a5b42006-03-24 03:15:14 -0800712
713 switch (secm_area->response.code) {
Cornelia Huckb9c9a212008-02-05 16:50:34 +0100714 case 0x0102:
715 case 0x0103:
Cornelia Huck495a5b42006-03-24 03:15:14 -0800716 ret = -EINVAL;
Sebastian Ott17e7d872009-03-26 15:24:17 +0100717 break;
Cornelia Huck495a5b42006-03-24 03:15:14 -0800718 default:
Cornelia Huckb9c9a212008-02-05 16:50:34 +0100719 ret = chsc_error_from_response(secm_area->response.code);
Cornelia Huck495a5b42006-03-24 03:15:14 -0800720 }
Cornelia Huckb9c9a212008-02-05 16:50:34 +0100721 if (ret != 0)
722 CIO_CRW_EVENT(2, "chsc: secm failed (rc=%04x)\n",
723 secm_area->response.code);
Sebastian Ott34196f82010-10-25 16:10:29 +0200724out:
725 spin_unlock_irq(&chsc_page_lock);
Cornelia Huck495a5b42006-03-24 03:15:14 -0800726 return ret;
727}
728
729int
730chsc_secm(struct channel_subsystem *css, int enable)
731{
Cornelia Huck495a5b42006-03-24 03:15:14 -0800732 int ret;
733
Cornelia Huck495a5b42006-03-24 03:15:14 -0800734 if (enable && !css->cm_enabled) {
735 css->cub_addr1 = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
736 css->cub_addr2 = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
737 if (!css->cub_addr1 || !css->cub_addr2) {
738 free_page((unsigned long)css->cub_addr1);
739 free_page((unsigned long)css->cub_addr2);
Cornelia Huck495a5b42006-03-24 03:15:14 -0800740 return -ENOMEM;
741 }
742 }
Sebastian Ott34196f82010-10-25 16:10:29 +0200743 ret = __chsc_do_secm(css, enable);
Cornelia Huck495a5b42006-03-24 03:15:14 -0800744 if (!ret) {
745 css->cm_enabled = enable;
746 if (css->cm_enabled) {
747 ret = chsc_add_cmg_attr(css);
748 if (ret) {
Sebastian Ott34196f82010-10-25 16:10:29 +0200749 __chsc_do_secm(css, 0);
Cornelia Huck495a5b42006-03-24 03:15:14 -0800750 css->cm_enabled = 0;
751 }
752 } else
753 chsc_remove_cmg_attr(css);
754 }
Cornelia Huck8c4941c2007-04-27 16:01:38 +0200755 if (!css->cm_enabled) {
Cornelia Huck495a5b42006-03-24 03:15:14 -0800756 free_page((unsigned long)css->cub_addr1);
757 free_page((unsigned long)css->cub_addr2);
758 }
Cornelia Huck495a5b42006-03-24 03:15:14 -0800759 return ret;
760}
761
Cornelia Huck9d92a7e2008-07-14 09:59:05 +0200762int chsc_determine_channel_path_desc(struct chp_id chpid, int fmt, int rfmt,
Sebastian Ott906c9762010-10-25 16:10:30 +0200763 int c, int m, void *page)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764{
Sebastian Ott906c9762010-10-25 16:10:30 +0200765 struct chsc_scpd *scpd_area;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766 int ccode, ret;
767
Cornelia Huck9d92a7e2008-07-14 09:59:05 +0200768 if ((rfmt == 1) && !css_general_characteristics.fcs)
769 return -EINVAL;
770 if ((rfmt == 2) && !css_general_characteristics.cib)
771 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772
Sebastian Ott906c9762010-10-25 16:10:30 +0200773 memset(page, 0, PAGE_SIZE);
774 scpd_area = page;
Cornelia Huck495a5b42006-03-24 03:15:14 -0800775 scpd_area->request.length = 0x0010;
776 scpd_area->request.code = 0x0002;
Cornelia Huck9d92a7e2008-07-14 09:59:05 +0200777 scpd_area->cssid = chpid.cssid;
Peter Oberparleiterf86635f2007-04-27 16:01:26 +0200778 scpd_area->first_chpid = chpid.id;
779 scpd_area->last_chpid = chpid.id;
Cornelia Huck9d92a7e2008-07-14 09:59:05 +0200780 scpd_area->m = m;
781 scpd_area->c = c;
782 scpd_area->fmt = fmt;
783 scpd_area->rfmt = rfmt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784
785 ccode = chsc(scpd_area);
Sebastian Ott906c9762010-10-25 16:10:30 +0200786 if (ccode > 0)
787 return (ccode == 3) ? -ENODEV : -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788
Cornelia Huckb9c9a212008-02-05 16:50:34 +0100789 ret = chsc_error_from_response(scpd_area->response.code);
Sebastian Ott906c9762010-10-25 16:10:30 +0200790 if (ret)
Cornelia Huckb9c9a212008-02-05 16:50:34 +0100791 CIO_CRW_EVENT(2, "chsc: scpd failed (rc=%04x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 scpd_area->response.code);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793 return ret;
794}
Cornelia Huck9d92a7e2008-07-14 09:59:05 +0200795EXPORT_SYMBOL_GPL(chsc_determine_channel_path_desc);
796
797int chsc_determine_base_channel_path_desc(struct chp_id chpid,
798 struct channel_path_desc *desc)
799{
800 struct chsc_response_struct *chsc_resp;
Sebastian Ott906c9762010-10-25 16:10:30 +0200801 struct chsc_scpd *scpd_area;
Sebastian Ott62da1772010-10-25 16:10:32 +0200802 unsigned long flags;
Cornelia Huck9d92a7e2008-07-14 09:59:05 +0200803 int ret;
804
Sebastian Ott62da1772010-10-25 16:10:32 +0200805 spin_lock_irqsave(&chsc_page_lock, flags);
Sebastian Ott906c9762010-10-25 16:10:30 +0200806 scpd_area = chsc_page;
807 ret = chsc_determine_channel_path_desc(chpid, 0, 0, 0, 0, scpd_area);
Cornelia Huck9d92a7e2008-07-14 09:59:05 +0200808 if (ret)
Sebastian Ott906c9762010-10-25 16:10:30 +0200809 goto out;
810 chsc_resp = (void *)&scpd_area->response;
Sebastian Ott878c4952010-07-19 09:22:37 +0200811 memcpy(desc, &chsc_resp->data, sizeof(*desc));
Sebastian Ott906c9762010-10-25 16:10:30 +0200812out:
Sebastian Ott62da1772010-10-25 16:10:32 +0200813 spin_unlock_irqrestore(&chsc_page_lock, flags);
Cornelia Huck9d92a7e2008-07-14 09:59:05 +0200814 return ret;
815}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816
Sebastian Ottce322cc2011-01-05 12:47:56 +0100817int chsc_determine_fmt1_channel_path_desc(struct chp_id chpid,
818 struct channel_path_desc_fmt1 *desc)
819{
820 struct chsc_response_struct *chsc_resp;
821 struct chsc_scpd *scpd_area;
822 int ret;
823
824 spin_lock_irq(&chsc_page_lock);
825 scpd_area = chsc_page;
826 ret = chsc_determine_channel_path_desc(chpid, 0, 0, 1, 0, scpd_area);
827 if (ret)
828 goto out;
829 chsc_resp = (void *)&scpd_area->response;
830 memcpy(desc, &chsc_resp->data, sizeof(*desc));
831out:
832 spin_unlock_irq(&chsc_page_lock);
833 return ret;
834}
835
Cornelia Huck495a5b42006-03-24 03:15:14 -0800836static void
837chsc_initialize_cmg_chars(struct channel_path *chp, u8 cmcv,
838 struct cmg_chars *chars)
839{
Sebastian Ott34196f82010-10-25 16:10:29 +0200840 struct cmg_chars *cmg_chars;
841 int i, mask;
Cornelia Huck495a5b42006-03-24 03:15:14 -0800842
Sebastian Ott34196f82010-10-25 16:10:29 +0200843 cmg_chars = chp->cmg_chars;
844 for (i = 0; i < NR_MEASUREMENT_CHARS; i++) {
845 mask = 0x80 >> (i + 3);
846 if (cmcv & mask)
847 cmg_chars->values[i] = chars->values[i];
848 else
849 cmg_chars->values[i] = 0;
Cornelia Huck495a5b42006-03-24 03:15:14 -0800850 }
851}
852
Peter Oberparleitere6b6e102007-04-27 16:01:28 +0200853int chsc_get_channel_measurement_chars(struct channel_path *chp)
Cornelia Huck495a5b42006-03-24 03:15:14 -0800854{
Sebastian Ott34196f82010-10-25 16:10:29 +0200855 struct cmg_chars *cmg_chars;
Cornelia Huck495a5b42006-03-24 03:15:14 -0800856 int ccode, ret;
857
858 struct {
859 struct chsc_header request;
860 u32 : 24;
861 u32 first_chpid : 8;
862 u32 : 24;
863 u32 last_chpid : 8;
864 u32 zeroes1;
865 struct chsc_header response;
866 u32 zeroes2;
867 u32 not_valid : 1;
868 u32 shared : 1;
869 u32 : 22;
870 u32 chpid : 8;
871 u32 cmcv : 5;
872 u32 : 11;
873 u32 cmgq : 8;
874 u32 cmg : 8;
875 u32 zeroes3;
876 u32 data[NR_MEASUREMENT_CHARS];
Peter Oberparleiter0f008aa2007-02-05 21:17:40 +0100877 } __attribute__ ((packed)) *scmc_area;
Cornelia Huck495a5b42006-03-24 03:15:14 -0800878
Sebastian Ott34196f82010-10-25 16:10:29 +0200879 chp->cmg_chars = NULL;
880 cmg_chars = kmalloc(sizeof(*cmg_chars), GFP_KERNEL);
881 if (!cmg_chars)
Cornelia Huck495a5b42006-03-24 03:15:14 -0800882 return -ENOMEM;
883
Sebastian Ott34196f82010-10-25 16:10:29 +0200884 spin_lock_irq(&chsc_page_lock);
885 memset(chsc_page, 0, PAGE_SIZE);
886 scmc_area = chsc_page;
Cornelia Huck495a5b42006-03-24 03:15:14 -0800887 scmc_area->request.length = 0x0010;
888 scmc_area->request.code = 0x0022;
Peter Oberparleiterf86635f2007-04-27 16:01:26 +0200889 scmc_area->first_chpid = chp->chpid.id;
890 scmc_area->last_chpid = chp->chpid.id;
Cornelia Huck495a5b42006-03-24 03:15:14 -0800891
892 ccode = chsc(scmc_area);
893 if (ccode > 0) {
894 ret = (ccode == 3) ? -ENODEV : -EBUSY;
895 goto out;
896 }
897
Cornelia Huckb9c9a212008-02-05 16:50:34 +0100898 ret = chsc_error_from_response(scmc_area->response.code);
Sebastian Ott34196f82010-10-25 16:10:29 +0200899 if (ret) {
Cornelia Huckb9c9a212008-02-05 16:50:34 +0100900 CIO_CRW_EVENT(2, "chsc: scmc failed (rc=%04x)\n",
Cornelia Huck495a5b42006-03-24 03:15:14 -0800901 scmc_area->response.code);
Sebastian Ott34196f82010-10-25 16:10:29 +0200902 goto out;
Cornelia Huck495a5b42006-03-24 03:15:14 -0800903 }
Sebastian Ott34196f82010-10-25 16:10:29 +0200904 if (scmc_area->not_valid) {
905 chp->cmg = -1;
906 chp->shared = -1;
907 goto out;
908 }
909 chp->cmg = scmc_area->cmg;
910 chp->shared = scmc_area->shared;
911 if (chp->cmg != 2 && chp->cmg != 3) {
912 /* No cmg-dependent data. */
913 goto out;
914 }
915 chp->cmg_chars = cmg_chars;
916 chsc_initialize_cmg_chars(chp, scmc_area->cmcv,
917 (struct cmg_chars *) &scmc_area->data);
Cornelia Huck495a5b42006-03-24 03:15:14 -0800918out:
Sebastian Ott34196f82010-10-25 16:10:29 +0200919 spin_unlock_irq(&chsc_page_lock);
920 if (!chp->cmg_chars)
921 kfree(cmg_chars);
922
Cornelia Huck495a5b42006-03-24 03:15:14 -0800923 return ret;
924}
925
Sebastian Ott34aec072010-10-25 16:10:28 +0200926int __init chsc_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927{
Cornelia Huckc1156182008-07-14 09:58:46 +0200928 int ret;
929
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930 sei_page = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
Sebastian Ott34196f82010-10-25 16:10:29 +0200931 chsc_page = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
932 if (!sei_page || !chsc_page) {
933 ret = -ENOMEM;
934 goto out_err;
Cornelia Huckc1156182008-07-14 09:58:46 +0200935 }
Heiko Carstensf5daba12009-03-26 15:24:01 +0100936 ret = crw_register_handler(CRW_RSC_CSS, chsc_process_crw);
Cornelia Huckc1156182008-07-14 09:58:46 +0200937 if (ret)
Sebastian Ott34196f82010-10-25 16:10:29 +0200938 goto out_err;
939 return ret;
940out_err:
941 free_page((unsigned long)chsc_page);
942 free_page((unsigned long)sei_page);
Cornelia Huckc1156182008-07-14 09:58:46 +0200943 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944}
945
Sebastian Ott34aec072010-10-25 16:10:28 +0200946void __init chsc_init_cleanup(void)
Cornelia Huck4434a382007-07-27 12:29:21 +0200947{
Heiko Carstensf5daba12009-03-26 15:24:01 +0100948 crw_unregister_handler(CRW_RSC_CSS);
Sebastian Ott34196f82010-10-25 16:10:29 +0200949 free_page((unsigned long)chsc_page);
Sebastian Ott34aec072010-10-25 16:10:28 +0200950 free_page((unsigned long)sei_page);
Cornelia Huck4434a382007-07-27 12:29:21 +0200951}
952
Sebastian Ott818c2722010-04-22 17:17:03 +0200953int chsc_enable_facility(int operation_code)
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800954{
Sebastian Ott34196f82010-10-25 16:10:29 +0200955 unsigned long flags;
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800956 int ret;
Sebastian Ott34196f82010-10-25 16:10:29 +0200957 struct {
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800958 struct chsc_header request;
959 u8 reserved1:4;
960 u8 format:4;
961 u8 reserved2;
962 u16 operation_code;
963 u32 reserved3;
964 u32 reserved4;
965 u32 operation_data_area[252];
966 struct chsc_header response;
967 u32 reserved5:4;
968 u32 format2:4;
969 u32 reserved6:24;
Sebastian Ott34196f82010-10-25 16:10:29 +0200970 } __attribute__ ((packed)) *sda_area;
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800971
Sebastian Ott34196f82010-10-25 16:10:29 +0200972 spin_lock_irqsave(&chsc_page_lock, flags);
973 memset(chsc_page, 0, PAGE_SIZE);
974 sda_area = chsc_page;
975 sda_area->request.length = 0x0400;
976 sda_area->request.code = 0x0031;
977 sda_area->operation_code = operation_code;
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800978
Sebastian Ott34196f82010-10-25 16:10:29 +0200979 ret = chsc(sda_area);
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800980 if (ret > 0) {
981 ret = (ret == 3) ? -ENODEV : -EBUSY;
982 goto out;
983 }
Cornelia Huckb9c9a212008-02-05 16:50:34 +0100984
Sebastian Ott34196f82010-10-25 16:10:29 +0200985 switch (sda_area->response.code) {
Cornelia Huckb9c9a212008-02-05 16:50:34 +0100986 case 0x0101:
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800987 ret = -EOPNOTSUPP;
988 break;
Cornelia Huckb9c9a212008-02-05 16:50:34 +0100989 default:
Sebastian Ott34196f82010-10-25 16:10:29 +0200990 ret = chsc_error_from_response(sda_area->response.code);
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800991 }
Cornelia Huckb9c9a212008-02-05 16:50:34 +0100992 if (ret != 0)
993 CIO_CRW_EVENT(2, "chsc: sda (oc=%x) failed (rc=%04x)\n",
Sebastian Ott34196f82010-10-25 16:10:29 +0200994 operation_code, sda_area->response.code);
995out:
996 spin_unlock_irqrestore(&chsc_page_lock, flags);
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800997 return ret;
998}
999
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000struct css_general_char css_general_characteristics;
1001struct css_chsc_char css_chsc_characteristics;
1002
1003int __init
1004chsc_determine_css_characteristics(void)
1005{
1006 int result;
1007 struct {
1008 struct chsc_header request;
1009 u32 reserved1;
1010 u32 reserved2;
1011 u32 reserved3;
1012 struct chsc_header response;
1013 u32 reserved4;
1014 u32 general_char[510];
Sebastian Ott34aec072010-10-25 16:10:28 +02001015 u32 chsc_char[508];
Peter Oberparleiter0f008aa2007-02-05 21:17:40 +01001016 } __attribute__ ((packed)) *scsc_area;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017
Sebastian Ott34196f82010-10-25 16:10:29 +02001018 spin_lock_irq(&chsc_page_lock);
1019 memset(chsc_page, 0, PAGE_SIZE);
1020 scsc_area = chsc_page;
Cornelia Huck495a5b42006-03-24 03:15:14 -08001021 scsc_area->request.length = 0x0010;
1022 scsc_area->request.code = 0x0010;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023
1024 result = chsc(scsc_area);
1025 if (result) {
Cornelia Huckb9c9a212008-02-05 16:50:34 +01001026 result = (result == 3) ? -ENODEV : -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027 goto exit;
1028 }
1029
Cornelia Huckb9c9a212008-02-05 16:50:34 +01001030 result = chsc_error_from_response(scsc_area->response.code);
1031 if (result == 0) {
1032 memcpy(&css_general_characteristics, scsc_area->general_char,
1033 sizeof(css_general_characteristics));
1034 memcpy(&css_chsc_characteristics, scsc_area->chsc_char,
1035 sizeof(css_chsc_characteristics));
1036 } else
1037 CIO_CRW_EVENT(2, "chsc: scsc failed (rc=%04x)\n",
1038 scsc_area->response.code);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039exit:
Sebastian Ott34196f82010-10-25 16:10:29 +02001040 spin_unlock_irq(&chsc_page_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041 return result;
1042}
1043
1044EXPORT_SYMBOL_GPL(css_general_characteristics);
1045EXPORT_SYMBOL_GPL(css_chsc_characteristics);
Martin Schwidefskyd2fec592008-07-14 09:58:56 +02001046
1047int chsc_sstpc(void *page, unsigned int op, u16 ctrl)
1048{
1049 struct {
1050 struct chsc_header request;
1051 unsigned int rsvd0;
1052 unsigned int op : 8;
1053 unsigned int rsvd1 : 8;
1054 unsigned int ctrl : 16;
1055 unsigned int rsvd2[5];
1056 struct chsc_header response;
1057 unsigned int rsvd3[7];
1058 } __attribute__ ((packed)) *rr;
1059 int rc;
1060
1061 memset(page, 0, PAGE_SIZE);
1062 rr = page;
1063 rr->request.length = 0x0020;
1064 rr->request.code = 0x0033;
1065 rr->op = op;
1066 rr->ctrl = ctrl;
1067 rc = chsc(rr);
1068 if (rc)
1069 return -EIO;
1070 rc = (rr->response.code == 0x0001) ? 0 : -EIO;
1071 return rc;
1072}
1073
1074int chsc_sstpi(void *page, void *result, size_t size)
1075{
1076 struct {
1077 struct chsc_header request;
1078 unsigned int rsvd0[3];
1079 struct chsc_header response;
1080 char data[size];
1081 } __attribute__ ((packed)) *rr;
1082 int rc;
1083
1084 memset(page, 0, PAGE_SIZE);
1085 rr = page;
1086 rr->request.length = 0x0010;
1087 rr->request.code = 0x0038;
1088 rc = chsc(rr);
1089 if (rc)
1090 return -EIO;
1091 memcpy(result, &rr->data, size);
1092 return (rr->response.code == 0x0001) ? 0 : -EIO;
1093}
1094
Michael Ernstfd0457a2010-08-09 18:12:50 +02001095int chsc_siosl(struct subchannel_id schid)
1096{
Sebastian Ott34196f82010-10-25 16:10:29 +02001097 struct {
1098 struct chsc_header request;
1099 u32 word1;
1100 struct subchannel_id sid;
1101 u32 word3;
1102 struct chsc_header response;
1103 u32 word[11];
1104 } __attribute__ ((packed)) *siosl_area;
Michael Ernstfd0457a2010-08-09 18:12:50 +02001105 unsigned long flags;
1106 int ccode;
1107 int rc;
1108
Sebastian Ott34196f82010-10-25 16:10:29 +02001109 spin_lock_irqsave(&chsc_page_lock, flags);
1110 memset(chsc_page, 0, PAGE_SIZE);
1111 siosl_area = chsc_page;
1112 siosl_area->request.length = 0x0010;
1113 siosl_area->request.code = 0x0046;
1114 siosl_area->word1 = 0x80000000;
1115 siosl_area->sid = schid;
Michael Ernstfd0457a2010-08-09 18:12:50 +02001116
Sebastian Ott34196f82010-10-25 16:10:29 +02001117 ccode = chsc(siosl_area);
Michael Ernstfd0457a2010-08-09 18:12:50 +02001118 if (ccode > 0) {
1119 if (ccode == 3)
1120 rc = -ENODEV;
1121 else
1122 rc = -EBUSY;
1123 CIO_MSG_EVENT(2, "chsc: chsc failed for 0.%x.%04x (ccode=%d)\n",
1124 schid.ssid, schid.sch_no, ccode);
1125 goto out;
1126 }
Sebastian Ott34196f82010-10-25 16:10:29 +02001127 rc = chsc_error_from_response(siosl_area->response.code);
Michael Ernstfd0457a2010-08-09 18:12:50 +02001128 if (rc)
1129 CIO_MSG_EVENT(2, "chsc: siosl failed for 0.%x.%04x (rc=%04x)\n",
1130 schid.ssid, schid.sch_no,
Sebastian Ott34196f82010-10-25 16:10:29 +02001131 siosl_area->response.code);
Michael Ernstfd0457a2010-08-09 18:12:50 +02001132 else
1133 CIO_MSG_EVENT(4, "chsc: siosl succeeded for 0.%x.%04x\n",
1134 schid.ssid, schid.sch_no);
1135out:
Sebastian Ott34196f82010-10-25 16:10:29 +02001136 spin_unlock_irqrestore(&chsc_page_lock, flags);
Michael Ernstfd0457a2010-08-09 18:12:50 +02001137 return rc;
1138}
1139EXPORT_SYMBOL_GPL(chsc_siosl);
Sebastian Ott184b08a2012-08-28 16:45:42 +02001140
1141/**
1142 * chsc_scm_info() - store SCM information (SSI)
1143 * @scm_area: request and response block for SSI
1144 * @token: continuation token
1145 *
1146 * Returns 0 on success.
1147 */
1148int chsc_scm_info(struct chsc_scm_info *scm_area, u64 token)
1149{
1150 int ccode, ret;
1151
1152 memset(scm_area, 0, sizeof(*scm_area));
1153 scm_area->request.length = 0x0020;
1154 scm_area->request.code = 0x004C;
1155 scm_area->reqtok = token;
1156
1157 ccode = chsc(scm_area);
1158 if (ccode > 0) {
1159 ret = (ccode == 3) ? -ENODEV : -EBUSY;
1160 goto out;
1161 }
1162 ret = chsc_error_from_response(scm_area->response.code);
1163 if (ret != 0)
1164 CIO_MSG_EVENT(2, "chsc: scm info failed (rc=%04x)\n",
1165 scm_area->response.code);
1166out:
1167 return ret;
1168}
1169EXPORT_SYMBOL_GPL(chsc_scm_info);