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. |
| 3 | * Copyright 2016-2017 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> |
Ioana Radulescu | 859f998 | 2018-04-26 18:23:47 +0800 | [diff] [blame] | 14 | #include <linux/net_tstamp.h> |
Bogdan Purcareata | 6bd067c | 2018-02-05 08:07:42 -0600 | [diff] [blame] | 15 | #include <linux/fsl/mc.h> |
Ioana Ciocoi Radulescu | 7e273a8 | 2018-11-26 16:27:29 +0000 | [diff] [blame] | 16 | #include <linux/bpf.h> |
| 17 | #include <linux/bpf_trace.h> |
Ioana Radulescu | 859f998 | 2018-04-26 18:23:47 +0800 | [diff] [blame] | 18 | #include <net/sock.h> |
| 19 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 20 | #include "dpaa2-eth.h" |
| 21 | |
Ioana Radulescu | 5636187 | 2017-04-28 04:50:32 -0500 | [diff] [blame] | 22 | /* CREATE_TRACE_POINTS only needs to be defined once. Other dpa files |
| 23 | * using trace events only need to #include <trace/events/sched.h> |
| 24 | */ |
| 25 | #define CREATE_TRACE_POINTS |
| 26 | #include "dpaa2-eth-trace.h" |
| 27 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 28 | MODULE_LICENSE("Dual BSD/GPL"); |
| 29 | MODULE_AUTHOR("Freescale Semiconductor, Inc"); |
| 30 | MODULE_DESCRIPTION("Freescale DPAA2 Ethernet Driver"); |
| 31 | |
Ioana Radulescu | 08eb239 | 2017-05-24 07:13:27 -0500 | [diff] [blame] | 32 | static void *dpaa2_iova_to_virt(struct iommu_domain *domain, |
| 33 | dma_addr_t iova_addr) |
| 34 | { |
| 35 | phys_addr_t phys_addr; |
| 36 | |
| 37 | phys_addr = domain ? iommu_iova_to_phys(domain, iova_addr) : iova_addr; |
| 38 | |
| 39 | return phys_to_virt(phys_addr); |
| 40 | } |
| 41 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 42 | static void validate_rx_csum(struct dpaa2_eth_priv *priv, |
| 43 | u32 fd_status, |
| 44 | struct sk_buff *skb) |
| 45 | { |
| 46 | skb_checksum_none_assert(skb); |
| 47 | |
| 48 | /* HW checksum validation is disabled, nothing to do here */ |
| 49 | if (!(priv->net_dev->features & NETIF_F_RXCSUM)) |
| 50 | return; |
| 51 | |
| 52 | /* Read checksum validation bits */ |
| 53 | if (!((fd_status & DPAA2_FAS_L3CV) && |
| 54 | (fd_status & DPAA2_FAS_L4CV))) |
| 55 | return; |
| 56 | |
| 57 | /* Inform the stack there's no need to compute L3/L4 csum anymore */ |
| 58 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 59 | } |
| 60 | |
| 61 | /* Free a received FD. |
| 62 | * Not to be used for Tx conf FDs or on any other paths. |
| 63 | */ |
| 64 | static void free_rx_fd(struct dpaa2_eth_priv *priv, |
| 65 | const struct dpaa2_fd *fd, |
| 66 | void *vaddr) |
| 67 | { |
| 68 | struct device *dev = priv->net_dev->dev.parent; |
| 69 | dma_addr_t addr = dpaa2_fd_get_addr(fd); |
| 70 | u8 fd_format = dpaa2_fd_get_format(fd); |
| 71 | struct dpaa2_sg_entry *sgt; |
| 72 | void *sg_vaddr; |
| 73 | int i; |
| 74 | |
| 75 | /* If single buffer frame, just free the data buffer */ |
| 76 | if (fd_format == dpaa2_fd_single) |
| 77 | goto free_buf; |
| 78 | else if (fd_format != dpaa2_fd_sg) |
| 79 | /* We don't support any other format */ |
| 80 | return; |
| 81 | |
Ioana Radulescu | 729d79b | 2017-10-11 08:29:48 -0500 | [diff] [blame] | 82 | /* For S/G frames, we first need to free all SG entries |
| 83 | * except the first one, which was taken care of already |
| 84 | */ |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 85 | sgt = vaddr + dpaa2_fd_get_offset(fd); |
Ioana Radulescu | 729d79b | 2017-10-11 08:29:48 -0500 | [diff] [blame] | 86 | for (i = 1; i < DPAA2_ETH_MAX_SG_ENTRIES; i++) { |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 87 | addr = dpaa2_sg_get_addr(&sgt[i]); |
Ioana Radulescu | 08eb239 | 2017-05-24 07:13:27 -0500 | [diff] [blame] | 88 | sg_vaddr = dpaa2_iova_to_virt(priv->iommu_domain, addr); |
Ioana Ciocoi Radulescu | 27c8748 | 2019-02-04 17:00:35 +0000 | [diff] [blame] | 89 | dma_unmap_page(dev, addr, DPAA2_ETH_RX_BUF_SIZE, |
| 90 | DMA_BIDIRECTIONAL); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 91 | |
Ioana Ciocoi Radulescu | 27c8748 | 2019-02-04 17:00:35 +0000 | [diff] [blame] | 92 | free_pages((unsigned long)sg_vaddr, 0); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 93 | if (dpaa2_sg_is_final(&sgt[i])) |
| 94 | break; |
| 95 | } |
| 96 | |
| 97 | free_buf: |
Ioana Ciocoi Radulescu | 27c8748 | 2019-02-04 17:00:35 +0000 | [diff] [blame] | 98 | free_pages((unsigned long)vaddr, 0); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | /* Build a linear skb based on a single-buffer frame descriptor */ |
Ioana Ciornei | fdb6ca9 | 2018-10-12 16:27:35 +0000 | [diff] [blame] | 102 | static struct sk_buff *build_linear_skb(struct dpaa2_eth_channel *ch, |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 103 | const struct dpaa2_fd *fd, |
| 104 | void *fd_vaddr) |
| 105 | { |
| 106 | struct sk_buff *skb = NULL; |
| 107 | u16 fd_offset = dpaa2_fd_get_offset(fd); |
| 108 | u32 fd_length = dpaa2_fd_get_len(fd); |
| 109 | |
Ioana Radulescu | cbb3ea4 | 2017-10-11 08:29:44 -0500 | [diff] [blame] | 110 | ch->buf_count--; |
| 111 | |
Ioana Ciocoi Radulescu | 27c8748 | 2019-02-04 17:00:35 +0000 | [diff] [blame] | 112 | skb = build_skb(fd_vaddr, DPAA2_ETH_RX_BUF_RAW_SIZE); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 113 | if (unlikely(!skb)) |
| 114 | return NULL; |
| 115 | |
| 116 | skb_reserve(skb, fd_offset); |
| 117 | skb_put(skb, fd_length); |
| 118 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 119 | return skb; |
| 120 | } |
| 121 | |
| 122 | /* Build a non linear (fragmented) skb based on a S/G table */ |
| 123 | static struct sk_buff *build_frag_skb(struct dpaa2_eth_priv *priv, |
| 124 | struct dpaa2_eth_channel *ch, |
| 125 | struct dpaa2_sg_entry *sgt) |
| 126 | { |
| 127 | struct sk_buff *skb = NULL; |
| 128 | struct device *dev = priv->net_dev->dev.parent; |
| 129 | void *sg_vaddr; |
| 130 | dma_addr_t sg_addr; |
| 131 | u16 sg_offset; |
| 132 | u32 sg_length; |
| 133 | struct page *page, *head_page; |
| 134 | int page_offset; |
| 135 | int i; |
| 136 | |
| 137 | for (i = 0; i < DPAA2_ETH_MAX_SG_ENTRIES; i++) { |
| 138 | struct dpaa2_sg_entry *sge = &sgt[i]; |
| 139 | |
| 140 | /* NOTE: We only support SG entries in dpaa2_sg_single format, |
| 141 | * but this is the only format we may receive from HW anyway |
| 142 | */ |
| 143 | |
| 144 | /* Get the address and length from the S/G entry */ |
| 145 | sg_addr = dpaa2_sg_get_addr(sge); |
Ioana Radulescu | 08eb239 | 2017-05-24 07:13:27 -0500 | [diff] [blame] | 146 | sg_vaddr = dpaa2_iova_to_virt(priv->iommu_domain, sg_addr); |
Ioana Ciocoi Radulescu | 27c8748 | 2019-02-04 17:00:35 +0000 | [diff] [blame] | 147 | dma_unmap_page(dev, sg_addr, DPAA2_ETH_RX_BUF_SIZE, |
| 148 | DMA_BIDIRECTIONAL); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 149 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 150 | sg_length = dpaa2_sg_get_len(sge); |
| 151 | |
| 152 | if (i == 0) { |
| 153 | /* We build the skb around the first data buffer */ |
Ioana Ciocoi Radulescu | 27c8748 | 2019-02-04 17:00:35 +0000 | [diff] [blame] | 154 | skb = build_skb(sg_vaddr, DPAA2_ETH_RX_BUF_RAW_SIZE); |
Ioana Radulescu | cbb3ea4 | 2017-10-11 08:29:44 -0500 | [diff] [blame] | 155 | if (unlikely(!skb)) { |
Ioana Radulescu | 729d79b | 2017-10-11 08:29:48 -0500 | [diff] [blame] | 156 | /* Free the first SG entry now, since we already |
| 157 | * unmapped it and obtained the virtual address |
| 158 | */ |
Ioana Ciocoi Radulescu | 27c8748 | 2019-02-04 17:00:35 +0000 | [diff] [blame] | 159 | free_pages((unsigned long)sg_vaddr, 0); |
Ioana Radulescu | 729d79b | 2017-10-11 08:29:48 -0500 | [diff] [blame] | 160 | |
Ioana Radulescu | cbb3ea4 | 2017-10-11 08:29:44 -0500 | [diff] [blame] | 161 | /* We still need to subtract the buffers used |
| 162 | * by this FD from our software counter |
| 163 | */ |
| 164 | while (!dpaa2_sg_is_final(&sgt[i]) && |
| 165 | i < DPAA2_ETH_MAX_SG_ENTRIES) |
| 166 | i++; |
| 167 | break; |
| 168 | } |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 169 | |
| 170 | sg_offset = dpaa2_sg_get_offset(sge); |
| 171 | skb_reserve(skb, sg_offset); |
| 172 | skb_put(skb, sg_length); |
| 173 | } else { |
| 174 | /* Rest of the data buffers are stored as skb frags */ |
| 175 | page = virt_to_page(sg_vaddr); |
| 176 | head_page = virt_to_head_page(sg_vaddr); |
| 177 | |
| 178 | /* Offset in page (which may be compound). |
| 179 | * Data in subsequent SG entries is stored from the |
| 180 | * beginning of the buffer, so we don't need to add the |
| 181 | * sg_offset. |
| 182 | */ |
| 183 | page_offset = ((unsigned long)sg_vaddr & |
| 184 | (PAGE_SIZE - 1)) + |
| 185 | (page_address(page) - page_address(head_page)); |
| 186 | |
| 187 | skb_add_rx_frag(skb, i - 1, head_page, page_offset, |
| 188 | sg_length, DPAA2_ETH_RX_BUF_SIZE); |
| 189 | } |
| 190 | |
| 191 | if (dpaa2_sg_is_final(sge)) |
| 192 | break; |
| 193 | } |
| 194 | |
Ioana Radulescu | b63baf7 | 2017-10-11 08:29:45 -0500 | [diff] [blame] | 195 | WARN_ONCE(i == DPAA2_ETH_MAX_SG_ENTRIES, "Final bit not set in SGT"); |
| 196 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 197 | /* Count all data buffers + SG table buffer */ |
| 198 | ch->buf_count -= i + 2; |
| 199 | |
| 200 | return skb; |
| 201 | } |
| 202 | |
Ioana Ciocoi Radulescu | 569375f | 2018-11-26 16:27:31 +0000 | [diff] [blame] | 203 | /* Free buffers acquired from the buffer pool or which were meant to |
| 204 | * be released in the pool |
| 205 | */ |
| 206 | static void free_bufs(struct dpaa2_eth_priv *priv, u64 *buf_array, int count) |
| 207 | { |
| 208 | struct device *dev = priv->net_dev->dev.parent; |
| 209 | void *vaddr; |
| 210 | int i; |
| 211 | |
| 212 | for (i = 0; i < count; i++) { |
| 213 | vaddr = dpaa2_iova_to_virt(priv->iommu_domain, buf_array[i]); |
Ioana Ciocoi Radulescu | 27c8748 | 2019-02-04 17:00:35 +0000 | [diff] [blame] | 214 | dma_unmap_page(dev, buf_array[i], DPAA2_ETH_RX_BUF_SIZE, |
| 215 | DMA_BIDIRECTIONAL); |
| 216 | free_pages((unsigned long)vaddr, 0); |
Ioana Ciocoi Radulescu | 569375f | 2018-11-26 16:27:31 +0000 | [diff] [blame] | 217 | } |
| 218 | } |
| 219 | |
Ioana Ciocoi Radulescu | 5d39dc2 | 2018-11-26 16:27:31 +0000 | [diff] [blame] | 220 | static void xdp_release_buf(struct dpaa2_eth_priv *priv, |
| 221 | struct dpaa2_eth_channel *ch, |
| 222 | dma_addr_t addr) |
| 223 | { |
| 224 | int err; |
| 225 | |
| 226 | ch->xdp.drop_bufs[ch->xdp.drop_cnt++] = addr; |
| 227 | if (ch->xdp.drop_cnt < DPAA2_ETH_BUFS_PER_CMD) |
| 228 | return; |
| 229 | |
| 230 | while ((err = dpaa2_io_service_release(ch->dpio, priv->bpid, |
| 231 | ch->xdp.drop_bufs, |
| 232 | ch->xdp.drop_cnt)) == -EBUSY) |
| 233 | cpu_relax(); |
| 234 | |
| 235 | if (err) { |
| 236 | free_bufs(priv, ch->xdp.drop_bufs, ch->xdp.drop_cnt); |
| 237 | ch->buf_count -= ch->xdp.drop_cnt; |
| 238 | } |
| 239 | |
| 240 | ch->xdp.drop_cnt = 0; |
| 241 | } |
| 242 | |
Ioana Ciocoi Radulescu | 99e4352 | 2018-11-26 16:27:33 +0000 | [diff] [blame] | 243 | static int xdp_enqueue(struct dpaa2_eth_priv *priv, struct dpaa2_fd *fd, |
| 244 | void *buf_start, u16 queue_id) |
| 245 | { |
| 246 | struct dpaa2_eth_fq *fq; |
| 247 | struct dpaa2_faead *faead; |
| 248 | u32 ctrl, frc; |
| 249 | int i, err; |
| 250 | |
| 251 | /* Mark the egress frame hardware annotation area as valid */ |
| 252 | frc = dpaa2_fd_get_frc(fd); |
| 253 | dpaa2_fd_set_frc(fd, frc | DPAA2_FD_FRC_FAEADV); |
| 254 | dpaa2_fd_set_ctrl(fd, DPAA2_FD_CTRL_ASAL); |
| 255 | |
| 256 | /* Instruct hardware to release the FD buffer directly into |
| 257 | * the buffer pool once transmission is completed, instead of |
| 258 | * sending a Tx confirmation frame to us |
| 259 | */ |
| 260 | ctrl = DPAA2_FAEAD_A4V | DPAA2_FAEAD_A2V | DPAA2_FAEAD_EBDDV; |
| 261 | faead = dpaa2_get_faead(buf_start, false); |
| 262 | faead->ctrl = cpu_to_le32(ctrl); |
| 263 | faead->conf_fqid = 0; |
| 264 | |
| 265 | fq = &priv->fq[queue_id]; |
| 266 | for (i = 0; i < DPAA2_ETH_ENQUEUE_RETRIES; i++) { |
Ioana Ciocoi Radulescu | 1fa0f68 | 2019-02-04 17:00:36 +0000 | [diff] [blame] | 267 | err = priv->enqueue(priv, fq, fd, 0); |
Ioana Ciocoi Radulescu | 99e4352 | 2018-11-26 16:27:33 +0000 | [diff] [blame] | 268 | if (err != -EBUSY) |
| 269 | break; |
| 270 | } |
| 271 | |
| 272 | return err; |
| 273 | } |
| 274 | |
Ioana Ciocoi Radulescu | 7e273a8 | 2018-11-26 16:27:29 +0000 | [diff] [blame] | 275 | static u32 run_xdp(struct dpaa2_eth_priv *priv, |
| 276 | struct dpaa2_eth_channel *ch, |
Ioana Ciocoi Radulescu | 99e4352 | 2018-11-26 16:27:33 +0000 | [diff] [blame] | 277 | struct dpaa2_eth_fq *rx_fq, |
Ioana Ciocoi Radulescu | 7e273a8 | 2018-11-26 16:27:29 +0000 | [diff] [blame] | 278 | struct dpaa2_fd *fd, void *vaddr) |
| 279 | { |
Ioana Ciocoi Radulescu | 5d39dc2 | 2018-11-26 16:27:31 +0000 | [diff] [blame] | 280 | dma_addr_t addr = dpaa2_fd_get_addr(fd); |
Ioana Ciocoi Radulescu | 99e4352 | 2018-11-26 16:27:33 +0000 | [diff] [blame] | 281 | struct rtnl_link_stats64 *percpu_stats; |
Ioana Ciocoi Radulescu | 7e273a8 | 2018-11-26 16:27:29 +0000 | [diff] [blame] | 282 | struct bpf_prog *xdp_prog; |
| 283 | struct xdp_buff xdp; |
| 284 | u32 xdp_act = XDP_PASS; |
Ioana Ciocoi Radulescu | 99e4352 | 2018-11-26 16:27:33 +0000 | [diff] [blame] | 285 | int err; |
| 286 | |
| 287 | percpu_stats = this_cpu_ptr(priv->percpu_stats); |
Ioana Ciocoi Radulescu | 7e273a8 | 2018-11-26 16:27:29 +0000 | [diff] [blame] | 288 | |
| 289 | rcu_read_lock(); |
| 290 | |
| 291 | xdp_prog = READ_ONCE(ch->xdp.prog); |
| 292 | if (!xdp_prog) |
| 293 | goto out; |
| 294 | |
| 295 | xdp.data = vaddr + dpaa2_fd_get_offset(fd); |
| 296 | xdp.data_end = xdp.data + dpaa2_fd_get_len(fd); |
Ioana Ciocoi Radulescu | 7b1eea1 | 2018-11-26 16:27:30 +0000 | [diff] [blame] | 297 | xdp.data_hard_start = xdp.data - XDP_PACKET_HEADROOM; |
Ioana Ciocoi Radulescu | 7e273a8 | 2018-11-26 16:27:29 +0000 | [diff] [blame] | 298 | xdp_set_data_meta_invalid(&xdp); |
Ioana Radulescu | d678be1 | 2019-03-01 17:47:24 +0000 | [diff] [blame] | 299 | xdp.rxq = &ch->xdp_rxq; |
Ioana Ciocoi Radulescu | 7e273a8 | 2018-11-26 16:27:29 +0000 | [diff] [blame] | 300 | |
| 301 | xdp_act = bpf_prog_run_xdp(xdp_prog, &xdp); |
| 302 | |
Ioana Ciocoi Radulescu | 7b1eea1 | 2018-11-26 16:27:30 +0000 | [diff] [blame] | 303 | /* xdp.data pointer may have changed */ |
| 304 | dpaa2_fd_set_offset(fd, xdp.data - vaddr); |
| 305 | dpaa2_fd_set_len(fd, xdp.data_end - xdp.data); |
| 306 | |
Ioana Ciocoi Radulescu | 7e273a8 | 2018-11-26 16:27:29 +0000 | [diff] [blame] | 307 | switch (xdp_act) { |
| 308 | case XDP_PASS: |
| 309 | break; |
Ioana Ciocoi Radulescu | 99e4352 | 2018-11-26 16:27:33 +0000 | [diff] [blame] | 310 | case XDP_TX: |
| 311 | err = xdp_enqueue(priv, fd, vaddr, rx_fq->flowid); |
| 312 | if (err) { |
| 313 | xdp_release_buf(priv, ch, addr); |
| 314 | percpu_stats->tx_errors++; |
Ioana Ciocoi Radulescu | a4a7b76 | 2018-11-26 16:27:34 +0000 | [diff] [blame] | 315 | ch->stats.xdp_tx_err++; |
Ioana Ciocoi Radulescu | 99e4352 | 2018-11-26 16:27:33 +0000 | [diff] [blame] | 316 | } else { |
| 317 | percpu_stats->tx_packets++; |
| 318 | percpu_stats->tx_bytes += dpaa2_fd_get_len(fd); |
Ioana Ciocoi Radulescu | a4a7b76 | 2018-11-26 16:27:34 +0000 | [diff] [blame] | 319 | ch->stats.xdp_tx++; |
Ioana Ciocoi Radulescu | 99e4352 | 2018-11-26 16:27:33 +0000 | [diff] [blame] | 320 | } |
| 321 | break; |
Ioana Ciocoi Radulescu | 7e273a8 | 2018-11-26 16:27:29 +0000 | [diff] [blame] | 322 | default: |
| 323 | bpf_warn_invalid_xdp_action(xdp_act); |
Ioana Ciocoi Radulescu | c1cb11b | 2018-11-29 08:43:40 +0000 | [diff] [blame] | 324 | /* fall through */ |
Ioana Ciocoi Radulescu | 7e273a8 | 2018-11-26 16:27:29 +0000 | [diff] [blame] | 325 | case XDP_ABORTED: |
| 326 | trace_xdp_exception(priv->net_dev, xdp_prog, xdp_act); |
Ioana Ciocoi Radulescu | c1cb11b | 2018-11-29 08:43:40 +0000 | [diff] [blame] | 327 | /* fall through */ |
Ioana Ciocoi Radulescu | 7e273a8 | 2018-11-26 16:27:29 +0000 | [diff] [blame] | 328 | case XDP_DROP: |
Ioana Ciocoi Radulescu | 5d39dc2 | 2018-11-26 16:27:31 +0000 | [diff] [blame] | 329 | xdp_release_buf(priv, ch, addr); |
Ioana Ciocoi Radulescu | a4a7b76 | 2018-11-26 16:27:34 +0000 | [diff] [blame] | 330 | ch->stats.xdp_drop++; |
Ioana Ciocoi Radulescu | 7e273a8 | 2018-11-26 16:27:29 +0000 | [diff] [blame] | 331 | break; |
Ioana Radulescu | d678be1 | 2019-03-01 17:47:24 +0000 | [diff] [blame] | 332 | case XDP_REDIRECT: |
| 333 | dma_unmap_page(priv->net_dev->dev.parent, addr, |
| 334 | DPAA2_ETH_RX_BUF_SIZE, DMA_BIDIRECTIONAL); |
| 335 | ch->buf_count--; |
| 336 | xdp.data_hard_start = vaddr; |
| 337 | err = xdp_do_redirect(priv->net_dev, &xdp, xdp_prog); |
| 338 | if (unlikely(err)) |
| 339 | ch->stats.xdp_drop++; |
| 340 | else |
| 341 | ch->stats.xdp_redirect++; |
| 342 | break; |
Ioana Ciocoi Radulescu | 7e273a8 | 2018-11-26 16:27:29 +0000 | [diff] [blame] | 343 | } |
| 344 | |
Ioana Radulescu | d678be1 | 2019-03-01 17:47:24 +0000 | [diff] [blame] | 345 | ch->xdp.res |= xdp_act; |
Ioana Ciocoi Radulescu | 7e273a8 | 2018-11-26 16:27:29 +0000 | [diff] [blame] | 346 | out: |
| 347 | rcu_read_unlock(); |
| 348 | return xdp_act; |
| 349 | } |
| 350 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 351 | /* Main Rx frame processing routine */ |
| 352 | static void dpaa2_eth_rx(struct dpaa2_eth_priv *priv, |
| 353 | struct dpaa2_eth_channel *ch, |
| 354 | const struct dpaa2_fd *fd, |
Ioana Ciocoi Radulescu | dbcdf72 | 2018-11-14 11:48:35 +0000 | [diff] [blame] | 355 | struct dpaa2_eth_fq *fq) |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 356 | { |
| 357 | dma_addr_t addr = dpaa2_fd_get_addr(fd); |
| 358 | u8 fd_format = dpaa2_fd_get_format(fd); |
| 359 | void *vaddr; |
| 360 | struct sk_buff *skb; |
| 361 | struct rtnl_link_stats64 *percpu_stats; |
Ioana Radulescu | 85047ab | 2017-04-28 04:50:31 -0500 | [diff] [blame] | 362 | struct dpaa2_eth_drv_stats *percpu_extras; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 363 | struct device *dev = priv->net_dev->dev.parent; |
| 364 | struct dpaa2_fas *fas; |
Ioana Radulescu | d695e76 | 2017-06-06 10:00:35 -0500 | [diff] [blame] | 365 | void *buf_data; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 366 | u32 status = 0; |
Ioana Ciocoi Radulescu | 7e273a8 | 2018-11-26 16:27:29 +0000 | [diff] [blame] | 367 | u32 xdp_act; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 368 | |
Ioana Radulescu | 5636187 | 2017-04-28 04:50:32 -0500 | [diff] [blame] | 369 | /* Tracing point */ |
| 370 | trace_dpaa2_rx_fd(priv->net_dev, fd); |
| 371 | |
Ioana Radulescu | 08eb239 | 2017-05-24 07:13:27 -0500 | [diff] [blame] | 372 | vaddr = dpaa2_iova_to_virt(priv->iommu_domain, addr); |
Ioana Ciocoi Radulescu | 5d39dc2 | 2018-11-26 16:27:31 +0000 | [diff] [blame] | 373 | dma_sync_single_for_cpu(dev, addr, DPAA2_ETH_RX_BUF_SIZE, |
Ioana Ciocoi Radulescu | 18c2e77 | 2018-11-26 16:27:32 +0000 | [diff] [blame] | 374 | DMA_BIDIRECTIONAL); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 375 | |
Ioana Radulescu | 54ce891 | 2017-12-08 06:47:53 -0600 | [diff] [blame] | 376 | fas = dpaa2_get_fas(vaddr, false); |
Ioana Radulescu | d695e76 | 2017-06-06 10:00:35 -0500 | [diff] [blame] | 377 | prefetch(fas); |
| 378 | buf_data = vaddr + dpaa2_fd_get_offset(fd); |
| 379 | prefetch(buf_data); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 380 | |
| 381 | percpu_stats = this_cpu_ptr(priv->percpu_stats); |
Ioana Radulescu | 85047ab | 2017-04-28 04:50:31 -0500 | [diff] [blame] | 382 | percpu_extras = this_cpu_ptr(priv->percpu_extras); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 383 | |
| 384 | if (fd_format == dpaa2_fd_single) { |
Ioana Ciocoi Radulescu | 99e4352 | 2018-11-26 16:27:33 +0000 | [diff] [blame] | 385 | xdp_act = run_xdp(priv, ch, fq, (struct dpaa2_fd *)fd, vaddr); |
Ioana Ciocoi Radulescu | 7e273a8 | 2018-11-26 16:27:29 +0000 | [diff] [blame] | 386 | if (xdp_act != XDP_PASS) { |
| 387 | percpu_stats->rx_packets++; |
| 388 | percpu_stats->rx_bytes += dpaa2_fd_get_len(fd); |
| 389 | return; |
| 390 | } |
| 391 | |
Ioana Ciocoi Radulescu | 27c8748 | 2019-02-04 17:00:35 +0000 | [diff] [blame] | 392 | dma_unmap_page(dev, addr, DPAA2_ETH_RX_BUF_SIZE, |
| 393 | DMA_BIDIRECTIONAL); |
Ioana Ciornei | fdb6ca9 | 2018-10-12 16:27:35 +0000 | [diff] [blame] | 394 | skb = build_linear_skb(ch, fd, vaddr); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 395 | } else if (fd_format == dpaa2_fd_sg) { |
Ioana Ciocoi Radulescu | 7e273a8 | 2018-11-26 16:27:29 +0000 | [diff] [blame] | 396 | WARN_ON(priv->xdp_prog); |
| 397 | |
Ioana Ciocoi Radulescu | 27c8748 | 2019-02-04 17:00:35 +0000 | [diff] [blame] | 398 | dma_unmap_page(dev, addr, DPAA2_ETH_RX_BUF_SIZE, |
| 399 | DMA_BIDIRECTIONAL); |
Ioana Radulescu | d695e76 | 2017-06-06 10:00:35 -0500 | [diff] [blame] | 400 | skb = build_frag_skb(priv, ch, buf_data); |
Ioana Ciocoi Radulescu | 27c8748 | 2019-02-04 17:00:35 +0000 | [diff] [blame] | 401 | free_pages((unsigned long)vaddr, 0); |
Ioana Radulescu | 85047ab | 2017-04-28 04:50:31 -0500 | [diff] [blame] | 402 | percpu_extras->rx_sg_frames++; |
| 403 | percpu_extras->rx_sg_bytes += dpaa2_fd_get_len(fd); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 404 | } else { |
| 405 | /* We don't support any other format */ |
| 406 | goto err_frame_format; |
| 407 | } |
| 408 | |
| 409 | if (unlikely(!skb)) |
| 410 | goto err_build_skb; |
| 411 | |
| 412 | prefetch(skb->data); |
| 413 | |
Ioana Radulescu | 859f998 | 2018-04-26 18:23:47 +0800 | [diff] [blame] | 414 | /* Get the timestamp value */ |
| 415 | if (priv->rx_tstamp) { |
| 416 | struct skb_shared_hwtstamps *shhwtstamps = skb_hwtstamps(skb); |
| 417 | __le64 *ts = dpaa2_get_ts(vaddr, false); |
| 418 | u64 ns; |
| 419 | |
| 420 | memset(shhwtstamps, 0, sizeof(*shhwtstamps)); |
| 421 | |
| 422 | ns = DPAA2_PTP_CLK_PERIOD_NS * le64_to_cpup(ts); |
| 423 | shhwtstamps->hwtstamp = ns_to_ktime(ns); |
| 424 | } |
| 425 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 426 | /* Check if we need to validate the L4 csum */ |
| 427 | if (likely(dpaa2_fd_get_frc(fd) & DPAA2_FD_FRC_FASV)) { |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 428 | status = le32_to_cpu(fas->status); |
| 429 | validate_rx_csum(priv, status, skb); |
| 430 | } |
| 431 | |
| 432 | skb->protocol = eth_type_trans(skb, priv->net_dev); |
Ioana Ciocoi Radulescu | dbcdf72 | 2018-11-14 11:48:35 +0000 | [diff] [blame] | 433 | skb_record_rx_queue(skb, fq->flowid); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 434 | |
| 435 | percpu_stats->rx_packets++; |
| 436 | percpu_stats->rx_bytes += dpaa2_fd_get_len(fd); |
| 437 | |
Ioana Ciornei | 0a25d92 | 2019-03-25 13:42:39 +0000 | [diff] [blame] | 438 | list_add_tail(&skb->list, ch->rx_list); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 439 | |
| 440 | return; |
| 441 | |
| 442 | err_build_skb: |
| 443 | free_rx_fd(priv, fd, vaddr); |
| 444 | err_frame_format: |
| 445 | percpu_stats->rx_dropped++; |
| 446 | } |
| 447 | |
| 448 | /* Consume all frames pull-dequeued into the store. This is the simplest way to |
| 449 | * make sure we don't accidentally issue another volatile dequeue which would |
| 450 | * overwrite (leak) frames already in the store. |
| 451 | * |
| 452 | * Observance of NAPI budget is not our concern, leaving that to the caller. |
| 453 | */ |
Ioana Ciocoi Radulescu | 68049a5 | 2018-10-08 14:16:31 +0000 | [diff] [blame] | 454 | static int consume_frames(struct dpaa2_eth_channel *ch, |
Ioana Ciocoi Radulescu | 569dac6 | 2018-11-14 11:48:36 +0000 | [diff] [blame] | 455 | struct dpaa2_eth_fq **src) |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 456 | { |
| 457 | struct dpaa2_eth_priv *priv = ch->priv; |
Ioana Ciocoi Radulescu | 68049a5 | 2018-10-08 14:16:31 +0000 | [diff] [blame] | 458 | struct dpaa2_eth_fq *fq = NULL; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 459 | struct dpaa2_dq *dq; |
| 460 | const struct dpaa2_fd *fd; |
| 461 | int cleaned = 0; |
| 462 | int is_last; |
| 463 | |
| 464 | do { |
| 465 | dq = dpaa2_io_store_next(ch->store, &is_last); |
| 466 | if (unlikely(!dq)) { |
| 467 | /* If we're here, we *must* have placed a |
| 468 | * volatile dequeue comnmand, so keep reading through |
| 469 | * the store until we get some sort of valid response |
| 470 | * token (either a valid frame or an "empty dequeue") |
| 471 | */ |
| 472 | continue; |
| 473 | } |
| 474 | |
| 475 | fd = dpaa2_dq_fd(dq); |
Ioana Radulescu | 75c583a | 2018-02-26 10:28:06 -0600 | [diff] [blame] | 476 | fq = (struct dpaa2_eth_fq *)(uintptr_t)dpaa2_dq_fqd_ctx(dq); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 477 | |
Ioana Ciocoi Radulescu | dbcdf72 | 2018-11-14 11:48:35 +0000 | [diff] [blame] | 478 | fq->consume(priv, ch, fd, fq); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 479 | cleaned++; |
| 480 | } while (!is_last); |
| 481 | |
Ioana Ciocoi Radulescu | 68049a5 | 2018-10-08 14:16:31 +0000 | [diff] [blame] | 482 | if (!cleaned) |
| 483 | return 0; |
| 484 | |
| 485 | fq->stats.frames += cleaned; |
Ioana Ciocoi Radulescu | 68049a5 | 2018-10-08 14:16:31 +0000 | [diff] [blame] | 486 | |
| 487 | /* A dequeue operation only pulls frames from a single queue |
Ioana Ciocoi Radulescu | 569dac6 | 2018-11-14 11:48:36 +0000 | [diff] [blame] | 488 | * into the store. Return the frame queue as an out param. |
Ioana Ciocoi Radulescu | 68049a5 | 2018-10-08 14:16:31 +0000 | [diff] [blame] | 489 | */ |
Ioana Ciocoi Radulescu | 569dac6 | 2018-11-14 11:48:36 +0000 | [diff] [blame] | 490 | if (src) |
| 491 | *src = fq; |
Ioana Ciocoi Radulescu | 68049a5 | 2018-10-08 14:16:31 +0000 | [diff] [blame] | 492 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 493 | return cleaned; |
| 494 | } |
| 495 | |
Ioana Radulescu | 859f998 | 2018-04-26 18:23:47 +0800 | [diff] [blame] | 496 | /* Configure the egress frame annotation for timestamp update */ |
| 497 | static void enable_tx_tstamp(struct dpaa2_fd *fd, void *buf_start) |
| 498 | { |
| 499 | struct dpaa2_faead *faead; |
| 500 | u32 ctrl, frc; |
| 501 | |
| 502 | /* Mark the egress frame annotation area as valid */ |
| 503 | frc = dpaa2_fd_get_frc(fd); |
| 504 | dpaa2_fd_set_frc(fd, frc | DPAA2_FD_FRC_FAEADV); |
| 505 | |
| 506 | /* Set hardware annotation size */ |
| 507 | ctrl = dpaa2_fd_get_ctrl(fd); |
| 508 | dpaa2_fd_set_ctrl(fd, ctrl | DPAA2_FD_CTRL_ASAL); |
| 509 | |
| 510 | /* enable UPD (update prepanded data) bit in FAEAD field of |
| 511 | * hardware frame annotation area |
| 512 | */ |
| 513 | ctrl = DPAA2_FAEAD_A2V | DPAA2_FAEAD_UPDV | DPAA2_FAEAD_UPD; |
| 514 | faead = dpaa2_get_faead(buf_start, true); |
| 515 | faead->ctrl = cpu_to_le32(ctrl); |
| 516 | } |
| 517 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 518 | /* Create a frame descriptor based on a fragmented skb */ |
| 519 | static int build_sg_fd(struct dpaa2_eth_priv *priv, |
| 520 | struct sk_buff *skb, |
| 521 | struct dpaa2_fd *fd) |
| 522 | { |
| 523 | struct device *dev = priv->net_dev->dev.parent; |
| 524 | void *sgt_buf = NULL; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 525 | dma_addr_t addr; |
| 526 | int nr_frags = skb_shinfo(skb)->nr_frags; |
| 527 | struct dpaa2_sg_entry *sgt; |
| 528 | int i, err; |
| 529 | int sgt_buf_size; |
| 530 | struct scatterlist *scl, *crt_scl; |
| 531 | int num_sg; |
| 532 | int num_dma_bufs; |
| 533 | struct dpaa2_eth_swa *swa; |
| 534 | |
| 535 | /* Create and map scatterlist. |
| 536 | * We don't advertise NETIF_F_FRAGLIST, so skb_to_sgvec() will not have |
| 537 | * to go beyond nr_frags+1. |
| 538 | * Note: We don't support chained scatterlists |
| 539 | */ |
| 540 | if (unlikely(PAGE_SIZE / sizeof(struct scatterlist) < nr_frags + 1)) |
| 541 | return -EINVAL; |
| 542 | |
| 543 | scl = kcalloc(nr_frags + 1, sizeof(struct scatterlist), GFP_ATOMIC); |
| 544 | if (unlikely(!scl)) |
| 545 | return -ENOMEM; |
| 546 | |
| 547 | sg_init_table(scl, nr_frags + 1); |
| 548 | num_sg = skb_to_sgvec(skb, scl, 0, skb->len); |
Ioana Radulescu | 1e5fa9e | 2017-05-24 07:13:28 -0500 | [diff] [blame] | 549 | num_dma_bufs = dma_map_sg(dev, scl, num_sg, DMA_BIDIRECTIONAL); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 550 | if (unlikely(!num_dma_bufs)) { |
| 551 | err = -ENOMEM; |
| 552 | goto dma_map_sg_failed; |
| 553 | } |
| 554 | |
| 555 | /* Prepare the HW SGT structure */ |
| 556 | sgt_buf_size = priv->tx_data_offset + |
Ioana Radulescu | fa722c0 | 2018-03-23 08:44:12 -0500 | [diff] [blame] | 557 | sizeof(struct dpaa2_sg_entry) * num_dma_bufs; |
Sebastian Andrzej Siewior | 90bc6d4 | 2019-06-07 21:20:37 +0200 | [diff] [blame] | 558 | 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] | 559 | if (unlikely(!sgt_buf)) { |
| 560 | err = -ENOMEM; |
| 561 | goto sgt_buf_alloc_failed; |
| 562 | } |
| 563 | sgt_buf = PTR_ALIGN(sgt_buf, DPAA2_ETH_TX_BUF_ALIGN); |
Ioana Radulescu | 6a9bbe5 | 2018-03-14 15:04:51 -0500 | [diff] [blame] | 564 | memset(sgt_buf, 0, sgt_buf_size); |
| 565 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 566 | sgt = (struct dpaa2_sg_entry *)(sgt_buf + priv->tx_data_offset); |
| 567 | |
| 568 | /* Fill in the HW SGT structure. |
| 569 | * |
| 570 | * sgt_buf is zeroed out, so the following fields are implicit |
| 571 | * in all sgt entries: |
| 572 | * - offset is 0 |
| 573 | * - format is 'dpaa2_sg_single' |
| 574 | */ |
| 575 | for_each_sg(scl, crt_scl, num_dma_bufs, i) { |
| 576 | dpaa2_sg_set_addr(&sgt[i], sg_dma_address(crt_scl)); |
| 577 | dpaa2_sg_set_len(&sgt[i], sg_dma_len(crt_scl)); |
| 578 | } |
| 579 | dpaa2_sg_set_final(&sgt[i - 1], true); |
| 580 | |
| 581 | /* Store the skb backpointer in the SGT buffer. |
| 582 | * Fit the scatterlist and the number of buffers alongside the |
| 583 | * skb backpointer in the software annotation area. We'll need |
| 584 | * all of them on Tx Conf. |
| 585 | */ |
| 586 | swa = (struct dpaa2_eth_swa *)sgt_buf; |
Ioana Radulescu | e3fdf6b | 2019-03-01 17:47:23 +0000 | [diff] [blame] | 587 | swa->type = DPAA2_ETH_SWA_SG; |
| 588 | swa->sg.skb = skb; |
| 589 | swa->sg.scl = scl; |
| 590 | swa->sg.num_sg = num_sg; |
| 591 | swa->sg.sgt_size = sgt_buf_size; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 592 | |
| 593 | /* Separately map the SGT buffer */ |
Ioana Radulescu | 1e5fa9e | 2017-05-24 07:13:28 -0500 | [diff] [blame] | 594 | addr = dma_map_single(dev, sgt_buf, sgt_buf_size, DMA_BIDIRECTIONAL); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 595 | if (unlikely(dma_mapping_error(dev, addr))) { |
| 596 | err = -ENOMEM; |
| 597 | goto dma_map_single_failed; |
| 598 | } |
| 599 | dpaa2_fd_set_offset(fd, priv->tx_data_offset); |
| 600 | dpaa2_fd_set_format(fd, dpaa2_fd_sg); |
| 601 | dpaa2_fd_set_addr(fd, addr); |
| 602 | dpaa2_fd_set_len(fd, skb->len); |
Ioana Radulescu | b948c8c | 2018-10-12 16:27:40 +0000 | [diff] [blame] | 603 | dpaa2_fd_set_ctrl(fd, FD_CTRL_PTA); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 604 | |
Ioana Radulescu | 859f998 | 2018-04-26 18:23:47 +0800 | [diff] [blame] | 605 | if (priv->tx_tstamp && skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) |
| 606 | enable_tx_tstamp(fd, sgt_buf); |
| 607 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 608 | return 0; |
| 609 | |
| 610 | dma_map_single_failed: |
Ioana Radulescu | 6a9bbe5 | 2018-03-14 15:04:51 -0500 | [diff] [blame] | 611 | skb_free_frag(sgt_buf); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 612 | sgt_buf_alloc_failed: |
Ioana Radulescu | 1e5fa9e | 2017-05-24 07:13:28 -0500 | [diff] [blame] | 613 | dma_unmap_sg(dev, scl, num_sg, DMA_BIDIRECTIONAL); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 614 | dma_map_sg_failed: |
| 615 | kfree(scl); |
| 616 | return err; |
| 617 | } |
| 618 | |
| 619 | /* Create a frame descriptor based on a linear skb */ |
| 620 | static int build_single_fd(struct dpaa2_eth_priv *priv, |
| 621 | struct sk_buff *skb, |
| 622 | struct dpaa2_fd *fd) |
| 623 | { |
| 624 | struct device *dev = priv->net_dev->dev.parent; |
Ioana Radulescu | c163685 | 2017-12-08 06:47:58 -0600 | [diff] [blame] | 625 | u8 *buffer_start, *aligned_start; |
Ioana Radulescu | e3fdf6b | 2019-03-01 17:47:23 +0000 | [diff] [blame] | 626 | struct dpaa2_eth_swa *swa; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 627 | dma_addr_t addr; |
| 628 | |
Ioana Radulescu | c163685 | 2017-12-08 06:47:58 -0600 | [diff] [blame] | 629 | buffer_start = skb->data - dpaa2_eth_needed_headroom(priv, skb); |
| 630 | |
| 631 | /* If there's enough room to align the FD address, do it. |
| 632 | * It will help hardware optimize accesses. |
| 633 | */ |
| 634 | aligned_start = PTR_ALIGN(buffer_start - DPAA2_ETH_TX_BUF_ALIGN, |
| 635 | DPAA2_ETH_TX_BUF_ALIGN); |
| 636 | if (aligned_start >= skb->head) |
| 637 | buffer_start = aligned_start; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 638 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 639 | /* Store a backpointer to the skb at the beginning of the buffer |
| 640 | * (in the private data area) such that we can release it |
| 641 | * on Tx confirm |
| 642 | */ |
Ioana Radulescu | e3fdf6b | 2019-03-01 17:47:23 +0000 | [diff] [blame] | 643 | swa = (struct dpaa2_eth_swa *)buffer_start; |
| 644 | swa->type = DPAA2_ETH_SWA_SINGLE; |
| 645 | swa->single.skb = skb; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 646 | |
| 647 | addr = dma_map_single(dev, buffer_start, |
| 648 | skb_tail_pointer(skb) - buffer_start, |
Ioana Radulescu | 1e5fa9e | 2017-05-24 07:13:28 -0500 | [diff] [blame] | 649 | DMA_BIDIRECTIONAL); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 650 | if (unlikely(dma_mapping_error(dev, addr))) |
| 651 | return -ENOMEM; |
| 652 | |
| 653 | dpaa2_fd_set_addr(fd, addr); |
| 654 | dpaa2_fd_set_offset(fd, (u16)(skb->data - buffer_start)); |
| 655 | dpaa2_fd_set_len(fd, skb->len); |
| 656 | dpaa2_fd_set_format(fd, dpaa2_fd_single); |
Ioana Radulescu | b948c8c | 2018-10-12 16:27:40 +0000 | [diff] [blame] | 657 | dpaa2_fd_set_ctrl(fd, FD_CTRL_PTA); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 658 | |
Ioana Radulescu | 859f998 | 2018-04-26 18:23:47 +0800 | [diff] [blame] | 659 | if (priv->tx_tstamp && skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) |
| 660 | enable_tx_tstamp(fd, buffer_start); |
| 661 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 662 | return 0; |
| 663 | } |
| 664 | |
| 665 | /* FD freeing routine on the Tx path |
| 666 | * |
| 667 | * DMA-unmap and free FD and possibly SGT buffer allocated on Tx. The skb |
| 668 | * back-pointed to is also freed. |
| 669 | * This can be called either from dpaa2_eth_tx_conf() or on the error path of |
| 670 | * dpaa2_eth_tx(). |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 671 | */ |
| 672 | static void free_tx_fd(const struct dpaa2_eth_priv *priv, |
Ioana Radulescu | d678be1 | 2019-03-01 17:47:24 +0000 | [diff] [blame] | 673 | struct dpaa2_eth_fq *fq, |
Ioana Ciocoi Radulescu | 0723a3a | 2019-02-04 17:00:35 +0000 | [diff] [blame] | 674 | const struct dpaa2_fd *fd, bool in_napi) |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 675 | { |
| 676 | struct device *dev = priv->net_dev->dev.parent; |
| 677 | dma_addr_t fd_addr; |
Ioana Radulescu | d678be1 | 2019-03-01 17:47:24 +0000 | [diff] [blame] | 678 | struct sk_buff *skb = NULL; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 679 | unsigned char *buffer_start; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 680 | struct dpaa2_eth_swa *swa; |
| 681 | u8 fd_format = dpaa2_fd_get_format(fd); |
Ioana Radulescu | d678be1 | 2019-03-01 17:47:24 +0000 | [diff] [blame] | 682 | u32 fd_len = dpaa2_fd_get_len(fd); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 683 | |
| 684 | fd_addr = dpaa2_fd_get_addr(fd); |
Ioana Radulescu | e3fdf6b | 2019-03-01 17:47:23 +0000 | [diff] [blame] | 685 | buffer_start = dpaa2_iova_to_virt(priv->iommu_domain, fd_addr); |
| 686 | swa = (struct dpaa2_eth_swa *)buffer_start; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 687 | |
| 688 | if (fd_format == dpaa2_fd_single) { |
Ioana Radulescu | d678be1 | 2019-03-01 17:47:24 +0000 | [diff] [blame] | 689 | if (swa->type == DPAA2_ETH_SWA_SINGLE) { |
| 690 | skb = swa->single.skb; |
| 691 | /* Accessing the skb buffer is safe before dma unmap, |
| 692 | * because we didn't map the actual skb shell. |
| 693 | */ |
| 694 | dma_unmap_single(dev, fd_addr, |
| 695 | skb_tail_pointer(skb) - buffer_start, |
| 696 | DMA_BIDIRECTIONAL); |
| 697 | } else { |
| 698 | WARN_ONCE(swa->type != DPAA2_ETH_SWA_XDP, "Wrong SWA type"); |
| 699 | dma_unmap_single(dev, fd_addr, swa->xdp.dma_size, |
| 700 | DMA_BIDIRECTIONAL); |
| 701 | } |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 702 | } else if (fd_format == dpaa2_fd_sg) { |
Ioana Radulescu | e3fdf6b | 2019-03-01 17:47:23 +0000 | [diff] [blame] | 703 | skb = swa->sg.skb; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 704 | |
| 705 | /* Unmap the scatterlist */ |
Ioana Radulescu | e3fdf6b | 2019-03-01 17:47:23 +0000 | [diff] [blame] | 706 | dma_unmap_sg(dev, swa->sg.scl, swa->sg.num_sg, |
| 707 | DMA_BIDIRECTIONAL); |
| 708 | kfree(swa->sg.scl); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 709 | |
| 710 | /* Unmap the SGT buffer */ |
Ioana Radulescu | e3fdf6b | 2019-03-01 17:47:23 +0000 | [diff] [blame] | 711 | dma_unmap_single(dev, fd_addr, swa->sg.sgt_size, |
Ioana Radulescu | b2718e6 | 2018-03-23 08:44:11 -0500 | [diff] [blame] | 712 | DMA_BIDIRECTIONAL); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 713 | } else { |
Ioana Radulescu | 2b7c86e | 2017-12-08 06:47:56 -0600 | [diff] [blame] | 714 | netdev_dbg(priv->net_dev, "Invalid FD format\n"); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 715 | return; |
| 716 | } |
| 717 | |
Ioana Radulescu | d678be1 | 2019-03-01 17:47:24 +0000 | [diff] [blame] | 718 | if (swa->type != DPAA2_ETH_SWA_XDP && in_napi) { |
| 719 | fq->dq_frames++; |
| 720 | fq->dq_bytes += fd_len; |
| 721 | } |
| 722 | |
| 723 | if (swa->type == DPAA2_ETH_SWA_XDP) { |
| 724 | xdp_return_frame(swa->xdp.xdpf); |
| 725 | return; |
| 726 | } |
| 727 | |
Ioana Radulescu | 859f998 | 2018-04-26 18:23:47 +0800 | [diff] [blame] | 728 | /* Get the timestamp value */ |
| 729 | if (priv->tx_tstamp && skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) { |
| 730 | struct skb_shared_hwtstamps shhwtstamps; |
Ioana Radulescu | e3fdf6b | 2019-03-01 17:47:23 +0000 | [diff] [blame] | 731 | __le64 *ts = dpaa2_get_ts(buffer_start, true); |
Ioana Radulescu | 859f998 | 2018-04-26 18:23:47 +0800 | [diff] [blame] | 732 | u64 ns; |
| 733 | |
| 734 | memset(&shhwtstamps, 0, sizeof(shhwtstamps)); |
| 735 | |
| 736 | ns = DPAA2_PTP_CLK_PERIOD_NS * le64_to_cpup(ts); |
| 737 | shhwtstamps.hwtstamp = ns_to_ktime(ns); |
| 738 | skb_tstamp_tx(skb, &shhwtstamps); |
| 739 | } |
| 740 | |
Ioana Radulescu | 6a9bbe5 | 2018-03-14 15:04:51 -0500 | [diff] [blame] | 741 | /* Free SGT buffer allocated on tx */ |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 742 | if (fd_format != dpaa2_fd_single) |
Ioana Radulescu | e3fdf6b | 2019-03-01 17:47:23 +0000 | [diff] [blame] | 743 | skb_free_frag(buffer_start); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 744 | |
| 745 | /* Move on with skb release */ |
Ioana Ciocoi Radulescu | 0723a3a | 2019-02-04 17:00:35 +0000 | [diff] [blame] | 746 | napi_consume_skb(skb, in_napi); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 747 | } |
| 748 | |
Ioana Radulescu | c433db4 | 2017-06-06 10:00:26 -0500 | [diff] [blame] | 749 | static netdev_tx_t dpaa2_eth_tx(struct sk_buff *skb, struct net_device *net_dev) |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 750 | { |
| 751 | struct dpaa2_eth_priv *priv = netdev_priv(net_dev); |
| 752 | struct dpaa2_fd fd; |
| 753 | struct rtnl_link_stats64 *percpu_stats; |
Ioana Radulescu | 85047ab | 2017-04-28 04:50:31 -0500 | [diff] [blame] | 754 | struct dpaa2_eth_drv_stats *percpu_extras; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 755 | struct dpaa2_eth_fq *fq; |
Ioana Ciocoi Radulescu | 569dac6 | 2018-11-14 11:48:36 +0000 | [diff] [blame] | 756 | struct netdev_queue *nq; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 757 | u16 queue_mapping; |
Ioana Radulescu | 18c2146 | 2017-12-08 06:47:57 -0600 | [diff] [blame] | 758 | unsigned int needed_headroom; |
Ioana Ciocoi Radulescu | 569dac6 | 2018-11-14 11:48:36 +0000 | [diff] [blame] | 759 | u32 fd_len; |
Ioana Radulescu | ab1e6de | 2019-06-11 14:50:03 +0300 | [diff] [blame] | 760 | u8 prio = 0; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 761 | int err, i; |
| 762 | |
| 763 | percpu_stats = this_cpu_ptr(priv->percpu_stats); |
Ioana Radulescu | 85047ab | 2017-04-28 04:50:31 -0500 | [diff] [blame] | 764 | percpu_extras = this_cpu_ptr(priv->percpu_extras); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 765 | |
Ioana Radulescu | 18c2146 | 2017-12-08 06:47:57 -0600 | [diff] [blame] | 766 | needed_headroom = dpaa2_eth_needed_headroom(priv, skb); |
| 767 | if (skb_headroom(skb) < needed_headroom) { |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 768 | struct sk_buff *ns; |
| 769 | |
Ioana Radulescu | 18c2146 | 2017-12-08 06:47:57 -0600 | [diff] [blame] | 770 | ns = skb_realloc_headroom(skb, needed_headroom); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 771 | if (unlikely(!ns)) { |
| 772 | percpu_stats->tx_dropped++; |
| 773 | goto err_alloc_headroom; |
| 774 | } |
Ioana Radulescu | 6662b5e | 2017-12-08 06:47:55 -0600 | [diff] [blame] | 775 | percpu_extras->tx_reallocs++; |
Ioana Radulescu | 859f998 | 2018-04-26 18:23:47 +0800 | [diff] [blame] | 776 | |
| 777 | if (skb->sk) |
| 778 | skb_set_owner_w(ns, skb->sk); |
| 779 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 780 | dev_kfree_skb(skb); |
| 781 | skb = ns; |
| 782 | } |
| 783 | |
| 784 | /* We'll be holding a back-reference to the skb until Tx Confirmation; |
| 785 | * we don't want that overwritten by a concurrent Tx with a cloned skb. |
| 786 | */ |
| 787 | skb = skb_unshare(skb, GFP_ATOMIC); |
| 788 | if (unlikely(!skb)) { |
| 789 | /* skb_unshare() has already freed the skb */ |
| 790 | percpu_stats->tx_dropped++; |
| 791 | return NETDEV_TX_OK; |
| 792 | } |
| 793 | |
| 794 | /* Setup the FD fields */ |
| 795 | memset(&fd, 0, sizeof(fd)); |
| 796 | |
Ioana Radulescu | 85047ab | 2017-04-28 04:50:31 -0500 | [diff] [blame] | 797 | if (skb_is_nonlinear(skb)) { |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 798 | err = build_sg_fd(priv, skb, &fd); |
Ioana Radulescu | 85047ab | 2017-04-28 04:50:31 -0500 | [diff] [blame] | 799 | percpu_extras->tx_sg_frames++; |
| 800 | percpu_extras->tx_sg_bytes += skb->len; |
| 801 | } else { |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 802 | err = build_single_fd(priv, skb, &fd); |
Ioana Radulescu | 85047ab | 2017-04-28 04:50:31 -0500 | [diff] [blame] | 803 | } |
| 804 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 805 | if (unlikely(err)) { |
| 806 | percpu_stats->tx_dropped++; |
| 807 | goto err_build_fd; |
| 808 | } |
| 809 | |
Ioana Radulescu | 5636187 | 2017-04-28 04:50:32 -0500 | [diff] [blame] | 810 | /* Tracing point */ |
| 811 | trace_dpaa2_tx_fd(net_dev, &fd); |
| 812 | |
Ioana Radulescu | 537336c | 2017-12-21 06:33:20 -0600 | [diff] [blame] | 813 | /* TxConf FQ selection relies on queue id from the stack. |
| 814 | * In case of a forwarded frame from another DPNI interface, we choose |
| 815 | * a queue affined to the same core that processed the Rx frame |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 816 | */ |
Ioana Radulescu | 537336c | 2017-12-21 06:33:20 -0600 | [diff] [blame] | 817 | queue_mapping = skb_get_queue_mapping(skb); |
Ioana Radulescu | ab1e6de | 2019-06-11 14:50:03 +0300 | [diff] [blame] | 818 | |
| 819 | if (net_dev->num_tc) { |
| 820 | prio = netdev_txq_to_tc(net_dev, queue_mapping); |
| 821 | /* Hardware interprets priority level 0 as being the highest, |
| 822 | * so we need to do a reverse mapping to the netdev tc index |
| 823 | */ |
| 824 | prio = net_dev->num_tc - prio - 1; |
| 825 | /* We have only one FQ array entry for all Tx hardware queues |
| 826 | * with the same flow id (but different priority levels) |
| 827 | */ |
| 828 | queue_mapping %= dpaa2_eth_queue_count(priv); |
| 829 | } |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 830 | fq = &priv->fq[queue_mapping]; |
Ioana Ciornei | 8c838f5 | 2019-03-25 13:06:22 +0000 | [diff] [blame] | 831 | |
| 832 | fd_len = dpaa2_fd_get_len(&fd); |
| 833 | nq = netdev_get_tx_queue(net_dev, queue_mapping); |
| 834 | netdev_tx_sent_queue(nq, fd_len); |
| 835 | |
| 836 | /* Everything that happens after this enqueues might race with |
| 837 | * the Tx confirmation callback for this frame |
| 838 | */ |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 839 | for (i = 0; i < DPAA2_ETH_ENQUEUE_RETRIES; i++) { |
Ioana Radulescu | ab1e6de | 2019-06-11 14:50:03 +0300 | [diff] [blame] | 840 | err = priv->enqueue(priv, fq, &fd, prio); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 841 | if (err != -EBUSY) |
| 842 | break; |
| 843 | } |
Ioana Radulescu | 85047ab | 2017-04-28 04:50:31 -0500 | [diff] [blame] | 844 | percpu_extras->tx_portal_busy += i; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 845 | if (unlikely(err < 0)) { |
| 846 | percpu_stats->tx_errors++; |
| 847 | /* Clean up everything, including freeing the skb */ |
Ioana Radulescu | d678be1 | 2019-03-01 17:47:24 +0000 | [diff] [blame] | 848 | free_tx_fd(priv, fq, &fd, false); |
Ioana Ciornei | 8c838f5 | 2019-03-25 13:06:22 +0000 | [diff] [blame] | 849 | netdev_tx_completed_queue(nq, 1, fd_len); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 850 | } else { |
| 851 | percpu_stats->tx_packets++; |
Ioana Ciocoi Radulescu | 569dac6 | 2018-11-14 11:48:36 +0000 | [diff] [blame] | 852 | percpu_stats->tx_bytes += fd_len; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 853 | } |
| 854 | |
| 855 | return NETDEV_TX_OK; |
| 856 | |
| 857 | err_build_fd: |
| 858 | err_alloc_headroom: |
| 859 | dev_kfree_skb(skb); |
| 860 | |
| 861 | return NETDEV_TX_OK; |
| 862 | } |
| 863 | |
| 864 | /* Tx confirmation frame processing routine */ |
| 865 | static void dpaa2_eth_tx_conf(struct dpaa2_eth_priv *priv, |
Ioana Ciornei | b00c898 | 2018-10-12 16:27:38 +0000 | [diff] [blame] | 866 | struct dpaa2_eth_channel *ch __always_unused, |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 867 | const struct dpaa2_fd *fd, |
Ioana Ciocoi Radulescu | 569dac6 | 2018-11-14 11:48:36 +0000 | [diff] [blame] | 868 | struct dpaa2_eth_fq *fq) |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 869 | { |
| 870 | struct rtnl_link_stats64 *percpu_stats; |
Ioana Radulescu | 85047ab | 2017-04-28 04:50:31 -0500 | [diff] [blame] | 871 | struct dpaa2_eth_drv_stats *percpu_extras; |
Ioana Ciocoi Radulescu | 569dac6 | 2018-11-14 11:48:36 +0000 | [diff] [blame] | 872 | u32 fd_len = dpaa2_fd_get_len(fd); |
Ioana Radulescu | 39163c0 | 2017-06-06 10:00:39 -0500 | [diff] [blame] | 873 | u32 fd_errors; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 874 | |
Ioana Radulescu | 5636187 | 2017-04-28 04:50:32 -0500 | [diff] [blame] | 875 | /* Tracing point */ |
| 876 | trace_dpaa2_tx_conf_fd(priv->net_dev, fd); |
| 877 | |
Ioana Radulescu | 85047ab | 2017-04-28 04:50:31 -0500 | [diff] [blame] | 878 | percpu_extras = this_cpu_ptr(priv->percpu_extras); |
| 879 | percpu_extras->tx_conf_frames++; |
Ioana Ciocoi Radulescu | 569dac6 | 2018-11-14 11:48:36 +0000 | [diff] [blame] | 880 | percpu_extras->tx_conf_bytes += fd_len; |
| 881 | |
Ioana Radulescu | 39163c0 | 2017-06-06 10:00:39 -0500 | [diff] [blame] | 882 | /* Check frame errors in the FD field */ |
| 883 | fd_errors = dpaa2_fd_get_ctrl(fd) & DPAA2_FD_TX_ERR_MASK; |
Ioana Radulescu | d678be1 | 2019-03-01 17:47:24 +0000 | [diff] [blame] | 884 | free_tx_fd(priv, fq, fd, true); |
Ioana Radulescu | 39163c0 | 2017-06-06 10:00:39 -0500 | [diff] [blame] | 885 | |
| 886 | if (likely(!fd_errors)) |
| 887 | return; |
| 888 | |
Ioana Radulescu | 2b7c86e | 2017-12-08 06:47:56 -0600 | [diff] [blame] | 889 | if (net_ratelimit()) |
| 890 | netdev_dbg(priv->net_dev, "TX frame FD error: 0x%08x\n", |
| 891 | fd_errors); |
| 892 | |
Ioana Radulescu | 39163c0 | 2017-06-06 10:00:39 -0500 | [diff] [blame] | 893 | percpu_stats = this_cpu_ptr(priv->percpu_stats); |
| 894 | /* Tx-conf logically pertains to the egress path. */ |
| 895 | percpu_stats->tx_errors++; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 896 | } |
| 897 | |
| 898 | static int set_rx_csum(struct dpaa2_eth_priv *priv, bool enable) |
| 899 | { |
| 900 | int err; |
| 901 | |
| 902 | err = dpni_set_offload(priv->mc_io, 0, priv->mc_token, |
| 903 | DPNI_OFF_RX_L3_CSUM, enable); |
| 904 | if (err) { |
| 905 | netdev_err(priv->net_dev, |
| 906 | "dpni_set_offload(RX_L3_CSUM) failed\n"); |
| 907 | return err; |
| 908 | } |
| 909 | |
| 910 | err = dpni_set_offload(priv->mc_io, 0, priv->mc_token, |
| 911 | DPNI_OFF_RX_L4_CSUM, enable); |
| 912 | if (err) { |
| 913 | netdev_err(priv->net_dev, |
| 914 | "dpni_set_offload(RX_L4_CSUM) failed\n"); |
| 915 | return err; |
| 916 | } |
| 917 | |
| 918 | return 0; |
| 919 | } |
| 920 | |
| 921 | static int set_tx_csum(struct dpaa2_eth_priv *priv, bool enable) |
| 922 | { |
| 923 | int err; |
| 924 | |
| 925 | err = dpni_set_offload(priv->mc_io, 0, priv->mc_token, |
| 926 | DPNI_OFF_TX_L3_CSUM, enable); |
| 927 | if (err) { |
| 928 | netdev_err(priv->net_dev, "dpni_set_offload(TX_L3_CSUM) failed\n"); |
| 929 | return err; |
| 930 | } |
| 931 | |
| 932 | err = dpni_set_offload(priv->mc_io, 0, priv->mc_token, |
| 933 | DPNI_OFF_TX_L4_CSUM, enable); |
| 934 | if (err) { |
| 935 | netdev_err(priv->net_dev, "dpni_set_offload(TX_L4_CSUM) failed\n"); |
| 936 | return err; |
| 937 | } |
| 938 | |
| 939 | return 0; |
| 940 | } |
| 941 | |
| 942 | /* Perform a single release command to add buffers |
| 943 | * to the specified buffer pool |
| 944 | */ |
Ioana Radulescu | 7ec0596 | 2018-01-05 05:04:32 -0600 | [diff] [blame] | 945 | static int add_bufs(struct dpaa2_eth_priv *priv, |
| 946 | struct dpaa2_eth_channel *ch, u16 bpid) |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 947 | { |
| 948 | struct device *dev = priv->net_dev->dev.parent; |
| 949 | u64 buf_array[DPAA2_ETH_BUFS_PER_CMD]; |
Ioana Ciocoi Radulescu | 27c8748 | 2019-02-04 17:00:35 +0000 | [diff] [blame] | 950 | struct page *page; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 951 | dma_addr_t addr; |
Ioana Radulescu | 87eb55e | 2017-10-11 08:29:43 -0500 | [diff] [blame] | 952 | int i, err; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 953 | |
| 954 | for (i = 0; i < DPAA2_ETH_BUFS_PER_CMD; i++) { |
| 955 | /* Allocate buffer visible to WRIOP + skb shared info + |
| 956 | * alignment padding |
| 957 | */ |
Ioana Ciocoi Radulescu | 27c8748 | 2019-02-04 17:00:35 +0000 | [diff] [blame] | 958 | /* allocate one page for each Rx buffer. WRIOP sees |
| 959 | * the entire page except for a tailroom reserved for |
| 960 | * skb shared info |
| 961 | */ |
| 962 | page = dev_alloc_pages(0); |
| 963 | if (!page) |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 964 | goto err_alloc; |
| 965 | |
Ioana Ciocoi Radulescu | 27c8748 | 2019-02-04 17:00:35 +0000 | [diff] [blame] | 966 | addr = dma_map_page(dev, page, 0, DPAA2_ETH_RX_BUF_SIZE, |
| 967 | DMA_BIDIRECTIONAL); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 968 | if (unlikely(dma_mapping_error(dev, addr))) |
| 969 | goto err_map; |
| 970 | |
| 971 | buf_array[i] = addr; |
Ioana Radulescu | 5636187 | 2017-04-28 04:50:32 -0500 | [diff] [blame] | 972 | |
| 973 | /* tracing point */ |
| 974 | trace_dpaa2_eth_buf_seed(priv->net_dev, |
Ioana Ciocoi Radulescu | 27c8748 | 2019-02-04 17:00:35 +0000 | [diff] [blame] | 975 | page, DPAA2_ETH_RX_BUF_RAW_SIZE, |
Ioana Radulescu | 5636187 | 2017-04-28 04:50:32 -0500 | [diff] [blame] | 976 | addr, DPAA2_ETH_RX_BUF_SIZE, |
| 977 | bpid); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 978 | } |
| 979 | |
| 980 | release_bufs: |
Ioana Radulescu | 87eb55e | 2017-10-11 08:29:43 -0500 | [diff] [blame] | 981 | /* In case the portal is busy, retry until successful */ |
Ioana Radulescu | 7ec0596 | 2018-01-05 05:04:32 -0600 | [diff] [blame] | 982 | while ((err = dpaa2_io_service_release(ch->dpio, bpid, |
Ioana Radulescu | 87eb55e | 2017-10-11 08:29:43 -0500 | [diff] [blame] | 983 | buf_array, i)) == -EBUSY) |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 984 | cpu_relax(); |
Ioana Radulescu | 87eb55e | 2017-10-11 08:29:43 -0500 | [diff] [blame] | 985 | |
| 986 | /* If release command failed, clean up and bail out; |
| 987 | * not much else we can do about it |
| 988 | */ |
| 989 | if (err) { |
| 990 | free_bufs(priv, buf_array, i); |
| 991 | return 0; |
| 992 | } |
| 993 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 994 | return i; |
| 995 | |
| 996 | err_map: |
Ioana Ciocoi Radulescu | 27c8748 | 2019-02-04 17:00:35 +0000 | [diff] [blame] | 997 | __free_pages(page, 0); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 998 | err_alloc: |
Ioana Radulescu | 87eb55e | 2017-10-11 08:29:43 -0500 | [diff] [blame] | 999 | /* If we managed to allocate at least some buffers, |
| 1000 | * release them to hardware |
| 1001 | */ |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1002 | if (i) |
| 1003 | goto release_bufs; |
| 1004 | |
| 1005 | return 0; |
| 1006 | } |
| 1007 | |
| 1008 | static int seed_pool(struct dpaa2_eth_priv *priv, u16 bpid) |
| 1009 | { |
| 1010 | int i, j; |
| 1011 | int new_count; |
| 1012 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1013 | for (j = 0; j < priv->num_channels; j++) { |
| 1014 | for (i = 0; i < DPAA2_ETH_NUM_BUFS; |
| 1015 | i += DPAA2_ETH_BUFS_PER_CMD) { |
Ioana Radulescu | 7ec0596 | 2018-01-05 05:04:32 -0600 | [diff] [blame] | 1016 | new_count = add_bufs(priv, priv->channel[j], bpid); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1017 | priv->channel[j]->buf_count += new_count; |
| 1018 | |
| 1019 | if (new_count < DPAA2_ETH_BUFS_PER_CMD) { |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1020 | return -ENOMEM; |
| 1021 | } |
| 1022 | } |
| 1023 | } |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1024 | |
| 1025 | return 0; |
| 1026 | } |
| 1027 | |
| 1028 | /** |
| 1029 | * Drain the specified number of buffers from the DPNI's private buffer pool. |
| 1030 | * @count must not exceeed DPAA2_ETH_BUFS_PER_CMD |
| 1031 | */ |
| 1032 | static void drain_bufs(struct dpaa2_eth_priv *priv, int count) |
| 1033 | { |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1034 | u64 buf_array[DPAA2_ETH_BUFS_PER_CMD]; |
Ioana Radulescu | 87eb55e | 2017-10-11 08:29:43 -0500 | [diff] [blame] | 1035 | int ret; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1036 | |
| 1037 | do { |
Ioana Radulescu | 05fa39c | 2017-06-06 10:00:37 -0500 | [diff] [blame] | 1038 | ret = dpaa2_io_service_acquire(NULL, priv->bpid, |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1039 | buf_array, count); |
| 1040 | if (ret < 0) { |
| 1041 | netdev_err(priv->net_dev, "dpaa2_io_service_acquire() failed\n"); |
| 1042 | return; |
| 1043 | } |
Ioana Radulescu | 87eb55e | 2017-10-11 08:29:43 -0500 | [diff] [blame] | 1044 | free_bufs(priv, buf_array, ret); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1045 | } while (ret); |
| 1046 | } |
| 1047 | |
| 1048 | static void drain_pool(struct dpaa2_eth_priv *priv) |
| 1049 | { |
| 1050 | int i; |
| 1051 | |
| 1052 | drain_bufs(priv, DPAA2_ETH_BUFS_PER_CMD); |
| 1053 | drain_bufs(priv, 1); |
| 1054 | |
| 1055 | for (i = 0; i < priv->num_channels; i++) |
| 1056 | priv->channel[i]->buf_count = 0; |
| 1057 | } |
| 1058 | |
| 1059 | /* Function is called from softirq context only, so we don't need to guard |
| 1060 | * the access to percpu count |
| 1061 | */ |
| 1062 | static int refill_pool(struct dpaa2_eth_priv *priv, |
| 1063 | struct dpaa2_eth_channel *ch, |
| 1064 | u16 bpid) |
| 1065 | { |
| 1066 | int new_count; |
| 1067 | |
| 1068 | if (likely(ch->buf_count >= DPAA2_ETH_REFILL_THRESH)) |
| 1069 | return 0; |
| 1070 | |
| 1071 | do { |
Ioana Radulescu | 7ec0596 | 2018-01-05 05:04:32 -0600 | [diff] [blame] | 1072 | new_count = add_bufs(priv, ch, bpid); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1073 | if (unlikely(!new_count)) { |
| 1074 | /* Out of memory; abort for now, we'll try later on */ |
| 1075 | break; |
| 1076 | } |
| 1077 | ch->buf_count += new_count; |
| 1078 | } while (ch->buf_count < DPAA2_ETH_NUM_BUFS); |
| 1079 | |
| 1080 | if (unlikely(ch->buf_count < DPAA2_ETH_NUM_BUFS)) |
| 1081 | return -ENOMEM; |
| 1082 | |
| 1083 | return 0; |
| 1084 | } |
| 1085 | |
| 1086 | static int pull_channel(struct dpaa2_eth_channel *ch) |
| 1087 | { |
| 1088 | int err; |
Ioana Radulescu | 85047ab | 2017-04-28 04:50:31 -0500 | [diff] [blame] | 1089 | int dequeues = -1; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1090 | |
| 1091 | /* Retry while portal is busy */ |
| 1092 | do { |
Ioana Radulescu | 7ec0596 | 2018-01-05 05:04:32 -0600 | [diff] [blame] | 1093 | err = dpaa2_io_service_pull_channel(ch->dpio, ch->ch_id, |
| 1094 | ch->store); |
Ioana Radulescu | 85047ab | 2017-04-28 04:50:31 -0500 | [diff] [blame] | 1095 | dequeues++; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1096 | cpu_relax(); |
| 1097 | } while (err == -EBUSY); |
| 1098 | |
Ioana Radulescu | 85047ab | 2017-04-28 04:50:31 -0500 | [diff] [blame] | 1099 | ch->stats.dequeue_portal_busy += dequeues; |
| 1100 | if (unlikely(err)) |
| 1101 | ch->stats.pull_err++; |
| 1102 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1103 | return err; |
| 1104 | } |
| 1105 | |
| 1106 | /* NAPI poll routine |
| 1107 | * |
| 1108 | * Frames are dequeued from the QMan channel associated with this NAPI context. |
| 1109 | * Rx, Tx confirmation and (if configured) Rx error frames all count |
| 1110 | * towards the NAPI budget. |
| 1111 | */ |
| 1112 | static int dpaa2_eth_poll(struct napi_struct *napi, int budget) |
| 1113 | { |
| 1114 | struct dpaa2_eth_channel *ch; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1115 | struct dpaa2_eth_priv *priv; |
Ioana Ciocoi Radulescu | 68049a5 | 2018-10-08 14:16:31 +0000 | [diff] [blame] | 1116 | int rx_cleaned = 0, txconf_cleaned = 0; |
Ioana Ciocoi Radulescu | 569dac6 | 2018-11-14 11:48:36 +0000 | [diff] [blame] | 1117 | struct dpaa2_eth_fq *fq, *txc_fq = NULL; |
| 1118 | struct netdev_queue *nq; |
| 1119 | int store_cleaned, work_done; |
Ioana Ciornei | 0a25d92 | 2019-03-25 13:42:39 +0000 | [diff] [blame] | 1120 | struct list_head rx_list; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1121 | int err; |
| 1122 | |
| 1123 | ch = container_of(napi, struct dpaa2_eth_channel, napi); |
Ioana Radulescu | d678be1 | 2019-03-01 17:47:24 +0000 | [diff] [blame] | 1124 | ch->xdp.res = 0; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1125 | priv = ch->priv; |
| 1126 | |
Ioana Ciornei | 0a25d92 | 2019-03-25 13:42:39 +0000 | [diff] [blame] | 1127 | INIT_LIST_HEAD(&rx_list); |
| 1128 | ch->rx_list = &rx_list; |
| 1129 | |
Ioana Ciocoi Radulescu | 68049a5 | 2018-10-08 14:16:31 +0000 | [diff] [blame] | 1130 | do { |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1131 | err = pull_channel(ch); |
| 1132 | if (unlikely(err)) |
| 1133 | break; |
| 1134 | |
| 1135 | /* Refill pool if appropriate */ |
Ioana Radulescu | 05fa39c | 2017-06-06 10:00:37 -0500 | [diff] [blame] | 1136 | refill_pool(priv, ch, priv->bpid); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1137 | |
Ioana Ciocoi Radulescu | 569dac6 | 2018-11-14 11:48:36 +0000 | [diff] [blame] | 1138 | store_cleaned = consume_frames(ch, &fq); |
| 1139 | if (!store_cleaned) |
| 1140 | break; |
| 1141 | if (fq->type == DPAA2_RX_FQ) { |
Ioana Ciocoi Radulescu | 68049a5 | 2018-10-08 14:16:31 +0000 | [diff] [blame] | 1142 | rx_cleaned += store_cleaned; |
Ioana Ciocoi Radulescu | 569dac6 | 2018-11-14 11:48:36 +0000 | [diff] [blame] | 1143 | } else { |
Ioana Ciocoi Radulescu | 68049a5 | 2018-10-08 14:16:31 +0000 | [diff] [blame] | 1144 | txconf_cleaned += store_cleaned; |
Ioana Ciocoi Radulescu | 569dac6 | 2018-11-14 11:48:36 +0000 | [diff] [blame] | 1145 | /* We have a single Tx conf FQ on this channel */ |
| 1146 | txc_fq = fq; |
| 1147 | } |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1148 | |
Ioana Ciocoi Radulescu | 68049a5 | 2018-10-08 14:16:31 +0000 | [diff] [blame] | 1149 | /* If we either consumed the whole NAPI budget with Rx frames |
| 1150 | * or we reached the Tx confirmations threshold, we're done. |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1151 | */ |
Ioana Ciocoi Radulescu | 68049a5 | 2018-10-08 14:16:31 +0000 | [diff] [blame] | 1152 | if (rx_cleaned >= budget || |
Ioana Ciocoi Radulescu | 569dac6 | 2018-11-14 11:48:36 +0000 | [diff] [blame] | 1153 | txconf_cleaned >= DPAA2_ETH_TXCONF_PER_NAPI) { |
| 1154 | work_done = budget; |
| 1155 | goto out; |
| 1156 | } |
Ioana Ciocoi Radulescu | 68049a5 | 2018-10-08 14:16:31 +0000 | [diff] [blame] | 1157 | } while (store_cleaned); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1158 | |
Ioana Ciocoi Radulescu | 68049a5 | 2018-10-08 14:16:31 +0000 | [diff] [blame] | 1159 | /* We didn't consume the entire budget, so finish napi and |
| 1160 | * re-enable data availability notifications |
| 1161 | */ |
| 1162 | napi_complete_done(napi, rx_cleaned); |
| 1163 | do { |
| 1164 | err = dpaa2_io_service_rearm(ch->dpio, &ch->nctx); |
| 1165 | cpu_relax(); |
| 1166 | } while (err == -EBUSY); |
| 1167 | WARN_ONCE(err, "CDAN notifications rearm failed on core %d", |
| 1168 | ch->nctx.desired_cpu); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1169 | |
Ioana Ciocoi Radulescu | 569dac6 | 2018-11-14 11:48:36 +0000 | [diff] [blame] | 1170 | work_done = max(rx_cleaned, 1); |
| 1171 | |
| 1172 | out: |
Ioana Ciornei | 0a25d92 | 2019-03-25 13:42:39 +0000 | [diff] [blame] | 1173 | netif_receive_skb_list(ch->rx_list); |
| 1174 | |
Ioana Radulescu | d678be1 | 2019-03-01 17:47:24 +0000 | [diff] [blame] | 1175 | if (txc_fq && txc_fq->dq_frames) { |
Ioana Ciocoi Radulescu | 569dac6 | 2018-11-14 11:48:36 +0000 | [diff] [blame] | 1176 | nq = netdev_get_tx_queue(priv->net_dev, txc_fq->flowid); |
| 1177 | netdev_tx_completed_queue(nq, txc_fq->dq_frames, |
| 1178 | txc_fq->dq_bytes); |
| 1179 | txc_fq->dq_frames = 0; |
| 1180 | txc_fq->dq_bytes = 0; |
| 1181 | } |
| 1182 | |
Ioana Radulescu | d678be1 | 2019-03-01 17:47:24 +0000 | [diff] [blame] | 1183 | if (ch->xdp.res & XDP_REDIRECT) |
| 1184 | xdp_do_flush_map(); |
| 1185 | |
Ioana Ciocoi Radulescu | 569dac6 | 2018-11-14 11:48:36 +0000 | [diff] [blame] | 1186 | return work_done; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1187 | } |
| 1188 | |
| 1189 | static void enable_ch_napi(struct dpaa2_eth_priv *priv) |
| 1190 | { |
| 1191 | struct dpaa2_eth_channel *ch; |
| 1192 | int i; |
| 1193 | |
| 1194 | for (i = 0; i < priv->num_channels; i++) { |
| 1195 | ch = priv->channel[i]; |
| 1196 | napi_enable(&ch->napi); |
| 1197 | } |
| 1198 | } |
| 1199 | |
| 1200 | static void disable_ch_napi(struct dpaa2_eth_priv *priv) |
| 1201 | { |
| 1202 | struct dpaa2_eth_channel *ch; |
| 1203 | int i; |
| 1204 | |
| 1205 | for (i = 0; i < priv->num_channels; i++) { |
| 1206 | ch = priv->channel[i]; |
| 1207 | napi_disable(&ch->napi); |
| 1208 | } |
| 1209 | } |
| 1210 | |
| 1211 | static int link_state_update(struct dpaa2_eth_priv *priv) |
| 1212 | { |
Ioana Ciornei | 85b7a34 | 2018-10-12 16:27:33 +0000 | [diff] [blame] | 1213 | struct dpni_link_state state = {0}; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1214 | int err; |
| 1215 | |
| 1216 | err = dpni_get_link_state(priv->mc_io, 0, priv->mc_token, &state); |
| 1217 | if (unlikely(err)) { |
| 1218 | netdev_err(priv->net_dev, |
| 1219 | "dpni_get_link_state() failed\n"); |
| 1220 | return err; |
| 1221 | } |
| 1222 | |
| 1223 | /* Chech link state; speed / duplex changes are not treated yet */ |
| 1224 | if (priv->link_state.up == state.up) |
Ioana Radulescu | cce62943 | 2019-08-28 17:08:14 +0300 | [diff] [blame^] | 1225 | goto out; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1226 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1227 | if (state.up) { |
| 1228 | netif_carrier_on(priv->net_dev); |
| 1229 | netif_tx_start_all_queues(priv->net_dev); |
| 1230 | } else { |
| 1231 | netif_tx_stop_all_queues(priv->net_dev); |
| 1232 | netif_carrier_off(priv->net_dev); |
| 1233 | } |
| 1234 | |
Ioana Radulescu | 77160af | 2017-06-06 10:00:28 -0500 | [diff] [blame] | 1235 | netdev_info(priv->net_dev, "Link Event: state %s\n", |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1236 | state.up ? "up" : "down"); |
| 1237 | |
Ioana Radulescu | cce62943 | 2019-08-28 17:08:14 +0300 | [diff] [blame^] | 1238 | out: |
| 1239 | priv->link_state = state; |
| 1240 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1241 | return 0; |
| 1242 | } |
| 1243 | |
| 1244 | static int dpaa2_eth_open(struct net_device *net_dev) |
| 1245 | { |
| 1246 | struct dpaa2_eth_priv *priv = netdev_priv(net_dev); |
| 1247 | int err; |
| 1248 | |
Ioana Radulescu | 05fa39c | 2017-06-06 10:00:37 -0500 | [diff] [blame] | 1249 | err = seed_pool(priv, priv->bpid); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1250 | if (err) { |
| 1251 | /* Not much to do; the buffer pool, though not filled up, |
| 1252 | * may still contain some buffers which would enable us |
| 1253 | * to limp on. |
| 1254 | */ |
| 1255 | 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] | 1256 | priv->dpbp_dev->obj_desc.id, priv->bpid); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1257 | } |
| 1258 | |
| 1259 | /* We'll only start the txqs when the link is actually ready; make sure |
| 1260 | * we don't race against the link up notification, which may come |
| 1261 | * immediately after dpni_enable(); |
| 1262 | */ |
| 1263 | netif_tx_stop_all_queues(net_dev); |
| 1264 | enable_ch_napi(priv); |
| 1265 | /* Also, explicitly set carrier off, otherwise netif_carrier_ok() will |
| 1266 | * return true and cause 'ip link show' to report the LOWER_UP flag, |
| 1267 | * even though the link notification wasn't even received. |
| 1268 | */ |
| 1269 | netif_carrier_off(net_dev); |
| 1270 | |
| 1271 | err = dpni_enable(priv->mc_io, 0, priv->mc_token); |
| 1272 | if (err < 0) { |
| 1273 | netdev_err(net_dev, "dpni_enable() failed\n"); |
| 1274 | goto enable_err; |
| 1275 | } |
| 1276 | |
| 1277 | /* If the DPMAC object has already processed the link up interrupt, |
| 1278 | * we have to learn the link state ourselves. |
| 1279 | */ |
| 1280 | err = link_state_update(priv); |
| 1281 | if (err < 0) { |
| 1282 | netdev_err(net_dev, "Can't update link state\n"); |
| 1283 | goto link_state_err; |
| 1284 | } |
| 1285 | |
| 1286 | return 0; |
| 1287 | |
| 1288 | link_state_err: |
| 1289 | enable_err: |
| 1290 | disable_ch_napi(priv); |
| 1291 | drain_pool(priv); |
| 1292 | return err; |
| 1293 | } |
| 1294 | |
Ioana Ciocoi Radulescu | 68d7431 | 2019-01-16 16:51:44 +0000 | [diff] [blame] | 1295 | /* Total number of in-flight frames on ingress queues */ |
| 1296 | static u32 ingress_fq_count(struct dpaa2_eth_priv *priv) |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1297 | { |
Ioana Ciocoi Radulescu | 68d7431 | 2019-01-16 16:51:44 +0000 | [diff] [blame] | 1298 | struct dpaa2_eth_fq *fq; |
| 1299 | u32 fcnt = 0, bcnt = 0, total = 0; |
| 1300 | int i, err; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1301 | |
Ioana Ciocoi Radulescu | 68d7431 | 2019-01-16 16:51:44 +0000 | [diff] [blame] | 1302 | for (i = 0; i < priv->num_fqs; i++) { |
| 1303 | fq = &priv->fq[i]; |
| 1304 | err = dpaa2_io_query_fq_count(NULL, fq->fqid, &fcnt, &bcnt); |
| 1305 | if (err) { |
| 1306 | netdev_warn(priv->net_dev, "query_fq_count failed"); |
| 1307 | break; |
| 1308 | } |
| 1309 | total += fcnt; |
| 1310 | } |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1311 | |
| 1312 | return total; |
| 1313 | } |
| 1314 | |
Ioana Ciocoi Radulescu | 68d7431 | 2019-01-16 16:51:44 +0000 | [diff] [blame] | 1315 | static void wait_for_fq_empty(struct dpaa2_eth_priv *priv) |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1316 | { |
Ioana Ciocoi Radulescu | 68d7431 | 2019-01-16 16:51:44 +0000 | [diff] [blame] | 1317 | int retries = 10; |
| 1318 | u32 pending; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1319 | |
Ioana Ciocoi Radulescu | 68d7431 | 2019-01-16 16:51:44 +0000 | [diff] [blame] | 1320 | do { |
| 1321 | pending = ingress_fq_count(priv); |
| 1322 | if (pending) |
| 1323 | msleep(100); |
| 1324 | } while (pending && --retries); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1325 | } |
| 1326 | |
| 1327 | static int dpaa2_eth_stop(struct net_device *net_dev) |
| 1328 | { |
| 1329 | struct dpaa2_eth_priv *priv = netdev_priv(net_dev); |
Ioana Ciornei | 85b7a34 | 2018-10-12 16:27:33 +0000 | [diff] [blame] | 1330 | int dpni_enabled = 0; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1331 | int retries = 10; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1332 | |
| 1333 | netif_tx_stop_all_queues(net_dev); |
| 1334 | netif_carrier_off(net_dev); |
| 1335 | |
Ioana Ciocoi Radulescu | 68d7431 | 2019-01-16 16:51:44 +0000 | [diff] [blame] | 1336 | /* On dpni_disable(), the MC firmware will: |
| 1337 | * - stop MAC Rx and wait for all Rx frames to be enqueued to software |
| 1338 | * - cut off WRIOP dequeues from egress FQs and wait until transmission |
| 1339 | * of all in flight Tx frames is finished (and corresponding Tx conf |
| 1340 | * frames are enqueued back to software) |
| 1341 | * |
| 1342 | * Before calling dpni_disable(), we wait for all Tx frames to arrive |
| 1343 | * on WRIOP. After it finishes, wait until all remaining frames on Rx |
| 1344 | * and Tx conf queues are consumed on NAPI poll. |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1345 | */ |
Ioana Ciocoi Radulescu | 68d7431 | 2019-01-16 16:51:44 +0000 | [diff] [blame] | 1346 | msleep(500); |
| 1347 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1348 | do { |
| 1349 | dpni_disable(priv->mc_io, 0, priv->mc_token); |
| 1350 | dpni_is_enabled(priv->mc_io, 0, priv->mc_token, &dpni_enabled); |
| 1351 | if (dpni_enabled) |
| 1352 | /* Allow the hardware some slack */ |
| 1353 | msleep(100); |
| 1354 | } while (dpni_enabled && --retries); |
| 1355 | if (!retries) { |
| 1356 | netdev_warn(net_dev, "Retry count exceeded disabling DPNI\n"); |
| 1357 | /* Must go on and disable NAPI nonetheless, so we don't crash at |
| 1358 | * the next "ifconfig up" |
| 1359 | */ |
| 1360 | } |
| 1361 | |
Ioana Ciocoi Radulescu | 68d7431 | 2019-01-16 16:51:44 +0000 | [diff] [blame] | 1362 | wait_for_fq_empty(priv); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1363 | disable_ch_napi(priv); |
| 1364 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1365 | /* Empty the buffer pool */ |
| 1366 | drain_pool(priv); |
| 1367 | |
| 1368 | return 0; |
| 1369 | } |
| 1370 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1371 | static int dpaa2_eth_set_addr(struct net_device *net_dev, void *addr) |
| 1372 | { |
| 1373 | struct dpaa2_eth_priv *priv = netdev_priv(net_dev); |
| 1374 | struct device *dev = net_dev->dev.parent; |
| 1375 | int err; |
| 1376 | |
| 1377 | err = eth_mac_addr(net_dev, addr); |
| 1378 | if (err < 0) { |
| 1379 | dev_err(dev, "eth_mac_addr() failed (%d)\n", err); |
| 1380 | return err; |
| 1381 | } |
| 1382 | |
| 1383 | err = dpni_set_primary_mac_addr(priv->mc_io, 0, priv->mc_token, |
| 1384 | net_dev->dev_addr); |
| 1385 | if (err) { |
| 1386 | dev_err(dev, "dpni_set_primary_mac_addr() failed (%d)\n", err); |
| 1387 | return err; |
| 1388 | } |
| 1389 | |
| 1390 | return 0; |
| 1391 | } |
| 1392 | |
| 1393 | /** Fill in counters maintained by the GPP driver. These may be different from |
| 1394 | * the hardware counters obtained by ethtool. |
| 1395 | */ |
Ioana Radulescu | acbff8e | 2017-06-06 10:00:24 -0500 | [diff] [blame] | 1396 | static void dpaa2_eth_get_stats(struct net_device *net_dev, |
| 1397 | struct rtnl_link_stats64 *stats) |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1398 | { |
| 1399 | struct dpaa2_eth_priv *priv = netdev_priv(net_dev); |
| 1400 | struct rtnl_link_stats64 *percpu_stats; |
| 1401 | u64 *cpustats; |
| 1402 | u64 *netstats = (u64 *)stats; |
| 1403 | int i, j; |
| 1404 | int num = sizeof(struct rtnl_link_stats64) / sizeof(u64); |
| 1405 | |
| 1406 | for_each_possible_cpu(i) { |
| 1407 | percpu_stats = per_cpu_ptr(priv->percpu_stats, i); |
| 1408 | cpustats = (u64 *)percpu_stats; |
| 1409 | for (j = 0; j < num; j++) |
| 1410 | netstats[j] += cpustats[j]; |
| 1411 | } |
| 1412 | } |
| 1413 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1414 | /* Copy mac unicast addresses from @net_dev to @priv. |
| 1415 | * Its sole purpose is to make dpaa2_eth_set_rx_mode() more readable. |
| 1416 | */ |
| 1417 | static void add_uc_hw_addr(const struct net_device *net_dev, |
| 1418 | struct dpaa2_eth_priv *priv) |
| 1419 | { |
| 1420 | struct netdev_hw_addr *ha; |
| 1421 | int err; |
| 1422 | |
| 1423 | netdev_for_each_uc_addr(ha, net_dev) { |
| 1424 | err = dpni_add_mac_addr(priv->mc_io, 0, priv->mc_token, |
| 1425 | ha->addr); |
| 1426 | if (err) |
| 1427 | netdev_warn(priv->net_dev, |
| 1428 | "Could not add ucast MAC %pM to the filtering table (err %d)\n", |
| 1429 | ha->addr, err); |
| 1430 | } |
| 1431 | } |
| 1432 | |
| 1433 | /* Copy mac multicast addresses from @net_dev to @priv |
| 1434 | * Its sole purpose is to make dpaa2_eth_set_rx_mode() more readable. |
| 1435 | */ |
| 1436 | static void add_mc_hw_addr(const struct net_device *net_dev, |
| 1437 | struct dpaa2_eth_priv *priv) |
| 1438 | { |
| 1439 | struct netdev_hw_addr *ha; |
| 1440 | int err; |
| 1441 | |
| 1442 | netdev_for_each_mc_addr(ha, net_dev) { |
| 1443 | err = dpni_add_mac_addr(priv->mc_io, 0, priv->mc_token, |
| 1444 | ha->addr); |
| 1445 | if (err) |
| 1446 | netdev_warn(priv->net_dev, |
| 1447 | "Could not add mcast MAC %pM to the filtering table (err %d)\n", |
| 1448 | ha->addr, err); |
| 1449 | } |
| 1450 | } |
| 1451 | |
| 1452 | static void dpaa2_eth_set_rx_mode(struct net_device *net_dev) |
| 1453 | { |
| 1454 | struct dpaa2_eth_priv *priv = netdev_priv(net_dev); |
| 1455 | int uc_count = netdev_uc_count(net_dev); |
| 1456 | int mc_count = netdev_mc_count(net_dev); |
| 1457 | u8 max_mac = priv->dpni_attrs.mac_filter_entries; |
| 1458 | u32 options = priv->dpni_attrs.options; |
| 1459 | u16 mc_token = priv->mc_token; |
| 1460 | struct fsl_mc_io *mc_io = priv->mc_io; |
| 1461 | int err; |
| 1462 | |
| 1463 | /* Basic sanity checks; these probably indicate a misconfiguration */ |
| 1464 | if (options & DPNI_OPT_NO_MAC_FILTER && max_mac != 0) |
| 1465 | netdev_info(net_dev, |
| 1466 | "mac_filter_entries=%d, DPNI_OPT_NO_MAC_FILTER option must be disabled\n", |
| 1467 | max_mac); |
| 1468 | |
| 1469 | /* Force promiscuous if the uc or mc counts exceed our capabilities. */ |
| 1470 | if (uc_count > max_mac) { |
| 1471 | netdev_info(net_dev, |
| 1472 | "Unicast addr count reached %d, max allowed is %d; forcing promisc\n", |
| 1473 | uc_count, max_mac); |
| 1474 | goto force_promisc; |
| 1475 | } |
| 1476 | if (mc_count + uc_count > max_mac) { |
| 1477 | netdev_info(net_dev, |
| 1478 | "Unicast + multicast addr count reached %d, max allowed is %d; forcing promisc\n", |
| 1479 | uc_count + mc_count, max_mac); |
| 1480 | goto force_mc_promisc; |
| 1481 | } |
| 1482 | |
| 1483 | /* Adjust promisc settings due to flag combinations */ |
| 1484 | if (net_dev->flags & IFF_PROMISC) |
| 1485 | goto force_promisc; |
| 1486 | if (net_dev->flags & IFF_ALLMULTI) { |
| 1487 | /* First, rebuild unicast filtering table. This should be done |
| 1488 | * in promisc mode, in order to avoid frame loss while we |
| 1489 | * progressively add entries to the table. |
| 1490 | * We don't know whether we had been in promisc already, and |
| 1491 | * making an MC call to find out is expensive; so set uc promisc |
| 1492 | * nonetheless. |
| 1493 | */ |
| 1494 | err = dpni_set_unicast_promisc(mc_io, 0, mc_token, 1); |
| 1495 | if (err) |
| 1496 | netdev_warn(net_dev, "Can't set uc promisc\n"); |
| 1497 | |
| 1498 | /* Actual uc table reconstruction. */ |
| 1499 | err = dpni_clear_mac_filters(mc_io, 0, mc_token, 1, 0); |
| 1500 | if (err) |
| 1501 | netdev_warn(net_dev, "Can't clear uc filters\n"); |
| 1502 | add_uc_hw_addr(net_dev, priv); |
| 1503 | |
| 1504 | /* Finally, clear uc promisc and set mc promisc as requested. */ |
| 1505 | err = dpni_set_unicast_promisc(mc_io, 0, mc_token, 0); |
| 1506 | if (err) |
| 1507 | netdev_warn(net_dev, "Can't clear uc promisc\n"); |
| 1508 | goto force_mc_promisc; |
| 1509 | } |
| 1510 | |
| 1511 | /* Neither unicast, nor multicast promisc will be on... eventually. |
| 1512 | * For now, rebuild mac filtering tables while forcing both of them on. |
| 1513 | */ |
| 1514 | err = dpni_set_unicast_promisc(mc_io, 0, mc_token, 1); |
| 1515 | if (err) |
| 1516 | netdev_warn(net_dev, "Can't set uc promisc (%d)\n", err); |
| 1517 | err = dpni_set_multicast_promisc(mc_io, 0, mc_token, 1); |
| 1518 | if (err) |
| 1519 | netdev_warn(net_dev, "Can't set mc promisc (%d)\n", err); |
| 1520 | |
| 1521 | /* Actual mac filtering tables reconstruction */ |
| 1522 | err = dpni_clear_mac_filters(mc_io, 0, mc_token, 1, 1); |
| 1523 | if (err) |
| 1524 | netdev_warn(net_dev, "Can't clear mac filters\n"); |
| 1525 | add_mc_hw_addr(net_dev, priv); |
| 1526 | add_uc_hw_addr(net_dev, priv); |
| 1527 | |
| 1528 | /* Now we can clear both ucast and mcast promisc, without risking |
| 1529 | * to drop legitimate frames anymore. |
| 1530 | */ |
| 1531 | err = dpni_set_unicast_promisc(mc_io, 0, mc_token, 0); |
| 1532 | if (err) |
| 1533 | netdev_warn(net_dev, "Can't clear ucast promisc\n"); |
| 1534 | err = dpni_set_multicast_promisc(mc_io, 0, mc_token, 0); |
| 1535 | if (err) |
| 1536 | netdev_warn(net_dev, "Can't clear mcast promisc\n"); |
| 1537 | |
| 1538 | return; |
| 1539 | |
| 1540 | force_promisc: |
| 1541 | err = dpni_set_unicast_promisc(mc_io, 0, mc_token, 1); |
| 1542 | if (err) |
| 1543 | netdev_warn(net_dev, "Can't set ucast promisc\n"); |
| 1544 | force_mc_promisc: |
| 1545 | err = dpni_set_multicast_promisc(mc_io, 0, mc_token, 1); |
| 1546 | if (err) |
| 1547 | netdev_warn(net_dev, "Can't set mcast promisc\n"); |
| 1548 | } |
| 1549 | |
| 1550 | static int dpaa2_eth_set_features(struct net_device *net_dev, |
| 1551 | netdev_features_t features) |
| 1552 | { |
| 1553 | struct dpaa2_eth_priv *priv = netdev_priv(net_dev); |
| 1554 | netdev_features_t changed = features ^ net_dev->features; |
| 1555 | bool enable; |
| 1556 | int err; |
| 1557 | |
| 1558 | if (changed & NETIF_F_RXCSUM) { |
| 1559 | enable = !!(features & NETIF_F_RXCSUM); |
| 1560 | err = set_rx_csum(priv, enable); |
| 1561 | if (err) |
| 1562 | return err; |
| 1563 | } |
| 1564 | |
| 1565 | if (changed & (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM)) { |
| 1566 | enable = !!(features & (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM)); |
| 1567 | err = set_tx_csum(priv, enable); |
| 1568 | if (err) |
| 1569 | return err; |
| 1570 | } |
| 1571 | |
| 1572 | return 0; |
| 1573 | } |
| 1574 | |
Ioana Radulescu | 859f998 | 2018-04-26 18:23:47 +0800 | [diff] [blame] | 1575 | static int dpaa2_eth_ts_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) |
| 1576 | { |
| 1577 | struct dpaa2_eth_priv *priv = netdev_priv(dev); |
| 1578 | struct hwtstamp_config config; |
| 1579 | |
| 1580 | if (copy_from_user(&config, rq->ifr_data, sizeof(config))) |
| 1581 | return -EFAULT; |
| 1582 | |
| 1583 | switch (config.tx_type) { |
| 1584 | case HWTSTAMP_TX_OFF: |
| 1585 | priv->tx_tstamp = false; |
| 1586 | break; |
| 1587 | case HWTSTAMP_TX_ON: |
| 1588 | priv->tx_tstamp = true; |
| 1589 | break; |
| 1590 | default: |
| 1591 | return -ERANGE; |
| 1592 | } |
| 1593 | |
| 1594 | if (config.rx_filter == HWTSTAMP_FILTER_NONE) { |
| 1595 | priv->rx_tstamp = false; |
| 1596 | } else { |
| 1597 | priv->rx_tstamp = true; |
| 1598 | /* TS is set for all frame types, not only those requested */ |
| 1599 | config.rx_filter = HWTSTAMP_FILTER_ALL; |
| 1600 | } |
| 1601 | |
| 1602 | return copy_to_user(rq->ifr_data, &config, sizeof(config)) ? |
| 1603 | -EFAULT : 0; |
| 1604 | } |
| 1605 | |
| 1606 | static int dpaa2_eth_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) |
| 1607 | { |
| 1608 | if (cmd == SIOCSHWTSTAMP) |
| 1609 | return dpaa2_eth_ts_ioctl(dev, rq, cmd); |
| 1610 | |
| 1611 | return -EINVAL; |
| 1612 | } |
| 1613 | |
Ioana Ciocoi Radulescu | 7e273a8 | 2018-11-26 16:27:29 +0000 | [diff] [blame] | 1614 | static bool xdp_mtu_valid(struct dpaa2_eth_priv *priv, int mtu) |
| 1615 | { |
| 1616 | int mfl, linear_mfl; |
| 1617 | |
| 1618 | mfl = DPAA2_ETH_L2_MAX_FRM(mtu); |
| 1619 | linear_mfl = DPAA2_ETH_RX_BUF_SIZE - DPAA2_ETH_RX_HWA_SIZE - |
Ioana Ciocoi Radulescu | 7b1eea1 | 2018-11-26 16:27:30 +0000 | [diff] [blame] | 1620 | dpaa2_eth_rx_head_room(priv) - XDP_PACKET_HEADROOM; |
Ioana Ciocoi Radulescu | 7e273a8 | 2018-11-26 16:27:29 +0000 | [diff] [blame] | 1621 | |
| 1622 | if (mfl > linear_mfl) { |
| 1623 | netdev_warn(priv->net_dev, "Maximum MTU for XDP is %d\n", |
| 1624 | linear_mfl - VLAN_ETH_HLEN); |
| 1625 | return false; |
| 1626 | } |
| 1627 | |
| 1628 | return true; |
| 1629 | } |
| 1630 | |
| 1631 | static int set_rx_mfl(struct dpaa2_eth_priv *priv, int mtu, bool has_xdp) |
| 1632 | { |
| 1633 | int mfl, err; |
| 1634 | |
| 1635 | /* We enforce a maximum Rx frame length based on MTU only if we have |
| 1636 | * an XDP program attached (in order to avoid Rx S/G frames). |
| 1637 | * Otherwise, we accept all incoming frames as long as they are not |
| 1638 | * larger than maximum size supported in hardware |
| 1639 | */ |
| 1640 | if (has_xdp) |
| 1641 | mfl = DPAA2_ETH_L2_MAX_FRM(mtu); |
| 1642 | else |
| 1643 | mfl = DPAA2_ETH_MFL; |
| 1644 | |
| 1645 | err = dpni_set_max_frame_length(priv->mc_io, 0, priv->mc_token, mfl); |
| 1646 | if (err) { |
| 1647 | netdev_err(priv->net_dev, "dpni_set_max_frame_length failed\n"); |
| 1648 | return err; |
| 1649 | } |
| 1650 | |
| 1651 | return 0; |
| 1652 | } |
| 1653 | |
| 1654 | static int dpaa2_eth_change_mtu(struct net_device *dev, int new_mtu) |
| 1655 | { |
| 1656 | struct dpaa2_eth_priv *priv = netdev_priv(dev); |
| 1657 | int err; |
| 1658 | |
| 1659 | if (!priv->xdp_prog) |
| 1660 | goto out; |
| 1661 | |
| 1662 | if (!xdp_mtu_valid(priv, new_mtu)) |
| 1663 | return -EINVAL; |
| 1664 | |
| 1665 | err = set_rx_mfl(priv, new_mtu, true); |
| 1666 | if (err) |
| 1667 | return err; |
| 1668 | |
| 1669 | out: |
| 1670 | dev->mtu = new_mtu; |
| 1671 | return 0; |
| 1672 | } |
| 1673 | |
Ioana Ciocoi Radulescu | 7b1eea1 | 2018-11-26 16:27:30 +0000 | [diff] [blame] | 1674 | static int update_rx_buffer_headroom(struct dpaa2_eth_priv *priv, bool has_xdp) |
| 1675 | { |
| 1676 | struct dpni_buffer_layout buf_layout = {0}; |
| 1677 | int err; |
| 1678 | |
| 1679 | err = dpni_get_buffer_layout(priv->mc_io, 0, priv->mc_token, |
| 1680 | DPNI_QUEUE_RX, &buf_layout); |
| 1681 | if (err) { |
| 1682 | netdev_err(priv->net_dev, "dpni_get_buffer_layout failed\n"); |
| 1683 | return err; |
| 1684 | } |
| 1685 | |
| 1686 | /* Reserve extra headroom for XDP header size changes */ |
| 1687 | buf_layout.data_head_room = dpaa2_eth_rx_head_room(priv) + |
| 1688 | (has_xdp ? XDP_PACKET_HEADROOM : 0); |
| 1689 | buf_layout.options = DPNI_BUF_LAYOUT_OPT_DATA_HEAD_ROOM; |
| 1690 | err = dpni_set_buffer_layout(priv->mc_io, 0, priv->mc_token, |
| 1691 | DPNI_QUEUE_RX, &buf_layout); |
| 1692 | if (err) { |
| 1693 | netdev_err(priv->net_dev, "dpni_set_buffer_layout failed\n"); |
| 1694 | return err; |
| 1695 | } |
| 1696 | |
| 1697 | return 0; |
| 1698 | } |
| 1699 | |
Ioana Ciocoi Radulescu | 7e273a8 | 2018-11-26 16:27:29 +0000 | [diff] [blame] | 1700 | static int setup_xdp(struct net_device *dev, struct bpf_prog *prog) |
| 1701 | { |
| 1702 | struct dpaa2_eth_priv *priv = netdev_priv(dev); |
| 1703 | struct dpaa2_eth_channel *ch; |
| 1704 | struct bpf_prog *old; |
| 1705 | bool up, need_update; |
| 1706 | int i, err; |
| 1707 | |
| 1708 | if (prog && !xdp_mtu_valid(priv, dev->mtu)) |
| 1709 | return -EINVAL; |
| 1710 | |
| 1711 | if (prog) { |
| 1712 | prog = bpf_prog_add(prog, priv->num_channels); |
| 1713 | if (IS_ERR(prog)) |
| 1714 | return PTR_ERR(prog); |
| 1715 | } |
| 1716 | |
| 1717 | up = netif_running(dev); |
| 1718 | need_update = (!!priv->xdp_prog != !!prog); |
| 1719 | |
| 1720 | if (up) |
| 1721 | dpaa2_eth_stop(dev); |
| 1722 | |
Ioana Ciocoi Radulescu | 7b1eea1 | 2018-11-26 16:27:30 +0000 | [diff] [blame] | 1723 | /* While in xdp mode, enforce a maximum Rx frame size based on MTU. |
| 1724 | * Also, when switching between xdp/non-xdp modes we need to reconfigure |
| 1725 | * our Rx buffer layout. Buffer pool was drained on dpaa2_eth_stop, |
| 1726 | * so we are sure no old format buffers will be used from now on. |
| 1727 | */ |
Ioana Ciocoi Radulescu | 7e273a8 | 2018-11-26 16:27:29 +0000 | [diff] [blame] | 1728 | if (need_update) { |
| 1729 | err = set_rx_mfl(priv, dev->mtu, !!prog); |
| 1730 | if (err) |
| 1731 | goto out_err; |
Ioana Ciocoi Radulescu | 7b1eea1 | 2018-11-26 16:27:30 +0000 | [diff] [blame] | 1732 | err = update_rx_buffer_headroom(priv, !!prog); |
| 1733 | if (err) |
| 1734 | goto out_err; |
Ioana Ciocoi Radulescu | 7e273a8 | 2018-11-26 16:27:29 +0000 | [diff] [blame] | 1735 | } |
| 1736 | |
| 1737 | old = xchg(&priv->xdp_prog, prog); |
| 1738 | if (old) |
| 1739 | bpf_prog_put(old); |
| 1740 | |
| 1741 | for (i = 0; i < priv->num_channels; i++) { |
| 1742 | ch = priv->channel[i]; |
| 1743 | old = xchg(&ch->xdp.prog, prog); |
| 1744 | if (old) |
| 1745 | bpf_prog_put(old); |
| 1746 | } |
| 1747 | |
| 1748 | if (up) { |
| 1749 | err = dpaa2_eth_open(dev); |
| 1750 | if (err) |
| 1751 | return err; |
| 1752 | } |
| 1753 | |
| 1754 | return 0; |
| 1755 | |
| 1756 | out_err: |
| 1757 | if (prog) |
| 1758 | bpf_prog_sub(prog, priv->num_channels); |
| 1759 | if (up) |
| 1760 | dpaa2_eth_open(dev); |
| 1761 | |
| 1762 | return err; |
| 1763 | } |
| 1764 | |
| 1765 | static int dpaa2_eth_xdp(struct net_device *dev, struct netdev_bpf *xdp) |
| 1766 | { |
| 1767 | struct dpaa2_eth_priv *priv = netdev_priv(dev); |
| 1768 | |
| 1769 | switch (xdp->command) { |
| 1770 | case XDP_SETUP_PROG: |
| 1771 | return setup_xdp(dev, xdp->prog); |
| 1772 | case XDP_QUERY_PROG: |
| 1773 | xdp->prog_id = priv->xdp_prog ? priv->xdp_prog->aux->id : 0; |
| 1774 | break; |
| 1775 | default: |
| 1776 | return -EINVAL; |
| 1777 | } |
| 1778 | |
| 1779 | return 0; |
| 1780 | } |
| 1781 | |
Ioana Radulescu | d678be1 | 2019-03-01 17:47:24 +0000 | [diff] [blame] | 1782 | static int dpaa2_eth_xdp_xmit_frame(struct net_device *net_dev, |
| 1783 | struct xdp_frame *xdpf) |
| 1784 | { |
| 1785 | struct dpaa2_eth_priv *priv = netdev_priv(net_dev); |
| 1786 | struct device *dev = net_dev->dev.parent; |
| 1787 | struct rtnl_link_stats64 *percpu_stats; |
| 1788 | struct dpaa2_eth_drv_stats *percpu_extras; |
| 1789 | unsigned int needed_headroom; |
| 1790 | struct dpaa2_eth_swa *swa; |
| 1791 | struct dpaa2_eth_fq *fq; |
| 1792 | struct dpaa2_fd fd; |
| 1793 | void *buffer_start, *aligned_start; |
| 1794 | dma_addr_t addr; |
| 1795 | int err, i; |
| 1796 | |
| 1797 | /* We require a minimum headroom to be able to transmit the frame. |
| 1798 | * Otherwise return an error and let the original net_device handle it |
| 1799 | */ |
| 1800 | needed_headroom = dpaa2_eth_needed_headroom(priv, NULL); |
| 1801 | if (xdpf->headroom < needed_headroom) |
| 1802 | return -EINVAL; |
| 1803 | |
| 1804 | percpu_stats = this_cpu_ptr(priv->percpu_stats); |
| 1805 | percpu_extras = this_cpu_ptr(priv->percpu_extras); |
| 1806 | |
| 1807 | /* Setup the FD fields */ |
| 1808 | memset(&fd, 0, sizeof(fd)); |
| 1809 | |
| 1810 | /* Align FD address, if possible */ |
| 1811 | buffer_start = xdpf->data - needed_headroom; |
| 1812 | aligned_start = PTR_ALIGN(buffer_start - DPAA2_ETH_TX_BUF_ALIGN, |
| 1813 | DPAA2_ETH_TX_BUF_ALIGN); |
| 1814 | if (aligned_start >= xdpf->data - xdpf->headroom) |
| 1815 | buffer_start = aligned_start; |
| 1816 | |
| 1817 | swa = (struct dpaa2_eth_swa *)buffer_start; |
| 1818 | /* fill in necessary fields here */ |
| 1819 | swa->type = DPAA2_ETH_SWA_XDP; |
| 1820 | swa->xdp.dma_size = xdpf->data + xdpf->len - buffer_start; |
| 1821 | swa->xdp.xdpf = xdpf; |
| 1822 | |
| 1823 | addr = dma_map_single(dev, buffer_start, |
| 1824 | swa->xdp.dma_size, |
| 1825 | DMA_BIDIRECTIONAL); |
| 1826 | if (unlikely(dma_mapping_error(dev, addr))) { |
| 1827 | percpu_stats->tx_dropped++; |
| 1828 | return -ENOMEM; |
| 1829 | } |
| 1830 | |
| 1831 | dpaa2_fd_set_addr(&fd, addr); |
| 1832 | dpaa2_fd_set_offset(&fd, xdpf->data - buffer_start); |
| 1833 | dpaa2_fd_set_len(&fd, xdpf->len); |
| 1834 | dpaa2_fd_set_format(&fd, dpaa2_fd_single); |
| 1835 | dpaa2_fd_set_ctrl(&fd, FD_CTRL_PTA); |
| 1836 | |
Ioana Ciocoi Radulescu | 6444750 | 2019-03-20 14:11:04 +0000 | [diff] [blame] | 1837 | fq = &priv->fq[smp_processor_id() % dpaa2_eth_queue_count(priv)]; |
Ioana Radulescu | d678be1 | 2019-03-01 17:47:24 +0000 | [diff] [blame] | 1838 | for (i = 0; i < DPAA2_ETH_ENQUEUE_RETRIES; i++) { |
| 1839 | err = priv->enqueue(priv, fq, &fd, 0); |
| 1840 | if (err != -EBUSY) |
| 1841 | break; |
| 1842 | } |
| 1843 | percpu_extras->tx_portal_busy += i; |
| 1844 | if (unlikely(err < 0)) { |
| 1845 | percpu_stats->tx_errors++; |
| 1846 | /* let the Rx device handle the cleanup */ |
| 1847 | return err; |
| 1848 | } |
| 1849 | |
| 1850 | percpu_stats->tx_packets++; |
| 1851 | percpu_stats->tx_bytes += dpaa2_fd_get_len(&fd); |
| 1852 | |
| 1853 | return 0; |
| 1854 | } |
| 1855 | |
| 1856 | static int dpaa2_eth_xdp_xmit(struct net_device *net_dev, int n, |
| 1857 | struct xdp_frame **frames, u32 flags) |
| 1858 | { |
| 1859 | int drops = 0; |
| 1860 | int i, err; |
| 1861 | |
| 1862 | if (unlikely(flags & ~XDP_XMIT_FLAGS_MASK)) |
| 1863 | return -EINVAL; |
| 1864 | |
| 1865 | if (!netif_running(net_dev)) |
| 1866 | return -ENETDOWN; |
| 1867 | |
| 1868 | for (i = 0; i < n; i++) { |
| 1869 | struct xdp_frame *xdpf = frames[i]; |
| 1870 | |
| 1871 | err = dpaa2_eth_xdp_xmit_frame(net_dev, xdpf); |
| 1872 | if (err) { |
| 1873 | xdp_return_frame_rx_napi(xdpf); |
| 1874 | drops++; |
| 1875 | } |
| 1876 | } |
| 1877 | |
| 1878 | return n - drops; |
| 1879 | } |
| 1880 | |
Ioana Radulescu | 06d5b17 | 2019-06-11 14:50:01 +0300 | [diff] [blame] | 1881 | static int update_xps(struct dpaa2_eth_priv *priv) |
| 1882 | { |
| 1883 | struct net_device *net_dev = priv->net_dev; |
| 1884 | struct cpumask xps_mask; |
| 1885 | struct dpaa2_eth_fq *fq; |
Ioana Radulescu | ab1e6de | 2019-06-11 14:50:03 +0300 | [diff] [blame] | 1886 | int i, num_queues, netdev_queues; |
Ioana Radulescu | 06d5b17 | 2019-06-11 14:50:01 +0300 | [diff] [blame] | 1887 | int err = 0; |
| 1888 | |
| 1889 | num_queues = dpaa2_eth_queue_count(priv); |
Ioana Radulescu | ab1e6de | 2019-06-11 14:50:03 +0300 | [diff] [blame] | 1890 | netdev_queues = (net_dev->num_tc ? : 1) * num_queues; |
Ioana Radulescu | 06d5b17 | 2019-06-11 14:50:01 +0300 | [diff] [blame] | 1891 | |
| 1892 | /* The first <num_queues> entries in priv->fq array are Tx/Tx conf |
| 1893 | * queues, so only process those |
| 1894 | */ |
Ioana Radulescu | ab1e6de | 2019-06-11 14:50:03 +0300 | [diff] [blame] | 1895 | for (i = 0; i < netdev_queues; i++) { |
| 1896 | fq = &priv->fq[i % num_queues]; |
Ioana Radulescu | 06d5b17 | 2019-06-11 14:50:01 +0300 | [diff] [blame] | 1897 | |
| 1898 | cpumask_clear(&xps_mask); |
| 1899 | cpumask_set_cpu(fq->target_cpu, &xps_mask); |
| 1900 | |
| 1901 | err = netif_set_xps_queue(net_dev, &xps_mask, i); |
| 1902 | if (err) { |
| 1903 | netdev_warn_once(net_dev, "Error setting XPS queue\n"); |
| 1904 | break; |
| 1905 | } |
| 1906 | } |
| 1907 | |
| 1908 | return err; |
| 1909 | } |
| 1910 | |
Ioana Radulescu | ab1e6de | 2019-06-11 14:50:03 +0300 | [diff] [blame] | 1911 | static int dpaa2_eth_setup_tc(struct net_device *net_dev, |
| 1912 | enum tc_setup_type type, void *type_data) |
| 1913 | { |
| 1914 | struct dpaa2_eth_priv *priv = netdev_priv(net_dev); |
| 1915 | struct tc_mqprio_qopt *mqprio = type_data; |
| 1916 | u8 num_tc, num_queues; |
| 1917 | int i; |
| 1918 | |
| 1919 | if (type != TC_SETUP_QDISC_MQPRIO) |
| 1920 | return -EINVAL; |
| 1921 | |
| 1922 | mqprio->hw = TC_MQPRIO_HW_OFFLOAD_TCS; |
| 1923 | num_queues = dpaa2_eth_queue_count(priv); |
| 1924 | num_tc = mqprio->num_tc; |
| 1925 | |
| 1926 | if (num_tc == net_dev->num_tc) |
| 1927 | return 0; |
| 1928 | |
| 1929 | if (num_tc > dpaa2_eth_tc_count(priv)) { |
| 1930 | netdev_err(net_dev, "Max %d traffic classes supported\n", |
| 1931 | dpaa2_eth_tc_count(priv)); |
| 1932 | return -EINVAL; |
| 1933 | } |
| 1934 | |
| 1935 | if (!num_tc) { |
| 1936 | netdev_reset_tc(net_dev); |
| 1937 | netif_set_real_num_tx_queues(net_dev, num_queues); |
| 1938 | goto out; |
| 1939 | } |
| 1940 | |
| 1941 | netdev_set_num_tc(net_dev, num_tc); |
| 1942 | netif_set_real_num_tx_queues(net_dev, num_tc * num_queues); |
| 1943 | |
| 1944 | for (i = 0; i < num_tc; i++) |
| 1945 | netdev_set_tc_queue(net_dev, i, num_queues, i * num_queues); |
| 1946 | |
| 1947 | out: |
| 1948 | update_xps(priv); |
| 1949 | |
| 1950 | return 0; |
| 1951 | } |
| 1952 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1953 | static const struct net_device_ops dpaa2_eth_ops = { |
| 1954 | .ndo_open = dpaa2_eth_open, |
| 1955 | .ndo_start_xmit = dpaa2_eth_tx, |
| 1956 | .ndo_stop = dpaa2_eth_stop, |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1957 | .ndo_set_mac_address = dpaa2_eth_set_addr, |
| 1958 | .ndo_get_stats64 = dpaa2_eth_get_stats, |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1959 | .ndo_set_rx_mode = dpaa2_eth_set_rx_mode, |
| 1960 | .ndo_set_features = dpaa2_eth_set_features, |
Ioana Radulescu | 859f998 | 2018-04-26 18:23:47 +0800 | [diff] [blame] | 1961 | .ndo_do_ioctl = dpaa2_eth_ioctl, |
Ioana Ciocoi Radulescu | 7e273a8 | 2018-11-26 16:27:29 +0000 | [diff] [blame] | 1962 | .ndo_change_mtu = dpaa2_eth_change_mtu, |
| 1963 | .ndo_bpf = dpaa2_eth_xdp, |
Ioana Radulescu | d678be1 | 2019-03-01 17:47:24 +0000 | [diff] [blame] | 1964 | .ndo_xdp_xmit = dpaa2_eth_xdp_xmit, |
Ioana Radulescu | ab1e6de | 2019-06-11 14:50:03 +0300 | [diff] [blame] | 1965 | .ndo_setup_tc = dpaa2_eth_setup_tc, |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1966 | }; |
| 1967 | |
| 1968 | static void cdan_cb(struct dpaa2_io_notification_ctx *ctx) |
| 1969 | { |
| 1970 | struct dpaa2_eth_channel *ch; |
| 1971 | |
| 1972 | ch = container_of(ctx, struct dpaa2_eth_channel, nctx); |
Ioana Radulescu | 85047ab | 2017-04-28 04:50:31 -0500 | [diff] [blame] | 1973 | |
| 1974 | /* Update NAPI statistics */ |
| 1975 | ch->stats.cdan++; |
| 1976 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1977 | napi_schedule_irqoff(&ch->napi); |
| 1978 | } |
| 1979 | |
| 1980 | /* Allocate and configure a DPCON object */ |
| 1981 | static struct fsl_mc_device *setup_dpcon(struct dpaa2_eth_priv *priv) |
| 1982 | { |
| 1983 | struct fsl_mc_device *dpcon; |
| 1984 | struct device *dev = priv->net_dev->dev.parent; |
| 1985 | struct dpcon_attr attrs; |
| 1986 | int err; |
| 1987 | |
| 1988 | err = fsl_mc_object_allocate(to_fsl_mc_device(dev), |
| 1989 | FSL_MC_POOL_DPCON, &dpcon); |
| 1990 | if (err) { |
Ioana Ciornei | d7f5a9d | 2018-11-09 15:26:45 +0000 | [diff] [blame] | 1991 | if (err == -ENXIO) |
| 1992 | err = -EPROBE_DEFER; |
| 1993 | else |
| 1994 | dev_info(dev, "Not enough DPCONs, will go on as-is\n"); |
| 1995 | return ERR_PTR(err); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 1996 | } |
| 1997 | |
| 1998 | err = dpcon_open(priv->mc_io, 0, dpcon->obj_desc.id, &dpcon->mc_handle); |
| 1999 | if (err) { |
| 2000 | dev_err(dev, "dpcon_open() failed\n"); |
Ioana Radulescu | f6dda80 | 2017-10-29 08:20:39 +0000 | [diff] [blame] | 2001 | goto free; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2002 | } |
| 2003 | |
| 2004 | err = dpcon_reset(priv->mc_io, 0, dpcon->mc_handle); |
| 2005 | if (err) { |
| 2006 | dev_err(dev, "dpcon_reset() failed\n"); |
Ioana Radulescu | f6dda80 | 2017-10-29 08:20:39 +0000 | [diff] [blame] | 2007 | goto close; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2008 | } |
| 2009 | |
| 2010 | err = dpcon_get_attributes(priv->mc_io, 0, dpcon->mc_handle, &attrs); |
| 2011 | if (err) { |
| 2012 | dev_err(dev, "dpcon_get_attributes() failed\n"); |
Ioana Radulescu | f6dda80 | 2017-10-29 08:20:39 +0000 | [diff] [blame] | 2013 | goto close; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2014 | } |
| 2015 | |
| 2016 | err = dpcon_enable(priv->mc_io, 0, dpcon->mc_handle); |
| 2017 | if (err) { |
| 2018 | dev_err(dev, "dpcon_enable() failed\n"); |
Ioana Radulescu | f6dda80 | 2017-10-29 08:20:39 +0000 | [diff] [blame] | 2019 | goto close; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2020 | } |
| 2021 | |
| 2022 | return dpcon; |
| 2023 | |
Ioana Radulescu | f6dda80 | 2017-10-29 08:20:39 +0000 | [diff] [blame] | 2024 | close: |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2025 | dpcon_close(priv->mc_io, 0, dpcon->mc_handle); |
Ioana Radulescu | f6dda80 | 2017-10-29 08:20:39 +0000 | [diff] [blame] | 2026 | free: |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2027 | fsl_mc_object_free(dpcon); |
| 2028 | |
| 2029 | return NULL; |
| 2030 | } |
| 2031 | |
| 2032 | static void free_dpcon(struct dpaa2_eth_priv *priv, |
| 2033 | struct fsl_mc_device *dpcon) |
| 2034 | { |
| 2035 | dpcon_disable(priv->mc_io, 0, dpcon->mc_handle); |
| 2036 | dpcon_close(priv->mc_io, 0, dpcon->mc_handle); |
| 2037 | fsl_mc_object_free(dpcon); |
| 2038 | } |
| 2039 | |
| 2040 | static struct dpaa2_eth_channel * |
| 2041 | alloc_channel(struct dpaa2_eth_priv *priv) |
| 2042 | { |
| 2043 | struct dpaa2_eth_channel *channel; |
| 2044 | struct dpcon_attr attr; |
| 2045 | struct device *dev = priv->net_dev->dev.parent; |
| 2046 | int err; |
| 2047 | |
| 2048 | channel = kzalloc(sizeof(*channel), GFP_KERNEL); |
| 2049 | if (!channel) |
| 2050 | return NULL; |
| 2051 | |
| 2052 | channel->dpcon = setup_dpcon(priv); |
Ioana Ciornei | d7f5a9d | 2018-11-09 15:26:45 +0000 | [diff] [blame] | 2053 | if (IS_ERR_OR_NULL(channel->dpcon)) { |
Ioana Radulescu | bd8460f | 2019-05-24 18:15:16 +0300 | [diff] [blame] | 2054 | err = PTR_ERR_OR_ZERO(channel->dpcon); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2055 | goto err_setup; |
Ioana Ciornei | d7f5a9d | 2018-11-09 15:26:45 +0000 | [diff] [blame] | 2056 | } |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2057 | |
| 2058 | err = dpcon_get_attributes(priv->mc_io, 0, channel->dpcon->mc_handle, |
| 2059 | &attr); |
| 2060 | if (err) { |
| 2061 | dev_err(dev, "dpcon_get_attributes() failed\n"); |
| 2062 | goto err_get_attr; |
| 2063 | } |
| 2064 | |
| 2065 | channel->dpcon_id = attr.id; |
| 2066 | channel->ch_id = attr.qbman_ch_id; |
| 2067 | channel->priv = priv; |
| 2068 | |
| 2069 | return channel; |
| 2070 | |
| 2071 | err_get_attr: |
| 2072 | free_dpcon(priv, channel->dpcon); |
| 2073 | err_setup: |
| 2074 | kfree(channel); |
Ioana Ciornei | d7f5a9d | 2018-11-09 15:26:45 +0000 | [diff] [blame] | 2075 | return ERR_PTR(err); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2076 | } |
| 2077 | |
| 2078 | static void free_channel(struct dpaa2_eth_priv *priv, |
| 2079 | struct dpaa2_eth_channel *channel) |
| 2080 | { |
| 2081 | free_dpcon(priv, channel->dpcon); |
| 2082 | kfree(channel); |
| 2083 | } |
| 2084 | |
| 2085 | /* DPIO setup: allocate and configure QBMan channels, setup core affinity |
| 2086 | * and register data availability notifications |
| 2087 | */ |
| 2088 | static int setup_dpio(struct dpaa2_eth_priv *priv) |
| 2089 | { |
| 2090 | struct dpaa2_io_notification_ctx *nctx; |
| 2091 | struct dpaa2_eth_channel *channel; |
| 2092 | struct dpcon_notification_cfg dpcon_notif_cfg; |
| 2093 | struct device *dev = priv->net_dev->dev.parent; |
| 2094 | int i, err; |
| 2095 | |
| 2096 | /* We want the ability to spread ingress traffic (RX, TX conf) to as |
| 2097 | * many cores as possible, so we need one channel for each core |
| 2098 | * (unless there's fewer queues than cores, in which case the extra |
| 2099 | * channels would be wasted). |
| 2100 | * Allocate one channel per core and register it to the core's |
| 2101 | * affine DPIO. If not enough channels are available for all cores |
| 2102 | * or if some cores don't have an affine DPIO, there will be no |
| 2103 | * ingress frame processing on those cores. |
| 2104 | */ |
| 2105 | cpumask_clear(&priv->dpio_cpumask); |
| 2106 | for_each_online_cpu(i) { |
| 2107 | /* Try to allocate a channel */ |
| 2108 | channel = alloc_channel(priv); |
Ioana Ciornei | d7f5a9d | 2018-11-09 15:26:45 +0000 | [diff] [blame] | 2109 | if (IS_ERR_OR_NULL(channel)) { |
Ioana Radulescu | bd8460f | 2019-05-24 18:15:16 +0300 | [diff] [blame] | 2110 | err = PTR_ERR_OR_ZERO(channel); |
Ioana Ciornei | d7f5a9d | 2018-11-09 15:26:45 +0000 | [diff] [blame] | 2111 | if (err != -EPROBE_DEFER) |
| 2112 | dev_info(dev, |
| 2113 | "No affine channel for cpu %d and above\n", i); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2114 | goto err_alloc_ch; |
| 2115 | } |
| 2116 | |
| 2117 | priv->channel[priv->num_channels] = channel; |
| 2118 | |
| 2119 | nctx = &channel->nctx; |
| 2120 | nctx->is_cdan = 1; |
| 2121 | nctx->cb = cdan_cb; |
| 2122 | nctx->id = channel->ch_id; |
| 2123 | nctx->desired_cpu = i; |
| 2124 | |
| 2125 | /* Register the new context */ |
Ioana Radulescu | 7ec0596 | 2018-01-05 05:04:32 -0600 | [diff] [blame] | 2126 | channel->dpio = dpaa2_io_service_select(i); |
Ioana Ciornei | 47441f7 | 2018-12-10 16:50:19 +0000 | [diff] [blame] | 2127 | err = dpaa2_io_service_register(channel->dpio, nctx, dev); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2128 | if (err) { |
Ioana Radulescu | 5206d8d | 2017-06-06 10:00:33 -0500 | [diff] [blame] | 2129 | dev_dbg(dev, "No affine DPIO for cpu %d\n", i); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2130 | /* If no affine DPIO for this core, there's probably |
Ioana Radulescu | 5206d8d | 2017-06-06 10:00:33 -0500 | [diff] [blame] | 2131 | * none available for next cores either. Signal we want |
| 2132 | * to retry later, in case the DPIO devices weren't |
| 2133 | * probed yet. |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2134 | */ |
Ioana Radulescu | 5206d8d | 2017-06-06 10:00:33 -0500 | [diff] [blame] | 2135 | err = -EPROBE_DEFER; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2136 | goto err_service_reg; |
| 2137 | } |
| 2138 | |
| 2139 | /* Register DPCON notification with MC */ |
| 2140 | dpcon_notif_cfg.dpio_id = nctx->dpio_id; |
| 2141 | dpcon_notif_cfg.priority = 0; |
| 2142 | dpcon_notif_cfg.user_ctx = nctx->qman64; |
| 2143 | err = dpcon_set_notification(priv->mc_io, 0, |
| 2144 | channel->dpcon->mc_handle, |
| 2145 | &dpcon_notif_cfg); |
| 2146 | if (err) { |
| 2147 | dev_err(dev, "dpcon_set_notification failed()\n"); |
| 2148 | goto err_set_cdan; |
| 2149 | } |
| 2150 | |
| 2151 | /* If we managed to allocate a channel and also found an affine |
| 2152 | * DPIO for this core, add it to the final mask |
| 2153 | */ |
| 2154 | cpumask_set_cpu(i, &priv->dpio_cpumask); |
| 2155 | priv->num_channels++; |
| 2156 | |
| 2157 | /* Stop if we already have enough channels to accommodate all |
| 2158 | * RX and TX conf queues |
| 2159 | */ |
Ioana Ciocoi Radulescu | b0e4f37 | 2018-11-14 11:48:35 +0000 | [diff] [blame] | 2160 | if (priv->num_channels == priv->dpni_attrs.num_queues) |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2161 | break; |
| 2162 | } |
| 2163 | |
| 2164 | return 0; |
| 2165 | |
| 2166 | err_set_cdan: |
Ioana Ciornei | 47441f7 | 2018-12-10 16:50:19 +0000 | [diff] [blame] | 2167 | dpaa2_io_service_deregister(channel->dpio, nctx, dev); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2168 | err_service_reg: |
| 2169 | free_channel(priv, channel); |
| 2170 | err_alloc_ch: |
Ioana Ciornei | d7f5a9d | 2018-11-09 15:26:45 +0000 | [diff] [blame] | 2171 | if (err == -EPROBE_DEFER) |
| 2172 | return err; |
| 2173 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2174 | if (cpumask_empty(&priv->dpio_cpumask)) { |
| 2175 | dev_err(dev, "No cpu with an affine DPIO/DPCON\n"); |
Ioana Ciornei | d7f5a9d | 2018-11-09 15:26:45 +0000 | [diff] [blame] | 2176 | return -ENODEV; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2177 | } |
| 2178 | |
| 2179 | dev_info(dev, "Cores %*pbl available for processing ingress traffic\n", |
| 2180 | cpumask_pr_args(&priv->dpio_cpumask)); |
| 2181 | |
| 2182 | return 0; |
| 2183 | } |
| 2184 | |
| 2185 | static void free_dpio(struct dpaa2_eth_priv *priv) |
| 2186 | { |
Ioana Ciornei | 47441f7 | 2018-12-10 16:50:19 +0000 | [diff] [blame] | 2187 | struct device *dev = priv->net_dev->dev.parent; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2188 | struct dpaa2_eth_channel *ch; |
Ioana Ciornei | 47441f7 | 2018-12-10 16:50:19 +0000 | [diff] [blame] | 2189 | int i; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2190 | |
| 2191 | /* deregister CDAN notifications and free channels */ |
| 2192 | for (i = 0; i < priv->num_channels; i++) { |
| 2193 | ch = priv->channel[i]; |
Ioana Ciornei | 47441f7 | 2018-12-10 16:50:19 +0000 | [diff] [blame] | 2194 | dpaa2_io_service_deregister(ch->dpio, &ch->nctx, dev); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2195 | free_channel(priv, ch); |
| 2196 | } |
| 2197 | } |
| 2198 | |
| 2199 | static struct dpaa2_eth_channel *get_affine_channel(struct dpaa2_eth_priv *priv, |
| 2200 | int cpu) |
| 2201 | { |
| 2202 | struct device *dev = priv->net_dev->dev.parent; |
| 2203 | int i; |
| 2204 | |
| 2205 | for (i = 0; i < priv->num_channels; i++) |
| 2206 | if (priv->channel[i]->nctx.desired_cpu == cpu) |
| 2207 | return priv->channel[i]; |
| 2208 | |
| 2209 | /* We should never get here. Issue a warning and return |
| 2210 | * the first channel, because it's still better than nothing |
| 2211 | */ |
| 2212 | dev_warn(dev, "No affine channel found for cpu %d\n", cpu); |
| 2213 | |
| 2214 | return priv->channel[0]; |
| 2215 | } |
| 2216 | |
| 2217 | static void set_fq_affinity(struct dpaa2_eth_priv *priv) |
| 2218 | { |
| 2219 | struct device *dev = priv->net_dev->dev.parent; |
| 2220 | struct dpaa2_eth_fq *fq; |
| 2221 | int rx_cpu, txc_cpu; |
Ioana Radulescu | 06d5b17 | 2019-06-11 14:50:01 +0300 | [diff] [blame] | 2222 | int i; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2223 | |
| 2224 | /* For each FQ, pick one channel/CPU to deliver frames to. |
| 2225 | * This may well change at runtime, either through irqbalance or |
| 2226 | * through direct user intervention. |
| 2227 | */ |
| 2228 | rx_cpu = txc_cpu = cpumask_first(&priv->dpio_cpumask); |
| 2229 | |
| 2230 | for (i = 0; i < priv->num_fqs; i++) { |
| 2231 | fq = &priv->fq[i]; |
| 2232 | switch (fq->type) { |
| 2233 | case DPAA2_RX_FQ: |
| 2234 | fq->target_cpu = rx_cpu; |
| 2235 | rx_cpu = cpumask_next(rx_cpu, &priv->dpio_cpumask); |
| 2236 | if (rx_cpu >= nr_cpu_ids) |
| 2237 | rx_cpu = cpumask_first(&priv->dpio_cpumask); |
| 2238 | break; |
| 2239 | case DPAA2_TX_CONF_FQ: |
| 2240 | fq->target_cpu = txc_cpu; |
| 2241 | txc_cpu = cpumask_next(txc_cpu, &priv->dpio_cpumask); |
| 2242 | if (txc_cpu >= nr_cpu_ids) |
| 2243 | txc_cpu = cpumask_first(&priv->dpio_cpumask); |
| 2244 | break; |
| 2245 | default: |
| 2246 | dev_err(dev, "Unknown FQ type: %d\n", fq->type); |
| 2247 | } |
| 2248 | fq->channel = get_affine_channel(priv, fq->target_cpu); |
| 2249 | } |
Ioana Radulescu | 06d5b17 | 2019-06-11 14:50:01 +0300 | [diff] [blame] | 2250 | |
| 2251 | update_xps(priv); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2252 | } |
| 2253 | |
| 2254 | static void setup_fqs(struct dpaa2_eth_priv *priv) |
| 2255 | { |
| 2256 | int i; |
| 2257 | |
| 2258 | /* We have one TxConf FQ per Tx flow. |
| 2259 | * The number of Tx and Rx queues is the same. |
| 2260 | * Tx queues come first in the fq array. |
| 2261 | */ |
| 2262 | for (i = 0; i < dpaa2_eth_queue_count(priv); i++) { |
| 2263 | priv->fq[priv->num_fqs].type = DPAA2_TX_CONF_FQ; |
| 2264 | priv->fq[priv->num_fqs].consume = dpaa2_eth_tx_conf; |
| 2265 | priv->fq[priv->num_fqs++].flowid = (u16)i; |
| 2266 | } |
| 2267 | |
| 2268 | for (i = 0; i < dpaa2_eth_queue_count(priv); i++) { |
| 2269 | priv->fq[priv->num_fqs].type = DPAA2_RX_FQ; |
| 2270 | priv->fq[priv->num_fqs].consume = dpaa2_eth_rx; |
| 2271 | priv->fq[priv->num_fqs++].flowid = (u16)i; |
| 2272 | } |
| 2273 | |
| 2274 | /* For each FQ, decide on which core to process incoming frames */ |
| 2275 | set_fq_affinity(priv); |
| 2276 | } |
| 2277 | |
| 2278 | /* Allocate and configure one buffer pool for each interface */ |
| 2279 | static int setup_dpbp(struct dpaa2_eth_priv *priv) |
| 2280 | { |
| 2281 | int err; |
| 2282 | struct fsl_mc_device *dpbp_dev; |
| 2283 | struct device *dev = priv->net_dev->dev.parent; |
Ioana Radulescu | 05fa39c | 2017-06-06 10:00:37 -0500 | [diff] [blame] | 2284 | struct dpbp_attr dpbp_attrs; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2285 | |
| 2286 | err = fsl_mc_object_allocate(to_fsl_mc_device(dev), FSL_MC_POOL_DPBP, |
| 2287 | &dpbp_dev); |
| 2288 | if (err) { |
Ioana Ciornei | d7f5a9d | 2018-11-09 15:26:45 +0000 | [diff] [blame] | 2289 | if (err == -ENXIO) |
| 2290 | err = -EPROBE_DEFER; |
| 2291 | else |
| 2292 | dev_err(dev, "DPBP device allocation failed\n"); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2293 | return err; |
| 2294 | } |
| 2295 | |
| 2296 | priv->dpbp_dev = dpbp_dev; |
| 2297 | |
| 2298 | err = dpbp_open(priv->mc_io, 0, priv->dpbp_dev->obj_desc.id, |
| 2299 | &dpbp_dev->mc_handle); |
| 2300 | if (err) { |
| 2301 | dev_err(dev, "dpbp_open() failed\n"); |
| 2302 | goto err_open; |
| 2303 | } |
| 2304 | |
Ioana Radulescu | d00defe | 2017-06-06 10:00:32 -0500 | [diff] [blame] | 2305 | err = dpbp_reset(priv->mc_io, 0, dpbp_dev->mc_handle); |
| 2306 | if (err) { |
| 2307 | dev_err(dev, "dpbp_reset() failed\n"); |
| 2308 | goto err_reset; |
| 2309 | } |
| 2310 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2311 | err = dpbp_enable(priv->mc_io, 0, dpbp_dev->mc_handle); |
| 2312 | if (err) { |
| 2313 | dev_err(dev, "dpbp_enable() failed\n"); |
| 2314 | goto err_enable; |
| 2315 | } |
| 2316 | |
| 2317 | err = dpbp_get_attributes(priv->mc_io, 0, dpbp_dev->mc_handle, |
Ioana Radulescu | 05fa39c | 2017-06-06 10:00:37 -0500 | [diff] [blame] | 2318 | &dpbp_attrs); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2319 | if (err) { |
| 2320 | dev_err(dev, "dpbp_get_attributes() failed\n"); |
| 2321 | goto err_get_attr; |
| 2322 | } |
Ioana Radulescu | 05fa39c | 2017-06-06 10:00:37 -0500 | [diff] [blame] | 2323 | priv->bpid = dpbp_attrs.bpid; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2324 | |
| 2325 | return 0; |
| 2326 | |
| 2327 | err_get_attr: |
| 2328 | dpbp_disable(priv->mc_io, 0, dpbp_dev->mc_handle); |
| 2329 | err_enable: |
Ioana Radulescu | d00defe | 2017-06-06 10:00:32 -0500 | [diff] [blame] | 2330 | err_reset: |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2331 | dpbp_close(priv->mc_io, 0, dpbp_dev->mc_handle); |
| 2332 | err_open: |
| 2333 | fsl_mc_object_free(dpbp_dev); |
| 2334 | |
| 2335 | return err; |
| 2336 | } |
| 2337 | |
| 2338 | static void free_dpbp(struct dpaa2_eth_priv *priv) |
| 2339 | { |
| 2340 | drain_pool(priv); |
| 2341 | dpbp_disable(priv->mc_io, 0, priv->dpbp_dev->mc_handle); |
| 2342 | dpbp_close(priv->mc_io, 0, priv->dpbp_dev->mc_handle); |
| 2343 | fsl_mc_object_free(priv->dpbp_dev); |
| 2344 | } |
| 2345 | |
Ioana Radulescu | 308f64e | 2017-10-29 08:20:40 +0000 | [diff] [blame] | 2346 | static int set_buffer_layout(struct dpaa2_eth_priv *priv) |
| 2347 | { |
| 2348 | struct device *dev = priv->net_dev->dev.parent; |
| 2349 | struct dpni_buffer_layout buf_layout = {0}; |
Ioana Ciocoi Radulescu | 27c8748 | 2019-02-04 17:00:35 +0000 | [diff] [blame] | 2350 | u16 rx_buf_align; |
Ioana Radulescu | 308f64e | 2017-10-29 08:20:40 +0000 | [diff] [blame] | 2351 | int err; |
| 2352 | |
Bogdan Purcareata | 8a4fd87 | 2017-10-29 08:20:42 +0000 | [diff] [blame] | 2353 | /* We need to check for WRIOP version 1.0.0, but depending on the MC |
| 2354 | * version, this number is not always provided correctly on rev1. |
| 2355 | * We need to check for both alternatives in this situation. |
| 2356 | */ |
| 2357 | if (priv->dpni_attrs.wriop_version == DPAA2_WRIOP_VERSION(0, 0, 0) || |
| 2358 | priv->dpni_attrs.wriop_version == DPAA2_WRIOP_VERSION(1, 0, 0)) |
Ioana Ciocoi Radulescu | 27c8748 | 2019-02-04 17:00:35 +0000 | [diff] [blame] | 2359 | rx_buf_align = DPAA2_ETH_RX_BUF_ALIGN_REV1; |
Bogdan Purcareata | 8a4fd87 | 2017-10-29 08:20:42 +0000 | [diff] [blame] | 2360 | else |
Ioana Ciocoi Radulescu | 27c8748 | 2019-02-04 17:00:35 +0000 | [diff] [blame] | 2361 | rx_buf_align = DPAA2_ETH_RX_BUF_ALIGN; |
Bogdan Purcareata | 8a4fd87 | 2017-10-29 08:20:42 +0000 | [diff] [blame] | 2362 | |
Bogdan Purcareata | 4b2d9fe | 2017-10-29 08:20:43 +0000 | [diff] [blame] | 2363 | /* tx buffer */ |
Ioana Radulescu | 308f64e | 2017-10-29 08:20:40 +0000 | [diff] [blame] | 2364 | buf_layout.private_data_size = DPAA2_ETH_SWA_SIZE; |
Ioana Radulescu | 859f998 | 2018-04-26 18:23:47 +0800 | [diff] [blame] | 2365 | buf_layout.pass_timestamp = true; |
| 2366 | buf_layout.options = DPNI_BUF_LAYOUT_OPT_PRIVATE_DATA_SIZE | |
| 2367 | DPNI_BUF_LAYOUT_OPT_TIMESTAMP; |
Ioana Radulescu | 308f64e | 2017-10-29 08:20:40 +0000 | [diff] [blame] | 2368 | err = dpni_set_buffer_layout(priv->mc_io, 0, priv->mc_token, |
| 2369 | DPNI_QUEUE_TX, &buf_layout); |
| 2370 | if (err) { |
| 2371 | dev_err(dev, "dpni_set_buffer_layout(TX) failed\n"); |
| 2372 | return err; |
| 2373 | } |
| 2374 | |
| 2375 | /* tx-confirm buffer */ |
Ioana Radulescu | 859f998 | 2018-04-26 18:23:47 +0800 | [diff] [blame] | 2376 | buf_layout.options = DPNI_BUF_LAYOUT_OPT_TIMESTAMP; |
Ioana Radulescu | 308f64e | 2017-10-29 08:20:40 +0000 | [diff] [blame] | 2377 | err = dpni_set_buffer_layout(priv->mc_io, 0, priv->mc_token, |
| 2378 | DPNI_QUEUE_TX_CONFIRM, &buf_layout); |
| 2379 | if (err) { |
| 2380 | dev_err(dev, "dpni_set_buffer_layout(TX_CONF) failed\n"); |
| 2381 | return err; |
| 2382 | } |
| 2383 | |
Bogdan Purcareata | 4b2d9fe | 2017-10-29 08:20:43 +0000 | [diff] [blame] | 2384 | /* Now that we've set our tx buffer layout, retrieve the minimum |
| 2385 | * required tx data offset. |
| 2386 | */ |
| 2387 | err = dpni_get_tx_data_offset(priv->mc_io, 0, priv->mc_token, |
| 2388 | &priv->tx_data_offset); |
| 2389 | if (err) { |
| 2390 | dev_err(dev, "dpni_get_tx_data_offset() failed\n"); |
| 2391 | return err; |
| 2392 | } |
| 2393 | |
| 2394 | if ((priv->tx_data_offset % 64) != 0) |
| 2395 | dev_warn(dev, "Tx data offset (%d) not a multiple of 64B\n", |
| 2396 | priv->tx_data_offset); |
| 2397 | |
| 2398 | /* rx buffer */ |
Ioana Radulescu | 2b7c86e | 2017-12-08 06:47:56 -0600 | [diff] [blame] | 2399 | buf_layout.pass_frame_status = true; |
Bogdan Purcareata | 4b2d9fe | 2017-10-29 08:20:43 +0000 | [diff] [blame] | 2400 | buf_layout.pass_parser_result = true; |
Ioana Ciocoi Radulescu | 27c8748 | 2019-02-04 17:00:35 +0000 | [diff] [blame] | 2401 | buf_layout.data_align = rx_buf_align; |
Bogdan Purcareata | 4b2d9fe | 2017-10-29 08:20:43 +0000 | [diff] [blame] | 2402 | buf_layout.data_head_room = dpaa2_eth_rx_head_room(priv); |
| 2403 | buf_layout.private_data_size = 0; |
| 2404 | buf_layout.options = DPNI_BUF_LAYOUT_OPT_PARSER_RESULT | |
| 2405 | DPNI_BUF_LAYOUT_OPT_FRAME_STATUS | |
| 2406 | DPNI_BUF_LAYOUT_OPT_DATA_ALIGN | |
Ioana Radulescu | 859f998 | 2018-04-26 18:23:47 +0800 | [diff] [blame] | 2407 | DPNI_BUF_LAYOUT_OPT_DATA_HEAD_ROOM | |
| 2408 | DPNI_BUF_LAYOUT_OPT_TIMESTAMP; |
Bogdan Purcareata | 4b2d9fe | 2017-10-29 08:20:43 +0000 | [diff] [blame] | 2409 | err = dpni_set_buffer_layout(priv->mc_io, 0, priv->mc_token, |
| 2410 | DPNI_QUEUE_RX, &buf_layout); |
| 2411 | if (err) { |
| 2412 | dev_err(dev, "dpni_set_buffer_layout(RX) failed\n"); |
| 2413 | return err; |
| 2414 | } |
| 2415 | |
Ioana Radulescu | 308f64e | 2017-10-29 08:20:40 +0000 | [diff] [blame] | 2416 | return 0; |
| 2417 | } |
| 2418 | |
Ioana Ciocoi Radulescu | 1fa0f68 | 2019-02-04 17:00:36 +0000 | [diff] [blame] | 2419 | #define DPNI_ENQUEUE_FQID_VER_MAJOR 7 |
| 2420 | #define DPNI_ENQUEUE_FQID_VER_MINOR 9 |
| 2421 | |
| 2422 | static inline int dpaa2_eth_enqueue_qd(struct dpaa2_eth_priv *priv, |
| 2423 | struct dpaa2_eth_fq *fq, |
| 2424 | struct dpaa2_fd *fd, u8 prio) |
| 2425 | { |
| 2426 | return dpaa2_io_service_enqueue_qd(fq->channel->dpio, |
| 2427 | priv->tx_qdid, prio, |
| 2428 | fq->tx_qdbin, fd); |
| 2429 | } |
| 2430 | |
| 2431 | static inline int dpaa2_eth_enqueue_fq(struct dpaa2_eth_priv *priv, |
| 2432 | struct dpaa2_eth_fq *fq, |
Ioana Radulescu | 15c87f6 | 2019-06-11 14:50:02 +0300 | [diff] [blame] | 2433 | struct dpaa2_fd *fd, u8 prio) |
Ioana Ciocoi Radulescu | 1fa0f68 | 2019-02-04 17:00:36 +0000 | [diff] [blame] | 2434 | { |
| 2435 | return dpaa2_io_service_enqueue_fq(fq->channel->dpio, |
Ioana Radulescu | 15c87f6 | 2019-06-11 14:50:02 +0300 | [diff] [blame] | 2436 | fq->tx_fqid[prio], fd); |
Ioana Ciocoi Radulescu | 1fa0f68 | 2019-02-04 17:00:36 +0000 | [diff] [blame] | 2437 | } |
| 2438 | |
| 2439 | static void set_enqueue_mode(struct dpaa2_eth_priv *priv) |
| 2440 | { |
| 2441 | if (dpaa2_eth_cmp_dpni_ver(priv, DPNI_ENQUEUE_FQID_VER_MAJOR, |
| 2442 | DPNI_ENQUEUE_FQID_VER_MINOR) < 0) |
| 2443 | priv->enqueue = dpaa2_eth_enqueue_qd; |
| 2444 | else |
| 2445 | priv->enqueue = dpaa2_eth_enqueue_fq; |
| 2446 | } |
| 2447 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2448 | /* Configure the DPNI object this interface is associated with */ |
| 2449 | static int setup_dpni(struct fsl_mc_device *ls_dev) |
| 2450 | { |
| 2451 | struct device *dev = &ls_dev->dev; |
| 2452 | struct dpaa2_eth_priv *priv; |
| 2453 | struct net_device *net_dev; |
| 2454 | int err; |
| 2455 | |
| 2456 | net_dev = dev_get_drvdata(dev); |
| 2457 | priv = netdev_priv(net_dev); |
| 2458 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2459 | /* get a handle for the DPNI object */ |
Ioana Radulescu | 50eacbc | 2017-06-06 10:00:36 -0500 | [diff] [blame] | 2460 | 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] | 2461 | if (err) { |
| 2462 | dev_err(dev, "dpni_open() failed\n"); |
Ioana Radulescu | f6dda80 | 2017-10-29 08:20:39 +0000 | [diff] [blame] | 2463 | return err; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2464 | } |
| 2465 | |
Ioana Radulescu | 311cffa | 2018-03-23 08:44:09 -0500 | [diff] [blame] | 2466 | /* Check if we can work with this DPNI object */ |
| 2467 | err = dpni_get_api_version(priv->mc_io, 0, &priv->dpni_ver_major, |
| 2468 | &priv->dpni_ver_minor); |
| 2469 | if (err) { |
| 2470 | dev_err(dev, "dpni_get_api_version() failed\n"); |
| 2471 | goto close; |
| 2472 | } |
| 2473 | if (dpaa2_eth_cmp_dpni_ver(priv, DPNI_VER_MAJOR, DPNI_VER_MINOR) < 0) { |
| 2474 | dev_err(dev, "DPNI version %u.%u not supported, need >= %u.%u\n", |
| 2475 | priv->dpni_ver_major, priv->dpni_ver_minor, |
| 2476 | DPNI_VER_MAJOR, DPNI_VER_MINOR); |
| 2477 | err = -ENOTSUPP; |
| 2478 | goto close; |
| 2479 | } |
| 2480 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2481 | ls_dev->mc_io = priv->mc_io; |
| 2482 | ls_dev->mc_handle = priv->mc_token; |
| 2483 | |
| 2484 | err = dpni_reset(priv->mc_io, 0, priv->mc_token); |
| 2485 | if (err) { |
| 2486 | dev_err(dev, "dpni_reset() failed\n"); |
Ioana Radulescu | f6dda80 | 2017-10-29 08:20:39 +0000 | [diff] [blame] | 2487 | goto close; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2488 | } |
| 2489 | |
| 2490 | err = dpni_get_attributes(priv->mc_io, 0, priv->mc_token, |
| 2491 | &priv->dpni_attrs); |
| 2492 | if (err) { |
| 2493 | dev_err(dev, "dpni_get_attributes() failed (err=%d)\n", err); |
Ioana Radulescu | f6dda80 | 2017-10-29 08:20:39 +0000 | [diff] [blame] | 2494 | goto close; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2495 | } |
| 2496 | |
Ioana Radulescu | 308f64e | 2017-10-29 08:20:40 +0000 | [diff] [blame] | 2497 | err = set_buffer_layout(priv); |
| 2498 | if (err) |
Ioana Radulescu | f6dda80 | 2017-10-29 08:20:39 +0000 | [diff] [blame] | 2499 | goto close; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2500 | |
Ioana Ciocoi Radulescu | 1fa0f68 | 2019-02-04 17:00:36 +0000 | [diff] [blame] | 2501 | set_enqueue_mode(priv); |
| 2502 | |
Ioana Radulescu | afb90db | 2018-10-01 13:44:58 +0300 | [diff] [blame] | 2503 | priv->cls_rules = devm_kzalloc(dev, sizeof(struct dpaa2_eth_cls_rule) * |
| 2504 | dpaa2_eth_fs_count(priv), GFP_KERNEL); |
| 2505 | if (!priv->cls_rules) |
| 2506 | goto close; |
| 2507 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2508 | return 0; |
| 2509 | |
Ioana Radulescu | f6dda80 | 2017-10-29 08:20:39 +0000 | [diff] [blame] | 2510 | close: |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2511 | dpni_close(priv->mc_io, 0, priv->mc_token); |
Ioana Radulescu | f6dda80 | 2017-10-29 08:20:39 +0000 | [diff] [blame] | 2512 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2513 | return err; |
| 2514 | } |
| 2515 | |
| 2516 | static void free_dpni(struct dpaa2_eth_priv *priv) |
| 2517 | { |
| 2518 | int err; |
| 2519 | |
| 2520 | err = dpni_reset(priv->mc_io, 0, priv->mc_token); |
| 2521 | if (err) |
| 2522 | netdev_warn(priv->net_dev, "dpni_reset() failed (err %d)\n", |
| 2523 | err); |
| 2524 | |
| 2525 | dpni_close(priv->mc_io, 0, priv->mc_token); |
| 2526 | } |
| 2527 | |
| 2528 | static int setup_rx_flow(struct dpaa2_eth_priv *priv, |
| 2529 | struct dpaa2_eth_fq *fq) |
| 2530 | { |
| 2531 | struct device *dev = priv->net_dev->dev.parent; |
| 2532 | struct dpni_queue queue; |
| 2533 | struct dpni_queue_id qid; |
| 2534 | struct dpni_taildrop td; |
| 2535 | int err; |
| 2536 | |
| 2537 | err = dpni_get_queue(priv->mc_io, 0, priv->mc_token, |
| 2538 | DPNI_QUEUE_RX, 0, fq->flowid, &queue, &qid); |
| 2539 | if (err) { |
| 2540 | dev_err(dev, "dpni_get_queue(RX) failed\n"); |
| 2541 | return err; |
| 2542 | } |
| 2543 | |
| 2544 | fq->fqid = qid.fqid; |
| 2545 | |
| 2546 | queue.destination.id = fq->channel->dpcon_id; |
| 2547 | queue.destination.type = DPNI_DEST_DPCON; |
| 2548 | queue.destination.priority = 1; |
Ioana Radulescu | 75c583a | 2018-02-26 10:28:06 -0600 | [diff] [blame] | 2549 | queue.user_context = (u64)(uintptr_t)fq; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2550 | err = dpni_set_queue(priv->mc_io, 0, priv->mc_token, |
| 2551 | DPNI_QUEUE_RX, 0, fq->flowid, |
Ioana Radulescu | 16fa1cf | 2019-05-23 17:38:22 +0300 | [diff] [blame] | 2552 | DPNI_QUEUE_OPT_USER_CTX | DPNI_QUEUE_OPT_DEST, |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2553 | &queue); |
| 2554 | if (err) { |
| 2555 | dev_err(dev, "dpni_set_queue(RX) failed\n"); |
| 2556 | return err; |
| 2557 | } |
| 2558 | |
| 2559 | td.enable = 1; |
| 2560 | td.threshold = DPAA2_ETH_TAILDROP_THRESH; |
| 2561 | err = dpni_set_taildrop(priv->mc_io, 0, priv->mc_token, DPNI_CP_QUEUE, |
| 2562 | DPNI_QUEUE_RX, 0, fq->flowid, &td); |
| 2563 | if (err) { |
| 2564 | dev_err(dev, "dpni_set_threshold() failed\n"); |
| 2565 | return err; |
| 2566 | } |
| 2567 | |
Ioana Radulescu | d678be1 | 2019-03-01 17:47:24 +0000 | [diff] [blame] | 2568 | /* xdp_rxq setup */ |
| 2569 | err = xdp_rxq_info_reg(&fq->channel->xdp_rxq, priv->net_dev, |
| 2570 | fq->flowid); |
| 2571 | if (err) { |
| 2572 | dev_err(dev, "xdp_rxq_info_reg failed\n"); |
| 2573 | return err; |
| 2574 | } |
| 2575 | |
| 2576 | err = xdp_rxq_info_reg_mem_model(&fq->channel->xdp_rxq, |
| 2577 | MEM_TYPE_PAGE_ORDER0, NULL); |
| 2578 | if (err) { |
| 2579 | dev_err(dev, "xdp_rxq_info_reg_mem_model failed\n"); |
| 2580 | return err; |
| 2581 | } |
| 2582 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2583 | return 0; |
| 2584 | } |
| 2585 | |
| 2586 | static int setup_tx_flow(struct dpaa2_eth_priv *priv, |
| 2587 | struct dpaa2_eth_fq *fq) |
| 2588 | { |
| 2589 | struct device *dev = priv->net_dev->dev.parent; |
| 2590 | struct dpni_queue queue; |
| 2591 | struct dpni_queue_id qid; |
Ioana Radulescu | 15c87f6 | 2019-06-11 14:50:02 +0300 | [diff] [blame] | 2592 | int i, err; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2593 | |
Ioana Radulescu | 15c87f6 | 2019-06-11 14:50:02 +0300 | [diff] [blame] | 2594 | for (i = 0; i < dpaa2_eth_tc_count(priv); i++) { |
| 2595 | err = dpni_get_queue(priv->mc_io, 0, priv->mc_token, |
| 2596 | DPNI_QUEUE_TX, i, fq->flowid, |
| 2597 | &queue, &qid); |
| 2598 | if (err) { |
| 2599 | dev_err(dev, "dpni_get_queue(TX) failed\n"); |
| 2600 | return err; |
| 2601 | } |
| 2602 | fq->tx_fqid[i] = qid.fqid; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2603 | } |
| 2604 | |
Ioana Radulescu | 15c87f6 | 2019-06-11 14:50:02 +0300 | [diff] [blame] | 2605 | /* All Tx queues belonging to the same flowid have the same qdbin */ |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2606 | fq->tx_qdbin = qid.qdbin; |
| 2607 | |
| 2608 | err = dpni_get_queue(priv->mc_io, 0, priv->mc_token, |
| 2609 | DPNI_QUEUE_TX_CONFIRM, 0, fq->flowid, |
| 2610 | &queue, &qid); |
| 2611 | if (err) { |
| 2612 | dev_err(dev, "dpni_get_queue(TX_CONF) failed\n"); |
| 2613 | return err; |
| 2614 | } |
| 2615 | |
| 2616 | fq->fqid = qid.fqid; |
| 2617 | |
| 2618 | queue.destination.id = fq->channel->dpcon_id; |
| 2619 | queue.destination.type = DPNI_DEST_DPCON; |
| 2620 | queue.destination.priority = 0; |
Ioana Radulescu | 75c583a | 2018-02-26 10:28:06 -0600 | [diff] [blame] | 2621 | queue.user_context = (u64)(uintptr_t)fq; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2622 | err = dpni_set_queue(priv->mc_io, 0, priv->mc_token, |
| 2623 | DPNI_QUEUE_TX_CONFIRM, 0, fq->flowid, |
| 2624 | DPNI_QUEUE_OPT_USER_CTX | DPNI_QUEUE_OPT_DEST, |
| 2625 | &queue); |
| 2626 | if (err) { |
| 2627 | dev_err(dev, "dpni_set_queue(TX_CONF) failed\n"); |
| 2628 | return err; |
| 2629 | } |
| 2630 | |
| 2631 | return 0; |
| 2632 | } |
| 2633 | |
Ioana Ciocoi Radulescu | edad8d2 | 2018-09-24 15:36:21 +0000 | [diff] [blame] | 2634 | /* Supported header fields for Rx hash distribution key */ |
Ioana Radulescu | f76c483 | 2018-10-01 13:44:56 +0300 | [diff] [blame] | 2635 | static const struct dpaa2_eth_dist_fields dist_fields[] = { |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2636 | { |
Ioana Ciocoi Radulescu | edad8d2 | 2018-09-24 15:36:21 +0000 | [diff] [blame] | 2637 | /* L2 header */ |
| 2638 | .rxnfc_field = RXH_L2DA, |
| 2639 | .cls_prot = NET_PROT_ETH, |
| 2640 | .cls_field = NH_FLD_ETH_DA, |
Ioana Ciocoi Radulescu | 3a1e6b8 | 2019-04-16 17:13:29 +0000 | [diff] [blame] | 2641 | .id = DPAA2_ETH_DIST_ETHDST, |
Ioana Ciocoi Radulescu | edad8d2 | 2018-09-24 15:36:21 +0000 | [diff] [blame] | 2642 | .size = 6, |
| 2643 | }, { |
Ioana Radulescu | afb90db | 2018-10-01 13:44:58 +0300 | [diff] [blame] | 2644 | .cls_prot = NET_PROT_ETH, |
| 2645 | .cls_field = NH_FLD_ETH_SA, |
Ioana Ciocoi Radulescu | 3a1e6b8 | 2019-04-16 17:13:29 +0000 | [diff] [blame] | 2646 | .id = DPAA2_ETH_DIST_ETHSRC, |
Ioana Radulescu | afb90db | 2018-10-01 13:44:58 +0300 | [diff] [blame] | 2647 | .size = 6, |
| 2648 | }, { |
| 2649 | /* This is the last ethertype field parsed: |
| 2650 | * depending on frame format, it can be the MAC ethertype |
| 2651 | * or the VLAN etype. |
| 2652 | */ |
| 2653 | .cls_prot = NET_PROT_ETH, |
| 2654 | .cls_field = NH_FLD_ETH_TYPE, |
Ioana Ciocoi Radulescu | 3a1e6b8 | 2019-04-16 17:13:29 +0000 | [diff] [blame] | 2655 | .id = DPAA2_ETH_DIST_ETHTYPE, |
Ioana Radulescu | afb90db | 2018-10-01 13:44:58 +0300 | [diff] [blame] | 2656 | .size = 2, |
| 2657 | }, { |
Ioana Ciocoi Radulescu | edad8d2 | 2018-09-24 15:36:21 +0000 | [diff] [blame] | 2658 | /* VLAN header */ |
| 2659 | .rxnfc_field = RXH_VLAN, |
| 2660 | .cls_prot = NET_PROT_VLAN, |
| 2661 | .cls_field = NH_FLD_VLAN_TCI, |
Ioana Ciocoi Radulescu | 3a1e6b8 | 2019-04-16 17:13:29 +0000 | [diff] [blame] | 2662 | .id = DPAA2_ETH_DIST_VLAN, |
Ioana Ciocoi Radulescu | edad8d2 | 2018-09-24 15:36:21 +0000 | [diff] [blame] | 2663 | .size = 2, |
| 2664 | }, { |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2665 | /* IP header */ |
| 2666 | .rxnfc_field = RXH_IP_SRC, |
| 2667 | .cls_prot = NET_PROT_IP, |
| 2668 | .cls_field = NH_FLD_IP_SRC, |
Ioana Ciocoi Radulescu | 3a1e6b8 | 2019-04-16 17:13:29 +0000 | [diff] [blame] | 2669 | .id = DPAA2_ETH_DIST_IPSRC, |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2670 | .size = 4, |
| 2671 | }, { |
| 2672 | .rxnfc_field = RXH_IP_DST, |
| 2673 | .cls_prot = NET_PROT_IP, |
| 2674 | .cls_field = NH_FLD_IP_DST, |
Ioana Ciocoi Radulescu | 3a1e6b8 | 2019-04-16 17:13:29 +0000 | [diff] [blame] | 2675 | .id = DPAA2_ETH_DIST_IPDST, |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2676 | .size = 4, |
| 2677 | }, { |
| 2678 | .rxnfc_field = RXH_L3_PROTO, |
| 2679 | .cls_prot = NET_PROT_IP, |
| 2680 | .cls_field = NH_FLD_IP_PROTO, |
Ioana Ciocoi Radulescu | 3a1e6b8 | 2019-04-16 17:13:29 +0000 | [diff] [blame] | 2681 | .id = DPAA2_ETH_DIST_IPPROTO, |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2682 | .size = 1, |
| 2683 | }, { |
| 2684 | /* Using UDP ports, this is functionally equivalent to raw |
| 2685 | * byte pairs from L4 header. |
| 2686 | */ |
| 2687 | .rxnfc_field = RXH_L4_B_0_1, |
| 2688 | .cls_prot = NET_PROT_UDP, |
| 2689 | .cls_field = NH_FLD_UDP_PORT_SRC, |
Ioana Ciocoi Radulescu | 3a1e6b8 | 2019-04-16 17:13:29 +0000 | [diff] [blame] | 2690 | .id = DPAA2_ETH_DIST_L4SRC, |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2691 | .size = 2, |
| 2692 | }, { |
| 2693 | .rxnfc_field = RXH_L4_B_2_3, |
| 2694 | .cls_prot = NET_PROT_UDP, |
| 2695 | .cls_field = NH_FLD_UDP_PORT_DST, |
Ioana Ciocoi Radulescu | 3a1e6b8 | 2019-04-16 17:13:29 +0000 | [diff] [blame] | 2696 | .id = DPAA2_ETH_DIST_L4DST, |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2697 | .size = 2, |
| 2698 | }, |
| 2699 | }; |
| 2700 | |
Ioana Radulescu | df85aeb | 2018-10-01 13:44:55 +0300 | [diff] [blame] | 2701 | /* Configure the Rx hash key using the legacy API */ |
| 2702 | static int config_legacy_hash_key(struct dpaa2_eth_priv *priv, dma_addr_t key) |
| 2703 | { |
| 2704 | struct device *dev = priv->net_dev->dev.parent; |
| 2705 | struct dpni_rx_tc_dist_cfg dist_cfg; |
| 2706 | int err; |
| 2707 | |
| 2708 | memset(&dist_cfg, 0, sizeof(dist_cfg)); |
| 2709 | |
| 2710 | dist_cfg.key_cfg_iova = key; |
| 2711 | dist_cfg.dist_size = dpaa2_eth_queue_count(priv); |
| 2712 | dist_cfg.dist_mode = DPNI_DIST_MODE_HASH; |
| 2713 | |
| 2714 | err = dpni_set_rx_tc_dist(priv->mc_io, 0, priv->mc_token, 0, &dist_cfg); |
| 2715 | if (err) |
| 2716 | dev_err(dev, "dpni_set_rx_tc_dist failed\n"); |
| 2717 | |
| 2718 | return err; |
| 2719 | } |
| 2720 | |
| 2721 | /* Configure the Rx hash key using the new API */ |
| 2722 | static int config_hash_key(struct dpaa2_eth_priv *priv, dma_addr_t key) |
| 2723 | { |
| 2724 | struct device *dev = priv->net_dev->dev.parent; |
| 2725 | struct dpni_rx_dist_cfg dist_cfg; |
| 2726 | int err; |
| 2727 | |
| 2728 | memset(&dist_cfg, 0, sizeof(dist_cfg)); |
| 2729 | |
| 2730 | dist_cfg.key_cfg_iova = key; |
| 2731 | dist_cfg.dist_size = dpaa2_eth_queue_count(priv); |
| 2732 | dist_cfg.enable = 1; |
| 2733 | |
| 2734 | err = dpni_set_rx_hash_dist(priv->mc_io, 0, priv->mc_token, &dist_cfg); |
| 2735 | if (err) |
| 2736 | dev_err(dev, "dpni_set_rx_hash_dist failed\n"); |
| 2737 | |
| 2738 | return err; |
| 2739 | } |
| 2740 | |
Ioana Radulescu | 4aaaf9b | 2018-10-01 13:44:57 +0300 | [diff] [blame] | 2741 | /* Configure the Rx flow classification key */ |
| 2742 | static int config_cls_key(struct dpaa2_eth_priv *priv, dma_addr_t key) |
| 2743 | { |
| 2744 | struct device *dev = priv->net_dev->dev.parent; |
| 2745 | struct dpni_rx_dist_cfg dist_cfg; |
| 2746 | int err; |
| 2747 | |
| 2748 | memset(&dist_cfg, 0, sizeof(dist_cfg)); |
| 2749 | |
| 2750 | dist_cfg.key_cfg_iova = key; |
| 2751 | dist_cfg.dist_size = dpaa2_eth_queue_count(priv); |
| 2752 | dist_cfg.enable = 1; |
| 2753 | |
| 2754 | err = dpni_set_rx_fs_dist(priv->mc_io, 0, priv->mc_token, &dist_cfg); |
| 2755 | if (err) |
| 2756 | dev_err(dev, "dpni_set_rx_fs_dist failed\n"); |
| 2757 | |
| 2758 | return err; |
| 2759 | } |
| 2760 | |
Ioana Radulescu | afb90db | 2018-10-01 13:44:58 +0300 | [diff] [blame] | 2761 | /* Size of the Rx flow classification key */ |
Ioana Ciocoi Radulescu | 2d68023 | 2019-04-16 17:13:30 +0000 | [diff] [blame] | 2762 | int dpaa2_eth_cls_key_size(u64 fields) |
Ioana Radulescu | afb90db | 2018-10-01 13:44:58 +0300 | [diff] [blame] | 2763 | { |
| 2764 | int i, size = 0; |
| 2765 | |
Ioana Ciocoi Radulescu | 2d68023 | 2019-04-16 17:13:30 +0000 | [diff] [blame] | 2766 | for (i = 0; i < ARRAY_SIZE(dist_fields); i++) { |
| 2767 | if (!(fields & dist_fields[i].id)) |
| 2768 | continue; |
Ioana Radulescu | afb90db | 2018-10-01 13:44:58 +0300 | [diff] [blame] | 2769 | size += dist_fields[i].size; |
Ioana Ciocoi Radulescu | 2d68023 | 2019-04-16 17:13:30 +0000 | [diff] [blame] | 2770 | } |
Ioana Radulescu | afb90db | 2018-10-01 13:44:58 +0300 | [diff] [blame] | 2771 | |
| 2772 | return size; |
| 2773 | } |
| 2774 | |
| 2775 | /* Offset of header field in Rx classification key */ |
| 2776 | int dpaa2_eth_cls_fld_off(int prot, int field) |
| 2777 | { |
| 2778 | int i, off = 0; |
| 2779 | |
| 2780 | for (i = 0; i < ARRAY_SIZE(dist_fields); i++) { |
| 2781 | if (dist_fields[i].cls_prot == prot && |
| 2782 | dist_fields[i].cls_field == field) |
| 2783 | return off; |
| 2784 | off += dist_fields[i].size; |
| 2785 | } |
| 2786 | |
| 2787 | WARN_ONCE(1, "Unsupported header field used for Rx flow cls\n"); |
| 2788 | return 0; |
| 2789 | } |
| 2790 | |
Ioana Ciocoi Radulescu | 2d68023 | 2019-04-16 17:13:30 +0000 | [diff] [blame] | 2791 | /* Prune unused fields from the classification rule. |
| 2792 | * Used when masking is not supported |
| 2793 | */ |
| 2794 | void dpaa2_eth_cls_trim_rule(void *key_mem, u64 fields) |
| 2795 | { |
| 2796 | int off = 0, new_off = 0; |
| 2797 | int i, size; |
| 2798 | |
| 2799 | for (i = 0; i < ARRAY_SIZE(dist_fields); i++) { |
| 2800 | size = dist_fields[i].size; |
| 2801 | if (dist_fields[i].id & fields) { |
| 2802 | memcpy(key_mem + new_off, key_mem + off, size); |
| 2803 | new_off += size; |
| 2804 | } |
| 2805 | off += size; |
| 2806 | } |
| 2807 | } |
| 2808 | |
Ioana Radulescu | 4aaaf9b | 2018-10-01 13:44:57 +0300 | [diff] [blame] | 2809 | /* Set Rx distribution (hash or flow classification) key |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2810 | * flags is a combination of RXH_ bits |
| 2811 | */ |
Ioana Ciornei | 3233c15 | 2018-10-12 16:27:29 +0000 | [diff] [blame] | 2812 | static int dpaa2_eth_set_dist_key(struct net_device *net_dev, |
| 2813 | enum dpaa2_eth_rx_dist type, u64 flags) |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2814 | { |
| 2815 | struct device *dev = net_dev->dev.parent; |
| 2816 | struct dpaa2_eth_priv *priv = netdev_priv(net_dev); |
| 2817 | struct dpkg_profile_cfg cls_cfg; |
Ioana Ciocoi Radulescu | edad8d2 | 2018-09-24 15:36:21 +0000 | [diff] [blame] | 2818 | u32 rx_hash_fields = 0; |
Ioana Radulescu | df85aeb | 2018-10-01 13:44:55 +0300 | [diff] [blame] | 2819 | dma_addr_t key_iova; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2820 | u8 *dma_mem; |
| 2821 | int i; |
| 2822 | int err = 0; |
| 2823 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2824 | memset(&cls_cfg, 0, sizeof(cls_cfg)); |
| 2825 | |
Ioana Radulescu | f76c483 | 2018-10-01 13:44:56 +0300 | [diff] [blame] | 2826 | for (i = 0; i < ARRAY_SIZE(dist_fields); i++) { |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2827 | struct dpkg_extract *key = |
| 2828 | &cls_cfg.extracts[cls_cfg.num_extracts]; |
| 2829 | |
Ioana Ciocoi Radulescu | 2d68023 | 2019-04-16 17:13:30 +0000 | [diff] [blame] | 2830 | /* For both Rx hashing and classification keys |
| 2831 | * we set only the selected fields. |
Ioana Radulescu | 4aaaf9b | 2018-10-01 13:44:57 +0300 | [diff] [blame] | 2832 | */ |
Ioana Ciocoi Radulescu | 2d68023 | 2019-04-16 17:13:30 +0000 | [diff] [blame] | 2833 | if (!(flags & dist_fields[i].id)) |
| 2834 | continue; |
| 2835 | if (type == DPAA2_ETH_RX_DIST_HASH) |
Ioana Radulescu | 4aaaf9b | 2018-10-01 13:44:57 +0300 | [diff] [blame] | 2836 | rx_hash_fields |= dist_fields[i].rxnfc_field; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2837 | |
| 2838 | if (cls_cfg.num_extracts >= DPKG_MAX_NUM_OF_EXTRACTS) { |
| 2839 | dev_err(dev, "error adding key extraction rule, too many rules?\n"); |
| 2840 | return -E2BIG; |
| 2841 | } |
| 2842 | |
| 2843 | key->type = DPKG_EXTRACT_FROM_HDR; |
Ioana Radulescu | f76c483 | 2018-10-01 13:44:56 +0300 | [diff] [blame] | 2844 | key->extract.from_hdr.prot = dist_fields[i].cls_prot; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2845 | key->extract.from_hdr.type = DPKG_FULL_FIELD; |
Ioana Radulescu | f76c483 | 2018-10-01 13:44:56 +0300 | [diff] [blame] | 2846 | key->extract.from_hdr.field = dist_fields[i].cls_field; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2847 | cls_cfg.num_extracts++; |
| 2848 | } |
| 2849 | |
Ioana Radulescu | e40ef9e | 2017-06-06 10:00:30 -0500 | [diff] [blame] | 2850 | dma_mem = kzalloc(DPAA2_CLASSIFIER_DMA_SIZE, GFP_KERNEL); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2851 | if (!dma_mem) |
| 2852 | return -ENOMEM; |
| 2853 | |
| 2854 | err = dpni_prepare_key_cfg(&cls_cfg, dma_mem); |
| 2855 | if (err) { |
Ioana Radulescu | 77160af | 2017-06-06 10:00:28 -0500 | [diff] [blame] | 2856 | dev_err(dev, "dpni_prepare_key_cfg error %d\n", err); |
Ioana Radulescu | df85aeb | 2018-10-01 13:44:55 +0300 | [diff] [blame] | 2857 | goto free_key; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2858 | } |
| 2859 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2860 | /* Prepare for setting the rx dist */ |
Ioana Radulescu | df85aeb | 2018-10-01 13:44:55 +0300 | [diff] [blame] | 2861 | key_iova = dma_map_single(dev, dma_mem, DPAA2_CLASSIFIER_DMA_SIZE, |
| 2862 | DMA_TO_DEVICE); |
| 2863 | if (dma_mapping_error(dev, key_iova)) { |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2864 | dev_err(dev, "DMA mapping failed\n"); |
| 2865 | err = -ENOMEM; |
Ioana Radulescu | df85aeb | 2018-10-01 13:44:55 +0300 | [diff] [blame] | 2866 | goto free_key; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2867 | } |
| 2868 | |
Ioana Radulescu | 4aaaf9b | 2018-10-01 13:44:57 +0300 | [diff] [blame] | 2869 | if (type == DPAA2_ETH_RX_DIST_HASH) { |
| 2870 | if (dpaa2_eth_has_legacy_dist(priv)) |
| 2871 | err = config_legacy_hash_key(priv, key_iova); |
| 2872 | else |
| 2873 | err = config_hash_key(priv, key_iova); |
| 2874 | } else { |
| 2875 | err = config_cls_key(priv, key_iova); |
| 2876 | } |
Ioana Radulescu | df85aeb | 2018-10-01 13:44:55 +0300 | [diff] [blame] | 2877 | |
| 2878 | dma_unmap_single(dev, key_iova, DPAA2_CLASSIFIER_DMA_SIZE, |
| 2879 | DMA_TO_DEVICE); |
Ioana Radulescu | 4aaaf9b | 2018-10-01 13:44:57 +0300 | [diff] [blame] | 2880 | if (!err && type == DPAA2_ETH_RX_DIST_HASH) |
Ioana Ciocoi Radulescu | edad8d2 | 2018-09-24 15:36:21 +0000 | [diff] [blame] | 2881 | priv->rx_hash_fields = rx_hash_fields; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2882 | |
Ioana Radulescu | df85aeb | 2018-10-01 13:44:55 +0300 | [diff] [blame] | 2883 | free_key: |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2884 | kfree(dma_mem); |
| 2885 | return err; |
| 2886 | } |
| 2887 | |
Ioana Radulescu | 4aaaf9b | 2018-10-01 13:44:57 +0300 | [diff] [blame] | 2888 | int dpaa2_eth_set_hash(struct net_device *net_dev, u64 flags) |
| 2889 | { |
| 2890 | struct dpaa2_eth_priv *priv = netdev_priv(net_dev); |
Ioana Ciocoi Radulescu | 3a1e6b8 | 2019-04-16 17:13:29 +0000 | [diff] [blame] | 2891 | u64 key = 0; |
| 2892 | int i; |
Ioana Radulescu | 4aaaf9b | 2018-10-01 13:44:57 +0300 | [diff] [blame] | 2893 | |
| 2894 | if (!dpaa2_eth_hash_enabled(priv)) |
| 2895 | return -EOPNOTSUPP; |
| 2896 | |
Ioana Ciocoi Radulescu | 3a1e6b8 | 2019-04-16 17:13:29 +0000 | [diff] [blame] | 2897 | for (i = 0; i < ARRAY_SIZE(dist_fields); i++) |
| 2898 | if (dist_fields[i].rxnfc_field & flags) |
| 2899 | key |= dist_fields[i].id; |
| 2900 | |
| 2901 | 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] | 2902 | } |
| 2903 | |
Ioana Ciocoi Radulescu | 2d68023 | 2019-04-16 17:13:30 +0000 | [diff] [blame] | 2904 | int dpaa2_eth_set_cls(struct net_device *net_dev, u64 flags) |
| 2905 | { |
| 2906 | return dpaa2_eth_set_dist_key(net_dev, DPAA2_ETH_RX_DIST_CLS, flags); |
| 2907 | } |
| 2908 | |
| 2909 | static int dpaa2_eth_set_default_cls(struct dpaa2_eth_priv *priv) |
Ioana Radulescu | 4aaaf9b | 2018-10-01 13:44:57 +0300 | [diff] [blame] | 2910 | { |
| 2911 | struct device *dev = priv->net_dev->dev.parent; |
Ioana Ciocoi Radulescu | df8e249 | 2019-04-16 17:13:28 +0000 | [diff] [blame] | 2912 | int err; |
Ioana Radulescu | 4aaaf9b | 2018-10-01 13:44:57 +0300 | [diff] [blame] | 2913 | |
| 2914 | /* Check if we actually support Rx flow classification */ |
| 2915 | if (dpaa2_eth_has_legacy_dist(priv)) { |
| 2916 | dev_dbg(dev, "Rx cls not supported by current MC version\n"); |
| 2917 | return -EOPNOTSUPP; |
| 2918 | } |
| 2919 | |
Ioana Ciocoi Radulescu | 2d68023 | 2019-04-16 17:13:30 +0000 | [diff] [blame] | 2920 | if (!dpaa2_eth_fs_enabled(priv)) { |
Ioana Radulescu | 4aaaf9b | 2018-10-01 13:44:57 +0300 | [diff] [blame] | 2921 | dev_dbg(dev, "Rx cls disabled in DPNI options\n"); |
| 2922 | return -EOPNOTSUPP; |
| 2923 | } |
| 2924 | |
| 2925 | if (!dpaa2_eth_hash_enabled(priv)) { |
| 2926 | dev_dbg(dev, "Rx cls disabled for single queue DPNIs\n"); |
| 2927 | return -EOPNOTSUPP; |
| 2928 | } |
| 2929 | |
Ioana Ciocoi Radulescu | 2d68023 | 2019-04-16 17:13:30 +0000 | [diff] [blame] | 2930 | /* If there is no support for masking in the classification table, |
| 2931 | * we don't set a default key, as it will depend on the rules |
| 2932 | * added by the user at runtime. |
| 2933 | */ |
| 2934 | if (!dpaa2_eth_fs_mask_enabled(priv)) |
| 2935 | goto out; |
| 2936 | |
| 2937 | 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] | 2938 | if (err) |
| 2939 | return err; |
| 2940 | |
Ioana Ciocoi Radulescu | 2d68023 | 2019-04-16 17:13:30 +0000 | [diff] [blame] | 2941 | out: |
Ioana Radulescu | 4aaaf9b | 2018-10-01 13:44:57 +0300 | [diff] [blame] | 2942 | priv->rx_cls_enabled = 1; |
| 2943 | |
Ioana Ciocoi Radulescu | df8e249 | 2019-04-16 17:13:28 +0000 | [diff] [blame] | 2944 | return 0; |
Ioana Radulescu | 4aaaf9b | 2018-10-01 13:44:57 +0300 | [diff] [blame] | 2945 | } |
| 2946 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2947 | /* Bind the DPNI to its needed objects and resources: buffer pool, DPIOs, |
| 2948 | * frame queues and channels |
| 2949 | */ |
| 2950 | static int bind_dpni(struct dpaa2_eth_priv *priv) |
| 2951 | { |
| 2952 | struct net_device *net_dev = priv->net_dev; |
| 2953 | struct device *dev = net_dev->dev.parent; |
| 2954 | struct dpni_pools_cfg pools_params; |
| 2955 | struct dpni_error_cfg err_cfg; |
| 2956 | int err = 0; |
| 2957 | int i; |
| 2958 | |
| 2959 | pools_params.num_dpbp = 1; |
| 2960 | pools_params.pools[0].dpbp_id = priv->dpbp_dev->obj_desc.id; |
| 2961 | pools_params.pools[0].backup_pool = 0; |
| 2962 | pools_params.pools[0].buffer_size = DPAA2_ETH_RX_BUF_SIZE; |
| 2963 | err = dpni_set_pools(priv->mc_io, 0, priv->mc_token, &pools_params); |
| 2964 | if (err) { |
| 2965 | dev_err(dev, "dpni_set_pools() failed\n"); |
| 2966 | return err; |
| 2967 | } |
| 2968 | |
Ioana Radulescu | 227686b | 2018-07-27 09:12:59 -0500 | [diff] [blame] | 2969 | /* have the interface implicitly distribute traffic based on |
| 2970 | * the default hash key |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2971 | */ |
Ioana Radulescu | 227686b | 2018-07-27 09:12:59 -0500 | [diff] [blame] | 2972 | err = dpaa2_eth_set_hash(net_dev, DPAA2_RXH_DEFAULT); |
Ioana Ciocoi Radulescu | edad8d2 | 2018-09-24 15:36:21 +0000 | [diff] [blame] | 2973 | if (err && err != -EOPNOTSUPP) |
Ioana Radulescu | 0f4c295 | 2017-10-11 08:29:50 -0500 | [diff] [blame] | 2974 | dev_err(dev, "Failed to configure hashing\n"); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2975 | |
Ioana Radulescu | 4aaaf9b | 2018-10-01 13:44:57 +0300 | [diff] [blame] | 2976 | /* Configure the flow classification key; it includes all |
| 2977 | * supported header fields and cannot be modified at runtime |
| 2978 | */ |
Ioana Ciocoi Radulescu | 2d68023 | 2019-04-16 17:13:30 +0000 | [diff] [blame] | 2979 | err = dpaa2_eth_set_default_cls(priv); |
Ioana Radulescu | 4aaaf9b | 2018-10-01 13:44:57 +0300 | [diff] [blame] | 2980 | if (err && err != -EOPNOTSUPP) |
| 2981 | dev_err(dev, "Failed to configure Rx classification key\n"); |
| 2982 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2983 | /* Configure handling of error frames */ |
Ioana Radulescu | 39163c0 | 2017-06-06 10:00:39 -0500 | [diff] [blame] | 2984 | err_cfg.errors = DPAA2_FAS_RX_ERR_MASK; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 2985 | err_cfg.set_frame_annotation = 1; |
| 2986 | err_cfg.error_action = DPNI_ERROR_ACTION_DISCARD; |
| 2987 | err = dpni_set_errors_behavior(priv->mc_io, 0, priv->mc_token, |
| 2988 | &err_cfg); |
| 2989 | if (err) { |
| 2990 | dev_err(dev, "dpni_set_errors_behavior failed\n"); |
| 2991 | return err; |
| 2992 | } |
| 2993 | |
| 2994 | /* Configure Rx and Tx conf queues to generate CDANs */ |
| 2995 | for (i = 0; i < priv->num_fqs; i++) { |
| 2996 | switch (priv->fq[i].type) { |
| 2997 | case DPAA2_RX_FQ: |
| 2998 | err = setup_rx_flow(priv, &priv->fq[i]); |
| 2999 | break; |
| 3000 | case DPAA2_TX_CONF_FQ: |
| 3001 | err = setup_tx_flow(priv, &priv->fq[i]); |
| 3002 | break; |
| 3003 | default: |
| 3004 | dev_err(dev, "Invalid FQ type %d\n", priv->fq[i].type); |
| 3005 | return -EINVAL; |
| 3006 | } |
| 3007 | if (err) |
| 3008 | return err; |
| 3009 | } |
| 3010 | |
| 3011 | err = dpni_get_qdid(priv->mc_io, 0, priv->mc_token, |
| 3012 | DPNI_QUEUE_TX, &priv->tx_qdid); |
| 3013 | if (err) { |
| 3014 | dev_err(dev, "dpni_get_qdid() failed\n"); |
| 3015 | return err; |
| 3016 | } |
| 3017 | |
| 3018 | return 0; |
| 3019 | } |
| 3020 | |
| 3021 | /* Allocate rings for storing incoming frame descriptors */ |
| 3022 | static int alloc_rings(struct dpaa2_eth_priv *priv) |
| 3023 | { |
| 3024 | struct net_device *net_dev = priv->net_dev; |
| 3025 | struct device *dev = net_dev->dev.parent; |
| 3026 | int i; |
| 3027 | |
| 3028 | for (i = 0; i < priv->num_channels; i++) { |
| 3029 | priv->channel[i]->store = |
| 3030 | dpaa2_io_store_create(DPAA2_ETH_STORE_SIZE, dev); |
| 3031 | if (!priv->channel[i]->store) { |
| 3032 | netdev_err(net_dev, "dpaa2_io_store_create() failed\n"); |
| 3033 | goto err_ring; |
| 3034 | } |
| 3035 | } |
| 3036 | |
| 3037 | return 0; |
| 3038 | |
| 3039 | err_ring: |
| 3040 | for (i = 0; i < priv->num_channels; i++) { |
| 3041 | if (!priv->channel[i]->store) |
| 3042 | break; |
| 3043 | dpaa2_io_store_destroy(priv->channel[i]->store); |
| 3044 | } |
| 3045 | |
| 3046 | return -ENOMEM; |
| 3047 | } |
| 3048 | |
| 3049 | static void free_rings(struct dpaa2_eth_priv *priv) |
| 3050 | { |
| 3051 | int i; |
| 3052 | |
| 3053 | for (i = 0; i < priv->num_channels; i++) |
| 3054 | dpaa2_io_store_destroy(priv->channel[i]->store); |
| 3055 | } |
| 3056 | |
Ioana Radulescu | 6ab0086 | 2017-06-06 10:00:40 -0500 | [diff] [blame] | 3057 | static int set_mac_addr(struct dpaa2_eth_priv *priv) |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3058 | { |
Ioana Radulescu | 6ab0086 | 2017-06-06 10:00:40 -0500 | [diff] [blame] | 3059 | struct net_device *net_dev = priv->net_dev; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3060 | struct device *dev = net_dev->dev.parent; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3061 | u8 mac_addr[ETH_ALEN], dpni_mac_addr[ETH_ALEN]; |
Ioana Radulescu | 6ab0086 | 2017-06-06 10:00:40 -0500 | [diff] [blame] | 3062 | int err; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3063 | |
| 3064 | /* Get firmware address, if any */ |
| 3065 | err = dpni_get_port_mac_addr(priv->mc_io, 0, priv->mc_token, mac_addr); |
| 3066 | if (err) { |
| 3067 | dev_err(dev, "dpni_get_port_mac_addr() failed\n"); |
| 3068 | return err; |
| 3069 | } |
| 3070 | |
| 3071 | /* Get DPNI attributes address, if any */ |
| 3072 | err = dpni_get_primary_mac_addr(priv->mc_io, 0, priv->mc_token, |
| 3073 | dpni_mac_addr); |
| 3074 | if (err) { |
Ioana Radulescu | 6ab0086 | 2017-06-06 10:00:40 -0500 | [diff] [blame] | 3075 | dev_err(dev, "dpni_get_primary_mac_addr() failed\n"); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3076 | return err; |
| 3077 | } |
| 3078 | |
| 3079 | /* First check if firmware has any address configured by bootloader */ |
| 3080 | if (!is_zero_ether_addr(mac_addr)) { |
| 3081 | /* If the DPMAC addr != DPNI addr, update it */ |
| 3082 | if (!ether_addr_equal(mac_addr, dpni_mac_addr)) { |
| 3083 | err = dpni_set_primary_mac_addr(priv->mc_io, 0, |
| 3084 | priv->mc_token, |
| 3085 | mac_addr); |
| 3086 | if (err) { |
| 3087 | dev_err(dev, "dpni_set_primary_mac_addr() failed\n"); |
| 3088 | return err; |
| 3089 | } |
| 3090 | } |
| 3091 | memcpy(net_dev->dev_addr, mac_addr, net_dev->addr_len); |
| 3092 | } else if (is_zero_ether_addr(dpni_mac_addr)) { |
Ioana Radulescu | 6ab0086 | 2017-06-06 10:00:40 -0500 | [diff] [blame] | 3093 | /* No MAC address configured, fill in net_dev->dev_addr |
| 3094 | * with a random one |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3095 | */ |
| 3096 | eth_hw_addr_random(net_dev); |
Ioana Radulescu | 6ab0086 | 2017-06-06 10:00:40 -0500 | [diff] [blame] | 3097 | dev_dbg_once(dev, "device(s) have all-zero hwaddr, replaced with random\n"); |
| 3098 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3099 | err = dpni_set_primary_mac_addr(priv->mc_io, 0, priv->mc_token, |
| 3100 | net_dev->dev_addr); |
| 3101 | if (err) { |
Ioana Radulescu | 6ab0086 | 2017-06-06 10:00:40 -0500 | [diff] [blame] | 3102 | dev_err(dev, "dpni_set_primary_mac_addr() failed\n"); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3103 | return err; |
| 3104 | } |
Ioana Radulescu | 6ab0086 | 2017-06-06 10:00:40 -0500 | [diff] [blame] | 3105 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3106 | /* Override NET_ADDR_RANDOM set by eth_hw_addr_random(); for all |
| 3107 | * practical purposes, this will be our "permanent" mac address, |
| 3108 | * at least until the next reboot. This move will also permit |
| 3109 | * register_netdevice() to properly fill up net_dev->perm_addr. |
| 3110 | */ |
| 3111 | net_dev->addr_assign_type = NET_ADDR_PERM; |
| 3112 | } else { |
| 3113 | /* NET_ADDR_PERM is default, all we have to do is |
| 3114 | * fill in the device addr. |
| 3115 | */ |
| 3116 | memcpy(net_dev->dev_addr, dpni_mac_addr, net_dev->addr_len); |
| 3117 | } |
| 3118 | |
Ioana Radulescu | 6ab0086 | 2017-06-06 10:00:40 -0500 | [diff] [blame] | 3119 | return 0; |
| 3120 | } |
| 3121 | |
| 3122 | static int netdev_init(struct net_device *net_dev) |
| 3123 | { |
| 3124 | struct device *dev = net_dev->dev.parent; |
| 3125 | struct dpaa2_eth_priv *priv = netdev_priv(net_dev); |
Ioana Radulescu | 7f12c8a3 | 2018-08-29 04:42:39 -0500 | [diff] [blame] | 3126 | u32 options = priv->dpni_attrs.options; |
| 3127 | u64 supported = 0, not_supported = 0; |
Ioana Radulescu | 6ab0086 | 2017-06-06 10:00:40 -0500 | [diff] [blame] | 3128 | u8 bcast_addr[ETH_ALEN]; |
Ioana Radulescu | bb5b42c | 2017-06-06 10:00:41 -0500 | [diff] [blame] | 3129 | u8 num_queues; |
Ioana Radulescu | 6ab0086 | 2017-06-06 10:00:40 -0500 | [diff] [blame] | 3130 | int err; |
| 3131 | |
| 3132 | net_dev->netdev_ops = &dpaa2_eth_ops; |
Ioana Radulescu | 7f12c8a3 | 2018-08-29 04:42:39 -0500 | [diff] [blame] | 3133 | net_dev->ethtool_ops = &dpaa2_ethtool_ops; |
Ioana Radulescu | 6ab0086 | 2017-06-06 10:00:40 -0500 | [diff] [blame] | 3134 | |
| 3135 | err = set_mac_addr(priv); |
| 3136 | if (err) |
| 3137 | return err; |
| 3138 | |
| 3139 | /* Explicitly add the broadcast address to the MAC filtering table */ |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3140 | eth_broadcast_addr(bcast_addr); |
| 3141 | err = dpni_add_mac_addr(priv->mc_io, 0, priv->mc_token, bcast_addr); |
| 3142 | if (err) { |
Ioana Radulescu | 6ab0086 | 2017-06-06 10:00:40 -0500 | [diff] [blame] | 3143 | dev_err(dev, "dpni_add_mac_addr() failed\n"); |
| 3144 | return err; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3145 | } |
| 3146 | |
Ioana Radulescu | 3ccc8d4 | 2018-07-09 10:01:10 -0500 | [diff] [blame] | 3147 | /* Set MTU upper limit; lower limit is 68B (default value) */ |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3148 | net_dev->max_mtu = DPAA2_ETH_MAX_MTU; |
Ioana Radulescu | 00fee00 | 2018-07-09 10:01:11 -0500 | [diff] [blame] | 3149 | 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] | 3150 | DPAA2_ETH_MFL); |
Ioana Radulescu | 00fee00 | 2018-07-09 10:01:11 -0500 | [diff] [blame] | 3151 | if (err) { |
| 3152 | dev_err(dev, "dpni_set_max_frame_length() failed\n"); |
| 3153 | return err; |
| 3154 | } |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3155 | |
Ioana Radulescu | bb5b42c | 2017-06-06 10:00:41 -0500 | [diff] [blame] | 3156 | /* Set actual number of queues in the net device */ |
| 3157 | num_queues = dpaa2_eth_queue_count(priv); |
| 3158 | err = netif_set_real_num_tx_queues(net_dev, num_queues); |
| 3159 | if (err) { |
| 3160 | dev_err(dev, "netif_set_real_num_tx_queues() failed\n"); |
| 3161 | return err; |
| 3162 | } |
| 3163 | err = netif_set_real_num_rx_queues(net_dev, num_queues); |
| 3164 | if (err) { |
| 3165 | dev_err(dev, "netif_set_real_num_rx_queues() failed\n"); |
| 3166 | return err; |
| 3167 | } |
| 3168 | |
Ioana Radulescu | 7f12c8a3 | 2018-08-29 04:42:39 -0500 | [diff] [blame] | 3169 | /* Capabilities listing */ |
| 3170 | supported |= IFF_LIVE_ADDR_CHANGE; |
| 3171 | |
| 3172 | if (options & DPNI_OPT_NO_MAC_FILTER) |
| 3173 | not_supported |= IFF_UNICAST_FLT; |
| 3174 | else |
| 3175 | supported |= IFF_UNICAST_FLT; |
| 3176 | |
| 3177 | net_dev->priv_flags |= supported; |
| 3178 | net_dev->priv_flags &= ~not_supported; |
| 3179 | |
| 3180 | /* Features */ |
| 3181 | net_dev->features = NETIF_F_RXCSUM | |
| 3182 | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | |
| 3183 | NETIF_F_SG | NETIF_F_HIGHDMA | |
| 3184 | NETIF_F_LLTX; |
| 3185 | net_dev->hw_features = net_dev->features; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3186 | |
| 3187 | return 0; |
| 3188 | } |
| 3189 | |
| 3190 | static int poll_link_state(void *arg) |
| 3191 | { |
| 3192 | struct dpaa2_eth_priv *priv = (struct dpaa2_eth_priv *)arg; |
| 3193 | int err; |
| 3194 | |
| 3195 | while (!kthread_should_stop()) { |
| 3196 | err = link_state_update(priv); |
| 3197 | if (unlikely(err)) |
| 3198 | return err; |
| 3199 | |
| 3200 | msleep(DPAA2_ETH_LINK_STATE_REFRESH); |
| 3201 | } |
| 3202 | |
| 3203 | return 0; |
| 3204 | } |
| 3205 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3206 | static irqreturn_t dpni_irq0_handler_thread(int irq_num, void *arg) |
| 3207 | { |
Ioana Radulescu | 112197d | 2017-10-11 08:29:49 -0500 | [diff] [blame] | 3208 | u32 status = ~0; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3209 | struct device *dev = (struct device *)arg; |
| 3210 | struct fsl_mc_device *dpni_dev = to_fsl_mc_device(dev); |
| 3211 | struct net_device *net_dev = dev_get_drvdata(dev); |
| 3212 | int err; |
| 3213 | |
| 3214 | err = dpni_get_irq_status(dpni_dev->mc_io, 0, dpni_dev->mc_handle, |
| 3215 | DPNI_IRQ_INDEX, &status); |
| 3216 | if (unlikely(err)) { |
Ioana Radulescu | 77160af | 2017-06-06 10:00:28 -0500 | [diff] [blame] | 3217 | 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] | 3218 | return IRQ_HANDLED; |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3219 | } |
| 3220 | |
Ioana Radulescu | 112197d | 2017-10-11 08:29:49 -0500 | [diff] [blame] | 3221 | if (status & DPNI_IRQ_EVENT_LINK_CHANGED) |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3222 | link_state_update(netdev_priv(net_dev)); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3223 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3224 | return IRQ_HANDLED; |
| 3225 | } |
| 3226 | |
| 3227 | static int setup_irqs(struct fsl_mc_device *ls_dev) |
| 3228 | { |
| 3229 | int err = 0; |
| 3230 | struct fsl_mc_device_irq *irq; |
| 3231 | |
| 3232 | err = fsl_mc_allocate_irqs(ls_dev); |
| 3233 | if (err) { |
| 3234 | dev_err(&ls_dev->dev, "MC irqs allocation failed\n"); |
| 3235 | return err; |
| 3236 | } |
| 3237 | |
| 3238 | irq = ls_dev->irqs[0]; |
| 3239 | err = devm_request_threaded_irq(&ls_dev->dev, irq->msi_desc->irq, |
Ioana Radulescu | fdc9b53 | 2018-03-23 08:44:05 -0500 | [diff] [blame] | 3240 | NULL, dpni_irq0_handler_thread, |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3241 | IRQF_NO_SUSPEND | IRQF_ONESHOT, |
| 3242 | dev_name(&ls_dev->dev), &ls_dev->dev); |
| 3243 | if (err < 0) { |
Ioana Radulescu | 77160af | 2017-06-06 10:00:28 -0500 | [diff] [blame] | 3244 | dev_err(&ls_dev->dev, "devm_request_threaded_irq(): %d\n", err); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3245 | goto free_mc_irq; |
| 3246 | } |
| 3247 | |
| 3248 | err = dpni_set_irq_mask(ls_dev->mc_io, 0, ls_dev->mc_handle, |
| 3249 | DPNI_IRQ_INDEX, DPNI_IRQ_EVENT_LINK_CHANGED); |
| 3250 | if (err < 0) { |
Ioana Radulescu | 77160af | 2017-06-06 10:00:28 -0500 | [diff] [blame] | 3251 | dev_err(&ls_dev->dev, "dpni_set_irq_mask(): %d\n", err); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3252 | goto free_irq; |
| 3253 | } |
| 3254 | |
| 3255 | err = dpni_set_irq_enable(ls_dev->mc_io, 0, ls_dev->mc_handle, |
| 3256 | DPNI_IRQ_INDEX, 1); |
| 3257 | if (err < 0) { |
Ioana Radulescu | 77160af | 2017-06-06 10:00:28 -0500 | [diff] [blame] | 3258 | dev_err(&ls_dev->dev, "dpni_set_irq_enable(): %d\n", err); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3259 | goto free_irq; |
| 3260 | } |
| 3261 | |
| 3262 | return 0; |
| 3263 | |
| 3264 | free_irq: |
| 3265 | devm_free_irq(&ls_dev->dev, irq->msi_desc->irq, &ls_dev->dev); |
| 3266 | free_mc_irq: |
| 3267 | fsl_mc_free_irqs(ls_dev); |
| 3268 | |
| 3269 | return err; |
| 3270 | } |
| 3271 | |
| 3272 | static void add_ch_napi(struct dpaa2_eth_priv *priv) |
| 3273 | { |
| 3274 | int i; |
| 3275 | struct dpaa2_eth_channel *ch; |
| 3276 | |
| 3277 | for (i = 0; i < priv->num_channels; i++) { |
| 3278 | ch = priv->channel[i]; |
| 3279 | /* NAPI weight *MUST* be a multiple of DPAA2_ETH_STORE_SIZE */ |
| 3280 | netif_napi_add(priv->net_dev, &ch->napi, dpaa2_eth_poll, |
| 3281 | NAPI_POLL_WEIGHT); |
| 3282 | } |
| 3283 | } |
| 3284 | |
| 3285 | static void del_ch_napi(struct dpaa2_eth_priv *priv) |
| 3286 | { |
| 3287 | int i; |
| 3288 | struct dpaa2_eth_channel *ch; |
| 3289 | |
| 3290 | for (i = 0; i < priv->num_channels; i++) { |
| 3291 | ch = priv->channel[i]; |
| 3292 | netif_napi_del(&ch->napi); |
| 3293 | } |
| 3294 | } |
| 3295 | |
| 3296 | static int dpaa2_eth_probe(struct fsl_mc_device *dpni_dev) |
| 3297 | { |
| 3298 | struct device *dev; |
| 3299 | struct net_device *net_dev = NULL; |
| 3300 | struct dpaa2_eth_priv *priv = NULL; |
| 3301 | int err = 0; |
| 3302 | |
| 3303 | dev = &dpni_dev->dev; |
| 3304 | |
| 3305 | /* Net device */ |
Ioana Radulescu | ab1e6de | 2019-06-11 14:50:03 +0300 | [diff] [blame] | 3306 | net_dev = alloc_etherdev_mq(sizeof(*priv), DPAA2_ETH_MAX_NETDEV_QUEUES); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3307 | if (!net_dev) { |
| 3308 | dev_err(dev, "alloc_etherdev_mq() failed\n"); |
| 3309 | return -ENOMEM; |
| 3310 | } |
| 3311 | |
| 3312 | SET_NETDEV_DEV(net_dev, dev); |
| 3313 | dev_set_drvdata(dev, net_dev); |
| 3314 | |
| 3315 | priv = netdev_priv(net_dev); |
| 3316 | priv->net_dev = net_dev; |
| 3317 | |
Ioana Radulescu | 08eb239 | 2017-05-24 07:13:27 -0500 | [diff] [blame] | 3318 | priv->iommu_domain = iommu_get_domain_for_dev(dev); |
| 3319 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3320 | /* Obtain a MC portal */ |
| 3321 | err = fsl_mc_portal_allocate(dpni_dev, FSL_MC_IO_ATOMIC_CONTEXT_PORTAL, |
| 3322 | &priv->mc_io); |
| 3323 | if (err) { |
Ioana Radulescu | 8c36961 | 2018-03-20 07:04:46 -0500 | [diff] [blame] | 3324 | if (err == -ENXIO) |
| 3325 | err = -EPROBE_DEFER; |
| 3326 | else |
| 3327 | dev_err(dev, "MC portal allocation failed\n"); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3328 | goto err_portal_alloc; |
| 3329 | } |
| 3330 | |
| 3331 | /* MC objects initialization and configuration */ |
| 3332 | err = setup_dpni(dpni_dev); |
| 3333 | if (err) |
| 3334 | goto err_dpni_setup; |
| 3335 | |
| 3336 | err = setup_dpio(priv); |
| 3337 | if (err) |
| 3338 | goto err_dpio_setup; |
| 3339 | |
| 3340 | setup_fqs(priv); |
| 3341 | |
| 3342 | err = setup_dpbp(priv); |
| 3343 | if (err) |
| 3344 | goto err_dpbp_setup; |
| 3345 | |
| 3346 | err = bind_dpni(priv); |
| 3347 | if (err) |
| 3348 | goto err_bind; |
| 3349 | |
| 3350 | /* Add a NAPI context for each channel */ |
| 3351 | add_ch_napi(priv); |
| 3352 | |
| 3353 | /* Percpu statistics */ |
| 3354 | priv->percpu_stats = alloc_percpu(*priv->percpu_stats); |
| 3355 | if (!priv->percpu_stats) { |
| 3356 | dev_err(dev, "alloc_percpu(percpu_stats) failed\n"); |
| 3357 | err = -ENOMEM; |
| 3358 | goto err_alloc_percpu_stats; |
| 3359 | } |
Ioana Radulescu | 85047ab | 2017-04-28 04:50:31 -0500 | [diff] [blame] | 3360 | priv->percpu_extras = alloc_percpu(*priv->percpu_extras); |
| 3361 | if (!priv->percpu_extras) { |
| 3362 | dev_err(dev, "alloc_percpu(percpu_extras) failed\n"); |
| 3363 | err = -ENOMEM; |
| 3364 | goto err_alloc_percpu_extras; |
| 3365 | } |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3366 | |
| 3367 | err = netdev_init(net_dev); |
| 3368 | if (err) |
| 3369 | goto err_netdev_init; |
| 3370 | |
| 3371 | /* Configure checksum offload based on current interface flags */ |
| 3372 | err = set_rx_csum(priv, !!(net_dev->features & NETIF_F_RXCSUM)); |
| 3373 | if (err) |
| 3374 | goto err_csum; |
| 3375 | |
| 3376 | err = set_tx_csum(priv, !!(net_dev->features & |
| 3377 | (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM))); |
| 3378 | if (err) |
| 3379 | goto err_csum; |
| 3380 | |
| 3381 | err = alloc_rings(priv); |
| 3382 | if (err) |
| 3383 | goto err_alloc_rings; |
| 3384 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3385 | err = setup_irqs(dpni_dev); |
| 3386 | if (err) { |
| 3387 | netdev_warn(net_dev, "Failed to set link interrupt, fall back to polling\n"); |
| 3388 | priv->poll_thread = kthread_run(poll_link_state, priv, |
| 3389 | "%s_poll_link", net_dev->name); |
| 3390 | if (IS_ERR(priv->poll_thread)) { |
Ioana Radulescu | 7f12c8a3 | 2018-08-29 04:42:39 -0500 | [diff] [blame] | 3391 | dev_err(dev, "Error starting polling thread\n"); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3392 | goto err_poll_thread; |
| 3393 | } |
| 3394 | priv->do_link_poll = true; |
| 3395 | } |
| 3396 | |
Ioana Radulescu | 7f12c8a3 | 2018-08-29 04:42:39 -0500 | [diff] [blame] | 3397 | err = register_netdev(net_dev); |
| 3398 | if (err < 0) { |
| 3399 | dev_err(dev, "register_netdev() failed\n"); |
| 3400 | goto err_netdev_reg; |
| 3401 | } |
| 3402 | |
Ioana Radulescu | 091a19e | 2019-01-18 16:16:00 +0000 | [diff] [blame] | 3403 | #ifdef CONFIG_DEBUG_FS |
| 3404 | dpaa2_dbg_add(priv); |
| 3405 | #endif |
| 3406 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3407 | dev_info(dev, "Probed interface %s\n", net_dev->name); |
| 3408 | return 0; |
| 3409 | |
Ioana Radulescu | 7f12c8a3 | 2018-08-29 04:42:39 -0500 | [diff] [blame] | 3410 | err_netdev_reg: |
| 3411 | if (priv->do_link_poll) |
| 3412 | kthread_stop(priv->poll_thread); |
| 3413 | else |
| 3414 | fsl_mc_free_irqs(dpni_dev); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3415 | err_poll_thread: |
| 3416 | free_rings(priv); |
| 3417 | err_alloc_rings: |
| 3418 | err_csum: |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3419 | err_netdev_init: |
Ioana Radulescu | 85047ab | 2017-04-28 04:50:31 -0500 | [diff] [blame] | 3420 | free_percpu(priv->percpu_extras); |
| 3421 | err_alloc_percpu_extras: |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3422 | free_percpu(priv->percpu_stats); |
| 3423 | err_alloc_percpu_stats: |
| 3424 | del_ch_napi(priv); |
| 3425 | err_bind: |
| 3426 | free_dpbp(priv); |
| 3427 | err_dpbp_setup: |
| 3428 | free_dpio(priv); |
| 3429 | err_dpio_setup: |
| 3430 | free_dpni(priv); |
| 3431 | err_dpni_setup: |
| 3432 | fsl_mc_portal_free(priv->mc_io); |
| 3433 | err_portal_alloc: |
| 3434 | dev_set_drvdata(dev, NULL); |
| 3435 | free_netdev(net_dev); |
| 3436 | |
| 3437 | return err; |
| 3438 | } |
| 3439 | |
| 3440 | static int dpaa2_eth_remove(struct fsl_mc_device *ls_dev) |
| 3441 | { |
| 3442 | struct device *dev; |
| 3443 | struct net_device *net_dev; |
| 3444 | struct dpaa2_eth_priv *priv; |
| 3445 | |
| 3446 | dev = &ls_dev->dev; |
| 3447 | net_dev = dev_get_drvdata(dev); |
| 3448 | priv = netdev_priv(net_dev); |
| 3449 | |
Ioana Radulescu | 091a19e | 2019-01-18 16:16:00 +0000 | [diff] [blame] | 3450 | #ifdef CONFIG_DEBUG_FS |
| 3451 | dpaa2_dbg_remove(priv); |
| 3452 | #endif |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3453 | unregister_netdev(net_dev); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3454 | |
| 3455 | if (priv->do_link_poll) |
| 3456 | kthread_stop(priv->poll_thread); |
| 3457 | else |
| 3458 | fsl_mc_free_irqs(ls_dev); |
| 3459 | |
| 3460 | free_rings(priv); |
| 3461 | free_percpu(priv->percpu_stats); |
Ioana Radulescu | 85047ab | 2017-04-28 04:50:31 -0500 | [diff] [blame] | 3462 | free_percpu(priv->percpu_extras); |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3463 | |
| 3464 | del_ch_napi(priv); |
| 3465 | free_dpbp(priv); |
| 3466 | free_dpio(priv); |
| 3467 | free_dpni(priv); |
| 3468 | |
| 3469 | fsl_mc_portal_free(priv->mc_io); |
| 3470 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3471 | free_netdev(net_dev); |
| 3472 | |
Ioana Radulescu | 4bc07aa | 2018-03-23 10:23:36 -0500 | [diff] [blame] | 3473 | 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] | 3474 | |
Ioana Radulescu | 6e2387e | 2017-04-28 04:50:29 -0500 | [diff] [blame] | 3475 | return 0; |
| 3476 | } |
| 3477 | |
| 3478 | static const struct fsl_mc_device_id dpaa2_eth_match_id_table[] = { |
| 3479 | { |
| 3480 | .vendor = FSL_MC_VENDOR_FREESCALE, |
| 3481 | .obj_type = "dpni", |
| 3482 | }, |
| 3483 | { .vendor = 0x0 } |
| 3484 | }; |
| 3485 | MODULE_DEVICE_TABLE(fslmc, dpaa2_eth_match_id_table); |
| 3486 | |
| 3487 | static struct fsl_mc_driver dpaa2_eth_driver = { |
| 3488 | .driver = { |
| 3489 | .name = KBUILD_MODNAME, |
| 3490 | .owner = THIS_MODULE, |
| 3491 | }, |
| 3492 | .probe = dpaa2_eth_probe, |
| 3493 | .remove = dpaa2_eth_remove, |
| 3494 | .match_id_table = dpaa2_eth_match_id_table |
| 3495 | }; |
| 3496 | |
Ioana Radulescu | 091a19e | 2019-01-18 16:16:00 +0000 | [diff] [blame] | 3497 | static int __init dpaa2_eth_driver_init(void) |
| 3498 | { |
| 3499 | int err; |
| 3500 | |
| 3501 | dpaa2_eth_dbg_init(); |
| 3502 | err = fsl_mc_driver_register(&dpaa2_eth_driver); |
| 3503 | if (err) { |
| 3504 | dpaa2_eth_dbg_exit(); |
| 3505 | return err; |
| 3506 | } |
| 3507 | |
| 3508 | return 0; |
| 3509 | } |
| 3510 | |
| 3511 | static void __exit dpaa2_eth_driver_exit(void) |
| 3512 | { |
| 3513 | dpaa2_eth_dbg_exit(); |
| 3514 | fsl_mc_driver_unregister(&dpaa2_eth_driver); |
| 3515 | } |
| 3516 | |
| 3517 | module_init(dpaa2_eth_driver_init); |
| 3518 | module_exit(dpaa2_eth_driver_exit); |