Lines Matching refs:bp
91 static void qec_init(struct bigmac *bp) in qec_init() argument
93 unsigned long gregs = bp->gregs; in qec_init()
94 struct sbus_dev *qec_sdev = bp->qec_sdev; in qec_init()
95 u8 bsizes = bp->bigmac_bursts; in qec_init()
158 static void bigmac_stop(struct bigmac *bp) in bigmac_stop() argument
160 bigmac_tx_reset(bp->bregs); in bigmac_stop()
161 bigmac_rx_reset(bp->bregs); in bigmac_stop()
164 static void bigmac_get_counters(struct bigmac *bp, unsigned long bregs) in bigmac_get_counters() argument
166 struct net_device_stats *stats = &bp->enet_stats; in bigmac_get_counters()
186 static void bigmac_clean_rings(struct bigmac *bp) in bigmac_clean_rings() argument
191 if (bp->rx_skbs[i] != NULL) { in bigmac_clean_rings()
192 dev_kfree_skb_any(bp->rx_skbs[i]); in bigmac_clean_rings()
193 bp->rx_skbs[i] = NULL; in bigmac_clean_rings()
198 if (bp->tx_skbs[i] != NULL) { in bigmac_clean_rings()
199 dev_kfree_skb_any(bp->tx_skbs[i]); in bigmac_clean_rings()
200 bp->tx_skbs[i] = NULL; in bigmac_clean_rings()
205 static void bigmac_init_rings(struct bigmac *bp, int from_irq) in bigmac_init_rings() argument
207 struct bmac_init_block *bb = bp->bmac_block; in bigmac_init_rings()
208 struct net_device *dev = bp->dev; in bigmac_init_rings()
214 bp->rx_new = bp->rx_old = bp->tx_new = bp->tx_old = 0; in bigmac_init_rings()
217 bigmac_clean_rings(bp); in bigmac_init_rings()
227 bp->rx_skbs[i] = skb; in bigmac_init_rings()
235 sbus_map_single(bp->bigmac_sdev, skb->data, in bigmac_init_rings()
261 static void write_tcvr_bit(struct bigmac *bp, unsigned long tregs, int bit) in write_tcvr_bit() argument
263 if (bp->tcvr_type == internal) { in write_tcvr_bit()
271 } else if (bp->tcvr_type == external) { in write_tcvr_bit()
284 static int read_tcvr_bit(struct bigmac *bp, unsigned long tregs) in read_tcvr_bit() argument
288 if (bp->tcvr_type == internal) { in read_tcvr_bit()
295 } else if (bp->tcvr_type == external) { in read_tcvr_bit()
307 static int read_tcvr_bit2(struct bigmac *bp, unsigned long tregs) in read_tcvr_bit2() argument
311 if (bp->tcvr_type == internal) { in read_tcvr_bit2()
317 } else if (bp->tcvr_type == external) { in read_tcvr_bit2()
329 static void put_tcvr_byte(struct bigmac *bp, in put_tcvr_byte() argument
336 write_tcvr_bit(bp, tregs, ((byte >> shift) & 1)); in put_tcvr_byte()
341 static void bigmac_tcvr_write(struct bigmac *bp, unsigned long tregs, in bigmac_tcvr_write() argument
348 switch(bp->tcvr_type) { in bigmac_tcvr_write()
359 write_tcvr_bit(bp, tregs, 0); in bigmac_tcvr_write()
360 write_tcvr_bit(bp, tregs, 1); in bigmac_tcvr_write()
361 write_tcvr_bit(bp, tregs, 0); in bigmac_tcvr_write()
362 write_tcvr_bit(bp, tregs, 1); in bigmac_tcvr_write()
364 put_tcvr_byte(bp, tregs, in bigmac_tcvr_write()
365 ((bp->tcvr_type == internal) ? in bigmac_tcvr_write()
368 put_tcvr_byte(bp, tregs, reg); in bigmac_tcvr_write()
370 write_tcvr_bit(bp, tregs, 1); in bigmac_tcvr_write()
371 write_tcvr_bit(bp, tregs, 0); in bigmac_tcvr_write()
375 write_tcvr_bit(bp, tregs, (val >> shift) & 1); in bigmac_tcvr_write()
380 static unsigned short bigmac_tcvr_read(struct bigmac *bp, in bigmac_tcvr_read() argument
387 switch(bp->tcvr_type) { in bigmac_tcvr_read()
398 write_tcvr_bit(bp, tregs, 0); in bigmac_tcvr_read()
399 write_tcvr_bit(bp, tregs, 1); in bigmac_tcvr_read()
400 write_tcvr_bit(bp, tregs, 1); in bigmac_tcvr_read()
401 write_tcvr_bit(bp, tregs, 0); in bigmac_tcvr_read()
403 put_tcvr_byte(bp, tregs, in bigmac_tcvr_read()
404 ((bp->tcvr_type == internal) ? in bigmac_tcvr_read()
407 put_tcvr_byte(bp, tregs, reg); in bigmac_tcvr_read()
409 if (bp->tcvr_type == external) { in bigmac_tcvr_read()
412 (void) read_tcvr_bit2(bp, tregs); in bigmac_tcvr_read()
413 (void) read_tcvr_bit2(bp, tregs); in bigmac_tcvr_read()
418 tmp = read_tcvr_bit2(bp, tregs); in bigmac_tcvr_read()
423 (void) read_tcvr_bit2(bp, tregs); in bigmac_tcvr_read()
424 (void) read_tcvr_bit2(bp, tregs); in bigmac_tcvr_read()
425 (void) read_tcvr_bit2(bp, tregs); in bigmac_tcvr_read()
429 (void) read_tcvr_bit(bp, tregs); in bigmac_tcvr_read()
430 (void) read_tcvr_bit(bp, tregs); in bigmac_tcvr_read()
435 tmp = read_tcvr_bit(bp, tregs); in bigmac_tcvr_read()
440 (void) read_tcvr_bit(bp, tregs); in bigmac_tcvr_read()
441 (void) read_tcvr_bit(bp, tregs); in bigmac_tcvr_read()
442 (void) read_tcvr_bit(bp, tregs); in bigmac_tcvr_read()
447 static void bigmac_tcvr_init(struct bigmac *bp) in bigmac_tcvr_init() argument
449 unsigned long tregs = bp->tregs; in bigmac_tcvr_init()
466 bp->tcvr_type = external; in bigmac_tcvr_init()
471 bp->tcvr_type = internal; in bigmac_tcvr_init()
487 static int try_next_permutation(struct bigmac *bp, unsigned long tregs) in try_next_permutation() argument
489 if (bp->sw_bmcr & BMCR_SPEED100) { in try_next_permutation()
493 bp->sw_bmcr = (BMCR_ISOLATE | BMCR_PDOWN | BMCR_LOOPBACK); in try_next_permutation()
494 bigmac_tcvr_write(bp, tregs, BIGMAC_BMCR, bp->sw_bmcr); in try_next_permutation()
495 bp->sw_bmcr = (BMCR_RESET); in try_next_permutation()
496 bigmac_tcvr_write(bp, tregs, BIGMAC_BMCR, bp->sw_bmcr); in try_next_permutation()
500 bp->sw_bmcr = bigmac_tcvr_read(bp, tregs, BIGMAC_BMCR); in try_next_permutation()
501 if ((bp->sw_bmcr & BMCR_RESET) == 0) in try_next_permutation()
506 printk(KERN_ERR "%s: PHY reset failed.\n", bp->dev->name); in try_next_permutation()
508 bp->sw_bmcr = bigmac_tcvr_read(bp, tregs, BIGMAC_BMCR); in try_next_permutation()
511 bp->sw_bmcr &= ~(BMCR_SPEED100); in try_next_permutation()
512 bigmac_tcvr_write(bp, tregs, BIGMAC_BMCR, bp->sw_bmcr); in try_next_permutation()
522 struct bigmac *bp = (struct bigmac *) data; in bigmac_timer() local
523 unsigned long tregs = bp->tregs; in bigmac_timer()
526 bp->timer_ticks++; in bigmac_timer()
527 if (bp->timer_state == ltrywait) { in bigmac_timer()
528 bp->sw_bmsr = bigmac_tcvr_read(bp, tregs, BIGMAC_BMSR); in bigmac_timer()
529 bp->sw_bmcr = bigmac_tcvr_read(bp, tregs, BIGMAC_BMCR); in bigmac_timer()
530 if (bp->sw_bmsr & BMSR_LSTATUS) { in bigmac_timer()
532 bp->dev->name, in bigmac_timer()
533 (bp->sw_bmcr & BMCR_SPEED100) ? in bigmac_timer()
535 bp->timer_state = asleep; in bigmac_timer()
538 if (bp->timer_ticks >= 4) { in bigmac_timer()
541 ret = try_next_permutation(bp, tregs); in bigmac_timer()
544 bp->dev->name); in bigmac_timer()
545 ret = bigmac_init(bp, 0); in bigmac_timer()
548 "BigMAC.\n", bp->dev->name); in bigmac_timer()
552 bp->timer_ticks = 0; in bigmac_timer()
561 bp->dev->name); in bigmac_timer()
563 bp->timer_ticks = 0; in bigmac_timer()
564 bp->timer_state = asleep; /* foo on you */ in bigmac_timer()
568 bp->bigmac_timer.expires = jiffies + ((12 * HZ)/10); /* 1.2 sec. */ in bigmac_timer()
569 add_timer(&bp->bigmac_timer); in bigmac_timer()
576 static void bigmac_begin_auto_negotiation(struct bigmac *bp) in bigmac_begin_auto_negotiation() argument
578 unsigned long tregs = bp->tregs; in bigmac_begin_auto_negotiation()
582 bp->sw_bmsr = bigmac_tcvr_read(bp, tregs, BIGMAC_BMSR); in bigmac_begin_auto_negotiation()
583 bp->sw_bmcr = bigmac_tcvr_read(bp, tregs, BIGMAC_BMCR); in bigmac_begin_auto_negotiation()
586 bp->sw_bmcr = (BMCR_ISOLATE | BMCR_PDOWN | BMCR_LOOPBACK); in bigmac_begin_auto_negotiation()
587 bigmac_tcvr_write(bp, tregs, BIGMAC_BMCR, bp->sw_bmcr); in bigmac_begin_auto_negotiation()
588 bp->sw_bmcr = (BMCR_RESET); in bigmac_begin_auto_negotiation()
589 bigmac_tcvr_write(bp, tregs, BIGMAC_BMCR, bp->sw_bmcr); in bigmac_begin_auto_negotiation()
593 bp->sw_bmcr = bigmac_tcvr_read(bp, tregs, BIGMAC_BMCR); in bigmac_begin_auto_negotiation()
594 if ((bp->sw_bmcr & BMCR_RESET) == 0) in bigmac_begin_auto_negotiation()
599 printk(KERN_ERR "%s: PHY reset failed.\n", bp->dev->name); in bigmac_begin_auto_negotiation()
601 bp->sw_bmcr = bigmac_tcvr_read(bp, tregs, BIGMAC_BMCR); in bigmac_begin_auto_negotiation()
604 bp->sw_bmcr |= BMCR_SPEED100; in bigmac_begin_auto_negotiation()
605 bigmac_tcvr_write(bp, tregs, BIGMAC_BMCR, bp->sw_bmcr); in bigmac_begin_auto_negotiation()
607 bp->timer_state = ltrywait; in bigmac_begin_auto_negotiation()
608 bp->timer_ticks = 0; in bigmac_begin_auto_negotiation()
609 bp->bigmac_timer.expires = jiffies + (12 * HZ) / 10; in bigmac_begin_auto_negotiation()
610 bp->bigmac_timer.data = (unsigned long) bp; in bigmac_begin_auto_negotiation()
611 bp->bigmac_timer.function = &bigmac_timer; in bigmac_begin_auto_negotiation()
612 add_timer(&bp->bigmac_timer); in bigmac_begin_auto_negotiation()
615 static int bigmac_init(struct bigmac *bp, int from_irq) in bigmac_init() argument
617 unsigned long gregs = bp->gregs; in bigmac_init()
618 unsigned long cregs = bp->creg; in bigmac_init()
619 unsigned long bregs = bp->bregs; in bigmac_init()
620 unsigned char *e = &bp->dev->dev_addr[0]; in bigmac_init()
623 bigmac_get_counters(bp, bregs); in bigmac_init()
629 qec_init(bp); in bigmac_init()
632 bigmac_init_rings(bp, from_irq); in bigmac_init()
635 bigmac_tcvr_init(bp); in bigmac_init()
638 bigmac_stop(bp); in bigmac_init()
668 sbus_writel(bp->bblock_dvma + bib_offset(be_rxd, 0), in bigmac_init()
670 sbus_writel(bp->bblock_dvma + bib_offset(be_txd, 0), in bigmac_init()
704 bigmac_begin_auto_negotiation(bp); in bigmac_init()
711 static void bigmac_is_medium_rare(struct bigmac *bp, u32 qec_status, u32 bmac_status) in bigmac_is_medium_rare() argument
746 bigmac_init(bp, 1); in bigmac_is_medium_rare()
750 static void bigmac_tx(struct bigmac *bp) in bigmac_tx() argument
752 struct be_txd *txbase = &bp->bmac_block->be_txd[0]; in bigmac_tx()
753 struct net_device *dev = bp->dev; in bigmac_tx()
756 spin_lock(&bp->lock); in bigmac_tx()
758 elem = bp->tx_old; in bigmac_tx()
760 while (elem != bp->tx_new) { in bigmac_tx()
769 skb = bp->tx_skbs[elem]; in bigmac_tx()
770 bp->enet_stats.tx_packets++; in bigmac_tx()
771 bp->enet_stats.tx_bytes += skb->len; in bigmac_tx()
772 sbus_unmap_single(bp->bigmac_sdev, in bigmac_tx()
777 bp->tx_skbs[elem] = NULL; in bigmac_tx()
783 bp->tx_old = elem; in bigmac_tx()
786 TX_BUFFS_AVAIL(bp) > 0) in bigmac_tx()
787 netif_wake_queue(bp->dev); in bigmac_tx()
789 spin_unlock(&bp->lock); in bigmac_tx()
793 static void bigmac_rx(struct bigmac *bp) in bigmac_rx() argument
795 struct be_rxd *rxbase = &bp->bmac_block->be_rxd[0]; in bigmac_rx()
797 int elem = bp->rx_new, drops = 0; in bigmac_rx()
807 bp->enet_stats.rx_errors++; in bigmac_rx()
808 bp->enet_stats.rx_length_errors++; in bigmac_rx()
812 bp->enet_stats.rx_dropped++; in bigmac_rx()
817 skb = bp->rx_skbs[elem]; in bigmac_rx()
827 sbus_unmap_single(bp->bigmac_sdev, in bigmac_rx()
831 bp->rx_skbs[elem] = new_skb; in bigmac_rx()
832 new_skb->dev = bp->dev; in bigmac_rx()
835 this->rx_addr = sbus_map_single(bp->bigmac_sdev, in bigmac_rx()
851 copy_skb->dev = bp->dev; in bigmac_rx()
854 sbus_dma_sync_single(bp->bigmac_sdev, in bigmac_rx()
866 skb->protocol = eth_type_trans(skb, bp->dev); in bigmac_rx()
868 bp->dev->last_rx = jiffies; in bigmac_rx()
869 bp->enet_stats.rx_packets++; in bigmac_rx()
870 bp->enet_stats.rx_bytes += len; in bigmac_rx()
875 bp->rx_new = elem; in bigmac_rx()
877 printk(KERN_NOTICE "%s: Memory squeeze, deferring packet.\n", bp->dev->name); in bigmac_rx()
882 struct bigmac *bp = (struct bigmac *) dev_id; in bigmac_interrupt() local
888 bmac_status = sbus_readl(bp->creg + CREG_STAT); in bigmac_interrupt()
889 qec_status = sbus_readl(bp->gregs + GLOB_STAT); in bigmac_interrupt()
894 bigmac_is_medium_rare(bp, qec_status, bmac_status); in bigmac_interrupt()
897 bigmac_tx(bp); in bigmac_interrupt()
900 bigmac_rx(bp); in bigmac_interrupt()
905 struct bigmac *bp = (struct bigmac *) dev->priv; in bigmac_open() local
908 ret = request_irq(dev->irq, &bigmac_interrupt, SA_SHIRQ, dev->name, bp); in bigmac_open()
913 init_timer(&bp->bigmac_timer); in bigmac_open()
914 ret = bigmac_init(bp, 0); in bigmac_open()
916 free_irq(dev->irq, bp); in bigmac_open()
922 struct bigmac *bp = (struct bigmac *) dev->priv; in bigmac_close() local
924 del_timer(&bp->bigmac_timer); in bigmac_close()
925 bp->timer_state = asleep; in bigmac_close()
926 bp->timer_ticks = 0; in bigmac_close()
928 bigmac_stop(bp); in bigmac_close()
929 bigmac_clean_rings(bp); in bigmac_close()
930 free_irq(dev->irq, bp); in bigmac_close()
936 struct bigmac *bp = (struct bigmac *) dev->priv; in bigmac_tx_timeout() local
938 bigmac_init(bp, 0); in bigmac_tx_timeout()
945 struct bigmac *bp = (struct bigmac *) dev->priv; in bigmac_start_xmit() local
950 mapping = sbus_map_single(bp->bigmac_sdev, skb->data, len, SBUS_DMA_TODEVICE); in bigmac_start_xmit()
953 spin_lock_irq(&bp->lock); in bigmac_start_xmit()
954 entry = bp->tx_new; in bigmac_start_xmit()
956 bp->bmac_block->be_txd[entry].tx_flags = TXD_UPDATE; in bigmac_start_xmit()
957 bp->tx_skbs[entry] = skb; in bigmac_start_xmit()
958 bp->bmac_block->be_txd[entry].tx_addr = mapping; in bigmac_start_xmit()
959 bp->bmac_block->be_txd[entry].tx_flags = in bigmac_start_xmit()
961 bp->tx_new = NEXT_TX(entry); in bigmac_start_xmit()
962 if (TX_BUFFS_AVAIL(bp) <= 0) in bigmac_start_xmit()
964 spin_unlock_irq(&bp->lock); in bigmac_start_xmit()
967 sbus_writel(CREG_CTRL_TWAKEUP, bp->creg + CREG_CTRL); in bigmac_start_xmit()
977 struct bigmac *bp = (struct bigmac *) dev->priv; in bigmac_get_stats() local
979 bigmac_get_counters(bp, bp->bregs); in bigmac_get_stats()
980 return &bp->enet_stats; in bigmac_get_stats()
985 struct bigmac *bp = (struct bigmac *) dev->priv; in bigmac_set_multicast() local
986 unsigned long bregs = bp->bregs; in bigmac_set_multicast()
1042 struct bigmac *bp; in bigmac_ether_init() local
1067 bp = dev->priv; in bigmac_ether_init()
1068 bp->qec_sdev = qec_sdev; in bigmac_ether_init()
1069 bp->bigmac_sdev = qec_sdev->child; in bigmac_ether_init()
1071 spin_lock_init(&bp->lock); in bigmac_ether_init()
1074 if ((bp->bigmac_sdev->num_registers != 3) || in bigmac_ether_init()
1075 (bp->qec_sdev->num_registers != 2)) { in bigmac_ether_init()
1077 bp->qec_sdev->num_registers, in bigmac_ether_init()
1078 bp->bigmac_sdev->num_registers); in bigmac_ether_init()
1084 bp->gregs = sbus_ioremap(&bp->qec_sdev->resource[0], 0, in bigmac_ether_init()
1086 if (!bp->gregs) { in bigmac_ether_init()
1092 if ((sbus_readl(bp->gregs + GLOB_CTRL) & 0xf0000000) != GLOB_CTRL_BMODE) { in bigmac_ether_init()
1098 if (qec_global_reset(bp->gregs)) in bigmac_ether_init()
1102 bsizes = prom_getintdefault(bp->qec_sdev->prom_node, in bigmac_ether_init()
1106 bsizes_more = prom_getintdefault(bp->qec_sdev->bus->prom_node, in bigmac_ether_init()
1116 bp->bigmac_bursts = bsizes; in bigmac_ether_init()
1119 qec_init(bp); in bigmac_ether_init()
1122 bp->creg = sbus_ioremap(&bp->bigmac_sdev->resource[0], 0, in bigmac_ether_init()
1124 if (!bp->creg) { in bigmac_ether_init()
1130 bp->bregs = sbus_ioremap(&bp->bigmac_sdev->resource[1], 0, in bigmac_ether_init()
1132 if (!bp->bregs) { in bigmac_ether_init()
1140 bp->tregs = sbus_ioremap(&bp->bigmac_sdev->resource[2], 0, in bigmac_ether_init()
1142 if (!bp->tregs) { in bigmac_ether_init()
1148 bigmac_stop(bp); in bigmac_ether_init()
1151 bp->bmac_block = sbus_alloc_consistent(bp->bigmac_sdev, in bigmac_ether_init()
1153 &bp->bblock_dvma); in bigmac_ether_init()
1154 if (bp->bmac_block == NULL || bp->bblock_dvma == 0) { in bigmac_ether_init()
1160 bp->board_rev = prom_getintdefault(bp->bigmac_sdev->prom_node, in bigmac_ether_init()
1164 init_timer(&bp->bigmac_timer); in bigmac_ether_init()
1165 bp->timer_state = asleep; in bigmac_ether_init()
1166 bp->timer_ticks = 0; in bigmac_ether_init()
1169 bp->dev = dev; in bigmac_ether_init()
1184 dev->irq = bp->bigmac_sdev->irqs[0]; in bigmac_ether_init()
1191 bp->next_module = root_bigmac_dev; in bigmac_ether_init()
1192 root_bigmac_dev = bp; in bigmac_ether_init()
1199 if (bp->gregs) in bigmac_ether_init()
1200 sbus_iounmap(bp->gregs, GLOB_REG_SIZE); in bigmac_ether_init()
1201 if (bp->creg) in bigmac_ether_init()
1202 sbus_iounmap(bp->creg, CREG_REG_SIZE); in bigmac_ether_init()
1203 if (bp->bregs) in bigmac_ether_init()
1204 sbus_iounmap(bp->bregs, BMAC_REG_SIZE); in bigmac_ether_init()
1205 if (bp->tregs) in bigmac_ether_init()
1206 sbus_iounmap(bp->tregs, TCVR_REG_SIZE); in bigmac_ether_init()
1208 if (bp->bmac_block) in bigmac_ether_init()
1209 sbus_free_consistent(bp->bigmac_sdev, in bigmac_ether_init()
1211 bp->bmac_block, in bigmac_ether_init()
1212 bp->bblock_dvma); in bigmac_ether_init()
1272 struct bigmac *bp = root_bigmac_dev; in bigmac_cleanup() local
1275 sbus_iounmap(bp->gregs, GLOB_REG_SIZE); in bigmac_cleanup()
1276 sbus_iounmap(bp->creg, CREG_REG_SIZE); in bigmac_cleanup()
1277 sbus_iounmap(bp->bregs, BMAC_REG_SIZE); in bigmac_cleanup()
1278 sbus_iounmap(bp->tregs, TCVR_REG_SIZE); in bigmac_cleanup()
1279 sbus_free_consistent(bp->bigmac_sdev, in bigmac_cleanup()
1281 bp->bmac_block, in bigmac_cleanup()
1282 bp->bblock_dvma); in bigmac_cleanup()
1284 unregister_netdev(bp->dev); in bigmac_cleanup()
1285 kfree(bp->dev); in bigmac_cleanup()