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