Lines Matching refs:bp

98 static void qec_init(struct bigmac *bp)  in qec_init()  argument
100 struct platform_device *qec_op = bp->qec_op; in qec_init()
101 void __iomem *gregs = bp->gregs; in qec_init()
102 u8 bsizes = bp->bigmac_bursts; in qec_init()
165 static void bigmac_stop(struct bigmac *bp) in bigmac_stop() argument
167 bigmac_tx_reset(bp->bregs); in bigmac_stop()
168 bigmac_rx_reset(bp->bregs); in bigmac_stop()
171 static void bigmac_get_counters(struct bigmac *bp, void __iomem *bregs) in bigmac_get_counters() argument
173 struct net_device_stats *stats = &bp->dev->stats; in bigmac_get_counters()
193 static void bigmac_clean_rings(struct bigmac *bp) in bigmac_clean_rings() argument
198 if (bp->rx_skbs[i] != NULL) { in bigmac_clean_rings()
199 dev_kfree_skb_any(bp->rx_skbs[i]); in bigmac_clean_rings()
200 bp->rx_skbs[i] = NULL; in bigmac_clean_rings()
205 if (bp->tx_skbs[i] != NULL) { in bigmac_clean_rings()
206 dev_kfree_skb_any(bp->tx_skbs[i]); in bigmac_clean_rings()
207 bp->tx_skbs[i] = NULL; in bigmac_clean_rings()
212 static void bigmac_init_rings(struct bigmac *bp, bool non_blocking) in bigmac_init_rings() argument
214 struct bmac_init_block *bb = bp->bmac_block; in bigmac_init_rings()
221 bp->rx_new = bp->rx_old = bp->tx_new = bp->tx_old = 0; in bigmac_init_rings()
224 bigmac_clean_rings(bp); in bigmac_init_rings()
234 bp->rx_skbs[i] = skb; in bigmac_init_rings()
241 dma_map_single(&bp->bigmac_op->dev, in bigmac_init_rings()
268 static void write_tcvr_bit(struct bigmac *bp, void __iomem *tregs, int bit) in write_tcvr_bit() argument
270 if (bp->tcvr_type == internal) { in write_tcvr_bit()
278 } else if (bp->tcvr_type == external) { in write_tcvr_bit()
291 static int read_tcvr_bit(struct bigmac *bp, void __iomem *tregs) in read_tcvr_bit() argument
295 if (bp->tcvr_type == internal) { in read_tcvr_bit()
302 } else if (bp->tcvr_type == external) { in read_tcvr_bit()
314 static int read_tcvr_bit2(struct bigmac *bp, void __iomem *tregs) in read_tcvr_bit2() argument
318 if (bp->tcvr_type == internal) { in read_tcvr_bit2()
324 } else if (bp->tcvr_type == external) { in read_tcvr_bit2()
336 static void put_tcvr_byte(struct bigmac *bp, in put_tcvr_byte() argument
343 write_tcvr_bit(bp, tregs, ((byte >> shift) & 1)); in put_tcvr_byte()
348 static void bigmac_tcvr_write(struct bigmac *bp, void __iomem *tregs, in bigmac_tcvr_write() argument
355 switch(bp->tcvr_type) { in bigmac_tcvr_write()
366 write_tcvr_bit(bp, tregs, 0); in bigmac_tcvr_write()
367 write_tcvr_bit(bp, tregs, 1); in bigmac_tcvr_write()
368 write_tcvr_bit(bp, tregs, 0); in bigmac_tcvr_write()
369 write_tcvr_bit(bp, tregs, 1); in bigmac_tcvr_write()
371 put_tcvr_byte(bp, tregs, in bigmac_tcvr_write()
372 ((bp->tcvr_type == internal) ? in bigmac_tcvr_write()
375 put_tcvr_byte(bp, tregs, reg); in bigmac_tcvr_write()
377 write_tcvr_bit(bp, tregs, 1); in bigmac_tcvr_write()
378 write_tcvr_bit(bp, tregs, 0); in bigmac_tcvr_write()
382 write_tcvr_bit(bp, tregs, (val >> shift) & 1); in bigmac_tcvr_write()
387 static unsigned short bigmac_tcvr_read(struct bigmac *bp, in bigmac_tcvr_read() argument
394 switch(bp->tcvr_type) { in bigmac_tcvr_read()
405 write_tcvr_bit(bp, tregs, 0); in bigmac_tcvr_read()
406 write_tcvr_bit(bp, tregs, 1); in bigmac_tcvr_read()
407 write_tcvr_bit(bp, tregs, 1); in bigmac_tcvr_read()
408 write_tcvr_bit(bp, tregs, 0); in bigmac_tcvr_read()
410 put_tcvr_byte(bp, tregs, in bigmac_tcvr_read()
411 ((bp->tcvr_type == internal) ? in bigmac_tcvr_read()
414 put_tcvr_byte(bp, tregs, reg); in bigmac_tcvr_read()
416 if (bp->tcvr_type == external) { in bigmac_tcvr_read()
419 (void) read_tcvr_bit2(bp, tregs); in bigmac_tcvr_read()
420 (void) read_tcvr_bit2(bp, tregs); in bigmac_tcvr_read()
425 tmp = read_tcvr_bit2(bp, tregs); in bigmac_tcvr_read()
430 (void) read_tcvr_bit2(bp, tregs); in bigmac_tcvr_read()
431 (void) read_tcvr_bit2(bp, tregs); in bigmac_tcvr_read()
432 (void) read_tcvr_bit2(bp, tregs); in bigmac_tcvr_read()
436 (void) read_tcvr_bit(bp, tregs); in bigmac_tcvr_read()
437 (void) read_tcvr_bit(bp, tregs); in bigmac_tcvr_read()
442 tmp = read_tcvr_bit(bp, tregs); in bigmac_tcvr_read()
447 (void) read_tcvr_bit(bp, tregs); in bigmac_tcvr_read()
448 (void) read_tcvr_bit(bp, tregs); in bigmac_tcvr_read()
449 (void) read_tcvr_bit(bp, tregs); in bigmac_tcvr_read()
454 static void bigmac_tcvr_init(struct bigmac *bp) in bigmac_tcvr_init() argument
456 void __iomem *tregs = bp->tregs; in bigmac_tcvr_init()
473 bp->tcvr_type = external; in bigmac_tcvr_init()
478 bp->tcvr_type = internal; in bigmac_tcvr_init()
494 static int try_next_permutation(struct bigmac *bp, void __iomem *tregs) in try_next_permutation() argument
496 if (bp->sw_bmcr & BMCR_SPEED100) { in try_next_permutation()
500 bp->sw_bmcr = (BMCR_ISOLATE | BMCR_PDOWN | BMCR_LOOPBACK); in try_next_permutation()
501 bigmac_tcvr_write(bp, tregs, MII_BMCR, bp->sw_bmcr); in try_next_permutation()
502 bp->sw_bmcr = (BMCR_RESET); in try_next_permutation()
503 bigmac_tcvr_write(bp, tregs, MII_BMCR, bp->sw_bmcr); in try_next_permutation()
507 bp->sw_bmcr = bigmac_tcvr_read(bp, tregs, MII_BMCR); in try_next_permutation()
508 if ((bp->sw_bmcr & BMCR_RESET) == 0) in try_next_permutation()
513 printk(KERN_ERR "%s: PHY reset failed.\n", bp->dev->name); in try_next_permutation()
515 bp->sw_bmcr = bigmac_tcvr_read(bp, tregs, MII_BMCR); in try_next_permutation()
518 bp->sw_bmcr &= ~(BMCR_SPEED100); in try_next_permutation()
519 bigmac_tcvr_write(bp, tregs, MII_BMCR, bp->sw_bmcr); in try_next_permutation()
529 struct bigmac *bp = from_timer(bp, t, bigmac_timer); in bigmac_timer() local
530 void __iomem *tregs = bp->tregs; in bigmac_timer()
533 bp->timer_ticks++; in bigmac_timer()
534 if (bp->timer_state == ltrywait) { in bigmac_timer()
535 bp->sw_bmsr = bigmac_tcvr_read(bp, tregs, MII_BMSR); in bigmac_timer()
536 bp->sw_bmcr = bigmac_tcvr_read(bp, tregs, MII_BMCR); in bigmac_timer()
537 if (bp->sw_bmsr & BMSR_LSTATUS) { in bigmac_timer()
539 bp->dev->name, in bigmac_timer()
540 (bp->sw_bmcr & BMCR_SPEED100) ? in bigmac_timer()
542 bp->timer_state = asleep; in bigmac_timer()
545 if (bp->timer_ticks >= 4) { in bigmac_timer()
548 ret = try_next_permutation(bp, tregs); in bigmac_timer()
551 bp->dev->name); in bigmac_timer()
552 ret = bigmac_init_hw(bp, true); in bigmac_timer()
555 "BigMAC.\n", bp->dev->name); in bigmac_timer()
559 bp->timer_ticks = 0; in bigmac_timer()
568 bp->dev->name); in bigmac_timer()
570 bp->timer_ticks = 0; in bigmac_timer()
571 bp->timer_state = asleep; /* foo on you */ in bigmac_timer()
575 bp->bigmac_timer.expires = jiffies + ((12 * HZ)/10); /* 1.2 sec. */ in bigmac_timer()
576 add_timer(&bp->bigmac_timer); in bigmac_timer()
583 static void bigmac_begin_auto_negotiation(struct bigmac *bp) in bigmac_begin_auto_negotiation() argument
585 void __iomem *tregs = bp->tregs; in bigmac_begin_auto_negotiation()
589 bp->sw_bmsr = bigmac_tcvr_read(bp, tregs, MII_BMSR); in bigmac_begin_auto_negotiation()
590 bp->sw_bmcr = bigmac_tcvr_read(bp, tregs, MII_BMCR); in bigmac_begin_auto_negotiation()
593 bp->sw_bmcr = (BMCR_ISOLATE | BMCR_PDOWN | BMCR_LOOPBACK); in bigmac_begin_auto_negotiation()
594 bigmac_tcvr_write(bp, tregs, MII_BMCR, bp->sw_bmcr); in bigmac_begin_auto_negotiation()
595 bp->sw_bmcr = (BMCR_RESET); in bigmac_begin_auto_negotiation()
596 bigmac_tcvr_write(bp, tregs, MII_BMCR, bp->sw_bmcr); in bigmac_begin_auto_negotiation()
600 bp->sw_bmcr = bigmac_tcvr_read(bp, tregs, MII_BMCR); in bigmac_begin_auto_negotiation()
601 if ((bp->sw_bmcr & BMCR_RESET) == 0) in bigmac_begin_auto_negotiation()
606 printk(KERN_ERR "%s: PHY reset failed.\n", bp->dev->name); in bigmac_begin_auto_negotiation()
608 bp->sw_bmcr = bigmac_tcvr_read(bp, tregs, MII_BMCR); in bigmac_begin_auto_negotiation()
611 bp->sw_bmcr |= BMCR_SPEED100; in bigmac_begin_auto_negotiation()
612 bigmac_tcvr_write(bp, tregs, MII_BMCR, bp->sw_bmcr); in bigmac_begin_auto_negotiation()
614 bp->timer_state = ltrywait; in bigmac_begin_auto_negotiation()
615 bp->timer_ticks = 0; in bigmac_begin_auto_negotiation()
616 bp->bigmac_timer.expires = jiffies + (12 * HZ) / 10; in bigmac_begin_auto_negotiation()
617 add_timer(&bp->bigmac_timer); in bigmac_begin_auto_negotiation()
620 static int bigmac_init_hw(struct bigmac *bp, bool non_blocking) in bigmac_init_hw() argument
622 void __iomem *gregs = bp->gregs; in bigmac_init_hw()
623 void __iomem *cregs = bp->creg; in bigmac_init_hw()
624 void __iomem *bregs = bp->bregs; in bigmac_init_hw()
625 __u32 bblk_dvma = (__u32)bp->bblock_dvma; in bigmac_init_hw()
626 const unsigned char *e = &bp->dev->dev_addr[0]; in bigmac_init_hw()
629 bigmac_get_counters(bp, bregs); in bigmac_init_hw()
635 qec_init(bp); in bigmac_init_hw()
638 bigmac_init_rings(bp, non_blocking); in bigmac_init_hw()
641 bigmac_tcvr_init(bp); in bigmac_init_hw()
644 bigmac_stop(bp); in bigmac_init_hw()
710 bigmac_begin_auto_negotiation(bp); in bigmac_init_hw()
717 static void bigmac_is_medium_rare(struct bigmac *bp, u32 qec_status, u32 bmac_status) in bigmac_is_medium_rare() argument
752 bigmac_init_hw(bp, true); in bigmac_is_medium_rare()
756 static void bigmac_tx(struct bigmac *bp) in bigmac_tx() argument
758 struct be_txd *txbase = &bp->bmac_block->be_txd[0]; in bigmac_tx()
759 struct net_device *dev = bp->dev; in bigmac_tx()
762 spin_lock(&bp->lock); in bigmac_tx()
764 elem = bp->tx_old; in bigmac_tx()
766 while (elem != bp->tx_new) { in bigmac_tx()
775 skb = bp->tx_skbs[elem]; in bigmac_tx()
778 dma_unmap_single(&bp->bigmac_op->dev, in bigmac_tx()
783 bp->tx_skbs[elem] = NULL; in bigmac_tx()
789 bp->tx_old = elem; in bigmac_tx()
792 TX_BUFFS_AVAIL(bp) > 0) in bigmac_tx()
793 netif_wake_queue(bp->dev); in bigmac_tx()
795 spin_unlock(&bp->lock); in bigmac_tx()
799 static void bigmac_rx(struct bigmac *bp) in bigmac_rx() argument
801 struct be_rxd *rxbase = &bp->bmac_block->be_rxd[0]; in bigmac_rx()
803 int elem = bp->rx_new, drops = 0; in bigmac_rx()
813 bp->dev->stats.rx_errors++; in bigmac_rx()
814 bp->dev->stats.rx_length_errors++; in bigmac_rx()
818 bp->dev->stats.rx_dropped++; in bigmac_rx()
823 skb = bp->rx_skbs[elem]; in bigmac_rx()
833 dma_unmap_single(&bp->bigmac_op->dev, in bigmac_rx()
837 bp->rx_skbs[elem] = new_skb; in bigmac_rx()
841 dma_map_single(&bp->bigmac_op->dev, in bigmac_rx()
851 struct sk_buff *copy_skb = netdev_alloc_skb(bp->dev, len + 2); in bigmac_rx()
859 dma_sync_single_for_cpu(&bp->bigmac_op->dev, in bigmac_rx()
863 dma_sync_single_for_device(&bp->bigmac_op->dev, in bigmac_rx()
875 skb->protocol = eth_type_trans(skb, bp->dev); in bigmac_rx()
877 bp->dev->stats.rx_packets++; in bigmac_rx()
878 bp->dev->stats.rx_bytes += len; in bigmac_rx()
883 bp->rx_new = elem; in bigmac_rx()
885 printk(KERN_NOTICE "%s: Memory squeeze, deferring packet.\n", bp->dev->name); in bigmac_rx()
890 struct bigmac *bp = (struct bigmac *) dev_id; in bigmac_interrupt() local
896 bmac_status = sbus_readl(bp->creg + CREG_STAT); in bigmac_interrupt()
897 qec_status = sbus_readl(bp->gregs + GLOB_STAT); in bigmac_interrupt()
902 bigmac_is_medium_rare(bp, qec_status, bmac_status); in bigmac_interrupt()
905 bigmac_tx(bp); in bigmac_interrupt()
908 bigmac_rx(bp); in bigmac_interrupt()
915 struct bigmac *bp = netdev_priv(dev); in bigmac_open() local
918 ret = request_irq(dev->irq, bigmac_interrupt, IRQF_SHARED, dev->name, bp); in bigmac_open()
923 timer_setup(&bp->bigmac_timer, bigmac_timer, 0); in bigmac_open()
924 ret = bigmac_init_hw(bp, false); in bigmac_open()
926 free_irq(dev->irq, bp); in bigmac_open()
932 struct bigmac *bp = netdev_priv(dev); in bigmac_close() local
934 del_timer(&bp->bigmac_timer); in bigmac_close()
935 bp->timer_state = asleep; in bigmac_close()
936 bp->timer_ticks = 0; in bigmac_close()
938 bigmac_stop(bp); in bigmac_close()
939 bigmac_clean_rings(bp); in bigmac_close()
940 free_irq(dev->irq, bp); in bigmac_close()
946 struct bigmac *bp = netdev_priv(dev); in bigmac_tx_timeout() local
948 bigmac_init_hw(bp, true); in bigmac_tx_timeout()
956 struct bigmac *bp = netdev_priv(dev); in bigmac_start_xmit() local
961 mapping = dma_map_single(&bp->bigmac_op->dev, skb->data, in bigmac_start_xmit()
965 spin_lock_irq(&bp->lock); in bigmac_start_xmit()
966 entry = bp->tx_new; in bigmac_start_xmit()
968 bp->bmac_block->be_txd[entry].tx_flags = TXD_UPDATE; in bigmac_start_xmit()
969 bp->tx_skbs[entry] = skb; in bigmac_start_xmit()
970 bp->bmac_block->be_txd[entry].tx_addr = mapping; in bigmac_start_xmit()
971 bp->bmac_block->be_txd[entry].tx_flags = in bigmac_start_xmit()
973 bp->tx_new = NEXT_TX(entry); in bigmac_start_xmit()
974 if (TX_BUFFS_AVAIL(bp) <= 0) in bigmac_start_xmit()
976 spin_unlock_irq(&bp->lock); in bigmac_start_xmit()
979 sbus_writel(CREG_CTRL_TWAKEUP, bp->creg + CREG_CTRL); in bigmac_start_xmit()
987 struct bigmac *bp = netdev_priv(dev); in bigmac_get_stats() local
989 bigmac_get_counters(bp, bp->bregs); in bigmac_get_stats()
995 struct bigmac *bp = netdev_priv(dev); in bigmac_set_multicast() local
996 void __iomem *bregs = bp->bregs; in bigmac_set_multicast()
1047 struct bigmac *bp = netdev_priv(dev); in bigmac_get_link() local
1049 spin_lock_irq(&bp->lock); in bigmac_get_link()
1050 bp->sw_bmsr = bigmac_tcvr_read(bp, bp->tregs, MII_BMSR); in bigmac_get_link()
1051 spin_unlock_irq(&bp->lock); in bigmac_get_link()
1053 return (bp->sw_bmsr & BMSR_LSTATUS); in bigmac_get_link()
1078 struct bigmac *bp; in bigmac_ether_init() local
1091 bp = netdev_priv(dev); in bigmac_ether_init()
1092 bp->qec_op = qec_op; in bigmac_ether_init()
1093 bp->bigmac_op = op; in bigmac_ether_init()
1097 spin_lock_init(&bp->lock); in bigmac_ether_init()
1100 bp->gregs = of_ioremap(&qec_op->resource[0], 0, in bigmac_ether_init()
1102 if (!bp->gregs) { in bigmac_ether_init()
1108 if ((sbus_readl(bp->gregs + GLOB_CTRL) & 0xf0000000) != GLOB_CTRL_BMODE) { in bigmac_ether_init()
1114 if (qec_global_reset(bp->gregs)) in bigmac_ether_init()
1127 bp->bigmac_bursts = bsizes; in bigmac_ether_init()
1130 qec_init(bp); in bigmac_ether_init()
1133 bp->creg = of_ioremap(&op->resource[0], 0, in bigmac_ether_init()
1135 if (!bp->creg) { in bigmac_ether_init()
1141 bp->bregs = of_ioremap(&op->resource[1], 0, in bigmac_ether_init()
1143 if (!bp->bregs) { in bigmac_ether_init()
1151 bp->tregs = of_ioremap(&op->resource[2], 0, in bigmac_ether_init()
1153 if (!bp->tregs) { in bigmac_ether_init()
1159 bigmac_stop(bp); in bigmac_ether_init()
1162 bp->bmac_block = dma_alloc_coherent(&bp->bigmac_op->dev, in bigmac_ether_init()
1164 &bp->bblock_dvma, GFP_ATOMIC); in bigmac_ether_init()
1165 if (bp->bmac_block == NULL || bp->bblock_dvma == 0) in bigmac_ether_init()
1169 bp->board_rev = of_getintprop_default(bp->bigmac_op->dev.of_node, in bigmac_ether_init()
1173 timer_setup(&bp->bigmac_timer, bigmac_timer, 0); in bigmac_ether_init()
1174 bp->timer_state = asleep; in bigmac_ether_init()
1175 bp->timer_ticks = 0; in bigmac_ether_init()
1178 bp->dev = dev; in bigmac_ether_init()
1186 dev->irq = bp->bigmac_op->archdata.irqs[0]; in bigmac_ether_init()
1194 dev_set_drvdata(&bp->bigmac_op->dev, bp); in bigmac_ether_init()
1204 if (bp->gregs) in bigmac_ether_init()
1205 of_iounmap(&qec_op->resource[0], bp->gregs, GLOB_REG_SIZE); in bigmac_ether_init()
1206 if (bp->creg) in bigmac_ether_init()
1207 of_iounmap(&op->resource[0], bp->creg, CREG_REG_SIZE); in bigmac_ether_init()
1208 if (bp->bregs) in bigmac_ether_init()
1209 of_iounmap(&op->resource[1], bp->bregs, BMAC_REG_SIZE); in bigmac_ether_init()
1210 if (bp->tregs) in bigmac_ether_init()
1211 of_iounmap(&op->resource[2], bp->tregs, TCVR_REG_SIZE); in bigmac_ether_init()
1213 if (bp->bmac_block) in bigmac_ether_init()
1214 dma_free_coherent(&bp->bigmac_op->dev, in bigmac_ether_init()
1216 bp->bmac_block, in bigmac_ether_init()
1217 bp->bblock_dvma); in bigmac_ether_init()
1239 struct bigmac *bp = platform_get_drvdata(op); in bigmac_sbus_remove() local
1241 struct net_device *net_dev = bp->dev; in bigmac_sbus_remove()
1248 of_iounmap(&qec_op->resource[0], bp->gregs, GLOB_REG_SIZE); in bigmac_sbus_remove()
1249 of_iounmap(&op->resource[0], bp->creg, CREG_REG_SIZE); in bigmac_sbus_remove()
1250 of_iounmap(&op->resource[1], bp->bregs, BMAC_REG_SIZE); in bigmac_sbus_remove()
1251 of_iounmap(&op->resource[2], bp->tregs, TCVR_REG_SIZE); in bigmac_sbus_remove()
1254 bp->bmac_block, in bigmac_sbus_remove()
1255 bp->bblock_dvma); in bigmac_sbus_remove()