patch-2.4.2 linux/drivers/s390/char/con3215.c

Next file: linux/drivers/s390/char/hwc.h
Previous file: linux/drivers/s390/char/Makefile
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.4.1/linux/drivers/s390/char/con3215.c linux/drivers/s390/char/con3215.c
@@ -5,6 +5,10 @@
  *  S390 version
  *    Copyright (C) 1999,2000 IBM Deutschland Entwicklung GmbH, IBM Corporation
  *    Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com),
+ *
+ *  Updated:
+ *   Aug-2000: Added tab support
+ *             Dan Morrison, IBM Corporation (dmorriso@cse.buffalo.edu)
  */
 
 #include <linux/config.h>
@@ -16,11 +20,12 @@
 #include <linux/console.h>
 #include <linux/interrupt.h>
 
-#include <linux/malloc.h>
+#include <linux/slab.h>
 #include <linux/bootmem.h>
 #include <asm/io.h>
 #include <asm/ebcdic.h>
 #include <asm/uaccess.h>
+#include <asm/delay.h>
 
 #include "../../../arch/s390/kernel/cpcmd.h"
 #include <asm/irq.h>
@@ -31,8 +36,9 @@
 #define RAW3215_INBUF_SIZE  256	      /* input buffer size */
 #define RAW3215_MIN_SPACE   128	      /* minimum free space for wakeup */
 #define RAW3215_MIN_WRITE   1024      /* min. length for immediate output */
-#define RAW3215_MAX_CCWLEN  3968      /* max. bytes to write with one ccw */
-#define RAW3215_NR_CCWS	    ((RAW3215_BUFFER_SIZE/RAW3215_MAX_CCWLEN)+2)
+#define RAW3215_MAX_BYTES   3968      /* max. bytes to write with one ssch */
+#define RAW3215_MAX_NEWLINE 50        /* max. lines to write with one ssch */
+#define RAW3215_NR_CCWS	    3
 #define RAW3215_TIMEOUT	    HZ/10     /* time for delayed output */
 
 #define RAW3215_FIXED	    1	      /* 3215 console device is not be freed */
@@ -45,6 +51,8 @@
 #define RAW3215_FLUSHING    128	      /* set to flush buffer (no delay) */
 #define RAW3215_BH_PENDING  256       /* indication for bh scheduling */
 
+#define TAB_STOP_SIZE	    8         /* tab stop size */
+
 struct _raw3215_info;		      /* forward declaration ... */
 
 int raw3215_condevice = -1;           /* preset console device */
@@ -61,7 +69,8 @@
  */
 typedef struct _raw3215_req {
 	raw3215_type type;	      /* type of the request */
-	int start, end;		      /* start/end index into output buffer */
+	int start, len;		      /* start index & len in output buffer */
+        int delayable;                /* indication to wait for more data */
 	int residual;		      /* residual count for read request */
 	ccw1_t ccws[RAW3215_NR_CCWS]; /* space for the channel program */
 	struct _raw3215_info *info;   /* pointer to main structure */
@@ -75,6 +84,7 @@
 	char *inbuf;		      /* pointer to input buffer */
 	int head;		      /* first free byte in output buffer */
 	int count;		      /* number of bytes in output buffer */
+        int written;                  /* number of bytes in write requests */
 	devstat_t devstat;	      /* device status structure for do_IO */
 	struct tty_struct *tty;	      /* pointer to tty structure if present */
 	struct tq_struct tqueue;      /* task queue to bottom half */
@@ -85,6 +95,7 @@
 	char *message;                /* pending message from raw3215_irq */
 	int msg_dstat;                /* dstat for pending message */
 	int msg_cstat;                /* cstat for pending message */
+	int line_pos;		      /* position on the line (for tabs) */
 } raw3215_info;
 
 static raw3215_info *raw3215[NR_3215];	/* array of 3215 devices structures */
