Lines Matching full:lp

125  * @lp:		Pointer to axienet local structure
132 static inline u32 axienet_dma_in32(struct axienet_local *lp, off_t reg) in axienet_dma_in32() argument
134 return ioread32(lp->dma_regs + reg); in axienet_dma_in32()
137 static void desc_set_phys_addr(struct axienet_local *lp, dma_addr_t addr, in desc_set_phys_addr() argument
141 if (lp->features & XAE_FEATURE_DMA_64BIT) in desc_set_phys_addr()
145 static dma_addr_t desc_get_phys_addr(struct axienet_local *lp, in desc_get_phys_addr() argument
150 if (lp->features & XAE_FEATURE_DMA_64BIT) in desc_get_phys_addr()
167 struct axienet_local *lp = netdev_priv(ndev); in axienet_dma_bd_release() local
170 dma_free_coherent(lp->dev, in axienet_dma_bd_release()
171 sizeof(*lp->tx_bd_v) * lp->tx_bd_num, in axienet_dma_bd_release()
172 lp->tx_bd_v, in axienet_dma_bd_release()
173 lp->tx_bd_p); in axienet_dma_bd_release()
175 if (!lp->rx_bd_v) in axienet_dma_bd_release()
178 for (i = 0; i < lp->rx_bd_num; i++) { in axienet_dma_bd_release()
184 if (!lp->rx_bd_v[i].skb) in axienet_dma_bd_release()
187 dev_kfree_skb(lp->rx_bd_v[i].skb); in axienet_dma_bd_release()
193 if (lp->rx_bd_v[i].cntrl) { in axienet_dma_bd_release()
194 phys = desc_get_phys_addr(lp, &lp->rx_bd_v[i]); in axienet_dma_bd_release()
195 dma_unmap_single(lp->dev, phys, in axienet_dma_bd_release()
196 lp->max_frm_size, DMA_FROM_DEVICE); in axienet_dma_bd_release()
200 dma_free_coherent(lp->dev, in axienet_dma_bd_release()
201 sizeof(*lp->rx_bd_v) * lp->rx_bd_num, in axienet_dma_bd_release()
202 lp->rx_bd_v, in axienet_dma_bd_release()
203 lp->rx_bd_p); in axienet_dma_bd_release()
208 * @lp: Pointer to the axienet_local structure
211 static u32 axienet_usec_to_timer(struct axienet_local *lp, u32 coalesce_usec) in axienet_usec_to_timer() argument
216 if (lp->axi_clk) in axienet_usec_to_timer()
217 clk_rate = clk_get_rate(lp->axi_clk); in axienet_usec_to_timer()
230 * @lp: Pointer to the axienet_local structure
232 static void axienet_dma_start(struct axienet_local *lp) in axienet_dma_start() argument
235 lp->rx_dma_cr = (lp->coalesce_count_rx << XAXIDMA_COALESCE_SHIFT) | in axienet_dma_start()
240 if (lp->coalesce_count_rx > 1) in axienet_dma_start()
241 lp->rx_dma_cr |= (axienet_usec_to_timer(lp, lp->coalesce_usec_rx) in axienet_dma_start()
244 axienet_dma_out32(lp, XAXIDMA_RX_CR_OFFSET, lp->rx_dma_cr); in axienet_dma_start()
247 lp->tx_dma_cr = (lp->coalesce_count_tx << XAXIDMA_COALESCE_SHIFT) | in axienet_dma_start()
252 if (lp->coalesce_count_tx > 1) in axienet_dma_start()
253 lp->tx_dma_cr |= (axienet_usec_to_timer(lp, lp->coalesce_usec_tx) in axienet_dma_start()
256 axienet_dma_out32(lp, XAXIDMA_TX_CR_OFFSET, lp->tx_dma_cr); in axienet_dma_start()
261 axienet_dma_out_addr(lp, XAXIDMA_RX_CDESC_OFFSET, lp->rx_bd_p); in axienet_dma_start()
262 lp->rx_dma_cr |= XAXIDMA_CR_RUNSTOP_MASK; in axienet_dma_start()
263 axienet_dma_out32(lp, XAXIDMA_RX_CR_OFFSET, lp->rx_dma_cr); in axienet_dma_start()
264 axienet_dma_out_addr(lp, XAXIDMA_RX_TDESC_OFFSET, lp->rx_bd_p + in axienet_dma_start()
265 (sizeof(*lp->rx_bd_v) * (lp->rx_bd_num - 1))); in axienet_dma_start()
271 axienet_dma_out_addr(lp, XAXIDMA_TX_CDESC_OFFSET, lp->tx_bd_p); in axienet_dma_start()
272 lp->tx_dma_cr |= XAXIDMA_CR_RUNSTOP_MASK; in axienet_dma_start()
273 axienet_dma_out32(lp, XAXIDMA_TX_CR_OFFSET, lp->tx_dma_cr); in axienet_dma_start()
290 struct axienet_local *lp = netdev_priv(ndev); in axienet_dma_bd_init() local
293 lp->tx_bd_ci = 0; in axienet_dma_bd_init()
294 lp->tx_bd_tail = 0; in axienet_dma_bd_init()
295 lp->rx_bd_ci = 0; in axienet_dma_bd_init()
298 lp->tx_bd_v = dma_alloc_coherent(lp->dev, in axienet_dma_bd_init()
299 sizeof(*lp->tx_bd_v) * lp->tx_bd_num, in axienet_dma_bd_init()
300 &lp->tx_bd_p, GFP_KERNEL); in axienet_dma_bd_init()
301 if (!lp->tx_bd_v) in axienet_dma_bd_init()
304 lp->rx_bd_v = dma_alloc_coherent(lp->dev, in axienet_dma_bd_init()
305 sizeof(*lp->rx_bd_v) * lp->rx_bd_num, in axienet_dma_bd_init()
306 &lp->rx_bd_p, GFP_KERNEL); in axienet_dma_bd_init()
307 if (!lp->rx_bd_v) in axienet_dma_bd_init()
310 for (i = 0; i < lp->tx_bd_num; i++) { in axienet_dma_bd_init()
311 dma_addr_t addr = lp->tx_bd_p + in axienet_dma_bd_init()
312 sizeof(*lp->tx_bd_v) * in axienet_dma_bd_init()
313 ((i + 1) % lp->tx_bd_num); in axienet_dma_bd_init()
315 lp->tx_bd_v[i].next = lower_32_bits(addr); in axienet_dma_bd_init()
316 if (lp->features & XAE_FEATURE_DMA_64BIT) in axienet_dma_bd_init()
317 lp->tx_bd_v[i].next_msb = upper_32_bits(addr); in axienet_dma_bd_init()
320 for (i = 0; i < lp->rx_bd_num; i++) { in axienet_dma_bd_init()
323 addr = lp->rx_bd_p + sizeof(*lp->rx_bd_v) * in axienet_dma_bd_init()
324 ((i + 1) % lp->rx_bd_num); in axienet_dma_bd_init()
325 lp->rx_bd_v[i].next = lower_32_bits(addr); in axienet_dma_bd_init()
326 if (lp->features & XAE_FEATURE_DMA_64BIT) in axienet_dma_bd_init()
327 lp->rx_bd_v[i].next_msb = upper_32_bits(addr); in axienet_dma_bd_init()
329 skb = netdev_alloc_skb_ip_align(ndev, lp->max_frm_size); in axienet_dma_bd_init()
333 lp->rx_bd_v[i].skb = skb; in axienet_dma_bd_init()
334 addr = dma_map_single(lp->dev, skb->data, in axienet_dma_bd_init()
335 lp->max_frm_size, DMA_FROM_DEVICE); in axienet_dma_bd_init()
336 if (dma_mapping_error(lp->dev, addr)) { in axienet_dma_bd_init()
340 desc_set_phys_addr(lp, addr, &lp->rx_bd_v[i]); in axienet_dma_bd_init()
342 lp->rx_bd_v[i].cntrl = lp->max_frm_size; in axienet_dma_bd_init()
345 axienet_dma_start(lp); in axienet_dma_bd_init()
364 struct axienet_local *lp = netdev_priv(ndev); in axienet_set_mac_address() local
372 axienet_iow(lp, XAE_UAW0_OFFSET, in axienet_set_mac_address()
377 axienet_iow(lp, XAE_UAW1_OFFSET, in axienet_set_mac_address()
378 (((axienet_ior(lp, XAE_UAW1_OFFSET)) & in axienet_set_mac_address()
417 struct axienet_local *lp = netdev_priv(ndev); in axienet_set_multicast_list() local
426 reg = axienet_ior(lp, XAE_FMI_OFFSET); in axienet_set_multicast_list()
428 axienet_iow(lp, XAE_FMI_OFFSET, reg); in axienet_set_multicast_list()
446 reg = axienet_ior(lp, XAE_FMI_OFFSET) & 0xFFFFFF00; in axienet_set_multicast_list()
449 axienet_iow(lp, XAE_FMI_OFFSET, reg); in axienet_set_multicast_list()
450 axienet_iow(lp, XAE_AF0_OFFSET, af0reg); in axienet_set_multicast_list()
451 axienet_iow(lp, XAE_AF1_OFFSET, af1reg); in axienet_set_multicast_list()
455 reg = axienet_ior(lp, XAE_FMI_OFFSET); in axienet_set_multicast_list()
458 axienet_iow(lp, XAE_FMI_OFFSET, reg); in axienet_set_multicast_list()
461 reg = axienet_ior(lp, XAE_FMI_OFFSET) & 0xFFFFFF00; in axienet_set_multicast_list()
464 axienet_iow(lp, XAE_FMI_OFFSET, reg); in axienet_set_multicast_list()
465 axienet_iow(lp, XAE_AF0_OFFSET, 0); in axienet_set_multicast_list()
466 axienet_iow(lp, XAE_AF1_OFFSET, 0); in axienet_set_multicast_list()
487 struct axienet_local *lp = netdev_priv(ndev); in axienet_setoptions() local
491 reg = ((axienet_ior(lp, tp->reg)) & ~(tp->m_or)); in axienet_setoptions()
494 axienet_iow(lp, tp->reg, reg); in axienet_setoptions()
498 lp->options |= options; in axienet_setoptions()
501 static int __axienet_device_reset(struct axienet_local *lp) in __axienet_device_reset() argument
513 axienet_dma_out32(lp, XAXIDMA_TX_CR_OFFSET, XAXIDMA_CR_RESET_MASK); in __axienet_device_reset()
516 DELAY_OF_ONE_MILLISEC, 50000, false, lp, in __axienet_device_reset()
519 dev_err(lp->dev, "%s: DMA reset timeout!\n", __func__); in __axienet_device_reset()
526 DELAY_OF_ONE_MILLISEC, 50000, false, lp, in __axienet_device_reset()
529 dev_err(lp->dev, "%s: timeout waiting for PhyRstCmplt\n", __func__); in __axienet_device_reset()
538 * @lp: Pointer to the axienet_local structure
540 static void axienet_dma_stop(struct axienet_local *lp) in axienet_dma_stop() argument
545 cr = axienet_dma_in32(lp, XAXIDMA_RX_CR_OFFSET); in axienet_dma_stop()
547 axienet_dma_out32(lp, XAXIDMA_RX_CR_OFFSET, cr); in axienet_dma_stop()
548 synchronize_irq(lp->rx_irq); in axienet_dma_stop()
550 cr = axienet_dma_in32(lp, XAXIDMA_TX_CR_OFFSET); in axienet_dma_stop()
552 axienet_dma_out32(lp, XAXIDMA_TX_CR_OFFSET, cr); in axienet_dma_stop()
553 synchronize_irq(lp->tx_irq); in axienet_dma_stop()
556 sr = axienet_dma_in32(lp, XAXIDMA_RX_SR_OFFSET); in axienet_dma_stop()
559 sr = axienet_dma_in32(lp, XAXIDMA_RX_SR_OFFSET); in axienet_dma_stop()
562 sr = axienet_dma_in32(lp, XAXIDMA_TX_SR_OFFSET); in axienet_dma_stop()
565 sr = axienet_dma_in32(lp, XAXIDMA_TX_SR_OFFSET); in axienet_dma_stop()
569 axienet_lock_mii(lp); in axienet_dma_stop()
570 __axienet_device_reset(lp); in axienet_dma_stop()
571 axienet_unlock_mii(lp); in axienet_dma_stop()
589 struct axienet_local *lp = netdev_priv(ndev); in axienet_device_reset() local
592 ret = __axienet_device_reset(lp); in axienet_device_reset()
596 lp->max_frm_size = XAE_MAX_VLAN_FRAME_SIZE; in axienet_device_reset()
597 lp->options |= XAE_OPTION_VLAN; in axienet_device_reset()
598 lp->options &= (~XAE_OPTION_JUMBO); in axienet_device_reset()
602 lp->max_frm_size = ndev->mtu + VLAN_ETH_HLEN + in axienet_device_reset()
605 if (lp->max_frm_size <= lp->rxmem) in axienet_device_reset()
606 lp->options |= XAE_OPTION_JUMBO; in axienet_device_reset()
616 axienet_status = axienet_ior(lp, XAE_RCW1_OFFSET); in axienet_device_reset()
618 axienet_iow(lp, XAE_RCW1_OFFSET, axienet_status); in axienet_device_reset()
620 axienet_status = axienet_ior(lp, XAE_IP_OFFSET); in axienet_device_reset()
622 axienet_iow(lp, XAE_IS_OFFSET, XAE_INT_RXRJECT_MASK); in axienet_device_reset()
623 axienet_iow(lp, XAE_IE_OFFSET, lp->eth_irq > 0 ? in axienet_device_reset()
626 axienet_iow(lp, XAE_FCC_OFFSET, XAE_FCC_FCRX_MASK); in axienet_device_reset()
631 axienet_setoptions(ndev, lp->options & in axienet_device_reset()
635 axienet_setoptions(ndev, lp->options); in axienet_device_reset()
644 * @lp: Pointer to the axienet_local structure
656 static int axienet_free_tx_chain(struct axienet_local *lp, u32 first_bd, in axienet_free_tx_chain() argument
665 cur_p = &lp->tx_bd_v[(first_bd + i) % lp->tx_bd_num]; in axienet_free_tx_chain()
676 phys = desc_get_phys_addr(lp, cur_p); in axienet_free_tx_chain()
677 dma_unmap_single(lp->dev, phys, in axienet_free_tx_chain()
703 * @lp: Pointer to the axienet_local structure
714 static inline int axienet_check_tx_bd_space(struct axienet_local *lp, in axienet_check_tx_bd_space() argument
721 cur_p = &lp->tx_bd_v[(READ_ONCE(lp->tx_bd_tail) + num_frag) % in axienet_check_tx_bd_space()
722 lp->tx_bd_num]; in axienet_check_tx_bd_space()
744 struct axienet_local *lp = container_of(napi, struct axienet_local, napi_tx); in axienet_tx_poll() local
745 struct net_device *ndev = lp->ndev; in axienet_tx_poll()
749 packets = axienet_free_tx_chain(lp, lp->tx_bd_ci, budget, false, &size, budget); in axienet_tx_poll()
752 lp->tx_bd_ci += packets; in axienet_tx_poll()
753 if (lp->tx_bd_ci >= lp->tx_bd_num) in axienet_tx_poll()
754 lp->tx_bd_ci %= lp->tx_bd_num; in axienet_tx_poll()
756 u64_stats_update_begin(&lp->tx_stat_sync); in axienet_tx_poll()
757 u64_stats_add(&lp->tx_packets, packets); in axienet_tx_poll()
758 u64_stats_add(&lp->tx_bytes, size); in axienet_tx_poll()
759 u64_stats_update_end(&lp->tx_stat_sync); in axienet_tx_poll()
764 if (!axienet_check_tx_bd_space(lp, MAX_SKB_FRAGS + 1)) in axienet_tx_poll()
773 axienet_dma_out32(lp, XAXIDMA_TX_CR_OFFSET, lp->tx_dma_cr); in axienet_tx_poll()
801 struct axienet_local *lp = netdev_priv(ndev); in axienet_start_xmit() local
804 orig_tail_ptr = lp->tx_bd_tail; in axienet_start_xmit()
808 cur_p = &lp->tx_bd_v[orig_tail_ptr]; in axienet_start_xmit()
810 if (axienet_check_tx_bd_space(lp, num_frag + 1)) { in axienet_start_xmit()
822 if (lp->features & XAE_FEATURE_FULL_TX_CSUM) { in axienet_start_xmit()
825 } else if (lp->features & XAE_FEATURE_PARTIAL_RX_CSUM) { in axienet_start_xmit()
836 phys = dma_map_single(lp->dev, skb->data, in axienet_start_xmit()
838 if (unlikely(dma_mapping_error(lp->dev, phys))) { in axienet_start_xmit()
844 desc_set_phys_addr(lp, phys, cur_p); in axienet_start_xmit()
848 if (++new_tail_ptr >= lp->tx_bd_num) in axienet_start_xmit()
850 cur_p = &lp->tx_bd_v[new_tail_ptr]; in axienet_start_xmit()
852 phys = dma_map_single(lp->dev, in axienet_start_xmit()
856 if (unlikely(dma_mapping_error(lp->dev, phys))) { in axienet_start_xmit()
860 axienet_free_tx_chain(lp, orig_tail_ptr, ii + 1, in axienet_start_xmit()
864 desc_set_phys_addr(lp, phys, cur_p); in axienet_start_xmit()
871 tail_p = lp->tx_bd_p + sizeof(*lp->tx_bd_v) * new_tail_ptr; in axienet_start_xmit()
872 if (++new_tail_ptr >= lp->tx_bd_num) in axienet_start_xmit()
874 WRITE_ONCE(lp->tx_bd_tail, new_tail_ptr); in axienet_start_xmit()
877 axienet_dma_out_addr(lp, XAXIDMA_TX_TDESC_OFFSET, tail_p); in axienet_start_xmit()
880 if (axienet_check_tx_bd_space(lp, MAX_SKB_FRAGS + 1)) { in axienet_start_xmit()
887 if (!axienet_check_tx_bd_space(lp, MAX_SKB_FRAGS + 1)) in axienet_start_xmit()
910 struct axienet_local *lp = container_of(napi, struct axienet_local, napi_rx); in axienet_rx_poll() local
912 cur_p = &lp->rx_bd_v[lp->rx_bd_ci]; in axienet_rx_poll()
931 phys = desc_get_phys_addr(lp, cur_p); in axienet_rx_poll()
932 dma_unmap_single(lp->dev, phys, lp->max_frm_size, in axienet_rx_poll()
936 skb->protocol = eth_type_trans(skb, lp->ndev); in axienet_rx_poll()
941 if (lp->features & XAE_FEATURE_FULL_RX_CSUM) { in axienet_rx_poll()
948 } else if ((lp->features & XAE_FEATURE_PARTIAL_RX_CSUM) != 0 && in axienet_rx_poll()
961 new_skb = napi_alloc_skb(napi, lp->max_frm_size); in axienet_rx_poll()
965 phys = dma_map_single(lp->dev, new_skb->data, in axienet_rx_poll()
966 lp->max_frm_size, in axienet_rx_poll()
968 if (unlikely(dma_mapping_error(lp->dev, phys))) { in axienet_rx_poll()
970 netdev_err(lp->ndev, "RX DMA mapping error\n"); in axienet_rx_poll()
974 desc_set_phys_addr(lp, phys, cur_p); in axienet_rx_poll()
976 cur_p->cntrl = lp->max_frm_size; in axienet_rx_poll()
983 tail_p = lp->rx_bd_p + sizeof(*lp->rx_bd_v) * lp->rx_bd_ci; in axienet_rx_poll()
985 if (++lp->rx_bd_ci >= lp->rx_bd_num) in axienet_rx_poll()
986 lp->rx_bd_ci = 0; in axienet_rx_poll()
987 cur_p = &lp->rx_bd_v[lp->rx_bd_ci]; in axienet_rx_poll()
990 u64_stats_update_begin(&lp->rx_stat_sync); in axienet_rx_poll()
991 u64_stats_add(&lp->rx_packets, packets); in axienet_rx_poll()
992 u64_stats_add(&lp->rx_bytes, size); in axienet_rx_poll()
993 u64_stats_update_end(&lp->rx_stat_sync); in axienet_rx_poll()
996 axienet_dma_out_addr(lp, XAXIDMA_RX_TDESC_OFFSET, tail_p); in axienet_rx_poll()
1003 axienet_dma_out32(lp, XAXIDMA_RX_CR_OFFSET, lp->rx_dma_cr); in axienet_rx_poll()
1022 struct axienet_local *lp = netdev_priv(ndev); in axienet_tx_irq() local
1024 status = axienet_dma_in32(lp, XAXIDMA_TX_SR_OFFSET); in axienet_tx_irq()
1029 axienet_dma_out32(lp, XAXIDMA_TX_SR_OFFSET, status); in axienet_tx_irq()
1034 (lp->tx_bd_v[lp->tx_bd_ci]).phys_msb, in axienet_tx_irq()
1035 (lp->tx_bd_v[lp->tx_bd_ci]).phys); in axienet_tx_irq()
1036 schedule_work(&lp->dma_err_task); in axienet_tx_irq()
1041 u32 cr = lp->tx_dma_cr; in axienet_tx_irq()
1044 axienet_dma_out32(lp, XAXIDMA_TX_CR_OFFSET, cr); in axienet_tx_irq()
1046 napi_schedule(&lp->napi_tx); in axienet_tx_irq()
1066 struct axienet_local *lp = netdev_priv(ndev); in axienet_rx_irq() local
1068 status = axienet_dma_in32(lp, XAXIDMA_RX_SR_OFFSET); in axienet_rx_irq()
1073 axienet_dma_out32(lp, XAXIDMA_RX_SR_OFFSET, status); in axienet_rx_irq()
1078 (lp->rx_bd_v[lp->rx_bd_ci]).phys_msb, in axienet_rx_irq()
1079 (lp->rx_bd_v[lp->rx_bd_ci]).phys); in axienet_rx_irq()
1080 schedule_work(&lp->dma_err_task); in axienet_rx_irq()
1085 u32 cr = lp->rx_dma_cr; in axienet_rx_irq()
1088 axienet_dma_out32(lp, XAXIDMA_RX_CR_OFFSET, cr); in axienet_rx_irq()
1090 napi_schedule(&lp->napi_rx); in axienet_rx_irq()
1108 struct axienet_local *lp = netdev_priv(ndev); in axienet_eth_irq() local
1111 pending = axienet_ior(lp, XAE_IP_OFFSET); in axienet_eth_irq()
1121 axienet_iow(lp, XAE_IS_OFFSET, pending); in axienet_eth_irq()
1143 struct axienet_local *lp = netdev_priv(ndev); in axienet_open() local
1151 axienet_lock_mii(lp); in axienet_open()
1153 axienet_unlock_mii(lp); in axienet_open()
1155 ret = phylink_of_phy_connect(lp->phylink, lp->dev->of_node, 0); in axienet_open()
1157 dev_err(lp->dev, "phylink_of_phy_connect() failed: %d\n", ret); in axienet_open()
1161 phylink_start(lp->phylink); in axienet_open()
1164 INIT_WORK(&lp->dma_err_task, axienet_dma_err_handler); in axienet_open()
1166 napi_enable(&lp->napi_rx); in axienet_open()
1167 napi_enable(&lp->napi_tx); in axienet_open()
1170 ret = request_irq(lp->tx_irq, axienet_tx_irq, IRQF_SHARED, in axienet_open()
1175 ret = request_irq(lp->rx_irq, axienet_rx_irq, IRQF_SHARED, in axienet_open()
1180 if (lp->eth_irq > 0) { in axienet_open()
1181 ret = request_irq(lp->eth_irq, axienet_eth_irq, IRQF_SHARED, in axienet_open()
1190 free_irq(lp->rx_irq, ndev); in axienet_open()
1192 free_irq(lp->tx_irq, ndev); in axienet_open()
1194 napi_disable(&lp->napi_tx); in axienet_open()
1195 napi_disable(&lp->napi_rx); in axienet_open()
1196 phylink_stop(lp->phylink); in axienet_open()
1197 phylink_disconnect_phy(lp->phylink); in axienet_open()
1198 cancel_work_sync(&lp->dma_err_task); in axienet_open()
1199 dev_err(lp->dev, "request_irq() failed\n"); in axienet_open()
1215 struct axienet_local *lp = netdev_priv(ndev); in axienet_stop() local
1219 napi_disable(&lp->napi_tx); in axienet_stop()
1220 napi_disable(&lp->napi_rx); in axienet_stop()
1222 phylink_stop(lp->phylink); in axienet_stop()
1223 phylink_disconnect_phy(lp->phylink); in axienet_stop()
1225 axienet_setoptions(ndev, lp->options & in axienet_stop()
1228 axienet_dma_stop(lp); in axienet_stop()
1230 axienet_iow(lp, XAE_IE_OFFSET, 0); in axienet_stop()
1232 cancel_work_sync(&lp->dma_err_task); in axienet_stop()
1234 if (lp->eth_irq > 0) in axienet_stop()
1235 free_irq(lp->eth_irq, ndev); in axienet_stop()
1236 free_irq(lp->tx_irq, ndev); in axienet_stop()
1237 free_irq(lp->rx_irq, ndev); in axienet_stop()
1256 struct axienet_local *lp = netdev_priv(ndev); in axienet_change_mtu() local
1262 XAE_TRL_SIZE) > lp->rxmem) in axienet_change_mtu()
1280 struct axienet_local *lp = netdev_priv(ndev); in axienet_poll_controller() local
1281 disable_irq(lp->tx_irq); in axienet_poll_controller()
1282 disable_irq(lp->rx_irq); in axienet_poll_controller()
1283 axienet_rx_irq(lp->tx_irq, ndev); in axienet_poll_controller()
1284 axienet_tx_irq(lp->rx_irq, ndev); in axienet_poll_controller()
1285 enable_irq(lp->tx_irq); in axienet_poll_controller()
1286 enable_irq(lp->rx_irq); in axienet_poll_controller()
1292 struct axienet_local *lp = netdev_priv(dev); in axienet_ioctl() local
1297 return phylink_mii_ioctl(lp->phylink, rq, cmd); in axienet_ioctl()
1303 struct axienet_local *lp = netdev_priv(dev); in axienet_get_stats64() local
1309 start = u64_stats_fetch_begin(&lp->rx_stat_sync); in axienet_get_stats64()
1310 stats->rx_packets = u64_stats_read(&lp->rx_packets); in axienet_get_stats64()
1311 stats->rx_bytes = u64_stats_read(&lp->rx_bytes); in axienet_get_stats64()
1312 } while (u64_stats_fetch_retry(&lp->rx_stat_sync, start)); in axienet_get_stats64()
1315 start = u64_stats_fetch_begin(&lp->tx_stat_sync); in axienet_get_stats64()
1316 stats->tx_packets = u64_stats_read(&lp->tx_packets); in axienet_get_stats64()
1317 stats->tx_bytes = u64_stats_read(&lp->tx_bytes); in axienet_get_stats64()
1318 } while (u64_stats_fetch_retry(&lp->tx_stat_sync, start)); in axienet_get_stats64()
1381 struct axienet_local *lp = netdev_priv(ndev); in axienet_ethtools_get_regs() local
1387 data[0] = axienet_ior(lp, XAE_RAF_OFFSET); in axienet_ethtools_get_regs()
1388 data[1] = axienet_ior(lp, XAE_TPF_OFFSET); in axienet_ethtools_get_regs()
1389 data[2] = axienet_ior(lp, XAE_IFGP_OFFSET); in axienet_ethtools_get_regs()
1390 data[3] = axienet_ior(lp, XAE_IS_OFFSET); in axienet_ethtools_get_regs()
1391 data[4] = axienet_ior(lp, XAE_IP_OFFSET); in axienet_ethtools_get_regs()
1392 data[5] = axienet_ior(lp, XAE_IE_OFFSET); in axienet_ethtools_get_regs()
1393 data[6] = axienet_ior(lp, XAE_TTAG_OFFSET); in axienet_ethtools_get_regs()
1394 data[7] = axienet_ior(lp, XAE_RTAG_OFFSET); in axienet_ethtools_get_regs()
1395 data[8] = axienet_ior(lp, XAE_UAWL_OFFSET); in axienet_ethtools_get_regs()
1396 data[9] = axienet_ior(lp, XAE_UAWU_OFFSET); in axienet_ethtools_get_regs()
1397 data[10] = axienet_ior(lp, XAE_TPID0_OFFSET); in axienet_ethtools_get_regs()
1398 data[11] = axienet_ior(lp, XAE_TPID1_OFFSET); in axienet_ethtools_get_regs()
1399 data[12] = axienet_ior(lp, XAE_PPST_OFFSET); in axienet_ethtools_get_regs()
1400 data[13] = axienet_ior(lp, XAE_RCW0_OFFSET); in axienet_ethtools_get_regs()
1401 data[14] = axienet_ior(lp, XAE_RCW1_OFFSET); in axienet_ethtools_get_regs()
1402 data[15] = axienet_ior(lp, XAE_TC_OFFSET); in axienet_ethtools_get_regs()
1403 data[16] = axienet_ior(lp, XAE_FCC_OFFSET); in axienet_ethtools_get_regs()
1404 data[17] = axienet_ior(lp, XAE_EMMC_OFFSET); in axienet_ethtools_get_regs()
1405 data[18] = axienet_ior(lp, XAE_PHYC_OFFSET); in axienet_ethtools_get_regs()
1406 data[19] = axienet_ior(lp, XAE_MDIO_MC_OFFSET); in axienet_ethtools_get_regs()
1407 data[20] = axienet_ior(lp, XAE_MDIO_MCR_OFFSET); in axienet_ethtools_get_regs()
1408 data[21] = axienet_ior(lp, XAE_MDIO_MWD_OFFSET); in axienet_ethtools_get_regs()
1409 data[22] = axienet_ior(lp, XAE_MDIO_MRD_OFFSET); in axienet_ethtools_get_regs()
1410 data[27] = axienet_ior(lp, XAE_UAW0_OFFSET); in axienet_ethtools_get_regs()
1411 data[28] = axienet_ior(lp, XAE_UAW1_OFFSET); in axienet_ethtools_get_regs()
1412 data[29] = axienet_ior(lp, XAE_FMI_OFFSET); in axienet_ethtools_get_regs()
1413 data[30] = axienet_ior(lp, XAE_AF0_OFFSET); in axienet_ethtools_get_regs()
1414 data[31] = axienet_ior(lp, XAE_AF1_OFFSET); in axienet_ethtools_get_regs()
1415 data[32] = axienet_dma_in32(lp, XAXIDMA_TX_CR_OFFSET); in axienet_ethtools_get_regs()
1416 data[33] = axienet_dma_in32(lp, XAXIDMA_TX_SR_OFFSET); in axienet_ethtools_get_regs()
1417 data[34] = axienet_dma_in32(lp, XAXIDMA_TX_CDESC_OFFSET); in axienet_ethtools_get_regs()
1418 data[35] = axienet_dma_in32(lp, XAXIDMA_TX_TDESC_OFFSET); in axienet_ethtools_get_regs()
1419 data[36] = axienet_dma_in32(lp, XAXIDMA_RX_CR_OFFSET); in axienet_ethtools_get_regs()
1420 data[37] = axienet_dma_in32(lp, XAXIDMA_RX_SR_OFFSET); in axienet_ethtools_get_regs()
1421 data[38] = axienet_dma_in32(lp, XAXIDMA_RX_CDESC_OFFSET); in axienet_ethtools_get_regs()
1422 data[39] = axienet_dma_in32(lp, XAXIDMA_RX_TDESC_OFFSET); in axienet_ethtools_get_regs()
1431 struct axienet_local *lp = netdev_priv(ndev); in axienet_ethtools_get_ringparam() local
1437 ering->rx_pending = lp->rx_bd_num; in axienet_ethtools_get_ringparam()
1440 ering->tx_pending = lp->tx_bd_num; in axienet_ethtools_get_ringparam()
1449 struct axienet_local *lp = netdev_priv(ndev); in axienet_ethtools_set_ringparam() local
1461 lp->rx_bd_num = ering->rx_pending; in axienet_ethtools_set_ringparam()
1462 lp->tx_bd_num = ering->tx_pending; in axienet_ethtools_set_ringparam()
1479 struct axienet_local *lp = netdev_priv(ndev); in axienet_ethtools_get_pauseparam() local
1481 phylink_ethtool_get_pauseparam(lp->phylink, epauseparm); in axienet_ethtools_get_pauseparam()
1500 struct axienet_local *lp = netdev_priv(ndev); in axienet_ethtools_set_pauseparam() local
1502 return phylink_ethtool_set_pauseparam(lp->phylink, epauseparm); in axienet_ethtools_set_pauseparam()
1524 struct axienet_local *lp = netdev_priv(ndev); in axienet_ethtools_get_coalesce() local
1526 ecoalesce->rx_max_coalesced_frames = lp->coalesce_count_rx; in axienet_ethtools_get_coalesce()
1527 ecoalesce->rx_coalesce_usecs = lp->coalesce_usec_rx; in axienet_ethtools_get_coalesce()
1528 ecoalesce->tx_max_coalesced_frames = lp->coalesce_count_tx; in axienet_ethtools_get_coalesce()
1529 ecoalesce->tx_coalesce_usecs = lp->coalesce_usec_tx; in axienet_ethtools_get_coalesce()
1552 struct axienet_local *lp = netdev_priv(ndev); in axienet_ethtools_set_coalesce() local
1561 lp->coalesce_count_rx = ecoalesce->rx_max_coalesced_frames; in axienet_ethtools_set_coalesce()
1563 lp->coalesce_usec_rx = ecoalesce->rx_coalesce_usecs; in axienet_ethtools_set_coalesce()
1565 lp->coalesce_count_tx = ecoalesce->tx_max_coalesced_frames; in axienet_ethtools_set_coalesce()
1567 lp->coalesce_usec_tx = ecoalesce->tx_coalesce_usecs; in axienet_ethtools_set_coalesce()
1576 struct axienet_local *lp = netdev_priv(ndev); in axienet_ethtools_get_link_ksettings() local
1578 return phylink_ethtool_ksettings_get(lp->phylink, cmd); in axienet_ethtools_get_link_ksettings()
1585 struct axienet_local *lp = netdev_priv(ndev); in axienet_ethtools_set_link_ksettings() local
1587 return phylink_ethtool_ksettings_set(lp->phylink, cmd); in axienet_ethtools_set_link_ksettings()
1592 struct axienet_local *lp = netdev_priv(dev); in axienet_ethtools_nway_reset() local
1594 return phylink_ethtool_nway_reset(lp->phylink); in axienet_ethtools_nway_reset()
1642 struct axienet_local *lp = netdev_priv(ndev); in axienet_pcs_config() local
1645 if (lp->switch_x_sgmii) { in axienet_pcs_config()
1675 struct axienet_local *lp = netdev_priv(ndev); in axienet_mac_select_pcs() local
1679 return &lp->pcs; in axienet_mac_select_pcs()
1704 struct axienet_local *lp = netdev_priv(ndev); in axienet_mac_link_up() local
1707 emmc_reg = axienet_ior(lp, XAE_EMMC_OFFSET); in axienet_mac_link_up()
1726 axienet_iow(lp, XAE_EMMC_OFFSET, emmc_reg); in axienet_mac_link_up()
1728 fcc_reg = axienet_ior(lp, XAE_FCC_OFFSET); in axienet_mac_link_up()
1737 axienet_iow(lp, XAE_FCC_OFFSET, fcc_reg); in axienet_mac_link_up()
1759 struct axienet_local *lp = container_of(work, struct axienet_local, in axienet_dma_err_handler() local
1761 struct net_device *ndev = lp->ndev; in axienet_dma_err_handler()
1763 napi_disable(&lp->napi_tx); in axienet_dma_err_handler()
1764 napi_disable(&lp->napi_rx); in axienet_dma_err_handler()
1766 axienet_setoptions(ndev, lp->options & in axienet_dma_err_handler()
1769 axienet_dma_stop(lp); in axienet_dma_err_handler()
1771 for (i = 0; i < lp->tx_bd_num; i++) { in axienet_dma_err_handler()
1772 cur_p = &lp->tx_bd_v[i]; in axienet_dma_err_handler()
1774 dma_addr_t addr = desc_get_phys_addr(lp, cur_p); in axienet_dma_err_handler()
1776 dma_unmap_single(lp->dev, addr, in axienet_dma_err_handler()
1795 for (i = 0; i < lp->rx_bd_num; i++) { in axienet_dma_err_handler()
1796 cur_p = &lp->rx_bd_v[i]; in axienet_dma_err_handler()
1805 lp->tx_bd_ci = 0; in axienet_dma_err_handler()
1806 lp->tx_bd_tail = 0; in axienet_dma_err_handler()
1807 lp->rx_bd_ci = 0; in axienet_dma_err_handler()
1809 axienet_dma_start(lp); in axienet_dma_err_handler()
1811 axienet_status = axienet_ior(lp, XAE_RCW1_OFFSET); in axienet_dma_err_handler()
1813 axienet_iow(lp, XAE_RCW1_OFFSET, axienet_status); in axienet_dma_err_handler()
1815 axienet_status = axienet_ior(lp, XAE_IP_OFFSET); in axienet_dma_err_handler()
1817 axienet_iow(lp, XAE_IS_OFFSET, XAE_INT_RXRJECT_MASK); in axienet_dma_err_handler()
1818 axienet_iow(lp, XAE_IE_OFFSET, lp->eth_irq > 0 ? in axienet_dma_err_handler()
1820 axienet_iow(lp, XAE_FCC_OFFSET, XAE_FCC_FCRX_MASK); in axienet_dma_err_handler()
1825 axienet_setoptions(ndev, lp->options & in axienet_dma_err_handler()
1829 axienet_setoptions(ndev, lp->options); in axienet_dma_err_handler()
1830 napi_enable(&lp->napi_rx); in axienet_dma_err_handler()
1831 napi_enable(&lp->napi_tx); in axienet_dma_err_handler()
1850 struct axienet_local *lp; in axienet_probe() local
1857 ndev = alloc_etherdev(sizeof(*lp)); in axienet_probe()
1873 lp = netdev_priv(ndev); in axienet_probe()
1874 lp->ndev = ndev; in axienet_probe()
1875 lp->dev = &pdev->dev; in axienet_probe()
1876 lp->options = XAE_OPTION_DEFAULTS; in axienet_probe()
1877 lp->rx_bd_num = RX_BD_NUM_DEFAULT; in axienet_probe()
1878 lp->tx_bd_num = TX_BD_NUM_DEFAULT; in axienet_probe()
1880 u64_stats_init(&lp->rx_stat_sync); in axienet_probe()
1881 u64_stats_init(&lp->tx_stat_sync); in axienet_probe()
1883 netif_napi_add(ndev, &lp->napi_rx, axienet_rx_poll); in axienet_probe()
1884 netif_napi_add(ndev, &lp->napi_tx, axienet_tx_poll); in axienet_probe()
1886 lp->axi_clk = devm_clk_get_optional(&pdev->dev, "s_axi_lite_clk"); in axienet_probe()
1887 if (!lp->axi_clk) { in axienet_probe()
1891 lp->axi_clk = devm_clk_get_optional(&pdev->dev, NULL); in axienet_probe()
1893 if (IS_ERR(lp->axi_clk)) { in axienet_probe()
1894 ret = PTR_ERR(lp->axi_clk); in axienet_probe()
1897 ret = clk_prepare_enable(lp->axi_clk); in axienet_probe()
1903 lp->misc_clks[0].id = "axis_clk"; in axienet_probe()
1904 lp->misc_clks[1].id = "ref_clk"; in axienet_probe()
1905 lp->misc_clks[2].id = "mgt_clk"; in axienet_probe()
1907 ret = devm_clk_bulk_get_optional(&pdev->dev, XAE_NUM_MISC_CLOCKS, lp->misc_clks); in axienet_probe()
1911 ret = clk_bulk_prepare_enable(XAE_NUM_MISC_CLOCKS, lp->misc_clks); in axienet_probe()
1916 lp->regs = devm_platform_get_and_ioremap_resource(pdev, 0, &ethres); in axienet_probe()
1917 if (IS_ERR(lp->regs)) { in axienet_probe()
1918 ret = PTR_ERR(lp->regs); in axienet_probe()
1921 lp->regs_start = ethres->start; in axienet_probe()
1924 lp->features = 0; in axienet_probe()
1930 lp->csum_offload_on_tx_path = in axienet_probe()
1932 lp->features |= XAE_FEATURE_PARTIAL_TX_CSUM; in axienet_probe()
1937 lp->csum_offload_on_tx_path = in axienet_probe()
1939 lp->features |= XAE_FEATURE_FULL_TX_CSUM; in axienet_probe()
1944 lp->csum_offload_on_tx_path = XAE_NO_CSUM_OFFLOAD; in axienet_probe()
1951 lp->csum_offload_on_rx_path = in axienet_probe()
1953 lp->features |= XAE_FEATURE_PARTIAL_RX_CSUM; in axienet_probe()
1956 lp->csum_offload_on_rx_path = in axienet_probe()
1958 lp->features |= XAE_FEATURE_FULL_RX_CSUM; in axienet_probe()
1961 lp->csum_offload_on_rx_path = XAE_NO_CSUM_OFFLOAD; in axienet_probe()
1970 of_property_read_u32(pdev->dev.of_node, "xlnx,rxmem", &lp->rxmem); in axienet_probe()
1972 lp->switch_x_sgmii = of_property_read_bool(pdev->dev.of_node, in axienet_probe()
1981 lp->phy_mode = PHY_INTERFACE_MODE_MII; in axienet_probe()
1984 lp->phy_mode = PHY_INTERFACE_MODE_GMII; in axienet_probe()
1987 lp->phy_mode = PHY_INTERFACE_MODE_RGMII_ID; in axienet_probe()
1990 lp->phy_mode = PHY_INTERFACE_MODE_SGMII; in axienet_probe()
1993 lp->phy_mode = PHY_INTERFACE_MODE_1000BASEX; in axienet_probe()
2000 ret = of_get_phy_mode(pdev->dev.of_node, &lp->phy_mode); in axienet_probe()
2004 if (lp->switch_x_sgmii && lp->phy_mode != PHY_INTERFACE_MODE_SGMII && in axienet_probe()
2005 lp->phy_mode != PHY_INTERFACE_MODE_1000BASEX) { in axienet_probe()
2023 lp->dma_regs = devm_ioremap_resource(&pdev->dev, in axienet_probe()
2025 lp->rx_irq = irq_of_parse_and_map(np, 1); in axienet_probe()
2026 lp->tx_irq = irq_of_parse_and_map(np, 0); in axienet_probe()
2028 lp->eth_irq = platform_get_irq_optional(pdev, 0); in axienet_probe()
2031 lp->dma_regs = devm_platform_get_and_ioremap_resource(pdev, 1, NULL); in axienet_probe()
2032 lp->rx_irq = platform_get_irq(pdev, 1); in axienet_probe()
2033 lp->tx_irq = platform_get_irq(pdev, 0); in axienet_probe()
2034 lp->eth_irq = platform_get_irq_optional(pdev, 2); in axienet_probe()
2036 if (IS_ERR(lp->dma_regs)) { in axienet_probe()
2038 ret = PTR_ERR(lp->dma_regs); in axienet_probe()
2041 if ((lp->rx_irq <= 0) || (lp->tx_irq <= 0)) { in axienet_probe()
2048 ret = __axienet_device_reset(lp); in axienet_probe()
2060 if ((axienet_ior(lp, XAE_ID_OFFSET) >> 24) >= 0x9) { in axienet_probe()
2061 void __iomem *desc = lp->dma_regs + XAXIDMA_TX_CDESC_OFFSET + 4; in axienet_probe()
2067 lp->features |= XAE_FEATURE_DMA_64BIT; in axienet_probe()
2075 if (!IS_ENABLED(CONFIG_64BIT) && lp->features & XAE_FEATURE_DMA_64BIT) { in axienet_probe()
2088 if (lp->eth_irq <= 0) in axienet_probe()
2101 lp->coalesce_count_rx = XAXIDMA_DFT_RX_THRESHOLD; in axienet_probe()
2102 lp->coalesce_usec_rx = XAXIDMA_DFT_RX_USEC; in axienet_probe()
2103 lp->coalesce_count_tx = XAXIDMA_DFT_TX_THRESHOLD; in axienet_probe()
2104 lp->coalesce_usec_tx = XAXIDMA_DFT_TX_USEC; in axienet_probe()
2106 ret = axienet_mdio_setup(lp); in axienet_probe()
2111 if (lp->phy_mode == PHY_INTERFACE_MODE_SGMII || in axienet_probe()
2112 lp->phy_mode == PHY_INTERFACE_MODE_1000BASEX) { in axienet_probe()
2126 lp->pcs_phy = of_mdio_find_device(np); in axienet_probe()
2127 if (!lp->pcs_phy) { in axienet_probe()
2133 lp->pcs.ops = &axienet_pcs_ops; in axienet_probe()
2134 lp->pcs.neg_mode = true; in axienet_probe()
2135 lp->pcs.poll = true; in axienet_probe()
2138 lp->phylink_config.dev = &ndev->dev; in axienet_probe()
2139 lp->phylink_config.type = PHYLINK_NETDEV; in axienet_probe()
2140 lp->phylink_config.mac_capabilities = MAC_SYM_PAUSE | MAC_ASYM_PAUSE | in axienet_probe()
2143 __set_bit(lp->phy_mode, lp->phylink_config.supported_interfaces); in axienet_probe()
2144 if (lp->switch_x_sgmii) { in axienet_probe()
2146 lp->phylink_config.supported_interfaces); in axienet_probe()
2148 lp->phylink_config.supported_interfaces); in axienet_probe()
2151 lp->phylink = phylink_create(&lp->phylink_config, pdev->dev.fwnode, in axienet_probe()
2152 lp->phy_mode, in axienet_probe()
2154 if (IS_ERR(lp->phylink)) { in axienet_probe()
2155 ret = PTR_ERR(lp->phylink); in axienet_probe()
2160 ret = register_netdev(lp->ndev); in axienet_probe()
2162 dev_err(lp->dev, "register_netdev() error (%i)\n", ret); in axienet_probe()
2169 phylink_destroy(lp->phylink); in axienet_probe()
2172 if (lp->pcs_phy) in axienet_probe()
2173 put_device(&lp->pcs_phy->dev); in axienet_probe()
2174 if (lp->mii_bus) in axienet_probe()
2175 axienet_mdio_teardown(lp); in axienet_probe()
2177 clk_bulk_disable_unprepare(XAE_NUM_MISC_CLOCKS, lp->misc_clks); in axienet_probe()
2178 clk_disable_unprepare(lp->axi_clk); in axienet_probe()
2189 struct axienet_local *lp = netdev_priv(ndev); in axienet_remove() local
2193 if (lp->phylink) in axienet_remove()
2194 phylink_destroy(lp->phylink); in axienet_remove()
2196 if (lp->pcs_phy) in axienet_remove()
2197 put_device(&lp->pcs_phy->dev); in axienet_remove()
2199 axienet_mdio_teardown(lp); in axienet_remove()
2201 clk_bulk_disable_unprepare(XAE_NUM_MISC_CLOCKS, lp->misc_clks); in axienet_remove()
2202 clk_disable_unprepare(lp->axi_clk); in axienet_remove()