1 // SPDX-License-Identifier: GPL-2.0
3 * Texas Instruments Ethernet Switch Driver
5 * Copyright (C) 2012 Texas Instruments
9 #include <linux/kernel.h>
11 #include <linux/clk.h>
12 #include <linux/timer.h>
13 #include <linux/module.h>
14 #include <linux/platform_device.h>
15 #include <linux/irqreturn.h>
16 #include <linux/interrupt.h>
17 #include <linux/if_ether.h>
18 #include <linux/etherdevice.h>
19 #include <linux/netdevice.h>
20 #include <linux/net_tstamp.h>
21 #include <linux/phy.h>
22 #include <linux/phy/phy.h>
23 #include <linux/workqueue.h>
24 #include <linux/delay.h>
25 #include <linux/pm_runtime.h>
26 #include <linux/gpio/consumer.h>
28 #include <linux/of_mdio.h>
29 #include <linux/of_net.h>
30 #include <linux/of_device.h>
31 #include <linux/if_vlan.h>
32 #include <linux/kmemleak.h>
33 #include <linux/sys_soc.h>
34 #include <net/page_pool.h>
35 #include <linux/bpf.h>
36 #include <linux/bpf_trace.h>
37 #include <linux/filter.h>
39 #include <linux/pinctrl/consumer.h>
40 #include <net/pkt_cls.h>
44 #include "cpsw_priv.h"
47 #include "davinci_cpdma.h"
49 #include <net/pkt_sched.h>
51 static int debug_level;
52 module_param(debug_level, int, 0);
53 MODULE_PARM_DESC(debug_level, "cpsw debug level (NETIF_MSG bits)");
55 static int ale_ageout = 10;
56 module_param(ale_ageout, int, 0);
57 MODULE_PARM_DESC(ale_ageout, "cpsw ale ageout interval (seconds)");
59 static int rx_packet_max = CPSW_MAX_PACKET_SIZE;
60 module_param(rx_packet_max, int, 0);
61 MODULE_PARM_DESC(rx_packet_max, "maximum receive packet size (bytes)");
63 static int descs_pool_size = CPSW_CPDMA_DESCS_POOL_SIZE_DEFAULT;
64 module_param(descs_pool_size, int, 0444);
65 MODULE_PARM_DESC(descs_pool_size, "Number of CPDMA CPPI descriptors in pool");
67 /* The buf includes headroom compatible with both skb and xdpf */
68 #define CPSW_HEADROOM_NA (max(XDP_PACKET_HEADROOM, NET_SKB_PAD) + NET_IP_ALIGN)
69 #define CPSW_HEADROOM ALIGN(CPSW_HEADROOM_NA, sizeof(long))
71 #define for_each_slave(priv, func, arg...) \
73 struct cpsw_slave *slave; \
74 struct cpsw_common *cpsw = (priv)->cpsw; \
76 if (cpsw->data.dual_emac) \
77 (func)((cpsw)->slaves + priv->emac_port, ##arg);\
79 for (n = cpsw->data.slaves, \
80 slave = cpsw->slaves; \
82 (func)(slave++, ##arg); \
85 #define CPSW_XMETA_OFFSET ALIGN(sizeof(struct xdp_frame), sizeof(long))
87 #define CPSW_XDP_CONSUMED 1
88 #define CPSW_XDP_PASS 0
90 static int cpsw_ndo_vlan_rx_add_vid(struct net_device *ndev,
91 __be16 proto, u16 vid);
93 static void cpsw_set_promiscious(struct net_device *ndev, bool enable)
95 struct cpsw_common *cpsw = ndev_to_cpsw(ndev);
96 struct cpsw_ale *ale = cpsw->ale;
99 if (cpsw->data.dual_emac) {
102 /* Enabling promiscuous mode for one interface will be
103 * common for both the interface as the interface shares
104 * the same hardware resource.
106 for (i = 0; i < cpsw->data.slaves; i++)
107 if (cpsw->slaves[i].ndev->flags & IFF_PROMISC)
110 if (!enable && flag) {
112 dev_err(&ndev->dev, "promiscuity not disabled as the other interface is still in promiscuity mode\n");
117 cpsw_ale_control_set(ale, 0, ALE_BYPASS, 1);
119 dev_dbg(&ndev->dev, "promiscuity enabled\n");
122 cpsw_ale_control_set(ale, 0, ALE_BYPASS, 0);
123 dev_dbg(&ndev->dev, "promiscuity disabled\n");
127 unsigned long timeout = jiffies + HZ;
129 /* Disable Learn for all ports (host is port 0 and slaves are port 1 and up */
130 for (i = 0; i <= cpsw->data.slaves; i++) {
131 cpsw_ale_control_set(ale, i,
132 ALE_PORT_NOLEARN, 1);
133 cpsw_ale_control_set(ale, i,
134 ALE_PORT_NO_SA_UPDATE, 1);
137 /* Clear All Untouched entries */
138 cpsw_ale_control_set(ale, 0, ALE_AGEOUT, 1);
141 if (cpsw_ale_control_get(ale, 0, ALE_AGEOUT))
143 } while (time_after(timeout, jiffies));
144 cpsw_ale_control_set(ale, 0, ALE_AGEOUT, 1);
146 /* Clear all mcast from ALE */
147 cpsw_ale_flush_multicast(ale, ALE_ALL_PORTS, -1);
148 __hw_addr_ref_unsync_dev(&ndev->mc, ndev, NULL);
150 /* Flood All Unicast Packets to Host port */
151 cpsw_ale_control_set(ale, 0, ALE_P0_UNI_FLOOD, 1);
152 dev_dbg(&ndev->dev, "promiscuity enabled\n");
154 /* Don't Flood All Unicast Packets to Host port */
155 cpsw_ale_control_set(ale, 0, ALE_P0_UNI_FLOOD, 0);
157 /* Enable Learn for all ports (host is port 0 and slaves are port 1 and up */
158 for (i = 0; i <= cpsw->data.slaves; i++) {
159 cpsw_ale_control_set(ale, i,
160 ALE_PORT_NOLEARN, 0);
161 cpsw_ale_control_set(ale, i,
162 ALE_PORT_NO_SA_UPDATE, 0);
164 dev_dbg(&ndev->dev, "promiscuity disabled\n");
170 * cpsw_set_mc - adds multicast entry to the table if it's not added or deletes
171 * if it's not deleted
172 * @ndev: device to sync
173 * @addr: address to be added or deleted
174 * @vid: vlan id, if vid < 0 set/unset address for real device
175 * @add: add address if the flag is set or remove otherwise
177 static int cpsw_set_mc(struct net_device *ndev, const u8 *addr,
180 struct cpsw_priv *priv = netdev_priv(ndev);
181 struct cpsw_common *cpsw = priv->cpsw;
182 int mask, flags, ret;
185 if (cpsw->data.dual_emac)
186 vid = cpsw->slaves[priv->emac_port].port_vlan;
191 mask = cpsw->data.dual_emac ? ALE_PORT_HOST : ALE_ALL_PORTS;
192 flags = vid ? ALE_VLAN : 0;
195 ret = cpsw_ale_add_mcast(cpsw->ale, addr, mask, flags, vid, 0);
197 ret = cpsw_ale_del_mcast(cpsw->ale, addr, 0, flags, vid);
202 static int cpsw_update_vlan_mc(struct net_device *vdev, int vid, void *ctx)
204 struct addr_sync_ctx *sync_ctx = ctx;
205 struct netdev_hw_addr *ha;
206 int found = 0, ret = 0;
208 if (!vdev || !(vdev->flags & IFF_UP))
211 /* vlan address is relevant if its sync_cnt != 0 */
212 netdev_for_each_mc_addr(ha, vdev) {
213 if (ether_addr_equal(ha->addr, sync_ctx->addr)) {
214 found = ha->sync_cnt;
220 sync_ctx->consumed++;
222 if (sync_ctx->flush) {
224 cpsw_set_mc(sync_ctx->ndev, sync_ctx->addr, vid, 0);
229 ret = cpsw_set_mc(sync_ctx->ndev, sync_ctx->addr, vid, 1);
234 static int cpsw_add_mc_addr(struct net_device *ndev, const u8 *addr, int num)
236 struct addr_sync_ctx sync_ctx;
239 sync_ctx.consumed = 0;
240 sync_ctx.addr = addr;
241 sync_ctx.ndev = ndev;
244 ret = vlan_for_each(ndev, cpsw_update_vlan_mc, &sync_ctx);
245 if (sync_ctx.consumed < num && !ret)
246 ret = cpsw_set_mc(ndev, addr, -1, 1);
251 static int cpsw_del_mc_addr(struct net_device *ndev, const u8 *addr, int num)
253 struct addr_sync_ctx sync_ctx;
255 sync_ctx.consumed = 0;
256 sync_ctx.addr = addr;
257 sync_ctx.ndev = ndev;
260 vlan_for_each(ndev, cpsw_update_vlan_mc, &sync_ctx);
261 if (sync_ctx.consumed == num)
262 cpsw_set_mc(ndev, addr, -1, 0);
267 static int cpsw_purge_vlan_mc(struct net_device *vdev, int vid, void *ctx)
269 struct addr_sync_ctx *sync_ctx = ctx;
270 struct netdev_hw_addr *ha;
273 if (!vdev || !(vdev->flags & IFF_UP))
276 /* vlan address is relevant if its sync_cnt != 0 */
277 netdev_for_each_mc_addr(ha, vdev) {
278 if (ether_addr_equal(ha->addr, sync_ctx->addr)) {
279 found = ha->sync_cnt;
287 sync_ctx->consumed++;
288 cpsw_set_mc(sync_ctx->ndev, sync_ctx->addr, vid, 0);
292 static int cpsw_purge_all_mc(struct net_device *ndev, const u8 *addr, int num)
294 struct addr_sync_ctx sync_ctx;
296 sync_ctx.addr = addr;
297 sync_ctx.ndev = ndev;
298 sync_ctx.consumed = 0;
300 vlan_for_each(ndev, cpsw_purge_vlan_mc, &sync_ctx);
301 if (sync_ctx.consumed < num)
302 cpsw_set_mc(ndev, addr, -1, 0);
307 static void cpsw_ndo_set_rx_mode(struct net_device *ndev)
309 struct cpsw_priv *priv = netdev_priv(ndev);
310 struct cpsw_common *cpsw = priv->cpsw;
313 if (cpsw->data.dual_emac)
314 slave_port = priv->emac_port + 1;
316 if (ndev->flags & IFF_PROMISC) {
317 /* Enable promiscuous mode */
318 cpsw_set_promiscious(ndev, true);
319 cpsw_ale_set_allmulti(cpsw->ale, IFF_ALLMULTI, slave_port);
322 /* Disable promiscuous mode */
323 cpsw_set_promiscious(ndev, false);
326 /* Restore allmulti on vlans if necessary */
327 cpsw_ale_set_allmulti(cpsw->ale,
328 ndev->flags & IFF_ALLMULTI, slave_port);
330 /* add/remove mcast address either for real netdev or for vlan */
331 __hw_addr_ref_sync_dev(&ndev->mc, ndev, cpsw_add_mc_addr,
335 void cpsw_intr_enable(struct cpsw_common *cpsw)
337 writel_relaxed(0xFF, &cpsw->wr_regs->tx_en);
338 writel_relaxed(0xFF, &cpsw->wr_regs->rx_en);
340 cpdma_ctlr_int_ctrl(cpsw->dma, true);
344 void cpsw_intr_disable(struct cpsw_common *cpsw)
346 writel_relaxed(0, &cpsw->wr_regs->tx_en);
347 writel_relaxed(0, &cpsw->wr_regs->rx_en);
349 cpdma_ctlr_int_ctrl(cpsw->dma, false);
353 static int cpsw_is_xdpf_handle(void *handle)
355 return (unsigned long)handle & BIT(0);
358 static void *cpsw_xdpf_to_handle(struct xdp_frame *xdpf)
360 return (void *)((unsigned long)xdpf | BIT(0));
363 static struct xdp_frame *cpsw_handle_to_xdpf(void *handle)
365 return (struct xdp_frame *)((unsigned long)handle & ~BIT(0));
368 struct __aligned(sizeof(long)) cpsw_meta_xdp {
369 struct net_device *ndev;
373 void cpsw_tx_handler(void *token, int len, int status)
375 struct cpsw_meta_xdp *xmeta;
376 struct xdp_frame *xdpf;
377 struct net_device *ndev;
378 struct netdev_queue *txq;
382 if (cpsw_is_xdpf_handle(token)) {
383 xdpf = cpsw_handle_to_xdpf(token);
384 xmeta = (void *)xdpf + CPSW_XMETA_OFFSET;
387 xdp_return_frame(xdpf);
391 ch = skb_get_queue_mapping(skb);
392 cpts_tx_timestamp(ndev_to_cpsw(ndev)->cpts, skb);
393 dev_kfree_skb_any(skb);
396 /* Check whether the queue is stopped due to stalled tx dma, if the
397 * queue is stopped then start the queue as we have free desc for tx
399 txq = netdev_get_tx_queue(ndev, ch);
400 if (unlikely(netif_tx_queue_stopped(txq)))
401 netif_tx_wake_queue(txq);
403 ndev->stats.tx_packets++;
404 ndev->stats.tx_bytes += len;
407 static void cpsw_rx_vlan_encap(struct sk_buff *skb)
409 struct cpsw_priv *priv = netdev_priv(skb->dev);
410 struct cpsw_common *cpsw = priv->cpsw;
411 u32 rx_vlan_encap_hdr = *((u32 *)skb->data);
412 u16 vtag, vid, prio, pkt_type;
414 /* Remove VLAN header encapsulation word */
415 skb_pull(skb, CPSW_RX_VLAN_ENCAP_HDR_SIZE);
417 pkt_type = (rx_vlan_encap_hdr >>
418 CPSW_RX_VLAN_ENCAP_HDR_PKT_TYPE_SHIFT) &
419 CPSW_RX_VLAN_ENCAP_HDR_PKT_TYPE_MSK;
420 /* Ignore unknown & Priority-tagged packets*/
421 if (pkt_type == CPSW_RX_VLAN_ENCAP_HDR_PKT_RESERV ||
422 pkt_type == CPSW_RX_VLAN_ENCAP_HDR_PKT_PRIO_TAG)
425 vid = (rx_vlan_encap_hdr >>
426 CPSW_RX_VLAN_ENCAP_HDR_VID_SHIFT) &
428 /* Ignore vid 0 and pass packet as is */
431 /* Ignore default vlans in dual mac mode */
432 if (cpsw->data.dual_emac &&
433 vid == cpsw->slaves[priv->emac_port].port_vlan)
436 prio = (rx_vlan_encap_hdr >>
437 CPSW_RX_VLAN_ENCAP_HDR_PRIO_SHIFT) &
438 CPSW_RX_VLAN_ENCAP_HDR_PRIO_MSK;
440 vtag = (prio << VLAN_PRIO_SHIFT) | vid;
441 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vtag);
443 /* strip vlan tag for VLAN-tagged packet */
444 if (pkt_type == CPSW_RX_VLAN_ENCAP_HDR_PKT_VLAN_TAG) {
445 memmove(skb->data + VLAN_HLEN, skb->data, 2 * ETH_ALEN);
446 skb_pull(skb, VLAN_HLEN);
450 static int cpsw_xdp_tx_frame(struct cpsw_priv *priv, struct xdp_frame *xdpf,
453 struct cpsw_common *cpsw = priv->cpsw;
454 struct cpsw_meta_xdp *xmeta;
455 struct cpdma_chan *txch;
459 xmeta = (void *)xdpf + CPSW_XMETA_OFFSET;
460 xmeta->ndev = priv->ndev;
462 txch = cpsw->txv[0].ch;
464 port = priv->emac_port + cpsw->data.dual_emac;
466 dma = page_pool_get_dma_addr(page);
467 dma += xdpf->headroom + sizeof(struct xdp_frame);
468 ret = cpdma_chan_submit_mapped(txch, cpsw_xdpf_to_handle(xdpf),
469 dma, xdpf->len, port);
471 if (sizeof(*xmeta) > xdpf->headroom) {
472 xdp_return_frame_rx_napi(xdpf);
476 ret = cpdma_chan_submit(txch, cpsw_xdpf_to_handle(xdpf),
477 xdpf->data, xdpf->len, port);
481 priv->ndev->stats.tx_dropped++;
482 xdp_return_frame_rx_napi(xdpf);
488 static int cpsw_run_xdp(struct cpsw_priv *priv, int ch, struct xdp_buff *xdp,
491 struct cpsw_common *cpsw = priv->cpsw;
492 struct net_device *ndev = priv->ndev;
493 int ret = CPSW_XDP_CONSUMED;
494 struct xdp_frame *xdpf;
495 struct bpf_prog *prog;
500 prog = READ_ONCE(priv->xdp_prog);
506 act = bpf_prog_run_xdp(prog, xdp);
512 xdpf = convert_to_xdp_frame(xdp);
516 cpsw_xdp_tx_frame(priv, xdpf, page);
519 if (xdp_do_redirect(ndev, xdp, prog))
522 /* Have to flush here, per packet, instead of doing it in bulk
523 * at the end of the napi handler. The RX devices on this
524 * particular hardware is sharing a common queue, so the
525 * incoming device might change per packet.
530 bpf_warn_invalid_xdp_action(act);
533 trace_xdp_exception(ndev, prog, act);
534 /* fall through -- handle aborts by dropping packet */
543 page_pool_recycle_direct(cpsw->page_pool[ch], page);
547 static unsigned int cpsw_rxbuf_total_len(unsigned int len)
549 len += CPSW_HEADROOM;
550 len += SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
552 return SKB_DATA_ALIGN(len);
555 static struct page_pool *cpsw_create_page_pool(struct cpsw_common *cpsw,
558 struct page_pool_params pp_params;
559 struct page_pool *pool;
562 pp_params.flags = PP_FLAG_DMA_MAP;
563 pp_params.pool_size = size;
564 pp_params.nid = NUMA_NO_NODE;
565 pp_params.dma_dir = DMA_BIDIRECTIONAL;
566 pp_params.dev = cpsw->dev;
568 pool = page_pool_create(&pp_params);
570 dev_err(cpsw->dev, "cannot create rx page pool\n");
575 static int cpsw_ndev_create_xdp_rxq(struct cpsw_priv *priv, int ch)
577 struct cpsw_common *cpsw = priv->cpsw;
578 struct xdp_rxq_info *rxq;
579 struct page_pool *pool;
582 pool = cpsw->page_pool[ch];
583 rxq = &priv->xdp_rxq[ch];
585 ret = xdp_rxq_info_reg(rxq, priv->ndev, ch);
589 ret = xdp_rxq_info_reg_mem_model(rxq, MEM_TYPE_PAGE_POOL, pool);
591 xdp_rxq_info_unreg(rxq);
596 static void cpsw_ndev_destroy_xdp_rxq(struct cpsw_priv *priv, int ch)
598 struct xdp_rxq_info *rxq = &priv->xdp_rxq[ch];
600 if (!xdp_rxq_info_is_reg(rxq))
603 xdp_rxq_info_unreg(rxq);
606 static int cpsw_create_rx_pool(struct cpsw_common *cpsw, int ch)
608 struct page_pool *pool;
609 int ret = 0, pool_size;
611 pool_size = cpdma_chan_get_rx_buf_num(cpsw->rxv[ch].ch);
612 pool = cpsw_create_page_pool(cpsw, pool_size);
616 cpsw->page_pool[ch] = pool;
621 void cpsw_destroy_xdp_rxqs(struct cpsw_common *cpsw)
623 struct net_device *ndev;
626 for (ch = 0; ch < cpsw->rx_ch_num; ch++) {
627 for (i = 0; i < cpsw->data.slaves; i++) {
628 ndev = cpsw->slaves[i].ndev;
632 cpsw_ndev_destroy_xdp_rxq(netdev_priv(ndev), ch);
635 page_pool_destroy(cpsw->page_pool[ch]);
636 cpsw->page_pool[ch] = NULL;
640 int cpsw_create_xdp_rxqs(struct cpsw_common *cpsw)
642 struct net_device *ndev;
645 for (ch = 0; ch < cpsw->rx_ch_num; ch++) {
646 ret = cpsw_create_rx_pool(cpsw, ch);
650 /* using same page pool is allowed as no running rx handlers
651 * simultaneously for both ndevs
653 for (i = 0; i < cpsw->data.slaves; i++) {
654 ndev = cpsw->slaves[i].ndev;
658 ret = cpsw_ndev_create_xdp_rxq(netdev_priv(ndev), ch);
667 cpsw_destroy_xdp_rxqs(cpsw);
672 static void cpsw_rx_handler(void *token, int len, int status)
674 struct page *new_page, *page = token;
675 void *pa = page_address(page);
676 struct cpsw_meta_xdp *xmeta = pa + CPSW_XMETA_OFFSET;
677 struct cpsw_common *cpsw = ndev_to_cpsw(xmeta->ndev);
678 int pkt_size = cpsw->rx_packet_max;
679 int ret = 0, port, ch = xmeta->ch;
680 int headroom = CPSW_HEADROOM;
681 struct net_device *ndev = xmeta->ndev;
682 struct cpsw_priv *priv;
683 struct page_pool *pool;
688 if (cpsw->data.dual_emac && status >= 0) {
689 port = CPDMA_RX_SOURCE_PORT(status);
691 ndev = cpsw->slaves[--port].ndev;
694 priv = netdev_priv(ndev);
695 pool = cpsw->page_pool[ch];
696 if (unlikely(status < 0) || unlikely(!netif_running(ndev))) {
697 /* In dual emac mode check for all interfaces */
698 if (cpsw->data.dual_emac && cpsw->usage_count &&
700 /* The packet received is for the interface which
701 * is already down and the other interface is up
702 * and running, instead of freeing which results
703 * in reducing of the number of rx descriptor in
704 * DMA engine, requeue page back to cpdma.
710 /* the interface is going down, pages are purged */
711 page_pool_recycle_direct(pool, page);
715 new_page = page_pool_dev_alloc_pages(pool);
716 if (unlikely(!new_page)) {
718 ndev->stats.rx_dropped++;
722 if (priv->xdp_prog) {
723 if (status & CPDMA_RX_VLAN_ENCAP) {
724 xdp.data = pa + CPSW_HEADROOM +
725 CPSW_RX_VLAN_ENCAP_HDR_SIZE;
726 xdp.data_end = xdp.data + len -
727 CPSW_RX_VLAN_ENCAP_HDR_SIZE;
729 xdp.data = pa + CPSW_HEADROOM;
730 xdp.data_end = xdp.data + len;
733 xdp_set_data_meta_invalid(&xdp);
735 xdp.data_hard_start = pa;
736 xdp.rxq = &priv->xdp_rxq[ch];
738 ret = cpsw_run_xdp(priv, ch, &xdp, page);
739 if (ret != CPSW_XDP_PASS)
742 /* XDP prog might have changed packet data and boundaries */
743 len = xdp.data_end - xdp.data;
744 headroom = xdp.data - xdp.data_hard_start;
746 /* XDP prog can modify vlan tag, so can't use encap header */
747 status &= ~CPDMA_RX_VLAN_ENCAP;
750 /* pass skb to netstack if no XDP prog or returned XDP_PASS */
751 skb = build_skb(pa, cpsw_rxbuf_total_len(pkt_size));
753 ndev->stats.rx_dropped++;
754 page_pool_recycle_direct(pool, page);
758 skb_reserve(skb, headroom);
761 if (status & CPDMA_RX_VLAN_ENCAP)
762 cpsw_rx_vlan_encap(skb);
763 if (priv->rx_ts_enabled)
764 cpts_rx_timestamp(cpsw->cpts, skb);
765 skb->protocol = eth_type_trans(skb, ndev);
767 /* unmap page as no netstack skb page recycling */
768 page_pool_release_page(pool, page);
769 netif_receive_skb(skb);
771 ndev->stats.rx_bytes += len;
772 ndev->stats.rx_packets++;
775 xmeta = page_address(new_page) + CPSW_XMETA_OFFSET;
779 dma = page_pool_get_dma_addr(new_page) + CPSW_HEADROOM;
780 ret = cpdma_chan_submit_mapped(cpsw->rxv[ch].ch, new_page, dma,
783 WARN_ON(ret == -ENOMEM);
784 page_pool_recycle_direct(pool, new_page);
788 void cpsw_split_res(struct cpsw_common *cpsw)
790 u32 consumed_rate = 0, bigest_rate = 0;
791 struct cpsw_vector *txv = cpsw->txv;
792 int i, ch_weight, rlim_ch_num = 0;
793 int budget, bigest_rate_ch = 0;
794 u32 ch_rate, max_rate;
797 for (i = 0; i < cpsw->tx_ch_num; i++) {
798 ch_rate = cpdma_chan_get_rate(txv[i].ch);
803 consumed_rate += ch_rate;
806 if (cpsw->tx_ch_num == rlim_ch_num) {
807 max_rate = consumed_rate;
808 } else if (!rlim_ch_num) {
809 ch_budget = CPSW_POLL_WEIGHT / cpsw->tx_ch_num;
811 max_rate = consumed_rate;
813 max_rate = cpsw->speed * 1000;
815 /* if max_rate is less then expected due to reduced link speed,
816 * split proportionally according next potential max speed
818 if (max_rate < consumed_rate)
821 if (max_rate < consumed_rate)
824 ch_budget = (consumed_rate * CPSW_POLL_WEIGHT) / max_rate;
825 ch_budget = (CPSW_POLL_WEIGHT - ch_budget) /
826 (cpsw->tx_ch_num - rlim_ch_num);
827 bigest_rate = (max_rate - consumed_rate) /
828 (cpsw->tx_ch_num - rlim_ch_num);
831 /* split tx weight/budget */
832 budget = CPSW_POLL_WEIGHT;
833 for (i = 0; i < cpsw->tx_ch_num; i++) {
834 ch_rate = cpdma_chan_get_rate(txv[i].ch);
836 txv[i].budget = (ch_rate * CPSW_POLL_WEIGHT) / max_rate;
839 if (ch_rate > bigest_rate) {
841 bigest_rate = ch_rate;
844 ch_weight = (ch_rate * 100) / max_rate;
847 cpdma_chan_set_weight(cpsw->txv[i].ch, ch_weight);
849 txv[i].budget = ch_budget;
852 cpdma_chan_set_weight(cpsw->txv[i].ch, 0);
855 budget -= txv[i].budget;
859 txv[bigest_rate_ch].budget += budget;
861 /* split rx budget */
862 budget = CPSW_POLL_WEIGHT;
863 ch_budget = budget / cpsw->rx_ch_num;
864 for (i = 0; i < cpsw->rx_ch_num; i++) {
865 cpsw->rxv[i].budget = ch_budget;
870 cpsw->rxv[0].budget += budget;
873 static irqreturn_t cpsw_tx_interrupt(int irq, void *dev_id)
875 struct cpsw_common *cpsw = dev_id;
877 writel(0, &cpsw->wr_regs->tx_en);
878 cpdma_ctlr_eoi(cpsw->dma, CPDMA_EOI_TX);
880 if (cpsw->quirk_irq) {
881 disable_irq_nosync(cpsw->irqs_table[1]);
882 cpsw->tx_irq_disabled = true;
885 napi_schedule(&cpsw->napi_tx);
889 static irqreturn_t cpsw_rx_interrupt(int irq, void *dev_id)
891 struct cpsw_common *cpsw = dev_id;
893 cpdma_ctlr_eoi(cpsw->dma, CPDMA_EOI_RX);
894 writel(0, &cpsw->wr_regs->rx_en);
896 if (cpsw->quirk_irq) {
897 disable_irq_nosync(cpsw->irqs_table[0]);
898 cpsw->rx_irq_disabled = true;
901 napi_schedule(&cpsw->napi_rx);
905 static int cpsw_tx_mq_poll(struct napi_struct *napi_tx, int budget)
908 int num_tx, cur_budget, ch;
909 struct cpsw_common *cpsw = napi_to_cpsw(napi_tx);
910 struct cpsw_vector *txv;
912 /* process every unprocessed channel */
913 ch_map = cpdma_ctrl_txchs_state(cpsw->dma);
914 for (ch = 0, num_tx = 0; ch_map & 0xff; ch_map <<= 1, ch++) {
915 if (!(ch_map & 0x80))
918 txv = &cpsw->txv[ch];
919 if (unlikely(txv->budget > budget - num_tx))
920 cur_budget = budget - num_tx;
922 cur_budget = txv->budget;
924 num_tx += cpdma_chan_process(txv->ch, cur_budget);
925 if (num_tx >= budget)
929 if (num_tx < budget) {
930 napi_complete(napi_tx);
931 writel(0xff, &cpsw->wr_regs->tx_en);
937 static int cpsw_tx_poll(struct napi_struct *napi_tx, int budget)
939 struct cpsw_common *cpsw = napi_to_cpsw(napi_tx);
942 num_tx = cpdma_chan_process(cpsw->txv[0].ch, budget);
943 if (num_tx < budget) {
944 napi_complete(napi_tx);
945 writel(0xff, &cpsw->wr_regs->tx_en);
946 if (cpsw->tx_irq_disabled) {
947 cpsw->tx_irq_disabled = false;
948 enable_irq(cpsw->irqs_table[1]);
955 static int cpsw_rx_mq_poll(struct napi_struct *napi_rx, int budget)
958 int num_rx, cur_budget, ch;
959 struct cpsw_common *cpsw = napi_to_cpsw(napi_rx);
960 struct cpsw_vector *rxv;
962 /* process every unprocessed channel */
963 ch_map = cpdma_ctrl_rxchs_state(cpsw->dma);
964 for (ch = 0, num_rx = 0; ch_map; ch_map >>= 1, ch++) {
965 if (!(ch_map & 0x01))
968 rxv = &cpsw->rxv[ch];
969 if (unlikely(rxv->budget > budget - num_rx))
970 cur_budget = budget - num_rx;
972 cur_budget = rxv->budget;
974 num_rx += cpdma_chan_process(rxv->ch, cur_budget);
975 if (num_rx >= budget)
979 if (num_rx < budget) {
980 napi_complete_done(napi_rx, num_rx);
981 writel(0xff, &cpsw->wr_regs->rx_en);
987 static int cpsw_rx_poll(struct napi_struct *napi_rx, int budget)
989 struct cpsw_common *cpsw = napi_to_cpsw(napi_rx);
992 num_rx = cpdma_chan_process(cpsw->rxv[0].ch, budget);
993 if (num_rx < budget) {
994 napi_complete_done(napi_rx, num_rx);
995 writel(0xff, &cpsw->wr_regs->rx_en);
996 if (cpsw->rx_irq_disabled) {
997 cpsw->rx_irq_disabled = false;
998 enable_irq(cpsw->irqs_table[0]);
1005 static inline void soft_reset(const char *module, void __iomem *reg)
1007 unsigned long timeout = jiffies + HZ;
1009 writel_relaxed(1, reg);
1012 } while ((readl_relaxed(reg) & 1) && time_after(timeout, jiffies));
1014 WARN(readl_relaxed(reg) & 1, "failed to soft-reset %s\n", module);
1017 static void cpsw_set_slave_mac(struct cpsw_slave *slave,
1018 struct cpsw_priv *priv)
1020 slave_write(slave, mac_hi(priv->mac_addr), SA_HI);
1021 slave_write(slave, mac_lo(priv->mac_addr), SA_LO);
1024 static bool cpsw_shp_is_off(struct cpsw_priv *priv)
1026 struct cpsw_common *cpsw = priv->cpsw;
1027 struct cpsw_slave *slave;
1028 u32 shift, mask, val;
1030 val = readl_relaxed(&cpsw->regs->ptype);
1032 slave = &cpsw->slaves[cpsw_slave_index(cpsw, priv)];
1033 shift = CPSW_FIFO_SHAPE_EN_SHIFT + 3 * slave->slave_num;
1040 static void cpsw_fifo_shp_on(struct cpsw_priv *priv, int fifo, int on)
1042 struct cpsw_common *cpsw = priv->cpsw;
1043 struct cpsw_slave *slave;
1044 u32 shift, mask, val;
1046 val = readl_relaxed(&cpsw->regs->ptype);
1048 slave = &cpsw->slaves[cpsw_slave_index(cpsw, priv)];
1049 shift = CPSW_FIFO_SHAPE_EN_SHIFT + 3 * slave->slave_num;
1050 mask = (1 << --fifo) << shift;
1051 val = on ? val | mask : val & ~mask;
1053 writel_relaxed(val, &cpsw->regs->ptype);
1056 static void _cpsw_adjust_link(struct cpsw_slave *slave,
1057 struct cpsw_priv *priv, bool *link)
1059 struct phy_device *phy = slave->phy;
1060 u32 mac_control = 0;
1062 struct cpsw_common *cpsw = priv->cpsw;
1067 slave_port = cpsw_get_slave_port(slave->slave_num);
1070 mac_control = CPSW_SL_CTL_GMII_EN;
1072 if (phy->speed == 1000)
1073 mac_control |= CPSW_SL_CTL_GIG;
1075 mac_control |= CPSW_SL_CTL_FULLDUPLEX;
1077 /* set speed_in input in case RMII mode is used in 100Mbps */
1078 if (phy->speed == 100)
1079 mac_control |= CPSW_SL_CTL_IFCTL_A;
1080 /* in band mode only works in 10Mbps RGMII mode */
1081 else if ((phy->speed == 10) && phy_interface_is_rgmii(phy))
1082 mac_control |= CPSW_SL_CTL_EXT_EN; /* In Band mode */
1085 mac_control |= CPSW_SL_CTL_RX_FLOW_EN;
1088 mac_control |= CPSW_SL_CTL_TX_FLOW_EN;
1090 if (mac_control != slave->mac_control)
1091 cpsw_sl_ctl_set(slave->mac_sl, mac_control);
1093 /* enable forwarding */
1094 cpsw_ale_control_set(cpsw->ale, slave_port,
1095 ALE_PORT_STATE, ALE_PORT_STATE_FORWARD);
1099 if (priv->shp_cfg_speed &&
1100 priv->shp_cfg_speed != slave->phy->speed &&
1101 !cpsw_shp_is_off(priv))
1103 "Speed was changed, CBS shaper speeds are changed!");
1106 /* disable forwarding */
1107 cpsw_ale_control_set(cpsw->ale, slave_port,
1108 ALE_PORT_STATE, ALE_PORT_STATE_DISABLE);
1110 cpsw_sl_wait_for_idle(slave->mac_sl, 100);
1112 cpsw_sl_ctl_reset(slave->mac_sl);
1115 if (mac_control != slave->mac_control)
1116 phy_print_status(phy);
1118 slave->mac_control = mac_control;
1121 static int cpsw_get_common_speed(struct cpsw_common *cpsw)
1125 for (i = 0, speed = 0; i < cpsw->data.slaves; i++)
1126 if (cpsw->slaves[i].phy && cpsw->slaves[i].phy->link)
1127 speed += cpsw->slaves[i].phy->speed;
1132 static int cpsw_need_resplit(struct cpsw_common *cpsw)
1137 /* re-split resources only in case speed was changed */
1138 speed = cpsw_get_common_speed(cpsw);
1139 if (speed == cpsw->speed || !speed)
1142 cpsw->speed = speed;
1144 for (i = 0, rlim_ch_num = 0; i < cpsw->tx_ch_num; i++) {
1145 ch_rate = cpdma_chan_get_rate(cpsw->txv[i].ch);
1152 /* cases not dependent on speed */
1153 if (!rlim_ch_num || rlim_ch_num == cpsw->tx_ch_num)
1159 static void cpsw_adjust_link(struct net_device *ndev)
1161 struct cpsw_priv *priv = netdev_priv(ndev);
1162 struct cpsw_common *cpsw = priv->cpsw;
1165 for_each_slave(priv, _cpsw_adjust_link, priv, &link);
1168 if (cpsw_need_resplit(cpsw))
1169 cpsw_split_res(cpsw);
1171 netif_carrier_on(ndev);
1172 if (netif_running(ndev))
1173 netif_tx_wake_all_queues(ndev);
1175 netif_carrier_off(ndev);
1176 netif_tx_stop_all_queues(ndev);
1180 static inline void cpsw_add_dual_emac_def_ale_entries(
1181 struct cpsw_priv *priv, struct cpsw_slave *slave,
1184 struct cpsw_common *cpsw = priv->cpsw;
1185 u32 port_mask = 1 << slave_port | ALE_PORT_HOST;
1187 if (cpsw->version == CPSW_VERSION_1)
1188 slave_write(slave, slave->port_vlan, CPSW1_PORT_VLAN);
1190 slave_write(slave, slave->port_vlan, CPSW2_PORT_VLAN);
1191 cpsw_ale_add_vlan(cpsw->ale, slave->port_vlan, port_mask,
1192 port_mask, port_mask, 0);
1193 cpsw_ale_add_mcast(cpsw->ale, priv->ndev->broadcast,
1194 ALE_PORT_HOST, ALE_VLAN, slave->port_vlan, 0);
1195 cpsw_ale_add_ucast(cpsw->ale, priv->mac_addr,
1196 HOST_PORT_NUM, ALE_VLAN |
1197 ALE_SECURE, slave->port_vlan);
1198 cpsw_ale_control_set(cpsw->ale, slave_port,
1199 ALE_PORT_DROP_UNKNOWN_VLAN, 1);
1202 static void cpsw_slave_open(struct cpsw_slave *slave, struct cpsw_priv *priv)
1205 struct phy_device *phy;
1206 struct cpsw_common *cpsw = priv->cpsw;
1208 cpsw_sl_reset(slave->mac_sl, 100);
1209 cpsw_sl_ctl_reset(slave->mac_sl);
1211 /* setup priority mapping */
1212 cpsw_sl_reg_write(slave->mac_sl, CPSW_SL_RX_PRI_MAP,
1213 RX_PRIORITY_MAPPING);
1215 switch (cpsw->version) {
1216 case CPSW_VERSION_1:
1217 slave_write(slave, TX_PRIORITY_MAPPING, CPSW1_TX_PRI_MAP);
1218 /* Increase RX FIFO size to 5 for supporting fullduplex
1222 (CPSW_MAX_BLKS_TX << CPSW_MAX_BLKS_TX_SHIFT) |
1223 CPSW_MAX_BLKS_RX, CPSW1_MAX_BLKS);
1225 case CPSW_VERSION_2:
1226 case CPSW_VERSION_3:
1227 case CPSW_VERSION_4:
1228 slave_write(slave, TX_PRIORITY_MAPPING, CPSW2_TX_PRI_MAP);
1229 /* Increase RX FIFO size to 5 for supporting fullduplex
1233 (CPSW_MAX_BLKS_TX << CPSW_MAX_BLKS_TX_SHIFT) |
1234 CPSW_MAX_BLKS_RX, CPSW2_MAX_BLKS);
1238 /* setup max packet size, and mac address */
1239 cpsw_sl_reg_write(slave->mac_sl, CPSW_SL_RX_MAXLEN,
1240 cpsw->rx_packet_max);
1241 cpsw_set_slave_mac(slave, priv);
1243 slave->mac_control = 0; /* no link yet */
1245 slave_port = cpsw_get_slave_port(slave->slave_num);
1247 if (cpsw->data.dual_emac)
1248 cpsw_add_dual_emac_def_ale_entries(priv, slave, slave_port);
1250 cpsw_ale_add_mcast(cpsw->ale, priv->ndev->broadcast,
1251 1 << slave_port, 0, 0, ALE_MCAST_FWD_2);
1253 if (slave->data->phy_node) {
1254 phy = of_phy_connect(priv->ndev, slave->data->phy_node,
1255 &cpsw_adjust_link, 0, slave->data->phy_if);
1257 dev_err(priv->dev, "phy \"%pOF\" not found on slave %d\n",
1258 slave->data->phy_node,
1263 phy = phy_connect(priv->ndev, slave->data->phy_id,
1264 &cpsw_adjust_link, slave->data->phy_if);
1267 "phy \"%s\" not found on slave %d, err %ld\n",
1268 slave->data->phy_id, slave->slave_num,
1276 phy_attached_info(slave->phy);
1278 phy_start(slave->phy);
1280 /* Configure GMII_SEL register */
1281 if (!IS_ERR(slave->data->ifphy))
1282 phy_set_mode_ext(slave->data->ifphy, PHY_MODE_ETHERNET,
1283 slave->data->phy_if);
1285 cpsw_phy_sel(cpsw->dev, slave->phy->interface,
1289 static inline void cpsw_add_default_vlan(struct cpsw_priv *priv)
1291 struct cpsw_common *cpsw = priv->cpsw;
1292 const int vlan = cpsw->data.default_vlan;
1295 int unreg_mcast_mask;
1297 reg = (cpsw->version == CPSW_VERSION_1) ? CPSW1_PORT_VLAN :
1300 writel(vlan, &cpsw->host_port_regs->port_vlan);
1302 for (i = 0; i < cpsw->data.slaves; i++)
1303 slave_write(cpsw->slaves + i, vlan, reg);
1305 if (priv->ndev->flags & IFF_ALLMULTI)
1306 unreg_mcast_mask = ALE_ALL_PORTS;
1308 unreg_mcast_mask = ALE_PORT_1 | ALE_PORT_2;
1310 cpsw_ale_add_vlan(cpsw->ale, vlan, ALE_ALL_PORTS,
1311 ALE_ALL_PORTS, ALE_ALL_PORTS,
1315 static void cpsw_init_host_port(struct cpsw_priv *priv)
1319 struct cpsw_common *cpsw = priv->cpsw;
1321 /* soft reset the controller and initialize ale */
1322 soft_reset("cpsw", &cpsw->regs->soft_reset);
1323 cpsw_ale_start(cpsw->ale);
1325 /* switch to vlan unaware mode */
1326 cpsw_ale_control_set(cpsw->ale, HOST_PORT_NUM, ALE_VLAN_AWARE,
1327 CPSW_ALE_VLAN_AWARE);
1328 control_reg = readl(&cpsw->regs->control);
1329 control_reg |= CPSW_VLAN_AWARE | CPSW_RX_VLAN_ENCAP;
1330 writel(control_reg, &cpsw->regs->control);
1331 fifo_mode = (cpsw->data.dual_emac) ? CPSW_FIFO_DUAL_MAC_MODE :
1332 CPSW_FIFO_NORMAL_MODE;
1333 writel(fifo_mode, &cpsw->host_port_regs->tx_in_ctl);
1335 /* setup host port priority mapping */
1336 writel_relaxed(CPDMA_TX_PRIORITY_MAP,
1337 &cpsw->host_port_regs->cpdma_tx_pri_map);
1338 writel_relaxed(0, &cpsw->host_port_regs->cpdma_rx_chan_map);
1340 cpsw_ale_control_set(cpsw->ale, HOST_PORT_NUM,
1341 ALE_PORT_STATE, ALE_PORT_STATE_FORWARD);
1343 if (!cpsw->data.dual_emac) {
1344 cpsw_ale_add_ucast(cpsw->ale, priv->mac_addr, HOST_PORT_NUM,
1346 cpsw_ale_add_mcast(cpsw->ale, priv->ndev->broadcast,
1347 ALE_PORT_HOST, 0, 0, ALE_MCAST_FWD_2);
1351 int cpsw_fill_rx_channels(struct cpsw_priv *priv)
1353 struct cpsw_common *cpsw = priv->cpsw;
1354 struct cpsw_meta_xdp *xmeta;
1355 struct page_pool *pool;
1361 for (ch = 0; ch < cpsw->rx_ch_num; ch++) {
1362 pool = cpsw->page_pool[ch];
1363 ch_buf_num = cpdma_chan_get_rx_buf_num(cpsw->rxv[ch].ch);
1364 for (i = 0; i < ch_buf_num; i++) {
1365 page = page_pool_dev_alloc_pages(pool);
1367 cpsw_err(priv, ifup, "allocate rx page err\n");
1371 xmeta = page_address(page) + CPSW_XMETA_OFFSET;
1372 xmeta->ndev = priv->ndev;
1375 dma = page_pool_get_dma_addr(page) + CPSW_HEADROOM;
1376 ret = cpdma_chan_idle_submit_mapped(cpsw->rxv[ch].ch,
1378 cpsw->rx_packet_max,
1381 cpsw_err(priv, ifup,
1382 "cannot submit page to channel %d rx, error %d\n",
1384 page_pool_recycle_direct(pool, page);
1389 cpsw_info(priv, ifup, "ch %d rx, submitted %d descriptors\n",
1396 static void cpsw_slave_stop(struct cpsw_slave *slave, struct cpsw_common *cpsw)
1400 slave_port = cpsw_get_slave_port(slave->slave_num);
1404 phy_stop(slave->phy);
1405 phy_disconnect(slave->phy);
1407 cpsw_ale_control_set(cpsw->ale, slave_port,
1408 ALE_PORT_STATE, ALE_PORT_STATE_DISABLE);
1409 cpsw_sl_reset(slave->mac_sl, 100);
1410 cpsw_sl_ctl_reset(slave->mac_sl);
1413 static int cpsw_tc_to_fifo(int tc, int num_tc)
1415 if (tc == num_tc - 1)
1418 return CPSW_FIFO_SHAPERS_NUM - tc;
1421 static int cpsw_set_fifo_bw(struct cpsw_priv *priv, int fifo, int bw)
1423 struct cpsw_common *cpsw = priv->cpsw;
1424 u32 val = 0, send_pct, shift;
1425 struct cpsw_slave *slave;
1428 if (bw > priv->shp_cfg_speed * 1000)
1431 /* shaping has to stay enabled for highest fifos linearly
1432 * and fifo bw no more then interface can allow
1434 slave = &cpsw->slaves[cpsw_slave_index(cpsw, priv)];
1435 send_pct = slave_read(slave, SEND_PERCENT);
1436 for (i = CPSW_FIFO_SHAPERS_NUM; i > 0; i--) {
1438 if (i >= fifo || !priv->fifo_bw[i])
1441 dev_warn(priv->dev, "Prev FIFO%d is shaped", i);
1445 if (!priv->fifo_bw[i] && i > fifo) {
1446 dev_err(priv->dev, "Upper FIFO%d is not shaped", i);
1450 shift = (i - 1) * 8;
1452 send_pct &= ~(CPSW_PCT_MASK << shift);
1453 val = DIV_ROUND_UP(bw, priv->shp_cfg_speed * 10);
1457 send_pct |= val << shift;
1462 if (priv->fifo_bw[i])
1463 pct += (send_pct >> shift) & CPSW_PCT_MASK;
1469 slave_write(slave, send_pct, SEND_PERCENT);
1470 priv->fifo_bw[fifo] = bw;
1472 dev_warn(priv->dev, "set FIFO%d bw = %d\n", fifo,
1473 DIV_ROUND_CLOSEST(val * priv->shp_cfg_speed, 100));
1477 dev_err(priv->dev, "Bandwidth doesn't fit in tc configuration");
1481 static int cpsw_set_fifo_rlimit(struct cpsw_priv *priv, int fifo, int bw)
1483 struct cpsw_common *cpsw = priv->cpsw;
1484 struct cpsw_slave *slave;
1485 u32 tx_in_ctl_rg, val;
1488 ret = cpsw_set_fifo_bw(priv, fifo, bw);
1492 slave = &cpsw->slaves[cpsw_slave_index(cpsw, priv)];
1493 tx_in_ctl_rg = cpsw->version == CPSW_VERSION_1 ?
1494 CPSW1_TX_IN_CTL : CPSW2_TX_IN_CTL;
1497 cpsw_fifo_shp_on(priv, fifo, bw);
1499 val = slave_read(slave, tx_in_ctl_rg);
1500 if (cpsw_shp_is_off(priv)) {
1501 /* disable FIFOs rate limited queues */
1502 val &= ~(0xf << CPSW_FIFO_RATE_EN_SHIFT);
1504 /* set type of FIFO queues to normal priority mode */
1505 val &= ~(3 << CPSW_FIFO_QUEUE_TYPE_SHIFT);
1507 /* set type of FIFO queues to be rate limited */
1509 val |= 2 << CPSW_FIFO_QUEUE_TYPE_SHIFT;
1511 priv->shp_cfg_speed = 0;
1514 /* toggle a FIFO rate limited queue */
1516 val |= BIT(fifo + CPSW_FIFO_RATE_EN_SHIFT);
1518 val &= ~BIT(fifo + CPSW_FIFO_RATE_EN_SHIFT);
1519 slave_write(slave, val, tx_in_ctl_rg);
1521 /* FIFO transmit shape enable */
1522 cpsw_fifo_shp_on(priv, fifo, bw);
1529 * shaping for class A should be set first
1531 static int cpsw_set_cbs(struct net_device *ndev,
1532 struct tc_cbs_qopt_offload *qopt)
1534 struct cpsw_priv *priv = netdev_priv(ndev);
1535 struct cpsw_common *cpsw = priv->cpsw;
1536 struct cpsw_slave *slave;
1541 tc = netdev_txq_to_tc(priv->ndev, qopt->queue);
1543 /* enable channels in backward order, as highest FIFOs must be rate
1544 * limited first and for compliance with CPDMA rate limited channels
1545 * that also used in bacward order. FIFO0 cannot be rate limited.
1547 fifo = cpsw_tc_to_fifo(tc, ndev->num_tc);
1549 dev_err(priv->dev, "Last tc%d can't be rate limited", tc);
1553 /* do nothing, it's disabled anyway */
1554 if (!qopt->enable && !priv->fifo_bw[fifo])
1557 /* shapers can be set if link speed is known */
1558 slave = &cpsw->slaves[cpsw_slave_index(cpsw, priv)];
1559 if (slave->phy && slave->phy->link) {
1560 if (priv->shp_cfg_speed &&
1561 priv->shp_cfg_speed != slave->phy->speed)
1562 prev_speed = priv->shp_cfg_speed;
1564 priv->shp_cfg_speed = slave->phy->speed;
1567 if (!priv->shp_cfg_speed) {
1568 dev_err(priv->dev, "Link speed is not known");
1572 ret = pm_runtime_get_sync(cpsw->dev);
1574 pm_runtime_put_noidle(cpsw->dev);
1578 bw = qopt->enable ? qopt->idleslope : 0;
1579 ret = cpsw_set_fifo_rlimit(priv, fifo, bw);
1581 priv->shp_cfg_speed = prev_speed;
1585 if (bw && prev_speed)
1587 "Speed was changed, CBS shaper speeds are changed!");
1589 pm_runtime_put_sync(cpsw->dev);
1593 static void cpsw_cbs_resume(struct cpsw_slave *slave, struct cpsw_priv *priv)
1597 for (fifo = CPSW_FIFO_SHAPERS_NUM; fifo > 0; fifo--) {
1598 bw = priv->fifo_bw[fifo];
1602 cpsw_set_fifo_rlimit(priv, fifo, bw);
1606 static void cpsw_mqprio_resume(struct cpsw_slave *slave, struct cpsw_priv *priv)
1608 struct cpsw_common *cpsw = priv->cpsw;
1609 u32 tx_prio_map = 0;
1613 if (!priv->mqprio_hw)
1616 for (i = 0; i < 8; i++) {
1617 tc = netdev_get_prio_tc_map(priv->ndev, i);
1618 fifo = CPSW_FIFO_SHAPERS_NUM - tc;
1619 tx_prio_map |= fifo << (4 * i);
1622 tx_prio_rg = cpsw->version == CPSW_VERSION_1 ?
1623 CPSW1_TX_PRI_MAP : CPSW2_TX_PRI_MAP;
1625 slave_write(slave, tx_prio_map, tx_prio_rg);
1628 static int cpsw_restore_vlans(struct net_device *vdev, int vid, void *arg)
1630 struct cpsw_priv *priv = arg;
1635 cpsw_ndo_vlan_rx_add_vid(priv->ndev, 0, vid);
1639 /* restore resources after port reset */
1640 static void cpsw_restore(struct cpsw_priv *priv)
1642 /* restore vlan configurations */
1643 vlan_for_each(priv->ndev, cpsw_restore_vlans, priv);
1645 /* restore MQPRIO offload */
1646 for_each_slave(priv, cpsw_mqprio_resume, priv);
1648 /* restore CBS offload */
1649 for_each_slave(priv, cpsw_cbs_resume, priv);
1652 static int cpsw_ndo_open(struct net_device *ndev)
1654 struct cpsw_priv *priv = netdev_priv(ndev);
1655 struct cpsw_common *cpsw = priv->cpsw;
1659 ret = pm_runtime_get_sync(cpsw->dev);
1661 pm_runtime_put_noidle(cpsw->dev);
1665 netif_carrier_off(ndev);
1667 /* Notify the stack of the actual queue counts. */
1668 ret = netif_set_real_num_tx_queues(ndev, cpsw->tx_ch_num);
1670 dev_err(priv->dev, "cannot set real number of tx queues\n");
1674 ret = netif_set_real_num_rx_queues(ndev, cpsw->rx_ch_num);
1676 dev_err(priv->dev, "cannot set real number of rx queues\n");
1680 reg = cpsw->version;
1682 dev_info(priv->dev, "initializing cpsw version %d.%d (%d)\n",
1683 CPSW_MAJOR_VERSION(reg), CPSW_MINOR_VERSION(reg),
1684 CPSW_RTL_VERSION(reg));
1686 /* Initialize host and slave ports */
1687 if (!cpsw->usage_count)
1688 cpsw_init_host_port(priv);
1689 for_each_slave(priv, cpsw_slave_open, priv);
1691 /* Add default VLAN */
1692 if (!cpsw->data.dual_emac)
1693 cpsw_add_default_vlan(priv);
1695 cpsw_ale_add_vlan(cpsw->ale, cpsw->data.default_vlan,
1696 ALE_ALL_PORTS, ALE_ALL_PORTS, 0, 0);
1698 /* initialize shared resources for every ndev */
1699 if (!cpsw->usage_count) {
1700 /* disable priority elevation */
1701 writel_relaxed(0, &cpsw->regs->ptype);
1703 /* enable statistics collection only on all ports */
1704 writel_relaxed(0x7, &cpsw->regs->stat_port_en);
1706 /* Enable internal fifo flow control */
1707 writel(0x7, &cpsw->regs->flow_control);
1709 napi_enable(&cpsw->napi_rx);
1710 napi_enable(&cpsw->napi_tx);
1712 if (cpsw->tx_irq_disabled) {
1713 cpsw->tx_irq_disabled = false;
1714 enable_irq(cpsw->irqs_table[1]);
1717 if (cpsw->rx_irq_disabled) {
1718 cpsw->rx_irq_disabled = false;
1719 enable_irq(cpsw->irqs_table[0]);
1722 /* create rxqs for both infs in dual mac as they use same pool
1723 * and must be destroyed together when no users.
1725 ret = cpsw_create_xdp_rxqs(cpsw);
1729 ret = cpsw_fill_rx_channels(priv);
1733 if (cpts_register(cpsw->cpts))
1734 dev_err(priv->dev, "error registering cpts device\n");
1740 /* Enable Interrupt pacing if configured */
1741 if (cpsw->coal_intvl != 0) {
1742 struct ethtool_coalesce coal;
1744 coal.rx_coalesce_usecs = cpsw->coal_intvl;
1745 cpsw_set_coalesce(ndev, &coal);
1748 cpdma_ctlr_start(cpsw->dma);
1749 cpsw_intr_enable(cpsw);
1750 cpsw->usage_count++;
1755 if (!cpsw->usage_count) {
1756 cpdma_ctlr_stop(cpsw->dma);
1757 cpsw_destroy_xdp_rxqs(cpsw);
1760 for_each_slave(priv, cpsw_slave_stop, cpsw);
1761 pm_runtime_put_sync(cpsw->dev);
1762 netif_carrier_off(priv->ndev);
1766 static int cpsw_ndo_stop(struct net_device *ndev)
1768 struct cpsw_priv *priv = netdev_priv(ndev);
1769 struct cpsw_common *cpsw = priv->cpsw;
1771 cpsw_info(priv, ifdown, "shutting down cpsw device\n");
1772 __hw_addr_ref_unsync_dev(&ndev->mc, ndev, cpsw_purge_all_mc);
1773 netif_tx_stop_all_queues(priv->ndev);
1774 netif_carrier_off(priv->ndev);
1776 if (cpsw->usage_count <= 1) {
1777 napi_disable(&cpsw->napi_rx);
1778 napi_disable(&cpsw->napi_tx);
1779 cpts_unregister(cpsw->cpts);
1780 cpsw_intr_disable(cpsw);
1781 cpdma_ctlr_stop(cpsw->dma);
1782 cpsw_ale_stop(cpsw->ale);
1783 cpsw_destroy_xdp_rxqs(cpsw);
1785 for_each_slave(priv, cpsw_slave_stop, cpsw);
1787 if (cpsw_need_resplit(cpsw))
1788 cpsw_split_res(cpsw);
1790 cpsw->usage_count--;
1791 pm_runtime_put_sync(cpsw->dev);
1795 static netdev_tx_t cpsw_ndo_start_xmit(struct sk_buff *skb,
1796 struct net_device *ndev)
1798 struct cpsw_priv *priv = netdev_priv(ndev);
1799 struct cpsw_common *cpsw = priv->cpsw;
1800 struct cpts *cpts = cpsw->cpts;
1801 struct netdev_queue *txq;
1802 struct cpdma_chan *txch;
1805 if (skb_padto(skb, CPSW_MIN_PACKET_SIZE)) {
1806 cpsw_err(priv, tx_err, "packet pad failed\n");
1807 ndev->stats.tx_dropped++;
1808 return NET_XMIT_DROP;
1811 if (skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP &&
1812 priv->tx_ts_enabled && cpts_can_timestamp(cpts, skb))
1813 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
1815 q_idx = skb_get_queue_mapping(skb);
1816 if (q_idx >= cpsw->tx_ch_num)
1817 q_idx = q_idx % cpsw->tx_ch_num;
1819 txch = cpsw->txv[q_idx].ch;
1820 txq = netdev_get_tx_queue(ndev, q_idx);
1821 skb_tx_timestamp(skb);
1822 ret = cpdma_chan_submit(txch, skb, skb->data, skb->len,
1823 priv->emac_port + cpsw->data.dual_emac);
1824 if (unlikely(ret != 0)) {
1825 cpsw_err(priv, tx_err, "desc submit failed\n");
1829 /* If there is no more tx desc left free then we need to
1830 * tell the kernel to stop sending us tx frames.
1832 if (unlikely(!cpdma_check_free_tx_desc(txch))) {
1833 netif_tx_stop_queue(txq);
1835 /* Barrier, so that stop_queue visible to other cpus */
1836 smp_mb__after_atomic();
1838 if (cpdma_check_free_tx_desc(txch))
1839 netif_tx_wake_queue(txq);
1842 return NETDEV_TX_OK;
1844 ndev->stats.tx_dropped++;
1845 netif_tx_stop_queue(txq);
1847 /* Barrier, so that stop_queue visible to other cpus */
1848 smp_mb__after_atomic();
1850 if (cpdma_check_free_tx_desc(txch))
1851 netif_tx_wake_queue(txq);
1853 return NETDEV_TX_BUSY;
1856 #if IS_ENABLED(CONFIG_TI_CPTS)
1858 static void cpsw_hwtstamp_v1(struct cpsw_priv *priv)
1860 struct cpsw_common *cpsw = priv->cpsw;
1861 struct cpsw_slave *slave = &cpsw->slaves[cpsw->data.active_slave];
1864 if (!priv->tx_ts_enabled && !priv->rx_ts_enabled) {
1865 slave_write(slave, 0, CPSW1_TS_CTL);
1869 seq_id = (30 << CPSW_V1_SEQ_ID_OFS_SHIFT) | ETH_P_1588;
1870 ts_en = EVENT_MSG_BITS << CPSW_V1_MSG_TYPE_OFS;
1872 if (priv->tx_ts_enabled)
1873 ts_en |= CPSW_V1_TS_TX_EN;
1875 if (priv->rx_ts_enabled)
1876 ts_en |= CPSW_V1_TS_RX_EN;
1878 slave_write(slave, ts_en, CPSW1_TS_CTL);
1879 slave_write(slave, seq_id, CPSW1_TS_SEQ_LTYPE);
1882 static void cpsw_hwtstamp_v2(struct cpsw_priv *priv)
1884 struct cpsw_slave *slave;
1885 struct cpsw_common *cpsw = priv->cpsw;
1888 slave = &cpsw->slaves[cpsw_slave_index(cpsw, priv)];
1890 ctrl = slave_read(slave, CPSW2_CONTROL);
1891 switch (cpsw->version) {
1892 case CPSW_VERSION_2:
1893 ctrl &= ~CTRL_V2_ALL_TS_MASK;
1895 if (priv->tx_ts_enabled)
1896 ctrl |= CTRL_V2_TX_TS_BITS;
1898 if (priv->rx_ts_enabled)
1899 ctrl |= CTRL_V2_RX_TS_BITS;
1901 case CPSW_VERSION_3:
1903 ctrl &= ~CTRL_V3_ALL_TS_MASK;
1905 if (priv->tx_ts_enabled)
1906 ctrl |= CTRL_V3_TX_TS_BITS;
1908 if (priv->rx_ts_enabled)
1909 ctrl |= CTRL_V3_RX_TS_BITS;
1913 mtype = (30 << TS_SEQ_ID_OFFSET_SHIFT) | EVENT_MSG_BITS;
1915 slave_write(slave, mtype, CPSW2_TS_SEQ_MTYPE);
1916 slave_write(slave, ctrl, CPSW2_CONTROL);
1917 writel_relaxed(ETH_P_1588, &cpsw->regs->ts_ltype);
1918 writel_relaxed(ETH_P_8021Q, &cpsw->regs->vlan_ltype);
1921 static int cpsw_hwtstamp_set(struct net_device *dev, struct ifreq *ifr)
1923 struct cpsw_priv *priv = netdev_priv(dev);
1924 struct hwtstamp_config cfg;
1925 struct cpsw_common *cpsw = priv->cpsw;
1927 if (cpsw->version != CPSW_VERSION_1 &&
1928 cpsw->version != CPSW_VERSION_2 &&
1929 cpsw->version != CPSW_VERSION_3)
1932 if (copy_from_user(&cfg, ifr->ifr_data, sizeof(cfg)))
1935 /* reserved for future extensions */
1939 if (cfg.tx_type != HWTSTAMP_TX_OFF && cfg.tx_type != HWTSTAMP_TX_ON)
1942 switch (cfg.rx_filter) {
1943 case HWTSTAMP_FILTER_NONE:
1944 priv->rx_ts_enabled = 0;
1946 case HWTSTAMP_FILTER_ALL:
1947 case HWTSTAMP_FILTER_NTP_ALL:
1949 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
1950 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
1951 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
1952 priv->rx_ts_enabled = HWTSTAMP_FILTER_PTP_V1_L4_EVENT;
1953 cfg.rx_filter = HWTSTAMP_FILTER_PTP_V1_L4_EVENT;
1955 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
1956 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
1957 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
1958 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
1959 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
1960 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
1961 case HWTSTAMP_FILTER_PTP_V2_EVENT:
1962 case HWTSTAMP_FILTER_PTP_V2_SYNC:
1963 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
1964 priv->rx_ts_enabled = HWTSTAMP_FILTER_PTP_V2_EVENT;
1965 cfg.rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT;
1971 priv->tx_ts_enabled = cfg.tx_type == HWTSTAMP_TX_ON;
1973 switch (cpsw->version) {
1974 case CPSW_VERSION_1:
1975 cpsw_hwtstamp_v1(priv);
1977 case CPSW_VERSION_2:
1978 case CPSW_VERSION_3:
1979 cpsw_hwtstamp_v2(priv);
1985 return copy_to_user(ifr->ifr_data, &cfg, sizeof(cfg)) ? -EFAULT : 0;
1988 static int cpsw_hwtstamp_get(struct net_device *dev, struct ifreq *ifr)
1990 struct cpsw_common *cpsw = ndev_to_cpsw(dev);
1991 struct cpsw_priv *priv = netdev_priv(dev);
1992 struct hwtstamp_config cfg;
1994 if (cpsw->version != CPSW_VERSION_1 &&
1995 cpsw->version != CPSW_VERSION_2 &&
1996 cpsw->version != CPSW_VERSION_3)
2000 cfg.tx_type = priv->tx_ts_enabled ? HWTSTAMP_TX_ON : HWTSTAMP_TX_OFF;
2001 cfg.rx_filter = priv->rx_ts_enabled;
2003 return copy_to_user(ifr->ifr_data, &cfg, sizeof(cfg)) ? -EFAULT : 0;
2006 static int cpsw_hwtstamp_get(struct net_device *dev, struct ifreq *ifr)
2011 static int cpsw_hwtstamp_set(struct net_device *dev, struct ifreq *ifr)
2015 #endif /*CONFIG_TI_CPTS*/
2017 static int cpsw_ndo_ioctl(struct net_device *dev, struct ifreq *req, int cmd)
2019 struct cpsw_priv *priv = netdev_priv(dev);
2020 struct cpsw_common *cpsw = priv->cpsw;
2021 int slave_no = cpsw_slave_index(cpsw, priv);
2023 if (!netif_running(dev))
2028 return cpsw_hwtstamp_set(dev, req);
2030 return cpsw_hwtstamp_get(dev, req);
2033 if (!cpsw->slaves[slave_no].phy)
2035 return phy_mii_ioctl(cpsw->slaves[slave_no].phy, req, cmd);
2038 static void cpsw_ndo_tx_timeout(struct net_device *ndev)
2040 struct cpsw_priv *priv = netdev_priv(ndev);
2041 struct cpsw_common *cpsw = priv->cpsw;
2044 cpsw_err(priv, tx_err, "transmit timeout, restarting dma\n");
2045 ndev->stats.tx_errors++;
2046 cpsw_intr_disable(cpsw);
2047 for (ch = 0; ch < cpsw->tx_ch_num; ch++) {
2048 cpdma_chan_stop(cpsw->txv[ch].ch);
2049 cpdma_chan_start(cpsw->txv[ch].ch);
2052 cpsw_intr_enable(cpsw);
2053 netif_trans_update(ndev);
2054 netif_tx_wake_all_queues(ndev);
2057 static int cpsw_ndo_set_mac_address(struct net_device *ndev, void *p)
2059 struct cpsw_priv *priv = netdev_priv(ndev);
2060 struct sockaddr *addr = (struct sockaddr *)p;
2061 struct cpsw_common *cpsw = priv->cpsw;
2066 if (!is_valid_ether_addr(addr->sa_data))
2067 return -EADDRNOTAVAIL;
2069 ret = pm_runtime_get_sync(cpsw->dev);
2071 pm_runtime_put_noidle(cpsw->dev);
2075 if (cpsw->data.dual_emac) {
2076 vid = cpsw->slaves[priv->emac_port].port_vlan;
2080 cpsw_ale_del_ucast(cpsw->ale, priv->mac_addr, HOST_PORT_NUM,
2082 cpsw_ale_add_ucast(cpsw->ale, addr->sa_data, HOST_PORT_NUM,
2085 memcpy(priv->mac_addr, addr->sa_data, ETH_ALEN);
2086 memcpy(ndev->dev_addr, priv->mac_addr, ETH_ALEN);
2087 for_each_slave(priv, cpsw_set_slave_mac, priv);
2089 pm_runtime_put(cpsw->dev);
2094 static inline int cpsw_add_vlan_ale_entry(struct cpsw_priv *priv,
2098 int unreg_mcast_mask = 0;
2101 struct cpsw_common *cpsw = priv->cpsw;
2103 if (cpsw->data.dual_emac) {
2104 port_mask = (1 << (priv->emac_port + 1)) | ALE_PORT_HOST;
2106 mcast_mask = ALE_PORT_HOST;
2107 if (priv->ndev->flags & IFF_ALLMULTI)
2108 unreg_mcast_mask = mcast_mask;
2110 port_mask = ALE_ALL_PORTS;
2111 mcast_mask = port_mask;
2113 if (priv->ndev->flags & IFF_ALLMULTI)
2114 unreg_mcast_mask = ALE_ALL_PORTS;
2116 unreg_mcast_mask = ALE_PORT_1 | ALE_PORT_2;
2119 ret = cpsw_ale_add_vlan(cpsw->ale, vid, port_mask, 0, port_mask,
2124 ret = cpsw_ale_add_ucast(cpsw->ale, priv->mac_addr,
2125 HOST_PORT_NUM, ALE_VLAN, vid);
2129 ret = cpsw_ale_add_mcast(cpsw->ale, priv->ndev->broadcast,
2130 mcast_mask, ALE_VLAN, vid, 0);
2132 goto clean_vlan_ucast;
2136 cpsw_ale_del_ucast(cpsw->ale, priv->mac_addr,
2137 HOST_PORT_NUM, ALE_VLAN, vid);
2139 cpsw_ale_del_vlan(cpsw->ale, vid, 0);
2143 static int cpsw_ndo_vlan_rx_add_vid(struct net_device *ndev,
2144 __be16 proto, u16 vid)
2146 struct cpsw_priv *priv = netdev_priv(ndev);
2147 struct cpsw_common *cpsw = priv->cpsw;
2150 if (vid == cpsw->data.default_vlan)
2153 ret = pm_runtime_get_sync(cpsw->dev);
2155 pm_runtime_put_noidle(cpsw->dev);
2159 if (cpsw->data.dual_emac) {
2160 /* In dual EMAC, reserved VLAN id should not be used for
2161 * creating VLAN interfaces as this can break the dual
2162 * EMAC port separation
2166 for (i = 0; i < cpsw->data.slaves; i++) {
2167 if (vid == cpsw->slaves[i].port_vlan) {
2174 dev_info(priv->dev, "Adding vlanid %d to vlan filter\n", vid);
2175 ret = cpsw_add_vlan_ale_entry(priv, vid);
2177 pm_runtime_put(cpsw->dev);
2181 static int cpsw_ndo_vlan_rx_kill_vid(struct net_device *ndev,
2182 __be16 proto, u16 vid)
2184 struct cpsw_priv *priv = netdev_priv(ndev);
2185 struct cpsw_common *cpsw = priv->cpsw;
2188 if (vid == cpsw->data.default_vlan)
2191 ret = pm_runtime_get_sync(cpsw->dev);
2193 pm_runtime_put_noidle(cpsw->dev);
2197 if (cpsw->data.dual_emac) {
2200 for (i = 0; i < cpsw->data.slaves; i++) {
2201 if (vid == cpsw->slaves[i].port_vlan)
2206 dev_info(priv->dev, "removing vlanid %d from vlan filter\n", vid);
2207 ret = cpsw_ale_del_vlan(cpsw->ale, vid, 0);
2208 ret |= cpsw_ale_del_ucast(cpsw->ale, priv->mac_addr,
2209 HOST_PORT_NUM, ALE_VLAN, vid);
2210 ret |= cpsw_ale_del_mcast(cpsw->ale, priv->ndev->broadcast,
2212 ret |= cpsw_ale_flush_multicast(cpsw->ale, 0, vid);
2214 pm_runtime_put(cpsw->dev);
2218 static int cpsw_ndo_set_tx_maxrate(struct net_device *ndev, int queue, u32 rate)
2220 struct cpsw_priv *priv = netdev_priv(ndev);
2221 struct cpsw_common *cpsw = priv->cpsw;
2222 struct cpsw_slave *slave;
2227 ch_rate = netdev_get_tx_queue(ndev, queue)->tx_maxrate;
2228 if (ch_rate == rate)
2231 ch_rate = rate * 1000;
2232 min_rate = cpdma_chan_get_min_rate(cpsw->dma);
2233 if ((ch_rate < min_rate && ch_rate)) {
2234 dev_err(priv->dev, "The channel rate cannot be less than %dMbps",
2239 if (rate > cpsw->speed) {
2240 dev_err(priv->dev, "The channel rate cannot be more than 2Gbps");
2244 ret = pm_runtime_get_sync(cpsw->dev);
2246 pm_runtime_put_noidle(cpsw->dev);
2250 ret = cpdma_chan_set_rate(cpsw->txv[queue].ch, ch_rate);
2251 pm_runtime_put(cpsw->dev);
2256 /* update rates for slaves tx queues */
2257 for (i = 0; i < cpsw->data.slaves; i++) {
2258 slave = &cpsw->slaves[i];
2262 netdev_get_tx_queue(slave->ndev, queue)->tx_maxrate = rate;
2265 cpsw_split_res(cpsw);
2269 static int cpsw_set_mqprio(struct net_device *ndev, void *type_data)
2271 struct tc_mqprio_qopt_offload *mqprio = type_data;
2272 struct cpsw_priv *priv = netdev_priv(ndev);
2273 struct cpsw_common *cpsw = priv->cpsw;
2274 int fifo, num_tc, count, offset;
2275 struct cpsw_slave *slave;
2276 u32 tx_prio_map = 0;
2279 num_tc = mqprio->qopt.num_tc;
2280 if (num_tc > CPSW_TC_NUM)
2283 if (mqprio->mode != TC_MQPRIO_MODE_DCB)
2286 ret = pm_runtime_get_sync(cpsw->dev);
2288 pm_runtime_put_noidle(cpsw->dev);
2293 for (i = 0; i < 8; i++) {
2294 tc = mqprio->qopt.prio_tc_map[i];
2295 fifo = cpsw_tc_to_fifo(tc, num_tc);
2296 tx_prio_map |= fifo << (4 * i);
2299 netdev_set_num_tc(ndev, num_tc);
2300 for (i = 0; i < num_tc; i++) {
2301 count = mqprio->qopt.count[i];
2302 offset = mqprio->qopt.offset[i];
2303 netdev_set_tc_queue(ndev, i, count, offset);
2307 if (!mqprio->qopt.hw) {
2308 /* restore default configuration */
2309 netdev_reset_tc(ndev);
2310 tx_prio_map = TX_PRIORITY_MAPPING;
2313 priv->mqprio_hw = mqprio->qopt.hw;
2315 offset = cpsw->version == CPSW_VERSION_1 ?
2316 CPSW1_TX_PRI_MAP : CPSW2_TX_PRI_MAP;
2318 slave = &cpsw->slaves[cpsw_slave_index(cpsw, priv)];
2319 slave_write(slave, tx_prio_map, offset);
2321 pm_runtime_put_sync(cpsw->dev);
2326 static int cpsw_ndo_setup_tc(struct net_device *ndev, enum tc_setup_type type,
2330 case TC_SETUP_QDISC_CBS:
2331 return cpsw_set_cbs(ndev, type_data);
2333 case TC_SETUP_QDISC_MQPRIO:
2334 return cpsw_set_mqprio(ndev, type_data);
2341 static int cpsw_xdp_prog_setup(struct cpsw_priv *priv, struct netdev_bpf *bpf)
2343 struct bpf_prog *prog = bpf->prog;
2345 if (!priv->xdpi.prog && !prog)
2348 if (!xdp_attachment_flags_ok(&priv->xdpi, bpf))
2351 WRITE_ONCE(priv->xdp_prog, prog);
2353 xdp_attachment_setup(&priv->xdpi, bpf);
2358 static int cpsw_ndo_bpf(struct net_device *ndev, struct netdev_bpf *bpf)
2360 struct cpsw_priv *priv = netdev_priv(ndev);
2362 switch (bpf->command) {
2363 case XDP_SETUP_PROG:
2364 return cpsw_xdp_prog_setup(priv, bpf);
2366 case XDP_QUERY_PROG:
2367 return xdp_attachment_query(&priv->xdpi, bpf);
2374 static int cpsw_ndo_xdp_xmit(struct net_device *ndev, int n,
2375 struct xdp_frame **frames, u32 flags)
2377 struct cpsw_priv *priv = netdev_priv(ndev);
2378 struct xdp_frame *xdpf;
2381 if (unlikely(flags & ~XDP_XMIT_FLAGS_MASK))
2384 for (i = 0; i < n; i++) {
2386 if (xdpf->len < CPSW_MIN_PACKET_SIZE) {
2387 xdp_return_frame_rx_napi(xdpf);
2392 if (cpsw_xdp_tx_frame(priv, xdpf, NULL))
2399 #ifdef CONFIG_NET_POLL_CONTROLLER
2400 static void cpsw_ndo_poll_controller(struct net_device *ndev)
2402 struct cpsw_common *cpsw = ndev_to_cpsw(ndev);
2404 cpsw_intr_disable(cpsw);
2405 cpsw_rx_interrupt(cpsw->irqs_table[0], cpsw);
2406 cpsw_tx_interrupt(cpsw->irqs_table[1], cpsw);
2407 cpsw_intr_enable(cpsw);
2411 static const struct net_device_ops cpsw_netdev_ops = {
2412 .ndo_open = cpsw_ndo_open,
2413 .ndo_stop = cpsw_ndo_stop,
2414 .ndo_start_xmit = cpsw_ndo_start_xmit,
2415 .ndo_set_mac_address = cpsw_ndo_set_mac_address,
2416 .ndo_do_ioctl = cpsw_ndo_ioctl,
2417 .ndo_validate_addr = eth_validate_addr,
2418 .ndo_tx_timeout = cpsw_ndo_tx_timeout,
2419 .ndo_set_rx_mode = cpsw_ndo_set_rx_mode,
2420 .ndo_set_tx_maxrate = cpsw_ndo_set_tx_maxrate,
2421 #ifdef CONFIG_NET_POLL_CONTROLLER
2422 .ndo_poll_controller = cpsw_ndo_poll_controller,
2424 .ndo_vlan_rx_add_vid = cpsw_ndo_vlan_rx_add_vid,
2425 .ndo_vlan_rx_kill_vid = cpsw_ndo_vlan_rx_kill_vid,
2426 .ndo_setup_tc = cpsw_ndo_setup_tc,
2427 .ndo_bpf = cpsw_ndo_bpf,
2428 .ndo_xdp_xmit = cpsw_ndo_xdp_xmit,
2431 static void cpsw_get_drvinfo(struct net_device *ndev,
2432 struct ethtool_drvinfo *info)
2434 struct cpsw_common *cpsw = ndev_to_cpsw(ndev);
2435 struct platform_device *pdev = to_platform_device(cpsw->dev);
2437 strlcpy(info->driver, "cpsw", sizeof(info->driver));
2438 strlcpy(info->version, "1.0", sizeof(info->version));
2439 strlcpy(info->bus_info, pdev->name, sizeof(info->bus_info));
2442 static int cpsw_set_pauseparam(struct net_device *ndev,
2443 struct ethtool_pauseparam *pause)
2445 struct cpsw_priv *priv = netdev_priv(ndev);
2448 priv->rx_pause = pause->rx_pause ? true : false;
2449 priv->tx_pause = pause->tx_pause ? true : false;
2451 for_each_slave(priv, _cpsw_adjust_link, priv, &link);
2455 static int cpsw_set_channels(struct net_device *ndev,
2456 struct ethtool_channels *chs)
2458 return cpsw_set_channels_common(ndev, chs, cpsw_rx_handler);
2461 static const struct ethtool_ops cpsw_ethtool_ops = {
2462 .get_drvinfo = cpsw_get_drvinfo,
2463 .get_msglevel = cpsw_get_msglevel,
2464 .set_msglevel = cpsw_set_msglevel,
2465 .get_link = ethtool_op_get_link,
2466 .get_ts_info = cpsw_get_ts_info,
2467 .get_coalesce = cpsw_get_coalesce,
2468 .set_coalesce = cpsw_set_coalesce,
2469 .get_sset_count = cpsw_get_sset_count,
2470 .get_strings = cpsw_get_strings,
2471 .get_ethtool_stats = cpsw_get_ethtool_stats,
2472 .get_pauseparam = cpsw_get_pauseparam,
2473 .set_pauseparam = cpsw_set_pauseparam,
2474 .get_wol = cpsw_get_wol,
2475 .set_wol = cpsw_set_wol,
2476 .get_regs_len = cpsw_get_regs_len,
2477 .get_regs = cpsw_get_regs,
2478 .begin = cpsw_ethtool_op_begin,
2479 .complete = cpsw_ethtool_op_complete,
2480 .get_channels = cpsw_get_channels,
2481 .set_channels = cpsw_set_channels,
2482 .get_link_ksettings = cpsw_get_link_ksettings,
2483 .set_link_ksettings = cpsw_set_link_ksettings,
2484 .get_eee = cpsw_get_eee,
2485 .set_eee = cpsw_set_eee,
2486 .nway_reset = cpsw_nway_reset,
2487 .get_ringparam = cpsw_get_ringparam,
2488 .set_ringparam = cpsw_set_ringparam,
2491 static int cpsw_probe_dt(struct cpsw_platform_data *data,
2492 struct platform_device *pdev)
2494 struct device_node *node = pdev->dev.of_node;
2495 struct device_node *slave_node;
2502 if (of_property_read_u32(node, "slaves", &prop)) {
2503 dev_err(&pdev->dev, "Missing slaves property in the DT.\n");
2506 data->slaves = prop;
2508 if (of_property_read_u32(node, "active_slave", &prop)) {
2509 dev_err(&pdev->dev, "Missing active_slave property in the DT.\n");
2512 data->active_slave = prop;
2514 data->slave_data = devm_kcalloc(&pdev->dev,
2516 sizeof(struct cpsw_slave_data),
2518 if (!data->slave_data)
2521 if (of_property_read_u32(node, "cpdma_channels", &prop)) {
2522 dev_err(&pdev->dev, "Missing cpdma_channels property in the DT.\n");
2525 data->channels = prop;
2527 if (of_property_read_u32(node, "ale_entries", &prop)) {
2528 dev_err(&pdev->dev, "Missing ale_entries property in the DT.\n");
2531 data->ale_entries = prop;
2533 if (of_property_read_u32(node, "bd_ram_size", &prop)) {
2534 dev_err(&pdev->dev, "Missing bd_ram_size property in the DT.\n");
2537 data->bd_ram_size = prop;
2539 if (of_property_read_u32(node, "mac_control", &prop)) {
2540 dev_err(&pdev->dev, "Missing mac_control property in the DT.\n");
2543 data->mac_control = prop;
2545 if (of_property_read_bool(node, "dual_emac"))
2546 data->dual_emac = 1;
2549 * Populate all the child nodes here...
2551 ret = of_platform_populate(node, NULL, NULL, &pdev->dev);
2552 /* We do not want to force this, as in some cases may not have child */
2554 dev_warn(&pdev->dev, "Doesn't have any child node\n");
2556 for_each_available_child_of_node(node, slave_node) {
2557 struct cpsw_slave_data *slave_data = data->slave_data + i;
2558 const void *mac_addr = NULL;
2562 /* This is no slave child node, continue */
2563 if (!of_node_name_eq(slave_node, "slave"))
2566 slave_data->ifphy = devm_of_phy_get(&pdev->dev, slave_node,
2568 if (!IS_ENABLED(CONFIG_TI_CPSW_PHY_SEL) &&
2569 IS_ERR(slave_data->ifphy)) {
2570 ret = PTR_ERR(slave_data->ifphy);
2572 "%d: Error retrieving port phy: %d\n", i, ret);
2576 slave_data->slave_node = slave_node;
2577 slave_data->phy_node = of_parse_phandle(slave_node,
2579 parp = of_get_property(slave_node, "phy_id", &lenp);
2580 if (slave_data->phy_node) {
2582 "slave[%d] using phy-handle=\"%pOF\"\n",
2583 i, slave_data->phy_node);
2584 } else if (of_phy_is_fixed_link(slave_node)) {
2585 /* In the case of a fixed PHY, the DT node associated
2586 * to the PHY is the Ethernet MAC DT node.
2588 ret = of_phy_register_fixed_link(slave_node);
2590 if (ret != -EPROBE_DEFER)
2591 dev_err(&pdev->dev, "failed to register fixed-link phy: %d\n", ret);
2594 slave_data->phy_node = of_node_get(slave_node);
2597 struct device_node *mdio_node;
2598 struct platform_device *mdio;
2600 if (lenp != (sizeof(__be32) * 2)) {
2601 dev_err(&pdev->dev, "Invalid slave[%d] phy_id property\n", i);
2604 mdio_node = of_find_node_by_phandle(be32_to_cpup(parp));
2605 phyid = be32_to_cpup(parp+1);
2606 mdio = of_find_device_by_node(mdio_node);
2607 of_node_put(mdio_node);
2609 dev_err(&pdev->dev, "Missing mdio platform device\n");
2612 snprintf(slave_data->phy_id, sizeof(slave_data->phy_id),
2613 PHY_ID_FMT, mdio->name, phyid);
2614 put_device(&mdio->dev);
2617 "No slave[%d] phy_id, phy-handle, or fixed-link property\n",
2621 slave_data->phy_if = of_get_phy_mode(slave_node);
2622 if (slave_data->phy_if < 0) {
2623 dev_err(&pdev->dev, "Missing or malformed slave[%d] phy-mode property\n",
2625 return slave_data->phy_if;
2629 mac_addr = of_get_mac_address(slave_node);
2630 if (!IS_ERR(mac_addr)) {
2631 ether_addr_copy(slave_data->mac_addr, mac_addr);
2633 ret = ti_cm_get_macid(&pdev->dev, i,
2634 slave_data->mac_addr);
2638 if (data->dual_emac) {
2639 if (of_property_read_u32(slave_node, "dual_emac_res_vlan",
2641 dev_err(&pdev->dev, "Missing dual_emac_res_vlan in DT.\n");
2642 slave_data->dual_emac_res_vlan = i+1;
2643 dev_err(&pdev->dev, "Using %d as Reserved VLAN for %d slave\n",
2644 slave_data->dual_emac_res_vlan, i);
2646 slave_data->dual_emac_res_vlan = prop;
2651 if (i == data->slaves)
2658 static void cpsw_remove_dt(struct platform_device *pdev)
2660 struct cpsw_common *cpsw = platform_get_drvdata(pdev);
2661 struct cpsw_platform_data *data = &cpsw->data;
2662 struct device_node *node = pdev->dev.of_node;
2663 struct device_node *slave_node;
2666 for_each_available_child_of_node(node, slave_node) {
2667 struct cpsw_slave_data *slave_data = &data->slave_data[i];
2669 if (!of_node_name_eq(slave_node, "slave"))
2672 if (of_phy_is_fixed_link(slave_node))
2673 of_phy_deregister_fixed_link(slave_node);
2675 of_node_put(slave_data->phy_node);
2678 if (i == data->slaves)
2682 of_platform_depopulate(&pdev->dev);
2685 static int cpsw_probe_dual_emac(struct cpsw_priv *priv)
2687 struct cpsw_common *cpsw = priv->cpsw;
2688 struct cpsw_platform_data *data = &cpsw->data;
2689 struct net_device *ndev;
2690 struct cpsw_priv *priv_sl2;
2693 ndev = devm_alloc_etherdev_mqs(cpsw->dev, sizeof(struct cpsw_priv),
2694 CPSW_MAX_QUEUES, CPSW_MAX_QUEUES);
2696 dev_err(cpsw->dev, "cpsw: error allocating net_device\n");
2700 priv_sl2 = netdev_priv(ndev);
2701 priv_sl2->cpsw = cpsw;
2702 priv_sl2->ndev = ndev;
2703 priv_sl2->dev = &ndev->dev;
2704 priv_sl2->msg_enable = netif_msg_init(debug_level, CPSW_DEBUG);
2706 if (is_valid_ether_addr(data->slave_data[1].mac_addr)) {
2707 memcpy(priv_sl2->mac_addr, data->slave_data[1].mac_addr,
2709 dev_info(cpsw->dev, "cpsw: Detected MACID = %pM\n",
2710 priv_sl2->mac_addr);
2712 eth_random_addr(priv_sl2->mac_addr);
2713 dev_info(cpsw->dev, "cpsw: Random MACID = %pM\n",
2714 priv_sl2->mac_addr);
2716 memcpy(ndev->dev_addr, priv_sl2->mac_addr, ETH_ALEN);
2718 priv_sl2->emac_port = 1;
2719 cpsw->slaves[1].ndev = ndev;
2720 ndev->features |= NETIF_F_HW_VLAN_CTAG_FILTER | NETIF_F_HW_VLAN_CTAG_RX;
2722 ndev->netdev_ops = &cpsw_netdev_ops;
2723 ndev->ethtool_ops = &cpsw_ethtool_ops;
2725 /* register the network device */
2726 SET_NETDEV_DEV(ndev, cpsw->dev);
2727 ndev->dev.of_node = cpsw->slaves[1].data->slave_node;
2728 ret = register_netdev(ndev);
2730 dev_err(cpsw->dev, "cpsw: error registering net device\n");
2735 static const struct of_device_id cpsw_of_mtable[] = {
2736 { .compatible = "ti,cpsw"},
2737 { .compatible = "ti,am335x-cpsw"},
2738 { .compatible = "ti,am4372-cpsw"},
2739 { .compatible = "ti,dra7-cpsw"},
2742 MODULE_DEVICE_TABLE(of, cpsw_of_mtable);
2744 static const struct soc_device_attribute cpsw_soc_devices[] = {
2745 { .family = "AM33xx", .revision = "ES1.0"},
2749 static int cpsw_probe(struct platform_device *pdev)
2751 struct device *dev = &pdev->dev;
2753 struct cpsw_platform_data *data;
2754 struct net_device *ndev;
2755 struct cpsw_priv *priv;
2756 void __iomem *ss_regs;
2757 struct resource *res, *ss_res;
2758 struct gpio_descs *mode;
2759 const struct soc_device_attribute *soc;
2760 struct cpsw_common *cpsw;
2764 cpsw = devm_kzalloc(dev, sizeof(struct cpsw_common), GFP_KERNEL);
2770 mode = devm_gpiod_get_array_optional(dev, "mode", GPIOD_OUT_LOW);
2772 ret = PTR_ERR(mode);
2773 dev_err(dev, "gpio request failed, ret %d\n", ret);
2777 clk = devm_clk_get(dev, "fck");
2780 dev_err(dev, "fck is not found %d\n", ret);
2783 cpsw->bus_freq_mhz = clk_get_rate(clk) / 1000000;
2785 ss_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
2786 ss_regs = devm_ioremap_resource(dev, ss_res);
2787 if (IS_ERR(ss_regs))
2788 return PTR_ERR(ss_regs);
2789 cpsw->regs = ss_regs;
2791 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
2792 cpsw->wr_regs = devm_ioremap_resource(dev, res);
2793 if (IS_ERR(cpsw->wr_regs))
2794 return PTR_ERR(cpsw->wr_regs);
2797 irq = platform_get_irq(pdev, 1);
2800 cpsw->irqs_table[0] = irq;
2803 irq = platform_get_irq(pdev, 2);
2806 cpsw->irqs_table[1] = irq;
2809 * This may be required here for child devices.
2811 pm_runtime_enable(dev);
2813 /* Need to enable clocks with runtime PM api to access module
2816 ret = pm_runtime_get_sync(dev);
2818 pm_runtime_put_noidle(dev);
2819 goto clean_runtime_disable_ret;
2822 ret = cpsw_probe_dt(&cpsw->data, pdev);
2826 soc = soc_device_match(cpsw_soc_devices);
2828 cpsw->quirk_irq = 1;
2831 cpsw->slaves = devm_kcalloc(dev,
2832 data->slaves, sizeof(struct cpsw_slave),
2834 if (!cpsw->slaves) {
2839 cpsw->rx_packet_max = max(rx_packet_max, CPSW_MAX_PACKET_SIZE);
2840 cpsw->descs_pool_size = descs_pool_size;
2842 ret = cpsw_init_common(cpsw, ss_regs, ale_ageout,
2843 ss_res->start + CPSW2_BD_OFFSET,
2848 ch = cpsw->quirk_irq ? 0 : 7;
2849 cpsw->txv[0].ch = cpdma_chan_create(cpsw->dma, ch, cpsw_tx_handler, 0);
2850 if (IS_ERR(cpsw->txv[0].ch)) {
2851 dev_err(dev, "error initializing tx dma channel\n");
2852 ret = PTR_ERR(cpsw->txv[0].ch);
2856 cpsw->rxv[0].ch = cpdma_chan_create(cpsw->dma, 0, cpsw_rx_handler, 1);
2857 if (IS_ERR(cpsw->rxv[0].ch)) {
2858 dev_err(dev, "error initializing rx dma channel\n");
2859 ret = PTR_ERR(cpsw->rxv[0].ch);
2862 cpsw_split_res(cpsw);
2865 ndev = devm_alloc_etherdev_mqs(dev, sizeof(struct cpsw_priv),
2866 CPSW_MAX_QUEUES, CPSW_MAX_QUEUES);
2868 dev_err(dev, "error allocating net_device\n");
2872 platform_set_drvdata(pdev, cpsw);
2873 priv = netdev_priv(ndev);
2877 priv->msg_enable = netif_msg_init(debug_level, CPSW_DEBUG);
2878 priv->emac_port = 0;
2880 if (is_valid_ether_addr(data->slave_data[0].mac_addr)) {
2881 memcpy(priv->mac_addr, data->slave_data[0].mac_addr, ETH_ALEN);
2882 dev_info(dev, "Detected MACID = %pM\n", priv->mac_addr);
2884 eth_random_addr(priv->mac_addr);
2885 dev_info(dev, "Random MACID = %pM\n", priv->mac_addr);
2888 memcpy(ndev->dev_addr, priv->mac_addr, ETH_ALEN);
2890 cpsw->slaves[0].ndev = ndev;
2892 ndev->features |= NETIF_F_HW_VLAN_CTAG_FILTER | NETIF_F_HW_VLAN_CTAG_RX;
2894 ndev->netdev_ops = &cpsw_netdev_ops;
2895 ndev->ethtool_ops = &cpsw_ethtool_ops;
2896 netif_napi_add(ndev, &cpsw->napi_rx,
2897 cpsw->quirk_irq ? cpsw_rx_poll : cpsw_rx_mq_poll,
2899 netif_tx_napi_add(ndev, &cpsw->napi_tx,
2900 cpsw->quirk_irq ? cpsw_tx_poll : cpsw_tx_mq_poll,
2903 /* register the network device */
2904 SET_NETDEV_DEV(ndev, dev);
2905 ndev->dev.of_node = cpsw->slaves[0].data->slave_node;
2906 ret = register_netdev(ndev);
2908 dev_err(dev, "error registering net device\n");
2913 if (cpsw->data.dual_emac) {
2914 ret = cpsw_probe_dual_emac(priv);
2916 cpsw_err(priv, probe, "error probe slave 2 emac interface\n");
2917 goto clean_unregister_netdev_ret;
2921 /* Grab RX and TX IRQs. Note that we also have RX_THRESHOLD and
2922 * MISC IRQs which are always kept disabled with this driver so
2923 * we will not request them.
2925 * If anyone wants to implement support for those, make sure to
2926 * first request and append them to irqs_table array.
2928 ret = devm_request_irq(dev, cpsw->irqs_table[0], cpsw_rx_interrupt,
2929 0, dev_name(dev), cpsw);
2931 dev_err(dev, "error attaching irq (%d)\n", ret);
2932 goto clean_unregister_netdev_ret;
2936 ret = devm_request_irq(dev, cpsw->irqs_table[1], cpsw_tx_interrupt,
2937 0, dev_name(&pdev->dev), cpsw);
2939 dev_err(dev, "error attaching irq (%d)\n", ret);
2940 goto clean_unregister_netdev_ret;
2943 cpsw_notice(priv, probe,
2944 "initialized device (regs %pa, irq %d, pool size %d)\n",
2945 &ss_res->start, cpsw->irqs_table[0], descs_pool_size);
2947 pm_runtime_put(&pdev->dev);
2951 clean_unregister_netdev_ret:
2952 unregister_netdev(ndev);
2954 cpts_release(cpsw->cpts);
2955 cpdma_ctlr_destroy(cpsw->dma);
2957 cpsw_remove_dt(pdev);
2958 pm_runtime_put_sync(&pdev->dev);
2959 clean_runtime_disable_ret:
2960 pm_runtime_disable(&pdev->dev);
2964 static int cpsw_remove(struct platform_device *pdev)
2966 struct cpsw_common *cpsw = platform_get_drvdata(pdev);
2969 ret = pm_runtime_get_sync(&pdev->dev);
2971 pm_runtime_put_noidle(&pdev->dev);
2975 for (i = 0; i < cpsw->data.slaves; i++)
2976 if (cpsw->slaves[i].ndev)
2977 unregister_netdev(cpsw->slaves[i].ndev);
2979 cpts_release(cpsw->cpts);
2980 cpdma_ctlr_destroy(cpsw->dma);
2981 cpsw_remove_dt(pdev);
2982 pm_runtime_put_sync(&pdev->dev);
2983 pm_runtime_disable(&pdev->dev);
2987 #ifdef CONFIG_PM_SLEEP
2988 static int cpsw_suspend(struct device *dev)
2990 struct cpsw_common *cpsw = dev_get_drvdata(dev);
2993 for (i = 0; i < cpsw->data.slaves; i++)
2994 if (cpsw->slaves[i].ndev)
2995 if (netif_running(cpsw->slaves[i].ndev))
2996 cpsw_ndo_stop(cpsw->slaves[i].ndev);
2998 /* Select sleep pin state */
2999 pinctrl_pm_select_sleep_state(dev);
3004 static int cpsw_resume(struct device *dev)
3006 struct cpsw_common *cpsw = dev_get_drvdata(dev);
3009 /* Select default pin state */
3010 pinctrl_pm_select_default_state(dev);
3012 /* shut up ASSERT_RTNL() warning in netif_set_real_num_tx/rx_queues */
3015 for (i = 0; i < cpsw->data.slaves; i++)
3016 if (cpsw->slaves[i].ndev)
3017 if (netif_running(cpsw->slaves[i].ndev))
3018 cpsw_ndo_open(cpsw->slaves[i].ndev);
3026 static SIMPLE_DEV_PM_OPS(cpsw_pm_ops, cpsw_suspend, cpsw_resume);
3028 static struct platform_driver cpsw_driver = {
3032 .of_match_table = cpsw_of_mtable,
3034 .probe = cpsw_probe,
3035 .remove = cpsw_remove,
3038 module_platform_driver(cpsw_driver);
3040 MODULE_LICENSE("GPL");
3041 MODULE_AUTHOR("Cyril Chemparathy <cyril@ti.com>");
3042 MODULE_AUTHOR("Mugunthan V N <mugunthanvnm@ti.com>");
3043 MODULE_DESCRIPTION("TI CPSW Ethernet driver");