Commit 2108eba5 authored by Jiri Slaby's avatar Jiri Slaby Committed by Linus Torvalds

Char: moxa, cleanup rx/tx

- cleanup types
- use tty_prepare_flip_string and io memcpys
Signed-off-by: default avatarJiri Slaby <jirislaby@gmail.com>
Tested-by: default avatarOyvind Aabling <Oyvind.Aabling@uni-c.dk>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 7bcf97d1
...@@ -224,7 +224,7 @@ static void MoxaPortLineCtrl(struct moxa_port *, int, int); ...@@ -224,7 +224,7 @@ static void MoxaPortLineCtrl(struct moxa_port *, int, int);
static void MoxaPortFlowCtrl(struct moxa_port *, int, int, int, int, int); static void MoxaPortFlowCtrl(struct moxa_port *, int, int, int, int, int);
static int MoxaPortLineStatus(struct moxa_port *); static int MoxaPortLineStatus(struct moxa_port *);
static void MoxaPortFlushData(struct moxa_port *, int); static void MoxaPortFlushData(struct moxa_port *, int);
static int MoxaPortWriteData(struct moxa_port *, unsigned char *, int); static int MoxaPortWriteData(struct moxa_port *, const unsigned char *, int);
static int MoxaPortReadData(struct moxa_port *); static int MoxaPortReadData(struct moxa_port *);
static int MoxaPortTxQueue(struct moxa_port *); static int MoxaPortTxQueue(struct moxa_port *);
static int MoxaPortRxQueue(struct moxa_port *); static int MoxaPortRxQueue(struct moxa_port *);
...@@ -1165,7 +1165,7 @@ static int moxa_write(struct tty_struct *tty, ...@@ -1165,7 +1165,7 @@ static int moxa_write(struct tty_struct *tty,
return 0; return 0;
spin_lock_bh(&moxa_lock); spin_lock_bh(&moxa_lock);
len = MoxaPortWriteData(ch, (unsigned char *) buf, count); len = MoxaPortWriteData(ch, buf, count);
spin_unlock_bh(&moxa_lock); spin_unlock_bh(&moxa_lock);
/********************************************* /*********************************************
...@@ -2030,15 +2030,13 @@ static int MoxaPortLineStatus(struct moxa_port *port) ...@@ -2030,15 +2030,13 @@ static int MoxaPortLineStatus(struct moxa_port *port)
return val; return val;
} }
static int MoxaPortWriteData(struct moxa_port *port, unsigned char *buffer, static int MoxaPortWriteData(struct moxa_port *port,
int len) const unsigned char *buffer, int len)
{ {
int c, total, i;
ushort tail;
int cnt;
ushort head, tx_mask, spage, epage;
ushort pageno, pageofs, bufhead;
void __iomem *baseAddr, *ofsAddr, *ofs; void __iomem *baseAddr, *ofsAddr, *ofs;
unsigned int c, total;
u16 head, tail, tx_mask, spage, epage;
u16 pageno, pageofs, bufhead;
ofsAddr = port->tableAddr; ofsAddr = port->tableAddr;
baseAddr = port->board->basemem; baseAddr = port->board->basemem;
...@@ -2047,8 +2045,7 @@ static int MoxaPortWriteData(struct moxa_port *port, unsigned char *buffer, ...@@ -2047,8 +2045,7 @@ static int MoxaPortWriteData(struct moxa_port *port, unsigned char *buffer,
epage = readw(ofsAddr + EndPage_txb); epage = readw(ofsAddr + EndPage_txb);
tail = readw(ofsAddr + TXwptr); tail = readw(ofsAddr + TXwptr);
head = readw(ofsAddr + TXrptr); head = readw(ofsAddr + TXrptr);
c = (head > tail) ? (head - tail - 1) c = (head > tail) ? (head - tail - 1) : (head - tail + tx_mask);
: (head - tail + tx_mask);
if (c > len) if (c > len)
c = len; c = len;
moxaLog.txcnt[port->tty->index] += c; moxaLog.txcnt[port->tty->index] += c;
...@@ -2063,46 +2060,42 @@ static int MoxaPortWriteData(struct moxa_port *port, unsigned char *buffer, ...@@ -2063,46 +2060,42 @@ static int MoxaPortWriteData(struct moxa_port *port, unsigned char *buffer,
len = tx_mask + 1 - tail; len = tx_mask + 1 - tail;
len = (c > len) ? len : c; len = (c > len) ? len : c;
ofs = baseAddr + DynPage_addr + bufhead + tail; ofs = baseAddr + DynPage_addr + bufhead + tail;
for (i = 0; i < len; i++) memcpy_toio(ofs, buffer, len);
writeb(*buffer++, ofs + i); buffer += len;
tail = (tail + len) & tx_mask; tail = (tail + len) & tx_mask;
c -= len; c -= len;
} }
writew(tail, ofsAddr + TXwptr);
} else { } else {
len = c;
pageno = spage + (tail >> 13); pageno = spage + (tail >> 13);
pageofs = tail & Page_mask; pageofs = tail & Page_mask;
do { while (c > 0) {
cnt = Page_size - pageofs; len = Page_size - pageofs;
if (cnt > c) if (len > c)
cnt = c; len = c;
c -= cnt;
writeb(pageno, baseAddr + Control_reg); writeb(pageno, baseAddr + Control_reg);
ofs = baseAddr + DynPage_addr + pageofs; ofs = baseAddr + DynPage_addr + pageofs;
for (i = 0; i < cnt; i++) memcpy_toio(ofs, buffer, len);
writeb(*buffer++, ofs + i); buffer += len;
if (c == 0) {
writew((tail + len) & tx_mask, ofsAddr + TXwptr);
break;
}
if (++pageno == epage) if (++pageno == epage)
pageno = spage; pageno = spage;
pageofs = 0; pageofs = 0;
} while (1); c -= len;
} }
tail = (tail + total) & tx_mask;
}
writew(tail, ofsAddr + TXwptr);
writeb(1, ofsAddr + CD180TXirq); /* start to send */ writeb(1, ofsAddr + CD180TXirq); /* start to send */
return (total); return total;
} }
static int MoxaPortReadData(struct moxa_port *port) static int MoxaPortReadData(struct moxa_port *port)
{ {
struct tty_struct *tty = port->tty; struct tty_struct *tty = port->tty;
register ushort head, pageofs; unsigned char *dst;
int i, count, cnt, len, total, remain;
ushort tail, rx_mask, spage, epage;
ushort pageno, bufhead;
void __iomem *baseAddr, *ofsAddr, *ofs; void __iomem *baseAddr, *ofsAddr, *ofs;
unsigned int count, len, total;
u16 tail, rx_mask, spage, epage;
u16 pageno, pageofs, bufhead, head;
ofsAddr = port->tableAddr; ofsAddr = port->tableAddr;
baseAddr = port->board->basemem; baseAddr = port->board->basemem;
...@@ -2111,101 +2104,84 @@ static int MoxaPortReadData(struct moxa_port *port) ...@@ -2111,101 +2104,84 @@ static int MoxaPortReadData(struct moxa_port *port)
rx_mask = readw(ofsAddr + RX_mask); rx_mask = readw(ofsAddr + RX_mask);
spage = readw(ofsAddr + Page_rxb); spage = readw(ofsAddr + Page_rxb);
epage = readw(ofsAddr + EndPage_rxb); epage = readw(ofsAddr + EndPage_rxb);
count = (tail >= head) ? (tail - head) count = (tail >= head) ? (tail - head) : (tail - head + rx_mask + 1);
: (tail - head + rx_mask + 1);
if (count == 0) if (count == 0)
return 0; return 0;
total = count; total = count;
remain = count - total;
moxaLog.rxcnt[tty->index] += total; moxaLog.rxcnt[tty->index] += total;
count = total;
if (spage == epage) { if (spage == epage) {
bufhead = readw(ofsAddr + Ofs_rxb); bufhead = readw(ofsAddr + Ofs_rxb);
writew(spage, baseAddr + Control_reg); writew(spage, baseAddr + Control_reg);
while (count > 0) { while (count > 0) {
if (tail >= head)
len = tail - head;
else
len = rx_mask + 1 - head;
len = (count > len) ? len : count;
ofs = baseAddr + DynPage_addr + bufhead + head; ofs = baseAddr + DynPage_addr + bufhead + head;
for (i = 0; i < len; i++) len = (tail >= head) ? (tail - head) :
tty_insert_flip_char(tty, readb(ofs + i), TTY_NORMAL); (rx_mask + 1 - head);
len = tty_prepare_flip_string(tty, &dst,
min(len, count));
memcpy_fromio(dst, ofs, len);
head = (head + len) & rx_mask; head = (head + len) & rx_mask;
count -= len; count -= len;
} }
writew(head, ofsAddr + RXrptr);
} else { } else {
len = count;
pageno = spage + (head >> 13); pageno = spage + (head >> 13);
pageofs = head & Page_mask; pageofs = head & Page_mask;
do { while (count > 0) {
cnt = Page_size - pageofs;
if (cnt > count)
cnt = count;
count -= cnt;
writew(pageno, baseAddr + Control_reg); writew(pageno, baseAddr + Control_reg);
ofs = baseAddr + DynPage_addr + pageofs; ofs = baseAddr + DynPage_addr + pageofs;
for (i = 0; i < cnt; i++) len = tty_prepare_flip_string(tty, &dst,
tty_insert_flip_char(tty, readb(ofs + i), TTY_NORMAL); min(Page_size - pageofs, count));
if (count == 0) { memcpy_fromio(dst, ofs, len);
writew((head + len) & rx_mask, ofsAddr + RXrptr);
break; count -= len;
} pageofs = (pageofs + len) & Page_mask;
if (++pageno == epage) if (pageofs == 0 && ++pageno == epage)
pageno = spage; pageno = spage;
pageofs = 0;
} while (1);
} }
if ((readb(ofsAddr + FlagStat) & Xoff_state) && (remain < LowWater)) { head = (head + total) & rx_mask;
}
writew(head, ofsAddr + RXrptr);
if (readb(ofsAddr + FlagStat) & Xoff_state) {
moxaLowWaterChk = 1; moxaLowWaterChk = 1;
port->lowChkFlag = 1; port->lowChkFlag = 1;
} }
return (total); return total;
} }
static int MoxaPortTxQueue(struct moxa_port *port) static int MoxaPortTxQueue(struct moxa_port *port)
{ {
void __iomem *ofsAddr = port->tableAddr; void __iomem *ofsAddr = port->tableAddr;
ushort rptr, wptr, mask; u16 rptr, wptr, mask;
int len;
rptr = readw(ofsAddr + TXrptr); rptr = readw(ofsAddr + TXrptr);
wptr = readw(ofsAddr + TXwptr); wptr = readw(ofsAddr + TXwptr);
mask = readw(ofsAddr + TX_mask); mask = readw(ofsAddr + TX_mask);
len = (wptr - rptr) & mask; return (wptr - rptr) & mask;
return (len);
} }
static int MoxaPortTxFree(struct moxa_port *port) static int MoxaPortTxFree(struct moxa_port *port)
{ {
void __iomem *ofsAddr = port->tableAddr; void __iomem *ofsAddr = port->tableAddr;
ushort rptr, wptr, mask; u16 rptr, wptr, mask;
int len;
rptr = readw(ofsAddr + TXrptr); rptr = readw(ofsAddr + TXrptr);
wptr = readw(ofsAddr + TXwptr); wptr = readw(ofsAddr + TXwptr);
mask = readw(ofsAddr + TX_mask); mask = readw(ofsAddr + TX_mask);
len = mask - ((wptr - rptr) & mask); return mask - ((wptr - rptr) & mask);
return (len);
} }
static int MoxaPortRxQueue(struct moxa_port *port) static int MoxaPortRxQueue(struct moxa_port *port)
{ {
void __iomem *ofsAddr = port->tableAddr; void __iomem *ofsAddr = port->tableAddr;
ushort rptr, wptr, mask; u16 rptr, wptr, mask;
int len;
rptr = readw(ofsAddr + RXrptr); rptr = readw(ofsAddr + RXrptr);
wptr = readw(ofsAddr + RXwptr); wptr = readw(ofsAddr + RXwptr);
mask = readw(ofsAddr + RX_mask); mask = readw(ofsAddr + RX_mask);
len = (wptr - rptr) & mask; return (wptr - rptr) & mask;
return (len);
} }
static void MoxaPortTxDisable(struct moxa_port *port) static void MoxaPortTxDisable(struct moxa_port *port)
{ {
moxafunc(port->tableAddr, FC_SetXoffState, Magic_code); moxafunc(port->tableAddr, FC_SetXoffState, Magic_code);
......
...@@ -217,7 +217,7 @@ ...@@ -217,7 +217,7 @@
#define C320p32rx_mask (C320p32rx_size - 1) #define C320p32rx_mask (C320p32rx_size - 1)
#define C320p32tx_mask (C320p32tx_size - 1) #define C320p32tx_mask (C320p32tx_size - 1)
#define Page_size 0x2000 #define Page_size 0x2000U
#define Page_mask (Page_size - 1) #define Page_mask (Page_size - 1)
#define C218rx_spage 3 #define C218rx_spage 3
#define C218tx_spage 4 #define C218tx_spage 4
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment