Ioana Ciornei | 0bb29b2 | 2018-07-31 12:02:47 -0500 | [diff] [blame] | 1 | // SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2 | /* Copyright 2014-2016 Freescale Semiconductor Inc. |
Ioana Ciornei | 48c0481 | 2020-04-22 15:05:10 +0300 | [diff] [blame] | 3 | * Copyright 2016-2020 NXP |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 4 | */ |
| 5 | #include <linux/init.h> |
| 6 | #include <linux/module.h> |
| 7 | #include <linux/platform_device.h> |
| 8 | #include <linux/etherdevice.h> |
| 9 | #include <linux/of_net.h> |
| 10 | #include <linux/interrupt.h> |
| 11 | #include <linux/msi.h> |
| 12 | #include <linux/kthread.h> |
Ioana Radulescu | 08eb239 | 2017-05-24 07:13:27 -0500 | [diff] [blame] | 13 | #include <linux/iommu.h> |
Bogdan Purcareata | 6bd067c | 2018-02-05 08:07:42 -0600 | [diff] [blame] | 14 | #include <linux/fsl/mc.h> |
Ioana Ciocoi Radulescu | 7e273a8 | 2018-11-26 16:27:29 +0000 | [diff] [blame] | 15 | #include <linux/bpf.h> |
| 16 | #include <linux/bpf_trace.h> |
Yangbo Lu | d21c784 | 2020-09-18 17:07:59 +0800 | [diff] [blame] | 17 | #include <linux/fsl/ptp_qoriq.h> |
Yangbo Lu | c552118 | 2020-09-18 17:08:02 +0800 | [diff] [blame] | 18 | #include <linux/ptp_classify.h> |
Ioana Ciornei | 3657cda | 2020-07-21 19:38:25 +0300 | [diff] [blame] | 19 | #include <net/pkt_cls.h> |
Ioana Radulescu | 859f998 | 2018-04-26 18:23:47 +0800 | [diff] [blame] | 20 | #include <net/sock.h> |
| 21 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 22 | #include "dpaa2-eth.h" |
| 23 | |
Ioana Radulescu | 5636187 | 2017-04-28 04:50:32 -0500 | [diff] [blame] | 24 | /* CREATE_TRACE_POINTS only needs to be defined once. Other dpa files |
| 25 | * using trace events only need to #include <trace/events/sched.h> |
| 26 | */ |
| 27 | #define CREATE_TRACE_POINTS |
| 28 | #include "dpaa2-eth-trace.h" |
| 29 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 30 | MODULE_LICENSE("Dual BSD/GPL"); |
| 31 | MODULE_AUTHOR("Freescale Semiconductor, Inc"); |
| 32 | MODULE_DESCRIPTION("Freescale DPAA2 Ethernet Driver"); |
| 33 | |
Yangbo Lu | d21c784 | 2020-09-18 17:07:59 +0800 | [diff] [blame] | 34 | struct ptp_qoriq *dpaa2_ptp; |
| 35 | EXPORT_SYMBOL(dpaa2_ptp); |
| 36 | |
Ioana Radulescu | 08eb239 | 2017-05-24 07:13:27 -0500 | [diff] [blame] | 37 | static void *dpaa2_iova_to_virt(struct iommu_domain *domain, |
| 38 | dma_addr_t iova_addr) |
| 39 | { |
| 40 | phys_addr_t phys_addr; |
| 41 | |
| 42 | phys_addr = domain ? iommu_iova_to_phys(domain, iova_addr) : iova_addr; |
| 43 | |
| 44 | return phys_to_virt(phys_addr); |
| 45 | } |
| 46 | |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 47 | static void dpaa2_eth_validate_rx_csum(struct dpaa2_eth_priv *priv, |
| 48 | u32 fd_status, |
| 49 | struct sk_buff *skb) |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 50 | { |
| 51 | skb_checksum_none_assert(skb); |
| 52 | |
| 53 | /* HW checksum validation is disabled, nothing to do here */ |
| 54 | if (!(priv->net_dev->features & NETIF_F_RXCSUM)) |
| 55 | return; |
| 56 | |
| 57 | /* Read checksum validation bits */ |
| 58 | if (!((fd_status & DPAA2_FAS_L3CV) && |
| 59 | (fd_status & DPAA2_FAS_L4CV))) |
| 60 | return; |
| 61 | |
| 62 | /* Inform the stack there's no need to compute L3/L4 csum anymore */ |
| 63 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 64 | } |
| 65 | |
| 66 | /* Free a received FD. |
| 67 | * Not to be used for Tx conf FDs or on any other paths. |
| 68 | */ |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 69 | static void dpaa2_eth_free_rx_fd(struct dpaa2_eth_priv *priv, |
| 70 | const struct dpaa2_fd *fd, |
| 71 | void *vaddr) |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 72 | { |
| 73 | struct device *dev = priv->net_dev->dev.parent; |
| 74 | dma_addr_t addr = dpaa2_fd_get_addr(fd); |
| 75 | u8 fd_format = dpaa2_fd_get_format(fd); |
| 76 | struct dpaa2_sg_entry *sgt; |
| 77 | void *sg_vaddr; |
| 78 | int i; |
| 79 | |
| 80 | /* If single buffer frame, just free the data buffer */ |
| 81 | if (fd_format == dpaa2_fd_single) |
| 82 | goto free_buf; |
| 83 | else if (fd_format != dpaa2_fd_sg) |
| 84 | /* We don't support any other format */ |
| 85 | return; |
| 86 | |
Ioana Radulescu | 729d79b | 2017-10-11 08:29:48 -0500 | [diff] [blame] | 87 | /* For S/G frames, we first need to free all SG entries |
| 88 | * except the first one, which was taken care of already |
| 89 | */ |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 90 | sgt = vaddr + dpaa2_fd_get_offset(fd); |
Ioana Radulescu | 729d79b | 2017-10-11 08:29:48 -0500 | [diff] [blame] | 91 | for (i = 1; i < DPAA2_ETH_MAX_SG_ENTRIES; i++) { |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 92 | addr = dpaa2_sg_get_addr(&sgt[i]); |
Ioana Radulescu | 08eb239 | 2017-05-24 07:13:27 -0500 | [diff] [blame] | 93 | sg_vaddr = dpaa2_iova_to_virt(priv->iommu_domain, addr); |
Ioana Ciornei | efa6a7d | 2020-05-15 15:30:22 +0300 | [diff] [blame] | 94 | dma_unmap_page(dev, addr, priv->rx_buf_size, |
Ioana Ciocoi Radulescu | 27c8748 | 2019-02-04 17:00:35 +0000 | [diff] [blame] | 95 | DMA_BIDIRECTIONAL); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 96 | |
Ioana Ciocoi Radulescu | 27c8748 | 2019-02-04 17:00:35 +0000 | [diff] [blame] | 97 | free_pages((unsigned long)sg_vaddr, 0); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 98 | if (dpaa2_sg_is_final(&sgt[i])) |
| 99 | break; |
| 100 | } |
| 101 | |
| 102 | free_buf: |
Ioana Ciocoi Radulescu | 27c8748 | 2019-02-04 17:00:35 +0000 | [diff] [blame] | 103 | free_pages((unsigned long)vaddr, 0); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | /* Build a linear skb based on a single-buffer frame descriptor */ |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 107 | static struct sk_buff *dpaa2_eth_build_linear_skb(struct dpaa2_eth_channel *ch, |
| 108 | const struct dpaa2_fd *fd, |
| 109 | void *fd_vaddr) |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 110 | { |
| 111 | struct sk_buff *skb = NULL; |
| 112 | u16 fd_offset = dpaa2_fd_get_offset(fd); |
| 113 | u32 fd_length = dpaa2_fd_get_len(fd); |
| 114 | |
Ioana Radulescu | cbb3ea4 | 2017-10-11 08:29:44 -0500 | [diff] [blame] | 115 | ch->buf_count--; |
| 116 | |
Ioana Ciocoi Radulescu | 27c8748 | 2019-02-04 17:00:35 +0000 | [diff] [blame] | 117 | skb = build_skb(fd_vaddr, DPAA2_ETH_RX_BUF_RAW_SIZE); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 118 | if (unlikely(!skb)) |
| 119 | return NULL; |
| 120 | |
| 121 | skb_reserve(skb, fd_offset); |
| 122 | skb_put(skb, fd_length); |
| 123 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 124 | return skb; |
| 125 | } |
| 126 | |
| 127 | /* Build a non linear (fragmented) skb based on a S/G table */ |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 128 | static struct sk_buff *dpaa2_eth_build_frag_skb(struct dpaa2_eth_priv *priv, |
| 129 | struct dpaa2_eth_channel *ch, |
| 130 | struct dpaa2_sg_entry *sgt) |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 131 | { |
| 132 | struct sk_buff *skb = NULL; |
| 133 | struct device *dev = priv->net_dev->dev.parent; |
| 134 | void *sg_vaddr; |
| 135 | dma_addr_t sg_addr; |
| 136 | u16 sg_offset; |
| 137 | u32 sg_length; |
| 138 | struct page *page, *head_page; |
| 139 | int page_offset; |
| 140 | int i; |
| 141 | |
| 142 | for (i = 0; i < DPAA2_ETH_MAX_SG_ENTRIES; i++) { |
| 143 | struct dpaa2_sg_entry *sge = &sgt[i]; |
| 144 | |
| 145 | /* NOTE: We only support SG entries in dpaa2_sg_single format, |
| 146 | * but this is the only format we may receive from HW anyway |
| 147 | */ |
| 148 | |
| 149 | /* Get the address and length from the S/G entry */ |
| 150 | sg_addr = dpaa2_sg_get_addr(sge); |
Ioana Radulescu | 08eb239 | 2017-05-24 07:13:27 -0500 | [diff] [blame] | 151 | sg_vaddr = dpaa2_iova_to_virt(priv->iommu_domain, sg_addr); |
Ioana Ciornei | efa6a7d | 2020-05-15 15:30:22 +0300 | [diff] [blame] | 152 | dma_unmap_page(dev, sg_addr, priv->rx_buf_size, |
Ioana Ciocoi Radulescu | 27c8748 | 2019-02-04 17:00:35 +0000 | [diff] [blame] | 153 | DMA_BIDIRECTIONAL); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 154 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 155 | sg_length = dpaa2_sg_get_len(sge); |
| 156 | |
| 157 | if (i == 0) { |
| 158 | /* We build the skb around the first data buffer */ |
Ioana Ciocoi Radulescu | 27c8748 | 2019-02-04 17:00:35 +0000 | [diff] [blame] | 159 | skb = build_skb(sg_vaddr, DPAA2_ETH_RX_BUF_RAW_SIZE); |
Ioana Radulescu | cbb3ea4 | 2017-10-11 08:29:44 -0500 | [diff] [blame] | 160 | if (unlikely(!skb)) { |
Ioana Radulescu | 729d79b | 2017-10-11 08:29:48 -0500 | [diff] [blame] | 161 | /* Free the first SG entry now, since we already |
| 162 | * unmapped it and obtained the virtual address |
| 163 | */ |
Ioana Ciocoi Radulescu | 27c8748 | 2019-02-04 17:00:35 +0000 | [diff] [blame] | 164 | free_pages((unsigned long)sg_vaddr, 0); |
Ioana Radulescu | 729d79b | 2017-10-11 08:29:48 -0500 | [diff] [blame] | 165 | |
Ioana Radulescu | cbb3ea4 | 2017-10-11 08:29:44 -0500 | [diff] [blame] | 166 | /* We still need to subtract the buffers used |
| 167 | * by this FD from our software counter |
| 168 | */ |
| 169 | while (!dpaa2_sg_is_final(&sgt[i]) && |
| 170 | i < DPAA2_ETH_MAX_SG_ENTRIES) |
| 171 | i++; |
| 172 | break; |
| 173 | } |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 174 | |
| 175 | sg_offset = dpaa2_sg_get_offset(sge); |
| 176 | skb_reserve(skb, sg_offset); |
| 177 | skb_put(skb, sg_length); |
| 178 | } else { |
| 179 | /* Rest of the data buffers are stored as skb frags */ |
| 180 | page = virt_to_page(sg_vaddr); |
| 181 | head_page = virt_to_head_page(sg_vaddr); |
| 182 | |
| 183 | /* Offset in page (which may be compound). |
| 184 | * Data in subsequent SG entries is stored from the |
| 185 | * beginning of the buffer, so we don't need to add the |
| 186 | * sg_offset. |
| 187 | */ |
| 188 | page_offset = ((unsigned long)sg_vaddr & |
| 189 | (PAGE_SIZE - 1)) + |
| 190 | (page_address(page) - page_address(head_page)); |
| 191 | |
| 192 | skb_add_rx_frag(skb, i - 1, head_page, page_offset, |
Ioana Ciornei | efa6a7d | 2020-05-15 15:30:22 +0300 | [diff] [blame] | 193 | sg_length, priv->rx_buf_size); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | if (dpaa2_sg_is_final(sge)) |
| 197 | break; |
| 198 | } |
| 199 | |
Ioana Radulescu | b63baf7 | 2017-10-11 08:29:45 -0500 | [diff] [blame] | 200 | WARN_ONCE(i == DPAA2_ETH_MAX_SG_ENTRIES, "Final bit not set in SGT"); |
| 201 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 202 | /* Count all data buffers + SG table buffer */ |
| 203 | ch->buf_count -= i + 2; |
| 204 | |
| 205 | return skb; |
| 206 | } |
| 207 | |
Ioana Ciocoi Radulescu | 569375f | 2018-11-26 16:27:31 +0000 | [diff] [blame] | 208 | /* Free buffers acquired from the buffer pool or which were meant to |
| 209 | * be released in the pool |
| 210 | */ |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 211 | static void dpaa2_eth_free_bufs(struct dpaa2_eth_priv *priv, u64 *buf_array, |
| 212 | int count) |
Ioana Ciocoi Radulescu | 569375f | 2018-11-26 16:27:31 +0000 | [diff] [blame] | 213 | { |
| 214 | struct device *dev = priv->net_dev->dev.parent; |
| 215 | void *vaddr; |
| 216 | int i; |
| 217 | |
| 218 | for (i = 0; i < count; i++) { |
| 219 | vaddr = dpaa2_iova_to_virt(priv->iommu_domain, buf_array[i]); |
Ioana Ciornei | efa6a7d | 2020-05-15 15:30:22 +0300 | [diff] [blame] | 220 | dma_unmap_page(dev, buf_array[i], priv->rx_buf_size, |
Ioana Ciocoi Radulescu | 27c8748 | 2019-02-04 17:00:35 +0000 | [diff] [blame] | 221 | DMA_BIDIRECTIONAL); |
| 222 | free_pages((unsigned long)vaddr, 0); |
Ioana Ciocoi Radulescu | 569375f | 2018-11-26 16:27:31 +0000 | [diff] [blame] | 223 | } |
| 224 | } |
| 225 | |
Ioana Ciornei | 28d137c | 2021-04-02 12:55:30 +0300 | [diff] [blame] | 226 | static void dpaa2_eth_recycle_buf(struct dpaa2_eth_priv *priv, |
| 227 | struct dpaa2_eth_channel *ch, |
| 228 | dma_addr_t addr) |
Ioana Ciocoi Radulescu | 5d39dc2 | 2018-11-26 16:27:31 +0000 | [diff] [blame] | 229 | { |
Ioana Radulescu | ef17bd7 | 2019-10-07 14:38:28 +0300 | [diff] [blame] | 230 | int retries = 0; |
Ioana Ciocoi Radulescu | 5d39dc2 | 2018-11-26 16:27:31 +0000 | [diff] [blame] | 231 | int err; |
| 232 | |
Ioana Ciornei | 28d137c | 2021-04-02 12:55:30 +0300 | [diff] [blame] | 233 | ch->recycled_bufs[ch->recycled_bufs_cnt++] = addr; |
| 234 | if (ch->recycled_bufs_cnt < DPAA2_ETH_BUFS_PER_CMD) |
Ioana Ciocoi Radulescu | 5d39dc2 | 2018-11-26 16:27:31 +0000 | [diff] [blame] | 235 | return; |
| 236 | |
| 237 | while ((err = dpaa2_io_service_release(ch->dpio, priv->bpid, |
Ioana Ciornei | 28d137c | 2021-04-02 12:55:30 +0300 | [diff] [blame] | 238 | ch->recycled_bufs, |
| 239 | ch->recycled_bufs_cnt)) == -EBUSY) { |
Ioana Radulescu | ef17bd7 | 2019-10-07 14:38:28 +0300 | [diff] [blame] | 240 | if (retries++ >= DPAA2_ETH_SWP_BUSY_RETRIES) |
| 241 | break; |
Ioana Ciocoi Radulescu | 5d39dc2 | 2018-11-26 16:27:31 +0000 | [diff] [blame] | 242 | cpu_relax(); |
Ioana Radulescu | ef17bd7 | 2019-10-07 14:38:28 +0300 | [diff] [blame] | 243 | } |
Ioana Ciocoi Radulescu | 5d39dc2 | 2018-11-26 16:27:31 +0000 | [diff] [blame] | 244 | |
| 245 | if (err) { |
Ioana Ciornei | 28d137c | 2021-04-02 12:55:30 +0300 | [diff] [blame] | 246 | dpaa2_eth_free_bufs(priv, ch->recycled_bufs, ch->recycled_bufs_cnt); |
| 247 | ch->buf_count -= ch->recycled_bufs_cnt; |
Ioana Ciocoi Radulescu | 5d39dc2 | 2018-11-26 16:27:31 +0000 | [diff] [blame] | 248 | } |
| 249 | |
Ioana Ciornei | 28d137c | 2021-04-02 12:55:30 +0300 | [diff] [blame] | 250 | ch->recycled_bufs_cnt = 0; |
Ioana Ciocoi Radulescu | 5d39dc2 | 2018-11-26 16:27:31 +0000 | [diff] [blame] | 251 | } |
| 252 | |
Ioana Ciornei | 38c440b | 2020-05-06 20:47:17 +0300 | [diff] [blame] | 253 | static int dpaa2_eth_xdp_flush(struct dpaa2_eth_priv *priv, |
| 254 | struct dpaa2_eth_fq *fq, |
| 255 | struct dpaa2_eth_xdp_fds *xdp_fds) |
| 256 | { |
| 257 | int total_enqueued = 0, retries = 0, enqueued; |
| 258 | struct dpaa2_eth_drv_stats *percpu_extras; |
| 259 | int num_fds, err, max_retries; |
| 260 | struct dpaa2_fd *fds; |
| 261 | |
| 262 | percpu_extras = this_cpu_ptr(priv->percpu_extras); |
| 263 | |
| 264 | /* try to enqueue all the FDs until the max number of retries is hit */ |
| 265 | fds = xdp_fds->fds; |
| 266 | num_fds = xdp_fds->num; |
| 267 | max_retries = num_fds * DPAA2_ETH_ENQUEUE_RETRIES; |
| 268 | while (total_enqueued < num_fds && retries < max_retries) { |
| 269 | err = priv->enqueue(priv, fq, &fds[total_enqueued], |
| 270 | 0, num_fds - total_enqueued, &enqueued); |
| 271 | if (err == -EBUSY) { |
| 272 | percpu_extras->tx_portal_busy += ++retries; |
| 273 | continue; |
| 274 | } |
| 275 | total_enqueued += enqueued; |
| 276 | } |
| 277 | xdp_fds->num = 0; |
| 278 | |
| 279 | return total_enqueued; |
| 280 | } |
| 281 | |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 282 | static void dpaa2_eth_xdp_tx_flush(struct dpaa2_eth_priv *priv, |
| 283 | struct dpaa2_eth_channel *ch, |
| 284 | struct dpaa2_eth_fq *fq) |
Ioana Ciocoi Radulescu | 99e4352 | 2018-11-26 16:27:33 +0000 | [diff] [blame] | 285 | { |
Ioana Ciornei | 74a1c05 | 2020-05-13 16:55:46 +0300 | [diff] [blame] | 286 | struct rtnl_link_stats64 *percpu_stats; |
| 287 | struct dpaa2_fd *fds; |
| 288 | int enqueued, i; |
| 289 | |
| 290 | percpu_stats = this_cpu_ptr(priv->percpu_stats); |
| 291 | |
| 292 | // enqueue the array of XDP_TX frames |
| 293 | enqueued = dpaa2_eth_xdp_flush(priv, fq, &fq->xdp_tx_fds); |
| 294 | |
| 295 | /* update statistics */ |
| 296 | percpu_stats->tx_packets += enqueued; |
| 297 | fds = fq->xdp_tx_fds.fds; |
| 298 | for (i = 0; i < enqueued; i++) { |
| 299 | percpu_stats->tx_bytes += dpaa2_fd_get_len(&fds[i]); |
| 300 | ch->stats.xdp_tx++; |
| 301 | } |
| 302 | for (i = enqueued; i < fq->xdp_tx_fds.num; i++) { |
Ioana Ciornei | 28d137c | 2021-04-02 12:55:30 +0300 | [diff] [blame] | 303 | dpaa2_eth_recycle_buf(priv, ch, dpaa2_fd_get_addr(&fds[i])); |
Ioana Ciornei | 74a1c05 | 2020-05-13 16:55:46 +0300 | [diff] [blame] | 304 | percpu_stats->tx_errors++; |
| 305 | ch->stats.xdp_tx_err++; |
| 306 | } |
| 307 | fq->xdp_tx_fds.num = 0; |
| 308 | } |
| 309 | |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 310 | static void dpaa2_eth_xdp_enqueue(struct dpaa2_eth_priv *priv, |
| 311 | struct dpaa2_eth_channel *ch, |
| 312 | struct dpaa2_fd *fd, |
| 313 | void *buf_start, u16 queue_id) |
Ioana Ciornei | 74a1c05 | 2020-05-13 16:55:46 +0300 | [diff] [blame] | 314 | { |
Ioana Ciocoi Radulescu | 99e4352 | 2018-11-26 16:27:33 +0000 | [diff] [blame] | 315 | struct dpaa2_faead *faead; |
Ioana Ciornei | 74a1c05 | 2020-05-13 16:55:46 +0300 | [diff] [blame] | 316 | struct dpaa2_fd *dest_fd; |
| 317 | struct dpaa2_eth_fq *fq; |
Ioana Ciocoi Radulescu | 99e4352 | 2018-11-26 16:27:33 +0000 | [diff] [blame] | 318 | u32 ctrl, frc; |
Ioana Ciocoi Radulescu | 99e4352 | 2018-11-26 16:27:33 +0000 | [diff] [blame] | 319 | |
| 320 | /* Mark the egress frame hardware annotation area as valid */ |
| 321 | frc = dpaa2_fd_get_frc(fd); |
| 322 | dpaa2_fd_set_frc(fd, frc | DPAA2_FD_FRC_FAEADV); |
| 323 | dpaa2_fd_set_ctrl(fd, DPAA2_FD_CTRL_ASAL); |
| 324 | |
| 325 | /* Instruct hardware to release the FD buffer directly into |
| 326 | * the buffer pool once transmission is completed, instead of |
| 327 | * sending a Tx confirmation frame to us |
| 328 | */ |
| 329 | ctrl = DPAA2_FAEAD_A4V | DPAA2_FAEAD_A2V | DPAA2_FAEAD_EBDDV; |
| 330 | faead = dpaa2_get_faead(buf_start, false); |
| 331 | faead->ctrl = cpu_to_le32(ctrl); |
| 332 | faead->conf_fqid = 0; |
| 333 | |
| 334 | fq = &priv->fq[queue_id]; |
Ioana Ciornei | 74a1c05 | 2020-05-13 16:55:46 +0300 | [diff] [blame] | 335 | dest_fd = &fq->xdp_tx_fds.fds[fq->xdp_tx_fds.num++]; |
| 336 | memcpy(dest_fd, fd, sizeof(*dest_fd)); |
Ioana Ciocoi Radulescu | 99e4352 | 2018-11-26 16:27:33 +0000 | [diff] [blame] | 337 | |
Ioana Ciornei | 74a1c05 | 2020-05-13 16:55:46 +0300 | [diff] [blame] | 338 | if (fq->xdp_tx_fds.num < DEV_MAP_BULK_SIZE) |
| 339 | return; |
| 340 | |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 341 | dpaa2_eth_xdp_tx_flush(priv, ch, fq); |
Ioana Ciocoi Radulescu | 99e4352 | 2018-11-26 16:27:33 +0000 | [diff] [blame] | 342 | } |
| 343 | |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 344 | static u32 dpaa2_eth_run_xdp(struct dpaa2_eth_priv *priv, |
| 345 | struct dpaa2_eth_channel *ch, |
| 346 | struct dpaa2_eth_fq *rx_fq, |
| 347 | struct dpaa2_fd *fd, void *vaddr) |
Ioana Ciocoi Radulescu | 7e273a8 | 2018-11-26 16:27:29 +0000 | [diff] [blame] | 348 | { |
Ioana Ciocoi Radulescu | 5d39dc2 | 2018-11-26 16:27:31 +0000 | [diff] [blame] | 349 | dma_addr_t addr = dpaa2_fd_get_addr(fd); |
Ioana Ciocoi Radulescu | 7e273a8 | 2018-11-26 16:27:29 +0000 | [diff] [blame] | 350 | struct bpf_prog *xdp_prog; |
| 351 | struct xdp_buff xdp; |
| 352 | u32 xdp_act = XDP_PASS; |
Lorenzo Bianconi | be9df4a | 2020-12-22 22:09:29 +0100 | [diff] [blame] | 353 | int err, offset; |
Ioana Ciocoi Radulescu | 99e4352 | 2018-11-26 16:27:33 +0000 | [diff] [blame] | 354 | |
Ioana Ciocoi Radulescu | 7e273a8 | 2018-11-26 16:27:29 +0000 | [diff] [blame] | 355 | xdp_prog = READ_ONCE(ch->xdp.prog); |
| 356 | if (!xdp_prog) |
| 357 | goto out; |
| 358 | |
Lorenzo Bianconi | be9df4a | 2020-12-22 22:09:29 +0100 | [diff] [blame] | 359 | offset = dpaa2_fd_get_offset(fd) - XDP_PACKET_HEADROOM; |
| 360 | xdp_init_buff(&xdp, DPAA2_ETH_RX_BUF_RAW_SIZE - offset, &ch->xdp_rxq); |
| 361 | xdp_prepare_buff(&xdp, vaddr + offset, XDP_PACKET_HEADROOM, |
| 362 | dpaa2_fd_get_len(fd), false); |
Jesper Dangaard Brouer | 4a9b052 | 2020-05-14 12:49:53 +0200 | [diff] [blame] | 363 | |
Ioana Ciocoi Radulescu | 7e273a8 | 2018-11-26 16:27:29 +0000 | [diff] [blame] | 364 | xdp_act = bpf_prog_run_xdp(xdp_prog, &xdp); |
| 365 | |
Ioana Ciocoi Radulescu | 7b1eea1 | 2018-11-26 16:27:30 +0000 | [diff] [blame] | 366 | /* xdp.data pointer may have changed */ |
| 367 | dpaa2_fd_set_offset(fd, xdp.data - vaddr); |
| 368 | dpaa2_fd_set_len(fd, xdp.data_end - xdp.data); |
| 369 | |
Ioana Ciocoi Radulescu | 7e273a8 | 2018-11-26 16:27:29 +0000 | [diff] [blame] | 370 | switch (xdp_act) { |
| 371 | case XDP_PASS: |
| 372 | break; |
Ioana Ciocoi Radulescu | 99e4352 | 2018-11-26 16:27:33 +0000 | [diff] [blame] | 373 | case XDP_TX: |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 374 | dpaa2_eth_xdp_enqueue(priv, ch, fd, vaddr, rx_fq->flowid); |
Ioana Ciocoi Radulescu | 99e4352 | 2018-11-26 16:27:33 +0000 | [diff] [blame] | 375 | break; |
Ioana Ciocoi Radulescu | 7e273a8 | 2018-11-26 16:27:29 +0000 | [diff] [blame] | 376 | default: |
Paolo Abeni | c8064e5 | 2021-11-30 11:08:07 +0100 | [diff] [blame] | 377 | bpf_warn_invalid_xdp_action(priv->net_dev, xdp_prog, xdp_act); |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 378 | fallthrough; |
Ioana Ciocoi Radulescu | 7e273a8 | 2018-11-26 16:27:29 +0000 | [diff] [blame] | 379 | case XDP_ABORTED: |
| 380 | trace_xdp_exception(priv->net_dev, xdp_prog, xdp_act); |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 381 | fallthrough; |
Ioana Ciocoi Radulescu | 7e273a8 | 2018-11-26 16:27:29 +0000 | [diff] [blame] | 382 | case XDP_DROP: |
Ioana Ciornei | 28d137c | 2021-04-02 12:55:30 +0300 | [diff] [blame] | 383 | dpaa2_eth_recycle_buf(priv, ch, addr); |
Ioana Ciocoi Radulescu | a4a7b76 | 2018-11-26 16:27:34 +0000 | [diff] [blame] | 384 | ch->stats.xdp_drop++; |
Ioana Ciocoi Radulescu | 7e273a8 | 2018-11-26 16:27:29 +0000 | [diff] [blame] | 385 | break; |
Ioana Radulescu | d678be1 | 2019-03-01 17:47:24 +0000 | [diff] [blame] | 386 | case XDP_REDIRECT: |
| 387 | dma_unmap_page(priv->net_dev->dev.parent, addr, |
Ioana Ciornei | efa6a7d | 2020-05-15 15:30:22 +0300 | [diff] [blame] | 388 | priv->rx_buf_size, DMA_BIDIRECTIONAL); |
Ioana Radulescu | d678be1 | 2019-03-01 17:47:24 +0000 | [diff] [blame] | 389 | ch->buf_count--; |
Jesper Dangaard Brouer | 4a9b052 | 2020-05-14 12:49:53 +0200 | [diff] [blame] | 390 | |
| 391 | /* Allow redirect use of full headroom */ |
Ioana Radulescu | d678be1 | 2019-03-01 17:47:24 +0000 | [diff] [blame] | 392 | xdp.data_hard_start = vaddr; |
Jesper Dangaard Brouer | 4a9b052 | 2020-05-14 12:49:53 +0200 | [diff] [blame] | 393 | xdp.frame_sz = DPAA2_ETH_RX_BUF_RAW_SIZE; |
| 394 | |
Ioana Radulescu | d678be1 | 2019-03-01 17:47:24 +0000 | [diff] [blame] | 395 | err = xdp_do_redirect(priv->net_dev, &xdp, xdp_prog); |
Ioana Ciornei | e12be91 | 2021-02-11 21:51:22 +0200 | [diff] [blame] | 396 | if (unlikely(err)) { |
| 397 | addr = dma_map_page(priv->net_dev->dev.parent, |
| 398 | virt_to_page(vaddr), 0, |
| 399 | priv->rx_buf_size, DMA_BIDIRECTIONAL); |
| 400 | if (unlikely(dma_mapping_error(priv->net_dev->dev.parent, addr))) { |
| 401 | free_pages((unsigned long)vaddr, 0); |
| 402 | } else { |
| 403 | ch->buf_count++; |
Ioana Ciornei | 28d137c | 2021-04-02 12:55:30 +0300 | [diff] [blame] | 404 | dpaa2_eth_recycle_buf(priv, ch, addr); |
Ioana Ciornei | e12be91 | 2021-02-11 21:51:22 +0200 | [diff] [blame] | 405 | } |
Ioana Radulescu | d678be1 | 2019-03-01 17:47:24 +0000 | [diff] [blame] | 406 | ch->stats.xdp_drop++; |
Ioana Ciornei | e12be91 | 2021-02-11 21:51:22 +0200 | [diff] [blame] | 407 | } else { |
Ioana Radulescu | d678be1 | 2019-03-01 17:47:24 +0000 | [diff] [blame] | 408 | ch->stats.xdp_redirect++; |
Ioana Ciornei | e12be91 | 2021-02-11 21:51:22 +0200 | [diff] [blame] | 409 | } |
Ioana Radulescu | d678be1 | 2019-03-01 17:47:24 +0000 | [diff] [blame] | 410 | break; |
Ioana Ciocoi Radulescu | 7e273a8 | 2018-11-26 16:27:29 +0000 | [diff] [blame] | 411 | } |
| 412 | |
Ioana Radulescu | d678be1 | 2019-03-01 17:47:24 +0000 | [diff] [blame] | 413 | ch->xdp.res |= xdp_act; |
Ioana Ciocoi Radulescu | 7e273a8 | 2018-11-26 16:27:29 +0000 | [diff] [blame] | 414 | out: |
Ioana Ciocoi Radulescu | 7e273a8 | 2018-11-26 16:27:29 +0000 | [diff] [blame] | 415 | return xdp_act; |
| 416 | } |
| 417 | |
Ioana Ciornei | 50f8269 | 2021-04-02 12:55:31 +0300 | [diff] [blame] | 418 | static struct sk_buff *dpaa2_eth_copybreak(struct dpaa2_eth_channel *ch, |
| 419 | const struct dpaa2_fd *fd, |
| 420 | void *fd_vaddr) |
| 421 | { |
| 422 | u16 fd_offset = dpaa2_fd_get_offset(fd); |
Ioana Ciornei | 8ed3cef | 2021-04-02 12:55:32 +0300 | [diff] [blame] | 423 | struct dpaa2_eth_priv *priv = ch->priv; |
Ioana Ciornei | 50f8269 | 2021-04-02 12:55:31 +0300 | [diff] [blame] | 424 | u32 fd_length = dpaa2_fd_get_len(fd); |
| 425 | struct sk_buff *skb = NULL; |
| 426 | unsigned int skb_len; |
| 427 | |
Ioana Ciornei | 8ed3cef | 2021-04-02 12:55:32 +0300 | [diff] [blame] | 428 | if (fd_length > priv->rx_copybreak) |
Ioana Ciornei | 50f8269 | 2021-04-02 12:55:31 +0300 | [diff] [blame] | 429 | return NULL; |
| 430 | |
| 431 | skb_len = fd_length + dpaa2_eth_needed_headroom(NULL); |
| 432 | |
| 433 | skb = napi_alloc_skb(&ch->napi, skb_len); |
| 434 | if (!skb) |
| 435 | return NULL; |
| 436 | |
| 437 | skb_reserve(skb, dpaa2_eth_needed_headroom(NULL)); |
| 438 | skb_put(skb, fd_length); |
| 439 | |
| 440 | memcpy(skb->data, fd_vaddr + fd_offset, fd_length); |
| 441 | |
Ioana Ciornei | 8ed3cef | 2021-04-02 12:55:32 +0300 | [diff] [blame] | 442 | dpaa2_eth_recycle_buf(priv, ch, dpaa2_fd_get_addr(fd)); |
Ioana Ciornei | 50f8269 | 2021-04-02 12:55:31 +0300 | [diff] [blame] | 443 | |
| 444 | return skb; |
| 445 | } |
| 446 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 447 | /* Main Rx frame processing routine */ |
| 448 | static void dpaa2_eth_rx(struct dpaa2_eth_priv *priv, |
| 449 | struct dpaa2_eth_channel *ch, |
| 450 | const struct dpaa2_fd *fd, |
Ioana Ciocoi Radulescu | dbcdf72 | 2018-11-14 11:48:35 +0000 | [diff] [blame] | 451 | struct dpaa2_eth_fq *fq) |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 452 | { |
| 453 | dma_addr_t addr = dpaa2_fd_get_addr(fd); |
| 454 | u8 fd_format = dpaa2_fd_get_format(fd); |
| 455 | void *vaddr; |
| 456 | struct sk_buff *skb; |
| 457 | struct rtnl_link_stats64 *percpu_stats; |
Ioana Radulescu | 85047ab | 2017-04-28 04:50:31 -0500 | [diff] [blame] | 458 | struct dpaa2_eth_drv_stats *percpu_extras; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 459 | struct device *dev = priv->net_dev->dev.parent; |
| 460 | struct dpaa2_fas *fas; |
Ioana Radulescu | d695e76 | 2017-06-06 10:00:35 -0500 | [diff] [blame] | 461 | void *buf_data; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 462 | u32 status = 0; |
Ioana Ciocoi Radulescu | 7e273a8 | 2018-11-26 16:27:29 +0000 | [diff] [blame] | 463 | u32 xdp_act; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 464 | |
Ioana Radulescu | 5636187 | 2017-04-28 04:50:32 -0500 | [diff] [blame] | 465 | /* Tracing point */ |
| 466 | trace_dpaa2_rx_fd(priv->net_dev, fd); |
| 467 | |
Ioana Radulescu | 08eb239 | 2017-05-24 07:13:27 -0500 | [diff] [blame] | 468 | vaddr = dpaa2_iova_to_virt(priv->iommu_domain, addr); |
Ioana Ciornei | efa6a7d | 2020-05-15 15:30:22 +0300 | [diff] [blame] | 469 | dma_sync_single_for_cpu(dev, addr, priv->rx_buf_size, |
Ioana Ciocoi Radulescu | 18c2e77 | 2018-11-26 16:27:32 +0000 | [diff] [blame] | 470 | DMA_BIDIRECTIONAL); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 471 | |
Ioana Radulescu | 54ce891 | 2017-12-08 06:47:53 -0600 | [diff] [blame] | 472 | fas = dpaa2_get_fas(vaddr, false); |
Ioana Radulescu | d695e76 | 2017-06-06 10:00:35 -0500 | [diff] [blame] | 473 | prefetch(fas); |
| 474 | buf_data = vaddr + dpaa2_fd_get_offset(fd); |
| 475 | prefetch(buf_data); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 476 | |
| 477 | percpu_stats = this_cpu_ptr(priv->percpu_stats); |
Ioana Radulescu | 85047ab | 2017-04-28 04:50:31 -0500 | [diff] [blame] | 478 | percpu_extras = this_cpu_ptr(priv->percpu_extras); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 479 | |
| 480 | if (fd_format == dpaa2_fd_single) { |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 481 | xdp_act = dpaa2_eth_run_xdp(priv, ch, fq, (struct dpaa2_fd *)fd, vaddr); |
Ioana Ciocoi Radulescu | 7e273a8 | 2018-11-26 16:27:29 +0000 | [diff] [blame] | 482 | if (xdp_act != XDP_PASS) { |
| 483 | percpu_stats->rx_packets++; |
| 484 | percpu_stats->rx_bytes += dpaa2_fd_get_len(fd); |
| 485 | return; |
| 486 | } |
| 487 | |
Ioana Ciornei | 50f8269 | 2021-04-02 12:55:31 +0300 | [diff] [blame] | 488 | skb = dpaa2_eth_copybreak(ch, fd, vaddr); |
| 489 | if (!skb) { |
| 490 | dma_unmap_page(dev, addr, priv->rx_buf_size, |
| 491 | DMA_BIDIRECTIONAL); |
| 492 | skb = dpaa2_eth_build_linear_skb(ch, fd, vaddr); |
| 493 | } |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 494 | } else if (fd_format == dpaa2_fd_sg) { |
Ioana Ciocoi Radulescu | 7e273a8 | 2018-11-26 16:27:29 +0000 | [diff] [blame] | 495 | WARN_ON(priv->xdp_prog); |
| 496 | |
Ioana Ciornei | efa6a7d | 2020-05-15 15:30:22 +0300 | [diff] [blame] | 497 | dma_unmap_page(dev, addr, priv->rx_buf_size, |
Ioana Ciocoi Radulescu | 27c8748 | 2019-02-04 17:00:35 +0000 | [diff] [blame] | 498 | DMA_BIDIRECTIONAL); |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 499 | skb = dpaa2_eth_build_frag_skb(priv, ch, buf_data); |
Ioana Ciocoi Radulescu | 27c8748 | 2019-02-04 17:00:35 +0000 | [diff] [blame] | 500 | free_pages((unsigned long)vaddr, 0); |
Ioana Radulescu | 85047ab | 2017-04-28 04:50:31 -0500 | [diff] [blame] | 501 | percpu_extras->rx_sg_frames++; |
| 502 | percpu_extras->rx_sg_bytes += dpaa2_fd_get_len(fd); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 503 | } else { |
| 504 | /* We don't support any other format */ |
| 505 | goto err_frame_format; |
| 506 | } |
| 507 | |
| 508 | if (unlikely(!skb)) |
| 509 | goto err_build_skb; |
| 510 | |
| 511 | prefetch(skb->data); |
| 512 | |
Ioana Radulescu | 859f998 | 2018-04-26 18:23:47 +0800 | [diff] [blame] | 513 | /* Get the timestamp value */ |
| 514 | if (priv->rx_tstamp) { |
| 515 | struct skb_shared_hwtstamps *shhwtstamps = skb_hwtstamps(skb); |
| 516 | __le64 *ts = dpaa2_get_ts(vaddr, false); |
| 517 | u64 ns; |
| 518 | |
| 519 | memset(shhwtstamps, 0, sizeof(*shhwtstamps)); |
| 520 | |
| 521 | ns = DPAA2_PTP_CLK_PERIOD_NS * le64_to_cpup(ts); |
| 522 | shhwtstamps->hwtstamp = ns_to_ktime(ns); |
| 523 | } |
| 524 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 525 | /* Check if we need to validate the L4 csum */ |
| 526 | if (likely(dpaa2_fd_get_frc(fd) & DPAA2_FD_FRC_FASV)) { |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 527 | status = le32_to_cpu(fas->status); |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 528 | dpaa2_eth_validate_rx_csum(priv, status, skb); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 529 | } |
| 530 | |
| 531 | skb->protocol = eth_type_trans(skb, priv->net_dev); |
Ioana Ciocoi Radulescu | dbcdf72 | 2018-11-14 11:48:35 +0000 | [diff] [blame] | 532 | skb_record_rx_queue(skb, fq->flowid); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 533 | |
| 534 | percpu_stats->rx_packets++; |
| 535 | percpu_stats->rx_bytes += dpaa2_fd_get_len(fd); |
Ioana Ciornei | fc398be | 2021-10-15 12:01:27 +0300 | [diff] [blame] | 536 | ch->stats.bytes_per_cdan += dpaa2_fd_get_len(fd); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 537 | |
Ioana Ciornei | 0a25d92 | 2019-03-25 13:42:39 +0000 | [diff] [blame] | 538 | list_add_tail(&skb->list, ch->rx_list); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 539 | |
| 540 | return; |
| 541 | |
| 542 | err_build_skb: |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 543 | dpaa2_eth_free_rx_fd(priv, fd, vaddr); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 544 | err_frame_format: |
| 545 | percpu_stats->rx_dropped++; |
| 546 | } |
| 547 | |
Ioana Ciornei | 061d631 | 2020-10-01 18:11:48 +0300 | [diff] [blame] | 548 | /* Processing of Rx frames received on the error FQ |
| 549 | * We check and print the error bits and then free the frame |
| 550 | */ |
| 551 | static void dpaa2_eth_rx_err(struct dpaa2_eth_priv *priv, |
| 552 | struct dpaa2_eth_channel *ch, |
| 553 | const struct dpaa2_fd *fd, |
| 554 | struct dpaa2_eth_fq *fq __always_unused) |
| 555 | { |
| 556 | struct device *dev = priv->net_dev->dev.parent; |
| 557 | dma_addr_t addr = dpaa2_fd_get_addr(fd); |
| 558 | u8 fd_format = dpaa2_fd_get_format(fd); |
| 559 | struct rtnl_link_stats64 *percpu_stats; |
| 560 | struct dpaa2_eth_trap_item *trap_item; |
| 561 | struct dpaa2_fapr *fapr; |
| 562 | struct sk_buff *skb; |
| 563 | void *buf_data; |
| 564 | void *vaddr; |
| 565 | |
| 566 | vaddr = dpaa2_iova_to_virt(priv->iommu_domain, addr); |
| 567 | dma_sync_single_for_cpu(dev, addr, priv->rx_buf_size, |
| 568 | DMA_BIDIRECTIONAL); |
| 569 | |
| 570 | buf_data = vaddr + dpaa2_fd_get_offset(fd); |
| 571 | |
| 572 | if (fd_format == dpaa2_fd_single) { |
| 573 | dma_unmap_page(dev, addr, priv->rx_buf_size, |
| 574 | DMA_BIDIRECTIONAL); |
| 575 | skb = dpaa2_eth_build_linear_skb(ch, fd, vaddr); |
| 576 | } else if (fd_format == dpaa2_fd_sg) { |
| 577 | dma_unmap_page(dev, addr, priv->rx_buf_size, |
| 578 | DMA_BIDIRECTIONAL); |
| 579 | skb = dpaa2_eth_build_frag_skb(priv, ch, buf_data); |
| 580 | free_pages((unsigned long)vaddr, 0); |
| 581 | } else { |
| 582 | /* We don't support any other format */ |
| 583 | dpaa2_eth_free_rx_fd(priv, fd, vaddr); |
| 584 | goto err_frame_format; |
| 585 | } |
| 586 | |
| 587 | fapr = dpaa2_get_fapr(vaddr, false); |
| 588 | trap_item = dpaa2_eth_dl_get_trap(priv, fapr); |
| 589 | if (trap_item) |
| 590 | devlink_trap_report(priv->devlink, skb, trap_item->trap_ctx, |
| 591 | &priv->devlink_port, NULL); |
| 592 | consume_skb(skb); |
| 593 | |
| 594 | err_frame_format: |
| 595 | percpu_stats = this_cpu_ptr(priv->percpu_stats); |
| 596 | percpu_stats->rx_errors++; |
| 597 | ch->buf_count--; |
| 598 | } |
| 599 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 600 | /* Consume all frames pull-dequeued into the store. This is the simplest way to |
| 601 | * make sure we don't accidentally issue another volatile dequeue which would |
| 602 | * overwrite (leak) frames already in the store. |
| 603 | * |
| 604 | * Observance of NAPI budget is not our concern, leaving that to the caller. |
| 605 | */ |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 606 | static int dpaa2_eth_consume_frames(struct dpaa2_eth_channel *ch, |
| 607 | struct dpaa2_eth_fq **src) |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 608 | { |
| 609 | struct dpaa2_eth_priv *priv = ch->priv; |
Ioana Ciocoi Radulescu | 68049a5 | 2018-10-08 14:16:31 +0000 | [diff] [blame] | 610 | struct dpaa2_eth_fq *fq = NULL; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 611 | struct dpaa2_dq *dq; |
| 612 | const struct dpaa2_fd *fd; |
Ioana Radulescu | ef17bd7 | 2019-10-07 14:38:28 +0300 | [diff] [blame] | 613 | int cleaned = 0, retries = 0; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 614 | int is_last; |
| 615 | |
| 616 | do { |
| 617 | dq = dpaa2_io_store_next(ch->store, &is_last); |
| 618 | if (unlikely(!dq)) { |
| 619 | /* If we're here, we *must* have placed a |
| 620 | * volatile dequeue comnmand, so keep reading through |
| 621 | * the store until we get some sort of valid response |
| 622 | * token (either a valid frame or an "empty dequeue") |
| 623 | */ |
Ioana Radulescu | ef17bd7 | 2019-10-07 14:38:28 +0300 | [diff] [blame] | 624 | if (retries++ >= DPAA2_ETH_SWP_BUSY_RETRIES) { |
| 625 | netdev_err_once(priv->net_dev, |
| 626 | "Unable to read a valid dequeue response\n"); |
| 627 | return -ETIMEDOUT; |
| 628 | } |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 629 | continue; |
| 630 | } |
| 631 | |
| 632 | fd = dpaa2_dq_fd(dq); |
Ioana Radulescu | 75c583a | 2018-02-26 10:28:06 -0600 | [diff] [blame] | 633 | fq = (struct dpaa2_eth_fq *)(uintptr_t)dpaa2_dq_fqd_ctx(dq); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 634 | |
Ioana Ciocoi Radulescu | dbcdf72 | 2018-11-14 11:48:35 +0000 | [diff] [blame] | 635 | fq->consume(priv, ch, fd, fq); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 636 | cleaned++; |
Ioana Radulescu | ef17bd7 | 2019-10-07 14:38:28 +0300 | [diff] [blame] | 637 | retries = 0; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 638 | } while (!is_last); |
| 639 | |
Ioana Ciocoi Radulescu | 68049a5 | 2018-10-08 14:16:31 +0000 | [diff] [blame] | 640 | if (!cleaned) |
| 641 | return 0; |
| 642 | |
| 643 | fq->stats.frames += cleaned; |
Ioana Ciornei | 460fd83 | 2020-04-24 12:33:18 +0300 | [diff] [blame] | 644 | ch->stats.frames += cleaned; |
Ioana Ciornei | fc398be | 2021-10-15 12:01:27 +0300 | [diff] [blame] | 645 | ch->stats.frames_per_cdan += cleaned; |
Ioana Ciocoi Radulescu | 68049a5 | 2018-10-08 14:16:31 +0000 | [diff] [blame] | 646 | |
| 647 | /* A dequeue operation only pulls frames from a single queue |
Ioana Ciocoi Radulescu | 569dac6 | 2018-11-14 11:48:36 +0000 | [diff] [blame] | 648 | * into the store. Return the frame queue as an out param. |
Ioana Ciocoi Radulescu | 68049a5 | 2018-10-08 14:16:31 +0000 | [diff] [blame] | 649 | */ |
Ioana Ciocoi Radulescu | 569dac6 | 2018-11-14 11:48:36 +0000 | [diff] [blame] | 650 | if (src) |
| 651 | *src = fq; |
Ioana Ciocoi Radulescu | 68049a5 | 2018-10-08 14:16:31 +0000 | [diff] [blame] | 652 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 653 | return cleaned; |
| 654 | } |
| 655 | |
Yangbo Lu | c552118 | 2020-09-18 17:08:02 +0800 | [diff] [blame] | 656 | static int dpaa2_eth_ptp_parse(struct sk_buff *skb, |
| 657 | u8 *msgtype, u8 *twostep, u8 *udp, |
| 658 | u16 *correction_offset, |
| 659 | u16 *origintimestamp_offset) |
Ioana Radulescu | 859f998 | 2018-04-26 18:23:47 +0800 | [diff] [blame] | 660 | { |
Yangbo Lu | c552118 | 2020-09-18 17:08:02 +0800 | [diff] [blame] | 661 | unsigned int ptp_class; |
| 662 | struct ptp_header *hdr; |
| 663 | unsigned int type; |
| 664 | u8 *base; |
| 665 | |
| 666 | ptp_class = ptp_classify_raw(skb); |
| 667 | if (ptp_class == PTP_CLASS_NONE) |
| 668 | return -EINVAL; |
| 669 | |
| 670 | hdr = ptp_parse_header(skb, ptp_class); |
| 671 | if (!hdr) |
| 672 | return -EINVAL; |
| 673 | |
| 674 | *msgtype = ptp_get_msgtype(hdr, ptp_class); |
| 675 | *twostep = hdr->flag_field[0] & 0x2; |
| 676 | |
| 677 | type = ptp_class & PTP_CLASS_PMASK; |
| 678 | if (type == PTP_CLASS_IPV4 || |
| 679 | type == PTP_CLASS_IPV6) |
| 680 | *udp = 1; |
| 681 | else |
| 682 | *udp = 0; |
| 683 | |
| 684 | base = skb_mac_header(skb); |
| 685 | *correction_offset = (u8 *)&hdr->correction - base; |
| 686 | *origintimestamp_offset = (u8 *)hdr + sizeof(struct ptp_header) - base; |
| 687 | |
| 688 | return 0; |
| 689 | } |
| 690 | |
| 691 | /* Configure the egress frame annotation for timestamp update */ |
| 692 | static void dpaa2_eth_enable_tx_tstamp(struct dpaa2_eth_priv *priv, |
| 693 | struct dpaa2_fd *fd, |
| 694 | void *buf_start, |
| 695 | struct sk_buff *skb) |
| 696 | { |
| 697 | struct ptp_tstamp origin_timestamp; |
| 698 | struct dpni_single_step_cfg cfg; |
| 699 | u8 msgtype, twostep, udp; |
Ioana Radulescu | 859f998 | 2018-04-26 18:23:47 +0800 | [diff] [blame] | 700 | struct dpaa2_faead *faead; |
Yangbo Lu | c552118 | 2020-09-18 17:08:02 +0800 | [diff] [blame] | 701 | struct dpaa2_fas *fas; |
| 702 | struct timespec64 ts; |
| 703 | u16 offset1, offset2; |
Ioana Radulescu | 859f998 | 2018-04-26 18:23:47 +0800 | [diff] [blame] | 704 | u32 ctrl, frc; |
Yangbo Lu | c552118 | 2020-09-18 17:08:02 +0800 | [diff] [blame] | 705 | __le64 *ns; |
| 706 | u8 *data; |
Ioana Radulescu | 859f998 | 2018-04-26 18:23:47 +0800 | [diff] [blame] | 707 | |
| 708 | /* Mark the egress frame annotation area as valid */ |
| 709 | frc = dpaa2_fd_get_frc(fd); |
| 710 | dpaa2_fd_set_frc(fd, frc | DPAA2_FD_FRC_FAEADV); |
| 711 | |
| 712 | /* Set hardware annotation size */ |
| 713 | ctrl = dpaa2_fd_get_ctrl(fd); |
| 714 | dpaa2_fd_set_ctrl(fd, ctrl | DPAA2_FD_CTRL_ASAL); |
| 715 | |
| 716 | /* enable UPD (update prepanded data) bit in FAEAD field of |
| 717 | * hardware frame annotation area |
| 718 | */ |
| 719 | ctrl = DPAA2_FAEAD_A2V | DPAA2_FAEAD_UPDV | DPAA2_FAEAD_UPD; |
| 720 | faead = dpaa2_get_faead(buf_start, true); |
| 721 | faead->ctrl = cpu_to_le32(ctrl); |
Yangbo Lu | c552118 | 2020-09-18 17:08:02 +0800 | [diff] [blame] | 722 | |
| 723 | if (skb->cb[0] == TX_TSTAMP_ONESTEP_SYNC) { |
| 724 | if (dpaa2_eth_ptp_parse(skb, &msgtype, &twostep, &udp, |
| 725 | &offset1, &offset2) || |
Christian Eggers | 6b6817c | 2020-11-20 09:41:05 +0100 | [diff] [blame] | 726 | msgtype != PTP_MSGTYPE_SYNC || twostep) { |
Yangbo Lu | c552118 | 2020-09-18 17:08:02 +0800 | [diff] [blame] | 727 | WARN_ONCE(1, "Bad packet for one-step timestamping\n"); |
| 728 | return; |
| 729 | } |
| 730 | |
| 731 | /* Mark the frame annotation status as valid */ |
| 732 | frc = dpaa2_fd_get_frc(fd); |
| 733 | dpaa2_fd_set_frc(fd, frc | DPAA2_FD_FRC_FASV); |
| 734 | |
| 735 | /* Mark the PTP flag for one step timestamping */ |
| 736 | fas = dpaa2_get_fas(buf_start, true); |
| 737 | fas->status = cpu_to_le32(DPAA2_FAS_PTP); |
| 738 | |
| 739 | dpaa2_ptp->caps.gettime64(&dpaa2_ptp->caps, &ts); |
| 740 | ns = dpaa2_get_ts(buf_start, true); |
| 741 | *ns = cpu_to_le64(timespec64_to_ns(&ts) / |
| 742 | DPAA2_PTP_CLK_PERIOD_NS); |
| 743 | |
| 744 | /* Update current time to PTP message originTimestamp field */ |
| 745 | ns_to_ptp_tstamp(&origin_timestamp, le64_to_cpup(ns)); |
| 746 | data = skb_mac_header(skb); |
| 747 | *(__be16 *)(data + offset2) = htons(origin_timestamp.sec_msb); |
| 748 | *(__be32 *)(data + offset2 + 2) = |
| 749 | htonl(origin_timestamp.sec_lsb); |
| 750 | *(__be32 *)(data + offset2 + 6) = htonl(origin_timestamp.nsec); |
| 751 | |
| 752 | cfg.en = 1; |
| 753 | cfg.ch_update = udp; |
| 754 | cfg.offset = offset1; |
| 755 | cfg.peer_delay = 0; |
| 756 | |
| 757 | if (dpni_set_single_step_cfg(priv->mc_io, 0, priv->mc_token, |
| 758 | &cfg)) |
| 759 | WARN_ONCE(1, "Failed to set single step register"); |
| 760 | } |
Ioana Radulescu | 859f998 | 2018-04-26 18:23:47 +0800 | [diff] [blame] | 761 | } |
| 762 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 763 | /* Create a frame descriptor based on a fragmented skb */ |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 764 | static int dpaa2_eth_build_sg_fd(struct dpaa2_eth_priv *priv, |
| 765 | struct sk_buff *skb, |
Yangbo Lu | 64a965d | 2020-09-18 17:08:00 +0800 | [diff] [blame] | 766 | struct dpaa2_fd *fd, |
| 767 | void **swa_addr) |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 768 | { |
| 769 | struct device *dev = priv->net_dev->dev.parent; |
| 770 | void *sgt_buf = NULL; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 771 | dma_addr_t addr; |
| 772 | int nr_frags = skb_shinfo(skb)->nr_frags; |
| 773 | struct dpaa2_sg_entry *sgt; |
| 774 | int i, err; |
| 775 | int sgt_buf_size; |
| 776 | struct scatterlist *scl, *crt_scl; |
| 777 | int num_sg; |
| 778 | int num_dma_bufs; |
| 779 | struct dpaa2_eth_swa *swa; |
| 780 | |
| 781 | /* Create and map scatterlist. |
| 782 | * We don't advertise NETIF_F_FRAGLIST, so skb_to_sgvec() will not have |
| 783 | * to go beyond nr_frags+1. |
| 784 | * Note: We don't support chained scatterlists |
| 785 | */ |
| 786 | if (unlikely(PAGE_SIZE / sizeof(struct scatterlist) < nr_frags + 1)) |
| 787 | return -EINVAL; |
| 788 | |
Julia Lawall | d4ceb8d | 2020-09-20 13:26:15 +0200 | [diff] [blame] | 789 | scl = kmalloc_array(nr_frags + 1, sizeof(struct scatterlist), GFP_ATOMIC); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 790 | if (unlikely(!scl)) |
| 791 | return -ENOMEM; |
| 792 | |
| 793 | sg_init_table(scl, nr_frags + 1); |
| 794 | num_sg = skb_to_sgvec(skb, scl, 0, skb->len); |
Ioana Ciornei | 37fbbdda | 2020-06-24 14:34:18 +0300 | [diff] [blame] | 795 | if (unlikely(num_sg < 0)) { |
| 796 | err = -ENOMEM; |
| 797 | goto dma_map_sg_failed; |
| 798 | } |
Ioana Radulescu | 1e5fa9e | 2017-05-24 07:13:28 -0500 | [diff] [blame] | 799 | num_dma_bufs = dma_map_sg(dev, scl, num_sg, DMA_BIDIRECTIONAL); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 800 | if (unlikely(!num_dma_bufs)) { |
| 801 | err = -ENOMEM; |
| 802 | goto dma_map_sg_failed; |
| 803 | } |
| 804 | |
| 805 | /* Prepare the HW SGT structure */ |
| 806 | sgt_buf_size = priv->tx_data_offset + |
Ioana Radulescu | fa722c0 | 2018-03-23 08:44:12 -0500 | [diff] [blame] | 807 | sizeof(struct dpaa2_sg_entry) * num_dma_bufs; |
Kevin Hao | d0dfbb9 | 2021-02-04 18:56:38 +0800 | [diff] [blame] | 808 | sgt_buf = napi_alloc_frag_align(sgt_buf_size, DPAA2_ETH_TX_BUF_ALIGN); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 809 | if (unlikely(!sgt_buf)) { |
| 810 | err = -ENOMEM; |
| 811 | goto sgt_buf_alloc_failed; |
| 812 | } |
Ioana Radulescu | 6a9bbe5 | 2018-03-14 15:04:51 -0500 | [diff] [blame] | 813 | memset(sgt_buf, 0, sgt_buf_size); |
| 814 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 815 | sgt = (struct dpaa2_sg_entry *)(sgt_buf + priv->tx_data_offset); |
| 816 | |
| 817 | /* Fill in the HW SGT structure. |
| 818 | * |
| 819 | * sgt_buf is zeroed out, so the following fields are implicit |
| 820 | * in all sgt entries: |
| 821 | * - offset is 0 |
| 822 | * - format is 'dpaa2_sg_single' |
| 823 | */ |
| 824 | for_each_sg(scl, crt_scl, num_dma_bufs, i) { |
| 825 | dpaa2_sg_set_addr(&sgt[i], sg_dma_address(crt_scl)); |
| 826 | dpaa2_sg_set_len(&sgt[i], sg_dma_len(crt_scl)); |
| 827 | } |
| 828 | dpaa2_sg_set_final(&sgt[i - 1], true); |
| 829 | |
| 830 | /* Store the skb backpointer in the SGT buffer. |
| 831 | * Fit the scatterlist and the number of buffers alongside the |
| 832 | * skb backpointer in the software annotation area. We'll need |
| 833 | * all of them on Tx Conf. |
| 834 | */ |
Yangbo Lu | 64a965d | 2020-09-18 17:08:00 +0800 | [diff] [blame] | 835 | *swa_addr = (void *)sgt_buf; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 836 | swa = (struct dpaa2_eth_swa *)sgt_buf; |
Ioana Radulescu | e3fdf6b | 2019-03-01 17:47:23 +0000 | [diff] [blame] | 837 | swa->type = DPAA2_ETH_SWA_SG; |
| 838 | swa->sg.skb = skb; |
| 839 | swa->sg.scl = scl; |
| 840 | swa->sg.num_sg = num_sg; |
| 841 | swa->sg.sgt_size = sgt_buf_size; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 842 | |
| 843 | /* Separately map the SGT buffer */ |
Ioana Radulescu | 1e5fa9e | 2017-05-24 07:13:28 -0500 | [diff] [blame] | 844 | addr = dma_map_single(dev, sgt_buf, sgt_buf_size, DMA_BIDIRECTIONAL); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 845 | if (unlikely(dma_mapping_error(dev, addr))) { |
| 846 | err = -ENOMEM; |
| 847 | goto dma_map_single_failed; |
| 848 | } |
| 849 | dpaa2_fd_set_offset(fd, priv->tx_data_offset); |
| 850 | dpaa2_fd_set_format(fd, dpaa2_fd_sg); |
| 851 | dpaa2_fd_set_addr(fd, addr); |
| 852 | dpaa2_fd_set_len(fd, skb->len); |
Ioana Radulescu | b948c8c | 2018-10-12 16:27:40 +0000 | [diff] [blame] | 853 | dpaa2_fd_set_ctrl(fd, FD_CTRL_PTA); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 854 | |
| 855 | return 0; |
| 856 | |
| 857 | dma_map_single_failed: |
Ioana Radulescu | 6a9bbe5 | 2018-03-14 15:04:51 -0500 | [diff] [blame] | 858 | skb_free_frag(sgt_buf); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 859 | sgt_buf_alloc_failed: |
Ioana Radulescu | 1e5fa9e | 2017-05-24 07:13:28 -0500 | [diff] [blame] | 860 | dma_unmap_sg(dev, scl, num_sg, DMA_BIDIRECTIONAL); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 861 | dma_map_sg_failed: |
| 862 | kfree(scl); |
| 863 | return err; |
| 864 | } |
| 865 | |
Ioana Ciornei | d70446e | 2020-06-29 21:47:11 +0300 | [diff] [blame] | 866 | /* Create a SG frame descriptor based on a linear skb. |
| 867 | * |
| 868 | * This function is used on the Tx path when the skb headroom is not large |
| 869 | * enough for the HW requirements, thus instead of realloc-ing the skb we |
| 870 | * create a SG frame descriptor with only one entry. |
| 871 | */ |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 872 | static int dpaa2_eth_build_sg_fd_single_buf(struct dpaa2_eth_priv *priv, |
| 873 | struct sk_buff *skb, |
Yangbo Lu | 64a965d | 2020-09-18 17:08:00 +0800 | [diff] [blame] | 874 | struct dpaa2_fd *fd, |
| 875 | void **swa_addr) |
Ioana Ciornei | d70446e | 2020-06-29 21:47:11 +0300 | [diff] [blame] | 876 | { |
| 877 | struct device *dev = priv->net_dev->dev.parent; |
| 878 | struct dpaa2_eth_sgt_cache *sgt_cache; |
| 879 | struct dpaa2_sg_entry *sgt; |
| 880 | struct dpaa2_eth_swa *swa; |
| 881 | dma_addr_t addr, sgt_addr; |
| 882 | void *sgt_buf = NULL; |
| 883 | int sgt_buf_size; |
| 884 | int err; |
| 885 | |
| 886 | /* Prepare the HW SGT structure */ |
| 887 | sgt_cache = this_cpu_ptr(priv->sgt_cache); |
| 888 | sgt_buf_size = priv->tx_data_offset + sizeof(struct dpaa2_sg_entry); |
| 889 | |
| 890 | if (sgt_cache->count == 0) |
| 891 | sgt_buf = kzalloc(sgt_buf_size + DPAA2_ETH_TX_BUF_ALIGN, |
| 892 | GFP_ATOMIC); |
| 893 | else |
| 894 | sgt_buf = sgt_cache->buf[--sgt_cache->count]; |
| 895 | if (unlikely(!sgt_buf)) |
| 896 | return -ENOMEM; |
| 897 | |
| 898 | sgt_buf = PTR_ALIGN(sgt_buf, DPAA2_ETH_TX_BUF_ALIGN); |
| 899 | sgt = (struct dpaa2_sg_entry *)(sgt_buf + priv->tx_data_offset); |
| 900 | |
| 901 | addr = dma_map_single(dev, skb->data, skb->len, DMA_BIDIRECTIONAL); |
| 902 | if (unlikely(dma_mapping_error(dev, addr))) { |
| 903 | err = -ENOMEM; |
| 904 | goto data_map_failed; |
| 905 | } |
| 906 | |
| 907 | /* Fill in the HW SGT structure */ |
| 908 | dpaa2_sg_set_addr(sgt, addr); |
| 909 | dpaa2_sg_set_len(sgt, skb->len); |
| 910 | dpaa2_sg_set_final(sgt, true); |
| 911 | |
| 912 | /* Store the skb backpointer in the SGT buffer */ |
Yangbo Lu | 64a965d | 2020-09-18 17:08:00 +0800 | [diff] [blame] | 913 | *swa_addr = (void *)sgt_buf; |
Ioana Ciornei | d70446e | 2020-06-29 21:47:11 +0300 | [diff] [blame] | 914 | swa = (struct dpaa2_eth_swa *)sgt_buf; |
| 915 | swa->type = DPAA2_ETH_SWA_SINGLE; |
| 916 | swa->single.skb = skb; |
Ioana Ciornei | 54a57d1 | 2020-12-11 19:16:07 +0200 | [diff] [blame] | 917 | swa->single.sgt_size = sgt_buf_size; |
Ioana Ciornei | d70446e | 2020-06-29 21:47:11 +0300 | [diff] [blame] | 918 | |
| 919 | /* Separately map the SGT buffer */ |
| 920 | sgt_addr = dma_map_single(dev, sgt_buf, sgt_buf_size, DMA_BIDIRECTIONAL); |
| 921 | if (unlikely(dma_mapping_error(dev, sgt_addr))) { |
| 922 | err = -ENOMEM; |
| 923 | goto sgt_map_failed; |
| 924 | } |
| 925 | |
| 926 | dpaa2_fd_set_offset(fd, priv->tx_data_offset); |
| 927 | dpaa2_fd_set_format(fd, dpaa2_fd_sg); |
| 928 | dpaa2_fd_set_addr(fd, sgt_addr); |
| 929 | dpaa2_fd_set_len(fd, skb->len); |
| 930 | dpaa2_fd_set_ctrl(fd, FD_CTRL_PTA); |
| 931 | |
Ioana Ciornei | d70446e | 2020-06-29 21:47:11 +0300 | [diff] [blame] | 932 | return 0; |
| 933 | |
| 934 | sgt_map_failed: |
| 935 | dma_unmap_single(dev, addr, skb->len, DMA_BIDIRECTIONAL); |
| 936 | data_map_failed: |
| 937 | if (sgt_cache->count >= DPAA2_ETH_SGT_CACHE_SIZE) |
| 938 | kfree(sgt_buf); |
| 939 | else |
| 940 | sgt_cache->buf[sgt_cache->count++] = sgt_buf; |
| 941 | |
| 942 | return err; |
| 943 | } |
| 944 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 945 | /* Create a frame descriptor based on a linear skb */ |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 946 | static int dpaa2_eth_build_single_fd(struct dpaa2_eth_priv *priv, |
| 947 | struct sk_buff *skb, |
Yangbo Lu | 64a965d | 2020-09-18 17:08:00 +0800 | [diff] [blame] | 948 | struct dpaa2_fd *fd, |
| 949 | void **swa_addr) |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 950 | { |
| 951 | struct device *dev = priv->net_dev->dev.parent; |
Ioana Radulescu | c163685 | 2017-12-08 06:47:58 -0600 | [diff] [blame] | 952 | u8 *buffer_start, *aligned_start; |
Ioana Radulescu | e3fdf6b | 2019-03-01 17:47:23 +0000 | [diff] [blame] | 953 | struct dpaa2_eth_swa *swa; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 954 | dma_addr_t addr; |
| 955 | |
Yangbo Lu | 1cf773b | 2020-09-18 17:08:01 +0800 | [diff] [blame] | 956 | buffer_start = skb->data - dpaa2_eth_needed_headroom(skb); |
Ioana Radulescu | c163685 | 2017-12-08 06:47:58 -0600 | [diff] [blame] | 957 | |
| 958 | /* If there's enough room to align the FD address, do it. |
| 959 | * It will help hardware optimize accesses. |
| 960 | */ |
| 961 | aligned_start = PTR_ALIGN(buffer_start - DPAA2_ETH_TX_BUF_ALIGN, |
| 962 | DPAA2_ETH_TX_BUF_ALIGN); |
| 963 | if (aligned_start >= skb->head) |
| 964 | buffer_start = aligned_start; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 965 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 966 | /* Store a backpointer to the skb at the beginning of the buffer |
| 967 | * (in the private data area) such that we can release it |
| 968 | * on Tx confirm |
| 969 | */ |
Yangbo Lu | 64a965d | 2020-09-18 17:08:00 +0800 | [diff] [blame] | 970 | *swa_addr = (void *)buffer_start; |
Ioana Radulescu | e3fdf6b | 2019-03-01 17:47:23 +0000 | [diff] [blame] | 971 | swa = (struct dpaa2_eth_swa *)buffer_start; |
| 972 | swa->type = DPAA2_ETH_SWA_SINGLE; |
| 973 | swa->single.skb = skb; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 974 | |
| 975 | addr = dma_map_single(dev, buffer_start, |
| 976 | skb_tail_pointer(skb) - buffer_start, |
Ioana Radulescu | 1e5fa9e | 2017-05-24 07:13:28 -0500 | [diff] [blame] | 977 | DMA_BIDIRECTIONAL); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 978 | if (unlikely(dma_mapping_error(dev, addr))) |
| 979 | return -ENOMEM; |
| 980 | |
| 981 | dpaa2_fd_set_addr(fd, addr); |
| 982 | dpaa2_fd_set_offset(fd, (u16)(skb->data - buffer_start)); |
| 983 | dpaa2_fd_set_len(fd, skb->len); |
| 984 | dpaa2_fd_set_format(fd, dpaa2_fd_single); |
Ioana Radulescu | b948c8c | 2018-10-12 16:27:40 +0000 | [diff] [blame] | 985 | dpaa2_fd_set_ctrl(fd, FD_CTRL_PTA); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 986 | |
| 987 | return 0; |
| 988 | } |
| 989 | |
| 990 | /* FD freeing routine on the Tx path |
| 991 | * |
| 992 | * DMA-unmap and free FD and possibly SGT buffer allocated on Tx. The skb |
| 993 | * back-pointed to is also freed. |
| 994 | * This can be called either from dpaa2_eth_tx_conf() or on the error path of |
| 995 | * dpaa2_eth_tx(). |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 996 | */ |
Yangbo Lu | c552118 | 2020-09-18 17:08:02 +0800 | [diff] [blame] | 997 | static void dpaa2_eth_free_tx_fd(struct dpaa2_eth_priv *priv, |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 998 | struct dpaa2_eth_fq *fq, |
| 999 | const struct dpaa2_fd *fd, bool in_napi) |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1000 | { |
| 1001 | struct device *dev = priv->net_dev->dev.parent; |
Ioana Ciornei | d70446e | 2020-06-29 21:47:11 +0300 | [diff] [blame] | 1002 | dma_addr_t fd_addr, sg_addr; |
Ioana Radulescu | d678be1 | 2019-03-01 17:47:24 +0000 | [diff] [blame] | 1003 | struct sk_buff *skb = NULL; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1004 | unsigned char *buffer_start; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1005 | struct dpaa2_eth_swa *swa; |
| 1006 | u8 fd_format = dpaa2_fd_get_format(fd); |
Ioana Radulescu | d678be1 | 2019-03-01 17:47:24 +0000 | [diff] [blame] | 1007 | u32 fd_len = dpaa2_fd_get_len(fd); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1008 | |
Ioana Ciornei | d70446e | 2020-06-29 21:47:11 +0300 | [diff] [blame] | 1009 | struct dpaa2_eth_sgt_cache *sgt_cache; |
| 1010 | struct dpaa2_sg_entry *sgt; |
| 1011 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1012 | fd_addr = dpaa2_fd_get_addr(fd); |
Ioana Radulescu | e3fdf6b | 2019-03-01 17:47:23 +0000 | [diff] [blame] | 1013 | buffer_start = dpaa2_iova_to_virt(priv->iommu_domain, fd_addr); |
| 1014 | swa = (struct dpaa2_eth_swa *)buffer_start; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1015 | |
| 1016 | if (fd_format == dpaa2_fd_single) { |
Ioana Radulescu | d678be1 | 2019-03-01 17:47:24 +0000 | [diff] [blame] | 1017 | if (swa->type == DPAA2_ETH_SWA_SINGLE) { |
| 1018 | skb = swa->single.skb; |
| 1019 | /* Accessing the skb buffer is safe before dma unmap, |
| 1020 | * because we didn't map the actual skb shell. |
| 1021 | */ |
| 1022 | dma_unmap_single(dev, fd_addr, |
| 1023 | skb_tail_pointer(skb) - buffer_start, |
| 1024 | DMA_BIDIRECTIONAL); |
| 1025 | } else { |
| 1026 | WARN_ONCE(swa->type != DPAA2_ETH_SWA_XDP, "Wrong SWA type"); |
| 1027 | dma_unmap_single(dev, fd_addr, swa->xdp.dma_size, |
| 1028 | DMA_BIDIRECTIONAL); |
| 1029 | } |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1030 | } else if (fd_format == dpaa2_fd_sg) { |
Ioana Ciornei | d70446e | 2020-06-29 21:47:11 +0300 | [diff] [blame] | 1031 | if (swa->type == DPAA2_ETH_SWA_SG) { |
| 1032 | skb = swa->sg.skb; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1033 | |
Ioana Ciornei | d70446e | 2020-06-29 21:47:11 +0300 | [diff] [blame] | 1034 | /* Unmap the scatterlist */ |
| 1035 | dma_unmap_sg(dev, swa->sg.scl, swa->sg.num_sg, |
| 1036 | DMA_BIDIRECTIONAL); |
| 1037 | kfree(swa->sg.scl); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1038 | |
Ioana Ciornei | d70446e | 2020-06-29 21:47:11 +0300 | [diff] [blame] | 1039 | /* Unmap the SGT buffer */ |
| 1040 | dma_unmap_single(dev, fd_addr, swa->sg.sgt_size, |
| 1041 | DMA_BIDIRECTIONAL); |
| 1042 | } else { |
| 1043 | skb = swa->single.skb; |
| 1044 | |
| 1045 | /* Unmap the SGT Buffer */ |
| 1046 | dma_unmap_single(dev, fd_addr, swa->single.sgt_size, |
| 1047 | DMA_BIDIRECTIONAL); |
| 1048 | |
| 1049 | sgt = (struct dpaa2_sg_entry *)(buffer_start + |
| 1050 | priv->tx_data_offset); |
| 1051 | sg_addr = dpaa2_sg_get_addr(sgt); |
| 1052 | dma_unmap_single(dev, sg_addr, skb->len, DMA_BIDIRECTIONAL); |
| 1053 | } |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1054 | } else { |
Ioana Radulescu | 2b7c86e | 2017-12-08 06:47:56 -0600 | [diff] [blame] | 1055 | netdev_dbg(priv->net_dev, "Invalid FD format\n"); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1056 | return; |
| 1057 | } |
| 1058 | |
Ioana Radulescu | d678be1 | 2019-03-01 17:47:24 +0000 | [diff] [blame] | 1059 | if (swa->type != DPAA2_ETH_SWA_XDP && in_napi) { |
| 1060 | fq->dq_frames++; |
| 1061 | fq->dq_bytes += fd_len; |
| 1062 | } |
| 1063 | |
| 1064 | if (swa->type == DPAA2_ETH_SWA_XDP) { |
| 1065 | xdp_return_frame(swa->xdp.xdpf); |
| 1066 | return; |
| 1067 | } |
| 1068 | |
Ioana Radulescu | 859f998 | 2018-04-26 18:23:47 +0800 | [diff] [blame] | 1069 | /* Get the timestamp value */ |
Yangbo Lu | 1cf773b | 2020-09-18 17:08:01 +0800 | [diff] [blame] | 1070 | if (skb->cb[0] == TX_TSTAMP) { |
Ioana Radulescu | 859f998 | 2018-04-26 18:23:47 +0800 | [diff] [blame] | 1071 | struct skb_shared_hwtstamps shhwtstamps; |
Ioana Radulescu | e3fdf6b | 2019-03-01 17:47:23 +0000 | [diff] [blame] | 1072 | __le64 *ts = dpaa2_get_ts(buffer_start, true); |
Ioana Radulescu | 859f998 | 2018-04-26 18:23:47 +0800 | [diff] [blame] | 1073 | u64 ns; |
| 1074 | |
| 1075 | memset(&shhwtstamps, 0, sizeof(shhwtstamps)); |
| 1076 | |
| 1077 | ns = DPAA2_PTP_CLK_PERIOD_NS * le64_to_cpup(ts); |
| 1078 | shhwtstamps.hwtstamp = ns_to_ktime(ns); |
| 1079 | skb_tstamp_tx(skb, &shhwtstamps); |
Yangbo Lu | c552118 | 2020-09-18 17:08:02 +0800 | [diff] [blame] | 1080 | } else if (skb->cb[0] == TX_TSTAMP_ONESTEP_SYNC) { |
| 1081 | mutex_unlock(&priv->onestep_tstamp_lock); |
Ioana Radulescu | 859f998 | 2018-04-26 18:23:47 +0800 | [diff] [blame] | 1082 | } |
| 1083 | |
Ioana Radulescu | 6a9bbe5 | 2018-03-14 15:04:51 -0500 | [diff] [blame] | 1084 | /* Free SGT buffer allocated on tx */ |
Ioana Ciornei | d70446e | 2020-06-29 21:47:11 +0300 | [diff] [blame] | 1085 | if (fd_format != dpaa2_fd_single) { |
| 1086 | sgt_cache = this_cpu_ptr(priv->sgt_cache); |
| 1087 | if (swa->type == DPAA2_ETH_SWA_SG) { |
| 1088 | skb_free_frag(buffer_start); |
| 1089 | } else { |
| 1090 | if (sgt_cache->count >= DPAA2_ETH_SGT_CACHE_SIZE) |
| 1091 | kfree(buffer_start); |
| 1092 | else |
| 1093 | sgt_cache->buf[sgt_cache->count++] = buffer_start; |
| 1094 | } |
| 1095 | } |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1096 | |
| 1097 | /* Move on with skb release */ |
Ioana Ciocoi Radulescu | 0723a3a | 2019-02-04 17:00:35 +0000 | [diff] [blame] | 1098 | napi_consume_skb(skb, in_napi); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1099 | } |
| 1100 | |
Yangbo Lu | c552118 | 2020-09-18 17:08:02 +0800 | [diff] [blame] | 1101 | static netdev_tx_t __dpaa2_eth_tx(struct sk_buff *skb, |
| 1102 | struct net_device *net_dev) |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1103 | { |
| 1104 | struct dpaa2_eth_priv *priv = netdev_priv(net_dev); |
| 1105 | struct dpaa2_fd fd; |
| 1106 | struct rtnl_link_stats64 *percpu_stats; |
Ioana Radulescu | 85047ab | 2017-04-28 04:50:31 -0500 | [diff] [blame] | 1107 | struct dpaa2_eth_drv_stats *percpu_extras; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1108 | struct dpaa2_eth_fq *fq; |
Ioana Ciocoi Radulescu | 569dac6 | 2018-11-14 11:48:36 +0000 | [diff] [blame] | 1109 | struct netdev_queue *nq; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1110 | u16 queue_mapping; |
Ioana Radulescu | 18c2146 | 2017-12-08 06:47:57 -0600 | [diff] [blame] | 1111 | unsigned int needed_headroom; |
Ioana Ciocoi Radulescu | 569dac6 | 2018-11-14 11:48:36 +0000 | [diff] [blame] | 1112 | u32 fd_len; |
Ioana Radulescu | ab1e6de | 2019-06-11 14:50:03 +0300 | [diff] [blame] | 1113 | u8 prio = 0; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1114 | int err, i; |
Yangbo Lu | 64a965d | 2020-09-18 17:08:00 +0800 | [diff] [blame] | 1115 | void *swa; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1116 | |
| 1117 | percpu_stats = this_cpu_ptr(priv->percpu_stats); |
Ioana Radulescu | 85047ab | 2017-04-28 04:50:31 -0500 | [diff] [blame] | 1118 | percpu_extras = this_cpu_ptr(priv->percpu_extras); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1119 | |
Yangbo Lu | 1cf773b | 2020-09-18 17:08:01 +0800 | [diff] [blame] | 1120 | needed_headroom = dpaa2_eth_needed_headroom(skb); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1121 | |
| 1122 | /* We'll be holding a back-reference to the skb until Tx Confirmation; |
| 1123 | * we don't want that overwritten by a concurrent Tx with a cloned skb. |
| 1124 | */ |
| 1125 | skb = skb_unshare(skb, GFP_ATOMIC); |
| 1126 | if (unlikely(!skb)) { |
| 1127 | /* skb_unshare() has already freed the skb */ |
| 1128 | percpu_stats->tx_dropped++; |
| 1129 | return NETDEV_TX_OK; |
| 1130 | } |
| 1131 | |
| 1132 | /* Setup the FD fields */ |
| 1133 | memset(&fd, 0, sizeof(fd)); |
| 1134 | |
Ioana Radulescu | 85047ab | 2017-04-28 04:50:31 -0500 | [diff] [blame] | 1135 | if (skb_is_nonlinear(skb)) { |
Yangbo Lu | 64a965d | 2020-09-18 17:08:00 +0800 | [diff] [blame] | 1136 | err = dpaa2_eth_build_sg_fd(priv, skb, &fd, &swa); |
Ioana Radulescu | 85047ab | 2017-04-28 04:50:31 -0500 | [diff] [blame] | 1137 | percpu_extras->tx_sg_frames++; |
| 1138 | percpu_extras->tx_sg_bytes += skb->len; |
Ioana Ciornei | d70446e | 2020-06-29 21:47:11 +0300 | [diff] [blame] | 1139 | } else if (skb_headroom(skb) < needed_headroom) { |
Yangbo Lu | 64a965d | 2020-09-18 17:08:00 +0800 | [diff] [blame] | 1140 | err = dpaa2_eth_build_sg_fd_single_buf(priv, skb, &fd, &swa); |
Ioana Ciornei | d70446e | 2020-06-29 21:47:11 +0300 | [diff] [blame] | 1141 | percpu_extras->tx_sg_frames++; |
| 1142 | percpu_extras->tx_sg_bytes += skb->len; |
Ioana Ciornei | 4c96c0a | 2020-06-29 21:47:12 +0300 | [diff] [blame] | 1143 | percpu_extras->tx_converted_sg_frames++; |
| 1144 | percpu_extras->tx_converted_sg_bytes += skb->len; |
Ioana Radulescu | 85047ab | 2017-04-28 04:50:31 -0500 | [diff] [blame] | 1145 | } else { |
Yangbo Lu | 64a965d | 2020-09-18 17:08:00 +0800 | [diff] [blame] | 1146 | err = dpaa2_eth_build_single_fd(priv, skb, &fd, &swa); |
Ioana Radulescu | 85047ab | 2017-04-28 04:50:31 -0500 | [diff] [blame] | 1147 | } |
| 1148 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1149 | if (unlikely(err)) { |
| 1150 | percpu_stats->tx_dropped++; |
| 1151 | goto err_build_fd; |
| 1152 | } |
| 1153 | |
Yangbo Lu | c552118 | 2020-09-18 17:08:02 +0800 | [diff] [blame] | 1154 | if (skb->cb[0]) |
| 1155 | dpaa2_eth_enable_tx_tstamp(priv, &fd, swa, skb); |
Yangbo Lu | 64a965d | 2020-09-18 17:08:00 +0800 | [diff] [blame] | 1156 | |
Ioana Radulescu | 5636187 | 2017-04-28 04:50:32 -0500 | [diff] [blame] | 1157 | /* Tracing point */ |
| 1158 | trace_dpaa2_tx_fd(net_dev, &fd); |
| 1159 | |
Ioana Radulescu | 537336c | 2017-12-21 06:33:20 -0600 | [diff] [blame] | 1160 | /* TxConf FQ selection relies on queue id from the stack. |
| 1161 | * In case of a forwarded frame from another DPNI interface, we choose |
| 1162 | * a queue affined to the same core that processed the Rx frame |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1163 | */ |
Ioana Radulescu | 537336c | 2017-12-21 06:33:20 -0600 | [diff] [blame] | 1164 | queue_mapping = skb_get_queue_mapping(skb); |
Ioana Radulescu | ab1e6de | 2019-06-11 14:50:03 +0300 | [diff] [blame] | 1165 | |
| 1166 | if (net_dev->num_tc) { |
| 1167 | prio = netdev_txq_to_tc(net_dev, queue_mapping); |
| 1168 | /* Hardware interprets priority level 0 as being the highest, |
| 1169 | * so we need to do a reverse mapping to the netdev tc index |
| 1170 | */ |
| 1171 | prio = net_dev->num_tc - prio - 1; |
| 1172 | /* We have only one FQ array entry for all Tx hardware queues |
| 1173 | * with the same flow id (but different priority levels) |
| 1174 | */ |
| 1175 | queue_mapping %= dpaa2_eth_queue_count(priv); |
| 1176 | } |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1177 | fq = &priv->fq[queue_mapping]; |
Ioana Ciornei | 8c838f5 | 2019-03-25 13:06:22 +0000 | [diff] [blame] | 1178 | |
| 1179 | fd_len = dpaa2_fd_get_len(&fd); |
| 1180 | nq = netdev_get_tx_queue(net_dev, queue_mapping); |
| 1181 | netdev_tx_sent_queue(nq, fd_len); |
| 1182 | |
| 1183 | /* Everything that happens after this enqueues might race with |
| 1184 | * the Tx confirmation callback for this frame |
| 1185 | */ |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1186 | for (i = 0; i < DPAA2_ETH_ENQUEUE_RETRIES; i++) { |
Ioana Ciornei | 6ff8044 | 2020-04-22 15:05:11 +0300 | [diff] [blame] | 1187 | err = priv->enqueue(priv, fq, &fd, prio, 1, NULL); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1188 | if (err != -EBUSY) |
| 1189 | break; |
| 1190 | } |
Ioana Radulescu | 85047ab | 2017-04-28 04:50:31 -0500 | [diff] [blame] | 1191 | percpu_extras->tx_portal_busy += i; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1192 | if (unlikely(err < 0)) { |
| 1193 | percpu_stats->tx_errors++; |
| 1194 | /* Clean up everything, including freeing the skb */ |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 1195 | dpaa2_eth_free_tx_fd(priv, fq, &fd, false); |
Ioana Ciornei | 8c838f5 | 2019-03-25 13:06:22 +0000 | [diff] [blame] | 1196 | netdev_tx_completed_queue(nq, 1, fd_len); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1197 | } else { |
| 1198 | percpu_stats->tx_packets++; |
Ioana Ciocoi Radulescu | 569dac6 | 2018-11-14 11:48:36 +0000 | [diff] [blame] | 1199 | percpu_stats->tx_bytes += fd_len; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1200 | } |
| 1201 | |
| 1202 | return NETDEV_TX_OK; |
| 1203 | |
| 1204 | err_build_fd: |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1205 | dev_kfree_skb(skb); |
| 1206 | |
| 1207 | return NETDEV_TX_OK; |
| 1208 | } |
| 1209 | |
Yangbo Lu | c552118 | 2020-09-18 17:08:02 +0800 | [diff] [blame] | 1210 | static void dpaa2_eth_tx_onestep_tstamp(struct work_struct *work) |
| 1211 | { |
| 1212 | struct dpaa2_eth_priv *priv = container_of(work, struct dpaa2_eth_priv, |
| 1213 | tx_onestep_tstamp); |
| 1214 | struct sk_buff *skb; |
| 1215 | |
| 1216 | while (true) { |
| 1217 | skb = skb_dequeue(&priv->tx_skbs); |
| 1218 | if (!skb) |
| 1219 | return; |
| 1220 | |
| 1221 | /* Lock just before TX one-step timestamping packet, |
| 1222 | * and release the lock in dpaa2_eth_free_tx_fd when |
| 1223 | * confirm the packet has been sent on hardware, or |
| 1224 | * when clean up during transmit failure. |
| 1225 | */ |
| 1226 | mutex_lock(&priv->onestep_tstamp_lock); |
| 1227 | __dpaa2_eth_tx(skb, priv->net_dev); |
| 1228 | } |
| 1229 | } |
| 1230 | |
| 1231 | static netdev_tx_t dpaa2_eth_tx(struct sk_buff *skb, struct net_device *net_dev) |
| 1232 | { |
| 1233 | struct dpaa2_eth_priv *priv = netdev_priv(net_dev); |
| 1234 | u8 msgtype, twostep, udp; |
| 1235 | u16 offset1, offset2; |
| 1236 | |
| 1237 | /* Utilize skb->cb[0] for timestamping request per skb */ |
| 1238 | skb->cb[0] = 0; |
| 1239 | |
| 1240 | if ((skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) && dpaa2_ptp) { |
| 1241 | if (priv->tx_tstamp_type == HWTSTAMP_TX_ON) |
| 1242 | skb->cb[0] = TX_TSTAMP; |
| 1243 | else if (priv->tx_tstamp_type == HWTSTAMP_TX_ONESTEP_SYNC) |
| 1244 | skb->cb[0] = TX_TSTAMP_ONESTEP_SYNC; |
| 1245 | } |
| 1246 | |
| 1247 | /* TX for one-step timestamping PTP Sync packet */ |
| 1248 | if (skb->cb[0] == TX_TSTAMP_ONESTEP_SYNC) { |
| 1249 | if (!dpaa2_eth_ptp_parse(skb, &msgtype, &twostep, &udp, |
| 1250 | &offset1, &offset2)) |
Christian Eggers | 6b6817c | 2020-11-20 09:41:05 +0100 | [diff] [blame] | 1251 | if (msgtype == PTP_MSGTYPE_SYNC && twostep == 0) { |
Yangbo Lu | c552118 | 2020-09-18 17:08:02 +0800 | [diff] [blame] | 1252 | skb_queue_tail(&priv->tx_skbs, skb); |
| 1253 | queue_work(priv->dpaa2_ptp_wq, |
| 1254 | &priv->tx_onestep_tstamp); |
| 1255 | return NETDEV_TX_OK; |
| 1256 | } |
| 1257 | /* Use two-step timestamping if not one-step timestamping |
| 1258 | * PTP Sync packet |
| 1259 | */ |
| 1260 | skb->cb[0] = TX_TSTAMP; |
| 1261 | } |
| 1262 | |
| 1263 | /* TX for other packets */ |
| 1264 | return __dpaa2_eth_tx(skb, net_dev); |
| 1265 | } |
| 1266 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1267 | /* Tx confirmation frame processing routine */ |
| 1268 | static void dpaa2_eth_tx_conf(struct dpaa2_eth_priv *priv, |
Ioana Ciornei | fc398be | 2021-10-15 12:01:27 +0300 | [diff] [blame] | 1269 | struct dpaa2_eth_channel *ch, |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1270 | const struct dpaa2_fd *fd, |
Ioana Ciocoi Radulescu | 569dac6 | 2018-11-14 11:48:36 +0000 | [diff] [blame] | 1271 | struct dpaa2_eth_fq *fq) |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1272 | { |
| 1273 | struct rtnl_link_stats64 *percpu_stats; |
Ioana Radulescu | 85047ab | 2017-04-28 04:50:31 -0500 | [diff] [blame] | 1274 | struct dpaa2_eth_drv_stats *percpu_extras; |
Ioana Ciocoi Radulescu | 569dac6 | 2018-11-14 11:48:36 +0000 | [diff] [blame] | 1275 | u32 fd_len = dpaa2_fd_get_len(fd); |
Ioana Radulescu | 39163c0 | 2017-06-06 10:00:39 -0500 | [diff] [blame] | 1276 | u32 fd_errors; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1277 | |
Ioana Radulescu | 5636187 | 2017-04-28 04:50:32 -0500 | [diff] [blame] | 1278 | /* Tracing point */ |
| 1279 | trace_dpaa2_tx_conf_fd(priv->net_dev, fd); |
| 1280 | |
Ioana Radulescu | 85047ab | 2017-04-28 04:50:31 -0500 | [diff] [blame] | 1281 | percpu_extras = this_cpu_ptr(priv->percpu_extras); |
| 1282 | percpu_extras->tx_conf_frames++; |
Ioana Ciocoi Radulescu | 569dac6 | 2018-11-14 11:48:36 +0000 | [diff] [blame] | 1283 | percpu_extras->tx_conf_bytes += fd_len; |
Ioana Ciornei | fc398be | 2021-10-15 12:01:27 +0300 | [diff] [blame] | 1284 | ch->stats.bytes_per_cdan += fd_len; |
Ioana Ciocoi Radulescu | 569dac6 | 2018-11-14 11:48:36 +0000 | [diff] [blame] | 1285 | |
Ioana Radulescu | 39163c0 | 2017-06-06 10:00:39 -0500 | [diff] [blame] | 1286 | /* Check frame errors in the FD field */ |
| 1287 | fd_errors = dpaa2_fd_get_ctrl(fd) & DPAA2_FD_TX_ERR_MASK; |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 1288 | dpaa2_eth_free_tx_fd(priv, fq, fd, true); |
Ioana Radulescu | 39163c0 | 2017-06-06 10:00:39 -0500 | [diff] [blame] | 1289 | |
| 1290 | if (likely(!fd_errors)) |
| 1291 | return; |
| 1292 | |
Ioana Radulescu | 2b7c86e | 2017-12-08 06:47:56 -0600 | [diff] [blame] | 1293 | if (net_ratelimit()) |
| 1294 | netdev_dbg(priv->net_dev, "TX frame FD error: 0x%08x\n", |
| 1295 | fd_errors); |
| 1296 | |
Ioana Radulescu | 39163c0 | 2017-06-06 10:00:39 -0500 | [diff] [blame] | 1297 | percpu_stats = this_cpu_ptr(priv->percpu_stats); |
| 1298 | /* Tx-conf logically pertains to the egress path. */ |
| 1299 | percpu_stats->tx_errors++; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1300 | } |
| 1301 | |
Ionut-robert Aron | 70b32d8 | 2021-01-11 19:07:25 +0200 | [diff] [blame] | 1302 | static int dpaa2_eth_set_rx_vlan_filtering(struct dpaa2_eth_priv *priv, |
| 1303 | bool enable) |
| 1304 | { |
| 1305 | int err; |
| 1306 | |
| 1307 | err = dpni_enable_vlan_filter(priv->mc_io, 0, priv->mc_token, enable); |
| 1308 | |
| 1309 | if (err) { |
| 1310 | netdev_err(priv->net_dev, |
| 1311 | "dpni_enable_vlan_filter failed\n"); |
| 1312 | return err; |
| 1313 | } |
| 1314 | |
| 1315 | return 0; |
| 1316 | } |
| 1317 | |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 1318 | static int dpaa2_eth_set_rx_csum(struct dpaa2_eth_priv *priv, bool enable) |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1319 | { |
| 1320 | int err; |
| 1321 | |
| 1322 | err = dpni_set_offload(priv->mc_io, 0, priv->mc_token, |
| 1323 | DPNI_OFF_RX_L3_CSUM, enable); |
| 1324 | if (err) { |
| 1325 | netdev_err(priv->net_dev, |
| 1326 | "dpni_set_offload(RX_L3_CSUM) failed\n"); |
| 1327 | return err; |
| 1328 | } |
| 1329 | |
| 1330 | err = dpni_set_offload(priv->mc_io, 0, priv->mc_token, |
| 1331 | DPNI_OFF_RX_L4_CSUM, enable); |
| 1332 | if (err) { |
| 1333 | netdev_err(priv->net_dev, |
| 1334 | "dpni_set_offload(RX_L4_CSUM) failed\n"); |
| 1335 | return err; |
| 1336 | } |
| 1337 | |
| 1338 | return 0; |
| 1339 | } |
| 1340 | |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 1341 | static int dpaa2_eth_set_tx_csum(struct dpaa2_eth_priv *priv, bool enable) |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1342 | { |
| 1343 | int err; |
| 1344 | |
| 1345 | err = dpni_set_offload(priv->mc_io, 0, priv->mc_token, |
| 1346 | DPNI_OFF_TX_L3_CSUM, enable); |
| 1347 | if (err) { |
| 1348 | netdev_err(priv->net_dev, "dpni_set_offload(TX_L3_CSUM) failed\n"); |
| 1349 | return err; |
| 1350 | } |
| 1351 | |
| 1352 | err = dpni_set_offload(priv->mc_io, 0, priv->mc_token, |
| 1353 | DPNI_OFF_TX_L4_CSUM, enable); |
| 1354 | if (err) { |
| 1355 | netdev_err(priv->net_dev, "dpni_set_offload(TX_L4_CSUM) failed\n"); |
| 1356 | return err; |
| 1357 | } |
| 1358 | |
| 1359 | return 0; |
| 1360 | } |
| 1361 | |
| 1362 | /* Perform a single release command to add buffers |
| 1363 | * to the specified buffer pool |
| 1364 | */ |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 1365 | static int dpaa2_eth_add_bufs(struct dpaa2_eth_priv *priv, |
| 1366 | struct dpaa2_eth_channel *ch, u16 bpid) |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1367 | { |
| 1368 | struct device *dev = priv->net_dev->dev.parent; |
| 1369 | u64 buf_array[DPAA2_ETH_BUFS_PER_CMD]; |
Ioana Ciocoi Radulescu | 27c8748 | 2019-02-04 17:00:35 +0000 | [diff] [blame] | 1370 | struct page *page; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1371 | dma_addr_t addr; |
Ioana Radulescu | ef17bd7 | 2019-10-07 14:38:28 +0300 | [diff] [blame] | 1372 | int retries = 0; |
Ioana Radulescu | 87eb55e | 2017-10-11 08:29:43 -0500 | [diff] [blame] | 1373 | int i, err; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1374 | |
| 1375 | for (i = 0; i < DPAA2_ETH_BUFS_PER_CMD; i++) { |
| 1376 | /* Allocate buffer visible to WRIOP + skb shared info + |
| 1377 | * alignment padding |
| 1378 | */ |
Ioana Ciocoi Radulescu | 27c8748 | 2019-02-04 17:00:35 +0000 | [diff] [blame] | 1379 | /* allocate one page for each Rx buffer. WRIOP sees |
| 1380 | * the entire page except for a tailroom reserved for |
| 1381 | * skb shared info |
| 1382 | */ |
| 1383 | page = dev_alloc_pages(0); |
| 1384 | if (!page) |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1385 | goto err_alloc; |
| 1386 | |
Ioana Ciornei | efa6a7d | 2020-05-15 15:30:22 +0300 | [diff] [blame] | 1387 | addr = dma_map_page(dev, page, 0, priv->rx_buf_size, |
Ioana Ciocoi Radulescu | 27c8748 | 2019-02-04 17:00:35 +0000 | [diff] [blame] | 1388 | DMA_BIDIRECTIONAL); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1389 | if (unlikely(dma_mapping_error(dev, addr))) |
| 1390 | goto err_map; |
| 1391 | |
| 1392 | buf_array[i] = addr; |
Ioana Radulescu | 5636187 | 2017-04-28 04:50:32 -0500 | [diff] [blame] | 1393 | |
| 1394 | /* tracing point */ |
| 1395 | trace_dpaa2_eth_buf_seed(priv->net_dev, |
Ioana Ciocoi Radulescu | 27c8748 | 2019-02-04 17:00:35 +0000 | [diff] [blame] | 1396 | page, DPAA2_ETH_RX_BUF_RAW_SIZE, |
Ioana Ciornei | efa6a7d | 2020-05-15 15:30:22 +0300 | [diff] [blame] | 1397 | addr, priv->rx_buf_size, |
Ioana Radulescu | 5636187 | 2017-04-28 04:50:32 -0500 | [diff] [blame] | 1398 | bpid); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1399 | } |
| 1400 | |
| 1401 | release_bufs: |
Ioana Radulescu | 87eb55e | 2017-10-11 08:29:43 -0500 | [diff] [blame] | 1402 | /* In case the portal is busy, retry until successful */ |
Ioana Radulescu | 7ec0596 | 2018-01-05 05:04:32 -0600 | [diff] [blame] | 1403 | while ((err = dpaa2_io_service_release(ch->dpio, bpid, |
Ioana Radulescu | ef17bd7 | 2019-10-07 14:38:28 +0300 | [diff] [blame] | 1404 | buf_array, i)) == -EBUSY) { |
| 1405 | if (retries++ >= DPAA2_ETH_SWP_BUSY_RETRIES) |
| 1406 | break; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1407 | cpu_relax(); |
Ioana Radulescu | ef17bd7 | 2019-10-07 14:38:28 +0300 | [diff] [blame] | 1408 | } |
Ioana Radulescu | 87eb55e | 2017-10-11 08:29:43 -0500 | [diff] [blame] | 1409 | |
| 1410 | /* If release command failed, clean up and bail out; |
| 1411 | * not much else we can do about it |
| 1412 | */ |
| 1413 | if (err) { |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 1414 | dpaa2_eth_free_bufs(priv, buf_array, i); |
Ioana Radulescu | 87eb55e | 2017-10-11 08:29:43 -0500 | [diff] [blame] | 1415 | return 0; |
| 1416 | } |
| 1417 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1418 | return i; |
| 1419 | |
| 1420 | err_map: |
Ioana Ciocoi Radulescu | 27c8748 | 2019-02-04 17:00:35 +0000 | [diff] [blame] | 1421 | __free_pages(page, 0); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1422 | err_alloc: |
Ioana Radulescu | 87eb55e | 2017-10-11 08:29:43 -0500 | [diff] [blame] | 1423 | /* If we managed to allocate at least some buffers, |
| 1424 | * release them to hardware |
| 1425 | */ |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1426 | if (i) |
| 1427 | goto release_bufs; |
| 1428 | |
| 1429 | return 0; |
| 1430 | } |
| 1431 | |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 1432 | static int dpaa2_eth_seed_pool(struct dpaa2_eth_priv *priv, u16 bpid) |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1433 | { |
| 1434 | int i, j; |
| 1435 | int new_count; |
| 1436 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1437 | for (j = 0; j < priv->num_channels; j++) { |
| 1438 | for (i = 0; i < DPAA2_ETH_NUM_BUFS; |
| 1439 | i += DPAA2_ETH_BUFS_PER_CMD) { |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 1440 | new_count = dpaa2_eth_add_bufs(priv, priv->channel[j], bpid); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1441 | priv->channel[j]->buf_count += new_count; |
| 1442 | |
| 1443 | if (new_count < DPAA2_ETH_BUFS_PER_CMD) { |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1444 | return -ENOMEM; |
| 1445 | } |
| 1446 | } |
| 1447 | } |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1448 | |
| 1449 | return 0; |
| 1450 | } |
| 1451 | |
Jesse Brandeburg | d0ea5cb | 2020-09-25 15:24:45 -0700 | [diff] [blame] | 1452 | /* |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1453 | * Drain the specified number of buffers from the DPNI's private buffer pool. |
| 1454 | * @count must not exceeed DPAA2_ETH_BUFS_PER_CMD |
| 1455 | */ |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 1456 | static void dpaa2_eth_drain_bufs(struct dpaa2_eth_priv *priv, int count) |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1457 | { |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1458 | u64 buf_array[DPAA2_ETH_BUFS_PER_CMD]; |
Ioana Radulescu | ef17bd7 | 2019-10-07 14:38:28 +0300 | [diff] [blame] | 1459 | int retries = 0; |
Ioana Radulescu | 87eb55e | 2017-10-11 08:29:43 -0500 | [diff] [blame] | 1460 | int ret; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1461 | |
| 1462 | do { |
Ioana Radulescu | 05fa39c | 2017-06-06 10:00:37 -0500 | [diff] [blame] | 1463 | ret = dpaa2_io_service_acquire(NULL, priv->bpid, |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1464 | buf_array, count); |
| 1465 | if (ret < 0) { |
Ioana Radulescu | ef17bd7 | 2019-10-07 14:38:28 +0300 | [diff] [blame] | 1466 | if (ret == -EBUSY && |
Ioana Ciornei | 0e5ad75 | 2020-06-24 14:34:19 +0300 | [diff] [blame] | 1467 | retries++ < DPAA2_ETH_SWP_BUSY_RETRIES) |
Ioana Radulescu | ef17bd7 | 2019-10-07 14:38:28 +0300 | [diff] [blame] | 1468 | continue; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1469 | netdev_err(priv->net_dev, "dpaa2_io_service_acquire() failed\n"); |
| 1470 | return; |
| 1471 | } |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 1472 | dpaa2_eth_free_bufs(priv, buf_array, ret); |
Ioana Radulescu | ef17bd7 | 2019-10-07 14:38:28 +0300 | [diff] [blame] | 1473 | retries = 0; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1474 | } while (ret); |
| 1475 | } |
| 1476 | |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 1477 | static void dpaa2_eth_drain_pool(struct dpaa2_eth_priv *priv) |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1478 | { |
| 1479 | int i; |
| 1480 | |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 1481 | dpaa2_eth_drain_bufs(priv, DPAA2_ETH_BUFS_PER_CMD); |
| 1482 | dpaa2_eth_drain_bufs(priv, 1); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1483 | |
| 1484 | for (i = 0; i < priv->num_channels; i++) |
| 1485 | priv->channel[i]->buf_count = 0; |
| 1486 | } |
| 1487 | |
| 1488 | /* Function is called from softirq context only, so we don't need to guard |
| 1489 | * the access to percpu count |
| 1490 | */ |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 1491 | static int dpaa2_eth_refill_pool(struct dpaa2_eth_priv *priv, |
| 1492 | struct dpaa2_eth_channel *ch, |
| 1493 | u16 bpid) |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1494 | { |
| 1495 | int new_count; |
| 1496 | |
| 1497 | if (likely(ch->buf_count >= DPAA2_ETH_REFILL_THRESH)) |
| 1498 | return 0; |
| 1499 | |
| 1500 | do { |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 1501 | new_count = dpaa2_eth_add_bufs(priv, ch, bpid); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1502 | if (unlikely(!new_count)) { |
| 1503 | /* Out of memory; abort for now, we'll try later on */ |
| 1504 | break; |
| 1505 | } |
| 1506 | ch->buf_count += new_count; |
| 1507 | } while (ch->buf_count < DPAA2_ETH_NUM_BUFS); |
| 1508 | |
| 1509 | if (unlikely(ch->buf_count < DPAA2_ETH_NUM_BUFS)) |
| 1510 | return -ENOMEM; |
| 1511 | |
| 1512 | return 0; |
| 1513 | } |
| 1514 | |
Ioana Ciornei | d70446e | 2020-06-29 21:47:11 +0300 | [diff] [blame] | 1515 | static void dpaa2_eth_sgt_cache_drain(struct dpaa2_eth_priv *priv) |
| 1516 | { |
| 1517 | struct dpaa2_eth_sgt_cache *sgt_cache; |
| 1518 | u16 count; |
| 1519 | int k, i; |
| 1520 | |
Ioana Ciornei | 0fe665d | 2020-07-06 17:55:54 +0300 | [diff] [blame] | 1521 | for_each_possible_cpu(k) { |
Ioana Ciornei | d70446e | 2020-06-29 21:47:11 +0300 | [diff] [blame] | 1522 | sgt_cache = per_cpu_ptr(priv->sgt_cache, k); |
| 1523 | count = sgt_cache->count; |
| 1524 | |
| 1525 | for (i = 0; i < count; i++) |
| 1526 | kfree(sgt_cache->buf[i]); |
| 1527 | sgt_cache->count = 0; |
| 1528 | } |
| 1529 | } |
| 1530 | |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 1531 | static int dpaa2_eth_pull_channel(struct dpaa2_eth_channel *ch) |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1532 | { |
| 1533 | int err; |
Ioana Radulescu | 85047ab | 2017-04-28 04:50:31 -0500 | [diff] [blame] | 1534 | int dequeues = -1; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1535 | |
| 1536 | /* Retry while portal is busy */ |
| 1537 | do { |
Ioana Radulescu | 7ec0596 | 2018-01-05 05:04:32 -0600 | [diff] [blame] | 1538 | err = dpaa2_io_service_pull_channel(ch->dpio, ch->ch_id, |
| 1539 | ch->store); |
Ioana Radulescu | 85047ab | 2017-04-28 04:50:31 -0500 | [diff] [blame] | 1540 | dequeues++; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1541 | cpu_relax(); |
Ioana Radulescu | ef17bd7 | 2019-10-07 14:38:28 +0300 | [diff] [blame] | 1542 | } while (err == -EBUSY && dequeues < DPAA2_ETH_SWP_BUSY_RETRIES); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1543 | |
Ioana Radulescu | 85047ab | 2017-04-28 04:50:31 -0500 | [diff] [blame] | 1544 | ch->stats.dequeue_portal_busy += dequeues; |
| 1545 | if (unlikely(err)) |
| 1546 | ch->stats.pull_err++; |
| 1547 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1548 | return err; |
| 1549 | } |
| 1550 | |
| 1551 | /* NAPI poll routine |
| 1552 | * |
| 1553 | * Frames are dequeued from the QMan channel associated with this NAPI context. |
| 1554 | * Rx, Tx confirmation and (if configured) Rx error frames all count |
| 1555 | * towards the NAPI budget. |
| 1556 | */ |
| 1557 | static int dpaa2_eth_poll(struct napi_struct *napi, int budget) |
| 1558 | { |
| 1559 | struct dpaa2_eth_channel *ch; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1560 | struct dpaa2_eth_priv *priv; |
Ioana Ciocoi Radulescu | 68049a5 | 2018-10-08 14:16:31 +0000 | [diff] [blame] | 1561 | int rx_cleaned = 0, txconf_cleaned = 0; |
Ioana Ciocoi Radulescu | 569dac6 | 2018-11-14 11:48:36 +0000 | [diff] [blame] | 1562 | struct dpaa2_eth_fq *fq, *txc_fq = NULL; |
| 1563 | struct netdev_queue *nq; |
| 1564 | int store_cleaned, work_done; |
Ioana Ciornei | 0a25d92 | 2019-03-25 13:42:39 +0000 | [diff] [blame] | 1565 | struct list_head rx_list; |
Ioana Radulescu | ef17bd7 | 2019-10-07 14:38:28 +0300 | [diff] [blame] | 1566 | int retries = 0; |
Ioana Ciornei | 74a1c05 | 2020-05-13 16:55:46 +0300 | [diff] [blame] | 1567 | u16 flowid; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1568 | int err; |
| 1569 | |
| 1570 | ch = container_of(napi, struct dpaa2_eth_channel, napi); |
Ioana Radulescu | d678be1 | 2019-03-01 17:47:24 +0000 | [diff] [blame] | 1571 | ch->xdp.res = 0; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1572 | priv = ch->priv; |
| 1573 | |
Ioana Ciornei | 0a25d92 | 2019-03-25 13:42:39 +0000 | [diff] [blame] | 1574 | INIT_LIST_HEAD(&rx_list); |
| 1575 | ch->rx_list = &rx_list; |
| 1576 | |
Ioana Ciocoi Radulescu | 68049a5 | 2018-10-08 14:16:31 +0000 | [diff] [blame] | 1577 | do { |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 1578 | err = dpaa2_eth_pull_channel(ch); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1579 | if (unlikely(err)) |
| 1580 | break; |
| 1581 | |
| 1582 | /* Refill pool if appropriate */ |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 1583 | dpaa2_eth_refill_pool(priv, ch, priv->bpid); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1584 | |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 1585 | store_cleaned = dpaa2_eth_consume_frames(ch, &fq); |
Ioana Radulescu | ef17bd7 | 2019-10-07 14:38:28 +0300 | [diff] [blame] | 1586 | if (store_cleaned <= 0) |
Ioana Ciocoi Radulescu | 569dac6 | 2018-11-14 11:48:36 +0000 | [diff] [blame] | 1587 | break; |
| 1588 | if (fq->type == DPAA2_RX_FQ) { |
Ioana Ciocoi Radulescu | 68049a5 | 2018-10-08 14:16:31 +0000 | [diff] [blame] | 1589 | rx_cleaned += store_cleaned; |
Ioana Ciornei | 74a1c05 | 2020-05-13 16:55:46 +0300 | [diff] [blame] | 1590 | flowid = fq->flowid; |
Ioana Ciocoi Radulescu | 569dac6 | 2018-11-14 11:48:36 +0000 | [diff] [blame] | 1591 | } else { |
Ioana Ciocoi Radulescu | 68049a5 | 2018-10-08 14:16:31 +0000 | [diff] [blame] | 1592 | txconf_cleaned += store_cleaned; |
Ioana Ciocoi Radulescu | 569dac6 | 2018-11-14 11:48:36 +0000 | [diff] [blame] | 1593 | /* We have a single Tx conf FQ on this channel */ |
| 1594 | txc_fq = fq; |
| 1595 | } |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1596 | |
Ioana Ciocoi Radulescu | 68049a5 | 2018-10-08 14:16:31 +0000 | [diff] [blame] | 1597 | /* If we either consumed the whole NAPI budget with Rx frames |
| 1598 | * or we reached the Tx confirmations threshold, we're done. |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1599 | */ |
Ioana Ciocoi Radulescu | 68049a5 | 2018-10-08 14:16:31 +0000 | [diff] [blame] | 1600 | if (rx_cleaned >= budget || |
Ioana Ciocoi Radulescu | 569dac6 | 2018-11-14 11:48:36 +0000 | [diff] [blame] | 1601 | txconf_cleaned >= DPAA2_ETH_TXCONF_PER_NAPI) { |
| 1602 | work_done = budget; |
| 1603 | goto out; |
| 1604 | } |
Ioana Ciocoi Radulescu | 68049a5 | 2018-10-08 14:16:31 +0000 | [diff] [blame] | 1605 | } while (store_cleaned); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1606 | |
Ioana Ciornei | fc398be | 2021-10-15 12:01:27 +0300 | [diff] [blame] | 1607 | /* Update NET DIM with the values for this CDAN */ |
| 1608 | dpaa2_io_update_net_dim(ch->dpio, ch->stats.frames_per_cdan, |
| 1609 | ch->stats.bytes_per_cdan); |
| 1610 | ch->stats.frames_per_cdan = 0; |
| 1611 | ch->stats.bytes_per_cdan = 0; |
| 1612 | |
Ioana Ciocoi Radulescu | 68049a5 | 2018-10-08 14:16:31 +0000 | [diff] [blame] | 1613 | /* We didn't consume the entire budget, so finish napi and |
| 1614 | * re-enable data availability notifications |
| 1615 | */ |
| 1616 | napi_complete_done(napi, rx_cleaned); |
| 1617 | do { |
| 1618 | err = dpaa2_io_service_rearm(ch->dpio, &ch->nctx); |
| 1619 | cpu_relax(); |
Ioana Radulescu | ef17bd7 | 2019-10-07 14:38:28 +0300 | [diff] [blame] | 1620 | } while (err == -EBUSY && retries++ < DPAA2_ETH_SWP_BUSY_RETRIES); |
Ioana Ciocoi Radulescu | 68049a5 | 2018-10-08 14:16:31 +0000 | [diff] [blame] | 1621 | WARN_ONCE(err, "CDAN notifications rearm failed on core %d", |
| 1622 | ch->nctx.desired_cpu); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1623 | |
Ioana Ciocoi Radulescu | 569dac6 | 2018-11-14 11:48:36 +0000 | [diff] [blame] | 1624 | work_done = max(rx_cleaned, 1); |
| 1625 | |
| 1626 | out: |
Ioana Ciornei | 0a25d92 | 2019-03-25 13:42:39 +0000 | [diff] [blame] | 1627 | netif_receive_skb_list(ch->rx_list); |
| 1628 | |
Ioana Radulescu | d678be1 | 2019-03-01 17:47:24 +0000 | [diff] [blame] | 1629 | if (txc_fq && txc_fq->dq_frames) { |
Ioana Ciocoi Radulescu | 569dac6 | 2018-11-14 11:48:36 +0000 | [diff] [blame] | 1630 | nq = netdev_get_tx_queue(priv->net_dev, txc_fq->flowid); |
| 1631 | netdev_tx_completed_queue(nq, txc_fq->dq_frames, |
| 1632 | txc_fq->dq_bytes); |
| 1633 | txc_fq->dq_frames = 0; |
| 1634 | txc_fq->dq_bytes = 0; |
| 1635 | } |
| 1636 | |
Ioana Radulescu | d678be1 | 2019-03-01 17:47:24 +0000 | [diff] [blame] | 1637 | if (ch->xdp.res & XDP_REDIRECT) |
| 1638 | xdp_do_flush_map(); |
Ioana Ciornei | 74a1c05 | 2020-05-13 16:55:46 +0300 | [diff] [blame] | 1639 | else if (rx_cleaned && ch->xdp.res & XDP_TX) |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 1640 | dpaa2_eth_xdp_tx_flush(priv, ch, &priv->fq[flowid]); |
Ioana Radulescu | d678be1 | 2019-03-01 17:47:24 +0000 | [diff] [blame] | 1641 | |
Ioana Ciocoi Radulescu | 569dac6 | 2018-11-14 11:48:36 +0000 | [diff] [blame] | 1642 | return work_done; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1643 | } |
| 1644 | |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 1645 | static void dpaa2_eth_enable_ch_napi(struct dpaa2_eth_priv *priv) |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1646 | { |
| 1647 | struct dpaa2_eth_channel *ch; |
| 1648 | int i; |
| 1649 | |
| 1650 | for (i = 0; i < priv->num_channels; i++) { |
| 1651 | ch = priv->channel[i]; |
| 1652 | napi_enable(&ch->napi); |
| 1653 | } |
| 1654 | } |
| 1655 | |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 1656 | static void dpaa2_eth_disable_ch_napi(struct dpaa2_eth_priv *priv) |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1657 | { |
| 1658 | struct dpaa2_eth_channel *ch; |
| 1659 | int i; |
| 1660 | |
| 1661 | for (i = 0; i < priv->num_channels; i++) { |
| 1662 | ch = priv->channel[i]; |
| 1663 | napi_disable(&ch->napi); |
| 1664 | } |
| 1665 | } |
| 1666 | |
Ioana Ciornei | 07beb16 | 2020-05-31 00:08:14 +0300 | [diff] [blame] | 1667 | void dpaa2_eth_set_rx_taildrop(struct dpaa2_eth_priv *priv, |
| 1668 | bool tx_pause, bool pfc) |
Ioana Radulescu | 8eb3cef | 2019-08-28 17:08:15 +0300 | [diff] [blame] | 1669 | { |
| 1670 | struct dpni_taildrop td = {0}; |
Ioana Radulescu | 685e39e | 2020-05-31 00:08:08 +0300 | [diff] [blame] | 1671 | struct dpaa2_eth_fq *fq; |
Ioana Radulescu | 8eb3cef | 2019-08-28 17:08:15 +0300 | [diff] [blame] | 1672 | int i, err; |
| 1673 | |
Ioana Ciornei | 07beb16 | 2020-05-31 00:08:14 +0300 | [diff] [blame] | 1674 | /* FQ taildrop: threshold is in bytes, per frame queue. Enabled if |
| 1675 | * flow control is disabled (as it might interfere with either the |
| 1676 | * buffer pool depletion trigger for pause frames or with the group |
| 1677 | * congestion trigger for PFC frames) |
| 1678 | */ |
Ioana Radulescu | 2c8d1c8 | 2020-05-31 00:08:11 +0300 | [diff] [blame] | 1679 | td.enable = !tx_pause; |
Ioana Ciornei | 07beb16 | 2020-05-31 00:08:14 +0300 | [diff] [blame] | 1680 | if (priv->rx_fqtd_enabled == td.enable) |
| 1681 | goto set_cgtd; |
Ioana Radulescu | 8eb3cef | 2019-08-28 17:08:15 +0300 | [diff] [blame] | 1682 | |
Ioana Radulescu | 2c8d1c8 | 2020-05-31 00:08:11 +0300 | [diff] [blame] | 1683 | td.threshold = DPAA2_ETH_FQ_TAILDROP_THRESH; |
| 1684 | td.units = DPNI_CONGESTION_UNIT_BYTES; |
Ioana Radulescu | 8eb3cef | 2019-08-28 17:08:15 +0300 | [diff] [blame] | 1685 | |
| 1686 | for (i = 0; i < priv->num_fqs; i++) { |
Ioana Radulescu | 685e39e | 2020-05-31 00:08:08 +0300 | [diff] [blame] | 1687 | fq = &priv->fq[i]; |
| 1688 | if (fq->type != DPAA2_RX_FQ) |
Ioana Radulescu | 8eb3cef | 2019-08-28 17:08:15 +0300 | [diff] [blame] | 1689 | continue; |
| 1690 | err = dpni_set_taildrop(priv->mc_io, 0, priv->mc_token, |
Ioana Radulescu | 685e39e | 2020-05-31 00:08:08 +0300 | [diff] [blame] | 1691 | DPNI_CP_QUEUE, DPNI_QUEUE_RX, |
| 1692 | fq->tc, fq->flowid, &td); |
Ioana Radulescu | 8eb3cef | 2019-08-28 17:08:15 +0300 | [diff] [blame] | 1693 | if (err) { |
| 1694 | netdev_err(priv->net_dev, |
Ioana Radulescu | 2c8d1c8 | 2020-05-31 00:08:11 +0300 | [diff] [blame] | 1695 | "dpni_set_taildrop(FQ) failed\n"); |
| 1696 | return; |
Ioana Radulescu | 8eb3cef | 2019-08-28 17:08:15 +0300 | [diff] [blame] | 1697 | } |
| 1698 | } |
| 1699 | |
Ioana Ciornei | 07beb16 | 2020-05-31 00:08:14 +0300 | [diff] [blame] | 1700 | priv->rx_fqtd_enabled = td.enable; |
| 1701 | |
| 1702 | set_cgtd: |
Ioana Radulescu | 2c8d1c8 | 2020-05-31 00:08:11 +0300 | [diff] [blame] | 1703 | /* Congestion group taildrop: threshold is in frames, per group |
| 1704 | * of FQs belonging to the same traffic class |
Ioana Ciornei | 07beb16 | 2020-05-31 00:08:14 +0300 | [diff] [blame] | 1705 | * Enabled if general Tx pause disabled or if PFCs are enabled |
| 1706 | * (congestion group threhsold for PFC generation is lower than the |
| 1707 | * CG taildrop threshold, so it won't interfere with it; we also |
| 1708 | * want frames in non-PFC enabled traffic classes to be kept in check) |
Ioana Radulescu | 2c8d1c8 | 2020-05-31 00:08:11 +0300 | [diff] [blame] | 1709 | */ |
Jiapeng Chong | b91b3a2 | 2021-02-02 18:02:37 +0800 | [diff] [blame] | 1710 | td.enable = !tx_pause || pfc; |
Ioana Ciornei | 07beb16 | 2020-05-31 00:08:14 +0300 | [diff] [blame] | 1711 | if (priv->rx_cgtd_enabled == td.enable) |
| 1712 | return; |
| 1713 | |
Ioana Radulescu | 2c8d1c8 | 2020-05-31 00:08:11 +0300 | [diff] [blame] | 1714 | td.threshold = DPAA2_ETH_CG_TAILDROP_THRESH(priv); |
| 1715 | td.units = DPNI_CONGESTION_UNIT_FRAMES; |
| 1716 | for (i = 0; i < dpaa2_eth_tc_count(priv); i++) { |
| 1717 | err = dpni_set_taildrop(priv->mc_io, 0, priv->mc_token, |
| 1718 | DPNI_CP_GROUP, DPNI_QUEUE_RX, |
| 1719 | i, 0, &td); |
| 1720 | if (err) { |
| 1721 | netdev_err(priv->net_dev, |
| 1722 | "dpni_set_taildrop(CG) failed\n"); |
| 1723 | return; |
| 1724 | } |
| 1725 | } |
| 1726 | |
Ioana Ciornei | 07beb16 | 2020-05-31 00:08:14 +0300 | [diff] [blame] | 1727 | priv->rx_cgtd_enabled = td.enable; |
Ioana Radulescu | 8eb3cef | 2019-08-28 17:08:15 +0300 | [diff] [blame] | 1728 | } |
| 1729 | |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 1730 | static int dpaa2_eth_link_state_update(struct dpaa2_eth_priv *priv) |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1731 | { |
Ioana Ciornei | 85b7a34 | 2018-10-12 16:27:33 +0000 | [diff] [blame] | 1732 | struct dpni_link_state state = {0}; |
Ioana Radulescu | 8eb3cef | 2019-08-28 17:08:15 +0300 | [diff] [blame] | 1733 | bool tx_pause; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1734 | int err; |
| 1735 | |
| 1736 | err = dpni_get_link_state(priv->mc_io, 0, priv->mc_token, &state); |
| 1737 | if (unlikely(err)) { |
| 1738 | netdev_err(priv->net_dev, |
| 1739 | "dpni_get_link_state() failed\n"); |
| 1740 | return err; |
| 1741 | } |
| 1742 | |
Ioana Radulescu | 8eb3cef | 2019-08-28 17:08:15 +0300 | [diff] [blame] | 1743 | /* If Tx pause frame settings have changed, we need to update |
| 1744 | * Rx FQ taildrop configuration as well. We configure taildrop |
| 1745 | * only when pause frame generation is disabled. |
| 1746 | */ |
Ioana Radulescu | ad054f2 | 2020-05-31 00:08:10 +0300 | [diff] [blame] | 1747 | tx_pause = dpaa2_eth_tx_pause_enabled(state.options); |
Ioana Ciornei | 07beb16 | 2020-05-31 00:08:14 +0300 | [diff] [blame] | 1748 | dpaa2_eth_set_rx_taildrop(priv, tx_pause, priv->pfc_enabled); |
Ioana Radulescu | 8eb3cef | 2019-08-28 17:08:15 +0300 | [diff] [blame] | 1749 | |
Ioana Ciornei | 7194792 | 2019-10-31 01:18:31 +0200 | [diff] [blame] | 1750 | /* When we manage the MAC/PHY using phylink there is no need |
| 1751 | * to manually update the netif_carrier. |
| 1752 | */ |
Ioana Ciornei | d87e606 | 2021-01-08 11:07:23 +0200 | [diff] [blame] | 1753 | if (dpaa2_eth_is_type_phy(priv)) |
Ioana Ciornei | 7194792 | 2019-10-31 01:18:31 +0200 | [diff] [blame] | 1754 | goto out; |
| 1755 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1756 | /* Chech link state; speed / duplex changes are not treated yet */ |
| 1757 | if (priv->link_state.up == state.up) |
Ioana Radulescu | cce62943 | 2019-08-28 17:08:14 +0300 | [diff] [blame] | 1758 | goto out; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1759 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1760 | if (state.up) { |
| 1761 | netif_carrier_on(priv->net_dev); |
| 1762 | netif_tx_start_all_queues(priv->net_dev); |
| 1763 | } else { |
| 1764 | netif_tx_stop_all_queues(priv->net_dev); |
| 1765 | netif_carrier_off(priv->net_dev); |
| 1766 | } |
| 1767 | |
Ioana Radulescu | 77160af | 2017-06-06 10:00:28 -0500 | [diff] [blame] | 1768 | netdev_info(priv->net_dev, "Link Event: state %s\n", |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1769 | state.up ? "up" : "down"); |
| 1770 | |
Ioana Radulescu | cce62943 | 2019-08-28 17:08:14 +0300 | [diff] [blame] | 1771 | out: |
| 1772 | priv->link_state = state; |
| 1773 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1774 | return 0; |
| 1775 | } |
| 1776 | |
| 1777 | static int dpaa2_eth_open(struct net_device *net_dev) |
| 1778 | { |
| 1779 | struct dpaa2_eth_priv *priv = netdev_priv(net_dev); |
| 1780 | int err; |
| 1781 | |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 1782 | err = dpaa2_eth_seed_pool(priv, priv->bpid); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1783 | if (err) { |
| 1784 | /* Not much to do; the buffer pool, though not filled up, |
| 1785 | * may still contain some buffers which would enable us |
| 1786 | * to limp on. |
| 1787 | */ |
| 1788 | netdev_err(net_dev, "Buffer seeding failed for DPBP %d (bpid=%d)\n", |
Ioana Radulescu | 05fa39c | 2017-06-06 10:00:37 -0500 | [diff] [blame] | 1789 | priv->dpbp_dev->obj_desc.id, priv->bpid); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1790 | } |
| 1791 | |
Ioana Ciornei | d87e606 | 2021-01-08 11:07:23 +0200 | [diff] [blame] | 1792 | if (!dpaa2_eth_is_type_phy(priv)) { |
Ioana Ciornei | 7194792 | 2019-10-31 01:18:31 +0200 | [diff] [blame] | 1793 | /* We'll only start the txqs when the link is actually ready; |
| 1794 | * make sure we don't race against the link up notification, |
| 1795 | * which may come immediately after dpni_enable(); |
| 1796 | */ |
| 1797 | netif_tx_stop_all_queues(net_dev); |
| 1798 | |
| 1799 | /* Also, explicitly set carrier off, otherwise |
| 1800 | * netif_carrier_ok() will return true and cause 'ip link show' |
| 1801 | * to report the LOWER_UP flag, even though the link |
| 1802 | * notification wasn't even received. |
| 1803 | */ |
| 1804 | netif_carrier_off(net_dev); |
| 1805 | } |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 1806 | dpaa2_eth_enable_ch_napi(priv); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1807 | |
| 1808 | err = dpni_enable(priv->mc_io, 0, priv->mc_token); |
| 1809 | if (err < 0) { |
| 1810 | netdev_err(net_dev, "dpni_enable() failed\n"); |
| 1811 | goto enable_err; |
| 1812 | } |
| 1813 | |
Ioana Ciornei | d87e606 | 2021-01-08 11:07:23 +0200 | [diff] [blame] | 1814 | if (dpaa2_eth_is_type_phy(priv)) |
Ioana Ciornei | 7194792 | 2019-10-31 01:18:31 +0200 | [diff] [blame] | 1815 | phylink_start(priv->mac->phylink); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1816 | |
| 1817 | return 0; |
| 1818 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1819 | enable_err: |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 1820 | dpaa2_eth_disable_ch_napi(priv); |
| 1821 | dpaa2_eth_drain_pool(priv); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1822 | return err; |
| 1823 | } |
| 1824 | |
Ioana Ciocoi Radulescu | 68d7431 | 2019-01-16 16:51:44 +0000 | [diff] [blame] | 1825 | /* Total number of in-flight frames on ingress queues */ |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 1826 | static u32 dpaa2_eth_ingress_fq_count(struct dpaa2_eth_priv *priv) |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1827 | { |
Ioana Ciocoi Radulescu | 68d7431 | 2019-01-16 16:51:44 +0000 | [diff] [blame] | 1828 | struct dpaa2_eth_fq *fq; |
| 1829 | u32 fcnt = 0, bcnt = 0, total = 0; |
| 1830 | int i, err; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1831 | |
Ioana Ciocoi Radulescu | 68d7431 | 2019-01-16 16:51:44 +0000 | [diff] [blame] | 1832 | for (i = 0; i < priv->num_fqs; i++) { |
| 1833 | fq = &priv->fq[i]; |
| 1834 | err = dpaa2_io_query_fq_count(NULL, fq->fqid, &fcnt, &bcnt); |
| 1835 | if (err) { |
| 1836 | netdev_warn(priv->net_dev, "query_fq_count failed"); |
| 1837 | break; |
| 1838 | } |
| 1839 | total += fcnt; |
| 1840 | } |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1841 | |
| 1842 | return total; |
| 1843 | } |
| 1844 | |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 1845 | static void dpaa2_eth_wait_for_ingress_fq_empty(struct dpaa2_eth_priv *priv) |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1846 | { |
Ioana Ciocoi Radulescu | 68d7431 | 2019-01-16 16:51:44 +0000 | [diff] [blame] | 1847 | int retries = 10; |
| 1848 | u32 pending; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1849 | |
Ioana Ciocoi Radulescu | 68d7431 | 2019-01-16 16:51:44 +0000 | [diff] [blame] | 1850 | do { |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 1851 | pending = dpaa2_eth_ingress_fq_count(priv); |
Ioana Ciocoi Radulescu | 68d7431 | 2019-01-16 16:51:44 +0000 | [diff] [blame] | 1852 | if (pending) |
| 1853 | msleep(100); |
| 1854 | } while (pending && --retries); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1855 | } |
| 1856 | |
Ioana Radulescu | 52b6a4f | 2019-09-02 13:23:19 +0300 | [diff] [blame] | 1857 | #define DPNI_TX_PENDING_VER_MAJOR 7 |
| 1858 | #define DPNI_TX_PENDING_VER_MINOR 13 |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 1859 | static void dpaa2_eth_wait_for_egress_fq_empty(struct dpaa2_eth_priv *priv) |
Ioana Radulescu | 52b6a4f | 2019-09-02 13:23:19 +0300 | [diff] [blame] | 1860 | { |
| 1861 | union dpni_statistics stats; |
| 1862 | int retries = 10; |
| 1863 | int err; |
| 1864 | |
| 1865 | if (dpaa2_eth_cmp_dpni_ver(priv, DPNI_TX_PENDING_VER_MAJOR, |
| 1866 | DPNI_TX_PENDING_VER_MINOR) < 0) |
| 1867 | goto out; |
| 1868 | |
| 1869 | do { |
| 1870 | err = dpni_get_statistics(priv->mc_io, 0, priv->mc_token, 6, |
| 1871 | &stats); |
| 1872 | if (err) |
| 1873 | goto out; |
| 1874 | if (stats.page_6.tx_pending_frames == 0) |
| 1875 | return; |
| 1876 | } while (--retries); |
| 1877 | |
| 1878 | out: |
| 1879 | msleep(500); |
| 1880 | } |
| 1881 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1882 | static int dpaa2_eth_stop(struct net_device *net_dev) |
| 1883 | { |
| 1884 | struct dpaa2_eth_priv *priv = netdev_priv(net_dev); |
Ioana Ciornei | 85b7a34 | 2018-10-12 16:27:33 +0000 | [diff] [blame] | 1885 | int dpni_enabled = 0; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1886 | int retries = 10; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1887 | |
Ioana Ciornei | d87e606 | 2021-01-08 11:07:23 +0200 | [diff] [blame] | 1888 | if (dpaa2_eth_is_type_phy(priv)) { |
| 1889 | phylink_stop(priv->mac->phylink); |
| 1890 | } else { |
Ioana Ciornei | 7194792 | 2019-10-31 01:18:31 +0200 | [diff] [blame] | 1891 | netif_tx_stop_all_queues(net_dev); |
| 1892 | netif_carrier_off(net_dev); |
Ioana Ciornei | 7194792 | 2019-10-31 01:18:31 +0200 | [diff] [blame] | 1893 | } |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1894 | |
Ioana Ciocoi Radulescu | 68d7431 | 2019-01-16 16:51:44 +0000 | [diff] [blame] | 1895 | /* On dpni_disable(), the MC firmware will: |
| 1896 | * - stop MAC Rx and wait for all Rx frames to be enqueued to software |
| 1897 | * - cut off WRIOP dequeues from egress FQs and wait until transmission |
| 1898 | * of all in flight Tx frames is finished (and corresponding Tx conf |
| 1899 | * frames are enqueued back to software) |
| 1900 | * |
| 1901 | * Before calling dpni_disable(), we wait for all Tx frames to arrive |
| 1902 | * on WRIOP. After it finishes, wait until all remaining frames on Rx |
| 1903 | * and Tx conf queues are consumed on NAPI poll. |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1904 | */ |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 1905 | dpaa2_eth_wait_for_egress_fq_empty(priv); |
Ioana Ciocoi Radulescu | 68d7431 | 2019-01-16 16:51:44 +0000 | [diff] [blame] | 1906 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1907 | do { |
| 1908 | dpni_disable(priv->mc_io, 0, priv->mc_token); |
| 1909 | dpni_is_enabled(priv->mc_io, 0, priv->mc_token, &dpni_enabled); |
| 1910 | if (dpni_enabled) |
| 1911 | /* Allow the hardware some slack */ |
| 1912 | msleep(100); |
| 1913 | } while (dpni_enabled && --retries); |
| 1914 | if (!retries) { |
| 1915 | netdev_warn(net_dev, "Retry count exceeded disabling DPNI\n"); |
| 1916 | /* Must go on and disable NAPI nonetheless, so we don't crash at |
| 1917 | * the next "ifconfig up" |
| 1918 | */ |
| 1919 | } |
| 1920 | |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 1921 | dpaa2_eth_wait_for_ingress_fq_empty(priv); |
| 1922 | dpaa2_eth_disable_ch_napi(priv); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1923 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1924 | /* Empty the buffer pool */ |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 1925 | dpaa2_eth_drain_pool(priv); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1926 | |
Ioana Ciornei | d70446e | 2020-06-29 21:47:11 +0300 | [diff] [blame] | 1927 | /* Empty the Scatter-Gather Buffer cache */ |
| 1928 | dpaa2_eth_sgt_cache_drain(priv); |
| 1929 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1930 | return 0; |
| 1931 | } |
| 1932 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1933 | static int dpaa2_eth_set_addr(struct net_device *net_dev, void *addr) |
| 1934 | { |
| 1935 | struct dpaa2_eth_priv *priv = netdev_priv(net_dev); |
| 1936 | struct device *dev = net_dev->dev.parent; |
| 1937 | int err; |
| 1938 | |
| 1939 | err = eth_mac_addr(net_dev, addr); |
| 1940 | if (err < 0) { |
| 1941 | dev_err(dev, "eth_mac_addr() failed (%d)\n", err); |
| 1942 | return err; |
| 1943 | } |
| 1944 | |
| 1945 | err = dpni_set_primary_mac_addr(priv->mc_io, 0, priv->mc_token, |
| 1946 | net_dev->dev_addr); |
| 1947 | if (err) { |
| 1948 | dev_err(dev, "dpni_set_primary_mac_addr() failed (%d)\n", err); |
| 1949 | return err; |
| 1950 | } |
| 1951 | |
| 1952 | return 0; |
| 1953 | } |
| 1954 | |
| 1955 | /** Fill in counters maintained by the GPP driver. These may be different from |
| 1956 | * the hardware counters obtained by ethtool. |
| 1957 | */ |
Ioana Radulescu | acbff8e | 2017-06-06 10:00:24 -0500 | [diff] [blame] | 1958 | static void dpaa2_eth_get_stats(struct net_device *net_dev, |
| 1959 | struct rtnl_link_stats64 *stats) |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1960 | { |
| 1961 | struct dpaa2_eth_priv *priv = netdev_priv(net_dev); |
| 1962 | struct rtnl_link_stats64 *percpu_stats; |
| 1963 | u64 *cpustats; |
| 1964 | u64 *netstats = (u64 *)stats; |
| 1965 | int i, j; |
| 1966 | int num = sizeof(struct rtnl_link_stats64) / sizeof(u64); |
| 1967 | |
| 1968 | for_each_possible_cpu(i) { |
| 1969 | percpu_stats = per_cpu_ptr(priv->percpu_stats, i); |
| 1970 | cpustats = (u64 *)percpu_stats; |
| 1971 | for (j = 0; j < num; j++) |
| 1972 | netstats[j] += cpustats[j]; |
| 1973 | } |
| 1974 | } |
| 1975 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1976 | /* Copy mac unicast addresses from @net_dev to @priv. |
| 1977 | * Its sole purpose is to make dpaa2_eth_set_rx_mode() more readable. |
| 1978 | */ |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 1979 | static void dpaa2_eth_add_uc_hw_addr(const struct net_device *net_dev, |
| 1980 | struct dpaa2_eth_priv *priv) |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1981 | { |
| 1982 | struct netdev_hw_addr *ha; |
| 1983 | int err; |
| 1984 | |
| 1985 | netdev_for_each_uc_addr(ha, net_dev) { |
| 1986 | err = dpni_add_mac_addr(priv->mc_io, 0, priv->mc_token, |
| 1987 | ha->addr); |
| 1988 | if (err) |
| 1989 | netdev_warn(priv->net_dev, |
| 1990 | "Could not add ucast MAC %pM to the filtering table (err %d)\n", |
| 1991 | ha->addr, err); |
| 1992 | } |
| 1993 | } |
| 1994 | |
| 1995 | /* Copy mac multicast addresses from @net_dev to @priv |
| 1996 | * Its sole purpose is to make dpaa2_eth_set_rx_mode() more readable. |
| 1997 | */ |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 1998 | static void dpaa2_eth_add_mc_hw_addr(const struct net_device *net_dev, |
| 1999 | struct dpaa2_eth_priv *priv) |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2000 | { |
| 2001 | struct netdev_hw_addr *ha; |
| 2002 | int err; |
| 2003 | |
| 2004 | netdev_for_each_mc_addr(ha, net_dev) { |
| 2005 | err = dpni_add_mac_addr(priv->mc_io, 0, priv->mc_token, |
| 2006 | ha->addr); |
| 2007 | if (err) |
| 2008 | netdev_warn(priv->net_dev, |
| 2009 | "Could not add mcast MAC %pM to the filtering table (err %d)\n", |
| 2010 | ha->addr, err); |
| 2011 | } |
| 2012 | } |
| 2013 | |
Ionut-robert Aron | 70b32d8 | 2021-01-11 19:07:25 +0200 | [diff] [blame] | 2014 | static int dpaa2_eth_rx_add_vid(struct net_device *net_dev, |
| 2015 | __be16 vlan_proto, u16 vid) |
| 2016 | { |
| 2017 | struct dpaa2_eth_priv *priv = netdev_priv(net_dev); |
| 2018 | int err; |
| 2019 | |
| 2020 | err = dpni_add_vlan_id(priv->mc_io, 0, priv->mc_token, |
| 2021 | vid, 0, 0, 0); |
| 2022 | |
| 2023 | if (err) { |
| 2024 | netdev_warn(priv->net_dev, |
| 2025 | "Could not add the vlan id %u\n", |
| 2026 | vid); |
| 2027 | return err; |
| 2028 | } |
| 2029 | |
| 2030 | return 0; |
| 2031 | } |
| 2032 | |
| 2033 | static int dpaa2_eth_rx_kill_vid(struct net_device *net_dev, |
| 2034 | __be16 vlan_proto, u16 vid) |
| 2035 | { |
| 2036 | struct dpaa2_eth_priv *priv = netdev_priv(net_dev); |
| 2037 | int err; |
| 2038 | |
| 2039 | err = dpni_remove_vlan_id(priv->mc_io, 0, priv->mc_token, vid); |
| 2040 | |
| 2041 | if (err) { |
| 2042 | netdev_warn(priv->net_dev, |
| 2043 | "Could not remove the vlan id %u\n", |
| 2044 | vid); |
| 2045 | return err; |
| 2046 | } |
| 2047 | |
| 2048 | return 0; |
| 2049 | } |
| 2050 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2051 | static void dpaa2_eth_set_rx_mode(struct net_device *net_dev) |
| 2052 | { |
| 2053 | struct dpaa2_eth_priv *priv = netdev_priv(net_dev); |
| 2054 | int uc_count = netdev_uc_count(net_dev); |
| 2055 | int mc_count = netdev_mc_count(net_dev); |
| 2056 | u8 max_mac = priv->dpni_attrs.mac_filter_entries; |
| 2057 | u32 options = priv->dpni_attrs.options; |
| 2058 | u16 mc_token = priv->mc_token; |
| 2059 | struct fsl_mc_io *mc_io = priv->mc_io; |
| 2060 | int err; |
| 2061 | |
| 2062 | /* Basic sanity checks; these probably indicate a misconfiguration */ |
| 2063 | if (options & DPNI_OPT_NO_MAC_FILTER && max_mac != 0) |
| 2064 | netdev_info(net_dev, |
| 2065 | "mac_filter_entries=%d, DPNI_OPT_NO_MAC_FILTER option must be disabled\n", |
| 2066 | max_mac); |
| 2067 | |
| 2068 | /* Force promiscuous if the uc or mc counts exceed our capabilities. */ |
| 2069 | if (uc_count > max_mac) { |
| 2070 | netdev_info(net_dev, |
| 2071 | "Unicast addr count reached %d, max allowed is %d; forcing promisc\n", |
| 2072 | uc_count, max_mac); |
| 2073 | goto force_promisc; |
| 2074 | } |
| 2075 | if (mc_count + uc_count > max_mac) { |
| 2076 | netdev_info(net_dev, |
| 2077 | "Unicast + multicast addr count reached %d, max allowed is %d; forcing promisc\n", |
| 2078 | uc_count + mc_count, max_mac); |
| 2079 | goto force_mc_promisc; |
| 2080 | } |
| 2081 | |
| 2082 | /* Adjust promisc settings due to flag combinations */ |
| 2083 | if (net_dev->flags & IFF_PROMISC) |
| 2084 | goto force_promisc; |
| 2085 | if (net_dev->flags & IFF_ALLMULTI) { |
| 2086 | /* First, rebuild unicast filtering table. This should be done |
| 2087 | * in promisc mode, in order to avoid frame loss while we |
| 2088 | * progressively add entries to the table. |
| 2089 | * We don't know whether we had been in promisc already, and |
| 2090 | * making an MC call to find out is expensive; so set uc promisc |
| 2091 | * nonetheless. |
| 2092 | */ |
| 2093 | err = dpni_set_unicast_promisc(mc_io, 0, mc_token, 1); |
| 2094 | if (err) |
| 2095 | netdev_warn(net_dev, "Can't set uc promisc\n"); |
| 2096 | |
| 2097 | /* Actual uc table reconstruction. */ |
| 2098 | err = dpni_clear_mac_filters(mc_io, 0, mc_token, 1, 0); |
| 2099 | if (err) |
| 2100 | netdev_warn(net_dev, "Can't clear uc filters\n"); |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 2101 | dpaa2_eth_add_uc_hw_addr(net_dev, priv); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2102 | |
| 2103 | /* Finally, clear uc promisc and set mc promisc as requested. */ |
| 2104 | err = dpni_set_unicast_promisc(mc_io, 0, mc_token, 0); |
| 2105 | if (err) |
| 2106 | netdev_warn(net_dev, "Can't clear uc promisc\n"); |
| 2107 | goto force_mc_promisc; |
| 2108 | } |
| 2109 | |
| 2110 | /* Neither unicast, nor multicast promisc will be on... eventually. |
| 2111 | * For now, rebuild mac filtering tables while forcing both of them on. |
| 2112 | */ |
| 2113 | err = dpni_set_unicast_promisc(mc_io, 0, mc_token, 1); |
| 2114 | if (err) |
| 2115 | netdev_warn(net_dev, "Can't set uc promisc (%d)\n", err); |
| 2116 | err = dpni_set_multicast_promisc(mc_io, 0, mc_token, 1); |
| 2117 | if (err) |
| 2118 | netdev_warn(net_dev, "Can't set mc promisc (%d)\n", err); |
| 2119 | |
| 2120 | /* Actual mac filtering tables reconstruction */ |
| 2121 | err = dpni_clear_mac_filters(mc_io, 0, mc_token, 1, 1); |
| 2122 | if (err) |
| 2123 | netdev_warn(net_dev, "Can't clear mac filters\n"); |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 2124 | dpaa2_eth_add_mc_hw_addr(net_dev, priv); |
| 2125 | dpaa2_eth_add_uc_hw_addr(net_dev, priv); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2126 | |
| 2127 | /* Now we can clear both ucast and mcast promisc, without risking |
| 2128 | * to drop legitimate frames anymore. |
| 2129 | */ |
| 2130 | err = dpni_set_unicast_promisc(mc_io, 0, mc_token, 0); |
| 2131 | if (err) |
| 2132 | netdev_warn(net_dev, "Can't clear ucast promisc\n"); |
| 2133 | err = dpni_set_multicast_promisc(mc_io, 0, mc_token, 0); |
| 2134 | if (err) |
| 2135 | netdev_warn(net_dev, "Can't clear mcast promisc\n"); |
| 2136 | |
| 2137 | return; |
| 2138 | |
| 2139 | force_promisc: |
| 2140 | err = dpni_set_unicast_promisc(mc_io, 0, mc_token, 1); |
| 2141 | if (err) |
| 2142 | netdev_warn(net_dev, "Can't set ucast promisc\n"); |
| 2143 | force_mc_promisc: |
| 2144 | err = dpni_set_multicast_promisc(mc_io, 0, mc_token, 1); |
| 2145 | if (err) |
| 2146 | netdev_warn(net_dev, "Can't set mcast promisc\n"); |
| 2147 | } |
| 2148 | |
| 2149 | static int dpaa2_eth_set_features(struct net_device *net_dev, |
| 2150 | netdev_features_t features) |
| 2151 | { |
| 2152 | struct dpaa2_eth_priv *priv = netdev_priv(net_dev); |
| 2153 | netdev_features_t changed = features ^ net_dev->features; |
| 2154 | bool enable; |
| 2155 | int err; |
| 2156 | |
Ionut-robert Aron | 70b32d8 | 2021-01-11 19:07:25 +0200 | [diff] [blame] | 2157 | if (changed & NETIF_F_HW_VLAN_CTAG_FILTER) { |
| 2158 | enable = !!(features & NETIF_F_HW_VLAN_CTAG_FILTER); |
| 2159 | err = dpaa2_eth_set_rx_vlan_filtering(priv, enable); |
| 2160 | if (err) |
| 2161 | return err; |
| 2162 | } |
| 2163 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2164 | if (changed & NETIF_F_RXCSUM) { |
| 2165 | enable = !!(features & NETIF_F_RXCSUM); |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 2166 | err = dpaa2_eth_set_rx_csum(priv, enable); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2167 | if (err) |
| 2168 | return err; |
| 2169 | } |
| 2170 | |
| 2171 | if (changed & (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM)) { |
| 2172 | enable = !!(features & (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM)); |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 2173 | err = dpaa2_eth_set_tx_csum(priv, enable); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2174 | if (err) |
| 2175 | return err; |
| 2176 | } |
| 2177 | |
| 2178 | return 0; |
| 2179 | } |
| 2180 | |
Ioana Radulescu | 859f998 | 2018-04-26 18:23:47 +0800 | [diff] [blame] | 2181 | static int dpaa2_eth_ts_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) |
| 2182 | { |
| 2183 | struct dpaa2_eth_priv *priv = netdev_priv(dev); |
| 2184 | struct hwtstamp_config config; |
| 2185 | |
Yangbo Lu | c552118 | 2020-09-18 17:08:02 +0800 | [diff] [blame] | 2186 | if (!dpaa2_ptp) |
| 2187 | return -EINVAL; |
| 2188 | |
Ioana Radulescu | 859f998 | 2018-04-26 18:23:47 +0800 | [diff] [blame] | 2189 | if (copy_from_user(&config, rq->ifr_data, sizeof(config))) |
| 2190 | return -EFAULT; |
| 2191 | |
| 2192 | switch (config.tx_type) { |
| 2193 | case HWTSTAMP_TX_OFF: |
Ioana Radulescu | 859f998 | 2018-04-26 18:23:47 +0800 | [diff] [blame] | 2194 | case HWTSTAMP_TX_ON: |
Yangbo Lu | c552118 | 2020-09-18 17:08:02 +0800 | [diff] [blame] | 2195 | case HWTSTAMP_TX_ONESTEP_SYNC: |
Yangbo Lu | 1cf773b | 2020-09-18 17:08:01 +0800 | [diff] [blame] | 2196 | priv->tx_tstamp_type = config.tx_type; |
Ioana Radulescu | 859f998 | 2018-04-26 18:23:47 +0800 | [diff] [blame] | 2197 | break; |
| 2198 | default: |
| 2199 | return -ERANGE; |
| 2200 | } |
| 2201 | |
| 2202 | if (config.rx_filter == HWTSTAMP_FILTER_NONE) { |
| 2203 | priv->rx_tstamp = false; |
| 2204 | } else { |
| 2205 | priv->rx_tstamp = true; |
| 2206 | /* TS is set for all frame types, not only those requested */ |
| 2207 | config.rx_filter = HWTSTAMP_FILTER_ALL; |
| 2208 | } |
| 2209 | |
| 2210 | return copy_to_user(rq->ifr_data, &config, sizeof(config)) ? |
| 2211 | -EFAULT : 0; |
| 2212 | } |
| 2213 | |
| 2214 | static int dpaa2_eth_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) |
| 2215 | { |
Russell King | 4a84182 | 2020-02-27 12:00:21 +0000 | [diff] [blame] | 2216 | struct dpaa2_eth_priv *priv = netdev_priv(dev); |
| 2217 | |
Ioana Radulescu | 859f998 | 2018-04-26 18:23:47 +0800 | [diff] [blame] | 2218 | if (cmd == SIOCSHWTSTAMP) |
| 2219 | return dpaa2_eth_ts_ioctl(dev, rq, cmd); |
| 2220 | |
Ioana Ciornei | d87e606 | 2021-01-08 11:07:23 +0200 | [diff] [blame] | 2221 | if (dpaa2_eth_is_type_phy(priv)) |
Russell King | 4a84182 | 2020-02-27 12:00:21 +0000 | [diff] [blame] | 2222 | return phylink_mii_ioctl(priv->mac->phylink, rq, cmd); |
| 2223 | |
| 2224 | return -EOPNOTSUPP; |
Ioana Radulescu | 859f998 | 2018-04-26 18:23:47 +0800 | [diff] [blame] | 2225 | } |
| 2226 | |
Ioana Ciocoi Radulescu | 7e273a8 | 2018-11-26 16:27:29 +0000 | [diff] [blame] | 2227 | static bool xdp_mtu_valid(struct dpaa2_eth_priv *priv, int mtu) |
| 2228 | { |
| 2229 | int mfl, linear_mfl; |
| 2230 | |
| 2231 | mfl = DPAA2_ETH_L2_MAX_FRM(mtu); |
Ioana Ciornei | efa6a7d | 2020-05-15 15:30:22 +0300 | [diff] [blame] | 2232 | linear_mfl = priv->rx_buf_size - DPAA2_ETH_RX_HWA_SIZE - |
Ioana Ciocoi Radulescu | 7b1eea1 | 2018-11-26 16:27:30 +0000 | [diff] [blame] | 2233 | dpaa2_eth_rx_head_room(priv) - XDP_PACKET_HEADROOM; |
Ioana Ciocoi Radulescu | 7e273a8 | 2018-11-26 16:27:29 +0000 | [diff] [blame] | 2234 | |
| 2235 | if (mfl > linear_mfl) { |
| 2236 | netdev_warn(priv->net_dev, "Maximum MTU for XDP is %d\n", |
| 2237 | linear_mfl - VLAN_ETH_HLEN); |
| 2238 | return false; |
| 2239 | } |
| 2240 | |
| 2241 | return true; |
| 2242 | } |
| 2243 | |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 2244 | static int dpaa2_eth_set_rx_mfl(struct dpaa2_eth_priv *priv, int mtu, bool has_xdp) |
Ioana Ciocoi Radulescu | 7e273a8 | 2018-11-26 16:27:29 +0000 | [diff] [blame] | 2245 | { |
| 2246 | int mfl, err; |
| 2247 | |
| 2248 | /* We enforce a maximum Rx frame length based on MTU only if we have |
| 2249 | * an XDP program attached (in order to avoid Rx S/G frames). |
| 2250 | * Otherwise, we accept all incoming frames as long as they are not |
| 2251 | * larger than maximum size supported in hardware |
| 2252 | */ |
| 2253 | if (has_xdp) |
| 2254 | mfl = DPAA2_ETH_L2_MAX_FRM(mtu); |
| 2255 | else |
| 2256 | mfl = DPAA2_ETH_MFL; |
| 2257 | |
| 2258 | err = dpni_set_max_frame_length(priv->mc_io, 0, priv->mc_token, mfl); |
| 2259 | if (err) { |
| 2260 | netdev_err(priv->net_dev, "dpni_set_max_frame_length failed\n"); |
| 2261 | return err; |
| 2262 | } |
| 2263 | |
| 2264 | return 0; |
| 2265 | } |
| 2266 | |
| 2267 | static int dpaa2_eth_change_mtu(struct net_device *dev, int new_mtu) |
| 2268 | { |
| 2269 | struct dpaa2_eth_priv *priv = netdev_priv(dev); |
| 2270 | int err; |
| 2271 | |
| 2272 | if (!priv->xdp_prog) |
| 2273 | goto out; |
| 2274 | |
| 2275 | if (!xdp_mtu_valid(priv, new_mtu)) |
| 2276 | return -EINVAL; |
| 2277 | |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 2278 | err = dpaa2_eth_set_rx_mfl(priv, new_mtu, true); |
Ioana Ciocoi Radulescu | 7e273a8 | 2018-11-26 16:27:29 +0000 | [diff] [blame] | 2279 | if (err) |
| 2280 | return err; |
| 2281 | |
| 2282 | out: |
| 2283 | dev->mtu = new_mtu; |
| 2284 | return 0; |
| 2285 | } |
| 2286 | |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 2287 | static int dpaa2_eth_update_rx_buffer_headroom(struct dpaa2_eth_priv *priv, bool has_xdp) |
Ioana Ciocoi Radulescu | 7b1eea1 | 2018-11-26 16:27:30 +0000 | [diff] [blame] | 2288 | { |
| 2289 | struct dpni_buffer_layout buf_layout = {0}; |
| 2290 | int err; |
| 2291 | |
| 2292 | err = dpni_get_buffer_layout(priv->mc_io, 0, priv->mc_token, |
| 2293 | DPNI_QUEUE_RX, &buf_layout); |
| 2294 | if (err) { |
| 2295 | netdev_err(priv->net_dev, "dpni_get_buffer_layout failed\n"); |
| 2296 | return err; |
| 2297 | } |
| 2298 | |
| 2299 | /* Reserve extra headroom for XDP header size changes */ |
| 2300 | buf_layout.data_head_room = dpaa2_eth_rx_head_room(priv) + |
| 2301 | (has_xdp ? XDP_PACKET_HEADROOM : 0); |
| 2302 | buf_layout.options = DPNI_BUF_LAYOUT_OPT_DATA_HEAD_ROOM; |
| 2303 | err = dpni_set_buffer_layout(priv->mc_io, 0, priv->mc_token, |
| 2304 | DPNI_QUEUE_RX, &buf_layout); |
| 2305 | if (err) { |
| 2306 | netdev_err(priv->net_dev, "dpni_set_buffer_layout failed\n"); |
| 2307 | return err; |
| 2308 | } |
| 2309 | |
| 2310 | return 0; |
| 2311 | } |
| 2312 | |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 2313 | static int dpaa2_eth_setup_xdp(struct net_device *dev, struct bpf_prog *prog) |
Ioana Ciocoi Radulescu | 7e273a8 | 2018-11-26 16:27:29 +0000 | [diff] [blame] | 2314 | { |
| 2315 | struct dpaa2_eth_priv *priv = netdev_priv(dev); |
| 2316 | struct dpaa2_eth_channel *ch; |
| 2317 | struct bpf_prog *old; |
| 2318 | bool up, need_update; |
| 2319 | int i, err; |
| 2320 | |
| 2321 | if (prog && !xdp_mtu_valid(priv, dev->mtu)) |
| 2322 | return -EINVAL; |
| 2323 | |
Andrii Nakryiko | 85192db | 2019-11-17 09:28:03 -0800 | [diff] [blame] | 2324 | if (prog) |
| 2325 | bpf_prog_add(prog, priv->num_channels); |
Ioana Ciocoi Radulescu | 7e273a8 | 2018-11-26 16:27:29 +0000 | [diff] [blame] | 2326 | |
| 2327 | up = netif_running(dev); |
| 2328 | need_update = (!!priv->xdp_prog != !!prog); |
| 2329 | |
| 2330 | if (up) |
| 2331 | dpaa2_eth_stop(dev); |
| 2332 | |
Ioana Ciocoi Radulescu | 7b1eea1 | 2018-11-26 16:27:30 +0000 | [diff] [blame] | 2333 | /* While in xdp mode, enforce a maximum Rx frame size based on MTU. |
| 2334 | * Also, when switching between xdp/non-xdp modes we need to reconfigure |
| 2335 | * our Rx buffer layout. Buffer pool was drained on dpaa2_eth_stop, |
| 2336 | * so we are sure no old format buffers will be used from now on. |
| 2337 | */ |
Ioana Ciocoi Radulescu | 7e273a8 | 2018-11-26 16:27:29 +0000 | [diff] [blame] | 2338 | if (need_update) { |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 2339 | err = dpaa2_eth_set_rx_mfl(priv, dev->mtu, !!prog); |
Ioana Ciocoi Radulescu | 7e273a8 | 2018-11-26 16:27:29 +0000 | [diff] [blame] | 2340 | if (err) |
| 2341 | goto out_err; |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 2342 | err = dpaa2_eth_update_rx_buffer_headroom(priv, !!prog); |
Ioana Ciocoi Radulescu | 7b1eea1 | 2018-11-26 16:27:30 +0000 | [diff] [blame] | 2343 | if (err) |
| 2344 | goto out_err; |
Ioana Ciocoi Radulescu | 7e273a8 | 2018-11-26 16:27:29 +0000 | [diff] [blame] | 2345 | } |
| 2346 | |
| 2347 | old = xchg(&priv->xdp_prog, prog); |
| 2348 | if (old) |
| 2349 | bpf_prog_put(old); |
| 2350 | |
| 2351 | for (i = 0; i < priv->num_channels; i++) { |
| 2352 | ch = priv->channel[i]; |
| 2353 | old = xchg(&ch->xdp.prog, prog); |
| 2354 | if (old) |
| 2355 | bpf_prog_put(old); |
| 2356 | } |
| 2357 | |
| 2358 | if (up) { |
| 2359 | err = dpaa2_eth_open(dev); |
| 2360 | if (err) |
| 2361 | return err; |
| 2362 | } |
| 2363 | |
| 2364 | return 0; |
| 2365 | |
| 2366 | out_err: |
| 2367 | if (prog) |
| 2368 | bpf_prog_sub(prog, priv->num_channels); |
| 2369 | if (up) |
| 2370 | dpaa2_eth_open(dev); |
| 2371 | |
| 2372 | return err; |
| 2373 | } |
| 2374 | |
| 2375 | static int dpaa2_eth_xdp(struct net_device *dev, struct netdev_bpf *xdp) |
| 2376 | { |
Ioana Ciocoi Radulescu | 7e273a8 | 2018-11-26 16:27:29 +0000 | [diff] [blame] | 2377 | switch (xdp->command) { |
| 2378 | case XDP_SETUP_PROG: |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 2379 | return dpaa2_eth_setup_xdp(dev, xdp->prog); |
Ioana Ciocoi Radulescu | 7e273a8 | 2018-11-26 16:27:29 +0000 | [diff] [blame] | 2380 | default: |
| 2381 | return -EINVAL; |
| 2382 | } |
| 2383 | |
| 2384 | return 0; |
| 2385 | } |
| 2386 | |
Ioana Ciornei | 6aa40b9 | 2020-04-22 15:05:12 +0300 | [diff] [blame] | 2387 | static int dpaa2_eth_xdp_create_fd(struct net_device *net_dev, |
| 2388 | struct xdp_frame *xdpf, |
| 2389 | struct dpaa2_fd *fd) |
Ioana Radulescu | d678be1 | 2019-03-01 17:47:24 +0000 | [diff] [blame] | 2390 | { |
Ioana Radulescu | d678be1 | 2019-03-01 17:47:24 +0000 | [diff] [blame] | 2391 | struct device *dev = net_dev->dev.parent; |
Ioana Radulescu | d678be1 | 2019-03-01 17:47:24 +0000 | [diff] [blame] | 2392 | unsigned int needed_headroom; |
| 2393 | struct dpaa2_eth_swa *swa; |
Ioana Radulescu | d678be1 | 2019-03-01 17:47:24 +0000 | [diff] [blame] | 2394 | void *buffer_start, *aligned_start; |
| 2395 | dma_addr_t addr; |
Ioana Radulescu | d678be1 | 2019-03-01 17:47:24 +0000 | [diff] [blame] | 2396 | |
| 2397 | /* We require a minimum headroom to be able to transmit the frame. |
| 2398 | * Otherwise return an error and let the original net_device handle it |
| 2399 | */ |
Yangbo Lu | 1cf773b | 2020-09-18 17:08:01 +0800 | [diff] [blame] | 2400 | needed_headroom = dpaa2_eth_needed_headroom(NULL); |
Ioana Radulescu | d678be1 | 2019-03-01 17:47:24 +0000 | [diff] [blame] | 2401 | if (xdpf->headroom < needed_headroom) |
| 2402 | return -EINVAL; |
| 2403 | |
Ioana Radulescu | d678be1 | 2019-03-01 17:47:24 +0000 | [diff] [blame] | 2404 | /* Setup the FD fields */ |
Ioana Ciornei | 6aa40b9 | 2020-04-22 15:05:12 +0300 | [diff] [blame] | 2405 | memset(fd, 0, sizeof(*fd)); |
Ioana Radulescu | d678be1 | 2019-03-01 17:47:24 +0000 | [diff] [blame] | 2406 | |
| 2407 | /* Align FD address, if possible */ |
| 2408 | buffer_start = xdpf->data - needed_headroom; |
| 2409 | aligned_start = PTR_ALIGN(buffer_start - DPAA2_ETH_TX_BUF_ALIGN, |
| 2410 | DPAA2_ETH_TX_BUF_ALIGN); |
| 2411 | if (aligned_start >= xdpf->data - xdpf->headroom) |
| 2412 | buffer_start = aligned_start; |
| 2413 | |
| 2414 | swa = (struct dpaa2_eth_swa *)buffer_start; |
| 2415 | /* fill in necessary fields here */ |
| 2416 | swa->type = DPAA2_ETH_SWA_XDP; |
| 2417 | swa->xdp.dma_size = xdpf->data + xdpf->len - buffer_start; |
| 2418 | swa->xdp.xdpf = xdpf; |
| 2419 | |
| 2420 | addr = dma_map_single(dev, buffer_start, |
| 2421 | swa->xdp.dma_size, |
| 2422 | DMA_BIDIRECTIONAL); |
Ioana Ciornei | 6aa40b9 | 2020-04-22 15:05:12 +0300 | [diff] [blame] | 2423 | if (unlikely(dma_mapping_error(dev, addr))) |
Ioana Radulescu | d678be1 | 2019-03-01 17:47:24 +0000 | [diff] [blame] | 2424 | return -ENOMEM; |
Ioana Radulescu | d678be1 | 2019-03-01 17:47:24 +0000 | [diff] [blame] | 2425 | |
Ioana Ciornei | 6aa40b9 | 2020-04-22 15:05:12 +0300 | [diff] [blame] | 2426 | dpaa2_fd_set_addr(fd, addr); |
| 2427 | dpaa2_fd_set_offset(fd, xdpf->data - buffer_start); |
| 2428 | dpaa2_fd_set_len(fd, xdpf->len); |
| 2429 | dpaa2_fd_set_format(fd, dpaa2_fd_single); |
| 2430 | dpaa2_fd_set_ctrl(fd, FD_CTRL_PTA); |
Ioana Radulescu | d678be1 | 2019-03-01 17:47:24 +0000 | [diff] [blame] | 2431 | |
| 2432 | return 0; |
| 2433 | } |
| 2434 | |
| 2435 | static int dpaa2_eth_xdp_xmit(struct net_device *net_dev, int n, |
| 2436 | struct xdp_frame **frames, u32 flags) |
| 2437 | { |
Ioana Ciornei | 6aa40b9 | 2020-04-22 15:05:12 +0300 | [diff] [blame] | 2438 | struct dpaa2_eth_priv *priv = netdev_priv(net_dev); |
Ioana Ciornei | 38c440b | 2020-05-06 20:47:17 +0300 | [diff] [blame] | 2439 | struct dpaa2_eth_xdp_fds *xdp_redirect_fds; |
Ioana Ciornei | 6aa40b9 | 2020-04-22 15:05:12 +0300 | [diff] [blame] | 2440 | struct rtnl_link_stats64 *percpu_stats; |
| 2441 | struct dpaa2_eth_fq *fq; |
Ioana Ciornei | 8665d97 | 2020-04-22 15:05:13 +0300 | [diff] [blame] | 2442 | struct dpaa2_fd *fds; |
Ioana Ciornei | 38c440b | 2020-05-06 20:47:17 +0300 | [diff] [blame] | 2443 | int enqueued, i, err; |
Ioana Radulescu | d678be1 | 2019-03-01 17:47:24 +0000 | [diff] [blame] | 2444 | |
| 2445 | if (unlikely(flags & ~XDP_XMIT_FLAGS_MASK)) |
| 2446 | return -EINVAL; |
| 2447 | |
| 2448 | if (!netif_running(net_dev)) |
| 2449 | return -ENETDOWN; |
| 2450 | |
Ioana Ciornei | 8665d97 | 2020-04-22 15:05:13 +0300 | [diff] [blame] | 2451 | fq = &priv->fq[smp_processor_id()]; |
Ioana Ciornei | 38c440b | 2020-05-06 20:47:17 +0300 | [diff] [blame] | 2452 | xdp_redirect_fds = &fq->xdp_redirect_fds; |
| 2453 | fds = xdp_redirect_fds->fds; |
Ioana Ciornei | 8665d97 | 2020-04-22 15:05:13 +0300 | [diff] [blame] | 2454 | |
Ioana Ciornei | 6aa40b9 | 2020-04-22 15:05:12 +0300 | [diff] [blame] | 2455 | percpu_stats = this_cpu_ptr(priv->percpu_stats); |
Ioana Ciornei | 6aa40b9 | 2020-04-22 15:05:12 +0300 | [diff] [blame] | 2456 | |
Ioana Ciornei | 8665d97 | 2020-04-22 15:05:13 +0300 | [diff] [blame] | 2457 | /* create a FD for each xdp_frame in the list received */ |
Ioana Radulescu | d678be1 | 2019-03-01 17:47:24 +0000 | [diff] [blame] | 2458 | for (i = 0; i < n; i++) { |
Ioana Ciornei | 8665d97 | 2020-04-22 15:05:13 +0300 | [diff] [blame] | 2459 | err = dpaa2_eth_xdp_create_fd(net_dev, frames[i], &fds[i]); |
| 2460 | if (err) |
| 2461 | break; |
| 2462 | } |
Ioana Ciornei | 38c440b | 2020-05-06 20:47:17 +0300 | [diff] [blame] | 2463 | xdp_redirect_fds->num = i; |
Ioana Radulescu | d678be1 | 2019-03-01 17:47:24 +0000 | [diff] [blame] | 2464 | |
Ioana Ciornei | 38c440b | 2020-05-06 20:47:17 +0300 | [diff] [blame] | 2465 | /* enqueue all the frame descriptors */ |
| 2466 | enqueued = dpaa2_eth_xdp_flush(priv, fq, xdp_redirect_fds); |
Ioana Radulescu | d678be1 | 2019-03-01 17:47:24 +0000 | [diff] [blame] | 2467 | |
Ioana Ciornei | 8665d97 | 2020-04-22 15:05:13 +0300 | [diff] [blame] | 2468 | /* update statistics */ |
Ioana Ciornei | 38c440b | 2020-05-06 20:47:17 +0300 | [diff] [blame] | 2469 | percpu_stats->tx_packets += enqueued; |
| 2470 | for (i = 0; i < enqueued; i++) |
Ioana Ciornei | 8665d97 | 2020-04-22 15:05:13 +0300 | [diff] [blame] | 2471 | percpu_stats->tx_bytes += dpaa2_fd_get_len(&fds[i]); |
Ioana Ciornei | 8665d97 | 2020-04-22 15:05:13 +0300 | [diff] [blame] | 2472 | |
Ioana Ciornei | 38c440b | 2020-05-06 20:47:17 +0300 | [diff] [blame] | 2473 | return enqueued; |
Ioana Radulescu | d678be1 | 2019-03-01 17:47:24 +0000 | [diff] [blame] | 2474 | } |
| 2475 | |
Ioana Radulescu | 06d5b17 | 2019-06-11 14:50:01 +0300 | [diff] [blame] | 2476 | static int update_xps(struct dpaa2_eth_priv *priv) |
| 2477 | { |
| 2478 | struct net_device *net_dev = priv->net_dev; |
| 2479 | struct cpumask xps_mask; |
| 2480 | struct dpaa2_eth_fq *fq; |
Ioana Radulescu | ab1e6de | 2019-06-11 14:50:03 +0300 | [diff] [blame] | 2481 | int i, num_queues, netdev_queues; |
Ioana Radulescu | 06d5b17 | 2019-06-11 14:50:01 +0300 | [diff] [blame] | 2482 | int err = 0; |
| 2483 | |
| 2484 | num_queues = dpaa2_eth_queue_count(priv); |
Ioana Radulescu | ab1e6de | 2019-06-11 14:50:03 +0300 | [diff] [blame] | 2485 | netdev_queues = (net_dev->num_tc ? : 1) * num_queues; |
Ioana Radulescu | 06d5b17 | 2019-06-11 14:50:01 +0300 | [diff] [blame] | 2486 | |
| 2487 | /* The first <num_queues> entries in priv->fq array are Tx/Tx conf |
| 2488 | * queues, so only process those |
| 2489 | */ |
Ioana Radulescu | ab1e6de | 2019-06-11 14:50:03 +0300 | [diff] [blame] | 2490 | for (i = 0; i < netdev_queues; i++) { |
| 2491 | fq = &priv->fq[i % num_queues]; |
Ioana Radulescu | 06d5b17 | 2019-06-11 14:50:01 +0300 | [diff] [blame] | 2492 | |
| 2493 | cpumask_clear(&xps_mask); |
| 2494 | cpumask_set_cpu(fq->target_cpu, &xps_mask); |
| 2495 | |
| 2496 | err = netif_set_xps_queue(net_dev, &xps_mask, i); |
| 2497 | if (err) { |
| 2498 | netdev_warn_once(net_dev, "Error setting XPS queue\n"); |
| 2499 | break; |
| 2500 | } |
| 2501 | } |
| 2502 | |
| 2503 | return err; |
| 2504 | } |
| 2505 | |
Ioana Ciornei | e3ec13b | 2020-07-21 19:38:23 +0300 | [diff] [blame] | 2506 | static int dpaa2_eth_setup_mqprio(struct net_device *net_dev, |
| 2507 | struct tc_mqprio_qopt *mqprio) |
Ioana Radulescu | ab1e6de | 2019-06-11 14:50:03 +0300 | [diff] [blame] | 2508 | { |
| 2509 | struct dpaa2_eth_priv *priv = netdev_priv(net_dev); |
Ioana Radulescu | ab1e6de | 2019-06-11 14:50:03 +0300 | [diff] [blame] | 2510 | u8 num_tc, num_queues; |
| 2511 | int i; |
| 2512 | |
Ioana Radulescu | ab1e6de | 2019-06-11 14:50:03 +0300 | [diff] [blame] | 2513 | mqprio->hw = TC_MQPRIO_HW_OFFLOAD_TCS; |
| 2514 | num_queues = dpaa2_eth_queue_count(priv); |
| 2515 | num_tc = mqprio->num_tc; |
| 2516 | |
| 2517 | if (num_tc == net_dev->num_tc) |
| 2518 | return 0; |
| 2519 | |
| 2520 | if (num_tc > dpaa2_eth_tc_count(priv)) { |
| 2521 | netdev_err(net_dev, "Max %d traffic classes supported\n", |
| 2522 | dpaa2_eth_tc_count(priv)); |
Jesper Dangaard Brouer | b89c1e6 | 2020-04-23 16:57:50 +0200 | [diff] [blame] | 2523 | return -EOPNOTSUPP; |
Ioana Radulescu | ab1e6de | 2019-06-11 14:50:03 +0300 | [diff] [blame] | 2524 | } |
| 2525 | |
| 2526 | if (!num_tc) { |
| 2527 | netdev_reset_tc(net_dev); |
| 2528 | netif_set_real_num_tx_queues(net_dev, num_queues); |
| 2529 | goto out; |
| 2530 | } |
| 2531 | |
| 2532 | netdev_set_num_tc(net_dev, num_tc); |
| 2533 | netif_set_real_num_tx_queues(net_dev, num_tc * num_queues); |
| 2534 | |
| 2535 | for (i = 0; i < num_tc; i++) |
| 2536 | netdev_set_tc_queue(net_dev, i, num_queues, i * num_queues); |
| 2537 | |
| 2538 | out: |
| 2539 | update_xps(priv); |
| 2540 | |
| 2541 | return 0; |
| 2542 | } |
| 2543 | |
Ioana Ciornei | 3657cda | 2020-07-21 19:38:25 +0300 | [diff] [blame] | 2544 | #define bps_to_mbits(rate) (div_u64((rate), 1000000) * 8) |
| 2545 | |
| 2546 | static int dpaa2_eth_setup_tbf(struct net_device *net_dev, struct tc_tbf_qopt_offload *p) |
| 2547 | { |
| 2548 | struct tc_tbf_qopt_offload_replace_params *cfg = &p->replace_params; |
| 2549 | struct dpaa2_eth_priv *priv = netdev_priv(net_dev); |
| 2550 | struct dpni_tx_shaping_cfg tx_cr_shaper = { 0 }; |
| 2551 | struct dpni_tx_shaping_cfg tx_er_shaper = { 0 }; |
| 2552 | int err; |
| 2553 | |
| 2554 | if (p->command == TC_TBF_STATS) |
| 2555 | return -EOPNOTSUPP; |
| 2556 | |
| 2557 | /* Only per port Tx shaping */ |
| 2558 | if (p->parent != TC_H_ROOT) |
| 2559 | return -EOPNOTSUPP; |
| 2560 | |
| 2561 | if (p->command == TC_TBF_REPLACE) { |
| 2562 | if (cfg->max_size > DPAA2_ETH_MAX_BURST_SIZE) { |
| 2563 | netdev_err(net_dev, "burst size cannot be greater than %d\n", |
| 2564 | DPAA2_ETH_MAX_BURST_SIZE); |
| 2565 | return -EINVAL; |
| 2566 | } |
| 2567 | |
| 2568 | tx_cr_shaper.max_burst_size = cfg->max_size; |
| 2569 | /* The TBF interface is in bytes/s, whereas DPAA2 expects the |
| 2570 | * rate in Mbits/s |
| 2571 | */ |
| 2572 | tx_cr_shaper.rate_limit = bps_to_mbits(cfg->rate.rate_bytes_ps); |
| 2573 | } |
| 2574 | |
| 2575 | err = dpni_set_tx_shaping(priv->mc_io, 0, priv->mc_token, &tx_cr_shaper, |
| 2576 | &tx_er_shaper, 0); |
| 2577 | if (err) { |
| 2578 | netdev_err(net_dev, "dpni_set_tx_shaping() = %d\n", err); |
| 2579 | return err; |
| 2580 | } |
| 2581 | |
| 2582 | return 0; |
| 2583 | } |
| 2584 | |
Ioana Ciornei | e3ec13b | 2020-07-21 19:38:23 +0300 | [diff] [blame] | 2585 | static int dpaa2_eth_setup_tc(struct net_device *net_dev, |
| 2586 | enum tc_setup_type type, void *type_data) |
| 2587 | { |
| 2588 | switch (type) { |
| 2589 | case TC_SETUP_QDISC_MQPRIO: |
| 2590 | return dpaa2_eth_setup_mqprio(net_dev, type_data); |
Ioana Ciornei | 3657cda | 2020-07-21 19:38:25 +0300 | [diff] [blame] | 2591 | case TC_SETUP_QDISC_TBF: |
| 2592 | return dpaa2_eth_setup_tbf(net_dev, type_data); |
Ioana Ciornei | e3ec13b | 2020-07-21 19:38:23 +0300 | [diff] [blame] | 2593 | default: |
| 2594 | return -EOPNOTSUPP; |
| 2595 | } |
| 2596 | } |
| 2597 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2598 | static const struct net_device_ops dpaa2_eth_ops = { |
| 2599 | .ndo_open = dpaa2_eth_open, |
| 2600 | .ndo_start_xmit = dpaa2_eth_tx, |
| 2601 | .ndo_stop = dpaa2_eth_stop, |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2602 | .ndo_set_mac_address = dpaa2_eth_set_addr, |
| 2603 | .ndo_get_stats64 = dpaa2_eth_get_stats, |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2604 | .ndo_set_rx_mode = dpaa2_eth_set_rx_mode, |
| 2605 | .ndo_set_features = dpaa2_eth_set_features, |
Arnd Bergmann | a760537 | 2021-07-27 15:45:13 +0200 | [diff] [blame] | 2606 | .ndo_eth_ioctl = dpaa2_eth_ioctl, |
Ioana Ciocoi Radulescu | 7e273a8 | 2018-11-26 16:27:29 +0000 | [diff] [blame] | 2607 | .ndo_change_mtu = dpaa2_eth_change_mtu, |
| 2608 | .ndo_bpf = dpaa2_eth_xdp, |
Ioana Radulescu | d678be1 | 2019-03-01 17:47:24 +0000 | [diff] [blame] | 2609 | .ndo_xdp_xmit = dpaa2_eth_xdp_xmit, |
Ioana Radulescu | ab1e6de | 2019-06-11 14:50:03 +0300 | [diff] [blame] | 2610 | .ndo_setup_tc = dpaa2_eth_setup_tc, |
Ionut-robert Aron | 70b32d8 | 2021-01-11 19:07:25 +0200 | [diff] [blame] | 2611 | .ndo_vlan_rx_add_vid = dpaa2_eth_rx_add_vid, |
| 2612 | .ndo_vlan_rx_kill_vid = dpaa2_eth_rx_kill_vid |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2613 | }; |
| 2614 | |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 2615 | static void dpaa2_eth_cdan_cb(struct dpaa2_io_notification_ctx *ctx) |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2616 | { |
| 2617 | struct dpaa2_eth_channel *ch; |
| 2618 | |
| 2619 | ch = container_of(ctx, struct dpaa2_eth_channel, nctx); |
Ioana Radulescu | 85047ab | 2017-04-28 04:50:31 -0500 | [diff] [blame] | 2620 | |
| 2621 | /* Update NAPI statistics */ |
| 2622 | ch->stats.cdan++; |
| 2623 | |
Jiafei Pan | 6c33ae1 | 2020-08-03 23:10:08 +0300 | [diff] [blame] | 2624 | napi_schedule(&ch->napi); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2625 | } |
| 2626 | |
| 2627 | /* Allocate and configure a DPCON object */ |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 2628 | static struct fsl_mc_device *dpaa2_eth_setup_dpcon(struct dpaa2_eth_priv *priv) |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2629 | { |
| 2630 | struct fsl_mc_device *dpcon; |
| 2631 | struct device *dev = priv->net_dev->dev.parent; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2632 | int err; |
| 2633 | |
| 2634 | err = fsl_mc_object_allocate(to_fsl_mc_device(dev), |
| 2635 | FSL_MC_POOL_DPCON, &dpcon); |
| 2636 | if (err) { |
Ioana Ciornei | d7f5a9d | 2018-11-09 15:26:45 +0000 | [diff] [blame] | 2637 | if (err == -ENXIO) |
| 2638 | err = -EPROBE_DEFER; |
| 2639 | else |
| 2640 | dev_info(dev, "Not enough DPCONs, will go on as-is\n"); |
| 2641 | return ERR_PTR(err); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2642 | } |
| 2643 | |
| 2644 | err = dpcon_open(priv->mc_io, 0, dpcon->obj_desc.id, &dpcon->mc_handle); |
| 2645 | if (err) { |
| 2646 | dev_err(dev, "dpcon_open() failed\n"); |
Ioana Radulescu | f6dda80 | 2017-10-29 08:20:39 +0000 | [diff] [blame] | 2647 | goto free; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2648 | } |
| 2649 | |
| 2650 | err = dpcon_reset(priv->mc_io, 0, dpcon->mc_handle); |
| 2651 | if (err) { |
| 2652 | dev_err(dev, "dpcon_reset() failed\n"); |
Ioana Radulescu | f6dda80 | 2017-10-29 08:20:39 +0000 | [diff] [blame] | 2653 | goto close; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2654 | } |
| 2655 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2656 | err = dpcon_enable(priv->mc_io, 0, dpcon->mc_handle); |
| 2657 | if (err) { |
| 2658 | dev_err(dev, "dpcon_enable() failed\n"); |
Ioana Radulescu | f6dda80 | 2017-10-29 08:20:39 +0000 | [diff] [blame] | 2659 | goto close; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2660 | } |
| 2661 | |
| 2662 | return dpcon; |
| 2663 | |
Ioana Radulescu | f6dda80 | 2017-10-29 08:20:39 +0000 | [diff] [blame] | 2664 | close: |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2665 | dpcon_close(priv->mc_io, 0, dpcon->mc_handle); |
Ioana Radulescu | f6dda80 | 2017-10-29 08:20:39 +0000 | [diff] [blame] | 2666 | free: |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2667 | fsl_mc_object_free(dpcon); |
| 2668 | |
YueHaibing | 02afa9c | 2020-08-04 21:26:43 +0800 | [diff] [blame] | 2669 | return ERR_PTR(err); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2670 | } |
| 2671 | |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 2672 | static void dpaa2_eth_free_dpcon(struct dpaa2_eth_priv *priv, |
| 2673 | struct fsl_mc_device *dpcon) |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2674 | { |
| 2675 | dpcon_disable(priv->mc_io, 0, dpcon->mc_handle); |
| 2676 | dpcon_close(priv->mc_io, 0, dpcon->mc_handle); |
| 2677 | fsl_mc_object_free(dpcon); |
| 2678 | } |
| 2679 | |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 2680 | static struct dpaa2_eth_channel *dpaa2_eth_alloc_channel(struct dpaa2_eth_priv *priv) |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2681 | { |
| 2682 | struct dpaa2_eth_channel *channel; |
| 2683 | struct dpcon_attr attr; |
| 2684 | struct device *dev = priv->net_dev->dev.parent; |
| 2685 | int err; |
| 2686 | |
| 2687 | channel = kzalloc(sizeof(*channel), GFP_KERNEL); |
| 2688 | if (!channel) |
| 2689 | return NULL; |
| 2690 | |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 2691 | channel->dpcon = dpaa2_eth_setup_dpcon(priv); |
YueHaibing | 02afa9c | 2020-08-04 21:26:43 +0800 | [diff] [blame] | 2692 | if (IS_ERR(channel->dpcon)) { |
| 2693 | err = PTR_ERR(channel->dpcon); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2694 | goto err_setup; |
Ioana Ciornei | d7f5a9d | 2018-11-09 15:26:45 +0000 | [diff] [blame] | 2695 | } |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2696 | |
| 2697 | err = dpcon_get_attributes(priv->mc_io, 0, channel->dpcon->mc_handle, |
| 2698 | &attr); |
| 2699 | if (err) { |
| 2700 | dev_err(dev, "dpcon_get_attributes() failed\n"); |
| 2701 | goto err_get_attr; |
| 2702 | } |
| 2703 | |
| 2704 | channel->dpcon_id = attr.id; |
| 2705 | channel->ch_id = attr.qbman_ch_id; |
| 2706 | channel->priv = priv; |
| 2707 | |
| 2708 | return channel; |
| 2709 | |
| 2710 | err_get_attr: |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 2711 | dpaa2_eth_free_dpcon(priv, channel->dpcon); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2712 | err_setup: |
| 2713 | kfree(channel); |
Ioana Ciornei | d7f5a9d | 2018-11-09 15:26:45 +0000 | [diff] [blame] | 2714 | return ERR_PTR(err); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2715 | } |
| 2716 | |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 2717 | static void dpaa2_eth_free_channel(struct dpaa2_eth_priv *priv, |
| 2718 | struct dpaa2_eth_channel *channel) |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2719 | { |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 2720 | dpaa2_eth_free_dpcon(priv, channel->dpcon); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2721 | kfree(channel); |
| 2722 | } |
| 2723 | |
| 2724 | /* DPIO setup: allocate and configure QBMan channels, setup core affinity |
| 2725 | * and register data availability notifications |
| 2726 | */ |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 2727 | static int dpaa2_eth_setup_dpio(struct dpaa2_eth_priv *priv) |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2728 | { |
| 2729 | struct dpaa2_io_notification_ctx *nctx; |
| 2730 | struct dpaa2_eth_channel *channel; |
| 2731 | struct dpcon_notification_cfg dpcon_notif_cfg; |
| 2732 | struct device *dev = priv->net_dev->dev.parent; |
| 2733 | int i, err; |
| 2734 | |
| 2735 | /* We want the ability to spread ingress traffic (RX, TX conf) to as |
| 2736 | * many cores as possible, so we need one channel for each core |
| 2737 | * (unless there's fewer queues than cores, in which case the extra |
| 2738 | * channels would be wasted). |
| 2739 | * Allocate one channel per core and register it to the core's |
| 2740 | * affine DPIO. If not enough channels are available for all cores |
| 2741 | * or if some cores don't have an affine DPIO, there will be no |
| 2742 | * ingress frame processing on those cores. |
| 2743 | */ |
| 2744 | cpumask_clear(&priv->dpio_cpumask); |
| 2745 | for_each_online_cpu(i) { |
| 2746 | /* Try to allocate a channel */ |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 2747 | channel = dpaa2_eth_alloc_channel(priv); |
Ioana Ciornei | d7f5a9d | 2018-11-09 15:26:45 +0000 | [diff] [blame] | 2748 | if (IS_ERR_OR_NULL(channel)) { |
Ioana Radulescu | bd8460f | 2019-05-24 18:15:16 +0300 | [diff] [blame] | 2749 | err = PTR_ERR_OR_ZERO(channel); |
Ioana Ciornei | d7f5a9d | 2018-11-09 15:26:45 +0000 | [diff] [blame] | 2750 | if (err != -EPROBE_DEFER) |
| 2751 | dev_info(dev, |
| 2752 | "No affine channel for cpu %d and above\n", i); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2753 | goto err_alloc_ch; |
| 2754 | } |
| 2755 | |
| 2756 | priv->channel[priv->num_channels] = channel; |
| 2757 | |
| 2758 | nctx = &channel->nctx; |
| 2759 | nctx->is_cdan = 1; |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 2760 | nctx->cb = dpaa2_eth_cdan_cb; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2761 | nctx->id = channel->ch_id; |
| 2762 | nctx->desired_cpu = i; |
| 2763 | |
| 2764 | /* Register the new context */ |
Ioana Radulescu | 7ec0596 | 2018-01-05 05:04:32 -0600 | [diff] [blame] | 2765 | channel->dpio = dpaa2_io_service_select(i); |
Ioana Ciornei | 47441f7 | 2018-12-10 16:50:19 +0000 | [diff] [blame] | 2766 | err = dpaa2_io_service_register(channel->dpio, nctx, dev); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2767 | if (err) { |
Ioana Radulescu | 5206d8d | 2017-06-06 10:00:33 -0500 | [diff] [blame] | 2768 | dev_dbg(dev, "No affine DPIO for cpu %d\n", i); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2769 | /* If no affine DPIO for this core, there's probably |
Ioana Radulescu | 5206d8d | 2017-06-06 10:00:33 -0500 | [diff] [blame] | 2770 | * none available for next cores either. Signal we want |
| 2771 | * to retry later, in case the DPIO devices weren't |
| 2772 | * probed yet. |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2773 | */ |
Ioana Radulescu | 5206d8d | 2017-06-06 10:00:33 -0500 | [diff] [blame] | 2774 | err = -EPROBE_DEFER; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2775 | goto err_service_reg; |
| 2776 | } |
| 2777 | |
| 2778 | /* Register DPCON notification with MC */ |
| 2779 | dpcon_notif_cfg.dpio_id = nctx->dpio_id; |
| 2780 | dpcon_notif_cfg.priority = 0; |
| 2781 | dpcon_notif_cfg.user_ctx = nctx->qman64; |
| 2782 | err = dpcon_set_notification(priv->mc_io, 0, |
| 2783 | channel->dpcon->mc_handle, |
| 2784 | &dpcon_notif_cfg); |
| 2785 | if (err) { |
| 2786 | dev_err(dev, "dpcon_set_notification failed()\n"); |
| 2787 | goto err_set_cdan; |
| 2788 | } |
| 2789 | |
| 2790 | /* If we managed to allocate a channel and also found an affine |
| 2791 | * DPIO for this core, add it to the final mask |
| 2792 | */ |
| 2793 | cpumask_set_cpu(i, &priv->dpio_cpumask); |
| 2794 | priv->num_channels++; |
| 2795 | |
| 2796 | /* Stop if we already have enough channels to accommodate all |
| 2797 | * RX and TX conf queues |
| 2798 | */ |
Ioana Ciocoi Radulescu | b0e4f37 | 2018-11-14 11:48:35 +0000 | [diff] [blame] | 2799 | if (priv->num_channels == priv->dpni_attrs.num_queues) |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2800 | break; |
| 2801 | } |
| 2802 | |
| 2803 | return 0; |
| 2804 | |
| 2805 | err_set_cdan: |
Ioana Ciornei | 47441f7 | 2018-12-10 16:50:19 +0000 | [diff] [blame] | 2806 | dpaa2_io_service_deregister(channel->dpio, nctx, dev); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2807 | err_service_reg: |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 2808 | dpaa2_eth_free_channel(priv, channel); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2809 | err_alloc_ch: |
Ioana Ciornei | 5aa4277 | 2019-11-12 18:21:52 +0200 | [diff] [blame] | 2810 | if (err == -EPROBE_DEFER) { |
| 2811 | for (i = 0; i < priv->num_channels; i++) { |
| 2812 | channel = priv->channel[i]; |
| 2813 | nctx = &channel->nctx; |
| 2814 | dpaa2_io_service_deregister(channel->dpio, nctx, dev); |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 2815 | dpaa2_eth_free_channel(priv, channel); |
Ioana Ciornei | 5aa4277 | 2019-11-12 18:21:52 +0200 | [diff] [blame] | 2816 | } |
| 2817 | priv->num_channels = 0; |
Ioana Ciornei | d7f5a9d | 2018-11-09 15:26:45 +0000 | [diff] [blame] | 2818 | return err; |
Ioana Ciornei | 5aa4277 | 2019-11-12 18:21:52 +0200 | [diff] [blame] | 2819 | } |
Ioana Ciornei | d7f5a9d | 2018-11-09 15:26:45 +0000 | [diff] [blame] | 2820 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2821 | if (cpumask_empty(&priv->dpio_cpumask)) { |
| 2822 | dev_err(dev, "No cpu with an affine DPIO/DPCON\n"); |
Ioana Ciornei | d7f5a9d | 2018-11-09 15:26:45 +0000 | [diff] [blame] | 2823 | return -ENODEV; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2824 | } |
| 2825 | |
| 2826 | dev_info(dev, "Cores %*pbl available for processing ingress traffic\n", |
| 2827 | cpumask_pr_args(&priv->dpio_cpumask)); |
| 2828 | |
| 2829 | return 0; |
| 2830 | } |
| 2831 | |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 2832 | static void dpaa2_eth_free_dpio(struct dpaa2_eth_priv *priv) |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2833 | { |
Ioana Ciornei | 47441f7 | 2018-12-10 16:50:19 +0000 | [diff] [blame] | 2834 | struct device *dev = priv->net_dev->dev.parent; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2835 | struct dpaa2_eth_channel *ch; |
Ioana Ciornei | 47441f7 | 2018-12-10 16:50:19 +0000 | [diff] [blame] | 2836 | int i; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2837 | |
| 2838 | /* deregister CDAN notifications and free channels */ |
| 2839 | for (i = 0; i < priv->num_channels; i++) { |
| 2840 | ch = priv->channel[i]; |
Ioana Ciornei | 47441f7 | 2018-12-10 16:50:19 +0000 | [diff] [blame] | 2841 | dpaa2_io_service_deregister(ch->dpio, &ch->nctx, dev); |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 2842 | dpaa2_eth_free_channel(priv, ch); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2843 | } |
| 2844 | } |
| 2845 | |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 2846 | static struct dpaa2_eth_channel *dpaa2_eth_get_affine_channel(struct dpaa2_eth_priv *priv, |
| 2847 | int cpu) |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2848 | { |
| 2849 | struct device *dev = priv->net_dev->dev.parent; |
| 2850 | int i; |
| 2851 | |
| 2852 | for (i = 0; i < priv->num_channels; i++) |
| 2853 | if (priv->channel[i]->nctx.desired_cpu == cpu) |
| 2854 | return priv->channel[i]; |
| 2855 | |
| 2856 | /* We should never get here. Issue a warning and return |
| 2857 | * the first channel, because it's still better than nothing |
| 2858 | */ |
| 2859 | dev_warn(dev, "No affine channel found for cpu %d\n", cpu); |
| 2860 | |
| 2861 | return priv->channel[0]; |
| 2862 | } |
| 2863 | |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 2864 | static void dpaa2_eth_set_fq_affinity(struct dpaa2_eth_priv *priv) |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2865 | { |
| 2866 | struct device *dev = priv->net_dev->dev.parent; |
| 2867 | struct dpaa2_eth_fq *fq; |
| 2868 | int rx_cpu, txc_cpu; |
Ioana Radulescu | 06d5b17 | 2019-06-11 14:50:01 +0300 | [diff] [blame] | 2869 | int i; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2870 | |
| 2871 | /* For each FQ, pick one channel/CPU to deliver frames to. |
| 2872 | * This may well change at runtime, either through irqbalance or |
| 2873 | * through direct user intervention. |
| 2874 | */ |
| 2875 | rx_cpu = txc_cpu = cpumask_first(&priv->dpio_cpumask); |
| 2876 | |
| 2877 | for (i = 0; i < priv->num_fqs; i++) { |
| 2878 | fq = &priv->fq[i]; |
| 2879 | switch (fq->type) { |
| 2880 | case DPAA2_RX_FQ: |
Ioana Ciornei | 061d631 | 2020-10-01 18:11:48 +0300 | [diff] [blame] | 2881 | case DPAA2_RX_ERR_FQ: |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2882 | fq->target_cpu = rx_cpu; |
| 2883 | rx_cpu = cpumask_next(rx_cpu, &priv->dpio_cpumask); |
| 2884 | if (rx_cpu >= nr_cpu_ids) |
| 2885 | rx_cpu = cpumask_first(&priv->dpio_cpumask); |
| 2886 | break; |
| 2887 | case DPAA2_TX_CONF_FQ: |
| 2888 | fq->target_cpu = txc_cpu; |
| 2889 | txc_cpu = cpumask_next(txc_cpu, &priv->dpio_cpumask); |
| 2890 | if (txc_cpu >= nr_cpu_ids) |
| 2891 | txc_cpu = cpumask_first(&priv->dpio_cpumask); |
| 2892 | break; |
| 2893 | default: |
| 2894 | dev_err(dev, "Unknown FQ type: %d\n", fq->type); |
| 2895 | } |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 2896 | fq->channel = dpaa2_eth_get_affine_channel(priv, fq->target_cpu); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2897 | } |
Ioana Radulescu | 06d5b17 | 2019-06-11 14:50:01 +0300 | [diff] [blame] | 2898 | |
| 2899 | update_xps(priv); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2900 | } |
| 2901 | |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 2902 | static void dpaa2_eth_setup_fqs(struct dpaa2_eth_priv *priv) |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2903 | { |
Ioana Radulescu | 685e39e | 2020-05-31 00:08:08 +0300 | [diff] [blame] | 2904 | int i, j; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2905 | |
| 2906 | /* We have one TxConf FQ per Tx flow. |
| 2907 | * The number of Tx and Rx queues is the same. |
| 2908 | * Tx queues come first in the fq array. |
| 2909 | */ |
| 2910 | for (i = 0; i < dpaa2_eth_queue_count(priv); i++) { |
| 2911 | priv->fq[priv->num_fqs].type = DPAA2_TX_CONF_FQ; |
| 2912 | priv->fq[priv->num_fqs].consume = dpaa2_eth_tx_conf; |
| 2913 | priv->fq[priv->num_fqs++].flowid = (u16)i; |
| 2914 | } |
| 2915 | |
Ioana Radulescu | 685e39e | 2020-05-31 00:08:08 +0300 | [diff] [blame] | 2916 | for (j = 0; j < dpaa2_eth_tc_count(priv); j++) { |
| 2917 | for (i = 0; i < dpaa2_eth_queue_count(priv); i++) { |
| 2918 | priv->fq[priv->num_fqs].type = DPAA2_RX_FQ; |
| 2919 | priv->fq[priv->num_fqs].consume = dpaa2_eth_rx; |
| 2920 | priv->fq[priv->num_fqs].tc = (u8)j; |
| 2921 | priv->fq[priv->num_fqs++].flowid = (u16)i; |
| 2922 | } |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2923 | } |
| 2924 | |
Ioana Ciornei | 061d631 | 2020-10-01 18:11:48 +0300 | [diff] [blame] | 2925 | /* We have exactly one Rx error queue per DPNI */ |
| 2926 | priv->fq[priv->num_fqs].type = DPAA2_RX_ERR_FQ; |
| 2927 | priv->fq[priv->num_fqs++].consume = dpaa2_eth_rx_err; |
| 2928 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2929 | /* For each FQ, decide on which core to process incoming frames */ |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 2930 | dpaa2_eth_set_fq_affinity(priv); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2931 | } |
| 2932 | |
| 2933 | /* Allocate and configure one buffer pool for each interface */ |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 2934 | static int dpaa2_eth_setup_dpbp(struct dpaa2_eth_priv *priv) |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2935 | { |
| 2936 | int err; |
| 2937 | struct fsl_mc_device *dpbp_dev; |
| 2938 | struct device *dev = priv->net_dev->dev.parent; |
Ioana Radulescu | 05fa39c | 2017-06-06 10:00:37 -0500 | [diff] [blame] | 2939 | struct dpbp_attr dpbp_attrs; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2940 | |
| 2941 | err = fsl_mc_object_allocate(to_fsl_mc_device(dev), FSL_MC_POOL_DPBP, |
| 2942 | &dpbp_dev); |
| 2943 | if (err) { |
Ioana Ciornei | d7f5a9d | 2018-11-09 15:26:45 +0000 | [diff] [blame] | 2944 | if (err == -ENXIO) |
| 2945 | err = -EPROBE_DEFER; |
| 2946 | else |
| 2947 | dev_err(dev, "DPBP device allocation failed\n"); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2948 | return err; |
| 2949 | } |
| 2950 | |
| 2951 | priv->dpbp_dev = dpbp_dev; |
| 2952 | |
| 2953 | err = dpbp_open(priv->mc_io, 0, priv->dpbp_dev->obj_desc.id, |
| 2954 | &dpbp_dev->mc_handle); |
| 2955 | if (err) { |
| 2956 | dev_err(dev, "dpbp_open() failed\n"); |
| 2957 | goto err_open; |
| 2958 | } |
| 2959 | |
Ioana Radulescu | d00defe | 2017-06-06 10:00:32 -0500 | [diff] [blame] | 2960 | err = dpbp_reset(priv->mc_io, 0, dpbp_dev->mc_handle); |
| 2961 | if (err) { |
| 2962 | dev_err(dev, "dpbp_reset() failed\n"); |
| 2963 | goto err_reset; |
| 2964 | } |
| 2965 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2966 | err = dpbp_enable(priv->mc_io, 0, dpbp_dev->mc_handle); |
| 2967 | if (err) { |
| 2968 | dev_err(dev, "dpbp_enable() failed\n"); |
| 2969 | goto err_enable; |
| 2970 | } |
| 2971 | |
| 2972 | err = dpbp_get_attributes(priv->mc_io, 0, dpbp_dev->mc_handle, |
Ioana Radulescu | 05fa39c | 2017-06-06 10:00:37 -0500 | [diff] [blame] | 2973 | &dpbp_attrs); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2974 | if (err) { |
| 2975 | dev_err(dev, "dpbp_get_attributes() failed\n"); |
| 2976 | goto err_get_attr; |
| 2977 | } |
Ioana Radulescu | 05fa39c | 2017-06-06 10:00:37 -0500 | [diff] [blame] | 2978 | priv->bpid = dpbp_attrs.bpid; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2979 | |
| 2980 | return 0; |
| 2981 | |
| 2982 | err_get_attr: |
| 2983 | dpbp_disable(priv->mc_io, 0, dpbp_dev->mc_handle); |
| 2984 | err_enable: |
Ioana Radulescu | d00defe | 2017-06-06 10:00:32 -0500 | [diff] [blame] | 2985 | err_reset: |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2986 | dpbp_close(priv->mc_io, 0, dpbp_dev->mc_handle); |
| 2987 | err_open: |
| 2988 | fsl_mc_object_free(dpbp_dev); |
| 2989 | |
| 2990 | return err; |
| 2991 | } |
| 2992 | |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 2993 | static void dpaa2_eth_free_dpbp(struct dpaa2_eth_priv *priv) |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2994 | { |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 2995 | dpaa2_eth_drain_pool(priv); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2996 | dpbp_disable(priv->mc_io, 0, priv->dpbp_dev->mc_handle); |
| 2997 | dpbp_close(priv->mc_io, 0, priv->dpbp_dev->mc_handle); |
| 2998 | fsl_mc_object_free(priv->dpbp_dev); |
| 2999 | } |
| 3000 | |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 3001 | static int dpaa2_eth_set_buffer_layout(struct dpaa2_eth_priv *priv) |
Ioana Radulescu | 308f64e | 2017-10-29 08:20:40 +0000 | [diff] [blame] | 3002 | { |
| 3003 | struct device *dev = priv->net_dev->dev.parent; |
| 3004 | struct dpni_buffer_layout buf_layout = {0}; |
Ioana Ciocoi Radulescu | 27c8748 | 2019-02-04 17:00:35 +0000 | [diff] [blame] | 3005 | u16 rx_buf_align; |
Ioana Radulescu | 308f64e | 2017-10-29 08:20:40 +0000 | [diff] [blame] | 3006 | int err; |
| 3007 | |
Bogdan Purcareata | 8a4fd87 | 2017-10-29 08:20:42 +0000 | [diff] [blame] | 3008 | /* We need to check for WRIOP version 1.0.0, but depending on the MC |
| 3009 | * version, this number is not always provided correctly on rev1. |
| 3010 | * We need to check for both alternatives in this situation. |
| 3011 | */ |
| 3012 | if (priv->dpni_attrs.wriop_version == DPAA2_WRIOP_VERSION(0, 0, 0) || |
| 3013 | priv->dpni_attrs.wriop_version == DPAA2_WRIOP_VERSION(1, 0, 0)) |
Ioana Ciocoi Radulescu | 27c8748 | 2019-02-04 17:00:35 +0000 | [diff] [blame] | 3014 | rx_buf_align = DPAA2_ETH_RX_BUF_ALIGN_REV1; |
Bogdan Purcareata | 8a4fd87 | 2017-10-29 08:20:42 +0000 | [diff] [blame] | 3015 | else |
Ioana Ciocoi Radulescu | 27c8748 | 2019-02-04 17:00:35 +0000 | [diff] [blame] | 3016 | rx_buf_align = DPAA2_ETH_RX_BUF_ALIGN; |
Bogdan Purcareata | 8a4fd87 | 2017-10-29 08:20:42 +0000 | [diff] [blame] | 3017 | |
Ioana Ciornei | efa6a7d | 2020-05-15 15:30:22 +0300 | [diff] [blame] | 3018 | /* We need to ensure that the buffer size seen by WRIOP is a multiple |
| 3019 | * of 64 or 256 bytes depending on the WRIOP version. |
| 3020 | */ |
| 3021 | priv->rx_buf_size = ALIGN_DOWN(DPAA2_ETH_RX_BUF_SIZE, rx_buf_align); |
| 3022 | |
Bogdan Purcareata | 4b2d9fe | 2017-10-29 08:20:43 +0000 | [diff] [blame] | 3023 | /* tx buffer */ |
Ioana Radulescu | 308f64e | 2017-10-29 08:20:40 +0000 | [diff] [blame] | 3024 | buf_layout.private_data_size = DPAA2_ETH_SWA_SIZE; |
Ioana Radulescu | 859f998 | 2018-04-26 18:23:47 +0800 | [diff] [blame] | 3025 | buf_layout.pass_timestamp = true; |
Yangbo Lu | c552118 | 2020-09-18 17:08:02 +0800 | [diff] [blame] | 3026 | buf_layout.pass_frame_status = true; |
Ioana Radulescu | 859f998 | 2018-04-26 18:23:47 +0800 | [diff] [blame] | 3027 | buf_layout.options = DPNI_BUF_LAYOUT_OPT_PRIVATE_DATA_SIZE | |
Yangbo Lu | c552118 | 2020-09-18 17:08:02 +0800 | [diff] [blame] | 3028 | DPNI_BUF_LAYOUT_OPT_TIMESTAMP | |
| 3029 | DPNI_BUF_LAYOUT_OPT_FRAME_STATUS; |
Ioana Radulescu | 308f64e | 2017-10-29 08:20:40 +0000 | [diff] [blame] | 3030 | err = dpni_set_buffer_layout(priv->mc_io, 0, priv->mc_token, |
| 3031 | DPNI_QUEUE_TX, &buf_layout); |
| 3032 | if (err) { |
| 3033 | dev_err(dev, "dpni_set_buffer_layout(TX) failed\n"); |
| 3034 | return err; |
| 3035 | } |
| 3036 | |
| 3037 | /* tx-confirm buffer */ |
Yangbo Lu | c552118 | 2020-09-18 17:08:02 +0800 | [diff] [blame] | 3038 | buf_layout.options = DPNI_BUF_LAYOUT_OPT_TIMESTAMP | |
| 3039 | DPNI_BUF_LAYOUT_OPT_FRAME_STATUS; |
Ioana Radulescu | 308f64e | 2017-10-29 08:20:40 +0000 | [diff] [blame] | 3040 | err = dpni_set_buffer_layout(priv->mc_io, 0, priv->mc_token, |
| 3041 | DPNI_QUEUE_TX_CONFIRM, &buf_layout); |
| 3042 | if (err) { |
| 3043 | dev_err(dev, "dpni_set_buffer_layout(TX_CONF) failed\n"); |
| 3044 | return err; |
| 3045 | } |
| 3046 | |
Bogdan Purcareata | 4b2d9fe | 2017-10-29 08:20:43 +0000 | [diff] [blame] | 3047 | /* Now that we've set our tx buffer layout, retrieve the minimum |
| 3048 | * required tx data offset. |
| 3049 | */ |
| 3050 | err = dpni_get_tx_data_offset(priv->mc_io, 0, priv->mc_token, |
| 3051 | &priv->tx_data_offset); |
| 3052 | if (err) { |
| 3053 | dev_err(dev, "dpni_get_tx_data_offset() failed\n"); |
| 3054 | return err; |
| 3055 | } |
| 3056 | |
| 3057 | if ((priv->tx_data_offset % 64) != 0) |
| 3058 | dev_warn(dev, "Tx data offset (%d) not a multiple of 64B\n", |
| 3059 | priv->tx_data_offset); |
| 3060 | |
| 3061 | /* rx buffer */ |
Ioana Radulescu | 2b7c86e | 2017-12-08 06:47:56 -0600 | [diff] [blame] | 3062 | buf_layout.pass_frame_status = true; |
Bogdan Purcareata | 4b2d9fe | 2017-10-29 08:20:43 +0000 | [diff] [blame] | 3063 | buf_layout.pass_parser_result = true; |
Ioana Ciocoi Radulescu | 27c8748 | 2019-02-04 17:00:35 +0000 | [diff] [blame] | 3064 | buf_layout.data_align = rx_buf_align; |
Bogdan Purcareata | 4b2d9fe | 2017-10-29 08:20:43 +0000 | [diff] [blame] | 3065 | buf_layout.data_head_room = dpaa2_eth_rx_head_room(priv); |
| 3066 | buf_layout.private_data_size = 0; |
| 3067 | buf_layout.options = DPNI_BUF_LAYOUT_OPT_PARSER_RESULT | |
| 3068 | DPNI_BUF_LAYOUT_OPT_FRAME_STATUS | |
| 3069 | DPNI_BUF_LAYOUT_OPT_DATA_ALIGN | |
Ioana Radulescu | 859f998 | 2018-04-26 18:23:47 +0800 | [diff] [blame] | 3070 | DPNI_BUF_LAYOUT_OPT_DATA_HEAD_ROOM | |
| 3071 | DPNI_BUF_LAYOUT_OPT_TIMESTAMP; |
Bogdan Purcareata | 4b2d9fe | 2017-10-29 08:20:43 +0000 | [diff] [blame] | 3072 | err = dpni_set_buffer_layout(priv->mc_io, 0, priv->mc_token, |
| 3073 | DPNI_QUEUE_RX, &buf_layout); |
| 3074 | if (err) { |
| 3075 | dev_err(dev, "dpni_set_buffer_layout(RX) failed\n"); |
| 3076 | return err; |
| 3077 | } |
| 3078 | |
Ioana Radulescu | 308f64e | 2017-10-29 08:20:40 +0000 | [diff] [blame] | 3079 | return 0; |
| 3080 | } |
| 3081 | |
Ioana Ciocoi Radulescu | 1fa0f68 | 2019-02-04 17:00:36 +0000 | [diff] [blame] | 3082 | #define DPNI_ENQUEUE_FQID_VER_MAJOR 7 |
| 3083 | #define DPNI_ENQUEUE_FQID_VER_MINOR 9 |
| 3084 | |
| 3085 | static inline int dpaa2_eth_enqueue_qd(struct dpaa2_eth_priv *priv, |
| 3086 | struct dpaa2_eth_fq *fq, |
Ioana Ciornei | 48c0481 | 2020-04-22 15:05:10 +0300 | [diff] [blame] | 3087 | struct dpaa2_fd *fd, u8 prio, |
Ioana Ciornei | 6ff8044 | 2020-04-22 15:05:11 +0300 | [diff] [blame] | 3088 | u32 num_frames __always_unused, |
Ioana Ciornei | 48c0481 | 2020-04-22 15:05:10 +0300 | [diff] [blame] | 3089 | int *frames_enqueued) |
Ioana Ciocoi Radulescu | 1fa0f68 | 2019-02-04 17:00:36 +0000 | [diff] [blame] | 3090 | { |
Ioana Ciornei | 48c0481 | 2020-04-22 15:05:10 +0300 | [diff] [blame] | 3091 | int err; |
| 3092 | |
| 3093 | err = dpaa2_io_service_enqueue_qd(fq->channel->dpio, |
| 3094 | priv->tx_qdid, prio, |
| 3095 | fq->tx_qdbin, fd); |
| 3096 | if (!err && frames_enqueued) |
| 3097 | *frames_enqueued = 1; |
| 3098 | return err; |
Ioana Ciocoi Radulescu | 1fa0f68 | 2019-02-04 17:00:36 +0000 | [diff] [blame] | 3099 | } |
| 3100 | |
Ioana Ciornei | 6ff8044 | 2020-04-22 15:05:11 +0300 | [diff] [blame] | 3101 | static inline int dpaa2_eth_enqueue_fq_multiple(struct dpaa2_eth_priv *priv, |
| 3102 | struct dpaa2_eth_fq *fq, |
| 3103 | struct dpaa2_fd *fd, |
| 3104 | u8 prio, u32 num_frames, |
| 3105 | int *frames_enqueued) |
Ioana Ciocoi Radulescu | 1fa0f68 | 2019-02-04 17:00:36 +0000 | [diff] [blame] | 3106 | { |
Ioana Ciornei | 48c0481 | 2020-04-22 15:05:10 +0300 | [diff] [blame] | 3107 | int err; |
| 3108 | |
Ioana Ciornei | 6ff8044 | 2020-04-22 15:05:11 +0300 | [diff] [blame] | 3109 | err = dpaa2_io_service_enqueue_multiple_fq(fq->channel->dpio, |
| 3110 | fq->tx_fqid[prio], |
| 3111 | fd, num_frames); |
| 3112 | |
| 3113 | if (err == 0) |
| 3114 | return -EBUSY; |
| 3115 | |
| 3116 | if (frames_enqueued) |
| 3117 | *frames_enqueued = err; |
| 3118 | return 0; |
Ioana Ciocoi Radulescu | 1fa0f68 | 2019-02-04 17:00:36 +0000 | [diff] [blame] | 3119 | } |
| 3120 | |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 3121 | static void dpaa2_eth_set_enqueue_mode(struct dpaa2_eth_priv *priv) |
Ioana Ciocoi Radulescu | 1fa0f68 | 2019-02-04 17:00:36 +0000 | [diff] [blame] | 3122 | { |
| 3123 | if (dpaa2_eth_cmp_dpni_ver(priv, DPNI_ENQUEUE_FQID_VER_MAJOR, |
| 3124 | DPNI_ENQUEUE_FQID_VER_MINOR) < 0) |
| 3125 | priv->enqueue = dpaa2_eth_enqueue_qd; |
| 3126 | else |
Ioana Ciornei | 6ff8044 | 2020-04-22 15:05:11 +0300 | [diff] [blame] | 3127 | priv->enqueue = dpaa2_eth_enqueue_fq_multiple; |
Ioana Ciocoi Radulescu | 1fa0f68 | 2019-02-04 17:00:36 +0000 | [diff] [blame] | 3128 | } |
| 3129 | |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 3130 | static int dpaa2_eth_set_pause(struct dpaa2_eth_priv *priv) |
Ioana Radulescu | 8eb3cef | 2019-08-28 17:08:15 +0300 | [diff] [blame] | 3131 | { |
| 3132 | struct device *dev = priv->net_dev->dev.parent; |
| 3133 | struct dpni_link_cfg link_cfg = {0}; |
| 3134 | int err; |
| 3135 | |
| 3136 | /* Get the default link options so we don't override other flags */ |
| 3137 | err = dpni_get_link_cfg(priv->mc_io, 0, priv->mc_token, &link_cfg); |
| 3138 | if (err) { |
| 3139 | dev_err(dev, "dpni_get_link_cfg() failed\n"); |
| 3140 | return err; |
| 3141 | } |
| 3142 | |
| 3143 | /* By default, enable both Rx and Tx pause frames */ |
| 3144 | link_cfg.options |= DPNI_LINK_OPT_PAUSE; |
| 3145 | link_cfg.options &= ~DPNI_LINK_OPT_ASYM_PAUSE; |
| 3146 | err = dpni_set_link_cfg(priv->mc_io, 0, priv->mc_token, &link_cfg); |
| 3147 | if (err) { |
| 3148 | dev_err(dev, "dpni_set_link_cfg() failed\n"); |
| 3149 | return err; |
| 3150 | } |
| 3151 | |
| 3152 | priv->link_state.options = link_cfg.options; |
| 3153 | |
| 3154 | return 0; |
| 3155 | } |
| 3156 | |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 3157 | static void dpaa2_eth_update_tx_fqids(struct dpaa2_eth_priv *priv) |
Ioana Radulescu | a690af4f | 2019-10-16 10:36:23 +0300 | [diff] [blame] | 3158 | { |
| 3159 | struct dpni_queue_id qid = {0}; |
| 3160 | struct dpaa2_eth_fq *fq; |
| 3161 | struct dpni_queue queue; |
| 3162 | int i, j, err; |
| 3163 | |
| 3164 | /* We only use Tx FQIDs for FQID-based enqueue, so check |
| 3165 | * if DPNI version supports it before updating FQIDs |
| 3166 | */ |
| 3167 | if (dpaa2_eth_cmp_dpni_ver(priv, DPNI_ENQUEUE_FQID_VER_MAJOR, |
| 3168 | DPNI_ENQUEUE_FQID_VER_MINOR) < 0) |
| 3169 | return; |
| 3170 | |
| 3171 | for (i = 0; i < priv->num_fqs; i++) { |
| 3172 | fq = &priv->fq[i]; |
| 3173 | if (fq->type != DPAA2_TX_CONF_FQ) |
| 3174 | continue; |
| 3175 | for (j = 0; j < dpaa2_eth_tc_count(priv); j++) { |
| 3176 | err = dpni_get_queue(priv->mc_io, 0, priv->mc_token, |
| 3177 | DPNI_QUEUE_TX, j, fq->flowid, |
| 3178 | &queue, &qid); |
| 3179 | if (err) |
| 3180 | goto out_err; |
| 3181 | |
| 3182 | fq->tx_fqid[j] = qid.fqid; |
| 3183 | if (fq->tx_fqid[j] == 0) |
| 3184 | goto out_err; |
| 3185 | } |
| 3186 | } |
| 3187 | |
Ioana Ciornei | 6ff8044 | 2020-04-22 15:05:11 +0300 | [diff] [blame] | 3188 | priv->enqueue = dpaa2_eth_enqueue_fq_multiple; |
Ioana Radulescu | a690af4f | 2019-10-16 10:36:23 +0300 | [diff] [blame] | 3189 | |
| 3190 | return; |
| 3191 | |
| 3192 | out_err: |
| 3193 | netdev_info(priv->net_dev, |
| 3194 | "Error reading Tx FQID, fallback to QDID-based enqueue\n"); |
| 3195 | priv->enqueue = dpaa2_eth_enqueue_qd; |
| 3196 | } |
| 3197 | |
Ioana Radulescu | 6aa90fe | 2020-05-31 00:08:09 +0300 | [diff] [blame] | 3198 | /* Configure ingress classification based on VLAN PCP */ |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 3199 | static int dpaa2_eth_set_vlan_qos(struct dpaa2_eth_priv *priv) |
Ioana Radulescu | 6aa90fe | 2020-05-31 00:08:09 +0300 | [diff] [blame] | 3200 | { |
| 3201 | struct device *dev = priv->net_dev->dev.parent; |
| 3202 | struct dpkg_profile_cfg kg_cfg = {0}; |
| 3203 | struct dpni_qos_tbl_cfg qos_cfg = {0}; |
| 3204 | struct dpni_rule_cfg key_params; |
| 3205 | void *dma_mem, *key, *mask; |
| 3206 | u8 key_size = 2; /* VLAN TCI field */ |
| 3207 | int i, pcp, err; |
| 3208 | |
| 3209 | /* VLAN-based classification only makes sense if we have multiple |
| 3210 | * traffic classes. |
| 3211 | * Also, we need to extract just the 3-bit PCP field from the VLAN |
| 3212 | * header and we can only do that by using a mask |
| 3213 | */ |
| 3214 | if (dpaa2_eth_tc_count(priv) == 1 || !dpaa2_eth_fs_mask_enabled(priv)) { |
| 3215 | dev_dbg(dev, "VLAN-based QoS classification not supported\n"); |
| 3216 | return -EOPNOTSUPP; |
| 3217 | } |
| 3218 | |
| 3219 | dma_mem = kzalloc(DPAA2_CLASSIFIER_DMA_SIZE, GFP_KERNEL); |
| 3220 | if (!dma_mem) |
| 3221 | return -ENOMEM; |
| 3222 | |
| 3223 | kg_cfg.num_extracts = 1; |
| 3224 | kg_cfg.extracts[0].type = DPKG_EXTRACT_FROM_HDR; |
| 3225 | kg_cfg.extracts[0].extract.from_hdr.prot = NET_PROT_VLAN; |
| 3226 | kg_cfg.extracts[0].extract.from_hdr.type = DPKG_FULL_FIELD; |
| 3227 | kg_cfg.extracts[0].extract.from_hdr.field = NH_FLD_VLAN_TCI; |
| 3228 | |
| 3229 | err = dpni_prepare_key_cfg(&kg_cfg, dma_mem); |
| 3230 | if (err) { |
| 3231 | dev_err(dev, "dpni_prepare_key_cfg failed\n"); |
| 3232 | goto out_free_tbl; |
| 3233 | } |
| 3234 | |
| 3235 | /* set QoS table */ |
| 3236 | qos_cfg.default_tc = 0; |
| 3237 | qos_cfg.discard_on_miss = 0; |
| 3238 | qos_cfg.key_cfg_iova = dma_map_single(dev, dma_mem, |
| 3239 | DPAA2_CLASSIFIER_DMA_SIZE, |
| 3240 | DMA_TO_DEVICE); |
| 3241 | if (dma_mapping_error(dev, qos_cfg.key_cfg_iova)) { |
| 3242 | dev_err(dev, "QoS table DMA mapping failed\n"); |
| 3243 | err = -ENOMEM; |
| 3244 | goto out_free_tbl; |
| 3245 | } |
| 3246 | |
| 3247 | err = dpni_set_qos_table(priv->mc_io, 0, priv->mc_token, &qos_cfg); |
| 3248 | if (err) { |
| 3249 | dev_err(dev, "dpni_set_qos_table failed\n"); |
| 3250 | goto out_unmap_tbl; |
| 3251 | } |
| 3252 | |
| 3253 | /* Add QoS table entries */ |
| 3254 | key = kzalloc(key_size * 2, GFP_KERNEL); |
| 3255 | if (!key) { |
| 3256 | err = -ENOMEM; |
| 3257 | goto out_unmap_tbl; |
| 3258 | } |
| 3259 | mask = key + key_size; |
| 3260 | *(__be16 *)mask = cpu_to_be16(VLAN_PRIO_MASK); |
| 3261 | |
| 3262 | key_params.key_iova = dma_map_single(dev, key, key_size * 2, |
| 3263 | DMA_TO_DEVICE); |
| 3264 | if (dma_mapping_error(dev, key_params.key_iova)) { |
| 3265 | dev_err(dev, "Qos table entry DMA mapping failed\n"); |
| 3266 | err = -ENOMEM; |
| 3267 | goto out_free_key; |
| 3268 | } |
| 3269 | |
| 3270 | key_params.mask_iova = key_params.key_iova + key_size; |
| 3271 | key_params.key_size = key_size; |
| 3272 | |
| 3273 | /* We add rules for PCP-based distribution starting with highest |
| 3274 | * priority (VLAN PCP = 7). If this DPNI doesn't have enough traffic |
| 3275 | * classes to accommodate all priority levels, the lowest ones end up |
| 3276 | * on TC 0 which was configured as default |
| 3277 | */ |
| 3278 | for (i = dpaa2_eth_tc_count(priv) - 1, pcp = 7; i >= 0; i--, pcp--) { |
| 3279 | *(__be16 *)key = cpu_to_be16(pcp << VLAN_PRIO_SHIFT); |
| 3280 | dma_sync_single_for_device(dev, key_params.key_iova, |
| 3281 | key_size * 2, DMA_TO_DEVICE); |
| 3282 | |
| 3283 | err = dpni_add_qos_entry(priv->mc_io, 0, priv->mc_token, |
| 3284 | &key_params, i, i); |
| 3285 | if (err) { |
| 3286 | dev_err(dev, "dpni_add_qos_entry failed\n"); |
| 3287 | dpni_clear_qos_table(priv->mc_io, 0, priv->mc_token); |
| 3288 | goto out_unmap_key; |
| 3289 | } |
| 3290 | } |
| 3291 | |
| 3292 | priv->vlan_cls_enabled = true; |
| 3293 | |
| 3294 | /* Table and key memory is not persistent, clean everything up after |
| 3295 | * configuration is finished |
| 3296 | */ |
| 3297 | out_unmap_key: |
| 3298 | dma_unmap_single(dev, key_params.key_iova, key_size * 2, DMA_TO_DEVICE); |
| 3299 | out_free_key: |
| 3300 | kfree(key); |
| 3301 | out_unmap_tbl: |
| 3302 | dma_unmap_single(dev, qos_cfg.key_cfg_iova, DPAA2_CLASSIFIER_DMA_SIZE, |
| 3303 | DMA_TO_DEVICE); |
| 3304 | out_free_tbl: |
| 3305 | kfree(dma_mem); |
| 3306 | |
| 3307 | return err; |
| 3308 | } |
| 3309 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3310 | /* Configure the DPNI object this interface is associated with */ |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 3311 | static int dpaa2_eth_setup_dpni(struct fsl_mc_device *ls_dev) |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3312 | { |
| 3313 | struct device *dev = &ls_dev->dev; |
| 3314 | struct dpaa2_eth_priv *priv; |
| 3315 | struct net_device *net_dev; |
| 3316 | int err; |
| 3317 | |
| 3318 | net_dev = dev_get_drvdata(dev); |
| 3319 | priv = netdev_priv(net_dev); |
| 3320 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3321 | /* get a handle for the DPNI object */ |
Ioana Radulescu | 50eacbc | 2017-06-06 10:00:36 -0500 | [diff] [blame] | 3322 | err = dpni_open(priv->mc_io, 0, ls_dev->obj_desc.id, &priv->mc_token); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3323 | if (err) { |
| 3324 | dev_err(dev, "dpni_open() failed\n"); |
Ioana Radulescu | f6dda80 | 2017-10-29 08:20:39 +0000 | [diff] [blame] | 3325 | return err; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3326 | } |
| 3327 | |
Ioana Radulescu | 311cffa | 2018-03-23 08:44:09 -0500 | [diff] [blame] | 3328 | /* Check if we can work with this DPNI object */ |
| 3329 | err = dpni_get_api_version(priv->mc_io, 0, &priv->dpni_ver_major, |
| 3330 | &priv->dpni_ver_minor); |
| 3331 | if (err) { |
| 3332 | dev_err(dev, "dpni_get_api_version() failed\n"); |
| 3333 | goto close; |
| 3334 | } |
| 3335 | if (dpaa2_eth_cmp_dpni_ver(priv, DPNI_VER_MAJOR, DPNI_VER_MINOR) < 0) { |
| 3336 | dev_err(dev, "DPNI version %u.%u not supported, need >= %u.%u\n", |
| 3337 | priv->dpni_ver_major, priv->dpni_ver_minor, |
| 3338 | DPNI_VER_MAJOR, DPNI_VER_MINOR); |
| 3339 | err = -ENOTSUPP; |
| 3340 | goto close; |
| 3341 | } |
| 3342 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3343 | ls_dev->mc_io = priv->mc_io; |
| 3344 | ls_dev->mc_handle = priv->mc_token; |
| 3345 | |
| 3346 | err = dpni_reset(priv->mc_io, 0, priv->mc_token); |
| 3347 | if (err) { |
| 3348 | dev_err(dev, "dpni_reset() failed\n"); |
Ioana Radulescu | f6dda80 | 2017-10-29 08:20:39 +0000 | [diff] [blame] | 3349 | goto close; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3350 | } |
| 3351 | |
| 3352 | err = dpni_get_attributes(priv->mc_io, 0, priv->mc_token, |
| 3353 | &priv->dpni_attrs); |
| 3354 | if (err) { |
| 3355 | dev_err(dev, "dpni_get_attributes() failed (err=%d)\n", err); |
Ioana Radulescu | f6dda80 | 2017-10-29 08:20:39 +0000 | [diff] [blame] | 3356 | goto close; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3357 | } |
| 3358 | |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 3359 | err = dpaa2_eth_set_buffer_layout(priv); |
Ioana Radulescu | 308f64e | 2017-10-29 08:20:40 +0000 | [diff] [blame] | 3360 | if (err) |
Ioana Radulescu | f6dda80 | 2017-10-29 08:20:39 +0000 | [diff] [blame] | 3361 | goto close; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3362 | |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 3363 | dpaa2_eth_set_enqueue_mode(priv); |
Ioana Ciocoi Radulescu | 1fa0f68 | 2019-02-04 17:00:36 +0000 | [diff] [blame] | 3364 | |
Ioana Radulescu | 8eb3cef | 2019-08-28 17:08:15 +0300 | [diff] [blame] | 3365 | /* Enable pause frame support */ |
| 3366 | if (dpaa2_eth_has_pause_support(priv)) { |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 3367 | err = dpaa2_eth_set_pause(priv); |
Ioana Radulescu | 8eb3cef | 2019-08-28 17:08:15 +0300 | [diff] [blame] | 3368 | if (err) |
| 3369 | goto close; |
| 3370 | } |
| 3371 | |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 3372 | err = dpaa2_eth_set_vlan_qos(priv); |
Ioana Radulescu | 6aa90fe | 2020-05-31 00:08:09 +0300 | [diff] [blame] | 3373 | if (err && err != -EOPNOTSUPP) |
| 3374 | goto close; |
| 3375 | |
Xu Wang | 9334d5b | 2020-06-11 02:45:20 +0000 | [diff] [blame] | 3376 | priv->cls_rules = devm_kcalloc(dev, dpaa2_eth_fs_count(priv), |
| 3377 | sizeof(struct dpaa2_eth_cls_rule), |
| 3378 | GFP_KERNEL); |
Wei Yongjun | 97fff7c | 2020-04-27 10:43:22 +0000 | [diff] [blame] | 3379 | if (!priv->cls_rules) { |
| 3380 | err = -ENOMEM; |
Ioana Radulescu | afb90db | 2018-10-01 13:44:58 +0300 | [diff] [blame] | 3381 | goto close; |
Wei Yongjun | 97fff7c | 2020-04-27 10:43:22 +0000 | [diff] [blame] | 3382 | } |
Ioana Radulescu | afb90db | 2018-10-01 13:44:58 +0300 | [diff] [blame] | 3383 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3384 | return 0; |
| 3385 | |
Ioana Radulescu | f6dda80 | 2017-10-29 08:20:39 +0000 | [diff] [blame] | 3386 | close: |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3387 | dpni_close(priv->mc_io, 0, priv->mc_token); |
Ioana Radulescu | f6dda80 | 2017-10-29 08:20:39 +0000 | [diff] [blame] | 3388 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3389 | return err; |
| 3390 | } |
| 3391 | |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 3392 | static void dpaa2_eth_free_dpni(struct dpaa2_eth_priv *priv) |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3393 | { |
| 3394 | int err; |
| 3395 | |
| 3396 | err = dpni_reset(priv->mc_io, 0, priv->mc_token); |
| 3397 | if (err) |
| 3398 | netdev_warn(priv->net_dev, "dpni_reset() failed (err %d)\n", |
| 3399 | err); |
| 3400 | |
| 3401 | dpni_close(priv->mc_io, 0, priv->mc_token); |
| 3402 | } |
| 3403 | |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 3404 | static int dpaa2_eth_setup_rx_flow(struct dpaa2_eth_priv *priv, |
| 3405 | struct dpaa2_eth_fq *fq) |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3406 | { |
| 3407 | struct device *dev = priv->net_dev->dev.parent; |
| 3408 | struct dpni_queue queue; |
| 3409 | struct dpni_queue_id qid; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3410 | int err; |
| 3411 | |
| 3412 | err = dpni_get_queue(priv->mc_io, 0, priv->mc_token, |
Ioana Radulescu | 685e39e | 2020-05-31 00:08:08 +0300 | [diff] [blame] | 3413 | DPNI_QUEUE_RX, fq->tc, fq->flowid, &queue, &qid); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3414 | if (err) { |
| 3415 | dev_err(dev, "dpni_get_queue(RX) failed\n"); |
| 3416 | return err; |
| 3417 | } |
| 3418 | |
| 3419 | fq->fqid = qid.fqid; |
| 3420 | |
| 3421 | queue.destination.id = fq->channel->dpcon_id; |
| 3422 | queue.destination.type = DPNI_DEST_DPCON; |
| 3423 | queue.destination.priority = 1; |
Ioana Radulescu | 75c583a | 2018-02-26 10:28:06 -0600 | [diff] [blame] | 3424 | queue.user_context = (u64)(uintptr_t)fq; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3425 | err = dpni_set_queue(priv->mc_io, 0, priv->mc_token, |
Ioana Radulescu | 685e39e | 2020-05-31 00:08:08 +0300 | [diff] [blame] | 3426 | DPNI_QUEUE_RX, fq->tc, fq->flowid, |
Ioana Radulescu | 16fa1cf | 2019-05-23 17:38:22 +0300 | [diff] [blame] | 3427 | DPNI_QUEUE_OPT_USER_CTX | DPNI_QUEUE_OPT_DEST, |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3428 | &queue); |
| 3429 | if (err) { |
| 3430 | dev_err(dev, "dpni_set_queue(RX) failed\n"); |
| 3431 | return err; |
| 3432 | } |
| 3433 | |
Ioana Radulescu | d678be1 | 2019-03-01 17:47:24 +0000 | [diff] [blame] | 3434 | /* xdp_rxq setup */ |
Ioana Radulescu | 685e39e | 2020-05-31 00:08:08 +0300 | [diff] [blame] | 3435 | /* only once for each channel */ |
| 3436 | if (fq->tc > 0) |
| 3437 | return 0; |
| 3438 | |
Ioana Radulescu | d678be1 | 2019-03-01 17:47:24 +0000 | [diff] [blame] | 3439 | err = xdp_rxq_info_reg(&fq->channel->xdp_rxq, priv->net_dev, |
Björn Töpel | b02e5a0 | 2020-11-30 19:52:01 +0100 | [diff] [blame] | 3440 | fq->flowid, 0); |
Ioana Radulescu | d678be1 | 2019-03-01 17:47:24 +0000 | [diff] [blame] | 3441 | if (err) { |
| 3442 | dev_err(dev, "xdp_rxq_info_reg failed\n"); |
| 3443 | return err; |
| 3444 | } |
| 3445 | |
| 3446 | err = xdp_rxq_info_reg_mem_model(&fq->channel->xdp_rxq, |
| 3447 | MEM_TYPE_PAGE_ORDER0, NULL); |
| 3448 | if (err) { |
| 3449 | dev_err(dev, "xdp_rxq_info_reg_mem_model failed\n"); |
| 3450 | return err; |
| 3451 | } |
| 3452 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3453 | return 0; |
| 3454 | } |
| 3455 | |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 3456 | static int dpaa2_eth_setup_tx_flow(struct dpaa2_eth_priv *priv, |
| 3457 | struct dpaa2_eth_fq *fq) |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3458 | { |
| 3459 | struct device *dev = priv->net_dev->dev.parent; |
| 3460 | struct dpni_queue queue; |
| 3461 | struct dpni_queue_id qid; |
Ioana Radulescu | 15c87f6 | 2019-06-11 14:50:02 +0300 | [diff] [blame] | 3462 | int i, err; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3463 | |
Ioana Radulescu | 15c87f6 | 2019-06-11 14:50:02 +0300 | [diff] [blame] | 3464 | for (i = 0; i < dpaa2_eth_tc_count(priv); i++) { |
| 3465 | err = dpni_get_queue(priv->mc_io, 0, priv->mc_token, |
| 3466 | DPNI_QUEUE_TX, i, fq->flowid, |
| 3467 | &queue, &qid); |
| 3468 | if (err) { |
| 3469 | dev_err(dev, "dpni_get_queue(TX) failed\n"); |
| 3470 | return err; |
| 3471 | } |
| 3472 | fq->tx_fqid[i] = qid.fqid; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3473 | } |
| 3474 | |
Ioana Radulescu | 15c87f6 | 2019-06-11 14:50:02 +0300 | [diff] [blame] | 3475 | /* All Tx queues belonging to the same flowid have the same qdbin */ |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3476 | fq->tx_qdbin = qid.qdbin; |
| 3477 | |
| 3478 | err = dpni_get_queue(priv->mc_io, 0, priv->mc_token, |
| 3479 | DPNI_QUEUE_TX_CONFIRM, 0, fq->flowid, |
| 3480 | &queue, &qid); |
| 3481 | if (err) { |
| 3482 | dev_err(dev, "dpni_get_queue(TX_CONF) failed\n"); |
| 3483 | return err; |
| 3484 | } |
| 3485 | |
| 3486 | fq->fqid = qid.fqid; |
| 3487 | |
| 3488 | queue.destination.id = fq->channel->dpcon_id; |
| 3489 | queue.destination.type = DPNI_DEST_DPCON; |
| 3490 | queue.destination.priority = 0; |
Ioana Radulescu | 75c583a | 2018-02-26 10:28:06 -0600 | [diff] [blame] | 3491 | queue.user_context = (u64)(uintptr_t)fq; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3492 | err = dpni_set_queue(priv->mc_io, 0, priv->mc_token, |
| 3493 | DPNI_QUEUE_TX_CONFIRM, 0, fq->flowid, |
| 3494 | DPNI_QUEUE_OPT_USER_CTX | DPNI_QUEUE_OPT_DEST, |
| 3495 | &queue); |
| 3496 | if (err) { |
| 3497 | dev_err(dev, "dpni_set_queue(TX_CONF) failed\n"); |
| 3498 | return err; |
| 3499 | } |
| 3500 | |
| 3501 | return 0; |
| 3502 | } |
| 3503 | |
Ioana Ciornei | 061d631 | 2020-10-01 18:11:48 +0300 | [diff] [blame] | 3504 | static int setup_rx_err_flow(struct dpaa2_eth_priv *priv, |
| 3505 | struct dpaa2_eth_fq *fq) |
| 3506 | { |
| 3507 | struct device *dev = priv->net_dev->dev.parent; |
| 3508 | struct dpni_queue q = { { 0 } }; |
| 3509 | struct dpni_queue_id qid; |
| 3510 | u8 q_opt = DPNI_QUEUE_OPT_USER_CTX | DPNI_QUEUE_OPT_DEST; |
| 3511 | int err; |
| 3512 | |
| 3513 | err = dpni_get_queue(priv->mc_io, 0, priv->mc_token, |
| 3514 | DPNI_QUEUE_RX_ERR, 0, 0, &q, &qid); |
| 3515 | if (err) { |
| 3516 | dev_err(dev, "dpni_get_queue() failed (%d)\n", err); |
| 3517 | return err; |
| 3518 | } |
| 3519 | |
| 3520 | fq->fqid = qid.fqid; |
| 3521 | |
| 3522 | q.destination.id = fq->channel->dpcon_id; |
| 3523 | q.destination.type = DPNI_DEST_DPCON; |
| 3524 | q.destination.priority = 1; |
| 3525 | q.user_context = (u64)(uintptr_t)fq; |
| 3526 | err = dpni_set_queue(priv->mc_io, 0, priv->mc_token, |
| 3527 | DPNI_QUEUE_RX_ERR, 0, 0, q_opt, &q); |
| 3528 | if (err) { |
| 3529 | dev_err(dev, "dpni_set_queue() failed (%d)\n", err); |
| 3530 | return err; |
| 3531 | } |
| 3532 | |
| 3533 | return 0; |
| 3534 | } |
| 3535 | |
Ioana Ciocoi Radulescu | edad8d2 | 2018-09-24 15:36:21 +0000 | [diff] [blame] | 3536 | /* Supported header fields for Rx hash distribution key */ |
Ioana Radulescu | f76c483 | 2018-10-01 13:44:56 +0300 | [diff] [blame] | 3537 | static const struct dpaa2_eth_dist_fields dist_fields[] = { |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3538 | { |
Ioana Ciocoi Radulescu | edad8d2 | 2018-09-24 15:36:21 +0000 | [diff] [blame] | 3539 | /* L2 header */ |
| 3540 | .rxnfc_field = RXH_L2DA, |
| 3541 | .cls_prot = NET_PROT_ETH, |
| 3542 | .cls_field = NH_FLD_ETH_DA, |
Ioana Ciocoi Radulescu | 3a1e6b8 | 2019-04-16 17:13:29 +0000 | [diff] [blame] | 3543 | .id = DPAA2_ETH_DIST_ETHDST, |
Ioana Ciocoi Radulescu | edad8d2 | 2018-09-24 15:36:21 +0000 | [diff] [blame] | 3544 | .size = 6, |
| 3545 | }, { |
Ioana Radulescu | afb90db | 2018-10-01 13:44:58 +0300 | [diff] [blame] | 3546 | .cls_prot = NET_PROT_ETH, |
| 3547 | .cls_field = NH_FLD_ETH_SA, |
Ioana Ciocoi Radulescu | 3a1e6b8 | 2019-04-16 17:13:29 +0000 | [diff] [blame] | 3548 | .id = DPAA2_ETH_DIST_ETHSRC, |
Ioana Radulescu | afb90db | 2018-10-01 13:44:58 +0300 | [diff] [blame] | 3549 | .size = 6, |
| 3550 | }, { |
| 3551 | /* This is the last ethertype field parsed: |
| 3552 | * depending on frame format, it can be the MAC ethertype |
| 3553 | * or the VLAN etype. |
| 3554 | */ |
| 3555 | .cls_prot = NET_PROT_ETH, |
| 3556 | .cls_field = NH_FLD_ETH_TYPE, |
Ioana Ciocoi Radulescu | 3a1e6b8 | 2019-04-16 17:13:29 +0000 | [diff] [blame] | 3557 | .id = DPAA2_ETH_DIST_ETHTYPE, |
Ioana Radulescu | afb90db | 2018-10-01 13:44:58 +0300 | [diff] [blame] | 3558 | .size = 2, |
| 3559 | }, { |
Ioana Ciocoi Radulescu | edad8d2 | 2018-09-24 15:36:21 +0000 | [diff] [blame] | 3560 | /* VLAN header */ |
| 3561 | .rxnfc_field = RXH_VLAN, |
| 3562 | .cls_prot = NET_PROT_VLAN, |
| 3563 | .cls_field = NH_FLD_VLAN_TCI, |
Ioana Ciocoi Radulescu | 3a1e6b8 | 2019-04-16 17:13:29 +0000 | [diff] [blame] | 3564 | .id = DPAA2_ETH_DIST_VLAN, |
Ioana Ciocoi Radulescu | edad8d2 | 2018-09-24 15:36:21 +0000 | [diff] [blame] | 3565 | .size = 2, |
| 3566 | }, { |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3567 | /* IP header */ |
| 3568 | .rxnfc_field = RXH_IP_SRC, |
| 3569 | .cls_prot = NET_PROT_IP, |
| 3570 | .cls_field = NH_FLD_IP_SRC, |
Ioana Ciocoi Radulescu | 3a1e6b8 | 2019-04-16 17:13:29 +0000 | [diff] [blame] | 3571 | .id = DPAA2_ETH_DIST_IPSRC, |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3572 | .size = 4, |
| 3573 | }, { |
| 3574 | .rxnfc_field = RXH_IP_DST, |
| 3575 | .cls_prot = NET_PROT_IP, |
| 3576 | .cls_field = NH_FLD_IP_DST, |
Ioana Ciocoi Radulescu | 3a1e6b8 | 2019-04-16 17:13:29 +0000 | [diff] [blame] | 3577 | .id = DPAA2_ETH_DIST_IPDST, |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3578 | .size = 4, |
| 3579 | }, { |
| 3580 | .rxnfc_field = RXH_L3_PROTO, |
| 3581 | .cls_prot = NET_PROT_IP, |
| 3582 | .cls_field = NH_FLD_IP_PROTO, |
Ioana Ciocoi Radulescu | 3a1e6b8 | 2019-04-16 17:13:29 +0000 | [diff] [blame] | 3583 | .id = DPAA2_ETH_DIST_IPPROTO, |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3584 | .size = 1, |
| 3585 | }, { |
| 3586 | /* Using UDP ports, this is functionally equivalent to raw |
| 3587 | * byte pairs from L4 header. |
| 3588 | */ |
| 3589 | .rxnfc_field = RXH_L4_B_0_1, |
| 3590 | .cls_prot = NET_PROT_UDP, |
| 3591 | .cls_field = NH_FLD_UDP_PORT_SRC, |
Ioana Ciocoi Radulescu | 3a1e6b8 | 2019-04-16 17:13:29 +0000 | [diff] [blame] | 3592 | .id = DPAA2_ETH_DIST_L4SRC, |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3593 | .size = 2, |
| 3594 | }, { |
| 3595 | .rxnfc_field = RXH_L4_B_2_3, |
| 3596 | .cls_prot = NET_PROT_UDP, |
| 3597 | .cls_field = NH_FLD_UDP_PORT_DST, |
Ioana Ciocoi Radulescu | 3a1e6b8 | 2019-04-16 17:13:29 +0000 | [diff] [blame] | 3598 | .id = DPAA2_ETH_DIST_L4DST, |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3599 | .size = 2, |
| 3600 | }, |
| 3601 | }; |
| 3602 | |
Ioana Radulescu | df85aeb | 2018-10-01 13:44:55 +0300 | [diff] [blame] | 3603 | /* Configure the Rx hash key using the legacy API */ |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 3604 | static int dpaa2_eth_config_legacy_hash_key(struct dpaa2_eth_priv *priv, dma_addr_t key) |
Ioana Radulescu | df85aeb | 2018-10-01 13:44:55 +0300 | [diff] [blame] | 3605 | { |
| 3606 | struct device *dev = priv->net_dev->dev.parent; |
| 3607 | struct dpni_rx_tc_dist_cfg dist_cfg; |
Ioana Radulescu | 685e39e | 2020-05-31 00:08:08 +0300 | [diff] [blame] | 3608 | int i, err = 0; |
Ioana Radulescu | df85aeb | 2018-10-01 13:44:55 +0300 | [diff] [blame] | 3609 | |
| 3610 | memset(&dist_cfg, 0, sizeof(dist_cfg)); |
| 3611 | |
| 3612 | dist_cfg.key_cfg_iova = key; |
| 3613 | dist_cfg.dist_size = dpaa2_eth_queue_count(priv); |
| 3614 | dist_cfg.dist_mode = DPNI_DIST_MODE_HASH; |
| 3615 | |
Ioana Radulescu | 685e39e | 2020-05-31 00:08:08 +0300 | [diff] [blame] | 3616 | for (i = 0; i < dpaa2_eth_tc_count(priv); i++) { |
| 3617 | err = dpni_set_rx_tc_dist(priv->mc_io, 0, priv->mc_token, |
| 3618 | i, &dist_cfg); |
| 3619 | if (err) { |
| 3620 | dev_err(dev, "dpni_set_rx_tc_dist failed\n"); |
| 3621 | break; |
| 3622 | } |
| 3623 | } |
Ioana Radulescu | df85aeb | 2018-10-01 13:44:55 +0300 | [diff] [blame] | 3624 | |
| 3625 | return err; |
| 3626 | } |
| 3627 | |
| 3628 | /* Configure the Rx hash key using the new API */ |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 3629 | static int dpaa2_eth_config_hash_key(struct dpaa2_eth_priv *priv, dma_addr_t key) |
Ioana Radulescu | df85aeb | 2018-10-01 13:44:55 +0300 | [diff] [blame] | 3630 | { |
| 3631 | struct device *dev = priv->net_dev->dev.parent; |
| 3632 | struct dpni_rx_dist_cfg dist_cfg; |
Ioana Radulescu | 685e39e | 2020-05-31 00:08:08 +0300 | [diff] [blame] | 3633 | int i, err = 0; |
Ioana Radulescu | df85aeb | 2018-10-01 13:44:55 +0300 | [diff] [blame] | 3634 | |
| 3635 | memset(&dist_cfg, 0, sizeof(dist_cfg)); |
| 3636 | |
| 3637 | dist_cfg.key_cfg_iova = key; |
| 3638 | dist_cfg.dist_size = dpaa2_eth_queue_count(priv); |
| 3639 | dist_cfg.enable = 1; |
| 3640 | |
Ioana Radulescu | 685e39e | 2020-05-31 00:08:08 +0300 | [diff] [blame] | 3641 | for (i = 0; i < dpaa2_eth_tc_count(priv); i++) { |
| 3642 | dist_cfg.tc = i; |
| 3643 | err = dpni_set_rx_hash_dist(priv->mc_io, 0, priv->mc_token, |
| 3644 | &dist_cfg); |
| 3645 | if (err) { |
| 3646 | dev_err(dev, "dpni_set_rx_hash_dist failed\n"); |
| 3647 | break; |
| 3648 | } |
Ionut-robert Aron | 5e29c16 | 2020-09-25 17:44:21 +0300 | [diff] [blame] | 3649 | |
| 3650 | /* If the flow steering / hashing key is shared between all |
| 3651 | * traffic classes, install it just once |
| 3652 | */ |
| 3653 | if (priv->dpni_attrs.options & DPNI_OPT_SHARED_FS) |
| 3654 | break; |
Ioana Radulescu | 685e39e | 2020-05-31 00:08:08 +0300 | [diff] [blame] | 3655 | } |
Ioana Radulescu | df85aeb | 2018-10-01 13:44:55 +0300 | [diff] [blame] | 3656 | |
| 3657 | return err; |
| 3658 | } |
| 3659 | |
Ioana Radulescu | 4aaaf9b | 2018-10-01 13:44:57 +0300 | [diff] [blame] | 3660 | /* Configure the Rx flow classification key */ |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 3661 | static int dpaa2_eth_config_cls_key(struct dpaa2_eth_priv *priv, dma_addr_t key) |
Ioana Radulescu | 4aaaf9b | 2018-10-01 13:44:57 +0300 | [diff] [blame] | 3662 | { |
| 3663 | struct device *dev = priv->net_dev->dev.parent; |
| 3664 | struct dpni_rx_dist_cfg dist_cfg; |
Ioana Radulescu | 685e39e | 2020-05-31 00:08:08 +0300 | [diff] [blame] | 3665 | int i, err = 0; |
Ioana Radulescu | 4aaaf9b | 2018-10-01 13:44:57 +0300 | [diff] [blame] | 3666 | |
| 3667 | memset(&dist_cfg, 0, sizeof(dist_cfg)); |
| 3668 | |
| 3669 | dist_cfg.key_cfg_iova = key; |
| 3670 | dist_cfg.dist_size = dpaa2_eth_queue_count(priv); |
| 3671 | dist_cfg.enable = 1; |
| 3672 | |
Ioana Radulescu | 685e39e | 2020-05-31 00:08:08 +0300 | [diff] [blame] | 3673 | for (i = 0; i < dpaa2_eth_tc_count(priv); i++) { |
| 3674 | dist_cfg.tc = i; |
| 3675 | err = dpni_set_rx_fs_dist(priv->mc_io, 0, priv->mc_token, |
| 3676 | &dist_cfg); |
| 3677 | if (err) { |
| 3678 | dev_err(dev, "dpni_set_rx_fs_dist failed\n"); |
| 3679 | break; |
| 3680 | } |
Ionut-robert Aron | 5e29c16 | 2020-09-25 17:44:21 +0300 | [diff] [blame] | 3681 | |
| 3682 | /* If the flow steering / hashing key is shared between all |
| 3683 | * traffic classes, install it just once |
| 3684 | */ |
| 3685 | if (priv->dpni_attrs.options & DPNI_OPT_SHARED_FS) |
| 3686 | break; |
Ioana Radulescu | 685e39e | 2020-05-31 00:08:08 +0300 | [diff] [blame] | 3687 | } |
Ioana Radulescu | 4aaaf9b | 2018-10-01 13:44:57 +0300 | [diff] [blame] | 3688 | |
| 3689 | return err; |
| 3690 | } |
| 3691 | |
Ioana Radulescu | afb90db | 2018-10-01 13:44:58 +0300 | [diff] [blame] | 3692 | /* Size of the Rx flow classification key */ |
Ioana Ciocoi Radulescu | 2d68023 | 2019-04-16 17:13:30 +0000 | [diff] [blame] | 3693 | int dpaa2_eth_cls_key_size(u64 fields) |
Ioana Radulescu | afb90db | 2018-10-01 13:44:58 +0300 | [diff] [blame] | 3694 | { |
| 3695 | int i, size = 0; |
| 3696 | |
Ioana Ciocoi Radulescu | 2d68023 | 2019-04-16 17:13:30 +0000 | [diff] [blame] | 3697 | for (i = 0; i < ARRAY_SIZE(dist_fields); i++) { |
| 3698 | if (!(fields & dist_fields[i].id)) |
| 3699 | continue; |
Ioana Radulescu | afb90db | 2018-10-01 13:44:58 +0300 | [diff] [blame] | 3700 | size += dist_fields[i].size; |
Ioana Ciocoi Radulescu | 2d68023 | 2019-04-16 17:13:30 +0000 | [diff] [blame] | 3701 | } |
Ioana Radulescu | afb90db | 2018-10-01 13:44:58 +0300 | [diff] [blame] | 3702 | |
| 3703 | return size; |
| 3704 | } |
| 3705 | |
| 3706 | /* Offset of header field in Rx classification key */ |
| 3707 | int dpaa2_eth_cls_fld_off(int prot, int field) |
| 3708 | { |
| 3709 | int i, off = 0; |
| 3710 | |
| 3711 | for (i = 0; i < ARRAY_SIZE(dist_fields); i++) { |
| 3712 | if (dist_fields[i].cls_prot == prot && |
| 3713 | dist_fields[i].cls_field == field) |
| 3714 | return off; |
| 3715 | off += dist_fields[i].size; |
| 3716 | } |
| 3717 | |
| 3718 | WARN_ONCE(1, "Unsupported header field used for Rx flow cls\n"); |
| 3719 | return 0; |
| 3720 | } |
| 3721 | |
Ioana Ciocoi Radulescu | 2d68023 | 2019-04-16 17:13:30 +0000 | [diff] [blame] | 3722 | /* Prune unused fields from the classification rule. |
| 3723 | * Used when masking is not supported |
| 3724 | */ |
| 3725 | void dpaa2_eth_cls_trim_rule(void *key_mem, u64 fields) |
| 3726 | { |
| 3727 | int off = 0, new_off = 0; |
| 3728 | int i, size; |
| 3729 | |
| 3730 | for (i = 0; i < ARRAY_SIZE(dist_fields); i++) { |
| 3731 | size = dist_fields[i].size; |
| 3732 | if (dist_fields[i].id & fields) { |
| 3733 | memcpy(key_mem + new_off, key_mem + off, size); |
| 3734 | new_off += size; |
| 3735 | } |
| 3736 | off += size; |
| 3737 | } |
| 3738 | } |
| 3739 | |
Ioana Radulescu | 4aaaf9b | 2018-10-01 13:44:57 +0300 | [diff] [blame] | 3740 | /* Set Rx distribution (hash or flow classification) key |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3741 | * flags is a combination of RXH_ bits |
| 3742 | */ |
Ioana Ciornei | 3233c15 | 2018-10-12 16:27:29 +0000 | [diff] [blame] | 3743 | static int dpaa2_eth_set_dist_key(struct net_device *net_dev, |
| 3744 | enum dpaa2_eth_rx_dist type, u64 flags) |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3745 | { |
| 3746 | struct device *dev = net_dev->dev.parent; |
| 3747 | struct dpaa2_eth_priv *priv = netdev_priv(net_dev); |
| 3748 | struct dpkg_profile_cfg cls_cfg; |
Ioana Ciocoi Radulescu | edad8d2 | 2018-09-24 15:36:21 +0000 | [diff] [blame] | 3749 | u32 rx_hash_fields = 0; |
Ioana Radulescu | df85aeb | 2018-10-01 13:44:55 +0300 | [diff] [blame] | 3750 | dma_addr_t key_iova; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3751 | u8 *dma_mem; |
| 3752 | int i; |
| 3753 | int err = 0; |
| 3754 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3755 | memset(&cls_cfg, 0, sizeof(cls_cfg)); |
| 3756 | |
Ioana Radulescu | f76c483 | 2018-10-01 13:44:56 +0300 | [diff] [blame] | 3757 | for (i = 0; i < ARRAY_SIZE(dist_fields); i++) { |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3758 | struct dpkg_extract *key = |
| 3759 | &cls_cfg.extracts[cls_cfg.num_extracts]; |
| 3760 | |
Ioana Ciocoi Radulescu | 2d68023 | 2019-04-16 17:13:30 +0000 | [diff] [blame] | 3761 | /* For both Rx hashing and classification keys |
| 3762 | * we set only the selected fields. |
Ioana Radulescu | 4aaaf9b | 2018-10-01 13:44:57 +0300 | [diff] [blame] | 3763 | */ |
Ioana Ciocoi Radulescu | 2d68023 | 2019-04-16 17:13:30 +0000 | [diff] [blame] | 3764 | if (!(flags & dist_fields[i].id)) |
| 3765 | continue; |
| 3766 | if (type == DPAA2_ETH_RX_DIST_HASH) |
Ioana Radulescu | 4aaaf9b | 2018-10-01 13:44:57 +0300 | [diff] [blame] | 3767 | rx_hash_fields |= dist_fields[i].rxnfc_field; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3768 | |
| 3769 | if (cls_cfg.num_extracts >= DPKG_MAX_NUM_OF_EXTRACTS) { |
| 3770 | dev_err(dev, "error adding key extraction rule, too many rules?\n"); |
| 3771 | return -E2BIG; |
| 3772 | } |
| 3773 | |
| 3774 | key->type = DPKG_EXTRACT_FROM_HDR; |
Ioana Radulescu | f76c483 | 2018-10-01 13:44:56 +0300 | [diff] [blame] | 3775 | key->extract.from_hdr.prot = dist_fields[i].cls_prot; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3776 | key->extract.from_hdr.type = DPKG_FULL_FIELD; |
Ioana Radulescu | f76c483 | 2018-10-01 13:44:56 +0300 | [diff] [blame] | 3777 | key->extract.from_hdr.field = dist_fields[i].cls_field; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3778 | cls_cfg.num_extracts++; |
| 3779 | } |
| 3780 | |
Ioana Radulescu | e40ef9e | 2017-06-06 10:00:30 -0500 | [diff] [blame] | 3781 | dma_mem = kzalloc(DPAA2_CLASSIFIER_DMA_SIZE, GFP_KERNEL); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3782 | if (!dma_mem) |
| 3783 | return -ENOMEM; |
| 3784 | |
| 3785 | err = dpni_prepare_key_cfg(&cls_cfg, dma_mem); |
| 3786 | if (err) { |
Ioana Radulescu | 77160af | 2017-06-06 10:00:28 -0500 | [diff] [blame] | 3787 | dev_err(dev, "dpni_prepare_key_cfg error %d\n", err); |
Ioana Radulescu | df85aeb | 2018-10-01 13:44:55 +0300 | [diff] [blame] | 3788 | goto free_key; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3789 | } |
| 3790 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3791 | /* Prepare for setting the rx dist */ |
Ioana Radulescu | df85aeb | 2018-10-01 13:44:55 +0300 | [diff] [blame] | 3792 | key_iova = dma_map_single(dev, dma_mem, DPAA2_CLASSIFIER_DMA_SIZE, |
| 3793 | DMA_TO_DEVICE); |
| 3794 | if (dma_mapping_error(dev, key_iova)) { |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3795 | dev_err(dev, "DMA mapping failed\n"); |
| 3796 | err = -ENOMEM; |
Ioana Radulescu | df85aeb | 2018-10-01 13:44:55 +0300 | [diff] [blame] | 3797 | goto free_key; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3798 | } |
| 3799 | |
Ioana Radulescu | 4aaaf9b | 2018-10-01 13:44:57 +0300 | [diff] [blame] | 3800 | if (type == DPAA2_ETH_RX_DIST_HASH) { |
| 3801 | if (dpaa2_eth_has_legacy_dist(priv)) |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 3802 | err = dpaa2_eth_config_legacy_hash_key(priv, key_iova); |
Ioana Radulescu | 4aaaf9b | 2018-10-01 13:44:57 +0300 | [diff] [blame] | 3803 | else |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 3804 | err = dpaa2_eth_config_hash_key(priv, key_iova); |
Ioana Radulescu | 4aaaf9b | 2018-10-01 13:44:57 +0300 | [diff] [blame] | 3805 | } else { |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 3806 | err = dpaa2_eth_config_cls_key(priv, key_iova); |
Ioana Radulescu | 4aaaf9b | 2018-10-01 13:44:57 +0300 | [diff] [blame] | 3807 | } |
Ioana Radulescu | df85aeb | 2018-10-01 13:44:55 +0300 | [diff] [blame] | 3808 | |
| 3809 | dma_unmap_single(dev, key_iova, DPAA2_CLASSIFIER_DMA_SIZE, |
| 3810 | DMA_TO_DEVICE); |
Ioana Radulescu | 4aaaf9b | 2018-10-01 13:44:57 +0300 | [diff] [blame] | 3811 | if (!err && type == DPAA2_ETH_RX_DIST_HASH) |
Ioana Ciocoi Radulescu | edad8d2 | 2018-09-24 15:36:21 +0000 | [diff] [blame] | 3812 | priv->rx_hash_fields = rx_hash_fields; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3813 | |
Ioana Radulescu | df85aeb | 2018-10-01 13:44:55 +0300 | [diff] [blame] | 3814 | free_key: |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3815 | kfree(dma_mem); |
| 3816 | return err; |
| 3817 | } |
| 3818 | |
Ioana Radulescu | 4aaaf9b | 2018-10-01 13:44:57 +0300 | [diff] [blame] | 3819 | int dpaa2_eth_set_hash(struct net_device *net_dev, u64 flags) |
| 3820 | { |
| 3821 | struct dpaa2_eth_priv *priv = netdev_priv(net_dev); |
Ioana Ciocoi Radulescu | 3a1e6b8 | 2019-04-16 17:13:29 +0000 | [diff] [blame] | 3822 | u64 key = 0; |
| 3823 | int i; |
Ioana Radulescu | 4aaaf9b | 2018-10-01 13:44:57 +0300 | [diff] [blame] | 3824 | |
| 3825 | if (!dpaa2_eth_hash_enabled(priv)) |
| 3826 | return -EOPNOTSUPP; |
| 3827 | |
Ioana Ciocoi Radulescu | 3a1e6b8 | 2019-04-16 17:13:29 +0000 | [diff] [blame] | 3828 | for (i = 0; i < ARRAY_SIZE(dist_fields); i++) |
| 3829 | if (dist_fields[i].rxnfc_field & flags) |
| 3830 | key |= dist_fields[i].id; |
| 3831 | |
| 3832 | return dpaa2_eth_set_dist_key(net_dev, DPAA2_ETH_RX_DIST_HASH, key); |
Ioana Radulescu | 4aaaf9b | 2018-10-01 13:44:57 +0300 | [diff] [blame] | 3833 | } |
| 3834 | |
Ioana Ciocoi Radulescu | 2d68023 | 2019-04-16 17:13:30 +0000 | [diff] [blame] | 3835 | int dpaa2_eth_set_cls(struct net_device *net_dev, u64 flags) |
| 3836 | { |
| 3837 | return dpaa2_eth_set_dist_key(net_dev, DPAA2_ETH_RX_DIST_CLS, flags); |
| 3838 | } |
| 3839 | |
| 3840 | static int dpaa2_eth_set_default_cls(struct dpaa2_eth_priv *priv) |
Ioana Radulescu | 4aaaf9b | 2018-10-01 13:44:57 +0300 | [diff] [blame] | 3841 | { |
| 3842 | struct device *dev = priv->net_dev->dev.parent; |
Ioana Ciocoi Radulescu | df8e249 | 2019-04-16 17:13:28 +0000 | [diff] [blame] | 3843 | int err; |
Ioana Radulescu | 4aaaf9b | 2018-10-01 13:44:57 +0300 | [diff] [blame] | 3844 | |
| 3845 | /* Check if we actually support Rx flow classification */ |
| 3846 | if (dpaa2_eth_has_legacy_dist(priv)) { |
| 3847 | dev_dbg(dev, "Rx cls not supported by current MC version\n"); |
| 3848 | return -EOPNOTSUPP; |
| 3849 | } |
| 3850 | |
Ioana Ciocoi Radulescu | 2d68023 | 2019-04-16 17:13:30 +0000 | [diff] [blame] | 3851 | if (!dpaa2_eth_fs_enabled(priv)) { |
Ioana Radulescu | 4aaaf9b | 2018-10-01 13:44:57 +0300 | [diff] [blame] | 3852 | dev_dbg(dev, "Rx cls disabled in DPNI options\n"); |
| 3853 | return -EOPNOTSUPP; |
| 3854 | } |
| 3855 | |
| 3856 | if (!dpaa2_eth_hash_enabled(priv)) { |
| 3857 | dev_dbg(dev, "Rx cls disabled for single queue DPNIs\n"); |
| 3858 | return -EOPNOTSUPP; |
| 3859 | } |
| 3860 | |
Ioana Ciocoi Radulescu | 2d68023 | 2019-04-16 17:13:30 +0000 | [diff] [blame] | 3861 | /* If there is no support for masking in the classification table, |
| 3862 | * we don't set a default key, as it will depend on the rules |
| 3863 | * added by the user at runtime. |
| 3864 | */ |
| 3865 | if (!dpaa2_eth_fs_mask_enabled(priv)) |
| 3866 | goto out; |
| 3867 | |
| 3868 | err = dpaa2_eth_set_cls(priv->net_dev, DPAA2_ETH_DIST_ALL); |
Ioana Ciocoi Radulescu | df8e249 | 2019-04-16 17:13:28 +0000 | [diff] [blame] | 3869 | if (err) |
| 3870 | return err; |
| 3871 | |
Ioana Ciocoi Radulescu | 2d68023 | 2019-04-16 17:13:30 +0000 | [diff] [blame] | 3872 | out: |
Ioana Radulescu | 4aaaf9b | 2018-10-01 13:44:57 +0300 | [diff] [blame] | 3873 | priv->rx_cls_enabled = 1; |
| 3874 | |
Ioana Ciocoi Radulescu | df8e249 | 2019-04-16 17:13:28 +0000 | [diff] [blame] | 3875 | return 0; |
Ioana Radulescu | 4aaaf9b | 2018-10-01 13:44:57 +0300 | [diff] [blame] | 3876 | } |
| 3877 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3878 | /* Bind the DPNI to its needed objects and resources: buffer pool, DPIOs, |
| 3879 | * frame queues and channels |
| 3880 | */ |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 3881 | static int dpaa2_eth_bind_dpni(struct dpaa2_eth_priv *priv) |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3882 | { |
| 3883 | struct net_device *net_dev = priv->net_dev; |
| 3884 | struct device *dev = net_dev->dev.parent; |
| 3885 | struct dpni_pools_cfg pools_params; |
| 3886 | struct dpni_error_cfg err_cfg; |
| 3887 | int err = 0; |
| 3888 | int i; |
| 3889 | |
| 3890 | pools_params.num_dpbp = 1; |
| 3891 | pools_params.pools[0].dpbp_id = priv->dpbp_dev->obj_desc.id; |
| 3892 | pools_params.pools[0].backup_pool = 0; |
Ioana Ciornei | efa6a7d | 2020-05-15 15:30:22 +0300 | [diff] [blame] | 3893 | pools_params.pools[0].buffer_size = priv->rx_buf_size; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3894 | err = dpni_set_pools(priv->mc_io, 0, priv->mc_token, &pools_params); |
| 3895 | if (err) { |
| 3896 | dev_err(dev, "dpni_set_pools() failed\n"); |
| 3897 | return err; |
| 3898 | } |
| 3899 | |
Ioana Radulescu | 227686b | 2018-07-27 09:12:59 -0500 | [diff] [blame] | 3900 | /* have the interface implicitly distribute traffic based on |
| 3901 | * the default hash key |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3902 | */ |
Ioana Radulescu | 227686b | 2018-07-27 09:12:59 -0500 | [diff] [blame] | 3903 | err = dpaa2_eth_set_hash(net_dev, DPAA2_RXH_DEFAULT); |
Ioana Ciocoi Radulescu | edad8d2 | 2018-09-24 15:36:21 +0000 | [diff] [blame] | 3904 | if (err && err != -EOPNOTSUPP) |
Ioana Radulescu | 0f4c295 | 2017-10-11 08:29:50 -0500 | [diff] [blame] | 3905 | dev_err(dev, "Failed to configure hashing\n"); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3906 | |
Ioana Radulescu | 4aaaf9b | 2018-10-01 13:44:57 +0300 | [diff] [blame] | 3907 | /* Configure the flow classification key; it includes all |
| 3908 | * supported header fields and cannot be modified at runtime |
| 3909 | */ |
Ioana Ciocoi Radulescu | 2d68023 | 2019-04-16 17:13:30 +0000 | [diff] [blame] | 3910 | err = dpaa2_eth_set_default_cls(priv); |
Ioana Radulescu | 4aaaf9b | 2018-10-01 13:44:57 +0300 | [diff] [blame] | 3911 | if (err && err != -EOPNOTSUPP) |
| 3912 | dev_err(dev, "Failed to configure Rx classification key\n"); |
| 3913 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3914 | /* Configure handling of error frames */ |
Ioana Radulescu | 39163c0 | 2017-06-06 10:00:39 -0500 | [diff] [blame] | 3915 | err_cfg.errors = DPAA2_FAS_RX_ERR_MASK; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3916 | err_cfg.set_frame_annotation = 1; |
| 3917 | err_cfg.error_action = DPNI_ERROR_ACTION_DISCARD; |
| 3918 | err = dpni_set_errors_behavior(priv->mc_io, 0, priv->mc_token, |
| 3919 | &err_cfg); |
| 3920 | if (err) { |
| 3921 | dev_err(dev, "dpni_set_errors_behavior failed\n"); |
| 3922 | return err; |
| 3923 | } |
| 3924 | |
| 3925 | /* Configure Rx and Tx conf queues to generate CDANs */ |
| 3926 | for (i = 0; i < priv->num_fqs; i++) { |
| 3927 | switch (priv->fq[i].type) { |
| 3928 | case DPAA2_RX_FQ: |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 3929 | err = dpaa2_eth_setup_rx_flow(priv, &priv->fq[i]); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3930 | break; |
| 3931 | case DPAA2_TX_CONF_FQ: |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 3932 | err = dpaa2_eth_setup_tx_flow(priv, &priv->fq[i]); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3933 | break; |
Ioana Ciornei | 061d631 | 2020-10-01 18:11:48 +0300 | [diff] [blame] | 3934 | case DPAA2_RX_ERR_FQ: |
| 3935 | err = setup_rx_err_flow(priv, &priv->fq[i]); |
| 3936 | break; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3937 | default: |
| 3938 | dev_err(dev, "Invalid FQ type %d\n", priv->fq[i].type); |
| 3939 | return -EINVAL; |
| 3940 | } |
| 3941 | if (err) |
| 3942 | return err; |
| 3943 | } |
| 3944 | |
| 3945 | err = dpni_get_qdid(priv->mc_io, 0, priv->mc_token, |
| 3946 | DPNI_QUEUE_TX, &priv->tx_qdid); |
| 3947 | if (err) { |
| 3948 | dev_err(dev, "dpni_get_qdid() failed\n"); |
| 3949 | return err; |
| 3950 | } |
| 3951 | |
| 3952 | return 0; |
| 3953 | } |
| 3954 | |
| 3955 | /* Allocate rings for storing incoming frame descriptors */ |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 3956 | static int dpaa2_eth_alloc_rings(struct dpaa2_eth_priv *priv) |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3957 | { |
| 3958 | struct net_device *net_dev = priv->net_dev; |
| 3959 | struct device *dev = net_dev->dev.parent; |
| 3960 | int i; |
| 3961 | |
| 3962 | for (i = 0; i < priv->num_channels; i++) { |
| 3963 | priv->channel[i]->store = |
| 3964 | dpaa2_io_store_create(DPAA2_ETH_STORE_SIZE, dev); |
| 3965 | if (!priv->channel[i]->store) { |
| 3966 | netdev_err(net_dev, "dpaa2_io_store_create() failed\n"); |
| 3967 | goto err_ring; |
| 3968 | } |
| 3969 | } |
| 3970 | |
| 3971 | return 0; |
| 3972 | |
| 3973 | err_ring: |
| 3974 | for (i = 0; i < priv->num_channels; i++) { |
| 3975 | if (!priv->channel[i]->store) |
| 3976 | break; |
| 3977 | dpaa2_io_store_destroy(priv->channel[i]->store); |
| 3978 | } |
| 3979 | |
| 3980 | return -ENOMEM; |
| 3981 | } |
| 3982 | |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 3983 | static void dpaa2_eth_free_rings(struct dpaa2_eth_priv *priv) |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3984 | { |
| 3985 | int i; |
| 3986 | |
| 3987 | for (i = 0; i < priv->num_channels; i++) |
| 3988 | dpaa2_io_store_destroy(priv->channel[i]->store); |
| 3989 | } |
| 3990 | |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 3991 | static int dpaa2_eth_set_mac_addr(struct dpaa2_eth_priv *priv) |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3992 | { |
Ioana Radulescu | 6ab0086 | 2017-06-06 10:00:40 -0500 | [diff] [blame] | 3993 | struct net_device *net_dev = priv->net_dev; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3994 | struct device *dev = net_dev->dev.parent; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3995 | u8 mac_addr[ETH_ALEN], dpni_mac_addr[ETH_ALEN]; |
Ioana Radulescu | 6ab0086 | 2017-06-06 10:00:40 -0500 | [diff] [blame] | 3996 | int err; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3997 | |
| 3998 | /* Get firmware address, if any */ |
| 3999 | err = dpni_get_port_mac_addr(priv->mc_io, 0, priv->mc_token, mac_addr); |
| 4000 | if (err) { |
| 4001 | dev_err(dev, "dpni_get_port_mac_addr() failed\n"); |
| 4002 | return err; |
| 4003 | } |
| 4004 | |
| 4005 | /* Get DPNI attributes address, if any */ |
| 4006 | err = dpni_get_primary_mac_addr(priv->mc_io, 0, priv->mc_token, |
| 4007 | dpni_mac_addr); |
| 4008 | if (err) { |
Ioana Radulescu | 6ab0086 | 2017-06-06 10:00:40 -0500 | [diff] [blame] | 4009 | dev_err(dev, "dpni_get_primary_mac_addr() failed\n"); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 4010 | return err; |
| 4011 | } |
| 4012 | |
| 4013 | /* First check if firmware has any address configured by bootloader */ |
| 4014 | if (!is_zero_ether_addr(mac_addr)) { |
| 4015 | /* If the DPMAC addr != DPNI addr, update it */ |
| 4016 | if (!ether_addr_equal(mac_addr, dpni_mac_addr)) { |
| 4017 | err = dpni_set_primary_mac_addr(priv->mc_io, 0, |
| 4018 | priv->mc_token, |
| 4019 | mac_addr); |
| 4020 | if (err) { |
| 4021 | dev_err(dev, "dpni_set_primary_mac_addr() failed\n"); |
| 4022 | return err; |
| 4023 | } |
| 4024 | } |
Jakub Kicinski | a05e4c0 | 2021-10-04 09:05:21 -0700 | [diff] [blame] | 4025 | eth_hw_addr_set(net_dev, mac_addr); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 4026 | } else if (is_zero_ether_addr(dpni_mac_addr)) { |
Ioana Radulescu | 6ab0086 | 2017-06-06 10:00:40 -0500 | [diff] [blame] | 4027 | /* No MAC address configured, fill in net_dev->dev_addr |
| 4028 | * with a random one |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 4029 | */ |
| 4030 | eth_hw_addr_random(net_dev); |
Ioana Radulescu | 6ab0086 | 2017-06-06 10:00:40 -0500 | [diff] [blame] | 4031 | dev_dbg_once(dev, "device(s) have all-zero hwaddr, replaced with random\n"); |
| 4032 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 4033 | err = dpni_set_primary_mac_addr(priv->mc_io, 0, priv->mc_token, |
| 4034 | net_dev->dev_addr); |
| 4035 | if (err) { |
Ioana Radulescu | 6ab0086 | 2017-06-06 10:00:40 -0500 | [diff] [blame] | 4036 | dev_err(dev, "dpni_set_primary_mac_addr() failed\n"); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 4037 | return err; |
| 4038 | } |
Ioana Radulescu | 6ab0086 | 2017-06-06 10:00:40 -0500 | [diff] [blame] | 4039 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 4040 | /* Override NET_ADDR_RANDOM set by eth_hw_addr_random(); for all |
| 4041 | * practical purposes, this will be our "permanent" mac address, |
| 4042 | * at least until the next reboot. This move will also permit |
| 4043 | * register_netdevice() to properly fill up net_dev->perm_addr. |
| 4044 | */ |
| 4045 | net_dev->addr_assign_type = NET_ADDR_PERM; |
| 4046 | } else { |
| 4047 | /* NET_ADDR_PERM is default, all we have to do is |
| 4048 | * fill in the device addr. |
| 4049 | */ |
Jakub Kicinski | a05e4c0 | 2021-10-04 09:05:21 -0700 | [diff] [blame] | 4050 | eth_hw_addr_set(net_dev, dpni_mac_addr); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 4051 | } |
| 4052 | |
Ioana Radulescu | 6ab0086 | 2017-06-06 10:00:40 -0500 | [diff] [blame] | 4053 | return 0; |
| 4054 | } |
| 4055 | |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 4056 | static int dpaa2_eth_netdev_init(struct net_device *net_dev) |
Ioana Radulescu | 6ab0086 | 2017-06-06 10:00:40 -0500 | [diff] [blame] | 4057 | { |
| 4058 | struct device *dev = net_dev->dev.parent; |
| 4059 | struct dpaa2_eth_priv *priv = netdev_priv(net_dev); |
Ioana Radulescu | 7f12c8a3 | 2018-08-29 04:42:39 -0500 | [diff] [blame] | 4060 | u32 options = priv->dpni_attrs.options; |
| 4061 | u64 supported = 0, not_supported = 0; |
Ioana Radulescu | 6ab0086 | 2017-06-06 10:00:40 -0500 | [diff] [blame] | 4062 | u8 bcast_addr[ETH_ALEN]; |
Ioana Radulescu | bb5b42c | 2017-06-06 10:00:41 -0500 | [diff] [blame] | 4063 | u8 num_queues; |
Ioana Radulescu | 6ab0086 | 2017-06-06 10:00:40 -0500 | [diff] [blame] | 4064 | int err; |
| 4065 | |
| 4066 | net_dev->netdev_ops = &dpaa2_eth_ops; |
Ioana Radulescu | 7f12c8a3 | 2018-08-29 04:42:39 -0500 | [diff] [blame] | 4067 | net_dev->ethtool_ops = &dpaa2_ethtool_ops; |
Ioana Radulescu | 6ab0086 | 2017-06-06 10:00:40 -0500 | [diff] [blame] | 4068 | |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 4069 | err = dpaa2_eth_set_mac_addr(priv); |
Ioana Radulescu | 6ab0086 | 2017-06-06 10:00:40 -0500 | [diff] [blame] | 4070 | if (err) |
| 4071 | return err; |
| 4072 | |
| 4073 | /* Explicitly add the broadcast address to the MAC filtering table */ |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 4074 | eth_broadcast_addr(bcast_addr); |
| 4075 | err = dpni_add_mac_addr(priv->mc_io, 0, priv->mc_token, bcast_addr); |
| 4076 | if (err) { |
Ioana Radulescu | 6ab0086 | 2017-06-06 10:00:40 -0500 | [diff] [blame] | 4077 | dev_err(dev, "dpni_add_mac_addr() failed\n"); |
| 4078 | return err; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 4079 | } |
| 4080 | |
Ioana Radulescu | 3ccc8d4 | 2018-07-09 10:01:10 -0500 | [diff] [blame] | 4081 | /* Set MTU upper limit; lower limit is 68B (default value) */ |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 4082 | net_dev->max_mtu = DPAA2_ETH_MAX_MTU; |
Ioana Radulescu | 00fee00 | 2018-07-09 10:01:11 -0500 | [diff] [blame] | 4083 | err = dpni_set_max_frame_length(priv->mc_io, 0, priv->mc_token, |
Ioana Radulescu | 81f34e9 | 2018-07-12 12:12:29 -0500 | [diff] [blame] | 4084 | DPAA2_ETH_MFL); |
Ioana Radulescu | 00fee00 | 2018-07-09 10:01:11 -0500 | [diff] [blame] | 4085 | if (err) { |
| 4086 | dev_err(dev, "dpni_set_max_frame_length() failed\n"); |
| 4087 | return err; |
| 4088 | } |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 4089 | |
Ioana Radulescu | bb5b42c | 2017-06-06 10:00:41 -0500 | [diff] [blame] | 4090 | /* Set actual number of queues in the net device */ |
| 4091 | num_queues = dpaa2_eth_queue_count(priv); |
| 4092 | err = netif_set_real_num_tx_queues(net_dev, num_queues); |
| 4093 | if (err) { |
| 4094 | dev_err(dev, "netif_set_real_num_tx_queues() failed\n"); |
| 4095 | return err; |
| 4096 | } |
| 4097 | err = netif_set_real_num_rx_queues(net_dev, num_queues); |
| 4098 | if (err) { |
| 4099 | dev_err(dev, "netif_set_real_num_rx_queues() failed\n"); |
| 4100 | return err; |
| 4101 | } |
| 4102 | |
Ioana Radulescu | 7f12c8a3 | 2018-08-29 04:42:39 -0500 | [diff] [blame] | 4103 | /* Capabilities listing */ |
| 4104 | supported |= IFF_LIVE_ADDR_CHANGE; |
| 4105 | |
| 4106 | if (options & DPNI_OPT_NO_MAC_FILTER) |
| 4107 | not_supported |= IFF_UNICAST_FLT; |
| 4108 | else |
| 4109 | supported |= IFF_UNICAST_FLT; |
| 4110 | |
| 4111 | net_dev->priv_flags |= supported; |
| 4112 | net_dev->priv_flags &= ~not_supported; |
| 4113 | |
| 4114 | /* Features */ |
| 4115 | net_dev->features = NETIF_F_RXCSUM | |
| 4116 | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | |
| 4117 | NETIF_F_SG | NETIF_F_HIGHDMA | |
Ioana Ciornei | 3657cda | 2020-07-21 19:38:25 +0300 | [diff] [blame] | 4118 | NETIF_F_LLTX | NETIF_F_HW_TC; |
Ioana Radulescu | 7f12c8a3 | 2018-08-29 04:42:39 -0500 | [diff] [blame] | 4119 | net_dev->hw_features = net_dev->features; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 4120 | |
Ionut-robert Aron | 70b32d8 | 2021-01-11 19:07:25 +0200 | [diff] [blame] | 4121 | if (priv->dpni_attrs.vlan_filter_entries) |
| 4122 | net_dev->hw_features |= NETIF_F_HW_VLAN_CTAG_FILTER; |
| 4123 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 4124 | return 0; |
| 4125 | } |
| 4126 | |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 4127 | static int dpaa2_eth_poll_link_state(void *arg) |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 4128 | { |
| 4129 | struct dpaa2_eth_priv *priv = (struct dpaa2_eth_priv *)arg; |
| 4130 | int err; |
| 4131 | |
| 4132 | while (!kthread_should_stop()) { |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 4133 | err = dpaa2_eth_link_state_update(priv); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 4134 | if (unlikely(err)) |
| 4135 | return err; |
| 4136 | |
| 4137 | msleep(DPAA2_ETH_LINK_STATE_REFRESH); |
| 4138 | } |
| 4139 | |
| 4140 | return 0; |
| 4141 | } |
| 4142 | |
Ioana Ciornei | 7194792 | 2019-10-31 01:18:31 +0200 | [diff] [blame] | 4143 | static int dpaa2_eth_connect_mac(struct dpaa2_eth_priv *priv) |
| 4144 | { |
| 4145 | struct fsl_mc_device *dpni_dev, *dpmac_dev; |
| 4146 | struct dpaa2_mac *mac; |
| 4147 | int err; |
| 4148 | |
| 4149 | dpni_dev = to_fsl_mc_device(priv->net_dev->dev.parent); |
Ioana Ciornei | 27cfdad | 2021-08-03 19:57:42 +0300 | [diff] [blame] | 4150 | dpmac_dev = fsl_mc_get_endpoint(dpni_dev, 0); |
Ioana Ciornei | 47325da | 2021-01-08 11:07:25 +0200 | [diff] [blame] | 4151 | |
| 4152 | if (PTR_ERR(dpmac_dev) == -EPROBE_DEFER) |
| 4153 | return PTR_ERR(dpmac_dev); |
| 4154 | |
| 4155 | if (IS_ERR(dpmac_dev) || dpmac_dev->dev.type != &fsl_mc_bus_dpmac_type) |
Ioana Ciornei | 7194792 | 2019-10-31 01:18:31 +0200 | [diff] [blame] | 4156 | return 0; |
| 4157 | |
Ioana Ciornei | 7194792 | 2019-10-31 01:18:31 +0200 | [diff] [blame] | 4158 | mac = kzalloc(sizeof(struct dpaa2_mac), GFP_KERNEL); |
| 4159 | if (!mac) |
| 4160 | return -ENOMEM; |
| 4161 | |
| 4162 | mac->mc_dev = dpmac_dev; |
| 4163 | mac->mc_io = priv->mc_io; |
| 4164 | mac->net_dev = priv->net_dev; |
| 4165 | |
Ioana Ciornei | 095dca1 | 2021-01-08 11:07:22 +0200 | [diff] [blame] | 4166 | err = dpaa2_mac_open(mac); |
| 4167 | if (err) |
| 4168 | goto err_free_mac; |
Ioana Ciornei | 7194792 | 2019-10-31 01:18:31 +0200 | [diff] [blame] | 4169 | priv->mac = mac; |
| 4170 | |
Ioana Ciornei | d87e606 | 2021-01-08 11:07:23 +0200 | [diff] [blame] | 4171 | if (dpaa2_eth_is_type_phy(priv)) { |
| 4172 | err = dpaa2_mac_connect(mac); |
Vladimir Oltean | f5120f5 | 2021-05-21 17:12:20 +0300 | [diff] [blame] | 4173 | if (err && err != -EPROBE_DEFER) |
| 4174 | netdev_err(priv->net_dev, "Error connecting to the MAC endpoint: %pe", |
| 4175 | ERR_PTR(err)); |
| 4176 | if (err) |
Ioana Ciornei | d87e606 | 2021-01-08 11:07:23 +0200 | [diff] [blame] | 4177 | goto err_close_mac; |
Ioana Ciornei | d87e606 | 2021-01-08 11:07:23 +0200 | [diff] [blame] | 4178 | } |
| 4179 | |
Ioana Ciornei | 7194792 | 2019-10-31 01:18:31 +0200 | [diff] [blame] | 4180 | return 0; |
Ioana Ciornei | 095dca1 | 2021-01-08 11:07:22 +0200 | [diff] [blame] | 4181 | |
| 4182 | err_close_mac: |
| 4183 | dpaa2_mac_close(mac); |
Ioana Ciornei | d87e606 | 2021-01-08 11:07:23 +0200 | [diff] [blame] | 4184 | priv->mac = NULL; |
Ioana Ciornei | 095dca1 | 2021-01-08 11:07:22 +0200 | [diff] [blame] | 4185 | err_free_mac: |
| 4186 | kfree(mac); |
| 4187 | return err; |
Ioana Ciornei | 7194792 | 2019-10-31 01:18:31 +0200 | [diff] [blame] | 4188 | } |
| 4189 | |
| 4190 | static void dpaa2_eth_disconnect_mac(struct dpaa2_eth_priv *priv) |
| 4191 | { |
Ioana Ciornei | d87e606 | 2021-01-08 11:07:23 +0200 | [diff] [blame] | 4192 | if (dpaa2_eth_is_type_phy(priv)) |
| 4193 | dpaa2_mac_disconnect(priv->mac); |
Ioana Ciornei | 7194792 | 2019-10-31 01:18:31 +0200 | [diff] [blame] | 4194 | |
Ioana Ciornei | 848c190 | 2021-01-11 19:18:02 +0200 | [diff] [blame] | 4195 | if (!dpaa2_eth_has_mac(priv)) |
| 4196 | return; |
| 4197 | |
Ioana Ciornei | 095dca1 | 2021-01-08 11:07:22 +0200 | [diff] [blame] | 4198 | dpaa2_mac_close(priv->mac); |
Ioana Ciornei | 7194792 | 2019-10-31 01:18:31 +0200 | [diff] [blame] | 4199 | kfree(priv->mac); |
| 4200 | priv->mac = NULL; |
| 4201 | } |
| 4202 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 4203 | static irqreturn_t dpni_irq0_handler_thread(int irq_num, void *arg) |
| 4204 | { |
Ioana Radulescu | 112197d | 2017-10-11 08:29:49 -0500 | [diff] [blame] | 4205 | u32 status = ~0; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 4206 | struct device *dev = (struct device *)arg; |
| 4207 | struct fsl_mc_device *dpni_dev = to_fsl_mc_device(dev); |
| 4208 | struct net_device *net_dev = dev_get_drvdata(dev); |
Ioana Ciornei | 7194792 | 2019-10-31 01:18:31 +0200 | [diff] [blame] | 4209 | struct dpaa2_eth_priv *priv = netdev_priv(net_dev); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 4210 | int err; |
| 4211 | |
| 4212 | err = dpni_get_irq_status(dpni_dev->mc_io, 0, dpni_dev->mc_handle, |
| 4213 | DPNI_IRQ_INDEX, &status); |
| 4214 | if (unlikely(err)) { |
Ioana Radulescu | 77160af | 2017-06-06 10:00:28 -0500 | [diff] [blame] | 4215 | netdev_err(net_dev, "Can't get irq status (err %d)\n", err); |
Ioana Radulescu | 112197d | 2017-10-11 08:29:49 -0500 | [diff] [blame] | 4216 | return IRQ_HANDLED; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 4217 | } |
| 4218 | |
Ioana Radulescu | 112197d | 2017-10-11 08:29:49 -0500 | [diff] [blame] | 4219 | if (status & DPNI_IRQ_EVENT_LINK_CHANGED) |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 4220 | dpaa2_eth_link_state_update(netdev_priv(net_dev)); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 4221 | |
Ioana Ciornei | f5c3fff | 2019-10-31 01:18:30 +0200 | [diff] [blame] | 4222 | if (status & DPNI_IRQ_EVENT_ENDPOINT_CHANGED) { |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 4223 | dpaa2_eth_set_mac_addr(netdev_priv(net_dev)); |
| 4224 | dpaa2_eth_update_tx_fqids(priv); |
Ioana Ciornei | 7194792 | 2019-10-31 01:18:31 +0200 | [diff] [blame] | 4225 | |
| 4226 | rtnl_lock(); |
Ioana Ciornei | d87e606 | 2021-01-08 11:07:23 +0200 | [diff] [blame] | 4227 | if (dpaa2_eth_has_mac(priv)) |
Ioana Ciornei | 7194792 | 2019-10-31 01:18:31 +0200 | [diff] [blame] | 4228 | dpaa2_eth_disconnect_mac(priv); |
| 4229 | else |
| 4230 | dpaa2_eth_connect_mac(priv); |
| 4231 | rtnl_unlock(); |
Ioana Ciornei | f5c3fff | 2019-10-31 01:18:30 +0200 | [diff] [blame] | 4232 | } |
Florin Chiculita | 8398b37 | 2019-10-16 10:36:22 +0300 | [diff] [blame] | 4233 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 4234 | return IRQ_HANDLED; |
| 4235 | } |
| 4236 | |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 4237 | static int dpaa2_eth_setup_irqs(struct fsl_mc_device *ls_dev) |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 4238 | { |
| 4239 | int err = 0; |
| 4240 | struct fsl_mc_device_irq *irq; |
| 4241 | |
| 4242 | err = fsl_mc_allocate_irqs(ls_dev); |
| 4243 | if (err) { |
| 4244 | dev_err(&ls_dev->dev, "MC irqs allocation failed\n"); |
| 4245 | return err; |
| 4246 | } |
| 4247 | |
| 4248 | irq = ls_dev->irqs[0]; |
Thomas Gleixner | d86a6d4 | 2021-12-10 23:19:34 +0100 | [diff] [blame] | 4249 | err = devm_request_threaded_irq(&ls_dev->dev, irq->virq, |
Ioana Radulescu | fdc9b53 | 2018-03-23 08:44:05 -0500 | [diff] [blame] | 4250 | NULL, dpni_irq0_handler_thread, |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 4251 | IRQF_NO_SUSPEND | IRQF_ONESHOT, |
| 4252 | dev_name(&ls_dev->dev), &ls_dev->dev); |
| 4253 | if (err < 0) { |
Ioana Radulescu | 77160af | 2017-06-06 10:00:28 -0500 | [diff] [blame] | 4254 | dev_err(&ls_dev->dev, "devm_request_threaded_irq(): %d\n", err); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 4255 | goto free_mc_irq; |
| 4256 | } |
| 4257 | |
| 4258 | err = dpni_set_irq_mask(ls_dev->mc_io, 0, ls_dev->mc_handle, |
Florin Chiculita | 8398b37 | 2019-10-16 10:36:22 +0300 | [diff] [blame] | 4259 | DPNI_IRQ_INDEX, DPNI_IRQ_EVENT_LINK_CHANGED | |
| 4260 | DPNI_IRQ_EVENT_ENDPOINT_CHANGED); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 4261 | if (err < 0) { |
Ioana Radulescu | 77160af | 2017-06-06 10:00:28 -0500 | [diff] [blame] | 4262 | dev_err(&ls_dev->dev, "dpni_set_irq_mask(): %d\n", err); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 4263 | goto free_irq; |
| 4264 | } |
| 4265 | |
| 4266 | err = dpni_set_irq_enable(ls_dev->mc_io, 0, ls_dev->mc_handle, |
| 4267 | DPNI_IRQ_INDEX, 1); |
| 4268 | if (err < 0) { |
Ioana Radulescu | 77160af | 2017-06-06 10:00:28 -0500 | [diff] [blame] | 4269 | dev_err(&ls_dev->dev, "dpni_set_irq_enable(): %d\n", err); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 4270 | goto free_irq; |
| 4271 | } |
| 4272 | |
| 4273 | return 0; |
| 4274 | |
| 4275 | free_irq: |
Thomas Gleixner | d86a6d4 | 2021-12-10 23:19:34 +0100 | [diff] [blame] | 4276 | devm_free_irq(&ls_dev->dev, irq->virq, &ls_dev->dev); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 4277 | free_mc_irq: |
| 4278 | fsl_mc_free_irqs(ls_dev); |
| 4279 | |
| 4280 | return err; |
| 4281 | } |
| 4282 | |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 4283 | static void dpaa2_eth_add_ch_napi(struct dpaa2_eth_priv *priv) |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 4284 | { |
| 4285 | int i; |
| 4286 | struct dpaa2_eth_channel *ch; |
| 4287 | |
| 4288 | for (i = 0; i < priv->num_channels; i++) { |
| 4289 | ch = priv->channel[i]; |
| 4290 | /* NAPI weight *MUST* be a multiple of DPAA2_ETH_STORE_SIZE */ |
| 4291 | netif_napi_add(priv->net_dev, &ch->napi, dpaa2_eth_poll, |
| 4292 | NAPI_POLL_WEIGHT); |
| 4293 | } |
| 4294 | } |
| 4295 | |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 4296 | static void dpaa2_eth_del_ch_napi(struct dpaa2_eth_priv *priv) |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 4297 | { |
| 4298 | int i; |
| 4299 | struct dpaa2_eth_channel *ch; |
| 4300 | |
| 4301 | for (i = 0; i < priv->num_channels; i++) { |
| 4302 | ch = priv->channel[i]; |
| 4303 | netif_napi_del(&ch->napi); |
| 4304 | } |
| 4305 | } |
| 4306 | |
| 4307 | static int dpaa2_eth_probe(struct fsl_mc_device *dpni_dev) |
| 4308 | { |
| 4309 | struct device *dev; |
| 4310 | struct net_device *net_dev = NULL; |
| 4311 | struct dpaa2_eth_priv *priv = NULL; |
| 4312 | int err = 0; |
| 4313 | |
| 4314 | dev = &dpni_dev->dev; |
| 4315 | |
| 4316 | /* Net device */ |
Ioana Radulescu | ab1e6de | 2019-06-11 14:50:03 +0300 | [diff] [blame] | 4317 | net_dev = alloc_etherdev_mq(sizeof(*priv), DPAA2_ETH_MAX_NETDEV_QUEUES); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 4318 | if (!net_dev) { |
| 4319 | dev_err(dev, "alloc_etherdev_mq() failed\n"); |
| 4320 | return -ENOMEM; |
| 4321 | } |
| 4322 | |
| 4323 | SET_NETDEV_DEV(net_dev, dev); |
| 4324 | dev_set_drvdata(dev, net_dev); |
| 4325 | |
| 4326 | priv = netdev_priv(net_dev); |
| 4327 | priv->net_dev = net_dev; |
| 4328 | |
Ioana Radulescu | 08eb239 | 2017-05-24 07:13:27 -0500 | [diff] [blame] | 4329 | priv->iommu_domain = iommu_get_domain_for_dev(dev); |
| 4330 | |
Yangbo Lu | 1cf773b | 2020-09-18 17:08:01 +0800 | [diff] [blame] | 4331 | priv->tx_tstamp_type = HWTSTAMP_TX_OFF; |
| 4332 | priv->rx_tstamp = false; |
| 4333 | |
Yangbo Lu | c552118 | 2020-09-18 17:08:02 +0800 | [diff] [blame] | 4334 | priv->dpaa2_ptp_wq = alloc_workqueue("dpaa2_ptp_wq", 0, 0); |
| 4335 | if (!priv->dpaa2_ptp_wq) { |
| 4336 | err = -ENOMEM; |
| 4337 | goto err_wq_alloc; |
| 4338 | } |
| 4339 | |
| 4340 | INIT_WORK(&priv->tx_onestep_tstamp, dpaa2_eth_tx_onestep_tstamp); |
| 4341 | |
| 4342 | skb_queue_head_init(&priv->tx_skbs); |
| 4343 | |
Ioana Ciornei | 8ed3cef | 2021-04-02 12:55:32 +0300 | [diff] [blame] | 4344 | priv->rx_copybreak = DPAA2_ETH_DEFAULT_COPYBREAK; |
| 4345 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 4346 | /* Obtain a MC portal */ |
| 4347 | err = fsl_mc_portal_allocate(dpni_dev, FSL_MC_IO_ATOMIC_CONTEXT_PORTAL, |
| 4348 | &priv->mc_io); |
| 4349 | if (err) { |
Ioana Radulescu | 8c36961 | 2018-03-20 07:04:46 -0500 | [diff] [blame] | 4350 | if (err == -ENXIO) |
| 4351 | err = -EPROBE_DEFER; |
| 4352 | else |
| 4353 | dev_err(dev, "MC portal allocation failed\n"); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 4354 | goto err_portal_alloc; |
| 4355 | } |
| 4356 | |
| 4357 | /* MC objects initialization and configuration */ |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 4358 | err = dpaa2_eth_setup_dpni(dpni_dev); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 4359 | if (err) |
| 4360 | goto err_dpni_setup; |
| 4361 | |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 4362 | err = dpaa2_eth_setup_dpio(priv); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 4363 | if (err) |
| 4364 | goto err_dpio_setup; |
| 4365 | |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 4366 | dpaa2_eth_setup_fqs(priv); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 4367 | |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 4368 | err = dpaa2_eth_setup_dpbp(priv); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 4369 | if (err) |
| 4370 | goto err_dpbp_setup; |
| 4371 | |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 4372 | err = dpaa2_eth_bind_dpni(priv); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 4373 | if (err) |
| 4374 | goto err_bind; |
| 4375 | |
| 4376 | /* Add a NAPI context for each channel */ |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 4377 | dpaa2_eth_add_ch_napi(priv); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 4378 | |
| 4379 | /* Percpu statistics */ |
| 4380 | priv->percpu_stats = alloc_percpu(*priv->percpu_stats); |
| 4381 | if (!priv->percpu_stats) { |
| 4382 | dev_err(dev, "alloc_percpu(percpu_stats) failed\n"); |
| 4383 | err = -ENOMEM; |
| 4384 | goto err_alloc_percpu_stats; |
| 4385 | } |
Ioana Radulescu | 85047ab | 2017-04-28 04:50:31 -0500 | [diff] [blame] | 4386 | priv->percpu_extras = alloc_percpu(*priv->percpu_extras); |
| 4387 | if (!priv->percpu_extras) { |
| 4388 | dev_err(dev, "alloc_percpu(percpu_extras) failed\n"); |
| 4389 | err = -ENOMEM; |
| 4390 | goto err_alloc_percpu_extras; |
| 4391 | } |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 4392 | |
Ioana Ciornei | d70446e | 2020-06-29 21:47:11 +0300 | [diff] [blame] | 4393 | priv->sgt_cache = alloc_percpu(*priv->sgt_cache); |
| 4394 | if (!priv->sgt_cache) { |
| 4395 | dev_err(dev, "alloc_percpu(sgt_cache) failed\n"); |
| 4396 | err = -ENOMEM; |
| 4397 | goto err_alloc_sgt_cache; |
| 4398 | } |
| 4399 | |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 4400 | err = dpaa2_eth_netdev_init(net_dev); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 4401 | if (err) |
| 4402 | goto err_netdev_init; |
| 4403 | |
| 4404 | /* Configure checksum offload based on current interface flags */ |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 4405 | err = dpaa2_eth_set_rx_csum(priv, !!(net_dev->features & NETIF_F_RXCSUM)); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 4406 | if (err) |
| 4407 | goto err_csum; |
| 4408 | |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 4409 | err = dpaa2_eth_set_tx_csum(priv, |
| 4410 | !!(net_dev->features & (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM))); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 4411 | if (err) |
| 4412 | goto err_csum; |
| 4413 | |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 4414 | err = dpaa2_eth_alloc_rings(priv); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 4415 | if (err) |
| 4416 | goto err_alloc_rings; |
| 4417 | |
Ioana Ciornei | f395b69 | 2020-05-31 00:08:13 +0300 | [diff] [blame] | 4418 | #ifdef CONFIG_FSL_DPAA2_ETH_DCB |
| 4419 | if (dpaa2_eth_has_pause_support(priv) && priv->vlan_cls_enabled) { |
| 4420 | priv->dcbx_mode = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_IEEE; |
| 4421 | net_dev->dcbnl_ops = &dpaa2_eth_dcbnl_ops; |
| 4422 | } else { |
| 4423 | dev_dbg(dev, "PFC not supported\n"); |
| 4424 | } |
| 4425 | #endif |
| 4426 | |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 4427 | err = dpaa2_eth_setup_irqs(dpni_dev); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 4428 | if (err) { |
| 4429 | netdev_warn(net_dev, "Failed to set link interrupt, fall back to polling\n"); |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 4430 | priv->poll_thread = kthread_run(dpaa2_eth_poll_link_state, priv, |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 4431 | "%s_poll_link", net_dev->name); |
| 4432 | if (IS_ERR(priv->poll_thread)) { |
Ioana Radulescu | 7f12c8a3 | 2018-08-29 04:42:39 -0500 | [diff] [blame] | 4433 | dev_err(dev, "Error starting polling thread\n"); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 4434 | goto err_poll_thread; |
| 4435 | } |
| 4436 | priv->do_link_poll = true; |
| 4437 | } |
| 4438 | |
Ioana Ciornei | 7194792 | 2019-10-31 01:18:31 +0200 | [diff] [blame] | 4439 | err = dpaa2_eth_connect_mac(priv); |
| 4440 | if (err) |
| 4441 | goto err_connect_mac; |
| 4442 | |
Leon Romanovsky | bbb9ae2 | 2021-09-25 14:22:44 +0300 | [diff] [blame] | 4443 | err = dpaa2_eth_dl_alloc(priv); |
Ioana Ciornei | ceeb03a | 2020-10-01 18:11:47 +0300 | [diff] [blame] | 4444 | if (err) |
| 4445 | goto err_dl_register; |
| 4446 | |
Ioana Ciornei | 061d631 | 2020-10-01 18:11:48 +0300 | [diff] [blame] | 4447 | err = dpaa2_eth_dl_traps_register(priv); |
| 4448 | if (err) |
| 4449 | goto err_dl_trap_register; |
| 4450 | |
Ioana Ciornei | ceeb03a | 2020-10-01 18:11:47 +0300 | [diff] [blame] | 4451 | err = dpaa2_eth_dl_port_add(priv); |
| 4452 | if (err) |
| 4453 | goto err_dl_port_add; |
| 4454 | |
Ioana Radulescu | 7f12c8a3 | 2018-08-29 04:42:39 -0500 | [diff] [blame] | 4455 | err = register_netdev(net_dev); |
| 4456 | if (err < 0) { |
| 4457 | dev_err(dev, "register_netdev() failed\n"); |
| 4458 | goto err_netdev_reg; |
| 4459 | } |
| 4460 | |
Ioana Radulescu | 091a19e | 2019-01-18 16:16:00 +0000 | [diff] [blame] | 4461 | #ifdef CONFIG_DEBUG_FS |
| 4462 | dpaa2_dbg_add(priv); |
| 4463 | #endif |
| 4464 | |
Leon Romanovsky | bbb9ae2 | 2021-09-25 14:22:44 +0300 | [diff] [blame] | 4465 | dpaa2_eth_dl_register(priv); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 4466 | dev_info(dev, "Probed interface %s\n", net_dev->name); |
| 4467 | return 0; |
| 4468 | |
Ioana Radulescu | 7f12c8a3 | 2018-08-29 04:42:39 -0500 | [diff] [blame] | 4469 | err_netdev_reg: |
Ioana Ciornei | ceeb03a | 2020-10-01 18:11:47 +0300 | [diff] [blame] | 4470 | dpaa2_eth_dl_port_del(priv); |
| 4471 | err_dl_port_add: |
Ioana Ciornei | 061d631 | 2020-10-01 18:11:48 +0300 | [diff] [blame] | 4472 | dpaa2_eth_dl_traps_unregister(priv); |
| 4473 | err_dl_trap_register: |
Leon Romanovsky | bbb9ae2 | 2021-09-25 14:22:44 +0300 | [diff] [blame] | 4474 | dpaa2_eth_dl_free(priv); |
Ioana Ciornei | ceeb03a | 2020-10-01 18:11:47 +0300 | [diff] [blame] | 4475 | err_dl_register: |
Ioana Ciornei | 7194792 | 2019-10-31 01:18:31 +0200 | [diff] [blame] | 4476 | dpaa2_eth_disconnect_mac(priv); |
| 4477 | err_connect_mac: |
Ioana Radulescu | 7f12c8a3 | 2018-08-29 04:42:39 -0500 | [diff] [blame] | 4478 | if (priv->do_link_poll) |
| 4479 | kthread_stop(priv->poll_thread); |
| 4480 | else |
| 4481 | fsl_mc_free_irqs(dpni_dev); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 4482 | err_poll_thread: |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 4483 | dpaa2_eth_free_rings(priv); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 4484 | err_alloc_rings: |
| 4485 | err_csum: |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 4486 | err_netdev_init: |
Ioana Ciornei | d70446e | 2020-06-29 21:47:11 +0300 | [diff] [blame] | 4487 | free_percpu(priv->sgt_cache); |
| 4488 | err_alloc_sgt_cache: |
Ioana Radulescu | 85047ab | 2017-04-28 04:50:31 -0500 | [diff] [blame] | 4489 | free_percpu(priv->percpu_extras); |
| 4490 | err_alloc_percpu_extras: |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 4491 | free_percpu(priv->percpu_stats); |
| 4492 | err_alloc_percpu_stats: |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 4493 | dpaa2_eth_del_ch_napi(priv); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 4494 | err_bind: |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 4495 | dpaa2_eth_free_dpbp(priv); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 4496 | err_dpbp_setup: |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 4497 | dpaa2_eth_free_dpio(priv); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 4498 | err_dpio_setup: |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 4499 | dpaa2_eth_free_dpni(priv); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 4500 | err_dpni_setup: |
| 4501 | fsl_mc_portal_free(priv->mc_io); |
| 4502 | err_portal_alloc: |
Yangbo Lu | c552118 | 2020-09-18 17:08:02 +0800 | [diff] [blame] | 4503 | destroy_workqueue(priv->dpaa2_ptp_wq); |
| 4504 | err_wq_alloc: |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 4505 | dev_set_drvdata(dev, NULL); |
| 4506 | free_netdev(net_dev); |
| 4507 | |
| 4508 | return err; |
| 4509 | } |
| 4510 | |
| 4511 | static int dpaa2_eth_remove(struct fsl_mc_device *ls_dev) |
| 4512 | { |
| 4513 | struct device *dev; |
| 4514 | struct net_device *net_dev; |
| 4515 | struct dpaa2_eth_priv *priv; |
| 4516 | |
| 4517 | dev = &ls_dev->dev; |
| 4518 | net_dev = dev_get_drvdata(dev); |
| 4519 | priv = netdev_priv(net_dev); |
| 4520 | |
Leon Romanovsky | bbb9ae2 | 2021-09-25 14:22:44 +0300 | [diff] [blame] | 4521 | dpaa2_eth_dl_unregister(priv); |
| 4522 | |
Ioana Radulescu | 091a19e | 2019-01-18 16:16:00 +0000 | [diff] [blame] | 4523 | #ifdef CONFIG_DEBUG_FS |
| 4524 | dpaa2_dbg_remove(priv); |
| 4525 | #endif |
Robert-Ionut Alexa | 9ccc6e0 | 2022-02-09 17:57:43 +0200 | [diff] [blame^] | 4526 | |
| 4527 | unregister_netdev(net_dev); |
Ioana Ciornei | 7194792 | 2019-10-31 01:18:31 +0200 | [diff] [blame] | 4528 | rtnl_lock(); |
| 4529 | dpaa2_eth_disconnect_mac(priv); |
| 4530 | rtnl_unlock(); |
| 4531 | |
Ioana Ciornei | ceeb03a | 2020-10-01 18:11:47 +0300 | [diff] [blame] | 4532 | dpaa2_eth_dl_port_del(priv); |
Ioana Ciornei | 061d631 | 2020-10-01 18:11:48 +0300 | [diff] [blame] | 4533 | dpaa2_eth_dl_traps_unregister(priv); |
Leon Romanovsky | bbb9ae2 | 2021-09-25 14:22:44 +0300 | [diff] [blame] | 4534 | dpaa2_eth_dl_free(priv); |
Ioana Ciornei | ceeb03a | 2020-10-01 18:11:47 +0300 | [diff] [blame] | 4535 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 4536 | if (priv->do_link_poll) |
| 4537 | kthread_stop(priv->poll_thread); |
| 4538 | else |
| 4539 | fsl_mc_free_irqs(ls_dev); |
| 4540 | |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 4541 | dpaa2_eth_free_rings(priv); |
Ioana Ciornei | d70446e | 2020-06-29 21:47:11 +0300 | [diff] [blame] | 4542 | free_percpu(priv->sgt_cache); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 4543 | free_percpu(priv->percpu_stats); |
Ioana Radulescu | 85047ab | 2017-04-28 04:50:31 -0500 | [diff] [blame] | 4544 | free_percpu(priv->percpu_extras); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 4545 | |
Ioana Ciornei | 5d8dccf | 2020-08-31 21:12:39 +0300 | [diff] [blame] | 4546 | dpaa2_eth_del_ch_napi(priv); |
| 4547 | dpaa2_eth_free_dpbp(priv); |
| 4548 | dpaa2_eth_free_dpio(priv); |
| 4549 | dpaa2_eth_free_dpni(priv); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 4550 | |
| 4551 | fsl_mc_portal_free(priv->mc_io); |
| 4552 | |
Dongliang Mu | f4a8adb | 2021-11-30 12:05:54 +0800 | [diff] [blame] | 4553 | destroy_workqueue(priv->dpaa2_ptp_wq); |
| 4554 | |
Ioana Radulescu | 4bc07aa | 2018-03-23 10:23:36 -0500 | [diff] [blame] | 4555 | dev_dbg(net_dev->dev.parent, "Removed interface %s\n", net_dev->name); |
Ioana Radulescu | 7472dd9 | 2018-03-23 08:44:06 -0500 | [diff] [blame] | 4556 | |
Pavel Skripkin | 9b5a333 | 2021-11-16 18:17:12 +0300 | [diff] [blame] | 4557 | free_netdev(net_dev); |
| 4558 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 4559 | return 0; |
| 4560 | } |
| 4561 | |
| 4562 | static const struct fsl_mc_device_id dpaa2_eth_match_id_table[] = { |
| 4563 | { |
| 4564 | .vendor = FSL_MC_VENDOR_FREESCALE, |
| 4565 | .obj_type = "dpni", |
| 4566 | }, |
| 4567 | { .vendor = 0x0 } |
| 4568 | }; |
| 4569 | MODULE_DEVICE_TABLE(fslmc, dpaa2_eth_match_id_table); |
| 4570 | |
| 4571 | static struct fsl_mc_driver dpaa2_eth_driver = { |
| 4572 | .driver = { |
| 4573 | .name = KBUILD_MODNAME, |
| 4574 | .owner = THIS_MODULE, |
| 4575 | }, |
| 4576 | .probe = dpaa2_eth_probe, |
| 4577 | .remove = dpaa2_eth_remove, |
| 4578 | .match_id_table = dpaa2_eth_match_id_table |
| 4579 | }; |
| 4580 | |
Ioana Radulescu | 091a19e | 2019-01-18 16:16:00 +0000 | [diff] [blame] | 4581 | static int __init dpaa2_eth_driver_init(void) |
| 4582 | { |
| 4583 | int err; |
| 4584 | |
| 4585 | dpaa2_eth_dbg_init(); |
| 4586 | err = fsl_mc_driver_register(&dpaa2_eth_driver); |
| 4587 | if (err) { |
| 4588 | dpaa2_eth_dbg_exit(); |
| 4589 | return err; |
| 4590 | } |
| 4591 | |
| 4592 | return 0; |
| 4593 | } |
| 4594 | |
| 4595 | static void __exit dpaa2_eth_driver_exit(void) |
| 4596 | { |
| 4597 | dpaa2_eth_dbg_exit(); |
| 4598 | fsl_mc_driver_unregister(&dpaa2_eth_driver); |
| 4599 | } |
| 4600 | |
| 4601 | module_init(dpaa2_eth_driver_init); |
| 4602 | module_exit(dpaa2_eth_driver_exit); |