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