net: trans_start cleanups
[deliverable/linux.git] / drivers / net / wan / hd64572.c
CommitLineData
1da177e4 1/*
30224392 2 * Hitachi (now Renesas) SCA-II HD64572 driver for Linux
1da177e4 3 *
abc9d91a 4 * Copyright (C) 1998-2008 Krzysztof Halasa <khc@pm.waw.pl>
1da177e4
LT
5 *
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.
9 *
30224392 10 * Source of information: HD64572 SCA-II User's Manual
1da177e4
LT
11 *
12 * We use the following SCA memory map:
13 *
61e0a6a2 14 * Packet buffer descriptor rings - starting from card->rambase:
1da177e4
LT
15 * rx_ring_buffers * sizeof(pkt_desc) = logical channel #0 RX ring
16 * tx_ring_buffers * sizeof(pkt_desc) = logical channel #0 TX ring
17 * rx_ring_buffers * sizeof(pkt_desc) = logical channel #1 RX ring (if used)
18 * tx_ring_buffers * sizeof(pkt_desc) = logical channel #1 TX ring (if used)
19 *
61e0a6a2 20 * Packet data buffers - starting from card->rambase + buff_offset:
1da177e4
LT
21 * rx_ring_buffers * HDLC_MAX_MRU = logical channel #0 RX buffers
22 * tx_ring_buffers * HDLC_MAX_MRU = logical channel #0 TX buffers
23 * rx_ring_buffers * HDLC_MAX_MRU = logical channel #0 RX buffers (if used)
24 * tx_ring_buffers * HDLC_MAX_MRU = logical channel #0 TX buffers (if used)
25 */
26
30224392
KH
27#include <linux/bitops.h>
28#include <linux/errno.h>
1da177e4 29#include <linux/fcntl.h>
30224392 30#include <linux/hdlc.h>
1da177e4 31#include <linux/in.h>
1da177e4 32#include <linux/init.h>
30224392 33#include <linux/interrupt.h>
1da177e4 34#include <linux/ioport.h>
30224392
KH
35#include <linux/jiffies.h>
36#include <linux/kernel.h>
37#include <linux/module.h>
1da177e4
LT
38#include <linux/netdevice.h>
39#include <linux/skbuff.h>
30224392
KH
40#include <linux/string.h>
41#include <linux/types.h>
42#include <asm/io.h>
43#include <asm/system.h>
44#include <asm/uaccess.h>
45#include "hd64572.h"
1da177e4 46
abc9d91a
KH
47#define NAPI_WEIGHT 16
48
61e0a6a2
KH
49#define get_msci(port) (port->chan ? MSCI1_OFFSET : MSCI0_OFFSET)
50#define get_dmac_rx(port) (port->chan ? DMAC1RX_OFFSET : DMAC0RX_OFFSET)
51#define get_dmac_tx(port) (port->chan ? DMAC1TX_OFFSET : DMAC0TX_OFFSET)
1da177e4 52
61e0a6a2
KH
53#define sca_in(reg, card) readb(card->scabase + (reg))
54#define sca_out(value, reg, card) writeb(value, card->scabase + (reg))
55#define sca_inw(reg, card) readw(card->scabase + (reg))
56#define sca_outw(value, reg, card) writew(value, card->scabase + (reg))
57#define sca_inl(reg, card) readl(card->scabase + (reg))
58#define sca_outl(value, reg, card) writel(value, card->scabase + (reg))
1da177e4 59
61e0a6a2 60static int sca_poll(struct napi_struct *napi, int budget);
1da177e4 61
1da177e4
LT
62static inline port_t* dev_to_port(struct net_device *dev)
63{
64 return dev_to_hdlc(dev)->priv;
65}
66
abc9d91a
KH
67static inline void enable_intr(port_t *port)
68{
0446c3b1 69 /* enable DMIB and MSCI RXINTA interrupts */
abc9d91a 70 sca_outl(sca_inl(IER0, port->card) |
61e0a6a2 71 (port->chan ? 0x08002200 : 0x00080022), IER0, port->card);
abc9d91a
KH
72}
73
74static inline void disable_intr(port_t *port)
75{
76 sca_outl(sca_inl(IER0, port->card) &
61e0a6a2 77 (port->chan ? 0x00FF00FF : 0xFF00FF00), IER0, port->card);
abc9d91a
KH
78}
79
1da177e4
LT
80static inline u16 desc_abs_number(port_t *port, u16 desc, int transmit)
81{
61e0a6a2
KH
82 u16 rx_buffs = port->card->rx_ring_buffers;
83 u16 tx_buffs = port->card->tx_ring_buffers;
1da177e4
LT
84
85 desc %= (transmit ? tx_buffs : rx_buffs); // called with "X + 1" etc.
61e0a6a2 86 return port->chan * (rx_buffs + tx_buffs) + transmit * rx_buffs + desc;
1da177e4
LT
87}
88
89
1da177e4
LT
90static inline u16 desc_offset(port_t *port, u16 desc, int transmit)
91{
fcfe9ff3 92 /* Descriptor offset always fits in 16 bits */
1da177e4
LT
93 return desc_abs_number(port, desc, transmit) * sizeof(pkt_desc);
94}
95
96
30224392
KH
97static inline pkt_desc __iomem *desc_address(port_t *port, u16 desc,
98 int transmit)
1da177e4 99{
61e0a6a2
KH
100 return (pkt_desc __iomem *)(port->card->rambase +
101 desc_offset(port, desc, transmit));
1da177e4
LT
102}
103
104
1da177e4
LT
105static inline u32 buffer_offset(port_t *port, u16 desc, int transmit)
106{
61e0a6a2 107 return port->card->buff_offset +
1da177e4
LT
108 desc_abs_number(port, desc, transmit) * (u32)HDLC_MAX_MRU;
109}
110
111
c2ce9204
KH
112static inline void sca_set_carrier(port_t *port)
113{
61e0a6a2 114 if (!(sca_in(get_msci(port) + ST3, port->card) & ST3_DCD)) {
c2ce9204
KH
115#ifdef DEBUG_LINK
116 printk(KERN_DEBUG "%s: sca_set_carrier on\n",
61e0a6a2 117 port->netdev.name);
c2ce9204 118#endif
61e0a6a2 119 netif_carrier_on(port->netdev);
c2ce9204
KH
120 } else {
121#ifdef DEBUG_LINK
122 printk(KERN_DEBUG "%s: sca_set_carrier off\n",
61e0a6a2 123 port->netdev.name);
c2ce9204 124#endif
61e0a6a2 125 netif_carrier_off(port->netdev);
c2ce9204
KH
126 }
127}
128
1da177e4 129
30224392 130static void sca_init_port(port_t *port)
1da177e4 131{
61e0a6a2 132 card_t *card = port->card;
e1f024eb 133 u16 dmac_rx = get_dmac_rx(port), dmac_tx = get_dmac_tx(port);
1da177e4
LT
134 int transmit, i;
135
136 port->rxin = 0;
137 port->txin = 0;
138 port->txlast = 0;
139
1da177e4 140 for (transmit = 0; transmit < 2; transmit++) {
1da177e4
LT
141 u16 buffs = transmit ? card->tx_ring_buffers
142 : card->rx_ring_buffers;
143
144 for (i = 0; i < buffs; i++) {
145 pkt_desc __iomem *desc = desc_address(port, i, transmit);
146 u16 chain_off = desc_offset(port, i + 1, transmit);
147 u32 buff_off = buffer_offset(port, i, transmit);
148
30224392 149 writel(chain_off, &desc->cp);
1da177e4
LT
150 writel(buff_off, &desc->bp);
151 writew(0, &desc->len);
152 writeb(0, &desc->stat);
153 }
1da177e4 154 }
e1f024eb
KH
155
156 /* DMA disable - to halt state */
157 sca_out(0, DSR_RX(port->chan), card);
158 sca_out(0, DSR_TX(port->chan), card);
159
160 /* software ABORT - to initial state */
161 sca_out(DCR_ABORT, DCR_RX(port->chan), card);
162 sca_out(DCR_ABORT, DCR_TX(port->chan), card);
163
164 /* current desc addr */
165 sca_outl(desc_offset(port, 0, 0), dmac_rx + CDAL, card);
166 sca_outl(desc_offset(port, card->tx_ring_buffers - 1, 0),
167 dmac_rx + EDAL, card);
168 sca_outl(desc_offset(port, 0, 1), dmac_tx + CDAL, card);
169 sca_outl(desc_offset(port, 0, 1), dmac_tx + EDAL, card);
170
171 /* clear frame end interrupt counter */
172 sca_out(DCR_CLEAR_EOF, DCR_RX(port->chan), card);
173 sca_out(DCR_CLEAR_EOF, DCR_TX(port->chan), card);
174
175 /* Receive */
176 sca_outw(HDLC_MAX_MRU, dmac_rx + BFLL, card); /* set buffer length */
177 sca_out(0x14, DMR_RX(port->chan), card); /* Chain mode, Multi-frame */
178 sca_out(DIR_EOME, DIR_RX(port->chan), card); /* enable interrupts */
179 sca_out(DSR_DE, DSR_RX(port->chan), card); /* DMA enable */
180
181 /* Transmit */
182 sca_out(0x14, DMR_TX(port->chan), card); /* Chain mode, Multi-frame */
183 sca_out(DIR_EOME, DIR_TX(port->chan), card); /* enable interrupts */
184
c2ce9204 185 sca_set_carrier(port);
61e0a6a2 186 netif_napi_add(port->netdev, &port->napi, sca_poll, NAPI_WEIGHT);
1da177e4
LT
187}
188
189
1da177e4
LT
190/* MSCI interrupt service */
191static inline void sca_msci_intr(port_t *port)
192{
193 u16 msci = get_msci(port);
61e0a6a2 194 card_t* card = port->card;
1da177e4 195
b0942f78
KH
196 if (sca_in(msci + ST1, card) & ST1_CDCD) {
197 /* Reset MSCI CDCD status bit */
198 sca_out(ST1_CDCD, msci + ST1, card);
c2ce9204 199 sca_set_carrier(port);
b0942f78 200 }
1da177e4 201}
1da177e4
LT
202
203
30224392
KH
204static inline void sca_rx(card_t *card, port_t *port, pkt_desc __iomem *desc,
205 u16 rxin)
1da177e4 206{
61e0a6a2 207 struct net_device *dev = port->netdev;
1da177e4
LT
208 struct sk_buff *skb;
209 u16 len;
210 u32 buff;
1da177e4
LT
211
212 len = readw(&desc->len);
213 skb = dev_alloc_skb(len);
214 if (!skb) {
198191c4 215 dev->stats.rx_dropped++;
1da177e4
LT
216 return;
217 }
218
219 buff = buffer_offset(port, rxin, 0);
61e0a6a2 220 memcpy_fromio(skb->data, card->rambase + buff, len);
1da177e4 221
1da177e4
LT
222 skb_put(skb, len);
223#ifdef DEBUG_PKT
224 printk(KERN_DEBUG "%s RX(%i):", dev->name, skb->len);
225 debug_frame(skb);
226#endif
198191c4
KH
227 dev->stats.rx_packets++;
228 dev->stats.rx_bytes += skb->len;
1da177e4 229 skb->protocol = hdlc_type_trans(skb, dev);
abc9d91a 230 netif_receive_skb(skb);
1da177e4
LT
231}
232
233
abc9d91a
KH
234/* Receive DMA service */
235static inline int sca_rx_done(port_t *port, int budget)
1da177e4 236{
61e0a6a2 237 struct net_device *dev = port->netdev;
1da177e4 238 u16 dmac = get_dmac_rx(port);
61e0a6a2
KH
239 card_t *card = port->card;
240 u8 stat = sca_in(DSR_RX(port->chan), card); /* read DMA Status */
abc9d91a 241 int received = 0;
1da177e4
LT
242
243 /* Reset DSR status bits */
244 sca_out((stat & (DSR_EOT | DSR_EOM | DSR_BOF | DSR_COF)) | DSR_DWE,
61e0a6a2 245 DSR_RX(port->chan), card);
1da177e4
LT
246
247 if (stat & DSR_BOF)
198191c4
KH
248 /* Dropped one or more frames */
249 dev->stats.rx_over_errors++;
1da177e4 250
abc9d91a 251 while (received < budget) {
1da177e4
LT
252 u32 desc_off = desc_offset(port, port->rxin, 0);
253 pkt_desc __iomem *desc;
30224392 254 u32 cda = sca_inl(dmac + CDAL, card);
1da177e4
LT
255
256 if ((cda >= desc_off) && (cda < desc_off + sizeof(pkt_desc)))
257 break; /* No frame received */
258
259 desc = desc_address(port, port->rxin, 0);
260 stat = readb(&desc->stat);
261 if (!(stat & ST_RX_EOM))
262 port->rxpart = 1; /* partial frame received */
263 else if ((stat & ST_ERROR_MASK) || port->rxpart) {
198191c4
KH
264 dev->stats.rx_errors++;
265 if (stat & ST_RX_OVERRUN)
266 dev->stats.rx_fifo_errors++;
1da177e4
LT
267 else if ((stat & (ST_RX_SHORT | ST_RX_ABORT |
268 ST_RX_RESBIT)) || port->rxpart)
198191c4
KH
269 dev->stats.rx_frame_errors++;
270 else if (stat & ST_RX_CRC)
271 dev->stats.rx_crc_errors++;
1da177e4
LT
272 if (stat & ST_RX_EOM)
273 port->rxpart = 0; /* received last fragment */
abc9d91a 274 } else {
1da177e4 275 sca_rx(card, port, desc, port->rxin);
abc9d91a
KH
276 received++;
277 }
1da177e4
LT
278
279 /* Set new error descriptor address */
30224392 280 sca_outl(desc_off, dmac + EDAL, card);
0b59cef8 281 port->rxin = (port->rxin + 1) % card->rx_ring_buffers;
1da177e4
LT
282 }
283
284 /* make sure RX DMA is enabled */
61e0a6a2 285 sca_out(DSR_DE, DSR_RX(port->chan), card);
abc9d91a 286 return received;
1da177e4
LT
287}
288
289
abc9d91a
KH
290/* Transmit DMA service */
291static inline void sca_tx_done(port_t *port)
1da177e4 292{
61e0a6a2
KH
293 struct net_device *dev = port->netdev;
294 card_t* card = port->card;
1da177e4
LT
295 u8 stat;
296
297 spin_lock(&port->lock);
298
61e0a6a2 299 stat = sca_in(DSR_TX(port->chan), card); /* read DMA Status */
1da177e4
LT
300
301 /* Reset DSR status bits */
302 sca_out((stat & (DSR_EOT | DSR_EOM | DSR_BOF | DSR_COF)) | DSR_DWE,
61e0a6a2 303 DSR_TX(port->chan), card);
1da177e4
LT
304
305 while (1) {
09fd65aa 306 pkt_desc __iomem *desc = desc_address(port, port->txlast, 1);
b0942f78 307 u8 stat = readb(&desc->stat);
1da177e4 308
b0942f78 309 if (!(stat & ST_TX_OWNRSHP))
09fd65aa 310 break; /* not yet transmitted */
b0942f78
KH
311 if (stat & ST_TX_UNDRRUN) {
312 dev->stats.tx_errors++;
313 dev->stats.tx_fifo_errors++;
314 } else {
315 dev->stats.tx_packets++;
316 dev->stats.tx_bytes += readw(&desc->len);
317 }
1da177e4 318 writeb(0, &desc->stat); /* Free descriptor */
0b59cef8 319 port->txlast = (port->txlast + 1) % card->tx_ring_buffers;
1da177e4
LT
320 }
321
322 netif_wake_queue(dev);
323 spin_unlock(&port->lock);
324}
325
326
abc9d91a
KH
327static int sca_poll(struct napi_struct *napi, int budget)
328{
329 port_t *port = container_of(napi, port_t, napi);
0954ed82 330 u32 isr0 = sca_inl(ISR0, port->card);
abc9d91a
KH
331 int received = 0;
332
61e0a6a2 333 if (isr0 & (port->chan ? 0x08000000 : 0x00080000))
abc9d91a
KH
334 sca_msci_intr(port);
335
61e0a6a2 336 if (isr0 & (port->chan ? 0x00002000 : 0x00000020))
abc9d91a
KH
337 sca_tx_done(port);
338
61e0a6a2 339 if (isr0 & (port->chan ? 0x00000200 : 0x00000002))
abc9d91a
KH
340 received = sca_rx_done(port, budget);
341
342 if (received < budget) {
288379f0 343 napi_complete(napi);
abc9d91a
KH
344 enable_intr(port);
345 }
346
347 return received;
348}
349
0954ed82 350static irqreturn_t sca_intr(int irq, void *dev_id)
1da177e4
LT
351{
352 card_t *card = dev_id;
0954ed82
KH
353 u32 isr0 = sca_inl(ISR0, card);
354 int i, handled = 0;
1da177e4 355
abc9d91a
KH
356 for (i = 0; i < 2; i++) {
357 port_t *port = get_port(card, i);
0954ed82 358 if (port && (isr0 & (i ? 0x08002200 : 0x00080022))) {
abc9d91a
KH
359 handled = 1;
360 disable_intr(port);
288379f0 361 napi_schedule(&port->napi);
1da177e4
LT
362 }
363 }
364
1da177e4
LT
365 return IRQ_RETVAL(handled);
366}
367
368
1da177e4
LT
369static void sca_set_port(port_t *port)
370{
61e0a6a2 371 card_t* card = port->card;
1da177e4
LT
372 u16 msci = get_msci(port);
373 u8 md2 = sca_in(msci + MD2, card);
374 unsigned int tmc, br = 10, brv = 1024;
375
376
377 if (port->settings.clock_rate > 0) {
378 /* Try lower br for better accuracy*/
379 do {
380 br--;
381 brv >>= 1; /* brv = 2^9 = 512 max in specs */
382
383 /* Baud Rate = CLOCK_BASE / TMC / 2^BR */
384 tmc = CLOCK_BASE / brv / port->settings.clock_rate;
385 }while (br > 1 && tmc <= 128);
386
387 if (tmc < 1) {
388 tmc = 1;
389 br = 0; /* For baud=CLOCK_BASE we use tmc=1 br=0 */
390 brv = 1;
391 } else if (tmc > 255)
392 tmc = 256; /* tmc=0 means 256 - low baud rates */
393
394 port->settings.clock_rate = CLOCK_BASE / brv / tmc;
395 } else {
396 br = 9; /* Minimum clock rate */
397 tmc = 256; /* 8bit = 0 */
398 port->settings.clock_rate = CLOCK_BASE / (256 * 512);
399 }
400
401 port->rxs = (port->rxs & ~CLK_BRG_MASK) | br;
402 port->txs = (port->txs & ~CLK_BRG_MASK) | br;
403 port->tmc = tmc;
404
405 /* baud divisor - time constant*/
1da177e4
LT
406 sca_out(port->tmc, msci + TMCR, card);
407 sca_out(port->tmc, msci + TMCT, card);
1da177e4
LT
408
409 /* Set BRG bits */
410 sca_out(port->rxs, msci + RXS, card);
411 sca_out(port->txs, msci + TXS, card);
412
413 if (port->settings.loopback)
414 md2 |= MD2_LOOPBACK;
415 else
416 md2 &= ~MD2_LOOPBACK;
417
418 sca_out(md2, msci + MD2, card);
419
420}
421
422
1da177e4
LT
423static void sca_open(struct net_device *dev)
424{
425 port_t *port = dev_to_port(dev);
61e0a6a2 426 card_t* card = port->card;
1da177e4
LT
427 u16 msci = get_msci(port);
428 u8 md0, md2;
429
430 switch(port->encoding) {
431 case ENCODING_NRZ: md2 = MD2_NRZ; break;
432 case ENCODING_NRZI: md2 = MD2_NRZI; break;
433 case ENCODING_FM_MARK: md2 = MD2_FM_MARK; break;
434 case ENCODING_FM_SPACE: md2 = MD2_FM_SPACE; break;
435 default: md2 = MD2_MANCHESTER;
436 }
437
438 if (port->settings.loopback)
439 md2 |= MD2_LOOPBACK;
440
441 switch(port->parity) {
442 case PARITY_CRC16_PR0: md0 = MD0_HDLC | MD0_CRC_16_0; break;
443 case PARITY_CRC16_PR1: md0 = MD0_HDLC | MD0_CRC_16; break;
1da177e4 444 case PARITY_CRC32_PR1_CCITT: md0 = MD0_HDLC | MD0_CRC_ITU32; break;
1da177e4
LT
445 case PARITY_CRC16_PR1_CCITT: md0 = MD0_HDLC | MD0_CRC_ITU; break;
446 default: md0 = MD0_HDLC | MD0_CRC_NONE;
447 }
448
449 sca_out(CMD_RESET, msci + CMD, card);
450 sca_out(md0, msci + MD0, card);
451 sca_out(0x00, msci + MD1, card); /* no address field check */
452 sca_out(md2, msci + MD2, card);
453 sca_out(0x7E, msci + IDL, card); /* flag character 0x7E */
1da177e4
LT
454 /* Skip the rest of underrun frame */
455 sca_out(CTL_IDLE | CTL_URCT | CTL_URSKP, msci + CTL, card);
1da177e4
LT
456 sca_out(0x0F, msci + RNR, card); /* +1=RX DMA activation condition */
457 sca_out(0x3C, msci + TFS, card); /* +1 = TX start */
458 sca_out(0x38, msci + TCR, card); /* =Critical TX DMA activ condition */
459 sca_out(0x38, msci + TNR0, card); /* =TX DMA activation condition */
460 sca_out(0x3F, msci + TNR1, card); /* +1=TX DMA deactivation condition*/
1da177e4
LT
461
462/* We're using the following interrupts:
0446c3b1
KH
463 - RXINTA (DCD changes only)
464 - DMIB (EOM - single frame transfer complete)
1da177e4 465*/
0446c3b1 466 sca_outl(IE0_RXINTA | IE0_CDCD, msci + IE0, card);
1da177e4 467
1da177e4
LT
468 sca_out(port->tmc, msci + TMCR, card);
469 sca_out(port->tmc, msci + TMCT, card);
1da177e4
LT
470 sca_out(port->rxs, msci + RXS, card);
471 sca_out(port->txs, msci + TXS, card);
472 sca_out(CMD_TX_ENABLE, msci + CMD, card);
473 sca_out(CMD_RX_ENABLE, msci + CMD, card);
474
abc9d91a
KH
475 sca_set_carrier(port);
476 enable_intr(port);
477 napi_enable(&port->napi);
1da177e4
LT
478 netif_start_queue(dev);
479}
480
481
1da177e4
LT
482static void sca_close(struct net_device *dev)
483{
484 port_t *port = dev_to_port(dev);
1da177e4
LT
485
486 /* reset channel */
61e0a6a2 487 sca_out(CMD_RESET, get_msci(port) + CMD, port->card);
abc9d91a
KH
488 disable_intr(port);
489 napi_disable(&port->napi);
1da177e4
LT
490 netif_stop_queue(dev);
491}
492
493
1da177e4
LT
494static int sca_attach(struct net_device *dev, unsigned short encoding,
495 unsigned short parity)
496{
497 if (encoding != ENCODING_NRZ &&
498 encoding != ENCODING_NRZI &&
499 encoding != ENCODING_FM_MARK &&
500 encoding != ENCODING_FM_SPACE &&
501 encoding != ENCODING_MANCHESTER)
502 return -EINVAL;
503
504 if (parity != PARITY_NONE &&
505 parity != PARITY_CRC16_PR0 &&
506 parity != PARITY_CRC16_PR1 &&
1da177e4 507 parity != PARITY_CRC32_PR1_CCITT &&
1da177e4
LT
508 parity != PARITY_CRC16_PR1_CCITT)
509 return -EINVAL;
510
511 dev_to_port(dev)->encoding = encoding;
512 dev_to_port(dev)->parity = parity;
513 return 0;
514}
515
516
1da177e4
LT
517#ifdef DEBUG_RINGS
518static void sca_dump_rings(struct net_device *dev)
519{
520 port_t *port = dev_to_port(dev);
61e0a6a2 521 card_t *card = port->card;
1da177e4 522 u16 cnt;
1da177e4
LT
523
524 printk(KERN_DEBUG "RX ring: CDA=%u EDA=%u DSR=%02X in=%u %sactive",
30224392
KH
525 sca_inl(get_dmac_rx(port) + CDAL, card),
526 sca_inl(get_dmac_rx(port) + EDAL, card),
61e0a6a2
KH
527 sca_in(DSR_RX(port->chan), card), port->rxin,
528 sca_in(DSR_RX(port->chan), card) & DSR_DE ? "" : "in");
529 for (cnt = 0; cnt < port->card->rx_ring_buffers; cnt++)
1da177e4 530 printk(" %02X", readb(&(desc_address(port, cnt, 0)->stat)));
ad361c98 531 printk(KERN_CONT "\n");
1da177e4 532
ad361c98 533 printk(KERN_DEBUG "TX ring: CDA=%u EDA=%u DSR=%02X in=%u "
1da177e4 534 "last=%u %sactive",
30224392
KH
535 sca_inl(get_dmac_tx(port) + CDAL, card),
536 sca_inl(get_dmac_tx(port) + EDAL, card),
61e0a6a2
KH
537 sca_in(DSR_TX(port->chan), card), port->txin, port->txlast,
538 sca_in(DSR_TX(port->chan), card) & DSR_DE ? "" : "in");
1da177e4 539
61e0a6a2 540 for (cnt = 0; cnt < port->card->tx_ring_buffers; cnt++)
1da177e4
LT
541 printk(" %02X", readb(&(desc_address(port, cnt, 1)->stat)));
542 printk("\n");
543
30224392
KH
544 printk(KERN_DEBUG "MSCI: MD: %02x %02x %02x,"
545 " ST: %02x %02x %02x %02x %02x, FST: %02x CST: %02x %02x\n",
1da177e4
LT
546 sca_in(get_msci(port) + MD0, card),
547 sca_in(get_msci(port) + MD1, card),
548 sca_in(get_msci(port) + MD2, card),
549 sca_in(get_msci(port) + ST0, card),
550 sca_in(get_msci(port) + ST1, card),
551 sca_in(get_msci(port) + ST2, card),
552 sca_in(get_msci(port) + ST3, card),
1da177e4 553 sca_in(get_msci(port) + ST4, card),
1da177e4
LT
554 sca_in(get_msci(port) + FST, card),
555 sca_in(get_msci(port) + CST0, card),
556 sca_in(get_msci(port) + CST1, card));
557
1da177e4
LT
558 printk(KERN_DEBUG "ILAR: %02x ISR: %08x %08x\n", sca_in(ILAR, card),
559 sca_inl(ISR0, card), sca_inl(ISR1, card));
1da177e4
LT
560}
561#endif /* DEBUG_RINGS */
562
563
d71a6749 564static netdev_tx_t sca_xmit(struct sk_buff *skb, struct net_device *dev)
1da177e4
LT
565{
566 port_t *port = dev_to_port(dev);
61e0a6a2 567 card_t *card = port->card;
1da177e4
LT
568 pkt_desc __iomem *desc;
569 u32 buff, len;
1da177e4
LT
570
571 spin_lock_irq(&port->lock);
572
573 desc = desc_address(port, port->txin + 1, 1);
30224392 574 BUG_ON(readb(&desc->stat)); /* previous xmit should stop queue */
1da177e4
LT
575
576#ifdef DEBUG_PKT
577 printk(KERN_DEBUG "%s TX(%i):", dev->name, skb->len);
578 debug_frame(skb);
579#endif
580
581 desc = desc_address(port, port->txin, 1);
582 buff = buffer_offset(port, port->txin, 1);
583 len = skb->len;
61e0a6a2 584 memcpy_toio(card->rambase + buff, skb->data, len);
1da177e4 585
1da177e4
LT
586 writew(len, &desc->len);
587 writeb(ST_TX_EOM, &desc->stat);
1da177e4 588
0b59cef8 589 port->txin = (port->txin + 1) % card->tx_ring_buffers;
30224392 590 sca_outl(desc_offset(port, port->txin, 1),
1da177e4
LT
591 get_dmac_tx(port) + EDAL, card);
592
61e0a6a2 593 sca_out(DSR_DE, DSR_TX(port->chan), card); /* Enable TX DMA */
1da177e4
LT
594
595 desc = desc_address(port, port->txin + 1, 1);
596 if (readb(&desc->stat)) /* allow 1 packet gap */
597 netif_stop_queue(dev);
598
599 spin_unlock_irq(&port->lock);
600
601 dev_kfree_skb(skb);
d71a6749 602 return NETDEV_TX_OK;
1da177e4
LT
603}
604
605
30224392
KH
606static u32 __devinit sca_detect_ram(card_t *card, u8 __iomem *rambase,
607 u32 ramsize)
1da177e4
LT
608{
609 /* Round RAM size to 32 bits, fill from end to start */
610 u32 i = ramsize &= ~3;
611
1da177e4
LT
612 do {
613 i -= 4;
1da177e4 614 writel(i ^ 0x12345678, rambase + i);
30224392 615 } while (i > 0);
1da177e4
LT
616
617 for (i = 0; i < ramsize ; i += 4) {
1da177e4
LT
618 if (readl(rambase + i) != (i ^ 0x12345678))
619 break;
1da177e4
LT
620 }
621
622 return i;
623}
1da177e4
LT
624
625
626static void __devinit sca_init(card_t *card, int wait_states)
627{
628 sca_out(wait_states, WCRL, card); /* Wait Control */
629 sca_out(wait_states, WCRM, card);
630 sca_out(wait_states, WCRH, card);
631
632 sca_out(0, DMER, card); /* DMA Master disable */
633 sca_out(0x03, PCR, card); /* DMA priority */
634 sca_out(0, DSR_RX(0), card); /* DMA disable - to halt state */
635 sca_out(0, DSR_TX(0), card);
636 sca_out(0, DSR_RX(1), card);
637 sca_out(0, DSR_TX(1), card);
638 sca_out(DMER_DME, DMER, card); /* DMA Master enable */
639}
This page took 0.61129 seconds and 5 git commands to generate.