Lines Matching +full:port +full:- +full:1
1 // SPDX-License-Identifier: GPL-2.0-only
3 * Hitachi (now Renesas) SCA-II HD64572 driver for Linux
5 * Copyright (C) 1998-2008 Krzysztof Halasa <khc@pm.waw.pl>
7 * Source of information: HD64572 SCA-II User's Manual
11 * Packet buffer descriptor rings - starting from card->rambase:
14 * rx_ring_buffers * sizeof(pkt_desc) = logical channel #1 RX ring (if used)
15 * tx_ring_buffers * sizeof(pkt_desc) = logical channel #1 TX ring (if used)
17 * Packet data buffers - starting from card->rambase + buff_offset:
44 #define get_msci(port) (port->chan ? MSCI1_OFFSET : MSCI0_OFFSET) argument
45 #define get_dmac_rx(port) (port->chan ? DMAC1RX_OFFSET : DMAC0RX_OFFSET) argument
46 #define get_dmac_tx(port) (port->chan ? DMAC1TX_OFFSET : DMAC0TX_OFFSET) argument
48 #define sca_in(reg, card) readb(card->scabase + (reg))
49 #define sca_out(value, reg, card) writeb(value, card->scabase + (reg))
50 #define sca_inw(reg, card) readw(card->scabase + (reg))
51 #define sca_outw(value, reg, card) writew(value, card->scabase + (reg))
52 #define sca_inl(reg, card) readl(card->scabase + (reg))
53 #define sca_outl(value, reg, card) writel(value, card->scabase + (reg))
59 return dev_to_hdlc(dev)->priv; in dev_to_port()
62 static inline void enable_intr(port_t *port) in enable_intr() argument
65 sca_outl(sca_inl(IER0, port->card) | in enable_intr()
66 (port->chan ? 0x08002200 : 0x00080022), IER0, port->card); in enable_intr()
69 static inline void disable_intr(port_t *port) in disable_intr() argument
71 sca_outl(sca_inl(IER0, port->card) & in disable_intr()
72 (port->chan ? 0x00FF00FF : 0xFF00FF00), IER0, port->card); in disable_intr()
75 static inline u16 desc_abs_number(port_t *port, u16 desc, int transmit) in desc_abs_number() argument
77 u16 rx_buffs = port->card->rx_ring_buffers; in desc_abs_number()
78 u16 tx_buffs = port->card->tx_ring_buffers; in desc_abs_number()
80 desc %= (transmit ? tx_buffs : rx_buffs); // called with "X + 1" etc. in desc_abs_number()
81 return port->chan * (rx_buffs + tx_buffs) + transmit * rx_buffs + desc; in desc_abs_number()
85 static inline u16 desc_offset(port_t *port, u16 desc, int transmit) in desc_offset() argument
88 return desc_abs_number(port, desc, transmit) * sizeof(pkt_desc); in desc_offset()
92 static inline pkt_desc __iomem *desc_address(port_t *port, u16 desc, in desc_address() argument
95 return (pkt_desc __iomem *)(port->card->rambase + in desc_address()
96 desc_offset(port, desc, transmit)); in desc_address()
100 static inline u32 buffer_offset(port_t *port, u16 desc, int transmit) in buffer_offset() argument
102 return port->card->buff_offset + in buffer_offset()
103 desc_abs_number(port, desc, transmit) * (u32)HDLC_MAX_MRU; in buffer_offset()
107 static inline void sca_set_carrier(port_t *port) in sca_set_carrier() argument
109 if (!(sca_in(get_msci(port) + ST3, port->card) & ST3_DCD)) { in sca_set_carrier()
112 port->netdev.name); in sca_set_carrier()
114 netif_carrier_on(port->netdev); in sca_set_carrier()
118 port->netdev.name); in sca_set_carrier()
120 netif_carrier_off(port->netdev); in sca_set_carrier()
125 static void sca_init_port(port_t *port) in sca_init_port() argument
127 card_t *card = port->card; in sca_init_port()
128 u16 dmac_rx = get_dmac_rx(port), dmac_tx = get_dmac_tx(port); in sca_init_port()
131 port->rxin = 0; in sca_init_port()
132 port->txin = 0; in sca_init_port()
133 port->txlast = 0; in sca_init_port()
136 u16 buffs = transmit ? card->tx_ring_buffers in sca_init_port()
137 : card->rx_ring_buffers; in sca_init_port()
140 pkt_desc __iomem *desc = desc_address(port, i, transmit); in sca_init_port()
141 u16 chain_off = desc_offset(port, i + 1, transmit); in sca_init_port()
142 u32 buff_off = buffer_offset(port, i, transmit); in sca_init_port()
144 writel(chain_off, &desc->cp); in sca_init_port()
145 writel(buff_off, &desc->bp); in sca_init_port()
146 writew(0, &desc->len); in sca_init_port()
147 writeb(0, &desc->stat); in sca_init_port()
151 /* DMA disable - to halt state */ in sca_init_port()
152 sca_out(0, DSR_RX(port->chan), card); in sca_init_port()
153 sca_out(0, DSR_TX(port->chan), card); in sca_init_port()
155 /* software ABORT - to initial state */ in sca_init_port()
156 sca_out(DCR_ABORT, DCR_RX(port->chan), card); in sca_init_port()
157 sca_out(DCR_ABORT, DCR_TX(port->chan), card); in sca_init_port()
160 sca_outl(desc_offset(port, 0, 0), dmac_rx + CDAL, card); in sca_init_port()
161 sca_outl(desc_offset(port, card->tx_ring_buffers - 1, 0), in sca_init_port()
163 sca_outl(desc_offset(port, 0, 1), dmac_tx + CDAL, card); in sca_init_port()
164 sca_outl(desc_offset(port, 0, 1), dmac_tx + EDAL, card); in sca_init_port()
167 sca_out(DCR_CLEAR_EOF, DCR_RX(port->chan), card); in sca_init_port()
168 sca_out(DCR_CLEAR_EOF, DCR_TX(port->chan), card); in sca_init_port()
172 sca_out(0x14, DMR_RX(port->chan), card); /* Chain mode, Multi-frame */ in sca_init_port()
173 sca_out(DIR_EOME, DIR_RX(port->chan), card); /* enable interrupts */ in sca_init_port()
174 sca_out(DSR_DE, DSR_RX(port->chan), card); /* DMA enable */ in sca_init_port()
177 sca_out(0x14, DMR_TX(port->chan), card); /* Chain mode, Multi-frame */ in sca_init_port()
178 sca_out(DIR_EOME, DIR_TX(port->chan), card); /* enable interrupts */ in sca_init_port()
180 sca_set_carrier(port); in sca_init_port()
181 netif_napi_add(port->netdev, &port->napi, sca_poll, NAPI_WEIGHT); in sca_init_port()
186 static inline void sca_msci_intr(port_t *port) in sca_msci_intr() argument
188 u16 msci = get_msci(port); in sca_msci_intr()
189 card_t* card = port->card; in sca_msci_intr()
194 sca_set_carrier(port); in sca_msci_intr()
199 static inline void sca_rx(card_t *card, port_t *port, pkt_desc __iomem *desc, in sca_rx() argument
202 struct net_device *dev = port->netdev; in sca_rx()
207 len = readw(&desc->len); in sca_rx()
210 dev->stats.rx_dropped++; in sca_rx()
214 buff = buffer_offset(port, rxin, 0); in sca_rx()
215 memcpy_fromio(skb->data, card->rambase + buff, len); in sca_rx()
219 printk(KERN_DEBUG "%s RX(%i):", dev->name, skb->len); in sca_rx()
222 dev->stats.rx_packets++; in sca_rx()
223 dev->stats.rx_bytes += skb->len; in sca_rx()
224 skb->protocol = hdlc_type_trans(skb, dev); in sca_rx()
230 static inline int sca_rx_done(port_t *port, int budget) in sca_rx_done() argument
232 struct net_device *dev = port->netdev; in sca_rx_done()
233 u16 dmac = get_dmac_rx(port); in sca_rx_done()
234 card_t *card = port->card; in sca_rx_done()
235 u8 stat = sca_in(DSR_RX(port->chan), card); /* read DMA Status */ in sca_rx_done()
240 DSR_RX(port->chan), card); in sca_rx_done()
244 dev->stats.rx_over_errors++; in sca_rx_done()
247 u32 desc_off = desc_offset(port, port->rxin, 0); in sca_rx_done()
254 desc = desc_address(port, port->rxin, 0); in sca_rx_done()
255 stat = readb(&desc->stat); in sca_rx_done()
257 port->rxpart = 1; /* partial frame received */ in sca_rx_done()
258 else if ((stat & ST_ERROR_MASK) || port->rxpart) { in sca_rx_done()
259 dev->stats.rx_errors++; in sca_rx_done()
261 dev->stats.rx_fifo_errors++; in sca_rx_done()
263 ST_RX_RESBIT)) || port->rxpart) in sca_rx_done()
264 dev->stats.rx_frame_errors++; in sca_rx_done()
266 dev->stats.rx_crc_errors++; in sca_rx_done()
268 port->rxpart = 0; /* received last fragment */ in sca_rx_done()
270 sca_rx(card, port, desc, port->rxin); in sca_rx_done()
276 port->rxin = (port->rxin + 1) % card->rx_ring_buffers; in sca_rx_done()
280 sca_out(DSR_DE, DSR_RX(port->chan), card); in sca_rx_done()
286 static inline void sca_tx_done(port_t *port) in sca_tx_done() argument
288 struct net_device *dev = port->netdev; in sca_tx_done()
289 card_t* card = port->card; in sca_tx_done()
293 spin_lock(&port->lock); in sca_tx_done()
295 stat = sca_in(DSR_TX(port->chan), card); /* read DMA Status */ in sca_tx_done()
299 DSR_TX(port->chan), card); in sca_tx_done()
301 while (1) { in sca_tx_done()
302 pkt_desc __iomem *desc = desc_address(port, port->txlast, 1); in sca_tx_done()
303 u8 stat = readb(&desc->stat); in sca_tx_done()
308 dev->stats.tx_errors++; in sca_tx_done()
309 dev->stats.tx_fifo_errors++; in sca_tx_done()
311 dev->stats.tx_packets++; in sca_tx_done()
312 dev->stats.tx_bytes += readw(&desc->len); in sca_tx_done()
314 writeb(0, &desc->stat); /* Free descriptor */ in sca_tx_done()
316 port->txlast = (port->txlast + 1) % card->tx_ring_buffers; in sca_tx_done()
321 spin_unlock(&port->lock); in sca_tx_done()
327 port_t *port = container_of(napi, port_t, napi); in sca_poll() local
328 u32 isr0 = sca_inl(ISR0, port->card); in sca_poll()
331 if (isr0 & (port->chan ? 0x08000000 : 0x00080000)) in sca_poll()
332 sca_msci_intr(port); in sca_poll()
334 if (isr0 & (port->chan ? 0x00002000 : 0x00000020)) in sca_poll()
335 sca_tx_done(port); in sca_poll()
337 if (isr0 & (port->chan ? 0x00000200 : 0x00000002)) in sca_poll()
338 received = sca_rx_done(port, budget); in sca_poll()
342 enable_intr(port); in sca_poll()
355 port_t *port = get_port(card, i); in sca_intr() local
356 if (port && (isr0 & (i ? 0x08002200 : 0x00080022))) { in sca_intr()
357 handled = 1; in sca_intr()
358 disable_intr(port); in sca_intr()
359 napi_schedule(&port->napi); in sca_intr()
367 static void sca_set_port(port_t *port) in sca_set_port() argument
369 card_t* card = port->card; in sca_set_port()
370 u16 msci = get_msci(port); in sca_set_port()
375 if (port->settings.clock_rate > 0) { in sca_set_port()
378 br--; in sca_set_port()
379 brv >>= 1; /* brv = 2^9 = 512 max in specs */ in sca_set_port()
382 tmc = CLOCK_BASE / brv / port->settings.clock_rate; in sca_set_port()
383 }while (br > 1 && tmc <= 128); in sca_set_port()
385 if (tmc < 1) { in sca_set_port()
386 tmc = 1; in sca_set_port()
387 br = 0; /* For baud=CLOCK_BASE we use tmc=1 br=0 */ in sca_set_port()
388 brv = 1; in sca_set_port()
390 tmc = 256; /* tmc=0 means 256 - low baud rates */ in sca_set_port()
392 port->settings.clock_rate = CLOCK_BASE / brv / tmc; in sca_set_port()
396 port->settings.clock_rate = CLOCK_BASE / (256 * 512); in sca_set_port()
399 port->rxs = (port->rxs & ~CLK_BRG_MASK) | br; in sca_set_port()
400 port->txs = (port->txs & ~CLK_BRG_MASK) | br; in sca_set_port()
401 port->tmc = tmc; in sca_set_port()
403 /* baud divisor - time constant*/ in sca_set_port()
404 sca_out(port->tmc, msci + TMCR, card); in sca_set_port()
405 sca_out(port->tmc, msci + TMCT, card); in sca_set_port()
408 sca_out(port->rxs, msci + RXS, card); in sca_set_port()
409 sca_out(port->txs, msci + TXS, card); in sca_set_port()
411 if (port->settings.loopback) in sca_set_port()
423 port_t *port = dev_to_port(dev); in sca_open() local
424 card_t* card = port->card; in sca_open()
425 u16 msci = get_msci(port); in sca_open()
428 switch(port->encoding) { in sca_open()
436 if (port->settings.loopback) in sca_open()
439 switch(port->parity) { in sca_open()
454 sca_out(0x0F, msci + RNR, card); /* +1=RX DMA activation condition */ in sca_open()
455 sca_out(0x3C, msci + TFS, card); /* +1 = TX start */ in sca_open()
458 sca_out(0x3F, msci + TNR1, card); /* +1=TX DMA deactivation condition*/ in sca_open()
461 - RXINTA (DCD changes only) in sca_open()
462 - DMIB (EOM - single frame transfer complete) in sca_open()
466 sca_out(port->tmc, msci + TMCR, card); in sca_open()
467 sca_out(port->tmc, msci + TMCT, card); in sca_open()
468 sca_out(port->rxs, msci + RXS, card); in sca_open()
469 sca_out(port->txs, msci + TXS, card); in sca_open()
473 sca_set_carrier(port); in sca_open()
474 enable_intr(port); in sca_open()
475 napi_enable(&port->napi); in sca_open()
482 port_t *port = dev_to_port(dev); in sca_close() local
485 sca_out(CMD_RESET, get_msci(port) + CMD, port->card); in sca_close()
486 disable_intr(port); in sca_close()
487 napi_disable(&port->napi); in sca_close()
500 return -EINVAL; in sca_attach()
507 return -EINVAL; in sca_attach()
509 dev_to_port(dev)->encoding = encoding; in sca_attach()
510 dev_to_port(dev)->parity = parity; in sca_attach()
518 port_t *port = dev_to_port(dev); in sca_dump_rings() local
519 card_t *card = port->card; in sca_dump_rings()
523 sca_inl(get_dmac_rx(port) + CDAL, card), in sca_dump_rings()
524 sca_inl(get_dmac_rx(port) + EDAL, card), in sca_dump_rings()
525 sca_in(DSR_RX(port->chan), card), port->rxin, in sca_dump_rings()
526 sca_in(DSR_RX(port->chan), card) & DSR_DE ? "" : "in"); in sca_dump_rings()
527 for (cnt = 0; cnt < port->card->rx_ring_buffers; cnt++) in sca_dump_rings()
528 pr_cont(" %02X", readb(&(desc_address(port, cnt, 0)->stat))); in sca_dump_rings()
533 sca_inl(get_dmac_tx(port) + CDAL, card), in sca_dump_rings()
534 sca_inl(get_dmac_tx(port) + EDAL, card), in sca_dump_rings()
535 sca_in(DSR_TX(port->chan), card), port->txin, port->txlast, in sca_dump_rings()
536 sca_in(DSR_TX(port->chan), card) & DSR_DE ? "" : "in"); in sca_dump_rings()
538 for (cnt = 0; cnt < port->card->tx_ring_buffers; cnt++) in sca_dump_rings()
539 pr_cont(" %02X", readb(&(desc_address(port, cnt, 1)->stat))); in sca_dump_rings()
544 sca_in(get_msci(port) + MD0, card), in sca_dump_rings()
545 sca_in(get_msci(port) + MD1, card), in sca_dump_rings()
546 sca_in(get_msci(port) + MD2, card), in sca_dump_rings()
547 sca_in(get_msci(port) + ST0, card), in sca_dump_rings()
548 sca_in(get_msci(port) + ST1, card), in sca_dump_rings()
549 sca_in(get_msci(port) + ST2, card), in sca_dump_rings()
550 sca_in(get_msci(port) + ST3, card), in sca_dump_rings()
551 sca_in(get_msci(port) + ST4, card), in sca_dump_rings()
552 sca_in(get_msci(port) + FST, card), in sca_dump_rings()
553 sca_in(get_msci(port) + CST0, card), in sca_dump_rings()
554 sca_in(get_msci(port) + CST1, card)); in sca_dump_rings()
564 port_t *port = dev_to_port(dev); in sca_xmit() local
565 card_t *card = port->card; in sca_xmit()
569 spin_lock_irq(&port->lock); in sca_xmit()
571 desc = desc_address(port, port->txin + 1, 1); in sca_xmit()
572 BUG_ON(readb(&desc->stat)); /* previous xmit should stop queue */ in sca_xmit()
575 printk(KERN_DEBUG "%s TX(%i):", dev->name, skb->len); in sca_xmit()
579 desc = desc_address(port, port->txin, 1); in sca_xmit()
580 buff = buffer_offset(port, port->txin, 1); in sca_xmit()
581 len = skb->len; in sca_xmit()
582 memcpy_toio(card->rambase + buff, skb->data, len); in sca_xmit()
584 writew(len, &desc->len); in sca_xmit()
585 writeb(ST_TX_EOM, &desc->stat); in sca_xmit()
587 port->txin = (port->txin + 1) % card->tx_ring_buffers; in sca_xmit()
588 sca_outl(desc_offset(port, port->txin, 1), in sca_xmit()
589 get_dmac_tx(port) + EDAL, card); in sca_xmit()
591 sca_out(DSR_DE, DSR_TX(port->chan), card); /* Enable TX DMA */ in sca_xmit()
593 desc = desc_address(port, port->txin + 1, 1); in sca_xmit()
594 if (readb(&desc->stat)) /* allow 1 packet gap */ in sca_xmit()
597 spin_unlock_irq(&port->lock); in sca_xmit()
610 i -= 4; in sca_detect_ram()
631 sca_out(0, DSR_RX(0), card); /* DMA disable - to halt state */ in sca_init()
633 sca_out(0, DSR_RX(1), card); in sca_init()
634 sca_out(0, DSR_TX(1), card); in sca_init()