Lines Matching refs:ks
37 static void ks8851_lock(struct ks8851_net *ks, unsigned long *flags) in ks8851_lock() argument
39 ks->lock(ks, flags); in ks8851_lock()
49 static void ks8851_unlock(struct ks8851_net *ks, unsigned long *flags) in ks8851_unlock() argument
51 ks->unlock(ks, flags); in ks8851_unlock()
62 static void ks8851_wrreg16(struct ks8851_net *ks, unsigned int reg, in ks8851_wrreg16() argument
65 ks->wrreg16(ks, reg, val); in ks8851_wrreg16()
75 static unsigned int ks8851_rdreg16(struct ks8851_net *ks, in ks8851_rdreg16() argument
78 return ks->rdreg16(ks, reg); in ks8851_rdreg16()
94 static void ks8851_soft_reset(struct ks8851_net *ks, unsigned op) in ks8851_soft_reset() argument
96 ks8851_wrreg16(ks, KS_GRR, op); in ks8851_soft_reset()
98 ks8851_wrreg16(ks, KS_GRR, 0); in ks8851_soft_reset()
109 static void ks8851_set_powermode(struct ks8851_net *ks, unsigned pwrmode) in ks8851_set_powermode() argument
113 netif_dbg(ks, hw, ks->netdev, "setting power mode %d\n", pwrmode); in ks8851_set_powermode()
115 pmecr = ks8851_rdreg16(ks, KS_PMECR); in ks8851_set_powermode()
119 ks8851_wrreg16(ks, KS_PMECR, pmecr); in ks8851_set_powermode()
133 struct ks8851_net *ks = netdev_priv(dev); in ks8851_write_mac_addr() local
138 ks8851_lock(ks, &flags); in ks8851_write_mac_addr()
144 ks8851_set_powermode(ks, PMECR_PM_NORMAL); in ks8851_write_mac_addr()
148 ks8851_wrreg16(ks, KS_MAR(i), val); in ks8851_write_mac_addr()
152 ks8851_set_powermode(ks, PMECR_PM_SOFTDOWN); in ks8851_write_mac_addr()
154 ks8851_unlock(ks, &flags); in ks8851_write_mac_addr()
167 struct ks8851_net *ks = netdev_priv(dev); in ks8851_read_mac_addr() local
172 ks8851_lock(ks, &flags); in ks8851_read_mac_addr()
175 reg = ks8851_rdreg16(ks, KS_MAR(i)); in ks8851_read_mac_addr()
180 ks8851_unlock(ks, &flags); in ks8851_read_mac_addr()
194 static void ks8851_init_mac(struct ks8851_net *ks, struct device_node *np) in ks8851_init_mac() argument
196 struct net_device *dev = ks->netdev; in ks8851_init_mac()
206 if (ks->rc_ccr & CCR_EEPROM) { in ks8851_init_mac()
211 netdev_err(ks->netdev, "invalid mac address read %pM\n", in ks8851_init_mac()
226 static void ks8851_dbg_dumpkkt(struct ks8851_net *ks, u8 *rxpkt) in ks8851_dbg_dumpkkt() argument
228 netdev_dbg(ks->netdev, in ks8851_dbg_dumpkkt()
240 static void ks8851_rx_skb(struct ks8851_net *ks, struct sk_buff *skb) in ks8851_rx_skb() argument
242 ks->rx_skb(ks, skb); in ks8851_rx_skb()
253 static void ks8851_rx_pkts(struct ks8851_net *ks) in ks8851_rx_pkts() argument
261 rxfc = (ks8851_rdreg16(ks, KS_RXFCTR) >> 8) & 0xff; in ks8851_rx_pkts()
263 netif_dbg(ks, rx_status, ks->netdev, in ks8851_rx_pkts()
277 rxstat = ks8851_rdreg16(ks, KS_RXFHSR); in ks8851_rx_pkts()
278 rxlen = ks8851_rdreg16(ks, KS_RXFHBCR) & RXFHBCR_CNT_MASK; in ks8851_rx_pkts()
280 netif_dbg(ks, rx_status, ks->netdev, in ks8851_rx_pkts()
286 ks8851_wrreg16(ks, KS_RXFDPR, RXFDPR_RXFPAI | 0x00); in ks8851_rx_pkts()
289 ks8851_wrreg16(ks, KS_RXQCR, ks->rc_rxqcr | RXQCR_SDA); in ks8851_rx_pkts()
296 skb = netdev_alloc_skb_ip_align(ks->netdev, rxalign); in ks8851_rx_pkts()
307 ks->rdfifo(ks, rxpkt, rxalign + 8); in ks8851_rx_pkts()
309 if (netif_msg_pktdata(ks)) in ks8851_rx_pkts()
310 ks8851_dbg_dumpkkt(ks, rxpkt); in ks8851_rx_pkts()
312 skb->protocol = eth_type_trans(skb, ks->netdev); in ks8851_rx_pkts()
313 ks8851_rx_skb(ks, skb); in ks8851_rx_pkts()
315 ks->netdev->stats.rx_packets++; in ks8851_rx_pkts()
316 ks->netdev->stats.rx_bytes += rxlen; in ks8851_rx_pkts()
321 ks8851_wrreg16(ks, KS_RXQCR, ks->rc_rxqcr | RXQCR_RRXEF); in ks8851_rx_pkts()
339 struct ks8851_net *ks = _ks; in ks8851_irq() local
344 ks8851_lock(ks, &flags); in ks8851_irq()
346 status = ks8851_rdreg16(ks, KS_ISR); in ks8851_irq()
348 netif_dbg(ks, intr, ks->netdev, in ks8851_irq()
355 u16 pmecr = ks8851_rdreg16(ks, KS_PMECR); in ks8851_irq()
357 ks8851_wrreg16(ks, KS_PMECR, pmecr | PMECR_WKEVT_LINK); in ks8851_irq()
372 ks->tx_space = ks8851_rdreg16(ks, KS_TXMIR); in ks8851_irq()
374 netif_dbg(ks, intr, ks->netdev, in ks8851_irq()
375 "%s: txspace %d\n", __func__, ks->tx_space); in ks8851_irq()
382 netdev_err(ks->netdev, "%s: spi bus error\n", __func__); in ks8851_irq()
386 ks8851_wrreg16(ks, KS_ISR, handled); in ks8851_irq()
394 ks8851_rx_pkts(ks); in ks8851_irq()
401 struct ks8851_rxctrl *rxc = &ks->rxctrl; in ks8851_irq()
404 ks8851_wrreg16(ks, KS_MAHTR0, rxc->mchash[0]); in ks8851_irq()
405 ks8851_wrreg16(ks, KS_MAHTR1, rxc->mchash[1]); in ks8851_irq()
406 ks8851_wrreg16(ks, KS_MAHTR2, rxc->mchash[2]); in ks8851_irq()
407 ks8851_wrreg16(ks, KS_MAHTR3, rxc->mchash[3]); in ks8851_irq()
409 ks8851_wrreg16(ks, KS_RXCR2, rxc->rxcr2); in ks8851_irq()
410 ks8851_wrreg16(ks, KS_RXCR1, rxc->rxcr1); in ks8851_irq()
413 ks8851_unlock(ks, &flags); in ks8851_irq()
416 mii_check_link(&ks->mii); in ks8851_irq()
419 netif_wake_queue(ks->netdev); in ks8851_irq()
428 static void ks8851_flush_tx_work(struct ks8851_net *ks) in ks8851_flush_tx_work() argument
430 if (ks->flush_tx_work) in ks8851_flush_tx_work()
431 ks->flush_tx_work(ks); in ks8851_flush_tx_work()
443 struct ks8851_net *ks = netdev_priv(dev); in ks8851_net_open() local
449 dev->name, ks); in ks8851_net_open()
457 ks8851_lock(ks, &flags); in ks8851_net_open()
459 netif_dbg(ks, ifup, ks->netdev, "opening\n"); in ks8851_net_open()
462 ks8851_set_powermode(ks, PMECR_PM_NORMAL); in ks8851_net_open()
466 ks8851_soft_reset(ks, GRR_QMU); in ks8851_net_open()
470 ks8851_wrreg16(ks, KS_TXCR, (TXCR_TXE | /* enable transmit process */ in ks8851_net_open()
476 ks8851_wrreg16(ks, KS_TXFDPR, TXFDPR_TXFPAI); in ks8851_net_open()
480 ks8851_wrreg16(ks, KS_RXCR1, (RXCR1_RXPAFMA | /* from mac filter */ in ks8851_net_open()
487 ks8851_wrreg16(ks, KS_RXCR2, RXCR2_SRDBL_FRAME); in ks8851_net_open()
490 ks8851_wrreg16(ks, KS_RXDTTR, 1000); /* 1ms after first frame to IRQ */ in ks8851_net_open()
491 ks8851_wrreg16(ks, KS_RXDBCTR, 4096); /* >4Kbytes in buffer to IRQ */ in ks8851_net_open()
492 ks8851_wrreg16(ks, KS_RXFCTR, 10); /* 10 frames to IRQ */ in ks8851_net_open()
494 ks->rc_rxqcr = (RXQCR_RXFCTE | /* IRQ on frame count exceeded */ in ks8851_net_open()
498 ks8851_wrreg16(ks, KS_RXQCR, ks->rc_rxqcr); in ks8851_net_open()
501 ks8851_wrreg16(ks, KS_ISR, ks->rc_ier); in ks8851_net_open()
502 ks8851_wrreg16(ks, KS_IER, ks->rc_ier); in ks8851_net_open()
504 netif_start_queue(ks->netdev); in ks8851_net_open()
506 netif_dbg(ks, ifup, ks->netdev, "network device up\n"); in ks8851_net_open()
508 ks8851_unlock(ks, &flags); in ks8851_net_open()
509 mii_check_link(&ks->mii); in ks8851_net_open()
523 struct ks8851_net *ks = netdev_priv(dev); in ks8851_net_stop() local
526 netif_info(ks, ifdown, dev, "shutting down\n"); in ks8851_net_stop()
530 ks8851_lock(ks, &flags); in ks8851_net_stop()
532 ks8851_wrreg16(ks, KS_IER, 0x0000); in ks8851_net_stop()
533 ks8851_wrreg16(ks, KS_ISR, 0xffff); in ks8851_net_stop()
534 ks8851_unlock(ks, &flags); in ks8851_net_stop()
537 ks8851_flush_tx_work(ks); in ks8851_net_stop()
538 flush_work(&ks->rxctrl_work); in ks8851_net_stop()
540 ks8851_lock(ks, &flags); in ks8851_net_stop()
542 ks8851_wrreg16(ks, KS_RXCR1, 0x0000); in ks8851_net_stop()
545 ks8851_wrreg16(ks, KS_TXCR, 0x0000); in ks8851_net_stop()
548 ks8851_set_powermode(ks, PMECR_PM_SOFTDOWN); in ks8851_net_stop()
549 ks8851_unlock(ks, &flags); in ks8851_net_stop()
552 while (!skb_queue_empty(&ks->txq)) { in ks8851_net_stop()
553 struct sk_buff *txb = skb_dequeue(&ks->txq); in ks8851_net_stop()
555 netif_dbg(ks, ifdown, ks->netdev, in ks8851_net_stop()
561 free_irq(dev->irq, ks); in ks8851_net_stop()
582 struct ks8851_net *ks = netdev_priv(dev); in ks8851_start_xmit() local
584 return ks->start_xmit(skb, dev); in ks8851_start_xmit()
602 struct ks8851_net *ks = container_of(work, struct ks8851_net, rxctrl_work); in ks8851_rxctrl_work() local
605 ks8851_lock(ks, &flags); in ks8851_rxctrl_work()
608 ks8851_wrreg16(ks, KS_RXCR1, 0x00); in ks8851_rxctrl_work()
610 ks8851_unlock(ks, &flags); in ks8851_rxctrl_work()
615 struct ks8851_net *ks = netdev_priv(dev); in ks8851_set_rx_mode() local
657 spin_lock(&ks->statelock); in ks8851_set_rx_mode()
659 if (memcmp(&rxctrl, &ks->rxctrl, sizeof(rxctrl)) != 0) { in ks8851_set_rx_mode()
660 memcpy(&ks->rxctrl, &rxctrl, sizeof(ks->rxctrl)); in ks8851_set_rx_mode()
661 schedule_work(&ks->rxctrl_work); in ks8851_set_rx_mode()
664 spin_unlock(&ks->statelock); in ks8851_set_rx_mode()
683 struct ks8851_net *ks = netdev_priv(dev); in ks8851_net_ioctl() local
688 return generic_mii_ioctl(&ks->mii, if_mii(req), cmd, NULL); in ks8851_net_ioctl()
713 struct ks8851_net *ks = netdev_priv(dev); in ks8851_get_msglevel() local
714 return ks->msg_enable; in ks8851_get_msglevel()
719 struct ks8851_net *ks = netdev_priv(dev); in ks8851_set_msglevel() local
720 ks->msg_enable = to; in ks8851_set_msglevel()
726 struct ks8851_net *ks = netdev_priv(dev); in ks8851_get_link_ksettings() local
728 mii_ethtool_get_link_ksettings(&ks->mii, cmd); in ks8851_get_link_ksettings()
736 struct ks8851_net *ks = netdev_priv(dev); in ks8851_set_link_ksettings() local
737 return mii_ethtool_set_link_ksettings(&ks->mii, cmd); in ks8851_set_link_ksettings()
742 struct ks8851_net *ks = netdev_priv(dev); in ks8851_get_link() local
743 return mii_link_ok(&ks->mii); in ks8851_get_link()
748 struct ks8851_net *ks = netdev_priv(dev); in ks8851_nway_reset() local
749 return mii_nway_restart(&ks->mii); in ks8851_nway_reset()
756 struct ks8851_net *ks = ee->data; in ks8851_eeprom_regread() local
759 val = ks8851_rdreg16(ks, KS_EEPCR); in ks8851_eeprom_regread()
768 struct ks8851_net *ks = ee->data; in ks8851_eeprom_regwrite() local
780 ks8851_wrreg16(ks, KS_EEPCR, val); in ks8851_eeprom_regwrite()
790 static int ks8851_eeprom_claim(struct ks8851_net *ks) in ks8851_eeprom_claim() argument
793 ks8851_wrreg16(ks, KS_EEPCR, EEPCR_EESA | EEPCR_EECS); in ks8851_eeprom_claim()
803 static void ks8851_eeprom_release(struct ks8851_net *ks) in ks8851_eeprom_release() argument
805 unsigned val = ks8851_rdreg16(ks, KS_EEPCR); in ks8851_eeprom_release()
807 ks8851_wrreg16(ks, KS_EEPCR, val & ~EEPCR_EESA); in ks8851_eeprom_release()
815 struct ks8851_net *ks = netdev_priv(dev); in ks8851_set_eeprom() local
828 if (!(ks->rc_ccr & CCR_EEPROM)) in ks8851_set_eeprom()
831 ks8851_lock(ks, &flags); in ks8851_set_eeprom()
833 ks8851_eeprom_claim(ks); in ks8851_set_eeprom()
835 eeprom_93cx6_wren(&ks->eeprom, true); in ks8851_set_eeprom()
840 eeprom_93cx6_read(&ks->eeprom, offset/2, &tmp); in ks8851_set_eeprom()
850 eeprom_93cx6_write(&ks->eeprom, offset/2, tmp); in ks8851_set_eeprom()
851 eeprom_93cx6_wren(&ks->eeprom, false); in ks8851_set_eeprom()
853 ks8851_eeprom_release(ks); in ks8851_set_eeprom()
854 ks8851_unlock(ks, &flags); in ks8851_set_eeprom()
862 struct ks8851_net *ks = netdev_priv(dev); in ks8851_get_eeprom() local
871 if (!(ks->rc_ccr & CCR_EEPROM)) in ks8851_get_eeprom()
874 ks8851_lock(ks, &flags); in ks8851_get_eeprom()
876 ks8851_eeprom_claim(ks); in ks8851_get_eeprom()
880 eeprom_93cx6_multiread(&ks->eeprom, offset/2, (__le16 *)data, len/2); in ks8851_get_eeprom()
881 ks8851_eeprom_release(ks); in ks8851_get_eeprom()
882 ks8851_unlock(ks, &flags); in ks8851_get_eeprom()
889 struct ks8851_net *ks = netdev_priv(dev); in ks8851_get_eeprom_len() local
892 return ks->rc_ccr & CCR_EEPROM ? 128 : 0; in ks8851_get_eeprom_len()
955 struct ks8851_net *ks = netdev_priv(dev); in ks8851_phy_read() local
964 ks8851_lock(ks, &flags); in ks8851_phy_read()
965 result = ks8851_rdreg16(ks, ksreg); in ks8851_phy_read()
966 ks8851_unlock(ks, &flags); in ks8851_phy_read()
974 struct ks8851_net *ks = netdev_priv(dev); in ks8851_phy_write() local
980 ks8851_lock(ks, &flags); in ks8851_phy_write()
981 ks8851_wrreg16(ks, ksreg, value); in ks8851_phy_write()
982 ks8851_unlock(ks, &flags); in ks8851_phy_write()
992 static int ks8851_read_selftest(struct ks8851_net *ks) in ks8851_read_selftest() argument
998 rd = ks8851_rdreg16(ks, KS_MBIR); in ks8851_read_selftest()
1001 netdev_warn(ks->netdev, "Memory selftest not finished\n"); in ks8851_read_selftest()
1006 netdev_err(ks->netdev, "TX memory selftest fail\n"); in ks8851_read_selftest()
1011 netdev_err(ks->netdev, "RX memory selftest fail\n"); in ks8851_read_selftest()
1024 struct ks8851_net *ks = dev_get_drvdata(dev); in ks8851_suspend() local
1025 struct net_device *netdev = ks->netdev; in ks8851_suspend()
1038 struct ks8851_net *ks = dev_get_drvdata(dev); in ks8851_resume() local
1039 struct net_device *netdev = ks->netdev; in ks8851_resume()
1054 struct ks8851_net *ks = netdev_priv(netdev); in ks8851_probe_common() local
1059 ks->netdev = netdev; in ks8851_probe_common()
1060 ks->tx_space = 6144; in ks8851_probe_common()
1066 ks->gpio = gpio; in ks8851_probe_common()
1076 ks->vdd_io = devm_regulator_get(dev, "vdd-io"); in ks8851_probe_common()
1077 if (IS_ERR(ks->vdd_io)) { in ks8851_probe_common()
1078 ret = PTR_ERR(ks->vdd_io); in ks8851_probe_common()
1082 ret = regulator_enable(ks->vdd_io); in ks8851_probe_common()
1088 ks->vdd_reg = devm_regulator_get(dev, "vdd"); in ks8851_probe_common()
1089 if (IS_ERR(ks->vdd_reg)) { in ks8851_probe_common()
1090 ret = PTR_ERR(ks->vdd_reg); in ks8851_probe_common()
1094 ret = regulator_enable(ks->vdd_reg); in ks8851_probe_common()
1105 spin_lock_init(&ks->statelock); in ks8851_probe_common()
1107 INIT_WORK(&ks->rxctrl_work, ks8851_rxctrl_work); in ks8851_probe_common()
1110 ks->eeprom.data = ks; in ks8851_probe_common()
1111 ks->eeprom.width = PCI_EEPROM_WIDTH_93C46; in ks8851_probe_common()
1112 ks->eeprom.register_read = ks8851_eeprom_regread; in ks8851_probe_common()
1113 ks->eeprom.register_write = ks8851_eeprom_regwrite; in ks8851_probe_common()
1116 ks->mii.dev = netdev; in ks8851_probe_common()
1117 ks->mii.phy_id = 1, in ks8851_probe_common()
1118 ks->mii.phy_id_mask = 1; in ks8851_probe_common()
1119 ks->mii.reg_num_mask = 0xf; in ks8851_probe_common()
1120 ks->mii.mdio_read = ks8851_phy_read; in ks8851_probe_common()
1121 ks->mii.mdio_write = ks8851_phy_write; in ks8851_probe_common()
1126 ks->msg_enable = netif_msg_init(msg_en, NETIF_MSG_DRV | in ks8851_probe_common()
1130 skb_queue_head_init(&ks->txq); in ks8851_probe_common()
1135 dev_set_drvdata(dev, ks); in ks8851_probe_common()
1137 netif_carrier_off(ks->netdev); in ks8851_probe_common()
1142 ks8851_soft_reset(ks, GRR_GSR); in ks8851_probe_common()
1145 cider = ks8851_rdreg16(ks, KS_CIDER); in ks8851_probe_common()
1153 ks->rc_ccr = ks8851_rdreg16(ks, KS_CCR); in ks8851_probe_common()
1155 ks8851_read_selftest(ks); in ks8851_probe_common()
1156 ks8851_init_mac(ks, dev->of_node); in ks8851_probe_common()
1166 ks->rc_ccr & CCR_EEPROM ? "has" : "no"); in ks8851_probe_common()
1174 regulator_disable(ks->vdd_reg); in ks8851_probe_common()
1176 regulator_disable(ks->vdd_io); in ks8851_probe_common()