1 // SPDX-License-Identifier: GPL-2.0
3 /* Texas Instruments ICSSG Ethernet Driver
5 * Copyright (C) 2018-2022 Texas Instruments Incorporated - https://www.ti.com/
9 #include <linux/bitops.h>
10 #include <linux/clk.h>
11 #include <linux/delay.h>
12 #include <linux/dma-mapping.h>
13 #include <linux/dma/ti-cppi5.h>
14 #include <linux/etherdevice.h>
15 #include <linux/genalloc.h>
16 #include <linux/if_vlan.h>
17 #include <linux/interrupt.h>
18 #include <linux/kernel.h>
19 #include <linux/mfd/syscon.h>
20 #include <linux/module.h>
22 #include <linux/of_irq.h>
23 #include <linux/of_mdio.h>
24 #include <linux/of_net.h>
25 #include <linux/of_platform.h>
26 #include <linux/phy.h>
27 #include <linux/remoteproc/pruss.h>
28 #include <linux/regmap.h>
29 #include <linux/remoteproc.h>
31 #include "icssg_prueth.h"
32 #include "icssg_mii_rt.h"
33 #include "../k3-cppi-desc-pool.h"
35 #define PRUETH_MODULE_DESCRIPTION "PRUSS ICSSG Ethernet driver"
37 /* Netif debug messages possible */
38 #define PRUETH_EMAC_DEBUG (NETIF_MSG_DRV | \
46 NETIF_MSG_TX_QUEUED | \
49 NETIF_MSG_RX_STATUS | \
54 #define prueth_napi_to_emac(napi) container_of(napi, struct prueth_emac, napi_rx)
56 /* CTRLMMR_ICSSG_RGMII_CTRL register bits */
57 #define ICSSG_CTRL_RGMII_ID_MODE BIT(24)
59 #define IEP_DEFAULT_CYCLE_TIME_NS 1000000 /* 1 ms */
61 static void prueth_cleanup_rx_chns(struct prueth_emac *emac,
62 struct prueth_rx_chn *rx_chn,
65 if (rx_chn->desc_pool)
66 k3_cppi_desc_pool_destroy(rx_chn->desc_pool);
69 k3_udma_glue_release_rx_chn(rx_chn->rx_chn);
72 static void prueth_cleanup_tx_chns(struct prueth_emac *emac)
76 for (i = 0; i < emac->tx_ch_num; i++) {
77 struct prueth_tx_chn *tx_chn = &emac->tx_chns[i];
79 if (tx_chn->desc_pool)
80 k3_cppi_desc_pool_destroy(tx_chn->desc_pool);
83 k3_udma_glue_release_tx_chn(tx_chn->tx_chn);
85 /* Assume prueth_cleanup_tx_chns() is called at the
86 * end after all channel resources are freed
88 memset(tx_chn, 0, sizeof(*tx_chn));
92 static void prueth_ndev_del_tx_napi(struct prueth_emac *emac, int num)
96 for (i = 0; i < num; i++) {
97 struct prueth_tx_chn *tx_chn = &emac->tx_chns[i];
100 free_irq(tx_chn->irq, tx_chn);
101 netif_napi_del(&tx_chn->napi_tx);
105 static void prueth_xmit_free(struct prueth_tx_chn *tx_chn,
106 struct cppi5_host_desc_t *desc)
108 struct cppi5_host_desc_t *first_desc, *next_desc;
109 dma_addr_t buf_dma, next_desc_dma;
113 next_desc = first_desc;
115 cppi5_hdesc_get_obuf(first_desc, &buf_dma, &buf_dma_len);
116 k3_udma_glue_tx_cppi5_to_dma_addr(tx_chn->tx_chn, &buf_dma);
118 dma_unmap_single(tx_chn->dma_dev, buf_dma, buf_dma_len,
121 next_desc_dma = cppi5_hdesc_get_next_hbdesc(first_desc);
122 k3_udma_glue_tx_cppi5_to_dma_addr(tx_chn->tx_chn, &next_desc_dma);
123 while (next_desc_dma) {
124 next_desc = k3_cppi_desc_pool_dma2virt(tx_chn->desc_pool,
126 cppi5_hdesc_get_obuf(next_desc, &buf_dma, &buf_dma_len);
127 k3_udma_glue_tx_cppi5_to_dma_addr(tx_chn->tx_chn, &buf_dma);
129 dma_unmap_page(tx_chn->dma_dev, buf_dma, buf_dma_len,
132 next_desc_dma = cppi5_hdesc_get_next_hbdesc(next_desc);
133 k3_udma_glue_tx_cppi5_to_dma_addr(tx_chn->tx_chn, &next_desc_dma);
135 k3_cppi_desc_pool_free(tx_chn->desc_pool, next_desc);
138 k3_cppi_desc_pool_free(tx_chn->desc_pool, first_desc);
141 static int emac_tx_complete_packets(struct prueth_emac *emac, int chn,
144 struct net_device *ndev = emac->ndev;
145 struct cppi5_host_desc_t *desc_tx;
146 struct netdev_queue *netif_txq;
147 struct prueth_tx_chn *tx_chn;
148 unsigned int total_bytes = 0;
154 tx_chn = &emac->tx_chns[chn];
157 res = k3_udma_glue_pop_tx_chn(tx_chn->tx_chn, &desc_dma);
161 /* teardown completion */
162 if (cppi5_desc_is_tdcm(desc_dma)) {
163 if (atomic_dec_and_test(&emac->tdown_cnt))
164 complete(&emac->tdown_complete);
168 desc_tx = k3_cppi_desc_pool_dma2virt(tx_chn->desc_pool,
170 swdata = cppi5_hdesc_get_swdata(desc_tx);
173 prueth_xmit_free(tx_chn, desc_tx);
176 ndev->stats.tx_packets++;
177 ndev->stats.tx_bytes += skb->len;
178 total_bytes += skb->len;
179 napi_consume_skb(skb, budget);
186 netif_txq = netdev_get_tx_queue(ndev, chn);
187 netdev_tx_completed_queue(netif_txq, num_tx, total_bytes);
189 if (netif_tx_queue_stopped(netif_txq)) {
190 /* If the TX queue was stopped, wake it now
191 * if we have enough room.
193 __netif_tx_lock(netif_txq, smp_processor_id());
194 if (netif_running(ndev) &&
195 (k3_cppi_desc_pool_avail(tx_chn->desc_pool) >=
197 netif_tx_wake_queue(netif_txq);
198 __netif_tx_unlock(netif_txq);
204 static int emac_napi_tx_poll(struct napi_struct *napi_tx, int budget)
206 struct prueth_tx_chn *tx_chn = prueth_napi_to_tx_chn(napi_tx);
207 struct prueth_emac *emac = tx_chn->emac;
210 num_tx_packets = emac_tx_complete_packets(emac, tx_chn->id, budget);
212 if (num_tx_packets >= budget)
215 if (napi_complete_done(napi_tx, num_tx_packets))
216 enable_irq(tx_chn->irq);
218 return num_tx_packets;
221 static irqreturn_t prueth_tx_irq(int irq, void *dev_id)
223 struct prueth_tx_chn *tx_chn = dev_id;
225 disable_irq_nosync(irq);
226 napi_schedule(&tx_chn->napi_tx);
231 static int prueth_ndev_add_tx_napi(struct prueth_emac *emac)
233 struct prueth *prueth = emac->prueth;
236 for (i = 0; i < emac->tx_ch_num; i++) {
237 struct prueth_tx_chn *tx_chn = &emac->tx_chns[i];
239 netif_napi_add_tx(emac->ndev, &tx_chn->napi_tx, emac_napi_tx_poll);
240 ret = request_irq(tx_chn->irq, prueth_tx_irq,
241 IRQF_TRIGGER_HIGH, tx_chn->name,
244 netif_napi_del(&tx_chn->napi_tx);
245 dev_err(prueth->dev, "unable to request TX IRQ %d\n",
253 prueth_ndev_del_tx_napi(emac, i);
257 static int prueth_init_tx_chns(struct prueth_emac *emac)
259 static const struct k3_ring_cfg ring_cfg = {
260 .elm_size = K3_RINGACC_RING_ELSIZE_8,
261 .mode = K3_RINGACC_RING_MODE_RING,
263 .size = PRUETH_MAX_TX_DESC,
265 struct k3_udma_glue_tx_channel_cfg tx_cfg;
266 struct device *dev = emac->prueth->dev;
267 struct net_device *ndev = emac->ndev;
271 slice = prueth_emac_slice(emac);
275 init_completion(&emac->tdown_complete);
277 hdesc_size = cppi5_hdesc_calc_size(true, PRUETH_NAV_PS_DATA_SIZE,
278 PRUETH_NAV_SW_DATA_SIZE);
279 memset(&tx_cfg, 0, sizeof(tx_cfg));
280 tx_cfg.swdata_size = PRUETH_NAV_SW_DATA_SIZE;
281 tx_cfg.tx_cfg = ring_cfg;
282 tx_cfg.txcq_cfg = ring_cfg;
284 for (i = 0; i < emac->tx_ch_num; i++) {
285 struct prueth_tx_chn *tx_chn = &emac->tx_chns[i];
287 /* To differentiate channels for SLICE0 vs SLICE1 */
288 snprintf(tx_chn->name, sizeof(tx_chn->name),
289 "tx%d-%d", slice, i);
293 tx_chn->descs_num = PRUETH_MAX_TX_DESC;
296 k3_udma_glue_request_tx_chn(dev, tx_chn->name,
298 if (IS_ERR(tx_chn->tx_chn)) {
299 ret = PTR_ERR(tx_chn->tx_chn);
300 tx_chn->tx_chn = NULL;
302 "Failed to request tx dma ch: %d\n", ret);
306 tx_chn->dma_dev = k3_udma_glue_tx_get_dma_device(tx_chn->tx_chn);
308 k3_cppi_desc_pool_create_name(tx_chn->dma_dev,
312 if (IS_ERR(tx_chn->desc_pool)) {
313 ret = PTR_ERR(tx_chn->desc_pool);
314 tx_chn->desc_pool = NULL;
315 netdev_err(ndev, "Failed to create tx pool: %d\n", ret);
319 ret = k3_udma_glue_tx_get_irq(tx_chn->tx_chn);
321 netdev_err(ndev, "failed to get tx irq\n");
326 snprintf(tx_chn->name, sizeof(tx_chn->name), "%s-tx%d",
327 dev_name(dev), tx_chn->id);
333 prueth_cleanup_tx_chns(emac);
337 static int prueth_init_rx_chns(struct prueth_emac *emac,
338 struct prueth_rx_chn *rx_chn,
339 char *name, u32 max_rflows,
342 struct k3_udma_glue_rx_channel_cfg rx_cfg;
343 struct device *dev = emac->prueth->dev;
344 struct net_device *ndev = emac->ndev;
345 u32 fdqring_id, hdesc_size;
346 int i, ret = 0, slice;
348 slice = prueth_emac_slice(emac);
352 /* To differentiate channels for SLICE0 vs SLICE1 */
353 snprintf(rx_chn->name, sizeof(rx_chn->name), "%s%d", name, slice);
355 hdesc_size = cppi5_hdesc_calc_size(true, PRUETH_NAV_PS_DATA_SIZE,
356 PRUETH_NAV_SW_DATA_SIZE);
357 memset(&rx_cfg, 0, sizeof(rx_cfg));
358 rx_cfg.swdata_size = PRUETH_NAV_SW_DATA_SIZE;
359 rx_cfg.flow_id_num = max_rflows;
360 rx_cfg.flow_id_base = -1; /* udmax will auto select flow id base */
364 rx_chn->descs_num = max_desc_num;
366 rx_chn->rx_chn = k3_udma_glue_request_rx_chn(dev, rx_chn->name,
368 if (IS_ERR(rx_chn->rx_chn)) {
369 ret = PTR_ERR(rx_chn->rx_chn);
370 rx_chn->rx_chn = NULL;
371 netdev_err(ndev, "Failed to request rx dma ch: %d\n", ret);
375 rx_chn->dma_dev = k3_udma_glue_rx_get_dma_device(rx_chn->rx_chn);
376 rx_chn->desc_pool = k3_cppi_desc_pool_create_name(rx_chn->dma_dev,
380 if (IS_ERR(rx_chn->desc_pool)) {
381 ret = PTR_ERR(rx_chn->desc_pool);
382 rx_chn->desc_pool = NULL;
383 netdev_err(ndev, "Failed to create rx pool: %d\n", ret);
387 emac->rx_flow_id_base = k3_udma_glue_rx_get_flow_id_base(rx_chn->rx_chn);
388 netdev_dbg(ndev, "flow id base = %d\n", emac->rx_flow_id_base);
390 fdqring_id = K3_RINGACC_RING_ID_ANY;
391 for (i = 0; i < rx_cfg.flow_id_num; i++) {
392 struct k3_ring_cfg rxring_cfg = {
393 .elm_size = K3_RINGACC_RING_ELSIZE_8,
394 .mode = K3_RINGACC_RING_MODE_RING,
397 struct k3_ring_cfg fdqring_cfg = {
398 .elm_size = K3_RINGACC_RING_ELSIZE_8,
399 .flags = K3_RINGACC_RING_SHARED,
401 struct k3_udma_glue_rx_flow_cfg rx_flow_cfg = {
402 .rx_cfg = rxring_cfg,
403 .rxfdq_cfg = fdqring_cfg,
404 .ring_rxq_id = K3_RINGACC_RING_ID_ANY,
406 K3_UDMA_GLUE_SRC_TAG_LO_USE_REMOTE_SRC_TAG,
409 rx_flow_cfg.ring_rxfdq0_id = fdqring_id;
410 rx_flow_cfg.rx_cfg.size = max_desc_num;
411 rx_flow_cfg.rxfdq_cfg.size = max_desc_num;
412 rx_flow_cfg.rxfdq_cfg.mode = emac->prueth->pdata.fdqring_mode;
414 ret = k3_udma_glue_rx_flow_init(rx_chn->rx_chn,
417 netdev_err(ndev, "Failed to init rx flow%d %d\n",
422 fdqring_id = k3_udma_glue_rx_flow_get_fdq_id(rx_chn->rx_chn,
424 rx_chn->irq[i] = k3_udma_glue_rx_get_irq(rx_chn->rx_chn, i);
425 if (rx_chn->irq[i] <= 0) {
426 ret = rx_chn->irq[i];
427 netdev_err(ndev, "Failed to get rx dma irq");
435 prueth_cleanup_rx_chns(emac, rx_chn, max_rflows);
439 static int prueth_dma_rx_push(struct prueth_emac *emac,
441 struct prueth_rx_chn *rx_chn)
443 struct net_device *ndev = emac->ndev;
444 struct cppi5_host_desc_t *desc_rx;
445 u32 pkt_len = skb_tailroom(skb);
450 desc_rx = k3_cppi_desc_pool_alloc(rx_chn->desc_pool);
452 netdev_err(ndev, "rx push: failed to allocate descriptor\n");
455 desc_dma = k3_cppi_desc_pool_virt2dma(rx_chn->desc_pool, desc_rx);
457 buf_dma = dma_map_single(rx_chn->dma_dev, skb->data, pkt_len, DMA_FROM_DEVICE);
458 if (unlikely(dma_mapping_error(rx_chn->dma_dev, buf_dma))) {
459 k3_cppi_desc_pool_free(rx_chn->desc_pool, desc_rx);
460 netdev_err(ndev, "rx push: failed to map rx pkt buffer\n");
464 cppi5_hdesc_init(desc_rx, CPPI5_INFO0_HDESC_EPIB_PRESENT,
465 PRUETH_NAV_PS_DATA_SIZE);
466 k3_udma_glue_rx_dma_to_cppi5_addr(rx_chn->rx_chn, &buf_dma);
467 cppi5_hdesc_attach_buf(desc_rx, buf_dma, skb_tailroom(skb), buf_dma, skb_tailroom(skb));
469 swdata = cppi5_hdesc_get_swdata(desc_rx);
472 return k3_udma_glue_push_rx_chn(rx_chn->rx_chn, 0,
476 static u64 icssg_ts_to_ns(u32 hi_sw, u32 hi, u32 lo, u32 cycle_time_ns)
478 u32 iepcount_lo, iepcount_hi, hi_rollover_count;
481 iepcount_lo = lo & GENMASK(19, 0);
482 iepcount_hi = (hi & GENMASK(11, 0)) << 12 | lo >> 20;
483 hi_rollover_count = hi >> 11;
485 ns = ((u64)hi_rollover_count) << 23 | (iepcount_hi + hi_sw);
486 ns = ns * cycle_time_ns + iepcount_lo;
491 static void emac_rx_timestamp(struct prueth_emac *emac,
492 struct sk_buff *skb, u32 *psdata)
494 struct skb_shared_hwtstamps *ssh;
497 u32 hi_sw = readl(emac->prueth->shram.va +
498 TIMESYNC_FW_WC_COUNT_HI_SW_OFFSET_OFFSET);
499 ns = icssg_ts_to_ns(hi_sw, psdata[1], psdata[0],
500 IEP_DEFAULT_CYCLE_TIME_NS);
502 ssh = skb_hwtstamps(skb);
503 memset(ssh, 0, sizeof(*ssh));
504 ssh->hwtstamp = ns_to_ktime(ns);
507 static int emac_rx_packet(struct prueth_emac *emac, u32 flow_id)
509 struct prueth_rx_chn *rx_chn = &emac->rx_chns;
510 u32 buf_dma_len, pkt_len, port_id = 0;
511 struct net_device *ndev = emac->ndev;
512 struct cppi5_host_desc_t *desc_rx;
513 struct sk_buff *skb, *new_skb;
514 dma_addr_t desc_dma, buf_dma;
519 ret = k3_udma_glue_pop_rx_chn(rx_chn->rx_chn, flow_id, &desc_dma);
522 netdev_err(ndev, "rx pop: failed: %d\n", ret);
526 if (cppi5_desc_is_tdcm(desc_dma)) /* Teardown ? */
529 desc_rx = k3_cppi_desc_pool_dma2virt(rx_chn->desc_pool, desc_dma);
531 swdata = cppi5_hdesc_get_swdata(desc_rx);
534 psdata = cppi5_hdesc_get_psdata(desc_rx);
535 /* RX HW timestamp */
536 if (emac->rx_ts_enabled)
537 emac_rx_timestamp(emac, skb, psdata);
539 cppi5_hdesc_get_obuf(desc_rx, &buf_dma, &buf_dma_len);
540 k3_udma_glue_rx_cppi5_to_dma_addr(rx_chn->rx_chn, &buf_dma);
541 pkt_len = cppi5_hdesc_get_pktlen(desc_rx);
542 /* firmware adds 4 CRC bytes, strip them */
544 cppi5_desc_get_tags_ids(&desc_rx->hdr, &port_id, NULL);
546 dma_unmap_single(rx_chn->dma_dev, buf_dma, buf_dma_len, DMA_FROM_DEVICE);
547 k3_cppi_desc_pool_free(rx_chn->desc_pool, desc_rx);
550 new_skb = netdev_alloc_skb_ip_align(ndev, PRUETH_MAX_PKT_SIZE);
551 /* if allocation fails we drop the packet but push the
552 * descriptor back to the ring with old skb to prevent a stall
555 ndev->stats.rx_dropped++;
558 /* send the filled skb up the n/w stack */
559 skb_put(skb, pkt_len);
560 skb->protocol = eth_type_trans(skb, ndev);
561 napi_gro_receive(&emac->napi_rx, skb);
562 ndev->stats.rx_bytes += pkt_len;
563 ndev->stats.rx_packets++;
566 /* queue another RX DMA */
567 ret = prueth_dma_rx_push(emac, new_skb, &emac->rx_chns);
568 if (WARN_ON(ret < 0)) {
569 dev_kfree_skb_any(new_skb);
570 ndev->stats.rx_errors++;
571 ndev->stats.rx_dropped++;
577 static void prueth_rx_cleanup(void *data, dma_addr_t desc_dma)
579 struct prueth_rx_chn *rx_chn = data;
580 struct cppi5_host_desc_t *desc_rx;
586 desc_rx = k3_cppi_desc_pool_dma2virt(rx_chn->desc_pool, desc_dma);
587 swdata = cppi5_hdesc_get_swdata(desc_rx);
589 cppi5_hdesc_get_obuf(desc_rx, &buf_dma, &buf_dma_len);
590 k3_udma_glue_rx_cppi5_to_dma_addr(rx_chn->rx_chn, &buf_dma);
592 dma_unmap_single(rx_chn->dma_dev, buf_dma, buf_dma_len,
594 k3_cppi_desc_pool_free(rx_chn->desc_pool, desc_rx);
596 dev_kfree_skb_any(skb);
599 static int emac_get_tx_ts(struct prueth_emac *emac,
600 struct emac_tx_ts_response *rsp)
602 struct prueth *prueth = emac->prueth;
603 int slice = prueth_emac_slice(emac);
606 addr = icssg_queue_pop(prueth, slice == 0 ?
607 ICSSG_TS_POP_SLICE0 : ICSSG_TS_POP_SLICE1);
611 memcpy_fromio(rsp, prueth->shram.va + addr, sizeof(*rsp));
612 /* return buffer back for to pool */
613 icssg_queue_push(prueth, slice == 0 ?
614 ICSSG_TS_PUSH_SLICE0 : ICSSG_TS_PUSH_SLICE1, addr);
619 static void tx_ts_work(struct prueth_emac *emac)
621 struct skb_shared_hwtstamps ssh;
622 struct emac_tx_ts_response tsr;
628 /* There may be more than one pending requests */
630 ret = emac_get_tx_ts(emac, &tsr);
631 if (ret) /* nothing more */
634 if (tsr.cookie >= PRUETH_MAX_TX_TS_REQUESTS ||
635 !emac->tx_ts_skb[tsr.cookie]) {
636 netdev_err(emac->ndev, "Invalid TX TS cookie 0x%x\n",
641 skb = emac->tx_ts_skb[tsr.cookie];
642 emac->tx_ts_skb[tsr.cookie] = NULL; /* free slot */
644 netdev_err(emac->ndev, "Driver Bug! got NULL skb\n");
648 hi_sw = readl(emac->prueth->shram.va +
649 TIMESYNC_FW_WC_COUNT_HI_SW_OFFSET_OFFSET);
650 ns = icssg_ts_to_ns(hi_sw, tsr.hi_ts, tsr.lo_ts,
651 IEP_DEFAULT_CYCLE_TIME_NS);
653 memset(&ssh, 0, sizeof(ssh));
654 ssh.hwtstamp = ns_to_ktime(ns);
656 skb_tstamp_tx(skb, &ssh);
657 dev_consume_skb_any(skb);
659 if (atomic_dec_and_test(&emac->tx_ts_pending)) /* no more? */
664 static int prueth_tx_ts_cookie_get(struct prueth_emac *emac)
668 /* search and get the next free slot */
669 for (i = 0; i < PRUETH_MAX_TX_TS_REQUESTS; i++) {
670 if (!emac->tx_ts_skb[i]) {
671 emac->tx_ts_skb[i] = ERR_PTR(-EBUSY); /* reserve slot */
680 * emac_ndo_start_xmit - EMAC Transmit function
682 * @ndev: EMAC network adapter
684 * Called by the system to transmit a packet - we queue the packet in
685 * EMAC hardware transmit queue
686 * Doesn't wait for completion we'll check for TX completion in
687 * emac_tx_complete_packets().
689 * Return: enum netdev_tx
691 static enum netdev_tx emac_ndo_start_xmit(struct sk_buff *skb, struct net_device *ndev)
693 struct cppi5_host_desc_t *first_desc, *next_desc, *cur_desc;
694 struct prueth_emac *emac = netdev_priv(ndev);
695 struct netdev_queue *netif_txq;
696 struct prueth_tx_chn *tx_chn;
697 dma_addr_t desc_dma, buf_dma;
698 int i, ret = 0, q_idx;
705 pkt_len = skb_headlen(skb);
706 q_idx = skb_get_queue_mapping(skb);
708 tx_chn = &emac->tx_chns[q_idx];
709 netif_txq = netdev_get_tx_queue(ndev, q_idx);
711 /* Map the linear buffer */
712 buf_dma = dma_map_single(tx_chn->dma_dev, skb->data, pkt_len, DMA_TO_DEVICE);
713 if (dma_mapping_error(tx_chn->dma_dev, buf_dma)) {
714 netdev_err(ndev, "tx: failed to map skb buffer\n");
719 first_desc = k3_cppi_desc_pool_alloc(tx_chn->desc_pool);
721 netdev_dbg(ndev, "tx: failed to allocate descriptor\n");
722 dma_unmap_single(tx_chn->dma_dev, buf_dma, pkt_len, DMA_TO_DEVICE);
723 goto drop_stop_q_busy;
726 cppi5_hdesc_init(first_desc, CPPI5_INFO0_HDESC_EPIB_PRESENT,
727 PRUETH_NAV_PS_DATA_SIZE);
728 cppi5_hdesc_set_pkttype(first_desc, 0);
729 epib = first_desc->epib;
732 if (skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP &&
733 emac->tx_ts_enabled) {
734 tx_ts_cookie = prueth_tx_ts_cookie_get(emac);
735 if (tx_ts_cookie >= 0) {
736 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
737 /* Request TX timestamp */
738 epib[0] = (u32)tx_ts_cookie;
739 epib[1] = 0x80000000; /* TX TS request */
740 emac->tx_ts_skb[tx_ts_cookie] = skb_get(skb);
745 /* set dst tag to indicate internal qid at the firmware which is at
746 * bit8..bit15. bit0..bit7 indicates port num for directed
747 * packets in case of switch mode operation
749 cppi5_desc_set_tags_ids(&first_desc->hdr, 0, (emac->port_id | (q_idx << 8)));
750 k3_udma_glue_tx_dma_to_cppi5_addr(tx_chn->tx_chn, &buf_dma);
751 cppi5_hdesc_attach_buf(first_desc, buf_dma, pkt_len, buf_dma, pkt_len);
752 swdata = cppi5_hdesc_get_swdata(first_desc);
755 /* Handle the case where skb is fragmented in pages */
756 cur_desc = first_desc;
757 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
758 skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
759 u32 frag_size = skb_frag_size(frag);
761 next_desc = k3_cppi_desc_pool_alloc(tx_chn->desc_pool);
764 "tx: failed to allocate frag. descriptor\n");
765 goto free_desc_stop_q_busy_cleanup_tx_ts;
768 buf_dma = skb_frag_dma_map(tx_chn->dma_dev, frag, 0, frag_size,
770 if (dma_mapping_error(tx_chn->dma_dev, buf_dma)) {
771 netdev_err(ndev, "tx: Failed to map skb page\n");
772 k3_cppi_desc_pool_free(tx_chn->desc_pool, next_desc);
777 cppi5_hdesc_reset_hbdesc(next_desc);
778 k3_udma_glue_tx_dma_to_cppi5_addr(tx_chn->tx_chn, &buf_dma);
779 cppi5_hdesc_attach_buf(next_desc,
780 buf_dma, frag_size, buf_dma, frag_size);
782 desc_dma = k3_cppi_desc_pool_virt2dma(tx_chn->desc_pool,
784 k3_udma_glue_tx_dma_to_cppi5_addr(tx_chn->tx_chn, &desc_dma);
785 cppi5_hdesc_link_hbdesc(cur_desc, desc_dma);
787 pkt_len += frag_size;
788 cur_desc = next_desc;
790 WARN_ON_ONCE(pkt_len != skb->len);
792 /* report bql before sending packet */
793 netdev_tx_sent_queue(netif_txq, pkt_len);
795 cppi5_hdesc_set_pktlen(first_desc, pkt_len);
796 desc_dma = k3_cppi_desc_pool_virt2dma(tx_chn->desc_pool, first_desc);
797 /* cppi5_desc_dump(first_desc, 64); */
799 skb_tx_timestamp(skb); /* SW timestamp if SKBTX_IN_PROGRESS not set */
800 ret = k3_udma_glue_push_tx_chn(tx_chn->tx_chn, first_desc, desc_dma);
802 netdev_err(ndev, "tx: push failed: %d\n", ret);
803 goto drop_free_descs;
807 atomic_inc(&emac->tx_ts_pending);
809 if (k3_cppi_desc_pool_avail(tx_chn->desc_pool) < MAX_SKB_FRAGS) {
810 netif_tx_stop_queue(netif_txq);
811 /* Barrier, so that stop_queue visible to other cpus */
812 smp_mb__after_atomic();
814 if (k3_cppi_desc_pool_avail(tx_chn->desc_pool) >=
816 netif_tx_wake_queue(netif_txq);
823 dev_kfree_skb_any(emac->tx_ts_skb[tx_ts_cookie]);
824 emac->tx_ts_skb[tx_ts_cookie] = NULL;
828 prueth_xmit_free(tx_chn, first_desc);
831 dev_kfree_skb_any(skb);
834 ndev->stats.tx_dropped++;
835 netdev_err(ndev, "tx: error: %d\n", ret);
839 free_desc_stop_q_busy_cleanup_tx_ts:
841 dev_kfree_skb_any(emac->tx_ts_skb[tx_ts_cookie]);
842 emac->tx_ts_skb[tx_ts_cookie] = NULL;
844 prueth_xmit_free(tx_chn, first_desc);
847 netif_tx_stop_queue(netif_txq);
848 return NETDEV_TX_BUSY;
851 static void prueth_tx_cleanup(void *data, dma_addr_t desc_dma)
853 struct prueth_tx_chn *tx_chn = data;
854 struct cppi5_host_desc_t *desc_tx;
858 desc_tx = k3_cppi_desc_pool_dma2virt(tx_chn->desc_pool, desc_dma);
859 swdata = cppi5_hdesc_get_swdata(desc_tx);
861 prueth_xmit_free(tx_chn, desc_tx);
863 dev_kfree_skb_any(skb);
866 static irqreturn_t prueth_tx_ts_irq(int irq, void *dev_id)
868 struct prueth_emac *emac = dev_id;
870 /* currently only TX timestamp is being returned */
876 static irqreturn_t prueth_rx_irq(int irq, void *dev_id)
878 struct prueth_emac *emac = dev_id;
880 disable_irq_nosync(irq);
881 napi_schedule(&emac->napi_rx);
886 struct icssg_firmwares {
892 static struct icssg_firmwares icssg_emac_firmwares[] = {
894 .pru = "ti-pruss/am65x-sr2-pru0-prueth-fw.elf",
895 .rtu = "ti-pruss/am65x-sr2-rtu0-prueth-fw.elf",
896 .txpru = "ti-pruss/am65x-sr2-txpru0-prueth-fw.elf",
899 .pru = "ti-pruss/am65x-sr2-pru1-prueth-fw.elf",
900 .rtu = "ti-pruss/am65x-sr2-rtu1-prueth-fw.elf",
901 .txpru = "ti-pruss/am65x-sr2-txpru1-prueth-fw.elf",
905 static int prueth_emac_start(struct prueth *prueth, struct prueth_emac *emac)
907 struct icssg_firmwares *firmwares;
908 struct device *dev = prueth->dev;
911 firmwares = icssg_emac_firmwares;
913 slice = prueth_emac_slice(emac);
915 netdev_err(emac->ndev, "invalid port\n");
919 ret = icssg_config(prueth, emac, slice);
923 ret = rproc_set_firmware(prueth->pru[slice], firmwares[slice].pru);
924 ret = rproc_boot(prueth->pru[slice]);
926 dev_err(dev, "failed to boot PRU%d: %d\n", slice, ret);
930 ret = rproc_set_firmware(prueth->rtu[slice], firmwares[slice].rtu);
931 ret = rproc_boot(prueth->rtu[slice]);
933 dev_err(dev, "failed to boot RTU%d: %d\n", slice, ret);
937 ret = rproc_set_firmware(prueth->txpru[slice], firmwares[slice].txpru);
938 ret = rproc_boot(prueth->txpru[slice]);
940 dev_err(dev, "failed to boot TX_PRU%d: %d\n", slice, ret);
944 emac->fw_running = 1;
948 rproc_shutdown(prueth->rtu[slice]);
951 rproc_shutdown(prueth->pru[slice]);
956 static void prueth_emac_stop(struct prueth_emac *emac)
958 struct prueth *prueth = emac->prueth;
961 switch (emac->port_id) {
962 case PRUETH_PORT_MII0:
965 case PRUETH_PORT_MII1:
969 netdev_err(emac->ndev, "invalid port\n");
973 emac->fw_running = 0;
974 rproc_shutdown(prueth->txpru[slice]);
975 rproc_shutdown(prueth->rtu[slice]);
976 rproc_shutdown(prueth->pru[slice]);
979 static void prueth_cleanup_tx_ts(struct prueth_emac *emac)
983 for (i = 0; i < PRUETH_MAX_TX_TS_REQUESTS; i++) {
984 if (emac->tx_ts_skb[i]) {
985 dev_kfree_skb_any(emac->tx_ts_skb[i]);
986 emac->tx_ts_skb[i] = NULL;
991 /* called back by PHY layer if there is change in link state of hw port*/
992 static void emac_adjust_link(struct net_device *ndev)
994 struct prueth_emac *emac = netdev_priv(ndev);
995 struct phy_device *phydev = ndev->phydev;
996 struct prueth *prueth = emac->prueth;
997 bool new_state = false;
1001 /* check the mode of operation - full/half duplex */
1002 if (phydev->duplex != emac->duplex) {
1004 emac->duplex = phydev->duplex;
1006 if (phydev->speed != emac->speed) {
1008 emac->speed = phydev->speed;
1014 } else if (emac->link) {
1018 /* f/w should support 100 & 1000 */
1019 emac->speed = SPEED_1000;
1021 /* half duplex may not be supported by f/w */
1022 emac->duplex = DUPLEX_FULL;
1026 phy_print_status(phydev);
1028 /* update RGMII and MII configuration based on PHY negotiated
1032 /* Set the RGMII cfg for gig en and full duplex */
1033 icssg_update_rgmii_cfg(prueth->miig_rt, emac);
1035 /* update the Tx IPG based on 100M/1G speed */
1036 spin_lock_irqsave(&emac->lock, flags);
1037 icssg_config_ipg(emac);
1038 spin_unlock_irqrestore(&emac->lock, flags);
1039 icssg_config_set_speed(emac);
1040 emac_set_port_state(emac, ICSSG_EMAC_PORT_FORWARD);
1043 emac_set_port_state(emac, ICSSG_EMAC_PORT_DISABLE);
1048 /* reactivate the transmit queue */
1049 netif_tx_wake_all_queues(ndev);
1051 netif_tx_stop_all_queues(ndev);
1052 prueth_cleanup_tx_ts(emac);
1056 static int emac_napi_rx_poll(struct napi_struct *napi_rx, int budget)
1058 struct prueth_emac *emac = prueth_napi_to_emac(napi_rx);
1059 int rx_flow = PRUETH_RX_FLOW_DATA;
1060 int flow = PRUETH_MAX_RX_FLOWS;
1066 cur_budget = budget - num_rx;
1068 while (cur_budget--) {
1069 ret = emac_rx_packet(emac, flow);
1075 if (num_rx >= budget)
1079 if (num_rx < budget && napi_complete_done(napi_rx, num_rx))
1080 enable_irq(emac->rx_chns.irq[rx_flow]);
1085 static int prueth_prepare_rx_chan(struct prueth_emac *emac,
1086 struct prueth_rx_chn *chn,
1089 struct sk_buff *skb;
1092 for (i = 0; i < chn->descs_num; i++) {
1093 skb = __netdev_alloc_skb_ip_align(NULL, buf_size, GFP_KERNEL);
1097 ret = prueth_dma_rx_push(emac, skb, chn);
1099 netdev_err(emac->ndev,
1100 "cannot submit skb for rx chan %s ret %d\n",
1110 static void prueth_reset_tx_chan(struct prueth_emac *emac, int ch_num,
1115 for (i = 0; i < ch_num; i++) {
1117 k3_udma_glue_reset_tx_chn(emac->tx_chns[i].tx_chn,
1120 k3_udma_glue_disable_tx_chn(emac->tx_chns[i].tx_chn);
1124 static void prueth_reset_rx_chan(struct prueth_rx_chn *chn,
1125 int num_flows, bool disable)
1129 for (i = 0; i < num_flows; i++)
1130 k3_udma_glue_reset_rx_chn(chn->rx_chn, i, chn,
1131 prueth_rx_cleanup, !!i);
1133 k3_udma_glue_disable_rx_chn(chn->rx_chn);
1136 static int emac_phy_connect(struct prueth_emac *emac)
1138 struct prueth *prueth = emac->prueth;
1139 struct net_device *ndev = emac->ndev;
1141 ndev->phydev = of_phy_connect(emac->ndev, emac->phy_node,
1142 &emac_adjust_link, 0,
1144 if (!ndev->phydev) {
1145 dev_err(prueth->dev, "couldn't connect to phy %s\n",
1146 emac->phy_node->full_name);
1150 /* remove unsupported modes */
1151 phy_remove_link_mode(ndev->phydev, ETHTOOL_LINK_MODE_10baseT_Half_BIT);
1152 phy_remove_link_mode(ndev->phydev, ETHTOOL_LINK_MODE_100baseT_Half_BIT);
1153 phy_remove_link_mode(ndev->phydev, ETHTOOL_LINK_MODE_1000baseT_Half_BIT);
1154 phy_remove_link_mode(ndev->phydev, ETHTOOL_LINK_MODE_Pause_BIT);
1155 phy_remove_link_mode(ndev->phydev, ETHTOOL_LINK_MODE_Asym_Pause_BIT);
1157 if (emac->phy_if == PHY_INTERFACE_MODE_MII)
1158 phy_set_max_speed(ndev->phydev, SPEED_100);
1163 static u64 prueth_iep_gettime(void *clockops_data, struct ptp_system_timestamp *sts)
1165 u32 hi_rollover_count, hi_rollover_count_r;
1166 struct prueth_emac *emac = clockops_data;
1167 struct prueth *prueth = emac->prueth;
1168 void __iomem *fw_hi_r_count_addr;
1169 void __iomem *fw_count_hi_addr;
1170 u32 iepcount_hi, iepcount_hi_r;
1171 unsigned long flags;
1175 fw_count_hi_addr = prueth->shram.va + TIMESYNC_FW_WC_COUNT_HI_SW_OFFSET_OFFSET;
1176 fw_hi_r_count_addr = prueth->shram.va + TIMESYNC_FW_WC_HI_ROLLOVER_COUNT_OFFSET;
1178 local_irq_save(flags);
1180 iepcount_hi = icss_iep_get_count_hi(emac->iep);
1181 iepcount_hi += readl(fw_count_hi_addr);
1182 hi_rollover_count = readl(fw_hi_r_count_addr);
1183 ptp_read_system_prets(sts);
1184 iepcount_lo = icss_iep_get_count_low(emac->iep);
1185 ptp_read_system_postts(sts);
1187 iepcount_hi_r = icss_iep_get_count_hi(emac->iep);
1188 iepcount_hi_r += readl(fw_count_hi_addr);
1189 hi_rollover_count_r = readl(fw_hi_r_count_addr);
1190 } while ((iepcount_hi_r != iepcount_hi) ||
1191 (hi_rollover_count != hi_rollover_count_r));
1192 local_irq_restore(flags);
1194 ts = ((u64)hi_rollover_count) << 23 | iepcount_hi;
1195 ts = ts * (u64)IEP_DEFAULT_CYCLE_TIME_NS + iepcount_lo;
1200 static void prueth_iep_settime(void *clockops_data, u64 ns)
1202 struct icssg_setclock_desc __iomem *sc_descp;
1203 struct prueth_emac *emac = clockops_data;
1204 struct icssg_setclock_desc sc_desc;
1209 if (!emac->fw_running)
1212 sc_descp = emac->prueth->shram.va + TIMESYNC_FW_WC_SETCLOCK_DESC_OFFSET;
1214 cycletime = IEP_DEFAULT_CYCLE_TIME_NS;
1215 cyclecount = ns / cycletime;
1217 memset(&sc_desc, 0, sizeof(sc_desc));
1218 sc_desc.margin = cycletime - 1000;
1219 sc_desc.cyclecounter0_set = cyclecount & GENMASK(31, 0);
1220 sc_desc.cyclecounter1_set = (cyclecount & GENMASK(63, 32)) >> 32;
1221 sc_desc.iepcount_set = ns % cycletime;
1222 sc_desc.CMP0_current = cycletime - 4; //Count from 0 to (cycle time)-4
1224 memcpy_toio(sc_descp, &sc_desc, sizeof(sc_desc));
1226 writeb(1, &sc_descp->request);
1228 timeout = 5; /* fw should take 2-3 ms */
1230 if (readb(&sc_descp->acknowledgment))
1233 usleep_range(500, 1000);
1236 dev_err(emac->prueth->dev, "settime timeout\n");
1239 static int prueth_perout_enable(void *clockops_data,
1240 struct ptp_perout_request *req, int on,
1243 struct prueth_emac *emac = clockops_data;
1244 u32 reduction_factor = 0, offset = 0;
1245 struct timespec64 ts;
1251 /* Any firmware specific stuff for PPS/PEROUT handling */
1252 ts.tv_sec = req->period.sec;
1253 ts.tv_nsec = req->period.nsec;
1254 ns_period = timespec64_to_ns(&ts);
1256 /* f/w doesn't support period less than cycle time */
1257 if (ns_period < IEP_DEFAULT_CYCLE_TIME_NS)
1260 reduction_factor = ns_period / IEP_DEFAULT_CYCLE_TIME_NS;
1261 offset = ns_period % IEP_DEFAULT_CYCLE_TIME_NS;
1263 /* f/w requires at least 1uS within a cycle so CMP
1264 * can trigger after SYNC is enabled
1266 if (offset < 5 * NSEC_PER_USEC)
1267 offset = 5 * NSEC_PER_USEC;
1269 /* if offset is close to cycle time then we will miss
1270 * the CMP event for last tick when IEP rolls over.
1271 * In normal mode, IEP tick is 4ns.
1272 * In slow compensation it could be 0ns or 8ns at
1273 * every slow compensation cycle.
1275 if (offset > IEP_DEFAULT_CYCLE_TIME_NS - 8)
1276 offset = IEP_DEFAULT_CYCLE_TIME_NS - 8;
1278 /* we're in shadow mode so need to set upper 32-bits */
1279 *cmp = (u64)offset << 32;
1281 writel(reduction_factor, emac->prueth->shram.va +
1282 TIMESYNC_FW_WC_SYNCOUT_REDUCTION_FACTOR_OFFSET);
1284 writel(0, emac->prueth->shram.va +
1285 TIMESYNC_FW_WC_SYNCOUT_START_TIME_CYCLECOUNT_OFFSET);
1290 const struct icss_iep_clockops prueth_iep_clockops = {
1291 .settime = prueth_iep_settime,
1292 .gettime = prueth_iep_gettime,
1293 .perout_enable = prueth_perout_enable,
1297 * emac_ndo_open - EMAC device open
1298 * @ndev: network adapter device
1300 * Called when system wants to start the interface.
1302 * Return: 0 for a successful open, or appropriate error code
1304 static int emac_ndo_open(struct net_device *ndev)
1306 struct prueth_emac *emac = netdev_priv(ndev);
1307 int ret, i, num_data_chn = emac->tx_ch_num;
1308 struct prueth *prueth = emac->prueth;
1309 int slice = prueth_emac_slice(emac);
1310 struct device *dev = prueth->dev;
1314 /* clear SMEM and MSMC settings for all slices */
1315 if (!prueth->emacs_initialized) {
1316 memset_io(prueth->msmcram.va, 0, prueth->msmcram.size);
1317 memset_io(prueth->shram.va, 0, ICSSG_CONFIG_OFFSET_SLICE1 * PRUETH_NUM_MACS);
1320 /* set h/w MAC as user might have re-configured */
1321 ether_addr_copy(emac->mac_addr, ndev->dev_addr);
1323 icssg_class_set_mac_addr(prueth->miig_rt, slice, emac->mac_addr);
1324 icssg_ft1_set_mac_addr(prueth->miig_rt, slice, emac->mac_addr);
1326 icssg_class_default(prueth->miig_rt, slice, 0);
1328 /* Notify the stack of the actual queue counts. */
1329 ret = netif_set_real_num_tx_queues(ndev, num_data_chn);
1331 dev_err(dev, "cannot set real number of tx queues\n");
1335 init_completion(&emac->cmd_complete);
1336 ret = prueth_init_tx_chns(emac);
1338 dev_err(dev, "failed to init tx channel: %d\n", ret);
1342 max_rx_flows = PRUETH_MAX_RX_FLOWS;
1343 ret = prueth_init_rx_chns(emac, &emac->rx_chns, "rx",
1344 max_rx_flows, PRUETH_MAX_RX_DESC);
1346 dev_err(dev, "failed to init rx channel: %d\n", ret);
1350 ret = prueth_ndev_add_tx_napi(emac);
1354 /* we use only the highest priority flow for now i.e. @irq[3] */
1355 rx_flow = PRUETH_RX_FLOW_DATA;
1356 ret = request_irq(emac->rx_chns.irq[rx_flow], prueth_rx_irq,
1357 IRQF_TRIGGER_HIGH, dev_name(dev), emac);
1359 dev_err(dev, "unable to request RX IRQ\n");
1363 /* reset and start PRU firmware */
1364 ret = prueth_emac_start(prueth, emac);
1368 icssg_mii_update_mtu(prueth->mii_rt, slice, ndev->max_mtu);
1370 if (!prueth->emacs_initialized) {
1371 ret = icss_iep_init(emac->iep, &prueth_iep_clockops,
1372 emac, IEP_DEFAULT_CYCLE_TIME_NS);
1375 ret = request_threaded_irq(emac->tx_ts_irq, NULL, prueth_tx_ts_irq,
1376 IRQF_ONESHOT, dev_name(dev), emac);
1381 ret = prueth_prepare_rx_chan(emac, &emac->rx_chns, PRUETH_MAX_PKT_SIZE);
1383 goto free_tx_ts_irq;
1385 ret = k3_udma_glue_enable_rx_chn(emac->rx_chns.rx_chn);
1389 for (i = 0; i < emac->tx_ch_num; i++) {
1390 ret = k3_udma_glue_enable_tx_chn(emac->tx_chns[i].tx_chn);
1395 /* Enable NAPI in Tx and Rx direction */
1396 for (i = 0; i < emac->tx_ch_num; i++)
1397 napi_enable(&emac->tx_chns[i].napi_tx);
1398 napi_enable(&emac->napi_rx);
1401 phy_start(ndev->phydev);
1403 prueth->emacs_initialized++;
1405 queue_work(system_long_wq, &emac->stats_work.work);
1410 /* Since interface is not yet up, there is wouldn't be
1411 * any SKB for completion. So set false to free_skb
1413 prueth_reset_tx_chan(emac, i, false);
1415 prueth_reset_rx_chan(&emac->rx_chns, max_rx_flows, false);
1417 free_irq(emac->tx_ts_irq, emac);
1419 prueth_emac_stop(emac);
1421 free_irq(emac->rx_chns.irq[rx_flow], emac);
1423 prueth_ndev_del_tx_napi(emac, emac->tx_ch_num);
1425 prueth_cleanup_rx_chns(emac, &emac->rx_chns, max_rx_flows);
1427 prueth_cleanup_tx_chns(emac);
1433 * emac_ndo_stop - EMAC device stop
1434 * @ndev: network adapter device
1436 * Called when system wants to stop or down the interface.
1438 * Return: Always 0 (Success)
1440 static int emac_ndo_stop(struct net_device *ndev)
1442 struct prueth_emac *emac = netdev_priv(ndev);
1443 struct prueth *prueth = emac->prueth;
1444 int rx_flow = PRUETH_RX_FLOW_DATA;
1448 /* inform the upper layers. */
1449 netif_tx_stop_all_queues(ndev);
1451 /* block packets from wire */
1453 phy_stop(ndev->phydev);
1455 icssg_class_disable(prueth->miig_rt, prueth_emac_slice(emac));
1457 atomic_set(&emac->tdown_cnt, emac->tx_ch_num);
1458 /* ensure new tdown_cnt value is visible */
1459 smp_mb__after_atomic();
1460 /* tear down and disable UDMA channels */
1461 reinit_completion(&emac->tdown_complete);
1462 for (i = 0; i < emac->tx_ch_num; i++)
1463 k3_udma_glue_tdown_tx_chn(emac->tx_chns[i].tx_chn, false);
1465 ret = wait_for_completion_timeout(&emac->tdown_complete,
1466 msecs_to_jiffies(1000));
1468 netdev_err(ndev, "tx teardown timeout\n");
1470 prueth_reset_tx_chan(emac, emac->tx_ch_num, true);
1471 for (i = 0; i < emac->tx_ch_num; i++)
1472 napi_disable(&emac->tx_chns[i].napi_tx);
1474 max_rx_flows = PRUETH_MAX_RX_FLOWS;
1475 k3_udma_glue_tdown_rx_chn(emac->rx_chns.rx_chn, true);
1477 prueth_reset_rx_chan(&emac->rx_chns, max_rx_flows, true);
1479 napi_disable(&emac->napi_rx);
1481 cancel_work_sync(&emac->rx_mode_work);
1483 /* Destroying the queued work in ndo_stop() */
1484 cancel_delayed_work_sync(&emac->stats_work);
1487 prueth_emac_stop(emac);
1489 if (prueth->emacs_initialized == 1)
1490 icss_iep_exit(emac->iep);
1493 prueth_emac_stop(emac);
1495 free_irq(emac->tx_ts_irq, emac);
1497 free_irq(emac->rx_chns.irq[rx_flow], emac);
1498 prueth_ndev_del_tx_napi(emac, emac->tx_ch_num);
1499 prueth_cleanup_tx_chns(emac);
1501 prueth_cleanup_rx_chns(emac, &emac->rx_chns, max_rx_flows);
1502 prueth_cleanup_tx_chns(emac);
1504 prueth->emacs_initialized--;
1509 static void emac_ndo_tx_timeout(struct net_device *ndev, unsigned int txqueue)
1511 ndev->stats.tx_errors++;
1514 static void emac_ndo_set_rx_mode_work(struct work_struct *work)
1516 struct prueth_emac *emac = container_of(work, struct prueth_emac, rx_mode_work);
1517 struct net_device *ndev = emac->ndev;
1518 bool promisc, allmulti;
1520 if (!netif_running(ndev))
1523 promisc = ndev->flags & IFF_PROMISC;
1524 allmulti = ndev->flags & IFF_ALLMULTI;
1525 emac_set_port_state(emac, ICSSG_EMAC_PORT_UC_FLOODING_DISABLE);
1526 emac_set_port_state(emac, ICSSG_EMAC_PORT_MC_FLOODING_DISABLE);
1529 emac_set_port_state(emac, ICSSG_EMAC_PORT_UC_FLOODING_ENABLE);
1530 emac_set_port_state(emac, ICSSG_EMAC_PORT_MC_FLOODING_ENABLE);
1535 emac_set_port_state(emac, ICSSG_EMAC_PORT_MC_FLOODING_ENABLE);
1539 if (!netdev_mc_empty(ndev)) {
1540 emac_set_port_state(emac, ICSSG_EMAC_PORT_MC_FLOODING_ENABLE);
1546 * emac_ndo_set_rx_mode - EMAC set receive mode function
1547 * @ndev: The EMAC network adapter
1549 * Called when system wants to set the receive mode of the device.
1552 static void emac_ndo_set_rx_mode(struct net_device *ndev)
1554 struct prueth_emac *emac = netdev_priv(ndev);
1556 queue_work(emac->cmd_wq, &emac->rx_mode_work);
1559 static int emac_set_ts_config(struct net_device *ndev, struct ifreq *ifr)
1561 struct prueth_emac *emac = netdev_priv(ndev);
1562 struct hwtstamp_config config;
1564 if (copy_from_user(&config, ifr->ifr_data, sizeof(config)))
1567 switch (config.tx_type) {
1568 case HWTSTAMP_TX_OFF:
1569 emac->tx_ts_enabled = 0;
1571 case HWTSTAMP_TX_ON:
1572 emac->tx_ts_enabled = 1;
1578 switch (config.rx_filter) {
1579 case HWTSTAMP_FILTER_NONE:
1580 emac->rx_ts_enabled = 0;
1582 case HWTSTAMP_FILTER_ALL:
1583 case HWTSTAMP_FILTER_SOME:
1584 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
1585 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
1586 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
1587 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
1588 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
1589 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
1590 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
1591 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
1592 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
1593 case HWTSTAMP_FILTER_PTP_V2_EVENT:
1594 case HWTSTAMP_FILTER_PTP_V2_SYNC:
1595 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
1596 case HWTSTAMP_FILTER_NTP_ALL:
1597 emac->rx_ts_enabled = 1;
1598 config.rx_filter = HWTSTAMP_FILTER_ALL;
1604 return copy_to_user(ifr->ifr_data, &config, sizeof(config)) ?
1608 static int emac_get_ts_config(struct net_device *ndev, struct ifreq *ifr)
1610 struct prueth_emac *emac = netdev_priv(ndev);
1611 struct hwtstamp_config config;
1614 config.tx_type = emac->tx_ts_enabled ? HWTSTAMP_TX_ON : HWTSTAMP_TX_OFF;
1615 config.rx_filter = emac->rx_ts_enabled ? HWTSTAMP_FILTER_ALL : HWTSTAMP_FILTER_NONE;
1617 return copy_to_user(ifr->ifr_data, &config, sizeof(config)) ?
1621 static int emac_ndo_ioctl(struct net_device *ndev, struct ifreq *ifr, int cmd)
1625 return emac_get_ts_config(ndev, ifr);
1627 return emac_set_ts_config(ndev, ifr);
1632 return phy_do_ioctl(ndev, ifr, cmd);
1635 static void emac_ndo_get_stats64(struct net_device *ndev,
1636 struct rtnl_link_stats64 *stats)
1638 struct prueth_emac *emac = netdev_priv(ndev);
1640 emac_update_hardware_stats(emac);
1642 stats->rx_packets = emac_get_stat_by_name(emac, "rx_packets");
1643 stats->rx_bytes = emac_get_stat_by_name(emac, "rx_bytes");
1644 stats->tx_packets = emac_get_stat_by_name(emac, "tx_packets");
1645 stats->tx_bytes = emac_get_stat_by_name(emac, "tx_bytes");
1646 stats->rx_crc_errors = emac_get_stat_by_name(emac, "rx_crc_errors");
1647 stats->rx_over_errors = emac_get_stat_by_name(emac, "rx_over_errors");
1648 stats->multicast = emac_get_stat_by_name(emac, "rx_multicast_frames");
1650 stats->rx_errors = ndev->stats.rx_errors;
1651 stats->rx_dropped = ndev->stats.rx_dropped;
1652 stats->tx_errors = ndev->stats.tx_errors;
1653 stats->tx_dropped = ndev->stats.tx_dropped;
1656 static const struct net_device_ops emac_netdev_ops = {
1657 .ndo_open = emac_ndo_open,
1658 .ndo_stop = emac_ndo_stop,
1659 .ndo_start_xmit = emac_ndo_start_xmit,
1660 .ndo_set_mac_address = eth_mac_addr,
1661 .ndo_validate_addr = eth_validate_addr,
1662 .ndo_tx_timeout = emac_ndo_tx_timeout,
1663 .ndo_set_rx_mode = emac_ndo_set_rx_mode,
1664 .ndo_eth_ioctl = emac_ndo_ioctl,
1665 .ndo_get_stats64 = emac_ndo_get_stats64,
1668 /* get emac_port corresponding to eth_node name */
1669 static int prueth_node_port(struct device_node *eth_node)
1674 ret = of_property_read_u32(eth_node, "reg", &port_id);
1679 return PRUETH_PORT_MII0;
1680 else if (port_id == 1)
1681 return PRUETH_PORT_MII1;
1683 return PRUETH_PORT_INVALID;
1686 /* get MAC instance corresponding to eth_node name */
1687 static int prueth_node_mac(struct device_node *eth_node)
1692 ret = of_property_read_u32(eth_node, "reg", &port_id);
1698 else if (port_id == 1)
1701 return PRUETH_MAC_INVALID;
1704 static int prueth_netdev_init(struct prueth *prueth,
1705 struct device_node *eth_node)
1707 int ret, num_tx_chn = PRUETH_MAX_TX_QUEUES;
1708 struct prueth_emac *emac;
1709 struct net_device *ndev;
1710 enum prueth_port port;
1711 const char *irq_name;
1712 enum prueth_mac mac;
1714 port = prueth_node_port(eth_node);
1715 if (port == PRUETH_PORT_INVALID)
1718 mac = prueth_node_mac(eth_node);
1719 if (mac == PRUETH_MAC_INVALID)
1722 ndev = alloc_etherdev_mq(sizeof(*emac), num_tx_chn);
1726 emac = netdev_priv(ndev);
1727 emac->prueth = prueth;
1729 emac->port_id = port;
1730 emac->cmd_wq = create_singlethread_workqueue("icssg_cmd_wq");
1731 if (!emac->cmd_wq) {
1735 INIT_WORK(&emac->rx_mode_work, emac_ndo_set_rx_mode_work);
1737 INIT_DELAYED_WORK(&emac->stats_work, emac_stats_work_handler);
1739 ret = pruss_request_mem_region(prueth->pruss,
1740 port == PRUETH_PORT_MII0 ?
1741 PRUSS_MEM_DRAM0 : PRUSS_MEM_DRAM1,
1744 dev_err(prueth->dev, "unable to get DRAM: %d\n", ret);
1749 emac->tx_ch_num = 1;
1751 irq_name = "tx_ts0";
1752 if (emac->port_id == PRUETH_PORT_MII1)
1753 irq_name = "tx_ts1";
1754 emac->tx_ts_irq = platform_get_irq_byname_optional(prueth->pdev, irq_name);
1755 if (emac->tx_ts_irq < 0) {
1756 ret = dev_err_probe(prueth->dev, emac->tx_ts_irq, "could not get tx_ts_irq\n");
1760 SET_NETDEV_DEV(ndev, prueth->dev);
1761 spin_lock_init(&emac->lock);
1762 mutex_init(&emac->cmd_lock);
1764 emac->phy_node = of_parse_phandle(eth_node, "phy-handle", 0);
1765 if (!emac->phy_node && !of_phy_is_fixed_link(eth_node)) {
1766 dev_err(prueth->dev, "couldn't find phy-handle\n");
1769 } else if (of_phy_is_fixed_link(eth_node)) {
1770 ret = of_phy_register_fixed_link(eth_node);
1772 ret = dev_err_probe(prueth->dev, ret,
1773 "failed to register fixed-link phy\n");
1777 emac->phy_node = eth_node;
1780 ret = of_get_phy_mode(eth_node, &emac->phy_if);
1782 dev_err(prueth->dev, "could not get phy-mode property\n");
1786 if (emac->phy_if != PHY_INTERFACE_MODE_MII &&
1787 !phy_interface_mode_is_rgmii(emac->phy_if)) {
1788 dev_err(prueth->dev, "PHY mode unsupported %s\n", phy_modes(emac->phy_if));
1793 /* AM65 SR2.0 has TX Internal delay always enabled by hardware
1794 * and it is not possible to disable TX Internal delay. The below
1795 * switch case block describes how we handle different phy modes
1796 * based on hardware restriction.
1798 switch (emac->phy_if) {
1799 case PHY_INTERFACE_MODE_RGMII_ID:
1800 emac->phy_if = PHY_INTERFACE_MODE_RGMII_RXID;
1802 case PHY_INTERFACE_MODE_RGMII_TXID:
1803 emac->phy_if = PHY_INTERFACE_MODE_RGMII;
1805 case PHY_INTERFACE_MODE_RGMII:
1806 case PHY_INTERFACE_MODE_RGMII_RXID:
1807 dev_err(prueth->dev, "RGMII mode without TX delay is not supported");
1814 /* get mac address from DT and set private and netdev addr */
1815 ret = of_get_ethdev_address(eth_node, ndev);
1816 if (!is_valid_ether_addr(ndev->dev_addr)) {
1817 eth_hw_addr_random(ndev);
1818 dev_warn(prueth->dev, "port %d: using random MAC addr: %pM\n",
1819 port, ndev->dev_addr);
1821 ether_addr_copy(emac->mac_addr, ndev->dev_addr);
1823 ndev->min_mtu = PRUETH_MIN_PKT_SIZE;
1824 ndev->max_mtu = PRUETH_MAX_MTU;
1825 ndev->netdev_ops = &emac_netdev_ops;
1826 ndev->ethtool_ops = &icssg_ethtool_ops;
1827 ndev->hw_features = NETIF_F_SG;
1828 ndev->features = ndev->hw_features;
1830 netif_napi_add(ndev, &emac->napi_rx, emac_napi_rx_poll);
1831 prueth->emac[mac] = emac;
1836 pruss_release_mem_region(prueth->pruss, &emac->dram);
1838 destroy_workqueue(emac->cmd_wq);
1841 prueth->emac[mac] = NULL;
1847 static void prueth_netdev_exit(struct prueth *prueth,
1848 struct device_node *eth_node)
1850 struct prueth_emac *emac;
1851 enum prueth_mac mac;
1853 mac = prueth_node_mac(eth_node);
1854 if (mac == PRUETH_MAC_INVALID)
1857 emac = prueth->emac[mac];
1861 if (of_phy_is_fixed_link(emac->phy_node))
1862 of_phy_deregister_fixed_link(emac->phy_node);
1864 netif_napi_del(&emac->napi_rx);
1866 pruss_release_mem_region(prueth->pruss, &emac->dram);
1867 destroy_workqueue(emac->cmd_wq);
1868 free_netdev(emac->ndev);
1869 prueth->emac[mac] = NULL;
1872 static int prueth_get_cores(struct prueth *prueth, int slice)
1874 struct device *dev = prueth->dev;
1875 enum pruss_pru_id pruss_id;
1876 struct device_node *np;
1892 prueth->pru[slice] = pru_rproc_get(np, idx, &pruss_id);
1893 if (IS_ERR(prueth->pru[slice])) {
1894 ret = PTR_ERR(prueth->pru[slice]);
1895 prueth->pru[slice] = NULL;
1896 return dev_err_probe(dev, ret, "unable to get PRU%d\n", slice);
1898 prueth->pru_id[slice] = pruss_id;
1901 prueth->rtu[slice] = pru_rproc_get(np, idx, NULL);
1902 if (IS_ERR(prueth->rtu[slice])) {
1903 ret = PTR_ERR(prueth->rtu[slice]);
1904 prueth->rtu[slice] = NULL;
1905 return dev_err_probe(dev, ret, "unable to get RTU%d\n", slice);
1909 prueth->txpru[slice] = pru_rproc_get(np, idx, NULL);
1910 if (IS_ERR(prueth->txpru[slice])) {
1911 ret = PTR_ERR(prueth->txpru[slice]);
1912 prueth->txpru[slice] = NULL;
1913 return dev_err_probe(dev, ret, "unable to get TX_PRU%d\n", slice);
1919 static void prueth_put_cores(struct prueth *prueth, int slice)
1921 if (prueth->txpru[slice])
1922 pru_rproc_put(prueth->txpru[slice]);
1924 if (prueth->rtu[slice])
1925 pru_rproc_put(prueth->rtu[slice]);
1927 if (prueth->pru[slice])
1928 pru_rproc_put(prueth->pru[slice]);
1931 static const struct of_device_id prueth_dt_match[];
1933 static int prueth_probe(struct platform_device *pdev)
1935 struct device_node *eth_node, *eth_ports_node;
1936 struct device_node *eth0_node = NULL;
1937 struct device_node *eth1_node = NULL;
1938 struct genpool_data_align gp_data = {
1941 const struct of_device_id *match;
1942 struct device *dev = &pdev->dev;
1943 struct device_node *np;
1944 struct prueth *prueth;
1945 struct pruss *pruss;
1951 match = of_match_device(prueth_dt_match, dev);
1955 prueth = devm_kzalloc(dev, sizeof(*prueth), GFP_KERNEL);
1959 dev_set_drvdata(dev, prueth);
1960 prueth->pdev = pdev;
1961 prueth->pdata = *(const struct prueth_pdata *)match->data;
1964 eth_ports_node = of_get_child_by_name(np, "ethernet-ports");
1965 if (!eth_ports_node)
1968 for_each_child_of_node(eth_ports_node, eth_node) {
1971 if (strcmp(eth_node->name, "port"))
1973 ret = of_property_read_u32(eth_node, "reg", ®);
1975 dev_err(dev, "%pOF error reading port_id %d\n",
1979 of_node_get(eth_node);
1982 eth0_node = eth_node;
1983 if (!of_device_is_available(eth0_node)) {
1984 of_node_put(eth0_node);
1987 } else if (reg == 1) {
1988 eth1_node = eth_node;
1989 if (!of_device_is_available(eth1_node)) {
1990 of_node_put(eth1_node);
1994 dev_err(dev, "port reg should be 0 or 1\n");
1998 of_node_put(eth_ports_node);
2000 /* At least one node must be present and available else we fail */
2001 if (!eth0_node && !eth1_node) {
2002 dev_err(dev, "neither port0 nor port1 node available\n");
2006 if (eth0_node == eth1_node) {
2007 dev_err(dev, "port0 and port1 can't have same reg\n");
2008 of_node_put(eth0_node);
2012 prueth->eth_node[PRUETH_MAC0] = eth0_node;
2013 prueth->eth_node[PRUETH_MAC1] = eth1_node;
2015 prueth->miig_rt = syscon_regmap_lookup_by_phandle(np, "ti,mii-g-rt");
2016 if (IS_ERR(prueth->miig_rt)) {
2017 dev_err(dev, "couldn't get ti,mii-g-rt syscon regmap\n");
2021 prueth->mii_rt = syscon_regmap_lookup_by_phandle(np, "ti,mii-rt");
2022 if (IS_ERR(prueth->mii_rt)) {
2023 dev_err(dev, "couldn't get ti,mii-rt syscon regmap\n");
2028 ret = prueth_get_cores(prueth, ICSS_SLICE0);
2034 ret = prueth_get_cores(prueth, ICSS_SLICE1);
2039 pruss = pruss_get(eth0_node ?
2040 prueth->pru[ICSS_SLICE0] : prueth->pru[ICSS_SLICE1]);
2041 if (IS_ERR(pruss)) {
2042 ret = PTR_ERR(pruss);
2043 dev_err(dev, "unable to get pruss handle\n");
2047 prueth->pruss = pruss;
2049 ret = pruss_request_mem_region(pruss, PRUSS_MEM_SHRD_RAM2,
2052 dev_err(dev, "unable to get PRUSS SHRD RAM2: %d\n", ret);
2053 pruss_put(prueth->pruss);
2056 prueth->sram_pool = of_gen_pool_get(np, "sram", 0);
2057 if (!prueth->sram_pool) {
2058 dev_err(dev, "unable to get SRAM pool\n");
2064 msmc_ram_size = MSMC_RAM_SIZE;
2066 /* NOTE: FW bug needs buffer base to be 64KB aligned */
2067 prueth->msmcram.va =
2068 (void __iomem *)gen_pool_alloc_algo(prueth->sram_pool,
2070 gen_pool_first_fit_align,
2073 if (!prueth->msmcram.va) {
2075 dev_err(dev, "unable to allocate MSMC resource\n");
2078 prueth->msmcram.pa = gen_pool_virt_to_phys(prueth->sram_pool,
2079 (unsigned long)prueth->msmcram.va);
2080 prueth->msmcram.size = msmc_ram_size;
2081 memset_io(prueth->msmcram.va, 0, msmc_ram_size);
2082 dev_dbg(dev, "sram: pa %llx va %p size %zx\n", prueth->msmcram.pa,
2083 prueth->msmcram.va, prueth->msmcram.size);
2085 prueth->iep0 = icss_iep_get_idx(np, 0);
2086 if (IS_ERR(prueth->iep0)) {
2087 ret = dev_err_probe(dev, PTR_ERR(prueth->iep0), "iep0 get failed\n");
2088 prueth->iep0 = NULL;
2092 prueth->iep1 = icss_iep_get_idx(np, 1);
2093 if (IS_ERR(prueth->iep1)) {
2094 ret = dev_err_probe(dev, PTR_ERR(prueth->iep1), "iep1 get failed\n");
2095 icss_iep_put(prueth->iep0);
2096 prueth->iep0 = NULL;
2097 prueth->iep1 = NULL;
2101 if (prueth->pdata.quirk_10m_link_issue) {
2102 /* Enable IEP1 for FW in 64bit mode as W/A for 10M FD link detect issue under TX
2105 icss_iep_init_fw(prueth->iep1);
2108 /* setup netdev interfaces */
2110 ret = prueth_netdev_init(prueth, eth0_node);
2112 dev_err_probe(dev, ret, "netdev init %s failed\n",
2116 prueth->emac[PRUETH_MAC0]->iep = prueth->iep0;
2120 ret = prueth_netdev_init(prueth, eth1_node);
2122 dev_err_probe(dev, ret, "netdev init %s failed\n",
2127 prueth->emac[PRUETH_MAC1]->iep = prueth->iep0;
2130 /* register the network devices */
2132 ret = register_netdev(prueth->emac[PRUETH_MAC0]->ndev);
2134 dev_err(dev, "can't register netdev for port MII0");
2138 prueth->registered_netdevs[PRUETH_MAC0] = prueth->emac[PRUETH_MAC0]->ndev;
2140 emac_phy_connect(prueth->emac[PRUETH_MAC0]);
2141 phy_attached_info(prueth->emac[PRUETH_MAC0]->ndev->phydev);
2145 ret = register_netdev(prueth->emac[PRUETH_MAC1]->ndev);
2147 dev_err(dev, "can't register netdev for port MII1");
2148 goto netdev_unregister;
2151 prueth->registered_netdevs[PRUETH_MAC1] = prueth->emac[PRUETH_MAC1]->ndev;
2152 emac_phy_connect(prueth->emac[PRUETH_MAC1]);
2153 phy_attached_info(prueth->emac[PRUETH_MAC1]->ndev->phydev);
2156 dev_info(dev, "TI PRU ethernet driver initialized: %s EMAC mode\n",
2157 (!eth0_node || !eth1_node) ? "single" : "dual");
2160 of_node_put(eth1_node);
2162 of_node_put(eth0_node);
2166 for (i = 0; i < PRUETH_NUM_MACS; i++) {
2167 if (!prueth->registered_netdevs[i])
2169 if (prueth->emac[i]->ndev->phydev) {
2170 phy_disconnect(prueth->emac[i]->ndev->phydev);
2171 prueth->emac[i]->ndev->phydev = NULL;
2173 unregister_netdev(prueth->registered_netdevs[i]);
2177 for (i = 0; i < PRUETH_NUM_MACS; i++) {
2178 eth_node = prueth->eth_node[i];
2182 prueth_netdev_exit(prueth, eth_node);
2186 if (prueth->pdata.quirk_10m_link_issue)
2187 icss_iep_exit_fw(prueth->iep1);
2190 gen_pool_free(prueth->sram_pool,
2191 (unsigned long)prueth->msmcram.va, msmc_ram_size);
2194 pruss_release_mem_region(prueth->pruss, &prueth->shram);
2195 pruss_put(prueth->pruss);
2199 prueth_put_cores(prueth, ICSS_SLICE1);
2200 of_node_put(eth1_node);
2204 prueth_put_cores(prueth, ICSS_SLICE0);
2205 of_node_put(eth0_node);
2211 static void prueth_remove(struct platform_device *pdev)
2213 struct prueth *prueth = platform_get_drvdata(pdev);
2214 struct device_node *eth_node;
2217 for (i = 0; i < PRUETH_NUM_MACS; i++) {
2218 if (!prueth->registered_netdevs[i])
2220 phy_stop(prueth->emac[i]->ndev->phydev);
2221 phy_disconnect(prueth->emac[i]->ndev->phydev);
2222 prueth->emac[i]->ndev->phydev = NULL;
2223 unregister_netdev(prueth->registered_netdevs[i]);
2226 for (i = 0; i < PRUETH_NUM_MACS; i++) {
2227 eth_node = prueth->eth_node[i];
2231 prueth_netdev_exit(prueth, eth_node);
2234 if (prueth->pdata.quirk_10m_link_issue)
2235 icss_iep_exit_fw(prueth->iep1);
2237 icss_iep_put(prueth->iep1);
2238 icss_iep_put(prueth->iep0);
2240 gen_pool_free(prueth->sram_pool,
2241 (unsigned long)prueth->msmcram.va,
2244 pruss_release_mem_region(prueth->pruss, &prueth->shram);
2246 pruss_put(prueth->pruss);
2248 if (prueth->eth_node[PRUETH_MAC1])
2249 prueth_put_cores(prueth, ICSS_SLICE1);
2251 if (prueth->eth_node[PRUETH_MAC0])
2252 prueth_put_cores(prueth, ICSS_SLICE0);
2255 #ifdef CONFIG_PM_SLEEP
2256 static int prueth_suspend(struct device *dev)
2258 struct prueth *prueth = dev_get_drvdata(dev);
2259 struct net_device *ndev;
2262 for (i = 0; i < PRUETH_NUM_MACS; i++) {
2263 ndev = prueth->registered_netdevs[i];
2268 if (netif_running(ndev)) {
2269 netif_device_detach(ndev);
2270 ret = emac_ndo_stop(ndev);
2272 netdev_err(ndev, "failed to stop: %d", ret);
2281 static int prueth_resume(struct device *dev)
2283 struct prueth *prueth = dev_get_drvdata(dev);
2284 struct net_device *ndev;
2287 for (i = 0; i < PRUETH_NUM_MACS; i++) {
2288 ndev = prueth->registered_netdevs[i];
2293 if (netif_running(ndev)) {
2294 ret = emac_ndo_open(ndev);
2296 netdev_err(ndev, "failed to start: %d", ret);
2299 netif_device_attach(ndev);
2305 #endif /* CONFIG_PM_SLEEP */
2307 static const struct dev_pm_ops prueth_dev_pm_ops = {
2308 SET_SYSTEM_SLEEP_PM_OPS(prueth_suspend, prueth_resume)
2311 static const struct prueth_pdata am654_icssg_pdata = {
2312 .fdqring_mode = K3_RINGACC_RING_MODE_MESSAGE,
2313 .quirk_10m_link_issue = 1,
2316 static const struct of_device_id prueth_dt_match[] = {
2317 { .compatible = "ti,am654-icssg-prueth", .data = &am654_icssg_pdata },
2320 MODULE_DEVICE_TABLE(of, prueth_dt_match);
2322 static struct platform_driver prueth_driver = {
2323 .probe = prueth_probe,
2324 .remove_new = prueth_remove,
2326 .name = "icssg-prueth",
2327 .of_match_table = prueth_dt_match,
2328 .pm = &prueth_dev_pm_ops,
2331 module_platform_driver(prueth_driver);
2333 MODULE_AUTHOR("Roger Quadros <rogerq@ti.com>");
2334 MODULE_AUTHOR("Md Danish Anwar <danishanwar@ti.com>");
2335 MODULE_DESCRIPTION("PRUSS ICSSG Ethernet Driver");
2336 MODULE_LICENSE("GPL");