blob: 49af8eeb90ea2b3cbd5786bdd075727b20a9a327 [file] [log] [blame]
Heiko Carstens08d07962008-01-26 14:10:56 +01001/*
Jan Glauber7441b062012-11-29 14:35:47 +01002 * Copyright IBM Corp. 2007,2012
Heiko Carstens08d07962008-01-26 14:10:56 +01003 *
Gerald Schaefer039979042009-06-16 10:30:48 +02004 * Author(s): Heiko Carstens <heiko.carstens@de.ibm.com>,
5 * Peter Oberparleiter <peter.oberparleiter@de.ibm.com>
Heiko Carstens08d07962008-01-26 14:10:56 +01006 */
7
Martin Schwidefskyb3ff0882008-12-25 13:39:48 +01008#define KMSG_COMPONENT "sclp_cmd"
9#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
10
Heiko Carstens08d07962008-01-26 14:10:56 +010011#include <linux/completion.h>
12#include <linux/init.h>
13#include <linux/errno.h>
Gerald Schaefer039979042009-06-16 10:30:48 +020014#include <linux/err.h>
Jan Glauber7441b062012-11-29 14:35:47 +010015#include <linux/export.h>
Heiko Carstens08d07962008-01-26 14:10:56 +010016#include <linux/slab.h>
17#include <linux/string.h>
Heiko Carstense0bc2492008-07-14 09:59:19 +020018#include <linux/mm.h>
19#include <linux/mmzone.h>
20#include <linux/memory.h>
Christian Borntraeger1526bf92012-05-15 14:15:25 +020021#include <linux/module.h>
Gerald Schaefer039979042009-06-16 10:30:48 +020022#include <linux/platform_device.h>
David Howellsa0616cd2012-03-28 18:30:02 +010023#include <asm/ctl_reg.h>
Heiko Carstens6b70a922012-11-02 12:56:43 +010024#include <asm/chpid.h>
25#include <asm/setup.h>
26#include <asm/page.h>
27#include <asm/sclp.h>
Heiko Carstens08d07962008-01-26 14:10:56 +010028
Martin Schwidefskyb3ff0882008-12-25 13:39:48 +010029#include "sclp.h"
Heiko Carstens08d07962008-01-26 14:10:56 +010030
Heiko Carstens08d07962008-01-26 14:10:56 +010031static void sclp_sync_callback(struct sclp_req *req, void *data)
32{
33 struct completion *completion = data;
34
35 complete(completion);
36}
37
Michael Holzheud475f942013-06-06 09:52:08 +020038int sclp_sync_request(sclp_cmdw_t cmd, void *sccb)
Heiko Carstens08d07962008-01-26 14:10:56 +010039{
40 struct completion completion;
41 struct sclp_req *request;
42 int rc;
43
44 request = kzalloc(sizeof(*request), GFP_KERNEL);
45 if (!request)
46 return -ENOMEM;
47 request->command = cmd;
48 request->sccb = sccb;
49 request->status = SCLP_REQ_FILLED;
50 request->callback = sclp_sync_callback;
51 request->callback_data = &completion;
52 init_completion(&completion);
53
54 /* Perform sclp request. */
55 rc = sclp_add_request(request);
56 if (rc)
57 goto out;
58 wait_for_completion(&completion);
59
60 /* Check response. */
61 if (request->status != SCLP_REQ_DONE) {
Martin Schwidefskyb3ff0882008-12-25 13:39:48 +010062 pr_warning("sync request failed (cmd=0x%08x, "
63 "status=0x%02x)\n", cmd, request->status);
Heiko Carstens08d07962008-01-26 14:10:56 +010064 rc = -EIO;
65 }
66out:
67 kfree(request);
68 return rc;
69}
70
71/*
72 * CPU configuration related functions.
73 */
74
75#define SCLP_CMDW_READ_CPU_INFO 0x00010001
76#define SCLP_CMDW_CONFIGURE_CPU 0x00110001
77#define SCLP_CMDW_DECONFIGURE_CPU 0x00100001
78
79struct read_cpu_info_sccb {
80 struct sccb_header header;
81 u16 nr_configured;
82 u16 offset_configured;
83 u16 nr_standby;
84 u16 offset_standby;
85 u8 reserved[4096 - 16];
86} __attribute__((packed, aligned(PAGE_SIZE)));
87
Heiko Carstens08d07962008-01-26 14:10:56 +010088static void sclp_fill_cpu_info(struct sclp_cpu_info *info,
89 struct read_cpu_info_sccb *sccb)
90{
91 char *page = (char *) sccb;
92
93 memset(info, 0, sizeof(*info));
94 info->configured = sccb->nr_configured;
95 info->standby = sccb->nr_standby;
96 info->combined = sccb->nr_configured + sccb->nr_standby;
97 info->has_cpu_type = sclp_fac84 & 0x1;
98 memcpy(&info->cpu, page + sccb->offset_configured,
99 info->combined * sizeof(struct sclp_cpu_entry));
100}
101
Heiko Carstens48483b32008-01-26 14:11:05 +0100102int sclp_get_cpu_info(struct sclp_cpu_info *info)
Heiko Carstens08d07962008-01-26 14:10:56 +0100103{
104 int rc;
105 struct read_cpu_info_sccb *sccb;
106
107 if (!SCLP_HAS_CPU_INFO)
108 return -EOPNOTSUPP;
Heiko Carstens48483b32008-01-26 14:11:05 +0100109 sccb = (void *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
Heiko Carstens08d07962008-01-26 14:10:56 +0100110 if (!sccb)
111 return -ENOMEM;
Heiko Carstens08d07962008-01-26 14:10:56 +0100112 sccb->header.length = sizeof(*sccb);
Michael Holzheud475f942013-06-06 09:52:08 +0200113 rc = sclp_sync_request(SCLP_CMDW_READ_CPU_INFO, sccb);
Heiko Carstens08d07962008-01-26 14:10:56 +0100114 if (rc)
115 goto out;
116 if (sccb->header.response_code != 0x0010) {
Martin Schwidefskyb3ff0882008-12-25 13:39:48 +0100117 pr_warning("readcpuinfo failed (response=0x%04x)\n",
118 sccb->header.response_code);
Heiko Carstens08d07962008-01-26 14:10:56 +0100119 rc = -EIO;
120 goto out;
121 }
122 sclp_fill_cpu_info(info, sccb);
123out:
124 free_page((unsigned long) sccb);
125 return rc;
126}
127
Heiko Carstens08d07962008-01-26 14:10:56 +0100128struct cpu_configure_sccb {
129 struct sccb_header header;
130} __attribute__((packed, aligned(8)));
131
132static int do_cpu_configure(sclp_cmdw_t cmd)
133{
134 struct cpu_configure_sccb *sccb;
135 int rc;
136
137 if (!SCLP_HAS_CPU_RECONFIG)
138 return -EOPNOTSUPP;
139 /*
140 * This is not going to cross a page boundary since we force
141 * kmalloc to have a minimum alignment of 8 bytes on s390.
142 */
143 sccb = kzalloc(sizeof(*sccb), GFP_KERNEL | GFP_DMA);
144 if (!sccb)
145 return -ENOMEM;
146 sccb->header.length = sizeof(*sccb);
Michael Holzheud475f942013-06-06 09:52:08 +0200147 rc = sclp_sync_request(cmd, sccb);
Heiko Carstens08d07962008-01-26 14:10:56 +0100148 if (rc)
149 goto out;
150 switch (sccb->header.response_code) {
151 case 0x0020:
152 case 0x0120:
153 break;
154 default:
Martin Schwidefskyb3ff0882008-12-25 13:39:48 +0100155 pr_warning("configure cpu failed (cmd=0x%08x, "
156 "response=0x%04x)\n", cmd,
157 sccb->header.response_code);
Heiko Carstens08d07962008-01-26 14:10:56 +0100158 rc = -EIO;
159 break;
160 }
161out:
162 kfree(sccb);
163 return rc;
164}
165
166int sclp_cpu_configure(u8 cpu)
167{
168 return do_cpu_configure(SCLP_CMDW_CONFIGURE_CPU | cpu << 8);
169}
170
171int sclp_cpu_deconfigure(u8 cpu)
172{
173 return do_cpu_configure(SCLP_CMDW_DECONFIGURE_CPU | cpu << 8);
174}
Heiko Carstens4b28a8f2008-01-26 14:10:57 +0100175
Heiko Carstense0bc2492008-07-14 09:59:19 +0200176#ifdef CONFIG_MEMORY_HOTPLUG
177
178static DEFINE_MUTEX(sclp_mem_mutex);
179static LIST_HEAD(sclp_mem_list);
180static u8 sclp_max_storage_id;
181static unsigned long sclp_storage_ids[256 / BITS_PER_LONG];
Gerald Schaefer039979042009-06-16 10:30:48 +0200182static int sclp_mem_state_changed;
Heiko Carstense0bc2492008-07-14 09:59:19 +0200183
184struct memory_increment {
185 struct list_head list;
186 u16 rn;
187 int standby;
Heiko Carstense0bc2492008-07-14 09:59:19 +0200188};
189
190struct assign_storage_sccb {
191 struct sccb_header header;
192 u16 rn;
193} __packed;
194
Heiko Carstens9c952582010-03-24 11:49:55 +0100195int arch_get_memory_phys_device(unsigned long start_pfn)
196{
Michael Holzheuacf6a002013-11-13 10:38:27 +0100197 if (!sclp_rzm)
Heiko Carstens9c952582010-03-24 11:49:55 +0100198 return 0;
Michael Holzheuacf6a002013-11-13 10:38:27 +0100199 return PFN_PHYS(start_pfn) >> ilog2(sclp_rzm);
Heiko Carstens9c952582010-03-24 11:49:55 +0100200}
201
Heiko Carstense0bc2492008-07-14 09:59:19 +0200202static unsigned long long rn2addr(u16 rn)
203{
Michael Holzheuacf6a002013-11-13 10:38:27 +0100204 return (unsigned long long) (rn - 1) * sclp_rzm;
Heiko Carstense0bc2492008-07-14 09:59:19 +0200205}
206
207static int do_assign_storage(sclp_cmdw_t cmd, u16 rn)
208{
209 struct assign_storage_sccb *sccb;
210 int rc;
211
212 sccb = (void *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
213 if (!sccb)
214 return -ENOMEM;
215 sccb->header.length = PAGE_SIZE;
216 sccb->rn = rn;
Michael Holzheud475f942013-06-06 09:52:08 +0200217 rc = sclp_sync_request(cmd, sccb);
Heiko Carstense0bc2492008-07-14 09:59:19 +0200218 if (rc)
219 goto out;
220 switch (sccb->header.response_code) {
221 case 0x0020:
222 case 0x0120:
223 break;
224 default:
Heiko Carstens675be972008-11-14 18:18:01 +0100225 pr_warning("assign storage failed (cmd=0x%08x, "
226 "response=0x%04x, rn=0x%04x)\n", cmd,
227 sccb->header.response_code, rn);
Heiko Carstense0bc2492008-07-14 09:59:19 +0200228 rc = -EIO;
229 break;
230 }
231out:
232 free_page((unsigned long) sccb);
233 return rc;
234}
235
236static int sclp_assign_storage(u16 rn)
237{
Heiko Carstens6b70a922012-11-02 12:56:43 +0100238 unsigned long long start;
Heiko Carstens0cd2f622012-05-14 11:04:10 +0200239 int rc;
240
241 rc = do_assign_storage(0x000d0001, rn);
242 if (rc)
Heiko Carstens6b70a922012-11-02 12:56:43 +0100243 return rc;
244 start = rn2addr(rn);
Michael Holzheuacf6a002013-11-13 10:38:27 +0100245 storage_key_init_range(start, start + sclp_rzm);
Heiko Carstens6b70a922012-11-02 12:56:43 +0100246 return 0;
Heiko Carstense0bc2492008-07-14 09:59:19 +0200247}
248
249static int sclp_unassign_storage(u16 rn)
250{
251 return do_assign_storage(0x000c0001, rn);
252}
253
254struct attach_storage_sccb {
255 struct sccb_header header;
256 u16 :16;
257 u16 assigned;
258 u32 :32;
259 u32 entries[0];
260} __packed;
261
262static int sclp_attach_storage(u8 id)
263{
264 struct attach_storage_sccb *sccb;
265 int rc;
266 int i;
267
268 sccb = (void *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
269 if (!sccb)
270 return -ENOMEM;
271 sccb->header.length = PAGE_SIZE;
Michael Holzheud475f942013-06-06 09:52:08 +0200272 rc = sclp_sync_request(0x00080001 | id << 8, sccb);
Heiko Carstense0bc2492008-07-14 09:59:19 +0200273 if (rc)
274 goto out;
275 switch (sccb->header.response_code) {
276 case 0x0020:
277 set_bit(id, sclp_storage_ids);
Heiko Carstens8adb4ca2011-08-24 17:15:13 +0200278 for (i = 0; i < sccb->assigned; i++) {
279 if (sccb->entries[i])
280 sclp_unassign_storage(sccb->entries[i] >> 16);
281 }
Heiko Carstense0bc2492008-07-14 09:59:19 +0200282 break;
283 default:
284 rc = -EIO;
285 break;
286 }
287out:
288 free_page((unsigned long) sccb);
289 return rc;
290}
291
292static int sclp_mem_change_state(unsigned long start, unsigned long size,
293 int online)
294{
295 struct memory_increment *incr;
296 unsigned long long istart;
297 int rc = 0;
298
299 list_for_each_entry(incr, &sclp_mem_list, list) {
300 istart = rn2addr(incr->rn);
301 if (start + size - 1 < istart)
302 break;
Michael Holzheuacf6a002013-11-13 10:38:27 +0100303 if (start > istart + sclp_rzm - 1)
Heiko Carstense0bc2492008-07-14 09:59:19 +0200304 continue;
Heiko Carstens15535562013-05-02 09:20:30 +0200305 if (online)
Heiko Carstense0bc2492008-07-14 09:59:19 +0200306 rc |= sclp_assign_storage(incr->rn);
Heiko Carstens15535562013-05-02 09:20:30 +0200307 else
Heiko Carstense0bc2492008-07-14 09:59:19 +0200308 sclp_unassign_storage(incr->rn);
Heiko Carstense0bc2492008-07-14 09:59:19 +0200309 }
310 return rc ? -EIO : 0;
311}
312
313static int sclp_mem_notifier(struct notifier_block *nb,
314 unsigned long action, void *data)
315{
316 unsigned long start, size;
317 struct memory_notify *arg;
318 unsigned char id;
319 int rc = 0;
320
321 arg = data;
322 start = arg->start_pfn << PAGE_SHIFT;
323 size = arg->nr_pages << PAGE_SHIFT;
324 mutex_lock(&sclp_mem_mutex);
Akinobu Mitafc89db42012-03-23 15:02:05 -0700325 for_each_clear_bit(id, sclp_storage_ids, sclp_max_storage_id + 1)
326 sclp_attach_storage(id);
Heiko Carstense0bc2492008-07-14 09:59:19 +0200327 switch (action) {
328 case MEM_ONLINE:
Gerald Schaefer7e9238f2008-08-01 16:39:16 +0200329 case MEM_GOING_OFFLINE:
330 case MEM_CANCEL_OFFLINE:
Heiko Carstense0bc2492008-07-14 09:59:19 +0200331 break;
332 case MEM_GOING_ONLINE:
333 rc = sclp_mem_change_state(start, size, 1);
334 break;
335 case MEM_CANCEL_ONLINE:
336 sclp_mem_change_state(start, size, 0);
337 break;
Gerald Schaefer7e9238f2008-08-01 16:39:16 +0200338 case MEM_OFFLINE:
339 sclp_mem_change_state(start, size, 0);
340 break;
Heiko Carstense0bc2492008-07-14 09:59:19 +0200341 default:
342 rc = -EINVAL;
343 break;
344 }
Gerald Schaefer039979042009-06-16 10:30:48 +0200345 if (!rc)
346 sclp_mem_state_changed = 1;
Heiko Carstense0bc2492008-07-14 09:59:19 +0200347 mutex_unlock(&sclp_mem_mutex);
348 return rc ? NOTIFY_BAD : NOTIFY_OK;
349}
350
351static struct notifier_block sclp_mem_nb = {
352 .notifier_call = sclp_mem_notifier,
353};
354
355static void __init add_memory_merged(u16 rn)
356{
357 static u16 first_rn, num;
358 unsigned long long start, size;
359
360 if (rn && first_rn && (first_rn + num == rn)) {
361 num++;
362 return;
363 }
364 if (!first_rn)
365 goto skip_add;
366 start = rn2addr(first_rn);
Michael Holzheuacf6a002013-11-13 10:38:27 +0100367 size = (unsigned long long) num * sclp_rzm;
Heiko Carstense0bc2492008-07-14 09:59:19 +0200368 if (start >= VMEM_MAX_PHYS)
369 goto skip_add;
370 if (start + size > VMEM_MAX_PHYS)
371 size = VMEM_MAX_PHYS - start;
Heiko Carstens23d75d92009-02-19 15:19:01 +0100372 if (memory_end_set && (start >= memory_end))
373 goto skip_add;
374 if (memory_end_set && (start + size > memory_end))
375 size = memory_end - start;
Heiko Carstense0bc2492008-07-14 09:59:19 +0200376 add_memory(0, start, size);
377skip_add:
378 first_rn = rn;
379 num = 1;
380}
381
382static void __init sclp_add_standby_memory(void)
383{
384 struct memory_increment *incr;
385
386 list_for_each_entry(incr, &sclp_mem_list, list)
387 if (incr->standby)
388 add_memory_merged(incr->rn);
389 add_memory_merged(0);
390}
391
392static void __init insert_increment(u16 rn, int standby, int assigned)
393{
394 struct memory_increment *incr, *new_incr;
395 struct list_head *prev;
396 u16 last_rn;
397
398 new_incr = kzalloc(sizeof(*new_incr), GFP_KERNEL);
399 if (!new_incr)
400 return;
401 new_incr->rn = rn;
402 new_incr->standby = standby;
403 last_rn = 0;
404 prev = &sclp_mem_list;
405 list_for_each_entry(incr, &sclp_mem_list, list) {
406 if (assigned && incr->rn > rn)
407 break;
408 if (!assigned && incr->rn - last_rn > 1)
409 break;
410 last_rn = incr->rn;
411 prev = &incr->list;
412 }
413 if (!assigned)
414 new_incr->rn = last_rn + 1;
Michael Holzheuacf6a002013-11-13 10:38:27 +0100415 if (new_incr->rn > sclp_rnmax) {
Heiko Carstense0bc2492008-07-14 09:59:19 +0200416 kfree(new_incr);
417 return;
418 }
419 list_add(&new_incr->list, prev);
420}
421
Gerald Schaefer039979042009-06-16 10:30:48 +0200422static int sclp_mem_freeze(struct device *dev)
423{
424 if (!sclp_mem_state_changed)
425 return 0;
426 pr_err("Memory hotplug state changed, suspend refused.\n");
427 return -EPERM;
428}
429
Heiko Carstense0bc2492008-07-14 09:59:19 +0200430struct read_storage_sccb {
431 struct sccb_header header;
432 u16 max_id;
433 u16 assigned;
434 u16 standby;
435 u16 :16;
436 u32 entries[0];
437} __packed;
438
Alexey Dobriyan47145212009-12-14 18:00:08 -0800439static const struct dev_pm_ops sclp_mem_pm_ops = {
Gerald Schaefer039979042009-06-16 10:30:48 +0200440 .freeze = sclp_mem_freeze,
441};
442
443static struct platform_driver sclp_mem_pdrv = {
444 .driver = {
445 .name = "sclp_mem",
446 .pm = &sclp_mem_pm_ops,
447 },
448};
449
Heiko Carstense0bc2492008-07-14 09:59:19 +0200450static int __init sclp_detect_standby_memory(void)
451{
Gerald Schaefer039979042009-06-16 10:30:48 +0200452 struct platform_device *sclp_pdev;
Heiko Carstense0bc2492008-07-14 09:59:19 +0200453 struct read_storage_sccb *sccb;
454 int i, id, assigned, rc;
455
Michael Holzheu52319b42013-03-08 09:29:34 +0100456 if (OLDMEM_BASE) /* No standby memory in kdump mode */
457 return 0;
Heiko Carstense0bc2492008-07-14 09:59:19 +0200458 if ((sclp_facilities & 0xe00000000000ULL) != 0xe00000000000ULL)
459 return 0;
460 rc = -ENOMEM;
461 sccb = (void *) __get_free_page(GFP_KERNEL | GFP_DMA);
462 if (!sccb)
463 goto out;
464 assigned = 0;
465 for (id = 0; id <= sclp_max_storage_id; id++) {
466 memset(sccb, 0, PAGE_SIZE);
467 sccb->header.length = PAGE_SIZE;
Michael Holzheud475f942013-06-06 09:52:08 +0200468 rc = sclp_sync_request(0x00040001 | id << 8, sccb);
Heiko Carstense0bc2492008-07-14 09:59:19 +0200469 if (rc)
470 goto out;
471 switch (sccb->header.response_code) {
472 case 0x0010:
473 set_bit(id, sclp_storage_ids);
474 for (i = 0; i < sccb->assigned; i++) {
475 if (!sccb->entries[i])
476 continue;
477 assigned++;
478 insert_increment(sccb->entries[i] >> 16, 0, 1);
479 }
480 break;
481 case 0x0310:
482 break;
483 case 0x0410:
484 for (i = 0; i < sccb->assigned; i++) {
485 if (!sccb->entries[i])
486 continue;
487 assigned++;
488 insert_increment(sccb->entries[i] >> 16, 1, 1);
489 }
490 break;
491 default:
492 rc = -EIO;
493 break;
494 }
495 if (!rc)
496 sclp_max_storage_id = sccb->max_id;
497 }
498 if (rc || list_empty(&sclp_mem_list))
499 goto out;
Michael Holzheuacf6a002013-11-13 10:38:27 +0100500 for (i = 1; i <= sclp_rnmax - assigned; i++)
Heiko Carstense0bc2492008-07-14 09:59:19 +0200501 insert_increment(0, 1, 0);
502 rc = register_memory_notifier(&sclp_mem_nb);
503 if (rc)
504 goto out;
Gerald Schaefer039979042009-06-16 10:30:48 +0200505 rc = platform_driver_register(&sclp_mem_pdrv);
506 if (rc)
507 goto out;
508 sclp_pdev = platform_device_register_simple("sclp_mem", -1, NULL, 0);
Thomas Meyer4bdb6132013-06-01 11:58:09 +0200509 rc = PTR_RET(sclp_pdev);
Gerald Schaefer039979042009-06-16 10:30:48 +0200510 if (rc)
511 goto out_driver;
Heiko Carstense0bc2492008-07-14 09:59:19 +0200512 sclp_add_standby_memory();
Gerald Schaefer039979042009-06-16 10:30:48 +0200513 goto out;
514out_driver:
515 platform_driver_unregister(&sclp_mem_pdrv);
Heiko Carstense0bc2492008-07-14 09:59:19 +0200516out:
517 free_page((unsigned long) sccb);
518 return rc;
519}
520__initcall(sclp_detect_standby_memory);
521
522#endif /* CONFIG_MEMORY_HOTPLUG */
523
Heiko Carstens4b28a8f2008-01-26 14:10:57 +0100524/*
Jan Glauber7441b062012-11-29 14:35:47 +0100525 * PCI I/O adapter configuration related functions.
526 */
527#define SCLP_CMDW_CONFIGURE_PCI 0x001a0001
528#define SCLP_CMDW_DECONFIGURE_PCI 0x001b0001
529
530#define SCLP_RECONFIG_PCI_ATPYE 2
531
532struct pci_cfg_sccb {
533 struct sccb_header header;
534 u8 atype; /* adapter type */
535 u8 reserved1;
536 u16 reserved2;
537 u32 aid; /* adapter identifier */
538} __packed;
539
540static int do_pci_configure(sclp_cmdw_t cmd, u32 fid)
541{
542 struct pci_cfg_sccb *sccb;
543 int rc;
544
545 if (!SCLP_HAS_PCI_RECONFIG)
546 return -EOPNOTSUPP;
547
548 sccb = (struct pci_cfg_sccb *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
549 if (!sccb)
550 return -ENOMEM;
551
552 sccb->header.length = PAGE_SIZE;
553 sccb->atype = SCLP_RECONFIG_PCI_ATPYE;
554 sccb->aid = fid;
Michael Holzheud475f942013-06-06 09:52:08 +0200555 rc = sclp_sync_request(cmd, sccb);
Jan Glauber7441b062012-11-29 14:35:47 +0100556 if (rc)
557 goto out;
558 switch (sccb->header.response_code) {
559 case 0x0020:
560 case 0x0120:
561 break;
562 default:
563 pr_warn("configure PCI I/O adapter failed: cmd=0x%08x response=0x%04x\n",
564 cmd, sccb->header.response_code);
565 rc = -EIO;
566 break;
567 }
568out:
569 free_page((unsigned long) sccb);
570 return rc;
571}
572
573int sclp_pci_configure(u32 fid)
574{
575 return do_pci_configure(SCLP_CMDW_CONFIGURE_PCI, fid);
576}
577EXPORT_SYMBOL(sclp_pci_configure);
578
579int sclp_pci_deconfigure(u32 fid)
580{
581 return do_pci_configure(SCLP_CMDW_DECONFIGURE_PCI, fid);
582}
583EXPORT_SYMBOL(sclp_pci_deconfigure);
584
585/*
Heiko Carstens4b28a8f2008-01-26 14:10:57 +0100586 * Channel path configuration related functions.
587 */
588
589#define SCLP_CMDW_CONFIGURE_CHPATH 0x000f0001
590#define SCLP_CMDW_DECONFIGURE_CHPATH 0x000e0001
591#define SCLP_CMDW_READ_CHPATH_INFORMATION 0x00030001
592
593struct chp_cfg_sccb {
594 struct sccb_header header;
595 u8 ccm;
596 u8 reserved[6];
597 u8 cssid;
598} __attribute__((packed));
599
600static int do_chp_configure(sclp_cmdw_t cmd)
601{
602 struct chp_cfg_sccb *sccb;
603 int rc;
604
605 if (!SCLP_HAS_CHP_RECONFIG)
606 return -EOPNOTSUPP;
607 /* Prepare sccb. */
608 sccb = (struct chp_cfg_sccb *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
609 if (!sccb)
610 return -ENOMEM;
611 sccb->header.length = sizeof(*sccb);
Michael Holzheud475f942013-06-06 09:52:08 +0200612 rc = sclp_sync_request(cmd, sccb);
Heiko Carstens4b28a8f2008-01-26 14:10:57 +0100613 if (rc)
614 goto out;
615 switch (sccb->header.response_code) {
616 case 0x0020:
617 case 0x0120:
618 case 0x0440:
619 case 0x0450:
620 break;
621 default:
Martin Schwidefskyb3ff0882008-12-25 13:39:48 +0100622 pr_warning("configure channel-path failed "
623 "(cmd=0x%08x, response=0x%04x)\n", cmd,
624 sccb->header.response_code);
Heiko Carstens4b28a8f2008-01-26 14:10:57 +0100625 rc = -EIO;
626 break;
627 }
628out:
629 free_page((unsigned long) sccb);
630 return rc;
631}
632
633/**
634 * sclp_chp_configure - perform configure channel-path sclp command
635 * @chpid: channel-path ID
636 *
637 * Perform configure channel-path command sclp command for specified chpid.
638 * Return 0 after command successfully finished, non-zero otherwise.
639 */
640int sclp_chp_configure(struct chp_id chpid)
641{
642 return do_chp_configure(SCLP_CMDW_CONFIGURE_CHPATH | chpid.id << 8);
643}
644
645/**
646 * sclp_chp_deconfigure - perform deconfigure channel-path sclp command
647 * @chpid: channel-path ID
648 *
649 * Perform deconfigure channel-path command sclp command for specified chpid
650 * and wait for completion. On success return 0. Return non-zero otherwise.
651 */
652int sclp_chp_deconfigure(struct chp_id chpid)
653{
654 return do_chp_configure(SCLP_CMDW_DECONFIGURE_CHPATH | chpid.id << 8);
655}
656
657struct chp_info_sccb {
658 struct sccb_header header;
659 u8 recognized[SCLP_CHP_INFO_MASK_SIZE];
660 u8 standby[SCLP_CHP_INFO_MASK_SIZE];
661 u8 configured[SCLP_CHP_INFO_MASK_SIZE];
662 u8 ccm;
663 u8 reserved[6];
664 u8 cssid;
665} __attribute__((packed));
666
667/**
668 * sclp_chp_read_info - perform read channel-path information sclp command
669 * @info: resulting channel-path information data
670 *
671 * Perform read channel-path information sclp command and wait for completion.
672 * On success, store channel-path information in @info and return 0. Return
673 * non-zero otherwise.
674 */
675int sclp_chp_read_info(struct sclp_chp_info *info)
676{
677 struct chp_info_sccb *sccb;
678 int rc;
679
680 if (!SCLP_HAS_CHP_INFO)
681 return -EOPNOTSUPP;
682 /* Prepare sccb. */
683 sccb = (struct chp_info_sccb *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
684 if (!sccb)
685 return -ENOMEM;
686 sccb->header.length = sizeof(*sccb);
Michael Holzheud475f942013-06-06 09:52:08 +0200687 rc = sclp_sync_request(SCLP_CMDW_READ_CHPATH_INFORMATION, sccb);
Heiko Carstens4b28a8f2008-01-26 14:10:57 +0100688 if (rc)
689 goto out;
690 if (sccb->header.response_code != 0x0010) {
Martin Schwidefskyb3ff0882008-12-25 13:39:48 +0100691 pr_warning("read channel-path info failed "
692 "(response=0x%04x)\n", sccb->header.response_code);
Heiko Carstens4b28a8f2008-01-26 14:10:57 +0100693 rc = -EIO;
694 goto out;
695 }
696 memcpy(info->recognized, sccb->recognized, SCLP_CHP_INFO_MASK_SIZE);
697 memcpy(info->standby, sccb->standby, SCLP_CHP_INFO_MASK_SIZE);
698 memcpy(info->configured, sccb->configured, SCLP_CHP_INFO_MASK_SIZE);
699out:
700 free_page((unsigned long) sccb);
701 return rc;
702}
Martin Schwidefsky07be0382014-01-24 09:18:52 +0100703
704bool sclp_has_sprp(void)
705{
706 return !!(sclp_fac84 & 0x2);
707}