Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1 | /* |
| 2 | * SuperH Ethernet device driver |
| 3 | * |
Nobuhiro Iwamatsu | f0e81fe | 2012-03-25 18:59:51 +0000 | [diff] [blame] | 4 | * Copyright (C) 2006-2012 Nobuhiro Iwamatsu |
Sergei Shtylyov | a3f109b | 2013-03-28 11:51:31 +0000 | [diff] [blame] | 5 | * Copyright (C) 2008-2013 Renesas Solutions Corp. |
| 6 | * Copyright (C) 2013 Cogent Embedded, Inc. |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify it |
| 9 | * under the terms and conditions of the GNU General Public License, |
| 10 | * version 2, as published by the Free Software Foundation. |
| 11 | * |
| 12 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 14 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 15 | * more details. |
| 16 | * You should have received a copy of the GNU General Public License along with |
| 17 | * this program; if not, write to the Free Software Foundation, Inc., |
| 18 | * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. |
| 19 | * |
| 20 | * The full GNU General Public License is included in this distribution in |
| 21 | * the file called "COPYING". |
| 22 | */ |
| 23 | |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 24 | #include <linux/init.h> |
Yoshihiro Shimoda | 0654011 | 2011-09-29 17:16:57 +0000 | [diff] [blame] | 25 | #include <linux/module.h> |
| 26 | #include <linux/kernel.h> |
| 27 | #include <linux/spinlock.h> |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 28 | #include <linux/interrupt.h> |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 29 | #include <linux/dma-mapping.h> |
| 30 | #include <linux/etherdevice.h> |
| 31 | #include <linux/delay.h> |
| 32 | #include <linux/platform_device.h> |
| 33 | #include <linux/mdio-bitbang.h> |
| 34 | #include <linux/netdevice.h> |
| 35 | #include <linux/phy.h> |
| 36 | #include <linux/cache.h> |
| 37 | #include <linux/io.h> |
Magnus Damm | bcd5149 | 2009-10-09 00:20:04 +0000 | [diff] [blame] | 38 | #include <linux/pm_runtime.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 39 | #include <linux/slab.h> |
Nobuhiro Iwamatsu | dc19e4e | 2011-02-15 21:17:32 +0000 | [diff] [blame] | 40 | #include <linux/ethtool.h> |
Yoshihiro Shimoda | fdb37a7 | 2012-02-06 23:55:15 +0000 | [diff] [blame] | 41 | #include <linux/if_vlan.h> |
Nobuhiro Iwamatsu | f0e81fe | 2012-03-25 18:59:51 +0000 | [diff] [blame] | 42 | #include <linux/clk.h> |
Yoshihiro Shimoda | d4fa0e3 | 2011-09-27 21:49:12 +0000 | [diff] [blame] | 43 | #include <linux/sh_eth.h> |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 44 | |
| 45 | #include "sh_eth.h" |
| 46 | |
Nobuhiro Iwamatsu | dc19e4e | 2011-02-15 21:17:32 +0000 | [diff] [blame] | 47 | #define SH_ETH_DEF_MSG_ENABLE \ |
| 48 | (NETIF_MSG_LINK | \ |
| 49 | NETIF_MSG_TIMER | \ |
| 50 | NETIF_MSG_RX_ERR| \ |
| 51 | NETIF_MSG_TX_ERR) |
| 52 | |
Sergei Shtylyov | c0013f6 | 2013-03-28 11:48:26 +0000 | [diff] [blame] | 53 | static const u16 sh_eth_offset_gigabit[SH_ETH_MAX_REGISTER_OFFSET] = { |
| 54 | [EDSR] = 0x0000, |
| 55 | [EDMR] = 0x0400, |
| 56 | [EDTRR] = 0x0408, |
| 57 | [EDRRR] = 0x0410, |
| 58 | [EESR] = 0x0428, |
| 59 | [EESIPR] = 0x0430, |
| 60 | [TDLAR] = 0x0010, |
| 61 | [TDFAR] = 0x0014, |
| 62 | [TDFXR] = 0x0018, |
| 63 | [TDFFR] = 0x001c, |
| 64 | [RDLAR] = 0x0030, |
| 65 | [RDFAR] = 0x0034, |
| 66 | [RDFXR] = 0x0038, |
| 67 | [RDFFR] = 0x003c, |
| 68 | [TRSCER] = 0x0438, |
| 69 | [RMFCR] = 0x0440, |
| 70 | [TFTR] = 0x0448, |
| 71 | [FDR] = 0x0450, |
| 72 | [RMCR] = 0x0458, |
| 73 | [RPADIR] = 0x0460, |
| 74 | [FCFTR] = 0x0468, |
| 75 | [CSMR] = 0x04E4, |
| 76 | |
| 77 | [ECMR] = 0x0500, |
| 78 | [ECSR] = 0x0510, |
| 79 | [ECSIPR] = 0x0518, |
| 80 | [PIR] = 0x0520, |
| 81 | [PSR] = 0x0528, |
| 82 | [PIPR] = 0x052c, |
| 83 | [RFLR] = 0x0508, |
| 84 | [APR] = 0x0554, |
| 85 | [MPR] = 0x0558, |
| 86 | [PFTCR] = 0x055c, |
| 87 | [PFRCR] = 0x0560, |
| 88 | [TPAUSER] = 0x0564, |
| 89 | [GECMR] = 0x05b0, |
| 90 | [BCULR] = 0x05b4, |
| 91 | [MAHR] = 0x05c0, |
| 92 | [MALR] = 0x05c8, |
| 93 | [TROCR] = 0x0700, |
| 94 | [CDCR] = 0x0708, |
| 95 | [LCCR] = 0x0710, |
| 96 | [CEFCR] = 0x0740, |
| 97 | [FRECR] = 0x0748, |
| 98 | [TSFRCR] = 0x0750, |
| 99 | [TLFRCR] = 0x0758, |
| 100 | [RFCR] = 0x0760, |
| 101 | [CERCR] = 0x0768, |
| 102 | [CEECR] = 0x0770, |
| 103 | [MAFCR] = 0x0778, |
| 104 | [RMII_MII] = 0x0790, |
| 105 | |
| 106 | [ARSTR] = 0x0000, |
| 107 | [TSU_CTRST] = 0x0004, |
| 108 | [TSU_FWEN0] = 0x0010, |
| 109 | [TSU_FWEN1] = 0x0014, |
| 110 | [TSU_FCM] = 0x0018, |
| 111 | [TSU_BSYSL0] = 0x0020, |
| 112 | [TSU_BSYSL1] = 0x0024, |
| 113 | [TSU_PRISL0] = 0x0028, |
| 114 | [TSU_PRISL1] = 0x002c, |
| 115 | [TSU_FWSL0] = 0x0030, |
| 116 | [TSU_FWSL1] = 0x0034, |
| 117 | [TSU_FWSLC] = 0x0038, |
| 118 | [TSU_QTAG0] = 0x0040, |
| 119 | [TSU_QTAG1] = 0x0044, |
| 120 | [TSU_FWSR] = 0x0050, |
| 121 | [TSU_FWINMK] = 0x0054, |
| 122 | [TSU_ADQT0] = 0x0048, |
| 123 | [TSU_ADQT1] = 0x004c, |
| 124 | [TSU_VTAG0] = 0x0058, |
| 125 | [TSU_VTAG1] = 0x005c, |
| 126 | [TSU_ADSBSY] = 0x0060, |
| 127 | [TSU_TEN] = 0x0064, |
| 128 | [TSU_POST1] = 0x0070, |
| 129 | [TSU_POST2] = 0x0074, |
| 130 | [TSU_POST3] = 0x0078, |
| 131 | [TSU_POST4] = 0x007c, |
| 132 | [TSU_ADRH0] = 0x0100, |
| 133 | [TSU_ADRL0] = 0x0104, |
| 134 | [TSU_ADRH31] = 0x01f8, |
| 135 | [TSU_ADRL31] = 0x01fc, |
| 136 | |
| 137 | [TXNLCR0] = 0x0080, |
| 138 | [TXALCR0] = 0x0084, |
| 139 | [RXNLCR0] = 0x0088, |
| 140 | [RXALCR0] = 0x008c, |
| 141 | [FWNLCR0] = 0x0090, |
| 142 | [FWALCR0] = 0x0094, |
| 143 | [TXNLCR1] = 0x00a0, |
| 144 | [TXALCR1] = 0x00a0, |
| 145 | [RXNLCR1] = 0x00a8, |
| 146 | [RXALCR1] = 0x00ac, |
| 147 | [FWNLCR1] = 0x00b0, |
| 148 | [FWALCR1] = 0x00b4, |
| 149 | }; |
| 150 | |
Sergei Shtylyov | a3f109b | 2013-03-28 11:51:31 +0000 | [diff] [blame] | 151 | static const u16 sh_eth_offset_fast_rcar[SH_ETH_MAX_REGISTER_OFFSET] = { |
| 152 | [ECMR] = 0x0300, |
| 153 | [RFLR] = 0x0308, |
| 154 | [ECSR] = 0x0310, |
| 155 | [ECSIPR] = 0x0318, |
| 156 | [PIR] = 0x0320, |
| 157 | [PSR] = 0x0328, |
| 158 | [RDMLR] = 0x0340, |
| 159 | [IPGR] = 0x0350, |
| 160 | [APR] = 0x0354, |
| 161 | [MPR] = 0x0358, |
| 162 | [RFCF] = 0x0360, |
| 163 | [TPAUSER] = 0x0364, |
| 164 | [TPAUSECR] = 0x0368, |
| 165 | [MAHR] = 0x03c0, |
| 166 | [MALR] = 0x03c8, |
| 167 | [TROCR] = 0x03d0, |
| 168 | [CDCR] = 0x03d4, |
| 169 | [LCCR] = 0x03d8, |
| 170 | [CNDCR] = 0x03dc, |
| 171 | [CEFCR] = 0x03e4, |
| 172 | [FRECR] = 0x03e8, |
| 173 | [TSFRCR] = 0x03ec, |
| 174 | [TLFRCR] = 0x03f0, |
| 175 | [RFCR] = 0x03f4, |
| 176 | [MAFCR] = 0x03f8, |
| 177 | |
| 178 | [EDMR] = 0x0200, |
| 179 | [EDTRR] = 0x0208, |
| 180 | [EDRRR] = 0x0210, |
| 181 | [TDLAR] = 0x0218, |
| 182 | [RDLAR] = 0x0220, |
| 183 | [EESR] = 0x0228, |
| 184 | [EESIPR] = 0x0230, |
| 185 | [TRSCER] = 0x0238, |
| 186 | [RMFCR] = 0x0240, |
| 187 | [TFTR] = 0x0248, |
| 188 | [FDR] = 0x0250, |
| 189 | [RMCR] = 0x0258, |
| 190 | [TFUCR] = 0x0264, |
| 191 | [RFOCR] = 0x0268, |
| 192 | [FCFTR] = 0x0270, |
| 193 | [TRIMD] = 0x027c, |
| 194 | }; |
| 195 | |
Sergei Shtylyov | c0013f6 | 2013-03-28 11:48:26 +0000 | [diff] [blame] | 196 | static const u16 sh_eth_offset_fast_sh4[SH_ETH_MAX_REGISTER_OFFSET] = { |
| 197 | [ECMR] = 0x0100, |
| 198 | [RFLR] = 0x0108, |
| 199 | [ECSR] = 0x0110, |
| 200 | [ECSIPR] = 0x0118, |
| 201 | [PIR] = 0x0120, |
| 202 | [PSR] = 0x0128, |
| 203 | [RDMLR] = 0x0140, |
| 204 | [IPGR] = 0x0150, |
| 205 | [APR] = 0x0154, |
| 206 | [MPR] = 0x0158, |
| 207 | [TPAUSER] = 0x0164, |
| 208 | [RFCF] = 0x0160, |
| 209 | [TPAUSECR] = 0x0168, |
| 210 | [BCFRR] = 0x016c, |
| 211 | [MAHR] = 0x01c0, |
| 212 | [MALR] = 0x01c8, |
| 213 | [TROCR] = 0x01d0, |
| 214 | [CDCR] = 0x01d4, |
| 215 | [LCCR] = 0x01d8, |
| 216 | [CNDCR] = 0x01dc, |
| 217 | [CEFCR] = 0x01e4, |
| 218 | [FRECR] = 0x01e8, |
| 219 | [TSFRCR] = 0x01ec, |
| 220 | [TLFRCR] = 0x01f0, |
| 221 | [RFCR] = 0x01f4, |
| 222 | [MAFCR] = 0x01f8, |
| 223 | [RTRATE] = 0x01fc, |
| 224 | |
| 225 | [EDMR] = 0x0000, |
| 226 | [EDTRR] = 0x0008, |
| 227 | [EDRRR] = 0x0010, |
| 228 | [TDLAR] = 0x0018, |
| 229 | [RDLAR] = 0x0020, |
| 230 | [EESR] = 0x0028, |
| 231 | [EESIPR] = 0x0030, |
| 232 | [TRSCER] = 0x0038, |
| 233 | [RMFCR] = 0x0040, |
| 234 | [TFTR] = 0x0048, |
| 235 | [FDR] = 0x0050, |
| 236 | [RMCR] = 0x0058, |
| 237 | [TFUCR] = 0x0064, |
| 238 | [RFOCR] = 0x0068, |
| 239 | [FCFTR] = 0x0070, |
| 240 | [RPADIR] = 0x0078, |
| 241 | [TRIMD] = 0x007c, |
| 242 | [RBWAR] = 0x00c8, |
| 243 | [RDFAR] = 0x00cc, |
| 244 | [TBRAR] = 0x00d4, |
| 245 | [TDFAR] = 0x00d8, |
| 246 | }; |
| 247 | |
| 248 | static const u16 sh_eth_offset_fast_sh3_sh2[SH_ETH_MAX_REGISTER_OFFSET] = { |
| 249 | [ECMR] = 0x0160, |
| 250 | [ECSR] = 0x0164, |
| 251 | [ECSIPR] = 0x0168, |
| 252 | [PIR] = 0x016c, |
| 253 | [MAHR] = 0x0170, |
| 254 | [MALR] = 0x0174, |
| 255 | [RFLR] = 0x0178, |
| 256 | [PSR] = 0x017c, |
| 257 | [TROCR] = 0x0180, |
| 258 | [CDCR] = 0x0184, |
| 259 | [LCCR] = 0x0188, |
| 260 | [CNDCR] = 0x018c, |
| 261 | [CEFCR] = 0x0194, |
| 262 | [FRECR] = 0x0198, |
| 263 | [TSFRCR] = 0x019c, |
| 264 | [TLFRCR] = 0x01a0, |
| 265 | [RFCR] = 0x01a4, |
| 266 | [MAFCR] = 0x01a8, |
| 267 | [IPGR] = 0x01b4, |
| 268 | [APR] = 0x01b8, |
| 269 | [MPR] = 0x01bc, |
| 270 | [TPAUSER] = 0x01c4, |
| 271 | [BCFR] = 0x01cc, |
| 272 | |
| 273 | [ARSTR] = 0x0000, |
| 274 | [TSU_CTRST] = 0x0004, |
| 275 | [TSU_FWEN0] = 0x0010, |
| 276 | [TSU_FWEN1] = 0x0014, |
| 277 | [TSU_FCM] = 0x0018, |
| 278 | [TSU_BSYSL0] = 0x0020, |
| 279 | [TSU_BSYSL1] = 0x0024, |
| 280 | [TSU_PRISL0] = 0x0028, |
| 281 | [TSU_PRISL1] = 0x002c, |
| 282 | [TSU_FWSL0] = 0x0030, |
| 283 | [TSU_FWSL1] = 0x0034, |
| 284 | [TSU_FWSLC] = 0x0038, |
| 285 | [TSU_QTAGM0] = 0x0040, |
| 286 | [TSU_QTAGM1] = 0x0044, |
| 287 | [TSU_ADQT0] = 0x0048, |
| 288 | [TSU_ADQT1] = 0x004c, |
| 289 | [TSU_FWSR] = 0x0050, |
| 290 | [TSU_FWINMK] = 0x0054, |
| 291 | [TSU_ADSBSY] = 0x0060, |
| 292 | [TSU_TEN] = 0x0064, |
| 293 | [TSU_POST1] = 0x0070, |
| 294 | [TSU_POST2] = 0x0074, |
| 295 | [TSU_POST3] = 0x0078, |
| 296 | [TSU_POST4] = 0x007c, |
| 297 | |
| 298 | [TXNLCR0] = 0x0080, |
| 299 | [TXALCR0] = 0x0084, |
| 300 | [RXNLCR0] = 0x0088, |
| 301 | [RXALCR0] = 0x008c, |
| 302 | [FWNLCR0] = 0x0090, |
| 303 | [FWALCR0] = 0x0094, |
| 304 | [TXNLCR1] = 0x00a0, |
| 305 | [TXALCR1] = 0x00a0, |
| 306 | [RXNLCR1] = 0x00a8, |
| 307 | [RXALCR1] = 0x00ac, |
| 308 | [FWNLCR1] = 0x00b0, |
| 309 | [FWALCR1] = 0x00b4, |
| 310 | |
| 311 | [TSU_ADRH0] = 0x0100, |
| 312 | [TSU_ADRL0] = 0x0104, |
| 313 | [TSU_ADRL31] = 0x01fc, |
| 314 | }; |
| 315 | |
Nobuhiro Iwamatsu | b7feacf | 2013-06-06 09:50:30 +0000 | [diff] [blame^] | 316 | static void __maybe_unused sh_eth_select_mii(struct net_device *ndev) |
Nobuhiro Iwamatsu | 5e7a76b | 2012-06-25 17:34:14 +0000 | [diff] [blame] | 317 | { |
| 318 | u32 value = 0x0; |
| 319 | struct sh_eth_private *mdp = netdev_priv(ndev); |
| 320 | |
| 321 | switch (mdp->phy_interface) { |
| 322 | case PHY_INTERFACE_MODE_GMII: |
| 323 | value = 0x2; |
| 324 | break; |
| 325 | case PHY_INTERFACE_MODE_MII: |
| 326 | value = 0x1; |
| 327 | break; |
| 328 | case PHY_INTERFACE_MODE_RMII: |
| 329 | value = 0x0; |
| 330 | break; |
| 331 | default: |
| 332 | pr_warn("PHY interface mode was not setup. Set to MII.\n"); |
| 333 | value = 0x1; |
| 334 | break; |
| 335 | } |
| 336 | |
| 337 | sh_eth_write(ndev, value, RMII_MII); |
| 338 | } |
Nobuhiro Iwamatsu | 5e7a76b | 2012-06-25 17:34:14 +0000 | [diff] [blame] | 339 | |
Nobuhiro Iwamatsu | 04b0ed2 | 2013-06-06 09:45:25 +0000 | [diff] [blame] | 340 | static void __maybe_unused sh_eth_set_duplex(struct net_device *ndev) |
Yoshihiro Shimoda | 65ac885 | 2009-05-24 23:54:30 +0000 | [diff] [blame] | 341 | { |
| 342 | struct sh_eth_private *mdp = netdev_priv(ndev); |
Yoshihiro Shimoda | 65ac885 | 2009-05-24 23:54:30 +0000 | [diff] [blame] | 343 | |
| 344 | if (mdp->duplex) /* Full */ |
Yoshihiro Shimoda | 4a55530 | 2011-03-07 21:59:26 +0000 | [diff] [blame] | 345 | sh_eth_write(ndev, sh_eth_read(ndev, ECMR) | ECMR_DM, ECMR); |
Yoshihiro Shimoda | 65ac885 | 2009-05-24 23:54:30 +0000 | [diff] [blame] | 346 | else /* Half */ |
Yoshihiro Shimoda | 4a55530 | 2011-03-07 21:59:26 +0000 | [diff] [blame] | 347 | sh_eth_write(ndev, sh_eth_read(ndev, ECMR) & ~ECMR_DM, ECMR); |
Yoshihiro Shimoda | 65ac885 | 2009-05-24 23:54:30 +0000 | [diff] [blame] | 348 | } |
| 349 | |
Nobuhiro Iwamatsu | 04b0ed2 | 2013-06-06 09:45:25 +0000 | [diff] [blame] | 350 | /* There is CPU dependent code */ |
| 351 | #if defined(CONFIG_ARCH_R8A7778) || defined(CONFIG_ARCH_R8A7779) |
| 352 | #define SH_ETH_RESET_DEFAULT 1 |
Yoshihiro Shimoda | 65ac885 | 2009-05-24 23:54:30 +0000 | [diff] [blame] | 353 | static void sh_eth_set_rate(struct net_device *ndev) |
| 354 | { |
| 355 | struct sh_eth_private *mdp = netdev_priv(ndev); |
Yoshihiro Shimoda | 65ac885 | 2009-05-24 23:54:30 +0000 | [diff] [blame] | 356 | |
| 357 | switch (mdp->speed) { |
| 358 | case 10: /* 10BASE */ |
Sergei Shtylyov | a3f109b | 2013-03-28 11:51:31 +0000 | [diff] [blame] | 359 | sh_eth_write(ndev, sh_eth_read(ndev, ECMR) & ~ECMR_ELB, ECMR); |
Yoshihiro Shimoda | 65ac885 | 2009-05-24 23:54:30 +0000 | [diff] [blame] | 360 | break; |
| 361 | case 100:/* 100BASE */ |
Sergei Shtylyov | a3f109b | 2013-03-28 11:51:31 +0000 | [diff] [blame] | 362 | sh_eth_write(ndev, sh_eth_read(ndev, ECMR) | ECMR_ELB, ECMR); |
| 363 | break; |
| 364 | default: |
| 365 | break; |
| 366 | } |
| 367 | } |
| 368 | |
Sergei Shtylyov | 674853b | 2013-04-27 10:44:24 +0000 | [diff] [blame] | 369 | /* R8A7778/9 */ |
Sergei Shtylyov | a3f109b | 2013-03-28 11:51:31 +0000 | [diff] [blame] | 370 | static struct sh_eth_cpu_data sh_eth_my_cpu_data = { |
| 371 | .set_duplex = sh_eth_set_duplex, |
| 372 | .set_rate = sh_eth_set_rate, |
| 373 | |
| 374 | .ecsr_value = ECSR_PSRTO | ECSR_LCHNG | ECSR_ICD, |
| 375 | .ecsipr_value = ECSIPR_PSRTOIP | ECSIPR_LCHNGIP | ECSIPR_ICDIP, |
| 376 | .eesipr_value = 0x01ff009f, |
| 377 | |
| 378 | .tx_check = EESR_FTC | EESR_CND | EESR_DLC | EESR_CD | EESR_RTO, |
| 379 | .eesr_err_check = EESR_TWB | EESR_TABT | EESR_RABT | EESR_RDE | |
| 380 | EESR_RFRMER | EESR_TFE | EESR_TDE | EESR_ECI, |
| 381 | .tx_error_check = EESR_TWB | EESR_TABT | EESR_TDE | EESR_TFE, |
| 382 | |
| 383 | .apr = 1, |
| 384 | .mpr = 1, |
| 385 | .tpauser = 1, |
| 386 | .hw_swap = 1, |
| 387 | }; |
| 388 | #elif defined(CONFIG_CPU_SUBTYPE_SH7724) |
| 389 | #define SH_ETH_RESET_DEFAULT 1 |
Sergei Shtylyov | a3f109b | 2013-03-28 11:51:31 +0000 | [diff] [blame] | 390 | |
| 391 | static void sh_eth_set_rate(struct net_device *ndev) |
| 392 | { |
| 393 | struct sh_eth_private *mdp = netdev_priv(ndev); |
| 394 | |
| 395 | switch (mdp->speed) { |
| 396 | case 10: /* 10BASE */ |
| 397 | sh_eth_write(ndev, sh_eth_read(ndev, ECMR) & ~ECMR_RTM, ECMR); |
| 398 | break; |
| 399 | case 100:/* 100BASE */ |
| 400 | sh_eth_write(ndev, sh_eth_read(ndev, ECMR) | ECMR_RTM, ECMR); |
Yoshihiro Shimoda | 65ac885 | 2009-05-24 23:54:30 +0000 | [diff] [blame] | 401 | break; |
| 402 | default: |
| 403 | break; |
| 404 | } |
| 405 | } |
| 406 | |
| 407 | /* SH7724 */ |
| 408 | static struct sh_eth_cpu_data sh_eth_my_cpu_data = { |
| 409 | .set_duplex = sh_eth_set_duplex, |
| 410 | .set_rate = sh_eth_set_rate, |
| 411 | |
| 412 | .ecsr_value = ECSR_PSRTO | ECSR_LCHNG | ECSR_ICD, |
| 413 | .ecsipr_value = ECSIPR_PSRTOIP | ECSIPR_LCHNGIP | ECSIPR_ICDIP, |
| 414 | .eesipr_value = DMAC_M_RFRMER | DMAC_M_ECI | 0x01ff009f, |
| 415 | |
| 416 | .tx_check = EESR_FTC | EESR_CND | EESR_DLC | EESR_CD | EESR_RTO, |
| 417 | .eesr_err_check = EESR_TWB | EESR_TABT | EESR_RABT | EESR_RDE | |
| 418 | EESR_RFRMER | EESR_TFE | EESR_TDE | EESR_ECI, |
| 419 | .tx_error_check = EESR_TWB | EESR_TABT | EESR_TDE | EESR_TFE, |
| 420 | |
| 421 | .apr = 1, |
| 422 | .mpr = 1, |
| 423 | .tpauser = 1, |
| 424 | .hw_swap = 1, |
Magnus Damm | 503914c | 2009-12-15 21:16:55 -0800 | [diff] [blame] | 425 | .rpadir = 1, |
| 426 | .rpadir_value = 0x00020000, /* NET_IP_ALIGN assumed to be 2 */ |
Yoshihiro Shimoda | 65ac885 | 2009-05-24 23:54:30 +0000 | [diff] [blame] | 427 | }; |
Yoshihiro Shimoda | f29a3d0 | 2010-07-05 18:32:50 +0000 | [diff] [blame] | 428 | #elif defined(CONFIG_CPU_SUBTYPE_SH7757) |
Yoshihiro Shimoda | 8fcd496 | 2011-03-07 21:59:49 +0000 | [diff] [blame] | 429 | #define SH_ETH_HAS_BOTH_MODULES 1 |
Nobuhiro Iwamatsu | 5cee1d3 | 2012-06-25 17:35:12 +0000 | [diff] [blame] | 430 | static int sh_eth_check_reset(struct net_device *ndev); |
| 431 | |
Yoshihiro Shimoda | f29a3d0 | 2010-07-05 18:32:50 +0000 | [diff] [blame] | 432 | static void sh_eth_set_rate(struct net_device *ndev) |
| 433 | { |
| 434 | struct sh_eth_private *mdp = netdev_priv(ndev); |
Yoshihiro Shimoda | f29a3d0 | 2010-07-05 18:32:50 +0000 | [diff] [blame] | 435 | |
| 436 | switch (mdp->speed) { |
| 437 | case 10: /* 10BASE */ |
Yoshihiro Shimoda | 4a55530 | 2011-03-07 21:59:26 +0000 | [diff] [blame] | 438 | sh_eth_write(ndev, 0, RTRATE); |
Yoshihiro Shimoda | f29a3d0 | 2010-07-05 18:32:50 +0000 | [diff] [blame] | 439 | break; |
| 440 | case 100:/* 100BASE */ |
Yoshihiro Shimoda | 4a55530 | 2011-03-07 21:59:26 +0000 | [diff] [blame] | 441 | sh_eth_write(ndev, 1, RTRATE); |
Yoshihiro Shimoda | f29a3d0 | 2010-07-05 18:32:50 +0000 | [diff] [blame] | 442 | break; |
| 443 | default: |
| 444 | break; |
| 445 | } |
| 446 | } |
| 447 | |
| 448 | /* SH7757 */ |
| 449 | static struct sh_eth_cpu_data sh_eth_my_cpu_data = { |
| 450 | .set_duplex = sh_eth_set_duplex, |
| 451 | .set_rate = sh_eth_set_rate, |
| 452 | |
| 453 | .eesipr_value = DMAC_M_RFRMER | DMAC_M_ECI | 0x003fffff, |
| 454 | .rmcr_value = 0x00000001, |
| 455 | |
| 456 | .tx_check = EESR_FTC | EESR_CND | EESR_DLC | EESR_CD | EESR_RTO, |
| 457 | .eesr_err_check = EESR_TWB | EESR_TABT | EESR_RABT | EESR_RDE | |
| 458 | EESR_RFRMER | EESR_TFE | EESR_TDE | EESR_ECI, |
| 459 | .tx_error_check = EESR_TWB | EESR_TABT | EESR_TDE | EESR_TFE, |
| 460 | |
Nobuhiro Iwamatsu | 5b3dfd1 | 2013-06-06 09:49:30 +0000 | [diff] [blame] | 461 | .irq_flags = IRQF_SHARED, |
Yoshihiro Shimoda | f29a3d0 | 2010-07-05 18:32:50 +0000 | [diff] [blame] | 462 | .apr = 1, |
| 463 | .mpr = 1, |
| 464 | .tpauser = 1, |
| 465 | .hw_swap = 1, |
| 466 | .no_ade = 1, |
Yoshihiro Shimoda | 2e98e79 | 2011-07-05 20:33:57 +0000 | [diff] [blame] | 467 | .rpadir = 1, |
| 468 | .rpadir_value = 2 << 16, |
Yoshihiro Shimoda | f29a3d0 | 2010-07-05 18:32:50 +0000 | [diff] [blame] | 469 | }; |
Yoshihiro Shimoda | 65ac885 | 2009-05-24 23:54:30 +0000 | [diff] [blame] | 470 | |
Yoshihiro Shimoda | 8fcd496 | 2011-03-07 21:59:49 +0000 | [diff] [blame] | 471 | #define SH_GIGA_ETH_BASE 0xfee00000 |
| 472 | #define GIGA_MALR(port) (SH_GIGA_ETH_BASE + 0x800 * (port) + 0x05c8) |
| 473 | #define GIGA_MAHR(port) (SH_GIGA_ETH_BASE + 0x800 * (port) + 0x05c0) |
| 474 | static void sh_eth_chip_reset_giga(struct net_device *ndev) |
| 475 | { |
| 476 | int i; |
| 477 | unsigned long mahr[2], malr[2]; |
| 478 | |
| 479 | /* save MAHR and MALR */ |
| 480 | for (i = 0; i < 2; i++) { |
Yoshihiro Shimoda | ae70644 | 2011-09-27 21:48:58 +0000 | [diff] [blame] | 481 | malr[i] = ioread32((void *)GIGA_MALR(i)); |
| 482 | mahr[i] = ioread32((void *)GIGA_MAHR(i)); |
Yoshihiro Shimoda | 8fcd496 | 2011-03-07 21:59:49 +0000 | [diff] [blame] | 483 | } |
| 484 | |
| 485 | /* reset device */ |
Yoshihiro Shimoda | ae70644 | 2011-09-27 21:48:58 +0000 | [diff] [blame] | 486 | iowrite32(ARSTR_ARSTR, (void *)(SH_GIGA_ETH_BASE + 0x1800)); |
Yoshihiro Shimoda | 8fcd496 | 2011-03-07 21:59:49 +0000 | [diff] [blame] | 487 | mdelay(1); |
| 488 | |
| 489 | /* restore MAHR and MALR */ |
| 490 | for (i = 0; i < 2; i++) { |
Yoshihiro Shimoda | ae70644 | 2011-09-27 21:48:58 +0000 | [diff] [blame] | 491 | iowrite32(malr[i], (void *)GIGA_MALR(i)); |
| 492 | iowrite32(mahr[i], (void *)GIGA_MAHR(i)); |
Yoshihiro Shimoda | 8fcd496 | 2011-03-07 21:59:49 +0000 | [diff] [blame] | 493 | } |
| 494 | } |
| 495 | |
| 496 | static int sh_eth_is_gether(struct sh_eth_private *mdp); |
Nobuhiro Iwamatsu | 5cee1d3 | 2012-06-25 17:35:12 +0000 | [diff] [blame] | 497 | static int sh_eth_reset(struct net_device *ndev) |
Yoshihiro Shimoda | 8fcd496 | 2011-03-07 21:59:49 +0000 | [diff] [blame] | 498 | { |
| 499 | struct sh_eth_private *mdp = netdev_priv(ndev); |
Nobuhiro Iwamatsu | 5cee1d3 | 2012-06-25 17:35:12 +0000 | [diff] [blame] | 500 | int ret = 0; |
Yoshihiro Shimoda | 8fcd496 | 2011-03-07 21:59:49 +0000 | [diff] [blame] | 501 | |
| 502 | if (sh_eth_is_gether(mdp)) { |
Nobuhiro Iwamatsu | ddcd91c | 2013-06-06 09:44:27 +0000 | [diff] [blame] | 503 | sh_eth_write(ndev, EDSR_ENALL, EDSR); |
Yoshihiro Shimoda | 8fcd496 | 2011-03-07 21:59:49 +0000 | [diff] [blame] | 504 | sh_eth_write(ndev, sh_eth_read(ndev, EDMR) | EDMR_SRST_GETHER, |
| 505 | EDMR); |
Nobuhiro Iwamatsu | 5cee1d3 | 2012-06-25 17:35:12 +0000 | [diff] [blame] | 506 | |
| 507 | ret = sh_eth_check_reset(ndev); |
| 508 | if (ret) |
| 509 | goto out; |
Yoshihiro Shimoda | 8fcd496 | 2011-03-07 21:59:49 +0000 | [diff] [blame] | 510 | |
| 511 | /* Table Init */ |
| 512 | sh_eth_write(ndev, 0x0, TDLAR); |
| 513 | sh_eth_write(ndev, 0x0, TDFAR); |
| 514 | sh_eth_write(ndev, 0x0, TDFXR); |
| 515 | sh_eth_write(ndev, 0x0, TDFFR); |
| 516 | sh_eth_write(ndev, 0x0, RDLAR); |
| 517 | sh_eth_write(ndev, 0x0, RDFAR); |
| 518 | sh_eth_write(ndev, 0x0, RDFXR); |
| 519 | sh_eth_write(ndev, 0x0, RDFFR); |
| 520 | } else { |
| 521 | sh_eth_write(ndev, sh_eth_read(ndev, EDMR) | EDMR_SRST_ETHER, |
| 522 | EDMR); |
| 523 | mdelay(3); |
| 524 | sh_eth_write(ndev, sh_eth_read(ndev, EDMR) & ~EDMR_SRST_ETHER, |
| 525 | EDMR); |
| 526 | } |
Nobuhiro Iwamatsu | 5cee1d3 | 2012-06-25 17:35:12 +0000 | [diff] [blame] | 527 | |
| 528 | out: |
| 529 | return ret; |
Yoshihiro Shimoda | 8fcd496 | 2011-03-07 21:59:49 +0000 | [diff] [blame] | 530 | } |
| 531 | |
Yoshihiro Shimoda | 8fcd496 | 2011-03-07 21:59:49 +0000 | [diff] [blame] | 532 | static void sh_eth_set_rate_giga(struct net_device *ndev) |
| 533 | { |
| 534 | struct sh_eth_private *mdp = netdev_priv(ndev); |
| 535 | |
| 536 | switch (mdp->speed) { |
| 537 | case 10: /* 10BASE */ |
| 538 | sh_eth_write(ndev, 0x00000000, GECMR); |
| 539 | break; |
| 540 | case 100:/* 100BASE */ |
| 541 | sh_eth_write(ndev, 0x00000010, GECMR); |
| 542 | break; |
| 543 | case 1000: /* 1000BASE */ |
| 544 | sh_eth_write(ndev, 0x00000020, GECMR); |
| 545 | break; |
| 546 | default: |
| 547 | break; |
| 548 | } |
| 549 | } |
| 550 | |
| 551 | /* SH7757(GETHERC) */ |
| 552 | static struct sh_eth_cpu_data sh_eth_my_cpu_data_giga = { |
| 553 | .chip_reset = sh_eth_chip_reset_giga, |
Nobuhiro Iwamatsu | 04b0ed2 | 2013-06-06 09:45:25 +0000 | [diff] [blame] | 554 | .set_duplex = sh_eth_set_duplex, |
Yoshihiro Shimoda | 8fcd496 | 2011-03-07 21:59:49 +0000 | [diff] [blame] | 555 | .set_rate = sh_eth_set_rate_giga, |
| 556 | |
| 557 | .ecsr_value = ECSR_ICD | ECSR_MPD, |
| 558 | .ecsipr_value = ECSIPR_LCHNGIP | ECSIPR_ICDIP | ECSIPR_MPDIP, |
| 559 | .eesipr_value = DMAC_M_RFRMER | DMAC_M_ECI | 0x003fffff, |
| 560 | |
| 561 | .tx_check = EESR_TC1 | EESR_FTC, |
| 562 | .eesr_err_check = EESR_TWB1 | EESR_TWB | EESR_TABT | EESR_RABT | \ |
| 563 | EESR_RDE | EESR_RFRMER | EESR_TFE | EESR_TDE | \ |
| 564 | EESR_ECI, |
| 565 | .tx_error_check = EESR_TWB1 | EESR_TWB | EESR_TABT | EESR_TDE | \ |
| 566 | EESR_TFE, |
| 567 | .fdr_value = 0x0000072f, |
| 568 | .rmcr_value = 0x00000001, |
| 569 | |
Nobuhiro Iwamatsu | 5b3dfd1 | 2013-06-06 09:49:30 +0000 | [diff] [blame] | 570 | .irq_flags = IRQF_SHARED, |
Yoshihiro Shimoda | 8fcd496 | 2011-03-07 21:59:49 +0000 | [diff] [blame] | 571 | .apr = 1, |
| 572 | .mpr = 1, |
| 573 | .tpauser = 1, |
| 574 | .bculr = 1, |
| 575 | .hw_swap = 1, |
| 576 | .rpadir = 1, |
| 577 | .rpadir_value = 2 << 16, |
| 578 | .no_trimd = 1, |
| 579 | .no_ade = 1, |
Yoshihiro Shimoda | 3acbc97 | 2012-02-15 17:54:51 +0000 | [diff] [blame] | 580 | .tsu = 1, |
Yoshihiro Shimoda | 8fcd496 | 2011-03-07 21:59:49 +0000 | [diff] [blame] | 581 | }; |
| 582 | |
| 583 | static struct sh_eth_cpu_data *sh_eth_get_cpu_data(struct sh_eth_private *mdp) |
| 584 | { |
| 585 | if (sh_eth_is_gether(mdp)) |
| 586 | return &sh_eth_my_cpu_data_giga; |
| 587 | else |
| 588 | return &sh_eth_my_cpu_data; |
| 589 | } |
| 590 | |
Nobuhiro Iwamatsu | f0e81fe | 2012-03-25 18:59:51 +0000 | [diff] [blame] | 591 | #elif defined(CONFIG_CPU_SUBTYPE_SH7734) || defined(CONFIG_CPU_SUBTYPE_SH7763) |
Nobuhiro Iwamatsu | 5cee1d3 | 2012-06-25 17:35:12 +0000 | [diff] [blame] | 592 | static int sh_eth_check_reset(struct net_device *ndev); |
Nobuhiro Iwamatsu | f0e81fe | 2012-03-25 18:59:51 +0000 | [diff] [blame] | 593 | static void sh_eth_reset_hw_crc(struct net_device *ndev); |
Nobuhiro Iwamatsu | 5e7a76b | 2012-06-25 17:34:14 +0000 | [diff] [blame] | 594 | |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 595 | static void sh_eth_chip_reset(struct net_device *ndev) |
| 596 | { |
Yoshihiro Shimoda | 4986b99 | 2011-03-07 21:59:34 +0000 | [diff] [blame] | 597 | struct sh_eth_private *mdp = netdev_priv(ndev); |
| 598 | |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 599 | /* reset device */ |
Yoshihiro Shimoda | 4986b99 | 2011-03-07 21:59:34 +0000 | [diff] [blame] | 600 | sh_eth_tsu_write(mdp, ARSTR_ARSTR, ARSTR); |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 601 | mdelay(1); |
| 602 | } |
| 603 | |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 604 | static void sh_eth_set_rate(struct net_device *ndev) |
| 605 | { |
| 606 | struct sh_eth_private *mdp = netdev_priv(ndev); |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 607 | |
| 608 | switch (mdp->speed) { |
| 609 | case 10: /* 10BASE */ |
Yoshihiro Shimoda | 4a55530 | 2011-03-07 21:59:26 +0000 | [diff] [blame] | 610 | sh_eth_write(ndev, GECMR_10, GECMR); |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 611 | break; |
| 612 | case 100:/* 100BASE */ |
Yoshihiro Shimoda | 4a55530 | 2011-03-07 21:59:26 +0000 | [diff] [blame] | 613 | sh_eth_write(ndev, GECMR_100, GECMR); |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 614 | break; |
| 615 | case 1000: /* 1000BASE */ |
Yoshihiro Shimoda | 4a55530 | 2011-03-07 21:59:26 +0000 | [diff] [blame] | 616 | sh_eth_write(ndev, GECMR_1000, GECMR); |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 617 | break; |
| 618 | default: |
| 619 | break; |
| 620 | } |
| 621 | } |
| 622 | |
| 623 | /* sh7763 */ |
| 624 | static struct sh_eth_cpu_data sh_eth_my_cpu_data = { |
| 625 | .chip_reset = sh_eth_chip_reset, |
| 626 | .set_duplex = sh_eth_set_duplex, |
| 627 | .set_rate = sh_eth_set_rate, |
| 628 | |
| 629 | .ecsr_value = ECSR_ICD | ECSR_MPD, |
| 630 | .ecsipr_value = ECSIPR_LCHNGIP | ECSIPR_ICDIP | ECSIPR_MPDIP, |
| 631 | .eesipr_value = DMAC_M_RFRMER | DMAC_M_ECI | 0x003fffff, |
| 632 | |
| 633 | .tx_check = EESR_TC1 | EESR_FTC, |
| 634 | .eesr_err_check = EESR_TWB1 | EESR_TWB | EESR_TABT | EESR_RABT | \ |
| 635 | EESR_RDE | EESR_RFRMER | EESR_TFE | EESR_TDE | \ |
| 636 | EESR_ECI, |
| 637 | .tx_error_check = EESR_TWB1 | EESR_TWB | EESR_TABT | EESR_TDE | \ |
| 638 | EESR_TFE, |
| 639 | |
| 640 | .apr = 1, |
| 641 | .mpr = 1, |
| 642 | .tpauser = 1, |
| 643 | .bculr = 1, |
| 644 | .hw_swap = 1, |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 645 | .no_trimd = 1, |
| 646 | .no_ade = 1, |
Yoshihiro Shimoda | 4986b99 | 2011-03-07 21:59:34 +0000 | [diff] [blame] | 647 | .tsu = 1, |
Nobuhiro Iwamatsu | f0e81fe | 2012-03-25 18:59:51 +0000 | [diff] [blame] | 648 | #if defined(CONFIG_CPU_SUBTYPE_SH7734) |
| 649 | .hw_crc = 1, |
Nobuhiro Iwamatsu | 5e7a76b | 2012-06-25 17:34:14 +0000 | [diff] [blame] | 650 | .select_mii = 1, |
Nobuhiro Iwamatsu | 5b3dfd1 | 2013-06-06 09:49:30 +0000 | [diff] [blame] | 651 | #else |
| 652 | .irq_flags = IRQF_SHARED, |
Nobuhiro Iwamatsu | f0e81fe | 2012-03-25 18:59:51 +0000 | [diff] [blame] | 653 | #endif |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 654 | }; |
| 655 | |
Nobuhiro Iwamatsu | 5cee1d3 | 2012-06-25 17:35:12 +0000 | [diff] [blame] | 656 | static int sh_eth_reset(struct net_device *ndev) |
Nobuhiro Iwamatsu | 5e7a76b | 2012-06-25 17:34:14 +0000 | [diff] [blame] | 657 | { |
Nobuhiro Iwamatsu | 5cee1d3 | 2012-06-25 17:35:12 +0000 | [diff] [blame] | 658 | int ret = 0; |
Nobuhiro Iwamatsu | 5e7a76b | 2012-06-25 17:34:14 +0000 | [diff] [blame] | 659 | |
| 660 | sh_eth_write(ndev, EDSR_ENALL, EDSR); |
| 661 | sh_eth_write(ndev, sh_eth_read(ndev, EDMR) | EDMR_SRST_GETHER, EDMR); |
Nobuhiro Iwamatsu | 5cee1d3 | 2012-06-25 17:35:12 +0000 | [diff] [blame] | 662 | |
| 663 | ret = sh_eth_check_reset(ndev); |
| 664 | if (ret) |
| 665 | goto out; |
Nobuhiro Iwamatsu | 5e7a76b | 2012-06-25 17:34:14 +0000 | [diff] [blame] | 666 | |
| 667 | /* Table Init */ |
| 668 | sh_eth_write(ndev, 0x0, TDLAR); |
| 669 | sh_eth_write(ndev, 0x0, TDFAR); |
| 670 | sh_eth_write(ndev, 0x0, TDFXR); |
| 671 | sh_eth_write(ndev, 0x0, TDFFR); |
| 672 | sh_eth_write(ndev, 0x0, RDLAR); |
| 673 | sh_eth_write(ndev, 0x0, RDFAR); |
| 674 | sh_eth_write(ndev, 0x0, RDFXR); |
| 675 | sh_eth_write(ndev, 0x0, RDFFR); |
| 676 | |
| 677 | /* Reset HW CRC register */ |
| 678 | sh_eth_reset_hw_crc(ndev); |
| 679 | |
| 680 | /* Select MII mode */ |
| 681 | if (sh_eth_my_cpu_data.select_mii) |
| 682 | sh_eth_select_mii(ndev); |
Nobuhiro Iwamatsu | 5cee1d3 | 2012-06-25 17:35:12 +0000 | [diff] [blame] | 683 | out: |
| 684 | return ret; |
Nobuhiro Iwamatsu | 5e7a76b | 2012-06-25 17:34:14 +0000 | [diff] [blame] | 685 | } |
| 686 | |
Nobuhiro Iwamatsu | f0e81fe | 2012-03-25 18:59:51 +0000 | [diff] [blame] | 687 | static void sh_eth_reset_hw_crc(struct net_device *ndev) |
| 688 | { |
| 689 | if (sh_eth_my_cpu_data.hw_crc) |
| 690 | sh_eth_write(ndev, 0x0, CSMR); |
| 691 | } |
| 692 | |
Yoshihiro Shimoda | 73a0d90 | 2012-04-04 18:37:10 +0000 | [diff] [blame] | 693 | #elif defined(CONFIG_ARCH_R8A7740) |
Nobuhiro Iwamatsu | 5cee1d3 | 2012-06-25 17:35:12 +0000 | [diff] [blame] | 694 | static int sh_eth_check_reset(struct net_device *ndev); |
| 695 | |
Yoshihiro Shimoda | 73a0d90 | 2012-04-04 18:37:10 +0000 | [diff] [blame] | 696 | static void sh_eth_chip_reset(struct net_device *ndev) |
| 697 | { |
| 698 | struct sh_eth_private *mdp = netdev_priv(ndev); |
Yoshihiro Shimoda | 73a0d90 | 2012-04-04 18:37:10 +0000 | [diff] [blame] | 699 | |
| 700 | /* reset device */ |
| 701 | sh_eth_tsu_write(mdp, ARSTR_ARSTR, ARSTR); |
| 702 | mdelay(1); |
| 703 | |
Nobuhiro Iwamatsu | 5e7a76b | 2012-06-25 17:34:14 +0000 | [diff] [blame] | 704 | sh_eth_select_mii(ndev); |
Yoshihiro Shimoda | 73a0d90 | 2012-04-04 18:37:10 +0000 | [diff] [blame] | 705 | } |
| 706 | |
Nobuhiro Iwamatsu | 5cee1d3 | 2012-06-25 17:35:12 +0000 | [diff] [blame] | 707 | static int sh_eth_reset(struct net_device *ndev) |
Yoshihiro Shimoda | 73a0d90 | 2012-04-04 18:37:10 +0000 | [diff] [blame] | 708 | { |
Nobuhiro Iwamatsu | 5cee1d3 | 2012-06-25 17:35:12 +0000 | [diff] [blame] | 709 | int ret = 0; |
Yoshihiro Shimoda | 73a0d90 | 2012-04-04 18:37:10 +0000 | [diff] [blame] | 710 | |
| 711 | sh_eth_write(ndev, EDSR_ENALL, EDSR); |
| 712 | sh_eth_write(ndev, sh_eth_read(ndev, EDMR) | EDMR_SRST_GETHER, EDMR); |
Nobuhiro Iwamatsu | 5cee1d3 | 2012-06-25 17:35:12 +0000 | [diff] [blame] | 713 | |
| 714 | ret = sh_eth_check_reset(ndev); |
| 715 | if (ret) |
| 716 | goto out; |
Yoshihiro Shimoda | 73a0d90 | 2012-04-04 18:37:10 +0000 | [diff] [blame] | 717 | |
| 718 | /* Table Init */ |
| 719 | sh_eth_write(ndev, 0x0, TDLAR); |
| 720 | sh_eth_write(ndev, 0x0, TDFAR); |
| 721 | sh_eth_write(ndev, 0x0, TDFXR); |
| 722 | sh_eth_write(ndev, 0x0, TDFFR); |
| 723 | sh_eth_write(ndev, 0x0, RDLAR); |
| 724 | sh_eth_write(ndev, 0x0, RDFAR); |
| 725 | sh_eth_write(ndev, 0x0, RDFXR); |
| 726 | sh_eth_write(ndev, 0x0, RDFFR); |
Nobuhiro Iwamatsu | 5cee1d3 | 2012-06-25 17:35:12 +0000 | [diff] [blame] | 727 | |
| 728 | out: |
| 729 | return ret; |
Yoshihiro Shimoda | 73a0d90 | 2012-04-04 18:37:10 +0000 | [diff] [blame] | 730 | } |
| 731 | |
Yoshihiro Shimoda | 73a0d90 | 2012-04-04 18:37:10 +0000 | [diff] [blame] | 732 | static void sh_eth_set_rate(struct net_device *ndev) |
| 733 | { |
| 734 | struct sh_eth_private *mdp = netdev_priv(ndev); |
| 735 | |
| 736 | switch (mdp->speed) { |
| 737 | case 10: /* 10BASE */ |
| 738 | sh_eth_write(ndev, GECMR_10, GECMR); |
| 739 | break; |
| 740 | case 100:/* 100BASE */ |
| 741 | sh_eth_write(ndev, GECMR_100, GECMR); |
| 742 | break; |
| 743 | case 1000: /* 1000BASE */ |
| 744 | sh_eth_write(ndev, GECMR_1000, GECMR); |
| 745 | break; |
| 746 | default: |
| 747 | break; |
| 748 | } |
| 749 | } |
| 750 | |
| 751 | /* R8A7740 */ |
| 752 | static struct sh_eth_cpu_data sh_eth_my_cpu_data = { |
| 753 | .chip_reset = sh_eth_chip_reset, |
| 754 | .set_duplex = sh_eth_set_duplex, |
| 755 | .set_rate = sh_eth_set_rate, |
| 756 | |
| 757 | .ecsr_value = ECSR_ICD | ECSR_MPD, |
| 758 | .ecsipr_value = ECSIPR_LCHNGIP | ECSIPR_ICDIP | ECSIPR_MPDIP, |
| 759 | .eesipr_value = DMAC_M_RFRMER | DMAC_M_ECI | 0x003fffff, |
| 760 | |
| 761 | .tx_check = EESR_TC1 | EESR_FTC, |
| 762 | .eesr_err_check = EESR_TWB1 | EESR_TWB | EESR_TABT | EESR_RABT | \ |
| 763 | EESR_RDE | EESR_RFRMER | EESR_TFE | EESR_TDE | \ |
| 764 | EESR_ECI, |
| 765 | .tx_error_check = EESR_TWB1 | EESR_TWB | EESR_TABT | EESR_TDE | \ |
| 766 | EESR_TFE, |
| 767 | |
| 768 | .apr = 1, |
| 769 | .mpr = 1, |
| 770 | .tpauser = 1, |
| 771 | .bculr = 1, |
| 772 | .hw_swap = 1, |
| 773 | .no_trimd = 1, |
| 774 | .no_ade = 1, |
| 775 | .tsu = 1, |
Nobuhiro Iwamatsu | 5e7a76b | 2012-06-25 17:34:14 +0000 | [diff] [blame] | 776 | .select_mii = 1, |
Yoshihiro Shimoda | 73a0d90 | 2012-04-04 18:37:10 +0000 | [diff] [blame] | 777 | }; |
| 778 | |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 779 | #elif defined(CONFIG_CPU_SUBTYPE_SH7619) |
| 780 | #define SH_ETH_RESET_DEFAULT 1 |
| 781 | static struct sh_eth_cpu_data sh_eth_my_cpu_data = { |
| 782 | .eesipr_value = DMAC_M_RFRMER | DMAC_M_ECI | 0x003fffff, |
| 783 | |
| 784 | .apr = 1, |
| 785 | .mpr = 1, |
| 786 | .tpauser = 1, |
| 787 | .hw_swap = 1, |
| 788 | }; |
| 789 | #elif defined(CONFIG_CPU_SUBTYPE_SH7710) || defined(CONFIG_CPU_SUBTYPE_SH7712) |
| 790 | #define SH_ETH_RESET_DEFAULT 1 |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 791 | static struct sh_eth_cpu_data sh_eth_my_cpu_data = { |
| 792 | .eesipr_value = DMAC_M_RFRMER | DMAC_M_ECI | 0x003fffff, |
Yoshihiro Shimoda | 4986b99 | 2011-03-07 21:59:34 +0000 | [diff] [blame] | 793 | .tsu = 1, |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 794 | }; |
| 795 | #endif |
| 796 | |
| 797 | static void sh_eth_set_default_cpu_data(struct sh_eth_cpu_data *cd) |
| 798 | { |
| 799 | if (!cd->ecsr_value) |
| 800 | cd->ecsr_value = DEFAULT_ECSR_INIT; |
| 801 | |
| 802 | if (!cd->ecsipr_value) |
| 803 | cd->ecsipr_value = DEFAULT_ECSIPR_INIT; |
| 804 | |
| 805 | if (!cd->fcftr_value) |
| 806 | cd->fcftr_value = DEFAULT_FIFO_F_D_RFF | \ |
| 807 | DEFAULT_FIFO_F_D_RFD; |
| 808 | |
| 809 | if (!cd->fdr_value) |
| 810 | cd->fdr_value = DEFAULT_FDR_INIT; |
| 811 | |
| 812 | if (!cd->rmcr_value) |
| 813 | cd->rmcr_value = DEFAULT_RMCR_VALUE; |
| 814 | |
| 815 | if (!cd->tx_check) |
| 816 | cd->tx_check = DEFAULT_TX_CHECK; |
| 817 | |
| 818 | if (!cd->eesr_err_check) |
| 819 | cd->eesr_err_check = DEFAULT_EESR_ERR_CHECK; |
| 820 | |
| 821 | if (!cd->tx_error_check) |
| 822 | cd->tx_error_check = DEFAULT_TX_ERROR_CHECK; |
| 823 | } |
| 824 | |
| 825 | #if defined(SH_ETH_RESET_DEFAULT) |
| 826 | /* Chip Reset */ |
Nobuhiro Iwamatsu | 5cee1d3 | 2012-06-25 17:35:12 +0000 | [diff] [blame] | 827 | static int sh_eth_reset(struct net_device *ndev) |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 828 | { |
Yoshihiro Shimoda | c5ed536 | 2011-03-07 21:59:38 +0000 | [diff] [blame] | 829 | sh_eth_write(ndev, sh_eth_read(ndev, EDMR) | EDMR_SRST_ETHER, EDMR); |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 830 | mdelay(3); |
Yoshihiro Shimoda | c5ed536 | 2011-03-07 21:59:38 +0000 | [diff] [blame] | 831 | sh_eth_write(ndev, sh_eth_read(ndev, EDMR) & ~EDMR_SRST_ETHER, EDMR); |
Nobuhiro Iwamatsu | 5cee1d3 | 2012-06-25 17:35:12 +0000 | [diff] [blame] | 832 | |
| 833 | return 0; |
| 834 | } |
| 835 | #else |
| 836 | static int sh_eth_check_reset(struct net_device *ndev) |
| 837 | { |
| 838 | int ret = 0; |
| 839 | int cnt = 100; |
| 840 | |
| 841 | while (cnt > 0) { |
| 842 | if (!(sh_eth_read(ndev, EDMR) & 0x3)) |
| 843 | break; |
| 844 | mdelay(1); |
| 845 | cnt--; |
| 846 | } |
| 847 | if (cnt < 0) { |
Nobuhiro Iwamatsu | 14c3326 | 2013-03-20 22:46:55 +0000 | [diff] [blame] | 848 | pr_err("Device reset fail\n"); |
Nobuhiro Iwamatsu | 5cee1d3 | 2012-06-25 17:35:12 +0000 | [diff] [blame] | 849 | ret = -ETIMEDOUT; |
| 850 | } |
| 851 | return ret; |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 852 | } |
| 853 | #endif |
| 854 | |
Yoshihiro Shimoda | 73a0d90 | 2012-04-04 18:37:10 +0000 | [diff] [blame] | 855 | #if defined(CONFIG_CPU_SH4) || defined(CONFIG_ARCH_SHMOBILE) |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 856 | static void sh_eth_set_receive_align(struct sk_buff *skb) |
| 857 | { |
| 858 | int reserve; |
| 859 | |
| 860 | reserve = SH4_SKB_RX_ALIGN - ((u32)skb->data & (SH4_SKB_RX_ALIGN - 1)); |
| 861 | if (reserve) |
| 862 | skb_reserve(skb, reserve); |
| 863 | } |
| 864 | #else |
| 865 | static void sh_eth_set_receive_align(struct sk_buff *skb) |
| 866 | { |
| 867 | skb_reserve(skb, SH2_SH3_SKB_RX_ALIGN); |
| 868 | } |
| 869 | #endif |
| 870 | |
| 871 | |
Yoshinori Sato | 71557a3 | 2008-08-06 19:49:00 -0400 | [diff] [blame] | 872 | /* CPU <-> EDMAC endian convert */ |
| 873 | static inline __u32 cpu_to_edmac(struct sh_eth_private *mdp, u32 x) |
| 874 | { |
| 875 | switch (mdp->edmac_endian) { |
| 876 | case EDMAC_LITTLE_ENDIAN: |
| 877 | return cpu_to_le32(x); |
| 878 | case EDMAC_BIG_ENDIAN: |
| 879 | return cpu_to_be32(x); |
| 880 | } |
| 881 | return x; |
| 882 | } |
| 883 | |
| 884 | static inline __u32 edmac_to_cpu(struct sh_eth_private *mdp, u32 x) |
| 885 | { |
| 886 | switch (mdp->edmac_endian) { |
| 887 | case EDMAC_LITTLE_ENDIAN: |
| 888 | return le32_to_cpu(x); |
| 889 | case EDMAC_BIG_ENDIAN: |
| 890 | return be32_to_cpu(x); |
| 891 | } |
| 892 | return x; |
| 893 | } |
| 894 | |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 895 | /* |
| 896 | * Program the hardware MAC address from dev->dev_addr. |
| 897 | */ |
| 898 | static void update_mac_address(struct net_device *ndev) |
| 899 | { |
Yoshihiro Shimoda | 4a55530 | 2011-03-07 21:59:26 +0000 | [diff] [blame] | 900 | sh_eth_write(ndev, |
| 901 | (ndev->dev_addr[0] << 24) | (ndev->dev_addr[1] << 16) | |
| 902 | (ndev->dev_addr[2] << 8) | (ndev->dev_addr[3]), MAHR); |
| 903 | sh_eth_write(ndev, |
| 904 | (ndev->dev_addr[4] << 8) | (ndev->dev_addr[5]), MALR); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 905 | } |
| 906 | |
| 907 | /* |
| 908 | * Get MAC address from SuperH MAC address register |
| 909 | * |
| 910 | * SuperH's Ethernet device doesn't have 'ROM' to MAC address. |
| 911 | * This driver get MAC address that use by bootloader(U-boot or sh-ipl+g). |
| 912 | * When you want use this device, you must set MAC address in bootloader. |
| 913 | * |
| 914 | */ |
Magnus Damm | 748031f | 2009-10-09 00:17:14 +0000 | [diff] [blame] | 915 | static void read_mac_address(struct net_device *ndev, unsigned char *mac) |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 916 | { |
Magnus Damm | 748031f | 2009-10-09 00:17:14 +0000 | [diff] [blame] | 917 | if (mac[0] || mac[1] || mac[2] || mac[3] || mac[4] || mac[5]) { |
| 918 | memcpy(ndev->dev_addr, mac, 6); |
| 919 | } else { |
Yoshihiro Shimoda | 4a55530 | 2011-03-07 21:59:26 +0000 | [diff] [blame] | 920 | ndev->dev_addr[0] = (sh_eth_read(ndev, MAHR) >> 24); |
| 921 | ndev->dev_addr[1] = (sh_eth_read(ndev, MAHR) >> 16) & 0xFF; |
| 922 | ndev->dev_addr[2] = (sh_eth_read(ndev, MAHR) >> 8) & 0xFF; |
| 923 | ndev->dev_addr[3] = (sh_eth_read(ndev, MAHR) & 0xFF); |
| 924 | ndev->dev_addr[4] = (sh_eth_read(ndev, MALR) >> 8) & 0xFF; |
| 925 | ndev->dev_addr[5] = (sh_eth_read(ndev, MALR) & 0xFF); |
Magnus Damm | 748031f | 2009-10-09 00:17:14 +0000 | [diff] [blame] | 926 | } |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 927 | } |
| 928 | |
Yoshihiro Shimoda | c5ed536 | 2011-03-07 21:59:38 +0000 | [diff] [blame] | 929 | static int sh_eth_is_gether(struct sh_eth_private *mdp) |
| 930 | { |
| 931 | if (mdp->reg_offset == sh_eth_offset_gigabit) |
| 932 | return 1; |
| 933 | else |
| 934 | return 0; |
| 935 | } |
| 936 | |
| 937 | static unsigned long sh_eth_get_edtrr_trns(struct sh_eth_private *mdp) |
| 938 | { |
| 939 | if (sh_eth_is_gether(mdp)) |
| 940 | return EDTRR_TRNS_GETHER; |
| 941 | else |
| 942 | return EDTRR_TRNS_ETHER; |
| 943 | } |
| 944 | |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 945 | struct bb_info { |
Yoshihiro Shimoda | ae70644 | 2011-09-27 21:48:58 +0000 | [diff] [blame] | 946 | void (*set_gate)(void *addr); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 947 | struct mdiobb_ctrl ctrl; |
Yoshihiro Shimoda | ae70644 | 2011-09-27 21:48:58 +0000 | [diff] [blame] | 948 | void *addr; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 949 | u32 mmd_msk;/* MMD */ |
| 950 | u32 mdo_msk; |
| 951 | u32 mdi_msk; |
| 952 | u32 mdc_msk; |
| 953 | }; |
| 954 | |
| 955 | /* PHY bit set */ |
Yoshihiro Shimoda | ae70644 | 2011-09-27 21:48:58 +0000 | [diff] [blame] | 956 | static void bb_set(void *addr, u32 msk) |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 957 | { |
Yoshihiro Shimoda | ae70644 | 2011-09-27 21:48:58 +0000 | [diff] [blame] | 958 | iowrite32(ioread32(addr) | msk, addr); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 959 | } |
| 960 | |
| 961 | /* PHY bit clear */ |
Yoshihiro Shimoda | ae70644 | 2011-09-27 21:48:58 +0000 | [diff] [blame] | 962 | static void bb_clr(void *addr, u32 msk) |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 963 | { |
Yoshihiro Shimoda | ae70644 | 2011-09-27 21:48:58 +0000 | [diff] [blame] | 964 | iowrite32((ioread32(addr) & ~msk), addr); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 965 | } |
| 966 | |
| 967 | /* PHY bit read */ |
Yoshihiro Shimoda | ae70644 | 2011-09-27 21:48:58 +0000 | [diff] [blame] | 968 | static int bb_read(void *addr, u32 msk) |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 969 | { |
Yoshihiro Shimoda | ae70644 | 2011-09-27 21:48:58 +0000 | [diff] [blame] | 970 | return (ioread32(addr) & msk) != 0; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 971 | } |
| 972 | |
| 973 | /* Data I/O pin control */ |
| 974 | static void sh_mmd_ctrl(struct mdiobb_ctrl *ctrl, int bit) |
| 975 | { |
| 976 | struct bb_info *bitbang = container_of(ctrl, struct bb_info, ctrl); |
Yoshihiro Shimoda | b3017e6 | 2011-03-07 21:59:55 +0000 | [diff] [blame] | 977 | |
| 978 | if (bitbang->set_gate) |
| 979 | bitbang->set_gate(bitbang->addr); |
| 980 | |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 981 | if (bit) |
| 982 | bb_set(bitbang->addr, bitbang->mmd_msk); |
| 983 | else |
| 984 | bb_clr(bitbang->addr, bitbang->mmd_msk); |
| 985 | } |
| 986 | |
| 987 | /* Set bit data*/ |
| 988 | static void sh_set_mdio(struct mdiobb_ctrl *ctrl, int bit) |
| 989 | { |
| 990 | struct bb_info *bitbang = container_of(ctrl, struct bb_info, ctrl); |
| 991 | |
Yoshihiro Shimoda | b3017e6 | 2011-03-07 21:59:55 +0000 | [diff] [blame] | 992 | if (bitbang->set_gate) |
| 993 | bitbang->set_gate(bitbang->addr); |
| 994 | |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 995 | if (bit) |
| 996 | bb_set(bitbang->addr, bitbang->mdo_msk); |
| 997 | else |
| 998 | bb_clr(bitbang->addr, bitbang->mdo_msk); |
| 999 | } |
| 1000 | |
| 1001 | /* Get bit data*/ |
| 1002 | static int sh_get_mdio(struct mdiobb_ctrl *ctrl) |
| 1003 | { |
| 1004 | struct bb_info *bitbang = container_of(ctrl, struct bb_info, ctrl); |
Yoshihiro Shimoda | b3017e6 | 2011-03-07 21:59:55 +0000 | [diff] [blame] | 1005 | |
| 1006 | if (bitbang->set_gate) |
| 1007 | bitbang->set_gate(bitbang->addr); |
| 1008 | |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1009 | return bb_read(bitbang->addr, bitbang->mdi_msk); |
| 1010 | } |
| 1011 | |
| 1012 | /* MDC pin control */ |
| 1013 | static void sh_mdc_ctrl(struct mdiobb_ctrl *ctrl, int bit) |
| 1014 | { |
| 1015 | struct bb_info *bitbang = container_of(ctrl, struct bb_info, ctrl); |
| 1016 | |
Yoshihiro Shimoda | b3017e6 | 2011-03-07 21:59:55 +0000 | [diff] [blame] | 1017 | if (bitbang->set_gate) |
| 1018 | bitbang->set_gate(bitbang->addr); |
| 1019 | |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1020 | if (bit) |
| 1021 | bb_set(bitbang->addr, bitbang->mdc_msk); |
| 1022 | else |
| 1023 | bb_clr(bitbang->addr, bitbang->mdc_msk); |
| 1024 | } |
| 1025 | |
| 1026 | /* mdio bus control struct */ |
| 1027 | static struct mdiobb_ops bb_ops = { |
| 1028 | .owner = THIS_MODULE, |
| 1029 | .set_mdc = sh_mdc_ctrl, |
| 1030 | .set_mdio_dir = sh_mmd_ctrl, |
| 1031 | .set_mdio_data = sh_set_mdio, |
| 1032 | .get_mdio_data = sh_get_mdio, |
| 1033 | }; |
| 1034 | |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1035 | /* free skb and descriptor buffer */ |
| 1036 | static void sh_eth_ring_free(struct net_device *ndev) |
| 1037 | { |
| 1038 | struct sh_eth_private *mdp = netdev_priv(ndev); |
| 1039 | int i; |
| 1040 | |
| 1041 | /* Free Rx skb ringbuffer */ |
| 1042 | if (mdp->rx_skbuff) { |
Yoshihiro Shimoda | 525b807 | 2012-06-26 20:00:03 +0000 | [diff] [blame] | 1043 | for (i = 0; i < mdp->num_rx_ring; i++) { |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1044 | if (mdp->rx_skbuff[i]) |
| 1045 | dev_kfree_skb(mdp->rx_skbuff[i]); |
| 1046 | } |
| 1047 | } |
| 1048 | kfree(mdp->rx_skbuff); |
Yoshihiro Shimoda | 91c7755 | 2012-06-26 20:00:01 +0000 | [diff] [blame] | 1049 | mdp->rx_skbuff = NULL; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1050 | |
| 1051 | /* Free Tx skb ringbuffer */ |
| 1052 | if (mdp->tx_skbuff) { |
Yoshihiro Shimoda | 525b807 | 2012-06-26 20:00:03 +0000 | [diff] [blame] | 1053 | for (i = 0; i < mdp->num_tx_ring; i++) { |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1054 | if (mdp->tx_skbuff[i]) |
| 1055 | dev_kfree_skb(mdp->tx_skbuff[i]); |
| 1056 | } |
| 1057 | } |
| 1058 | kfree(mdp->tx_skbuff); |
Yoshihiro Shimoda | 91c7755 | 2012-06-26 20:00:01 +0000 | [diff] [blame] | 1059 | mdp->tx_skbuff = NULL; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1060 | } |
| 1061 | |
| 1062 | /* format skb and descriptor buffer */ |
| 1063 | static void sh_eth_ring_format(struct net_device *ndev) |
| 1064 | { |
| 1065 | struct sh_eth_private *mdp = netdev_priv(ndev); |
| 1066 | int i; |
| 1067 | struct sk_buff *skb; |
| 1068 | struct sh_eth_rxdesc *rxdesc = NULL; |
| 1069 | struct sh_eth_txdesc *txdesc = NULL; |
Yoshihiro Shimoda | 525b807 | 2012-06-26 20:00:03 +0000 | [diff] [blame] | 1070 | int rx_ringsize = sizeof(*rxdesc) * mdp->num_rx_ring; |
| 1071 | int tx_ringsize = sizeof(*txdesc) * mdp->num_tx_ring; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1072 | |
| 1073 | mdp->cur_rx = mdp->cur_tx = 0; |
| 1074 | mdp->dirty_rx = mdp->dirty_tx = 0; |
| 1075 | |
| 1076 | memset(mdp->rx_ring, 0, rx_ringsize); |
| 1077 | |
| 1078 | /* build Rx ring buffer */ |
Yoshihiro Shimoda | 525b807 | 2012-06-26 20:00:03 +0000 | [diff] [blame] | 1079 | for (i = 0; i < mdp->num_rx_ring; i++) { |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1080 | /* skb */ |
| 1081 | mdp->rx_skbuff[i] = NULL; |
Pradeep A. Dalvi | dae2e9f | 2012-02-06 11:16:13 +0000 | [diff] [blame] | 1082 | skb = netdev_alloc_skb(ndev, mdp->rx_buf_sz); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1083 | mdp->rx_skbuff[i] = skb; |
| 1084 | if (skb == NULL) |
| 1085 | break; |
Eric Dumazet | bb7d92e | 2012-02-06 22:17:21 +0000 | [diff] [blame] | 1086 | dma_map_single(&ndev->dev, skb->data, mdp->rx_buf_sz, |
Yoshihiro Shimoda | e88aae7 | 2009-05-24 23:52:35 +0000 | [diff] [blame] | 1087 | DMA_FROM_DEVICE); |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 1088 | sh_eth_set_receive_align(skb); |
| 1089 | |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1090 | /* RX descriptor */ |
| 1091 | rxdesc = &mdp->rx_ring[i]; |
Yoshihiro Shimoda | 0029d64 | 2009-05-24 23:53:20 +0000 | [diff] [blame] | 1092 | rxdesc->addr = virt_to_phys(PTR_ALIGN(skb->data, 4)); |
Yoshinori Sato | 71557a3 | 2008-08-06 19:49:00 -0400 | [diff] [blame] | 1093 | rxdesc->status = cpu_to_edmac(mdp, RD_RACT | RD_RFP); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1094 | |
| 1095 | /* The size of the buffer is 16 byte boundary. */ |
Yoshihiro Shimoda | 0029d64 | 2009-05-24 23:53:20 +0000 | [diff] [blame] | 1096 | rxdesc->buffer_length = ALIGN(mdp->rx_buf_sz, 16); |
Nobuhiro Iwamatsu | b0ca2a2 | 2008-06-30 11:08:17 +0900 | [diff] [blame] | 1097 | /* Rx descriptor address set */ |
| 1098 | if (i == 0) { |
Yoshihiro Shimoda | 4a55530 | 2011-03-07 21:59:26 +0000 | [diff] [blame] | 1099 | sh_eth_write(ndev, mdp->rx_desc_dma, RDLAR); |
Yoshihiro Shimoda | c5ed536 | 2011-03-07 21:59:38 +0000 | [diff] [blame] | 1100 | if (sh_eth_is_gether(mdp)) |
| 1101 | sh_eth_write(ndev, mdp->rx_desc_dma, RDFAR); |
Nobuhiro Iwamatsu | b0ca2a2 | 2008-06-30 11:08:17 +0900 | [diff] [blame] | 1102 | } |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1103 | } |
| 1104 | |
Yoshihiro Shimoda | 525b807 | 2012-06-26 20:00:03 +0000 | [diff] [blame] | 1105 | mdp->dirty_rx = (u32) (i - mdp->num_rx_ring); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1106 | |
| 1107 | /* Mark the last entry as wrapping the ring. */ |
Yoshinori Sato | 71557a3 | 2008-08-06 19:49:00 -0400 | [diff] [blame] | 1108 | rxdesc->status |= cpu_to_edmac(mdp, RD_RDEL); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1109 | |
| 1110 | memset(mdp->tx_ring, 0, tx_ringsize); |
| 1111 | |
| 1112 | /* build Tx ring buffer */ |
Yoshihiro Shimoda | 525b807 | 2012-06-26 20:00:03 +0000 | [diff] [blame] | 1113 | for (i = 0; i < mdp->num_tx_ring; i++) { |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1114 | mdp->tx_skbuff[i] = NULL; |
| 1115 | txdesc = &mdp->tx_ring[i]; |
Yoshinori Sato | 71557a3 | 2008-08-06 19:49:00 -0400 | [diff] [blame] | 1116 | txdesc->status = cpu_to_edmac(mdp, TD_TFP); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1117 | txdesc->buffer_length = 0; |
Nobuhiro Iwamatsu | b0ca2a2 | 2008-06-30 11:08:17 +0900 | [diff] [blame] | 1118 | if (i == 0) { |
Yoshinori Sato | 71557a3 | 2008-08-06 19:49:00 -0400 | [diff] [blame] | 1119 | /* Tx descriptor address set */ |
Yoshihiro Shimoda | 4a55530 | 2011-03-07 21:59:26 +0000 | [diff] [blame] | 1120 | sh_eth_write(ndev, mdp->tx_desc_dma, TDLAR); |
Yoshihiro Shimoda | c5ed536 | 2011-03-07 21:59:38 +0000 | [diff] [blame] | 1121 | if (sh_eth_is_gether(mdp)) |
| 1122 | sh_eth_write(ndev, mdp->tx_desc_dma, TDFAR); |
Nobuhiro Iwamatsu | b0ca2a2 | 2008-06-30 11:08:17 +0900 | [diff] [blame] | 1123 | } |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1124 | } |
| 1125 | |
Yoshinori Sato | 71557a3 | 2008-08-06 19:49:00 -0400 | [diff] [blame] | 1126 | txdesc->status |= cpu_to_edmac(mdp, TD_TDLE); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1127 | } |
| 1128 | |
| 1129 | /* Get skb and descriptor buffer */ |
| 1130 | static int sh_eth_ring_init(struct net_device *ndev) |
| 1131 | { |
| 1132 | struct sh_eth_private *mdp = netdev_priv(ndev); |
| 1133 | int rx_ringsize, tx_ringsize, ret = 0; |
| 1134 | |
| 1135 | /* |
| 1136 | * +26 gets the maximum ethernet encapsulation, +7 & ~7 because the |
| 1137 | * card needs room to do 8 byte alignment, +2 so we can reserve |
| 1138 | * the first 2 bytes, and +16 gets room for the status word from the |
| 1139 | * card. |
| 1140 | */ |
| 1141 | mdp->rx_buf_sz = (ndev->mtu <= 1492 ? PKT_BUF_SZ : |
| 1142 | (((ndev->mtu + 26 + 7) & ~7) + 2 + 16)); |
Magnus Damm | 503914c | 2009-12-15 21:16:55 -0800 | [diff] [blame] | 1143 | if (mdp->cd->rpadir) |
| 1144 | mdp->rx_buf_sz += NET_IP_ALIGN; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1145 | |
| 1146 | /* Allocate RX and TX skb rings */ |
Joe Perches | b2adaca | 2013-02-03 17:43:58 +0000 | [diff] [blame] | 1147 | mdp->rx_skbuff = kmalloc_array(mdp->num_rx_ring, |
| 1148 | sizeof(*mdp->rx_skbuff), GFP_KERNEL); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1149 | if (!mdp->rx_skbuff) { |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1150 | ret = -ENOMEM; |
| 1151 | return ret; |
| 1152 | } |
| 1153 | |
Joe Perches | b2adaca | 2013-02-03 17:43:58 +0000 | [diff] [blame] | 1154 | mdp->tx_skbuff = kmalloc_array(mdp->num_tx_ring, |
| 1155 | sizeof(*mdp->tx_skbuff), GFP_KERNEL); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1156 | if (!mdp->tx_skbuff) { |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1157 | ret = -ENOMEM; |
| 1158 | goto skb_ring_free; |
| 1159 | } |
| 1160 | |
| 1161 | /* Allocate all Rx descriptors. */ |
Yoshihiro Shimoda | 525b807 | 2012-06-26 20:00:03 +0000 | [diff] [blame] | 1162 | rx_ringsize = sizeof(struct sh_eth_rxdesc) * mdp->num_rx_ring; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1163 | 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] | 1164 | GFP_KERNEL); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1165 | if (!mdp->rx_ring) { |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1166 | ret = -ENOMEM; |
| 1167 | goto desc_ring_free; |
| 1168 | } |
| 1169 | |
| 1170 | mdp->dirty_rx = 0; |
| 1171 | |
| 1172 | /* Allocate all Tx descriptors. */ |
Yoshihiro Shimoda | 525b807 | 2012-06-26 20:00:03 +0000 | [diff] [blame] | 1173 | tx_ringsize = sizeof(struct sh_eth_txdesc) * mdp->num_tx_ring; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1174 | 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] | 1175 | GFP_KERNEL); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1176 | if (!mdp->tx_ring) { |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1177 | ret = -ENOMEM; |
| 1178 | goto desc_ring_free; |
| 1179 | } |
| 1180 | return ret; |
| 1181 | |
| 1182 | desc_ring_free: |
| 1183 | /* free DMA buffer */ |
| 1184 | dma_free_coherent(NULL, rx_ringsize, mdp->rx_ring, mdp->rx_desc_dma); |
| 1185 | |
| 1186 | skb_ring_free: |
| 1187 | /* Free Rx and Tx skb ring buffer */ |
| 1188 | sh_eth_ring_free(ndev); |
Yoshihiro Shimoda | 91c7755 | 2012-06-26 20:00:01 +0000 | [diff] [blame] | 1189 | mdp->tx_ring = NULL; |
| 1190 | mdp->rx_ring = NULL; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1191 | |
| 1192 | return ret; |
| 1193 | } |
| 1194 | |
Yoshihiro Shimoda | 91c7755 | 2012-06-26 20:00:01 +0000 | [diff] [blame] | 1195 | static void sh_eth_free_dma_buffer(struct sh_eth_private *mdp) |
| 1196 | { |
| 1197 | int ringsize; |
| 1198 | |
| 1199 | if (mdp->rx_ring) { |
Yoshihiro Shimoda | 525b807 | 2012-06-26 20:00:03 +0000 | [diff] [blame] | 1200 | ringsize = sizeof(struct sh_eth_rxdesc) * mdp->num_rx_ring; |
Yoshihiro Shimoda | 91c7755 | 2012-06-26 20:00:01 +0000 | [diff] [blame] | 1201 | dma_free_coherent(NULL, ringsize, mdp->rx_ring, |
| 1202 | mdp->rx_desc_dma); |
| 1203 | mdp->rx_ring = NULL; |
| 1204 | } |
| 1205 | |
| 1206 | if (mdp->tx_ring) { |
Yoshihiro Shimoda | 525b807 | 2012-06-26 20:00:03 +0000 | [diff] [blame] | 1207 | ringsize = sizeof(struct sh_eth_txdesc) * mdp->num_tx_ring; |
Yoshihiro Shimoda | 91c7755 | 2012-06-26 20:00:01 +0000 | [diff] [blame] | 1208 | dma_free_coherent(NULL, ringsize, mdp->tx_ring, |
| 1209 | mdp->tx_desc_dma); |
| 1210 | mdp->tx_ring = NULL; |
| 1211 | } |
| 1212 | } |
| 1213 | |
Yoshihiro Shimoda | 525b807 | 2012-06-26 20:00:03 +0000 | [diff] [blame] | 1214 | static int sh_eth_dev_init(struct net_device *ndev, bool start) |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1215 | { |
| 1216 | int ret = 0; |
| 1217 | struct sh_eth_private *mdp = netdev_priv(ndev); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1218 | u32 val; |
| 1219 | |
| 1220 | /* Soft Reset */ |
Nobuhiro Iwamatsu | 5cee1d3 | 2012-06-25 17:35:12 +0000 | [diff] [blame] | 1221 | ret = sh_eth_reset(ndev); |
| 1222 | if (ret) |
| 1223 | goto out; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1224 | |
Nobuhiro Iwamatsu | b0ca2a2 | 2008-06-30 11:08:17 +0900 | [diff] [blame] | 1225 | /* Descriptor format */ |
| 1226 | sh_eth_ring_format(ndev); |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 1227 | if (mdp->cd->rpadir) |
Yoshihiro Shimoda | 4a55530 | 2011-03-07 21:59:26 +0000 | [diff] [blame] | 1228 | sh_eth_write(ndev, mdp->cd->rpadir_value, RPADIR); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1229 | |
| 1230 | /* all sh_eth int mask */ |
Yoshihiro Shimoda | 4a55530 | 2011-03-07 21:59:26 +0000 | [diff] [blame] | 1231 | sh_eth_write(ndev, 0, EESIPR); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1232 | |
Yoshihiro Shimoda | 10b9194 | 2012-03-29 19:32:08 +0000 | [diff] [blame] | 1233 | #if defined(__LITTLE_ENDIAN) |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 1234 | if (mdp->cd->hw_swap) |
Yoshihiro Shimoda | 4a55530 | 2011-03-07 21:59:26 +0000 | [diff] [blame] | 1235 | sh_eth_write(ndev, EDMR_EL, EDMR); |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 1236 | else |
Nobuhiro Iwamatsu | b0ca2a2 | 2008-06-30 11:08:17 +0900 | [diff] [blame] | 1237 | #endif |
Yoshihiro Shimoda | 4a55530 | 2011-03-07 21:59:26 +0000 | [diff] [blame] | 1238 | sh_eth_write(ndev, 0, EDMR); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1239 | |
Nobuhiro Iwamatsu | b0ca2a2 | 2008-06-30 11:08:17 +0900 | [diff] [blame] | 1240 | /* FIFO size set */ |
Yoshihiro Shimoda | 4a55530 | 2011-03-07 21:59:26 +0000 | [diff] [blame] | 1241 | sh_eth_write(ndev, mdp->cd->fdr_value, FDR); |
| 1242 | sh_eth_write(ndev, 0, TFTR); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1243 | |
Nobuhiro Iwamatsu | b0ca2a2 | 2008-06-30 11:08:17 +0900 | [diff] [blame] | 1244 | /* Frame recv control */ |
Yoshihiro Shimoda | 4a55530 | 2011-03-07 21:59:26 +0000 | [diff] [blame] | 1245 | sh_eth_write(ndev, mdp->cd->rmcr_value, RMCR); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1246 | |
Yoshihiro Shimoda | 2ecbb78 | 2012-06-26 19:59:58 +0000 | [diff] [blame] | 1247 | sh_eth_write(ndev, DESC_I_RINT8 | DESC_I_RINT5 | DESC_I_TINT2, TRSCER); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1248 | |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 1249 | if (mdp->cd->bculr) |
Yoshihiro Shimoda | 4a55530 | 2011-03-07 21:59:26 +0000 | [diff] [blame] | 1250 | sh_eth_write(ndev, 0x800, BCULR); /* Burst sycle set */ |
Nobuhiro Iwamatsu | b0ca2a2 | 2008-06-30 11:08:17 +0900 | [diff] [blame] | 1251 | |
Yoshihiro Shimoda | 4a55530 | 2011-03-07 21:59:26 +0000 | [diff] [blame] | 1252 | sh_eth_write(ndev, mdp->cd->fcftr_value, FCFTR); |
Nobuhiro Iwamatsu | b0ca2a2 | 2008-06-30 11:08:17 +0900 | [diff] [blame] | 1253 | |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 1254 | if (!mdp->cd->no_trimd) |
Yoshihiro Shimoda | 4a55530 | 2011-03-07 21:59:26 +0000 | [diff] [blame] | 1255 | sh_eth_write(ndev, 0, TRIMD); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1256 | |
Nobuhiro Iwamatsu | b0ca2a2 | 2008-06-30 11:08:17 +0900 | [diff] [blame] | 1257 | /* Recv frame limit set register */ |
Yoshihiro Shimoda | fdb37a7 | 2012-02-06 23:55:15 +0000 | [diff] [blame] | 1258 | sh_eth_write(ndev, ndev->mtu + ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN, |
| 1259 | RFLR); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1260 | |
Yoshihiro Shimoda | 4a55530 | 2011-03-07 21:59:26 +0000 | [diff] [blame] | 1261 | sh_eth_write(ndev, sh_eth_read(ndev, EESR), EESR); |
Yoshihiro Shimoda | 525b807 | 2012-06-26 20:00:03 +0000 | [diff] [blame] | 1262 | if (start) |
| 1263 | sh_eth_write(ndev, mdp->cd->eesipr_value, EESIPR); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1264 | |
| 1265 | /* PAUSE Prohibition */ |
Yoshihiro Shimoda | 4a55530 | 2011-03-07 21:59:26 +0000 | [diff] [blame] | 1266 | val = (sh_eth_read(ndev, ECMR) & ECMR_DM) | |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1267 | ECMR_ZPF | (mdp->duplex ? ECMR_DM : 0) | ECMR_TE | ECMR_RE; |
| 1268 | |
Yoshihiro Shimoda | 4a55530 | 2011-03-07 21:59:26 +0000 | [diff] [blame] | 1269 | sh_eth_write(ndev, val, ECMR); |
Nobuhiro Iwamatsu | b0ca2a2 | 2008-06-30 11:08:17 +0900 | [diff] [blame] | 1270 | |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 1271 | if (mdp->cd->set_rate) |
| 1272 | mdp->cd->set_rate(ndev); |
| 1273 | |
Nobuhiro Iwamatsu | b0ca2a2 | 2008-06-30 11:08:17 +0900 | [diff] [blame] | 1274 | /* E-MAC Status Register clear */ |
Yoshihiro Shimoda | 4a55530 | 2011-03-07 21:59:26 +0000 | [diff] [blame] | 1275 | sh_eth_write(ndev, mdp->cd->ecsr_value, ECSR); |
Nobuhiro Iwamatsu | b0ca2a2 | 2008-06-30 11:08:17 +0900 | [diff] [blame] | 1276 | |
| 1277 | /* E-MAC Interrupt Enable register */ |
Yoshihiro Shimoda | 525b807 | 2012-06-26 20:00:03 +0000 | [diff] [blame] | 1278 | if (start) |
| 1279 | sh_eth_write(ndev, mdp->cd->ecsipr_value, ECSIPR); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1280 | |
| 1281 | /* Set MAC address */ |
| 1282 | update_mac_address(ndev); |
| 1283 | |
| 1284 | /* mask reset */ |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 1285 | if (mdp->cd->apr) |
Yoshihiro Shimoda | 4a55530 | 2011-03-07 21:59:26 +0000 | [diff] [blame] | 1286 | sh_eth_write(ndev, APR_AP, APR); |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 1287 | if (mdp->cd->mpr) |
Yoshihiro Shimoda | 4a55530 | 2011-03-07 21:59:26 +0000 | [diff] [blame] | 1288 | sh_eth_write(ndev, MPR_MP, MPR); |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 1289 | if (mdp->cd->tpauser) |
Yoshihiro Shimoda | 4a55530 | 2011-03-07 21:59:26 +0000 | [diff] [blame] | 1290 | sh_eth_write(ndev, TPAUSER_UNLIMITED, TPAUSER); |
Nobuhiro Iwamatsu | b0ca2a2 | 2008-06-30 11:08:17 +0900 | [diff] [blame] | 1291 | |
Yoshihiro Shimoda | 525b807 | 2012-06-26 20:00:03 +0000 | [diff] [blame] | 1292 | if (start) { |
| 1293 | /* Setting the Rx mode will start the Rx process. */ |
| 1294 | sh_eth_write(ndev, EDRRR_R, EDRRR); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1295 | |
Yoshihiro Shimoda | 525b807 | 2012-06-26 20:00:03 +0000 | [diff] [blame] | 1296 | netif_start_queue(ndev); |
| 1297 | } |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1298 | |
Nobuhiro Iwamatsu | 5cee1d3 | 2012-06-25 17:35:12 +0000 | [diff] [blame] | 1299 | out: |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1300 | return ret; |
| 1301 | } |
| 1302 | |
| 1303 | /* free Tx skb function */ |
| 1304 | static int sh_eth_txfree(struct net_device *ndev) |
| 1305 | { |
| 1306 | struct sh_eth_private *mdp = netdev_priv(ndev); |
| 1307 | struct sh_eth_txdesc *txdesc; |
| 1308 | int freeNum = 0; |
| 1309 | int entry = 0; |
| 1310 | |
| 1311 | for (; mdp->cur_tx - mdp->dirty_tx > 0; mdp->dirty_tx++) { |
Yoshihiro Shimoda | 525b807 | 2012-06-26 20:00:03 +0000 | [diff] [blame] | 1312 | entry = mdp->dirty_tx % mdp->num_tx_ring; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1313 | txdesc = &mdp->tx_ring[entry]; |
Yoshinori Sato | 71557a3 | 2008-08-06 19:49:00 -0400 | [diff] [blame] | 1314 | if (txdesc->status & cpu_to_edmac(mdp, TD_TACT)) |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1315 | break; |
| 1316 | /* Free the original skb. */ |
| 1317 | if (mdp->tx_skbuff[entry]) { |
Yoshihiro Shimoda | 31fcb99 | 2011-06-30 22:52:13 +0000 | [diff] [blame] | 1318 | dma_unmap_single(&ndev->dev, txdesc->addr, |
| 1319 | txdesc->buffer_length, DMA_TO_DEVICE); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1320 | dev_kfree_skb_irq(mdp->tx_skbuff[entry]); |
| 1321 | mdp->tx_skbuff[entry] = NULL; |
| 1322 | freeNum++; |
| 1323 | } |
Yoshinori Sato | 71557a3 | 2008-08-06 19:49:00 -0400 | [diff] [blame] | 1324 | txdesc->status = cpu_to_edmac(mdp, TD_TFP); |
Yoshihiro Shimoda | 525b807 | 2012-06-26 20:00:03 +0000 | [diff] [blame] | 1325 | if (entry >= mdp->num_tx_ring - 1) |
Yoshinori Sato | 71557a3 | 2008-08-06 19:49:00 -0400 | [diff] [blame] | 1326 | txdesc->status |= cpu_to_edmac(mdp, TD_TDLE); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1327 | |
Eric Dumazet | bb7d92e | 2012-02-06 22:17:21 +0000 | [diff] [blame] | 1328 | ndev->stats.tx_packets++; |
| 1329 | ndev->stats.tx_bytes += txdesc->buffer_length; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1330 | } |
| 1331 | return freeNum; |
| 1332 | } |
| 1333 | |
| 1334 | /* Packet receive function */ |
Yoshihiro Shimoda | a18e08b | 2012-06-20 15:26:34 +0000 | [diff] [blame] | 1335 | static int sh_eth_rx(struct net_device *ndev, u32 intr_status) |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1336 | { |
| 1337 | struct sh_eth_private *mdp = netdev_priv(ndev); |
| 1338 | struct sh_eth_rxdesc *rxdesc; |
| 1339 | |
Yoshihiro Shimoda | 525b807 | 2012-06-26 20:00:03 +0000 | [diff] [blame] | 1340 | int entry = mdp->cur_rx % mdp->num_rx_ring; |
| 1341 | int boguscnt = (mdp->dirty_rx + mdp->num_rx_ring) - mdp->cur_rx; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1342 | struct sk_buff *skb; |
| 1343 | u16 pkt_len = 0; |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 1344 | u32 desc_status; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1345 | |
| 1346 | rxdesc = &mdp->rx_ring[entry]; |
Yoshinori Sato | 71557a3 | 2008-08-06 19:49:00 -0400 | [diff] [blame] | 1347 | while (!(rxdesc->status & cpu_to_edmac(mdp, RD_RACT))) { |
| 1348 | desc_status = edmac_to_cpu(mdp, rxdesc->status); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1349 | pkt_len = rxdesc->frame_length; |
| 1350 | |
Yoshihiro Shimoda | 73a0d90 | 2012-04-04 18:37:10 +0000 | [diff] [blame] | 1351 | #if defined(CONFIG_ARCH_R8A7740) |
| 1352 | desc_status >>= 16; |
| 1353 | #endif |
| 1354 | |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1355 | if (--boguscnt < 0) |
| 1356 | break; |
| 1357 | |
| 1358 | if (!(desc_status & RDFEND)) |
Eric Dumazet | bb7d92e | 2012-02-06 22:17:21 +0000 | [diff] [blame] | 1359 | ndev->stats.rx_length_errors++; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1360 | |
| 1361 | if (desc_status & (RD_RFS1 | RD_RFS2 | RD_RFS3 | RD_RFS4 | |
| 1362 | RD_RFS5 | RD_RFS6 | RD_RFS10)) { |
Eric Dumazet | bb7d92e | 2012-02-06 22:17:21 +0000 | [diff] [blame] | 1363 | ndev->stats.rx_errors++; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1364 | if (desc_status & RD_RFS1) |
Eric Dumazet | bb7d92e | 2012-02-06 22:17:21 +0000 | [diff] [blame] | 1365 | ndev->stats.rx_crc_errors++; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1366 | if (desc_status & RD_RFS2) |
Eric Dumazet | bb7d92e | 2012-02-06 22:17:21 +0000 | [diff] [blame] | 1367 | ndev->stats.rx_frame_errors++; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1368 | if (desc_status & RD_RFS3) |
Eric Dumazet | bb7d92e | 2012-02-06 22:17:21 +0000 | [diff] [blame] | 1369 | ndev->stats.rx_length_errors++; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1370 | if (desc_status & RD_RFS4) |
Eric Dumazet | bb7d92e | 2012-02-06 22:17:21 +0000 | [diff] [blame] | 1371 | ndev->stats.rx_length_errors++; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1372 | if (desc_status & RD_RFS6) |
Eric Dumazet | bb7d92e | 2012-02-06 22:17:21 +0000 | [diff] [blame] | 1373 | ndev->stats.rx_missed_errors++; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1374 | if (desc_status & RD_RFS10) |
Eric Dumazet | bb7d92e | 2012-02-06 22:17:21 +0000 | [diff] [blame] | 1375 | ndev->stats.rx_over_errors++; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1376 | } else { |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 1377 | if (!mdp->cd->hw_swap) |
| 1378 | sh_eth_soft_swap( |
| 1379 | phys_to_virt(ALIGN(rxdesc->addr, 4)), |
| 1380 | pkt_len + 2); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1381 | skb = mdp->rx_skbuff[entry]; |
| 1382 | mdp->rx_skbuff[entry] = NULL; |
Magnus Damm | 503914c | 2009-12-15 21:16:55 -0800 | [diff] [blame] | 1383 | if (mdp->cd->rpadir) |
| 1384 | skb_reserve(skb, NET_IP_ALIGN); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1385 | skb_put(skb, pkt_len); |
| 1386 | skb->protocol = eth_type_trans(skb, ndev); |
| 1387 | netif_rx(skb); |
Eric Dumazet | bb7d92e | 2012-02-06 22:17:21 +0000 | [diff] [blame] | 1388 | ndev->stats.rx_packets++; |
| 1389 | ndev->stats.rx_bytes += pkt_len; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1390 | } |
Yoshinori Sato | 71557a3 | 2008-08-06 19:49:00 -0400 | [diff] [blame] | 1391 | rxdesc->status |= cpu_to_edmac(mdp, RD_RACT); |
Yoshihiro Shimoda | 525b807 | 2012-06-26 20:00:03 +0000 | [diff] [blame] | 1392 | entry = (++mdp->cur_rx) % mdp->num_rx_ring; |
Yoshihiro Shimoda | 862df49 | 2009-05-24 23:53:40 +0000 | [diff] [blame] | 1393 | rxdesc = &mdp->rx_ring[entry]; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1394 | } |
| 1395 | |
| 1396 | /* Refill the Rx ring buffers. */ |
| 1397 | for (; mdp->cur_rx - mdp->dirty_rx > 0; mdp->dirty_rx++) { |
Yoshihiro Shimoda | 525b807 | 2012-06-26 20:00:03 +0000 | [diff] [blame] | 1398 | entry = mdp->dirty_rx % mdp->num_rx_ring; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1399 | rxdesc = &mdp->rx_ring[entry]; |
Nobuhiro Iwamatsu | b0ca2a2 | 2008-06-30 11:08:17 +0900 | [diff] [blame] | 1400 | /* The size of the buffer is 16 byte boundary. */ |
Yoshihiro Shimoda | 0029d64 | 2009-05-24 23:53:20 +0000 | [diff] [blame] | 1401 | rxdesc->buffer_length = ALIGN(mdp->rx_buf_sz, 16); |
Nobuhiro Iwamatsu | b0ca2a2 | 2008-06-30 11:08:17 +0900 | [diff] [blame] | 1402 | |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1403 | if (mdp->rx_skbuff[entry] == NULL) { |
Pradeep A. Dalvi | dae2e9f | 2012-02-06 11:16:13 +0000 | [diff] [blame] | 1404 | skb = netdev_alloc_skb(ndev, mdp->rx_buf_sz); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1405 | mdp->rx_skbuff[entry] = skb; |
| 1406 | if (skb == NULL) |
| 1407 | break; /* Better luck next round. */ |
Eric Dumazet | bb7d92e | 2012-02-06 22:17:21 +0000 | [diff] [blame] | 1408 | dma_map_single(&ndev->dev, skb->data, mdp->rx_buf_sz, |
Yoshihiro Shimoda | e88aae7 | 2009-05-24 23:52:35 +0000 | [diff] [blame] | 1409 | DMA_FROM_DEVICE); |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 1410 | sh_eth_set_receive_align(skb); |
| 1411 | |
Eric Dumazet | bc8acf2 | 2010-09-02 13:07:41 -0700 | [diff] [blame] | 1412 | skb_checksum_none_assert(skb); |
Yoshihiro Shimoda | 0029d64 | 2009-05-24 23:53:20 +0000 | [diff] [blame] | 1413 | rxdesc->addr = virt_to_phys(PTR_ALIGN(skb->data, 4)); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1414 | } |
Yoshihiro Shimoda | 525b807 | 2012-06-26 20:00:03 +0000 | [diff] [blame] | 1415 | if (entry >= mdp->num_rx_ring - 1) |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1416 | rxdesc->status |= |
Yoshinori Sato | 71557a3 | 2008-08-06 19:49:00 -0400 | [diff] [blame] | 1417 | cpu_to_edmac(mdp, RD_RACT | RD_RFP | RD_RDEL); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1418 | else |
| 1419 | rxdesc->status |= |
Yoshinori Sato | 71557a3 | 2008-08-06 19:49:00 -0400 | [diff] [blame] | 1420 | cpu_to_edmac(mdp, RD_RACT | RD_RFP); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1421 | } |
| 1422 | |
| 1423 | /* Restart Rx engine if stopped. */ |
| 1424 | /* If we don't need to check status, don't. -KDU */ |
Yoshihiro Shimoda | 79fba9f | 2012-05-28 23:07:55 +0000 | [diff] [blame] | 1425 | if (!(sh_eth_read(ndev, EDRRR) & EDRRR_R)) { |
Yoshihiro Shimoda | a18e08b | 2012-06-20 15:26:34 +0000 | [diff] [blame] | 1426 | /* fix the values for the next receiving if RDE is set */ |
| 1427 | if (intr_status & EESR_RDE) |
| 1428 | mdp->cur_rx = mdp->dirty_rx = |
| 1429 | (sh_eth_read(ndev, RDFAR) - |
| 1430 | sh_eth_read(ndev, RDLAR)) >> 4; |
Yoshihiro Shimoda | 4a55530 | 2011-03-07 21:59:26 +0000 | [diff] [blame] | 1431 | sh_eth_write(ndev, EDRRR_R, EDRRR); |
Yoshihiro Shimoda | 79fba9f | 2012-05-28 23:07:55 +0000 | [diff] [blame] | 1432 | } |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1433 | |
| 1434 | return 0; |
| 1435 | } |
| 1436 | |
Yoshihiro Shimoda | 4a55530 | 2011-03-07 21:59:26 +0000 | [diff] [blame] | 1437 | static void sh_eth_rcv_snd_disable(struct net_device *ndev) |
Nobuhiro Iwamatsu | dc19e4e | 2011-02-15 21:17:32 +0000 | [diff] [blame] | 1438 | { |
| 1439 | /* disable tx and rx */ |
Yoshihiro Shimoda | 4a55530 | 2011-03-07 21:59:26 +0000 | [diff] [blame] | 1440 | sh_eth_write(ndev, sh_eth_read(ndev, ECMR) & |
| 1441 | ~(ECMR_RE | ECMR_TE), ECMR); |
Nobuhiro Iwamatsu | dc19e4e | 2011-02-15 21:17:32 +0000 | [diff] [blame] | 1442 | } |
| 1443 | |
Yoshihiro Shimoda | 4a55530 | 2011-03-07 21:59:26 +0000 | [diff] [blame] | 1444 | static void sh_eth_rcv_snd_enable(struct net_device *ndev) |
Nobuhiro Iwamatsu | dc19e4e | 2011-02-15 21:17:32 +0000 | [diff] [blame] | 1445 | { |
| 1446 | /* enable tx and rx */ |
Yoshihiro Shimoda | 4a55530 | 2011-03-07 21:59:26 +0000 | [diff] [blame] | 1447 | sh_eth_write(ndev, sh_eth_read(ndev, ECMR) | |
| 1448 | (ECMR_RE | ECMR_TE), ECMR); |
Nobuhiro Iwamatsu | dc19e4e | 2011-02-15 21:17:32 +0000 | [diff] [blame] | 1449 | } |
| 1450 | |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1451 | /* error control function */ |
| 1452 | static void sh_eth_error(struct net_device *ndev, int intr_status) |
| 1453 | { |
| 1454 | struct sh_eth_private *mdp = netdev_priv(ndev); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1455 | u32 felic_stat; |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 1456 | u32 link_stat; |
| 1457 | u32 mask; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1458 | |
| 1459 | if (intr_status & EESR_ECI) { |
Yoshihiro Shimoda | 4a55530 | 2011-03-07 21:59:26 +0000 | [diff] [blame] | 1460 | felic_stat = sh_eth_read(ndev, ECSR); |
| 1461 | sh_eth_write(ndev, felic_stat, ECSR); /* clear int */ |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1462 | if (felic_stat & ECSR_ICD) |
Eric Dumazet | bb7d92e | 2012-02-06 22:17:21 +0000 | [diff] [blame] | 1463 | ndev->stats.tx_carrier_errors++; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1464 | if (felic_stat & ECSR_LCHNG) { |
| 1465 | /* Link Changed */ |
Yoshihiro Shimoda | 4923576 | 2009-08-27 23:25:03 +0000 | [diff] [blame] | 1466 | if (mdp->cd->no_psr || mdp->no_ether_link) { |
Sergei Shtylyov | 1e1b812 | 2013-03-31 09:50:07 +0000 | [diff] [blame] | 1467 | goto ignore_link; |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 1468 | } else { |
Yoshihiro Shimoda | 4a55530 | 2011-03-07 21:59:26 +0000 | [diff] [blame] | 1469 | link_stat = (sh_eth_read(ndev, PSR)); |
Yoshihiro Shimoda | 4923576 | 2009-08-27 23:25:03 +0000 | [diff] [blame] | 1470 | if (mdp->ether_link_active_low) |
| 1471 | link_stat = ~link_stat; |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 1472 | } |
Nobuhiro Iwamatsu | dc19e4e | 2011-02-15 21:17:32 +0000 | [diff] [blame] | 1473 | if (!(link_stat & PHY_ST_LINK)) |
Yoshihiro Shimoda | 4a55530 | 2011-03-07 21:59:26 +0000 | [diff] [blame] | 1474 | sh_eth_rcv_snd_disable(ndev); |
Nobuhiro Iwamatsu | dc19e4e | 2011-02-15 21:17:32 +0000 | [diff] [blame] | 1475 | else { |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1476 | /* Link Up */ |
Yoshihiro Shimoda | 4a55530 | 2011-03-07 21:59:26 +0000 | [diff] [blame] | 1477 | sh_eth_write(ndev, sh_eth_read(ndev, EESIPR) & |
| 1478 | ~DMAC_M_ECI, EESIPR); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1479 | /*clear int */ |
Yoshihiro Shimoda | 4a55530 | 2011-03-07 21:59:26 +0000 | [diff] [blame] | 1480 | sh_eth_write(ndev, sh_eth_read(ndev, ECSR), |
| 1481 | ECSR); |
| 1482 | sh_eth_write(ndev, sh_eth_read(ndev, EESIPR) | |
| 1483 | DMAC_M_ECI, EESIPR); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1484 | /* enable tx and rx */ |
Yoshihiro Shimoda | 4a55530 | 2011-03-07 21:59:26 +0000 | [diff] [blame] | 1485 | sh_eth_rcv_snd_enable(ndev); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1486 | } |
| 1487 | } |
| 1488 | } |
| 1489 | |
Sergei Shtylyov | 1e1b812 | 2013-03-31 09:50:07 +0000 | [diff] [blame] | 1490 | ignore_link: |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1491 | if (intr_status & EESR_TWB) { |
| 1492 | /* Write buck end. unused write back interrupt */ |
| 1493 | if (intr_status & EESR_TABT) /* Transmit Abort int */ |
Eric Dumazet | bb7d92e | 2012-02-06 22:17:21 +0000 | [diff] [blame] | 1494 | ndev->stats.tx_aborted_errors++; |
Nobuhiro Iwamatsu | dc19e4e | 2011-02-15 21:17:32 +0000 | [diff] [blame] | 1495 | if (netif_msg_tx_err(mdp)) |
| 1496 | dev_err(&ndev->dev, "Transmit Abort\n"); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1497 | } |
| 1498 | |
| 1499 | if (intr_status & EESR_RABT) { |
| 1500 | /* Receive Abort int */ |
| 1501 | if (intr_status & EESR_RFRMER) { |
| 1502 | /* Receive Frame Overflow int */ |
Eric Dumazet | bb7d92e | 2012-02-06 22:17:21 +0000 | [diff] [blame] | 1503 | ndev->stats.rx_frame_errors++; |
Nobuhiro Iwamatsu | dc19e4e | 2011-02-15 21:17:32 +0000 | [diff] [blame] | 1504 | if (netif_msg_rx_err(mdp)) |
| 1505 | dev_err(&ndev->dev, "Receive Abort\n"); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1506 | } |
| 1507 | } |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 1508 | |
Nobuhiro Iwamatsu | dc19e4e | 2011-02-15 21:17:32 +0000 | [diff] [blame] | 1509 | if (intr_status & EESR_TDE) { |
| 1510 | /* Transmit Descriptor Empty int */ |
Eric Dumazet | bb7d92e | 2012-02-06 22:17:21 +0000 | [diff] [blame] | 1511 | ndev->stats.tx_fifo_errors++; |
Nobuhiro Iwamatsu | dc19e4e | 2011-02-15 21:17:32 +0000 | [diff] [blame] | 1512 | if (netif_msg_tx_err(mdp)) |
| 1513 | dev_err(&ndev->dev, "Transmit Descriptor Empty\n"); |
| 1514 | } |
| 1515 | |
| 1516 | if (intr_status & EESR_TFE) { |
| 1517 | /* FIFO under flow */ |
Eric Dumazet | bb7d92e | 2012-02-06 22:17:21 +0000 | [diff] [blame] | 1518 | ndev->stats.tx_fifo_errors++; |
Nobuhiro Iwamatsu | dc19e4e | 2011-02-15 21:17:32 +0000 | [diff] [blame] | 1519 | if (netif_msg_tx_err(mdp)) |
| 1520 | dev_err(&ndev->dev, "Transmit FIFO Under flow\n"); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1521 | } |
| 1522 | |
| 1523 | if (intr_status & EESR_RDE) { |
| 1524 | /* Receive Descriptor Empty int */ |
Eric Dumazet | bb7d92e | 2012-02-06 22:17:21 +0000 | [diff] [blame] | 1525 | ndev->stats.rx_over_errors++; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1526 | |
Nobuhiro Iwamatsu | dc19e4e | 2011-02-15 21:17:32 +0000 | [diff] [blame] | 1527 | if (netif_msg_rx_err(mdp)) |
| 1528 | dev_err(&ndev->dev, "Receive Descriptor Empty\n"); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1529 | } |
Nobuhiro Iwamatsu | dc19e4e | 2011-02-15 21:17:32 +0000 | [diff] [blame] | 1530 | |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1531 | if (intr_status & EESR_RFE) { |
| 1532 | /* Receive FIFO Overflow int */ |
Eric Dumazet | bb7d92e | 2012-02-06 22:17:21 +0000 | [diff] [blame] | 1533 | ndev->stats.rx_fifo_errors++; |
Nobuhiro Iwamatsu | dc19e4e | 2011-02-15 21:17:32 +0000 | [diff] [blame] | 1534 | if (netif_msg_rx_err(mdp)) |
| 1535 | dev_err(&ndev->dev, "Receive FIFO Overflow\n"); |
| 1536 | } |
| 1537 | |
| 1538 | if (!mdp->cd->no_ade && (intr_status & EESR_ADE)) { |
| 1539 | /* Address Error */ |
Eric Dumazet | bb7d92e | 2012-02-06 22:17:21 +0000 | [diff] [blame] | 1540 | ndev->stats.tx_fifo_errors++; |
Nobuhiro Iwamatsu | dc19e4e | 2011-02-15 21:17:32 +0000 | [diff] [blame] | 1541 | if (netif_msg_tx_err(mdp)) |
| 1542 | dev_err(&ndev->dev, "Address Error\n"); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1543 | } |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 1544 | |
| 1545 | mask = EESR_TWB | EESR_TABT | EESR_ADE | EESR_TDE | EESR_TFE; |
| 1546 | if (mdp->cd->no_ade) |
| 1547 | mask &= ~EESR_ADE; |
| 1548 | if (intr_status & mask) { |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1549 | /* Tx error */ |
Yoshihiro Shimoda | 4a55530 | 2011-03-07 21:59:26 +0000 | [diff] [blame] | 1550 | u32 edtrr = sh_eth_read(ndev, EDTRR); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1551 | /* dmesg */ |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 1552 | dev_err(&ndev->dev, "TX error. status=%8.8x cur_tx=%8.8x ", |
| 1553 | intr_status, mdp->cur_tx); |
| 1554 | dev_err(&ndev->dev, "dirty_tx=%8.8x state=%8.8x EDTRR=%8.8x.\n", |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1555 | mdp->dirty_tx, (u32) ndev->state, edtrr); |
| 1556 | /* dirty buffer free */ |
| 1557 | sh_eth_txfree(ndev); |
| 1558 | |
| 1559 | /* SH7712 BUG */ |
Yoshihiro Shimoda | c5ed536 | 2011-03-07 21:59:38 +0000 | [diff] [blame] | 1560 | if (edtrr ^ sh_eth_get_edtrr_trns(mdp)) { |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1561 | /* tx dma start */ |
Yoshihiro Shimoda | c5ed536 | 2011-03-07 21:59:38 +0000 | [diff] [blame] | 1562 | sh_eth_write(ndev, sh_eth_get_edtrr_trns(mdp), EDTRR); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1563 | } |
| 1564 | /* wakeup */ |
| 1565 | netif_wake_queue(ndev); |
| 1566 | } |
| 1567 | } |
| 1568 | |
| 1569 | static irqreturn_t sh_eth_interrupt(int irq, void *netdev) |
| 1570 | { |
| 1571 | struct net_device *ndev = netdev; |
| 1572 | struct sh_eth_private *mdp = netdev_priv(ndev); |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 1573 | struct sh_eth_cpu_data *cd = mdp->cd; |
Nobuhiro Iwamatsu | 0e0fde3 | 2009-03-16 19:50:57 +0000 | [diff] [blame] | 1574 | irqreturn_t ret = IRQ_NONE; |
Sergei Shtylyov | 3893b27345 | 2013-03-31 09:54:20 +0000 | [diff] [blame] | 1575 | unsigned long intr_status; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1576 | |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1577 | spin_lock(&mdp->lock); |
| 1578 | |
Sergei Shtylyov | 3893b27345 | 2013-03-31 09:54:20 +0000 | [diff] [blame] | 1579 | /* Get interrupt status */ |
Yoshihiro Shimoda | 4a55530 | 2011-03-07 21:59:26 +0000 | [diff] [blame] | 1580 | intr_status = sh_eth_read(ndev, EESR); |
Sergei Shtylyov | 3893b27345 | 2013-03-31 09:54:20 +0000 | [diff] [blame] | 1581 | /* Mask it with the interrupt mask, forcing ECI interrupt to be always |
| 1582 | * enabled since it's the one that comes thru regardless of the mask, |
| 1583 | * and we need to fully handle it in sh_eth_error() in order to quench |
| 1584 | * it as it doesn't get cleared by just writing 1 to the ECI bit... |
| 1585 | */ |
| 1586 | intr_status &= sh_eth_read(ndev, EESIPR) | DMAC_M_ECI; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1587 | /* Clear interrupt */ |
Nobuhiro Iwamatsu | 0e0fde3 | 2009-03-16 19:50:57 +0000 | [diff] [blame] | 1588 | if (intr_status & (EESR_FRC | EESR_RMAF | EESR_RRF | |
| 1589 | EESR_RTLF | EESR_RTSF | EESR_PRE | EESR_CERF | |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 1590 | cd->tx_check | cd->eesr_err_check)) { |
Yoshihiro Shimoda | 4a55530 | 2011-03-07 21:59:26 +0000 | [diff] [blame] | 1591 | sh_eth_write(ndev, intr_status, EESR); |
Nobuhiro Iwamatsu | 0e0fde3 | 2009-03-16 19:50:57 +0000 | [diff] [blame] | 1592 | ret = IRQ_HANDLED; |
| 1593 | } else |
| 1594 | goto other_irq; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1595 | |
Nobuhiro Iwamatsu | b0ca2a2 | 2008-06-30 11:08:17 +0900 | [diff] [blame] | 1596 | if (intr_status & (EESR_FRC | /* Frame recv*/ |
| 1597 | EESR_RMAF | /* Multi cast address recv*/ |
| 1598 | EESR_RRF | /* Bit frame recv */ |
| 1599 | EESR_RTLF | /* Long frame recv*/ |
| 1600 | EESR_RTSF | /* short frame recv */ |
| 1601 | EESR_PRE | /* PHY-LSI recv error */ |
| 1602 | EESR_CERF)){ /* recv frame CRC error */ |
Yoshihiro Shimoda | a18e08b | 2012-06-20 15:26:34 +0000 | [diff] [blame] | 1603 | sh_eth_rx(ndev, intr_status); |
Nobuhiro Iwamatsu | b0ca2a2 | 2008-06-30 11:08:17 +0900 | [diff] [blame] | 1604 | } |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1605 | |
Nobuhiro Iwamatsu | b0ca2a2 | 2008-06-30 11:08:17 +0900 | [diff] [blame] | 1606 | /* Tx Check */ |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 1607 | if (intr_status & cd->tx_check) { |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1608 | sh_eth_txfree(ndev); |
| 1609 | netif_wake_queue(ndev); |
| 1610 | } |
| 1611 | |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 1612 | if (intr_status & cd->eesr_err_check) |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1613 | sh_eth_error(ndev, intr_status); |
| 1614 | |
Nobuhiro Iwamatsu | 0e0fde3 | 2009-03-16 19:50:57 +0000 | [diff] [blame] | 1615 | other_irq: |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1616 | spin_unlock(&mdp->lock); |
| 1617 | |
Nobuhiro Iwamatsu | 0e0fde3 | 2009-03-16 19:50:57 +0000 | [diff] [blame] | 1618 | return ret; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1619 | } |
| 1620 | |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1621 | /* PHY state control function */ |
| 1622 | static void sh_eth_adjust_link(struct net_device *ndev) |
| 1623 | { |
| 1624 | struct sh_eth_private *mdp = netdev_priv(ndev); |
| 1625 | struct phy_device *phydev = mdp->phydev; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1626 | int new_state = 0; |
| 1627 | |
Sergei Shtylyov | 3340d2a | 2013-03-31 10:11:04 +0000 | [diff] [blame] | 1628 | if (phydev->link) { |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1629 | if (phydev->duplex != mdp->duplex) { |
| 1630 | new_state = 1; |
| 1631 | mdp->duplex = phydev->duplex; |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 1632 | if (mdp->cd->set_duplex) |
| 1633 | mdp->cd->set_duplex(ndev); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1634 | } |
| 1635 | |
| 1636 | if (phydev->speed != mdp->speed) { |
| 1637 | new_state = 1; |
| 1638 | mdp->speed = phydev->speed; |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 1639 | if (mdp->cd->set_rate) |
| 1640 | mdp->cd->set_rate(ndev); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1641 | } |
Sergei Shtylyov | 3340d2a | 2013-03-31 10:11:04 +0000 | [diff] [blame] | 1642 | if (!mdp->link) { |
Yoshihiro Shimoda | 91a5615 | 2011-07-05 20:33:51 +0000 | [diff] [blame] | 1643 | sh_eth_write(ndev, |
| 1644 | (sh_eth_read(ndev, ECMR) & ~ECMR_TXF), ECMR); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1645 | new_state = 1; |
| 1646 | mdp->link = phydev->link; |
Sergei Shtylyov | 1e1b812 | 2013-03-31 09:50:07 +0000 | [diff] [blame] | 1647 | if (mdp->cd->no_psr || mdp->no_ether_link) |
| 1648 | sh_eth_rcv_snd_enable(ndev); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1649 | } |
| 1650 | } else if (mdp->link) { |
| 1651 | new_state = 1; |
Sergei Shtylyov | 3340d2a | 2013-03-31 10:11:04 +0000 | [diff] [blame] | 1652 | mdp->link = 0; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1653 | mdp->speed = 0; |
| 1654 | mdp->duplex = -1; |
Sergei Shtylyov | 1e1b812 | 2013-03-31 09:50:07 +0000 | [diff] [blame] | 1655 | if (mdp->cd->no_psr || mdp->no_ether_link) |
| 1656 | sh_eth_rcv_snd_disable(ndev); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1657 | } |
| 1658 | |
Nobuhiro Iwamatsu | dc19e4e | 2011-02-15 21:17:32 +0000 | [diff] [blame] | 1659 | if (new_state && netif_msg_link(mdp)) |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1660 | phy_print_status(phydev); |
| 1661 | } |
| 1662 | |
| 1663 | /* PHY init function */ |
| 1664 | static int sh_eth_phy_init(struct net_device *ndev) |
| 1665 | { |
| 1666 | struct sh_eth_private *mdp = netdev_priv(ndev); |
David S. Miller | 0a372eb | 2009-05-26 21:11:09 -0700 | [diff] [blame] | 1667 | char phy_id[MII_BUS_ID_SIZE + 3]; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1668 | struct phy_device *phydev = NULL; |
| 1669 | |
Kay Sievers | fb28ad3 | 2008-11-10 13:55:14 -0800 | [diff] [blame] | 1670 | snprintf(phy_id, sizeof(phy_id), PHY_ID_FMT, |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1671 | mdp->mii_bus->id , mdp->phy_id); |
| 1672 | |
Sergei Shtylyov | 3340d2a | 2013-03-31 10:11:04 +0000 | [diff] [blame] | 1673 | mdp->link = 0; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1674 | mdp->speed = 0; |
| 1675 | mdp->duplex = -1; |
| 1676 | |
| 1677 | /* Try connect to PHY */ |
Joe Perches | c061b18 | 2010-08-23 18:20:03 +0000 | [diff] [blame] | 1678 | phydev = phy_connect(ndev, phy_id, sh_eth_adjust_link, |
Florian Fainelli | f9a8f83 | 2013-01-14 00:52:52 +0000 | [diff] [blame] | 1679 | mdp->phy_interface); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1680 | if (IS_ERR(phydev)) { |
| 1681 | dev_err(&ndev->dev, "phy_connect failed\n"); |
| 1682 | return PTR_ERR(phydev); |
| 1683 | } |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 1684 | |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1685 | dev_info(&ndev->dev, "attached phy %i to driver %s\n", |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 1686 | phydev->addr, phydev->drv->name); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1687 | |
| 1688 | mdp->phydev = phydev; |
| 1689 | |
| 1690 | return 0; |
| 1691 | } |
| 1692 | |
| 1693 | /* PHY control start function */ |
| 1694 | static int sh_eth_phy_start(struct net_device *ndev) |
| 1695 | { |
| 1696 | struct sh_eth_private *mdp = netdev_priv(ndev); |
| 1697 | int ret; |
| 1698 | |
| 1699 | ret = sh_eth_phy_init(ndev); |
| 1700 | if (ret) |
| 1701 | return ret; |
| 1702 | |
| 1703 | /* reset phy - this also wakes it from PDOWN */ |
| 1704 | phy_write(mdp->phydev, MII_BMCR, BMCR_RESET); |
| 1705 | phy_start(mdp->phydev); |
| 1706 | |
| 1707 | return 0; |
| 1708 | } |
| 1709 | |
Nobuhiro Iwamatsu | dc19e4e | 2011-02-15 21:17:32 +0000 | [diff] [blame] | 1710 | static int sh_eth_get_settings(struct net_device *ndev, |
| 1711 | struct ethtool_cmd *ecmd) |
| 1712 | { |
| 1713 | struct sh_eth_private *mdp = netdev_priv(ndev); |
| 1714 | unsigned long flags; |
| 1715 | int ret; |
| 1716 | |
| 1717 | spin_lock_irqsave(&mdp->lock, flags); |
| 1718 | ret = phy_ethtool_gset(mdp->phydev, ecmd); |
| 1719 | spin_unlock_irqrestore(&mdp->lock, flags); |
| 1720 | |
| 1721 | return ret; |
| 1722 | } |
| 1723 | |
| 1724 | static int sh_eth_set_settings(struct net_device *ndev, |
| 1725 | struct ethtool_cmd *ecmd) |
| 1726 | { |
| 1727 | struct sh_eth_private *mdp = netdev_priv(ndev); |
| 1728 | unsigned long flags; |
| 1729 | int ret; |
Nobuhiro Iwamatsu | dc19e4e | 2011-02-15 21:17:32 +0000 | [diff] [blame] | 1730 | |
| 1731 | spin_lock_irqsave(&mdp->lock, flags); |
| 1732 | |
| 1733 | /* disable tx and rx */ |
Yoshihiro Shimoda | 4a55530 | 2011-03-07 21:59:26 +0000 | [diff] [blame] | 1734 | sh_eth_rcv_snd_disable(ndev); |
Nobuhiro Iwamatsu | dc19e4e | 2011-02-15 21:17:32 +0000 | [diff] [blame] | 1735 | |
| 1736 | ret = phy_ethtool_sset(mdp->phydev, ecmd); |
| 1737 | if (ret) |
| 1738 | goto error_exit; |
| 1739 | |
| 1740 | if (ecmd->duplex == DUPLEX_FULL) |
| 1741 | mdp->duplex = 1; |
| 1742 | else |
| 1743 | mdp->duplex = 0; |
| 1744 | |
| 1745 | if (mdp->cd->set_duplex) |
| 1746 | mdp->cd->set_duplex(ndev); |
| 1747 | |
| 1748 | error_exit: |
| 1749 | mdelay(1); |
| 1750 | |
| 1751 | /* enable tx and rx */ |
Yoshihiro Shimoda | 4a55530 | 2011-03-07 21:59:26 +0000 | [diff] [blame] | 1752 | sh_eth_rcv_snd_enable(ndev); |
Nobuhiro Iwamatsu | dc19e4e | 2011-02-15 21:17:32 +0000 | [diff] [blame] | 1753 | |
| 1754 | spin_unlock_irqrestore(&mdp->lock, flags); |
| 1755 | |
| 1756 | return ret; |
| 1757 | } |
| 1758 | |
| 1759 | static int sh_eth_nway_reset(struct net_device *ndev) |
| 1760 | { |
| 1761 | struct sh_eth_private *mdp = netdev_priv(ndev); |
| 1762 | unsigned long flags; |
| 1763 | int ret; |
| 1764 | |
| 1765 | spin_lock_irqsave(&mdp->lock, flags); |
| 1766 | ret = phy_start_aneg(mdp->phydev); |
| 1767 | spin_unlock_irqrestore(&mdp->lock, flags); |
| 1768 | |
| 1769 | return ret; |
| 1770 | } |
| 1771 | |
| 1772 | static u32 sh_eth_get_msglevel(struct net_device *ndev) |
| 1773 | { |
| 1774 | struct sh_eth_private *mdp = netdev_priv(ndev); |
| 1775 | return mdp->msg_enable; |
| 1776 | } |
| 1777 | |
| 1778 | static void sh_eth_set_msglevel(struct net_device *ndev, u32 value) |
| 1779 | { |
| 1780 | struct sh_eth_private *mdp = netdev_priv(ndev); |
| 1781 | mdp->msg_enable = value; |
| 1782 | } |
| 1783 | |
| 1784 | static const char sh_eth_gstrings_stats[][ETH_GSTRING_LEN] = { |
| 1785 | "rx_current", "tx_current", |
| 1786 | "rx_dirty", "tx_dirty", |
| 1787 | }; |
| 1788 | #define SH_ETH_STATS_LEN ARRAY_SIZE(sh_eth_gstrings_stats) |
| 1789 | |
| 1790 | static int sh_eth_get_sset_count(struct net_device *netdev, int sset) |
| 1791 | { |
| 1792 | switch (sset) { |
| 1793 | case ETH_SS_STATS: |
| 1794 | return SH_ETH_STATS_LEN; |
| 1795 | default: |
| 1796 | return -EOPNOTSUPP; |
| 1797 | } |
| 1798 | } |
| 1799 | |
| 1800 | static void sh_eth_get_ethtool_stats(struct net_device *ndev, |
| 1801 | struct ethtool_stats *stats, u64 *data) |
| 1802 | { |
| 1803 | struct sh_eth_private *mdp = netdev_priv(ndev); |
| 1804 | int i = 0; |
| 1805 | |
| 1806 | /* device-specific stats */ |
| 1807 | data[i++] = mdp->cur_rx; |
| 1808 | data[i++] = mdp->cur_tx; |
| 1809 | data[i++] = mdp->dirty_rx; |
| 1810 | data[i++] = mdp->dirty_tx; |
| 1811 | } |
| 1812 | |
| 1813 | static void sh_eth_get_strings(struct net_device *ndev, u32 stringset, u8 *data) |
| 1814 | { |
| 1815 | switch (stringset) { |
| 1816 | case ETH_SS_STATS: |
| 1817 | memcpy(data, *sh_eth_gstrings_stats, |
| 1818 | sizeof(sh_eth_gstrings_stats)); |
| 1819 | break; |
| 1820 | } |
| 1821 | } |
| 1822 | |
Yoshihiro Shimoda | 525b807 | 2012-06-26 20:00:03 +0000 | [diff] [blame] | 1823 | static void sh_eth_get_ringparam(struct net_device *ndev, |
| 1824 | struct ethtool_ringparam *ring) |
| 1825 | { |
| 1826 | struct sh_eth_private *mdp = netdev_priv(ndev); |
| 1827 | |
| 1828 | ring->rx_max_pending = RX_RING_MAX; |
| 1829 | ring->tx_max_pending = TX_RING_MAX; |
| 1830 | ring->rx_pending = mdp->num_rx_ring; |
| 1831 | ring->tx_pending = mdp->num_tx_ring; |
| 1832 | } |
| 1833 | |
| 1834 | static int sh_eth_set_ringparam(struct net_device *ndev, |
| 1835 | struct ethtool_ringparam *ring) |
| 1836 | { |
| 1837 | struct sh_eth_private *mdp = netdev_priv(ndev); |
| 1838 | int ret; |
| 1839 | |
| 1840 | if (ring->tx_pending > TX_RING_MAX || |
| 1841 | ring->rx_pending > RX_RING_MAX || |
| 1842 | ring->tx_pending < TX_RING_MIN || |
| 1843 | ring->rx_pending < RX_RING_MIN) |
| 1844 | return -EINVAL; |
| 1845 | if (ring->rx_mini_pending || ring->rx_jumbo_pending) |
| 1846 | return -EINVAL; |
| 1847 | |
| 1848 | if (netif_running(ndev)) { |
| 1849 | netif_tx_disable(ndev); |
| 1850 | /* Disable interrupts by clearing the interrupt mask. */ |
| 1851 | sh_eth_write(ndev, 0x0000, EESIPR); |
| 1852 | /* Stop the chip's Tx and Rx processes. */ |
| 1853 | sh_eth_write(ndev, 0, EDTRR); |
| 1854 | sh_eth_write(ndev, 0, EDRRR); |
| 1855 | synchronize_irq(ndev->irq); |
| 1856 | } |
| 1857 | |
| 1858 | /* Free all the skbuffs in the Rx queue. */ |
| 1859 | sh_eth_ring_free(ndev); |
| 1860 | /* Free DMA buffer */ |
| 1861 | sh_eth_free_dma_buffer(mdp); |
| 1862 | |
| 1863 | /* Set new parameters */ |
| 1864 | mdp->num_rx_ring = ring->rx_pending; |
| 1865 | mdp->num_tx_ring = ring->tx_pending; |
| 1866 | |
| 1867 | ret = sh_eth_ring_init(ndev); |
| 1868 | if (ret < 0) { |
| 1869 | dev_err(&ndev->dev, "%s: sh_eth_ring_init failed.\n", __func__); |
| 1870 | return ret; |
| 1871 | } |
| 1872 | ret = sh_eth_dev_init(ndev, false); |
| 1873 | if (ret < 0) { |
| 1874 | dev_err(&ndev->dev, "%s: sh_eth_dev_init failed.\n", __func__); |
| 1875 | return ret; |
| 1876 | } |
| 1877 | |
| 1878 | if (netif_running(ndev)) { |
| 1879 | sh_eth_write(ndev, mdp->cd->eesipr_value, EESIPR); |
| 1880 | /* Setting the Rx mode will start the Rx process. */ |
| 1881 | sh_eth_write(ndev, EDRRR_R, EDRRR); |
| 1882 | netif_wake_queue(ndev); |
| 1883 | } |
| 1884 | |
| 1885 | return 0; |
| 1886 | } |
| 1887 | |
stephen hemminger | 9b07be4 | 2012-01-04 12:59:49 +0000 | [diff] [blame] | 1888 | static const struct ethtool_ops sh_eth_ethtool_ops = { |
Nobuhiro Iwamatsu | dc19e4e | 2011-02-15 21:17:32 +0000 | [diff] [blame] | 1889 | .get_settings = sh_eth_get_settings, |
| 1890 | .set_settings = sh_eth_set_settings, |
stephen hemminger | 9b07be4 | 2012-01-04 12:59:49 +0000 | [diff] [blame] | 1891 | .nway_reset = sh_eth_nway_reset, |
Nobuhiro Iwamatsu | dc19e4e | 2011-02-15 21:17:32 +0000 | [diff] [blame] | 1892 | .get_msglevel = sh_eth_get_msglevel, |
| 1893 | .set_msglevel = sh_eth_set_msglevel, |
stephen hemminger | 9b07be4 | 2012-01-04 12:59:49 +0000 | [diff] [blame] | 1894 | .get_link = ethtool_op_get_link, |
Nobuhiro Iwamatsu | dc19e4e | 2011-02-15 21:17:32 +0000 | [diff] [blame] | 1895 | .get_strings = sh_eth_get_strings, |
| 1896 | .get_ethtool_stats = sh_eth_get_ethtool_stats, |
| 1897 | .get_sset_count = sh_eth_get_sset_count, |
Yoshihiro Shimoda | 525b807 | 2012-06-26 20:00:03 +0000 | [diff] [blame] | 1898 | .get_ringparam = sh_eth_get_ringparam, |
| 1899 | .set_ringparam = sh_eth_set_ringparam, |
Nobuhiro Iwamatsu | dc19e4e | 2011-02-15 21:17:32 +0000 | [diff] [blame] | 1900 | }; |
| 1901 | |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1902 | /* network device open function */ |
| 1903 | static int sh_eth_open(struct net_device *ndev) |
| 1904 | { |
| 1905 | int ret = 0; |
| 1906 | struct sh_eth_private *mdp = netdev_priv(ndev); |
| 1907 | |
Magnus Damm | bcd5149 | 2009-10-09 00:20:04 +0000 | [diff] [blame] | 1908 | pm_runtime_get_sync(&mdp->pdev->dev); |
| 1909 | |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 1910 | ret = request_irq(ndev->irq, sh_eth_interrupt, |
Nobuhiro Iwamatsu | 5b3dfd1 | 2013-06-06 09:49:30 +0000 | [diff] [blame] | 1911 | mdp->cd->irq_flags, ndev->name, ndev); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1912 | if (ret) { |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 1913 | dev_err(&ndev->dev, "Can not assign IRQ number\n"); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1914 | return ret; |
| 1915 | } |
| 1916 | |
| 1917 | /* Descriptor set */ |
| 1918 | ret = sh_eth_ring_init(ndev); |
| 1919 | if (ret) |
| 1920 | goto out_free_irq; |
| 1921 | |
| 1922 | /* device init */ |
Yoshihiro Shimoda | 525b807 | 2012-06-26 20:00:03 +0000 | [diff] [blame] | 1923 | ret = sh_eth_dev_init(ndev, true); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1924 | if (ret) |
| 1925 | goto out_free_irq; |
| 1926 | |
| 1927 | /* PHY control start*/ |
| 1928 | ret = sh_eth_phy_start(ndev); |
| 1929 | if (ret) |
| 1930 | goto out_free_irq; |
| 1931 | |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1932 | return ret; |
| 1933 | |
| 1934 | out_free_irq: |
| 1935 | free_irq(ndev->irq, ndev); |
Magnus Damm | bcd5149 | 2009-10-09 00:20:04 +0000 | [diff] [blame] | 1936 | pm_runtime_put_sync(&mdp->pdev->dev); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1937 | return ret; |
| 1938 | } |
| 1939 | |
| 1940 | /* Timeout function */ |
| 1941 | static void sh_eth_tx_timeout(struct net_device *ndev) |
| 1942 | { |
| 1943 | struct sh_eth_private *mdp = netdev_priv(ndev); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1944 | struct sh_eth_rxdesc *rxdesc; |
| 1945 | int i; |
| 1946 | |
| 1947 | netif_stop_queue(ndev); |
| 1948 | |
Nobuhiro Iwamatsu | dc19e4e | 2011-02-15 21:17:32 +0000 | [diff] [blame] | 1949 | if (netif_msg_timer(mdp)) |
| 1950 | dev_err(&ndev->dev, "%s: transmit timed out, status %8.8x," |
Yoshihiro Shimoda | 4a55530 | 2011-03-07 21:59:26 +0000 | [diff] [blame] | 1951 | " resetting...\n", ndev->name, (int)sh_eth_read(ndev, EESR)); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1952 | |
| 1953 | /* tx_errors count up */ |
Eric Dumazet | bb7d92e | 2012-02-06 22:17:21 +0000 | [diff] [blame] | 1954 | ndev->stats.tx_errors++; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1955 | |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1956 | /* Free all the skbuffs in the Rx queue. */ |
Yoshihiro Shimoda | 525b807 | 2012-06-26 20:00:03 +0000 | [diff] [blame] | 1957 | for (i = 0; i < mdp->num_rx_ring; i++) { |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1958 | rxdesc = &mdp->rx_ring[i]; |
| 1959 | rxdesc->status = 0; |
| 1960 | rxdesc->addr = 0xBADF00D0; |
| 1961 | if (mdp->rx_skbuff[i]) |
| 1962 | dev_kfree_skb(mdp->rx_skbuff[i]); |
| 1963 | mdp->rx_skbuff[i] = NULL; |
| 1964 | } |
Yoshihiro Shimoda | 525b807 | 2012-06-26 20:00:03 +0000 | [diff] [blame] | 1965 | for (i = 0; i < mdp->num_tx_ring; i++) { |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1966 | if (mdp->tx_skbuff[i]) |
| 1967 | dev_kfree_skb(mdp->tx_skbuff[i]); |
| 1968 | mdp->tx_skbuff[i] = NULL; |
| 1969 | } |
| 1970 | |
| 1971 | /* device init */ |
Yoshihiro Shimoda | 525b807 | 2012-06-26 20:00:03 +0000 | [diff] [blame] | 1972 | sh_eth_dev_init(ndev, true); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1973 | } |
| 1974 | |
| 1975 | /* Packet transmit function */ |
| 1976 | static int sh_eth_start_xmit(struct sk_buff *skb, struct net_device *ndev) |
| 1977 | { |
| 1978 | struct sh_eth_private *mdp = netdev_priv(ndev); |
| 1979 | struct sh_eth_txdesc *txdesc; |
| 1980 | u32 entry; |
Nobuhiro Iwamatsu | fb5e2f9 | 2008-11-17 20:29:58 +0000 | [diff] [blame] | 1981 | unsigned long flags; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1982 | |
| 1983 | spin_lock_irqsave(&mdp->lock, flags); |
Yoshihiro Shimoda | 525b807 | 2012-06-26 20:00:03 +0000 | [diff] [blame] | 1984 | if ((mdp->cur_tx - mdp->dirty_tx) >= (mdp->num_tx_ring - 4)) { |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1985 | if (!sh_eth_txfree(ndev)) { |
Nobuhiro Iwamatsu | dc19e4e | 2011-02-15 21:17:32 +0000 | [diff] [blame] | 1986 | if (netif_msg_tx_queued(mdp)) |
| 1987 | dev_warn(&ndev->dev, "TxFD exhausted.\n"); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1988 | netif_stop_queue(ndev); |
| 1989 | spin_unlock_irqrestore(&mdp->lock, flags); |
Patrick McHardy | 5b54814 | 2009-06-12 06:22:29 +0000 | [diff] [blame] | 1990 | return NETDEV_TX_BUSY; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1991 | } |
| 1992 | } |
| 1993 | spin_unlock_irqrestore(&mdp->lock, flags); |
| 1994 | |
Yoshihiro Shimoda | 525b807 | 2012-06-26 20:00:03 +0000 | [diff] [blame] | 1995 | entry = mdp->cur_tx % mdp->num_tx_ring; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1996 | mdp->tx_skbuff[entry] = skb; |
| 1997 | txdesc = &mdp->tx_ring[entry]; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 1998 | /* soft swap. */ |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 1999 | if (!mdp->cd->hw_swap) |
| 2000 | sh_eth_soft_swap(phys_to_virt(ALIGN(txdesc->addr, 4)), |
| 2001 | skb->len + 2); |
Yoshihiro Shimoda | 31fcb99 | 2011-06-30 22:52:13 +0000 | [diff] [blame] | 2002 | txdesc->addr = dma_map_single(&ndev->dev, skb->data, skb->len, |
| 2003 | DMA_TO_DEVICE); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2004 | if (skb->len < ETHERSMALL) |
| 2005 | txdesc->buffer_length = ETHERSMALL; |
| 2006 | else |
| 2007 | txdesc->buffer_length = skb->len; |
| 2008 | |
Yoshihiro Shimoda | 525b807 | 2012-06-26 20:00:03 +0000 | [diff] [blame] | 2009 | if (entry >= mdp->num_tx_ring - 1) |
Yoshinori Sato | 71557a3 | 2008-08-06 19:49:00 -0400 | [diff] [blame] | 2010 | txdesc->status |= cpu_to_edmac(mdp, TD_TACT | TD_TDLE); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2011 | else |
Yoshinori Sato | 71557a3 | 2008-08-06 19:49:00 -0400 | [diff] [blame] | 2012 | txdesc->status |= cpu_to_edmac(mdp, TD_TACT); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2013 | |
| 2014 | mdp->cur_tx++; |
| 2015 | |
Yoshihiro Shimoda | c5ed536 | 2011-03-07 21:59:38 +0000 | [diff] [blame] | 2016 | if (!(sh_eth_read(ndev, EDTRR) & sh_eth_get_edtrr_trns(mdp))) |
| 2017 | sh_eth_write(ndev, sh_eth_get_edtrr_trns(mdp), EDTRR); |
Nobuhiro Iwamatsu | b0ca2a2 | 2008-06-30 11:08:17 +0900 | [diff] [blame] | 2018 | |
Patrick McHardy | 6ed1065 | 2009-06-23 06:03:08 +0000 | [diff] [blame] | 2019 | return NETDEV_TX_OK; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2020 | } |
| 2021 | |
| 2022 | /* device close function */ |
| 2023 | static int sh_eth_close(struct net_device *ndev) |
| 2024 | { |
| 2025 | struct sh_eth_private *mdp = netdev_priv(ndev); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2026 | |
| 2027 | netif_stop_queue(ndev); |
| 2028 | |
| 2029 | /* Disable interrupts by clearing the interrupt mask. */ |
Yoshihiro Shimoda | 4a55530 | 2011-03-07 21:59:26 +0000 | [diff] [blame] | 2030 | sh_eth_write(ndev, 0x0000, EESIPR); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2031 | |
| 2032 | /* Stop the chip's Tx and Rx processes. */ |
Yoshihiro Shimoda | 4a55530 | 2011-03-07 21:59:26 +0000 | [diff] [blame] | 2033 | sh_eth_write(ndev, 0, EDTRR); |
| 2034 | sh_eth_write(ndev, 0, EDRRR); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2035 | |
| 2036 | /* PHY Disconnect */ |
| 2037 | if (mdp->phydev) { |
| 2038 | phy_stop(mdp->phydev); |
| 2039 | phy_disconnect(mdp->phydev); |
| 2040 | } |
| 2041 | |
| 2042 | free_irq(ndev->irq, ndev); |
| 2043 | |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2044 | /* Free all the skbuffs in the Rx queue. */ |
| 2045 | sh_eth_ring_free(ndev); |
| 2046 | |
| 2047 | /* free DMA buffer */ |
Yoshihiro Shimoda | 91c7755 | 2012-06-26 20:00:01 +0000 | [diff] [blame] | 2048 | sh_eth_free_dma_buffer(mdp); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2049 | |
Magnus Damm | bcd5149 | 2009-10-09 00:20:04 +0000 | [diff] [blame] | 2050 | pm_runtime_put_sync(&mdp->pdev->dev); |
| 2051 | |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2052 | return 0; |
| 2053 | } |
| 2054 | |
| 2055 | static struct net_device_stats *sh_eth_get_stats(struct net_device *ndev) |
| 2056 | { |
| 2057 | struct sh_eth_private *mdp = netdev_priv(ndev); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2058 | |
Magnus Damm | bcd5149 | 2009-10-09 00:20:04 +0000 | [diff] [blame] | 2059 | pm_runtime_get_sync(&mdp->pdev->dev); |
| 2060 | |
Eric Dumazet | bb7d92e | 2012-02-06 22:17:21 +0000 | [diff] [blame] | 2061 | ndev->stats.tx_dropped += sh_eth_read(ndev, TROCR); |
Yoshihiro Shimoda | 4a55530 | 2011-03-07 21:59:26 +0000 | [diff] [blame] | 2062 | sh_eth_write(ndev, 0, TROCR); /* (write clear) */ |
Eric Dumazet | bb7d92e | 2012-02-06 22:17:21 +0000 | [diff] [blame] | 2063 | ndev->stats.collisions += sh_eth_read(ndev, CDCR); |
Yoshihiro Shimoda | 4a55530 | 2011-03-07 21:59:26 +0000 | [diff] [blame] | 2064 | sh_eth_write(ndev, 0, CDCR); /* (write clear) */ |
Eric Dumazet | bb7d92e | 2012-02-06 22:17:21 +0000 | [diff] [blame] | 2065 | ndev->stats.tx_carrier_errors += sh_eth_read(ndev, LCCR); |
Yoshihiro Shimoda | 4a55530 | 2011-03-07 21:59:26 +0000 | [diff] [blame] | 2066 | sh_eth_write(ndev, 0, LCCR); /* (write clear) */ |
Yoshihiro Shimoda | c5ed536 | 2011-03-07 21:59:38 +0000 | [diff] [blame] | 2067 | if (sh_eth_is_gether(mdp)) { |
Eric Dumazet | bb7d92e | 2012-02-06 22:17:21 +0000 | [diff] [blame] | 2068 | ndev->stats.tx_carrier_errors += sh_eth_read(ndev, CERCR); |
Yoshihiro Shimoda | c5ed536 | 2011-03-07 21:59:38 +0000 | [diff] [blame] | 2069 | sh_eth_write(ndev, 0, CERCR); /* (write clear) */ |
Eric Dumazet | bb7d92e | 2012-02-06 22:17:21 +0000 | [diff] [blame] | 2070 | ndev->stats.tx_carrier_errors += sh_eth_read(ndev, CEECR); |
Yoshihiro Shimoda | c5ed536 | 2011-03-07 21:59:38 +0000 | [diff] [blame] | 2071 | sh_eth_write(ndev, 0, CEECR); /* (write clear) */ |
| 2072 | } else { |
Eric Dumazet | bb7d92e | 2012-02-06 22:17:21 +0000 | [diff] [blame] | 2073 | ndev->stats.tx_carrier_errors += sh_eth_read(ndev, CNDCR); |
Yoshihiro Shimoda | c5ed536 | 2011-03-07 21:59:38 +0000 | [diff] [blame] | 2074 | sh_eth_write(ndev, 0, CNDCR); /* (write clear) */ |
| 2075 | } |
Magnus Damm | bcd5149 | 2009-10-09 00:20:04 +0000 | [diff] [blame] | 2076 | pm_runtime_put_sync(&mdp->pdev->dev); |
| 2077 | |
Eric Dumazet | bb7d92e | 2012-02-06 22:17:21 +0000 | [diff] [blame] | 2078 | return &ndev->stats; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2079 | } |
| 2080 | |
Eric Dumazet | bb7d92e | 2012-02-06 22:17:21 +0000 | [diff] [blame] | 2081 | /* ioctl to device function */ |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2082 | static int sh_eth_do_ioctl(struct net_device *ndev, struct ifreq *rq, |
| 2083 | int cmd) |
| 2084 | { |
| 2085 | struct sh_eth_private *mdp = netdev_priv(ndev); |
| 2086 | struct phy_device *phydev = mdp->phydev; |
| 2087 | |
| 2088 | if (!netif_running(ndev)) |
| 2089 | return -EINVAL; |
| 2090 | |
| 2091 | if (!phydev) |
| 2092 | return -ENODEV; |
| 2093 | |
Richard Cochran | 28b0411 | 2010-07-17 08:48:55 +0000 | [diff] [blame] | 2094 | return phy_mii_ioctl(phydev, rq, cmd); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2095 | } |
| 2096 | |
Yoshihiro Shimoda | 6743fe6 | 2012-02-15 17:55:03 +0000 | [diff] [blame] | 2097 | /* For TSU_POSTn. Please refer to the manual about this (strange) bitfields */ |
| 2098 | static void *sh_eth_tsu_get_post_reg_offset(struct sh_eth_private *mdp, |
| 2099 | int entry) |
| 2100 | { |
| 2101 | return sh_eth_tsu_get_offset(mdp, TSU_POST1) + (entry / 8 * 4); |
| 2102 | } |
| 2103 | |
| 2104 | static u32 sh_eth_tsu_get_post_mask(int entry) |
| 2105 | { |
| 2106 | return 0x0f << (28 - ((entry % 8) * 4)); |
| 2107 | } |
| 2108 | |
| 2109 | static u32 sh_eth_tsu_get_post_bit(struct sh_eth_private *mdp, int entry) |
| 2110 | { |
| 2111 | return (0x08 >> (mdp->port << 1)) << (28 - ((entry % 8) * 4)); |
| 2112 | } |
| 2113 | |
| 2114 | static void sh_eth_tsu_enable_cam_entry_post(struct net_device *ndev, |
| 2115 | int entry) |
| 2116 | { |
| 2117 | struct sh_eth_private *mdp = netdev_priv(ndev); |
| 2118 | u32 tmp; |
| 2119 | void *reg_offset; |
| 2120 | |
| 2121 | reg_offset = sh_eth_tsu_get_post_reg_offset(mdp, entry); |
| 2122 | tmp = ioread32(reg_offset); |
| 2123 | iowrite32(tmp | sh_eth_tsu_get_post_bit(mdp, entry), reg_offset); |
| 2124 | } |
| 2125 | |
| 2126 | static bool sh_eth_tsu_disable_cam_entry_post(struct net_device *ndev, |
| 2127 | int entry) |
| 2128 | { |
| 2129 | struct sh_eth_private *mdp = netdev_priv(ndev); |
| 2130 | u32 post_mask, ref_mask, tmp; |
| 2131 | void *reg_offset; |
| 2132 | |
| 2133 | reg_offset = sh_eth_tsu_get_post_reg_offset(mdp, entry); |
| 2134 | post_mask = sh_eth_tsu_get_post_mask(entry); |
| 2135 | ref_mask = sh_eth_tsu_get_post_bit(mdp, entry) & ~post_mask; |
| 2136 | |
| 2137 | tmp = ioread32(reg_offset); |
| 2138 | iowrite32(tmp & ~post_mask, reg_offset); |
| 2139 | |
| 2140 | /* If other port enables, the function returns "true" */ |
| 2141 | return tmp & ref_mask; |
| 2142 | } |
| 2143 | |
| 2144 | static int sh_eth_tsu_busy(struct net_device *ndev) |
| 2145 | { |
| 2146 | int timeout = SH_ETH_TSU_TIMEOUT_MS * 100; |
| 2147 | struct sh_eth_private *mdp = netdev_priv(ndev); |
| 2148 | |
| 2149 | while ((sh_eth_tsu_read(mdp, TSU_ADSBSY) & TSU_ADSBSY_0)) { |
| 2150 | udelay(10); |
| 2151 | timeout--; |
| 2152 | if (timeout <= 0) { |
| 2153 | dev_err(&ndev->dev, "%s: timeout\n", __func__); |
| 2154 | return -ETIMEDOUT; |
| 2155 | } |
| 2156 | } |
| 2157 | |
| 2158 | return 0; |
| 2159 | } |
| 2160 | |
| 2161 | static int sh_eth_tsu_write_entry(struct net_device *ndev, void *reg, |
| 2162 | const u8 *addr) |
| 2163 | { |
| 2164 | u32 val; |
| 2165 | |
| 2166 | val = addr[0] << 24 | addr[1] << 16 | addr[2] << 8 | addr[3]; |
| 2167 | iowrite32(val, reg); |
| 2168 | if (sh_eth_tsu_busy(ndev) < 0) |
| 2169 | return -EBUSY; |
| 2170 | |
| 2171 | val = addr[4] << 8 | addr[5]; |
| 2172 | iowrite32(val, reg + 4); |
| 2173 | if (sh_eth_tsu_busy(ndev) < 0) |
| 2174 | return -EBUSY; |
| 2175 | |
| 2176 | return 0; |
| 2177 | } |
| 2178 | |
| 2179 | static void sh_eth_tsu_read_entry(void *reg, u8 *addr) |
| 2180 | { |
| 2181 | u32 val; |
| 2182 | |
| 2183 | val = ioread32(reg); |
| 2184 | addr[0] = (val >> 24) & 0xff; |
| 2185 | addr[1] = (val >> 16) & 0xff; |
| 2186 | addr[2] = (val >> 8) & 0xff; |
| 2187 | addr[3] = val & 0xff; |
| 2188 | val = ioread32(reg + 4); |
| 2189 | addr[4] = (val >> 8) & 0xff; |
| 2190 | addr[5] = val & 0xff; |
| 2191 | } |
| 2192 | |
| 2193 | |
| 2194 | static int sh_eth_tsu_find_entry(struct net_device *ndev, const u8 *addr) |
| 2195 | { |
| 2196 | struct sh_eth_private *mdp = netdev_priv(ndev); |
| 2197 | void *reg_offset = sh_eth_tsu_get_offset(mdp, TSU_ADRH0); |
| 2198 | int i; |
| 2199 | u8 c_addr[ETH_ALEN]; |
| 2200 | |
| 2201 | for (i = 0; i < SH_ETH_TSU_CAM_ENTRIES; i++, reg_offset += 8) { |
| 2202 | sh_eth_tsu_read_entry(reg_offset, c_addr); |
| 2203 | if (memcmp(addr, c_addr, ETH_ALEN) == 0) |
| 2204 | return i; |
| 2205 | } |
| 2206 | |
| 2207 | return -ENOENT; |
| 2208 | } |
| 2209 | |
| 2210 | static int sh_eth_tsu_find_empty(struct net_device *ndev) |
| 2211 | { |
| 2212 | u8 blank[ETH_ALEN]; |
| 2213 | int entry; |
| 2214 | |
| 2215 | memset(blank, 0, sizeof(blank)); |
| 2216 | entry = sh_eth_tsu_find_entry(ndev, blank); |
| 2217 | return (entry < 0) ? -ENOMEM : entry; |
| 2218 | } |
| 2219 | |
| 2220 | static int sh_eth_tsu_disable_cam_entry_table(struct net_device *ndev, |
| 2221 | int entry) |
| 2222 | { |
| 2223 | struct sh_eth_private *mdp = netdev_priv(ndev); |
| 2224 | void *reg_offset = sh_eth_tsu_get_offset(mdp, TSU_ADRH0); |
| 2225 | int ret; |
| 2226 | u8 blank[ETH_ALEN]; |
| 2227 | |
| 2228 | sh_eth_tsu_write(mdp, sh_eth_tsu_read(mdp, TSU_TEN) & |
| 2229 | ~(1 << (31 - entry)), TSU_TEN); |
| 2230 | |
| 2231 | memset(blank, 0, sizeof(blank)); |
| 2232 | ret = sh_eth_tsu_write_entry(ndev, reg_offset + entry * 8, blank); |
| 2233 | if (ret < 0) |
| 2234 | return ret; |
| 2235 | return 0; |
| 2236 | } |
| 2237 | |
| 2238 | static int sh_eth_tsu_add_entry(struct net_device *ndev, const u8 *addr) |
| 2239 | { |
| 2240 | struct sh_eth_private *mdp = netdev_priv(ndev); |
| 2241 | void *reg_offset = sh_eth_tsu_get_offset(mdp, TSU_ADRH0); |
| 2242 | int i, ret; |
| 2243 | |
| 2244 | if (!mdp->cd->tsu) |
| 2245 | return 0; |
| 2246 | |
| 2247 | i = sh_eth_tsu_find_entry(ndev, addr); |
| 2248 | if (i < 0) { |
| 2249 | /* No entry found, create one */ |
| 2250 | i = sh_eth_tsu_find_empty(ndev); |
| 2251 | if (i < 0) |
| 2252 | return -ENOMEM; |
| 2253 | ret = sh_eth_tsu_write_entry(ndev, reg_offset + i * 8, addr); |
| 2254 | if (ret < 0) |
| 2255 | return ret; |
| 2256 | |
| 2257 | /* Enable the entry */ |
| 2258 | sh_eth_tsu_write(mdp, sh_eth_tsu_read(mdp, TSU_TEN) | |
| 2259 | (1 << (31 - i)), TSU_TEN); |
| 2260 | } |
| 2261 | |
| 2262 | /* Entry found or created, enable POST */ |
| 2263 | sh_eth_tsu_enable_cam_entry_post(ndev, i); |
| 2264 | |
| 2265 | return 0; |
| 2266 | } |
| 2267 | |
| 2268 | static int sh_eth_tsu_del_entry(struct net_device *ndev, const u8 *addr) |
| 2269 | { |
| 2270 | struct sh_eth_private *mdp = netdev_priv(ndev); |
| 2271 | int i, ret; |
| 2272 | |
| 2273 | if (!mdp->cd->tsu) |
| 2274 | return 0; |
| 2275 | |
| 2276 | i = sh_eth_tsu_find_entry(ndev, addr); |
| 2277 | if (i) { |
| 2278 | /* Entry found */ |
| 2279 | if (sh_eth_tsu_disable_cam_entry_post(ndev, i)) |
| 2280 | goto done; |
| 2281 | |
| 2282 | /* Disable the entry if both ports was disabled */ |
| 2283 | ret = sh_eth_tsu_disable_cam_entry_table(ndev, i); |
| 2284 | if (ret < 0) |
| 2285 | return ret; |
| 2286 | } |
| 2287 | done: |
| 2288 | return 0; |
| 2289 | } |
| 2290 | |
| 2291 | static int sh_eth_tsu_purge_all(struct net_device *ndev) |
| 2292 | { |
| 2293 | struct sh_eth_private *mdp = netdev_priv(ndev); |
| 2294 | int i, ret; |
| 2295 | |
| 2296 | if (unlikely(!mdp->cd->tsu)) |
| 2297 | return 0; |
| 2298 | |
| 2299 | for (i = 0; i < SH_ETH_TSU_CAM_ENTRIES; i++) { |
| 2300 | if (sh_eth_tsu_disable_cam_entry_post(ndev, i)) |
| 2301 | continue; |
| 2302 | |
| 2303 | /* Disable the entry if both ports was disabled */ |
| 2304 | ret = sh_eth_tsu_disable_cam_entry_table(ndev, i); |
| 2305 | if (ret < 0) |
| 2306 | return ret; |
| 2307 | } |
| 2308 | |
| 2309 | return 0; |
| 2310 | } |
| 2311 | |
| 2312 | static void sh_eth_tsu_purge_mcast(struct net_device *ndev) |
| 2313 | { |
| 2314 | struct sh_eth_private *mdp = netdev_priv(ndev); |
| 2315 | u8 addr[ETH_ALEN]; |
| 2316 | void *reg_offset = sh_eth_tsu_get_offset(mdp, TSU_ADRH0); |
| 2317 | int i; |
| 2318 | |
| 2319 | if (unlikely(!mdp->cd->tsu)) |
| 2320 | return; |
| 2321 | |
| 2322 | for (i = 0; i < SH_ETH_TSU_CAM_ENTRIES; i++, reg_offset += 8) { |
| 2323 | sh_eth_tsu_read_entry(reg_offset, addr); |
| 2324 | if (is_multicast_ether_addr(addr)) |
| 2325 | sh_eth_tsu_del_entry(ndev, addr); |
| 2326 | } |
| 2327 | } |
| 2328 | |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2329 | /* Multicast reception directions set */ |
| 2330 | static void sh_eth_set_multicast_list(struct net_device *ndev) |
| 2331 | { |
Yoshihiro Shimoda | 6743fe6 | 2012-02-15 17:55:03 +0000 | [diff] [blame] | 2332 | struct sh_eth_private *mdp = netdev_priv(ndev); |
| 2333 | u32 ecmr_bits; |
| 2334 | int mcast_all = 0; |
| 2335 | unsigned long flags; |
| 2336 | |
| 2337 | spin_lock_irqsave(&mdp->lock, flags); |
| 2338 | /* |
| 2339 | * Initial condition is MCT = 1, PRM = 0. |
| 2340 | * Depending on ndev->flags, set PRM or clear MCT |
| 2341 | */ |
| 2342 | ecmr_bits = (sh_eth_read(ndev, ECMR) & ~ECMR_PRM) | ECMR_MCT; |
| 2343 | |
| 2344 | if (!(ndev->flags & IFF_MULTICAST)) { |
| 2345 | sh_eth_tsu_purge_mcast(ndev); |
| 2346 | mcast_all = 1; |
| 2347 | } |
| 2348 | if (ndev->flags & IFF_ALLMULTI) { |
| 2349 | sh_eth_tsu_purge_mcast(ndev); |
| 2350 | ecmr_bits &= ~ECMR_MCT; |
| 2351 | mcast_all = 1; |
| 2352 | } |
| 2353 | |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2354 | if (ndev->flags & IFF_PROMISC) { |
Yoshihiro Shimoda | 6743fe6 | 2012-02-15 17:55:03 +0000 | [diff] [blame] | 2355 | sh_eth_tsu_purge_all(ndev); |
| 2356 | ecmr_bits = (ecmr_bits & ~ECMR_MCT) | ECMR_PRM; |
| 2357 | } else if (mdp->cd->tsu) { |
| 2358 | struct netdev_hw_addr *ha; |
| 2359 | netdev_for_each_mc_addr(ha, ndev) { |
| 2360 | if (mcast_all && is_multicast_ether_addr(ha->addr)) |
| 2361 | continue; |
| 2362 | |
| 2363 | if (sh_eth_tsu_add_entry(ndev, ha->addr) < 0) { |
| 2364 | if (!mcast_all) { |
| 2365 | sh_eth_tsu_purge_mcast(ndev); |
| 2366 | ecmr_bits &= ~ECMR_MCT; |
| 2367 | mcast_all = 1; |
| 2368 | } |
| 2369 | } |
| 2370 | } |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2371 | } else { |
| 2372 | /* Normal, unicast/broadcast-only mode. */ |
Yoshihiro Shimoda | 6743fe6 | 2012-02-15 17:55:03 +0000 | [diff] [blame] | 2373 | ecmr_bits = (ecmr_bits & ~ECMR_PRM) | ECMR_MCT; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2374 | } |
Yoshihiro Shimoda | 6743fe6 | 2012-02-15 17:55:03 +0000 | [diff] [blame] | 2375 | |
| 2376 | /* update the ethernet mode */ |
| 2377 | sh_eth_write(ndev, ecmr_bits, ECMR); |
| 2378 | |
| 2379 | spin_unlock_irqrestore(&mdp->lock, flags); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2380 | } |
Yoshihiro Shimoda | 71cc7c3 | 2012-02-15 17:55:06 +0000 | [diff] [blame] | 2381 | |
| 2382 | static int sh_eth_get_vtag_index(struct sh_eth_private *mdp) |
| 2383 | { |
| 2384 | if (!mdp->port) |
| 2385 | return TSU_VTAG0; |
| 2386 | else |
| 2387 | return TSU_VTAG1; |
| 2388 | } |
| 2389 | |
Patrick McHardy | 80d5c36 | 2013-04-19 02:04:28 +0000 | [diff] [blame] | 2390 | static int sh_eth_vlan_rx_add_vid(struct net_device *ndev, |
| 2391 | __be16 proto, u16 vid) |
Yoshihiro Shimoda | 71cc7c3 | 2012-02-15 17:55:06 +0000 | [diff] [blame] | 2392 | { |
| 2393 | struct sh_eth_private *mdp = netdev_priv(ndev); |
| 2394 | int vtag_reg_index = sh_eth_get_vtag_index(mdp); |
| 2395 | |
| 2396 | if (unlikely(!mdp->cd->tsu)) |
| 2397 | return -EPERM; |
| 2398 | |
| 2399 | /* No filtering if vid = 0 */ |
| 2400 | if (!vid) |
| 2401 | return 0; |
| 2402 | |
| 2403 | mdp->vlan_num_ids++; |
| 2404 | |
| 2405 | /* |
| 2406 | * The controller has one VLAN tag HW filter. So, if the filter is |
| 2407 | * already enabled, the driver disables it and the filte |
| 2408 | */ |
| 2409 | if (mdp->vlan_num_ids > 1) { |
| 2410 | /* disable VLAN filter */ |
| 2411 | sh_eth_tsu_write(mdp, 0, vtag_reg_index); |
| 2412 | return 0; |
| 2413 | } |
| 2414 | |
| 2415 | sh_eth_tsu_write(mdp, TSU_VTAG_ENABLE | (vid & TSU_VTAG_VID_MASK), |
| 2416 | vtag_reg_index); |
| 2417 | |
| 2418 | return 0; |
| 2419 | } |
| 2420 | |
Patrick McHardy | 80d5c36 | 2013-04-19 02:04:28 +0000 | [diff] [blame] | 2421 | static int sh_eth_vlan_rx_kill_vid(struct net_device *ndev, |
| 2422 | __be16 proto, u16 vid) |
Yoshihiro Shimoda | 71cc7c3 | 2012-02-15 17:55:06 +0000 | [diff] [blame] | 2423 | { |
| 2424 | struct sh_eth_private *mdp = netdev_priv(ndev); |
| 2425 | int vtag_reg_index = sh_eth_get_vtag_index(mdp); |
| 2426 | |
| 2427 | if (unlikely(!mdp->cd->tsu)) |
| 2428 | return -EPERM; |
| 2429 | |
| 2430 | /* No filtering if vid = 0 */ |
| 2431 | if (!vid) |
| 2432 | return 0; |
| 2433 | |
| 2434 | mdp->vlan_num_ids--; |
| 2435 | sh_eth_tsu_write(mdp, 0, vtag_reg_index); |
| 2436 | |
| 2437 | return 0; |
| 2438 | } |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2439 | |
| 2440 | /* SuperH's TSU register init function */ |
Yoshihiro Shimoda | 4a55530 | 2011-03-07 21:59:26 +0000 | [diff] [blame] | 2441 | static void sh_eth_tsu_init(struct sh_eth_private *mdp) |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2442 | { |
Yoshihiro Shimoda | 4a55530 | 2011-03-07 21:59:26 +0000 | [diff] [blame] | 2443 | sh_eth_tsu_write(mdp, 0, TSU_FWEN0); /* Disable forward(0->1) */ |
| 2444 | sh_eth_tsu_write(mdp, 0, TSU_FWEN1); /* Disable forward(1->0) */ |
| 2445 | sh_eth_tsu_write(mdp, 0, TSU_FCM); /* forward fifo 3k-3k */ |
| 2446 | sh_eth_tsu_write(mdp, 0xc, TSU_BSYSL0); |
| 2447 | sh_eth_tsu_write(mdp, 0xc, TSU_BSYSL1); |
| 2448 | sh_eth_tsu_write(mdp, 0, TSU_PRISL0); |
| 2449 | sh_eth_tsu_write(mdp, 0, TSU_PRISL1); |
| 2450 | sh_eth_tsu_write(mdp, 0, TSU_FWSL0); |
| 2451 | sh_eth_tsu_write(mdp, 0, TSU_FWSL1); |
| 2452 | 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] | 2453 | if (sh_eth_is_gether(mdp)) { |
| 2454 | sh_eth_tsu_write(mdp, 0, TSU_QTAG0); /* Disable QTAG(0->1) */ |
| 2455 | sh_eth_tsu_write(mdp, 0, TSU_QTAG1); /* Disable QTAG(1->0) */ |
| 2456 | } else { |
| 2457 | sh_eth_tsu_write(mdp, 0, TSU_QTAGM0); /* Disable QTAG(0->1) */ |
| 2458 | sh_eth_tsu_write(mdp, 0, TSU_QTAGM1); /* Disable QTAG(1->0) */ |
| 2459 | } |
Yoshihiro Shimoda | 4a55530 | 2011-03-07 21:59:26 +0000 | [diff] [blame] | 2460 | sh_eth_tsu_write(mdp, 0, TSU_FWSR); /* all interrupt status clear */ |
| 2461 | sh_eth_tsu_write(mdp, 0, TSU_FWINMK); /* Disable all interrupt */ |
| 2462 | sh_eth_tsu_write(mdp, 0, TSU_TEN); /* Disable all CAM entry */ |
| 2463 | sh_eth_tsu_write(mdp, 0, TSU_POST1); /* Disable CAM entry [ 0- 7] */ |
| 2464 | sh_eth_tsu_write(mdp, 0, TSU_POST2); /* Disable CAM entry [ 8-15] */ |
| 2465 | sh_eth_tsu_write(mdp, 0, TSU_POST3); /* Disable CAM entry [16-23] */ |
| 2466 | 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] | 2467 | } |
| 2468 | |
| 2469 | /* MDIO bus release function */ |
| 2470 | static int sh_mdio_release(struct net_device *ndev) |
| 2471 | { |
| 2472 | struct mii_bus *bus = dev_get_drvdata(&ndev->dev); |
| 2473 | |
| 2474 | /* unregister mdio bus */ |
| 2475 | mdiobus_unregister(bus); |
| 2476 | |
| 2477 | /* remove mdio bus info from net_device */ |
| 2478 | dev_set_drvdata(&ndev->dev, NULL); |
| 2479 | |
| 2480 | /* free bitbang info */ |
| 2481 | free_mdio_bitbang(bus); |
| 2482 | |
| 2483 | return 0; |
| 2484 | } |
| 2485 | |
| 2486 | /* MDIO bus init function */ |
Yoshihiro Shimoda | b3017e6 | 2011-03-07 21:59:55 +0000 | [diff] [blame] | 2487 | static int sh_mdio_init(struct net_device *ndev, int id, |
| 2488 | struct sh_eth_plat_data *pd) |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2489 | { |
| 2490 | int ret, i; |
| 2491 | struct bb_info *bitbang; |
| 2492 | struct sh_eth_private *mdp = netdev_priv(ndev); |
| 2493 | |
| 2494 | /* create bit control struct for PHY */ |
Sergei Shtylyov | d5e07e6 | 2013-03-21 10:41:11 +0000 | [diff] [blame] | 2495 | bitbang = devm_kzalloc(&ndev->dev, sizeof(struct bb_info), |
| 2496 | GFP_KERNEL); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2497 | if (!bitbang) { |
| 2498 | ret = -ENOMEM; |
| 2499 | goto out; |
| 2500 | } |
| 2501 | |
| 2502 | /* bitbang init */ |
Yoshihiro Shimoda | ae70644 | 2011-09-27 21:48:58 +0000 | [diff] [blame] | 2503 | bitbang->addr = mdp->addr + mdp->reg_offset[PIR]; |
Yoshihiro Shimoda | b3017e6 | 2011-03-07 21:59:55 +0000 | [diff] [blame] | 2504 | bitbang->set_gate = pd->set_mdio_gate; |
Sergei Shtylyov | dfed5e7 | 2013-03-21 10:37:54 +0000 | [diff] [blame] | 2505 | bitbang->mdi_msk = PIR_MDI; |
| 2506 | bitbang->mdo_msk = PIR_MDO; |
| 2507 | bitbang->mmd_msk = PIR_MMD; |
| 2508 | bitbang->mdc_msk = PIR_MDC; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2509 | bitbang->ctrl.ops = &bb_ops; |
| 2510 | |
Stefan Weil | c2e07b3 | 2010-08-03 19:44:52 +0200 | [diff] [blame] | 2511 | /* MII controller setting */ |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2512 | mdp->mii_bus = alloc_mdio_bitbang(&bitbang->ctrl); |
| 2513 | if (!mdp->mii_bus) { |
| 2514 | ret = -ENOMEM; |
Sergei Shtylyov | d5e07e6 | 2013-03-21 10:41:11 +0000 | [diff] [blame] | 2515 | goto out; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2516 | } |
| 2517 | |
| 2518 | /* Hook up MII support for ethtool */ |
| 2519 | mdp->mii_bus->name = "sh_mii"; |
Lennert Buytenhek | 18ee49d | 2008-10-01 15:41:33 +0000 | [diff] [blame] | 2520 | mdp->mii_bus->parent = &ndev->dev; |
Florian Fainelli | 5278fb5 | 2012-01-09 23:59:17 +0000 | [diff] [blame] | 2521 | snprintf(mdp->mii_bus->id, MII_BUS_ID_SIZE, "%s-%x", |
Nobuhiro Iwamatsu | 34aa6f1 | 2012-01-16 16:50:16 +0000 | [diff] [blame] | 2522 | mdp->pdev->name, id); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2523 | |
| 2524 | /* PHY IRQ */ |
Sergei Shtylyov | d5e07e6 | 2013-03-21 10:41:11 +0000 | [diff] [blame] | 2525 | mdp->mii_bus->irq = devm_kzalloc(&ndev->dev, |
| 2526 | sizeof(int) * PHY_MAX_ADDR, |
| 2527 | GFP_KERNEL); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2528 | if (!mdp->mii_bus->irq) { |
| 2529 | ret = -ENOMEM; |
| 2530 | goto out_free_bus; |
| 2531 | } |
| 2532 | |
| 2533 | for (i = 0; i < PHY_MAX_ADDR; i++) |
| 2534 | mdp->mii_bus->irq[i] = PHY_POLL; |
| 2535 | |
YOSHIFUJI Hideaki / 吉藤英明 | 8f6352f | 2012-11-02 04:45:07 +0000 | [diff] [blame] | 2536 | /* register mdio bus */ |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2537 | ret = mdiobus_register(mdp->mii_bus); |
| 2538 | if (ret) |
Sergei Shtylyov | d5e07e6 | 2013-03-21 10:41:11 +0000 | [diff] [blame] | 2539 | goto out_free_bus; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2540 | |
| 2541 | dev_set_drvdata(&ndev->dev, mdp->mii_bus); |
| 2542 | |
| 2543 | return 0; |
| 2544 | |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2545 | out_free_bus: |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 2546 | free_mdio_bitbang(mdp->mii_bus); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2547 | |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2548 | out: |
| 2549 | return ret; |
| 2550 | } |
| 2551 | |
Yoshihiro Shimoda | 4a55530 | 2011-03-07 21:59:26 +0000 | [diff] [blame] | 2552 | static const u16 *sh_eth_get_register_offset(int register_type) |
| 2553 | { |
| 2554 | const u16 *reg_offset = NULL; |
| 2555 | |
| 2556 | switch (register_type) { |
| 2557 | case SH_ETH_REG_GIGABIT: |
| 2558 | reg_offset = sh_eth_offset_gigabit; |
| 2559 | break; |
Sergei Shtylyov | a3f109b | 2013-03-28 11:51:31 +0000 | [diff] [blame] | 2560 | case SH_ETH_REG_FAST_RCAR: |
| 2561 | reg_offset = sh_eth_offset_fast_rcar; |
| 2562 | break; |
Yoshihiro Shimoda | 4a55530 | 2011-03-07 21:59:26 +0000 | [diff] [blame] | 2563 | case SH_ETH_REG_FAST_SH4: |
| 2564 | reg_offset = sh_eth_offset_fast_sh4; |
| 2565 | break; |
| 2566 | case SH_ETH_REG_FAST_SH3_SH2: |
| 2567 | reg_offset = sh_eth_offset_fast_sh3_sh2; |
| 2568 | break; |
| 2569 | default: |
Nobuhiro Iwamatsu | 14c3326 | 2013-03-20 22:46:55 +0000 | [diff] [blame] | 2570 | pr_err("Unknown register type (%d)\n", register_type); |
Yoshihiro Shimoda | 4a55530 | 2011-03-07 21:59:26 +0000 | [diff] [blame] | 2571 | break; |
| 2572 | } |
| 2573 | |
| 2574 | return reg_offset; |
| 2575 | } |
| 2576 | |
Nobuhiro Iwamatsu | 9f86134 | 2013-06-06 09:48:09 +0000 | [diff] [blame] | 2577 | static struct net_device_ops sh_eth_netdev_ops = { |
Alexander Beregalov | ebf84ea | 2009-04-11 07:40:49 +0000 | [diff] [blame] | 2578 | .ndo_open = sh_eth_open, |
| 2579 | .ndo_stop = sh_eth_close, |
| 2580 | .ndo_start_xmit = sh_eth_start_xmit, |
| 2581 | .ndo_get_stats = sh_eth_get_stats, |
Alexander Beregalov | ebf84ea | 2009-04-11 07:40:49 +0000 | [diff] [blame] | 2582 | .ndo_tx_timeout = sh_eth_tx_timeout, |
| 2583 | .ndo_do_ioctl = sh_eth_do_ioctl, |
| 2584 | .ndo_validate_addr = eth_validate_addr, |
| 2585 | .ndo_set_mac_address = eth_mac_addr, |
| 2586 | .ndo_change_mtu = eth_change_mtu, |
| 2587 | }; |
| 2588 | |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2589 | static int sh_eth_drv_probe(struct platform_device *pdev) |
| 2590 | { |
Kuninori Morimoto | 9c38657 | 2010-08-19 00:39:45 -0700 | [diff] [blame] | 2591 | int ret, devno = 0; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2592 | struct resource *res; |
| 2593 | struct net_device *ndev = NULL; |
Kuninori Morimoto | ec0d755 | 2011-06-23 16:02:38 +0000 | [diff] [blame] | 2594 | struct sh_eth_private *mdp = NULL; |
Sergei Shtylyov | 564044b | 2013-03-21 10:39:22 +0000 | [diff] [blame] | 2595 | struct sh_eth_plat_data *pd = pdev->dev.platform_data; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2596 | |
| 2597 | /* get base addr */ |
| 2598 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 2599 | if (unlikely(res == NULL)) { |
| 2600 | dev_err(&pdev->dev, "invalid resource\n"); |
| 2601 | ret = -EINVAL; |
| 2602 | goto out; |
| 2603 | } |
| 2604 | |
| 2605 | ndev = alloc_etherdev(sizeof(struct sh_eth_private)); |
| 2606 | if (!ndev) { |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2607 | ret = -ENOMEM; |
| 2608 | goto out; |
| 2609 | } |
| 2610 | |
| 2611 | /* The sh Ether-specific entries in the device structure. */ |
| 2612 | ndev->base_addr = res->start; |
| 2613 | devno = pdev->id; |
| 2614 | if (devno < 0) |
| 2615 | devno = 0; |
| 2616 | |
| 2617 | ndev->dma = -1; |
roel kluin | cc3c080 | 2008-09-10 19:22:44 +0200 | [diff] [blame] | 2618 | ret = platform_get_irq(pdev, 0); |
| 2619 | if (ret < 0) { |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2620 | ret = -ENODEV; |
| 2621 | goto out_release; |
| 2622 | } |
roel kluin | cc3c080 | 2008-09-10 19:22:44 +0200 | [diff] [blame] | 2623 | ndev->irq = ret; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2624 | |
| 2625 | SET_NETDEV_DEV(ndev, &pdev->dev); |
| 2626 | |
| 2627 | /* Fill in the fields of the device structure with ethernet values. */ |
| 2628 | ether_setup(ndev); |
| 2629 | |
| 2630 | mdp = netdev_priv(ndev); |
Yoshihiro Shimoda | 525b807 | 2012-06-26 20:00:03 +0000 | [diff] [blame] | 2631 | mdp->num_tx_ring = TX_RING_SIZE; |
| 2632 | mdp->num_rx_ring = RX_RING_SIZE; |
Sergei Shtylyov | d5e07e6 | 2013-03-21 10:41:11 +0000 | [diff] [blame] | 2633 | mdp->addr = devm_ioremap_resource(&pdev->dev, res); |
| 2634 | if (IS_ERR(mdp->addr)) { |
| 2635 | ret = PTR_ERR(mdp->addr); |
Yoshihiro Shimoda | ae70644 | 2011-09-27 21:48:58 +0000 | [diff] [blame] | 2636 | goto out_release; |
| 2637 | } |
| 2638 | |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2639 | spin_lock_init(&mdp->lock); |
Magnus Damm | bcd5149 | 2009-10-09 00:20:04 +0000 | [diff] [blame] | 2640 | mdp->pdev = pdev; |
| 2641 | pm_runtime_enable(&pdev->dev); |
| 2642 | pm_runtime_resume(&pdev->dev); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2643 | |
| 2644 | /* get PHY ID */ |
Yoshinori Sato | 71557a3 | 2008-08-06 19:49:00 -0400 | [diff] [blame] | 2645 | mdp->phy_id = pd->phy; |
Yoshihiro Shimoda | e47c905 | 2011-03-07 21:59:45 +0000 | [diff] [blame] | 2646 | mdp->phy_interface = pd->phy_interface; |
Yoshinori Sato | 71557a3 | 2008-08-06 19:49:00 -0400 | [diff] [blame] | 2647 | /* EDMAC endian */ |
| 2648 | mdp->edmac_endian = pd->edmac_endian; |
Yoshihiro Shimoda | 4923576 | 2009-08-27 23:25:03 +0000 | [diff] [blame] | 2649 | mdp->no_ether_link = pd->no_ether_link; |
| 2650 | mdp->ether_link_active_low = pd->ether_link_active_low; |
Yoshihiro Shimoda | 4a55530 | 2011-03-07 21:59:26 +0000 | [diff] [blame] | 2651 | mdp->reg_offset = sh_eth_get_register_offset(pd->register_type); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2652 | |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 2653 | /* set cpu data */ |
Yoshihiro Shimoda | 8fcd496 | 2011-03-07 21:59:49 +0000 | [diff] [blame] | 2654 | #if defined(SH_ETH_HAS_BOTH_MODULES) |
| 2655 | mdp->cd = sh_eth_get_cpu_data(mdp); |
| 2656 | #else |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 2657 | mdp->cd = &sh_eth_my_cpu_data; |
Yoshihiro Shimoda | 8fcd496 | 2011-03-07 21:59:49 +0000 | [diff] [blame] | 2658 | #endif |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 2659 | sh_eth_set_default_cpu_data(mdp->cd); |
| 2660 | |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2661 | /* set function */ |
Nobuhiro Iwamatsu | 9f86134 | 2013-06-06 09:48:09 +0000 | [diff] [blame] | 2662 | if (mdp->cd->tsu) { |
| 2663 | sh_eth_netdev_ops.ndo_set_rx_mode = sh_eth_set_multicast_list; |
| 2664 | sh_eth_netdev_ops.ndo_vlan_rx_add_vid = sh_eth_vlan_rx_add_vid; |
| 2665 | sh_eth_netdev_ops.ndo_vlan_rx_kill_vid = |
| 2666 | sh_eth_vlan_rx_kill_vid; |
| 2667 | } |
| 2668 | |
Alexander Beregalov | ebf84ea | 2009-04-11 07:40:49 +0000 | [diff] [blame] | 2669 | ndev->netdev_ops = &sh_eth_netdev_ops; |
Nobuhiro Iwamatsu | dc19e4e | 2011-02-15 21:17:32 +0000 | [diff] [blame] | 2670 | SET_ETHTOOL_OPS(ndev, &sh_eth_ethtool_ops); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2671 | ndev->watchdog_timeo = TX_TIMEOUT; |
| 2672 | |
Nobuhiro Iwamatsu | dc19e4e | 2011-02-15 21:17:32 +0000 | [diff] [blame] | 2673 | /* debug message level */ |
| 2674 | mdp->msg_enable = SH_ETH_DEF_MSG_ENABLE; |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2675 | |
| 2676 | /* read and set MAC address */ |
Magnus Damm | 748031f | 2009-10-09 00:17:14 +0000 | [diff] [blame] | 2677 | read_mac_address(ndev, pd->mac_addr); |
Sergei Shtylyov | ff6e722 | 2013-04-29 09:49:42 +0000 | [diff] [blame] | 2678 | if (!is_valid_ether_addr(ndev->dev_addr)) { |
| 2679 | dev_warn(&pdev->dev, |
| 2680 | "no valid MAC address supplied, using a random one.\n"); |
| 2681 | eth_hw_addr_random(ndev); |
| 2682 | } |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2683 | |
Yoshihiro Shimoda | 6ba8802 | 2012-02-15 17:55:01 +0000 | [diff] [blame] | 2684 | /* ioremap the TSU registers */ |
| 2685 | if (mdp->cd->tsu) { |
| 2686 | struct resource *rtsu; |
| 2687 | rtsu = platform_get_resource(pdev, IORESOURCE_MEM, 1); |
Sergei Shtylyov | d5e07e6 | 2013-03-21 10:41:11 +0000 | [diff] [blame] | 2688 | mdp->tsu_addr = devm_ioremap_resource(&pdev->dev, rtsu); |
| 2689 | if (IS_ERR(mdp->tsu_addr)) { |
| 2690 | ret = PTR_ERR(mdp->tsu_addr); |
Sergei Shtylyov | fc0c090 | 2013-03-19 13:41:32 +0000 | [diff] [blame] | 2691 | goto out_release; |
| 2692 | } |
Yoshihiro Shimoda | 6743fe6 | 2012-02-15 17:55:03 +0000 | [diff] [blame] | 2693 | mdp->port = devno % 2; |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 2694 | ndev->features = NETIF_F_HW_VLAN_CTAG_FILTER; |
Yoshihiro Shimoda | 6ba8802 | 2012-02-15 17:55:01 +0000 | [diff] [blame] | 2695 | } |
| 2696 | |
Yoshihiro Shimoda | 150647f | 2012-02-15 17:54:56 +0000 | [diff] [blame] | 2697 | /* initialize first or needed device */ |
| 2698 | if (!devno || pd->needs_init) { |
Yoshihiro Shimoda | 380af9e | 2009-05-24 23:54:21 +0000 | [diff] [blame] | 2699 | if (mdp->cd->chip_reset) |
| 2700 | mdp->cd->chip_reset(ndev); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2701 | |
Yoshihiro Shimoda | 4986b99 | 2011-03-07 21:59:34 +0000 | [diff] [blame] | 2702 | if (mdp->cd->tsu) { |
| 2703 | /* TSU init (Init only)*/ |
| 2704 | sh_eth_tsu_init(mdp); |
| 2705 | } |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2706 | } |
| 2707 | |
| 2708 | /* network device register */ |
| 2709 | ret = register_netdev(ndev); |
| 2710 | if (ret) |
| 2711 | goto out_release; |
| 2712 | |
| 2713 | /* mdio bus init */ |
Yoshihiro Shimoda | b3017e6 | 2011-03-07 21:59:55 +0000 | [diff] [blame] | 2714 | ret = sh_mdio_init(ndev, pdev->id, pd); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2715 | if (ret) |
| 2716 | goto out_unregister; |
| 2717 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 2718 | /* print device information */ |
H Hartley Sweeten | 6cd9b49 | 2009-12-29 20:10:35 -0800 | [diff] [blame] | 2719 | pr_info("Base address at 0x%x, %pM, IRQ %d.\n", |
| 2720 | (u32)ndev->base_addr, ndev->dev_addr, ndev->irq); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2721 | |
| 2722 | platform_set_drvdata(pdev, ndev); |
| 2723 | |
| 2724 | return ret; |
| 2725 | |
| 2726 | out_unregister: |
| 2727 | unregister_netdev(ndev); |
| 2728 | |
| 2729 | out_release: |
| 2730 | /* net_dev free */ |
| 2731 | if (ndev) |
| 2732 | free_netdev(ndev); |
| 2733 | |
| 2734 | out: |
| 2735 | return ret; |
| 2736 | } |
| 2737 | |
| 2738 | static int sh_eth_drv_remove(struct platform_device *pdev) |
| 2739 | { |
| 2740 | struct net_device *ndev = platform_get_drvdata(pdev); |
| 2741 | |
| 2742 | sh_mdio_release(ndev); |
| 2743 | unregister_netdev(ndev); |
Magnus Damm | bcd5149 | 2009-10-09 00:20:04 +0000 | [diff] [blame] | 2744 | pm_runtime_disable(&pdev->dev); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2745 | free_netdev(ndev); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2746 | |
| 2747 | return 0; |
| 2748 | } |
| 2749 | |
Magnus Damm | bcd5149 | 2009-10-09 00:20:04 +0000 | [diff] [blame] | 2750 | static int sh_eth_runtime_nop(struct device *dev) |
| 2751 | { |
| 2752 | /* |
| 2753 | * Runtime PM callback shared between ->runtime_suspend() |
| 2754 | * and ->runtime_resume(). Simply returns success. |
| 2755 | * |
| 2756 | * This driver re-initializes all registers after |
| 2757 | * pm_runtime_get_sync() anyway so there is no need |
| 2758 | * to save and restore registers here. |
| 2759 | */ |
| 2760 | return 0; |
| 2761 | } |
| 2762 | |
| 2763 | static struct dev_pm_ops sh_eth_dev_pm_ops = { |
| 2764 | .runtime_suspend = sh_eth_runtime_nop, |
| 2765 | .runtime_resume = sh_eth_runtime_nop, |
| 2766 | }; |
| 2767 | |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2768 | static struct platform_driver sh_eth_driver = { |
| 2769 | .probe = sh_eth_drv_probe, |
| 2770 | .remove = sh_eth_drv_remove, |
| 2771 | .driver = { |
| 2772 | .name = CARDNAME, |
Magnus Damm | bcd5149 | 2009-10-09 00:20:04 +0000 | [diff] [blame] | 2773 | .pm = &sh_eth_dev_pm_ops, |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2774 | }, |
| 2775 | }; |
| 2776 | |
Axel Lin | db62f68 | 2011-11-27 16:44:17 +0000 | [diff] [blame] | 2777 | module_platform_driver(sh_eth_driver); |
Nobuhiro Iwamatsu | 86a74ff | 2008-06-09 16:33:56 -0700 | [diff] [blame] | 2778 | |
| 2779 | MODULE_AUTHOR("Nobuhiro Iwamatsu, Yoshihiro Shimoda"); |
| 2780 | MODULE_DESCRIPTION("Renesas SuperH Ethernet driver"); |
| 2781 | MODULE_LICENSE("GPL v2"); |