blob: bd06607a5dcc169ee3e1528fc5674525006f93fe [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * drivers/s390/char/raw3270.c
3 * IBM/3270 Driver - core functions.
4 *
5 * Author(s):
6 * Original 3270 Code for 2.4 written by Richard Hitt (UTS Global)
7 * Rewritten for 2.5 by Martin Schwidefsky <schwidefsky@de.ibm.com>
8 * -- Copyright (C) 2003 IBM Deutschland Entwicklung GmbH, IBM Corporation
9 */
10
11#include <linux/config.h>
12#include <linux/bootmem.h>
13#include <linux/module.h>
14#include <linux/err.h>
15#include <linux/init.h>
16#include <linux/interrupt.h>
17#include <linux/list.h>
18#include <linux/slab.h>
19#include <linux/types.h>
20#include <linux/wait.h>
21
22#include <asm/ccwdev.h>
23#include <asm/cio.h>
24#include <asm/ebcdic.h>
25
26#include "raw3270.h"
27
Richard Hitted3cb6f2005-10-30 15:00:10 -080028#include <linux/major.h>
29#include <linux/kdev_t.h>
30#include <linux/device.h>
31
32struct class *class3270;
33
Linus Torvalds1da177e2005-04-16 15:20:36 -070034/* The main 3270 data structure. */
35struct raw3270 {
36 struct list_head list;
37 struct ccw_device *cdev;
38 int minor;
39
40 short model, rows, cols;
41 unsigned long flags;
42
43 struct list_head req_queue; /* Request queue. */
44 struct list_head view_list; /* List of available views. */
45 struct raw3270_view *view; /* Active view. */
46
47 struct timer_list timer; /* Device timer. */
48
49 unsigned char *ascebc; /* ascii -> ebcdic table */
Richard Hitted3cb6f2005-10-30 15:00:10 -080050 struct class_device *clttydev; /* 3270-class tty device ptr */
51 struct class_device *cltubdev; /* 3270-class tub device ptr */
Linus Torvalds1da177e2005-04-16 15:20:36 -070052};
53
54/* raw3270->flags */
55#define RAW3270_FLAGS_14BITADDR 0 /* 14-bit buffer addresses */
56#define RAW3270_FLAGS_BUSY 1 /* Device busy, leave it alone */
57#define RAW3270_FLAGS_ATTN 2 /* Device sent an ATTN interrupt */
58#define RAW3270_FLAGS_READY 4 /* Device is useable by views */
59#define RAW3270_FLAGS_CONSOLE 8 /* Device is the console. */
60
61/* Semaphore to protect global data of raw3270 (devices, views, etc). */
62static DECLARE_MUTEX(raw3270_sem);
63
64/* List of 3270 devices. */
65static struct list_head raw3270_devices = LIST_HEAD_INIT(raw3270_devices);
66
67/*
68 * Flag to indicate if the driver has been registered. Some operations
69 * like waiting for the end of i/o need to be done differently as long
70 * as the kernel is still starting up (console support).
71 */
72static int raw3270_registered;
73
74/* Module parameters */
75static int tubxcorrect = 0;
76module_param(tubxcorrect, bool, 0);
77
78/*
79 * Wait queue for device init/delete, view delete.
80 */
81DECLARE_WAIT_QUEUE_HEAD(raw3270_wait_queue);
82
83/*
84 * Encode array for 12 bit 3270 addresses.
85 */
86unsigned char raw3270_ebcgraf[64] = {
87 0x40, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
88 0xc8, 0xc9, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
89 0x50, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
90 0xd8, 0xd9, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
91 0x60, 0x61, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,
92 0xe8, 0xe9, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
93 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
94 0xf8, 0xf9, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f
95};
96
97void
98raw3270_buffer_address(struct raw3270 *rp, char *cp, unsigned short addr)
99{
100 if (test_bit(RAW3270_FLAGS_14BITADDR, &rp->flags)) {
101 cp[0] = (addr >> 8) & 0x3f;
102 cp[1] = addr & 0xff;
103 } else {
104 cp[0] = raw3270_ebcgraf[(addr >> 6) & 0x3f];
105 cp[1] = raw3270_ebcgraf[addr & 0x3f];
106 }
107}
108
109/*
110 * Allocate a new 3270 ccw request
111 */
112struct raw3270_request *
113raw3270_request_alloc(size_t size)
114{
115 struct raw3270_request *rq;
116
117 /* Allocate request structure */
Eric Sesterhenn88abaab2006-03-24 03:15:31 -0800118 rq = kzalloc(sizeof(struct raw3270_request), GFP_KERNEL | GFP_DMA);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 if (!rq)
120 return ERR_PTR(-ENOMEM);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121
122 /* alloc output buffer. */
123 if (size > 0) {
124 rq->buffer = kmalloc(size, GFP_KERNEL | GFP_DMA);
125 if (!rq->buffer) {
126 kfree(rq);
127 return ERR_PTR(-ENOMEM);
128 }
129 }
130 rq->size = size;
131 INIT_LIST_HEAD(&rq->list);
132
133 /*
134 * Setup ccw.
135 */
136 rq->ccw.cda = __pa(rq->buffer);
137 rq->ccw.flags = CCW_FLAG_SLI;
138
139 return rq;
140}
141
142#ifdef CONFIG_TN3270_CONSOLE
143/*
144 * Allocate a new 3270 ccw request from bootmem. Only works very
145 * early in the boot process. Only con3270.c should be using this.
146 */
147struct raw3270_request *
148raw3270_request_alloc_bootmem(size_t size)
149{
150 struct raw3270_request *rq;
151
152 rq = alloc_bootmem_low(sizeof(struct raw3270));
153 if (!rq)
154 return ERR_PTR(-ENOMEM);
155 memset(rq, 0, sizeof(struct raw3270_request));
156
157 /* alloc output buffer. */
158 if (size > 0) {
159 rq->buffer = alloc_bootmem_low(size);
160 if (!rq->buffer) {
161 free_bootmem((unsigned long) rq,
162 sizeof(struct raw3270));
163 return ERR_PTR(-ENOMEM);
164 }
165 }
166 rq->size = size;
167 INIT_LIST_HEAD(&rq->list);
168
169 /*
170 * Setup ccw.
171 */
172 rq->ccw.cda = __pa(rq->buffer);
173 rq->ccw.flags = CCW_FLAG_SLI;
174
175 return rq;
176}
177#endif
178
179/*
180 * Free 3270 ccw request
181 */
182void
183raw3270_request_free (struct raw3270_request *rq)
184{
Jesper Juhl17fd6822005-11-07 01:01:30 -0800185 kfree(rq->buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 kfree(rq);
187}
188
189/*
190 * Reset request to initial state.
191 */
192void
193raw3270_request_reset(struct raw3270_request *rq)
194{
195 BUG_ON(!list_empty(&rq->list));
196 rq->ccw.cmd_code = 0;
197 rq->ccw.count = 0;
198 rq->ccw.cda = __pa(rq->buffer);
199 rq->ccw.flags = CCW_FLAG_SLI;
200 rq->rescnt = 0;
201 rq->rc = 0;
202}
203
204/*
205 * Set command code to ccw of a request.
206 */
207void
208raw3270_request_set_cmd(struct raw3270_request *rq, u8 cmd)
209{
210 rq->ccw.cmd_code = cmd;
211}
212
213/*
214 * Add data fragment to output buffer.
215 */
216int
217raw3270_request_add_data(struct raw3270_request *rq, void *data, size_t size)
218{
219 if (size + rq->ccw.count > rq->size)
220 return -E2BIG;
221 memcpy(rq->buffer + rq->ccw.count, data, size);
222 rq->ccw.count += size;
223 return 0;
224}
225
226/*
227 * Set address/length pair to ccw of a request.
228 */
229void
230raw3270_request_set_data(struct raw3270_request *rq, void *data, size_t size)
231{
232 rq->ccw.cda = __pa(data);
233 rq->ccw.count = size;
234}
235
236/*
237 * Set idal buffer to ccw of a request.
238 */
239void
240raw3270_request_set_idal(struct raw3270_request *rq, struct idal_buffer *ib)
241{
242 rq->ccw.cda = __pa(ib->data);
243 rq->ccw.count = ib->size;
244 rq->ccw.flags |= CCW_FLAG_IDA;
245}
246
247/*
248 * Stop running ccw.
249 */
250static int
251raw3270_halt_io_nolock(struct raw3270 *rp, struct raw3270_request *rq)
252{
253 int retries;
254 int rc;
255
256 if (raw3270_request_final(rq))
257 return 0;
258 /* Check if interrupt has already been processed */
259 for (retries = 0; retries < 5; retries++) {
260 if (retries < 2)
261 rc = ccw_device_halt(rp->cdev, (long) rq);
262 else
263 rc = ccw_device_clear(rp->cdev, (long) rq);
264 if (rc == 0)
265 break; /* termination successful */
266 }
267 return rc;
268}
269
270static int
271raw3270_halt_io(struct raw3270 *rp, struct raw3270_request *rq)
272{
273 unsigned long flags;
274 int rc;
275
276 spin_lock_irqsave(get_ccwdev_lock(rp->cdev), flags);
277 rc = raw3270_halt_io_nolock(rp, rq);
278 spin_unlock_irqrestore(get_ccwdev_lock(rp->cdev), flags);
279 return rc;
280}
281
282/*
283 * Add the request to the request queue, try to start it if the
284 * 3270 device is idle. Return without waiting for end of i/o.
285 */
286static int
287__raw3270_start(struct raw3270 *rp, struct raw3270_view *view,
288 struct raw3270_request *rq)
289{
290 rq->view = view;
291 raw3270_get_view(view);
292 if (list_empty(&rp->req_queue) &&
293 !test_bit(RAW3270_FLAGS_BUSY, &rp->flags)) {
294 /* No other requests are on the queue. Start this one. */
295 rq->rc = ccw_device_start(rp->cdev, &rq->ccw,
296 (unsigned long) rq, 0, 0);
297 if (rq->rc) {
298 raw3270_put_view(view);
299 return rq->rc;
300 }
301 }
302 list_add_tail(&rq->list, &rp->req_queue);
303 return 0;
304}
305
306int
307raw3270_start(struct raw3270_view *view, struct raw3270_request *rq)
308{
309 unsigned long flags;
310 struct raw3270 *rp;
311 int rc;
312
313 spin_lock_irqsave(get_ccwdev_lock(view->dev->cdev), flags);
314 rp = view->dev;
315 if (!rp || rp->view != view)
316 rc = -EACCES;
317 else if (!test_bit(RAW3270_FLAGS_READY, &rp->flags))
318 rc = -ENODEV;
319 else
320 rc = __raw3270_start(rp, view, rq);
321 spin_unlock_irqrestore(get_ccwdev_lock(view->dev->cdev), flags);
322 return rc;
323}
324
325int
Richard Hitted3cb6f2005-10-30 15:00:10 -0800326raw3270_start_locked(struct raw3270_view *view, struct raw3270_request *rq)
327{
328 struct raw3270 *rp;
329 int rc;
330
331 rp = view->dev;
332 if (!rp || rp->view != view)
333 rc = -EACCES;
334 else if (!test_bit(RAW3270_FLAGS_READY, &rp->flags))
335 rc = -ENODEV;
336 else
337 rc = __raw3270_start(rp, view, rq);
338 return rc;
339}
340
341int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342raw3270_start_irq(struct raw3270_view *view, struct raw3270_request *rq)
343{
344 struct raw3270 *rp;
345
346 rp = view->dev;
347 rq->view = view;
348 raw3270_get_view(view);
349 list_add_tail(&rq->list, &rp->req_queue);
350 return 0;
351}
352
353/*
354 * 3270 interrupt routine, called from the ccw_device layer
355 */
356static void
357raw3270_irq (struct ccw_device *cdev, unsigned long intparm, struct irb *irb)
358{
359 struct raw3270 *rp;
360 struct raw3270_view *view;
361 struct raw3270_request *rq;
362 int rc;
363
364 rp = (struct raw3270 *) cdev->dev.driver_data;
365 if (!rp)
366 return;
367 rq = (struct raw3270_request *) intparm;
368 view = rq ? rq->view : rp->view;
369
370 if (IS_ERR(irb))
371 rc = RAW3270_IO_RETRY;
372 else if (irb->scsw.fctl & SCSW_FCTL_HALT_FUNC) {
373 rq->rc = -EIO;
374 rc = RAW3270_IO_DONE;
375 } else if (irb->scsw.dstat == (DEV_STAT_CHN_END | DEV_STAT_DEV_END |
376 DEV_STAT_UNIT_EXCEP)) {
377 /* Handle CE-DE-UE and subsequent UDE */
378 set_bit(RAW3270_FLAGS_BUSY, &rp->flags);
379 rc = RAW3270_IO_BUSY;
380 } else if (test_bit(RAW3270_FLAGS_BUSY, &rp->flags)) {
381 /* Wait for UDE if busy flag is set. */
382 if (irb->scsw.dstat & DEV_STAT_DEV_END) {
383 clear_bit(RAW3270_FLAGS_BUSY, &rp->flags);
384 /* Got it, now retry. */
385 rc = RAW3270_IO_RETRY;
386 } else
387 rc = RAW3270_IO_BUSY;
388 } else if (view)
389 rc = view->fn->intv(view, rq, irb);
390 else
391 rc = RAW3270_IO_DONE;
392
393 switch (rc) {
394 case RAW3270_IO_DONE:
395 break;
396 case RAW3270_IO_BUSY:
397 /*
398 * Intervention required by the operator. We have to wait
399 * for unsolicited device end.
400 */
401 return;
402 case RAW3270_IO_RETRY:
403 if (!rq)
404 break;
405 rq->rc = ccw_device_start(rp->cdev, &rq->ccw,
406 (unsigned long) rq, 0, 0);
407 if (rq->rc == 0)
408 return; /* Sucessfully restarted. */
409 break;
410 case RAW3270_IO_STOP:
411 if (!rq)
412 break;
413 raw3270_halt_io_nolock(rp, rq);
414 rq->rc = -EIO;
415 break;
416 default:
417 BUG();
418 }
419 if (rq) {
420 BUG_ON(list_empty(&rq->list));
421 /* The request completed, remove from queue and do callback. */
422 list_del_init(&rq->list);
423 if (rq->callback)
424 rq->callback(rq, rq->callback_data);
425 /* Do put_device for get_device in raw3270_start. */
426 raw3270_put_view(view);
427 }
428 /*
429 * Try to start each request on request queue until one is
430 * started successful.
431 */
432 while (!list_empty(&rp->req_queue)) {
433 rq = list_entry(rp->req_queue.next,struct raw3270_request,list);
434 rq->rc = ccw_device_start(rp->cdev, &rq->ccw,
435 (unsigned long) rq, 0, 0);
436 if (rq->rc == 0)
437 break;
438 /* Start failed. Remove request and do callback. */
439 list_del_init(&rq->list);
440 if (rq->callback)
441 rq->callback(rq, rq->callback_data);
442 /* Do put_device for get_device in raw3270_start. */
443 raw3270_put_view(view);
444 }
445}
446
447/*
448 * Size sensing.
449 */
450
451struct raw3270_ua { /* Query Reply structure for Usable Area */
452 struct { /* Usable Area Query Reply Base */
453 short l; /* Length of this structured field */
454 char sfid; /* 0x81 if Query Reply */
455 char qcode; /* 0x81 if Usable Area */
456 char flags0;
457 char flags1;
458 short w; /* Width of usable area */
459 short h; /* Heigth of usavle area */
460 char units; /* 0x00:in; 0x01:mm */
461 int xr;
462 int yr;
463 char aw;
464 char ah;
465 short buffsz; /* Character buffer size, bytes */
466 char xmin;
467 char ymin;
468 char xmax;
469 char ymax;
470 } __attribute__ ((packed)) uab;
471 struct { /* Alternate Usable Area Self-Defining Parameter */
472 char l; /* Length of this Self-Defining Parm */
473 char sdpid; /* 0x02 if Alternate Usable Area */
474 char res;
475 char auaid; /* 0x01 is Id for the A U A */
476 short wauai; /* Width of AUAi */
477 short hauai; /* Height of AUAi */
478 char auaunits; /* 0x00:in, 0x01:mm */
479 int auaxr;
480 int auayr;
481 char awauai;
482 char ahauai;
483 } __attribute__ ((packed)) aua;
484} __attribute__ ((packed));
485
486static unsigned char raw3270_init_data[256];
487static struct raw3270_request raw3270_init_request;
488static struct diag210 raw3270_init_diag210;
489static DECLARE_MUTEX(raw3270_init_sem);
490
491static int
492raw3270_init_irq(struct raw3270_view *view, struct raw3270_request *rq,
493 struct irb *irb)
494{
495 /*
496 * Unit-Check Processing:
497 * Expect Command Reject or Intervention Required.
498 */
499 if (irb->scsw.dstat & DEV_STAT_UNIT_CHECK) {
500 /* Request finished abnormally. */
501 if (irb->ecw[0] & SNS0_INTERVENTION_REQ) {
502 set_bit(RAW3270_FLAGS_BUSY, &view->dev->flags);
503 return RAW3270_IO_BUSY;
504 }
505 }
506 if (rq) {
507 if (irb->scsw.dstat & DEV_STAT_UNIT_CHECK) {
508 if (irb->ecw[0] & SNS0_CMD_REJECT)
509 rq->rc = -EOPNOTSUPP;
510 else
511 rq->rc = -EIO;
512 } else
513 /* Request finished normally. Copy residual count. */
514 rq->rescnt = irb->scsw.count;
515 }
516 if (irb->scsw.dstat & DEV_STAT_ATTENTION) {
517 set_bit(RAW3270_FLAGS_ATTN, &view->dev->flags);
518 wake_up(&raw3270_wait_queue);
519 }
520 return RAW3270_IO_DONE;
521}
522
523static struct raw3270_fn raw3270_init_fn = {
524 .intv = raw3270_init_irq
525};
526
527static struct raw3270_view raw3270_init_view = {
528 .fn = &raw3270_init_fn
529};
530
531/*
532 * raw3270_wait/raw3270_wait_interruptible/__raw3270_wakeup
533 * Wait for end of request. The request must have been started
534 * with raw3270_start, rc = 0. The device lock may NOT have been
535 * released between calling raw3270_start and raw3270_wait.
536 */
537static void
538raw3270_wake_init(struct raw3270_request *rq, void *data)
539{
540 wake_up((wait_queue_head_t *) data);
541}
542
543/*
544 * Special wait function that can cope with console initialization.
545 */
546static int
547raw3270_start_init(struct raw3270 *rp, struct raw3270_view *view,
548 struct raw3270_request *rq)
549{
550 unsigned long flags;
551 wait_queue_head_t wq;
552 int rc;
553
554#ifdef CONFIG_TN3270_CONSOLE
555 if (raw3270_registered == 0) {
556 spin_lock_irqsave(get_ccwdev_lock(view->dev->cdev), flags);
557 rq->callback = 0;
558 rc = __raw3270_start(rp, view, rq);
559 if (rc == 0)
560 while (!raw3270_request_final(rq)) {
561 wait_cons_dev();
562 barrier();
563 }
564 spin_unlock_irqrestore(get_ccwdev_lock(view->dev->cdev), flags);
565 return rq->rc;
566 }
567#endif
568 init_waitqueue_head(&wq);
569 rq->callback = raw3270_wake_init;
570 rq->callback_data = &wq;
571 spin_lock_irqsave(get_ccwdev_lock(view->dev->cdev), flags);
572 rc = __raw3270_start(rp, view, rq);
573 spin_unlock_irqrestore(get_ccwdev_lock(view->dev->cdev), flags);
574 if (rc)
575 return rc;
576 /* Now wait for the completion. */
577 rc = wait_event_interruptible(wq, raw3270_request_final(rq));
578 if (rc == -ERESTARTSYS) { /* Interrupted by a signal. */
579 raw3270_halt_io(view->dev, rq);
580 /* No wait for the halt to complete. */
581 wait_event(wq, raw3270_request_final(rq));
582 return -ERESTARTSYS;
583 }
584 return rq->rc;
585}
586
587static int
588__raw3270_size_device_vm(struct raw3270 *rp)
589{
590 int rc, model;
591
592 raw3270_init_diag210.vrdcdvno =
593 _ccw_device_get_device_number(rp->cdev);
594 raw3270_init_diag210.vrdclen = sizeof(struct diag210);
595 rc = diag210(&raw3270_init_diag210);
596 if (rc)
597 return rc;
598 model = raw3270_init_diag210.vrdccrmd;
599 switch (model) {
600 case 2:
601 rp->model = model;
602 rp->rows = 24;
603 rp->cols = 80;
604 break;
605 case 3:
606 rp->model = model;
607 rp->rows = 32;
608 rp->cols = 80;
609 break;
610 case 4:
611 rp->model = model;
612 rp->rows = 43;
613 rp->cols = 80;
614 break;
615 case 5:
616 rp->model = model;
617 rp->rows = 27;
618 rp->cols = 132;
619 break;
620 default:
621 printk(KERN_WARNING "vrdccrmd is 0x%.8x\n", model);
622 rc = -EOPNOTSUPP;
623 break;
624 }
625 return rc;
626}
627
628static int
629__raw3270_size_device(struct raw3270 *rp)
630{
631 static const unsigned char wbuf[] =
632 { 0x00, 0x07, 0x01, 0xff, 0x03, 0x00, 0x81 };
633 struct raw3270_ua *uap;
634 unsigned short count;
635 int rc;
636
637 /*
638 * To determine the size of the 3270 device we need to do:
639 * 1) send a 'read partition' data stream to the device
640 * 2) wait for the attn interrupt that preceeds the query reply
641 * 3) do a read modified to get the query reply
642 * To make things worse we have to cope with intervention
643 * required (3270 device switched to 'stand-by') and command
644 * rejects (old devices that can't do 'read partition').
645 */
646 memset(&raw3270_init_request, 0, sizeof(raw3270_init_request));
647 memset(raw3270_init_data, 0, sizeof(raw3270_init_data));
648 /* Store 'read partition' data stream to raw3270_init_data */
649 memcpy(raw3270_init_data, wbuf, sizeof(wbuf));
650 INIT_LIST_HEAD(&raw3270_init_request.list);
651 raw3270_init_request.ccw.cmd_code = TC_WRITESF;
652 raw3270_init_request.ccw.flags = CCW_FLAG_SLI;
653 raw3270_init_request.ccw.count = sizeof(wbuf);
654 raw3270_init_request.ccw.cda = (__u32) __pa(raw3270_init_data);
655
656 rc = raw3270_start_init(rp, &raw3270_init_view, &raw3270_init_request);
Martin Schwidefsky3863e722005-09-03 15:58:06 -0700657 if (rc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 /* Check error cases: -ERESTARTSYS, -EIO and -EOPNOTSUPP */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660
661 /* Wait for attention interrupt. */
662#ifdef CONFIG_TN3270_CONSOLE
663 if (raw3270_registered == 0) {
664 unsigned long flags;
665
666 spin_lock_irqsave(get_ccwdev_lock(rp->cdev), flags);
667 while (!test_and_clear_bit(RAW3270_FLAGS_ATTN, &rp->flags))
668 wait_cons_dev();
669 spin_unlock_irqrestore(get_ccwdev_lock(rp->cdev), flags);
670 } else
671#endif
672 rc = wait_event_interruptible(raw3270_wait_queue,
673 test_and_clear_bit(RAW3270_FLAGS_ATTN, &rp->flags));
674 if (rc)
675 return rc;
676
677 /*
678 * The device accepted the 'read partition' command. Now
679 * set up a read ccw and issue it.
680 */
681 raw3270_init_request.ccw.cmd_code = TC_READMOD;
682 raw3270_init_request.ccw.flags = CCW_FLAG_SLI;
683 raw3270_init_request.ccw.count = sizeof(raw3270_init_data);
684 raw3270_init_request.ccw.cda = (__u32) __pa(raw3270_init_data);
685 rc = raw3270_start_init(rp, &raw3270_init_view, &raw3270_init_request);
686 if (rc)
687 return rc;
688 /* Got a Query Reply */
689 count = sizeof(raw3270_init_data) - raw3270_init_request.rescnt;
690 uap = (struct raw3270_ua *) (raw3270_init_data + 1);
691 /* Paranoia check. */
692 if (raw3270_init_data[0] != 0x88 || uap->uab.qcode != 0x81)
693 return -EOPNOTSUPP;
694 /* Copy rows/columns of default Usable Area */
695 rp->rows = uap->uab.h;
696 rp->cols = uap->uab.w;
697 /* Check for 14 bit addressing */
698 if ((uap->uab.flags0 & 0x0d) == 0x01)
699 set_bit(RAW3270_FLAGS_14BITADDR, &rp->flags);
700 /* Check for Alternate Usable Area */
701 if (uap->uab.l == sizeof(struct raw3270_ua) &&
702 uap->aua.sdpid == 0x02) {
703 rp->rows = uap->aua.hauai;
704 rp->cols = uap->aua.wauai;
705 }
706 return 0;
707}
708
709static int
710raw3270_size_device(struct raw3270 *rp)
711{
712 int rc;
713
714 down(&raw3270_init_sem);
715 rp->view = &raw3270_init_view;
716 raw3270_init_view.dev = rp;
Martin Schwidefsky3863e722005-09-03 15:58:06 -0700717 if (MACHINE_IS_VM)
718 rc = __raw3270_size_device_vm(rp);
719 else
720 rc = __raw3270_size_device(rp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 raw3270_init_view.dev = 0;
722 rp->view = 0;
723 up(&raw3270_init_sem);
724 if (rc == 0) { /* Found something. */
725 /* Try to find a model. */
726 rp->model = 0;
727 if (rp->rows == 24 && rp->cols == 80)
728 rp->model = 2;
729 if (rp->rows == 32 && rp->cols == 80)
730 rp->model = 3;
731 if (rp->rows == 43 && rp->cols == 80)
732 rp->model = 4;
733 if (rp->rows == 27 && rp->cols == 132)
734 rp->model = 5;
Martin Schwidefsky3863e722005-09-03 15:58:06 -0700735 } else {
736 /* Couldn't detect size. Use default model 2. */
737 rp->model = 2;
738 rp->rows = 24;
739 rp->cols = 80;
740 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741 }
742 return rc;
743}
744
745static int
746raw3270_reset_device(struct raw3270 *rp)
747{
748 int rc;
749
750 down(&raw3270_init_sem);
751 memset(&raw3270_init_request, 0, sizeof(raw3270_init_request));
752 memset(raw3270_init_data, 0, sizeof(raw3270_init_data));
753 /* Store reset data stream to raw3270_init_data/raw3270_init_request */
754 raw3270_init_data[0] = TW_KR;
755 INIT_LIST_HEAD(&raw3270_init_request.list);
756 raw3270_init_request.ccw.cmd_code = TC_EWRITEA;
757 raw3270_init_request.ccw.flags = CCW_FLAG_SLI;
758 raw3270_init_request.ccw.count = 1;
759 raw3270_init_request.ccw.cda = (__u32) __pa(raw3270_init_data);
760 rp->view = &raw3270_init_view;
761 raw3270_init_view.dev = rp;
762 rc = raw3270_start_init(rp, &raw3270_init_view, &raw3270_init_request);
763 raw3270_init_view.dev = 0;
764 rp->view = 0;
765 up(&raw3270_init_sem);
766 return rc;
767}
768
Richard Hitted3cb6f2005-10-30 15:00:10 -0800769int
770raw3270_reset(struct raw3270_view *view)
771{
772 struct raw3270 *rp;
773 int rc;
774
775 rp = view->dev;
776 if (!rp || rp->view != view)
777 rc = -EACCES;
778 else if (!test_bit(RAW3270_FLAGS_READY, &rp->flags))
779 rc = -ENODEV;
780 else
781 rc = raw3270_reset_device(view->dev);
782 return rc;
783}
784
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785/*
786 * Setup new 3270 device.
787 */
788static int
789raw3270_setup_device(struct ccw_device *cdev, struct raw3270 *rp, char *ascebc)
790{
791 struct list_head *l;
792 struct raw3270 *tmp;
793 int minor;
794
795 memset(rp, 0, sizeof(struct raw3270));
796 /* Copy ebcdic -> ascii translation table. */
797 memcpy(ascebc, _ascebc, 256);
798 if (tubxcorrect) {
799 /* correct brackets and circumflex */
800 ascebc['['] = 0xad;
801 ascebc[']'] = 0xbd;
802 ascebc['^'] = 0xb0;
803 }
804 rp->ascebc = ascebc;
805
806 /* Set defaults. */
807 rp->rows = 24;
808 rp->cols = 80;
809
810 INIT_LIST_HEAD(&rp->req_queue);
811 INIT_LIST_HEAD(&rp->view_list);
812
813 /*
814 * Add device to list and find the smallest unused minor
Richard Hitted3cb6f2005-10-30 15:00:10 -0800815 * number for it. Note: there is no device with minor 0,
816 * see special case for fs3270.c:fs3270_open().
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817 */
818 down(&raw3270_sem);
819 /* Keep the list sorted. */
Richard Hitted3cb6f2005-10-30 15:00:10 -0800820 minor = RAW3270_FIRSTMINOR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821 rp->minor = -1;
822 list_for_each(l, &raw3270_devices) {
823 tmp = list_entry(l, struct raw3270, list);
824 if (tmp->minor > minor) {
825 rp->minor = minor;
826 __list_add(&rp->list, l->prev, l);
827 break;
828 }
829 minor++;
830 }
Richard Hitted3cb6f2005-10-30 15:00:10 -0800831 if (rp->minor == -1 && minor < RAW3270_MAXDEVS + RAW3270_FIRSTMINOR) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832 rp->minor = minor;
833 list_add_tail(&rp->list, &raw3270_devices);
834 }
835 up(&raw3270_sem);
836 /* No free minor number? Then give up. */
837 if (rp->minor == -1)
838 return -EUSERS;
839 rp->cdev = cdev;
840 cdev->dev.driver_data = rp;
841 cdev->handler = raw3270_irq;
842 return 0;
843}
844
845#ifdef CONFIG_TN3270_CONSOLE
846/*
847 * Setup 3270 device configured as console.
848 */
849struct raw3270 *
850raw3270_setup_console(struct ccw_device *cdev)
851{
852 struct raw3270 *rp;
853 char *ascebc;
854 int rc;
855
856 rp = (struct raw3270 *) alloc_bootmem(sizeof(struct raw3270));
857 ascebc = (char *) alloc_bootmem(256);
858 rc = raw3270_setup_device(cdev, rp, ascebc);
859 if (rc)
860 return ERR_PTR(rc);
861 set_bit(RAW3270_FLAGS_CONSOLE, &rp->flags);
862 rc = raw3270_reset_device(rp);
863 if (rc)
864 return ERR_PTR(rc);
865 rc = raw3270_size_device(rp);
866 if (rc)
867 return ERR_PTR(rc);
868 rc = raw3270_reset_device(rp);
869 if (rc)
870 return ERR_PTR(rc);
871 set_bit(RAW3270_FLAGS_READY, &rp->flags);
872 return rp;
873}
874
875void
876raw3270_wait_cons_dev(struct raw3270 *rp)
877{
878 unsigned long flags;
879
880 spin_lock_irqsave(get_ccwdev_lock(rp->cdev), flags);
881 wait_cons_dev();
882 spin_unlock_irqrestore(get_ccwdev_lock(rp->cdev), flags);
883}
884
885#endif
886
887/*
888 * Create a 3270 device structure.
889 */
890static struct raw3270 *
891raw3270_create_device(struct ccw_device *cdev)
892{
893 struct raw3270 *rp;
894 char *ascebc;
895 int rc;
896
897 rp = kmalloc(sizeof(struct raw3270), GFP_KERNEL);
898 if (!rp)
899 return ERR_PTR(-ENOMEM);
900 ascebc = kmalloc(256, GFP_KERNEL);
901 if (!ascebc) {
902 kfree(rp);
903 return ERR_PTR(-ENOMEM);
904 }
905 rc = raw3270_setup_device(cdev, rp, ascebc);
906 if (rc) {
907 kfree(rp->ascebc);
908 kfree(rp);
909 rp = ERR_PTR(rc);
910 }
911 /* Get reference to ccw_device structure. */
912 get_device(&cdev->dev);
913 return rp;
914}
915
916/*
917 * Activate a view.
918 */
919int
920raw3270_activate_view(struct raw3270_view *view)
921{
922 struct raw3270 *rp;
923 struct raw3270_view *oldview, *nv;
924 unsigned long flags;
925 int rc;
926
927 rp = view->dev;
928 if (!rp)
929 return -ENODEV;
930 spin_lock_irqsave(get_ccwdev_lock(rp->cdev), flags);
931 if (rp->view == view)
932 rc = 0;
933 else if (!test_bit(RAW3270_FLAGS_READY, &rp->flags))
934 rc = -ENODEV;
935 else {
936 oldview = 0;
937 if (rp->view) {
938 oldview = rp->view;
939 oldview->fn->deactivate(oldview);
940 }
941 rp->view = view;
942 rc = view->fn->activate(view);
943 if (rc) {
944 /* Didn't work. Try to reactivate the old view. */
945 rp->view = oldview;
946 if (!oldview || oldview->fn->activate(oldview) != 0) {
947 /* Didn't work as well. Try any other view. */
948 list_for_each_entry(nv, &rp->view_list, list)
949 if (nv != view && nv != oldview) {
950 rp->view = nv;
951 if (nv->fn->activate(nv) == 0)
952 break;
953 rp->view = 0;
954 }
955 }
956 }
957 }
958 spin_unlock_irqrestore(get_ccwdev_lock(rp->cdev), flags);
959 return rc;
960}
961
962/*
963 * Deactivate current view.
964 */
965void
966raw3270_deactivate_view(struct raw3270_view *view)
967{
968 unsigned long flags;
969 struct raw3270 *rp;
970
971 rp = view->dev;
972 if (!rp)
973 return;
974 spin_lock_irqsave(get_ccwdev_lock(rp->cdev), flags);
975 if (rp->view == view) {
976 view->fn->deactivate(view);
977 rp->view = 0;
978 /* Move deactivated view to end of list. */
979 list_del_init(&view->list);
980 list_add_tail(&view->list, &rp->view_list);
981 /* Try to activate another view. */
982 if (test_bit(RAW3270_FLAGS_READY, &rp->flags)) {
Richard Hitted3cb6f2005-10-30 15:00:10 -0800983 list_for_each_entry(view, &rp->view_list, list) {
984 rp->view = view;
985 if (view->fn->activate(view) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986 break;
Richard Hitted3cb6f2005-10-30 15:00:10 -0800987 rp->view = 0;
988 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989 }
990 }
991 spin_unlock_irqrestore(get_ccwdev_lock(rp->cdev), flags);
992}
993
994/*
995 * Add view to device with minor "minor".
996 */
997int
998raw3270_add_view(struct raw3270_view *view, struct raw3270_fn *fn, int minor)
999{
1000 unsigned long flags;
1001 struct raw3270 *rp;
1002 int rc;
1003
Richard Hitted3cb6f2005-10-30 15:00:10 -08001004 if (minor <= 0)
1005 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006 down(&raw3270_sem);
1007 rc = -ENODEV;
1008 list_for_each_entry(rp, &raw3270_devices, list) {
1009 if (rp->minor != minor)
1010 continue;
1011 spin_lock_irqsave(get_ccwdev_lock(rp->cdev), flags);
1012 if (test_bit(RAW3270_FLAGS_READY, &rp->flags)) {
1013 atomic_set(&view->ref_count, 2);
1014 view->dev = rp;
1015 view->fn = fn;
1016 view->model = rp->model;
1017 view->rows = rp->rows;
1018 view->cols = rp->cols;
1019 view->ascebc = rp->ascebc;
1020 spin_lock_init(&view->lock);
Richard Hitted3cb6f2005-10-30 15:00:10 -08001021 list_add(&view->list, &rp->view_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022 rc = 0;
1023 }
1024 spin_unlock_irqrestore(get_ccwdev_lock(rp->cdev), flags);
1025 break;
1026 }
1027 up(&raw3270_sem);
1028 return rc;
1029}
1030
1031/*
1032 * Find specific view of device with minor "minor".
1033 */
1034struct raw3270_view *
1035raw3270_find_view(struct raw3270_fn *fn, int minor)
1036{
1037 struct raw3270 *rp;
1038 struct raw3270_view *view, *tmp;
1039 unsigned long flags;
1040
1041 down(&raw3270_sem);
1042 view = ERR_PTR(-ENODEV);
1043 list_for_each_entry(rp, &raw3270_devices, list) {
1044 if (rp->minor != minor)
1045 continue;
1046 spin_lock_irqsave(get_ccwdev_lock(rp->cdev), flags);
1047 if (test_bit(RAW3270_FLAGS_READY, &rp->flags)) {
1048 view = ERR_PTR(-ENOENT);
1049 list_for_each_entry(tmp, &rp->view_list, list) {
1050 if (tmp->fn == fn) {
1051 raw3270_get_view(tmp);
1052 view = tmp;
1053 break;
1054 }
1055 }
1056 }
1057 spin_unlock_irqrestore(get_ccwdev_lock(rp->cdev), flags);
1058 break;
1059 }
1060 up(&raw3270_sem);
1061 return view;
1062}
1063
1064/*
1065 * Remove view from device and free view structure via call to view->fn->free.
1066 */
1067void
1068raw3270_del_view(struct raw3270_view *view)
1069{
1070 unsigned long flags;
1071 struct raw3270 *rp;
1072 struct raw3270_view *nv;
1073
1074 rp = view->dev;
1075 spin_lock_irqsave(get_ccwdev_lock(rp->cdev), flags);
1076 if (rp->view == view) {
1077 view->fn->deactivate(view);
1078 rp->view = 0;
1079 }
1080 list_del_init(&view->list);
1081 if (!rp->view && test_bit(RAW3270_FLAGS_READY, &rp->flags)) {
1082 /* Try to activate another view. */
1083 list_for_each_entry(nv, &rp->view_list, list) {
Richard Hitted3cb6f2005-10-30 15:00:10 -08001084 if (nv->fn->activate(nv) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085 rp->view = nv;
1086 break;
1087 }
1088 }
1089 }
1090 spin_unlock_irqrestore(get_ccwdev_lock(rp->cdev), flags);
1091 /* Wait for reference counter to drop to zero. */
1092 atomic_dec(&view->ref_count);
1093 wait_event(raw3270_wait_queue, atomic_read(&view->ref_count) == 0);
1094 if (view->fn->free)
1095 view->fn->free(view);
1096}
1097
1098/*
1099 * Remove a 3270 device structure.
1100 */
1101static void
1102raw3270_delete_device(struct raw3270 *rp)
1103{
1104 struct ccw_device *cdev;
1105
1106 /* Remove from device chain. */
1107 down(&raw3270_sem);
Richard Hitted3cb6f2005-10-30 15:00:10 -08001108 if (rp->clttydev)
1109 class_device_destroy(class3270,
1110 MKDEV(IBM_TTY3270_MAJOR, rp->minor));
1111 if (rp->cltubdev)
1112 class_device_destroy(class3270,
1113 MKDEV(IBM_FS3270_MAJOR, rp->minor));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114 list_del_init(&rp->list);
1115 up(&raw3270_sem);
1116
1117 /* Disconnect from ccw_device. */
1118 cdev = rp->cdev;
1119 rp->cdev = 0;
1120 cdev->dev.driver_data = 0;
1121 cdev->handler = 0;
1122
1123 /* Put ccw_device structure. */
1124 put_device(&cdev->dev);
1125
1126 /* Now free raw3270 structure. */
1127 kfree(rp->ascebc);
1128 kfree(rp);
1129}
1130
1131static int
1132raw3270_probe (struct ccw_device *cdev)
1133{
1134 return 0;
1135}
1136
1137/*
1138 * Additional attributes for a 3270 device
1139 */
1140static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -04001141raw3270_model_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142{
1143 return snprintf(buf, PAGE_SIZE, "%i\n",
1144 ((struct raw3270 *) dev->driver_data)->model);
1145}
1146static DEVICE_ATTR(model, 0444, raw3270_model_show, 0);
1147
1148static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -04001149raw3270_rows_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150{
1151 return snprintf(buf, PAGE_SIZE, "%i\n",
1152 ((struct raw3270 *) dev->driver_data)->rows);
1153}
1154static DEVICE_ATTR(rows, 0444, raw3270_rows_show, 0);
1155
1156static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -04001157raw3270_columns_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158{
1159 return snprintf(buf, PAGE_SIZE, "%i\n",
1160 ((struct raw3270 *) dev->driver_data)->cols);
1161}
1162static DEVICE_ATTR(columns, 0444, raw3270_columns_show, 0);
1163
1164static struct attribute * raw3270_attrs[] = {
1165 &dev_attr_model.attr,
1166 &dev_attr_rows.attr,
1167 &dev_attr_columns.attr,
1168 NULL,
1169};
1170
1171static struct attribute_group raw3270_attr_group = {
1172 .attrs = raw3270_attrs,
1173};
1174
1175static void
1176raw3270_create_attributes(struct raw3270 *rp)
1177{
1178 //FIXME: check return code
1179 sysfs_create_group(&rp->cdev->dev.kobj, &raw3270_attr_group);
Richard Hitted3cb6f2005-10-30 15:00:10 -08001180 rp->clttydev =
Martin Schwidefskyfc71fe42005-11-18 01:11:03 -08001181 class_device_create(class3270, NULL,
Richard Hitted3cb6f2005-10-30 15:00:10 -08001182 MKDEV(IBM_TTY3270_MAJOR, rp->minor),
1183 &rp->cdev->dev, "tty%s",
1184 rp->cdev->dev.bus_id);
1185 rp->cltubdev =
Martin Schwidefskyfc71fe42005-11-18 01:11:03 -08001186 class_device_create(class3270, NULL,
Richard Hitted3cb6f2005-10-30 15:00:10 -08001187 MKDEV(IBM_FS3270_MAJOR, rp->minor),
1188 &rp->cdev->dev, "tub%s",
1189 rp->cdev->dev.bus_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190}
1191
1192/*
1193 * Notifier for device addition/removal
1194 */
1195struct raw3270_notifier {
1196 struct list_head list;
1197 void (*notifier)(int, int);
1198};
1199
1200static struct list_head raw3270_notifier = LIST_HEAD_INIT(raw3270_notifier);
1201
1202int raw3270_register_notifier(void (*notifier)(int, int))
1203{
1204 struct raw3270_notifier *np;
1205 struct raw3270 *rp;
1206
1207 np = kmalloc(sizeof(struct raw3270_notifier), GFP_KERNEL);
1208 if (!np)
1209 return -ENOMEM;
1210 np->notifier = notifier;
1211 down(&raw3270_sem);
1212 list_add_tail(&np->list, &raw3270_notifier);
1213 list_for_each_entry(rp, &raw3270_devices, list) {
1214 get_device(&rp->cdev->dev);
1215 notifier(rp->minor, 1);
1216 }
1217 up(&raw3270_sem);
1218 return 0;
1219}
1220
1221void raw3270_unregister_notifier(void (*notifier)(int, int))
1222{
1223 struct raw3270_notifier *np;
1224
1225 down(&raw3270_sem);
1226 list_for_each_entry(np, &raw3270_notifier, list)
1227 if (np->notifier == notifier) {
1228 list_del(&np->list);
1229 kfree(np);
1230 break;
1231 }
1232 up(&raw3270_sem);
1233}
1234
1235/*
1236 * Set 3270 device online.
1237 */
1238static int
1239raw3270_set_online (struct ccw_device *cdev)
1240{
1241 struct raw3270 *rp;
1242 struct raw3270_notifier *np;
1243 int rc;
1244
1245 rp = raw3270_create_device(cdev);
1246 if (IS_ERR(rp))
1247 return PTR_ERR(rp);
1248 rc = raw3270_reset_device(rp);
1249 if (rc)
Richard Hitted3cb6f2005-10-30 15:00:10 -08001250 goto failure;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251 rc = raw3270_size_device(rp);
1252 if (rc)
Richard Hitted3cb6f2005-10-30 15:00:10 -08001253 goto failure;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254 rc = raw3270_reset_device(rp);
1255 if (rc)
Richard Hitted3cb6f2005-10-30 15:00:10 -08001256 goto failure;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257 raw3270_create_attributes(rp);
1258 set_bit(RAW3270_FLAGS_READY, &rp->flags);
1259 down(&raw3270_sem);
1260 list_for_each_entry(np, &raw3270_notifier, list)
1261 np->notifier(rp->minor, 1);
1262 up(&raw3270_sem);
1263 return 0;
Richard Hitted3cb6f2005-10-30 15:00:10 -08001264
1265failure:
1266 raw3270_delete_device(rp);
1267 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268}
1269
1270/*
1271 * Remove 3270 device structure.
1272 */
1273static void
1274raw3270_remove (struct ccw_device *cdev)
1275{
1276 unsigned long flags;
1277 struct raw3270 *rp;
1278 struct raw3270_view *v;
1279 struct raw3270_notifier *np;
1280
1281 rp = cdev->dev.driver_data;
Richard Hitted3cb6f2005-10-30 15:00:10 -08001282 /*
1283 * _remove is the opposite of _probe; it's probe that
1284 * should set up rp. raw3270_remove gets entered for
1285 * devices even if they haven't been varied online.
1286 * Thus, rp may validly be NULL here.
1287 */
1288 if (rp == NULL)
1289 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290 clear_bit(RAW3270_FLAGS_READY, &rp->flags);
1291
1292 sysfs_remove_group(&cdev->dev.kobj, &raw3270_attr_group);
1293
1294 /* Deactivate current view and remove all views. */
1295 spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
1296 if (rp->view) {
1297 rp->view->fn->deactivate(rp->view);
1298 rp->view = 0;
1299 }
1300 while (!list_empty(&rp->view_list)) {
1301 v = list_entry(rp->view_list.next, struct raw3270_view, list);
1302 if (v->fn->release)
1303 v->fn->release(v);
1304 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
1305 raw3270_del_view(v);
1306 spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
1307 }
1308 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
1309
1310 down(&raw3270_sem);
1311 list_for_each_entry(np, &raw3270_notifier, list)
1312 np->notifier(rp->minor, 0);
1313 up(&raw3270_sem);
1314
1315 /* Reset 3270 device. */
1316 raw3270_reset_device(rp);
1317 /* And finally remove it. */
1318 raw3270_delete_device(rp);
1319}
1320
1321/*
1322 * Set 3270 device offline.
1323 */
1324static int
1325raw3270_set_offline (struct ccw_device *cdev)
1326{
1327 struct raw3270 *rp;
1328
1329 rp = cdev->dev.driver_data;
1330 if (test_bit(RAW3270_FLAGS_CONSOLE, &rp->flags))
1331 return -EBUSY;
1332 raw3270_remove(cdev);
1333 return 0;
1334}
1335
1336static struct ccw_device_id raw3270_id[] = {
1337 { CCW_DEVICE(0x3270, 0) },
1338 { CCW_DEVICE(0x3271, 0) },
1339 { CCW_DEVICE(0x3272, 0) },
1340 { CCW_DEVICE(0x3273, 0) },
1341 { CCW_DEVICE(0x3274, 0) },
1342 { CCW_DEVICE(0x3275, 0) },
1343 { CCW_DEVICE(0x3276, 0) },
1344 { CCW_DEVICE(0x3277, 0) },
1345 { CCW_DEVICE(0x3278, 0) },
1346 { CCW_DEVICE(0x3279, 0) },
1347 { CCW_DEVICE(0x3174, 0) },
1348 { /* end of list */ },
1349};
1350
1351static struct ccw_driver raw3270_ccw_driver = {
1352 .name = "3270",
1353 .owner = THIS_MODULE,
1354 .ids = raw3270_id,
1355 .probe = &raw3270_probe,
1356 .remove = &raw3270_remove,
1357 .set_online = &raw3270_set_online,
1358 .set_offline = &raw3270_set_offline,
1359};
1360
1361static int
1362raw3270_init(void)
1363{
1364 struct raw3270 *rp;
1365 int rc;
1366
1367 if (raw3270_registered)
1368 return 0;
1369 raw3270_registered = 1;
1370 rc = ccw_driver_register(&raw3270_ccw_driver);
1371 if (rc == 0) {
1372 /* Create attributes for early (= console) device. */
1373 down(&raw3270_sem);
Richard Hitted3cb6f2005-10-30 15:00:10 -08001374 class3270 = class_create(THIS_MODULE, "3270");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375 list_for_each_entry(rp, &raw3270_devices, list) {
1376 get_device(&rp->cdev->dev);
1377 raw3270_create_attributes(rp);
1378 }
1379 up(&raw3270_sem);
1380 }
1381 return rc;
1382}
1383
1384static void
1385raw3270_exit(void)
1386{
1387 ccw_driver_unregister(&raw3270_ccw_driver);
Richard Hitted3cb6f2005-10-30 15:00:10 -08001388 class_destroy(class3270);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389}
1390
1391MODULE_LICENSE("GPL");
1392
1393module_init(raw3270_init);
1394module_exit(raw3270_exit);
1395
1396EXPORT_SYMBOL(raw3270_request_alloc);
1397EXPORT_SYMBOL(raw3270_request_free);
1398EXPORT_SYMBOL(raw3270_request_reset);
1399EXPORT_SYMBOL(raw3270_request_set_cmd);
1400EXPORT_SYMBOL(raw3270_request_add_data);
1401EXPORT_SYMBOL(raw3270_request_set_data);
1402EXPORT_SYMBOL(raw3270_request_set_idal);
1403EXPORT_SYMBOL(raw3270_buffer_address);
1404EXPORT_SYMBOL(raw3270_add_view);
1405EXPORT_SYMBOL(raw3270_del_view);
1406EXPORT_SYMBOL(raw3270_find_view);
1407EXPORT_SYMBOL(raw3270_activate_view);
1408EXPORT_SYMBOL(raw3270_deactivate_view);
1409EXPORT_SYMBOL(raw3270_start);
Richard Hitted3cb6f2005-10-30 15:00:10 -08001410EXPORT_SYMBOL(raw3270_start_locked);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411EXPORT_SYMBOL(raw3270_start_irq);
Richard Hitted3cb6f2005-10-30 15:00:10 -08001412EXPORT_SYMBOL(raw3270_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001413EXPORT_SYMBOL(raw3270_register_notifier);
1414EXPORT_SYMBOL(raw3270_unregister_notifier);
1415EXPORT_SYMBOL(raw3270_wait_queue);