Lines Matching +full:5 +full:gbase +full:- +full:x
1 // SPDX-License-Identifier: GPL-2.0
76 writel(data, priv->swth_base[0] + offset); in mvpp2_write()
81 return readl(priv->swth_base[0] + offset); in mvpp2_read()
86 return readl_relaxed(priv->swth_base[0] + offset); in mvpp2_read_relaxed()
91 return cpu % priv->nthreads; in mvpp2_cpu_to_thread()
96 writel(data, priv->cm3_base + offset); in mvpp2_cm3_write()
101 return readl(priv->cm3_base + offset); in mvpp2_cm3_read()
124 * - per-thread registers, where each thread has its own copy of the
140 * - global registers that must be accessed through a specific thread
141 * window, because they are related to an access to a per-thread
161 writel(data, priv->swth_base[thread] + offset); in mvpp2_thread_write()
167 return readl(priv->swth_base[thread] + offset); in mvpp2_thread_read()
173 writel_relaxed(data, priv->swth_base[thread] + offset); in mvpp2_thread_write_relaxed()
179 return readl_relaxed(priv->swth_base[thread] + offset); in mvpp2_thread_read_relaxed()
185 if (port->priv->hw_version == MVPP21) in mvpp2_txdesc_dma_addr_get()
186 return le32_to_cpu(tx_desc->pp21.buf_dma_addr); in mvpp2_txdesc_dma_addr_get()
188 return le64_to_cpu(tx_desc->pp22.buf_dma_addr_ptp) & in mvpp2_txdesc_dma_addr_get()
201 if (port->priv->hw_version == MVPP21) { in mvpp2_txdesc_dma_addr_set()
202 tx_desc->pp21.buf_dma_addr = cpu_to_le32(addr); in mvpp2_txdesc_dma_addr_set()
203 tx_desc->pp21.packet_offset = offset; in mvpp2_txdesc_dma_addr_set()
207 tx_desc->pp22.buf_dma_addr_ptp &= ~cpu_to_le64(MVPP2_DESC_DMA_MASK); in mvpp2_txdesc_dma_addr_set()
208 tx_desc->pp22.buf_dma_addr_ptp |= val; in mvpp2_txdesc_dma_addr_set()
209 tx_desc->pp22.packet_offset = offset; in mvpp2_txdesc_dma_addr_set()
216 if (port->priv->hw_version == MVPP21) in mvpp2_txdesc_size_get()
217 return le16_to_cpu(tx_desc->pp21.data_size); in mvpp2_txdesc_size_get()
219 return le16_to_cpu(tx_desc->pp22.data_size); in mvpp2_txdesc_size_get()
226 if (port->priv->hw_version == MVPP21) in mvpp2_txdesc_size_set()
227 tx_desc->pp21.data_size = cpu_to_le16(size); in mvpp2_txdesc_size_set()
229 tx_desc->pp22.data_size = cpu_to_le16(size); in mvpp2_txdesc_size_set()
236 if (port->priv->hw_version == MVPP21) in mvpp2_txdesc_txq_set()
237 tx_desc->pp21.phys_txq = txq; in mvpp2_txdesc_txq_set()
239 tx_desc->pp22.phys_txq = txq; in mvpp2_txdesc_txq_set()
246 if (port->priv->hw_version == MVPP21) in mvpp2_txdesc_cmd_set()
247 tx_desc->pp21.command = cpu_to_le32(command); in mvpp2_txdesc_cmd_set()
249 tx_desc->pp22.command = cpu_to_le32(command); in mvpp2_txdesc_cmd_set()
255 if (port->priv->hw_version == MVPP21) in mvpp2_txdesc_offset_get()
256 return tx_desc->pp21.packet_offset; in mvpp2_txdesc_offset_get()
258 return tx_desc->pp22.packet_offset; in mvpp2_txdesc_offset_get()
264 if (port->priv->hw_version == MVPP21) in mvpp2_rxdesc_dma_addr_get()
265 return le32_to_cpu(rx_desc->pp21.buf_dma_addr); in mvpp2_rxdesc_dma_addr_get()
267 return le64_to_cpu(rx_desc->pp22.buf_dma_addr_key_hash) & in mvpp2_rxdesc_dma_addr_get()
274 if (port->priv->hw_version == MVPP21) in mvpp2_rxdesc_cookie_get()
275 return le32_to_cpu(rx_desc->pp21.buf_cookie); in mvpp2_rxdesc_cookie_get()
277 return le64_to_cpu(rx_desc->pp22.buf_cookie_misc) & in mvpp2_rxdesc_cookie_get()
284 if (port->priv->hw_version == MVPP21) in mvpp2_rxdesc_size_get()
285 return le16_to_cpu(rx_desc->pp21.data_size); in mvpp2_rxdesc_size_get()
287 return le16_to_cpu(rx_desc->pp22.data_size); in mvpp2_rxdesc_size_get()
293 if (port->priv->hw_version == MVPP21) in mvpp2_rxdesc_status_get()
294 return le32_to_cpu(rx_desc->pp21.status); in mvpp2_rxdesc_status_get()
296 return le32_to_cpu(rx_desc->pp22.status); in mvpp2_rxdesc_status_get()
301 txq_pcpu->txq_get_index++; in mvpp2_txq_inc_get()
302 if (txq_pcpu->txq_get_index == txq_pcpu->size) in mvpp2_txq_inc_get()
303 txq_pcpu->txq_get_index = 0; in mvpp2_txq_inc_get()
313 txq_pcpu->buffs + txq_pcpu->txq_put_index; in mvpp2_txq_inc_put()
314 tx_buf->type = buf_type; in mvpp2_txq_inc_put()
316 tx_buf->skb = data; in mvpp2_txq_inc_put()
318 tx_buf->xdpf = data; in mvpp2_txq_inc_put()
319 tx_buf->size = mvpp2_txdesc_size_get(port, tx_desc); in mvpp2_txq_inc_put()
320 tx_buf->dma = mvpp2_txdesc_dma_addr_get(port, tx_desc) + in mvpp2_txq_inc_put()
322 txq_pcpu->txq_put_index++; in mvpp2_txq_inc_put()
323 if (txq_pcpu->txq_put_index == txq_pcpu->size) in mvpp2_txq_inc_put()
324 txq_pcpu->txq_put_index = 0; in mvpp2_txq_inc_put()
332 if (priv->hw_version >= MVPP22 && queue_mode == MVPP2_QDIST_SINGLE_MODE) in mvpp2_get_nrxqs()
350 return MVPP2_MAX_TCONT + port->id; in mvpp2_egress_port()
366 if (likely(pool->frag_size <= PAGE_SIZE)) in mvpp2_frag_alloc()
367 return netdev_alloc_frag(pool->frag_size); in mvpp2_frag_alloc()
369 return kmalloc(pool->frag_size, GFP_ATOMIC); in mvpp2_frag_alloc()
377 else if (likely(pool->frag_size <= PAGE_SIZE)) in mvpp2_frag_free()
395 return -EINVAL; in mvpp2_bm_pool_create()
400 if (priv->hw_version == MVPP21) in mvpp2_bm_pool_create()
401 bm_pool->size_bytes = 2 * sizeof(u32) * size; in mvpp2_bm_pool_create()
403 bm_pool->size_bytes = 2 * sizeof(u64) * size; in mvpp2_bm_pool_create()
405 bm_pool->virt_addr = dma_alloc_coherent(dev, bm_pool->size_bytes, in mvpp2_bm_pool_create()
406 &bm_pool->dma_addr, in mvpp2_bm_pool_create()
408 if (!bm_pool->virt_addr) in mvpp2_bm_pool_create()
409 return -ENOMEM; in mvpp2_bm_pool_create()
411 if (!IS_ALIGNED((unsigned long)bm_pool->virt_addr, in mvpp2_bm_pool_create()
413 dma_free_coherent(dev, bm_pool->size_bytes, in mvpp2_bm_pool_create()
414 bm_pool->virt_addr, bm_pool->dma_addr); in mvpp2_bm_pool_create()
416 bm_pool->id, MVPP2_BM_POOL_PTR_ALIGN); in mvpp2_bm_pool_create()
417 return -ENOMEM; in mvpp2_bm_pool_create()
420 mvpp2_write(priv, MVPP2_BM_POOL_BASE_REG(bm_pool->id), in mvpp2_bm_pool_create()
421 lower_32_bits(bm_pool->dma_addr)); in mvpp2_bm_pool_create()
422 mvpp2_write(priv, MVPP2_BM_POOL_SIZE_REG(bm_pool->id), size); in mvpp2_bm_pool_create()
424 val = mvpp2_read(priv, MVPP2_BM_POOL_CTRL_REG(bm_pool->id)); in mvpp2_bm_pool_create()
431 if (priv->hw_version == MVPP23) { in mvpp2_bm_pool_create()
439 mvpp2_write(priv, MVPP2_BM_POOL_CTRL_REG(bm_pool->id), val); in mvpp2_bm_pool_create()
441 bm_pool->size = size; in mvpp2_bm_pool_create()
442 bm_pool->pkt_size = 0; in mvpp2_bm_pool_create()
443 bm_pool->buf_num = 0; in mvpp2_bm_pool_create()
455 bm_pool->buf_size = buf_size; in mvpp2_bm_pool_bufsize_set()
458 mvpp2_write(priv, MVPP2_POOL_BUF_SIZE_REG(bm_pool->id), val); in mvpp2_bm_pool_bufsize_set()
469 MVPP2_BM_PHY_ALLOC_REG(bm_pool->id)); in mvpp2_bm_bufs_get_addrs()
472 if (priv->hw_version >= MVPP22) { in mvpp2_bm_bufs_get_addrs()
498 if (buf_num > bm_pool->buf_num) { in mvpp2_bm_bufs_free()
500 bm_pool->id, buf_num); in mvpp2_bm_bufs_free()
501 buf_num = bm_pool->buf_num; in mvpp2_bm_bufs_free()
504 if (priv->percpu_pools) in mvpp2_bm_bufs_free()
505 pp = priv->page_pool[bm_pool->id]; in mvpp2_bm_bufs_free()
517 bm_pool->buf_size, DMA_FROM_DEVICE); in mvpp2_bm_bufs_free()
527 bm_pool->buf_num -= i; in mvpp2_bm_bufs_free()
535 buf_num += mvpp2_read(priv, MVPP2_BM_POOL_PTRS_NUM_REG(bm_pool->id)) & in mvpp2_check_hw_buf_num()
537 buf_num += mvpp2_read(priv, MVPP2_BM_BPPI_PTRS_NUM_REG(bm_pool->id)) & in mvpp2_check_hw_buf_num()
561 bm_pool->id, bm_pool->buf_num); in mvpp2_bm_pool_destroy()
565 val = mvpp2_read(priv, MVPP2_BM_POOL_CTRL_REG(bm_pool->id)); in mvpp2_bm_pool_destroy()
567 mvpp2_write(priv, MVPP2_BM_POOL_CTRL_REG(bm_pool->id), val); in mvpp2_bm_pool_destroy()
569 if (priv->percpu_pools) { in mvpp2_bm_pool_destroy()
570 page_pool_destroy(priv->page_pool[bm_pool->id]); in mvpp2_bm_pool_destroy()
571 priv->page_pool[bm_pool->id] = NULL; in mvpp2_bm_pool_destroy()
574 dma_free_coherent(dev, bm_pool->size_bytes, in mvpp2_bm_pool_destroy()
575 bm_pool->virt_addr, in mvpp2_bm_pool_destroy()
576 bm_pool->dma_addr); in mvpp2_bm_pool_destroy()
585 if (priv->percpu_pools) in mvpp2_bm_pools_init()
591 bm_pool = &priv->bm_pools[i]; in mvpp2_bm_pools_init()
592 bm_pool->id = i; in mvpp2_bm_pools_init()
602 for (i = i - 1; i >= 0; i--) in mvpp2_bm_pools_init()
603 mvpp2_bm_pool_destroy(dev, priv, &priv->bm_pools[i]); in mvpp2_bm_pools_init()
642 if (priv->percpu_pools) in mvpp2_bm_init()
649 if (priv->percpu_pools) { in mvpp2_bm_init()
650 for (i = 0; i < priv->port_count; i++) { in mvpp2_bm_init()
651 port = priv->port_list[i]; in mvpp2_bm_init()
652 if (port->xdp_prog) { in mvpp2_bm_init()
662 priv->page_pool[i] = in mvpp2_bm_init()
667 if (IS_ERR(priv->page_pool[i])) { in mvpp2_bm_init()
671 page_pool_destroy(priv->page_pool[j]); in mvpp2_bm_init()
672 priv->page_pool[j] = NULL; in mvpp2_bm_init()
674 return PTR_ERR(priv->page_pool[i]); in mvpp2_bm_init()
680 priv->percpu_pools ? "per-cpu" : "shared"); in mvpp2_bm_init()
690 priv->bm_pools = devm_kcalloc(dev, poolnum, in mvpp2_bm_init()
691 sizeof(*priv->bm_pools), GFP_KERNEL); in mvpp2_bm_init()
692 if (!priv->bm_pools) in mvpp2_bm_init()
693 return -ENOMEM; in mvpp2_bm_init()
695 if (priv->hw_version == MVPP23) in mvpp2_bm_init()
727 prxq = port->rxqs[lrxq]->id; in mvpp2_rxq_long_pool_set()
729 if (port->priv->hw_version == MVPP21) in mvpp2_rxq_long_pool_set()
734 val = mvpp2_read(port->priv, MVPP2_RXQ_CONFIG_REG(prxq)); in mvpp2_rxq_long_pool_set()
737 mvpp2_write(port->priv, MVPP2_RXQ_CONFIG_REG(prxq), val); in mvpp2_rxq_long_pool_set()
748 prxq = port->rxqs[lrxq]->id; in mvpp2_rxq_short_pool_set()
750 if (port->priv->hw_version == MVPP21) in mvpp2_rxq_short_pool_set()
755 val = mvpp2_read(port->priv, MVPP2_RXQ_CONFIG_REG(prxq)); in mvpp2_rxq_short_pool_set()
758 mvpp2_write(port->priv, MVPP2_RXQ_CONFIG_REG(prxq), val); in mvpp2_rxq_short_pool_set()
781 dma_addr = dma_map_single(port->dev->dev.parent, data, in mvpp2_buf_alloc()
782 MVPP2_RX_BUF_SIZE(bm_pool->pkt_size), in mvpp2_buf_alloc()
784 if (unlikely(dma_mapping_error(port->dev->dev.parent, dma_addr))) { in mvpp2_buf_alloc()
799 int fq = port->first_rxq; in mvpp2_rxq_enable_fc()
802 spin_lock_irqsave(&port->priv->mss_spinlock, flags); in mvpp2_rxq_enable_fc()
805 * If Flow control was enabled, it would be re-enabled. in mvpp2_rxq_enable_fc()
807 val = mvpp2_cm3_read(port->priv, MSS_FC_COM_REG); in mvpp2_rxq_enable_fc()
810 mvpp2_cm3_write(port->priv, MSS_FC_COM_REG, val); in mvpp2_rxq_enable_fc()
813 for (q = 0; q < port->nrxqs; q++) { in mvpp2_rxq_enable_fc()
817 mvpp2_cm3_write(port->priv, MSS_RXQ_TRESH_REG(q, fq), val); in mvpp2_rxq_enable_fc()
819 val = mvpp2_cm3_read(port->priv, MSS_RXQ_ASS_REG(q, fq)); in mvpp2_rxq_enable_fc()
822 val |= (port->id << MSS_RXQ_ASS_Q_BASE(q, fq)); in mvpp2_rxq_enable_fc()
834 host_id = port->nqvecs; in mvpp2_rxq_enable_fc()
844 mvpp2_cm3_write(port->priv, MSS_RXQ_ASS_REG(q, fq), val); in mvpp2_rxq_enable_fc()
848 val = mvpp2_cm3_read(port->priv, MSS_FC_COM_REG); in mvpp2_rxq_enable_fc()
851 mvpp2_cm3_write(port->priv, MSS_FC_COM_REG, val); in mvpp2_rxq_enable_fc()
853 spin_unlock_irqrestore(&port->priv->mss_spinlock, flags); in mvpp2_rxq_enable_fc()
861 int fq = port->first_rxq; in mvpp2_rxq_disable_fc()
863 spin_lock_irqsave(&port->priv->mss_spinlock, flags); in mvpp2_rxq_disable_fc()
866 * If Flow control was enabled, it would be re-enabled. in mvpp2_rxq_disable_fc()
868 val = mvpp2_cm3_read(port->priv, MSS_FC_COM_REG); in mvpp2_rxq_disable_fc()
871 mvpp2_cm3_write(port->priv, MSS_FC_COM_REG, val); in mvpp2_rxq_disable_fc()
874 for (q = 0; q < port->nrxqs; q++) { in mvpp2_rxq_disable_fc()
878 mvpp2_cm3_write(port->priv, MSS_RXQ_TRESH_REG(q, fq), val); in mvpp2_rxq_disable_fc()
880 val = mvpp2_cm3_read(port->priv, MSS_RXQ_ASS_REG(q, fq)); in mvpp2_rxq_disable_fc()
887 mvpp2_cm3_write(port->priv, MSS_RXQ_ASS_REG(q, fq), val); in mvpp2_rxq_disable_fc()
891 val = mvpp2_cm3_read(port->priv, MSS_FC_COM_REG); in mvpp2_rxq_disable_fc()
894 mvpp2_cm3_write(port->priv, MSS_FC_COM_REG, val); in mvpp2_rxq_disable_fc()
896 spin_unlock_irqrestore(&port->priv->mss_spinlock, flags); in mvpp2_rxq_disable_fc()
907 spin_lock_irqsave(&port->priv->mss_spinlock, flags); in mvpp2_bm_pool_update_fc()
910 * If Flow control were enabled, it would be re-enabled. in mvpp2_bm_pool_update_fc()
912 val = mvpp2_cm3_read(port->priv, MSS_FC_COM_REG); in mvpp2_bm_pool_update_fc()
915 mvpp2_cm3_write(port->priv, MSS_FC_COM_REG, val); in mvpp2_bm_pool_update_fc()
920 val = mvpp2_cm3_read(port->priv, MSS_BUF_POOL_REG(pool->id)); in mvpp2_bm_pool_update_fc()
921 val |= MSS_BUF_POOL_PORT_OFFS(port->id); in mvpp2_bm_pool_update_fc()
926 mvpp2_cm3_write(port->priv, MSS_BUF_POOL_REG(pool->id), val); in mvpp2_bm_pool_update_fc()
929 val = mvpp2_cm3_read(port->priv, MSS_BUF_POOL_REG(pool->id)); in mvpp2_bm_pool_update_fc()
930 val &= ~MSS_BUF_POOL_PORT_OFFS(port->id); in mvpp2_bm_pool_update_fc()
935 if (!pool->buf_num) { in mvpp2_bm_pool_update_fc()
940 mvpp2_cm3_write(port->priv, MSS_BUF_POOL_REG(pool->id), val); in mvpp2_bm_pool_update_fc()
944 val = mvpp2_cm3_read(port->priv, MSS_FC_COM_REG); in mvpp2_bm_pool_update_fc()
947 mvpp2_cm3_write(port->priv, MSS_FC_COM_REG, val); in mvpp2_bm_pool_update_fc()
949 spin_unlock_irqrestore(&port->priv->mss_spinlock, flags); in mvpp2_bm_pool_update_fc()
958 for (i = 0; i < priv->port_count; i++) { in mvpp2_bm_pool_update_priv_fc()
959 port = priv->port_list[i]; in mvpp2_bm_pool_update_priv_fc()
960 if (port->priv->percpu_pools) { in mvpp2_bm_pool_update_priv_fc()
961 for (j = 0; j < port->nrxqs; j++) in mvpp2_bm_pool_update_priv_fc()
962 mvpp2_bm_pool_update_fc(port, &port->priv->bm_pools[j], in mvpp2_bm_pool_update_priv_fc()
963 port->tx_fc & en); in mvpp2_bm_pool_update_priv_fc()
965 mvpp2_bm_pool_update_fc(port, port->pool_long, port->tx_fc & en); in mvpp2_bm_pool_update_priv_fc()
966 mvpp2_bm_pool_update_fc(port, port->pool_short, port->tx_fc & en); in mvpp2_bm_pool_update_priv_fc()
995 priv->global_tx_fc = false; in mvpp2_enable_global_fc()
996 return -EOPNOTSUPP; in mvpp2_enable_global_fc()
1004 unsigned int thread = mvpp2_cpu_to_thread(port->priv, get_cpu()); in mvpp2_bm_pool_put()
1007 if (test_bit(thread, &port->priv->lock_map)) in mvpp2_bm_pool_put()
1008 spin_lock_irqsave(&port->bm_lock[thread], flags); in mvpp2_bm_pool_put()
1010 if (port->priv->hw_version >= MVPP22) { in mvpp2_bm_pool_put()
1022 mvpp2_thread_write_relaxed(port->priv, thread, in mvpp2_bm_pool_put()
1031 mvpp2_thread_write_relaxed(port->priv, thread, in mvpp2_bm_pool_put()
1033 mvpp2_thread_write_relaxed(port->priv, thread, in mvpp2_bm_pool_put()
1036 if (test_bit(thread, &port->priv->lock_map)) in mvpp2_bm_pool_put()
1037 spin_unlock_irqrestore(&port->bm_lock[thread], flags); in mvpp2_bm_pool_put()
1052 if (port->priv->percpu_pools && in mvpp2_bm_bufs_add()
1053 bm_pool->pkt_size > MVPP2_BM_LONG_PKT_SIZE) { in mvpp2_bm_bufs_add()
1054 netdev_err(port->dev, in mvpp2_bm_bufs_add()
1055 "attempted to use jumbo frames with per-cpu pools"); in mvpp2_bm_bufs_add()
1059 buf_size = MVPP2_RX_BUF_SIZE(bm_pool->pkt_size); in mvpp2_bm_bufs_add()
1063 (buf_num + bm_pool->buf_num > bm_pool->size)) { in mvpp2_bm_bufs_add()
1064 netdev_err(port->dev, in mvpp2_bm_bufs_add()
1066 buf_num, bm_pool->id); in mvpp2_bm_bufs_add()
1070 if (port->priv->percpu_pools) in mvpp2_bm_bufs_add()
1071 pp = port->priv->page_pool[bm_pool->id]; in mvpp2_bm_bufs_add()
1078 mvpp2_bm_pool_put(port, bm_pool->id, dma_addr, in mvpp2_bm_bufs_add()
1083 bm_pool->buf_num += i; in mvpp2_bm_bufs_add()
1085 netdev_dbg(port->dev, in mvpp2_bm_bufs_add()
1087 bm_pool->id, bm_pool->pkt_size, buf_size, total_size); in mvpp2_bm_bufs_add()
1089 netdev_dbg(port->dev, in mvpp2_bm_bufs_add()
1091 bm_pool->id, i, buf_num); in mvpp2_bm_bufs_add()
1101 struct mvpp2_bm_pool *new_pool = &port->priv->bm_pools[pool]; in mvpp2_bm_pool_use()
1104 if ((port->priv->percpu_pools && pool > mvpp2_get_nrxqs(port->priv) * 2) || in mvpp2_bm_pool_use()
1105 (!port->priv->percpu_pools && pool >= MVPP2_BM_POOLS_NUM)) { in mvpp2_bm_pool_use()
1106 netdev_err(port->dev, "Invalid pool %d\n", pool); in mvpp2_bm_pool_use()
1113 if (new_pool->pkt_size == 0) { in mvpp2_bm_pool_use()
1119 pkts_num = new_pool->buf_num; in mvpp2_bm_pool_use()
1121 if (port->priv->percpu_pools) { in mvpp2_bm_pool_use()
1122 if (pool < port->nrxqs) in mvpp2_bm_pool_use()
1130 mvpp2_bm_bufs_free(port->dev->dev.parent, in mvpp2_bm_pool_use()
1131 port->priv, new_pool, pkts_num); in mvpp2_bm_pool_use()
1134 new_pool->pkt_size = pkt_size; in mvpp2_bm_pool_use()
1135 new_pool->frag_size = in mvpp2_bm_pool_use()
1143 new_pool->id, num, pkts_num); in mvpp2_bm_pool_use()
1148 mvpp2_bm_pool_bufsize_set(port->priv, new_pool, in mvpp2_bm_pool_use()
1149 MVPP2_RX_BUF_SIZE(new_pool->pkt_size)); in mvpp2_bm_pool_use()
1158 struct mvpp2_bm_pool *new_pool = &port->priv->bm_pools[pool]; in mvpp2_bm_pool_use_percpu()
1161 if (pool > port->nrxqs * 2) { in mvpp2_bm_pool_use_percpu()
1162 netdev_err(port->dev, "Invalid pool %d\n", pool); in mvpp2_bm_pool_use_percpu()
1169 if (new_pool->pkt_size == 0) { in mvpp2_bm_pool_use_percpu()
1175 pkts_num = new_pool->buf_num; in mvpp2_bm_pool_use_percpu()
1179 mvpp2_bm_bufs_free(port->dev->dev.parent, in mvpp2_bm_pool_use_percpu()
1180 port->priv, new_pool, pkts_num); in mvpp2_bm_pool_use_percpu()
1182 new_pool->pkt_size = pkt_size; in mvpp2_bm_pool_use_percpu()
1183 new_pool->frag_size = in mvpp2_bm_pool_use_percpu()
1191 new_pool->id, num, pkts_num); in mvpp2_bm_pool_use_percpu()
1196 mvpp2_bm_pool_bufsize_set(port->priv, new_pool, in mvpp2_bm_pool_use_percpu()
1197 MVPP2_RX_BUF_SIZE(new_pool->pkt_size)); in mvpp2_bm_pool_use_percpu()
1209 * HW Long pool - SW Jumbo pool, HW Short pool - SW Long pool in mvpp2_swf_bm_pool_init_shared()
1210 * else: HW Long pool - SW Long pool, HW Short pool - SW Short pool in mvpp2_swf_bm_pool_init_shared()
1212 if (port->pkt_size > MVPP2_BM_LONG_PKT_SIZE) { in mvpp2_swf_bm_pool_init_shared()
1220 if (!port->pool_long) { in mvpp2_swf_bm_pool_init_shared()
1221 port->pool_long = in mvpp2_swf_bm_pool_init_shared()
1224 if (!port->pool_long) in mvpp2_swf_bm_pool_init_shared()
1225 return -ENOMEM; in mvpp2_swf_bm_pool_init_shared()
1227 port->pool_long->port_map |= BIT(port->id); in mvpp2_swf_bm_pool_init_shared()
1229 for (rxq = 0; rxq < port->nrxqs; rxq++) in mvpp2_swf_bm_pool_init_shared()
1230 mvpp2_rxq_long_pool_set(port, rxq, port->pool_long->id); in mvpp2_swf_bm_pool_init_shared()
1233 if (!port->pool_short) { in mvpp2_swf_bm_pool_init_shared()
1234 port->pool_short = in mvpp2_swf_bm_pool_init_shared()
1237 if (!port->pool_short) in mvpp2_swf_bm_pool_init_shared()
1238 return -ENOMEM; in mvpp2_swf_bm_pool_init_shared()
1240 port->pool_short->port_map |= BIT(port->id); in mvpp2_swf_bm_pool_init_shared()
1242 for (rxq = 0; rxq < port->nrxqs; rxq++) in mvpp2_swf_bm_pool_init_shared()
1244 port->pool_short->id); in mvpp2_swf_bm_pool_init_shared()
1256 for (i = 0; i < port->nrxqs; i++) { in mvpp2_swf_bm_pool_init_percpu()
1260 return -ENOMEM; in mvpp2_swf_bm_pool_init_percpu()
1262 bm_pool->port_map |= BIT(port->id); in mvpp2_swf_bm_pool_init_percpu()
1263 mvpp2_rxq_short_pool_set(port, i, bm_pool->id); in mvpp2_swf_bm_pool_init_percpu()
1266 for (i = 0; i < port->nrxqs; i++) { in mvpp2_swf_bm_pool_init_percpu()
1267 bm_pool = mvpp2_bm_pool_use_percpu(port, MVPP2_BM_LONG, i + port->nrxqs, in mvpp2_swf_bm_pool_init_percpu()
1270 return -ENOMEM; in mvpp2_swf_bm_pool_init_percpu()
1272 bm_pool->port_map |= BIT(port->id); in mvpp2_swf_bm_pool_init_percpu()
1273 mvpp2_rxq_long_pool_set(port, i, bm_pool->id); in mvpp2_swf_bm_pool_init_percpu()
1276 port->pool_long = NULL; in mvpp2_swf_bm_pool_init_percpu()
1277 port->pool_short = NULL; in mvpp2_swf_bm_pool_init_percpu()
1284 if (port->priv->percpu_pools) in mvpp2_swf_bm_pool_init()
1301 if (new_long_pool == MVPP2_BM_JUMBO && port->id != 0) { in mvpp2_set_hw_csum()
1302 port->dev->features &= ~csums; in mvpp2_set_hw_csum()
1303 port->dev->hw_features &= ~csums; in mvpp2_set_hw_csum()
1305 port->dev->features |= csums; in mvpp2_set_hw_csum()
1306 port->dev->hw_features |= csums; in mvpp2_set_hw_csum()
1316 if (port->priv->percpu_pools) in mvpp2_bm_update_mtu()
1320 * HW Long pool - SW Jumbo pool, HW Short pool - SW Long pool in mvpp2_bm_update_mtu()
1321 * else: HW Long pool - SW Long pool, HW Short pool - SW Short pool in mvpp2_bm_update_mtu()
1328 if (new_long_pool != port->pool_long->id) { in mvpp2_bm_update_mtu()
1329 if (port->tx_fc) { in mvpp2_bm_update_mtu()
1332 port->pool_short, in mvpp2_bm_update_mtu()
1335 mvpp2_bm_pool_update_fc(port, port->pool_long, in mvpp2_bm_update_mtu()
1340 port->pool_long = mvpp2_bm_pool_use(port, port->pool_long->id, in mvpp2_bm_update_mtu()
1341 port->pool_long->pkt_size); in mvpp2_bm_update_mtu()
1342 port->pool_long->port_map &= ~BIT(port->id); in mvpp2_bm_update_mtu()
1343 port->pool_long = NULL; in mvpp2_bm_update_mtu()
1345 port->pool_short = mvpp2_bm_pool_use(port, port->pool_short->id, in mvpp2_bm_update_mtu()
1346 port->pool_short->pkt_size); in mvpp2_bm_update_mtu()
1347 port->pool_short->port_map &= ~BIT(port->id); in mvpp2_bm_update_mtu()
1348 port->pool_short = NULL; in mvpp2_bm_update_mtu()
1350 port->pkt_size = pkt_size; in mvpp2_bm_update_mtu()
1357 if (port->tx_fc) { in mvpp2_bm_update_mtu()
1359 mvpp2_bm_pool_update_fc(port, port->pool_long, in mvpp2_bm_update_mtu()
1362 mvpp2_bm_pool_update_fc(port, port->pool_short, in mvpp2_bm_update_mtu()
1367 if (new_long_pool == MVPP2_BM_JUMBO && port->id != 0) { in mvpp2_bm_update_mtu()
1368 dev->features &= ~(NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM); in mvpp2_bm_update_mtu()
1369 dev->hw_features &= ~(NETIF_F_IP_CSUM | in mvpp2_bm_update_mtu()
1372 dev->features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM; in mvpp2_bm_update_mtu()
1373 dev->hw_features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM; in mvpp2_bm_update_mtu()
1378 WRITE_ONCE(dev->mtu, mtu); in mvpp2_bm_update_mtu()
1379 dev->wanted_features = dev->features; in mvpp2_bm_update_mtu()
1389 for (i = 0; i < port->nqvecs; i++) in mvpp2_interrupts_enable()
1390 sw_thread_mask |= port->qvecs[i].sw_thread_mask; in mvpp2_interrupts_enable()
1392 mvpp2_write(port->priv, MVPP2_ISR_ENABLE_REG(port->id), in mvpp2_interrupts_enable()
1400 for (i = 0; i < port->nqvecs; i++) in mvpp2_interrupts_disable()
1401 sw_thread_mask |= port->qvecs[i].sw_thread_mask; in mvpp2_interrupts_disable()
1403 mvpp2_write(port->priv, MVPP2_ISR_ENABLE_REG(port->id), in mvpp2_interrupts_disable()
1409 struct mvpp2_port *port = qvec->port; in mvpp2_qvec_interrupt_enable()
1411 mvpp2_write(port->priv, MVPP2_ISR_ENABLE_REG(port->id), in mvpp2_qvec_interrupt_enable()
1412 MVPP2_ISR_ENABLE_INTERRUPT(qvec->sw_thread_mask)); in mvpp2_qvec_interrupt_enable()
1417 struct mvpp2_port *port = qvec->port; in mvpp2_qvec_interrupt_disable()
1419 mvpp2_write(port->priv, MVPP2_ISR_ENABLE_REG(port->id), in mvpp2_qvec_interrupt_disable()
1420 MVPP2_ISR_DISABLE_INTERRUPT(qvec->sw_thread_mask)); in mvpp2_qvec_interrupt_disable()
1434 if (cpu > port->priv->nthreads) in mvpp2_interrupts_mask()
1437 thread = mvpp2_cpu_to_thread(port->priv, cpu); in mvpp2_interrupts_mask()
1439 mvpp2_thread_write(port->priv, thread, in mvpp2_interrupts_mask()
1440 MVPP2_ISR_RX_TX_MASK_REG(port->id), 0); in mvpp2_interrupts_mask()
1441 mvpp2_thread_write(port->priv, thread, in mvpp2_interrupts_mask()
1442 MVPP2_ISR_RX_ERR_CAUSE_REG(port->id), 0); in mvpp2_interrupts_mask()
1456 if (cpu >= port->priv->nthreads) in mvpp2_interrupts_unmask()
1459 thread = mvpp2_cpu_to_thread(port->priv, cpu); in mvpp2_interrupts_unmask()
1462 MVPP2_CAUSE_RXQ_OCCUP_DESC_ALL_MASK(port->priv->hw_version); in mvpp2_interrupts_unmask()
1463 if (port->has_tx_irqs) in mvpp2_interrupts_unmask()
1466 mvpp2_thread_write(port->priv, thread, in mvpp2_interrupts_unmask()
1467 MVPP2_ISR_RX_TX_MASK_REG(port->id), val); in mvpp2_interrupts_unmask()
1468 mvpp2_thread_write(port->priv, thread, in mvpp2_interrupts_unmask()
1469 MVPP2_ISR_RX_ERR_CAUSE_REG(port->id), in mvpp2_interrupts_unmask()
1479 if (port->priv->hw_version == MVPP21) in mvpp2_shared_interrupt_mask_unmask()
1487 for (i = 0; i < port->nqvecs; i++) { in mvpp2_shared_interrupt_mask_unmask()
1488 struct mvpp2_queue_vector *v = port->qvecs + i; in mvpp2_shared_interrupt_mask_unmask()
1490 if (v->type != MVPP2_QUEUE_VECTOR_SHARED) in mvpp2_shared_interrupt_mask_unmask()
1493 mvpp2_thread_write(port->priv, v->sw_thread_id, in mvpp2_shared_interrupt_mask_unmask()
1494 MVPP2_ISR_RX_TX_MASK_REG(port->id), val); in mvpp2_shared_interrupt_mask_unmask()
1495 mvpp2_thread_write(port->priv, v->sw_thread_id, in mvpp2_shared_interrupt_mask_unmask()
1496 MVPP2_ISR_RX_ERR_CAUSE_REG(port->id), in mvpp2_shared_interrupt_mask_unmask()
1504 return port->gop_id == 0; in mvpp2_port_supports_xlg()
1509 return !(port->priv->hw_version >= MVPP22 && port->gop_id == 0); in mvpp2_port_supports_rgmii()
1533 struct mvpp2 *priv = port->priv; in mvpp22_gop_init_rgmii()
1536 regmap_read(priv->sysctrl_base, GENCONF_PORT_CTRL0, &val); in mvpp22_gop_init_rgmii()
1538 regmap_write(priv->sysctrl_base, GENCONF_PORT_CTRL0, val); in mvpp22_gop_init_rgmii()
1540 regmap_read(priv->sysctrl_base, GENCONF_CTRL0, &val); in mvpp22_gop_init_rgmii()
1541 if (port->gop_id == 2) { in mvpp22_gop_init_rgmii()
1543 } else if (port->gop_id == 3) { in mvpp22_gop_init_rgmii()
1549 * U-Boot does for mvpp2, so it is assumed to be correct. in mvpp22_gop_init_rgmii()
1551 if (port->phy_interface == PHY_INTERFACE_MODE_MII) in mvpp22_gop_init_rgmii()
1556 regmap_write(priv->sysctrl_base, GENCONF_CTRL0, val); in mvpp22_gop_init_rgmii()
1561 struct mvpp2 *priv = port->priv; in mvpp22_gop_init_sgmii()
1564 regmap_read(priv->sysctrl_base, GENCONF_PORT_CTRL0, &val); in mvpp22_gop_init_sgmii()
1567 regmap_write(priv->sysctrl_base, GENCONF_PORT_CTRL0, val); in mvpp22_gop_init_sgmii()
1569 if (port->gop_id > 1) { in mvpp22_gop_init_sgmii()
1570 regmap_read(priv->sysctrl_base, GENCONF_CTRL0, &val); in mvpp22_gop_init_sgmii()
1571 if (port->gop_id == 2) in mvpp22_gop_init_sgmii()
1573 else if (port->gop_id == 3) in mvpp22_gop_init_sgmii()
1575 regmap_write(priv->sysctrl_base, GENCONF_CTRL0, val); in mvpp22_gop_init_sgmii()
1581 struct mvpp2 *priv = port->priv; in mvpp22_gop_init_10gkr()
1582 void __iomem *mpcs = priv->iface_base + MVPP22_MPCS_BASE(port->gop_id); in mvpp22_gop_init_10gkr()
1583 void __iomem *xpcs = priv->iface_base + MVPP22_XPCS_BASE(port->gop_id); in mvpp22_gop_init_10gkr()
1604 struct mvpp2 *priv = port->priv; in mvpp22_gop_fca_enable_periodic()
1605 void __iomem *fca = priv->iface_base + MVPP22_FCA_BASE(port->gop_id); in mvpp22_gop_fca_enable_periodic()
1617 struct mvpp2 *priv = port->priv; in mvpp22_gop_fca_set_timer()
1618 void __iomem *fca = priv->iface_base + MVPP22_FCA_BASE(port->gop_id); in mvpp22_gop_fca_set_timer()
1635 timer = (port->priv->tclk / (USEC_PER_SEC * FC_CLK_DIVIDER)) in mvpp22_gop_fca_set_periodic_timer()
1647 struct mvpp2 *priv = port->priv; in mvpp22_gop_init()
1650 if (!priv->sysctrl_base) in mvpp22_gop_init()
1678 regmap_read(priv->sysctrl_base, GENCONF_PORT_CTRL1, &val); in mvpp22_gop_init()
1679 val |= GENCONF_PORT_CTRL1_RESET(port->gop_id) | in mvpp22_gop_init()
1680 GENCONF_PORT_CTRL1_EN(port->gop_id); in mvpp22_gop_init()
1681 regmap_write(priv->sysctrl_base, GENCONF_PORT_CTRL1, val); in mvpp22_gop_init()
1683 regmap_read(priv->sysctrl_base, GENCONF_PORT_CTRL0, &val); in mvpp22_gop_init()
1685 regmap_write(priv->sysctrl_base, GENCONF_PORT_CTRL0, val); in mvpp22_gop_init()
1687 regmap_read(priv->sysctrl_base, GENCONF_SOFT_RESET1, &val); in mvpp22_gop_init()
1689 regmap_write(priv->sysctrl_base, GENCONF_SOFT_RESET1, val); in mvpp22_gop_init()
1697 netdev_err(port->dev, "Invalid port configuration\n"); in mvpp22_gop_init()
1698 return -EINVAL; in mvpp22_gop_init()
1705 if (phy_interface_mode_is_rgmii(port->phy_interface) || in mvpp22_gop_unmask_irq()
1706 phy_interface_mode_is_8023z(port->phy_interface) || in mvpp22_gop_unmask_irq()
1707 port->phy_interface == PHY_INTERFACE_MODE_SGMII) { in mvpp22_gop_unmask_irq()
1709 val = readl(port->base + MVPP22_GMAC_INT_SUM_MASK); in mvpp22_gop_unmask_irq()
1711 writel(val, port->base + MVPP22_GMAC_INT_SUM_MASK); in mvpp22_gop_unmask_irq()
1716 val = readl(port->base + MVPP22_XLG_EXT_INT_MASK); in mvpp22_gop_unmask_irq()
1717 if (mvpp2_is_xlg(port->phy_interface)) in mvpp22_gop_unmask_irq()
1721 writel(val, port->base + MVPP22_XLG_EXT_INT_MASK); in mvpp22_gop_unmask_irq()
1730 val = readl(port->base + MVPP22_XLG_EXT_INT_MASK); in mvpp22_gop_mask_irq()
1733 writel(val, port->base + MVPP22_XLG_EXT_INT_MASK); in mvpp22_gop_mask_irq()
1736 if (phy_interface_mode_is_rgmii(port->phy_interface) || in mvpp22_gop_mask_irq()
1737 phy_interface_mode_is_8023z(port->phy_interface) || in mvpp22_gop_mask_irq()
1738 port->phy_interface == PHY_INTERFACE_MODE_SGMII) { in mvpp22_gop_mask_irq()
1739 val = readl(port->base + MVPP22_GMAC_INT_SUM_MASK); in mvpp22_gop_mask_irq()
1741 writel(val, port->base + MVPP22_GMAC_INT_SUM_MASK); in mvpp22_gop_mask_irq()
1749 mvpp2_modify(port->base + MVPP22_GMAC_INT_SUM_MASK, in mvpp22_gop_setup_irq()
1753 if (port->phylink || in mvpp22_gop_setup_irq()
1754 phy_interface_mode_is_rgmii(port->phy_interface) || in mvpp22_gop_setup_irq()
1755 phy_interface_mode_is_8023z(port->phy_interface) || in mvpp22_gop_setup_irq()
1756 port->phy_interface == PHY_INTERFACE_MODE_SGMII) { in mvpp22_gop_setup_irq()
1757 val = readl(port->base + MVPP22_GMAC_INT_MASK); in mvpp22_gop_setup_irq()
1759 writel(val, port->base + MVPP22_GMAC_INT_MASK); in mvpp22_gop_setup_irq()
1763 val = readl(port->base + MVPP22_XLG_INT_MASK); in mvpp22_gop_setup_irq()
1765 writel(val, port->base + MVPP22_XLG_INT_MASK); in mvpp22_gop_setup_irq()
1767 mvpp2_modify(port->base + MVPP22_XLG_EXT_INT_MASK, in mvpp22_gop_setup_irq()
1783 * "PPv2 (2500BaseX) - COMPHY (2500SGMII)" are valid.
1790 if (!port->comphy) in mvpp22_comphy_init()
1793 ret = phy_set_mode_ext(port->comphy, PHY_MODE_ETHERNET, interface); in mvpp22_comphy_init()
1797 return phy_power_on(port->comphy); in mvpp22_comphy_init()
1805 mvpp2_is_xlg(port->phy_interface)) { in mvpp2_port_enable()
1806 val = readl(port->base + MVPP22_XLG_CTRL0_REG); in mvpp2_port_enable()
1809 writel(val, port->base + MVPP22_XLG_CTRL0_REG); in mvpp2_port_enable()
1811 val = readl(port->base + MVPP2_GMAC_CTRL_0_REG); in mvpp2_port_enable()
1814 writel(val, port->base + MVPP2_GMAC_CTRL_0_REG); in mvpp2_port_enable()
1823 mvpp2_is_xlg(port->phy_interface)) { in mvpp2_port_disable()
1824 val = readl(port->base + MVPP22_XLG_CTRL0_REG); in mvpp2_port_disable()
1826 writel(val, port->base + MVPP22_XLG_CTRL0_REG); in mvpp2_port_disable()
1829 val = readl(port->base + MVPP2_GMAC_CTRL_0_REG); in mvpp2_port_disable()
1831 writel(val, port->base + MVPP2_GMAC_CTRL_0_REG); in mvpp2_port_disable()
1834 /* Set IEEE 802.3x Flow Control Xon Packet Transmission Mode */
1839 val = readl(port->base + MVPP2_GMAC_CTRL_1_REG) & in mvpp2_port_periodic_xon_disable()
1841 writel(val, port->base + MVPP2_GMAC_CTRL_1_REG); in mvpp2_port_periodic_xon_disable()
1850 val = readl(port->base + MVPP2_GMAC_CTRL_1_REG); in mvpp2_port_loopback_set()
1852 if (state->speed == 1000) in mvpp2_port_loopback_set()
1857 if (phy_interface_mode_is_8023z(state->interface) || in mvpp2_port_loopback_set()
1858 state->interface == PHY_INTERFACE_MODE_SGMII) in mvpp2_port_loopback_set()
1863 writel(val, port->base + MVPP2_GMAC_CTRL_1_REG); in mvpp2_port_loopback_set()
1887 val = readl(port->stats_base + counter->offset); in mvpp2_read_count()
1888 if (counter->reg_is_64b) in mvpp2_read_count()
1889 val += (u64)readl(port->stats_base + counter->offset + 4) << 32; in mvpp2_read_count()
2000 for (q = 0; q < port->ntxqs; q++) in mvpp2_ethtool_get_strings()
2006 for (q = 0; q < port->nrxqs; q++) in mvpp2_ethtool_get_strings()
2033 cpu_stats = per_cpu_ptr(port->stats, cpu); in mvpp2_get_xdp_stats()
2035 start = u64_stats_fetch_begin(&cpu_stats->syncp); in mvpp2_get_xdp_stats()
2036 xdp_redirect = cpu_stats->xdp_redirect; in mvpp2_get_xdp_stats()
2037 xdp_pass = cpu_stats->xdp_pass; in mvpp2_get_xdp_stats()
2038 xdp_drop = cpu_stats->xdp_drop; in mvpp2_get_xdp_stats()
2039 xdp_xmit = cpu_stats->xdp_xmit; in mvpp2_get_xdp_stats()
2040 xdp_xmit_err = cpu_stats->xdp_xmit_err; in mvpp2_get_xdp_stats()
2041 xdp_tx = cpu_stats->xdp_tx; in mvpp2_get_xdp_stats()
2042 xdp_tx_err = cpu_stats->xdp_tx_err; in mvpp2_get_xdp_stats()
2043 } while (u64_stats_fetch_retry(&cpu_stats->syncp, start)); in mvpp2_get_xdp_stats()
2045 xdp_stats->xdp_redirect += xdp_redirect; in mvpp2_get_xdp_stats()
2046 xdp_stats->xdp_pass += xdp_pass; in mvpp2_get_xdp_stats()
2047 xdp_stats->xdp_drop += xdp_drop; in mvpp2_get_xdp_stats()
2048 xdp_stats->xdp_xmit += xdp_xmit; in mvpp2_get_xdp_stats()
2049 xdp_stats->xdp_xmit_err += xdp_xmit_err; in mvpp2_get_xdp_stats()
2050 xdp_stats->xdp_tx += xdp_tx; in mvpp2_get_xdp_stats()
2051 xdp_stats->xdp_tx_err += xdp_tx_err; in mvpp2_get_xdp_stats()
2062 pstats = port->ethtool_stats; in mvpp2_read_stats()
2068 *pstats++ += mvpp2_read(port->priv, in mvpp2_read_stats()
2070 4 * port->id); in mvpp2_read_stats()
2072 for (q = 0; q < port->ntxqs; q++) in mvpp2_read_stats()
2074 *pstats++ += mvpp2_read_index(port->priv, in mvpp2_read_stats()
2075 MVPP22_CTRS_TX_CTR(port->id, q), in mvpp2_read_stats()
2079 * driver's. We need to add the port->first_rxq offset. in mvpp2_read_stats()
2081 for (q = 0; q < port->nrxqs; q++) in mvpp2_read_stats()
2083 *pstats++ += mvpp2_read_index(port->priv, in mvpp2_read_stats()
2084 port->first_rxq + q, in mvpp2_read_stats()
2093 switch (s->offset) { in mvpp2_read_stats()
2125 mutex_lock(&port->gather_stats_lock); in mvpp2_gather_hw_statistics()
2132 cancel_delayed_work(&port->stats_work); in mvpp2_gather_hw_statistics()
2133 queue_delayed_work(port->priv->stats_queue, &port->stats_work, in mvpp2_gather_hw_statistics()
2136 mutex_unlock(&port->gather_stats_lock); in mvpp2_gather_hw_statistics()
2147 mvpp2_gather_hw_statistics(&port->stats_work.work); in mvpp2_ethtool_get_stats()
2149 mutex_lock(&port->gather_stats_lock); in mvpp2_ethtool_get_stats()
2150 memcpy(data, port->ethtool_stats, in mvpp2_ethtool_get_stats()
2151 sizeof(u64) * MVPP2_N_ETHTOOL_STATS(port->ntxqs, port->nrxqs)); in mvpp2_ethtool_get_stats()
2152 mutex_unlock(&port->gather_stats_lock); in mvpp2_ethtool_get_stats()
2160 return MVPP2_N_ETHTOOL_STATS(port->ntxqs, port->nrxqs); in mvpp2_ethtool_get_sset_count()
2162 return -EOPNOTSUPP; in mvpp2_ethtool_get_sset_count()
2169 val = readl(port->base + MVPP2_GMAC_CTRL_2_REG) | in mvpp2_mac_reset_assert()
2171 writel(val, port->base + MVPP2_GMAC_CTRL_2_REG); in mvpp2_mac_reset_assert()
2173 if (port->priv->hw_version >= MVPP22 && port->gop_id == 0) { in mvpp2_mac_reset_assert()
2174 val = readl(port->base + MVPP22_XLG_CTRL0_REG) & in mvpp2_mac_reset_assert()
2176 writel(val, port->base + MVPP22_XLG_CTRL0_REG); in mvpp2_mac_reset_assert()
2182 struct mvpp2 *priv = port->priv; in mvpp22_pcs_reset_assert()
2186 if (port->priv->hw_version == MVPP21 || port->gop_id != 0) in mvpp22_pcs_reset_assert()
2189 mpcs = priv->iface_base + MVPP22_MPCS_BASE(port->gop_id); in mvpp22_pcs_reset_assert()
2190 xpcs = priv->iface_base + MVPP22_XPCS_BASE(port->gop_id); in mvpp22_pcs_reset_assert()
2204 struct mvpp2 *priv = port->priv; in mvpp22_pcs_reset_deassert()
2208 if (port->priv->hw_version == MVPP21 || port->gop_id != 0) in mvpp22_pcs_reset_deassert()
2211 mpcs = priv->iface_base + MVPP22_MPCS_BASE(port->gop_id); in mvpp22_pcs_reset_deassert()
2212 xpcs = priv->iface_base + MVPP22_XPCS_BASE(port->gop_id); in mvpp22_pcs_reset_deassert()
2238 val = readl(port->base + MVPP2_GMAC_CTRL_0_REG); in mvpp2_gmac_max_rx_size_set()
2240 val |= (((port->pkt_size - MVPP2_MH_SIZE) / 2) << in mvpp2_gmac_max_rx_size_set()
2242 writel(val, port->base + MVPP2_GMAC_CTRL_0_REG); in mvpp2_gmac_max_rx_size_set()
2250 val = readl(port->base + MVPP22_XLG_CTRL1_REG); in mvpp2_xlg_max_rx_size_set()
2252 val |= ((port->pkt_size - MVPP2_MH_SIZE) / 2) << in mvpp2_xlg_max_rx_size_set()
2254 writel(val, port->base + MVPP22_XLG_CTRL1_REG); in mvpp2_xlg_max_rx_size_set()
2262 if (port->priv->hw_version == MVPP21) { in mvpp2_defaults_set()
2264 val = readl(port->base + MVPP2_GMAC_PORT_FIFO_CFG_1_REG); in mvpp2_defaults_set()
2267 val |= MVPP2_GMAC_TX_FIFO_MIN_TH_MASK(64 - 4 - 2); in mvpp2_defaults_set()
2268 writel(val, port->base + MVPP2_GMAC_PORT_FIFO_CFG_1_REG); in mvpp2_defaults_set()
2273 mvpp2_write(port->priv, MVPP2_TXP_SCHED_PORT_INDEX_REG, in mvpp2_defaults_set()
2275 mvpp2_write(port->priv, MVPP2_TXP_SCHED_CMD_1_REG, 0); in mvpp2_defaults_set()
2277 /* Set TXQ scheduling to Round-Robin */ in mvpp2_defaults_set()
2278 mvpp2_write(port->priv, MVPP2_TXP_SCHED_FIXED_PRIO_REG, 0); in mvpp2_defaults_set()
2282 mvpp2_write(port->priv, in mvpp2_defaults_set()
2288 mvpp2_write(port->priv, MVPP2_TXP_SCHED_PERIOD_REG, in mvpp2_defaults_set()
2289 port->priv->tclk / USEC_PER_SEC); in mvpp2_defaults_set()
2290 val = mvpp2_read(port->priv, MVPP2_TXP_SCHED_REFILL_REG); in mvpp2_defaults_set()
2294 mvpp2_write(port->priv, MVPP2_TXP_SCHED_REFILL_REG, val); in mvpp2_defaults_set()
2296 mvpp2_write(port->priv, MVPP2_TXP_SCHED_TOKEN_SIZE_REG, val); in mvpp2_defaults_set()
2299 mvpp2_write(port->priv, MVPP2_RX_CTRL_REG(port->id), in mvpp2_defaults_set()
2304 for (lrxq = 0; lrxq < port->nrxqs; lrxq++) { in mvpp2_defaults_set()
2305 queue = port->rxqs[lrxq]->id; in mvpp2_defaults_set()
2306 val = mvpp2_read(port->priv, MVPP2_RXQ_CONFIG_REG(queue)); in mvpp2_defaults_set()
2309 mvpp2_write(port->priv, MVPP2_RXQ_CONFIG_REG(queue), val); in mvpp2_defaults_set()
2322 for (lrxq = 0; lrxq < port->nrxqs; lrxq++) { in mvpp2_ingress_enable()
2323 queue = port->rxqs[lrxq]->id; in mvpp2_ingress_enable()
2324 val = mvpp2_read(port->priv, MVPP2_RXQ_CONFIG_REG(queue)); in mvpp2_ingress_enable()
2326 mvpp2_write(port->priv, MVPP2_RXQ_CONFIG_REG(queue), val); in mvpp2_ingress_enable()
2335 for (lrxq = 0; lrxq < port->nrxqs; lrxq++) { in mvpp2_ingress_disable()
2336 queue = port->rxqs[lrxq]->id; in mvpp2_ingress_disable()
2337 val = mvpp2_read(port->priv, MVPP2_RXQ_CONFIG_REG(queue)); in mvpp2_ingress_disable()
2339 mvpp2_write(port->priv, MVPP2_RXQ_CONFIG_REG(queue), val); in mvpp2_ingress_disable()
2344 * - HW starts take descriptors from DRAM
2354 for (queue = 0; queue < port->ntxqs; queue++) { in mvpp2_egress_enable()
2355 struct mvpp2_tx_queue *txq = port->txqs[queue]; in mvpp2_egress_enable()
2357 if (txq->descs) in mvpp2_egress_enable()
2361 mvpp2_write(port->priv, MVPP2_TXP_SCHED_PORT_INDEX_REG, tx_port_num); in mvpp2_egress_enable()
2362 mvpp2_write(port->priv, MVPP2_TXP_SCHED_Q_CMD_REG, qmap); in mvpp2_egress_enable()
2366 * - HW doesn't take descriptors from DRAM
2375 mvpp2_write(port->priv, MVPP2_TXP_SCHED_PORT_INDEX_REG, tx_port_num); in mvpp2_egress_disable()
2376 reg_data = (mvpp2_read(port->priv, MVPP2_TXP_SCHED_Q_CMD_REG)) & in mvpp2_egress_disable()
2379 mvpp2_write(port->priv, MVPP2_TXP_SCHED_Q_CMD_REG, in mvpp2_egress_disable()
2386 netdev_warn(port->dev, in mvpp2_egress_disable()
2387 "Tx stop timed out, status=0x%08x\n", in mvpp2_egress_disable()
2397 reg_data = mvpp2_read(port->priv, MVPP2_TXP_SCHED_Q_CMD_REG); in mvpp2_egress_disable()
2407 u32 val = mvpp2_read(port->priv, MVPP2_RXQ_STATUS_REG(rxq_id)); in mvpp2_rxq_received()
2424 mvpp2_write(port->priv, MVPP2_RXQ_STATUS_UPDATE_REG(rxq_id), val); in mvpp2_rxq_status_update()
2431 int rx_desc = rxq->next_desc_to_proc; in mvpp2_rxq_next_desc_get()
2433 rxq->next_desc_to_proc = MVPP2_QUEUE_NEXT_DESC(rxq, rx_desc); in mvpp2_rxq_next_desc_get()
2434 prefetch(rxq->descs + rxq->next_desc_to_proc); in mvpp2_rxq_next_desc_get()
2435 return rxq->descs + rx_desc; in mvpp2_rxq_next_desc_get()
2445 offset = offset >> 5; in mvpp2_rxq_offset_set()
2447 val = mvpp2_read(port->priv, MVPP2_RXQ_CONFIG_REG(prxq)); in mvpp2_rxq_offset_set()
2454 mvpp2_write(port->priv, MVPP2_RXQ_CONFIG_REG(prxq), val); in mvpp2_rxq_offset_set()
2463 int tx_desc = txq->next_desc_to_proc; in mvpp2_txq_next_desc_get()
2465 txq->next_desc_to_proc = MVPP2_QUEUE_NEXT_DESC(txq, tx_desc); in mvpp2_txq_next_desc_get()
2466 return txq->descs + tx_desc; in mvpp2_txq_next_desc_get()
2476 /* aggregated access - relevant TXQ number is written in TX desc */ in mvpp2_aggr_txq_pend_desc_add()
2477 mvpp2_thread_write(port->priv, in mvpp2_aggr_txq_pend_desc_add()
2478 mvpp2_cpu_to_thread(port->priv, smp_processor_id()), in mvpp2_aggr_txq_pend_desc_add()
2491 if ((aggr_txq->count + num) > MVPP2_AGGR_TXQ_SIZE) { in mvpp2_aggr_desc_num_check()
2494 mvpp2_cpu_to_thread(port->priv, smp_processor_id()); in mvpp2_aggr_desc_num_check()
2495 u32 val = mvpp2_read_relaxed(port->priv, in mvpp2_aggr_desc_num_check()
2498 aggr_txq->count = val & MVPP2_AGGR_TXQ_PENDING_MASK; in mvpp2_aggr_desc_num_check()
2500 if ((aggr_txq->count + num) > MVPP2_AGGR_TXQ_SIZE) in mvpp2_aggr_desc_num_check()
2501 return -ENOMEM; in mvpp2_aggr_desc_num_check()
2515 unsigned int thread = mvpp2_cpu_to_thread(port->priv, smp_processor_id()); in mvpp2_txq_alloc_reserved_desc()
2516 struct mvpp2 *priv = port->priv; in mvpp2_txq_alloc_reserved_desc()
2519 val = (txq->id << MVPP2_TXQ_RSVD_REQ_Q_OFFSET) | num; in mvpp2_txq_alloc_reserved_desc()
2538 if (txq_pcpu->reserved_num >= num) in mvpp2_txq_reserved_desc_num_proc()
2547 for (thread = 0; thread < port->priv->nthreads; thread++) { in mvpp2_txq_reserved_desc_num_proc()
2550 txq_pcpu_aux = per_cpu_ptr(txq->pcpu, thread); in mvpp2_txq_reserved_desc_num_proc()
2551 desc_count += txq_pcpu_aux->count; in mvpp2_txq_reserved_desc_num_proc()
2552 desc_count += txq_pcpu_aux->reserved_num; in mvpp2_txq_reserved_desc_num_proc()
2555 req = max(MVPP2_CPU_DESC_CHUNK, num - txq_pcpu->reserved_num); in mvpp2_txq_reserved_desc_num_proc()
2559 (txq->size - (MVPP2_MAX_THREADS * MVPP2_CPU_DESC_CHUNK))) in mvpp2_txq_reserved_desc_num_proc()
2560 return -ENOMEM; in mvpp2_txq_reserved_desc_num_proc()
2562 txq_pcpu->reserved_num += mvpp2_txq_alloc_reserved_desc(port, txq, req); in mvpp2_txq_reserved_desc_num_proc()
2565 if (txq_pcpu->reserved_num < num) in mvpp2_txq_reserved_desc_num_proc()
2566 return -ENOMEM; in mvpp2_txq_reserved_desc_num_proc()
2575 if (txq->next_desc_to_proc == 0) in mvpp2_txq_desc_put()
2576 txq->next_desc_to_proc = txq->last_desc - 1; in mvpp2_txq_desc_put()
2578 txq->next_desc_to_proc--; in mvpp2_txq_desc_put()
2616 * Per-thread access
2628 val = mvpp2_thread_read_relaxed(port->priv, in mvpp2_txq_sent_desc_proc()
2629 mvpp2_cpu_to_thread(port->priv, smp_processor_id()), in mvpp2_txq_sent_desc_proc()
2630 MVPP2_TXQ_SENT_REG(txq->id)); in mvpp2_txq_sent_desc_proc()
2645 if (smp_processor_id() >= port->priv->nthreads) in mvpp2_txq_sent_counter_clear()
2648 for (queue = 0; queue < port->ntxqs; queue++) { in mvpp2_txq_sent_counter_clear()
2649 int id = port->txqs[queue]->id; in mvpp2_txq_sent_counter_clear()
2651 mvpp2_thread_read(port->priv, in mvpp2_txq_sent_counter_clear()
2652 mvpp2_cpu_to_thread(port->priv, smp_processor_id()), in mvpp2_txq_sent_counter_clear()
2663 mtu = port->pkt_size * 8; in mvpp2_txp_max_tx_size_set()
2672 mvpp2_write(port->priv, MVPP2_TXP_SCHED_PORT_INDEX_REG, tx_port_num); in mvpp2_txp_max_tx_size_set()
2675 val = mvpp2_read(port->priv, MVPP2_TXP_SCHED_MTU_REG); in mvpp2_txp_max_tx_size_set()
2678 mvpp2_write(port->priv, MVPP2_TXP_SCHED_MTU_REG, val); in mvpp2_txp_max_tx_size_set()
2681 val = mvpp2_read(port->priv, MVPP2_TXP_SCHED_TOKEN_SIZE_REG); in mvpp2_txp_max_tx_size_set()
2687 mvpp2_write(port->priv, MVPP2_TXP_SCHED_TOKEN_SIZE_REG, val); in mvpp2_txp_max_tx_size_set()
2690 for (txq = 0; txq < port->ntxqs; txq++) { in mvpp2_txp_max_tx_size_set()
2691 val = mvpp2_read(port->priv, in mvpp2_txp_max_tx_size_set()
2699 mvpp2_write(port->priv, in mvpp2_txp_max_tx_size_set()
2706 /* Set the number of non-occupied descriptors threshold */
2712 mvpp2_write(port->priv, MVPP2_RXQ_NUM_REG, rxq->id); in mvpp2_set_rxq_free_tresh()
2714 val = mvpp2_read(port->priv, MVPP2_RXQ_THRESH_REG); in mvpp2_set_rxq_free_tresh()
2717 mvpp2_write(port->priv, MVPP2_RXQ_THRESH_REG, val); in mvpp2_set_rxq_free_tresh()
2726 unsigned int thread = mvpp2_cpu_to_thread(port->priv, get_cpu()); in mvpp2_rx_pkts_coal_set()
2728 if (rxq->pkts_coal > MVPP2_OCCUPIED_THRESH_MASK) in mvpp2_rx_pkts_coal_set()
2729 rxq->pkts_coal = MVPP2_OCCUPIED_THRESH_MASK; in mvpp2_rx_pkts_coal_set()
2731 mvpp2_thread_write(port->priv, thread, MVPP2_RXQ_NUM_REG, rxq->id); in mvpp2_rx_pkts_coal_set()
2732 mvpp2_thread_write(port->priv, thread, MVPP2_RXQ_THRESH_REG, in mvpp2_rx_pkts_coal_set()
2733 rxq->pkts_coal); in mvpp2_rx_pkts_coal_set()
2745 if (txq->done_pkts_coal > MVPP2_TXQ_THRESH_MASK) in mvpp2_tx_pkts_coal_set()
2746 txq->done_pkts_coal = MVPP2_TXQ_THRESH_MASK; in mvpp2_tx_pkts_coal_set()
2748 val = (txq->done_pkts_coal << MVPP2_TXQ_THRESH_OFFSET); in mvpp2_tx_pkts_coal_set()
2749 /* PKT-coalescing registers are per-queue + per-thread */ in mvpp2_tx_pkts_coal_set()
2751 mvpp2_thread_write(port->priv, thread, MVPP2_TXQ_NUM_REG, txq->id); in mvpp2_tx_pkts_coal_set()
2752 mvpp2_thread_write(port->priv, thread, MVPP2_TXQ_THRESH_REG, val); in mvpp2_tx_pkts_coal_set()
2778 unsigned long freq = port->priv->tclk; in mvpp2_rx_time_coal_set()
2779 u32 val = mvpp2_usec_to_cycles(rxq->time_coal, freq); in mvpp2_rx_time_coal_set()
2782 rxq->time_coal = in mvpp2_rx_time_coal_set()
2785 /* re-evaluate to get actual register value */ in mvpp2_rx_time_coal_set()
2786 val = mvpp2_usec_to_cycles(rxq->time_coal, freq); in mvpp2_rx_time_coal_set()
2789 mvpp2_write(port->priv, MVPP2_ISR_RX_THRESHOLD_REG(rxq->id), val); in mvpp2_rx_time_coal_set()
2794 unsigned long freq = port->priv->tclk; in mvpp2_tx_time_coal_set()
2795 u32 val = mvpp2_usec_to_cycles(port->tx_time_coal, freq); in mvpp2_tx_time_coal_set()
2798 port->tx_time_coal = in mvpp2_tx_time_coal_set()
2801 /* re-evaluate to get actual register value */ in mvpp2_tx_time_coal_set()
2802 val = mvpp2_usec_to_cycles(port->tx_time_coal, freq); in mvpp2_tx_time_coal_set()
2805 mvpp2_write(port->priv, MVPP2_ISR_TX_THRESHOLD_REG(port->id), val); in mvpp2_tx_time_coal_set()
2822 txq_pcpu->buffs + txq_pcpu->txq_get_index; in mvpp2_txq_bufs_free()
2824 if (!IS_TSO_HEADER(txq_pcpu, tx_buf->dma) && in mvpp2_txq_bufs_free()
2825 tx_buf->type != MVPP2_TYPE_XDP_TX) in mvpp2_txq_bufs_free()
2826 dma_unmap_single(port->dev->dev.parent, tx_buf->dma, in mvpp2_txq_bufs_free()
2827 tx_buf->size, DMA_TO_DEVICE); in mvpp2_txq_bufs_free()
2828 if (tx_buf->type == MVPP2_TYPE_SKB && tx_buf->skb) in mvpp2_txq_bufs_free()
2829 dev_kfree_skb_any(tx_buf->skb); in mvpp2_txq_bufs_free()
2830 else if (tx_buf->type == MVPP2_TYPE_XDP_TX || in mvpp2_txq_bufs_free()
2831 tx_buf->type == MVPP2_TYPE_XDP_NDO) in mvpp2_txq_bufs_free()
2832 xdp_return_frame_bulk(tx_buf->xdpf, &bq); in mvpp2_txq_bufs_free()
2844 int queue = fls(cause) - 1; in mvpp2_get_rx_queue()
2846 return port->rxqs[queue]; in mvpp2_get_rx_queue()
2852 int queue = fls(cause) - 1; in mvpp2_get_tx_queue()
2854 return port->txqs[queue]; in mvpp2_get_tx_queue()
2861 struct netdev_queue *nq = netdev_get_tx_queue(port->dev, txq->log_id); in mvpp2_txq_done()
2864 if (txq_pcpu->thread != mvpp2_cpu_to_thread(port->priv, smp_processor_id())) in mvpp2_txq_done()
2865 netdev_err(port->dev, "wrong cpu on the end of Tx processing\n"); in mvpp2_txq_done()
2872 txq_pcpu->count -= tx_done; in mvpp2_txq_done()
2875 if (txq_pcpu->count <= txq_pcpu->wake_threshold) in mvpp2_txq_done()
2891 txq_pcpu = per_cpu_ptr(txq->pcpu, thread); in mvpp2_tx_done()
2893 if (txq_pcpu->count) { in mvpp2_tx_done()
2895 tx_todo += txq_pcpu->count; in mvpp2_tx_done()
2898 cause &= ~(1 << txq->log_id); in mvpp2_tx_done()
2913 aggr_txq->descs = dma_alloc_coherent(&pdev->dev, in mvpp2_aggr_txq_init()
2915 &aggr_txq->descs_dma, GFP_KERNEL); in mvpp2_aggr_txq_init()
2916 if (!aggr_txq->descs) in mvpp2_aggr_txq_init()
2917 return -ENOMEM; in mvpp2_aggr_txq_init()
2919 aggr_txq->last_desc = MVPP2_AGGR_TXQ_SIZE - 1; in mvpp2_aggr_txq_init()
2922 aggr_txq->next_desc_to_proc = mvpp2_read(priv, in mvpp2_aggr_txq_init()
2928 if (priv->hw_version == MVPP21) in mvpp2_aggr_txq_init()
2929 txq_dma = aggr_txq->descs_dma; in mvpp2_aggr_txq_init()
2931 txq_dma = aggr_txq->descs_dma >> in mvpp2_aggr_txq_init()
2945 struct mvpp2 *priv = port->priv; in mvpp2_rxq_init()
2950 rxq->size = port->rx_ring_size; in mvpp2_rxq_init()
2953 rxq->descs = dma_alloc_coherent(port->dev->dev.parent, in mvpp2_rxq_init()
2954 rxq->size * MVPP2_DESC_ALIGNED_SIZE, in mvpp2_rxq_init()
2955 &rxq->descs_dma, GFP_KERNEL); in mvpp2_rxq_init()
2956 if (!rxq->descs) in mvpp2_rxq_init()
2957 return -ENOMEM; in mvpp2_rxq_init()
2959 rxq->last_desc = rxq->size - 1; in mvpp2_rxq_init()
2961 /* Zero occupied and non-occupied counters - direct access */ in mvpp2_rxq_init()
2962 mvpp2_write(port->priv, MVPP2_RXQ_STATUS_REG(rxq->id), 0); in mvpp2_rxq_init()
2964 /* Set Rx descriptors queue starting address - indirect access */ in mvpp2_rxq_init()
2965 thread = mvpp2_cpu_to_thread(port->priv, get_cpu()); in mvpp2_rxq_init()
2966 mvpp2_thread_write(port->priv, thread, MVPP2_RXQ_NUM_REG, rxq->id); in mvpp2_rxq_init()
2967 if (port->priv->hw_version == MVPP21) in mvpp2_rxq_init()
2968 rxq_dma = rxq->descs_dma; in mvpp2_rxq_init()
2970 rxq_dma = rxq->descs_dma >> MVPP22_DESC_ADDR_OFFS; in mvpp2_rxq_init()
2971 mvpp2_thread_write(port->priv, thread, MVPP2_RXQ_DESC_ADDR_REG, rxq_dma); in mvpp2_rxq_init()
2972 mvpp2_thread_write(port->priv, thread, MVPP2_RXQ_DESC_SIZE_REG, rxq->size); in mvpp2_rxq_init()
2973 mvpp2_thread_write(port->priv, thread, MVPP2_RXQ_INDEX_REG, 0); in mvpp2_rxq_init()
2977 mvpp2_rxq_offset_set(port, rxq->id, MVPP2_SKB_HEADROOM); in mvpp2_rxq_init()
2987 mvpp2_rxq_status_update(port, rxq->id, 0, rxq->size); in mvpp2_rxq_init()
2989 if (priv->percpu_pools) { in mvpp2_rxq_init()
2990 err = xdp_rxq_info_reg(&rxq->xdp_rxq_short, port->dev, rxq->logic_rxq, 0); in mvpp2_rxq_init()
2994 err = xdp_rxq_info_reg(&rxq->xdp_rxq_long, port->dev, rxq->logic_rxq, 0); in mvpp2_rxq_init()
2999 err = xdp_rxq_info_reg_mem_model(&rxq->xdp_rxq_short, in mvpp2_rxq_init()
3001 priv->page_pool[rxq->logic_rxq]); in mvpp2_rxq_init()
3005 err = xdp_rxq_info_reg_mem_model(&rxq->xdp_rxq_long, in mvpp2_rxq_init()
3007 priv->page_pool[rxq->logic_rxq + in mvpp2_rxq_init()
3008 port->nrxqs]); in mvpp2_rxq_init()
3016 xdp_rxq_info_unreg_mem_model(&rxq->xdp_rxq_short); in mvpp2_rxq_init()
3018 xdp_rxq_info_unreg(&rxq->xdp_rxq_long); in mvpp2_rxq_init()
3020 xdp_rxq_info_unreg(&rxq->xdp_rxq_short); in mvpp2_rxq_init()
3022 dma_free_coherent(port->dev->dev.parent, in mvpp2_rxq_init()
3023 rxq->size * MVPP2_DESC_ALIGNED_SIZE, in mvpp2_rxq_init()
3024 rxq->descs, rxq->descs_dma); in mvpp2_rxq_init()
3034 rx_received = mvpp2_rxq_received(port, rxq->id); in mvpp2_rxq_drop_pkts()
3050 mvpp2_rxq_status_update(port, rxq->id, rx_received, rx_received); in mvpp2_rxq_drop_pkts()
3059 if (xdp_rxq_info_is_reg(&rxq->xdp_rxq_short)) in mvpp2_rxq_deinit()
3060 xdp_rxq_info_unreg(&rxq->xdp_rxq_short); in mvpp2_rxq_deinit()
3062 if (xdp_rxq_info_is_reg(&rxq->xdp_rxq_long)) in mvpp2_rxq_deinit()
3063 xdp_rxq_info_unreg(&rxq->xdp_rxq_long); in mvpp2_rxq_deinit()
3067 if (rxq->descs) in mvpp2_rxq_deinit()
3068 dma_free_coherent(port->dev->dev.parent, in mvpp2_rxq_deinit()
3069 rxq->size * MVPP2_DESC_ALIGNED_SIZE, in mvpp2_rxq_deinit()
3070 rxq->descs, in mvpp2_rxq_deinit()
3071 rxq->descs_dma); in mvpp2_rxq_deinit()
3073 rxq->descs = NULL; in mvpp2_rxq_deinit()
3074 rxq->last_desc = 0; in mvpp2_rxq_deinit()
3075 rxq->next_desc_to_proc = 0; in mvpp2_rxq_deinit()
3076 rxq->descs_dma = 0; in mvpp2_rxq_deinit()
3081 mvpp2_write(port->priv, MVPP2_RXQ_STATUS_REG(rxq->id), 0); in mvpp2_rxq_deinit()
3082 thread = mvpp2_cpu_to_thread(port->priv, get_cpu()); in mvpp2_rxq_deinit()
3083 mvpp2_thread_write(port->priv, thread, MVPP2_RXQ_NUM_REG, rxq->id); in mvpp2_rxq_deinit()
3084 mvpp2_thread_write(port->priv, thread, MVPP2_RXQ_DESC_ADDR_REG, 0); in mvpp2_rxq_deinit()
3085 mvpp2_thread_write(port->priv, thread, MVPP2_RXQ_DESC_SIZE_REG, 0); in mvpp2_rxq_deinit()
3098 txq->size = port->tx_ring_size; in mvpp2_txq_init()
3101 txq->descs = dma_alloc_coherent(port->dev->dev.parent, in mvpp2_txq_init()
3102 txq->size * MVPP2_DESC_ALIGNED_SIZE, in mvpp2_txq_init()
3103 &txq->descs_dma, GFP_KERNEL); in mvpp2_txq_init()
3104 if (!txq->descs) in mvpp2_txq_init()
3105 return -ENOMEM; in mvpp2_txq_init()
3107 txq->last_desc = txq->size - 1; in mvpp2_txq_init()
3109 /* Set Tx descriptors queue starting address - indirect access */ in mvpp2_txq_init()
3110 thread = mvpp2_cpu_to_thread(port->priv, get_cpu()); in mvpp2_txq_init()
3111 mvpp2_thread_write(port->priv, thread, MVPP2_TXQ_NUM_REG, txq->id); in mvpp2_txq_init()
3112 mvpp2_thread_write(port->priv, thread, MVPP2_TXQ_DESC_ADDR_REG, in mvpp2_txq_init()
3113 txq->descs_dma); in mvpp2_txq_init()
3114 mvpp2_thread_write(port->priv, thread, MVPP2_TXQ_DESC_SIZE_REG, in mvpp2_txq_init()
3115 txq->size & MVPP2_TXQ_DESC_SIZE_MASK); in mvpp2_txq_init()
3116 mvpp2_thread_write(port->priv, thread, MVPP2_TXQ_INDEX_REG, 0); in mvpp2_txq_init()
3117 mvpp2_thread_write(port->priv, thread, MVPP2_TXQ_RSVD_CLR_REG, in mvpp2_txq_init()
3118 txq->id << MVPP2_TXQ_RSVD_CLR_OFFSET); in mvpp2_txq_init()
3119 val = mvpp2_thread_read(port->priv, thread, MVPP2_TXQ_PENDING_REG); in mvpp2_txq_init()
3121 mvpp2_thread_write(port->priv, thread, MVPP2_TXQ_PENDING_REG, val); in mvpp2_txq_init()
3129 desc = (port->id * MVPP2_MAX_TXQ * desc_per_txq) + in mvpp2_txq_init()
3130 (txq->log_id * desc_per_txq); in mvpp2_txq_init()
3132 mvpp2_thread_write(port->priv, thread, MVPP2_TXQ_PREF_BUF_REG, in mvpp2_txq_init()
3137 /* WRR / EJP configuration - indirect access */ in mvpp2_txq_init()
3139 mvpp2_write(port->priv, MVPP2_TXP_SCHED_PORT_INDEX_REG, tx_port_num); in mvpp2_txq_init()
3141 val = mvpp2_read(port->priv, MVPP2_TXQ_SCHED_REFILL_REG(txq->log_id)); in mvpp2_txq_init()
3145 mvpp2_write(port->priv, MVPP2_TXQ_SCHED_REFILL_REG(txq->log_id), val); in mvpp2_txq_init()
3148 mvpp2_write(port->priv, MVPP2_TXQ_SCHED_TOKEN_SIZE_REG(txq->log_id), in mvpp2_txq_init()
3151 for (thread = 0; thread < port->priv->nthreads; thread++) { in mvpp2_txq_init()
3152 txq_pcpu = per_cpu_ptr(txq->pcpu, thread); in mvpp2_txq_init()
3153 txq_pcpu->size = txq->size; in mvpp2_txq_init()
3154 txq_pcpu->buffs = kmalloc_array(txq_pcpu->size, in mvpp2_txq_init()
3155 sizeof(*txq_pcpu->buffs), in mvpp2_txq_init()
3157 if (!txq_pcpu->buffs) in mvpp2_txq_init()
3158 return -ENOMEM; in mvpp2_txq_init()
3160 txq_pcpu->count = 0; in mvpp2_txq_init()
3161 txq_pcpu->reserved_num = 0; in mvpp2_txq_init()
3162 txq_pcpu->txq_put_index = 0; in mvpp2_txq_init()
3163 txq_pcpu->txq_get_index = 0; in mvpp2_txq_init()
3164 txq_pcpu->tso_headers = NULL; in mvpp2_txq_init()
3166 txq_pcpu->stop_threshold = txq->size - MVPP2_MAX_SKB_DESCS; in mvpp2_txq_init()
3167 txq_pcpu->wake_threshold = txq_pcpu->stop_threshold / 2; in mvpp2_txq_init()
3169 txq_pcpu->tso_headers = in mvpp2_txq_init()
3170 dma_alloc_coherent(port->dev->dev.parent, in mvpp2_txq_init()
3171 txq_pcpu->size * TSO_HEADER_SIZE, in mvpp2_txq_init()
3172 &txq_pcpu->tso_headers_dma, in mvpp2_txq_init()
3174 if (!txq_pcpu->tso_headers) in mvpp2_txq_init()
3175 return -ENOMEM; in mvpp2_txq_init()
3188 for (thread = 0; thread < port->priv->nthreads; thread++) { in mvpp2_txq_deinit()
3189 txq_pcpu = per_cpu_ptr(txq->pcpu, thread); in mvpp2_txq_deinit()
3190 kfree(txq_pcpu->buffs); in mvpp2_txq_deinit()
3192 if (txq_pcpu->tso_headers) in mvpp2_txq_deinit()
3193 dma_free_coherent(port->dev->dev.parent, in mvpp2_txq_deinit()
3194 txq_pcpu->size * TSO_HEADER_SIZE, in mvpp2_txq_deinit()
3195 txq_pcpu->tso_headers, in mvpp2_txq_deinit()
3196 txq_pcpu->tso_headers_dma); in mvpp2_txq_deinit()
3198 txq_pcpu->tso_headers = NULL; in mvpp2_txq_deinit()
3201 if (txq->descs) in mvpp2_txq_deinit()
3202 dma_free_coherent(port->dev->dev.parent, in mvpp2_txq_deinit()
3203 txq->size * MVPP2_DESC_ALIGNED_SIZE, in mvpp2_txq_deinit()
3204 txq->descs, txq->descs_dma); in mvpp2_txq_deinit()
3206 txq->descs = NULL; in mvpp2_txq_deinit()
3207 txq->last_desc = 0; in mvpp2_txq_deinit()
3208 txq->next_desc_to_proc = 0; in mvpp2_txq_deinit()
3209 txq->descs_dma = 0; in mvpp2_txq_deinit()
3212 mvpp2_write(port->priv, MVPP2_TXQ_SCHED_TOKEN_CNTR_REG(txq->log_id), 0); in mvpp2_txq_deinit()
3215 thread = mvpp2_cpu_to_thread(port->priv, get_cpu()); in mvpp2_txq_deinit()
3216 mvpp2_thread_write(port->priv, thread, MVPP2_TXQ_NUM_REG, txq->id); in mvpp2_txq_deinit()
3217 mvpp2_thread_write(port->priv, thread, MVPP2_TXQ_DESC_ADDR_REG, 0); in mvpp2_txq_deinit()
3218 mvpp2_thread_write(port->priv, thread, MVPP2_TXQ_DESC_SIZE_REG, 0); in mvpp2_txq_deinit()
3227 unsigned int thread = mvpp2_cpu_to_thread(port->priv, get_cpu()); in mvpp2_txq_clean()
3230 mvpp2_thread_write(port->priv, thread, MVPP2_TXQ_NUM_REG, txq->id); in mvpp2_txq_clean()
3231 val = mvpp2_thread_read(port->priv, thread, MVPP2_TXQ_PREF_BUF_REG); in mvpp2_txq_clean()
3233 mvpp2_thread_write(port->priv, thread, MVPP2_TXQ_PREF_BUF_REG, val); in mvpp2_txq_clean()
3241 netdev_warn(port->dev, in mvpp2_txq_clean()
3243 port->id, txq->log_id); in mvpp2_txq_clean()
3249 pending = mvpp2_thread_read(port->priv, thread, in mvpp2_txq_clean()
3255 mvpp2_thread_write(port->priv, thread, MVPP2_TXQ_PREF_BUF_REG, val); in mvpp2_txq_clean()
3258 for (thread = 0; thread < port->priv->nthreads; thread++) { in mvpp2_txq_clean()
3259 txq_pcpu = per_cpu_ptr(txq->pcpu, thread); in mvpp2_txq_clean()
3262 mvpp2_txq_bufs_free(port, txq, txq_pcpu, txq_pcpu->count); in mvpp2_txq_clean()
3265 txq_pcpu->count = 0; in mvpp2_txq_clean()
3266 txq_pcpu->txq_put_index = 0; in mvpp2_txq_clean()
3267 txq_pcpu->txq_get_index = 0; in mvpp2_txq_clean()
3278 val = mvpp2_read(port->priv, MVPP2_TX_PORT_FLUSH_REG); in mvpp2_cleanup_txqs()
3281 val |= MVPP2_TX_PORT_FLUSH_MASK(port->id); in mvpp2_cleanup_txqs()
3282 mvpp2_write(port->priv, MVPP2_TX_PORT_FLUSH_REG, val); in mvpp2_cleanup_txqs()
3284 for (queue = 0; queue < port->ntxqs; queue++) { in mvpp2_cleanup_txqs()
3285 txq = port->txqs[queue]; in mvpp2_cleanup_txqs()
3292 val &= ~MVPP2_TX_PORT_FLUSH_MASK(port->id); in mvpp2_cleanup_txqs()
3293 mvpp2_write(port->priv, MVPP2_TX_PORT_FLUSH_REG, val); in mvpp2_cleanup_txqs()
3301 for (queue = 0; queue < port->nrxqs; queue++) in mvpp2_cleanup_rxqs()
3302 mvpp2_rxq_deinit(port, port->rxqs[queue]); in mvpp2_cleanup_rxqs()
3304 if (port->tx_fc) in mvpp2_cleanup_rxqs()
3313 for (queue = 0; queue < port->nrxqs; queue++) { in mvpp2_setup_rxqs()
3314 err = mvpp2_rxq_init(port, port->rxqs[queue]); in mvpp2_setup_rxqs()
3319 if (port->tx_fc) in mvpp2_setup_rxqs()
3335 for (queue = 0; queue < port->ntxqs; queue++) { in mvpp2_setup_txqs()
3336 txq = port->txqs[queue]; in mvpp2_setup_txqs()
3343 netif_set_xps_queue(port->dev, cpumask_of(queue), queue); in mvpp2_setup_txqs()
3346 if (port->has_tx_irqs) { in mvpp2_setup_txqs()
3348 for (queue = 0; queue < port->ntxqs; queue++) { in mvpp2_setup_txqs()
3349 txq = port->txqs[queue]; in mvpp2_setup_txqs()
3362 /* The callback for per-port interrupt */
3369 napi_schedule(&qv->napi); in mvpp2_isr()
3383 ptp_q = port->priv->iface_base + MVPP22_PTP_BASE(port->gop_id); in mvpp2_isr_handle_ptp_queue()
3385 ptp_q += MVPP22_PTP_TX_Q1_R0 - MVPP22_PTP_TX_Q0_R0; in mvpp2_isr_handle_ptp_queue()
3387 queue = &port->tx_hwtstamp_queue[nq]; in mvpp2_isr_handle_ptp_queue()
3399 skb = queue->skb[id]; in mvpp2_isr_handle_ptp_queue()
3400 queue->skb[id] = NULL; in mvpp2_isr_handle_ptp_queue()
3404 mvpp22_tai_tstamp(port->priv->tai, ts, &shhwtstamps); in mvpp2_isr_handle_ptp_queue()
3416 ptp = port->priv->iface_base + MVPP22_PTP_BASE(port->gop_id); in mvpp2_isr_handle_ptp()
3427 struct net_device *dev = port->dev; in mvpp2_isr_handle_link()
3429 if (port->phylink) { in mvpp2_isr_handle_link()
3459 val = readl(port->base + MVPP22_XLG_INT_STAT); in mvpp2_isr_handle_xlg()
3461 val = readl(port->base + MVPP22_XLG_STATUS); in mvpp2_isr_handle_xlg()
3463 mvpp2_isr_handle_link(port, &port->pcs_xlg, link); in mvpp2_isr_handle_xlg()
3472 if (phy_interface_mode_is_rgmii(port->phy_interface) || in mvpp2_isr_handle_gmac_internal()
3473 phy_interface_mode_is_8023z(port->phy_interface) || in mvpp2_isr_handle_gmac_internal()
3474 port->phy_interface == PHY_INTERFACE_MODE_SGMII) { in mvpp2_isr_handle_gmac_internal()
3475 val = readl(port->base + MVPP22_GMAC_INT_STAT); in mvpp2_isr_handle_gmac_internal()
3477 val = readl(port->base + MVPP2_GMAC_STATUS0); in mvpp2_isr_handle_gmac_internal()
3479 mvpp2_isr_handle_link(port, &port->pcs_gmac, link); in mvpp2_isr_handle_gmac_internal()
3484 /* Per-port interrupt for link status changes */
3493 mvpp2_is_xlg(port->phy_interface)) { in mvpp2_port_isr()
3495 val = readl(port->base + MVPP22_XLG_EXT_INT_STAT); in mvpp2_port_isr()
3504 val = readl(port->base + MVPP22_GMAC_INT_SUM_STAT); in mvpp2_port_isr()
3523 dev = port_pcpu->dev; in mvpp2_hr_timer_cb()
3528 port_pcpu->timer_scheduled = false; in mvpp2_hr_timer_cb()
3532 cause = (1 << port->ntxqs) - 1; in mvpp2_hr_timer_cb()
3534 mvpp2_cpu_to_thread(port->priv, smp_processor_id())); in mvpp2_hr_timer_cb()
3537 if (tx_todo && !port_pcpu->timer_scheduled) { in mvpp2_hr_timer_cb()
3538 port_pcpu->timer_scheduled = true; in mvpp2_hr_timer_cb()
3539 hrtimer_forward_now(&port_pcpu->tx_done_timer, in mvpp2_hr_timer_cb()
3569 netdev_err(port->dev, in mvpp2_rx_error()
3570 "bad rx status %08x (%s error), size=%zu\n", in mvpp2_rx_error()
3600 return -ENOMEM; in mvpp2_rx_refill()
3610 if (skb->ip_summed == CHECKSUM_PARTIAL) { in mvpp2_skb_tx_csum()
3619 ip_hdr_len = ip4h->ihl; in mvpp2_skb_tx_csum()
3620 l4_proto = ip4h->protocol; in mvpp2_skb_tx_csum()
3627 l4_proto = ip6h->nexthdr; in mvpp2_skb_tx_csum()
3641 unsigned int thread = mvpp2_cpu_to_thread(port->priv, smp_processor_id()); in mvpp2_xdp_finish_tx()
3647 txq = port->txqs[txq_id]; in mvpp2_xdp_finish_tx()
3648 txq_pcpu = per_cpu_ptr(txq->pcpu, thread); in mvpp2_xdp_finish_tx()
3649 nq = netdev_get_tx_queue(port->dev, txq_id); in mvpp2_xdp_finish_tx()
3650 aggr_txq = &port->priv->aggr_txqs[thread]; in mvpp2_xdp_finish_tx()
3652 txq_pcpu->reserved_num -= nxmit; in mvpp2_xdp_finish_tx()
3653 txq_pcpu->count += nxmit; in mvpp2_xdp_finish_tx()
3654 aggr_txq->count += nxmit; in mvpp2_xdp_finish_tx()
3660 if (txq_pcpu->count >= txq_pcpu->stop_threshold) in mvpp2_xdp_finish_tx()
3664 if (!port->has_tx_irqs && txq_pcpu->count >= txq->done_pkts_coal) in mvpp2_xdp_finish_tx()
3672 unsigned int thread = mvpp2_cpu_to_thread(port->priv, smp_processor_id()); in mvpp2_xdp_submit_frame()
3683 txq = port->txqs[txq_id]; in mvpp2_xdp_submit_frame()
3684 txq_pcpu = per_cpu_ptr(txq->pcpu, thread); in mvpp2_xdp_submit_frame()
3685 aggr_txq = &port->priv->aggr_txqs[thread]; in mvpp2_xdp_submit_frame()
3696 mvpp2_txdesc_txq_set(port, tx_desc, txq->id); in mvpp2_xdp_submit_frame()
3697 mvpp2_txdesc_size_set(port, tx_desc, xdpf->len); in mvpp2_xdp_submit_frame()
3701 dma_addr = dma_map_single(port->dev->dev.parent, xdpf->data, in mvpp2_xdp_submit_frame()
3702 xdpf->len, DMA_TO_DEVICE); in mvpp2_xdp_submit_frame()
3704 if (unlikely(dma_mapping_error(port->dev->dev.parent, dma_addr))) { in mvpp2_xdp_submit_frame()
3713 struct page *page = virt_to_page(xdpf->data); in mvpp2_xdp_submit_frame()
3716 sizeof(*xdpf) + xdpf->headroom; in mvpp2_xdp_submit_frame()
3717 dma_sync_single_for_device(port->dev->dev.parent, dma_addr, in mvpp2_xdp_submit_frame()
3718 xdpf->len, DMA_BIDIRECTIONAL); in mvpp2_xdp_submit_frame()
3735 struct mvpp2_pcpu_stats *stats = this_cpu_ptr(port->stats); in mvpp2_xdp_xmit_back()
3747 txq_id = mvpp2_cpu_to_thread(port->priv, smp_processor_id()) + (port->ntxqs / 2); in mvpp2_xdp_xmit_back()
3751 u64_stats_update_begin(&stats->syncp); in mvpp2_xdp_xmit_back()
3752 stats->tx_bytes += xdpf->len; in mvpp2_xdp_xmit_back()
3753 stats->tx_packets++; in mvpp2_xdp_xmit_back()
3754 stats->xdp_tx++; in mvpp2_xdp_xmit_back()
3755 u64_stats_update_end(&stats->syncp); in mvpp2_xdp_xmit_back()
3757 mvpp2_xdp_finish_tx(port, txq_id, 1, xdpf->len); in mvpp2_xdp_xmit_back()
3759 u64_stats_update_begin(&stats->syncp); in mvpp2_xdp_xmit_back()
3760 stats->xdp_tx_err++; in mvpp2_xdp_xmit_back()
3761 u64_stats_update_end(&stats->syncp); in mvpp2_xdp_xmit_back()
3777 if (unlikely(test_bit(0, &port->state))) in mvpp2_xdp_xmit()
3778 return -ENETDOWN; in mvpp2_xdp_xmit()
3781 return -EINVAL; in mvpp2_xdp_xmit()
3786 txq_id = mvpp2_cpu_to_thread(port->priv, smp_processor_id()) + (port->ntxqs / 2); in mvpp2_xdp_xmit()
3793 nxmit_byte += frames[i]->len; in mvpp2_xdp_xmit()
3800 stats = this_cpu_ptr(port->stats); in mvpp2_xdp_xmit()
3801 u64_stats_update_begin(&stats->syncp); in mvpp2_xdp_xmit()
3802 stats->tx_bytes += nxmit_byte; in mvpp2_xdp_xmit()
3803 stats->tx_packets += nxmit; in mvpp2_xdp_xmit()
3804 stats->xdp_xmit += nxmit; in mvpp2_xdp_xmit()
3805 stats->xdp_xmit_err += num_frame - nxmit; in mvpp2_xdp_xmit()
3806 u64_stats_update_end(&stats->syncp); in mvpp2_xdp_xmit()
3820 len = xdp->data_end - xdp->data_hard_start - MVPP2_SKB_HEADROOM; in mvpp2_run_xdp()
3824 sync = xdp->data_end - xdp->data_hard_start - MVPP2_SKB_HEADROOM; in mvpp2_run_xdp()
3829 stats->xdp_pass++; in mvpp2_run_xdp()
3833 err = xdp_do_redirect(port->dev, xdp, prog); in mvpp2_run_xdp()
3836 page = virt_to_head_page(xdp->data); in mvpp2_run_xdp()
3840 stats->xdp_redirect++; in mvpp2_run_xdp()
3846 page = virt_to_head_page(xdp->data); in mvpp2_run_xdp()
3851 bpf_warn_invalid_xdp_action(port->dev, prog, act); in mvpp2_run_xdp()
3854 trace_xdp_exception(port->dev, prog, act); in mvpp2_run_xdp()
3857 page = virt_to_head_page(xdp->data); in mvpp2_run_xdp()
3860 stats->xdp_drop++; in mvpp2_run_xdp()
3880 phys_addr_next = le32_to_cpu(buff_hdr->next_phys_addr); in mvpp2_buff_hdr_pool_put()
3881 dma_addr_next = le32_to_cpu(buff_hdr->next_dma_addr); in mvpp2_buff_hdr_pool_put()
3883 if (port->priv->hw_version >= MVPP22) { in mvpp2_buff_hdr_pool_put()
3884 phys_addr_next |= ((u64)buff_hdr->next_phys_addr_high << 32); in mvpp2_buff_hdr_pool_put()
3885 dma_addr_next |= ((u64)buff_hdr->next_dma_addr_high << 32); in mvpp2_buff_hdr_pool_put()
3893 } while (!MVPP2_B_HDR_INFO_IS_LAST(le16_to_cpu(buff_hdr->info))); in mvpp2_buff_hdr_pool_put()
3900 struct net_device *dev = port->dev; in mvpp2_rx()
3909 xdp_prog = READ_ONCE(port->xdp_prog); in mvpp2_rx()
3911 /* Get number of received packets and clamp the to-do */ in mvpp2_rx()
3912 rx_received = mvpp2_rxq_received(port, rxq->id); in mvpp2_rx()
3937 rx_bytes -= MVPP2_MH_SIZE; in mvpp2_rx()
3942 bm_pool = &port->priv->bm_pools[pool]; in mvpp2_rx()
3944 if (port->priv->percpu_pools) { in mvpp2_rx()
3945 pp = port->priv->page_pool[pool]; in mvpp2_rx()
3951 dma_sync_single_for_cpu(dev->dev.parent, dma_addr, in mvpp2_rx()
3970 if (bm_pool->frag_size > PAGE_SIZE) in mvpp2_rx()
3973 frag_size = bm_pool->frag_size; in mvpp2_rx()
3978 if (bm_pool->pkt_size == MVPP2_BM_SHORT_PKT_SIZE) in mvpp2_rx()
3979 xdp_rxq = &rxq->xdp_rxq_short; in mvpp2_rx()
3981 xdp_rxq = &rxq->xdp_rxq_long; in mvpp2_rx()
3994 netdev_err(port->dev, "failed to refill BM pools\n"); in mvpp2_rx()
4009 netdev_warn(port->dev, "skb build failed\n"); in mvpp2_rx()
4017 timestamp = le32_to_cpu(rx_desc->pp22.timestamp); in mvpp2_rx()
4018 mvpp22_tai_tstamp(port->priv->tai, timestamp, in mvpp2_rx()
4024 netdev_err(port->dev, "failed to refill BM pools\n"); in mvpp2_rx()
4032 dma_unmap_single_attrs(dev->dev.parent, dma_addr, in mvpp2_rx()
4033 bm_pool->buf_size, DMA_FROM_DEVICE, in mvpp2_rx()
4041 skb->ip_summed = mvpp2_rx_csum(port, rx_status); in mvpp2_rx()
4042 skb->protocol = eth_type_trans(skb, dev); in mvpp2_rx()
4048 dev->stats.rx_errors++; in mvpp2_rx()
4061 struct mvpp2_pcpu_stats *stats = this_cpu_ptr(port->stats); in mvpp2_rx()
4063 u64_stats_update_begin(&stats->syncp); in mvpp2_rx()
4064 stats->rx_packets += ps.rx_packets; in mvpp2_rx()
4065 stats->rx_bytes += ps.rx_bytes; in mvpp2_rx()
4067 stats->xdp_redirect += ps.xdp_redirect; in mvpp2_rx()
4068 stats->xdp_pass += ps.xdp_pass; in mvpp2_rx()
4069 stats->xdp_drop += ps.xdp_drop; in mvpp2_rx()
4070 u64_stats_update_end(&stats->syncp); in mvpp2_rx()
4075 mvpp2_rxq_status_update(port, rxq->id, rx_done, rx_done); in mvpp2_rx()
4084 unsigned int thread = mvpp2_cpu_to_thread(port->priv, smp_processor_id()); in tx_desc_unmap_put()
4085 struct mvpp2_txq_pcpu *txq_pcpu = per_cpu_ptr(txq->pcpu, thread); in tx_desc_unmap_put()
4092 dma_unmap_single(port->dev->dev.parent, buf_dma_addr, in tx_desc_unmap_put()
4101 if (port->priv->hw_version >= MVPP22) in mvpp2_txdesc_clear_ptp()
4102 desc->pp22.ptp_descriptor &= in mvpp2_txdesc_clear_ptp()
4115 if (port->priv->hw_version == MVPP21 || in mvpp2_tx_hw_tstamp()
4116 port->tx_hwtstamp_type == HWTSTAMP_TX_OFF) in mvpp2_tx_hw_tstamp()
4127 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS; in mvpp2_tx_hw_tstamp()
4131 queue = &port->tx_hwtstamp_queue[0]; in mvpp2_tx_hw_tstamp()
4140 mtype = hdr->tsmt & 15; in mvpp2_tx_hw_tstamp()
4144 queue = &port->tx_hwtstamp_queue[1]; in mvpp2_tx_hw_tstamp()
4150 i = queue->next; in mvpp2_tx_hw_tstamp()
4151 queue->next = (i + 1) & 31; in mvpp2_tx_hw_tstamp()
4152 if (queue->skb[i]) in mvpp2_tx_hw_tstamp()
4153 dev_kfree_skb_any(queue->skb[i]); in mvpp2_tx_hw_tstamp()
4154 queue->skb[i] = skb_get(skb); in mvpp2_tx_hw_tstamp()
4159 * 3:0 - PTPAction in mvpp2_tx_hw_tstamp()
4160 * 6:4 - PTPPacketFormat in mvpp2_tx_hw_tstamp()
4161 * 7 - PTP_CF_WraparoundCheckEn in mvpp2_tx_hw_tstamp()
4162 * 9:8 - IngressTimestampSeconds[1:0] in mvpp2_tx_hw_tstamp()
4163 * 10 - Reserved in mvpp2_tx_hw_tstamp()
4164 * 11 - MACTimestampingEn in mvpp2_tx_hw_tstamp()
4165 * 17:12 - PTP_TimestampQueueEntryID[5:0] in mvpp2_tx_hw_tstamp()
4166 * 18 - PTPTimestampQueueSelect in mvpp2_tx_hw_tstamp()
4167 * 19 - UDPChecksumUpdateEn in mvpp2_tx_hw_tstamp()
4168 * 27:20 - TimestampOffset in mvpp2_tx_hw_tstamp()
4169 * PTP, NTPTransmit, OWAMP/TWAMP - L3 to PTP header in mvpp2_tx_hw_tstamp()
4170 * NTPTs, Y.1731 - L3 to timestamp entry in mvpp2_tx_hw_tstamp()
4171 * 35:28 - UDP Checksum Offset in mvpp2_tx_hw_tstamp()
4175 tx_desc->pp22.ptp_descriptor &= in mvpp2_tx_hw_tstamp()
4177 tx_desc->pp22.ptp_descriptor |= in mvpp2_tx_hw_tstamp()
4179 tx_desc->pp22.buf_dma_addr_ptp &= cpu_to_le64(~0xffffff0000000000ULL); in mvpp2_tx_hw_tstamp()
4180 tx_desc->pp22.buf_dma_addr_ptp |= cpu_to_le64((ptpdesc >> 12) << 40); in mvpp2_tx_hw_tstamp()
4190 unsigned int thread = mvpp2_cpu_to_thread(port->priv, smp_processor_id()); in mvpp2_tx_frag_process()
4191 struct mvpp2_txq_pcpu *txq_pcpu = per_cpu_ptr(txq->pcpu, thread); in mvpp2_tx_frag_process()
4196 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { in mvpp2_tx_frag_process()
4197 skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; in mvpp2_tx_frag_process()
4202 mvpp2_txdesc_txq_set(port, tx_desc, txq->id); in mvpp2_tx_frag_process()
4205 buf_dma_addr = dma_map_single(port->dev->dev.parent, addr, in mvpp2_tx_frag_process()
4208 if (dma_mapping_error(port->dev->dev.parent, buf_dma_addr)) { in mvpp2_tx_frag_process()
4215 if (i == (skb_shinfo(skb)->nr_frags - 1)) { in mvpp2_tx_frag_process()
4232 for (i = i - 1; i >= 0; i--) { in mvpp2_tx_frag_process()
4233 tx_desc = txq->descs + i; in mvpp2_tx_frag_process()
4237 return -ENOMEM; in mvpp2_tx_frag_process()
4252 mvpp2_txdesc_txq_set(port, tx_desc, txq->id); in mvpp2_tso_put_hdr()
4255 addr = txq_pcpu->tso_headers_dma + in mvpp2_tso_put_hdr()
4256 txq_pcpu->txq_put_index * TSO_HEADER_SIZE; in mvpp2_tso_put_hdr()
4277 mvpp2_txdesc_txq_set(port, tx_desc, txq->id); in mvpp2_tso_put_data()
4280 buf_dma_addr = dma_map_single(dev->dev.parent, tso->data, sz, in mvpp2_tso_put_data()
4282 if (unlikely(dma_mapping_error(dev->dev.parent, buf_dma_addr))) { in mvpp2_tso_put_data()
4284 return -ENOMEM; in mvpp2_tso_put_data()
4320 len = skb->len - hdr_sz; in mvpp2_tx_tso()
4322 int left = min_t(int, skb_shinfo(skb)->gso_size, len); in mvpp2_tx_tso()
4323 char *hdr = txq_pcpu->tso_headers + in mvpp2_tx_tso()
4324 txq_pcpu->txq_put_index * TSO_HEADER_SIZE; in mvpp2_tx_tso()
4326 len -= left; in mvpp2_tx_tso()
4334 left -= sz; in mvpp2_tx_tso()
4347 for (i = descs - 1; i >= 0; i--) { in mvpp2_tx_tso()
4348 struct mvpp2_tx_desc *tx_desc = txq->descs + i; in mvpp2_tx_tso()
4368 thread = mvpp2_cpu_to_thread(port->priv, smp_processor_id()); in mvpp2_tx()
4371 txq = port->txqs[txq_id]; in mvpp2_tx()
4372 txq_pcpu = per_cpu_ptr(txq->pcpu, thread); in mvpp2_tx()
4373 aggr_txq = &port->priv->aggr_txqs[thread]; in mvpp2_tx()
4375 if (test_bit(thread, &port->priv->lock_map)) in mvpp2_tx()
4376 spin_lock_irqsave(&port->tx_lock[thread], flags); in mvpp2_tx()
4382 frags = skb_shinfo(skb)->nr_frags + 1; in mvpp2_tx()
4393 if (!(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) || in mvpp2_tx()
4396 mvpp2_txdesc_txq_set(port, tx_desc, txq->id); in mvpp2_tx()
4399 buf_dma_addr = dma_map_single(dev->dev.parent, skb->data, in mvpp2_tx()
4401 if (unlikely(dma_mapping_error(dev->dev.parent, buf_dma_addr))) { in mvpp2_tx()
4431 struct mvpp2_pcpu_stats *stats = per_cpu_ptr(port->stats, thread); in mvpp2_tx()
4434 txq_pcpu->reserved_num -= frags; in mvpp2_tx()
4435 txq_pcpu->count += frags; in mvpp2_tx()
4436 aggr_txq->count += frags; in mvpp2_tx()
4442 if (txq_pcpu->count >= txq_pcpu->stop_threshold) in mvpp2_tx()
4445 u64_stats_update_begin(&stats->syncp); in mvpp2_tx()
4446 stats->tx_packets++; in mvpp2_tx()
4447 stats->tx_bytes += skb->len; in mvpp2_tx()
4448 u64_stats_update_end(&stats->syncp); in mvpp2_tx()
4450 dev->stats.tx_dropped++; in mvpp2_tx()
4455 if (!port->has_tx_irqs && txq_pcpu->count >= txq->done_pkts_coal) in mvpp2_tx()
4459 if (!port->has_tx_irqs && txq_pcpu->count <= frags && in mvpp2_tx()
4460 txq_pcpu->count > 0) { in mvpp2_tx()
4461 struct mvpp2_port_pcpu *port_pcpu = per_cpu_ptr(port->pcpu, thread); in mvpp2_tx()
4463 if (!port_pcpu->timer_scheduled) { in mvpp2_tx()
4464 port_pcpu->timer_scheduled = true; in mvpp2_tx()
4465 hrtimer_start(&port_pcpu->tx_done_timer, in mvpp2_tx()
4471 if (test_bit(thread, &port->priv->lock_map)) in mvpp2_tx()
4472 spin_unlock_irqrestore(&port->tx_lock[thread], flags); in mvpp2_tx()
4491 struct mvpp2_port *port = netdev_priv(napi->dev); in mvpp2_poll()
4493 unsigned int thread = mvpp2_cpu_to_thread(port->priv, smp_processor_id()); in mvpp2_poll()
4499 * Bits 0-15: each bit indicates received packets on the Rx queue in mvpp2_poll()
4502 * Bits 16-23: each bit indicates transmitted packets on the Tx queue in mvpp2_poll()
4507 cause_rx_tx = mvpp2_thread_read_relaxed(port->priv, qv->sw_thread_id, in mvpp2_poll()
4508 MVPP2_ISR_RX_TX_CAUSE_REG(port->id)); in mvpp2_poll()
4512 mvpp2_cause_error(port->dev, cause_misc); in mvpp2_poll()
4515 mvpp2_write(port->priv, MVPP2_ISR_MISC_CAUSE_REG, 0); in mvpp2_poll()
4516 mvpp2_thread_write(port->priv, thread, in mvpp2_poll()
4517 MVPP2_ISR_RX_TX_CAUSE_REG(port->id), in mvpp2_poll()
4521 if (port->has_tx_irqs) { in mvpp2_poll()
4525 mvpp2_tx_done(port, cause_tx, qv->sw_thread_id); in mvpp2_poll()
4531 MVPP2_CAUSE_RXQ_OCCUP_DESC_ALL_MASK(port->priv->hw_version); in mvpp2_poll()
4532 cause_rx <<= qv->first_rxq; in mvpp2_poll()
4533 cause_rx |= qv->pending_cause_rx; in mvpp2_poll()
4544 budget -= count; in mvpp2_poll()
4550 cause_rx &= ~(1 << rxq->logic_rxq); in mvpp2_poll()
4560 qv->pending_cause_rx = cause_rx; in mvpp2_poll()
4584 ctrl3 = readl(port->base + MVPP22_XLG_CTRL3_REG); in mvpp22_mode_reconfigure()
4592 writel(ctrl3, port->base + MVPP22_XLG_CTRL3_REG); in mvpp22_mode_reconfigure()
4608 for (i = 0; i < port->nqvecs; i++) in mvpp2_start_dev()
4609 napi_enable(&port->qvecs[i].napi); in mvpp2_start_dev()
4614 if (port->priv->hw_version >= MVPP22) in mvpp2_start_dev()
4615 mvpp22_mode_reconfigure(port, port->phy_interface); in mvpp2_start_dev()
4617 if (port->phylink) { in mvpp2_start_dev()
4618 phylink_start(port->phylink); in mvpp2_start_dev()
4623 netif_tx_start_all_queues(port->dev); in mvpp2_start_dev()
4625 clear_bit(0, &port->state); in mvpp2_start_dev()
4633 set_bit(0, &port->state); in mvpp2_stop_dev()
4638 for (i = 0; i < port->nqvecs; i++) in mvpp2_stop_dev()
4639 napi_disable(&port->qvecs[i].napi); in mvpp2_stop_dev()
4641 if (port->phylink) in mvpp2_stop_dev()
4642 phylink_stop(port->phylink); in mvpp2_stop_dev()
4643 phy_power_off(port->comphy); in mvpp2_stop_dev()
4649 u16 new_rx_pending = ring->rx_pending; in mvpp2_check_ringparam_valid()
4650 u16 new_tx_pending = ring->tx_pending; in mvpp2_check_ringparam_valid()
4652 if (ring->rx_pending == 0 || ring->tx_pending == 0) in mvpp2_check_ringparam_valid()
4653 return -EINVAL; in mvpp2_check_ringparam_valid()
4655 if (ring->rx_pending > MVPP2_MAX_RXD_MAX) in mvpp2_check_ringparam_valid()
4657 else if (ring->rx_pending < MSS_THRESHOLD_START) in mvpp2_check_ringparam_valid()
4659 else if (!IS_ALIGNED(ring->rx_pending, 16)) in mvpp2_check_ringparam_valid()
4660 new_rx_pending = ALIGN(ring->rx_pending, 16); in mvpp2_check_ringparam_valid()
4662 if (ring->tx_pending > MVPP2_MAX_TXD_MAX) in mvpp2_check_ringparam_valid()
4664 else if (!IS_ALIGNED(ring->tx_pending, 32)) in mvpp2_check_ringparam_valid()
4665 new_tx_pending = ALIGN(ring->tx_pending, 32); in mvpp2_check_ringparam_valid()
4673 if (ring->rx_pending != new_rx_pending) { in mvpp2_check_ringparam_valid()
4675 ring->rx_pending, new_rx_pending); in mvpp2_check_ringparam_valid()
4676 ring->rx_pending = new_rx_pending; in mvpp2_check_ringparam_valid()
4679 if (ring->tx_pending != new_tx_pending) { in mvpp2_check_ringparam_valid()
4681 ring->tx_pending, new_tx_pending); in mvpp2_check_ringparam_valid()
4682 ring->tx_pending = new_tx_pending; in mvpp2_check_ringparam_valid()
4692 mac_addr_l = readl(port->base + MVPP2_GMAC_CTRL_1_REG); in mvpp21_get_mac_address()
4693 mac_addr_m = readl(port->priv->lms_base + MVPP2_SRC_ADDR_MIDDLE); in mvpp21_get_mac_address()
4694 mac_addr_h = readl(port->priv->lms_base + MVPP2_SRC_ADDR_HIGH); in mvpp21_get_mac_address()
4700 addr[5] = (mac_addr_l >> MVPP2_GMAC_SA_LOW_OFFS) & 0xFF; in mvpp21_get_mac_address()
4707 for (i = 0; i < port->nqvecs; i++) { in mvpp2_irqs_init()
4708 struct mvpp2_queue_vector *qv = port->qvecs + i; in mvpp2_irqs_init()
4710 if (qv->type == MVPP2_QUEUE_VECTOR_PRIVATE) { in mvpp2_irqs_init()
4711 qv->mask = kzalloc(cpumask_size(), GFP_KERNEL); in mvpp2_irqs_init()
4712 if (!qv->mask) { in mvpp2_irqs_init()
4713 err = -ENOMEM; in mvpp2_irqs_init()
4717 irq_set_status_flags(qv->irq, IRQ_NO_BALANCING); in mvpp2_irqs_init()
4720 err = request_irq(qv->irq, mvpp2_isr, 0, port->dev->name, qv); in mvpp2_irqs_init()
4724 if (qv->type == MVPP2_QUEUE_VECTOR_PRIVATE) { in mvpp2_irqs_init()
4728 if (mvpp2_cpu_to_thread(port->priv, cpu) == in mvpp2_irqs_init()
4729 qv->sw_thread_id) in mvpp2_irqs_init()
4730 cpumask_set_cpu(cpu, qv->mask); in mvpp2_irqs_init()
4733 irq_set_affinity_hint(qv->irq, qv->mask); in mvpp2_irqs_init()
4739 for (i = 0; i < port->nqvecs; i++) { in mvpp2_irqs_init()
4740 struct mvpp2_queue_vector *qv = port->qvecs + i; in mvpp2_irqs_init()
4742 irq_set_affinity_hint(qv->irq, NULL); in mvpp2_irqs_init()
4743 kfree(qv->mask); in mvpp2_irqs_init()
4744 qv->mask = NULL; in mvpp2_irqs_init()
4745 free_irq(qv->irq, qv); in mvpp2_irqs_init()
4755 for (i = 0; i < port->nqvecs; i++) { in mvpp2_irqs_deinit()
4756 struct mvpp2_queue_vector *qv = port->qvecs + i; in mvpp2_irqs_deinit()
4758 irq_set_affinity_hint(qv->irq, NULL); in mvpp2_irqs_deinit()
4759 kfree(qv->mask); in mvpp2_irqs_deinit()
4760 qv->mask = NULL; in mvpp2_irqs_deinit()
4761 irq_clear_status_flags(qv->irq, IRQ_NO_BALANCING); in mvpp2_irqs_deinit()
4762 free_irq(qv->irq, qv); in mvpp2_irqs_deinit()
4769 !(port->flags & MVPP2_F_LOOPBACK); in mvpp22_rss_is_supported()
4775 struct mvpp2 *priv = port->priv; in mvpp2_open()
4786 err = mvpp2_prs_mac_da_accept(port, dev->dev_addr, true); in mvpp2_open()
4791 err = mvpp2_prs_tag_mode_set(port->priv, port->id, MVPP2_TAG_TYPE_MH); in mvpp2_open()
4805 netdev_err(port->dev, "cannot allocate Rx queues\n"); in mvpp2_open()
4811 netdev_err(port->dev, "cannot allocate Tx queues\n"); in mvpp2_open()
4817 netdev_err(port->dev, "cannot init IRQs\n"); in mvpp2_open()
4821 if (port->phylink) { in mvpp2_open()
4822 err = phylink_fwnode_phy_connect(port->phylink, port->fwnode, 0); in mvpp2_open()
4824 netdev_err(port->dev, "could not attach PHY (%d)\n", in mvpp2_open()
4832 if (priv->hw_version >= MVPP22 && port->port_irq) { in mvpp2_open()
4833 err = request_irq(port->port_irq, mvpp2_port_isr, 0, in mvpp2_open()
4834 dev->name, port); in mvpp2_open()
4836 netdev_err(port->dev, in mvpp2_open()
4838 port->port_irq); in mvpp2_open()
4845 netif_carrier_off(port->dev); in mvpp2_open()
4849 port->port_irq = 0; in mvpp2_open()
4853 netdev_err(port->dev, in mvpp2_open()
4855 err = -ENOENT; in mvpp2_open()
4866 queue_delayed_work(priv->stats_queue, &port->stats_work, in mvpp2_open()
4892 if (port->phylink) in mvpp2_stop()
4893 phylink_disconnect_phy(port->phylink); in mvpp2_stop()
4894 if (port->port_irq) in mvpp2_stop()
4895 free_irq(port->port_irq, port); in mvpp2_stop()
4898 if (!port->has_tx_irqs) { in mvpp2_stop()
4899 for (thread = 0; thread < port->priv->nthreads; thread++) { in mvpp2_stop()
4900 port_pcpu = per_cpu_ptr(port->pcpu, thread); in mvpp2_stop()
4902 hrtimer_cancel(&port_pcpu->tx_done_timer); in mvpp2_stop()
4903 port_pcpu->timer_scheduled = false; in mvpp2_stop()
4909 cancel_delayed_work_sync(&port->stats_work); in mvpp2_stop()
4924 ret = mvpp2_prs_mac_da_accept(port, ha->addr, true); in mvpp2_prs_mac_da_accept_list()
4934 if (!enable && (port->dev->features & NETIF_F_HW_VLAN_CTAG_FILTER)) in mvpp2_set_rx_promisc()
4939 mvpp2_prs_mac_promisc_set(port->priv, port->id, in mvpp2_set_rx_promisc()
4942 mvpp2_prs_mac_promisc_set(port->priv, port->id, in mvpp2_set_rx_promisc()
4953 if (dev->flags & IFF_PROMISC) { in mvpp2_set_rx_mode()
4961 mvpp2_prs_mac_da_accept_list(port, &dev->uc)) in mvpp2_set_rx_mode()
4962 mvpp2_prs_mac_promisc_set(port->priv, port->id, in mvpp2_set_rx_mode()
4965 if (dev->flags & IFF_ALLMULTI) { in mvpp2_set_rx_mode()
4966 mvpp2_prs_mac_promisc_set(port->priv, port->id, in mvpp2_set_rx_mode()
4972 mvpp2_prs_mac_da_accept_list(port, &dev->mc)) in mvpp2_set_rx_mode()
4973 mvpp2_prs_mac_promisc_set(port->priv, port->id, in mvpp2_set_rx_mode()
4982 if (!is_valid_ether_addr(addr->sa_data)) in mvpp2_set_mac_address()
4983 return -EADDRNOTAVAIL; in mvpp2_set_mac_address()
4985 err = mvpp2_prs_update_mac_da(dev, addr->sa_data); in mvpp2_set_mac_address()
4988 mvpp2_prs_update_mac_da(dev, dev->dev_addr); in mvpp2_set_mac_address()
4999 bool change_percpu = (percpu != priv->percpu_pools); in mvpp2_bm_switch_buffers()
5004 for (i = 0; i < priv->port_count; i++) { in mvpp2_bm_switch_buffers()
5005 port = priv->port_list[i]; in mvpp2_bm_switch_buffers()
5006 status[i] = netif_running(port->dev); in mvpp2_bm_switch_buffers()
5008 mvpp2_stop(port->dev); in mvpp2_bm_switch_buffers()
5012 if (priv->percpu_pools) in mvpp2_bm_switch_buffers()
5013 numbufs = port->nrxqs * 2; in mvpp2_bm_switch_buffers()
5019 mvpp2_bm_pool_destroy(port->dev->dev.parent, priv, &priv->bm_pools[i]); in mvpp2_bm_switch_buffers()
5021 devm_kfree(port->dev->dev.parent, priv->bm_pools); in mvpp2_bm_switch_buffers()
5022 priv->percpu_pools = percpu; in mvpp2_bm_switch_buffers()
5023 mvpp2_bm_init(port->dev->dev.parent, priv); in mvpp2_bm_switch_buffers()
5025 for (i = 0; i < priv->port_count; i++) { in mvpp2_bm_switch_buffers()
5026 port = priv->port_list[i]; in mvpp2_bm_switch_buffers()
5027 if (percpu && port->ntxqs >= num_possible_cpus() * 2) in mvpp2_bm_switch_buffers()
5028 xdp_set_features_flag(port->dev, in mvpp2_bm_switch_buffers()
5033 xdp_clear_features_flag(port->dev); in mvpp2_bm_switch_buffers()
5037 mvpp2_open(port->dev); in mvpp2_bm_switch_buffers()
5050 struct mvpp2 *priv = port->priv; in mvpp2_change_mtu()
5059 if (port->xdp_prog && mtu > MVPP2_MAX_RX_BUF_SIZE) { in mvpp2_change_mtu()
5062 return -EINVAL; in mvpp2_change_mtu()
5066 if (priv->percpu_pools) { in mvpp2_change_mtu()
5074 for (i = 0; i < priv->port_count; i++) in mvpp2_change_mtu()
5075 if (priv->port_list[i] != port && in mvpp2_change_mtu()
5076 MVPP2_RX_PKT_SIZE(priv->port_list[i]->dev->mtu) > in mvpp2_change_mtu()
5084 dev_info(port->dev->dev.parent, in mvpp2_change_mtu()
5085 "all ports have a low MTU, switching to per-cpu buffers"); in mvpp2_change_mtu()
5097 mvpp2_bm_update_mtu(dev, dev->mtu); in mvpp2_change_mtu()
5099 port->pkt_size = MVPP2_RX_PKT_SIZE(mtu); in mvpp2_change_mtu()
5114 struct mvpp2 *priv = port->priv; in mvpp2_check_pagepool_dma()
5115 int err = -1, i; in mvpp2_check_pagepool_dma()
5117 if (!priv->percpu_pools) in mvpp2_check_pagepool_dma()
5120 if (!priv->page_pool[0]) in mvpp2_check_pagepool_dma()
5121 return -ENOMEM; in mvpp2_check_pagepool_dma()
5123 for (i = 0; i < priv->port_count; i++) { in mvpp2_check_pagepool_dma()
5124 port = priv->port_list[i]; in mvpp2_check_pagepool_dma()
5125 if (port->xdp_prog) { in mvpp2_check_pagepool_dma()
5132 if (priv->page_pool[0]->p.dma_dir != dma_dir) in mvpp2_check_pagepool_dma()
5152 cpu_stats = per_cpu_ptr(port->stats, cpu); in mvpp2_get_stats64()
5154 start = u64_stats_fetch_begin(&cpu_stats->syncp); in mvpp2_get_stats64()
5155 rx_packets = cpu_stats->rx_packets; in mvpp2_get_stats64()
5156 rx_bytes = cpu_stats->rx_bytes; in mvpp2_get_stats64()
5157 tx_packets = cpu_stats->tx_packets; in mvpp2_get_stats64()
5158 tx_bytes = cpu_stats->tx_bytes; in mvpp2_get_stats64()
5159 } while (u64_stats_fetch_retry(&cpu_stats->syncp, start)); in mvpp2_get_stats64()
5161 stats->rx_packets += rx_packets; in mvpp2_get_stats64()
5162 stats->rx_bytes += rx_bytes; in mvpp2_get_stats64()
5163 stats->tx_packets += tx_packets; in mvpp2_get_stats64()
5164 stats->tx_bytes += tx_bytes; in mvpp2_get_stats64()
5167 stats->rx_errors = dev->stats.rx_errors; in mvpp2_get_stats64()
5168 stats->rx_dropped = dev->stats.rx_dropped; in mvpp2_get_stats64()
5169 stats->tx_dropped = dev->stats.tx_dropped; in mvpp2_get_stats64()
5178 if (copy_from_user(&config, ifr->ifr_data, sizeof(config))) in mvpp2_set_ts_config()
5179 return -EFAULT; in mvpp2_set_ts_config()
5183 return -ERANGE; in mvpp2_set_ts_config()
5185 ptp = port->priv->iface_base + MVPP22_PTP_BASE(port->gop_id); in mvpp2_set_ts_config()
5200 mvpp22_tai_start(port->priv->tai); in mvpp2_set_ts_config()
5208 port->rx_hwtstamp = true; in mvpp2_set_ts_config()
5210 port->rx_hwtstamp = false; in mvpp2_set_ts_config()
5222 mvpp22_tai_stop(port->priv->tai); in mvpp2_set_ts_config()
5224 port->tx_hwtstamp_type = config.tx_type; in mvpp2_set_ts_config()
5226 if (copy_to_user(ifr->ifr_data, &config, sizeof(config))) in mvpp2_set_ts_config()
5227 return -EFAULT; in mvpp2_set_ts_config()
5238 config.tx_type = port->tx_hwtstamp_type; in mvpp2_get_ts_config()
5239 config.rx_filter = port->rx_hwtstamp ? in mvpp2_get_ts_config()
5242 if (copy_to_user(ifr->ifr_data, &config, sizeof(config))) in mvpp2_get_ts_config()
5243 return -EFAULT; in mvpp2_get_ts_config()
5253 if (!port->hwtstamp) in mvpp2_ethtool_get_ts_info()
5254 return -EOPNOTSUPP; in mvpp2_ethtool_get_ts_info()
5256 info->phc_index = mvpp22_tai_ptp_clock_index(port->priv->tai); in mvpp2_ethtool_get_ts_info()
5257 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE | in mvpp2_ethtool_get_ts_info()
5261 info->tx_types = BIT(HWTSTAMP_TX_OFF) | in mvpp2_ethtool_get_ts_info()
5263 info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) | in mvpp2_ethtool_get_ts_info()
5275 if (port->hwtstamp) in mvpp2_ioctl()
5280 if (port->hwtstamp) in mvpp2_ioctl()
5285 if (!port->phylink) in mvpp2_ioctl()
5286 return -ENOTSUPP; in mvpp2_ioctl()
5288 return phylink_mii_ioctl(port->phylink, ifr, cmd); in mvpp2_ioctl()
5298 netdev_err(dev, "rx-vlan-filter offloading cannot accept more than %d VIDs per port\n", in mvpp2_vlan_rx_add_vid()
5299 MVPP2_PRS_VLAN_FILT_MAX - 1); in mvpp2_vlan_rx_add_vid()
5314 netdev_features_t changed = dev->features ^ features; in mvpp2_set_features()
5342 struct bpf_prog *prog = bpf->prog, *old_prog; in mvpp2_xdp_setup()
5343 bool running = netif_running(port->dev); in mvpp2_xdp_setup()
5344 bool reset = !prog != !port->xdp_prog; in mvpp2_xdp_setup()
5346 if (port->dev->mtu > MVPP2_MAX_RX_BUF_SIZE) { in mvpp2_xdp_setup()
5347 NL_SET_ERR_MSG_MOD(bpf->extack, "MTU too large for XDP"); in mvpp2_xdp_setup()
5348 return -EOPNOTSUPP; in mvpp2_xdp_setup()
5351 if (!port->priv->percpu_pools) { in mvpp2_xdp_setup()
5352 NL_SET_ERR_MSG_MOD(bpf->extack, "Per CPU Pools required for XDP"); in mvpp2_xdp_setup()
5353 return -EOPNOTSUPP; in mvpp2_xdp_setup()
5356 if (port->ntxqs < num_possible_cpus() * 2) { in mvpp2_xdp_setup()
5357 NL_SET_ERR_MSG_MOD(bpf->extack, "XDP_TX needs two TX queues per CPU"); in mvpp2_xdp_setup()
5358 return -EOPNOTSUPP; in mvpp2_xdp_setup()
5363 mvpp2_stop(port->dev); in mvpp2_xdp_setup()
5365 old_prog = xchg(&port->xdp_prog, prog); in mvpp2_xdp_setup()
5375 mvpp2_open(port->dev); in mvpp2_xdp_setup()
5387 switch (xdp->command) { in mvpp2_xdp()
5391 return -EINVAL; in mvpp2_xdp()
5401 if (!port->phylink) in mvpp2_ethtool_nway_reset()
5402 return -ENOTSUPP; in mvpp2_ethtool_nway_reset()
5404 return phylink_ethtool_nway_reset(port->phylink); in mvpp2_ethtool_nway_reset()
5417 for (queue = 0; queue < port->nrxqs; queue++) { in mvpp2_ethtool_set_coalesce()
5418 struct mvpp2_rx_queue *rxq = port->rxqs[queue]; in mvpp2_ethtool_set_coalesce()
5420 rxq->time_coal = c->rx_coalesce_usecs; in mvpp2_ethtool_set_coalesce()
5421 rxq->pkts_coal = c->rx_max_coalesced_frames; in mvpp2_ethtool_set_coalesce()
5426 if (port->has_tx_irqs) { in mvpp2_ethtool_set_coalesce()
5427 port->tx_time_coal = c->tx_coalesce_usecs; in mvpp2_ethtool_set_coalesce()
5431 for (queue = 0; queue < port->ntxqs; queue++) { in mvpp2_ethtool_set_coalesce()
5432 struct mvpp2_tx_queue *txq = port->txqs[queue]; in mvpp2_ethtool_set_coalesce()
5434 txq->done_pkts_coal = c->tx_max_coalesced_frames; in mvpp2_ethtool_set_coalesce()
5436 if (port->has_tx_irqs) in mvpp2_ethtool_set_coalesce()
5452 c->rx_coalesce_usecs = port->rxqs[0]->time_coal; in mvpp2_ethtool_get_coalesce()
5453 c->rx_max_coalesced_frames = port->rxqs[0]->pkts_coal; in mvpp2_ethtool_get_coalesce()
5454 c->tx_max_coalesced_frames = port->txqs[0]->done_pkts_coal; in mvpp2_ethtool_get_coalesce()
5455 c->tx_coalesce_usecs = port->tx_time_coal; in mvpp2_ethtool_get_coalesce()
5462 strscpy(drvinfo->driver, MVPP2_DRIVER_NAME, in mvpp2_ethtool_get_drvinfo()
5463 sizeof(drvinfo->driver)); in mvpp2_ethtool_get_drvinfo()
5464 strscpy(drvinfo->version, MVPP2_DRIVER_VERSION, in mvpp2_ethtool_get_drvinfo()
5465 sizeof(drvinfo->version)); in mvpp2_ethtool_get_drvinfo()
5466 strscpy(drvinfo->bus_info, dev_name(&dev->dev), in mvpp2_ethtool_get_drvinfo()
5467 sizeof(drvinfo->bus_info)); in mvpp2_ethtool_get_drvinfo()
5478 ring->rx_max_pending = MVPP2_MAX_RXD_MAX; in mvpp2_ethtool_get_ringparam()
5479 ring->tx_max_pending = MVPP2_MAX_TXD_MAX; in mvpp2_ethtool_get_ringparam()
5480 ring->rx_pending = port->rx_ring_size; in mvpp2_ethtool_get_ringparam()
5481 ring->tx_pending = port->tx_ring_size; in mvpp2_ethtool_get_ringparam()
5491 u16 prev_rx_ring_size = port->rx_ring_size; in mvpp2_ethtool_set_ringparam()
5492 u16 prev_tx_ring_size = port->tx_ring_size; in mvpp2_ethtool_set_ringparam()
5500 port->rx_ring_size = ring->rx_pending; in mvpp2_ethtool_set_ringparam()
5501 port->tx_ring_size = ring->tx_pending; in mvpp2_ethtool_set_ringparam()
5512 port->rx_ring_size = ring->rx_pending; in mvpp2_ethtool_set_ringparam()
5513 port->tx_ring_size = ring->tx_pending; in mvpp2_ethtool_set_ringparam()
5518 port->rx_ring_size = prev_rx_ring_size; in mvpp2_ethtool_set_ringparam()
5519 ring->rx_pending = prev_rx_ring_size; in mvpp2_ethtool_set_ringparam()
5527 port->tx_ring_size = prev_tx_ring_size; in mvpp2_ethtool_set_ringparam()
5528 ring->tx_pending = prev_tx_ring_size; in mvpp2_ethtool_set_ringparam()
5552 if (!port->phylink) in mvpp2_ethtool_get_pause_param()
5555 phylink_ethtool_get_pauseparam(port->phylink, pause); in mvpp2_ethtool_get_pause_param()
5563 if (!port->phylink) in mvpp2_ethtool_set_pause_param()
5564 return -ENOTSUPP; in mvpp2_ethtool_set_pause_param()
5566 return phylink_ethtool_set_pauseparam(port->phylink, pause); in mvpp2_ethtool_set_pause_param()
5574 if (!port->phylink) in mvpp2_ethtool_get_link_ksettings()
5575 return -ENOTSUPP; in mvpp2_ethtool_get_link_ksettings()
5577 return phylink_ethtool_ksettings_get(port->phylink, cmd); in mvpp2_ethtool_get_link_ksettings()
5585 if (!port->phylink) in mvpp2_ethtool_set_link_ksettings()
5586 return -ENOTSUPP; in mvpp2_ethtool_set_link_ksettings()
5588 return phylink_ethtool_ksettings_set(port->phylink, cmd); in mvpp2_ethtool_set_link_ksettings()
5598 return -EOPNOTSUPP; in mvpp2_ethtool_get_rxnfc()
5600 switch (info->cmd) { in mvpp2_ethtool_get_rxnfc()
5605 info->data = port->nrxqs; in mvpp2_ethtool_get_rxnfc()
5608 info->rule_cnt = port->n_rfs_rules; in mvpp2_ethtool_get_rxnfc()
5615 if (loc == info->rule_cnt) { in mvpp2_ethtool_get_rxnfc()
5616 ret = -EMSGSIZE; in mvpp2_ethtool_get_rxnfc()
5620 if (port->rfs_rules[i]) in mvpp2_ethtool_get_rxnfc()
5625 return -ENOTSUPP; in mvpp2_ethtool_get_rxnfc()
5638 return -EOPNOTSUPP; in mvpp2_ethtool_set_rxnfc()
5640 switch (info->cmd) { in mvpp2_ethtool_set_rxnfc()
5651 return -EOPNOTSUPP; in mvpp2_ethtool_set_rxnfc()
5667 u32 rss_context = rxfh->rss_context; in mvpp2_ethtool_get_rxfh()
5671 return -EOPNOTSUPP; in mvpp2_ethtool_get_rxfh()
5673 return -EINVAL; in mvpp2_ethtool_get_rxfh()
5675 rxfh->hfunc = ETH_RSS_HASH_CRC32; in mvpp2_ethtool_get_rxfh()
5677 if (rxfh->indir) in mvpp2_ethtool_get_rxfh()
5679 rxfh->indir); in mvpp2_ethtool_get_rxfh()
5690 if (rxfh->hfunc != ETH_RSS_HASH_NO_CHANGE && in mvpp2_ethtool_rxfh_okay()
5691 rxfh->hfunc != ETH_RSS_HASH_CRC32) in mvpp2_ethtool_rxfh_okay()
5694 if (rxfh->key) in mvpp2_ethtool_rxfh_okay()
5709 return -EOPNOTSUPP; in mvpp2_create_rxfh_context()
5711 ctx->hfunc = ETH_RSS_HASH_CRC32; in mvpp2_create_rxfh_context()
5713 ret = mvpp22_port_rss_ctx_create(port, rxfh->rss_context); in mvpp2_create_rxfh_context()
5717 if (!rxfh->indir) in mvpp2_create_rxfh_context()
5718 ret = mvpp22_port_rss_ctx_indir_get(port, rxfh->rss_context, in mvpp2_create_rxfh_context()
5721 ret = mvpp22_port_rss_ctx_indir_set(port, rxfh->rss_context, in mvpp2_create_rxfh_context()
5722 rxfh->indir); in mvpp2_create_rxfh_context()
5735 return -EOPNOTSUPP; in mvpp2_modify_rxfh_context()
5737 if (rxfh->indir) in mvpp2_modify_rxfh_context()
5738 ret = mvpp22_port_rss_ctx_indir_set(port, rxfh->rss_context, in mvpp2_modify_rxfh_context()
5739 rxfh->indir); in mvpp2_modify_rxfh_context()
5808 * had a single IRQ defined per-port.
5813 struct mvpp2_queue_vector *v = &port->qvecs[0]; in mvpp2_simple_queue_vectors_init()
5815 v->first_rxq = 0; in mvpp2_simple_queue_vectors_init()
5816 v->nrxqs = port->nrxqs; in mvpp2_simple_queue_vectors_init()
5817 v->type = MVPP2_QUEUE_VECTOR_SHARED; in mvpp2_simple_queue_vectors_init()
5818 v->sw_thread_id = 0; in mvpp2_simple_queue_vectors_init()
5819 v->sw_thread_mask = *cpumask_bits(cpu_online_mask); in mvpp2_simple_queue_vectors_init()
5820 v->port = port; in mvpp2_simple_queue_vectors_init()
5821 v->irq = irq_of_parse_and_map(port_node, 0); in mvpp2_simple_queue_vectors_init()
5822 if (v->irq <= 0) in mvpp2_simple_queue_vectors_init()
5823 return -EINVAL; in mvpp2_simple_queue_vectors_init()
5824 netif_napi_add(port->dev, &v->napi, mvpp2_poll); in mvpp2_simple_queue_vectors_init()
5826 port->nqvecs = 1; in mvpp2_simple_queue_vectors_init()
5834 struct mvpp2 *priv = port->priv; in mvpp2_multi_queue_vectors_init()
5840 port->nqvecs = priv->nthreads + 1; in mvpp2_multi_queue_vectors_init()
5843 port->nqvecs = priv->nthreads; in mvpp2_multi_queue_vectors_init()
5847 for (i = 0; i < port->nqvecs; i++) { in mvpp2_multi_queue_vectors_init()
5850 v = port->qvecs + i; in mvpp2_multi_queue_vectors_init()
5852 v->port = port; in mvpp2_multi_queue_vectors_init()
5853 v->type = MVPP2_QUEUE_VECTOR_PRIVATE; in mvpp2_multi_queue_vectors_init()
5854 v->sw_thread_id = i; in mvpp2_multi_queue_vectors_init()
5855 v->sw_thread_mask = BIT(i); in mvpp2_multi_queue_vectors_init()
5857 if (port->flags & MVPP2_F_DT_COMPAT) in mvpp2_multi_queue_vectors_init()
5858 snprintf(irqname, sizeof(irqname), "tx-cpu%d", i); in mvpp2_multi_queue_vectors_init()
5863 v->first_rxq = i; in mvpp2_multi_queue_vectors_init()
5864 v->nrxqs = 1; in mvpp2_multi_queue_vectors_init()
5866 i == (port->nqvecs - 1)) { in mvpp2_multi_queue_vectors_init()
5867 v->first_rxq = 0; in mvpp2_multi_queue_vectors_init()
5868 v->nrxqs = port->nrxqs; in mvpp2_multi_queue_vectors_init()
5869 v->type = MVPP2_QUEUE_VECTOR_SHARED; in mvpp2_multi_queue_vectors_init()
5871 if (port->flags & MVPP2_F_DT_COMPAT) in mvpp2_multi_queue_vectors_init()
5872 strscpy(irqname, "rx-shared", sizeof(irqname)); in mvpp2_multi_queue_vectors_init()
5876 v->irq = of_irq_get_byname(port_node, irqname); in mvpp2_multi_queue_vectors_init()
5878 v->irq = fwnode_irq_get(port->fwnode, i); in mvpp2_multi_queue_vectors_init()
5879 if (v->irq <= 0) { in mvpp2_multi_queue_vectors_init()
5880 ret = -EINVAL; in mvpp2_multi_queue_vectors_init()
5884 netif_napi_add(port->dev, &v->napi, mvpp2_poll); in mvpp2_multi_queue_vectors_init()
5890 for (i = 0; i < port->nqvecs; i++) in mvpp2_multi_queue_vectors_init()
5891 irq_dispose_mapping(port->qvecs[i].irq); in mvpp2_multi_queue_vectors_init()
5898 if (port->has_tx_irqs) in mvpp2_queue_vectors_init()
5908 for (i = 0; i < port->nqvecs; i++) in mvpp2_queue_vectors_deinit()
5909 irq_dispose_mapping(port->qvecs[i].irq); in mvpp2_queue_vectors_deinit()
5915 struct mvpp2 *priv = port->priv; in mvpp2_rx_irqs_setup()
5919 if (priv->hw_version == MVPP21) { in mvpp2_rx_irqs_setup()
5920 mvpp2_write(priv, MVPP21_ISR_RXQ_GROUP_REG(port->id), in mvpp2_rx_irqs_setup()
5921 port->nrxqs); in mvpp2_rx_irqs_setup()
5926 for (i = 0; i < port->nqvecs; i++) { in mvpp2_rx_irqs_setup()
5927 struct mvpp2_queue_vector *qv = port->qvecs + i; in mvpp2_rx_irqs_setup()
5929 if (!qv->nrxqs) in mvpp2_rx_irqs_setup()
5932 val = qv->sw_thread_id; in mvpp2_rx_irqs_setup()
5933 val |= port->id << MVPP22_ISR_RXQ_GROUP_INDEX_GROUP_OFFSET; in mvpp2_rx_irqs_setup()
5936 val = qv->first_rxq; in mvpp2_rx_irqs_setup()
5937 val |= qv->nrxqs << MVPP22_ISR_RXQ_SUB_GROUP_SIZE_OFFSET; in mvpp2_rx_irqs_setup()
5945 struct device *dev = port->dev->dev.parent; in mvpp2_port_init()
5946 struct mvpp2 *priv = port->priv; in mvpp2_port_init()
5952 if (port->first_rxq + port->nrxqs > in mvpp2_port_init()
5953 MVPP2_MAX_PORTS * priv->max_port_rxqs) in mvpp2_port_init()
5954 return -EINVAL; in mvpp2_port_init()
5956 if (port->nrxqs > priv->max_port_rxqs || port->ntxqs > MVPP2_MAX_TXQ) in mvpp2_port_init()
5957 return -EINVAL; in mvpp2_port_init()
5963 if (mvpp2_is_xlg(port->phy_interface)) { in mvpp2_port_init()
5964 val = readl(port->base + MVPP22_XLG_CTRL0_REG); in mvpp2_port_init()
5967 writel(val, port->base + MVPP22_XLG_CTRL0_REG); in mvpp2_port_init()
5969 val = readl(port->base + MVPP2_GMAC_AUTONEG_CONFIG); in mvpp2_port_init()
5972 writel(val, port->base + MVPP2_GMAC_AUTONEG_CONFIG); in mvpp2_port_init()
5975 port->tx_time_coal = MVPP2_TXDONE_COAL_USEC; in mvpp2_port_init()
5977 port->txqs = devm_kcalloc(dev, port->ntxqs, sizeof(*port->txqs), in mvpp2_port_init()
5979 if (!port->txqs) in mvpp2_port_init()
5980 return -ENOMEM; in mvpp2_port_init()
5985 for (queue = 0; queue < port->ntxqs; queue++) { in mvpp2_port_init()
5986 int queue_phy_id = mvpp2_txq_phys(port->id, queue); in mvpp2_port_init()
5991 err = -ENOMEM; in mvpp2_port_init()
5995 txq->pcpu = alloc_percpu(struct mvpp2_txq_pcpu); in mvpp2_port_init()
5996 if (!txq->pcpu) { in mvpp2_port_init()
5997 err = -ENOMEM; in mvpp2_port_init()
6001 txq->id = queue_phy_id; in mvpp2_port_init()
6002 txq->log_id = queue; in mvpp2_port_init()
6003 txq->done_pkts_coal = MVPP2_TXDONE_COAL_PKTS_THRESH; in mvpp2_port_init()
6004 for (thread = 0; thread < priv->nthreads; thread++) { in mvpp2_port_init()
6005 txq_pcpu = per_cpu_ptr(txq->pcpu, thread); in mvpp2_port_init()
6006 txq_pcpu->thread = thread; in mvpp2_port_init()
6009 port->txqs[queue] = txq; in mvpp2_port_init()
6012 port->rxqs = devm_kcalloc(dev, port->nrxqs, sizeof(*port->rxqs), in mvpp2_port_init()
6014 if (!port->rxqs) { in mvpp2_port_init()
6015 err = -ENOMEM; in mvpp2_port_init()
6020 for (queue = 0; queue < port->nrxqs; queue++) { in mvpp2_port_init()
6026 err = -ENOMEM; in mvpp2_port_init()
6030 rxq->id = port->first_rxq + queue; in mvpp2_port_init()
6031 rxq->port = port->id; in mvpp2_port_init()
6032 rxq->logic_rxq = queue; in mvpp2_port_init()
6034 port->rxqs[queue] = rxq; in mvpp2_port_init()
6040 for (queue = 0; queue < port->nrxqs; queue++) { in mvpp2_port_init()
6041 struct mvpp2_rx_queue *rxq = port->rxqs[queue]; in mvpp2_port_init()
6043 rxq->size = port->rx_ring_size; in mvpp2_port_init()
6044 rxq->pkts_coal = MVPP2_RX_COAL_PKTS; in mvpp2_port_init()
6045 rxq->time_coal = MVPP2_RX_COAL_USEC; in mvpp2_port_init()
6061 port->pkt_size = MVPP2_RX_PKT_SIZE(port->dev->mtu); in mvpp2_port_init()
6070 memset(port->ethtool_stats, 0, in mvpp2_port_init()
6071 MVPP2_N_ETHTOOL_STATS(port->ntxqs, port->nrxqs) * sizeof(u64)); in mvpp2_port_init()
6076 for (queue = 0; queue < port->ntxqs; queue++) { in mvpp2_port_init()
6077 if (!port->txqs[queue]) in mvpp2_port_init()
6079 free_percpu(port->txqs[queue]->pcpu); in mvpp2_port_init()
6087 char *irqs[5] = { "rx-shared", "tx-cpu0", "tx-cpu1", "tx-cpu2", in mvpp22_port_has_legacy_tx_irqs()
6088 "tx-cpu3" }; in mvpp22_port_has_legacy_tx_irqs()
6091 for (i = 0; i < 5; i++) in mvpp22_port_has_legacy_tx_irqs()
6092 if (of_property_match_string(port_node, "interrupt-names", in mvpp22_port_has_legacy_tx_irqs()
6101 * - PPv2.1: there are no such interrupts.
6102 * - PPv2.2 and PPv2.3:
6103 * - The old DTs have: "rx-shared", "tx-cpuX" with X in [0...3]
6104 * - The new ones have: "hifX" with X in [0..8]
6112 char name[5]; in mvpp2_port_has_irqs()
6119 if (priv->hw_version == MVPP21) in mvpp2_port_has_irqs()
6126 snprintf(name, 5, "hif%d", i); in mvpp2_port_has_irqs()
6127 if (of_property_match_string(port_node, "interrupt-names", in mvpp2_port_has_irqs()
6150 if (priv->hw_version == MVPP21) { in mvpp2_port_copy_mac_addr()
6161 if (ret == -EPROBE_DEFER) in mvpp2_port_copy_mac_addr()
6196 if (port->phy_interface == PHY_INTERFACE_MODE_5GBASER) in mvpp2_xlg_pcs_get_state()
6197 state->speed = SPEED_5000; in mvpp2_xlg_pcs_get_state()
6199 state->speed = SPEED_10000; in mvpp2_xlg_pcs_get_state()
6200 state->duplex = 1; in mvpp2_xlg_pcs_get_state()
6201 state->an_complete = 1; in mvpp2_xlg_pcs_get_state()
6203 val = readl(port->base + MVPP22_XLG_STATUS); in mvpp2_xlg_pcs_get_state()
6204 state->link = !!(val & MVPP22_XLG_STATUS_LINK_UP); in mvpp2_xlg_pcs_get_state()
6206 state->pause = 0; in mvpp2_xlg_pcs_get_state()
6207 val = readl(port->base + MVPP22_XLG_CTRL0_REG); in mvpp2_xlg_pcs_get_state()
6209 state->pause |= MLO_PAUSE_TX; in mvpp2_xlg_pcs_get_state()
6211 state->pause |= MLO_PAUSE_RX; in mvpp2_xlg_pcs_get_state()
6232 * Bit 2 Field InBandAnEn In-band Auto-Negotiation enable. ... in mvpp2_gmac_pcs_validate()
6233 * When <PortType> = 1 (1000BASE-X) this field must be set to 1. in mvpp2_gmac_pcs_validate()
6235 if (phy_interface_mode_is_8023z(state->interface) && in mvpp2_gmac_pcs_validate()
6236 !phylink_test(state->advertising, Autoneg)) in mvpp2_gmac_pcs_validate()
6237 return -EINVAL; in mvpp2_gmac_pcs_validate()
6248 val = readl(port->base + MVPP2_GMAC_STATUS0); in mvpp2_gmac_pcs_get_state()
6250 state->an_complete = !!(val & MVPP2_GMAC_STATUS0_AN_COMPLETE); in mvpp2_gmac_pcs_get_state()
6251 state->link = !!(val & MVPP2_GMAC_STATUS0_LINK_UP); in mvpp2_gmac_pcs_get_state()
6252 state->duplex = !!(val & MVPP2_GMAC_STATUS0_FULL_DUPLEX); in mvpp2_gmac_pcs_get_state()
6254 switch (port->phy_interface) { in mvpp2_gmac_pcs_get_state()
6256 state->speed = SPEED_1000; in mvpp2_gmac_pcs_get_state()
6259 state->speed = SPEED_2500; in mvpp2_gmac_pcs_get_state()
6263 state->speed = SPEED_1000; in mvpp2_gmac_pcs_get_state()
6265 state->speed = SPEED_100; in mvpp2_gmac_pcs_get_state()
6267 state->speed = SPEED_10; in mvpp2_gmac_pcs_get_state()
6270 state->pause = 0; in mvpp2_gmac_pcs_get_state()
6272 state->pause |= MLO_PAUSE_RX; in mvpp2_gmac_pcs_get_state()
6274 state->pause |= MLO_PAUSE_TX; in mvpp2_gmac_pcs_get_state()
6324 old_an = an = readl(port->base + MVPP2_GMAC_AUTONEG_CONFIG); in mvpp2_gmac_pcs_config()
6328 writel(an, port->base + MVPP2_GMAC_AUTONEG_CONFIG); in mvpp2_gmac_pcs_config()
6337 u32 val = readl(port->base + MVPP2_GMAC_AUTONEG_CONFIG); in mvpp2_gmac_pcs_an_restart()
6340 port->base + MVPP2_GMAC_AUTONEG_CONFIG); in mvpp2_gmac_pcs_an_restart()
6342 port->base + MVPP2_GMAC_AUTONEG_CONFIG); in mvpp2_gmac_pcs_an_restart()
6357 mvpp2_modify(port->base + MVPP22_XLG_CTRL0_REG, in mvpp2_xlg_config()
6360 mvpp2_modify(port->base + MVPP22_XLG_CTRL4_REG, in mvpp2_xlg_config()
6368 val = readl(port->base + MVPP22_XLG_CTRL0_REG); in mvpp2_xlg_config()
6379 old_ctrl0 = ctrl0 = readl(port->base + MVPP2_GMAC_CTRL_0_REG); in mvpp2_gmac_config()
6380 old_ctrl2 = ctrl2 = readl(port->base + MVPP2_GMAC_CTRL_2_REG); in mvpp2_gmac_config()
6381 old_ctrl4 = ctrl4 = readl(port->base + MVPP22_GMAC_CTRL_4_REG); in mvpp2_gmac_config()
6387 if (phy_interface_mode_is_8023z(state->interface)) { in mvpp2_gmac_config()
6393 } else if (state->interface == PHY_INTERFACE_MODE_SGMII) { in mvpp2_gmac_config()
6399 } else if (phy_interface_mode_is_rgmii(state->interface)) { in mvpp2_gmac_config()
6408 /* Phy or fixed speed - no in-band AN, nothing to do, leave the in mvpp2_gmac_config()
6409 * configured speed, duplex and flow control as-is. in mvpp2_gmac_config()
6411 } else if (state->interface == PHY_INTERFACE_MODE_SGMII) { in mvpp2_gmac_config()
6412 /* SGMII in-band mode receives the speed and duplex from in mvpp2_gmac_config()
6414 } else if (phy_interface_mode_is_8023z(state->interface)) { in mvpp2_gmac_config()
6424 writel(ctrl0, port->base + MVPP2_GMAC_CTRL_0_REG); in mvpp2_gmac_config()
6426 writel(ctrl2, port->base + MVPP2_GMAC_CTRL_2_REG); in mvpp2_gmac_config()
6428 writel(ctrl4, port->base + MVPP22_GMAC_CTRL_4_REG); in mvpp2_gmac_config()
6441 return &port->pcs_xlg; in mvpp2_select_pcs()
6443 return &port->pcs_gmac; in mvpp2_select_pcs()
6452 if (mvpp2_is_xlg(interface) && port->gop_id != 0) { in mvpp2_mac_prepare()
6453 netdev_err(port->dev, "Invalid mode on %s\n", port->dev->name); in mvpp2_mac_prepare()
6454 return -EINVAL; in mvpp2_mac_prepare()
6457 if (port->phy_interface != interface || in mvpp2_mac_prepare()
6460 * in-band mode to ensure we do not change the configuration in mvpp2_mac_prepare()
6465 mvpp2_modify(port->base + MVPP2_GMAC_AUTONEG_CONFIG, in mvpp2_mac_prepare()
6471 mvpp2_modify(port->base + MVPP22_XLG_CTRL0_REG, in mvpp2_mac_prepare()
6480 if (port->phy_interface != interface) { in mvpp2_mac_prepare()
6482 mvpp2_modify(port->base + MVPP2_GMAC_CTRL_2_REG, in mvpp2_mac_prepare()
6486 if (port->priv->hw_version >= MVPP22) { in mvpp2_mac_prepare()
6489 phy_power_off(port->comphy); in mvpp2_mac_prepare()
6505 if (mvpp2_is_xlg(state->interface)) in mvpp2_mac_config()
6507 else if (phy_interface_mode_is_rgmii(state->interface) || in mvpp2_mac_config()
6508 phy_interface_mode_is_8023z(state->interface) || in mvpp2_mac_config()
6509 state->interface == PHY_INTERFACE_MODE_SGMII) in mvpp2_mac_config()
6512 if (port->priv->hw_version == MVPP21 && port->flags & MVPP2_F_LOOPBACK) in mvpp2_mac_config()
6521 if (port->priv->hw_version >= MVPP22 && in mvpp2_mac_finish()
6522 port->phy_interface != interface) { in mvpp2_mac_finish()
6523 port->phy_interface = interface; in mvpp2_mac_finish()
6531 mvpp2_modify(port->base + MVPP2_GMAC_CTRL_2_REG, in mvpp2_mac_finish()
6534 while (readl(port->base + MVPP2_GMAC_CTRL_2_REG) & in mvpp2_mac_finish()
6541 /* Allow the link to come up if in in-band mode, otherwise the in mvpp2_mac_finish()
6546 mvpp2_modify(port->base + MVPP22_XLG_CTRL0_REG, in mvpp2_mac_finish()
6550 mvpp2_modify(port->base + MVPP2_GMAC_AUTONEG_CONFIG, in mvpp2_mac_finish()
6576 mvpp2_modify(port->base + MVPP22_XLG_CTRL0_REG, in mvpp2_mac_link_up()
6594 mvpp2_modify(port->base + MVPP2_GMAC_AUTONEG_CONFIG, in mvpp2_mac_link_up()
6612 mvpp2_modify(port->base + MVPP22_GMAC_CTRL_4_REG, in mvpp2_mac_link_up()
6617 if (port->priv->global_tx_fc) { in mvpp2_mac_link_up()
6618 port->tx_fc = tx_pause; in mvpp2_mac_link_up()
6623 if (port->priv->percpu_pools) { in mvpp2_mac_link_up()
6624 for (i = 0; i < port->nrxqs; i++) in mvpp2_mac_link_up()
6625 mvpp2_bm_pool_update_fc(port, &port->priv->bm_pools[i], tx_pause); in mvpp2_mac_link_up()
6627 mvpp2_bm_pool_update_fc(port, port->pool_long, tx_pause); in mvpp2_mac_link_up()
6628 mvpp2_bm_pool_update_fc(port, port->pool_short, tx_pause); in mvpp2_mac_link_up()
6630 if (port->priv->hw_version == MVPP23) in mvpp2_mac_link_up()
6631 mvpp23_rx_fifo_fc_en(port->priv, port->id, tx_pause); in mvpp2_mac_link_up()
6638 netif_tx_wake_all_queues(port->dev); in mvpp2_mac_link_up()
6649 val = readl(port->base + MVPP22_XLG_CTRL0_REG); in mvpp2_mac_link_down()
6652 writel(val, port->base + MVPP22_XLG_CTRL0_REG); in mvpp2_mac_link_down()
6654 val = readl(port->base + MVPP2_GMAC_AUTONEG_CONFIG); in mvpp2_mac_link_down()
6657 writel(val, port->base + MVPP2_GMAC_AUTONEG_CONFIG); in mvpp2_mac_link_down()
6661 netif_tx_stop_all_queues(port->dev); in mvpp2_mac_link_down()
6677 /* Work-around for ACPI */
6685 .interface = port->phy_interface, in mvpp2_acpi_start()
6689 pcs = mvpp2_select_pcs(&port->phylink_config, port->phy_interface); in mvpp2_acpi_start()
6691 mvpp2_mac_prepare(&port->phylink_config, MLO_AN_INBAND, in mvpp2_acpi_start()
6692 port->phy_interface); in mvpp2_acpi_start()
6693 mvpp2_mac_config(&port->phylink_config, MLO_AN_INBAND, &state); in mvpp2_acpi_start()
6694 pcs->ops->pcs_config(pcs, PHYLINK_PCS_NEG_INBAND_ENABLED, in mvpp2_acpi_start()
6695 port->phy_interface, state.advertising, in mvpp2_acpi_start()
6697 mvpp2_mac_finish(&port->phylink_config, MLO_AN_INBAND, in mvpp2_acpi_start()
6698 port->phy_interface); in mvpp2_acpi_start()
6699 mvpp2_mac_link_up(&port->phylink_config, NULL, in mvpp2_acpi_start()
6700 MLO_AN_INBAND, port->phy_interface, in mvpp2_acpi_start()
6712 return (!fwnode_property_present(port_fwnode, "phy-handle") && in mvpp2_use_acpi_compat_mode()
6714 !fwnode_get_named_child_node(port_fwnode, "fixed-link")); in mvpp2_use_acpi_compat_mode()
6739 dev_err(&pdev->dev, in mvpp2_port_probe()
6741 return -EINVAL; in mvpp2_port_probe()
6749 return -ENOMEM; in mvpp2_port_probe()
6753 dev_err(&pdev->dev, "incorrect phy mode\n"); in mvpp2_port_probe()
6759 * Rewrite 10GBASE-KR to 10GBASE-R for compatibility with existing DT. in mvpp2_port_probe()
6760 * Existing usage of 10GBASE-KR is not correct; no backplane in mvpp2_port_probe()
6762 * 10GBASE-KR. in mvpp2_port_probe()
6768 comphy = devm_of_phy_get(&pdev->dev, port_node, NULL); in mvpp2_port_probe()
6770 if (PTR_ERR(comphy) == -EPROBE_DEFER) { in mvpp2_port_probe()
6771 err = -EPROBE_DEFER; in mvpp2_port_probe()
6778 if (fwnode_property_read_u32(port_fwnode, "port-id", &id)) { in mvpp2_port_probe()
6779 err = -EINVAL; in mvpp2_port_probe()
6780 dev_err(&pdev->dev, "missing port-id value\n"); in mvpp2_port_probe()
6784 dev->tx_queue_len = MVPP2_MAX_TXD_MAX; in mvpp2_port_probe()
6785 dev->watchdog_timeo = 5 * HZ; in mvpp2_port_probe()
6786 dev->netdev_ops = &mvpp2_netdev_ops; in mvpp2_port_probe()
6787 dev->ethtool_ops = &mvpp2_eth_tool_ops; in mvpp2_port_probe()
6790 port->dev = dev; in mvpp2_port_probe()
6791 port->fwnode = port_fwnode; in mvpp2_port_probe()
6792 port->ntxqs = ntxqs; in mvpp2_port_probe()
6793 port->nrxqs = nrxqs; in mvpp2_port_probe()
6794 port->priv = priv; in mvpp2_port_probe()
6795 port->has_tx_irqs = has_tx_irqs; in mvpp2_port_probe()
6796 port->flags = flags; in mvpp2_port_probe()
6803 port->port_irq = of_irq_get_byname(port_node, "link"); in mvpp2_port_probe()
6805 port->port_irq = fwnode_irq_get(port_fwnode, port->nqvecs + 1); in mvpp2_port_probe()
6806 if (port->port_irq == -EPROBE_DEFER) { in mvpp2_port_probe()
6807 err = -EPROBE_DEFER; in mvpp2_port_probe()
6810 if (port->port_irq <= 0) in mvpp2_port_probe()
6812 port->port_irq = 0; in mvpp2_port_probe()
6815 port->flags |= MVPP2_F_LOOPBACK; in mvpp2_port_probe()
6817 port->id = id; in mvpp2_port_probe()
6818 if (priv->hw_version == MVPP21) in mvpp2_port_probe()
6819 port->first_rxq = port->id * port->nrxqs; in mvpp2_port_probe()
6821 port->first_rxq = port->id * priv->max_port_rxqs; in mvpp2_port_probe()
6823 port->of_node = port_node; in mvpp2_port_probe()
6824 port->phy_interface = phy_mode; in mvpp2_port_probe()
6825 port->comphy = comphy; in mvpp2_port_probe()
6827 if (priv->hw_version == MVPP21) { in mvpp2_port_probe()
6828 port->base = devm_platform_ioremap_resource(pdev, 2 + id); in mvpp2_port_probe()
6829 if (IS_ERR(port->base)) { in mvpp2_port_probe()
6830 err = PTR_ERR(port->base); in mvpp2_port_probe()
6834 port->stats_base = port->priv->lms_base + in mvpp2_port_probe()
6836 port->gop_id * MVPP21_MIB_COUNTERS_PORT_SZ; in mvpp2_port_probe()
6838 if (fwnode_property_read_u32(port_fwnode, "gop-port-id", in mvpp2_port_probe()
6839 &port->gop_id)) { in mvpp2_port_probe()
6840 err = -EINVAL; in mvpp2_port_probe()
6841 dev_err(&pdev->dev, "missing gop-port-id value\n"); in mvpp2_port_probe()
6845 port->base = priv->iface_base + MVPP22_GMAC_BASE(port->gop_id); in mvpp2_port_probe()
6846 port->stats_base = port->priv->iface_base + in mvpp2_port_probe()
6848 port->gop_id * MVPP22_MIB_COUNTERS_PORT_SZ; in mvpp2_port_probe()
6853 if (priv->tai) in mvpp2_port_probe()
6854 port->hwtstamp = true; in mvpp2_port_probe()
6857 /* Alloc per-cpu and ethtool stats */ in mvpp2_port_probe()
6858 port->stats = netdev_alloc_pcpu_stats(struct mvpp2_pcpu_stats); in mvpp2_port_probe()
6859 if (!port->stats) { in mvpp2_port_probe()
6860 err = -ENOMEM; in mvpp2_port_probe()
6864 port->ethtool_stats = devm_kcalloc(&pdev->dev, in mvpp2_port_probe()
6867 if (!port->ethtool_stats) { in mvpp2_port_probe()
6868 err = -ENOMEM; in mvpp2_port_probe()
6872 mutex_init(&port->gather_stats_lock); in mvpp2_port_probe()
6873 INIT_DELAYED_WORK(&port->stats_work, mvpp2_gather_hw_statistics); in mvpp2_port_probe()
6879 port->tx_ring_size = MVPP2_MAX_TXD_DFLT; in mvpp2_port_probe()
6880 port->rx_ring_size = MVPP2_MAX_RXD_DFLT; in mvpp2_port_probe()
6881 SET_NETDEV_DEV(dev, &pdev->dev); in mvpp2_port_probe()
6885 dev_err(&pdev->dev, "failed to init port %d\n", id); in mvpp2_port_probe()
6894 port->pcpu = alloc_percpu(struct mvpp2_port_pcpu); in mvpp2_port_probe()
6895 if (!port->pcpu) { in mvpp2_port_probe()
6896 err = -ENOMEM; in mvpp2_port_probe()
6900 if (!port->has_tx_irqs) { in mvpp2_port_probe()
6901 for (thread = 0; thread < priv->nthreads; thread++) { in mvpp2_port_probe()
6902 port_pcpu = per_cpu_ptr(port->pcpu, thread); in mvpp2_port_probe()
6904 hrtimer_init(&port_pcpu->tx_done_timer, CLOCK_MONOTONIC, in mvpp2_port_probe()
6906 port_pcpu->tx_done_timer.function = mvpp2_hr_timer_cb; in mvpp2_port_probe()
6907 port_pcpu->timer_scheduled = false; in mvpp2_port_probe()
6908 port_pcpu->dev = dev; in mvpp2_port_probe()
6914 dev->features = features | NETIF_F_RXCSUM; in mvpp2_port_probe()
6915 dev->hw_features |= features | NETIF_F_RXCSUM | NETIF_F_GRO | in mvpp2_port_probe()
6919 dev->hw_features |= NETIF_F_RXHASH; in mvpp2_port_probe()
6920 dev->features |= NETIF_F_NTUPLE; in mvpp2_port_probe()
6923 if (!port->priv->percpu_pools) in mvpp2_port_probe()
6924 mvpp2_set_hw_csum(port, port->pool_long->id); in mvpp2_port_probe()
6925 else if (port->ntxqs >= num_possible_cpus() * 2) in mvpp2_port_probe()
6926 dev->xdp_features = NETDEV_XDP_ACT_BASIC | in mvpp2_port_probe()
6930 dev->vlan_features |= features; in mvpp2_port_probe()
6933 dev->priv_flags |= IFF_UNICAST_FLT; in mvpp2_port_probe()
6935 /* MTU range: 68 - 9704 */ in mvpp2_port_probe()
6936 dev->min_mtu = ETH_MIN_MTU; in mvpp2_port_probe()
6937 /* 9704 == 9728 - 20 and rounding to 8 */ in mvpp2_port_probe()
6938 dev->max_mtu = MVPP2_BM_JUMBO_PKT_SIZE; in mvpp2_port_probe()
6939 device_set_node(&dev->dev, port_fwnode); in mvpp2_port_probe()
6940 dev->dev_port = port->id; in mvpp2_port_probe()
6942 port->pcs_gmac.ops = &mvpp2_phylink_gmac_pcs_ops; in mvpp2_port_probe()
6943 port->pcs_gmac.neg_mode = true; in mvpp2_port_probe()
6944 port->pcs_xlg.ops = &mvpp2_phylink_xlg_pcs_ops; in mvpp2_port_probe()
6945 port->pcs_xlg.neg_mode = true; in mvpp2_port_probe()
6948 port->phylink_config.dev = &dev->dev; in mvpp2_port_probe()
6949 port->phylink_config.type = PHYLINK_NETDEV; in mvpp2_port_probe()
6950 port->phylink_config.mac_capabilities = in mvpp2_port_probe()
6953 if (port->priv->global_tx_fc) in mvpp2_port_probe()
6954 port->phylink_config.mac_capabilities |= in mvpp2_port_probe()
6963 port->phylink_config.supported_interfaces); in mvpp2_port_probe()
6965 port->phylink_config.supported_interfaces); in mvpp2_port_probe()
6967 port->phylink_config.supported_interfaces); in mvpp2_port_probe()
6970 port->phylink_config.supported_interfaces); in mvpp2_port_probe()
6973 port->phylink_config.supported_interfaces); in mvpp2_port_probe()
6976 port->phylink_config.supported_interfaces); in mvpp2_port_probe()
6980 port->phylink_config.mac_capabilities |= in mvpp2_port_probe()
6983 port->phylink_config.mac_capabilities |= in mvpp2_port_probe()
6986 port->phylink_config.mac_capabilities |= in mvpp2_port_probe()
6991 phy_interface_set_rgmii(port->phylink_config.supported_interfaces); in mvpp2_port_probe()
6993 port->phylink_config.supported_interfaces); in mvpp2_port_probe()
7001 port->phylink_config.supported_interfaces); in mvpp2_port_probe()
7003 port->phylink_config.supported_interfaces); in mvpp2_port_probe()
7005 port->phylink_config.supported_interfaces); in mvpp2_port_probe()
7007 /* No COMPHY, with only 2500BASE-X mode supported */ in mvpp2_port_probe()
7009 port->phylink_config.supported_interfaces); in mvpp2_port_probe()
7012 /* No COMPHY, we can switch between 1000BASE-X and SGMII in mvpp2_port_probe()
7015 port->phylink_config.supported_interfaces); in mvpp2_port_probe()
7017 port->phylink_config.supported_interfaces); in mvpp2_port_probe()
7020 phylink = phylink_create(&port->phylink_config, port_fwnode, in mvpp2_port_probe()
7026 port->phylink = phylink; in mvpp2_port_probe()
7028 dev_warn(&pdev->dev, "Use link irqs for port#%d. FW update required\n", port->id); in mvpp2_port_probe()
7029 port->phylink = NULL; in mvpp2_port_probe()
7032 /* Cycle the comphy to power it down, saving 270mW per port - in mvpp2_port_probe()
7036 if (port->comphy) { in mvpp2_port_probe()
7037 err = mvpp22_comphy_init(port, port->phy_interface); in mvpp2_port_probe()
7039 phy_power_off(port->comphy); in mvpp2_port_probe()
7044 dev_err(&pdev->dev, "failed to register netdev\n"); in mvpp2_port_probe()
7047 netdev_info(dev, "Using %s mac address %pM\n", mac_from, dev->dev_addr); in mvpp2_port_probe()
7049 priv->port_list[priv->port_count++] = port; in mvpp2_port_probe()
7054 if (port->phylink) in mvpp2_port_probe()
7055 phylink_destroy(port->phylink); in mvpp2_port_probe()
7057 free_percpu(port->pcpu); in mvpp2_port_probe()
7059 for (i = 0; i < port->ntxqs; i++) in mvpp2_port_probe()
7060 free_percpu(port->txqs[i]->pcpu); in mvpp2_port_probe()
7062 free_percpu(port->stats); in mvpp2_port_probe()
7064 if (port->port_irq) in mvpp2_port_probe()
7065 irq_dispose_mapping(port->port_irq); in mvpp2_port_probe()
7078 unregister_netdev(port->dev); in mvpp2_port_remove()
7079 if (port->phylink) in mvpp2_port_remove()
7080 phylink_destroy(port->phylink); in mvpp2_port_remove()
7081 free_percpu(port->pcpu); in mvpp2_port_remove()
7082 free_percpu(port->stats); in mvpp2_port_remove()
7083 for (i = 0; i < port->ntxqs; i++) in mvpp2_port_remove()
7084 free_percpu(port->txqs[i]->pcpu); in mvpp2_port_remove()
7086 if (port->port_irq) in mvpp2_port_remove()
7087 irq_dispose_mapping(port->port_irq); in mvpp2_port_remove()
7088 free_netdev(port->dev); in mvpp2_port_remove()
7108 for (i = 0; i < dram->num_cs; i++) { in mvpp2_conf_mbus_windows()
7109 const struct mbus_dram_window *cs = dram->cs + i; in mvpp2_conf_mbus_windows()
7112 (cs->base & 0xffff0000) | (cs->mbus_attr << 8) | in mvpp2_conf_mbus_windows()
7113 dram->mbus_dram_target_id); in mvpp2_conf_mbus_windows()
7116 (cs->size - 1) & 0xffff0000); in mvpp2_conf_mbus_windows()
7165 port_map = priv->port_map & ~BIT(MVPP2_LOOPBACK_PORT_INDEX); in mvpp22_rx_fifo_init()
7187 size_remainder -= size; in mvpp22_rx_fifo_init()
7188 remaining_ports_count--; in mvpp22_rx_fifo_init()
7203 /* Port 0: maximum speed -10Gb/s port in mvpp23_rx_fifo_fc_set_tresh()
7205 * Port 1: maximum speed -5Gb/s port in mvpp23_rx_fifo_fc_set_tresh()
7207 * Port 2: maximum speed -1Gb/s port in mvpp23_rx_fifo_fc_set_tresh()
7212 for (port = 0; port < (MVPP2_MAX_PORTS - 1); port++) { in mvpp23_rx_fifo_fc_set_tresh()
7271 port_map = priv->port_map & ~BIT(MVPP2_LOOPBACK_PORT_INDEX); in mvpp22_tx_fifo_init()
7290 size_remainder -= size; in mvpp22_tx_fifo_init()
7291 remaining_ports_count--; in mvpp22_tx_fifo_init()
7363 if (priv->hw_version >= MVPP22) in mvpp2_init()
7367 if (priv->hw_version == MVPP21) { in mvpp2_init()
7368 val = readl(priv->lms_base + MVPP2_PHY_AN_CFG0_REG); in mvpp2_init()
7370 writel(val, priv->lms_base + MVPP2_PHY_AN_CFG0_REG); in mvpp2_init()
7372 val = readl(priv->iface_base + MVPP22_SMI_MISC_CFG_REG); in mvpp2_init()
7374 writel(val, priv->iface_base + MVPP22_SMI_MISC_CFG_REG); in mvpp2_init()
7378 priv->aggr_txqs = devm_kcalloc(&pdev->dev, MVPP2_MAX_THREADS, in mvpp2_init()
7379 sizeof(*priv->aggr_txqs), in mvpp2_init()
7381 if (!priv->aggr_txqs) in mvpp2_init()
7382 return -ENOMEM; in mvpp2_init()
7385 priv->aggr_txqs[i].id = i; in mvpp2_init()
7386 priv->aggr_txqs[i].size = MVPP2_AGGR_TXQ_SIZE; in mvpp2_init()
7387 err = mvpp2_aggr_txq_init(pdev, &priv->aggr_txqs[i], i, priv); in mvpp2_init()
7393 if (priv->hw_version == MVPP21) { in mvpp2_init()
7398 if (priv->hw_version == MVPP23) in mvpp2_init()
7402 if (priv->hw_version == MVPP21) in mvpp2_init()
7404 priv->lms_base + MVPP2_MNG_EXTENDED_GLOBAL_CTRL_REG); in mvpp2_init()
7410 err = mvpp2_bm_init(&pdev->dev, priv); in mvpp2_init()
7433 if (has_acpi_companion(&pdev->dev)) in mvpp2_get_sram()
7434 dev_warn(&pdev->dev, "ACPI is too old, Flow control not supported\n"); in mvpp2_get_sram()
7436 dev_warn(&pdev->dev, "DT is too old, Flow control not supported\n"); in mvpp2_get_sram()
7440 base = devm_ioremap_resource(&pdev->dev, res); in mvpp2_get_sram()
7444 priv->cm3_base = base; in mvpp2_get_sram()
7456 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); in mvpp2_probe()
7458 return -ENOMEM; in mvpp2_probe()
7460 priv->hw_version = (unsigned long)device_get_match_data(&pdev->dev); in mvpp2_probe()
7465 if (priv->hw_version == MVPP21) in mvpp2_probe()
7472 if (priv->hw_version == MVPP21) { in mvpp2_probe()
7473 priv->lms_base = devm_platform_ioremap_resource(pdev, 1); in mvpp2_probe()
7474 if (IS_ERR(priv->lms_base)) in mvpp2_probe()
7475 return PTR_ERR(priv->lms_base); in mvpp2_probe()
7479 dev_err(&pdev->dev, "Invalid resource\n"); in mvpp2_probe()
7480 return -EINVAL; in mvpp2_probe()
7482 if (has_acpi_companion(&pdev->dev)) { in mvpp2_probe()
7484 * the ACPI, it can already appear as 'in-use' in mvpp2_probe()
7493 priv->iface_base = devm_ioremap_resource(&pdev->dev, res); in mvpp2_probe()
7494 if (IS_ERR(priv->iface_base)) in mvpp2_probe()
7495 return PTR_ERR(priv->iface_base); in mvpp2_probe()
7500 dev_warn(&pdev->dev, "Fail to alloc CM3 SRAM\n"); in mvpp2_probe()
7503 if (priv->cm3_base) in mvpp2_probe()
7504 priv->global_tx_fc = true; in mvpp2_probe()
7507 if (priv->hw_version >= MVPP22 && dev_of_node(&pdev->dev)) { in mvpp2_probe()
7508 priv->sysctrl_base = in mvpp2_probe()
7509 syscon_regmap_lookup_by_phandle(pdev->dev.of_node, in mvpp2_probe()
7510 "marvell,system-controller"); in mvpp2_probe()
7511 if (IS_ERR(priv->sysctrl_base)) in mvpp2_probe()
7517 priv->sysctrl_base = NULL; in mvpp2_probe()
7520 if (priv->hw_version >= MVPP22 && in mvpp2_probe()
7522 priv->percpu_pools = 1; in mvpp2_probe()
7527 priv->nthreads = min_t(unsigned int, num_present_cpus(), in mvpp2_probe()
7530 shared = num_present_cpus() - priv->nthreads; in mvpp2_probe()
7532 bitmap_set(&priv->lock_map, 0, in mvpp2_probe()
7538 addr_space_sz = (priv->hw_version == MVPP21 ? in mvpp2_probe()
7540 priv->swth_base[i] = base + i * addr_space_sz; in mvpp2_probe()
7543 if (priv->hw_version == MVPP21) in mvpp2_probe()
7544 priv->max_port_rxqs = 8; in mvpp2_probe()
7546 priv->max_port_rxqs = 32; in mvpp2_probe()
7548 if (dev_of_node(&pdev->dev)) { in mvpp2_probe()
7549 priv->pp_clk = devm_clk_get(&pdev->dev, "pp_clk"); in mvpp2_probe()
7550 if (IS_ERR(priv->pp_clk)) in mvpp2_probe()
7551 return PTR_ERR(priv->pp_clk); in mvpp2_probe()
7552 err = clk_prepare_enable(priv->pp_clk); in mvpp2_probe()
7556 priv->gop_clk = devm_clk_get(&pdev->dev, "gop_clk"); in mvpp2_probe()
7557 if (IS_ERR(priv->gop_clk)) { in mvpp2_probe()
7558 err = PTR_ERR(priv->gop_clk); in mvpp2_probe()
7561 err = clk_prepare_enable(priv->gop_clk); in mvpp2_probe()
7565 if (priv->hw_version >= MVPP22) { in mvpp2_probe()
7566 priv->mg_clk = devm_clk_get(&pdev->dev, "mg_clk"); in mvpp2_probe()
7567 if (IS_ERR(priv->mg_clk)) { in mvpp2_probe()
7568 err = PTR_ERR(priv->mg_clk); in mvpp2_probe()
7572 err = clk_prepare_enable(priv->mg_clk); in mvpp2_probe()
7576 priv->mg_core_clk = devm_clk_get_optional(&pdev->dev, "mg_core_clk"); in mvpp2_probe()
7577 if (IS_ERR(priv->mg_core_clk)) { in mvpp2_probe()
7578 err = PTR_ERR(priv->mg_core_clk); in mvpp2_probe()
7582 err = clk_prepare_enable(priv->mg_core_clk); in mvpp2_probe()
7587 priv->axi_clk = devm_clk_get_optional(&pdev->dev, "axi_clk"); in mvpp2_probe()
7588 if (IS_ERR(priv->axi_clk)) { in mvpp2_probe()
7589 err = PTR_ERR(priv->axi_clk); in mvpp2_probe()
7593 err = clk_prepare_enable(priv->axi_clk); in mvpp2_probe()
7598 priv->tclk = clk_get_rate(priv->pp_clk); in mvpp2_probe()
7600 err = device_property_read_u32(&pdev->dev, "clock-frequency", &priv->tclk); in mvpp2_probe()
7602 dev_err(&pdev->dev, "missing clock-frequency value\n"); in mvpp2_probe()
7607 if (priv->hw_version >= MVPP22) { in mvpp2_probe()
7608 err = dma_set_mask(&pdev->dev, MVPP2_DESC_DMA_MASK); in mvpp2_probe()
7616 err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32)); in mvpp2_probe()
7621 /* Map DTS-active ports. Should be done before FIFO mvpp2_init */ in mvpp2_probe()
7622 device_for_each_child_node_scoped(&pdev->dev, port_fwnode) { in mvpp2_probe()
7623 if (!fwnode_property_read_u32(port_fwnode, "port-id", &i)) in mvpp2_probe()
7624 priv->port_map |= BIT(i); in mvpp2_probe()
7628 priv->hw_version = MVPP23; in mvpp2_probe()
7631 spin_lock_init(&priv->mss_spinlock); in mvpp2_probe()
7636 dev_err(&pdev->dev, "failed to initialize controller\n"); in mvpp2_probe()
7640 err = mvpp22_tai_probe(&pdev->dev, priv); in mvpp2_probe()
7645 device_for_each_child_node_scoped(&pdev->dev, port_fwnode) { in mvpp2_probe()
7651 if (priv->port_count == 0) { in mvpp2_probe()
7652 dev_err(&pdev->dev, "no ports enabled\n"); in mvpp2_probe()
7653 err = -ENODEV; in mvpp2_probe()
7658 * packets counters) are 32-bit registers and could overflow quite in mvpp2_probe()
7660 * smallest packets (64B) will overflow a 32-bit counter in less than in mvpp2_probe()
7661 * 30 seconds. Then, use a workqueue to fill 64-bit counters. in mvpp2_probe()
7663 snprintf(priv->queue_name, sizeof(priv->queue_name), in mvpp2_probe()
7664 "stats-wq-%s%s", netdev_name(priv->port_list[0]->dev), in mvpp2_probe()
7665 priv->port_count > 1 ? "+" : ""); in mvpp2_probe()
7666 priv->stats_queue = create_singlethread_workqueue(priv->queue_name); in mvpp2_probe()
7667 if (!priv->stats_queue) { in mvpp2_probe()
7668 err = -ENOMEM; in mvpp2_probe()
7672 if (priv->global_tx_fc && priv->hw_version >= MVPP22) { in mvpp2_probe()
7675 …dev_warn(&pdev->dev, "Minimum of CM3 firmware 18.09 and chip revision B0 required for flow control… in mvpp2_probe()
7678 mvpp2_dbgfs_init(priv, pdev->name); in mvpp2_probe()
7684 for (i = 0; i < priv->port_count; i++) in mvpp2_probe()
7685 mvpp2_port_remove(priv->port_list[i]); in mvpp2_probe()
7687 clk_disable_unprepare(priv->axi_clk); in mvpp2_probe()
7689 clk_disable_unprepare(priv->mg_core_clk); in mvpp2_probe()
7691 clk_disable_unprepare(priv->mg_clk); in mvpp2_probe()
7693 clk_disable_unprepare(priv->gop_clk); in mvpp2_probe()
7695 clk_disable_unprepare(priv->pp_clk); in mvpp2_probe()
7706 for (i = 0; i < priv->port_count; i++) { in mvpp2_remove()
7707 mutex_destroy(&priv->port_list[i]->gather_stats_lock); in mvpp2_remove()
7708 mvpp2_port_remove(priv->port_list[i]); in mvpp2_remove()
7711 destroy_workqueue(priv->stats_queue); in mvpp2_remove()
7713 if (priv->percpu_pools) in mvpp2_remove()
7717 struct mvpp2_bm_pool *bm_pool = &priv->bm_pools[i]; in mvpp2_remove()
7719 mvpp2_bm_pool_destroy(&pdev->dev, priv, bm_pool); in mvpp2_remove()
7723 struct mvpp2_tx_queue *aggr_txq = &priv->aggr_txqs[i]; in mvpp2_remove()
7725 dma_free_coherent(&pdev->dev, in mvpp2_remove()
7727 aggr_txq->descs, in mvpp2_remove()
7728 aggr_txq->descs_dma); in mvpp2_remove()
7731 if (!dev_of_node(&pdev->dev)) in mvpp2_remove()
7734 clk_disable_unprepare(priv->axi_clk); in mvpp2_remove()
7735 clk_disable_unprepare(priv->mg_core_clk); in mvpp2_remove()
7736 clk_disable_unprepare(priv->mg_clk); in mvpp2_remove()
7737 clk_disable_unprepare(priv->pp_clk); in mvpp2_remove()
7738 clk_disable_unprepare(priv->gop_clk); in mvpp2_remove()
7743 .compatible = "marvell,armada-375-pp2",
7747 .compatible = "marvell,armada-7k-pp22",
7785 MODULE_DESCRIPTION("Marvell PPv2 Ethernet Driver - www.marvell.com");