Wolfram Sang | 00e1cae | 2018-08-22 00:02:19 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Sergei Shtylyov | 128296f | 2014-01-03 15:52:22 +0300 | [diff] [blame] | 2 | /* SuperH Ethernet device driver |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 3 | * |
Sergei Shtylyov | 9b39f05 | 2017-01-04 15:11:21 +0300 | [diff] [blame] | 4 | * Copyright (C) 2014 Renesas Electronics Corporation |
Nobuhiro Iwamatsu | f0e81fe | 2012-03-25 18:59:51 +0000 | [diff] [blame] | 5 | * Copyright (C) 2006-2012 Nobuhiro Iwamatsu |
Sergei Shtylyov | b356e97 | 2014-02-18 03:12:43 +0300 | [diff] [blame] | 6 | * Copyright (C) 2008-2014 Renesas Solutions Corp. |
Sergei Shtylyov | 9b39f05 | 2017-01-04 15:11:21 +0300 | [diff] [blame] | 7 | * Copyright (C) 2013-2017 Cogent Embedded, Inc. |
Ben Dooks | 702eca0 | 2014-03-12 17:47:40 +0000 | [diff] [blame] | 8 | * Copyright (C) 2014 Codethink Limited |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 9 | */ |
| 10 | |
Yoshihiro Shimoda | 0654011 | 2011-09-29 17:16:57 +0000 | [diff] [blame] | 11 | #include <linux/module.h> |
| 12 | #include <linux/kernel.h> |
| 13 | #include <linux/spinlock.h> |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 14 | #include <linux/interrupt.h> |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 15 | #include <linux/dma-mapping.h> |
| 16 | #include <linux/etherdevice.h> |
| 17 | #include <linux/delay.h> |
| 18 | #include <linux/platform_device.h> |
| 19 | #include <linux/mdio-bitbang.h> |
| 20 | #include <linux/netdevice.h> |
Sergei Shtylyov | b356e97 | 2014-02-18 03:12:43 +0300 | [diff] [blame] | 21 | #include <linux/of.h> |
| 22 | #include <linux/of_device.h> |
| 23 | #include <linux/of_irq.h> |
| 24 | #include <linux/of_net.h> |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 25 | #include <linux/phy.h> |
| 26 | #include <linux/cache.h> |
| 27 | #include <linux/io.h> |
Magnus Damm | bcd5149 | 2009-10-09 00:20:04 +0000 | [diff] [blame] | 28 | #include <linux/pm_runtime.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 29 | #include <linux/slab.h> |
Nobuhiro Iwamatsu | dc19e4e | 2011-02-15 21:17:32 +0000 | [diff] [blame] | 30 | #include <linux/ethtool.h> |
Yoshihiro Shimoda | fdb37a7 | 2012-02-06 23:55:15 +0000 | [diff] [blame] | 31 | #include <linux/if_vlan.h> |
Yoshihiro Shimoda | d4fa0e3 | 2011-09-27 21:49:12 +0000 | [diff] [blame] | 32 | #include <linux/sh_eth.h> |
Ben Dooks | 702eca0 | 2014-03-12 17:47:40 +0000 | [diff] [blame] | 33 | #include <linux/of_mdio.h> |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 34 | |
| 35 | #include "sh_eth.h" |
| 36 | |
Nobuhiro Iwamatsu | dc19e4e | 2011-02-15 21:17:32 +0000 | [diff] [blame] | 37 | #define SH_ETH_DEF_MSG_ENABLE \ |
| 38 | (NETIF_MSG_LINK | \ |
| 39 | NETIF_MSG_TIMER | \ |
| 40 | NETIF_MSG_RX_ERR| \ |
| 41 | NETIF_MSG_TX_ERR) |
| 42 | |
Sergei Shtylyov | 2274d37 | 2015-12-13 01:44:50 +0300 | [diff] [blame] | 43 | #define SH_ETH_OFFSET_INVALID ((u16)~0) |
| 44 | |
Ben Hutchings | 3365711 | 2015-02-26 20:34:14 +0000 | [diff] [blame] | 45 | #define SH_ETH_OFFSET_DEFAULTS \ |
| 46 | [0 ... SH_ETH_MAX_REGISTER_OFFSET - 1] = SH_ETH_OFFSET_INVALID |
| 47 | |
Sergei Shtylyov | c0013f6 | 2013-03-28 11:48:26 +0000 | [diff] [blame] | 48 | static const u16 sh_eth_offset_gigabit[SH_ETH_MAX_REGISTER_OFFSET] = { |
Ben Hutchings | 3365711 | 2015-02-26 20:34:14 +0000 | [diff] [blame] | 49 | SH_ETH_OFFSET_DEFAULTS, |
| 50 | |
Sergei Shtylyov | c0013f6 | 2013-03-28 11:48:26 +0000 | [diff] [blame] | 51 | [EDSR] = 0x0000, |
| 52 | [EDMR] = 0x0400, |
| 53 | [EDTRR] = 0x0408, |
| 54 | [EDRRR] = 0x0410, |
| 55 | [EESR] = 0x0428, |
| 56 | [EESIPR] = 0x0430, |
| 57 | [TDLAR] = 0x0010, |
| 58 | [TDFAR] = 0x0014, |
| 59 | [TDFXR] = 0x0018, |
| 60 | [TDFFR] = 0x001c, |
| 61 | [RDLAR] = 0x0030, |
| 62 | [RDFAR] = 0x0034, |
| 63 | [RDFXR] = 0x0038, |
| 64 | [RDFFR] = 0x003c, |
| 65 | [TRSCER] = 0x0438, |
| 66 | [RMFCR] = 0x0440, |
| 67 | [TFTR] = 0x0448, |
| 68 | [FDR] = 0x0450, |
| 69 | [RMCR] = 0x0458, |
| 70 | [RPADIR] = 0x0460, |
| 71 | [FCFTR] = 0x0468, |
| 72 | [CSMR] = 0x04E4, |
| 73 | |
| 74 | [ECMR] = 0x0500, |
| 75 | [ECSR] = 0x0510, |
| 76 | [ECSIPR] = 0x0518, |
| 77 | [PIR] = 0x0520, |
| 78 | [PSR] = 0x0528, |
| 79 | [PIPR] = 0x052c, |
| 80 | [RFLR] = 0x0508, |
| 81 | [APR] = 0x0554, |
| 82 | [MPR] = 0x0558, |
| 83 | [PFTCR] = 0x055c, |
| 84 | [PFRCR] = 0x0560, |
| 85 | [TPAUSER] = 0x0564, |
| 86 | [GECMR] = 0x05b0, |
| 87 | [BCULR] = 0x05b4, |
| 88 | [MAHR] = 0x05c0, |
| 89 | [MALR] = 0x05c8, |
| 90 | [TROCR] = 0x0700, |
| 91 | [CDCR] = 0x0708, |
| 92 | [LCCR] = 0x0710, |
| 93 | [CEFCR] = 0x0740, |
| 94 | [FRECR] = 0x0748, |
| 95 | [TSFRCR] = 0x0750, |
| 96 | [TLFRCR] = 0x0758, |
| 97 | [RFCR] = 0x0760, |
| 98 | [CERCR] = 0x0768, |
| 99 | [CEECR] = 0x0770, |
| 100 | [MAFCR] = 0x0778, |
| 101 | [RMII_MII] = 0x0790, |
| 102 | |
| 103 | [ARSTR] = 0x0000, |
| 104 | [TSU_CTRST] = 0x0004, |
| 105 | [TSU_FWEN0] = 0x0010, |
| 106 | [TSU_FWEN1] = 0x0014, |
| 107 | [TSU_FCM] = 0x0018, |
| 108 | [TSU_BSYSL0] = 0x0020, |
| 109 | [TSU_BSYSL1] = 0x0024, |
| 110 | [TSU_PRISL0] = 0x0028, |
| 111 | [TSU_PRISL1] = 0x002c, |
| 112 | [TSU_FWSL0] = 0x0030, |
| 113 | [TSU_FWSL1] = 0x0034, |
| 114 | [TSU_FWSLC] = 0x0038, |
Sergei Shtylyov | 4869a14 | 2018-02-24 20:28:16 +0300 | [diff] [blame] | 115 | [TSU_QTAGM0] = 0x0040, |
| 116 | [TSU_QTAGM1] = 0x0044, |
Sergei Shtylyov | c0013f6 | 2013-03-28 11:48:26 +0000 | [diff] [blame] | 117 | [TSU_FWSR] = 0x0050, |
| 118 | [TSU_FWINMK] = 0x0054, |
| 119 | [TSU_ADQT0] = 0x0048, |
| 120 | [TSU_ADQT1] = 0x004c, |
| 121 | [TSU_VTAG0] = 0x0058, |
| 122 | [TSU_VTAG1] = 0x005c, |
| 123 | [TSU_ADSBSY] = 0x0060, |
| 124 | [TSU_TEN] = 0x0064, |
| 125 | [TSU_POST1] = 0x0070, |
| 126 | [TSU_POST2] = 0x0074, |
| 127 | [TSU_POST3] = 0x0078, |
| 128 | [TSU_POST4] = 0x007c, |
| 129 | [TSU_ADRH0] = 0x0100, |
Sergei Shtylyov | c0013f6 | 2013-03-28 11:48:26 +0000 | [diff] [blame] | 130 | |
| 131 | [TXNLCR0] = 0x0080, |
| 132 | [TXALCR0] = 0x0084, |
| 133 | [RXNLCR0] = 0x0088, |
| 134 | [RXALCR0] = 0x008c, |
| 135 | [FWNLCR0] = 0x0090, |
| 136 | [FWALCR0] = 0x0094, |
| 137 | [TXNLCR1] = 0x00a0, |
Sergei Shtylyov | 50f3d74 | 2018-01-07 00:26:47 +0300 | [diff] [blame] | 138 | [TXALCR1] = 0x00a4, |
Sergei Shtylyov | c0013f6 | 2013-03-28 11:48:26 +0000 | [diff] [blame] | 139 | [RXNLCR1] = 0x00a8, |
| 140 | [RXALCR1] = 0x00ac, |
| 141 | [FWNLCR1] = 0x00b0, |
| 142 | [FWALCR1] = 0x00b4, |
| 143 | }; |
| 144 | |
Sergei Shtylyov | a3f109b | 2013-03-28 11:51:31 +0000 | [diff] [blame] | 145 | static const u16 sh_eth_offset_fast_rcar[SH_ETH_MAX_REGISTER_OFFSET] = { |
Ben Hutchings | 3365711 | 2015-02-26 20:34:14 +0000 | [diff] [blame] | 146 | SH_ETH_OFFSET_DEFAULTS, |
| 147 | |
Sergei Shtylyov | a3f109b | 2013-03-28 11:51:31 +0000 | [diff] [blame] | 148 | [ECMR] = 0x0300, |
| 149 | [RFLR] = 0x0308, |
| 150 | [ECSR] = 0x0310, |
| 151 | [ECSIPR] = 0x0318, |
| 152 | [PIR] = 0x0320, |
| 153 | [PSR] = 0x0328, |
| 154 | [RDMLR] = 0x0340, |
| 155 | [IPGR] = 0x0350, |
| 156 | [APR] = 0x0354, |
| 157 | [MPR] = 0x0358, |
| 158 | [RFCF] = 0x0360, |
| 159 | [TPAUSER] = 0x0364, |
| 160 | [TPAUSECR] = 0x0368, |
| 161 | [MAHR] = 0x03c0, |
| 162 | [MALR] = 0x03c8, |
| 163 | [TROCR] = 0x03d0, |
| 164 | [CDCR] = 0x03d4, |
| 165 | [LCCR] = 0x03d8, |
| 166 | [CNDCR] = 0x03dc, |
| 167 | [CEFCR] = 0x03e4, |
| 168 | [FRECR] = 0x03e8, |
| 169 | [TSFRCR] = 0x03ec, |
| 170 | [TLFRCR] = 0x03f0, |
| 171 | [RFCR] = 0x03f4, |
| 172 | [MAFCR] = 0x03f8, |
| 173 | |
| 174 | [EDMR] = 0x0200, |
| 175 | [EDTRR] = 0x0208, |
| 176 | [EDRRR] = 0x0210, |
| 177 | [TDLAR] = 0x0218, |
| 178 | [RDLAR] = 0x0220, |
| 179 | [EESR] = 0x0228, |
| 180 | [EESIPR] = 0x0230, |
| 181 | [TRSCER] = 0x0238, |
| 182 | [RMFCR] = 0x0240, |
| 183 | [TFTR] = 0x0248, |
| 184 | [FDR] = 0x0250, |
| 185 | [RMCR] = 0x0258, |
| 186 | [TFUCR] = 0x0264, |
| 187 | [RFOCR] = 0x0268, |
Simon Horman | 55754f1 | 2013-07-23 10:18:04 +0900 | [diff] [blame] | 188 | [RMIIMODE] = 0x026c, |
Sergei Shtylyov | a3f109b | 2013-03-28 11:51:31 +0000 | [diff] [blame] | 189 | [FCFTR] = 0x0270, |
| 190 | [TRIMD] = 0x027c, |
| 191 | }; |
| 192 | |
Sergei Shtylyov | c0013f6 | 2013-03-28 11:48:26 +0000 | [diff] [blame] | 193 | static const u16 sh_eth_offset_fast_sh4[SH_ETH_MAX_REGISTER_OFFSET] = { |
Ben Hutchings | 3365711 | 2015-02-26 20:34:14 +0000 | [diff] [blame] | 194 | SH_ETH_OFFSET_DEFAULTS, |
| 195 | |
Sergei Shtylyov | c0013f6 | 2013-03-28 11:48:26 +0000 | [diff] [blame] | 196 | [ECMR] = 0x0100, |
| 197 | [RFLR] = 0x0108, |
| 198 | [ECSR] = 0x0110, |
| 199 | [ECSIPR] = 0x0118, |
| 200 | [PIR] = 0x0120, |
| 201 | [PSR] = 0x0128, |
| 202 | [RDMLR] = 0x0140, |
| 203 | [IPGR] = 0x0150, |
| 204 | [APR] = 0x0154, |
| 205 | [MPR] = 0x0158, |
| 206 | [TPAUSER] = 0x0164, |
| 207 | [RFCF] = 0x0160, |
| 208 | [TPAUSECR] = 0x0168, |
| 209 | [BCFRR] = 0x016c, |
| 210 | [MAHR] = 0x01c0, |
| 211 | [MALR] = 0x01c8, |
| 212 | [TROCR] = 0x01d0, |
| 213 | [CDCR] = 0x01d4, |
| 214 | [LCCR] = 0x01d8, |
| 215 | [CNDCR] = 0x01dc, |
| 216 | [CEFCR] = 0x01e4, |
| 217 | [FRECR] = 0x01e8, |
| 218 | [TSFRCR] = 0x01ec, |
| 219 | [TLFRCR] = 0x01f0, |
| 220 | [RFCR] = 0x01f4, |
| 221 | [MAFCR] = 0x01f8, |
| 222 | [RTRATE] = 0x01fc, |
| 223 | |
| 224 | [EDMR] = 0x0000, |
| 225 | [EDTRR] = 0x0008, |
| 226 | [EDRRR] = 0x0010, |
| 227 | [TDLAR] = 0x0018, |
| 228 | [RDLAR] = 0x0020, |
| 229 | [EESR] = 0x0028, |
| 230 | [EESIPR] = 0x0030, |
| 231 | [TRSCER] = 0x0038, |
| 232 | [RMFCR] = 0x0040, |
| 233 | [TFTR] = 0x0048, |
| 234 | [FDR] = 0x0050, |
| 235 | [RMCR] = 0x0058, |
| 236 | [TFUCR] = 0x0064, |
| 237 | [RFOCR] = 0x0068, |
| 238 | [FCFTR] = 0x0070, |
| 239 | [RPADIR] = 0x0078, |
| 240 | [TRIMD] = 0x007c, |
| 241 | [RBWAR] = 0x00c8, |
| 242 | [RDFAR] = 0x00cc, |
| 243 | [TBRAR] = 0x00d4, |
| 244 | [TDFAR] = 0x00d8, |
| 245 | }; |
| 246 | |
| 247 | static const u16 sh_eth_offset_fast_sh3_sh2[SH_ETH_MAX_REGISTER_OFFSET] = { |
Ben Hutchings | 3365711 | 2015-02-26 20:34:14 +0000 | [diff] [blame] | 248 | SH_ETH_OFFSET_DEFAULTS, |
| 249 | |
Sergei Shtylyov | d8b0426 | 2014-06-03 23:42:26 +0400 | [diff] [blame] | 250 | [EDMR] = 0x0000, |
| 251 | [EDTRR] = 0x0004, |
| 252 | [EDRRR] = 0x0008, |
| 253 | [TDLAR] = 0x000c, |
| 254 | [RDLAR] = 0x0010, |
| 255 | [EESR] = 0x0014, |
| 256 | [EESIPR] = 0x0018, |
| 257 | [TRSCER] = 0x001c, |
| 258 | [RMFCR] = 0x0020, |
| 259 | [TFTR] = 0x0024, |
| 260 | [FDR] = 0x0028, |
| 261 | [RMCR] = 0x002c, |
| 262 | [EDOCR] = 0x0030, |
| 263 | [FCFTR] = 0x0034, |
| 264 | [RPADIR] = 0x0038, |
| 265 | [TRIMD] = 0x003c, |
| 266 | [RBWAR] = 0x0040, |
| 267 | [RDFAR] = 0x0044, |
| 268 | [TBRAR] = 0x004c, |
| 269 | [TDFAR] = 0x0050, |
| 270 | |
Sergei Shtylyov | c0013f6 | 2013-03-28 11:48:26 +0000 | [diff] [blame] | 271 | [ECMR] = 0x0160, |
| 272 | [ECSR] = 0x0164, |
| 273 | [ECSIPR] = 0x0168, |
| 274 | [PIR] = 0x016c, |
| 275 | [MAHR] = 0x0170, |
| 276 | [MALR] = 0x0174, |
| 277 | [RFLR] = 0x0178, |
| 278 | [PSR] = 0x017c, |
| 279 | [TROCR] = 0x0180, |
| 280 | [CDCR] = 0x0184, |
| 281 | [LCCR] = 0x0188, |
| 282 | [CNDCR] = 0x018c, |
| 283 | [CEFCR] = 0x0194, |
| 284 | [FRECR] = 0x0198, |
| 285 | [TSFRCR] = 0x019c, |
| 286 | [TLFRCR] = 0x01a0, |
| 287 | [RFCR] = 0x01a4, |
| 288 | [MAFCR] = 0x01a8, |
| 289 | [IPGR] = 0x01b4, |
| 290 | [APR] = 0x01b8, |
| 291 | [MPR] = 0x01bc, |
| 292 | [TPAUSER] = 0x01c4, |
| 293 | [BCFR] = 0x01cc, |
| 294 | |
| 295 | [ARSTR] = 0x0000, |
| 296 | [TSU_CTRST] = 0x0004, |
| 297 | [TSU_FWEN0] = 0x0010, |
| 298 | [TSU_FWEN1] = 0x0014, |
| 299 | [TSU_FCM] = 0x0018, |
| 300 | [TSU_BSYSL0] = 0x0020, |
| 301 | [TSU_BSYSL1] = 0x0024, |
| 302 | [TSU_PRISL0] = 0x0028, |
| 303 | [TSU_PRISL1] = 0x002c, |
| 304 | [TSU_FWSL0] = 0x0030, |
| 305 | [TSU_FWSL1] = 0x0034, |
| 306 | [TSU_FWSLC] = 0x0038, |
| 307 | [TSU_QTAGM0] = 0x0040, |
| 308 | [TSU_QTAGM1] = 0x0044, |
| 309 | [TSU_ADQT0] = 0x0048, |
| 310 | [TSU_ADQT1] = 0x004c, |
| 311 | [TSU_FWSR] = 0x0050, |
| 312 | [TSU_FWINMK] = 0x0054, |
| 313 | [TSU_ADSBSY] = 0x0060, |
| 314 | [TSU_TEN] = 0x0064, |
| 315 | [TSU_POST1] = 0x0070, |
| 316 | [TSU_POST2] = 0x0074, |
| 317 | [TSU_POST3] = 0x0078, |
| 318 | [TSU_POST4] = 0x007c, |
| 319 | |
| 320 | [TXNLCR0] = 0x0080, |
| 321 | [TXALCR0] = 0x0084, |
| 322 | [RXNLCR0] = 0x0088, |
| 323 | [RXALCR0] = 0x008c, |
| 324 | [FWNLCR0] = 0x0090, |
| 325 | [FWALCR0] = 0x0094, |
| 326 | [TXNLCR1] = 0x00a0, |
Sergei Shtylyov | 50f3d74 | 2018-01-07 00:26:47 +0300 | [diff] [blame] | 327 | [TXALCR1] = 0x00a4, |
Sergei Shtylyov | c0013f6 | 2013-03-28 11:48:26 +0000 | [diff] [blame] | 328 | [RXNLCR1] = 0x00a8, |
| 329 | [RXALCR1] = 0x00ac, |
| 330 | [FWNLCR1] = 0x00b0, |
| 331 | [FWALCR1] = 0x00b4, |
| 332 | |
| 333 | [TSU_ADRH0] = 0x0100, |
Sergei Shtylyov | c0013f6 | 2013-03-28 11:48:26 +0000 | [diff] [blame] | 334 | }; |
| 335 | |
Ben Hutchings | 740c7f3 | 2015-01-27 00:49:32 +0000 | [diff] [blame] | 336 | static void sh_eth_rcv_snd_disable(struct net_device *ndev); |
| 337 | static struct net_device_stats *sh_eth_get_stats(struct net_device *ndev); |
| 338 | |
Sergei Shtylyov | 2274d37 | 2015-12-13 01:44:50 +0300 | [diff] [blame] | 339 | static void sh_eth_write(struct net_device *ndev, u32 data, int enum_index) |
| 340 | { |
| 341 | struct sh_eth_private *mdp = netdev_priv(ndev); |
| 342 | u16 offset = mdp->reg_offset[enum_index]; |
| 343 | |
| 344 | if (WARN_ON(offset == SH_ETH_OFFSET_INVALID)) |
| 345 | return; |
| 346 | |
| 347 | iowrite32(data, mdp->addr + offset); |
| 348 | } |
| 349 | |
| 350 | static u32 sh_eth_read(struct net_device *ndev, int enum_index) |
| 351 | { |
| 352 | struct sh_eth_private *mdp = netdev_priv(ndev); |
| 353 | u16 offset = mdp->reg_offset[enum_index]; |
| 354 | |
| 355 | if (WARN_ON(offset == SH_ETH_OFFSET_INVALID)) |
| 356 | return ~0U; |
| 357 | |
| 358 | return ioread32(mdp->addr + offset); |
| 359 | } |
| 360 | |
Sergei Shtylyov | b2b14d2 | 2016-02-10 01:38:28 +0300 | [diff] [blame] | 361 | static void sh_eth_modify(struct net_device *ndev, int enum_index, u32 clear, |
| 362 | u32 set) |
| 363 | { |
| 364 | sh_eth_write(ndev, (sh_eth_read(ndev, enum_index) & ~clear) | set, |
| 365 | enum_index); |
| 366 | } |
| 367 | |
Sergei Shtylyov | 41414f0 | 2018-07-23 21:11:19 +0300 | [diff] [blame] | 368 | static u16 sh_eth_tsu_get_offset(struct sh_eth_private *mdp, int enum_index) |
Sergei Shtylyov | 388c4bb | 2018-07-23 21:10:02 +0300 | [diff] [blame] | 369 | { |
Sergei Shtylyov | 41414f0 | 2018-07-23 21:11:19 +0300 | [diff] [blame] | 370 | return mdp->reg_offset[enum_index]; |
Sergei Shtylyov | 388c4bb | 2018-07-23 21:10:02 +0300 | [diff] [blame] | 371 | } |
| 372 | |
Sergei Shtylyov | 55ea874 | 2018-02-27 14:58:16 +0300 | [diff] [blame] | 373 | static void sh_eth_tsu_write(struct sh_eth_private *mdp, u32 data, |
| 374 | int enum_index) |
| 375 | { |
Sergei Shtylyov | ecbecb0 | 2018-07-23 21:12:38 +0300 | [diff] [blame] | 376 | u16 offset = sh_eth_tsu_get_offset(mdp, enum_index); |
Sergei Shtylyov | 627a0d2 | 2018-05-02 22:55:52 +0300 | [diff] [blame] | 377 | |
| 378 | if (WARN_ON(offset == SH_ETH_OFFSET_INVALID)) |
| 379 | return; |
| 380 | |
| 381 | iowrite32(data, mdp->tsu_addr + offset); |
Sergei Shtylyov | 55ea874 | 2018-02-27 14:58:16 +0300 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | static u32 sh_eth_tsu_read(struct sh_eth_private *mdp, int enum_index) |
| 385 | { |
Sergei Shtylyov | ecbecb0 | 2018-07-23 21:12:38 +0300 | [diff] [blame] | 386 | u16 offset = sh_eth_tsu_get_offset(mdp, enum_index); |
Sergei Shtylyov | 627a0d2 | 2018-05-02 22:55:52 +0300 | [diff] [blame] | 387 | |
| 388 | if (WARN_ON(offset == SH_ETH_OFFSET_INVALID)) |
| 389 | return ~0U; |
| 390 | |
| 391 | return ioread32(mdp->tsu_addr + offset); |
Sergei Shtylyov | 55ea874 | 2018-02-27 14:58:16 +0300 | [diff] [blame] | 392 | } |
| 393 | |
Sergei Shtylyov | bb2fa4e | 2018-06-02 22:38:56 +0300 | [diff] [blame] | 394 | static void sh_eth_soft_swap(char *src, int len) |
| 395 | { |
| 396 | #ifdef __LITTLE_ENDIAN |
| 397 | u32 *p = (u32 *)src; |
Sergei Shtylyov | 1100149 | 2018-06-02 22:40:16 +0300 | [diff] [blame] | 398 | u32 *maxp = p + DIV_ROUND_UP(len, sizeof(u32)); |
Sergei Shtylyov | bb2fa4e | 2018-06-02 22:38:56 +0300 | [diff] [blame] | 399 | |
| 400 | for (; p < maxp; p++) |
| 401 | *p = swab32(*p); |
| 402 | #endif |
| 403 | } |
| 404 | |
Sergei Shtylyov | 8e99440 | 2013-06-12 03:07:29 +0400 | [diff] [blame] | 405 | static void sh_eth_select_mii(struct net_device *ndev) |
Nobuhiro Iwamatsu | 5e7a76b | 2012-06-25 17:34:14 +0000 | [diff] [blame] | 406 | { |
Nobuhiro Iwamatsu | 5e7a76b | 2012-06-25 17:34:14 +0000 | [diff] [blame] | 407 | struct sh_eth_private *mdp = netdev_priv(ndev); |
Sergei Shtylyov | 4fa8c3c | 2016-03-13 01:29:45 +0300 | [diff] [blame] | 408 | u32 value; |
Nobuhiro Iwamatsu | 5e7a76b | 2012-06-25 17:34:14 +0000 | [diff] [blame] | 409 | |
| 410 | switch (mdp->phy_interface) { |
Sergei Shtylyov | 230c184 | 2018-05-18 21:30:18 +0300 | [diff] [blame] | 411 | case PHY_INTERFACE_MODE_RGMII ... PHY_INTERFACE_MODE_RGMII_TXID: |
| 412 | value = 0x3; |
| 413 | break; |
Nobuhiro Iwamatsu | 5e7a76b | 2012-06-25 17:34:14 +0000 | [diff] [blame] | 414 | case PHY_INTERFACE_MODE_GMII: |
| 415 | value = 0x2; |
| 416 | break; |
| 417 | case PHY_INTERFACE_MODE_MII: |
| 418 | value = 0x1; |
| 419 | break; |
| 420 | case PHY_INTERFACE_MODE_RMII: |
| 421 | value = 0x0; |
| 422 | break; |
| 423 | default: |
Sergei Shtylyov | f75f14e | 2014-03-15 03:27:54 +0300 | [diff] [blame] | 424 | netdev_warn(ndev, |
| 425 | "PHY interface mode was not setup. Set to MII.\n"); |
Nobuhiro Iwamatsu | 5e7a76b | 2012-06-25 17:34:14 +0000 | [diff] [blame] | 426 | value = 0x1; |
| 427 | break; |
| 428 | } |
| 429 | |
| 430 | sh_eth_write(ndev, value, RMII_MII); |
| 431 | } |
Nobuhiro Iwamatsu | 5e7a76b | 2012-06-25 17:34:14 +0000 | [diff] [blame] | 432 | |
Sergei Shtylyov | 8e99440 | 2013-06-12 03:07:29 +0400 | [diff] [blame] | 433 | static void sh_eth_set_duplex(struct net_device *ndev) |
Yoshihiro Shimoda | 65ac885 | 2009-05-24 23:54:30 +0000 | [diff] [blame] | 434 | { |
| 435 | struct sh_eth_private *mdp = netdev_priv(ndev); |
Yoshihiro Shimoda | 65ac885 | 2009-05-24 23:54:30 +0000 | [diff] [blame] | 436 | |
Sergei Shtylyov | b2b14d2 | 2016-02-10 01:38:28 +0300 | [diff] [blame] | 437 | sh_eth_modify(ndev, ECMR, ECMR_DM, mdp->duplex ? ECMR_DM : 0); |
Yoshihiro Shimoda | 65ac885 | 2009-05-24 23:54:30 +0000 | [diff] [blame] | 438 | } |
| 439 | |
Geert Uytterhoeven | 99f84be6 | 2015-11-24 15:40:57 +0100 | [diff] [blame] | 440 | static void sh_eth_chip_reset(struct net_device *ndev) |
| 441 | { |
| 442 | struct sh_eth_private *mdp = netdev_priv(ndev); |
| 443 | |
| 444 | /* reset device */ |
Sergei Shtylyov | ec65cfc | 2016-04-24 23:46:15 +0300 | [diff] [blame] | 445 | sh_eth_tsu_write(mdp, ARSTR_ARST, ARSTR); |
Geert Uytterhoeven | 99f84be6 | 2015-11-24 15:40:57 +0100 | [diff] [blame] | 446 | mdelay(1); |
| 447 | } |
| 448 | |
Sergei Shtylyov | 4ceedeb | 2018-03-24 23:07:41 +0300 | [diff] [blame] | 449 | static int sh_eth_soft_reset(struct net_device *ndev) |
| 450 | { |
| 451 | sh_eth_modify(ndev, EDMR, EDMR_SRST_ETHER, EDMR_SRST_ETHER); |
| 452 | mdelay(3); |
| 453 | sh_eth_modify(ndev, EDMR, EDMR_SRST_ETHER, 0); |
| 454 | |
| 455 | return 0; |
| 456 | } |
| 457 | |
| 458 | static int sh_eth_check_soft_reset(struct net_device *ndev) |
| 459 | { |
| 460 | int cnt; |
| 461 | |
| 462 | for (cnt = 100; cnt > 0; cnt--) { |
| 463 | if (!(sh_eth_read(ndev, EDMR) & EDMR_SRST_GETHER)) |
| 464 | return 0; |
| 465 | mdelay(1); |
| 466 | } |
| 467 | |
| 468 | netdev_err(ndev, "Device reset failed\n"); |
| 469 | return -ETIMEDOUT; |
| 470 | } |
| 471 | |
| 472 | static int sh_eth_soft_reset_gether(struct net_device *ndev) |
| 473 | { |
| 474 | struct sh_eth_private *mdp = netdev_priv(ndev); |
| 475 | int ret; |
| 476 | |
| 477 | sh_eth_write(ndev, EDSR_ENALL, EDSR); |
| 478 | sh_eth_modify(ndev, EDMR, EDMR_SRST_GETHER, EDMR_SRST_GETHER); |
| 479 | |
| 480 | ret = sh_eth_check_soft_reset(ndev); |
| 481 | if (ret) |
| 482 | return ret; |
| 483 | |
| 484 | /* Table Init */ |
| 485 | sh_eth_write(ndev, 0, TDLAR); |
| 486 | sh_eth_write(ndev, 0, TDFAR); |
| 487 | sh_eth_write(ndev, 0, TDFXR); |
| 488 | sh_eth_write(ndev, 0, TDFFR); |
| 489 | sh_eth_write(ndev, 0, RDLAR); |
| 490 | sh_eth_write(ndev, 0, RDFAR); |
| 491 | sh_eth_write(ndev, 0, RDFXR); |
| 492 | sh_eth_write(ndev, 0, RDFFR); |
| 493 | |
| 494 | /* Reset HW CRC register */ |
Sergei Shtylyov | 2c2ab5a | 2019-02-04 21:05:55 +0300 | [diff] [blame] | 495 | if (mdp->cd->csmr) |
Sergei Shtylyov | 4ceedeb | 2018-03-24 23:07:41 +0300 | [diff] [blame] | 496 | sh_eth_write(ndev, 0, CSMR); |
| 497 | |
| 498 | /* Select MII mode */ |
| 499 | if (mdp->cd->select_mii) |
| 500 | sh_eth_select_mii(ndev); |
| 501 | |
| 502 | return ret; |
| 503 | } |
| 504 | |
Geert Uytterhoeven | a0f48be | 2015-11-24 15:40:59 +0100 | [diff] [blame] | 505 | static void sh_eth_set_rate_gether(struct net_device *ndev) |
| 506 | { |
| 507 | struct sh_eth_private *mdp = netdev_priv(ndev); |
| 508 | |
Sergei Shtylyov | a6318d5 | 2020-02-15 23:13:45 +0300 | [diff] [blame] | 509 | if (WARN_ON(!mdp->cd->gecmr)) |
| 510 | return; |
| 511 | |
Geert Uytterhoeven | a0f48be | 2015-11-24 15:40:59 +0100 | [diff] [blame] | 512 | switch (mdp->speed) { |
| 513 | case 10: /* 10BASE */ |
| 514 | sh_eth_write(ndev, GECMR_10, GECMR); |
| 515 | break; |
| 516 | case 100:/* 100BASE */ |
| 517 | sh_eth_write(ndev, GECMR_100, GECMR); |
| 518 | break; |
| 519 | case 1000: /* 1000BASE */ |
| 520 | sh_eth_write(ndev, GECMR_1000, GECMR); |
| 521 | break; |
Geert Uytterhoeven | a0f48be | 2015-11-24 15:40:59 +0100 | [diff] [blame] | 522 | } |
| 523 | } |
| 524 | |
Geert Uytterhoeven | 99f84be6 | 2015-11-24 15:40:57 +0100 | [diff] [blame] | 525 | #ifdef CONFIG_OF |
| 526 | /* R7S72100 */ |
| 527 | static struct sh_eth_cpu_data r7s72100_data = { |
Sergei Shtylyov | 4ceedeb | 2018-03-24 23:07:41 +0300 | [diff] [blame] | 528 | .soft_reset = sh_eth_soft_reset_gether, |
| 529 | |
Geert Uytterhoeven | 99f84be6 | 2015-11-24 15:40:57 +0100 | [diff] [blame] | 530 | .chip_reset = sh_eth_chip_reset, |
| 531 | .set_duplex = sh_eth_set_duplex, |
| 532 | |
Sergei Shtylyov | b39b709 | 2020-02-15 23:14:44 +0300 | [diff] [blame] | 533 | .register_type = SH_ETH_REG_GIGABIT, |
Geert Uytterhoeven | 99f84be6 | 2015-11-24 15:40:57 +0100 | [diff] [blame] | 534 | |
Sergei Shtylyov | 3e41699 | 2018-03-24 23:08:42 +0300 | [diff] [blame] | 535 | .edtrr_trns = EDTRR_TRNS_GETHER, |
Geert Uytterhoeven | 99f84be6 | 2015-11-24 15:40:57 +0100 | [diff] [blame] | 536 | .ecsr_value = ECSR_ICD, |
| 537 | .ecsipr_value = ECSIPR_ICDIP, |
Sergei Shtylyov | 2b2d3eb | 2017-01-29 15:13:48 +0300 | [diff] [blame] | 538 | .eesipr_value = EESIPR_TWB1IP | EESIPR_TWBIP | EESIPR_TC1IP | |
| 539 | EESIPR_TABTIP | EESIPR_RABTIP | EESIPR_RFCOFIP | |
| 540 | EESIPR_ECIIP | |
| 541 | EESIPR_FTCIP | EESIPR_TDEIP | EESIPR_TFUFIP | |
| 542 | EESIPR_FRIP | EESIPR_RDEIP | EESIPR_RFOFIP | |
| 543 | EESIPR_RMAFIP | EESIPR_RRFIP | |
| 544 | EESIPR_RTLFIP | EESIPR_RTSFIP | |
| 545 | EESIPR_PREIP | EESIPR_CERFIP, |
Geert Uytterhoeven | 99f84be6 | 2015-11-24 15:40:57 +0100 | [diff] [blame] | 546 | |
| 547 | .tx_check = EESR_TC1 | EESR_FTC, |
| 548 | .eesr_err_check = EESR_TWB1 | EESR_TWB | EESR_TABT | EESR_RABT | |
| 549 | EESR_RFE | EESR_RDE | EESR_RFRMER | EESR_TFE | |
Sergei Shtylyov | 9b39f05 | 2017-01-04 15:11:21 +0300 | [diff] [blame] | 550 | EESR_TDE, |
Geert Uytterhoeven | 99f84be6 | 2015-11-24 15:40:57 +0100 | [diff] [blame] | 551 | .fdr_value = 0x0000070f, |
| 552 | |
| 553 | .no_psr = 1, |
| 554 | .apr = 1, |
| 555 | .mpr = 1, |
| 556 | .tpauser = 1, |
| 557 | .hw_swap = 1, |
| 558 | .rpadir = 1, |
Geert Uytterhoeven | 99f84be6 | 2015-11-24 15:40:57 +0100 | [diff] [blame] | 559 | .no_trimd = 1, |
| 560 | .no_ade = 1, |
Sergei Shtylyov | 246e30c | 2018-03-24 23:09:55 +0300 | [diff] [blame] | 561 | .xdfar_rw = 1, |
Sergei Shtylyov | 2c2ab5a | 2019-02-04 21:05:55 +0300 | [diff] [blame] | 562 | .csmr = 1, |
Sergei Shtylyov | 48132cd | 2019-02-04 21:07:53 +0300 | [diff] [blame] | 563 | .rx_csum = 1, |
Geert Uytterhoeven | 99f84be6 | 2015-11-24 15:40:57 +0100 | [diff] [blame] | 564 | .tsu = 1, |
Sergei Shtylyov | ce9134d | 2018-03-24 23:11:19 +0300 | [diff] [blame] | 565 | .no_tx_cntrs = 1, |
Geert Uytterhoeven | 99f84be6 | 2015-11-24 15:40:57 +0100 | [diff] [blame] | 566 | }; |
Geert Uytterhoeven | a0f48be | 2015-11-24 15:40:59 +0100 | [diff] [blame] | 567 | |
| 568 | static void sh_eth_chip_reset_r8a7740(struct net_device *ndev) |
| 569 | { |
Sergei Shtylyov | c66b258 | 2016-05-07 14:09:01 -0700 | [diff] [blame] | 570 | sh_eth_chip_reset(ndev); |
Geert Uytterhoeven | a0f48be | 2015-11-24 15:40:59 +0100 | [diff] [blame] | 571 | |
| 572 | sh_eth_select_mii(ndev); |
| 573 | } |
| 574 | |
| 575 | /* R8A7740 */ |
| 576 | static struct sh_eth_cpu_data r8a7740_data = { |
Sergei Shtylyov | 4ceedeb | 2018-03-24 23:07:41 +0300 | [diff] [blame] | 577 | .soft_reset = sh_eth_soft_reset_gether, |
| 578 | |
Geert Uytterhoeven | a0f48be | 2015-11-24 15:40:59 +0100 | [diff] [blame] | 579 | .chip_reset = sh_eth_chip_reset_r8a7740, |
| 580 | .set_duplex = sh_eth_set_duplex, |
| 581 | .set_rate = sh_eth_set_rate_gether, |
| 582 | |
| 583 | .register_type = SH_ETH_REG_GIGABIT, |
| 584 | |
Sergei Shtylyov | 3e41699 | 2018-03-24 23:08:42 +0300 | [diff] [blame] | 585 | .edtrr_trns = EDTRR_TRNS_GETHER, |
Geert Uytterhoeven | a0f48be | 2015-11-24 15:40:59 +0100 | [diff] [blame] | 586 | .ecsr_value = ECSR_ICD | ECSR_MPD, |
| 587 | .ecsipr_value = ECSIPR_LCHNGIP | ECSIPR_ICDIP | ECSIPR_MPDIP, |
Sergei Shtylyov | 2b2d3eb | 2017-01-29 15:13:48 +0300 | [diff] [blame] | 588 | .eesipr_value = EESIPR_RFCOFIP | EESIPR_ECIIP | |
| 589 | EESIPR_FTCIP | EESIPR_TDEIP | EESIPR_TFUFIP | |
| 590 | EESIPR_FRIP | EESIPR_RDEIP | EESIPR_RFOFIP | |
| 591 | 0x0000f000 | EESIPR_CNDIP | EESIPR_DLCIP | |
| 592 | EESIPR_CDIP | EESIPR_TROIP | EESIPR_RMAFIP | |
| 593 | EESIPR_CEEFIP | EESIPR_CELFIP | |
| 594 | EESIPR_RRFIP | EESIPR_RTLFIP | EESIPR_RTSFIP | |
| 595 | EESIPR_PREIP | EESIPR_CERFIP, |
Geert Uytterhoeven | a0f48be | 2015-11-24 15:40:59 +0100 | [diff] [blame] | 596 | |
| 597 | .tx_check = EESR_TC1 | EESR_FTC, |
| 598 | .eesr_err_check = EESR_TWB1 | EESR_TWB | EESR_TABT | EESR_RABT | |
| 599 | EESR_RFE | EESR_RDE | EESR_RFRMER | EESR_TFE | |
Sergei Shtylyov | 9b39f05 | 2017-01-04 15:11:21 +0300 | [diff] [blame] | 600 | EESR_TDE, |
Geert Uytterhoeven | a0f48be | 2015-11-24 15:40:59 +0100 | [diff] [blame] | 601 | .fdr_value = 0x0000070f, |
| 602 | |
| 603 | .apr = 1, |
| 604 | .mpr = 1, |
| 605 | .tpauser = 1, |
Sergei Shtylyov | a6318d5 | 2020-02-15 23:13:45 +0300 | [diff] [blame] | 606 | .gecmr = 1, |
Geert Uytterhoeven | a0f48be | 2015-11-24 15:40:59 +0100 | [diff] [blame] | 607 | .bculr = 1, |
| 608 | .hw_swap = 1, |
| 609 | .rpadir = 1, |
Geert Uytterhoeven | a0f48be | 2015-11-24 15:40:59 +0100 | [diff] [blame] | 610 | .no_trimd = 1, |
| 611 | .no_ade = 1, |
Sergei Shtylyov | 246e30c | 2018-03-24 23:09:55 +0300 | [diff] [blame] | 612 | .xdfar_rw = 1, |
Sergei Shtylyov | 2c2ab5a | 2019-02-04 21:05:55 +0300 | [diff] [blame] | 613 | .csmr = 1, |
Sergei Shtylyov | 040c16f | 2019-02-04 21:08:54 +0300 | [diff] [blame] | 614 | .rx_csum = 1, |
Geert Uytterhoeven | a0f48be | 2015-11-24 15:40:59 +0100 | [diff] [blame] | 615 | .tsu = 1, |
| 616 | .select_mii = 1, |
Niklas Söderlund | 33017e2 | 2017-01-09 16:34:07 +0100 | [diff] [blame] | 617 | .magic = 1, |
Sergei Shtylyov | 4c1d458 | 2018-03-24 23:12:54 +0300 | [diff] [blame] | 618 | .cexcr = 1, |
Geert Uytterhoeven | a0f48be | 2015-11-24 15:40:59 +0100 | [diff] [blame] | 619 | }; |
Geert Uytterhoeven | 99f84be6 | 2015-11-24 15:40:57 +0100 | [diff] [blame] | 620 | |
Nobuhiro Iwamatsu | 04b0ed2 | 2013-06-06 09:45:25 +0000 | [diff] [blame] | 621 | /* There is CPU dependent code */ |
Simon Horman | 6c4b2f7 | 2017-10-18 09:21:27 +0200 | [diff] [blame] | 622 | static void sh_eth_set_rate_rcar(struct net_device *ndev) |
Yoshihiro Shimoda | 65ac885 | 2009-05-24 23:54:30 +0000 | [diff] [blame] | 623 | { |
| 624 | struct sh_eth_private *mdp = netdev_priv(ndev); |
Yoshihiro Shimoda | 65ac885 | 2009-05-24 23:54:30 +0000 | [diff] [blame] | 625 | |
| 626 | switch (mdp->speed) { |
| 627 | case 10: /* 10BASE */ |
Sergei Shtylyov | b2b14d2 | 2016-02-10 01:38:28 +0300 | [diff] [blame] | 628 | sh_eth_modify(ndev, ECMR, ECMR_ELB, 0); |
Yoshihiro Shimoda | 65ac885 | 2009-05-24 23:54:30 +0000 | [diff] [blame] | 629 | break; |
| 630 | case 100:/* 100BASE */ |
Sergei Shtylyov | b2b14d2 | 2016-02-10 01:38:28 +0300 | [diff] [blame] | 631 | sh_eth_modify(ndev, ECMR, ECMR_ELB, ECMR_ELB); |
Sergei Shtylyov | a3f109b | 2013-03-28 11:51:31 +0000 | [diff] [blame] | 632 | break; |
Sergei Shtylyov | a3f109b | 2013-03-28 11:51:31 +0000 | [diff] [blame] | 633 | } |
| 634 | } |
| 635 | |
Simon Horman | 6c4b2f7 | 2017-10-18 09:21:27 +0200 | [diff] [blame] | 636 | /* R-Car Gen1 */ |
| 637 | static struct sh_eth_cpu_data rcar_gen1_data = { |
Sergei Shtylyov | 4ceedeb | 2018-03-24 23:07:41 +0300 | [diff] [blame] | 638 | .soft_reset = sh_eth_soft_reset, |
| 639 | |
Sergei Shtylyov | a3f109b | 2013-03-28 11:51:31 +0000 | [diff] [blame] | 640 | .set_duplex = sh_eth_set_duplex, |
Simon Horman | 6c4b2f7 | 2017-10-18 09:21:27 +0200 | [diff] [blame] | 641 | .set_rate = sh_eth_set_rate_rcar, |
Sergei Shtylyov | a3f109b | 2013-03-28 11:51:31 +0000 | [diff] [blame] | 642 | |
Sergei Shtylyov | a3153d8 | 2013-08-18 03:11:28 +0400 | [diff] [blame] | 643 | .register_type = SH_ETH_REG_FAST_RCAR, |
| 644 | |
Sergei Shtylyov | 3e41699 | 2018-03-24 23:08:42 +0300 | [diff] [blame] | 645 | .edtrr_trns = EDTRR_TRNS_ETHER, |
Sergei Shtylyov | a3f109b | 2013-03-28 11:51:31 +0000 | [diff] [blame] | 646 | .ecsr_value = ECSR_PSRTO | ECSR_LCHNG | ECSR_ICD, |
| 647 | .ecsipr_value = ECSIPR_PSRTOIP | ECSIPR_LCHNGIP | ECSIPR_ICDIP, |
Sergei Shtylyov | 2b2d3eb | 2017-01-29 15:13:48 +0300 | [diff] [blame] | 648 | .eesipr_value = EESIPR_RFCOFIP | EESIPR_ADEIP | EESIPR_ECIIP | |
| 649 | EESIPR_FTCIP | EESIPR_TDEIP | EESIPR_TFUFIP | |
| 650 | EESIPR_FRIP | EESIPR_RDEIP | EESIPR_RFOFIP | |
| 651 | EESIPR_RMAFIP | EESIPR_RRFIP | |
| 652 | EESIPR_RTLFIP | EESIPR_RTSFIP | |
| 653 | EESIPR_PREIP | EESIPR_CERFIP, |
Sergei Shtylyov | a3f109b | 2013-03-28 11:51:31 +0000 | [diff] [blame] | 654 | |
Sergei Shtylyov | 2716449 | 2018-05-20 00:02:36 +0300 | [diff] [blame] | 655 | .tx_check = EESR_FTC | EESR_CND | EESR_DLC | EESR_CD | EESR_TRO, |
Sergei Shtylyov | ca8c358 | 2013-06-21 01:12:21 +0400 | [diff] [blame] | 656 | .eesr_err_check = EESR_TWB | EESR_TABT | EESR_RABT | EESR_RFE | |
Sergei Shtylyov | 9b39f05 | 2017-01-04 15:11:21 +0300 | [diff] [blame] | 657 | EESR_RDE | EESR_RFRMER | EESR_TFE | EESR_TDE, |
Nobuhiro Iwamatsu | d407bc0 | 2015-01-07 14:40:15 +0900 | [diff] [blame] | 658 | .fdr_value = 0x00000f0f, |
Sergei Shtylyov | a3f109b | 2013-03-28 11:51:31 +0000 | [diff] [blame] | 659 | |
| 660 | .apr = 1, |
| 661 | .mpr = 1, |
| 662 | .tpauser = 1, |
| 663 | .hw_swap = 1, |
Sergei Shtylyov | 6e80e55 | 2018-04-01 00:22:08 +0300 | [diff] [blame] | 664 | .no_xdfar = 1, |
Sergei Shtylyov | a3f109b | 2013-03-28 11:51:31 +0000 | [diff] [blame] | 665 | }; |
Sergei Shtylyov | a3f109b | 2013-03-28 11:51:31 +0000 | [diff] [blame] | 666 | |
Simon Horman | 6c4b2f7 | 2017-10-18 09:21:27 +0200 | [diff] [blame] | 667 | /* R-Car Gen2 and RZ/G1 */ |
| 668 | static struct sh_eth_cpu_data rcar_gen2_data = { |
Sergei Shtylyov | 4ceedeb | 2018-03-24 23:07:41 +0300 | [diff] [blame] | 669 | .soft_reset = sh_eth_soft_reset, |
| 670 | |
Simon Horman | e18dbf7 | 2013-07-23 10:18:05 +0900 | [diff] [blame] | 671 | .set_duplex = sh_eth_set_duplex, |
Simon Horman | 6c4b2f7 | 2017-10-18 09:21:27 +0200 | [diff] [blame] | 672 | .set_rate = sh_eth_set_rate_rcar, |
Simon Horman | e18dbf7 | 2013-07-23 10:18:05 +0900 | [diff] [blame] | 673 | |
Sergei Shtylyov | a3153d8 | 2013-08-18 03:11:28 +0400 | [diff] [blame] | 674 | .register_type = SH_ETH_REG_FAST_RCAR, |
| 675 | |
Sergei Shtylyov | 3e41699 | 2018-03-24 23:08:42 +0300 | [diff] [blame] | 676 | .edtrr_trns = EDTRR_TRNS_ETHER, |
Niklas Söderlund | e410d86d | 2017-01-09 16:34:06 +0100 | [diff] [blame] | 677 | .ecsr_value = ECSR_PSRTO | ECSR_LCHNG | ECSR_ICD | ECSR_MPD, |
| 678 | .ecsipr_value = ECSIPR_PSRTOIP | ECSIPR_LCHNGIP | ECSIPR_ICDIP | |
| 679 | ECSIPR_MPDIP, |
Sergei Shtylyov | 2b2d3eb | 2017-01-29 15:13:48 +0300 | [diff] [blame] | 680 | .eesipr_value = EESIPR_RFCOFIP | EESIPR_ADEIP | EESIPR_ECIIP | |
| 681 | EESIPR_FTCIP | EESIPR_TDEIP | EESIPR_TFUFIP | |
| 682 | EESIPR_FRIP | EESIPR_RDEIP | EESIPR_RFOFIP | |
| 683 | EESIPR_RMAFIP | EESIPR_RRFIP | |
| 684 | EESIPR_RTLFIP | EESIPR_RTSFIP | |
| 685 | EESIPR_PREIP | EESIPR_CERFIP, |
Simon Horman | e18dbf7 | 2013-07-23 10:18:05 +0900 | [diff] [blame] | 686 | |
Sergei Shtylyov | 2716449 | 2018-05-20 00:02:36 +0300 | [diff] [blame] | 687 | .tx_check = EESR_FTC | EESR_CND | EESR_DLC | EESR_CD | EESR_TRO, |
Laurent Pinchart | ba361cb | 2013-07-31 16:42:11 +0900 | [diff] [blame] | 688 | .eesr_err_check = EESR_TWB | EESR_TABT | EESR_RABT | EESR_RFE | |
Sergei Shtylyov | 9b39f05 | 2017-01-04 15:11:21 +0300 | [diff] [blame] | 689 | EESR_RDE | EESR_RFRMER | EESR_TFE | EESR_TDE, |
Nobuhiro Iwamatsu | d407bc0 | 2015-01-07 14:40:15 +0900 | [diff] [blame] | 690 | .fdr_value = 0x00000f0f, |
Simon Horman | e18dbf7 | 2013-07-23 10:18:05 +0900 | [diff] [blame] | 691 | |
Geert Uytterhoeven | 01fbd3f | 2015-01-15 11:52:19 +0100 | [diff] [blame] | 692 | .trscer_err_mask = DESC_I_RINT8, |
| 693 | |
Simon Horman | e18dbf7 | 2013-07-23 10:18:05 +0900 | [diff] [blame] | 694 | .apr = 1, |
| 695 | .mpr = 1, |
| 696 | .tpauser = 1, |
| 697 | .hw_swap = 1, |
Sergei Shtylyov | 6e80e55 | 2018-04-01 00:22:08 +0300 | [diff] [blame] | 698 | .no_xdfar = 1, |
Simon Horman | e18dbf7 | 2013-07-23 10:18:05 +0900 | [diff] [blame] | 699 | .rmiimode = 1, |
Niklas Söderlund | e410d86d | 2017-01-09 16:34:06 +0100 | [diff] [blame] | 700 | .magic = 1, |
Simon Horman | e18dbf7 | 2013-07-23 10:18:05 +0900 | [diff] [blame] | 701 | }; |
Sergei Shtylyov | 3eb9c2a | 2018-05-18 21:32:46 +0300 | [diff] [blame] | 702 | |
| 703 | /* R8A77980 */ |
| 704 | static struct sh_eth_cpu_data r8a77980_data = { |
| 705 | .soft_reset = sh_eth_soft_reset_gether, |
| 706 | |
| 707 | .set_duplex = sh_eth_set_duplex, |
| 708 | .set_rate = sh_eth_set_rate_gether, |
| 709 | |
| 710 | .register_type = SH_ETH_REG_GIGABIT, |
| 711 | |
| 712 | .edtrr_trns = EDTRR_TRNS_GETHER, |
| 713 | .ecsr_value = ECSR_PSRTO | ECSR_LCHNG | ECSR_ICD | ECSR_MPD, |
| 714 | .ecsipr_value = ECSIPR_PSRTOIP | ECSIPR_LCHNGIP | ECSIPR_ICDIP | |
| 715 | ECSIPR_MPDIP, |
| 716 | .eesipr_value = EESIPR_RFCOFIP | EESIPR_ECIIP | |
| 717 | EESIPR_FTCIP | EESIPR_TDEIP | EESIPR_TFUFIP | |
| 718 | EESIPR_FRIP | EESIPR_RDEIP | EESIPR_RFOFIP | |
| 719 | EESIPR_RMAFIP | EESIPR_RRFIP | |
| 720 | EESIPR_RTLFIP | EESIPR_RTSFIP | |
| 721 | EESIPR_PREIP | EESIPR_CERFIP, |
| 722 | |
Sergei Shtylyov | 2716449 | 2018-05-20 00:02:36 +0300 | [diff] [blame] | 723 | .tx_check = EESR_FTC | EESR_CD | EESR_TRO, |
Sergei Shtylyov | 3eb9c2a | 2018-05-18 21:32:46 +0300 | [diff] [blame] | 724 | .eesr_err_check = EESR_TWB1 | EESR_TWB | EESR_TABT | EESR_RABT | |
| 725 | EESR_RFE | EESR_RDE | EESR_RFRMER | |
| 726 | EESR_TFE | EESR_TDE | EESR_ECI, |
| 727 | .fdr_value = 0x0000070f, |
| 728 | |
| 729 | .apr = 1, |
| 730 | .mpr = 1, |
| 731 | .tpauser = 1, |
Sergei Shtylyov | a6318d5 | 2020-02-15 23:13:45 +0300 | [diff] [blame] | 732 | .gecmr = 1, |
Sergei Shtylyov | 3eb9c2a | 2018-05-18 21:32:46 +0300 | [diff] [blame] | 733 | .bculr = 1, |
| 734 | .hw_swap = 1, |
| 735 | .nbst = 1, |
| 736 | .rpadir = 1, |
Sergei Shtylyov | 3eb9c2a | 2018-05-18 21:32:46 +0300 | [diff] [blame] | 737 | .no_trimd = 1, |
| 738 | .no_ade = 1, |
| 739 | .xdfar_rw = 1, |
Sergei Shtylyov | 2c2ab5a | 2019-02-04 21:05:55 +0300 | [diff] [blame] | 740 | .csmr = 1, |
Sergei Shtylyov | 0da843a | 2019-02-04 21:10:32 +0300 | [diff] [blame] | 741 | .rx_csum = 1, |
Sergei Shtylyov | 3eb9c2a | 2018-05-18 21:32:46 +0300 | [diff] [blame] | 742 | .select_mii = 1, |
| 743 | .magic = 1, |
| 744 | .cexcr = 1, |
| 745 | }; |
Chris Brandt | 6e0bb04 | 2018-08-27 12:42:02 -0500 | [diff] [blame] | 746 | |
| 747 | /* R7S9210 */ |
| 748 | static struct sh_eth_cpu_data r7s9210_data = { |
| 749 | .soft_reset = sh_eth_soft_reset, |
| 750 | |
| 751 | .set_duplex = sh_eth_set_duplex, |
| 752 | .set_rate = sh_eth_set_rate_rcar, |
| 753 | |
| 754 | .register_type = SH_ETH_REG_FAST_SH4, |
| 755 | |
| 756 | .edtrr_trns = EDTRR_TRNS_ETHER, |
| 757 | .ecsr_value = ECSR_ICD, |
| 758 | .ecsipr_value = ECSIPR_ICDIP, |
| 759 | .eesipr_value = EESIPR_TWBIP | EESIPR_TABTIP | EESIPR_RABTIP | |
| 760 | EESIPR_RFCOFIP | EESIPR_ECIIP | EESIPR_FTCIP | |
| 761 | EESIPR_TDEIP | EESIPR_TFUFIP | EESIPR_FRIP | |
| 762 | EESIPR_RDEIP | EESIPR_RFOFIP | EESIPR_CNDIP | |
| 763 | EESIPR_DLCIP | EESIPR_CDIP | EESIPR_TROIP | |
| 764 | EESIPR_RMAFIP | EESIPR_RRFIP | EESIPR_RTLFIP | |
| 765 | EESIPR_RTSFIP | EESIPR_PREIP | EESIPR_CERFIP, |
| 766 | |
| 767 | .tx_check = EESR_FTC | EESR_CND | EESR_DLC | EESR_CD | EESR_TRO, |
| 768 | .eesr_err_check = EESR_TWB | EESR_TABT | EESR_RABT | EESR_RFE | |
| 769 | EESR_RDE | EESR_RFRMER | EESR_TFE | EESR_TDE, |
| 770 | |
| 771 | .fdr_value = 0x0000070f, |
| 772 | |
| 773 | .apr = 1, |
| 774 | .mpr = 1, |
| 775 | .tpauser = 1, |
| 776 | .hw_swap = 1, |
| 777 | .rpadir = 1, |
| 778 | .no_ade = 1, |
| 779 | .xdfar_rw = 1, |
| 780 | }; |
Geert Uytterhoeven | c74a224 | 2015-11-24 15:40:58 +0100 | [diff] [blame] | 781 | #endif /* CONFIG_OF */ |
Simon Horman | e18dbf7 | 2013-07-23 10:18:05 +0900 | [diff] [blame] | 782 | |
Sergei Shtylyov | 9c3beaa | 2013-06-07 14:03:37 +0000 | [diff] [blame] | 783 | static void sh_eth_set_rate_sh7724(struct net_device *ndev) |
Sergei Shtylyov | a3f109b | 2013-03-28 11:51:31 +0000 | [diff] [blame] | 784 | { |
| 785 | struct sh_eth_private *mdp = netdev_priv(ndev); |
| 786 | |
| 787 | switch (mdp->speed) { |
| 788 | case 10: /* 10BASE */ |
Sergei Shtylyov | b2b14d2 | 2016-02-10 01:38:28 +0300 | [diff] [blame] | 789 | sh_eth_modify(ndev, ECMR, ECMR_RTM, 0); |
Sergei Shtylyov | a3f109b | 2013-03-28 11:51:31 +0000 | [diff] [blame] | 790 | break; |
| 791 | case 100:/* 100BASE */ |
Sergei Shtylyov | b2b14d2 | 2016-02-10 01:38:28 +0300 | [diff] [blame] | 792 | sh_eth_modify(ndev, ECMR, ECMR_RTM, ECMR_RTM); |
Yoshihiro Shimoda | 65ac885 | 2009-05-24 23:54:30 +0000 | [diff] [blame] | 793 | break; |
Yoshihiro Shimoda | 65ac885 | 2009-05-24 23:54:30 +0000 | [diff] [blame] | 794 | } |
| 795 | } |
| 796 | |
| 797 | /* SH7724 */ |
Sergei Shtylyov | 9c3beaa | 2013-06-07 14:03:37 +0000 | [diff] [blame] | 798 | static struct sh_eth_cpu_data sh7724_data = { |
Sergei Shtylyov | 4ceedeb | 2018-03-24 23:07:41 +0300 | [diff] [blame] | 799 | .soft_reset = sh_eth_soft_reset, |
| 800 | |
Yoshihiro Shimoda | 65ac885 | 2009-05-24 23:54:30 +0000 | [diff] [blame] | 801 | .set_duplex = sh_eth_set_duplex, |
Sergei Shtylyov | 9c3beaa | 2013-06-07 14:03:37 +0000 | [diff] [blame] | 802 | .set_rate = sh_eth_set_rate_sh7724, |
Yoshihiro Shimoda | 65ac885 | 2009-05-24 23:54:30 +0000 | [diff] [blame] | 803 | |
Sergei Shtylyov | a3153d8 | 2013-08-18 03:11:28 +0400 | [diff] [blame] | 804 | .register_type = SH_ETH_REG_FAST_SH4, |
| 805 | |
Sergei Shtylyov | 3e41699 | 2018-03-24 23:08:42 +0300 | [diff] [blame] | 806 | .edtrr_trns = EDTRR_TRNS_ETHER, |
Yoshihiro Shimoda | 65ac885 | 2009-05-24 23:54:30 +0000 | [diff] [blame] | 807 | .ecsr_value = ECSR_PSRTO | ECSR_LCHNG | ECSR_ICD, |
| 808 | .ecsipr_value = ECSIPR_PSRTOIP | ECSIPR_LCHNGIP | ECSIPR_ICDIP, |
Sergei Shtylyov | 2b2d3eb | 2017-01-29 15:13:48 +0300 | [diff] [blame] | 809 | .eesipr_value = EESIPR_RFCOFIP | EESIPR_ADEIP | EESIPR_ECIIP | |
| 810 | EESIPR_FTCIP | EESIPR_TDEIP | EESIPR_TFUFIP | |
| 811 | EESIPR_FRIP | EESIPR_RDEIP | EESIPR_RFOFIP | |
| 812 | EESIPR_RMAFIP | EESIPR_RRFIP | |
| 813 | EESIPR_RTLFIP | EESIPR_RTSFIP | |
| 814 | EESIPR_PREIP | EESIPR_CERFIP, |
Yoshihiro Shimoda | 65ac885 | 2009-05-24 23:54:30 +0000 | [diff] [blame] | 815 | |
Sergei Shtylyov | 2716449 | 2018-05-20 00:02:36 +0300 | [diff] [blame] | 816 | .tx_check = EESR_FTC | EESR_CND | EESR_DLC | EESR_CD | EESR_TRO, |
Sergei Shtylyov | ca8c358 | 2013-06-21 01:12:21 +0400 | [diff] [blame] | 817 | .eesr_err_check = EESR_TWB | EESR_TABT | EESR_RABT | EESR_RFE | |
Sergei Shtylyov | 9b39f05 | 2017-01-04 15:11:21 +0300 | [diff] [blame] | 818 | EESR_RDE | EESR_RFRMER | EESR_TFE | EESR_TDE, |
Yoshihiro Shimoda | 65ac885 | 2009-05-24 23:54:30 +0000 | [diff] [blame] | 819 | |
| 820 | .apr = 1, |
| 821 | .mpr = 1, |
| 822 | .tpauser = 1, |
| 823 | .hw_swap = 1, |
Magnus Damm | 503914c | 2009-12-15 21:16:55 -0800 | [diff] [blame] | 824 | .rpadir = 1, |
Yoshihiro Shimoda | 65ac885 | 2009-05-24 23:54:30 +0000 | [diff] [blame] | 825 | }; |
Nobuhiro Iwamatsu | 5cee1d3 | 2012-06-25 17:35:12 +0000 | [diff] [blame] | 826 | |
Sergei Shtylyov | 24549e2 | 2013-06-07 13:59:21 +0000 | [diff] [blame] | 827 | static void sh_eth_set_rate_sh7757(struct net_device *ndev) |
Yoshihiro Shimoda | f29a3d0 | 2010-07-05 18:32:50 +0000 | [diff] [blame] | 828 | { |
| 829 | struct sh_eth_private *mdp = netdev_priv(ndev); |
Yoshihiro Shimoda | f29a3d0 | 2010-07-05 18:32:50 +0000 | [diff] [blame] | 830 | |
| 831 | switch (mdp->speed) { |
| 832 | case 10: /* 10BASE */ |
Yoshihiro Shimoda | 4a55530 | 2011-03-07 21:59:26 +0000 | [diff] [blame] | 833 | sh_eth_write(ndev, 0, RTRATE); |
Yoshihiro Shimoda | f29a3d0 | 2010-07-05 18:32:50 +0000 | [diff] [blame] | 834 | break; |
| 835 | case 100:/* 100BASE */ |
Yoshihiro Shimoda | 4a55530 | 2011-03-07 21:59:26 +0000 | [diff] [blame] | 836 | sh_eth_write(ndev, 1, RTRATE); |
Yoshihiro Shimoda | f29a3d0 | 2010-07-05 18:32:50 +0000 | [diff] [blame] | 837 | break; |
Yoshihiro Shimoda | f29a3d0 | 2010-07-05 18:32:50 +0000 | [diff] [blame] | 838 | } |
| 839 | } |
| 840 | |
| 841 | /* SH7757 */ |
Sergei Shtylyov | 24549e2 | 2013-06-07 13:59:21 +0000 | [diff] [blame] | 842 | static struct sh_eth_cpu_data sh7757_data = { |
Sergei Shtylyov | 4ceedeb | 2018-03-24 23:07:41 +0300 | [diff] [blame] | 843 | .soft_reset = sh_eth_soft_reset, |
| 844 | |
Sergei Shtylyov | 24549e2 | 2013-06-07 13:59:21 +0000 | [diff] [blame] | 845 | .set_duplex = sh_eth_set_duplex, |
| 846 | .set_rate = sh_eth_set_rate_sh7757, |
Yoshihiro Shimoda | f29a3d0 | 2010-07-05 18:32:50 +0000 | [diff] [blame] | 847 | |
Sergei Shtylyov | a3153d8 | 2013-08-18 03:11:28 +0400 | [diff] [blame] | 848 | .register_type = SH_ETH_REG_FAST_SH4, |
| 849 | |
Sergei Shtylyov | 3e41699 | 2018-03-24 23:08:42 +0300 | [diff] [blame] | 850 | .edtrr_trns = EDTRR_TRNS_ETHER, |
Sergei Shtylyov | 2b2d3eb | 2017-01-29 15:13:48 +0300 | [diff] [blame] | 851 | .eesipr_value = EESIPR_RFCOFIP | EESIPR_ECIIP | |
| 852 | EESIPR_FTCIP | EESIPR_TDEIP | EESIPR_TFUFIP | |
| 853 | EESIPR_FRIP | EESIPR_RDEIP | EESIPR_RFOFIP | |
| 854 | 0x0000f000 | EESIPR_CNDIP | EESIPR_DLCIP | |
| 855 | EESIPR_CDIP | EESIPR_TROIP | EESIPR_RMAFIP | |
| 856 | EESIPR_CEEFIP | EESIPR_CELFIP | |
| 857 | EESIPR_RRFIP | EESIPR_RTLFIP | EESIPR_RTSFIP | |
| 858 | EESIPR_PREIP | EESIPR_CERFIP, |
Yoshihiro Shimoda | f29a3d0 | 2010-07-05 18:32:50 +0000 | [diff] [blame] | 859 | |
Sergei Shtylyov | 2716449 | 2018-05-20 00:02:36 +0300 | [diff] [blame] | 860 | .tx_check = EESR_FTC | EESR_CND | EESR_DLC | EESR_CD | EESR_TRO, |
Sergei Shtylyov | ca8c358 | 2013-06-21 01:12:21 +0400 | [diff] [blame] | 861 | .eesr_err_check = EESR_TWB | EESR_TABT | EESR_RABT | EESR_RFE | |
Sergei Shtylyov | 9b39f05 | 2017-01-04 15:11:21 +0300 | [diff] [blame] | 862 | EESR_RDE | EESR_RFRMER | EESR_TFE | EESR_TDE, |
Yoshihiro Shimoda | f29a3d0 | 2010-07-05 18:32:50 +0000 | [diff] [blame] | 863 | |
Nobuhiro Iwamatsu | 5b3dfd1 | 2013-06-06 09:49:30 +0000 | [diff] [blame] | 864 | .irq_flags = IRQF_SHARED, |
Yoshihiro Shimoda | f29a3d0 | 2010-07-05 18:32:50 +0000 | [diff] [blame] | 865 | .apr = 1, |
| 866 | .mpr = 1, |
| 867 | .tpauser = 1, |
| 868 | .hw_swap = 1, |
| 869 | .no_ade = 1, |
Yoshihiro Shimoda | 2e98e79 | 2011-07-05 20:33:57 +0000 | [diff] [blame] | 870 | .rpadir = 1, |
Ben Hutchings | 6b4b4fe | 2015-02-26 20:34:35 +0000 | [diff] [blame] | 871 | .rtrate = 1, |
Sergei Shtylyov | a94cf2a | 2018-02-24 22:41:45 +0300 | [diff] [blame] | 872 | .dual_port = 1, |
Yoshihiro Shimoda | f29a3d0 | 2010-07-05 18:32:50 +0000 | [diff] [blame] | 873 | }; |
Yoshihiro Shimoda | 65ac885 | 2009-05-24 23:54:30 +0000 | [diff] [blame] | 874 | |
David S. Miller | e403d29 | 2013-06-07 23:40:41 -0700 | [diff] [blame] | 875 | #define SH_GIGA_ETH_BASE 0xfee00000UL |
Yoshihiro Shimoda | 8fcd496 | 2011-03-07 21:59:49 +0000 | [diff] [blame] | 876 | #define GIGA_MALR(port) (SH_GIGA_ETH_BASE + 0x800 * (port) + 0x05c8) |
| 877 | #define GIGA_MAHR(port) (SH_GIGA_ETH_BASE + 0x800 * (port) + 0x05c0) |
| 878 | static void sh_eth_chip_reset_giga(struct net_device *ndev) |
| 879 | { |
Geert Uytterhoeven | 0799c2d | 2015-01-15 11:54:28 +0100 | [diff] [blame] | 880 | u32 mahr[2], malr[2]; |
Sergei Shtylyov | 7927092 | 2016-05-08 00:08:05 +0300 | [diff] [blame] | 881 | int i; |
Yoshihiro Shimoda | 8fcd496 | 2011-03-07 21:59:49 +0000 | [diff] [blame] | 882 | |
| 883 | /* save MAHR and MALR */ |
| 884 | for (i = 0; i < 2; i++) { |
Yoshihiro Shimoda | ae70644 | 2011-09-27 21:48:58 +0000 | [diff] [blame] | 885 | malr[i] = ioread32((void *)GIGA_MALR(i)); |
| 886 | mahr[i] = ioread32((void *)GIGA_MAHR(i)); |
Yoshihiro Shimoda | 8fcd496 | 2011-03-07 21:59:49 +0000 | [diff] [blame] | 887 | } |
| 888 | |
Sergei Shtylyov | c66b258 | 2016-05-07 14:09:01 -0700 | [diff] [blame] | 889 | sh_eth_chip_reset(ndev); |
Yoshihiro Shimoda | 8fcd496 | 2011-03-07 21:59:49 +0000 | [diff] [blame] | 890 | |
| 891 | /* restore MAHR and MALR */ |
| 892 | for (i = 0; i < 2; i++) { |
Yoshihiro Shimoda | ae70644 | 2011-09-27 21:48:58 +0000 | [diff] [blame] | 893 | iowrite32(malr[i], (void *)GIGA_MALR(i)); |
| 894 | iowrite32(mahr[i], (void *)GIGA_MAHR(i)); |
Yoshihiro Shimoda | 8fcd496 | 2011-03-07 21:59:49 +0000 | [diff] [blame] | 895 | } |
| 896 | } |
| 897 | |
Yoshihiro Shimoda | 8fcd496 | 2011-03-07 21:59:49 +0000 | [diff] [blame] | 898 | static void sh_eth_set_rate_giga(struct net_device *ndev) |
| 899 | { |
| 900 | struct sh_eth_private *mdp = netdev_priv(ndev); |
| 901 | |
Sergei Shtylyov | a6318d5 | 2020-02-15 23:13:45 +0300 | [diff] [blame] | 902 | if (WARN_ON(!mdp->cd->gecmr)) |
| 903 | return; |
| 904 | |
Yoshihiro Shimoda | 8fcd496 | 2011-03-07 21:59:49 +0000 | [diff] [blame] | 905 | switch (mdp->speed) { |
| 906 | case 10: /* 10BASE */ |
| 907 | sh_eth_write(ndev, 0x00000000, GECMR); |
| 908 | break; |
| 909 | case 100:/* 100BASE */ |
| 910 | sh_eth_write(ndev, 0x00000010, GECMR); |
| 911 | break; |
| 912 | case 1000: /* 1000BASE */ |
| 913 | sh_eth_write(ndev, 0x00000020, GECMR); |
| 914 | break; |
Yoshihiro Shimoda | 8fcd496 | 2011-03-07 21:59:49 +0000 | [diff] [blame] | 915 | } |
| 916 | } |
| 917 | |
| 918 | /* SH7757(GETHERC) */ |
Sergei Shtylyov | 24549e2 | 2013-06-07 13:59:21 +0000 | [diff] [blame] | 919 | static struct sh_eth_cpu_data sh7757_data_giga = { |
Sergei Shtylyov | 4ceedeb | 2018-03-24 23:07:41 +0300 | [diff] [blame] | 920 | .soft_reset = sh_eth_soft_reset_gether, |
| 921 | |
Yoshihiro Shimoda | 8fcd496 | 2011-03-07 21:59:49 +0000 | [diff] [blame] | 922 | .chip_reset = sh_eth_chip_reset_giga, |
Nobuhiro Iwamatsu | 04b0ed2 | 2013-06-06 09:45:25 +0000 | [diff] [blame] | 923 | .set_duplex = sh_eth_set_duplex, |
Yoshihiro Shimoda | 8fcd496 | 2011-03-07 21:59:49 +0000 | [diff] [blame] | 924 | .set_rate = sh_eth_set_rate_giga, |
| 925 | |
Sergei Shtylyov | a3153d8 | 2013-08-18 03:11:28 +0400 | [diff] [blame] | 926 | .register_type = SH_ETH_REG_GIGABIT, |
| 927 | |
Sergei Shtylyov | 3e41699 | 2018-03-24 23:08:42 +0300 | [diff] [blame] | 928 | .edtrr_trns = EDTRR_TRNS_GETHER, |
Yoshihiro Shimoda | 8fcd496 | 2011-03-07 21:59:49 +0000 | [diff] [blame] | 929 | .ecsr_value = ECSR_ICD | ECSR_MPD, |
| 930 | .ecsipr_value = ECSIPR_LCHNGIP | ECSIPR_ICDIP | ECSIPR_MPDIP, |
Sergei Shtylyov | 2b2d3eb | 2017-01-29 15:13:48 +0300 | [diff] [blame] | 931 | .eesipr_value = EESIPR_RFCOFIP | EESIPR_ECIIP | |
| 932 | EESIPR_FTCIP | EESIPR_TDEIP | EESIPR_TFUFIP | |
| 933 | EESIPR_FRIP | EESIPR_RDEIP | EESIPR_RFOFIP | |
| 934 | 0x0000f000 | EESIPR_CNDIP | EESIPR_DLCIP | |
| 935 | EESIPR_CDIP | EESIPR_TROIP | EESIPR_RMAFIP | |
| 936 | EESIPR_CEEFIP | EESIPR_CELFIP | |
| 937 | EESIPR_RRFIP | EESIPR_RTLFIP | EESIPR_RTSFIP | |
| 938 | EESIPR_PREIP | EESIPR_CERFIP, |
Yoshihiro Shimoda | 8fcd496 | 2011-03-07 21:59:49 +0000 | [diff] [blame] | 939 | |
| 940 | .tx_check = EESR_TC1 | EESR_FTC, |
Sergei Shtylyov | ca8c358 | 2013-06-21 01:12:21 +0400 | [diff] [blame] | 941 | .eesr_err_check = EESR_TWB1 | EESR_TWB | EESR_TABT | EESR_RABT | |
| 942 | EESR_RFE | EESR_RDE | EESR_RFRMER | EESR_TFE | |
Sergei Shtylyov | 9b39f05 | 2017-01-04 15:11:21 +0300 | [diff] [blame] | 943 | EESR_TDE, |
Yoshihiro Shimoda | 8fcd496 | 2011-03-07 21:59:49 +0000 | [diff] [blame] | 944 | .fdr_value = 0x0000072f, |
Yoshihiro Shimoda | 8fcd496 | 2011-03-07 21:59:49 +0000 | [diff] [blame] | 945 | |
Nobuhiro Iwamatsu | 5b3dfd1 | 2013-06-06 09:49:30 +0000 | [diff] [blame] | 946 | .irq_flags = IRQF_SHARED, |
Yoshihiro Shimoda | 8fcd496 | 2011-03-07 21:59:49 +0000 | [diff] [blame] | 947 | .apr = 1, |
| 948 | .mpr = 1, |
| 949 | .tpauser = 1, |
Sergei Shtylyov | a6318d5 | 2020-02-15 23:13:45 +0300 | [diff] [blame] | 950 | .gecmr = 1, |
Yoshihiro Shimoda | 8fcd496 | 2011-03-07 21:59:49 +0000 | [diff] [blame] | 951 | .bculr = 1, |
| 952 | .hw_swap = 1, |
| 953 | .rpadir = 1, |
Yoshihiro Shimoda | 8fcd496 | 2011-03-07 21:59:49 +0000 | [diff] [blame] | 954 | .no_trimd = 1, |
| 955 | .no_ade = 1, |
Sergei Shtylyov | 246e30c | 2018-03-24 23:09:55 +0300 | [diff] [blame] | 956 | .xdfar_rw = 1, |
Yoshihiro Shimoda | 3acbc97 | 2012-02-15 17:54:51 +0000 | [diff] [blame] | 957 | .tsu = 1, |
Sergei Shtylyov | 4c1d458 | 2018-03-24 23:12:54 +0300 | [diff] [blame] | 958 | .cexcr = 1, |
Sergei Shtylyov | a94cf2a | 2018-02-24 22:41:45 +0300 | [diff] [blame] | 959 | .dual_port = 1, |
Yoshihiro Shimoda | 8fcd496 | 2011-03-07 21:59:49 +0000 | [diff] [blame] | 960 | }; |
| 961 | |
Sergei Shtylyov | f5d1276 | 2013-06-07 13:58:18 +0000 | [diff] [blame] | 962 | /* SH7734 */ |
| 963 | static struct sh_eth_cpu_data sh7734_data = { |
Sergei Shtylyov | 4ceedeb | 2018-03-24 23:07:41 +0300 | [diff] [blame] | 964 | .soft_reset = sh_eth_soft_reset_gether, |
| 965 | |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 966 | .chip_reset = sh_eth_chip_reset, |
| 967 | .set_duplex = sh_eth_set_duplex, |
Sergei Shtylyov | f5d1276 | 2013-06-07 13:58:18 +0000 | [diff] [blame] | 968 | .set_rate = sh_eth_set_rate_gether, |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 969 | |
Sergei Shtylyov | a3153d8 | 2013-08-18 03:11:28 +0400 | [diff] [blame] | 970 | .register_type = SH_ETH_REG_GIGABIT, |
| 971 | |
Sergei Shtylyov | 3e41699 | 2018-03-24 23:08:42 +0300 | [diff] [blame] | 972 | .edtrr_trns = EDTRR_TRNS_GETHER, |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 973 | .ecsr_value = ECSR_ICD | ECSR_MPD, |
| 974 | .ecsipr_value = ECSIPR_LCHNGIP | ECSIPR_ICDIP | ECSIPR_MPDIP, |
Sergei Shtylyov | 2b2d3eb | 2017-01-29 15:13:48 +0300 | [diff] [blame] | 975 | .eesipr_value = EESIPR_RFCOFIP | EESIPR_ECIIP | |
| 976 | EESIPR_FTCIP | EESIPR_TDEIP | EESIPR_TFUFIP | |
| 977 | EESIPR_FRIP | EESIPR_RDEIP | EESIPR_RFOFIP | |
| 978 | EESIPR_DLCIP | EESIPR_CDIP | EESIPR_TROIP | |
| 979 | EESIPR_RMAFIP | EESIPR_CEEFIP | EESIPR_CELFIP | |
| 980 | EESIPR_RRFIP | EESIPR_RTLFIP | EESIPR_RTSFIP | |
| 981 | EESIPR_PREIP | EESIPR_CERFIP, |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 982 | |
| 983 | .tx_check = EESR_TC1 | EESR_FTC, |
Sergei Shtylyov | ca8c358 | 2013-06-21 01:12:21 +0400 | [diff] [blame] | 984 | .eesr_err_check = EESR_TWB1 | EESR_TWB | EESR_TABT | EESR_RABT | |
| 985 | EESR_RFE | EESR_RDE | EESR_RFRMER | EESR_TFE | |
Sergei Shtylyov | 9b39f05 | 2017-01-04 15:11:21 +0300 | [diff] [blame] | 986 | EESR_TDE, |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 987 | |
| 988 | .apr = 1, |
| 989 | .mpr = 1, |
| 990 | .tpauser = 1, |
Sergei Shtylyov | a6318d5 | 2020-02-15 23:13:45 +0300 | [diff] [blame] | 991 | .gecmr = 1, |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 992 | .bculr = 1, |
| 993 | .hw_swap = 1, |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 994 | .no_trimd = 1, |
| 995 | .no_ade = 1, |
Sergei Shtylyov | 246e30c | 2018-03-24 23:09:55 +0300 | [diff] [blame] | 996 | .xdfar_rw = 1, |
Yoshihiro Shimoda | 4986b99 | 2011-03-07 21:59:34 +0000 | [diff] [blame] | 997 | .tsu = 1, |
Sergei Shtylyov | 2c2ab5a | 2019-02-04 21:05:55 +0300 | [diff] [blame] | 998 | .csmr = 1, |
Sergei Shtylyov | 06240e1 | 2019-02-04 21:11:32 +0300 | [diff] [blame] | 999 | .rx_csum = 1, |
Sergei Shtylyov | f5d1276 | 2013-06-07 13:58:18 +0000 | [diff] [blame] | 1000 | .select_mii = 1, |
Niklas Söderlund | 159c2a9 | 2017-01-09 16:34:08 +0100 | [diff] [blame] | 1001 | .magic = 1, |
Sergei Shtylyov | 4c1d458 | 2018-03-24 23:12:54 +0300 | [diff] [blame] | 1002 | .cexcr = 1, |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 1003 | }; |
Sergei Shtylyov | f5d1276 | 2013-06-07 13:58:18 +0000 | [diff] [blame] | 1004 | |
| 1005 | /* SH7763 */ |
| 1006 | static struct sh_eth_cpu_data sh7763_data = { |
Sergei Shtylyov | 4ceedeb | 2018-03-24 23:07:41 +0300 | [diff] [blame] | 1007 | .soft_reset = sh_eth_soft_reset_gether, |
| 1008 | |
Sergei Shtylyov | f5d1276 | 2013-06-07 13:58:18 +0000 | [diff] [blame] | 1009 | .chip_reset = sh_eth_chip_reset, |
| 1010 | .set_duplex = sh_eth_set_duplex, |
| 1011 | .set_rate = sh_eth_set_rate_gether, |
| 1012 | |
Sergei Shtylyov | a3153d8 | 2013-08-18 03:11:28 +0400 | [diff] [blame] | 1013 | .register_type = SH_ETH_REG_GIGABIT, |
| 1014 | |
Sergei Shtylyov | 3e41699 | 2018-03-24 23:08:42 +0300 | [diff] [blame] | 1015 | .edtrr_trns = EDTRR_TRNS_GETHER, |
Sergei Shtylyov | f5d1276 | 2013-06-07 13:58:18 +0000 | [diff] [blame] | 1016 | .ecsr_value = ECSR_ICD | ECSR_MPD, |
| 1017 | .ecsipr_value = ECSIPR_LCHNGIP | ECSIPR_ICDIP | ECSIPR_MPDIP, |
Sergei Shtylyov | 2b2d3eb | 2017-01-29 15:13:48 +0300 | [diff] [blame] | 1018 | .eesipr_value = EESIPR_RFCOFIP | EESIPR_ECIIP | |
| 1019 | EESIPR_FTCIP | EESIPR_TDEIP | EESIPR_TFUFIP | |
| 1020 | EESIPR_FRIP | EESIPR_RDEIP | EESIPR_RFOFIP | |
| 1021 | EESIPR_DLCIP | EESIPR_CDIP | EESIPR_TROIP | |
| 1022 | EESIPR_RMAFIP | EESIPR_CEEFIP | EESIPR_CELFIP | |
| 1023 | EESIPR_RRFIP | EESIPR_RTLFIP | EESIPR_RTSFIP | |
| 1024 | EESIPR_PREIP | EESIPR_CERFIP, |
Sergei Shtylyov | f5d1276 | 2013-06-07 13:58:18 +0000 | [diff] [blame] | 1025 | |
| 1026 | .tx_check = EESR_TC1 | EESR_FTC, |
Sergei Shtylyov | 128296f | 2014-01-03 15:52:22 +0300 | [diff] [blame] | 1027 | .eesr_err_check = EESR_TWB1 | EESR_TWB | EESR_TABT | EESR_RABT | |
Sergei Shtylyov | 9b39f05 | 2017-01-04 15:11:21 +0300 | [diff] [blame] | 1028 | EESR_RDE | EESR_RFRMER | EESR_TFE | EESR_TDE, |
Sergei Shtylyov | f5d1276 | 2013-06-07 13:58:18 +0000 | [diff] [blame] | 1029 | |
| 1030 | .apr = 1, |
| 1031 | .mpr = 1, |
| 1032 | .tpauser = 1, |
Sergei Shtylyov | a6318d5 | 2020-02-15 23:13:45 +0300 | [diff] [blame] | 1033 | .gecmr = 1, |
Sergei Shtylyov | f5d1276 | 2013-06-07 13:58:18 +0000 | [diff] [blame] | 1034 | .bculr = 1, |
| 1035 | .hw_swap = 1, |
| 1036 | .no_trimd = 1, |
| 1037 | .no_ade = 1, |
Sergei Shtylyov | 246e30c | 2018-03-24 23:09:55 +0300 | [diff] [blame] | 1038 | .xdfar_rw = 1, |
Sergei Shtylyov | f5d1276 | 2013-06-07 13:58:18 +0000 | [diff] [blame] | 1039 | .tsu = 1, |
| 1040 | .irq_flags = IRQF_SHARED, |
Niklas Söderlund | 267e1d5 | 2017-01-09 16:34:09 +0100 | [diff] [blame] | 1041 | .magic = 1, |
Sergei Shtylyov | 4c1d458 | 2018-03-24 23:12:54 +0300 | [diff] [blame] | 1042 | .cexcr = 1, |
Sergei Shtylyov | 997feb1 | 2019-02-04 21:12:39 +0300 | [diff] [blame] | 1043 | .rx_csum = 1, |
Sergei Shtylyov | a94cf2a | 2018-02-24 22:41:45 +0300 | [diff] [blame] | 1044 | .dual_port = 1, |
Sergei Shtylyov | f5d1276 | 2013-06-07 13:58:18 +0000 | [diff] [blame] | 1045 | }; |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 1046 | |
Sergei Shtylyov | c18a79a | 2013-06-07 13:56:05 +0000 | [diff] [blame] | 1047 | static struct sh_eth_cpu_data sh7619_data = { |
Sergei Shtylyov | 4ceedeb | 2018-03-24 23:07:41 +0300 | [diff] [blame] | 1048 | .soft_reset = sh_eth_soft_reset, |
| 1049 | |
Sergei Shtylyov | a3153d8 | 2013-08-18 03:11:28 +0400 | [diff] [blame] | 1050 | .register_type = SH_ETH_REG_FAST_SH3_SH2, |
| 1051 | |
Sergei Shtylyov | 3e41699 | 2018-03-24 23:08:42 +0300 | [diff] [blame] | 1052 | .edtrr_trns = EDTRR_TRNS_ETHER, |
Sergei Shtylyov | 2b2d3eb | 2017-01-29 15:13:48 +0300 | [diff] [blame] | 1053 | .eesipr_value = EESIPR_RFCOFIP | EESIPR_ECIIP | |
| 1054 | EESIPR_FTCIP | EESIPR_TDEIP | EESIPR_TFUFIP | |
| 1055 | EESIPR_FRIP | EESIPR_RDEIP | EESIPR_RFOFIP | |
| 1056 | 0x0000f000 | EESIPR_CNDIP | EESIPR_DLCIP | |
| 1057 | EESIPR_CDIP | EESIPR_TROIP | EESIPR_RMAFIP | |
| 1058 | EESIPR_CEEFIP | EESIPR_CELFIP | |
| 1059 | EESIPR_RRFIP | EESIPR_RTLFIP | EESIPR_RTSFIP | |
| 1060 | EESIPR_PREIP | EESIPR_CERFIP, |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 1061 | |
| 1062 | .apr = 1, |
| 1063 | .mpr = 1, |
| 1064 | .tpauser = 1, |
| 1065 | .hw_swap = 1, |
| 1066 | }; |
Sergei Shtylyov | 7bbe150 | 2013-06-07 13:55:08 +0000 | [diff] [blame] | 1067 | |
| 1068 | static struct sh_eth_cpu_data sh771x_data = { |
Sergei Shtylyov | 4ceedeb | 2018-03-24 23:07:41 +0300 | [diff] [blame] | 1069 | .soft_reset = sh_eth_soft_reset, |
| 1070 | |
Sergei Shtylyov | a3153d8 | 2013-08-18 03:11:28 +0400 | [diff] [blame] | 1071 | .register_type = SH_ETH_REG_FAST_SH3_SH2, |
| 1072 | |
Sergei Shtylyov | 3e41699 | 2018-03-24 23:08:42 +0300 | [diff] [blame] | 1073 | .edtrr_trns = EDTRR_TRNS_ETHER, |
Sergei Shtylyov | 2b2d3eb | 2017-01-29 15:13:48 +0300 | [diff] [blame] | 1074 | .eesipr_value = EESIPR_RFCOFIP | EESIPR_ECIIP | |
| 1075 | EESIPR_FTCIP | EESIPR_TDEIP | EESIPR_TFUFIP | |
| 1076 | EESIPR_FRIP | EESIPR_RDEIP | EESIPR_RFOFIP | |
| 1077 | 0x0000f000 | EESIPR_CNDIP | EESIPR_DLCIP | |
| 1078 | EESIPR_CDIP | EESIPR_TROIP | EESIPR_RMAFIP | |
| 1079 | EESIPR_CEEFIP | EESIPR_CELFIP | |
| 1080 | EESIPR_RRFIP | EESIPR_RTLFIP | EESIPR_RTSFIP | |
| 1081 | EESIPR_PREIP | EESIPR_CERFIP, |
Yoshihiro Shimoda | 4986b99 | 2011-03-07 21:59:34 +0000 | [diff] [blame] | 1082 | .tsu = 1, |
Sergei Shtylyov | a94cf2a | 2018-02-24 22:41:45 +0300 | [diff] [blame] | 1083 | .dual_port = 1, |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 1084 | }; |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 1085 | |
| 1086 | static void sh_eth_set_default_cpu_data(struct sh_eth_cpu_data *cd) |
| 1087 | { |
| 1088 | if (!cd->ecsr_value) |
| 1089 | cd->ecsr_value = DEFAULT_ECSR_INIT; |
| 1090 | |
| 1091 | if (!cd->ecsipr_value) |
| 1092 | cd->ecsipr_value = DEFAULT_ECSIPR_INIT; |
| 1093 | |
| 1094 | if (!cd->fcftr_value) |
Sergei Shtylyov | 128296f | 2014-01-03 15:52:22 +0300 | [diff] [blame] | 1095 | cd->fcftr_value = DEFAULT_FIFO_F_D_RFF | |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 1096 | DEFAULT_FIFO_F_D_RFD; |
| 1097 | |
| 1098 | if (!cd->fdr_value) |
| 1099 | cd->fdr_value = DEFAULT_FDR_INIT; |
| 1100 | |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 1101 | if (!cd->tx_check) |
| 1102 | cd->tx_check = DEFAULT_TX_CHECK; |
| 1103 | |
| 1104 | if (!cd->eesr_err_check) |
| 1105 | cd->eesr_err_check = DEFAULT_EESR_ERR_CHECK; |
Nobuhiro Iwamatsu | b284fbe | 2015-01-08 15:25:07 +0900 | [diff] [blame] | 1106 | |
| 1107 | if (!cd->trscer_err_mask) |
| 1108 | cd->trscer_err_mask = DEFAULT_TRSCER_ERR_MASK; |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 1109 | } |
| 1110 | |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 1111 | static void sh_eth_set_receive_align(struct sk_buff *skb) |
| 1112 | { |
Mitsuhiro Kimura | 4d6a949 | 2014-11-27 20:34:00 +0900 | [diff] [blame] | 1113 | uintptr_t reserve = (uintptr_t)skb->data & (SH_ETH_RX_ALIGN - 1); |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 1114 | |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 1115 | if (reserve) |
Mitsuhiro Kimura | 4d6a949 | 2014-11-27 20:34:00 +0900 | [diff] [blame] | 1116 | skb_reserve(skb, SH_ETH_RX_ALIGN - reserve); |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 1117 | } |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 1118 | |
Sergei Shtylyov | 128296f | 2014-01-03 15:52:22 +0300 | [diff] [blame] | 1119 | /* Program the hardware MAC address from dev->dev_addr. */ |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1120 | static void update_mac_address(struct net_device *ndev) |
| 1121 | { |
Yoshihiro Shimoda | 4a55530 | 2011-03-07 21:59:26 +0000 | [diff] [blame] | 1122 | sh_eth_write(ndev, |
Sergei Shtylyov | 128296f | 2014-01-03 15:52:22 +0300 | [diff] [blame] | 1123 | (ndev->dev_addr[0] << 24) | (ndev->dev_addr[1] << 16) | |
| 1124 | (ndev->dev_addr[2] << 8) | (ndev->dev_addr[3]), MAHR); |
Yoshihiro Shimoda | 4a55530 | 2011-03-07 21:59:26 +0000 | [diff] [blame] | 1125 | sh_eth_write(ndev, |
Sergei Shtylyov | 128296f | 2014-01-03 15:52:22 +0300 | [diff] [blame] | 1126 | (ndev->dev_addr[4] << 8) | (ndev->dev_addr[5]), MALR); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1127 | } |
| 1128 | |
Sergei Shtylyov | 128296f | 2014-01-03 15:52:22 +0300 | [diff] [blame] | 1129 | /* Get MAC address from SuperH MAC address register |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1130 | * |
| 1131 | * SuperH's Ethernet device doesn't have 'ROM' to MAC address. |
| 1132 | * This driver get MAC address that use by bootloader(U-boot or sh-ipl+g). |
| 1133 | * When you want use this device, you must set MAC address in bootloader. |
| 1134 | * |
| 1135 | */ |
Magnus Damm | 748031f | 2009-10-09 00:17:14 +0000 | [diff] [blame] | 1136 | static void read_mac_address(struct net_device *ndev, unsigned char *mac) |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1137 | { |
Magnus Damm | 748031f | 2009-10-09 00:17:14 +0000 | [diff] [blame] | 1138 | if (mac[0] || mac[1] || mac[2] || mac[3] || mac[4] || mac[5]) { |
Joe Perches | d458cdf | 2013-10-01 19:04:40 -0700 | [diff] [blame] | 1139 | memcpy(ndev->dev_addr, mac, ETH_ALEN); |
Magnus Damm | 748031f | 2009-10-09 00:17:14 +0000 | [diff] [blame] | 1140 | } else { |
Sergei Shtylyov | 37742f0 | 2015-12-05 00:58:57 +0300 | [diff] [blame] | 1141 | u32 mahr = sh_eth_read(ndev, MAHR); |
| 1142 | u32 malr = sh_eth_read(ndev, MALR); |
| 1143 | |
| 1144 | ndev->dev_addr[0] = (mahr >> 24) & 0xFF; |
| 1145 | ndev->dev_addr[1] = (mahr >> 16) & 0xFF; |
| 1146 | ndev->dev_addr[2] = (mahr >> 8) & 0xFF; |
| 1147 | ndev->dev_addr[3] = (mahr >> 0) & 0xFF; |
| 1148 | ndev->dev_addr[4] = (malr >> 8) & 0xFF; |
| 1149 | ndev->dev_addr[5] = (malr >> 0) & 0xFF; |
Magnus Damm | 748031f | 2009-10-09 00:17:14 +0000 | [diff] [blame] | 1150 | } |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1151 | } |
| 1152 | |
| 1153 | struct bb_info { |
Yoshihiro Shimoda | ae70644 | 2011-09-27 21:48:58 +0000 | [diff] [blame] | 1154 | void (*set_gate)(void *addr); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1155 | struct mdiobb_ctrl ctrl; |
Yoshihiro Shimoda | ae70644 | 2011-09-27 21:48:58 +0000 | [diff] [blame] | 1156 | void *addr; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1157 | }; |
| 1158 | |
Sergei Shtylyov | 39b4b06 | 2015-12-08 00:40:57 +0300 | [diff] [blame] | 1159 | static void sh_mdio_ctrl(struct mdiobb_ctrl *ctrl, u32 mask, int set) |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1160 | { |
| 1161 | struct bb_info *bitbang = container_of(ctrl, struct bb_info, ctrl); |
Sergei Shtylyov | 78fa3c5 | 2015-12-08 00:41:43 +0300 | [diff] [blame] | 1162 | u32 pir; |
Yoshihiro Shimoda | b3017e6 | 2011-03-07 21:59:55 +0000 | [diff] [blame] | 1163 | |
| 1164 | if (bitbang->set_gate) |
| 1165 | bitbang->set_gate(bitbang->addr); |
| 1166 | |
Sergei Shtylyov | 78fa3c5 | 2015-12-08 00:41:43 +0300 | [diff] [blame] | 1167 | pir = ioread32(bitbang->addr); |
Sergei Shtylyov | 39b4b06 | 2015-12-08 00:40:57 +0300 | [diff] [blame] | 1168 | if (set) |
Sergei Shtylyov | 78fa3c5 | 2015-12-08 00:41:43 +0300 | [diff] [blame] | 1169 | pir |= mask; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1170 | else |
Sergei Shtylyov | 78fa3c5 | 2015-12-08 00:41:43 +0300 | [diff] [blame] | 1171 | pir &= ~mask; |
| 1172 | iowrite32(pir, bitbang->addr); |
Sergei Shtylyov | 39b4b06 | 2015-12-08 00:40:57 +0300 | [diff] [blame] | 1173 | } |
| 1174 | |
| 1175 | /* Data I/O pin control */ |
| 1176 | static void sh_mmd_ctrl(struct mdiobb_ctrl *ctrl, int bit) |
| 1177 | { |
| 1178 | sh_mdio_ctrl(ctrl, PIR_MMD, bit); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1179 | } |
| 1180 | |
| 1181 | /* Set bit data*/ |
| 1182 | static void sh_set_mdio(struct mdiobb_ctrl *ctrl, int bit) |
| 1183 | { |
Sergei Shtylyov | 39b4b06 | 2015-12-08 00:40:57 +0300 | [diff] [blame] | 1184 | sh_mdio_ctrl(ctrl, PIR_MDO, bit); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1185 | } |
| 1186 | |
| 1187 | /* Get bit data*/ |
| 1188 | static int sh_get_mdio(struct mdiobb_ctrl *ctrl) |
| 1189 | { |
| 1190 | struct bb_info *bitbang = container_of(ctrl, struct bb_info, ctrl); |
Yoshihiro Shimoda | b3017e6 | 2011-03-07 21:59:55 +0000 | [diff] [blame] | 1191 | |
| 1192 | if (bitbang->set_gate) |
| 1193 | bitbang->set_gate(bitbang->addr); |
| 1194 | |
Sergei Shtylyov | 78fa3c5 | 2015-12-08 00:41:43 +0300 | [diff] [blame] | 1195 | return (ioread32(bitbang->addr) & PIR_MDI) != 0; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1196 | } |
| 1197 | |
| 1198 | /* MDC pin control */ |
| 1199 | static void sh_mdc_ctrl(struct mdiobb_ctrl *ctrl, int bit) |
| 1200 | { |
Sergei Shtylyov | 39b4b06 | 2015-12-08 00:40:57 +0300 | [diff] [blame] | 1201 | sh_mdio_ctrl(ctrl, PIR_MDC, bit); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1202 | } |
| 1203 | |
| 1204 | /* mdio bus control struct */ |
| 1205 | static struct mdiobb_ops bb_ops = { |
| 1206 | .owner = THIS_MODULE, |
| 1207 | .set_mdc = sh_mdc_ctrl, |
| 1208 | .set_mdio_dir = sh_mmd_ctrl, |
| 1209 | .set_mdio_data = sh_set_mdio, |
| 1210 | .get_mdio_data = sh_get_mdio, |
| 1211 | }; |
| 1212 | |
Sergei Shtylyov | 1debdc8 | 2017-04-17 15:55:22 +0300 | [diff] [blame] | 1213 | /* free Tx skb function */ |
| 1214 | static int sh_eth_tx_free(struct net_device *ndev, bool sent_only) |
| 1215 | { |
| 1216 | struct sh_eth_private *mdp = netdev_priv(ndev); |
| 1217 | struct sh_eth_txdesc *txdesc; |
| 1218 | int free_num = 0; |
| 1219 | int entry; |
| 1220 | bool sent; |
| 1221 | |
| 1222 | for (; mdp->cur_tx - mdp->dirty_tx > 0; mdp->dirty_tx++) { |
| 1223 | entry = mdp->dirty_tx % mdp->num_tx_ring; |
| 1224 | txdesc = &mdp->tx_ring[entry]; |
| 1225 | sent = !(txdesc->status & cpu_to_le32(TD_TACT)); |
| 1226 | if (sent_only && !sent) |
| 1227 | break; |
| 1228 | /* TACT bit must be checked before all the following reads */ |
| 1229 | dma_rmb(); |
| 1230 | netif_info(mdp, tx_done, ndev, |
| 1231 | "tx entry %d status 0x%08x\n", |
| 1232 | entry, le32_to_cpu(txdesc->status)); |
| 1233 | /* Free the original skb. */ |
| 1234 | if (mdp->tx_skbuff[entry]) { |
Thomas Petazzoni | 22c1aed | 2017-12-04 14:33:26 +0100 | [diff] [blame] | 1235 | dma_unmap_single(&mdp->pdev->dev, |
| 1236 | le32_to_cpu(txdesc->addr), |
Sergei Shtylyov | 1debdc8 | 2017-04-17 15:55:22 +0300 | [diff] [blame] | 1237 | le32_to_cpu(txdesc->len) >> 16, |
| 1238 | DMA_TO_DEVICE); |
| 1239 | dev_kfree_skb_irq(mdp->tx_skbuff[entry]); |
| 1240 | mdp->tx_skbuff[entry] = NULL; |
| 1241 | free_num++; |
| 1242 | } |
| 1243 | txdesc->status = cpu_to_le32(TD_TFP); |
| 1244 | if (entry >= mdp->num_tx_ring - 1) |
| 1245 | txdesc->status |= cpu_to_le32(TD_TDLE); |
| 1246 | |
| 1247 | if (sent) { |
| 1248 | ndev->stats.tx_packets++; |
| 1249 | ndev->stats.tx_bytes += le32_to_cpu(txdesc->len) >> 16; |
| 1250 | } |
| 1251 | } |
| 1252 | return free_num; |
| 1253 | } |
| 1254 | |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1255 | /* free skb and descriptor buffer */ |
| 1256 | static void sh_eth_ring_free(struct net_device *ndev) |
| 1257 | { |
| 1258 | struct sh_eth_private *mdp = netdev_priv(ndev); |
Sergei Shtylyov | 8e03a5e | 2015-11-04 00:55:13 +0300 | [diff] [blame] | 1259 | int ringsize, i; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1260 | |
Sergei Shtylyov | 1debdc8 | 2017-04-17 15:55:22 +0300 | [diff] [blame] | 1261 | if (mdp->rx_ring) { |
| 1262 | for (i = 0; i < mdp->num_rx_ring; i++) { |
| 1263 | if (mdp->rx_skbuff[i]) { |
| 1264 | struct sh_eth_rxdesc *rxdesc = &mdp->rx_ring[i]; |
| 1265 | |
Thomas Petazzoni | 22c1aed | 2017-12-04 14:33:26 +0100 | [diff] [blame] | 1266 | dma_unmap_single(&mdp->pdev->dev, |
Sergei Shtylyov | 1debdc8 | 2017-04-17 15:55:22 +0300 | [diff] [blame] | 1267 | le32_to_cpu(rxdesc->addr), |
| 1268 | ALIGN(mdp->rx_buf_sz, 32), |
| 1269 | DMA_FROM_DEVICE); |
| 1270 | } |
| 1271 | } |
| 1272 | ringsize = sizeof(struct sh_eth_rxdesc) * mdp->num_rx_ring; |
Thomas Petazzoni | 573500dbf | 2017-12-04 14:33:27 +0100 | [diff] [blame] | 1273 | dma_free_coherent(&mdp->pdev->dev, ringsize, mdp->rx_ring, |
Sergei Shtylyov | 1debdc8 | 2017-04-17 15:55:22 +0300 | [diff] [blame] | 1274 | mdp->rx_desc_dma); |
| 1275 | mdp->rx_ring = NULL; |
| 1276 | } |
| 1277 | |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1278 | /* Free Rx skb ringbuffer */ |
| 1279 | if (mdp->rx_skbuff) { |
Sergei Shtylyov | 179d80a | 2014-06-28 04:10:00 +0400 | [diff] [blame] | 1280 | for (i = 0; i < mdp->num_rx_ring; i++) |
| 1281 | dev_kfree_skb(mdp->rx_skbuff[i]); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1282 | } |
| 1283 | kfree(mdp->rx_skbuff); |
Yoshihiro Shimoda | 91c77550 | 2012-06-26 20:00:01 +0000 | [diff] [blame] | 1284 | mdp->rx_skbuff = NULL; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1285 | |
Sergei Shtylyov | 8e03a5e | 2015-11-04 00:55:13 +0300 | [diff] [blame] | 1286 | if (mdp->tx_ring) { |
Sergei Shtylyov | 1debdc8 | 2017-04-17 15:55:22 +0300 | [diff] [blame] | 1287 | sh_eth_tx_free(ndev, false); |
| 1288 | |
Sergei Shtylyov | 8e03a5e | 2015-11-04 00:55:13 +0300 | [diff] [blame] | 1289 | ringsize = sizeof(struct sh_eth_txdesc) * mdp->num_tx_ring; |
Thomas Petazzoni | 573500dbf | 2017-12-04 14:33:27 +0100 | [diff] [blame] | 1290 | dma_free_coherent(&mdp->pdev->dev, ringsize, mdp->tx_ring, |
Sergei Shtylyov | 8e03a5e | 2015-11-04 00:55:13 +0300 | [diff] [blame] | 1291 | mdp->tx_desc_dma); |
| 1292 | mdp->tx_ring = NULL; |
| 1293 | } |
Sergei Shtylyov | 1debdc8 | 2017-04-17 15:55:22 +0300 | [diff] [blame] | 1294 | |
| 1295 | /* Free Tx skb ringbuffer */ |
| 1296 | kfree(mdp->tx_skbuff); |
| 1297 | mdp->tx_skbuff = NULL; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1298 | } |
| 1299 | |
| 1300 | /* format skb and descriptor buffer */ |
| 1301 | static void sh_eth_ring_format(struct net_device *ndev) |
| 1302 | { |
| 1303 | struct sh_eth_private *mdp = netdev_priv(ndev); |
| 1304 | int i; |
| 1305 | struct sk_buff *skb; |
| 1306 | struct sh_eth_rxdesc *rxdesc = NULL; |
| 1307 | struct sh_eth_txdesc *txdesc = NULL; |
Yoshihiro Shimoda | 525b807 | 2012-06-26 20:00:03 +0000 | [diff] [blame] | 1308 | int rx_ringsize = sizeof(*rxdesc) * mdp->num_rx_ring; |
| 1309 | int tx_ringsize = sizeof(*txdesc) * mdp->num_tx_ring; |
Sergei Shtylyov | cb36859 | 2015-10-24 00:46:40 +0300 | [diff] [blame] | 1310 | int skbuff_size = mdp->rx_buf_sz + SH_ETH_RX_ALIGN + 32 - 1; |
Ben Hutchings | 52b9fa3 | 2015-01-27 00:50:24 +0000 | [diff] [blame] | 1311 | dma_addr_t dma_addr; |
Sergei Shtylyov | 5cbf20c | 2015-12-20 01:48:04 +0300 | [diff] [blame] | 1312 | u32 buf_len; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1313 | |
Sergei Shtylyov | 128296f | 2014-01-03 15:52:22 +0300 | [diff] [blame] | 1314 | mdp->cur_rx = 0; |
| 1315 | mdp->cur_tx = 0; |
| 1316 | mdp->dirty_rx = 0; |
| 1317 | mdp->dirty_tx = 0; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1318 | |
| 1319 | memset(mdp->rx_ring, 0, rx_ringsize); |
| 1320 | |
| 1321 | /* build Rx ring buffer */ |
Yoshihiro Shimoda | 525b807 | 2012-06-26 20:00:03 +0000 | [diff] [blame] | 1322 | for (i = 0; i < mdp->num_rx_ring; i++) { |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1323 | /* skb */ |
| 1324 | mdp->rx_skbuff[i] = NULL; |
Mitsuhiro Kimura | 4d6a949 | 2014-11-27 20:34:00 +0900 | [diff] [blame] | 1325 | skb = netdev_alloc_skb(ndev, skbuff_size); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1326 | if (skb == NULL) |
| 1327 | break; |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 1328 | sh_eth_set_receive_align(skb); |
| 1329 | |
Sergei Shtylyov | ab85791 | 2015-10-24 00:46:03 +0300 | [diff] [blame] | 1330 | /* The size of the buffer is a multiple of 32 bytes. */ |
Sergei Shtylyov | 5cbf20c | 2015-12-20 01:48:04 +0300 | [diff] [blame] | 1331 | buf_len = ALIGN(mdp->rx_buf_sz, 32); |
Thomas Petazzoni | 22c1aed | 2017-12-04 14:33:26 +0100 | [diff] [blame] | 1332 | dma_addr = dma_map_single(&mdp->pdev->dev, skb->data, buf_len, |
Ben Hutchings | 52b9fa3 | 2015-01-27 00:50:24 +0000 | [diff] [blame] | 1333 | DMA_FROM_DEVICE); |
Thomas Petazzoni | 22c1aed | 2017-12-04 14:33:26 +0100 | [diff] [blame] | 1334 | if (dma_mapping_error(&mdp->pdev->dev, dma_addr)) { |
Ben Hutchings | 52b9fa3 | 2015-01-27 00:50:24 +0000 | [diff] [blame] | 1335 | kfree_skb(skb); |
| 1336 | break; |
| 1337 | } |
| 1338 | mdp->rx_skbuff[i] = skb; |
Sergei Shtylyov | d0ba913 | 2016-03-08 01:37:09 +0300 | [diff] [blame] | 1339 | |
| 1340 | /* RX descriptor */ |
| 1341 | rxdesc = &mdp->rx_ring[i]; |
| 1342 | rxdesc->len = cpu_to_le32(buf_len << 16); |
Sergei Shtylyov | 7cf7247 | 2015-12-28 02:10:47 +0300 | [diff] [blame] | 1343 | rxdesc->addr = cpu_to_le32(dma_addr); |
| 1344 | rxdesc->status = cpu_to_le32(RD_RACT | RD_RFP); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1345 | |
Nobuhiro Iwamatsu | b0ca2a2 | 2008-06-30 11:08:17 +0900 | [diff] [blame] | 1346 | /* Rx descriptor address set */ |
| 1347 | if (i == 0) { |
Yoshihiro Shimoda | 4a55530 | 2011-03-07 21:59:26 +0000 | [diff] [blame] | 1348 | sh_eth_write(ndev, mdp->rx_desc_dma, RDLAR); |
Sergei Shtylyov | 246e30c | 2018-03-24 23:09:55 +0300 | [diff] [blame] | 1349 | if (mdp->cd->xdfar_rw) |
Yoshihiro Shimoda | c5ed536 | 2011-03-07 21:59:38 +0000 | [diff] [blame] | 1350 | sh_eth_write(ndev, mdp->rx_desc_dma, RDFAR); |
Nobuhiro Iwamatsu | b0ca2a2 | 2008-06-30 11:08:17 +0900 | [diff] [blame] | 1351 | } |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1352 | } |
| 1353 | |
Yoshihiro Shimoda | 525b807 | 2012-06-26 20:00:03 +0000 | [diff] [blame] | 1354 | mdp->dirty_rx = (u32) (i - mdp->num_rx_ring); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1355 | |
| 1356 | /* Mark the last entry as wrapping the ring. */ |
Sergei Shtylyov | c1b7fca | 2016-03-08 01:36:28 +0300 | [diff] [blame] | 1357 | if (rxdesc) |
| 1358 | rxdesc->status |= cpu_to_le32(RD_RDLE); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1359 | |
| 1360 | memset(mdp->tx_ring, 0, tx_ringsize); |
| 1361 | |
| 1362 | /* build Tx ring buffer */ |
Yoshihiro Shimoda | 525b807 | 2012-06-26 20:00:03 +0000 | [diff] [blame] | 1363 | for (i = 0; i < mdp->num_tx_ring; i++) { |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1364 | mdp->tx_skbuff[i] = NULL; |
| 1365 | txdesc = &mdp->tx_ring[i]; |
Sergei Shtylyov | 7cf7247 | 2015-12-28 02:10:47 +0300 | [diff] [blame] | 1366 | txdesc->status = cpu_to_le32(TD_TFP); |
| 1367 | txdesc->len = cpu_to_le32(0); |
Nobuhiro Iwamatsu | b0ca2a2 | 2008-06-30 11:08:17 +0900 | [diff] [blame] | 1368 | if (i == 0) { |
Yoshinori Sato | 71557a3 | 2008-08-06 19:49:00 -0400 | [diff] [blame] | 1369 | /* Tx descriptor address set */ |
Yoshihiro Shimoda | 4a55530 | 2011-03-07 21:59:26 +0000 | [diff] [blame] | 1370 | sh_eth_write(ndev, mdp->tx_desc_dma, TDLAR); |
Sergei Shtylyov | 246e30c | 2018-03-24 23:09:55 +0300 | [diff] [blame] | 1371 | if (mdp->cd->xdfar_rw) |
Yoshihiro Shimoda | c5ed536 | 2011-03-07 21:59:38 +0000 | [diff] [blame] | 1372 | sh_eth_write(ndev, mdp->tx_desc_dma, TDFAR); |
Nobuhiro Iwamatsu | b0ca2a2 | 2008-06-30 11:08:17 +0900 | [diff] [blame] | 1373 | } |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1374 | } |
| 1375 | |
Sergei Shtylyov | 7cf7247 | 2015-12-28 02:10:47 +0300 | [diff] [blame] | 1376 | txdesc->status |= cpu_to_le32(TD_TDLE); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1377 | } |
| 1378 | |
| 1379 | /* Get skb and descriptor buffer */ |
| 1380 | static int sh_eth_ring_init(struct net_device *ndev) |
| 1381 | { |
| 1382 | struct sh_eth_private *mdp = netdev_priv(ndev); |
Sergei Shtylyov | 91d8068 | 2015-11-04 00:17:08 +0300 | [diff] [blame] | 1383 | int rx_ringsize, tx_ringsize; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1384 | |
Sergei Shtylyov | 128296f | 2014-01-03 15:52:22 +0300 | [diff] [blame] | 1385 | /* +26 gets the maximum ethernet encapsulation, +7 & ~7 because the |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1386 | * card needs room to do 8 byte alignment, +2 so we can reserve |
| 1387 | * the first 2 bytes, and +16 gets room for the status word from the |
| 1388 | * card. |
| 1389 | */ |
| 1390 | mdp->rx_buf_sz = (ndev->mtu <= 1492 ? PKT_BUF_SZ : |
| 1391 | (((ndev->mtu + 26 + 7) & ~7) + 2 + 16)); |
Magnus Damm | 503914c | 2009-12-15 21:16:55 -0800 | [diff] [blame] | 1392 | if (mdp->cd->rpadir) |
| 1393 | mdp->rx_buf_sz += NET_IP_ALIGN; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1394 | |
| 1395 | /* Allocate RX and TX skb rings */ |
Sergei Shtylyov | 2c94e85 | 2015-10-31 02:05:56 +0300 | [diff] [blame] | 1396 | mdp->rx_skbuff = kcalloc(mdp->num_rx_ring, sizeof(*mdp->rx_skbuff), |
| 1397 | GFP_KERNEL); |
Sergei Shtylyov | 91d8068 | 2015-11-04 00:17:08 +0300 | [diff] [blame] | 1398 | if (!mdp->rx_skbuff) |
| 1399 | return -ENOMEM; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1400 | |
Sergei Shtylyov | 2c94e85 | 2015-10-31 02:05:56 +0300 | [diff] [blame] | 1401 | mdp->tx_skbuff = kcalloc(mdp->num_tx_ring, sizeof(*mdp->tx_skbuff), |
| 1402 | GFP_KERNEL); |
Sergei Shtylyov | 91d8068 | 2015-11-04 00:17:08 +0300 | [diff] [blame] | 1403 | if (!mdp->tx_skbuff) |
Sergei Shtylyov | 8e03a5e | 2015-11-04 00:55:13 +0300 | [diff] [blame] | 1404 | goto ring_free; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1405 | |
| 1406 | /* Allocate all Rx descriptors. */ |
Yoshihiro Shimoda | 525b807 | 2012-06-26 20:00:03 +0000 | [diff] [blame] | 1407 | rx_ringsize = sizeof(struct sh_eth_rxdesc) * mdp->num_rx_ring; |
Thomas Petazzoni | 573500dbf | 2017-12-04 14:33:27 +0100 | [diff] [blame] | 1408 | mdp->rx_ring = dma_alloc_coherent(&mdp->pdev->dev, rx_ringsize, |
| 1409 | &mdp->rx_desc_dma, GFP_KERNEL); |
Sergei Shtylyov | 91d8068 | 2015-11-04 00:17:08 +0300 | [diff] [blame] | 1410 | if (!mdp->rx_ring) |
Sergei Shtylyov | 8e03a5e | 2015-11-04 00:55:13 +0300 | [diff] [blame] | 1411 | goto ring_free; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1412 | |
| 1413 | mdp->dirty_rx = 0; |
| 1414 | |
| 1415 | /* Allocate all Tx descriptors. */ |
Yoshihiro Shimoda | 525b807 | 2012-06-26 20:00:03 +0000 | [diff] [blame] | 1416 | tx_ringsize = sizeof(struct sh_eth_txdesc) * mdp->num_tx_ring; |
Thomas Petazzoni | 573500dbf | 2017-12-04 14:33:27 +0100 | [diff] [blame] | 1417 | mdp->tx_ring = dma_alloc_coherent(&mdp->pdev->dev, tx_ringsize, |
| 1418 | &mdp->tx_desc_dma, GFP_KERNEL); |
Sergei Shtylyov | 91d8068 | 2015-11-04 00:17:08 +0300 | [diff] [blame] | 1419 | if (!mdp->tx_ring) |
Sergei Shtylyov | 8e03a5e | 2015-11-04 00:55:13 +0300 | [diff] [blame] | 1420 | goto ring_free; |
Sergei Shtylyov | 91d8068 | 2015-11-04 00:17:08 +0300 | [diff] [blame] | 1421 | return 0; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1422 | |
Sergei Shtylyov | 8e03a5e | 2015-11-04 00:55:13 +0300 | [diff] [blame] | 1423 | ring_free: |
| 1424 | /* Free Rx and Tx skb ring buffer and DMA buffer */ |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1425 | sh_eth_ring_free(ndev); |
| 1426 | |
Sergei Shtylyov | 91d8068 | 2015-11-04 00:17:08 +0300 | [diff] [blame] | 1427 | return -ENOMEM; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1428 | } |
| 1429 | |
Sergei Shtylyov | f796721 | 2016-04-24 19:11:07 +0300 | [diff] [blame] | 1430 | static int sh_eth_dev_init(struct net_device *ndev) |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1431 | { |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1432 | struct sh_eth_private *mdp = netdev_priv(ndev); |
Sergei Shtylyov | 4fa8c3c | 2016-03-13 01:29:45 +0300 | [diff] [blame] | 1433 | int ret; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1434 | |
| 1435 | /* Soft Reset */ |
Sergei Shtylyov | 4ceedeb | 2018-03-24 23:07:41 +0300 | [diff] [blame] | 1436 | ret = mdp->cd->soft_reset(ndev); |
Nobuhiro Iwamatsu | 5cee1d3 | 2012-06-25 17:35:12 +0000 | [diff] [blame] | 1437 | if (ret) |
Laurent Pinchart | f738a13 | 2014-03-20 15:00:35 +0100 | [diff] [blame] | 1438 | return ret; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1439 | |
Simon Horman | 55754f1 | 2013-07-23 10:18:04 +0900 | [diff] [blame] | 1440 | if (mdp->cd->rmiimode) |
| 1441 | sh_eth_write(ndev, 0x1, RMIIMODE); |
| 1442 | |
Nobuhiro Iwamatsu | b0ca2a2 | 2008-06-30 11:08:17 +0900 | [diff] [blame] | 1443 | /* Descriptor format */ |
| 1444 | sh_eth_ring_format(ndev); |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 1445 | if (mdp->cd->rpadir) |
Sergei Shtylyov | 470103d | 2018-06-25 23:37:06 +0300 | [diff] [blame] | 1446 | sh_eth_write(ndev, NET_IP_ALIGN << 16, RPADIR); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1447 | |
| 1448 | /* all sh_eth int mask */ |
Yoshihiro Shimoda | 4a55530 | 2011-03-07 21:59:26 +0000 | [diff] [blame] | 1449 | sh_eth_write(ndev, 0, EESIPR); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1450 | |
Yoshihiro Shimoda | 10b9194 | 2012-03-29 19:32:08 +0000 | [diff] [blame] | 1451 | #if defined(__LITTLE_ENDIAN) |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 1452 | if (mdp->cd->hw_swap) |
Yoshihiro Shimoda | 4a55530 | 2011-03-07 21:59:26 +0000 | [diff] [blame] | 1453 | sh_eth_write(ndev, EDMR_EL, EDMR); |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 1454 | else |
Nobuhiro Iwamatsu | b0ca2a2 | 2008-06-30 11:08:17 +0900 | [diff] [blame] | 1455 | #endif |
Yoshihiro Shimoda | 4a55530 | 2011-03-07 21:59:26 +0000 | [diff] [blame] | 1456 | sh_eth_write(ndev, 0, EDMR); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1457 | |
Nobuhiro Iwamatsu | b0ca2a2 | 2008-06-30 11:08:17 +0900 | [diff] [blame] | 1458 | /* FIFO size set */ |
Yoshihiro Shimoda | 4a55530 | 2011-03-07 21:59:26 +0000 | [diff] [blame] | 1459 | sh_eth_write(ndev, mdp->cd->fdr_value, FDR); |
| 1460 | sh_eth_write(ndev, 0, TFTR); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1461 | |
Ben Dooks | 530aa2d | 2014-06-03 12:21:13 +0100 | [diff] [blame] | 1462 | /* Frame recv control (enable multiple-packets per rx irq) */ |
| 1463 | sh_eth_write(ndev, RMCR_RNC, RMCR); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1464 | |
Nobuhiro Iwamatsu | b284fbe | 2015-01-08 15:25:07 +0900 | [diff] [blame] | 1465 | sh_eth_write(ndev, mdp->cd->trscer_err_mask, TRSCER); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1466 | |
Sergei Shtylyov | 93f0fa7 | 2018-05-18 21:31:28 +0300 | [diff] [blame] | 1467 | /* DMA transfer burst mode */ |
| 1468 | if (mdp->cd->nbst) |
| 1469 | sh_eth_modify(ndev, EDMR, EDMR_NBST, EDMR_NBST); |
| 1470 | |
Sergei Shtylyov | 6b14787 | 2018-05-20 00:05:02 +0300 | [diff] [blame] | 1471 | /* Burst cycle count upper-limit */ |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 1472 | if (mdp->cd->bculr) |
Sergei Shtylyov | 6b14787 | 2018-05-20 00:05:02 +0300 | [diff] [blame] | 1473 | sh_eth_write(ndev, 0x800, BCULR); |
Nobuhiro Iwamatsu | b0ca2a2 | 2008-06-30 11:08:17 +0900 | [diff] [blame] | 1474 | |
Yoshihiro Shimoda | 4a55530 | 2011-03-07 21:59:26 +0000 | [diff] [blame] | 1475 | sh_eth_write(ndev, mdp->cd->fcftr_value, FCFTR); |
Nobuhiro Iwamatsu | b0ca2a2 | 2008-06-30 11:08:17 +0900 | [diff] [blame] | 1476 | |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 1477 | if (!mdp->cd->no_trimd) |
Yoshihiro Shimoda | 4a55530 | 2011-03-07 21:59:26 +0000 | [diff] [blame] | 1478 | sh_eth_write(ndev, 0, TRIMD); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1479 | |
Nobuhiro Iwamatsu | b0ca2a2 | 2008-06-30 11:08:17 +0900 | [diff] [blame] | 1480 | /* Recv frame limit set register */ |
Yoshihiro Shimoda | fdb37a7 | 2012-02-06 23:55:15 +0000 | [diff] [blame] | 1481 | sh_eth_write(ndev, ndev->mtu + ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN, |
| 1482 | RFLR); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1483 | |
Sergei Shtylyov | b2b14d2 | 2016-02-10 01:38:28 +0300 | [diff] [blame] | 1484 | sh_eth_modify(ndev, EESR, 0, 0); |
Sergei Shtylyov | f796721 | 2016-04-24 19:11:07 +0300 | [diff] [blame] | 1485 | mdp->irq_enabled = true; |
| 1486 | sh_eth_write(ndev, mdp->cd->eesipr_value, EESIPR); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1487 | |
Sergei Shtylyov | f8e022d | 2019-02-04 21:06:52 +0300 | [diff] [blame] | 1488 | /* EMAC Mode: PAUSE prohibition; Duplex; RX Checksum; TX; RX */ |
Sergei Shtylyov | bffa731 | 2016-01-11 00:28:14 +0300 | [diff] [blame] | 1489 | sh_eth_write(ndev, ECMR_ZPF | (mdp->duplex ? ECMR_DM : 0) | |
Sergei Shtylyov | f8e022d | 2019-02-04 21:06:52 +0300 | [diff] [blame] | 1490 | (ndev->features & NETIF_F_RXCSUM ? ECMR_RCSC : 0) | |
Sergei Shtylyov | bffa731 | 2016-01-11 00:28:14 +0300 | [diff] [blame] | 1491 | ECMR_TE | ECMR_RE, ECMR); |
Nobuhiro Iwamatsu | b0ca2a2 | 2008-06-30 11:08:17 +0900 | [diff] [blame] | 1492 | |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 1493 | if (mdp->cd->set_rate) |
| 1494 | mdp->cd->set_rate(ndev); |
| 1495 | |
Nobuhiro Iwamatsu | b0ca2a2 | 2008-06-30 11:08:17 +0900 | [diff] [blame] | 1496 | /* E-MAC Status Register clear */ |
Yoshihiro Shimoda | 4a55530 | 2011-03-07 21:59:26 +0000 | [diff] [blame] | 1497 | sh_eth_write(ndev, mdp->cd->ecsr_value, ECSR); |
Nobuhiro Iwamatsu | b0ca2a2 | 2008-06-30 11:08:17 +0900 | [diff] [blame] | 1498 | |
| 1499 | /* E-MAC Interrupt Enable register */ |
Sergei Shtylyov | f796721 | 2016-04-24 19:11:07 +0300 | [diff] [blame] | 1500 | sh_eth_write(ndev, mdp->cd->ecsipr_value, ECSIPR); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1501 | |
| 1502 | /* Set MAC address */ |
| 1503 | update_mac_address(ndev); |
| 1504 | |
| 1505 | /* mask reset */ |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 1506 | if (mdp->cd->apr) |
Sergei Shtylyov | 782e85c | 2018-06-26 18:42:33 +0300 | [diff] [blame] | 1507 | sh_eth_write(ndev, 1, APR); |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 1508 | if (mdp->cd->mpr) |
Sergei Shtylyov | 782e85c | 2018-06-26 18:42:33 +0300 | [diff] [blame] | 1509 | sh_eth_write(ndev, 1, MPR); |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 1510 | if (mdp->cd->tpauser) |
Yoshihiro Shimoda | 4a55530 | 2011-03-07 21:59:26 +0000 | [diff] [blame] | 1511 | sh_eth_write(ndev, TPAUSER_UNLIMITED, TPAUSER); |
Nobuhiro Iwamatsu | b0ca2a2 | 2008-06-30 11:08:17 +0900 | [diff] [blame] | 1512 | |
Sergei Shtylyov | f796721 | 2016-04-24 19:11:07 +0300 | [diff] [blame] | 1513 | /* Setting the Rx mode will start the Rx process. */ |
| 1514 | sh_eth_write(ndev, EDRRR_R, EDRRR); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1515 | |
| 1516 | return ret; |
| 1517 | } |
| 1518 | |
Ben Hutchings | 740c7f3 | 2015-01-27 00:49:32 +0000 | [diff] [blame] | 1519 | static void sh_eth_dev_exit(struct net_device *ndev) |
| 1520 | { |
| 1521 | struct sh_eth_private *mdp = netdev_priv(ndev); |
| 1522 | int i; |
| 1523 | |
| 1524 | /* Deactivate all TX descriptors, so DMA should stop at next |
| 1525 | * packet boundary if it's currently running |
| 1526 | */ |
| 1527 | for (i = 0; i < mdp->num_tx_ring; i++) |
Sergei Shtylyov | 7cf7247 | 2015-12-28 02:10:47 +0300 | [diff] [blame] | 1528 | mdp->tx_ring[i].status &= ~cpu_to_le32(TD_TACT); |
Ben Hutchings | 740c7f3 | 2015-01-27 00:49:32 +0000 | [diff] [blame] | 1529 | |
| 1530 | /* Disable TX FIFO egress to MAC */ |
| 1531 | sh_eth_rcv_snd_disable(ndev); |
| 1532 | |
| 1533 | /* Stop RX DMA at next packet boundary */ |
| 1534 | sh_eth_write(ndev, 0, EDRRR); |
| 1535 | |
| 1536 | /* Aside from TX DMA, we can't tell when the hardware is |
| 1537 | * really stopped, so we need to reset to make sure. |
| 1538 | * Before doing that, wait for long enough to *probably* |
| 1539 | * finish transmitting the last packet and poll stats. |
| 1540 | */ |
| 1541 | msleep(2); /* max frame time at 10 Mbps < 1250 us */ |
| 1542 | sh_eth_get_stats(ndev); |
Sergei Shtylyov | 4ceedeb | 2018-03-24 23:07:41 +0300 | [diff] [blame] | 1543 | mdp->cd->soft_reset(ndev); |
Geert Uytterhoeven | a14c7d1 | 2015-02-27 17:16:26 +0100 | [diff] [blame] | 1544 | |
Yoshihiro Shimoda | 315ca92 | 2019-05-28 13:10:46 +0900 | [diff] [blame] | 1545 | /* Set the RMII mode again if required */ |
| 1546 | if (mdp->cd->rmiimode) |
| 1547 | sh_eth_write(ndev, 0x1, RMIIMODE); |
| 1548 | |
Geert Uytterhoeven | a14c7d1 | 2015-02-27 17:16:26 +0100 | [diff] [blame] | 1549 | /* Set MAC address again */ |
| 1550 | update_mac_address(ndev); |
Ben Hutchings | 740c7f3 | 2015-01-27 00:49:32 +0000 | [diff] [blame] | 1551 | } |
| 1552 | |
Sergei Shtylyov | f8e022d | 2019-02-04 21:06:52 +0300 | [diff] [blame] | 1553 | static void sh_eth_rx_csum(struct sk_buff *skb) |
| 1554 | { |
| 1555 | u8 *hw_csum; |
| 1556 | |
| 1557 | /* The hardware checksum is 2 bytes appended to packet data */ |
| 1558 | if (unlikely(skb->len < sizeof(__sum16))) |
| 1559 | return; |
| 1560 | hw_csum = skb_tail_pointer(skb) - sizeof(__sum16); |
| 1561 | skb->csum = csum_unfold((__force __sum16)get_unaligned_le16(hw_csum)); |
| 1562 | skb->ip_summed = CHECKSUM_COMPLETE; |
| 1563 | skb_trim(skb, skb->len - sizeof(__sum16)); |
| 1564 | } |
| 1565 | |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1566 | /* Packet receive function */ |
Sergei Shtylyov | 3719109 | 2013-06-19 23:30:23 +0400 | [diff] [blame] | 1567 | static int sh_eth_rx(struct net_device *ndev, u32 intr_status, int *quota) |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1568 | { |
| 1569 | struct sh_eth_private *mdp = netdev_priv(ndev); |
| 1570 | struct sh_eth_rxdesc *rxdesc; |
| 1571 | |
Yoshihiro Shimoda | 525b807 | 2012-06-26 20:00:03 +0000 | [diff] [blame] | 1572 | int entry = mdp->cur_rx % mdp->num_rx_ring; |
| 1573 | int boguscnt = (mdp->dirty_rx + mdp->num_rx_ring) - mdp->cur_rx; |
Mitsuhiro Kimura | 319cd52 | 2014-12-09 21:23:42 +0900 | [diff] [blame] | 1574 | int limit; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1575 | struct sk_buff *skb; |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 1576 | u32 desc_status; |
Sergei Shtylyov | cb36859 | 2015-10-24 00:46:40 +0300 | [diff] [blame] | 1577 | int skbuff_size = mdp->rx_buf_sz + SH_ETH_RX_ALIGN + 32 - 1; |
Ben Hutchings | 52b9fa3 | 2015-01-27 00:50:24 +0000 | [diff] [blame] | 1578 | dma_addr_t dma_addr; |
Sergei Shtylyov | 4fa8c3c | 2016-03-13 01:29:45 +0300 | [diff] [blame] | 1579 | u16 pkt_len; |
Sergei Shtylyov | 5cbf20c | 2015-12-20 01:48:04 +0300 | [diff] [blame] | 1580 | u32 buf_len; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1581 | |
Mitsuhiro Kimura | 319cd52 | 2014-12-09 21:23:42 +0900 | [diff] [blame] | 1582 | boguscnt = min(boguscnt, *quota); |
| 1583 | limit = boguscnt; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1584 | rxdesc = &mdp->rx_ring[entry]; |
Sergei Shtylyov | 7cf7247 | 2015-12-28 02:10:47 +0300 | [diff] [blame] | 1585 | while (!(rxdesc->status & cpu_to_le32(RD_RACT))) { |
Ben Hutchings | 7d7355f | 2015-03-03 00:52:00 +0000 | [diff] [blame] | 1586 | /* RACT bit must be checked before all the following reads */ |
Sergei Shtylyov | f32bfb9 | 2015-11-03 22:36:04 +0300 | [diff] [blame] | 1587 | dma_rmb(); |
Sergei Shtylyov | 7cf7247 | 2015-12-28 02:10:47 +0300 | [diff] [blame] | 1588 | desc_status = le32_to_cpu(rxdesc->status); |
| 1589 | pkt_len = le32_to_cpu(rxdesc->len) & RD_RFL; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1590 | |
| 1591 | if (--boguscnt < 0) |
| 1592 | break; |
| 1593 | |
Ben Hutchings | e5fd13f | 2015-02-26 20:34:46 +0000 | [diff] [blame] | 1594 | netif_info(mdp, rx_status, ndev, |
| 1595 | "rx entry %d status 0x%08x len %d\n", |
| 1596 | entry, desc_status, pkt_len); |
| 1597 | |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1598 | if (!(desc_status & RDFEND)) |
Eric Dumazet | bb7d92e | 2012-02-06 22:17:21 +0000 | [diff] [blame] | 1599 | ndev->stats.rx_length_errors++; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1600 | |
Sergei Shtylyov | 128296f | 2014-01-03 15:52:22 +0300 | [diff] [blame] | 1601 | /* In case of almost all GETHER/ETHERs, the Receive Frame State |
Yoshihiro Shimoda | dd01989 | 2013-06-13 10:15:45 +0900 | [diff] [blame] | 1602 | * (RFS) bits in the Receive Descriptor 0 are from bit 9 to |
Ben Hutchings | 9b4a636 | 2015-03-03 00:52:39 +0000 | [diff] [blame] | 1603 | * bit 0. However, in case of the R8A7740 and R7S72100 |
| 1604 | * the RFS bits are from bit 25 to bit 16. So, the |
Simon Horman | db89347 | 2014-01-17 09:22:28 +0900 | [diff] [blame] | 1605 | * driver needs right shifting by 16. |
Yoshihiro Shimoda | dd01989 | 2013-06-13 10:15:45 +0900 | [diff] [blame] | 1606 | */ |
Sergei Shtylyov | 2c2ab5a | 2019-02-04 21:05:55 +0300 | [diff] [blame] | 1607 | if (mdp->cd->csmr) |
Sergei Shtylyov | ac8025a | 2013-06-13 22:12:45 +0400 | [diff] [blame] | 1608 | desc_status >>= 16; |
Yoshihiro Shimoda | dd01989 | 2013-06-13 10:15:45 +0900 | [diff] [blame] | 1609 | |
Sergei Shtylyov | 248be83 | 2015-12-04 01:45:40 +0300 | [diff] [blame] | 1610 | skb = mdp->rx_skbuff[entry]; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1611 | if (desc_status & (RD_RFS1 | RD_RFS2 | RD_RFS3 | RD_RFS4 | |
| 1612 | RD_RFS5 | RD_RFS6 | RD_RFS10)) { |
Eric Dumazet | bb7d92e | 2012-02-06 22:17:21 +0000 | [diff] [blame] | 1613 | ndev->stats.rx_errors++; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1614 | if (desc_status & RD_RFS1) |
Eric Dumazet | bb7d92e | 2012-02-06 22:17:21 +0000 | [diff] [blame] | 1615 | ndev->stats.rx_crc_errors++; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1616 | if (desc_status & RD_RFS2) |
Eric Dumazet | bb7d92e | 2012-02-06 22:17:21 +0000 | [diff] [blame] | 1617 | ndev->stats.rx_frame_errors++; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1618 | if (desc_status & RD_RFS3) |
Eric Dumazet | bb7d92e | 2012-02-06 22:17:21 +0000 | [diff] [blame] | 1619 | ndev->stats.rx_length_errors++; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1620 | if (desc_status & RD_RFS4) |
Eric Dumazet | bb7d92e | 2012-02-06 22:17:21 +0000 | [diff] [blame] | 1621 | ndev->stats.rx_length_errors++; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1622 | if (desc_status & RD_RFS6) |
Eric Dumazet | bb7d92e | 2012-02-06 22:17:21 +0000 | [diff] [blame] | 1623 | ndev->stats.rx_missed_errors++; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1624 | if (desc_status & RD_RFS10) |
Eric Dumazet | bb7d92e | 2012-02-06 22:17:21 +0000 | [diff] [blame] | 1625 | ndev->stats.rx_over_errors++; |
Sergei Shtylyov | 248be83 | 2015-12-04 01:45:40 +0300 | [diff] [blame] | 1626 | } else if (skb) { |
Sergei Shtylyov | 7cf7247 | 2015-12-28 02:10:47 +0300 | [diff] [blame] | 1627 | dma_addr = le32_to_cpu(rxdesc->addr); |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 1628 | if (!mdp->cd->hw_swap) |
| 1629 | sh_eth_soft_swap( |
Sergei Shtylyov | 1299653 | 2015-12-13 23:05:07 +0300 | [diff] [blame] | 1630 | phys_to_virt(ALIGN(dma_addr, 4)), |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 1631 | pkt_len + 2); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1632 | mdp->rx_skbuff[entry] = NULL; |
Magnus Damm | 503914c | 2009-12-15 21:16:55 -0800 | [diff] [blame] | 1633 | if (mdp->cd->rpadir) |
| 1634 | skb_reserve(skb, NET_IP_ALIGN); |
Thomas Petazzoni | 22c1aed | 2017-12-04 14:33:26 +0100 | [diff] [blame] | 1635 | dma_unmap_single(&mdp->pdev->dev, dma_addr, |
Sergei Shtylyov | ab85791 | 2015-10-24 00:46:03 +0300 | [diff] [blame] | 1636 | ALIGN(mdp->rx_buf_sz, 32), |
Ben Hutchings | 52b9fa3 | 2015-01-27 00:50:24 +0000 | [diff] [blame] | 1637 | DMA_FROM_DEVICE); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1638 | skb_put(skb, pkt_len); |
| 1639 | skb->protocol = eth_type_trans(skb, ndev); |
Sergei Shtylyov | f8e022d | 2019-02-04 21:06:52 +0300 | [diff] [blame] | 1640 | if (ndev->features & NETIF_F_RXCSUM) |
| 1641 | sh_eth_rx_csum(skb); |
Sergei Shtylyov | a8e9fd0 | 2013-09-03 03:03:10 +0400 | [diff] [blame] | 1642 | netif_receive_skb(skb); |
Eric Dumazet | bb7d92e | 2012-02-06 22:17:21 +0000 | [diff] [blame] | 1643 | ndev->stats.rx_packets++; |
| 1644 | ndev->stats.rx_bytes += pkt_len; |
Ben Hutchings | 25b77ad | 2015-02-26 20:33:30 +0000 | [diff] [blame] | 1645 | if (desc_status & RD_RFS8) |
| 1646 | ndev->stats.multicast++; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1647 | } |
Yoshihiro Shimoda | 525b807 | 2012-06-26 20:00:03 +0000 | [diff] [blame] | 1648 | entry = (++mdp->cur_rx) % mdp->num_rx_ring; |
Yoshihiro Shimoda | 862df49 | 2009-05-24 23:53:40 +0000 | [diff] [blame] | 1649 | rxdesc = &mdp->rx_ring[entry]; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1650 | } |
| 1651 | |
| 1652 | /* Refill the Rx ring buffers. */ |
| 1653 | for (; mdp->cur_rx - mdp->dirty_rx > 0; mdp->dirty_rx++) { |
Yoshihiro Shimoda | 525b807 | 2012-06-26 20:00:03 +0000 | [diff] [blame] | 1654 | entry = mdp->dirty_rx % mdp->num_rx_ring; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1655 | rxdesc = &mdp->rx_ring[entry]; |
Sergei Shtylyov | ab85791 | 2015-10-24 00:46:03 +0300 | [diff] [blame] | 1656 | /* The size of the buffer is 32 byte boundary. */ |
Sergei Shtylyov | 5cbf20c | 2015-12-20 01:48:04 +0300 | [diff] [blame] | 1657 | buf_len = ALIGN(mdp->rx_buf_sz, 32); |
Sergei Shtylyov | 7cf7247 | 2015-12-28 02:10:47 +0300 | [diff] [blame] | 1658 | rxdesc->len = cpu_to_le32(buf_len << 16); |
Nobuhiro Iwamatsu | b0ca2a2 | 2008-06-30 11:08:17 +0900 | [diff] [blame] | 1659 | |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1660 | if (mdp->rx_skbuff[entry] == NULL) { |
Mitsuhiro Kimura | 4d6a949 | 2014-11-27 20:34:00 +0900 | [diff] [blame] | 1661 | skb = netdev_alloc_skb(ndev, skbuff_size); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1662 | if (skb == NULL) |
| 1663 | break; /* Better luck next round. */ |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 1664 | sh_eth_set_receive_align(skb); |
Thomas Petazzoni | 22c1aed | 2017-12-04 14:33:26 +0100 | [diff] [blame] | 1665 | dma_addr = dma_map_single(&mdp->pdev->dev, skb->data, |
Sergei Shtylyov | 5cbf20c | 2015-12-20 01:48:04 +0300 | [diff] [blame] | 1666 | buf_len, DMA_FROM_DEVICE); |
Thomas Petazzoni | 22c1aed | 2017-12-04 14:33:26 +0100 | [diff] [blame] | 1667 | if (dma_mapping_error(&mdp->pdev->dev, dma_addr)) { |
Ben Hutchings | 52b9fa3 | 2015-01-27 00:50:24 +0000 | [diff] [blame] | 1668 | kfree_skb(skb); |
| 1669 | break; |
| 1670 | } |
| 1671 | mdp->rx_skbuff[entry] = skb; |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 1672 | |
Eric Dumazet | bc8acf2 | 2010-09-02 13:07:41 -0700 | [diff] [blame] | 1673 | skb_checksum_none_assert(skb); |
Sergei Shtylyov | 7cf7247 | 2015-12-28 02:10:47 +0300 | [diff] [blame] | 1674 | rxdesc->addr = cpu_to_le32(dma_addr); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1675 | } |
Sergei Shtylyov | f32bfb9 | 2015-11-03 22:36:04 +0300 | [diff] [blame] | 1676 | dma_wmb(); /* RACT bit must be set after all the above writes */ |
Yoshihiro Shimoda | 525b807 | 2012-06-26 20:00:03 +0000 | [diff] [blame] | 1677 | if (entry >= mdp->num_rx_ring - 1) |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1678 | rxdesc->status |= |
Sergei Shtylyov | 7cf7247 | 2015-12-28 02:10:47 +0300 | [diff] [blame] | 1679 | cpu_to_le32(RD_RACT | RD_RFP | RD_RDLE); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1680 | else |
Sergei Shtylyov | 7cf7247 | 2015-12-28 02:10:47 +0300 | [diff] [blame] | 1681 | rxdesc->status |= cpu_to_le32(RD_RACT | RD_RFP); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1682 | } |
| 1683 | |
| 1684 | /* Restart Rx engine if stopped. */ |
| 1685 | /* If we don't need to check status, don't. -KDU */ |
Yoshihiro Shimoda | 79fba9f | 2012-05-28 23:07:55 +0000 | [diff] [blame] | 1686 | if (!(sh_eth_read(ndev, EDRRR) & EDRRR_R)) { |
Yoshihiro Shimoda | a18e08b | 2012-06-20 15:26:34 +0000 | [diff] [blame] | 1687 | /* fix the values for the next receiving if RDE is set */ |
Sergei Shtylyov | 6e80e55 | 2018-04-01 00:22:08 +0300 | [diff] [blame] | 1688 | if (intr_status & EESR_RDE && !mdp->cd->no_xdfar) { |
Sergei Shtylyov | 128296f | 2014-01-03 15:52:22 +0300 | [diff] [blame] | 1689 | u32 count = (sh_eth_read(ndev, RDFAR) - |
| 1690 | sh_eth_read(ndev, RDLAR)) >> 4; |
| 1691 | |
| 1692 | mdp->cur_rx = count; |
| 1693 | mdp->dirty_rx = count; |
| 1694 | } |
Yoshihiro Shimoda | 4a55530 | 2011-03-07 21:59:26 +0000 | [diff] [blame] | 1695 | sh_eth_write(ndev, EDRRR_R, EDRRR); |
Yoshihiro Shimoda | 79fba9f | 2012-05-28 23:07:55 +0000 | [diff] [blame] | 1696 | } |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1697 | |
Mitsuhiro Kimura | 319cd52 | 2014-12-09 21:23:42 +0900 | [diff] [blame] | 1698 | *quota -= limit - boguscnt - 1; |
| 1699 | |
Yoshihiro Shimoda | 4f809ce | 2014-06-10 09:40:14 +0900 | [diff] [blame] | 1700 | return *quota <= 0; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1701 | } |
| 1702 | |
Yoshihiro Shimoda | 4a55530 | 2011-03-07 21:59:26 +0000 | [diff] [blame] | 1703 | static void sh_eth_rcv_snd_disable(struct net_device *ndev) |
Nobuhiro Iwamatsu | dc19e4e | 2011-02-15 21:17:32 +0000 | [diff] [blame] | 1704 | { |
| 1705 | /* disable tx and rx */ |
Sergei Shtylyov | b2b14d2 | 2016-02-10 01:38:28 +0300 | [diff] [blame] | 1706 | sh_eth_modify(ndev, ECMR, ECMR_RE | ECMR_TE, 0); |
Nobuhiro Iwamatsu | dc19e4e | 2011-02-15 21:17:32 +0000 | [diff] [blame] | 1707 | } |
| 1708 | |
Yoshihiro Shimoda | 4a55530 | 2011-03-07 21:59:26 +0000 | [diff] [blame] | 1709 | static void sh_eth_rcv_snd_enable(struct net_device *ndev) |
Nobuhiro Iwamatsu | dc19e4e | 2011-02-15 21:17:32 +0000 | [diff] [blame] | 1710 | { |
| 1711 | /* enable tx and rx */ |
Sergei Shtylyov | b2b14d2 | 2016-02-10 01:38:28 +0300 | [diff] [blame] | 1712 | sh_eth_modify(ndev, ECMR, ECMR_RE | ECMR_TE, ECMR_RE | ECMR_TE); |
Nobuhiro Iwamatsu | dc19e4e | 2011-02-15 21:17:32 +0000 | [diff] [blame] | 1713 | } |
| 1714 | |
Sergei Shtylyov | 9b39f05 | 2017-01-04 15:11:21 +0300 | [diff] [blame] | 1715 | /* E-MAC interrupt handler */ |
| 1716 | static void sh_eth_emac_interrupt(struct net_device *ndev) |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1717 | { |
| 1718 | struct sh_eth_private *mdp = netdev_priv(ndev); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1719 | u32 felic_stat; |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 1720 | u32 link_stat; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1721 | |
Sergei Shtylyov | 9b39f05 | 2017-01-04 15:11:21 +0300 | [diff] [blame] | 1722 | felic_stat = sh_eth_read(ndev, ECSR) & sh_eth_read(ndev, ECSIPR); |
| 1723 | sh_eth_write(ndev, felic_stat, ECSR); /* clear int */ |
| 1724 | if (felic_stat & ECSR_ICD) |
| 1725 | ndev->stats.tx_carrier_errors++; |
Niklas Söderlund | 0cf45a3 | 2017-02-01 15:41:55 +0100 | [diff] [blame] | 1726 | if (felic_stat & ECSR_MPD) |
| 1727 | pm_wakeup_event(&mdp->pdev->dev, 0); |
Sergei Shtylyov | 9b39f05 | 2017-01-04 15:11:21 +0300 | [diff] [blame] | 1728 | if (felic_stat & ECSR_LCHNG) { |
| 1729 | /* Link Changed */ |
| 1730 | if (mdp->cd->no_psr || mdp->no_ether_link) |
| 1731 | return; |
| 1732 | link_stat = sh_eth_read(ndev, PSR); |
| 1733 | if (mdp->ether_link_active_low) |
| 1734 | link_stat = ~link_stat; |
| 1735 | if (!(link_stat & PHY_ST_LINK)) { |
| 1736 | sh_eth_rcv_snd_disable(ndev); |
| 1737 | } else { |
| 1738 | /* Link Up */ |
Sergei Shtylyov | 1a0bee6 | 2017-01-29 15:07:34 +0300 | [diff] [blame] | 1739 | sh_eth_modify(ndev, EESIPR, EESIPR_ECIIP, 0); |
Sergei Shtylyov | 9b39f05 | 2017-01-04 15:11:21 +0300 | [diff] [blame] | 1740 | /* clear int */ |
| 1741 | sh_eth_modify(ndev, ECSR, 0, 0); |
Sergei Shtylyov | 1a0bee6 | 2017-01-29 15:07:34 +0300 | [diff] [blame] | 1742 | sh_eth_modify(ndev, EESIPR, EESIPR_ECIIP, EESIPR_ECIIP); |
Sergei Shtylyov | 9b39f05 | 2017-01-04 15:11:21 +0300 | [diff] [blame] | 1743 | /* enable tx and rx */ |
| 1744 | sh_eth_rcv_snd_enable(ndev); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1745 | } |
| 1746 | } |
Sergei Shtylyov | 9b39f05 | 2017-01-04 15:11:21 +0300 | [diff] [blame] | 1747 | } |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1748 | |
Sergei Shtylyov | 9b39f05 | 2017-01-04 15:11:21 +0300 | [diff] [blame] | 1749 | /* error control function */ |
| 1750 | static void sh_eth_error(struct net_device *ndev, u32 intr_status) |
| 1751 | { |
| 1752 | struct sh_eth_private *mdp = netdev_priv(ndev); |
| 1753 | u32 mask; |
| 1754 | |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1755 | if (intr_status & EESR_TWB) { |
Sergei Shtylyov | 4eb313a | 2013-06-21 01:13:42 +0400 | [diff] [blame] | 1756 | /* Unused write back interrupt */ |
| 1757 | if (intr_status & EESR_TABT) { /* Transmit Abort int */ |
Eric Dumazet | bb7d92e | 2012-02-06 22:17:21 +0000 | [diff] [blame] | 1758 | ndev->stats.tx_aborted_errors++; |
Sergei Shtylyov | 8d5009f | 2014-03-15 03:30:59 +0300 | [diff] [blame] | 1759 | netif_err(mdp, tx_err, ndev, "Transmit Abort\n"); |
Sergei Shtylyov | 4eb313a | 2013-06-21 01:13:42 +0400 | [diff] [blame] | 1760 | } |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1761 | } |
| 1762 | |
| 1763 | if (intr_status & EESR_RABT) { |
| 1764 | /* Receive Abort int */ |
| 1765 | if (intr_status & EESR_RFRMER) { |
| 1766 | /* Receive Frame Overflow int */ |
Eric Dumazet | bb7d92e | 2012-02-06 22:17:21 +0000 | [diff] [blame] | 1767 | ndev->stats.rx_frame_errors++; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1768 | } |
| 1769 | } |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 1770 | |
Nobuhiro Iwamatsu | dc19e4e | 2011-02-15 21:17:32 +0000 | [diff] [blame] | 1771 | if (intr_status & EESR_TDE) { |
| 1772 | /* Transmit Descriptor Empty int */ |
Eric Dumazet | bb7d92e | 2012-02-06 22:17:21 +0000 | [diff] [blame] | 1773 | ndev->stats.tx_fifo_errors++; |
Sergei Shtylyov | 8d5009f | 2014-03-15 03:30:59 +0300 | [diff] [blame] | 1774 | netif_err(mdp, tx_err, ndev, "Transmit Descriptor Empty\n"); |
Nobuhiro Iwamatsu | dc19e4e | 2011-02-15 21:17:32 +0000 | [diff] [blame] | 1775 | } |
| 1776 | |
| 1777 | if (intr_status & EESR_TFE) { |
| 1778 | /* FIFO under flow */ |
Eric Dumazet | bb7d92e | 2012-02-06 22:17:21 +0000 | [diff] [blame] | 1779 | ndev->stats.tx_fifo_errors++; |
Sergei Shtylyov | 8d5009f | 2014-03-15 03:30:59 +0300 | [diff] [blame] | 1780 | netif_err(mdp, tx_err, ndev, "Transmit FIFO Under flow\n"); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1781 | } |
| 1782 | |
| 1783 | if (intr_status & EESR_RDE) { |
| 1784 | /* Receive Descriptor Empty int */ |
Eric Dumazet | bb7d92e | 2012-02-06 22:17:21 +0000 | [diff] [blame] | 1785 | ndev->stats.rx_over_errors++; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1786 | } |
Nobuhiro Iwamatsu | dc19e4e | 2011-02-15 21:17:32 +0000 | [diff] [blame] | 1787 | |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1788 | if (intr_status & EESR_RFE) { |
| 1789 | /* Receive FIFO Overflow int */ |
Eric Dumazet | bb7d92e | 2012-02-06 22:17:21 +0000 | [diff] [blame] | 1790 | ndev->stats.rx_fifo_errors++; |
Nobuhiro Iwamatsu | dc19e4e | 2011-02-15 21:17:32 +0000 | [diff] [blame] | 1791 | } |
| 1792 | |
| 1793 | if (!mdp->cd->no_ade && (intr_status & EESR_ADE)) { |
| 1794 | /* Address Error */ |
Eric Dumazet | bb7d92e | 2012-02-06 22:17:21 +0000 | [diff] [blame] | 1795 | ndev->stats.tx_fifo_errors++; |
Sergei Shtylyov | 8d5009f | 2014-03-15 03:30:59 +0300 | [diff] [blame] | 1796 | netif_err(mdp, tx_err, ndev, "Address Error\n"); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1797 | } |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 1798 | |
| 1799 | mask = EESR_TWB | EESR_TABT | EESR_ADE | EESR_TDE | EESR_TFE; |
| 1800 | if (mdp->cd->no_ade) |
| 1801 | mask &= ~EESR_ADE; |
| 1802 | if (intr_status & mask) { |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1803 | /* Tx error */ |
Yoshihiro Shimoda | 4a55530 | 2011-03-07 21:59:26 +0000 | [diff] [blame] | 1804 | u32 edtrr = sh_eth_read(ndev, EDTRR); |
Sergei Shtylyov | 090d560 | 2014-01-11 02:41:49 +0300 | [diff] [blame] | 1805 | |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1806 | /* dmesg */ |
Sergei Shtylyov | da24685 | 2014-03-15 03:29:14 +0300 | [diff] [blame] | 1807 | netdev_err(ndev, "TX error. status=%8.8x cur_tx=%8.8x dirty_tx=%8.8x state=%8.8x EDTRR=%8.8x.\n", |
| 1808 | intr_status, mdp->cur_tx, mdp->dirty_tx, |
| 1809 | (u32)ndev->state, edtrr); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1810 | /* dirty buffer free */ |
Sergei Shtylyov | 1debdc8 | 2017-04-17 15:55:22 +0300 | [diff] [blame] | 1811 | sh_eth_tx_free(ndev, true); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1812 | |
| 1813 | /* SH7712 BUG */ |
Sergei Shtylyov | 3e41699 | 2018-03-24 23:08:42 +0300 | [diff] [blame] | 1814 | if (edtrr ^ mdp->cd->edtrr_trns) { |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1815 | /* tx dma start */ |
Sergei Shtylyov | 3e41699 | 2018-03-24 23:08:42 +0300 | [diff] [blame] | 1816 | sh_eth_write(ndev, mdp->cd->edtrr_trns, EDTRR); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1817 | } |
| 1818 | /* wakeup */ |
| 1819 | netif_wake_queue(ndev); |
| 1820 | } |
| 1821 | } |
| 1822 | |
| 1823 | static irqreturn_t sh_eth_interrupt(int irq, void *netdev) |
| 1824 | { |
| 1825 | struct net_device *ndev = netdev; |
| 1826 | struct sh_eth_private *mdp = netdev_priv(ndev); |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 1827 | struct sh_eth_cpu_data *cd = mdp->cd; |
Nobuhiro Iwamatsu | 0e0fde3 | 2009-03-16 19:50:57 +0000 | [diff] [blame] | 1828 | irqreturn_t ret = IRQ_NONE; |
Geert Uytterhoeven | 0799c2d | 2015-01-15 11:54:28 +0100 | [diff] [blame] | 1829 | u32 intr_status, intr_enable; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1830 | |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1831 | spin_lock(&mdp->lock); |
| 1832 | |
Sergei Shtylyov | 3893b27345 | 2013-03-31 09:54:20 +0000 | [diff] [blame] | 1833 | /* Get interrupt status */ |
Yoshihiro Shimoda | 4a55530 | 2011-03-07 21:59:26 +0000 | [diff] [blame] | 1834 | intr_status = sh_eth_read(ndev, EESR); |
Sergei Shtylyov | 9b39f05 | 2017-01-04 15:11:21 +0300 | [diff] [blame] | 1835 | /* Mask it with the interrupt mask, forcing ECI interrupt to be always |
| 1836 | * enabled since it's the one that comes thru regardless of the mask, |
| 1837 | * and we need to fully handle it in sh_eth_emac_interrupt() in order |
| 1838 | * to quench it as it doesn't get cleared by just writing 1 to the ECI |
| 1839 | * bit... |
Sergei Shtylyov | 3893b27345 | 2013-03-31 09:54:20 +0000 | [diff] [blame] | 1840 | */ |
Sergei Shtylyov | 3719109 | 2013-06-19 23:30:23 +0400 | [diff] [blame] | 1841 | intr_enable = sh_eth_read(ndev, EESIPR); |
Sergei Shtylyov | 1a0bee6 | 2017-01-29 15:07:34 +0300 | [diff] [blame] | 1842 | intr_status &= intr_enable | EESIPR_ECIIP; |
Sergei Shtylyov | 9b39f05 | 2017-01-04 15:11:21 +0300 | [diff] [blame] | 1843 | if (intr_status & (EESR_RX_CHECK | cd->tx_check | EESR_ECI | |
| 1844 | cd->eesr_err_check)) |
Nobuhiro Iwamatsu | 0e0fde3 | 2009-03-16 19:50:57 +0000 | [diff] [blame] | 1845 | ret = IRQ_HANDLED; |
Sergei Shtylyov | 3719109 | 2013-06-19 23:30:23 +0400 | [diff] [blame] | 1846 | else |
Ben Hutchings | 283e38d | 2015-01-22 12:44:08 +0000 | [diff] [blame] | 1847 | goto out; |
| 1848 | |
Sergei Shtylyov | 2344ef3 | 2016-12-30 00:07:38 +0300 | [diff] [blame] | 1849 | if (unlikely(!mdp->irq_enabled)) { |
Ben Hutchings | 283e38d | 2015-01-22 12:44:08 +0000 | [diff] [blame] | 1850 | sh_eth_write(ndev, 0, EESIPR); |
| 1851 | goto out; |
| 1852 | } |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1853 | |
Sergei Shtylyov | 3719109 | 2013-06-19 23:30:23 +0400 | [diff] [blame] | 1854 | if (intr_status & EESR_RX_CHECK) { |
| 1855 | if (napi_schedule_prep(&mdp->napi)) { |
| 1856 | /* Mask Rx interrupts */ |
| 1857 | sh_eth_write(ndev, intr_enable & ~EESR_RX_CHECK, |
| 1858 | EESIPR); |
| 1859 | __napi_schedule(&mdp->napi); |
| 1860 | } else { |
Sergei Shtylyov | da24685 | 2014-03-15 03:29:14 +0300 | [diff] [blame] | 1861 | netdev_warn(ndev, |
Geert Uytterhoeven | 0799c2d | 2015-01-15 11:54:28 +0100 | [diff] [blame] | 1862 | "ignoring interrupt, status 0x%08x, mask 0x%08x.\n", |
Sergei Shtylyov | da24685 | 2014-03-15 03:29:14 +0300 | [diff] [blame] | 1863 | intr_status, intr_enable); |
Sergei Shtylyov | 3719109 | 2013-06-19 23:30:23 +0400 | [diff] [blame] | 1864 | } |
| 1865 | } |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1866 | |
Nobuhiro Iwamatsu | b0ca2a2 | 2008-06-30 11:08:17 +0900 | [diff] [blame] | 1867 | /* Tx Check */ |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 1868 | if (intr_status & cd->tx_check) { |
Sergei Shtylyov | 3719109 | 2013-06-19 23:30:23 +0400 | [diff] [blame] | 1869 | /* Clear Tx interrupts */ |
| 1870 | sh_eth_write(ndev, intr_status & cd->tx_check, EESR); |
| 1871 | |
Sergei Shtylyov | 1debdc8 | 2017-04-17 15:55:22 +0300 | [diff] [blame] | 1872 | sh_eth_tx_free(ndev, true); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1873 | netif_wake_queue(ndev); |
| 1874 | } |
| 1875 | |
Sergei Shtylyov | 9b39f05 | 2017-01-04 15:11:21 +0300 | [diff] [blame] | 1876 | /* E-MAC interrupt */ |
| 1877 | if (intr_status & EESR_ECI) |
| 1878 | sh_eth_emac_interrupt(ndev); |
| 1879 | |
Sergei Shtylyov | 3719109 | 2013-06-19 23:30:23 +0400 | [diff] [blame] | 1880 | if (intr_status & cd->eesr_err_check) { |
| 1881 | /* Clear error interrupts */ |
| 1882 | sh_eth_write(ndev, intr_status & cd->eesr_err_check, EESR); |
| 1883 | |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1884 | sh_eth_error(ndev, intr_status); |
Sergei Shtylyov | 3719109 | 2013-06-19 23:30:23 +0400 | [diff] [blame] | 1885 | } |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1886 | |
Ben Hutchings | 283e38d | 2015-01-22 12:44:08 +0000 | [diff] [blame] | 1887 | out: |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1888 | spin_unlock(&mdp->lock); |
| 1889 | |
Nobuhiro Iwamatsu | 0e0fde3 | 2009-03-16 19:50:57 +0000 | [diff] [blame] | 1890 | return ret; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1891 | } |
| 1892 | |
Sergei Shtylyov | 3719109 | 2013-06-19 23:30:23 +0400 | [diff] [blame] | 1893 | static int sh_eth_poll(struct napi_struct *napi, int budget) |
| 1894 | { |
| 1895 | struct sh_eth_private *mdp = container_of(napi, struct sh_eth_private, |
| 1896 | napi); |
| 1897 | struct net_device *ndev = napi->dev; |
| 1898 | int quota = budget; |
Geert Uytterhoeven | 0799c2d | 2015-01-15 11:54:28 +0100 | [diff] [blame] | 1899 | u32 intr_status; |
Sergei Shtylyov | 3719109 | 2013-06-19 23:30:23 +0400 | [diff] [blame] | 1900 | |
| 1901 | for (;;) { |
| 1902 | intr_status = sh_eth_read(ndev, EESR); |
| 1903 | if (!(intr_status & EESR_RX_CHECK)) |
| 1904 | break; |
| 1905 | /* Clear Rx interrupts */ |
| 1906 | sh_eth_write(ndev, intr_status & EESR_RX_CHECK, EESR); |
| 1907 | |
| 1908 | if (sh_eth_rx(ndev, intr_status, "a)) |
| 1909 | goto out; |
| 1910 | } |
| 1911 | |
| 1912 | napi_complete(napi); |
| 1913 | |
| 1914 | /* Reenable Rx interrupts */ |
Ben Hutchings | 283e38d | 2015-01-22 12:44:08 +0000 | [diff] [blame] | 1915 | if (mdp->irq_enabled) |
| 1916 | sh_eth_write(ndev, mdp->cd->eesipr_value, EESIPR); |
Sergei Shtylyov | 3719109 | 2013-06-19 23:30:23 +0400 | [diff] [blame] | 1917 | out: |
| 1918 | return budget - quota; |
| 1919 | } |
| 1920 | |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1921 | /* PHY state control function */ |
| 1922 | static void sh_eth_adjust_link(struct net_device *ndev) |
| 1923 | { |
| 1924 | struct sh_eth_private *mdp = netdev_priv(ndev); |
Philippe Reynes | 9fd0375 | 2016-08-10 00:04:48 +0200 | [diff] [blame] | 1925 | struct phy_device *phydev = ndev->phydev; |
Vladimir Zapolskiy | 5cb3f52 | 2018-07-04 11:12:40 +0300 | [diff] [blame] | 1926 | unsigned long flags; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1927 | int new_state = 0; |
| 1928 | |
Vladimir Zapolskiy | 5cb3f52 | 2018-07-04 11:12:40 +0300 | [diff] [blame] | 1929 | spin_lock_irqsave(&mdp->lock, flags); |
| 1930 | |
| 1931 | /* Disable TX and RX right over here, if E-MAC change is ignored */ |
| 1932 | if (mdp->cd->no_psr || mdp->no_ether_link) |
| 1933 | sh_eth_rcv_snd_disable(ndev); |
| 1934 | |
Sergei Shtylyov | 3340d2a | 2013-03-31 10:11:04 +0000 | [diff] [blame] | 1935 | if (phydev->link) { |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1936 | if (phydev->duplex != mdp->duplex) { |
| 1937 | new_state = 1; |
| 1938 | mdp->duplex = phydev->duplex; |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 1939 | if (mdp->cd->set_duplex) |
| 1940 | mdp->cd->set_duplex(ndev); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1941 | } |
| 1942 | |
| 1943 | if (phydev->speed != mdp->speed) { |
| 1944 | new_state = 1; |
| 1945 | mdp->speed = phydev->speed; |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 1946 | if (mdp->cd->set_rate) |
| 1947 | mdp->cd->set_rate(ndev); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1948 | } |
Sergei Shtylyov | 3340d2a | 2013-03-31 10:11:04 +0000 | [diff] [blame] | 1949 | if (!mdp->link) { |
Sergei Shtylyov | b2b14d2 | 2016-02-10 01:38:28 +0300 | [diff] [blame] | 1950 | sh_eth_modify(ndev, ECMR, ECMR_TXF, 0); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1951 | new_state = 1; |
| 1952 | mdp->link = phydev->link; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1953 | } |
| 1954 | } else if (mdp->link) { |
| 1955 | new_state = 1; |
Sergei Shtylyov | 3340d2a | 2013-03-31 10:11:04 +0000 | [diff] [blame] | 1956 | mdp->link = 0; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1957 | mdp->speed = 0; |
| 1958 | mdp->duplex = -1; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1959 | } |
| 1960 | |
Vladimir Zapolskiy | 5cb3f52 | 2018-07-04 11:12:40 +0300 | [diff] [blame] | 1961 | /* Enable TX and RX right over here, if E-MAC change is ignored */ |
| 1962 | if ((mdp->cd->no_psr || mdp->no_ether_link) && phydev->link) |
| 1963 | sh_eth_rcv_snd_enable(ndev); |
| 1964 | |
Vladimir Zapolskiy | 5cb3f52 | 2018-07-04 11:12:40 +0300 | [diff] [blame] | 1965 | spin_unlock_irqrestore(&mdp->lock, flags); |
| 1966 | |
Nobuhiro Iwamatsu | dc19e4e | 2011-02-15 21:17:32 +0000 | [diff] [blame] | 1967 | if (new_state && netif_msg_link(mdp)) |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1968 | phy_print_status(phydev); |
| 1969 | } |
| 1970 | |
| 1971 | /* PHY init function */ |
| 1972 | static int sh_eth_phy_init(struct net_device *ndev) |
| 1973 | { |
Ben Dooks | 702eca0 | 2014-03-12 17:47:40 +0000 | [diff] [blame] | 1974 | struct device_node *np = ndev->dev.parent->of_node; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1975 | struct sh_eth_private *mdp = netdev_priv(ndev); |
Sergei Shtylyov | 4fa8c3c | 2016-03-13 01:29:45 +0300 | [diff] [blame] | 1976 | struct phy_device *phydev; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1977 | |
Sergei Shtylyov | 3340d2a | 2013-03-31 10:11:04 +0000 | [diff] [blame] | 1978 | mdp->link = 0; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1979 | mdp->speed = 0; |
| 1980 | mdp->duplex = -1; |
| 1981 | |
| 1982 | /* Try connect to PHY */ |
Ben Dooks | 702eca0 | 2014-03-12 17:47:40 +0000 | [diff] [blame] | 1983 | if (np) { |
| 1984 | struct device_node *pn; |
| 1985 | |
| 1986 | pn = of_parse_phandle(np, "phy-handle", 0); |
| 1987 | phydev = of_phy_connect(ndev, pn, |
| 1988 | sh_eth_adjust_link, 0, |
| 1989 | mdp->phy_interface); |
| 1990 | |
Peter Chen | 8da703d | 2016-08-01 15:02:40 +0800 | [diff] [blame] | 1991 | of_node_put(pn); |
Ben Dooks | 702eca0 | 2014-03-12 17:47:40 +0000 | [diff] [blame] | 1992 | if (!phydev) |
| 1993 | phydev = ERR_PTR(-ENOENT); |
| 1994 | } else { |
| 1995 | char phy_id[MII_BUS_ID_SIZE + 3]; |
| 1996 | |
| 1997 | snprintf(phy_id, sizeof(phy_id), PHY_ID_FMT, |
| 1998 | mdp->mii_bus->id, mdp->phy_id); |
| 1999 | |
| 2000 | phydev = phy_connect(ndev, phy_id, sh_eth_adjust_link, |
| 2001 | mdp->phy_interface); |
| 2002 | } |
| 2003 | |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2004 | if (IS_ERR(phydev)) { |
Sergei Shtylyov | da24685 | 2014-03-15 03:29:14 +0300 | [diff] [blame] | 2005 | netdev_err(ndev, "failed to connect PHY\n"); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2006 | return PTR_ERR(phydev); |
| 2007 | } |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 2008 | |
Thomas Petazzoni | 2aab6b4 | 2017-12-08 16:35:40 +0100 | [diff] [blame] | 2009 | /* mask with MAC supported features */ |
| 2010 | if (mdp->cd->register_type != SH_ETH_REG_GIGABIT) { |
| 2011 | int err = phy_set_max_speed(phydev, SPEED_100); |
| 2012 | if (err) { |
| 2013 | netdev_err(ndev, "failed to limit PHY to 100 Mbit/s\n"); |
| 2014 | phy_disconnect(phydev); |
| 2015 | return err; |
| 2016 | } |
| 2017 | } |
| 2018 | |
Andrew Lunn | 2220943 | 2016-01-06 20:11:13 +0100 | [diff] [blame] | 2019 | phy_attached_info(phydev); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2020 | |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2021 | return 0; |
| 2022 | } |
| 2023 | |
| 2024 | /* PHY control start function */ |
| 2025 | static int sh_eth_phy_start(struct net_device *ndev) |
| 2026 | { |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2027 | int ret; |
| 2028 | |
| 2029 | ret = sh_eth_phy_init(ndev); |
| 2030 | if (ret) |
| 2031 | return ret; |
| 2032 | |
Philippe Reynes | 9fd0375 | 2016-08-10 00:04:48 +0200 | [diff] [blame] | 2033 | phy_start(ndev->phydev); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2034 | |
| 2035 | return 0; |
| 2036 | } |
| 2037 | |
Ben Hutchings | 6b4b4fe | 2015-02-26 20:34:35 +0000 | [diff] [blame] | 2038 | /* If it is ever necessary to increase SH_ETH_REG_DUMP_MAX_REGS, the |
| 2039 | * version must be bumped as well. Just adding registers up to that |
| 2040 | * limit is fine, as long as the existing register indices don't |
| 2041 | * change. |
| 2042 | */ |
| 2043 | #define SH_ETH_REG_DUMP_VERSION 1 |
| 2044 | #define SH_ETH_REG_DUMP_MAX_REGS 256 |
| 2045 | |
| 2046 | static size_t __sh_eth_get_regs(struct net_device *ndev, u32 *buf) |
| 2047 | { |
| 2048 | struct sh_eth_private *mdp = netdev_priv(ndev); |
| 2049 | struct sh_eth_cpu_data *cd = mdp->cd; |
| 2050 | u32 *valid_map; |
| 2051 | size_t len; |
| 2052 | |
| 2053 | BUILD_BUG_ON(SH_ETH_MAX_REGISTER_OFFSET > SH_ETH_REG_DUMP_MAX_REGS); |
| 2054 | |
| 2055 | /* Dump starts with a bitmap that tells ethtool which |
| 2056 | * registers are defined for this chip. |
| 2057 | */ |
| 2058 | len = DIV_ROUND_UP(SH_ETH_REG_DUMP_MAX_REGS, 32); |
| 2059 | if (buf) { |
| 2060 | valid_map = buf; |
| 2061 | buf += len; |
| 2062 | } else { |
| 2063 | valid_map = NULL; |
| 2064 | } |
| 2065 | |
| 2066 | /* Add a register to the dump, if it has a defined offset. |
| 2067 | * This automatically skips most undefined registers, but for |
| 2068 | * some it is also necessary to check a capability flag in |
| 2069 | * struct sh_eth_cpu_data. |
| 2070 | */ |
| 2071 | #define mark_reg_valid(reg) valid_map[reg / 32] |= 1U << (reg % 32) |
| 2072 | #define add_reg_from(reg, read_expr) do { \ |
| 2073 | if (mdp->reg_offset[reg] != SH_ETH_OFFSET_INVALID) { \ |
| 2074 | if (buf) { \ |
| 2075 | mark_reg_valid(reg); \ |
| 2076 | *buf++ = read_expr; \ |
| 2077 | } \ |
| 2078 | ++len; \ |
| 2079 | } \ |
| 2080 | } while (0) |
| 2081 | #define add_reg(reg) add_reg_from(reg, sh_eth_read(ndev, reg)) |
| 2082 | #define add_tsu_reg(reg) add_reg_from(reg, sh_eth_tsu_read(mdp, reg)) |
| 2083 | |
| 2084 | add_reg(EDSR); |
| 2085 | add_reg(EDMR); |
| 2086 | add_reg(EDTRR); |
| 2087 | add_reg(EDRRR); |
| 2088 | add_reg(EESR); |
| 2089 | add_reg(EESIPR); |
| 2090 | add_reg(TDLAR); |
Sergei Shtylyov | 7bf47f6 | 2020-02-15 23:10:53 +0300 | [diff] [blame] | 2091 | if (!cd->no_xdfar) |
| 2092 | add_reg(TDFAR); |
Ben Hutchings | 6b4b4fe | 2015-02-26 20:34:35 +0000 | [diff] [blame] | 2093 | add_reg(TDFXR); |
| 2094 | add_reg(TDFFR); |
| 2095 | add_reg(RDLAR); |
Sergei Shtylyov | 7bf47f6 | 2020-02-15 23:10:53 +0300 | [diff] [blame] | 2096 | if (!cd->no_xdfar) |
| 2097 | add_reg(RDFAR); |
Ben Hutchings | 6b4b4fe | 2015-02-26 20:34:35 +0000 | [diff] [blame] | 2098 | add_reg(RDFXR); |
| 2099 | add_reg(RDFFR); |
| 2100 | add_reg(TRSCER); |
| 2101 | add_reg(RMFCR); |
| 2102 | add_reg(TFTR); |
| 2103 | add_reg(FDR); |
| 2104 | add_reg(RMCR); |
| 2105 | add_reg(TFUCR); |
| 2106 | add_reg(RFOCR); |
| 2107 | if (cd->rmiimode) |
| 2108 | add_reg(RMIIMODE); |
| 2109 | add_reg(FCFTR); |
| 2110 | if (cd->rpadir) |
| 2111 | add_reg(RPADIR); |
| 2112 | if (!cd->no_trimd) |
| 2113 | add_reg(TRIMD); |
| 2114 | add_reg(ECMR); |
| 2115 | add_reg(ECSR); |
| 2116 | add_reg(ECSIPR); |
| 2117 | add_reg(PIR); |
| 2118 | if (!cd->no_psr) |
| 2119 | add_reg(PSR); |
| 2120 | add_reg(RDMLR); |
| 2121 | add_reg(RFLR); |
| 2122 | add_reg(IPGR); |
| 2123 | if (cd->apr) |
| 2124 | add_reg(APR); |
| 2125 | if (cd->mpr) |
| 2126 | add_reg(MPR); |
| 2127 | add_reg(RFCR); |
| 2128 | add_reg(RFCF); |
| 2129 | if (cd->tpauser) |
| 2130 | add_reg(TPAUSER); |
| 2131 | add_reg(TPAUSECR); |
Sergei Shtylyov | a6318d5 | 2020-02-15 23:13:45 +0300 | [diff] [blame] | 2132 | if (cd->gecmr) |
| 2133 | add_reg(GECMR); |
Ben Hutchings | 6b4b4fe | 2015-02-26 20:34:35 +0000 | [diff] [blame] | 2134 | if (cd->bculr) |
| 2135 | add_reg(BCULR); |
| 2136 | add_reg(MAHR); |
| 2137 | add_reg(MALR); |
Sergei Shtylyov | 6eaeedc | 2020-02-15 23:08:20 +0300 | [diff] [blame] | 2138 | if (!cd->no_tx_cntrs) { |
| 2139 | add_reg(TROCR); |
| 2140 | add_reg(CDCR); |
| 2141 | add_reg(LCCR); |
| 2142 | add_reg(CNDCR); |
| 2143 | } |
Ben Hutchings | 6b4b4fe | 2015-02-26 20:34:35 +0000 | [diff] [blame] | 2144 | add_reg(CEFCR); |
| 2145 | add_reg(FRECR); |
| 2146 | add_reg(TSFRCR); |
| 2147 | add_reg(TLFRCR); |
Sergei Shtylyov | f75ca32 | 2020-02-15 23:09:35 +0300 | [diff] [blame] | 2148 | if (cd->cexcr) { |
| 2149 | add_reg(CERCR); |
| 2150 | add_reg(CEECR); |
| 2151 | } |
Ben Hutchings | 6b4b4fe | 2015-02-26 20:34:35 +0000 | [diff] [blame] | 2152 | add_reg(MAFCR); |
| 2153 | if (cd->rtrate) |
| 2154 | add_reg(RTRATE); |
Sergei Shtylyov | 2c2ab5a | 2019-02-04 21:05:55 +0300 | [diff] [blame] | 2155 | if (cd->csmr) |
Ben Hutchings | 6b4b4fe | 2015-02-26 20:34:35 +0000 | [diff] [blame] | 2156 | add_reg(CSMR); |
| 2157 | if (cd->select_mii) |
| 2158 | add_reg(RMII_MII); |
Ben Hutchings | 6b4b4fe | 2015-02-26 20:34:35 +0000 | [diff] [blame] | 2159 | if (cd->tsu) { |
Sergei Shtylyov | 17d0fb0 | 2018-01-13 20:22:01 +0300 | [diff] [blame] | 2160 | add_tsu_reg(ARSTR); |
Ben Hutchings | 6b4b4fe | 2015-02-26 20:34:35 +0000 | [diff] [blame] | 2161 | add_tsu_reg(TSU_CTRST); |
Sergei Shtylyov | 3249b1e | 2020-01-08 23:42:42 +0300 | [diff] [blame] | 2162 | if (cd->dual_port) { |
| 2163 | add_tsu_reg(TSU_FWEN0); |
| 2164 | add_tsu_reg(TSU_FWEN1); |
| 2165 | add_tsu_reg(TSU_FCM); |
| 2166 | add_tsu_reg(TSU_BSYSL0); |
| 2167 | add_tsu_reg(TSU_BSYSL1); |
| 2168 | add_tsu_reg(TSU_PRISL0); |
| 2169 | add_tsu_reg(TSU_PRISL1); |
| 2170 | add_tsu_reg(TSU_FWSL0); |
| 2171 | add_tsu_reg(TSU_FWSL1); |
| 2172 | } |
Ben Hutchings | 6b4b4fe | 2015-02-26 20:34:35 +0000 | [diff] [blame] | 2173 | add_tsu_reg(TSU_FWSLC); |
Sergei Shtylyov | 3249b1e | 2020-01-08 23:42:42 +0300 | [diff] [blame] | 2174 | if (cd->dual_port) { |
| 2175 | add_tsu_reg(TSU_QTAGM0); |
| 2176 | add_tsu_reg(TSU_QTAGM1); |
| 2177 | add_tsu_reg(TSU_FWSR); |
| 2178 | add_tsu_reg(TSU_FWINMK); |
| 2179 | add_tsu_reg(TSU_ADQT0); |
| 2180 | add_tsu_reg(TSU_ADQT1); |
| 2181 | add_tsu_reg(TSU_VTAG0); |
| 2182 | add_tsu_reg(TSU_VTAG1); |
| 2183 | } |
Ben Hutchings | 6b4b4fe | 2015-02-26 20:34:35 +0000 | [diff] [blame] | 2184 | add_tsu_reg(TSU_ADSBSY); |
| 2185 | add_tsu_reg(TSU_TEN); |
| 2186 | add_tsu_reg(TSU_POST1); |
| 2187 | add_tsu_reg(TSU_POST2); |
| 2188 | add_tsu_reg(TSU_POST3); |
| 2189 | add_tsu_reg(TSU_POST4); |
Sergei Shtylyov | e14549a | 2018-04-01 00:23:51 +0300 | [diff] [blame] | 2190 | /* This is the start of a table, not just a single register. */ |
| 2191 | if (buf) { |
| 2192 | unsigned int i; |
Ben Hutchings | 6b4b4fe | 2015-02-26 20:34:35 +0000 | [diff] [blame] | 2193 | |
Sergei Shtylyov | e14549a | 2018-04-01 00:23:51 +0300 | [diff] [blame] | 2194 | mark_reg_valid(TSU_ADRH0); |
| 2195 | for (i = 0; i < SH_ETH_TSU_CAM_ENTRIES * 2; i++) |
| 2196 | *buf++ = ioread32(mdp->tsu_addr + |
| 2197 | mdp->reg_offset[TSU_ADRH0] + |
| 2198 | i * 4); |
Ben Hutchings | 6b4b4fe | 2015-02-26 20:34:35 +0000 | [diff] [blame] | 2199 | } |
Sergei Shtylyov | e14549a | 2018-04-01 00:23:51 +0300 | [diff] [blame] | 2200 | len += SH_ETH_TSU_CAM_ENTRIES * 2; |
Ben Hutchings | 6b4b4fe | 2015-02-26 20:34:35 +0000 | [diff] [blame] | 2201 | } |
| 2202 | |
| 2203 | #undef mark_reg_valid |
| 2204 | #undef add_reg_from |
| 2205 | #undef add_reg |
| 2206 | #undef add_tsu_reg |
| 2207 | |
| 2208 | return len * 4; |
| 2209 | } |
| 2210 | |
| 2211 | static int sh_eth_get_regs_len(struct net_device *ndev) |
| 2212 | { |
| 2213 | return __sh_eth_get_regs(ndev, NULL); |
| 2214 | } |
| 2215 | |
| 2216 | static void sh_eth_get_regs(struct net_device *ndev, struct ethtool_regs *regs, |
| 2217 | void *buf) |
| 2218 | { |
| 2219 | struct sh_eth_private *mdp = netdev_priv(ndev); |
| 2220 | |
| 2221 | regs->version = SH_ETH_REG_DUMP_VERSION; |
| 2222 | |
| 2223 | pm_runtime_get_sync(&mdp->pdev->dev); |
| 2224 | __sh_eth_get_regs(ndev, buf); |
| 2225 | pm_runtime_put_sync(&mdp->pdev->dev); |
| 2226 | } |
| 2227 | |
Nobuhiro Iwamatsu | dc19e4e | 2011-02-15 21:17:32 +0000 | [diff] [blame] | 2228 | static u32 sh_eth_get_msglevel(struct net_device *ndev) |
| 2229 | { |
| 2230 | struct sh_eth_private *mdp = netdev_priv(ndev); |
| 2231 | return mdp->msg_enable; |
| 2232 | } |
| 2233 | |
| 2234 | static void sh_eth_set_msglevel(struct net_device *ndev, u32 value) |
| 2235 | { |
| 2236 | struct sh_eth_private *mdp = netdev_priv(ndev); |
| 2237 | mdp->msg_enable = value; |
| 2238 | } |
| 2239 | |
| 2240 | static const char sh_eth_gstrings_stats[][ETH_GSTRING_LEN] = { |
| 2241 | "rx_current", "tx_current", |
| 2242 | "rx_dirty", "tx_dirty", |
| 2243 | }; |
| 2244 | #define SH_ETH_STATS_LEN ARRAY_SIZE(sh_eth_gstrings_stats) |
| 2245 | |
| 2246 | static int sh_eth_get_sset_count(struct net_device *netdev, int sset) |
| 2247 | { |
| 2248 | switch (sset) { |
| 2249 | case ETH_SS_STATS: |
| 2250 | return SH_ETH_STATS_LEN; |
| 2251 | default: |
| 2252 | return -EOPNOTSUPP; |
| 2253 | } |
| 2254 | } |
| 2255 | |
| 2256 | static void sh_eth_get_ethtool_stats(struct net_device *ndev, |
Sergei Shtylyov | 128296f | 2014-01-03 15:52:22 +0300 | [diff] [blame] | 2257 | struct ethtool_stats *stats, u64 *data) |
Nobuhiro Iwamatsu | dc19e4e | 2011-02-15 21:17:32 +0000 | [diff] [blame] | 2258 | { |
| 2259 | struct sh_eth_private *mdp = netdev_priv(ndev); |
| 2260 | int i = 0; |
| 2261 | |
| 2262 | /* device-specific stats */ |
| 2263 | data[i++] = mdp->cur_rx; |
| 2264 | data[i++] = mdp->cur_tx; |
| 2265 | data[i++] = mdp->dirty_rx; |
| 2266 | data[i++] = mdp->dirty_tx; |
| 2267 | } |
| 2268 | |
| 2269 | static void sh_eth_get_strings(struct net_device *ndev, u32 stringset, u8 *data) |
| 2270 | { |
| 2271 | switch (stringset) { |
| 2272 | case ETH_SS_STATS: |
| 2273 | memcpy(data, *sh_eth_gstrings_stats, |
Sergei Shtylyov | 128296f | 2014-01-03 15:52:22 +0300 | [diff] [blame] | 2274 | sizeof(sh_eth_gstrings_stats)); |
Nobuhiro Iwamatsu | dc19e4e | 2011-02-15 21:17:32 +0000 | [diff] [blame] | 2275 | break; |
| 2276 | } |
| 2277 | } |
| 2278 | |
Yoshihiro Shimoda | 525b807 | 2012-06-26 20:00:03 +0000 | [diff] [blame] | 2279 | static void sh_eth_get_ringparam(struct net_device *ndev, |
| 2280 | struct ethtool_ringparam *ring) |
| 2281 | { |
| 2282 | struct sh_eth_private *mdp = netdev_priv(ndev); |
| 2283 | |
| 2284 | ring->rx_max_pending = RX_RING_MAX; |
| 2285 | ring->tx_max_pending = TX_RING_MAX; |
| 2286 | ring->rx_pending = mdp->num_rx_ring; |
| 2287 | ring->tx_pending = mdp->num_tx_ring; |
| 2288 | } |
| 2289 | |
| 2290 | static int sh_eth_set_ringparam(struct net_device *ndev, |
| 2291 | struct ethtool_ringparam *ring) |
| 2292 | { |
| 2293 | struct sh_eth_private *mdp = netdev_priv(ndev); |
| 2294 | int ret; |
| 2295 | |
| 2296 | if (ring->tx_pending > TX_RING_MAX || |
| 2297 | ring->rx_pending > RX_RING_MAX || |
| 2298 | ring->tx_pending < TX_RING_MIN || |
| 2299 | ring->rx_pending < RX_RING_MIN) |
| 2300 | return -EINVAL; |
| 2301 | if (ring->rx_mini_pending || ring->rx_jumbo_pending) |
| 2302 | return -EINVAL; |
| 2303 | |
| 2304 | if (netif_running(ndev)) { |
Ben Hutchings | bd88891 | 2015-01-22 12:40:25 +0000 | [diff] [blame] | 2305 | netif_device_detach(ndev); |
Yoshihiro Shimoda | 525b807 | 2012-06-26 20:00:03 +0000 | [diff] [blame] | 2306 | netif_tx_disable(ndev); |
Yoshihiro Shimoda | 525b807 | 2012-06-26 20:00:03 +0000 | [diff] [blame] | 2307 | |
Ben Hutchings | 283e38d | 2015-01-22 12:44:08 +0000 | [diff] [blame] | 2308 | /* Serialise with the interrupt handler and NAPI, then |
| 2309 | * disable interrupts. We have to clear the |
| 2310 | * irq_enabled flag first to ensure that interrupts |
| 2311 | * won't be re-enabled. |
| 2312 | */ |
| 2313 | mdp->irq_enabled = false; |
| 2314 | synchronize_irq(ndev->irq); |
| 2315 | napi_synchronize(&mdp->napi); |
Yoshihiro Shimoda | 525b807 | 2012-06-26 20:00:03 +0000 | [diff] [blame] | 2316 | sh_eth_write(ndev, 0x0000, EESIPR); |
Ben Hutchings | 283e38d | 2015-01-22 12:44:08 +0000 | [diff] [blame] | 2317 | |
Ben Hutchings | 740c7f3 | 2015-01-27 00:49:32 +0000 | [diff] [blame] | 2318 | sh_eth_dev_exit(ndev); |
Yoshihiro Shimoda | 525b807 | 2012-06-26 20:00:03 +0000 | [diff] [blame] | 2319 | |
Sergei Shtylyov | 8e03a5e | 2015-11-04 00:55:13 +0300 | [diff] [blame] | 2320 | /* Free all the skbuffs in the Rx queue and the DMA buffers. */ |
Ben Hutchings | 084236d | 2015-01-22 12:41:34 +0000 | [diff] [blame] | 2321 | sh_eth_ring_free(ndev); |
Ben Hutchings | 084236d | 2015-01-22 12:41:34 +0000 | [diff] [blame] | 2322 | } |
Yoshihiro Shimoda | 525b807 | 2012-06-26 20:00:03 +0000 | [diff] [blame] | 2323 | |
| 2324 | /* Set new parameters */ |
| 2325 | mdp->num_rx_ring = ring->rx_pending; |
| 2326 | mdp->num_tx_ring = ring->tx_pending; |
| 2327 | |
Yoshihiro Shimoda | 525b807 | 2012-06-26 20:00:03 +0000 | [diff] [blame] | 2328 | if (netif_running(ndev)) { |
Ben Hutchings | 084236d | 2015-01-22 12:41:34 +0000 | [diff] [blame] | 2329 | ret = sh_eth_ring_init(ndev); |
| 2330 | if (ret < 0) { |
| 2331 | netdev_err(ndev, "%s: sh_eth_ring_init failed.\n", |
| 2332 | __func__); |
| 2333 | return ret; |
| 2334 | } |
Sergei Shtylyov | f796721 | 2016-04-24 19:11:07 +0300 | [diff] [blame] | 2335 | ret = sh_eth_dev_init(ndev); |
Ben Hutchings | 084236d | 2015-01-22 12:41:34 +0000 | [diff] [blame] | 2336 | if (ret < 0) { |
| 2337 | netdev_err(ndev, "%s: sh_eth_dev_init failed.\n", |
| 2338 | __func__); |
| 2339 | return ret; |
| 2340 | } |
| 2341 | |
Ben Hutchings | bd88891 | 2015-01-22 12:40:25 +0000 | [diff] [blame] | 2342 | netif_device_attach(ndev); |
Yoshihiro Shimoda | 525b807 | 2012-06-26 20:00:03 +0000 | [diff] [blame] | 2343 | } |
| 2344 | |
| 2345 | return 0; |
| 2346 | } |
| 2347 | |
Niklas Söderlund | d8981d0 | 2017-01-09 16:34:05 +0100 | [diff] [blame] | 2348 | static void sh_eth_get_wol(struct net_device *ndev, struct ethtool_wolinfo *wol) |
| 2349 | { |
| 2350 | struct sh_eth_private *mdp = netdev_priv(ndev); |
| 2351 | |
| 2352 | wol->supported = 0; |
| 2353 | wol->wolopts = 0; |
| 2354 | |
Geert Uytterhoeven | b4580c9 | 2018-02-12 14:42:36 +0100 | [diff] [blame] | 2355 | if (mdp->cd->magic) { |
Niklas Söderlund | d8981d0 | 2017-01-09 16:34:05 +0100 | [diff] [blame] | 2356 | wol->supported = WAKE_MAGIC; |
| 2357 | wol->wolopts = mdp->wol_enabled ? WAKE_MAGIC : 0; |
| 2358 | } |
| 2359 | } |
| 2360 | |
| 2361 | static int sh_eth_set_wol(struct net_device *ndev, struct ethtool_wolinfo *wol) |
| 2362 | { |
| 2363 | struct sh_eth_private *mdp = netdev_priv(ndev); |
| 2364 | |
Geert Uytterhoeven | b4580c9 | 2018-02-12 14:42:36 +0100 | [diff] [blame] | 2365 | if (!mdp->cd->magic || wol->wolopts & ~WAKE_MAGIC) |
Niklas Söderlund | d8981d0 | 2017-01-09 16:34:05 +0100 | [diff] [blame] | 2366 | return -EOPNOTSUPP; |
| 2367 | |
| 2368 | mdp->wol_enabled = !!(wol->wolopts & WAKE_MAGIC); |
| 2369 | |
| 2370 | device_set_wakeup_enable(&mdp->pdev->dev, mdp->wol_enabled); |
| 2371 | |
| 2372 | return 0; |
| 2373 | } |
| 2374 | |
stephen hemminger | 9b07be4 | 2012-01-04 12:59:49 +0000 | [diff] [blame] | 2375 | static const struct ethtool_ops sh_eth_ethtool_ops = { |
Ben Hutchings | 6b4b4fe | 2015-02-26 20:34:35 +0000 | [diff] [blame] | 2376 | .get_regs_len = sh_eth_get_regs_len, |
| 2377 | .get_regs = sh_eth_get_regs, |
Vladimir Zapolskiy | 4c10628 | 2018-07-04 11:12:42 +0300 | [diff] [blame] | 2378 | .nway_reset = phy_ethtool_nway_reset, |
Nobuhiro Iwamatsu | dc19e4e | 2011-02-15 21:17:32 +0000 | [diff] [blame] | 2379 | .get_msglevel = sh_eth_get_msglevel, |
| 2380 | .set_msglevel = sh_eth_set_msglevel, |
stephen hemminger | 9b07be4 | 2012-01-04 12:59:49 +0000 | [diff] [blame] | 2381 | .get_link = ethtool_op_get_link, |
Nobuhiro Iwamatsu | dc19e4e | 2011-02-15 21:17:32 +0000 | [diff] [blame] | 2382 | .get_strings = sh_eth_get_strings, |
| 2383 | .get_ethtool_stats = sh_eth_get_ethtool_stats, |
| 2384 | .get_sset_count = sh_eth_get_sset_count, |
Yoshihiro Shimoda | 525b807 | 2012-06-26 20:00:03 +0000 | [diff] [blame] | 2385 | .get_ringparam = sh_eth_get_ringparam, |
| 2386 | .set_ringparam = sh_eth_set_ringparam, |
Vladimir Zapolskiy | 45abbd4 | 2018-07-04 11:14:48 +0300 | [diff] [blame] | 2387 | .get_link_ksettings = phy_ethtool_get_link_ksettings, |
Vladimir Zapolskiy | 6783f50 | 2018-07-04 11:14:49 +0300 | [diff] [blame] | 2388 | .set_link_ksettings = phy_ethtool_set_link_ksettings, |
Niklas Söderlund | d8981d0 | 2017-01-09 16:34:05 +0100 | [diff] [blame] | 2389 | .get_wol = sh_eth_get_wol, |
| 2390 | .set_wol = sh_eth_set_wol, |
Nobuhiro Iwamatsu | dc19e4e | 2011-02-15 21:17:32 +0000 | [diff] [blame] | 2391 | }; |
| 2392 | |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2393 | /* network device open function */ |
| 2394 | static int sh_eth_open(struct net_device *ndev) |
| 2395 | { |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2396 | struct sh_eth_private *mdp = netdev_priv(ndev); |
Sergei Shtylyov | 4fa8c3c | 2016-03-13 01:29:45 +0300 | [diff] [blame] | 2397 | int ret; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2398 | |
Magnus Damm | bcd5149 | 2009-10-09 00:20:04 +0000 | [diff] [blame] | 2399 | pm_runtime_get_sync(&mdp->pdev->dev); |
| 2400 | |
Sergei Shtylyov | d2779e9 | 2013-09-04 02:41:27 +0400 | [diff] [blame] | 2401 | napi_enable(&mdp->napi); |
| 2402 | |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 2403 | ret = request_irq(ndev->irq, sh_eth_interrupt, |
Nobuhiro Iwamatsu | 5b3dfd1 | 2013-06-06 09:49:30 +0000 | [diff] [blame] | 2404 | mdp->cd->irq_flags, ndev->name, ndev); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2405 | if (ret) { |
Sergei Shtylyov | da24685 | 2014-03-15 03:29:14 +0300 | [diff] [blame] | 2406 | netdev_err(ndev, "Can not assign IRQ number\n"); |
Sergei Shtylyov | d2779e9 | 2013-09-04 02:41:27 +0400 | [diff] [blame] | 2407 | goto out_napi_off; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2408 | } |
| 2409 | |
| 2410 | /* Descriptor set */ |
| 2411 | ret = sh_eth_ring_init(ndev); |
| 2412 | if (ret) |
| 2413 | goto out_free_irq; |
| 2414 | |
| 2415 | /* device init */ |
Sergei Shtylyov | f796721 | 2016-04-24 19:11:07 +0300 | [diff] [blame] | 2416 | ret = sh_eth_dev_init(ndev); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2417 | if (ret) |
| 2418 | goto out_free_irq; |
| 2419 | |
| 2420 | /* PHY control start*/ |
| 2421 | ret = sh_eth_phy_start(ndev); |
| 2422 | if (ret) |
| 2423 | goto out_free_irq; |
| 2424 | |
Sergei Shtylyov | ad846aa | 2016-03-14 01:09:53 +0300 | [diff] [blame] | 2425 | netif_start_queue(ndev); |
| 2426 | |
Mitsuhiro Kimura | 7fa2955 | 2014-11-28 10:04:15 +0900 | [diff] [blame] | 2427 | mdp->is_opened = 1; |
| 2428 | |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2429 | return ret; |
| 2430 | |
| 2431 | out_free_irq: |
| 2432 | free_irq(ndev->irq, ndev); |
Sergei Shtylyov | d2779e9 | 2013-09-04 02:41:27 +0400 | [diff] [blame] | 2433 | out_napi_off: |
| 2434 | napi_disable(&mdp->napi); |
Magnus Damm | bcd5149 | 2009-10-09 00:20:04 +0000 | [diff] [blame] | 2435 | pm_runtime_put_sync(&mdp->pdev->dev); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2436 | return ret; |
| 2437 | } |
| 2438 | |
| 2439 | /* Timeout function */ |
Michael S. Tsirkin | 0290bd2 | 2019-12-10 09:23:51 -0500 | [diff] [blame] | 2440 | static void sh_eth_tx_timeout(struct net_device *ndev, unsigned int txqueue) |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2441 | { |
| 2442 | struct sh_eth_private *mdp = netdev_priv(ndev); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2443 | struct sh_eth_rxdesc *rxdesc; |
| 2444 | int i; |
| 2445 | |
| 2446 | netif_stop_queue(ndev); |
| 2447 | |
Sergei Shtylyov | 8d5009f | 2014-03-15 03:30:59 +0300 | [diff] [blame] | 2448 | netif_err(mdp, timer, ndev, |
| 2449 | "transmit timed out, status %8.8x, resetting...\n", |
Geert Uytterhoeven | 0799c2d | 2015-01-15 11:54:28 +0100 | [diff] [blame] | 2450 | sh_eth_read(ndev, EESR)); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2451 | |
| 2452 | /* tx_errors count up */ |
Eric Dumazet | bb7d92e | 2012-02-06 22:17:21 +0000 | [diff] [blame] | 2453 | ndev->stats.tx_errors++; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2454 | |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2455 | /* Free all the skbuffs in the Rx queue. */ |
Yoshihiro Shimoda | 525b807 | 2012-06-26 20:00:03 +0000 | [diff] [blame] | 2456 | for (i = 0; i < mdp->num_rx_ring; i++) { |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2457 | rxdesc = &mdp->rx_ring[i]; |
Sergei Shtylyov | 7cf7247 | 2015-12-28 02:10:47 +0300 | [diff] [blame] | 2458 | rxdesc->status = cpu_to_le32(0); |
| 2459 | rxdesc->addr = cpu_to_le32(0xBADF00D0); |
Sergei Shtylyov | 179d80a | 2014-06-28 04:10:00 +0400 | [diff] [blame] | 2460 | dev_kfree_skb(mdp->rx_skbuff[i]); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2461 | mdp->rx_skbuff[i] = NULL; |
| 2462 | } |
Yoshihiro Shimoda | 525b807 | 2012-06-26 20:00:03 +0000 | [diff] [blame] | 2463 | for (i = 0; i < mdp->num_tx_ring; i++) { |
Sergei Shtylyov | 179d80a | 2014-06-28 04:10:00 +0400 | [diff] [blame] | 2464 | dev_kfree_skb(mdp->tx_skbuff[i]); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2465 | mdp->tx_skbuff[i] = NULL; |
| 2466 | } |
| 2467 | |
| 2468 | /* device init */ |
Sergei Shtylyov | f796721 | 2016-04-24 19:11:07 +0300 | [diff] [blame] | 2469 | sh_eth_dev_init(ndev); |
Sergei Shtylyov | ad846aa | 2016-03-14 01:09:53 +0300 | [diff] [blame] | 2470 | |
| 2471 | netif_start_queue(ndev); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2472 | } |
| 2473 | |
| 2474 | /* Packet transmit function */ |
Yunjian Wang | 1f3e915 | 2020-05-06 17:25:14 +0800 | [diff] [blame] | 2475 | static netdev_tx_t sh_eth_start_xmit(struct sk_buff *skb, |
| 2476 | struct net_device *ndev) |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2477 | { |
| 2478 | struct sh_eth_private *mdp = netdev_priv(ndev); |
| 2479 | struct sh_eth_txdesc *txdesc; |
Sergei Shtylyov | 1299653 | 2015-12-13 23:05:07 +0300 | [diff] [blame] | 2480 | dma_addr_t dma_addr; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2481 | u32 entry; |
Nobuhiro Iwamatsu | fb5e2f9 | 2008-11-17 20:29:58 +0000 | [diff] [blame] | 2482 | unsigned long flags; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2483 | |
| 2484 | spin_lock_irqsave(&mdp->lock, flags); |
Yoshihiro Shimoda | 525b807 | 2012-06-26 20:00:03 +0000 | [diff] [blame] | 2485 | if ((mdp->cur_tx - mdp->dirty_tx) >= (mdp->num_tx_ring - 4)) { |
Sergei Shtylyov | 1debdc8 | 2017-04-17 15:55:22 +0300 | [diff] [blame] | 2486 | if (!sh_eth_tx_free(ndev, true)) { |
Sergei Shtylyov | 8d5009f | 2014-03-15 03:30:59 +0300 | [diff] [blame] | 2487 | netif_warn(mdp, tx_queued, ndev, "TxFD exhausted.\n"); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2488 | netif_stop_queue(ndev); |
| 2489 | spin_unlock_irqrestore(&mdp->lock, flags); |
Patrick McHardy | 5b54814 | 2009-06-12 06:22:29 +0000 | [diff] [blame] | 2490 | return NETDEV_TX_BUSY; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2491 | } |
| 2492 | } |
| 2493 | spin_unlock_irqrestore(&mdp->lock, flags); |
| 2494 | |
Ben Hutchings | dacc73e | 2015-03-03 00:53:08 +0000 | [diff] [blame] | 2495 | if (skb_put_padto(skb, ETH_ZLEN)) |
Ben Hutchings | eebfb64 | 2015-01-22 12:40:13 +0000 | [diff] [blame] | 2496 | return NETDEV_TX_OK; |
| 2497 | |
Yoshihiro Shimoda | 525b807 | 2012-06-26 20:00:03 +0000 | [diff] [blame] | 2498 | entry = mdp->cur_tx % mdp->num_tx_ring; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2499 | mdp->tx_skbuff[entry] = skb; |
| 2500 | txdesc = &mdp->tx_ring[entry]; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2501 | /* soft swap. */ |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 2502 | if (!mdp->cd->hw_swap) |
Sergei Shtylyov | 3e23099 | 2015-12-13 21:27:04 +0300 | [diff] [blame] | 2503 | sh_eth_soft_swap(PTR_ALIGN(skb->data, 4), skb->len + 2); |
Thomas Petazzoni | 22c1aed | 2017-12-04 14:33:26 +0100 | [diff] [blame] | 2504 | dma_addr = dma_map_single(&mdp->pdev->dev, skb->data, skb->len, |
Sergei Shtylyov | 1299653 | 2015-12-13 23:05:07 +0300 | [diff] [blame] | 2505 | DMA_TO_DEVICE); |
Thomas Petazzoni | 22c1aed | 2017-12-04 14:33:26 +0100 | [diff] [blame] | 2506 | if (dma_mapping_error(&mdp->pdev->dev, dma_addr)) { |
Ben Hutchings | aa3933b | 2015-01-27 00:49:47 +0000 | [diff] [blame] | 2507 | kfree_skb(skb); |
| 2508 | return NETDEV_TX_OK; |
| 2509 | } |
Sergei Shtylyov | 7cf7247 | 2015-12-28 02:10:47 +0300 | [diff] [blame] | 2510 | txdesc->addr = cpu_to_le32(dma_addr); |
| 2511 | txdesc->len = cpu_to_le32(skb->len << 16); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2512 | |
Sergei Shtylyov | f32bfb9 | 2015-11-03 22:36:04 +0300 | [diff] [blame] | 2513 | dma_wmb(); /* TACT bit must be set after all the above writes */ |
Yoshihiro Shimoda | 525b807 | 2012-06-26 20:00:03 +0000 | [diff] [blame] | 2514 | if (entry >= mdp->num_tx_ring - 1) |
Sergei Shtylyov | 7cf7247 | 2015-12-28 02:10:47 +0300 | [diff] [blame] | 2515 | txdesc->status |= cpu_to_le32(TD_TACT | TD_TDLE); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2516 | else |
Sergei Shtylyov | 7cf7247 | 2015-12-28 02:10:47 +0300 | [diff] [blame] | 2517 | txdesc->status |= cpu_to_le32(TD_TACT); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2518 | |
| 2519 | mdp->cur_tx++; |
| 2520 | |
Sergei Shtylyov | 3e41699 | 2018-03-24 23:08:42 +0300 | [diff] [blame] | 2521 | if (!(sh_eth_read(ndev, EDTRR) & mdp->cd->edtrr_trns)) |
| 2522 | sh_eth_write(ndev, mdp->cd->edtrr_trns, EDTRR); |
Nobuhiro Iwamatsu | b0ca2a2 | 2008-06-30 11:08:17 +0900 | [diff] [blame] | 2523 | |
Patrick McHardy | 6ed1065 | 2009-06-23 06:03:08 +0000 | [diff] [blame] | 2524 | return NETDEV_TX_OK; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2525 | } |
| 2526 | |
Ben Hutchings | 4398f9c | 2015-02-26 20:35:05 +0000 | [diff] [blame] | 2527 | /* The statistics registers have write-clear behaviour, which means we |
| 2528 | * will lose any increment between the read and write. We mitigate |
| 2529 | * this by only clearing when we read a non-zero value, so we will |
| 2530 | * never falsely report a total of zero. |
| 2531 | */ |
| 2532 | static void |
| 2533 | sh_eth_update_stat(struct net_device *ndev, unsigned long *stat, int reg) |
| 2534 | { |
| 2535 | u32 delta = sh_eth_read(ndev, reg); |
| 2536 | |
| 2537 | if (delta) { |
| 2538 | *stat += delta; |
| 2539 | sh_eth_write(ndev, 0, reg); |
| 2540 | } |
| 2541 | } |
| 2542 | |
Mitsuhiro Kimura | 7fa2955 | 2014-11-28 10:04:15 +0900 | [diff] [blame] | 2543 | static struct net_device_stats *sh_eth_get_stats(struct net_device *ndev) |
| 2544 | { |
| 2545 | struct sh_eth_private *mdp = netdev_priv(ndev); |
| 2546 | |
Sergei Shtylyov | ce9134d | 2018-03-24 23:11:19 +0300 | [diff] [blame] | 2547 | if (mdp->cd->no_tx_cntrs) |
Mitsuhiro Kimura | 7fa2955 | 2014-11-28 10:04:15 +0900 | [diff] [blame] | 2548 | return &ndev->stats; |
| 2549 | |
| 2550 | if (!mdp->is_opened) |
| 2551 | return &ndev->stats; |
| 2552 | |
Ben Hutchings | 4398f9c | 2015-02-26 20:35:05 +0000 | [diff] [blame] | 2553 | sh_eth_update_stat(ndev, &ndev->stats.tx_dropped, TROCR); |
| 2554 | sh_eth_update_stat(ndev, &ndev->stats.collisions, CDCR); |
| 2555 | sh_eth_update_stat(ndev, &ndev->stats.tx_carrier_errors, LCCR); |
Mitsuhiro Kimura | 7fa2955 | 2014-11-28 10:04:15 +0900 | [diff] [blame] | 2556 | |
Sergei Shtylyov | 4c1d458 | 2018-03-24 23:12:54 +0300 | [diff] [blame] | 2557 | if (mdp->cd->cexcr) { |
Ben Hutchings | 4398f9c | 2015-02-26 20:35:05 +0000 | [diff] [blame] | 2558 | sh_eth_update_stat(ndev, &ndev->stats.tx_carrier_errors, |
| 2559 | CERCR); |
| 2560 | sh_eth_update_stat(ndev, &ndev->stats.tx_carrier_errors, |
| 2561 | CEECR); |
Mitsuhiro Kimura | 7fa2955 | 2014-11-28 10:04:15 +0900 | [diff] [blame] | 2562 | } else { |
Ben Hutchings | 4398f9c | 2015-02-26 20:35:05 +0000 | [diff] [blame] | 2563 | sh_eth_update_stat(ndev, &ndev->stats.tx_carrier_errors, |
| 2564 | CNDCR); |
Mitsuhiro Kimura | 7fa2955 | 2014-11-28 10:04:15 +0900 | [diff] [blame] | 2565 | } |
| 2566 | |
| 2567 | return &ndev->stats; |
| 2568 | } |
| 2569 | |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2570 | /* device close function */ |
| 2571 | static int sh_eth_close(struct net_device *ndev) |
| 2572 | { |
| 2573 | struct sh_eth_private *mdp = netdev_priv(ndev); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2574 | |
| 2575 | netif_stop_queue(ndev); |
| 2576 | |
Ben Hutchings | 283e38d | 2015-01-22 12:44:08 +0000 | [diff] [blame] | 2577 | /* Serialise with the interrupt handler and NAPI, then disable |
| 2578 | * interrupts. We have to clear the irq_enabled flag first to |
| 2579 | * ensure that interrupts won't be re-enabled. |
| 2580 | */ |
| 2581 | mdp->irq_enabled = false; |
| 2582 | synchronize_irq(ndev->irq); |
| 2583 | napi_disable(&mdp->napi); |
Yoshihiro Shimoda | 4a55530 | 2011-03-07 21:59:26 +0000 | [diff] [blame] | 2584 | sh_eth_write(ndev, 0x0000, EESIPR); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2585 | |
Ben Hutchings | 740c7f3 | 2015-01-27 00:49:32 +0000 | [diff] [blame] | 2586 | sh_eth_dev_exit(ndev); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2587 | |
| 2588 | /* PHY Disconnect */ |
Philippe Reynes | 9fd0375 | 2016-08-10 00:04:48 +0200 | [diff] [blame] | 2589 | if (ndev->phydev) { |
| 2590 | phy_stop(ndev->phydev); |
| 2591 | phy_disconnect(ndev->phydev); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2592 | } |
| 2593 | |
| 2594 | free_irq(ndev->irq, ndev); |
| 2595 | |
Sergei Shtylyov | 8e03a5e | 2015-11-04 00:55:13 +0300 | [diff] [blame] | 2596 | /* Free all the skbuffs in the Rx queue and the DMA buffer. */ |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2597 | sh_eth_ring_free(ndev); |
| 2598 | |
Magnus Damm | bcd5149 | 2009-10-09 00:20:04 +0000 | [diff] [blame] | 2599 | pm_runtime_put_sync(&mdp->pdev->dev); |
| 2600 | |
Mitsuhiro Kimura | 7fa2955 | 2014-11-28 10:04:15 +0900 | [diff] [blame] | 2601 | mdp->is_opened = 0; |
| 2602 | |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2603 | return 0; |
| 2604 | } |
| 2605 | |
Niklas Söderlund | 78d6102 | 2017-06-12 10:39:03 +0200 | [diff] [blame] | 2606 | static int sh_eth_change_mtu(struct net_device *ndev, int new_mtu) |
| 2607 | { |
| 2608 | if (netif_running(ndev)) |
| 2609 | return -EBUSY; |
| 2610 | |
| 2611 | ndev->mtu = new_mtu; |
| 2612 | netdev_update_features(ndev); |
| 2613 | |
| 2614 | return 0; |
| 2615 | } |
| 2616 | |
Yoshihiro Shimoda | 6743fe6 | 2012-02-15 17:55:03 +0000 | [diff] [blame] | 2617 | /* For TSU_POSTn. Please refer to the manual about this (strange) bitfields */ |
Yoshihiro Shimoda | 6743fe6 | 2012-02-15 17:55:03 +0000 | [diff] [blame] | 2618 | static u32 sh_eth_tsu_get_post_mask(int entry) |
| 2619 | { |
| 2620 | return 0x0f << (28 - ((entry % 8) * 4)); |
| 2621 | } |
| 2622 | |
| 2623 | static u32 sh_eth_tsu_get_post_bit(struct sh_eth_private *mdp, int entry) |
| 2624 | { |
| 2625 | return (0x08 >> (mdp->port << 1)) << (28 - ((entry % 8) * 4)); |
| 2626 | } |
| 2627 | |
| 2628 | static void sh_eth_tsu_enable_cam_entry_post(struct net_device *ndev, |
| 2629 | int entry) |
| 2630 | { |
| 2631 | struct sh_eth_private *mdp = netdev_priv(ndev); |
Sergei Shtylyov | 77cb065 | 2018-05-02 22:54:48 +0300 | [diff] [blame] | 2632 | int reg = TSU_POST1 + entry / 8; |
Yoshihiro Shimoda | 6743fe6 | 2012-02-15 17:55:03 +0000 | [diff] [blame] | 2633 | u32 tmp; |
Yoshihiro Shimoda | 6743fe6 | 2012-02-15 17:55:03 +0000 | [diff] [blame] | 2634 | |
Sergei Shtylyov | 77cb065 | 2018-05-02 22:54:48 +0300 | [diff] [blame] | 2635 | tmp = sh_eth_tsu_read(mdp, reg); |
| 2636 | sh_eth_tsu_write(mdp, tmp | sh_eth_tsu_get_post_bit(mdp, entry), reg); |
Yoshihiro Shimoda | 6743fe6 | 2012-02-15 17:55:03 +0000 | [diff] [blame] | 2637 | } |
| 2638 | |
| 2639 | static bool sh_eth_tsu_disable_cam_entry_post(struct net_device *ndev, |
| 2640 | int entry) |
| 2641 | { |
| 2642 | struct sh_eth_private *mdp = netdev_priv(ndev); |
Sergei Shtylyov | 77cb065 | 2018-05-02 22:54:48 +0300 | [diff] [blame] | 2643 | int reg = TSU_POST1 + entry / 8; |
Yoshihiro Shimoda | 6743fe6 | 2012-02-15 17:55:03 +0000 | [diff] [blame] | 2644 | u32 post_mask, ref_mask, tmp; |
Yoshihiro Shimoda | 6743fe6 | 2012-02-15 17:55:03 +0000 | [diff] [blame] | 2645 | |
Yoshihiro Shimoda | 6743fe6 | 2012-02-15 17:55:03 +0000 | [diff] [blame] | 2646 | post_mask = sh_eth_tsu_get_post_mask(entry); |
| 2647 | ref_mask = sh_eth_tsu_get_post_bit(mdp, entry) & ~post_mask; |
| 2648 | |
Sergei Shtylyov | 77cb065 | 2018-05-02 22:54:48 +0300 | [diff] [blame] | 2649 | tmp = sh_eth_tsu_read(mdp, reg); |
| 2650 | sh_eth_tsu_write(mdp, tmp & ~post_mask, reg); |
Yoshihiro Shimoda | 6743fe6 | 2012-02-15 17:55:03 +0000 | [diff] [blame] | 2651 | |
| 2652 | /* If other port enables, the function returns "true" */ |
| 2653 | return tmp & ref_mask; |
| 2654 | } |
| 2655 | |
| 2656 | static int sh_eth_tsu_busy(struct net_device *ndev) |
| 2657 | { |
| 2658 | int timeout = SH_ETH_TSU_TIMEOUT_MS * 100; |
| 2659 | struct sh_eth_private *mdp = netdev_priv(ndev); |
| 2660 | |
| 2661 | while ((sh_eth_tsu_read(mdp, TSU_ADSBSY) & TSU_ADSBSY_0)) { |
| 2662 | udelay(10); |
| 2663 | timeout--; |
| 2664 | if (timeout <= 0) { |
Sergei Shtylyov | da24685 | 2014-03-15 03:29:14 +0300 | [diff] [blame] | 2665 | netdev_err(ndev, "%s: timeout\n", __func__); |
Yoshihiro Shimoda | 6743fe6 | 2012-02-15 17:55:03 +0000 | [diff] [blame] | 2666 | return -ETIMEDOUT; |
| 2667 | } |
| 2668 | } |
| 2669 | |
| 2670 | return 0; |
| 2671 | } |
| 2672 | |
Sergei Shtylyov | 7a54c86 | 2018-07-23 21:14:38 +0300 | [diff] [blame] | 2673 | static int sh_eth_tsu_write_entry(struct net_device *ndev, u16 offset, |
Yoshihiro Shimoda | 6743fe6 | 2012-02-15 17:55:03 +0000 | [diff] [blame] | 2674 | const u8 *addr) |
| 2675 | { |
Sergei Shtylyov | 7a54c86 | 2018-07-23 21:14:38 +0300 | [diff] [blame] | 2676 | struct sh_eth_private *mdp = netdev_priv(ndev); |
Yoshihiro Shimoda | 6743fe6 | 2012-02-15 17:55:03 +0000 | [diff] [blame] | 2677 | u32 val; |
| 2678 | |
| 2679 | val = addr[0] << 24 | addr[1] << 16 | addr[2] << 8 | addr[3]; |
Sergei Shtylyov | 7a54c86 | 2018-07-23 21:14:38 +0300 | [diff] [blame] | 2680 | iowrite32(val, mdp->tsu_addr + offset); |
Yoshihiro Shimoda | 6743fe6 | 2012-02-15 17:55:03 +0000 | [diff] [blame] | 2681 | if (sh_eth_tsu_busy(ndev) < 0) |
| 2682 | return -EBUSY; |
| 2683 | |
| 2684 | val = addr[4] << 8 | addr[5]; |
Sergei Shtylyov | 7a54c86 | 2018-07-23 21:14:38 +0300 | [diff] [blame] | 2685 | iowrite32(val, mdp->tsu_addr + offset + 4); |
Yoshihiro Shimoda | 6743fe6 | 2012-02-15 17:55:03 +0000 | [diff] [blame] | 2686 | if (sh_eth_tsu_busy(ndev) < 0) |
| 2687 | return -EBUSY; |
| 2688 | |
| 2689 | return 0; |
| 2690 | } |
| 2691 | |
Sergei Shtylyov | 51459d4 | 2018-07-23 21:15:47 +0300 | [diff] [blame] | 2692 | static void sh_eth_tsu_read_entry(struct net_device *ndev, u16 offset, u8 *addr) |
Yoshihiro Shimoda | 6743fe6 | 2012-02-15 17:55:03 +0000 | [diff] [blame] | 2693 | { |
Sergei Shtylyov | 51459d4 | 2018-07-23 21:15:47 +0300 | [diff] [blame] | 2694 | struct sh_eth_private *mdp = netdev_priv(ndev); |
Yoshihiro Shimoda | 6743fe6 | 2012-02-15 17:55:03 +0000 | [diff] [blame] | 2695 | u32 val; |
| 2696 | |
Sergei Shtylyov | 51459d4 | 2018-07-23 21:15:47 +0300 | [diff] [blame] | 2697 | val = ioread32(mdp->tsu_addr + offset); |
Yoshihiro Shimoda | 6743fe6 | 2012-02-15 17:55:03 +0000 | [diff] [blame] | 2698 | addr[0] = (val >> 24) & 0xff; |
| 2699 | addr[1] = (val >> 16) & 0xff; |
| 2700 | addr[2] = (val >> 8) & 0xff; |
| 2701 | addr[3] = val & 0xff; |
Sergei Shtylyov | 51459d4 | 2018-07-23 21:15:47 +0300 | [diff] [blame] | 2702 | val = ioread32(mdp->tsu_addr + offset + 4); |
Yoshihiro Shimoda | 6743fe6 | 2012-02-15 17:55:03 +0000 | [diff] [blame] | 2703 | addr[4] = (val >> 8) & 0xff; |
| 2704 | addr[5] = val & 0xff; |
| 2705 | } |
| 2706 | |
| 2707 | |
| 2708 | static int sh_eth_tsu_find_entry(struct net_device *ndev, const u8 *addr) |
| 2709 | { |
| 2710 | struct sh_eth_private *mdp = netdev_priv(ndev); |
Sergei Shtylyov | 41414f0 | 2018-07-23 21:11:19 +0300 | [diff] [blame] | 2711 | u16 reg_offset = sh_eth_tsu_get_offset(mdp, TSU_ADRH0); |
Yoshihiro Shimoda | 6743fe6 | 2012-02-15 17:55:03 +0000 | [diff] [blame] | 2712 | int i; |
| 2713 | u8 c_addr[ETH_ALEN]; |
| 2714 | |
| 2715 | for (i = 0; i < SH_ETH_TSU_CAM_ENTRIES; i++, reg_offset += 8) { |
Sergei Shtylyov | 51459d4 | 2018-07-23 21:15:47 +0300 | [diff] [blame] | 2716 | sh_eth_tsu_read_entry(ndev, reg_offset, c_addr); |
dingtianhong | c4bde29 | 2013-12-30 15:41:17 +0800 | [diff] [blame] | 2717 | if (ether_addr_equal(addr, c_addr)) |
Yoshihiro Shimoda | 6743fe6 | 2012-02-15 17:55:03 +0000 | [diff] [blame] | 2718 | return i; |
| 2719 | } |
| 2720 | |
| 2721 | return -ENOENT; |
| 2722 | } |
| 2723 | |
| 2724 | static int sh_eth_tsu_find_empty(struct net_device *ndev) |
| 2725 | { |
| 2726 | u8 blank[ETH_ALEN]; |
| 2727 | int entry; |
| 2728 | |
| 2729 | memset(blank, 0, sizeof(blank)); |
| 2730 | entry = sh_eth_tsu_find_entry(ndev, blank); |
| 2731 | return (entry < 0) ? -ENOMEM : entry; |
| 2732 | } |
| 2733 | |
| 2734 | static int sh_eth_tsu_disable_cam_entry_table(struct net_device *ndev, |
| 2735 | int entry) |
| 2736 | { |
| 2737 | struct sh_eth_private *mdp = netdev_priv(ndev); |
Sergei Shtylyov | 41414f0 | 2018-07-23 21:11:19 +0300 | [diff] [blame] | 2738 | u16 reg_offset = sh_eth_tsu_get_offset(mdp, TSU_ADRH0); |
Yoshihiro Shimoda | 6743fe6 | 2012-02-15 17:55:03 +0000 | [diff] [blame] | 2739 | int ret; |
| 2740 | u8 blank[ETH_ALEN]; |
| 2741 | |
| 2742 | sh_eth_tsu_write(mdp, sh_eth_tsu_read(mdp, TSU_TEN) & |
| 2743 | ~(1 << (31 - entry)), TSU_TEN); |
| 2744 | |
| 2745 | memset(blank, 0, sizeof(blank)); |
Sergei Shtylyov | 7a54c86 | 2018-07-23 21:14:38 +0300 | [diff] [blame] | 2746 | ret = sh_eth_tsu_write_entry(ndev, reg_offset + entry * 8, blank); |
Yoshihiro Shimoda | 6743fe6 | 2012-02-15 17:55:03 +0000 | [diff] [blame] | 2747 | if (ret < 0) |
| 2748 | return ret; |
| 2749 | return 0; |
| 2750 | } |
| 2751 | |
| 2752 | static int sh_eth_tsu_add_entry(struct net_device *ndev, const u8 *addr) |
| 2753 | { |
| 2754 | struct sh_eth_private *mdp = netdev_priv(ndev); |
Sergei Shtylyov | 41414f0 | 2018-07-23 21:11:19 +0300 | [diff] [blame] | 2755 | u16 reg_offset = sh_eth_tsu_get_offset(mdp, TSU_ADRH0); |
Yoshihiro Shimoda | 6743fe6 | 2012-02-15 17:55:03 +0000 | [diff] [blame] | 2756 | int i, ret; |
| 2757 | |
| 2758 | if (!mdp->cd->tsu) |
| 2759 | return 0; |
| 2760 | |
| 2761 | i = sh_eth_tsu_find_entry(ndev, addr); |
| 2762 | if (i < 0) { |
| 2763 | /* No entry found, create one */ |
| 2764 | i = sh_eth_tsu_find_empty(ndev); |
| 2765 | if (i < 0) |
| 2766 | return -ENOMEM; |
Sergei Shtylyov | 7a54c86 | 2018-07-23 21:14:38 +0300 | [diff] [blame] | 2767 | ret = sh_eth_tsu_write_entry(ndev, reg_offset + i * 8, addr); |
Yoshihiro Shimoda | 6743fe6 | 2012-02-15 17:55:03 +0000 | [diff] [blame] | 2768 | if (ret < 0) |
| 2769 | return ret; |
| 2770 | |
| 2771 | /* Enable the entry */ |
| 2772 | sh_eth_tsu_write(mdp, sh_eth_tsu_read(mdp, TSU_TEN) | |
| 2773 | (1 << (31 - i)), TSU_TEN); |
| 2774 | } |
| 2775 | |
| 2776 | /* Entry found or created, enable POST */ |
| 2777 | sh_eth_tsu_enable_cam_entry_post(ndev, i); |
| 2778 | |
| 2779 | return 0; |
| 2780 | } |
| 2781 | |
| 2782 | static int sh_eth_tsu_del_entry(struct net_device *ndev, const u8 *addr) |
| 2783 | { |
| 2784 | struct sh_eth_private *mdp = netdev_priv(ndev); |
| 2785 | int i, ret; |
| 2786 | |
| 2787 | if (!mdp->cd->tsu) |
| 2788 | return 0; |
| 2789 | |
| 2790 | i = sh_eth_tsu_find_entry(ndev, addr); |
| 2791 | if (i) { |
| 2792 | /* Entry found */ |
| 2793 | if (sh_eth_tsu_disable_cam_entry_post(ndev, i)) |
| 2794 | goto done; |
| 2795 | |
| 2796 | /* Disable the entry if both ports was disabled */ |
| 2797 | ret = sh_eth_tsu_disable_cam_entry_table(ndev, i); |
| 2798 | if (ret < 0) |
| 2799 | return ret; |
| 2800 | } |
| 2801 | done: |
| 2802 | return 0; |
| 2803 | } |
| 2804 | |
| 2805 | static int sh_eth_tsu_purge_all(struct net_device *ndev) |
| 2806 | { |
| 2807 | struct sh_eth_private *mdp = netdev_priv(ndev); |
| 2808 | int i, ret; |
| 2809 | |
Ben Hutchings | b37feed | 2015-01-16 17:51:12 +0000 | [diff] [blame] | 2810 | if (!mdp->cd->tsu) |
Yoshihiro Shimoda | 6743fe6 | 2012-02-15 17:55:03 +0000 | [diff] [blame] | 2811 | return 0; |
| 2812 | |
| 2813 | for (i = 0; i < SH_ETH_TSU_CAM_ENTRIES; i++) { |
| 2814 | if (sh_eth_tsu_disable_cam_entry_post(ndev, i)) |
| 2815 | continue; |
| 2816 | |
| 2817 | /* Disable the entry if both ports was disabled */ |
| 2818 | ret = sh_eth_tsu_disable_cam_entry_table(ndev, i); |
| 2819 | if (ret < 0) |
| 2820 | return ret; |
| 2821 | } |
| 2822 | |
| 2823 | return 0; |
| 2824 | } |
| 2825 | |
| 2826 | static void sh_eth_tsu_purge_mcast(struct net_device *ndev) |
| 2827 | { |
| 2828 | struct sh_eth_private *mdp = netdev_priv(ndev); |
Sergei Shtylyov | 41414f0 | 2018-07-23 21:11:19 +0300 | [diff] [blame] | 2829 | u16 reg_offset = sh_eth_tsu_get_offset(mdp, TSU_ADRH0); |
Yoshihiro Shimoda | 6743fe6 | 2012-02-15 17:55:03 +0000 | [diff] [blame] | 2830 | u8 addr[ETH_ALEN]; |
Yoshihiro Shimoda | 6743fe6 | 2012-02-15 17:55:03 +0000 | [diff] [blame] | 2831 | int i; |
| 2832 | |
Ben Hutchings | b37feed | 2015-01-16 17:51:12 +0000 | [diff] [blame] | 2833 | if (!mdp->cd->tsu) |
Yoshihiro Shimoda | 6743fe6 | 2012-02-15 17:55:03 +0000 | [diff] [blame] | 2834 | return; |
| 2835 | |
| 2836 | for (i = 0; i < SH_ETH_TSU_CAM_ENTRIES; i++, reg_offset += 8) { |
Sergei Shtylyov | 51459d4 | 2018-07-23 21:15:47 +0300 | [diff] [blame] | 2837 | sh_eth_tsu_read_entry(ndev, reg_offset, addr); |
Yoshihiro Shimoda | 6743fe6 | 2012-02-15 17:55:03 +0000 | [diff] [blame] | 2838 | if (is_multicast_ether_addr(addr)) |
| 2839 | sh_eth_tsu_del_entry(ndev, addr); |
| 2840 | } |
| 2841 | } |
| 2842 | |
Ben Hutchings | b37feed | 2015-01-16 17:51:12 +0000 | [diff] [blame] | 2843 | /* Update promiscuous flag and multicast filter */ |
| 2844 | static void sh_eth_set_rx_mode(struct net_device *ndev) |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2845 | { |
Yoshihiro Shimoda | 6743fe6 | 2012-02-15 17:55:03 +0000 | [diff] [blame] | 2846 | struct sh_eth_private *mdp = netdev_priv(ndev); |
| 2847 | u32 ecmr_bits; |
| 2848 | int mcast_all = 0; |
| 2849 | unsigned long flags; |
| 2850 | |
| 2851 | spin_lock_irqsave(&mdp->lock, flags); |
Sergei Shtylyov | 128296f | 2014-01-03 15:52:22 +0300 | [diff] [blame] | 2852 | /* Initial condition is MCT = 1, PRM = 0. |
Yoshihiro Shimoda | 6743fe6 | 2012-02-15 17:55:03 +0000 | [diff] [blame] | 2853 | * Depending on ndev->flags, set PRM or clear MCT |
| 2854 | */ |
Ben Hutchings | b37feed | 2015-01-16 17:51:12 +0000 | [diff] [blame] | 2855 | ecmr_bits = sh_eth_read(ndev, ECMR) & ~ECMR_PRM; |
| 2856 | if (mdp->cd->tsu) |
| 2857 | ecmr_bits |= ECMR_MCT; |
Yoshihiro Shimoda | 6743fe6 | 2012-02-15 17:55:03 +0000 | [diff] [blame] | 2858 | |
| 2859 | if (!(ndev->flags & IFF_MULTICAST)) { |
| 2860 | sh_eth_tsu_purge_mcast(ndev); |
| 2861 | mcast_all = 1; |
| 2862 | } |
| 2863 | if (ndev->flags & IFF_ALLMULTI) { |
| 2864 | sh_eth_tsu_purge_mcast(ndev); |
| 2865 | ecmr_bits &= ~ECMR_MCT; |
| 2866 | mcast_all = 1; |
| 2867 | } |
| 2868 | |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2869 | if (ndev->flags & IFF_PROMISC) { |
Yoshihiro Shimoda | 6743fe6 | 2012-02-15 17:55:03 +0000 | [diff] [blame] | 2870 | sh_eth_tsu_purge_all(ndev); |
| 2871 | ecmr_bits = (ecmr_bits & ~ECMR_MCT) | ECMR_PRM; |
| 2872 | } else if (mdp->cd->tsu) { |
| 2873 | struct netdev_hw_addr *ha; |
| 2874 | netdev_for_each_mc_addr(ha, ndev) { |
| 2875 | if (mcast_all && is_multicast_ether_addr(ha->addr)) |
| 2876 | continue; |
| 2877 | |
| 2878 | if (sh_eth_tsu_add_entry(ndev, ha->addr) < 0) { |
| 2879 | if (!mcast_all) { |
| 2880 | sh_eth_tsu_purge_mcast(ndev); |
| 2881 | ecmr_bits &= ~ECMR_MCT; |
| 2882 | mcast_all = 1; |
| 2883 | } |
| 2884 | } |
| 2885 | } |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2886 | } |
Yoshihiro Shimoda | 6743fe6 | 2012-02-15 17:55:03 +0000 | [diff] [blame] | 2887 | |
| 2888 | /* update the ethernet mode */ |
| 2889 | sh_eth_write(ndev, ecmr_bits, ECMR); |
| 2890 | |
| 2891 | spin_unlock_irqrestore(&mdp->lock, flags); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2892 | } |
Yoshihiro Shimoda | 71cc7c3 | 2012-02-15 17:55:06 +0000 | [diff] [blame] | 2893 | |
Sergei Shtylyov | f8e022d | 2019-02-04 21:06:52 +0300 | [diff] [blame] | 2894 | static void sh_eth_set_rx_csum(struct net_device *ndev, bool enable) |
| 2895 | { |
| 2896 | struct sh_eth_private *mdp = netdev_priv(ndev); |
| 2897 | unsigned long flags; |
| 2898 | |
| 2899 | spin_lock_irqsave(&mdp->lock, flags); |
| 2900 | |
| 2901 | /* Disable TX and RX */ |
| 2902 | sh_eth_rcv_snd_disable(ndev); |
| 2903 | |
| 2904 | /* Modify RX Checksum setting */ |
| 2905 | sh_eth_modify(ndev, ECMR, ECMR_RCSC, enable ? ECMR_RCSC : 0); |
| 2906 | |
| 2907 | /* Enable TX and RX */ |
| 2908 | sh_eth_rcv_snd_enable(ndev); |
| 2909 | |
| 2910 | spin_unlock_irqrestore(&mdp->lock, flags); |
| 2911 | } |
| 2912 | |
| 2913 | static int sh_eth_set_features(struct net_device *ndev, |
| 2914 | netdev_features_t features) |
| 2915 | { |
| 2916 | netdev_features_t changed = ndev->features ^ features; |
| 2917 | struct sh_eth_private *mdp = netdev_priv(ndev); |
| 2918 | |
| 2919 | if (changed & NETIF_F_RXCSUM && mdp->cd->rx_csum) |
| 2920 | sh_eth_set_rx_csum(ndev, features & NETIF_F_RXCSUM); |
| 2921 | |
| 2922 | ndev->features = features; |
| 2923 | |
| 2924 | return 0; |
| 2925 | } |
| 2926 | |
Yoshihiro Shimoda | 71cc7c3 | 2012-02-15 17:55:06 +0000 | [diff] [blame] | 2927 | static int sh_eth_get_vtag_index(struct sh_eth_private *mdp) |
| 2928 | { |
| 2929 | if (!mdp->port) |
| 2930 | return TSU_VTAG0; |
| 2931 | else |
| 2932 | return TSU_VTAG1; |
| 2933 | } |
| 2934 | |
Patrick McHardy | 80d5c36 | 2013-04-19 02:04:28 +0000 | [diff] [blame] | 2935 | static int sh_eth_vlan_rx_add_vid(struct net_device *ndev, |
| 2936 | __be16 proto, u16 vid) |
Yoshihiro Shimoda | 71cc7c3 | 2012-02-15 17:55:06 +0000 | [diff] [blame] | 2937 | { |
| 2938 | struct sh_eth_private *mdp = netdev_priv(ndev); |
| 2939 | int vtag_reg_index = sh_eth_get_vtag_index(mdp); |
| 2940 | |
| 2941 | if (unlikely(!mdp->cd->tsu)) |
| 2942 | return -EPERM; |
| 2943 | |
| 2944 | /* No filtering if vid = 0 */ |
| 2945 | if (!vid) |
| 2946 | return 0; |
| 2947 | |
| 2948 | mdp->vlan_num_ids++; |
| 2949 | |
Sergei Shtylyov | 128296f | 2014-01-03 15:52:22 +0300 | [diff] [blame] | 2950 | /* The controller has one VLAN tag HW filter. So, if the filter is |
Yoshihiro Shimoda | 71cc7c3 | 2012-02-15 17:55:06 +0000 | [diff] [blame] | 2951 | * already enabled, the driver disables it and the filte |
| 2952 | */ |
| 2953 | if (mdp->vlan_num_ids > 1) { |
| 2954 | /* disable VLAN filter */ |
| 2955 | sh_eth_tsu_write(mdp, 0, vtag_reg_index); |
| 2956 | return 0; |
| 2957 | } |
| 2958 | |
| 2959 | sh_eth_tsu_write(mdp, TSU_VTAG_ENABLE | (vid & TSU_VTAG_VID_MASK), |
| 2960 | vtag_reg_index); |
| 2961 | |
| 2962 | return 0; |
| 2963 | } |
| 2964 | |
Patrick McHardy | 80d5c36 | 2013-04-19 02:04:28 +0000 | [diff] [blame] | 2965 | static int sh_eth_vlan_rx_kill_vid(struct net_device *ndev, |
| 2966 | __be16 proto, u16 vid) |
Yoshihiro Shimoda | 71cc7c3 | 2012-02-15 17:55:06 +0000 | [diff] [blame] | 2967 | { |
| 2968 | struct sh_eth_private *mdp = netdev_priv(ndev); |
| 2969 | int vtag_reg_index = sh_eth_get_vtag_index(mdp); |
| 2970 | |
| 2971 | if (unlikely(!mdp->cd->tsu)) |
| 2972 | return -EPERM; |
| 2973 | |
| 2974 | /* No filtering if vid = 0 */ |
| 2975 | if (!vid) |
| 2976 | return 0; |
| 2977 | |
| 2978 | mdp->vlan_num_ids--; |
| 2979 | sh_eth_tsu_write(mdp, 0, vtag_reg_index); |
| 2980 | |
| 2981 | return 0; |
| 2982 | } |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2983 | |
| 2984 | /* SuperH's TSU register init function */ |
Yoshihiro Shimoda | 4a55530 | 2011-03-07 21:59:26 +0000 | [diff] [blame] | 2985 | static void sh_eth_tsu_init(struct sh_eth_private *mdp) |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2986 | { |
Sergei Shtylyov | a94cf2a | 2018-02-24 22:41:45 +0300 | [diff] [blame] | 2987 | if (!mdp->cd->dual_port) { |
Simon Horman | db89347 | 2014-01-17 09:22:28 +0900 | [diff] [blame] | 2988 | sh_eth_tsu_write(mdp, 0, TSU_TEN); /* Disable all CAM entry */ |
Chris Brandt | e148788 | 2016-09-07 14:57:09 -0400 | [diff] [blame] | 2989 | sh_eth_tsu_write(mdp, TSU_FWSLC_POSTENU | TSU_FWSLC_POSTENL, |
| 2990 | TSU_FWSLC); /* Enable POST registers */ |
Simon Horman | db89347 | 2014-01-17 09:22:28 +0900 | [diff] [blame] | 2991 | return; |
| 2992 | } |
| 2993 | |
Yoshihiro Shimoda | 4a55530 | 2011-03-07 21:59:26 +0000 | [diff] [blame] | 2994 | sh_eth_tsu_write(mdp, 0, TSU_FWEN0); /* Disable forward(0->1) */ |
| 2995 | sh_eth_tsu_write(mdp, 0, TSU_FWEN1); /* Disable forward(1->0) */ |
| 2996 | sh_eth_tsu_write(mdp, 0, TSU_FCM); /* forward fifo 3k-3k */ |
| 2997 | sh_eth_tsu_write(mdp, 0xc, TSU_BSYSL0); |
| 2998 | sh_eth_tsu_write(mdp, 0xc, TSU_BSYSL1); |
| 2999 | sh_eth_tsu_write(mdp, 0, TSU_PRISL0); |
| 3000 | sh_eth_tsu_write(mdp, 0, TSU_PRISL1); |
| 3001 | sh_eth_tsu_write(mdp, 0, TSU_FWSL0); |
| 3002 | sh_eth_tsu_write(mdp, 0, TSU_FWSL1); |
| 3003 | sh_eth_tsu_write(mdp, TSU_FWSLC_POSTENU | TSU_FWSLC_POSTENL, TSU_FWSLC); |
Sergei Shtylyov | 4869a14 | 2018-02-24 20:28:16 +0300 | [diff] [blame] | 3004 | sh_eth_tsu_write(mdp, 0, TSU_QTAGM0); /* Disable QTAG(0->1) */ |
| 3005 | sh_eth_tsu_write(mdp, 0, TSU_QTAGM1); /* Disable QTAG(1->0) */ |
Yoshihiro Shimoda | 4a55530 | 2011-03-07 21:59:26 +0000 | [diff] [blame] | 3006 | sh_eth_tsu_write(mdp, 0, TSU_FWSR); /* all interrupt status clear */ |
| 3007 | sh_eth_tsu_write(mdp, 0, TSU_FWINMK); /* Disable all interrupt */ |
| 3008 | sh_eth_tsu_write(mdp, 0, TSU_TEN); /* Disable all CAM entry */ |
| 3009 | sh_eth_tsu_write(mdp, 0, TSU_POST1); /* Disable CAM entry [ 0- 7] */ |
| 3010 | sh_eth_tsu_write(mdp, 0, TSU_POST2); /* Disable CAM entry [ 8-15] */ |
| 3011 | sh_eth_tsu_write(mdp, 0, TSU_POST3); /* Disable CAM entry [16-23] */ |
| 3012 | sh_eth_tsu_write(mdp, 0, TSU_POST4); /* Disable CAM entry [24-31] */ |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 3013 | } |
| 3014 | |
| 3015 | /* MDIO bus release function */ |
Laurent Pinchart | bd920ff | 2014-03-20 15:00:33 +0100 | [diff] [blame] | 3016 | static int sh_mdio_release(struct sh_eth_private *mdp) |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 3017 | { |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 3018 | /* unregister mdio bus */ |
Laurent Pinchart | bd920ff | 2014-03-20 15:00:33 +0100 | [diff] [blame] | 3019 | mdiobus_unregister(mdp->mii_bus); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 3020 | |
| 3021 | /* free bitbang info */ |
Laurent Pinchart | bd920ff | 2014-03-20 15:00:33 +0100 | [diff] [blame] | 3022 | free_mdio_bitbang(mdp->mii_bus); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 3023 | |
| 3024 | return 0; |
| 3025 | } |
| 3026 | |
| 3027 | /* MDIO bus init function */ |
Laurent Pinchart | bd920ff | 2014-03-20 15:00:33 +0100 | [diff] [blame] | 3028 | static int sh_mdio_init(struct sh_eth_private *mdp, |
Yoshihiro Shimoda | b3017e6 | 2011-03-07 21:59:55 +0000 | [diff] [blame] | 3029 | struct sh_eth_plat_data *pd) |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 3030 | { |
Andrew Lunn | e7f4dc3 | 2016-01-06 20:11:15 +0100 | [diff] [blame] | 3031 | int ret; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 3032 | struct bb_info *bitbang; |
Laurent Pinchart | bd920ff | 2014-03-20 15:00:33 +0100 | [diff] [blame] | 3033 | struct platform_device *pdev = mdp->pdev; |
Laurent Pinchart | aa8d422 | 2014-03-20 15:00:31 +0100 | [diff] [blame] | 3034 | struct device *dev = &mdp->pdev->dev; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 3035 | |
| 3036 | /* create bit control struct for PHY */ |
Laurent Pinchart | aa8d422 | 2014-03-20 15:00:31 +0100 | [diff] [blame] | 3037 | bitbang = devm_kzalloc(dev, sizeof(struct bb_info), GFP_KERNEL); |
Laurent Pinchart | f738a13 | 2014-03-20 15:00:35 +0100 | [diff] [blame] | 3038 | if (!bitbang) |
| 3039 | return -ENOMEM; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 3040 | |
| 3041 | /* bitbang init */ |
Yoshihiro Shimoda | ae70644 | 2011-09-27 21:48:58 +0000 | [diff] [blame] | 3042 | bitbang->addr = mdp->addr + mdp->reg_offset[PIR]; |
Yoshihiro Shimoda | b3017e6 | 2011-03-07 21:59:55 +0000 | [diff] [blame] | 3043 | bitbang->set_gate = pd->set_mdio_gate; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 3044 | bitbang->ctrl.ops = &bb_ops; |
| 3045 | |
Stefan Weil | c2e07b3 | 2010-08-03 19:44:52 +0200 | [diff] [blame] | 3046 | /* MII controller setting */ |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 3047 | mdp->mii_bus = alloc_mdio_bitbang(&bitbang->ctrl); |
Laurent Pinchart | f738a13 | 2014-03-20 15:00:35 +0100 | [diff] [blame] | 3048 | if (!mdp->mii_bus) |
| 3049 | return -ENOMEM; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 3050 | |
| 3051 | /* Hook up MII support for ethtool */ |
| 3052 | mdp->mii_bus->name = "sh_mii"; |
Laurent Pinchart | a5bd6060 | 2014-03-20 15:00:32 +0100 | [diff] [blame] | 3053 | mdp->mii_bus->parent = dev; |
Florian Fainelli | 5278fb5 | 2012-01-09 23:59:17 +0000 | [diff] [blame] | 3054 | snprintf(mdp->mii_bus->id, MII_BUS_ID_SIZE, "%s-%x", |
Laurent Pinchart | bd920ff | 2014-03-20 15:00:33 +0100 | [diff] [blame] | 3055 | pdev->name, pdev->id); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 3056 | |
Laurent Pinchart | bd920ff | 2014-03-20 15:00:33 +0100 | [diff] [blame] | 3057 | /* register MDIO bus */ |
Florian Fainelli | 00e798c | 2018-05-15 16:56:19 -0700 | [diff] [blame] | 3058 | if (pd->phy_irq > 0) |
| 3059 | mdp->mii_bus->irq[pd->phy] = pd->phy_irq; |
Ben Dooks | 702eca0 | 2014-03-12 17:47:40 +0000 | [diff] [blame] | 3060 | |
Florian Fainelli | 00e798c | 2018-05-15 16:56:19 -0700 | [diff] [blame] | 3061 | ret = of_mdiobus_register(mdp->mii_bus, dev->of_node); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 3062 | if (ret) |
Sergei Shtylyov | d5e07e6 | 2013-03-21 10:41:11 +0000 | [diff] [blame] | 3063 | goto out_free_bus; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 3064 | |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 3065 | return 0; |
| 3066 | |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 3067 | out_free_bus: |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 3068 | free_mdio_bitbang(mdp->mii_bus); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 3069 | return ret; |
| 3070 | } |
| 3071 | |
Yoshihiro Shimoda | 4a55530 | 2011-03-07 21:59:26 +0000 | [diff] [blame] | 3072 | static const u16 *sh_eth_get_register_offset(int register_type) |
| 3073 | { |
| 3074 | const u16 *reg_offset = NULL; |
| 3075 | |
| 3076 | switch (register_type) { |
| 3077 | case SH_ETH_REG_GIGABIT: |
| 3078 | reg_offset = sh_eth_offset_gigabit; |
| 3079 | break; |
Sergei Shtylyov | a3f109b | 2013-03-28 11:51:31 +0000 | [diff] [blame] | 3080 | case SH_ETH_REG_FAST_RCAR: |
| 3081 | reg_offset = sh_eth_offset_fast_rcar; |
| 3082 | break; |
Yoshihiro Shimoda | 4a55530 | 2011-03-07 21:59:26 +0000 | [diff] [blame] | 3083 | case SH_ETH_REG_FAST_SH4: |
| 3084 | reg_offset = sh_eth_offset_fast_sh4; |
| 3085 | break; |
| 3086 | case SH_ETH_REG_FAST_SH3_SH2: |
| 3087 | reg_offset = sh_eth_offset_fast_sh3_sh2; |
| 3088 | break; |
Yoshihiro Shimoda | 4a55530 | 2011-03-07 21:59:26 +0000 | [diff] [blame] | 3089 | } |
| 3090 | |
| 3091 | return reg_offset; |
| 3092 | } |
| 3093 | |
Sergei Shtylyov | 8f728d7 | 2013-06-13 00:55:34 +0400 | [diff] [blame] | 3094 | static const struct net_device_ops sh_eth_netdev_ops = { |
Alexander Beregalov | ebf84ea | 2009-04-11 07:40:49 +0000 | [diff] [blame] | 3095 | .ndo_open = sh_eth_open, |
| 3096 | .ndo_stop = sh_eth_close, |
| 3097 | .ndo_start_xmit = sh_eth_start_xmit, |
| 3098 | .ndo_get_stats = sh_eth_get_stats, |
Ben Hutchings | b37feed | 2015-01-16 17:51:12 +0000 | [diff] [blame] | 3099 | .ndo_set_rx_mode = sh_eth_set_rx_mode, |
Alexander Beregalov | ebf84ea | 2009-04-11 07:40:49 +0000 | [diff] [blame] | 3100 | .ndo_tx_timeout = sh_eth_tx_timeout, |
Heiner Kallweit | fd786fb1 | 2020-01-21 22:09:33 +0100 | [diff] [blame] | 3101 | .ndo_do_ioctl = phy_do_ioctl_running, |
Niklas Söderlund | 78d6102 | 2017-06-12 10:39:03 +0200 | [diff] [blame] | 3102 | .ndo_change_mtu = sh_eth_change_mtu, |
Alexander Beregalov | ebf84ea | 2009-04-11 07:40:49 +0000 | [diff] [blame] | 3103 | .ndo_validate_addr = eth_validate_addr, |
| 3104 | .ndo_set_mac_address = eth_mac_addr, |
Sergei Shtylyov | f8e022d | 2019-02-04 21:06:52 +0300 | [diff] [blame] | 3105 | .ndo_set_features = sh_eth_set_features, |
Alexander Beregalov | ebf84ea | 2009-04-11 07:40:49 +0000 | [diff] [blame] | 3106 | }; |
| 3107 | |
Sergei Shtylyov | 8f728d7 | 2013-06-13 00:55:34 +0400 | [diff] [blame] | 3108 | static const struct net_device_ops sh_eth_netdev_ops_tsu = { |
| 3109 | .ndo_open = sh_eth_open, |
| 3110 | .ndo_stop = sh_eth_close, |
| 3111 | .ndo_start_xmit = sh_eth_start_xmit, |
| 3112 | .ndo_get_stats = sh_eth_get_stats, |
Ben Hutchings | b37feed | 2015-01-16 17:51:12 +0000 | [diff] [blame] | 3113 | .ndo_set_rx_mode = sh_eth_set_rx_mode, |
Sergei Shtylyov | 8f728d7 | 2013-06-13 00:55:34 +0400 | [diff] [blame] | 3114 | .ndo_vlan_rx_add_vid = sh_eth_vlan_rx_add_vid, |
| 3115 | .ndo_vlan_rx_kill_vid = sh_eth_vlan_rx_kill_vid, |
| 3116 | .ndo_tx_timeout = sh_eth_tx_timeout, |
Heiner Kallweit | fd786fb1 | 2020-01-21 22:09:33 +0100 | [diff] [blame] | 3117 | .ndo_do_ioctl = phy_do_ioctl_running, |
Niklas Söderlund | 78d6102 | 2017-06-12 10:39:03 +0200 | [diff] [blame] | 3118 | .ndo_change_mtu = sh_eth_change_mtu, |
Sergei Shtylyov | 8f728d7 | 2013-06-13 00:55:34 +0400 | [diff] [blame] | 3119 | .ndo_validate_addr = eth_validate_addr, |
| 3120 | .ndo_set_mac_address = eth_mac_addr, |
Sergei Shtylyov | f8e022d | 2019-02-04 21:06:52 +0300 | [diff] [blame] | 3121 | .ndo_set_features = sh_eth_set_features, |
Sergei Shtylyov | 8f728d7 | 2013-06-13 00:55:34 +0400 | [diff] [blame] | 3122 | }; |
| 3123 | |
Sergei Shtylyov | b356e97 | 2014-02-18 03:12:43 +0300 | [diff] [blame] | 3124 | #ifdef CONFIG_OF |
| 3125 | static struct sh_eth_plat_data *sh_eth_parse_dt(struct device *dev) |
| 3126 | { |
| 3127 | struct device_node *np = dev->of_node; |
| 3128 | struct sh_eth_plat_data *pdata; |
Andrew Lunn | 0c65b2b | 2019-11-04 02:40:33 +0100 | [diff] [blame] | 3129 | phy_interface_t interface; |
Sergei Shtylyov | b356e97 | 2014-02-18 03:12:43 +0300 | [diff] [blame] | 3130 | const char *mac_addr; |
Kangjie Lu | 035a14e | 2019-03-12 02:43:18 -0500 | [diff] [blame] | 3131 | int ret; |
Sergei Shtylyov | b356e97 | 2014-02-18 03:12:43 +0300 | [diff] [blame] | 3132 | |
| 3133 | pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); |
| 3134 | if (!pdata) |
| 3135 | return NULL; |
| 3136 | |
Andrew Lunn | 0c65b2b | 2019-11-04 02:40:33 +0100 | [diff] [blame] | 3137 | ret = of_get_phy_mode(np, &interface); |
| 3138 | if (ret) |
Kangjie Lu | 035a14e | 2019-03-12 02:43:18 -0500 | [diff] [blame] | 3139 | return NULL; |
Andrew Lunn | 0c65b2b | 2019-11-04 02:40:33 +0100 | [diff] [blame] | 3140 | pdata->phy_interface = interface; |
Sergei Shtylyov | b356e97 | 2014-02-18 03:12:43 +0300 | [diff] [blame] | 3141 | |
Sergei Shtylyov | b356e97 | 2014-02-18 03:12:43 +0300 | [diff] [blame] | 3142 | mac_addr = of_get_mac_address(np); |
Petr Štetiar | a51645f | 2019-05-06 23:27:04 +0200 | [diff] [blame] | 3143 | if (!IS_ERR(mac_addr)) |
Petr Štetiar | 2d2924a | 2019-05-10 11:35:17 +0200 | [diff] [blame] | 3144 | ether_addr_copy(pdata->mac_addr, mac_addr); |
Sergei Shtylyov | b356e97 | 2014-02-18 03:12:43 +0300 | [diff] [blame] | 3145 | |
| 3146 | pdata->no_ether_link = |
| 3147 | of_property_read_bool(np, "renesas,no-ether-link"); |
| 3148 | pdata->ether_link_active_low = |
| 3149 | of_property_read_bool(np, "renesas,ether-link-active-low"); |
| 3150 | |
| 3151 | return pdata; |
| 3152 | } |
| 3153 | |
| 3154 | static const struct of_device_id sh_eth_match_table[] = { |
| 3155 | { .compatible = "renesas,gether-r8a7740", .data = &r8a7740_data }, |
Simon Horman | 6c4b2f7 | 2017-10-18 09:21:27 +0200 | [diff] [blame] | 3156 | { .compatible = "renesas,ether-r8a7743", .data = &rcar_gen2_data }, |
| 3157 | { .compatible = "renesas,ether-r8a7745", .data = &rcar_gen2_data }, |
| 3158 | { .compatible = "renesas,ether-r8a7778", .data = &rcar_gen1_data }, |
| 3159 | { .compatible = "renesas,ether-r8a7779", .data = &rcar_gen1_data }, |
| 3160 | { .compatible = "renesas,ether-r8a7790", .data = &rcar_gen2_data }, |
| 3161 | { .compatible = "renesas,ether-r8a7791", .data = &rcar_gen2_data }, |
| 3162 | { .compatible = "renesas,ether-r8a7793", .data = &rcar_gen2_data }, |
| 3163 | { .compatible = "renesas,ether-r8a7794", .data = &rcar_gen2_data }, |
Sergei Shtylyov | 3eb9c2a | 2018-05-18 21:32:46 +0300 | [diff] [blame] | 3164 | { .compatible = "renesas,gether-r8a77980", .data = &r8a77980_data }, |
Sergei Shtylyov | b356e97 | 2014-02-18 03:12:43 +0300 | [diff] [blame] | 3165 | { .compatible = "renesas,ether-r7s72100", .data = &r7s72100_data }, |
Chris Brandt | 6e0bb04 | 2018-08-27 12:42:02 -0500 | [diff] [blame] | 3166 | { .compatible = "renesas,ether-r7s9210", .data = &r7s9210_data }, |
Simon Horman | b4804e0 | 2017-10-18 09:21:28 +0200 | [diff] [blame] | 3167 | { .compatible = "renesas,rcar-gen1-ether", .data = &rcar_gen1_data }, |
| 3168 | { .compatible = "renesas,rcar-gen2-ether", .data = &rcar_gen2_data }, |
Sergei Shtylyov | b356e97 | 2014-02-18 03:12:43 +0300 | [diff] [blame] | 3169 | { } |
| 3170 | }; |
| 3171 | MODULE_DEVICE_TABLE(of, sh_eth_match_table); |
| 3172 | #else |
| 3173 | static inline struct sh_eth_plat_data *sh_eth_parse_dt(struct device *dev) |
| 3174 | { |
| 3175 | return NULL; |
| 3176 | } |
| 3177 | #endif |
| 3178 | |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 3179 | static int sh_eth_drv_probe(struct platform_device *pdev) |
| 3180 | { |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 3181 | struct resource *res; |
Jingoo Han | 0b76b86 | 2013-08-30 14:00:11 +0900 | [diff] [blame] | 3182 | struct sh_eth_plat_data *pd = dev_get_platdata(&pdev->dev); |
Sergei Shtylyov | afe391a | 2013-06-07 13:54:02 +0000 | [diff] [blame] | 3183 | const struct platform_device_id *id = platform_get_device_id(pdev); |
Sergei Shtylyov | 4fa8c3c | 2016-03-13 01:29:45 +0300 | [diff] [blame] | 3184 | struct sh_eth_private *mdp; |
| 3185 | struct net_device *ndev; |
Sergei Shtylyov | 9662ec1 | 2018-01-14 20:47:44 +0300 | [diff] [blame] | 3186 | int ret; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 3187 | |
| 3188 | /* get base addr */ |
| 3189 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 3190 | |
| 3191 | ndev = alloc_etherdev(sizeof(struct sh_eth_private)); |
Laurent Pinchart | f738a13 | 2014-03-20 15:00:35 +0100 | [diff] [blame] | 3192 | if (!ndev) |
| 3193 | return -ENOMEM; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 3194 | |
Ben Dooks | b5893a0 | 2014-03-21 12:09:14 +0100 | [diff] [blame] | 3195 | pm_runtime_enable(&pdev->dev); |
| 3196 | pm_runtime_get_sync(&pdev->dev); |
| 3197 | |
roel kluin | cc3c080 | 2008-09-10 19:22:44 +0200 | [diff] [blame] | 3198 | ret = platform_get_irq(pdev, 0); |
Sergei Shtylyov | 7a468ac | 2015-08-28 16:56:01 +0300 | [diff] [blame] | 3199 | if (ret < 0) |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 3200 | goto out_release; |
roel kluin | cc3c080 | 2008-09-10 19:22:44 +0200 | [diff] [blame] | 3201 | ndev->irq = ret; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 3202 | |
| 3203 | SET_NETDEV_DEV(ndev, &pdev->dev); |
| 3204 | |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 3205 | mdp = netdev_priv(ndev); |
Yoshihiro Shimoda | 525b807 | 2012-06-26 20:00:03 +0000 | [diff] [blame] | 3206 | mdp->num_tx_ring = TX_RING_SIZE; |
| 3207 | mdp->num_rx_ring = RX_RING_SIZE; |
Sergei Shtylyov | d5e07e6 | 2013-03-21 10:41:11 +0000 | [diff] [blame] | 3208 | mdp->addr = devm_ioremap_resource(&pdev->dev, res); |
| 3209 | if (IS_ERR(mdp->addr)) { |
| 3210 | ret = PTR_ERR(mdp->addr); |
Yoshihiro Shimoda | ae70644 | 2011-09-27 21:48:58 +0000 | [diff] [blame] | 3211 | goto out_release; |
| 3212 | } |
| 3213 | |
Varka Bhadram | c960804 | 2014-10-24 07:42:09 +0530 | [diff] [blame] | 3214 | ndev->base_addr = res->start; |
| 3215 | |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 3216 | spin_lock_init(&mdp->lock); |
Magnus Damm | bcd5149 | 2009-10-09 00:20:04 +0000 | [diff] [blame] | 3217 | mdp->pdev = pdev; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 3218 | |
Sergei Shtylyov | b356e97 | 2014-02-18 03:12:43 +0300 | [diff] [blame] | 3219 | if (pdev->dev.of_node) |
| 3220 | pd = sh_eth_parse_dt(&pdev->dev); |
Sergei Shtylyov | 3b4c5cb | 2013-10-30 23:30:19 +0300 | [diff] [blame] | 3221 | if (!pd) { |
| 3222 | dev_err(&pdev->dev, "no platform data\n"); |
| 3223 | ret = -EINVAL; |
| 3224 | goto out_release; |
| 3225 | } |
| 3226 | |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 3227 | /* get PHY ID */ |
Yoshinori Sato | 71557a3 | 2008-08-06 19:49:00 -0400 | [diff] [blame] | 3228 | mdp->phy_id = pd->phy; |
Yoshihiro Shimoda | e47c905 | 2011-03-07 21:59:45 +0000 | [diff] [blame] | 3229 | mdp->phy_interface = pd->phy_interface; |
Yoshihiro Shimoda | 4923576 | 2009-08-27 23:25:03 +0000 | [diff] [blame] | 3230 | mdp->no_ether_link = pd->no_ether_link; |
| 3231 | mdp->ether_link_active_low = pd->ether_link_active_low; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 3232 | |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 3233 | /* set cpu data */ |
Wolfram Sang | 42a67c9 | 2016-03-01 17:37:59 +0100 | [diff] [blame] | 3234 | if (id) |
Sergei Shtylyov | b356e97 | 2014-02-18 03:12:43 +0300 | [diff] [blame] | 3235 | mdp->cd = (struct sh_eth_cpu_data *)id->driver_data; |
Wolfram Sang | 42a67c9 | 2016-03-01 17:37:59 +0100 | [diff] [blame] | 3236 | else |
| 3237 | mdp->cd = (struct sh_eth_cpu_data *)of_device_get_match_data(&pdev->dev); |
Sergei Shtylyov | b356e97 | 2014-02-18 03:12:43 +0300 | [diff] [blame] | 3238 | |
Sergei Shtylyov | a3153d8 | 2013-08-18 03:11:28 +0400 | [diff] [blame] | 3239 | mdp->reg_offset = sh_eth_get_register_offset(mdp->cd->register_type); |
Sergei Shtylyov | 264be2f | 2014-03-15 03:11:24 +0300 | [diff] [blame] | 3240 | if (!mdp->reg_offset) { |
| 3241 | dev_err(&pdev->dev, "Unknown register type (%d)\n", |
| 3242 | mdp->cd->register_type); |
| 3243 | ret = -EINVAL; |
| 3244 | goto out_release; |
| 3245 | } |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 3246 | sh_eth_set_default_cpu_data(mdp->cd); |
| 3247 | |
Niklas Söderlund | 78d6102 | 2017-06-12 10:39:03 +0200 | [diff] [blame] | 3248 | /* User's manual states max MTU should be 2048 but due to the |
| 3249 | * alignment calculations in sh_eth_ring_init() the practical |
| 3250 | * MTU is a bit less. Maybe this can be optimized some more. |
| 3251 | */ |
| 3252 | ndev->max_mtu = 2000 - (ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN); |
| 3253 | ndev->min_mtu = ETH_MIN_MTU; |
| 3254 | |
Sergei Shtylyov | f8e022d | 2019-02-04 21:06:52 +0300 | [diff] [blame] | 3255 | if (mdp->cd->rx_csum) { |
| 3256 | ndev->features = NETIF_F_RXCSUM; |
| 3257 | ndev->hw_features = NETIF_F_RXCSUM; |
| 3258 | } |
| 3259 | |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 3260 | /* set function */ |
Sergei Shtylyov | 8f728d7 | 2013-06-13 00:55:34 +0400 | [diff] [blame] | 3261 | if (mdp->cd->tsu) |
| 3262 | ndev->netdev_ops = &sh_eth_netdev_ops_tsu; |
| 3263 | else |
| 3264 | ndev->netdev_ops = &sh_eth_netdev_ops; |
Wilfried Klaebe | 7ad24ea | 2014-05-11 00:12:32 +0000 | [diff] [blame] | 3265 | ndev->ethtool_ops = &sh_eth_ethtool_ops; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 3266 | ndev->watchdog_timeo = TX_TIMEOUT; |
| 3267 | |
Nobuhiro Iwamatsu | dc19e4e | 2011-02-15 21:17:32 +0000 | [diff] [blame] | 3268 | /* debug message level */ |
| 3269 | mdp->msg_enable = SH_ETH_DEF_MSG_ENABLE; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 3270 | |
| 3271 | /* read and set MAC address */ |
Magnus Damm | 748031f | 2009-10-09 00:17:14 +0000 | [diff] [blame] | 3272 | read_mac_address(ndev, pd->mac_addr); |
Sergei Shtylyov | ff6e722 | 2013-04-29 09:49:42 +0000 | [diff] [blame] | 3273 | if (!is_valid_ether_addr(ndev->dev_addr)) { |
| 3274 | dev_warn(&pdev->dev, |
| 3275 | "no valid MAC address supplied, using a random one.\n"); |
| 3276 | eth_hw_addr_random(ndev); |
| 3277 | } |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 3278 | |
Yoshihiro Shimoda | 6ba8802 | 2012-02-15 17:55:01 +0000 | [diff] [blame] | 3279 | if (mdp->cd->tsu) { |
Sergei Shtylyov | 9662ec1 | 2018-01-14 20:47:44 +0300 | [diff] [blame] | 3280 | int port = pdev->id < 0 ? 0 : pdev->id % 2; |
Yoshihiro Shimoda | 6ba8802 | 2012-02-15 17:55:01 +0000 | [diff] [blame] | 3281 | struct resource *rtsu; |
Sergei Shtylyov | dfe8266 | 2018-01-03 20:09:49 +0300 | [diff] [blame] | 3282 | |
Yoshihiro Shimoda | 6ba8802 | 2012-02-15 17:55:01 +0000 | [diff] [blame] | 3283 | rtsu = platform_get_resource(pdev, IORESOURCE_MEM, 1); |
Sergei Shtylyov | dfe8266 | 2018-01-03 20:09:49 +0300 | [diff] [blame] | 3284 | if (!rtsu) { |
| 3285 | dev_err(&pdev->dev, "no TSU resource\n"); |
| 3286 | ret = -ENODEV; |
| 3287 | goto out_release; |
| 3288 | } |
| 3289 | /* We can only request the TSU region for the first port |
| 3290 | * of the two sharing this TSU for the probe to succeed... |
| 3291 | */ |
Sergei Shtylyov | 9662ec1 | 2018-01-14 20:47:44 +0300 | [diff] [blame] | 3292 | if (port == 0 && |
Sergei Shtylyov | dfe8266 | 2018-01-03 20:09:49 +0300 | [diff] [blame] | 3293 | !devm_request_mem_region(&pdev->dev, rtsu->start, |
| 3294 | resource_size(rtsu), |
| 3295 | dev_name(&pdev->dev))) { |
| 3296 | dev_err(&pdev->dev, "can't request TSU resource.\n"); |
| 3297 | ret = -EBUSY; |
| 3298 | goto out_release; |
| 3299 | } |
Sergei Shtylyov | 3e14c96 | 2018-01-14 20:47:43 +0300 | [diff] [blame] | 3300 | /* ioremap the TSU registers */ |
Sergei Shtylyov | dfe8266 | 2018-01-03 20:09:49 +0300 | [diff] [blame] | 3301 | mdp->tsu_addr = devm_ioremap(&pdev->dev, rtsu->start, |
| 3302 | resource_size(rtsu)); |
| 3303 | if (!mdp->tsu_addr) { |
| 3304 | dev_err(&pdev->dev, "TSU region ioremap() failed.\n"); |
| 3305 | ret = -ENOMEM; |
Sergei Shtylyov | fc0c090 | 2013-03-19 13:41:32 +0000 | [diff] [blame] | 3306 | goto out_release; |
| 3307 | } |
Sergei Shtylyov | 9662ec1 | 2018-01-14 20:47:44 +0300 | [diff] [blame] | 3308 | mdp->port = port; |
Sergei Shtylyov | f8e022d | 2019-02-04 21:06:52 +0300 | [diff] [blame] | 3309 | ndev->features |= NETIF_F_HW_VLAN_CTAG_FILTER; |
Yoshihiro Shimoda | 6ba8802 | 2012-02-15 17:55:01 +0000 | [diff] [blame] | 3310 | |
Sergei Shtylyov | 3e14c96 | 2018-01-14 20:47:43 +0300 | [diff] [blame] | 3311 | /* Need to init only the first port of the two sharing a TSU */ |
Sergei Shtylyov | 9662ec1 | 2018-01-14 20:47:44 +0300 | [diff] [blame] | 3312 | if (port == 0) { |
Sergei Shtylyov | 3e14c96 | 2018-01-14 20:47:43 +0300 | [diff] [blame] | 3313 | if (mdp->cd->chip_reset) |
| 3314 | mdp->cd->chip_reset(ndev); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 3315 | |
Yoshihiro Shimoda | 4986b99 | 2011-03-07 21:59:34 +0000 | [diff] [blame] | 3316 | /* TSU init (Init only)*/ |
| 3317 | sh_eth_tsu_init(mdp); |
| 3318 | } |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 3319 | } |
| 3320 | |
Hisashi Nakamura | 966d6db | 2014-11-13 15:54:05 +0900 | [diff] [blame] | 3321 | if (mdp->cd->rmiimode) |
| 3322 | sh_eth_write(ndev, 0x1, RMIIMODE); |
| 3323 | |
Laurent Pinchart | daacf03 | 2014-03-20 15:00:34 +0100 | [diff] [blame] | 3324 | /* MDIO bus init */ |
| 3325 | ret = sh_mdio_init(mdp, pd); |
| 3326 | if (ret) { |
Geert Uytterhoeven | b7ce520 | 2017-05-18 15:01:35 +0200 | [diff] [blame] | 3327 | if (ret != -EPROBE_DEFER) |
| 3328 | dev_err(&pdev->dev, "MDIO init failed: %d\n", ret); |
Laurent Pinchart | daacf03 | 2014-03-20 15:00:34 +0100 | [diff] [blame] | 3329 | goto out_release; |
| 3330 | } |
| 3331 | |
Sergei Shtylyov | 3719109 | 2013-06-19 23:30:23 +0400 | [diff] [blame] | 3332 | netif_napi_add(ndev, &mdp->napi, sh_eth_poll, 64); |
| 3333 | |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 3334 | /* network device register */ |
| 3335 | ret = register_netdev(ndev); |
| 3336 | if (ret) |
Sergei Shtylyov | 3719109 | 2013-06-19 23:30:23 +0400 | [diff] [blame] | 3337 | goto out_napi_del; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 3338 | |
Geert Uytterhoeven | b4580c9 | 2018-02-12 14:42:36 +0100 | [diff] [blame] | 3339 | if (mdp->cd->magic) |
Niklas Söderlund | d8981d0 | 2017-01-09 16:34:05 +0100 | [diff] [blame] | 3340 | device_set_wakeup_capable(&pdev->dev, 1); |
| 3341 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3342 | /* print device information */ |
Sergei Shtylyov | f75f14e | 2014-03-15 03:27:54 +0300 | [diff] [blame] | 3343 | netdev_info(ndev, "Base address at 0x%x, %pM, IRQ %d.\n", |
| 3344 | (u32)ndev->base_addr, ndev->dev_addr, ndev->irq); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 3345 | |
Ben Dooks | b5893a0 | 2014-03-21 12:09:14 +0100 | [diff] [blame] | 3346 | pm_runtime_put(&pdev->dev); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 3347 | platform_set_drvdata(pdev, ndev); |
| 3348 | |
| 3349 | return ret; |
| 3350 | |
Sergei Shtylyov | 3719109 | 2013-06-19 23:30:23 +0400 | [diff] [blame] | 3351 | out_napi_del: |
| 3352 | netif_napi_del(&mdp->napi); |
Laurent Pinchart | daacf03 | 2014-03-20 15:00:34 +0100 | [diff] [blame] | 3353 | sh_mdio_release(mdp); |
Sergei Shtylyov | 3719109 | 2013-06-19 23:30:23 +0400 | [diff] [blame] | 3354 | |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 3355 | out_release: |
| 3356 | /* net_dev free */ |
Sergei Shtylyov | 4282fc4 | 2017-12-31 21:41:36 +0300 | [diff] [blame] | 3357 | free_netdev(ndev); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 3358 | |
Ben Dooks | b5893a0 | 2014-03-21 12:09:14 +0100 | [diff] [blame] | 3359 | pm_runtime_put(&pdev->dev); |
| 3360 | pm_runtime_disable(&pdev->dev); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 3361 | return ret; |
| 3362 | } |
| 3363 | |
| 3364 | static int sh_eth_drv_remove(struct platform_device *pdev) |
| 3365 | { |
| 3366 | struct net_device *ndev = platform_get_drvdata(pdev); |
Sergei Shtylyov | 3719109 | 2013-06-19 23:30:23 +0400 | [diff] [blame] | 3367 | struct sh_eth_private *mdp = netdev_priv(ndev); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 3368 | |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 3369 | unregister_netdev(ndev); |
Sergei Shtylyov | 3719109 | 2013-06-19 23:30:23 +0400 | [diff] [blame] | 3370 | netif_napi_del(&mdp->napi); |
Laurent Pinchart | daacf03 | 2014-03-20 15:00:34 +0100 | [diff] [blame] | 3371 | sh_mdio_release(mdp); |
Magnus Damm | bcd5149 | 2009-10-09 00:20:04 +0000 | [diff] [blame] | 3372 | pm_runtime_disable(&pdev->dev); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 3373 | free_netdev(ndev); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 3374 | |
| 3375 | return 0; |
| 3376 | } |
| 3377 | |
Nobuhiro Iwamatsu | 540ad1b | 2013-06-06 09:52:37 +0000 | [diff] [blame] | 3378 | #ifdef CONFIG_PM |
Mikhail Ulyanov | b71af04 | 2015-01-22 01:19:48 +0300 | [diff] [blame] | 3379 | #ifdef CONFIG_PM_SLEEP |
Niklas Söderlund | d8981d0 | 2017-01-09 16:34:05 +0100 | [diff] [blame] | 3380 | static int sh_eth_wol_setup(struct net_device *ndev) |
| 3381 | { |
| 3382 | struct sh_eth_private *mdp = netdev_priv(ndev); |
| 3383 | |
| 3384 | /* Only allow ECI interrupts */ |
| 3385 | synchronize_irq(ndev->irq); |
| 3386 | napi_disable(&mdp->napi); |
Sergei Shtylyov | 1a0bee6 | 2017-01-29 15:07:34 +0300 | [diff] [blame] | 3387 | sh_eth_write(ndev, EESIPR_ECIIP, EESIPR); |
Niklas Söderlund | d8981d0 | 2017-01-09 16:34:05 +0100 | [diff] [blame] | 3388 | |
| 3389 | /* Enable MagicPacket */ |
Niklas Söderlund | 5e2ed13 | 2017-02-01 15:41:54 +0100 | [diff] [blame] | 3390 | sh_eth_modify(ndev, ECMR, ECMR_MPDE, ECMR_MPDE); |
Niklas Söderlund | d8981d0 | 2017-01-09 16:34:05 +0100 | [diff] [blame] | 3391 | |
Niklas Söderlund | d8981d0 | 2017-01-09 16:34:05 +0100 | [diff] [blame] | 3392 | return enable_irq_wake(ndev->irq); |
| 3393 | } |
| 3394 | |
| 3395 | static int sh_eth_wol_restore(struct net_device *ndev) |
| 3396 | { |
| 3397 | struct sh_eth_private *mdp = netdev_priv(ndev); |
| 3398 | int ret; |
| 3399 | |
| 3400 | napi_enable(&mdp->napi); |
| 3401 | |
| 3402 | /* Disable MagicPacket */ |
| 3403 | sh_eth_modify(ndev, ECMR, ECMR_MPDE, 0); |
| 3404 | |
| 3405 | /* The device needs to be reset to restore MagicPacket logic |
| 3406 | * for next wakeup. If we close and open the device it will |
| 3407 | * both be reset and all registers restored. This is what |
| 3408 | * happens during suspend and resume without WoL enabled. |
| 3409 | */ |
| 3410 | ret = sh_eth_close(ndev); |
| 3411 | if (ret < 0) |
| 3412 | return ret; |
| 3413 | ret = sh_eth_open(ndev); |
| 3414 | if (ret < 0) |
| 3415 | return ret; |
| 3416 | |
Niklas Söderlund | d8981d0 | 2017-01-09 16:34:05 +0100 | [diff] [blame] | 3417 | return disable_irq_wake(ndev->irq); |
| 3418 | } |
| 3419 | |
Mikhail Ulyanov | b71af04 | 2015-01-22 01:19:48 +0300 | [diff] [blame] | 3420 | static int sh_eth_suspend(struct device *dev) |
| 3421 | { |
| 3422 | struct net_device *ndev = dev_get_drvdata(dev); |
Niklas Söderlund | d8981d0 | 2017-01-09 16:34:05 +0100 | [diff] [blame] | 3423 | struct sh_eth_private *mdp = netdev_priv(ndev); |
Mikhail Ulyanov | b71af04 | 2015-01-22 01:19:48 +0300 | [diff] [blame] | 3424 | int ret = 0; |
| 3425 | |
Niklas Söderlund | d8981d0 | 2017-01-09 16:34:05 +0100 | [diff] [blame] | 3426 | if (!netif_running(ndev)) |
| 3427 | return 0; |
| 3428 | |
| 3429 | netif_device_detach(ndev); |
| 3430 | |
| 3431 | if (mdp->wol_enabled) |
| 3432 | ret = sh_eth_wol_setup(ndev); |
| 3433 | else |
Mikhail Ulyanov | b71af04 | 2015-01-22 01:19:48 +0300 | [diff] [blame] | 3434 | ret = sh_eth_close(ndev); |
Mikhail Ulyanov | b71af04 | 2015-01-22 01:19:48 +0300 | [diff] [blame] | 3435 | |
| 3436 | return ret; |
| 3437 | } |
| 3438 | |
| 3439 | static int sh_eth_resume(struct device *dev) |
| 3440 | { |
| 3441 | struct net_device *ndev = dev_get_drvdata(dev); |
Niklas Söderlund | d8981d0 | 2017-01-09 16:34:05 +0100 | [diff] [blame] | 3442 | struct sh_eth_private *mdp = netdev_priv(ndev); |
Mikhail Ulyanov | b71af04 | 2015-01-22 01:19:48 +0300 | [diff] [blame] | 3443 | int ret = 0; |
| 3444 | |
Niklas Söderlund | d8981d0 | 2017-01-09 16:34:05 +0100 | [diff] [blame] | 3445 | if (!netif_running(ndev)) |
| 3446 | return 0; |
| 3447 | |
| 3448 | if (mdp->wol_enabled) |
| 3449 | ret = sh_eth_wol_restore(ndev); |
| 3450 | else |
Mikhail Ulyanov | b71af04 | 2015-01-22 01:19:48 +0300 | [diff] [blame] | 3451 | ret = sh_eth_open(ndev); |
Niklas Söderlund | d8981d0 | 2017-01-09 16:34:05 +0100 | [diff] [blame] | 3452 | |
| 3453 | if (ret < 0) |
| 3454 | return ret; |
| 3455 | |
| 3456 | netif_device_attach(ndev); |
Mikhail Ulyanov | b71af04 | 2015-01-22 01:19:48 +0300 | [diff] [blame] | 3457 | |
| 3458 | return ret; |
| 3459 | } |
| 3460 | #endif |
| 3461 | |
Magnus Damm | bcd5149 | 2009-10-09 00:20:04 +0000 | [diff] [blame] | 3462 | static int sh_eth_runtime_nop(struct device *dev) |
| 3463 | { |
Sergei Shtylyov | 128296f | 2014-01-03 15:52:22 +0300 | [diff] [blame] | 3464 | /* Runtime PM callback shared between ->runtime_suspend() |
Magnus Damm | bcd5149 | 2009-10-09 00:20:04 +0000 | [diff] [blame] | 3465 | * and ->runtime_resume(). Simply returns success. |
| 3466 | * |
| 3467 | * This driver re-initializes all registers after |
| 3468 | * pm_runtime_get_sync() anyway so there is no need |
| 3469 | * to save and restore registers here. |
| 3470 | */ |
| 3471 | return 0; |
| 3472 | } |
| 3473 | |
Nobuhiro Iwamatsu | 540ad1b | 2013-06-06 09:52:37 +0000 | [diff] [blame] | 3474 | static const struct dev_pm_ops sh_eth_dev_pm_ops = { |
Mikhail Ulyanov | b71af04 | 2015-01-22 01:19:48 +0300 | [diff] [blame] | 3475 | SET_SYSTEM_SLEEP_PM_OPS(sh_eth_suspend, sh_eth_resume) |
Mikhail Ulyanov | e7d7e89 | 2015-01-22 01:18:44 +0300 | [diff] [blame] | 3476 | SET_RUNTIME_PM_OPS(sh_eth_runtime_nop, sh_eth_runtime_nop, NULL) |
Magnus Damm | bcd5149 | 2009-10-09 00:20:04 +0000 | [diff] [blame] | 3477 | }; |
Nobuhiro Iwamatsu | 540ad1b | 2013-06-06 09:52:37 +0000 | [diff] [blame] | 3478 | #define SH_ETH_PM_OPS (&sh_eth_dev_pm_ops) |
| 3479 | #else |
| 3480 | #define SH_ETH_PM_OPS NULL |
| 3481 | #endif |
Magnus Damm | bcd5149 | 2009-10-09 00:20:04 +0000 | [diff] [blame] | 3482 | |
Arvind Yadav | ef00df8 | 2017-08-13 16:42:42 +0530 | [diff] [blame] | 3483 | static const struct platform_device_id sh_eth_id_table[] = { |
Sergei Shtylyov | c18a79a | 2013-06-07 13:56:05 +0000 | [diff] [blame] | 3484 | { "sh7619-ether", (kernel_ulong_t)&sh7619_data }, |
Sergei Shtylyov | 7bbe150 | 2013-06-07 13:55:08 +0000 | [diff] [blame] | 3485 | { "sh771x-ether", (kernel_ulong_t)&sh771x_data }, |
Sergei Shtylyov | 9c3beaa | 2013-06-07 14:03:37 +0000 | [diff] [blame] | 3486 | { "sh7724-ether", (kernel_ulong_t)&sh7724_data }, |
Sergei Shtylyov | f5d1276 | 2013-06-07 13:58:18 +0000 | [diff] [blame] | 3487 | { "sh7734-gether", (kernel_ulong_t)&sh7734_data }, |
Sergei Shtylyov | 24549e2 | 2013-06-07 13:59:21 +0000 | [diff] [blame] | 3488 | { "sh7757-ether", (kernel_ulong_t)&sh7757_data }, |
| 3489 | { "sh7757-gether", (kernel_ulong_t)&sh7757_data_giga }, |
Sergei Shtylyov | f5d1276 | 2013-06-07 13:58:18 +0000 | [diff] [blame] | 3490 | { "sh7763-gether", (kernel_ulong_t)&sh7763_data }, |
Sergei Shtylyov | afe391a | 2013-06-07 13:54:02 +0000 | [diff] [blame] | 3491 | { } |
| 3492 | }; |
| 3493 | MODULE_DEVICE_TABLE(platform, sh_eth_id_table); |
| 3494 | |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 3495 | static struct platform_driver sh_eth_driver = { |
| 3496 | .probe = sh_eth_drv_probe, |
| 3497 | .remove = sh_eth_drv_remove, |
Sergei Shtylyov | afe391a | 2013-06-07 13:54:02 +0000 | [diff] [blame] | 3498 | .id_table = sh_eth_id_table, |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 3499 | .driver = { |
| 3500 | .name = CARDNAME, |
Nobuhiro Iwamatsu | 540ad1b | 2013-06-06 09:52:37 +0000 | [diff] [blame] | 3501 | .pm = SH_ETH_PM_OPS, |
Sergei Shtylyov | b356e97 | 2014-02-18 03:12:43 +0300 | [diff] [blame] | 3502 | .of_match_table = of_match_ptr(sh_eth_match_table), |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 3503 | }, |
| 3504 | }; |
| 3505 | |
Axel Lin | db62f68 | 2011-11-27 16:44:17 +0000 | [diff] [blame] | 3506 | module_platform_driver(sh_eth_driver); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 3507 | |
| 3508 | MODULE_AUTHOR("Nobuhiro Iwamatsu, Yoshihiro Shimoda"); |
| 3509 | MODULE_DESCRIPTION("Renesas SuperH Ethernet driver"); |
| 3510 | MODULE_LICENSE("GPL v2"); |