2 * Texas Instruments Ethernet Switch Driver
4 * Copyright (C) 2012 Texas Instruments
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation version 2.
10 * This program is distributed "as is" WITHOUT ANY WARRANTY of any
11 * kind, whether express or implied; without even the implied warranty
12 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
16 #include <linux/kernel.h>
18 #include <linux/clk.h>
19 #include <linux/timer.h>
20 #include <linux/module.h>
21 #include <linux/platform_device.h>
22 #include <linux/irqreturn.h>
23 #include <linux/interrupt.h>
24 #include <linux/if_ether.h>
25 #include <linux/etherdevice.h>
26 #include <linux/netdevice.h>
27 #include <linux/net_tstamp.h>
28 #include <linux/phy.h>
29 #include <linux/workqueue.h>
30 #include <linux/delay.h>
31 #include <linux/pm_runtime.h>
33 #include <linux/of_net.h>
34 #include <linux/of_device.h>
36 #include <linux/platform_data/cpsw.h>
40 #include "davinci_cpdma.h"
42 #define CPSW_DEBUG (NETIF_MSG_HW | NETIF_MSG_WOL | \
43 NETIF_MSG_DRV | NETIF_MSG_LINK | \
44 NETIF_MSG_IFUP | NETIF_MSG_INTR | \
45 NETIF_MSG_PROBE | NETIF_MSG_TIMER | \
46 NETIF_MSG_IFDOWN | NETIF_MSG_RX_ERR | \
47 NETIF_MSG_TX_ERR | NETIF_MSG_TX_DONE | \
48 NETIF_MSG_PKTDATA | NETIF_MSG_TX_QUEUED | \
51 #define cpsw_info(priv, type, format, ...) \
53 if (netif_msg_##type(priv) && net_ratelimit()) \
54 dev_info(priv->dev, format, ## __VA_ARGS__); \
57 #define cpsw_err(priv, type, format, ...) \
59 if (netif_msg_##type(priv) && net_ratelimit()) \
60 dev_err(priv->dev, format, ## __VA_ARGS__); \
63 #define cpsw_dbg(priv, type, format, ...) \
65 if (netif_msg_##type(priv) && net_ratelimit()) \
66 dev_dbg(priv->dev, format, ## __VA_ARGS__); \
69 #define cpsw_notice(priv, type, format, ...) \
71 if (netif_msg_##type(priv) && net_ratelimit()) \
72 dev_notice(priv->dev, format, ## __VA_ARGS__); \
75 #define ALE_ALL_PORTS 0x7
77 #define CPSW_MAJOR_VERSION(reg) (reg >> 8 & 0x7)
78 #define CPSW_MINOR_VERSION(reg) (reg & 0xff)
79 #define CPSW_RTL_VERSION(reg) ((reg >> 11) & 0x1f)
81 #define CPSW_VERSION_1 0x19010a
82 #define CPSW_VERSION_2 0x19010c
83 #define CPDMA_RXTHRESH 0x0c0
84 #define CPDMA_RXFREE 0x0e0
85 #define CPDMA_TXHDP 0x00
86 #define CPDMA_RXHDP 0x20
87 #define CPDMA_TXCP 0x40
88 #define CPDMA_RXCP 0x60
90 #define cpsw_dma_regs(base, offset) \
91 (void __iomem *)((base) + (offset))
92 #define cpsw_dma_rxthresh(base, offset) \
93 (void __iomem *)((base) + (offset) + CPDMA_RXTHRESH)
94 #define cpsw_dma_rxfree(base, offset) \
95 (void __iomem *)((base) + (offset) + CPDMA_RXFREE)
96 #define cpsw_dma_txhdp(base, offset) \
97 (void __iomem *)((base) + (offset) + CPDMA_TXHDP)
98 #define cpsw_dma_rxhdp(base, offset) \
99 (void __iomem *)((base) + (offset) + CPDMA_RXHDP)
100 #define cpsw_dma_txcp(base, offset) \
101 (void __iomem *)((base) + (offset) + CPDMA_TXCP)
102 #define cpsw_dma_rxcp(base, offset) \
103 (void __iomem *)((base) + (offset) + CPDMA_RXCP)
105 #define CPSW_POLL_WEIGHT 64
106 #define CPSW_MIN_PACKET_SIZE 60
107 #define CPSW_MAX_PACKET_SIZE (1500 + 14 + 4 + 4)
109 #define RX_PRIORITY_MAPPING 0x76543210
110 #define TX_PRIORITY_MAPPING 0x33221100
111 #define CPDMA_TX_PRIORITY_MAP 0x76543210
113 #define cpsw_enable_irq(priv) \
116 for (i = 0; i < priv->num_irqs; i++) \
117 enable_irq(priv->irqs_table[i]); \
119 #define cpsw_disable_irq(priv) \
122 for (i = 0; i < priv->num_irqs; i++) \
123 disable_irq_nosync(priv->irqs_table[i]); \
126 static int debug_level;
127 module_param(debug_level, int, 0);
128 MODULE_PARM_DESC(debug_level, "cpsw debug level (NETIF_MSG bits)");
130 static int ale_ageout = 10;
131 module_param(ale_ageout, int, 0);
132 MODULE_PARM_DESC(ale_ageout, "cpsw ale ageout interval (seconds)");
134 static int rx_packet_max = CPSW_MAX_PACKET_SIZE;
135 module_param(rx_packet_max, int, 0);
136 MODULE_PARM_DESC(rx_packet_max, "maximum receive packet size (bytes)");
138 struct cpsw_wr_regs {
149 struct cpsw_ss_regs {
166 #define CPSW1_MAX_BLKS 0x00 /* Maximum FIFO Blocks */
167 #define CPSW1_BLK_CNT 0x04 /* FIFO Block Usage Count (Read Only) */
168 #define CPSW1_TX_IN_CTL 0x08 /* Transmit FIFO Control */
169 #define CPSW1_PORT_VLAN 0x0c /* VLAN Register */
170 #define CPSW1_TX_PRI_MAP 0x10 /* Tx Header Priority to Switch Pri Mapping */
171 #define CPSW1_TS_CTL 0x14 /* Time Sync Control */
172 #define CPSW1_TS_SEQ_LTYPE 0x18 /* Time Sync Sequence ID Offset and Msg Type */
173 #define CPSW1_TS_VLAN 0x1c /* Time Sync VLAN1 and VLAN2 */
176 #define CPSW2_CONTROL 0x00 /* Control Register */
177 #define CPSW2_MAX_BLKS 0x08 /* Maximum FIFO Blocks */
178 #define CPSW2_BLK_CNT 0x0c /* FIFO Block Usage Count (Read Only) */
179 #define CPSW2_TX_IN_CTL 0x10 /* Transmit FIFO Control */
180 #define CPSW2_PORT_VLAN 0x14 /* VLAN Register */
181 #define CPSW2_TX_PRI_MAP 0x18 /* Tx Header Priority to Switch Pri Mapping */
182 #define CPSW2_TS_SEQ_MTYPE 0x1c /* Time Sync Sequence ID Offset and Msg Type */
184 /* CPSW_PORT_V1 and V2 */
185 #define SA_LO 0x20 /* CPGMAC_SL Source Address Low */
186 #define SA_HI 0x24 /* CPGMAC_SL Source Address High */
187 #define SEND_PERCENT 0x28 /* Transmit Queue Send Percentages */
189 /* CPSW_PORT_V2 only */
190 #define RX_DSCP_PRI_MAP0 0x30 /* Rx DSCP Priority to Rx Packet Mapping */
191 #define RX_DSCP_PRI_MAP1 0x34 /* Rx DSCP Priority to Rx Packet Mapping */
192 #define RX_DSCP_PRI_MAP2 0x38 /* Rx DSCP Priority to Rx Packet Mapping */
193 #define RX_DSCP_PRI_MAP3 0x3c /* Rx DSCP Priority to Rx Packet Mapping */
194 #define RX_DSCP_PRI_MAP4 0x40 /* Rx DSCP Priority to Rx Packet Mapping */
195 #define RX_DSCP_PRI_MAP5 0x44 /* Rx DSCP Priority to Rx Packet Mapping */
196 #define RX_DSCP_PRI_MAP6 0x48 /* Rx DSCP Priority to Rx Packet Mapping */
197 #define RX_DSCP_PRI_MAP7 0x4c /* Rx DSCP Priority to Rx Packet Mapping */
199 /* Bit definitions for the CPSW2_CONTROL register */
200 #define PASS_PRI_TAGGED (1<<24) /* Pass Priority Tagged */
201 #define VLAN_LTYPE2_EN (1<<21) /* VLAN LTYPE 2 enable */
202 #define VLAN_LTYPE1_EN (1<<20) /* VLAN LTYPE 1 enable */
203 #define DSCP_PRI_EN (1<<16) /* DSCP Priority Enable */
204 #define TS_320 (1<<14) /* Time Sync Dest Port 320 enable */
205 #define TS_319 (1<<13) /* Time Sync Dest Port 319 enable */
206 #define TS_132 (1<<12) /* Time Sync Dest IP Addr 132 enable */
207 #define TS_131 (1<<11) /* Time Sync Dest IP Addr 131 enable */
208 #define TS_130 (1<<10) /* Time Sync Dest IP Addr 130 enable */
209 #define TS_129 (1<<9) /* Time Sync Dest IP Addr 129 enable */
210 #define TS_BIT8 (1<<8) /* ts_ttl_nonzero? */
211 #define TS_ANNEX_D_EN (1<<4) /* Time Sync Annex D enable */
212 #define TS_LTYPE2_EN (1<<3) /* Time Sync LTYPE 2 enable */
213 #define TS_LTYPE1_EN (1<<2) /* Time Sync LTYPE 1 enable */
214 #define TS_TX_EN (1<<1) /* Time Sync Transmit Enable */
215 #define TS_RX_EN (1<<0) /* Time Sync Receive Enable */
217 #define CTRL_TS_BITS \
218 (TS_320 | TS_319 | TS_132 | TS_131 | TS_130 | TS_129 | TS_BIT8 | \
219 TS_ANNEX_D_EN | TS_LTYPE1_EN)
221 #define CTRL_ALL_TS_MASK (CTRL_TS_BITS | TS_TX_EN | TS_RX_EN)
222 #define CTRL_TX_TS_BITS (CTRL_TS_BITS | TS_TX_EN)
223 #define CTRL_RX_TS_BITS (CTRL_TS_BITS | TS_RX_EN)
225 /* Bit definitions for the CPSW2_TS_SEQ_MTYPE register */
226 #define TS_SEQ_ID_OFFSET_SHIFT (16) /* Time Sync Sequence ID Offset */
227 #define TS_SEQ_ID_OFFSET_MASK (0x3f)
228 #define TS_MSG_TYPE_EN_SHIFT (0) /* Time Sync Message Type Enable */
229 #define TS_MSG_TYPE_EN_MASK (0xffff)
231 /* The PTP event messages - Sync, Delay_Req, Pdelay_Req, and Pdelay_Resp. */
232 #define EVENT_MSG_BITS ((1<<0) | (1<<1) | (1<<2) | (1<<3))
234 /* Bit definitions for the CPSW1_TS_CTL register */
235 #define CPSW_V1_TS_RX_EN BIT(0)
236 #define CPSW_V1_TS_TX_EN BIT(4)
237 #define CPSW_V1_MSG_TYPE_OFS 16
239 /* Bit definitions for the CPSW1_TS_SEQ_LTYPE register */
240 #define CPSW_V1_SEQ_ID_OFS_SHIFT 16
242 struct cpsw_host_regs {
248 u32 cpdma_tx_pri_map;
249 u32 cpdma_rx_chan_map;
252 struct cpsw_sliver_regs {
267 struct cpsw_sliver_regs __iomem *sliver;
270 struct cpsw_slave_data *data;
271 struct phy_device *phy;
274 static inline u32 slave_read(struct cpsw_slave *slave, u32 offset)
276 return __raw_readl(slave->regs + offset);
279 static inline void slave_write(struct cpsw_slave *slave, u32 val, u32 offset)
281 __raw_writel(val, slave->regs + offset);
286 struct platform_device *pdev;
287 struct net_device *ndev;
288 struct resource *cpsw_res;
289 struct resource *cpsw_wr_res;
290 struct napi_struct napi;
292 struct cpsw_platform_data data;
293 struct cpsw_ss_regs __iomem *regs;
294 struct cpsw_wr_regs __iomem *wr_regs;
295 struct cpsw_host_regs __iomem *host_port_regs;
298 struct net_device_stats stats;
302 u8 mac_addr[ETH_ALEN];
303 struct cpsw_slave *slaves;
304 struct cpdma_ctlr *dma;
305 struct cpdma_chan *txch, *rxch;
306 struct cpsw_ale *ale;
307 /* snapshot of IRQ numbers */
313 #define napi_to_priv(napi) container_of(napi, struct cpsw_priv, napi)
314 #define for_each_slave(priv, func, arg...) \
317 for (idx = 0; idx < (priv)->data.slaves; idx++) \
318 (func)((priv)->slaves + idx, ##arg); \
321 static void cpsw_ndo_set_rx_mode(struct net_device *ndev)
323 struct cpsw_priv *priv = netdev_priv(ndev);
325 if (ndev->flags & IFF_PROMISC) {
326 /* Enable promiscuous mode */
327 dev_err(priv->dev, "Ignoring Promiscuous mode\n");
331 /* Clear all mcast from ALE */
332 cpsw_ale_flush_multicast(priv->ale, ALE_ALL_PORTS << priv->host_port);
334 if (!netdev_mc_empty(ndev)) {
335 struct netdev_hw_addr *ha;
337 /* program multicast address list into ALE register */
338 netdev_for_each_mc_addr(ha, ndev) {
339 cpsw_ale_add_mcast(priv->ale, (u8 *)ha->addr,
340 ALE_ALL_PORTS << priv->host_port, 0, 0);
345 static void cpsw_intr_enable(struct cpsw_priv *priv)
347 __raw_writel(0xFF, &priv->wr_regs->tx_en);
348 __raw_writel(0xFF, &priv->wr_regs->rx_en);
350 cpdma_ctlr_int_ctrl(priv->dma, true);
354 static void cpsw_intr_disable(struct cpsw_priv *priv)
356 __raw_writel(0, &priv->wr_regs->tx_en);
357 __raw_writel(0, &priv->wr_regs->rx_en);
359 cpdma_ctlr_int_ctrl(priv->dma, false);
363 void cpsw_tx_handler(void *token, int len, int status)
365 struct sk_buff *skb = token;
366 struct net_device *ndev = skb->dev;
367 struct cpsw_priv *priv = netdev_priv(ndev);
369 if (unlikely(netif_queue_stopped(ndev)))
370 netif_start_queue(ndev);
371 cpts_tx_timestamp(&priv->cpts, skb);
372 priv->stats.tx_packets++;
373 priv->stats.tx_bytes += len;
374 dev_kfree_skb_any(skb);
377 void cpsw_rx_handler(void *token, int len, int status)
379 struct sk_buff *skb = token;
380 struct net_device *ndev = skb->dev;
381 struct cpsw_priv *priv = netdev_priv(ndev);
384 /* free and bail if we are shutting down */
385 if (unlikely(!netif_running(ndev)) ||
386 unlikely(!netif_carrier_ok(ndev))) {
387 dev_kfree_skb_any(skb);
390 if (likely(status >= 0)) {
392 cpts_rx_timestamp(&priv->cpts, skb);
393 skb->protocol = eth_type_trans(skb, ndev);
394 netif_receive_skb(skb);
395 priv->stats.rx_bytes += len;
396 priv->stats.rx_packets++;
400 if (unlikely(!netif_running(ndev))) {
402 dev_kfree_skb_any(skb);
407 skb = netdev_alloc_skb_ip_align(ndev, priv->rx_packet_max);
411 ret = cpdma_chan_submit(priv->rxch, skb, skb->data,
412 skb_tailroom(skb), GFP_KERNEL);
417 static irqreturn_t cpsw_interrupt(int irq, void *dev_id)
419 struct cpsw_priv *priv = dev_id;
421 if (likely(netif_running(priv->ndev))) {
422 cpsw_intr_disable(priv);
423 cpsw_disable_irq(priv);
424 napi_schedule(&priv->napi);
429 static inline int cpsw_get_slave_port(struct cpsw_priv *priv, u32 slave_num)
431 if (priv->host_port == 0)
432 return slave_num + 1;
437 static int cpsw_poll(struct napi_struct *napi, int budget)
439 struct cpsw_priv *priv = napi_to_priv(napi);
442 num_tx = cpdma_chan_process(priv->txch, 128);
443 num_rx = cpdma_chan_process(priv->rxch, budget);
445 if (num_rx || num_tx)
446 cpsw_dbg(priv, intr, "poll %d rx, %d tx pkts\n",
449 if (num_rx < budget) {
451 cpsw_intr_enable(priv);
452 cpdma_ctlr_eoi(priv->dma);
453 cpsw_enable_irq(priv);
459 static inline void soft_reset(const char *module, void __iomem *reg)
461 unsigned long timeout = jiffies + HZ;
463 __raw_writel(1, reg);
466 } while ((__raw_readl(reg) & 1) && time_after(timeout, jiffies));
468 WARN(__raw_readl(reg) & 1, "failed to soft-reset %s\n", module);
471 #define mac_hi(mac) (((mac)[0] << 0) | ((mac)[1] << 8) | \
472 ((mac)[2] << 16) | ((mac)[3] << 24))
473 #define mac_lo(mac) (((mac)[4] << 0) | ((mac)[5] << 8))
475 static void cpsw_set_slave_mac(struct cpsw_slave *slave,
476 struct cpsw_priv *priv)
478 slave_write(slave, mac_hi(priv->mac_addr), SA_HI);
479 slave_write(slave, mac_lo(priv->mac_addr), SA_LO);
482 static void _cpsw_adjust_link(struct cpsw_slave *slave,
483 struct cpsw_priv *priv, bool *link)
485 struct phy_device *phy = slave->phy;
492 slave_port = cpsw_get_slave_port(priv, slave->slave_num);
495 mac_control = priv->data.mac_control;
497 /* enable forwarding */
498 cpsw_ale_control_set(priv->ale, slave_port,
499 ALE_PORT_STATE, ALE_PORT_STATE_FORWARD);
501 if (phy->speed == 1000)
502 mac_control |= BIT(7); /* GIGABITEN */
504 mac_control |= BIT(0); /* FULLDUPLEXEN */
506 /* set speed_in input in case RMII mode is used in 100Mbps */
507 if (phy->speed == 100)
508 mac_control |= BIT(15);
513 /* disable forwarding */
514 cpsw_ale_control_set(priv->ale, slave_port,
515 ALE_PORT_STATE, ALE_PORT_STATE_DISABLE);
518 if (mac_control != slave->mac_control) {
519 phy_print_status(phy);
520 __raw_writel(mac_control, &slave->sliver->mac_control);
523 slave->mac_control = mac_control;
526 static void cpsw_adjust_link(struct net_device *ndev)
528 struct cpsw_priv *priv = netdev_priv(ndev);
531 for_each_slave(priv, _cpsw_adjust_link, priv, &link);
534 netif_carrier_on(ndev);
535 if (netif_running(ndev))
536 netif_wake_queue(ndev);
538 netif_carrier_off(ndev);
539 netif_stop_queue(ndev);
543 static inline int __show_stat(char *buf, int maxlen, const char *name, u32 val)
545 static char *leader = "........................................";
550 return snprintf(buf, maxlen, "%s %s %10d\n", name,
551 leader + strlen(name), val);
554 static void cpsw_slave_open(struct cpsw_slave *slave, struct cpsw_priv *priv)
559 sprintf(name, "slave-%d", slave->slave_num);
561 soft_reset(name, &slave->sliver->soft_reset);
563 /* setup priority mapping */
564 __raw_writel(RX_PRIORITY_MAPPING, &slave->sliver->rx_pri_map);
566 switch (priv->version) {
568 slave_write(slave, TX_PRIORITY_MAPPING, CPSW1_TX_PRI_MAP);
571 slave_write(slave, TX_PRIORITY_MAPPING, CPSW2_TX_PRI_MAP);
575 /* setup max packet size, and mac address */
576 __raw_writel(priv->rx_packet_max, &slave->sliver->rx_maxlen);
577 cpsw_set_slave_mac(slave, priv);
579 slave->mac_control = 0; /* no link yet */
581 slave_port = cpsw_get_slave_port(priv, slave->slave_num);
583 cpsw_ale_add_mcast(priv->ale, priv->ndev->broadcast,
584 1 << slave_port, 0, ALE_MCAST_FWD_2);
586 slave->phy = phy_connect(priv->ndev, slave->data->phy_id,
587 &cpsw_adjust_link, 0, slave->data->phy_if);
588 if (IS_ERR(slave->phy)) {
589 dev_err(priv->dev, "phy %s not found on slave %d\n",
590 slave->data->phy_id, slave->slave_num);
593 dev_info(priv->dev, "phy found : id is : 0x%x\n",
595 phy_start(slave->phy);
599 static void cpsw_init_host_port(struct cpsw_priv *priv)
601 /* soft reset the controller and initialize ale */
602 soft_reset("cpsw", &priv->regs->soft_reset);
603 cpsw_ale_start(priv->ale);
605 /* switch to vlan unaware mode */
606 cpsw_ale_control_set(priv->ale, 0, ALE_VLAN_AWARE, 0);
608 /* setup host port priority mapping */
609 __raw_writel(CPDMA_TX_PRIORITY_MAP,
610 &priv->host_port_regs->cpdma_tx_pri_map);
611 __raw_writel(0, &priv->host_port_regs->cpdma_rx_chan_map);
613 cpsw_ale_control_set(priv->ale, priv->host_port,
614 ALE_PORT_STATE, ALE_PORT_STATE_FORWARD);
616 cpsw_ale_add_ucast(priv->ale, priv->mac_addr, priv->host_port, 0);
617 cpsw_ale_add_mcast(priv->ale, priv->ndev->broadcast,
618 1 << priv->host_port, 0, ALE_MCAST_FWD_2);
621 static int cpsw_ndo_open(struct net_device *ndev)
623 struct cpsw_priv *priv = netdev_priv(ndev);
627 cpsw_intr_disable(priv);
628 netif_carrier_off(ndev);
630 pm_runtime_get_sync(&priv->pdev->dev);
632 reg = __raw_readl(&priv->regs->id_ver);
635 dev_info(priv->dev, "initializing cpsw version %d.%d (%d)\n",
636 CPSW_MAJOR_VERSION(reg), CPSW_MINOR_VERSION(reg),
637 CPSW_RTL_VERSION(reg));
639 /* initialize host and slave ports */
640 cpsw_init_host_port(priv);
641 for_each_slave(priv, cpsw_slave_open, priv);
643 /* setup tx dma to fixed prio and zero offset */
644 cpdma_control_set(priv->dma, CPDMA_TX_PRIO_FIXED, 1);
645 cpdma_control_set(priv->dma, CPDMA_RX_BUFFER_OFFSET, 0);
647 /* disable priority elevation and enable statistics on all ports */
648 __raw_writel(0, &priv->regs->ptype);
650 /* enable statistics collection only on the host port */
651 __raw_writel(0x7, &priv->regs->stat_port_en);
653 if (WARN_ON(!priv->data.rx_descs))
654 priv->data.rx_descs = 128;
656 for (i = 0; i < priv->data.rx_descs; i++) {
660 skb = netdev_alloc_skb_ip_align(priv->ndev,
661 priv->rx_packet_max);
664 ret = cpdma_chan_submit(priv->rxch, skb, skb->data,
665 skb_tailroom(skb), GFP_KERNEL);
666 if (WARN_ON(ret < 0))
669 /* continue even if we didn't manage to submit all receive descs */
670 cpsw_info(priv, ifup, "submitted %d rx descriptors\n", i);
672 cpdma_ctlr_start(priv->dma);
673 cpsw_intr_enable(priv);
674 napi_enable(&priv->napi);
675 cpdma_ctlr_eoi(priv->dma);
680 static void cpsw_slave_stop(struct cpsw_slave *slave, struct cpsw_priv *priv)
684 phy_stop(slave->phy);
685 phy_disconnect(slave->phy);
689 static int cpsw_ndo_stop(struct net_device *ndev)
691 struct cpsw_priv *priv = netdev_priv(ndev);
693 cpsw_info(priv, ifdown, "shutting down cpsw device\n");
694 cpsw_intr_disable(priv);
695 cpdma_ctlr_int_ctrl(priv->dma, false);
696 cpdma_ctlr_stop(priv->dma);
697 netif_stop_queue(priv->ndev);
698 napi_disable(&priv->napi);
699 netif_carrier_off(priv->ndev);
700 cpsw_ale_stop(priv->ale);
701 for_each_slave(priv, cpsw_slave_stop, priv);
702 pm_runtime_put_sync(&priv->pdev->dev);
706 static netdev_tx_t cpsw_ndo_start_xmit(struct sk_buff *skb,
707 struct net_device *ndev)
709 struct cpsw_priv *priv = netdev_priv(ndev);
712 ndev->trans_start = jiffies;
714 if (skb_padto(skb, CPSW_MIN_PACKET_SIZE)) {
715 cpsw_err(priv, tx_err, "packet pad failed\n");
716 priv->stats.tx_dropped++;
720 if (skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP && priv->cpts.tx_enable)
721 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
723 skb_tx_timestamp(skb);
725 ret = cpdma_chan_submit(priv->txch, skb, skb->data,
726 skb->len, GFP_KERNEL);
727 if (unlikely(ret != 0)) {
728 cpsw_err(priv, tx_err, "desc submit failed\n");
734 priv->stats.tx_dropped++;
735 netif_stop_queue(ndev);
736 return NETDEV_TX_BUSY;
739 static void cpsw_ndo_change_rx_flags(struct net_device *ndev, int flags)
742 * The switch cannot operate in promiscuous mode without substantial
743 * headache. For promiscuous mode to work, we would need to put the
744 * ALE in bypass mode and route all traffic to the host port.
745 * Subsequently, the host will need to operate as a "bridge", learn,
746 * and flood as needed. For now, we simply complain here and
747 * do nothing about it :-)
749 if ((flags & IFF_PROMISC) && (ndev->flags & IFF_PROMISC))
750 dev_err(&ndev->dev, "promiscuity ignored!\n");
753 * The switch cannot filter multicast traffic unless it is configured
754 * in "VLAN Aware" mode. Unfortunately, VLAN awareness requires a
755 * whole bunch of additional logic that this driver does not implement
758 if ((flags & IFF_ALLMULTI) && !(ndev->flags & IFF_ALLMULTI))
759 dev_err(&ndev->dev, "multicast traffic cannot be filtered!\n");
762 #ifdef CONFIG_TI_CPTS
764 static void cpsw_hwtstamp_v1(struct cpsw_priv *priv)
766 struct cpsw_slave *slave = &priv->slaves[priv->data.cpts_active_slave];
769 if (!priv->cpts.tx_enable && !priv->cpts.rx_enable) {
770 slave_write(slave, 0, CPSW1_TS_CTL);
774 seq_id = (30 << CPSW_V1_SEQ_ID_OFS_SHIFT) | ETH_P_1588;
775 ts_en = EVENT_MSG_BITS << CPSW_V1_MSG_TYPE_OFS;
777 if (priv->cpts.tx_enable)
778 ts_en |= CPSW_V1_TS_TX_EN;
780 if (priv->cpts.rx_enable)
781 ts_en |= CPSW_V1_TS_RX_EN;
783 slave_write(slave, ts_en, CPSW1_TS_CTL);
784 slave_write(slave, seq_id, CPSW1_TS_SEQ_LTYPE);
787 static void cpsw_hwtstamp_v2(struct cpsw_priv *priv)
789 struct cpsw_slave *slave = &priv->slaves[priv->data.cpts_active_slave];
792 ctrl = slave_read(slave, CPSW2_CONTROL);
793 ctrl &= ~CTRL_ALL_TS_MASK;
795 if (priv->cpts.tx_enable)
796 ctrl |= CTRL_TX_TS_BITS;
798 if (priv->cpts.rx_enable)
799 ctrl |= CTRL_RX_TS_BITS;
801 mtype = (30 << TS_SEQ_ID_OFFSET_SHIFT) | EVENT_MSG_BITS;
803 slave_write(slave, mtype, CPSW2_TS_SEQ_MTYPE);
804 slave_write(slave, ctrl, CPSW2_CONTROL);
805 __raw_writel(ETH_P_1588, &priv->regs->ts_ltype);
808 static int cpsw_hwtstamp_ioctl(struct cpsw_priv *priv, struct ifreq *ifr)
810 struct cpts *cpts = &priv->cpts;
811 struct hwtstamp_config cfg;
813 if (copy_from_user(&cfg, ifr->ifr_data, sizeof(cfg)))
816 /* reserved for future extensions */
820 switch (cfg.tx_type) {
821 case HWTSTAMP_TX_OFF:
831 switch (cfg.rx_filter) {
832 case HWTSTAMP_FILTER_NONE:
835 case HWTSTAMP_FILTER_ALL:
836 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
837 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
838 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
840 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
841 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
842 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
843 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
844 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
845 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
846 case HWTSTAMP_FILTER_PTP_V2_EVENT:
847 case HWTSTAMP_FILTER_PTP_V2_SYNC:
848 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
850 cfg.rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT;
856 switch (priv->version) {
858 cpsw_hwtstamp_v1(priv);
861 cpsw_hwtstamp_v2(priv);
867 return copy_to_user(ifr->ifr_data, &cfg, sizeof(cfg)) ? -EFAULT : 0;
870 #endif /*CONFIG_TI_CPTS*/
872 static int cpsw_ndo_ioctl(struct net_device *dev, struct ifreq *req, int cmd)
874 struct cpsw_priv *priv = netdev_priv(dev);
876 if (!netif_running(dev))
879 #ifdef CONFIG_TI_CPTS
880 if (cmd == SIOCSHWTSTAMP)
881 return cpsw_hwtstamp_ioctl(priv, req);
886 static void cpsw_ndo_tx_timeout(struct net_device *ndev)
888 struct cpsw_priv *priv = netdev_priv(ndev);
890 cpsw_err(priv, tx_err, "transmit timeout, restarting dma\n");
891 priv->stats.tx_errors++;
892 cpsw_intr_disable(priv);
893 cpdma_ctlr_int_ctrl(priv->dma, false);
894 cpdma_chan_stop(priv->txch);
895 cpdma_chan_start(priv->txch);
896 cpdma_ctlr_int_ctrl(priv->dma, true);
897 cpsw_intr_enable(priv);
898 cpdma_ctlr_eoi(priv->dma);
901 static struct net_device_stats *cpsw_ndo_get_stats(struct net_device *ndev)
903 struct cpsw_priv *priv = netdev_priv(ndev);
907 #ifdef CONFIG_NET_POLL_CONTROLLER
908 static void cpsw_ndo_poll_controller(struct net_device *ndev)
910 struct cpsw_priv *priv = netdev_priv(ndev);
912 cpsw_intr_disable(priv);
913 cpdma_ctlr_int_ctrl(priv->dma, false);
914 cpsw_interrupt(ndev->irq, priv);
915 cpdma_ctlr_int_ctrl(priv->dma, true);
916 cpsw_intr_enable(priv);
917 cpdma_ctlr_eoi(priv->dma);
921 static const struct net_device_ops cpsw_netdev_ops = {
922 .ndo_open = cpsw_ndo_open,
923 .ndo_stop = cpsw_ndo_stop,
924 .ndo_start_xmit = cpsw_ndo_start_xmit,
925 .ndo_change_rx_flags = cpsw_ndo_change_rx_flags,
926 .ndo_do_ioctl = cpsw_ndo_ioctl,
927 .ndo_validate_addr = eth_validate_addr,
928 .ndo_change_mtu = eth_change_mtu,
929 .ndo_tx_timeout = cpsw_ndo_tx_timeout,
930 .ndo_get_stats = cpsw_ndo_get_stats,
931 .ndo_set_rx_mode = cpsw_ndo_set_rx_mode,
932 #ifdef CONFIG_NET_POLL_CONTROLLER
933 .ndo_poll_controller = cpsw_ndo_poll_controller,
937 static void cpsw_get_drvinfo(struct net_device *ndev,
938 struct ethtool_drvinfo *info)
940 struct cpsw_priv *priv = netdev_priv(ndev);
941 strcpy(info->driver, "TI CPSW Driver v1.0");
942 strcpy(info->version, "1.0");
943 strcpy(info->bus_info, priv->pdev->name);
946 static u32 cpsw_get_msglevel(struct net_device *ndev)
948 struct cpsw_priv *priv = netdev_priv(ndev);
949 return priv->msg_enable;
952 static void cpsw_set_msglevel(struct net_device *ndev, u32 value)
954 struct cpsw_priv *priv = netdev_priv(ndev);
955 priv->msg_enable = value;
958 static int cpsw_get_ts_info(struct net_device *ndev,
959 struct ethtool_ts_info *info)
961 #ifdef CONFIG_TI_CPTS
962 struct cpsw_priv *priv = netdev_priv(ndev);
964 info->so_timestamping =
965 SOF_TIMESTAMPING_TX_HARDWARE |
966 SOF_TIMESTAMPING_TX_SOFTWARE |
967 SOF_TIMESTAMPING_RX_HARDWARE |
968 SOF_TIMESTAMPING_RX_SOFTWARE |
969 SOF_TIMESTAMPING_SOFTWARE |
970 SOF_TIMESTAMPING_RAW_HARDWARE;
971 info->phc_index = priv->cpts.phc_index;
973 (1 << HWTSTAMP_TX_OFF) |
974 (1 << HWTSTAMP_TX_ON);
976 (1 << HWTSTAMP_FILTER_NONE) |
977 (1 << HWTSTAMP_FILTER_PTP_V2_EVENT);
979 info->so_timestamping =
980 SOF_TIMESTAMPING_TX_SOFTWARE |
981 SOF_TIMESTAMPING_RX_SOFTWARE |
982 SOF_TIMESTAMPING_SOFTWARE;
983 info->phc_index = -1;
985 info->rx_filters = 0;
990 static const struct ethtool_ops cpsw_ethtool_ops = {
991 .get_drvinfo = cpsw_get_drvinfo,
992 .get_msglevel = cpsw_get_msglevel,
993 .set_msglevel = cpsw_set_msglevel,
994 .get_link = ethtool_op_get_link,
995 .get_ts_info = cpsw_get_ts_info,
998 static void cpsw_slave_init(struct cpsw_slave *slave, struct cpsw_priv *priv)
1000 void __iomem *regs = priv->regs;
1001 int slave_num = slave->slave_num;
1002 struct cpsw_slave_data *data = priv->data.slave_data + slave_num;
1005 slave->regs = regs + data->slave_reg_ofs;
1006 slave->sliver = regs + data->sliver_reg_ofs;
1009 static int cpsw_probe_dt(struct cpsw_platform_data *data,
1010 struct platform_device *pdev)
1012 struct device_node *node = pdev->dev.of_node;
1013 struct device_node *slave_node;
1020 if (of_property_read_u32(node, "slaves", &prop)) {
1021 pr_err("Missing slaves property in the DT.\n");
1024 data->slaves = prop;
1026 if (of_property_read_u32(node, "cpts_active_slave", &prop)) {
1027 pr_err("Missing cpts_active_slave property in the DT.\n");
1031 data->cpts_active_slave = prop;
1033 if (of_property_read_u32(node, "cpts_clock_mult", &prop)) {
1034 pr_err("Missing cpts_clock_mult property in the DT.\n");
1038 data->cpts_clock_mult = prop;
1040 if (of_property_read_u32(node, "cpts_clock_shift", &prop)) {
1041 pr_err("Missing cpts_clock_shift property in the DT.\n");
1045 data->cpts_clock_shift = prop;
1047 data->slave_data = kzalloc(sizeof(struct cpsw_slave_data) *
1048 data->slaves, GFP_KERNEL);
1049 if (!data->slave_data) {
1050 pr_err("Could not allocate slave memory.\n");
1054 data->no_bd_ram = of_property_read_bool(node, "no_bd_ram");
1056 if (of_property_read_u32(node, "cpdma_channels", &prop)) {
1057 pr_err("Missing cpdma_channels property in the DT.\n");
1061 data->channels = prop;
1063 if (of_property_read_u32(node, "host_port_no", &prop)) {
1064 pr_err("Missing host_port_no property in the DT.\n");
1068 data->host_port_num = prop;
1070 if (of_property_read_u32(node, "cpdma_reg_ofs", &prop)) {
1071 pr_err("Missing cpdma_reg_ofs property in the DT.\n");
1075 data->cpdma_reg_ofs = prop;
1077 if (of_property_read_u32(node, "cpdma_sram_ofs", &prop)) {
1078 pr_err("Missing cpdma_sram_ofs property in the DT.\n");
1082 data->cpdma_sram_ofs = prop;
1084 if (of_property_read_u32(node, "ale_reg_ofs", &prop)) {
1085 pr_err("Missing ale_reg_ofs property in the DT.\n");
1089 data->ale_reg_ofs = prop;
1091 if (of_property_read_u32(node, "ale_entries", &prop)) {
1092 pr_err("Missing ale_entries property in the DT.\n");
1096 data->ale_entries = prop;
1098 if (of_property_read_u32(node, "host_port_reg_ofs", &prop)) {
1099 pr_err("Missing host_port_reg_ofs property in the DT.\n");
1103 data->host_port_reg_ofs = prop;
1105 if (of_property_read_u32(node, "hw_stats_reg_ofs", &prop)) {
1106 pr_err("Missing hw_stats_reg_ofs property in the DT.\n");
1110 data->hw_stats_reg_ofs = prop;
1112 if (of_property_read_u32(node, "cpts_reg_ofs", &prop)) {
1113 pr_err("Missing cpts_reg_ofs property in the DT.\n");
1117 data->cpts_reg_ofs = prop;
1119 if (of_property_read_u32(node, "bd_ram_ofs", &prop)) {
1120 pr_err("Missing bd_ram_ofs property in the DT.\n");
1124 data->bd_ram_ofs = prop;
1126 if (of_property_read_u32(node, "bd_ram_size", &prop)) {
1127 pr_err("Missing bd_ram_size property in the DT.\n");
1131 data->bd_ram_size = prop;
1133 if (of_property_read_u32(node, "rx_descs", &prop)) {
1134 pr_err("Missing rx_descs property in the DT.\n");
1138 data->rx_descs = prop;
1140 if (of_property_read_u32(node, "mac_control", &prop)) {
1141 pr_err("Missing mac_control property in the DT.\n");
1145 data->mac_control = prop;
1147 for_each_node_by_name(slave_node, "slave") {
1148 struct cpsw_slave_data *slave_data = data->slave_data + i;
1149 const char *phy_id = NULL;
1150 const void *mac_addr = NULL;
1152 if (of_property_read_string(slave_node, "phy_id", &phy_id)) {
1153 pr_err("Missing slave[%d] phy_id property\n", i);
1157 slave_data->phy_id = phy_id;
1159 if (of_property_read_u32(slave_node, "slave_reg_ofs", &prop)) {
1160 pr_err("Missing slave[%d] slave_reg_ofs property\n", i);
1164 slave_data->slave_reg_ofs = prop;
1166 if (of_property_read_u32(slave_node, "sliver_reg_ofs",
1168 pr_err("Missing slave[%d] sliver_reg_ofs property\n",
1173 slave_data->sliver_reg_ofs = prop;
1175 mac_addr = of_get_mac_address(slave_node);
1177 memcpy(slave_data->mac_addr, mac_addr, ETH_ALEN);
1183 * Populate all the child nodes here...
1185 ret = of_platform_populate(node, NULL, NULL, &pdev->dev);
1186 /* We do not want to force this, as in some cases may not have child */
1188 pr_warn("Doesn't have any child node\n");
1193 kfree(data->slave_data);
1197 static int __devinit cpsw_probe(struct platform_device *pdev)
1199 struct cpsw_platform_data *data = pdev->dev.platform_data;
1200 struct net_device *ndev;
1201 struct cpsw_priv *priv;
1202 struct cpdma_params dma_params;
1203 struct cpsw_ale_params ale_params;
1205 struct resource *res;
1206 int ret = 0, i, k = 0;
1208 ndev = alloc_etherdev(sizeof(struct cpsw_priv));
1210 pr_err("error allocating net_device\n");
1214 platform_set_drvdata(pdev, ndev);
1215 priv = netdev_priv(ndev);
1216 spin_lock_init(&priv->lock);
1219 priv->dev = &ndev->dev;
1220 priv->msg_enable = netif_msg_init(debug_level, CPSW_DEBUG);
1221 priv->rx_packet_max = max(rx_packet_max, 128);
1224 * This may be required here for child devices.
1226 pm_runtime_enable(&pdev->dev);
1228 if (cpsw_probe_dt(&priv->data, pdev)) {
1229 pr_err("cpsw: platform data missing\n");
1231 goto clean_ndev_ret;
1235 if (is_valid_ether_addr(data->slave_data[0].mac_addr)) {
1236 memcpy(priv->mac_addr, data->slave_data[0].mac_addr, ETH_ALEN);
1237 pr_info("Detected MACID = %pM", priv->mac_addr);
1239 eth_random_addr(priv->mac_addr);
1240 pr_info("Random MACID = %pM", priv->mac_addr);
1243 memcpy(ndev->dev_addr, priv->mac_addr, ETH_ALEN);
1245 priv->slaves = kzalloc(sizeof(struct cpsw_slave) * data->slaves,
1247 if (!priv->slaves) {
1249 goto clean_ndev_ret;
1251 for (i = 0; i < data->slaves; i++)
1252 priv->slaves[i].slave_num = i;
1254 priv->clk = clk_get(&pdev->dev, "fck");
1255 if (IS_ERR(priv->clk)) {
1256 dev_err(&pdev->dev, "fck is not found\n");
1258 goto clean_slave_ret;
1261 priv->cpsw_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1262 if (!priv->cpsw_res) {
1263 dev_err(priv->dev, "error getting i/o resource\n");
1267 if (!request_mem_region(priv->cpsw_res->start,
1268 resource_size(priv->cpsw_res), ndev->name)) {
1269 dev_err(priv->dev, "failed request i/o region\n");
1273 regs = ioremap(priv->cpsw_res->start, resource_size(priv->cpsw_res));
1275 dev_err(priv->dev, "unable to map i/o region\n");
1276 goto clean_cpsw_iores_ret;
1279 priv->host_port = data->host_port_num;
1280 priv->host_port_regs = regs + data->host_port_reg_ofs;
1281 priv->cpts.reg = regs + data->cpts_reg_ofs;
1283 priv->cpsw_wr_res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
1284 if (!priv->cpsw_wr_res) {
1285 dev_err(priv->dev, "error getting i/o resource\n");
1287 goto clean_iomap_ret;
1289 if (!request_mem_region(priv->cpsw_wr_res->start,
1290 resource_size(priv->cpsw_wr_res), ndev->name)) {
1291 dev_err(priv->dev, "failed request i/o region\n");
1293 goto clean_iomap_ret;
1295 regs = ioremap(priv->cpsw_wr_res->start,
1296 resource_size(priv->cpsw_wr_res));
1298 dev_err(priv->dev, "unable to map i/o region\n");
1299 goto clean_cpsw_wr_iores_ret;
1301 priv->wr_regs = regs;
1303 for_each_slave(priv, cpsw_slave_init, priv);
1305 memset(&dma_params, 0, sizeof(dma_params));
1306 dma_params.dev = &pdev->dev;
1307 dma_params.dmaregs = cpsw_dma_regs((u32)priv->regs,
1308 data->cpdma_reg_ofs);
1309 dma_params.rxthresh = cpsw_dma_rxthresh((u32)priv->regs,
1310 data->cpdma_reg_ofs);
1311 dma_params.rxfree = cpsw_dma_rxfree((u32)priv->regs,
1312 data->cpdma_reg_ofs);
1313 dma_params.txhdp = cpsw_dma_txhdp((u32)priv->regs,
1314 data->cpdma_sram_ofs);
1315 dma_params.rxhdp = cpsw_dma_rxhdp((u32)priv->regs,
1316 data->cpdma_sram_ofs);
1317 dma_params.txcp = cpsw_dma_txcp((u32)priv->regs,
1318 data->cpdma_sram_ofs);
1319 dma_params.rxcp = cpsw_dma_rxcp((u32)priv->regs,
1320 data->cpdma_sram_ofs);
1322 dma_params.num_chan = data->channels;
1323 dma_params.has_soft_reset = true;
1324 dma_params.min_packet_size = CPSW_MIN_PACKET_SIZE;
1325 dma_params.desc_mem_size = data->bd_ram_size;
1326 dma_params.desc_align = 16;
1327 dma_params.has_ext_regs = true;
1328 dma_params.desc_mem_phys = data->no_bd_ram ? 0 :
1329 (u32 __force)priv->cpsw_res->start + data->bd_ram_ofs;
1330 dma_params.desc_hw_addr = data->hw_ram_addr ?
1331 data->hw_ram_addr : dma_params.desc_mem_phys ;
1333 priv->dma = cpdma_ctlr_create(&dma_params);
1335 dev_err(priv->dev, "error initializing dma\n");
1337 goto clean_wr_iomap_ret;
1340 priv->txch = cpdma_chan_create(priv->dma, tx_chan_num(0),
1342 priv->rxch = cpdma_chan_create(priv->dma, rx_chan_num(0),
1345 if (WARN_ON(!priv->txch || !priv->rxch)) {
1346 dev_err(priv->dev, "error initializing dma channels\n");
1351 memset(&ale_params, 0, sizeof(ale_params));
1352 ale_params.dev = &ndev->dev;
1353 ale_params.ale_regs = (void *)((u32)priv->regs) +
1354 ((u32)data->ale_reg_ofs);
1355 ale_params.ale_ageout = ale_ageout;
1356 ale_params.ale_entries = data->ale_entries;
1357 ale_params.ale_ports = data->slaves;
1359 priv->ale = cpsw_ale_create(&ale_params);
1361 dev_err(priv->dev, "error initializing ale engine\n");
1366 ndev->irq = platform_get_irq(pdev, 0);
1367 if (ndev->irq < 0) {
1368 dev_err(priv->dev, "error getting irq resource\n");
1373 while ((res = platform_get_resource(priv->pdev, IORESOURCE_IRQ, k))) {
1374 for (i = res->start; i <= res->end; i++) {
1375 if (request_irq(i, cpsw_interrupt, IRQF_DISABLED,
1376 dev_name(&pdev->dev), priv)) {
1377 dev_err(priv->dev, "error attaching irq\n");
1380 priv->irqs_table[k] = i;
1386 ndev->flags |= IFF_ALLMULTI; /* see cpsw_ndo_change_rx_flags() */
1388 ndev->netdev_ops = &cpsw_netdev_ops;
1389 SET_ETHTOOL_OPS(ndev, &cpsw_ethtool_ops);
1390 netif_napi_add(ndev, &priv->napi, cpsw_poll, CPSW_POLL_WEIGHT);
1392 /* register the network device */
1393 SET_NETDEV_DEV(ndev, &pdev->dev);
1394 ret = register_netdev(ndev);
1396 dev_err(priv->dev, "error registering net device\n");
1401 if (cpts_register(&pdev->dev, &priv->cpts,
1402 data->cpts_clock_mult, data->cpts_clock_shift))
1403 dev_err(priv->dev, "error registering cpts device\n");
1405 cpsw_notice(priv, probe, "initialized device (regs %x, irq %d)\n",
1406 priv->cpsw_res->start, ndev->irq);
1411 free_irq(ndev->irq, priv);
1413 cpsw_ale_destroy(priv->ale);
1415 cpdma_chan_destroy(priv->txch);
1416 cpdma_chan_destroy(priv->rxch);
1417 cpdma_ctlr_destroy(priv->dma);
1419 iounmap(priv->wr_regs);
1420 clean_cpsw_wr_iores_ret:
1421 release_mem_region(priv->cpsw_wr_res->start,
1422 resource_size(priv->cpsw_wr_res));
1424 iounmap(priv->regs);
1425 clean_cpsw_iores_ret:
1426 release_mem_region(priv->cpsw_res->start,
1427 resource_size(priv->cpsw_res));
1431 pm_runtime_disable(&pdev->dev);
1432 kfree(priv->slaves);
1438 static int __devexit cpsw_remove(struct platform_device *pdev)
1440 struct net_device *ndev = platform_get_drvdata(pdev);
1441 struct cpsw_priv *priv = netdev_priv(ndev);
1443 pr_info("removing device");
1444 platform_set_drvdata(pdev, NULL);
1446 cpts_unregister(&priv->cpts);
1447 free_irq(ndev->irq, priv);
1448 cpsw_ale_destroy(priv->ale);
1449 cpdma_chan_destroy(priv->txch);
1450 cpdma_chan_destroy(priv->rxch);
1451 cpdma_ctlr_destroy(priv->dma);
1452 iounmap(priv->regs);
1453 release_mem_region(priv->cpsw_res->start,
1454 resource_size(priv->cpsw_res));
1455 iounmap(priv->wr_regs);
1456 release_mem_region(priv->cpsw_wr_res->start,
1457 resource_size(priv->cpsw_wr_res));
1458 pm_runtime_disable(&pdev->dev);
1460 kfree(priv->slaves);
1466 static int cpsw_suspend(struct device *dev)
1468 struct platform_device *pdev = to_platform_device(dev);
1469 struct net_device *ndev = platform_get_drvdata(pdev);
1471 if (netif_running(ndev))
1472 cpsw_ndo_stop(ndev);
1473 pm_runtime_put_sync(&pdev->dev);
1478 static int cpsw_resume(struct device *dev)
1480 struct platform_device *pdev = to_platform_device(dev);
1481 struct net_device *ndev = platform_get_drvdata(pdev);
1483 pm_runtime_get_sync(&pdev->dev);
1484 if (netif_running(ndev))
1485 cpsw_ndo_open(ndev);
1489 static const struct dev_pm_ops cpsw_pm_ops = {
1490 .suspend = cpsw_suspend,
1491 .resume = cpsw_resume,
1494 static const struct of_device_id cpsw_of_mtable[] = {
1495 { .compatible = "ti,cpsw", },
1499 static struct platform_driver cpsw_driver = {
1502 .owner = THIS_MODULE,
1504 .of_match_table = of_match_ptr(cpsw_of_mtable),
1506 .probe = cpsw_probe,
1507 .remove = __devexit_p(cpsw_remove),
1510 static int __init cpsw_init(void)
1512 return platform_driver_register(&cpsw_driver);
1514 late_initcall(cpsw_init);
1516 static void __exit cpsw_exit(void)
1518 platform_driver_unregister(&cpsw_driver);
1520 module_exit(cpsw_exit);
1522 MODULE_LICENSE("GPL");
1523 MODULE_AUTHOR("Cyril Chemparathy <cyril@ti.com>");
1524 MODULE_AUTHOR("Mugunthan V N <mugunthanvnm@ti.com>");
1525 MODULE_DESCRIPTION("TI CPSW Ethernet driver");