aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wan/hd64572.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/wan/hd64572.c')
-rw-r--r--drivers/net/wan/hd64572.c296
1 files changed, 43 insertions, 253 deletions
diff --git a/drivers/net/wan/hd64572.c b/drivers/net/wan/hd64572.c
index 434583a94b32..aa82e8f9d333 100644
--- a/drivers/net/wan/hd64572.c
+++ b/drivers/net/wan/hd64572.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Hitachi SCA HD64570 and HD64572 common driver for Linux 2 * Hitachi (now Renesas) SCA-II HD64572 driver for Linux
3 * 3 *
4 * Copyright (C) 1998-2003 Krzysztof Halasa <khc@pm.waw.pl> 4 * Copyright (C) 1998-2003 Krzysztof Halasa <khc@pm.waw.pl>
5 * 5 *
@@ -7,9 +7,7 @@
7 * under the terms of version 2 of the GNU General Public License 7 * under the terms of version 2 of the GNU General Public License
8 * as published by the Free Software Foundation. 8 * as published by the Free Software Foundation.
9 * 9 *
10 * Sources of information: 10 * Source of information: HD64572 SCA-II User's Manual
11 * Hitachi HD64570 SCA User's Manual
12 * Hitachi HD64572 SCA-II User's Manual
13 * 11 *
14 * We use the following SCA memory map: 12 * We use the following SCA memory map:
15 * 13 *
@@ -26,33 +24,26 @@
26 * tx_ring_buffers * HDLC_MAX_MRU = logical channel #0 TX buffers (if used) 24 * tx_ring_buffers * HDLC_MAX_MRU = logical channel #0 TX buffers (if used)
27 */ 25 */
28 26
29#include <linux/module.h> 27#include <linux/bitops.h>
30#include <linux/kernel.h> 28#include <linux/errno.h>
31#include <linux/slab.h>
32#include <linux/jiffies.h>
33#include <linux/types.h>
34#include <linux/fcntl.h> 29#include <linux/fcntl.h>
35#include <linux/interrupt.h> 30#include <linux/hdlc.h>
36#include <linux/in.h> 31#include <linux/in.h>
37#include <linux/string.h>
38#include <linux/errno.h>
39#include <linux/init.h> 32#include <linux/init.h>
33#include <linux/interrupt.h>
40#include <linux/ioport.h> 34#include <linux/ioport.h>
41#include <linux/bitops.h> 35#include <linux/jiffies.h>
42 36#include <linux/kernel.h>
43#include <asm/system.h> 37#include <linux/module.h>
44#include <asm/uaccess.h>
45#include <asm/io.h>
46
47#include <linux/netdevice.h> 38#include <linux/netdevice.h>
48#include <linux/skbuff.h> 39#include <linux/skbuff.h>
49 40#include <linux/slab.h>
50#include <linux/hdlc.h> 41#include <linux/string.h>
51 42#include <linux/types.h>
52#if (!defined (__HD64570_H) && !defined (__HD64572_H)) || \ 43#include <asm/io.h>
53 (defined (__HD64570_H) && defined (__HD64572_H)) 44#include <asm/system.h>
54#error Either hd64570.h or hd64572.h must be included 45#include <asm/uaccess.h>
55#endif 46#include "hd64572.h"
56 47
57#define get_msci(port) (phy_node(port) ? MSCI1_OFFSET : MSCI0_OFFSET) 48#define get_msci(port) (phy_node(port) ? MSCI1_OFFSET : MSCI0_OFFSET)
58#define get_dmac_rx(port) (phy_node(port) ? DMAC1RX_OFFSET : DMAC0RX_OFFSET) 49#define get_dmac_rx(port) (phy_node(port) ? DMAC1RX_OFFSET : DMAC0RX_OFFSET)
@@ -62,16 +53,6 @@
62#define SCA_INTR_DMAC_RX(node) (node ? 0x20 : 0x02) 53#define SCA_INTR_DMAC_RX(node) (node ? 0x20 : 0x02)
63#define SCA_INTR_DMAC_TX(node) (node ? 0x40 : 0x04) 54#define SCA_INTR_DMAC_TX(node) (node ? 0x40 : 0x04)
64 55
65#ifdef __HD64570_H /* HD64570 */
66#define sca_outa(value, reg, card) sca_outw(value, reg, card)
67#define sca_ina(reg, card) sca_inw(reg, card)
68#define writea(value, ptr) writew(value, ptr)
69
70#else /* HD64572 */
71#define sca_outa(value, reg, card) sca_outl(value, reg, card)
72#define sca_ina(reg, card) sca_inl(reg, card)
73#define writea(value, ptr) writel(value, ptr)
74#endif
75 56
76static inline struct net_device *port_to_dev(port_t *port) 57static inline struct net_device *port_to_dev(port_t *port)
77{ 58{
@@ -81,19 +62,6 @@ static inline struct net_device *port_to_dev(port_t *port)
81static inline int sca_intr_status(card_t *card) 62static inline int sca_intr_status(card_t *card)
82{ 63{
83 u8 result = 0; 64 u8 result = 0;
84
85#ifdef __HD64570_H /* HD64570 */
86 u8 isr0 = sca_in(ISR0, card);
87 u8 isr1 = sca_in(ISR1, card);
88
89 if (isr1 & 0x03) result |= SCA_INTR_DMAC_RX(0);
90 if (isr1 & 0x0C) result |= SCA_INTR_DMAC_TX(0);
91 if (isr1 & 0x30) result |= SCA_INTR_DMAC_RX(1);
92 if (isr1 & 0xC0) result |= SCA_INTR_DMAC_TX(1);
93 if (isr0 & 0x0F) result |= SCA_INTR_MSCI(0);
94 if (isr0 & 0xF0) result |= SCA_INTR_MSCI(1);
95
96#else /* HD64572 */
97 u32 isr0 = sca_inl(ISR0, card); 65 u32 isr0 = sca_inl(ISR0, card);
98 66
99 if (isr0 & 0x0000000F) result |= SCA_INTR_DMAC_RX(0); 67 if (isr0 & 0x0000000F) result |= SCA_INTR_DMAC_RX(0);
@@ -103,8 +71,6 @@ static inline int sca_intr_status(card_t *card)
103 if (isr0 & 0x003E0000) result |= SCA_INTR_MSCI(0); 71 if (isr0 & 0x003E0000) result |= SCA_INTR_MSCI(0);
104 if (isr0 & 0x3E000000) result |= SCA_INTR_MSCI(1); 72 if (isr0 & 0x3E000000) result |= SCA_INTR_MSCI(1);
105 73
106#endif /* HD64570 vs HD64572 */
107
108 if (!(result & SCA_INTR_DMAC_TX(0))) 74 if (!(result & SCA_INTR_DMAC_TX(0)))
109 if (sca_in(DSR_TX(0), card) & DSR_EOM) 75 if (sca_in(DSR_TX(0), card) & DSR_EOM)
110 result |= SCA_INTR_DMAC_TX(0); 76 result |= SCA_INTR_DMAC_TX(0);
@@ -127,7 +93,6 @@ static inline u16 next_desc(port_t *port, u16 desc, int transmit)
127} 93}
128 94
129 95
130
131static inline u16 desc_abs_number(port_t *port, u16 desc, int transmit) 96static inline u16 desc_abs_number(port_t *port, u16 desc, int transmit)
132{ 97{
133 u16 rx_buffs = port_to_card(port)->rx_ring_buffers; 98 u16 rx_buffs = port_to_card(port)->rx_ring_buffers;
@@ -139,7 +104,6 @@ static inline u16 desc_abs_number(port_t *port, u16 desc, int transmit)
139} 104}
140 105
141 106
142
143static inline u16 desc_offset(port_t *port, u16 desc, int transmit) 107static inline u16 desc_offset(port_t *port, u16 desc, int transmit)
144{ 108{
145 /* Descriptor offset always fits in 16 bytes */ 109 /* Descriptor offset always fits in 16 bytes */
@@ -147,20 +111,14 @@ static inline u16 desc_offset(port_t *port, u16 desc, int transmit)
147} 111}
148 112
149 113
150 114static inline pkt_desc __iomem *desc_address(port_t *port, u16 desc,
151static inline pkt_desc __iomem *desc_address(port_t *port, u16 desc, int transmit) 115 int transmit)
152{ 116{
153#ifdef PAGE0_ALWAYS_MAPPED
154 return (pkt_desc __iomem *)(win0base(port_to_card(port))
155 + desc_offset(port, desc, transmit));
156#else
157 return (pkt_desc __iomem *)(winbase(port_to_card(port)) 117 return (pkt_desc __iomem *)(winbase(port_to_card(port))
158 + desc_offset(port, desc, transmit)); 118 + desc_offset(port, desc, transmit));
159#endif
160} 119}
161 120
162 121
163
164static inline u32 buffer_offset(port_t *port, u16 desc, int transmit) 122static inline u32 buffer_offset(port_t *port, u16 desc, int transmit)
165{ 123{
166 return port_to_card(port)->buff_offset + 124 return port_to_card(port)->buff_offset +
@@ -186,7 +144,7 @@ static inline void sca_set_carrier(port_t *port)
186} 144}
187 145
188 146
189static void sca_init_sync_port(port_t *port) 147static void sca_init_port(port_t *port)
190{ 148{
191 card_t *card = port_to_card(port); 149 card_t *card = port_to_card(port);
192 int transmit, i; 150 int transmit, i;
@@ -195,10 +153,6 @@ static void sca_init_sync_port(port_t *port)
195 port->txin = 0; 153 port->txin = 0;
196 port->txlast = 0; 154 port->txlast = 0;
197 155
198#if !defined(PAGE0_ALWAYS_MAPPED) && !defined(ALL_PAGES_ALWAYS_MAPPED)
199 openwin(card, 0);
200#endif
201
202 for (transmit = 0; transmit < 2; transmit++) { 156 for (transmit = 0; transmit < 2; transmit++) {
203 u16 dmac = transmit ? get_dmac_tx(port) : get_dmac_rx(port); 157 u16 dmac = transmit ? get_dmac_tx(port) : get_dmac_rx(port);
204 u16 buffs = transmit ? card->tx_ring_buffers 158 u16 buffs = transmit ? card->tx_ring_buffers
@@ -209,7 +163,7 @@ static void sca_init_sync_port(port_t *port)
209 u16 chain_off = desc_offset(port, i + 1, transmit); 163 u16 chain_off = desc_offset(port, i + 1, transmit);
210 u32 buff_off = buffer_offset(port, i, transmit); 164 u32 buff_off = buffer_offset(port, i, transmit);
211 165
212 writea(chain_off, &desc->cp); 166 writel(chain_off, &desc->cp);
213 writel(buff_off, &desc->bp); 167 writel(buff_off, &desc->bp);
214 writew(0, &desc->len); 168 writew(0, &desc->len);
215 writeb(0, &desc->stat); 169 writeb(0, &desc->stat);
@@ -222,16 +176,13 @@ static void sca_init_sync_port(port_t *port)
222 sca_out(DCR_ABORT, transmit ? DCR_TX(phy_node(port)) : 176 sca_out(DCR_ABORT, transmit ? DCR_TX(phy_node(port)) :
223 DCR_RX(phy_node(port)), card); 177 DCR_RX(phy_node(port)), card);
224 178
225#ifdef __HD64570_H
226 sca_out(0, dmac + CPB, card); /* pointer base */
227#endif
228 /* current desc addr */ 179 /* current desc addr */
229 sca_outa(desc_offset(port, 0, transmit), dmac + CDAL, card); 180 sca_outl(desc_offset(port, 0, transmit), dmac + CDAL, card);
230 if (!transmit) 181 if (!transmit)
231 sca_outa(desc_offset(port, buffs - 1, transmit), 182 sca_outl(desc_offset(port, buffs - 1, transmit),
232 dmac + EDAL, card); 183 dmac + EDAL, card);
233 else 184 else
234 sca_outa(desc_offset(port, 0, transmit), dmac + EDAL, 185 sca_outl(desc_offset(port, 0, transmit), dmac + EDAL,
235 card); 186 card);
236 187
237 /* clear frame end interrupt counter */ 188 /* clear frame end interrupt counter */
@@ -258,8 +209,6 @@ static void sca_init_sync_port(port_t *port)
258} 209}
259 210
260 211
261
262#ifdef NEED_SCA_MSCI_INTR
263/* MSCI interrupt service */ 212/* MSCI interrupt service */
264static inline void sca_msci_intr(port_t *port) 213static inline void sca_msci_intr(port_t *port)
265{ 214{
@@ -279,20 +228,15 @@ static inline void sca_msci_intr(port_t *port)
279 if (stat & ST1_CDCD) 228 if (stat & ST1_CDCD)
280 sca_set_carrier(port); 229 sca_set_carrier(port);
281} 230}
282#endif
283
284 231
285 232
286static inline void sca_rx(card_t *card, port_t *port, pkt_desc __iomem *desc, u16 rxin) 233static inline void sca_rx(card_t *card, port_t *port, pkt_desc __iomem *desc,
234 u16 rxin)
287{ 235{
288 struct net_device *dev = port_to_dev(port); 236 struct net_device *dev = port_to_dev(port);
289 struct sk_buff *skb; 237 struct sk_buff *skb;
290 u16 len; 238 u16 len;
291 u32 buff; 239 u32 buff;
292#ifndef ALL_PAGES_ALWAYS_MAPPED
293 u32 maxlen;
294 u8 page;
295#endif
296 240
297 len = readw(&desc->len); 241 len = readw(&desc->len);
298 skb = dev_alloc_skb(len); 242 skb = dev_alloc_skb(len);
@@ -302,25 +246,8 @@ static inline void sca_rx(card_t *card, port_t *port, pkt_desc __iomem *desc, u1
302 } 246 }
303 247
304 buff = buffer_offset(port, rxin, 0); 248 buff = buffer_offset(port, rxin, 0);
305#ifndef ALL_PAGES_ALWAYS_MAPPED
306 page = buff / winsize(card);
307 buff = buff % winsize(card);
308 maxlen = winsize(card) - buff;
309
310 openwin(card, page);
311
312 if (len > maxlen) {
313 memcpy_fromio(skb->data, winbase(card) + buff, maxlen);
314 openwin(card, page + 1);
315 memcpy_fromio(skb->data + maxlen, winbase(card), len - maxlen);
316 } else
317#endif
318 memcpy_fromio(skb->data, winbase(card) + buff, len); 249 memcpy_fromio(skb->data, winbase(card) + buff, len);
319 250
320#if !defined(PAGE0_ALWAYS_MAPPED) && !defined(ALL_PAGES_ALWAYS_MAPPED)
321 /* select pkt_desc table page back */
322 openwin(card, 0);
323#endif
324 skb_put(skb, len); 251 skb_put(skb, len);
325#ifdef DEBUG_PKT 252#ifdef DEBUG_PKT
326 printk(KERN_DEBUG "%s RX(%i):", dev->name, skb->len); 253 printk(KERN_DEBUG "%s RX(%i):", dev->name, skb->len);
@@ -333,7 +260,6 @@ static inline void sca_rx(card_t *card, port_t *port, pkt_desc __iomem *desc, u1
333} 260}
334 261
335 262
336
337/* Receive DMA interrupt service */ 263/* Receive DMA interrupt service */
338static inline void sca_rx_intr(port_t *port) 264static inline void sca_rx_intr(port_t *port)
339{ 265{
@@ -353,7 +279,7 @@ static inline void sca_rx_intr(port_t *port)
353 while (1) { 279 while (1) {
354 u32 desc_off = desc_offset(port, port->rxin, 0); 280 u32 desc_off = desc_offset(port, port->rxin, 0);
355 pkt_desc __iomem *desc; 281 pkt_desc __iomem *desc;
356 u32 cda = sca_ina(dmac + CDAL, card); 282 u32 cda = sca_inl(dmac + CDAL, card);
357 283
358 if ((cda >= desc_off) && (cda < desc_off + sizeof(pkt_desc))) 284 if ((cda >= desc_off) && (cda < desc_off + sizeof(pkt_desc)))
359 break; /* No frame received */ 285 break; /* No frame received */
@@ -377,7 +303,7 @@ static inline void sca_rx_intr(port_t *port)
377 sca_rx(card, port, desc, port->rxin); 303 sca_rx(card, port, desc, port->rxin);
378 304
379 /* Set new error descriptor address */ 305 /* Set new error descriptor address */
380 sca_outa(desc_off, dmac + EDAL, card); 306 sca_outl(desc_off, dmac + EDAL, card);
381 port->rxin = next_desc(port, port->rxin, 0); 307 port->rxin = next_desc(port, port->rxin, 0);
382 } 308 }
383 309
@@ -386,7 +312,6 @@ static inline void sca_rx_intr(port_t *port)
386} 312}
387 313
388 314
389
390/* Transmit DMA interrupt service */ 315/* Transmit DMA interrupt service */
391static inline void sca_tx_intr(port_t *port) 316static inline void sca_tx_intr(port_t *port)
392{ 317{
@@ -407,7 +332,7 @@ static inline void sca_tx_intr(port_t *port)
407 pkt_desc __iomem *desc; 332 pkt_desc __iomem *desc;
408 333
409 u32 desc_off = desc_offset(port, port->txlast, 1); 334 u32 desc_off = desc_offset(port, port->txlast, 1);
410 u32 cda = sca_ina(dmac + CDAL, card); 335 u32 cda = sca_inl(dmac + CDAL, card);
411 if ((cda >= desc_off) && (cda < desc_off + sizeof(pkt_desc))) 336 if ((cda >= desc_off) && (cda < desc_off + sizeof(pkt_desc)))
412 break; /* Transmitter is/will_be sending this frame */ 337 break; /* Transmitter is/will_be sending this frame */
413 338
@@ -423,7 +348,6 @@ static inline void sca_tx_intr(port_t *port)
423} 348}
424 349
425 350
426
427static irqreturn_t sca_intr(int irq, void* dev_id) 351static irqreturn_t sca_intr(int irq, void* dev_id)
428{ 352{
429 card_t *card = dev_id; 353 card_t *card = dev_id;
@@ -431,10 +355,6 @@ static irqreturn_t sca_intr(int irq, void* dev_id)
431 u8 stat; 355 u8 stat;
432 int handled = 0; 356 int handled = 0;
433 357
434#ifndef ALL_PAGES_ALWAYS_MAPPED
435 u8 page = sca_get_page(card);
436#endif
437
438 while((stat = sca_intr_status(card)) != 0) { 358 while((stat = sca_intr_status(card)) != 0) {
439 handled = 1; 359 handled = 1;
440 for (i = 0; i < 2; i++) { 360 for (i = 0; i < 2; i++) {
@@ -452,14 +372,10 @@ static irqreturn_t sca_intr(int irq, void* dev_id)
452 } 372 }
453 } 373 }
454 374
455#ifndef ALL_PAGES_ALWAYS_MAPPED
456 openwin(card, page); /* Restore original page */
457#endif
458 return IRQ_RETVAL(handled); 375 return IRQ_RETVAL(handled);
459} 376}
460 377
461 378
462
463static void sca_set_port(port_t *port) 379static void sca_set_port(port_t *port)
464{ 380{
465 card_t* card = port_to_card(port); 381 card_t* card = port_to_card(port);
@@ -497,12 +413,8 @@ static void sca_set_port(port_t *port)
497 port->tmc = tmc; 413 port->tmc = tmc;
498 414
499 /* baud divisor - time constant*/ 415 /* baud divisor - time constant*/
500#ifdef __HD64570_H
501 sca_out(port->tmc, msci + TMC, card);
502#else
503 sca_out(port->tmc, msci + TMCR, card); 416 sca_out(port->tmc, msci + TMCR, card);
504 sca_out(port->tmc, msci + TMCT, card); 417 sca_out(port->tmc, msci + TMCT, card);
505#endif
506 418
507 /* Set BRG bits */ 419 /* Set BRG bits */
508 sca_out(port->rxs, msci + RXS, card); 420 sca_out(port->rxs, msci + RXS, card);
@@ -518,7 +430,6 @@ static void sca_set_port(port_t *port)
518} 430}
519 431
520 432
521
522static void sca_open(struct net_device *dev) 433static void sca_open(struct net_device *dev)
523{ 434{
524 port_t *port = dev_to_port(dev); 435 port_t *port = dev_to_port(dev);
@@ -540,11 +451,7 @@ static void sca_open(struct net_device *dev)
540 switch(port->parity) { 451 switch(port->parity) {
541 case PARITY_CRC16_PR0: md0 = MD0_HDLC | MD0_CRC_16_0; break; 452 case PARITY_CRC16_PR0: md0 = MD0_HDLC | MD0_CRC_16_0; break;
542 case PARITY_CRC16_PR1: md0 = MD0_HDLC | MD0_CRC_16; break; 453 case PARITY_CRC16_PR1: md0 = MD0_HDLC | MD0_CRC_16; break;
543#ifdef __HD64570_H
544 case PARITY_CRC16_PR0_CCITT: md0 = MD0_HDLC | MD0_CRC_ITU_0; break;
545#else
546 case PARITY_CRC32_PR1_CCITT: md0 = MD0_HDLC | MD0_CRC_ITU32; break; 454 case PARITY_CRC32_PR1_CCITT: md0 = MD0_HDLC | MD0_CRC_ITU32; break;
547#endif
548 case PARITY_CRC16_PR1_CCITT: md0 = MD0_HDLC | MD0_CRC_ITU; break; 455 case PARITY_CRC16_PR1_CCITT: md0 = MD0_HDLC | MD0_CRC_ITU; break;
549 default: md0 = MD0_HDLC | MD0_CRC_NONE; 456 default: md0 = MD0_HDLC | MD0_CRC_NONE;
550 } 457 }
@@ -554,26 +461,13 @@ static void sca_open(struct net_device *dev)
554 sca_out(0x00, msci + MD1, card); /* no address field check */ 461 sca_out(0x00, msci + MD1, card); /* no address field check */
555 sca_out(md2, msci + MD2, card); 462 sca_out(md2, msci + MD2, card);
556 sca_out(0x7E, msci + IDL, card); /* flag character 0x7E */ 463 sca_out(0x7E, msci + IDL, card); /* flag character 0x7E */
557#ifdef __HD64570_H
558 sca_out(CTL_IDLE, msci + CTL, card);
559#else
560 /* Skip the rest of underrun frame */ 464 /* Skip the rest of underrun frame */
561 sca_out(CTL_IDLE | CTL_URCT | CTL_URSKP, msci + CTL, card); 465 sca_out(CTL_IDLE | CTL_URCT | CTL_URSKP, msci + CTL, card);
562#endif
563
564#ifdef __HD64570_H
565 /* Allow at least 8 bytes before requesting RX DMA operation */
566 /* TX with higher priority and possibly with shorter transfers */
567 sca_out(0x07, msci + RRC, card); /* +1=RXRDY/DMA activation condition*/
568 sca_out(0x10, msci + TRC0, card); /* = TXRDY/DMA activation condition*/
569 sca_out(0x14, msci + TRC1, card); /* +1=TXRDY/DMA deactiv condition */
570#else
571 sca_out(0x0F, msci + RNR, card); /* +1=RX DMA activation condition */ 466 sca_out(0x0F, msci + RNR, card); /* +1=RX DMA activation condition */
572 sca_out(0x3C, msci + TFS, card); /* +1 = TX start */ 467 sca_out(0x3C, msci + TFS, card); /* +1 = TX start */
573 sca_out(0x38, msci + TCR, card); /* =Critical TX DMA activ condition */ 468 sca_out(0x38, msci + TCR, card); /* =Critical TX DMA activ condition */
574 sca_out(0x38, msci + TNR0, card); /* =TX DMA activation condition */ 469 sca_out(0x38, msci + TNR0, card); /* =TX DMA activation condition */
575 sca_out(0x3F, msci + TNR1, card); /* +1=TX DMA deactivation condition*/ 470 sca_out(0x3F, msci + TNR1, card); /* +1=TX DMA deactivation condition*/
576#endif
577 471
578/* We're using the following interrupts: 472/* We're using the following interrupts:
579 - TXINT (DMAC completed all transmisions, underrun or DCD change) 473 - TXINT (DMAC completed all transmisions, underrun or DCD change)
@@ -582,30 +476,15 @@ static void sca_open(struct net_device *dev)
582 476
583 sca_set_carrier(port); 477 sca_set_carrier(port);
584 478
585#ifdef __HD64570_H
586 /* MSCI TX INT and RX INT A IRQ enable */
587 sca_out(IE0_TXINT | IE0_RXINTA, msci + IE0, card);
588 sca_out(IE1_UDRN | IE1_CDCD, msci + IE1, card);
589 sca_out(sca_in(IER0, card) | (phy_node(port) ? 0xC0 : 0x0C),
590 IER0, card); /* TXINT and RXINT */
591 /* enable DMA IRQ */
592 sca_out(sca_in(IER1, card) | (phy_node(port) ? 0xF0 : 0x0F),
593 IER1, card);
594#else
595 /* MSCI TXINT and RXINTA interrupt enable */ 479 /* MSCI TXINT and RXINTA interrupt enable */
596 sca_outl(IE0_TXINT | IE0_RXINTA | IE0_UDRN | IE0_CDCD, msci + IE0, 480 sca_outl(IE0_TXINT | IE0_RXINTA | IE0_UDRN | IE0_CDCD, msci + IE0,
597 card); 481 card);
598 /* DMA & MSCI IRQ enable */ 482 /* DMA & MSCI IRQ enable */
599 sca_outl(sca_inl(IER0, card) | 483 sca_outl(sca_inl(IER0, card) |
600 (phy_node(port) ? 0x0A006600 : 0x000A0066), IER0, card); 484 (phy_node(port) ? 0x0A006600 : 0x000A0066), IER0, card);
601#endif
602 485
603#ifdef __HD64570_H
604 sca_out(port->tmc, msci + TMC, card); /* Restore registers */
605#else
606 sca_out(port->tmc, msci + TMCR, card); 486 sca_out(port->tmc, msci + TMCR, card);
607 sca_out(port->tmc, msci + TMCT, card); 487 sca_out(port->tmc, msci + TMCT, card);
608#endif
609 sca_out(port->rxs, msci + RXS, card); 488 sca_out(port->rxs, msci + RXS, card);
610 sca_out(port->txs, msci + TXS, card); 489 sca_out(port->txs, msci + TXS, card);
611 sca_out(CMD_TX_ENABLE, msci + CMD, card); 490 sca_out(CMD_TX_ENABLE, msci + CMD, card);
@@ -615,7 +494,6 @@ static void sca_open(struct net_device *dev)
615} 494}
616 495
617 496
618
619static void sca_close(struct net_device *dev) 497static void sca_close(struct net_device *dev)
620{ 498{
621 port_t *port = dev_to_port(dev); 499 port_t *port = dev_to_port(dev);
@@ -623,23 +501,14 @@ static void sca_close(struct net_device *dev)
623 501
624 /* reset channel */ 502 /* reset channel */
625 sca_out(CMD_RESET, get_msci(port) + CMD, port_to_card(port)); 503 sca_out(CMD_RESET, get_msci(port) + CMD, port_to_card(port));
626#ifdef __HD64570_H
627 /* disable MSCI interrupts */
628 sca_out(sca_in(IER0, card) & (phy_node(port) ? 0x0F : 0xF0),
629 IER0, card);
630 /* disable DMA interrupts */
631 sca_out(sca_in(IER1, card) & (phy_node(port) ? 0x0F : 0xF0),
632 IER1, card);
633#else
634 /* disable DMA & MSCI IRQ */ 504 /* disable DMA & MSCI IRQ */
635 sca_outl(sca_inl(IER0, card) & 505 sca_outl(sca_inl(IER0, card) &
636 (phy_node(port) ? 0x00FF00FF : 0xFF00FF00), IER0, card); 506 (phy_node(port) ? 0x00FF00FF : 0xFF00FF00), IER0, card);
637#endif 507
638 netif_stop_queue(dev); 508 netif_stop_queue(dev);
639} 509}
640 510
641 511
642
643static int sca_attach(struct net_device *dev, unsigned short encoding, 512static int sca_attach(struct net_device *dev, unsigned short encoding,
644 unsigned short parity) 513 unsigned short parity)
645{ 514{
@@ -653,11 +522,7 @@ static int sca_attach(struct net_device *dev, unsigned short encoding,
653 if (parity != PARITY_NONE && 522 if (parity != PARITY_NONE &&
654 parity != PARITY_CRC16_PR0 && 523 parity != PARITY_CRC16_PR0 &&
655 parity != PARITY_CRC16_PR1 && 524 parity != PARITY_CRC16_PR1 &&
656#ifdef __HD64570_H
657 parity != PARITY_CRC16_PR0_CCITT &&
658#else
659 parity != PARITY_CRC32_PR1_CCITT && 525 parity != PARITY_CRC32_PR1_CCITT &&
660#endif
661 parity != PARITY_CRC16_PR1_CCITT) 526 parity != PARITY_CRC16_PR1_CCITT)
662 return -EINVAL; 527 return -EINVAL;
663 528
@@ -667,34 +532,25 @@ static int sca_attach(struct net_device *dev, unsigned short encoding,
667} 532}
668 533
669 534
670
671#ifdef DEBUG_RINGS 535#ifdef DEBUG_RINGS
672static void sca_dump_rings(struct net_device *dev) 536static void sca_dump_rings(struct net_device *dev)
673{ 537{
674 port_t *port = dev_to_port(dev); 538 port_t *port = dev_to_port(dev);
675 card_t *card = port_to_card(port); 539 card_t *card = port_to_card(port);
676 u16 cnt; 540 u16 cnt;
677#if !defined(PAGE0_ALWAYS_MAPPED) && !defined(ALL_PAGES_ALWAYS_MAPPED)
678 u8 page;
679#endif
680
681#if !defined(PAGE0_ALWAYS_MAPPED) && !defined(ALL_PAGES_ALWAYS_MAPPED)
682 page = sca_get_page(card);
683 openwin(card, 0);
684#endif
685 541
686 printk(KERN_DEBUG "RX ring: CDA=%u EDA=%u DSR=%02X in=%u %sactive", 542 printk(KERN_DEBUG "RX ring: CDA=%u EDA=%u DSR=%02X in=%u %sactive",
687 sca_ina(get_dmac_rx(port) + CDAL, card), 543 sca_inl(get_dmac_rx(port) + CDAL, card),
688 sca_ina(get_dmac_rx(port) + EDAL, card), 544 sca_inl(get_dmac_rx(port) + EDAL, card),
689 sca_in(DSR_RX(phy_node(port)), card), port->rxin, 545 sca_in(DSR_RX(phy_node(port)), card), port->rxin,
690 sca_in(DSR_RX(phy_node(port)), card) & DSR_DE?"":"in"); 546 sca_in(DSR_RX(phy_node(port)), card) & DSR_DE ? "" : "in");
691 for (cnt = 0; cnt < port_to_card(port)->rx_ring_buffers; cnt++) 547 for (cnt = 0; cnt < port_to_card(port)->rx_ring_buffers; cnt++)
692 printk(" %02X", readb(&(desc_address(port, cnt, 0)->stat))); 548 printk(" %02X", readb(&(desc_address(port, cnt, 0)->stat)));
693 549
694 printk("\n" KERN_DEBUG "TX ring: CDA=%u EDA=%u DSR=%02X in=%u " 550 printk("\n" KERN_DEBUG "TX ring: CDA=%u EDA=%u DSR=%02X in=%u "
695 "last=%u %sactive", 551 "last=%u %sactive",
696 sca_ina(get_dmac_tx(port) + CDAL, card), 552 sca_inl(get_dmac_tx(port) + CDAL, card),
697 sca_ina(get_dmac_tx(port) + EDAL, card), 553 sca_inl(get_dmac_tx(port) + EDAL, card),
698 sca_in(DSR_TX(phy_node(port)), card), port->txin, port->txlast, 554 sca_in(DSR_TX(phy_node(port)), card), port->txin, port->txlast,
699 sca_in(DSR_TX(phy_node(port)), card) & DSR_DE ? "" : "in"); 555 sca_in(DSR_TX(phy_node(port)), card) & DSR_DE ? "" : "in");
700 556
@@ -702,12 +558,8 @@ static void sca_dump_rings(struct net_device *dev)
702 printk(" %02X", readb(&(desc_address(port, cnt, 1)->stat))); 558 printk(" %02X", readb(&(desc_address(port, cnt, 1)->stat)));
703 printk("\n"); 559 printk("\n");
704 560
705 printk(KERN_DEBUG "MSCI: MD: %02x %02x %02x, " 561 printk(KERN_DEBUG "MSCI: MD: %02x %02x %02x,"
706 "ST: %02x %02x %02x %02x" 562 " ST: %02x %02x %02x %02x %02x, FST: %02x CST: %02x %02x\n",
707#ifdef __HD64572_H
708 " %02x"
709#endif
710 ", FST: %02x CST: %02x %02x\n",
711 sca_in(get_msci(port) + MD0, card), 563 sca_in(get_msci(port) + MD0, card),
712 sca_in(get_msci(port) + MD1, card), 564 sca_in(get_msci(port) + MD1, card),
713 sca_in(get_msci(port) + MD2, card), 565 sca_in(get_msci(port) + MD2, card),
@@ -715,52 +567,28 @@ static void sca_dump_rings(struct net_device *dev)
715 sca_in(get_msci(port) + ST1, card), 567 sca_in(get_msci(port) + ST1, card),
716 sca_in(get_msci(port) + ST2, card), 568 sca_in(get_msci(port) + ST2, card),
717 sca_in(get_msci(port) + ST3, card), 569 sca_in(get_msci(port) + ST3, card),
718#ifdef __HD64572_H
719 sca_in(get_msci(port) + ST4, card), 570 sca_in(get_msci(port) + ST4, card),
720#endif
721 sca_in(get_msci(port) + FST, card), 571 sca_in(get_msci(port) + FST, card),
722 sca_in(get_msci(port) + CST0, card), 572 sca_in(get_msci(port) + CST0, card),
723 sca_in(get_msci(port) + CST1, card)); 573 sca_in(get_msci(port) + CST1, card));
724 574
725#ifdef __HD64572_H
726 printk(KERN_DEBUG "ILAR: %02x ISR: %08x %08x\n", sca_in(ILAR, card), 575 printk(KERN_DEBUG "ILAR: %02x ISR: %08x %08x\n", sca_in(ILAR, card),
727 sca_inl(ISR0, card), sca_inl(ISR1, card)); 576 sca_inl(ISR0, card), sca_inl(ISR1, card));
728#else
729 printk(KERN_DEBUG "ISR: %02x %02x %02x\n", sca_in(ISR0, card),
730 sca_in(ISR1, card), sca_in(ISR2, card));
731#endif
732
733#if !defined(PAGE0_ALWAYS_MAPPED) && !defined(ALL_PAGES_ALWAYS_MAPPED)
734 openwin(card, page); /* Restore original page */
735#endif
736} 577}
737#endif /* DEBUG_RINGS */ 578#endif /* DEBUG_RINGS */
738 579
739 580
740
741static int sca_xmit(struct sk_buff *skb, struct net_device *dev) 581static int sca_xmit(struct sk_buff *skb, struct net_device *dev)
742{ 582{
743 port_t *port = dev_to_port(dev); 583 port_t *port = dev_to_port(dev);
744 card_t *card = port_to_card(port); 584 card_t *card = port_to_card(port);
745 pkt_desc __iomem *desc; 585 pkt_desc __iomem *desc;
746 u32 buff, len; 586 u32 buff, len;
747#ifndef ALL_PAGES_ALWAYS_MAPPED
748 u8 page;
749 u32 maxlen;
750#endif
751 587
752 spin_lock_irq(&port->lock); 588 spin_lock_irq(&port->lock);
753 589
754 desc = desc_address(port, port->txin + 1, 1); 590 desc = desc_address(port, port->txin + 1, 1);
755 if (readb(&desc->stat)) { /* allow 1 packet gap */ 591 BUG_ON(readb(&desc->stat)); /* previous xmit should stop queue */
756 /* should never happen - previous xmit should stop queue */
757#ifdef DEBUG_PKT
758 printk(KERN_DEBUG "%s: transmitter buffer full\n", dev->name);
759#endif
760 netif_stop_queue(dev);
761 spin_unlock_irq(&port->lock);
762 return 1; /* request packet to be queued */
763 }
764 592
765#ifdef DEBUG_PKT 593#ifdef DEBUG_PKT
766 printk(KERN_DEBUG "%s TX(%i):", dev->name, skb->len); 594 printk(KERN_DEBUG "%s TX(%i):", dev->name, skb->len);
@@ -770,30 +598,14 @@ static int sca_xmit(struct sk_buff *skb, struct net_device *dev)
770 desc = desc_address(port, port->txin, 1); 598 desc = desc_address(port, port->txin, 1);
771 buff = buffer_offset(port, port->txin, 1); 599 buff = buffer_offset(port, port->txin, 1);
772 len = skb->len; 600 len = skb->len;
773#ifndef ALL_PAGES_ALWAYS_MAPPED 601 memcpy_toio(winbase(card) + buff, skb->data, len);
774 page = buff / winsize(card);
775 buff = buff % winsize(card);
776 maxlen = winsize(card) - buff;
777
778 openwin(card, page);
779 if (len > maxlen) {
780 memcpy_toio(winbase(card) + buff, skb->data, maxlen);
781 openwin(card, page + 1);
782 memcpy_toio(winbase(card), skb->data + maxlen, len - maxlen);
783 }
784 else
785#endif
786 memcpy_toio(winbase(card) + buff, skb->data, len);
787 602
788#if !defined(PAGE0_ALWAYS_MAPPED) && !defined(ALL_PAGES_ALWAYS_MAPPED)
789 openwin(card, 0); /* select pkt_desc table page back */
790#endif
791 writew(len, &desc->len); 603 writew(len, &desc->len);
792 writeb(ST_TX_EOM, &desc->stat); 604 writeb(ST_TX_EOM, &desc->stat);
793 dev->trans_start = jiffies; 605 dev->trans_start = jiffies;
794 606
795 port->txin = next_desc(port, port->txin, 1); 607 port->txin = next_desc(port, port->txin, 1);
796 sca_outa(desc_offset(port, port->txin, 1), 608 sca_outl(desc_offset(port, port->txin, 1),
797 get_dmac_tx(port) + EDAL, card); 609 get_dmac_tx(port) + EDAL, card);
798 610
799 sca_out(DSR_DE, DSR_TX(phy_node(port)), card); /* Enable TX DMA */ 611 sca_out(DSR_DE, DSR_TX(phy_node(port)), card); /* Enable TX DMA */
@@ -809,46 +621,24 @@ static int sca_xmit(struct sk_buff *skb, struct net_device *dev)
809} 621}
810 622
811 623
812 624static u32 __devinit sca_detect_ram(card_t *card, u8 __iomem *rambase,
813#ifdef NEED_DETECT_RAM 625 u32 ramsize)
814static u32 __devinit sca_detect_ram(card_t *card, u8 __iomem *rambase, u32 ramsize)
815{ 626{
816 /* Round RAM size to 32 bits, fill from end to start */ 627 /* Round RAM size to 32 bits, fill from end to start */
817 u32 i = ramsize &= ~3; 628 u32 i = ramsize &= ~3;
818 629
819#ifndef ALL_PAGES_ALWAYS_MAPPED
820 u32 size = winsize(card);
821
822 openwin(card, (i - 4) / size); /* select last window */
823#endif
824 do { 630 do {
825 i -= 4; 631 i -= 4;
826#ifndef ALL_PAGES_ALWAYS_MAPPED
827 if ((i + 4) % size == 0)
828 openwin(card, i / size);
829 writel(i ^ 0x12345678, rambase + i % size);
830#else
831 writel(i ^ 0x12345678, rambase + i); 632 writel(i ^ 0x12345678, rambase + i);
832#endif 633 } while (i > 0);
833 }while (i > 0);
834 634
835 for (i = 0; i < ramsize ; i += 4) { 635 for (i = 0; i < ramsize ; i += 4) {
836#ifndef ALL_PAGES_ALWAYS_MAPPED
837 if (i % size == 0)
838 openwin(card, i / size);
839
840 if (readl(rambase + i % size) != (i ^ 0x12345678))
841 break;
842#else
843 if (readl(rambase + i) != (i ^ 0x12345678)) 636 if (readl(rambase + i) != (i ^ 0x12345678))
844 break; 637 break;
845#endif
846 } 638 }
847 639
848 return i; 640 return i;
849} 641}
850#endif /* NEED_DETECT_RAM */
851
852 642
853 643
854static void __devinit sca_init(card_t *card, int wait_states) 644static void __devinit sca_init(card_t *card, int wait_states)