Lines Matching full:cp
111 * also, we need to make cp->lock finer-grained.
161 #define CAS_MAX_MTU min(((cp->page_size << 1) - 0x50), 9000)
230 static void cas_set_link_modes(struct cas *cp);
232 static inline void cas_lock_tx(struct cas *cp) in cas_lock_tx() argument
237 spin_lock_nested(&cp->tx_lock[i], i); in cas_lock_tx()
248 #define cas_lock_all_save(cp, flags) \ argument
250 struct cas *xxxcp = (cp); \
255 static inline void cas_unlock_tx(struct cas *cp) in cas_unlock_tx() argument
260 spin_unlock(&cp->tx_lock[i - 1]); in cas_unlock_tx()
263 #define cas_unlock_all_restore(cp, flags) \ argument
265 struct cas *xxxcp = (cp); \
270 static void cas_disable_irq(struct cas *cp, const int ring) in cas_disable_irq() argument
274 writel(0xFFFFFFFF, cp->regs + REG_INTR_MASK); in cas_disable_irq()
279 if (cp->cas_flags & CAS_FLAG_REG_PLUS) { in cas_disable_irq()
292 cp->regs + REG_PLUS_INTRN_MASK(ring)); in cas_disable_irq()
296 writel(INTRN_MASK_CLEAR_ALL, cp->regs + in cas_disable_irq()
303 static inline void cas_mask_intr(struct cas *cp) in cas_mask_intr() argument
308 cas_disable_irq(cp, i); in cas_mask_intr()
311 static void cas_enable_irq(struct cas *cp, const int ring) in cas_enable_irq() argument
314 writel(INTR_TX_DONE, cp->regs + REG_INTR_MASK); in cas_enable_irq()
318 if (cp->cas_flags & CAS_FLAG_REG_PLUS) { in cas_enable_irq()
330 writel(INTRN_MASK_RX_EN, cp->regs + in cas_enable_irq()
340 static inline void cas_unmask_intr(struct cas *cp) in cas_unmask_intr() argument
345 cas_enable_irq(cp, i); in cas_unmask_intr()
348 static inline void cas_entropy_gather(struct cas *cp) in cas_entropy_gather() argument
351 if ((cp->cas_flags & CAS_FLAG_ENTROPY_DEV) == 0) in cas_entropy_gather()
354 batch_entropy_store(readl(cp->regs + REG_ENTROPY_IV), in cas_entropy_gather()
355 readl(cp->regs + REG_ENTROPY_IV), in cas_entropy_gather()
360 static inline void cas_entropy_reset(struct cas *cp) in cas_entropy_reset() argument
363 if ((cp->cas_flags & CAS_FLAG_ENTROPY_DEV) == 0) in cas_entropy_reset()
367 cp->regs + REG_BIM_LOCAL_DEV_EN); in cas_entropy_reset()
368 writeb(ENTROPY_RESET_STC_MODE, cp->regs + REG_ENTROPY_RESET); in cas_entropy_reset()
369 writeb(0x55, cp->regs + REG_ENTROPY_RAND_REG); in cas_entropy_reset()
372 if (readb(cp->regs + REG_ENTROPY_RAND_REG) == 0) in cas_entropy_reset()
373 cp->cas_flags &= ~CAS_FLAG_ENTROPY_DEV; in cas_entropy_reset()
380 static u16 cas_phy_read(struct cas *cp, int reg) in cas_phy_read() argument
386 cmd |= CAS_BASE(MIF_FRAME_PHY_ADDR, cp->phy_addr); in cas_phy_read()
389 writel(cmd, cp->regs + REG_MIF_FRAME); in cas_phy_read()
394 cmd = readl(cp->regs + REG_MIF_FRAME); in cas_phy_read()
401 static int cas_phy_write(struct cas *cp, int reg, u16 val) in cas_phy_write() argument
407 cmd |= CAS_BASE(MIF_FRAME_PHY_ADDR, cp->phy_addr); in cas_phy_write()
411 writel(cmd, cp->regs + REG_MIF_FRAME); in cas_phy_write()
416 cmd = readl(cp->regs + REG_MIF_FRAME); in cas_phy_write()
423 static void cas_phy_powerup(struct cas *cp) in cas_phy_powerup() argument
425 u16 ctl = cas_phy_read(cp, MII_BMCR); in cas_phy_powerup()
430 cas_phy_write(cp, MII_BMCR, ctl); in cas_phy_powerup()
433 static void cas_phy_powerdown(struct cas *cp) in cas_phy_powerdown() argument
435 u16 ctl = cas_phy_read(cp, MII_BMCR); in cas_phy_powerdown()
440 cas_phy_write(cp, MII_BMCR, ctl); in cas_phy_powerdown()
443 /* cp->lock held. note: the last put_page will free the buffer */
444 static int cas_page_free(struct cas *cp, cas_page_t *page) in cas_page_free() argument
446 dma_unmap_page(&cp->pdev->dev, page->dma_addr, cp->page_size, in cas_page_free()
448 __free_pages(page->buffer, cp->page_order); in cas_page_free()
464 static cas_page_t *cas_page_alloc(struct cas *cp, const gfp_t flags) in cas_page_alloc() argument
474 page->buffer = alloc_pages(flags, cp->page_order); in cas_page_alloc()
477 page->dma_addr = dma_map_page(&cp->pdev->dev, page->buffer, 0, in cas_page_alloc()
478 cp->page_size, DMA_FROM_DEVICE); in cas_page_alloc()
487 static void cas_spare_init(struct cas *cp) in cas_spare_init() argument
489 spin_lock(&cp->rx_inuse_lock); in cas_spare_init()
490 INIT_LIST_HEAD(&cp->rx_inuse_list); in cas_spare_init()
491 spin_unlock(&cp->rx_inuse_lock); in cas_spare_init()
493 spin_lock(&cp->rx_spare_lock); in cas_spare_init()
494 INIT_LIST_HEAD(&cp->rx_spare_list); in cas_spare_init()
495 cp->rx_spares_needed = RX_SPARE_COUNT; in cas_spare_init()
496 spin_unlock(&cp->rx_spare_lock); in cas_spare_init()
500 static void cas_spare_free(struct cas *cp) in cas_spare_free() argument
506 spin_lock(&cp->rx_spare_lock); in cas_spare_free()
507 list_splice_init(&cp->rx_spare_list, &list); in cas_spare_free()
508 spin_unlock(&cp->rx_spare_lock); in cas_spare_free()
510 cas_page_free(cp, list_entry(elem, cas_page_t, list)); in cas_spare_free()
519 spin_lock(&cp->rx_inuse_lock); in cas_spare_free()
520 list_splice_init(&cp->rx_inuse_list, &list); in cas_spare_free()
521 spin_unlock(&cp->rx_inuse_lock); in cas_spare_free()
523 spin_lock(&cp->rx_spare_lock); in cas_spare_free()
524 list_splice_init(&cp->rx_inuse_list, &list); in cas_spare_free()
525 spin_unlock(&cp->rx_spare_lock); in cas_spare_free()
528 cas_page_free(cp, list_entry(elem, cas_page_t, list)); in cas_spare_free()
533 static void cas_spare_recover(struct cas *cp, const gfp_t flags) in cas_spare_recover() argument
544 spin_lock(&cp->rx_inuse_lock); in cas_spare_recover()
545 list_splice_init(&cp->rx_inuse_list, &list); in cas_spare_recover()
546 spin_unlock(&cp->rx_inuse_lock); in cas_spare_recover()
567 spin_lock(&cp->rx_spare_lock); in cas_spare_recover()
568 if (cp->rx_spares_needed > 0) { in cas_spare_recover()
569 list_add(elem, &cp->rx_spare_list); in cas_spare_recover()
570 cp->rx_spares_needed--; in cas_spare_recover()
571 spin_unlock(&cp->rx_spare_lock); in cas_spare_recover()
573 spin_unlock(&cp->rx_spare_lock); in cas_spare_recover()
574 cas_page_free(cp, page); in cas_spare_recover()
580 spin_lock(&cp->rx_inuse_lock); in cas_spare_recover()
581 list_splice(&list, &cp->rx_inuse_list); in cas_spare_recover()
582 spin_unlock(&cp->rx_inuse_lock); in cas_spare_recover()
585 spin_lock(&cp->rx_spare_lock); in cas_spare_recover()
586 needed = cp->rx_spares_needed; in cas_spare_recover()
587 spin_unlock(&cp->rx_spare_lock); in cas_spare_recover()
595 cas_page_t *spare = cas_page_alloc(cp, flags); in cas_spare_recover()
602 spin_lock(&cp->rx_spare_lock); in cas_spare_recover()
603 list_splice(&list, &cp->rx_spare_list); in cas_spare_recover()
604 cp->rx_spares_needed -= i; in cas_spare_recover()
605 spin_unlock(&cp->rx_spare_lock); in cas_spare_recover()
609 static cas_page_t *cas_page_dequeue(struct cas *cp) in cas_page_dequeue() argument
614 spin_lock(&cp->rx_spare_lock); in cas_page_dequeue()
615 if (list_empty(&cp->rx_spare_list)) { in cas_page_dequeue()
617 spin_unlock(&cp->rx_spare_lock); in cas_page_dequeue()
618 cas_spare_recover(cp, GFP_ATOMIC); in cas_page_dequeue()
619 spin_lock(&cp->rx_spare_lock); in cas_page_dequeue()
620 if (list_empty(&cp->rx_spare_list)) { in cas_page_dequeue()
621 netif_err(cp, rx_err, cp->dev, in cas_page_dequeue()
623 spin_unlock(&cp->rx_spare_lock); in cas_page_dequeue()
628 entry = cp->rx_spare_list.next; in cas_page_dequeue()
630 recover = ++cp->rx_spares_needed; in cas_page_dequeue()
631 spin_unlock(&cp->rx_spare_lock); in cas_page_dequeue()
636 atomic_inc(&cp->reset_task_pending); in cas_page_dequeue()
637 atomic_inc(&cp->reset_task_pending_spare); in cas_page_dequeue()
638 schedule_work(&cp->reset_task); in cas_page_dequeue()
640 atomic_set(&cp->reset_task_pending, CAS_RESET_SPARE); in cas_page_dequeue()
641 schedule_work(&cp->reset_task); in cas_page_dequeue()
648 static void cas_mif_poll(struct cas *cp, const int enable) in cas_mif_poll() argument
652 cfg = readl(cp->regs + REG_MIF_CFG); in cas_mif_poll()
655 if (cp->phy_type & CAS_PHY_MII_MDIO1) in cas_mif_poll()
662 cfg |= CAS_BASE(MIF_CFG_POLL_PHY, cp->phy_addr); in cas_mif_poll()
665 cp->regs + REG_MIF_MASK); in cas_mif_poll()
666 writel(cfg, cp->regs + REG_MIF_CFG); in cas_mif_poll()
669 /* Must be invoked under cp->lock */
670 static void cas_begin_auto_negotiation(struct cas *cp, in cas_begin_auto_negotiation() argument
677 int oldstate = cp->lstate; in cas_begin_auto_negotiation()
683 lcntl = cp->link_cntl; in cas_begin_auto_negotiation()
685 cp->link_cntl = BMCR_ANENABLE; in cas_begin_auto_negotiation()
688 cp->link_cntl = 0; in cas_begin_auto_negotiation()
690 cp->link_cntl |= BMCR_SPEED100; in cas_begin_auto_negotiation()
692 cp->link_cntl |= CAS_BMCR_SPEED1000; in cas_begin_auto_negotiation()
694 cp->link_cntl |= BMCR_FULLDPLX; in cas_begin_auto_negotiation()
697 changed = (lcntl != cp->link_cntl); in cas_begin_auto_negotiation()
700 if (cp->lstate == link_up) { in cas_begin_auto_negotiation()
701 netdev_info(cp->dev, "PCS link down\n"); in cas_begin_auto_negotiation()
704 netdev_info(cp->dev, "link configuration changed\n"); in cas_begin_auto_negotiation()
707 cp->lstate = link_down; in cas_begin_auto_negotiation()
708 cp->link_transition = LINK_TRANSITION_LINK_DOWN; in cas_begin_auto_negotiation()
709 if (!cp->hw_running) in cas_begin_auto_negotiation()
718 netif_carrier_off(cp->dev); in cas_begin_auto_negotiation()
725 atomic_inc(&cp->reset_task_pending); in cas_begin_auto_negotiation()
726 atomic_inc(&cp->reset_task_pending_all); in cas_begin_auto_negotiation()
727 schedule_work(&cp->reset_task); in cas_begin_auto_negotiation()
728 cp->timer_ticks = 0; in cas_begin_auto_negotiation()
729 mod_timer(&cp->link_timer, jiffies + CAS_LINK_TIMEOUT); in cas_begin_auto_negotiation()
733 if (cp->phy_type & CAS_PHY_SERDES) { in cas_begin_auto_negotiation()
734 u32 val = readl(cp->regs + REG_PCS_MII_CTRL); in cas_begin_auto_negotiation()
736 if (cp->link_cntl & BMCR_ANENABLE) { in cas_begin_auto_negotiation()
738 cp->lstate = link_aneg; in cas_begin_auto_negotiation()
740 if (cp->link_cntl & BMCR_FULLDPLX) in cas_begin_auto_negotiation()
743 cp->lstate = link_force_ok; in cas_begin_auto_negotiation()
745 cp->link_transition = LINK_TRANSITION_LINK_CONFIG; in cas_begin_auto_negotiation()
746 writel(val, cp->regs + REG_PCS_MII_CTRL); in cas_begin_auto_negotiation()
749 cas_mif_poll(cp, 0); in cas_begin_auto_negotiation()
750 ctl = cas_phy_read(cp, MII_BMCR); in cas_begin_auto_negotiation()
753 ctl |= cp->link_cntl; in cas_begin_auto_negotiation()
756 cp->lstate = link_aneg; in cas_begin_auto_negotiation()
758 cp->lstate = link_force_ok; in cas_begin_auto_negotiation()
760 cp->link_transition = LINK_TRANSITION_LINK_CONFIG; in cas_begin_auto_negotiation()
761 cas_phy_write(cp, MII_BMCR, ctl); in cas_begin_auto_negotiation()
762 cas_mif_poll(cp, 1); in cas_begin_auto_negotiation()
765 cp->timer_ticks = 0; in cas_begin_auto_negotiation()
766 mod_timer(&cp->link_timer, jiffies + CAS_LINK_TIMEOUT); in cas_begin_auto_negotiation()
769 /* Must be invoked under cp->lock. */
770 static int cas_reset_mii_phy(struct cas *cp) in cas_reset_mii_phy() argument
775 cas_phy_write(cp, MII_BMCR, BMCR_RESET); in cas_reset_mii_phy()
778 val = cas_phy_read(cp, MII_BMCR); in cas_reset_mii_phy()
786 static void cas_saturn_firmware_init(struct cas *cp) in cas_saturn_firmware_init() argument
792 if (PHY_NS_DP83065 != cp->phy_id) in cas_saturn_firmware_init()
795 err = request_firmware(&fw, fw_name, &cp->pdev->dev); in cas_saturn_firmware_init()
806 cp->fw_load_addr= fw->data[1] << 8 | fw->data[0]; in cas_saturn_firmware_init()
807 cp->fw_size = fw->size - 2; in cas_saturn_firmware_init()
808 cp->fw_data = vmalloc(cp->fw_size); in cas_saturn_firmware_init()
809 if (!cp->fw_data) in cas_saturn_firmware_init()
811 memcpy(cp->fw_data, &fw->data[2], cp->fw_size); in cas_saturn_firmware_init()
816 static void cas_saturn_firmware_load(struct cas *cp) in cas_saturn_firmware_load() argument
820 if (!cp->fw_data) in cas_saturn_firmware_load()
823 cas_phy_powerdown(cp); in cas_saturn_firmware_load()
826 cas_phy_write(cp, DP83065_MII_MEM, 0x0); in cas_saturn_firmware_load()
829 cas_phy_write(cp, DP83065_MII_REGE, 0x8ff9); in cas_saturn_firmware_load()
830 cas_phy_write(cp, DP83065_MII_REGD, 0xbd); in cas_saturn_firmware_load()
831 cas_phy_write(cp, DP83065_MII_REGE, 0x8ffa); in cas_saturn_firmware_load()
832 cas_phy_write(cp, DP83065_MII_REGD, 0x82); in cas_saturn_firmware_load()
833 cas_phy_write(cp, DP83065_MII_REGE, 0x8ffb); in cas_saturn_firmware_load()
834 cas_phy_write(cp, DP83065_MII_REGD, 0x0); in cas_saturn_firmware_load()
835 cas_phy_write(cp, DP83065_MII_REGE, 0x8ffc); in cas_saturn_firmware_load()
836 cas_phy_write(cp, DP83065_MII_REGD, 0x39); in cas_saturn_firmware_load()
839 cas_phy_write(cp, DP83065_MII_MEM, 0x1); in cas_saturn_firmware_load()
840 cas_phy_write(cp, DP83065_MII_REGE, cp->fw_load_addr); in cas_saturn_firmware_load()
841 for (i = 0; i < cp->fw_size; i++) in cas_saturn_firmware_load()
842 cas_phy_write(cp, DP83065_MII_REGD, cp->fw_data[i]); in cas_saturn_firmware_load()
845 cas_phy_write(cp, DP83065_MII_REGE, 0x8ff8); in cas_saturn_firmware_load()
846 cas_phy_write(cp, DP83065_MII_REGD, 0x1); in cas_saturn_firmware_load()
851 static void cas_phy_init(struct cas *cp) in cas_phy_init() argument
856 if (CAS_PHY_MII(cp->phy_type)) { in cas_phy_init()
858 cp->regs + REG_PCS_DATAPATH_MODE); in cas_phy_init()
860 cas_mif_poll(cp, 0); in cas_phy_init()
861 cas_reset_mii_phy(cp); /* take out of isolate mode */ in cas_phy_init()
863 if (PHY_LUCENT_B0 == cp->phy_id) { in cas_phy_init()
865 cas_phy_write(cp, LUCENT_MII_REG, 0x8000); in cas_phy_init()
866 cas_phy_write(cp, MII_BMCR, 0x00f1); in cas_phy_init()
867 cas_phy_write(cp, LUCENT_MII_REG, 0x0); in cas_phy_init()
869 } else if (PHY_BROADCOM_B0 == (cp->phy_id & 0xFFFFFFFC)) { in cas_phy_init()
871 cas_phy_write(cp, BROADCOM_MII_REG8, 0x0C20); in cas_phy_init()
872 cas_phy_write(cp, BROADCOM_MII_REG7, 0x0012); in cas_phy_init()
873 cas_phy_write(cp, BROADCOM_MII_REG5, 0x1804); in cas_phy_init()
874 cas_phy_write(cp, BROADCOM_MII_REG7, 0x0013); in cas_phy_init()
875 cas_phy_write(cp, BROADCOM_MII_REG5, 0x1204); in cas_phy_init()
876 cas_phy_write(cp, BROADCOM_MII_REG7, 0x8006); in cas_phy_init()
877 cas_phy_write(cp, BROADCOM_MII_REG5, 0x0132); in cas_phy_init()
878 cas_phy_write(cp, BROADCOM_MII_REG7, 0x8006); in cas_phy_init()
879 cas_phy_write(cp, BROADCOM_MII_REG5, 0x0232); in cas_phy_init()
880 cas_phy_write(cp, BROADCOM_MII_REG7, 0x201F); in cas_phy_init()
881 cas_phy_write(cp, BROADCOM_MII_REG5, 0x0A20); in cas_phy_init()
883 } else if (PHY_BROADCOM_5411 == cp->phy_id) { in cas_phy_init()
884 val = cas_phy_read(cp, BROADCOM_MII_REG4); in cas_phy_init()
885 val = cas_phy_read(cp, BROADCOM_MII_REG4); in cas_phy_init()
888 cas_phy_write(cp, BROADCOM_MII_REG4, in cas_phy_init()
892 } else if (cp->cas_flags & CAS_FLAG_SATURN) { in cas_phy_init()
893 writel((cp->phy_type & CAS_PHY_MII_MDIO0) ? in cas_phy_init()
895 cp->regs + REG_SATURN_PCFG); in cas_phy_init()
901 if (PHY_NS_DP83065 == cp->phy_id) { in cas_phy_init()
902 cas_saturn_firmware_load(cp); in cas_phy_init()
904 cas_phy_powerup(cp); in cas_phy_init()
908 val = cas_phy_read(cp, MII_BMCR); in cas_phy_init()
910 cas_phy_write(cp, MII_BMCR, val); in cas_phy_init()
913 cas_phy_write(cp, MII_ADVERTISE, in cas_phy_init()
914 cas_phy_read(cp, MII_ADVERTISE) | in cas_phy_init()
920 if (cp->cas_flags & CAS_FLAG_1000MB_CAP) { in cas_phy_init()
924 val = cas_phy_read(cp, CAS_MII_1000_CTRL); in cas_phy_init()
927 cas_phy_write(cp, CAS_MII_1000_CTRL, val); in cas_phy_init()
936 cp->regs + REG_PCS_DATAPATH_MODE); in cas_phy_init()
939 if (cp->cas_flags & CAS_FLAG_SATURN) in cas_phy_init()
940 writel(0, cp->regs + REG_SATURN_PCFG); in cas_phy_init()
943 val = readl(cp->regs + REG_PCS_MII_CTRL); in cas_phy_init()
945 writel(val, cp->regs + REG_PCS_MII_CTRL); in cas_phy_init()
950 if ((readl(cp->regs + REG_PCS_MII_CTRL) & in cas_phy_init()
955 netdev_warn(cp->dev, "PCS reset bit would not clear [%08x]\n", in cas_phy_init()
956 readl(cp->regs + REG_PCS_STATE_MACHINE)); in cas_phy_init()
961 writel(0x0, cp->regs + REG_PCS_CFG); in cas_phy_init()
964 val = readl(cp->regs + REG_PCS_MII_ADVERT); in cas_phy_init()
968 writel(val, cp->regs + REG_PCS_MII_ADVERT); in cas_phy_init()
971 writel(PCS_CFG_EN, cp->regs + REG_PCS_CFG); in cas_phy_init()
975 cp->regs + REG_PCS_SERDES_CTRL); in cas_phy_init()
980 static int cas_pcs_link_check(struct cas *cp) in cas_pcs_link_check() argument
989 stat = readl(cp->regs + REG_PCS_MII_STATUS); in cas_pcs_link_check()
991 stat = readl(cp->regs + REG_PCS_MII_STATUS); in cas_pcs_link_check()
999 netif_info(cp, link, cp->dev, "PCS RemoteFault\n"); in cas_pcs_link_check()
1004 state_machine = readl(cp->regs + REG_PCS_STATE_MACHINE); in cas_pcs_link_check()
1012 if (cp->lstate != link_up) { in cas_pcs_link_check()
1013 if (cp->opened) { in cas_pcs_link_check()
1014 cp->lstate = link_up; in cas_pcs_link_check()
1015 cp->link_transition = LINK_TRANSITION_LINK_UP; in cas_pcs_link_check()
1017 cas_set_link_modes(cp); in cas_pcs_link_check()
1018 netif_carrier_on(cp->dev); in cas_pcs_link_check()
1021 } else if (cp->lstate == link_up) { in cas_pcs_link_check()
1022 cp->lstate = link_down; in cas_pcs_link_check()
1024 cp->link_transition != LINK_TRANSITION_REQUESTED_RESET && in cas_pcs_link_check()
1025 !cp->link_transition_jiffies_valid) { in cas_pcs_link_check()
1039 cp->link_transition = LINK_TRANSITION_REQUESTED_RESET; in cas_pcs_link_check()
1040 cp->link_transition_jiffies = jiffies; in cas_pcs_link_check()
1041 cp->link_transition_jiffies_valid = 1; in cas_pcs_link_check()
1043 cp->link_transition = LINK_TRANSITION_ON_FAILURE; in cas_pcs_link_check()
1045 netif_carrier_off(cp->dev); in cas_pcs_link_check()
1046 if (cp->opened) in cas_pcs_link_check()
1047 netif_info(cp, link, cp->dev, "PCS link down\n"); in cas_pcs_link_check()
1057 if ((cp->cas_flags & CAS_FLAG_REG_PLUS) == 0) { in cas_pcs_link_check()
1059 stat = readl(cp->regs + REG_PCS_SERDES_STATE); in cas_pcs_link_check()
1063 } else if (cp->lstate == link_down) { in cas_pcs_link_check()
1065 cp->link_transition != LINK_TRANSITION_REQUESTED_RESET && in cas_pcs_link_check()
1066 !cp->link_transition_jiffies_valid) { in cas_pcs_link_check()
1073 cp->link_transition = LINK_TRANSITION_REQUESTED_RESET; in cas_pcs_link_check()
1074 cp->link_transition_jiffies = jiffies; in cas_pcs_link_check()
1075 cp->link_transition_jiffies_valid = 1; in cas_pcs_link_check()
1077 cp->link_transition = LINK_TRANSITION_STILL_FAILED; in cas_pcs_link_check()
1085 struct cas *cp, u32 status) in cas_pcs_interrupt() argument
1087 u32 stat = readl(cp->regs + REG_PCS_INTR_STATUS); in cas_pcs_interrupt()
1091 return cas_pcs_link_check(cp); in cas_pcs_interrupt()
1095 struct cas *cp, u32 status) in cas_txmac_interrupt() argument
1097 u32 txmac_stat = readl(cp->regs + REG_MAC_TX_STATUS); in cas_txmac_interrupt()
1102 netif_printk(cp, intr, KERN_DEBUG, cp->dev, in cas_txmac_interrupt()
1112 spin_lock(&cp->stat_lock[0]); in cas_txmac_interrupt()
1115 cp->net_stats[0].tx_fifo_errors++; in cas_txmac_interrupt()
1120 cp->net_stats[0].tx_errors++; in cas_txmac_interrupt()
1127 cp->net_stats[0].collisions += 0x10000; in cas_txmac_interrupt()
1130 cp->net_stats[0].tx_aborted_errors += 0x10000; in cas_txmac_interrupt()
1131 cp->net_stats[0].collisions += 0x10000; in cas_txmac_interrupt()
1135 cp->net_stats[0].tx_aborted_errors += 0x10000; in cas_txmac_interrupt()
1136 cp->net_stats[0].collisions += 0x10000; in cas_txmac_interrupt()
1138 spin_unlock(&cp->stat_lock[0]); in cas_txmac_interrupt()
1146 static void cas_load_firmware(struct cas *cp, cas_hp_inst_t *firmware) in cas_load_firmware() argument
1154 writel(i, cp->regs + REG_HP_INSTR_RAM_ADDR); in cas_load_firmware()
1158 writel(val, cp->regs + REG_HP_INSTR_RAM_DATA_HI); in cas_load_firmware()
1167 writel(val, cp->regs + REG_HP_INSTR_RAM_DATA_MID); in cas_load_firmware()
1173 writel(val, cp->regs + REG_HP_INSTR_RAM_DATA_LOW); in cas_load_firmware()
1179 static void cas_init_rx_dma(struct cas *cp) in cas_init_rx_dma() argument
1181 u64 desc_dma = cp->block_dvma; in cas_init_rx_dma()
1190 (cp->cas_flags & CAS_FLAG_REG_PLUS)) /* do desc 2 */ in cas_init_rx_dma()
1192 writel(val, cp->regs + REG_RX_CFG); in cas_init_rx_dma()
1194 val = (unsigned long) cp->init_rxds[0] - in cas_init_rx_dma()
1195 (unsigned long) cp->init_block; in cas_init_rx_dma()
1196 writel((desc_dma + val) >> 32, cp->regs + REG_RX_DB_HI); in cas_init_rx_dma()
1197 writel((desc_dma + val) & 0xffffffff, cp->regs + REG_RX_DB_LOW); in cas_init_rx_dma()
1198 writel(RX_DESC_RINGN_SIZE(0) - 4, cp->regs + REG_RX_KICK); in cas_init_rx_dma()
1200 if (cp->cas_flags & CAS_FLAG_REG_PLUS) { in cas_init_rx_dma()
1204 val = (unsigned long) cp->init_rxds[1] - in cas_init_rx_dma()
1205 (unsigned long) cp->init_block; in cas_init_rx_dma()
1206 writel((desc_dma + val) >> 32, cp->regs + REG_PLUS_RX_DB1_HI); in cas_init_rx_dma()
1207 writel((desc_dma + val) & 0xffffffff, cp->regs + in cas_init_rx_dma()
1209 writel(RX_DESC_RINGN_SIZE(1) - 4, cp->regs + in cas_init_rx_dma()
1214 val = (unsigned long) cp->init_rxcs[0] - in cas_init_rx_dma()
1215 (unsigned long) cp->init_block; in cas_init_rx_dma()
1216 writel((desc_dma + val) >> 32, cp->regs + REG_RX_CB_HI); in cas_init_rx_dma()
1217 writel((desc_dma + val) & 0xffffffff, cp->regs + REG_RX_CB_LOW); in cas_init_rx_dma()
1219 if (cp->cas_flags & CAS_FLAG_REG_PLUS) { in cas_init_rx_dma()
1222 val = (unsigned long) cp->init_rxcs[i] - in cas_init_rx_dma()
1223 (unsigned long) cp->init_block; in cas_init_rx_dma()
1224 writel((desc_dma + val) >> 32, cp->regs + in cas_init_rx_dma()
1226 writel((desc_dma + val) & 0xffffffff, cp->regs + in cas_init_rx_dma()
1235 readl(cp->regs + REG_INTR_STATUS_ALIAS); in cas_init_rx_dma()
1236 writel(INTR_RX_DONE | INTR_RX_BUF_UNAVAIL, cp->regs + REG_ALIAS_CLEAR); in cas_init_rx_dma()
1237 if (cp->cas_flags & CAS_FLAG_REG_PLUS) { in cas_init_rx_dma()
1239 readl(cp->regs + REG_PLUS_INTRN_STATUS_ALIAS(i)); in cas_init_rx_dma()
1244 cp->regs + REG_PLUS_ALIASN_CLEAR(1)); in cas_init_rx_dma()
1248 cp->regs + REG_PLUS_ALIASN_CLEAR(i)); in cas_init_rx_dma()
1253 cp->rx_pause_off / RX_PAUSE_THRESH_QUANTUM); in cas_init_rx_dma()
1255 cp->rx_pause_on / RX_PAUSE_THRESH_QUANTUM); in cas_init_rx_dma()
1256 writel(val, cp->regs + REG_RX_PAUSE_THRESH); in cas_init_rx_dma()
1260 writel(i, cp->regs + REG_RX_TABLE_ADDR); in cas_init_rx_dma()
1261 writel(0x0, cp->regs + REG_RX_TABLE_DATA_LOW); in cas_init_rx_dma()
1262 writel(0x0, cp->regs + REG_RX_TABLE_DATA_MID); in cas_init_rx_dma()
1263 writel(0x0, cp->regs + REG_RX_TABLE_DATA_HI); in cas_init_rx_dma()
1267 writel(0x0, cp->regs + REG_RX_CTRL_FIFO_ADDR); in cas_init_rx_dma()
1268 writel(0x0, cp->regs + REG_RX_IPP_FIFO_ADDR); in cas_init_rx_dma()
1274 writel(val, cp->regs + REG_RX_BLANK); in cas_init_rx_dma()
1276 writel(0x0, cp->regs + REG_RX_BLANK); in cas_init_rx_dma()
1286 writel(val, cp->regs + REG_RX_AE_THRESH); in cas_init_rx_dma()
1287 if (cp->cas_flags & CAS_FLAG_REG_PLUS) { in cas_init_rx_dma()
1289 writel(val, cp->regs + REG_PLUS_RX_AE1_THRESH); in cas_init_rx_dma()
1295 writel(0x0, cp->regs + REG_RX_RED); in cas_init_rx_dma()
1299 if (cp->page_size == 0x1000) in cas_init_rx_dma()
1301 else if (cp->page_size == 0x2000) in cas_init_rx_dma()
1303 else if (cp->page_size == 0x4000) in cas_init_rx_dma()
1307 size = cp->dev->mtu + 64; in cas_init_rx_dma()
1308 if (size > cp->page_size) in cas_init_rx_dma()
1309 size = cp->page_size; in cas_init_rx_dma()
1320 cp->mtu_stride = 1 << (i + 10); in cas_init_rx_dma()
1323 val |= CAS_BASE(RX_PAGE_SIZE_MTU_COUNT, cp->page_size >> (i + 10)); in cas_init_rx_dma()
1325 writel(val, cp->regs + REG_RX_PAGE_SIZE); in cas_init_rx_dma()
1334 writel(val, cp->regs + REG_HP_CFG); in cas_init_rx_dma()
1347 static inline cas_page_t *cas_page_spare(struct cas *cp, const int index) in cas_page_spare() argument
1349 cas_page_t *page = cp->rx_pages[1][index]; in cas_page_spare()
1355 new = cas_page_dequeue(cp); in cas_page_spare()
1357 spin_lock(&cp->rx_inuse_lock); in cas_page_spare()
1358 list_add(&page->list, &cp->rx_inuse_list); in cas_page_spare()
1359 spin_unlock(&cp->rx_inuse_lock); in cas_page_spare()
1365 static cas_page_t *cas_page_swap(struct cas *cp, const int ring, in cas_page_swap() argument
1368 cas_page_t **page0 = cp->rx_pages[0]; in cas_page_swap()
1369 cas_page_t **page1 = cp->rx_pages[1]; in cas_page_swap()
1373 cas_page_t *new = cas_page_spare(cp, index); in cas_page_swap()
1383 static void cas_clean_rxds(struct cas *cp) in cas_clean_rxds() argument
1386 struct cas_rx_desc *rxd = cp->init_rxds[0]; in cas_clean_rxds()
1392 while ((skb = __skb_dequeue(&cp->rx_flows[i]))) { in cas_clean_rxds()
1400 cas_page_t *page = cas_page_swap(cp, 0, i); in cas_clean_rxds()
1406 cp->rx_old[0] = RX_DESC_RINGN_SIZE(0) - 4; in cas_clean_rxds()
1407 cp->rx_last[0] = 0; in cas_clean_rxds()
1408 cp->cas_flags &= ~CAS_FLAG_RXD_POST(0); in cas_clean_rxds()
1411 static void cas_clean_rxcs(struct cas *cp) in cas_clean_rxcs() argument
1416 memset(cp->rx_cur, 0, sizeof(*cp->rx_cur)*N_RX_COMP_RINGS); in cas_clean_rxcs()
1417 memset(cp->rx_new, 0, sizeof(*cp->rx_new)*N_RX_COMP_RINGS); in cas_clean_rxcs()
1419 struct cas_rx_comp *rxc = cp->init_rxcs[i]; in cas_clean_rxcs()
1433 static int cas_rxmac_reset(struct cas *cp)
1435 struct net_device *dev = cp->dev;
1440 writel(cp->mac_rx_cfg & ~MAC_RX_CFG_EN, cp->regs + REG_MAC_RX_CFG);
1442 if (!(readl(cp->regs + REG_MAC_RX_CFG) & MAC_RX_CFG_EN))
1452 writel(0, cp->regs + REG_RX_CFG);
1454 if (!(readl(cp->regs + REG_RX_CFG) & RX_CFG_DMA_EN))
1466 writel(SW_RESET_RX, cp->regs + REG_SW_RESET);
1468 if (!(readl(cp->regs + REG_SW_RESET) & SW_RESET_RX))
1478 cas_clean_rxds(cp);
1479 cas_clean_rxcs(cp);
1482 cas_init_rx_dma(cp);
1485 val = readl(cp->regs + REG_RX_CFG);
1486 writel(val | RX_CFG_DMA_EN, cp->regs + REG_RX_CFG);
1487 writel(MAC_RX_FRAME_RECV, cp->regs + REG_MAC_RX_MASK);
1488 val = readl(cp->regs + REG_MAC_RX_CFG);
1489 writel(val | MAC_RX_CFG_EN, cp->regs + REG_MAC_RX_CFG);
1494 static int cas_rxmac_interrupt(struct net_device *dev, struct cas *cp, in cas_rxmac_interrupt() argument
1497 u32 stat = readl(cp->regs + REG_MAC_RX_STATUS); in cas_rxmac_interrupt()
1502 netif_dbg(cp, intr, cp->dev, "rxmac interrupt, stat: 0x%x\n", stat); in cas_rxmac_interrupt()
1505 spin_lock(&cp->stat_lock[0]); in cas_rxmac_interrupt()
1507 cp->net_stats[0].rx_frame_errors += 0x10000; in cas_rxmac_interrupt()
1510 cp->net_stats[0].rx_crc_errors += 0x10000; in cas_rxmac_interrupt()
1513 cp->net_stats[0].rx_length_errors += 0x10000; in cas_rxmac_interrupt()
1516 cp->net_stats[0].rx_over_errors++; in cas_rxmac_interrupt()
1517 cp->net_stats[0].rx_fifo_errors++; in cas_rxmac_interrupt()
1523 spin_unlock(&cp->stat_lock[0]); in cas_rxmac_interrupt()
1527 static int cas_mac_interrupt(struct net_device *dev, struct cas *cp, in cas_mac_interrupt() argument
1530 u32 stat = readl(cp->regs + REG_MAC_CTRL_STATUS); in cas_mac_interrupt()
1535 netif_printk(cp, intr, KERN_DEBUG, cp->dev, in cas_mac_interrupt()
1543 cp->pause_entered++; in cas_mac_interrupt()
1546 cp->pause_last_time_recvd = (stat >> 16); in cas_mac_interrupt()
1552 /* Must be invoked under cp->lock. */
1553 static inline int cas_mdio_link_not_up(struct cas *cp) in cas_mdio_link_not_up() argument
1557 switch (cp->lstate) { in cas_mdio_link_not_up()
1559 netif_info(cp, link, cp->dev, "Autoneg failed again, keeping forced mode\n"); in cas_mdio_link_not_up()
1560 cas_phy_write(cp, MII_BMCR, cp->link_fcntl); in cas_mdio_link_not_up()
1561 cp->timer_ticks = 5; in cas_mdio_link_not_up()
1562 cp->lstate = link_force_ok; in cas_mdio_link_not_up()
1563 cp->link_transition = LINK_TRANSITION_LINK_CONFIG; in cas_mdio_link_not_up()
1567 val = cas_phy_read(cp, MII_BMCR); in cas_mdio_link_not_up()
1574 val |= (cp->cas_flags & CAS_FLAG_1000MB_CAP) ? in cas_mdio_link_not_up()
1576 cas_phy_write(cp, MII_BMCR, val); in cas_mdio_link_not_up()
1577 cp->timer_ticks = 5; in cas_mdio_link_not_up()
1578 cp->lstate = link_force_try; in cas_mdio_link_not_up()
1579 cp->link_transition = LINK_TRANSITION_LINK_CONFIG; in cas_mdio_link_not_up()
1584 val = cas_phy_read(cp, MII_BMCR); in cas_mdio_link_not_up()
1585 cp->timer_ticks = 5; in cas_mdio_link_not_up()
1589 cas_phy_write(cp, MII_BMCR, val); in cas_mdio_link_not_up()
1599 cas_phy_write(cp, MII_BMCR, val); in cas_mdio_link_not_up()
1609 /* must be invoked with cp->lock held */
1610 static int cas_mii_link_check(struct cas *cp, const u16 bmsr) in cas_mii_link_check() argument
1620 if ((cp->lstate == link_force_try) && in cas_mii_link_check()
1621 (cp->link_cntl & BMCR_ANENABLE)) { in cas_mii_link_check()
1622 cp->lstate = link_force_ret; in cas_mii_link_check()
1623 cp->link_transition = LINK_TRANSITION_LINK_CONFIG; in cas_mii_link_check()
1624 cas_mif_poll(cp, 0); in cas_mii_link_check()
1625 cp->link_fcntl = cas_phy_read(cp, MII_BMCR); in cas_mii_link_check()
1626 cp->timer_ticks = 5; in cas_mii_link_check()
1627 if (cp->opened) in cas_mii_link_check()
1628 netif_info(cp, link, cp->dev, in cas_mii_link_check()
1630 cas_phy_write(cp, MII_BMCR, in cas_mii_link_check()
1631 cp->link_fcntl | BMCR_ANENABLE | in cas_mii_link_check()
1633 cas_mif_poll(cp, 1); in cas_mii_link_check()
1635 } else if (cp->lstate != link_up) { in cas_mii_link_check()
1636 cp->lstate = link_up; in cas_mii_link_check()
1637 cp->link_transition = LINK_TRANSITION_LINK_UP; in cas_mii_link_check()
1639 if (cp->opened) { in cas_mii_link_check()
1640 cas_set_link_modes(cp); in cas_mii_link_check()
1641 netif_carrier_on(cp->dev); in cas_mii_link_check()
1651 if (cp->lstate == link_up) { in cas_mii_link_check()
1652 cp->lstate = link_down; in cas_mii_link_check()
1653 cp->link_transition = LINK_TRANSITION_LINK_DOWN; in cas_mii_link_check()
1655 netif_carrier_off(cp->dev); in cas_mii_link_check()
1656 if (cp->opened) in cas_mii_link_check()
1657 netif_info(cp, link, cp->dev, "Link down\n"); in cas_mii_link_check()
1660 } else if (++cp->timer_ticks > 10) in cas_mii_link_check()
1661 cas_mdio_link_not_up(cp); in cas_mii_link_check()
1666 static int cas_mif_interrupt(struct net_device *dev, struct cas *cp, in cas_mif_interrupt() argument
1669 u32 stat = readl(cp->regs + REG_MIF_STATUS); in cas_mif_interrupt()
1677 return cas_mii_link_check(cp, bmsr); in cas_mif_interrupt()
1680 static int cas_pci_interrupt(struct net_device *dev, struct cas *cp, in cas_pci_interrupt() argument
1683 u32 stat = readl(cp->regs + REG_PCI_ERR_STATUS); in cas_pci_interrupt()
1689 stat, readl(cp->regs + REG_BIM_DIAG)); in cas_pci_interrupt()
1693 ((cp->cas_flags & CAS_FLAG_REG_PLUS) == 0)) in cas_pci_interrupt()
1712 pci_errs = pci_status_get_and_clear_errors(cp->pdev); in cas_pci_interrupt()
1738 static int cas_abnormal_irq(struct net_device *dev, struct cas *cp, in cas_abnormal_irq() argument
1743 netif_printk(cp, rx_err, KERN_DEBUG, cp->dev, in cas_abnormal_irq()
1745 spin_lock(&cp->stat_lock[0]); in cas_abnormal_irq()
1746 cp->net_stats[0].rx_errors++; in cas_abnormal_irq()
1747 spin_unlock(&cp->stat_lock[0]); in cas_abnormal_irq()
1753 netif_printk(cp, rx_err, KERN_DEBUG, cp->dev, in cas_abnormal_irq()
1755 spin_lock(&cp->stat_lock[0]); in cas_abnormal_irq()
1756 cp->net_stats[0].rx_errors++; in cas_abnormal_irq()
1757 spin_unlock(&cp->stat_lock[0]); in cas_abnormal_irq()
1762 if (cas_pcs_interrupt(dev, cp, status)) in cas_abnormal_irq()
1767 if (cas_txmac_interrupt(dev, cp, status)) in cas_abnormal_irq()
1772 if (cas_rxmac_interrupt(dev, cp, status)) in cas_abnormal_irq()
1777 if (cas_mac_interrupt(dev, cp, status)) in cas_abnormal_irq()
1782 if (cas_mif_interrupt(dev, cp, status)) in cas_abnormal_irq()
1787 if (cas_pci_interrupt(dev, cp, status)) in cas_abnormal_irq()
1794 atomic_inc(&cp->reset_task_pending); in cas_abnormal_irq()
1795 atomic_inc(&cp->reset_task_pending_all); in cas_abnormal_irq()
1797 schedule_work(&cp->reset_task); in cas_abnormal_irq()
1799 atomic_set(&cp->reset_task_pending, CAS_RESET_ALL); in cas_abnormal_irq()
1801 schedule_work(&cp->reset_task); in cas_abnormal_irq()
1811 static inline int cas_calc_tabort(struct cas *cp, const unsigned long addr, in cas_calc_tabort() argument
1816 if (CAS_TABORT(cp) == 1) in cas_calc_tabort()
1823 static inline void cas_tx_ringN(struct cas *cp, int ring, int limit) in cas_tx_ringN() argument
1827 struct net_device *dev = cp->dev; in cas_tx_ringN()
1830 spin_lock(&cp->tx_lock[ring]); in cas_tx_ringN()
1831 txds = cp->init_txds[ring]; in cas_tx_ringN()
1832 skbs = cp->tx_skbs[ring]; in cas_tx_ringN()
1833 entry = cp->tx_old[ring]; in cas_tx_ringN()
1850 + cp->tx_tiny_use[ring][entry].nbufs + 1; in cas_tx_ringN()
1854 netif_printk(cp, tx_done, KERN_DEBUG, cp->dev, in cas_tx_ringN()
1858 cp->tx_tiny_use[ring][entry].nbufs = 0; in cas_tx_ringN()
1866 dma_unmap_page(&cp->pdev->dev, daddr, dlen, in cas_tx_ringN()
1871 if (cp->tx_tiny_use[ring][entry].used) { in cas_tx_ringN()
1872 cp->tx_tiny_use[ring][entry].used = 0; in cas_tx_ringN()
1877 spin_lock(&cp->stat_lock[ring]); in cas_tx_ringN()
1878 cp->net_stats[ring].tx_packets++; in cas_tx_ringN()
1879 cp->net_stats[ring].tx_bytes += skb->len; in cas_tx_ringN()
1880 spin_unlock(&cp->stat_lock[ring]); in cas_tx_ringN()
1883 cp->tx_old[ring] = entry; in cas_tx_ringN()
1890 (TX_BUFFS_AVAIL(cp, ring) > CAS_TABORT(cp)*(MAX_SKB_FRAGS + 1))) in cas_tx_ringN()
1892 spin_unlock(&cp->tx_lock[ring]); in cas_tx_ringN()
1895 static void cas_tx(struct net_device *dev, struct cas *cp, in cas_tx() argument
1900 u64 compwb = le64_to_cpu(cp->init_block->tx_compwb); in cas_tx()
1902 netif_printk(cp, intr, KERN_DEBUG, cp->dev, in cas_tx()
1913 limit = readl(cp->regs + REG_TX_COMPN(ring)); in cas_tx()
1915 if (cp->tx_old[ring] != limit) in cas_tx()
1916 cas_tx_ringN(cp, ring, limit); in cas_tx()
1921 static int cas_rx_process_pkt(struct cas *cp, struct cas_rx_comp *rxc, in cas_rx_process_pkt() argument
1942 skb = netdev_alloc_skb(cp->dev, alloclen + swivel + cp->crc_size); in cas_rx_process_pkt()
1953 page = cp->rx_pages[CAS_VAL(RX_INDEX_RING, i)][CAS_VAL(RX_INDEX_NUM, i)]; in cas_rx_process_pkt()
1959 i += cp->crc_size; in cas_rx_process_pkt()
1960 dma_sync_single_for_cpu(&cp->pdev->dev, page->dma_addr + off, in cas_rx_process_pkt()
1964 dma_sync_single_for_device(&cp->pdev->dev, in cas_rx_process_pkt()
1979 page = cp->rx_pages[CAS_VAL(RX_INDEX_RING, i)][CAS_VAL(RX_INDEX_NUM, i)]; in cas_rx_process_pkt()
1982 hlen = min(cp->page_size - off, dlen); in cas_rx_process_pkt()
1984 netif_printk(cp, rx_err, KERN_DEBUG, cp->dev, in cas_rx_process_pkt()
1991 i += cp->crc_size; in cas_rx_process_pkt()
1992 dma_sync_single_for_cpu(&cp->pdev->dev, page->dma_addr + off, in cas_rx_process_pkt()
2000 dma_sync_single_for_device(&cp->pdev->dev, in cas_rx_process_pkt()
2006 RX_USED_ADD(page, cp->mtu_stride); in cas_rx_process_pkt()
2028 page = cp->rx_pages[CAS_VAL(RX_INDEX_RING, i)][CAS_VAL(RX_INDEX_NUM, i)]; in cas_rx_process_pkt()
2029 dma_sync_single_for_cpu(&cp->pdev->dev, in cas_rx_process_pkt()
2031 hlen + cp->crc_size, in cas_rx_process_pkt()
2033 dma_sync_single_for_device(&cp->pdev->dev, in cas_rx_process_pkt()
2035 hlen + cp->crc_size, in cas_rx_process_pkt()
2047 RX_USED_ADD(page, hlen + cp->crc_size); in cas_rx_process_pkt()
2050 if (cp->crc_size) { in cas_rx_process_pkt()
2061 page = cp->rx_pages[CAS_VAL(RX_INDEX_RING, i)][CAS_VAL(RX_INDEX_NUM, i)]; in cas_rx_process_pkt()
2063 hlen = min(cp->page_size - off, dlen); in cas_rx_process_pkt()
2065 netif_printk(cp, rx_err, KERN_DEBUG, cp->dev, in cas_rx_process_pkt()
2072 i += cp->crc_size; in cas_rx_process_pkt()
2073 dma_sync_single_for_cpu(&cp->pdev->dev, page->dma_addr + off, in cas_rx_process_pkt()
2077 dma_sync_single_for_device(&cp->pdev->dev, in cas_rx_process_pkt()
2082 RX_USED_ADD(page, cp->mtu_stride); in cas_rx_process_pkt()
2090 page = cp->rx_pages[CAS_VAL(RX_INDEX_RING, i)][CAS_VAL(RX_INDEX_NUM, i)]; in cas_rx_process_pkt()
2091 dma_sync_single_for_cpu(&cp->pdev->dev, in cas_rx_process_pkt()
2093 dlen + cp->crc_size, in cas_rx_process_pkt()
2096 memcpy(p, addr, dlen + cp->crc_size); in cas_rx_process_pkt()
2097 dma_sync_single_for_device(&cp->pdev->dev, in cas_rx_process_pkt()
2099 dlen + cp->crc_size, in cas_rx_process_pkt()
2102 RX_USED_ADD(page, dlen + cp->crc_size); in cas_rx_process_pkt()
2105 if (cp->crc_size) { in cas_rx_process_pkt()
2113 if (cp->crc_size) { in cas_rx_process_pkt()
2115 csum = csum_fold(csum_partial(crcaddr, cp->crc_size, in cas_rx_process_pkt()
2120 skb->protocol = eth_type_trans(skb, cp->dev); in cas_rx_process_pkt()
2144 static inline void cas_rx_flow_pkt(struct cas *cp, const u64 *words, in cas_rx_flow_pkt() argument
2148 struct sk_buff_head *flow = &cp->rx_flows[flowid]; in cas_rx_flow_pkt()
2165 static void cas_post_page(struct cas *cp, const int ring, const int index) in cas_post_page() argument
2170 entry = cp->rx_old[ring]; in cas_post_page()
2172 new = cas_page_swap(cp, ring, index); in cas_post_page()
2173 cp->init_rxds[ring][entry].buffer = cpu_to_le64(new->dma_addr); in cas_post_page()
2174 cp->init_rxds[ring][entry].index = in cas_post_page()
2179 cp->rx_old[ring] = entry; in cas_post_page()
2185 writel(entry, cp->regs + REG_RX_KICK); in cas_post_page()
2187 (cp->cas_flags & CAS_FLAG_REG_PLUS)) in cas_post_page()
2188 writel(entry, cp->regs + REG_PLUS_RX_KICK1); in cas_post_page()
2193 static int cas_post_rxds_ringN(struct cas *cp, int ring, int num) in cas_post_rxds_ringN() argument
2197 cas_page_t **page = cp->rx_pages[ring]; in cas_post_rxds_ringN()
2199 entry = cp->rx_old[ring]; in cas_post_rxds_ringN()
2201 netif_printk(cp, intr, KERN_DEBUG, cp->dev, in cas_post_rxds_ringN()
2211 cas_page_t *new = cas_page_dequeue(cp); in cas_post_rxds_ringN()
2216 cp->cas_flags |= CAS_FLAG_RXD_POST(ring); in cas_post_rxds_ringN()
2217 if (!timer_pending(&cp->link_timer)) in cas_post_rxds_ringN()
2218 mod_timer(&cp->link_timer, jiffies + in cas_post_rxds_ringN()
2220 cp->rx_old[ring] = entry; in cas_post_rxds_ringN()
2221 cp->rx_last[ring] = num ? num - released : 0; in cas_post_rxds_ringN()
2224 spin_lock(&cp->rx_inuse_lock); in cas_post_rxds_ringN()
2225 list_add(&page[entry]->list, &cp->rx_inuse_list); in cas_post_rxds_ringN()
2226 spin_unlock(&cp->rx_inuse_lock); in cas_post_rxds_ringN()
2227 cp->init_rxds[ring][entry].buffer = in cas_post_rxds_ringN()
2240 cp->rx_old[ring] = entry; in cas_post_rxds_ringN()
2246 writel(cluster, cp->regs + REG_RX_KICK); in cas_post_rxds_ringN()
2248 (cp->cas_flags & CAS_FLAG_REG_PLUS)) in cas_post_rxds_ringN()
2249 writel(cluster, cp->regs + REG_PLUS_RX_KICK1); in cas_post_rxds_ringN()
2266 static int cas_rx_ringN(struct cas *cp, int ring, int budget) in cas_rx_ringN() argument
2268 struct cas_rx_comp *rxcs = cp->init_rxcs[ring]; in cas_rx_ringN()
2272 netif_printk(cp, intr, KERN_DEBUG, cp->dev, in cas_rx_ringN()
2275 readl(cp->regs + REG_RX_COMP_HEAD), cp->rx_new[ring]); in cas_rx_ringN()
2277 entry = cp->rx_new[ring]; in cas_rx_ringN()
2303 spin_lock(&cp->stat_lock[ring]); in cas_rx_ringN()
2304 cp->net_stats[ring].rx_errors++; in cas_rx_ringN()
2306 cp->net_stats[ring].rx_length_errors++; in cas_rx_ringN()
2308 cp->net_stats[ring].rx_crc_errors++; in cas_rx_ringN()
2309 spin_unlock(&cp->stat_lock[ring]); in cas_rx_ringN()
2313 spin_lock(&cp->stat_lock[ring]); in cas_rx_ringN()
2314 ++cp->net_stats[ring].rx_dropped; in cas_rx_ringN()
2315 spin_unlock(&cp->stat_lock[ring]); in cas_rx_ringN()
2319 len = cas_rx_process_pkt(cp, rxc, entry, words, &skb); in cas_rx_ringN()
2332 cas_rx_flow_pkt(cp, words, skb); in cas_rx_ringN()
2335 spin_lock(&cp->stat_lock[ring]); in cas_rx_ringN()
2336 cp->net_stats[ring].rx_packets++; in cas_rx_ringN()
2337 cp->net_stats[ring].rx_bytes += len; in cas_rx_ringN()
2338 spin_unlock(&cp->stat_lock[ring]); in cas_rx_ringN()
2348 cas_post_page(cp, dring, i); in cas_rx_ringN()
2355 cas_post_page(cp, dring, i); in cas_rx_ringN()
2362 cas_post_page(cp, dring, i); in cas_rx_ringN()
2373 cp->rx_new[ring] = entry; in cas_rx_ringN()
2376 netdev_info(cp->dev, "Memory squeeze, deferring packet\n"); in cas_rx_ringN()
2383 struct cas *cp, int ring) in cas_post_rxcs_ringN() argument
2385 struct cas_rx_comp *rxc = cp->init_rxcs[ring]; in cas_post_rxcs_ringN()
2388 last = cp->rx_cur[ring]; in cas_post_rxcs_ringN()
2389 entry = cp->rx_new[ring]; in cas_post_rxcs_ringN()
2390 netif_printk(cp, intr, KERN_DEBUG, dev, in cas_post_rxcs_ringN()
2392 ring, readl(cp->regs + REG_RX_COMP_HEAD), entry); in cas_post_rxcs_ringN()
2399 cp->rx_cur[ring] = last; in cas_post_rxcs_ringN()
2402 writel(last, cp->regs + REG_RX_COMP_TAIL); in cas_post_rxcs_ringN()
2403 else if (cp->cas_flags & CAS_FLAG_REG_PLUS) in cas_post_rxcs_ringN()
2404 writel(last, cp->regs + REG_PLUS_RX_COMPN_TAIL(ring)); in cas_post_rxcs_ringN()
2414 struct cas *cp, const u32 status, in cas_handle_irqN() argument
2418 cas_post_rxcs_ringN(dev, cp, ring); in cas_handle_irqN()
2424 struct cas *cp = netdev_priv(dev); in cas_interruptN() local
2426 int ring = (irq == cp->pci_irq_INTC) ? 2 : 3; in cas_interruptN()
2427 u32 status = readl(cp->regs + REG_PLUS_INTRN_STATUS(ring)); in cas_interruptN()
2433 spin_lock_irqsave(&cp->lock, flags); in cas_interruptN()
2436 cas_mask_intr(cp); in cas_interruptN()
2437 napi_schedule(&cp->napi); in cas_interruptN()
2439 cas_rx_ringN(cp, ring, 0); in cas_interruptN()
2445 cas_handle_irqN(dev, cp, status, ring); in cas_interruptN()
2446 spin_unlock_irqrestore(&cp->lock, flags); in cas_interruptN()
2453 static inline void cas_handle_irq1(struct cas *cp, const u32 status) in cas_handle_irq1() argument
2458 cas_post_rxds_ringN(cp, 1, 0); in cas_handle_irq1()
2459 spin_lock(&cp->stat_lock[1]); in cas_handle_irq1()
2460 cp->net_stats[1].rx_dropped++; in cas_handle_irq1()
2461 spin_unlock(&cp->stat_lock[1]); in cas_handle_irq1()
2465 cas_post_rxds_ringN(cp, 1, RX_DESC_RINGN_SIZE(1) - in cas_handle_irq1()
2469 cas_post_rxcs_ringN(cp, 1); in cas_handle_irq1()
2476 struct cas *cp = netdev_priv(dev); in cas_interrupt1() local
2478 u32 status = readl(cp->regs + REG_PLUS_INTRN_STATUS(1)); in cas_interrupt1()
2484 spin_lock_irqsave(&cp->lock, flags); in cas_interrupt1()
2487 cas_mask_intr(cp); in cas_interrupt1()
2488 napi_schedule(&cp->napi); in cas_interrupt1()
2490 cas_rx_ringN(cp, 1, 0); in cas_interrupt1()
2495 cas_handle_irq1(cp, status); in cas_interrupt1()
2496 spin_unlock_irqrestore(&cp->lock, flags); in cas_interrupt1()
2502 struct cas *cp, const u32 status) in cas_handle_irq() argument
2506 cas_abnormal_irq(dev, cp, status); in cas_handle_irq()
2512 cas_post_rxds_ringN(cp, 0, 0); in cas_handle_irq()
2513 spin_lock(&cp->stat_lock[0]); in cas_handle_irq()
2514 cp->net_stats[0].rx_dropped++; in cas_handle_irq()
2515 spin_unlock(&cp->stat_lock[0]); in cas_handle_irq()
2517 cas_post_rxds_ringN(cp, 0, RX_DESC_RINGN_SIZE(0) - in cas_handle_irq()
2522 cas_post_rxcs_ringN(dev, cp, 0); in cas_handle_irq()
2528 struct cas *cp = netdev_priv(dev); in cas_interrupt() local
2530 u32 status = readl(cp->regs + REG_INTR_STATUS); in cas_interrupt()
2535 spin_lock_irqsave(&cp->lock, flags); in cas_interrupt()
2537 cas_tx(dev, cp, status); in cas_interrupt()
2543 cas_mask_intr(cp); in cas_interrupt()
2544 napi_schedule(&cp->napi); in cas_interrupt()
2546 cas_rx_ringN(cp, 0, 0); in cas_interrupt()
2552 cas_handle_irq(dev, cp, status); in cas_interrupt()
2553 spin_unlock_irqrestore(&cp->lock, flags); in cas_interrupt()
2561 struct cas *cp = container_of(napi, struct cas, napi); in cas_poll() local
2562 struct net_device *dev = cp->dev; in cas_poll()
2564 u32 status = readl(cp->regs + REG_INTR_STATUS); in cas_poll()
2567 spin_lock_irqsave(&cp->lock, flags); in cas_poll()
2568 cas_tx(dev, cp, status); in cas_poll()
2569 spin_unlock_irqrestore(&cp->lock, flags); in cas_poll()
2583 credits += cas_rx_ringN(cp, j, budget / N_RX_COMP_RINGS); in cas_poll()
2593 spin_lock_irqsave(&cp->lock, flags); in cas_poll()
2595 cas_handle_irq(dev, cp, status); in cas_poll()
2599 status = readl(cp->regs + REG_PLUS_INTRN_STATUS(1)); in cas_poll()
2601 cas_handle_irq1(dev, cp, status); in cas_poll()
2607 status = readl(cp->regs + REG_PLUS_INTRN_STATUS(2)); in cas_poll()
2609 cas_handle_irqN(dev, cp, status, 2); in cas_poll()
2615 status = readl(cp->regs + REG_PLUS_INTRN_STATUS(3)); in cas_poll()
2617 cas_handle_irqN(dev, cp, status, 3); in cas_poll()
2620 spin_unlock_irqrestore(&cp->lock, flags); in cas_poll()
2623 cas_unmask_intr(cp); in cas_poll()
2632 struct cas *cp = netdev_priv(dev); in cas_netpoll() local
2634 cas_disable_irq(cp, 0); in cas_netpoll()
2635 cas_interrupt(cp->pdev->irq, dev); in cas_netpoll()
2636 cas_enable_irq(cp, 0); in cas_netpoll()
2658 struct cas *cp = netdev_priv(dev); in cas_tx_timeout() local
2661 if (!cp->hw_running) { in cas_tx_timeout()
2667 readl(cp->regs + REG_MIF_STATE_MACHINE)); in cas_tx_timeout()
2670 readl(cp->regs + REG_MAC_STATE_MACHINE)); in cas_tx_timeout()
2673 readl(cp->regs + REG_TX_CFG), in cas_tx_timeout()
2674 readl(cp->regs + REG_MAC_TX_STATUS), in cas_tx_timeout()
2675 readl(cp->regs + REG_MAC_TX_CFG), in cas_tx_timeout()
2676 readl(cp->regs + REG_TX_FIFO_PKT_CNT), in cas_tx_timeout()
2677 readl(cp->regs + REG_TX_FIFO_WRITE_PTR), in cas_tx_timeout()
2678 readl(cp->regs + REG_TX_FIFO_READ_PTR), in cas_tx_timeout()
2679 readl(cp->regs + REG_TX_SM_1), in cas_tx_timeout()
2680 readl(cp->regs + REG_TX_SM_2)); in cas_tx_timeout()
2683 readl(cp->regs + REG_RX_CFG), in cas_tx_timeout()
2684 readl(cp->regs + REG_MAC_RX_STATUS), in cas_tx_timeout()
2685 readl(cp->regs + REG_MAC_RX_CFG)); in cas_tx_timeout()
2688 readl(cp->regs + REG_HP_STATE_MACHINE), in cas_tx_timeout()
2689 readl(cp->regs + REG_HP_STATUS0), in cas_tx_timeout()
2690 readl(cp->regs + REG_HP_STATUS1), in cas_tx_timeout()
2691 readl(cp->regs + REG_HP_STATUS2)); in cas_tx_timeout()
2694 atomic_inc(&cp->reset_task_pending); in cas_tx_timeout()
2695 atomic_inc(&cp->reset_task_pending_all); in cas_tx_timeout()
2696 schedule_work(&cp->reset_task); in cas_tx_timeout()
2698 atomic_set(&cp->reset_task_pending, CAS_RESET_ALL); in cas_tx_timeout()
2699 schedule_work(&cp->reset_task); in cas_tx_timeout()
2712 static void cas_write_txd(struct cas *cp, int ring, int entry, in cas_write_txd() argument
2715 struct cas_tx_desc *txd = cp->init_txds[ring] + entry; in cas_write_txd()
2726 static inline void *tx_tiny_buf(struct cas *cp, const int ring, in tx_tiny_buf() argument
2729 return cp->tx_tiny_bufs[ring] + TX_TINY_BUF_LEN*entry; in tx_tiny_buf()
2732 static inline dma_addr_t tx_tiny_map(struct cas *cp, const int ring, in tx_tiny_map() argument
2735 cp->tx_tiny_use[ring][tentry].nbufs++; in tx_tiny_map()
2736 cp->tx_tiny_use[ring][entry].used = 1; in tx_tiny_map()
2737 return cp->tx_tiny_dvma[ring] + TX_TINY_BUF_LEN*entry; in tx_tiny_map()
2740 static inline int cas_xmit_tx_ringN(struct cas *cp, int ring, in cas_xmit_tx_ringN() argument
2743 struct net_device *dev = cp->dev; in cas_xmit_tx_ringN()
2750 spin_lock_irqsave(&cp->tx_lock[ring], flags); in cas_xmit_tx_ringN()
2753 if (TX_BUFFS_AVAIL(cp, ring) <= in cas_xmit_tx_ringN()
2754 CAS_TABORT(cp)*(skb_shinfo(skb)->nr_frags + 1)) { in cas_xmit_tx_ringN()
2756 spin_unlock_irqrestore(&cp->tx_lock[ring], flags); in cas_xmit_tx_ringN()
2771 entry = cp->tx_new[ring]; in cas_xmit_tx_ringN()
2772 cp->tx_skbs[ring][entry] = skb; in cas_xmit_tx_ringN()
2776 mapping = dma_map_page(&cp->pdev->dev, virt_to_page(skb->data), in cas_xmit_tx_ringN()
2780 tabort = cas_calc_tabort(cp, (unsigned long) skb->data, len); in cas_xmit_tx_ringN()
2783 cas_write_txd(cp, ring, entry, mapping, len - tabort, in cas_xmit_tx_ringN()
2788 tx_tiny_buf(cp, ring, entry), tabort); in cas_xmit_tx_ringN()
2789 mapping = tx_tiny_map(cp, ring, entry, tentry); in cas_xmit_tx_ringN()
2790 cas_write_txd(cp, ring, entry, mapping, tabort, ctrl, in cas_xmit_tx_ringN()
2793 cas_write_txd(cp, ring, entry, mapping, len, ctrl | in cas_xmit_tx_ringN()
2802 mapping = skb_frag_dma_map(&cp->pdev->dev, fragp, 0, len, in cas_xmit_tx_ringN()
2805 tabort = cas_calc_tabort(cp, skb_frag_off(fragp), len); in cas_xmit_tx_ringN()
2810 cas_write_txd(cp, ring, entry, mapping, len - tabort, in cas_xmit_tx_ringN()
2815 memcpy(tx_tiny_buf(cp, ring, entry), in cas_xmit_tx_ringN()
2819 mapping = tx_tiny_map(cp, ring, entry, tentry); in cas_xmit_tx_ringN()
2823 cas_write_txd(cp, ring, entry, mapping, len, ctrl, in cas_xmit_tx_ringN()
2828 cp->tx_new[ring] = entry; in cas_xmit_tx_ringN()
2829 if (TX_BUFFS_AVAIL(cp, ring) <= CAS_TABORT(cp)*(MAX_SKB_FRAGS + 1)) in cas_xmit_tx_ringN()
2832 netif_printk(cp, tx_queued, KERN_DEBUG, dev, in cas_xmit_tx_ringN()
2834 ring, entry, skb->len, TX_BUFFS_AVAIL(cp, ring)); in cas_xmit_tx_ringN()
2835 writel(entry, cp->regs + REG_TX_KICKN(ring)); in cas_xmit_tx_ringN()
2836 spin_unlock_irqrestore(&cp->tx_lock[ring], flags); in cas_xmit_tx_ringN()
2842 struct cas *cp = netdev_priv(dev); in cas_start_xmit() local
2849 if (skb_padto(skb, cp->min_frame_size)) in cas_start_xmit()
2855 if (cas_xmit_tx_ringN(cp, ring++ & N_TX_RINGS_MASK, skb)) in cas_start_xmit()
2860 static void cas_init_tx_dma(struct cas *cp) in cas_init_tx_dma() argument
2862 u64 desc_dma = cp->block_dvma; in cas_init_tx_dma()
2870 writel((desc_dma + off) >> 32, cp->regs + REG_TX_COMPWB_DB_HI); in cas_init_tx_dma()
2871 writel((desc_dma + off) & 0xffffffff, cp->regs + REG_TX_COMPWB_DB_LOW); in cas_init_tx_dma()
2884 off = (unsigned long) cp->init_txds[i] - in cas_init_tx_dma()
2885 (unsigned long) cp->init_block; in cas_init_tx_dma()
2888 writel((desc_dma + off) >> 32, cp->regs + REG_TX_DBN_HI(i)); in cas_init_tx_dma()
2889 writel((desc_dma + off) & 0xffffffff, cp->regs + in cas_init_tx_dma()
2895 writel(val, cp->regs + REG_TX_CFG); in cas_init_tx_dma()
2901 writel(0x800, cp->regs + REG_TX_MAXBURST_0); in cas_init_tx_dma()
2902 writel(0x1600, cp->regs + REG_TX_MAXBURST_1); in cas_init_tx_dma()
2903 writel(0x2400, cp->regs + REG_TX_MAXBURST_2); in cas_init_tx_dma()
2904 writel(0x4800, cp->regs + REG_TX_MAXBURST_3); in cas_init_tx_dma()
2906 writel(0x800, cp->regs + REG_TX_MAXBURST_0); in cas_init_tx_dma()
2907 writel(0x800, cp->regs + REG_TX_MAXBURST_1); in cas_init_tx_dma()
2908 writel(0x800, cp->regs + REG_TX_MAXBURST_2); in cas_init_tx_dma()
2909 writel(0x800, cp->regs + REG_TX_MAXBURST_3); in cas_init_tx_dma()
2913 /* Must be invoked under cp->lock. */
2914 static inline void cas_init_dma(struct cas *cp) in cas_init_dma() argument
2916 cas_init_tx_dma(cp); in cas_init_dma()
2917 cas_init_rx_dma(cp); in cas_init_dma()
2920 static void cas_process_mc_list(struct cas *cp) in cas_process_mc_list() argument
2928 netdev_for_each_mc_addr(ha, cp->dev) { in cas_process_mc_list()
2934 cp->regs + REG_MAC_ADDRN(i*3 + 0)); in cas_process_mc_list()
2936 cp->regs + REG_MAC_ADDRN(i*3 + 1)); in cas_process_mc_list()
2938 cp->regs + REG_MAC_ADDRN(i*3 + 2)); in cas_process_mc_list()
2951 writel(hash_table[i], cp->regs + REG_MAC_HASH_TABLEN(i)); in cas_process_mc_list()
2954 /* Must be invoked under cp->lock. */
2955 static u32 cas_setup_multicast(struct cas *cp) in cas_setup_multicast() argument
2960 if (cp->dev->flags & IFF_PROMISC) { in cas_setup_multicast()
2963 } else if (cp->dev->flags & IFF_ALLMULTI) { in cas_setup_multicast()
2965 writel(0xFFFF, cp->regs + REG_MAC_HASH_TABLEN(i)); in cas_setup_multicast()
2969 cas_process_mc_list(cp); in cas_setup_multicast()
2976 /* must be invoked under cp->stat_lock[N_TX_RINGS] */
2977 static void cas_clear_mac_err(struct cas *cp) in cas_clear_mac_err() argument
2979 writel(0, cp->regs + REG_MAC_COLL_NORMAL); in cas_clear_mac_err()
2980 writel(0, cp->regs + REG_MAC_COLL_FIRST); in cas_clear_mac_err()
2981 writel(0, cp->regs + REG_MAC_COLL_EXCESS); in cas_clear_mac_err()
2982 writel(0, cp->regs + REG_MAC_COLL_LATE); in cas_clear_mac_err()
2983 writel(0, cp->regs + REG_MAC_TIMER_DEFER); in cas_clear_mac_err()
2984 writel(0, cp->regs + REG_MAC_ATTEMPTS_PEAK); in cas_clear_mac_err()
2985 writel(0, cp->regs + REG_MAC_RECV_FRAME); in cas_clear_mac_err()
2986 writel(0, cp->regs + REG_MAC_LEN_ERR); in cas_clear_mac_err()
2987 writel(0, cp->regs + REG_MAC_ALIGN_ERR); in cas_clear_mac_err()
2988 writel(0, cp->regs + REG_MAC_FCS_ERR); in cas_clear_mac_err()
2989 writel(0, cp->regs + REG_MAC_RX_CODE_ERR); in cas_clear_mac_err()
2993 static void cas_mac_reset(struct cas *cp) in cas_mac_reset() argument
2998 writel(0x1, cp->regs + REG_MAC_TX_RESET); in cas_mac_reset()
2999 writel(0x1, cp->regs + REG_MAC_RX_RESET); in cas_mac_reset()
3004 if (readl(cp->regs + REG_MAC_TX_RESET) == 0) in cas_mac_reset()
3012 if (readl(cp->regs + REG_MAC_RX_RESET) == 0) in cas_mac_reset()
3017 if (readl(cp->regs + REG_MAC_TX_RESET) | in cas_mac_reset()
3018 readl(cp->regs + REG_MAC_RX_RESET)) in cas_mac_reset()
3019 netdev_err(cp->dev, "mac tx[%d]/rx[%d] reset failed [%08x]\n", in cas_mac_reset()
3020 readl(cp->regs + REG_MAC_TX_RESET), in cas_mac_reset()
3021 readl(cp->regs + REG_MAC_RX_RESET), in cas_mac_reset()
3022 readl(cp->regs + REG_MAC_STATE_MACHINE)); in cas_mac_reset()
3026 /* Must be invoked under cp->lock. */
3027 static void cas_init_mac(struct cas *cp) in cas_init_mac() argument
3029 unsigned char *e = &cp->dev->dev_addr[0]; in cas_init_mac()
3031 cas_mac_reset(cp); in cas_init_mac()
3034 writel(CAWR_RR_DIS, cp->regs + REG_CAWR); in cas_init_mac()
3040 if ((cp->cas_flags & CAS_FLAG_TARGET_ABORT) == 0) in cas_init_mac()
3041 writel(INF_BURST_EN, cp->regs + REG_INF_BURST); in cas_init_mac()
3044 writel(0x1BF0, cp->regs + REG_MAC_SEND_PAUSE); in cas_init_mac()
3046 writel(0x00, cp->regs + REG_MAC_IPG0); in cas_init_mac()
3047 writel(0x08, cp->regs + REG_MAC_IPG1); in cas_init_mac()
3048 writel(0x04, cp->regs + REG_MAC_IPG2); in cas_init_mac()
3051 writel(0x40, cp->regs + REG_MAC_SLOT_TIME); in cas_init_mac()
3054 writel(ETH_ZLEN + 4, cp->regs + REG_MAC_FRAMESIZE_MIN); in cas_init_mac()
3063 cp->regs + REG_MAC_FRAMESIZE_MAX); in cas_init_mac()
3069 if ((cp->cas_flags & CAS_FLAG_SATURN) && cp->crc_size) in cas_init_mac()
3070 writel(0x41, cp->regs + REG_MAC_PA_SIZE); in cas_init_mac()
3072 writel(0x07, cp->regs + REG_MAC_PA_SIZE); in cas_init_mac()
3073 writel(0x04, cp->regs + REG_MAC_JAM_SIZE); in cas_init_mac()
3074 writel(0x10, cp->regs + REG_MAC_ATTEMPT_LIMIT); in cas_init_mac()
3075 writel(0x8808, cp->regs + REG_MAC_CTRL_TYPE); in cas_init_mac()
3077 writel((e[5] | (e[4] << 8)) & 0x3ff, cp->regs + REG_MAC_RANDOM_SEED); in cas_init_mac()
3079 writel(0, cp->regs + REG_MAC_ADDR_FILTER0); in cas_init_mac()
3080 writel(0, cp->regs + REG_MAC_ADDR_FILTER1); in cas_init_mac()
3081 writel(0, cp->regs + REG_MAC_ADDR_FILTER2); in cas_init_mac()
3082 writel(0, cp->regs + REG_MAC_ADDR_FILTER2_1_MASK); in cas_init_mac()
3083 writel(0, cp->regs + REG_MAC_ADDR_FILTER0_MASK); in cas_init_mac()
3087 writel(0x0, cp->regs + REG_MAC_ADDRN(i)); in cas_init_mac()
3089 writel((e[4] << 8) | e[5], cp->regs + REG_MAC_ADDRN(0)); in cas_init_mac()
3090 writel((e[2] << 8) | e[3], cp->regs + REG_MAC_ADDRN(1)); in cas_init_mac()
3091 writel((e[0] << 8) | e[1], cp->regs + REG_MAC_ADDRN(2)); in cas_init_mac()
3093 writel(0x0001, cp->regs + REG_MAC_ADDRN(42)); in cas_init_mac()
3094 writel(0xc200, cp->regs + REG_MAC_ADDRN(43)); in cas_init_mac()
3095 writel(0x0180, cp->regs + REG_MAC_ADDRN(44)); in cas_init_mac()
3097 cp->mac_rx_cfg = cas_setup_multicast(cp); in cas_init_mac()
3099 spin_lock(&cp->stat_lock[N_TX_RINGS]); in cas_init_mac()
3100 cas_clear_mac_err(cp); in cas_init_mac()
3101 spin_unlock(&cp->stat_lock[N_TX_RINGS]); in cas_init_mac()
3107 writel(MAC_TX_FRAME_XMIT, cp->regs + REG_MAC_TX_MASK); in cas_init_mac()
3108 writel(MAC_RX_FRAME_RECV, cp->regs + REG_MAC_RX_MASK); in cas_init_mac()
3113 writel(0xffffffff, cp->regs + REG_MAC_CTRL_MASK); in cas_init_mac()
3116 /* Must be invoked under cp->lock. */
3117 static void cas_init_pause_thresholds(struct cas *cp) in cas_init_pause_thresholds() argument
3122 if (cp->rx_fifo_size <= (2 * 1024)) { in cas_init_pause_thresholds()
3123 cp->rx_pause_off = cp->rx_pause_on = cp->rx_fifo_size; in cas_init_pause_thresholds()
3125 int max_frame = (cp->dev->mtu + ETH_HLEN + 4 + 4 + 64) & ~63; in cas_init_pause_thresholds()
3126 if (max_frame * 3 > cp->rx_fifo_size) { in cas_init_pause_thresholds()
3127 cp->rx_pause_off = 7104; in cas_init_pause_thresholds()
3128 cp->rx_pause_on = 960; in cas_init_pause_thresholds()
3130 int off = (cp->rx_fifo_size - (max_frame * 2)); in cas_init_pause_thresholds()
3132 cp->rx_pause_off = off; in cas_init_pause_thresholds()
3133 cp->rx_pause_on = on; in cas_init_pause_thresholds()
3162 static int cas_get_vpd_info(struct cas *cp, unsigned char *dev_addr, in cas_get_vpd_info() argument
3165 void __iomem *p = cp->regs + REG_EXPANSION_ROM_RUN_START; in cas_get_vpd_info()
3181 cp->regs + REG_BIM_LOCAL_DEV_EN); in cas_get_vpd_info()
3286 cp->cas_flags |= CAS_FLAG_ENTROPY_DEV; in cas_get_vpd_info()
3327 addr = of_get_property(cp->of_node, "local-mac-address", NULL); in cas_get_vpd_info()
3342 writel(0, cp->regs + REG_BIM_LOCAL_DEV_EN); in cas_get_vpd_info()
3347 static void cas_check_pci_invariants(struct cas *cp) in cas_check_pci_invariants() argument
3349 struct pci_dev *pdev = cp->pdev; in cas_check_pci_invariants()
3351 cp->cas_flags = 0; in cas_check_pci_invariants()
3355 cp->cas_flags |= CAS_FLAG_REG_PLUS; in cas_check_pci_invariants()
3357 cp->cas_flags |= CAS_FLAG_TARGET_ABORT; in cas_check_pci_invariants()
3363 cp->cas_flags |= CAS_FLAG_NO_HW_CSUM; in cas_check_pci_invariants()
3366 cp->cas_flags |= CAS_FLAG_REG_PLUS; in cas_check_pci_invariants()
3373 cp->cas_flags |= CAS_FLAG_SATURN; in cas_check_pci_invariants()
3378 static int cas_check_invariants(struct cas *cp) in cas_check_invariants() argument
3380 struct pci_dev *pdev = cp->pdev; in cas_check_invariants()
3385 cp->page_order = 0; in cas_check_invariants()
3394 cp->page_order = CAS_JUMBO_PAGE_SHIFT - PAGE_SHIFT; in cas_check_invariants()
3400 cp->page_size = (PAGE_SIZE << cp->page_order); in cas_check_invariants()
3403 cp->tx_fifo_size = readl(cp->regs + REG_TX_FIFO_SIZE) * 64; in cas_check_invariants()
3404 cp->rx_fifo_size = RX_FIFO_SIZE; in cas_check_invariants()
3409 cp->phy_type = cas_get_vpd_info(cp, cp->dev->dev_addr, in cas_check_invariants()
3411 if (cp->phy_type & CAS_PHY_SERDES) { in cas_check_invariants()
3412 cp->cas_flags |= CAS_FLAG_1000MB_CAP; in cas_check_invariants()
3417 cfg = readl(cp->regs + REG_MIF_CFG); in cas_check_invariants()
3419 cp->phy_type = CAS_PHY_MII_MDIO1; in cas_check_invariants()
3421 cp->phy_type = CAS_PHY_MII_MDIO0; in cas_check_invariants()
3424 cas_mif_poll(cp, 0); in cas_check_invariants()
3425 writel(PCS_DATAPATH_MODE_MII, cp->regs + REG_PCS_DATAPATH_MODE); in cas_check_invariants()
3432 cp->phy_addr = i; in cas_check_invariants()
3433 phy_id = cas_phy_read(cp, MII_PHYSID1) << 16; in cas_check_invariants()
3434 phy_id |= cas_phy_read(cp, MII_PHYSID2); in cas_check_invariants()
3436 cp->phy_id = phy_id; in cas_check_invariants()
3442 readl(cp->regs + REG_MIF_STATE_MACHINE)); in cas_check_invariants()
3447 cfg = cas_phy_read(cp, MII_BMSR); in cas_check_invariants()
3449 cas_phy_read(cp, CAS_MII_1000_EXTEND)) in cas_check_invariants()
3450 cp->cas_flags |= CAS_FLAG_1000MB_CAP; in cas_check_invariants()
3454 /* Must be invoked under cp->lock. */
3455 static inline void cas_start_dma(struct cas *cp) in cas_start_dma() argument
3462 val = readl(cp->regs + REG_TX_CFG) | TX_CFG_DMA_EN; in cas_start_dma()
3463 writel(val, cp->regs + REG_TX_CFG); in cas_start_dma()
3464 val = readl(cp->regs + REG_RX_CFG) | RX_CFG_DMA_EN; in cas_start_dma()
3465 writel(val, cp->regs + REG_RX_CFG); in cas_start_dma()
3468 val = readl(cp->regs + REG_MAC_TX_CFG) | MAC_TX_CFG_EN; in cas_start_dma()
3469 writel(val, cp->regs + REG_MAC_TX_CFG); in cas_start_dma()
3470 val = readl(cp->regs + REG_MAC_RX_CFG) | MAC_RX_CFG_EN; in cas_start_dma()
3471 writel(val, cp->regs + REG_MAC_RX_CFG); in cas_start_dma()
3475 val = readl(cp->regs + REG_MAC_TX_CFG); in cas_start_dma()
3483 val = readl(cp->regs + REG_MAC_RX_CFG); in cas_start_dma()
3486 netdev_err(cp->dev, in cas_start_dma()
3488 readl(cp->regs + REG_MIF_STATE_MACHINE), in cas_start_dma()
3489 readl(cp->regs + REG_MAC_STATE_MACHINE)); in cas_start_dma()
3495 netdev_err(cp->dev, "enabling mac failed [%s:%08x:%08x]\n", in cas_start_dma()
3497 readl(cp->regs + REG_MIF_STATE_MACHINE), in cas_start_dma()
3498 readl(cp->regs + REG_MAC_STATE_MACHINE)); in cas_start_dma()
3501 cas_unmask_intr(cp); /* enable interrupts */ in cas_start_dma()
3502 writel(RX_DESC_RINGN_SIZE(0) - 4, cp->regs + REG_RX_KICK); in cas_start_dma()
3503 writel(0, cp->regs + REG_RX_COMP_TAIL); in cas_start_dma()
3505 if (cp->cas_flags & CAS_FLAG_REG_PLUS) { in cas_start_dma()
3508 cp->regs + REG_PLUS_RX_KICK1); in cas_start_dma()
3511 writel(0, cp->regs + REG_PLUS_RX_COMPN_TAIL(i)); in cas_start_dma()
3515 /* Must be invoked under cp->lock. */
3516 static void cas_read_pcs_link_mode(struct cas *cp, int *fd, int *spd, in cas_read_pcs_link_mode() argument
3519 u32 val = readl(cp->regs + REG_PCS_MII_LPA); in cas_read_pcs_link_mode()
3527 /* Must be invoked under cp->lock. */
3528 static void cas_read_mii_link_mode(struct cas *cp, int *fd, int *spd, in cas_read_mii_link_mode() argument
3538 val = cas_phy_read(cp, MII_LPA); in cas_read_mii_link_mode()
3550 if (cp->cas_flags & CAS_FLAG_1000MB_CAP) { in cas_read_mii_link_mode()
3551 val = cas_phy_read(cp, CAS_MII_1000_STATUS); in cas_read_mii_link_mode()
3562 * Must be invoked under cp->lock.
3564 static void cas_set_link_modes(struct cas *cp) in cas_set_link_modes() argument
3573 if (CAS_PHY_MII(cp->phy_type)) { in cas_set_link_modes()
3574 cas_mif_poll(cp, 0); in cas_set_link_modes()
3575 val = cas_phy_read(cp, MII_BMCR); in cas_set_link_modes()
3577 cas_read_mii_link_mode(cp, &full_duplex, &speed, in cas_set_link_modes()
3586 speed = (cp->cas_flags & CAS_FLAG_1000MB_CAP) ? in cas_set_link_modes()
3589 cas_mif_poll(cp, 1); in cas_set_link_modes()
3592 val = readl(cp->regs + REG_PCS_MII_CTRL); in cas_set_link_modes()
3593 cas_read_pcs_link_mode(cp, &full_duplex, &speed, &pause); in cas_set_link_modes()
3600 netif_info(cp, link, cp->dev, "Link up at %d Mbps, %s-duplex\n", in cas_set_link_modes()
3604 if (CAS_PHY_MII(cp->phy_type)) { in cas_set_link_modes()
3613 writel(val, cp->regs + REG_MAC_XIF_CFG); in cas_set_link_modes()
3635 cp->regs + REG_MAC_TX_CFG); in cas_set_link_modes()
3637 val = readl(cp->regs + REG_MAC_RX_CFG); in cas_set_link_modes()
3640 cp->regs + REG_MAC_RX_CFG); in cas_set_link_modes()
3642 writel(0x200, cp->regs + REG_MAC_SLOT_TIME); in cas_set_link_modes()
3644 cp->crc_size = 4; in cas_set_link_modes()
3646 cp->min_frame_size = CAS_1000MB_MIN_FRAME; in cas_set_link_modes()
3649 writel(val, cp->regs + REG_MAC_TX_CFG); in cas_set_link_modes()
3654 val = readl(cp->regs + REG_MAC_RX_CFG); in cas_set_link_modes()
3657 cp->crc_size = 0; in cas_set_link_modes()
3658 cp->min_frame_size = CAS_MIN_MTU; in cas_set_link_modes()
3661 cp->crc_size = 4; in cas_set_link_modes()
3662 cp->min_frame_size = CAS_MIN_FRAME; in cas_set_link_modes()
3665 cp->regs + REG_MAC_RX_CFG); in cas_set_link_modes()
3666 writel(0x40, cp->regs + REG_MAC_SLOT_TIME); in cas_set_link_modes()
3669 if (netif_msg_link(cp)) { in cas_set_link_modes()
3671 netdev_info(cp->dev, "Pause is enabled (rxfifo: %d off: %d on: %d)\n", in cas_set_link_modes()
3672 cp->rx_fifo_size, in cas_set_link_modes()
3673 cp->rx_pause_off, in cas_set_link_modes()
3674 cp->rx_pause_on); in cas_set_link_modes()
3676 netdev_info(cp->dev, "TX pause enabled\n"); in cas_set_link_modes()
3678 netdev_info(cp->dev, "Pause is disabled\n"); in cas_set_link_modes()
3682 val = readl(cp->regs + REG_MAC_CTRL_CFG); in cas_set_link_modes()
3690 writel(val, cp->regs + REG_MAC_CTRL_CFG); in cas_set_link_modes()
3691 cas_start_dma(cp); in cas_set_link_modes()
3694 /* Must be invoked under cp->lock. */
3695 static void cas_init_hw(struct cas *cp, int restart_link) in cas_init_hw() argument
3698 cas_phy_init(cp); in cas_init_hw()
3700 cas_init_pause_thresholds(cp); in cas_init_hw()
3701 cas_init_mac(cp); in cas_init_hw()
3702 cas_init_dma(cp); in cas_init_hw()
3706 cp->timer_ticks = 0; in cas_init_hw()
3707 cas_begin_auto_negotiation(cp, NULL); in cas_init_hw()
3708 } else if (cp->lstate == link_up) { in cas_init_hw()
3709 cas_set_link_modes(cp); in cas_init_hw()
3710 netif_carrier_on(cp->dev); in cas_init_hw()
3714 /* Must be invoked under cp->lock. on earlier cassini boards,
3718 static void cas_hard_reset(struct cas *cp) in cas_hard_reset() argument
3720 writel(BIM_LOCAL_DEV_SOFT_0, cp->regs + REG_BIM_LOCAL_DEV_EN); in cas_hard_reset()
3722 pci_restore_state(cp->pdev); in cas_hard_reset()
3726 static void cas_global_reset(struct cas *cp, int blkflag) in cas_global_reset() argument
3731 if (blkflag && !CAS_PHY_MII(cp->phy_type)) { in cas_global_reset()
3739 cp->regs + REG_SW_RESET); in cas_global_reset()
3741 writel(SW_RESET_TX | SW_RESET_RX, cp->regs + REG_SW_RESET); in cas_global_reset()
3749 u32 val = readl(cp->regs + REG_SW_RESET); in cas_global_reset()
3754 netdev_err(cp->dev, "sw reset failed\n"); in cas_global_reset()
3759 BIM_CFG_RTA_INTR_ENABLE, cp->regs + REG_BIM_CFG); in cas_global_reset()
3767 PCI_ERR_BIM_DMA_READ), cp->regs + in cas_global_reset()
3773 writel(PCS_DATAPATH_MODE_MII, cp->regs + REG_PCS_DATAPATH_MODE); in cas_global_reset()
3776 static void cas_reset(struct cas *cp, int blkflag) in cas_reset() argument
3780 cas_mask_intr(cp); in cas_reset()
3781 cas_global_reset(cp, blkflag); in cas_reset()
3782 cas_mac_reset(cp); in cas_reset()
3783 cas_entropy_reset(cp); in cas_reset()
3786 val = readl(cp->regs + REG_TX_CFG); in cas_reset()
3788 writel(val, cp->regs + REG_TX_CFG); in cas_reset()
3790 val = readl(cp->regs + REG_RX_CFG); in cas_reset()
3792 writel(val, cp->regs + REG_RX_CFG); in cas_reset()
3795 if ((cp->cas_flags & CAS_FLAG_TARGET_ABORT) || in cas_reset()
3797 cas_load_firmware(cp, CAS_HP_FIRMWARE); in cas_reset()
3799 cas_load_firmware(cp, CAS_HP_ALT_FIRMWARE); in cas_reset()
3803 spin_lock(&cp->stat_lock[N_TX_RINGS]); in cas_reset()
3804 cas_clear_mac_err(cp); in cas_reset()
3805 spin_unlock(&cp->stat_lock[N_TX_RINGS]); in cas_reset()
3809 static void cas_shutdown(struct cas *cp) in cas_shutdown() argument
3814 cp->hw_running = 0; in cas_shutdown()
3816 del_timer_sync(&cp->link_timer); in cas_shutdown()
3820 while (atomic_read(&cp->reset_task_pending_mtu) || in cas_shutdown()
3821 atomic_read(&cp->reset_task_pending_spare) || in cas_shutdown()
3822 atomic_read(&cp->reset_task_pending_all)) in cas_shutdown()
3826 while (atomic_read(&cp->reset_task_pending)) in cas_shutdown()
3830 cas_lock_all_save(cp, flags); in cas_shutdown()
3831 cas_reset(cp, 0); in cas_shutdown()
3832 if (cp->cas_flags & CAS_FLAG_SATURN) in cas_shutdown()
3833 cas_phy_powerdown(cp); in cas_shutdown()
3834 cas_unlock_all_restore(cp, flags); in cas_shutdown()
3839 struct cas *cp = netdev_priv(dev); in cas_change_mtu() local
3847 atomic_inc(&cp->reset_task_pending); in cas_change_mtu()
3848 if ((cp->phy_type & CAS_PHY_SERDES)) { in cas_change_mtu()
3849 atomic_inc(&cp->reset_task_pending_all); in cas_change_mtu()
3851 atomic_inc(&cp->reset_task_pending_mtu); in cas_change_mtu()
3853 schedule_work(&cp->reset_task); in cas_change_mtu()
3855 atomic_set(&cp->reset_task_pending, (cp->phy_type & CAS_PHY_SERDES) ? in cas_change_mtu()
3858 schedule_work(&cp->reset_task); in cas_change_mtu()
3861 flush_work(&cp->reset_task); in cas_change_mtu()
3865 static void cas_clean_txd(struct cas *cp, int ring) in cas_clean_txd() argument
3867 struct cas_tx_desc *txd = cp->init_txds[ring]; in cas_clean_txd()
3868 struct sk_buff *skb, **skbs = cp->tx_skbs[ring]; in cas_clean_txd()
3891 dma_unmap_page(&cp->pdev->dev, daddr, dlen, in cas_clean_txd()
3901 if (cp->tx_tiny_use[ring][ent].used) in cas_clean_txd()
3909 memset(cp->tx_tiny_use[ring], 0, size*sizeof(*cp->tx_tiny_use[ring])); in cas_clean_txd()
3913 static inline void cas_free_rx_desc(struct cas *cp, int ring) in cas_free_rx_desc() argument
3915 cas_page_t **page = cp->rx_pages[ring]; in cas_free_rx_desc()
3921 cas_page_free(cp, page[i]); in cas_free_rx_desc()
3927 static void cas_free_rxds(struct cas *cp) in cas_free_rxds() argument
3932 cas_free_rx_desc(cp, i); in cas_free_rxds()
3935 /* Must be invoked under cp->lock. */
3936 static void cas_clean_rings(struct cas *cp) in cas_clean_rings() argument
3941 memset(cp->tx_old, 0, sizeof(*cp->tx_old)*N_TX_RINGS); in cas_clean_rings()
3942 memset(cp->tx_new, 0, sizeof(*cp->tx_new)*N_TX_RINGS); in cas_clean_rings()
3944 cas_clean_txd(cp, i); in cas_clean_rings()
3947 memset(cp->init_block, 0, sizeof(struct cas_init_block)); in cas_clean_rings()
3948 cas_clean_rxds(cp); in cas_clean_rings()
3949 cas_clean_rxcs(cp); in cas_clean_rings()
3953 static inline int cas_alloc_rx_desc(struct cas *cp, int ring) in cas_alloc_rx_desc() argument
3955 cas_page_t **page = cp->rx_pages[ring]; in cas_alloc_rx_desc()
3960 if ((page[i] = cas_page_alloc(cp, GFP_KERNEL)) == NULL) in cas_alloc_rx_desc()
3966 static int cas_alloc_rxds(struct cas *cp) in cas_alloc_rxds() argument
3971 if (cas_alloc_rx_desc(cp, i) < 0) { in cas_alloc_rxds()
3972 cas_free_rxds(cp); in cas_alloc_rxds()
3981 struct cas *cp = container_of(work, struct cas, reset_task); in cas_reset_task() local
3983 int pending = atomic_read(&cp->reset_task_pending); in cas_reset_task()
3985 int pending_all = atomic_read(&cp->reset_task_pending_all); in cas_reset_task()
3986 int pending_spare = atomic_read(&cp->reset_task_pending_spare); in cas_reset_task()
3987 int pending_mtu = atomic_read(&cp->reset_task_pending_mtu); in cas_reset_task()
3993 atomic_dec(&cp->reset_task_pending); in cas_reset_task()
4001 if (cp->hw_running) { in cas_reset_task()
4005 netif_device_detach(cp->dev); in cas_reset_task()
4006 cas_lock_all_save(cp, flags); in cas_reset_task()
4008 if (cp->opened) { in cas_reset_task()
4013 cas_spare_recover(cp, GFP_ATOMIC); in cas_reset_task()
4031 cas_reset(cp, !(pending_all > 0)); in cas_reset_task()
4032 if (cp->opened) in cas_reset_task()
4033 cas_clean_rings(cp); in cas_reset_task()
4034 cas_init_hw(cp, (pending_all > 0)); in cas_reset_task()
4036 cas_reset(cp, !(pending == CAS_RESET_ALL)); in cas_reset_task()
4037 if (cp->opened) in cas_reset_task()
4038 cas_clean_rings(cp); in cas_reset_task()
4039 cas_init_hw(cp, pending == CAS_RESET_ALL); in cas_reset_task()
4043 cas_unlock_all_restore(cp, flags); in cas_reset_task()
4044 netif_device_attach(cp->dev); in cas_reset_task()
4047 atomic_sub(pending_all, &cp->reset_task_pending_all); in cas_reset_task()
4048 atomic_sub(pending_spare, &cp->reset_task_pending_spare); in cas_reset_task()
4049 atomic_sub(pending_mtu, &cp->reset_task_pending_mtu); in cas_reset_task()
4050 atomic_dec(&cp->reset_task_pending); in cas_reset_task()
4052 atomic_set(&cp->reset_task_pending, 0); in cas_reset_task()
4058 struct cas *cp = from_timer(cp, t, link_timer); in cas_link_timer() local
4063 cp->link_transition_jiffies_valid && in cas_link_timer()
4064 ((jiffies - cp->link_transition_jiffies) > in cas_link_timer()
4070 cp->link_transition_jiffies_valid = 0; in cas_link_timer()
4073 if (!cp->hw_running) in cas_link_timer()
4076 spin_lock_irqsave(&cp->lock, flags); in cas_link_timer()
4077 cas_lock_tx(cp); in cas_link_timer()
4078 cas_entropy_gather(cp); in cas_link_timer()
4084 if (atomic_read(&cp->reset_task_pending_all) || in cas_link_timer()
4085 atomic_read(&cp->reset_task_pending_spare) || in cas_link_timer()
4086 atomic_read(&cp->reset_task_pending_mtu)) in cas_link_timer()
4089 if (atomic_read(&cp->reset_task_pending)) in cas_link_timer()
4094 if ((mask = (cp->cas_flags & CAS_FLAG_RXD_POST_MASK))) { in cas_link_timer()
4103 if (cas_post_rxds_ringN(cp, i, cp->rx_last[i]) < 0) { in cas_link_timer()
4107 cp->cas_flags &= ~rmask; in cas_link_timer()
4111 if (CAS_PHY_MII(cp->phy_type)) { in cas_link_timer()
4113 cas_mif_poll(cp, 0); in cas_link_timer()
4114 bmsr = cas_phy_read(cp, MII_BMSR); in cas_link_timer()
4120 bmsr = cas_phy_read(cp, MII_BMSR); in cas_link_timer()
4121 cas_mif_poll(cp, 1); in cas_link_timer()
4122 readl(cp->regs + REG_MIF_STATUS); /* avoid dups */ in cas_link_timer()
4123 reset = cas_mii_link_check(cp, bmsr); in cas_link_timer()
4125 reset = cas_pcs_link_check(cp); in cas_link_timer()
4132 if ((readl(cp->regs + REG_MAC_TX_STATUS) & MAC_TX_FRAME_XMIT) == 0) { in cas_link_timer()
4133 u32 val = readl(cp->regs + REG_MAC_STATE_MACHINE); in cas_link_timer()
4139 netif_printk(cp, tx_err, KERN_DEBUG, cp->dev, in cas_link_timer()
4145 val = readl(cp->regs + REG_TX_FIFO_PKT_CNT); in cas_link_timer()
4146 wptr = readl(cp->regs + REG_TX_FIFO_WRITE_PTR); in cas_link_timer()
4147 rptr = readl(cp->regs + REG_TX_FIFO_READ_PTR); in cas_link_timer()
4149 netif_printk(cp, tx_err, KERN_DEBUG, cp->dev, in cas_link_timer()
4156 cas_hard_reset(cp); in cas_link_timer()
4162 atomic_inc(&cp->reset_task_pending); in cas_link_timer()
4163 atomic_inc(&cp->reset_task_pending_all); in cas_link_timer()
4164 schedule_work(&cp->reset_task); in cas_link_timer()
4166 atomic_set(&cp->reset_task_pending, CAS_RESET_ALL); in cas_link_timer()
4168 schedule_work(&cp->reset_task); in cas_link_timer()
4173 mod_timer(&cp->link_timer, jiffies + CAS_LINK_TIMEOUT); in cas_link_timer()
4174 cas_unlock_tx(cp); in cas_link_timer()
4175 spin_unlock_irqrestore(&cp->lock, flags); in cas_link_timer()
4181 static void cas_tx_tiny_free(struct cas *cp) in cas_tx_tiny_free() argument
4183 struct pci_dev *pdev = cp->pdev; in cas_tx_tiny_free()
4187 if (!cp->tx_tiny_bufs[i]) in cas_tx_tiny_free()
4191 cp->tx_tiny_bufs[i], cp->tx_tiny_dvma[i]); in cas_tx_tiny_free()
4192 cp->tx_tiny_bufs[i] = NULL; in cas_tx_tiny_free()
4196 static int cas_tx_tiny_alloc(struct cas *cp) in cas_tx_tiny_alloc() argument
4198 struct pci_dev *pdev = cp->pdev; in cas_tx_tiny_alloc()
4202 cp->tx_tiny_bufs[i] = in cas_tx_tiny_alloc()
4204 &cp->tx_tiny_dvma[i], GFP_KERNEL); in cas_tx_tiny_alloc()
4205 if (!cp->tx_tiny_bufs[i]) { in cas_tx_tiny_alloc()
4206 cas_tx_tiny_free(cp); in cas_tx_tiny_alloc()
4216 struct cas *cp = netdev_priv(dev); in cas_open() local
4220 mutex_lock(&cp->pm_mutex); in cas_open()
4222 hw_was_up = cp->hw_running; in cas_open()
4225 * etc. state so it is safe to do this bit without cp->lock in cas_open()
4227 if (!cp->hw_running) { in cas_open()
4229 cas_lock_all_save(cp, flags); in cas_open()
4235 cas_reset(cp, 0); in cas_open()
4236 cp->hw_running = 1; in cas_open()
4237 cas_unlock_all_restore(cp, flags); in cas_open()
4241 if (cas_tx_tiny_alloc(cp) < 0) in cas_open()
4245 if (cas_alloc_rxds(cp) < 0) in cas_open()
4249 cas_spare_init(cp); in cas_open()
4250 cas_spare_recover(cp, GFP_KERNEL); in cas_open()
4257 if (request_irq(cp->pdev->irq, cas_interrupt, in cas_open()
4259 netdev_err(cp->dev, "failed to request irq !\n"); in cas_open()
4265 napi_enable(&cp->napi); in cas_open()
4268 cas_lock_all_save(cp, flags); in cas_open()
4269 cas_clean_rings(cp); in cas_open()
4270 cas_init_hw(cp, !hw_was_up); in cas_open()
4271 cp->opened = 1; in cas_open()
4272 cas_unlock_all_restore(cp, flags); in cas_open()
4275 mutex_unlock(&cp->pm_mutex); in cas_open()
4279 cas_spare_free(cp); in cas_open()
4280 cas_free_rxds(cp); in cas_open()
4282 cas_tx_tiny_free(cp); in cas_open()
4284 mutex_unlock(&cp->pm_mutex); in cas_open()
4291 struct cas *cp = netdev_priv(dev); in cas_close() local
4294 napi_disable(&cp->napi); in cas_close()
4297 mutex_lock(&cp->pm_mutex); in cas_close()
4302 cas_lock_all_save(cp, flags); in cas_close()
4303 cp->opened = 0; in cas_close()
4304 cas_reset(cp, 0); in cas_close()
4305 cas_phy_init(cp); in cas_close()
4306 cas_begin_auto_negotiation(cp, NULL); in cas_close()
4307 cas_clean_rings(cp); in cas_close()
4308 cas_unlock_all_restore(cp, flags); in cas_close()
4310 free_irq(cp->pdev->irq, (void *) dev); in cas_close()
4311 cas_spare_free(cp); in cas_close()
4312 cas_free_rxds(cp); in cas_close()
4313 cas_tx_tiny_free(cp); in cas_close()
4314 mutex_unlock(&cp->pm_mutex); in cas_close()
4365 static void cas_read_regs(struct cas *cp, u8 *ptr, int len) in cas_read_regs() argument
4371 spin_lock_irqsave(&cp->lock, flags); in cas_read_regs()
4376 hval = cas_phy_read(cp, in cas_read_regs()
4380 val= readl(cp->regs+ethtool_register_table[i].offsets); in cas_read_regs()
4384 spin_unlock_irqrestore(&cp->lock, flags); in cas_read_regs()
4389 struct cas *cp = netdev_priv(dev); in cas_get_stats() local
4390 struct net_device_stats *stats = cp->net_stats; in cas_get_stats()
4396 if (!cp->hw_running) in cas_get_stats()
4407 spin_lock_irqsave(&cp->stat_lock[N_TX_RINGS], flags); in cas_get_stats()
4409 readl(cp->regs + REG_MAC_FCS_ERR) & 0xffff; in cas_get_stats()
4411 readl(cp->regs + REG_MAC_ALIGN_ERR) &0xffff; in cas_get_stats()
4413 readl(cp->regs + REG_MAC_LEN_ERR) & 0xffff; in cas_get_stats()
4415 tmp = (readl(cp->regs + REG_MAC_COLL_EXCESS) & 0xffff) + in cas_get_stats()
4416 (readl(cp->regs + REG_MAC_COLL_LATE) & 0xffff); in cas_get_stats()
4419 tmp + (readl(cp->regs + REG_MAC_COLL_NORMAL) & 0xffff); in cas_get_stats()
4422 readl(cp->regs + REG_MAC_COLL_EXCESS); in cas_get_stats()
4423 stats[N_TX_RINGS].collisions += readl(cp->regs + REG_MAC_COLL_EXCESS) + in cas_get_stats()
4424 readl(cp->regs + REG_MAC_COLL_LATE); in cas_get_stats()
4426 cas_clear_mac_err(cp); in cas_get_stats()
4429 spin_lock(&cp->stat_lock[0]); in cas_get_stats()
4436 spin_unlock(&cp->stat_lock[0]); in cas_get_stats()
4439 spin_lock(&cp->stat_lock[i]); in cas_get_stats()
4452 spin_unlock(&cp->stat_lock[i]); in cas_get_stats()
4454 spin_unlock_irqrestore(&cp->stat_lock[N_TX_RINGS], flags); in cas_get_stats()
4461 struct cas *cp = netdev_priv(dev); in cas_set_multicast() local
4466 if (!cp->hw_running) in cas_set_multicast()
4469 spin_lock_irqsave(&cp->lock, flags); in cas_set_multicast()
4470 rxcfg = readl(cp->regs + REG_MAC_RX_CFG); in cas_set_multicast()
4473 writel(rxcfg & ~MAC_RX_CFG_EN, cp->regs + REG_MAC_RX_CFG); in cas_set_multicast()
4474 while (readl(cp->regs + REG_MAC_RX_CFG) & MAC_RX_CFG_EN) { in cas_set_multicast()
4483 writel(rxcfg & ~MAC_RX_CFG_EN, cp->regs + REG_MAC_RX_CFG); in cas_set_multicast()
4484 while (readl(cp->regs + REG_MAC_RX_CFG) & MAC_RX_CFG_HASH_FILTER_EN) { in cas_set_multicast()
4491 cp->mac_rx_cfg = rxcfg_new = cas_setup_multicast(cp); in cas_set_multicast()
4493 writel(rxcfg, cp->regs + REG_MAC_RX_CFG); in cas_set_multicast()
4494 spin_unlock_irqrestore(&cp->lock, flags); in cas_set_multicast()
4499 struct cas *cp = netdev_priv(dev); in cas_get_drvinfo() local
4502 strlcpy(info->bus_info, pci_name(cp->pdev), sizeof(info->bus_info)); in cas_get_drvinfo()
4508 struct cas *cp = netdev_priv(dev); in cas_get_link_ksettings() local
4517 if (cp->cas_flags & CAS_FLAG_1000MB_CAP) { in cas_get_link_ksettings()
4523 spin_lock_irqsave(&cp->lock, flags); in cas_get_link_ksettings()
4525 linkstate = cp->lstate; in cas_get_link_ksettings()
4526 if (CAS_PHY_MII(cp->phy_type)) { in cas_get_link_ksettings()
4528 cmd->base.phy_address = cp->phy_addr; in cas_get_link_ksettings()
4542 if (cp->hw_running) { in cas_get_link_ksettings()
4543 cas_mif_poll(cp, 0); in cas_get_link_ksettings()
4544 bmcr = cas_phy_read(cp, MII_BMCR); in cas_get_link_ksettings()
4545 cas_read_mii_link_mode(cp, &full_duplex, in cas_get_link_ksettings()
4547 cas_mif_poll(cp, 1); in cas_get_link_ksettings()
4556 if (cp->hw_running) { in cas_get_link_ksettings()
4558 bmcr = readl(cp->regs + REG_PCS_MII_CTRL); in cas_get_link_ksettings()
4559 cas_read_pcs_link_mode(cp, &full_duplex, in cas_get_link_ksettings()
4563 spin_unlock_irqrestore(&cp->lock, flags); in cas_get_link_ksettings()
4593 if (cp->link_cntl & BMCR_ANENABLE) { in cas_get_link_ksettings()
4598 if (cp->link_cntl & BMCR_SPEED100) { in cas_get_link_ksettings()
4600 } else if (cp->link_cntl & CAS_BMCR_SPEED1000) { in cas_get_link_ksettings()
4603 cmd->base.duplex = (cp->link_cntl & BMCR_FULLDPLX) ? in cas_get_link_ksettings()
4619 struct cas *cp = netdev_priv(dev); in cas_set_link_ksettings() local
4637 spin_lock_irqsave(&cp->lock, flags); in cas_set_link_ksettings()
4638 cas_begin_auto_negotiation(cp, cmd); in cas_set_link_ksettings()
4639 spin_unlock_irqrestore(&cp->lock, flags); in cas_set_link_ksettings()
4645 struct cas *cp = netdev_priv(dev); in cas_nway_reset() local
4648 if ((cp->link_cntl & BMCR_ANENABLE) == 0) in cas_nway_reset()
4652 spin_lock_irqsave(&cp->lock, flags); in cas_nway_reset()
4653 cas_begin_auto_negotiation(cp, NULL); in cas_nway_reset()
4654 spin_unlock_irqrestore(&cp->lock, flags); in cas_nway_reset()
4661 struct cas *cp = netdev_priv(dev); in cas_get_link() local
4662 return cp->lstate == link_up; in cas_get_link()
4667 struct cas *cp = netdev_priv(dev); in cas_get_msglevel() local
4668 return cp->msg_enable; in cas_get_msglevel()
4673 struct cas *cp = netdev_priv(dev); in cas_set_msglevel() local
4674 cp->msg_enable = value; in cas_set_msglevel()
4679 struct cas *cp = netdev_priv(dev); in cas_get_regs_len() local
4680 return cp->casreg_len < CAS_MAX_REGS ? cp->casreg_len: CAS_MAX_REGS; in cas_get_regs_len()
4686 struct cas *cp = netdev_priv(dev); in cas_get_regs() local
4688 /* cas_read_regs handles locks (cp->lock). */ in cas_get_regs()
4689 cas_read_regs(cp, p, regs->len / sizeof(u32)); in cas_get_regs()
4711 struct cas *cp = netdev_priv(dev); in cas_get_ethtool_stats() local
4712 struct net_device_stats *stats = cas_get_stats(cp->dev); in cas_get_ethtool_stats()
4750 struct cas *cp = netdev_priv(dev); in cas_ioctl() local
4758 mutex_lock(&cp->pm_mutex); in cas_ioctl()
4761 data->phy_id = cp->phy_addr; in cas_ioctl()
4765 spin_lock_irqsave(&cp->lock, flags); in cas_ioctl()
4766 cas_mif_poll(cp, 0); in cas_ioctl()
4767 data->val_out = cas_phy_read(cp, data->reg_num & 0x1f); in cas_ioctl()
4768 cas_mif_poll(cp, 1); in cas_ioctl()
4769 spin_unlock_irqrestore(&cp->lock, flags); in cas_ioctl()
4774 spin_lock_irqsave(&cp->lock, flags); in cas_ioctl()
4775 cas_mif_poll(cp, 0); in cas_ioctl()
4776 rc = cas_phy_write(cp, data->reg_num & 0x1f, data->val_in); in cas_ioctl()
4777 cas_mif_poll(cp, 1); in cas_ioctl()
4778 spin_unlock_irqrestore(&cp->lock, flags); in cas_ioctl()
4784 mutex_unlock(&cp->pm_mutex); in cas_ioctl()
4893 struct cas *cp; in cas_init_one() local
4914 dev = alloc_etherdev(sizeof(*cp)); in cas_init_one()
4987 cp = netdev_priv(dev); in cas_init_one()
4988 cp->pdev = pdev; in cas_init_one()
4991 cp->orig_cacheline_size = cas_cacheline_size ? orig_cacheline_size: 0; in cas_init_one()
4993 cp->dev = dev; in cas_init_one()
4994 cp->msg_enable = (cassini_debug < 0) ? CAS_DEF_MSG_ENABLE : in cas_init_one()
4998 cp->of_node = pci_device_to_OF_node(pdev); in cas_init_one()
5001 cp->link_transition = LINK_TRANSITION_UNKNOWN; in cas_init_one()
5002 cp->link_transition_jiffies_valid = 0; in cas_init_one()
5004 spin_lock_init(&cp->lock); in cas_init_one()
5005 spin_lock_init(&cp->rx_inuse_lock); in cas_init_one()
5006 spin_lock_init(&cp->rx_spare_lock); in cas_init_one()
5008 spin_lock_init(&cp->stat_lock[i]); in cas_init_one()
5009 spin_lock_init(&cp->tx_lock[i]); in cas_init_one()
5011 spin_lock_init(&cp->stat_lock[N_TX_RINGS]); in cas_init_one()
5012 mutex_init(&cp->pm_mutex); in cas_init_one()
5014 timer_setup(&cp->link_timer, cas_link_timer, 0); in cas_init_one()
5020 atomic_set(&cp->reset_task_pending, 0); in cas_init_one()
5021 atomic_set(&cp->reset_task_pending_all, 0); in cas_init_one()
5022 atomic_set(&cp->reset_task_pending_spare, 0); in cas_init_one()
5023 atomic_set(&cp->reset_task_pending_mtu, 0); in cas_init_one()
5025 INIT_WORK(&cp->reset_task, cas_reset_task); in cas_init_one()
5029 cp->link_cntl = link_modes[link_mode]; in cas_init_one()
5031 cp->link_cntl = BMCR_ANENABLE; in cas_init_one()
5032 cp->lstate = link_down; in cas_init_one()
5033 cp->link_transition = LINK_TRANSITION_LINK_DOWN; in cas_init_one()
5034 netif_carrier_off(cp->dev); in cas_init_one()
5035 cp->timer_ticks = 0; in cas_init_one()
5038 cp->regs = pci_iomap(pdev, 0, casreg_len); in cas_init_one()
5039 if (!cp->regs) { in cas_init_one()
5043 cp->casreg_len = casreg_len; in cas_init_one()
5046 cas_check_pci_invariants(cp); in cas_init_one()
5047 cas_hard_reset(cp); in cas_init_one()
5048 cas_reset(cp, 0); in cas_init_one()
5049 if (cas_check_invariants(cp)) in cas_init_one()
5051 if (cp->cas_flags & CAS_FLAG_SATURN) in cas_init_one()
5052 cas_saturn_firmware_init(cp); in cas_init_one()
5054 cp->init_block = in cas_init_one()
5056 &cp->block_dvma, GFP_KERNEL); in cas_init_one()
5057 if (!cp->init_block) { in cas_init_one()
5063 cp->init_txds[i] = cp->init_block->txds[i]; in cas_init_one()
5066 cp->init_rxds[i] = cp->init_block->rxds[i]; in cas_init_one()
5069 cp->init_rxcs[i] = cp->init_block->rxcs[i]; in cas_init_one()
5072 skb_queue_head_init(&cp->rx_flows[i]); in cas_init_one()
5079 netif_napi_add(dev, &cp->napi, cas_poll, 64); in cas_init_one()
5085 if ((cp->cas_flags & CAS_FLAG_NO_HW_CSUM) == 0) in cas_init_one()
5100 i = readl(cp->regs + REG_BIM_CFG); in cas_init_one()
5102 (cp->cas_flags & CAS_FLAG_REG_PLUS) ? "+" : "", in cas_init_one()
5105 (cp->phy_type == CAS_PHY_SERDES) ? "Fi" : "Cu", pdev->irq, in cas_init_one()
5109 cp->hw_running = 1; in cas_init_one()
5110 cas_entropy_reset(cp); in cas_init_one()
5111 cas_phy_init(cp); in cas_init_one()
5112 cas_begin_auto_negotiation(cp, NULL); in cas_init_one()
5117 cp->init_block, cp->block_dvma); in cas_init_one()
5120 mutex_lock(&cp->pm_mutex); in cas_init_one()
5121 if (cp->hw_running) in cas_init_one()
5122 cas_shutdown(cp); in cas_init_one()
5123 mutex_unlock(&cp->pm_mutex); in cas_init_one()
5125 pci_iounmap(pdev, cp->regs); in cas_init_one()
5147 struct cas *cp; in cas_remove_one() local
5151 cp = netdev_priv(dev); in cas_remove_one()
5154 vfree(cp->fw_data); in cas_remove_one()
5156 mutex_lock(&cp->pm_mutex); in cas_remove_one()
5157 cancel_work_sync(&cp->reset_task); in cas_remove_one()
5158 if (cp->hw_running) in cas_remove_one()
5159 cas_shutdown(cp); in cas_remove_one()
5160 mutex_unlock(&cp->pm_mutex); in cas_remove_one()
5163 if (cp->orig_cacheline_size) { in cas_remove_one()
5168 cp->orig_cacheline_size); in cas_remove_one()
5172 cp->init_block, cp->block_dvma); in cas_remove_one()
5173 pci_iounmap(pdev, cp->regs); in cas_remove_one()
5182 struct cas *cp = netdev_priv(dev); in cas_suspend() local
5185 mutex_lock(&cp->pm_mutex); in cas_suspend()
5188 if (cp->opened) { in cas_suspend()
5191 cas_lock_all_save(cp, flags); in cas_suspend()
5198 cas_reset(cp, 0); in cas_suspend()
5199 cas_clean_rings(cp); in cas_suspend()
5200 cas_unlock_all_restore(cp, flags); in cas_suspend()
5203 if (cp->hw_running) in cas_suspend()
5204 cas_shutdown(cp); in cas_suspend()
5205 mutex_unlock(&cp->pm_mutex); in cas_suspend()
5213 struct cas *cp = netdev_priv(dev); in cas_resume() local
5217 mutex_lock(&cp->pm_mutex); in cas_resume()
5218 cas_hard_reset(cp); in cas_resume()
5219 if (cp->opened) { in cas_resume()
5221 cas_lock_all_save(cp, flags); in cas_resume()
5222 cas_reset(cp, 0); in cas_resume()
5223 cp->hw_running = 1; in cas_resume()
5224 cas_clean_rings(cp); in cas_resume()
5225 cas_init_hw(cp, 1); in cas_resume()
5226 cas_unlock_all_restore(cp, flags); in cas_resume()
5230 mutex_unlock(&cp->pm_mutex); in cas_resume()