27 #include <linux/bitops.h>
28 #include <linux/errno.h>
29 #include <linux/fcntl.h>
30 #include <linux/hdlc.h>
36 #include <linux/kernel.h>
37 #include <linux/module.h>
38 #include <linux/netdevice.h>
40 #include <linux/string.h>
41 #include <linux/types.h>
43 #include <asm/uaccess.h>
46 #define NAPI_WEIGHT 16
48 #define get_msci(port) (port->chan ? MSCI1_OFFSET : MSCI0_OFFSET)
49 #define get_dmac_rx(port) (port->chan ? DMAC1RX_OFFSET : DMAC0RX_OFFSET)
50 #define get_dmac_tx(port) (port->chan ? DMAC1TX_OFFSET : DMAC0TX_OFFSET)
52 #define sca_in(reg, card) readb(card->scabase + (reg))
53 #define sca_out(value, reg, card) writeb(value, card->scabase + (reg))
54 #define sca_inw(reg, card) readw(card->scabase + (reg))
55 #define sca_outw(value, reg, card) writew(value, card->scabase + (reg))
56 #define sca_inl(reg, card) readl(card->scabase + (reg))
57 #define sca_outl(value, reg, card) writel(value, card->scabase + (reg))
63 return dev_to_hdlc(dev)->priv;
70 (port->chan ? 0x08002200 : 0x00080022),
IER0, port->
card);
73 static inline void disable_intr(
port_t *port)
76 (port->chan ? 0x00FF00FF : 0xFF00FF00),
IER0, port->
card);
81 u16 rx_buffs = port->
card->rx_ring_buffers;
82 u16 tx_buffs = port->
card->tx_ring_buffers;
84 desc %= (transmit ? tx_buffs : rx_buffs);
85 return port->chan * (rx_buffs + tx_buffs) + transmit * rx_buffs + desc;
92 return desc_abs_number(port, desc, transmit) *
sizeof(
pkt_desc);
100 desc_offset(port, desc, transmit));
104 static inline u32 buffer_offset(
port_t *port,
u16 desc,
int transmit)
106 return port->
card->buff_offset +
111 static inline void sca_set_carrier(
port_t *port)
129 static void sca_init_port(
port_t *port)
139 for (transmit = 0; transmit < 2; transmit++) {
140 u16 buffs = transmit ? card->tx_ring_buffers
141 : card->rx_ring_buffers;
143 for (i = 0; i < buffs; i++) {
145 u16 chain_off = desc_offset(port, i + 1, transmit);
146 u32 buff_off = buffer_offset(port, i, transmit);
148 writel(chain_off, &desc->cp);
149 writel(buff_off, &desc->bp);
164 sca_outl(desc_offset(port, 0, 0), dmac_rx +
CDAL, card);
165 sca_outl(desc_offset(port, card->tx_ring_buffers - 1, 0),
166 dmac_rx +
EDAL, card);
167 sca_outl(desc_offset(port, 0, 1), dmac_tx +
CDAL, card);
168 sca_outl(desc_offset(port, 0, 1), dmac_tx +
EDAL, card);
184 sca_set_carrier(port);
190 static inline void sca_msci_intr(
port_t *port)
198 sca_set_carrier(port);
211 len =
readw(&desc->len);
212 skb = dev_alloc_skb(len);
214 dev->
stats.rx_dropped++;
218 buff = buffer_offset(port, rxin, 0);
226 dev->
stats.rx_packets++;
228 skb->
protocol = hdlc_type_trans(skb, dev);
244 DSR_RX(port->chan), card);
248 dev->
stats.rx_over_errors++;
250 while (received < budget) {
251 u32 desc_off = desc_offset(port, port->rxin, 0);
255 if ((cda >= desc_off) && (cda < desc_off +
sizeof(
pkt_desc)))
258 desc = desc_address(port, port->rxin, 0);
259 stat =
readb(&desc->stat);
263 dev->
stats.rx_errors++;
265 dev->
stats.rx_fifo_errors++;
268 dev->
stats.rx_frame_errors++;
270 dev->
stats.rx_crc_errors++;
271 if (stat & ST_RX_EOM)
274 sca_rx(card, port, desc, port->rxin);
280 port->rxin = (port->rxin + 1) % card->rx_ring_buffers;
290 static inline void sca_tx_done(
port_t *port)
297 spin_lock(&port->
lock);
303 DSR_TX(port->chan), card);
312 dev->
stats.tx_errors++;
313 dev->
stats.tx_fifo_errors++;
315 dev->
stats.tx_packets++;
320 port->txlast = (port->txlast + 1) % card->tx_ring_buffers;
324 netif_wake_queue(dev);
325 spin_unlock(&port->
lock);
335 if (isr0 & (port->chan ? 0x08000000 : 0x00080000))
338 if (isr0 & (port->chan ? 0x00002000 : 0x00000020))
341 if (isr0 & (port->chan ? 0x00000200 : 0x00000002))
342 received = sca_rx_done(port, budget);
344 if (received < budget) {
358 for (i = 0; i < 2; i++) {
360 if (port && (isr0 & (i ? 0x08002200 : 0x00080022))) {
363 napi_schedule(&port->napi);
371 static void sca_set_port(
port_t *port)
376 unsigned int tmc, br = 10, brv = 1024;
379 if (port->settings.clock_rate > 0) {
386 tmc =
CLOCK_BASE / brv / port->settings.clock_rate;
387 }
while (br > 1 && tmc <= 128);
393 }
else if (tmc > 255)
396 port->settings.clock_rate =
CLOCK_BASE / brv / tmc;
400 port->settings.clock_rate =
CLOCK_BASE / (256 * 512);
415 if (port->settings.loopback)
432 switch(port->encoding) {
440 if (port->settings.loopback)
443 switch(port->parity) {
477 sca_set_carrier(port);
479 napi_enable(&port->napi);
480 netif_start_queue(dev);
491 napi_disable(&port->napi);
492 netif_stop_queue(dev);
496 static int sca_attach(
struct net_device *dev,
unsigned short encoding,
497 unsigned short parity)
520 static void sca_dump_rings(
struct net_device *dev)
531 for (cnt = 0; cnt < port->
card->rx_ring_buffers; cnt++)
532 pr_cont(
" %02X",
readb(&(desc_address(port, cnt, 0)->stat)));
539 sca_in(
DSR_TX(port->chan), card), port->txin, port->txlast,
542 for (cnt = 0; cnt < port->
card->tx_ring_buffers; cnt++)
543 pr_cont(
" %02X",
readb(&(desc_address(port, cnt, 1)->stat)));
547 " ST: %02x %02x %02x %02x %02x, FST: %02x CST: %02x %02x\n",
573 spin_lock_irq(&port->
lock);
575 desc = desc_address(port, port->txin + 1, 1);
583 desc = desc_address(port, port->txin, 1);
584 buff = buffer_offset(port, port->txin, 1);
591 port->txin = (port->txin + 1) % card->tx_ring_buffers;
592 sca_outl(desc_offset(port, port->txin, 1),
597 desc = desc_address(port, port->txin + 1, 1);
598 if (
readb(&desc->stat))
599 netif_stop_queue(dev);
601 spin_unlock_irq(&port->
lock);
612 u32 i = ramsize &= ~3;
616 writel(i ^ 0x12345678, rambase + i);
619 for (i = 0; i < ramsize ; i += 4) {
620 if (
readl(rambase + i) != (i ^ 0x12345678))