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