@@ -143,35 +154,15 @@
 }
 
 /*
- * Get a write request structure. That is either a new or the last
- * queued write request. The request structure is set up in 
- * raw3215_mk_write_ccw.
- */
-static raw3215_req *raw3215_mk_write_req(raw3215_info *raw)
-{
-	raw3215_req *req;
-
-	/* check if there is a queued write request */
-	req = raw->queued_write;
-	if (req == NULL) {
-		/* no queued write request, use new req structure */
-		req = raw3215_alloc_req();
-		req->type = RAW3215_WRITE;
-		req->info = raw;
-		req->start = raw->head;
-	} else
-		raw->queued_write = NULL;
-	return req;
-}
-
-/*
- * Get a read request structure. If there is a queued read request
- * it is used, but that shouldn't happen because a 3215 terminal
- * won't accept a new read before the old one is completed.
+ * Set up a read request that reads up to 160 byte from the 3215 device.
+ * If there is a queued read request it is used, but that shouldn't happen
+ * because a 3215 terminal won't accept a new read before the old one is
+ * completed.
  */
-static raw3215_req *raw3215_mk_read_req(raw3215_info *raw)
+static void raw3215_mk_read_req(raw3215_info *raw)
 {
 	raw3215_req *req;
+        ccw1_t *ccw;
 
 	/* there can only be ONE read request at a time */
 	req = raw->queued_read;
@@ -180,24 +171,66 @@
 		req = raw3215_alloc_req();
 		req->type = RAW3215_READ;
 		req->info = raw;
-	} else
-		raw->queued_read = NULL;
-	return req;
+                raw->queued_read = req;
+	}
+
+        ccw = req->ccws;
+        ccw->cmd_code = 0x0A; /* read inquiry */
+        ccw->flags = 0x20;    /* ignore incorrect length */
+        ccw->count = 160;
+        ccw->cda = (__u32) __pa(raw->inbuf);
 }
 
 /*
  * Set up a write request with the information from the main structure.
- * A ccw chain is created that writes everything in the output buffer
- * to the 3215 device.
+ * A ccw chain is created that writes as much as possible from the output
+ * buffer to the 3215 device. If a queued write exists it is replaced by
+ * the new, probably lengthened request.
  */
