blob: eee70cb8730bf381fe4da4373a7fc65b98361fba [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>
Sebastian Ottca4ba152013-06-05 18:59:22 +020023#include <asm/isc.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024
25#include "css.h"
26#include "cio.h"
27#include "cio_debug.h"
28#include "ioasm.h"
Peter Oberparleitere6b6e102007-04-27 16:01:28 +020029#include "chp.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include "chsc.h"
31
Linus Torvalds1da177e2005-04-16 15:20:36 -070032static void *sei_page;
Sebastian Ott34196f82010-10-25 16:10:29 +020033static void *chsc_page;
34static DEFINE_SPINLOCK(chsc_page_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
Cornelia Huckdae39842008-07-17 17:16:47 +020036/**
37 * chsc_error_from_response() - convert a chsc response to an error
38 * @response: chsc response code
39 *
40 * Returns an appropriate Linux error code for @response.
41 */
42int chsc_error_from_response(int response)
Cornelia Huckb9c9a212008-02-05 16:50:34 +010043{
44 switch (response) {
45 case 0x0001:
46 return 0;
47 case 0x0002:
48 case 0x0003:
49 case 0x0006:
50 case 0x0007:
51 case 0x0008:
52 case 0x000a:
Michael Ernstfd0457a2010-08-09 18:12:50 +020053 case 0x0104:
Cornelia Huckb9c9a212008-02-05 16:50:34 +010054 return -EINVAL;
55 case 0x0004:
56 return -EOPNOTSUPP;
Sebastian Ott184b08a2012-08-28 16:45:42 +020057 case 0x000b:
58 return -EBUSY;
59 case 0x0100:
60 case 0x0102:
61 return -ENOMEM;
Cornelia Huckb9c9a212008-02-05 16:50:34 +010062 default:
63 return -EIO;
64 }
65}
Cornelia Huckdae39842008-07-17 17:16:47 +020066EXPORT_SYMBOL_GPL(chsc_error_from_response);
Cornelia Huckb9c9a212008-02-05 16:50:34 +010067
Peter Oberparleiter7ad6a242007-04-27 16:01:35 +020068struct chsc_ssd_area {
69 struct chsc_header request;
70 u16 :10;
71 u16 ssid:2;
72 u16 :4;
73 u16 f_sch; /* first subchannel */
74 u16 :16;
75 u16 l_sch; /* last subchannel */
76 u32 :32;
77 struct chsc_header response;
78 u32 :32;
79 u8 sch_valid : 1;
80 u8 dev_valid : 1;
81 u8 st : 3; /* subchannel type */
82 u8 zeroes : 3;
83 u8 unit_addr; /* unit address */
84 u16 devno; /* device number */
85 u8 path_mask;
86 u8 fla_valid_mask;
87 u16 sch; /* subchannel */
88 u8 chpid[8]; /* chpids 0-7 */
89 u16 fla[8]; /* full link addresses 0-7 */
90} __attribute__ ((packed));
91
92int chsc_get_ssd_info(struct subchannel_id schid, struct chsc_ssd_info *ssd)
Linus Torvalds1da177e2005-04-16 15:20:36 -070093{
Peter Oberparleiter7ad6a242007-04-27 16:01:35 +020094 struct chsc_ssd_area *ssd_area;
95 int ccode;
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 int ret;
Peter Oberparleiter7ad6a242007-04-27 16:01:35 +020097 int i;
98 int mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -070099
Sebastian Ott34196f82010-10-25 16:10:29 +0200100 spin_lock_irq(&chsc_page_lock);
101 memset(chsc_page, 0, PAGE_SIZE);
102 ssd_area = chsc_page;
Peter Oberparleiter7ad6a242007-04-27 16:01:35 +0200103 ssd_area->request.length = 0x0010;
104 ssd_area->request.code = 0x0004;
105 ssd_area->ssid = schid.ssid;
106 ssd_area->f_sch = schid.sch_no;
107 ssd_area->l_sch = schid.sch_no;
Peter Oberparleiterf86635f2007-04-27 16:01:26 +0200108
Peter Oberparleiter7ad6a242007-04-27 16:01:35 +0200109 ccode = chsc(ssd_area);
110 /* Check response. */
111 if (ccode > 0) {
112 ret = (ccode == 3) ? -ENODEV : -EBUSY;
Sebastian Ott34196f82010-10-25 16:10:29 +0200113 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 }
Cornelia Huckb9c9a212008-02-05 16:50:34 +0100115 ret = chsc_error_from_response(ssd_area->response.code);
116 if (ret != 0) {
Peter Oberparleiter7ad6a242007-04-27 16:01:35 +0200117 CIO_MSG_EVENT(2, "chsc: ssd failed for 0.%x.%04x (rc=%04x)\n",
118 schid.ssid, schid.sch_no,
119 ssd_area->response.code);
Sebastian Ott34196f82010-10-25 16:10:29 +0200120 goto out;
Peter Oberparleiter7ad6a242007-04-27 16:01:35 +0200121 }
122 if (!ssd_area->sch_valid) {
123 ret = -ENODEV;
Sebastian Ott34196f82010-10-25 16:10:29 +0200124 goto out;
Peter Oberparleiter7ad6a242007-04-27 16:01:35 +0200125 }
126 /* Copy data */
127 ret = 0;
128 memset(ssd, 0, sizeof(struct chsc_ssd_info));
Cornelia Huckb279a4f2008-01-26 14:10:45 +0100129 if ((ssd_area->st != SUBCHANNEL_TYPE_IO) &&
130 (ssd_area->st != SUBCHANNEL_TYPE_MSG))
Sebastian Ott34196f82010-10-25 16:10:29 +0200131 goto out;
Peter Oberparleiter7ad6a242007-04-27 16:01:35 +0200132 ssd->path_mask = ssd_area->path_mask;
133 ssd->fla_valid_mask = ssd_area->fla_valid_mask;
134 for (i = 0; i < 8; i++) {
135 mask = 0x80 >> i;
136 if (ssd_area->path_mask & mask) {
137 chp_id_init(&ssd->chpid[i]);
138 ssd->chpid[i].id = ssd_area->chpid[i];
139 }
140 if (ssd_area->fla_valid_mask & mask)
141 ssd->fla[i] = ssd_area->fla[i];
142 }
Sebastian Ott34196f82010-10-25 16:10:29 +0200143out:
144 spin_unlock_irq(&chsc_page_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 return ret;
146}
147
Sebastian Ottda5b6cb2013-06-05 18:58:35 +0200148/**
149 * chsc_ssqd() - store subchannel QDIO data (SSQD)
150 * @schid: id of the subchannel on which SSQD is performed
151 * @ssqd: request and response block for SSQD
152 *
153 * Returns 0 on success.
154 */
155int chsc_ssqd(struct subchannel_id schid, struct chsc_ssqd_area *ssqd)
156{
157 memset(ssqd, 0, sizeof(*ssqd));
158 ssqd->request.length = 0x0010;
159 ssqd->request.code = 0x0024;
160 ssqd->first_sch = schid.sch_no;
161 ssqd->last_sch = schid.sch_no;
162 ssqd->ssid = schid.ssid;
163
164 if (chsc(ssqd))
165 return -EIO;
166
167 return chsc_error_from_response(ssqd->response.code);
168}
169EXPORT_SYMBOL_GPL(chsc_ssqd);
170
Sebastian Ottca4ba152013-06-05 18:59:22 +0200171/**
172 * chsc_sadc() - set adapter device controls (SADC)
173 * @schid: id of the subchannel on which SADC is performed
174 * @scssc: request and response block for SADC
175 * @summary_indicator_addr: summary indicator address
176 * @subchannel_indicator_addr: subchannel indicator address
177 *
178 * Returns 0 on success.
179 */
180int chsc_sadc(struct subchannel_id schid, struct chsc_scssc_area *scssc,
181 u64 summary_indicator_addr, u64 subchannel_indicator_addr)
182{
183 memset(scssc, 0, sizeof(*scssc));
184 scssc->request.length = 0x0fe0;
185 scssc->request.code = 0x0021;
186 scssc->operation_code = 0;
187
188 scssc->summary_indicator_addr = summary_indicator_addr;
189 scssc->subchannel_indicator_addr = subchannel_indicator_addr;
190
191 scssc->ks = PAGE_DEFAULT_KEY >> 4;
192 scssc->kc = PAGE_DEFAULT_KEY >> 4;
193 scssc->isc = QDIO_AIRQ_ISC;
194 scssc->schid = schid;
195
196 /* enable the time delay disablement facility */
197 if (css_general_characteristics.aif_tdd)
198 scssc->word_with_d_bit = 0x10000000;
199
200 if (chsc(scssc))
201 return -EIO;
202
203 return chsc_error_from_response(scssc->response.code);
204}
205EXPORT_SYMBOL_GPL(chsc_sadc);
206
Peter Oberparleitere82a1562008-01-26 14:10:48 +0100207static int s390_subchannel_remove_chpid(struct subchannel *sch, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208{
Cornelia Huck2ec22982006-12-08 15:54:26 +0100209 spin_lock_irq(sch->lock);
Cornelia Huckc820de32008-07-14 09:58:45 +0200210 if (sch->driver && sch->driver->chp_event)
211 if (sch->driver->chp_event(sch, data, CHP_OFFLINE) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 goto out_unreg;
Cornelia Huck2ec22982006-12-08 15:54:26 +0100213 spin_unlock_irq(sch->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 return 0;
Stefan Bader387b7342007-04-27 16:01:33 +0200215
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216out_unreg:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 sch->lpm = 0;
Stefan Bader387b7342007-04-27 16:01:33 +0200218 spin_unlock_irq(sch->lock);
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200219 css_schedule_eval(sch->schid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 return 0;
221}
222
Peter Oberparleitere6b6e102007-04-27 16:01:28 +0200223void chsc_chp_offline(struct chp_id chpid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224{
225 char dbf_txt[15];
Cornelia Huck99611f82008-07-14 09:59:02 +0200226 struct chp_link link;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227
Peter Oberparleiterf86635f2007-04-27 16:01:26 +0200228 sprintf(dbf_txt, "chpr%x.%02x", chpid.cssid, chpid.id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 CIO_TRACE_EVENT(2, dbf_txt);
230
Peter Oberparleitere6b6e102007-04-27 16:01:28 +0200231 if (chp_get_status(chpid) <= 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 return;
Cornelia Huck99611f82008-07-14 09:59:02 +0200233 memset(&link, 0, sizeof(struct chp_link));
234 link.chpid = chpid;
Cornelia Huck22806dc2008-04-17 07:45:59 +0200235 /* Wait until previous actions have settled. */
236 css_wait_for_slow_path();
Cornelia Huck99611f82008-07-14 09:59:02 +0200237 for_each_subchannel_staged(s390_subchannel_remove_chpid, NULL, &link);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238}
239
Peter Oberparleitere82a1562008-01-26 14:10:48 +0100240static int __s390_process_res_acc(struct subchannel *sch, void *data)
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800241{
Cornelia Huck2ec22982006-12-08 15:54:26 +0100242 spin_lock_irq(sch->lock);
Cornelia Huckc820de32008-07-14 09:58:45 +0200243 if (sch->driver && sch->driver->chp_event)
244 sch->driver->chp_event(sch, data, CHP_ONLINE);
Cornelia Huck2ec22982006-12-08 15:54:26 +0100245 spin_unlock_irq(sch->lock);
Peter Oberparleitere82a1562008-01-26 14:10:48 +0100246
Peter Oberparleiterdd9963f2006-09-20 15:59:54 +0200247 return 0;
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800248}
249
Cornelia Huck99611f82008-07-14 09:59:02 +0200250static void s390_process_res_acc(struct chp_link *link)
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800251{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 char dbf_txt[15];
253
Cornelia Huck99611f82008-07-14 09:59:02 +0200254 sprintf(dbf_txt, "accpr%x.%02x", link->chpid.cssid,
255 link->chpid.id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 CIO_TRACE_EVENT( 2, dbf_txt);
Cornelia Huck99611f82008-07-14 09:59:02 +0200257 if (link->fla != 0) {
258 sprintf(dbf_txt, "fla%x", link->fla);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 CIO_TRACE_EVENT( 2, dbf_txt);
260 }
Cornelia Huck22806dc2008-04-17 07:45:59 +0200261 /* Wait until previous actions have settled. */
262 css_wait_for_slow_path();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 /*
264 * I/O resources may have become accessible.
265 * Scan through all subchannels that may be concerned and
266 * do a validation on those.
267 * The more information we have (info), the less scanning
268 * will we have to do.
269 */
Peter Oberparleiter449666d2013-11-26 14:55:56 +0100270 for_each_subchannel_staged(__s390_process_res_acc, NULL, link);
271 css_schedule_reprobe();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272}
273
274static int
275__get_chpid_from_lir(void *data)
276{
277 struct lir {
278 u8 iq;
279 u8 ic;
280 u16 sci;
281 /* incident-node descriptor */
282 u32 indesc[28];
283 /* attached-node descriptor */
284 u32 andesc[28];
285 /* incident-specific information */
286 u32 isinfo[28];
Peter Oberparleiter0f008aa2007-02-05 21:17:40 +0100287 } __attribute__ ((packed)) *lir;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288
Cornelia Huck12975ae2006-10-11 15:31:47 +0200289 lir = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 if (!(lir->iq&0x80))
291 /* NULL link incident record */
292 return -EINVAL;
293 if (!(lir->indesc[0]&0xc0000000))
294 /* node descriptor not valid */
295 return -EINVAL;
296 if (!(lir->indesc[0]&0x10000000))
297 /* don't handle device-type nodes - FIXME */
298 return -EINVAL;
299 /* Byte 3 contains the chpid. Could also be CTCA, but we don't care */
300
301 return (u16) (lir->indesc[0]&0x000000ff);
302}
303
Jan Glaubercbc0dd12012-11-29 14:34:48 +0100304struct chsc_sei_nt0_area {
305 u8 flags;
306 u8 vf; /* validity flags */
307 u8 rs; /* reporting source */
308 u8 cc; /* content code */
309 u16 fla; /* full link address */
310 u16 rsid; /* reporting source id */
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100311 u32 reserved1;
312 u32 reserved2;
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100313 /* ccdf has to be big enough for a link-incident record */
Jan Glaubercbc0dd12012-11-29 14:34:48 +0100314 u8 ccdf[PAGE_SIZE - 24 - 16]; /* content-code dependent field */
315} __packed;
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100316
Jan Glaubercbc0dd12012-11-29 14:34:48 +0100317struct chsc_sei_nt2_area {
318 u8 flags; /* p and v bit */
319 u8 reserved1;
320 u8 reserved2;
321 u8 cc; /* content code */
322 u32 reserved3[13];
323 u8 ccdf[PAGE_SIZE - 24 - 56]; /* content-code dependent field */
324} __packed;
325
Sebastian Ott509d97b2013-01-15 19:02:01 +0100326#define CHSC_SEI_NT0 (1ULL << 63)
Jan Glaubercbc0dd12012-11-29 14:34:48 +0100327#define CHSC_SEI_NT2 (1ULL << 61)
328
329struct chsc_sei {
330 struct chsc_header request;
331 u32 reserved1;
332 u64 ntsm; /* notification type mask */
333 struct chsc_header response;
Sebastian Ott509d97b2013-01-15 19:02:01 +0100334 u32 :24;
335 u8 nt;
Jan Glaubercbc0dd12012-11-29 14:34:48 +0100336 union {
337 struct chsc_sei_nt0_area nt0_area;
338 struct chsc_sei_nt2_area nt2_area;
339 u8 nt_area[PAGE_SIZE - 24];
340 } u;
341} __packed;
342
343static void chsc_process_sei_link_incident(struct chsc_sei_nt0_area *sei_area)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344{
Peter Oberparleiterf86635f2007-04-27 16:01:26 +0200345 struct chp_id chpid;
346 int id;
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100347
348 CIO_CRW_EVENT(4, "chsc: link incident (rs=%02x, rs_id=%04x)\n",
349 sei_area->rs, sei_area->rsid);
350 if (sei_area->rs != 4)
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200351 return;
Peter Oberparleiterf86635f2007-04-27 16:01:26 +0200352 id = __get_chpid_from_lir(sei_area->ccdf);
353 if (id < 0)
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100354 CIO_CRW_EVENT(4, "chsc: link incident - invalid LIR\n");
Peter Oberparleiterf86635f2007-04-27 16:01:26 +0200355 else {
356 chp_id_init(&chpid);
357 chpid.id = id;
Peter Oberparleitere6b6e102007-04-27 16:01:28 +0200358 chsc_chp_offline(chpid);
Peter Oberparleiterf86635f2007-04-27 16:01:26 +0200359 }
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100360}
361
Jan Glaubercbc0dd12012-11-29 14:34:48 +0100362static void chsc_process_sei_res_acc(struct chsc_sei_nt0_area *sei_area)
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100363{
Cornelia Huck99611f82008-07-14 09:59:02 +0200364 struct chp_link link;
Peter Oberparleiterf86635f2007-04-27 16:01:26 +0200365 struct chp_id chpid;
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100366 int status;
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100367
368 CIO_CRW_EVENT(4, "chsc: resource accessibility event (rs=%02x, "
369 "rs_id=%04x)\n", sei_area->rs, sei_area->rsid);
370 if (sei_area->rs != 4)
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200371 return;
Peter Oberparleiterf86635f2007-04-27 16:01:26 +0200372 chp_id_init(&chpid);
373 chpid.id = sei_area->rsid;
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100374 /* allocate a new channel path structure, if needed */
Peter Oberparleitere6b6e102007-04-27 16:01:28 +0200375 status = chp_get_status(chpid);
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100376 if (status < 0)
Peter Oberparleitere6b6e102007-04-27 16:01:28 +0200377 chp_new(chpid);
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100378 else if (!status)
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200379 return;
Cornelia Huck99611f82008-07-14 09:59:02 +0200380 memset(&link, 0, sizeof(struct chp_link));
381 link.chpid = chpid;
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100382 if ((sei_area->vf & 0xc0) != 0) {
Cornelia Huck99611f82008-07-14 09:59:02 +0200383 link.fla = sei_area->fla;
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100384 if ((sei_area->vf & 0xc0) == 0xc0)
385 /* full link address */
Cornelia Huck99611f82008-07-14 09:59:02 +0200386 link.fla_mask = 0xffff;
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100387 else
388 /* link address */
Cornelia Huck99611f82008-07-14 09:59:02 +0200389 link.fla_mask = 0xff00;
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100390 }
Cornelia Huck99611f82008-07-14 09:59:02 +0200391 s390_process_res_acc(&link);
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100392}
393
Jan Glaubercbc0dd12012-11-29 14:34:48 +0100394static void chsc_process_sei_chp_avail(struct chsc_sei_nt0_area *sei_area)
Sebastian Ottfca894ed2011-05-23 10:24:41 +0200395{
396 struct channel_path *chp;
397 struct chp_id chpid;
398 u8 *data;
399 int num;
400
401 CIO_CRW_EVENT(4, "chsc: channel path availability information\n");
402 if (sei_area->rs != 0)
403 return;
404 data = sei_area->ccdf;
405 chp_id_init(&chpid);
406 for (num = 0; num <= __MAX_CHPID; num++) {
407 if (!chp_test_bit(data, num))
408 continue;
409 chpid.id = num;
410
411 CIO_CRW_EVENT(4, "Update information for channel path "
412 "%x.%02x\n", chpid.cssid, chpid.id);
413 chp = chpid_to_chp(chpid);
414 if (!chp) {
415 chp_new(chpid);
416 continue;
417 }
418 mutex_lock(&chp->lock);
Peter Oberparleitercce0eac2013-03-11 12:58:18 +0100419 chp_update_desc(chp);
Sebastian Ottfca894ed2011-05-23 10:24:41 +0200420 mutex_unlock(&chp->lock);
421 }
422}
423
Peter Oberparleitere5854a52007-04-27 16:01:31 +0200424struct chp_config_data {
425 u8 map[32];
426 u8 op;
427 u8 pc;
428};
429
Jan Glaubercbc0dd12012-11-29 14:34:48 +0100430static void chsc_process_sei_chp_config(struct chsc_sei_nt0_area *sei_area)
Peter Oberparleitere5854a52007-04-27 16:01:31 +0200431{
432 struct chp_config_data *data;
433 struct chp_id chpid;
434 int num;
Michael Ernste6d5a422008-12-25 13:39:36 +0100435 char *events[3] = {"configure", "deconfigure", "cancel deconfigure"};
Peter Oberparleitere5854a52007-04-27 16:01:31 +0200436
437 CIO_CRW_EVENT(4, "chsc: channel-path-configuration notification\n");
438 if (sei_area->rs != 0)
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200439 return;
Peter Oberparleitere5854a52007-04-27 16:01:31 +0200440 data = (struct chp_config_data *) &(sei_area->ccdf);
441 chp_id_init(&chpid);
442 for (num = 0; num <= __MAX_CHPID; num++) {
443 if (!chp_test_bit(data->map, num))
444 continue;
445 chpid.id = num;
Michael Ernste6d5a422008-12-25 13:39:36 +0100446 pr_notice("Processing %s for channel path %x.%02x\n",
447 events[data->op], chpid.cssid, chpid.id);
Peter Oberparleitere5854a52007-04-27 16:01:31 +0200448 switch (data->op) {
449 case 0:
450 chp_cfg_schedule(chpid, 1);
451 break;
452 case 1:
453 chp_cfg_schedule(chpid, 0);
454 break;
455 case 2:
456 chp_cfg_cancel_deconfigure(chpid);
457 break;
458 }
459 }
Peter Oberparleitere5854a52007-04-27 16:01:31 +0200460}
461
Jan Glaubercbc0dd12012-11-29 14:34:48 +0100462static void chsc_process_sei_scm_change(struct chsc_sei_nt0_area *sei_area)
Sebastian Ott40ff4cc2012-08-28 16:47:02 +0200463{
464 int ret;
465
466 CIO_CRW_EVENT(4, "chsc: scm change notification\n");
467 if (sei_area->rs != 7)
468 return;
469
470 ret = scm_update_information();
471 if (ret)
472 CIO_CRW_EVENT(0, "chsc: updating change notification"
473 " failed (rc=%d).\n", ret);
474}
475
Sebastian Ottaebfa662013-02-28 12:07:55 +0100476static void chsc_process_sei_scm_avail(struct chsc_sei_nt0_area *sei_area)
477{
478 int ret;
479
480 CIO_CRW_EVENT(4, "chsc: scm available information\n");
481 if (sei_area->rs != 7)
482 return;
483
484 ret = scm_process_availability_information();
485 if (ret)
486 CIO_CRW_EVENT(0, "chsc: process availability information"
487 " failed (rc=%d).\n", ret);
488}
489
Jan Glaubercbc0dd12012-11-29 14:34:48 +0100490static void chsc_process_sei_nt2(struct chsc_sei_nt2_area *sei_area)
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100491{
Jan Glaubercbc0dd12012-11-29 14:34:48 +0100492 switch (sei_area->cc) {
493 case 1:
494 zpci_event_error(sei_area->ccdf);
495 break;
496 case 2:
497 zpci_event_availability(sei_area->ccdf);
498 break;
499 default:
Sebastian Ott9a17e972013-01-15 19:04:39 +0100500 CIO_CRW_EVENT(2, "chsc: sei nt2 unhandled cc=%d\n",
Jan Glaubercbc0dd12012-11-29 14:34:48 +0100501 sei_area->cc);
502 break;
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200503 }
Jan Glaubercbc0dd12012-11-29 14:34:48 +0100504}
505
506static void chsc_process_sei_nt0(struct chsc_sei_nt0_area *sei_area)
507{
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100508 /* which kind of information was stored? */
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100509 switch (sei_area->cc) {
510 case 1: /* link incident*/
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200511 chsc_process_sei_link_incident(sei_area);
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100512 break;
Sebastian Ottfca894ed2011-05-23 10:24:41 +0200513 case 2: /* i/o resource accessibility */
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200514 chsc_process_sei_res_acc(sei_area);
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100515 break;
Sebastian Ottfca894ed2011-05-23 10:24:41 +0200516 case 7: /* channel-path-availability information */
517 chsc_process_sei_chp_avail(sei_area);
518 break;
Peter Oberparleitere5854a52007-04-27 16:01:31 +0200519 case 8: /* channel-path-configuration notification */
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200520 chsc_process_sei_chp_config(sei_area);
Peter Oberparleitere5854a52007-04-27 16:01:31 +0200521 break;
Sebastian Ott40ff4cc2012-08-28 16:47:02 +0200522 case 12: /* scm change notification */
523 chsc_process_sei_scm_change(sei_area);
524 break;
Sebastian Ottaebfa662013-02-28 12:07:55 +0100525 case 14: /* scm available notification */
526 chsc_process_sei_scm_avail(sei_area);
527 break;
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100528 default: /* other stuff */
Sebastian Ott9a17e972013-01-15 19:04:39 +0100529 CIO_CRW_EVENT(2, "chsc: sei nt0 unhandled cc=%d\n",
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100530 sei_area->cc);
531 break;
532 }
Sebastian Ott9a17e972013-01-15 19:04:39 +0100533
534 /* Check if we might have lost some information. */
535 if (sei_area->flags & 0x40) {
536 CIO_CRW_EVENT(2, "chsc: event overflow\n");
537 css_schedule_eval_all();
538 }
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100539}
540
Sebastian Ott9a17e972013-01-15 19:04:39 +0100541static void chsc_process_event_information(struct chsc_sei *sei, u64 ntsm)
Jan Glaubercbc0dd12012-11-29 14:34:48 +0100542{
543 do {
544 memset(sei, 0, sizeof(*sei));
545 sei->request.length = 0x0010;
546 sei->request.code = 0x000e;
547 sei->ntsm = ntsm;
548
549 if (chsc(sei))
550 break;
551
Sebastian Ott9a17e972013-01-15 19:04:39 +0100552 if (sei->response.code != 0x0001) {
Jan Glaubercbc0dd12012-11-29 14:34:48 +0100553 CIO_CRW_EVENT(2, "chsc: sei failed (rc=%04x)\n",
554 sei->response.code);
555 break;
556 }
Jan Glaubercbc0dd12012-11-29 14:34:48 +0100557
Sebastian Ott9a17e972013-01-15 19:04:39 +0100558 CIO_CRW_EVENT(2, "chsc: sei successful (nt=%d)\n", sei->nt);
559 switch (sei->nt) {
560 case 0:
561 chsc_process_sei_nt0(&sei->u.nt0_area);
562 break;
563 case 2:
564 chsc_process_sei_nt2(&sei->u.nt2_area);
565 break;
566 default:
567 CIO_CRW_EVENT(2, "chsc: unhandled nt: %d\n", sei->nt);
568 break;
569 }
570 } while (sei->u.nt0_area.flags & 0x80);
Jan Glaubercbc0dd12012-11-29 14:34:48 +0100571}
572
Sebastian Ott9a17e972013-01-15 19:04:39 +0100573/*
574 * Handle channel subsystem related CRWs.
575 * Use store event information to find out what's going on.
576 *
577 * Note: Access to sei_page is serialized through machine check handler
578 * thread, so no need for locking.
579 */
Cornelia Huckc1156182008-07-14 09:58:46 +0200580static void chsc_process_crw(struct crw *crw0, struct crw *crw1, int overflow)
Peter Oberparleiter184357a2007-02-05 21:17:42 +0100581{
Sebastian Ott9a17e972013-01-15 19:04:39 +0100582 struct chsc_sei *sei = sei_page;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583
Cornelia Huckc1156182008-07-14 09:58:46 +0200584 if (overflow) {
585 css_schedule_eval_all();
586 return;
587 }
588 CIO_CRW_EVENT(2, "CRW reports slct=%d, oflw=%d, "
589 "chn=%d, rsc=%X, anc=%d, erc=%X, rsid=%X\n",
590 crw0->slct, crw0->oflw, crw0->chn, crw0->rsc, crw0->anc,
591 crw0->erc, crw0->rsid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592
Cornelia Huckc1156182008-07-14 09:58:46 +0200593 CIO_TRACE_EVENT(2, "prcss");
Sebastian Ott9a17e972013-01-15 19:04:39 +0100594 chsc_process_event_information(sei, CHSC_SEI_NT0 | CHSC_SEI_NT2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595}
596
Peter Oberparleiter83b33702007-04-27 16:01:34 +0200597void chsc_chp_online(struct chp_id chpid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 char dbf_txt[15];
Cornelia Huck99611f82008-07-14 09:59:02 +0200600 struct chp_link link;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601
Peter Oberparleiterf86635f2007-04-27 16:01:26 +0200602 sprintf(dbf_txt, "cadd%x.%02x", chpid.cssid, chpid.id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 CIO_TRACE_EVENT(2, dbf_txt);
604
Cornelia Huck22806dc2008-04-17 07:45:59 +0200605 if (chp_get_status(chpid) != 0) {
Cornelia Huck99611f82008-07-14 09:59:02 +0200606 memset(&link, 0, sizeof(struct chp_link));
607 link.chpid = chpid;
Cornelia Huck22806dc2008-04-17 07:45:59 +0200608 /* Wait until previous actions have settled. */
609 css_wait_for_slow_path();
Cornelia Huckc820de32008-07-14 09:58:45 +0200610 for_each_subchannel_staged(__s390_process_res_acc, NULL,
Cornelia Huck99611f82008-07-14 09:59:02 +0200611 &link);
Cornelia Huck22806dc2008-04-17 07:45:59 +0200612 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613}
614
Peter Oberparleiterf86635f2007-04-27 16:01:26 +0200615static void __s390_subchannel_vary_chpid(struct subchannel *sch,
616 struct chp_id chpid, int on)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 unsigned long flags;
Cornelia Huck99611f82008-07-14 09:59:02 +0200619 struct chp_link link;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620
Cornelia Huck99611f82008-07-14 09:59:02 +0200621 memset(&link, 0, sizeof(struct chp_link));
622 link.chpid = chpid;
Cornelia Huck2ec22982006-12-08 15:54:26 +0100623 spin_lock_irqsave(sch->lock, flags);
Cornelia Huckc820de32008-07-14 09:58:45 +0200624 if (sch->driver && sch->driver->chp_event)
Cornelia Huck99611f82008-07-14 09:59:02 +0200625 sch->driver->chp_event(sch, &link,
Cornelia Huckc820de32008-07-14 09:58:45 +0200626 on ? CHP_VARY_ON : CHP_VARY_OFF);
Cornelia Huck2ec22982006-12-08 15:54:26 +0100627 spin_unlock_irqrestore(sch->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628}
629
Peter Oberparleitere82a1562008-01-26 14:10:48 +0100630static int s390_subchannel_vary_chpid_off(struct subchannel *sch, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631{
Peter Oberparleitere82a1562008-01-26 14:10:48 +0100632 struct chp_id *chpid = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633
634 __s390_subchannel_vary_chpid(sch, *chpid, 0);
635 return 0;
636}
637
Peter Oberparleitere82a1562008-01-26 14:10:48 +0100638static int s390_subchannel_vary_chpid_on(struct subchannel *sch, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639{
Peter Oberparleitere82a1562008-01-26 14:10:48 +0100640 struct chp_id *chpid = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641
642 __s390_subchannel_vary_chpid(sch, *chpid, 1);
643 return 0;
644}
645
Peter Oberparleitere6b6e102007-04-27 16:01:28 +0200646/**
647 * chsc_chp_vary - propagate channel-path vary operation to subchannels
648 * @chpid: channl-path ID
649 * @on: non-zero for vary online, zero for vary offline
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650 */
Peter Oberparleitere6b6e102007-04-27 16:01:28 +0200651int chsc_chp_vary(struct chp_id chpid, int on)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652{
Sebastian Ottc38a90a2010-10-25 16:10:31 +0200653 struct channel_path *chp = chpid_to_chp(chpid);
Cornelia Huck99611f82008-07-14 09:59:02 +0200654
Cornelia Huck22806dc2008-04-17 07:45:59 +0200655 /* Wait until previous actions have settled. */
656 css_wait_for_slow_path();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 /*
658 * Redo PathVerification on the devices the chpid connects to
659 */
Sebastian Ottc38a90a2010-10-25 16:10:31 +0200660 if (on) {
Peter Oberparleitercce0eac2013-03-11 12:58:18 +0100661 /* Try to update the channel path description. */
662 chp_update_desc(chp);
Peter Oberparleitere82a1562008-01-26 14:10:48 +0100663 for_each_subchannel_staged(s390_subchannel_vary_chpid_on,
Peter Oberparleiter449666d2013-11-26 14:55:56 +0100664 NULL, &chpid);
665 css_schedule_reprobe();
Sebastian Ottc38a90a2010-10-25 16:10:31 +0200666 } else
Peter Oberparleitere82a1562008-01-26 14:10:48 +0100667 for_each_subchannel_staged(s390_subchannel_vary_chpid_off,
Sebastian Ott3b484ec2011-12-01 13:32:22 +0100668 NULL, &chpid);
Peter Oberparleitere82a1562008-01-26 14:10:48 +0100669
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 return 0;
671}
672
Cornelia Huck495a5b42006-03-24 03:15:14 -0800673static void
674chsc_remove_cmg_attr(struct channel_subsystem *css)
675{
676 int i;
677
678 for (i = 0; i <= __MAX_CHPID; i++) {
679 if (!css->chps[i])
680 continue;
Peter Oberparleitere6b6e102007-04-27 16:01:28 +0200681 chp_remove_cmg_attr(css->chps[i]);
Cornelia Huck495a5b42006-03-24 03:15:14 -0800682 }
683}
684
685static int
686chsc_add_cmg_attr(struct channel_subsystem *css)
687{
688 int i, ret;
689
690 ret = 0;
691 for (i = 0; i <= __MAX_CHPID; i++) {
692 if (!css->chps[i])
693 continue;
Peter Oberparleitere6b6e102007-04-27 16:01:28 +0200694 ret = chp_add_cmg_attr(css->chps[i]);
Cornelia Huck495a5b42006-03-24 03:15:14 -0800695 if (ret)
696 goto cleanup;
697 }
698 return ret;
699cleanup:
700 for (--i; i >= 0; i--) {
701 if (!css->chps[i])
702 continue;
Peter Oberparleitere6b6e102007-04-27 16:01:28 +0200703 chp_remove_cmg_attr(css->chps[i]);
Cornelia Huck495a5b42006-03-24 03:15:14 -0800704 }
705 return ret;
706}
707
Sebastian Ott34196f82010-10-25 16:10:29 +0200708int __chsc_do_secm(struct channel_subsystem *css, int enable)
Cornelia Huck495a5b42006-03-24 03:15:14 -0800709{
710 struct {
711 struct chsc_header request;
712 u32 operation_code : 2;
713 u32 : 30;
714 u32 key : 4;
715 u32 : 28;
716 u32 zeroes1;
717 u32 cub_addr1;
718 u32 zeroes2;
719 u32 cub_addr2;
720 u32 reserved[13];
721 struct chsc_header response;
722 u32 status : 8;
723 u32 : 4;
724 u32 fmt : 4;
725 u32 : 16;
Peter Oberparleiter0f008aa2007-02-05 21:17:40 +0100726 } __attribute__ ((packed)) *secm_area;
Cornelia Huck495a5b42006-03-24 03:15:14 -0800727 int ret, ccode;
728
Sebastian Ott34196f82010-10-25 16:10:29 +0200729 spin_lock_irq(&chsc_page_lock);
730 memset(chsc_page, 0, PAGE_SIZE);
731 secm_area = chsc_page;
Cornelia Huck495a5b42006-03-24 03:15:14 -0800732 secm_area->request.length = 0x0050;
733 secm_area->request.code = 0x0016;
734
Heiko Carstensd1bf8592010-02-26 22:37:30 +0100735 secm_area->key = PAGE_DEFAULT_KEY >> 4;
Cornelia Huck495a5b42006-03-24 03:15:14 -0800736 secm_area->cub_addr1 = (u64)(unsigned long)css->cub_addr1;
737 secm_area->cub_addr2 = (u64)(unsigned long)css->cub_addr2;
738
739 secm_area->operation_code = enable ? 0 : 1;
740
741 ccode = chsc(secm_area);
Sebastian Ott34196f82010-10-25 16:10:29 +0200742 if (ccode > 0) {
743 ret = (ccode == 3) ? -ENODEV : -EBUSY;
744 goto out;
745 }
Cornelia Huck495a5b42006-03-24 03:15:14 -0800746
747 switch (secm_area->response.code) {
Cornelia Huckb9c9a212008-02-05 16:50:34 +0100748 case 0x0102:
749 case 0x0103:
Cornelia Huck495a5b42006-03-24 03:15:14 -0800750 ret = -EINVAL;
Sebastian Ott17e7d872009-03-26 15:24:17 +0100751 break;
Cornelia Huck495a5b42006-03-24 03:15:14 -0800752 default:
Cornelia Huckb9c9a212008-02-05 16:50:34 +0100753 ret = chsc_error_from_response(secm_area->response.code);
Cornelia Huck495a5b42006-03-24 03:15:14 -0800754 }
Cornelia Huckb9c9a212008-02-05 16:50:34 +0100755 if (ret != 0)
756 CIO_CRW_EVENT(2, "chsc: secm failed (rc=%04x)\n",
757 secm_area->response.code);
Sebastian Ott34196f82010-10-25 16:10:29 +0200758out:
759 spin_unlock_irq(&chsc_page_lock);
Cornelia Huck495a5b42006-03-24 03:15:14 -0800760 return ret;
761}
762
763int
764chsc_secm(struct channel_subsystem *css, int enable)
765{
Cornelia Huck495a5b42006-03-24 03:15:14 -0800766 int ret;
767
Cornelia Huck495a5b42006-03-24 03:15:14 -0800768 if (enable && !css->cm_enabled) {
769 css->cub_addr1 = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
770 css->cub_addr2 = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
771 if (!css->cub_addr1 || !css->cub_addr2) {
772 free_page((unsigned long)css->cub_addr1);
773 free_page((unsigned long)css->cub_addr2);
Cornelia Huck495a5b42006-03-24 03:15:14 -0800774 return -ENOMEM;
775 }
776 }
Sebastian Ott34196f82010-10-25 16:10:29 +0200777 ret = __chsc_do_secm(css, enable);
Cornelia Huck495a5b42006-03-24 03:15:14 -0800778 if (!ret) {
779 css->cm_enabled = enable;
780 if (css->cm_enabled) {
781 ret = chsc_add_cmg_attr(css);
782 if (ret) {
Sebastian Ott34196f82010-10-25 16:10:29 +0200783 __chsc_do_secm(css, 0);
Cornelia Huck495a5b42006-03-24 03:15:14 -0800784 css->cm_enabled = 0;
785 }
786 } else
787 chsc_remove_cmg_attr(css);
788 }
Cornelia Huck8c4941c2007-04-27 16:01:38 +0200789 if (!css->cm_enabled) {
Cornelia Huck495a5b42006-03-24 03:15:14 -0800790 free_page((unsigned long)css->cub_addr1);
791 free_page((unsigned long)css->cub_addr2);
792 }
Cornelia Huck495a5b42006-03-24 03:15:14 -0800793 return ret;
794}
795
Cornelia Huck9d92a7e2008-07-14 09:59:05 +0200796int chsc_determine_channel_path_desc(struct chp_id chpid, int fmt, int rfmt,
Sebastian Ott906c9762010-10-25 16:10:30 +0200797 int c, int m, void *page)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798{
Sebastian Ott906c9762010-10-25 16:10:30 +0200799 struct chsc_scpd *scpd_area;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800 int ccode, ret;
801
Cornelia Huck9d92a7e2008-07-14 09:59:05 +0200802 if ((rfmt == 1) && !css_general_characteristics.fcs)
803 return -EINVAL;
804 if ((rfmt == 2) && !css_general_characteristics.cib)
805 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806
Sebastian Ott906c9762010-10-25 16:10:30 +0200807 memset(page, 0, PAGE_SIZE);
808 scpd_area = page;
Cornelia Huck495a5b42006-03-24 03:15:14 -0800809 scpd_area->request.length = 0x0010;
810 scpd_area->request.code = 0x0002;
Cornelia Huck9d92a7e2008-07-14 09:59:05 +0200811 scpd_area->cssid = chpid.cssid;
Peter Oberparleiterf86635f2007-04-27 16:01:26 +0200812 scpd_area->first_chpid = chpid.id;
813 scpd_area->last_chpid = chpid.id;
Cornelia Huck9d92a7e2008-07-14 09:59:05 +0200814 scpd_area->m = m;
815 scpd_area->c = c;
816 scpd_area->fmt = fmt;
817 scpd_area->rfmt = rfmt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818
819 ccode = chsc(scpd_area);
Sebastian Ott906c9762010-10-25 16:10:30 +0200820 if (ccode > 0)
821 return (ccode == 3) ? -ENODEV : -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822
Cornelia Huckb9c9a212008-02-05 16:50:34 +0100823 ret = chsc_error_from_response(scpd_area->response.code);
Sebastian Ott906c9762010-10-25 16:10:30 +0200824 if (ret)
Cornelia Huckb9c9a212008-02-05 16:50:34 +0100825 CIO_CRW_EVENT(2, "chsc: scpd failed (rc=%04x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826 scpd_area->response.code);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827 return ret;
828}
Cornelia Huck9d92a7e2008-07-14 09:59:05 +0200829EXPORT_SYMBOL_GPL(chsc_determine_channel_path_desc);
830
831int chsc_determine_base_channel_path_desc(struct chp_id chpid,
832 struct channel_path_desc *desc)
833{
834 struct chsc_response_struct *chsc_resp;
Sebastian Ott906c9762010-10-25 16:10:30 +0200835 struct chsc_scpd *scpd_area;
Sebastian Ott62da1772010-10-25 16:10:32 +0200836 unsigned long flags;
Cornelia Huck9d92a7e2008-07-14 09:59:05 +0200837 int ret;
838
Sebastian Ott62da1772010-10-25 16:10:32 +0200839 spin_lock_irqsave(&chsc_page_lock, flags);
Sebastian Ott906c9762010-10-25 16:10:30 +0200840 scpd_area = chsc_page;
841 ret = chsc_determine_channel_path_desc(chpid, 0, 0, 0, 0, scpd_area);
Cornelia Huck9d92a7e2008-07-14 09:59:05 +0200842 if (ret)
Sebastian Ott906c9762010-10-25 16:10:30 +0200843 goto out;
844 chsc_resp = (void *)&scpd_area->response;
Sebastian Ott878c4952010-07-19 09:22:37 +0200845 memcpy(desc, &chsc_resp->data, sizeof(*desc));
Sebastian Ott906c9762010-10-25 16:10:30 +0200846out:
Sebastian Ott62da1772010-10-25 16:10:32 +0200847 spin_unlock_irqrestore(&chsc_page_lock, flags);
Cornelia Huck9d92a7e2008-07-14 09:59:05 +0200848 return ret;
849}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850
Sebastian Ottce322cc2011-01-05 12:47:56 +0100851int chsc_determine_fmt1_channel_path_desc(struct chp_id chpid,
852 struct channel_path_desc_fmt1 *desc)
853{
854 struct chsc_response_struct *chsc_resp;
855 struct chsc_scpd *scpd_area;
Peter Oberparleitercce0eac2013-03-11 12:58:18 +0100856 unsigned long flags;
Sebastian Ottce322cc2011-01-05 12:47:56 +0100857 int ret;
858
Peter Oberparleitercce0eac2013-03-11 12:58:18 +0100859 spin_lock_irqsave(&chsc_page_lock, flags);
Sebastian Ottce322cc2011-01-05 12:47:56 +0100860 scpd_area = chsc_page;
861 ret = chsc_determine_channel_path_desc(chpid, 0, 0, 1, 0, scpd_area);
862 if (ret)
863 goto out;
864 chsc_resp = (void *)&scpd_area->response;
865 memcpy(desc, &chsc_resp->data, sizeof(*desc));
866out:
Peter Oberparleitercce0eac2013-03-11 12:58:18 +0100867 spin_unlock_irqrestore(&chsc_page_lock, flags);
Sebastian Ottce322cc2011-01-05 12:47:56 +0100868 return ret;
869}
870
Cornelia Huck495a5b42006-03-24 03:15:14 -0800871static void
872chsc_initialize_cmg_chars(struct channel_path *chp, u8 cmcv,
873 struct cmg_chars *chars)
874{
Sebastian Ott34196f82010-10-25 16:10:29 +0200875 struct cmg_chars *cmg_chars;
876 int i, mask;
Cornelia Huck495a5b42006-03-24 03:15:14 -0800877
Sebastian Ott34196f82010-10-25 16:10:29 +0200878 cmg_chars = chp->cmg_chars;
879 for (i = 0; i < NR_MEASUREMENT_CHARS; i++) {
880 mask = 0x80 >> (i + 3);
881 if (cmcv & mask)
882 cmg_chars->values[i] = chars->values[i];
883 else
884 cmg_chars->values[i] = 0;
Cornelia Huck495a5b42006-03-24 03:15:14 -0800885 }
886}
887
Peter Oberparleitere6b6e102007-04-27 16:01:28 +0200888int chsc_get_channel_measurement_chars(struct channel_path *chp)
Cornelia Huck495a5b42006-03-24 03:15:14 -0800889{
Sebastian Ott34196f82010-10-25 16:10:29 +0200890 struct cmg_chars *cmg_chars;
Cornelia Huck495a5b42006-03-24 03:15:14 -0800891 int ccode, ret;
892
893 struct {
894 struct chsc_header request;
895 u32 : 24;
896 u32 first_chpid : 8;
897 u32 : 24;
898 u32 last_chpid : 8;
899 u32 zeroes1;
900 struct chsc_header response;
901 u32 zeroes2;
902 u32 not_valid : 1;
903 u32 shared : 1;
904 u32 : 22;
905 u32 chpid : 8;
906 u32 cmcv : 5;
907 u32 : 11;
908 u32 cmgq : 8;
909 u32 cmg : 8;
910 u32 zeroes3;
911 u32 data[NR_MEASUREMENT_CHARS];
Peter Oberparleiter0f008aa2007-02-05 21:17:40 +0100912 } __attribute__ ((packed)) *scmc_area;
Cornelia Huck495a5b42006-03-24 03:15:14 -0800913
Sebastian Ott34196f82010-10-25 16:10:29 +0200914 chp->cmg_chars = NULL;
915 cmg_chars = kmalloc(sizeof(*cmg_chars), GFP_KERNEL);
916 if (!cmg_chars)
Cornelia Huck495a5b42006-03-24 03:15:14 -0800917 return -ENOMEM;
918
Sebastian Ott34196f82010-10-25 16:10:29 +0200919 spin_lock_irq(&chsc_page_lock);
920 memset(chsc_page, 0, PAGE_SIZE);
921 scmc_area = chsc_page;
Cornelia Huck495a5b42006-03-24 03:15:14 -0800922 scmc_area->request.length = 0x0010;
923 scmc_area->request.code = 0x0022;
Peter Oberparleiterf86635f2007-04-27 16:01:26 +0200924 scmc_area->first_chpid = chp->chpid.id;
925 scmc_area->last_chpid = chp->chpid.id;
Cornelia Huck495a5b42006-03-24 03:15:14 -0800926
927 ccode = chsc(scmc_area);
928 if (ccode > 0) {
929 ret = (ccode == 3) ? -ENODEV : -EBUSY;
930 goto out;
931 }
932
Cornelia Huckb9c9a212008-02-05 16:50:34 +0100933 ret = chsc_error_from_response(scmc_area->response.code);
Sebastian Ott34196f82010-10-25 16:10:29 +0200934 if (ret) {
Cornelia Huckb9c9a212008-02-05 16:50:34 +0100935 CIO_CRW_EVENT(2, "chsc: scmc failed (rc=%04x)\n",
Cornelia Huck495a5b42006-03-24 03:15:14 -0800936 scmc_area->response.code);
Sebastian Ott34196f82010-10-25 16:10:29 +0200937 goto out;
Cornelia Huck495a5b42006-03-24 03:15:14 -0800938 }
Sebastian Ott34196f82010-10-25 16:10:29 +0200939 if (scmc_area->not_valid) {
940 chp->cmg = -1;
941 chp->shared = -1;
942 goto out;
943 }
944 chp->cmg = scmc_area->cmg;
945 chp->shared = scmc_area->shared;
946 if (chp->cmg != 2 && chp->cmg != 3) {
947 /* No cmg-dependent data. */
948 goto out;
949 }
950 chp->cmg_chars = cmg_chars;
951 chsc_initialize_cmg_chars(chp, scmc_area->cmcv,
952 (struct cmg_chars *) &scmc_area->data);
Cornelia Huck495a5b42006-03-24 03:15:14 -0800953out:
Sebastian Ott34196f82010-10-25 16:10:29 +0200954 spin_unlock_irq(&chsc_page_lock);
955 if (!chp->cmg_chars)
956 kfree(cmg_chars);
957
Cornelia Huck495a5b42006-03-24 03:15:14 -0800958 return ret;
959}
960
Sebastian Ott34aec072010-10-25 16:10:28 +0200961int __init chsc_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962{
Cornelia Huckc1156182008-07-14 09:58:46 +0200963 int ret;
964
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965 sei_page = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
Sebastian Ott34196f82010-10-25 16:10:29 +0200966 chsc_page = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
967 if (!sei_page || !chsc_page) {
968 ret = -ENOMEM;
969 goto out_err;
Cornelia Huckc1156182008-07-14 09:58:46 +0200970 }
Heiko Carstensf5daba12009-03-26 15:24:01 +0100971 ret = crw_register_handler(CRW_RSC_CSS, chsc_process_crw);
Cornelia Huckc1156182008-07-14 09:58:46 +0200972 if (ret)
Sebastian Ott34196f82010-10-25 16:10:29 +0200973 goto out_err;
974 return ret;
975out_err:
976 free_page((unsigned long)chsc_page);
977 free_page((unsigned long)sei_page);
Cornelia Huckc1156182008-07-14 09:58:46 +0200978 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979}
980
Sebastian Ott34aec072010-10-25 16:10:28 +0200981void __init chsc_init_cleanup(void)
Cornelia Huck4434a382007-07-27 12:29:21 +0200982{
Heiko Carstensf5daba12009-03-26 15:24:01 +0100983 crw_unregister_handler(CRW_RSC_CSS);
Sebastian Ott34196f82010-10-25 16:10:29 +0200984 free_page((unsigned long)chsc_page);
Sebastian Ott34aec072010-10-25 16:10:28 +0200985 free_page((unsigned long)sei_page);
Cornelia Huck4434a382007-07-27 12:29:21 +0200986}
987
Sebastian Ott818c2722010-04-22 17:17:03 +0200988int chsc_enable_facility(int operation_code)
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800989{
Sebastian Ott34196f82010-10-25 16:10:29 +0200990 unsigned long flags;
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800991 int ret;
Sebastian Ott34196f82010-10-25 16:10:29 +0200992 struct {
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800993 struct chsc_header request;
994 u8 reserved1:4;
995 u8 format:4;
996 u8 reserved2;
997 u16 operation_code;
998 u32 reserved3;
999 u32 reserved4;
1000 u32 operation_data_area[252];
1001 struct chsc_header response;
1002 u32 reserved5:4;
1003 u32 format2:4;
1004 u32 reserved6:24;
Sebastian Ott34196f82010-10-25 16:10:29 +02001005 } __attribute__ ((packed)) *sda_area;
Cornelia Huckfb6958a2006-01-06 00:19:25 -08001006
Sebastian Ott34196f82010-10-25 16:10:29 +02001007 spin_lock_irqsave(&chsc_page_lock, flags);
1008 memset(chsc_page, 0, PAGE_SIZE);
1009 sda_area = chsc_page;
1010 sda_area->request.length = 0x0400;
1011 sda_area->request.code = 0x0031;
1012 sda_area->operation_code = operation_code;
Cornelia Huckfb6958a2006-01-06 00:19:25 -08001013
Sebastian Ott34196f82010-10-25 16:10:29 +02001014 ret = chsc(sda_area);
Cornelia Huckfb6958a2006-01-06 00:19:25 -08001015 if (ret > 0) {
1016 ret = (ret == 3) ? -ENODEV : -EBUSY;
1017 goto out;
1018 }
Cornelia Huckb9c9a212008-02-05 16:50:34 +01001019
Sebastian Ott34196f82010-10-25 16:10:29 +02001020 switch (sda_area->response.code) {
Cornelia Huckb9c9a212008-02-05 16:50:34 +01001021 case 0x0101:
Cornelia Huckfb6958a2006-01-06 00:19:25 -08001022 ret = -EOPNOTSUPP;
1023 break;
Cornelia Huckb9c9a212008-02-05 16:50:34 +01001024 default:
Sebastian Ott34196f82010-10-25 16:10:29 +02001025 ret = chsc_error_from_response(sda_area->response.code);
Cornelia Huckfb6958a2006-01-06 00:19:25 -08001026 }
Cornelia Huckb9c9a212008-02-05 16:50:34 +01001027 if (ret != 0)
1028 CIO_CRW_EVENT(2, "chsc: sda (oc=%x) failed (rc=%04x)\n",
Sebastian Ott34196f82010-10-25 16:10:29 +02001029 operation_code, sda_area->response.code);
1030out:
1031 spin_unlock_irqrestore(&chsc_page_lock, flags);
Cornelia Huckfb6958a2006-01-06 00:19:25 -08001032 return ret;
1033}
1034
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035struct css_general_char css_general_characteristics;
1036struct css_chsc_char css_chsc_characteristics;
1037
1038int __init
1039chsc_determine_css_characteristics(void)
1040{
1041 int result;
1042 struct {
1043 struct chsc_header request;
1044 u32 reserved1;
1045 u32 reserved2;
1046 u32 reserved3;
1047 struct chsc_header response;
1048 u32 reserved4;
1049 u32 general_char[510];
Sebastian Ott34aec072010-10-25 16:10:28 +02001050 u32 chsc_char[508];
Peter Oberparleiter0f008aa2007-02-05 21:17:40 +01001051 } __attribute__ ((packed)) *scsc_area;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052
Sebastian Ott34196f82010-10-25 16:10:29 +02001053 spin_lock_irq(&chsc_page_lock);
1054 memset(chsc_page, 0, PAGE_SIZE);
1055 scsc_area = chsc_page;
Cornelia Huck495a5b42006-03-24 03:15:14 -08001056 scsc_area->request.length = 0x0010;
1057 scsc_area->request.code = 0x0010;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058
1059 result = chsc(scsc_area);
1060 if (result) {
Cornelia Huckb9c9a212008-02-05 16:50:34 +01001061 result = (result == 3) ? -ENODEV : -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062 goto exit;
1063 }
1064
Cornelia Huckb9c9a212008-02-05 16:50:34 +01001065 result = chsc_error_from_response(scsc_area->response.code);
1066 if (result == 0) {
1067 memcpy(&css_general_characteristics, scsc_area->general_char,
1068 sizeof(css_general_characteristics));
1069 memcpy(&css_chsc_characteristics, scsc_area->chsc_char,
1070 sizeof(css_chsc_characteristics));
1071 } else
1072 CIO_CRW_EVENT(2, "chsc: scsc failed (rc=%04x)\n",
1073 scsc_area->response.code);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074exit:
Sebastian Ott34196f82010-10-25 16:10:29 +02001075 spin_unlock_irq(&chsc_page_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076 return result;
1077}
1078
1079EXPORT_SYMBOL_GPL(css_general_characteristics);
1080EXPORT_SYMBOL_GPL(css_chsc_characteristics);
Martin Schwidefskyd2fec592008-07-14 09:58:56 +02001081
1082int chsc_sstpc(void *page, unsigned int op, u16 ctrl)
1083{
1084 struct {
1085 struct chsc_header request;
1086 unsigned int rsvd0;
1087 unsigned int op : 8;
1088 unsigned int rsvd1 : 8;
1089 unsigned int ctrl : 16;
1090 unsigned int rsvd2[5];
1091 struct chsc_header response;
1092 unsigned int rsvd3[7];
1093 } __attribute__ ((packed)) *rr;
1094 int rc;
1095
1096 memset(page, 0, PAGE_SIZE);
1097 rr = page;
1098 rr->request.length = 0x0020;
1099 rr->request.code = 0x0033;
1100 rr->op = op;
1101 rr->ctrl = ctrl;
1102 rc = chsc(rr);
1103 if (rc)
1104 return -EIO;
1105 rc = (rr->response.code == 0x0001) ? 0 : -EIO;
1106 return rc;
1107}
1108
1109int chsc_sstpi(void *page, void *result, size_t size)
1110{
1111 struct {
1112 struct chsc_header request;
1113 unsigned int rsvd0[3];
1114 struct chsc_header response;
1115 char data[size];
1116 } __attribute__ ((packed)) *rr;
1117 int rc;
1118
1119 memset(page, 0, PAGE_SIZE);
1120 rr = page;
1121 rr->request.length = 0x0010;
1122 rr->request.code = 0x0038;
1123 rc = chsc(rr);
1124 if (rc)
1125 return -EIO;
1126 memcpy(result, &rr->data, size);
1127 return (rr->response.code == 0x0001) ? 0 : -EIO;
1128}
1129
Michael Ernstfd0457a2010-08-09 18:12:50 +02001130int chsc_siosl(struct subchannel_id schid)
1131{
Sebastian Ott34196f82010-10-25 16:10:29 +02001132 struct {
1133 struct chsc_header request;
1134 u32 word1;
1135 struct subchannel_id sid;
1136 u32 word3;
1137 struct chsc_header response;
1138 u32 word[11];
1139 } __attribute__ ((packed)) *siosl_area;
Michael Ernstfd0457a2010-08-09 18:12:50 +02001140 unsigned long flags;
1141 int ccode;
1142 int rc;
1143
Sebastian Ott34196f82010-10-25 16:10:29 +02001144 spin_lock_irqsave(&chsc_page_lock, flags);
1145 memset(chsc_page, 0, PAGE_SIZE);
1146 siosl_area = chsc_page;
1147 siosl_area->request.length = 0x0010;
1148 siosl_area->request.code = 0x0046;
1149 siosl_area->word1 = 0x80000000;
1150 siosl_area->sid = schid;
Michael Ernstfd0457a2010-08-09 18:12:50 +02001151
Sebastian Ott34196f82010-10-25 16:10:29 +02001152 ccode = chsc(siosl_area);
Michael Ernstfd0457a2010-08-09 18:12:50 +02001153 if (ccode > 0) {
1154 if (ccode == 3)
1155 rc = -ENODEV;
1156 else
1157 rc = -EBUSY;
1158 CIO_MSG_EVENT(2, "chsc: chsc failed for 0.%x.%04x (ccode=%d)\n",
1159 schid.ssid, schid.sch_no, ccode);
1160 goto out;
1161 }
Sebastian Ott34196f82010-10-25 16:10:29 +02001162 rc = chsc_error_from_response(siosl_area->response.code);
Michael Ernstfd0457a2010-08-09 18:12:50 +02001163 if (rc)
1164 CIO_MSG_EVENT(2, "chsc: siosl failed for 0.%x.%04x (rc=%04x)\n",
1165 schid.ssid, schid.sch_no,
Sebastian Ott34196f82010-10-25 16:10:29 +02001166 siosl_area->response.code);
Michael Ernstfd0457a2010-08-09 18:12:50 +02001167 else
1168 CIO_MSG_EVENT(4, "chsc: siosl succeeded for 0.%x.%04x\n",
1169 schid.ssid, schid.sch_no);
1170out:
Sebastian Ott34196f82010-10-25 16:10:29 +02001171 spin_unlock_irqrestore(&chsc_page_lock, flags);
Michael Ernstfd0457a2010-08-09 18:12:50 +02001172 return rc;
1173}
1174EXPORT_SYMBOL_GPL(chsc_siosl);
Sebastian Ott184b08a2012-08-28 16:45:42 +02001175
1176/**
1177 * chsc_scm_info() - store SCM information (SSI)
1178 * @scm_area: request and response block for SSI
1179 * @token: continuation token
1180 *
1181 * Returns 0 on success.
1182 */
1183int chsc_scm_info(struct chsc_scm_info *scm_area, u64 token)
1184{
1185 int ccode, ret;
1186
1187 memset(scm_area, 0, sizeof(*scm_area));
1188 scm_area->request.length = 0x0020;
1189 scm_area->request.code = 0x004C;
1190 scm_area->reqtok = token;
1191
1192 ccode = chsc(scm_area);
1193 if (ccode > 0) {
1194 ret = (ccode == 3) ? -ENODEV : -EBUSY;
1195 goto out;
1196 }
1197 ret = chsc_error_from_response(scm_area->response.code);
1198 if (ret != 0)
1199 CIO_MSG_EVENT(2, "chsc: scm info failed (rc=%04x)\n",
1200 scm_area->response.code);
1201out:
1202 return ret;
1203}
1204EXPORT_SYMBOL_GPL(chsc_scm_info);