]> git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/blame - drivers/s390/cio/chsc.c
[PATCH] s390: introduce struct subchannel_id
[mirror_ubuntu-eoan-kernel.git] / drivers / s390 / cio / chsc.c
CommitLineData
1da177e4
LT
1/*
2 * drivers/s390/cio/chsc.c
3 * S/390 common I/O routines -- channel subsystem call
c63307f1 4 * $Revision: 1.120 $
1da177e4
LT
5 *
6 * Copyright (C) 1999-2002 IBM Deutschland Entwicklung GmbH,
7 * IBM Corporation
8 * Author(s): Ingo Adlung (adlung@de.ibm.com)
9 * Cornelia Huck (cohuck@de.ibm.com)
10 * Arnd Bergmann (arndb@de.ibm.com)
11 */
12
13#include <linux/module.h>
14#include <linux/config.h>
15#include <linux/slab.h>
16#include <linux/init.h>
17#include <linux/device.h>
18
19#include <asm/cio.h>
20
21#include "css.h"
22#include "cio.h"
23#include "cio_debug.h"
24#include "ioasm.h"
25#include "chsc.h"
26
27static struct channel_path *chps[NR_CHPIDS];
28
29static void *sei_page;
30
31static int new_channel_path(int chpid);
32
33static inline void
34set_chp_logically_online(int chp, int onoff)
35{
36 chps[chp]->state = onoff;
37}
38
39static int
40get_chp_status(int chp)
41{
42 return (chps[chp] ? chps[chp]->state : -ENODEV);
43}
44
45void
46chsc_validate_chpids(struct subchannel *sch)
47{
48 int mask, chp;
49
50 for (chp = 0; chp <= 7; chp++) {
51 mask = 0x80 >> chp;
52 if (!get_chp_status(sch->schib.pmcw.chpid[chp]))
53 /* disable using this path */
54 sch->opm &= ~mask;
55 }
56}
57
58void
59chpid_is_actually_online(int chp)
60{
61 int state;
62
63 state = get_chp_status(chp);
64 if (state < 0) {
65 need_rescan = 1;
66 queue_work(slow_path_wq, &slow_path_work);
67 } else
68 WARN_ON(!state);
69}
70
71/* FIXME: this is _always_ called for every subchannel. shouldn't we
72 * process more than one at a time? */
73static int
74chsc_get_sch_desc_irq(struct subchannel *sch, void *page)
75{
76 int ccode, j;
77
78 struct {
79 struct chsc_header request;
80 u16 reserved1;
81 u16 f_sch; /* first subchannel */
82 u16 reserved2;
83 u16 l_sch; /* last subchannel */
84 u32 reserved3;
85 struct chsc_header response;
86 u32 reserved4;
87 u8 sch_valid : 1;
88 u8 dev_valid : 1;
89 u8 st : 3; /* subchannel type */
90 u8 zeroes : 3;
91 u8 unit_addr; /* unit address */
92 u16 devno; /* device number */
93 u8 path_mask;
94 u8 fla_valid_mask;
95 u16 sch; /* subchannel */
96 u8 chpid[8]; /* chpids 0-7 */
97 u16 fla[8]; /* full link addresses 0-7 */
98 } *ssd_area;
99
100 ssd_area = page;
101
102 ssd_area->request = (struct chsc_header) {
103 .length = 0x0010,
104 .code = 0x0004,
105 };
106
a8237fc4
CH
107 ssd_area->f_sch = sch->schid.sch_no;
108 ssd_area->l_sch = sch->schid.sch_no;
1da177e4
LT
109
110 ccode = chsc(ssd_area);
111 if (ccode > 0) {
112 pr_debug("chsc returned with ccode = %d\n", ccode);
113 return (ccode == 3) ? -ENODEV : -EBUSY;
114 }
115
116 switch (ssd_area->response.code) {
117 case 0x0001: /* everything ok */
118 break;
119 case 0x0002:
120 CIO_CRW_EVENT(2, "Invalid command!\n");
121 return -EINVAL;
122 case 0x0003:
123 CIO_CRW_EVENT(2, "Error in chsc request block!\n");
124 return -EINVAL;
125 case 0x0004:
126 CIO_CRW_EVENT(2, "Model does not provide ssd\n");
127 return -EOPNOTSUPP;
128 default:
129 CIO_CRW_EVENT(2, "Unknown CHSC response %d\n",
130 ssd_area->response.code);
131 return -EIO;
132 }
133
134 /*
135 * ssd_area->st stores the type of the detected
136 * subchannel, with the following definitions:
137 *
138 * 0: I/O subchannel: All fields have meaning
139 * 1: CHSC subchannel: Only sch_val, st and sch
140 * have meaning
141 * 2: Message subchannel: All fields except unit_addr
142 * have meaning
143 * 3: ADM subchannel: Only sch_val, st and sch
144 * have meaning
145 *
146 * Other types are currently undefined.
147 */
148 if (ssd_area->st > 3) { /* uhm, that looks strange... */
149 CIO_CRW_EVENT(0, "Strange subchannel type %d"
a8237fc4
CH
150 " for sch %04x\n", ssd_area->st,
151 sch->schid.sch_no);
1da177e4
LT
152 /*
153 * There may have been a new subchannel type defined in the
154 * time since this code was written; since we don't know which
155 * fields have meaning and what to do with it we just jump out
156 */
157 return 0;
158 } else {
159 const char *type[4] = {"I/O", "chsc", "message", "ADM"};
160 CIO_CRW_EVENT(6, "ssd: sch %04x is %s subchannel\n",
a8237fc4 161 sch->schid.sch_no, type[ssd_area->st]);
1da177e4
LT
162
163 sch->ssd_info.valid = 1;
164 sch->ssd_info.type = ssd_area->st;
165 }
166
167 if (ssd_area->st == 0 || ssd_area->st == 2) {
168 for (j = 0; j < 8; j++) {
169 if (!((0x80 >> j) & ssd_area->path_mask &
170 ssd_area->fla_valid_mask))
171 continue;
172 sch->ssd_info.chpid[j] = ssd_area->chpid[j];
173 sch->ssd_info.fla[j] = ssd_area->fla[j];
174 }
175 }
176 return 0;
177}
178
179int
180css_get_ssd_info(struct subchannel *sch)
181{
182 int ret;
183 void *page;
184
185 page = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
186 if (!page)
187 return -ENOMEM;
188 spin_lock_irq(&sch->lock);
189 ret = chsc_get_sch_desc_irq(sch, page);
190 if (ret) {
191 static int cio_chsc_err_msg;
192
193 if (!cio_chsc_err_msg) {
194 printk(KERN_ERR
195 "chsc_get_sch_descriptions:"
196 " Error %d while doing chsc; "
197 "processing some machine checks may "
198 "not work\n", ret);
199 cio_chsc_err_msg = 1;
200 }
201 }
202 spin_unlock_irq(&sch->lock);
203 free_page((unsigned long)page);
204 if (!ret) {
205 int j, chpid;
206 /* Allocate channel path structures, if needed. */
207 for (j = 0; j < 8; j++) {
208 chpid = sch->ssd_info.chpid[j];
209 if (chpid && (get_chp_status(chpid) < 0))
210 new_channel_path(chpid);
211 }
212 }
213 return ret;
214}
215
216static int
217s390_subchannel_remove_chpid(struct device *dev, void *data)
218{
219 int j;
220 int mask;
221 struct subchannel *sch;
222 __u8 *chpid;
223 struct schib schib;
224
225 sch = to_subchannel(dev);
226 chpid = data;
227 for (j = 0; j < 8; j++)
228 if (sch->schib.pmcw.chpid[j] == *chpid)
229 break;
230 if (j >= 8)
231 return 0;
232
233 mask = 0x80 >> j;
234 spin_lock(&sch->lock);
235
a8237fc4 236 stsch(sch->schid, &schib);
1da177e4
LT
237 if (!schib.pmcw.dnv)
238 goto out_unreg;
239 memcpy(&sch->schib, &schib, sizeof(struct schib));
240 /* Check for single path devices. */
241 if (sch->schib.pmcw.pim == 0x80)
242 goto out_unreg;
243 if (sch->vpm == mask)
244 goto out_unreg;
245
246 if ((sch->schib.scsw.actl & (SCSW_ACTL_CLEAR_PEND |
247 SCSW_ACTL_HALT_PEND |
248 SCSW_ACTL_START_PEND |
249 SCSW_ACTL_RESUME_PEND)) &&
250 (sch->schib.pmcw.lpum == mask)) {
251 int cc = cio_cancel(sch);
252
253 if (cc == -ENODEV)
254 goto out_unreg;
255
256 if (cc == -EINVAL) {
257 cc = cio_clear(sch);
258 if (cc == -ENODEV)
259 goto out_unreg;
260 /* Call handler. */
261 if (sch->driver && sch->driver->termination)
262 sch->driver->termination(&sch->dev);
263 goto out_unlock;
264 }
265 } else if ((sch->schib.scsw.actl & SCSW_ACTL_DEVACT) &&
266 (sch->schib.scsw.actl & SCSW_ACTL_SCHACT) &&
267 (sch->schib.pmcw.lpum == mask)) {
268 int cc;
269
270 cc = cio_clear(sch);
271 if (cc == -ENODEV)
272 goto out_unreg;
273 /* Call handler. */
274 if (sch->driver && sch->driver->termination)
275 sch->driver->termination(&sch->dev);
276 goto out_unlock;
277 }
278
279 /* trigger path verification. */
280 if (sch->driver && sch->driver->verify)
281 sch->driver->verify(&sch->dev);
282out_unlock:
283 spin_unlock(&sch->lock);
284 return 0;
285out_unreg:
286 spin_unlock(&sch->lock);
287 sch->lpm = 0;
a8237fc4 288 if (css_enqueue_subchannel_slow(sch->schid)) {
1da177e4
LT
289 css_clear_subchannel_slow_list();
290 need_rescan = 1;
291 }
292 return 0;
293}
294
295static inline void
296s390_set_chpid_offline( __u8 chpid)
297{
298 char dbf_txt[15];
299
300 sprintf(dbf_txt, "chpr%x", chpid);
301 CIO_TRACE_EVENT(2, dbf_txt);
302
303 if (get_chp_status(chpid) <= 0)
304 return;
305
306 bus_for_each_dev(&css_bus_type, NULL, &chpid,
307 s390_subchannel_remove_chpid);
308
309 if (need_rescan || css_slow_subchannels_exist())
310 queue_work(slow_path_wq, &slow_path_work);
311}
312
313static int
314s390_process_res_acc_sch(u8 chpid, __u16 fla, u32 fla_mask,
315 struct subchannel *sch)
316{
317 int found;
318 int chp;
319 int ccode;
320
321 found = 0;
322 for (chp = 0; chp <= 7; chp++)
323 /*
324 * check if chpid is in information updated by ssd
325 */
326 if (sch->ssd_info.valid &&
327 sch->ssd_info.chpid[chp] == chpid &&
328 (sch->ssd_info.fla[chp] & fla_mask) == fla) {
329 found = 1;
330 break;
331 }
332
333 if (found == 0)
334 return 0;
335
336 /*
337 * Do a stsch to update our subchannel structure with the
338 * new path information and eventually check for logically
339 * offline chpids.
340 */
a8237fc4 341 ccode = stsch(sch->schid, &sch->schib);
1da177e4
LT
342 if (ccode > 0)
343 return 0;
344
345 return 0x80 >> chp;
346}
347
348static int
349s390_process_res_acc (u8 chpid, __u16 fla, u32 fla_mask)
350{
351 struct subchannel *sch;
a8237fc4
CH
352 int rc;
353 struct subchannel_id schid;
1da177e4
LT
354 char dbf_txt[15];
355
356 sprintf(dbf_txt, "accpr%x", chpid);
357 CIO_TRACE_EVENT( 2, dbf_txt);
358 if (fla != 0) {
359 sprintf(dbf_txt, "fla%x", fla);
360 CIO_TRACE_EVENT( 2, dbf_txt);
361 }
362
363 /*
364 * I/O resources may have become accessible.
365 * Scan through all subchannels that may be concerned and
366 * do a validation on those.
367 * The more information we have (info), the less scanning
368 * will we have to do.
369 */
370
371 if (!get_chp_status(chpid))
372 return 0; /* no need to do the rest */
373
374 rc = 0;
a8237fc4
CH
375 init_subchannel_id(&schid);
376 do {
1da177e4
LT
377 int chp_mask, old_lpm;
378
a8237fc4 379 sch = get_subchannel_by_schid(schid);
1da177e4
LT
380 if (!sch) {
381 struct schib schib;
382 int ret;
383 /*
384 * We don't know the device yet, but since a path
385 * may be available now to the device we'll have
386 * to do recognition again.
387 * Since we don't have any idea about which chpid
388 * that beast may be on we'll have to do a stsch
389 * on all devices, grr...
390 */
a8237fc4 391 if (stsch(schid, &schib)) {
1da177e4
LT
392 /* We're through */
393 if (need_rescan)
394 rc = -EAGAIN;
395 break;
396 }
397 if (need_rescan) {
398 rc = -EAGAIN;
399 continue;
400 }
401 /* Put it on the slow path. */
a8237fc4 402 ret = css_enqueue_subchannel_slow(schid);
1da177e4
LT
403 if (ret) {
404 css_clear_subchannel_slow_list();
405 need_rescan = 1;
406 }
407 rc = -EAGAIN;
408 continue;
409 }
410
411 spin_lock_irq(&sch->lock);
412
413 chp_mask = s390_process_res_acc_sch(chpid, fla, fla_mask, sch);
414
415 if (chp_mask == 0) {
416
417 spin_unlock_irq(&sch->lock);
c63307f1 418 continue;
1da177e4
LT
419 }
420 old_lpm = sch->lpm;
421 sch->lpm = ((sch->schib.pmcw.pim &
422 sch->schib.pmcw.pam &
423 sch->schib.pmcw.pom)
424 | chp_mask) & sch->opm;
425 if (!old_lpm && sch->lpm)
426 device_trigger_reprobe(sch);
427 else if (sch->driver && sch->driver->verify)
428 sch->driver->verify(&sch->dev);
429
430 spin_unlock_irq(&sch->lock);
431 put_device(&sch->dev);
c63307f1 432 if (fla_mask == 0xffff)
1da177e4 433 break;
a8237fc4 434 } while (schid.sch_no++ < __MAX_SUBCHANNEL);
1da177e4
LT
435 return rc;
436}
437
438static int
439__get_chpid_from_lir(void *data)
440{
441 struct lir {
442 u8 iq;
443 u8 ic;
444 u16 sci;
445 /* incident-node descriptor */
446 u32 indesc[28];
447 /* attached-node descriptor */
448 u32 andesc[28];
449 /* incident-specific information */
450 u32 isinfo[28];
451 } *lir;
452
453 lir = (struct lir*) data;
454 if (!(lir->iq&0x80))
455 /* NULL link incident record */
456 return -EINVAL;
457 if (!(lir->indesc[0]&0xc0000000))
458 /* node descriptor not valid */
459 return -EINVAL;
460 if (!(lir->indesc[0]&0x10000000))
461 /* don't handle device-type nodes - FIXME */
462 return -EINVAL;
463 /* Byte 3 contains the chpid. Could also be CTCA, but we don't care */
464
465 return (u16) (lir->indesc[0]&0x000000ff);
466}
467
468int
469chsc_process_crw(void)
470{
471 int chpid, ret;
472 struct {
473 struct chsc_header request;
474 u32 reserved1;
475 u32 reserved2;
476 u32 reserved3;
477 struct chsc_header response;
478 u32 reserved4;
479 u8 flags;
480 u8 vf; /* validity flags */
481 u8 rs; /* reporting source */
482 u8 cc; /* content code */
483 u16 fla; /* full link address */
484 u16 rsid; /* reporting source id */
485 u32 reserved5;
486 u32 reserved6;
487 u32 ccdf[96]; /* content-code dependent field */
488 /* ccdf has to be big enough for a link-incident record */
489 } *sei_area;
490
491 if (!sei_page)
492 return 0;
493 /*
494 * build the chsc request block for store event information
495 * and do the call
496 * This function is only called by the machine check handler thread,
497 * so we don't need locking for the sei_page.
498 */
499 sei_area = sei_page;
500
501 CIO_TRACE_EVENT( 2, "prcss");
502 ret = 0;
503 do {
504 int ccode, status;
505 memset(sei_area, 0, sizeof(*sei_area));
506
507 sei_area->request = (struct chsc_header) {
508 .length = 0x0010,
509 .code = 0x000e,
510 };
511
512 ccode = chsc(sei_area);
513 if (ccode > 0)
514 return 0;
515
516 switch (sei_area->response.code) {
517 /* for debug purposes, check for problems */
518 case 0x0001:
519 CIO_CRW_EVENT(4, "chsc_process_crw: event information "
520 "successfully stored\n");
521 break; /* everything ok */
522 case 0x0002:
523 CIO_CRW_EVENT(2,
524 "chsc_process_crw: invalid command!\n");
525 return 0;
526 case 0x0003:
527 CIO_CRW_EVENT(2, "chsc_process_crw: error in chsc "
528 "request block!\n");
529 return 0;
530 case 0x0005:
531 CIO_CRW_EVENT(2, "chsc_process_crw: no event "
532 "information stored\n");
533 return 0;
534 default:
535 CIO_CRW_EVENT(2, "chsc_process_crw: chsc response %d\n",
536 sei_area->response.code);
537 return 0;
538 }
539
540 /* Check if we might have lost some information. */
541 if (sei_area->flags & 0x40)
542 CIO_CRW_EVENT(2, "chsc_process_crw: Event information "
543 "has been lost due to overflow!\n");
544
545 if (sei_area->rs != 4) {
546 CIO_CRW_EVENT(2, "chsc_process_crw: reporting source "
547 "(%04X) isn't a chpid!\n",
548 sei_area->rsid);
549 continue;
550 }
551
552 /* which kind of information was stored? */
553 switch (sei_area->cc) {
554 case 1: /* link incident*/
555 CIO_CRW_EVENT(4, "chsc_process_crw: "
556 "channel subsystem reports link incident,"
557 " reporting source is chpid %x\n",
558 sei_area->rsid);
559 chpid = __get_chpid_from_lir(sei_area->ccdf);
560 if (chpid < 0)
561 CIO_CRW_EVENT(4, "%s: Invalid LIR, skipping\n",
562 __FUNCTION__);
563 else
564 s390_set_chpid_offline(chpid);
565 break;
566
567 case 2: /* i/o resource accessibiliy */
568 CIO_CRW_EVENT(4, "chsc_process_crw: "
569 "channel subsystem reports some I/O "
570 "devices may have become accessible\n");
571 pr_debug("Data received after sei: \n");
572 pr_debug("Validity flags: %x\n", sei_area->vf);
573
574 /* allocate a new channel path structure, if needed */
575 status = get_chp_status(sei_area->rsid);
576 if (status < 0)
577 new_channel_path(sei_area->rsid);
578 else if (!status)
579 return 0;
580 if ((sei_area->vf & 0x80) == 0) {
581 pr_debug("chpid: %x\n", sei_area->rsid);
582 ret = s390_process_res_acc(sei_area->rsid,
583 0, 0);
584 } else if ((sei_area->vf & 0xc0) == 0x80) {
585 pr_debug("chpid: %x link addr: %x\n",
586 sei_area->rsid, sei_area->fla);
587 ret = s390_process_res_acc(sei_area->rsid,
588 sei_area->fla,
589 0xff00);
590 } else if ((sei_area->vf & 0xc0) == 0xc0) {
591 pr_debug("chpid: %x full link addr: %x\n",
592 sei_area->rsid, sei_area->fla);
593 ret = s390_process_res_acc(sei_area->rsid,
594 sei_area->fla,
595 0xffff);
596 }
597 pr_debug("\n");
598
599 break;
600
601 default: /* other stuff */
602 CIO_CRW_EVENT(4, "chsc_process_crw: event %d\n",
603 sei_area->cc);
604 break;
605 }
606 } while (sei_area->flags & 0x80);
607 return ret;
608}
609
610static int
611chp_add(int chpid)
612{
613 struct subchannel *sch;
a8237fc4
CH
614 int ret, rc;
615 struct subchannel_id schid;
1da177e4
LT
616 char dbf_txt[15];
617
618 if (!get_chp_status(chpid))
619 return 0; /* no need to do the rest */
620
621 sprintf(dbf_txt, "cadd%x", chpid);
622 CIO_TRACE_EVENT(2, dbf_txt);
623
624 rc = 0;
a8237fc4
CH
625 init_subchannel_id(&schid);
626 do {
1da177e4
LT
627 int i;
628
a8237fc4 629 sch = get_subchannel_by_schid(schid);
1da177e4
LT
630 if (!sch) {
631 struct schib schib;
632
a8237fc4 633 if (stsch(schid, &schib)) {
1da177e4
LT
634 /* We're through */
635 if (need_rescan)
636 rc = -EAGAIN;
637 break;
638 }
639 if (need_rescan) {
640 rc = -EAGAIN;
641 continue;
642 }
643 /* Put it on the slow path. */
a8237fc4 644 ret = css_enqueue_subchannel_slow(schid);
1da177e4
LT
645 if (ret) {
646 css_clear_subchannel_slow_list();
647 need_rescan = 1;
648 }
649 rc = -EAGAIN;
650 continue;
651 }
652
653 spin_lock(&sch->lock);
654 for (i=0; i<8; i++)
655 if (sch->schib.pmcw.chpid[i] == chpid) {
a8237fc4 656 if (stsch(sch->schid, &sch->schib) != 0) {
1da177e4
LT
657 /* Endgame. */
658 spin_unlock(&sch->lock);
659 return rc;
660 }
661 break;
662 }
663 if (i==8) {
664 spin_unlock(&sch->lock);
665 return rc;
666 }
667 sch->lpm = ((sch->schib.pmcw.pim &
668 sch->schib.pmcw.pam &
669 sch->schib.pmcw.pom)
670 | 0x80 >> i) & sch->opm;
671
672 if (sch->driver && sch->driver->verify)
673 sch->driver->verify(&sch->dev);
674
675 spin_unlock(&sch->lock);
676 put_device(&sch->dev);
a8237fc4 677 } while (schid.sch_no++ < __MAX_SUBCHANNEL);
1da177e4
LT
678 return rc;
679}
680
681/*
682 * Handling of crw machine checks with channel path source.
683 */
684int
685chp_process_crw(int chpid, int on)
686{
687 if (on == 0) {
688 /* Path has gone. We use the link incident routine.*/
689 s390_set_chpid_offline(chpid);
690 return 0; /* De-register is async anyway. */
691 }
692 /*
693 * Path has come. Allocate a new channel path structure,
694 * if needed.
695 */
696 if (get_chp_status(chpid) < 0)
697 new_channel_path(chpid);
698 /* Avoid the extra overhead in process_rec_acc. */
699 return chp_add(chpid);
700}
701
702static inline int
703__check_for_io_and_kill(struct subchannel *sch, int index)
704{
705 int cc;
706
707 if (!device_is_online(sch))
708 /* cio could be doing I/O. */
709 return 0;
a8237fc4 710 cc = stsch(sch->schid, &sch->schib);
1da177e4
LT
711 if (cc)
712 return 0;
713 if (sch->schib.scsw.actl && sch->schib.pmcw.lpum == (0x80 >> index)) {
714 device_set_waiting(sch);
715 return 1;
716 }
717 return 0;
718}
719
720static inline void
721__s390_subchannel_vary_chpid(struct subchannel *sch, __u8 chpid, int on)
722{
723 int chp, old_lpm;
724 unsigned long flags;
725
726 if (!sch->ssd_info.valid)
727 return;
728
729 spin_lock_irqsave(&sch->lock, flags);
730 old_lpm = sch->lpm;
731 for (chp = 0; chp < 8; chp++) {
732 if (sch->ssd_info.chpid[chp] != chpid)
733 continue;
734
735 if (on) {
736 sch->opm |= (0x80 >> chp);
737 sch->lpm |= (0x80 >> chp);
738 if (!old_lpm)
739 device_trigger_reprobe(sch);
740 else if (sch->driver && sch->driver->verify)
741 sch->driver->verify(&sch->dev);
742 } else {
743 sch->opm &= ~(0x80 >> chp);
744 sch->lpm &= ~(0x80 >> chp);
745 /*
746 * Give running I/O a grace period in which it
747 * can successfully terminate, even using the
748 * just varied off path. Then kill it.
749 */
750 if (!__check_for_io_and_kill(sch, chp) && !sch->lpm) {
a8237fc4 751 if (css_enqueue_subchannel_slow(sch->schid)) {
1da177e4
LT
752 css_clear_subchannel_slow_list();
753 need_rescan = 1;
754 }
755 } else if (sch->driver && sch->driver->verify)
756 sch->driver->verify(&sch->dev);
757 }
758 break;
759 }
760 spin_unlock_irqrestore(&sch->lock, flags);
761}
762
763static int
764s390_subchannel_vary_chpid_off(struct device *dev, void *data)
765{
766 struct subchannel *sch;
767 __u8 *chpid;
768
769 sch = to_subchannel(dev);
770 chpid = data;
771
772 __s390_subchannel_vary_chpid(sch, *chpid, 0);
773 return 0;
774}
775
776static int
777s390_subchannel_vary_chpid_on(struct device *dev, void *data)
778{
779 struct subchannel *sch;
780 __u8 *chpid;
781
782 sch = to_subchannel(dev);
783 chpid = data;
784
785 __s390_subchannel_vary_chpid(sch, *chpid, 1);
786 return 0;
787}
788
789/*
790 * Function: s390_vary_chpid
791 * Varies the specified chpid online or offline
792 */
793static int
794s390_vary_chpid( __u8 chpid, int on)
795{
796 char dbf_text[15];
a8237fc4
CH
797 int status, ret;
798 struct subchannel_id schid;
1da177e4
LT
799 struct subchannel *sch;
800
801 sprintf(dbf_text, on?"varyon%x":"varyoff%x", chpid);
802 CIO_TRACE_EVENT( 2, dbf_text);
803
804 status = get_chp_status(chpid);
805 if (status < 0) {
806 printk(KERN_ERR "Can't vary unknown chpid %02X\n", chpid);
807 return -EINVAL;
808 }
809
810 if (!on && !status) {
811 printk(KERN_ERR "chpid %x is already offline\n", chpid);
812 return -EINVAL;
813 }
814
815 set_chp_logically_online(chpid, on);
816
817 /*
818 * Redo PathVerification on the devices the chpid connects to
819 */
820
821 bus_for_each_dev(&css_bus_type, NULL, &chpid, on ?
822 s390_subchannel_vary_chpid_on :
823 s390_subchannel_vary_chpid_off);
824 if (!on)
825 goto out;
826 /* Scan for new devices on varied on path. */
a8237fc4
CH
827 init_subchannel_id(&schid);
828 do {
1da177e4
LT
829 struct schib schib;
830
831 if (need_rescan)
832 break;
a8237fc4 833 sch = get_subchannel_by_schid(schid);
1da177e4
LT
834 if (sch) {
835 put_device(&sch->dev);
836 continue;
837 }
a8237fc4 838 if (stsch(schid, &schib))
1da177e4
LT
839 /* We're through */
840 break;
841 /* Put it on the slow path. */
a8237fc4 842 ret = css_enqueue_subchannel_slow(schid);
1da177e4
LT
843 if (ret) {
844 css_clear_subchannel_slow_list();
845 need_rescan = 1;
846 }
a8237fc4 847 } while (schid.sch_no++ < __MAX_SUBCHANNEL);
1da177e4
LT
848out:
849 if (need_rescan || css_slow_subchannels_exist())
850 queue_work(slow_path_wq, &slow_path_work);
851 return 0;
852}
853
854/*
855 * Files for the channel path entries.
856 */
857static ssize_t
3fd3c0a5 858chp_status_show(struct device *dev, struct device_attribute *attr, char *buf)
1da177e4
LT
859{
860 struct channel_path *chp = container_of(dev, struct channel_path, dev);
861
862 if (!chp)
863 return 0;
864 return (get_chp_status(chp->id) ? sprintf(buf, "online\n") :
865 sprintf(buf, "offline\n"));
866}
867
868static ssize_t
3fd3c0a5 869chp_status_write(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1da177e4
LT
870{
871 struct channel_path *cp = container_of(dev, struct channel_path, dev);
872 char cmd[10];
873 int num_args;
874 int error;
875
876 num_args = sscanf(buf, "%5s", cmd);
877 if (!num_args)
878 return count;
879
880 if (!strnicmp(cmd, "on", 2))
881 error = s390_vary_chpid(cp->id, 1);
882 else if (!strnicmp(cmd, "off", 3))
883 error = s390_vary_chpid(cp->id, 0);
884 else
885 error = -EINVAL;
886
887 return error < 0 ? error : count;
888
889}
890
891static DEVICE_ATTR(status, 0644, chp_status_show, chp_status_write);
892
893static ssize_t
3fd3c0a5 894chp_type_show(struct device *dev, struct device_attribute *attr, char *buf)
1da177e4
LT
895{
896 struct channel_path *chp = container_of(dev, struct channel_path, dev);
897
898 if (!chp)
899 return 0;
900 return sprintf(buf, "%x\n", chp->desc.desc);
901}
902
903static DEVICE_ATTR(type, 0444, chp_type_show, NULL);
904
905static struct attribute * chp_attrs[] = {
906 &dev_attr_status.attr,
907 &dev_attr_type.attr,
908 NULL,
909};
910
911static struct attribute_group chp_attr_group = {
912 .attrs = chp_attrs,
913};
914
915static void
916chp_release(struct device *dev)
917{
918 struct channel_path *cp;
919
920 cp = container_of(dev, struct channel_path, dev);
921 kfree(cp);
922}
923
924static int
925chsc_determine_channel_path_description(int chpid,
926 struct channel_path_desc *desc)
927{
928 int ccode, ret;
929
930 struct {
931 struct chsc_header request;
932 u32 : 24;
933 u32 first_chpid : 8;
934 u32 : 24;
935 u32 last_chpid : 8;
936 u32 zeroes1;
937 struct chsc_header response;
938 u32 zeroes2;
939 struct channel_path_desc desc;
940 } *scpd_area;
941
942 scpd_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
943 if (!scpd_area)
944 return -ENOMEM;
945
946 scpd_area->request = (struct chsc_header) {
947 .length = 0x0010,
948 .code = 0x0002,
949 };
950
951 scpd_area->first_chpid = chpid;
952 scpd_area->last_chpid = chpid;
953
954 ccode = chsc(scpd_area);
955 if (ccode > 0) {
956 ret = (ccode == 3) ? -ENODEV : -EBUSY;
957 goto out;
958 }
959
960 switch (scpd_area->response.code) {
961 case 0x0001: /* Success. */
962 memcpy(desc, &scpd_area->desc,
963 sizeof(struct channel_path_desc));
964 ret = 0;
965 break;
966 case 0x0003: /* Invalid block. */
967 case 0x0007: /* Invalid format. */
968 case 0x0008: /* Other invalid block. */
969 CIO_CRW_EVENT(2, "Error in chsc request block!\n");
970 ret = -EINVAL;
971 break;
972 case 0x0004: /* Command not provided in model. */
973 CIO_CRW_EVENT(2, "Model does not provide scpd\n");
974 ret = -EOPNOTSUPP;
975 break;
976 default:
977 CIO_CRW_EVENT(2, "Unknown CHSC response %d\n",
978 scpd_area->response.code);
979 ret = -EIO;
980 }
981out:
982 free_page((unsigned long)scpd_area);
983 return ret;
984}
985
986/*
987 * Entries for chpids on the system bus.
988 * This replaces /proc/chpids.
989 */
990static int
991new_channel_path(int chpid)
992{
993 struct channel_path *chp;
994 int ret;
995
996 chp = kmalloc(sizeof(struct channel_path), GFP_KERNEL);
997 if (!chp)
998 return -ENOMEM;
999 memset(chp, 0, sizeof(struct channel_path));
1000
1001 /* fill in status, etc. */
1002 chp->id = chpid;
1003 chp->state = 1;
1004 chp->dev = (struct device) {
1005 .parent = &css_bus_device,
1006 .release = chp_release,
1007 };
1008 snprintf(chp->dev.bus_id, BUS_ID_SIZE, "chp0.%x", chpid);
1009
1010 /* Obtain channel path description and fill it in. */
1011 ret = chsc_determine_channel_path_description(chpid, &chp->desc);
1012 if (ret)
1013 goto out_free;
1014
1015 /* make it known to the system */
1016 ret = device_register(&chp->dev);
1017 if (ret) {
1018 printk(KERN_WARNING "%s: could not register %02x\n",
1019 __func__, chpid);
1020 goto out_free;
1021 }
1022 ret = sysfs_create_group(&chp->dev.kobj, &chp_attr_group);
1023 if (ret) {
1024 device_unregister(&chp->dev);
1025 goto out_free;
1026 } else
1027 chps[chpid] = chp;
1028 return ret;
1029out_free:
1030 kfree(chp);
1031 return ret;
1032}
1033
1034void *
1035chsc_get_chp_desc(struct subchannel *sch, int chp_no)
1036{
1037 struct channel_path *chp;
1038 struct channel_path_desc *desc;
1039
1040 chp = chps[sch->schib.pmcw.chpid[chp_no]];
1041 if (!chp)
1042 return NULL;
1043 desc = kmalloc(sizeof(struct channel_path_desc), GFP_KERNEL);
1044 if (!desc)
1045 return NULL;
1046 memcpy(desc, &chp->desc, sizeof(struct channel_path_desc));
1047 return desc;
1048}
1049
1050
1051static int __init
1052chsc_alloc_sei_area(void)
1053{
1054 sei_page = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
1055 if (!sei_page)
1056 printk(KERN_WARNING"Can't allocate page for processing of " \
1057 "chsc machine checks!\n");
1058 return (sei_page ? 0 : -ENOMEM);
1059}
1060
1061subsys_initcall(chsc_alloc_sei_area);
1062
1063struct css_general_char css_general_characteristics;
1064struct css_chsc_char css_chsc_characteristics;
1065
1066int __init
1067chsc_determine_css_characteristics(void)
1068{
1069 int result;
1070 struct {
1071 struct chsc_header request;
1072 u32 reserved1;
1073 u32 reserved2;
1074 u32 reserved3;
1075 struct chsc_header response;
1076 u32 reserved4;
1077 u32 general_char[510];
1078 u32 chsc_char[518];
1079 } *scsc_area;
1080
1081 scsc_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
1082 if (!scsc_area) {
1083 printk(KERN_WARNING"cio: Was not able to determine available" \
1084 "CHSCs due to no memory.\n");
1085 return -ENOMEM;
1086 }
1087
1088 scsc_area->request = (struct chsc_header) {
1089 .length = 0x0010,
1090 .code = 0x0010,
1091 };
1092
1093 result = chsc(scsc_area);
1094 if (result) {
1095 printk(KERN_WARNING"cio: Was not able to determine " \
1096 "available CHSCs, cc=%i.\n", result);
1097 result = -EIO;
1098 goto exit;
1099 }
1100
1101 if (scsc_area->response.code != 1) {
1102 printk(KERN_WARNING"cio: Was not able to determine " \
1103 "available CHSCs.\n");
1104 result = -EIO;
1105 goto exit;
1106 }
1107 memcpy(&css_general_characteristics, scsc_area->general_char,
1108 sizeof(css_general_characteristics));
1109 memcpy(&css_chsc_characteristics, scsc_area->chsc_char,
1110 sizeof(css_chsc_characteristics));
1111exit:
1112 free_page ((unsigned long) scsc_area);
1113 return result;
1114}
1115
1116EXPORT_SYMBOL_GPL(css_general_characteristics);
1117EXPORT_SYMBOL_GPL(css_chsc_characteristics);