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