Lines Matching +full:port +full:- +full:1

1 // SPDX-License-Identifier: GPL-2.0-only
5 * Copyright (C) 1998-2003 Krzysztof Halasa <khc@pm.waw.pl>
11 * Packet buffer descriptor rings - starting from winbase or win0base:
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 winbase + buff_offset:
42 #define get_msci(port) (phy_node(port) ? MSCI1_OFFSET : MSCI0_OFFSET) argument
43 #define get_dmac_rx(port) (phy_node(port) ? DMAC1RX_OFFSET : DMAC0RX_OFFSET) argument
44 #define get_dmac_tx(port) (phy_node(port) ? DMAC1TX_OFFSET : DMAC0TX_OFFSET) argument
50 static inline struct net_device *port_to_dev(port_t *port) in port_to_dev() argument
52 return port->dev; in port_to_dev()
66 result |= SCA_INTR_DMAC_RX(1); in sca_intr_status()
68 result |= SCA_INTR_DMAC_TX(1); in sca_intr_status()
72 result |= SCA_INTR_MSCI(1); in sca_intr_status()
77 if (!(result & SCA_INTR_DMAC_TX(1))) in sca_intr_status()
78 if (sca_in(DSR_TX(1), card) & DSR_EOM) in sca_intr_status()
79 result |= SCA_INTR_DMAC_TX(1); in sca_intr_status()
86 return dev_to_hdlc(dev)->priv; in dev_to_port()
89 static inline u16 next_desc(port_t *port, u16 desc, int transmit) in next_desc() argument
91 return (desc + 1) % (transmit ? port_to_card(port)->tx_ring_buffers in next_desc()
92 : port_to_card(port)->rx_ring_buffers); in next_desc()
95 static inline u16 desc_abs_number(port_t *port, u16 desc, int transmit) in desc_abs_number() argument
97 u16 rx_buffs = port_to_card(port)->rx_ring_buffers; in desc_abs_number()
98 u16 tx_buffs = port_to_card(port)->tx_ring_buffers; in desc_abs_number()
100 desc %= (transmit ? tx_buffs : rx_buffs); // called with "X + 1" etc. in desc_abs_number()
101 return log_node(port) * (rx_buffs + tx_buffs) + in desc_abs_number()
105 static inline u16 desc_offset(port_t *port, u16 desc, int transmit) in desc_offset() argument
108 return desc_abs_number(port, desc, transmit) * sizeof(pkt_desc); in desc_offset()
111 static inline pkt_desc __iomem *desc_address(port_t *port, u16 desc, in desc_address() argument
115 return (pkt_desc __iomem *)(win0base(port_to_card(port)) in desc_address()
116 + desc_offset(port, desc, transmit)); in desc_address()
118 return (pkt_desc __iomem *)(winbase(port_to_card(port)) in desc_address()
119 + desc_offset(port, desc, transmit)); in desc_address()
123 static inline u32 buffer_offset(port_t *port, u16 desc, int transmit) in buffer_offset() argument
125 return port_to_card(port)->buff_offset + in buffer_offset()
126 desc_abs_number(port, desc, transmit) * (u32)HDLC_MAX_MRU; in buffer_offset()
129 static inline void sca_set_carrier(port_t *port) in sca_set_carrier() argument
131 if (!(sca_in(get_msci(port) + ST3, port_to_card(port)) & ST3_DCD)) { in sca_set_carrier()
134 port_to_dev(port)->name); in sca_set_carrier()
136 netif_carrier_on(port_to_dev(port)); in sca_set_carrier()
140 port_to_dev(port)->name); in sca_set_carrier()
142 netif_carrier_off(port_to_dev(port)); in sca_set_carrier()
146 static void sca_init_port(port_t *port) in sca_init_port() argument
148 card_t *card = port_to_card(port); in sca_init_port()
151 port->rxin = 0; in sca_init_port()
152 port->txin = 0; in sca_init_port()
153 port->txlast = 0; in sca_init_port()
160 u16 dmac = transmit ? get_dmac_tx(port) : get_dmac_rx(port); in sca_init_port()
161 u16 buffs = transmit ? card->tx_ring_buffers in sca_init_port()
162 : card->rx_ring_buffers; in sca_init_port()
165 pkt_desc __iomem *desc = desc_address(port, i, transmit); in sca_init_port()
166 u16 chain_off = desc_offset(port, i + 1, transmit); in sca_init_port()
167 u32 buff_off = buffer_offset(port, i, transmit); in sca_init_port()
169 writew(chain_off, &desc->cp); in sca_init_port()
170 writel(buff_off, &desc->bp); in sca_init_port()
171 writew(0, &desc->len); in sca_init_port()
172 writeb(0, &desc->stat); in sca_init_port()
175 /* DMA disable - to halt state */ in sca_init_port()
176 sca_out(0, transmit ? DSR_TX(phy_node(port)) : in sca_init_port()
177 DSR_RX(phy_node(port)), card); in sca_init_port()
178 /* software ABORT - to initial state */ in sca_init_port()
179 sca_out(DCR_ABORT, transmit ? DCR_TX(phy_node(port)) : in sca_init_port()
180 DCR_RX(phy_node(port)), card); in sca_init_port()
184 sca_outw(desc_offset(port, 0, transmit), dmac + CDAL, card); in sca_init_port()
186 sca_outw(desc_offset(port, buffs - 1, transmit), in sca_init_port()
189 sca_outw(desc_offset(port, 0, transmit), dmac + EDAL, in sca_init_port()
193 sca_out(DCR_CLEAR_EOF, transmit ? DCR_TX(phy_node(port)) : in sca_init_port()
194 DCR_RX(phy_node(port)), card); in sca_init_port()
199 /* Chain mode, Multi-frame */ in sca_init_port()
200 sca_out(0x14, DMR_RX(phy_node(port)), card); in sca_init_port()
201 sca_out(DIR_EOME | DIR_BOFE, DIR_RX(phy_node(port)), in sca_init_port()
204 sca_out(DSR_DE, DSR_RX(phy_node(port)), card); in sca_init_port()
206 /* Chain mode, Multi-frame */ in sca_init_port()
207 sca_out(0x14, DMR_TX(phy_node(port)), card); in sca_init_port()
209 sca_out(DIR_BOFE, DIR_TX(phy_node(port)), card); in sca_init_port()
212 sca_set_carrier(port); in sca_init_port()
217 static inline void sca_msci_intr(port_t *port) in sca_msci_intr() argument
219 u16 msci = get_msci(port); in sca_msci_intr()
220 card_t *card = port_to_card(port); in sca_msci_intr()
228 port_to_dev(port)->stats.tx_errors++; in sca_msci_intr()
229 port_to_dev(port)->stats.tx_fifo_errors++; in sca_msci_intr()
233 sca_set_carrier(port); in sca_msci_intr()
237 static inline void sca_rx(card_t *card, port_t *port, pkt_desc __iomem *desc, in sca_rx() argument
240 struct net_device *dev = port_to_dev(port); in sca_rx()
247 len = readw(&desc->len); in sca_rx()
250 dev->stats.rx_dropped++; in sca_rx()
254 buff = buffer_offset(port, rxin, 0); in sca_rx()
257 maxlen = winsize(card) - buff; in sca_rx()
262 memcpy_fromio(skb->data, winbase(card) + buff, maxlen); in sca_rx()
263 openwin(card, page + 1); in sca_rx()
264 memcpy_fromio(skb->data + maxlen, winbase(card), len - maxlen); in sca_rx()
266 memcpy_fromio(skb->data, winbase(card) + buff, len); in sca_rx()
274 printk(KERN_DEBUG "%s RX(%i):", dev->name, skb->len); in sca_rx()
277 dev->stats.rx_packets++; in sca_rx()
278 dev->stats.rx_bytes += skb->len; in sca_rx()
279 skb->protocol = hdlc_type_trans(skb, dev); in sca_rx()
284 static inline void sca_rx_intr(port_t *port) in sca_rx_intr() argument
286 struct net_device *dev = port_to_dev(port); in sca_rx_intr()
287 u16 dmac = get_dmac_rx(port); in sca_rx_intr()
288 card_t *card = port_to_card(port); in sca_rx_intr()
289 u8 stat = sca_in(DSR_RX(phy_node(port)), card); /* read DMA Status */ in sca_rx_intr()
293 DSR_RX(phy_node(port)), card); in sca_rx_intr()
297 dev->stats.rx_over_errors++; in sca_rx_intr()
299 while (1) { in sca_rx_intr()
300 u32 desc_off = desc_offset(port, port->rxin, 0); in sca_rx_intr()
307 desc = desc_address(port, port->rxin, 0); in sca_rx_intr()
308 stat = readb(&desc->stat); in sca_rx_intr()
310 port->rxpart = 1; /* partial frame received */ in sca_rx_intr()
311 else if ((stat & ST_ERROR_MASK) || port->rxpart) { in sca_rx_intr()
312 dev->stats.rx_errors++; in sca_rx_intr()
314 dev->stats.rx_fifo_errors++; in sca_rx_intr()
316 ST_RX_RESBIT)) || port->rxpart) in sca_rx_intr()
317 dev->stats.rx_frame_errors++; in sca_rx_intr()
319 dev->stats.rx_crc_errors++; in sca_rx_intr()
321 port->rxpart = 0; /* received last fragment */ in sca_rx_intr()
323 sca_rx(card, port, desc, port->rxin); in sca_rx_intr()
328 port->rxin = next_desc(port, port->rxin, 0); in sca_rx_intr()
332 sca_out(DSR_DE, DSR_RX(phy_node(port)), card); in sca_rx_intr()
336 static inline void sca_tx_intr(port_t *port) in sca_tx_intr() argument
338 struct net_device *dev = port_to_dev(port); in sca_tx_intr()
339 u16 dmac = get_dmac_tx(port); in sca_tx_intr()
340 card_t *card = port_to_card(port); in sca_tx_intr()
343 spin_lock(&port->lock); in sca_tx_intr()
345 stat = sca_in(DSR_TX(phy_node(port)), card); /* read DMA Status */ in sca_tx_intr()
349 DSR_TX(phy_node(port)), card); in sca_tx_intr()
351 while (1) { in sca_tx_intr()
354 u32 desc_off = desc_offset(port, port->txlast, 1); in sca_tx_intr()
360 desc = desc_address(port, port->txlast, 1); in sca_tx_intr()
361 dev->stats.tx_packets++; in sca_tx_intr()
362 dev->stats.tx_bytes += readw(&desc->len); in sca_tx_intr()
363 writeb(0, &desc->stat); /* Free descriptor */ in sca_tx_intr()
364 port->txlast = next_desc(port, port->txlast, 1); in sca_tx_intr()
368 spin_unlock(&port->lock); in sca_tx_intr()
380 handled = 1; in sca_intr()
382 port_t *port = get_port(card, i); in sca_intr() local
384 if (port) { in sca_intr()
386 sca_msci_intr(port); in sca_intr()
389 sca_rx_intr(port); in sca_intr()
392 sca_tx_intr(port); in sca_intr()
401 static void sca_set_port(port_t *port) in sca_set_port() argument
403 card_t *card = port_to_card(port); in sca_set_port()
404 u16 msci = get_msci(port); in sca_set_port()
408 if (port->settings.clock_rate > 0) { in sca_set_port()
411 br--; in sca_set_port()
412 brv >>= 1; /* brv = 2^9 = 512 max in specs */ in sca_set_port()
415 tmc = CLOCK_BASE / brv / port->settings.clock_rate; in sca_set_port()
416 } while (br > 1 && tmc <= 128); in sca_set_port()
418 if (tmc < 1) { in sca_set_port()
419 tmc = 1; in sca_set_port()
420 br = 0; /* For baud=CLOCK_BASE we use tmc=1 br=0 */ in sca_set_port()
421 brv = 1; in sca_set_port()
423 tmc = 256; /* tmc=0 means 256 - low baud rates */ in sca_set_port()
426 port->settings.clock_rate = CLOCK_BASE / brv / tmc; in sca_set_port()
430 port->settings.clock_rate = CLOCK_BASE / (256 * 512); in sca_set_port()
433 port->rxs = (port->rxs & ~CLK_BRG_MASK) | br; in sca_set_port()
434 port->txs = (port->txs & ~CLK_BRG_MASK) | br; in sca_set_port()
435 port->tmc = tmc; in sca_set_port()
437 /* baud divisor - time constant*/ in sca_set_port()
438 sca_out(port->tmc, msci + TMC, card); in sca_set_port()
441 sca_out(port->rxs, msci + RXS, card); in sca_set_port()
442 sca_out(port->txs, msci + TXS, card); in sca_set_port()
444 if (port->settings.loopback) in sca_set_port()
454 port_t *port = dev_to_port(dev); in sca_open() local
455 card_t *card = port_to_card(port); in sca_open()
456 u16 msci = get_msci(port); in sca_open()
459 switch (port->encoding) { in sca_open()
476 if (port->settings.loopback) in sca_open()
479 switch (port->parity) { in sca_open()
505 sca_out(0x07, msci + RRC, card); /* +1=RXRDY/DMA activation condition*/ in sca_open()
507 sca_out(0x14, msci + TRC1, card); /* +1=TXRDY/DMA deactiv condition */ in sca_open()
510 * - TXINT (DMAC completed all transmisions, underrun or DCD change) in sca_open()
511 * - all DMA interrupts in sca_open()
513 sca_set_carrier(port); in sca_open()
518 sca_out(sca_in(IER0, card) | (phy_node(port) ? 0xC0 : 0x0C), in sca_open()
521 sca_out(sca_in(IER1, card) | (phy_node(port) ? 0xF0 : 0x0F), in sca_open()
524 sca_out(port->tmc, msci + TMC, card); /* Restore registers */ in sca_open()
525 sca_out(port->rxs, msci + RXS, card); in sca_open()
526 sca_out(port->txs, msci + TXS, card); in sca_open()
535 port_t *port = dev_to_port(dev); in sca_close() local
536 card_t *card = port_to_card(port); in sca_close()
539 sca_out(CMD_RESET, get_msci(port) + CMD, port_to_card(port)); in sca_close()
541 sca_out(sca_in(IER0, card) & (phy_node(port) ? 0x0F : 0xF0), in sca_close()
544 sca_out(sca_in(IER1, card) & (phy_node(port) ? 0x0F : 0xF0), in sca_close()
558 return -EINVAL; in sca_attach()
565 return -EINVAL; in sca_attach()
567 dev_to_port(dev)->encoding = encoding; in sca_attach()
568 dev_to_port(dev)->parity = parity; in sca_attach()
575 port_t *port = dev_to_port(dev); in sca_dump_rings() local
576 card_t *card = port_to_card(port); in sca_dump_rings()
585 sca_inw(get_dmac_rx(port) + CDAL, card), in sca_dump_rings()
586 sca_inw(get_dmac_rx(port) + EDAL, card), in sca_dump_rings()
587 sca_in(DSR_RX(phy_node(port)), card), port->rxin, in sca_dump_rings()
588 sca_in(DSR_RX(phy_node(port)), card) & DSR_DE ? "" : "in"); in sca_dump_rings()
589 for (cnt = 0; cnt < port_to_card(port)->rx_ring_buffers; cnt++) in sca_dump_rings()
590 pr_cont(" %02X", readb(&(desc_address(port, cnt, 0)->stat))); in sca_dump_rings()
595 sca_inw(get_dmac_tx(port) + CDAL, card), in sca_dump_rings()
596 sca_inw(get_dmac_tx(port) + EDAL, card), in sca_dump_rings()
597 sca_in(DSR_TX(phy_node(port)), card), port->txin, port->txlast, in sca_dump_rings()
598 sca_in(DSR_TX(phy_node(port)), card) & DSR_DE ? "" : "in"); in sca_dump_rings()
600 for (cnt = 0; cnt < port_to_card(port)->tx_ring_buffers; cnt++) in sca_dump_rings()
601 pr_cont(" %02X", readb(&(desc_address(port, cnt, 1)->stat))); in sca_dump_rings()
606 sca_in(get_msci(port) + MD0, card), in sca_dump_rings()
607 sca_in(get_msci(port) + MD1, card), in sca_dump_rings()
608 sca_in(get_msci(port) + MD2, card), in sca_dump_rings()
609 sca_in(get_msci(port) + ST0, card), in sca_dump_rings()
610 sca_in(get_msci(port) + ST1, card), in sca_dump_rings()
611 sca_in(get_msci(port) + ST2, card), in sca_dump_rings()
612 sca_in(get_msci(port) + ST3, card), in sca_dump_rings()
613 sca_in(get_msci(port) + FST, card), in sca_dump_rings()
614 sca_in(get_msci(port) + CST0, card), in sca_dump_rings()
615 sca_in(get_msci(port) + CST1, card)); in sca_dump_rings()
628 port_t *port = dev_to_port(dev); in sca_xmit() local
629 card_t *card = port_to_card(port); in sca_xmit()
635 spin_lock_irq(&port->lock); in sca_xmit()
637 desc = desc_address(port, port->txin + 1, 1); in sca_xmit()
638 BUG_ON(readb(&desc->stat)); /* previous xmit should stop queue */ in sca_xmit()
641 printk(KERN_DEBUG "%s TX(%i):", dev->name, skb->len); in sca_xmit()
645 desc = desc_address(port, port->txin, 1); in sca_xmit()
646 buff = buffer_offset(port, port->txin, 1); in sca_xmit()
647 len = skb->len; in sca_xmit()
650 maxlen = winsize(card) - buff; in sca_xmit()
654 memcpy_toio(winbase(card) + buff, skb->data, maxlen); in sca_xmit()
655 openwin(card, page + 1); in sca_xmit()
656 memcpy_toio(winbase(card), skb->data + maxlen, len - maxlen); in sca_xmit()
658 memcpy_toio(winbase(card) + buff, skb->data, len); in sca_xmit()
664 writew(len, &desc->len); in sca_xmit()
665 writeb(ST_TX_EOM, &desc->stat); in sca_xmit()
667 port->txin = next_desc(port, port->txin, 1); in sca_xmit()
668 sca_outw(desc_offset(port, port->txin, 1), in sca_xmit()
669 get_dmac_tx(port) + EDAL, card); in sca_xmit()
671 sca_out(DSR_DE, DSR_TX(phy_node(port)), card); /* Enable TX DMA */ in sca_xmit()
673 desc = desc_address(port, port->txin + 1, 1); in sca_xmit()
674 if (readb(&desc->stat)) /* allow 1 packet gap */ in sca_xmit()
677 spin_unlock_irq(&port->lock); in sca_xmit()
690 openwin(card, (i - 4) / size); /* select last window */ in sca_detect_ram()
693 i -= 4; in sca_detect_ram()
719 sca_out(0, DSR_RX(0), card); /* DMA disable - to halt state */ in sca_init()
721 sca_out(0, DSR_RX(1), card); in sca_init()
722 sca_out(0, DSR_TX(1), card); in sca_init()