-static int raw3215_mk_write_ccw(raw3215_info *raw, raw3215_req *req)
+static void raw3215_mk_write_req(raw3215_info *raw)
 {
+        raw3215_req *req;
 	ccw1_t *ccw;
-	int len, count, ix;
+	int len, count, ix, lines;
+
+        if (raw->count <= raw->written)
+                return;
+        /* check if there is a queued write request */
+        req = raw->queued_write;
+        if (req == NULL) {
+                /* no queued write request, use new req structure */
+                req = raw3215_alloc_req();
+                req->type = RAW3215_WRITE;
+                req->info = raw;
+                raw->queued_write = req;
+        } else {
+                raw->written -= req->len;
+        }
 
 	ccw = req->ccws;
-	req->end = (raw->head - 1) & (RAW3215_BUFFER_SIZE - 1);
-	len = ((req->end - req->start) & (RAW3215_BUFFER_SIZE - 1)) + 1;
+        req->start = (raw->head - raw->count + raw->written) &
+                     (RAW3215_BUFFER_SIZE - 1);
+        /*
+         * now we have to count newlines. We can at max accept
+         * RAW3215_MAX_NEWLINE newlines in a single ssch due to
+         * a restriction in VM
+         */
+        lines = 0;
+        ix = req->start;
+        while (lines < RAW3215_MAX_NEWLINE && ix != raw->head) {
+                if (raw->buffer[ix] == 0x15)
+                        lines++;
+                ix = (ix + 1) & (RAW3215_BUFFER_SIZE - 1);
+        }
+	len = ((ix - 1 - req->start) & (RAW3215_BUFFER_SIZE - 1)) + 1;
+        if (len > RAW3215_MAX_BYTES)
+                len = RAW3215_MAX_BYTES;
+        req->len = len;
+        raw->written += len;
+
+        /* set the indication if we should try to enlarge this request */
+        req->delayable = (ix == raw->head) && (len < RAW3215_MIN_WRITE);
+
 	ix = req->start;
 	while (len > 0) {
 		if (ccw > req->ccws)
@@ -205,31 +238,26 @@
 		ccw->cmd_code = 0x01; /* write, auto carrier return */
 		ccw->flags = 0x20;    /* ignore incorrect length ind.  */
 		ccw->cda =
-			(void *) virt_to_phys(raw->buffer + ix);
-		count = (len > RAW3215_MAX_CCWLEN) ? 
-			RAW3215_MAX_CCWLEN : len;
+			(__u32) __pa(raw->buffer + ix);
+		count = len;
 		if (ix + count > RAW3215_BUFFER_SIZE)
-			count = RAW3215_BUFFER_SIZE-ix;
+			count = RAW3215_BUFFER_SIZE - ix;
 		ccw->count = count;
 		len -= count;
 		ix = (ix + count) & (RAW3215_BUFFER_SIZE - 1);
 		ccw++;
 	}
-	return len;
-}
-
-/*
- * Set up a read request that reads up to 160 byte from the 3215 device.
- */
-static void raw3215_mk_read_ccw(raw3215_info *raw, raw3215_req *req)
-{
-	ccw1_t *ccw;
-
-	ccw = req->ccws;
-	ccw->cmd_code = 0x0A; /* read inquiry */
-	ccw->flags = 0x20;    /* ignore incorrect length */
-	ccw->count = 160;
-	ccw->cda = (void *) virt_to_phys(raw->inbuf);
+        /*
+         * Add a NOP to the channel program. 3215 devices are purely
+         * emulated and its much better to avoid the channel end
+         * interrupt in this case.
+         */
+        if (ccw > req->ccws)
+                ccw[-1].flags |= 0x40; /* use command chaining */
+        ccw->cmd_code = 0x03; /* NOP */
+        ccw->flags = 0;
+        ccw->cda = 0;
+        ccw->count = 1;
 }
 
 /*
@@ -245,7 +273,7 @@
 	    !(raw->flags & (RAW3215_WORKING | RAW3215_THROTTLED))) {
 		/* dequeue request */
 		raw->queued_read = NULL;
