1 // SPDX-License-Identifier: GPL-2.0+
3 #include "lan966x_main.h"
5 static int lan966x_fdma_channel_active(struct lan966x *lan966x)
7 return lan_rd(lan966x, FDMA_CH_ACTIVE);
10 static struct page *lan966x_fdma_rx_alloc_page(struct lan966x_rx *rx,
11 struct lan966x_db *db)
13 struct lan966x *lan966x = rx->lan966x;
17 page = dev_alloc_pages(rx->page_order);
21 dma_addr = dma_map_page(lan966x->dev, page, 0,
22 PAGE_SIZE << rx->page_order,
24 if (unlikely(dma_mapping_error(lan966x->dev, dma_addr)))
27 db->dataptr = dma_addr;
32 __free_pages(page, rx->page_order);
36 static void lan966x_fdma_rx_free_pages(struct lan966x_rx *rx)
38 struct lan966x *lan966x = rx->lan966x;
39 struct lan966x_rx_dcb *dcb;
40 struct lan966x_db *db;
43 for (i = 0; i < FDMA_DCB_MAX; ++i) {
46 for (j = 0; j < FDMA_RX_DCB_MAX_DBS; ++j) {
48 dma_unmap_single(lan966x->dev,
49 (dma_addr_t)db->dataptr,
50 PAGE_SIZE << rx->page_order,
52 __free_pages(rx->page[i][j], rx->page_order);
57 static void lan966x_fdma_rx_add_dcb(struct lan966x_rx *rx,
58 struct lan966x_rx_dcb *dcb,
61 struct lan966x_db *db;
64 for (i = 0; i < FDMA_RX_DCB_MAX_DBS; ++i) {
66 db->status = FDMA_DCB_STATUS_INTR;
69 dcb->nextptr = FDMA_DCB_INVALID_DATA;
70 dcb->info = FDMA_DCB_INFO_DATAL(PAGE_SIZE << rx->page_order);
72 rx->last_entry->nextptr = nextptr;
76 static int lan966x_fdma_rx_alloc(struct lan966x_rx *rx)
78 struct lan966x *lan966x = rx->lan966x;
79 struct lan966x_rx_dcb *dcb;
80 struct lan966x_db *db;
85 /* calculate how many pages are needed to allocate the dcbs */
86 size = sizeof(struct lan966x_rx_dcb) * FDMA_DCB_MAX;
87 size = ALIGN(size, PAGE_SIZE);
89 rx->dcbs = dma_alloc_coherent(lan966x->dev, size, &rx->dma, GFP_KERNEL);
93 rx->last_entry = rx->dcbs;
97 /* Now for each dcb allocate the dbs */
98 for (i = 0; i < FDMA_DCB_MAX; ++i) {
102 /* For each db allocate a page and map it to the DB dataptr. */
103 for (j = 0; j < FDMA_RX_DCB_MAX_DBS; ++j) {
105 page = lan966x_fdma_rx_alloc_page(rx, db);
110 rx->page[i][j] = page;
113 lan966x_fdma_rx_add_dcb(rx, dcb, rx->dma + sizeof(*dcb) * i);
119 static void lan966x_fdma_rx_free(struct lan966x_rx *rx)
121 struct lan966x *lan966x = rx->lan966x;
124 /* Now it is possible to do the cleanup of dcb */
125 size = sizeof(struct lan966x_tx_dcb) * FDMA_DCB_MAX;
126 size = ALIGN(size, PAGE_SIZE);
127 dma_free_coherent(lan966x->dev, size, rx->dcbs, rx->dma);
130 static void lan966x_fdma_rx_start(struct lan966x_rx *rx)
132 struct lan966x *lan966x = rx->lan966x;
135 /* When activating a channel, first is required to write the first DCB
136 * address and then to activate it
138 lan_wr(lower_32_bits((u64)rx->dma), lan966x,
139 FDMA_DCB_LLP(rx->channel_id));
140 lan_wr(upper_32_bits((u64)rx->dma), lan966x,
141 FDMA_DCB_LLP1(rx->channel_id));
143 lan_wr(FDMA_CH_CFG_CH_DCB_DB_CNT_SET(FDMA_RX_DCB_MAX_DBS) |
144 FDMA_CH_CFG_CH_INTR_DB_EOF_ONLY_SET(1) |
145 FDMA_CH_CFG_CH_INJ_PORT_SET(0) |
146 FDMA_CH_CFG_CH_MEM_SET(1),
147 lan966x, FDMA_CH_CFG(rx->channel_id));
150 lan_rmw(FDMA_PORT_CTRL_XTR_STOP_SET(0),
151 FDMA_PORT_CTRL_XTR_STOP,
152 lan966x, FDMA_PORT_CTRL(0));
154 /* Enable interrupts */
155 mask = lan_rd(lan966x, FDMA_INTR_DB_ENA);
156 mask = FDMA_INTR_DB_ENA_INTR_DB_ENA_GET(mask);
157 mask |= BIT(rx->channel_id);
158 lan_rmw(FDMA_INTR_DB_ENA_INTR_DB_ENA_SET(mask),
159 FDMA_INTR_DB_ENA_INTR_DB_ENA,
160 lan966x, FDMA_INTR_DB_ENA);
162 /* Activate the channel */
163 lan_rmw(FDMA_CH_ACTIVATE_CH_ACTIVATE_SET(BIT(rx->channel_id)),
164 FDMA_CH_ACTIVATE_CH_ACTIVATE,
165 lan966x, FDMA_CH_ACTIVATE);
168 static void lan966x_fdma_rx_disable(struct lan966x_rx *rx)
170 struct lan966x *lan966x = rx->lan966x;
173 /* Disable the channel */
174 lan_rmw(FDMA_CH_DISABLE_CH_DISABLE_SET(BIT(rx->channel_id)),
175 FDMA_CH_DISABLE_CH_DISABLE,
176 lan966x, FDMA_CH_DISABLE);
178 readx_poll_timeout_atomic(lan966x_fdma_channel_active, lan966x,
179 val, !(val & BIT(rx->channel_id)),
180 READL_SLEEP_US, READL_TIMEOUT_US);
182 lan_rmw(FDMA_CH_DB_DISCARD_DB_DISCARD_SET(BIT(rx->channel_id)),
183 FDMA_CH_DB_DISCARD_DB_DISCARD,
184 lan966x, FDMA_CH_DB_DISCARD);
187 static void lan966x_fdma_rx_reload(struct lan966x_rx *rx)
189 struct lan966x *lan966x = rx->lan966x;
191 lan_rmw(FDMA_CH_RELOAD_CH_RELOAD_SET(BIT(rx->channel_id)),
192 FDMA_CH_RELOAD_CH_RELOAD,
193 lan966x, FDMA_CH_RELOAD);
196 static void lan966x_fdma_tx_add_dcb(struct lan966x_tx *tx,
197 struct lan966x_tx_dcb *dcb)
199 dcb->nextptr = FDMA_DCB_INVALID_DATA;
203 static int lan966x_fdma_tx_alloc(struct lan966x_tx *tx)
205 struct lan966x *lan966x = tx->lan966x;
206 struct lan966x_tx_dcb *dcb;
207 struct lan966x_db *db;
211 tx->dcbs_buf = kcalloc(FDMA_DCB_MAX, sizeof(struct lan966x_tx_dcb_buf),
216 /* calculate how many pages are needed to allocate the dcbs */
217 size = sizeof(struct lan966x_tx_dcb) * FDMA_DCB_MAX;
218 size = ALIGN(size, PAGE_SIZE);
219 tx->dcbs = dma_alloc_coherent(lan966x->dev, size, &tx->dma, GFP_KERNEL);
223 /* Now for each dcb allocate the db */
224 for (i = 0; i < FDMA_DCB_MAX; ++i) {
227 for (j = 0; j < FDMA_TX_DCB_MAX_DBS; ++j) {
233 lan966x_fdma_tx_add_dcb(tx, dcb);
243 static void lan966x_fdma_tx_free(struct lan966x_tx *tx)
245 struct lan966x *lan966x = tx->lan966x;
250 size = sizeof(struct lan966x_tx_dcb) * FDMA_DCB_MAX;
251 size = ALIGN(size, PAGE_SIZE);
252 dma_free_coherent(lan966x->dev, size, tx->dcbs, tx->dma);
255 static void lan966x_fdma_tx_activate(struct lan966x_tx *tx)
257 struct lan966x *lan966x = tx->lan966x;
260 /* When activating a channel, first is required to write the first DCB
261 * address and then to activate it
263 lan_wr(lower_32_bits((u64)tx->dma), lan966x,
264 FDMA_DCB_LLP(tx->channel_id));
265 lan_wr(upper_32_bits((u64)tx->dma), lan966x,
266 FDMA_DCB_LLP1(tx->channel_id));
268 lan_wr(FDMA_CH_CFG_CH_DCB_DB_CNT_SET(FDMA_TX_DCB_MAX_DBS) |
269 FDMA_CH_CFG_CH_INTR_DB_EOF_ONLY_SET(1) |
270 FDMA_CH_CFG_CH_INJ_PORT_SET(0) |
271 FDMA_CH_CFG_CH_MEM_SET(1),
272 lan966x, FDMA_CH_CFG(tx->channel_id));
275 lan_rmw(FDMA_PORT_CTRL_INJ_STOP_SET(0),
276 FDMA_PORT_CTRL_INJ_STOP,
277 lan966x, FDMA_PORT_CTRL(0));
279 /* Enable interrupts */
280 mask = lan_rd(lan966x, FDMA_INTR_DB_ENA);
281 mask = FDMA_INTR_DB_ENA_INTR_DB_ENA_GET(mask);
282 mask |= BIT(tx->channel_id);
283 lan_rmw(FDMA_INTR_DB_ENA_INTR_DB_ENA_SET(mask),
284 FDMA_INTR_DB_ENA_INTR_DB_ENA,
285 lan966x, FDMA_INTR_DB_ENA);
287 /* Activate the channel */
288 lan_rmw(FDMA_CH_ACTIVATE_CH_ACTIVATE_SET(BIT(tx->channel_id)),
289 FDMA_CH_ACTIVATE_CH_ACTIVATE,
290 lan966x, FDMA_CH_ACTIVATE);
293 static void lan966x_fdma_tx_disable(struct lan966x_tx *tx)
295 struct lan966x *lan966x = tx->lan966x;
298 /* Disable the channel */
299 lan_rmw(FDMA_CH_DISABLE_CH_DISABLE_SET(BIT(tx->channel_id)),
300 FDMA_CH_DISABLE_CH_DISABLE,
301 lan966x, FDMA_CH_DISABLE);
303 readx_poll_timeout_atomic(lan966x_fdma_channel_active, lan966x,
304 val, !(val & BIT(tx->channel_id)),
305 READL_SLEEP_US, READL_TIMEOUT_US);
307 lan_rmw(FDMA_CH_DB_DISCARD_DB_DISCARD_SET(BIT(tx->channel_id)),
308 FDMA_CH_DB_DISCARD_DB_DISCARD,
309 lan966x, FDMA_CH_DB_DISCARD);
311 tx->activated = false;
314 static void lan966x_fdma_tx_reload(struct lan966x_tx *tx)
316 struct lan966x *lan966x = tx->lan966x;
318 /* Write the registers to reload the channel */
319 lan_rmw(FDMA_CH_RELOAD_CH_RELOAD_SET(BIT(tx->channel_id)),
320 FDMA_CH_RELOAD_CH_RELOAD,
321 lan966x, FDMA_CH_RELOAD);
324 static void lan966x_fdma_wakeup_netdev(struct lan966x *lan966x)
326 struct lan966x_port *port;
329 for (i = 0; i < lan966x->num_phys_ports; ++i) {
330 port = lan966x->ports[i];
334 if (netif_queue_stopped(port->dev))
335 netif_wake_queue(port->dev);
339 static void lan966x_fdma_stop_netdev(struct lan966x *lan966x)
341 struct lan966x_port *port;
344 for (i = 0; i < lan966x->num_phys_ports; ++i) {
345 port = lan966x->ports[i];
349 netif_stop_queue(port->dev);
353 static void lan966x_fdma_tx_clear_buf(struct lan966x *lan966x, int weight)
355 struct lan966x_tx *tx = &lan966x->tx;
356 struct lan966x_tx_dcb_buf *dcb_buf;
357 struct lan966x_db *db;
362 spin_lock_irqsave(&lan966x->tx_lock, flags);
363 for (i = 0; i < FDMA_DCB_MAX; ++i) {
364 dcb_buf = &tx->dcbs_buf[i];
369 db = &tx->dcbs[i].db[0];
370 if (!(db->status & FDMA_DCB_STATUS_DONE))
373 dcb_buf->dev->stats.tx_packets++;
374 dcb_buf->dev->stats.tx_bytes += dcb_buf->skb->len;
376 dcb_buf->used = false;
377 dma_unmap_single(lan966x->dev,
382 dev_kfree_skb_any(dcb_buf->skb);
388 lan966x_fdma_wakeup_netdev(lan966x);
390 spin_unlock_irqrestore(&lan966x->tx_lock, flags);
393 static bool lan966x_fdma_rx_more_frames(struct lan966x_rx *rx)
395 struct lan966x_db *db;
397 /* Check if there is any data */
398 db = &rx->dcbs[rx->dcb_index].db[rx->db_index];
399 if (unlikely(!(db->status & FDMA_DCB_STATUS_DONE)))
405 static struct sk_buff *lan966x_fdma_rx_get_frame(struct lan966x_rx *rx)
407 struct lan966x *lan966x = rx->lan966x;
408 u64 src_port, timestamp;
409 struct lan966x_db *db;
413 /* Get the received frame and unmap it */
414 db = &rx->dcbs[rx->dcb_index].db[rx->db_index];
415 page = rx->page[rx->dcb_index][rx->db_index];
416 skb = build_skb(page_address(page), PAGE_SIZE << rx->page_order);
420 dma_unmap_single(lan966x->dev, (dma_addr_t)db->dataptr,
421 FDMA_DCB_STATUS_BLOCKL(db->status),
423 skb_put(skb, FDMA_DCB_STATUS_BLOCKL(db->status));
425 lan966x_ifh_get_src_port(skb->data, &src_port);
426 lan966x_ifh_get_timestamp(skb->data, ×tamp);
428 if (WARN_ON(src_port >= lan966x->num_phys_ports))
431 skb->dev = lan966x->ports[src_port]->dev;
432 skb_pull(skb, IFH_LEN * sizeof(u32));
434 if (likely(!(skb->dev->features & NETIF_F_RXFCS)))
435 skb_trim(skb, skb->len - ETH_FCS_LEN);
437 lan966x_ptp_rxtstamp(lan966x, skb, timestamp);
438 skb->protocol = eth_type_trans(skb, skb->dev);
440 if (lan966x->bridge_mask & BIT(src_port)) {
441 skb->offload_fwd_mark = 1;
443 skb_reset_network_header(skb);
444 if (!lan966x_hw_offload(lan966x, src_port, skb))
445 skb->offload_fwd_mark = 0;
448 skb->dev->stats.rx_bytes += skb->len;
449 skb->dev->stats.rx_packets++;
456 dma_unmap_page(lan966x->dev, (dma_addr_t)db->dataptr,
457 FDMA_DCB_STATUS_BLOCKL(db->status),
459 __free_pages(page, rx->page_order);
464 static int lan966x_fdma_napi_poll(struct napi_struct *napi, int weight)
466 struct lan966x *lan966x = container_of(napi, struct lan966x, napi);
467 struct lan966x_rx *rx = &lan966x->rx;
468 int dcb_reload = rx->dcb_index;
469 struct lan966x_rx_dcb *old_dcb;
470 struct lan966x_db *db;
476 lan966x_fdma_tx_clear_buf(lan966x, weight);
478 /* Get all received skb */
479 while (counter < weight) {
480 if (!lan966x_fdma_rx_more_frames(rx))
483 skb = lan966x_fdma_rx_get_frame(rx);
485 rx->page[rx->dcb_index][rx->db_index] = NULL;
487 rx->dcb_index &= FDMA_DCB_MAX - 1;
492 napi_gro_receive(&lan966x->napi, skb);
496 /* Allocate new pages and map them */
497 while (dcb_reload != rx->dcb_index) {
498 db = &rx->dcbs[dcb_reload].db[rx->db_index];
499 page = lan966x_fdma_rx_alloc_page(rx, db);
502 rx->page[dcb_reload][rx->db_index] = page;
504 old_dcb = &rx->dcbs[dcb_reload];
506 dcb_reload &= FDMA_DCB_MAX - 1;
508 nextptr = rx->dma + ((unsigned long)old_dcb -
509 (unsigned long)rx->dcbs);
510 lan966x_fdma_rx_add_dcb(rx, old_dcb, nextptr);
511 lan966x_fdma_rx_reload(rx);
514 if (counter < weight && napi_complete_done(napi, counter))
515 lan_wr(0xff, lan966x, FDMA_INTR_DB_ENA);
520 irqreturn_t lan966x_fdma_irq_handler(int irq, void *args)
522 struct lan966x *lan966x = args;
523 u32 db, err, err_type;
525 db = lan_rd(lan966x, FDMA_INTR_DB);
526 err = lan_rd(lan966x, FDMA_INTR_ERR);
529 lan_wr(0, lan966x, FDMA_INTR_DB_ENA);
530 lan_wr(db, lan966x, FDMA_INTR_DB);
532 napi_schedule(&lan966x->napi);
536 err_type = lan_rd(lan966x, FDMA_ERRORS);
538 WARN(1, "Unexpected error: %d, error_type: %d\n", err, err_type);
540 lan_wr(err, lan966x, FDMA_INTR_ERR);
541 lan_wr(err_type, lan966x, FDMA_ERRORS);
547 static int lan966x_fdma_get_next_dcb(struct lan966x_tx *tx)
549 struct lan966x_tx_dcb_buf *dcb_buf;
552 for (i = 0; i < FDMA_DCB_MAX; ++i) {
553 dcb_buf = &tx->dcbs_buf[i];
554 if (!dcb_buf->used && i != tx->last_in_use)
561 int lan966x_fdma_xmit(struct sk_buff *skb, __be32 *ifh, struct net_device *dev)
563 struct lan966x_port *port = netdev_priv(dev);
564 struct lan966x *lan966x = port->lan966x;
565 struct lan966x_tx_dcb_buf *next_dcb_buf;
566 struct lan966x_tx_dcb *next_dcb, *dcb;
567 struct lan966x_tx *tx = &lan966x->tx;
568 struct lan966x_db *next_db;
576 next_to_use = lan966x_fdma_get_next_dcb(tx);
577 if (next_to_use < 0) {
578 netif_stop_queue(dev);
579 return NETDEV_TX_BUSY;
582 if (skb_put_padto(skb, ETH_ZLEN)) {
583 dev->stats.tx_dropped++;
588 needed_headroom = max_t(int, IFH_LEN * sizeof(u32) - skb_headroom(skb), 0);
589 needed_tailroom = max_t(int, ETH_FCS_LEN - skb_tailroom(skb), 0);
590 if (needed_headroom || needed_tailroom || skb_header_cloned(skb)) {
591 err = pskb_expand_head(skb, needed_headroom, needed_tailroom,
594 dev->stats.tx_dropped++;
600 skb_tx_timestamp(skb);
601 skb_push(skb, IFH_LEN * sizeof(u32));
602 memcpy(skb->data, ifh, IFH_LEN * sizeof(u32));
605 dma_addr = dma_map_single(lan966x->dev, skb->data, skb->len,
607 if (dma_mapping_error(lan966x->dev, dma_addr)) {
608 dev->stats.tx_dropped++;
614 next_dcb = &tx->dcbs[next_to_use];
615 next_dcb->nextptr = FDMA_DCB_INVALID_DATA;
617 next_db = &next_dcb->db[0];
618 next_db->dataptr = dma_addr;
619 next_db->status = FDMA_DCB_STATUS_SOF |
620 FDMA_DCB_STATUS_EOF |
621 FDMA_DCB_STATUS_INTR |
622 FDMA_DCB_STATUS_BLOCKO(0) |
623 FDMA_DCB_STATUS_BLOCKL(skb->len);
625 /* Fill up the buffer */
626 next_dcb_buf = &tx->dcbs_buf[next_to_use];
627 next_dcb_buf->skb = skb;
628 next_dcb_buf->dma_addr = dma_addr;
629 next_dcb_buf->used = true;
630 next_dcb_buf->ptp = false;
631 next_dcb_buf->dev = dev;
633 if (skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP &&
634 LAN966X_SKB_CB(skb)->rew_op == IFH_REW_OP_TWO_STEP_PTP)
635 next_dcb_buf->ptp = true;
637 if (likely(lan966x->tx.activated)) {
638 /* Connect current dcb to the next db */
639 dcb = &tx->dcbs[tx->last_in_use];
640 dcb->nextptr = tx->dma + (next_to_use *
641 sizeof(struct lan966x_tx_dcb));
643 lan966x_fdma_tx_reload(tx);
645 /* Because it is first time, then just activate */
646 lan966x->tx.activated = true;
647 lan966x_fdma_tx_activate(tx);
650 /* Move to next dcb because this last in use */
651 tx->last_in_use = next_to_use;
656 if (skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP &&
657 LAN966X_SKB_CB(skb)->rew_op == IFH_REW_OP_TWO_STEP_PTP)
658 lan966x_ptp_txtstamp_release(port, skb);
660 dev_kfree_skb_any(skb);
664 static int lan966x_fdma_get_max_mtu(struct lan966x *lan966x)
669 for (i = 0; i < lan966x->num_phys_ports; ++i) {
672 if (!lan966x->ports[i])
675 mtu = lan966x->ports[i]->dev->mtu;
683 static int lan966x_qsys_sw_status(struct lan966x *lan966x)
685 return lan_rd(lan966x, QSYS_SW_STATUS(CPU_PORT));
688 static int lan966x_fdma_reload(struct lan966x *lan966x, int new_mtu)
690 void *rx_dcbs, *tx_dcbs, *tx_dcbs_buf;
691 dma_addr_t rx_dma, tx_dma;
695 /* Store these for later to free them */
696 rx_dma = lan966x->rx.dma;
697 tx_dma = lan966x->tx.dma;
698 rx_dcbs = lan966x->rx.dcbs;
699 tx_dcbs = lan966x->tx.dcbs;
700 tx_dcbs_buf = lan966x->tx.dcbs_buf;
702 napi_synchronize(&lan966x->napi);
703 napi_disable(&lan966x->napi);
704 lan966x_fdma_stop_netdev(lan966x);
706 lan966x_fdma_rx_disable(&lan966x->rx);
707 lan966x_fdma_rx_free_pages(&lan966x->rx);
708 lan966x->rx.page_order = round_up(new_mtu, PAGE_SIZE) / PAGE_SIZE - 1;
709 err = lan966x_fdma_rx_alloc(&lan966x->rx);
712 lan966x_fdma_rx_start(&lan966x->rx);
714 size = sizeof(struct lan966x_rx_dcb) * FDMA_DCB_MAX;
715 size = ALIGN(size, PAGE_SIZE);
716 dma_free_coherent(lan966x->dev, size, rx_dcbs, rx_dma);
718 lan966x_fdma_tx_disable(&lan966x->tx);
719 err = lan966x_fdma_tx_alloc(&lan966x->tx);
723 size = sizeof(struct lan966x_tx_dcb) * FDMA_DCB_MAX;
724 size = ALIGN(size, PAGE_SIZE);
725 dma_free_coherent(lan966x->dev, size, tx_dcbs, tx_dma);
729 lan966x_fdma_wakeup_netdev(lan966x);
730 napi_enable(&lan966x->napi);
734 lan966x->rx.dma = rx_dma;
735 lan966x->rx.dcbs = rx_dcbs;
736 lan966x_fdma_rx_start(&lan966x->rx);
739 lan966x->tx.dma = tx_dma;
740 lan966x->tx.dcbs = tx_dcbs;
741 lan966x->tx.dcbs_buf = tx_dcbs_buf;
746 int lan966x_fdma_change_mtu(struct lan966x *lan966x)
752 max_mtu = lan966x_fdma_get_max_mtu(lan966x);
753 max_mtu += IFH_LEN * sizeof(u32);
755 if (round_up(max_mtu, PAGE_SIZE) / PAGE_SIZE - 1 ==
756 lan966x->rx.page_order)
759 /* Disable the CPU port */
760 lan_rmw(QSYS_SW_PORT_MODE_PORT_ENA_SET(0),
761 QSYS_SW_PORT_MODE_PORT_ENA,
762 lan966x, QSYS_SW_PORT_MODE(CPU_PORT));
764 /* Flush the CPU queues */
765 readx_poll_timeout(lan966x_qsys_sw_status, lan966x,
766 val, !(QSYS_SW_STATUS_EQ_AVAIL_GET(val)),
767 READL_SLEEP_US, READL_TIMEOUT_US);
769 /* Add a sleep in case there are frames between the queues and the CPU
772 usleep_range(1000, 2000);
774 err = lan966x_fdma_reload(lan966x, max_mtu);
776 /* Enable back the CPU port */
777 lan_rmw(QSYS_SW_PORT_MODE_PORT_ENA_SET(1),
778 QSYS_SW_PORT_MODE_PORT_ENA,
779 lan966x, QSYS_SW_PORT_MODE(CPU_PORT));
784 void lan966x_fdma_netdev_init(struct lan966x *lan966x, struct net_device *dev)
786 if (lan966x->fdma_ndev)
789 lan966x->fdma_ndev = dev;
790 netif_napi_add(dev, &lan966x->napi, lan966x_fdma_napi_poll,
792 napi_enable(&lan966x->napi);
795 void lan966x_fdma_netdev_deinit(struct lan966x *lan966x, struct net_device *dev)
797 if (lan966x->fdma_ndev == dev) {
798 netif_napi_del(&lan966x->napi);
799 lan966x->fdma_ndev = NULL;
803 int lan966x_fdma_init(struct lan966x *lan966x)
810 lan966x->rx.lan966x = lan966x;
811 lan966x->rx.channel_id = FDMA_XTR_CHANNEL;
812 lan966x->tx.lan966x = lan966x;
813 lan966x->tx.channel_id = FDMA_INJ_CHANNEL;
814 lan966x->tx.last_in_use = -1;
816 err = lan966x_fdma_rx_alloc(&lan966x->rx);
820 err = lan966x_fdma_tx_alloc(&lan966x->tx);
822 lan966x_fdma_rx_free(&lan966x->rx);
826 lan966x_fdma_rx_start(&lan966x->rx);
831 void lan966x_fdma_deinit(struct lan966x *lan966x)
836 lan966x_fdma_rx_disable(&lan966x->rx);
837 lan966x_fdma_tx_disable(&lan966x->tx);
839 napi_synchronize(&lan966x->napi);
840 napi_disable(&lan966x->napi);
842 lan966x_fdma_rx_free_pages(&lan966x->rx);
843 lan966x_fdma_rx_free(&lan966x->rx);
844 lan966x_fdma_tx_free(&lan966x->tx);