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