-		res = do_IO(raw->irq, req->ccws, (__u32) req, 0, 0);
+		res = do_IO(raw->irq, req->ccws, (unsigned long) req, 0, 0);
 		if (res != 0) {
 			/* do_IO failed, put request back to queue */
 			raw->queued_read = req;
@@ -258,7 +286,7 @@
 	    !(raw->flags & (RAW3215_WORKING | RAW3215_STOPPED))) {
 		/* dequeue request */
 		raw->queued_write = NULL;
-		res = do_IO(raw->irq, req->ccws, (__u32) req, 0, 0);
+		res = do_IO(raw->irq, req->ccws, (unsigned long) req, 0, 0);
 		if (res != 0) {
 			/* do_IO failed, put request back to queue */
 			raw->queued_write = req;
@@ -280,6 +308,7 @@
 	if (raw->flags & RAW3215_TIMER_RUNS) {
 		del_timer(&raw->timer);
 		raw->flags &= ~RAW3215_TIMER_RUNS;
+                raw3215_mk_write_req(raw);
 		raw3215_start_io(raw);
 	}
 	s390irq_spin_unlock_irqrestore(raw->irq, flags);
@@ -298,10 +327,10 @@
 	if (raw->queued_read != NULL)
 		raw3215_start_io(raw);
 	else if (raw->queued_write != NULL) {
-		if (raw->count >= RAW3215_MIN_WRITE ||
+		if ((raw->queued_write->delayable == 0) ||
 		    (raw->flags & RAW3215_FLUSHING)) {
 			/* execute write requests bigger than minimum size */
-			raw3215_start_io(raw);
+                        raw3215_start_io(raw);
 			if (raw->flags & RAW3215_TIMER_RUNS) {
 				del_timer(&raw->timer);
 				raw->flags &= ~RAW3215_TIMER_RUNS;
@@ -330,7 +359,8 @@
 
 	raw = (raw3215_info *) data;
 	s390irq_spin_lock_irqsave(raw->irq, flags);
-	raw3215_try_io((raw3215_info *) data);
+        raw3215_mk_write_req(raw);
+        raw3215_try_io(raw);
         raw->flags &= ~RAW3215_BH_PENDING;
 	s390irq_spin_unlock_irqrestore(raw->irq, flags);
 	/* Check for pending message from raw3215_irq */
@@ -357,6 +387,8 @@
         if (raw->flags & RAW3215_BH_PENDING)
                 return;       /* already pending */
         raw->flags |= RAW3215_BH_PENDING;
+	INIT_LIST_HEAD(&raw->tqueue.list);
+	raw->tqueue.sync = 0;
         raw->tqueue.routine = raw3215_softint;
         raw->tqueue.data = raw;
         queue_task(&raw->tqueue, &tq_immediate);
@@ -417,9 +449,7 @@
 		if ((raw = raw3215_find_info(irq)) == NULL)
 			return;              /* That shouldn't happen ... */
 		/* Setup a read request */
-		req = raw3215_mk_read_req(raw);
-		raw3215_mk_read_ccw(raw, req);
-		raw->queued_read = req;
+		raw3215_mk_read_req(raw);
                 if (MACHINE_IS_P390)
                         memset(raw->inbuf, 0, RAW3215_INBUF_SIZE);
                 raw3215_sched_bh(raw);
@@ -427,7 +457,8 @@
 	case 0x08:
 	case 0x0C:
 		/* Channel end interrupt. */
-		raw = req->info;
+		if ((raw = req->info) == NULL)
+                        return;              /* That shouldn't happen ... */
 		if (req->type == RAW3215_READ) {
 			/* store residual count, then wait for device end */
 			req->residual = stat->rescnt;
@@ -436,7 +467,8 @@
 			break;
 	case 0x04:
 		/* Device end interrupt. */
-		raw = req->info;
+                if ((raw = req->info) == NULL)
+                        return;              /* That shouldn't happen ... */
 		if (req->type == RAW3215_READ && raw->tty != NULL) {
 			tty = raw->tty;
                         count = 160 - req->residual;
@@ -449,28 +481,28 @@
 				count = TTY_FLIPBUF_SIZE - tty->flip.count - 1;
 			EBCASC(raw->inbuf, count);
 			if (count == 2 && (
-                            /* hat is 0xb0 in codepage 037 (US etc.) and thus */
-                            /* converted to 0x5e in ascii ('^') */
-                            strncmp(raw->inbuf, "^c", 2) == 0 ||
-                            /* hat is 0xb0 in several other codepages (German,*/
-                            /* UK, ...) and thus converted to ascii octal 252 */
-                            strncmp(raw->inbuf, "\252c", 2) == 0) ) {
+			    /* hat is 0xb0 in codepage 037 (US etc.) and thus */
+			    /* converted to 0x5e in ascii ('^') */
+			    strncmp(raw->inbuf, "^c", 2) == 0 ||
+			    /* hat is 0xb0 in several other codepages (German,*/
+			    /* UK, ...) and thus converted to ascii octal 252 */
+			    strncmp(raw->inbuf, "\252c", 2) == 0) ) {
 				/* emulate a control C = break */
 				tty->flip.count++;
 				*tty->flip.flag_buf_ptr++ = TTY_NORMAL;
 				*tty->flip.char_buf_ptr++ = INTR_CHAR(tty);
 				tty_flip_buffer_push(raw->tty);
 			} else if (count == 2 && (
-                                   strncmp(raw->inbuf, "^d", 2) == 0 ||
-                                    strncmp(raw->inbuf, "\252d", 2) == 0) ) {
+				   strncmp(raw->inbuf, "^d", 2) == 0 ||
+				    strncmp(raw->inbuf, "\252d", 2) == 0) ) {
 				/* emulate a control D = end of file */
 				tty->flip.count++;
 				*tty->flip.flag_buf_ptr++ = TTY_NORMAL;
 				*tty->flip.char_buf_ptr++ = EOF_CHAR(tty);
 				tty_flip_buffer_push(raw->tty);
 			} else if (count == 2 && (
-                                   strncmp(raw->inbuf, "^z", 2) == 0 ||
-                                    strncmp(raw->inbuf, "\252z", 2) == 0) ) {
+				   strncmp(raw->inbuf, "^z", 2) == 0 ||
+				    strncmp(raw->inbuf, "\252z", 2) == 0) ) {
 				/* emulate a control Z = suspend */
 				tty->flip.count++;
 				*tty->flip.flag_buf_ptr++ = TTY_NORMAL;
@@ -480,8 +512,9 @@
 				memcpy(tty->flip.char_buf_ptr,
 				       raw->inbuf, count);
 				if (count < 2 ||
-                                    (strncmp(raw->inbuf+count-2, "^n", 2) ||
-                                    strncmp(raw->inbuf+count-2, "\252n", 2)) ) {					/* don't add the auto \n */
+				    (strncmp(raw->inbuf+count-2, "^n", 2) ||
+				    strncmp(raw->inbuf+count-2, "\252n", 2)) ) {
+					/* don't add the auto \n */
 					tty->flip.char_buf_ptr[count] = '\n';
 					memset(tty->flip.flag_buf_ptr,
 					       TTY_NORMAL, count + 1);
@@ -494,9 +527,9 @@
 				tty_flip_buffer_push(raw->tty);
 			}
 		} else if (req->type == RAW3215_WRITE) {
-			raw->count -= ((req->end - req->start) &
-				       (RAW3215_BUFFER_SIZE - 1)) + 1;
-		}
+			raw->count -= req->len;
+                        raw->written -= req->len;
+		} 
 		raw->flags &= ~RAW3215_WORKING;
 		raw3215_free_req(req);
 		/* check for empty wait */
@@ -513,9 +546,10 @@
                         return;              /* That shouldn't happen ... */
                 if (raw == NULL) break;
 		if (req != NULL && req->type != RAW3215_FREE) {
-		        if (req->type == RAW3215_WRITE) 
-			        raw->count -= ((req->end - req->start) &
-				              (RAW3215_BUFFER_SIZE-1))+1;
+		        if (req->type == RAW3215_WRITE) {
+			        raw->count -= req->len;
+                                raw->written -= req->len;
+                        }
                         raw->flags &= ~RAW3215_WORKING;
                         raw3215_free_req(req);
 		}
@@ -530,13 +564,40 @@
 }
 
 /*
+ * Wait until length bytes are available int the output buffer.
+ * Has to be called with the s390irq lock held. Can be called
+ * disabled.
+ */
+void raw3215_make_room(raw3215_info *raw, unsigned int length)
+{
+	while (RAW3215_BUFFER_SIZE - raw->count < length) {
+		/* there might be a request pending */
+		raw->flags |= RAW3215_FLUSHING;
+		raw3215_mk_write_req(raw);
+		raw3215_try_io(raw);
+		raw->flags &= ~RAW3215_FLUSHING;
+		if (wait_cons_dev(raw->irq) != 0) {
+			/* that shouldn't happen */
+			raw->count = 0;
+			raw->written = 0;
+		}
+		/* Enough room freed up ? */
+		if (RAW3215_BUFFER_SIZE - raw->count >= length)
+			break;
+		/* there might be another cpu waiting for the lock */
+		s390irq_spin_unlock(raw->irq);
+		udelay(100);
+		s390irq_spin_lock(raw->irq);
+	}
+}
+
+/*
  * String write routine for 3215 devices
  */
 static int
 raw3215_write(raw3215_info *raw, const char *str,
 	      int from_user, unsigned int length)
 {
-	raw3215_req *req;
 	unsigned long flags;
 	int ret, c;
 	int count;
@@ -548,16 +609,8 @@
 					     RAW3215_BUFFER_SIZE : length;
 		length -= count;
 
-		while (RAW3215_BUFFER_SIZE - raw->count < count) {
-			/* there might be a request pending */
-			raw3215_try_io(raw);
-			if (wait_cons_dev(raw->irq) != 0) {
-				/* that shouldn't happen */
-				raw->count = 0;
-			} 
-		}
+                raw3215_make_room(raw, count);
 
-		req = raw3215_mk_write_req(raw);
 		/* copy string to output buffer and convert it to EBCDIC */
 		if (from_user) {
 			while (1) {
@@ -577,6 +630,7 @@
 				raw->head = (raw->head + c) &
 					    (RAW3215_BUFFER_SIZE - 1);
 				raw->count += c;
+				raw->line_pos += c;
 				str += c;
 				count -= c;
 				ret += c;
@@ -593,17 +647,18 @@
 				raw->head = (raw->head + c) &
 					    (RAW3215_BUFFER_SIZE - 1);
 				raw->count += c;
+				raw->line_pos += c;
 				str += c;
 				count -= c;
 				ret += c;
 			}
 		}
-		raw3215_mk_write_ccw(raw, req);
-		raw->queued_write = req;
-		/* start or queue request */
-		raw3215_try_io(raw);
+                if (!(raw->flags & RAW3215_WORKING)) {
+                        raw3215_mk_write_req(raw);
+		        /* start or queue request */
+		        raw3215_try_io(raw);
+                }
 		s390irq_spin_unlock_irqrestore(raw->irq, flags);
-
 	}
 
 	return ret;
@@ -612,29 +667,36 @@
 /*
  * Put character routine for 3215 devices
  */
+	
 static void raw3215_putchar(raw3215_info *raw, unsigned char ch)
 {
-	raw3215_req *req;
 	unsigned long flags;
+        unsigned int length, i;
 
 	s390irq_spin_lock_irqsave(raw->irq, flags);
-	while (RAW3215_BUFFER_SIZE - raw->count < 1) {
-		/* there might be a request pending */
-		raw3215_try_io(raw);
-		if (wait_cons_dev(raw->irq) != 0) {
-			/* that shouldn't happen */
-			raw->count = 0;
-		}
+	if (ch == '\t') {
+		length = TAB_STOP_SIZE - (raw->line_pos%TAB_STOP_SIZE);
+		raw->line_pos += length;
+		ch = ' ';
+        } else if (ch == '\n') {
+		length = 1;
+		raw->line_pos = 0;
+	} else {
+		length = 1;
+		raw->line_pos++;
 	}
+        raw3215_make_room(raw, length);
 
-	req = raw3215_mk_write_req(raw);
-	raw->buffer[raw->head] = (char) _ascebc[(int) ch];
-	raw->head = (raw->head + 1) & (RAW3215_BUFFER_SIZE - 1);
-	raw->count++;
-	raw3215_mk_write_ccw(raw, req);
-	raw->queued_write = req;
-	/* start or queue request */
-	raw3215_try_io(raw);
+	for (i = 0; i < length; i++) {
+		raw->buffer[raw->head] = (char) _ascebc[(int) ch];
+		raw->head = (raw->head + 1) & (RAW3215_BUFFER_SIZE - 1);
+		raw->count++;
+	}
+        if (!(raw->flags & RAW3215_WORKING)) {
+                raw3215_mk_write_req(raw);
+	        /* start or queue request */
+	        raw3215_try_io(raw);
+        }
 	s390irq_spin_unlock_irqrestore(raw->irq, flags);
 }
 
@@ -667,8 +729,10 @@
 	if (request_irq(raw->irq, raw3215_irq, SA_INTERRUPT,
 			"3215 terminal driver", &raw->devstat) != 0)
 		return -1;
+	raw->line_pos = 0;
 	raw->flags |= RAW3215_ACTIVE;
 	s390irq_spin_lock_irqsave(raw->irq, flags);
+        set_cons_dev(raw->irq);
 	raw3215_try_io(raw);
 	s390irq_spin_unlock_irqrestore(raw->irq, flags);
 
@@ -680,7 +744,7 @@
  */
 static void raw3215_shutdown(raw3215_info *raw)
 {
-	DECLARE_WAITQUEUE(wait, current);
+        DECLARE_WAITQUEUE(wait, current);
 	unsigned long flags;
 
 	if (!(raw->flags & RAW3215_ACTIVE) || (raw->flags & RAW3215_FIXED))
@@ -707,7 +771,7 @@
 static int
 raw3215_find_dev(int number)
 {
-	dev_info_t dinfo;
+	s390_dev_info_t dinfo;
 	int irq;
 	int count;
 
@@ -739,7 +803,8 @@
         if (!MACHINE_IS_VM && !MACHINE_IS_P390)
                 return 0;
 	raw = raw3215[0];  /* 3215 console is the first one */
-	if (raw->irq == -1) /* now console device found in con3215_init */
+	if (raw == NULL || raw->irq == -1)
+                /* console device not found in con3215_init */
 		return -1;
 	return raw3215_startup(raw);
 }
@@ -751,16 +816,29 @@
 con3215_write(struct console *co, const char *str, unsigned int count)
 {
 	raw3215_info *raw;
+	int i;
 
 	if (count <= 0)
 		return;
-	raw = raw3215[0];  /* console 3215 is the first one */
-	raw3215_write(raw, str, 0, count);
+        raw = raw3215[0];       /* console 3215 is the first one */
+        while (count > 0) {
+                for (i = 0; i < count; i++)
+                        if (str[i] == '\t' || str[i] == '\n')
+                                break;
+                raw3215_write(raw, str, 0, i);
+		count -= i;
+		str += i;
+                if (count > 0) {
+			raw3215_putchar(raw, *str);
+			count--;
+			str++;
+                }
+        }
 }
 
 kdev_t con3215_device(struct console *c)
 {
-	return MKDEV(TTY_MAJOR, c->index);
+	return MKDEV(TTY_MAJOR, c->index + 64 );
 }
 
 /*
@@ -774,16 +852,7 @@
 
 	raw = raw3215[0];  /* console 3215 is the first one */
 	s390irq_spin_lock_irqsave(raw->irq, flags);
-	while (raw->count > 0) {
-		/* there might be a request pending */
-		raw->flags |= RAW3215_FLUSHING;
-		raw3215_try_io(raw);
-		if (wait_cons_dev(raw->irq) != 0) {
-			/* that shouldn't happen */
-			raw->count = 0;
-		}
-		raw->flags &= ~RAW3215_FLUSHING;
-	}
+	raw3215_make_room(raw, RAW3215_BUFFER_SIZE);
 	s390irq_spin_unlock_irqrestore(raw->irq, flags);
 }
 
@@ -823,7 +892,7 @@
 	raw = raw3215[line];
 	if (raw == NULL) {
 		raw = kmalloc(sizeof(raw3215_info) +
-			      RAW3215_INBUF_SIZE, GFP_KERNEL);
+			      RAW3215_INBUF_SIZE, GFP_KERNEL|GFP_DMA);
 		if (raw == NULL)
 			return -ENOMEM;
 		raw->irq = raw3215_find_dev(line);
@@ -833,7 +902,8 @@
 		}
 		raw->inbuf = (char *) raw + sizeof(raw3215_info);
 		memset(raw, 0, sizeof(raw3215_info));
-		raw->buffer = (char *) kmalloc(RAW3215_BUFFER_SIZE, GFP_KERNEL);
+		raw->buffer = (char *) kmalloc(RAW3215_BUFFER_SIZE,
+					       GFP_KERNEL|GFP_DMA);
 		if (raw->buffer == NULL) {
 			kfree(raw);
 			return -ENOMEM;
@@ -886,7 +956,12 @@
 	raw3215_info *raw;
 				
 	raw = (raw3215_info *) tty->driver_data;
-	return RAW3215_BUFFER_SIZE - raw->count;
+
+	/* Subtract TAB_STOP_SIZE to allow for a tab, 8 <<< 64K */
+	if ((RAW3215_BUFFER_SIZE - raw->count - TAB_STOP_SIZE) >= 0)
+		return RAW3215_BUFFER_SIZE - raw->count - TAB_STOP_SIZE;
+	else
+		return 0;
 }
 
 /*
@@ -896,7 +971,7 @@
 		    const unsigned char *buf, int count)
 {
 	raw3215_info *raw;
-	int ret;
+	int ret = 0;
 				
 	if (!tty)
 		return 0;
@@ -1041,17 +1116,18 @@
 	raw3215_freelist = NULL;
 	spin_lock_init(&raw3215_freelist_lock);
 	for (i = 0; i < NR_3215_REQ; i++) {
-		req = (raw3215_req *) alloc_bootmem(sizeof(raw3215_req));
+                req = (raw3215_req *) alloc_bootmem_low(sizeof(raw3215_req));
 		req->next = raw3215_freelist;
 		raw3215_freelist = req;
 	}
 
 #ifdef CONFIG_3215_CONSOLE
-	raw3215[0] = raw = (raw3215_info *) 
-		alloc_bootmem(sizeof(raw3215_info));
+        raw3215[0] = raw = (raw3215_info *)
+                alloc_bootmem_low(sizeof(raw3215_info));
 	memset(raw, 0, sizeof(raw3215_info));
-	raw->buffer = (char *) alloc_bootmem(RAW3215_BUFFER_SIZE);
-	raw->inbuf = (char *) alloc_bootmem(RAW3215_INBUF_SIZE);
+        raw->buffer = (char *) alloc_bootmem_low(RAW3215_BUFFER_SIZE);
+        raw->inbuf = (char *) alloc_bootmem_low(RAW3215_INBUF_SIZE);
+
 	/* Find the first console */
 	raw->irq = raw3215_find_dev(0);
 	raw->flags |= RAW3215_FIXED;
@@ -1061,13 +1137,10 @@
 
 	if (raw->irq != -1) {
 		register_console(&con3215);
-		s390irq_spin_lock(raw->irq);
-		set_cons_dev(raw->irq);
-		s390irq_spin_unlock(raw->irq);
 	} else {
-		free_bootmem((unsigned long) raw->inbuf, RAW3215_INBUF_SIZE);
-		free_bootmem((unsigned long) raw->buffer, RAW3215_BUFFER_SIZE);
-		free_bootmem((unsigned long) raw, sizeof(raw3215_info));
+                free_bootmem((unsigned long) raw->inbuf, RAW3215_INBUF_SIZE);
+                free_bootmem((unsigned long) raw->buffer, RAW3215_BUFFER_SIZE);
+                free_bootmem((unsigned long) raw, sizeof(raw3215_info));
 		raw3215[0] = NULL;
 		printk("Couldn't find a 3215 console device\n");
 	}
@@ -1091,7 +1164,7 @@
 	tty3215_driver.subtype = SYSTEM_TYPE_TTY;
 	tty3215_driver.init_termios = tty_std_termios;
 	tty3215_driver.init_termios.c_iflag = IGNBRK | IGNPAR;
-	tty3215_driver.init_termios.c_oflag = ONLCR;
+	tty3215_driver.init_termios.c_oflag = ONLCR | XTABS;
 	tty3215_driver.init_termios.c_lflag = ISIG;
 	tty3215_driver.flags = TTY_DRIVER_REAL_RAW;
 	tty3215_driver.refcount = &tty3215_refcount;

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)