2 * drivers/s390/char/sclp_cmd.c
4 * Copyright IBM Corp. 2007
5 * Author(s): Heiko Carstens <heiko.carstens@de.ibm.com>,
6 * Peter Oberparleiter <peter.oberparleiter@de.ibm.com>
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>
15 #include <linux/mmzone.h>
16 #include <linux/memory.h>
17 #include <asm/chpid.h>
21 #define TAG "sclp_cmd: "
23 #define SCLP_CMDW_READ_SCP_INFO 0x00020001
24 #define SCLP_CMDW_READ_SCP_INFO_FORCED 0x00120001
26 struct read_info_sccb
{
27 struct sccb_header header
; /* 0-7 */
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 */
36 u8 _reserved3
[91 - 85]; /* 85-90 */
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
)));
44 static struct read_info_sccb __initdata early_read_info_sccb
;
45 static int __initdata early_read_info_sccb_valid
;
49 static unsigned long long rzm
;
50 static unsigned long long rnmax
;
52 static int __init
sclp_cmd_sync_early(sclp_cmdw_t cmd
, void *sccb
)
57 rc
= sclp_service_call(cmd
, sccb
);
60 __load_psw_mask(PSW_BASE_BITS
| PSW_MASK_EXT
|
61 PSW_MASK_WAIT
| PSW_DEFAULT_KEY
);
64 /* Contents of the sccb might have changed. */
66 __ctl_clear_bit(0, 9);
70 static void __init
sclp_read_info_early(void)
74 struct read_info_sccb
*sccb
;
75 sclp_cmdw_t commands
[] = {SCLP_CMDW_READ_SCP_INFO_FORCED
,
76 SCLP_CMDW_READ_SCP_INFO
};
78 sccb
= &early_read_info_sccb
;
79 for (i
= 0; i
< ARRAY_SIZE(commands
); i
++) {
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
);
89 if (sccb
->header
.response_code
== 0x10) {
90 early_read_info_sccb_valid
= 1;
93 if (sccb
->header
.response_code
!= 0x1f0)
98 void __init
sclp_facilities_detect(void)
100 struct read_info_sccb
*sccb
;
102 sclp_read_info_early();
103 if (!early_read_info_sccb_valid
)
106 sccb
= &early_read_info_sccb
;
107 sclp_facilities
= sccb
->facilities
;
108 sclp_fac84
= sccb
->fac84
;
109 rnmax
= sccb
->rnmax
? sccb
->rnmax
: sccb
->rnmax2
;
110 rzm
= sccb
->rnsize
? sccb
->rnsize
: sccb
->rnsize2
;
114 unsigned long long sclp_get_rnmax(void)
119 unsigned long long sclp_get_rzm(void)
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.
128 void __init
sclp_get_ipl_info(struct sclp_ipl_info
*info
)
130 struct read_info_sccb
*sccb
;
132 if (!early_read_info_sccb_valid
)
134 sccb
= &early_read_info_sccb
;
136 if (sccb
->flags
& 0x2)
138 memcpy(&info
->loadparm
, &sccb
->loadparm
, LOADPARM_LEN
);
141 static void sclp_sync_callback(struct sclp_req
*req
, void *data
)
143 struct completion
*completion
= data
;
145 complete(completion
);
148 static int do_sync_request(sclp_cmdw_t cmd
, void *sccb
)
150 struct completion completion
;
151 struct sclp_req
*request
;
154 request
= kzalloc(sizeof(*request
), GFP_KERNEL
);
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
);
164 /* Perform sclp request. */
165 rc
= sclp_add_request(request
);
168 wait_for_completion(&completion
);
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
);
182 * CPU configuration related functions.
185 #define SCLP_CMDW_READ_CPU_INFO 0x00010001
186 #define SCLP_CMDW_CONFIGURE_CPU 0x00110001
187 #define SCLP_CMDW_DECONFIGURE_CPU 0x00100001
189 struct read_cpu_info_sccb
{
190 struct sccb_header header
;
192 u16 offset_configured
;
195 u8 reserved
[4096 - 16];
196 } __attribute__((packed
, aligned(PAGE_SIZE
)));
198 static void sclp_fill_cpu_info(struct sclp_cpu_info
*info
,
199 struct read_cpu_info_sccb
*sccb
)
201 char *page
= (char *) sccb
;
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
));
212 int sclp_get_cpu_info(struct sclp_cpu_info
*info
)
215 struct read_cpu_info_sccb
*sccb
;
217 if (!SCLP_HAS_CPU_INFO
)
219 sccb
= (void *) get_zeroed_page(GFP_KERNEL
| GFP_DMA
);
222 sccb
->header
.length
= sizeof(*sccb
);
223 rc
= do_sync_request(SCLP_CMDW_READ_CPU_INFO
, sccb
);
226 if (sccb
->header
.response_code
!= 0x0010) {
227 printk(KERN_WARNING TAG
"readcpuinfo failed "
228 "(response=0x%04x)\n", sccb
->header
.response_code
);
232 sclp_fill_cpu_info(info
, sccb
);
234 free_page((unsigned long) sccb
);
238 struct cpu_configure_sccb
{
239 struct sccb_header header
;
240 } __attribute__((packed
, aligned(8)));
242 static int do_cpu_configure(sclp_cmdw_t cmd
)
244 struct cpu_configure_sccb
*sccb
;
247 if (!SCLP_HAS_CPU_RECONFIG
)
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.
253 sccb
= kzalloc(sizeof(*sccb
), GFP_KERNEL
| GFP_DMA
);
256 sccb
->header
.length
= sizeof(*sccb
);
257 rc
= do_sync_request(cmd
, sccb
);
260 switch (sccb
->header
.response_code
) {
265 printk(KERN_WARNING TAG
"configure cpu failed (cmd=0x%08x, "
266 "response=0x%04x)\n", cmd
, sccb
->header
.response_code
);
275 int sclp_cpu_configure(u8 cpu
)
277 return do_cpu_configure(SCLP_CMDW_CONFIGURE_CPU
| cpu
<< 8);
280 int sclp_cpu_deconfigure(u8 cpu
)
282 return do_cpu_configure(SCLP_CMDW_DECONFIGURE_CPU
| cpu
<< 8);
285 #ifdef CONFIG_MEMORY_HOTPLUG
287 static DEFINE_MUTEX(sclp_mem_mutex
);
288 static LIST_HEAD(sclp_mem_list
);
289 static u8 sclp_max_storage_id
;
290 static unsigned long sclp_storage_ids
[256 / BITS_PER_LONG
];
292 struct memory_increment
{
293 struct list_head list
;
299 struct assign_storage_sccb
{
300 struct sccb_header header
;
304 static unsigned long long rn2addr(u16 rn
)
306 return (unsigned long long) (rn
- 1) * rzm
;
309 static int do_assign_storage(sclp_cmdw_t cmd
, u16 rn
)
311 struct assign_storage_sccb
*sccb
;
314 sccb
= (void *) get_zeroed_page(GFP_KERNEL
| GFP_DMA
);
317 sccb
->header
.length
= PAGE_SIZE
;
319 rc
= do_sync_request(cmd
, sccb
);
322 switch (sccb
->header
.response_code
) {
331 free_page((unsigned long) sccb
);
335 static int sclp_assign_storage(u16 rn
)
337 return do_assign_storage(0x000d0001, rn
);
340 static int sclp_unassign_storage(u16 rn
)
342 return do_assign_storage(0x000c0001, rn
);
345 struct attach_storage_sccb
{
346 struct sccb_header header
;
353 static int sclp_attach_storage(u8 id
)
355 struct attach_storage_sccb
*sccb
;
359 sccb
= (void *) get_zeroed_page(GFP_KERNEL
| GFP_DMA
);
362 sccb
->header
.length
= PAGE_SIZE
;
363 rc
= do_sync_request(0x00080001 | id
<< 8, sccb
);
366 switch (sccb
->header
.response_code
) {
368 set_bit(id
, sclp_storage_ids
);
369 for (i
= 0; i
< sccb
->assigned
; i
++)
370 sclp_unassign_storage(sccb
->entries
[i
] >> 16);
377 free_page((unsigned long) sccb
);
381 static int sclp_mem_change_state(unsigned long start
, unsigned long size
,
384 struct memory_increment
*incr
;
385 unsigned long long istart
;
388 list_for_each_entry(incr
, &sclp_mem_list
, list
) {
389 istart
= rn2addr(incr
->rn
);
390 if (start
+ size
- 1 < istart
)
392 if (start
> istart
+ rzm
- 1)
395 if (incr
->usecount
++)
398 * Don't break the loop if one assign fails. Loop may
399 * be walked again on CANCEL and we can't save
400 * information if state changed before or not.
401 * So continue and increase usecount for all increments.
403 rc
|= sclp_assign_storage(incr
->rn
);
405 if (--incr
->usecount
)
407 sclp_unassign_storage(incr
->rn
);
410 return rc
? -EIO
: 0;
413 static int sclp_mem_notifier(struct notifier_block
*nb
,
414 unsigned long action
, void *data
)
416 unsigned long start
, size
;
417 struct memory_notify
*arg
;
422 start
= arg
->start_pfn
<< PAGE_SHIFT
;
423 size
= arg
->nr_pages
<< PAGE_SHIFT
;
424 mutex_lock(&sclp_mem_mutex
);
425 for (id
= 0; id
<= sclp_max_storage_id
; id
++)
426 if (!test_bit(id
, sclp_storage_ids
))
427 sclp_attach_storage(id
);
431 case MEM_GOING_ONLINE
:
432 rc
= sclp_mem_change_state(start
, size
, 1);
434 case MEM_CANCEL_ONLINE
:
435 sclp_mem_change_state(start
, size
, 0);
441 mutex_unlock(&sclp_mem_mutex
);
442 return rc
? NOTIFY_BAD
: NOTIFY_OK
;
445 static struct notifier_block sclp_mem_nb
= {
446 .notifier_call
= sclp_mem_notifier
,
449 static void __init
add_memory_merged(u16 rn
)
451 static u16 first_rn
, num
;
452 unsigned long long start
, size
;
454 if (rn
&& first_rn
&& (first_rn
+ num
== rn
)) {
460 start
= rn2addr(first_rn
);
461 size
= (unsigned long long ) num
* rzm
;
462 if (start
>= VMEM_MAX_PHYS
)
464 if (start
+ size
> VMEM_MAX_PHYS
)
465 size
= VMEM_MAX_PHYS
- start
;
466 add_memory(0, start
, size
);
472 static void __init
sclp_add_standby_memory(void)
474 struct memory_increment
*incr
;
476 list_for_each_entry(incr
, &sclp_mem_list
, list
)
478 add_memory_merged(incr
->rn
);
479 add_memory_merged(0);
482 static void __init
insert_increment(u16 rn
, int standby
, int assigned
)
484 struct memory_increment
*incr
, *new_incr
;
485 struct list_head
*prev
;
488 new_incr
= kzalloc(sizeof(*new_incr
), GFP_KERNEL
);
492 new_incr
->standby
= standby
;
494 prev
= &sclp_mem_list
;
495 list_for_each_entry(incr
, &sclp_mem_list
, list
) {
496 if (assigned
&& incr
->rn
> rn
)
498 if (!assigned
&& incr
->rn
- last_rn
> 1)
504 new_incr
->rn
= last_rn
+ 1;
505 if (new_incr
->rn
> rnmax
) {
509 list_add(&new_incr
->list
, prev
);
512 struct read_storage_sccb
{
513 struct sccb_header header
;
521 static int __init
sclp_detect_standby_memory(void)
523 struct read_storage_sccb
*sccb
;
524 int i
, id
, assigned
, rc
;
526 if (!early_read_info_sccb_valid
)
528 if ((sclp_facilities
& 0xe00000000000ULL
) != 0xe00000000000ULL
)
531 sccb
= (void *) __get_free_page(GFP_KERNEL
| GFP_DMA
);
535 for (id
= 0; id
<= sclp_max_storage_id
; id
++) {
536 memset(sccb
, 0, PAGE_SIZE
);
537 sccb
->header
.length
= PAGE_SIZE
;
538 rc
= do_sync_request(0x00040001 | id
<< 8, sccb
);
541 switch (sccb
->header
.response_code
) {
543 set_bit(id
, sclp_storage_ids
);
544 for (i
= 0; i
< sccb
->assigned
; i
++) {
545 if (!sccb
->entries
[i
])
548 insert_increment(sccb
->entries
[i
] >> 16, 0, 1);
554 for (i
= 0; i
< sccb
->assigned
; i
++) {
555 if (!sccb
->entries
[i
])
558 insert_increment(sccb
->entries
[i
] >> 16, 1, 1);
566 sclp_max_storage_id
= sccb
->max_id
;
568 if (rc
|| list_empty(&sclp_mem_list
))
570 for (i
= 1; i
<= rnmax
- assigned
; i
++)
571 insert_increment(0, 1, 0);
572 rc
= register_memory_notifier(&sclp_mem_nb
);
575 sclp_add_standby_memory();
577 free_page((unsigned long) sccb
);
580 __initcall(sclp_detect_standby_memory
);
582 #endif /* CONFIG_MEMORY_HOTPLUG */
585 * Channel path configuration related functions.
588 #define SCLP_CMDW_CONFIGURE_CHPATH 0x000f0001
589 #define SCLP_CMDW_DECONFIGURE_CHPATH 0x000e0001
590 #define SCLP_CMDW_READ_CHPATH_INFORMATION 0x00030001
592 struct chp_cfg_sccb
{
593 struct sccb_header header
;
597 } __attribute__((packed
));
599 static int do_chp_configure(sclp_cmdw_t cmd
)
601 struct chp_cfg_sccb
*sccb
;
604 if (!SCLP_HAS_CHP_RECONFIG
)
607 sccb
= (struct chp_cfg_sccb
*) get_zeroed_page(GFP_KERNEL
| GFP_DMA
);
610 sccb
->header
.length
= sizeof(*sccb
);
611 rc
= do_sync_request(cmd
, sccb
);
614 switch (sccb
->header
.response_code
) {
621 printk(KERN_WARNING TAG
"configure channel-path failed "
622 "(cmd=0x%08x, response=0x%04x)\n", cmd
,
623 sccb
->header
.response_code
);
628 free_page((unsigned long) sccb
);
633 * sclp_chp_configure - perform configure channel-path sclp command
634 * @chpid: channel-path ID
636 * Perform configure channel-path command sclp command for specified chpid.
637 * Return 0 after command successfully finished, non-zero otherwise.
639 int sclp_chp_configure(struct chp_id chpid
)
641 return do_chp_configure(SCLP_CMDW_CONFIGURE_CHPATH
| chpid
.id
<< 8);
645 * sclp_chp_deconfigure - perform deconfigure channel-path sclp command
646 * @chpid: channel-path ID
648 * Perform deconfigure channel-path command sclp command for specified chpid
649 * and wait for completion. On success return 0. Return non-zero otherwise.
651 int sclp_chp_deconfigure(struct chp_id chpid
)
653 return do_chp_configure(SCLP_CMDW_DECONFIGURE_CHPATH
| chpid
.id
<< 8);
656 struct chp_info_sccb
{
657 struct sccb_header header
;
658 u8 recognized
[SCLP_CHP_INFO_MASK_SIZE
];
659 u8 standby
[SCLP_CHP_INFO_MASK_SIZE
];
660 u8 configured
[SCLP_CHP_INFO_MASK_SIZE
];
664 } __attribute__((packed
));
667 * sclp_chp_read_info - perform read channel-path information sclp command
668 * @info: resulting channel-path information data
670 * Perform read channel-path information sclp command and wait for completion.
671 * On success, store channel-path information in @info and return 0. Return
672 * non-zero otherwise.
674 int sclp_chp_read_info(struct sclp_chp_info
*info
)
676 struct chp_info_sccb
*sccb
;
679 if (!SCLP_HAS_CHP_INFO
)
682 sccb
= (struct chp_info_sccb
*) get_zeroed_page(GFP_KERNEL
| GFP_DMA
);
685 sccb
->header
.length
= sizeof(*sccb
);
686 rc
= do_sync_request(SCLP_CMDW_READ_CHPATH_INFORMATION
, sccb
);
689 if (sccb
->header
.response_code
!= 0x0010) {
690 printk(KERN_WARNING TAG
"read channel-path info failed "
691 "(response=0x%04x)\n", sccb
->header
.response_code
);
695 memcpy(info
->recognized
, sccb
->recognized
, SCLP_CHP_INFO_MASK_SIZE
);
696 memcpy(info
->standby
, sccb
->standby
, SCLP_CHP_INFO_MASK_SIZE
);
697 memcpy(info
->configured
, sccb
->configured
, SCLP_CHP_INFO_MASK_SIZE
);
699 free_page((unsigned long) sccb
);