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 | 1d147cc | 2015-09-07 15:16:44 +0530 | [diff] [blame] | 32 | #include <linux/gpio.h> |
Mugunthan V N | 2eb32b0 | 2012-07-30 10:17:14 +0000 | [diff] [blame] | 33 | #include <linux/of.h> |
Heiko Schocher | 9e42f71 | 2015-10-17 06:04:35 +0200 | [diff] [blame] | 34 | #include <linux/of_mdio.h> |
Mugunthan V N | 2eb32b0 | 2012-07-30 10:17:14 +0000 | [diff] [blame] | 35 | #include <linux/of_net.h> |
| 36 | #include <linux/of_device.h> |
Mugunthan V N | 3b72c2f | 2013-02-05 08:26:48 +0000 | [diff] [blame] | 37 | #include <linux/if_vlan.h> |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 38 | |
Mugunthan V N | 739683b | 2013-06-06 23:45:14 +0530 | [diff] [blame] | 39 | #include <linux/pinctrl/consumer.h> |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 40 | |
Mugunthan V N | dbe3472 | 2013-08-19 17:47:40 +0530 | [diff] [blame] | 41 | #include "cpsw.h" |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 42 | #include "cpsw_ale.h" |
Richard Cochran | 2e5b38a | 2012-10-29 08:45:20 +0000 | [diff] [blame] | 43 | #include "cpts.h" |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 44 | #include "davinci_cpdma.h" |
| 45 | |
| 46 | #define CPSW_DEBUG (NETIF_MSG_HW | NETIF_MSG_WOL | \ |
| 47 | NETIF_MSG_DRV | NETIF_MSG_LINK | \ |
| 48 | NETIF_MSG_IFUP | NETIF_MSG_INTR | \ |
| 49 | NETIF_MSG_PROBE | NETIF_MSG_TIMER | \ |
| 50 | NETIF_MSG_IFDOWN | NETIF_MSG_RX_ERR | \ |
| 51 | NETIF_MSG_TX_ERR | NETIF_MSG_TX_DONE | \ |
| 52 | NETIF_MSG_PKTDATA | NETIF_MSG_TX_QUEUED | \ |
| 53 | NETIF_MSG_RX_STATUS) |
| 54 | |
| 55 | #define cpsw_info(priv, type, format, ...) \ |
| 56 | do { \ |
| 57 | if (netif_msg_##type(priv) && net_ratelimit()) \ |
| 58 | dev_info(priv->dev, format, ## __VA_ARGS__); \ |
| 59 | } while (0) |
| 60 | |
| 61 | #define cpsw_err(priv, type, format, ...) \ |
| 62 | do { \ |
| 63 | if (netif_msg_##type(priv) && net_ratelimit()) \ |
| 64 | dev_err(priv->dev, format, ## __VA_ARGS__); \ |
| 65 | } while (0) |
| 66 | |
| 67 | #define cpsw_dbg(priv, type, format, ...) \ |
| 68 | do { \ |
| 69 | if (netif_msg_##type(priv) && net_ratelimit()) \ |
| 70 | dev_dbg(priv->dev, format, ## __VA_ARGS__); \ |
| 71 | } while (0) |
| 72 | |
| 73 | #define cpsw_notice(priv, type, format, ...) \ |
| 74 | do { \ |
| 75 | if (netif_msg_##type(priv) && net_ratelimit()) \ |
| 76 | dev_notice(priv->dev, format, ## __VA_ARGS__); \ |
| 77 | } while (0) |
| 78 | |
Mugunthan V N | 5c50a85 | 2012-10-29 08:45:11 +0000 | [diff] [blame] | 79 | #define ALE_ALL_PORTS 0x7 |
| 80 | |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 81 | #define CPSW_MAJOR_VERSION(reg) (reg >> 8 & 0x7) |
| 82 | #define CPSW_MINOR_VERSION(reg) (reg & 0xff) |
| 83 | #define CPSW_RTL_VERSION(reg) ((reg >> 11) & 0x1f) |
| 84 | |
Richard Cochran | e90cfac | 2012-10-29 08:45:14 +0000 | [diff] [blame] | 85 | #define CPSW_VERSION_1 0x19010a |
| 86 | #define CPSW_VERSION_2 0x19010c |
Mugunthan V N | c193f36 | 2013-08-05 17:30:05 +0530 | [diff] [blame] | 87 | #define CPSW_VERSION_3 0x19010f |
Mugunthan V N | 926489b | 2013-08-12 17:11:15 +0530 | [diff] [blame] | 88 | #define CPSW_VERSION_4 0x190112 |
Richard Cochran | 549985e | 2012-11-14 09:07:56 +0000 | [diff] [blame] | 89 | |
| 90 | #define HOST_PORT_NUM 0 |
| 91 | #define SLIVER_SIZE 0x40 |
| 92 | |
| 93 | #define CPSW1_HOST_PORT_OFFSET 0x028 |
| 94 | #define CPSW1_SLAVE_OFFSET 0x050 |
| 95 | #define CPSW1_SLAVE_SIZE 0x040 |
| 96 | #define CPSW1_CPDMA_OFFSET 0x100 |
| 97 | #define CPSW1_STATERAM_OFFSET 0x200 |
Mugunthan V N | d971854 | 2013-07-23 15:38:17 +0530 | [diff] [blame] | 98 | #define CPSW1_HW_STATS 0x400 |
Richard Cochran | 549985e | 2012-11-14 09:07:56 +0000 | [diff] [blame] | 99 | #define CPSW1_CPTS_OFFSET 0x500 |
| 100 | #define CPSW1_ALE_OFFSET 0x600 |
| 101 | #define CPSW1_SLIVER_OFFSET 0x700 |
| 102 | |
| 103 | #define CPSW2_HOST_PORT_OFFSET 0x108 |
| 104 | #define CPSW2_SLAVE_OFFSET 0x200 |
| 105 | #define CPSW2_SLAVE_SIZE 0x100 |
| 106 | #define CPSW2_CPDMA_OFFSET 0x800 |
Mugunthan V N | d971854 | 2013-07-23 15:38:17 +0530 | [diff] [blame] | 107 | #define CPSW2_HW_STATS 0x900 |
Richard Cochran | 549985e | 2012-11-14 09:07:56 +0000 | [diff] [blame] | 108 | #define CPSW2_STATERAM_OFFSET 0xa00 |
| 109 | #define CPSW2_CPTS_OFFSET 0xc00 |
| 110 | #define CPSW2_ALE_OFFSET 0xd00 |
| 111 | #define CPSW2_SLIVER_OFFSET 0xd80 |
| 112 | #define CPSW2_BD_OFFSET 0x2000 |
| 113 | |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 114 | #define CPDMA_RXTHRESH 0x0c0 |
| 115 | #define CPDMA_RXFREE 0x0e0 |
| 116 | #define CPDMA_TXHDP 0x00 |
| 117 | #define CPDMA_RXHDP 0x20 |
| 118 | #define CPDMA_TXCP 0x40 |
| 119 | #define CPDMA_RXCP 0x60 |
| 120 | |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 121 | #define CPSW_POLL_WEIGHT 64 |
| 122 | #define CPSW_MIN_PACKET_SIZE 60 |
| 123 | #define CPSW_MAX_PACKET_SIZE (1500 + 14 + 4 + 4) |
| 124 | |
| 125 | #define RX_PRIORITY_MAPPING 0x76543210 |
| 126 | #define TX_PRIORITY_MAPPING 0x33221100 |
| 127 | #define CPDMA_TX_PRIORITY_MAP 0x76543210 |
| 128 | |
Mugunthan V N | 3b72c2f | 2013-02-05 08:26:48 +0000 | [diff] [blame] | 129 | #define CPSW_VLAN_AWARE BIT(1) |
| 130 | #define CPSW_ALE_VLAN_AWARE 1 |
| 131 | |
John Ogness | 35717d8 | 2014-11-14 15:42:52 +0100 | [diff] [blame] | 132 | #define CPSW_FIFO_NORMAL_MODE (0 << 16) |
| 133 | #define CPSW_FIFO_DUAL_MAC_MODE (1 << 16) |
| 134 | #define CPSW_FIFO_RATE_LIMIT_MODE (2 << 16) |
Mugunthan V N | d9ba8f9 | 2013-02-11 09:52:20 +0000 | [diff] [blame] | 135 | |
Mugunthan V N | ff5b8ef | 2013-03-11 23:16:37 +0000 | [diff] [blame] | 136 | #define CPSW_INTPACEEN (0x3f << 16) |
| 137 | #define CPSW_INTPRESCALE_MASK (0x7FF << 0) |
| 138 | #define CPSW_CMINTMAX_CNT 63 |
| 139 | #define CPSW_CMINTMIN_CNT 2 |
| 140 | #define CPSW_CMINTMAX_INTVL (1000 / CPSW_CMINTMIN_CNT) |
| 141 | #define CPSW_CMINTMIN_INTVL ((1000 / CPSW_CMINTMAX_CNT) + 1) |
| 142 | |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 143 | #define cpsw_slave_index(cpsw, priv) \ |
| 144 | ((cpsw->data.dual_emac) ? priv->emac_port : \ |
| 145 | cpsw->data.active_slave) |
Ivan Khoronzhuk | e38b5a3 | 2016-08-10 02:22:41 +0300 | [diff] [blame] | 146 | #define IRQ_NUM 2 |
Mugunthan V N | d3bb9c5 | 2013-03-11 23:16:36 +0000 | [diff] [blame] | 147 | |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 148 | static int debug_level; |
| 149 | module_param(debug_level, int, 0); |
| 150 | MODULE_PARM_DESC(debug_level, "cpsw debug level (NETIF_MSG bits)"); |
| 151 | |
| 152 | static int ale_ageout = 10; |
| 153 | module_param(ale_ageout, int, 0); |
| 154 | MODULE_PARM_DESC(ale_ageout, "cpsw ale ageout interval (seconds)"); |
| 155 | |
| 156 | static int rx_packet_max = CPSW_MAX_PACKET_SIZE; |
| 157 | module_param(rx_packet_max, int, 0); |
| 158 | MODULE_PARM_DESC(rx_packet_max, "maximum receive packet size (bytes)"); |
| 159 | |
Richard Cochran | 996a5c2 | 2012-10-29 08:45:12 +0000 | [diff] [blame] | 160 | struct cpsw_wr_regs { |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 161 | u32 id_ver; |
| 162 | u32 soft_reset; |
| 163 | u32 control; |
| 164 | u32 int_control; |
| 165 | u32 rx_thresh_en; |
| 166 | u32 rx_en; |
| 167 | u32 tx_en; |
| 168 | u32 misc_en; |
Mugunthan V N | ff5b8ef | 2013-03-11 23:16:37 +0000 | [diff] [blame] | 169 | u32 mem_allign1[8]; |
| 170 | u32 rx_thresh_stat; |
| 171 | u32 rx_stat; |
| 172 | u32 tx_stat; |
| 173 | u32 misc_stat; |
| 174 | u32 mem_allign2[8]; |
| 175 | u32 rx_imax; |
| 176 | u32 tx_imax; |
| 177 | |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 178 | }; |
| 179 | |
Richard Cochran | 996a5c2 | 2012-10-29 08:45:12 +0000 | [diff] [blame] | 180 | struct cpsw_ss_regs { |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 181 | u32 id_ver; |
| 182 | u32 control; |
| 183 | u32 soft_reset; |
| 184 | u32 stat_port_en; |
| 185 | u32 ptype; |
Richard Cochran | bd357af | 2012-10-29 08:45:13 +0000 | [diff] [blame] | 186 | u32 soft_idle; |
| 187 | u32 thru_rate; |
| 188 | u32 gap_thresh; |
| 189 | u32 tx_start_wds; |
| 190 | u32 flow_control; |
| 191 | u32 vlan_ltype; |
| 192 | u32 ts_ltype; |
| 193 | u32 dlr_ltype; |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 194 | }; |
| 195 | |
Richard Cochran | 9750a3a | 2012-10-29 08:45:15 +0000 | [diff] [blame] | 196 | /* CPSW_PORT_V1 */ |
| 197 | #define CPSW1_MAX_BLKS 0x00 /* Maximum FIFO Blocks */ |
| 198 | #define CPSW1_BLK_CNT 0x04 /* FIFO Block Usage Count (Read Only) */ |
| 199 | #define CPSW1_TX_IN_CTL 0x08 /* Transmit FIFO Control */ |
| 200 | #define CPSW1_PORT_VLAN 0x0c /* VLAN Register */ |
| 201 | #define CPSW1_TX_PRI_MAP 0x10 /* Tx Header Priority to Switch Pri Mapping */ |
| 202 | #define CPSW1_TS_CTL 0x14 /* Time Sync Control */ |
| 203 | #define CPSW1_TS_SEQ_LTYPE 0x18 /* Time Sync Sequence ID Offset and Msg Type */ |
| 204 | #define CPSW1_TS_VLAN 0x1c /* Time Sync VLAN1 and VLAN2 */ |
| 205 | |
| 206 | /* CPSW_PORT_V2 */ |
| 207 | #define CPSW2_CONTROL 0x00 /* Control Register */ |
| 208 | #define CPSW2_MAX_BLKS 0x08 /* Maximum FIFO Blocks */ |
| 209 | #define CPSW2_BLK_CNT 0x0c /* FIFO Block Usage Count (Read Only) */ |
| 210 | #define CPSW2_TX_IN_CTL 0x10 /* Transmit FIFO Control */ |
| 211 | #define CPSW2_PORT_VLAN 0x14 /* VLAN Register */ |
| 212 | #define CPSW2_TX_PRI_MAP 0x18 /* Tx Header Priority to Switch Pri Mapping */ |
| 213 | #define CPSW2_TS_SEQ_MTYPE 0x1c /* Time Sync Sequence ID Offset and Msg Type */ |
| 214 | |
| 215 | /* CPSW_PORT_V1 and V2 */ |
| 216 | #define SA_LO 0x20 /* CPGMAC_SL Source Address Low */ |
| 217 | #define SA_HI 0x24 /* CPGMAC_SL Source Address High */ |
| 218 | #define SEND_PERCENT 0x28 /* Transmit Queue Send Percentages */ |
| 219 | |
| 220 | /* CPSW_PORT_V2 only */ |
| 221 | #define RX_DSCP_PRI_MAP0 0x30 /* Rx DSCP Priority to Rx Packet Mapping */ |
| 222 | #define RX_DSCP_PRI_MAP1 0x34 /* Rx DSCP Priority to Rx Packet Mapping */ |
| 223 | #define RX_DSCP_PRI_MAP2 0x38 /* Rx DSCP Priority to Rx Packet Mapping */ |
| 224 | #define RX_DSCP_PRI_MAP3 0x3c /* Rx DSCP Priority to Rx Packet Mapping */ |
| 225 | #define RX_DSCP_PRI_MAP4 0x40 /* Rx DSCP Priority to Rx Packet Mapping */ |
| 226 | #define RX_DSCP_PRI_MAP5 0x44 /* Rx DSCP Priority to Rx Packet Mapping */ |
| 227 | #define RX_DSCP_PRI_MAP6 0x48 /* Rx DSCP Priority to Rx Packet Mapping */ |
| 228 | #define RX_DSCP_PRI_MAP7 0x4c /* Rx DSCP Priority to Rx Packet Mapping */ |
| 229 | |
| 230 | /* Bit definitions for the CPSW2_CONTROL register */ |
| 231 | #define PASS_PRI_TAGGED (1<<24) /* Pass Priority Tagged */ |
| 232 | #define VLAN_LTYPE2_EN (1<<21) /* VLAN LTYPE 2 enable */ |
| 233 | #define VLAN_LTYPE1_EN (1<<20) /* VLAN LTYPE 1 enable */ |
| 234 | #define DSCP_PRI_EN (1<<16) /* DSCP Priority Enable */ |
| 235 | #define TS_320 (1<<14) /* Time Sync Dest Port 320 enable */ |
| 236 | #define TS_319 (1<<13) /* Time Sync Dest Port 319 enable */ |
| 237 | #define TS_132 (1<<12) /* Time Sync Dest IP Addr 132 enable */ |
| 238 | #define TS_131 (1<<11) /* Time Sync Dest IP Addr 131 enable */ |
| 239 | #define TS_130 (1<<10) /* Time Sync Dest IP Addr 130 enable */ |
| 240 | #define TS_129 (1<<9) /* Time Sync Dest IP Addr 129 enable */ |
George Cherian | 09c5537 | 2014-05-02 12:02:02 +0530 | [diff] [blame] | 241 | #define TS_TTL_NONZERO (1<<8) /* Time Sync Time To Live Non-zero enable */ |
| 242 | #define TS_ANNEX_F_EN (1<<6) /* Time Sync Annex F enable */ |
Richard Cochran | 9750a3a | 2012-10-29 08:45:15 +0000 | [diff] [blame] | 243 | #define TS_ANNEX_D_EN (1<<4) /* Time Sync Annex D enable */ |
| 244 | #define TS_LTYPE2_EN (1<<3) /* Time Sync LTYPE 2 enable */ |
| 245 | #define TS_LTYPE1_EN (1<<2) /* Time Sync LTYPE 1 enable */ |
| 246 | #define TS_TX_EN (1<<1) /* Time Sync Transmit Enable */ |
| 247 | #define TS_RX_EN (1<<0) /* Time Sync Receive Enable */ |
| 248 | |
George Cherian | 09c5537 | 2014-05-02 12:02:02 +0530 | [diff] [blame] | 249 | #define CTRL_V2_TS_BITS \ |
| 250 | (TS_320 | TS_319 | TS_132 | TS_131 | TS_130 | TS_129 |\ |
| 251 | TS_TTL_NONZERO | TS_ANNEX_D_EN | TS_LTYPE1_EN) |
Richard Cochran | 9750a3a | 2012-10-29 08:45:15 +0000 | [diff] [blame] | 252 | |
George Cherian | 09c5537 | 2014-05-02 12:02:02 +0530 | [diff] [blame] | 253 | #define CTRL_V2_ALL_TS_MASK (CTRL_V2_TS_BITS | TS_TX_EN | TS_RX_EN) |
| 254 | #define CTRL_V2_TX_TS_BITS (CTRL_V2_TS_BITS | TS_TX_EN) |
| 255 | #define CTRL_V2_RX_TS_BITS (CTRL_V2_TS_BITS | TS_RX_EN) |
| 256 | |
| 257 | |
| 258 | #define CTRL_V3_TS_BITS \ |
| 259 | (TS_320 | TS_319 | TS_132 | TS_131 | TS_130 | TS_129 |\ |
| 260 | TS_TTL_NONZERO | TS_ANNEX_F_EN | TS_ANNEX_D_EN |\ |
| 261 | TS_LTYPE1_EN) |
| 262 | |
| 263 | #define CTRL_V3_ALL_TS_MASK (CTRL_V3_TS_BITS | TS_TX_EN | TS_RX_EN) |
| 264 | #define CTRL_V3_TX_TS_BITS (CTRL_V3_TS_BITS | TS_TX_EN) |
| 265 | #define CTRL_V3_RX_TS_BITS (CTRL_V3_TS_BITS | TS_RX_EN) |
Richard Cochran | 9750a3a | 2012-10-29 08:45:15 +0000 | [diff] [blame] | 266 | |
| 267 | /* Bit definitions for the CPSW2_TS_SEQ_MTYPE register */ |
| 268 | #define TS_SEQ_ID_OFFSET_SHIFT (16) /* Time Sync Sequence ID Offset */ |
| 269 | #define TS_SEQ_ID_OFFSET_MASK (0x3f) |
| 270 | #define TS_MSG_TYPE_EN_SHIFT (0) /* Time Sync Message Type Enable */ |
| 271 | #define TS_MSG_TYPE_EN_MASK (0xffff) |
| 272 | |
| 273 | /* The PTP event messages - Sync, Delay_Req, Pdelay_Req, and Pdelay_Resp. */ |
| 274 | #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] | 275 | |
Richard Cochran | 2e5b38a | 2012-10-29 08:45:20 +0000 | [diff] [blame] | 276 | /* Bit definitions for the CPSW1_TS_CTL register */ |
| 277 | #define CPSW_V1_TS_RX_EN BIT(0) |
| 278 | #define CPSW_V1_TS_TX_EN BIT(4) |
| 279 | #define CPSW_V1_MSG_TYPE_OFS 16 |
| 280 | |
| 281 | /* Bit definitions for the CPSW1_TS_SEQ_LTYPE register */ |
| 282 | #define CPSW_V1_SEQ_ID_OFS_SHIFT 16 |
| 283 | |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 284 | struct cpsw_host_regs { |
| 285 | u32 max_blks; |
| 286 | u32 blk_cnt; |
Mugunthan V N | d9ba8f9 | 2013-02-11 09:52:20 +0000 | [diff] [blame] | 287 | u32 tx_in_ctl; |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 288 | u32 port_vlan; |
| 289 | u32 tx_pri_map; |
| 290 | u32 cpdma_tx_pri_map; |
| 291 | u32 cpdma_rx_chan_map; |
| 292 | }; |
| 293 | |
| 294 | struct cpsw_sliver_regs { |
| 295 | u32 id_ver; |
| 296 | u32 mac_control; |
| 297 | u32 mac_status; |
| 298 | u32 soft_reset; |
| 299 | u32 rx_maxlen; |
| 300 | u32 __reserved_0; |
| 301 | u32 rx_pause; |
| 302 | u32 tx_pause; |
| 303 | u32 __reserved_1; |
| 304 | u32 rx_pri_map; |
| 305 | }; |
| 306 | |
Mugunthan V N | d971854 | 2013-07-23 15:38:17 +0530 | [diff] [blame] | 307 | struct cpsw_hw_stats { |
| 308 | u32 rxgoodframes; |
| 309 | u32 rxbroadcastframes; |
| 310 | u32 rxmulticastframes; |
| 311 | u32 rxpauseframes; |
| 312 | u32 rxcrcerrors; |
| 313 | u32 rxaligncodeerrors; |
| 314 | u32 rxoversizedframes; |
| 315 | u32 rxjabberframes; |
| 316 | u32 rxundersizedframes; |
| 317 | u32 rxfragments; |
| 318 | u32 __pad_0[2]; |
| 319 | u32 rxoctets; |
| 320 | u32 txgoodframes; |
| 321 | u32 txbroadcastframes; |
| 322 | u32 txmulticastframes; |
| 323 | u32 txpauseframes; |
| 324 | u32 txdeferredframes; |
| 325 | u32 txcollisionframes; |
| 326 | u32 txsinglecollframes; |
| 327 | u32 txmultcollframes; |
| 328 | u32 txexcessivecollisions; |
| 329 | u32 txlatecollisions; |
| 330 | u32 txunderrun; |
| 331 | u32 txcarriersenseerrors; |
| 332 | u32 txoctets; |
| 333 | u32 octetframes64; |
| 334 | u32 octetframes65t127; |
| 335 | u32 octetframes128t255; |
| 336 | u32 octetframes256t511; |
| 337 | u32 octetframes512t1023; |
| 338 | u32 octetframes1024tup; |
| 339 | u32 netoctets; |
| 340 | u32 rxsofoverruns; |
| 341 | u32 rxmofoverruns; |
| 342 | u32 rxdmaoverruns; |
| 343 | }; |
| 344 | |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 345 | struct cpsw_slave { |
Richard Cochran | 9750a3a | 2012-10-29 08:45:15 +0000 | [diff] [blame] | 346 | void __iomem *regs; |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 347 | struct cpsw_sliver_regs __iomem *sliver; |
| 348 | int slave_num; |
| 349 | u32 mac_control; |
| 350 | struct cpsw_slave_data *data; |
| 351 | struct phy_device *phy; |
Mugunthan V N | d9ba8f9 | 2013-02-11 09:52:20 +0000 | [diff] [blame] | 352 | struct net_device *ndev; |
| 353 | u32 port_vlan; |
| 354 | u32 open_stat; |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 355 | }; |
| 356 | |
Richard Cochran | 9750a3a | 2012-10-29 08:45:15 +0000 | [diff] [blame] | 357 | static inline u32 slave_read(struct cpsw_slave *slave, u32 offset) |
| 358 | { |
| 359 | return __raw_readl(slave->regs + offset); |
| 360 | } |
| 361 | |
| 362 | static inline void slave_write(struct cpsw_slave *slave, u32 val, u32 offset) |
| 363 | { |
| 364 | __raw_writel(val, slave->regs + offset); |
| 365 | } |
| 366 | |
Ivan Khoronzhuk | 649a168 | 2016-08-10 02:22:37 +0300 | [diff] [blame] | 367 | struct cpsw_common { |
Ivan Khoronzhuk | 56e31bd | 2016-08-10 02:22:38 +0300 | [diff] [blame] | 368 | struct device *dev; |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 369 | struct cpsw_platform_data data; |
Ivan Khoronzhuk | dbc4ec5 | 2016-08-10 02:22:43 +0300 | [diff] [blame] | 370 | struct napi_struct napi_rx; |
| 371 | struct napi_struct napi_tx; |
Ivan Khoronzhuk | 5d8d0d4 | 2016-08-10 02:22:39 +0300 | [diff] [blame] | 372 | struct cpsw_ss_regs __iomem *regs; |
| 373 | struct cpsw_wr_regs __iomem *wr_regs; |
| 374 | u8 __iomem *hw_stats; |
| 375 | struct cpsw_host_regs __iomem *host_port_regs; |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 376 | u32 version; |
| 377 | u32 coal_intvl; |
| 378 | u32 bus_freq_mhz; |
| 379 | int rx_packet_max; |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 380 | struct cpsw_slave *slaves; |
Ivan Khoronzhuk | 2c836bd | 2016-08-10 02:22:40 +0300 | [diff] [blame] | 381 | struct cpdma_ctlr *dma; |
| 382 | struct cpdma_chan *txch, *rxch; |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 383 | struct cpsw_ale *ale; |
Ivan Khoronzhuk | e38b5a3 | 2016-08-10 02:22:41 +0300 | [diff] [blame] | 384 | bool quirk_irq; |
| 385 | bool rx_irq_disabled; |
| 386 | bool tx_irq_disabled; |
| 387 | u32 irqs_table[IRQ_NUM]; |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 388 | struct cpts *cpts; |
Ivan Khoronzhuk | 649a168 | 2016-08-10 02:22:37 +0300 | [diff] [blame] | 389 | }; |
| 390 | |
| 391 | struct cpsw_priv { |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 392 | struct net_device *ndev; |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 393 | struct device *dev; |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 394 | u32 msg_enable; |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 395 | u8 mac_addr[ETH_ALEN]; |
Mugunthan V N | 1923d6e | 2014-09-08 22:54:02 +0530 | [diff] [blame] | 396 | bool rx_pause; |
| 397 | bool tx_pause; |
Mugunthan V N | d9ba8f9 | 2013-02-11 09:52:20 +0000 | [diff] [blame] | 398 | u32 emac_port; |
Ivan Khoronzhuk | 649a168 | 2016-08-10 02:22:37 +0300 | [diff] [blame] | 399 | struct cpsw_common *cpsw; |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 400 | }; |
| 401 | |
Mugunthan V N | d971854 | 2013-07-23 15:38:17 +0530 | [diff] [blame] | 402 | struct cpsw_stats { |
| 403 | char stat_string[ETH_GSTRING_LEN]; |
| 404 | int type; |
| 405 | int sizeof_stat; |
| 406 | int stat_offset; |
| 407 | }; |
| 408 | |
| 409 | enum { |
| 410 | CPSW_STATS, |
| 411 | CPDMA_RX_STATS, |
| 412 | CPDMA_TX_STATS, |
| 413 | }; |
| 414 | |
| 415 | #define CPSW_STAT(m) CPSW_STATS, \ |
| 416 | sizeof(((struct cpsw_hw_stats *)0)->m), \ |
| 417 | offsetof(struct cpsw_hw_stats, m) |
| 418 | #define CPDMA_RX_STAT(m) CPDMA_RX_STATS, \ |
| 419 | sizeof(((struct cpdma_chan_stats *)0)->m), \ |
| 420 | offsetof(struct cpdma_chan_stats, m) |
| 421 | #define CPDMA_TX_STAT(m) CPDMA_TX_STATS, \ |
| 422 | sizeof(((struct cpdma_chan_stats *)0)->m), \ |
| 423 | offsetof(struct cpdma_chan_stats, m) |
| 424 | |
| 425 | static const struct cpsw_stats cpsw_gstrings_stats[] = { |
| 426 | { "Good Rx Frames", CPSW_STAT(rxgoodframes) }, |
| 427 | { "Broadcast Rx Frames", CPSW_STAT(rxbroadcastframes) }, |
| 428 | { "Multicast Rx Frames", CPSW_STAT(rxmulticastframes) }, |
| 429 | { "Pause Rx Frames", CPSW_STAT(rxpauseframes) }, |
| 430 | { "Rx CRC Errors", CPSW_STAT(rxcrcerrors) }, |
| 431 | { "Rx Align/Code Errors", CPSW_STAT(rxaligncodeerrors) }, |
| 432 | { "Oversize Rx Frames", CPSW_STAT(rxoversizedframes) }, |
| 433 | { "Rx Jabbers", CPSW_STAT(rxjabberframes) }, |
| 434 | { "Undersize (Short) Rx Frames", CPSW_STAT(rxundersizedframes) }, |
| 435 | { "Rx Fragments", CPSW_STAT(rxfragments) }, |
| 436 | { "Rx Octets", CPSW_STAT(rxoctets) }, |
| 437 | { "Good Tx Frames", CPSW_STAT(txgoodframes) }, |
| 438 | { "Broadcast Tx Frames", CPSW_STAT(txbroadcastframes) }, |
| 439 | { "Multicast Tx Frames", CPSW_STAT(txmulticastframes) }, |
| 440 | { "Pause Tx Frames", CPSW_STAT(txpauseframes) }, |
| 441 | { "Deferred Tx Frames", CPSW_STAT(txdeferredframes) }, |
| 442 | { "Collisions", CPSW_STAT(txcollisionframes) }, |
| 443 | { "Single Collision Tx Frames", CPSW_STAT(txsinglecollframes) }, |
| 444 | { "Multiple Collision Tx Frames", CPSW_STAT(txmultcollframes) }, |
| 445 | { "Excessive Collisions", CPSW_STAT(txexcessivecollisions) }, |
| 446 | { "Late Collisions", CPSW_STAT(txlatecollisions) }, |
| 447 | { "Tx Underrun", CPSW_STAT(txunderrun) }, |
| 448 | { "Carrier Sense Errors", CPSW_STAT(txcarriersenseerrors) }, |
| 449 | { "Tx Octets", CPSW_STAT(txoctets) }, |
| 450 | { "Rx + Tx 64 Octet Frames", CPSW_STAT(octetframes64) }, |
| 451 | { "Rx + Tx 65-127 Octet Frames", CPSW_STAT(octetframes65t127) }, |
| 452 | { "Rx + Tx 128-255 Octet Frames", CPSW_STAT(octetframes128t255) }, |
| 453 | { "Rx + Tx 256-511 Octet Frames", CPSW_STAT(octetframes256t511) }, |
| 454 | { "Rx + Tx 512-1023 Octet Frames", CPSW_STAT(octetframes512t1023) }, |
| 455 | { "Rx + Tx 1024-Up Octet Frames", CPSW_STAT(octetframes1024tup) }, |
| 456 | { "Net Octets", CPSW_STAT(netoctets) }, |
| 457 | { "Rx Start of Frame Overruns", CPSW_STAT(rxsofoverruns) }, |
| 458 | { "Rx Middle of Frame Overruns", CPSW_STAT(rxmofoverruns) }, |
| 459 | { "Rx DMA Overruns", CPSW_STAT(rxdmaoverruns) }, |
| 460 | { "Rx DMA chan: head_enqueue", CPDMA_RX_STAT(head_enqueue) }, |
| 461 | { "Rx DMA chan: tail_enqueue", CPDMA_RX_STAT(tail_enqueue) }, |
| 462 | { "Rx DMA chan: pad_enqueue", CPDMA_RX_STAT(pad_enqueue) }, |
| 463 | { "Rx DMA chan: misqueued", CPDMA_RX_STAT(misqueued) }, |
| 464 | { "Rx DMA chan: desc_alloc_fail", CPDMA_RX_STAT(desc_alloc_fail) }, |
| 465 | { "Rx DMA chan: pad_alloc_fail", CPDMA_RX_STAT(pad_alloc_fail) }, |
| 466 | { "Rx DMA chan: runt_receive_buf", CPDMA_RX_STAT(runt_receive_buff) }, |
| 467 | { "Rx DMA chan: runt_transmit_buf", CPDMA_RX_STAT(runt_transmit_buff) }, |
| 468 | { "Rx DMA chan: empty_dequeue", CPDMA_RX_STAT(empty_dequeue) }, |
| 469 | { "Rx DMA chan: busy_dequeue", CPDMA_RX_STAT(busy_dequeue) }, |
| 470 | { "Rx DMA chan: good_dequeue", CPDMA_RX_STAT(good_dequeue) }, |
| 471 | { "Rx DMA chan: requeue", CPDMA_RX_STAT(requeue) }, |
| 472 | { "Rx DMA chan: teardown_dequeue", CPDMA_RX_STAT(teardown_dequeue) }, |
| 473 | { "Tx DMA chan: head_enqueue", CPDMA_TX_STAT(head_enqueue) }, |
| 474 | { "Tx DMA chan: tail_enqueue", CPDMA_TX_STAT(tail_enqueue) }, |
| 475 | { "Tx DMA chan: pad_enqueue", CPDMA_TX_STAT(pad_enqueue) }, |
| 476 | { "Tx DMA chan: misqueued", CPDMA_TX_STAT(misqueued) }, |
| 477 | { "Tx DMA chan: desc_alloc_fail", CPDMA_TX_STAT(desc_alloc_fail) }, |
| 478 | { "Tx DMA chan: pad_alloc_fail", CPDMA_TX_STAT(pad_alloc_fail) }, |
| 479 | { "Tx DMA chan: runt_receive_buf", CPDMA_TX_STAT(runt_receive_buff) }, |
| 480 | { "Tx DMA chan: runt_transmit_buf", CPDMA_TX_STAT(runt_transmit_buff) }, |
| 481 | { "Tx DMA chan: empty_dequeue", CPDMA_TX_STAT(empty_dequeue) }, |
| 482 | { "Tx DMA chan: busy_dequeue", CPDMA_TX_STAT(busy_dequeue) }, |
| 483 | { "Tx DMA chan: good_dequeue", CPDMA_TX_STAT(good_dequeue) }, |
| 484 | { "Tx DMA chan: requeue", CPDMA_TX_STAT(requeue) }, |
| 485 | { "Tx DMA chan: teardown_dequeue", CPDMA_TX_STAT(teardown_dequeue) }, |
| 486 | }; |
| 487 | |
| 488 | #define CPSW_STATS_LEN ARRAY_SIZE(cpsw_gstrings_stats) |
| 489 | |
Ivan Khoronzhuk | 649a168 | 2016-08-10 02:22:37 +0300 | [diff] [blame] | 490 | #define ndev_to_cpsw(ndev) (((struct cpsw_priv *)netdev_priv(ndev))->cpsw) |
Ivan Khoronzhuk | dbc4ec5 | 2016-08-10 02:22:43 +0300 | [diff] [blame] | 491 | #define napi_to_cpsw(napi) container_of(napi, struct cpsw_common, napi) |
Mugunthan V N | d9ba8f9 | 2013-02-11 09:52:20 +0000 | [diff] [blame] | 492 | #define for_each_slave(priv, func, arg...) \ |
| 493 | do { \ |
Sebastian Siewior | 6e6ceae | 2013-04-24 08:48:24 +0000 | [diff] [blame] | 494 | struct cpsw_slave *slave; \ |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 495 | struct cpsw_common *cpsw = (priv)->cpsw; \ |
Sebastian Siewior | 6e6ceae | 2013-04-24 08:48:24 +0000 | [diff] [blame] | 496 | int n; \ |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 497 | if (cpsw->data.dual_emac) \ |
| 498 | (func)((cpsw)->slaves + priv->emac_port, ##arg);\ |
Mugunthan V N | d9ba8f9 | 2013-02-11 09:52:20 +0000 | [diff] [blame] | 499 | else \ |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 500 | for (n = cpsw->data.slaves, \ |
| 501 | slave = cpsw->slaves; \ |
Sebastian Siewior | 6e6ceae | 2013-04-24 08:48:24 +0000 | [diff] [blame] | 502 | n; n--) \ |
| 503 | (func)(slave++, ##arg); \ |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 504 | } while (0) |
Mugunthan V N | d9ba8f9 | 2013-02-11 09:52:20 +0000 | [diff] [blame] | 505 | |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 506 | #define cpsw_dual_emac_src_port_detect(cpsw, status, ndev, skb) \ |
Mugunthan V N | d9ba8f9 | 2013-02-11 09:52:20 +0000 | [diff] [blame] | 507 | do { \ |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 508 | if (!cpsw->data.dual_emac) \ |
Mugunthan V N | d9ba8f9 | 2013-02-11 09:52:20 +0000 | [diff] [blame] | 509 | break; \ |
| 510 | if (CPDMA_RX_SOURCE_PORT(status) == 1) { \ |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 511 | ndev = cpsw->slaves[0].ndev; \ |
Mugunthan V N | d9ba8f9 | 2013-02-11 09:52:20 +0000 | [diff] [blame] | 512 | skb->dev = ndev; \ |
| 513 | } else if (CPDMA_RX_SOURCE_PORT(status) == 2) { \ |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 514 | ndev = cpsw->slaves[1].ndev; \ |
Mugunthan V N | d9ba8f9 | 2013-02-11 09:52:20 +0000 | [diff] [blame] | 515 | skb->dev = ndev; \ |
| 516 | } \ |
| 517 | } while (0) |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 518 | #define cpsw_add_mcast(cpsw, priv, addr) \ |
Mugunthan V N | d9ba8f9 | 2013-02-11 09:52:20 +0000 | [diff] [blame] | 519 | do { \ |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 520 | if (cpsw->data.dual_emac) { \ |
| 521 | struct cpsw_slave *slave = cpsw->slaves + \ |
Mugunthan V N | d9ba8f9 | 2013-02-11 09:52:20 +0000 | [diff] [blame] | 522 | priv->emac_port; \ |
Ivan Khoronzhuk | 6f1f583 | 2016-08-10 02:22:34 +0300 | [diff] [blame] | 523 | int slave_port = cpsw_get_slave_port( \ |
Mugunthan V N | d9ba8f9 | 2013-02-11 09:52:20 +0000 | [diff] [blame] | 524 | slave->slave_num); \ |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 525 | cpsw_ale_add_mcast(cpsw->ale, addr, \ |
Grygorii Strashko | 71a2cbb | 2016-04-07 15:16:44 +0300 | [diff] [blame] | 526 | 1 << slave_port | ALE_PORT_HOST, \ |
Mugunthan V N | d9ba8f9 | 2013-02-11 09:52:20 +0000 | [diff] [blame] | 527 | ALE_VLAN, slave->port_vlan, 0); \ |
| 528 | } else { \ |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 529 | cpsw_ale_add_mcast(cpsw->ale, addr, \ |
Grygorii Strashko | 61f1cef | 2016-04-07 15:16:43 +0300 | [diff] [blame] | 530 | ALE_ALL_PORTS, \ |
Mugunthan V N | d9ba8f9 | 2013-02-11 09:52:20 +0000 | [diff] [blame] | 531 | 0, 0, 0); \ |
| 532 | } \ |
| 533 | } while (0) |
| 534 | |
Ivan Khoronzhuk | 6f1f583 | 2016-08-10 02:22:34 +0300 | [diff] [blame] | 535 | static inline int cpsw_get_slave_port(u32 slave_num) |
Mugunthan V N | d9ba8f9 | 2013-02-11 09:52:20 +0000 | [diff] [blame] | 536 | { |
Grygorii Strashko | 71a2cbb | 2016-04-07 15:16:44 +0300 | [diff] [blame] | 537 | return slave_num + 1; |
Mugunthan V N | d9ba8f9 | 2013-02-11 09:52:20 +0000 | [diff] [blame] | 538 | } |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 539 | |
Mugunthan V N | 0cd8f9c | 2014-01-23 00:03:12 +0530 | [diff] [blame] | 540 | static void cpsw_set_promiscious(struct net_device *ndev, bool enable) |
| 541 | { |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 542 | struct cpsw_common *cpsw = ndev_to_cpsw(ndev); |
| 543 | struct cpsw_ale *ale = cpsw->ale; |
Mugunthan V N | 0cd8f9c | 2014-01-23 00:03:12 +0530 | [diff] [blame] | 544 | int i; |
| 545 | |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 546 | if (cpsw->data.dual_emac) { |
Mugunthan V N | 0cd8f9c | 2014-01-23 00:03:12 +0530 | [diff] [blame] | 547 | bool flag = false; |
| 548 | |
| 549 | /* Enabling promiscuous mode for one interface will be |
| 550 | * common for both the interface as the interface shares |
| 551 | * the same hardware resource. |
| 552 | */ |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 553 | for (i = 0; i < cpsw->data.slaves; i++) |
| 554 | if (cpsw->slaves[i].ndev->flags & IFF_PROMISC) |
Mugunthan V N | 0cd8f9c | 2014-01-23 00:03:12 +0530 | [diff] [blame] | 555 | flag = true; |
| 556 | |
| 557 | if (!enable && flag) { |
| 558 | enable = true; |
| 559 | dev_err(&ndev->dev, "promiscuity not disabled as the other interface is still in promiscuity mode\n"); |
| 560 | } |
| 561 | |
| 562 | if (enable) { |
| 563 | /* Enable Bypass */ |
| 564 | cpsw_ale_control_set(ale, 0, ALE_BYPASS, 1); |
| 565 | |
| 566 | dev_dbg(&ndev->dev, "promiscuity enabled\n"); |
| 567 | } else { |
| 568 | /* Disable Bypass */ |
| 569 | cpsw_ale_control_set(ale, 0, ALE_BYPASS, 0); |
| 570 | dev_dbg(&ndev->dev, "promiscuity disabled\n"); |
| 571 | } |
| 572 | } else { |
| 573 | if (enable) { |
| 574 | unsigned long timeout = jiffies + HZ; |
| 575 | |
Lennart Sorensen | 6f979eb | 2014-10-31 13:28:54 -0400 | [diff] [blame] | 576 | /* Disable Learn for all ports (host is port 0 and slaves are port 1 and up */ |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 577 | for (i = 0; i <= cpsw->data.slaves; i++) { |
Mugunthan V N | 0cd8f9c | 2014-01-23 00:03:12 +0530 | [diff] [blame] | 578 | cpsw_ale_control_set(ale, i, |
| 579 | ALE_PORT_NOLEARN, 1); |
| 580 | cpsw_ale_control_set(ale, i, |
| 581 | ALE_PORT_NO_SA_UPDATE, 1); |
| 582 | } |
| 583 | |
| 584 | /* Clear All Untouched entries */ |
| 585 | cpsw_ale_control_set(ale, 0, ALE_AGEOUT, 1); |
| 586 | do { |
| 587 | cpu_relax(); |
| 588 | if (cpsw_ale_control_get(ale, 0, ALE_AGEOUT)) |
| 589 | break; |
| 590 | } while (time_after(timeout, jiffies)); |
| 591 | cpsw_ale_control_set(ale, 0, ALE_AGEOUT, 1); |
| 592 | |
| 593 | /* Clear all mcast from ALE */ |
Grygorii Strashko | 61f1cef | 2016-04-07 15:16:43 +0300 | [diff] [blame] | 594 | cpsw_ale_flush_multicast(ale, ALE_ALL_PORTS, -1); |
Mugunthan V N | 0cd8f9c | 2014-01-23 00:03:12 +0530 | [diff] [blame] | 595 | |
| 596 | /* Flood All Unicast Packets to Host port */ |
| 597 | cpsw_ale_control_set(ale, 0, ALE_P0_UNI_FLOOD, 1); |
| 598 | dev_dbg(&ndev->dev, "promiscuity enabled\n"); |
| 599 | } else { |
Lennart Sorensen | 6f979eb | 2014-10-31 13:28:54 -0400 | [diff] [blame] | 600 | /* Don't Flood All Unicast Packets to Host port */ |
Mugunthan V N | 0cd8f9c | 2014-01-23 00:03:12 +0530 | [diff] [blame] | 601 | cpsw_ale_control_set(ale, 0, ALE_P0_UNI_FLOOD, 0); |
| 602 | |
Lennart Sorensen | 6f979eb | 2014-10-31 13:28:54 -0400 | [diff] [blame] | 603 | /* Enable Learn for all ports (host is port 0 and slaves are port 1 and up */ |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 604 | for (i = 0; i <= cpsw->data.slaves; i++) { |
Mugunthan V N | 0cd8f9c | 2014-01-23 00:03:12 +0530 | [diff] [blame] | 605 | cpsw_ale_control_set(ale, i, |
| 606 | ALE_PORT_NOLEARN, 0); |
| 607 | cpsw_ale_control_set(ale, i, |
| 608 | ALE_PORT_NO_SA_UPDATE, 0); |
| 609 | } |
| 610 | dev_dbg(&ndev->dev, "promiscuity disabled\n"); |
| 611 | } |
| 612 | } |
| 613 | } |
| 614 | |
Mugunthan V N | 5c50a85 | 2012-10-29 08:45:11 +0000 | [diff] [blame] | 615 | static void cpsw_ndo_set_rx_mode(struct net_device *ndev) |
| 616 | { |
| 617 | struct cpsw_priv *priv = netdev_priv(ndev); |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 618 | struct cpsw_common *cpsw = priv->cpsw; |
Mugunthan V N | 2590605 | 2015-01-13 17:35:49 +0530 | [diff] [blame] | 619 | int vid; |
| 620 | |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 621 | if (cpsw->data.dual_emac) |
| 622 | vid = cpsw->slaves[priv->emac_port].port_vlan; |
Mugunthan V N | 2590605 | 2015-01-13 17:35:49 +0530 | [diff] [blame] | 623 | else |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 624 | vid = cpsw->data.default_vlan; |
Mugunthan V N | 5c50a85 | 2012-10-29 08:45:11 +0000 | [diff] [blame] | 625 | |
| 626 | if (ndev->flags & IFF_PROMISC) { |
| 627 | /* Enable promiscuous mode */ |
Mugunthan V N | 0cd8f9c | 2014-01-23 00:03:12 +0530 | [diff] [blame] | 628 | cpsw_set_promiscious(ndev, true); |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 629 | cpsw_ale_set_allmulti(cpsw->ale, IFF_ALLMULTI); |
Mugunthan V N | 5c50a85 | 2012-10-29 08:45:11 +0000 | [diff] [blame] | 630 | return; |
Mugunthan V N | 0cd8f9c | 2014-01-23 00:03:12 +0530 | [diff] [blame] | 631 | } else { |
| 632 | /* Disable promiscuous mode */ |
| 633 | cpsw_set_promiscious(ndev, false); |
Mugunthan V N | 5c50a85 | 2012-10-29 08:45:11 +0000 | [diff] [blame] | 634 | } |
| 635 | |
Lennart Sorensen | 1e5c4bc | 2014-10-31 13:38:52 -0400 | [diff] [blame] | 636 | /* Restore allmulti on vlans if necessary */ |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 637 | cpsw_ale_set_allmulti(cpsw->ale, priv->ndev->flags & IFF_ALLMULTI); |
Lennart Sorensen | 1e5c4bc | 2014-10-31 13:38:52 -0400 | [diff] [blame] | 638 | |
Mugunthan V N | 5c50a85 | 2012-10-29 08:45:11 +0000 | [diff] [blame] | 639 | /* Clear all mcast from ALE */ |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 640 | cpsw_ale_flush_multicast(cpsw->ale, ALE_ALL_PORTS, vid); |
Mugunthan V N | 5c50a85 | 2012-10-29 08:45:11 +0000 | [diff] [blame] | 641 | |
| 642 | if (!netdev_mc_empty(ndev)) { |
| 643 | struct netdev_hw_addr *ha; |
| 644 | |
| 645 | /* program multicast address list into ALE register */ |
| 646 | netdev_for_each_mc_addr(ha, ndev) { |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 647 | cpsw_add_mcast(cpsw, priv, (u8 *)ha->addr); |
Mugunthan V N | 5c50a85 | 2012-10-29 08:45:11 +0000 | [diff] [blame] | 648 | } |
| 649 | } |
| 650 | } |
| 651 | |
Ivan Khoronzhuk | 2c836bd | 2016-08-10 02:22:40 +0300 | [diff] [blame] | 652 | static void cpsw_intr_enable(struct cpsw_common *cpsw) |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 653 | { |
Ivan Khoronzhuk | 5d8d0d4 | 2016-08-10 02:22:39 +0300 | [diff] [blame] | 654 | __raw_writel(0xFF, &cpsw->wr_regs->tx_en); |
| 655 | __raw_writel(0xFF, &cpsw->wr_regs->rx_en); |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 656 | |
Ivan Khoronzhuk | 2c836bd | 2016-08-10 02:22:40 +0300 | [diff] [blame] | 657 | cpdma_ctlr_int_ctrl(cpsw->dma, true); |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 658 | return; |
| 659 | } |
| 660 | |
Ivan Khoronzhuk | 2c836bd | 2016-08-10 02:22:40 +0300 | [diff] [blame] | 661 | static void cpsw_intr_disable(struct cpsw_common *cpsw) |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 662 | { |
Ivan Khoronzhuk | 5d8d0d4 | 2016-08-10 02:22:39 +0300 | [diff] [blame] | 663 | __raw_writel(0, &cpsw->wr_regs->tx_en); |
| 664 | __raw_writel(0, &cpsw->wr_regs->rx_en); |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 665 | |
Ivan Khoronzhuk | 2c836bd | 2016-08-10 02:22:40 +0300 | [diff] [blame] | 666 | cpdma_ctlr_int_ctrl(cpsw->dma, false); |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 667 | return; |
| 668 | } |
| 669 | |
Olof Johansson | 1a3b505 | 2013-12-11 15:58:07 -0800 | [diff] [blame] | 670 | static void cpsw_tx_handler(void *token, int len, int status) |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 671 | { |
| 672 | struct sk_buff *skb = token; |
| 673 | struct net_device *ndev = skb->dev; |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 674 | struct cpsw_common *cpsw = ndev_to_cpsw(ndev); |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 675 | |
Mugunthan V N | fae5082 | 2013-01-17 06:31:34 +0000 | [diff] [blame] | 676 | /* Check whether the queue is stopped due to stalled tx dma, if the |
| 677 | * queue is stopped then start the queue as we have free desc for tx |
| 678 | */ |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 679 | if (unlikely(netif_queue_stopped(ndev))) |
Mugunthan V N | b56d6b3f | 2013-03-27 04:41:59 +0000 | [diff] [blame] | 680 | netif_wake_queue(ndev); |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 681 | cpts_tx_timestamp(cpsw->cpts, skb); |
Tobias Klauser | 8dc43dd | 2014-03-10 13:12:23 +0100 | [diff] [blame] | 682 | ndev->stats.tx_packets++; |
| 683 | ndev->stats.tx_bytes += len; |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 684 | dev_kfree_skb_any(skb); |
| 685 | } |
| 686 | |
Olof Johansson | 1a3b505 | 2013-12-11 15:58:07 -0800 | [diff] [blame] | 687 | static void cpsw_rx_handler(void *token, int len, int status) |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 688 | { |
| 689 | struct sk_buff *skb = token; |
Sebastian Siewior | b4727e6 | 2013-04-23 07:31:39 +0000 | [diff] [blame] | 690 | struct sk_buff *new_skb; |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 691 | struct net_device *ndev = skb->dev; |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 692 | int ret = 0; |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 693 | struct cpsw_common *cpsw = ndev_to_cpsw(ndev); |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 694 | |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 695 | cpsw_dual_emac_src_port_detect(cpsw, status, ndev, skb); |
Mugunthan V N | d9ba8f9 | 2013-02-11 09:52:20 +0000 | [diff] [blame] | 696 | |
Mugunthan V N | 16e5c57 | 2014-04-10 14:23:23 +0530 | [diff] [blame] | 697 | if (unlikely(status < 0) || unlikely(!netif_running(ndev))) { |
Mugunthan V N | a0e2c82 | 2014-09-10 16:38:09 +0530 | [diff] [blame] | 698 | bool ndev_status = false; |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 699 | struct cpsw_slave *slave = cpsw->slaves; |
Mugunthan V N | a0e2c82 | 2014-09-10 16:38:09 +0530 | [diff] [blame] | 700 | int n; |
| 701 | |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 702 | if (cpsw->data.dual_emac) { |
Mugunthan V N | a0e2c82 | 2014-09-10 16:38:09 +0530 | [diff] [blame] | 703 | /* In dual emac mode check for all interfaces */ |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 704 | for (n = cpsw->data.slaves; n; n--, slave++) |
Mugunthan V N | a0e2c82 | 2014-09-10 16:38:09 +0530 | [diff] [blame] | 705 | if (netif_running(slave->ndev)) |
| 706 | ndev_status = true; |
| 707 | } |
| 708 | |
| 709 | if (ndev_status && (status >= 0)) { |
| 710 | /* The packet received is for the interface which |
| 711 | * is already down and the other interface is up |
Joe Perches | dbedd44 | 2015-03-06 20:49:12 -0800 | [diff] [blame] | 712 | * and running, instead of freeing which results |
Mugunthan V N | a0e2c82 | 2014-09-10 16:38:09 +0530 | [diff] [blame] | 713 | * in reducing of the number of rx descriptor in |
| 714 | * DMA engine, requeue skb back to cpdma. |
| 715 | */ |
| 716 | new_skb = skb; |
| 717 | goto requeue; |
| 718 | } |
| 719 | |
Sebastian Siewior | b4727e6 | 2013-04-23 07:31:39 +0000 | [diff] [blame] | 720 | /* the interface is going down, skbs are purged */ |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 721 | dev_kfree_skb_any(skb); |
| 722 | return; |
| 723 | } |
Sebastian Siewior | b4727e6 | 2013-04-23 07:31:39 +0000 | [diff] [blame] | 724 | |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 725 | new_skb = netdev_alloc_skb_ip_align(ndev, cpsw->rx_packet_max); |
Sebastian Siewior | b4727e6 | 2013-04-23 07:31:39 +0000 | [diff] [blame] | 726 | if (new_skb) { |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 727 | skb_put(skb, len); |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 728 | cpts_rx_timestamp(cpsw->cpts, skb); |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 729 | skb->protocol = eth_type_trans(skb, ndev); |
| 730 | netif_receive_skb(skb); |
Tobias Klauser | 8dc43dd | 2014-03-10 13:12:23 +0100 | [diff] [blame] | 731 | ndev->stats.rx_bytes += len; |
| 732 | ndev->stats.rx_packets++; |
Sebastian Siewior | b4727e6 | 2013-04-23 07:31:39 +0000 | [diff] [blame] | 733 | } else { |
Tobias Klauser | 8dc43dd | 2014-03-10 13:12:23 +0100 | [diff] [blame] | 734 | ndev->stats.rx_dropped++; |
Sebastian Siewior | b4727e6 | 2013-04-23 07:31:39 +0000 | [diff] [blame] | 735 | new_skb = skb; |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 736 | } |
| 737 | |
Mugunthan V N | a0e2c82 | 2014-09-10 16:38:09 +0530 | [diff] [blame] | 738 | requeue: |
Ivan Khoronzhuk | 2c836bd | 2016-08-10 02:22:40 +0300 | [diff] [blame] | 739 | ret = cpdma_chan_submit(cpsw->rxch, new_skb, new_skb->data, |
| 740 | skb_tailroom(new_skb), 0); |
Sebastian Siewior | b4727e6 | 2013-04-23 07:31:39 +0000 | [diff] [blame] | 741 | if (WARN_ON(ret < 0)) |
| 742 | dev_kfree_skb_any(new_skb); |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 743 | } |
| 744 | |
Felipe Balbi | c03abd8 | 2015-01-16 10:11:12 -0600 | [diff] [blame] | 745 | static irqreturn_t cpsw_tx_interrupt(int irq, void *dev_id) |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 746 | { |
Ivan Khoronzhuk | dbc4ec5 | 2016-08-10 02:22:43 +0300 | [diff] [blame] | 747 | struct cpsw_common *cpsw = dev_id; |
Felipe Balbi | 7ce67a3 | 2015-01-02 16:15:59 -0600 | [diff] [blame] | 748 | |
Ivan Khoronzhuk | 5d8d0d4 | 2016-08-10 02:22:39 +0300 | [diff] [blame] | 749 | writel(0, &cpsw->wr_regs->tx_en); |
Ivan Khoronzhuk | 2c836bd | 2016-08-10 02:22:40 +0300 | [diff] [blame] | 750 | cpdma_ctlr_eoi(cpsw->dma, CPDMA_EOI_TX); |
Felipe Balbi | c03abd8 | 2015-01-16 10:11:12 -0600 | [diff] [blame] | 751 | |
Ivan Khoronzhuk | e38b5a3 | 2016-08-10 02:22:41 +0300 | [diff] [blame] | 752 | if (cpsw->quirk_irq) { |
| 753 | disable_irq_nosync(cpsw->irqs_table[1]); |
| 754 | cpsw->tx_irq_disabled = true; |
Mugunthan V N | 7da1160 | 2015-08-12 15:22:53 +0530 | [diff] [blame] | 755 | } |
| 756 | |
Ivan Khoronzhuk | dbc4ec5 | 2016-08-10 02:22:43 +0300 | [diff] [blame] | 757 | napi_schedule(&cpsw->napi_tx); |
Felipe Balbi | c03abd8 | 2015-01-16 10:11:12 -0600 | [diff] [blame] | 758 | return IRQ_HANDLED; |
| 759 | } |
| 760 | |
| 761 | static irqreturn_t cpsw_rx_interrupt(int irq, void *dev_id) |
| 762 | { |
Ivan Khoronzhuk | dbc4ec5 | 2016-08-10 02:22:43 +0300 | [diff] [blame] | 763 | struct cpsw_common *cpsw = dev_id; |
Felipe Balbi | c03abd8 | 2015-01-16 10:11:12 -0600 | [diff] [blame] | 764 | |
Ivan Khoronzhuk | 2c836bd | 2016-08-10 02:22:40 +0300 | [diff] [blame] | 765 | cpdma_ctlr_eoi(cpsw->dma, CPDMA_EOI_RX); |
Ivan Khoronzhuk | 5d8d0d4 | 2016-08-10 02:22:39 +0300 | [diff] [blame] | 766 | writel(0, &cpsw->wr_regs->rx_en); |
Sebastian Siewior | fd51cf1 | 2013-04-23 07:31:37 +0000 | [diff] [blame] | 767 | |
Ivan Khoronzhuk | e38b5a3 | 2016-08-10 02:22:41 +0300 | [diff] [blame] | 768 | if (cpsw->quirk_irq) { |
| 769 | disable_irq_nosync(cpsw->irqs_table[0]); |
| 770 | cpsw->rx_irq_disabled = true; |
Mugunthan V N | 7da1160 | 2015-08-12 15:22:53 +0530 | [diff] [blame] | 771 | } |
| 772 | |
Ivan Khoronzhuk | dbc4ec5 | 2016-08-10 02:22:43 +0300 | [diff] [blame] | 773 | napi_schedule(&cpsw->napi_rx); |
Mugunthan V N | d354eb8 | 2015-08-04 16:06:19 +0530 | [diff] [blame] | 774 | return IRQ_HANDLED; |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 775 | } |
| 776 | |
Mugunthan V N | 32a7432 | 2015-08-04 16:06:20 +0530 | [diff] [blame] | 777 | static int cpsw_tx_poll(struct napi_struct *napi_tx, int budget) |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 778 | { |
Ivan Khoronzhuk | dbc4ec5 | 2016-08-10 02:22:43 +0300 | [diff] [blame] | 779 | struct cpsw_common *cpsw = napi_to_cpsw(napi_tx); |
Mugunthan V N | 32a7432 | 2015-08-04 16:06:20 +0530 | [diff] [blame] | 780 | int num_tx; |
| 781 | |
Ivan Khoronzhuk | 2c836bd | 2016-08-10 02:22:40 +0300 | [diff] [blame] | 782 | num_tx = cpdma_chan_process(cpsw->txch, budget); |
Mugunthan V N | 32a7432 | 2015-08-04 16:06:20 +0530 | [diff] [blame] | 783 | if (num_tx < budget) { |
| 784 | napi_complete(napi_tx); |
Ivan Khoronzhuk | 5d8d0d4 | 2016-08-10 02:22:39 +0300 | [diff] [blame] | 785 | writel(0xff, &cpsw->wr_regs->tx_en); |
Ivan Khoronzhuk | e38b5a3 | 2016-08-10 02:22:41 +0300 | [diff] [blame] | 786 | if (cpsw->quirk_irq && cpsw->tx_irq_disabled) { |
| 787 | cpsw->tx_irq_disabled = false; |
| 788 | enable_irq(cpsw->irqs_table[1]); |
Mugunthan V N | 7da1160 | 2015-08-12 15:22:53 +0530 | [diff] [blame] | 789 | } |
Mugunthan V N | 32a7432 | 2015-08-04 16:06:20 +0530 | [diff] [blame] | 790 | } |
| 791 | |
Mugunthan V N | 32a7432 | 2015-08-04 16:06:20 +0530 | [diff] [blame] | 792 | return num_tx; |
| 793 | } |
| 794 | |
| 795 | static int cpsw_rx_poll(struct napi_struct *napi_rx, int budget) |
| 796 | { |
Ivan Khoronzhuk | dbc4ec5 | 2016-08-10 02:22:43 +0300 | [diff] [blame] | 797 | struct cpsw_common *cpsw = napi_to_cpsw(napi_rx); |
Mugunthan V N | 1e353cd | 2015-07-21 16:00:42 +0530 | [diff] [blame] | 798 | int num_rx; |
Mugunthan V N | 510a1e72 | 2013-02-17 22:19:20 +0000 | [diff] [blame] | 799 | |
Ivan Khoronzhuk | 2c836bd | 2016-08-10 02:22:40 +0300 | [diff] [blame] | 800 | num_rx = cpdma_chan_process(cpsw->rxch, budget); |
Mugunthan V N | 510a1e72 | 2013-02-17 22:19:20 +0000 | [diff] [blame] | 801 | if (num_rx < budget) { |
Mugunthan V N | 32a7432 | 2015-08-04 16:06:20 +0530 | [diff] [blame] | 802 | napi_complete(napi_rx); |
Ivan Khoronzhuk | 5d8d0d4 | 2016-08-10 02:22:39 +0300 | [diff] [blame] | 803 | writel(0xff, &cpsw->wr_regs->rx_en); |
Ivan Khoronzhuk | e38b5a3 | 2016-08-10 02:22:41 +0300 | [diff] [blame] | 804 | if (cpsw->quirk_irq && cpsw->rx_irq_disabled) { |
| 805 | cpsw->rx_irq_disabled = false; |
| 806 | enable_irq(cpsw->irqs_table[0]); |
Mugunthan V N | 7da1160 | 2015-08-12 15:22:53 +0530 | [diff] [blame] | 807 | } |
Mugunthan V N | 510a1e72 | 2013-02-17 22:19:20 +0000 | [diff] [blame] | 808 | } |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 809 | |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 810 | return num_rx; |
| 811 | } |
| 812 | |
| 813 | static inline void soft_reset(const char *module, void __iomem *reg) |
| 814 | { |
| 815 | unsigned long timeout = jiffies + HZ; |
| 816 | |
| 817 | __raw_writel(1, reg); |
| 818 | do { |
| 819 | cpu_relax(); |
| 820 | } while ((__raw_readl(reg) & 1) && time_after(timeout, jiffies)); |
| 821 | |
| 822 | WARN(__raw_readl(reg) & 1, "failed to soft-reset %s\n", module); |
| 823 | } |
| 824 | |
| 825 | #define mac_hi(mac) (((mac)[0] << 0) | ((mac)[1] << 8) | \ |
| 826 | ((mac)[2] << 16) | ((mac)[3] << 24)) |
| 827 | #define mac_lo(mac) (((mac)[4] << 0) | ((mac)[5] << 8)) |
| 828 | |
| 829 | static void cpsw_set_slave_mac(struct cpsw_slave *slave, |
| 830 | struct cpsw_priv *priv) |
| 831 | { |
Richard Cochran | 9750a3a | 2012-10-29 08:45:15 +0000 | [diff] [blame] | 832 | slave_write(slave, mac_hi(priv->mac_addr), SA_HI); |
| 833 | slave_write(slave, mac_lo(priv->mac_addr), SA_LO); |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 834 | } |
| 835 | |
| 836 | static void _cpsw_adjust_link(struct cpsw_slave *slave, |
| 837 | struct cpsw_priv *priv, bool *link) |
| 838 | { |
| 839 | struct phy_device *phy = slave->phy; |
| 840 | u32 mac_control = 0; |
| 841 | u32 slave_port; |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 842 | struct cpsw_common *cpsw = priv->cpsw; |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 843 | |
| 844 | if (!phy) |
| 845 | return; |
| 846 | |
Ivan Khoronzhuk | 6f1f583 | 2016-08-10 02:22:34 +0300 | [diff] [blame] | 847 | slave_port = cpsw_get_slave_port(slave->slave_num); |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 848 | |
| 849 | if (phy->link) { |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 850 | mac_control = cpsw->data.mac_control; |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 851 | |
| 852 | /* enable forwarding */ |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 853 | cpsw_ale_control_set(cpsw->ale, slave_port, |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 854 | ALE_PORT_STATE, ALE_PORT_STATE_FORWARD); |
| 855 | |
| 856 | if (phy->speed == 1000) |
| 857 | mac_control |= BIT(7); /* GIGABITEN */ |
| 858 | if (phy->duplex) |
| 859 | mac_control |= BIT(0); /* FULLDUPLEXEN */ |
Daniel Mack | 342b7b7 | 2012-09-27 09:19:34 +0000 | [diff] [blame] | 860 | |
| 861 | /* set speed_in input in case RMII mode is used in 100Mbps */ |
| 862 | if (phy->speed == 100) |
| 863 | mac_control |= BIT(15); |
Mugunthan V N | a81d876 | 2013-12-13 18:42:55 +0530 | [diff] [blame] | 864 | else if (phy->speed == 10) |
| 865 | mac_control |= BIT(18); /* In Band mode */ |
Daniel Mack | 342b7b7 | 2012-09-27 09:19:34 +0000 | [diff] [blame] | 866 | |
Mugunthan V N | 1923d6e | 2014-09-08 22:54:02 +0530 | [diff] [blame] | 867 | if (priv->rx_pause) |
| 868 | mac_control |= BIT(3); |
| 869 | |
| 870 | if (priv->tx_pause) |
| 871 | mac_control |= BIT(4); |
| 872 | |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 873 | *link = true; |
| 874 | } else { |
| 875 | mac_control = 0; |
| 876 | /* disable forwarding */ |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 877 | cpsw_ale_control_set(cpsw->ale, slave_port, |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 878 | ALE_PORT_STATE, ALE_PORT_STATE_DISABLE); |
| 879 | } |
| 880 | |
| 881 | if (mac_control != slave->mac_control) { |
| 882 | phy_print_status(phy); |
| 883 | __raw_writel(mac_control, &slave->sliver->mac_control); |
| 884 | } |
| 885 | |
| 886 | slave->mac_control = mac_control; |
| 887 | } |
| 888 | |
| 889 | static void cpsw_adjust_link(struct net_device *ndev) |
| 890 | { |
| 891 | struct cpsw_priv *priv = netdev_priv(ndev); |
| 892 | bool link = false; |
| 893 | |
| 894 | for_each_slave(priv, _cpsw_adjust_link, priv, &link); |
| 895 | |
| 896 | if (link) { |
| 897 | netif_carrier_on(ndev); |
| 898 | if (netif_running(ndev)) |
| 899 | netif_wake_queue(ndev); |
| 900 | } else { |
| 901 | netif_carrier_off(ndev); |
| 902 | netif_stop_queue(ndev); |
| 903 | } |
| 904 | } |
| 905 | |
Mugunthan V N | ff5b8ef | 2013-03-11 23:16:37 +0000 | [diff] [blame] | 906 | static int cpsw_get_coalesce(struct net_device *ndev, |
| 907 | struct ethtool_coalesce *coal) |
| 908 | { |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 909 | struct cpsw_common *cpsw = ndev_to_cpsw(ndev); |
Mugunthan V N | ff5b8ef | 2013-03-11 23:16:37 +0000 | [diff] [blame] | 910 | |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 911 | coal->rx_coalesce_usecs = cpsw->coal_intvl; |
Mugunthan V N | ff5b8ef | 2013-03-11 23:16:37 +0000 | [diff] [blame] | 912 | return 0; |
| 913 | } |
| 914 | |
| 915 | static int cpsw_set_coalesce(struct net_device *ndev, |
| 916 | struct ethtool_coalesce *coal) |
| 917 | { |
| 918 | struct cpsw_priv *priv = netdev_priv(ndev); |
| 919 | u32 int_ctrl; |
| 920 | u32 num_interrupts = 0; |
| 921 | u32 prescale = 0; |
| 922 | u32 addnl_dvdr = 1; |
| 923 | u32 coal_intvl = 0; |
Ivan Khoronzhuk | 5d8d0d4 | 2016-08-10 02:22:39 +0300 | [diff] [blame] | 924 | struct cpsw_common *cpsw = priv->cpsw; |
Mugunthan V N | ff5b8ef | 2013-03-11 23:16:37 +0000 | [diff] [blame] | 925 | |
Mugunthan V N | ff5b8ef | 2013-03-11 23:16:37 +0000 | [diff] [blame] | 926 | coal_intvl = coal->rx_coalesce_usecs; |
| 927 | |
Ivan Khoronzhuk | 5d8d0d4 | 2016-08-10 02:22:39 +0300 | [diff] [blame] | 928 | int_ctrl = readl(&cpsw->wr_regs->int_control); |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 929 | prescale = cpsw->bus_freq_mhz * 4; |
Mugunthan V N | ff5b8ef | 2013-03-11 23:16:37 +0000 | [diff] [blame] | 930 | |
Mugunthan V N | a84bc2a | 2014-07-15 20:26:53 +0530 | [diff] [blame] | 931 | if (!coal->rx_coalesce_usecs) { |
| 932 | int_ctrl &= ~(CPSW_INTPRESCALE_MASK | CPSW_INTPACEEN); |
| 933 | goto update_return; |
| 934 | } |
| 935 | |
Mugunthan V N | ff5b8ef | 2013-03-11 23:16:37 +0000 | [diff] [blame] | 936 | if (coal_intvl < CPSW_CMINTMIN_INTVL) |
| 937 | coal_intvl = CPSW_CMINTMIN_INTVL; |
| 938 | |
| 939 | if (coal_intvl > CPSW_CMINTMAX_INTVL) { |
| 940 | /* Interrupt pacer works with 4us Pulse, we can |
| 941 | * throttle further by dilating the 4us pulse. |
| 942 | */ |
| 943 | addnl_dvdr = CPSW_INTPRESCALE_MASK / prescale; |
| 944 | |
| 945 | if (addnl_dvdr > 1) { |
| 946 | prescale *= addnl_dvdr; |
| 947 | if (coal_intvl > (CPSW_CMINTMAX_INTVL * addnl_dvdr)) |
| 948 | coal_intvl = (CPSW_CMINTMAX_INTVL |
| 949 | * addnl_dvdr); |
| 950 | } else { |
| 951 | addnl_dvdr = 1; |
| 952 | coal_intvl = CPSW_CMINTMAX_INTVL; |
| 953 | } |
| 954 | } |
| 955 | |
| 956 | num_interrupts = (1000 * addnl_dvdr) / coal_intvl; |
Ivan Khoronzhuk | 5d8d0d4 | 2016-08-10 02:22:39 +0300 | [diff] [blame] | 957 | writel(num_interrupts, &cpsw->wr_regs->rx_imax); |
| 958 | writel(num_interrupts, &cpsw->wr_regs->tx_imax); |
Mugunthan V N | ff5b8ef | 2013-03-11 23:16:37 +0000 | [diff] [blame] | 959 | |
| 960 | int_ctrl |= CPSW_INTPACEEN; |
| 961 | int_ctrl &= (~CPSW_INTPRESCALE_MASK); |
| 962 | int_ctrl |= (prescale & CPSW_INTPRESCALE_MASK); |
Mugunthan V N | a84bc2a | 2014-07-15 20:26:53 +0530 | [diff] [blame] | 963 | |
| 964 | update_return: |
Ivan Khoronzhuk | 5d8d0d4 | 2016-08-10 02:22:39 +0300 | [diff] [blame] | 965 | writel(int_ctrl, &cpsw->wr_regs->int_control); |
Mugunthan V N | ff5b8ef | 2013-03-11 23:16:37 +0000 | [diff] [blame] | 966 | |
| 967 | cpsw_notice(priv, timer, "Set coalesce to %d usecs.\n", coal_intvl); |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 968 | cpsw->coal_intvl = coal_intvl; |
Mugunthan V N | ff5b8ef | 2013-03-11 23:16:37 +0000 | [diff] [blame] | 969 | |
| 970 | return 0; |
| 971 | } |
| 972 | |
Mugunthan V N | d971854 | 2013-07-23 15:38:17 +0530 | [diff] [blame] | 973 | static int cpsw_get_sset_count(struct net_device *ndev, int sset) |
| 974 | { |
| 975 | switch (sset) { |
| 976 | case ETH_SS_STATS: |
| 977 | return CPSW_STATS_LEN; |
| 978 | default: |
| 979 | return -EOPNOTSUPP; |
| 980 | } |
| 981 | } |
| 982 | |
| 983 | static void cpsw_get_strings(struct net_device *ndev, u32 stringset, u8 *data) |
| 984 | { |
| 985 | u8 *p = data; |
| 986 | int i; |
| 987 | |
| 988 | switch (stringset) { |
| 989 | case ETH_SS_STATS: |
| 990 | for (i = 0; i < CPSW_STATS_LEN; i++) { |
| 991 | memcpy(p, cpsw_gstrings_stats[i].stat_string, |
| 992 | ETH_GSTRING_LEN); |
| 993 | p += ETH_GSTRING_LEN; |
| 994 | } |
| 995 | break; |
| 996 | } |
| 997 | } |
| 998 | |
| 999 | static void cpsw_get_ethtool_stats(struct net_device *ndev, |
| 1000 | struct ethtool_stats *stats, u64 *data) |
| 1001 | { |
Mugunthan V N | d971854 | 2013-07-23 15:38:17 +0530 | [diff] [blame] | 1002 | struct cpdma_chan_stats rx_stats; |
| 1003 | struct cpdma_chan_stats tx_stats; |
| 1004 | u32 val; |
| 1005 | u8 *p; |
| 1006 | int i; |
Ivan Khoronzhuk | 2c836bd | 2016-08-10 02:22:40 +0300 | [diff] [blame] | 1007 | struct cpsw_common *cpsw = ndev_to_cpsw(ndev); |
Mugunthan V N | d971854 | 2013-07-23 15:38:17 +0530 | [diff] [blame] | 1008 | |
| 1009 | /* Collect Davinci CPDMA stats for Rx and Tx Channel */ |
Ivan Khoronzhuk | 2c836bd | 2016-08-10 02:22:40 +0300 | [diff] [blame] | 1010 | cpdma_chan_get_stats(cpsw->rxch, &rx_stats); |
| 1011 | cpdma_chan_get_stats(cpsw->txch, &tx_stats); |
Mugunthan V N | d971854 | 2013-07-23 15:38:17 +0530 | [diff] [blame] | 1012 | |
| 1013 | for (i = 0; i < CPSW_STATS_LEN; i++) { |
| 1014 | switch (cpsw_gstrings_stats[i].type) { |
| 1015 | case CPSW_STATS: |
Ivan Khoronzhuk | 5d8d0d4 | 2016-08-10 02:22:39 +0300 | [diff] [blame] | 1016 | val = readl(cpsw->hw_stats + |
Mugunthan V N | d971854 | 2013-07-23 15:38:17 +0530 | [diff] [blame] | 1017 | cpsw_gstrings_stats[i].stat_offset); |
| 1018 | data[i] = val; |
| 1019 | break; |
| 1020 | |
| 1021 | case CPDMA_RX_STATS: |
| 1022 | p = (u8 *)&rx_stats + |
| 1023 | cpsw_gstrings_stats[i].stat_offset; |
| 1024 | data[i] = *(u32 *)p; |
| 1025 | break; |
| 1026 | |
| 1027 | case CPDMA_TX_STATS: |
| 1028 | p = (u8 *)&tx_stats + |
| 1029 | cpsw_gstrings_stats[i].stat_offset; |
| 1030 | data[i] = *(u32 *)p; |
| 1031 | break; |
| 1032 | } |
| 1033 | } |
| 1034 | } |
| 1035 | |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 1036 | static int cpsw_common_res_usage_state(struct cpsw_common *cpsw) |
Mugunthan V N | d9ba8f9 | 2013-02-11 09:52:20 +0000 | [diff] [blame] | 1037 | { |
| 1038 | u32 i; |
| 1039 | u32 usage_count = 0; |
| 1040 | |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 1041 | if (!cpsw->data.dual_emac) |
Mugunthan V N | d9ba8f9 | 2013-02-11 09:52:20 +0000 | [diff] [blame] | 1042 | return 0; |
| 1043 | |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 1044 | for (i = 0; i < cpsw->data.slaves; i++) |
| 1045 | if (cpsw->slaves[i].open_stat) |
Mugunthan V N | d9ba8f9 | 2013-02-11 09:52:20 +0000 | [diff] [blame] | 1046 | usage_count++; |
| 1047 | |
| 1048 | return usage_count; |
| 1049 | } |
| 1050 | |
Ivan Khoronzhuk | 27e9e10 | 2016-08-10 02:22:32 +0300 | [diff] [blame] | 1051 | static inline int cpsw_tx_packet_submit(struct cpsw_priv *priv, |
| 1052 | struct sk_buff *skb) |
Mugunthan V N | d9ba8f9 | 2013-02-11 09:52:20 +0000 | [diff] [blame] | 1053 | { |
Ivan Khoronzhuk | 2c836bd | 2016-08-10 02:22:40 +0300 | [diff] [blame] | 1054 | struct cpsw_common *cpsw = priv->cpsw; |
| 1055 | |
| 1056 | return cpdma_chan_submit(cpsw->txch, skb, skb->data, skb->len, |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 1057 | priv->emac_port + cpsw->data.dual_emac); |
Mugunthan V N | d9ba8f9 | 2013-02-11 09:52:20 +0000 | [diff] [blame] | 1058 | } |
| 1059 | |
| 1060 | static inline void cpsw_add_dual_emac_def_ale_entries( |
| 1061 | struct cpsw_priv *priv, struct cpsw_slave *slave, |
| 1062 | u32 slave_port) |
| 1063 | { |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 1064 | struct cpsw_common *cpsw = priv->cpsw; |
Grygorii Strashko | 71a2cbb | 2016-04-07 15:16:44 +0300 | [diff] [blame] | 1065 | u32 port_mask = 1 << slave_port | ALE_PORT_HOST; |
Mugunthan V N | d9ba8f9 | 2013-02-11 09:52:20 +0000 | [diff] [blame] | 1066 | |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 1067 | if (cpsw->version == CPSW_VERSION_1) |
Mugunthan V N | d9ba8f9 | 2013-02-11 09:52:20 +0000 | [diff] [blame] | 1068 | slave_write(slave, slave->port_vlan, CPSW1_PORT_VLAN); |
| 1069 | else |
| 1070 | slave_write(slave, slave->port_vlan, CPSW2_PORT_VLAN); |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 1071 | cpsw_ale_add_vlan(cpsw->ale, slave->port_vlan, port_mask, |
Mugunthan V N | d9ba8f9 | 2013-02-11 09:52:20 +0000 | [diff] [blame] | 1072 | port_mask, port_mask, 0); |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 1073 | cpsw_ale_add_mcast(cpsw->ale, priv->ndev->broadcast, |
Mugunthan V N | d9ba8f9 | 2013-02-11 09:52:20 +0000 | [diff] [blame] | 1074 | port_mask, ALE_VLAN, slave->port_vlan, 0); |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 1075 | cpsw_ale_add_ucast(cpsw->ale, priv->mac_addr, |
| 1076 | HOST_PORT_NUM, ALE_VLAN | |
| 1077 | ALE_SECURE, slave->port_vlan); |
Mugunthan V N | d9ba8f9 | 2013-02-11 09:52:20 +0000 | [diff] [blame] | 1078 | } |
| 1079 | |
Daniel Mack | 1e7a2e2 | 2013-11-15 08:29:16 +0100 | [diff] [blame] | 1080 | static void soft_reset_slave(struct cpsw_slave *slave) |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1081 | { |
| 1082 | char name[32]; |
Daniel Mack | 1e7a2e2 | 2013-11-15 08:29:16 +0100 | [diff] [blame] | 1083 | |
| 1084 | snprintf(name, sizeof(name), "slave-%d", slave->slave_num); |
| 1085 | soft_reset(name, &slave->sliver->soft_reset); |
| 1086 | } |
| 1087 | |
| 1088 | static void cpsw_slave_open(struct cpsw_slave *slave, struct cpsw_priv *priv) |
| 1089 | { |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1090 | u32 slave_port; |
Ivan Khoronzhuk | 649a168 | 2016-08-10 02:22:37 +0300 | [diff] [blame] | 1091 | struct cpsw_common *cpsw = priv->cpsw; |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1092 | |
Daniel Mack | 1e7a2e2 | 2013-11-15 08:29:16 +0100 | [diff] [blame] | 1093 | soft_reset_slave(slave); |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1094 | |
| 1095 | /* setup priority mapping */ |
| 1096 | __raw_writel(RX_PRIORITY_MAPPING, &slave->sliver->rx_pri_map); |
Richard Cochran | 9750a3a | 2012-10-29 08:45:15 +0000 | [diff] [blame] | 1097 | |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 1098 | switch (cpsw->version) { |
Richard Cochran | 9750a3a | 2012-10-29 08:45:15 +0000 | [diff] [blame] | 1099 | case CPSW_VERSION_1: |
| 1100 | slave_write(slave, TX_PRIORITY_MAPPING, CPSW1_TX_PRI_MAP); |
| 1101 | break; |
| 1102 | case CPSW_VERSION_2: |
Mugunthan V N | c193f36 | 2013-08-05 17:30:05 +0530 | [diff] [blame] | 1103 | case CPSW_VERSION_3: |
Mugunthan V N | 926489b | 2013-08-12 17:11:15 +0530 | [diff] [blame] | 1104 | case CPSW_VERSION_4: |
Richard Cochran | 9750a3a | 2012-10-29 08:45:15 +0000 | [diff] [blame] | 1105 | slave_write(slave, TX_PRIORITY_MAPPING, CPSW2_TX_PRI_MAP); |
| 1106 | break; |
| 1107 | } |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1108 | |
| 1109 | /* setup max packet size, and mac address */ |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 1110 | __raw_writel(cpsw->rx_packet_max, &slave->sliver->rx_maxlen); |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1111 | cpsw_set_slave_mac(slave, priv); |
| 1112 | |
| 1113 | slave->mac_control = 0; /* no link yet */ |
| 1114 | |
Ivan Khoronzhuk | 6f1f583 | 2016-08-10 02:22:34 +0300 | [diff] [blame] | 1115 | slave_port = cpsw_get_slave_port(slave->slave_num); |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1116 | |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 1117 | if (cpsw->data.dual_emac) |
Mugunthan V N | d9ba8f9 | 2013-02-11 09:52:20 +0000 | [diff] [blame] | 1118 | cpsw_add_dual_emac_def_ale_entries(priv, slave, slave_port); |
| 1119 | else |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 1120 | cpsw_ale_add_mcast(cpsw->ale, priv->ndev->broadcast, |
Mugunthan V N | d9ba8f9 | 2013-02-11 09:52:20 +0000 | [diff] [blame] | 1121 | 1 << slave_port, 0, 0, ALE_MCAST_FWD_2); |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1122 | |
David Rivshin | d733f754 | 2016-04-27 21:32:31 -0400 | [diff] [blame] | 1123 | if (slave->data->phy_node) { |
David Rivshin | 552165b | 2016-04-27 21:25:25 -0400 | [diff] [blame] | 1124 | slave->phy = of_phy_connect(priv->ndev, slave->data->phy_node, |
Heiko Schocher | 9e42f71 | 2015-10-17 06:04:35 +0200 | [diff] [blame] | 1125 | &cpsw_adjust_link, 0, slave->data->phy_if); |
David Rivshin | d733f754 | 2016-04-27 21:32:31 -0400 | [diff] [blame] | 1126 | if (!slave->phy) { |
| 1127 | dev_err(priv->dev, "phy \"%s\" not found on slave %d\n", |
| 1128 | slave->data->phy_node->full_name, |
| 1129 | slave->slave_num); |
| 1130 | return; |
| 1131 | } |
| 1132 | } else { |
Heiko Schocher | 9e42f71 | 2015-10-17 06:04:35 +0200 | [diff] [blame] | 1133 | slave->phy = phy_connect(priv->ndev, slave->data->phy_id, |
Florian Fainelli | f9a8f83 | 2013-01-14 00:52:52 +0000 | [diff] [blame] | 1134 | &cpsw_adjust_link, slave->data->phy_if); |
David Rivshin | d733f754 | 2016-04-27 21:32:31 -0400 | [diff] [blame] | 1135 | if (IS_ERR(slave->phy)) { |
| 1136 | dev_err(priv->dev, |
| 1137 | "phy \"%s\" not found on slave %d, err %ld\n", |
| 1138 | slave->data->phy_id, slave->slave_num, |
| 1139 | PTR_ERR(slave->phy)); |
| 1140 | slave->phy = NULL; |
| 1141 | return; |
| 1142 | } |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1143 | } |
David Rivshin | d733f754 | 2016-04-27 21:32:31 -0400 | [diff] [blame] | 1144 | |
| 1145 | phy_attached_info(slave->phy); |
| 1146 | |
| 1147 | phy_start(slave->phy); |
| 1148 | |
| 1149 | /* Configure GMII_SEL register */ |
Ivan Khoronzhuk | 56e31bd | 2016-08-10 02:22:38 +0300 | [diff] [blame] | 1150 | cpsw_phy_sel(cpsw->dev, slave->phy->interface, slave->slave_num); |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1151 | } |
| 1152 | |
Mugunthan V N | 3b72c2f | 2013-02-05 08:26:48 +0000 | [diff] [blame] | 1153 | static inline void cpsw_add_default_vlan(struct cpsw_priv *priv) |
| 1154 | { |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 1155 | struct cpsw_common *cpsw = priv->cpsw; |
| 1156 | const int vlan = cpsw->data.default_vlan; |
Mugunthan V N | 3b72c2f | 2013-02-05 08:26:48 +0000 | [diff] [blame] | 1157 | u32 reg; |
| 1158 | int i; |
Lennart Sorensen | 1e5c4bc | 2014-10-31 13:38:52 -0400 | [diff] [blame] | 1159 | int unreg_mcast_mask; |
Mugunthan V N | 3b72c2f | 2013-02-05 08:26:48 +0000 | [diff] [blame] | 1160 | |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 1161 | reg = (cpsw->version == CPSW_VERSION_1) ? CPSW1_PORT_VLAN : |
Mugunthan V N | 3b72c2f | 2013-02-05 08:26:48 +0000 | [diff] [blame] | 1162 | CPSW2_PORT_VLAN; |
| 1163 | |
Ivan Khoronzhuk | 5d8d0d4 | 2016-08-10 02:22:39 +0300 | [diff] [blame] | 1164 | writel(vlan, &cpsw->host_port_regs->port_vlan); |
Mugunthan V N | 3b72c2f | 2013-02-05 08:26:48 +0000 | [diff] [blame] | 1165 | |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 1166 | for (i = 0; i < cpsw->data.slaves; i++) |
| 1167 | slave_write(cpsw->slaves + i, vlan, reg); |
Mugunthan V N | 3b72c2f | 2013-02-05 08:26:48 +0000 | [diff] [blame] | 1168 | |
Lennart Sorensen | 1e5c4bc | 2014-10-31 13:38:52 -0400 | [diff] [blame] | 1169 | if (priv->ndev->flags & IFF_ALLMULTI) |
| 1170 | unreg_mcast_mask = ALE_ALL_PORTS; |
| 1171 | else |
| 1172 | unreg_mcast_mask = ALE_PORT_1 | ALE_PORT_2; |
| 1173 | |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 1174 | cpsw_ale_add_vlan(cpsw->ale, vlan, ALE_ALL_PORTS, |
Grygorii Strashko | 61f1cef | 2016-04-07 15:16:43 +0300 | [diff] [blame] | 1175 | ALE_ALL_PORTS, ALE_ALL_PORTS, |
| 1176 | unreg_mcast_mask); |
Mugunthan V N | 3b72c2f | 2013-02-05 08:26:48 +0000 | [diff] [blame] | 1177 | } |
| 1178 | |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1179 | static void cpsw_init_host_port(struct cpsw_priv *priv) |
| 1180 | { |
Mugunthan V N | d9ba8f9 | 2013-02-11 09:52:20 +0000 | [diff] [blame] | 1181 | u32 fifo_mode; |
Ivan Khoronzhuk | 5d8d0d4 | 2016-08-10 02:22:39 +0300 | [diff] [blame] | 1182 | u32 control_reg; |
| 1183 | struct cpsw_common *cpsw = priv->cpsw; |
Mugunthan V N | 3b72c2f | 2013-02-05 08:26:48 +0000 | [diff] [blame] | 1184 | |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1185 | /* soft reset the controller and initialize ale */ |
Ivan Khoronzhuk | 5d8d0d4 | 2016-08-10 02:22:39 +0300 | [diff] [blame] | 1186 | soft_reset("cpsw", &cpsw->regs->soft_reset); |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 1187 | cpsw_ale_start(cpsw->ale); |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1188 | |
| 1189 | /* switch to vlan unaware mode */ |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 1190 | cpsw_ale_control_set(cpsw->ale, HOST_PORT_NUM, ALE_VLAN_AWARE, |
Mugunthan V N | 3b72c2f | 2013-02-05 08:26:48 +0000 | [diff] [blame] | 1191 | CPSW_ALE_VLAN_AWARE); |
Ivan Khoronzhuk | 5d8d0d4 | 2016-08-10 02:22:39 +0300 | [diff] [blame] | 1192 | control_reg = readl(&cpsw->regs->control); |
Mugunthan V N | 3b72c2f | 2013-02-05 08:26:48 +0000 | [diff] [blame] | 1193 | control_reg |= CPSW_VLAN_AWARE; |
Ivan Khoronzhuk | 5d8d0d4 | 2016-08-10 02:22:39 +0300 | [diff] [blame] | 1194 | writel(control_reg, &cpsw->regs->control); |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 1195 | fifo_mode = (cpsw->data.dual_emac) ? CPSW_FIFO_DUAL_MAC_MODE : |
Mugunthan V N | d9ba8f9 | 2013-02-11 09:52:20 +0000 | [diff] [blame] | 1196 | CPSW_FIFO_NORMAL_MODE; |
Ivan Khoronzhuk | 5d8d0d4 | 2016-08-10 02:22:39 +0300 | [diff] [blame] | 1197 | writel(fifo_mode, &cpsw->host_port_regs->tx_in_ctl); |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1198 | |
| 1199 | /* setup host port priority mapping */ |
| 1200 | __raw_writel(CPDMA_TX_PRIORITY_MAP, |
Ivan Khoronzhuk | 5d8d0d4 | 2016-08-10 02:22:39 +0300 | [diff] [blame] | 1201 | &cpsw->host_port_regs->cpdma_tx_pri_map); |
| 1202 | __raw_writel(0, &cpsw->host_port_regs->cpdma_rx_chan_map); |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1203 | |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 1204 | cpsw_ale_control_set(cpsw->ale, HOST_PORT_NUM, |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1205 | ALE_PORT_STATE, ALE_PORT_STATE_FORWARD); |
| 1206 | |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 1207 | if (!cpsw->data.dual_emac) { |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 1208 | cpsw_ale_add_ucast(cpsw->ale, priv->mac_addr, HOST_PORT_NUM, |
Mugunthan V N | d9ba8f9 | 2013-02-11 09:52:20 +0000 | [diff] [blame] | 1209 | 0, 0); |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 1210 | cpsw_ale_add_mcast(cpsw->ale, priv->ndev->broadcast, |
Grygorii Strashko | 71a2cbb | 2016-04-07 15:16:44 +0300 | [diff] [blame] | 1211 | ALE_PORT_HOST, 0, 0, ALE_MCAST_FWD_2); |
Mugunthan V N | d9ba8f9 | 2013-02-11 09:52:20 +0000 | [diff] [blame] | 1212 | } |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1213 | } |
| 1214 | |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 1215 | static void cpsw_slave_stop(struct cpsw_slave *slave, struct cpsw_common *cpsw) |
Sebastian Siewior | aacebbf | 2013-04-23 07:31:36 +0000 | [diff] [blame] | 1216 | { |
Schuyler Patton | 3995d26 | 2014-03-03 16:19:06 +0530 | [diff] [blame] | 1217 | u32 slave_port; |
| 1218 | |
Ivan Khoronzhuk | 6f1f583 | 2016-08-10 02:22:34 +0300 | [diff] [blame] | 1219 | slave_port = cpsw_get_slave_port(slave->slave_num); |
Schuyler Patton | 3995d26 | 2014-03-03 16:19:06 +0530 | [diff] [blame] | 1220 | |
Sebastian Siewior | aacebbf | 2013-04-23 07:31:36 +0000 | [diff] [blame] | 1221 | if (!slave->phy) |
| 1222 | return; |
| 1223 | phy_stop(slave->phy); |
| 1224 | phy_disconnect(slave->phy); |
| 1225 | slave->phy = NULL; |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 1226 | cpsw_ale_control_set(cpsw->ale, slave_port, |
Schuyler Patton | 3995d26 | 2014-03-03 16:19:06 +0530 | [diff] [blame] | 1227 | ALE_PORT_STATE, ALE_PORT_STATE_DISABLE); |
Grygorii Strashko | 1f95ba0 | 2016-06-24 21:23:41 +0300 | [diff] [blame] | 1228 | soft_reset_slave(slave); |
Sebastian Siewior | aacebbf | 2013-04-23 07:31:36 +0000 | [diff] [blame] | 1229 | } |
| 1230 | |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1231 | static int cpsw_ndo_open(struct net_device *ndev) |
| 1232 | { |
| 1233 | struct cpsw_priv *priv = netdev_priv(ndev); |
Ivan Khoronzhuk | 649a168 | 2016-08-10 02:22:37 +0300 | [diff] [blame] | 1234 | struct cpsw_common *cpsw = priv->cpsw; |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1235 | int i, ret; |
| 1236 | u32 reg; |
| 1237 | |
Ivan Khoronzhuk | 56e31bd | 2016-08-10 02:22:38 +0300 | [diff] [blame] | 1238 | ret = pm_runtime_get_sync(cpsw->dev); |
Grygorii Strashko | 108a653 | 2016-06-24 21:23:42 +0300 | [diff] [blame] | 1239 | if (ret < 0) { |
Ivan Khoronzhuk | 56e31bd | 2016-08-10 02:22:38 +0300 | [diff] [blame] | 1240 | pm_runtime_put_noidle(cpsw->dev); |
Grygorii Strashko | 108a653 | 2016-06-24 21:23:42 +0300 | [diff] [blame] | 1241 | return ret; |
| 1242 | } |
Grygorii Strashko | 3fa88c5 | 2016-04-19 21:09:49 +0300 | [diff] [blame] | 1243 | |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 1244 | if (!cpsw_common_res_usage_state(cpsw)) |
Ivan Khoronzhuk | 2c836bd | 2016-08-10 02:22:40 +0300 | [diff] [blame] | 1245 | cpsw_intr_disable(cpsw); |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1246 | netif_carrier_off(ndev); |
| 1247 | |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 1248 | reg = cpsw->version; |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1249 | |
| 1250 | dev_info(priv->dev, "initializing cpsw version %d.%d (%d)\n", |
| 1251 | CPSW_MAJOR_VERSION(reg), CPSW_MINOR_VERSION(reg), |
| 1252 | CPSW_RTL_VERSION(reg)); |
| 1253 | |
| 1254 | /* initialize host and slave ports */ |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 1255 | if (!cpsw_common_res_usage_state(cpsw)) |
Mugunthan V N | d9ba8f9 | 2013-02-11 09:52:20 +0000 | [diff] [blame] | 1256 | cpsw_init_host_port(priv); |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1257 | for_each_slave(priv, cpsw_slave_open, priv); |
| 1258 | |
Mugunthan V N | 3b72c2f | 2013-02-05 08:26:48 +0000 | [diff] [blame] | 1259 | /* Add default VLAN */ |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 1260 | if (!cpsw->data.dual_emac) |
Mugunthan V N | e6afea0 | 2014-06-18 17:21:48 +0530 | [diff] [blame] | 1261 | cpsw_add_default_vlan(priv); |
| 1262 | else |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 1263 | cpsw_ale_add_vlan(cpsw->ale, cpsw->data.default_vlan, |
Grygorii Strashko | 61f1cef | 2016-04-07 15:16:43 +0300 | [diff] [blame] | 1264 | ALE_ALL_PORTS, ALE_ALL_PORTS, 0, 0); |
Mugunthan V N | 3b72c2f | 2013-02-05 08:26:48 +0000 | [diff] [blame] | 1265 | |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 1266 | if (!cpsw_common_res_usage_state(cpsw)) { |
Ivan Khoronzhuk | 1793331 | 2016-06-17 13:25:39 +0300 | [diff] [blame] | 1267 | int buf_num; |
Mugunthan V N | d354eb8 | 2015-08-04 16:06:19 +0530 | [diff] [blame] | 1268 | |
Mugunthan V N | d9ba8f9 | 2013-02-11 09:52:20 +0000 | [diff] [blame] | 1269 | /* setup tx dma to fixed prio and zero offset */ |
Ivan Khoronzhuk | 2c836bd | 2016-08-10 02:22:40 +0300 | [diff] [blame] | 1270 | cpdma_control_set(cpsw->dma, CPDMA_TX_PRIO_FIXED, 1); |
| 1271 | cpdma_control_set(cpsw->dma, CPDMA_RX_BUFFER_OFFSET, 0); |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1272 | |
Mugunthan V N | d9ba8f9 | 2013-02-11 09:52:20 +0000 | [diff] [blame] | 1273 | /* disable priority elevation */ |
Ivan Khoronzhuk | 5d8d0d4 | 2016-08-10 02:22:39 +0300 | [diff] [blame] | 1274 | __raw_writel(0, &cpsw->regs->ptype); |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1275 | |
Mugunthan V N | d9ba8f9 | 2013-02-11 09:52:20 +0000 | [diff] [blame] | 1276 | /* enable statistics collection only on all ports */ |
Ivan Khoronzhuk | 5d8d0d4 | 2016-08-10 02:22:39 +0300 | [diff] [blame] | 1277 | __raw_writel(0x7, &cpsw->regs->stat_port_en); |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1278 | |
Mugunthan V N | 1923d6e | 2014-09-08 22:54:02 +0530 | [diff] [blame] | 1279 | /* Enable internal fifo flow control */ |
Ivan Khoronzhuk | 5d8d0d4 | 2016-08-10 02:22:39 +0300 | [diff] [blame] | 1280 | writel(0x7, &cpsw->regs->flow_control); |
Mugunthan V N | 1923d6e | 2014-09-08 22:54:02 +0530 | [diff] [blame] | 1281 | |
Ivan Khoronzhuk | dbc4ec5 | 2016-08-10 02:22:43 +0300 | [diff] [blame] | 1282 | napi_enable(&cpsw->napi_rx); |
| 1283 | napi_enable(&cpsw->napi_tx); |
Mugunthan V N | d354eb8 | 2015-08-04 16:06:19 +0530 | [diff] [blame] | 1284 | |
Ivan Khoronzhuk | e38b5a3 | 2016-08-10 02:22:41 +0300 | [diff] [blame] | 1285 | if (cpsw->tx_irq_disabled) { |
| 1286 | cpsw->tx_irq_disabled = false; |
| 1287 | enable_irq(cpsw->irqs_table[1]); |
Mugunthan V N | 7da1160 | 2015-08-12 15:22:53 +0530 | [diff] [blame] | 1288 | } |
| 1289 | |
Ivan Khoronzhuk | e38b5a3 | 2016-08-10 02:22:41 +0300 | [diff] [blame] | 1290 | if (cpsw->rx_irq_disabled) { |
| 1291 | cpsw->rx_irq_disabled = false; |
| 1292 | enable_irq(cpsw->irqs_table[0]); |
Mugunthan V N | 7da1160 | 2015-08-12 15:22:53 +0530 | [diff] [blame] | 1293 | } |
| 1294 | |
Ivan Khoronzhuk | 2c836bd | 2016-08-10 02:22:40 +0300 | [diff] [blame] | 1295 | buf_num = cpdma_chan_get_rx_buf_num(cpsw->dma); |
Ivan Khoronzhuk | 1793331 | 2016-06-17 13:25:39 +0300 | [diff] [blame] | 1296 | for (i = 0; i < buf_num; i++) { |
Mugunthan V N | d9ba8f9 | 2013-02-11 09:52:20 +0000 | [diff] [blame] | 1297 | struct sk_buff *skb; |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1298 | |
Mugunthan V N | d9ba8f9 | 2013-02-11 09:52:20 +0000 | [diff] [blame] | 1299 | ret = -ENOMEM; |
Sebastian Siewior | aacebbf | 2013-04-23 07:31:36 +0000 | [diff] [blame] | 1300 | skb = __netdev_alloc_skb_ip_align(priv->ndev, |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 1301 | cpsw->rx_packet_max, GFP_KERNEL); |
Mugunthan V N | d9ba8f9 | 2013-02-11 09:52:20 +0000 | [diff] [blame] | 1302 | if (!skb) |
Sebastian Siewior | aacebbf | 2013-04-23 07:31:36 +0000 | [diff] [blame] | 1303 | goto err_cleanup; |
Ivan Khoronzhuk | 2c836bd | 2016-08-10 02:22:40 +0300 | [diff] [blame] | 1304 | ret = cpdma_chan_submit(cpsw->rxch, skb, skb->data, |
| 1305 | skb_tailroom(skb), 0); |
Sebastian Siewior | aacebbf | 2013-04-23 07:31:36 +0000 | [diff] [blame] | 1306 | if (ret < 0) { |
| 1307 | kfree_skb(skb); |
| 1308 | goto err_cleanup; |
| 1309 | } |
Mugunthan V N | d9ba8f9 | 2013-02-11 09:52:20 +0000 | [diff] [blame] | 1310 | } |
| 1311 | /* continue even if we didn't manage to submit all |
| 1312 | * receive descs |
| 1313 | */ |
| 1314 | cpsw_info(priv, ifup, "submitted %d rx descriptors\n", i); |
Mugunthan V N | f280e89 | 2013-12-11 22:09:05 -0600 | [diff] [blame] | 1315 | |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 1316 | if (cpts_register(cpsw->dev, cpsw->cpts, |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 1317 | cpsw->data.cpts_clock_mult, |
| 1318 | cpsw->data.cpts_clock_shift)) |
Mugunthan V N | f280e89 | 2013-12-11 22:09:05 -0600 | [diff] [blame] | 1319 | dev_err(priv->dev, "error registering cpts device\n"); |
| 1320 | |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1321 | } |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1322 | |
Mugunthan V N | ff5b8ef | 2013-03-11 23:16:37 +0000 | [diff] [blame] | 1323 | /* Enable Interrupt pacing if configured */ |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 1324 | if (cpsw->coal_intvl != 0) { |
Mugunthan V N | ff5b8ef | 2013-03-11 23:16:37 +0000 | [diff] [blame] | 1325 | struct ethtool_coalesce coal; |
| 1326 | |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 1327 | coal.rx_coalesce_usecs = cpsw->coal_intvl; |
Mugunthan V N | ff5b8ef | 2013-03-11 23:16:37 +0000 | [diff] [blame] | 1328 | cpsw_set_coalesce(ndev, &coal); |
| 1329 | } |
| 1330 | |
Ivan Khoronzhuk | 2c836bd | 2016-08-10 02:22:40 +0300 | [diff] [blame] | 1331 | cpdma_ctlr_start(cpsw->dma); |
| 1332 | cpsw_intr_enable(cpsw); |
Mugunthan V N | f63a975 | 2014-04-10 14:23:24 +0530 | [diff] [blame] | 1333 | |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 1334 | if (cpsw->data.dual_emac) |
| 1335 | cpsw->slaves[priv->emac_port].open_stat = true; |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1336 | return 0; |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1337 | |
Sebastian Siewior | aacebbf | 2013-04-23 07:31:36 +0000 | [diff] [blame] | 1338 | err_cleanup: |
Ivan Khoronzhuk | 2c836bd | 2016-08-10 02:22:40 +0300 | [diff] [blame] | 1339 | cpdma_ctlr_stop(cpsw->dma); |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 1340 | for_each_slave(priv, cpsw_slave_stop, cpsw); |
Ivan Khoronzhuk | 56e31bd | 2016-08-10 02:22:38 +0300 | [diff] [blame] | 1341 | pm_runtime_put_sync(cpsw->dev); |
Sebastian Siewior | aacebbf | 2013-04-23 07:31:36 +0000 | [diff] [blame] | 1342 | netif_carrier_off(priv->ndev); |
| 1343 | return ret; |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1344 | } |
| 1345 | |
| 1346 | static int cpsw_ndo_stop(struct net_device *ndev) |
| 1347 | { |
| 1348 | struct cpsw_priv *priv = netdev_priv(ndev); |
Ivan Khoronzhuk | 649a168 | 2016-08-10 02:22:37 +0300 | [diff] [blame] | 1349 | struct cpsw_common *cpsw = priv->cpsw; |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1350 | |
| 1351 | cpsw_info(priv, ifdown, "shutting down cpsw device\n"); |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1352 | netif_stop_queue(priv->ndev); |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1353 | netif_carrier_off(priv->ndev); |
Mugunthan V N | d9ba8f9 | 2013-02-11 09:52:20 +0000 | [diff] [blame] | 1354 | |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 1355 | if (cpsw_common_res_usage_state(cpsw) <= 1) { |
Ivan Khoronzhuk | dbc4ec5 | 2016-08-10 02:22:43 +0300 | [diff] [blame] | 1356 | napi_disable(&cpsw->napi_rx); |
| 1357 | napi_disable(&cpsw->napi_tx); |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 1358 | cpts_unregister(cpsw->cpts); |
Ivan Khoronzhuk | 2c836bd | 2016-08-10 02:22:40 +0300 | [diff] [blame] | 1359 | cpsw_intr_disable(cpsw); |
| 1360 | cpdma_ctlr_stop(cpsw->dma); |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 1361 | cpsw_ale_stop(cpsw->ale); |
Mugunthan V N | d9ba8f9 | 2013-02-11 09:52:20 +0000 | [diff] [blame] | 1362 | } |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 1363 | for_each_slave(priv, cpsw_slave_stop, cpsw); |
Ivan Khoronzhuk | 56e31bd | 2016-08-10 02:22:38 +0300 | [diff] [blame] | 1364 | pm_runtime_put_sync(cpsw->dev); |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 1365 | if (cpsw->data.dual_emac) |
| 1366 | cpsw->slaves[priv->emac_port].open_stat = false; |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1367 | return 0; |
| 1368 | } |
| 1369 | |
| 1370 | static netdev_tx_t cpsw_ndo_start_xmit(struct sk_buff *skb, |
| 1371 | struct net_device *ndev) |
| 1372 | { |
| 1373 | struct cpsw_priv *priv = netdev_priv(ndev); |
| 1374 | int ret; |
Ivan Khoronzhuk | 2c836bd | 2016-08-10 02:22:40 +0300 | [diff] [blame] | 1375 | struct cpsw_common *cpsw = priv->cpsw; |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1376 | |
Florian Westphal | 860e953 | 2016-05-03 16:33:13 +0200 | [diff] [blame] | 1377 | netif_trans_update(ndev); |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1378 | |
| 1379 | if (skb_padto(skb, CPSW_MIN_PACKET_SIZE)) { |
| 1380 | cpsw_err(priv, tx_err, "packet pad failed\n"); |
Tobias Klauser | 8dc43dd | 2014-03-10 13:12:23 +0100 | [diff] [blame] | 1381 | ndev->stats.tx_dropped++; |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1382 | return NETDEV_TX_OK; |
| 1383 | } |
| 1384 | |
Mugunthan V N | 9232b16 | 2013-02-11 09:52:19 +0000 | [diff] [blame] | 1385 | if (skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP && |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 1386 | cpsw->cpts->tx_enable) |
Richard Cochran | 2e5b38a | 2012-10-29 08:45:20 +0000 | [diff] [blame] | 1387 | skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS; |
| 1388 | |
| 1389 | skb_tx_timestamp(skb); |
| 1390 | |
Ivan Khoronzhuk | 27e9e10 | 2016-08-10 02:22:32 +0300 | [diff] [blame] | 1391 | ret = cpsw_tx_packet_submit(priv, skb); |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1392 | if (unlikely(ret != 0)) { |
| 1393 | cpsw_err(priv, tx_err, "desc submit failed\n"); |
| 1394 | goto fail; |
| 1395 | } |
| 1396 | |
Mugunthan V N | fae5082 | 2013-01-17 06:31:34 +0000 | [diff] [blame] | 1397 | /* If there is no more tx desc left free then we need to |
| 1398 | * tell the kernel to stop sending us tx frames. |
| 1399 | */ |
Ivan Khoronzhuk | 2c836bd | 2016-08-10 02:22:40 +0300 | [diff] [blame] | 1400 | if (unlikely(!cpdma_check_free_tx_desc(cpsw->txch))) |
Mugunthan V N | fae5082 | 2013-01-17 06:31:34 +0000 | [diff] [blame] | 1401 | netif_stop_queue(ndev); |
| 1402 | |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1403 | return NETDEV_TX_OK; |
| 1404 | fail: |
Tobias Klauser | 8dc43dd | 2014-03-10 13:12:23 +0100 | [diff] [blame] | 1405 | ndev->stats.tx_dropped++; |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1406 | netif_stop_queue(ndev); |
| 1407 | return NETDEV_TX_BUSY; |
| 1408 | } |
| 1409 | |
Richard Cochran | 2e5b38a | 2012-10-29 08:45:20 +0000 | [diff] [blame] | 1410 | #ifdef CONFIG_TI_CPTS |
| 1411 | |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 1412 | static void cpsw_hwtstamp_v1(struct cpsw_common *cpsw) |
Richard Cochran | 2e5b38a | 2012-10-29 08:45:20 +0000 | [diff] [blame] | 1413 | { |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 1414 | struct cpsw_slave *slave = &cpsw->slaves[cpsw->data.active_slave]; |
Richard Cochran | 2e5b38a | 2012-10-29 08:45:20 +0000 | [diff] [blame] | 1415 | u32 ts_en, seq_id; |
| 1416 | |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 1417 | if (!cpsw->cpts->tx_enable && !cpsw->cpts->rx_enable) { |
Richard Cochran | 2e5b38a | 2012-10-29 08:45:20 +0000 | [diff] [blame] | 1418 | slave_write(slave, 0, CPSW1_TS_CTL); |
| 1419 | return; |
| 1420 | } |
| 1421 | |
| 1422 | seq_id = (30 << CPSW_V1_SEQ_ID_OFS_SHIFT) | ETH_P_1588; |
| 1423 | ts_en = EVENT_MSG_BITS << CPSW_V1_MSG_TYPE_OFS; |
| 1424 | |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 1425 | if (cpsw->cpts->tx_enable) |
Richard Cochran | 2e5b38a | 2012-10-29 08:45:20 +0000 | [diff] [blame] | 1426 | ts_en |= CPSW_V1_TS_TX_EN; |
| 1427 | |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 1428 | if (cpsw->cpts->rx_enable) |
Richard Cochran | 2e5b38a | 2012-10-29 08:45:20 +0000 | [diff] [blame] | 1429 | ts_en |= CPSW_V1_TS_RX_EN; |
| 1430 | |
| 1431 | slave_write(slave, ts_en, CPSW1_TS_CTL); |
| 1432 | slave_write(slave, seq_id, CPSW1_TS_SEQ_LTYPE); |
| 1433 | } |
| 1434 | |
| 1435 | static void cpsw_hwtstamp_v2(struct cpsw_priv *priv) |
| 1436 | { |
Mugunthan V N | d9ba8f9 | 2013-02-11 09:52:20 +0000 | [diff] [blame] | 1437 | struct cpsw_slave *slave; |
Ivan Khoronzhuk | 5d8d0d4 | 2016-08-10 02:22:39 +0300 | [diff] [blame] | 1438 | struct cpsw_common *cpsw = priv->cpsw; |
Richard Cochran | 2e5b38a | 2012-10-29 08:45:20 +0000 | [diff] [blame] | 1439 | u32 ctrl, mtype; |
| 1440 | |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 1441 | if (cpsw->data.dual_emac) |
| 1442 | slave = &cpsw->slaves[priv->emac_port]; |
Mugunthan V N | d9ba8f9 | 2013-02-11 09:52:20 +0000 | [diff] [blame] | 1443 | else |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 1444 | slave = &cpsw->slaves[cpsw->data.active_slave]; |
Mugunthan V N | d9ba8f9 | 2013-02-11 09:52:20 +0000 | [diff] [blame] | 1445 | |
Richard Cochran | 2e5b38a | 2012-10-29 08:45:20 +0000 | [diff] [blame] | 1446 | ctrl = slave_read(slave, CPSW2_CONTROL); |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 1447 | switch (cpsw->version) { |
George Cherian | 09c5537 | 2014-05-02 12:02:02 +0530 | [diff] [blame] | 1448 | case CPSW_VERSION_2: |
| 1449 | ctrl &= ~CTRL_V2_ALL_TS_MASK; |
Richard Cochran | 2e5b38a | 2012-10-29 08:45:20 +0000 | [diff] [blame] | 1450 | |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 1451 | if (cpsw->cpts->tx_enable) |
George Cherian | 09c5537 | 2014-05-02 12:02:02 +0530 | [diff] [blame] | 1452 | ctrl |= CTRL_V2_TX_TS_BITS; |
Richard Cochran | 2e5b38a | 2012-10-29 08:45:20 +0000 | [diff] [blame] | 1453 | |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 1454 | if (cpsw->cpts->rx_enable) |
George Cherian | 09c5537 | 2014-05-02 12:02:02 +0530 | [diff] [blame] | 1455 | ctrl |= CTRL_V2_RX_TS_BITS; |
Richard Cochran | 26fe7eb | 2015-05-25 11:02:13 +0200 | [diff] [blame] | 1456 | break; |
George Cherian | 09c5537 | 2014-05-02 12:02:02 +0530 | [diff] [blame] | 1457 | case CPSW_VERSION_3: |
| 1458 | default: |
| 1459 | ctrl &= ~CTRL_V3_ALL_TS_MASK; |
| 1460 | |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 1461 | if (cpsw->cpts->tx_enable) |
George Cherian | 09c5537 | 2014-05-02 12:02:02 +0530 | [diff] [blame] | 1462 | ctrl |= CTRL_V3_TX_TS_BITS; |
| 1463 | |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 1464 | if (cpsw->cpts->rx_enable) |
George Cherian | 09c5537 | 2014-05-02 12:02:02 +0530 | [diff] [blame] | 1465 | ctrl |= CTRL_V3_RX_TS_BITS; |
Richard Cochran | 26fe7eb | 2015-05-25 11:02:13 +0200 | [diff] [blame] | 1466 | break; |
George Cherian | 09c5537 | 2014-05-02 12:02:02 +0530 | [diff] [blame] | 1467 | } |
Richard Cochran | 2e5b38a | 2012-10-29 08:45:20 +0000 | [diff] [blame] | 1468 | |
| 1469 | mtype = (30 << TS_SEQ_ID_OFFSET_SHIFT) | EVENT_MSG_BITS; |
| 1470 | |
| 1471 | slave_write(slave, mtype, CPSW2_TS_SEQ_MTYPE); |
| 1472 | slave_write(slave, ctrl, CPSW2_CONTROL); |
Ivan Khoronzhuk | 5d8d0d4 | 2016-08-10 02:22:39 +0300 | [diff] [blame] | 1473 | __raw_writel(ETH_P_1588, &cpsw->regs->ts_ltype); |
Richard Cochran | 2e5b38a | 2012-10-29 08:45:20 +0000 | [diff] [blame] | 1474 | } |
| 1475 | |
Ben Hutchings | a5b4145 | 2013-11-18 23:23:40 +0000 | [diff] [blame] | 1476 | static int cpsw_hwtstamp_set(struct net_device *dev, struct ifreq *ifr) |
Richard Cochran | 2e5b38a | 2012-10-29 08:45:20 +0000 | [diff] [blame] | 1477 | { |
Mugunthan V N | 3177bf6 | 2012-11-27 07:53:40 +0000 | [diff] [blame] | 1478 | struct cpsw_priv *priv = netdev_priv(dev); |
Richard Cochran | 2e5b38a | 2012-10-29 08:45:20 +0000 | [diff] [blame] | 1479 | struct hwtstamp_config cfg; |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 1480 | struct cpsw_common *cpsw = priv->cpsw; |
| 1481 | struct cpts *cpts = cpsw->cpts; |
Richard Cochran | 2e5b38a | 2012-10-29 08:45:20 +0000 | [diff] [blame] | 1482 | |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 1483 | if (cpsw->version != CPSW_VERSION_1 && |
| 1484 | cpsw->version != CPSW_VERSION_2 && |
| 1485 | cpsw->version != CPSW_VERSION_3) |
Ben Hutchings | 2ee91e5 | 2013-11-14 00:47:36 +0000 | [diff] [blame] | 1486 | return -EOPNOTSUPP; |
| 1487 | |
Richard Cochran | 2e5b38a | 2012-10-29 08:45:20 +0000 | [diff] [blame] | 1488 | if (copy_from_user(&cfg, ifr->ifr_data, sizeof(cfg))) |
| 1489 | return -EFAULT; |
| 1490 | |
| 1491 | /* reserved for future extensions */ |
| 1492 | if (cfg.flags) |
| 1493 | return -EINVAL; |
| 1494 | |
Ben Hutchings | 2ee91e5 | 2013-11-14 00:47:36 +0000 | [diff] [blame] | 1495 | if (cfg.tx_type != HWTSTAMP_TX_OFF && cfg.tx_type != HWTSTAMP_TX_ON) |
Richard Cochran | 2e5b38a | 2012-10-29 08:45:20 +0000 | [diff] [blame] | 1496 | return -ERANGE; |
Richard Cochran | 2e5b38a | 2012-10-29 08:45:20 +0000 | [diff] [blame] | 1497 | |
| 1498 | switch (cfg.rx_filter) { |
| 1499 | case HWTSTAMP_FILTER_NONE: |
| 1500 | cpts->rx_enable = 0; |
| 1501 | break; |
| 1502 | case HWTSTAMP_FILTER_ALL: |
| 1503 | case HWTSTAMP_FILTER_PTP_V1_L4_EVENT: |
| 1504 | case HWTSTAMP_FILTER_PTP_V1_L4_SYNC: |
| 1505 | case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ: |
| 1506 | return -ERANGE; |
| 1507 | case HWTSTAMP_FILTER_PTP_V2_L4_EVENT: |
| 1508 | case HWTSTAMP_FILTER_PTP_V2_L4_SYNC: |
| 1509 | case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ: |
| 1510 | case HWTSTAMP_FILTER_PTP_V2_L2_EVENT: |
| 1511 | case HWTSTAMP_FILTER_PTP_V2_L2_SYNC: |
| 1512 | case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ: |
| 1513 | case HWTSTAMP_FILTER_PTP_V2_EVENT: |
| 1514 | case HWTSTAMP_FILTER_PTP_V2_SYNC: |
| 1515 | case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ: |
| 1516 | cpts->rx_enable = 1; |
| 1517 | cfg.rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT; |
| 1518 | break; |
| 1519 | default: |
| 1520 | return -ERANGE; |
| 1521 | } |
| 1522 | |
Ben Hutchings | 2ee91e5 | 2013-11-14 00:47:36 +0000 | [diff] [blame] | 1523 | cpts->tx_enable = cfg.tx_type == HWTSTAMP_TX_ON; |
| 1524 | |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 1525 | switch (cpsw->version) { |
Richard Cochran | 2e5b38a | 2012-10-29 08:45:20 +0000 | [diff] [blame] | 1526 | case CPSW_VERSION_1: |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 1527 | cpsw_hwtstamp_v1(cpsw); |
Richard Cochran | 2e5b38a | 2012-10-29 08:45:20 +0000 | [diff] [blame] | 1528 | break; |
| 1529 | case CPSW_VERSION_2: |
George Cherian | f7d403c | 2014-05-02 12:02:01 +0530 | [diff] [blame] | 1530 | case CPSW_VERSION_3: |
Richard Cochran | 2e5b38a | 2012-10-29 08:45:20 +0000 | [diff] [blame] | 1531 | cpsw_hwtstamp_v2(priv); |
| 1532 | break; |
| 1533 | default: |
Ben Hutchings | 2ee91e5 | 2013-11-14 00:47:36 +0000 | [diff] [blame] | 1534 | WARN_ON(1); |
Richard Cochran | 2e5b38a | 2012-10-29 08:45:20 +0000 | [diff] [blame] | 1535 | } |
| 1536 | |
| 1537 | return copy_to_user(ifr->ifr_data, &cfg, sizeof(cfg)) ? -EFAULT : 0; |
| 1538 | } |
| 1539 | |
Ben Hutchings | a5b4145 | 2013-11-18 23:23:40 +0000 | [diff] [blame] | 1540 | static int cpsw_hwtstamp_get(struct net_device *dev, struct ifreq *ifr) |
| 1541 | { |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 1542 | struct cpsw_common *cpsw = ndev_to_cpsw(dev); |
| 1543 | struct cpts *cpts = cpsw->cpts; |
Ben Hutchings | a5b4145 | 2013-11-18 23:23:40 +0000 | [diff] [blame] | 1544 | struct hwtstamp_config cfg; |
| 1545 | |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 1546 | if (cpsw->version != CPSW_VERSION_1 && |
| 1547 | cpsw->version != CPSW_VERSION_2 && |
| 1548 | cpsw->version != CPSW_VERSION_3) |
Ben Hutchings | a5b4145 | 2013-11-18 23:23:40 +0000 | [diff] [blame] | 1549 | return -EOPNOTSUPP; |
| 1550 | |
| 1551 | cfg.flags = 0; |
| 1552 | cfg.tx_type = cpts->tx_enable ? HWTSTAMP_TX_ON : HWTSTAMP_TX_OFF; |
| 1553 | cfg.rx_filter = (cpts->rx_enable ? |
| 1554 | HWTSTAMP_FILTER_PTP_V2_EVENT : HWTSTAMP_FILTER_NONE); |
| 1555 | |
| 1556 | return copy_to_user(ifr->ifr_data, &cfg, sizeof(cfg)) ? -EFAULT : 0; |
| 1557 | } |
| 1558 | |
Richard Cochran | 2e5b38a | 2012-10-29 08:45:20 +0000 | [diff] [blame] | 1559 | #endif /*CONFIG_TI_CPTS*/ |
| 1560 | |
| 1561 | static int cpsw_ndo_ioctl(struct net_device *dev, struct ifreq *req, int cmd) |
| 1562 | { |
Mugunthan V N | 11f2c98 | 2013-03-11 23:16:38 +0000 | [diff] [blame] | 1563 | struct cpsw_priv *priv = netdev_priv(dev); |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 1564 | struct cpsw_common *cpsw = priv->cpsw; |
| 1565 | int slave_no = cpsw_slave_index(cpsw, priv); |
Mugunthan V N | 11f2c98 | 2013-03-11 23:16:38 +0000 | [diff] [blame] | 1566 | |
Richard Cochran | 2e5b38a | 2012-10-29 08:45:20 +0000 | [diff] [blame] | 1567 | if (!netif_running(dev)) |
| 1568 | return -EINVAL; |
| 1569 | |
Mugunthan V N | 11f2c98 | 2013-03-11 23:16:38 +0000 | [diff] [blame] | 1570 | switch (cmd) { |
Richard Cochran | 2e5b38a | 2012-10-29 08:45:20 +0000 | [diff] [blame] | 1571 | #ifdef CONFIG_TI_CPTS |
Mugunthan V N | 11f2c98 | 2013-03-11 23:16:38 +0000 | [diff] [blame] | 1572 | case SIOCSHWTSTAMP: |
Ben Hutchings | a5b4145 | 2013-11-18 23:23:40 +0000 | [diff] [blame] | 1573 | return cpsw_hwtstamp_set(dev, req); |
| 1574 | case SIOCGHWTSTAMP: |
| 1575 | return cpsw_hwtstamp_get(dev, req); |
Richard Cochran | 2e5b38a | 2012-10-29 08:45:20 +0000 | [diff] [blame] | 1576 | #endif |
Mugunthan V N | 11f2c98 | 2013-03-11 23:16:38 +0000 | [diff] [blame] | 1577 | } |
| 1578 | |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 1579 | if (!cpsw->slaves[slave_no].phy) |
Stefan Sørensen | c1b5994 | 2014-02-16 14:54:25 +0100 | [diff] [blame] | 1580 | return -EOPNOTSUPP; |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 1581 | return phy_mii_ioctl(cpsw->slaves[slave_no].phy, req, cmd); |
Richard Cochran | 2e5b38a | 2012-10-29 08:45:20 +0000 | [diff] [blame] | 1582 | } |
| 1583 | |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1584 | static void cpsw_ndo_tx_timeout(struct net_device *ndev) |
| 1585 | { |
| 1586 | struct cpsw_priv *priv = netdev_priv(ndev); |
Ivan Khoronzhuk | 2c836bd | 2016-08-10 02:22:40 +0300 | [diff] [blame] | 1587 | struct cpsw_common *cpsw = priv->cpsw; |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1588 | |
| 1589 | cpsw_err(priv, tx_err, "transmit timeout, restarting dma\n"); |
Tobias Klauser | 8dc43dd | 2014-03-10 13:12:23 +0100 | [diff] [blame] | 1590 | ndev->stats.tx_errors++; |
Ivan Khoronzhuk | 2c836bd | 2016-08-10 02:22:40 +0300 | [diff] [blame] | 1591 | cpsw_intr_disable(cpsw); |
| 1592 | cpdma_chan_stop(cpsw->txch); |
| 1593 | cpdma_chan_start(cpsw->txch); |
| 1594 | cpsw_intr_enable(cpsw); |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1595 | } |
| 1596 | |
Mugunthan V N | dcfd8d5 | 2013-07-25 23:44:01 +0530 | [diff] [blame] | 1597 | static int cpsw_ndo_set_mac_address(struct net_device *ndev, void *p) |
| 1598 | { |
| 1599 | struct cpsw_priv *priv = netdev_priv(ndev); |
| 1600 | struct sockaddr *addr = (struct sockaddr *)p; |
Ivan Khoronzhuk | 649a168 | 2016-08-10 02:22:37 +0300 | [diff] [blame] | 1601 | struct cpsw_common *cpsw = priv->cpsw; |
Mugunthan V N | dcfd8d5 | 2013-07-25 23:44:01 +0530 | [diff] [blame] | 1602 | int flags = 0; |
| 1603 | u16 vid = 0; |
Grygorii Strashko | a6c5d14 | 2016-06-24 21:23:45 +0300 | [diff] [blame] | 1604 | int ret; |
Mugunthan V N | dcfd8d5 | 2013-07-25 23:44:01 +0530 | [diff] [blame] | 1605 | |
| 1606 | if (!is_valid_ether_addr(addr->sa_data)) |
| 1607 | return -EADDRNOTAVAIL; |
| 1608 | |
Ivan Khoronzhuk | 56e31bd | 2016-08-10 02:22:38 +0300 | [diff] [blame] | 1609 | ret = pm_runtime_get_sync(cpsw->dev); |
Grygorii Strashko | a6c5d14 | 2016-06-24 21:23:45 +0300 | [diff] [blame] | 1610 | if (ret < 0) { |
Ivan Khoronzhuk | 56e31bd | 2016-08-10 02:22:38 +0300 | [diff] [blame] | 1611 | pm_runtime_put_noidle(cpsw->dev); |
Grygorii Strashko | a6c5d14 | 2016-06-24 21:23:45 +0300 | [diff] [blame] | 1612 | return ret; |
| 1613 | } |
| 1614 | |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 1615 | if (cpsw->data.dual_emac) { |
| 1616 | vid = cpsw->slaves[priv->emac_port].port_vlan; |
Mugunthan V N | dcfd8d5 | 2013-07-25 23:44:01 +0530 | [diff] [blame] | 1617 | flags = ALE_VLAN; |
| 1618 | } |
| 1619 | |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 1620 | cpsw_ale_del_ucast(cpsw->ale, priv->mac_addr, HOST_PORT_NUM, |
Mugunthan V N | dcfd8d5 | 2013-07-25 23:44:01 +0530 | [diff] [blame] | 1621 | flags, vid); |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 1622 | cpsw_ale_add_ucast(cpsw->ale, addr->sa_data, HOST_PORT_NUM, |
Mugunthan V N | dcfd8d5 | 2013-07-25 23:44:01 +0530 | [diff] [blame] | 1623 | flags, vid); |
| 1624 | |
| 1625 | memcpy(priv->mac_addr, addr->sa_data, ETH_ALEN); |
| 1626 | memcpy(ndev->dev_addr, priv->mac_addr, ETH_ALEN); |
| 1627 | for_each_slave(priv, cpsw_set_slave_mac, priv); |
| 1628 | |
Ivan Khoronzhuk | 56e31bd | 2016-08-10 02:22:38 +0300 | [diff] [blame] | 1629 | pm_runtime_put(cpsw->dev); |
Grygorii Strashko | a6c5d14 | 2016-06-24 21:23:45 +0300 | [diff] [blame] | 1630 | |
Mugunthan V N | dcfd8d5 | 2013-07-25 23:44:01 +0530 | [diff] [blame] | 1631 | return 0; |
| 1632 | } |
| 1633 | |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1634 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 1635 | static void cpsw_ndo_poll_controller(struct net_device *ndev) |
| 1636 | { |
Ivan Khoronzhuk | dbc4ec5 | 2016-08-10 02:22:43 +0300 | [diff] [blame] | 1637 | struct cpsw_common *cpsw = ndev_to_cpsw(ndev); |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1638 | |
Ivan Khoronzhuk | dbc4ec5 | 2016-08-10 02:22:43 +0300 | [diff] [blame] | 1639 | cpsw_intr_disable(cpsw); |
| 1640 | cpsw_rx_interrupt(cpsw->irqs_table[0], cpsw); |
| 1641 | cpsw_tx_interrupt(cpsw->irqs_table[1], cpsw); |
| 1642 | cpsw_intr_enable(cpsw); |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1643 | } |
| 1644 | #endif |
| 1645 | |
Mugunthan V N | 3b72c2f | 2013-02-05 08:26:48 +0000 | [diff] [blame] | 1646 | static inline int cpsw_add_vlan_ale_entry(struct cpsw_priv *priv, |
| 1647 | unsigned short vid) |
| 1648 | { |
| 1649 | int ret; |
Mugunthan V N | 9f6bd8f | 2015-01-15 14:59:28 +0530 | [diff] [blame] | 1650 | int unreg_mcast_mask = 0; |
| 1651 | u32 port_mask; |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 1652 | struct cpsw_common *cpsw = priv->cpsw; |
Lennart Sorensen | 1e5c4bc | 2014-10-31 13:38:52 -0400 | [diff] [blame] | 1653 | |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 1654 | if (cpsw->data.dual_emac) { |
Mugunthan V N | 9f6bd8f | 2015-01-15 14:59:28 +0530 | [diff] [blame] | 1655 | port_mask = (1 << (priv->emac_port + 1)) | ALE_PORT_HOST; |
Mugunthan V N | 3b72c2f | 2013-02-05 08:26:48 +0000 | [diff] [blame] | 1656 | |
Mugunthan V N | 9f6bd8f | 2015-01-15 14:59:28 +0530 | [diff] [blame] | 1657 | if (priv->ndev->flags & IFF_ALLMULTI) |
| 1658 | unreg_mcast_mask = port_mask; |
| 1659 | } else { |
| 1660 | port_mask = ALE_ALL_PORTS; |
| 1661 | |
| 1662 | if (priv->ndev->flags & IFF_ALLMULTI) |
| 1663 | unreg_mcast_mask = ALE_ALL_PORTS; |
| 1664 | else |
| 1665 | unreg_mcast_mask = ALE_PORT_1 | ALE_PORT_2; |
| 1666 | } |
| 1667 | |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 1668 | ret = cpsw_ale_add_vlan(cpsw->ale, vid, port_mask, 0, port_mask, |
Grygorii Strashko | 61f1cef | 2016-04-07 15:16:43 +0300 | [diff] [blame] | 1669 | unreg_mcast_mask); |
Mugunthan V N | 3b72c2f | 2013-02-05 08:26:48 +0000 | [diff] [blame] | 1670 | if (ret != 0) |
| 1671 | return ret; |
| 1672 | |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 1673 | ret = cpsw_ale_add_ucast(cpsw->ale, priv->mac_addr, |
Grygorii Strashko | 71a2cbb | 2016-04-07 15:16:44 +0300 | [diff] [blame] | 1674 | HOST_PORT_NUM, ALE_VLAN, vid); |
Mugunthan V N | 3b72c2f | 2013-02-05 08:26:48 +0000 | [diff] [blame] | 1675 | if (ret != 0) |
| 1676 | goto clean_vid; |
| 1677 | |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 1678 | ret = cpsw_ale_add_mcast(cpsw->ale, priv->ndev->broadcast, |
Mugunthan V N | 9f6bd8f | 2015-01-15 14:59:28 +0530 | [diff] [blame] | 1679 | port_mask, ALE_VLAN, vid, 0); |
Mugunthan V N | 3b72c2f | 2013-02-05 08:26:48 +0000 | [diff] [blame] | 1680 | if (ret != 0) |
| 1681 | goto clean_vlan_ucast; |
| 1682 | return 0; |
| 1683 | |
| 1684 | clean_vlan_ucast: |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 1685 | cpsw_ale_del_ucast(cpsw->ale, priv->mac_addr, |
Grygorii Strashko | 71a2cbb | 2016-04-07 15:16:44 +0300 | [diff] [blame] | 1686 | HOST_PORT_NUM, ALE_VLAN, vid); |
Mugunthan V N | 3b72c2f | 2013-02-05 08:26:48 +0000 | [diff] [blame] | 1687 | clean_vid: |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 1688 | cpsw_ale_del_vlan(cpsw->ale, vid, 0); |
Mugunthan V N | 3b72c2f | 2013-02-05 08:26:48 +0000 | [diff] [blame] | 1689 | return ret; |
| 1690 | } |
| 1691 | |
| 1692 | static int cpsw_ndo_vlan_rx_add_vid(struct net_device *ndev, |
Patrick McHardy | 80d5c36 | 2013-04-19 02:04:28 +0000 | [diff] [blame] | 1693 | __be16 proto, u16 vid) |
Mugunthan V N | 3b72c2f | 2013-02-05 08:26:48 +0000 | [diff] [blame] | 1694 | { |
| 1695 | struct cpsw_priv *priv = netdev_priv(ndev); |
Ivan Khoronzhuk | 649a168 | 2016-08-10 02:22:37 +0300 | [diff] [blame] | 1696 | struct cpsw_common *cpsw = priv->cpsw; |
Grygorii Strashko | a6c5d14 | 2016-06-24 21:23:45 +0300 | [diff] [blame] | 1697 | int ret; |
Mugunthan V N | 3b72c2f | 2013-02-05 08:26:48 +0000 | [diff] [blame] | 1698 | |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 1699 | if (vid == cpsw->data.default_vlan) |
Mugunthan V N | 3b72c2f | 2013-02-05 08:26:48 +0000 | [diff] [blame] | 1700 | return 0; |
| 1701 | |
Ivan Khoronzhuk | 56e31bd | 2016-08-10 02:22:38 +0300 | [diff] [blame] | 1702 | ret = pm_runtime_get_sync(cpsw->dev); |
Grygorii Strashko | a6c5d14 | 2016-06-24 21:23:45 +0300 | [diff] [blame] | 1703 | if (ret < 0) { |
Ivan Khoronzhuk | 56e31bd | 2016-08-10 02:22:38 +0300 | [diff] [blame] | 1704 | pm_runtime_put_noidle(cpsw->dev); |
Grygorii Strashko | a6c5d14 | 2016-06-24 21:23:45 +0300 | [diff] [blame] | 1705 | return ret; |
| 1706 | } |
| 1707 | |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 1708 | if (cpsw->data.dual_emac) { |
Mugunthan V N | 02a5416 | 2015-01-22 15:19:22 +0530 | [diff] [blame] | 1709 | /* In dual EMAC, reserved VLAN id should not be used for |
| 1710 | * creating VLAN interfaces as this can break the dual |
| 1711 | * EMAC port separation |
| 1712 | */ |
| 1713 | int i; |
| 1714 | |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 1715 | for (i = 0; i < cpsw->data.slaves; i++) { |
| 1716 | if (vid == cpsw->slaves[i].port_vlan) |
Mugunthan V N | 02a5416 | 2015-01-22 15:19:22 +0530 | [diff] [blame] | 1717 | return -EINVAL; |
| 1718 | } |
| 1719 | } |
| 1720 | |
Mugunthan V N | 3b72c2f | 2013-02-05 08:26:48 +0000 | [diff] [blame] | 1721 | dev_info(priv->dev, "Adding vlanid %d to vlan filter\n", vid); |
Grygorii Strashko | a6c5d14 | 2016-06-24 21:23:45 +0300 | [diff] [blame] | 1722 | ret = cpsw_add_vlan_ale_entry(priv, vid); |
| 1723 | |
Ivan Khoronzhuk | 56e31bd | 2016-08-10 02:22:38 +0300 | [diff] [blame] | 1724 | pm_runtime_put(cpsw->dev); |
Grygorii Strashko | a6c5d14 | 2016-06-24 21:23:45 +0300 | [diff] [blame] | 1725 | return ret; |
Mugunthan V N | 3b72c2f | 2013-02-05 08:26:48 +0000 | [diff] [blame] | 1726 | } |
| 1727 | |
| 1728 | static int cpsw_ndo_vlan_rx_kill_vid(struct net_device *ndev, |
Patrick McHardy | 80d5c36 | 2013-04-19 02:04:28 +0000 | [diff] [blame] | 1729 | __be16 proto, u16 vid) |
Mugunthan V N | 3b72c2f | 2013-02-05 08:26:48 +0000 | [diff] [blame] | 1730 | { |
| 1731 | struct cpsw_priv *priv = netdev_priv(ndev); |
Ivan Khoronzhuk | 649a168 | 2016-08-10 02:22:37 +0300 | [diff] [blame] | 1732 | struct cpsw_common *cpsw = priv->cpsw; |
Mugunthan V N | 3b72c2f | 2013-02-05 08:26:48 +0000 | [diff] [blame] | 1733 | int ret; |
| 1734 | |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 1735 | if (vid == cpsw->data.default_vlan) |
Mugunthan V N | 3b72c2f | 2013-02-05 08:26:48 +0000 | [diff] [blame] | 1736 | return 0; |
| 1737 | |
Ivan Khoronzhuk | 56e31bd | 2016-08-10 02:22:38 +0300 | [diff] [blame] | 1738 | ret = pm_runtime_get_sync(cpsw->dev); |
Grygorii Strashko | a6c5d14 | 2016-06-24 21:23:45 +0300 | [diff] [blame] | 1739 | if (ret < 0) { |
Ivan Khoronzhuk | 56e31bd | 2016-08-10 02:22:38 +0300 | [diff] [blame] | 1740 | pm_runtime_put_noidle(cpsw->dev); |
Grygorii Strashko | a6c5d14 | 2016-06-24 21:23:45 +0300 | [diff] [blame] | 1741 | return ret; |
| 1742 | } |
| 1743 | |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 1744 | if (cpsw->data.dual_emac) { |
Mugunthan V N | 02a5416 | 2015-01-22 15:19:22 +0530 | [diff] [blame] | 1745 | int i; |
| 1746 | |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 1747 | for (i = 0; i < cpsw->data.slaves; i++) { |
| 1748 | if (vid == cpsw->slaves[i].port_vlan) |
Mugunthan V N | 02a5416 | 2015-01-22 15:19:22 +0530 | [diff] [blame] | 1749 | return -EINVAL; |
| 1750 | } |
| 1751 | } |
| 1752 | |
Mugunthan V N | 3b72c2f | 2013-02-05 08:26:48 +0000 | [diff] [blame] | 1753 | dev_info(priv->dev, "removing vlanid %d from vlan filter\n", vid); |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 1754 | ret = cpsw_ale_del_vlan(cpsw->ale, vid, 0); |
Mugunthan V N | 3b72c2f | 2013-02-05 08:26:48 +0000 | [diff] [blame] | 1755 | if (ret != 0) |
| 1756 | return ret; |
| 1757 | |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 1758 | ret = cpsw_ale_del_ucast(cpsw->ale, priv->mac_addr, |
Grygorii Strashko | 61f1cef | 2016-04-07 15:16:43 +0300 | [diff] [blame] | 1759 | HOST_PORT_NUM, ALE_VLAN, vid); |
Mugunthan V N | 3b72c2f | 2013-02-05 08:26:48 +0000 | [diff] [blame] | 1760 | if (ret != 0) |
| 1761 | return ret; |
| 1762 | |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 1763 | ret = cpsw_ale_del_mcast(cpsw->ale, priv->ndev->broadcast, |
Grygorii Strashko | a6c5d14 | 2016-06-24 21:23:45 +0300 | [diff] [blame] | 1764 | 0, ALE_VLAN, vid); |
Ivan Khoronzhuk | 56e31bd | 2016-08-10 02:22:38 +0300 | [diff] [blame] | 1765 | pm_runtime_put(cpsw->dev); |
Grygorii Strashko | a6c5d14 | 2016-06-24 21:23:45 +0300 | [diff] [blame] | 1766 | return ret; |
Mugunthan V N | 3b72c2f | 2013-02-05 08:26:48 +0000 | [diff] [blame] | 1767 | } |
| 1768 | |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1769 | static const struct net_device_ops cpsw_netdev_ops = { |
| 1770 | .ndo_open = cpsw_ndo_open, |
| 1771 | .ndo_stop = cpsw_ndo_stop, |
| 1772 | .ndo_start_xmit = cpsw_ndo_start_xmit, |
Mugunthan V N | dcfd8d5 | 2013-07-25 23:44:01 +0530 | [diff] [blame] | 1773 | .ndo_set_mac_address = cpsw_ndo_set_mac_address, |
Richard Cochran | 2e5b38a | 2012-10-29 08:45:20 +0000 | [diff] [blame] | 1774 | .ndo_do_ioctl = cpsw_ndo_ioctl, |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1775 | .ndo_validate_addr = eth_validate_addr, |
David S. Miller | 5c473ed | 2012-03-20 00:33:59 -0400 | [diff] [blame] | 1776 | .ndo_change_mtu = eth_change_mtu, |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1777 | .ndo_tx_timeout = cpsw_ndo_tx_timeout, |
Mugunthan V N | 5c50a85 | 2012-10-29 08:45:11 +0000 | [diff] [blame] | 1778 | .ndo_set_rx_mode = cpsw_ndo_set_rx_mode, |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1779 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 1780 | .ndo_poll_controller = cpsw_ndo_poll_controller, |
| 1781 | #endif |
Mugunthan V N | 3b72c2f | 2013-02-05 08:26:48 +0000 | [diff] [blame] | 1782 | .ndo_vlan_rx_add_vid = cpsw_ndo_vlan_rx_add_vid, |
| 1783 | .ndo_vlan_rx_kill_vid = cpsw_ndo_vlan_rx_kill_vid, |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1784 | }; |
| 1785 | |
Mugunthan V N | 52c4f0e | 2014-07-22 23:25:07 +0530 | [diff] [blame] | 1786 | static int cpsw_get_regs_len(struct net_device *ndev) |
| 1787 | { |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 1788 | struct cpsw_common *cpsw = ndev_to_cpsw(ndev); |
Mugunthan V N | 52c4f0e | 2014-07-22 23:25:07 +0530 | [diff] [blame] | 1789 | |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 1790 | return cpsw->data.ale_entries * ALE_ENTRY_WORDS * sizeof(u32); |
Mugunthan V N | 52c4f0e | 2014-07-22 23:25:07 +0530 | [diff] [blame] | 1791 | } |
| 1792 | |
| 1793 | static void cpsw_get_regs(struct net_device *ndev, |
| 1794 | struct ethtool_regs *regs, void *p) |
| 1795 | { |
Mugunthan V N | 52c4f0e | 2014-07-22 23:25:07 +0530 | [diff] [blame] | 1796 | u32 *reg = p; |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 1797 | struct cpsw_common *cpsw = ndev_to_cpsw(ndev); |
Mugunthan V N | 52c4f0e | 2014-07-22 23:25:07 +0530 | [diff] [blame] | 1798 | |
| 1799 | /* update CPSW IP version */ |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 1800 | regs->version = cpsw->version; |
Mugunthan V N | 52c4f0e | 2014-07-22 23:25:07 +0530 | [diff] [blame] | 1801 | |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 1802 | cpsw_ale_dump(cpsw->ale, reg); |
Mugunthan V N | 52c4f0e | 2014-07-22 23:25:07 +0530 | [diff] [blame] | 1803 | } |
| 1804 | |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1805 | static void cpsw_get_drvinfo(struct net_device *ndev, |
| 1806 | struct ethtool_drvinfo *info) |
| 1807 | { |
Ivan Khoronzhuk | 649a168 | 2016-08-10 02:22:37 +0300 | [diff] [blame] | 1808 | struct cpsw_common *cpsw = ndev_to_cpsw(ndev); |
Ivan Khoronzhuk | 56e31bd | 2016-08-10 02:22:38 +0300 | [diff] [blame] | 1809 | struct platform_device *pdev = to_platform_device(cpsw->dev); |
Jiri Pirko | 7826d43 | 2013-01-06 00:44:26 +0000 | [diff] [blame] | 1810 | |
Mugunthan V N | 52c4f0e | 2014-07-22 23:25:07 +0530 | [diff] [blame] | 1811 | strlcpy(info->driver, "cpsw", sizeof(info->driver)); |
Jiri Pirko | 7826d43 | 2013-01-06 00:44:26 +0000 | [diff] [blame] | 1812 | strlcpy(info->version, "1.0", sizeof(info->version)); |
Ivan Khoronzhuk | 56e31bd | 2016-08-10 02:22:38 +0300 | [diff] [blame] | 1813 | strlcpy(info->bus_info, pdev->name, sizeof(info->bus_info)); |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1814 | } |
| 1815 | |
| 1816 | static u32 cpsw_get_msglevel(struct net_device *ndev) |
| 1817 | { |
| 1818 | struct cpsw_priv *priv = netdev_priv(ndev); |
| 1819 | return priv->msg_enable; |
| 1820 | } |
| 1821 | |
| 1822 | static void cpsw_set_msglevel(struct net_device *ndev, u32 value) |
| 1823 | { |
| 1824 | struct cpsw_priv *priv = netdev_priv(ndev); |
| 1825 | priv->msg_enable = value; |
| 1826 | } |
| 1827 | |
Richard Cochran | 2e5b38a | 2012-10-29 08:45:20 +0000 | [diff] [blame] | 1828 | static int cpsw_get_ts_info(struct net_device *ndev, |
| 1829 | struct ethtool_ts_info *info) |
| 1830 | { |
| 1831 | #ifdef CONFIG_TI_CPTS |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 1832 | struct cpsw_common *cpsw = ndev_to_cpsw(ndev); |
Richard Cochran | 2e5b38a | 2012-10-29 08:45:20 +0000 | [diff] [blame] | 1833 | |
| 1834 | info->so_timestamping = |
| 1835 | SOF_TIMESTAMPING_TX_HARDWARE | |
| 1836 | SOF_TIMESTAMPING_TX_SOFTWARE | |
| 1837 | SOF_TIMESTAMPING_RX_HARDWARE | |
| 1838 | SOF_TIMESTAMPING_RX_SOFTWARE | |
| 1839 | SOF_TIMESTAMPING_SOFTWARE | |
| 1840 | SOF_TIMESTAMPING_RAW_HARDWARE; |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 1841 | info->phc_index = cpsw->cpts->phc_index; |
Richard Cochran | 2e5b38a | 2012-10-29 08:45:20 +0000 | [diff] [blame] | 1842 | info->tx_types = |
| 1843 | (1 << HWTSTAMP_TX_OFF) | |
| 1844 | (1 << HWTSTAMP_TX_ON); |
| 1845 | info->rx_filters = |
| 1846 | (1 << HWTSTAMP_FILTER_NONE) | |
| 1847 | (1 << HWTSTAMP_FILTER_PTP_V2_EVENT); |
| 1848 | #else |
| 1849 | info->so_timestamping = |
| 1850 | SOF_TIMESTAMPING_TX_SOFTWARE | |
| 1851 | SOF_TIMESTAMPING_RX_SOFTWARE | |
| 1852 | SOF_TIMESTAMPING_SOFTWARE; |
| 1853 | info->phc_index = -1; |
| 1854 | info->tx_types = 0; |
| 1855 | info->rx_filters = 0; |
| 1856 | #endif |
| 1857 | return 0; |
| 1858 | } |
| 1859 | |
Mugunthan V N | d3bb9c5 | 2013-03-11 23:16:36 +0000 | [diff] [blame] | 1860 | static int cpsw_get_settings(struct net_device *ndev, |
| 1861 | struct ethtool_cmd *ecmd) |
| 1862 | { |
| 1863 | struct cpsw_priv *priv = netdev_priv(ndev); |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 1864 | struct cpsw_common *cpsw = priv->cpsw; |
| 1865 | int slave_no = cpsw_slave_index(cpsw, priv); |
Mugunthan V N | d3bb9c5 | 2013-03-11 23:16:36 +0000 | [diff] [blame] | 1866 | |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 1867 | if (cpsw->slaves[slave_no].phy) |
| 1868 | return phy_ethtool_gset(cpsw->slaves[slave_no].phy, ecmd); |
Mugunthan V N | d3bb9c5 | 2013-03-11 23:16:36 +0000 | [diff] [blame] | 1869 | else |
| 1870 | return -EOPNOTSUPP; |
| 1871 | } |
| 1872 | |
| 1873 | static int cpsw_set_settings(struct net_device *ndev, struct ethtool_cmd *ecmd) |
| 1874 | { |
| 1875 | struct cpsw_priv *priv = netdev_priv(ndev); |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 1876 | struct cpsw_common *cpsw = priv->cpsw; |
| 1877 | int slave_no = cpsw_slave_index(cpsw, priv); |
Mugunthan V N | d3bb9c5 | 2013-03-11 23:16:36 +0000 | [diff] [blame] | 1878 | |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 1879 | if (cpsw->slaves[slave_no].phy) |
| 1880 | return phy_ethtool_sset(cpsw->slaves[slave_no].phy, ecmd); |
Mugunthan V N | d3bb9c5 | 2013-03-11 23:16:36 +0000 | [diff] [blame] | 1881 | else |
| 1882 | return -EOPNOTSUPP; |
| 1883 | } |
| 1884 | |
Matus Ujhelyi | d8a6442 | 2013-08-20 07:59:38 +0200 | [diff] [blame] | 1885 | static void cpsw_get_wol(struct net_device *ndev, struct ethtool_wolinfo *wol) |
| 1886 | { |
| 1887 | struct cpsw_priv *priv = netdev_priv(ndev); |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 1888 | struct cpsw_common *cpsw = priv->cpsw; |
| 1889 | int slave_no = cpsw_slave_index(cpsw, priv); |
Matus Ujhelyi | d8a6442 | 2013-08-20 07:59:38 +0200 | [diff] [blame] | 1890 | |
| 1891 | wol->supported = 0; |
| 1892 | wol->wolopts = 0; |
| 1893 | |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 1894 | if (cpsw->slaves[slave_no].phy) |
| 1895 | phy_ethtool_get_wol(cpsw->slaves[slave_no].phy, wol); |
Matus Ujhelyi | d8a6442 | 2013-08-20 07:59:38 +0200 | [diff] [blame] | 1896 | } |
| 1897 | |
| 1898 | static int cpsw_set_wol(struct net_device *ndev, struct ethtool_wolinfo *wol) |
| 1899 | { |
| 1900 | struct cpsw_priv *priv = netdev_priv(ndev); |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 1901 | struct cpsw_common *cpsw = priv->cpsw; |
| 1902 | int slave_no = cpsw_slave_index(cpsw, priv); |
Matus Ujhelyi | d8a6442 | 2013-08-20 07:59:38 +0200 | [diff] [blame] | 1903 | |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 1904 | if (cpsw->slaves[slave_no].phy) |
| 1905 | return phy_ethtool_set_wol(cpsw->slaves[slave_no].phy, wol); |
Matus Ujhelyi | d8a6442 | 2013-08-20 07:59:38 +0200 | [diff] [blame] | 1906 | else |
| 1907 | return -EOPNOTSUPP; |
| 1908 | } |
| 1909 | |
Mugunthan V N | 1923d6e | 2014-09-08 22:54:02 +0530 | [diff] [blame] | 1910 | static void cpsw_get_pauseparam(struct net_device *ndev, |
| 1911 | struct ethtool_pauseparam *pause) |
| 1912 | { |
| 1913 | struct cpsw_priv *priv = netdev_priv(ndev); |
| 1914 | |
| 1915 | pause->autoneg = AUTONEG_DISABLE; |
| 1916 | pause->rx_pause = priv->rx_pause ? true : false; |
| 1917 | pause->tx_pause = priv->tx_pause ? true : false; |
| 1918 | } |
| 1919 | |
| 1920 | static int cpsw_set_pauseparam(struct net_device *ndev, |
| 1921 | struct ethtool_pauseparam *pause) |
| 1922 | { |
| 1923 | struct cpsw_priv *priv = netdev_priv(ndev); |
| 1924 | bool link; |
| 1925 | |
| 1926 | priv->rx_pause = pause->rx_pause ? true : false; |
| 1927 | priv->tx_pause = pause->tx_pause ? true : false; |
| 1928 | |
| 1929 | for_each_slave(priv, _cpsw_adjust_link, priv, &link); |
Mugunthan V N | 1923d6e | 2014-09-08 22:54:02 +0530 | [diff] [blame] | 1930 | return 0; |
| 1931 | } |
| 1932 | |
Grygorii Strashko | 7898b1d | 2016-06-24 21:23:44 +0300 | [diff] [blame] | 1933 | static int cpsw_ethtool_op_begin(struct net_device *ndev) |
| 1934 | { |
| 1935 | struct cpsw_priv *priv = netdev_priv(ndev); |
Ivan Khoronzhuk | 649a168 | 2016-08-10 02:22:37 +0300 | [diff] [blame] | 1936 | struct cpsw_common *cpsw = priv->cpsw; |
Grygorii Strashko | 7898b1d | 2016-06-24 21:23:44 +0300 | [diff] [blame] | 1937 | int ret; |
| 1938 | |
Ivan Khoronzhuk | 56e31bd | 2016-08-10 02:22:38 +0300 | [diff] [blame] | 1939 | ret = pm_runtime_get_sync(cpsw->dev); |
Grygorii Strashko | 7898b1d | 2016-06-24 21:23:44 +0300 | [diff] [blame] | 1940 | if (ret < 0) { |
| 1941 | cpsw_err(priv, drv, "ethtool begin failed %d\n", ret); |
Ivan Khoronzhuk | 56e31bd | 2016-08-10 02:22:38 +0300 | [diff] [blame] | 1942 | pm_runtime_put_noidle(cpsw->dev); |
Grygorii Strashko | 7898b1d | 2016-06-24 21:23:44 +0300 | [diff] [blame] | 1943 | } |
| 1944 | |
| 1945 | return ret; |
| 1946 | } |
| 1947 | |
| 1948 | static void cpsw_ethtool_op_complete(struct net_device *ndev) |
| 1949 | { |
| 1950 | struct cpsw_priv *priv = netdev_priv(ndev); |
| 1951 | int ret; |
| 1952 | |
Ivan Khoronzhuk | 56e31bd | 2016-08-10 02:22:38 +0300 | [diff] [blame] | 1953 | ret = pm_runtime_put(priv->cpsw->dev); |
Grygorii Strashko | 7898b1d | 2016-06-24 21:23:44 +0300 | [diff] [blame] | 1954 | if (ret < 0) |
| 1955 | cpsw_err(priv, drv, "ethtool complete failed %d\n", ret); |
| 1956 | } |
| 1957 | |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1958 | static const struct ethtool_ops cpsw_ethtool_ops = { |
| 1959 | .get_drvinfo = cpsw_get_drvinfo, |
| 1960 | .get_msglevel = cpsw_get_msglevel, |
| 1961 | .set_msglevel = cpsw_set_msglevel, |
| 1962 | .get_link = ethtool_op_get_link, |
Richard Cochran | 2e5b38a | 2012-10-29 08:45:20 +0000 | [diff] [blame] | 1963 | .get_ts_info = cpsw_get_ts_info, |
Mugunthan V N | d3bb9c5 | 2013-03-11 23:16:36 +0000 | [diff] [blame] | 1964 | .get_settings = cpsw_get_settings, |
| 1965 | .set_settings = cpsw_set_settings, |
Mugunthan V N | ff5b8ef | 2013-03-11 23:16:37 +0000 | [diff] [blame] | 1966 | .get_coalesce = cpsw_get_coalesce, |
| 1967 | .set_coalesce = cpsw_set_coalesce, |
Mugunthan V N | d971854 | 2013-07-23 15:38:17 +0530 | [diff] [blame] | 1968 | .get_sset_count = cpsw_get_sset_count, |
| 1969 | .get_strings = cpsw_get_strings, |
| 1970 | .get_ethtool_stats = cpsw_get_ethtool_stats, |
Mugunthan V N | 1923d6e | 2014-09-08 22:54:02 +0530 | [diff] [blame] | 1971 | .get_pauseparam = cpsw_get_pauseparam, |
| 1972 | .set_pauseparam = cpsw_set_pauseparam, |
Matus Ujhelyi | d8a6442 | 2013-08-20 07:59:38 +0200 | [diff] [blame] | 1973 | .get_wol = cpsw_get_wol, |
| 1974 | .set_wol = cpsw_set_wol, |
Mugunthan V N | 52c4f0e | 2014-07-22 23:25:07 +0530 | [diff] [blame] | 1975 | .get_regs_len = cpsw_get_regs_len, |
| 1976 | .get_regs = cpsw_get_regs, |
Grygorii Strashko | 7898b1d | 2016-06-24 21:23:44 +0300 | [diff] [blame] | 1977 | .begin = cpsw_ethtool_op_begin, |
| 1978 | .complete = cpsw_ethtool_op_complete, |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1979 | }; |
| 1980 | |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 1981 | static void cpsw_slave_init(struct cpsw_slave *slave, struct cpsw_common *cpsw, |
Richard Cochran | 549985e | 2012-11-14 09:07:56 +0000 | [diff] [blame] | 1982 | u32 slave_reg_ofs, u32 sliver_reg_ofs) |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1983 | { |
Ivan Khoronzhuk | 5d8d0d4 | 2016-08-10 02:22:39 +0300 | [diff] [blame] | 1984 | void __iomem *regs = cpsw->regs; |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1985 | int slave_num = slave->slave_num; |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 1986 | struct cpsw_slave_data *data = cpsw->data.slave_data + slave_num; |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1987 | |
| 1988 | slave->data = data; |
Richard Cochran | 549985e | 2012-11-14 09:07:56 +0000 | [diff] [blame] | 1989 | slave->regs = regs + slave_reg_ofs; |
| 1990 | slave->sliver = regs + sliver_reg_ofs; |
Mugunthan V N | d9ba8f9 | 2013-02-11 09:52:20 +0000 | [diff] [blame] | 1991 | slave->port_vlan = data->dual_emac_res_vlan; |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 1992 | } |
| 1993 | |
David Rivshin | 552165b | 2016-04-27 21:25:25 -0400 | [diff] [blame] | 1994 | static int cpsw_probe_dt(struct cpsw_platform_data *data, |
Mugunthan V N | 2eb32b0 | 2012-07-30 10:17:14 +0000 | [diff] [blame] | 1995 | struct platform_device *pdev) |
| 1996 | { |
| 1997 | struct device_node *node = pdev->dev.of_node; |
| 1998 | struct device_node *slave_node; |
| 1999 | int i = 0, ret; |
| 2000 | u32 prop; |
| 2001 | |
| 2002 | if (!node) |
| 2003 | return -EINVAL; |
| 2004 | |
| 2005 | if (of_property_read_u32(node, "slaves", &prop)) { |
George Cherian | 88c99ff | 2014-05-12 10:21:19 +0530 | [diff] [blame] | 2006 | dev_err(&pdev->dev, "Missing slaves property in the DT.\n"); |
Mugunthan V N | 2eb32b0 | 2012-07-30 10:17:14 +0000 | [diff] [blame] | 2007 | return -EINVAL; |
| 2008 | } |
| 2009 | data->slaves = prop; |
| 2010 | |
Mugunthan V N | e86ac13 | 2013-03-11 23:16:35 +0000 | [diff] [blame] | 2011 | if (of_property_read_u32(node, "active_slave", &prop)) { |
George Cherian | 88c99ff | 2014-05-12 10:21:19 +0530 | [diff] [blame] | 2012 | dev_err(&pdev->dev, "Missing active_slave property in the DT.\n"); |
Daniel Mack | aa1a15e | 2013-09-21 00:50:38 +0530 | [diff] [blame] | 2013 | return -EINVAL; |
Richard Cochran | 78ca0b2 | 2012-10-29 08:45:18 +0000 | [diff] [blame] | 2014 | } |
Mugunthan V N | e86ac13 | 2013-03-11 23:16:35 +0000 | [diff] [blame] | 2015 | data->active_slave = prop; |
Richard Cochran | 78ca0b2 | 2012-10-29 08:45:18 +0000 | [diff] [blame] | 2016 | |
Richard Cochran | 00ab94e | 2012-10-29 08:45:19 +0000 | [diff] [blame] | 2017 | if (of_property_read_u32(node, "cpts_clock_mult", &prop)) { |
George Cherian | 88c99ff | 2014-05-12 10:21:19 +0530 | [diff] [blame] | 2018 | dev_err(&pdev->dev, "Missing cpts_clock_mult property in the DT.\n"); |
Daniel Mack | aa1a15e | 2013-09-21 00:50:38 +0530 | [diff] [blame] | 2019 | return -EINVAL; |
Richard Cochran | 00ab94e | 2012-10-29 08:45:19 +0000 | [diff] [blame] | 2020 | } |
| 2021 | data->cpts_clock_mult = prop; |
| 2022 | |
| 2023 | if (of_property_read_u32(node, "cpts_clock_shift", &prop)) { |
George Cherian | 88c99ff | 2014-05-12 10:21:19 +0530 | [diff] [blame] | 2024 | dev_err(&pdev->dev, "Missing cpts_clock_shift property in the DT.\n"); |
Daniel Mack | aa1a15e | 2013-09-21 00:50:38 +0530 | [diff] [blame] | 2025 | return -EINVAL; |
Richard Cochran | 00ab94e | 2012-10-29 08:45:19 +0000 | [diff] [blame] | 2026 | } |
| 2027 | data->cpts_clock_shift = prop; |
| 2028 | |
Daniel Mack | aa1a15e | 2013-09-21 00:50:38 +0530 | [diff] [blame] | 2029 | data->slave_data = devm_kzalloc(&pdev->dev, data->slaves |
| 2030 | * sizeof(struct cpsw_slave_data), |
| 2031 | GFP_KERNEL); |
Joe Perches | b2adaca | 2013-02-03 17:43:58 +0000 | [diff] [blame] | 2032 | if (!data->slave_data) |
Daniel Mack | aa1a15e | 2013-09-21 00:50:38 +0530 | [diff] [blame] | 2033 | return -ENOMEM; |
Mugunthan V N | 2eb32b0 | 2012-07-30 10:17:14 +0000 | [diff] [blame] | 2034 | |
Mugunthan V N | 2eb32b0 | 2012-07-30 10:17:14 +0000 | [diff] [blame] | 2035 | if (of_property_read_u32(node, "cpdma_channels", &prop)) { |
George Cherian | 88c99ff | 2014-05-12 10:21:19 +0530 | [diff] [blame] | 2036 | dev_err(&pdev->dev, "Missing cpdma_channels property in the DT.\n"); |
Daniel Mack | aa1a15e | 2013-09-21 00:50:38 +0530 | [diff] [blame] | 2037 | return -EINVAL; |
Mugunthan V N | 2eb32b0 | 2012-07-30 10:17:14 +0000 | [diff] [blame] | 2038 | } |
| 2039 | data->channels = prop; |
| 2040 | |
Mugunthan V N | 2eb32b0 | 2012-07-30 10:17:14 +0000 | [diff] [blame] | 2041 | if (of_property_read_u32(node, "ale_entries", &prop)) { |
George Cherian | 88c99ff | 2014-05-12 10:21:19 +0530 | [diff] [blame] | 2042 | dev_err(&pdev->dev, "Missing ale_entries property in the DT.\n"); |
Daniel Mack | aa1a15e | 2013-09-21 00:50:38 +0530 | [diff] [blame] | 2043 | return -EINVAL; |
Mugunthan V N | 2eb32b0 | 2012-07-30 10:17:14 +0000 | [diff] [blame] | 2044 | } |
| 2045 | data->ale_entries = prop; |
| 2046 | |
Mugunthan V N | 2eb32b0 | 2012-07-30 10:17:14 +0000 | [diff] [blame] | 2047 | if (of_property_read_u32(node, "bd_ram_size", &prop)) { |
George Cherian | 88c99ff | 2014-05-12 10:21:19 +0530 | [diff] [blame] | 2048 | dev_err(&pdev->dev, "Missing bd_ram_size property in the DT.\n"); |
Daniel Mack | aa1a15e | 2013-09-21 00:50:38 +0530 | [diff] [blame] | 2049 | return -EINVAL; |
Mugunthan V N | 2eb32b0 | 2012-07-30 10:17:14 +0000 | [diff] [blame] | 2050 | } |
| 2051 | data->bd_ram_size = prop; |
| 2052 | |
Mugunthan V N | 2eb32b0 | 2012-07-30 10:17:14 +0000 | [diff] [blame] | 2053 | if (of_property_read_u32(node, "mac_control", &prop)) { |
George Cherian | 88c99ff | 2014-05-12 10:21:19 +0530 | [diff] [blame] | 2054 | dev_err(&pdev->dev, "Missing mac_control property in the DT.\n"); |
Daniel Mack | aa1a15e | 2013-09-21 00:50:38 +0530 | [diff] [blame] | 2055 | return -EINVAL; |
Mugunthan V N | 2eb32b0 | 2012-07-30 10:17:14 +0000 | [diff] [blame] | 2056 | } |
| 2057 | data->mac_control = prop; |
| 2058 | |
Markus Pargmann | 281abd9 | 2013-10-04 14:44:40 +0200 | [diff] [blame] | 2059 | if (of_property_read_bool(node, "dual_emac")) |
| 2060 | data->dual_emac = 1; |
Mugunthan V N | d9ba8f9 | 2013-02-11 09:52:20 +0000 | [diff] [blame] | 2061 | |
Vaibhav Hiremath | 1fb19aa | 2012-11-14 09:07:55 +0000 | [diff] [blame] | 2062 | /* |
| 2063 | * Populate all the child nodes here... |
| 2064 | */ |
| 2065 | ret = of_platform_populate(node, NULL, NULL, &pdev->dev); |
| 2066 | /* We do not want to force this, as in some cases may not have child */ |
| 2067 | if (ret) |
George Cherian | 88c99ff | 2014-05-12 10:21:19 +0530 | [diff] [blame] | 2068 | dev_warn(&pdev->dev, "Doesn't have any child node\n"); |
Vaibhav Hiremath | 1fb19aa | 2012-11-14 09:07:55 +0000 | [diff] [blame] | 2069 | |
Ben Hutchings | 8658aaf | 2016-06-21 01:16:31 +0100 | [diff] [blame] | 2070 | for_each_available_child_of_node(node, slave_node) { |
Richard Cochran | 549985e | 2012-11-14 09:07:56 +0000 | [diff] [blame] | 2071 | struct cpsw_slave_data *slave_data = data->slave_data + i; |
| 2072 | const void *mac_addr = NULL; |
Richard Cochran | 549985e | 2012-11-14 09:07:56 +0000 | [diff] [blame] | 2073 | int lenp; |
| 2074 | const __be32 *parp; |
Richard Cochran | 549985e | 2012-11-14 09:07:56 +0000 | [diff] [blame] | 2075 | |
Markus Pargmann | f468b10 | 2013-10-04 14:44:39 +0200 | [diff] [blame] | 2076 | /* This is no slave child node, continue */ |
| 2077 | if (strcmp(slave_node->name, "slave")) |
| 2078 | continue; |
| 2079 | |
David Rivshin | 552165b | 2016-04-27 21:25:25 -0400 | [diff] [blame] | 2080 | slave_data->phy_node = of_parse_phandle(slave_node, |
| 2081 | "phy-handle", 0); |
David Rivshin | f1eea5c | 2015-12-16 23:02:10 -0500 | [diff] [blame] | 2082 | parp = of_get_property(slave_node, "phy_id", &lenp); |
David Rivshin | ae092b5 | 2016-04-27 21:38:26 -0400 | [diff] [blame] | 2083 | if (slave_data->phy_node) { |
| 2084 | dev_dbg(&pdev->dev, |
| 2085 | "slave[%d] using phy-handle=\"%s\"\n", |
| 2086 | i, slave_data->phy_node->full_name); |
| 2087 | } else if (of_phy_is_fixed_link(slave_node)) { |
David Rivshin | dfc0a6d | 2015-12-16 23:02:11 -0500 | [diff] [blame] | 2088 | /* In the case of a fixed PHY, the DT node associated |
| 2089 | * to the PHY is the Ethernet MAC DT node. |
| 2090 | */ |
Markus Brunner | 1f71e8c | 2015-11-03 22:09:51 +0100 | [diff] [blame] | 2091 | ret = of_phy_register_fixed_link(slave_node); |
| 2092 | if (ret) |
| 2093 | return ret; |
David Rivshin | 06cd6d6 | 2016-04-27 21:45:45 -0400 | [diff] [blame] | 2094 | slave_data->phy_node = of_node_get(slave_node); |
David Rivshin | f1eea5c | 2015-12-16 23:02:10 -0500 | [diff] [blame] | 2095 | } else if (parp) { |
| 2096 | u32 phyid; |
| 2097 | struct device_node *mdio_node; |
| 2098 | struct platform_device *mdio; |
| 2099 | |
| 2100 | if (lenp != (sizeof(__be32) * 2)) { |
| 2101 | dev_err(&pdev->dev, "Invalid slave[%d] phy_id property\n", i); |
| 2102 | goto no_phy_slave; |
| 2103 | } |
| 2104 | mdio_node = of_find_node_by_phandle(be32_to_cpup(parp)); |
| 2105 | phyid = be32_to_cpup(parp+1); |
| 2106 | mdio = of_find_device_by_node(mdio_node); |
| 2107 | of_node_put(mdio_node); |
| 2108 | if (!mdio) { |
| 2109 | dev_err(&pdev->dev, "Missing mdio platform device\n"); |
| 2110 | return -EINVAL; |
| 2111 | } |
| 2112 | snprintf(slave_data->phy_id, sizeof(slave_data->phy_id), |
| 2113 | PHY_ID_FMT, mdio->name, phyid); |
| 2114 | } else { |
David Rivshin | ae092b5 | 2016-04-27 21:38:26 -0400 | [diff] [blame] | 2115 | dev_err(&pdev->dev, |
| 2116 | "No slave[%d] phy_id, phy-handle, or fixed-link property\n", |
| 2117 | i); |
Markus Brunner | 1f71e8c | 2015-11-03 22:09:51 +0100 | [diff] [blame] | 2118 | goto no_phy_slave; |
| 2119 | } |
Mugunthan V N | 47276fc | 2014-10-24 18:51:33 +0530 | [diff] [blame] | 2120 | slave_data->phy_if = of_get_phy_mode(slave_node); |
| 2121 | if (slave_data->phy_if < 0) { |
| 2122 | dev_err(&pdev->dev, "Missing or malformed slave[%d] phy-mode property\n", |
| 2123 | i); |
| 2124 | return slave_data->phy_if; |
| 2125 | } |
| 2126 | |
| 2127 | no_phy_slave: |
Richard Cochran | 549985e | 2012-11-14 09:07:56 +0000 | [diff] [blame] | 2128 | mac_addr = of_get_mac_address(slave_node); |
Markus Pargmann | 0ba517b | 2014-09-29 08:53:17 +0200 | [diff] [blame] | 2129 | if (mac_addr) { |
Richard Cochran | 549985e | 2012-11-14 09:07:56 +0000 | [diff] [blame] | 2130 | memcpy(slave_data->mac_addr, mac_addr, ETH_ALEN); |
Markus Pargmann | 0ba517b | 2014-09-29 08:53:17 +0200 | [diff] [blame] | 2131 | } else { |
Mugunthan V N | b6745f6 | 2015-09-21 15:56:50 +0530 | [diff] [blame] | 2132 | ret = ti_cm_get_macid(&pdev->dev, i, |
| 2133 | slave_data->mac_addr); |
| 2134 | if (ret) |
| 2135 | return ret; |
Markus Pargmann | 0ba517b | 2014-09-29 08:53:17 +0200 | [diff] [blame] | 2136 | } |
Mugunthan V N | d9ba8f9 | 2013-02-11 09:52:20 +0000 | [diff] [blame] | 2137 | if (data->dual_emac) { |
Mugunthan V N | 91c4166 | 2013-04-15 07:31:28 +0000 | [diff] [blame] | 2138 | if (of_property_read_u32(slave_node, "dual_emac_res_vlan", |
Mugunthan V N | d9ba8f9 | 2013-02-11 09:52:20 +0000 | [diff] [blame] | 2139 | &prop)) { |
George Cherian | 88c99ff | 2014-05-12 10:21:19 +0530 | [diff] [blame] | 2140 | dev_err(&pdev->dev, "Missing dual_emac_res_vlan in DT.\n"); |
Mugunthan V N | d9ba8f9 | 2013-02-11 09:52:20 +0000 | [diff] [blame] | 2141 | slave_data->dual_emac_res_vlan = i+1; |
George Cherian | 88c99ff | 2014-05-12 10:21:19 +0530 | [diff] [blame] | 2142 | dev_err(&pdev->dev, "Using %d as Reserved VLAN for %d slave\n", |
| 2143 | slave_data->dual_emac_res_vlan, i); |
Mugunthan V N | d9ba8f9 | 2013-02-11 09:52:20 +0000 | [diff] [blame] | 2144 | } else { |
| 2145 | slave_data->dual_emac_res_vlan = prop; |
| 2146 | } |
| 2147 | } |
| 2148 | |
Richard Cochran | 549985e | 2012-11-14 09:07:56 +0000 | [diff] [blame] | 2149 | i++; |
Mugunthan V N | 3a27bfa | 2013-12-02 12:53:39 +0530 | [diff] [blame] | 2150 | if (i == data->slaves) |
| 2151 | break; |
Richard Cochran | 549985e | 2012-11-14 09:07:56 +0000 | [diff] [blame] | 2152 | } |
| 2153 | |
Mugunthan V N | 2eb32b0 | 2012-07-30 10:17:14 +0000 | [diff] [blame] | 2154 | return 0; |
Mugunthan V N | 2eb32b0 | 2012-07-30 10:17:14 +0000 | [diff] [blame] | 2155 | } |
| 2156 | |
Ivan Khoronzhuk | 56e31bd | 2016-08-10 02:22:38 +0300 | [diff] [blame] | 2157 | static int cpsw_probe_dual_emac(struct cpsw_priv *priv) |
Mugunthan V N | d9ba8f9 | 2013-02-11 09:52:20 +0000 | [diff] [blame] | 2158 | { |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 2159 | struct cpsw_common *cpsw = priv->cpsw; |
| 2160 | struct cpsw_platform_data *data = &cpsw->data; |
Mugunthan V N | d9ba8f9 | 2013-02-11 09:52:20 +0000 | [diff] [blame] | 2161 | struct net_device *ndev; |
| 2162 | struct cpsw_priv *priv_sl2; |
Ivan Khoronzhuk | e38b5a3 | 2016-08-10 02:22:41 +0300 | [diff] [blame] | 2163 | int ret = 0; |
Mugunthan V N | d9ba8f9 | 2013-02-11 09:52:20 +0000 | [diff] [blame] | 2164 | |
| 2165 | ndev = alloc_etherdev(sizeof(struct cpsw_priv)); |
| 2166 | if (!ndev) { |
Ivan Khoronzhuk | 56e31bd | 2016-08-10 02:22:38 +0300 | [diff] [blame] | 2167 | dev_err(cpsw->dev, "cpsw: error allocating net_device\n"); |
Mugunthan V N | d9ba8f9 | 2013-02-11 09:52:20 +0000 | [diff] [blame] | 2168 | return -ENOMEM; |
| 2169 | } |
| 2170 | |
| 2171 | priv_sl2 = netdev_priv(ndev); |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 2172 | priv_sl2->cpsw = cpsw; |
Mugunthan V N | d9ba8f9 | 2013-02-11 09:52:20 +0000 | [diff] [blame] | 2173 | priv_sl2->ndev = ndev; |
| 2174 | priv_sl2->dev = &ndev->dev; |
| 2175 | priv_sl2->msg_enable = netif_msg_init(debug_level, CPSW_DEBUG); |
Mugunthan V N | d9ba8f9 | 2013-02-11 09:52:20 +0000 | [diff] [blame] | 2176 | |
| 2177 | if (is_valid_ether_addr(data->slave_data[1].mac_addr)) { |
| 2178 | memcpy(priv_sl2->mac_addr, data->slave_data[1].mac_addr, |
| 2179 | ETH_ALEN); |
Ivan Khoronzhuk | 56e31bd | 2016-08-10 02:22:38 +0300 | [diff] [blame] | 2180 | dev_info(cpsw->dev, "cpsw: Detected MACID = %pM\n", |
| 2181 | priv_sl2->mac_addr); |
Mugunthan V N | d9ba8f9 | 2013-02-11 09:52:20 +0000 | [diff] [blame] | 2182 | } else { |
| 2183 | random_ether_addr(priv_sl2->mac_addr); |
Ivan Khoronzhuk | 56e31bd | 2016-08-10 02:22:38 +0300 | [diff] [blame] | 2184 | dev_info(cpsw->dev, "cpsw: Random MACID = %pM\n", |
| 2185 | priv_sl2->mac_addr); |
Mugunthan V N | d9ba8f9 | 2013-02-11 09:52:20 +0000 | [diff] [blame] | 2186 | } |
| 2187 | memcpy(ndev->dev_addr, priv_sl2->mac_addr, ETH_ALEN); |
| 2188 | |
Mugunthan V N | d9ba8f9 | 2013-02-11 09:52:20 +0000 | [diff] [blame] | 2189 | priv_sl2->emac_port = 1; |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 2190 | cpsw->slaves[1].ndev = ndev; |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 2191 | ndev->features |= NETIF_F_HW_VLAN_CTAG_FILTER; |
Mugunthan V N | d9ba8f9 | 2013-02-11 09:52:20 +0000 | [diff] [blame] | 2192 | |
| 2193 | ndev->netdev_ops = &cpsw_netdev_ops; |
Wilfried Klaebe | 7ad24ea | 2014-05-11 00:12:32 +0000 | [diff] [blame] | 2194 | ndev->ethtool_ops = &cpsw_ethtool_ops; |
Mugunthan V N | d9ba8f9 | 2013-02-11 09:52:20 +0000 | [diff] [blame] | 2195 | |
| 2196 | /* register the network device */ |
Ivan Khoronzhuk | 56e31bd | 2016-08-10 02:22:38 +0300 | [diff] [blame] | 2197 | SET_NETDEV_DEV(ndev, cpsw->dev); |
Mugunthan V N | d9ba8f9 | 2013-02-11 09:52:20 +0000 | [diff] [blame] | 2198 | ret = register_netdev(ndev); |
| 2199 | if (ret) { |
Ivan Khoronzhuk | 56e31bd | 2016-08-10 02:22:38 +0300 | [diff] [blame] | 2200 | dev_err(cpsw->dev, "cpsw: error registering net device\n"); |
Mugunthan V N | d9ba8f9 | 2013-02-11 09:52:20 +0000 | [diff] [blame] | 2201 | free_netdev(ndev); |
| 2202 | ret = -ENODEV; |
| 2203 | } |
| 2204 | |
| 2205 | return ret; |
| 2206 | } |
| 2207 | |
Mugunthan V N | 7da1160 | 2015-08-12 15:22:53 +0530 | [diff] [blame] | 2208 | #define CPSW_QUIRK_IRQ BIT(0) |
| 2209 | |
| 2210 | static struct platform_device_id cpsw_devtype[] = { |
| 2211 | { |
| 2212 | /* keep it for existing comaptibles */ |
| 2213 | .name = "cpsw", |
| 2214 | .driver_data = CPSW_QUIRK_IRQ, |
| 2215 | }, { |
| 2216 | .name = "am335x-cpsw", |
| 2217 | .driver_data = CPSW_QUIRK_IRQ, |
| 2218 | }, { |
| 2219 | .name = "am4372-cpsw", |
| 2220 | .driver_data = 0, |
| 2221 | }, { |
| 2222 | .name = "dra7-cpsw", |
| 2223 | .driver_data = 0, |
| 2224 | }, { |
| 2225 | /* sentinel */ |
| 2226 | } |
| 2227 | }; |
| 2228 | MODULE_DEVICE_TABLE(platform, cpsw_devtype); |
| 2229 | |
| 2230 | enum ti_cpsw_type { |
| 2231 | CPSW = 0, |
| 2232 | AM335X_CPSW, |
| 2233 | AM4372_CPSW, |
| 2234 | DRA7_CPSW, |
| 2235 | }; |
| 2236 | |
| 2237 | static const struct of_device_id cpsw_of_mtable[] = { |
| 2238 | { .compatible = "ti,cpsw", .data = &cpsw_devtype[CPSW], }, |
| 2239 | { .compatible = "ti,am335x-cpsw", .data = &cpsw_devtype[AM335X_CPSW], }, |
| 2240 | { .compatible = "ti,am4372-cpsw", .data = &cpsw_devtype[AM4372_CPSW], }, |
| 2241 | { .compatible = "ti,dra7-cpsw", .data = &cpsw_devtype[DRA7_CPSW], }, |
| 2242 | { /* sentinel */ }, |
| 2243 | }; |
| 2244 | MODULE_DEVICE_TABLE(of, cpsw_of_mtable); |
| 2245 | |
Bill Pemberton | 663e12e | 2012-12-03 09:23:45 -0500 | [diff] [blame] | 2246 | static int cpsw_probe(struct platform_device *pdev) |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 2247 | { |
Ivan Khoronzhuk | ef4183a | 2016-08-10 02:22:35 +0300 | [diff] [blame] | 2248 | struct clk *clk; |
Sebastian Siewior | d1bd9ac | 2013-04-24 08:48:23 +0000 | [diff] [blame] | 2249 | struct cpsw_platform_data *data; |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 2250 | struct net_device *ndev; |
| 2251 | struct cpsw_priv *priv; |
| 2252 | struct cpdma_params dma_params; |
| 2253 | struct cpsw_ale_params ale_params; |
Daniel Mack | aa1a15e | 2013-09-21 00:50:38 +0530 | [diff] [blame] | 2254 | void __iomem *ss_regs; |
| 2255 | struct resource *res, *ss_res; |
Mugunthan V N | 7da1160 | 2015-08-12 15:22:53 +0530 | [diff] [blame] | 2256 | const struct of_device_id *of_id; |
Mugunthan V N | 1d147cc | 2015-09-07 15:16:44 +0530 | [diff] [blame] | 2257 | struct gpio_descs *mode; |
Richard Cochran | 549985e | 2012-11-14 09:07:56 +0000 | [diff] [blame] | 2258 | u32 slave_offset, sliver_offset, slave_size; |
Ivan Khoronzhuk | 649a168 | 2016-08-10 02:22:37 +0300 | [diff] [blame] | 2259 | struct cpsw_common *cpsw; |
Felipe Balbi | 5087b91 | 2015-01-16 10:11:11 -0600 | [diff] [blame] | 2260 | int ret = 0, i; |
| 2261 | int irq; |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 2262 | |
Ivan Khoronzhuk | 649a168 | 2016-08-10 02:22:37 +0300 | [diff] [blame] | 2263 | cpsw = devm_kzalloc(&pdev->dev, sizeof(struct cpsw_common), GFP_KERNEL); |
Ivan Khoronzhuk | 56e31bd | 2016-08-10 02:22:38 +0300 | [diff] [blame] | 2264 | cpsw->dev = &pdev->dev; |
Ivan Khoronzhuk | 649a168 | 2016-08-10 02:22:37 +0300 | [diff] [blame] | 2265 | |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 2266 | ndev = alloc_etherdev(sizeof(struct cpsw_priv)); |
| 2267 | if (!ndev) { |
George Cherian | 88c99ff | 2014-05-12 10:21:19 +0530 | [diff] [blame] | 2268 | dev_err(&pdev->dev, "error allocating net_device\n"); |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 2269 | return -ENOMEM; |
| 2270 | } |
| 2271 | |
| 2272 | platform_set_drvdata(pdev, ndev); |
| 2273 | priv = netdev_priv(ndev); |
Ivan Khoronzhuk | 649a168 | 2016-08-10 02:22:37 +0300 | [diff] [blame] | 2274 | priv->cpsw = cpsw; |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 2275 | priv->ndev = ndev; |
| 2276 | priv->dev = &ndev->dev; |
| 2277 | priv->msg_enable = netif_msg_init(debug_level, CPSW_DEBUG); |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 2278 | cpsw->rx_packet_max = max(rx_packet_max, 128); |
| 2279 | cpsw->cpts = devm_kzalloc(&pdev->dev, sizeof(struct cpts), GFP_KERNEL); |
| 2280 | if (!cpsw->cpts) { |
George Cherian | 88c99ff | 2014-05-12 10:21:19 +0530 | [diff] [blame] | 2281 | dev_err(&pdev->dev, "error allocating cpts\n"); |
Markus Pargmann | 4d507df | 2014-09-29 08:53:14 +0200 | [diff] [blame] | 2282 | ret = -ENOMEM; |
Mugunthan V N | 9232b16 | 2013-02-11 09:52:19 +0000 | [diff] [blame] | 2283 | goto clean_ndev_ret; |
| 2284 | } |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 2285 | |
Mugunthan V N | 1d147cc | 2015-09-07 15:16:44 +0530 | [diff] [blame] | 2286 | mode = devm_gpiod_get_array_optional(&pdev->dev, "mode", GPIOD_OUT_LOW); |
| 2287 | if (IS_ERR(mode)) { |
| 2288 | ret = PTR_ERR(mode); |
| 2289 | dev_err(&pdev->dev, "gpio request failed, ret %d\n", ret); |
| 2290 | goto clean_ndev_ret; |
| 2291 | } |
| 2292 | |
Vaibhav Hiremath | 1fb19aa | 2012-11-14 09:07:55 +0000 | [diff] [blame] | 2293 | /* |
| 2294 | * This may be required here for child devices. |
| 2295 | */ |
| 2296 | pm_runtime_enable(&pdev->dev); |
| 2297 | |
Mugunthan V N | 739683b | 2013-06-06 23:45:14 +0530 | [diff] [blame] | 2298 | /* Select default pin state */ |
| 2299 | pinctrl_pm_select_default_state(&pdev->dev); |
| 2300 | |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 2301 | if (cpsw_probe_dt(&cpsw->data, pdev)) { |
George Cherian | 88c99ff | 2014-05-12 10:21:19 +0530 | [diff] [blame] | 2302 | dev_err(&pdev->dev, "cpsw: platform data missing\n"); |
Mugunthan V N | 2eb32b0 | 2012-07-30 10:17:14 +0000 | [diff] [blame] | 2303 | ret = -ENODEV; |
Daniel Mack | aa1a15e | 2013-09-21 00:50:38 +0530 | [diff] [blame] | 2304 | goto clean_runtime_disable_ret; |
Mugunthan V N | 2eb32b0 | 2012-07-30 10:17:14 +0000 | [diff] [blame] | 2305 | } |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 2306 | data = &cpsw->data; |
Mugunthan V N | 2eb32b0 | 2012-07-30 10:17:14 +0000 | [diff] [blame] | 2307 | |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 2308 | if (is_valid_ether_addr(data->slave_data[0].mac_addr)) { |
| 2309 | memcpy(priv->mac_addr, data->slave_data[0].mac_addr, ETH_ALEN); |
George Cherian | 88c99ff | 2014-05-12 10:21:19 +0530 | [diff] [blame] | 2310 | dev_info(&pdev->dev, "Detected MACID = %pM\n", priv->mac_addr); |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 2311 | } else { |
Joe Perches | 7efd26d | 2012-07-12 19:33:06 +0000 | [diff] [blame] | 2312 | eth_random_addr(priv->mac_addr); |
George Cherian | 88c99ff | 2014-05-12 10:21:19 +0530 | [diff] [blame] | 2313 | dev_info(&pdev->dev, "Random MACID = %pM\n", priv->mac_addr); |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 2314 | } |
| 2315 | |
| 2316 | memcpy(ndev->dev_addr, priv->mac_addr, ETH_ALEN); |
| 2317 | |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 2318 | cpsw->slaves = devm_kzalloc(&pdev->dev, |
Daniel Mack | aa1a15e | 2013-09-21 00:50:38 +0530 | [diff] [blame] | 2319 | sizeof(struct cpsw_slave) * data->slaves, |
| 2320 | GFP_KERNEL); |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 2321 | if (!cpsw->slaves) { |
Daniel Mack | aa1a15e | 2013-09-21 00:50:38 +0530 | [diff] [blame] | 2322 | ret = -ENOMEM; |
| 2323 | goto clean_runtime_disable_ret; |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 2324 | } |
| 2325 | for (i = 0; i < data->slaves; i++) |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 2326 | cpsw->slaves[i].slave_num = i; |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 2327 | |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 2328 | cpsw->slaves[0].ndev = ndev; |
Mugunthan V N | d9ba8f9 | 2013-02-11 09:52:20 +0000 | [diff] [blame] | 2329 | priv->emac_port = 0; |
| 2330 | |
Ivan Khoronzhuk | ef4183a | 2016-08-10 02:22:35 +0300 | [diff] [blame] | 2331 | clk = devm_clk_get(&pdev->dev, "fck"); |
| 2332 | if (IS_ERR(clk)) { |
Daniel Mack | aa1a15e | 2013-09-21 00:50:38 +0530 | [diff] [blame] | 2333 | dev_err(priv->dev, "fck is not found\n"); |
Mugunthan V N | f150bd7 | 2012-07-17 08:09:50 +0000 | [diff] [blame] | 2334 | ret = -ENODEV; |
Daniel Mack | aa1a15e | 2013-09-21 00:50:38 +0530 | [diff] [blame] | 2335 | goto clean_runtime_disable_ret; |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 2336 | } |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 2337 | cpsw->bus_freq_mhz = clk_get_rate(clk) / 1000000; |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 2338 | |
Daniel Mack | aa1a15e | 2013-09-21 00:50:38 +0530 | [diff] [blame] | 2339 | ss_res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 2340 | ss_regs = devm_ioremap_resource(&pdev->dev, ss_res); |
| 2341 | if (IS_ERR(ss_regs)) { |
| 2342 | ret = PTR_ERR(ss_regs); |
| 2343 | goto clean_runtime_disable_ret; |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 2344 | } |
Ivan Khoronzhuk | 5d8d0d4 | 2016-08-10 02:22:39 +0300 | [diff] [blame] | 2345 | cpsw->regs = ss_regs; |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 2346 | |
Mugunthan V N | f280e89 | 2013-12-11 22:09:05 -0600 | [diff] [blame] | 2347 | /* Need to enable clocks with runtime PM api to access module |
| 2348 | * registers |
| 2349 | */ |
Grygorii Strashko | 108a653 | 2016-06-24 21:23:42 +0300 | [diff] [blame] | 2350 | ret = pm_runtime_get_sync(&pdev->dev); |
| 2351 | if (ret < 0) { |
| 2352 | pm_runtime_put_noidle(&pdev->dev); |
| 2353 | goto clean_runtime_disable_ret; |
| 2354 | } |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 2355 | cpsw->version = readl(&cpsw->regs->id_ver); |
Mugunthan V N | f280e89 | 2013-12-11 22:09:05 -0600 | [diff] [blame] | 2356 | pm_runtime_put_sync(&pdev->dev); |
| 2357 | |
Daniel Mack | aa1a15e | 2013-09-21 00:50:38 +0530 | [diff] [blame] | 2358 | res = platform_get_resource(pdev, IORESOURCE_MEM, 1); |
Ivan Khoronzhuk | 5d8d0d4 | 2016-08-10 02:22:39 +0300 | [diff] [blame] | 2359 | cpsw->wr_regs = devm_ioremap_resource(&pdev->dev, res); |
| 2360 | if (IS_ERR(cpsw->wr_regs)) { |
| 2361 | ret = PTR_ERR(cpsw->wr_regs); |
Daniel Mack | aa1a15e | 2013-09-21 00:50:38 +0530 | [diff] [blame] | 2362 | goto clean_runtime_disable_ret; |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 2363 | } |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 2364 | |
| 2365 | memset(&dma_params, 0, sizeof(dma_params)); |
Richard Cochran | 549985e | 2012-11-14 09:07:56 +0000 | [diff] [blame] | 2366 | memset(&ale_params, 0, sizeof(ale_params)); |
| 2367 | |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 2368 | switch (cpsw->version) { |
Richard Cochran | 549985e | 2012-11-14 09:07:56 +0000 | [diff] [blame] | 2369 | case CPSW_VERSION_1: |
Ivan Khoronzhuk | 5d8d0d4 | 2016-08-10 02:22:39 +0300 | [diff] [blame] | 2370 | cpsw->host_port_regs = ss_regs + CPSW1_HOST_PORT_OFFSET; |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 2371 | cpsw->cpts->reg = ss_regs + CPSW1_CPTS_OFFSET; |
Ivan Khoronzhuk | 5d8d0d4 | 2016-08-10 02:22:39 +0300 | [diff] [blame] | 2372 | cpsw->hw_stats = ss_regs + CPSW1_HW_STATS; |
Richard Cochran | 549985e | 2012-11-14 09:07:56 +0000 | [diff] [blame] | 2373 | dma_params.dmaregs = ss_regs + CPSW1_CPDMA_OFFSET; |
| 2374 | dma_params.txhdp = ss_regs + CPSW1_STATERAM_OFFSET; |
| 2375 | ale_params.ale_regs = ss_regs + CPSW1_ALE_OFFSET; |
| 2376 | slave_offset = CPSW1_SLAVE_OFFSET; |
| 2377 | slave_size = CPSW1_SLAVE_SIZE; |
| 2378 | sliver_offset = CPSW1_SLIVER_OFFSET; |
| 2379 | dma_params.desc_mem_phys = 0; |
| 2380 | break; |
| 2381 | case CPSW_VERSION_2: |
Mugunthan V N | c193f36 | 2013-08-05 17:30:05 +0530 | [diff] [blame] | 2382 | case CPSW_VERSION_3: |
Mugunthan V N | 926489b | 2013-08-12 17:11:15 +0530 | [diff] [blame] | 2383 | case CPSW_VERSION_4: |
Ivan Khoronzhuk | 5d8d0d4 | 2016-08-10 02:22:39 +0300 | [diff] [blame] | 2384 | cpsw->host_port_regs = ss_regs + CPSW2_HOST_PORT_OFFSET; |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 2385 | cpsw->cpts->reg = ss_regs + CPSW2_CPTS_OFFSET; |
Ivan Khoronzhuk | 5d8d0d4 | 2016-08-10 02:22:39 +0300 | [diff] [blame] | 2386 | cpsw->hw_stats = ss_regs + CPSW2_HW_STATS; |
Richard Cochran | 549985e | 2012-11-14 09:07:56 +0000 | [diff] [blame] | 2387 | dma_params.dmaregs = ss_regs + CPSW2_CPDMA_OFFSET; |
| 2388 | dma_params.txhdp = ss_regs + CPSW2_STATERAM_OFFSET; |
| 2389 | ale_params.ale_regs = ss_regs + CPSW2_ALE_OFFSET; |
| 2390 | slave_offset = CPSW2_SLAVE_OFFSET; |
| 2391 | slave_size = CPSW2_SLAVE_SIZE; |
| 2392 | sliver_offset = CPSW2_SLIVER_OFFSET; |
| 2393 | dma_params.desc_mem_phys = |
Daniel Mack | aa1a15e | 2013-09-21 00:50:38 +0530 | [diff] [blame] | 2394 | (u32 __force) ss_res->start + CPSW2_BD_OFFSET; |
Richard Cochran | 549985e | 2012-11-14 09:07:56 +0000 | [diff] [blame] | 2395 | break; |
| 2396 | default: |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 2397 | dev_err(priv->dev, "unknown version 0x%08x\n", cpsw->version); |
Richard Cochran | 549985e | 2012-11-14 09:07:56 +0000 | [diff] [blame] | 2398 | ret = -ENODEV; |
Daniel Mack | aa1a15e | 2013-09-21 00:50:38 +0530 | [diff] [blame] | 2399 | goto clean_runtime_disable_ret; |
Richard Cochran | 549985e | 2012-11-14 09:07:56 +0000 | [diff] [blame] | 2400 | } |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 2401 | for (i = 0; i < cpsw->data.slaves; i++) { |
| 2402 | struct cpsw_slave *slave = &cpsw->slaves[i]; |
| 2403 | |
| 2404 | cpsw_slave_init(slave, cpsw, slave_offset, sliver_offset); |
Richard Cochran | 549985e | 2012-11-14 09:07:56 +0000 | [diff] [blame] | 2405 | slave_offset += slave_size; |
| 2406 | sliver_offset += SLIVER_SIZE; |
| 2407 | } |
| 2408 | |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 2409 | dma_params.dev = &pdev->dev; |
Richard Cochran | 549985e | 2012-11-14 09:07:56 +0000 | [diff] [blame] | 2410 | dma_params.rxthresh = dma_params.dmaregs + CPDMA_RXTHRESH; |
| 2411 | dma_params.rxfree = dma_params.dmaregs + CPDMA_RXFREE; |
| 2412 | dma_params.rxhdp = dma_params.txhdp + CPDMA_RXHDP; |
| 2413 | dma_params.txcp = dma_params.txhdp + CPDMA_TXCP; |
| 2414 | dma_params.rxcp = dma_params.txhdp + CPDMA_RXCP; |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 2415 | |
| 2416 | dma_params.num_chan = data->channels; |
| 2417 | dma_params.has_soft_reset = true; |
| 2418 | dma_params.min_packet_size = CPSW_MIN_PACKET_SIZE; |
| 2419 | dma_params.desc_mem_size = data->bd_ram_size; |
| 2420 | dma_params.desc_align = 16; |
| 2421 | dma_params.has_ext_regs = true; |
Richard Cochran | 549985e | 2012-11-14 09:07:56 +0000 | [diff] [blame] | 2422 | dma_params.desc_hw_addr = dma_params.desc_mem_phys; |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 2423 | |
Ivan Khoronzhuk | 2c836bd | 2016-08-10 02:22:40 +0300 | [diff] [blame] | 2424 | cpsw->dma = cpdma_ctlr_create(&dma_params); |
| 2425 | if (!cpsw->dma) { |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 2426 | dev_err(priv->dev, "error initializing dma\n"); |
| 2427 | ret = -ENOMEM; |
Daniel Mack | aa1a15e | 2013-09-21 00:50:38 +0530 | [diff] [blame] | 2428 | goto clean_runtime_disable_ret; |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 2429 | } |
| 2430 | |
Ivan Khoronzhuk | 2c836bd | 2016-08-10 02:22:40 +0300 | [diff] [blame] | 2431 | cpsw->txch = cpdma_chan_create(cpsw->dma, tx_chan_num(0), |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 2432 | cpsw_tx_handler); |
Ivan Khoronzhuk | 2c836bd | 2016-08-10 02:22:40 +0300 | [diff] [blame] | 2433 | cpsw->rxch = cpdma_chan_create(cpsw->dma, rx_chan_num(0), |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 2434 | cpsw_rx_handler); |
| 2435 | |
Ivan Khoronzhuk | 2c836bd | 2016-08-10 02:22:40 +0300 | [diff] [blame] | 2436 | if (WARN_ON(!cpsw->txch || !cpsw->rxch)) { |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 2437 | dev_err(priv->dev, "error initializing dma channels\n"); |
| 2438 | ret = -ENOMEM; |
| 2439 | goto clean_dma_ret; |
| 2440 | } |
| 2441 | |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 2442 | ale_params.dev = &ndev->dev; |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 2443 | ale_params.ale_ageout = ale_ageout; |
| 2444 | ale_params.ale_entries = data->ale_entries; |
| 2445 | ale_params.ale_ports = data->slaves; |
| 2446 | |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 2447 | cpsw->ale = cpsw_ale_create(&ale_params); |
| 2448 | if (!cpsw->ale) { |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 2449 | dev_err(priv->dev, "error initializing ale engine\n"); |
| 2450 | ret = -ENODEV; |
| 2451 | goto clean_dma_ret; |
| 2452 | } |
| 2453 | |
Felipe Balbi | c03abd8 | 2015-01-16 10:11:12 -0600 | [diff] [blame] | 2454 | ndev->irq = platform_get_irq(pdev, 1); |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 2455 | if (ndev->irq < 0) { |
| 2456 | dev_err(priv->dev, "error getting irq resource\n"); |
Julia Lawall | c1e3334 | 2015-12-26 20:12:13 +0100 | [diff] [blame] | 2457 | ret = ndev->irq; |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 2458 | goto clean_ale_ret; |
| 2459 | } |
| 2460 | |
Mugunthan V N | 7da1160 | 2015-08-12 15:22:53 +0530 | [diff] [blame] | 2461 | of_id = of_match_device(cpsw_of_mtable, &pdev->dev); |
| 2462 | if (of_id) { |
| 2463 | pdev->id_entry = of_id->data; |
| 2464 | if (pdev->id_entry->driver_data) |
Ivan Khoronzhuk | e38b5a3 | 2016-08-10 02:22:41 +0300 | [diff] [blame] | 2465 | cpsw->quirk_irq = true; |
Mugunthan V N | 7da1160 | 2015-08-12 15:22:53 +0530 | [diff] [blame] | 2466 | } |
| 2467 | |
Felipe Balbi | c03abd8 | 2015-01-16 10:11:12 -0600 | [diff] [blame] | 2468 | /* Grab RX and TX IRQs. Note that we also have RX_THRESHOLD and |
| 2469 | * MISC IRQs which are always kept disabled with this driver so |
| 2470 | * we will not request them. |
| 2471 | * |
| 2472 | * If anyone wants to implement support for those, make sure to |
| 2473 | * first request and append them to irqs_table array. |
| 2474 | */ |
Daniel Mack | c2b32e5 | 2014-09-04 09:00:23 +0200 | [diff] [blame] | 2475 | |
Felipe Balbi | c03abd8 | 2015-01-16 10:11:12 -0600 | [diff] [blame] | 2476 | /* RX IRQ */ |
Felipe Balbi | 5087b91 | 2015-01-16 10:11:11 -0600 | [diff] [blame] | 2477 | irq = platform_get_irq(pdev, 1); |
Julia Lawall | c1e3334 | 2015-12-26 20:12:13 +0100 | [diff] [blame] | 2478 | if (irq < 0) { |
| 2479 | ret = irq; |
Felipe Balbi | 5087b91 | 2015-01-16 10:11:11 -0600 | [diff] [blame] | 2480 | goto clean_ale_ret; |
Julia Lawall | c1e3334 | 2015-12-26 20:12:13 +0100 | [diff] [blame] | 2481 | } |
Felipe Balbi | 5087b91 | 2015-01-16 10:11:11 -0600 | [diff] [blame] | 2482 | |
Ivan Khoronzhuk | e38b5a3 | 2016-08-10 02:22:41 +0300 | [diff] [blame] | 2483 | cpsw->irqs_table[0] = irq; |
Felipe Balbi | c03abd8 | 2015-01-16 10:11:12 -0600 | [diff] [blame] | 2484 | ret = devm_request_irq(&pdev->dev, irq, cpsw_rx_interrupt, |
Ivan Khoronzhuk | dbc4ec5 | 2016-08-10 02:22:43 +0300 | [diff] [blame] | 2485 | 0, dev_name(&pdev->dev), cpsw); |
Felipe Balbi | 5087b91 | 2015-01-16 10:11:11 -0600 | [diff] [blame] | 2486 | if (ret < 0) { |
| 2487 | dev_err(priv->dev, "error attaching irq (%d)\n", ret); |
| 2488 | goto clean_ale_ret; |
| 2489 | } |
| 2490 | |
Felipe Balbi | c03abd8 | 2015-01-16 10:11:12 -0600 | [diff] [blame] | 2491 | /* TX IRQ */ |
Felipe Balbi | 5087b91 | 2015-01-16 10:11:11 -0600 | [diff] [blame] | 2492 | irq = platform_get_irq(pdev, 2); |
Julia Lawall | c1e3334 | 2015-12-26 20:12:13 +0100 | [diff] [blame] | 2493 | if (irq < 0) { |
| 2494 | ret = irq; |
Felipe Balbi | 5087b91 | 2015-01-16 10:11:11 -0600 | [diff] [blame] | 2495 | goto clean_ale_ret; |
Julia Lawall | c1e3334 | 2015-12-26 20:12:13 +0100 | [diff] [blame] | 2496 | } |
Felipe Balbi | 5087b91 | 2015-01-16 10:11:11 -0600 | [diff] [blame] | 2497 | |
Ivan Khoronzhuk | e38b5a3 | 2016-08-10 02:22:41 +0300 | [diff] [blame] | 2498 | cpsw->irqs_table[1] = irq; |
Felipe Balbi | c03abd8 | 2015-01-16 10:11:12 -0600 | [diff] [blame] | 2499 | ret = devm_request_irq(&pdev->dev, irq, cpsw_tx_interrupt, |
Ivan Khoronzhuk | dbc4ec5 | 2016-08-10 02:22:43 +0300 | [diff] [blame] | 2500 | 0, dev_name(&pdev->dev), cpsw); |
Felipe Balbi | 5087b91 | 2015-01-16 10:11:11 -0600 | [diff] [blame] | 2501 | if (ret < 0) { |
| 2502 | dev_err(priv->dev, "error attaching irq (%d)\n", ret); |
| 2503 | goto clean_ale_ret; |
| 2504 | } |
Daniel Mack | c2b32e5 | 2014-09-04 09:00:23 +0200 | [diff] [blame] | 2505 | |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 2506 | ndev->features |= NETIF_F_HW_VLAN_CTAG_FILTER; |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 2507 | |
| 2508 | ndev->netdev_ops = &cpsw_netdev_ops; |
Wilfried Klaebe | 7ad24ea | 2014-05-11 00:12:32 +0000 | [diff] [blame] | 2509 | ndev->ethtool_ops = &cpsw_ethtool_ops; |
Ivan Khoronzhuk | dbc4ec5 | 2016-08-10 02:22:43 +0300 | [diff] [blame] | 2510 | netif_napi_add(ndev, &cpsw->napi_rx, cpsw_rx_poll, CPSW_POLL_WEIGHT); |
| 2511 | netif_tx_napi_add(ndev, &cpsw->napi_tx, cpsw_tx_poll, CPSW_POLL_WEIGHT); |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 2512 | |
| 2513 | /* register the network device */ |
| 2514 | SET_NETDEV_DEV(ndev, &pdev->dev); |
| 2515 | ret = register_netdev(ndev); |
| 2516 | if (ret) { |
| 2517 | dev_err(priv->dev, "error registering net device\n"); |
| 2518 | ret = -ENODEV; |
Daniel Mack | aa1a15e | 2013-09-21 00:50:38 +0530 | [diff] [blame] | 2519 | goto clean_ale_ret; |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 2520 | } |
| 2521 | |
Olof Johansson | 1a3b505 | 2013-12-11 15:58:07 -0800 | [diff] [blame] | 2522 | cpsw_notice(priv, probe, "initialized device (regs %pa, irq %d)\n", |
| 2523 | &ss_res->start, ndev->irq); |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 2524 | |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 2525 | if (cpsw->data.dual_emac) { |
Ivan Khoronzhuk | 56e31bd | 2016-08-10 02:22:38 +0300 | [diff] [blame] | 2526 | ret = cpsw_probe_dual_emac(priv); |
Mugunthan V N | d9ba8f9 | 2013-02-11 09:52:20 +0000 | [diff] [blame] | 2527 | if (ret) { |
| 2528 | cpsw_err(priv, probe, "error probe slave 2 emac interface\n"); |
Daniel Mack | aa1a15e | 2013-09-21 00:50:38 +0530 | [diff] [blame] | 2529 | goto clean_ale_ret; |
Mugunthan V N | d9ba8f9 | 2013-02-11 09:52:20 +0000 | [diff] [blame] | 2530 | } |
| 2531 | } |
| 2532 | |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 2533 | return 0; |
| 2534 | |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 2535 | clean_ale_ret: |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 2536 | cpsw_ale_destroy(cpsw->ale); |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 2537 | clean_dma_ret: |
Ivan Khoronzhuk | 2c836bd | 2016-08-10 02:22:40 +0300 | [diff] [blame] | 2538 | cpdma_ctlr_destroy(cpsw->dma); |
Daniel Mack | aa1a15e | 2013-09-21 00:50:38 +0530 | [diff] [blame] | 2539 | clean_runtime_disable_ret: |
Mugunthan V N | f150bd7 | 2012-07-17 08:09:50 +0000 | [diff] [blame] | 2540 | pm_runtime_disable(&pdev->dev); |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 2541 | clean_ndev_ret: |
Sebastian Siewior | d1bd9ac | 2013-04-24 08:48:23 +0000 | [diff] [blame] | 2542 | free_netdev(priv->ndev); |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 2543 | return ret; |
| 2544 | } |
| 2545 | |
Bill Pemberton | 663e12e | 2012-12-03 09:23:45 -0500 | [diff] [blame] | 2546 | static int cpsw_remove(struct platform_device *pdev) |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 2547 | { |
| 2548 | struct net_device *ndev = platform_get_drvdata(pdev); |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 2549 | struct cpsw_common *cpsw = ndev_to_cpsw(ndev); |
Grygorii Strashko | 8a0b6dc | 2016-07-28 20:50:35 +0300 | [diff] [blame] | 2550 | int ret; |
| 2551 | |
| 2552 | ret = pm_runtime_get_sync(&pdev->dev); |
| 2553 | if (ret < 0) { |
| 2554 | pm_runtime_put_noidle(&pdev->dev); |
| 2555 | return ret; |
| 2556 | } |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 2557 | |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 2558 | if (cpsw->data.dual_emac) |
| 2559 | unregister_netdev(cpsw->slaves[1].ndev); |
Sebastian Siewior | d1bd9ac | 2013-04-24 08:48:23 +0000 | [diff] [blame] | 2560 | unregister_netdev(ndev); |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 2561 | |
Ivan Khoronzhuk | 2a05a62 | 2016-08-10 02:22:44 +0300 | [diff] [blame^] | 2562 | cpsw_ale_destroy(cpsw->ale); |
Ivan Khoronzhuk | 2c836bd | 2016-08-10 02:22:40 +0300 | [diff] [blame] | 2563 | cpdma_ctlr_destroy(cpsw->dma); |
Grygorii Strashko | 3bf2cb3 | 2016-07-28 20:50:36 +0300 | [diff] [blame] | 2564 | of_platform_depopulate(&pdev->dev); |
Grygorii Strashko | 8a0b6dc | 2016-07-28 20:50:35 +0300 | [diff] [blame] | 2565 | pm_runtime_put_sync(&pdev->dev); |
| 2566 | pm_runtime_disable(&pdev->dev); |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 2567 | if (cpsw->data.dual_emac) |
| 2568 | free_netdev(cpsw->slaves[1].ndev); |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 2569 | free_netdev(ndev); |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 2570 | return 0; |
| 2571 | } |
| 2572 | |
Grygorii Strashko | 8963a50 | 2015-02-27 13:19:45 +0200 | [diff] [blame] | 2573 | #ifdef CONFIG_PM_SLEEP |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 2574 | static int cpsw_suspend(struct device *dev) |
| 2575 | { |
| 2576 | struct platform_device *pdev = to_platform_device(dev); |
| 2577 | struct net_device *ndev = platform_get_drvdata(pdev); |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 2578 | struct cpsw_common *cpsw = ndev_to_cpsw(ndev); |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 2579 | |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 2580 | if (cpsw->data.dual_emac) { |
Mugunthan V N | 618073e | 2014-09-11 22:52:38 +0530 | [diff] [blame] | 2581 | int i; |
Daniel Mack | 1e7a2e2 | 2013-11-15 08:29:16 +0100 | [diff] [blame] | 2582 | |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 2583 | for (i = 0; i < cpsw->data.slaves; i++) { |
| 2584 | if (netif_running(cpsw->slaves[i].ndev)) |
| 2585 | cpsw_ndo_stop(cpsw->slaves[i].ndev); |
Mugunthan V N | 618073e | 2014-09-11 22:52:38 +0530 | [diff] [blame] | 2586 | } |
| 2587 | } else { |
| 2588 | if (netif_running(ndev)) |
| 2589 | cpsw_ndo_stop(ndev); |
Mugunthan V N | 618073e | 2014-09-11 22:52:38 +0530 | [diff] [blame] | 2590 | } |
Daniel Mack | 1e7a2e2 | 2013-11-15 08:29:16 +0100 | [diff] [blame] | 2591 | |
Mugunthan V N | 739683b | 2013-06-06 23:45:14 +0530 | [diff] [blame] | 2592 | /* Select sleep pin state */ |
Ivan Khoronzhuk | 56e31bd | 2016-08-10 02:22:38 +0300 | [diff] [blame] | 2593 | pinctrl_pm_select_sleep_state(dev); |
Mugunthan V N | 739683b | 2013-06-06 23:45:14 +0530 | [diff] [blame] | 2594 | |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 2595 | return 0; |
| 2596 | } |
| 2597 | |
| 2598 | static int cpsw_resume(struct device *dev) |
| 2599 | { |
| 2600 | struct platform_device *pdev = to_platform_device(dev); |
| 2601 | struct net_device *ndev = platform_get_drvdata(pdev); |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 2602 | struct cpsw_common *cpsw = netdev_priv(ndev); |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 2603 | |
Mugunthan V N | 739683b | 2013-06-06 23:45:14 +0530 | [diff] [blame] | 2604 | /* Select default pin state */ |
Ivan Khoronzhuk | 56e31bd | 2016-08-10 02:22:38 +0300 | [diff] [blame] | 2605 | pinctrl_pm_select_default_state(dev); |
Mugunthan V N | 739683b | 2013-06-06 23:45:14 +0530 | [diff] [blame] | 2606 | |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 2607 | if (cpsw->data.dual_emac) { |
Mugunthan V N | 618073e | 2014-09-11 22:52:38 +0530 | [diff] [blame] | 2608 | int i; |
| 2609 | |
Ivan Khoronzhuk | 606f399 | 2016-08-10 02:22:42 +0300 | [diff] [blame] | 2610 | for (i = 0; i < cpsw->data.slaves; i++) { |
| 2611 | if (netif_running(cpsw->slaves[i].ndev)) |
| 2612 | cpsw_ndo_open(cpsw->slaves[i].ndev); |
Mugunthan V N | 618073e | 2014-09-11 22:52:38 +0530 | [diff] [blame] | 2613 | } |
| 2614 | } else { |
| 2615 | if (netif_running(ndev)) |
| 2616 | cpsw_ndo_open(ndev); |
| 2617 | } |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 2618 | return 0; |
| 2619 | } |
Grygorii Strashko | 8963a50 | 2015-02-27 13:19:45 +0200 | [diff] [blame] | 2620 | #endif |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 2621 | |
Grygorii Strashko | 8963a50 | 2015-02-27 13:19:45 +0200 | [diff] [blame] | 2622 | static SIMPLE_DEV_PM_OPS(cpsw_pm_ops, cpsw_suspend, cpsw_resume); |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 2623 | |
| 2624 | static struct platform_driver cpsw_driver = { |
| 2625 | .driver = { |
| 2626 | .name = "cpsw", |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 2627 | .pm = &cpsw_pm_ops, |
Sachin Kamat | 1e5c76d | 2013-09-30 09:55:12 +0530 | [diff] [blame] | 2628 | .of_match_table = cpsw_of_mtable, |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 2629 | }, |
| 2630 | .probe = cpsw_probe, |
Bill Pemberton | 663e12e | 2012-12-03 09:23:45 -0500 | [diff] [blame] | 2631 | .remove = cpsw_remove, |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 2632 | }; |
| 2633 | |
Grygorii Strashko | 6fb3b6b5 | 2015-10-23 14:41:12 +0300 | [diff] [blame] | 2634 | module_platform_driver(cpsw_driver); |
Mugunthan V N | df82859 | 2012-03-18 20:17:54 +0000 | [diff] [blame] | 2635 | |
| 2636 | MODULE_LICENSE("GPL"); |
| 2637 | MODULE_AUTHOR("Cyril Chemparathy <cyril@ti.com>"); |
| 2638 | MODULE_AUTHOR("Mugunthan V N <mugunthanvnm@ti.com>"); |
| 2639 | MODULE_DESCRIPTION("TI CPSW Ethernet driver"); |