s390/mm: Fix crst upgrade of mmap with MAP_FIXED
[deliverable/linux.git] / drivers / s390 / char / sclp_cmd.c
CommitLineData
08d07968 1/*
7441b062 2 * Copyright IBM Corp. 2007,2012
08d07968 3 *
03997904
GS
4 * Author(s): Heiko Carstens <heiko.carstens@de.ibm.com>,
5 * Peter Oberparleiter <peter.oberparleiter@de.ibm.com>
08d07968
HC
6 */
7
b3ff088b
MS
8#define KMSG_COMPONENT "sclp_cmd"
9#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
10
08d07968
HC
11#include <linux/completion.h>
12#include <linux/init.h>
13#include <linux/errno.h>
03997904 14#include <linux/err.h>
7441b062 15#include <linux/export.h>
08d07968
HC
16#include <linux/slab.h>
17#include <linux/string.h>
e0bc2495
HC
18#include <linux/mm.h>
19#include <linux/mmzone.h>
20#include <linux/memory.h>
1526bf9c 21#include <linux/module.h>
03997904 22#include <linux/platform_device.h>
6b70a920 23#include <asm/ctl_reg.h>
4b28a8fe 24#include <asm/chpid.h>
23d75d9c 25#include <asm/setup.h>
6b70a920
HC
26#include <asm/page.h>
27#include <asm/sclp.h>
08d07968 28
b3ff088b 29#include "sclp.h"
08d07968
HC
30
31#define SCLP_CMDW_READ_SCP_INFO 0x00020001
32#define SCLP_CMDW_READ_SCP_INFO_FORCED 0x00120001
33
34struct read_info_sccb {
35 struct sccb_header header; /* 0-7 */
36 u16 rnmax; /* 8-9 */
37 u8 rnsize; /* 10 */
38 u8 _reserved0[24 - 11]; /* 11-15 */
39 u8 loadparm[8]; /* 24-31 */
40 u8 _reserved1[48 - 32]; /* 32-47 */
41 u64 facilities; /* 48-55 */
42 u8 _reserved2[84 - 56]; /* 56-83 */
43 u8 fac84; /* 84 */
1526bf9c
CB
44 u8 fac85; /* 85 */
45 u8 _reserved3[91 - 86]; /* 86-90 */
08d07968
HC
46 u8 flags; /* 91 */
47 u8 _reserved4[100 - 92]; /* 92-99 */
48 u32 rnsize2; /* 100-103 */
49 u64 rnmax2; /* 104-111 */
50 u8 _reserved5[4096 - 112]; /* 112-4095 */
51} __attribute__((packed, aligned(PAGE_SIZE)));
52
cd183459 53static struct init_sccb __initdata early_event_mask_sccb __aligned(PAGE_SIZE);
08d07968
HC
54static struct read_info_sccb __initdata early_read_info_sccb;
55static int __initdata early_read_info_sccb_valid;
56
57u64 sclp_facilities;
58static u8 sclp_fac84;
1526bf9c 59static u8 sclp_fac85;
e0bc2495
HC
60static unsigned long long rzm;
61static unsigned long long rnmax;
08d07968
HC
62
63static int __init sclp_cmd_sync_early(sclp_cmdw_t cmd, void *sccb)
64{
65 int rc;
66
67 __ctl_set_bit(0, 9);
68 rc = sclp_service_call(cmd, sccb);
69 if (rc)
70 goto out;
b50511e4
MS
71 __load_psw_mask(PSW_DEFAULT_KEY | PSW_MASK_BASE | PSW_MASK_EA |
72 PSW_MASK_BA | PSW_MASK_EXT | PSW_MASK_WAIT);
08d07968
HC
73 local_irq_disable();
74out:
75 /* Contents of the sccb might have changed. */
76 barrier();
77 __ctl_clear_bit(0, 9);
78 return rc;
79}
80
23d17421 81static void __init sclp_read_info_early(void)
08d07968
HC
82{
83 int rc;
84 int i;
85 struct read_info_sccb *sccb;
86 sclp_cmdw_t commands[] = {SCLP_CMDW_READ_SCP_INFO_FORCED,
87 SCLP_CMDW_READ_SCP_INFO};
88
89 sccb = &early_read_info_sccb;
90 for (i = 0; i < ARRAY_SIZE(commands); i++) {
91 do {
92 memset(sccb, 0, sizeof(*sccb));
93 sccb->header.length = sizeof(*sccb);
cb9d7160 94 sccb->header.function_code = 0x80;
08d07968
HC
95 sccb->header.control_mask[2] = 0x80;
96 rc = sclp_cmd_sync_early(commands[i], sccb);
97 } while (rc == -EBUSY);
98
99 if (rc)
100 break;
101 if (sccb->header.response_code == 0x10) {
102 early_read_info_sccb_valid = 1;
103 break;
104 }
105 if (sccb->header.response_code != 0x1f0)
106 break;
107 }
108}
109
cd183459
HG
110static void __init sclp_event_mask_early(void)
111{
112 struct init_sccb *sccb = &early_event_mask_sccb;
113 int rc;
114
115 do {
116 memset(sccb, 0, sizeof(*sccb));
117 sccb->header.length = sizeof(*sccb);
118 sccb->mask_length = sizeof(sccb_mask_t);
119 rc = sclp_cmd_sync_early(SCLP_CMDW_WRITE_EVENT_MASK, sccb);
120 } while (rc == -EBUSY);
121}
122
08d07968
HC
123void __init sclp_facilities_detect(void)
124{
08d07968
HC
125 struct read_info_sccb *sccb;
126
23d17421 127 sclp_read_info_early();
08d07968 128 if (!early_read_info_sccb_valid)
23d17421
HC
129 return;
130
08d07968 131 sccb = &early_read_info_sccb;
23d17421
HC
132 sclp_facilities = sccb->facilities;
133 sclp_fac84 = sccb->fac84;
1526bf9c 134 sclp_fac85 = sccb->fac85;
e0bc2495
HC
135 rnmax = sccb->rnmax ? sccb->rnmax : sccb->rnmax2;
136 rzm = sccb->rnsize ? sccb->rnsize : sccb->rnsize2;
137 rzm <<= 20;
cd183459
HG
138
139 sclp_event_mask_early();
140}
141
142bool __init sclp_has_linemode(void)
143{
144 struct init_sccb *sccb = &early_event_mask_sccb;
145
146 if (sccb->header.response_code != 0x20)
147 return 0;
148 if (sccb->sclp_send_mask & (EVTYP_MSG_MASK | EVTYP_PMSGCMD_MASK))
149 return 1;
150 return 0;
151}
152
153bool __init sclp_has_vt220(void)
154{
155 struct init_sccb *sccb = &early_event_mask_sccb;
156
157 if (sccb->header.response_code != 0x20)
158 return 0;
159 if (sccb->sclp_send_mask & EVTYP_VT220MSG_MASK)
160 return 1;
161 return 0;
23d17421
HC
162}
163
164unsigned long long sclp_get_rnmax(void)
165{
166 return rnmax;
167}
168
169unsigned long long sclp_get_rzm(void)
170{
171 return rzm;
08d07968
HC
172}
173
1526bf9c
CB
174u8 sclp_get_fac85(void)
175{
176 return sclp_fac85;
177}
178EXPORT_SYMBOL_GPL(sclp_get_fac85);
179
08d07968 180/*
23d17421
HC
181 * This function will be called after sclp_facilities_detect(), which gets
182 * called from early.c code. Therefore the sccb should have valid contents.
08d07968
HC
183 */
184void __init sclp_get_ipl_info(struct sclp_ipl_info *info)
185{
186 struct read_info_sccb *sccb;
187
188 if (!early_read_info_sccb_valid)
189 return;
190 sccb = &early_read_info_sccb;
191 info->is_valid = 1;
192 if (sccb->flags & 0x2)
193 info->has_dump = 1;
194 memcpy(&info->loadparm, &sccb->loadparm, LOADPARM_LEN);
195}
196
197static void sclp_sync_callback(struct sclp_req *req, void *data)
198{
199 struct completion *completion = data;
200
201 complete(completion);
202}
203
204static int do_sync_request(sclp_cmdw_t cmd, void *sccb)
205{
206 struct completion completion;
207 struct sclp_req *request;
208 int rc;
209
210 request = kzalloc(sizeof(*request), GFP_KERNEL);
211 if (!request)
212 return -ENOMEM;
213 request->command = cmd;
214 request->sccb = sccb;
215 request->status = SCLP_REQ_FILLED;
216 request->callback = sclp_sync_callback;
217 request->callback_data = &completion;
218 init_completion(&completion);
219
220 /* Perform sclp request. */
221 rc = sclp_add_request(request);
222 if (rc)
223 goto out;
224 wait_for_completion(&completion);
225
226 /* Check response. */
227 if (request->status != SCLP_REQ_DONE) {
b3ff088b
MS
228 pr_warning("sync request failed (cmd=0x%08x, "
229 "status=0x%02x)\n", cmd, request->status);
08d07968
HC
230 rc = -EIO;
231 }
232out:
233 kfree(request);
234 return rc;
235}
236
237/*
238 * CPU configuration related functions.
239 */
240
241#define SCLP_CMDW_READ_CPU_INFO 0x00010001
242#define SCLP_CMDW_CONFIGURE_CPU 0x00110001
243#define SCLP_CMDW_DECONFIGURE_CPU 0x00100001
244
245struct read_cpu_info_sccb {
246 struct sccb_header header;
247 u16 nr_configured;
248 u16 offset_configured;
249 u16 nr_standby;
250 u16 offset_standby;
251 u8 reserved[4096 - 16];
252} __attribute__((packed, aligned(PAGE_SIZE)));
253
08d07968
HC
254static void sclp_fill_cpu_info(struct sclp_cpu_info *info,
255 struct read_cpu_info_sccb *sccb)
256{
257 char *page = (char *) sccb;
258
259 memset(info, 0, sizeof(*info));
260 info->configured = sccb->nr_configured;
261 info->standby = sccb->nr_standby;
262 info->combined = sccb->nr_configured + sccb->nr_standby;
263 info->has_cpu_type = sclp_fac84 & 0x1;
264 memcpy(&info->cpu, page + sccb->offset_configured,
265 info->combined * sizeof(struct sclp_cpu_entry));
266}
267
48483b32 268int sclp_get_cpu_info(struct sclp_cpu_info *info)
08d07968
HC
269{
270 int rc;
271 struct read_cpu_info_sccb *sccb;
272
273 if (!SCLP_HAS_CPU_INFO)
274 return -EOPNOTSUPP;
48483b32 275 sccb = (void *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
08d07968
HC
276 if (!sccb)
277 return -ENOMEM;
08d07968
HC
278 sccb->header.length = sizeof(*sccb);
279 rc = do_sync_request(SCLP_CMDW_READ_CPU_INFO, sccb);
280 if (rc)
281 goto out;
282 if (sccb->header.response_code != 0x0010) {
b3ff088b
MS
283 pr_warning("readcpuinfo failed (response=0x%04x)\n",
284 sccb->header.response_code);
08d07968
HC
285 rc = -EIO;
286 goto out;
287 }
288 sclp_fill_cpu_info(info, sccb);
289out:
290 free_page((unsigned long) sccb);
291 return rc;
292}
293
08d07968
HC
294struct cpu_configure_sccb {
295 struct sccb_header header;
296} __attribute__((packed, aligned(8)));
297
298static int do_cpu_configure(sclp_cmdw_t cmd)
299{
300 struct cpu_configure_sccb *sccb;
301 int rc;
302
303 if (!SCLP_HAS_CPU_RECONFIG)
304 return -EOPNOTSUPP;
305 /*
306 * This is not going to cross a page boundary since we force
307 * kmalloc to have a minimum alignment of 8 bytes on s390.
308 */
309 sccb = kzalloc(sizeof(*sccb), GFP_KERNEL | GFP_DMA);
310 if (!sccb)
311 return -ENOMEM;
312 sccb->header.length = sizeof(*sccb);
313 rc = do_sync_request(cmd, sccb);
314 if (rc)
315 goto out;
316 switch (sccb->header.response_code) {
317 case 0x0020:
318 case 0x0120:
319 break;
320 default:
b3ff088b
MS
321 pr_warning("configure cpu failed (cmd=0x%08x, "
322 "response=0x%04x)\n", cmd,
323 sccb->header.response_code);
08d07968
HC
324 rc = -EIO;
325 break;
326 }
327out:
328 kfree(sccb);
329 return rc;
330}
331
332int sclp_cpu_configure(u8 cpu)
333{
334 return do_cpu_configure(SCLP_CMDW_CONFIGURE_CPU | cpu << 8);
335}
336
337int sclp_cpu_deconfigure(u8 cpu)
338{
339 return do_cpu_configure(SCLP_CMDW_DECONFIGURE_CPU | cpu << 8);
340}
4b28a8fe 341
e0bc2495
HC
342#ifdef CONFIG_MEMORY_HOTPLUG
343
344static DEFINE_MUTEX(sclp_mem_mutex);
345static LIST_HEAD(sclp_mem_list);
346static u8 sclp_max_storage_id;
347static unsigned long sclp_storage_ids[256 / BITS_PER_LONG];
03997904 348static int sclp_mem_state_changed;
e0bc2495
HC
349
350struct memory_increment {
351 struct list_head list;
352 u16 rn;
353 int standby;
354 int usecount;
355};
356
357struct assign_storage_sccb {
358 struct sccb_header header;
359 u16 rn;
360} __packed;
361
9c95258c
HC
362int arch_get_memory_phys_device(unsigned long start_pfn)
363{
364 if (!rzm)
365 return 0;
366 return PFN_PHYS(start_pfn) >> ilog2(rzm);
367}
368
e0bc2495
HC
369static unsigned long long rn2addr(u16 rn)
370{
371 return (unsigned long long) (rn - 1) * rzm;
372}
373
374static int do_assign_storage(sclp_cmdw_t cmd, u16 rn)
375{
376 struct assign_storage_sccb *sccb;
377 int rc;
378
379 sccb = (void *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
380 if (!sccb)
381 return -ENOMEM;
382 sccb->header.length = PAGE_SIZE;
383 sccb->rn = rn;
384 rc = do_sync_request(cmd, sccb);
385 if (rc)
386 goto out;
387 switch (sccb->header.response_code) {
388 case 0x0020:
389 case 0x0120:
390 break;
391 default:
675be97a
HC
392 pr_warning("assign storage failed (cmd=0x%08x, "
393 "response=0x%04x, rn=0x%04x)\n", cmd,
394 sccb->header.response_code, rn);
e0bc2495
HC
395 rc = -EIO;
396 break;
397 }
398out:
399 free_page((unsigned long) sccb);
400 return rc;
401}
402
403static int sclp_assign_storage(u16 rn)
404{
6b70a920 405 unsigned long long start;
0cd2f620
HC
406 int rc;
407
408 rc = do_assign_storage(0x000d0001, rn);
409 if (rc)
6b70a920
HC
410 return rc;
411 start = rn2addr(rn);
412 storage_key_init_range(start, start + rzm);
413 return 0;
e0bc2495
HC
414}
415
416static int sclp_unassign_storage(u16 rn)
417{
418 return do_assign_storage(0x000c0001, rn);
419}
420
421struct attach_storage_sccb {
422 struct sccb_header header;
423 u16 :16;
424 u16 assigned;
425 u32 :32;
426 u32 entries[0];
427} __packed;
428
429static int sclp_attach_storage(u8 id)
430{
431 struct attach_storage_sccb *sccb;
432 int rc;
433 int i;
434
435 sccb = (void *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
436 if (!sccb)
437 return -ENOMEM;
438 sccb->header.length = PAGE_SIZE;
439 rc = do_sync_request(0x00080001 | id << 8, sccb);
440 if (rc)
441 goto out;
442 switch (sccb->header.response_code) {
443 case 0x0020:
444 set_bit(id, sclp_storage_ids);
8adb4ca3
HC
445 for (i = 0; i < sccb->assigned; i++) {
446 if (sccb->entries[i])
447 sclp_unassign_storage(sccb->entries[i] >> 16);
448 }
e0bc2495
HC
449 break;
450 default:
451 rc = -EIO;
452 break;
453 }
454out:
455 free_page((unsigned long) sccb);
456 return rc;
457}
458
459static int sclp_mem_change_state(unsigned long start, unsigned long size,
460 int online)
461{
462 struct memory_increment *incr;
463 unsigned long long istart;
464 int rc = 0;
465
466 list_for_each_entry(incr, &sclp_mem_list, list) {
467 istart = rn2addr(incr->rn);
468 if (start + size - 1 < istart)
469 break;
470 if (start > istart + rzm - 1)
471 continue;
472 if (online) {
473 if (incr->usecount++)
474 continue;
475 /*
476 * Don't break the loop if one assign fails. Loop may
477 * be walked again on CANCEL and we can't save
478 * information if state changed before or not.
479 * So continue and increase usecount for all increments.
480 */
481 rc |= sclp_assign_storage(incr->rn);
482 } else {
483 if (--incr->usecount)
484 continue;
485 sclp_unassign_storage(incr->rn);
486 }
487 }
488 return rc ? -EIO : 0;
489}
490
491static int sclp_mem_notifier(struct notifier_block *nb,
492 unsigned long action, void *data)
493{
494 unsigned long start, size;
495 struct memory_notify *arg;
496 unsigned char id;
497 int rc = 0;
498
499 arg = data;
500 start = arg->start_pfn << PAGE_SHIFT;
501 size = arg->nr_pages << PAGE_SHIFT;
502 mutex_lock(&sclp_mem_mutex);
fc89db4b
AM
503 for_each_clear_bit(id, sclp_storage_ids, sclp_max_storage_id + 1)
504 sclp_attach_storage(id);
e0bc2495
HC
505 switch (action) {
506 case MEM_ONLINE:
7e9238fb
GS
507 case MEM_GOING_OFFLINE:
508 case MEM_CANCEL_OFFLINE:
e0bc2495
HC
509 break;
510 case MEM_GOING_ONLINE:
511 rc = sclp_mem_change_state(start, size, 1);
512 break;
513 case MEM_CANCEL_ONLINE:
514 sclp_mem_change_state(start, size, 0);
515 break;
7e9238fb
GS
516 case MEM_OFFLINE:
517 sclp_mem_change_state(start, size, 0);
518 break;
e0bc2495
HC
519 default:
520 rc = -EINVAL;
521 break;
522 }
03997904
GS
523 if (!rc)
524 sclp_mem_state_changed = 1;
e0bc2495
HC
525 mutex_unlock(&sclp_mem_mutex);
526 return rc ? NOTIFY_BAD : NOTIFY_OK;
527}
528
529static struct notifier_block sclp_mem_nb = {
530 .notifier_call = sclp_mem_notifier,
531};
532
533static void __init add_memory_merged(u16 rn)
534{
535 static u16 first_rn, num;
536 unsigned long long start, size;
537
538 if (rn && first_rn && (first_rn + num == rn)) {
539 num++;
540 return;
541 }
542 if (!first_rn)
543 goto skip_add;
544 start = rn2addr(first_rn);
545 size = (unsigned long long ) num * rzm;
546 if (start >= VMEM_MAX_PHYS)
547 goto skip_add;
548 if (start + size > VMEM_MAX_PHYS)
549 size = VMEM_MAX_PHYS - start;
23d75d9c
HC
550 if (memory_end_set && (start >= memory_end))
551 goto skip_add;
552 if (memory_end_set && (start + size > memory_end))
553 size = memory_end - start;
e0bc2495
HC
554 add_memory(0, start, size);
555skip_add:
556 first_rn = rn;
557 num = 1;
558}
559
560static void __init sclp_add_standby_memory(void)
561{
562 struct memory_increment *incr;
563
564 list_for_each_entry(incr, &sclp_mem_list, list)
565 if (incr->standby)
566 add_memory_merged(incr->rn);
567 add_memory_merged(0);
568}
569
570static void __init insert_increment(u16 rn, int standby, int assigned)
571{
572 struct memory_increment *incr, *new_incr;
573 struct list_head *prev;
574 u16 last_rn;
575
576 new_incr = kzalloc(sizeof(*new_incr), GFP_KERNEL);
577 if (!new_incr)
578 return;
579 new_incr->rn = rn;
580 new_incr->standby = standby;
fdb1bb15
HC
581 if (!standby)
582 new_incr->usecount = 1;
e0bc2495
HC
583 last_rn = 0;
584 prev = &sclp_mem_list;
585 list_for_each_entry(incr, &sclp_mem_list, list) {
586 if (assigned && incr->rn > rn)
587 break;
588 if (!assigned && incr->rn - last_rn > 1)
589 break;
590 last_rn = incr->rn;
591 prev = &incr->list;
592 }
593 if (!assigned)
594 new_incr->rn = last_rn + 1;
595 if (new_incr->rn > rnmax) {
596 kfree(new_incr);
597 return;
598 }
599 list_add(&new_incr->list, prev);
600}
601
03997904
GS
602static int sclp_mem_freeze(struct device *dev)
603{
604 if (!sclp_mem_state_changed)
605 return 0;
606 pr_err("Memory hotplug state changed, suspend refused.\n");
607 return -EPERM;
608}
609
e0bc2495
HC
610struct read_storage_sccb {
611 struct sccb_header header;
612 u16 max_id;
613 u16 assigned;
614 u16 standby;
615 u16 :16;
616 u32 entries[0];
617} __packed;
618
47145210 619static const struct dev_pm_ops sclp_mem_pm_ops = {
03997904
GS
620 .freeze = sclp_mem_freeze,
621};
622
623static struct platform_driver sclp_mem_pdrv = {
624 .driver = {
625 .name = "sclp_mem",
626 .pm = &sclp_mem_pm_ops,
627 },
628};
629
e0bc2495
HC
630static int __init sclp_detect_standby_memory(void)
631{
03997904 632 struct platform_device *sclp_pdev;
e0bc2495
HC
633 struct read_storage_sccb *sccb;
634 int i, id, assigned, rc;
635
636 if (!early_read_info_sccb_valid)
637 return 0;
638 if ((sclp_facilities & 0xe00000000000ULL) != 0xe00000000000ULL)
639 return 0;
640 rc = -ENOMEM;
641 sccb = (void *) __get_free_page(GFP_KERNEL | GFP_DMA);
642 if (!sccb)
643 goto out;
644 assigned = 0;
645 for (id = 0; id <= sclp_max_storage_id; id++) {
646 memset(sccb, 0, PAGE_SIZE);
647 sccb->header.length = PAGE_SIZE;
648 rc = do_sync_request(0x00040001 | id << 8, sccb);
649 if (rc)
650 goto out;
651 switch (sccb->header.response_code) {
652 case 0x0010:
653 set_bit(id, sclp_storage_ids);
654 for (i = 0; i < sccb->assigned; i++) {
655 if (!sccb->entries[i])
656 continue;
657 assigned++;
658 insert_increment(sccb->entries[i] >> 16, 0, 1);
659 }
660 break;
661 case 0x0310:
662 break;
663 case 0x0410:
664 for (i = 0; i < sccb->assigned; i++) {
665 if (!sccb->entries[i])
666 continue;
667 assigned++;
668 insert_increment(sccb->entries[i] >> 16, 1, 1);
669 }
670 break;
671 default:
672 rc = -EIO;
673 break;
674 }
675 if (!rc)
676 sclp_max_storage_id = sccb->max_id;
677 }
678 if (rc || list_empty(&sclp_mem_list))
679 goto out;
680 for (i = 1; i <= rnmax - assigned; i++)
681 insert_increment(0, 1, 0);
682 rc = register_memory_notifier(&sclp_mem_nb);
683 if (rc)
684 goto out;
03997904
GS
685 rc = platform_driver_register(&sclp_mem_pdrv);
686 if (rc)
687 goto out;
688 sclp_pdev = platform_device_register_simple("sclp_mem", -1, NULL, 0);
689 rc = IS_ERR(sclp_pdev) ? PTR_ERR(sclp_pdev) : 0;
690 if (rc)
691 goto out_driver;
e0bc2495 692 sclp_add_standby_memory();
03997904
GS
693 goto out;
694out_driver:
695 platform_driver_unregister(&sclp_mem_pdrv);
e0bc2495
HC
696out:
697 free_page((unsigned long) sccb);
698 return rc;
699}
700__initcall(sclp_detect_standby_memory);
701
702#endif /* CONFIG_MEMORY_HOTPLUG */
703
7441b062
JG
704/*
705 * PCI I/O adapter configuration related functions.
706 */
707#define SCLP_CMDW_CONFIGURE_PCI 0x001a0001
708#define SCLP_CMDW_DECONFIGURE_PCI 0x001b0001
709
710#define SCLP_RECONFIG_PCI_ATPYE 2
711
712struct pci_cfg_sccb {
713 struct sccb_header header;
714 u8 atype; /* adapter type */
715 u8 reserved1;
716 u16 reserved2;
717 u32 aid; /* adapter identifier */
718} __packed;
719
720static int do_pci_configure(sclp_cmdw_t cmd, u32 fid)
721{
722 struct pci_cfg_sccb *sccb;
723 int rc;
724
725 if (!SCLP_HAS_PCI_RECONFIG)
726 return -EOPNOTSUPP;
727
728 sccb = (struct pci_cfg_sccb *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
729 if (!sccb)
730 return -ENOMEM;
731
732 sccb->header.length = PAGE_SIZE;
733 sccb->atype = SCLP_RECONFIG_PCI_ATPYE;
734 sccb->aid = fid;
735 rc = do_sync_request(cmd, sccb);
736 if (rc)
737 goto out;
738 switch (sccb->header.response_code) {
739 case 0x0020:
740 case 0x0120:
741 break;
742 default:
743 pr_warn("configure PCI I/O adapter failed: cmd=0x%08x response=0x%04x\n",
744 cmd, sccb->header.response_code);
745 rc = -EIO;
746 break;
747 }
748out:
749 free_page((unsigned long) sccb);
750 return rc;
751}
752
753int sclp_pci_configure(u32 fid)
754{
755 return do_pci_configure(SCLP_CMDW_CONFIGURE_PCI, fid);
756}
757EXPORT_SYMBOL(sclp_pci_configure);
758
759int sclp_pci_deconfigure(u32 fid)
760{
761 return do_pci_configure(SCLP_CMDW_DECONFIGURE_PCI, fid);
762}
763EXPORT_SYMBOL(sclp_pci_deconfigure);
764
4b28a8fe
HC
765/*
766 * Channel path configuration related functions.
767 */
768
769#define SCLP_CMDW_CONFIGURE_CHPATH 0x000f0001
770#define SCLP_CMDW_DECONFIGURE_CHPATH 0x000e0001
771#define SCLP_CMDW_READ_CHPATH_INFORMATION 0x00030001
772
773struct chp_cfg_sccb {
774 struct sccb_header header;
775 u8 ccm;
776 u8 reserved[6];
777 u8 cssid;
778} __attribute__((packed));
779
780static int do_chp_configure(sclp_cmdw_t cmd)
781{
782 struct chp_cfg_sccb *sccb;
783 int rc;
784
785 if (!SCLP_HAS_CHP_RECONFIG)
786 return -EOPNOTSUPP;
787 /* Prepare sccb. */
788 sccb = (struct chp_cfg_sccb *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
789 if (!sccb)
790 return -ENOMEM;
791 sccb->header.length = sizeof(*sccb);
792 rc = do_sync_request(cmd, sccb);
793 if (rc)
794 goto out;
795 switch (sccb->header.response_code) {
796 case 0x0020:
797 case 0x0120:
798 case 0x0440:
799 case 0x0450:
800 break;
801 default:
b3ff088b
MS
802 pr_warning("configure channel-path failed "
803 "(cmd=0x%08x, response=0x%04x)\n", cmd,
804 sccb->header.response_code);
4b28a8fe
HC
805 rc = -EIO;
806 break;
807 }
808out:
809 free_page((unsigned long) sccb);
810 return rc;
811}
812
813/**
814 * sclp_chp_configure - perform configure channel-path sclp command
815 * @chpid: channel-path ID
816 *
817 * Perform configure channel-path command sclp command for specified chpid.
818 * Return 0 after command successfully finished, non-zero otherwise.
819 */
820int sclp_chp_configure(struct chp_id chpid)
821{
822 return do_chp_configure(SCLP_CMDW_CONFIGURE_CHPATH | chpid.id << 8);
823}
824
825/**
826 * sclp_chp_deconfigure - perform deconfigure channel-path sclp command
827 * @chpid: channel-path ID
828 *
829 * Perform deconfigure channel-path command sclp command for specified chpid
830 * and wait for completion. On success return 0. Return non-zero otherwise.
831 */
832int sclp_chp_deconfigure(struct chp_id chpid)
833{
834 return do_chp_configure(SCLP_CMDW_DECONFIGURE_CHPATH | chpid.id << 8);
835}
836
837struct chp_info_sccb {
838 struct sccb_header header;
839 u8 recognized[SCLP_CHP_INFO_MASK_SIZE];
840 u8 standby[SCLP_CHP_INFO_MASK_SIZE];
841 u8 configured[SCLP_CHP_INFO_MASK_SIZE];
842 u8 ccm;
843 u8 reserved[6];
844 u8 cssid;
845} __attribute__((packed));
846
847/**
848 * sclp_chp_read_info - perform read channel-path information sclp command
849 * @info: resulting channel-path information data
850 *
851 * Perform read channel-path information sclp command and wait for completion.
852 * On success, store channel-path information in @info and return 0. Return
853 * non-zero otherwise.
854 */
855int sclp_chp_read_info(struct sclp_chp_info *info)
856{
857 struct chp_info_sccb *sccb;
858 int rc;
859
860 if (!SCLP_HAS_CHP_INFO)
861 return -EOPNOTSUPP;
862 /* Prepare sccb. */
863 sccb = (struct chp_info_sccb *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
864 if (!sccb)
865 return -ENOMEM;
866 sccb->header.length = sizeof(*sccb);
867 rc = do_sync_request(SCLP_CMDW_READ_CHPATH_INFORMATION, sccb);
868 if (rc)
869 goto out;
870 if (sccb->header.response_code != 0x0010) {
b3ff088b
MS
871 pr_warning("read channel-path info failed "
872 "(response=0x%04x)\n", sccb->header.response_code);
4b28a8fe
HC
873 rc = -EIO;
874 goto out;
875 }
876 memcpy(info->recognized, sccb->recognized, SCLP_CHP_INFO_MASK_SIZE);
877 memcpy(info->standby, sccb->standby, SCLP_CHP_INFO_MASK_SIZE);
878 memcpy(info->configured, sccb->configured, SCLP_CHP_INFO_MASK_SIZE);
879out:
880 free_page((unsigned long) sccb);
881 return rc;
882}
This page took 0.488242 seconds and 5 git commands to generate.