Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    3)  * 3215 line mode terminal driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5)  * Copyright IBM Corp. 1999, 2009
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6)  * Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8)  * Updated:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9)  *  Aug-2000: Added tab support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10)  *	      Dan Morrison, IBM Corporation <dmorriso@cse.buffalo.edu>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14) #include <linux/kdev_t.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15) #include <linux/tty.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16) #include <linux/tty_flip.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17) #include <linux/vt_kern.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19) #include <linux/console.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22) #include <linux/reboot.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23) #include <linux/serial.h> /* ASYNC_* flags */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25) #include <asm/ccwdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26) #include <asm/cio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27) #include <asm/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28) #include <asm/ebcdic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30) #include <asm/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31) #include <asm/cpcmd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32) #include <asm/setup.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34) #include "ctrlchar.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36) #define NR_3215		    1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37) #define NR_3215_REQ	    (4*NR_3215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38) #define RAW3215_BUFFER_SIZE 65536     /* output buffer size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39) #define RAW3215_INBUF_SIZE  256	      /* input buffer size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40) #define RAW3215_MIN_SPACE   128	      /* minimum free space for wakeup */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41) #define RAW3215_MIN_WRITE   1024      /* min. length for immediate output */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42) #define RAW3215_MAX_BYTES   3968      /* max. bytes to write with one ssch */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43) #define RAW3215_MAX_NEWLINE 50	      /* max. lines to write with one ssch */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) #define RAW3215_NR_CCWS	    3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) #define RAW3215_TIMEOUT	    HZ/10     /* time for delayed output */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) #define RAW3215_FIXED	    1	      /* 3215 console device is not be freed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48) #define RAW3215_WORKING	    4	      /* set if a request is being worked on */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) #define RAW3215_THROTTLED   8	      /* set if reading is disabled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) #define RAW3215_STOPPED	    16	      /* set if writing is disabled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) #define RAW3215_TIMER_RUNS  64	      /* set if the output delay timer is on */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) #define RAW3215_FLUSHING    128	      /* set to flush buffer (no delay) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) #define TAB_STOP_SIZE	    8	      /* tab stop size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57)  * Request types for a 3215 device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) enum raw3215_type {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60) 	RAW3215_FREE, RAW3215_READ, RAW3215_WRITE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64)  * Request structure for a 3215 device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) struct raw3215_req {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67) 	enum raw3215_type type;	      /* type of the request */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68) 	int start, len;		      /* start index & len in output buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) 	int delayable;		      /* indication to wait for more data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70) 	int residual;		      /* residual count for read request */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71) 	struct ccw1 ccws[RAW3215_NR_CCWS]; /* space for the channel program */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) 	struct raw3215_info *info;    /* pointer to main structure */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) 	struct raw3215_req *next;     /* pointer to next request */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) } __attribute__ ((aligned(8)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76) struct raw3215_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) 	struct tty_port port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) 	struct ccw_device *cdev;      /* device for tty driver */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) 	spinlock_t *lock;	      /* pointer to irq lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80) 	int flags;		      /* state flags */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) 	char *buffer;		      /* pointer to output buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) 	char *inbuf;		      /* pointer to input buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83) 	int head;		      /* first free byte in output buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84) 	int count;		      /* number of bytes in output buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85) 	int written;		      /* number of bytes in write requests */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) 	struct raw3215_req *queued_read; /* pointer to queued read requests */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) 	struct raw3215_req *queued_write;/* pointer to queued write requests */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) 	struct tasklet_struct tlet;   /* tasklet to invoke tty_wakeup */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) 	wait_queue_head_t empty_wait; /* wait queue for flushing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90) 	struct timer_list timer;      /* timer for delayed output */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91) 	int line_pos;		      /* position on the line (for tabs) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92) 	char ubuffer[80];	      /* copy_from_user buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) /* array of 3215 devices structures */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96) static struct raw3215_info *raw3215[NR_3215];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97) /* spinlock to protect the raw3215 array */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98) static DEFINE_SPINLOCK(raw3215_device_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) /* list of free request structures */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) static struct raw3215_req *raw3215_freelist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) /* spinlock to protect free list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) static spinlock_t raw3215_freelist_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104) static struct tty_driver *tty3215_driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107)  * Get a request structure from the free list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) static inline struct raw3215_req *raw3215_alloc_req(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111) 	struct raw3215_req *req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114) 	spin_lock_irqsave(&raw3215_freelist_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115) 	req = raw3215_freelist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) 	raw3215_freelist = req->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) 	spin_unlock_irqrestore(&raw3215_freelist_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) 	return req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122)  * Put a request structure back to the free list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) static inline void raw3215_free_req(struct raw3215_req *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) 	if (req->type == RAW3215_FREE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) 		return;		/* don't free a free request */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) 	req->type = RAW3215_FREE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) 	spin_lock_irqsave(&raw3215_freelist_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) 	req->next = raw3215_freelist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) 	raw3215_freelist = req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) 	spin_unlock_irqrestore(&raw3215_freelist_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138)  * Set up a read request that reads up to 160 byte from the 3215 device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139)  * If there is a queued read request it is used, but that shouldn't happen
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140)  * because a 3215 terminal won't accept a new read before the old one is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141)  * completed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) static void raw3215_mk_read_req(struct raw3215_info *raw)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) 	struct raw3215_req *req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) 	struct ccw1 *ccw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) 	/* there can only be ONE read request at a time */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) 	req = raw->queued_read;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) 	if (req == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) 		/* no queued read request, use new req structure */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) 		req = raw3215_alloc_req();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) 		req->type = RAW3215_READ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) 		req->info = raw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) 		raw->queued_read = req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) 	ccw = req->ccws;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) 	ccw->cmd_code = 0x0A; /* read inquiry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) 	ccw->flags = 0x20;    /* ignore incorrect length */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) 	ccw->count = 160;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) 	ccw->cda = (__u32) __pa(raw->inbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166)  * Set up a write request with the information from the main structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167)  * A ccw chain is created that writes as much as possible from the output
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168)  * buffer to the 3215 device. If a queued write exists it is replaced by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169)  * the new, probably lengthened request.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171) static void raw3215_mk_write_req(struct raw3215_info *raw)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) 	struct raw3215_req *req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) 	struct ccw1 *ccw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) 	int len, count, ix, lines;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) 	if (raw->count <= raw->written)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) 	/* check if there is a queued write request */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) 	req = raw->queued_write;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) 	if (req == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) 		/* no queued write request, use new req structure */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) 		req = raw3215_alloc_req();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) 		req->type = RAW3215_WRITE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) 		req->info = raw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) 		raw->queued_write = req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) 		raw->written -= req->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) 	ccw = req->ccws;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) 	req->start = (raw->head - raw->count + raw->written) &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) 		     (RAW3215_BUFFER_SIZE - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) 	 * now we have to count newlines. We can at max accept
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) 	 * RAW3215_MAX_NEWLINE newlines in a single ssch due to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) 	 * a restriction in VM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) 	lines = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) 	ix = req->start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) 	while (lines < RAW3215_MAX_NEWLINE && ix != raw->head) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) 		if (raw->buffer[ix] == 0x15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) 			lines++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) 		ix = (ix + 1) & (RAW3215_BUFFER_SIZE - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) 	len = ((ix - 1 - req->start) & (RAW3215_BUFFER_SIZE - 1)) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) 	if (len > RAW3215_MAX_BYTES)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) 		len = RAW3215_MAX_BYTES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) 	req->len = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) 	raw->written += len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) 	/* set the indication if we should try to enlarge this request */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) 	req->delayable = (ix == raw->head) && (len < RAW3215_MIN_WRITE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) 	ix = req->start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) 	while (len > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) 		if (ccw > req->ccws)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) 			ccw[-1].flags |= 0x40; /* use command chaining */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219) 		ccw->cmd_code = 0x01; /* write, auto carrier return */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) 		ccw->flags = 0x20;    /* ignore incorrect length ind.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) 		ccw->cda =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) 			(__u32) __pa(raw->buffer + ix);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) 		count = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) 		if (ix + count > RAW3215_BUFFER_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) 			count = RAW3215_BUFFER_SIZE - ix;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) 		ccw->count = count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) 		len -= count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) 		ix = (ix + count) & (RAW3215_BUFFER_SIZE - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) 		ccw++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) 	 * Add a NOP to the channel program. 3215 devices are purely
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) 	 * emulated and its much better to avoid the channel end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) 	 * interrupt in this case.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) 	if (ccw > req->ccws)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) 		ccw[-1].flags |= 0x40; /* use command chaining */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) 	ccw->cmd_code = 0x03; /* NOP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) 	ccw->flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) 	ccw->cda = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) 	ccw->count = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245)  * Start a read or a write request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) static void raw3215_start_io(struct raw3215_info *raw)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) 	struct raw3215_req *req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) 	int res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) 	req = raw->queued_read;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) 	if (req != NULL &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) 	    !(raw->flags & (RAW3215_WORKING | RAW3215_THROTTLED))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) 		/* dequeue request */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) 		raw->queued_read = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) 		res = ccw_device_start(raw->cdev, req->ccws,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) 				       (unsigned long) req, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) 		if (res != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) 			/* do_IO failed, put request back to queue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) 			raw->queued_read = req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) 			raw->flags |= RAW3215_WORKING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) 	req = raw->queued_write;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) 	if (req != NULL &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) 	    !(raw->flags & (RAW3215_WORKING | RAW3215_STOPPED))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) 		/* dequeue request */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) 		raw->queued_write = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) 		res = ccw_device_start(raw->cdev, req->ccws,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) 				       (unsigned long) req, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) 		if (res != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) 			/* do_IO failed, put request back to queue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) 			raw->queued_write = req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) 			raw->flags |= RAW3215_WORKING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283)  * Function to start a delayed output after RAW3215_TIMEOUT seconds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) static void raw3215_timeout(struct timer_list *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) 	struct raw3215_info *raw = from_timer(raw, t, timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) 	spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) 	raw->flags &= ~RAW3215_TIMER_RUNS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) 	if (!tty_port_suspended(&raw->port)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) 		raw3215_mk_write_req(raw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) 		raw3215_start_io(raw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) 		if ((raw->queued_read || raw->queued_write) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) 		    !(raw->flags & RAW3215_WORKING) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) 		    !(raw->flags & RAW3215_TIMER_RUNS)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) 			raw->timer.expires = RAW3215_TIMEOUT + jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) 			add_timer(&raw->timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) 			raw->flags |= RAW3215_TIMER_RUNS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) 	spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307)  * Function to conditionally start an IO. A read is started immediately,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308)  * a write is only started immediately if the flush flag is on or the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309)  * amount of data is bigger than RAW3215_MIN_WRITE. If a write is not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310)  * done immediately a timer is started with a delay of RAW3215_TIMEOUT.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) static inline void raw3215_try_io(struct raw3215_info *raw)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) 	if (!tty_port_initialized(&raw->port) || tty_port_suspended(&raw->port))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) 	if (raw->queued_read != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) 		raw3215_start_io(raw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) 	else if (raw->queued_write != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) 		if ((raw->queued_write->delayable == 0) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) 		    (raw->flags & RAW3215_FLUSHING)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) 			/* execute write requests bigger than minimum size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) 			raw3215_start_io(raw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) 	if ((raw->queued_read || raw->queued_write) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) 	    !(raw->flags & RAW3215_WORKING) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) 	    !(raw->flags & RAW3215_TIMER_RUNS)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) 		raw->timer.expires = RAW3215_TIMEOUT + jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) 		add_timer(&raw->timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) 		raw->flags |= RAW3215_TIMER_RUNS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335)  * Call tty_wakeup from tasklet context
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) static void raw3215_wakeup(unsigned long data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) 	struct raw3215_info *raw = (struct raw3215_info *) data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) 	struct tty_struct *tty;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) 	tty = tty_port_tty_get(&raw->port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) 	if (tty) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) 		tty_wakeup(tty);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) 		tty_kref_put(tty);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350)  * Try to start the next IO and wake up processes waiting on the tty.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) static void raw3215_next_io(struct raw3215_info *raw, struct tty_struct *tty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) 	raw3215_mk_write_req(raw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) 	raw3215_try_io(raw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) 	if (tty && RAW3215_BUFFER_SIZE - raw->count >= RAW3215_MIN_SPACE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) 		tasklet_schedule(&raw->tlet);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361)  * Interrupt routine, called from common io layer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) static void raw3215_irq(struct ccw_device *cdev, unsigned long intparm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) 			struct irb *irb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) 	struct raw3215_info *raw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) 	struct raw3215_req *req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) 	struct tty_struct *tty;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) 	int cstat, dstat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) 	int count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) 	raw = dev_get_drvdata(&cdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) 	req = (struct raw3215_req *) intparm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) 	tty = tty_port_tty_get(&raw->port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) 	cstat = irb->scsw.cmd.cstat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) 	dstat = irb->scsw.cmd.dstat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) 	if (cstat != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) 		raw3215_next_io(raw, tty);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) 	if (dstat & 0x01) { /* we got a unit exception */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) 		dstat &= ~0x01;	 /* we can ignore it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) 	switch (dstat) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) 	case 0x80:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) 		if (cstat != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 		/* Attention interrupt, someone hit the enter key */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) 		raw3215_mk_read_req(raw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) 		raw3215_next_io(raw, tty);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) 	case 0x08:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) 	case 0x0C:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) 		/* Channel end interrupt. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) 		if ((raw = req->info) == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) 			goto put_tty;	     /* That shouldn't happen ... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) 		if (req->type == RAW3215_READ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) 			/* store residual count, then wait for device end */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) 			req->residual = irb->scsw.cmd.count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) 		if (dstat == 0x08)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) 		fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) 	case 0x04:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) 		/* Device end interrupt. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) 		if ((raw = req->info) == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) 			goto put_tty;	     /* That shouldn't happen ... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) 		if (req->type == RAW3215_READ && tty != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) 			unsigned int cchar;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) 			count = 160 - req->residual;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) 			EBCASC(raw->inbuf, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) 			cchar = ctrlchar_handle(raw->inbuf, count, tty);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) 			switch (cchar & CTRLCHAR_MASK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) 			case CTRLCHAR_SYSRQ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) 			case CTRLCHAR_CTRL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) 				tty_insert_flip_char(&raw->port, cchar,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) 						TTY_NORMAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) 				tty_flip_buffer_push(&raw->port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) 			case CTRLCHAR_NONE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) 				if (count < 2 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) 				    (strncmp(raw->inbuf+count-2, "\252n", 2) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) 				     strncmp(raw->inbuf+count-2, "^n", 2)) ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) 					/* add the auto \n */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) 					raw->inbuf[count] = '\n';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) 					count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) 				} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) 					count -= 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) 				tty_insert_flip_string(&raw->port, raw->inbuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) 						count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) 				tty_flip_buffer_push(&raw->port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) 		} else if (req->type == RAW3215_WRITE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) 			raw->count -= req->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 			raw->written -= req->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 		raw->flags &= ~RAW3215_WORKING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) 		raw3215_free_req(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 		/* check for empty wait */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) 		if (waitqueue_active(&raw->empty_wait) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 		    raw->queued_write == NULL &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) 		    raw->queued_read == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) 			wake_up_interruptible(&raw->empty_wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) 		raw3215_next_io(raw, tty);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) 		/* Strange interrupt, I'll do my best to clean up */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) 		if (req != NULL && req->type != RAW3215_FREE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) 			if (req->type == RAW3215_WRITE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) 				raw->count -= req->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) 				raw->written -= req->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) 			raw->flags &= ~RAW3215_WORKING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) 			raw3215_free_req(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) 		raw3215_next_io(raw, tty);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) put_tty:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) 	tty_kref_put(tty);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467)  * Drop the oldest line from the output buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) static void raw3215_drop_line(struct raw3215_info *raw)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 	int ix;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) 	char ch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) 	BUG_ON(raw->written != 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) 	ix = (raw->head - raw->count) & (RAW3215_BUFFER_SIZE - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) 	while (raw->count > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) 		ch = raw->buffer[ix];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) 		ix = (ix + 1) & (RAW3215_BUFFER_SIZE - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) 		raw->count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) 		if (ch == 0x15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) 	raw->head = ix;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487)  * Wait until length bytes are available int the output buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488)  * Has to be called with the s390irq lock held. Can be called
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489)  * disabled.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) static void raw3215_make_room(struct raw3215_info *raw, unsigned int length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) 	while (RAW3215_BUFFER_SIZE - raw->count < length) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 		/* While console is frozen for suspend we have no other
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) 		 * choice but to drop message from the buffer to make
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) 		 * room for even more messages. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) 		if (tty_port_suspended(&raw->port)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) 			raw3215_drop_line(raw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) 		/* there might be a request pending */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) 		raw->flags |= RAW3215_FLUSHING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) 		raw3215_mk_write_req(raw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) 		raw3215_try_io(raw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) 		raw->flags &= ~RAW3215_FLUSHING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) #ifdef CONFIG_TN3215_CONSOLE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) 		ccw_device_wait_idle(raw->cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) 		/* Enough room freed up ? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) 		if (RAW3215_BUFFER_SIZE - raw->count >= length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) 		/* there might be another cpu waiting for the lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) 		spin_unlock(get_ccwdev_lock(raw->cdev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) 		udelay(100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 		spin_lock(get_ccwdev_lock(raw->cdev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520)  * String write routine for 3215 devices
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) static void raw3215_write(struct raw3215_info *raw, const char *str,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) 			  unsigned int length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) 	int c, count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) 	while (length > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) 		spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) 		count = (length > RAW3215_BUFFER_SIZE) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) 					     RAW3215_BUFFER_SIZE : length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) 		length -= count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) 		raw3215_make_room(raw, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) 		/* copy string to output buffer and convert it to EBCDIC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) 		while (1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) 			c = min_t(int, count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) 				  min(RAW3215_BUFFER_SIZE - raw->count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) 				      RAW3215_BUFFER_SIZE - raw->head));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) 			if (c <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) 			memcpy(raw->buffer + raw->head, str, c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) 			ASCEBC(raw->buffer + raw->head, c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 			raw->head = (raw->head + c) & (RAW3215_BUFFER_SIZE - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 			raw->count += c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) 			raw->line_pos += c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) 			str += c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) 			count -= c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) 		if (!(raw->flags & RAW3215_WORKING)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) 			raw3215_mk_write_req(raw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) 			/* start or queue request */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) 			raw3215_try_io(raw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) 		spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561)  * Put character routine for 3215 devices
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) static void raw3215_putchar(struct raw3215_info *raw, unsigned char ch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) 	unsigned int length, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) 	spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) 	if (ch == '\t') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) 		length = TAB_STOP_SIZE - (raw->line_pos%TAB_STOP_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) 		raw->line_pos += length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) 		ch = ' ';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) 	} else if (ch == '\n') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) 		length = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) 		raw->line_pos = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) 		length = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) 		raw->line_pos++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) 	raw3215_make_room(raw, length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) 	for (i = 0; i < length; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) 		raw->buffer[raw->head] = (char) _ascebc[(int) ch];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) 		raw->head = (raw->head + 1) & (RAW3215_BUFFER_SIZE - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) 		raw->count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) 	if (!(raw->flags & RAW3215_WORKING)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) 		raw3215_mk_write_req(raw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) 		/* start or queue request */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) 		raw3215_try_io(raw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) 	spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596)  * Flush routine, it simply sets the flush flag and tries to start
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597)  * pending IO.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) static void raw3215_flush_buffer(struct raw3215_info *raw)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) 	spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) 	if (raw->count > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) 		raw->flags |= RAW3215_FLUSHING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 		raw3215_try_io(raw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) 		raw->flags &= ~RAW3215_FLUSHING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) 	spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613)  * Fire up a 3215 device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) static int raw3215_startup(struct raw3215_info *raw)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) 	if (tty_port_initialized(&raw->port))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) 	raw->line_pos = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) 	tty_port_set_initialized(&raw->port, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) 	spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) 	raw3215_try_io(raw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) 	spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631)  * Shutdown a 3215 device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) static void raw3215_shutdown(struct raw3215_info *raw)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) 	DECLARE_WAITQUEUE(wait, current);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) 	if (!tty_port_initialized(&raw->port) || (raw->flags & RAW3215_FIXED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) 	/* Wait for outstanding requests, then free irq */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) 	spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) 	if ((raw->flags & RAW3215_WORKING) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) 	    raw->queued_write != NULL ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) 	    raw->queued_read != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) 		add_wait_queue(&raw->empty_wait, &wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) 		set_current_state(TASK_INTERRUPTIBLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) 		spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) 		schedule();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) 		spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) 		remove_wait_queue(&raw->empty_wait, &wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) 		set_current_state(TASK_RUNNING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) 		tty_port_set_initialized(&raw->port, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) 	spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) static struct raw3215_info *raw3215_alloc_info(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) 	struct raw3215_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) 	info = kzalloc(sizeof(struct raw3215_info), GFP_KERNEL | GFP_DMA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) 	if (!info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) 	info->buffer = kzalloc(RAW3215_BUFFER_SIZE, GFP_KERNEL | GFP_DMA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) 	info->inbuf = kzalloc(RAW3215_INBUF_SIZE, GFP_KERNEL | GFP_DMA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) 	if (!info->buffer || !info->inbuf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) 		kfree(info->inbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) 		kfree(info->buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) 		kfree(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) 	timer_setup(&info->timer, raw3215_timeout, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) 	init_waitqueue_head(&info->empty_wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) 	tasklet_init(&info->tlet, raw3215_wakeup, (unsigned long)info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) 	tty_port_init(&info->port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) 	return info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) static void raw3215_free_info(struct raw3215_info *raw)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) 	kfree(raw->inbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) 	kfree(raw->buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) 	tty_port_destroy(&raw->port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) 	kfree(raw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) static int raw3215_probe (struct ccw_device *cdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) 	struct raw3215_info *raw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) 	int line;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 	/* Console is special. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) 	if (raw3215[0] && (raw3215[0] == dev_get_drvdata(&cdev->dev)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) 	raw = raw3215_alloc_info();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) 	if (raw == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) 	raw->cdev = cdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) 	dev_set_drvdata(&cdev->dev, raw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) 	cdev->handler = raw3215_irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) 	spin_lock(&raw3215_device_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) 	for (line = 0; line < NR_3215; line++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) 		if (!raw3215[line]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) 			raw3215[line] = raw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) 	spin_unlock(&raw3215_device_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) 	if (line == NR_3215) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) 		raw3215_free_info(raw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) static void raw3215_remove (struct ccw_device *cdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) 	struct raw3215_info *raw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 	unsigned int line;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) 	ccw_device_set_offline(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 	raw = dev_get_drvdata(&cdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) 	if (raw) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 		spin_lock(&raw3215_device_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) 		for (line = 0; line < NR_3215; line++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 			if (raw3215[line] == raw)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 		raw3215[line] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) 		spin_unlock(&raw3215_device_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) 		dev_set_drvdata(&cdev->dev, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 		raw3215_free_info(raw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) static int raw3215_set_online (struct ccw_device *cdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) 	struct raw3215_info *raw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) 	raw = dev_get_drvdata(&cdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) 	if (!raw)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) 	return raw3215_startup(raw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) static int raw3215_set_offline (struct ccw_device *cdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 	struct raw3215_info *raw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) 	raw = dev_get_drvdata(&cdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 	if (!raw)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) 	raw3215_shutdown(raw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) static int raw3215_pm_stop(struct ccw_device *cdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) 	struct raw3215_info *raw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) 	/* Empty the output buffer, then prevent new I/O. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 	raw = dev_get_drvdata(&cdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) 	spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) 	raw3215_make_room(raw, RAW3215_BUFFER_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) 	tty_port_set_suspended(&raw->port, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) 	spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) static int raw3215_pm_start(struct ccw_device *cdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) 	struct raw3215_info *raw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) 	/* Allow I/O again and flush output buffer. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) 	raw = dev_get_drvdata(&cdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) 	spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) 	tty_port_set_suspended(&raw->port, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) 	raw->flags |= RAW3215_FLUSHING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) 	raw3215_try_io(raw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) 	raw->flags &= ~RAW3215_FLUSHING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 	spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) static struct ccw_device_id raw3215_id[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 	{ CCW_DEVICE(0x3215, 0) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) 	{ /* end of list */ },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) static struct ccw_driver raw3215_ccw_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) 		.name	= "3215",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) 		.owner	= THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) 	.ids		= raw3215_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) 	.probe		= &raw3215_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) 	.remove		= &raw3215_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) 	.set_online	= &raw3215_set_online,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) 	.set_offline	= &raw3215_set_offline,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) 	.freeze		= &raw3215_pm_stop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) 	.thaw		= &raw3215_pm_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) 	.restore	= &raw3215_pm_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) 	.int_class	= IRQIO_C15,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) #ifdef CONFIG_TN3215_CONSOLE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819)  * Write a string to the 3215 console
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) static void con3215_write(struct console *co, const char *str,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) 			  unsigned int count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) 	struct raw3215_info *raw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) 	if (count <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) 	raw = raw3215[0];	/* console 3215 is the first one */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) 	while (count > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) 		for (i = 0; i < count; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) 			if (str[i] == '\t' || str[i] == '\n')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) 		raw3215_write(raw, str, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) 		count -= i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 		str += i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) 		if (count > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) 			raw3215_putchar(raw, *str);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) 			count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) 			str++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) static struct tty_driver *con3215_device(struct console *c, int *index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) 	*index = c->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) 	return tty3215_driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852)  * panic() calls con3215_flush through a panic_notifier
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853)  * before the system enters a disabled, endless loop.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) static void con3215_flush(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) 	struct raw3215_info *raw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) 	raw = raw3215[0];  /* console 3215 is the first one */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) 	if (tty_port_suspended(&raw->port))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) 		/* The console is still frozen for suspend. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) 		if (ccw_device_force_console(raw->cdev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) 			/* Forcing didn't work, no panic message .. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) 	spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) 	raw3215_make_room(raw, RAW3215_BUFFER_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) 	spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) static int con3215_notify(struct notifier_block *self,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) 			  unsigned long event, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) 	con3215_flush();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) 	return NOTIFY_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) static struct notifier_block on_panic_nb = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 	.notifier_call = con3215_notify,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) 	.priority = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) static struct notifier_block on_reboot_nb = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 	.notifier_call = con3215_notify,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) 	.priority = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889)  *  The console structure for the 3215 console
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) static struct console con3215 = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) 	.name	 = "ttyS",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 	.write	 = con3215_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) 	.device	 = con3215_device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) 	.flags	 = CON_PRINTBUFFER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899)  * 3215 console initialization code called from console_init().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) static int __init con3215_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) 	struct ccw_device *cdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) 	struct raw3215_info *raw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) 	struct raw3215_req *req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) 	/* Check if 3215 is to be the console */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) 	if (!CONSOLE_IS_3215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) 	/* Set the console mode for VM */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) 	if (MACHINE_IS_VM) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) 		cpcmd("TERM CONMODE 3215", NULL, 0, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) 		cpcmd("TERM AUTOCR OFF", NULL, 0, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) 	/* allocate 3215 request structures */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) 	raw3215_freelist = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) 	spin_lock_init(&raw3215_freelist_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) 	for (i = 0; i < NR_3215_REQ; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) 		req = kzalloc(sizeof(struct raw3215_req), GFP_KERNEL | GFP_DMA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) 		if (!req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) 			return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) 		req->next = raw3215_freelist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) 		raw3215_freelist = req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 	cdev = ccw_device_create_console(&raw3215_ccw_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) 	if (IS_ERR(cdev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) 	raw3215[0] = raw = raw3215_alloc_info();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) 	raw->cdev = cdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) 	dev_set_drvdata(&cdev->dev, raw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) 	cdev->handler = raw3215_irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) 	raw->flags |= RAW3215_FIXED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) 	if (ccw_device_enable_console(cdev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 		ccw_device_destroy_console(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) 		raw3215_free_info(raw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) 		raw3215[0] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) 	/* Request the console irq */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) 	if (raw3215_startup(raw) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 		raw3215_free_info(raw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) 		raw3215[0] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) 	atomic_notifier_chain_register(&panic_notifier_list, &on_panic_nb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) 	register_reboot_notifier(&on_reboot_nb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) 	register_console(&con3215);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) console_initcall(con3215_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) static int tty3215_install(struct tty_driver *driver, struct tty_struct *tty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) 	struct raw3215_info *raw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) 	raw = raw3215[tty->index];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) 	if (raw == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) 	tty->driver_data = raw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) 	return tty_port_install(&raw->port, driver, tty);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974)  * tty3215_open
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976)  * This routine is called whenever a 3215 tty is opened.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) static int tty3215_open(struct tty_struct *tty, struct file * filp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) 	struct raw3215_info *raw = tty->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) 	tty_port_tty_set(&raw->port, tty);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 	raw->port.low_latency = 0; /* don't use bottom half for pushing chars */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) 	 * Start up 3215 device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) 	return raw3215_startup(raw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992)  * tty3215_close()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994)  * This routine is called when the 3215 tty is closed. We wait
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995)  * for the remaining request to be completed. Then we clean up.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) static void tty3215_close(struct tty_struct *tty, struct file * filp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 	struct raw3215_info *raw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) 	raw = (struct raw3215_info *) tty->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) 	if (raw == NULL || tty->count > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) 	tty->closing = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) 	/* Shutdown the terminal */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) 	raw3215_shutdown(raw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) 	tasklet_kill(&raw->tlet);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) 	tty->closing = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) 	tty_port_tty_set(&raw->port, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013)  * Returns the amount of free space in the output buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) static int tty3215_write_room(struct tty_struct *tty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) 	struct raw3215_info *raw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) 	raw = (struct raw3215_info *) tty->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) 	/* Subtract TAB_STOP_SIZE to allow for a tab, 8 <<< 64K */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) 	if ((RAW3215_BUFFER_SIZE - raw->count - TAB_STOP_SIZE) >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) 		return RAW3215_BUFFER_SIZE - raw->count - TAB_STOP_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029)  * String write routine for 3215 ttys
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) static int tty3215_write(struct tty_struct * tty,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) 			 const unsigned char *buf, int count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) 	struct raw3215_info *raw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) 	int i, written;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) 	if (!tty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) 	raw = (struct raw3215_info *) tty->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) 	written = count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) 	while (count > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) 		for (i = 0; i < count; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) 			if (buf[i] == '\t' || buf[i] == '\n')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) 		raw3215_write(raw, buf, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) 		count -= i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) 		buf += i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) 		if (count > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) 			raw3215_putchar(raw, *buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) 			count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) 			buf++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) 	return written;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058)  * Put character routine for 3215 ttys
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) static int tty3215_put_char(struct tty_struct *tty, unsigned char ch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) 	struct raw3215_info *raw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) 	if (!tty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) 	raw = (struct raw3215_info *) tty->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) 	raw3215_putchar(raw, ch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) static void tty3215_flush_chars(struct tty_struct *tty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076)  * Returns the number of characters in the output buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) static int tty3215_chars_in_buffer(struct tty_struct *tty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) 	struct raw3215_info *raw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) 	raw = (struct raw3215_info *) tty->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) 	return raw->count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) static void tty3215_flush_buffer(struct tty_struct *tty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) 	struct raw3215_info *raw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) 	raw = (struct raw3215_info *) tty->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) 	raw3215_flush_buffer(raw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) 	tty_wakeup(tty);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096)  * Disable reading from a 3215 tty
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) static void tty3215_throttle(struct tty_struct * tty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) 	struct raw3215_info *raw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) 	raw = (struct raw3215_info *) tty->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) 	raw->flags |= RAW3215_THROTTLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107)  * Enable reading from a 3215 tty
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) static void tty3215_unthrottle(struct tty_struct * tty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) 	struct raw3215_info *raw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) 	raw = (struct raw3215_info *) tty->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) 	if (raw->flags & RAW3215_THROTTLED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) 		spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) 		raw->flags &= ~RAW3215_THROTTLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) 		raw3215_try_io(raw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) 		spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124)  * Disable writing to a 3215 tty
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) static void tty3215_stop(struct tty_struct *tty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) 	struct raw3215_info *raw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) 	raw = (struct raw3215_info *) tty->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) 	raw->flags |= RAW3215_STOPPED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135)  * Enable writing to a 3215 tty
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) static void tty3215_start(struct tty_struct *tty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) 	struct raw3215_info *raw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) 	raw = (struct raw3215_info *) tty->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) 	if (raw->flags & RAW3215_STOPPED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) 		spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) 		raw->flags &= ~RAW3215_STOPPED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) 		raw3215_try_io(raw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) 		spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) static const struct tty_operations tty3215_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) 	.install = tty3215_install,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) 	.open = tty3215_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) 	.close = tty3215_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) 	.write = tty3215_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) 	.put_char = tty3215_put_char,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) 	.flush_chars = tty3215_flush_chars,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) 	.write_room = tty3215_write_room,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) 	.chars_in_buffer = tty3215_chars_in_buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) 	.flush_buffer = tty3215_flush_buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) 	.throttle = tty3215_throttle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) 	.unthrottle = tty3215_unthrottle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) 	.stop = tty3215_stop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) 	.start = tty3215_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168)  * 3215 tty registration code called from tty_init().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169)  * Most kernel services (incl. kmalloc) are available at this poimt.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) static int __init tty3215_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) 	struct tty_driver *driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) 	if (!CONSOLE_IS_3215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) 	driver = alloc_tty_driver(NR_3215);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) 	if (!driver)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) 	ret = ccw_driver_register(&raw3215_ccw_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) 		put_tty_driver(driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) 	 * Initialize the tty_driver structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) 	 * Entries in tty3215_driver that are NOT initialized:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) 	 * proc_entry, set_termios, flush_buffer, set_ldisc, write_proc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) 	driver->driver_name = "tty3215";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) 	driver->name = "ttyS";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) 	driver->major = TTY_MAJOR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) 	driver->minor_start = 64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) 	driver->type = TTY_DRIVER_TYPE_SYSTEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) 	driver->subtype = SYSTEM_TYPE_TTY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) 	driver->init_termios = tty_std_termios;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) 	driver->init_termios.c_iflag = IGNBRK | IGNPAR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) 	driver->init_termios.c_oflag = ONLCR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) 	driver->init_termios.c_lflag = ISIG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) 	driver->flags = TTY_DRIVER_REAL_RAW;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) 	tty_set_operations(driver, &tty3215_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) 	ret = tty_register_driver(driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) 		put_tty_driver(driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) 	tty3215_driver = driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) device_initcall(tty3215_init);