Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Texas Instruments Ethernet Switch Driver |
| 3 | * |
| 4 | * Copyright (C) 2012 Texas Instruments |
| 5 | * |
| 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. |
| 9 | * |
| 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. |
| 14 | */ |
| 15 | |
| 16 | #include <linux/kernel.h> |
| 17 | #include <linux/io.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> |
Richard Cochran | 2e5b38a | 2012-10-29 08:45:20 +0000 | [diff] [blame] | 27 | #include <linux/net_tstamp.h> |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 28 | #include <linux/phy.h> |
| 29 | #include <linux/workqueue.h> |
| 30 | #include <linux/delay.h> |
Mugunthan V N | f150bd7 | 2012-07-17 08:09:50 +0000 | [diff] [blame] | 31 | #include <linux/pm_runtime.h> |
Mugunthan V N | 2eb32b0 | 2012-07-30 10:17:14 +0000 | [diff] [blame] | 32 | #include <linux/of.h> |
| 33 | #include <linux/of_net.h> |
| 34 | #include <linux/of_device.h> |
Mugunthan V N | 3b72c2f | 2013-02-05 08:26:48 +0000 | [diff] [blame^] | 35 | #include <linux/if_vlan.h> |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 36 | |
| 37 | #include <linux/platform_data/cpsw.h> |
| 38 | |
| 39 | #include "cpsw_ale.h" |
Richard Cochran | 2e5b38a | 2012-10-29 08:45:20 +0000 | [diff] [blame] | 40 | #include "cpts.h" |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 41 | #include "davinci_cpdma.h" |
| 42 | |
| 43 | #define CPSW_DEBUG (NETIF_MSG_HW | NETIF_MSG_WOL | \ |
| 44 | NETIF_MSG_DRV | NETIF_MSG_LINK | \ |
| 45 | NETIF_MSG_IFUP | NETIF_MSG_INTR | \ |
| 46 | NETIF_MSG_PROBE | NETIF_MSG_TIMER | \ |
| 47 | NETIF_MSG_IFDOWN | NETIF_MSG_RX_ERR | \ |
| 48 | NETIF_MSG_TX_ERR | NETIF_MSG_TX_DONE | \ |
| 49 | NETIF_MSG_PKTDATA | NETIF_MSG_TX_QUEUED | \ |
| 50 | NETIF_MSG_RX_STATUS) |
| 51 | |
| 52 | #define cpsw_info(priv, type, format, ...) \ |
| 53 | do { \ |
| 54 | if (netif_msg_##type(priv) && net_ratelimit()) \ |
| 55 | dev_info(priv->dev, format, ## __VA_ARGS__); \ |
| 56 | } while (0) |
| 57 | |
| 58 | #define cpsw_err(priv, type, format, ...) \ |
| 59 | do { \ |
| 60 | if (netif_msg_##type(priv) && net_ratelimit()) \ |
| 61 | dev_err(priv->dev, format, ## __VA_ARGS__); \ |
| 62 | } while (0) |
| 63 | |
| 64 | #define cpsw_dbg(priv, type, format, ...) \ |
| 65 | do { \ |
| 66 | if (netif_msg_##type(priv) && net_ratelimit()) \ |
| 67 | dev_dbg(priv->dev, format, ## __VA_ARGS__); \ |
| 68 | } while (0) |
| 69 | |
| 70 | #define cpsw_notice(priv, type, format, ...) \ |
| 71 | do { \ |
| 72 | if (netif_msg_##type(priv) && net_ratelimit()) \ |
| 73 | dev_notice(priv->dev, format, ## __VA_ARGS__); \ |
| 74 | } while (0) |
| 75 | |
Mugunthan V N | 5c50a85 | 2012-10-29 08:45:11 +0000 | [diff] [blame] | 76 | #define ALE_ALL_PORTS 0x7 |
| 77 | |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 78 | #define CPSW_MAJOR_VERSION(reg) (reg >> 8 & 0x7) |
| 79 | #define CPSW_MINOR_VERSION(reg) (reg & 0xff) |
| 80 | #define CPSW_RTL_VERSION(reg) ((reg >> 11) & 0x1f) |
| 81 | |
Richard Cochran | e90cfac | 2012-10-29 08:45:14 +0000 | [diff] [blame] | 82 | #define CPSW_VERSION_1 0x19010a |
| 83 | #define CPSW_VERSION_2 0x19010c |
Richard Cochran | 549985e | 2012-11-14 09:07:56 +0000 | [diff] [blame] | 84 | |
| 85 | #define HOST_PORT_NUM 0 |
| 86 | #define SLIVER_SIZE 0x40 |
| 87 | |
| 88 | #define CPSW1_HOST_PORT_OFFSET 0x028 |
| 89 | #define CPSW1_SLAVE_OFFSET 0x050 |
| 90 | #define CPSW1_SLAVE_SIZE 0x040 |
| 91 | #define CPSW1_CPDMA_OFFSET 0x100 |
| 92 | #define CPSW1_STATERAM_OFFSET 0x200 |
| 93 | #define CPSW1_CPTS_OFFSET 0x500 |
| 94 | #define CPSW1_ALE_OFFSET 0x600 |
| 95 | #define CPSW1_SLIVER_OFFSET 0x700 |
| 96 | |
| 97 | #define CPSW2_HOST_PORT_OFFSET 0x108 |
| 98 | #define CPSW2_SLAVE_OFFSET 0x200 |
| 99 | #define CPSW2_SLAVE_SIZE 0x100 |
| 100 | #define CPSW2_CPDMA_OFFSET 0x800 |
| 101 | #define CPSW2_STATERAM_OFFSET 0xa00 |
| 102 | #define CPSW2_CPTS_OFFSET 0xc00 |
| 103 | #define CPSW2_ALE_OFFSET 0xd00 |
| 104 | #define CPSW2_SLIVER_OFFSET 0xd80 |
| 105 | #define CPSW2_BD_OFFSET 0x2000 |
| 106 | |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 107 | #define CPDMA_RXTHRESH 0x0c0 |
| 108 | #define CPDMA_RXFREE 0x0e0 |
| 109 | #define CPDMA_TXHDP 0x00 |
| 110 | #define CPDMA_RXHDP 0x20 |
| 111 | #define CPDMA_TXCP 0x40 |
| 112 | #define CPDMA_RXCP 0x60 |
| 113 | |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 114 | #define CPSW_POLL_WEIGHT 64 |
| 115 | #define CPSW_MIN_PACKET_SIZE 60 |
| 116 | #define CPSW_MAX_PACKET_SIZE (1500 + 14 + 4 + 4) |
| 117 | |
| 118 | #define RX_PRIORITY_MAPPING 0x76543210 |
| 119 | #define TX_PRIORITY_MAPPING 0x33221100 |
| 120 | #define CPDMA_TX_PRIORITY_MAP 0x76543210 |
| 121 | |
Mugunthan V N | 3b72c2f | 2013-02-05 08:26:48 +0000 | [diff] [blame^] | 122 | #define CPSW_VLAN_AWARE BIT(1) |
| 123 | #define CPSW_ALE_VLAN_AWARE 1 |
| 124 | |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 125 | #define cpsw_enable_irq(priv) \ |
| 126 | do { \ |
| 127 | u32 i; \ |
| 128 | for (i = 0; i < priv->num_irqs; i++) \ |
| 129 | enable_irq(priv->irqs_table[i]); \ |
| 130 | } while (0); |
| 131 | #define cpsw_disable_irq(priv) \ |
| 132 | do { \ |
| 133 | u32 i; \ |
| 134 | for (i = 0; i < priv->num_irqs; i++) \ |
| 135 | disable_irq_nosync(priv->irqs_table[i]); \ |
| 136 | } while (0); |
| 137 | |
| 138 | static int debug_level; |
| 139 | module_param(debug_level, int, 0); |
| 140 | MODULE_PARM_DESC(debug_level, "cpsw debug level (NETIF_MSG bits)"); |
| 141 | |
| 142 | static int ale_ageout = 10; |
| 143 | module_param(ale_ageout, int, 0); |
| 144 | MODULE_PARM_DESC(ale_ageout, "cpsw ale ageout interval (seconds)"); |
| 145 | |
| 146 | static int rx_packet_max = CPSW_MAX_PACKET_SIZE; |
| 147 | module_param(rx_packet_max, int, 0); |
| 148 | MODULE_PARM_DESC(rx_packet_max, "maximum receive packet size (bytes)"); |
| 149 | |
Richard Cochran | 996a5c2 | 2012-10-29 08:45:12 +0000 | [diff] [blame] | 150 | struct cpsw_wr_regs { |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 151 | u32 id_ver; |
| 152 | u32 soft_reset; |
| 153 | u32 control; |
| 154 | u32 int_control; |
| 155 | u32 rx_thresh_en; |
| 156 | u32 rx_en; |
| 157 | u32 tx_en; |
| 158 | u32 misc_en; |
| 159 | }; |
| 160 | |
Richard Cochran | 996a5c2 | 2012-10-29 08:45:12 +0000 | [diff] [blame] | 161 | struct cpsw_ss_regs { |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 162 | u32 id_ver; |
| 163 | u32 control; |
| 164 | u32 soft_reset; |
| 165 | u32 stat_port_en; |
| 166 | u32 ptype; |
Richard Cochran | bd357af | 2012-10-29 08:45:13 +0000 | [diff] [blame] | 167 | u32 soft_idle; |
| 168 | u32 thru_rate; |
| 169 | u32 gap_thresh; |
| 170 | u32 tx_start_wds; |
| 171 | u32 flow_control; |
| 172 | u32 vlan_ltype; |
| 173 | u32 ts_ltype; |
| 174 | u32 dlr_ltype; |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 175 | }; |
| 176 | |
Richard Cochran | 9750a3a | 2012-10-29 08:45:15 +0000 | [diff] [blame] | 177 | /* CPSW_PORT_V1 */ |
| 178 | #define CPSW1_MAX_BLKS 0x00 /* Maximum FIFO Blocks */ |
| 179 | #define CPSW1_BLK_CNT 0x04 /* FIFO Block Usage Count (Read Only) */ |
| 180 | #define CPSW1_TX_IN_CTL 0x08 /* Transmit FIFO Control */ |
| 181 | #define CPSW1_PORT_VLAN 0x0c /* VLAN Register */ |
| 182 | #define CPSW1_TX_PRI_MAP 0x10 /* Tx Header Priority to Switch Pri Mapping */ |
| 183 | #define CPSW1_TS_CTL 0x14 /* Time Sync Control */ |
| 184 | #define CPSW1_TS_SEQ_LTYPE 0x18 /* Time Sync Sequence ID Offset and Msg Type */ |
| 185 | #define CPSW1_TS_VLAN 0x1c /* Time Sync VLAN1 and VLAN2 */ |
| 186 | |
| 187 | /* CPSW_PORT_V2 */ |
| 188 | #define CPSW2_CONTROL 0x00 /* Control Register */ |
| 189 | #define CPSW2_MAX_BLKS 0x08 /* Maximum FIFO Blocks */ |
| 190 | #define CPSW2_BLK_CNT 0x0c /* FIFO Block Usage Count (Read Only) */ |
| 191 | #define CPSW2_TX_IN_CTL 0x10 /* Transmit FIFO Control */ |
| 192 | #define CPSW2_PORT_VLAN 0x14 /* VLAN Register */ |
| 193 | #define CPSW2_TX_PRI_MAP 0x18 /* Tx Header Priority to Switch Pri Mapping */ |
| 194 | #define CPSW2_TS_SEQ_MTYPE 0x1c /* Time Sync Sequence ID Offset and Msg Type */ |
| 195 | |
| 196 | /* CPSW_PORT_V1 and V2 */ |
| 197 | #define SA_LO 0x20 /* CPGMAC_SL Source Address Low */ |
| 198 | #define SA_HI 0x24 /* CPGMAC_SL Source Address High */ |
| 199 | #define SEND_PERCENT 0x28 /* Transmit Queue Send Percentages */ |
| 200 | |
| 201 | /* CPSW_PORT_V2 only */ |
| 202 | #define RX_DSCP_PRI_MAP0 0x30 /* Rx DSCP Priority to Rx Packet Mapping */ |
| 203 | #define RX_DSCP_PRI_MAP1 0x34 /* Rx DSCP Priority to Rx Packet Mapping */ |
| 204 | #define RX_DSCP_PRI_MAP2 0x38 /* Rx DSCP Priority to Rx Packet Mapping */ |
| 205 | #define RX_DSCP_PRI_MAP3 0x3c /* Rx DSCP Priority to Rx Packet Mapping */ |
| 206 | #define RX_DSCP_PRI_MAP4 0x40 /* Rx DSCP Priority to Rx Packet Mapping */ |
| 207 | #define RX_DSCP_PRI_MAP5 0x44 /* Rx DSCP Priority to Rx Packet Mapping */ |
| 208 | #define RX_DSCP_PRI_MAP6 0x48 /* Rx DSCP Priority to Rx Packet Mapping */ |
| 209 | #define RX_DSCP_PRI_MAP7 0x4c /* Rx DSCP Priority to Rx Packet Mapping */ |
| 210 | |
| 211 | /* Bit definitions for the CPSW2_CONTROL register */ |
| 212 | #define PASS_PRI_TAGGED (1<<24) /* Pass Priority Tagged */ |
| 213 | #define VLAN_LTYPE2_EN (1<<21) /* VLAN LTYPE 2 enable */ |
| 214 | #define VLAN_LTYPE1_EN (1<<20) /* VLAN LTYPE 1 enable */ |
| 215 | #define DSCP_PRI_EN (1<<16) /* DSCP Priority Enable */ |
| 216 | #define TS_320 (1<<14) /* Time Sync Dest Port 320 enable */ |
| 217 | #define TS_319 (1<<13) /* Time Sync Dest Port 319 enable */ |
| 218 | #define TS_132 (1<<12) /* Time Sync Dest IP Addr 132 enable */ |
| 219 | #define TS_131 (1<<11) /* Time Sync Dest IP Addr 131 enable */ |
| 220 | #define TS_130 (1<<10) /* Time Sync Dest IP Addr 130 enable */ |
| 221 | #define TS_129 (1<<9) /* Time Sync Dest IP Addr 129 enable */ |
| 222 | #define TS_BIT8 (1<<8) /* ts_ttl_nonzero? */ |
| 223 | #define TS_ANNEX_D_EN (1<<4) /* Time Sync Annex D enable */ |
| 224 | #define TS_LTYPE2_EN (1<<3) /* Time Sync LTYPE 2 enable */ |
| 225 | #define TS_LTYPE1_EN (1<<2) /* Time Sync LTYPE 1 enable */ |
| 226 | #define TS_TX_EN (1<<1) /* Time Sync Transmit Enable */ |
| 227 | #define TS_RX_EN (1<<0) /* Time Sync Receive Enable */ |
| 228 | |
| 229 | #define CTRL_TS_BITS \ |
| 230 | (TS_320 | TS_319 | TS_132 | TS_131 | TS_130 | TS_129 | TS_BIT8 | \ |
| 231 | TS_ANNEX_D_EN | TS_LTYPE1_EN) |
| 232 | |
| 233 | #define CTRL_ALL_TS_MASK (CTRL_TS_BITS | TS_TX_EN | TS_RX_EN) |
| 234 | #define CTRL_TX_TS_BITS (CTRL_TS_BITS | TS_TX_EN) |
| 235 | #define CTRL_RX_TS_BITS (CTRL_TS_BITS | TS_RX_EN) |
| 236 | |
| 237 | /* Bit definitions for the CPSW2_TS_SEQ_MTYPE register */ |
| 238 | #define TS_SEQ_ID_OFFSET_SHIFT (16) /* Time Sync Sequence ID Offset */ |
| 239 | #define TS_SEQ_ID_OFFSET_MASK (0x3f) |
| 240 | #define TS_MSG_TYPE_EN_SHIFT (0) /* Time Sync Message Type Enable */ |
| 241 | #define TS_MSG_TYPE_EN_MASK (0xffff) |
| 242 | |
| 243 | /* The PTP event messages - Sync, Delay_Req, Pdelay_Req, and Pdelay_Resp. */ |
| 244 | #define EVENT_MSG_BITS ((1<<0) | (1<<1) | (1<<2) | (1<<3)) |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 245 | |
Richard Cochran | 2e5b38a | 2012-10-29 08:45:20 +0000 | [diff] [blame] | 246 | /* Bit definitions for the CPSW1_TS_CTL register */ |
| 247 | #define CPSW_V1_TS_RX_EN BIT(0) |
| 248 | #define CPSW_V1_TS_TX_EN BIT(4) |
| 249 | #define CPSW_V1_MSG_TYPE_OFS 16 |
| 250 | |
| 251 | /* Bit definitions for the CPSW1_TS_SEQ_LTYPE register */ |
| 252 | #define CPSW_V1_SEQ_ID_OFS_SHIFT 16 |
| 253 | |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 254 | struct cpsw_host_regs { |
| 255 | u32 max_blks; |
| 256 | u32 blk_cnt; |
| 257 | u32 flow_thresh; |
| 258 | u32 port_vlan; |
| 259 | u32 tx_pri_map; |
| 260 | u32 cpdma_tx_pri_map; |
| 261 | u32 cpdma_rx_chan_map; |
| 262 | }; |
| 263 | |
| 264 | struct cpsw_sliver_regs { |
| 265 | u32 id_ver; |
| 266 | u32 mac_control; |
| 267 | u32 mac_status; |
| 268 | u32 soft_reset; |
| 269 | u32 rx_maxlen; |
| 270 | u32 __reserved_0; |
| 271 | u32 rx_pause; |
| 272 | u32 tx_pause; |
| 273 | u32 __reserved_1; |
| 274 | u32 rx_pri_map; |
| 275 | }; |
| 276 | |
| 277 | struct cpsw_slave { |
Richard Cochran | 9750a3a | 2012-10-29 08:45:15 +0000 | [diff] [blame] | 278 | void __iomem *regs; |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 279 | struct cpsw_sliver_regs __iomem *sliver; |
| 280 | int slave_num; |
| 281 | u32 mac_control; |
| 282 | struct cpsw_slave_data *data; |
| 283 | struct phy_device *phy; |
| 284 | }; |
| 285 | |
Richard Cochran | 9750a3a | 2012-10-29 08:45:15 +0000 | [diff] [blame] | 286 | static inline u32 slave_read(struct cpsw_slave *slave, u32 offset) |
| 287 | { |
| 288 | return __raw_readl(slave->regs + offset); |
| 289 | } |
| 290 | |
| 291 | static inline void slave_write(struct cpsw_slave *slave, u32 val, u32 offset) |
| 292 | { |
| 293 | __raw_writel(val, slave->regs + offset); |
| 294 | } |
| 295 | |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 296 | struct cpsw_priv { |
| 297 | spinlock_t lock; |
| 298 | struct platform_device *pdev; |
| 299 | struct net_device *ndev; |
| 300 | struct resource *cpsw_res; |
Richard Cochran | a65dd5b | 2012-11-02 22:25:29 +0000 | [diff] [blame] | 301 | struct resource *cpsw_wr_res; |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 302 | struct napi_struct napi; |
| 303 | struct device *dev; |
| 304 | struct cpsw_platform_data data; |
Richard Cochran | 996a5c2 | 2012-10-29 08:45:12 +0000 | [diff] [blame] | 305 | struct cpsw_ss_regs __iomem *regs; |
| 306 | struct cpsw_wr_regs __iomem *wr_regs; |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 307 | struct cpsw_host_regs __iomem *host_port_regs; |
| 308 | u32 msg_enable; |
Richard Cochran | e90cfac | 2012-10-29 08:45:14 +0000 | [diff] [blame] | 309 | u32 version; |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 310 | struct net_device_stats stats; |
| 311 | int rx_packet_max; |
| 312 | int host_port; |
| 313 | struct clk *clk; |
| 314 | u8 mac_addr[ETH_ALEN]; |
| 315 | struct cpsw_slave *slaves; |
| 316 | struct cpdma_ctlr *dma; |
| 317 | struct cpdma_chan *txch, *rxch; |
| 318 | struct cpsw_ale *ale; |
| 319 | /* snapshot of IRQ numbers */ |
| 320 | u32 irqs_table[4]; |
| 321 | u32 num_irqs; |
Richard Cochran | 2e5b38a | 2012-10-29 08:45:20 +0000 | [diff] [blame] | 322 | struct cpts cpts; |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 323 | }; |
| 324 | |
| 325 | #define napi_to_priv(napi) container_of(napi, struct cpsw_priv, napi) |
| 326 | #define for_each_slave(priv, func, arg...) \ |
| 327 | do { \ |
| 328 | int idx; \ |
| 329 | for (idx = 0; idx < (priv)->data.slaves; idx++) \ |
| 330 | (func)((priv)->slaves + idx, ##arg); \ |
| 331 | } while (0) |
| 332 | |
Mugunthan V N | 5c50a85 | 2012-10-29 08:45:11 +0000 | [diff] [blame] | 333 | static void cpsw_ndo_set_rx_mode(struct net_device *ndev) |
| 334 | { |
| 335 | struct cpsw_priv *priv = netdev_priv(ndev); |
| 336 | |
| 337 | if (ndev->flags & IFF_PROMISC) { |
| 338 | /* Enable promiscuous mode */ |
| 339 | dev_err(priv->dev, "Ignoring Promiscuous mode\n"); |
| 340 | return; |
| 341 | } |
| 342 | |
| 343 | /* Clear all mcast from ALE */ |
| 344 | cpsw_ale_flush_multicast(priv->ale, ALE_ALL_PORTS << priv->host_port); |
| 345 | |
| 346 | if (!netdev_mc_empty(ndev)) { |
| 347 | struct netdev_hw_addr *ha; |
| 348 | |
| 349 | /* program multicast address list into ALE register */ |
| 350 | netdev_for_each_mc_addr(ha, ndev) { |
| 351 | cpsw_ale_add_mcast(priv->ale, (u8 *)ha->addr, |
Mugunthan V N | e11b220 | 2013-02-05 08:26:47 +0000 | [diff] [blame] | 352 | ALE_ALL_PORTS << priv->host_port, 0, 0, 0); |
Mugunthan V N | 5c50a85 | 2012-10-29 08:45:11 +0000 | [diff] [blame] | 353 | } |
| 354 | } |
| 355 | } |
| 356 | |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 357 | static void cpsw_intr_enable(struct cpsw_priv *priv) |
| 358 | { |
Richard Cochran | 996a5c2 | 2012-10-29 08:45:12 +0000 | [diff] [blame] | 359 | __raw_writel(0xFF, &priv->wr_regs->tx_en); |
| 360 | __raw_writel(0xFF, &priv->wr_regs->rx_en); |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 361 | |
| 362 | cpdma_ctlr_int_ctrl(priv->dma, true); |
| 363 | return; |
| 364 | } |
| 365 | |
| 366 | static void cpsw_intr_disable(struct cpsw_priv *priv) |
| 367 | { |
Richard Cochran | 996a5c2 | 2012-10-29 08:45:12 +0000 | [diff] [blame] | 368 | __raw_writel(0, &priv->wr_regs->tx_en); |
| 369 | __raw_writel(0, &priv->wr_regs->rx_en); |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 370 | |
| 371 | cpdma_ctlr_int_ctrl(priv->dma, false); |
| 372 | return; |
| 373 | } |
| 374 | |
| 375 | void cpsw_tx_handler(void *token, int len, int status) |
| 376 | { |
| 377 | struct sk_buff *skb = token; |
| 378 | struct net_device *ndev = skb->dev; |
| 379 | struct cpsw_priv *priv = netdev_priv(ndev); |
| 380 | |
Mugunthan V N | fae5082 | 2013-01-17 06:31:34 +0000 | [diff] [blame] | 381 | /* Check whether the queue is stopped due to stalled tx dma, if the |
| 382 | * queue is stopped then start the queue as we have free desc for tx |
| 383 | */ |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 384 | if (unlikely(netif_queue_stopped(ndev))) |
| 385 | netif_start_queue(ndev); |
Richard Cochran | 2e5b38a | 2012-10-29 08:45:20 +0000 | [diff] [blame] | 386 | cpts_tx_timestamp(&priv->cpts, skb); |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 387 | priv->stats.tx_packets++; |
| 388 | priv->stats.tx_bytes += len; |
| 389 | dev_kfree_skb_any(skb); |
| 390 | } |
| 391 | |
| 392 | void cpsw_rx_handler(void *token, int len, int status) |
| 393 | { |
| 394 | struct sk_buff *skb = token; |
| 395 | struct net_device *ndev = skb->dev; |
| 396 | struct cpsw_priv *priv = netdev_priv(ndev); |
| 397 | int ret = 0; |
| 398 | |
| 399 | /* free and bail if we are shutting down */ |
| 400 | if (unlikely(!netif_running(ndev)) || |
| 401 | unlikely(!netif_carrier_ok(ndev))) { |
| 402 | dev_kfree_skb_any(skb); |
| 403 | return; |
| 404 | } |
| 405 | if (likely(status >= 0)) { |
| 406 | skb_put(skb, len); |
Richard Cochran | 2e5b38a | 2012-10-29 08:45:20 +0000 | [diff] [blame] | 407 | cpts_rx_timestamp(&priv->cpts, skb); |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 408 | skb->protocol = eth_type_trans(skb, ndev); |
| 409 | netif_receive_skb(skb); |
| 410 | priv->stats.rx_bytes += len; |
| 411 | priv->stats.rx_packets++; |
| 412 | skb = NULL; |
| 413 | } |
| 414 | |
| 415 | if (unlikely(!netif_running(ndev))) { |
| 416 | if (skb) |
| 417 | dev_kfree_skb_any(skb); |
| 418 | return; |
| 419 | } |
| 420 | |
| 421 | if (likely(!skb)) { |
| 422 | skb = netdev_alloc_skb_ip_align(ndev, priv->rx_packet_max); |
| 423 | if (WARN_ON(!skb)) |
| 424 | return; |
| 425 | |
| 426 | ret = cpdma_chan_submit(priv->rxch, skb, skb->data, |
| 427 | skb_tailroom(skb), GFP_KERNEL); |
| 428 | } |
| 429 | WARN_ON(ret < 0); |
| 430 | } |
| 431 | |
| 432 | static irqreturn_t cpsw_interrupt(int irq, void *dev_id) |
| 433 | { |
| 434 | struct cpsw_priv *priv = dev_id; |
| 435 | |
| 436 | if (likely(netif_running(priv->ndev))) { |
| 437 | cpsw_intr_disable(priv); |
| 438 | cpsw_disable_irq(priv); |
| 439 | napi_schedule(&priv->napi); |
| 440 | } |
| 441 | return IRQ_HANDLED; |
| 442 | } |
| 443 | |
| 444 | static inline int cpsw_get_slave_port(struct cpsw_priv *priv, u32 slave_num) |
| 445 | { |
| 446 | if (priv->host_port == 0) |
| 447 | return slave_num + 1; |
| 448 | else |
| 449 | return slave_num; |
| 450 | } |
| 451 | |
| 452 | static int cpsw_poll(struct napi_struct *napi, int budget) |
| 453 | { |
| 454 | struct cpsw_priv *priv = napi_to_priv(napi); |
| 455 | int num_tx, num_rx; |
| 456 | |
| 457 | num_tx = cpdma_chan_process(priv->txch, 128); |
| 458 | num_rx = cpdma_chan_process(priv->rxch, budget); |
| 459 | |
| 460 | if (num_rx || num_tx) |
| 461 | cpsw_dbg(priv, intr, "poll %d rx, %d tx pkts\n", |
| 462 | num_rx, num_tx); |
| 463 | |
| 464 | if (num_rx < budget) { |
| 465 | napi_complete(napi); |
| 466 | cpsw_intr_enable(priv); |
| 467 | cpdma_ctlr_eoi(priv->dma); |
| 468 | cpsw_enable_irq(priv); |
| 469 | } |
| 470 | |
| 471 | return num_rx; |
| 472 | } |
| 473 | |
| 474 | static inline void soft_reset(const char *module, void __iomem *reg) |
| 475 | { |
| 476 | unsigned long timeout = jiffies + HZ; |
| 477 | |
| 478 | __raw_writel(1, reg); |
| 479 | do { |
| 480 | cpu_relax(); |
| 481 | } while ((__raw_readl(reg) & 1) && time_after(timeout, jiffies)); |
| 482 | |
| 483 | WARN(__raw_readl(reg) & 1, "failed to soft-reset %s\n", module); |
| 484 | } |
| 485 | |
| 486 | #define mac_hi(mac) (((mac)[0] << 0) | ((mac)[1] << 8) | \ |
| 487 | ((mac)[2] << 16) | ((mac)[3] << 24)) |
| 488 | #define mac_lo(mac) (((mac)[4] << 0) | ((mac)[5] << 8)) |
| 489 | |
| 490 | static void cpsw_set_slave_mac(struct cpsw_slave *slave, |
| 491 | struct cpsw_priv *priv) |
| 492 | { |
Richard Cochran | 9750a3a | 2012-10-29 08:45:15 +0000 | [diff] [blame] | 493 | slave_write(slave, mac_hi(priv->mac_addr), SA_HI); |
| 494 | slave_write(slave, mac_lo(priv->mac_addr), SA_LO); |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 495 | } |
| 496 | |
| 497 | static void _cpsw_adjust_link(struct cpsw_slave *slave, |
| 498 | struct cpsw_priv *priv, bool *link) |
| 499 | { |
| 500 | struct phy_device *phy = slave->phy; |
| 501 | u32 mac_control = 0; |
| 502 | u32 slave_port; |
| 503 | |
| 504 | if (!phy) |
| 505 | return; |
| 506 | |
| 507 | slave_port = cpsw_get_slave_port(priv, slave->slave_num); |
| 508 | |
| 509 | if (phy->link) { |
| 510 | mac_control = priv->data.mac_control; |
| 511 | |
| 512 | /* enable forwarding */ |
| 513 | cpsw_ale_control_set(priv->ale, slave_port, |
| 514 | ALE_PORT_STATE, ALE_PORT_STATE_FORWARD); |
| 515 | |
| 516 | if (phy->speed == 1000) |
| 517 | mac_control |= BIT(7); /* GIGABITEN */ |
| 518 | if (phy->duplex) |
| 519 | mac_control |= BIT(0); /* FULLDUPLEXEN */ |
Daniel Mack | 342b7b7 | 2012-09-27 09:19:34 +0000 | [diff] [blame] | 520 | |
| 521 | /* set speed_in input in case RMII mode is used in 100Mbps */ |
| 522 | if (phy->speed == 100) |
| 523 | mac_control |= BIT(15); |
| 524 | |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 525 | *link = true; |
| 526 | } else { |
| 527 | mac_control = 0; |
| 528 | /* disable forwarding */ |
| 529 | cpsw_ale_control_set(priv->ale, slave_port, |
| 530 | ALE_PORT_STATE, ALE_PORT_STATE_DISABLE); |
| 531 | } |
| 532 | |
| 533 | if (mac_control != slave->mac_control) { |
| 534 | phy_print_status(phy); |
| 535 | __raw_writel(mac_control, &slave->sliver->mac_control); |
| 536 | } |
| 537 | |
| 538 | slave->mac_control = mac_control; |
| 539 | } |
| 540 | |
| 541 | static void cpsw_adjust_link(struct net_device *ndev) |
| 542 | { |
| 543 | struct cpsw_priv *priv = netdev_priv(ndev); |
| 544 | bool link = false; |
| 545 | |
| 546 | for_each_slave(priv, _cpsw_adjust_link, priv, &link); |
| 547 | |
| 548 | if (link) { |
| 549 | netif_carrier_on(ndev); |
| 550 | if (netif_running(ndev)) |
| 551 | netif_wake_queue(ndev); |
| 552 | } else { |
| 553 | netif_carrier_off(ndev); |
| 554 | netif_stop_queue(ndev); |
| 555 | } |
| 556 | } |
| 557 | |
| 558 | static inline int __show_stat(char *buf, int maxlen, const char *name, u32 val) |
| 559 | { |
| 560 | static char *leader = "........................................"; |
| 561 | |
| 562 | if (!val) |
| 563 | return 0; |
| 564 | else |
| 565 | return snprintf(buf, maxlen, "%s %s %10d\n", name, |
| 566 | leader + strlen(name), val); |
| 567 | } |
| 568 | |
| 569 | static void cpsw_slave_open(struct cpsw_slave *slave, struct cpsw_priv *priv) |
| 570 | { |
| 571 | char name[32]; |
| 572 | u32 slave_port; |
| 573 | |
| 574 | sprintf(name, "slave-%d", slave->slave_num); |
| 575 | |
| 576 | soft_reset(name, &slave->sliver->soft_reset); |
| 577 | |
| 578 | /* setup priority mapping */ |
| 579 | __raw_writel(RX_PRIORITY_MAPPING, &slave->sliver->rx_pri_map); |
Richard Cochran | 9750a3a | 2012-10-29 08:45:15 +0000 | [diff] [blame] | 580 | |
| 581 | switch (priv->version) { |
| 582 | case CPSW_VERSION_1: |
| 583 | slave_write(slave, TX_PRIORITY_MAPPING, CPSW1_TX_PRI_MAP); |
| 584 | break; |
| 585 | case CPSW_VERSION_2: |
| 586 | slave_write(slave, TX_PRIORITY_MAPPING, CPSW2_TX_PRI_MAP); |
| 587 | break; |
| 588 | } |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 589 | |
| 590 | /* setup max packet size, and mac address */ |
| 591 | __raw_writel(priv->rx_packet_max, &slave->sliver->rx_maxlen); |
| 592 | cpsw_set_slave_mac(slave, priv); |
| 593 | |
| 594 | slave->mac_control = 0; /* no link yet */ |
| 595 | |
| 596 | slave_port = cpsw_get_slave_port(priv, slave->slave_num); |
| 597 | |
| 598 | cpsw_ale_add_mcast(priv->ale, priv->ndev->broadcast, |
Mugunthan V N | e11b220 | 2013-02-05 08:26:47 +0000 | [diff] [blame] | 599 | 1 << slave_port, 0, 0, ALE_MCAST_FWD_2); |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 600 | |
| 601 | slave->phy = phy_connect(priv->ndev, slave->data->phy_id, |
Florian Fainelli | f9a8f83 | 2013-01-14 00:52:52 +0000 | [diff] [blame] | 602 | &cpsw_adjust_link, slave->data->phy_if); |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 603 | if (IS_ERR(slave->phy)) { |
| 604 | dev_err(priv->dev, "phy %s not found on slave %d\n", |
| 605 | slave->data->phy_id, slave->slave_num); |
| 606 | slave->phy = NULL; |
| 607 | } else { |
| 608 | dev_info(priv->dev, "phy found : id is : 0x%x\n", |
| 609 | slave->phy->phy_id); |
| 610 | phy_start(slave->phy); |
| 611 | } |
| 612 | } |
| 613 | |
Mugunthan V N | 3b72c2f | 2013-02-05 08:26:48 +0000 | [diff] [blame^] | 614 | static inline void cpsw_add_default_vlan(struct cpsw_priv *priv) |
| 615 | { |
| 616 | const int vlan = priv->data.default_vlan; |
| 617 | const int port = priv->host_port; |
| 618 | u32 reg; |
| 619 | int i; |
| 620 | |
| 621 | reg = (priv->version == CPSW_VERSION_1) ? CPSW1_PORT_VLAN : |
| 622 | CPSW2_PORT_VLAN; |
| 623 | |
| 624 | writel(vlan, &priv->host_port_regs->port_vlan); |
| 625 | |
| 626 | for (i = 0; i < 2; i++) |
| 627 | slave_write(priv->slaves + i, vlan, reg); |
| 628 | |
| 629 | cpsw_ale_add_vlan(priv->ale, vlan, ALE_ALL_PORTS << port, |
| 630 | ALE_ALL_PORTS << port, ALE_ALL_PORTS << port, |
| 631 | (ALE_PORT_1 | ALE_PORT_2) << port); |
| 632 | } |
| 633 | |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 634 | static void cpsw_init_host_port(struct cpsw_priv *priv) |
| 635 | { |
Mugunthan V N | 3b72c2f | 2013-02-05 08:26:48 +0000 | [diff] [blame^] | 636 | u32 control_reg; |
| 637 | |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 638 | /* soft reset the controller and initialize ale */ |
| 639 | soft_reset("cpsw", &priv->regs->soft_reset); |
| 640 | cpsw_ale_start(priv->ale); |
| 641 | |
| 642 | /* switch to vlan unaware mode */ |
Mugunthan V N | 3b72c2f | 2013-02-05 08:26:48 +0000 | [diff] [blame^] | 643 | cpsw_ale_control_set(priv->ale, priv->host_port, ALE_VLAN_AWARE, |
| 644 | CPSW_ALE_VLAN_AWARE); |
| 645 | control_reg = readl(&priv->regs->control); |
| 646 | control_reg |= CPSW_VLAN_AWARE; |
| 647 | writel(control_reg, &priv->regs->control); |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 648 | |
| 649 | /* setup host port priority mapping */ |
| 650 | __raw_writel(CPDMA_TX_PRIORITY_MAP, |
| 651 | &priv->host_port_regs->cpdma_tx_pri_map); |
| 652 | __raw_writel(0, &priv->host_port_regs->cpdma_rx_chan_map); |
| 653 | |
| 654 | cpsw_ale_control_set(priv->ale, priv->host_port, |
| 655 | ALE_PORT_STATE, ALE_PORT_STATE_FORWARD); |
| 656 | |
Mugunthan V N | e11b220 | 2013-02-05 08:26:47 +0000 | [diff] [blame] | 657 | cpsw_ale_add_ucast(priv->ale, priv->mac_addr, priv->host_port, 0, 0); |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 658 | cpsw_ale_add_mcast(priv->ale, priv->ndev->broadcast, |
Mugunthan V N | e11b220 | 2013-02-05 08:26:47 +0000 | [diff] [blame] | 659 | 1 << priv->host_port, 0, 0, ALE_MCAST_FWD_2); |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 660 | } |
| 661 | |
| 662 | static int cpsw_ndo_open(struct net_device *ndev) |
| 663 | { |
| 664 | struct cpsw_priv *priv = netdev_priv(ndev); |
| 665 | int i, ret; |
| 666 | u32 reg; |
| 667 | |
| 668 | cpsw_intr_disable(priv); |
| 669 | netif_carrier_off(ndev); |
| 670 | |
Mugunthan V N | f150bd7 | 2012-07-17 08:09:50 +0000 | [diff] [blame] | 671 | pm_runtime_get_sync(&priv->pdev->dev); |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 672 | |
Richard Cochran | 549985e | 2012-11-14 09:07:56 +0000 | [diff] [blame] | 673 | reg = priv->version; |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 674 | |
| 675 | dev_info(priv->dev, "initializing cpsw version %d.%d (%d)\n", |
| 676 | CPSW_MAJOR_VERSION(reg), CPSW_MINOR_VERSION(reg), |
| 677 | CPSW_RTL_VERSION(reg)); |
| 678 | |
| 679 | /* initialize host and slave ports */ |
| 680 | cpsw_init_host_port(priv); |
| 681 | for_each_slave(priv, cpsw_slave_open, priv); |
| 682 | |
Mugunthan V N | 3b72c2f | 2013-02-05 08:26:48 +0000 | [diff] [blame^] | 683 | /* Add default VLAN */ |
| 684 | cpsw_add_default_vlan(priv); |
| 685 | |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 686 | /* setup tx dma to fixed prio and zero offset */ |
| 687 | cpdma_control_set(priv->dma, CPDMA_TX_PRIO_FIXED, 1); |
| 688 | cpdma_control_set(priv->dma, CPDMA_RX_BUFFER_OFFSET, 0); |
| 689 | |
| 690 | /* disable priority elevation and enable statistics on all ports */ |
| 691 | __raw_writel(0, &priv->regs->ptype); |
| 692 | |
| 693 | /* enable statistics collection only on the host port */ |
| 694 | __raw_writel(0x7, &priv->regs->stat_port_en); |
| 695 | |
| 696 | if (WARN_ON(!priv->data.rx_descs)) |
| 697 | priv->data.rx_descs = 128; |
| 698 | |
| 699 | for (i = 0; i < priv->data.rx_descs; i++) { |
| 700 | struct sk_buff *skb; |
| 701 | |
| 702 | ret = -ENOMEM; |
| 703 | skb = netdev_alloc_skb_ip_align(priv->ndev, |
| 704 | priv->rx_packet_max); |
| 705 | if (!skb) |
| 706 | break; |
| 707 | ret = cpdma_chan_submit(priv->rxch, skb, skb->data, |
| 708 | skb_tailroom(skb), GFP_KERNEL); |
| 709 | if (WARN_ON(ret < 0)) |
| 710 | break; |
| 711 | } |
| 712 | /* continue even if we didn't manage to submit all receive descs */ |
| 713 | cpsw_info(priv, ifup, "submitted %d rx descriptors\n", i); |
| 714 | |
| 715 | cpdma_ctlr_start(priv->dma); |
| 716 | cpsw_intr_enable(priv); |
| 717 | napi_enable(&priv->napi); |
| 718 | cpdma_ctlr_eoi(priv->dma); |
| 719 | |
| 720 | return 0; |
| 721 | } |
| 722 | |
| 723 | static void cpsw_slave_stop(struct cpsw_slave *slave, struct cpsw_priv *priv) |
| 724 | { |
| 725 | if (!slave->phy) |
| 726 | return; |
| 727 | phy_stop(slave->phy); |
| 728 | phy_disconnect(slave->phy); |
| 729 | slave->phy = NULL; |
| 730 | } |
| 731 | |
| 732 | static int cpsw_ndo_stop(struct net_device *ndev) |
| 733 | { |
| 734 | struct cpsw_priv *priv = netdev_priv(ndev); |
| 735 | |
| 736 | cpsw_info(priv, ifdown, "shutting down cpsw device\n"); |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 737 | netif_stop_queue(priv->ndev); |
| 738 | napi_disable(&priv->napi); |
| 739 | netif_carrier_off(priv->ndev); |
Mugunthan V N | 71380f9 | 2012-11-14 09:07:57 +0000 | [diff] [blame] | 740 | cpsw_intr_disable(priv); |
| 741 | cpdma_ctlr_int_ctrl(priv->dma, false); |
| 742 | cpdma_ctlr_stop(priv->dma); |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 743 | cpsw_ale_stop(priv->ale); |
| 744 | for_each_slave(priv, cpsw_slave_stop, priv); |
Mugunthan V N | f150bd7 | 2012-07-17 08:09:50 +0000 | [diff] [blame] | 745 | pm_runtime_put_sync(&priv->pdev->dev); |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 746 | return 0; |
| 747 | } |
| 748 | |
| 749 | static netdev_tx_t cpsw_ndo_start_xmit(struct sk_buff *skb, |
| 750 | struct net_device *ndev) |
| 751 | { |
| 752 | struct cpsw_priv *priv = netdev_priv(ndev); |
| 753 | int ret; |
| 754 | |
| 755 | ndev->trans_start = jiffies; |
| 756 | |
| 757 | if (skb_padto(skb, CPSW_MIN_PACKET_SIZE)) { |
| 758 | cpsw_err(priv, tx_err, "packet pad failed\n"); |
| 759 | priv->stats.tx_dropped++; |
| 760 | return NETDEV_TX_OK; |
| 761 | } |
| 762 | |
Richard Cochran | 2e5b38a | 2012-10-29 08:45:20 +0000 | [diff] [blame] | 763 | if (skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP && priv->cpts.tx_enable) |
| 764 | skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS; |
| 765 | |
| 766 | skb_tx_timestamp(skb); |
| 767 | |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 768 | ret = cpdma_chan_submit(priv->txch, skb, skb->data, |
| 769 | skb->len, GFP_KERNEL); |
| 770 | if (unlikely(ret != 0)) { |
| 771 | cpsw_err(priv, tx_err, "desc submit failed\n"); |
| 772 | goto fail; |
| 773 | } |
| 774 | |
Mugunthan V N | fae5082 | 2013-01-17 06:31:34 +0000 | [diff] [blame] | 775 | /* If there is no more tx desc left free then we need to |
| 776 | * tell the kernel to stop sending us tx frames. |
| 777 | */ |
| 778 | if (unlikely(cpdma_check_free_tx_desc(priv->txch))) |
| 779 | netif_stop_queue(ndev); |
| 780 | |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 781 | return NETDEV_TX_OK; |
| 782 | fail: |
| 783 | priv->stats.tx_dropped++; |
| 784 | netif_stop_queue(ndev); |
| 785 | return NETDEV_TX_BUSY; |
| 786 | } |
| 787 | |
| 788 | static void cpsw_ndo_change_rx_flags(struct net_device *ndev, int flags) |
| 789 | { |
| 790 | /* |
| 791 | * The switch cannot operate in promiscuous mode without substantial |
| 792 | * headache. For promiscuous mode to work, we would need to put the |
| 793 | * ALE in bypass mode and route all traffic to the host port. |
| 794 | * Subsequently, the host will need to operate as a "bridge", learn, |
| 795 | * and flood as needed. For now, we simply complain here and |
| 796 | * do nothing about it :-) |
| 797 | */ |
| 798 | if ((flags & IFF_PROMISC) && (ndev->flags & IFF_PROMISC)) |
| 799 | dev_err(&ndev->dev, "promiscuity ignored!\n"); |
| 800 | |
| 801 | /* |
| 802 | * The switch cannot filter multicast traffic unless it is configured |
| 803 | * in "VLAN Aware" mode. Unfortunately, VLAN awareness requires a |
| 804 | * whole bunch of additional logic that this driver does not implement |
| 805 | * at present. |
| 806 | */ |
| 807 | if ((flags & IFF_ALLMULTI) && !(ndev->flags & IFF_ALLMULTI)) |
| 808 | dev_err(&ndev->dev, "multicast traffic cannot be filtered!\n"); |
| 809 | } |
| 810 | |
Richard Cochran | 2e5b38a | 2012-10-29 08:45:20 +0000 | [diff] [blame] | 811 | #ifdef CONFIG_TI_CPTS |
| 812 | |
| 813 | static void cpsw_hwtstamp_v1(struct cpsw_priv *priv) |
| 814 | { |
| 815 | struct cpsw_slave *slave = &priv->slaves[priv->data.cpts_active_slave]; |
| 816 | u32 ts_en, seq_id; |
| 817 | |
| 818 | if (!priv->cpts.tx_enable && !priv->cpts.rx_enable) { |
| 819 | slave_write(slave, 0, CPSW1_TS_CTL); |
| 820 | return; |
| 821 | } |
| 822 | |
| 823 | seq_id = (30 << CPSW_V1_SEQ_ID_OFS_SHIFT) | ETH_P_1588; |
| 824 | ts_en = EVENT_MSG_BITS << CPSW_V1_MSG_TYPE_OFS; |
| 825 | |
| 826 | if (priv->cpts.tx_enable) |
| 827 | ts_en |= CPSW_V1_TS_TX_EN; |
| 828 | |
| 829 | if (priv->cpts.rx_enable) |
| 830 | ts_en |= CPSW_V1_TS_RX_EN; |
| 831 | |
| 832 | slave_write(slave, ts_en, CPSW1_TS_CTL); |
| 833 | slave_write(slave, seq_id, CPSW1_TS_SEQ_LTYPE); |
| 834 | } |
| 835 | |
| 836 | static void cpsw_hwtstamp_v2(struct cpsw_priv *priv) |
| 837 | { |
| 838 | struct cpsw_slave *slave = &priv->slaves[priv->data.cpts_active_slave]; |
| 839 | u32 ctrl, mtype; |
| 840 | |
| 841 | ctrl = slave_read(slave, CPSW2_CONTROL); |
| 842 | ctrl &= ~CTRL_ALL_TS_MASK; |
| 843 | |
| 844 | if (priv->cpts.tx_enable) |
| 845 | ctrl |= CTRL_TX_TS_BITS; |
| 846 | |
| 847 | if (priv->cpts.rx_enable) |
| 848 | ctrl |= CTRL_RX_TS_BITS; |
| 849 | |
| 850 | mtype = (30 << TS_SEQ_ID_OFFSET_SHIFT) | EVENT_MSG_BITS; |
| 851 | |
| 852 | slave_write(slave, mtype, CPSW2_TS_SEQ_MTYPE); |
| 853 | slave_write(slave, ctrl, CPSW2_CONTROL); |
| 854 | __raw_writel(ETH_P_1588, &priv->regs->ts_ltype); |
| 855 | } |
| 856 | |
Mugunthan V N | 3177bf6 | 2012-11-27 07:53:40 +0000 | [diff] [blame] | 857 | static int cpsw_hwtstamp_ioctl(struct net_device *dev, struct ifreq *ifr) |
Richard Cochran | 2e5b38a | 2012-10-29 08:45:20 +0000 | [diff] [blame] | 858 | { |
Mugunthan V N | 3177bf6 | 2012-11-27 07:53:40 +0000 | [diff] [blame] | 859 | struct cpsw_priv *priv = netdev_priv(dev); |
Richard Cochran | 2e5b38a | 2012-10-29 08:45:20 +0000 | [diff] [blame] | 860 | struct cpts *cpts = &priv->cpts; |
| 861 | struct hwtstamp_config cfg; |
| 862 | |
| 863 | if (copy_from_user(&cfg, ifr->ifr_data, sizeof(cfg))) |
| 864 | return -EFAULT; |
| 865 | |
| 866 | /* reserved for future extensions */ |
| 867 | if (cfg.flags) |
| 868 | return -EINVAL; |
| 869 | |
| 870 | switch (cfg.tx_type) { |
| 871 | case HWTSTAMP_TX_OFF: |
| 872 | cpts->tx_enable = 0; |
| 873 | break; |
| 874 | case HWTSTAMP_TX_ON: |
| 875 | cpts->tx_enable = 1; |
| 876 | break; |
| 877 | default: |
| 878 | return -ERANGE; |
| 879 | } |
| 880 | |
| 881 | switch (cfg.rx_filter) { |
| 882 | case HWTSTAMP_FILTER_NONE: |
| 883 | cpts->rx_enable = 0; |
| 884 | break; |
| 885 | case HWTSTAMP_FILTER_ALL: |
| 886 | case HWTSTAMP_FILTER_PTP_V1_L4_EVENT: |
| 887 | case HWTSTAMP_FILTER_PTP_V1_L4_SYNC: |
| 888 | case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ: |
| 889 | return -ERANGE; |
| 890 | case HWTSTAMP_FILTER_PTP_V2_L4_EVENT: |
| 891 | case HWTSTAMP_FILTER_PTP_V2_L4_SYNC: |
| 892 | case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ: |
| 893 | case HWTSTAMP_FILTER_PTP_V2_L2_EVENT: |
| 894 | case HWTSTAMP_FILTER_PTP_V2_L2_SYNC: |
| 895 | case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ: |
| 896 | case HWTSTAMP_FILTER_PTP_V2_EVENT: |
| 897 | case HWTSTAMP_FILTER_PTP_V2_SYNC: |
| 898 | case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ: |
| 899 | cpts->rx_enable = 1; |
| 900 | cfg.rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT; |
| 901 | break; |
| 902 | default: |
| 903 | return -ERANGE; |
| 904 | } |
| 905 | |
| 906 | switch (priv->version) { |
| 907 | case CPSW_VERSION_1: |
| 908 | cpsw_hwtstamp_v1(priv); |
| 909 | break; |
| 910 | case CPSW_VERSION_2: |
| 911 | cpsw_hwtstamp_v2(priv); |
| 912 | break; |
| 913 | default: |
| 914 | return -ENOTSUPP; |
| 915 | } |
| 916 | |
| 917 | return copy_to_user(ifr->ifr_data, &cfg, sizeof(cfg)) ? -EFAULT : 0; |
| 918 | } |
| 919 | |
| 920 | #endif /*CONFIG_TI_CPTS*/ |
| 921 | |
| 922 | static int cpsw_ndo_ioctl(struct net_device *dev, struct ifreq *req, int cmd) |
| 923 | { |
Richard Cochran | 2e5b38a | 2012-10-29 08:45:20 +0000 | [diff] [blame] | 924 | if (!netif_running(dev)) |
| 925 | return -EINVAL; |
| 926 | |
| 927 | #ifdef CONFIG_TI_CPTS |
| 928 | if (cmd == SIOCSHWTSTAMP) |
Mugunthan V N | 3177bf6 | 2012-11-27 07:53:40 +0000 | [diff] [blame] | 929 | return cpsw_hwtstamp_ioctl(dev, req); |
Richard Cochran | 2e5b38a | 2012-10-29 08:45:20 +0000 | [diff] [blame] | 930 | #endif |
| 931 | return -ENOTSUPP; |
| 932 | } |
| 933 | |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 934 | static void cpsw_ndo_tx_timeout(struct net_device *ndev) |
| 935 | { |
| 936 | struct cpsw_priv *priv = netdev_priv(ndev); |
| 937 | |
| 938 | cpsw_err(priv, tx_err, "transmit timeout, restarting dma\n"); |
| 939 | priv->stats.tx_errors++; |
| 940 | cpsw_intr_disable(priv); |
| 941 | cpdma_ctlr_int_ctrl(priv->dma, false); |
| 942 | cpdma_chan_stop(priv->txch); |
| 943 | cpdma_chan_start(priv->txch); |
| 944 | cpdma_ctlr_int_ctrl(priv->dma, true); |
| 945 | cpsw_intr_enable(priv); |
| 946 | cpdma_ctlr_eoi(priv->dma); |
| 947 | } |
| 948 | |
| 949 | static struct net_device_stats *cpsw_ndo_get_stats(struct net_device *ndev) |
| 950 | { |
| 951 | struct cpsw_priv *priv = netdev_priv(ndev); |
| 952 | return &priv->stats; |
| 953 | } |
| 954 | |
| 955 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 956 | static void cpsw_ndo_poll_controller(struct net_device *ndev) |
| 957 | { |
| 958 | struct cpsw_priv *priv = netdev_priv(ndev); |
| 959 | |
| 960 | cpsw_intr_disable(priv); |
| 961 | cpdma_ctlr_int_ctrl(priv->dma, false); |
| 962 | cpsw_interrupt(ndev->irq, priv); |
| 963 | cpdma_ctlr_int_ctrl(priv->dma, true); |
| 964 | cpsw_intr_enable(priv); |
| 965 | cpdma_ctlr_eoi(priv->dma); |
| 966 | } |
| 967 | #endif |
| 968 | |
Mugunthan V N | 3b72c2f | 2013-02-05 08:26:48 +0000 | [diff] [blame^] | 969 | static inline int cpsw_add_vlan_ale_entry(struct cpsw_priv *priv, |
| 970 | unsigned short vid) |
| 971 | { |
| 972 | int ret; |
| 973 | |
| 974 | ret = cpsw_ale_add_vlan(priv->ale, vid, |
| 975 | ALE_ALL_PORTS << priv->host_port, |
| 976 | 0, ALE_ALL_PORTS << priv->host_port, |
| 977 | (ALE_PORT_1 | ALE_PORT_2) << priv->host_port); |
| 978 | if (ret != 0) |
| 979 | return ret; |
| 980 | |
| 981 | ret = cpsw_ale_add_ucast(priv->ale, priv->mac_addr, |
| 982 | priv->host_port, ALE_VLAN, vid); |
| 983 | if (ret != 0) |
| 984 | goto clean_vid; |
| 985 | |
| 986 | ret = cpsw_ale_add_mcast(priv->ale, priv->ndev->broadcast, |
| 987 | ALE_ALL_PORTS << priv->host_port, |
| 988 | ALE_VLAN, vid, 0); |
| 989 | if (ret != 0) |
| 990 | goto clean_vlan_ucast; |
| 991 | return 0; |
| 992 | |
| 993 | clean_vlan_ucast: |
| 994 | cpsw_ale_del_ucast(priv->ale, priv->mac_addr, |
| 995 | priv->host_port, ALE_VLAN, vid); |
| 996 | clean_vid: |
| 997 | cpsw_ale_del_vlan(priv->ale, vid, 0); |
| 998 | return ret; |
| 999 | } |
| 1000 | |
| 1001 | static int cpsw_ndo_vlan_rx_add_vid(struct net_device *ndev, |
| 1002 | unsigned short vid) |
| 1003 | { |
| 1004 | struct cpsw_priv *priv = netdev_priv(ndev); |
| 1005 | |
| 1006 | if (vid == priv->data.default_vlan) |
| 1007 | return 0; |
| 1008 | |
| 1009 | dev_info(priv->dev, "Adding vlanid %d to vlan filter\n", vid); |
| 1010 | return cpsw_add_vlan_ale_entry(priv, vid); |
| 1011 | } |
| 1012 | |
| 1013 | static int cpsw_ndo_vlan_rx_kill_vid(struct net_device *ndev, |
| 1014 | unsigned short vid) |
| 1015 | { |
| 1016 | struct cpsw_priv *priv = netdev_priv(ndev); |
| 1017 | int ret; |
| 1018 | |
| 1019 | if (vid == priv->data.default_vlan) |
| 1020 | return 0; |
| 1021 | |
| 1022 | dev_info(priv->dev, "removing vlanid %d from vlan filter\n", vid); |
| 1023 | ret = cpsw_ale_del_vlan(priv->ale, vid, 0); |
| 1024 | if (ret != 0) |
| 1025 | return ret; |
| 1026 | |
| 1027 | ret = cpsw_ale_del_ucast(priv->ale, priv->mac_addr, |
| 1028 | priv->host_port, ALE_VLAN, vid); |
| 1029 | if (ret != 0) |
| 1030 | return ret; |
| 1031 | |
| 1032 | return cpsw_ale_del_mcast(priv->ale, priv->ndev->broadcast, |
| 1033 | 0, ALE_VLAN, vid); |
| 1034 | } |
| 1035 | |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1036 | static const struct net_device_ops cpsw_netdev_ops = { |
| 1037 | .ndo_open = cpsw_ndo_open, |
| 1038 | .ndo_stop = cpsw_ndo_stop, |
| 1039 | .ndo_start_xmit = cpsw_ndo_start_xmit, |
| 1040 | .ndo_change_rx_flags = cpsw_ndo_change_rx_flags, |
Richard Cochran | 2e5b38a | 2012-10-29 08:45:20 +0000 | [diff] [blame] | 1041 | .ndo_do_ioctl = cpsw_ndo_ioctl, |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1042 | .ndo_validate_addr = eth_validate_addr, |
David S. Miller | 5c473ed | 2012-03-20 00:33:59 -0400 | [diff] [blame] | 1043 | .ndo_change_mtu = eth_change_mtu, |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1044 | .ndo_tx_timeout = cpsw_ndo_tx_timeout, |
| 1045 | .ndo_get_stats = cpsw_ndo_get_stats, |
Mugunthan V N | 5c50a85 | 2012-10-29 08:45:11 +0000 | [diff] [blame] | 1046 | .ndo_set_rx_mode = cpsw_ndo_set_rx_mode, |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1047 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 1048 | .ndo_poll_controller = cpsw_ndo_poll_controller, |
| 1049 | #endif |
Mugunthan V N | 3b72c2f | 2013-02-05 08:26:48 +0000 | [diff] [blame^] | 1050 | .ndo_vlan_rx_add_vid = cpsw_ndo_vlan_rx_add_vid, |
| 1051 | .ndo_vlan_rx_kill_vid = cpsw_ndo_vlan_rx_kill_vid, |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1052 | }; |
| 1053 | |
| 1054 | static void cpsw_get_drvinfo(struct net_device *ndev, |
| 1055 | struct ethtool_drvinfo *info) |
| 1056 | { |
| 1057 | struct cpsw_priv *priv = netdev_priv(ndev); |
Jiri Pirko | 7826d43 | 2013-01-06 00:44:26 +0000 | [diff] [blame] | 1058 | |
| 1059 | strlcpy(info->driver, "TI CPSW Driver v1.0", sizeof(info->driver)); |
| 1060 | strlcpy(info->version, "1.0", sizeof(info->version)); |
| 1061 | strlcpy(info->bus_info, priv->pdev->name, sizeof(info->bus_info)); |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1062 | } |
| 1063 | |
| 1064 | static u32 cpsw_get_msglevel(struct net_device *ndev) |
| 1065 | { |
| 1066 | struct cpsw_priv *priv = netdev_priv(ndev); |
| 1067 | return priv->msg_enable; |
| 1068 | } |
| 1069 | |
| 1070 | static void cpsw_set_msglevel(struct net_device *ndev, u32 value) |
| 1071 | { |
| 1072 | struct cpsw_priv *priv = netdev_priv(ndev); |
| 1073 | priv->msg_enable = value; |
| 1074 | } |
| 1075 | |
Richard Cochran | 2e5b38a | 2012-10-29 08:45:20 +0000 | [diff] [blame] | 1076 | static int cpsw_get_ts_info(struct net_device *ndev, |
| 1077 | struct ethtool_ts_info *info) |
| 1078 | { |
| 1079 | #ifdef CONFIG_TI_CPTS |
| 1080 | struct cpsw_priv *priv = netdev_priv(ndev); |
| 1081 | |
| 1082 | info->so_timestamping = |
| 1083 | SOF_TIMESTAMPING_TX_HARDWARE | |
| 1084 | SOF_TIMESTAMPING_TX_SOFTWARE | |
| 1085 | SOF_TIMESTAMPING_RX_HARDWARE | |
| 1086 | SOF_TIMESTAMPING_RX_SOFTWARE | |
| 1087 | SOF_TIMESTAMPING_SOFTWARE | |
| 1088 | SOF_TIMESTAMPING_RAW_HARDWARE; |
| 1089 | info->phc_index = priv->cpts.phc_index; |
| 1090 | info->tx_types = |
| 1091 | (1 << HWTSTAMP_TX_OFF) | |
| 1092 | (1 << HWTSTAMP_TX_ON); |
| 1093 | info->rx_filters = |
| 1094 | (1 << HWTSTAMP_FILTER_NONE) | |
| 1095 | (1 << HWTSTAMP_FILTER_PTP_V2_EVENT); |
| 1096 | #else |
| 1097 | info->so_timestamping = |
| 1098 | SOF_TIMESTAMPING_TX_SOFTWARE | |
| 1099 | SOF_TIMESTAMPING_RX_SOFTWARE | |
| 1100 | SOF_TIMESTAMPING_SOFTWARE; |
| 1101 | info->phc_index = -1; |
| 1102 | info->tx_types = 0; |
| 1103 | info->rx_filters = 0; |
| 1104 | #endif |
| 1105 | return 0; |
| 1106 | } |
| 1107 | |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1108 | static const struct ethtool_ops cpsw_ethtool_ops = { |
| 1109 | .get_drvinfo = cpsw_get_drvinfo, |
| 1110 | .get_msglevel = cpsw_get_msglevel, |
| 1111 | .set_msglevel = cpsw_set_msglevel, |
| 1112 | .get_link = ethtool_op_get_link, |
Richard Cochran | 2e5b38a | 2012-10-29 08:45:20 +0000 | [diff] [blame] | 1113 | .get_ts_info = cpsw_get_ts_info, |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1114 | }; |
| 1115 | |
Richard Cochran | 549985e | 2012-11-14 09:07:56 +0000 | [diff] [blame] | 1116 | static void cpsw_slave_init(struct cpsw_slave *slave, struct cpsw_priv *priv, |
| 1117 | u32 slave_reg_ofs, u32 sliver_reg_ofs) |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1118 | { |
| 1119 | void __iomem *regs = priv->regs; |
| 1120 | int slave_num = slave->slave_num; |
| 1121 | struct cpsw_slave_data *data = priv->data.slave_data + slave_num; |
| 1122 | |
| 1123 | slave->data = data; |
Richard Cochran | 549985e | 2012-11-14 09:07:56 +0000 | [diff] [blame] | 1124 | slave->regs = regs + slave_reg_ofs; |
| 1125 | slave->sliver = regs + sliver_reg_ofs; |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1126 | } |
| 1127 | |
Mugunthan V N | 2eb32b0 | 2012-07-30 10:17:14 +0000 | [diff] [blame] | 1128 | static int cpsw_probe_dt(struct cpsw_platform_data *data, |
| 1129 | struct platform_device *pdev) |
| 1130 | { |
| 1131 | struct device_node *node = pdev->dev.of_node; |
| 1132 | struct device_node *slave_node; |
| 1133 | int i = 0, ret; |
| 1134 | u32 prop; |
| 1135 | |
| 1136 | if (!node) |
| 1137 | return -EINVAL; |
| 1138 | |
| 1139 | if (of_property_read_u32(node, "slaves", &prop)) { |
| 1140 | pr_err("Missing slaves property in the DT.\n"); |
| 1141 | return -EINVAL; |
| 1142 | } |
| 1143 | data->slaves = prop; |
| 1144 | |
Richard Cochran | 78ca0b2 | 2012-10-29 08:45:18 +0000 | [diff] [blame] | 1145 | if (of_property_read_u32(node, "cpts_active_slave", &prop)) { |
| 1146 | pr_err("Missing cpts_active_slave property in the DT.\n"); |
| 1147 | ret = -EINVAL; |
| 1148 | goto error_ret; |
| 1149 | } |
| 1150 | data->cpts_active_slave = prop; |
| 1151 | |
Richard Cochran | 00ab94e | 2012-10-29 08:45:19 +0000 | [diff] [blame] | 1152 | if (of_property_read_u32(node, "cpts_clock_mult", &prop)) { |
| 1153 | pr_err("Missing cpts_clock_mult property in the DT.\n"); |
| 1154 | ret = -EINVAL; |
| 1155 | goto error_ret; |
| 1156 | } |
| 1157 | data->cpts_clock_mult = prop; |
| 1158 | |
| 1159 | if (of_property_read_u32(node, "cpts_clock_shift", &prop)) { |
| 1160 | pr_err("Missing cpts_clock_shift property in the DT.\n"); |
| 1161 | ret = -EINVAL; |
| 1162 | goto error_ret; |
| 1163 | } |
| 1164 | data->cpts_clock_shift = prop; |
| 1165 | |
Joe Perches | b2adaca | 2013-02-03 17:43:58 +0000 | [diff] [blame] | 1166 | data->slave_data = kcalloc(data->slaves, sizeof(struct cpsw_slave_data), |
| 1167 | GFP_KERNEL); |
| 1168 | if (!data->slave_data) |
Mugunthan V N | 2eb32b0 | 2012-07-30 10:17:14 +0000 | [diff] [blame] | 1169 | return -EINVAL; |
Mugunthan V N | 2eb32b0 | 2012-07-30 10:17:14 +0000 | [diff] [blame] | 1170 | |
Mugunthan V N | 2eb32b0 | 2012-07-30 10:17:14 +0000 | [diff] [blame] | 1171 | if (of_property_read_u32(node, "cpdma_channels", &prop)) { |
| 1172 | pr_err("Missing cpdma_channels property in the DT.\n"); |
| 1173 | ret = -EINVAL; |
| 1174 | goto error_ret; |
| 1175 | } |
| 1176 | data->channels = prop; |
| 1177 | |
Mugunthan V N | 2eb32b0 | 2012-07-30 10:17:14 +0000 | [diff] [blame] | 1178 | if (of_property_read_u32(node, "ale_entries", &prop)) { |
| 1179 | pr_err("Missing ale_entries property in the DT.\n"); |
| 1180 | ret = -EINVAL; |
| 1181 | goto error_ret; |
| 1182 | } |
| 1183 | data->ale_entries = prop; |
| 1184 | |
Mugunthan V N | 2eb32b0 | 2012-07-30 10:17:14 +0000 | [diff] [blame] | 1185 | if (of_property_read_u32(node, "bd_ram_size", &prop)) { |
| 1186 | pr_err("Missing bd_ram_size property in the DT.\n"); |
| 1187 | ret = -EINVAL; |
| 1188 | goto error_ret; |
| 1189 | } |
| 1190 | data->bd_ram_size = prop; |
| 1191 | |
| 1192 | if (of_property_read_u32(node, "rx_descs", &prop)) { |
| 1193 | pr_err("Missing rx_descs property in the DT.\n"); |
| 1194 | ret = -EINVAL; |
| 1195 | goto error_ret; |
| 1196 | } |
| 1197 | data->rx_descs = prop; |
| 1198 | |
| 1199 | if (of_property_read_u32(node, "mac_control", &prop)) { |
| 1200 | pr_err("Missing mac_control property in the DT.\n"); |
| 1201 | ret = -EINVAL; |
| 1202 | goto error_ret; |
| 1203 | } |
| 1204 | data->mac_control = prop; |
| 1205 | |
Vaibhav Hiremath | 1fb19aa | 2012-11-14 09:07:55 +0000 | [diff] [blame] | 1206 | /* |
| 1207 | * Populate all the child nodes here... |
| 1208 | */ |
| 1209 | ret = of_platform_populate(node, NULL, NULL, &pdev->dev); |
| 1210 | /* We do not want to force this, as in some cases may not have child */ |
| 1211 | if (ret) |
| 1212 | pr_warn("Doesn't have any child node\n"); |
| 1213 | |
Richard Cochran | 549985e | 2012-11-14 09:07:56 +0000 | [diff] [blame] | 1214 | for_each_node_by_name(slave_node, "slave") { |
| 1215 | struct cpsw_slave_data *slave_data = data->slave_data + i; |
| 1216 | const void *mac_addr = NULL; |
| 1217 | u32 phyid; |
| 1218 | int lenp; |
| 1219 | const __be32 *parp; |
| 1220 | struct device_node *mdio_node; |
| 1221 | struct platform_device *mdio; |
| 1222 | |
| 1223 | parp = of_get_property(slave_node, "phy_id", &lenp); |
| 1224 | if ((parp == NULL) && (lenp != (sizeof(void *) * 2))) { |
| 1225 | pr_err("Missing slave[%d] phy_id property\n", i); |
| 1226 | ret = -EINVAL; |
| 1227 | goto error_ret; |
| 1228 | } |
| 1229 | mdio_node = of_find_node_by_phandle(be32_to_cpup(parp)); |
| 1230 | phyid = be32_to_cpup(parp+1); |
| 1231 | mdio = of_find_device_by_node(mdio_node); |
| 1232 | snprintf(slave_data->phy_id, sizeof(slave_data->phy_id), |
| 1233 | PHY_ID_FMT, mdio->name, phyid); |
| 1234 | |
| 1235 | mac_addr = of_get_mac_address(slave_node); |
| 1236 | if (mac_addr) |
| 1237 | memcpy(slave_data->mac_addr, mac_addr, ETH_ALEN); |
| 1238 | |
| 1239 | i++; |
| 1240 | } |
| 1241 | |
Mugunthan V N | 2eb32b0 | 2012-07-30 10:17:14 +0000 | [diff] [blame] | 1242 | return 0; |
| 1243 | |
| 1244 | error_ret: |
| 1245 | kfree(data->slave_data); |
| 1246 | return ret; |
| 1247 | } |
| 1248 | |
Bill Pemberton | 663e12e | 2012-12-03 09:23:45 -0500 | [diff] [blame] | 1249 | static int cpsw_probe(struct platform_device *pdev) |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1250 | { |
| 1251 | struct cpsw_platform_data *data = pdev->dev.platform_data; |
| 1252 | struct net_device *ndev; |
| 1253 | struct cpsw_priv *priv; |
| 1254 | struct cpdma_params dma_params; |
| 1255 | struct cpsw_ale_params ale_params; |
Richard Cochran | 549985e | 2012-11-14 09:07:56 +0000 | [diff] [blame] | 1256 | void __iomem *ss_regs, *wr_regs; |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1257 | struct resource *res; |
Richard Cochran | 549985e | 2012-11-14 09:07:56 +0000 | [diff] [blame] | 1258 | u32 slave_offset, sliver_offset, slave_size; |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1259 | int ret = 0, i, k = 0; |
| 1260 | |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1261 | ndev = alloc_etherdev(sizeof(struct cpsw_priv)); |
| 1262 | if (!ndev) { |
| 1263 | pr_err("error allocating net_device\n"); |
| 1264 | return -ENOMEM; |
| 1265 | } |
| 1266 | |
| 1267 | platform_set_drvdata(pdev, ndev); |
| 1268 | priv = netdev_priv(ndev); |
| 1269 | spin_lock_init(&priv->lock); |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1270 | priv->pdev = pdev; |
| 1271 | priv->ndev = ndev; |
| 1272 | priv->dev = &ndev->dev; |
| 1273 | priv->msg_enable = netif_msg_init(debug_level, CPSW_DEBUG); |
| 1274 | priv->rx_packet_max = max(rx_packet_max, 128); |
| 1275 | |
Vaibhav Hiremath | 1fb19aa | 2012-11-14 09:07:55 +0000 | [diff] [blame] | 1276 | /* |
| 1277 | * This may be required here for child devices. |
| 1278 | */ |
| 1279 | pm_runtime_enable(&pdev->dev); |
| 1280 | |
Mugunthan V N | 2eb32b0 | 2012-07-30 10:17:14 +0000 | [diff] [blame] | 1281 | if (cpsw_probe_dt(&priv->data, pdev)) { |
| 1282 | pr_err("cpsw: platform data missing\n"); |
| 1283 | ret = -ENODEV; |
| 1284 | goto clean_ndev_ret; |
| 1285 | } |
| 1286 | data = &priv->data; |
| 1287 | |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1288 | if (is_valid_ether_addr(data->slave_data[0].mac_addr)) { |
| 1289 | memcpy(priv->mac_addr, data->slave_data[0].mac_addr, ETH_ALEN); |
| 1290 | pr_info("Detected MACID = %pM", priv->mac_addr); |
| 1291 | } else { |
Joe Perches | 7efd26d | 2012-07-12 19:33:06 +0000 | [diff] [blame] | 1292 | eth_random_addr(priv->mac_addr); |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1293 | pr_info("Random MACID = %pM", priv->mac_addr); |
| 1294 | } |
| 1295 | |
| 1296 | memcpy(ndev->dev_addr, priv->mac_addr, ETH_ALEN); |
| 1297 | |
| 1298 | priv->slaves = kzalloc(sizeof(struct cpsw_slave) * data->slaves, |
| 1299 | GFP_KERNEL); |
| 1300 | if (!priv->slaves) { |
| 1301 | ret = -EBUSY; |
| 1302 | goto clean_ndev_ret; |
| 1303 | } |
| 1304 | for (i = 0; i < data->slaves; i++) |
| 1305 | priv->slaves[i].slave_num = i; |
| 1306 | |
Mugunthan V N | f150bd7 | 2012-07-17 08:09:50 +0000 | [diff] [blame] | 1307 | priv->clk = clk_get(&pdev->dev, "fck"); |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1308 | if (IS_ERR(priv->clk)) { |
Mugunthan V N | f150bd7 | 2012-07-17 08:09:50 +0000 | [diff] [blame] | 1309 | dev_err(&pdev->dev, "fck is not found\n"); |
| 1310 | ret = -ENODEV; |
| 1311 | goto clean_slave_ret; |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1312 | } |
| 1313 | |
| 1314 | priv->cpsw_res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 1315 | if (!priv->cpsw_res) { |
| 1316 | dev_err(priv->dev, "error getting i/o resource\n"); |
| 1317 | ret = -ENOENT; |
| 1318 | goto clean_clk_ret; |
| 1319 | } |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1320 | if (!request_mem_region(priv->cpsw_res->start, |
| 1321 | resource_size(priv->cpsw_res), ndev->name)) { |
| 1322 | dev_err(priv->dev, "failed request i/o region\n"); |
| 1323 | ret = -ENXIO; |
| 1324 | goto clean_clk_ret; |
| 1325 | } |
Richard Cochran | 549985e | 2012-11-14 09:07:56 +0000 | [diff] [blame] | 1326 | ss_regs = ioremap(priv->cpsw_res->start, resource_size(priv->cpsw_res)); |
| 1327 | if (!ss_regs) { |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1328 | dev_err(priv->dev, "unable to map i/o region\n"); |
| 1329 | goto clean_cpsw_iores_ret; |
| 1330 | } |
Richard Cochran | 549985e | 2012-11-14 09:07:56 +0000 | [diff] [blame] | 1331 | priv->regs = ss_regs; |
| 1332 | priv->version = __raw_readl(&priv->regs->id_ver); |
| 1333 | priv->host_port = HOST_PORT_NUM; |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1334 | |
Richard Cochran | a65dd5b | 2012-11-02 22:25:29 +0000 | [diff] [blame] | 1335 | priv->cpsw_wr_res = platform_get_resource(pdev, IORESOURCE_MEM, 1); |
| 1336 | if (!priv->cpsw_wr_res) { |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1337 | dev_err(priv->dev, "error getting i/o resource\n"); |
| 1338 | ret = -ENOENT; |
Richard Cochran | 5250c96 | 2012-11-02 22:25:30 +0000 | [diff] [blame] | 1339 | goto clean_iomap_ret; |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1340 | } |
Richard Cochran | a65dd5b | 2012-11-02 22:25:29 +0000 | [diff] [blame] | 1341 | if (!request_mem_region(priv->cpsw_wr_res->start, |
| 1342 | resource_size(priv->cpsw_wr_res), ndev->name)) { |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1343 | dev_err(priv->dev, "failed request i/o region\n"); |
| 1344 | ret = -ENXIO; |
Richard Cochran | 5250c96 | 2012-11-02 22:25:30 +0000 | [diff] [blame] | 1345 | goto clean_iomap_ret; |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1346 | } |
Richard Cochran | 549985e | 2012-11-14 09:07:56 +0000 | [diff] [blame] | 1347 | wr_regs = ioremap(priv->cpsw_wr_res->start, |
Richard Cochran | a65dd5b | 2012-11-02 22:25:29 +0000 | [diff] [blame] | 1348 | resource_size(priv->cpsw_wr_res)); |
Richard Cochran | 549985e | 2012-11-14 09:07:56 +0000 | [diff] [blame] | 1349 | if (!wr_regs) { |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1350 | dev_err(priv->dev, "unable to map i/o region\n"); |
Richard Cochran | a65dd5b | 2012-11-02 22:25:29 +0000 | [diff] [blame] | 1351 | goto clean_cpsw_wr_iores_ret; |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1352 | } |
Richard Cochran | 549985e | 2012-11-14 09:07:56 +0000 | [diff] [blame] | 1353 | priv->wr_regs = wr_regs; |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1354 | |
| 1355 | memset(&dma_params, 0, sizeof(dma_params)); |
Richard Cochran | 549985e | 2012-11-14 09:07:56 +0000 | [diff] [blame] | 1356 | memset(&ale_params, 0, sizeof(ale_params)); |
| 1357 | |
| 1358 | switch (priv->version) { |
| 1359 | case CPSW_VERSION_1: |
| 1360 | priv->host_port_regs = ss_regs + CPSW1_HOST_PORT_OFFSET; |
| 1361 | priv->cpts.reg = ss_regs + CPSW1_CPTS_OFFSET; |
| 1362 | dma_params.dmaregs = ss_regs + CPSW1_CPDMA_OFFSET; |
| 1363 | dma_params.txhdp = ss_regs + CPSW1_STATERAM_OFFSET; |
| 1364 | ale_params.ale_regs = ss_regs + CPSW1_ALE_OFFSET; |
| 1365 | slave_offset = CPSW1_SLAVE_OFFSET; |
| 1366 | slave_size = CPSW1_SLAVE_SIZE; |
| 1367 | sliver_offset = CPSW1_SLIVER_OFFSET; |
| 1368 | dma_params.desc_mem_phys = 0; |
| 1369 | break; |
| 1370 | case CPSW_VERSION_2: |
| 1371 | priv->host_port_regs = ss_regs + CPSW2_HOST_PORT_OFFSET; |
| 1372 | priv->cpts.reg = ss_regs + CPSW2_CPTS_OFFSET; |
| 1373 | dma_params.dmaregs = ss_regs + CPSW2_CPDMA_OFFSET; |
| 1374 | dma_params.txhdp = ss_regs + CPSW2_STATERAM_OFFSET; |
| 1375 | ale_params.ale_regs = ss_regs + CPSW2_ALE_OFFSET; |
| 1376 | slave_offset = CPSW2_SLAVE_OFFSET; |
| 1377 | slave_size = CPSW2_SLAVE_SIZE; |
| 1378 | sliver_offset = CPSW2_SLIVER_OFFSET; |
| 1379 | dma_params.desc_mem_phys = |
| 1380 | (u32 __force) priv->cpsw_res->start + CPSW2_BD_OFFSET; |
| 1381 | break; |
| 1382 | default: |
| 1383 | dev_err(priv->dev, "unknown version 0x%08x\n", priv->version); |
| 1384 | ret = -ENODEV; |
| 1385 | goto clean_cpsw_wr_iores_ret; |
| 1386 | } |
| 1387 | for (i = 0; i < priv->data.slaves; i++) { |
| 1388 | struct cpsw_slave *slave = &priv->slaves[i]; |
| 1389 | cpsw_slave_init(slave, priv, slave_offset, sliver_offset); |
| 1390 | slave_offset += slave_size; |
| 1391 | sliver_offset += SLIVER_SIZE; |
| 1392 | } |
| 1393 | |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1394 | dma_params.dev = &pdev->dev; |
Richard Cochran | 549985e | 2012-11-14 09:07:56 +0000 | [diff] [blame] | 1395 | dma_params.rxthresh = dma_params.dmaregs + CPDMA_RXTHRESH; |
| 1396 | dma_params.rxfree = dma_params.dmaregs + CPDMA_RXFREE; |
| 1397 | dma_params.rxhdp = dma_params.txhdp + CPDMA_RXHDP; |
| 1398 | dma_params.txcp = dma_params.txhdp + CPDMA_TXCP; |
| 1399 | dma_params.rxcp = dma_params.txhdp + CPDMA_RXCP; |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1400 | |
| 1401 | dma_params.num_chan = data->channels; |
| 1402 | dma_params.has_soft_reset = true; |
| 1403 | dma_params.min_packet_size = CPSW_MIN_PACKET_SIZE; |
| 1404 | dma_params.desc_mem_size = data->bd_ram_size; |
| 1405 | dma_params.desc_align = 16; |
| 1406 | dma_params.has_ext_regs = true; |
Richard Cochran | 549985e | 2012-11-14 09:07:56 +0000 | [diff] [blame] | 1407 | dma_params.desc_hw_addr = dma_params.desc_mem_phys; |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1408 | |
| 1409 | priv->dma = cpdma_ctlr_create(&dma_params); |
| 1410 | if (!priv->dma) { |
| 1411 | dev_err(priv->dev, "error initializing dma\n"); |
| 1412 | ret = -ENOMEM; |
Richard Cochran | 5250c96 | 2012-11-02 22:25:30 +0000 | [diff] [blame] | 1413 | goto clean_wr_iomap_ret; |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1414 | } |
| 1415 | |
| 1416 | priv->txch = cpdma_chan_create(priv->dma, tx_chan_num(0), |
| 1417 | cpsw_tx_handler); |
| 1418 | priv->rxch = cpdma_chan_create(priv->dma, rx_chan_num(0), |
| 1419 | cpsw_rx_handler); |
| 1420 | |
| 1421 | if (WARN_ON(!priv->txch || !priv->rxch)) { |
| 1422 | dev_err(priv->dev, "error initializing dma channels\n"); |
| 1423 | ret = -ENOMEM; |
| 1424 | goto clean_dma_ret; |
| 1425 | } |
| 1426 | |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1427 | ale_params.dev = &ndev->dev; |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1428 | ale_params.ale_ageout = ale_ageout; |
| 1429 | ale_params.ale_entries = data->ale_entries; |
| 1430 | ale_params.ale_ports = data->slaves; |
| 1431 | |
| 1432 | priv->ale = cpsw_ale_create(&ale_params); |
| 1433 | if (!priv->ale) { |
| 1434 | dev_err(priv->dev, "error initializing ale engine\n"); |
| 1435 | ret = -ENODEV; |
| 1436 | goto clean_dma_ret; |
| 1437 | } |
| 1438 | |
| 1439 | ndev->irq = platform_get_irq(pdev, 0); |
| 1440 | if (ndev->irq < 0) { |
| 1441 | dev_err(priv->dev, "error getting irq resource\n"); |
| 1442 | ret = -ENOENT; |
| 1443 | goto clean_ale_ret; |
| 1444 | } |
| 1445 | |
| 1446 | while ((res = platform_get_resource(priv->pdev, IORESOURCE_IRQ, k))) { |
| 1447 | for (i = res->start; i <= res->end; i++) { |
| 1448 | if (request_irq(i, cpsw_interrupt, IRQF_DISABLED, |
| 1449 | dev_name(&pdev->dev), priv)) { |
| 1450 | dev_err(priv->dev, "error attaching irq\n"); |
| 1451 | goto clean_ale_ret; |
| 1452 | } |
| 1453 | priv->irqs_table[k] = i; |
| 1454 | priv->num_irqs = k; |
| 1455 | } |
| 1456 | k++; |
| 1457 | } |
| 1458 | |
Mugunthan V N | 3b72c2f | 2013-02-05 08:26:48 +0000 | [diff] [blame^] | 1459 | ndev->features |= NETIF_F_HW_VLAN_FILTER; |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1460 | |
| 1461 | ndev->netdev_ops = &cpsw_netdev_ops; |
| 1462 | SET_ETHTOOL_OPS(ndev, &cpsw_ethtool_ops); |
| 1463 | netif_napi_add(ndev, &priv->napi, cpsw_poll, CPSW_POLL_WEIGHT); |
| 1464 | |
| 1465 | /* register the network device */ |
| 1466 | SET_NETDEV_DEV(ndev, &pdev->dev); |
| 1467 | ret = register_netdev(ndev); |
| 1468 | if (ret) { |
| 1469 | dev_err(priv->dev, "error registering net device\n"); |
| 1470 | ret = -ENODEV; |
| 1471 | goto clean_irq_ret; |
| 1472 | } |
| 1473 | |
Richard Cochran | 2e5b38a | 2012-10-29 08:45:20 +0000 | [diff] [blame] | 1474 | if (cpts_register(&pdev->dev, &priv->cpts, |
| 1475 | data->cpts_clock_mult, data->cpts_clock_shift)) |
| 1476 | dev_err(priv->dev, "error registering cpts device\n"); |
| 1477 | |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1478 | cpsw_notice(priv, probe, "initialized device (regs %x, irq %d)\n", |
| 1479 | priv->cpsw_res->start, ndev->irq); |
| 1480 | |
| 1481 | return 0; |
| 1482 | |
| 1483 | clean_irq_ret: |
| 1484 | free_irq(ndev->irq, priv); |
| 1485 | clean_ale_ret: |
| 1486 | cpsw_ale_destroy(priv->ale); |
| 1487 | clean_dma_ret: |
| 1488 | cpdma_chan_destroy(priv->txch); |
| 1489 | cpdma_chan_destroy(priv->rxch); |
| 1490 | cpdma_ctlr_destroy(priv->dma); |
Richard Cochran | 5250c96 | 2012-11-02 22:25:30 +0000 | [diff] [blame] | 1491 | clean_wr_iomap_ret: |
| 1492 | iounmap(priv->wr_regs); |
Richard Cochran | a65dd5b | 2012-11-02 22:25:29 +0000 | [diff] [blame] | 1493 | clean_cpsw_wr_iores_ret: |
| 1494 | release_mem_region(priv->cpsw_wr_res->start, |
| 1495 | resource_size(priv->cpsw_wr_res)); |
Richard Cochran | 5250c96 | 2012-11-02 22:25:30 +0000 | [diff] [blame] | 1496 | clean_iomap_ret: |
| 1497 | iounmap(priv->regs); |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1498 | clean_cpsw_iores_ret: |
| 1499 | release_mem_region(priv->cpsw_res->start, |
| 1500 | resource_size(priv->cpsw_res)); |
| 1501 | clean_clk_ret: |
| 1502 | clk_put(priv->clk); |
Mugunthan V N | f150bd7 | 2012-07-17 08:09:50 +0000 | [diff] [blame] | 1503 | clean_slave_ret: |
| 1504 | pm_runtime_disable(&pdev->dev); |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1505 | kfree(priv->slaves); |
| 1506 | clean_ndev_ret: |
| 1507 | free_netdev(ndev); |
| 1508 | return ret; |
| 1509 | } |
| 1510 | |
Bill Pemberton | 663e12e | 2012-12-03 09:23:45 -0500 | [diff] [blame] | 1511 | static int cpsw_remove(struct platform_device *pdev) |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1512 | { |
| 1513 | struct net_device *ndev = platform_get_drvdata(pdev); |
| 1514 | struct cpsw_priv *priv = netdev_priv(ndev); |
| 1515 | |
| 1516 | pr_info("removing device"); |
| 1517 | platform_set_drvdata(pdev, NULL); |
| 1518 | |
Richard Cochran | 2e5b38a | 2012-10-29 08:45:20 +0000 | [diff] [blame] | 1519 | cpts_unregister(&priv->cpts); |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1520 | free_irq(ndev->irq, priv); |
| 1521 | cpsw_ale_destroy(priv->ale); |
| 1522 | cpdma_chan_destroy(priv->txch); |
| 1523 | cpdma_chan_destroy(priv->rxch); |
| 1524 | cpdma_ctlr_destroy(priv->dma); |
| 1525 | iounmap(priv->regs); |
| 1526 | release_mem_region(priv->cpsw_res->start, |
| 1527 | resource_size(priv->cpsw_res)); |
Richard Cochran | 5250c96 | 2012-11-02 22:25:30 +0000 | [diff] [blame] | 1528 | iounmap(priv->wr_regs); |
Richard Cochran | a65dd5b | 2012-11-02 22:25:29 +0000 | [diff] [blame] | 1529 | release_mem_region(priv->cpsw_wr_res->start, |
| 1530 | resource_size(priv->cpsw_wr_res)); |
Mugunthan V N | f150bd7 | 2012-07-17 08:09:50 +0000 | [diff] [blame] | 1531 | pm_runtime_disable(&pdev->dev); |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1532 | clk_put(priv->clk); |
| 1533 | kfree(priv->slaves); |
| 1534 | free_netdev(ndev); |
| 1535 | |
| 1536 | return 0; |
| 1537 | } |
| 1538 | |
| 1539 | static int cpsw_suspend(struct device *dev) |
| 1540 | { |
| 1541 | struct platform_device *pdev = to_platform_device(dev); |
| 1542 | struct net_device *ndev = platform_get_drvdata(pdev); |
| 1543 | |
| 1544 | if (netif_running(ndev)) |
| 1545 | cpsw_ndo_stop(ndev); |
Mugunthan V N | f150bd7 | 2012-07-17 08:09:50 +0000 | [diff] [blame] | 1546 | pm_runtime_put_sync(&pdev->dev); |
| 1547 | |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1548 | return 0; |
| 1549 | } |
| 1550 | |
| 1551 | static int cpsw_resume(struct device *dev) |
| 1552 | { |
| 1553 | struct platform_device *pdev = to_platform_device(dev); |
| 1554 | struct net_device *ndev = platform_get_drvdata(pdev); |
| 1555 | |
Mugunthan V N | f150bd7 | 2012-07-17 08:09:50 +0000 | [diff] [blame] | 1556 | pm_runtime_get_sync(&pdev->dev); |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1557 | if (netif_running(ndev)) |
| 1558 | cpsw_ndo_open(ndev); |
| 1559 | return 0; |
| 1560 | } |
| 1561 | |
| 1562 | static const struct dev_pm_ops cpsw_pm_ops = { |
| 1563 | .suspend = cpsw_suspend, |
| 1564 | .resume = cpsw_resume, |
| 1565 | }; |
| 1566 | |
Mugunthan V N | 2eb32b0 | 2012-07-30 10:17:14 +0000 | [diff] [blame] | 1567 | static const struct of_device_id cpsw_of_mtable[] = { |
| 1568 | { .compatible = "ti,cpsw", }, |
| 1569 | { /* sentinel */ }, |
| 1570 | }; |
| 1571 | |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1572 | static struct platform_driver cpsw_driver = { |
| 1573 | .driver = { |
| 1574 | .name = "cpsw", |
| 1575 | .owner = THIS_MODULE, |
| 1576 | .pm = &cpsw_pm_ops, |
Mugunthan V N | 2eb32b0 | 2012-07-30 10:17:14 +0000 | [diff] [blame] | 1577 | .of_match_table = of_match_ptr(cpsw_of_mtable), |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1578 | }, |
| 1579 | .probe = cpsw_probe, |
Bill Pemberton | 663e12e | 2012-12-03 09:23:45 -0500 | [diff] [blame] | 1580 | .remove = cpsw_remove, |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1581 | }; |
| 1582 | |
| 1583 | static int __init cpsw_init(void) |
| 1584 | { |
| 1585 | return platform_driver_register(&cpsw_driver); |
| 1586 | } |
| 1587 | late_initcall(cpsw_init); |
| 1588 | |
| 1589 | static void __exit cpsw_exit(void) |
| 1590 | { |
| 1591 | platform_driver_unregister(&cpsw_driver); |
| 1592 | } |
| 1593 | module_exit(cpsw_exit); |
| 1594 | |
| 1595 | MODULE_LICENSE("GPL"); |
| 1596 | MODULE_AUTHOR("Cyril Chemparathy <cyril@ti.com>"); |
| 1597 | MODULE_AUTHOR("Mugunthan V N <mugunthanvnm@ti.com>"); |
| 1598 | MODULE_DESCRIPTION("TI CPSW Ethernet driver"); |