blob: 09c2ea84a57f2110ffb32e3c40fb809687dc502a [file] [log] [blame]
Cornelia Huck9d92a7e2008-07-14 09:59:05 +02001/*
2 * Driver for s390 chsc subchannels
3 *
Cornelia Huckad285ae2009-06-16 10:30:24 +02004 * Copyright IBM Corp. 2008, 2009
5 *
Cornelia Huck9d92a7e2008-07-14 09:59:05 +02006 * Author(s): Cornelia Huck <cornelia.huck@de.ibm.com>
7 *
8 */
9
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090010#include <linux/slab.h>
Cornelia Huck9d92a7e2008-07-14 09:59:05 +020011#include <linux/device.h>
12#include <linux/module.h>
13#include <linux/uaccess.h>
14#include <linux/miscdevice.h>
15
Heiko Carstens44ee6a82010-01-13 20:44:30 +010016#include <asm/compat.h>
Cornelia Huck9d92a7e2008-07-14 09:59:05 +020017#include <asm/cio.h>
18#include <asm/chsc.h>
19#include <asm/isc.h>
20
21#include "cio.h"
22#include "cio_debug.h"
23#include "css.h"
24#include "chsc_sch.h"
25#include "ioasm.h"
26
27static debug_info_t *chsc_debug_msg_id;
28static debug_info_t *chsc_debug_log_id;
29
30#define CHSC_MSG(imp, args...) do { \
31 debug_sprintf_event(chsc_debug_msg_id, imp , ##args); \
32 } while (0)
33
34#define CHSC_LOG(imp, txt) do { \
35 debug_text_event(chsc_debug_log_id, imp , txt); \
36 } while (0)
37
38static void CHSC_LOG_HEX(int level, void *data, int length)
39{
40 while (length > 0) {
41 debug_event(chsc_debug_log_id, level, data, length);
42 length -= chsc_debug_log_id->buf_size;
43 data += chsc_debug_log_id->buf_size;
44 }
45}
46
47MODULE_AUTHOR("IBM Corporation");
48MODULE_DESCRIPTION("driver for s390 chsc subchannels");
49MODULE_LICENSE("GPL");
50
51static void chsc_subchannel_irq(struct subchannel *sch)
52{
Sebastian Ott85fb5342011-03-15 17:08:28 +010053 struct chsc_private *private = dev_get_drvdata(&sch->dev);
Cornelia Huck9d92a7e2008-07-14 09:59:05 +020054 struct chsc_request *request = private->request;
Heiko Carstenscbb870c2010-02-26 22:37:43 +010055 struct irb *irb = (struct irb *)&S390_lowcore.irb;
Cornelia Huck9d92a7e2008-07-14 09:59:05 +020056
57 CHSC_LOG(4, "irb");
58 CHSC_LOG_HEX(4, irb, sizeof(*irb));
59 /* Copy irb to provided request and set done. */
60 if (!request) {
61 CHSC_MSG(0, "Interrupt on sch 0.%x.%04x with no request\n",
62 sch->schid.ssid, sch->schid.sch_no);
63 return;
64 }
65 private->request = NULL;
66 memcpy(&request->irb, irb, sizeof(*irb));
Sebastian Ottcdb912a2008-12-25 13:39:12 +010067 cio_update_schib(sch);
Cornelia Huck9d92a7e2008-07-14 09:59:05 +020068 complete(&request->completion);
69 put_device(&sch->dev);
70}
71
72static int chsc_subchannel_probe(struct subchannel *sch)
73{
74 struct chsc_private *private;
75 int ret;
76
77 CHSC_MSG(6, "Detected chsc subchannel 0.%x.%04x\n",
78 sch->schid.ssid, sch->schid.sch_no);
79 sch->isc = CHSC_SCH_ISC;
80 private = kzalloc(sizeof(*private), GFP_KERNEL);
81 if (!private)
82 return -ENOMEM;
Sebastian Ott85fb5342011-03-15 17:08:28 +010083 dev_set_drvdata(&sch->dev, private);
Cornelia Huck9d92a7e2008-07-14 09:59:05 +020084 ret = cio_enable_subchannel(sch, (u32)(unsigned long)sch);
85 if (ret) {
86 CHSC_MSG(0, "Failed to enable 0.%x.%04x: %d\n",
87 sch->schid.ssid, sch->schid.sch_no, ret);
Sebastian Ott85fb5342011-03-15 17:08:28 +010088 dev_set_drvdata(&sch->dev, NULL);
Cornelia Huck9d92a7e2008-07-14 09:59:05 +020089 kfree(private);
90 } else {
Ming Leif67f1292009-03-01 21:10:49 +080091 if (dev_get_uevent_suppress(&sch->dev)) {
92 dev_set_uevent_suppress(&sch->dev, 0);
Cornelia Huck9d92a7e2008-07-14 09:59:05 +020093 kobject_uevent(&sch->dev.kobj, KOBJ_ADD);
94 }
95 }
96 return ret;
97}
98
99static int chsc_subchannel_remove(struct subchannel *sch)
100{
101 struct chsc_private *private;
102
103 cio_disable_subchannel(sch);
Sebastian Ott85fb5342011-03-15 17:08:28 +0100104 private = dev_get_drvdata(&sch->dev);
105 dev_set_drvdata(&sch->dev, NULL);
Cornelia Huck9d92a7e2008-07-14 09:59:05 +0200106 if (private->request) {
107 complete(&private->request->completion);
108 put_device(&sch->dev);
109 }
110 kfree(private);
111 return 0;
112}
113
114static void chsc_subchannel_shutdown(struct subchannel *sch)
115{
116 cio_disable_subchannel(sch);
117}
118
Cornelia Huckad285ae2009-06-16 10:30:24 +0200119static int chsc_subchannel_prepare(struct subchannel *sch)
120{
121 int cc;
122 struct schib schib;
123 /*
124 * Don't allow suspend while the subchannel is not idle
125 * since we don't have a way to clear the subchannel and
126 * cannot disable it with a request running.
127 */
Sebastian Ott8821d242010-04-22 17:17:05 +0200128 cc = stsch_err(sch->schid, &schib);
Cornelia Huckad285ae2009-06-16 10:30:24 +0200129 if (!cc && scsw_stctl(&schib.scsw))
130 return -EAGAIN;
131 return 0;
132}
133
134static int chsc_subchannel_freeze(struct subchannel *sch)
135{
136 return cio_disable_subchannel(sch);
137}
138
139static int chsc_subchannel_restore(struct subchannel *sch)
140{
141 return cio_enable_subchannel(sch, (u32)(unsigned long)sch);
142}
143
Cornelia Huck9d92a7e2008-07-14 09:59:05 +0200144static struct css_device_id chsc_subchannel_ids[] = {
145 { .match_flags = 0x1, .type =SUBCHANNEL_TYPE_CHSC, },
146 { /* end of list */ },
147};
148MODULE_DEVICE_TABLE(css, chsc_subchannel_ids);
149
150static struct css_driver chsc_subchannel_driver = {
151 .owner = THIS_MODULE,
152 .subchannel_type = chsc_subchannel_ids,
153 .irq = chsc_subchannel_irq,
154 .probe = chsc_subchannel_probe,
155 .remove = chsc_subchannel_remove,
156 .shutdown = chsc_subchannel_shutdown,
Cornelia Huckad285ae2009-06-16 10:30:24 +0200157 .prepare = chsc_subchannel_prepare,
158 .freeze = chsc_subchannel_freeze,
159 .thaw = chsc_subchannel_restore,
160 .restore = chsc_subchannel_restore,
Cornelia Huck9d92a7e2008-07-14 09:59:05 +0200161 .name = "chsc_subchannel",
162};
163
164static int __init chsc_init_dbfs(void)
165{
166 chsc_debug_msg_id = debug_register("chsc_msg", 16, 1,
167 16 * sizeof(long));
168 if (!chsc_debug_msg_id)
169 goto out;
170 debug_register_view(chsc_debug_msg_id, &debug_sprintf_view);
171 debug_set_level(chsc_debug_msg_id, 2);
172 chsc_debug_log_id = debug_register("chsc_log", 16, 1, 16);
173 if (!chsc_debug_log_id)
174 goto out;
175 debug_register_view(chsc_debug_log_id, &debug_hex_ascii_view);
176 debug_set_level(chsc_debug_log_id, 2);
177 return 0;
178out:
179 if (chsc_debug_msg_id)
180 debug_unregister(chsc_debug_msg_id);
181 return -ENOMEM;
182}
183
184static void chsc_remove_dbfs(void)
185{
186 debug_unregister(chsc_debug_log_id);
187 debug_unregister(chsc_debug_msg_id);
188}
189
190static int __init chsc_init_sch_driver(void)
191{
192 return css_driver_register(&chsc_subchannel_driver);
193}
194
195static void chsc_cleanup_sch_driver(void)
196{
197 css_driver_unregister(&chsc_subchannel_driver);
198}
199
200static DEFINE_SPINLOCK(chsc_lock);
201
202static int chsc_subchannel_match_next_free(struct device *dev, void *data)
203{
204 struct subchannel *sch = to_subchannel(dev);
205
206 return sch->schib.pmcw.ena && !scsw_fctl(&sch->schib.scsw);
207}
208
209static struct subchannel *chsc_get_next_subchannel(struct subchannel *sch)
210{
211 struct device *dev;
212
213 dev = driver_find_device(&chsc_subchannel_driver.drv,
214 sch ? &sch->dev : NULL, NULL,
215 chsc_subchannel_match_next_free);
216 return dev ? to_subchannel(dev) : NULL;
217}
218
219/**
220 * chsc_async() - try to start a chsc request asynchronously
221 * @chsc_area: request to be started
222 * @request: request structure to associate
223 *
224 * Tries to start a chsc request on one of the existing chsc subchannels.
225 * Returns:
226 * %0 if the request was performed synchronously
227 * %-EINPROGRESS if the request was successfully started
228 * %-EBUSY if all chsc subchannels are busy
229 * %-ENODEV if no chsc subchannels are available
230 * Context:
231 * interrupts disabled, chsc_lock held
232 */
233static int chsc_async(struct chsc_async_area *chsc_area,
234 struct chsc_request *request)
235{
236 int cc;
237 struct chsc_private *private;
238 struct subchannel *sch = NULL;
239 int ret = -ENODEV;
240 char dbf[10];
241
Heiko Carstensd1bf8592010-02-26 22:37:30 +0100242 chsc_area->header.key = PAGE_DEFAULT_KEY >> 4;
Cornelia Huck9d92a7e2008-07-14 09:59:05 +0200243 while ((sch = chsc_get_next_subchannel(sch))) {
244 spin_lock(sch->lock);
Sebastian Ott85fb5342011-03-15 17:08:28 +0100245 private = dev_get_drvdata(&sch->dev);
Cornelia Huck9d92a7e2008-07-14 09:59:05 +0200246 if (private->request) {
247 spin_unlock(sch->lock);
248 ret = -EBUSY;
249 continue;
250 }
251 chsc_area->header.sid = sch->schid;
252 CHSC_LOG(2, "schid");
253 CHSC_LOG_HEX(2, &sch->schid, sizeof(sch->schid));
254 cc = chsc(chsc_area);
255 sprintf(dbf, "cc:%d", cc);
256 CHSC_LOG(2, dbf);
257 switch (cc) {
258 case 0:
259 ret = 0;
260 break;
261 case 1:
262 sch->schib.scsw.cmd.fctl |= SCSW_FCTL_START_FUNC;
263 ret = -EINPROGRESS;
264 private->request = request;
265 break;
266 case 2:
267 ret = -EBUSY;
268 break;
269 default:
270 ret = -ENODEV;
271 }
272 spin_unlock(sch->lock);
273 CHSC_MSG(2, "chsc on 0.%x.%04x returned cc=%d\n",
274 sch->schid.ssid, sch->schid.sch_no, cc);
275 if (ret == -EINPROGRESS)
276 return -EINPROGRESS;
277 put_device(&sch->dev);
278 if (ret == 0)
279 return 0;
280 }
281 return ret;
282}
283
284static void chsc_log_command(struct chsc_async_area *chsc_area)
285{
286 char dbf[10];
287
288 sprintf(dbf, "CHSC:%x", chsc_area->header.code);
289 CHSC_LOG(0, dbf);
290 CHSC_LOG_HEX(0, chsc_area, 32);
291}
292
293static int chsc_examine_irb(struct chsc_request *request)
294{
295 int backed_up;
296
Julia Lawallb2bbb642008-10-10 21:33:16 +0200297 if (!(scsw_stctl(&request->irb.scsw) & SCSW_STCTL_STATUS_PEND))
Cornelia Huck9d92a7e2008-07-14 09:59:05 +0200298 return -EIO;
299 backed_up = scsw_cstat(&request->irb.scsw) & SCHN_STAT_CHAIN_CHECK;
300 request->irb.scsw.cmd.cstat &= ~SCHN_STAT_CHAIN_CHECK;
301 if (scsw_cstat(&request->irb.scsw) == 0)
302 return 0;
303 if (!backed_up)
304 return 0;
305 if (scsw_cstat(&request->irb.scsw) & SCHN_STAT_PROG_CHECK)
306 return -EIO;
307 if (scsw_cstat(&request->irb.scsw) & SCHN_STAT_PROT_CHECK)
308 return -EPERM;
309 if (scsw_cstat(&request->irb.scsw) & SCHN_STAT_CHN_DATA_CHK)
310 return -EAGAIN;
311 if (scsw_cstat(&request->irb.scsw) & SCHN_STAT_CHN_CTRL_CHK)
312 return -EAGAIN;
313 return -EIO;
314}
315
316static int chsc_ioctl_start(void __user *user_area)
317{
318 struct chsc_request *request;
319 struct chsc_async_area *chsc_area;
320 int ret;
321 char dbf[10];
322
323 if (!css_general_characteristics.dynio)
324 /* It makes no sense to try. */
325 return -EOPNOTSUPP;
326 chsc_area = (void *)get_zeroed_page(GFP_DMA | GFP_KERNEL);
327 if (!chsc_area)
328 return -ENOMEM;
329 request = kzalloc(sizeof(*request), GFP_KERNEL);
330 if (!request) {
331 ret = -ENOMEM;
332 goto out_free;
333 }
334 init_completion(&request->completion);
335 if (copy_from_user(chsc_area, user_area, PAGE_SIZE)) {
336 ret = -EFAULT;
337 goto out_free;
338 }
339 chsc_log_command(chsc_area);
340 spin_lock_irq(&chsc_lock);
341 ret = chsc_async(chsc_area, request);
342 spin_unlock_irq(&chsc_lock);
343 if (ret == -EINPROGRESS) {
344 wait_for_completion(&request->completion);
345 ret = chsc_examine_irb(request);
346 }
347 /* copy area back to user */
348 if (!ret)
349 if (copy_to_user(user_area, chsc_area, PAGE_SIZE))
350 ret = -EFAULT;
351out_free:
352 sprintf(dbf, "ret:%d", ret);
353 CHSC_LOG(0, dbf);
354 kfree(request);
355 free_page((unsigned long)chsc_area);
356 return ret;
357}
358
359static int chsc_ioctl_info_channel_path(void __user *user_cd)
360{
361 struct chsc_chp_cd *cd;
362 int ret, ccode;
363 struct {
364 struct chsc_header request;
365 u32 : 2;
366 u32 m : 1;
367 u32 : 1;
368 u32 fmt1 : 4;
369 u32 cssid : 8;
370 u32 : 8;
371 u32 first_chpid : 8;
372 u32 : 24;
373 u32 last_chpid : 8;
374 u32 : 32;
375 struct chsc_header response;
376 u8 data[PAGE_SIZE - 20];
377 } __attribute__ ((packed)) *scpcd_area;
378
379 scpcd_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
380 if (!scpcd_area)
381 return -ENOMEM;
382 cd = kzalloc(sizeof(*cd), GFP_KERNEL);
383 if (!cd) {
384 ret = -ENOMEM;
385 goto out_free;
386 }
387 if (copy_from_user(cd, user_cd, sizeof(*cd))) {
388 ret = -EFAULT;
389 goto out_free;
390 }
391 scpcd_area->request.length = 0x0010;
392 scpcd_area->request.code = 0x0028;
393 scpcd_area->m = cd->m;
394 scpcd_area->fmt1 = cd->fmt;
395 scpcd_area->cssid = cd->chpid.cssid;
396 scpcd_area->first_chpid = cd->chpid.id;
397 scpcd_area->last_chpid = cd->chpid.id;
398
399 ccode = chsc(scpcd_area);
400 if (ccode != 0) {
401 ret = -EIO;
402 goto out_free;
403 }
404 if (scpcd_area->response.code != 0x0001) {
405 ret = -EIO;
406 CHSC_MSG(0, "scpcd: response code=%x\n",
407 scpcd_area->response.code);
408 goto out_free;
409 }
410 memcpy(&cd->cpcb, &scpcd_area->response, scpcd_area->response.length);
411 if (copy_to_user(user_cd, cd, sizeof(*cd)))
412 ret = -EFAULT;
413 else
414 ret = 0;
415out_free:
416 kfree(cd);
417 free_page((unsigned long)scpcd_area);
418 return ret;
419}
420
421static int chsc_ioctl_info_cu(void __user *user_cd)
422{
423 struct chsc_cu_cd *cd;
424 int ret, ccode;
425 struct {
426 struct chsc_header request;
427 u32 : 2;
428 u32 m : 1;
429 u32 : 1;
430 u32 fmt1 : 4;
431 u32 cssid : 8;
432 u32 : 8;
433 u32 first_cun : 8;
434 u32 : 24;
435 u32 last_cun : 8;
436 u32 : 32;
437 struct chsc_header response;
438 u8 data[PAGE_SIZE - 20];
439 } __attribute__ ((packed)) *scucd_area;
440
441 scucd_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
442 if (!scucd_area)
443 return -ENOMEM;
444 cd = kzalloc(sizeof(*cd), GFP_KERNEL);
445 if (!cd) {
446 ret = -ENOMEM;
447 goto out_free;
448 }
449 if (copy_from_user(cd, user_cd, sizeof(*cd))) {
450 ret = -EFAULT;
451 goto out_free;
452 }
453 scucd_area->request.length = 0x0010;
454 scucd_area->request.code = 0x0028;
455 scucd_area->m = cd->m;
456 scucd_area->fmt1 = cd->fmt;
457 scucd_area->cssid = cd->cssid;
458 scucd_area->first_cun = cd->cun;
459 scucd_area->last_cun = cd->cun;
460
461 ccode = chsc(scucd_area);
462 if (ccode != 0) {
463 ret = -EIO;
464 goto out_free;
465 }
466 if (scucd_area->response.code != 0x0001) {
467 ret = -EIO;
468 CHSC_MSG(0, "scucd: response code=%x\n",
469 scucd_area->response.code);
470 goto out_free;
471 }
472 memcpy(&cd->cucb, &scucd_area->response, scucd_area->response.length);
473 if (copy_to_user(user_cd, cd, sizeof(*cd)))
474 ret = -EFAULT;
475 else
476 ret = 0;
477out_free:
478 kfree(cd);
479 free_page((unsigned long)scucd_area);
480 return ret;
481}
482
483static int chsc_ioctl_info_sch_cu(void __user *user_cud)
484{
485 struct chsc_sch_cud *cud;
486 int ret, ccode;
487 struct {
488 struct chsc_header request;
489 u32 : 2;
490 u32 m : 1;
491 u32 : 5;
492 u32 fmt1 : 4;
493 u32 : 2;
494 u32 ssid : 2;
495 u32 first_sch : 16;
496 u32 : 8;
497 u32 cssid : 8;
498 u32 last_sch : 16;
499 u32 : 32;
500 struct chsc_header response;
501 u8 data[PAGE_SIZE - 20];
502 } __attribute__ ((packed)) *sscud_area;
503
504 sscud_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
505 if (!sscud_area)
506 return -ENOMEM;
507 cud = kzalloc(sizeof(*cud), GFP_KERNEL);
508 if (!cud) {
509 ret = -ENOMEM;
510 goto out_free;
511 }
512 if (copy_from_user(cud, user_cud, sizeof(*cud))) {
513 ret = -EFAULT;
514 goto out_free;
515 }
516 sscud_area->request.length = 0x0010;
517 sscud_area->request.code = 0x0006;
518 sscud_area->m = cud->schid.m;
519 sscud_area->fmt1 = cud->fmt;
520 sscud_area->ssid = cud->schid.ssid;
521 sscud_area->first_sch = cud->schid.sch_no;
522 sscud_area->cssid = cud->schid.cssid;
523 sscud_area->last_sch = cud->schid.sch_no;
524
525 ccode = chsc(sscud_area);
526 if (ccode != 0) {
527 ret = -EIO;
528 goto out_free;
529 }
530 if (sscud_area->response.code != 0x0001) {
531 ret = -EIO;
532 CHSC_MSG(0, "sscud: response code=%x\n",
533 sscud_area->response.code);
534 goto out_free;
535 }
536 memcpy(&cud->scub, &sscud_area->response, sscud_area->response.length);
537 if (copy_to_user(user_cud, cud, sizeof(*cud)))
538 ret = -EFAULT;
539 else
540 ret = 0;
541out_free:
542 kfree(cud);
543 free_page((unsigned long)sscud_area);
544 return ret;
545}
546
547static int chsc_ioctl_conf_info(void __user *user_ci)
548{
549 struct chsc_conf_info *ci;
550 int ret, ccode;
551 struct {
552 struct chsc_header request;
553 u32 : 2;
554 u32 m : 1;
555 u32 : 1;
556 u32 fmt1 : 4;
557 u32 cssid : 8;
558 u32 : 6;
559 u32 ssid : 2;
560 u32 : 8;
561 u64 : 64;
562 struct chsc_header response;
563 u8 data[PAGE_SIZE - 20];
564 } __attribute__ ((packed)) *sci_area;
565
566 sci_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
567 if (!sci_area)
568 return -ENOMEM;
569 ci = kzalloc(sizeof(*ci), GFP_KERNEL);
570 if (!ci) {
571 ret = -ENOMEM;
572 goto out_free;
573 }
574 if (copy_from_user(ci, user_ci, sizeof(*ci))) {
575 ret = -EFAULT;
576 goto out_free;
577 }
578 sci_area->request.length = 0x0010;
579 sci_area->request.code = 0x0012;
580 sci_area->m = ci->id.m;
581 sci_area->fmt1 = ci->fmt;
582 sci_area->cssid = ci->id.cssid;
583 sci_area->ssid = ci->id.ssid;
584
585 ccode = chsc(sci_area);
586 if (ccode != 0) {
587 ret = -EIO;
588 goto out_free;
589 }
590 if (sci_area->response.code != 0x0001) {
591 ret = -EIO;
592 CHSC_MSG(0, "sci: response code=%x\n",
593 sci_area->response.code);
594 goto out_free;
595 }
596 memcpy(&ci->scid, &sci_area->response, sci_area->response.length);
597 if (copy_to_user(user_ci, ci, sizeof(*ci)))
598 ret = -EFAULT;
599 else
600 ret = 0;
601out_free:
602 kfree(ci);
603 free_page((unsigned long)sci_area);
604 return ret;
605}
606
607static int chsc_ioctl_conf_comp_list(void __user *user_ccl)
608{
609 struct chsc_comp_list *ccl;
610 int ret, ccode;
611 struct {
612 struct chsc_header request;
613 u32 ctype : 8;
614 u32 : 4;
615 u32 fmt : 4;
616 u32 : 16;
617 u64 : 64;
618 u32 list_parm[2];
619 u64 : 64;
620 struct chsc_header response;
621 u8 data[PAGE_SIZE - 36];
622 } __attribute__ ((packed)) *sccl_area;
623 struct {
624 u32 m : 1;
625 u32 : 31;
626 u32 cssid : 8;
627 u32 : 16;
628 u32 chpid : 8;
629 } __attribute__ ((packed)) *chpid_parm;
630 struct {
631 u32 f_cssid : 8;
632 u32 l_cssid : 8;
633 u32 : 16;
634 u32 res;
635 } __attribute__ ((packed)) *cssids_parm;
636
637 sccl_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
638 if (!sccl_area)
639 return -ENOMEM;
640 ccl = kzalloc(sizeof(*ccl), GFP_KERNEL);
641 if (!ccl) {
642 ret = -ENOMEM;
643 goto out_free;
644 }
645 if (copy_from_user(ccl, user_ccl, sizeof(*ccl))) {
646 ret = -EFAULT;
647 goto out_free;
648 }
649 sccl_area->request.length = 0x0020;
650 sccl_area->request.code = 0x0030;
651 sccl_area->fmt = ccl->req.fmt;
652 sccl_area->ctype = ccl->req.ctype;
653 switch (sccl_area->ctype) {
654 case CCL_CU_ON_CHP:
655 case CCL_IOP_CHP:
656 chpid_parm = (void *)&sccl_area->list_parm;
657 chpid_parm->m = ccl->req.chpid.m;
658 chpid_parm->cssid = ccl->req.chpid.chp.cssid;
659 chpid_parm->chpid = ccl->req.chpid.chp.id;
660 break;
661 case CCL_CSS_IMG:
662 case CCL_CSS_IMG_CONF_CHAR:
663 cssids_parm = (void *)&sccl_area->list_parm;
664 cssids_parm->f_cssid = ccl->req.cssids.f_cssid;
665 cssids_parm->l_cssid = ccl->req.cssids.l_cssid;
666 break;
667 }
668 ccode = chsc(sccl_area);
669 if (ccode != 0) {
670 ret = -EIO;
671 goto out_free;
672 }
673 if (sccl_area->response.code != 0x0001) {
674 ret = -EIO;
675 CHSC_MSG(0, "sccl: response code=%x\n",
676 sccl_area->response.code);
677 goto out_free;
678 }
679 memcpy(&ccl->sccl, &sccl_area->response, sccl_area->response.length);
680 if (copy_to_user(user_ccl, ccl, sizeof(*ccl)))
681 ret = -EFAULT;
682 else
683 ret = 0;
684out_free:
685 kfree(ccl);
686 free_page((unsigned long)sccl_area);
687 return ret;
688}
689
690static int chsc_ioctl_chpd(void __user *user_chpd)
691{
Sebastian Ott906c9762010-10-25 16:10:30 +0200692 struct chsc_scpd *scpd_area;
Cornelia Huck9d92a7e2008-07-14 09:59:05 +0200693 struct chsc_cpd_info *chpd;
694 int ret;
695
696 chpd = kzalloc(sizeof(*chpd), GFP_KERNEL);
Sebastian Ott906c9762010-10-25 16:10:30 +0200697 scpd_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
698 if (!scpd_area || !chpd) {
699 ret = -ENOMEM;
700 goto out_free;
701 }
Cornelia Huck9d92a7e2008-07-14 09:59:05 +0200702 if (copy_from_user(chpd, user_chpd, sizeof(*chpd))) {
703 ret = -EFAULT;
704 goto out_free;
705 }
706 ret = chsc_determine_channel_path_desc(chpd->chpid, chpd->fmt,
707 chpd->rfmt, chpd->c, chpd->m,
Sebastian Ott906c9762010-10-25 16:10:30 +0200708 scpd_area);
Cornelia Huck9d92a7e2008-07-14 09:59:05 +0200709 if (ret)
710 goto out_free;
Sebastian Ott906c9762010-10-25 16:10:30 +0200711 memcpy(&chpd->chpdb, &scpd_area->response, scpd_area->response.length);
Cornelia Huck9d92a7e2008-07-14 09:59:05 +0200712 if (copy_to_user(user_chpd, chpd, sizeof(*chpd)))
713 ret = -EFAULT;
714out_free:
715 kfree(chpd);
Sebastian Ott906c9762010-10-25 16:10:30 +0200716 free_page((unsigned long)scpd_area);
Cornelia Huck9d92a7e2008-07-14 09:59:05 +0200717 return ret;
718}
719
720static int chsc_ioctl_dcal(void __user *user_dcal)
721{
722 struct chsc_dcal *dcal;
723 int ret, ccode;
724 struct {
725 struct chsc_header request;
726 u32 atype : 8;
727 u32 : 4;
728 u32 fmt : 4;
729 u32 : 16;
730 u32 res0[2];
731 u32 list_parm[2];
732 u32 res1[2];
733 struct chsc_header response;
734 u8 data[PAGE_SIZE - 36];
735 } __attribute__ ((packed)) *sdcal_area;
736
737 sdcal_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
738 if (!sdcal_area)
739 return -ENOMEM;
740 dcal = kzalloc(sizeof(*dcal), GFP_KERNEL);
741 if (!dcal) {
742 ret = -ENOMEM;
743 goto out_free;
744 }
745 if (copy_from_user(dcal, user_dcal, sizeof(*dcal))) {
746 ret = -EFAULT;
747 goto out_free;
748 }
749 sdcal_area->request.length = 0x0020;
750 sdcal_area->request.code = 0x0034;
751 sdcal_area->atype = dcal->req.atype;
752 sdcal_area->fmt = dcal->req.fmt;
753 memcpy(&sdcal_area->list_parm, &dcal->req.list_parm,
754 sizeof(sdcal_area->list_parm));
755
756 ccode = chsc(sdcal_area);
757 if (ccode != 0) {
758 ret = -EIO;
759 goto out_free;
760 }
761 if (sdcal_area->response.code != 0x0001) {
762 ret = -EIO;
763 CHSC_MSG(0, "sdcal: response code=%x\n",
764 sdcal_area->response.code);
765 goto out_free;
766 }
767 memcpy(&dcal->sdcal, &sdcal_area->response,
768 sdcal_area->response.length);
769 if (copy_to_user(user_dcal, dcal, sizeof(*dcal)))
770 ret = -EFAULT;
771 else
772 ret = 0;
773out_free:
774 kfree(dcal);
775 free_page((unsigned long)sdcal_area);
776 return ret;
777}
778
779static long chsc_ioctl(struct file *filp, unsigned int cmd,
780 unsigned long arg)
781{
Heiko Carstens44ee6a82010-01-13 20:44:30 +0100782 void __user *argp;
783
Cornelia Huck9d92a7e2008-07-14 09:59:05 +0200784 CHSC_MSG(2, "chsc_ioctl called, cmd=%x\n", cmd);
Heiko Carstens44ee6a82010-01-13 20:44:30 +0100785 if (is_compat_task())
786 argp = compat_ptr(arg);
787 else
788 argp = (void __user *)arg;
Cornelia Huck9d92a7e2008-07-14 09:59:05 +0200789 switch (cmd) {
790 case CHSC_START:
Heiko Carstens44ee6a82010-01-13 20:44:30 +0100791 return chsc_ioctl_start(argp);
Cornelia Huck9d92a7e2008-07-14 09:59:05 +0200792 case CHSC_INFO_CHANNEL_PATH:
Heiko Carstens44ee6a82010-01-13 20:44:30 +0100793 return chsc_ioctl_info_channel_path(argp);
Cornelia Huck9d92a7e2008-07-14 09:59:05 +0200794 case CHSC_INFO_CU:
Heiko Carstens44ee6a82010-01-13 20:44:30 +0100795 return chsc_ioctl_info_cu(argp);
Cornelia Huck9d92a7e2008-07-14 09:59:05 +0200796 case CHSC_INFO_SCH_CU:
Heiko Carstens44ee6a82010-01-13 20:44:30 +0100797 return chsc_ioctl_info_sch_cu(argp);
Cornelia Huck9d92a7e2008-07-14 09:59:05 +0200798 case CHSC_INFO_CI:
Heiko Carstens44ee6a82010-01-13 20:44:30 +0100799 return chsc_ioctl_conf_info(argp);
Cornelia Huck9d92a7e2008-07-14 09:59:05 +0200800 case CHSC_INFO_CCL:
Heiko Carstens44ee6a82010-01-13 20:44:30 +0100801 return chsc_ioctl_conf_comp_list(argp);
Cornelia Huck9d92a7e2008-07-14 09:59:05 +0200802 case CHSC_INFO_CPD:
Heiko Carstens44ee6a82010-01-13 20:44:30 +0100803 return chsc_ioctl_chpd(argp);
Cornelia Huck9d92a7e2008-07-14 09:59:05 +0200804 case CHSC_INFO_DCAL:
Heiko Carstens44ee6a82010-01-13 20:44:30 +0100805 return chsc_ioctl_dcal(argp);
Cornelia Huck9d92a7e2008-07-14 09:59:05 +0200806 default: /* unknown ioctl number */
807 return -ENOIOCTLCMD;
808 }
809}
810
811static const struct file_operations chsc_fops = {
812 .owner = THIS_MODULE,
Martin Schwidefsky58ea91c2010-05-17 10:00:07 +0200813 .open = nonseekable_open,
Cornelia Huck9d92a7e2008-07-14 09:59:05 +0200814 .unlocked_ioctl = chsc_ioctl,
815 .compat_ioctl = chsc_ioctl,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200816 .llseek = no_llseek,
Cornelia Huck9d92a7e2008-07-14 09:59:05 +0200817};
818
819static struct miscdevice chsc_misc_device = {
820 .minor = MISC_DYNAMIC_MINOR,
821 .name = "chsc",
822 .fops = &chsc_fops,
823};
824
825static int __init chsc_misc_init(void)
826{
827 return misc_register(&chsc_misc_device);
828}
829
830static void chsc_misc_cleanup(void)
831{
832 misc_deregister(&chsc_misc_device);
833}
834
835static int __init chsc_sch_init(void)
836{
837 int ret;
838
839 ret = chsc_init_dbfs();
840 if (ret)
841 return ret;
842 isc_register(CHSC_SCH_ISC);
843 ret = chsc_init_sch_driver();
844 if (ret)
845 goto out_dbf;
846 ret = chsc_misc_init();
847 if (ret)
848 goto out_driver;
849 return ret;
850out_driver:
851 chsc_cleanup_sch_driver();
852out_dbf:
853 isc_unregister(CHSC_SCH_ISC);
854 chsc_remove_dbfs();
855 return ret;
856}
857
858static void __exit chsc_sch_exit(void)
859{
860 chsc_misc_cleanup();
861 chsc_cleanup_sch_driver();
862 isc_unregister(CHSC_SCH_ISC);
863 chsc_remove_dbfs();
864}
865
866module_init(chsc_sch_init);
867module_exit(chsc_sch_exit);