patch-2.2.17 linux/drivers/s390/char/con3215.c
Next file: linux/drivers/s390/char/hwc_tty.c
Previous file: linux/drivers/s390/ccwcache.c
Back to the patch index
Back to the overall index
- Lines: 366
- Date:
Mon Sep 4 18:39:20 2000
- Orig file:
v2.2.16/drivers/s390/char/con3215.c
- Orig date:
Mon Sep 4 18:37:42 2000
diff -u --recursive --new-file v2.2.16/drivers/s390/char/con3215.c linux/drivers/s390/char/con3215.c
@@ -30,8 +30,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 */
@@ -60,7 +61,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 */
@@ -74,6 +76,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 */
@@ -104,7 +107,7 @@
{
int vdev;
- vdev = simple_strtoul(str,&str,16);
+ vdev = simple_strtoul(str,&str,10);
if (vdev >= 0 && vdev < 65536)
raw3215_condevice = vdev;
return;
@@ -140,61 +143,83 @@
}
/*
- * 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.
+ * 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_write_req(raw3215_info *raw)
+static void raw3215_mk_read_req(raw3215_info *raw)
{
raw3215_req *req;
+ ccw1_t *ccw;
- /* check if there is a queued write request */
- req = raw->queued_write;
+ /* there can only be ONE read request at a time */
+ req = raw->queued_read;
if (req == NULL) {
- /* no queued write request, use new req structure */
+ /* no queued read request, use new req structure */
req = raw3215_alloc_req();
- req->type = RAW3215_WRITE;
+ req->type = RAW3215_READ;
req->info = raw;
- req->start = raw->head;
- } else
- raw->queued_write = 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 = (void *) virt_to_phys(raw->inbuf);
}
/*
- * 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 write request with the information from the main structure.
+ * 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 raw3215_req *raw3215_mk_read_req(raw3215_info *raw)
+static void raw3215_mk_write_req(raw3215_info *raw)
{
raw3215_req *req;
+ ccw1_t *ccw;
+ int len, count, ix, lines;
- /* there can only be ONE read request at a time */
- req = raw->queued_read;
+ if (raw->count <= raw->written)
+ return;
+ /* check if there is a queued write request */
+ req = raw->queued_write;
if (req == NULL) {
- /* no queued read request, use new req structure */
+ /* no queued write request, use new req structure */
req = raw3215_alloc_req();
- req->type = RAW3215_READ;
+ req->type = RAW3215_WRITE;
req->info = raw;
- } else
- raw->queued_read = NULL;
- return req;
+ raw->queued_write = req;
+ } else {
+ raw->written -= req->len;
}
+ ccw = req->ccws;
+ req->start = (raw->head - raw->count + raw->written) &
+ (RAW3215_BUFFER_SIZE - 1);
/*
- * 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.
- */
-static int raw3215_mk_write_ccw(raw3215_info *raw, raw3215_req *req)
-{
- ccw1_t *ccw;
- int len, count, ix;
+ * 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] == '\n')
+ 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);
- ccw = req->ccws;
- req->end = (raw->head - 1) & (RAW3215_BUFFER_SIZE - 1);
- len = ((req->end - req->start) & (RAW3215_BUFFER_SIZE - 1)) + 1;
ix = req->start;
while (len > 0) {
if (ccw > req->ccws)
@@ -203,8 +228,7 @@
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;
+ count = len;
if (ix + count > RAW3215_BUFFER_SIZE)
count = RAW3215_BUFFER_SIZE-ix;
ccw->count = count;
@@ -212,21 +236,17 @@
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;
}
/*
@@ -277,6 +297,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);
@@ -295,7 +316,7 @@
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);
@@ -327,7 +348,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 */
@@ -415,9 +437,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);
@@ -425,7 +445,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;
@@ -434,7 +455,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;
@@ -493,8 +515,8 @@
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);
@@ -511,11 +533,11 @@
/* Strange interrupt, I'll do my best to clean up */
if ((raw = raw3215_find_info(irq)) == NULL)
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);
}
@@ -536,7 +558,6 @@
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;
@@ -550,14 +571,15 @@
while (RAW3215_BUFFER_SIZE - raw->count < count) {
/* there might be a request pending */
+ raw3215_mk_write_req(raw);
raw3215_try_io(raw);
if (wait_cons_dev(raw->irq) != 0) {
/* that shouldn't happen */
raw->count = 0;
+ raw->written = 0;
}
}
- req = raw3215_mk_write_req(raw);
/* copy string to output buffer and convert it to EBCDIC */
if (from_user) {
while (1) {
@@ -598,12 +620,12 @@
ret += c;
}
}
- raw3215_mk_write_ccw(raw, req);
- raw->queued_write = req;
+ 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;
@@ -614,27 +636,28 @@
*/
static void raw3215_putchar(raw3215_info *raw, unsigned char ch)
{
- raw3215_req *req;
unsigned long flags;
s390irq_spin_lock_irqsave(raw->irq, flags);
while (RAW3215_BUFFER_SIZE - raw->count < 1) {
/* there might be a request pending */
+ raw3215_mk_write_req(raw);
raw3215_try_io(raw);
if (wait_cons_dev(raw->irq) != 0) {
/* that shouldn't happen */
raw->count = 0;
+ raw->written = 0;
}
}
- 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;
+ 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);
}
@@ -781,6 +804,7 @@
if (wait_cons_dev(raw->irq) != 0) {
/* that shouldn't happen */
raw->count = 0;
+ raw->written = 0;
}
raw->flags &= ~RAW3215_FLUSHING;
}
FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)