]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/s390/char/sclp_cmd.c
[S390] convert iucv printks to dev_xxx and pr_xxx macros.
[mirror_ubuntu-artful-kernel.git] / drivers / s390 / char / sclp_cmd.c
CommitLineData
08d07968
HC
1/*
2 * drivers/s390/char/sclp_cmd.c
3 *
4 * Copyright IBM Corp. 2007
4b28a8fe
HC
5 * Author(s): Heiko Carstens <heiko.carstens@de.ibm.com>,
6 * Peter Oberparleiter <peter.oberparleiter@de.ibm.com>
08d07968
HC
7 */
8
9#include <linux/completion.h>
10#include <linux/init.h>
11#include <linux/errno.h>
12#include <linux/slab.h>
13#include <linux/string.h>
e0bc2495
HC
14#include <linux/mm.h>
15#include <linux/mmzone.h>
16#include <linux/memory.h>
4b28a8fe 17#include <asm/chpid.h>
08d07968
HC
18#include <asm/sclp.h>
19#include "sclp.h"
20
21#define TAG "sclp_cmd: "
22
23#define SCLP_CMDW_READ_SCP_INFO 0x00020001
24#define SCLP_CMDW_READ_SCP_INFO_FORCED 0x00120001
25
26struct read_info_sccb {
27 struct sccb_header header; /* 0-7 */
28 u16 rnmax; /* 8-9 */
29 u8 rnsize; /* 10 */
30 u8 _reserved0[24 - 11]; /* 11-15 */
31 u8 loadparm[8]; /* 24-31 */
32 u8 _reserved1[48 - 32]; /* 32-47 */
33 u64 facilities; /* 48-55 */
34 u8 _reserved2[84 - 56]; /* 56-83 */
35 u8 fac84; /* 84 */
36 u8 _reserved3[91 - 85]; /* 85-90 */
37 u8 flags; /* 91 */
38 u8 _reserved4[100 - 92]; /* 92-99 */
39 u32 rnsize2; /* 100-103 */
40 u64 rnmax2; /* 104-111 */
41 u8 _reserved5[4096 - 112]; /* 112-4095 */
42} __attribute__((packed, aligned(PAGE_SIZE)));
43
44static struct read_info_sccb __initdata early_read_info_sccb;
45static int __initdata early_read_info_sccb_valid;
46
47u64 sclp_facilities;
48static u8 sclp_fac84;
e0bc2495
HC
49static unsigned long long rzm;
50static unsigned long long rnmax;
08d07968
HC
51
52static int __init sclp_cmd_sync_early(sclp_cmdw_t cmd, void *sccb)
53{
54 int rc;
55
56 __ctl_set_bit(0, 9);
57 rc = sclp_service_call(cmd, sccb);
58 if (rc)
59 goto out;
60 __load_psw_mask(PSW_BASE_BITS | PSW_MASK_EXT |
61 PSW_MASK_WAIT | PSW_DEFAULT_KEY);
62 local_irq_disable();
63out:
64 /* Contents of the sccb might have changed. */
65 barrier();
66 __ctl_clear_bit(0, 9);
67 return rc;
68}
69
23d17421 70static void __init sclp_read_info_early(void)
08d07968
HC
71{
72 int rc;
73 int i;
74 struct read_info_sccb *sccb;
75 sclp_cmdw_t commands[] = {SCLP_CMDW_READ_SCP_INFO_FORCED,
76 SCLP_CMDW_READ_SCP_INFO};
77
78 sccb = &early_read_info_sccb;
79 for (i = 0; i < ARRAY_SIZE(commands); i++) {
80 do {
81 memset(sccb, 0, sizeof(*sccb));
82 sccb->header.length = sizeof(*sccb);
83 sccb->header.control_mask[2] = 0x80;
84 rc = sclp_cmd_sync_early(commands[i], sccb);
85 } while (rc == -EBUSY);
86
87 if (rc)
88 break;
89 if (sccb->header.response_code == 0x10) {
90 early_read_info_sccb_valid = 1;
91 break;
92 }
93 if (sccb->header.response_code != 0x1f0)
94 break;
95 }
96}
97
98void __init sclp_facilities_detect(void)
99{
08d07968
HC
100 struct read_info_sccb *sccb;
101
23d17421 102 sclp_read_info_early();
08d07968 103 if (!early_read_info_sccb_valid)
23d17421
HC
104 return;
105
08d07968 106 sccb = &early_read_info_sccb;
23d17421
HC
107 sclp_facilities = sccb->facilities;
108 sclp_fac84 = sccb->fac84;
e0bc2495
HC
109 rnmax = sccb->rnmax ? sccb->rnmax : sccb->rnmax2;
110 rzm = sccb->rnsize ? sccb->rnsize : sccb->rnsize2;
111 rzm <<= 20;
23d17421
HC
112}
113
114unsigned long long sclp_get_rnmax(void)
115{
116 return rnmax;
117}
118
119unsigned long long sclp_get_rzm(void)
120{
121 return rzm;
08d07968
HC
122}
123
124/*
23d17421
HC
125 * This function will be called after sclp_facilities_detect(), which gets
126 * called from early.c code. Therefore the sccb should have valid contents.
08d07968
HC
127 */
128void __init sclp_get_ipl_info(struct sclp_ipl_info *info)
129{
130 struct read_info_sccb *sccb;
131
132 if (!early_read_info_sccb_valid)
133 return;
134 sccb = &early_read_info_sccb;
135 info->is_valid = 1;
136 if (sccb->flags & 0x2)
137 info->has_dump = 1;
138 memcpy(&info->loadparm, &sccb->loadparm, LOADPARM_LEN);
139}
140
141static void sclp_sync_callback(struct sclp_req *req, void *data)
142{
143 struct completion *completion = data;
144
145 complete(completion);
146}
147
148static int do_sync_request(sclp_cmdw_t cmd, void *sccb)
149{
150 struct completion completion;
151 struct sclp_req *request;
152 int rc;
153
154 request = kzalloc(sizeof(*request), GFP_KERNEL);
155 if (!request)
156 return -ENOMEM;
157 request->command = cmd;
158 request->sccb = sccb;
159 request->status = SCLP_REQ_FILLED;
160 request->callback = sclp_sync_callback;
161 request->callback_data = &completion;
162 init_completion(&completion);
163
164 /* Perform sclp request. */
165 rc = sclp_add_request(request);
166 if (rc)
167 goto out;
168 wait_for_completion(&completion);
169
170 /* Check response. */
171 if (request->status != SCLP_REQ_DONE) {
172 printk(KERN_WARNING TAG "sync request failed "
173 "(cmd=0x%08x, status=0x%02x)\n", cmd, request->status);
174 rc = -EIO;
175 }
176out:
177 kfree(request);
178 return rc;
179}
180
181/*
182 * CPU configuration related functions.
183 */
184
185#define SCLP_CMDW_READ_CPU_INFO 0x00010001
186#define SCLP_CMDW_CONFIGURE_CPU 0x00110001
187#define SCLP_CMDW_DECONFIGURE_CPU 0x00100001
188
189struct read_cpu_info_sccb {
190 struct sccb_header header;
191 u16 nr_configured;
192 u16 offset_configured;
193 u16 nr_standby;
194 u16 offset_standby;
195 u8 reserved[4096 - 16];
196} __attribute__((packed, aligned(PAGE_SIZE)));
197
08d07968
HC
198static void sclp_fill_cpu_info(struct sclp_cpu_info *info,
199 struct read_cpu_info_sccb *sccb)
200{
201 char *page = (char *) sccb;
202
203 memset(info, 0, sizeof(*info));
204 info->configured = sccb->nr_configured;
205 info->standby = sccb->nr_standby;
206 info->combined = sccb->nr_configured + sccb->nr_standby;
207 info->has_cpu_type = sclp_fac84 & 0x1;
208 memcpy(&info->cpu, page + sccb->offset_configured,
209 info->combined * sizeof(struct sclp_cpu_entry));
210}
211
48483b32 212int sclp_get_cpu_info(struct sclp_cpu_info *info)
08d07968
HC
213{
214 int rc;
215 struct read_cpu_info_sccb *sccb;
216
217 if (!SCLP_HAS_CPU_INFO)
218 return -EOPNOTSUPP;
48483b32 219 sccb = (void *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
08d07968
HC
220 if (!sccb)
221 return -ENOMEM;
08d07968
HC
222 sccb->header.length = sizeof(*sccb);
223 rc = do_sync_request(SCLP_CMDW_READ_CPU_INFO, sccb);
224 if (rc)
225 goto out;
226 if (sccb->header.response_code != 0x0010) {
227 printk(KERN_WARNING TAG "readcpuinfo failed "
228 "(response=0x%04x)\n", sccb->header.response_code);
229 rc = -EIO;
230 goto out;
231 }
232 sclp_fill_cpu_info(info, sccb);
233out:
234 free_page((unsigned long) sccb);
235 return rc;
236}
237
08d07968
HC
238struct cpu_configure_sccb {
239 struct sccb_header header;
240} __attribute__((packed, aligned(8)));
241
242static int do_cpu_configure(sclp_cmdw_t cmd)
243{
244 struct cpu_configure_sccb *sccb;
245 int rc;
246
247 if (!SCLP_HAS_CPU_RECONFIG)
248 return -EOPNOTSUPP;
249 /*
250 * This is not going to cross a page boundary since we force
251 * kmalloc to have a minimum alignment of 8 bytes on s390.
252 */
253 sccb = kzalloc(sizeof(*sccb), GFP_KERNEL | GFP_DMA);
254 if (!sccb)
255 return -ENOMEM;
256 sccb->header.length = sizeof(*sccb);
257 rc = do_sync_request(cmd, sccb);
258 if (rc)
259 goto out;
260 switch (sccb->header.response_code) {
261 case 0x0020:
262 case 0x0120:
263 break;
264 default:
265 printk(KERN_WARNING TAG "configure cpu failed (cmd=0x%08x, "
266 "response=0x%04x)\n", cmd, sccb->header.response_code);
267 rc = -EIO;
268 break;
269 }
270out:
271 kfree(sccb);
272 return rc;
273}
274
275int sclp_cpu_configure(u8 cpu)
276{
277 return do_cpu_configure(SCLP_CMDW_CONFIGURE_CPU | cpu << 8);
278}
279
280int sclp_cpu_deconfigure(u8 cpu)
281{
282 return do_cpu_configure(SCLP_CMDW_DECONFIGURE_CPU | cpu << 8);
283}
4b28a8fe 284
e0bc2495
HC
285#ifdef CONFIG_MEMORY_HOTPLUG
286
287static DEFINE_MUTEX(sclp_mem_mutex);
288static LIST_HEAD(sclp_mem_list);
289static u8 sclp_max_storage_id;
290static unsigned long sclp_storage_ids[256 / BITS_PER_LONG];
291
292struct memory_increment {
293 struct list_head list;
294 u16 rn;
295 int standby;
296 int usecount;
297};
298
299struct assign_storage_sccb {
300 struct sccb_header header;
301 u16 rn;
302} __packed;
303
304static unsigned long long rn2addr(u16 rn)
305{
306 return (unsigned long long) (rn - 1) * rzm;
307}
308
309static int do_assign_storage(sclp_cmdw_t cmd, u16 rn)
310{
311 struct assign_storage_sccb *sccb;
312 int rc;
313
314 sccb = (void *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
315 if (!sccb)
316 return -ENOMEM;
317 sccb->header.length = PAGE_SIZE;
318 sccb->rn = rn;
319 rc = do_sync_request(cmd, sccb);
320 if (rc)
321 goto out;
322 switch (sccb->header.response_code) {
323 case 0x0020:
324 case 0x0120:
325 break;
326 default:
675be97a
HC
327 pr_warning("assign storage failed (cmd=0x%08x, "
328 "response=0x%04x, rn=0x%04x)\n", cmd,
329 sccb->header.response_code, rn);
e0bc2495
HC
330 rc = -EIO;
331 break;
332 }
333out:
334 free_page((unsigned long) sccb);
335 return rc;
336}
337
338static int sclp_assign_storage(u16 rn)
339{
340 return do_assign_storage(0x000d0001, rn);
341}
342
343static int sclp_unassign_storage(u16 rn)
344{
345 return do_assign_storage(0x000c0001, rn);
346}
347
348struct attach_storage_sccb {
349 struct sccb_header header;
350 u16 :16;
351 u16 assigned;
352 u32 :32;
353 u32 entries[0];
354} __packed;
355
356static int sclp_attach_storage(u8 id)
357{
358 struct attach_storage_sccb *sccb;
359 int rc;
360 int i;
361
362 sccb = (void *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
363 if (!sccb)
364 return -ENOMEM;
365 sccb->header.length = PAGE_SIZE;
366 rc = do_sync_request(0x00080001 | id << 8, sccb);
367 if (rc)
368 goto out;
369 switch (sccb->header.response_code) {
370 case 0x0020:
371 set_bit(id, sclp_storage_ids);
372 for (i = 0; i < sccb->assigned; i++)
373 sclp_unassign_storage(sccb->entries[i] >> 16);
374 break;
375 default:
376 rc = -EIO;
377 break;
378 }
379out:
380 free_page((unsigned long) sccb);
381 return rc;
382}
383
384static int sclp_mem_change_state(unsigned long start, unsigned long size,
385 int online)
386{
387 struct memory_increment *incr;
388 unsigned long long istart;
389 int rc = 0;
390
391 list_for_each_entry(incr, &sclp_mem_list, list) {
392 istart = rn2addr(incr->rn);
393 if (start + size - 1 < istart)
394 break;
395 if (start > istart + rzm - 1)
396 continue;
397 if (online) {
398 if (incr->usecount++)
399 continue;
400 /*
401 * Don't break the loop if one assign fails. Loop may
402 * be walked again on CANCEL and we can't save
403 * information if state changed before or not.
404 * So continue and increase usecount for all increments.
405 */
406 rc |= sclp_assign_storage(incr->rn);
407 } else {
408 if (--incr->usecount)
409 continue;
410 sclp_unassign_storage(incr->rn);
411 }
412 }
413 return rc ? -EIO : 0;
414}
415
416static int sclp_mem_notifier(struct notifier_block *nb,
417 unsigned long action, void *data)
418{
419 unsigned long start, size;
420 struct memory_notify *arg;
421 unsigned char id;
422 int rc = 0;
423
424 arg = data;
425 start = arg->start_pfn << PAGE_SHIFT;
426 size = arg->nr_pages << PAGE_SHIFT;
427 mutex_lock(&sclp_mem_mutex);
428 for (id = 0; id <= sclp_max_storage_id; id++)
429 if (!test_bit(id, sclp_storage_ids))
430 sclp_attach_storage(id);
431 switch (action) {
432 case MEM_ONLINE:
7e9238fb
GS
433 case MEM_GOING_OFFLINE:
434 case MEM_CANCEL_OFFLINE:
e0bc2495
HC
435 break;
436 case MEM_GOING_ONLINE:
437 rc = sclp_mem_change_state(start, size, 1);
438 break;
439 case MEM_CANCEL_ONLINE:
440 sclp_mem_change_state(start, size, 0);
441 break;
7e9238fb
GS
442 case MEM_OFFLINE:
443 sclp_mem_change_state(start, size, 0);
444 break;
e0bc2495
HC
445 default:
446 rc = -EINVAL;
447 break;
448 }
449 mutex_unlock(&sclp_mem_mutex);
450 return rc ? NOTIFY_BAD : NOTIFY_OK;
451}
452
453static struct notifier_block sclp_mem_nb = {
454 .notifier_call = sclp_mem_notifier,
455};
456
457static void __init add_memory_merged(u16 rn)
458{
459 static u16 first_rn, num;
460 unsigned long long start, size;
461
462 if (rn && first_rn && (first_rn + num == rn)) {
463 num++;
464 return;
465 }
466 if (!first_rn)
467 goto skip_add;
468 start = rn2addr(first_rn);
469 size = (unsigned long long ) num * rzm;
470 if (start >= VMEM_MAX_PHYS)
471 goto skip_add;
472 if (start + size > VMEM_MAX_PHYS)
473 size = VMEM_MAX_PHYS - start;
474 add_memory(0, start, size);
475skip_add:
476 first_rn = rn;
477 num = 1;
478}
479
480static void __init sclp_add_standby_memory(void)
481{
482 struct memory_increment *incr;
483
484 list_for_each_entry(incr, &sclp_mem_list, list)
485 if (incr->standby)
486 add_memory_merged(incr->rn);
487 add_memory_merged(0);
488}
489
490static void __init insert_increment(u16 rn, int standby, int assigned)
491{
492 struct memory_increment *incr, *new_incr;
493 struct list_head *prev;
494 u16 last_rn;
495
496 new_incr = kzalloc(sizeof(*new_incr), GFP_KERNEL);
497 if (!new_incr)
498 return;
499 new_incr->rn = rn;
500 new_incr->standby = standby;
501 last_rn = 0;
502 prev = &sclp_mem_list;
503 list_for_each_entry(incr, &sclp_mem_list, list) {
504 if (assigned && incr->rn > rn)
505 break;
506 if (!assigned && incr->rn - last_rn > 1)
507 break;
508 last_rn = incr->rn;
509 prev = &incr->list;
510 }
511 if (!assigned)
512 new_incr->rn = last_rn + 1;
513 if (new_incr->rn > rnmax) {
514 kfree(new_incr);
515 return;
516 }
517 list_add(&new_incr->list, prev);
518}
519
520struct read_storage_sccb {
521 struct sccb_header header;
522 u16 max_id;
523 u16 assigned;
524 u16 standby;
525 u16 :16;
526 u32 entries[0];
527} __packed;
528
529static int __init sclp_detect_standby_memory(void)
530{
531 struct read_storage_sccb *sccb;
532 int i, id, assigned, rc;
533
534 if (!early_read_info_sccb_valid)
535 return 0;
536 if ((sclp_facilities & 0xe00000000000ULL) != 0xe00000000000ULL)
537 return 0;
538 rc = -ENOMEM;
539 sccb = (void *) __get_free_page(GFP_KERNEL | GFP_DMA);
540 if (!sccb)
541 goto out;
542 assigned = 0;
543 for (id = 0; id <= sclp_max_storage_id; id++) {
544 memset(sccb, 0, PAGE_SIZE);
545 sccb->header.length = PAGE_SIZE;
546 rc = do_sync_request(0x00040001 | id << 8, sccb);
547 if (rc)
548 goto out;
549 switch (sccb->header.response_code) {
550 case 0x0010:
551 set_bit(id, sclp_storage_ids);
552 for (i = 0; i < sccb->assigned; i++) {
553 if (!sccb->entries[i])
554 continue;
555 assigned++;
556 insert_increment(sccb->entries[i] >> 16, 0, 1);
557 }
558 break;
559 case 0x0310:
560 break;
561 case 0x0410:
562 for (i = 0; i < sccb->assigned; i++) {
563 if (!sccb->entries[i])
564 continue;
565 assigned++;
566 insert_increment(sccb->entries[i] >> 16, 1, 1);
567 }
568 break;
569 default:
570 rc = -EIO;
571 break;
572 }
573 if (!rc)
574 sclp_max_storage_id = sccb->max_id;
575 }
576 if (rc || list_empty(&sclp_mem_list))
577 goto out;
578 for (i = 1; i <= rnmax - assigned; i++)
579 insert_increment(0, 1, 0);
580 rc = register_memory_notifier(&sclp_mem_nb);
581 if (rc)
582 goto out;
583 sclp_add_standby_memory();
584out:
585 free_page((unsigned long) sccb);
586 return rc;
587}
588__initcall(sclp_detect_standby_memory);
589
590#endif /* CONFIG_MEMORY_HOTPLUG */
591
4b28a8fe
HC
592/*
593 * Channel path configuration related functions.
594 */
595
596#define SCLP_CMDW_CONFIGURE_CHPATH 0x000f0001
597#define SCLP_CMDW_DECONFIGURE_CHPATH 0x000e0001
598#define SCLP_CMDW_READ_CHPATH_INFORMATION 0x00030001
599
600struct chp_cfg_sccb {
601 struct sccb_header header;
602 u8 ccm;
603 u8 reserved[6];
604 u8 cssid;
605} __attribute__((packed));
606
607static int do_chp_configure(sclp_cmdw_t cmd)
608{
609 struct chp_cfg_sccb *sccb;
610 int rc;
611
612 if (!SCLP_HAS_CHP_RECONFIG)
613 return -EOPNOTSUPP;
614 /* Prepare sccb. */
615 sccb = (struct chp_cfg_sccb *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
616 if (!sccb)
617 return -ENOMEM;
618 sccb->header.length = sizeof(*sccb);
619 rc = do_sync_request(cmd, sccb);
620 if (rc)
621 goto out;
622 switch (sccb->header.response_code) {
623 case 0x0020:
624 case 0x0120:
625 case 0x0440:
626 case 0x0450:
627 break;
628 default:
629 printk(KERN_WARNING TAG "configure channel-path failed "
630 "(cmd=0x%08x, response=0x%04x)\n", cmd,
631 sccb->header.response_code);
632 rc = -EIO;
633 break;
634 }
635out:
636 free_page((unsigned long) sccb);
637 return rc;
638}
639
640/**
641 * sclp_chp_configure - perform configure channel-path sclp command
642 * @chpid: channel-path ID
643 *
644 * Perform configure channel-path command sclp command for specified chpid.
645 * Return 0 after command successfully finished, non-zero otherwise.
646 */
647int sclp_chp_configure(struct chp_id chpid)
648{
649 return do_chp_configure(SCLP_CMDW_CONFIGURE_CHPATH | chpid.id << 8);
650}
651
652/**
653 * sclp_chp_deconfigure - perform deconfigure channel-path sclp command
654 * @chpid: channel-path ID
655 *
656 * Perform deconfigure channel-path command sclp command for specified chpid
657 * and wait for completion. On success return 0. Return non-zero otherwise.
658 */
659int sclp_chp_deconfigure(struct chp_id chpid)
660{
661 return do_chp_configure(SCLP_CMDW_DECONFIGURE_CHPATH | chpid.id << 8);
662}
663
664struct chp_info_sccb {
665 struct sccb_header header;
666 u8 recognized[SCLP_CHP_INFO_MASK_SIZE];
667 u8 standby[SCLP_CHP_INFO_MASK_SIZE];
668 u8 configured[SCLP_CHP_INFO_MASK_SIZE];
669 u8 ccm;
670 u8 reserved[6];
671 u8 cssid;
672} __attribute__((packed));
673
674/**
675 * sclp_chp_read_info - perform read channel-path information sclp command
676 * @info: resulting channel-path information data
677 *
678 * Perform read channel-path information sclp command and wait for completion.
679 * On success, store channel-path information in @info and return 0. Return
680 * non-zero otherwise.
681 */
682int sclp_chp_read_info(struct sclp_chp_info *info)
683{
684 struct chp_info_sccb *sccb;
685 int rc;
686
687 if (!SCLP_HAS_CHP_INFO)
688 return -EOPNOTSUPP;
689 /* Prepare sccb. */
690 sccb = (struct chp_info_sccb *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
691 if (!sccb)
692 return -ENOMEM;
693 sccb->header.length = sizeof(*sccb);
694 rc = do_sync_request(SCLP_CMDW_READ_CHPATH_INFORMATION, sccb);
695 if (rc)
696 goto out;
697 if (sccb->header.response_code != 0x0010) {
698 printk(KERN_WARNING TAG "read channel-path info failed "
699 "(response=0x%04x)\n", sccb->header.response_code);
700 rc = -EIO;
701 goto out;
702 }
703 memcpy(info->recognized, sccb->recognized, SCLP_CHP_INFO_MASK_SIZE);
704 memcpy(info->standby, sccb->standby, SCLP_CHP_INFO_MASK_SIZE);
705 memcpy(info->configured, sccb->configured, SCLP_CHP_INFO_MASK_SIZE);
706out:
707 free_page((unsigned long) sccb);
708 return rc;
709}