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