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()
84 static inline u16 desc_offset(port_t *port, u16 desc, int transmit) in desc_offset() argument
87 return desc_abs_number(port, desc, transmit) * sizeof(pkt_desc); in desc_offset()
90 static inline pkt_desc __iomem *desc_address(port_t *port, u16 desc, in desc_address() argument
93 return (pkt_desc __iomem *)(port->card->rambase + in desc_address()
94 desc_offset(port, desc, transmit)); in desc_address()
97 static inline u32 buffer_offset(port_t *port, u16 desc, int transmit) in buffer_offset() argument
99 return port->card->buff_offset + in buffer_offset()
100 desc_abs_number(port, desc, transmit) * (u32)HDLC_MAX_MRU; in buffer_offset()
103 static inline void sca_set_carrier(port_t *port) in sca_set_carrier() argument
105 if (!(sca_in(get_msci(port) + ST3, port->card) & ST3_DCD)) { in sca_set_carrier()
108 port->netdev.name); in sca_set_carrier()
110 netif_carrier_on(port->netdev); in sca_set_carrier()
114 port->netdev.name); in sca_set_carrier()
116 netif_carrier_off(port->netdev); in sca_set_carrier()
120 static void sca_init_port(port_t *port) in sca_init_port() argument
122 card_t *card = port->card; in sca_init_port()
123 u16 dmac_rx = get_dmac_rx(port), dmac_tx = get_dmac_tx(port); in sca_init_port()
126 port->rxin = 0; in sca_init_port()
127 port->txin = 0; in sca_init_port()
128 port->txlast = 0; in sca_init_port()
131 u16 buffs = transmit ? card->tx_ring_buffers in sca_init_port()
132 : card->rx_ring_buffers; in sca_init_port()
135 pkt_desc __iomem *desc = desc_address(port, i, transmit); in sca_init_port()
136 u16 chain_off = desc_offset(port, i + 1, transmit); in sca_init_port()
137 u32 buff_off = buffer_offset(port, i, transmit); in sca_init_port()
139 writel(chain_off, &desc->cp); in sca_init_port()
140 writel(buff_off, &desc->bp); in sca_init_port()
141 writew(0, &desc->len); in sca_init_port()
142 writeb(0, &desc->stat); in sca_init_port()
146 /* DMA disable - to halt state */ in sca_init_port()
147 sca_out(0, DSR_RX(port->chan), card); in sca_init_port()
148 sca_out(0, DSR_TX(port->chan), card); in sca_init_port()
150 /* software ABORT - to initial state */ in sca_init_port()
151 sca_out(DCR_ABORT, DCR_RX(port->chan), card); in sca_init_port()
152 sca_out(DCR_ABORT, DCR_TX(port->chan), card); in sca_init_port()
155 sca_outl(desc_offset(port, 0, 0), dmac_rx + CDAL, card); in sca_init_port()
156 sca_outl(desc_offset(port, card->tx_ring_buffers - 1, 0), in sca_init_port()
158 sca_outl(desc_offset(port, 0, 1), dmac_tx + CDAL, card); in sca_init_port()
159 sca_outl(desc_offset(port, 0, 1), dmac_tx + EDAL, card); in sca_init_port()
162 sca_out(DCR_CLEAR_EOF, DCR_RX(port->chan), card); in sca_init_port()
163 sca_out(DCR_CLEAR_EOF, DCR_TX(port->chan), card); in sca_init_port()
167 sca_out(0x14, DMR_RX(port->chan), card); /* Chain mode, Multi-frame */ in sca_init_port()
168 sca_out(DIR_EOME, DIR_RX(port->chan), card); /* enable interrupts */ in sca_init_port()
169 sca_out(DSR_DE, DSR_RX(port->chan), card); /* DMA enable */ in sca_init_port()
172 sca_out(0x14, DMR_TX(port->chan), card); /* Chain mode, Multi-frame */ in sca_init_port()
173 sca_out(DIR_EOME, DIR_TX(port->chan), card); /* enable interrupts */ in sca_init_port()
175 sca_set_carrier(port); in sca_init_port()
176 netif_napi_add_weight(port->netdev, &port->napi, sca_poll, in sca_init_port()
181 static inline void sca_msci_intr(port_t *port) in sca_msci_intr() argument
183 u16 msci = get_msci(port); in sca_msci_intr()
184 card_t *card = port->card; in sca_msci_intr()
189 sca_set_carrier(port); in sca_msci_intr()
193 static inline void sca_rx(card_t *card, port_t *port, pkt_desc __iomem *desc, in sca_rx() argument
196 struct net_device *dev = port->netdev; in sca_rx()
201 len = readw(&desc->len); in sca_rx()
204 dev->stats.rx_dropped++; in sca_rx()
208 buff = buffer_offset(port, rxin, 0); in sca_rx()
209 memcpy_fromio(skb->data, card->rambase + buff, len); in sca_rx()
213 printk(KERN_DEBUG "%s RX(%i):", dev->name, skb->len); in sca_rx()
216 dev->stats.rx_packets++; in sca_rx()
217 dev->stats.rx_bytes += skb->len; in sca_rx()
218 skb->protocol = hdlc_type_trans(skb, dev); in sca_rx()
223 static inline int sca_rx_done(port_t *port, int budget) in sca_rx_done() argument
225 struct net_device *dev = port->netdev; in sca_rx_done()
226 u16 dmac = get_dmac_rx(port); in sca_rx_done()
227 card_t *card = port->card; in sca_rx_done()
228 u8 stat = sca_in(DSR_RX(port->chan), card); /* read DMA Status */ in sca_rx_done()
233 DSR_RX(port->chan), card); in sca_rx_done()
237 dev->stats.rx_over_errors++; in sca_rx_done()
240 u32 desc_off = desc_offset(port, port->rxin, 0); in sca_rx_done()
247 desc = desc_address(port, port->rxin, 0); in sca_rx_done()
248 stat = readb(&desc->stat); in sca_rx_done()
250 port->rxpart = 1; /* partial frame received */ in sca_rx_done()
251 else if ((stat & ST_ERROR_MASK) || port->rxpart) { in sca_rx_done()
252 dev->stats.rx_errors++; in sca_rx_done()
254 dev->stats.rx_fifo_errors++; in sca_rx_done()
256 ST_RX_RESBIT)) || port->rxpart) in sca_rx_done()
257 dev->stats.rx_frame_errors++; in sca_rx_done()
259 dev->stats.rx_crc_errors++; in sca_rx_done()
261 port->rxpart = 0; /* received last fragment */ in sca_rx_done()
263 sca_rx(card, port, desc, port->rxin); in sca_rx_done()
269 port->rxin = (port->rxin + 1) % card->rx_ring_buffers; in sca_rx_done()
273 sca_out(DSR_DE, DSR_RX(port->chan), card); in sca_rx_done()
278 static inline void sca_tx_done(port_t *port) in sca_tx_done() argument
280 struct net_device *dev = port->netdev; in sca_tx_done()
281 card_t *card = port->card; in sca_tx_done()
285 spin_lock(&port->lock); in sca_tx_done()
287 stat = sca_in(DSR_TX(port->chan), card); /* read DMA Status */ in sca_tx_done()
291 DSR_TX(port->chan), card); in sca_tx_done()
293 while (1) { in sca_tx_done()
294 pkt_desc __iomem *desc = desc_address(port, port->txlast, 1); in sca_tx_done()
295 u8 stat = readb(&desc->stat); in sca_tx_done()
300 dev->stats.tx_errors++; in sca_tx_done()
301 dev->stats.tx_fifo_errors++; in sca_tx_done()
303 dev->stats.tx_packets++; in sca_tx_done()
304 dev->stats.tx_bytes += readw(&desc->len); in sca_tx_done()
306 writeb(0, &desc->stat); /* Free descriptor */ in sca_tx_done()
308 port->txlast = (port->txlast + 1) % card->tx_ring_buffers; in sca_tx_done()
313 spin_unlock(&port->lock); in sca_tx_done()
318 port_t *port = container_of(napi, port_t, napi); in sca_poll() local
319 u32 isr0 = sca_inl(ISR0, port->card); in sca_poll()
322 if (isr0 & (port->chan ? 0x08000000 : 0x00080000)) in sca_poll()
323 sca_msci_intr(port); in sca_poll()
325 if (isr0 & (port->chan ? 0x00002000 : 0x00000020)) in sca_poll()
326 sca_tx_done(port); in sca_poll()
328 if (isr0 & (port->chan ? 0x00000200 : 0x00000002)) in sca_poll()
329 received = sca_rx_done(port, budget); in sca_poll()
333 enable_intr(port); in sca_poll()
346 port_t *port = get_port(card, i); in sca_intr() local
347 if (port && (isr0 & (i ? 0x08002200 : 0x00080022))) { in sca_intr()
348 handled = 1; in sca_intr()
349 disable_intr(port); in sca_intr()
350 napi_schedule(&port->napi); in sca_intr()
357 static void sca_set_port(port_t *port) in sca_set_port() argument
359 card_t *card = port->card; in sca_set_port()
360 u16 msci = get_msci(port); in sca_set_port()
364 if (port->settings.clock_rate > 0) { in sca_set_port()
367 br--; in sca_set_port()
368 brv >>= 1; /* brv = 2^9 = 512 max in specs */ in sca_set_port()
371 tmc = CLOCK_BASE / brv / port->settings.clock_rate; in sca_set_port()
372 } while (br > 1 && tmc <= 128); in sca_set_port()
374 if (tmc < 1) { in sca_set_port()
375 tmc = 1; in sca_set_port()
376 br = 0; /* For baud=CLOCK_BASE we use tmc=1 br=0 */ in sca_set_port()
377 brv = 1; in sca_set_port()
379 tmc = 256; /* tmc=0 means 256 - low baud rates */ in sca_set_port()
382 port->settings.clock_rate = CLOCK_BASE / brv / tmc; in sca_set_port()
386 port->settings.clock_rate = CLOCK_BASE / (256 * 512); in sca_set_port()
389 port->rxs = (port->rxs & ~CLK_BRG_MASK) | br; in sca_set_port()
390 port->txs = (port->txs & ~CLK_BRG_MASK) | br; in sca_set_port()
391 port->tmc = tmc; in sca_set_port()
393 /* baud divisor - time constant*/ in sca_set_port()
394 sca_out(port->tmc, msci + TMCR, card); in sca_set_port()
395 sca_out(port->tmc, msci + TMCT, card); in sca_set_port()
398 sca_out(port->rxs, msci + RXS, card); in sca_set_port()
399 sca_out(port->txs, msci + TXS, card); in sca_set_port()
401 if (port->settings.loopback) in sca_set_port()
411 port_t *port = dev_to_port(dev); in sca_open() local
412 card_t *card = port->card; in sca_open()
413 u16 msci = get_msci(port); in sca_open()
416 switch (port->encoding) { in sca_open()
433 if (port->settings.loopback) in sca_open()
436 switch (port->parity) { in sca_open()
460 sca_out(0x0F, msci + RNR, card); /* +1=RX DMA activation condition */ in sca_open()
461 sca_out(0x3C, msci + TFS, card); /* +1 = TX start */ in sca_open()
464 sca_out(0x3F, msci + TNR1, card); /* +1=TX DMA deactivation condition*/ in sca_open()
467 - RXINTA (DCD changes only) in sca_open()
468 - DMIB (EOM - single frame transfer complete) in sca_open()
472 sca_out(port->tmc, msci + TMCR, card); in sca_open()
473 sca_out(port->tmc, msci + TMCT, card); in sca_open()
474 sca_out(port->rxs, msci + RXS, card); in sca_open()
475 sca_out(port->txs, msci + TXS, card); in sca_open()
479 sca_set_carrier(port); in sca_open()
480 enable_intr(port); in sca_open()
481 napi_enable(&port->napi); in sca_open()
487 port_t *port = dev_to_port(dev); in sca_close() local
490 sca_out(CMD_RESET, get_msci(port) + CMD, port->card); in sca_close()
491 disable_intr(port); in sca_close()
492 napi_disable(&port->napi); in sca_close()
504 return -EINVAL; in sca_attach()
511 return -EINVAL; in sca_attach()
513 dev_to_port(dev)->encoding = encoding; in sca_attach()
514 dev_to_port(dev)->parity = parity; in sca_attach()
521 port_t *port = dev_to_port(dev); in sca_dump_rings() local
522 card_t *card = port->card; in sca_dump_rings()
526 sca_inl(get_dmac_rx(port) + CDAL, card), in sca_dump_rings()
527 sca_inl(get_dmac_rx(port) + EDAL, card), in sca_dump_rings()
528 sca_in(DSR_RX(port->chan), card), port->rxin, in sca_dump_rings()
529 sca_in(DSR_RX(port->chan), card) & DSR_DE ? "" : "in"); in sca_dump_rings()
530 for (cnt = 0; cnt < port->card->rx_ring_buffers; cnt++) in sca_dump_rings()
531 pr_cont(" %02X", readb(&(desc_address(port, cnt, 0)->stat))); in sca_dump_rings()
536 sca_inl(get_dmac_tx(port) + CDAL, card), in sca_dump_rings()
537 sca_inl(get_dmac_tx(port) + EDAL, card), in sca_dump_rings()
538 sca_in(DSR_TX(port->chan), card), port->txin, port->txlast, in sca_dump_rings()
539 sca_in(DSR_TX(port->chan), card) & DSR_DE ? "" : "in"); in sca_dump_rings()
541 for (cnt = 0; cnt < port->card->tx_ring_buffers; cnt++) in sca_dump_rings()
542 pr_cont(" %02X", readb(&(desc_address(port, cnt, 1)->stat))); in sca_dump_rings()
547 sca_in(get_msci(port) + MD0, card), in sca_dump_rings()
548 sca_in(get_msci(port) + MD1, card), in sca_dump_rings()
549 sca_in(get_msci(port) + MD2, card), in sca_dump_rings()
550 sca_in(get_msci(port) + ST0, card), in sca_dump_rings()
551 sca_in(get_msci(port) + ST1, card), in sca_dump_rings()
552 sca_in(get_msci(port) + ST2, card), in sca_dump_rings()
553 sca_in(get_msci(port) + ST3, card), in sca_dump_rings()
554 sca_in(get_msci(port) + ST4, card), in sca_dump_rings()
555 sca_in(get_msci(port) + FST, card), in sca_dump_rings()
556 sca_in(get_msci(port) + CST0, card), in sca_dump_rings()
557 sca_in(get_msci(port) + CST1, card)); in sca_dump_rings()
566 port_t *port = dev_to_port(dev); in sca_xmit() local
567 card_t *card = port->card; in sca_xmit()
571 spin_lock_irq(&port->lock); in sca_xmit()
573 desc = desc_address(port, port->txin + 1, 1); in sca_xmit()
574 BUG_ON(readb(&desc->stat)); /* previous xmit should stop queue */ in sca_xmit()
577 printk(KERN_DEBUG "%s TX(%i):", dev->name, skb->len); in sca_xmit()
581 desc = desc_address(port, port->txin, 1); in sca_xmit()
582 buff = buffer_offset(port, port->txin, 1); in sca_xmit()
583 len = skb->len; in sca_xmit()
584 memcpy_toio(card->rambase + buff, skb->data, len); in sca_xmit()
586 writew(len, &desc->len); in sca_xmit()
587 writeb(ST_TX_EOM, &desc->stat); in sca_xmit()
589 port->txin = (port->txin + 1) % card->tx_ring_buffers; in sca_xmit()
590 sca_outl(desc_offset(port, port->txin, 1), in sca_xmit()
591 get_dmac_tx(port) + EDAL, card); in sca_xmit()
593 sca_out(DSR_DE, DSR_TX(port->chan), card); /* Enable TX DMA */ in sca_xmit()
595 desc = desc_address(port, port->txin + 1, 1); in sca_xmit()
596 if (readb(&desc->stat)) /* allow 1 packet gap */ in sca_xmit()
599 spin_unlock_irq(&port->lock); in sca_xmit()
611 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()