Lines Matching +full:m0 +full:- +full:gpios

1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* Applied Micro X-Gene SoC Ethernet Driver
28 for (i = 0; i < buf_pool->slots; i++) { in xgene_enet_init_bufpool()
29 raw_desc = &buf_pool->raw_desc16[i]; in xgene_enet_init_bufpool()
32 raw_desc->m0 = cpu_to_le64(i | in xgene_enet_init_bufpool()
33 SET_VAL(FPQNUM, buf_pool->dst_ring_num) | in xgene_enet_init_bufpool()
83 ndev = buf_pool->ndev; in xgene_enet_refill_pagepool()
86 slots = buf_pool->slots - 1; in xgene_enet_refill_pagepool()
87 tail = buf_pool->tail; in xgene_enet_refill_pagepool()
90 raw_desc = &buf_pool->raw_desc16[tail]; in xgene_enet_refill_pagepool()
94 return -ENOMEM; in xgene_enet_refill_pagepool()
100 return -ENOMEM; in xgene_enet_refill_pagepool()
104 raw_desc->m1 = cpu_to_le64(SET_VAL(DATAADDR, dma_addr) | in xgene_enet_refill_pagepool()
108 buf_pool->frag_page[tail] = page; in xgene_enet_refill_pagepool()
112 pdata->ring_ops->wr_cmd(buf_pool, nbuf); in xgene_enet_refill_pagepool()
113 buf_pool->tail = tail; in xgene_enet_refill_pagepool()
127 u32 tail = buf_pool->tail; in xgene_enet_refill_bufpool()
128 u32 slots = buf_pool->slots - 1; in xgene_enet_refill_bufpool()
132 ndev = buf_pool->ndev; in xgene_enet_refill_bufpool()
133 dev = ndev_to_dev(buf_pool->ndev); in xgene_enet_refill_bufpool()
140 raw_desc = &buf_pool->raw_desc16[tail]; in xgene_enet_refill_bufpool()
144 return -ENOMEM; in xgene_enet_refill_bufpool()
146 dma_addr = dma_map_single(dev, skb->data, len, DMA_FROM_DEVICE); in xgene_enet_refill_bufpool()
150 return -EINVAL; in xgene_enet_refill_bufpool()
153 buf_pool->rx_skb[tail] = skb; in xgene_enet_refill_bufpool()
155 raw_desc->m1 = cpu_to_le64(SET_VAL(DATAADDR, dma_addr) | in xgene_enet_refill_bufpool()
161 pdata->ring_ops->wr_cmd(buf_pool, nbuf); in xgene_enet_refill_bufpool()
162 buf_pool->tail = tail; in xgene_enet_refill_bufpool()
171 return (eth->h_proto == htons(ETH_P_8021Q)) ? VLAN_ETH_HLEN : ETH_HLEN; in xgene_enet_hdr_len()
176 struct device *dev = ndev_to_dev(buf_pool->ndev); in xgene_enet_delete_bufpool()
182 for (i = 0; i < buf_pool->slots; i++) { in xgene_enet_delete_bufpool()
183 if (buf_pool->rx_skb[i]) { in xgene_enet_delete_bufpool()
184 dev_kfree_skb_any(buf_pool->rx_skb[i]); in xgene_enet_delete_bufpool()
186 raw_desc = &buf_pool->raw_desc16[i]; in xgene_enet_delete_bufpool()
187 dma_addr = GET_VAL(DATAADDR, le64_to_cpu(raw_desc->m1)); in xgene_enet_delete_bufpool()
196 struct device *dev = ndev_to_dev(buf_pool->ndev); in xgene_enet_delete_pagepool()
202 for (i = 0; i < buf_pool->slots; i++) { in xgene_enet_delete_pagepool()
203 page = buf_pool->frag_page[i]; in xgene_enet_delete_pagepool()
205 dma_addr = buf_pool->frag_dma_addr[i]; in xgene_enet_delete_pagepool()
217 if (napi_schedule_prep(&rx_ring->napi)) { in xgene_enet_rx_irq()
219 __napi_schedule(&rx_ring->napi); in xgene_enet_rx_irq()
228 struct xgene_enet_pdata *pdata = netdev_priv(cp_ring->ndev); in xgene_enet_tx_completion()
238 skb_index = GET_VAL(USERINFO, le64_to_cpu(raw_desc->m0)); in xgene_enet_tx_completion()
239 skb = cp_ring->cp_skb[skb_index]; in xgene_enet_tx_completion()
240 frag_dma_addr = &cp_ring->frag_dma_addr[skb_index * MAX_SKB_FRAGS]; in xgene_enet_tx_completion()
242 dev = ndev_to_dev(cp_ring->ndev); in xgene_enet_tx_completion()
243 dma_unmap_single(dev, GET_VAL(DATAADDR, le64_to_cpu(raw_desc->m1)), in xgene_enet_tx_completion()
247 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { in xgene_enet_tx_completion()
248 frag = &skb_shinfo(skb)->frags[i]; in xgene_enet_tx_completion()
253 if (GET_BIT(ET, le64_to_cpu(raw_desc->m3))) { in xgene_enet_tx_completion()
254 mss_index = GET_VAL(MSS, le64_to_cpu(raw_desc->m3)); in xgene_enet_tx_completion()
255 spin_lock(&pdata->mss_lock); in xgene_enet_tx_completion()
256 pdata->mss_refcnt[mss_index]--; in xgene_enet_tx_completion()
257 spin_unlock(&pdata->mss_lock); in xgene_enet_tx_completion()
261 status = GET_VAL(LERR, le64_to_cpu(raw_desc->m0)); in xgene_enet_tx_completion()
263 cp_ring->tx_dropped++; in xgene_enet_tx_completion()
264 cp_ring->tx_errors++; in xgene_enet_tx_completion()
270 netdev_err(cp_ring->ndev, "completion skb is NULL\n"); in xgene_enet_tx_completion()
279 int mss_index = -EBUSY; in xgene_enet_setup_mss()
282 spin_lock(&pdata->mss_lock); in xgene_enet_setup_mss()
286 if (pdata->mss[i] == mss) { in xgene_enet_setup_mss()
287 pdata->mss_refcnt[i]++; in xgene_enet_setup_mss()
294 if (!pdata->mss_refcnt[i]) { in xgene_enet_setup_mss()
295 pdata->mss_refcnt[i]++; in xgene_enet_setup_mss()
296 pdata->mac_ops->set_mss(pdata, mss, i); in xgene_enet_setup_mss()
297 pdata->mss[i] = mss; in xgene_enet_setup_mss()
302 spin_unlock(&pdata->mss_lock); in xgene_enet_setup_mss()
309 struct net_device *ndev = skb->dev; in xgene_enet_work_msg()
317 ethhdr = xgene_enet_hdr_len(skb->data); in xgene_enet_work_msg()
319 if (unlikely(skb->protocol != htons(ETH_P_IP)) && in xgene_enet_work_msg()
320 unlikely(skb->protocol != htons(ETH_P_8021Q))) in xgene_enet_work_msg()
323 if (unlikely(!(skb->dev->features & NETIF_F_IP_CSUM))) in xgene_enet_work_msg()
330 if (likely(iph->protocol == IPPROTO_TCP)) { in xgene_enet_work_msg()
334 if (ndev->features & NETIF_F_TSO) { in xgene_enet_work_msg()
336 mss = skb_shinfo(skb)->gso_size; in xgene_enet_work_msg()
340 nr_frags = skb_shinfo(skb)->nr_frags; in xgene_enet_work_msg()
344 &skb_shinfo(skb)->frags[i]); in xgene_enet_work_msg()
353 if (!mss || ((skb->len - hdr_len) <= mss)) in xgene_enet_work_msg()
358 return -EBUSY; in xgene_enet_work_msg()
362 } else if (iph->protocol == IPPROTO_UDP) { in xgene_enet_work_msg()
394 exp_bufs = &ring->exp_bufs[ring->exp_buf_tail * MAX_EXP_BUFFS]; in xgene_enet_get_exp_bufs()
396 ring->exp_buf_tail = (ring->exp_buf_tail + 1) & ((ring->slots / 2) - 1); in xgene_enet_get_exp_bufs()
403 return &ring->cp_ring->frag_dma_addr[ring->tail * MAX_SKB_FRAGS]; in xgene_get_frag_dma_array()
409 struct device *dev = ndev_to_dev(tx_ring->ndev); in xgene_enet_setup_tx_desc()
410 struct xgene_enet_pdata *pdata = netdev_priv(tx_ring->ndev); in xgene_enet_setup_tx_desc()
415 u16 tail = tx_ring->tail; in xgene_enet_setup_tx_desc()
424 raw_desc = &tx_ring->raw_desc[tail]; in xgene_enet_setup_tx_desc()
425 tail = (tail + 1) & (tx_ring->slots - 1); in xgene_enet_setup_tx_desc()
432 raw_desc->m3 = cpu_to_le64(SET_VAL(HENQNUM, tx_ring->dst_ring_num) | in xgene_enet_setup_tx_desc()
438 dma_addr = dma_map_single(dev, skb->data, len, DMA_TO_DEVICE); in xgene_enet_setup_tx_desc()
440 netdev_err(tx_ring->ndev, "DMA mapping error\n"); in xgene_enet_setup_tx_desc()
441 return -EINVAL; in xgene_enet_setup_tx_desc()
445 raw_desc->m1 = cpu_to_le64(SET_VAL(DATAADDR, dma_addr) | in xgene_enet_setup_tx_desc()
454 exp_desc = (void *)&tx_ring->raw_desc[tail]; in xgene_enet_setup_tx_desc()
455 tail = (tail + 1) & (tx_ring->slots - 1); in xgene_enet_setup_tx_desc()
458 nr_frags = skb_shinfo(skb)->nr_frags; in xgene_enet_setup_tx_desc()
466 frag = &skb_shinfo(skb)->frags[fidx]; in xgene_enet_setup_tx_desc()
473 return -EINVAL; in xgene_enet_setup_tx_desc()
484 size -= BUFLEN_16K; in xgene_enet_setup_tx_desc()
530 return -EINVAL; in xgene_enet_setup_tx_desc()
536 raw_desc->m2 = cpu_to_le64(SET_VAL(LL_BYTES_LSB, ell_bytes)); in xgene_enet_setup_tx_desc()
540 raw_desc->m0 = cpu_to_le64(SET_VAL(LL, ll) | SET_VAL(NV, nv) | in xgene_enet_setup_tx_desc()
541 SET_VAL(USERINFO, tx_ring->tail)); in xgene_enet_setup_tx_desc()
542 tx_ring->cp_ring->cp_skb[tx_ring->tail] = skb; in xgene_enet_setup_tx_desc()
543 pdata->tx_level[tx_ring->cp_ring->index] += count; in xgene_enet_setup_tx_desc()
544 tx_ring->tail = tail; in xgene_enet_setup_tx_desc()
554 int index = skb->queue_mapping; in xgene_enet_start_xmit()
555 u32 tx_level = pdata->tx_level[index]; in xgene_enet_start_xmit()
558 tx_ring = pdata->tx_ring[index]; in xgene_enet_start_xmit()
559 if (tx_level < pdata->txc_level[index]) in xgene_enet_start_xmit()
560 tx_level += ((typeof(pdata->tx_level[index]))~0U); in xgene_enet_start_xmit()
562 if ((tx_level - pdata->txc_level[index]) > pdata->tx_qcnt_hi) { in xgene_enet_start_xmit()
571 if (count == -EBUSY) in xgene_enet_start_xmit()
581 tx_ring->tx_packets++; in xgene_enet_start_xmit()
582 tx_ring->tx_bytes += skb->len; in xgene_enet_start_xmit()
584 pdata->ring_ops->wr_cmd(tx_ring, count); in xgene_enet_start_xmit()
590 struct net_device *ndev = skb->dev; in xgene_enet_rx_csum()
593 if (!(ndev->features & NETIF_F_RXCSUM)) in xgene_enet_rx_csum()
596 if (skb->protocol != htons(ETH_P_IP)) in xgene_enet_rx_csum()
602 if (iph->protocol != IPPROTO_TCP && iph->protocol != IPPROTO_UDP) in xgene_enet_rx_csum()
605 skb->ip_summed = CHECKSUM_UNNECESSARY; in xgene_enet_rx_csum()
621 (!GET_VAL(NV, le64_to_cpu(raw_desc->m0)))) in xgene_enet_free_pagepool()
624 dev = ndev_to_dev(buf_pool->ndev); in xgene_enet_free_pagepool()
625 slots = buf_pool->slots - 1; in xgene_enet_free_pagepool()
626 head = buf_pool->head; in xgene_enet_free_pagepool()
636 page = buf_pool->frag_page[head]; in xgene_enet_free_pagepool()
639 buf_pool->frag_page[head] = NULL; in xgene_enet_free_pagepool()
642 buf_pool->head = head; in xgene_enet_free_pagepool()
645 /* Errata 10GE_10 and ENET_15 - Fix duplicated HW statistic counters */
651 skb->protocol == htons(ETH_P_8021Q)) in xgene_enet_errata_10GE_10()
657 /* Errata 10GE_8 and ENET_11 - allow packet with length <=64B */
661 if (ntohs(eth_hdr(skb)->h_proto) < 46) in xgene_enet_errata_10GE_8()
686 ndev = rx_ring->ndev; in xgene_enet_rx_frame()
688 dev = ndev_to_dev(rx_ring->ndev); in xgene_enet_rx_frame()
689 buf_pool = rx_ring->buf_pool; in xgene_enet_rx_frame()
690 page_pool = rx_ring->page_pool; in xgene_enet_rx_frame()
692 dma_unmap_single(dev, GET_VAL(DATAADDR, le64_to_cpu(raw_desc->m1)), in xgene_enet_rx_frame()
694 skb_index = GET_VAL(USERINFO, le64_to_cpu(raw_desc->m0)); in xgene_enet_rx_frame()
695 skb = buf_pool->rx_skb[skb_index]; in xgene_enet_rx_frame()
696 buf_pool->rx_skb[skb_index] = NULL; in xgene_enet_rx_frame()
698 datalen = xgene_enet_get_data_len(le64_to_cpu(raw_desc->m1)); in xgene_enet_rx_frame()
701 nv = GET_VAL(NV, le64_to_cpu(raw_desc->m0)); in xgene_enet_rx_frame()
703 datalen -= 4; in xgene_enet_rx_frame()
706 prefetch(skb->data - NET_IP_ALIGN); in xgene_enet_rx_frame()
707 skb->protocol = eth_type_trans(skb, ndev); in xgene_enet_rx_frame()
710 status = (GET_VAL(ELERR, le64_to_cpu(raw_desc->m0)) << LERR_LEN) | in xgene_enet_rx_frame()
711 GET_VAL(LERR, le64_to_cpu(raw_desc->m0)); in xgene_enet_rx_frame()
714 pdata->false_rflr++; in xgene_enet_rx_frame()
716 pdata->vlan_rjbr++; in xgene_enet_rx_frame()
721 rx_ring->rx_dropped++; in xgene_enet_rx_frame()
729 slots = page_pool->slots - 1; in xgene_enet_rx_frame()
730 head = page_pool->head; in xgene_enet_rx_frame()
741 page = page_pool->frag_page[head]; in xgene_enet_rx_frame()
742 skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, page, 0, in xgene_enet_rx_frame()
747 page_pool->frag_page[head] = NULL; in xgene_enet_rx_frame()
751 page_pool->head = head; in xgene_enet_rx_frame()
752 rx_ring->npagepool -= skb_shinfo(skb)->nr_frags; in xgene_enet_rx_frame()
758 rx_ring->rx_packets++; in xgene_enet_rx_frame()
759 rx_ring->rx_bytes += datalen; in xgene_enet_rx_frame()
760 napi_gro_receive(&rx_ring->napi, skb); in xgene_enet_rx_frame()
763 if (rx_ring->npagepool <= 0) { in xgene_enet_rx_frame()
765 rx_ring->npagepool = NUM_NXTBUFPOOL; in xgene_enet_rx_frame()
770 if (--rx_ring->nbufpool == 0) { in xgene_enet_rx_frame()
772 rx_ring->nbufpool = NUM_BUFPOOL; in xgene_enet_rx_frame()
780 return GET_VAL(FPQNUM, le64_to_cpu(raw_desc->m0)) ? true : false; in is_rx_desc()
786 struct net_device *ndev = ring->ndev; in xgene_enet_process_ring()
789 u16 head = ring->head; in xgene_enet_process_ring()
790 u16 slots = ring->slots - 1; in xgene_enet_process_ring()
795 raw_desc = &ring->raw_desc[head]; in xgene_enet_process_ring()
804 if (GET_BIT(NV, le64_to_cpu(raw_desc->m0))) { in xgene_enet_process_ring()
806 exp_desc = &ring->raw_desc[head]; in xgene_enet_process_ring()
809 head = (head - 1) & slots; in xgene_enet_process_ring()
831 pdata->txc_level[ring->index] += desc_count; in xgene_enet_process_ring()
835 } while (--budget); in xgene_enet_process_ring()
838 pdata->ring_ops->wr_cmd(ring, -count); in xgene_enet_process_ring()
839 ring->head = head; in xgene_enet_process_ring()
841 if (__netif_subqueue_stopped(ndev, ring->index)) in xgene_enet_process_ring()
842 netif_start_subqueue(ndev, ring->index); in xgene_enet_process_ring()
858 enable_irq(ring->irq); in xgene_enet_napi()
870 pdata->mac_ops->reset(pdata); in xgene_enet_timeout()
872 for (i = 0; i < pdata->txq_cnt; i++) { in xgene_enet_timeout()
885 for (i = 0; i < pdata->rxq_cnt; i++) { in xgene_enet_set_irq_name()
886 ring = pdata->rx_ring[i]; in xgene_enet_set_irq_name()
887 if (!pdata->cq_cnt) { in xgene_enet_set_irq_name()
888 snprintf(ring->irq_name, IRQ_ID_SIZE, "%s-rx-txc", in xgene_enet_set_irq_name()
889 ndev->name); in xgene_enet_set_irq_name()
891 snprintf(ring->irq_name, IRQ_ID_SIZE, "%s-rx-%d", in xgene_enet_set_irq_name()
892 ndev->name, i); in xgene_enet_set_irq_name()
896 for (i = 0; i < pdata->cq_cnt; i++) { in xgene_enet_set_irq_name()
897 ring = pdata->tx_ring[i]->cp_ring; in xgene_enet_set_irq_name()
898 snprintf(ring->irq_name, IRQ_ID_SIZE, "%s-txc-%d", in xgene_enet_set_irq_name()
899 ndev->name, i); in xgene_enet_set_irq_name()
911 for (i = 0; i < pdata->rxq_cnt; i++) { in xgene_enet_register_irq()
912 ring = pdata->rx_ring[i]; in xgene_enet_register_irq()
913 irq_set_status_flags(ring->irq, IRQ_DISABLE_UNLAZY); in xgene_enet_register_irq()
914 ret = devm_request_irq(dev, ring->irq, xgene_enet_rx_irq, in xgene_enet_register_irq()
915 0, ring->irq_name, ring); in xgene_enet_register_irq()
918 ring->irq_name); in xgene_enet_register_irq()
922 for (i = 0; i < pdata->cq_cnt; i++) { in xgene_enet_register_irq()
923 ring = pdata->tx_ring[i]->cp_ring; in xgene_enet_register_irq()
924 irq_set_status_flags(ring->irq, IRQ_DISABLE_UNLAZY); in xgene_enet_register_irq()
925 ret = devm_request_irq(dev, ring->irq, xgene_enet_rx_irq, in xgene_enet_register_irq()
926 0, ring->irq_name, ring); in xgene_enet_register_irq()
929 ring->irq_name); in xgene_enet_register_irq()
946 for (i = 0; i < pdata->rxq_cnt; i++) { in xgene_enet_free_irq()
947 ring = pdata->rx_ring[i]; in xgene_enet_free_irq()
948 irq_clear_status_flags(ring->irq, IRQ_DISABLE_UNLAZY); in xgene_enet_free_irq()
949 devm_free_irq(dev, ring->irq, ring); in xgene_enet_free_irq()
952 for (i = 0; i < pdata->cq_cnt; i++) { in xgene_enet_free_irq()
953 ring = pdata->tx_ring[i]->cp_ring; in xgene_enet_free_irq()
954 irq_clear_status_flags(ring->irq, IRQ_DISABLE_UNLAZY); in xgene_enet_free_irq()
955 devm_free_irq(dev, ring->irq, ring); in xgene_enet_free_irq()
964 for (i = 0; i < pdata->rxq_cnt; i++) { in xgene_enet_napi_enable()
965 napi = &pdata->rx_ring[i]->napi; in xgene_enet_napi_enable()
969 for (i = 0; i < pdata->cq_cnt; i++) { in xgene_enet_napi_enable()
970 napi = &pdata->tx_ring[i]->cp_ring->napi; in xgene_enet_napi_enable()
980 for (i = 0; i < pdata->rxq_cnt; i++) { in xgene_enet_napi_disable()
981 napi = &pdata->rx_ring[i]->napi; in xgene_enet_napi_disable()
985 for (i = 0; i < pdata->cq_cnt; i++) { in xgene_enet_napi_disable()
986 napi = &pdata->tx_ring[i]->cp_ring->napi; in xgene_enet_napi_disable()
994 const struct xgene_mac_ops *mac_ops = pdata->mac_ops; in xgene_enet_open()
997 ret = netif_set_real_num_tx_queues(ndev, pdata->txq_cnt); in xgene_enet_open()
1001 ret = netif_set_real_num_rx_queues(ndev, pdata->rxq_cnt); in xgene_enet_open()
1012 if (ndev->phydev) { in xgene_enet_open()
1013 phy_start(ndev->phydev); in xgene_enet_open()
1015 schedule_delayed_work(&pdata->link_work, PHY_POLL_LINK_OFF); in xgene_enet_open()
1019 mac_ops->tx_enable(pdata); in xgene_enet_open()
1020 mac_ops->rx_enable(pdata); in xgene_enet_open()
1029 const struct xgene_mac_ops *mac_ops = pdata->mac_ops; in xgene_enet_close()
1033 mac_ops->tx_disable(pdata); in xgene_enet_close()
1034 mac_ops->rx_disable(pdata); in xgene_enet_close()
1036 if (ndev->phydev) in xgene_enet_close()
1037 phy_stop(ndev->phydev); in xgene_enet_close()
1039 cancel_delayed_work_sync(&pdata->link_work); in xgene_enet_close()
1043 for (i = 0; i < pdata->rxq_cnt; i++) in xgene_enet_close()
1044 xgene_enet_process_ring(pdata->rx_ring[i], -1); in xgene_enet_close()
1053 pdata = netdev_priv(ring->ndev); in xgene_enet_delete_ring()
1054 dev = ndev_to_dev(ring->ndev); in xgene_enet_delete_ring()
1056 pdata->ring_ops->clear(ring); in xgene_enet_delete_ring()
1057 dmam_free_coherent(dev, ring->size, ring->desc_addr, ring->dma); in xgene_enet_delete_ring()
1066 for (i = 0; i < pdata->txq_cnt; i++) { in xgene_enet_delete_desc_rings()
1067 ring = pdata->tx_ring[i]; in xgene_enet_delete_desc_rings()
1070 pdata->port_ops->clear(pdata, ring); in xgene_enet_delete_desc_rings()
1071 if (pdata->cq_cnt) in xgene_enet_delete_desc_rings()
1072 xgene_enet_delete_ring(ring->cp_ring); in xgene_enet_delete_desc_rings()
1073 pdata->tx_ring[i] = NULL; in xgene_enet_delete_desc_rings()
1078 for (i = 0; i < pdata->rxq_cnt; i++) { in xgene_enet_delete_desc_rings()
1079 ring = pdata->rx_ring[i]; in xgene_enet_delete_desc_rings()
1081 page_pool = ring->page_pool; in xgene_enet_delete_desc_rings()
1085 pdata->port_ops->clear(pdata, page_pool); in xgene_enet_delete_desc_rings()
1088 buf_pool = ring->buf_pool; in xgene_enet_delete_desc_rings()
1091 pdata->port_ops->clear(pdata, buf_pool); in xgene_enet_delete_desc_rings()
1094 pdata->rx_ring[i] = NULL; in xgene_enet_delete_desc_rings()
1103 int size = -EINVAL; in xgene_enet_get_ring_size()
1137 dev = ndev_to_dev(ring->ndev); in xgene_enet_free_desc_ring()
1138 pdata = netdev_priv(ring->ndev); in xgene_enet_free_desc_ring()
1140 if (ring->desc_addr) { in xgene_enet_free_desc_ring()
1141 pdata->ring_ops->clear(ring); in xgene_enet_free_desc_ring()
1142 dmam_free_coherent(dev, ring->size, ring->desc_addr, ring->dma); in xgene_enet_free_desc_ring()
1150 struct device *dev = &pdata->pdev->dev; in xgene_enet_free_desc_rings()
1155 for (i = 0; i < pdata->txq_cnt; i++) { in xgene_enet_free_desc_rings()
1156 ring = pdata->tx_ring[i]; in xgene_enet_free_desc_rings()
1158 if (ring->cp_ring && ring->cp_ring->cp_skb) in xgene_enet_free_desc_rings()
1159 devm_kfree(dev, ring->cp_ring->cp_skb); in xgene_enet_free_desc_rings()
1161 if (ring->cp_ring && pdata->cq_cnt) in xgene_enet_free_desc_rings()
1162 xgene_enet_free_desc_ring(ring->cp_ring); in xgene_enet_free_desc_rings()
1169 for (i = 0; i < pdata->rxq_cnt; i++) { in xgene_enet_free_desc_rings()
1170 ring = pdata->rx_ring[i]; in xgene_enet_free_desc_rings()
1172 if (ring->buf_pool) { in xgene_enet_free_desc_rings()
1173 if (ring->buf_pool->rx_skb) in xgene_enet_free_desc_rings()
1174 devm_kfree(dev, ring->buf_pool->rx_skb); in xgene_enet_free_desc_rings()
1176 xgene_enet_free_desc_ring(ring->buf_pool); in xgene_enet_free_desc_rings()
1179 page_pool = ring->page_pool; in xgene_enet_free_desc_rings()
1181 p = page_pool->frag_page; in xgene_enet_free_desc_rings()
1185 p = page_pool->frag_dma_addr; in xgene_enet_free_desc_rings()
1198 if ((pdata->enet_id == XGENE_ENET2) && in is_irq_mbox_required()
1199 (xgene_enet_ring_owner(ring->id) == RING_OWNER_CPU)) { in is_irq_mbox_required()
1209 u8 num_ring_id_shift = pdata->ring_ops->num_ring_id_shift; in xgene_enet_ring_cmd_base()
1211 return pdata->ring_cmd_addr + (ring->num << num_ring_id_shift); in xgene_enet_ring_cmd_base()
1233 ring->ndev = ndev; in xgene_enet_create_desc_ring()
1234 ring->num = ring_num; in xgene_enet_create_desc_ring()
1235 ring->cfgsize = cfgsize; in xgene_enet_create_desc_ring()
1236 ring->id = ring_id; in xgene_enet_create_desc_ring()
1238 ring->desc_addr = dmam_alloc_coherent(dev, size, &ring->dma, in xgene_enet_create_desc_ring()
1240 if (!ring->desc_addr) { in xgene_enet_create_desc_ring()
1244 ring->size = size; in xgene_enet_create_desc_ring()
1248 &ring->irq_mbox_dma, in xgene_enet_create_desc_ring()
1251 dmam_free_coherent(dev, size, ring->desc_addr, in xgene_enet_create_desc_ring()
1252 ring->dma); in xgene_enet_create_desc_ring()
1256 ring->irq_mbox_addr = irq_mbox_addr; in xgene_enet_create_desc_ring()
1259 ring->cmd_base = xgene_enet_ring_cmd_base(pdata, ring); in xgene_enet_create_desc_ring()
1260 ring->cmd = ring->cmd_base + INC_DEC_CMD_ADDR; in xgene_enet_create_desc_ring()
1261 ring = pdata->ring_ops->setup(ring); in xgene_enet_create_desc_ring()
1263 ring->num, ring->size, ring->id, ring->slots); in xgene_enet_create_desc_ring()
1277 if (p->enet_id == XGENE_ENET1) { in xgene_derive_ring_owner()
1278 switch (p->phy_mode) { in xgene_derive_ring_owner()
1283 owner = (!p->port_id) ? RING_OWNER_ETH0 : in xgene_derive_ring_owner()
1288 owner = (!p->port_id) ? RING_OWNER_ETH0 : RING_OWNER_ETH1; in xgene_derive_ring_owner()
1296 struct device *dev = &pdata->pdev->dev; in xgene_start_cpu_bufnum()
1302 return (!ret) ? cpu_bufnum : pdata->cpu_bufnum; in xgene_start_cpu_bufnum()
1312 u8 eth_bufnum = pdata->eth_bufnum; in xgene_enet_create_desc_rings()
1313 u8 bp_bufnum = pdata->bp_bufnum; in xgene_enet_create_desc_rings()
1314 u16 ring_num = pdata->ring_num; in xgene_enet_create_desc_rings()
1324 for (i = 0; i < pdata->rxq_cnt; i++) { in xgene_enet_create_desc_rings()
1332 ret = -ENOMEM; in xgene_enet_create_desc_rings()
1343 ret = -ENOMEM; in xgene_enet_create_desc_rings()
1347 rx_ring->nbufpool = NUM_BUFPOOL; in xgene_enet_create_desc_rings()
1348 rx_ring->npagepool = NUM_NXTBUFPOOL; in xgene_enet_create_desc_rings()
1349 rx_ring->irq = pdata->irqs[i]; in xgene_enet_create_desc_rings()
1350 buf_pool->rx_skb = devm_kcalloc(dev, buf_pool->slots, in xgene_enet_create_desc_rings()
1353 if (!buf_pool->rx_skb) { in xgene_enet_create_desc_rings()
1354 ret = -ENOMEM; in xgene_enet_create_desc_rings()
1358 buf_pool->dst_ring_num = xgene_enet_dst_ring_num(buf_pool); in xgene_enet_create_desc_rings()
1359 rx_ring->buf_pool = buf_pool; in xgene_enet_create_desc_rings()
1360 pdata->rx_ring[i] = rx_ring; in xgene_enet_create_desc_rings()
1362 if ((pdata->enet_id == XGENE_ENET1 && pdata->rxq_cnt > 4) || in xgene_enet_create_desc_rings()
1363 (pdata->enet_id == XGENE_ENET2 && pdata->rxq_cnt > 16)) { in xgene_enet_create_desc_rings()
1374 ret = -ENOMEM; in xgene_enet_create_desc_rings()
1378 slots = page_pool->slots; in xgene_enet_create_desc_rings()
1379 page_pool->frag_page = devm_kcalloc(dev, slots, in xgene_enet_create_desc_rings()
1382 if (!page_pool->frag_page) { in xgene_enet_create_desc_rings()
1383 ret = -ENOMEM; in xgene_enet_create_desc_rings()
1387 page_pool->frag_dma_addr = devm_kcalloc(dev, slots, in xgene_enet_create_desc_rings()
1390 if (!page_pool->frag_dma_addr) { in xgene_enet_create_desc_rings()
1391 ret = -ENOMEM; in xgene_enet_create_desc_rings()
1395 page_pool->dst_ring_num = xgene_enet_dst_ring_num(page_pool); in xgene_enet_create_desc_rings()
1396 rx_ring->page_pool = page_pool; in xgene_enet_create_desc_rings()
1399 for (i = 0; i < pdata->txq_cnt; i++) { in xgene_enet_create_desc_rings()
1407 ret = -ENOMEM; in xgene_enet_create_desc_rings()
1411 size = (tx_ring->slots / 2) * sizeof(__le64) * MAX_EXP_BUFFS; in xgene_enet_create_desc_rings()
1415 ret = -ENOMEM; in xgene_enet_create_desc_rings()
1418 tx_ring->exp_bufs = exp_bufs; in xgene_enet_create_desc_rings()
1420 pdata->tx_ring[i] = tx_ring; in xgene_enet_create_desc_rings()
1422 if (!pdata->cq_cnt) { in xgene_enet_create_desc_rings()
1423 cp_ring = pdata->rx_ring[i]; in xgene_enet_create_desc_rings()
1432 ret = -ENOMEM; in xgene_enet_create_desc_rings()
1436 cp_ring->irq = pdata->irqs[pdata->rxq_cnt + i]; in xgene_enet_create_desc_rings()
1437 cp_ring->index = i; in xgene_enet_create_desc_rings()
1440 cp_ring->cp_skb = devm_kcalloc(dev, tx_ring->slots, in xgene_enet_create_desc_rings()
1443 if (!cp_ring->cp_skb) { in xgene_enet_create_desc_rings()
1444 ret = -ENOMEM; in xgene_enet_create_desc_rings()
1449 cp_ring->frag_dma_addr = devm_kcalloc(dev, tx_ring->slots, in xgene_enet_create_desc_rings()
1451 if (!cp_ring->frag_dma_addr) { in xgene_enet_create_desc_rings()
1452 devm_kfree(dev, cp_ring->cp_skb); in xgene_enet_create_desc_rings()
1453 ret = -ENOMEM; in xgene_enet_create_desc_rings()
1457 tx_ring->cp_ring = cp_ring; in xgene_enet_create_desc_rings()
1458 tx_ring->dst_ring_num = xgene_enet_dst_ring_num(cp_ring); in xgene_enet_create_desc_rings()
1461 if (pdata->ring_ops->coalesce) in xgene_enet_create_desc_rings()
1462 pdata->ring_ops->coalesce(pdata->tx_ring[0]); in xgene_enet_create_desc_rings()
1463 pdata->tx_qcnt_hi = pdata->tx_ring[0]->slots - 128; in xgene_enet_create_desc_rings()
1480 for (i = 0; i < pdata->txq_cnt; i++) { in xgene_enet_get_stats64()
1481 ring = pdata->tx_ring[i]; in xgene_enet_get_stats64()
1483 stats->tx_packets += ring->tx_packets; in xgene_enet_get_stats64()
1484 stats->tx_bytes += ring->tx_bytes; in xgene_enet_get_stats64()
1485 stats->tx_dropped += ring->tx_dropped; in xgene_enet_get_stats64()
1486 stats->tx_errors += ring->tx_errors; in xgene_enet_get_stats64()
1490 for (i = 0; i < pdata->rxq_cnt; i++) { in xgene_enet_get_stats64()
1491 ring = pdata->rx_ring[i]; in xgene_enet_get_stats64()
1493 stats->rx_packets += ring->rx_packets; in xgene_enet_get_stats64()
1494 stats->rx_bytes += ring->rx_bytes; in xgene_enet_get_stats64()
1495 stats->rx_dropped += ring->rx_dropped; in xgene_enet_get_stats64()
1496 stats->rx_errors += ring->rx_errors + in xgene_enet_get_stats64()
1497 ring->rx_length_errors + in xgene_enet_get_stats64()
1498 ring->rx_crc_errors + in xgene_enet_get_stats64()
1499 ring->rx_frame_errors + in xgene_enet_get_stats64()
1500 ring->rx_fifo_errors; in xgene_enet_get_stats64()
1501 stats->rx_length_errors += ring->rx_length_errors; in xgene_enet_get_stats64()
1502 stats->rx_crc_errors += ring->rx_crc_errors; in xgene_enet_get_stats64()
1503 stats->rx_frame_errors += ring->rx_frame_errors; in xgene_enet_get_stats64()
1504 stats->rx_fifo_errors += ring->rx_fifo_errors; in xgene_enet_get_stats64()
1517 pdata->mac_ops->set_mac_addr(pdata); in xgene_enet_set_mac_address()
1533 WRITE_ONCE(ndev->mtu, new_mtu); in xgene_change_mtu()
1534 pdata->mac_ops->set_framesize(pdata, frame_size); in xgene_change_mtu()
1559 pdata->port_id = 0; in xgene_get_port_id_acpi()
1561 pdata->port_id = temp; in xgene_get_port_id_acpi()
1572 of_property_read_u32(dev->of_node, "port-id", &id); in xgene_get_port_id_dt()
1574 pdata->port_id = id & BIT(0); in xgene_get_port_id_dt()
1581 struct device *dev = &pdata->pdev->dev; in xgene_get_tx_delay()
1584 ret = device_property_read_u32(dev, "tx-delay", &delay); in xgene_get_tx_delay()
1586 pdata->tx_delay = 4; in xgene_get_tx_delay()
1591 dev_err(dev, "Invalid tx-delay specified\n"); in xgene_get_tx_delay()
1592 return -EINVAL; in xgene_get_tx_delay()
1595 pdata->tx_delay = delay; in xgene_get_tx_delay()
1602 struct device *dev = &pdata->pdev->dev; in xgene_get_rx_delay()
1605 ret = device_property_read_u32(dev, "rx-delay", &delay); in xgene_get_rx_delay()
1607 pdata->rx_delay = 2; in xgene_get_rx_delay()
1612 dev_err(dev, "Invalid rx-delay specified\n"); in xgene_get_rx_delay()
1613 return -EINVAL; in xgene_get_rx_delay()
1616 pdata->rx_delay = delay; in xgene_get_rx_delay()
1623 struct platform_device *pdev = pdata->pdev; in xgene_enet_get_irqs()
1626 if (phy_interface_mode_is_rgmii(pdata->phy_mode)) in xgene_enet_get_irqs()
1628 else if (pdata->phy_mode == PHY_INTERFACE_MODE_SGMII) in xgene_enet_get_irqs()
1636 if (pdata->phy_mode == PHY_INTERFACE_MODE_XGMII) { in xgene_enet_get_irqs()
1638 pdata->rxq_cnt = max_irqs / 2; in xgene_enet_get_irqs()
1639 pdata->txq_cnt = max_irqs / 2; in xgene_enet_get_irqs()
1640 pdata->cq_cnt = max_irqs / 2; in xgene_enet_get_irqs()
1645 pdata->irqs[i] = ret; in xgene_enet_get_irqs()
1655 if (pdata->phy_mode == PHY_INTERFACE_MODE_XGMII) in xgene_enet_check_phy_handle()
1661 ret = xgene_enet_phy_connect(pdata->ndev); in xgene_enet_check_phy_handle()
1663 pdata->mdio_driver = true; in xgene_enet_check_phy_handle()
1668 struct device *dev = &pdata->pdev->dev; in xgene_enet_gpiod_get()
1670 pdata->sfp_gpio_en = false; in xgene_enet_gpiod_get()
1671 if (pdata->phy_mode != PHY_INTERFACE_MODE_XGMII || in xgene_enet_gpiod_get()
1672 (!device_property_present(dev, "sfp-gpios") && in xgene_enet_gpiod_get()
1673 !device_property_present(dev, "rxlos-gpios"))) in xgene_enet_gpiod_get()
1676 pdata->sfp_gpio_en = true; in xgene_enet_gpiod_get()
1677 pdata->sfp_rdy = gpiod_get(dev, "rxlos", GPIOD_IN); in xgene_enet_gpiod_get()
1678 if (IS_ERR(pdata->sfp_rdy)) in xgene_enet_gpiod_get()
1679 pdata->sfp_rdy = gpiod_get(dev, "sfp", GPIOD_IN); in xgene_enet_gpiod_get()
1692 pdev = pdata->pdev; in xgene_enet_get_resources()
1693 dev = &pdev->dev; in xgene_enet_get_resources()
1694 ndev = pdata->ndev; in xgene_enet_get_resources()
1699 return -ENODEV; in xgene_enet_get_resources()
1701 pdata->base_addr = devm_ioremap(dev, res->start, resource_size(res)); in xgene_enet_get_resources()
1702 if (!pdata->base_addr) { in xgene_enet_get_resources()
1704 return -ENOMEM; in xgene_enet_get_resources()
1710 return -ENODEV; in xgene_enet_get_resources()
1712 pdata->ring_csr_addr = devm_ioremap(dev, res->start, in xgene_enet_get_resources()
1714 if (!pdata->ring_csr_addr) { in xgene_enet_get_resources()
1716 return -ENOMEM; in xgene_enet_get_resources()
1722 return -ENODEV; in xgene_enet_get_resources()
1724 pdata->ring_cmd_addr = devm_ioremap(dev, res->start, in xgene_enet_get_resources()
1726 if (!pdata->ring_cmd_addr) { in xgene_enet_get_resources()
1728 return -ENOMEM; in xgene_enet_get_resources()
1731 if (dev->of_node) in xgene_enet_get_resources()
1741 memcpy(ndev->perm_addr, ndev->dev_addr, ndev->addr_len); in xgene_enet_get_resources()
1743 pdata->phy_mode = device_get_phy_mode(dev); in xgene_enet_get_resources()
1744 if (pdata->phy_mode < 0) { in xgene_enet_get_resources()
1745 dev_err(dev, "Unable to get phy-connection-type\n"); in xgene_enet_get_resources()
1746 return pdata->phy_mode; in xgene_enet_get_resources()
1748 if (!phy_interface_mode_is_rgmii(pdata->phy_mode) && in xgene_enet_get_resources()
1749 pdata->phy_mode != PHY_INTERFACE_MODE_SGMII && in xgene_enet_get_resources()
1750 pdata->phy_mode != PHY_INTERFACE_MODE_XGMII) { in xgene_enet_get_resources()
1751 dev_err(dev, "Incorrect phy-connection-type specified\n"); in xgene_enet_get_resources()
1752 return -ENODEV; in xgene_enet_get_resources()
1769 pdata->clk = devm_clk_get(&pdev->dev, NULL); in xgene_enet_get_resources()
1770 if (IS_ERR(pdata->clk)) { in xgene_enet_get_resources()
1771 if (pdata->phy_mode != PHY_INTERFACE_MODE_SGMII) { in xgene_enet_get_resources()
1776 if (PTR_ERR(pdata->clk) != -ENOENT || dev->of_node) in xgene_enet_get_resources()
1777 return PTR_ERR(pdata->clk); in xgene_enet_get_resources()
1783 if (pdata->phy_mode != PHY_INTERFACE_MODE_XGMII) in xgene_enet_get_resources()
1784 base_addr = pdata->base_addr - (pdata->port_id * MAC_OFFSET); in xgene_enet_get_resources()
1786 base_addr = pdata->base_addr; in xgene_enet_get_resources()
1787 pdata->eth_csr_addr = base_addr + BLOCK_ETH_CSR_OFFSET; in xgene_enet_get_resources()
1788 pdata->cle.base = base_addr + BLOCK_ETH_CLE_CSR_OFFSET; in xgene_enet_get_resources()
1789 pdata->eth_ring_if_addr = base_addr + BLOCK_ETH_RING_IF_OFFSET; in xgene_enet_get_resources()
1790 pdata->eth_diag_csr_addr = base_addr + BLOCK_ETH_DIAG_CSR_OFFSET; in xgene_enet_get_resources()
1791 if (phy_interface_mode_is_rgmii(pdata->phy_mode) || in xgene_enet_get_resources()
1792 pdata->phy_mode == PHY_INTERFACE_MODE_SGMII) { in xgene_enet_get_resources()
1793 pdata->mcx_mac_addr = pdata->base_addr + BLOCK_ETH_MAC_OFFSET; in xgene_enet_get_resources()
1794 pdata->mcx_stats_addr = in xgene_enet_get_resources()
1795 pdata->base_addr + BLOCK_ETH_STATS_OFFSET; in xgene_enet_get_resources()
1796 offset = (pdata->enet_id == XGENE_ENET1) ? in xgene_enet_get_resources()
1799 pdata->mcx_mac_csr_addr = base_addr + offset; in xgene_enet_get_resources()
1801 pdata->mcx_mac_addr = base_addr + BLOCK_AXG_MAC_OFFSET; in xgene_enet_get_resources()
1802 pdata->mcx_stats_addr = base_addr + BLOCK_AXG_STATS_OFFSET; in xgene_enet_get_resources()
1803 pdata->mcx_mac_csr_addr = base_addr + BLOCK_AXG_MAC_CSR_OFFSET; in xgene_enet_get_resources()
1804 pdata->pcs_addr = base_addr + BLOCK_PCS_OFFSET; in xgene_enet_get_resources()
1806 pdata->rx_buff_cnt = NUM_PKT_BUF; in xgene_enet_get_resources()
1813 struct xgene_enet_cle *enet_cle = &pdata->cle; in xgene_enet_init_hw()
1815 struct net_device *ndev = pdata->ndev; in xgene_enet_init_hw()
1821 ret = pdata->port_ops->reset(pdata); in xgene_enet_init_hw()
1832 for (i = 0; i < pdata->rxq_cnt; i++) { in xgene_enet_init_hw()
1833 buf_pool = pdata->rx_ring[i]->buf_pool; in xgene_enet_init_hw()
1835 page_pool = pdata->rx_ring[i]->page_pool; in xgene_enet_init_hw()
1838 count = pdata->rx_buff_cnt; in xgene_enet_init_hw()
1849 dst_ring_num = xgene_enet_dst_ring_num(pdata->rx_ring[0]); in xgene_enet_init_hw()
1850 buf_pool = pdata->rx_ring[0]->buf_pool; in xgene_enet_init_hw()
1851 if (pdata->phy_mode == PHY_INTERFACE_MODE_XGMII) { in xgene_enet_init_hw()
1853 enet_cle->max_nodes = 512; in xgene_enet_init_hw()
1854 enet_cle->max_dbptrs = 1024; in xgene_enet_init_hw()
1855 enet_cle->parsers = 3; in xgene_enet_init_hw()
1856 enet_cle->active_parser = PARSER_ALL; in xgene_enet_init_hw()
1857 enet_cle->ptree.start_node = 0; in xgene_enet_init_hw()
1858 enet_cle->ptree.start_dbptr = 0; in xgene_enet_init_hw()
1859 enet_cle->jump_bytes = 8; in xgene_enet_init_hw()
1860 ret = pdata->cle_ops->cle_init(pdata); in xgene_enet_init_hw()
1867 dst_ring_num = xgene_enet_dst_ring_num(pdata->rx_ring[0]); in xgene_enet_init_hw()
1868 buf_pool = pdata->rx_ring[0]->buf_pool; in xgene_enet_init_hw()
1869 page_pool = pdata->rx_ring[0]->page_pool; in xgene_enet_init_hw()
1870 ring_id = (page_pool) ? page_pool->id : 0; in xgene_enet_init_hw()
1871 pdata->port_ops->cle_bypass(pdata, dst_ring_num, in xgene_enet_init_hw()
1872 buf_pool->id, ring_id); in xgene_enet_init_hw()
1875 ndev->max_mtu = XGENE_ENET_MAX_MTU; in xgene_enet_init_hw()
1876 pdata->phy_speed = SPEED_UNKNOWN; in xgene_enet_init_hw()
1877 pdata->mac_ops->init(pdata); in xgene_enet_init_hw()
1888 switch (pdata->phy_mode) { in xgene_enet_setup_ops()
1893 pdata->mac_ops = &xgene_gmac_ops; in xgene_enet_setup_ops()
1894 pdata->port_ops = &xgene_gport_ops; in xgene_enet_setup_ops()
1895 pdata->rm = RM3; in xgene_enet_setup_ops()
1896 pdata->rxq_cnt = 1; in xgene_enet_setup_ops()
1897 pdata->txq_cnt = 1; in xgene_enet_setup_ops()
1898 pdata->cq_cnt = 0; in xgene_enet_setup_ops()
1901 pdata->mac_ops = &xgene_sgmac_ops; in xgene_enet_setup_ops()
1902 pdata->port_ops = &xgene_sgport_ops; in xgene_enet_setup_ops()
1903 pdata->rm = RM1; in xgene_enet_setup_ops()
1904 pdata->rxq_cnt = 1; in xgene_enet_setup_ops()
1905 pdata->txq_cnt = 1; in xgene_enet_setup_ops()
1906 pdata->cq_cnt = 1; in xgene_enet_setup_ops()
1909 pdata->mac_ops = &xgene_xgmac_ops; in xgene_enet_setup_ops()
1910 pdata->port_ops = &xgene_xgport_ops; in xgene_enet_setup_ops()
1911 pdata->cle_ops = &xgene_cle3in_ops; in xgene_enet_setup_ops()
1912 pdata->rm = RM0; in xgene_enet_setup_ops()
1913 if (!pdata->rxq_cnt) { in xgene_enet_setup_ops()
1914 pdata->rxq_cnt = XGENE_NUM_RX_RING; in xgene_enet_setup_ops()
1915 pdata->txq_cnt = XGENE_NUM_TX_RING; in xgene_enet_setup_ops()
1916 pdata->cq_cnt = XGENE_NUM_TXC_RING; in xgene_enet_setup_ops()
1921 if (pdata->enet_id == XGENE_ENET1) { in xgene_enet_setup_ops()
1922 switch (pdata->port_id) { in xgene_enet_setup_ops()
1924 if (pdata->phy_mode == PHY_INTERFACE_MODE_XGMII) { in xgene_enet_setup_ops()
1925 pdata->cpu_bufnum = X2_START_CPU_BUFNUM_0; in xgene_enet_setup_ops()
1926 pdata->eth_bufnum = X2_START_ETH_BUFNUM_0; in xgene_enet_setup_ops()
1927 pdata->bp_bufnum = X2_START_BP_BUFNUM_0; in xgene_enet_setup_ops()
1928 pdata->ring_num = START_RING_NUM_0; in xgene_enet_setup_ops()
1930 pdata->cpu_bufnum = START_CPU_BUFNUM_0; in xgene_enet_setup_ops()
1931 pdata->eth_bufnum = START_ETH_BUFNUM_0; in xgene_enet_setup_ops()
1932 pdata->bp_bufnum = START_BP_BUFNUM_0; in xgene_enet_setup_ops()
1933 pdata->ring_num = START_RING_NUM_0; in xgene_enet_setup_ops()
1937 if (pdata->phy_mode == PHY_INTERFACE_MODE_XGMII) { in xgene_enet_setup_ops()
1938 pdata->cpu_bufnum = XG_START_CPU_BUFNUM_1; in xgene_enet_setup_ops()
1939 pdata->eth_bufnum = XG_START_ETH_BUFNUM_1; in xgene_enet_setup_ops()
1940 pdata->bp_bufnum = XG_START_BP_BUFNUM_1; in xgene_enet_setup_ops()
1941 pdata->ring_num = XG_START_RING_NUM_1; in xgene_enet_setup_ops()
1943 pdata->cpu_bufnum = START_CPU_BUFNUM_1; in xgene_enet_setup_ops()
1944 pdata->eth_bufnum = START_ETH_BUFNUM_1; in xgene_enet_setup_ops()
1945 pdata->bp_bufnum = START_BP_BUFNUM_1; in xgene_enet_setup_ops()
1946 pdata->ring_num = START_RING_NUM_1; in xgene_enet_setup_ops()
1952 pdata->ring_ops = &xgene_ring1_ops; in xgene_enet_setup_ops()
1954 switch (pdata->port_id) { in xgene_enet_setup_ops()
1956 pdata->cpu_bufnum = X2_START_CPU_BUFNUM_0; in xgene_enet_setup_ops()
1957 pdata->eth_bufnum = X2_START_ETH_BUFNUM_0; in xgene_enet_setup_ops()
1958 pdata->bp_bufnum = X2_START_BP_BUFNUM_0; in xgene_enet_setup_ops()
1959 pdata->ring_num = X2_START_RING_NUM_0; in xgene_enet_setup_ops()
1962 pdata->cpu_bufnum = X2_START_CPU_BUFNUM_1; in xgene_enet_setup_ops()
1963 pdata->eth_bufnum = X2_START_ETH_BUFNUM_1; in xgene_enet_setup_ops()
1964 pdata->bp_bufnum = X2_START_BP_BUFNUM_1; in xgene_enet_setup_ops()
1965 pdata->ring_num = X2_START_RING_NUM_1; in xgene_enet_setup_ops()
1970 pdata->rm = RM0; in xgene_enet_setup_ops()
1971 pdata->ring_ops = &xgene_ring2_ops; in xgene_enet_setup_ops()
1980 for (i = 0; i < pdata->rxq_cnt; i++) { in xgene_enet_napi_add()
1981 napi = &pdata->rx_ring[i]->napi; in xgene_enet_napi_add()
1982 netif_napi_add(pdata->ndev, napi, xgene_enet_napi); in xgene_enet_napi_add()
1985 for (i = 0; i < pdata->cq_cnt; i++) { in xgene_enet_napi_add()
1986 napi = &pdata->tx_ring[i]->cp_ring->napi; in xgene_enet_napi_add()
1987 netif_napi_add(pdata->ndev, napi, xgene_enet_napi); in xgene_enet_napi_add()
2005 {.compatible = "apm,xgene-enet", .data = (void *)XGENE_ENET1},
2006 {.compatible = "apm,xgene1-sgenet", .data = (void *)XGENE_ENET1},
2007 {.compatible = "apm,xgene1-xgenet", .data = (void *)XGENE_ENET1},
2008 {.compatible = "apm,xgene2-sgenet", .data = (void *)XGENE_ENET2},
2009 {.compatible = "apm,xgene2-xgenet", .data = (void *)XGENE_ENET2},
2019 struct device *dev = &pdev->dev; in xgene_enet_probe()
2026 return -ENOMEM; in xgene_enet_probe()
2030 pdata->pdev = pdev; in xgene_enet_probe()
2031 pdata->ndev = ndev; in xgene_enet_probe()
2034 ndev->netdev_ops = &xgene_ndev_ops; in xgene_enet_probe()
2036 ndev->features |= NETIF_F_IP_CSUM | in xgene_enet_probe()
2041 pdata->enet_id = (enum xgene_enet_id)device_get_match_data(&pdev->dev); in xgene_enet_probe()
2042 if (!pdata->enet_id) { in xgene_enet_probe()
2043 ret = -ENODEV; in xgene_enet_probe()
2052 spin_lock_init(&pdata->mac_lock); in xgene_enet_probe()
2054 if (pdata->phy_mode == PHY_INTERFACE_MODE_XGMII) { in xgene_enet_probe()
2055 ndev->features |= NETIF_F_TSO | NETIF_F_RXCSUM; in xgene_enet_probe()
2056 spin_lock_init(&pdata->mss_lock); in xgene_enet_probe()
2058 ndev->hw_features = ndev->features; in xgene_enet_probe()
2072 link_state = pdata->mac_ops->link_state; in xgene_enet_probe()
2073 if (pdata->phy_mode == PHY_INTERFACE_MODE_XGMII) { in xgene_enet_probe()
2074 INIT_DELAYED_WORK(&pdata->link_work, link_state); in xgene_enet_probe()
2075 } else if (!pdata->mdio_driver) { in xgene_enet_probe()
2076 if (phy_interface_mode_is_rgmii(pdata->phy_mode)) in xgene_enet_probe()
2079 INIT_DELAYED_WORK(&pdata->link_work, link_state); in xgene_enet_probe()
2085 spin_lock_init(&pdata->stats_lock); in xgene_enet_probe()
2108 if (pdata->mdio_driver) in xgene_enet_probe()
2110 else if (phy_interface_mode_is_rgmii(pdata->phy_mode)) in xgene_enet_probe()
2123 ndev = pdata->ndev; in xgene_enet_remove()
2130 if (pdata->mdio_driver) in xgene_enet_remove()
2132 else if (phy_interface_mode_is_rgmii(pdata->phy_mode)) in xgene_enet_remove()
2137 pdata->port_ops->shutdown(pdata); in xgene_enet_remove()
2149 if (!pdata->ndev) in xgene_enet_shutdown()
2157 .name = "xgene-enet",
2168 MODULE_DESCRIPTION("APM X-Gene SoC Ethernet driver");