2 * Hitachi SCA HD64570 and HD64572 common driver for Linux
4 * Copyright (C) 1998-2003 Krzysztof Halasa <khc@pm.waw.pl>
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of version 2 of the GNU General Public License
8 * as published by the Free Software Foundation.
10 * Sources of information:
11 * Hitachi HD64570 SCA User's Manual
12 * Hitachi HD64572 SCA-II User's Manual
14 * We use the following SCA memory map:
16 * Packet buffer descriptor rings - starting from winbase or win0base:
17 * rx_ring_buffers * sizeof(pkt_desc) = logical channel #0 RX ring
18 * tx_ring_buffers * sizeof(pkt_desc) = logical channel #0 TX ring
19 * rx_ring_buffers * sizeof(pkt_desc) = logical channel #1 RX ring (if used)
20 * tx_ring_buffers * sizeof(pkt_desc) = logical channel #1 TX ring (if used)
22 * Packet data buffers - starting from winbase + buff_offset:
23 * rx_ring_buffers * HDLC_MAX_MRU = logical channel #0 RX buffers
24 * tx_ring_buffers * HDLC_MAX_MRU = logical channel #0 TX buffers
25 * rx_ring_buffers * HDLC_MAX_MRU = logical channel #0 RX buffers (if used)
26 * tx_ring_buffers * HDLC_MAX_MRU = logical channel #0 TX buffers (if used)
29 #include <linux/module.h>
30 #include <linux/kernel.h>
31 #include <linux/slab.h>
32 #include <linux/jiffies.h>
33 #include <linux/types.h>
34 #include <linux/fcntl.h>
35 #include <linux/interrupt.h>
37 #include <linux/string.h>
38 #include <linux/errno.h>
39 #include <linux/init.h>
40 #include <linux/ioport.h>
41 #include <linux/bitops.h>
43 #include <asm/system.h>
44 #include <asm/uaccess.h>
47 #include <linux/netdevice.h>
48 #include <linux/skbuff.h>
50 #include <linux/hdlc.h>
52 #if (!defined (__HD64570_H) && !defined (__HD64572_H)) || \
53 (defined (__HD64570_H) && defined (__HD64572_H))
54 #error Either hd64570.h or hd64572.h must be included
57 #define get_msci(port) (phy_node(port) ? MSCI1_OFFSET : MSCI0_OFFSET)
58 #define get_dmac_rx(port) (phy_node(port) ? DMAC1RX_OFFSET : DMAC0RX_OFFSET)
59 #define get_dmac_tx(port) (phy_node(port) ? DMAC1TX_OFFSET : DMAC0TX_OFFSET)
61 #define SCA_INTR_MSCI(node) (node ? 0x10 : 0x01)
62 #define SCA_INTR_DMAC_RX(node) (node ? 0x20 : 0x02)
63 #define SCA_INTR_DMAC_TX(node) (node ? 0x40 : 0x04)
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)
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)
76 static inline struct net_device
*port_to_dev(port_t
*port
)
81 static inline int sca_intr_status(card_t
*card
)
85 #ifdef __HD64570_H /* HD64570 */
86 u8 isr0
= sca_in(ISR0
, card
);
87 u8 isr1
= sca_in(ISR1
, card
);
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);
97 u32 isr0
= sca_inl(ISR0
, card
);
99 if (isr0
& 0x0000000F) result
|= SCA_INTR_DMAC_RX(0);
100 if (isr0
& 0x000000F0) result
|= SCA_INTR_DMAC_TX(0);
101 if (isr0
& 0x00000F00) result
|= SCA_INTR_DMAC_RX(1);
102 if (isr0
& 0x0000F000) result
|= SCA_INTR_DMAC_TX(1);
103 if (isr0
& 0x003E0000) result
|= SCA_INTR_MSCI(0);
104 if (isr0
& 0x3E000000) result
|= SCA_INTR_MSCI(1);
106 #endif /* HD64570 vs HD64572 */
108 if (!(result
& SCA_INTR_DMAC_TX(0)))
109 if (sca_in(DSR_TX(0), card
) & DSR_EOM
)
110 result
|= SCA_INTR_DMAC_TX(0);
111 if (!(result
& SCA_INTR_DMAC_TX(1)))
112 if (sca_in(DSR_TX(1), card
) & DSR_EOM
)
113 result
|= SCA_INTR_DMAC_TX(1);
118 static inline port_t
* dev_to_port(struct net_device
*dev
)
120 return dev_to_hdlc(dev
)->priv
;
123 static inline u16
next_desc(port_t
*port
, u16 desc
, int transmit
)
125 return (desc
+ 1) % (transmit
? port_to_card(port
)->tx_ring_buffers
126 : port_to_card(port
)->rx_ring_buffers
);
131 static inline u16
desc_abs_number(port_t
*port
, u16 desc
, int transmit
)
133 u16 rx_buffs
= port_to_card(port
)->rx_ring_buffers
;
134 u16 tx_buffs
= port_to_card(port
)->tx_ring_buffers
;
136 desc
%= (transmit
? tx_buffs
: rx_buffs
); // called with "X + 1" etc.
137 return log_node(port
) * (rx_buffs
+ tx_buffs
) +
138 transmit
* rx_buffs
+ desc
;
143 static inline u16
desc_offset(port_t
*port
, u16 desc
, int transmit
)
145 /* Descriptor offset always fits in 16 bytes */
146 return desc_abs_number(port
, desc
, transmit
) * sizeof(pkt_desc
);
151 static inline pkt_desc __iomem
*desc_address(port_t
*port
, u16 desc
, int transmit
)
153 #ifdef PAGE0_ALWAYS_MAPPED
154 return (pkt_desc __iomem
*)(win0base(port_to_card(port
))
155 + desc_offset(port
, desc
, transmit
));
157 return (pkt_desc __iomem
*)(winbase(port_to_card(port
))
158 + desc_offset(port
, desc
, transmit
));
164 static inline u32
buffer_offset(port_t
*port
, u16 desc
, int transmit
)
166 return port_to_card(port
)->buff_offset
+
167 desc_abs_number(port
, desc
, transmit
) * (u32
)HDLC_MAX_MRU
;
172 static void sca_init_sync_port(port_t
*port
)
174 card_t
*card
= port_to_card(port
);
181 #if !defined(PAGE0_ALWAYS_MAPPED) && !defined(ALL_PAGES_ALWAYS_MAPPED)
185 for (transmit
= 0; transmit
< 2; transmit
++) {
186 u16 dmac
= transmit
? get_dmac_tx(port
) : get_dmac_rx(port
);
187 u16 buffs
= transmit
? card
->tx_ring_buffers
188 : card
->rx_ring_buffers
;
190 for (i
= 0; i
< buffs
; i
++) {
191 pkt_desc __iomem
*desc
= desc_address(port
, i
, transmit
);
192 u16 chain_off
= desc_offset(port
, i
+ 1, transmit
);
193 u32 buff_off
= buffer_offset(port
, i
, transmit
);
195 writea(chain_off
, &desc
->cp
);
196 writel(buff_off
, &desc
->bp
);
197 writew(0, &desc
->len
);
198 writeb(0, &desc
->stat
);
201 /* DMA disable - to halt state */
202 sca_out(0, transmit
? DSR_TX(phy_node(port
)) :
203 DSR_RX(phy_node(port
)), card
);
204 /* software ABORT - to initial state */
205 sca_out(DCR_ABORT
, transmit
? DCR_TX(phy_node(port
)) :
206 DCR_RX(phy_node(port
)), card
);
209 sca_out(0, dmac
+ CPB
, card
); /* pointer base */
211 /* current desc addr */
212 sca_outa(desc_offset(port
, 0, transmit
), dmac
+ CDAL
, card
);
214 sca_outa(desc_offset(port
, buffs
- 1, transmit
),
217 sca_outa(desc_offset(port
, 0, transmit
), dmac
+ EDAL
,
220 /* clear frame end interrupt counter */
221 sca_out(DCR_CLEAR_EOF
, transmit
? DCR_TX(phy_node(port
)) :
222 DCR_RX(phy_node(port
)), card
);
224 if (!transmit
) { /* Receive */
225 /* set buffer length */
226 sca_outw(HDLC_MAX_MRU
, dmac
+ BFLL
, card
);
227 /* Chain mode, Multi-frame */
228 sca_out(0x14, DMR_RX(phy_node(port
)), card
);
229 sca_out(DIR_EOME
| DIR_BOFE
, DIR_RX(phy_node(port
)),
232 sca_out(DSR_DE
, DSR_RX(phy_node(port
)), card
);
233 } else { /* Transmit */
234 /* Chain mode, Multi-frame */
235 sca_out(0x14, DMR_TX(phy_node(port
)), card
);
236 /* enable underflow interrupts */
237 sca_out(DIR_BOFE
, DIR_TX(phy_node(port
)), card
);
241 hdlc_set_carrier(!(sca_in(get_msci(port
) + ST3
, card
) & ST3_DCD
),
247 #ifdef NEED_SCA_MSCI_INTR
248 /* MSCI interrupt service */
249 static inline void sca_msci_intr(port_t
*port
)
251 u16 msci
= get_msci(port
);
252 card_t
* card
= port_to_card(port
);
253 u8 stat
= sca_in(msci
+ ST1
, card
); /* read MSCI ST1 status */
255 /* Reset MSCI TX underrun and CDCD status bit */
256 sca_out(stat
& (ST1_UDRN
| ST1_CDCD
), msci
+ ST1
, card
);
258 if (stat
& ST1_UDRN
) {
259 struct net_device_stats
*stats
= hdlc_stats(port_to_dev(port
));
260 stats
->tx_errors
++; /* TX Underrun error detected */
261 stats
->tx_fifo_errors
++;
265 hdlc_set_carrier(!(sca_in(msci
+ ST3
, card
) & ST3_DCD
),
272 static inline void sca_rx(card_t
*card
, port_t
*port
, pkt_desc __iomem
*desc
, u16 rxin
)
274 struct net_device
*dev
= port_to_dev(port
);
275 struct net_device_stats
*stats
= hdlc_stats(dev
);
279 #ifndef ALL_PAGES_ALWAYS_MAPPED
284 len
= readw(&desc
->len
);
285 skb
= dev_alloc_skb(len
);
291 buff
= buffer_offset(port
, rxin
, 0);
292 #ifndef ALL_PAGES_ALWAYS_MAPPED
293 page
= buff
/ winsize(card
);
294 buff
= buff
% winsize(card
);
295 maxlen
= winsize(card
) - buff
;
300 memcpy_fromio(skb
->data
, winbase(card
) + buff
, maxlen
);
301 openwin(card
, page
+ 1);
302 memcpy_fromio(skb
->data
+ maxlen
, winbase(card
), len
- maxlen
);
305 memcpy_fromio(skb
->data
, winbase(card
) + buff
, len
);
307 #if !defined(PAGE0_ALWAYS_MAPPED) && !defined(ALL_PAGES_ALWAYS_MAPPED)
308 /* select pkt_desc table page back */
313 printk(KERN_DEBUG
"%s RX(%i):", dev
->name
, skb
->len
);
317 stats
->rx_bytes
+= skb
->len
;
318 dev
->last_rx
= jiffies
;
319 skb
->protocol
= hdlc_type_trans(skb
, dev
);
325 /* Receive DMA interrupt service */
326 static inline void sca_rx_intr(port_t
*port
)
328 u16 dmac
= get_dmac_rx(port
);
329 card_t
*card
= port_to_card(port
);
330 u8 stat
= sca_in(DSR_RX(phy_node(port
)), card
); /* read DMA Status */
331 struct net_device_stats
*stats
= hdlc_stats(port_to_dev(port
));
333 /* Reset DSR status bits */
334 sca_out((stat
& (DSR_EOT
| DSR_EOM
| DSR_BOF
| DSR_COF
)) | DSR_DWE
,
335 DSR_RX(phy_node(port
)), card
);
338 stats
->rx_over_errors
++; /* Dropped one or more frames */
341 u32 desc_off
= desc_offset(port
, port
->rxin
, 0);
342 pkt_desc __iomem
*desc
;
343 u32 cda
= sca_ina(dmac
+ CDAL
, card
);
345 if ((cda
>= desc_off
) && (cda
< desc_off
+ sizeof(pkt_desc
)))
346 break; /* No frame received */
348 desc
= desc_address(port
, port
->rxin
, 0);
349 stat
= readb(&desc
->stat
);
350 if (!(stat
& ST_RX_EOM
))
351 port
->rxpart
= 1; /* partial frame received */
352 else if ((stat
& ST_ERROR_MASK
) || port
->rxpart
) {
354 if (stat
& ST_RX_OVERRUN
) stats
->rx_fifo_errors
++;
355 else if ((stat
& (ST_RX_SHORT
| ST_RX_ABORT
|
356 ST_RX_RESBIT
)) || port
->rxpart
)
357 stats
->rx_frame_errors
++;
358 else if (stat
& ST_RX_CRC
) stats
->rx_crc_errors
++;
359 if (stat
& ST_RX_EOM
)
360 port
->rxpart
= 0; /* received last fragment */
362 sca_rx(card
, port
, desc
, port
->rxin
);
364 /* Set new error descriptor address */
365 sca_outa(desc_off
, dmac
+ EDAL
, card
);
366 port
->rxin
= next_desc(port
, port
->rxin
, 0);
369 /* make sure RX DMA is enabled */
370 sca_out(DSR_DE
, DSR_RX(phy_node(port
)), card
);
375 /* Transmit DMA interrupt service */
376 static inline void sca_tx_intr(port_t
*port
)
378 struct net_device
*dev
= port_to_dev(port
);
379 struct net_device_stats
*stats
= hdlc_stats(dev
);
380 u16 dmac
= get_dmac_tx(port
);
381 card_t
* card
= port_to_card(port
);
384 spin_lock(&port
->lock
);
386 stat
= sca_in(DSR_TX(phy_node(port
)), card
); /* read DMA Status */
388 /* Reset DSR status bits */
389 sca_out((stat
& (DSR_EOT
| DSR_EOM
| DSR_BOF
| DSR_COF
)) | DSR_DWE
,
390 DSR_TX(phy_node(port
)), card
);
393 pkt_desc __iomem
*desc
;
395 u32 desc_off
= desc_offset(port
, port
->txlast
, 1);
396 u32 cda
= sca_ina(dmac
+ CDAL
, card
);
397 if ((cda
>= desc_off
) && (cda
< desc_off
+ sizeof(pkt_desc
)))
398 break; /* Transmitter is/will_be sending this frame */
400 desc
= desc_address(port
, port
->txlast
, 1);
402 stats
->tx_bytes
+= readw(&desc
->len
);
403 writeb(0, &desc
->stat
); /* Free descriptor */
404 port
->txlast
= next_desc(port
, port
->txlast
, 1);
407 netif_wake_queue(dev
);
408 spin_unlock(&port
->lock
);
413 static irqreturn_t
sca_intr(int irq
, void* dev_id
, struct pt_regs
*regs
)
415 card_t
*card
= dev_id
;
420 #ifndef ALL_PAGES_ALWAYS_MAPPED
421 u8 page
= sca_get_page(card
);
424 while((stat
= sca_intr_status(card
)) != 0) {
426 for (i
= 0; i
< 2; i
++) {
427 port_t
*port
= get_port(card
, i
);
429 if (stat
& SCA_INTR_MSCI(i
))
432 if (stat
& SCA_INTR_DMAC_RX(i
))
435 if (stat
& SCA_INTR_DMAC_TX(i
))
441 #ifndef ALL_PAGES_ALWAYS_MAPPED
442 openwin(card
, page
); /* Restore original page */
444 return IRQ_RETVAL(handled
);
449 static void sca_set_port(port_t
*port
)
451 card_t
* card
= port_to_card(port
);
452 u16 msci
= get_msci(port
);
453 u8 md2
= sca_in(msci
+ MD2
, card
);
454 unsigned int tmc
, br
= 10, brv
= 1024;
457 if (port
->settings
.clock_rate
> 0) {
458 /* Try lower br for better accuracy*/
461 brv
>>= 1; /* brv = 2^9 = 512 max in specs */
463 /* Baud Rate = CLOCK_BASE / TMC / 2^BR */
464 tmc
= CLOCK_BASE
/ brv
/ port
->settings
.clock_rate
;
465 }while (br
> 1 && tmc
<= 128);
469 br
= 0; /* For baud=CLOCK_BASE we use tmc=1 br=0 */
471 } else if (tmc
> 255)
472 tmc
= 256; /* tmc=0 means 256 - low baud rates */
474 port
->settings
.clock_rate
= CLOCK_BASE
/ brv
/ tmc
;
476 br
= 9; /* Minimum clock rate */
477 tmc
= 256; /* 8bit = 0 */
478 port
->settings
.clock_rate
= CLOCK_BASE
/ (256 * 512);
481 port
->rxs
= (port
->rxs
& ~CLK_BRG_MASK
) | br
;
482 port
->txs
= (port
->txs
& ~CLK_BRG_MASK
) | br
;
485 /* baud divisor - time constant*/
487 sca_out(port
->tmc
, msci
+ TMC
, card
);
489 sca_out(port
->tmc
, msci
+ TMCR
, card
);
490 sca_out(port
->tmc
, msci
+ TMCT
, card
);
494 sca_out(port
->rxs
, msci
+ RXS
, card
);
495 sca_out(port
->txs
, msci
+ TXS
, card
);
497 if (port
->settings
.loopback
)
500 md2
&= ~MD2_LOOPBACK
;
502 sca_out(md2
, msci
+ MD2
, card
);
508 static void sca_open(struct net_device
*dev
)
510 port_t
*port
= dev_to_port(dev
);
511 card_t
* card
= port_to_card(port
);
512 u16 msci
= get_msci(port
);
515 switch(port
->encoding
) {
516 case ENCODING_NRZ
: md2
= MD2_NRZ
; break;
517 case ENCODING_NRZI
: md2
= MD2_NRZI
; break;
518 case ENCODING_FM_MARK
: md2
= MD2_FM_MARK
; break;
519 case ENCODING_FM_SPACE
: md2
= MD2_FM_SPACE
; break;
520 default: md2
= MD2_MANCHESTER
;
523 if (port
->settings
.loopback
)
526 switch(port
->parity
) {
527 case PARITY_CRC16_PR0
: md0
= MD0_HDLC
| MD0_CRC_16_0
; break;
528 case PARITY_CRC16_PR1
: md0
= MD0_HDLC
| MD0_CRC_16
; break;
530 case PARITY_CRC16_PR0_CCITT
: md0
= MD0_HDLC
| MD0_CRC_ITU_0
; break;
532 case PARITY_CRC32_PR1_CCITT
: md0
= MD0_HDLC
| MD0_CRC_ITU32
; break;
534 case PARITY_CRC16_PR1_CCITT
: md0
= MD0_HDLC
| MD0_CRC_ITU
; break;
535 default: md0
= MD0_HDLC
| MD0_CRC_NONE
;
538 sca_out(CMD_RESET
, msci
+ CMD
, card
);
539 sca_out(md0
, msci
+ MD0
, card
);
540 sca_out(0x00, msci
+ MD1
, card
); /* no address field check */
541 sca_out(md2
, msci
+ MD2
, card
);
542 sca_out(0x7E, msci
+ IDL
, card
); /* flag character 0x7E */
544 sca_out(CTL_IDLE
, msci
+ CTL
, card
);
546 /* Skip the rest of underrun frame */
547 sca_out(CTL_IDLE
| CTL_URCT
| CTL_URSKP
, msci
+ CTL
, card
);
551 /* Allow at least 8 bytes before requesting RX DMA operation */
552 /* TX with higher priority and possibly with shorter transfers */
553 sca_out(0x07, msci
+ RRC
, card
); /* +1=RXRDY/DMA activation condition*/
554 sca_out(0x10, msci
+ TRC0
, card
); /* = TXRDY/DMA activation condition*/
555 sca_out(0x14, msci
+ TRC1
, card
); /* +1=TXRDY/DMA deactiv condition */
557 sca_out(0x0F, msci
+ RNR
, card
); /* +1=RX DMA activation condition */
558 sca_out(0x3C, msci
+ TFS
, card
); /* +1 = TX start */
559 sca_out(0x38, msci
+ TCR
, card
); /* =Critical TX DMA activ condition */
560 sca_out(0x38, msci
+ TNR0
, card
); /* =TX DMA activation condition */
561 sca_out(0x3F, msci
+ TNR1
, card
); /* +1=TX DMA deactivation condition*/
564 /* We're using the following interrupts:
565 - TXINT (DMAC completed all transmisions, underrun or DCD change)
569 hdlc_set_carrier(!(sca_in(msci
+ ST3
, card
) & ST3_DCD
), dev
);
572 /* MSCI TX INT and RX INT A IRQ enable */
573 sca_out(IE0_TXINT
| IE0_RXINTA
, msci
+ IE0
, card
);
574 sca_out(IE1_UDRN
| IE1_CDCD
, msci
+ IE1
, card
);
575 sca_out(sca_in(IER0
, card
) | (phy_node(port
) ? 0xC0 : 0x0C),
576 IER0
, card
); /* TXINT and RXINT */
578 sca_out(sca_in(IER1
, card
) | (phy_node(port
) ? 0xF0 : 0x0F),
581 /* MSCI TXINT and RXINTA interrupt enable */
582 sca_outl(IE0_TXINT
| IE0_RXINTA
| IE0_UDRN
| IE0_CDCD
, msci
+ IE0
,
584 /* DMA & MSCI IRQ enable */
585 sca_outl(sca_inl(IER0
, card
) |
586 (phy_node(port
) ? 0x0A006600 : 0x000A0066), IER0
, card
);
590 sca_out(port
->tmc
, msci
+ TMC
, card
); /* Restore registers */
592 sca_out(port
->tmc
, msci
+ TMCR
, card
);
593 sca_out(port
->tmc
, msci
+ TMCT
, card
);
595 sca_out(port
->rxs
, msci
+ RXS
, card
);
596 sca_out(port
->txs
, msci
+ TXS
, card
);
597 sca_out(CMD_TX_ENABLE
, msci
+ CMD
, card
);
598 sca_out(CMD_RX_ENABLE
, msci
+ CMD
, card
);
600 netif_start_queue(dev
);
605 static void sca_close(struct net_device
*dev
)
607 port_t
*port
= dev_to_port(dev
);
608 card_t
* card
= port_to_card(port
);
611 sca_out(CMD_RESET
, get_msci(port
) + CMD
, port_to_card(port
));
613 /* disable MSCI interrupts */
614 sca_out(sca_in(IER0
, card
) & (phy_node(port
) ? 0x0F : 0xF0),
616 /* disable DMA interrupts */
617 sca_out(sca_in(IER1
, card
) & (phy_node(port
) ? 0x0F : 0xF0),
620 /* disable DMA & MSCI IRQ */
621 sca_outl(sca_inl(IER0
, card
) &
622 (phy_node(port
) ? 0x00FF00FF : 0xFF00FF00), IER0
, card
);
624 netif_stop_queue(dev
);
629 static int sca_attach(struct net_device
*dev
, unsigned short encoding
,
630 unsigned short parity
)
632 if (encoding
!= ENCODING_NRZ
&&
633 encoding
!= ENCODING_NRZI
&&
634 encoding
!= ENCODING_FM_MARK
&&
635 encoding
!= ENCODING_FM_SPACE
&&
636 encoding
!= ENCODING_MANCHESTER
)
639 if (parity
!= PARITY_NONE
&&
640 parity
!= PARITY_CRC16_PR0
&&
641 parity
!= PARITY_CRC16_PR1
&&
643 parity
!= PARITY_CRC16_PR0_CCITT
&&
645 parity
!= PARITY_CRC32_PR1_CCITT
&&
647 parity
!= PARITY_CRC16_PR1_CCITT
)
650 dev_to_port(dev
)->encoding
= encoding
;
651 dev_to_port(dev
)->parity
= parity
;
658 static void sca_dump_rings(struct net_device
*dev
)
660 port_t
*port
= dev_to_port(dev
);
661 card_t
*card
= port_to_card(port
);
663 #if !defined(PAGE0_ALWAYS_MAPPED) && !defined(ALL_PAGES_ALWAYS_MAPPED)
667 #if !defined(PAGE0_ALWAYS_MAPPED) && !defined(ALL_PAGES_ALWAYS_MAPPED)
668 page
= sca_get_page(card
);
672 printk(KERN_DEBUG
"RX ring: CDA=%u EDA=%u DSR=%02X in=%u %sactive",
673 sca_ina(get_dmac_rx(port
) + CDAL
, card
),
674 sca_ina(get_dmac_rx(port
) + EDAL
, card
),
675 sca_in(DSR_RX(phy_node(port
)), card
), port
->rxin
,
676 sca_in(DSR_RX(phy_node(port
)), card
) & DSR_DE
?"":"in");
677 for (cnt
= 0; cnt
< port_to_card(port
)->rx_ring_buffers
; cnt
++)
678 printk(" %02X", readb(&(desc_address(port
, cnt
, 0)->stat
)));
680 printk("\n" KERN_DEBUG
"TX ring: CDA=%u EDA=%u DSR=%02X in=%u "
682 sca_ina(get_dmac_tx(port
) + CDAL
, card
),
683 sca_ina(get_dmac_tx(port
) + EDAL
, card
),
684 sca_in(DSR_TX(phy_node(port
)), card
), port
->txin
, port
->txlast
,
685 sca_in(DSR_TX(phy_node(port
)), card
) & DSR_DE
? "" : "in");
687 for (cnt
= 0; cnt
< port_to_card(port
)->tx_ring_buffers
; cnt
++)
688 printk(" %02X", readb(&(desc_address(port
, cnt
, 1)->stat
)));
691 printk(KERN_DEBUG
"MSCI: MD: %02x %02x %02x, "
692 "ST: %02x %02x %02x %02x"
696 ", FST: %02x CST: %02x %02x\n",
697 sca_in(get_msci(port
) + MD0
, card
),
698 sca_in(get_msci(port
) + MD1
, card
),
699 sca_in(get_msci(port
) + MD2
, card
),
700 sca_in(get_msci(port
) + ST0
, card
),
701 sca_in(get_msci(port
) + ST1
, card
),
702 sca_in(get_msci(port
) + ST2
, card
),
703 sca_in(get_msci(port
) + ST3
, card
),
705 sca_in(get_msci(port
) + ST4
, card
),
707 sca_in(get_msci(port
) + FST
, card
),
708 sca_in(get_msci(port
) + CST0
, card
),
709 sca_in(get_msci(port
) + CST1
, card
));
712 printk(KERN_DEBUG
"ILAR: %02x ISR: %08x %08x\n", sca_in(ILAR
, card
),
713 sca_inl(ISR0
, card
), sca_inl(ISR1
, card
));
715 printk(KERN_DEBUG
"ISR: %02x %02x %02x\n", sca_in(ISR0
, card
),
716 sca_in(ISR1
, card
), sca_in(ISR2
, card
));
719 #if !defined(PAGE0_ALWAYS_MAPPED) && !defined(ALL_PAGES_ALWAYS_MAPPED)
720 openwin(card
, page
); /* Restore original page */
723 #endif /* DEBUG_RINGS */
727 static int sca_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
729 port_t
*port
= dev_to_port(dev
);
730 card_t
*card
= port_to_card(port
);
731 pkt_desc __iomem
*desc
;
733 #ifndef ALL_PAGES_ALWAYS_MAPPED
738 spin_lock_irq(&port
->lock
);
740 desc
= desc_address(port
, port
->txin
+ 1, 1);
741 if (readb(&desc
->stat
)) { /* allow 1 packet gap */
742 /* should never happen - previous xmit should stop queue */
744 printk(KERN_DEBUG
"%s: transmitter buffer full\n", dev
->name
);
746 netif_stop_queue(dev
);
747 spin_unlock_irq(&port
->lock
);
748 return 1; /* request packet to be queued */
752 printk(KERN_DEBUG
"%s TX(%i):", dev
->name
, skb
->len
);
756 desc
= desc_address(port
, port
->txin
, 1);
757 buff
= buffer_offset(port
, port
->txin
, 1);
759 #ifndef ALL_PAGES_ALWAYS_MAPPED
760 page
= buff
/ winsize(card
);
761 buff
= buff
% winsize(card
);
762 maxlen
= winsize(card
) - buff
;
766 memcpy_toio(winbase(card
) + buff
, skb
->data
, maxlen
);
767 openwin(card
, page
+ 1);
768 memcpy_toio(winbase(card
), skb
->data
+ maxlen
, len
- maxlen
);
772 memcpy_toio(winbase(card
) + buff
, skb
->data
, len
);
774 #if !defined(PAGE0_ALWAYS_MAPPED) && !defined(ALL_PAGES_ALWAYS_MAPPED)
775 openwin(card
, 0); /* select pkt_desc table page back */
777 writew(len
, &desc
->len
);
778 writeb(ST_TX_EOM
, &desc
->stat
);
779 dev
->trans_start
= jiffies
;
781 port
->txin
= next_desc(port
, port
->txin
, 1);
782 sca_outa(desc_offset(port
, port
->txin
, 1),
783 get_dmac_tx(port
) + EDAL
, card
);
785 sca_out(DSR_DE
, DSR_TX(phy_node(port
)), card
); /* Enable TX DMA */
787 desc
= desc_address(port
, port
->txin
+ 1, 1);
788 if (readb(&desc
->stat
)) /* allow 1 packet gap */
789 netif_stop_queue(dev
);
791 spin_unlock_irq(&port
->lock
);
799 #ifdef NEED_DETECT_RAM
800 static u32 __devinit
sca_detect_ram(card_t
*card
, u8 __iomem
*rambase
, u32 ramsize
)
802 /* Round RAM size to 32 bits, fill from end to start */
803 u32 i
= ramsize
&= ~3;
805 #ifndef ALL_PAGES_ALWAYS_MAPPED
806 u32 size
= winsize(card
);
808 openwin(card
, (i
- 4) / size
); /* select last window */
812 #ifndef ALL_PAGES_ALWAYS_MAPPED
813 if ((i
+ 4) % size
== 0)
814 openwin(card
, i
/ size
);
815 writel(i
^ 0x12345678, rambase
+ i
% size
);
817 writel(i
^ 0x12345678, rambase
+ i
);
821 for (i
= 0; i
< ramsize
; i
+= 4) {
822 #ifndef ALL_PAGES_ALWAYS_MAPPED
824 openwin(card
, i
/ size
);
826 if (readl(rambase
+ i
% size
) != (i
^ 0x12345678))
829 if (readl(rambase
+ i
) != (i
^ 0x12345678))
836 #endif /* NEED_DETECT_RAM */
840 static void __devinit
sca_init(card_t
*card
, int wait_states
)
842 sca_out(wait_states
, WCRL
, card
); /* Wait Control */
843 sca_out(wait_states
, WCRM
, card
);
844 sca_out(wait_states
, WCRH
, card
);
846 sca_out(0, DMER
, card
); /* DMA Master disable */
847 sca_out(0x03, PCR
, card
); /* DMA priority */
848 sca_out(0, DSR_RX(0), card
); /* DMA disable - to halt state */
849 sca_out(0, DSR_TX(0), card
);
850 sca_out(0, DSR_RX(1), card
);
851 sca_out(0, DSR_TX(1), card
);
852 sca_out(DMER_DME
, DMER
, card
); /* DMA Master enable */