diff options
author | Glenn Elliott <gelliott@cs.unc.edu> | 2012-03-04 19:47:13 -0500 |
---|---|---|
committer | Glenn Elliott <gelliott@cs.unc.edu> | 2012-03-04 19:47:13 -0500 |
commit | c71c03bda1e86c9d5198c5d83f712e695c4f2a1e (patch) | |
tree | ecb166cb3e2b7e2adb3b5e292245fefd23381ac8 /drivers/net/sh_eth.c | |
parent | ea53c912f8a86a8567697115b6a0d8152beee5c8 (diff) | |
parent | 6a00f206debf8a5c8899055726ad127dbeeed098 (diff) |
Merge branch 'mpi-master' into wip-k-fmlpwip-k-fmlp
Conflicts:
litmus/sched_cedf.c
Diffstat (limited to 'drivers/net/sh_eth.c')
-rw-r--r-- | drivers/net/sh_eth.c | 752 |
1 files changed, 553 insertions, 199 deletions
diff --git a/drivers/net/sh_eth.c b/drivers/net/sh_eth.c index 79fd02bc69fd..1f3f7b4dd638 100644 --- a/drivers/net/sh_eth.c +++ b/drivers/net/sh_eth.c | |||
@@ -32,35 +32,40 @@ | |||
32 | #include <linux/io.h> | 32 | #include <linux/io.h> |
33 | #include <linux/pm_runtime.h> | 33 | #include <linux/pm_runtime.h> |
34 | #include <linux/slab.h> | 34 | #include <linux/slab.h> |
35 | #include <linux/ethtool.h> | ||
35 | #include <asm/cacheflush.h> | 36 | #include <asm/cacheflush.h> |
36 | 37 | ||
37 | #include "sh_eth.h" | 38 | #include "sh_eth.h" |
38 | 39 | ||
40 | #define SH_ETH_DEF_MSG_ENABLE \ | ||
41 | (NETIF_MSG_LINK | \ | ||
42 | NETIF_MSG_TIMER | \ | ||
43 | NETIF_MSG_RX_ERR| \ | ||
44 | NETIF_MSG_TX_ERR) | ||
45 | |||
39 | /* There is CPU dependent code */ | 46 | /* There is CPU dependent code */ |
40 | #if defined(CONFIG_CPU_SUBTYPE_SH7724) | 47 | #if defined(CONFIG_CPU_SUBTYPE_SH7724) |
41 | #define SH_ETH_RESET_DEFAULT 1 | 48 | #define SH_ETH_RESET_DEFAULT 1 |
42 | static void sh_eth_set_duplex(struct net_device *ndev) | 49 | static void sh_eth_set_duplex(struct net_device *ndev) |
43 | { | 50 | { |
44 | struct sh_eth_private *mdp = netdev_priv(ndev); | 51 | struct sh_eth_private *mdp = netdev_priv(ndev); |
45 | u32 ioaddr = ndev->base_addr; | ||
46 | 52 | ||
47 | if (mdp->duplex) /* Full */ | 53 | if (mdp->duplex) /* Full */ |
48 | ctrl_outl(ctrl_inl(ioaddr + ECMR) | ECMR_DM, ioaddr + ECMR); | 54 | sh_eth_write(ndev, sh_eth_read(ndev, ECMR) | ECMR_DM, ECMR); |
49 | else /* Half */ | 55 | else /* Half */ |
50 | ctrl_outl(ctrl_inl(ioaddr + ECMR) & ~ECMR_DM, ioaddr + ECMR); | 56 | sh_eth_write(ndev, sh_eth_read(ndev, ECMR) & ~ECMR_DM, ECMR); |
51 | } | 57 | } |
52 | 58 | ||
53 | static void sh_eth_set_rate(struct net_device *ndev) | 59 | static void sh_eth_set_rate(struct net_device *ndev) |
54 | { | 60 | { |
55 | struct sh_eth_private *mdp = netdev_priv(ndev); | 61 | struct sh_eth_private *mdp = netdev_priv(ndev); |
56 | u32 ioaddr = ndev->base_addr; | ||
57 | 62 | ||
58 | switch (mdp->speed) { | 63 | switch (mdp->speed) { |
59 | case 10: /* 10BASE */ | 64 | case 10: /* 10BASE */ |
60 | ctrl_outl(ctrl_inl(ioaddr + ECMR) & ~ECMR_RTM, ioaddr + ECMR); | 65 | sh_eth_write(ndev, sh_eth_read(ndev, ECMR) & ~ECMR_RTM, ECMR); |
61 | break; | 66 | break; |
62 | case 100:/* 100BASE */ | 67 | case 100:/* 100BASE */ |
63 | ctrl_outl(ctrl_inl(ioaddr + ECMR) | ECMR_RTM, ioaddr + ECMR); | 68 | sh_eth_write(ndev, sh_eth_read(ndev, ECMR) | ECMR_RTM, ECMR); |
64 | break; | 69 | break; |
65 | default: | 70 | default: |
66 | break; | 71 | break; |
@@ -89,29 +94,28 @@ static struct sh_eth_cpu_data sh_eth_my_cpu_data = { | |||
89 | .rpadir_value = 0x00020000, /* NET_IP_ALIGN assumed to be 2 */ | 94 | .rpadir_value = 0x00020000, /* NET_IP_ALIGN assumed to be 2 */ |
90 | }; | 95 | }; |
91 | #elif defined(CONFIG_CPU_SUBTYPE_SH7757) | 96 | #elif defined(CONFIG_CPU_SUBTYPE_SH7757) |
92 | #define SH_ETH_RESET_DEFAULT 1 | 97 | #define SH_ETH_HAS_BOTH_MODULES 1 |
98 | #define SH_ETH_HAS_TSU 1 | ||
93 | static void sh_eth_set_duplex(struct net_device *ndev) | 99 | static void sh_eth_set_duplex(struct net_device *ndev) |
94 | { | 100 | { |
95 | struct sh_eth_private *mdp = netdev_priv(ndev); | 101 | struct sh_eth_private *mdp = netdev_priv(ndev); |
96 | u32 ioaddr = ndev->base_addr; | ||
97 | 102 | ||
98 | if (mdp->duplex) /* Full */ | 103 | if (mdp->duplex) /* Full */ |
99 | ctrl_outl(ctrl_inl(ioaddr + ECMR) | ECMR_DM, ioaddr + ECMR); | 104 | sh_eth_write(ndev, sh_eth_read(ndev, ECMR) | ECMR_DM, ECMR); |
100 | else /* Half */ | 105 | else /* Half */ |
101 | ctrl_outl(ctrl_inl(ioaddr + ECMR) & ~ECMR_DM, ioaddr + ECMR); | 106 | sh_eth_write(ndev, sh_eth_read(ndev, ECMR) & ~ECMR_DM, ECMR); |
102 | } | 107 | } |
103 | 108 | ||
104 | static void sh_eth_set_rate(struct net_device *ndev) | 109 | static void sh_eth_set_rate(struct net_device *ndev) |
105 | { | 110 | { |
106 | struct sh_eth_private *mdp = netdev_priv(ndev); | 111 | struct sh_eth_private *mdp = netdev_priv(ndev); |
107 | u32 ioaddr = ndev->base_addr; | ||
108 | 112 | ||
109 | switch (mdp->speed) { | 113 | switch (mdp->speed) { |
110 | case 10: /* 10BASE */ | 114 | case 10: /* 10BASE */ |
111 | ctrl_outl(0, ioaddr + RTRATE); | 115 | sh_eth_write(ndev, 0, RTRATE); |
112 | break; | 116 | break; |
113 | case 100:/* 100BASE */ | 117 | case 100:/* 100BASE */ |
114 | ctrl_outl(1, ioaddr + RTRATE); | 118 | sh_eth_write(ndev, 1, RTRATE); |
115 | break; | 119 | break; |
116 | default: | 120 | default: |
117 | break; | 121 | break; |
@@ -136,26 +140,158 @@ static struct sh_eth_cpu_data sh_eth_my_cpu_data = { | |||
136 | .tpauser = 1, | 140 | .tpauser = 1, |
137 | .hw_swap = 1, | 141 | .hw_swap = 1, |
138 | .no_ade = 1, | 142 | .no_ade = 1, |
143 | .rpadir = 1, | ||
144 | .rpadir_value = 2 << 16, | ||
145 | }; | ||
146 | |||
147 | #define SH_GIGA_ETH_BASE 0xfee00000 | ||
148 | #define GIGA_MALR(port) (SH_GIGA_ETH_BASE + 0x800 * (port) + 0x05c8) | ||
149 | #define GIGA_MAHR(port) (SH_GIGA_ETH_BASE + 0x800 * (port) + 0x05c0) | ||
150 | static void sh_eth_chip_reset_giga(struct net_device *ndev) | ||
151 | { | ||
152 | int i; | ||
153 | unsigned long mahr[2], malr[2]; | ||
154 | |||
155 | /* save MAHR and MALR */ | ||
156 | for (i = 0; i < 2; i++) { | ||
157 | malr[i] = readl(GIGA_MALR(i)); | ||
158 | mahr[i] = readl(GIGA_MAHR(i)); | ||
159 | } | ||
160 | |||
161 | /* reset device */ | ||
162 | writel(ARSTR_ARSTR, SH_GIGA_ETH_BASE + 0x1800); | ||
163 | mdelay(1); | ||
164 | |||
165 | /* restore MAHR and MALR */ | ||
166 | for (i = 0; i < 2; i++) { | ||
167 | writel(malr[i], GIGA_MALR(i)); | ||
168 | writel(mahr[i], GIGA_MAHR(i)); | ||
169 | } | ||
170 | } | ||
171 | |||
172 | static int sh_eth_is_gether(struct sh_eth_private *mdp); | ||
173 | static void sh_eth_reset(struct net_device *ndev) | ||
174 | { | ||
175 | struct sh_eth_private *mdp = netdev_priv(ndev); | ||
176 | int cnt = 100; | ||
177 | |||
178 | if (sh_eth_is_gether(mdp)) { | ||
179 | sh_eth_write(ndev, 0x03, EDSR); | ||
180 | sh_eth_write(ndev, sh_eth_read(ndev, EDMR) | EDMR_SRST_GETHER, | ||
181 | EDMR); | ||
182 | while (cnt > 0) { | ||
183 | if (!(sh_eth_read(ndev, EDMR) & 0x3)) | ||
184 | break; | ||
185 | mdelay(1); | ||
186 | cnt--; | ||
187 | } | ||
188 | if (cnt < 0) | ||
189 | printk(KERN_ERR "Device reset fail\n"); | ||
190 | |||
191 | /* Table Init */ | ||
192 | sh_eth_write(ndev, 0x0, TDLAR); | ||
193 | sh_eth_write(ndev, 0x0, TDFAR); | ||
194 | sh_eth_write(ndev, 0x0, TDFXR); | ||
195 | sh_eth_write(ndev, 0x0, TDFFR); | ||
196 | sh_eth_write(ndev, 0x0, RDLAR); | ||
197 | sh_eth_write(ndev, 0x0, RDFAR); | ||
198 | sh_eth_write(ndev, 0x0, RDFXR); | ||
199 | sh_eth_write(ndev, 0x0, RDFFR); | ||
200 | } else { | ||
201 | sh_eth_write(ndev, sh_eth_read(ndev, EDMR) | EDMR_SRST_ETHER, | ||
202 | EDMR); | ||
203 | mdelay(3); | ||
204 | sh_eth_write(ndev, sh_eth_read(ndev, EDMR) & ~EDMR_SRST_ETHER, | ||
205 | EDMR); | ||
206 | } | ||
207 | } | ||
208 | |||
209 | static void sh_eth_set_duplex_giga(struct net_device *ndev) | ||
210 | { | ||
211 | struct sh_eth_private *mdp = netdev_priv(ndev); | ||
212 | |||
213 | if (mdp->duplex) /* Full */ | ||
214 | sh_eth_write(ndev, sh_eth_read(ndev, ECMR) | ECMR_DM, ECMR); | ||
215 | else /* Half */ | ||
216 | sh_eth_write(ndev, sh_eth_read(ndev, ECMR) & ~ECMR_DM, ECMR); | ||
217 | } | ||
218 | |||
219 | static void sh_eth_set_rate_giga(struct net_device *ndev) | ||
220 | { | ||
221 | struct sh_eth_private *mdp = netdev_priv(ndev); | ||
222 | |||
223 | switch (mdp->speed) { | ||
224 | case 10: /* 10BASE */ | ||
225 | sh_eth_write(ndev, 0x00000000, GECMR); | ||
226 | break; | ||
227 | case 100:/* 100BASE */ | ||
228 | sh_eth_write(ndev, 0x00000010, GECMR); | ||
229 | break; | ||
230 | case 1000: /* 1000BASE */ | ||
231 | sh_eth_write(ndev, 0x00000020, GECMR); | ||
232 | break; | ||
233 | default: | ||
234 | break; | ||
235 | } | ||
236 | } | ||
237 | |||
238 | /* SH7757(GETHERC) */ | ||
239 | static struct sh_eth_cpu_data sh_eth_my_cpu_data_giga = { | ||
240 | .chip_reset = sh_eth_chip_reset_giga, | ||
241 | .set_duplex = sh_eth_set_duplex_giga, | ||
242 | .set_rate = sh_eth_set_rate_giga, | ||
243 | |||
244 | .ecsr_value = ECSR_ICD | ECSR_MPD, | ||
245 | .ecsipr_value = ECSIPR_LCHNGIP | ECSIPR_ICDIP | ECSIPR_MPDIP, | ||
246 | .eesipr_value = DMAC_M_RFRMER | DMAC_M_ECI | 0x003fffff, | ||
247 | |||
248 | .tx_check = EESR_TC1 | EESR_FTC, | ||
249 | .eesr_err_check = EESR_TWB1 | EESR_TWB | EESR_TABT | EESR_RABT | \ | ||
250 | EESR_RDE | EESR_RFRMER | EESR_TFE | EESR_TDE | \ | ||
251 | EESR_ECI, | ||
252 | .tx_error_check = EESR_TWB1 | EESR_TWB | EESR_TABT | EESR_TDE | \ | ||
253 | EESR_TFE, | ||
254 | .fdr_value = 0x0000072f, | ||
255 | .rmcr_value = 0x00000001, | ||
256 | |||
257 | .apr = 1, | ||
258 | .mpr = 1, | ||
259 | .tpauser = 1, | ||
260 | .bculr = 1, | ||
261 | .hw_swap = 1, | ||
262 | .rpadir = 1, | ||
263 | .rpadir_value = 2 << 16, | ||
264 | .no_trimd = 1, | ||
265 | .no_ade = 1, | ||
139 | }; | 266 | }; |
140 | 267 | ||
268 | static struct sh_eth_cpu_data *sh_eth_get_cpu_data(struct sh_eth_private *mdp) | ||
269 | { | ||
270 | if (sh_eth_is_gether(mdp)) | ||
271 | return &sh_eth_my_cpu_data_giga; | ||
272 | else | ||
273 | return &sh_eth_my_cpu_data; | ||
274 | } | ||
275 | |||
141 | #elif defined(CONFIG_CPU_SUBTYPE_SH7763) | 276 | #elif defined(CONFIG_CPU_SUBTYPE_SH7763) |
142 | #define SH_ETH_HAS_TSU 1 | 277 | #define SH_ETH_HAS_TSU 1 |
143 | static void sh_eth_chip_reset(struct net_device *ndev) | 278 | static void sh_eth_chip_reset(struct net_device *ndev) |
144 | { | 279 | { |
280 | struct sh_eth_private *mdp = netdev_priv(ndev); | ||
281 | |||
145 | /* reset device */ | 282 | /* reset device */ |
146 | ctrl_outl(ARSTR_ARSTR, ARSTR); | 283 | sh_eth_tsu_write(mdp, ARSTR_ARSTR, ARSTR); |
147 | mdelay(1); | 284 | mdelay(1); |
148 | } | 285 | } |
149 | 286 | ||
150 | static void sh_eth_reset(struct net_device *ndev) | 287 | static void sh_eth_reset(struct net_device *ndev) |
151 | { | 288 | { |
152 | u32 ioaddr = ndev->base_addr; | ||
153 | int cnt = 100; | 289 | int cnt = 100; |
154 | 290 | ||
155 | ctrl_outl(EDSR_ENALL, ioaddr + EDSR); | 291 | sh_eth_write(ndev, EDSR_ENALL, EDSR); |
156 | ctrl_outl(ctrl_inl(ioaddr + EDMR) | EDMR_SRST, ioaddr + EDMR); | 292 | sh_eth_write(ndev, sh_eth_read(ndev, EDMR) | EDMR_SRST_GETHER, EDMR); |
157 | while (cnt > 0) { | 293 | while (cnt > 0) { |
158 | if (!(ctrl_inl(ioaddr + EDMR) & 0x3)) | 294 | if (!(sh_eth_read(ndev, EDMR) & 0x3)) |
159 | break; | 295 | break; |
160 | mdelay(1); | 296 | mdelay(1); |
161 | cnt--; | 297 | cnt--; |
@@ -164,41 +300,39 @@ static void sh_eth_reset(struct net_device *ndev) | |||
164 | printk(KERN_ERR "Device reset fail\n"); | 300 | printk(KERN_ERR "Device reset fail\n"); |
165 | 301 | ||
166 | /* Table Init */ | 302 | /* Table Init */ |
167 | ctrl_outl(0x0, ioaddr + TDLAR); | 303 | sh_eth_write(ndev, 0x0, TDLAR); |
168 | ctrl_outl(0x0, ioaddr + TDFAR); | 304 | sh_eth_write(ndev, 0x0, TDFAR); |
169 | ctrl_outl(0x0, ioaddr + TDFXR); | 305 | sh_eth_write(ndev, 0x0, TDFXR); |
170 | ctrl_outl(0x0, ioaddr + TDFFR); | 306 | sh_eth_write(ndev, 0x0, TDFFR); |
171 | ctrl_outl(0x0, ioaddr + RDLAR); | 307 | sh_eth_write(ndev, 0x0, RDLAR); |
172 | ctrl_outl(0x0, ioaddr + RDFAR); | 308 | sh_eth_write(ndev, 0x0, RDFAR); |
173 | ctrl_outl(0x0, ioaddr + RDFXR); | 309 | sh_eth_write(ndev, 0x0, RDFXR); |
174 | ctrl_outl(0x0, ioaddr + RDFFR); | 310 | sh_eth_write(ndev, 0x0, RDFFR); |
175 | } | 311 | } |
176 | 312 | ||
177 | static void sh_eth_set_duplex(struct net_device *ndev) | 313 | static void sh_eth_set_duplex(struct net_device *ndev) |
178 | { | 314 | { |
179 | struct sh_eth_private *mdp = netdev_priv(ndev); | 315 | struct sh_eth_private *mdp = netdev_priv(ndev); |
180 | u32 ioaddr = ndev->base_addr; | ||
181 | 316 | ||
182 | if (mdp->duplex) /* Full */ | 317 | if (mdp->duplex) /* Full */ |
183 | ctrl_outl(ctrl_inl(ioaddr + ECMR) | ECMR_DM, ioaddr + ECMR); | 318 | sh_eth_write(ndev, sh_eth_read(ndev, ECMR) | ECMR_DM, ECMR); |
184 | else /* Half */ | 319 | else /* Half */ |
185 | ctrl_outl(ctrl_inl(ioaddr + ECMR) & ~ECMR_DM, ioaddr + ECMR); | 320 | sh_eth_write(ndev, sh_eth_read(ndev, ECMR) & ~ECMR_DM, ECMR); |
186 | } | 321 | } |
187 | 322 | ||
188 | static void sh_eth_set_rate(struct net_device *ndev) | 323 | static void sh_eth_set_rate(struct net_device *ndev) |
189 | { | 324 | { |
190 | struct sh_eth_private *mdp = netdev_priv(ndev); | 325 | struct sh_eth_private *mdp = netdev_priv(ndev); |
191 | u32 ioaddr = ndev->base_addr; | ||
192 | 326 | ||
193 | switch (mdp->speed) { | 327 | switch (mdp->speed) { |
194 | case 10: /* 10BASE */ | 328 | case 10: /* 10BASE */ |
195 | ctrl_outl(GECMR_10, ioaddr + GECMR); | 329 | sh_eth_write(ndev, GECMR_10, GECMR); |
196 | break; | 330 | break; |
197 | case 100:/* 100BASE */ | 331 | case 100:/* 100BASE */ |
198 | ctrl_outl(GECMR_100, ioaddr + GECMR); | 332 | sh_eth_write(ndev, GECMR_100, GECMR); |
199 | break; | 333 | break; |
200 | case 1000: /* 1000BASE */ | 334 | case 1000: /* 1000BASE */ |
201 | ctrl_outl(GECMR_1000, ioaddr + GECMR); | 335 | sh_eth_write(ndev, GECMR_1000, GECMR); |
202 | break; | 336 | break; |
203 | default: | 337 | default: |
204 | break; | 338 | break; |
@@ -229,6 +363,7 @@ static struct sh_eth_cpu_data sh_eth_my_cpu_data = { | |||
229 | .hw_swap = 1, | 363 | .hw_swap = 1, |
230 | .no_trimd = 1, | 364 | .no_trimd = 1, |
231 | .no_ade = 1, | 365 | .no_ade = 1, |
366 | .tsu = 1, | ||
232 | }; | 367 | }; |
233 | 368 | ||
234 | #elif defined(CONFIG_CPU_SUBTYPE_SH7619) | 369 | #elif defined(CONFIG_CPU_SUBTYPE_SH7619) |
@@ -246,6 +381,7 @@ static struct sh_eth_cpu_data sh_eth_my_cpu_data = { | |||
246 | #define SH_ETH_HAS_TSU 1 | 381 | #define SH_ETH_HAS_TSU 1 |
247 | static struct sh_eth_cpu_data sh_eth_my_cpu_data = { | 382 | static struct sh_eth_cpu_data sh_eth_my_cpu_data = { |
248 | .eesipr_value = DMAC_M_RFRMER | DMAC_M_ECI | 0x003fffff, | 383 | .eesipr_value = DMAC_M_RFRMER | DMAC_M_ECI | 0x003fffff, |
384 | .tsu = 1, | ||
249 | }; | 385 | }; |
250 | #endif | 386 | #endif |
251 | 387 | ||
@@ -281,11 +417,9 @@ static void sh_eth_set_default_cpu_data(struct sh_eth_cpu_data *cd) | |||
281 | /* Chip Reset */ | 417 | /* Chip Reset */ |
282 | static void sh_eth_reset(struct net_device *ndev) | 418 | static void sh_eth_reset(struct net_device *ndev) |
283 | { | 419 | { |
284 | u32 ioaddr = ndev->base_addr; | 420 | sh_eth_write(ndev, sh_eth_read(ndev, EDMR) | EDMR_SRST_ETHER, EDMR); |
285 | |||
286 | ctrl_outl(ctrl_inl(ioaddr + EDMR) | EDMR_SRST, ioaddr + EDMR); | ||
287 | mdelay(3); | 421 | mdelay(3); |
288 | ctrl_outl(ctrl_inl(ioaddr + EDMR) & ~EDMR_SRST, ioaddr + EDMR); | 422 | sh_eth_write(ndev, sh_eth_read(ndev, EDMR) & ~EDMR_SRST_ETHER, EDMR); |
289 | } | 423 | } |
290 | #endif | 424 | #endif |
291 | 425 | ||
@@ -334,13 +468,11 @@ static inline __u32 edmac_to_cpu(struct sh_eth_private *mdp, u32 x) | |||
334 | */ | 468 | */ |
335 | static void update_mac_address(struct net_device *ndev) | 469 | static void update_mac_address(struct net_device *ndev) |
336 | { | 470 | { |
337 | u32 ioaddr = ndev->base_addr; | 471 | sh_eth_write(ndev, |
338 | 472 | (ndev->dev_addr[0] << 24) | (ndev->dev_addr[1] << 16) | | |
339 | ctrl_outl((ndev->dev_addr[0] << 24) | (ndev->dev_addr[1] << 16) | | 473 | (ndev->dev_addr[2] << 8) | (ndev->dev_addr[3]), MAHR); |
340 | (ndev->dev_addr[2] << 8) | (ndev->dev_addr[3]), | 474 | sh_eth_write(ndev, |
341 | ioaddr + MAHR); | 475 | (ndev->dev_addr[4] << 8) | (ndev->dev_addr[5]), MALR); |
342 | ctrl_outl((ndev->dev_addr[4] << 8) | (ndev->dev_addr[5]), | ||
343 | ioaddr + MALR); | ||
344 | } | 476 | } |
345 | 477 | ||
346 | /* | 478 | /* |
@@ -353,21 +485,36 @@ static void update_mac_address(struct net_device *ndev) | |||
353 | */ | 485 | */ |
354 | static void read_mac_address(struct net_device *ndev, unsigned char *mac) | 486 | static void read_mac_address(struct net_device *ndev, unsigned char *mac) |
355 | { | 487 | { |
356 | u32 ioaddr = ndev->base_addr; | ||
357 | |||
358 | if (mac[0] || mac[1] || mac[2] || mac[3] || mac[4] || mac[5]) { | 488 | if (mac[0] || mac[1] || mac[2] || mac[3] || mac[4] || mac[5]) { |
359 | memcpy(ndev->dev_addr, mac, 6); | 489 | memcpy(ndev->dev_addr, mac, 6); |
360 | } else { | 490 | } else { |
361 | ndev->dev_addr[0] = (ctrl_inl(ioaddr + MAHR) >> 24); | 491 | ndev->dev_addr[0] = (sh_eth_read(ndev, MAHR) >> 24); |
362 | ndev->dev_addr[1] = (ctrl_inl(ioaddr + MAHR) >> 16) & 0xFF; | 492 | ndev->dev_addr[1] = (sh_eth_read(ndev, MAHR) >> 16) & 0xFF; |
363 | ndev->dev_addr[2] = (ctrl_inl(ioaddr + MAHR) >> 8) & 0xFF; | 493 | ndev->dev_addr[2] = (sh_eth_read(ndev, MAHR) >> 8) & 0xFF; |
364 | ndev->dev_addr[3] = (ctrl_inl(ioaddr + MAHR) & 0xFF); | 494 | ndev->dev_addr[3] = (sh_eth_read(ndev, MAHR) & 0xFF); |
365 | ndev->dev_addr[4] = (ctrl_inl(ioaddr + MALR) >> 8) & 0xFF; | 495 | ndev->dev_addr[4] = (sh_eth_read(ndev, MALR) >> 8) & 0xFF; |
366 | ndev->dev_addr[5] = (ctrl_inl(ioaddr + MALR) & 0xFF); | 496 | ndev->dev_addr[5] = (sh_eth_read(ndev, MALR) & 0xFF); |
367 | } | 497 | } |
368 | } | 498 | } |
369 | 499 | ||
500 | static int sh_eth_is_gether(struct sh_eth_private *mdp) | ||
501 | { | ||
502 | if (mdp->reg_offset == sh_eth_offset_gigabit) | ||
503 | return 1; | ||
504 | else | ||
505 | return 0; | ||
506 | } | ||
507 | |||
508 | static unsigned long sh_eth_get_edtrr_trns(struct sh_eth_private *mdp) | ||
509 | { | ||
510 | if (sh_eth_is_gether(mdp)) | ||
511 | return EDTRR_TRNS_GETHER; | ||
512 | else | ||
513 | return EDTRR_TRNS_ETHER; | ||
514 | } | ||
515 | |||
370 | struct bb_info { | 516 | struct bb_info { |
517 | void (*set_gate)(unsigned long addr); | ||
371 | struct mdiobb_ctrl ctrl; | 518 | struct mdiobb_ctrl ctrl; |
372 | u32 addr; | 519 | u32 addr; |
373 | u32 mmd_msk;/* MMD */ | 520 | u32 mmd_msk;/* MMD */ |
@@ -379,25 +526,29 @@ struct bb_info { | |||
379 | /* PHY bit set */ | 526 | /* PHY bit set */ |
380 | static void bb_set(u32 addr, u32 msk) | 527 | static void bb_set(u32 addr, u32 msk) |
381 | { | 528 | { |
382 | ctrl_outl(ctrl_inl(addr) | msk, addr); | 529 | writel(readl(addr) | msk, addr); |
383 | } | 530 | } |
384 | 531 | ||
385 | /* PHY bit clear */ | 532 | /* PHY bit clear */ |
386 | static void bb_clr(u32 addr, u32 msk) | 533 | static void bb_clr(u32 addr, u32 msk) |
387 | { | 534 | { |
388 | ctrl_outl((ctrl_inl(addr) & ~msk), addr); | 535 | writel((readl(addr) & ~msk), addr); |
389 | } | 536 | } |
390 | 537 | ||
391 | /* PHY bit read */ | 538 | /* PHY bit read */ |
392 | static int bb_read(u32 addr, u32 msk) | 539 | static int bb_read(u32 addr, u32 msk) |
393 | { | 540 | { |
394 | return (ctrl_inl(addr) & msk) != 0; | 541 | return (readl(addr) & msk) != 0; |
395 | } | 542 | } |
396 | 543 | ||
397 | /* Data I/O pin control */ | 544 | /* Data I/O pin control */ |
398 | static void sh_mmd_ctrl(struct mdiobb_ctrl *ctrl, int bit) | 545 | static void sh_mmd_ctrl(struct mdiobb_ctrl *ctrl, int bit) |
399 | { | 546 | { |
400 | struct bb_info *bitbang = container_of(ctrl, struct bb_info, ctrl); | 547 | struct bb_info *bitbang = container_of(ctrl, struct bb_info, ctrl); |
548 | |||
549 | if (bitbang->set_gate) | ||
550 | bitbang->set_gate(bitbang->addr); | ||
551 | |||
401 | if (bit) | 552 | if (bit) |
402 | bb_set(bitbang->addr, bitbang->mmd_msk); | 553 | bb_set(bitbang->addr, bitbang->mmd_msk); |
403 | else | 554 | else |
@@ -409,6 +560,9 @@ static void sh_set_mdio(struct mdiobb_ctrl *ctrl, int bit) | |||
409 | { | 560 | { |
410 | struct bb_info *bitbang = container_of(ctrl, struct bb_info, ctrl); | 561 | struct bb_info *bitbang = container_of(ctrl, struct bb_info, ctrl); |
411 | 562 | ||
563 | if (bitbang->set_gate) | ||
564 | bitbang->set_gate(bitbang->addr); | ||
565 | |||
412 | if (bit) | 566 | if (bit) |
413 | bb_set(bitbang->addr, bitbang->mdo_msk); | 567 | bb_set(bitbang->addr, bitbang->mdo_msk); |
414 | else | 568 | else |
@@ -419,6 +573,10 @@ static void sh_set_mdio(struct mdiobb_ctrl *ctrl, int bit) | |||
419 | static int sh_get_mdio(struct mdiobb_ctrl *ctrl) | 573 | static int sh_get_mdio(struct mdiobb_ctrl *ctrl) |
420 | { | 574 | { |
421 | struct bb_info *bitbang = container_of(ctrl, struct bb_info, ctrl); | 575 | struct bb_info *bitbang = container_of(ctrl, struct bb_info, ctrl); |
576 | |||
577 | if (bitbang->set_gate) | ||
578 | bitbang->set_gate(bitbang->addr); | ||
579 | |||
422 | return bb_read(bitbang->addr, bitbang->mdi_msk); | 580 | return bb_read(bitbang->addr, bitbang->mdi_msk); |
423 | } | 581 | } |
424 | 582 | ||
@@ -427,6 +585,9 @@ static void sh_mdc_ctrl(struct mdiobb_ctrl *ctrl, int bit) | |||
427 | { | 585 | { |
428 | struct bb_info *bitbang = container_of(ctrl, struct bb_info, ctrl); | 586 | struct bb_info *bitbang = container_of(ctrl, struct bb_info, ctrl); |
429 | 587 | ||
588 | if (bitbang->set_gate) | ||
589 | bitbang->set_gate(bitbang->addr); | ||
590 | |||
430 | if (bit) | 591 | if (bit) |
431 | bb_set(bitbang->addr, bitbang->mdc_msk); | 592 | bb_set(bitbang->addr, bitbang->mdc_msk); |
432 | else | 593 | else |
@@ -470,7 +631,6 @@ static void sh_eth_ring_free(struct net_device *ndev) | |||
470 | /* format skb and descriptor buffer */ | 631 | /* format skb and descriptor buffer */ |
471 | static void sh_eth_ring_format(struct net_device *ndev) | 632 | static void sh_eth_ring_format(struct net_device *ndev) |
472 | { | 633 | { |
473 | u32 ioaddr = ndev->base_addr; | ||
474 | struct sh_eth_private *mdp = netdev_priv(ndev); | 634 | struct sh_eth_private *mdp = netdev_priv(ndev); |
475 | int i; | 635 | int i; |
476 | struct sk_buff *skb; | 636 | struct sk_buff *skb; |
@@ -506,10 +666,9 @@ static void sh_eth_ring_format(struct net_device *ndev) | |||
506 | rxdesc->buffer_length = ALIGN(mdp->rx_buf_sz, 16); | 666 | rxdesc->buffer_length = ALIGN(mdp->rx_buf_sz, 16); |
507 | /* Rx descriptor address set */ | 667 | /* Rx descriptor address set */ |
508 | if (i == 0) { | 668 | if (i == 0) { |
509 | ctrl_outl(mdp->rx_desc_dma, ioaddr + RDLAR); | 669 | sh_eth_write(ndev, mdp->rx_desc_dma, RDLAR); |
510 | #if defined(CONFIG_CPU_SUBTYPE_SH7763) | 670 | if (sh_eth_is_gether(mdp)) |
511 | ctrl_outl(mdp->rx_desc_dma, ioaddr + RDFAR); | 671 | sh_eth_write(ndev, mdp->rx_desc_dma, RDFAR); |
512 | #endif | ||
513 | } | 672 | } |
514 | } | 673 | } |
515 | 674 | ||
@@ -528,10 +687,9 @@ static void sh_eth_ring_format(struct net_device *ndev) | |||
528 | txdesc->buffer_length = 0; | 687 | txdesc->buffer_length = 0; |
529 | if (i == 0) { | 688 | if (i == 0) { |
530 | /* Tx descriptor address set */ | 689 | /* Tx descriptor address set */ |
531 | ctrl_outl(mdp->tx_desc_dma, ioaddr + TDLAR); | 690 | sh_eth_write(ndev, mdp->tx_desc_dma, TDLAR); |
532 | #if defined(CONFIG_CPU_SUBTYPE_SH7763) | 691 | if (sh_eth_is_gether(mdp)) |
533 | ctrl_outl(mdp->tx_desc_dma, ioaddr + TDFAR); | 692 | sh_eth_write(ndev, mdp->tx_desc_dma, TDFAR); |
534 | #endif | ||
535 | } | 693 | } |
536 | } | 694 | } |
537 | 695 | ||
@@ -613,7 +771,6 @@ static int sh_eth_dev_init(struct net_device *ndev) | |||
613 | { | 771 | { |
614 | int ret = 0; | 772 | int ret = 0; |
615 | struct sh_eth_private *mdp = netdev_priv(ndev); | 773 | struct sh_eth_private *mdp = netdev_priv(ndev); |
616 | u32 ioaddr = ndev->base_addr; | ||
617 | u_int32_t rx_int_var, tx_int_var; | 774 | u_int32_t rx_int_var, tx_int_var; |
618 | u32 val; | 775 | u32 val; |
619 | 776 | ||
@@ -623,71 +780,71 @@ static int sh_eth_dev_init(struct net_device *ndev) | |||
623 | /* Descriptor format */ | 780 | /* Descriptor format */ |
624 | sh_eth_ring_format(ndev); | 781 | sh_eth_ring_format(ndev); |
625 | if (mdp->cd->rpadir) | 782 | if (mdp->cd->rpadir) |
626 | ctrl_outl(mdp->cd->rpadir_value, ioaddr + RPADIR); | 783 | sh_eth_write(ndev, mdp->cd->rpadir_value, RPADIR); |
627 | 784 | ||
628 | /* all sh_eth int mask */ | 785 | /* all sh_eth int mask */ |
629 | ctrl_outl(0, ioaddr + EESIPR); | 786 | sh_eth_write(ndev, 0, EESIPR); |
630 | 787 | ||
631 | #if defined(__LITTLE_ENDIAN__) | 788 | #if defined(__LITTLE_ENDIAN__) |
632 | if (mdp->cd->hw_swap) | 789 | if (mdp->cd->hw_swap) |
633 | ctrl_outl(EDMR_EL, ioaddr + EDMR); | 790 | sh_eth_write(ndev, EDMR_EL, EDMR); |
634 | else | 791 | else |
635 | #endif | 792 | #endif |
636 | ctrl_outl(0, ioaddr + EDMR); | 793 | sh_eth_write(ndev, 0, EDMR); |
637 | 794 | ||
638 | /* FIFO size set */ | 795 | /* FIFO size set */ |
639 | ctrl_outl(mdp->cd->fdr_value, ioaddr + FDR); | 796 | sh_eth_write(ndev, mdp->cd->fdr_value, FDR); |
640 | ctrl_outl(0, ioaddr + TFTR); | 797 | sh_eth_write(ndev, 0, TFTR); |
641 | 798 | ||
642 | /* Frame recv control */ | 799 | /* Frame recv control */ |
643 | ctrl_outl(mdp->cd->rmcr_value, ioaddr + RMCR); | 800 | sh_eth_write(ndev, mdp->cd->rmcr_value, RMCR); |
644 | 801 | ||
645 | rx_int_var = mdp->rx_int_var = DESC_I_RINT8 | DESC_I_RINT5; | 802 | rx_int_var = mdp->rx_int_var = DESC_I_RINT8 | DESC_I_RINT5; |
646 | tx_int_var = mdp->tx_int_var = DESC_I_TINT2; | 803 | tx_int_var = mdp->tx_int_var = DESC_I_TINT2; |
647 | ctrl_outl(rx_int_var | tx_int_var, ioaddr + TRSCER); | 804 | sh_eth_write(ndev, rx_int_var | tx_int_var, TRSCER); |
648 | 805 | ||
649 | if (mdp->cd->bculr) | 806 | if (mdp->cd->bculr) |
650 | ctrl_outl(0x800, ioaddr + BCULR); /* Burst sycle set */ | 807 | sh_eth_write(ndev, 0x800, BCULR); /* Burst sycle set */ |
651 | 808 | ||
652 | ctrl_outl(mdp->cd->fcftr_value, ioaddr + FCFTR); | 809 | sh_eth_write(ndev, mdp->cd->fcftr_value, FCFTR); |
653 | 810 | ||
654 | if (!mdp->cd->no_trimd) | 811 | if (!mdp->cd->no_trimd) |
655 | ctrl_outl(0, ioaddr + TRIMD); | 812 | sh_eth_write(ndev, 0, TRIMD); |
656 | 813 | ||
657 | /* Recv frame limit set register */ | 814 | /* Recv frame limit set register */ |
658 | ctrl_outl(RFLR_VALUE, ioaddr + RFLR); | 815 | sh_eth_write(ndev, RFLR_VALUE, RFLR); |
659 | 816 | ||
660 | ctrl_outl(ctrl_inl(ioaddr + EESR), ioaddr + EESR); | 817 | sh_eth_write(ndev, sh_eth_read(ndev, EESR), EESR); |
661 | ctrl_outl(mdp->cd->eesipr_value, ioaddr + EESIPR); | 818 | sh_eth_write(ndev, mdp->cd->eesipr_value, EESIPR); |
662 | 819 | ||
663 | /* PAUSE Prohibition */ | 820 | /* PAUSE Prohibition */ |
664 | val = (ctrl_inl(ioaddr + ECMR) & ECMR_DM) | | 821 | val = (sh_eth_read(ndev, ECMR) & ECMR_DM) | |
665 | ECMR_ZPF | (mdp->duplex ? ECMR_DM : 0) | ECMR_TE | ECMR_RE; | 822 | ECMR_ZPF | (mdp->duplex ? ECMR_DM : 0) | ECMR_TE | ECMR_RE; |
666 | 823 | ||
667 | ctrl_outl(val, ioaddr + ECMR); | 824 | sh_eth_write(ndev, val, ECMR); |
668 | 825 | ||
669 | if (mdp->cd->set_rate) | 826 | if (mdp->cd->set_rate) |
670 | mdp->cd->set_rate(ndev); | 827 | mdp->cd->set_rate(ndev); |
671 | 828 | ||
672 | /* E-MAC Status Register clear */ | 829 | /* E-MAC Status Register clear */ |
673 | ctrl_outl(mdp->cd->ecsr_value, ioaddr + ECSR); | 830 | sh_eth_write(ndev, mdp->cd->ecsr_value, ECSR); |
674 | 831 | ||
675 | /* E-MAC Interrupt Enable register */ | 832 | /* E-MAC Interrupt Enable register */ |
676 | ctrl_outl(mdp->cd->ecsipr_value, ioaddr + ECSIPR); | 833 | sh_eth_write(ndev, mdp->cd->ecsipr_value, ECSIPR); |
677 | 834 | ||
678 | /* Set MAC address */ | 835 | /* Set MAC address */ |
679 | update_mac_address(ndev); | 836 | update_mac_address(ndev); |
680 | 837 | ||
681 | /* mask reset */ | 838 | /* mask reset */ |
682 | if (mdp->cd->apr) | 839 | if (mdp->cd->apr) |
683 | ctrl_outl(APR_AP, ioaddr + APR); | 840 | sh_eth_write(ndev, APR_AP, APR); |
684 | if (mdp->cd->mpr) | 841 | if (mdp->cd->mpr) |
685 | ctrl_outl(MPR_MP, ioaddr + MPR); | 842 | sh_eth_write(ndev, MPR_MP, MPR); |
686 | if (mdp->cd->tpauser) | 843 | if (mdp->cd->tpauser) |
687 | ctrl_outl(TPAUSER_UNLIMITED, ioaddr + TPAUSER); | 844 | sh_eth_write(ndev, TPAUSER_UNLIMITED, TPAUSER); |
688 | 845 | ||
689 | /* Setting the Rx mode will start the Rx process. */ | 846 | /* Setting the Rx mode will start the Rx process. */ |
690 | ctrl_outl(EDRRR_R, ioaddr + EDRRR); | 847 | sh_eth_write(ndev, EDRRR_R, EDRRR); |
691 | 848 | ||
692 | netif_start_queue(ndev); | 849 | netif_start_queue(ndev); |
693 | 850 | ||
@@ -798,7 +955,7 @@ static int sh_eth_rx(struct net_device *ndev) | |||
798 | skb->dev = ndev; | 955 | skb->dev = ndev; |
799 | sh_eth_set_receive_align(skb); | 956 | sh_eth_set_receive_align(skb); |
800 | 957 | ||
801 | skb->ip_summed = CHECKSUM_NONE; | 958 | skb_checksum_none_assert(skb); |
802 | rxdesc->addr = virt_to_phys(PTR_ALIGN(skb->data, 4)); | 959 | rxdesc->addr = virt_to_phys(PTR_ALIGN(skb->data, 4)); |
803 | } | 960 | } |
804 | if (entry >= RX_RING_SIZE - 1) | 961 | if (entry >= RX_RING_SIZE - 1) |
@@ -811,24 +968,37 @@ static int sh_eth_rx(struct net_device *ndev) | |||
811 | 968 | ||
812 | /* Restart Rx engine if stopped. */ | 969 | /* Restart Rx engine if stopped. */ |
813 | /* If we don't need to check status, don't. -KDU */ | 970 | /* If we don't need to check status, don't. -KDU */ |
814 | if (!(ctrl_inl(ndev->base_addr + EDRRR) & EDRRR_R)) | 971 | if (!(sh_eth_read(ndev, EDRRR) & EDRRR_R)) |
815 | ctrl_outl(EDRRR_R, ndev->base_addr + EDRRR); | 972 | sh_eth_write(ndev, EDRRR_R, EDRRR); |
816 | 973 | ||
817 | return 0; | 974 | return 0; |
818 | } | 975 | } |
819 | 976 | ||
977 | static void sh_eth_rcv_snd_disable(struct net_device *ndev) | ||
978 | { | ||
979 | /* disable tx and rx */ | ||
980 | sh_eth_write(ndev, sh_eth_read(ndev, ECMR) & | ||
981 | ~(ECMR_RE | ECMR_TE), ECMR); | ||
982 | } | ||
983 | |||
984 | static void sh_eth_rcv_snd_enable(struct net_device *ndev) | ||
985 | { | ||
986 | /* enable tx and rx */ | ||
987 | sh_eth_write(ndev, sh_eth_read(ndev, ECMR) | | ||
988 | (ECMR_RE | ECMR_TE), ECMR); | ||
989 | } | ||
990 | |||
820 | /* error control function */ | 991 | /* error control function */ |
821 | static void sh_eth_error(struct net_device *ndev, int intr_status) | 992 | static void sh_eth_error(struct net_device *ndev, int intr_status) |
822 | { | 993 | { |
823 | struct sh_eth_private *mdp = netdev_priv(ndev); | 994 | struct sh_eth_private *mdp = netdev_priv(ndev); |
824 | u32 ioaddr = ndev->base_addr; | ||
825 | u32 felic_stat; | 995 | u32 felic_stat; |
826 | u32 link_stat; | 996 | u32 link_stat; |
827 | u32 mask; | 997 | u32 mask; |
828 | 998 | ||
829 | if (intr_status & EESR_ECI) { | 999 | if (intr_status & EESR_ECI) { |
830 | felic_stat = ctrl_inl(ioaddr + ECSR); | 1000 | felic_stat = sh_eth_read(ndev, ECSR); |
831 | ctrl_outl(felic_stat, ioaddr + ECSR); /* clear int */ | 1001 | sh_eth_write(ndev, felic_stat, ECSR); /* clear int */ |
832 | if (felic_stat & ECSR_ICD) | 1002 | if (felic_stat & ECSR_ICD) |
833 | mdp->stats.tx_carrier_errors++; | 1003 | mdp->stats.tx_carrier_errors++; |
834 | if (felic_stat & ECSR_LCHNG) { | 1004 | if (felic_stat & ECSR_LCHNG) { |
@@ -839,26 +1009,23 @@ static void sh_eth_error(struct net_device *ndev, int intr_status) | |||
839 | else | 1009 | else |
840 | link_stat = PHY_ST_LINK; | 1010 | link_stat = PHY_ST_LINK; |
841 | } else { | 1011 | } else { |
842 | link_stat = (ctrl_inl(ioaddr + PSR)); | 1012 | link_stat = (sh_eth_read(ndev, PSR)); |
843 | if (mdp->ether_link_active_low) | 1013 | if (mdp->ether_link_active_low) |
844 | link_stat = ~link_stat; | 1014 | link_stat = ~link_stat; |
845 | } | 1015 | } |
846 | if (!(link_stat & PHY_ST_LINK)) { | 1016 | if (!(link_stat & PHY_ST_LINK)) |
847 | /* Link Down : disable tx and rx */ | 1017 | sh_eth_rcv_snd_disable(ndev); |
848 | ctrl_outl(ctrl_inl(ioaddr + ECMR) & | 1018 | else { |
849 | ~(ECMR_RE | ECMR_TE), ioaddr + ECMR); | ||
850 | } else { | ||
851 | /* Link Up */ | 1019 | /* Link Up */ |
852 | ctrl_outl(ctrl_inl(ioaddr + EESIPR) & | 1020 | sh_eth_write(ndev, sh_eth_read(ndev, EESIPR) & |
853 | ~DMAC_M_ECI, ioaddr + EESIPR); | 1021 | ~DMAC_M_ECI, EESIPR); |
854 | /*clear int */ | 1022 | /*clear int */ |
855 | ctrl_outl(ctrl_inl(ioaddr + ECSR), | 1023 | sh_eth_write(ndev, sh_eth_read(ndev, ECSR), |
856 | ioaddr + ECSR); | 1024 | ECSR); |
857 | ctrl_outl(ctrl_inl(ioaddr + EESIPR) | | 1025 | sh_eth_write(ndev, sh_eth_read(ndev, EESIPR) | |
858 | DMAC_M_ECI, ioaddr + EESIPR); | 1026 | DMAC_M_ECI, EESIPR); |
859 | /* enable tx and rx */ | 1027 | /* enable tx and rx */ |
860 | ctrl_outl(ctrl_inl(ioaddr + ECMR) | | 1028 | sh_eth_rcv_snd_enable(ndev); |
861 | (ECMR_RE | ECMR_TE), ioaddr + ECMR); | ||
862 | } | 1029 | } |
863 | } | 1030 | } |
864 | } | 1031 | } |
@@ -867,6 +1034,8 @@ static void sh_eth_error(struct net_device *ndev, int intr_status) | |||
867 | /* Write buck end. unused write back interrupt */ | 1034 | /* Write buck end. unused write back interrupt */ |
868 | if (intr_status & EESR_TABT) /* Transmit Abort int */ | 1035 | if (intr_status & EESR_TABT) /* Transmit Abort int */ |
869 | mdp->stats.tx_aborted_errors++; | 1036 | mdp->stats.tx_aborted_errors++; |
1037 | if (netif_msg_tx_err(mdp)) | ||
1038 | dev_err(&ndev->dev, "Transmit Abort\n"); | ||
870 | } | 1039 | } |
871 | 1040 | ||
872 | if (intr_status & EESR_RABT) { | 1041 | if (intr_status & EESR_RABT) { |
@@ -874,28 +1043,47 @@ static void sh_eth_error(struct net_device *ndev, int intr_status) | |||
874 | if (intr_status & EESR_RFRMER) { | 1043 | if (intr_status & EESR_RFRMER) { |
875 | /* Receive Frame Overflow int */ | 1044 | /* Receive Frame Overflow int */ |
876 | mdp->stats.rx_frame_errors++; | 1045 | mdp->stats.rx_frame_errors++; |
877 | dev_err(&ndev->dev, "Receive Frame Overflow\n"); | 1046 | if (netif_msg_rx_err(mdp)) |
1047 | dev_err(&ndev->dev, "Receive Abort\n"); | ||
878 | } | 1048 | } |
879 | } | 1049 | } |
880 | 1050 | ||
881 | if (!mdp->cd->no_ade) { | 1051 | if (intr_status & EESR_TDE) { |
882 | if (intr_status & EESR_ADE && intr_status & EESR_TDE && | 1052 | /* Transmit Descriptor Empty int */ |
883 | intr_status & EESR_TFE) | 1053 | mdp->stats.tx_fifo_errors++; |
884 | mdp->stats.tx_fifo_errors++; | 1054 | if (netif_msg_tx_err(mdp)) |
1055 | dev_err(&ndev->dev, "Transmit Descriptor Empty\n"); | ||
1056 | } | ||
1057 | |||
1058 | if (intr_status & EESR_TFE) { | ||
1059 | /* FIFO under flow */ | ||
1060 | mdp->stats.tx_fifo_errors++; | ||
1061 | if (netif_msg_tx_err(mdp)) | ||
1062 | dev_err(&ndev->dev, "Transmit FIFO Under flow\n"); | ||
885 | } | 1063 | } |
886 | 1064 | ||
887 | if (intr_status & EESR_RDE) { | 1065 | if (intr_status & EESR_RDE) { |
888 | /* Receive Descriptor Empty int */ | 1066 | /* Receive Descriptor Empty int */ |
889 | mdp->stats.rx_over_errors++; | 1067 | mdp->stats.rx_over_errors++; |
890 | 1068 | ||
891 | if (ctrl_inl(ioaddr + EDRRR) ^ EDRRR_R) | 1069 | if (sh_eth_read(ndev, EDRRR) ^ EDRRR_R) |
892 | ctrl_outl(EDRRR_R, ioaddr + EDRRR); | 1070 | sh_eth_write(ndev, EDRRR_R, EDRRR); |
893 | dev_err(&ndev->dev, "Receive Descriptor Empty\n"); | 1071 | if (netif_msg_rx_err(mdp)) |
1072 | dev_err(&ndev->dev, "Receive Descriptor Empty\n"); | ||
894 | } | 1073 | } |
1074 | |||
895 | if (intr_status & EESR_RFE) { | 1075 | if (intr_status & EESR_RFE) { |
896 | /* Receive FIFO Overflow int */ | 1076 | /* Receive FIFO Overflow int */ |
897 | mdp->stats.rx_fifo_errors++; | 1077 | mdp->stats.rx_fifo_errors++; |
898 | dev_err(&ndev->dev, "Receive FIFO Overflow\n"); | 1078 | if (netif_msg_rx_err(mdp)) |
1079 | dev_err(&ndev->dev, "Receive FIFO Overflow\n"); | ||
1080 | } | ||
1081 | |||
1082 | if (!mdp->cd->no_ade && (intr_status & EESR_ADE)) { | ||
1083 | /* Address Error */ | ||
1084 | mdp->stats.tx_fifo_errors++; | ||
1085 | if (netif_msg_tx_err(mdp)) | ||
1086 | dev_err(&ndev->dev, "Address Error\n"); | ||
899 | } | 1087 | } |
900 | 1088 | ||
901 | mask = EESR_TWB | EESR_TABT | EESR_ADE | EESR_TDE | EESR_TFE; | 1089 | mask = EESR_TWB | EESR_TABT | EESR_ADE | EESR_TDE | EESR_TFE; |
@@ -903,7 +1091,7 @@ static void sh_eth_error(struct net_device *ndev, int intr_status) | |||
903 | mask &= ~EESR_ADE; | 1091 | mask &= ~EESR_ADE; |
904 | if (intr_status & mask) { | 1092 | if (intr_status & mask) { |
905 | /* Tx error */ | 1093 | /* Tx error */ |
906 | u32 edtrr = ctrl_inl(ndev->base_addr + EDTRR); | 1094 | u32 edtrr = sh_eth_read(ndev, EDTRR); |
907 | /* dmesg */ | 1095 | /* dmesg */ |
908 | dev_err(&ndev->dev, "TX error. status=%8.8x cur_tx=%8.8x ", | 1096 | dev_err(&ndev->dev, "TX error. status=%8.8x cur_tx=%8.8x ", |
909 | intr_status, mdp->cur_tx); | 1097 | intr_status, mdp->cur_tx); |
@@ -913,9 +1101,9 @@ static void sh_eth_error(struct net_device *ndev, int intr_status) | |||
913 | sh_eth_txfree(ndev); | 1101 | sh_eth_txfree(ndev); |
914 | 1102 | ||
915 | /* SH7712 BUG */ | 1103 | /* SH7712 BUG */ |
916 | if (edtrr ^ EDTRR_TRNS) { | 1104 | if (edtrr ^ sh_eth_get_edtrr_trns(mdp)) { |
917 | /* tx dma start */ | 1105 | /* tx dma start */ |
918 | ctrl_outl(EDTRR_TRNS, ndev->base_addr + EDTRR); | 1106 | sh_eth_write(ndev, sh_eth_get_edtrr_trns(mdp), EDTRR); |
919 | } | 1107 | } |
920 | /* wakeup */ | 1108 | /* wakeup */ |
921 | netif_wake_queue(ndev); | 1109 | netif_wake_queue(ndev); |
@@ -928,18 +1116,17 @@ static irqreturn_t sh_eth_interrupt(int irq, void *netdev) | |||
928 | struct sh_eth_private *mdp = netdev_priv(ndev); | 1116 | struct sh_eth_private *mdp = netdev_priv(ndev); |
929 | struct sh_eth_cpu_data *cd = mdp->cd; | 1117 | struct sh_eth_cpu_data *cd = mdp->cd; |
930 | irqreturn_t ret = IRQ_NONE; | 1118 | irqreturn_t ret = IRQ_NONE; |
931 | u32 ioaddr, intr_status = 0; | 1119 | u32 intr_status = 0; |
932 | 1120 | ||
933 | ioaddr = ndev->base_addr; | ||
934 | spin_lock(&mdp->lock); | 1121 | spin_lock(&mdp->lock); |
935 | 1122 | ||
936 | /* Get interrpt stat */ | 1123 | /* Get interrpt stat */ |
937 | intr_status = ctrl_inl(ioaddr + EESR); | 1124 | intr_status = sh_eth_read(ndev, EESR); |
938 | /* Clear interrupt */ | 1125 | /* Clear interrupt */ |
939 | if (intr_status & (EESR_FRC | EESR_RMAF | EESR_RRF | | 1126 | if (intr_status & (EESR_FRC | EESR_RMAF | EESR_RRF | |
940 | EESR_RTLF | EESR_RTSF | EESR_PRE | EESR_CERF | | 1127 | EESR_RTLF | EESR_RTSF | EESR_PRE | EESR_CERF | |
941 | cd->tx_check | cd->eesr_err_check)) { | 1128 | cd->tx_check | cd->eesr_err_check)) { |
942 | ctrl_outl(intr_status, ioaddr + EESR); | 1129 | sh_eth_write(ndev, intr_status, EESR); |
943 | ret = IRQ_HANDLED; | 1130 | ret = IRQ_HANDLED; |
944 | } else | 1131 | } else |
945 | goto other_irq; | 1132 | goto other_irq; |
@@ -982,7 +1169,6 @@ static void sh_eth_adjust_link(struct net_device *ndev) | |||
982 | { | 1169 | { |
983 | struct sh_eth_private *mdp = netdev_priv(ndev); | 1170 | struct sh_eth_private *mdp = netdev_priv(ndev); |
984 | struct phy_device *phydev = mdp->phydev; | 1171 | struct phy_device *phydev = mdp->phydev; |
985 | u32 ioaddr = ndev->base_addr; | ||
986 | int new_state = 0; | 1172 | int new_state = 0; |
987 | 1173 | ||
988 | if (phydev->link != PHY_DOWN) { | 1174 | if (phydev->link != PHY_DOWN) { |
@@ -1000,8 +1186,8 @@ static void sh_eth_adjust_link(struct net_device *ndev) | |||
1000 | mdp->cd->set_rate(ndev); | 1186 | mdp->cd->set_rate(ndev); |
1001 | } | 1187 | } |
1002 | if (mdp->link == PHY_DOWN) { | 1188 | if (mdp->link == PHY_DOWN) { |
1003 | ctrl_outl((ctrl_inl(ioaddr + ECMR) & ~ECMR_TXF) | 1189 | sh_eth_write(ndev, |
1004 | | ECMR_DM, ioaddr + ECMR); | 1190 | (sh_eth_read(ndev, ECMR) & ~ECMR_TXF), ECMR); |
1005 | new_state = 1; | 1191 | new_state = 1; |
1006 | mdp->link = phydev->link; | 1192 | mdp->link = phydev->link; |
1007 | } | 1193 | } |
@@ -1012,7 +1198,7 @@ static void sh_eth_adjust_link(struct net_device *ndev) | |||
1012 | mdp->duplex = -1; | 1198 | mdp->duplex = -1; |
1013 | } | 1199 | } |
1014 | 1200 | ||
1015 | if (new_state) | 1201 | if (new_state && netif_msg_link(mdp)) |
1016 | phy_print_status(phydev); | 1202 | phy_print_status(phydev); |
1017 | } | 1203 | } |
1018 | 1204 | ||
@@ -1031,8 +1217,8 @@ static int sh_eth_phy_init(struct net_device *ndev) | |||
1031 | mdp->duplex = -1; | 1217 | mdp->duplex = -1; |
1032 | 1218 | ||
1033 | /* Try connect to PHY */ | 1219 | /* Try connect to PHY */ |
1034 | phydev = phy_connect(ndev, phy_id, &sh_eth_adjust_link, | 1220 | phydev = phy_connect(ndev, phy_id, sh_eth_adjust_link, |
1035 | 0, PHY_INTERFACE_MODE_MII); | 1221 | 0, mdp->phy_interface); |
1036 | if (IS_ERR(phydev)) { | 1222 | if (IS_ERR(phydev)) { |
1037 | dev_err(&ndev->dev, "phy_connect failed\n"); | 1223 | dev_err(&ndev->dev, "phy_connect failed\n"); |
1038 | return PTR_ERR(phydev); | 1224 | return PTR_ERR(phydev); |
@@ -1063,6 +1249,131 @@ static int sh_eth_phy_start(struct net_device *ndev) | |||
1063 | return 0; | 1249 | return 0; |
1064 | } | 1250 | } |
1065 | 1251 | ||
1252 | static int sh_eth_get_settings(struct net_device *ndev, | ||
1253 | struct ethtool_cmd *ecmd) | ||
1254 | { | ||
1255 | struct sh_eth_private *mdp = netdev_priv(ndev); | ||
1256 | unsigned long flags; | ||
1257 | int ret; | ||
1258 | |||
1259 | spin_lock_irqsave(&mdp->lock, flags); | ||
1260 | ret = phy_ethtool_gset(mdp->phydev, ecmd); | ||
1261 | spin_unlock_irqrestore(&mdp->lock, flags); | ||
1262 | |||
1263 | return ret; | ||
1264 | } | ||
1265 | |||
1266 | static int sh_eth_set_settings(struct net_device *ndev, | ||
1267 | struct ethtool_cmd *ecmd) | ||
1268 | { | ||
1269 | struct sh_eth_private *mdp = netdev_priv(ndev); | ||
1270 | unsigned long flags; | ||
1271 | int ret; | ||
1272 | |||
1273 | spin_lock_irqsave(&mdp->lock, flags); | ||
1274 | |||
1275 | /* disable tx and rx */ | ||
1276 | sh_eth_rcv_snd_disable(ndev); | ||
1277 | |||
1278 | ret = phy_ethtool_sset(mdp->phydev, ecmd); | ||
1279 | if (ret) | ||
1280 | goto error_exit; | ||
1281 | |||
1282 | if (ecmd->duplex == DUPLEX_FULL) | ||
1283 | mdp->duplex = 1; | ||
1284 | else | ||
1285 | mdp->duplex = 0; | ||
1286 | |||
1287 | if (mdp->cd->set_duplex) | ||
1288 | mdp->cd->set_duplex(ndev); | ||
1289 | |||
1290 | error_exit: | ||
1291 | mdelay(1); | ||
1292 | |||
1293 | /* enable tx and rx */ | ||
1294 | sh_eth_rcv_snd_enable(ndev); | ||
1295 | |||
1296 | spin_unlock_irqrestore(&mdp->lock, flags); | ||
1297 | |||
1298 | return ret; | ||
1299 | } | ||
1300 | |||
1301 | static int sh_eth_nway_reset(struct net_device *ndev) | ||
1302 | { | ||
1303 | struct sh_eth_private *mdp = netdev_priv(ndev); | ||
1304 | unsigned long flags; | ||
1305 | int ret; | ||
1306 | |||
1307 | spin_lock_irqsave(&mdp->lock, flags); | ||
1308 | ret = phy_start_aneg(mdp->phydev); | ||
1309 | spin_unlock_irqrestore(&mdp->lock, flags); | ||
1310 | |||
1311 | return ret; | ||
1312 | } | ||
1313 | |||
1314 | static u32 sh_eth_get_msglevel(struct net_device *ndev) | ||
1315 | { | ||
1316 | struct sh_eth_private *mdp = netdev_priv(ndev); | ||
1317 | return mdp->msg_enable; | ||
1318 | } | ||
1319 | |||
1320 | static void sh_eth_set_msglevel(struct net_device *ndev, u32 value) | ||
1321 | { | ||
1322 | struct sh_eth_private *mdp = netdev_priv(ndev); | ||
1323 | mdp->msg_enable = value; | ||
1324 | } | ||
1325 | |||
1326 | static const char sh_eth_gstrings_stats[][ETH_GSTRING_LEN] = { | ||
1327 | "rx_current", "tx_current", | ||
1328 | "rx_dirty", "tx_dirty", | ||
1329 | }; | ||
1330 | #define SH_ETH_STATS_LEN ARRAY_SIZE(sh_eth_gstrings_stats) | ||
1331 | |||
1332 | static int sh_eth_get_sset_count(struct net_device *netdev, int sset) | ||
1333 | { | ||
1334 | switch (sset) { | ||
1335 | case ETH_SS_STATS: | ||
1336 | return SH_ETH_STATS_LEN; | ||
1337 | default: | ||
1338 | return -EOPNOTSUPP; | ||
1339 | } | ||
1340 | } | ||
1341 | |||
1342 | static void sh_eth_get_ethtool_stats(struct net_device *ndev, | ||
1343 | struct ethtool_stats *stats, u64 *data) | ||
1344 | { | ||
1345 | struct sh_eth_private *mdp = netdev_priv(ndev); | ||
1346 | int i = 0; | ||
1347 | |||
1348 | /* device-specific stats */ | ||
1349 | data[i++] = mdp->cur_rx; | ||
1350 | data[i++] = mdp->cur_tx; | ||
1351 | data[i++] = mdp->dirty_rx; | ||
1352 | data[i++] = mdp->dirty_tx; | ||
1353 | } | ||
1354 | |||
1355 | static void sh_eth_get_strings(struct net_device *ndev, u32 stringset, u8 *data) | ||
1356 | { | ||
1357 | switch (stringset) { | ||
1358 | case ETH_SS_STATS: | ||
1359 | memcpy(data, *sh_eth_gstrings_stats, | ||
1360 | sizeof(sh_eth_gstrings_stats)); | ||
1361 | break; | ||
1362 | } | ||
1363 | } | ||
1364 | |||
1365 | static struct ethtool_ops sh_eth_ethtool_ops = { | ||
1366 | .get_settings = sh_eth_get_settings, | ||
1367 | .set_settings = sh_eth_set_settings, | ||
1368 | .nway_reset = sh_eth_nway_reset, | ||
1369 | .get_msglevel = sh_eth_get_msglevel, | ||
1370 | .set_msglevel = sh_eth_set_msglevel, | ||
1371 | .get_link = ethtool_op_get_link, | ||
1372 | .get_strings = sh_eth_get_strings, | ||
1373 | .get_ethtool_stats = sh_eth_get_ethtool_stats, | ||
1374 | .get_sset_count = sh_eth_get_sset_count, | ||
1375 | }; | ||
1376 | |||
1066 | /* network device open function */ | 1377 | /* network device open function */ |
1067 | static int sh_eth_open(struct net_device *ndev) | 1378 | static int sh_eth_open(struct net_device *ndev) |
1068 | { | 1379 | { |
@@ -1073,8 +1384,8 @@ static int sh_eth_open(struct net_device *ndev) | |||
1073 | 1384 | ||
1074 | ret = request_irq(ndev->irq, sh_eth_interrupt, | 1385 | ret = request_irq(ndev->irq, sh_eth_interrupt, |
1075 | #if defined(CONFIG_CPU_SUBTYPE_SH7763) || \ | 1386 | #if defined(CONFIG_CPU_SUBTYPE_SH7763) || \ |
1076 | defined(CONFIG_CPU_SUBTYPE_SH7764) || \ | 1387 | defined(CONFIG_CPU_SUBTYPE_SH7764) || \ |
1077 | defined(CONFIG_CPU_SUBTYPE_SH7757) | 1388 | defined(CONFIG_CPU_SUBTYPE_SH7757) |
1078 | IRQF_SHARED, | 1389 | IRQF_SHARED, |
1079 | #else | 1390 | #else |
1080 | 0, | 1391 | 0, |
@@ -1117,15 +1428,14 @@ out_free_irq: | |||
1117 | static void sh_eth_tx_timeout(struct net_device *ndev) | 1428 | static void sh_eth_tx_timeout(struct net_device *ndev) |
1118 | { | 1429 | { |
1119 | struct sh_eth_private *mdp = netdev_priv(ndev); | 1430 | struct sh_eth_private *mdp = netdev_priv(ndev); |
1120 | u32 ioaddr = ndev->base_addr; | ||
1121 | struct sh_eth_rxdesc *rxdesc; | 1431 | struct sh_eth_rxdesc *rxdesc; |
1122 | int i; | 1432 | int i; |
1123 | 1433 | ||
1124 | netif_stop_queue(ndev); | 1434 | netif_stop_queue(ndev); |
1125 | 1435 | ||
1126 | /* worning message out. */ | 1436 | if (netif_msg_timer(mdp)) |
1127 | printk(KERN_WARNING "%s: transmit timed out, status %8.8x," | 1437 | dev_err(&ndev->dev, "%s: transmit timed out, status %8.8x," |
1128 | " resetting...\n", ndev->name, (int)ctrl_inl(ioaddr + EESR)); | 1438 | " resetting...\n", ndev->name, (int)sh_eth_read(ndev, EESR)); |
1129 | 1439 | ||
1130 | /* tx_errors count up */ | 1440 | /* tx_errors count up */ |
1131 | mdp->stats.tx_errors++; | 1441 | mdp->stats.tx_errors++; |
@@ -1167,6 +1477,8 @@ static int sh_eth_start_xmit(struct sk_buff *skb, struct net_device *ndev) | |||
1167 | spin_lock_irqsave(&mdp->lock, flags); | 1477 | spin_lock_irqsave(&mdp->lock, flags); |
1168 | if ((mdp->cur_tx - mdp->dirty_tx) >= (TX_RING_SIZE - 4)) { | 1478 | if ((mdp->cur_tx - mdp->dirty_tx) >= (TX_RING_SIZE - 4)) { |
1169 | if (!sh_eth_txfree(ndev)) { | 1479 | if (!sh_eth_txfree(ndev)) { |
1480 | if (netif_msg_tx_queued(mdp)) | ||
1481 | dev_warn(&ndev->dev, "TxFD exhausted.\n"); | ||
1170 | netif_stop_queue(ndev); | 1482 | netif_stop_queue(ndev); |
1171 | spin_unlock_irqrestore(&mdp->lock, flags); | 1483 | spin_unlock_irqrestore(&mdp->lock, flags); |
1172 | return NETDEV_TX_BUSY; | 1484 | return NETDEV_TX_BUSY; |
@@ -1196,8 +1508,8 @@ static int sh_eth_start_xmit(struct sk_buff *skb, struct net_device *ndev) | |||
1196 | 1508 | ||
1197 | mdp->cur_tx++; | 1509 | mdp->cur_tx++; |
1198 | 1510 | ||
1199 | if (!(ctrl_inl(ndev->base_addr + EDTRR) & EDTRR_TRNS)) | 1511 | if (!(sh_eth_read(ndev, EDTRR) & sh_eth_get_edtrr_trns(mdp))) |
1200 | ctrl_outl(EDTRR_TRNS, ndev->base_addr + EDTRR); | 1512 | sh_eth_write(ndev, sh_eth_get_edtrr_trns(mdp), EDTRR); |
1201 | 1513 | ||
1202 | return NETDEV_TX_OK; | 1514 | return NETDEV_TX_OK; |
1203 | } | 1515 | } |
@@ -1206,17 +1518,16 @@ static int sh_eth_start_xmit(struct sk_buff *skb, struct net_device *ndev) | |||
1206 | static int sh_eth_close(struct net_device *ndev) | 1518 | static int sh_eth_close(struct net_device *ndev) |
1207 | { | 1519 | { |
1208 | struct sh_eth_private *mdp = netdev_priv(ndev); | 1520 | struct sh_eth_private *mdp = netdev_priv(ndev); |
1209 | u32 ioaddr = ndev->base_addr; | ||
1210 | int ringsize; | 1521 | int ringsize; |
1211 | 1522 | ||
1212 | netif_stop_queue(ndev); | 1523 | netif_stop_queue(ndev); |
1213 | 1524 | ||
1214 | /* Disable interrupts by clearing the interrupt mask. */ | 1525 | /* Disable interrupts by clearing the interrupt mask. */ |
1215 | ctrl_outl(0x0000, ioaddr + EESIPR); | 1526 | sh_eth_write(ndev, 0x0000, EESIPR); |
1216 | 1527 | ||
1217 | /* Stop the chip's Tx and Rx processes. */ | 1528 | /* Stop the chip's Tx and Rx processes. */ |
1218 | ctrl_outl(0, ioaddr + EDTRR); | 1529 | sh_eth_write(ndev, 0, EDTRR); |
1219 | ctrl_outl(0, ioaddr + EDRRR); | 1530 | sh_eth_write(ndev, 0, EDRRR); |
1220 | 1531 | ||
1221 | /* PHY Disconnect */ | 1532 | /* PHY Disconnect */ |
1222 | if (mdp->phydev) { | 1533 | if (mdp->phydev) { |
@@ -1247,25 +1558,24 @@ static int sh_eth_close(struct net_device *ndev) | |||
1247 | static struct net_device_stats *sh_eth_get_stats(struct net_device *ndev) | 1558 | static struct net_device_stats *sh_eth_get_stats(struct net_device *ndev) |
1248 | { | 1559 | { |
1249 | struct sh_eth_private *mdp = netdev_priv(ndev); | 1560 | struct sh_eth_private *mdp = netdev_priv(ndev); |
1250 | u32 ioaddr = ndev->base_addr; | ||
1251 | 1561 | ||
1252 | pm_runtime_get_sync(&mdp->pdev->dev); | 1562 | pm_runtime_get_sync(&mdp->pdev->dev); |
1253 | 1563 | ||
1254 | mdp->stats.tx_dropped += ctrl_inl(ioaddr + TROCR); | 1564 | mdp->stats.tx_dropped += sh_eth_read(ndev, TROCR); |
1255 | ctrl_outl(0, ioaddr + TROCR); /* (write clear) */ | 1565 | sh_eth_write(ndev, 0, TROCR); /* (write clear) */ |
1256 | mdp->stats.collisions += ctrl_inl(ioaddr + CDCR); | 1566 | mdp->stats.collisions += sh_eth_read(ndev, CDCR); |
1257 | ctrl_outl(0, ioaddr + CDCR); /* (write clear) */ | 1567 | sh_eth_write(ndev, 0, CDCR); /* (write clear) */ |
1258 | mdp->stats.tx_carrier_errors += ctrl_inl(ioaddr + LCCR); | 1568 | mdp->stats.tx_carrier_errors += sh_eth_read(ndev, LCCR); |
1259 | ctrl_outl(0, ioaddr + LCCR); /* (write clear) */ | 1569 | sh_eth_write(ndev, 0, LCCR); /* (write clear) */ |
1260 | #if defined(CONFIG_CPU_SUBTYPE_SH7763) | 1570 | if (sh_eth_is_gether(mdp)) { |
1261 | mdp->stats.tx_carrier_errors += ctrl_inl(ioaddr + CERCR);/* CERCR */ | 1571 | mdp->stats.tx_carrier_errors += sh_eth_read(ndev, CERCR); |
1262 | ctrl_outl(0, ioaddr + CERCR); /* (write clear) */ | 1572 | sh_eth_write(ndev, 0, CERCR); /* (write clear) */ |
1263 | mdp->stats.tx_carrier_errors += ctrl_inl(ioaddr + CEECR);/* CEECR */ | 1573 | mdp->stats.tx_carrier_errors += sh_eth_read(ndev, CEECR); |
1264 | ctrl_outl(0, ioaddr + CEECR); /* (write clear) */ | 1574 | sh_eth_write(ndev, 0, CEECR); /* (write clear) */ |
1265 | #else | 1575 | } else { |
1266 | mdp->stats.tx_carrier_errors += ctrl_inl(ioaddr + CNDCR); | 1576 | mdp->stats.tx_carrier_errors += sh_eth_read(ndev, CNDCR); |
1267 | ctrl_outl(0, ioaddr + CNDCR); /* (write clear) */ | 1577 | sh_eth_write(ndev, 0, CNDCR); /* (write clear) */ |
1268 | #endif | 1578 | } |
1269 | pm_runtime_put_sync(&mdp->pdev->dev); | 1579 | pm_runtime_put_sync(&mdp->pdev->dev); |
1270 | 1580 | ||
1271 | return &mdp->stats; | 1581 | return &mdp->stats; |
@@ -1291,48 +1601,46 @@ static int sh_eth_do_ioctl(struct net_device *ndev, struct ifreq *rq, | |||
1291 | /* Multicast reception directions set */ | 1601 | /* Multicast reception directions set */ |
1292 | static void sh_eth_set_multicast_list(struct net_device *ndev) | 1602 | static void sh_eth_set_multicast_list(struct net_device *ndev) |
1293 | { | 1603 | { |
1294 | u32 ioaddr = ndev->base_addr; | ||
1295 | |||
1296 | if (ndev->flags & IFF_PROMISC) { | 1604 | if (ndev->flags & IFF_PROMISC) { |
1297 | /* Set promiscuous. */ | 1605 | /* Set promiscuous. */ |
1298 | ctrl_outl((ctrl_inl(ioaddr + ECMR) & ~ECMR_MCT) | ECMR_PRM, | 1606 | sh_eth_write(ndev, (sh_eth_read(ndev, ECMR) & ~ECMR_MCT) | |
1299 | ioaddr + ECMR); | 1607 | ECMR_PRM, ECMR); |
1300 | } else { | 1608 | } else { |
1301 | /* Normal, unicast/broadcast-only mode. */ | 1609 | /* Normal, unicast/broadcast-only mode. */ |
1302 | ctrl_outl((ctrl_inl(ioaddr + ECMR) & ~ECMR_PRM) | ECMR_MCT, | 1610 | sh_eth_write(ndev, (sh_eth_read(ndev, ECMR) & ~ECMR_PRM) | |
1303 | ioaddr + ECMR); | 1611 | ECMR_MCT, ECMR); |
1304 | } | 1612 | } |
1305 | } | 1613 | } |
1614 | #endif /* SH_ETH_HAS_TSU */ | ||
1306 | 1615 | ||
1307 | /* SuperH's TSU register init function */ | 1616 | /* SuperH's TSU register init function */ |
1308 | static void sh_eth_tsu_init(u32 ioaddr) | 1617 | static void sh_eth_tsu_init(struct sh_eth_private *mdp) |
1309 | { | 1618 | { |
1310 | ctrl_outl(0, ioaddr + TSU_FWEN0); /* Disable forward(0->1) */ | 1619 | sh_eth_tsu_write(mdp, 0, TSU_FWEN0); /* Disable forward(0->1) */ |
1311 | ctrl_outl(0, ioaddr + TSU_FWEN1); /* Disable forward(1->0) */ | 1620 | sh_eth_tsu_write(mdp, 0, TSU_FWEN1); /* Disable forward(1->0) */ |
1312 | ctrl_outl(0, ioaddr + TSU_FCM); /* forward fifo 3k-3k */ | 1621 | sh_eth_tsu_write(mdp, 0, TSU_FCM); /* forward fifo 3k-3k */ |
1313 | ctrl_outl(0xc, ioaddr + TSU_BSYSL0); | 1622 | sh_eth_tsu_write(mdp, 0xc, TSU_BSYSL0); |
1314 | ctrl_outl(0xc, ioaddr + TSU_BSYSL1); | 1623 | sh_eth_tsu_write(mdp, 0xc, TSU_BSYSL1); |
1315 | ctrl_outl(0, ioaddr + TSU_PRISL0); | 1624 | sh_eth_tsu_write(mdp, 0, TSU_PRISL0); |
1316 | ctrl_outl(0, ioaddr + TSU_PRISL1); | 1625 | sh_eth_tsu_write(mdp, 0, TSU_PRISL1); |
1317 | ctrl_outl(0, ioaddr + TSU_FWSL0); | 1626 | sh_eth_tsu_write(mdp, 0, TSU_FWSL0); |
1318 | ctrl_outl(0, ioaddr + TSU_FWSL1); | 1627 | sh_eth_tsu_write(mdp, 0, TSU_FWSL1); |
1319 | ctrl_outl(TSU_FWSLC_POSTENU | TSU_FWSLC_POSTENL, ioaddr + TSU_FWSLC); | 1628 | sh_eth_tsu_write(mdp, TSU_FWSLC_POSTENU | TSU_FWSLC_POSTENL, TSU_FWSLC); |
1320 | #if defined(CONFIG_CPU_SUBTYPE_SH7763) | 1629 | if (sh_eth_is_gether(mdp)) { |
1321 | ctrl_outl(0, ioaddr + TSU_QTAG0); /* Disable QTAG(0->1) */ | 1630 | sh_eth_tsu_write(mdp, 0, TSU_QTAG0); /* Disable QTAG(0->1) */ |
1322 | ctrl_outl(0, ioaddr + TSU_QTAG1); /* Disable QTAG(1->0) */ | 1631 | sh_eth_tsu_write(mdp, 0, TSU_QTAG1); /* Disable QTAG(1->0) */ |
1323 | #else | 1632 | } else { |
1324 | ctrl_outl(0, ioaddr + TSU_QTAGM0); /* Disable QTAG(0->1) */ | 1633 | sh_eth_tsu_write(mdp, 0, TSU_QTAGM0); /* Disable QTAG(0->1) */ |
1325 | ctrl_outl(0, ioaddr + TSU_QTAGM1); /* Disable QTAG(1->0) */ | 1634 | sh_eth_tsu_write(mdp, 0, TSU_QTAGM1); /* Disable QTAG(1->0) */ |
1326 | #endif | 1635 | } |
1327 | ctrl_outl(0, ioaddr + TSU_FWSR); /* all interrupt status clear */ | 1636 | sh_eth_tsu_write(mdp, 0, TSU_FWSR); /* all interrupt status clear */ |
1328 | ctrl_outl(0, ioaddr + TSU_FWINMK); /* Disable all interrupt */ | 1637 | sh_eth_tsu_write(mdp, 0, TSU_FWINMK); /* Disable all interrupt */ |
1329 | ctrl_outl(0, ioaddr + TSU_TEN); /* Disable all CAM entry */ | 1638 | sh_eth_tsu_write(mdp, 0, TSU_TEN); /* Disable all CAM entry */ |
1330 | ctrl_outl(0, ioaddr + TSU_POST1); /* Disable CAM entry [ 0- 7] */ | 1639 | sh_eth_tsu_write(mdp, 0, TSU_POST1); /* Disable CAM entry [ 0- 7] */ |
1331 | ctrl_outl(0, ioaddr + TSU_POST2); /* Disable CAM entry [ 8-15] */ | 1640 | sh_eth_tsu_write(mdp, 0, TSU_POST2); /* Disable CAM entry [ 8-15] */ |
1332 | ctrl_outl(0, ioaddr + TSU_POST3); /* Disable CAM entry [16-23] */ | 1641 | sh_eth_tsu_write(mdp, 0, TSU_POST3); /* Disable CAM entry [16-23] */ |
1333 | ctrl_outl(0, ioaddr + TSU_POST4); /* Disable CAM entry [24-31] */ | 1642 | sh_eth_tsu_write(mdp, 0, TSU_POST4); /* Disable CAM entry [24-31] */ |
1334 | } | 1643 | } |
1335 | #endif /* SH_ETH_HAS_TSU */ | ||
1336 | 1644 | ||
1337 | /* MDIO bus release function */ | 1645 | /* MDIO bus release function */ |
1338 | static int sh_mdio_release(struct net_device *ndev) | 1646 | static int sh_mdio_release(struct net_device *ndev) |
@@ -1355,7 +1663,8 @@ static int sh_mdio_release(struct net_device *ndev) | |||
1355 | } | 1663 | } |
1356 | 1664 | ||
1357 | /* MDIO bus init function */ | 1665 | /* MDIO bus init function */ |
1358 | static int sh_mdio_init(struct net_device *ndev, int id) | 1666 | static int sh_mdio_init(struct net_device *ndev, int id, |
1667 | struct sh_eth_plat_data *pd) | ||
1359 | { | 1668 | { |
1360 | int ret, i; | 1669 | int ret, i; |
1361 | struct bb_info *bitbang; | 1670 | struct bb_info *bitbang; |
@@ -1369,7 +1678,8 @@ static int sh_mdio_init(struct net_device *ndev, int id) | |||
1369 | } | 1678 | } |
1370 | 1679 | ||
1371 | /* bitbang init */ | 1680 | /* bitbang init */ |
1372 | bitbang->addr = ndev->base_addr + PIR; | 1681 | bitbang->addr = ndev->base_addr + mdp->reg_offset[PIR]; |
1682 | bitbang->set_gate = pd->set_mdio_gate; | ||
1373 | bitbang->mdi_msk = 0x08; | 1683 | bitbang->mdi_msk = 0x08; |
1374 | bitbang->mdo_msk = 0x04; | 1684 | bitbang->mdo_msk = 0x04; |
1375 | bitbang->mmd_msk = 0x02;/* MMD */ | 1685 | bitbang->mmd_msk = 0x02;/* MMD */ |
@@ -1420,6 +1730,28 @@ out: | |||
1420 | return ret; | 1730 | return ret; |
1421 | } | 1731 | } |
1422 | 1732 | ||
1733 | static const u16 *sh_eth_get_register_offset(int register_type) | ||
1734 | { | ||
1735 | const u16 *reg_offset = NULL; | ||
1736 | |||
1737 | switch (register_type) { | ||
1738 | case SH_ETH_REG_GIGABIT: | ||
1739 | reg_offset = sh_eth_offset_gigabit; | ||
1740 | break; | ||
1741 | case SH_ETH_REG_FAST_SH4: | ||
1742 | reg_offset = sh_eth_offset_fast_sh4; | ||
1743 | break; | ||
1744 | case SH_ETH_REG_FAST_SH3_SH2: | ||
1745 | reg_offset = sh_eth_offset_fast_sh3_sh2; | ||
1746 | break; | ||
1747 | default: | ||
1748 | printk(KERN_ERR "Unknown register type (%d)\n", register_type); | ||
1749 | break; | ||
1750 | } | ||
1751 | |||
1752 | return reg_offset; | ||
1753 | } | ||
1754 | |||
1423 | static const struct net_device_ops sh_eth_netdev_ops = { | 1755 | static const struct net_device_ops sh_eth_netdev_ops = { |
1424 | .ndo_open = sh_eth_open, | 1756 | .ndo_open = sh_eth_open, |
1425 | .ndo_stop = sh_eth_close, | 1757 | .ndo_stop = sh_eth_close, |
@@ -1486,19 +1818,28 @@ static int sh_eth_drv_probe(struct platform_device *pdev) | |||
1486 | pd = (struct sh_eth_plat_data *)(pdev->dev.platform_data); | 1818 | pd = (struct sh_eth_plat_data *)(pdev->dev.platform_data); |
1487 | /* get PHY ID */ | 1819 | /* get PHY ID */ |
1488 | mdp->phy_id = pd->phy; | 1820 | mdp->phy_id = pd->phy; |
1821 | mdp->phy_interface = pd->phy_interface; | ||
1489 | /* EDMAC endian */ | 1822 | /* EDMAC endian */ |
1490 | mdp->edmac_endian = pd->edmac_endian; | 1823 | mdp->edmac_endian = pd->edmac_endian; |
1491 | mdp->no_ether_link = pd->no_ether_link; | 1824 | mdp->no_ether_link = pd->no_ether_link; |
1492 | mdp->ether_link_active_low = pd->ether_link_active_low; | 1825 | mdp->ether_link_active_low = pd->ether_link_active_low; |
1826 | mdp->reg_offset = sh_eth_get_register_offset(pd->register_type); | ||
1493 | 1827 | ||
1494 | /* set cpu data */ | 1828 | /* set cpu data */ |
1829 | #if defined(SH_ETH_HAS_BOTH_MODULES) | ||
1830 | mdp->cd = sh_eth_get_cpu_data(mdp); | ||
1831 | #else | ||
1495 | mdp->cd = &sh_eth_my_cpu_data; | 1832 | mdp->cd = &sh_eth_my_cpu_data; |
1833 | #endif | ||
1496 | sh_eth_set_default_cpu_data(mdp->cd); | 1834 | sh_eth_set_default_cpu_data(mdp->cd); |
1497 | 1835 | ||
1498 | /* set function */ | 1836 | /* set function */ |
1499 | ndev->netdev_ops = &sh_eth_netdev_ops; | 1837 | ndev->netdev_ops = &sh_eth_netdev_ops; |
1838 | SET_ETHTOOL_OPS(ndev, &sh_eth_ethtool_ops); | ||
1500 | ndev->watchdog_timeo = TX_TIMEOUT; | 1839 | ndev->watchdog_timeo = TX_TIMEOUT; |
1501 | 1840 | ||
1841 | /* debug message level */ | ||
1842 | mdp->msg_enable = SH_ETH_DEF_MSG_ENABLE; | ||
1502 | mdp->post_rx = POST_RX >> (devno << 1); | 1843 | mdp->post_rx = POST_RX >> (devno << 1); |
1503 | mdp->post_fw = POST_FW >> (devno << 1); | 1844 | mdp->post_fw = POST_FW >> (devno << 1); |
1504 | 1845 | ||
@@ -1507,13 +1848,23 @@ static int sh_eth_drv_probe(struct platform_device *pdev) | |||
1507 | 1848 | ||
1508 | /* First device only init */ | 1849 | /* First device only init */ |
1509 | if (!devno) { | 1850 | if (!devno) { |
1851 | if (mdp->cd->tsu) { | ||
1852 | struct resource *rtsu; | ||
1853 | rtsu = platform_get_resource(pdev, IORESOURCE_MEM, 1); | ||
1854 | if (!rtsu) { | ||
1855 | dev_err(&pdev->dev, "Not found TSU resource\n"); | ||
1856 | goto out_release; | ||
1857 | } | ||
1858 | mdp->tsu_addr = ioremap(rtsu->start, | ||
1859 | resource_size(rtsu)); | ||
1860 | } | ||
1510 | if (mdp->cd->chip_reset) | 1861 | if (mdp->cd->chip_reset) |
1511 | mdp->cd->chip_reset(ndev); | 1862 | mdp->cd->chip_reset(ndev); |
1512 | 1863 | ||
1513 | #if defined(SH_ETH_HAS_TSU) | 1864 | if (mdp->cd->tsu) { |
1514 | /* TSU init (Init only)*/ | 1865 | /* TSU init (Init only)*/ |
1515 | sh_eth_tsu_init(SH_TSU_ADDR); | 1866 | sh_eth_tsu_init(mdp); |
1516 | #endif | 1867 | } |
1517 | } | 1868 | } |
1518 | 1869 | ||
1519 | /* network device register */ | 1870 | /* network device register */ |
@@ -1522,11 +1873,11 @@ static int sh_eth_drv_probe(struct platform_device *pdev) | |||
1522 | goto out_release; | 1873 | goto out_release; |
1523 | 1874 | ||
1524 | /* mdio bus init */ | 1875 | /* mdio bus init */ |
1525 | ret = sh_mdio_init(ndev, pdev->id); | 1876 | ret = sh_mdio_init(ndev, pdev->id, pd); |
1526 | if (ret) | 1877 | if (ret) |
1527 | goto out_unregister; | 1878 | goto out_unregister; |
1528 | 1879 | ||
1529 | /* print device infomation */ | 1880 | /* print device information */ |
1530 | pr_info("Base address at 0x%x, %pM, IRQ %d.\n", | 1881 | pr_info("Base address at 0x%x, %pM, IRQ %d.\n", |
1531 | (u32)ndev->base_addr, ndev->dev_addr, ndev->irq); | 1882 | (u32)ndev->base_addr, ndev->dev_addr, ndev->irq); |
1532 | 1883 | ||
@@ -1539,6 +1890,8 @@ out_unregister: | |||
1539 | 1890 | ||
1540 | out_release: | 1891 | out_release: |
1541 | /* net_dev free */ | 1892 | /* net_dev free */ |
1893 | if (mdp->tsu_addr) | ||
1894 | iounmap(mdp->tsu_addr); | ||
1542 | if (ndev) | 1895 | if (ndev) |
1543 | free_netdev(ndev); | 1896 | free_netdev(ndev); |
1544 | 1897 | ||
@@ -1549,10 +1902,11 @@ out: | |||
1549 | static int sh_eth_drv_remove(struct platform_device *pdev) | 1902 | static int sh_eth_drv_remove(struct platform_device *pdev) |
1550 | { | 1903 | { |
1551 | struct net_device *ndev = platform_get_drvdata(pdev); | 1904 | struct net_device *ndev = platform_get_drvdata(pdev); |
1905 | struct sh_eth_private *mdp = netdev_priv(ndev); | ||
1552 | 1906 | ||
1907 | iounmap(mdp->tsu_addr); | ||
1553 | sh_mdio_release(ndev); | 1908 | sh_mdio_release(ndev); |
1554 | unregister_netdev(ndev); | 1909 | unregister_netdev(ndev); |
1555 | flush_scheduled_work(); | ||
1556 | pm_runtime_disable(&pdev->dev); | 1910 | pm_runtime_disable(&pdev->dev); |
1557 | free_netdev(ndev); | 1911 | free_netdev(ndev); |
1558 | platform_set_drvdata(pdev, NULL); | 1912 | platform_set_drvdata(pdev, NULL); |