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