aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char/stallion.c
diff options
context:
space:
mode:
authorAlan Cox <alan@lxorguk.ukuu.org.uk>2006-01-09 23:54:13 -0500
committerLinus Torvalds <torvalds@g5.osdl.org>2006-01-10 11:01:59 -0500
commit33f0f88f1c51ae5c2d593d26960c760ea154c2e2 (patch)
treef53a38cf49406863f079d74d0e8f91b276f7c1a9 /drivers/char/stallion.c
parent6ed80991a2dce4afc113be35089c564d62fa1f11 (diff)
[PATCH] TTY layer buffering revamp
The API and code have been through various bits of initial review by serial driver people but they definitely need to live somewhere for a while so the unconverted drivers can get knocked into shape, existing drivers that have been updated can be better tuned and bugs whacked out. This replaces the tty flip buffers with kmalloc objects in rings. In the normal situation for an IRQ driven serial port at typical speeds the behaviour is pretty much the same, two buffers end up allocated and the kernel cycles between them as before. When there are delays or at high speed we now behave far better as the buffer pool can grow a bit rather than lose characters. This also means that we can operate at higher speeds reliably. For drivers that receive characters in blocks (DMA based, USB and especially virtualisation) the layer allows a lot of driver specific code that works around the tty layer with private secondary queues to be removed. The IBM folks need this sort of layer, the smart serial port people do, the virtualisers do (because a virtualised tty typically operates at infinite speed rather than emulating 9600 baud). Finally many drivers had invalid and unsafe attempts to avoid buffer overflows by directly invoking tty methods extracted out of the innards of work queue structs. These are no longer needed and all go away. That fixes various random hangs with serial ports on overflow. The other change in here is to optimise the receive_room path that is used by some callers. It turns out that only one ldisc uses receive room except asa constant and it updates it far far less than the value is read. We thus make it a variable not a function call. I expect the code to contain bugs due to the size alone but I'll be watching and squashing them and feeding out new patches as it goes. Because the buffers now dynamically expand you should only run out of buffering when the kernel runs out of memory for real. That means a lot of the horrible hacks high performance drivers used to do just aren't needed any more. Description: tty_insert_flip_char is an old API and continues to work as before, as does tty_flip_buffer_push() [this is why many drivers dont need modification]. It does now also return the number of chars inserted There are also tty_buffer_request_room(tty, len) which asks for a buffer block of the length requested and returns the space found. This improves efficiency with hardware that knows how much to transfer. and tty_insert_flip_string_flags(tty, str, flags, len) to insert a string of characters and flags For a smart interface the usual code is len = tty_request_buffer_room(tty, amount_hardware_says); tty_insert_flip_string(tty, buffer_from_card, len); More description! At the moment tty buffers are attached directly to the tty. This is causing a lot of the problems related to tty layer locking, also problems at high speed and also with bursty data (such as occurs in virtualised environments) I'm working on ripping out the flip buffers and replacing them with a pool of dynamically allocated buffers. This allows both for old style "byte I/O" devices and also helps virtualisation and smart devices where large blocks of data suddenely materialise and need storing. So far so good. Lots of drivers reference tty->flip.*. Several of them also call directly and unsafely into function pointers it provides. This will all break. Most drivers can use tty_insert_flip_char which can be kept as an API but others need more. At the moment I've added the following interfaces, if people think more will be needed now is a good time to say int tty_buffer_request_room(tty, size) Try and ensure at least size bytes are available, returns actual room (may be zero). At the moment it just uses the flipbuf space but that will change. Repeated calls without characters being added are not cumulative. (ie if you call it with 1, 1, 1, and then 4 you'll have four characters of space. The other functions will also try and grow buffers in future but this will be a more efficient way when you know block sizes. int tty_insert_flip_char(tty, ch, flag) As before insert a character if there is room. Now returns 1 for success, 0 for failure. int tty_insert_flip_string(tty, str, len) Insert a block of non error characters. Returns the number inserted. int tty_prepare_flip_string(tty, strptr, len) Adjust the buffer to allow len characters to be added. Returns a buffer pointer in strptr and the length available. This allows for hardware that needs to use functions like insl or mencpy_fromio. Signed-off-by: Alan Cox <alan@redhat.com> Cc: Paul Fulghum <paulkf@microgate.com> Signed-off-by: Hirokazu Takata <takata@linux-m32r.org> Signed-off-by: Serge Hallyn <serue@us.ibm.com> Signed-off-by: Jeff Dike <jdike@addtoit.com> Signed-off-by: John Hawkes <hawkes@sgi.com> Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com> Signed-off-by: Adrian Bunk <bunk@stusta.de> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'drivers/char/stallion.c')
-rw-r--r--drivers/char/stallion.c50
1 files changed, 15 insertions, 35 deletions
diff --git a/drivers/char/stallion.c b/drivers/char/stallion.c
index acef2abf3f0d..0e20780d4a29 100644
--- a/drivers/char/stallion.c
+++ b/drivers/char/stallion.c
@@ -2901,7 +2901,8 @@ static int stl_getportstats(stlport_t *portp, comstats_t __user *cp)
2901 if (portp->tty != (struct tty_struct *) NULL) { 2901 if (portp->tty != (struct tty_struct *) NULL) {
2902 if (portp->tty->driver_data == portp) { 2902 if (portp->tty->driver_data == portp) {
2903 portp->stats.ttystate = portp->tty->flags; 2903 portp->stats.ttystate = portp->tty->flags;
2904 portp->stats.rxbuffered = portp->tty->flip.count; 2904 /* No longer available as a statistic */
2905 portp->stats.rxbuffered = 1; /*portp->tty->flip.count; */
2905 if (portp->tty->termios != (struct termios *) NULL) { 2906 if (portp->tty->termios != (struct termios *) NULL) {
2906 portp->stats.cflags = portp->tty->termios->c_cflag; 2907 portp->stats.cflags = portp->tty->termios->c_cflag;
2907 portp->stats.iflags = portp->tty->termios->c_iflag; 2908 portp->stats.iflags = portp->tty->termios->c_iflag;
@@ -4045,9 +4046,7 @@ static void stl_cd1400rxisr(stlpanel_t *panelp, int ioaddr)
4045 if ((ioack & ACK_TYPMASK) == ACK_TYPRXGOOD) { 4046 if ((ioack & ACK_TYPMASK) == ACK_TYPRXGOOD) {
4046 outb((RDCR + portp->uartaddr), ioaddr); 4047 outb((RDCR + portp->uartaddr), ioaddr);
4047 len = inb(ioaddr + EREG_DATA); 4048 len = inb(ioaddr + EREG_DATA);
4048 if ((tty == (struct tty_struct *) NULL) || 4049 if (tty == NULL || (buflen = tty_buffer_request_room(tty, len)) == 0) {
4049 (tty->flip.char_buf_ptr == (char *) NULL) ||
4050 ((buflen = TTY_FLIPBUF_SIZE - tty->flip.count) == 0)) {
4051 len = MIN(len, sizeof(stl_unwanted)); 4050 len = MIN(len, sizeof(stl_unwanted));
4052 outb((RDSR + portp->uartaddr), ioaddr); 4051 outb((RDSR + portp->uartaddr), ioaddr);
4053 insb((ioaddr + EREG_DATA), &stl_unwanted[0], len); 4052 insb((ioaddr + EREG_DATA), &stl_unwanted[0], len);
@@ -4056,12 +4055,10 @@ static void stl_cd1400rxisr(stlpanel_t *panelp, int ioaddr)
4056 } else { 4055 } else {
4057 len = MIN(len, buflen); 4056 len = MIN(len, buflen);
4058 if (len > 0) { 4057 if (len > 0) {
4058 unsigned char *ptr;
4059 outb((RDSR + portp->uartaddr), ioaddr); 4059 outb((RDSR + portp->uartaddr), ioaddr);
4060 insb((ioaddr + EREG_DATA), tty->flip.char_buf_ptr, len); 4060 tty_prepare_flip_string(tty, &ptr, len);
4061 memset(tty->flip.flag_buf_ptr, 0, len); 4061 insb((ioaddr + EREG_DATA), ptr, len);
4062 tty->flip.flag_buf_ptr += len;
4063 tty->flip.char_buf_ptr += len;
4064 tty->flip.count += len;
4065 tty_schedule_flip(tty); 4062 tty_schedule_flip(tty);
4066 portp->stats.rxtotal += len; 4063 portp->stats.rxtotal += len;
4067 } 4064 }
@@ -4085,8 +4082,7 @@ static void stl_cd1400rxisr(stlpanel_t *panelp, int ioaddr)
4085 portp->stats.txxoff++; 4082 portp->stats.txxoff++;
4086 goto stl_rxalldone; 4083 goto stl_rxalldone;
4087 } 4084 }
4088 if ((tty != (struct tty_struct *) NULL) && 4085 if (tty != NULL && (portp->rxignoremsk & status) == 0) {
4089 ((portp->rxignoremsk & status) == 0)) {
4090 if (portp->rxmarkmsk & status) { 4086 if (portp->rxmarkmsk & status) {
4091 if (status & ST_BREAK) { 4087 if (status & ST_BREAK) {
4092 status = TTY_BREAK; 4088 status = TTY_BREAK;
@@ -4106,14 +4102,8 @@ static void stl_cd1400rxisr(stlpanel_t *panelp, int ioaddr)
4106 } else { 4102 } else {
4107 status = 0; 4103 status = 0;
4108 } 4104 }
4109 if (tty->flip.char_buf_ptr != (char *) NULL) { 4105 tty_insert_flip_char(tty, ch, status);
4110 if (tty->flip.count < TTY_FLIPBUF_SIZE) { 4106 tty_schedule_flip(tty);
4111 *tty->flip.flag_buf_ptr++ = status;
4112 *tty->flip.char_buf_ptr++ = ch;
4113 tty->flip.count++;
4114 }
4115 tty_schedule_flip(tty);
4116 }
4117 } 4107 }
4118 } else { 4108 } else {
4119 printk("STALLION: bad RX interrupt ack value=%x\n", ioack); 4109 printk("STALLION: bad RX interrupt ack value=%x\n", ioack);
@@ -5012,9 +5002,7 @@ static void stl_sc26198rxisr(stlport_t *portp, unsigned int iack)
5012 len = inb(ioaddr + XP_DATA) + 1; 5002 len = inb(ioaddr + XP_DATA) + 1;
5013 5003
5014 if ((iack & IVR_TYPEMASK) == IVR_RXDATA) { 5004 if ((iack & IVR_TYPEMASK) == IVR_RXDATA) {
5015 if ((tty == (struct tty_struct *) NULL) || 5005 if (tty == NULL || (buflen = tty_buffer_request_room(tty, len)) == 0) {
5016 (tty->flip.char_buf_ptr == (char *) NULL) ||
5017 ((buflen = TTY_FLIPBUF_SIZE - tty->flip.count) == 0)) {
5018 len = MIN(len, sizeof(stl_unwanted)); 5006 len = MIN(len, sizeof(stl_unwanted));
5019 outb(GRXFIFO, (ioaddr + XP_ADDR)); 5007 outb(GRXFIFO, (ioaddr + XP_ADDR));
5020 insb((ioaddr + XP_DATA), &stl_unwanted[0], len); 5008 insb((ioaddr + XP_DATA), &stl_unwanted[0], len);
@@ -5023,12 +5011,10 @@ static void stl_sc26198rxisr(stlport_t *portp, unsigned int iack)
5023 } else { 5011 } else {
5024 len = MIN(len, buflen); 5012 len = MIN(len, buflen);
5025 if (len > 0) { 5013 if (len > 0) {
5014 unsigned char *ptr;
5026 outb(GRXFIFO, (ioaddr + XP_ADDR)); 5015 outb(GRXFIFO, (ioaddr + XP_ADDR));
5027 insb((ioaddr + XP_DATA), tty->flip.char_buf_ptr, len); 5016 tty_prepare_flip_string(tty, &ptr, len);
5028 memset(tty->flip.flag_buf_ptr, 0, len); 5017 insb((ioaddr + XP_DATA), ptr, len);
5029 tty->flip.flag_buf_ptr += len;
5030 tty->flip.char_buf_ptr += len;
5031 tty->flip.count += len;
5032 tty_schedule_flip(tty); 5018 tty_schedule_flip(tty);
5033 portp->stats.rxtotal += len; 5019 portp->stats.rxtotal += len;
5034 } 5020 }
@@ -5096,14 +5082,8 @@ static inline void stl_sc26198rxbadch(stlport_t *portp, unsigned char status, ch
5096 status = 0; 5082 status = 0;
5097 } 5083 }
5098 5084
5099 if (tty->flip.char_buf_ptr != (char *) NULL) { 5085 tty_insert_flip_char(tty, ch, status);
5100 if (tty->flip.count < TTY_FLIPBUF_SIZE) { 5086 tty_schedule_flip(tty);
5101 *tty->flip.flag_buf_ptr++ = status;
5102 *tty->flip.char_buf_ptr++ = ch;
5103 tty->flip.count++;
5104 }
5105 tty_schedule_flip(tty);
5106 }
5107 5087
5108 if (status == 0) 5088 if (status == 0)
5109 portp->stats.rxtotal++; 5089 portp->stats.rxtotal++;