Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[PATCH] New PowerPC 4xx on-chip ethernet controller driver

This patch replaces current PowerPC 4xx EMAC driver with
new, re-written from the scratch version. This patch is quite big
(~234K) because there is virtualy 0% of common code between old and
new version.

New driver uses NAPI, it solves stability problems under heavy packet
load and low memory, corrects chip register access and fixes numerous
small bugs I don't even remember now.

This patch has been tested on all supported in 2.6 PPC 4xx boards.
It's been used in production for almost a year now on custom
4xx hardware. PPC32 specific parts are already upstream.

Patch was acked by the current EMAC driver maintainer (Matt Porter). I
will be maintaining this new version.

Signed-off-by: Eugene Surovegin <ebs@ebshome.net>
--

Kconfig | 72
ibm_emac/Makefile | 13
ibm_emac/ibm_emac.h | 418 +++--
ibm_emac/ibm_emac_core.c | 3414 ++++++++++++++++++++++++----------------------
ibm_emac/ibm_emac_core.h | 313 ++--
ibm_emac/ibm_emac_debug.c | 377 ++---
ibm_emac/ibm_emac_debug.h | 63
ibm_emac/ibm_emac_mal.c | 674 +++++----
ibm_emac/ibm_emac_mal.h | 336 +++-
ibm_emac/ibm_emac_phy.c | 335 ++--
ibm_emac/ibm_emac_phy.h | 105 -
ibm_emac/ibm_emac_rgmii.c | 201 ++
ibm_emac/ibm_emac_rgmii.h | 68
ibm_emac/ibm_emac_tah.c | 111 +
ibm_emac/ibm_emac_tah.h | 96 -
ibm_emac/ibm_emac_zmii.c | 255 +++
ibm_emac/ibm_emac_zmii.h | 114 -
17 files changed, 4114 insertions(+), 2851 deletions(-)
Signed-off-by: Jeff Garzik <jgarzik@pobox.com>

authored by

Eugene Surovegin and committed by
Jeff Garzik
37448f7d b71b95ef

+4381 -3118
+54 -18
drivers/net/Kconfig
··· 1163 1163 be called ibmveth. 1164 1164 1165 1165 config IBM_EMAC 1166 - bool "IBM PPC4xx EMAC driver support" 1166 + tristate "PowerPC 4xx on-chip Ethernet support" 1167 1167 depends on 4xx 1168 - select CRC32 1169 - ---help--- 1170 - This driver supports the IBM PPC4xx EMAC family of on-chip 1171 - Ethernet controllers. 1172 - 1173 - config IBM_EMAC_ERRMSG 1174 - bool "Verbose error messages" 1175 - depends on IBM_EMAC && BROKEN 1168 + help 1169 + This driver supports the PowerPC 4xx EMAC family of on-chip 1170 + Ethernet controllers. 1176 1171 1177 1172 config IBM_EMAC_RXB 1178 1173 int "Number of receive buffers" 1179 1174 depends on IBM_EMAC 1180 - default "128" if IBM_EMAC4 1181 - default "64" 1175 + default "128" 1182 1176 1183 1177 config IBM_EMAC_TXB 1184 1178 int "Number of transmit buffers" 1185 1179 depends on IBM_EMAC 1186 - default "128" if IBM_EMAC4 1187 - default "8" 1180 + default "64" 1188 1181 1189 - config IBM_EMAC_FGAP 1190 - int "Frame gap" 1182 + config IBM_EMAC_POLL_WEIGHT 1183 + int "MAL NAPI polling weight" 1191 1184 depends on IBM_EMAC 1192 - default "8" 1185 + default "32" 1193 1186 1194 - config IBM_EMAC_SKBRES 1195 - int "Skb reserve amount" 1187 + config IBM_EMAC_RX_COPY_THRESHOLD 1188 + int "RX skb copy threshold (bytes)" 1189 + depends on IBM_EMAC 1190 + default "256" 1191 + 1192 + config IBM_EMAC_RX_SKB_HEADROOM 1193 + int "Additional RX skb headroom (bytes)" 1196 1194 depends on IBM_EMAC 1197 1195 default "0" 1196 + help 1197 + Additional receive skb headroom. Note, that driver 1198 + will always reserve at least 2 bytes to make IP header 1199 + aligned, so usualy there is no need to add any additional 1200 + headroom. 1201 + 1202 + If unsure, set to 0. 1203 + 1204 + config IBM_EMAC_PHY_RX_CLK_FIX 1205 + bool "PHY Rx clock workaround" 1206 + depends on IBM_EMAC && (405EP || 440GX || 440EP) 1207 + help 1208 + Enable this if EMAC attached to a PHY which doesn't generate 1209 + RX clock if there is no link, if this is the case, you will 1210 + see "TX disable timeout" or "RX disable timeout" in the system 1211 + log. 1212 + 1213 + If unsure, say N. 1214 + 1215 + config IBM_EMAC_DEBUG 1216 + bool "Debugging" 1217 + depends on IBM_EMAC 1218 + default n 1219 + 1220 + config IBM_EMAC_ZMII 1221 + bool 1222 + depends on IBM_EMAC && (NP405H || NP405L || 44x) 1223 + default y 1224 + 1225 + config IBM_EMAC_RGMII 1226 + bool 1227 + depends on IBM_EMAC && 440GX 1228 + default y 1229 + 1230 + config IBM_EMAC_TAH 1231 + bool 1232 + depends on IBM_EMAC && 440GX 1233 + default y 1198 1234 1199 1235 config NET_PCI 1200 1236 bool "EISA, VLB, PCI and on board controllers"
+6 -7
drivers/net/ibm_emac/Makefile
··· 1 1 # 2 - # Makefile for the IBM PPC4xx EMAC controllers 2 + # Makefile for the PowerPC 4xx on-chip ethernet driver 3 3 # 4 4 5 5 obj-$(CONFIG_IBM_EMAC) += ibm_emac.o 6 6 7 - ibm_emac-objs := ibm_emac_mal.o ibm_emac_core.o ibm_emac_phy.o 8 - 9 - # Only need this if you want to see additional debug messages 10 - ifeq ($(CONFIG_IBM_EMAC_ERRMSG), y) 11 - ibm_emac-objs += ibm_emac_debug.o 12 - endif 7 + ibm_emac-objs := ibm_emac_mal.o ibm_emac_core.o ibm_emac_phy.o 8 + ibm_emac-$(CONFIG_IBM_EMAC_ZMII) += ibm_emac_zmii.o 9 + ibm_emac-$(CONFIG_IBM_EMAC_RGMII) += ibm_emac_rgmii.o 10 + ibm_emac-$(CONFIG_IBM_EMAC_TAH) += ibm_emac_tah.o 11 + ibm_emac-$(CONFIG_IBM_EMAC_DEBUG) += ibm_emac_debug.o
+225 -183
drivers/net/ibm_emac/ibm_emac.h
··· 1 1 /* 2 - * ibm_emac.h 2 + * drivers/net/ibm_emac/ibm_emac.h 3 3 * 4 + * Register definitions for PowerPC 4xx on-chip ethernet contoller 4 5 * 5 - * Armin Kuster akuster@mvista.com 6 - * June, 2002 6 + * Copyright (c) 2004, 2005 Zultys Technologies. 7 + * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net> 7 8 * 8 - * Copyright 2002 MontaVista Softare Inc. 9 + * Based on original work by 10 + * Matt Porter <mporter@kernel.crashing.org> 11 + * Armin Kuster <akuster@mvista.com> 12 + * Copyright 2002-2004 MontaVista Software Inc. 9 13 * 10 14 * This program is free software; you can redistribute it and/or modify it 11 15 * under the terms of the GNU General Public License as published by the 12 16 * Free Software Foundation; either version 2 of the License, or (at your 13 17 * option) any later version. 18 + * 14 19 */ 20 + #ifndef __IBM_EMAC_H_ 21 + #define __IBM_EMAC_H_ 15 22 16 - #ifndef _IBM_EMAC_H_ 17 - #define _IBM_EMAC_H_ 18 - /* General defines needed for the driver */ 23 + #include <linux/config.h> 24 + #include <linux/types.h> 19 25 20 - /* Emac */ 21 - typedef struct emac_regs { 22 - u32 em0mr0; 23 - u32 em0mr1; 24 - u32 em0tmr0; 25 - u32 em0tmr1; 26 - u32 em0rmr; 27 - u32 em0isr; 28 - u32 em0iser; 29 - u32 em0iahr; 30 - u32 em0ialr; 31 - u32 em0vtpid; 32 - u32 em0vtci; 33 - u32 em0ptr; 34 - u32 em0iaht1; 35 - u32 em0iaht2; 36 - u32 em0iaht3; 37 - u32 em0iaht4; 38 - u32 em0gaht1; 39 - u32 em0gaht2; 40 - u32 em0gaht3; 41 - u32 em0gaht4; 42 - u32 em0lsah; 43 - u32 em0lsal; 44 - u32 em0ipgvr; 45 - u32 em0stacr; 46 - u32 em0trtr; 47 - u32 em0rwmr; 48 - } emac_t; 26 + /* This is a simple check to prevent use of this driver on non-tested SoCs */ 27 + #if !defined(CONFIG_405GP) && !defined(CONFIG_405GPR) && !defined(CONFIG_405EP) && \ 28 + !defined(CONFIG_440GP) && !defined(CONFIG_440GX) && !defined(CONFIG_440SP) && \ 29 + !defined(CONFIG_440EP) && !defined(CONFIG_NP405H) 30 + #error "Unknown SoC. Please, check chip user manual and make sure EMAC defines are OK" 31 + #endif 49 32 50 - /* MODE REG 0 */ 51 - #define EMAC_M0_RXI 0x80000000 52 - #define EMAC_M0_TXI 0x40000000 53 - #define EMAC_M0_SRST 0x20000000 54 - #define EMAC_M0_TXE 0x10000000 55 - #define EMAC_M0_RXE 0x08000000 56 - #define EMAC_M0_WKE 0x04000000 33 + /* EMAC registers Write Access rules */ 34 + struct emac_regs { 35 + u32 mr0; /* special */ 36 + u32 mr1; /* Reset */ 37 + u32 tmr0; /* special */ 38 + u32 tmr1; /* special */ 39 + u32 rmr; /* Reset */ 40 + u32 isr; /* Always */ 41 + u32 iser; /* Reset */ 42 + u32 iahr; /* Reset, R, T */ 43 + u32 ialr; /* Reset, R, T */ 44 + u32 vtpid; /* Reset, R, T */ 45 + u32 vtci; /* Reset, R, T */ 46 + u32 ptr; /* Reset, T */ 47 + u32 iaht1; /* Reset, R */ 48 + u32 iaht2; /* Reset, R */ 49 + u32 iaht3; /* Reset, R */ 50 + u32 iaht4; /* Reset, R */ 51 + u32 gaht1; /* Reset, R */ 52 + u32 gaht2; /* Reset, R */ 53 + u32 gaht3; /* Reset, R */ 54 + u32 gaht4; /* Reset, R */ 55 + u32 lsah; 56 + u32 lsal; 57 + u32 ipgvr; /* Reset, T */ 58 + u32 stacr; /* special */ 59 + u32 trtr; /* special */ 60 + u32 rwmr; /* Reset */ 61 + u32 octx; 62 + u32 ocrx; 63 + u32 ipcr; 64 + }; 57 65 58 - /* MODE Reg 1 */ 59 - #define EMAC_M1_FDE 0x80000000 60 - #define EMAC_M1_ILE 0x40000000 61 - #define EMAC_M1_VLE 0x20000000 62 - #define EMAC_M1_EIFC 0x10000000 63 - #define EMAC_M1_APP 0x08000000 64 - #define EMAC_M1_AEMI 0x02000000 65 - #define EMAC_M1_IST 0x01000000 66 - #define EMAC_M1_MF_1000GPCS 0x00c00000 /* Internal GPCS */ 67 - #define EMAC_M1_MF_1000MBPS 0x00800000 /* External GPCS */ 68 - #define EMAC_M1_MF_100MBPS 0x00400000 69 - #define EMAC_M1_RFS_16K 0x00280000 /* 000 for 512 byte */ 70 - #define EMAC_M1_TR 0x00008000 71 - #ifdef CONFIG_IBM_EMAC4 72 - #define EMAC_M1_RFS_8K 0x00200000 73 - #define EMAC_M1_RFS_4K 0x00180000 74 - #define EMAC_M1_RFS_2K 0x00100000 75 - #define EMAC_M1_RFS_1K 0x00080000 76 - #define EMAC_M1_TX_FIFO_16K 0x00050000 /* 0's for 512 byte */ 77 - #define EMAC_M1_TX_FIFO_8K 0x00040000 78 - #define EMAC_M1_TX_FIFO_4K 0x00030000 79 - #define EMAC_M1_TX_FIFO_2K 0x00020000 80 - #define EMAC_M1_TX_FIFO_1K 0x00010000 81 - #define EMAC_M1_TX_TR 0x00008000 82 - #define EMAC_M1_TX_MWSW 0x00001000 /* 0 wait for status */ 83 - #define EMAC_M1_JUMBO_ENABLE 0x00000800 /* Upt to 9Kr status */ 84 - #define EMAC_M1_OPB_CLK_66 0x00000008 /* 66Mhz */ 85 - #define EMAC_M1_OPB_CLK_83 0x00000010 /* 83Mhz */ 86 - #define EMAC_M1_OPB_CLK_100 0x00000018 /* 100Mhz */ 87 - #define EMAC_M1_OPB_CLK_100P 0x00000020 /* 100Mhz+ */ 88 - #else /* CONFIG_IBM_EMAC4 */ 89 - #define EMAC_M1_RFS_4K 0x00300000 /* ~4k for 512 byte */ 90 - #define EMAC_M1_RFS_2K 0x00200000 91 - #define EMAC_M1_RFS_1K 0x00100000 92 - #define EMAC_M1_TX_FIFO_2K 0x00080000 /* 0's for 512 byte */ 93 - #define EMAC_M1_TX_FIFO_1K 0x00040000 94 - #define EMAC_M1_TR0_DEPEND 0x00010000 /* 0'x for single packet */ 95 - #define EMAC_M1_TR1_DEPEND 0x00004000 96 - #define EMAC_M1_TR1_MULTI 0x00002000 97 - #define EMAC_M1_JUMBO_ENABLE 0x00001000 98 - #endif /* CONFIG_IBM_EMAC4 */ 99 - #define EMAC_M1_BASE (EMAC_M1_TX_FIFO_2K | \ 100 - EMAC_M1_APP | \ 101 - EMAC_M1_TR | EMAC_M1_VLE) 66 + #if !defined(CONFIG_IBM_EMAC4) 67 + #define EMAC_ETHTOOL_REGS_VER 0 68 + #define EMAC_ETHTOOL_REGS_SIZE (sizeof(struct emac_regs) - sizeof(u32)) 69 + #else 70 + #define EMAC_ETHTOOL_REGS_VER 1 71 + #define EMAC_ETHTOOL_REGS_SIZE sizeof(struct emac_regs) 72 + #endif 102 73 103 - /* Transmit Mode Register 0 */ 104 - #define EMAC_TMR0_GNP0 0x80000000 105 - #define EMAC_TMR0_GNP1 0x40000000 106 - #define EMAC_TMR0_GNPD 0x20000000 107 - #define EMAC_TMR0_FC 0x10000000 74 + /* EMACx_MR0 */ 75 + #define EMAC_MR0_RXI 0x80000000 76 + #define EMAC_MR0_TXI 0x40000000 77 + #define EMAC_MR0_SRST 0x20000000 78 + #define EMAC_MR0_TXE 0x10000000 79 + #define EMAC_MR0_RXE 0x08000000 80 + #define EMAC_MR0_WKE 0x04000000 81 + 82 + /* EMACx_MR1 */ 83 + #define EMAC_MR1_FDE 0x80000000 84 + #define EMAC_MR1_ILE 0x40000000 85 + #define EMAC_MR1_VLE 0x20000000 86 + #define EMAC_MR1_EIFC 0x10000000 87 + #define EMAC_MR1_APP 0x08000000 88 + #define EMAC_MR1_IST 0x01000000 89 + 90 + #define EMAC_MR1_MF_MASK 0x00c00000 91 + #define EMAC_MR1_MF_10 0x00000000 92 + #define EMAC_MR1_MF_100 0x00400000 93 + #if !defined(CONFIG_IBM_EMAC4) 94 + #define EMAC_MR1_MF_1000 0x00000000 95 + #define EMAC_MR1_MF_1000GPCS 0x00000000 96 + #define EMAC_MR1_MF_IPPA(id) 0x00000000 97 + #else 98 + #define EMAC_MR1_MF_1000 0x00800000 99 + #define EMAC_MR1_MF_1000GPCS 0x00c00000 100 + #define EMAC_MR1_MF_IPPA(id) (((id) & 0x1f) << 6) 101 + #endif 102 + 103 + #define EMAC_TX_FIFO_SIZE 2048 104 + 105 + #if !defined(CONFIG_IBM_EMAC4) 106 + #define EMAC_MR1_RFS_4K 0x00300000 107 + #define EMAC_MR1_RFS_16K 0x00000000 108 + #define EMAC_RX_FIFO_SIZE(gige) 4096 109 + #define EMAC_MR1_TFS_2K 0x00080000 110 + #define EMAC_MR1_TR0_MULT 0x00008000 111 + #define EMAC_MR1_JPSM 0x00000000 112 + #define EMAC_MR1_BASE(opb) (EMAC_MR1_TFS_2K | EMAC_MR1_TR0_MULT) 113 + #else 114 + #define EMAC_MR1_RFS_4K 0x00180000 115 + #define EMAC_MR1_RFS_16K 0x00280000 116 + #define EMAC_RX_FIFO_SIZE(gige) ((gige) ? 16384 : 4096) 117 + #define EMAC_MR1_TFS_2K 0x00020000 118 + #define EMAC_MR1_TR 0x00008000 119 + #define EMAC_MR1_MWSW_001 0x00001000 120 + #define EMAC_MR1_JPSM 0x00000800 121 + #define EMAC_MR1_OBCI_MASK 0x00000038 122 + #define EMAC_MR1_OBCI_50 0x00000000 123 + #define EMAC_MR1_OBCI_66 0x00000008 124 + #define EMAC_MR1_OBCI_83 0x00000010 125 + #define EMAC_MR1_OBCI_100 0x00000018 126 + #define EMAC_MR1_OBCI_100P 0x00000020 127 + #define EMAC_MR1_OBCI(freq) ((freq) <= 50 ? EMAC_MR1_OBCI_50 : \ 128 + (freq) <= 66 ? EMAC_MR1_OBCI_66 : \ 129 + (freq) <= 83 ? EMAC_MR1_OBCI_83 : \ 130 + (freq) <= 100 ? EMAC_MR1_OBCI_100 : EMAC_MR1_OBCI_100P) 131 + #define EMAC_MR1_BASE(opb) (EMAC_MR1_TFS_2K | EMAC_MR1_TR | \ 132 + EMAC_MR1_MWSW_001 | EMAC_MR1_OBCI(opb)) 133 + #endif 134 + 135 + /* EMACx_TMR0 */ 136 + #define EMAC_TMR0_GNP 0x80000000 137 + #if !defined(CONFIG_IBM_EMAC4) 138 + #define EMAC_TMR0_DEFAULT 0x00000000 139 + #else 108 140 #define EMAC_TMR0_TFAE_2_32 0x00000001 109 141 #define EMAC_TMR0_TFAE_4_64 0x00000002 110 142 #define EMAC_TMR0_TFAE_8_128 0x00000003 ··· 144 112 #define EMAC_TMR0_TFAE_32_512 0x00000005 145 113 #define EMAC_TMR0_TFAE_64_1024 0x00000006 146 114 #define EMAC_TMR0_TFAE_128_2048 0x00000007 115 + #define EMAC_TMR0_DEFAULT EMAC_TMR0_TFAE_2_32 116 + #endif 117 + #define EMAC_TMR0_XMIT (EMAC_TMR0_GNP | EMAC_TMR0_DEFAULT) 147 118 148 - /* Receive Mode Register */ 119 + /* EMACx_TMR1 */ 120 + 121 + /* IBM manuals are not very clear here. 122 + * This is my interpretation of how things are. --ebs 123 + */ 124 + #if defined(CONFIG_40x) 125 + #define EMAC_FIFO_ENTRY_SIZE 8 126 + #define EMAC_MAL_BURST_SIZE (16 * 4) 127 + #else 128 + #define EMAC_FIFO_ENTRY_SIZE 16 129 + #define EMAC_MAL_BURST_SIZE (64 * 4) 130 + #endif 131 + 132 + #if !defined(CONFIG_IBM_EMAC4) 133 + #define EMAC_TMR1(l,h) (((l) << 27) | (((h) & 0xff) << 16)) 134 + #else 135 + #define EMAC_TMR1(l,h) (((l) << 27) | (((h) & 0x3ff) << 14)) 136 + #endif 137 + 138 + /* EMACx_RMR */ 149 139 #define EMAC_RMR_SP 0x80000000 150 140 #define EMAC_RMR_SFCS 0x40000000 151 - #define EMAC_RMR_ARRP 0x20000000 152 - #define EMAC_RMR_ARP 0x10000000 153 - #define EMAC_RMR_AROP 0x08000000 154 - #define EMAC_RMR_ARPI 0x04000000 141 + #define EMAC_RMR_RRP 0x20000000 142 + #define EMAC_RMR_RFP 0x10000000 143 + #define EMAC_RMR_ROP 0x08000000 144 + #define EMAC_RMR_RPIR 0x04000000 155 145 #define EMAC_RMR_PPP 0x02000000 156 146 #define EMAC_RMR_PME 0x01000000 157 147 #define EMAC_RMR_PMME 0x00800000 ··· 181 127 #define EMAC_RMR_MIAE 0x00200000 182 128 #define EMAC_RMR_BAE 0x00100000 183 129 #define EMAC_RMR_MAE 0x00080000 130 + #if !defined(CONFIG_IBM_EMAC4) 131 + #define EMAC_RMR_BASE 0x00000000 132 + #else 184 133 #define EMAC_RMR_RFAF_2_32 0x00000001 185 134 #define EMAC_RMR_RFAF_4_64 0x00000002 186 135 #define EMAC_RMR_RFAF_8_128 0x00000003 ··· 191 134 #define EMAC_RMR_RFAF_32_512 0x00000005 192 135 #define EMAC_RMR_RFAF_64_1024 0x00000006 193 136 #define EMAC_RMR_RFAF_128_2048 0x00000007 194 - #define EMAC_RMR_BASE (EMAC_RMR_IAE | EMAC_RMR_BAE) 137 + #define EMAC_RMR_BASE EMAC_RMR_RFAF_128_2048 138 + #endif 195 139 196 - /* Interrupt Status & enable Regs */ 140 + /* EMACx_ISR & EMACx_ISER */ 141 + #if !defined(CONFIG_IBM_EMAC4) 142 + #define EMAC_ISR_TXPE 0x00000000 143 + #define EMAC_ISR_RXPE 0x00000000 144 + #define EMAC_ISR_TXUE 0x00000000 145 + #define EMAC_ISR_RXOE 0x00000000 146 + #else 147 + #define EMAC_ISR_TXPE 0x20000000 148 + #define EMAC_ISR_RXPE 0x10000000 149 + #define EMAC_ISR_TXUE 0x08000000 150 + #define EMAC_ISR_RXOE 0x04000000 151 + #endif 197 152 #define EMAC_ISR_OVR 0x02000000 198 153 #define EMAC_ISR_PP 0x01000000 199 154 #define EMAC_ISR_BP 0x00800000 ··· 216 147 #define EMAC_ISR_PTLE 0x00040000 217 148 #define EMAC_ISR_ORE 0x00020000 218 149 #define EMAC_ISR_IRE 0x00010000 219 - #define EMAC_ISR_DBDM 0x00000200 220 - #define EMAC_ISR_DB0 0x00000100 221 - #define EMAC_ISR_SE0 0x00000080 222 - #define EMAC_ISR_TE0 0x00000040 223 - #define EMAC_ISR_DB1 0x00000020 224 - #define EMAC_ISR_SE1 0x00000010 225 - #define EMAC_ISR_TE1 0x00000008 150 + #define EMAC_ISR_SQE 0x00000080 151 + #define EMAC_ISR_TE 0x00000040 226 152 #define EMAC_ISR_MOS 0x00000002 227 153 #define EMAC_ISR_MOF 0x00000001 228 154 229 - /* STA CONTROL REG */ 155 + /* EMACx_STACR */ 156 + #define EMAC_STACR_PHYD_MASK 0xffff 157 + #define EMAC_STACR_PHYD_SHIFT 16 230 158 #define EMAC_STACR_OC 0x00008000 231 159 #define EMAC_STACR_PHYE 0x00004000 232 - #define EMAC_STACR_WRITE 0x00002000 233 - #define EMAC_STACR_READ 0x00001000 234 - #define EMAC_STACR_CLK_83MHZ 0x00000800 /* 0's for 50Mhz */ 235 - #define EMAC_STACR_CLK_66MHZ 0x00000400 236 - #define EMAC_STACR_CLK_100MHZ 0x00000C00 160 + #define EMAC_STACR_STAC_MASK 0x00003000 161 + #define EMAC_STACR_STAC_READ 0x00001000 162 + #define EMAC_STACR_STAC_WRITE 0x00002000 163 + #if !defined(CONFIG_IBM_EMAC4) 164 + #define EMAC_STACR_OPBC_MASK 0x00000C00 165 + #define EMAC_STACR_OPBC_50 0x00000000 166 + #define EMAC_STACR_OPBC_66 0x00000400 167 + #define EMAC_STACR_OPBC_83 0x00000800 168 + #define EMAC_STACR_OPBC_100 0x00000C00 169 + #define EMAC_STACR_OPBC(freq) ((freq) <= 50 ? EMAC_STACR_OPBC_50 : \ 170 + (freq) <= 66 ? EMAC_STACR_OPBC_66 : \ 171 + (freq) <= 83 ? EMAC_STACR_OPBC_83 : EMAC_STACR_OPBC_100) 172 + #define EMAC_STACR_BASE(opb) EMAC_STACR_OPBC(opb) 173 + #else 174 + #define EMAC_STACR_BASE(opb) 0x00000000 175 + #endif 176 + #define EMAC_STACR_PCDA_MASK 0x1f 177 + #define EMAC_STACR_PCDA_SHIFT 5 178 + #define EMAC_STACR_PRA_MASK 0x1f 237 179 238 - /* Transmit Request Threshold Register */ 239 - #define EMAC_TRTR_1600 0x18000000 /* 0's for 64 Bytes */ 240 - #define EMAC_TRTR_1024 0x0f000000 241 - #define EMAC_TRTR_512 0x07000000 242 - #define EMAC_TRTR_256 0x03000000 243 - #define EMAC_TRTR_192 0x10000000 244 - #define EMAC_TRTR_128 0x01000000 180 + /* EMACx_TRTR */ 181 + #if !defined(CONFIG_IBM_EMAC4) 182 + #define EMAC_TRTR_SHIFT 27 183 + #else 184 + #define EMAC_TRTR_SHIFT 24 185 + #endif 186 + #define EMAC_TRTR(size) ((((size) >> 6) - 1) << EMAC_TRTR_SHIFT) 245 187 188 + /* EMACx_RWMR */ 189 + #if !defined(CONFIG_IBM_EMAC4) 190 + #define EMAC_RWMR(l,h) (((l) << 23) | ( ((h) & 0x1ff) << 7)) 191 + #else 192 + #define EMAC_RWMR(l,h) (((l) << 22) | ( ((h) & 0x3ff) << 6)) 193 + #endif 194 + 195 + /* EMAC specific TX descriptor control fields (write access) */ 246 196 #define EMAC_TX_CTRL_GFCS 0x0200 247 197 #define EMAC_TX_CTRL_GP 0x0100 248 198 #define EMAC_TX_CTRL_ISA 0x0080 249 199 #define EMAC_TX_CTRL_RSA 0x0040 250 200 #define EMAC_TX_CTRL_IVT 0x0020 251 201 #define EMAC_TX_CTRL_RVT 0x0010 252 - #define EMAC_TX_CTRL_TAH_CSUM 0x000e /* TAH only */ 253 - #define EMAC_TX_CTRL_TAH_SEG4 0x000a /* TAH only */ 254 - #define EMAC_TX_CTRL_TAH_SEG3 0x0008 /* TAH only */ 255 - #define EMAC_TX_CTRL_TAH_SEG2 0x0006 /* TAH only */ 256 - #define EMAC_TX_CTRL_TAH_SEG1 0x0004 /* TAH only */ 257 - #define EMAC_TX_CTRL_TAH_SEG0 0x0002 /* TAH only */ 258 - #define EMAC_TX_CTRL_TAH_DIS 0x0000 /* TAH only */ 202 + #define EMAC_TX_CTRL_TAH_CSUM 0x000e 259 203 260 - #define EMAC_TX_CTRL_DFLT ( \ 261 - MAL_TX_CTRL_INTR | EMAC_TX_CTRL_GFCS | EMAC_TX_CTRL_GP ) 262 - 263 - /* madmal transmit status / Control bits */ 204 + /* EMAC specific TX descriptor status fields (read access) */ 264 205 #define EMAC_TX_ST_BFCS 0x0200 265 - #define EMAC_TX_ST_BPP 0x0100 266 206 #define EMAC_TX_ST_LCS 0x0080 267 207 #define EMAC_TX_ST_ED 0x0040 268 208 #define EMAC_TX_ST_EC 0x0020 ··· 280 202 #define EMAC_TX_ST_SC 0x0004 281 203 #define EMAC_TX_ST_UR 0x0002 282 204 #define EMAC_TX_ST_SQE 0x0001 205 + #if !defined(CONFIG_IBM_EMAC_TAH) 206 + #define EMAC_IS_BAD_TX(v) ((v) & (EMAC_TX_ST_LCS | EMAC_TX_ST_ED | \ 207 + EMAC_TX_ST_EC | EMAC_TX_ST_LC | \ 208 + EMAC_TX_ST_MC | EMAC_TX_ST_UR)) 209 + #else 210 + #define EMAC_IS_BAD_TX(v) ((v) & (EMAC_TX_ST_LCS | EMAC_TX_ST_ED | \ 211 + EMAC_TX_ST_EC | EMAC_TX_ST_LC)) 212 + #endif 283 213 284 - /* madmal receive status / Control bits */ 214 + /* EMAC specific RX descriptor status fields (read access) */ 285 215 #define EMAC_RX_ST_OE 0x0200 286 216 #define EMAC_RX_ST_PP 0x0100 287 217 #define EMAC_RX_ST_BP 0x0080 ··· 300 214 #define EMAC_RX_ST_PTL 0x0004 301 215 #define EMAC_RX_ST_ORE 0x0002 302 216 #define EMAC_RX_ST_IRE 0x0001 303 - #define EMAC_BAD_RX_PACKET 0x02ff 304 - #define EMAC_CSUM_VER_ERROR 0x0003 305 - 306 - /* identify a bad rx packet dependent on emac features */ 307 - #ifdef CONFIG_IBM_EMAC4 308 - #define EMAC_IS_BAD_RX_PACKET(desc) \ 309 - (((desc & (EMAC_BAD_RX_PACKET & ~EMAC_CSUM_VER_ERROR)) || \ 310 - ((desc & EMAC_CSUM_VER_ERROR) == EMAC_RX_ST_ORE) || \ 311 - ((desc & EMAC_CSUM_VER_ERROR) == EMAC_RX_ST_IRE))) 312 - #else 313 - #define EMAC_IS_BAD_RX_PACKET(desc) \ 314 - (desc & EMAC_BAD_RX_PACKET) 315 - #endif 316 - 317 - /* SoC implementation specific EMAC register defaults */ 318 - #if defined(CONFIG_440GP) 319 - #define EMAC_RWMR_DEFAULT 0x80009000 320 - #define EMAC_TMR0_DEFAULT 0x00000000 321 - #define EMAC_TMR1_DEFAULT 0xf8640000 322 - #elif defined(CONFIG_440GX) 323 - #define EMAC_RWMR_DEFAULT 0x1000a200 324 - #define EMAC_TMR0_DEFAULT EMAC_TMR0_TFAE_2_32 325 - #define EMAC_TMR1_DEFAULT 0xa00f0000 326 - #elif defined(CONFIG_440SP) 327 - #define EMAC_RWMR_DEFAULT 0x08002000 328 - #define EMAC_TMR0_DEFAULT EMAC_TMR0_TFAE_128_2048 329 - #define EMAC_TMR1_DEFAULT 0xf8200000 330 - #else 331 - #define EMAC_RWMR_DEFAULT 0x0f002000 332 - #define EMAC_TMR0_DEFAULT 0x00000000 333 - #define EMAC_TMR1_DEFAULT 0x380f0000 334 - #endif /* CONFIG_440GP */ 335 - 336 - /* Revision specific EMAC register defaults */ 337 - #ifdef CONFIG_IBM_EMAC4 338 - #define EMAC_M1_DEFAULT (EMAC_M1_BASE | \ 339 - EMAC_M1_OPB_CLK_83 | \ 340 - EMAC_M1_TX_MWSW) 341 - #define EMAC_RMR_DEFAULT (EMAC_RMR_BASE | \ 342 - EMAC_RMR_RFAF_128_2048) 343 - #define EMAC_TMR0_XMIT (EMAC_TMR0_GNP0 | \ 344 - EMAC_TMR0_DEFAULT) 345 - #define EMAC_TRTR_DEFAULT EMAC_TRTR_1024 346 - #else /* !CONFIG_IBM_EMAC4 */ 347 - #define EMAC_M1_DEFAULT EMAC_M1_BASE 348 - #define EMAC_RMR_DEFAULT EMAC_RMR_BASE 349 - #define EMAC_TMR0_XMIT EMAC_TMR0_GNP0 350 - #define EMAC_TRTR_DEFAULT EMAC_TRTR_1600 351 - #endif /* CONFIG_IBM_EMAC4 */ 352 - 353 - #endif 217 + #define EMAC_RX_TAH_BAD_CSUM 0x0003 218 + #define EMAC_BAD_RX_MASK (EMAC_RX_ST_OE | EMAC_RX_ST_BP | \ 219 + EMAC_RX_ST_RP | EMAC_RX_ST_SE | \ 220 + EMAC_RX_ST_AE | EMAC_RX_ST_BFCS | \ 221 + EMAC_RX_ST_PTL | EMAC_RX_ST_ORE | \ 222 + EMAC_RX_ST_IRE ) 223 + #endif /* __IBM_EMAC_H_ */
+2036 -1830
drivers/net/ibm_emac/ibm_emac_core.c
··· 1 1 /* 2 - * ibm_emac_core.c 2 + * drivers/net/ibm_emac/ibm_emac_core.c 3 3 * 4 - * Ethernet driver for the built in ethernet on the IBM 4xx PowerPC 5 - * processors. 6 - * 7 - * (c) 2003 Benjamin Herrenschmidt <benh@kernel.crashing.org> 4 + * Driver for PowerPC 4xx on-chip ethernet controller. 5 + * 6 + * Copyright (c) 2004, 2005 Zultys Technologies. 7 + * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net> 8 8 * 9 9 * Based on original work by 10 - * 10 + * Matt Porter <mporter@kernel.crashing.org> 11 + * (c) 2003 Benjamin Herrenschmidt <benh@kernel.crashing.org> 11 12 * Armin Kuster <akuster@mvista.com> 12 13 * Johnnie Peters <jpeters@mvista.com> 13 14 * ··· 16 15 * under the terms of the GNU General Public License as published by the 17 16 * Free Software Foundation; either version 2 of the License, or (at your 18 17 * option) any later version. 19 - * TODO 20 - * - Check for races in the "remove" code path 21 - * - Add some Power Management to the MAC and the PHY 22 - * - Audit remaining of non-rewritten code (--BenH) 23 - * - Cleanup message display using msglevel mecanism 24 - * - Address all errata 25 - * - Audit all register update paths to ensure they 26 - * are being written post soft reset if required. 18 + * 27 19 */ 20 + 21 + #include <linux/config.h> 28 22 #include <linux/module.h> 29 23 #include <linux/kernel.h> 30 24 #include <linux/sched.h> 31 25 #include <linux/string.h> 32 - #include <linux/timer.h> 33 - #include <linux/ptrace.h> 34 26 #include <linux/errno.h> 35 - #include <linux/ioport.h> 36 - #include <linux/slab.h> 37 27 #include <linux/interrupt.h> 38 28 #include <linux/delay.h> 39 29 #include <linux/init.h> 40 30 #include <linux/types.h> 41 - #include <linux/dma-mapping.h> 31 + #include <linux/pci.h> 32 + #include <linux/netdevice.h> 33 + #include <linux/etherdevice.h> 34 + #include <linux/skbuff.h> 35 + #include <linux/crc32.h> 42 36 #include <linux/ethtool.h> 43 37 #include <linux/mii.h> 44 38 #include <linux/bitops.h> ··· 41 45 #include <asm/processor.h> 42 46 #include <asm/io.h> 43 47 #include <asm/dma.h> 44 - #include <asm/irq.h> 45 48 #include <asm/uaccess.h> 46 49 #include <asm/ocp.h> 47 50 48 - #include <linux/netdevice.h> 49 - #include <linux/etherdevice.h> 50 - #include <linux/skbuff.h> 51 - #include <linux/crc32.h> 52 - 53 51 #include "ibm_emac_core.h" 54 - 55 - //#define MDIO_DEBUG(fmt) printk fmt 56 - #define MDIO_DEBUG(fmt) 57 - 58 - //#define LINK_DEBUG(fmt) printk fmt 59 - #define LINK_DEBUG(fmt) 60 - 61 - //#define PKT_DEBUG(fmt) printk fmt 62 - #define PKT_DEBUG(fmt) 63 - 64 - #define DRV_NAME "emac" 65 - #define DRV_VERSION "2.0" 66 - #define DRV_AUTHOR "Benjamin Herrenschmidt <benh@kernel.crashing.org>" 67 - #define DRV_DESC "IBM EMAC Ethernet driver" 52 + #include "ibm_emac_debug.h" 68 53 69 54 /* 70 - * When mdio_idx >= 0, contains a list of emac ocp_devs 71 - * that have had their initialization deferred until the 72 - * common MDIO controller has been initialized. 55 + * Lack of dma_unmap_???? calls is intentional. 56 + * 57 + * API-correct usage requires additional support state information to be 58 + * maintained for every RX and TX buffer descriptor (BD). Unfortunately, due to 59 + * EMAC design (e.g. TX buffer passed from network stack can be split into 60 + * several BDs, dma_map_single/dma_map_page can be used to map particular BD), 61 + * maintaining such information will add additional overhead. 62 + * Current DMA API implementation for 4xx processors only ensures cache coherency 63 + * and dma_unmap_???? routines are empty and are likely to stay this way. 64 + * I decided to omit dma_unmap_??? calls because I don't want to add additional 65 + * complexity just for the sake of following some abstract API, when it doesn't 66 + * add any real benefit to the driver. I understand that this decision maybe 67 + * controversial, but I really tried to make code API-correct and efficient 68 + * at the same time and didn't come up with code I liked :(. --ebs 73 69 */ 74 - LIST_HEAD(emac_init_list); 75 70 76 - MODULE_AUTHOR(DRV_AUTHOR); 71 + #define DRV_NAME "emac" 72 + #define DRV_VERSION "3.53" 73 + #define DRV_DESC "PPC 4xx OCP EMAC driver" 74 + 77 75 MODULE_DESCRIPTION(DRV_DESC); 76 + MODULE_AUTHOR 77 + ("Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net>"); 78 78 MODULE_LICENSE("GPL"); 79 79 80 - static int skb_res = SKB_RES; 81 - module_param(skb_res, int, 0444); 82 - MODULE_PARM_DESC(skb_res, "Amount of data to reserve on skb buffs\n" 83 - "The 405 handles a misaligned IP header fine but\n" 84 - "this can help if you are routing to a tunnel or a\n" 85 - "device that needs aligned data. 0..2"); 80 + /* minimum number of free TX descriptors required to wake up TX process */ 81 + #define EMAC_TX_WAKEUP_THRESH (NUM_TX_BUFF / 4) 86 82 87 - #define RGMII_PRIV(ocpdev) ((struct ibm_ocp_rgmii*)ocp_get_drvdata(ocpdev)) 88 - 89 - static unsigned int rgmii_enable[] = { 90 - RGMII_RTBI, 91 - RGMII_RGMII, 92 - RGMII_TBI, 93 - RGMII_GMII 94 - }; 95 - 96 - static unsigned int rgmii_speed_mask[] = { 97 - RGMII_MII2_SPDMASK, 98 - RGMII_MII3_SPDMASK 99 - }; 100 - 101 - static unsigned int rgmii_speed100[] = { 102 - RGMII_MII2_100MB, 103 - RGMII_MII3_100MB 104 - }; 105 - 106 - static unsigned int rgmii_speed1000[] = { 107 - RGMII_MII2_1000MB, 108 - RGMII_MII3_1000MB 109 - }; 110 - 111 - #define ZMII_PRIV(ocpdev) ((struct ibm_ocp_zmii*)ocp_get_drvdata(ocpdev)) 112 - 113 - static unsigned int zmii_enable[][4] = { 114 - {ZMII_SMII0, ZMII_RMII0, ZMII_MII0, 115 - ~(ZMII_MDI1 | ZMII_MDI2 | ZMII_MDI3)}, 116 - {ZMII_SMII1, ZMII_RMII1, ZMII_MII1, 117 - ~(ZMII_MDI0 | ZMII_MDI2 | ZMII_MDI3)}, 118 - {ZMII_SMII2, ZMII_RMII2, ZMII_MII2, 119 - ~(ZMII_MDI0 | ZMII_MDI1 | ZMII_MDI3)}, 120 - {ZMII_SMII3, ZMII_RMII3, ZMII_MII3, ~(ZMII_MDI0 | ZMII_MDI1 | ZMII_MDI2)} 121 - }; 122 - 123 - static unsigned int mdi_enable[] = { 124 - ZMII_MDI0, 125 - ZMII_MDI1, 126 - ZMII_MDI2, 127 - ZMII_MDI3 128 - }; 129 - 130 - static unsigned int zmii_speed = 0x0; 131 - static unsigned int zmii_speed100[] = { 132 - ZMII_MII0_100MB, 133 - ZMII_MII1_100MB, 134 - ZMII_MII2_100MB, 135 - ZMII_MII3_100MB 136 - }; 83 + /* If packet size is less than this number, we allocate small skb and copy packet 84 + * contents into it instead of just sending original big skb up 85 + */ 86 + #define EMAC_RX_COPY_THRESH CONFIG_IBM_EMAC_RX_COPY_THRESHOLD 137 87 138 88 /* Since multiple EMACs share MDIO lines in various ways, we need 139 89 * to avoid re-using the same PHY ID in cases where the arch didn't 140 90 * setup precise phy_map entries 141 91 */ 142 - static u32 busy_phy_map = 0; 143 - 144 - /* If EMACs share a common MDIO device, this points to it */ 145 - static struct net_device *mdio_ndev = NULL; 146 - 147 - struct emac_def_dev { 148 - struct list_head link; 149 - struct ocp_device *ocpdev; 150 - struct ibm_ocp_mal *mal; 151 - }; 152 - 153 - static struct net_device_stats *emac_stats(struct net_device *dev) 154 - { 155 - struct ocp_enet_private *fep = dev->priv; 156 - return &fep->stats; 157 - }; 158 - 159 - static int 160 - emac_init_rgmii(struct ocp_device *rgmii_dev, int input, int phy_mode) 161 - { 162 - struct ibm_ocp_rgmii *rgmii = RGMII_PRIV(rgmii_dev); 163 - const char *mode_name[] = { "RTBI", "RGMII", "TBI", "GMII" }; 164 - int mode = -1; 165 - 166 - if (!rgmii) { 167 - rgmii = kmalloc(sizeof(struct ibm_ocp_rgmii), GFP_KERNEL); 168 - 169 - if (rgmii == NULL) { 170 - printk(KERN_ERR 171 - "rgmii%d: Out of memory allocating RGMII structure!\n", 172 - rgmii_dev->def->index); 173 - return -ENOMEM; 174 - } 175 - 176 - memset(rgmii, 0, sizeof(*rgmii)); 177 - 178 - rgmii->base = 179 - (struct rgmii_regs *)ioremap(rgmii_dev->def->paddr, 180 - sizeof(*rgmii->base)); 181 - if (rgmii->base == NULL) { 182 - printk(KERN_ERR 183 - "rgmii%d: Cannot ioremap bridge registers!\n", 184 - rgmii_dev->def->index); 185 - 186 - kfree(rgmii); 187 - return -ENOMEM; 188 - } 189 - ocp_set_drvdata(rgmii_dev, rgmii); 190 - } 191 - 192 - if (phy_mode) { 193 - switch (phy_mode) { 194 - case PHY_MODE_GMII: 195 - mode = GMII; 196 - break; 197 - case PHY_MODE_TBI: 198 - mode = TBI; 199 - break; 200 - case PHY_MODE_RTBI: 201 - mode = RTBI; 202 - break; 203 - case PHY_MODE_RGMII: 204 - default: 205 - mode = RGMII; 206 - } 207 - rgmii->base->fer &= ~RGMII_FER_MASK(input); 208 - rgmii->base->fer |= rgmii_enable[mode] << (4 * input); 209 - } else { 210 - switch ((rgmii->base->fer & RGMII_FER_MASK(input)) >> (4 * 211 - input)) { 212 - case RGMII_RTBI: 213 - mode = RTBI; 214 - break; 215 - case RGMII_RGMII: 216 - mode = RGMII; 217 - break; 218 - case RGMII_TBI: 219 - mode = TBI; 220 - break; 221 - case RGMII_GMII: 222 - mode = GMII; 223 - } 224 - } 225 - 226 - /* Set mode to RGMII if nothing valid is detected */ 227 - if (mode < 0) 228 - mode = RGMII; 229 - 230 - printk(KERN_NOTICE "rgmii%d: input %d in %s mode\n", 231 - rgmii_dev->def->index, input, mode_name[mode]); 232 - 233 - rgmii->mode[input] = mode; 234 - rgmii->users++; 235 - 236 - return 0; 237 - } 238 - 239 - static void 240 - emac_rgmii_port_speed(struct ocp_device *ocpdev, int input, int speed) 241 - { 242 - struct ibm_ocp_rgmii *rgmii = RGMII_PRIV(ocpdev); 243 - unsigned int rgmii_speed; 244 - 245 - rgmii_speed = in_be32(&rgmii->base->ssr); 246 - 247 - rgmii_speed &= ~rgmii_speed_mask[input]; 248 - 249 - if (speed == 1000) 250 - rgmii_speed |= rgmii_speed1000[input]; 251 - else if (speed == 100) 252 - rgmii_speed |= rgmii_speed100[input]; 253 - 254 - out_be32(&rgmii->base->ssr, rgmii_speed); 255 - } 256 - 257 - static void emac_close_rgmii(struct ocp_device *ocpdev) 258 - { 259 - struct ibm_ocp_rgmii *rgmii = RGMII_PRIV(ocpdev); 260 - BUG_ON(!rgmii || rgmii->users == 0); 261 - 262 - if (!--rgmii->users) { 263 - ocp_set_drvdata(ocpdev, NULL); 264 - iounmap((void *)rgmii->base); 265 - kfree(rgmii); 266 - } 267 - } 268 - 269 - static int emac_init_zmii(struct ocp_device *zmii_dev, int input, int phy_mode) 270 - { 271 - struct ibm_ocp_zmii *zmii = ZMII_PRIV(zmii_dev); 272 - const char *mode_name[] = { "SMII", "RMII", "MII" }; 273 - int mode = -1; 274 - 275 - if (!zmii) { 276 - zmii = kmalloc(sizeof(struct ibm_ocp_zmii), GFP_KERNEL); 277 - if (zmii == NULL) { 278 - printk(KERN_ERR 279 - "zmii%d: Out of memory allocating ZMII structure!\n", 280 - zmii_dev->def->index); 281 - return -ENOMEM; 282 - } 283 - memset(zmii, 0, sizeof(*zmii)); 284 - 285 - zmii->base = 286 - (struct zmii_regs *)ioremap(zmii_dev->def->paddr, 287 - sizeof(*zmii->base)); 288 - if (zmii->base == NULL) { 289 - printk(KERN_ERR 290 - "zmii%d: Cannot ioremap bridge registers!\n", 291 - zmii_dev->def->index); 292 - 293 - kfree(zmii); 294 - return -ENOMEM; 295 - } 296 - ocp_set_drvdata(zmii_dev, zmii); 297 - } 298 - 299 - if (phy_mode) { 300 - switch (phy_mode) { 301 - case PHY_MODE_MII: 302 - mode = MII; 303 - break; 304 - case PHY_MODE_RMII: 305 - mode = RMII; 306 - break; 307 - case PHY_MODE_SMII: 308 - default: 309 - mode = SMII; 310 - } 311 - zmii->base->fer &= ~ZMII_FER_MASK(input); 312 - zmii->base->fer |= zmii_enable[input][mode]; 313 - } else { 314 - switch ((zmii->base->fer & ZMII_FER_MASK(input)) << (4 * input)) { 315 - case ZMII_MII0: 316 - mode = MII; 317 - break; 318 - case ZMII_RMII0: 319 - mode = RMII; 320 - break; 321 - case ZMII_SMII0: 322 - mode = SMII; 323 - } 324 - } 325 - 326 - /* Set mode to SMII if nothing valid is detected */ 327 - if (mode < 0) 328 - mode = SMII; 329 - 330 - printk(KERN_NOTICE "zmii%d: input %d in %s mode\n", 331 - zmii_dev->def->index, input, mode_name[mode]); 332 - 333 - zmii->mode[input] = mode; 334 - zmii->users++; 335 - 336 - return 0; 337 - } 338 - 339 - static void emac_enable_zmii_port(struct ocp_device *ocpdev, int input) 340 - { 341 - u32 mask; 342 - struct ibm_ocp_zmii *zmii = ZMII_PRIV(ocpdev); 343 - 344 - mask = in_be32(&zmii->base->fer); 345 - mask &= zmii_enable[input][MDI]; /* turn all non enabled MDI's off */ 346 - mask |= zmii_enable[input][zmii->mode[input]] | mdi_enable[input]; 347 - out_be32(&zmii->base->fer, mask); 348 - } 349 - 350 - static void 351 - emac_zmii_port_speed(struct ocp_device *ocpdev, int input, int speed) 352 - { 353 - struct ibm_ocp_zmii *zmii = ZMII_PRIV(ocpdev); 354 - 355 - if (speed == 100) 356 - zmii_speed |= zmii_speed100[input]; 357 - else 358 - zmii_speed &= ~zmii_speed100[input]; 359 - 360 - out_be32(&zmii->base->ssr, zmii_speed); 361 - } 362 - 363 - static void emac_close_zmii(struct ocp_device *ocpdev) 364 - { 365 - struct ibm_ocp_zmii *zmii = ZMII_PRIV(ocpdev); 366 - BUG_ON(!zmii || zmii->users == 0); 367 - 368 - if (!--zmii->users) { 369 - ocp_set_drvdata(ocpdev, NULL); 370 - iounmap((void *)zmii->base); 371 - kfree(zmii); 372 - } 373 - } 374 - 375 - int emac_phy_read(struct net_device *dev, int mii_id, int reg) 376 - { 377 - int count; 378 - uint32_t stacr; 379 - struct ocp_enet_private *fep = dev->priv; 380 - emac_t *emacp = fep->emacp; 381 - 382 - MDIO_DEBUG(("%s: phy_read, id: 0x%x, reg: 0x%x\n", dev->name, mii_id, 383 - reg)); 384 - 385 - /* Enable proper ZMII port */ 386 - if (fep->zmii_dev) 387 - emac_enable_zmii_port(fep->zmii_dev, fep->zmii_input); 388 - 389 - /* Use the EMAC that has the MDIO port */ 390 - if (fep->mdio_dev) { 391 - dev = fep->mdio_dev; 392 - fep = dev->priv; 393 - emacp = fep->emacp; 394 - } 395 - 396 - count = 0; 397 - while ((((stacr = in_be32(&emacp->em0stacr)) & EMAC_STACR_OC) == 0) 398 - && (count++ < MDIO_DELAY)) 399 - udelay(1); 400 - MDIO_DEBUG((" (count was %d)\n", count)); 401 - 402 - if ((stacr & EMAC_STACR_OC) == 0) { 403 - printk(KERN_WARNING "%s: PHY read timeout #1!\n", dev->name); 404 - return -1; 405 - } 406 - 407 - /* Clear the speed bits and make a read request to the PHY */ 408 - stacr = ((EMAC_STACR_READ | (reg & 0x1f)) & ~EMAC_STACR_CLK_100MHZ); 409 - stacr |= ((mii_id & 0x1F) << 5); 410 - 411 - out_be32(&emacp->em0stacr, stacr); 412 - 413 - count = 0; 414 - while ((((stacr = in_be32(&emacp->em0stacr)) & EMAC_STACR_OC) == 0) 415 - && (count++ < MDIO_DELAY)) 416 - udelay(1); 417 - MDIO_DEBUG((" (count was %d)\n", count)); 418 - 419 - if ((stacr & EMAC_STACR_OC) == 0) { 420 - printk(KERN_WARNING "%s: PHY read timeout #2!\n", dev->name); 421 - return -1; 422 - } 423 - 424 - /* Check for a read error */ 425 - if (stacr & EMAC_STACR_PHYE) { 426 - MDIO_DEBUG(("EMAC MDIO PHY error !\n")); 427 - return -1; 428 - } 429 - 430 - MDIO_DEBUG((" -> 0x%x\n", stacr >> 16)); 431 - 432 - return (stacr >> 16); 433 - } 434 - 435 - void emac_phy_write(struct net_device *dev, int mii_id, int reg, int data) 436 - { 437 - int count; 438 - uint32_t stacr; 439 - struct ocp_enet_private *fep = dev->priv; 440 - emac_t *emacp = fep->emacp; 441 - 442 - MDIO_DEBUG(("%s phy_write, id: 0x%x, reg: 0x%x, data: 0x%x\n", 443 - dev->name, mii_id, reg, data)); 444 - 445 - /* Enable proper ZMII port */ 446 - if (fep->zmii_dev) 447 - emac_enable_zmii_port(fep->zmii_dev, fep->zmii_input); 448 - 449 - /* Use the EMAC that has the MDIO port */ 450 - if (fep->mdio_dev) { 451 - dev = fep->mdio_dev; 452 - fep = dev->priv; 453 - emacp = fep->emacp; 454 - } 455 - 456 - count = 0; 457 - while ((((stacr = in_be32(&emacp->em0stacr)) & EMAC_STACR_OC) == 0) 458 - && (count++ < MDIO_DELAY)) 459 - udelay(1); 460 - MDIO_DEBUG((" (count was %d)\n", count)); 461 - 462 - if ((stacr & EMAC_STACR_OC) == 0) { 463 - printk(KERN_WARNING "%s: PHY write timeout #2!\n", dev->name); 464 - return; 465 - } 466 - 467 - /* Clear the speed bits and make a read request to the PHY */ 468 - 469 - stacr = ((EMAC_STACR_WRITE | (reg & 0x1f)) & ~EMAC_STACR_CLK_100MHZ); 470 - stacr |= ((mii_id & 0x1f) << 5) | ((data & 0xffff) << 16); 471 - 472 - out_be32(&emacp->em0stacr, stacr); 473 - 474 - count = 0; 475 - while ((((stacr = in_be32(&emacp->em0stacr)) & EMAC_STACR_OC) == 0) 476 - && (count++ < MDIO_DELAY)) 477 - udelay(1); 478 - MDIO_DEBUG((" (count was %d)\n", count)); 479 - 480 - if ((stacr & EMAC_STACR_OC) == 0) 481 - printk(KERN_WARNING "%s: PHY write timeout #2!\n", dev->name); 482 - 483 - /* Check for a write error */ 484 - if ((stacr & EMAC_STACR_PHYE) != 0) { 485 - MDIO_DEBUG(("EMAC MDIO PHY error !\n")); 486 - } 487 - } 488 - 489 - static void emac_txeob_dev(void *param, u32 chanmask) 490 - { 491 - struct net_device *dev = param; 492 - struct ocp_enet_private *fep = dev->priv; 493 - unsigned long flags; 494 - 495 - spin_lock_irqsave(&fep->lock, flags); 496 - 497 - PKT_DEBUG(("emac_txeob_dev() entry, tx_cnt: %d\n", fep->tx_cnt)); 498 - 499 - while (fep->tx_cnt && 500 - !(fep->tx_desc[fep->ack_slot].ctrl & MAL_TX_CTRL_READY)) { 501 - 502 - if (fep->tx_desc[fep->ack_slot].ctrl & MAL_TX_CTRL_LAST) { 503 - /* Tell the system the transmit completed. */ 504 - dma_unmap_single(&fep->ocpdev->dev, 505 - fep->tx_desc[fep->ack_slot].data_ptr, 506 - fep->tx_desc[fep->ack_slot].data_len, 507 - DMA_TO_DEVICE); 508 - dev_kfree_skb_irq(fep->tx_skb[fep->ack_slot]); 509 - 510 - if (fep->tx_desc[fep->ack_slot].ctrl & 511 - (EMAC_TX_ST_EC | EMAC_TX_ST_MC | EMAC_TX_ST_SC)) 512 - fep->stats.collisions++; 513 - } 514 - 515 - fep->tx_skb[fep->ack_slot] = (struct sk_buff *)NULL; 516 - if (++fep->ack_slot == NUM_TX_BUFF) 517 - fep->ack_slot = 0; 518 - 519 - fep->tx_cnt--; 520 - } 521 - if (fep->tx_cnt < NUM_TX_BUFF) 522 - netif_wake_queue(dev); 523 - 524 - PKT_DEBUG(("emac_txeob_dev() exit, tx_cnt: %d\n", fep->tx_cnt)); 525 - 526 - spin_unlock_irqrestore(&fep->lock, flags); 527 - } 528 - 529 - /* 530 - Fill/Re-fill the rx chain with valid ctrl/ptrs. 531 - This function will fill from rx_slot up to the parm end. 532 - So to completely fill the chain pre-set rx_slot to 0 and 533 - pass in an end of 0. 92 + static u32 busy_phy_map; 93 + 94 + #if defined(CONFIG_IBM_EMAC_PHY_RX_CLK_FIX) && (defined(CONFIG_405EP) || defined(CONFIG_440EP)) 95 + /* 405EP has "EMAC to PHY Control Register" (CPC0_EPCTL) which can help us 96 + * with PHY RX clock problem. 97 + * 440EP has more sane SDR0_MFR register implementation than 440GX, which 98 + * also allows controlling each EMAC clock 534 99 */ 535 - static void emac_rx_fill(struct net_device *dev, int end) 100 + static inline void EMAC_RX_CLK_TX(int idx) 536 101 { 537 - int i; 538 - struct ocp_enet_private *fep = dev->priv; 539 - 540 - i = fep->rx_slot; 541 - do { 542 - /* We don't want the 16 bytes skb_reserve done by dev_alloc_skb, 543 - * it breaks our cache line alignement. However, we still allocate 544 - * +16 so that we end up allocating the exact same size as 545 - * dev_alloc_skb() would do. 546 - * Also, because of the skb_res, the max DMA size we give to EMAC 547 - * is slighly wrong, causing it to potentially DMA 2 more bytes 548 - * from a broken/oversized packet. These 16 bytes will take care 549 - * that we don't walk on somebody else toes with that. 550 - */ 551 - fep->rx_skb[i] = 552 - alloc_skb(fep->rx_buffer_size + 16, GFP_ATOMIC); 553 - 554 - if (fep->rx_skb[i] == NULL) { 555 - /* Keep rx_slot here, the next time clean/fill is called 556 - * we will try again before the MAL wraps back here 557 - * If the MAL tries to use this descriptor with 558 - * the EMPTY bit off it will cause the 559 - * rxde interrupt. That is where we will 560 - * try again to allocate an sk_buff. 561 - */ 562 - break; 563 - 564 - } 565 - 566 - if (skb_res) 567 - skb_reserve(fep->rx_skb[i], skb_res); 568 - 569 - /* We must NOT dma_map_single the cache line right after the 570 - * buffer, so we must crop our sync size to account for the 571 - * reserved space 572 - */ 573 - fep->rx_desc[i].data_ptr = 574 - (unsigned char *)dma_map_single(&fep->ocpdev->dev, 575 - (void *)fep->rx_skb[i]-> 576 - data, 577 - fep->rx_buffer_size - 578 - skb_res, DMA_FROM_DEVICE); 579 - 580 - /* 581 - * Some 4xx implementations use the previously 582 - * reserved bits in data_len to encode the MS 583 - * 4-bits of a 36-bit physical address (ERPN) 584 - * This must be initialized. 585 - */ 586 - fep->rx_desc[i].data_len = 0; 587 - fep->rx_desc[i].ctrl = MAL_RX_CTRL_EMPTY | MAL_RX_CTRL_INTR | 588 - (i == (NUM_RX_BUFF - 1) ? MAL_RX_CTRL_WRAP : 0); 589 - 590 - } while ((i = (i + 1) % NUM_RX_BUFF) != end); 591 - 592 - fep->rx_slot = i; 593 - } 594 - 595 - static void 596 - emac_rx_csum(struct net_device *dev, unsigned short ctrl, struct sk_buff *skb) 597 - { 598 - struct ocp_enet_private *fep = dev->priv; 599 - 600 - /* Exit if interface has no TAH engine */ 601 - if (!fep->tah_dev) { 602 - skb->ip_summed = CHECKSUM_NONE; 603 - return; 604 - } 605 - 606 - /* Check for TCP/UDP/IP csum error */ 607 - if (ctrl & EMAC_CSUM_VER_ERROR) { 608 - /* Let the stack verify checksum errors */ 609 - skb->ip_summed = CHECKSUM_NONE; 610 - /* adapter->hw_csum_err++; */ 611 - } else { 612 - /* Csum is good */ 613 - skb->ip_summed = CHECKSUM_UNNECESSARY; 614 - /* adapter->hw_csum_good++; */ 615 - } 616 - } 617 - 618 - static int emac_rx_clean(struct net_device *dev) 619 - { 620 - int i, b, bnum = 0, buf[6]; 621 - int error, frame_length; 622 - struct ocp_enet_private *fep = dev->priv; 623 - unsigned short ctrl; 624 - 625 - i = fep->rx_slot; 626 - 627 - PKT_DEBUG(("emac_rx_clean() entry, rx_slot: %d\n", fep->rx_slot)); 628 - 629 - do { 630 - if (fep->rx_skb[i] == NULL) 631 - continue; /*we have already handled the packet but haved failed to alloc */ 632 - /* 633 - since rx_desc is in uncached mem we don't keep reading it directly 634 - we pull out a local copy of ctrl and do the checks on the copy. 635 - */ 636 - ctrl = fep->rx_desc[i].ctrl; 637 - if (ctrl & MAL_RX_CTRL_EMPTY) 638 - break; /*we don't have any more ready packets */ 639 - 640 - if (EMAC_IS_BAD_RX_PACKET(ctrl)) { 641 - fep->stats.rx_errors++; 642 - fep->stats.rx_dropped++; 643 - 644 - if (ctrl & EMAC_RX_ST_OE) 645 - fep->stats.rx_fifo_errors++; 646 - if (ctrl & EMAC_RX_ST_AE) 647 - fep->stats.rx_frame_errors++; 648 - if (ctrl & EMAC_RX_ST_BFCS) 649 - fep->stats.rx_crc_errors++; 650 - if (ctrl & (EMAC_RX_ST_RP | EMAC_RX_ST_PTL | 651 - EMAC_RX_ST_ORE | EMAC_RX_ST_IRE)) 652 - fep->stats.rx_length_errors++; 653 - } else { 654 - if ((ctrl & (MAL_RX_CTRL_FIRST | MAL_RX_CTRL_LAST)) == 655 - (MAL_RX_CTRL_FIRST | MAL_RX_CTRL_LAST)) { 656 - /* Single descriptor packet */ 657 - emac_rx_csum(dev, ctrl, fep->rx_skb[i]); 658 - /* Send the skb up the chain. */ 659 - frame_length = fep->rx_desc[i].data_len - 4; 660 - skb_put(fep->rx_skb[i], frame_length); 661 - fep->rx_skb[i]->dev = dev; 662 - fep->rx_skb[i]->protocol = 663 - eth_type_trans(fep->rx_skb[i], dev); 664 - error = netif_rx(fep->rx_skb[i]); 665 - 666 - if ((error == NET_RX_DROP) || 667 - (error == NET_RX_BAD)) { 668 - fep->stats.rx_dropped++; 669 - } else { 670 - fep->stats.rx_packets++; 671 - fep->stats.rx_bytes += frame_length; 672 - } 673 - fep->rx_skb[i] = NULL; 674 - } else { 675 - /* Multiple descriptor packet */ 676 - if (ctrl & MAL_RX_CTRL_FIRST) { 677 - if (fep->rx_desc[(i + 1) % NUM_RX_BUFF]. 678 - ctrl & MAL_RX_CTRL_EMPTY) 679 - break; 680 - bnum = 0; 681 - buf[bnum] = i; 682 - ++bnum; 683 - continue; 684 - } 685 - if (((ctrl & MAL_RX_CTRL_FIRST) != 686 - MAL_RX_CTRL_FIRST) && 687 - ((ctrl & MAL_RX_CTRL_LAST) != 688 - MAL_RX_CTRL_LAST)) { 689 - if (fep->rx_desc[(i + 1) % 690 - NUM_RX_BUFF].ctrl & 691 - MAL_RX_CTRL_EMPTY) { 692 - i = buf[0]; 693 - break; 694 - } 695 - buf[bnum] = i; 696 - ++bnum; 697 - continue; 698 - } 699 - if (ctrl & MAL_RX_CTRL_LAST) { 700 - buf[bnum] = i; 701 - ++bnum; 702 - skb_put(fep->rx_skb[buf[0]], 703 - fep->rx_desc[buf[0]].data_len); 704 - for (b = 1; b < bnum; b++) { 705 - /* 706 - * MAL is braindead, we need 707 - * to copy the remainder 708 - * of the packet from the 709 - * latter descriptor buffers 710 - * to the first skb. Then 711 - * dispose of the source 712 - * skbs. 713 - * 714 - * Once the stack is fixed 715 - * to handle frags on most 716 - * protocols we can generate 717 - * a fragmented skb with 718 - * no copies. 719 - */ 720 - memcpy(fep->rx_skb[buf[0]]-> 721 - data + 722 - fep->rx_skb[buf[0]]->len, 723 - fep->rx_skb[buf[b]]-> 724 - data, 725 - fep->rx_desc[buf[b]]. 726 - data_len); 727 - skb_put(fep->rx_skb[buf[0]], 728 - fep->rx_desc[buf[b]]. 729 - data_len); 730 - dma_unmap_single(&fep->ocpdev-> 731 - dev, 732 - fep-> 733 - rx_desc[buf 734 - [b]]. 735 - data_ptr, 736 - fep-> 737 - rx_desc[buf 738 - [b]]. 739 - data_len, 740 - DMA_FROM_DEVICE); 741 - dev_kfree_skb(fep-> 742 - rx_skb[buf[b]]); 743 - } 744 - emac_rx_csum(dev, ctrl, 745 - fep->rx_skb[buf[0]]); 746 - 747 - fep->rx_skb[buf[0]]->dev = dev; 748 - fep->rx_skb[buf[0]]->protocol = 749 - eth_type_trans(fep->rx_skb[buf[0]], 750 - dev); 751 - error = netif_rx(fep->rx_skb[buf[0]]); 752 - 753 - if ((error == NET_RX_DROP) 754 - || (error == NET_RX_BAD)) { 755 - fep->stats.rx_dropped++; 756 - } else { 757 - fep->stats.rx_packets++; 758 - fep->stats.rx_bytes += 759 - fep->rx_skb[buf[0]]->len; 760 - } 761 - for (b = 0; b < bnum; b++) 762 - fep->rx_skb[buf[b]] = NULL; 763 - } 764 - } 765 - } 766 - } while ((i = (i + 1) % NUM_RX_BUFF) != fep->rx_slot); 767 - 768 - PKT_DEBUG(("emac_rx_clean() exit, rx_slot: %d\n", fep->rx_slot)); 769 - 770 - return i; 771 - } 772 - 773 - static void emac_rxeob_dev(void *param, u32 chanmask) 774 - { 775 - struct net_device *dev = param; 776 - struct ocp_enet_private *fep = dev->priv; 777 102 unsigned long flags; 103 + local_irq_save(flags); 104 + 105 + #if defined(CONFIG_405EP) 106 + mtdcr(0xf3, mfdcr(0xf3) | (1 << idx)); 107 + #else /* CONFIG_440EP */ 108 + SDR_WRITE(DCRN_SDR_MFR, SDR_READ(DCRN_SDR_MFR) | (0x08000000 >> idx)); 109 + #endif 110 + 111 + local_irq_restore(flags); 112 + } 113 + 114 + static inline void EMAC_RX_CLK_DEFAULT(int idx) 115 + { 116 + unsigned long flags; 117 + local_irq_save(flags); 118 + 119 + #if defined(CONFIG_405EP) 120 + mtdcr(0xf3, mfdcr(0xf3) & ~(1 << idx)); 121 + #else /* CONFIG_440EP */ 122 + SDR_WRITE(DCRN_SDR_MFR, SDR_READ(DCRN_SDR_MFR) & ~(0x08000000 >> idx)); 123 + #endif 124 + 125 + local_irq_restore(flags); 126 + } 127 + #else 128 + #define EMAC_RX_CLK_TX(idx) ((void)0) 129 + #define EMAC_RX_CLK_DEFAULT(idx) ((void)0) 130 + #endif 131 + 132 + #if defined(CONFIG_IBM_EMAC_PHY_RX_CLK_FIX) && defined(CONFIG_440GX) 133 + /* We can switch Ethernet clock to the internal source through SDR0_MFR[ECS], 134 + * unfortunately this is less flexible than 440EP case, because it's a global 135 + * setting for all EMACs, therefore we do this clock trick only during probe. 136 + */ 137 + #define EMAC_CLK_INTERNAL SDR_WRITE(DCRN_SDR_MFR, \ 138 + SDR_READ(DCRN_SDR_MFR) | 0x08000000) 139 + #define EMAC_CLK_EXTERNAL SDR_WRITE(DCRN_SDR_MFR, \ 140 + SDR_READ(DCRN_SDR_MFR) & ~0x08000000) 141 + #else 142 + #define EMAC_CLK_INTERNAL ((void)0) 143 + #define EMAC_CLK_EXTERNAL ((void)0) 144 + #endif 145 + 146 + /* I don't want to litter system log with timeout errors 147 + * when we have brain-damaged PHY. 148 + */ 149 + static inline void emac_report_timeout_error(struct ocp_enet_private *dev, 150 + const char *error) 151 + { 152 + #if defined(CONFIG_IBM_EMAC_PHY_RX_CLK_FIX) 153 + DBG("%d: %s" NL, dev->def->index, error); 154 + #else 155 + if (net_ratelimit()) 156 + printk(KERN_ERR "emac%d: %s\n", dev->def->index, error); 157 + #endif 158 + } 159 + 160 + /* PHY polling intervals */ 161 + #define PHY_POLL_LINK_ON HZ 162 + #define PHY_POLL_LINK_OFF (HZ / 5) 163 + 164 + /* Please, keep in sync with struct ibm_emac_stats/ibm_emac_error_stats */ 165 + static const char emac_stats_keys[EMAC_ETHTOOL_STATS_COUNT][ETH_GSTRING_LEN] = { 166 + "rx_packets", "rx_bytes", "tx_packets", "tx_bytes", "rx_packets_csum", 167 + "tx_packets_csum", "tx_undo", "rx_dropped_stack", "rx_dropped_oom", 168 + "rx_dropped_error", "rx_dropped_resize", "rx_dropped_mtu", 169 + "rx_stopped", "rx_bd_errors", "rx_bd_overrun", "rx_bd_bad_packet", 170 + "rx_bd_runt_packet", "rx_bd_short_event", "rx_bd_alignment_error", 171 + "rx_bd_bad_fcs", "rx_bd_packet_too_long", "rx_bd_out_of_range", 172 + "rx_bd_in_range", "rx_parity", "rx_fifo_overrun", "rx_overrun", 173 + "rx_bad_packet", "rx_runt_packet", "rx_short_event", 174 + "rx_alignment_error", "rx_bad_fcs", "rx_packet_too_long", 175 + "rx_out_of_range", "rx_in_range", "tx_dropped", "tx_bd_errors", 176 + "tx_bd_bad_fcs", "tx_bd_carrier_loss", "tx_bd_excessive_deferral", 177 + "tx_bd_excessive_collisions", "tx_bd_late_collision", 178 + "tx_bd_multple_collisions", "tx_bd_single_collision", 179 + "tx_bd_underrun", "tx_bd_sqe", "tx_parity", "tx_underrun", "tx_sqe", 180 + "tx_errors" 181 + }; 182 + 183 + static irqreturn_t emac_irq(int irq, void *dev_instance, struct pt_regs *regs); 184 + static void emac_clean_tx_ring(struct ocp_enet_private *dev); 185 + 186 + static inline int emac_phy_supports_gige(int phy_mode) 187 + { 188 + return phy_mode == PHY_MODE_GMII || 189 + phy_mode == PHY_MODE_RGMII || 190 + phy_mode == PHY_MODE_TBI || 191 + phy_mode == PHY_MODE_RTBI; 192 + } 193 + 194 + static inline int emac_phy_gpcs(int phy_mode) 195 + { 196 + return phy_mode == PHY_MODE_TBI || 197 + phy_mode == PHY_MODE_RTBI; 198 + } 199 + 200 + static inline void emac_tx_enable(struct ocp_enet_private *dev) 201 + { 202 + struct emac_regs *p = dev->emacp; 203 + unsigned long flags; 204 + u32 r; 205 + 206 + local_irq_save(flags); 207 + 208 + DBG("%d: tx_enable" NL, dev->def->index); 209 + 210 + r = in_be32(&p->mr0); 211 + if (!(r & EMAC_MR0_TXE)) 212 + out_be32(&p->mr0, r | EMAC_MR0_TXE); 213 + local_irq_restore(flags); 214 + } 215 + 216 + static void emac_tx_disable(struct ocp_enet_private *dev) 217 + { 218 + struct emac_regs *p = dev->emacp; 219 + unsigned long flags; 220 + u32 r; 221 + 222 + local_irq_save(flags); 223 + 224 + DBG("%d: tx_disable" NL, dev->def->index); 225 + 226 + r = in_be32(&p->mr0); 227 + if (r & EMAC_MR0_TXE) { 228 + int n = 300; 229 + out_be32(&p->mr0, r & ~EMAC_MR0_TXE); 230 + while (!(in_be32(&p->mr0) & EMAC_MR0_TXI) && n) 231 + --n; 232 + if (unlikely(!n)) 233 + emac_report_timeout_error(dev, "TX disable timeout"); 234 + } 235 + local_irq_restore(flags); 236 + } 237 + 238 + static void emac_rx_enable(struct ocp_enet_private *dev) 239 + { 240 + struct emac_regs *p = dev->emacp; 241 + unsigned long flags; 242 + u32 r; 243 + 244 + local_irq_save(flags); 245 + if (unlikely(dev->commac.rx_stopped)) 246 + goto out; 247 + 248 + DBG("%d: rx_enable" NL, dev->def->index); 249 + 250 + r = in_be32(&p->mr0); 251 + if (!(r & EMAC_MR0_RXE)) { 252 + if (unlikely(!(r & EMAC_MR0_RXI))) { 253 + /* Wait if previous async disable is still in progress */ 254 + int n = 100; 255 + while (!(r = in_be32(&p->mr0) & EMAC_MR0_RXI) && n) 256 + --n; 257 + if (unlikely(!n)) 258 + emac_report_timeout_error(dev, 259 + "RX disable timeout"); 260 + } 261 + out_be32(&p->mr0, r | EMAC_MR0_RXE); 262 + } 263 + out: 264 + local_irq_restore(flags); 265 + } 266 + 267 + static void emac_rx_disable(struct ocp_enet_private *dev) 268 + { 269 + struct emac_regs *p = dev->emacp; 270 + unsigned long flags; 271 + u32 r; 272 + 273 + local_irq_save(flags); 274 + 275 + DBG("%d: rx_disable" NL, dev->def->index); 276 + 277 + r = in_be32(&p->mr0); 278 + if (r & EMAC_MR0_RXE) { 279 + int n = 300; 280 + out_be32(&p->mr0, r & ~EMAC_MR0_RXE); 281 + while (!(in_be32(&p->mr0) & EMAC_MR0_RXI) && n) 282 + --n; 283 + if (unlikely(!n)) 284 + emac_report_timeout_error(dev, "RX disable timeout"); 285 + } 286 + local_irq_restore(flags); 287 + } 288 + 289 + static inline void emac_rx_disable_async(struct ocp_enet_private *dev) 290 + { 291 + struct emac_regs *p = dev->emacp; 292 + unsigned long flags; 293 + u32 r; 294 + 295 + local_irq_save(flags); 296 + 297 + DBG("%d: rx_disable_async" NL, dev->def->index); 298 + 299 + r = in_be32(&p->mr0); 300 + if (r & EMAC_MR0_RXE) 301 + out_be32(&p->mr0, r & ~EMAC_MR0_RXE); 302 + local_irq_restore(flags); 303 + } 304 + 305 + static int emac_reset(struct ocp_enet_private *dev) 306 + { 307 + struct emac_regs *p = dev->emacp; 308 + unsigned long flags; 309 + int n = 20; 310 + 311 + DBG("%d: reset" NL, dev->def->index); 312 + 313 + local_irq_save(flags); 314 + 315 + if (!dev->reset_failed) { 316 + /* 40x erratum suggests stopping RX channel before reset, 317 + * we stop TX as well 318 + */ 319 + emac_rx_disable(dev); 320 + emac_tx_disable(dev); 321 + } 322 + 323 + out_be32(&p->mr0, EMAC_MR0_SRST); 324 + while ((in_be32(&p->mr0) & EMAC_MR0_SRST) && n) 325 + --n; 326 + local_irq_restore(flags); 327 + 328 + if (n) { 329 + dev->reset_failed = 0; 330 + return 0; 331 + } else { 332 + emac_report_timeout_error(dev, "reset timeout"); 333 + dev->reset_failed = 1; 334 + return -ETIMEDOUT; 335 + } 336 + } 337 + 338 + static void emac_hash_mc(struct ocp_enet_private *dev) 339 + { 340 + struct emac_regs *p = dev->emacp; 341 + u16 gaht[4] = { 0 }; 342 + struct dev_mc_list *dmi; 343 + 344 + DBG("%d: hash_mc %d" NL, dev->def->index, dev->ndev->mc_count); 345 + 346 + for (dmi = dev->ndev->mc_list; dmi; dmi = dmi->next) { 347 + int bit; 348 + DBG2("%d: mc %02x:%02x:%02x:%02x:%02x:%02x" NL, 349 + dev->def->index, 350 + dmi->dmi_addr[0], dmi->dmi_addr[1], dmi->dmi_addr[2], 351 + dmi->dmi_addr[3], dmi->dmi_addr[4], dmi->dmi_addr[5]); 352 + 353 + bit = 63 - (ether_crc(ETH_ALEN, dmi->dmi_addr) >> 26); 354 + gaht[bit >> 4] |= 0x8000 >> (bit & 0x0f); 355 + } 356 + out_be32(&p->gaht1, gaht[0]); 357 + out_be32(&p->gaht2, gaht[1]); 358 + out_be32(&p->gaht3, gaht[2]); 359 + out_be32(&p->gaht4, gaht[3]); 360 + } 361 + 362 + static inline u32 emac_iff2rmr(struct net_device *ndev) 363 + { 364 + u32 r = EMAC_RMR_SP | EMAC_RMR_SFCS | EMAC_RMR_IAE | EMAC_RMR_BAE | 365 + EMAC_RMR_BASE; 366 + 367 + if (ndev->flags & IFF_PROMISC) 368 + r |= EMAC_RMR_PME; 369 + else if (ndev->flags & IFF_ALLMULTI || ndev->mc_count > 32) 370 + r |= EMAC_RMR_PMME; 371 + else if (ndev->mc_count > 0) 372 + r |= EMAC_RMR_MAE; 373 + 374 + return r; 375 + } 376 + 377 + static inline int emac_opb_mhz(void) 378 + { 379 + return (ocp_sys_info.opb_bus_freq + 500000) / 1000000; 380 + } 381 + 382 + /* BHs disabled */ 383 + static int emac_configure(struct ocp_enet_private *dev) 384 + { 385 + struct emac_regs *p = dev->emacp; 386 + struct net_device *ndev = dev->ndev; 387 + int gige; 388 + u32 r; 389 + 390 + DBG("%d: configure" NL, dev->def->index); 391 + 392 + if (emac_reset(dev) < 0) 393 + return -ETIMEDOUT; 394 + 395 + tah_reset(dev->tah_dev); 396 + 397 + /* Mode register */ 398 + r = EMAC_MR1_BASE(emac_opb_mhz()) | EMAC_MR1_VLE | EMAC_MR1_IST; 399 + if (dev->phy.duplex == DUPLEX_FULL) 400 + r |= EMAC_MR1_FDE; 401 + switch (dev->phy.speed) { 402 + case SPEED_1000: 403 + if (emac_phy_gpcs(dev->phy.mode)) { 404 + r |= EMAC_MR1_MF_1000GPCS | 405 + EMAC_MR1_MF_IPPA(dev->phy.address); 406 + 407 + /* Put some arbitrary OUI, Manuf & Rev IDs so we can 408 + * identify this GPCS PHY later. 409 + */ 410 + out_be32(&p->ipcr, 0xdeadbeef); 411 + } else 412 + r |= EMAC_MR1_MF_1000; 413 + r |= EMAC_MR1_RFS_16K; 414 + gige = 1; 415 + 416 + if (dev->ndev->mtu > ETH_DATA_LEN) 417 + r |= EMAC_MR1_JPSM; 418 + break; 419 + case SPEED_100: 420 + r |= EMAC_MR1_MF_100; 421 + /* Fall through */ 422 + default: 423 + r |= EMAC_MR1_RFS_4K; 424 + gige = 0; 425 + break; 426 + } 427 + 428 + if (dev->rgmii_dev) 429 + rgmii_set_speed(dev->rgmii_dev, dev->rgmii_input, 430 + dev->phy.speed); 431 + else 432 + zmii_set_speed(dev->zmii_dev, dev->zmii_input, dev->phy.speed); 433 + 434 + #if !defined(CONFIG_40x) 435 + /* on 40x erratum forces us to NOT use integrated flow control, 436 + * let's hope it works on 44x ;) 437 + */ 438 + if (dev->phy.duplex == DUPLEX_FULL) { 439 + if (dev->phy.pause) 440 + r |= EMAC_MR1_EIFC | EMAC_MR1_APP; 441 + else if (dev->phy.asym_pause) 442 + r |= EMAC_MR1_APP; 443 + } 444 + #endif 445 + out_be32(&p->mr1, r); 446 + 447 + /* Set individual MAC address */ 448 + out_be32(&p->iahr, (ndev->dev_addr[0] << 8) | ndev->dev_addr[1]); 449 + out_be32(&p->ialr, (ndev->dev_addr[2] << 24) | 450 + (ndev->dev_addr[3] << 16) | (ndev->dev_addr[4] << 8) | 451 + ndev->dev_addr[5]); 452 + 453 + /* VLAN Tag Protocol ID */ 454 + out_be32(&p->vtpid, 0x8100); 455 + 456 + /* Receive mode register */ 457 + r = emac_iff2rmr(ndev); 458 + if (r & EMAC_RMR_MAE) 459 + emac_hash_mc(dev); 460 + out_be32(&p->rmr, r); 461 + 462 + /* FIFOs thresholds */ 463 + r = EMAC_TMR1((EMAC_MAL_BURST_SIZE / EMAC_FIFO_ENTRY_SIZE) + 1, 464 + EMAC_TX_FIFO_SIZE / 2 / EMAC_FIFO_ENTRY_SIZE); 465 + out_be32(&p->tmr1, r); 466 + out_be32(&p->trtr, EMAC_TRTR(EMAC_TX_FIFO_SIZE / 2)); 467 + 468 + /* PAUSE frame is sent when RX FIFO reaches its high-water mark, 469 + there should be still enough space in FIFO to allow the our link 470 + partner time to process this frame and also time to send PAUSE 471 + frame itself. 472 + 473 + Here is the worst case scenario for the RX FIFO "headroom" 474 + (from "The Switch Book") (100Mbps, without preamble, inter-frame gap): 475 + 476 + 1) One maximum-length frame on TX 1522 bytes 477 + 2) One PAUSE frame time 64 bytes 478 + 3) PAUSE frame decode time allowance 64 bytes 479 + 4) One maximum-length frame on RX 1522 bytes 480 + 5) Round-trip propagation delay of the link (100Mb) 15 bytes 481 + ---------- 482 + 3187 bytes 483 + 484 + I chose to set high-water mark to RX_FIFO_SIZE / 4 (1024 bytes) 485 + low-water mark to RX_FIFO_SIZE / 8 (512 bytes) 486 + */ 487 + r = EMAC_RWMR(EMAC_RX_FIFO_SIZE(gige) / 8 / EMAC_FIFO_ENTRY_SIZE, 488 + EMAC_RX_FIFO_SIZE(gige) / 4 / EMAC_FIFO_ENTRY_SIZE); 489 + out_be32(&p->rwmr, r); 490 + 491 + /* Set PAUSE timer to the maximum */ 492 + out_be32(&p->ptr, 0xffff); 493 + 494 + /* IRQ sources */ 495 + out_be32(&p->iser, EMAC_ISR_TXPE | EMAC_ISR_RXPE | /* EMAC_ISR_TXUE | 496 + EMAC_ISR_RXOE | */ EMAC_ISR_OVR | EMAC_ISR_BP | EMAC_ISR_SE | 497 + EMAC_ISR_ALE | EMAC_ISR_BFCS | EMAC_ISR_PTLE | EMAC_ISR_ORE | 498 + EMAC_ISR_IRE | EMAC_ISR_TE); 499 + 500 + /* We need to take GPCS PHY out of isolate mode after EMAC reset */ 501 + if (emac_phy_gpcs(dev->phy.mode)) 502 + mii_reset_phy(&dev->phy); 503 + 504 + return 0; 505 + } 506 + 507 + /* BHs disabled */ 508 + static void emac_reinitialize(struct ocp_enet_private *dev) 509 + { 510 + DBG("%d: reinitialize" NL, dev->def->index); 511 + 512 + if (!emac_configure(dev)) { 513 + emac_tx_enable(dev); 514 + emac_rx_enable(dev); 515 + } 516 + } 517 + 518 + /* BHs disabled */ 519 + static void emac_full_tx_reset(struct net_device *ndev) 520 + { 521 + struct ocp_enet_private *dev = ndev->priv; 522 + struct ocp_func_emac_data *emacdata = dev->def->additions; 523 + 524 + DBG("%d: full_tx_reset" NL, dev->def->index); 525 + 526 + emac_tx_disable(dev); 527 + mal_disable_tx_channel(dev->mal, emacdata->mal_tx_chan); 528 + emac_clean_tx_ring(dev); 529 + dev->tx_cnt = dev->tx_slot = dev->ack_slot = 0; 530 + 531 + emac_configure(dev); 532 + 533 + mal_enable_tx_channel(dev->mal, emacdata->mal_tx_chan); 534 + emac_tx_enable(dev); 535 + emac_rx_enable(dev); 536 + 537 + netif_wake_queue(ndev); 538 + } 539 + 540 + static int __emac_mdio_read(struct ocp_enet_private *dev, u8 id, u8 reg) 541 + { 542 + struct emac_regs *p = dev->emacp; 543 + u32 r; 778 544 int n; 779 545 780 - spin_lock_irqsave(&fep->lock, flags); 781 - if ((n = emac_rx_clean(dev)) != fep->rx_slot) 782 - emac_rx_fill(dev, n); 783 - spin_unlock_irqrestore(&fep->lock, flags); 784 - } 546 + DBG2("%d: mdio_read(%02x,%02x)" NL, dev->def->index, id, reg); 785 547 786 - /* 787 - * This interrupt should never occurr, we don't program 788 - * the MAL for contiunous mode. 789 - */ 790 - static void emac_txde_dev(void *param, u32 chanmask) 791 - { 792 - struct net_device *dev = param; 793 - struct ocp_enet_private *fep = dev->priv; 548 + /* Enable proper MDIO port */ 549 + zmii_enable_mdio(dev->zmii_dev, dev->zmii_input); 794 550 795 - printk(KERN_WARNING "%s: transmit descriptor error\n", dev->name); 796 - 797 - emac_mac_dump(dev); 798 - emac_mal_dump(dev); 799 - 800 - /* Reenable the transmit channel */ 801 - mal_enable_tx_channels(fep->mal, fep->commac.tx_chan_mask); 802 - } 803 - 804 - /* 805 - * This interrupt should be very rare at best. This occurs when 806 - * the hardware has a problem with the receive descriptors. The manual 807 - * states that it occurs when the hardware cannot the receive descriptor 808 - * empty bit is not set. The recovery mechanism will be to 809 - * traverse through the descriptors, handle any that are marked to be 810 - * handled and reinitialize each along the way. At that point the driver 811 - * will be restarted. 812 - */ 813 - static void emac_rxde_dev(void *param, u32 chanmask) 814 - { 815 - struct net_device *dev = param; 816 - struct ocp_enet_private *fep = dev->priv; 817 - unsigned long flags; 818 - 819 - if (net_ratelimit()) { 820 - printk(KERN_WARNING "%s: receive descriptor error\n", 821 - fep->ndev->name); 822 - 823 - emac_mac_dump(dev); 824 - emac_mal_dump(dev); 825 - emac_desc_dump(dev); 551 + /* Wait for management interface to become idle */ 552 + n = 10; 553 + while (!(in_be32(&p->stacr) & EMAC_STACR_OC)) { 554 + udelay(1); 555 + if (!--n) 556 + goto to; 826 557 } 827 558 828 - /* Disable RX channel */ 829 - spin_lock_irqsave(&fep->lock, flags); 830 - mal_disable_rx_channels(fep->mal, fep->commac.rx_chan_mask); 559 + /* Issue read command */ 560 + out_be32(&p->stacr, 561 + EMAC_STACR_BASE(emac_opb_mhz()) | EMAC_STACR_STAC_READ | 562 + (reg & EMAC_STACR_PRA_MASK) 563 + | ((id & EMAC_STACR_PCDA_MASK) << EMAC_STACR_PCDA_SHIFT)); 831 564 832 - /* For now, charge the error against all emacs */ 833 - fep->stats.rx_errors++; 565 + /* Wait for read to complete */ 566 + n = 100; 567 + while (!((r = in_be32(&p->stacr)) & EMAC_STACR_OC)) { 568 + udelay(1); 569 + if (!--n) 570 + goto to; 571 + } 834 572 835 - /* so do we have any good packets still? */ 836 - emac_rx_clean(dev); 573 + if (unlikely(r & EMAC_STACR_PHYE)) { 574 + DBG("%d: mdio_read(%02x, %02x) failed" NL, dev->def->index, 575 + id, reg); 576 + return -EREMOTEIO; 577 + } 837 578 838 - /* When the interface is restarted it resets processing to the 839 - * first descriptor in the table. 579 + r = ((r >> EMAC_STACR_PHYD_SHIFT) & EMAC_STACR_PHYD_MASK); 580 + DBG2("%d: mdio_read -> %04x" NL, dev->def->index, r); 581 + return r; 582 + to: 583 + DBG("%d: MII management interface timeout (read)" NL, dev->def->index); 584 + return -ETIMEDOUT; 585 + } 586 + 587 + static void __emac_mdio_write(struct ocp_enet_private *dev, u8 id, u8 reg, 588 + u16 val) 589 + { 590 + struct emac_regs *p = dev->emacp; 591 + int n; 592 + 593 + DBG2("%d: mdio_write(%02x,%02x,%04x)" NL, dev->def->index, id, reg, 594 + val); 595 + 596 + /* Enable proper MDIO port */ 597 + zmii_enable_mdio(dev->zmii_dev, dev->zmii_input); 598 + 599 + /* Wait for management interface to be idle */ 600 + n = 10; 601 + while (!(in_be32(&p->stacr) & EMAC_STACR_OC)) { 602 + udelay(1); 603 + if (!--n) 604 + goto to; 605 + } 606 + 607 + /* Issue write command */ 608 + out_be32(&p->stacr, 609 + EMAC_STACR_BASE(emac_opb_mhz()) | EMAC_STACR_STAC_WRITE | 610 + (reg & EMAC_STACR_PRA_MASK) | 611 + ((id & EMAC_STACR_PCDA_MASK) << EMAC_STACR_PCDA_SHIFT) | 612 + (val << EMAC_STACR_PHYD_SHIFT)); 613 + 614 + /* Wait for write to complete */ 615 + n = 100; 616 + while (!(in_be32(&p->stacr) & EMAC_STACR_OC)) { 617 + udelay(1); 618 + if (!--n) 619 + goto to; 620 + } 621 + return; 622 + to: 623 + DBG("%d: MII management interface timeout (write)" NL, dev->def->index); 624 + } 625 + 626 + static int emac_mdio_read(struct net_device *ndev, int id, int reg) 627 + { 628 + struct ocp_enet_private *dev = ndev->priv; 629 + int res; 630 + 631 + local_bh_disable(); 632 + res = __emac_mdio_read(dev->mdio_dev ? dev->mdio_dev : dev, (u8) id, 633 + (u8) reg); 634 + local_bh_enable(); 635 + return res; 636 + } 637 + 638 + static void emac_mdio_write(struct net_device *ndev, int id, int reg, int val) 639 + { 640 + struct ocp_enet_private *dev = ndev->priv; 641 + 642 + local_bh_disable(); 643 + __emac_mdio_write(dev->mdio_dev ? dev->mdio_dev : dev, (u8) id, 644 + (u8) reg, (u16) val); 645 + local_bh_enable(); 646 + } 647 + 648 + /* BHs disabled */ 649 + static void emac_set_multicast_list(struct net_device *ndev) 650 + { 651 + struct ocp_enet_private *dev = ndev->priv; 652 + struct emac_regs *p = dev->emacp; 653 + u32 rmr = emac_iff2rmr(ndev); 654 + 655 + DBG("%d: multicast %08x" NL, dev->def->index, rmr); 656 + BUG_ON(!netif_running(dev->ndev)); 657 + 658 + /* I decided to relax register access rules here to avoid 659 + * full EMAC reset. 660 + * 661 + * There is a real problem with EMAC4 core if we use MWSW_001 bit 662 + * in MR1 register and do a full EMAC reset. 663 + * One TX BD status update is delayed and, after EMAC reset, it 664 + * never happens, resulting in TX hung (it'll be recovered by TX 665 + * timeout handler eventually, but this is just gross). 666 + * So we either have to do full TX reset or try to cheat here :) 667 + * 668 + * The only required change is to RX mode register, so I *think* all 669 + * we need is just to stop RX channel. This seems to work on all 670 + * tested SoCs. --ebs 840 671 */ 841 - 842 - fep->rx_slot = 0; 843 - emac_rx_fill(dev, 0); 844 - 845 - set_mal_dcrn(fep->mal, DCRN_MALRXEOBISR, fep->commac.rx_chan_mask); 846 - set_mal_dcrn(fep->mal, DCRN_MALRXDEIR, fep->commac.rx_chan_mask); 847 - 848 - /* Reenable the receive channels */ 849 - mal_enable_rx_channels(fep->mal, fep->commac.rx_chan_mask); 850 - spin_unlock_irqrestore(&fep->lock, flags); 672 + emac_rx_disable(dev); 673 + if (rmr & EMAC_RMR_MAE) 674 + emac_hash_mc(dev); 675 + out_be32(&p->rmr, rmr); 676 + emac_rx_enable(dev); 851 677 } 852 678 853 - static irqreturn_t 854 - emac_mac_irq(int irq, void *dev_instance, struct pt_regs *regs) 679 + /* BHs disabled */ 680 + static int emac_resize_rx_ring(struct ocp_enet_private *dev, int new_mtu) 855 681 { 856 - struct net_device *dev = dev_instance; 857 - struct ocp_enet_private *fep = dev->priv; 858 - emac_t *emacp = fep->emacp; 859 - unsigned long tmp_em0isr; 682 + struct ocp_func_emac_data *emacdata = dev->def->additions; 683 + int rx_sync_size = emac_rx_sync_size(new_mtu); 684 + int rx_skb_size = emac_rx_skb_size(new_mtu); 685 + int i, ret = 0; 860 686 861 - /* EMAC interrupt */ 862 - tmp_em0isr = in_be32(&emacp->em0isr); 863 - if (tmp_em0isr & (EMAC_ISR_TE0 | EMAC_ISR_TE1)) { 864 - /* This error is a hard transmit error - could retransmit */ 865 - fep->stats.tx_errors++; 687 + emac_rx_disable(dev); 688 + mal_disable_rx_channel(dev->mal, emacdata->mal_rx_chan); 866 689 867 - /* Reenable the transmit channel */ 868 - mal_enable_tx_channels(fep->mal, fep->commac.tx_chan_mask); 869 - 870 - } else { 871 - fep->stats.rx_errors++; 690 + if (dev->rx_sg_skb) { 691 + ++dev->estats.rx_dropped_resize; 692 + dev_kfree_skb(dev->rx_sg_skb); 693 + dev->rx_sg_skb = NULL; 872 694 } 873 695 874 - if (tmp_em0isr & EMAC_ISR_RP) 875 - fep->stats.rx_length_errors++; 876 - if (tmp_em0isr & EMAC_ISR_ALE) 877 - fep->stats.rx_frame_errors++; 878 - if (tmp_em0isr & EMAC_ISR_BFCS) 879 - fep->stats.rx_crc_errors++; 880 - if (tmp_em0isr & EMAC_ISR_PTLE) 881 - fep->stats.rx_length_errors++; 882 - if (tmp_em0isr & EMAC_ISR_ORE) 883 - fep->stats.rx_length_errors++; 884 - if (tmp_em0isr & EMAC_ISR_TE0) 885 - fep->stats.tx_aborted_errors++; 696 + /* Make a first pass over RX ring and mark BDs ready, dropping 697 + * non-processed packets on the way. We need this as a separate pass 698 + * to simplify error recovery in the case of allocation failure later. 699 + */ 700 + for (i = 0; i < NUM_RX_BUFF; ++i) { 701 + if (dev->rx_desc[i].ctrl & MAL_RX_CTRL_FIRST) 702 + ++dev->estats.rx_dropped_resize; 886 703 887 - emac_err_dump(dev, tmp_em0isr); 704 + dev->rx_desc[i].data_len = 0; 705 + dev->rx_desc[i].ctrl = MAL_RX_CTRL_EMPTY | 706 + (i == (NUM_RX_BUFF - 1) ? MAL_RX_CTRL_WRAP : 0); 707 + } 888 708 889 - out_be32(&emacp->em0isr, tmp_em0isr); 709 + /* Reallocate RX ring only if bigger skb buffers are required */ 710 + if (rx_skb_size <= dev->rx_skb_size) 711 + goto skip; 712 + 713 + /* Second pass, allocate new skbs */ 714 + for (i = 0; i < NUM_RX_BUFF; ++i) { 715 + struct sk_buff *skb = alloc_skb(rx_skb_size, GFP_ATOMIC); 716 + if (!skb) { 717 + ret = -ENOMEM; 718 + goto oom; 719 + } 720 + 721 + BUG_ON(!dev->rx_skb[i]); 722 + dev_kfree_skb(dev->rx_skb[i]); 723 + 724 + skb_reserve(skb, EMAC_RX_SKB_HEADROOM + 2); 725 + dev->rx_desc[i].data_ptr = 726 + dma_map_single(dev->ldev, skb->data - 2, rx_sync_size, 727 + DMA_FROM_DEVICE) + 2; 728 + dev->rx_skb[i] = skb; 729 + } 730 + skip: 731 + /* Check if we need to change "Jumbo" bit in MR1 */ 732 + if ((new_mtu > ETH_DATA_LEN) ^ (dev->ndev->mtu > ETH_DATA_LEN)) { 733 + /* This is to prevent starting RX channel in emac_rx_enable() */ 734 + dev->commac.rx_stopped = 1; 735 + 736 + dev->ndev->mtu = new_mtu; 737 + emac_full_tx_reset(dev->ndev); 738 + } 739 + 740 + mal_set_rcbs(dev->mal, emacdata->mal_rx_chan, emac_rx_size(new_mtu)); 741 + oom: 742 + /* Restart RX */ 743 + dev->commac.rx_stopped = dev->rx_slot = 0; 744 + mal_enable_rx_channel(dev->mal, emacdata->mal_rx_chan); 745 + emac_rx_enable(dev); 746 + 747 + return ret; 748 + } 749 + 750 + /* Process ctx, rtnl_lock semaphore */ 751 + static int emac_change_mtu(struct net_device *ndev, int new_mtu) 752 + { 753 + struct ocp_enet_private *dev = ndev->priv; 754 + int ret = 0; 755 + 756 + if (new_mtu < EMAC_MIN_MTU || new_mtu > EMAC_MAX_MTU) 757 + return -EINVAL; 758 + 759 + DBG("%d: change_mtu(%d)" NL, dev->def->index, new_mtu); 760 + 761 + local_bh_disable(); 762 + if (netif_running(ndev)) { 763 + /* Check if we really need to reinitalize RX ring */ 764 + if (emac_rx_skb_size(ndev->mtu) != emac_rx_skb_size(new_mtu)) 765 + ret = emac_resize_rx_ring(dev, new_mtu); 766 + } 767 + 768 + if (!ret) { 769 + ndev->mtu = new_mtu; 770 + dev->rx_skb_size = emac_rx_skb_size(new_mtu); 771 + dev->rx_sync_size = emac_rx_sync_size(new_mtu); 772 + } 773 + local_bh_enable(); 774 + 775 + return ret; 776 + } 777 + 778 + static void emac_clean_tx_ring(struct ocp_enet_private *dev) 779 + { 780 + int i; 781 + for (i = 0; i < NUM_TX_BUFF; ++i) { 782 + if (dev->tx_skb[i]) { 783 + dev_kfree_skb(dev->tx_skb[i]); 784 + dev->tx_skb[i] = NULL; 785 + if (dev->tx_desc[i].ctrl & MAL_TX_CTRL_READY) 786 + ++dev->estats.tx_dropped; 787 + } 788 + dev->tx_desc[i].ctrl = 0; 789 + dev->tx_desc[i].data_ptr = 0; 790 + } 791 + } 792 + 793 + static void emac_clean_rx_ring(struct ocp_enet_private *dev) 794 + { 795 + int i; 796 + for (i = 0; i < NUM_RX_BUFF; ++i) 797 + if (dev->rx_skb[i]) { 798 + dev->rx_desc[i].ctrl = 0; 799 + dev_kfree_skb(dev->rx_skb[i]); 800 + dev->rx_skb[i] = NULL; 801 + dev->rx_desc[i].data_ptr = 0; 802 + } 803 + 804 + if (dev->rx_sg_skb) { 805 + dev_kfree_skb(dev->rx_sg_skb); 806 + dev->rx_sg_skb = NULL; 807 + } 808 + } 809 + 810 + static inline int emac_alloc_rx_skb(struct ocp_enet_private *dev, int slot, 811 + int flags) 812 + { 813 + struct sk_buff *skb = alloc_skb(dev->rx_skb_size, flags); 814 + if (unlikely(!skb)) 815 + return -ENOMEM; 816 + 817 + dev->rx_skb[slot] = skb; 818 + dev->rx_desc[slot].data_len = 0; 819 + 820 + skb_reserve(skb, EMAC_RX_SKB_HEADROOM + 2); 821 + dev->rx_desc[slot].data_ptr = 822 + dma_map_single(dev->ldev, skb->data - 2, dev->rx_sync_size, 823 + DMA_FROM_DEVICE) + 2; 824 + barrier(); 825 + dev->rx_desc[slot].ctrl = MAL_RX_CTRL_EMPTY | 826 + (slot == (NUM_RX_BUFF - 1) ? MAL_RX_CTRL_WRAP : 0); 827 + 828 + return 0; 829 + } 830 + 831 + static void emac_print_link_status(struct ocp_enet_private *dev) 832 + { 833 + if (netif_carrier_ok(dev->ndev)) 834 + printk(KERN_INFO "%s: link is up, %d %s%s\n", 835 + dev->ndev->name, dev->phy.speed, 836 + dev->phy.duplex == DUPLEX_FULL ? "FDX" : "HDX", 837 + dev->phy.pause ? ", pause enabled" : 838 + dev->phy.asym_pause ? ", assymetric pause enabled" : ""); 839 + else 840 + printk(KERN_INFO "%s: link is down\n", dev->ndev->name); 841 + } 842 + 843 + /* Process ctx, rtnl_lock semaphore */ 844 + static int emac_open(struct net_device *ndev) 845 + { 846 + struct ocp_enet_private *dev = ndev->priv; 847 + struct ocp_func_emac_data *emacdata = dev->def->additions; 848 + int err, i; 849 + 850 + DBG("%d: open" NL, dev->def->index); 851 + 852 + /* Setup error IRQ handler */ 853 + err = request_irq(dev->def->irq, emac_irq, 0, "EMAC", dev); 854 + if (err) { 855 + printk(KERN_ERR "%s: failed to request IRQ %d\n", 856 + ndev->name, dev->def->irq); 857 + return err; 858 + } 859 + 860 + /* Allocate RX ring */ 861 + for (i = 0; i < NUM_RX_BUFF; ++i) 862 + if (emac_alloc_rx_skb(dev, i, GFP_KERNEL)) { 863 + printk(KERN_ERR "%s: failed to allocate RX ring\n", 864 + ndev->name); 865 + goto oom; 866 + } 867 + 868 + local_bh_disable(); 869 + dev->tx_cnt = dev->tx_slot = dev->ack_slot = dev->rx_slot = 870 + dev->commac.rx_stopped = 0; 871 + dev->rx_sg_skb = NULL; 872 + 873 + if (dev->phy.address >= 0) { 874 + int link_poll_interval; 875 + if (dev->phy.def->ops->poll_link(&dev->phy)) { 876 + dev->phy.def->ops->read_link(&dev->phy); 877 + EMAC_RX_CLK_DEFAULT(dev->def->index); 878 + netif_carrier_on(dev->ndev); 879 + link_poll_interval = PHY_POLL_LINK_ON; 880 + } else { 881 + EMAC_RX_CLK_TX(dev->def->index); 882 + netif_carrier_off(dev->ndev); 883 + link_poll_interval = PHY_POLL_LINK_OFF; 884 + } 885 + mod_timer(&dev->link_timer, jiffies + link_poll_interval); 886 + emac_print_link_status(dev); 887 + } else 888 + netif_carrier_on(dev->ndev); 889 + 890 + emac_configure(dev); 891 + mal_poll_add(dev->mal, &dev->commac); 892 + mal_enable_tx_channel(dev->mal, emacdata->mal_tx_chan); 893 + mal_set_rcbs(dev->mal, emacdata->mal_rx_chan, emac_rx_size(ndev->mtu)); 894 + mal_enable_rx_channel(dev->mal, emacdata->mal_rx_chan); 895 + emac_tx_enable(dev); 896 + emac_rx_enable(dev); 897 + netif_start_queue(ndev); 898 + local_bh_enable(); 899 + 900 + return 0; 901 + oom: 902 + emac_clean_rx_ring(dev); 903 + free_irq(dev->def->irq, dev); 904 + return -ENOMEM; 905 + } 906 + 907 + /* BHs disabled */ 908 + static int emac_link_differs(struct ocp_enet_private *dev) 909 + { 910 + u32 r = in_be32(&dev->emacp->mr1); 911 + 912 + int duplex = r & EMAC_MR1_FDE ? DUPLEX_FULL : DUPLEX_HALF; 913 + int speed, pause, asym_pause; 914 + 915 + if (r & (EMAC_MR1_MF_1000 | EMAC_MR1_MF_1000GPCS)) 916 + speed = SPEED_1000; 917 + else if (r & EMAC_MR1_MF_100) 918 + speed = SPEED_100; 919 + else 920 + speed = SPEED_10; 921 + 922 + switch (r & (EMAC_MR1_EIFC | EMAC_MR1_APP)) { 923 + case (EMAC_MR1_EIFC | EMAC_MR1_APP): 924 + pause = 1; 925 + asym_pause = 0; 926 + break; 927 + case EMAC_MR1_APP: 928 + pause = 0; 929 + asym_pause = 1; 930 + break; 931 + default: 932 + pause = asym_pause = 0; 933 + } 934 + return speed != dev->phy.speed || duplex != dev->phy.duplex || 935 + pause != dev->phy.pause || asym_pause != dev->phy.asym_pause; 936 + } 937 + 938 + /* BHs disabled */ 939 + static void emac_link_timer(unsigned long data) 940 + { 941 + struct ocp_enet_private *dev = (struct ocp_enet_private *)data; 942 + int link_poll_interval; 943 + 944 + DBG2("%d: link timer" NL, dev->def->index); 945 + 946 + if (dev->phy.def->ops->poll_link(&dev->phy)) { 947 + if (!netif_carrier_ok(dev->ndev)) { 948 + EMAC_RX_CLK_DEFAULT(dev->def->index); 949 + 950 + /* Get new link parameters */ 951 + dev->phy.def->ops->read_link(&dev->phy); 952 + 953 + if (dev->tah_dev || emac_link_differs(dev)) 954 + emac_full_tx_reset(dev->ndev); 955 + 956 + netif_carrier_on(dev->ndev); 957 + emac_print_link_status(dev); 958 + } 959 + link_poll_interval = PHY_POLL_LINK_ON; 960 + } else { 961 + if (netif_carrier_ok(dev->ndev)) { 962 + EMAC_RX_CLK_TX(dev->def->index); 963 + #if defined(CONFIG_IBM_EMAC_PHY_RX_CLK_FIX) 964 + emac_reinitialize(dev); 965 + #endif 966 + netif_carrier_off(dev->ndev); 967 + emac_print_link_status(dev); 968 + } 969 + 970 + /* Retry reset if the previous attempt failed. 971 + * This is needed mostly for CONFIG_IBM_EMAC_PHY_RX_CLK_FIX 972 + * case, but I left it here because it shouldn't trigger for 973 + * sane PHYs anyway. 974 + */ 975 + if (unlikely(dev->reset_failed)) 976 + emac_reinitialize(dev); 977 + 978 + link_poll_interval = PHY_POLL_LINK_OFF; 979 + } 980 + mod_timer(&dev->link_timer, jiffies + link_poll_interval); 981 + } 982 + 983 + /* BHs disabled */ 984 + static void emac_force_link_update(struct ocp_enet_private *dev) 985 + { 986 + netif_carrier_off(dev->ndev); 987 + if (timer_pending(&dev->link_timer)) 988 + mod_timer(&dev->link_timer, jiffies + PHY_POLL_LINK_OFF); 989 + } 990 + 991 + /* Process ctx, rtnl_lock semaphore */ 992 + static int emac_close(struct net_device *ndev) 993 + { 994 + struct ocp_enet_private *dev = ndev->priv; 995 + struct ocp_func_emac_data *emacdata = dev->def->additions; 996 + 997 + DBG("%d: close" NL, dev->def->index); 998 + 999 + local_bh_disable(); 1000 + 1001 + if (dev->phy.address >= 0) 1002 + del_timer_sync(&dev->link_timer); 1003 + 1004 + netif_stop_queue(ndev); 1005 + emac_rx_disable(dev); 1006 + emac_tx_disable(dev); 1007 + mal_disable_rx_channel(dev->mal, emacdata->mal_rx_chan); 1008 + mal_disable_tx_channel(dev->mal, emacdata->mal_tx_chan); 1009 + mal_poll_del(dev->mal, &dev->commac); 1010 + local_bh_enable(); 1011 + 1012 + emac_clean_tx_ring(dev); 1013 + emac_clean_rx_ring(dev); 1014 + free_irq(dev->def->irq, dev); 1015 + 1016 + return 0; 1017 + } 1018 + 1019 + static inline u16 emac_tx_csum(struct ocp_enet_private *dev, 1020 + struct sk_buff *skb) 1021 + { 1022 + #if defined(CONFIG_IBM_EMAC_TAH) 1023 + if (skb->ip_summed == CHECKSUM_HW) { 1024 + ++dev->stats.tx_packets_csum; 1025 + return EMAC_TX_CTRL_TAH_CSUM; 1026 + } 1027 + #endif 1028 + return 0; 1029 + } 1030 + 1031 + static inline int emac_xmit_finish(struct ocp_enet_private *dev, int len) 1032 + { 1033 + struct emac_regs *p = dev->emacp; 1034 + struct net_device *ndev = dev->ndev; 1035 + 1036 + /* Send the packet out */ 1037 + out_be32(&p->tmr0, EMAC_TMR0_XMIT); 1038 + 1039 + if (unlikely(++dev->tx_cnt == NUM_TX_BUFF)) { 1040 + netif_stop_queue(ndev); 1041 + DBG2("%d: stopped TX queue" NL, dev->def->index); 1042 + } 1043 + 1044 + ndev->trans_start = jiffies; 1045 + ++dev->stats.tx_packets; 1046 + dev->stats.tx_bytes += len; 1047 + 1048 + return 0; 1049 + } 1050 + 1051 + /* BHs disabled */ 1052 + static int emac_start_xmit(struct sk_buff *skb, struct net_device *ndev) 1053 + { 1054 + struct ocp_enet_private *dev = ndev->priv; 1055 + unsigned int len = skb->len; 1056 + int slot; 1057 + 1058 + u16 ctrl = EMAC_TX_CTRL_GFCS | EMAC_TX_CTRL_GP | MAL_TX_CTRL_READY | 1059 + MAL_TX_CTRL_LAST | emac_tx_csum(dev, skb); 1060 + 1061 + slot = dev->tx_slot++; 1062 + if (dev->tx_slot == NUM_TX_BUFF) { 1063 + dev->tx_slot = 0; 1064 + ctrl |= MAL_TX_CTRL_WRAP; 1065 + } 1066 + 1067 + DBG2("%d: xmit(%u) %d" NL, dev->def->index, len, slot); 1068 + 1069 + dev->tx_skb[slot] = skb; 1070 + dev->tx_desc[slot].data_ptr = dma_map_single(dev->ldev, skb->data, len, 1071 + DMA_TO_DEVICE); 1072 + dev->tx_desc[slot].data_len = (u16) len; 1073 + barrier(); 1074 + dev->tx_desc[slot].ctrl = ctrl; 1075 + 1076 + return emac_xmit_finish(dev, len); 1077 + } 1078 + 1079 + #if defined(CONFIG_IBM_EMAC_TAH) 1080 + static inline int emac_xmit_split(struct ocp_enet_private *dev, int slot, 1081 + u32 pd, int len, int last, u16 base_ctrl) 1082 + { 1083 + while (1) { 1084 + u16 ctrl = base_ctrl; 1085 + int chunk = min(len, MAL_MAX_TX_SIZE); 1086 + len -= chunk; 1087 + 1088 + slot = (slot + 1) % NUM_TX_BUFF; 1089 + 1090 + if (last && !len) 1091 + ctrl |= MAL_TX_CTRL_LAST; 1092 + if (slot == NUM_TX_BUFF - 1) 1093 + ctrl |= MAL_TX_CTRL_WRAP; 1094 + 1095 + dev->tx_skb[slot] = NULL; 1096 + dev->tx_desc[slot].data_ptr = pd; 1097 + dev->tx_desc[slot].data_len = (u16) chunk; 1098 + dev->tx_desc[slot].ctrl = ctrl; 1099 + ++dev->tx_cnt; 1100 + 1101 + if (!len) 1102 + break; 1103 + 1104 + pd += chunk; 1105 + } 1106 + return slot; 1107 + } 1108 + 1109 + /* BHs disabled (SG version for TAH equipped EMACs) */ 1110 + static int emac_start_xmit_sg(struct sk_buff *skb, struct net_device *ndev) 1111 + { 1112 + struct ocp_enet_private *dev = ndev->priv; 1113 + int nr_frags = skb_shinfo(skb)->nr_frags; 1114 + int len = skb->len, chunk; 1115 + int slot, i; 1116 + u16 ctrl; 1117 + u32 pd; 1118 + 1119 + /* This is common "fast" path */ 1120 + if (likely(!nr_frags && len <= MAL_MAX_TX_SIZE)) 1121 + return emac_start_xmit(skb, ndev); 1122 + 1123 + len -= skb->data_len; 1124 + 1125 + /* Note, this is only an *estimation*, we can still run out of empty 1126 + * slots because of the additional fragmentation into 1127 + * MAL_MAX_TX_SIZE-sized chunks 1128 + */ 1129 + if (unlikely(dev->tx_cnt + nr_frags + mal_tx_chunks(len) > NUM_TX_BUFF)) 1130 + goto stop_queue; 1131 + 1132 + ctrl = EMAC_TX_CTRL_GFCS | EMAC_TX_CTRL_GP | MAL_TX_CTRL_READY | 1133 + emac_tx_csum(dev, skb); 1134 + slot = dev->tx_slot; 1135 + 1136 + /* skb data */ 1137 + dev->tx_skb[slot] = NULL; 1138 + chunk = min(len, MAL_MAX_TX_SIZE); 1139 + dev->tx_desc[slot].data_ptr = pd = 1140 + dma_map_single(dev->ldev, skb->data, len, DMA_TO_DEVICE); 1141 + dev->tx_desc[slot].data_len = (u16) chunk; 1142 + len -= chunk; 1143 + if (unlikely(len)) 1144 + slot = emac_xmit_split(dev, slot, pd + chunk, len, !nr_frags, 1145 + ctrl); 1146 + /* skb fragments */ 1147 + for (i = 0; i < nr_frags; ++i) { 1148 + struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[i]; 1149 + len = frag->size; 1150 + 1151 + if (unlikely(dev->tx_cnt + mal_tx_chunks(len) >= NUM_TX_BUFF)) 1152 + goto undo_frame; 1153 + 1154 + pd = dma_map_page(dev->ldev, frag->page, frag->page_offset, len, 1155 + DMA_TO_DEVICE); 1156 + 1157 + slot = emac_xmit_split(dev, slot, pd, len, i == nr_frags - 1, 1158 + ctrl); 1159 + } 1160 + 1161 + DBG2("%d: xmit_sg(%u) %d - %d" NL, dev->def->index, skb->len, 1162 + dev->tx_slot, slot); 1163 + 1164 + /* Attach skb to the last slot so we don't release it too early */ 1165 + dev->tx_skb[slot] = skb; 1166 + 1167 + /* Send the packet out */ 1168 + if (dev->tx_slot == NUM_TX_BUFF - 1) 1169 + ctrl |= MAL_TX_CTRL_WRAP; 1170 + barrier(); 1171 + dev->tx_desc[dev->tx_slot].ctrl = ctrl; 1172 + dev->tx_slot = (slot + 1) % NUM_TX_BUFF; 1173 + 1174 + return emac_xmit_finish(dev, skb->len); 1175 + 1176 + undo_frame: 1177 + /* Well, too bad. Our previous estimation was overly optimistic. 1178 + * Undo everything. 1179 + */ 1180 + while (slot != dev->tx_slot) { 1181 + dev->tx_desc[slot].ctrl = 0; 1182 + --dev->tx_cnt; 1183 + if (--slot < 0) 1184 + slot = NUM_TX_BUFF - 1; 1185 + } 1186 + ++dev->estats.tx_undo; 1187 + 1188 + stop_queue: 1189 + netif_stop_queue(ndev); 1190 + DBG2("%d: stopped TX queue" NL, dev->def->index); 1191 + return 1; 1192 + } 1193 + #else 1194 + # define emac_start_xmit_sg emac_start_xmit 1195 + #endif /* !defined(CONFIG_IBM_EMAC_TAH) */ 1196 + 1197 + /* BHs disabled */ 1198 + static void emac_parse_tx_error(struct ocp_enet_private *dev, u16 ctrl) 1199 + { 1200 + struct ibm_emac_error_stats *st = &dev->estats; 1201 + DBG("%d: BD TX error %04x" NL, dev->def->index, ctrl); 1202 + 1203 + ++st->tx_bd_errors; 1204 + if (ctrl & EMAC_TX_ST_BFCS) 1205 + ++st->tx_bd_bad_fcs; 1206 + if (ctrl & EMAC_TX_ST_LCS) 1207 + ++st->tx_bd_carrier_loss; 1208 + if (ctrl & EMAC_TX_ST_ED) 1209 + ++st->tx_bd_excessive_deferral; 1210 + if (ctrl & EMAC_TX_ST_EC) 1211 + ++st->tx_bd_excessive_collisions; 1212 + if (ctrl & EMAC_TX_ST_LC) 1213 + ++st->tx_bd_late_collision; 1214 + if (ctrl & EMAC_TX_ST_MC) 1215 + ++st->tx_bd_multple_collisions; 1216 + if (ctrl & EMAC_TX_ST_SC) 1217 + ++st->tx_bd_single_collision; 1218 + if (ctrl & EMAC_TX_ST_UR) 1219 + ++st->tx_bd_underrun; 1220 + if (ctrl & EMAC_TX_ST_SQE) 1221 + ++st->tx_bd_sqe; 1222 + } 1223 + 1224 + static void emac_poll_tx(void *param) 1225 + { 1226 + struct ocp_enet_private *dev = param; 1227 + DBG2("%d: poll_tx, %d %d" NL, dev->def->index, dev->tx_cnt, 1228 + dev->ack_slot); 1229 + 1230 + if (dev->tx_cnt) { 1231 + u16 ctrl; 1232 + int slot = dev->ack_slot, n = 0; 1233 + again: 1234 + ctrl = dev->tx_desc[slot].ctrl; 1235 + if (!(ctrl & MAL_TX_CTRL_READY)) { 1236 + struct sk_buff *skb = dev->tx_skb[slot]; 1237 + ++n; 1238 + 1239 + if (skb) { 1240 + dev_kfree_skb(skb); 1241 + dev->tx_skb[slot] = NULL; 1242 + } 1243 + slot = (slot + 1) % NUM_TX_BUFF; 1244 + 1245 + if (unlikely(EMAC_IS_BAD_TX(ctrl))) 1246 + emac_parse_tx_error(dev, ctrl); 1247 + 1248 + if (--dev->tx_cnt) 1249 + goto again; 1250 + } 1251 + if (n) { 1252 + dev->ack_slot = slot; 1253 + if (netif_queue_stopped(dev->ndev) && 1254 + dev->tx_cnt < EMAC_TX_WAKEUP_THRESH) 1255 + netif_wake_queue(dev->ndev); 1256 + 1257 + DBG2("%d: tx %d pkts" NL, dev->def->index, n); 1258 + } 1259 + } 1260 + } 1261 + 1262 + static inline void emac_recycle_rx_skb(struct ocp_enet_private *dev, int slot, 1263 + int len) 1264 + { 1265 + struct sk_buff *skb = dev->rx_skb[slot]; 1266 + DBG2("%d: recycle %d %d" NL, dev->def->index, slot, len); 1267 + 1268 + if (len) 1269 + dma_map_single(dev->ldev, skb->data - 2, 1270 + EMAC_DMA_ALIGN(len + 2), DMA_FROM_DEVICE); 1271 + 1272 + dev->rx_desc[slot].data_len = 0; 1273 + barrier(); 1274 + dev->rx_desc[slot].ctrl = MAL_RX_CTRL_EMPTY | 1275 + (slot == (NUM_RX_BUFF - 1) ? MAL_RX_CTRL_WRAP : 0); 1276 + } 1277 + 1278 + static void emac_parse_rx_error(struct ocp_enet_private *dev, u16 ctrl) 1279 + { 1280 + struct ibm_emac_error_stats *st = &dev->estats; 1281 + DBG("%d: BD RX error %04x" NL, dev->def->index, ctrl); 1282 + 1283 + ++st->rx_bd_errors; 1284 + if (ctrl & EMAC_RX_ST_OE) 1285 + ++st->rx_bd_overrun; 1286 + if (ctrl & EMAC_RX_ST_BP) 1287 + ++st->rx_bd_bad_packet; 1288 + if (ctrl & EMAC_RX_ST_RP) 1289 + ++st->rx_bd_runt_packet; 1290 + if (ctrl & EMAC_RX_ST_SE) 1291 + ++st->rx_bd_short_event; 1292 + if (ctrl & EMAC_RX_ST_AE) 1293 + ++st->rx_bd_alignment_error; 1294 + if (ctrl & EMAC_RX_ST_BFCS) 1295 + ++st->rx_bd_bad_fcs; 1296 + if (ctrl & EMAC_RX_ST_PTL) 1297 + ++st->rx_bd_packet_too_long; 1298 + if (ctrl & EMAC_RX_ST_ORE) 1299 + ++st->rx_bd_out_of_range; 1300 + if (ctrl & EMAC_RX_ST_IRE) 1301 + ++st->rx_bd_in_range; 1302 + } 1303 + 1304 + static inline void emac_rx_csum(struct ocp_enet_private *dev, 1305 + struct sk_buff *skb, u16 ctrl) 1306 + { 1307 + #if defined(CONFIG_IBM_EMAC_TAH) 1308 + if (!ctrl && dev->tah_dev) { 1309 + skb->ip_summed = CHECKSUM_UNNECESSARY; 1310 + ++dev->stats.rx_packets_csum; 1311 + } 1312 + #endif 1313 + } 1314 + 1315 + static inline int emac_rx_sg_append(struct ocp_enet_private *dev, int slot) 1316 + { 1317 + if (likely(dev->rx_sg_skb != NULL)) { 1318 + int len = dev->rx_desc[slot].data_len; 1319 + int tot_len = dev->rx_sg_skb->len + len; 1320 + 1321 + if (unlikely(tot_len + 2 > dev->rx_skb_size)) { 1322 + ++dev->estats.rx_dropped_mtu; 1323 + dev_kfree_skb(dev->rx_sg_skb); 1324 + dev->rx_sg_skb = NULL; 1325 + } else { 1326 + cacheable_memcpy(dev->rx_sg_skb->tail, 1327 + dev->rx_skb[slot]->data, len); 1328 + skb_put(dev->rx_sg_skb, len); 1329 + emac_recycle_rx_skb(dev, slot, len); 1330 + return 0; 1331 + } 1332 + } 1333 + emac_recycle_rx_skb(dev, slot, 0); 1334 + return -1; 1335 + } 1336 + 1337 + /* BHs disabled */ 1338 + static int emac_poll_rx(void *param, int budget) 1339 + { 1340 + struct ocp_enet_private *dev = param; 1341 + int slot = dev->rx_slot, received = 0; 1342 + 1343 + DBG2("%d: poll_rx(%d)" NL, dev->def->index, budget); 1344 + 1345 + again: 1346 + while (budget > 0) { 1347 + int len; 1348 + struct sk_buff *skb; 1349 + u16 ctrl = dev->rx_desc[slot].ctrl; 1350 + 1351 + if (ctrl & MAL_RX_CTRL_EMPTY) 1352 + break; 1353 + 1354 + skb = dev->rx_skb[slot]; 1355 + barrier(); 1356 + len = dev->rx_desc[slot].data_len; 1357 + 1358 + if (unlikely(!MAL_IS_SINGLE_RX(ctrl))) 1359 + goto sg; 1360 + 1361 + ctrl &= EMAC_BAD_RX_MASK; 1362 + if (unlikely(ctrl && ctrl != EMAC_RX_TAH_BAD_CSUM)) { 1363 + emac_parse_rx_error(dev, ctrl); 1364 + ++dev->estats.rx_dropped_error; 1365 + emac_recycle_rx_skb(dev, slot, 0); 1366 + len = 0; 1367 + goto next; 1368 + } 1369 + 1370 + if (len && len < EMAC_RX_COPY_THRESH) { 1371 + struct sk_buff *copy_skb = 1372 + alloc_skb(len + EMAC_RX_SKB_HEADROOM + 2, GFP_ATOMIC); 1373 + if (unlikely(!copy_skb)) 1374 + goto oom; 1375 + 1376 + skb_reserve(copy_skb, EMAC_RX_SKB_HEADROOM + 2); 1377 + cacheable_memcpy(copy_skb->data - 2, skb->data - 2, 1378 + len + 2); 1379 + emac_recycle_rx_skb(dev, slot, len); 1380 + skb = copy_skb; 1381 + } else if (unlikely(emac_alloc_rx_skb(dev, slot, GFP_ATOMIC))) 1382 + goto oom; 1383 + 1384 + skb_put(skb, len); 1385 + push_packet: 1386 + skb->dev = dev->ndev; 1387 + skb->protocol = eth_type_trans(skb, dev->ndev); 1388 + emac_rx_csum(dev, skb, ctrl); 1389 + 1390 + if (unlikely(netif_receive_skb(skb) == NET_RX_DROP)) 1391 + ++dev->estats.rx_dropped_stack; 1392 + next: 1393 + ++dev->stats.rx_packets; 1394 + skip: 1395 + dev->stats.rx_bytes += len; 1396 + slot = (slot + 1) % NUM_RX_BUFF; 1397 + --budget; 1398 + ++received; 1399 + continue; 1400 + sg: 1401 + if (ctrl & MAL_RX_CTRL_FIRST) { 1402 + BUG_ON(dev->rx_sg_skb); 1403 + if (unlikely(emac_alloc_rx_skb(dev, slot, GFP_ATOMIC))) { 1404 + DBG("%d: rx OOM %d" NL, dev->def->index, slot); 1405 + ++dev->estats.rx_dropped_oom; 1406 + emac_recycle_rx_skb(dev, slot, 0); 1407 + } else { 1408 + dev->rx_sg_skb = skb; 1409 + skb_put(skb, len); 1410 + } 1411 + } else if (!emac_rx_sg_append(dev, slot) && 1412 + (ctrl & MAL_RX_CTRL_LAST)) { 1413 + 1414 + skb = dev->rx_sg_skb; 1415 + dev->rx_sg_skb = NULL; 1416 + 1417 + ctrl &= EMAC_BAD_RX_MASK; 1418 + if (unlikely(ctrl && ctrl != EMAC_RX_TAH_BAD_CSUM)) { 1419 + emac_parse_rx_error(dev, ctrl); 1420 + ++dev->estats.rx_dropped_error; 1421 + dev_kfree_skb(skb); 1422 + len = 0; 1423 + } else 1424 + goto push_packet; 1425 + } 1426 + goto skip; 1427 + oom: 1428 + DBG("%d: rx OOM %d" NL, dev->def->index, slot); 1429 + /* Drop the packet and recycle skb */ 1430 + ++dev->estats.rx_dropped_oom; 1431 + emac_recycle_rx_skb(dev, slot, 0); 1432 + goto next; 1433 + } 1434 + 1435 + if (received) { 1436 + DBG2("%d: rx %d BDs" NL, dev->def->index, received); 1437 + dev->rx_slot = slot; 1438 + } 1439 + 1440 + if (unlikely(budget && dev->commac.rx_stopped)) { 1441 + struct ocp_func_emac_data *emacdata = dev->def->additions; 1442 + 1443 + barrier(); 1444 + if (!(dev->rx_desc[slot].ctrl & MAL_RX_CTRL_EMPTY)) { 1445 + DBG2("%d: rx restart" NL, dev->def->index); 1446 + received = 0; 1447 + goto again; 1448 + } 1449 + 1450 + if (dev->rx_sg_skb) { 1451 + DBG2("%d: dropping partial rx packet" NL, 1452 + dev->def->index); 1453 + ++dev->estats.rx_dropped_error; 1454 + dev_kfree_skb(dev->rx_sg_skb); 1455 + dev->rx_sg_skb = NULL; 1456 + } 1457 + 1458 + dev->commac.rx_stopped = 0; 1459 + mal_enable_rx_channel(dev->mal, emacdata->mal_rx_chan); 1460 + emac_rx_enable(dev); 1461 + dev->rx_slot = 0; 1462 + } 1463 + return received; 1464 + } 1465 + 1466 + /* BHs disabled */ 1467 + static int emac_peek_rx(void *param) 1468 + { 1469 + struct ocp_enet_private *dev = param; 1470 + return !(dev->rx_desc[dev->rx_slot].ctrl & MAL_RX_CTRL_EMPTY); 1471 + } 1472 + 1473 + /* BHs disabled */ 1474 + static int emac_peek_rx_sg(void *param) 1475 + { 1476 + struct ocp_enet_private *dev = param; 1477 + int slot = dev->rx_slot; 1478 + while (1) { 1479 + u16 ctrl = dev->rx_desc[slot].ctrl; 1480 + if (ctrl & MAL_RX_CTRL_EMPTY) 1481 + return 0; 1482 + else if (ctrl & MAL_RX_CTRL_LAST) 1483 + return 1; 1484 + 1485 + slot = (slot + 1) % NUM_RX_BUFF; 1486 + 1487 + /* I'm just being paranoid here :) */ 1488 + if (unlikely(slot == dev->rx_slot)) 1489 + return 0; 1490 + } 1491 + } 1492 + 1493 + /* Hard IRQ */ 1494 + static void emac_rxde(void *param) 1495 + { 1496 + struct ocp_enet_private *dev = param; 1497 + ++dev->estats.rx_stopped; 1498 + emac_rx_disable_async(dev); 1499 + } 1500 + 1501 + /* Hard IRQ */ 1502 + static irqreturn_t emac_irq(int irq, void *dev_instance, struct pt_regs *regs) 1503 + { 1504 + struct ocp_enet_private *dev = dev_instance; 1505 + struct emac_regs *p = dev->emacp; 1506 + struct ibm_emac_error_stats *st = &dev->estats; 1507 + 1508 + u32 isr = in_be32(&p->isr); 1509 + out_be32(&p->isr, isr); 1510 + 1511 + DBG("%d: isr = %08x" NL, dev->def->index, isr); 1512 + 1513 + if (isr & EMAC_ISR_TXPE) 1514 + ++st->tx_parity; 1515 + if (isr & EMAC_ISR_RXPE) 1516 + ++st->rx_parity; 1517 + if (isr & EMAC_ISR_TXUE) 1518 + ++st->tx_underrun; 1519 + if (isr & EMAC_ISR_RXOE) 1520 + ++st->rx_fifo_overrun; 1521 + if (isr & EMAC_ISR_OVR) 1522 + ++st->rx_overrun; 1523 + if (isr & EMAC_ISR_BP) 1524 + ++st->rx_bad_packet; 1525 + if (isr & EMAC_ISR_RP) 1526 + ++st->rx_runt_packet; 1527 + if (isr & EMAC_ISR_SE) 1528 + ++st->rx_short_event; 1529 + if (isr & EMAC_ISR_ALE) 1530 + ++st->rx_alignment_error; 1531 + if (isr & EMAC_ISR_BFCS) 1532 + ++st->rx_bad_fcs; 1533 + if (isr & EMAC_ISR_PTLE) 1534 + ++st->rx_packet_too_long; 1535 + if (isr & EMAC_ISR_ORE) 1536 + ++st->rx_out_of_range; 1537 + if (isr & EMAC_ISR_IRE) 1538 + ++st->rx_in_range; 1539 + if (isr & EMAC_ISR_SQE) 1540 + ++st->tx_sqe; 1541 + if (isr & EMAC_ISR_TE) 1542 + ++st->tx_errors; 890 1543 891 1544 return IRQ_HANDLED; 892 1545 } 893 1546 894 - static int emac_start_xmit(struct sk_buff *skb, struct net_device *dev) 1547 + static struct net_device_stats *emac_stats(struct net_device *ndev) 895 1548 { 896 - unsigned short ctrl; 897 - unsigned long flags; 898 - struct ocp_enet_private *fep = dev->priv; 899 - emac_t *emacp = fep->emacp; 900 - int len = skb->len; 901 - unsigned int offset = 0, size, f, tx_slot_first; 902 - unsigned int nr_frags = skb_shinfo(skb)->nr_frags; 1549 + struct ocp_enet_private *dev = ndev->priv; 1550 + struct ibm_emac_stats *st = &dev->stats; 1551 + struct ibm_emac_error_stats *est = &dev->estats; 1552 + struct net_device_stats *nst = &dev->nstats; 903 1553 904 - spin_lock_irqsave(&fep->lock, flags); 1554 + DBG2("%d: stats" NL, dev->def->index); 905 1555 906 - len -= skb->data_len; 1556 + /* Compute "legacy" statistics */ 1557 + local_irq_disable(); 1558 + nst->rx_packets = (unsigned long)st->rx_packets; 1559 + nst->rx_bytes = (unsigned long)st->rx_bytes; 1560 + nst->tx_packets = (unsigned long)st->tx_packets; 1561 + nst->tx_bytes = (unsigned long)st->tx_bytes; 1562 + nst->rx_dropped = (unsigned long)(est->rx_dropped_oom + 1563 + est->rx_dropped_error + 1564 + est->rx_dropped_resize + 1565 + est->rx_dropped_mtu); 1566 + nst->tx_dropped = (unsigned long)est->tx_dropped; 907 1567 908 - if ((fep->tx_cnt + nr_frags + len / DESC_BUF_SIZE + 1) > NUM_TX_BUFF) { 909 - PKT_DEBUG(("emac_start_xmit() stopping queue\n")); 910 - netif_stop_queue(dev); 911 - spin_unlock_irqrestore(&fep->lock, flags); 912 - return -EBUSY; 913 - } 1568 + nst->rx_errors = (unsigned long)est->rx_bd_errors; 1569 + nst->rx_fifo_errors = (unsigned long)(est->rx_bd_overrun + 1570 + est->rx_fifo_overrun + 1571 + est->rx_overrun); 1572 + nst->rx_frame_errors = (unsigned long)(est->rx_bd_alignment_error + 1573 + est->rx_alignment_error); 1574 + nst->rx_crc_errors = (unsigned long)(est->rx_bd_bad_fcs + 1575 + est->rx_bad_fcs); 1576 + nst->rx_length_errors = (unsigned long)(est->rx_bd_runt_packet + 1577 + est->rx_bd_short_event + 1578 + est->rx_bd_packet_too_long + 1579 + est->rx_bd_out_of_range + 1580 + est->rx_bd_in_range + 1581 + est->rx_runt_packet + 1582 + est->rx_short_event + 1583 + est->rx_packet_too_long + 1584 + est->rx_out_of_range + 1585 + est->rx_in_range); 914 1586 915 - tx_slot_first = fep->tx_slot; 916 - 917 - while (len) { 918 - size = min(len, DESC_BUF_SIZE); 919 - 920 - fep->tx_desc[fep->tx_slot].data_len = (short)size; 921 - fep->tx_desc[fep->tx_slot].data_ptr = 922 - (unsigned char *)dma_map_single(&fep->ocpdev->dev, 923 - (void *)((unsigned int)skb-> 924 - data + offset), 925 - size, DMA_TO_DEVICE); 926 - 927 - ctrl = EMAC_TX_CTRL_DFLT; 928 - if (fep->tx_slot != tx_slot_first) 929 - ctrl |= MAL_TX_CTRL_READY; 930 - if ((NUM_TX_BUFF - 1) == fep->tx_slot) 931 - ctrl |= MAL_TX_CTRL_WRAP; 932 - if (!nr_frags && (len == size)) { 933 - ctrl |= MAL_TX_CTRL_LAST; 934 - fep->tx_skb[fep->tx_slot] = skb; 935 - } 936 - if (skb->ip_summed == CHECKSUM_HW) 937 - ctrl |= EMAC_TX_CTRL_TAH_CSUM; 938 - 939 - fep->tx_desc[fep->tx_slot].ctrl = ctrl; 940 - 941 - len -= size; 942 - offset += size; 943 - 944 - /* Bump tx count */ 945 - if (++fep->tx_cnt == NUM_TX_BUFF) 946 - netif_stop_queue(dev); 947 - 948 - /* Next descriptor */ 949 - if (++fep->tx_slot == NUM_TX_BUFF) 950 - fep->tx_slot = 0; 951 - } 952 - 953 - for (f = 0; f < nr_frags; f++) { 954 - struct skb_frag_struct *frag; 955 - 956 - frag = &skb_shinfo(skb)->frags[f]; 957 - len = frag->size; 958 - offset = 0; 959 - 960 - while (len) { 961 - size = min(len, DESC_BUF_SIZE); 962 - 963 - dma_map_page(&fep->ocpdev->dev, 964 - frag->page, 965 - frag->page_offset + offset, 966 - size, DMA_TO_DEVICE); 967 - 968 - ctrl = EMAC_TX_CTRL_DFLT | MAL_TX_CTRL_READY; 969 - if ((NUM_TX_BUFF - 1) == fep->tx_slot) 970 - ctrl |= MAL_TX_CTRL_WRAP; 971 - if ((f == (nr_frags - 1)) && (len == size)) { 972 - ctrl |= MAL_TX_CTRL_LAST; 973 - fep->tx_skb[fep->tx_slot] = skb; 974 - } 975 - 976 - if (skb->ip_summed == CHECKSUM_HW) 977 - ctrl |= EMAC_TX_CTRL_TAH_CSUM; 978 - 979 - fep->tx_desc[fep->tx_slot].data_len = (short)size; 980 - fep->tx_desc[fep->tx_slot].data_ptr = 981 - (char *)((page_to_pfn(frag->page) << PAGE_SHIFT) + 982 - frag->page_offset + offset); 983 - fep->tx_desc[fep->tx_slot].ctrl = ctrl; 984 - 985 - len -= size; 986 - offset += size; 987 - 988 - /* Bump tx count */ 989 - if (++fep->tx_cnt == NUM_TX_BUFF) 990 - netif_stop_queue(dev); 991 - 992 - /* Next descriptor */ 993 - if (++fep->tx_slot == NUM_TX_BUFF) 994 - fep->tx_slot = 0; 995 - } 996 - } 997 - 998 - /* 999 - * Deferred set READY on first descriptor of packet to 1000 - * avoid TX MAL race. 1001 - */ 1002 - fep->tx_desc[tx_slot_first].ctrl |= MAL_TX_CTRL_READY; 1003 - 1004 - /* Send the packet out. */ 1005 - out_be32(&emacp->em0tmr0, EMAC_TMR0_XMIT); 1006 - 1007 - fep->stats.tx_packets++; 1008 - fep->stats.tx_bytes += skb->len; 1009 - 1010 - PKT_DEBUG(("emac_start_xmit() exitn")); 1011 - 1012 - spin_unlock_irqrestore(&fep->lock, flags); 1013 - 1014 - return 0; 1587 + nst->tx_errors = (unsigned long)(est->tx_bd_errors + est->tx_errors); 1588 + nst->tx_fifo_errors = (unsigned long)(est->tx_bd_underrun + 1589 + est->tx_underrun); 1590 + nst->tx_carrier_errors = (unsigned long)est->tx_bd_carrier_loss; 1591 + nst->collisions = (unsigned long)(est->tx_bd_excessive_deferral + 1592 + est->tx_bd_excessive_collisions + 1593 + est->tx_bd_late_collision + 1594 + est->tx_bd_multple_collisions); 1595 + local_irq_enable(); 1596 + return nst; 1015 1597 } 1016 1598 1017 - static int emac_adjust_to_link(struct ocp_enet_private *fep) 1599 + static void emac_remove(struct ocp_device *ocpdev) 1018 1600 { 1019 - emac_t *emacp = fep->emacp; 1020 - unsigned long mode_reg; 1021 - int full_duplex, speed; 1601 + struct ocp_enet_private *dev = ocp_get_drvdata(ocpdev); 1022 1602 1023 - full_duplex = 0; 1024 - speed = SPEED_10; 1603 + DBG("%d: remove" NL, dev->def->index); 1025 1604 1026 - /* set mode register 1 defaults */ 1027 - mode_reg = EMAC_M1_DEFAULT; 1605 + ocp_set_drvdata(ocpdev, 0); 1606 + unregister_netdev(dev->ndev); 1028 1607 1029 - /* Read link mode on PHY */ 1030 - if (fep->phy_mii.def->ops->read_link(&fep->phy_mii) == 0) { 1031 - /* If an error occurred, we don't deal with it yet */ 1032 - full_duplex = (fep->phy_mii.duplex == DUPLEX_FULL); 1033 - speed = fep->phy_mii.speed; 1034 - } 1608 + tah_fini(dev->tah_dev); 1609 + rgmii_fini(dev->rgmii_dev, dev->rgmii_input); 1610 + zmii_fini(dev->zmii_dev, dev->zmii_input); 1035 1611 1612 + emac_dbg_register(dev->def->index, 0); 1036 1613 1037 - /* set speed (default is 10Mb) */ 1038 - switch (speed) { 1039 - case SPEED_1000: 1040 - mode_reg |= EMAC_M1_RFS_16K; 1041 - if (fep->rgmii_dev) { 1042 - struct ibm_ocp_rgmii *rgmii = RGMII_PRIV(fep->rgmii_dev); 1043 - 1044 - if ((rgmii->mode[fep->rgmii_input] == RTBI) 1045 - || (rgmii->mode[fep->rgmii_input] == TBI)) 1046 - mode_reg |= EMAC_M1_MF_1000GPCS; 1047 - else 1048 - mode_reg |= EMAC_M1_MF_1000MBPS; 1049 - 1050 - emac_rgmii_port_speed(fep->rgmii_dev, fep->rgmii_input, 1051 - 1000); 1052 - } 1053 - break; 1054 - case SPEED_100: 1055 - mode_reg |= EMAC_M1_MF_100MBPS | EMAC_M1_RFS_4K; 1056 - if (fep->rgmii_dev) 1057 - emac_rgmii_port_speed(fep->rgmii_dev, fep->rgmii_input, 1058 - 100); 1059 - if (fep->zmii_dev) 1060 - emac_zmii_port_speed(fep->zmii_dev, fep->zmii_input, 1061 - 100); 1062 - break; 1063 - case SPEED_10: 1064 - default: 1065 - mode_reg = (mode_reg & ~EMAC_M1_MF_100MBPS) | EMAC_M1_RFS_4K; 1066 - if (fep->rgmii_dev) 1067 - emac_rgmii_port_speed(fep->rgmii_dev, fep->rgmii_input, 1068 - 10); 1069 - if (fep->zmii_dev) 1070 - emac_zmii_port_speed(fep->zmii_dev, fep->zmii_input, 1071 - 10); 1072 - } 1073 - 1074 - if (full_duplex) 1075 - mode_reg |= EMAC_M1_FDE | EMAC_M1_EIFC | EMAC_M1_IST; 1076 - else 1077 - mode_reg &= ~(EMAC_M1_FDE | EMAC_M1_EIFC | EMAC_M1_ILE); 1078 - 1079 - LINK_DEBUG(("%s: adjust to link, speed: %d, duplex: %d, opened: %d\n", 1080 - fep->ndev->name, speed, full_duplex, fep->opened)); 1081 - 1082 - printk(KERN_INFO "%s: Speed: %d, %s duplex.\n", 1083 - fep->ndev->name, speed, full_duplex ? "Full" : "Half"); 1084 - if (fep->opened) 1085 - out_be32(&emacp->em0mr1, mode_reg); 1086 - 1087 - return 0; 1614 + mal_unregister_commac(dev->mal, &dev->commac); 1615 + iounmap((void *)dev->emacp); 1616 + kfree(dev->ndev); 1088 1617 } 1089 1618 1090 - static int emac_set_mac_address(struct net_device *ndev, void *p) 1619 + static struct mal_commac_ops emac_commac_ops = { 1620 + .poll_tx = &emac_poll_tx, 1621 + .poll_rx = &emac_poll_rx, 1622 + .peek_rx = &emac_peek_rx, 1623 + .rxde = &emac_rxde, 1624 + }; 1625 + 1626 + static struct mal_commac_ops emac_commac_sg_ops = { 1627 + .poll_tx = &emac_poll_tx, 1628 + .poll_rx = &emac_poll_rx, 1629 + .peek_rx = &emac_peek_rx_sg, 1630 + .rxde = &emac_rxde, 1631 + }; 1632 + 1633 + /* Ethtool support */ 1634 + static int emac_ethtool_get_settings(struct net_device *ndev, 1635 + struct ethtool_cmd *cmd) 1091 1636 { 1092 - struct ocp_enet_private *fep = ndev->priv; 1093 - emac_t *emacp = fep->emacp; 1094 - struct sockaddr *addr = p; 1637 + struct ocp_enet_private *dev = ndev->priv; 1095 1638 1096 - if (!is_valid_ether_addr(addr->sa_data)) 1097 - return -EADDRNOTAVAIL; 1098 - 1099 - memcpy(ndev->dev_addr, addr->sa_data, ndev->addr_len); 1100 - 1101 - /* set the high address */ 1102 - out_be32(&emacp->em0iahr, 1103 - (fep->ndev->dev_addr[0] << 8) | fep->ndev->dev_addr[1]); 1104 - 1105 - /* set the low address */ 1106 - out_be32(&emacp->em0ialr, 1107 - (fep->ndev->dev_addr[2] << 24) | (fep->ndev->dev_addr[3] << 16) 1108 - | (fep->ndev->dev_addr[4] << 8) | fep->ndev->dev_addr[5]); 1109 - 1110 - return 0; 1111 - } 1112 - 1113 - static int emac_change_mtu(struct net_device *dev, int new_mtu) 1114 - { 1115 - struct ocp_enet_private *fep = dev->priv; 1116 - int old_mtu = dev->mtu; 1117 - unsigned long mode_reg; 1118 - emac_t *emacp = fep->emacp; 1119 - u32 em0mr0; 1120 - int i, full; 1121 - unsigned long flags; 1122 - 1123 - if ((new_mtu < EMAC_MIN_MTU) || (new_mtu > EMAC_MAX_MTU)) { 1124 - printk(KERN_ERR 1125 - "emac: Invalid MTU setting, MTU must be between %d and %d\n", 1126 - EMAC_MIN_MTU, EMAC_MAX_MTU); 1127 - return -EINVAL; 1128 - } 1129 - 1130 - if (old_mtu != new_mtu && netif_running(dev)) { 1131 - /* Stop rx engine */ 1132 - em0mr0 = in_be32(&emacp->em0mr0); 1133 - out_be32(&emacp->em0mr0, em0mr0 & ~EMAC_M0_RXE); 1134 - 1135 - /* Wait for descriptors to be empty */ 1136 - do { 1137 - full = 0; 1138 - for (i = 0; i < NUM_RX_BUFF; i++) 1139 - if (!(fep->rx_desc[i].ctrl & MAL_RX_CTRL_EMPTY)) { 1140 - printk(KERN_NOTICE 1141 - "emac: RX ring is still full\n"); 1142 - full = 1; 1143 - } 1144 - } while (full); 1145 - 1146 - spin_lock_irqsave(&fep->lock, flags); 1147 - 1148 - mal_disable_rx_channels(fep->mal, fep->commac.rx_chan_mask); 1149 - 1150 - /* Destroy all old rx skbs */ 1151 - for (i = 0; i < NUM_RX_BUFF; i++) { 1152 - dma_unmap_single(&fep->ocpdev->dev, 1153 - fep->rx_desc[i].data_ptr, 1154 - fep->rx_desc[i].data_len, 1155 - DMA_FROM_DEVICE); 1156 - dev_kfree_skb(fep->rx_skb[i]); 1157 - fep->rx_skb[i] = NULL; 1158 - } 1159 - 1160 - /* Set new rx_buffer_size, jumbo cap, and advertise new mtu */ 1161 - mode_reg = in_be32(&emacp->em0mr1); 1162 - if (new_mtu > ENET_DEF_MTU_SIZE) { 1163 - mode_reg |= EMAC_M1_JUMBO_ENABLE; 1164 - fep->rx_buffer_size = EMAC_MAX_FRAME; 1165 - } else { 1166 - mode_reg &= ~EMAC_M1_JUMBO_ENABLE; 1167 - fep->rx_buffer_size = ENET_DEF_BUF_SIZE; 1168 - } 1169 - dev->mtu = new_mtu; 1170 - out_be32(&emacp->em0mr1, mode_reg); 1171 - 1172 - /* Re-init rx skbs */ 1173 - fep->rx_slot = 0; 1174 - emac_rx_fill(dev, 0); 1175 - 1176 - /* Restart the rx engine */ 1177 - mal_enable_rx_channels(fep->mal, fep->commac.rx_chan_mask); 1178 - out_be32(&emacp->em0mr0, em0mr0 | EMAC_M0_RXE); 1179 - 1180 - spin_unlock_irqrestore(&fep->lock, flags); 1181 - } 1182 - 1183 - return 0; 1184 - } 1185 - 1186 - static void __emac_set_multicast_list(struct net_device *dev) 1187 - { 1188 - struct ocp_enet_private *fep = dev->priv; 1189 - emac_t *emacp = fep->emacp; 1190 - u32 rmr = in_be32(&emacp->em0rmr); 1191 - 1192 - /* First clear all special bits, they can be set later */ 1193 - rmr &= ~(EMAC_RMR_PME | EMAC_RMR_PMME | EMAC_RMR_MAE); 1194 - 1195 - if (dev->flags & IFF_PROMISC) { 1196 - rmr |= EMAC_RMR_PME; 1197 - } else if (dev->flags & IFF_ALLMULTI || 32 < dev->mc_count) { 1198 - /* 1199 - * Must be setting up to use multicast 1200 - * Now check for promiscuous multicast 1201 - */ 1202 - rmr |= EMAC_RMR_PMME; 1203 - } else if (dev->flags & IFF_MULTICAST && 0 < dev->mc_count) { 1204 - unsigned short em0gaht[4] = { 0, 0, 0, 0 }; 1205 - struct dev_mc_list *dmi; 1206 - 1207 - /* Need to hash on the multicast address. */ 1208 - for (dmi = dev->mc_list; dmi; dmi = dmi->next) { 1209 - unsigned long mc_crc; 1210 - unsigned int bit_number; 1211 - 1212 - mc_crc = ether_crc(6, (char *)dmi->dmi_addr); 1213 - bit_number = 63 - (mc_crc >> 26); /* MSB: 0 LSB: 63 */ 1214 - em0gaht[bit_number >> 4] |= 1215 - 0x8000 >> (bit_number & 0x0f); 1216 - } 1217 - emacp->em0gaht1 = em0gaht[0]; 1218 - emacp->em0gaht2 = em0gaht[1]; 1219 - emacp->em0gaht3 = em0gaht[2]; 1220 - emacp->em0gaht4 = em0gaht[3]; 1221 - 1222 - /* Turn on multicast addressing */ 1223 - rmr |= EMAC_RMR_MAE; 1224 - } 1225 - out_be32(&emacp->em0rmr, rmr); 1226 - } 1227 - 1228 - static int emac_init_tah(struct ocp_enet_private *fep) 1229 - { 1230 - tah_t *tahp; 1231 - 1232 - /* Initialize TAH and enable checksum verification */ 1233 - tahp = (tah_t *) ioremap(fep->tah_dev->def->paddr, sizeof(*tahp)); 1234 - 1235 - if (tahp == NULL) { 1236 - printk(KERN_ERR "tah%d: Cannot ioremap TAH registers!\n", 1237 - fep->tah_dev->def->index); 1238 - 1239 - return -ENOMEM; 1240 - } 1241 - 1242 - out_be32(&tahp->tah_mr, TAH_MR_SR); 1243 - 1244 - /* wait for reset to complete */ 1245 - while (in_be32(&tahp->tah_mr) & TAH_MR_SR) ; 1246 - 1247 - /* 10KB TAH TX FIFO accomodates the max MTU of 9000 */ 1248 - out_be32(&tahp->tah_mr, 1249 - TAH_MR_CVR | TAH_MR_ST_768 | TAH_MR_TFS_10KB | TAH_MR_DTFP | 1250 - TAH_MR_DIG); 1251 - 1252 - iounmap(tahp); 1253 - 1254 - return 0; 1255 - } 1256 - 1257 - static void emac_init_rings(struct net_device *dev) 1258 - { 1259 - struct ocp_enet_private *ep = dev->priv; 1260 - int loop; 1261 - 1262 - ep->tx_desc = (struct mal_descriptor *)((char *)ep->mal->tx_virt_addr + 1263 - (ep->mal_tx_chan * 1264 - MAL_DT_ALIGN)); 1265 - ep->rx_desc = 1266 - (struct mal_descriptor *)((char *)ep->mal->rx_virt_addr + 1267 - (ep->mal_rx_chan * MAL_DT_ALIGN)); 1268 - 1269 - /* Fill in the transmit descriptor ring. */ 1270 - for (loop = 0; loop < NUM_TX_BUFF; loop++) { 1271 - if (ep->tx_skb[loop]) { 1272 - dma_unmap_single(&ep->ocpdev->dev, 1273 - ep->tx_desc[loop].data_ptr, 1274 - ep->tx_desc[loop].data_len, 1275 - DMA_TO_DEVICE); 1276 - dev_kfree_skb_irq(ep->tx_skb[loop]); 1277 - } 1278 - ep->tx_skb[loop] = NULL; 1279 - ep->tx_desc[loop].ctrl = 0; 1280 - ep->tx_desc[loop].data_len = 0; 1281 - ep->tx_desc[loop].data_ptr = NULL; 1282 - } 1283 - ep->tx_desc[loop - 1].ctrl |= MAL_TX_CTRL_WRAP; 1284 - 1285 - /* Format the receive descriptor ring. */ 1286 - ep->rx_slot = 0; 1287 - /* Default is MTU=1500 + Ethernet overhead */ 1288 - ep->rx_buffer_size = dev->mtu + ENET_HEADER_SIZE + ENET_FCS_SIZE; 1289 - emac_rx_fill(dev, 0); 1290 - if (ep->rx_slot != 0) { 1291 - printk(KERN_ERR 1292 - "%s: Not enough mem for RxChain durning Open?\n", 1293 - dev->name); 1294 - /*We couldn't fill the ring at startup? 1295 - *We could clean up and fail to open but right now we will try to 1296 - *carry on. It may be a sign of a bad NUM_RX_BUFF value 1297 - */ 1298 - } 1299 - 1300 - ep->tx_cnt = 0; 1301 - ep->tx_slot = 0; 1302 - ep->ack_slot = 0; 1303 - } 1304 - 1305 - static void emac_reset_configure(struct ocp_enet_private *fep) 1306 - { 1307 - emac_t *emacp = fep->emacp; 1308 - int i; 1309 - 1310 - mal_disable_tx_channels(fep->mal, fep->commac.tx_chan_mask); 1311 - mal_disable_rx_channels(fep->mal, fep->commac.rx_chan_mask); 1312 - 1313 - /* 1314 - * Check for a link, some PHYs don't provide a clock if 1315 - * no link is present. Some EMACs will not come out of 1316 - * soft reset without a PHY clock present. 1317 - */ 1318 - if (fep->phy_mii.def->ops->poll_link(&fep->phy_mii)) { 1319 - /* Reset the EMAC */ 1320 - out_be32(&emacp->em0mr0, EMAC_M0_SRST); 1321 - udelay(20); 1322 - for (i = 0; i < 100; i++) { 1323 - if ((in_be32(&emacp->em0mr0) & EMAC_M0_SRST) == 0) 1324 - break; 1325 - udelay(10); 1326 - } 1327 - 1328 - if (i >= 100) { 1329 - printk(KERN_ERR "%s: Cannot reset EMAC\n", 1330 - fep->ndev->name); 1331 - return; 1332 - } 1333 - } 1334 - 1335 - /* Switch IRQs off for now */ 1336 - out_be32(&emacp->em0iser, 0); 1337 - 1338 - /* Configure MAL rx channel */ 1339 - mal_set_rcbs(fep->mal, fep->mal_rx_chan, DESC_BUF_SIZE_REG); 1340 - 1341 - /* set the high address */ 1342 - out_be32(&emacp->em0iahr, 1343 - (fep->ndev->dev_addr[0] << 8) | fep->ndev->dev_addr[1]); 1344 - 1345 - /* set the low address */ 1346 - out_be32(&emacp->em0ialr, 1347 - (fep->ndev->dev_addr[2] << 24) | (fep->ndev->dev_addr[3] << 16) 1348 - | (fep->ndev->dev_addr[4] << 8) | fep->ndev->dev_addr[5]); 1349 - 1350 - /* Adjust to link */ 1351 - if (netif_carrier_ok(fep->ndev)) 1352 - emac_adjust_to_link(fep); 1353 - 1354 - /* enable broadcast/individual address and RX FIFO defaults */ 1355 - out_be32(&emacp->em0rmr, EMAC_RMR_DEFAULT); 1356 - 1357 - /* set transmit request threshold register */ 1358 - out_be32(&emacp->em0trtr, EMAC_TRTR_DEFAULT); 1359 - 1360 - /* Reconfigure multicast */ 1361 - __emac_set_multicast_list(fep->ndev); 1362 - 1363 - /* Set receiver/transmitter defaults */ 1364 - out_be32(&emacp->em0rwmr, EMAC_RWMR_DEFAULT); 1365 - out_be32(&emacp->em0tmr0, EMAC_TMR0_DEFAULT); 1366 - out_be32(&emacp->em0tmr1, EMAC_TMR1_DEFAULT); 1367 - 1368 - /* set frame gap */ 1369 - out_be32(&emacp->em0ipgvr, CONFIG_IBM_EMAC_FGAP); 1370 - 1371 - /* set VLAN Tag Protocol Identifier */ 1372 - out_be32(&emacp->em0vtpid, 0x8100); 1373 - 1374 - /* Init ring buffers */ 1375 - emac_init_rings(fep->ndev); 1376 - } 1377 - 1378 - static void emac_kick(struct ocp_enet_private *fep) 1379 - { 1380 - emac_t *emacp = fep->emacp; 1381 - unsigned long emac_ier; 1382 - 1383 - emac_ier = EMAC_ISR_PP | EMAC_ISR_BP | EMAC_ISR_RP | 1384 - EMAC_ISR_SE | EMAC_ISR_PTLE | EMAC_ISR_ALE | 1385 - EMAC_ISR_BFCS | EMAC_ISR_ORE | EMAC_ISR_IRE; 1386 - 1387 - out_be32(&emacp->em0iser, emac_ier); 1388 - 1389 - /* enable all MAL transmit and receive channels */ 1390 - mal_enable_tx_channels(fep->mal, fep->commac.tx_chan_mask); 1391 - mal_enable_rx_channels(fep->mal, fep->commac.rx_chan_mask); 1392 - 1393 - /* set transmit and receive enable */ 1394 - out_be32(&emacp->em0mr0, EMAC_M0_TXE | EMAC_M0_RXE); 1395 - } 1396 - 1397 - static void 1398 - emac_start_link(struct ocp_enet_private *fep, struct ethtool_cmd *ep) 1399 - { 1400 - u32 advertise; 1401 - int autoneg; 1402 - int forced_speed; 1403 - int forced_duplex; 1404 - 1405 - /* Default advertise */ 1406 - advertise = ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full | 1407 - ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full | 1408 - ADVERTISED_1000baseT_Half | ADVERTISED_1000baseT_Full; 1409 - autoneg = fep->want_autoneg; 1410 - forced_speed = fep->phy_mii.speed; 1411 - forced_duplex = fep->phy_mii.duplex; 1412 - 1413 - /* Setup link parameters */ 1414 - if (ep) { 1415 - if (ep->autoneg == AUTONEG_ENABLE) { 1416 - advertise = ep->advertising; 1417 - autoneg = 1; 1418 - } else { 1419 - autoneg = 0; 1420 - forced_speed = ep->speed; 1421 - forced_duplex = ep->duplex; 1422 - } 1423 - } 1424 - 1425 - /* Configure PHY & start aneg */ 1426 - fep->want_autoneg = autoneg; 1427 - if (autoneg) { 1428 - LINK_DEBUG(("%s: start link aneg, advertise: 0x%x\n", 1429 - fep->ndev->name, advertise)); 1430 - fep->phy_mii.def->ops->setup_aneg(&fep->phy_mii, advertise); 1431 - } else { 1432 - LINK_DEBUG(("%s: start link forced, speed: %d, duplex: %d\n", 1433 - fep->ndev->name, forced_speed, forced_duplex)); 1434 - fep->phy_mii.def->ops->setup_forced(&fep->phy_mii, forced_speed, 1435 - forced_duplex); 1436 - } 1437 - fep->timer_ticks = 0; 1438 - mod_timer(&fep->link_timer, jiffies + HZ); 1439 - } 1440 - 1441 - static void emac_link_timer(unsigned long data) 1442 - { 1443 - struct ocp_enet_private *fep = (struct ocp_enet_private *)data; 1444 - int link; 1445 - 1446 - if (fep->going_away) 1447 - return; 1448 - 1449 - spin_lock_irq(&fep->lock); 1450 - 1451 - link = fep->phy_mii.def->ops->poll_link(&fep->phy_mii); 1452 - LINK_DEBUG(("%s: poll_link: %d\n", fep->ndev->name, link)); 1453 - 1454 - if (link == netif_carrier_ok(fep->ndev)) { 1455 - if (!link && fep->want_autoneg && (++fep->timer_ticks) > 10) 1456 - emac_start_link(fep, NULL); 1457 - goto out; 1458 - } 1459 - printk(KERN_INFO "%s: Link is %s\n", fep->ndev->name, 1460 - link ? "Up" : "Down"); 1461 - if (link) { 1462 - netif_carrier_on(fep->ndev); 1463 - /* Chip needs a full reset on config change. That sucks, so I 1464 - * should ultimately move that to some tasklet to limit 1465 - * latency peaks caused by this code 1466 - */ 1467 - emac_reset_configure(fep); 1468 - if (fep->opened) 1469 - emac_kick(fep); 1470 - } else { 1471 - fep->timer_ticks = 0; 1472 - netif_carrier_off(fep->ndev); 1473 - } 1474 - out: 1475 - mod_timer(&fep->link_timer, jiffies + HZ); 1476 - spin_unlock_irq(&fep->lock); 1477 - } 1478 - 1479 - static void emac_set_multicast_list(struct net_device *dev) 1480 - { 1481 - struct ocp_enet_private *fep = dev->priv; 1482 - 1483 - spin_lock_irq(&fep->lock); 1484 - __emac_set_multicast_list(dev); 1485 - spin_unlock_irq(&fep->lock); 1486 - } 1487 - 1488 - static int emac_get_settings(struct net_device *ndev, struct ethtool_cmd *cmd) 1489 - { 1490 - struct ocp_enet_private *fep = ndev->priv; 1491 - 1492 - cmd->supported = fep->phy_mii.def->features; 1639 + cmd->supported = dev->phy.features; 1493 1640 cmd->port = PORT_MII; 1494 - cmd->transceiver = XCVR_EXTERNAL; 1495 - cmd->phy_address = fep->mii_phy_addr; 1496 - spin_lock_irq(&fep->lock); 1497 - cmd->autoneg = fep->want_autoneg; 1498 - cmd->speed = fep->phy_mii.speed; 1499 - cmd->duplex = fep->phy_mii.duplex; 1500 - spin_unlock_irq(&fep->lock); 1641 + cmd->phy_address = dev->phy.address; 1642 + cmd->transceiver = 1643 + dev->phy.address >= 0 ? XCVR_EXTERNAL : XCVR_INTERNAL; 1644 + 1645 + local_bh_disable(); 1646 + cmd->advertising = dev->phy.advertising; 1647 + cmd->autoneg = dev->phy.autoneg; 1648 + cmd->speed = dev->phy.speed; 1649 + cmd->duplex = dev->phy.duplex; 1650 + local_bh_enable(); 1651 + 1501 1652 return 0; 1502 1653 } 1503 1654 1504 - static int emac_set_settings(struct net_device *ndev, struct ethtool_cmd *cmd) 1655 + static int emac_ethtool_set_settings(struct net_device *ndev, 1656 + struct ethtool_cmd *cmd) 1505 1657 { 1506 - struct ocp_enet_private *fep = ndev->priv; 1507 - unsigned long features = fep->phy_mii.def->features; 1658 + struct ocp_enet_private *dev = ndev->priv; 1659 + u32 f = dev->phy.features; 1508 1660 1509 - if (!capable(CAP_NET_ADMIN)) 1510 - return -EPERM; 1661 + DBG("%d: set_settings(%d, %d, %d, 0x%08x)" NL, dev->def->index, 1662 + cmd->autoneg, cmd->speed, cmd->duplex, cmd->advertising); 1511 1663 1664 + /* Basic sanity checks */ 1665 + if (dev->phy.address < 0) 1666 + return -EOPNOTSUPP; 1512 1667 if (cmd->autoneg != AUTONEG_ENABLE && cmd->autoneg != AUTONEG_DISABLE) 1513 1668 return -EINVAL; 1514 1669 if (cmd->autoneg == AUTONEG_ENABLE && cmd->advertising == 0) 1515 1670 return -EINVAL; 1516 1671 if (cmd->duplex != DUPLEX_HALF && cmd->duplex != DUPLEX_FULL) 1517 1672 return -EINVAL; 1518 - if (cmd->autoneg == AUTONEG_DISABLE) 1673 + 1674 + if (cmd->autoneg == AUTONEG_DISABLE) { 1519 1675 switch (cmd->speed) { 1520 1676 case SPEED_10: 1521 - if (cmd->duplex == DUPLEX_HALF && 1522 - (features & SUPPORTED_10baseT_Half) == 0) 1677 + if (cmd->duplex == DUPLEX_HALF 1678 + && !(f & SUPPORTED_10baseT_Half)) 1523 1679 return -EINVAL; 1524 - if (cmd->duplex == DUPLEX_FULL && 1525 - (features & SUPPORTED_10baseT_Full) == 0) 1680 + if (cmd->duplex == DUPLEX_FULL 1681 + && !(f & SUPPORTED_10baseT_Full)) 1526 1682 return -EINVAL; 1527 1683 break; 1528 1684 case SPEED_100: 1529 - if (cmd->duplex == DUPLEX_HALF && 1530 - (features & SUPPORTED_100baseT_Half) == 0) 1685 + if (cmd->duplex == DUPLEX_HALF 1686 + && !(f & SUPPORTED_100baseT_Half)) 1531 1687 return -EINVAL; 1532 - if (cmd->duplex == DUPLEX_FULL && 1533 - (features & SUPPORTED_100baseT_Full) == 0) 1688 + if (cmd->duplex == DUPLEX_FULL 1689 + && !(f & SUPPORTED_100baseT_Full)) 1534 1690 return -EINVAL; 1535 1691 break; 1536 1692 case SPEED_1000: 1537 - if (cmd->duplex == DUPLEX_HALF && 1538 - (features & SUPPORTED_1000baseT_Half) == 0) 1693 + if (cmd->duplex == DUPLEX_HALF 1694 + && !(f & SUPPORTED_1000baseT_Half)) 1539 1695 return -EINVAL; 1540 - if (cmd->duplex == DUPLEX_FULL && 1541 - (features & SUPPORTED_1000baseT_Full) == 0) 1696 + if (cmd->duplex == DUPLEX_FULL 1697 + && !(f & SUPPORTED_1000baseT_Full)) 1542 1698 return -EINVAL; 1543 1699 break; 1544 1700 default: 1545 1701 return -EINVAL; 1546 - } else if ((features & SUPPORTED_Autoneg) == 0) 1547 - return -EINVAL; 1548 - spin_lock_irq(&fep->lock); 1549 - emac_start_link(fep, cmd); 1550 - spin_unlock_irq(&fep->lock); 1702 + } 1703 + 1704 + local_bh_disable(); 1705 + dev->phy.def->ops->setup_forced(&dev->phy, cmd->speed, 1706 + cmd->duplex); 1707 + 1708 + } else { 1709 + if (!(f & SUPPORTED_Autoneg)) 1710 + return -EINVAL; 1711 + 1712 + local_bh_disable(); 1713 + dev->phy.def->ops->setup_aneg(&dev->phy, 1714 + (cmd->advertising & f) | 1715 + (dev->phy.advertising & 1716 + (ADVERTISED_Pause | 1717 + ADVERTISED_Asym_Pause))); 1718 + } 1719 + emac_force_link_update(dev); 1720 + local_bh_enable(); 1721 + 1551 1722 return 0; 1552 1723 } 1553 1724 1554 - static void 1555 - emac_get_drvinfo(struct net_device *ndev, struct ethtool_drvinfo *info) 1725 + static void emac_ethtool_get_ringparam(struct net_device *ndev, 1726 + struct ethtool_ringparam *rp) 1556 1727 { 1557 - struct ocp_enet_private *fep = ndev->priv; 1728 + rp->rx_max_pending = rp->rx_pending = NUM_RX_BUFF; 1729 + rp->tx_max_pending = rp->tx_pending = NUM_TX_BUFF; 1730 + } 1558 1731 1559 - strcpy(info->driver, DRV_NAME); 1732 + static void emac_ethtool_get_pauseparam(struct net_device *ndev, 1733 + struct ethtool_pauseparam *pp) 1734 + { 1735 + struct ocp_enet_private *dev = ndev->priv; 1736 + 1737 + local_bh_disable(); 1738 + if ((dev->phy.features & SUPPORTED_Autoneg) && 1739 + (dev->phy.advertising & (ADVERTISED_Pause | ADVERTISED_Asym_Pause))) 1740 + pp->autoneg = 1; 1741 + 1742 + if (dev->phy.duplex == DUPLEX_FULL) { 1743 + if (dev->phy.pause) 1744 + pp->rx_pause = pp->tx_pause = 1; 1745 + else if (dev->phy.asym_pause) 1746 + pp->tx_pause = 1; 1747 + } 1748 + local_bh_enable(); 1749 + } 1750 + 1751 + static u32 emac_ethtool_get_rx_csum(struct net_device *ndev) 1752 + { 1753 + struct ocp_enet_private *dev = ndev->priv; 1754 + return dev->tah_dev != 0; 1755 + } 1756 + 1757 + static int emac_get_regs_len(struct ocp_enet_private *dev) 1758 + { 1759 + return sizeof(struct emac_ethtool_regs_subhdr) + EMAC_ETHTOOL_REGS_SIZE; 1760 + } 1761 + 1762 + static int emac_ethtool_get_regs_len(struct net_device *ndev) 1763 + { 1764 + struct ocp_enet_private *dev = ndev->priv; 1765 + return sizeof(struct emac_ethtool_regs_hdr) + 1766 + emac_get_regs_len(dev) + mal_get_regs_len(dev->mal) + 1767 + zmii_get_regs_len(dev->zmii_dev) + 1768 + rgmii_get_regs_len(dev->rgmii_dev) + 1769 + tah_get_regs_len(dev->tah_dev); 1770 + } 1771 + 1772 + static void *emac_dump_regs(struct ocp_enet_private *dev, void *buf) 1773 + { 1774 + struct emac_ethtool_regs_subhdr *hdr = buf; 1775 + 1776 + hdr->version = EMAC_ETHTOOL_REGS_VER; 1777 + hdr->index = dev->def->index; 1778 + memcpy_fromio(hdr + 1, dev->emacp, EMAC_ETHTOOL_REGS_SIZE); 1779 + return ((void *)(hdr + 1) + EMAC_ETHTOOL_REGS_SIZE); 1780 + } 1781 + 1782 + static void emac_ethtool_get_regs(struct net_device *ndev, 1783 + struct ethtool_regs *regs, void *buf) 1784 + { 1785 + struct ocp_enet_private *dev = ndev->priv; 1786 + struct emac_ethtool_regs_hdr *hdr = buf; 1787 + 1788 + hdr->components = 0; 1789 + buf = hdr + 1; 1790 + 1791 + local_irq_disable(); 1792 + buf = mal_dump_regs(dev->mal, buf); 1793 + buf = emac_dump_regs(dev, buf); 1794 + if (dev->zmii_dev) { 1795 + hdr->components |= EMAC_ETHTOOL_REGS_ZMII; 1796 + buf = zmii_dump_regs(dev->zmii_dev, buf); 1797 + } 1798 + if (dev->rgmii_dev) { 1799 + hdr->components |= EMAC_ETHTOOL_REGS_RGMII; 1800 + buf = rgmii_dump_regs(dev->rgmii_dev, buf); 1801 + } 1802 + if (dev->tah_dev) { 1803 + hdr->components |= EMAC_ETHTOOL_REGS_TAH; 1804 + buf = tah_dump_regs(dev->tah_dev, buf); 1805 + } 1806 + local_irq_enable(); 1807 + } 1808 + 1809 + static int emac_ethtool_nway_reset(struct net_device *ndev) 1810 + { 1811 + struct ocp_enet_private *dev = ndev->priv; 1812 + int res = 0; 1813 + 1814 + DBG("%d: nway_reset" NL, dev->def->index); 1815 + 1816 + if (dev->phy.address < 0) 1817 + return -EOPNOTSUPP; 1818 + 1819 + local_bh_disable(); 1820 + if (!dev->phy.autoneg) { 1821 + res = -EINVAL; 1822 + goto out; 1823 + } 1824 + 1825 + dev->phy.def->ops->setup_aneg(&dev->phy, dev->phy.advertising); 1826 + emac_force_link_update(dev); 1827 + 1828 + out: 1829 + local_bh_enable(); 1830 + return res; 1831 + } 1832 + 1833 + static int emac_ethtool_get_stats_count(struct net_device *ndev) 1834 + { 1835 + return EMAC_ETHTOOL_STATS_COUNT; 1836 + } 1837 + 1838 + static void emac_ethtool_get_strings(struct net_device *ndev, u32 stringset, 1839 + u8 * buf) 1840 + { 1841 + if (stringset == ETH_SS_STATS) 1842 + memcpy(buf, &emac_stats_keys, sizeof(emac_stats_keys)); 1843 + } 1844 + 1845 + static void emac_ethtool_get_ethtool_stats(struct net_device *ndev, 1846 + struct ethtool_stats *estats, 1847 + u64 * tmp_stats) 1848 + { 1849 + struct ocp_enet_private *dev = ndev->priv; 1850 + local_irq_disable(); 1851 + memcpy(tmp_stats, &dev->stats, sizeof(dev->stats)); 1852 + tmp_stats += sizeof(dev->stats) / sizeof(u64); 1853 + memcpy(tmp_stats, &dev->estats, sizeof(dev->estats)); 1854 + local_irq_enable(); 1855 + } 1856 + 1857 + static void emac_ethtool_get_drvinfo(struct net_device *ndev, 1858 + struct ethtool_drvinfo *info) 1859 + { 1860 + struct ocp_enet_private *dev = ndev->priv; 1861 + 1862 + strcpy(info->driver, "ibm_emac"); 1560 1863 strcpy(info->version, DRV_VERSION); 1561 1864 info->fw_version[0] = '\0'; 1562 - sprintf(info->bus_info, "IBM EMAC %d", fep->ocpdev->def->index); 1563 - info->regdump_len = 0; 1564 - } 1565 - 1566 - static int emac_nway_reset(struct net_device *ndev) 1567 - { 1568 - struct ocp_enet_private *fep = ndev->priv; 1569 - 1570 - if (!fep->want_autoneg) 1571 - return -EINVAL; 1572 - spin_lock_irq(&fep->lock); 1573 - emac_start_link(fep, NULL); 1574 - spin_unlock_irq(&fep->lock); 1575 - return 0; 1576 - } 1577 - 1578 - static u32 emac_get_link(struct net_device *ndev) 1579 - { 1580 - return netif_carrier_ok(ndev); 1865 + sprintf(info->bus_info, "PPC 4xx EMAC %d", dev->def->index); 1866 + info->n_stats = emac_ethtool_get_stats_count(ndev); 1867 + info->regdump_len = emac_ethtool_get_regs_len(ndev); 1581 1868 } 1582 1869 1583 1870 static struct ethtool_ops emac_ethtool_ops = { 1584 - .get_settings = emac_get_settings, 1585 - .set_settings = emac_set_settings, 1586 - .get_drvinfo = emac_get_drvinfo, 1587 - .nway_reset = emac_nway_reset, 1588 - .get_link = emac_get_link 1871 + .get_settings = emac_ethtool_get_settings, 1872 + .set_settings = emac_ethtool_set_settings, 1873 + .get_drvinfo = emac_ethtool_get_drvinfo, 1874 + 1875 + .get_regs_len = emac_ethtool_get_regs_len, 1876 + .get_regs = emac_ethtool_get_regs, 1877 + 1878 + .nway_reset = emac_ethtool_nway_reset, 1879 + 1880 + .get_ringparam = emac_ethtool_get_ringparam, 1881 + .get_pauseparam = emac_ethtool_get_pauseparam, 1882 + 1883 + .get_rx_csum = emac_ethtool_get_rx_csum, 1884 + 1885 + .get_strings = emac_ethtool_get_strings, 1886 + .get_stats_count = emac_ethtool_get_stats_count, 1887 + .get_ethtool_stats = emac_ethtool_get_ethtool_stats, 1888 + 1889 + .get_link = ethtool_op_get_link, 1890 + .get_tx_csum = ethtool_op_get_tx_csum, 1891 + .get_sg = ethtool_op_get_sg, 1589 1892 }; 1590 1893 1591 - static int emac_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) 1894 + static int emac_ioctl(struct net_device *ndev, struct ifreq *rq, int cmd) 1592 1895 { 1593 - struct ocp_enet_private *fep = dev->priv; 1896 + struct ocp_enet_private *dev = ndev->priv; 1594 1897 uint16_t *data = (uint16_t *) & rq->ifr_ifru; 1898 + 1899 + DBG("%d: ioctl %08x" NL, dev->def->index, cmd); 1900 + 1901 + if (dev->phy.address < 0) 1902 + return -EOPNOTSUPP; 1595 1903 1596 1904 switch (cmd) { 1597 1905 case SIOCGMIIPHY: 1598 - data[0] = fep->mii_phy_addr; 1906 + case SIOCDEVPRIVATE: 1907 + data[0] = dev->phy.address; 1599 1908 /* Fall through */ 1600 1909 case SIOCGMIIREG: 1601 - data[3] = emac_phy_read(dev, fep->mii_phy_addr, data[1]); 1910 + case SIOCDEVPRIVATE + 1: 1911 + data[3] = emac_mdio_read(ndev, dev->phy.address, data[1]); 1602 1912 return 0; 1913 + 1603 1914 case SIOCSMIIREG: 1915 + case SIOCDEVPRIVATE + 2: 1604 1916 if (!capable(CAP_NET_ADMIN)) 1605 1917 return -EPERM; 1606 - 1607 - emac_phy_write(dev, fep->mii_phy_addr, data[1], data[2]); 1918 + emac_mdio_write(ndev, dev->phy.address, data[1], data[2]); 1608 1919 return 0; 1609 1920 default: 1610 1921 return -EOPNOTSUPP; 1611 1922 } 1612 1923 } 1613 1924 1614 - static int emac_open(struct net_device *dev) 1925 + static int __init emac_probe(struct ocp_device *ocpdev) 1615 1926 { 1616 - struct ocp_enet_private *fep = dev->priv; 1617 - int rc; 1618 - 1619 - spin_lock_irq(&fep->lock); 1620 - 1621 - fep->opened = 1; 1622 - netif_carrier_off(dev); 1623 - 1624 - /* Reset & configure the chip */ 1625 - emac_reset_configure(fep); 1626 - 1627 - spin_unlock_irq(&fep->lock); 1628 - 1629 - /* Request our interrupt lines */ 1630 - rc = request_irq(dev->irq, emac_mac_irq, 0, "IBM EMAC MAC", dev); 1631 - if (rc != 0) { 1632 - printk("dev->irq %d failed\n", dev->irq); 1633 - goto bail; 1634 - } 1635 - /* Kick the chip rx & tx channels into life */ 1636 - spin_lock_irq(&fep->lock); 1637 - emac_kick(fep); 1638 - spin_unlock_irq(&fep->lock); 1639 - 1640 - netif_start_queue(dev); 1641 - bail: 1642 - return rc; 1643 - } 1644 - 1645 - static int emac_close(struct net_device *dev) 1646 - { 1647 - struct ocp_enet_private *fep = dev->priv; 1648 - emac_t *emacp = fep->emacp; 1649 - 1650 - /* XXX Stop IRQ emitting here */ 1651 - spin_lock_irq(&fep->lock); 1652 - fep->opened = 0; 1653 - mal_disable_tx_channels(fep->mal, fep->commac.tx_chan_mask); 1654 - mal_disable_rx_channels(fep->mal, fep->commac.rx_chan_mask); 1655 - netif_carrier_off(dev); 1656 - netif_stop_queue(dev); 1657 - 1658 - /* 1659 - * Check for a link, some PHYs don't provide a clock if 1660 - * no link is present. Some EMACs will not come out of 1661 - * soft reset without a PHY clock present. 1662 - */ 1663 - if (fep->phy_mii.def->ops->poll_link(&fep->phy_mii)) { 1664 - out_be32(&emacp->em0mr0, EMAC_M0_SRST); 1665 - udelay(10); 1666 - 1667 - if (emacp->em0mr0 & EMAC_M0_SRST) { 1668 - /*not sure what to do here hopefully it clears before another open */ 1669 - printk(KERN_ERR 1670 - "%s: Phy SoftReset didn't clear, no link?\n", 1671 - dev->name); 1672 - } 1673 - } 1674 - 1675 - /* Free the irq's */ 1676 - free_irq(dev->irq, dev); 1677 - 1678 - spin_unlock_irq(&fep->lock); 1679 - 1680 - return 0; 1681 - } 1682 - 1683 - static void emac_remove(struct ocp_device *ocpdev) 1684 - { 1685 - struct net_device *dev = ocp_get_drvdata(ocpdev); 1686 - struct ocp_enet_private *ep = dev->priv; 1687 - 1688 - /* FIXME: locking, races, ... */ 1689 - ep->going_away = 1; 1690 - ocp_set_drvdata(ocpdev, NULL); 1691 - if (ep->rgmii_dev) 1692 - emac_close_rgmii(ep->rgmii_dev); 1693 - if (ep->zmii_dev) 1694 - emac_close_zmii(ep->zmii_dev); 1695 - 1696 - unregister_netdev(dev); 1697 - del_timer_sync(&ep->link_timer); 1698 - mal_unregister_commac(ep->mal, &ep->commac); 1699 - iounmap((void *)ep->emacp); 1700 - kfree(dev); 1701 - } 1702 - 1703 - struct mal_commac_ops emac_commac_ops = { 1704 - .txeob = &emac_txeob_dev, 1705 - .txde = &emac_txde_dev, 1706 - .rxeob = &emac_rxeob_dev, 1707 - .rxde = &emac_rxde_dev, 1708 - }; 1709 - 1710 - #ifdef CONFIG_NET_POLL_CONTROLLER 1711 - static void emac_netpoll(struct net_device *ndev) 1712 - { 1713 - emac_rxeob_dev((void *)ndev, 0); 1714 - emac_txeob_dev((void *)ndev, 0); 1715 - } 1716 - #endif 1717 - 1718 - static int emac_init_device(struct ocp_device *ocpdev, struct ibm_ocp_mal *mal) 1719 - { 1720 - int deferred_init = 0; 1721 - int rc = 0, i; 1927 + struct ocp_func_emac_data *emacdata = ocpdev->def->additions; 1722 1928 struct net_device *ndev; 1723 - struct ocp_enet_private *ep; 1724 - struct ocp_func_emac_data *emacdata; 1725 - int commac_reg = 0; 1726 - u32 phy_map; 1929 + struct ocp_device *maldev; 1930 + struct ocp_enet_private *dev; 1931 + int err, i; 1727 1932 1728 - emacdata = (struct ocp_func_emac_data *)ocpdev->def->additions; 1933 + DBG("%d: probe" NL, ocpdev->def->index); 1934 + 1729 1935 if (!emacdata) { 1730 1936 printk(KERN_ERR "emac%d: Missing additional data!\n", 1731 1937 ocpdev->def->index); ··· 1936 1738 1937 1739 /* Allocate our net_device structure */ 1938 1740 ndev = alloc_etherdev(sizeof(struct ocp_enet_private)); 1939 - if (ndev == NULL) { 1940 - printk(KERN_ERR 1941 - "emac%d: Could not allocate ethernet device.\n", 1741 + if (!ndev) { 1742 + printk(KERN_ERR "emac%d: could not allocate ethernet device!\n", 1942 1743 ocpdev->def->index); 1943 1744 return -ENOMEM; 1944 1745 } 1945 - ep = ndev->priv; 1946 - ep->ndev = ndev; 1947 - ep->ocpdev = ocpdev; 1948 - ndev->irq = ocpdev->def->irq; 1949 - ep->wol_irq = emacdata->wol_irq; 1950 - if (emacdata->mdio_idx >= 0) { 1951 - if (emacdata->mdio_idx == ocpdev->def->index) { 1952 - /* Set the common MDIO net_device */ 1953 - mdio_ndev = ndev; 1954 - deferred_init = 1; 1746 + dev = ndev->priv; 1747 + dev->ndev = ndev; 1748 + dev->ldev = &ocpdev->dev; 1749 + dev->def = ocpdev->def; 1750 + SET_MODULE_OWNER(ndev); 1751 + 1752 + /* Find MAL device we are connected to */ 1753 + maldev = 1754 + ocp_find_device(OCP_VENDOR_IBM, OCP_FUNC_MAL, emacdata->mal_idx); 1755 + if (!maldev) { 1756 + printk(KERN_ERR "emac%d: unknown mal%d device!\n", 1757 + dev->def->index, emacdata->mal_idx); 1758 + err = -ENODEV; 1759 + goto out; 1760 + } 1761 + dev->mal = ocp_get_drvdata(maldev); 1762 + if (!dev->mal) { 1763 + printk(KERN_ERR "emac%d: mal%d hasn't been initialized yet!\n", 1764 + dev->def->index, emacdata->mal_idx); 1765 + err = -ENODEV; 1766 + goto out; 1767 + } 1768 + 1769 + /* Register with MAL */ 1770 + dev->commac.ops = &emac_commac_ops; 1771 + dev->commac.dev = dev; 1772 + dev->commac.tx_chan_mask = MAL_CHAN_MASK(emacdata->mal_tx_chan); 1773 + dev->commac.rx_chan_mask = MAL_CHAN_MASK(emacdata->mal_rx_chan); 1774 + err = mal_register_commac(dev->mal, &dev->commac); 1775 + if (err) { 1776 + printk(KERN_ERR "emac%d: failed to register with mal%d!\n", 1777 + dev->def->index, emacdata->mal_idx); 1778 + goto out; 1779 + } 1780 + dev->rx_skb_size = emac_rx_skb_size(ndev->mtu); 1781 + dev->rx_sync_size = emac_rx_sync_size(ndev->mtu); 1782 + 1783 + /* Get pointers to BD rings */ 1784 + dev->tx_desc = 1785 + dev->mal->bd_virt + mal_tx_bd_offset(dev->mal, 1786 + emacdata->mal_tx_chan); 1787 + dev->rx_desc = 1788 + dev->mal->bd_virt + mal_rx_bd_offset(dev->mal, 1789 + emacdata->mal_rx_chan); 1790 + 1791 + DBG("%d: tx_desc %p" NL, ocpdev->def->index, dev->tx_desc); 1792 + DBG("%d: rx_desc %p" NL, ocpdev->def->index, dev->rx_desc); 1793 + 1794 + /* Clean rings */ 1795 + memset(dev->tx_desc, 0, NUM_TX_BUFF * sizeof(struct mal_descriptor)); 1796 + memset(dev->rx_desc, 0, NUM_RX_BUFF * sizeof(struct mal_descriptor)); 1797 + 1798 + /* If we depend on another EMAC for MDIO, check whether it was probed already */ 1799 + if (emacdata->mdio_idx >= 0 && emacdata->mdio_idx != ocpdev->def->index) { 1800 + struct ocp_device *mdiodev = 1801 + ocp_find_device(OCP_VENDOR_IBM, OCP_FUNC_EMAC, 1802 + emacdata->mdio_idx); 1803 + if (!mdiodev) { 1804 + printk(KERN_ERR "emac%d: unknown emac%d device!\n", 1805 + dev->def->index, emacdata->mdio_idx); 1806 + err = -ENODEV; 1807 + goto out2; 1955 1808 } 1956 - ep->mdio_dev = mdio_ndev; 1957 - } else { 1958 - ep->mdio_dev = ndev; 1959 - } 1960 - 1961 - ocp_set_drvdata(ocpdev, ndev); 1962 - 1963 - spin_lock_init(&ep->lock); 1964 - 1965 - /* Fill out MAL informations and register commac */ 1966 - ep->mal = mal; 1967 - ep->mal_tx_chan = emacdata->mal_tx_chan; 1968 - ep->mal_rx_chan = emacdata->mal_rx_chan; 1969 - ep->commac.ops = &emac_commac_ops; 1970 - ep->commac.dev = ndev; 1971 - ep->commac.tx_chan_mask = MAL_CHAN_MASK(ep->mal_tx_chan); 1972 - ep->commac.rx_chan_mask = MAL_CHAN_MASK(ep->mal_rx_chan); 1973 - rc = mal_register_commac(ep->mal, &ep->commac); 1974 - if (rc != 0) 1975 - goto bail; 1976 - commac_reg = 1; 1977 - 1978 - /* Map our MMIOs */ 1979 - ep->emacp = (emac_t *) ioremap(ocpdev->def->paddr, sizeof(emac_t)); 1980 - 1981 - /* Check if we need to attach to a ZMII */ 1982 - if (emacdata->zmii_idx >= 0) { 1983 - ep->zmii_input = emacdata->zmii_mux; 1984 - ep->zmii_dev = 1985 - ocp_find_device(OCP_ANY_ID, OCP_FUNC_ZMII, 1986 - emacdata->zmii_idx); 1987 - if (ep->zmii_dev == NULL) 1988 - printk(KERN_WARNING 1989 - "emac%d: ZMII %d requested but not found !\n", 1990 - ocpdev->def->index, emacdata->zmii_idx); 1991 - else if ((rc = 1992 - emac_init_zmii(ep->zmii_dev, ep->zmii_input, 1993 - emacdata->phy_mode)) != 0) 1994 - goto bail; 1995 - } 1996 - 1997 - /* Check if we need to attach to a RGMII */ 1998 - if (emacdata->rgmii_idx >= 0) { 1999 - ep->rgmii_input = emacdata->rgmii_mux; 2000 - ep->rgmii_dev = 2001 - ocp_find_device(OCP_ANY_ID, OCP_FUNC_RGMII, 2002 - emacdata->rgmii_idx); 2003 - if (ep->rgmii_dev == NULL) 2004 - printk(KERN_WARNING 2005 - "emac%d: RGMII %d requested but not found !\n", 2006 - ocpdev->def->index, emacdata->rgmii_idx); 2007 - else if ((rc = 2008 - emac_init_rgmii(ep->rgmii_dev, ep->rgmii_input, 2009 - emacdata->phy_mode)) != 0) 2010 - goto bail; 2011 - } 2012 - 2013 - /* Check if we need to attach to a TAH */ 2014 - if (emacdata->tah_idx >= 0) { 2015 - ep->tah_dev = 2016 - ocp_find_device(OCP_ANY_ID, OCP_FUNC_TAH, 2017 - emacdata->tah_idx); 2018 - if (ep->tah_dev == NULL) 2019 - printk(KERN_WARNING 2020 - "emac%d: TAH %d requested but not found !\n", 2021 - ocpdev->def->index, emacdata->tah_idx); 2022 - else if ((rc = emac_init_tah(ep)) != 0) 2023 - goto bail; 2024 - } 2025 - 2026 - if (deferred_init) { 2027 - if (!list_empty(&emac_init_list)) { 2028 - struct list_head *entry; 2029 - struct emac_def_dev *ddev; 2030 - 2031 - list_for_each(entry, &emac_init_list) { 2032 - ddev = 2033 - list_entry(entry, struct emac_def_dev, 2034 - link); 2035 - emac_init_device(ddev->ocpdev, ddev->mal); 2036 - } 1809 + dev->mdio_dev = ocp_get_drvdata(mdiodev); 1810 + if (!dev->mdio_dev) { 1811 + printk(KERN_ERR 1812 + "emac%d: emac%d hasn't been initialized yet!\n", 1813 + dev->def->index, emacdata->mdio_idx); 1814 + err = -ENODEV; 1815 + goto out2; 2037 1816 } 2038 1817 } 2039 1818 2040 - /* Init link monitoring timer */ 2041 - init_timer(&ep->link_timer); 2042 - ep->link_timer.function = emac_link_timer; 2043 - ep->link_timer.data = (unsigned long)ep; 2044 - ep->timer_ticks = 0; 1819 + /* Attach to ZMII, if needed */ 1820 + if ((err = zmii_attach(dev)) != 0) 1821 + goto out2; 2045 1822 2046 - /* Fill up the mii_phy structure */ 2047 - ep->phy_mii.dev = ndev; 2048 - ep->phy_mii.mdio_read = emac_phy_read; 2049 - ep->phy_mii.mdio_write = emac_phy_write; 2050 - ep->phy_mii.mode = emacdata->phy_mode; 1823 + /* Attach to RGMII, if needed */ 1824 + if ((err = rgmii_attach(dev)) != 0) 1825 + goto out3; 2051 1826 2052 - /* Find PHY */ 2053 - phy_map = emacdata->phy_map | busy_phy_map; 2054 - for (i = 0; i <= 0x1f; i++, phy_map >>= 1) { 2055 - if ((phy_map & 0x1) == 0) { 2056 - int val = emac_phy_read(ndev, i, MII_BMCR); 2057 - if (val != 0xffff && val != -1) 2058 - break; 2059 - } 2060 - } 2061 - if (i == 0x20) { 2062 - printk(KERN_WARNING "emac%d: Can't find PHY.\n", 2063 - ocpdev->def->index); 2064 - rc = -ENODEV; 2065 - goto bail; 2066 - } 2067 - busy_phy_map |= 1 << i; 2068 - ep->mii_phy_addr = i; 2069 - rc = mii_phy_probe(&ep->phy_mii, i); 2070 - if (rc) { 2071 - printk(KERN_WARNING "emac%d: Failed to probe PHY type.\n", 2072 - ocpdev->def->index); 2073 - rc = -ENODEV; 2074 - goto bail; 2075 - } 2076 - 2077 - /* Disable any PHY features not supported by the platform */ 2078 - ep->phy_mii.def->features &= ~emacdata->phy_feat_exc; 1827 + /* Attach to TAH, if needed */ 1828 + if ((err = tah_attach(dev)) != 0) 1829 + goto out4; 2079 1830 2080 - /* Setup initial PHY config & startup aneg */ 2081 - if (ep->phy_mii.def->ops->init) 2082 - ep->phy_mii.def->ops->init(&ep->phy_mii); 2083 - netif_carrier_off(ndev); 2084 - if (ep->phy_mii.def->features & SUPPORTED_Autoneg) 2085 - ep->want_autoneg = 1; 2086 - else { 2087 - ep->want_autoneg = 0; 2088 - 2089 - /* Select highest supported speed/duplex */ 2090 - if (ep->phy_mii.def->features & SUPPORTED_1000baseT_Full) { 2091 - ep->phy_mii.speed = SPEED_1000; 2092 - ep->phy_mii.duplex = DUPLEX_FULL; 2093 - } else if (ep->phy_mii.def->features & 2094 - SUPPORTED_1000baseT_Half) { 2095 - ep->phy_mii.speed = SPEED_1000; 2096 - ep->phy_mii.duplex = DUPLEX_HALF; 2097 - } else if (ep->phy_mii.def->features & 2098 - SUPPORTED_100baseT_Full) { 2099 - ep->phy_mii.speed = SPEED_100; 2100 - ep->phy_mii.duplex = DUPLEX_FULL; 2101 - } else if (ep->phy_mii.def->features & 2102 - SUPPORTED_100baseT_Half) { 2103 - ep->phy_mii.speed = SPEED_100; 2104 - ep->phy_mii.duplex = DUPLEX_HALF; 2105 - } else if (ep->phy_mii.def->features & 2106 - SUPPORTED_10baseT_Full) { 2107 - ep->phy_mii.speed = SPEED_10; 2108 - ep->phy_mii.duplex = DUPLEX_FULL; 2109 - } else { 2110 - ep->phy_mii.speed = SPEED_10; 2111 - ep->phy_mii.duplex = DUPLEX_HALF; 2112 - } 1831 + /* Map EMAC regs */ 1832 + dev->emacp = 1833 + (struct emac_regs *)ioremap(dev->def->paddr, 1834 + sizeof(struct emac_regs)); 1835 + if (!dev->emacp) { 1836 + printk(KERN_ERR "emac%d: could not ioremap device registers!\n", 1837 + dev->def->index); 1838 + err = -ENOMEM; 1839 + goto out5; 2113 1840 } 2114 - emac_start_link(ep, NULL); 2115 1841 2116 - /* read the MAC Address */ 2117 - for (i = 0; i < 6; i++) 1842 + /* Fill in MAC address */ 1843 + for (i = 0; i < 6; ++i) 2118 1844 ndev->dev_addr[i] = emacdata->mac_addr[i]; 1845 + 1846 + /* Set some link defaults before we can find out real parameters */ 1847 + dev->phy.speed = SPEED_100; 1848 + dev->phy.duplex = DUPLEX_FULL; 1849 + dev->phy.autoneg = AUTONEG_DISABLE; 1850 + dev->phy.pause = dev->phy.asym_pause = 0; 1851 + init_timer(&dev->link_timer); 1852 + dev->link_timer.function = emac_link_timer; 1853 + dev->link_timer.data = (unsigned long)dev; 1854 + 1855 + /* Find PHY if any */ 1856 + dev->phy.dev = ndev; 1857 + dev->phy.mode = emacdata->phy_mode; 1858 + if (emacdata->phy_map != 0xffffffff) { 1859 + u32 phy_map = emacdata->phy_map | busy_phy_map; 1860 + u32 adv; 1861 + 1862 + DBG("%d: PHY maps %08x %08x" NL, dev->def->index, 1863 + emacdata->phy_map, busy_phy_map); 1864 + 1865 + EMAC_RX_CLK_TX(dev->def->index); 1866 + 1867 + dev->phy.mdio_read = emac_mdio_read; 1868 + dev->phy.mdio_write = emac_mdio_write; 1869 + 1870 + /* Configure EMAC with defaults so we can at least use MDIO 1871 + * This is needed mostly for 440GX 1872 + */ 1873 + if (emac_phy_gpcs(dev->phy.mode)) { 1874 + /* XXX 1875 + * Make GPCS PHY address equal to EMAC index. 1876 + * We probably should take into account busy_phy_map 1877 + * and/or phy_map here. 1878 + */ 1879 + dev->phy.address = dev->def->index; 1880 + } 1881 + 1882 + emac_configure(dev); 1883 + 1884 + for (i = 0; i < 0x20; phy_map >>= 1, ++i) 1885 + if (!(phy_map & 1)) { 1886 + int r; 1887 + busy_phy_map |= 1 << i; 1888 + 1889 + /* Quick check if there is a PHY at the address */ 1890 + r = emac_mdio_read(dev->ndev, i, MII_BMCR); 1891 + if (r == 0xffff || r < 0) 1892 + continue; 1893 + if (!mii_phy_probe(&dev->phy, i)) 1894 + break; 1895 + } 1896 + if (i == 0x20) { 1897 + printk(KERN_WARNING "emac%d: can't find PHY!\n", 1898 + dev->def->index); 1899 + goto out6; 1900 + } 1901 + 1902 + /* Init PHY */ 1903 + if (dev->phy.def->ops->init) 1904 + dev->phy.def->ops->init(&dev->phy); 1905 + 1906 + /* Disable any PHY features not supported by the platform */ 1907 + dev->phy.def->features &= ~emacdata->phy_feat_exc; 1908 + 1909 + /* Setup initial link parameters */ 1910 + if (dev->phy.features & SUPPORTED_Autoneg) { 1911 + adv = dev->phy.features; 1912 + #if !defined(CONFIG_40x) 1913 + adv |= ADVERTISED_Pause | ADVERTISED_Asym_Pause; 1914 + #endif 1915 + /* Restart autonegotiation */ 1916 + dev->phy.def->ops->setup_aneg(&dev->phy, adv); 1917 + } else { 1918 + u32 f = dev->phy.def->features; 1919 + int speed = SPEED_10, fd = DUPLEX_HALF; 1920 + 1921 + /* Select highest supported speed/duplex */ 1922 + if (f & SUPPORTED_1000baseT_Full) { 1923 + speed = SPEED_1000; 1924 + fd = DUPLEX_FULL; 1925 + } else if (f & SUPPORTED_1000baseT_Half) 1926 + speed = SPEED_1000; 1927 + else if (f & SUPPORTED_100baseT_Full) { 1928 + speed = SPEED_100; 1929 + fd = DUPLEX_FULL; 1930 + } else if (f & SUPPORTED_100baseT_Half) 1931 + speed = SPEED_100; 1932 + else if (f & SUPPORTED_10baseT_Full) 1933 + fd = DUPLEX_FULL; 1934 + 1935 + /* Force link parameters */ 1936 + dev->phy.def->ops->setup_forced(&dev->phy, speed, fd); 1937 + } 1938 + } else { 1939 + emac_reset(dev); 1940 + 1941 + /* PHY-less configuration. 1942 + * XXX I probably should move these settings to emacdata 1943 + */ 1944 + dev->phy.address = -1; 1945 + dev->phy.features = SUPPORTED_100baseT_Full | SUPPORTED_MII; 1946 + dev->phy.pause = 1; 1947 + } 2119 1948 2120 1949 /* Fill in the driver function table */ 2121 1950 ndev->open = &emac_open; 2122 - ndev->hard_start_xmit = &emac_start_xmit; 1951 + if (dev->tah_dev) { 1952 + ndev->hard_start_xmit = &emac_start_xmit_sg; 1953 + ndev->features |= NETIF_F_IP_CSUM | NETIF_F_SG; 1954 + } else 1955 + ndev->hard_start_xmit = &emac_start_xmit; 1956 + ndev->tx_timeout = &emac_full_tx_reset; 1957 + ndev->watchdog_timeo = 5 * HZ; 2123 1958 ndev->stop = &emac_close; 2124 1959 ndev->get_stats = &emac_stats; 2125 - if (emacdata->jumbo) 2126 - ndev->change_mtu = &emac_change_mtu; 2127 - ndev->set_mac_address = &emac_set_mac_address; 2128 1960 ndev->set_multicast_list = &emac_set_multicast_list; 2129 1961 ndev->do_ioctl = &emac_ioctl; 1962 + if (emac_phy_supports_gige(emacdata->phy_mode)) { 1963 + ndev->change_mtu = &emac_change_mtu; 1964 + dev->commac.ops = &emac_commac_sg_ops; 1965 + } 2130 1966 SET_ETHTOOL_OPS(ndev, &emac_ethtool_ops); 2131 - if (emacdata->tah_idx >= 0) 2132 - ndev->features = NETIF_F_IP_CSUM | NETIF_F_SG; 2133 - #ifdef CONFIG_NET_POLL_CONTROLLER 2134 - ndev->poll_controller = emac_netpoll; 2135 - #endif 2136 1967 2137 - SET_MODULE_OWNER(ndev); 1968 + netif_carrier_off(ndev); 1969 + netif_stop_queue(ndev); 2138 1970 2139 - rc = register_netdev(ndev); 2140 - if (rc != 0) 2141 - goto bail; 1971 + err = register_netdev(ndev); 1972 + if (err) { 1973 + printk(KERN_ERR "emac%d: failed to register net device (%d)!\n", 1974 + dev->def->index, err); 1975 + goto out6; 1976 + } 2142 1977 2143 - printk("%s: IBM emac, MAC %02x:%02x:%02x:%02x:%02x:%02x\n", 2144 - ndev->name, 1978 + ocp_set_drvdata(ocpdev, dev); 1979 + 1980 + printk("%s: emac%d, MAC %02x:%02x:%02x:%02x:%02x:%02x\n", 1981 + ndev->name, dev->def->index, 2145 1982 ndev->dev_addr[0], ndev->dev_addr[1], ndev->dev_addr[2], 2146 1983 ndev->dev_addr[3], ndev->dev_addr[4], ndev->dev_addr[5]); 2147 - printk(KERN_INFO "%s: Found %s PHY (0x%02x)\n", 2148 - ndev->name, ep->phy_mii.def->name, ep->mii_phy_addr); 2149 1984 2150 - bail: 2151 - if (rc && commac_reg) 2152 - mal_unregister_commac(ep->mal, &ep->commac); 2153 - if (rc && ndev) 2154 - kfree(ndev); 1985 + if (dev->phy.address >= 0) 1986 + printk("%s: found %s PHY (0x%02x)\n", ndev->name, 1987 + dev->phy.def->name, dev->phy.address); 2155 1988 2156 - return rc; 2157 - } 2158 - 2159 - static int emac_probe(struct ocp_device *ocpdev) 2160 - { 2161 - struct ocp_device *maldev; 2162 - struct ibm_ocp_mal *mal; 2163 - struct ocp_func_emac_data *emacdata; 2164 - 2165 - emacdata = (struct ocp_func_emac_data *)ocpdev->def->additions; 2166 - if (emacdata == NULL) { 2167 - printk(KERN_ERR "emac%d: Missing additional datas !\n", 2168 - ocpdev->def->index); 2169 - return -ENODEV; 2170 - } 2171 - 2172 - /* Get the MAL device */ 2173 - maldev = ocp_find_device(OCP_ANY_ID, OCP_FUNC_MAL, emacdata->mal_idx); 2174 - if (maldev == NULL) { 2175 - printk("No maldev\n"); 2176 - return -ENODEV; 2177 - } 2178 - /* 2179 - * Get MAL driver data, it must be here due to link order. 2180 - * When the driver is modularized, symbol dependencies will 2181 - * ensure the MAL driver is already present if built as a 2182 - * module. 2183 - */ 2184 - mal = (struct ibm_ocp_mal *)ocp_get_drvdata(maldev); 2185 - if (mal == NULL) { 2186 - printk("No maldrv\n"); 2187 - return -ENODEV; 2188 - } 2189 - 2190 - /* If we depend on another EMAC for MDIO, wait for it to show up */ 2191 - if (emacdata->mdio_idx >= 0 && 2192 - (emacdata->mdio_idx != ocpdev->def->index) && !mdio_ndev) { 2193 - struct emac_def_dev *ddev; 2194 - /* Add this index to the deferred init table */ 2195 - ddev = kmalloc(sizeof(struct emac_def_dev), GFP_KERNEL); 2196 - ddev->ocpdev = ocpdev; 2197 - ddev->mal = mal; 2198 - list_add_tail(&ddev->link, &emac_init_list); 2199 - } else { 2200 - emac_init_device(ocpdev, mal); 2201 - } 1989 + emac_dbg_register(dev->def->index, dev); 2202 1990 2203 1991 return 0; 1992 + out6: 1993 + iounmap((void *)dev->emacp); 1994 + out5: 1995 + tah_fini(dev->tah_dev); 1996 + out4: 1997 + rgmii_fini(dev->rgmii_dev, dev->rgmii_input); 1998 + out3: 1999 + zmii_fini(dev->zmii_dev, dev->zmii_input); 2000 + out2: 2001 + mal_unregister_commac(dev->mal, &dev->commac); 2002 + out: 2003 + kfree(ndev); 2004 + return err; 2204 2005 } 2205 2006 2206 - /* Structure for a device driver */ 2207 2007 static struct ocp_device_id emac_ids[] = { 2208 - {.vendor = OCP_ANY_ID,.function = OCP_FUNC_EMAC}, 2209 - {.vendor = OCP_VENDOR_INVALID} 2008 + { .vendor = OCP_VENDOR_IBM, .function = OCP_FUNC_EMAC }, 2009 + { .vendor = OCP_VENDOR_INVALID} 2210 2010 }; 2211 2011 2212 2012 static struct ocp_driver emac_driver = { 2213 2013 .name = "emac", 2214 2014 .id_table = emac_ids, 2215 - 2216 2015 .probe = emac_probe, 2217 2016 .remove = emac_remove, 2218 2017 }; 2219 2018 2220 2019 static int __init emac_init(void) 2221 2020 { 2222 - printk(KERN_INFO DRV_NAME ": " DRV_DESC ", version " DRV_VERSION "\n"); 2223 - printk(KERN_INFO "Maintained by " DRV_AUTHOR "\n"); 2021 + printk(KERN_INFO DRV_DESC ", version " DRV_VERSION "\n"); 2224 2022 2225 - if (skb_res > 2) { 2226 - printk(KERN_WARNING "Invalid skb_res: %d, cropping to 2\n", 2227 - skb_res); 2228 - skb_res = 2; 2023 + DBG(": init" NL); 2024 + 2025 + if (mal_init()) 2026 + return -ENODEV; 2027 + 2028 + EMAC_CLK_INTERNAL; 2029 + if (ocp_register_driver(&emac_driver)) { 2030 + EMAC_CLK_EXTERNAL; 2031 + ocp_unregister_driver(&emac_driver); 2032 + mal_exit(); 2033 + return -ENODEV; 2229 2034 } 2035 + EMAC_CLK_EXTERNAL; 2230 2036 2231 - return ocp_register_driver(&emac_driver); 2037 + emac_init_debug(); 2038 + return 0; 2232 2039 } 2233 2040 2234 2041 static void __exit emac_exit(void) 2235 2042 { 2043 + DBG(": exit" NL); 2236 2044 ocp_unregister_driver(&emac_driver); 2045 + mal_exit(); 2046 + emac_fini_debug(); 2237 2047 } 2238 2048 2239 2049 module_init(emac_init);
+184 -109
drivers/net/ibm_emac/ibm_emac_core.h
··· 1 1 /* 2 - * ibm_emac_core.h 2 + * drivers/net/ibm_emac/ibm_emac_core.h 3 3 * 4 - * Ethernet driver for the built in ethernet on the IBM 405 PowerPC 5 - * processor. 4 + * Driver for PowerPC 4xx on-chip ethernet controller. 6 5 * 7 - * Armin Kuster akuster@mvista.com 8 - * Sept, 2001 6 + * Copyright (c) 2004, 2005 Zultys Technologies. 7 + * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net> 9 8 * 10 - * Orignial driver 11 - * Johnnie Peters 12 - * jpeters@mvista.com 13 - * 14 - * Copyright 2000 MontaVista Softare Inc. 9 + * Based on original work by 10 + * Armin Kuster <akuster@mvista.com> 11 + * Johnnie Peters <jpeters@mvista.com> 12 + * Copyright 2000, 2001 MontaVista Softare Inc. 15 13 * 16 14 * This program is free software; you can redistribute it and/or modify it 17 15 * under the terms of the GNU General Public License as published by the 18 16 * Free Software Foundation; either version 2 of the License, or (at your 19 17 * option) any later version. 18 + * 20 19 */ 20 + #ifndef __IBM_EMAC_CORE_H_ 21 + #define __IBM_EMAC_CORE_H_ 21 22 22 - #ifndef _IBM_EMAC_CORE_H_ 23 - #define _IBM_EMAC_CORE_H_ 24 - 23 + #include <linux/config.h> 25 24 #include <linux/netdevice.h> 25 + #include <linux/dma-mapping.h> 26 26 #include <asm/ocp.h> 27 - #include <asm/mmu.h> /* For phys_addr_t */ 28 27 29 28 #include "ibm_emac.h" 30 29 #include "ibm_emac_phy.h" 31 - #include "ibm_emac_rgmii.h" 32 30 #include "ibm_emac_zmii.h" 31 + #include "ibm_emac_rgmii.h" 33 32 #include "ibm_emac_mal.h" 34 33 #include "ibm_emac_tah.h" 35 34 36 - #ifndef CONFIG_IBM_EMAC_TXB 37 - #define NUM_TX_BUFF 64 38 - #define NUM_RX_BUFF 64 39 - #else 40 - #define NUM_TX_BUFF CONFIG_IBM_EMAC_TXB 41 - #define NUM_RX_BUFF CONFIG_IBM_EMAC_RXB 35 + #define NUM_TX_BUFF CONFIG_IBM_EMAC_TXB 36 + #define NUM_RX_BUFF CONFIG_IBM_EMAC_RXB 37 + 38 + /* Simple sanity check */ 39 + #if NUM_TX_BUFF > 256 || NUM_RX_BUFF > 256 40 + #error Invalid number of buffer descriptors (greater than 256) 42 41 #endif 43 42 44 - /* This does 16 byte alignment, exactly what we need. 45 - * The packet length includes FCS, but we don't want to 46 - * include that when passing upstream as it messes up 47 - * bridging applications. 43 + // XXX 44 + #define EMAC_MIN_MTU 46 45 + #define EMAC_MAX_MTU 9000 46 + 47 + /* Maximum L2 header length (VLAN tagged, no FCS) */ 48 + #define EMAC_MTU_OVERHEAD (6 * 2 + 2 + 4) 49 + 50 + /* RX BD size for the given MTU */ 51 + static inline int emac_rx_size(int mtu) 52 + { 53 + if (mtu > ETH_DATA_LEN) 54 + return MAL_MAX_RX_SIZE; 55 + else 56 + return mal_rx_size(ETH_DATA_LEN + EMAC_MTU_OVERHEAD); 57 + } 58 + 59 + #define EMAC_DMA_ALIGN(x) ALIGN((x), dma_get_cache_alignment()) 60 + 61 + #define EMAC_RX_SKB_HEADROOM \ 62 + EMAC_DMA_ALIGN(CONFIG_IBM_EMAC_RX_SKB_HEADROOM) 63 + 64 + /* Size of RX skb for the given MTU */ 65 + static inline int emac_rx_skb_size(int mtu) 66 + { 67 + int size = max(mtu + EMAC_MTU_OVERHEAD, emac_rx_size(mtu)); 68 + return EMAC_DMA_ALIGN(size + 2) + EMAC_RX_SKB_HEADROOM; 69 + } 70 + 71 + /* RX DMA sync size */ 72 + static inline int emac_rx_sync_size(int mtu) 73 + { 74 + return EMAC_DMA_ALIGN(emac_rx_size(mtu) + 2); 75 + } 76 + 77 + /* Driver statistcs is split into two parts to make it more cache friendly: 78 + * - normal statistics (packet count, etc) 79 + * - error statistics 80 + * 81 + * When statistics is requested by ethtool, these parts are concatenated, 82 + * normal one goes first. 83 + * 84 + * Please, keep these structures in sync with emac_stats_keys. 48 85 */ 49 - #ifndef CONFIG_IBM_EMAC_SKBRES 50 - #define SKB_RES 2 51 - #else 52 - #define SKB_RES CONFIG_IBM_EMAC_SKBRES 53 - #endif 54 86 55 - /* Note about alignement. alloc_skb() returns a cache line 56 - * aligned buffer. However, dev_alloc_skb() will add 16 more 57 - * bytes and "reserve" them, so our buffer will actually end 58 - * on a half cache line. What we do is to use directly 59 - * alloc_skb, allocate 16 more bytes to match the total amount 60 - * allocated by dev_alloc_skb(), but we don't reserve. 61 - */ 62 - #define MAX_NUM_BUF_DESC 255 63 - #define DESC_BUF_SIZE 4080 /* max 4096-16 */ 64 - #define DESC_BUF_SIZE_REG (DESC_BUF_SIZE / 16) 87 + /* Normal TX/RX Statistics */ 88 + struct ibm_emac_stats { 89 + u64 rx_packets; 90 + u64 rx_bytes; 91 + u64 tx_packets; 92 + u64 tx_bytes; 93 + u64 rx_packets_csum; 94 + u64 tx_packets_csum; 95 + }; 65 96 66 - /* Transmitter timeout. */ 67 - #define TX_TIMEOUT (2*HZ) 97 + /* Error statistics */ 98 + struct ibm_emac_error_stats { 99 + u64 tx_undo; 68 100 69 - /* MDIO latency delay */ 70 - #define MDIO_DELAY 250 101 + /* Software RX Errors */ 102 + u64 rx_dropped_stack; 103 + u64 rx_dropped_oom; 104 + u64 rx_dropped_error; 105 + u64 rx_dropped_resize; 106 + u64 rx_dropped_mtu; 107 + u64 rx_stopped; 108 + /* BD reported RX errors */ 109 + u64 rx_bd_errors; 110 + u64 rx_bd_overrun; 111 + u64 rx_bd_bad_packet; 112 + u64 rx_bd_runt_packet; 113 + u64 rx_bd_short_event; 114 + u64 rx_bd_alignment_error; 115 + u64 rx_bd_bad_fcs; 116 + u64 rx_bd_packet_too_long; 117 + u64 rx_bd_out_of_range; 118 + u64 rx_bd_in_range; 119 + /* EMAC IRQ reported RX errors */ 120 + u64 rx_parity; 121 + u64 rx_fifo_overrun; 122 + u64 rx_overrun; 123 + u64 rx_bad_packet; 124 + u64 rx_runt_packet; 125 + u64 rx_short_event; 126 + u64 rx_alignment_error; 127 + u64 rx_bad_fcs; 128 + u64 rx_packet_too_long; 129 + u64 rx_out_of_range; 130 + u64 rx_in_range; 71 131 72 - /* Power managment shift registers */ 73 - #define IBM_CPM_EMMII 0 /* Shift value for MII */ 74 - #define IBM_CPM_EMRX 1 /* Shift value for recv */ 75 - #define IBM_CPM_EMTX 2 /* Shift value for MAC */ 76 - #define IBM_CPM_EMAC(x) (((x)>>IBM_CPM_EMMII) | ((x)>>IBM_CPM_EMRX) | ((x)>>IBM_CPM_EMTX)) 132 + /* Software TX Errors */ 133 + u64 tx_dropped; 134 + /* BD reported TX errors */ 135 + u64 tx_bd_errors; 136 + u64 tx_bd_bad_fcs; 137 + u64 tx_bd_carrier_loss; 138 + u64 tx_bd_excessive_deferral; 139 + u64 tx_bd_excessive_collisions; 140 + u64 tx_bd_late_collision; 141 + u64 tx_bd_multple_collisions; 142 + u64 tx_bd_single_collision; 143 + u64 tx_bd_underrun; 144 + u64 tx_bd_sqe; 145 + /* EMAC IRQ reported TX errors */ 146 + u64 tx_parity; 147 + u64 tx_underrun; 148 + u64 tx_sqe; 149 + u64 tx_errors; 150 + }; 77 151 78 - #define ENET_HEADER_SIZE 14 79 - #define ENET_FCS_SIZE 4 80 - #define ENET_DEF_MTU_SIZE 1500 81 - #define ENET_DEF_BUF_SIZE (ENET_DEF_MTU_SIZE + ENET_HEADER_SIZE + ENET_FCS_SIZE) 82 - #define EMAC_MIN_FRAME 64 83 - #define EMAC_MAX_FRAME 9018 84 - #define EMAC_MIN_MTU (EMAC_MIN_FRAME - ENET_HEADER_SIZE - ENET_FCS_SIZE) 85 - #define EMAC_MAX_MTU (EMAC_MAX_FRAME - ENET_HEADER_SIZE - ENET_FCS_SIZE) 86 - 87 - #ifdef CONFIG_IBM_EMAC_ERRMSG 88 - void emac_serr_dump_0(struct net_device *dev); 89 - void emac_serr_dump_1(struct net_device *dev); 90 - void emac_err_dump(struct net_device *dev, int em0isr); 91 - void emac_phy_dump(struct net_device *); 92 - void emac_desc_dump(struct net_device *); 93 - void emac_mac_dump(struct net_device *); 94 - void emac_mal_dump(struct net_device *); 95 - #else 96 - #define emac_serr_dump_0(dev) do { } while (0) 97 - #define emac_serr_dump_1(dev) do { } while (0) 98 - #define emac_err_dump(dev,x) do { } while (0) 99 - #define emac_phy_dump(dev) do { } while (0) 100 - #define emac_desc_dump(dev) do { } while (0) 101 - #define emac_mac_dump(dev) do { } while (0) 102 - #define emac_mal_dump(dev) do { } while (0) 103 - #endif 152 + #define EMAC_ETHTOOL_STATS_COUNT ((sizeof(struct ibm_emac_stats) + \ 153 + sizeof(struct ibm_emac_error_stats)) \ 154 + / sizeof(u64)) 104 155 105 156 struct ocp_enet_private { 106 - struct sk_buff *tx_skb[NUM_TX_BUFF]; 107 - struct sk_buff *rx_skb[NUM_RX_BUFF]; 108 - struct mal_descriptor *tx_desc; 109 - struct mal_descriptor *rx_desc; 110 - struct mal_descriptor *rx_dirty; 111 - struct net_device_stats stats; 112 - int tx_cnt; 113 - int rx_slot; 114 - int dirty_rx; 115 - int tx_slot; 116 - int ack_slot; 117 - int rx_buffer_size; 157 + struct net_device *ndev; /* 0 */ 158 + struct emac_regs *emacp; 159 + 160 + struct mal_descriptor *tx_desc; 161 + int tx_cnt; 162 + int tx_slot; 163 + int ack_slot; 118 164 119 - struct mii_phy phy_mii; 120 - int mii_phy_addr; 121 - int want_autoneg; 122 - int timer_ticks; 123 - struct timer_list link_timer; 124 - struct net_device *mdio_dev; 165 + struct mal_descriptor *rx_desc; 166 + int rx_slot; 167 + struct sk_buff *rx_sg_skb; /* 1 */ 168 + int rx_skb_size; 169 + int rx_sync_size; 125 170 126 - struct ocp_device *rgmii_dev; 127 - int rgmii_input; 171 + struct ibm_emac_stats stats; 172 + struct ocp_device *tah_dev; 128 173 129 - struct ocp_device *zmii_dev; 130 - int zmii_input; 174 + struct ibm_ocp_mal *mal; 175 + struct mal_commac commac; 131 176 132 - struct ibm_ocp_mal *mal; 133 - int mal_tx_chan, mal_rx_chan; 134 - struct mal_commac commac; 177 + struct sk_buff *tx_skb[NUM_TX_BUFF]; 178 + struct sk_buff *rx_skb[NUM_RX_BUFF]; 135 179 136 - struct ocp_device *tah_dev; 180 + struct ocp_device *zmii_dev; 181 + int zmii_input; 182 + struct ocp_enet_private *mdio_dev; 183 + struct ocp_device *rgmii_dev; 184 + int rgmii_input; 137 185 138 - int opened; 139 - int going_away; 140 - int wol_irq; 141 - emac_t *emacp; 142 - struct ocp_device *ocpdev; 143 - struct net_device *ndev; 144 - spinlock_t lock; 186 + struct ocp_def *def; 187 + 188 + struct mii_phy phy; 189 + struct timer_list link_timer; 190 + int reset_failed; 191 + 192 + struct ibm_emac_error_stats estats; 193 + struct net_device_stats nstats; 194 + 195 + struct device* ldev; 145 196 }; 146 - #endif /* _IBM_EMAC_CORE_H_ */ 197 + 198 + /* Ethtool get_regs complex data. 199 + * We want to get not just EMAC registers, but also MAL, ZMII, RGMII, TAH 200 + * when available. 201 + * 202 + * Returned BLOB consists of the ibm_emac_ethtool_regs_hdr, 203 + * MAL registers, EMAC registers and optional ZMII, RGMII, TAH registers. 204 + * Each register component is preceded with emac_ethtool_regs_subhdr. 205 + * Order of the optional headers follows their relative bit posititions 206 + * in emac_ethtool_regs_hdr.components 207 + */ 208 + #define EMAC_ETHTOOL_REGS_ZMII 0x00000001 209 + #define EMAC_ETHTOOL_REGS_RGMII 0x00000002 210 + #define EMAC_ETHTOOL_REGS_TAH 0x00000004 211 + 212 + struct emac_ethtool_regs_hdr { 213 + u32 components; 214 + }; 215 + 216 + struct emac_ethtool_regs_subhdr { 217 + u32 version; 218 + u32 index; 219 + }; 220 + 221 + #endif /* __IBM_EMAC_CORE_H_ */
+183 -194
drivers/net/ibm_emac/ibm_emac_debug.c
··· 1 1 /* 2 - * ibm_ocp_debug.c 2 + * drivers/net/ibm_emac/ibm_emac_debug.c 3 3 * 4 - * This has all the debug routines that where in *_enet.c 4 + * Driver for PowerPC 4xx on-chip ethernet controller, debug print routines. 5 5 * 6 - * Armin Kuster akuster@mvista.com 7 - * April , 2002 8 - * 9 - * Copyright 2002 MontaVista Softare Inc. 6 + * Copyright (c) 2004, 2005 Zultys Technologies 7 + * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net> 10 8 * 11 9 * This program is free software; you can redistribute it and/or modify it 12 10 * under the terms of the GNU General Public License as published by the 13 11 * Free Software Foundation; either version 2 of the License, or (at your 14 12 * option) any later version. 13 + * 15 14 */ 16 - 17 15 #include <linux/config.h> 16 + #include <linux/init.h> 17 + #include <linux/module.h> 18 18 #include <linux/kernel.h> 19 19 #include <linux/netdevice.h> 20 + #include <linux/sysrq.h> 20 21 #include <asm/io.h> 21 - #include "ibm_ocp_mal.h" 22 - #include "ibm_ocp_zmii.h" 23 - #include "ibm_ocp_enet.h" 24 22 25 - extern int emac_phy_read(struct net_device *dev, int mii_id, int reg); 23 + #include "ibm_emac_core.h" 26 24 27 - void emac_phy_dump(struct net_device *dev) 25 + static void emac_desc_dump(int idx, struct ocp_enet_private *p) 28 26 { 29 - struct ocp_enet_private *fep = dev->priv; 30 - unsigned long i; 31 - uint data; 27 + int i; 28 + printk("** EMAC%d TX BDs **\n" 29 + " tx_cnt = %d tx_slot = %d ack_slot = %d\n", 30 + idx, p->tx_cnt, p->tx_slot, p->ack_slot); 31 + for (i = 0; i < NUM_TX_BUFF / 2; ++i) 32 + printk 33 + ("bd[%2d] 0x%08x %c 0x%04x %4u - bd[%2d] 0x%08x %c 0x%04x %4u\n", 34 + i, p->tx_desc[i].data_ptr, p->tx_skb[i] ? 'V' : ' ', 35 + p->tx_desc[i].ctrl, p->tx_desc[i].data_len, 36 + NUM_TX_BUFF / 2 + i, 37 + p->tx_desc[NUM_TX_BUFF / 2 + i].data_ptr, 38 + p->tx_skb[NUM_TX_BUFF / 2 + i] ? 'V' : ' ', 39 + p->tx_desc[NUM_TX_BUFF / 2 + i].ctrl, 40 + p->tx_desc[NUM_TX_BUFF / 2 + i].data_len); 32 41 33 - printk(KERN_DEBUG " Prepare for Phy dump....\n"); 34 - for (i = 0; i < 0x1A; i++) { 35 - data = emac_phy_read(dev, fep->mii_phy_addr, i); 36 - printk(KERN_DEBUG "Phy reg 0x%lx ==> %4x\n", i, data); 37 - if (i == 0x07) 38 - i = 0x0f; 42 + printk("** EMAC%d RX BDs **\n" 43 + " rx_slot = %d rx_stopped = %d rx_skb_size = %d rx_sync_size = %d\n" 44 + " rx_sg_skb = 0x%p\n", 45 + idx, p->rx_slot, p->commac.rx_stopped, p->rx_skb_size, 46 + p->rx_sync_size, p->rx_sg_skb); 47 + for (i = 0; i < NUM_RX_BUFF / 2; ++i) 48 + printk 49 + ("bd[%2d] 0x%08x %c 0x%04x %4u - bd[%2d] 0x%08x %c 0x%04x %4u\n", 50 + i, p->rx_desc[i].data_ptr, p->rx_skb[i] ? 'V' : ' ', 51 + p->rx_desc[i].ctrl, p->rx_desc[i].data_len, 52 + NUM_RX_BUFF / 2 + i, 53 + p->rx_desc[NUM_RX_BUFF / 2 + i].data_ptr, 54 + p->rx_skb[NUM_RX_BUFF / 2 + i] ? 'V' : ' ', 55 + p->rx_desc[NUM_RX_BUFF / 2 + i].ctrl, 56 + p->rx_desc[NUM_RX_BUFF / 2 + i].data_len); 57 + } 58 + 59 + static void emac_mac_dump(int idx, struct ocp_enet_private *dev) 60 + { 61 + struct emac_regs *p = dev->emacp; 62 + 63 + printk("** EMAC%d registers **\n" 64 + "MR0 = 0x%08x MR1 = 0x%08x TMR0 = 0x%08x TMR1 = 0x%08x\n" 65 + "RMR = 0x%08x ISR = 0x%08x ISER = 0x%08x\n" 66 + "IAR = %04x%08x VTPID = 0x%04x VTCI = 0x%04x\n" 67 + "IAHT: 0x%04x 0x%04x 0x%04x 0x%04x " 68 + "GAHT: 0x%04x 0x%04x 0x%04x 0x%04x\n" 69 + "LSA = %04x%08x IPGVR = 0x%04x\n" 70 + "STACR = 0x%08x TRTR = 0x%08x RWMR = 0x%08x\n" 71 + "OCTX = 0x%08x OCRX = 0x%08x IPCR = 0x%08x\n", 72 + idx, in_be32(&p->mr0), in_be32(&p->mr1), 73 + in_be32(&p->tmr0), in_be32(&p->tmr1), 74 + in_be32(&p->rmr), in_be32(&p->isr), in_be32(&p->iser), 75 + in_be32(&p->iahr), in_be32(&p->ialr), in_be32(&p->vtpid), 76 + in_be32(&p->vtci), 77 + in_be32(&p->iaht1), in_be32(&p->iaht2), in_be32(&p->iaht3), 78 + in_be32(&p->iaht4), 79 + in_be32(&p->gaht1), in_be32(&p->gaht2), in_be32(&p->gaht3), 80 + in_be32(&p->gaht4), 81 + in_be32(&p->lsah), in_be32(&p->lsal), in_be32(&p->ipgvr), 82 + in_be32(&p->stacr), in_be32(&p->trtr), in_be32(&p->rwmr), 83 + in_be32(&p->octx), in_be32(&p->ocrx), in_be32(&p->ipcr) 84 + ); 85 + 86 + emac_desc_dump(idx, dev); 87 + } 88 + 89 + static void emac_mal_dump(struct ibm_ocp_mal *mal) 90 + { 91 + struct ocp_func_mal_data *maldata = mal->def->additions; 92 + int i; 93 + 94 + printk("** MAL%d Registers **\n" 95 + "CFG = 0x%08x ESR = 0x%08x IER = 0x%08x\n" 96 + "TX|CASR = 0x%08x CARR = 0x%08x EOBISR = 0x%08x DEIR = 0x%08x\n" 97 + "RX|CASR = 0x%08x CARR = 0x%08x EOBISR = 0x%08x DEIR = 0x%08x\n", 98 + mal->def->index, 99 + get_mal_dcrn(mal, MAL_CFG), get_mal_dcrn(mal, MAL_ESR), 100 + get_mal_dcrn(mal, MAL_IER), 101 + get_mal_dcrn(mal, MAL_TXCASR), get_mal_dcrn(mal, MAL_TXCARR), 102 + get_mal_dcrn(mal, MAL_TXEOBISR), get_mal_dcrn(mal, MAL_TXDEIR), 103 + get_mal_dcrn(mal, MAL_RXCASR), get_mal_dcrn(mal, MAL_RXCARR), 104 + get_mal_dcrn(mal, MAL_RXEOBISR), get_mal_dcrn(mal, MAL_RXDEIR) 105 + ); 106 + 107 + printk("TX|"); 108 + for (i = 0; i < maldata->num_tx_chans; ++i) { 109 + if (i && !(i % 4)) 110 + printk("\n "); 111 + printk("CTP%d = 0x%08x ", i, get_mal_dcrn(mal, MAL_TXCTPR(i))); 39 112 } 40 - } 41 - 42 - void emac_desc_dump(struct net_device *dev) 43 - { 44 - struct ocp_enet_private *fep = dev->priv; 45 - int curr_slot; 46 - 47 - printk(KERN_DEBUG 48 - "dumping the receive descriptors: current slot is %d\n", 49 - fep->rx_slot); 50 - for (curr_slot = 0; curr_slot < NUM_RX_BUFF; curr_slot++) { 51 - printk(KERN_DEBUG 52 - "Desc %02d: status 0x%04x, length %3d, addr 0x%x\n", 53 - curr_slot, fep->rx_desc[curr_slot].ctrl, 54 - fep->rx_desc[curr_slot].data_len, 55 - (unsigned int)fep->rx_desc[curr_slot].data_ptr); 113 + printk("\nRX|"); 114 + for (i = 0; i < maldata->num_rx_chans; ++i) { 115 + if (i && !(i % 4)) 116 + printk("\n "); 117 + printk("CTP%d = 0x%08x ", i, get_mal_dcrn(mal, MAL_RXCTPR(i))); 56 118 } 57 - } 58 - 59 - void emac_mac_dump(struct net_device *dev) 60 - { 61 - struct ocp_enet_private *fep = dev->priv; 62 - volatile emac_t *emacp = fep->emacp; 63 - 64 - printk(KERN_DEBUG "EMAC DEBUG ********** \n"); 65 - printk(KERN_DEBUG "EMAC_M0 ==> 0x%x\n", in_be32(&emacp->em0mr0)); 66 - printk(KERN_DEBUG "EMAC_M1 ==> 0x%x\n", in_be32(&emacp->em0mr1)); 67 - printk(KERN_DEBUG "EMAC_TXM0==> 0x%x\n", in_be32(&emacp->em0tmr0)); 68 - printk(KERN_DEBUG "EMAC_TXM1==> 0x%x\n", in_be32(&emacp->em0tmr1)); 69 - printk(KERN_DEBUG "EMAC_RXM ==> 0x%x\n", in_be32(&emacp->em0rmr)); 70 - printk(KERN_DEBUG "EMAC_ISR ==> 0x%x\n", in_be32(&emacp->em0isr)); 71 - printk(KERN_DEBUG "EMAC_IER ==> 0x%x\n", in_be32(&emacp->em0iser)); 72 - printk(KERN_DEBUG "EMAC_IAH ==> 0x%x\n", in_be32(&emacp->em0iahr)); 73 - printk(KERN_DEBUG "EMAC_IAL ==> 0x%x\n", in_be32(&emacp->em0ialr)); 74 - printk(KERN_DEBUG "EMAC_VLAN_TPID_REG ==> 0x%x\n", 75 - in_be32(&emacp->em0vtpid)); 76 - } 77 - 78 - void emac_mal_dump(struct net_device *dev) 79 - { 80 - struct ibm_ocp_mal *mal = ((struct ocp_enet_private *)dev->priv)->mal; 81 - 82 - printk(KERN_DEBUG " MAL DEBUG ********** \n"); 83 - printk(KERN_DEBUG " MCR ==> 0x%x\n", 84 - (unsigned int)get_mal_dcrn(mal, DCRN_MALCR)); 85 - printk(KERN_DEBUG " ESR ==> 0x%x\n", 86 - (unsigned int)get_mal_dcrn(mal, DCRN_MALESR)); 87 - printk(KERN_DEBUG " IER ==> 0x%x\n", 88 - (unsigned int)get_mal_dcrn(mal, DCRN_MALIER)); 89 - #ifdef CONFIG_40x 90 - printk(KERN_DEBUG " DBR ==> 0x%x\n", 91 - (unsigned int)get_mal_dcrn(mal, DCRN_MALDBR)); 92 - #endif /* CONFIG_40x */ 93 - printk(KERN_DEBUG " TXCASR ==> 0x%x\n", 94 - (unsigned int)get_mal_dcrn(mal, DCRN_MALTXCASR)); 95 - printk(KERN_DEBUG " TXCARR ==> 0x%x\n", 96 - (unsigned int)get_mal_dcrn(mal, DCRN_MALTXCARR)); 97 - printk(KERN_DEBUG " TXEOBISR ==> 0x%x\n", 98 - (unsigned int)get_mal_dcrn(mal, DCRN_MALTXEOBISR)); 99 - printk(KERN_DEBUG " TXDEIR ==> 0x%x\n", 100 - (unsigned int)get_mal_dcrn(mal, DCRN_MALTXDEIR)); 101 - printk(KERN_DEBUG " RXCASR ==> 0x%x\n", 102 - (unsigned int)get_mal_dcrn(mal, DCRN_MALRXCASR)); 103 - printk(KERN_DEBUG " RXCARR ==> 0x%x\n", 104 - (unsigned int)get_mal_dcrn(mal, DCRN_MALRXCARR)); 105 - printk(KERN_DEBUG " RXEOBISR ==> 0x%x\n", 106 - (unsigned int)get_mal_dcrn(mal, DCRN_MALRXEOBISR)); 107 - printk(KERN_DEBUG " RXDEIR ==> 0x%x\n", 108 - (unsigned int)get_mal_dcrn(mal, DCRN_MALRXDEIR)); 109 - printk(KERN_DEBUG " TXCTP0R ==> 0x%x\n", 110 - (unsigned int)get_mal_dcrn(mal, DCRN_MALTXCTP0R)); 111 - printk(KERN_DEBUG " TXCTP1R ==> 0x%x\n", 112 - (unsigned int)get_mal_dcrn(mal, DCRN_MALTXCTP1R)); 113 - printk(KERN_DEBUG " TXCTP2R ==> 0x%x\n", 114 - (unsigned int)get_mal_dcrn(mal, DCRN_MALTXCTP2R)); 115 - printk(KERN_DEBUG " TXCTP3R ==> 0x%x\n", 116 - (unsigned int)get_mal_dcrn(mal, DCRN_MALTXCTP3R)); 117 - printk(KERN_DEBUG " RXCTP0R ==> 0x%x\n", 118 - (unsigned int)get_mal_dcrn(mal, DCRN_MALRXCTP0R)); 119 - printk(KERN_DEBUG " RXCTP1R ==> 0x%x\n", 120 - (unsigned int)get_mal_dcrn(mal, DCRN_MALRXCTP1R)); 121 - printk(KERN_DEBUG " RCBS0 ==> 0x%x\n", 122 - (unsigned int)get_mal_dcrn(mal, DCRN_MALRCBS0)); 123 - printk(KERN_DEBUG " RCBS1 ==> 0x%x\n", 124 - (unsigned int)get_mal_dcrn(mal, DCRN_MALRCBS1)); 125 - } 126 - 127 - void emac_serr_dump_0(struct net_device *dev) 128 - { 129 - struct ibm_ocp_mal *mal = ((struct ocp_enet_private *)dev->priv)->mal; 130 - unsigned long int mal_error, plb_error, plb_addr; 131 - 132 - mal_error = get_mal_dcrn(mal, DCRN_MALESR); 133 - printk(KERN_DEBUG "ppc405_eth_serr: %s channel %ld \n", 134 - (mal_error & 0x40000000) ? "Receive" : 135 - "Transmit", (mal_error & 0x3e000000) >> 25); 136 - printk(KERN_DEBUG " ----- latched error -----\n"); 137 - if (mal_error & MALESR_DE) 138 - printk(KERN_DEBUG " DE: descriptor error\n"); 139 - if (mal_error & MALESR_OEN) 140 - printk(KERN_DEBUG " ONE: OPB non-fullword error\n"); 141 - if (mal_error & MALESR_OTE) 142 - printk(KERN_DEBUG " OTE: OPB timeout error\n"); 143 - if (mal_error & MALESR_OSE) 144 - printk(KERN_DEBUG " OSE: OPB slave error\n"); 145 - 146 - if (mal_error & MALESR_PEIN) { 147 - plb_error = mfdcr(DCRN_PLB0_BESR); 148 - printk(KERN_DEBUG 149 - " PEIN: PLB error, PLB0_BESR is 0x%x\n", 150 - (unsigned int)plb_error); 151 - plb_addr = mfdcr(DCRN_PLB0_BEAR); 152 - printk(KERN_DEBUG 153 - " PEIN: PLB error, PLB0_BEAR is 0x%x\n", 154 - (unsigned int)plb_addr); 119 + printk("\n "); 120 + for (i = 0; i < maldata->num_rx_chans; ++i) { 121 + u32 r = get_mal_dcrn(mal, MAL_RCBS(i)); 122 + if (i && !(i % 3)) 123 + printk("\n "); 124 + printk("RCBS%d = 0x%08x (%d) ", i, r, r * 16); 155 125 } 126 + printk("\n"); 156 127 } 157 128 158 - void emac_serr_dump_1(struct net_device *dev) 129 + static struct ocp_enet_private *__emacs[4]; 130 + static struct ibm_ocp_mal *__mals[1]; 131 + 132 + void emac_dbg_register(int idx, struct ocp_enet_private *dev) 159 133 { 160 - struct ibm_ocp_mal *mal = ((struct ocp_enet_private *)dev->priv)->mal; 161 - int mal_error = get_mal_dcrn(mal, DCRN_MALESR); 134 + unsigned long flags; 162 135 163 - printk(KERN_DEBUG " ----- cumulative errors -----\n"); 164 - if (mal_error & MALESR_DEI) 165 - printk(KERN_DEBUG " DEI: descriptor error interrupt\n"); 166 - if (mal_error & MALESR_ONEI) 167 - printk(KERN_DEBUG " OPB non-fullword error interrupt\n"); 168 - if (mal_error & MALESR_OTEI) 169 - printk(KERN_DEBUG " OTEI: timeout error interrupt\n"); 170 - if (mal_error & MALESR_OSEI) 171 - printk(KERN_DEBUG " OSEI: slave error interrupt\n"); 172 - if (mal_error & MALESR_PBEI) 173 - printk(KERN_DEBUG " PBEI: PLB bus error interrupt\n"); 136 + if (idx >= sizeof(__emacs) / sizeof(__emacs[0])) { 137 + printk(KERN_WARNING 138 + "invalid index %d when registering EMAC for debugging\n", 139 + idx); 140 + return; 141 + } 142 + 143 + local_irq_save(flags); 144 + __emacs[idx] = dev; 145 + local_irq_restore(flags); 174 146 } 175 147 176 - void emac_err_dump(struct net_device *dev, int em0isr) 148 + void mal_dbg_register(int idx, struct ibm_ocp_mal *mal) 177 149 { 178 - printk(KERN_DEBUG "%s: on-chip ethernet error:\n", dev->name); 150 + unsigned long flags; 179 151 180 - if (em0isr & EMAC_ISR_OVR) 181 - printk(KERN_DEBUG " OVR: overrun\n"); 182 - if (em0isr & EMAC_ISR_PP) 183 - printk(KERN_DEBUG " PP: control pause packet\n"); 184 - if (em0isr & EMAC_ISR_BP) 185 - printk(KERN_DEBUG " BP: packet error\n"); 186 - if (em0isr & EMAC_ISR_RP) 187 - printk(KERN_DEBUG " RP: runt packet\n"); 188 - if (em0isr & EMAC_ISR_SE) 189 - printk(KERN_DEBUG " SE: short event\n"); 190 - if (em0isr & EMAC_ISR_ALE) 191 - printk(KERN_DEBUG " ALE: odd number of nibbles in packet\n"); 192 - if (em0isr & EMAC_ISR_BFCS) 193 - printk(KERN_DEBUG " BFCS: bad FCS\n"); 194 - if (em0isr & EMAC_ISR_PTLE) 195 - printk(KERN_DEBUG " PTLE: oversized packet\n"); 196 - if (em0isr & EMAC_ISR_ORE) 197 - printk(KERN_DEBUG 198 - " ORE: packet length field > max allowed LLC\n"); 199 - if (em0isr & EMAC_ISR_IRE) 200 - printk(KERN_DEBUG " IRE: In Range error\n"); 201 - if (em0isr & EMAC_ISR_DBDM) 202 - printk(KERN_DEBUG " DBDM: xmit error or SQE\n"); 203 - if (em0isr & EMAC_ISR_DB0) 204 - printk(KERN_DEBUG " DB0: xmit error or SQE on TX channel 0\n"); 205 - if (em0isr & EMAC_ISR_SE0) 206 - printk(KERN_DEBUG 207 - " SE0: Signal Quality Error test failure from TX channel 0\n"); 208 - if (em0isr & EMAC_ISR_TE0) 209 - printk(KERN_DEBUG " TE0: xmit channel 0 aborted\n"); 210 - if (em0isr & EMAC_ISR_DB1) 211 - printk(KERN_DEBUG " DB1: xmit error or SQE on TX channel \n"); 212 - if (em0isr & EMAC_ISR_SE1) 213 - printk(KERN_DEBUG 214 - " SE1: Signal Quality Error test failure from TX channel 1\n"); 215 - if (em0isr & EMAC_ISR_TE1) 216 - printk(KERN_DEBUG " TE1: xmit channel 1 aborted\n"); 217 - if (em0isr & EMAC_ISR_MOS) 218 - printk(KERN_DEBUG " MOS\n"); 219 - if (em0isr & EMAC_ISR_MOF) 220 - printk(KERN_DEBUG " MOF\n"); 152 + if (idx >= sizeof(__mals) / sizeof(__mals[0])) { 153 + printk(KERN_WARNING 154 + "invalid index %d when registering MAL for debugging\n", 155 + idx); 156 + return; 157 + } 221 158 222 - emac_mac_dump(dev); 223 - emac_mal_dump(dev); 159 + local_irq_save(flags); 160 + __mals[idx] = mal; 161 + local_irq_restore(flags); 224 162 } 163 + 164 + void emac_dbg_dump_all(void) 165 + { 166 + unsigned int i; 167 + unsigned long flags; 168 + 169 + local_irq_save(flags); 170 + 171 + for (i = 0; i < sizeof(__mals) / sizeof(__mals[0]); ++i) 172 + if (__mals[i]) 173 + emac_mal_dump(__mals[i]); 174 + 175 + for (i = 0; i < sizeof(__emacs) / sizeof(__emacs[0]); ++i) 176 + if (__emacs[i]) 177 + emac_mac_dump(i, __emacs[i]); 178 + 179 + local_irq_restore(flags); 180 + } 181 + 182 + #if defined(CONFIG_MAGIC_SYSRQ) 183 + static void emac_sysrq_handler(int key, struct pt_regs *pt_regs, 184 + struct tty_struct *tty) 185 + { 186 + emac_dbg_dump_all(); 187 + } 188 + 189 + static struct sysrq_key_op emac_sysrq_op = { 190 + .handler = emac_sysrq_handler, 191 + .help_msg = "emaC", 192 + .action_msg = "Show EMAC(s) status", 193 + }; 194 + 195 + int __init emac_init_debug(void) 196 + { 197 + return register_sysrq_key('c', &emac_sysrq_op); 198 + } 199 + 200 + void __exit emac_fini_debug(void) 201 + { 202 + unregister_sysrq_key('c', &emac_sysrq_op); 203 + } 204 + 205 + #else 206 + int __init emac_init_debug(void) 207 + { 208 + return 0; 209 + } 210 + void __exit emac_fini_debug(void) 211 + { 212 + } 213 + #endif /* CONFIG_MAGIC_SYSRQ */
+63
drivers/net/ibm_emac/ibm_emac_debug.h
··· 1 + /* 2 + * drivers/net/ibm_emac/ibm_ocp_debug.h 3 + * 4 + * Driver for PowerPC 4xx on-chip ethernet controller, debug print routines. 5 + * 6 + * Copyright (c) 2004, 2005 Zultys Technologies 7 + * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net> 8 + * 9 + * This program is free software; you can redistribute it and/or modify it 10 + * under the terms of the GNU General Public License as published by the 11 + * Free Software Foundation; either version 2 of the License, or (at your 12 + * option) any later version. 13 + * 14 + */ 15 + #ifndef __IBM_EMAC_DEBUG_H_ 16 + #define __IBM_EMAC_DEBUG_H_ 17 + 18 + #include <linux/config.h> 19 + #include <linux/init.h> 20 + #include "ibm_emac_core.h" 21 + #include "ibm_emac_mal.h" 22 + 23 + #if defined(CONFIG_IBM_EMAC_DEBUG) 24 + void emac_dbg_register(int idx, struct ocp_enet_private *dev); 25 + void mal_dbg_register(int idx, struct ibm_ocp_mal *mal); 26 + int emac_init_debug(void) __init; 27 + void emac_fini_debug(void) __exit; 28 + void emac_dbg_dump_all(void); 29 + # define DBG_LEVEL 1 30 + #else 31 + # define emac_dbg_register(x,y) ((void)0) 32 + # define mal_dbg_register(x,y) ((void)0) 33 + # define emac_init_debug() ((void)0) 34 + # define emac_fini_debug() ((void)0) 35 + # define emac_dbg_dump_all() ((void)0) 36 + # define DBG_LEVEL 0 37 + #endif 38 + 39 + #if DBG_LEVEL > 0 40 + # define DBG(f,x...) printk("emac" f, ##x) 41 + # define MAL_DBG(f,x...) printk("mal" f, ##x) 42 + # define ZMII_DBG(f,x...) printk("zmii" f, ##x) 43 + # define RGMII_DBG(f,x...) printk("rgmii" f, ##x) 44 + # define NL "\n" 45 + #else 46 + # define DBG(f,x...) ((void)0) 47 + # define MAL_DBG(f,x...) ((void)0) 48 + # define ZMII_DBG(f,x...) ((void)0) 49 + # define RGMII_DBG(f,x...) ((void)0) 50 + #endif 51 + #if DBG_LEVEL > 1 52 + # define DBG2(f,x...) DBG(f, ##x) 53 + # define MAL_DBG2(f,x...) MAL_DBG(f, ##x) 54 + # define ZMII_DBG2(f,x...) ZMII_DBG(f, ##x) 55 + # define RGMII_DBG2(f,x...) RGMII_DBG(f, ##x) 56 + #else 57 + # define DBG2(f,x...) ((void)0) 58 + # define MAL_DBG2(f,x...) ((void)0) 59 + # define ZMII_DBG2(f,x...) ((void)0) 60 + # define RGMII_DBG2(f,x...) ((void)0) 61 + #endif 62 + 63 + #endif /* __IBM_EMAC_DEBUG_H_ */
+403 -283
drivers/net/ibm_emac/ibm_emac_mal.c
··· 1 1 /* 2 - * ibm_ocp_mal.c 2 + * drivers/net/ibm_emac/ibm_emac_mal.c 3 3 * 4 - * Armin Kuster akuster@mvista.com 5 - * Juen, 2002 4 + * Memory Access Layer (MAL) support 5 + * 6 + * Copyright (c) 2004, 2005 Zultys Technologies. 7 + * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net> 6 8 * 7 - * Copyright 2002 MontaVista Softare Inc. 9 + * Based on original work by 10 + * Benjamin Herrenschmidt <benh@kernel.crashing.org>, 11 + * David Gibson <hermes@gibson.dropbear.id.au>, 12 + * 13 + * Armin Kuster <akuster@mvista.com> 14 + * Copyright 2002 MontaVista Softare Inc. 8 15 * 9 16 * This program is free software; you can redistribute it and/or modify it 10 17 * under the terms of the GNU General Public License as published by the 11 18 * Free Software Foundation; either version 2 of the License, or (at your 12 19 * option) any later version. 20 + * 13 21 */ 14 - 15 22 #include <linux/config.h> 16 23 #include <linux/module.h> 17 24 #include <linux/kernel.h> 18 25 #include <linux/errno.h> 19 26 #include <linux/netdevice.h> 20 27 #include <linux/init.h> 28 + #include <linux/interrupt.h> 21 29 #include <linux/dma-mapping.h> 22 30 23 - #include <asm/io.h> 24 - #include <asm/irq.h> 25 31 #include <asm/ocp.h> 26 32 33 + #include "ibm_emac_core.h" 27 34 #include "ibm_emac_mal.h" 35 + #include "ibm_emac_debug.h" 28 36 29 - // Locking: Should we share a lock with the client ? The client could provide 30 - // a lock pointer (optionally) in the commac structure... I don't think this is 31 - // really necessary though 32 - 33 - /* This lock protects the commac list. On today UP implementations, it's 34 - * really only used as IRQ protection in mal_{register,unregister}_commac() 35 - */ 36 - static DEFINE_RWLOCK(mal_list_lock); 37 - 38 - int mal_register_commac(struct ibm_ocp_mal *mal, struct mal_commac *commac) 37 + int __init mal_register_commac(struct ibm_ocp_mal *mal, 38 + struct mal_commac *commac) 39 39 { 40 40 unsigned long flags; 41 + local_irq_save(flags); 41 42 42 - write_lock_irqsave(&mal_list_lock, flags); 43 + MAL_DBG("%d: reg(%08x, %08x)" NL, mal->def->index, 44 + commac->tx_chan_mask, commac->rx_chan_mask); 43 45 44 - /* Don't let multiple commacs claim the same channel */ 46 + /* Don't let multiple commacs claim the same channel(s) */ 45 47 if ((mal->tx_chan_mask & commac->tx_chan_mask) || 46 48 (mal->rx_chan_mask & commac->rx_chan_mask)) { 47 - write_unlock_irqrestore(&mal_list_lock, flags); 49 + local_irq_restore(flags); 50 + printk(KERN_WARNING "mal%d: COMMAC channels conflict!\n", 51 + mal->def->index); 48 52 return -EBUSY; 49 53 } 50 54 51 55 mal->tx_chan_mask |= commac->tx_chan_mask; 52 56 mal->rx_chan_mask |= commac->rx_chan_mask; 57 + list_add(&commac->list, &mal->list); 53 58 54 - list_add(&commac->list, &mal->commac); 55 - 56 - write_unlock_irqrestore(&mal_list_lock, flags); 57 - 59 + local_irq_restore(flags); 58 60 return 0; 59 61 } 60 62 61 - int mal_unregister_commac(struct ibm_ocp_mal *mal, struct mal_commac *commac) 63 + void __exit mal_unregister_commac(struct ibm_ocp_mal *mal, 64 + struct mal_commac *commac) 62 65 { 63 66 unsigned long flags; 67 + local_irq_save(flags); 64 68 65 - write_lock_irqsave(&mal_list_lock, flags); 69 + MAL_DBG("%d: unreg(%08x, %08x)" NL, mal->def->index, 70 + commac->tx_chan_mask, commac->rx_chan_mask); 66 71 67 72 mal->tx_chan_mask &= ~commac->tx_chan_mask; 68 73 mal->rx_chan_mask &= ~commac->rx_chan_mask; 69 - 70 74 list_del_init(&commac->list); 71 75 72 - write_unlock_irqrestore(&mal_list_lock, flags); 73 - 74 - return 0; 76 + local_irq_restore(flags); 75 77 } 76 78 77 79 int mal_set_rcbs(struct ibm_ocp_mal *mal, int channel, unsigned long size) 78 80 { 79 - switch (channel) { 80 - case 0: 81 - set_mal_dcrn(mal, DCRN_MALRCBS0, size); 82 - break; 83 - #ifdef DCRN_MALRCBS1 84 - case 1: 85 - set_mal_dcrn(mal, DCRN_MALRCBS1, size); 86 - break; 87 - #endif 88 - #ifdef DCRN_MALRCBS2 89 - case 2: 90 - set_mal_dcrn(mal, DCRN_MALRCBS2, size); 91 - break; 92 - #endif 93 - #ifdef DCRN_MALRCBS3 94 - case 3: 95 - set_mal_dcrn(mal, DCRN_MALRCBS3, size); 96 - break; 97 - #endif 98 - default: 81 + struct ocp_func_mal_data *maldata = mal->def->additions; 82 + BUG_ON(channel < 0 || channel >= maldata->num_rx_chans || 83 + size > MAL_MAX_RX_SIZE); 84 + 85 + MAL_DBG("%d: set_rbcs(%d, %lu)" NL, mal->def->index, channel, size); 86 + 87 + if (size & 0xf) { 88 + printk(KERN_WARNING 89 + "mal%d: incorrect RX size %lu for the channel %d\n", 90 + mal->def->index, size, channel); 99 91 return -EINVAL; 100 92 } 101 93 94 + set_mal_dcrn(mal, MAL_RCBS(channel), size >> 4); 102 95 return 0; 96 + } 97 + 98 + int mal_tx_bd_offset(struct ibm_ocp_mal *mal, int channel) 99 + { 100 + struct ocp_func_mal_data *maldata = mal->def->additions; 101 + BUG_ON(channel < 0 || channel >= maldata->num_tx_chans); 102 + return channel * NUM_TX_BUFF; 103 + } 104 + 105 + int mal_rx_bd_offset(struct ibm_ocp_mal *mal, int channel) 106 + { 107 + struct ocp_func_mal_data *maldata = mal->def->additions; 108 + BUG_ON(channel < 0 || channel >= maldata->num_rx_chans); 109 + return maldata->num_tx_chans * NUM_TX_BUFF + channel * NUM_RX_BUFF; 110 + } 111 + 112 + void mal_enable_tx_channel(struct ibm_ocp_mal *mal, int channel) 113 + { 114 + local_bh_disable(); 115 + MAL_DBG("%d: enable_tx(%d)" NL, mal->def->index, channel); 116 + set_mal_dcrn(mal, MAL_TXCASR, 117 + get_mal_dcrn(mal, MAL_TXCASR) | MAL_CHAN_MASK(channel)); 118 + local_bh_enable(); 119 + } 120 + 121 + void mal_disable_tx_channel(struct ibm_ocp_mal *mal, int channel) 122 + { 123 + set_mal_dcrn(mal, MAL_TXCARR, MAL_CHAN_MASK(channel)); 124 + MAL_DBG("%d: disable_tx(%d)" NL, mal->def->index, channel); 125 + } 126 + 127 + void mal_enable_rx_channel(struct ibm_ocp_mal *mal, int channel) 128 + { 129 + local_bh_disable(); 130 + MAL_DBG("%d: enable_rx(%d)" NL, mal->def->index, channel); 131 + set_mal_dcrn(mal, MAL_RXCASR, 132 + get_mal_dcrn(mal, MAL_RXCASR) | MAL_CHAN_MASK(channel)); 133 + local_bh_enable(); 134 + } 135 + 136 + void mal_disable_rx_channel(struct ibm_ocp_mal *mal, int channel) 137 + { 138 + set_mal_dcrn(mal, MAL_RXCARR, MAL_CHAN_MASK(channel)); 139 + MAL_DBG("%d: disable_rx(%d)" NL, mal->def->index, channel); 140 + } 141 + 142 + void mal_poll_add(struct ibm_ocp_mal *mal, struct mal_commac *commac) 143 + { 144 + local_bh_disable(); 145 + MAL_DBG("%d: poll_add(%p)" NL, mal->def->index, commac); 146 + list_add_tail(&commac->poll_list, &mal->poll_list); 147 + local_bh_enable(); 148 + } 149 + 150 + void mal_poll_del(struct ibm_ocp_mal *mal, struct mal_commac *commac) 151 + { 152 + local_bh_disable(); 153 + MAL_DBG("%d: poll_del(%p)" NL, mal->def->index, commac); 154 + list_del(&commac->poll_list); 155 + local_bh_enable(); 156 + } 157 + 158 + /* synchronized by mal_poll() */ 159 + static inline void mal_enable_eob_irq(struct ibm_ocp_mal *mal) 160 + { 161 + MAL_DBG2("%d: enable_irq" NL, mal->def->index); 162 + set_mal_dcrn(mal, MAL_CFG, get_mal_dcrn(mal, MAL_CFG) | MAL_CFG_EOPIE); 163 + } 164 + 165 + /* synchronized by __LINK_STATE_RX_SCHED bit in ndev->state */ 166 + static inline void mal_disable_eob_irq(struct ibm_ocp_mal *mal) 167 + { 168 + set_mal_dcrn(mal, MAL_CFG, get_mal_dcrn(mal, MAL_CFG) & ~MAL_CFG_EOPIE); 169 + MAL_DBG2("%d: disable_irq" NL, mal->def->index); 103 170 } 104 171 105 172 static irqreturn_t mal_serr(int irq, void *dev_instance, struct pt_regs *regs) 106 173 { 107 174 struct ibm_ocp_mal *mal = dev_instance; 108 - unsigned long mal_error; 109 - 110 - /* 111 - * This SERR applies to one of the devices on the MAL, here we charge 112 - * it against the first EMAC registered for the MAL. 113 - */ 114 - 115 - mal_error = get_mal_dcrn(mal, DCRN_MALESR); 116 - 117 - printk(KERN_ERR "%s: System Error (MALESR=%lx)\n", 118 - "MAL" /* FIXME: get the name right */ , mal_error); 119 - 120 - /* FIXME: decipher error */ 121 - /* DIXME: distribute to commacs, if possible */ 175 + u32 esr = get_mal_dcrn(mal, MAL_ESR); 122 176 123 177 /* Clear the error status register */ 124 - set_mal_dcrn(mal, DCRN_MALESR, mal_error); 178 + set_mal_dcrn(mal, MAL_ESR, esr); 125 179 180 + MAL_DBG("%d: SERR %08x" NL, mal->def->index, esr); 181 + 182 + if (esr & MAL_ESR_EVB) { 183 + if (esr & MAL_ESR_DE) { 184 + /* We ignore Descriptor error, 185 + * TXDE or RXDE interrupt will be generated anyway. 186 + */ 187 + return IRQ_HANDLED; 188 + } 189 + 190 + if (esr & MAL_ESR_PEIN) { 191 + /* PLB error, it's probably buggy hardware or 192 + * incorrect physical address in BD (i.e. bug) 193 + */ 194 + if (net_ratelimit()) 195 + printk(KERN_ERR 196 + "mal%d: system error, PLB (ESR = 0x%08x)\n", 197 + mal->def->index, esr); 198 + return IRQ_HANDLED; 199 + } 200 + 201 + /* OPB error, it's probably buggy hardware or incorrect EBC setup */ 202 + if (net_ratelimit()) 203 + printk(KERN_ERR 204 + "mal%d: system error, OPB (ESR = 0x%08x)\n", 205 + mal->def->index, esr); 206 + } 126 207 return IRQ_HANDLED; 208 + } 209 + 210 + static inline void mal_schedule_poll(struct ibm_ocp_mal *mal) 211 + { 212 + if (likely(netif_rx_schedule_prep(&mal->poll_dev))) { 213 + MAL_DBG2("%d: schedule_poll" NL, mal->def->index); 214 + mal_disable_eob_irq(mal); 215 + __netif_rx_schedule(&mal->poll_dev); 216 + } else 217 + MAL_DBG2("%d: already in poll" NL, mal->def->index); 127 218 } 128 219 129 220 static irqreturn_t mal_txeob(int irq, void *dev_instance, struct pt_regs *regs) 130 221 { 131 222 struct ibm_ocp_mal *mal = dev_instance; 132 - struct list_head *l; 133 - unsigned long isr; 134 - 135 - isr = get_mal_dcrn(mal, DCRN_MALTXEOBISR); 136 - set_mal_dcrn(mal, DCRN_MALTXEOBISR, isr); 137 - 138 - read_lock(&mal_list_lock); 139 - list_for_each(l, &mal->commac) { 140 - struct mal_commac *mc = list_entry(l, struct mal_commac, list); 141 - 142 - if (isr & mc->tx_chan_mask) { 143 - mc->ops->txeob(mc->dev, isr & mc->tx_chan_mask); 144 - } 145 - } 146 - read_unlock(&mal_list_lock); 147 - 223 + u32 r = get_mal_dcrn(mal, MAL_TXEOBISR); 224 + MAL_DBG2("%d: txeob %08x" NL, mal->def->index, r); 225 + mal_schedule_poll(mal); 226 + set_mal_dcrn(mal, MAL_TXEOBISR, r); 148 227 return IRQ_HANDLED; 149 228 } 150 229 151 230 static irqreturn_t mal_rxeob(int irq, void *dev_instance, struct pt_regs *regs) 152 231 { 153 232 struct ibm_ocp_mal *mal = dev_instance; 154 - struct list_head *l; 155 - unsigned long isr; 156 - 157 - isr = get_mal_dcrn(mal, DCRN_MALRXEOBISR); 158 - set_mal_dcrn(mal, DCRN_MALRXEOBISR, isr); 159 - 160 - read_lock(&mal_list_lock); 161 - list_for_each(l, &mal->commac) { 162 - struct mal_commac *mc = list_entry(l, struct mal_commac, list); 163 - 164 - if (isr & mc->rx_chan_mask) { 165 - mc->ops->rxeob(mc->dev, isr & mc->rx_chan_mask); 166 - } 167 - } 168 - read_unlock(&mal_list_lock); 169 - 233 + u32 r = get_mal_dcrn(mal, MAL_RXEOBISR); 234 + MAL_DBG2("%d: rxeob %08x" NL, mal->def->index, r); 235 + mal_schedule_poll(mal); 236 + set_mal_dcrn(mal, MAL_RXEOBISR, r); 170 237 return IRQ_HANDLED; 171 238 } 172 239 173 240 static irqreturn_t mal_txde(int irq, void *dev_instance, struct pt_regs *regs) 174 241 { 175 242 struct ibm_ocp_mal *mal = dev_instance; 176 - struct list_head *l; 177 - unsigned long deir; 243 + u32 deir = get_mal_dcrn(mal, MAL_TXDEIR); 244 + set_mal_dcrn(mal, MAL_TXDEIR, deir); 178 245 179 - deir = get_mal_dcrn(mal, DCRN_MALTXDEIR); 246 + MAL_DBG("%d: txde %08x" NL, mal->def->index, deir); 180 247 181 - /* FIXME: print which MAL correctly */ 182 - printk(KERN_WARNING "%s: Tx descriptor error (MALTXDEIR=%lx)\n", 183 - "MAL", deir); 184 - 185 - read_lock(&mal_list_lock); 186 - list_for_each(l, &mal->commac) { 187 - struct mal_commac *mc = list_entry(l, struct mal_commac, list); 188 - 189 - if (deir & mc->tx_chan_mask) { 190 - mc->ops->txde(mc->dev, deir & mc->tx_chan_mask); 191 - } 192 - } 193 - read_unlock(&mal_list_lock); 248 + if (net_ratelimit()) 249 + printk(KERN_ERR 250 + "mal%d: TX descriptor error (TXDEIR = 0x%08x)\n", 251 + mal->def->index, deir); 194 252 195 253 return IRQ_HANDLED; 196 254 } 197 255 198 - /* 199 - * This interrupt should be very rare at best. This occurs when 200 - * the hardware has a problem with the receive descriptors. The manual 201 - * states that it occurs when the hardware cannot the receive descriptor 202 - * empty bit is not set. The recovery mechanism will be to 203 - * traverse through the descriptors, handle any that are marked to be 204 - * handled and reinitialize each along the way. At that point the driver 205 - * will be restarted. 206 - */ 207 256 static irqreturn_t mal_rxde(int irq, void *dev_instance, struct pt_regs *regs) 208 257 { 209 258 struct ibm_ocp_mal *mal = dev_instance; 210 259 struct list_head *l; 211 - unsigned long deir; 260 + u32 deir = get_mal_dcrn(mal, MAL_RXDEIR); 212 261 213 - deir = get_mal_dcrn(mal, DCRN_MALRXDEIR); 262 + MAL_DBG("%d: rxde %08x" NL, mal->def->index, deir); 214 263 215 - /* 216 - * This really is needed. This case encountered in stress testing. 217 - */ 218 - if (deir == 0) 219 - return IRQ_HANDLED; 220 - 221 - /* FIXME: print which MAL correctly */ 222 - printk(KERN_WARNING "%s: Rx descriptor error (MALRXDEIR=%lx)\n", 223 - "MAL", deir); 224 - 225 - read_lock(&mal_list_lock); 226 - list_for_each(l, &mal->commac) { 264 + list_for_each(l, &mal->list) { 227 265 struct mal_commac *mc = list_entry(l, struct mal_commac, list); 228 - 229 266 if (deir & mc->rx_chan_mask) { 230 - mc->ops->rxde(mc->dev, deir & mc->rx_chan_mask); 267 + mc->rx_stopped = 1; 268 + mc->ops->rxde(mc->dev); 231 269 } 232 270 } 233 - read_unlock(&mal_list_lock); 271 + 272 + mal_schedule_poll(mal); 273 + set_mal_dcrn(mal, MAL_RXDEIR, deir); 234 274 235 275 return IRQ_HANDLED; 236 276 } 237 277 278 + static int mal_poll(struct net_device *ndev, int *budget) 279 + { 280 + struct ibm_ocp_mal *mal = ndev->priv; 281 + struct list_head *l; 282 + int rx_work_limit = min(ndev->quota, *budget), received = 0, done; 283 + 284 + MAL_DBG2("%d: poll(%d) %d ->" NL, mal->def->index, *budget, 285 + rx_work_limit); 286 + again: 287 + /* Process TX skbs */ 288 + list_for_each(l, &mal->poll_list) { 289 + struct mal_commac *mc = 290 + list_entry(l, struct mal_commac, poll_list); 291 + mc->ops->poll_tx(mc->dev); 292 + } 293 + 294 + /* Process RX skbs. 295 + * We _might_ need something more smart here to enforce polling fairness. 296 + */ 297 + list_for_each(l, &mal->poll_list) { 298 + struct mal_commac *mc = 299 + list_entry(l, struct mal_commac, poll_list); 300 + int n = mc->ops->poll_rx(mc->dev, rx_work_limit); 301 + if (n) { 302 + received += n; 303 + rx_work_limit -= n; 304 + if (rx_work_limit <= 0) { 305 + done = 0; 306 + goto more_work; // XXX What if this is the last one ? 307 + } 308 + } 309 + } 310 + 311 + /* We need to disable IRQs to protect from RXDE IRQ here */ 312 + local_irq_disable(); 313 + __netif_rx_complete(ndev); 314 + mal_enable_eob_irq(mal); 315 + local_irq_enable(); 316 + 317 + done = 1; 318 + 319 + /* Check for "rotting" packet(s) */ 320 + list_for_each(l, &mal->poll_list) { 321 + struct mal_commac *mc = 322 + list_entry(l, struct mal_commac, poll_list); 323 + if (unlikely(mc->ops->peek_rx(mc->dev) || mc->rx_stopped)) { 324 + MAL_DBG2("%d: rotting packet" NL, mal->def->index); 325 + if (netif_rx_reschedule(ndev, received)) 326 + mal_disable_eob_irq(mal); 327 + else 328 + MAL_DBG2("%d: already in poll list" NL, 329 + mal->def->index); 330 + 331 + if (rx_work_limit > 0) 332 + goto again; 333 + else 334 + goto more_work; 335 + } 336 + mc->ops->poll_tx(mc->dev); 337 + } 338 + 339 + more_work: 340 + ndev->quota -= received; 341 + *budget -= received; 342 + 343 + MAL_DBG2("%d: poll() %d <- %d" NL, mal->def->index, *budget, 344 + done ? 0 : 1); 345 + return done ? 0 : 1; 346 + } 347 + 348 + static void mal_reset(struct ibm_ocp_mal *mal) 349 + { 350 + int n = 10; 351 + MAL_DBG("%d: reset" NL, mal->def->index); 352 + 353 + set_mal_dcrn(mal, MAL_CFG, MAL_CFG_SR); 354 + 355 + /* Wait for reset to complete (1 system clock) */ 356 + while ((get_mal_dcrn(mal, MAL_CFG) & MAL_CFG_SR) && n) 357 + --n; 358 + 359 + if (unlikely(!n)) 360 + printk(KERN_ERR "mal%d: reset timeout\n", mal->def->index); 361 + } 362 + 363 + int mal_get_regs_len(struct ibm_ocp_mal *mal) 364 + { 365 + return sizeof(struct emac_ethtool_regs_subhdr) + 366 + sizeof(struct ibm_mal_regs); 367 + } 368 + 369 + void *mal_dump_regs(struct ibm_ocp_mal *mal, void *buf) 370 + { 371 + struct emac_ethtool_regs_subhdr *hdr = buf; 372 + struct ibm_mal_regs *regs = (struct ibm_mal_regs *)(hdr + 1); 373 + struct ocp_func_mal_data *maldata = mal->def->additions; 374 + int i; 375 + 376 + hdr->version = MAL_VERSION; 377 + hdr->index = mal->def->index; 378 + 379 + regs->tx_count = maldata->num_tx_chans; 380 + regs->rx_count = maldata->num_rx_chans; 381 + 382 + regs->cfg = get_mal_dcrn(mal, MAL_CFG); 383 + regs->esr = get_mal_dcrn(mal, MAL_ESR); 384 + regs->ier = get_mal_dcrn(mal, MAL_IER); 385 + regs->tx_casr = get_mal_dcrn(mal, MAL_TXCASR); 386 + regs->tx_carr = get_mal_dcrn(mal, MAL_TXCARR); 387 + regs->tx_eobisr = get_mal_dcrn(mal, MAL_TXEOBISR); 388 + regs->tx_deir = get_mal_dcrn(mal, MAL_TXDEIR); 389 + regs->rx_casr = get_mal_dcrn(mal, MAL_RXCASR); 390 + regs->rx_carr = get_mal_dcrn(mal, MAL_RXCARR); 391 + regs->rx_eobisr = get_mal_dcrn(mal, MAL_RXEOBISR); 392 + regs->rx_deir = get_mal_dcrn(mal, MAL_RXDEIR); 393 + 394 + for (i = 0; i < regs->tx_count; ++i) 395 + regs->tx_ctpr[i] = get_mal_dcrn(mal, MAL_TXCTPR(i)); 396 + 397 + for (i = 0; i < regs->rx_count; ++i) { 398 + regs->rx_ctpr[i] = get_mal_dcrn(mal, MAL_RXCTPR(i)); 399 + regs->rcbs[i] = get_mal_dcrn(mal, MAL_RCBS(i)); 400 + } 401 + return regs + 1; 402 + } 403 + 238 404 static int __init mal_probe(struct ocp_device *ocpdev) 239 405 { 240 - struct ibm_ocp_mal *mal = NULL; 406 + struct ibm_ocp_mal *mal; 241 407 struct ocp_func_mal_data *maldata; 242 - int err = 0; 408 + int err = 0, i, bd_size; 243 409 244 - maldata = (struct ocp_func_mal_data *)ocpdev->def->additions; 410 + MAL_DBG("%d: probe" NL, ocpdev->def->index); 411 + 412 + maldata = ocpdev->def->additions; 245 413 if (maldata == NULL) { 246 - printk(KERN_ERR "mal%d: Missing additional datas !\n", 414 + printk(KERN_ERR "mal%d: missing additional data!\n", 247 415 ocpdev->def->index); 248 416 return -ENODEV; 249 417 } 250 418 251 - mal = kmalloc(sizeof(struct ibm_ocp_mal), GFP_KERNEL); 252 - if (mal == NULL) { 419 + mal = kzalloc(sizeof(struct ibm_ocp_mal), GFP_KERNEL); 420 + if (!mal) { 253 421 printk(KERN_ERR 254 - "mal%d: Out of memory allocating MAL structure !\n", 422 + "mal%d: out of memory allocating MAL structure!\n", 255 423 ocpdev->def->index); 256 424 return -ENOMEM; 257 425 } 258 - memset(mal, 0, sizeof(*mal)); 426 + mal->dcrbase = maldata->dcr_base; 427 + mal->def = ocpdev->def; 259 428 260 - switch (ocpdev->def->index) { 261 - case 0: 262 - mal->dcrbase = DCRN_MAL_BASE; 263 - break; 264 - #ifdef DCRN_MAL1_BASE 265 - case 1: 266 - mal->dcrbase = DCRN_MAL1_BASE; 267 - break; 268 - #endif 269 - default: 270 - BUG(); 271 - } 429 + INIT_LIST_HEAD(&mal->poll_list); 430 + set_bit(__LINK_STATE_START, &mal->poll_dev.state); 431 + mal->poll_dev.weight = CONFIG_IBM_EMAC_POLL_WEIGHT; 432 + mal->poll_dev.poll = mal_poll; 433 + mal->poll_dev.priv = mal; 434 + atomic_set(&mal->poll_dev.refcnt, 1); 272 435 273 - /**************************/ 436 + INIT_LIST_HEAD(&mal->list); 274 437 275 - INIT_LIST_HEAD(&mal->commac); 276 - 277 - set_mal_dcrn(mal, DCRN_MALRXCARR, 0xFFFFFFFF); 278 - set_mal_dcrn(mal, DCRN_MALTXCARR, 0xFFFFFFFF); 279 - 280 - set_mal_dcrn(mal, DCRN_MALCR, MALCR_MMSR); /* 384 */ 281 - /* FIXME: Add delay */ 438 + /* Load power-on reset defaults */ 439 + mal_reset(mal); 282 440 283 441 /* Set the MAL configuration register */ 284 - set_mal_dcrn(mal, DCRN_MALCR, 285 - MALCR_PLBB | MALCR_OPBBL | MALCR_LEA | 286 - MALCR_PLBLT_DEFAULT); 442 + set_mal_dcrn(mal, MAL_CFG, MAL_CFG_DEFAULT | MAL_CFG_PLBB | 443 + MAL_CFG_OPBBL | MAL_CFG_LEA); 287 444 288 - /* It would be nice to allocate buffers separately for each 289 - * channel, but we can't because the channels share the upper 290 - * 13 bits of address lines. Each channels buffer must also 291 - * be 4k aligned, so we allocate 4k for each channel. This is 292 - * inefficient FIXME: do better, if possible */ 293 - mal->tx_virt_addr = dma_alloc_coherent(&ocpdev->dev, 294 - MAL_DT_ALIGN * 295 - maldata->num_tx_chans, 296 - &mal->tx_phys_addr, GFP_KERNEL); 297 - if (mal->tx_virt_addr == NULL) { 445 + mal_enable_eob_irq(mal); 446 + 447 + /* Allocate space for BD rings */ 448 + BUG_ON(maldata->num_tx_chans <= 0 || maldata->num_tx_chans > 32); 449 + BUG_ON(maldata->num_rx_chans <= 0 || maldata->num_rx_chans > 32); 450 + bd_size = sizeof(struct mal_descriptor) * 451 + (NUM_TX_BUFF * maldata->num_tx_chans + 452 + NUM_RX_BUFF * maldata->num_rx_chans); 453 + mal->bd_virt = 454 + dma_alloc_coherent(&ocpdev->dev, bd_size, &mal->bd_dma, GFP_KERNEL); 455 + 456 + if (!mal->bd_virt) { 298 457 printk(KERN_ERR 299 - "mal%d: Out of memory allocating MAL descriptors !\n", 300 - ocpdev->def->index); 458 + "mal%d: out of memory allocating RX/TX descriptors!\n", 459 + mal->def->index); 301 460 err = -ENOMEM; 302 461 goto fail; 303 462 } 463 + memset(mal->bd_virt, 0, bd_size); 304 464 305 - /* God, oh, god, I hate DCRs */ 306 - set_mal_dcrn(mal, DCRN_MALTXCTP0R, mal->tx_phys_addr); 307 - #ifdef DCRN_MALTXCTP1R 308 - if (maldata->num_tx_chans > 1) 309 - set_mal_dcrn(mal, DCRN_MALTXCTP1R, 310 - mal->tx_phys_addr + MAL_DT_ALIGN); 311 - #endif /* DCRN_MALTXCTP1R */ 312 - #ifdef DCRN_MALTXCTP2R 313 - if (maldata->num_tx_chans > 2) 314 - set_mal_dcrn(mal, DCRN_MALTXCTP2R, 315 - mal->tx_phys_addr + 2 * MAL_DT_ALIGN); 316 - #endif /* DCRN_MALTXCTP2R */ 317 - #ifdef DCRN_MALTXCTP3R 318 - if (maldata->num_tx_chans > 3) 319 - set_mal_dcrn(mal, DCRN_MALTXCTP3R, 320 - mal->tx_phys_addr + 3 * MAL_DT_ALIGN); 321 - #endif /* DCRN_MALTXCTP3R */ 322 - #ifdef DCRN_MALTXCTP4R 323 - if (maldata->num_tx_chans > 4) 324 - set_mal_dcrn(mal, DCRN_MALTXCTP4R, 325 - mal->tx_phys_addr + 4 * MAL_DT_ALIGN); 326 - #endif /* DCRN_MALTXCTP4R */ 327 - #ifdef DCRN_MALTXCTP5R 328 - if (maldata->num_tx_chans > 5) 329 - set_mal_dcrn(mal, DCRN_MALTXCTP5R, 330 - mal->tx_phys_addr + 5 * MAL_DT_ALIGN); 331 - #endif /* DCRN_MALTXCTP5R */ 332 - #ifdef DCRN_MALTXCTP6R 333 - if (maldata->num_tx_chans > 6) 334 - set_mal_dcrn(mal, DCRN_MALTXCTP6R, 335 - mal->tx_phys_addr + 6 * MAL_DT_ALIGN); 336 - #endif /* DCRN_MALTXCTP6R */ 337 - #ifdef DCRN_MALTXCTP7R 338 - if (maldata->num_tx_chans > 7) 339 - set_mal_dcrn(mal, DCRN_MALTXCTP7R, 340 - mal->tx_phys_addr + 7 * MAL_DT_ALIGN); 341 - #endif /* DCRN_MALTXCTP7R */ 465 + for (i = 0; i < maldata->num_tx_chans; ++i) 466 + set_mal_dcrn(mal, MAL_TXCTPR(i), mal->bd_dma + 467 + sizeof(struct mal_descriptor) * 468 + mal_tx_bd_offset(mal, i)); 342 469 343 - mal->rx_virt_addr = dma_alloc_coherent(&ocpdev->dev, 344 - MAL_DT_ALIGN * 345 - maldata->num_rx_chans, 346 - &mal->rx_phys_addr, GFP_KERNEL); 347 - 348 - set_mal_dcrn(mal, DCRN_MALRXCTP0R, mal->rx_phys_addr); 349 - #ifdef DCRN_MALRXCTP1R 350 - if (maldata->num_rx_chans > 1) 351 - set_mal_dcrn(mal, DCRN_MALRXCTP1R, 352 - mal->rx_phys_addr + MAL_DT_ALIGN); 353 - #endif /* DCRN_MALRXCTP1R */ 354 - #ifdef DCRN_MALRXCTP2R 355 - if (maldata->num_rx_chans > 2) 356 - set_mal_dcrn(mal, DCRN_MALRXCTP2R, 357 - mal->rx_phys_addr + 2 * MAL_DT_ALIGN); 358 - #endif /* DCRN_MALRXCTP2R */ 359 - #ifdef DCRN_MALRXCTP3R 360 - if (maldata->num_rx_chans > 3) 361 - set_mal_dcrn(mal, DCRN_MALRXCTP3R, 362 - mal->rx_phys_addr + 3 * MAL_DT_ALIGN); 363 - #endif /* DCRN_MALRXCTP3R */ 470 + for (i = 0; i < maldata->num_rx_chans; ++i) 471 + set_mal_dcrn(mal, MAL_RXCTPR(i), mal->bd_dma + 472 + sizeof(struct mal_descriptor) * 473 + mal_rx_bd_offset(mal, i)); 364 474 365 475 err = request_irq(maldata->serr_irq, mal_serr, 0, "MAL SERR", mal); 366 476 if (err) 367 - goto fail; 368 - err = request_irq(maldata->txde_irq, mal_txde, 0, "MAL TX DE ", mal); 477 + goto fail2; 478 + err = request_irq(maldata->txde_irq, mal_txde, 0, "MAL TX DE", mal); 369 479 if (err) 370 - goto fail; 480 + goto fail3; 371 481 err = request_irq(maldata->txeob_irq, mal_txeob, 0, "MAL TX EOB", mal); 372 482 if (err) 373 - goto fail; 483 + goto fail4; 374 484 err = request_irq(maldata->rxde_irq, mal_rxde, 0, "MAL RX DE", mal); 375 485 if (err) 376 - goto fail; 486 + goto fail5; 377 487 err = request_irq(maldata->rxeob_irq, mal_rxeob, 0, "MAL RX EOB", mal); 378 488 if (err) 379 - goto fail; 489 + goto fail6; 380 490 381 - set_mal_dcrn(mal, DCRN_MALIER, 382 - MALIER_DE | MALIER_NE | MALIER_TE | 383 - MALIER_OPBE | MALIER_PLBE); 491 + /* Enable all MAL SERR interrupt sources */ 492 + set_mal_dcrn(mal, MAL_IER, MAL_IER_EVENTS); 384 493 385 - /* Advertise me to the rest of the world */ 494 + /* Advertise this instance to the rest of the world */ 386 495 ocp_set_drvdata(ocpdev, mal); 387 496 388 - printk(KERN_INFO "mal%d: Initialized, %d tx channels, %d rx channels\n", 389 - ocpdev->def->index, maldata->num_tx_chans, 390 - maldata->num_rx_chans); 497 + mal_dbg_register(mal->def->index, mal); 391 498 499 + printk(KERN_INFO "mal%d: initialized, %d TX channels, %d RX channels\n", 500 + mal->def->index, maldata->num_tx_chans, maldata->num_rx_chans); 392 501 return 0; 393 502 503 + fail6: 504 + free_irq(maldata->rxde_irq, mal); 505 + fail5: 506 + free_irq(maldata->txeob_irq, mal); 507 + fail4: 508 + free_irq(maldata->txde_irq, mal); 509 + fail3: 510 + free_irq(maldata->serr_irq, mal); 511 + fail2: 512 + dma_free_coherent(&ocpdev->dev, bd_size, mal->bd_virt, mal->bd_dma); 394 513 fail: 395 - /* FIXME: dispose requested IRQs ! */ 396 - if (err && mal) 397 - kfree(mal); 514 + kfree(mal); 398 515 return err; 399 516 } 400 517 401 518 static void __exit mal_remove(struct ocp_device *ocpdev) 402 519 { 403 520 struct ibm_ocp_mal *mal = ocp_get_drvdata(ocpdev); 404 - struct ocp_func_mal_data *maldata = ocpdev->def->additions; 521 + struct ocp_func_mal_data *maldata = mal->def->additions; 405 522 406 - BUG_ON(!maldata); 523 + MAL_DBG("%d: remove" NL, mal->def->index); 524 + 525 + /* Syncronize with scheduled polling, 526 + stolen from net/core/dev.c:dev_close() 527 + */ 528 + clear_bit(__LINK_STATE_START, &mal->poll_dev.state); 529 + netif_poll_disable(&mal->poll_dev); 530 + 531 + if (!list_empty(&mal->list)) { 532 + /* This is *very* bad */ 533 + printk(KERN_EMERG 534 + "mal%d: commac list is not empty on remove!\n", 535 + mal->def->index); 536 + } 407 537 408 538 ocp_set_drvdata(ocpdev, NULL); 409 539 410 - /* FIXME: shut down the MAL, deal with dependency with emac */ 411 540 free_irq(maldata->serr_irq, mal); 412 541 free_irq(maldata->txde_irq, mal); 413 542 free_irq(maldata->txeob_irq, mal); 414 543 free_irq(maldata->rxde_irq, mal); 415 544 free_irq(maldata->rxeob_irq, mal); 416 545 417 - if (mal->tx_virt_addr) 418 - dma_free_coherent(&ocpdev->dev, 419 - MAL_DT_ALIGN * maldata->num_tx_chans, 420 - mal->tx_virt_addr, mal->tx_phys_addr); 546 + mal_reset(mal); 421 547 422 - if (mal->rx_virt_addr) 423 - dma_free_coherent(&ocpdev->dev, 424 - MAL_DT_ALIGN * maldata->num_rx_chans, 425 - mal->rx_virt_addr, mal->rx_phys_addr); 548 + mal_dbg_register(mal->def->index, NULL); 549 + 550 + dma_free_coherent(&ocpdev->dev, 551 + sizeof(struct mal_descriptor) * 552 + (NUM_TX_BUFF * maldata->num_tx_chans + 553 + NUM_RX_BUFF * maldata->num_rx_chans), mal->bd_virt, 554 + mal->bd_dma); 426 555 427 556 kfree(mal); 428 557 } 429 558 430 559 /* Structure for a device driver */ 431 560 static struct ocp_device_id mal_ids[] = { 432 - {.vendor = OCP_ANY_ID,.function = OCP_FUNC_MAL}, 433 - {.vendor = OCP_VENDOR_INVALID} 561 + { .vendor = OCP_VENDOR_IBM, .function = OCP_FUNC_MAL }, 562 + { .vendor = OCP_VENDOR_INVALID} 434 563 }; 435 564 436 565 static struct ocp_driver mal_driver = { ··· 570 441 .remove = mal_remove, 571 442 }; 572 443 573 - static int __init init_mals(void) 444 + int __init mal_init(void) 574 445 { 575 - int rc; 576 - 577 - rc = ocp_register_driver(&mal_driver); 578 - if (rc < 0) { 579 - ocp_unregister_driver(&mal_driver); 580 - return -ENODEV; 581 - } 582 - 583 - return 0; 446 + MAL_DBG(": init" NL); 447 + return ocp_register_driver(&mal_driver); 584 448 } 585 449 586 - static void __exit exit_mals(void) 450 + void __exit mal_exit(void) 587 451 { 452 + MAL_DBG(": exit" NL); 588 453 ocp_unregister_driver(&mal_driver); 589 454 } 590 - 591 - module_init(init_mals); 592 - module_exit(exit_mals);
+233 -97
drivers/net/ibm_emac/ibm_emac_mal.h
··· 1 - #ifndef _IBM_EMAC_MAL_H 2 - #define _IBM_EMAC_MAL_H 1 + /* 2 + * drivers/net/ibm_emac/ibm_emac_mal.h 3 + * 4 + * Memory Access Layer (MAL) support 5 + * 6 + * Copyright (c) 2004, 2005 Zultys Technologies. 7 + * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net> 8 + * 9 + * Based on original work by 10 + * Armin Kuster <akuster@mvista.com> 11 + * Copyright 2002 MontaVista Softare Inc. 12 + * 13 + * This program is free software; you can redistribute it and/or modify it 14 + * under the terms of the GNU General Public License as published by the 15 + * Free Software Foundation; either version 2 of the License, or (at your 16 + * option) any later version. 17 + * 18 + */ 19 + #ifndef __IBM_EMAC_MAL_H_ 20 + #define __IBM_EMAC_MAL_H_ 3 21 22 + #include <linux/config.h> 23 + #include <linux/init.h> 4 24 #include <linux/list.h> 25 + #include <linux/netdevice.h> 5 26 6 - #define MAL_DT_ALIGN (4096) /* Alignment for each channel's descriptor table */ 27 + #include <asm/io.h> 7 28 8 - #define MAL_CHAN_MASK(chan) (0x80000000 >> (chan)) 29 + /* 30 + * These MAL "versions" probably aren't the real versions IBM uses for these 31 + * MAL cores, I assigned them just to make #ifdefs in this file nicer and 32 + * reflect the fact that 40x and 44x have slightly different MALs. --ebs 33 + */ 34 + #if defined(CONFIG_405GP) || defined(CONFIG_405GPR) || defined(CONFIG_405EP) || \ 35 + defined(CONFIG_440EP) || defined(CONFIG_NP405H) 36 + #define MAL_VERSION 1 37 + #elif defined(CONFIG_440GP) || defined(CONFIG_440GX) || defined(CONFIG_440SP) 38 + #define MAL_VERSION 2 39 + #else 40 + #error "Unknown SoC, please check chip manual and choose MAL 'version'" 41 + #endif 42 + 43 + /* MALx DCR registers */ 44 + #define MAL_CFG 0x00 45 + #define MAL_CFG_SR 0x80000000 46 + #define MAL_CFG_PLBB 0x00004000 47 + #define MAL_CFG_OPBBL 0x00000080 48 + #define MAL_CFG_EOPIE 0x00000004 49 + #define MAL_CFG_LEA 0x00000002 50 + #define MAL_CFG_SD 0x00000001 51 + #if MAL_VERSION == 1 52 + #define MAL_CFG_PLBP_MASK 0x00c00000 53 + #define MAL_CFG_PLBP_10 0x00800000 54 + #define MAL_CFG_GA 0x00200000 55 + #define MAL_CFG_OA 0x00100000 56 + #define MAL_CFG_PLBLE 0x00080000 57 + #define MAL_CFG_PLBT_MASK 0x00078000 58 + #define MAL_CFG_DEFAULT (MAL_CFG_PLBP_10 | MAL_CFG_PLBT_MASK) 59 + #elif MAL_VERSION == 2 60 + #define MAL_CFG_RPP_MASK 0x00c00000 61 + #define MAL_CFG_RPP_10 0x00800000 62 + #define MAL_CFG_RMBS_MASK 0x00300000 63 + #define MAL_CFG_WPP_MASK 0x000c0000 64 + #define MAL_CFG_WPP_10 0x00080000 65 + #define MAL_CFG_WMBS_MASK 0x00030000 66 + #define MAL_CFG_PLBLE 0x00008000 67 + #define MAL_CFG_DEFAULT (MAL_CFG_RMBS_MASK | MAL_CFG_WMBS_MASK | \ 68 + MAL_CFG_RPP_10 | MAL_CFG_WPP_10) 69 + #else 70 + #error "Unknown MAL version" 71 + #endif 72 + 73 + #define MAL_ESR 0x01 74 + #define MAL_ESR_EVB 0x80000000 75 + #define MAL_ESR_CIDT 0x40000000 76 + #define MAL_ESR_CID_MASK 0x3e000000 77 + #define MAL_ESR_CID_SHIFT 25 78 + #define MAL_ESR_DE 0x00100000 79 + #define MAL_ESR_OTE 0x00040000 80 + #define MAL_ESR_OSE 0x00020000 81 + #define MAL_ESR_PEIN 0x00010000 82 + #define MAL_ESR_DEI 0x00000010 83 + #define MAL_ESR_OTEI 0x00000004 84 + #define MAL_ESR_OSEI 0x00000002 85 + #define MAL_ESR_PBEI 0x00000001 86 + #if MAL_VERSION == 1 87 + #define MAL_ESR_ONE 0x00080000 88 + #define MAL_ESR_ONEI 0x00000008 89 + #elif MAL_VERSION == 2 90 + #define MAL_ESR_PTE 0x00800000 91 + #define MAL_ESR_PRE 0x00400000 92 + #define MAL_ESR_PWE 0x00200000 93 + #define MAL_ESR_PTEI 0x00000080 94 + #define MAL_ESR_PREI 0x00000040 95 + #define MAL_ESR_PWEI 0x00000020 96 + #else 97 + #error "Unknown MAL version" 98 + #endif 99 + 100 + #define MAL_IER 0x02 101 + #define MAL_IER_DE 0x00000010 102 + #define MAL_IER_OTE 0x00000004 103 + #define MAL_IER_OE 0x00000002 104 + #define MAL_IER_PE 0x00000001 105 + #if MAL_VERSION == 1 106 + #define MAL_IER_NWE 0x00000008 107 + #define MAL_IER_SOC_EVENTS MAL_IER_NWE 108 + #elif MAL_VERSION == 2 109 + #define MAL_IER_PT 0x00000080 110 + #define MAL_IER_PRE 0x00000040 111 + #define MAL_IER_PWE 0x00000020 112 + #define MAL_IER_SOC_EVENTS (MAL_IER_PT | MAL_IER_PRE | MAL_IER_PWE) 113 + #else 114 + #error "Unknown MAL version" 115 + #endif 116 + #define MAL_IER_EVENTS (MAL_IER_SOC_EVENTS | MAL_IER_OTE | \ 117 + MAL_IER_OTE | MAL_IER_OE | MAL_IER_PE) 118 + 119 + #define MAL_TXCASR 0x04 120 + #define MAL_TXCARR 0x05 121 + #define MAL_TXEOBISR 0x06 122 + #define MAL_TXDEIR 0x07 123 + #define MAL_RXCASR 0x10 124 + #define MAL_RXCARR 0x11 125 + #define MAL_RXEOBISR 0x12 126 + #define MAL_RXDEIR 0x13 127 + #define MAL_TXCTPR(n) ((n) + 0x20) 128 + #define MAL_RXCTPR(n) ((n) + 0x40) 129 + #define MAL_RCBS(n) ((n) + 0x60) 130 + 131 + /* In reality MAL can handle TX buffers up to 4095 bytes long, 132 + * but this isn't a good round number :) --ebs 133 + */ 134 + #define MAL_MAX_TX_SIZE 4080 135 + #define MAL_MAX_RX_SIZE 4080 136 + 137 + static inline int mal_rx_size(int len) 138 + { 139 + len = (len + 0xf) & ~0xf; 140 + return len > MAL_MAX_RX_SIZE ? MAL_MAX_RX_SIZE : len; 141 + } 142 + 143 + static inline int mal_tx_chunks(int len) 144 + { 145 + return (len + MAL_MAX_TX_SIZE - 1) / MAL_MAX_TX_SIZE; 146 + } 147 + 148 + #define MAL_CHAN_MASK(n) (0x80000000 >> (n)) 9 149 10 150 /* MAL Buffer Descriptor structure */ 11 151 struct mal_descriptor { 12 - unsigned short ctrl; /* MAL / Commac status control bits */ 13 - short data_len; /* Max length is 4K-1 (12 bits) */ 14 - unsigned char *data_ptr; /* pointer to actual data buffer */ 15 - } __attribute__ ((packed)); 152 + u16 ctrl; /* MAL / Commac status control bits */ 153 + u16 data_len; /* Max length is 4K-1 (12 bits) */ 154 + u32 data_ptr; /* pointer to actual data buffer */ 155 + }; 16 156 17 157 /* the following defines are for the MadMAL status and control registers. */ 18 158 /* MADMAL transmit and receive status/control bits */ 19 - #define MAL_RX_CTRL_EMPTY 0x8000 20 - #define MAL_RX_CTRL_WRAP 0x4000 21 - #define MAL_RX_CTRL_CM 0x2000 22 - #define MAL_RX_CTRL_LAST 0x1000 23 - #define MAL_RX_CTRL_FIRST 0x0800 24 - #define MAL_RX_CTRL_INTR 0x0400 159 + #define MAL_RX_CTRL_EMPTY 0x8000 160 + #define MAL_RX_CTRL_WRAP 0x4000 161 + #define MAL_RX_CTRL_CM 0x2000 162 + #define MAL_RX_CTRL_LAST 0x1000 163 + #define MAL_RX_CTRL_FIRST 0x0800 164 + #define MAL_RX_CTRL_INTR 0x0400 165 + #define MAL_RX_CTRL_SINGLE (MAL_RX_CTRL_LAST | MAL_RX_CTRL_FIRST) 166 + #define MAL_IS_SINGLE_RX(ctrl) (((ctrl) & MAL_RX_CTRL_SINGLE) == MAL_RX_CTRL_SINGLE) 25 167 26 - #define MAL_TX_CTRL_READY 0x8000 27 - #define MAL_TX_CTRL_WRAP 0x4000 28 - #define MAL_TX_CTRL_CM 0x2000 29 - #define MAL_TX_CTRL_LAST 0x1000 30 - #define MAL_TX_CTRL_INTR 0x0400 168 + #define MAL_TX_CTRL_READY 0x8000 169 + #define MAL_TX_CTRL_WRAP 0x4000 170 + #define MAL_TX_CTRL_CM 0x2000 171 + #define MAL_TX_CTRL_LAST 0x1000 172 + #define MAL_TX_CTRL_INTR 0x0400 31 173 32 174 struct mal_commac_ops { 33 - void (*txeob) (void *dev, u32 chanmask); 34 - void (*txde) (void *dev, u32 chanmask); 35 - void (*rxeob) (void *dev, u32 chanmask); 36 - void (*rxde) (void *dev, u32 chanmask); 175 + void (*poll_tx) (void *dev); 176 + int (*poll_rx) (void *dev, int budget); 177 + int (*peek_rx) (void *dev); 178 + void (*rxde) (void *dev); 37 179 }; 38 180 39 181 struct mal_commac { 40 - struct mal_commac_ops *ops; 41 - void *dev; 42 - u32 tx_chan_mask, rx_chan_mask; 43 - struct list_head list; 182 + struct mal_commac_ops *ops; 183 + void *dev; 184 + struct list_head poll_list; 185 + int rx_stopped; 186 + 187 + u32 tx_chan_mask; 188 + u32 rx_chan_mask; 189 + struct list_head list; 44 190 }; 45 191 46 192 struct ibm_ocp_mal { 47 - int dcrbase; 193 + int dcrbase; 48 194 49 - struct list_head commac; 50 - u32 tx_chan_mask, rx_chan_mask; 195 + struct list_head poll_list; 196 + struct net_device poll_dev; 51 197 52 - dma_addr_t tx_phys_addr; 53 - struct mal_descriptor *tx_virt_addr; 198 + struct list_head list; 199 + u32 tx_chan_mask; 200 + u32 rx_chan_mask; 54 201 55 - dma_addr_t rx_phys_addr; 56 - struct mal_descriptor *rx_virt_addr; 202 + dma_addr_t bd_dma; 203 + struct mal_descriptor *bd_virt; 204 + 205 + struct ocp_def *def; 57 206 }; 58 207 59 - #define GET_MAL_STANZA(base,dcrn) \ 60 - case base: \ 61 - x = mfdcr(dcrn(base)); \ 62 - break; 63 - 64 - #define SET_MAL_STANZA(base,dcrn, val) \ 65 - case base: \ 66 - mtdcr(dcrn(base), (val)); \ 67 - break; 68 - 69 - #define GET_MAL0_STANZA(dcrn) GET_MAL_STANZA(DCRN_MAL_BASE,dcrn) 70 - #define SET_MAL0_STANZA(dcrn,val) SET_MAL_STANZA(DCRN_MAL_BASE,dcrn,val) 71 - 72 - #ifdef DCRN_MAL1_BASE 73 - #define GET_MAL1_STANZA(dcrn) GET_MAL_STANZA(DCRN_MAL1_BASE,dcrn) 74 - #define SET_MAL1_STANZA(dcrn,val) SET_MAL_STANZA(DCRN_MAL1_BASE,dcrn,val) 75 - #else /* ! DCRN_MAL1_BASE */ 76 - #define GET_MAL1_STANZA(dcrn) 77 - #define SET_MAL1_STANZA(dcrn,val) 78 - #endif 79 - 80 - #define get_mal_dcrn(mal, dcrn) ({ \ 81 - u32 x; \ 82 - switch ((mal)->dcrbase) { \ 83 - GET_MAL0_STANZA(dcrn) \ 84 - GET_MAL1_STANZA(dcrn) \ 85 - default: \ 86 - x = 0; \ 87 - BUG(); \ 88 - } \ 89 - x; }) 90 - 91 - #define set_mal_dcrn(mal, dcrn, val) do { \ 92 - switch ((mal)->dcrbase) { \ 93 - SET_MAL0_STANZA(dcrn,val) \ 94 - SET_MAL1_STANZA(dcrn,val) \ 95 - default: \ 96 - BUG(); \ 97 - } } while (0) 98 - 99 - static inline void mal_enable_tx_channels(struct ibm_ocp_mal *mal, u32 chanmask) 208 + static inline u32 get_mal_dcrn(struct ibm_ocp_mal *mal, int reg) 100 209 { 101 - set_mal_dcrn(mal, DCRN_MALTXCASR, 102 - get_mal_dcrn(mal, DCRN_MALTXCASR) | chanmask); 210 + return mfdcr(mal->dcrbase + reg); 103 211 } 104 212 105 - static inline void mal_disable_tx_channels(struct ibm_ocp_mal *mal, 106 - u32 chanmask) 213 + static inline void set_mal_dcrn(struct ibm_ocp_mal *mal, int reg, u32 val) 107 214 { 108 - set_mal_dcrn(mal, DCRN_MALTXCARR, chanmask); 215 + mtdcr(mal->dcrbase + reg, val); 109 216 } 110 217 111 - static inline void mal_enable_rx_channels(struct ibm_ocp_mal *mal, u32 chanmask) 112 - { 113 - set_mal_dcrn(mal, DCRN_MALRXCASR, 114 - get_mal_dcrn(mal, DCRN_MALRXCASR) | chanmask); 115 - } 218 + /* Register MAL devices */ 219 + int mal_init(void) __init; 220 + void mal_exit(void) __exit; 116 221 117 - static inline void mal_disable_rx_channels(struct ibm_ocp_mal *mal, 118 - u32 chanmask) 119 - { 120 - set_mal_dcrn(mal, DCRN_MALRXCARR, chanmask); 121 - } 222 + int mal_register_commac(struct ibm_ocp_mal *mal, 223 + struct mal_commac *commac) __init; 224 + void mal_unregister_commac(struct ibm_ocp_mal *mal, 225 + struct mal_commac *commac) __exit; 226 + int mal_set_rcbs(struct ibm_ocp_mal *mal, int channel, unsigned long size); 122 227 123 - extern int mal_register_commac(struct ibm_ocp_mal *mal, 124 - struct mal_commac *commac); 125 - extern int mal_unregister_commac(struct ibm_ocp_mal *mal, 126 - struct mal_commac *commac); 228 + /* Returns BD ring offset for a particular channel 229 + (in 'struct mal_descriptor' elements) 230 + */ 231 + int mal_tx_bd_offset(struct ibm_ocp_mal *mal, int channel); 232 + int mal_rx_bd_offset(struct ibm_ocp_mal *mal, int channel); 127 233 128 - extern int mal_set_rcbs(struct ibm_ocp_mal *mal, int channel, 129 - unsigned long size); 234 + void mal_enable_tx_channel(struct ibm_ocp_mal *mal, int channel); 235 + void mal_disable_tx_channel(struct ibm_ocp_mal *mal, int channel); 236 + void mal_enable_rx_channel(struct ibm_ocp_mal *mal, int channel); 237 + void mal_disable_rx_channel(struct ibm_ocp_mal *mal, int channel); 130 238 131 - #endif /* _IBM_EMAC_MAL_H */ 239 + /* Add/remove EMAC to/from MAL polling list */ 240 + void mal_poll_add(struct ibm_ocp_mal *mal, struct mal_commac *commac); 241 + void mal_poll_del(struct ibm_ocp_mal *mal, struct mal_commac *commac); 242 + 243 + /* Ethtool MAL registers */ 244 + struct ibm_mal_regs { 245 + u32 tx_count; 246 + u32 rx_count; 247 + 248 + u32 cfg; 249 + u32 esr; 250 + u32 ier; 251 + u32 tx_casr; 252 + u32 tx_carr; 253 + u32 tx_eobisr; 254 + u32 tx_deir; 255 + u32 rx_casr; 256 + u32 rx_carr; 257 + u32 rx_eobisr; 258 + u32 rx_deir; 259 + u32 tx_ctpr[32]; 260 + u32 rx_ctpr[32]; 261 + u32 rcbs[32]; 262 + }; 263 + 264 + int mal_get_regs_len(struct ibm_ocp_mal *mal); 265 + void *mal_dump_regs(struct ibm_ocp_mal *mal, void *buf); 266 + 267 + #endif /* __IBM_EMAC_MAL_H_ */
+258 -201
drivers/net/ibm_emac/ibm_emac_phy.c
··· 1 1 /* 2 - * ibm_ocp_phy.c 2 + * drivers/net/ibm_emac/ibm_emac_phy.c 3 3 * 4 - * PHY drivers for the ibm ocp ethernet driver. Borrowed 5 - * from sungem_phy.c, though I only kept the generic MII 4 + * Driver for PowerPC 4xx on-chip ethernet controller, PHY support. 5 + * Borrowed from sungem_phy.c, though I only kept the generic MII 6 6 * driver for now. 7 7 * 8 8 * This file should be shared with other drivers or eventually 9 9 * merged as the "low level" part of miilib 10 10 * 11 11 * (c) 2003, Benjamin Herrenscmidt (benh@kernel.crashing.org) 12 + * (c) 2004-2005, Eugene Surovegin <ebs@ebshome.net> 12 13 * 13 14 */ 14 - 15 15 #include <linux/config.h> 16 - 17 16 #include <linux/module.h> 18 - 19 17 #include <linux/kernel.h> 20 - #include <linux/sched.h> 21 18 #include <linux/types.h> 22 19 #include <linux/netdevice.h> 23 - #include <linux/etherdevice.h> 24 20 #include <linux/mii.h> 25 21 #include <linux/ethtool.h> 26 22 #include <linux/delay.h> 27 23 24 + #include <asm/ocp.h> 25 + 28 26 #include "ibm_emac_phy.h" 29 27 30 - static int reset_one_mii_phy(struct mii_phy *phy, int phy_id) 28 + static inline int phy_read(struct mii_phy *phy, int reg) 31 29 { 32 - u16 val; 30 + return phy->mdio_read(phy->dev, phy->address, reg); 31 + } 32 + 33 + static inline void phy_write(struct mii_phy *phy, int reg, int val) 34 + { 35 + phy->mdio_write(phy->dev, phy->address, reg, val); 36 + } 37 + 38 + int mii_reset_phy(struct mii_phy *phy) 39 + { 40 + int val; 33 41 int limit = 10000; 34 42 35 - val = __phy_read(phy, phy_id, MII_BMCR); 43 + val = phy_read(phy, MII_BMCR); 36 44 val &= ~BMCR_ISOLATE; 37 45 val |= BMCR_RESET; 38 - __phy_write(phy, phy_id, MII_BMCR, val); 46 + phy_write(phy, MII_BMCR, val); 39 47 40 - udelay(100); 48 + udelay(300); 41 49 42 50 while (limit--) { 43 - val = __phy_read(phy, phy_id, MII_BMCR); 44 - if ((val & BMCR_RESET) == 0) 51 + val = phy_read(phy, MII_BMCR); 52 + if (val >= 0 && (val & BMCR_RESET) == 0) 45 53 break; 46 54 udelay(10); 47 55 } 48 56 if ((val & BMCR_ISOLATE) && limit > 0) 49 - __phy_write(phy, phy_id, MII_BMCR, val & ~BMCR_ISOLATE); 57 + phy_write(phy, MII_BMCR, val & ~BMCR_ISOLATE); 50 58 51 - return (limit <= 0); 59 + return limit <= 0; 52 60 } 61 + 62 + static int genmii_setup_aneg(struct mii_phy *phy, u32 advertise) 63 + { 64 + int ctl, adv; 65 + 66 + phy->autoneg = AUTONEG_ENABLE; 67 + phy->speed = SPEED_10; 68 + phy->duplex = DUPLEX_HALF; 69 + phy->pause = phy->asym_pause = 0; 70 + phy->advertising = advertise; 71 + 72 + /* Setup standard advertise */ 73 + adv = phy_read(phy, MII_ADVERTISE); 74 + if (adv < 0) 75 + return adv; 76 + adv &= ~(ADVERTISE_ALL | ADVERTISE_100BASE4 | ADVERTISE_PAUSE_CAP | 77 + ADVERTISE_PAUSE_ASYM); 78 + if (advertise & ADVERTISED_10baseT_Half) 79 + adv |= ADVERTISE_10HALF; 80 + if (advertise & ADVERTISED_10baseT_Full) 81 + adv |= ADVERTISE_10FULL; 82 + if (advertise & ADVERTISED_100baseT_Half) 83 + adv |= ADVERTISE_100HALF; 84 + if (advertise & ADVERTISED_100baseT_Full) 85 + adv |= ADVERTISE_100FULL; 86 + if (advertise & ADVERTISED_Pause) 87 + adv |= ADVERTISE_PAUSE_CAP; 88 + if (advertise & ADVERTISED_Asym_Pause) 89 + adv |= ADVERTISE_PAUSE_ASYM; 90 + phy_write(phy, MII_ADVERTISE, adv); 91 + 92 + if (phy->features & 93 + (SUPPORTED_1000baseT_Full | SUPPORTED_1000baseT_Half)) { 94 + adv = phy_read(phy, MII_CTRL1000); 95 + if (adv < 0) 96 + return adv; 97 + adv &= ~(ADVERTISE_1000FULL | ADVERTISE_1000HALF); 98 + if (advertise & ADVERTISED_1000baseT_Full) 99 + adv |= ADVERTISE_1000FULL; 100 + if (advertise & ADVERTISED_1000baseT_Half) 101 + adv |= ADVERTISE_1000HALF; 102 + phy_write(phy, MII_CTRL1000, adv); 103 + } 104 + 105 + /* Start/Restart aneg */ 106 + ctl = phy_read(phy, MII_BMCR); 107 + ctl |= (BMCR_ANENABLE | BMCR_ANRESTART); 108 + phy_write(phy, MII_BMCR, ctl); 109 + 110 + return 0; 111 + } 112 + 113 + static int genmii_setup_forced(struct mii_phy *phy, int speed, int fd) 114 + { 115 + int ctl; 116 + 117 + phy->autoneg = AUTONEG_DISABLE; 118 + phy->speed = speed; 119 + phy->duplex = fd; 120 + phy->pause = phy->asym_pause = 0; 121 + 122 + ctl = phy_read(phy, MII_BMCR); 123 + if (ctl < 0) 124 + return ctl; 125 + ctl &= ~(BMCR_FULLDPLX | BMCR_SPEED100 | BMCR_ANENABLE); 126 + 127 + /* First reset the PHY */ 128 + phy_write(phy, MII_BMCR, ctl | BMCR_RESET); 129 + 130 + /* Select speed & duplex */ 131 + switch (speed) { 132 + case SPEED_10: 133 + break; 134 + case SPEED_100: 135 + ctl |= BMCR_SPEED100; 136 + break; 137 + case SPEED_1000: 138 + ctl |= BMCR_SPEED1000; 139 + break; 140 + default: 141 + return -EINVAL; 142 + } 143 + if (fd == DUPLEX_FULL) 144 + ctl |= BMCR_FULLDPLX; 145 + phy_write(phy, MII_BMCR, ctl); 146 + 147 + return 0; 148 + } 149 + 150 + static int genmii_poll_link(struct mii_phy *phy) 151 + { 152 + int status; 153 + 154 + /* Clear latched value with dummy read */ 155 + phy_read(phy, MII_BMSR); 156 + status = phy_read(phy, MII_BMSR); 157 + if (status < 0 || (status & BMSR_LSTATUS) == 0) 158 + return 0; 159 + if (phy->autoneg == AUTONEG_ENABLE && !(status & BMSR_ANEGCOMPLETE)) 160 + return 0; 161 + return 1; 162 + } 163 + 164 + static int genmii_read_link(struct mii_phy *phy) 165 + { 166 + if (phy->autoneg == AUTONEG_ENABLE) { 167 + int glpa = 0; 168 + int lpa = phy_read(phy, MII_LPA) & phy_read(phy, MII_ADVERTISE); 169 + if (lpa < 0) 170 + return lpa; 171 + 172 + if (phy->features & 173 + (SUPPORTED_1000baseT_Full | SUPPORTED_1000baseT_Half)) { 174 + int adv = phy_read(phy, MII_CTRL1000); 175 + glpa = phy_read(phy, MII_STAT1000); 176 + 177 + if (glpa < 0 || adv < 0) 178 + return adv; 179 + 180 + glpa &= adv << 2; 181 + } 182 + 183 + phy->speed = SPEED_10; 184 + phy->duplex = DUPLEX_HALF; 185 + phy->pause = phy->asym_pause = 0; 186 + 187 + if (glpa & (LPA_1000FULL | LPA_1000HALF)) { 188 + phy->speed = SPEED_1000; 189 + if (glpa & LPA_1000FULL) 190 + phy->duplex = DUPLEX_FULL; 191 + } else if (lpa & (LPA_100FULL | LPA_100HALF)) { 192 + phy->speed = SPEED_100; 193 + if (lpa & LPA_100FULL) 194 + phy->duplex = DUPLEX_FULL; 195 + } else if (lpa & LPA_10FULL) 196 + phy->duplex = DUPLEX_FULL; 197 + 198 + if (phy->duplex == DUPLEX_FULL) { 199 + phy->pause = lpa & LPA_PAUSE_CAP ? 1 : 0; 200 + phy->asym_pause = lpa & LPA_PAUSE_ASYM ? 1 : 0; 201 + } 202 + } else { 203 + int bmcr = phy_read(phy, MII_BMCR); 204 + if (bmcr < 0) 205 + return bmcr; 206 + 207 + if (bmcr & BMCR_FULLDPLX) 208 + phy->duplex = DUPLEX_FULL; 209 + else 210 + phy->duplex = DUPLEX_HALF; 211 + if (bmcr & BMCR_SPEED1000) 212 + phy->speed = SPEED_1000; 213 + else if (bmcr & BMCR_SPEED100) 214 + phy->speed = SPEED_100; 215 + else 216 + phy->speed = SPEED_10; 217 + 218 + phy->pause = phy->asym_pause = 0; 219 + } 220 + return 0; 221 + } 222 + 223 + /* Generic implementation for most 10/100/1000 PHYs */ 224 + static struct mii_phy_ops generic_phy_ops = { 225 + .setup_aneg = genmii_setup_aneg, 226 + .setup_forced = genmii_setup_forced, 227 + .poll_link = genmii_poll_link, 228 + .read_link = genmii_read_link 229 + }; 230 + 231 + static struct mii_phy_def genmii_phy_def = { 232 + .phy_id = 0x00000000, 233 + .phy_id_mask = 0x00000000, 234 + .name = "Generic MII", 235 + .ops = &generic_phy_ops 236 + }; 237 + 238 + /* CIS8201 */ 239 + #define MII_CIS8201_EPCR 0x17 240 + #define EPCR_MODE_MASK 0x3000 241 + #define EPCR_GMII_MODE 0x0000 242 + #define EPCR_RGMII_MODE 0x1000 243 + #define EPCR_TBI_MODE 0x2000 244 + #define EPCR_RTBI_MODE 0x3000 53 245 54 246 static int cis8201_init(struct mii_phy *phy) 55 247 { 56 - u16 epcr; 248 + int epcr; 57 249 58 250 epcr = phy_read(phy, MII_CIS8201_EPCR); 251 + if (epcr < 0) 252 + return epcr; 253 + 59 254 epcr &= ~EPCR_MODE_MASK; 60 255 61 256 switch (phy->mode) { ··· 273 78 return 0; 274 79 } 275 80 276 - static int genmii_setup_aneg(struct mii_phy *phy, u32 advertise) 277 - { 278 - u16 ctl, adv; 279 - 280 - phy->autoneg = 1; 281 - phy->speed = SPEED_10; 282 - phy->duplex = DUPLEX_HALF; 283 - phy->pause = 0; 284 - phy->advertising = advertise; 285 - 286 - /* Setup standard advertise */ 287 - adv = phy_read(phy, MII_ADVERTISE); 288 - adv &= ~(ADVERTISE_ALL | ADVERTISE_100BASE4); 289 - if (advertise & ADVERTISED_10baseT_Half) 290 - adv |= ADVERTISE_10HALF; 291 - if (advertise & ADVERTISED_10baseT_Full) 292 - adv |= ADVERTISE_10FULL; 293 - if (advertise & ADVERTISED_100baseT_Half) 294 - adv |= ADVERTISE_100HALF; 295 - if (advertise & ADVERTISED_100baseT_Full) 296 - adv |= ADVERTISE_100FULL; 297 - phy_write(phy, MII_ADVERTISE, adv); 298 - 299 - /* Start/Restart aneg */ 300 - ctl = phy_read(phy, MII_BMCR); 301 - ctl |= (BMCR_ANENABLE | BMCR_ANRESTART); 302 - phy_write(phy, MII_BMCR, ctl); 303 - 304 - return 0; 305 - } 306 - 307 - static int genmii_setup_forced(struct mii_phy *phy, int speed, int fd) 308 - { 309 - u16 ctl; 310 - 311 - phy->autoneg = 0; 312 - phy->speed = speed; 313 - phy->duplex = fd; 314 - phy->pause = 0; 315 - 316 - ctl = phy_read(phy, MII_BMCR); 317 - ctl &= ~(BMCR_FULLDPLX | BMCR_SPEED100 | BMCR_ANENABLE); 318 - 319 - /* First reset the PHY */ 320 - phy_write(phy, MII_BMCR, ctl | BMCR_RESET); 321 - 322 - /* Select speed & duplex */ 323 - switch (speed) { 324 - case SPEED_10: 325 - break; 326 - case SPEED_100: 327 - ctl |= BMCR_SPEED100; 328 - break; 329 - case SPEED_1000: 330 - default: 331 - return -EINVAL; 332 - } 333 - if (fd == DUPLEX_FULL) 334 - ctl |= BMCR_FULLDPLX; 335 - phy_write(phy, MII_BMCR, ctl); 336 - 337 - return 0; 338 - } 339 - 340 - static int genmii_poll_link(struct mii_phy *phy) 341 - { 342 - u16 status; 343 - 344 - (void)phy_read(phy, MII_BMSR); 345 - status = phy_read(phy, MII_BMSR); 346 - if ((status & BMSR_LSTATUS) == 0) 347 - return 0; 348 - if (phy->autoneg && !(status & BMSR_ANEGCOMPLETE)) 349 - return 0; 350 - return 1; 351 - } 352 - 353 - #define MII_CIS8201_ACSR 0x1c 354 - #define ACSR_DUPLEX_STATUS 0x0020 355 - #define ACSR_SPEED_1000BASET 0x0010 356 - #define ACSR_SPEED_100BASET 0x0008 357 - 358 - static int cis8201_read_link(struct mii_phy *phy) 359 - { 360 - u16 acsr; 361 - 362 - if (phy->autoneg) { 363 - acsr = phy_read(phy, MII_CIS8201_ACSR); 364 - 365 - if (acsr & ACSR_DUPLEX_STATUS) 366 - phy->duplex = DUPLEX_FULL; 367 - else 368 - phy->duplex = DUPLEX_HALF; 369 - if (acsr & ACSR_SPEED_1000BASET) { 370 - phy->speed = SPEED_1000; 371 - } else if (acsr & ACSR_SPEED_100BASET) 372 - phy->speed = SPEED_100; 373 - else 374 - phy->speed = SPEED_10; 375 - phy->pause = 0; 376 - } 377 - /* On non-aneg, we assume what we put in BMCR is the speed, 378 - * though magic-aneg shouldn't prevent this case from occurring 379 - */ 380 - 381 - return 0; 382 - } 383 - 384 - static int genmii_read_link(struct mii_phy *phy) 385 - { 386 - u16 lpa; 387 - 388 - if (phy->autoneg) { 389 - lpa = phy_read(phy, MII_LPA) & phy_read(phy, MII_ADVERTISE); 390 - 391 - phy->speed = SPEED_10; 392 - phy->duplex = DUPLEX_HALF; 393 - phy->pause = 0; 394 - 395 - if (lpa & (LPA_100FULL | LPA_100HALF)) { 396 - phy->speed = SPEED_100; 397 - if (lpa & LPA_100FULL) 398 - phy->duplex = DUPLEX_FULL; 399 - } else if (lpa & LPA_10FULL) 400 - phy->duplex = DUPLEX_FULL; 401 - } 402 - /* On non-aneg, we assume what we put in BMCR is the speed, 403 - * though magic-aneg shouldn't prevent this case from occurring 404 - */ 405 - 406 - return 0; 407 - } 408 - 409 - #define MII_BASIC_FEATURES (SUPPORTED_10baseT_Half | SUPPORTED_10baseT_Full | \ 410 - SUPPORTED_100baseT_Half | SUPPORTED_100baseT_Full | \ 411 - SUPPORTED_Autoneg | SUPPORTED_TP | SUPPORTED_MII) 412 - #define MII_GBIT_FEATURES (MII_BASIC_FEATURES | \ 413 - SUPPORTED_1000baseT_Half | SUPPORTED_1000baseT_Full) 414 - 415 - /* CIS8201 phy ops */ 416 81 static struct mii_phy_ops cis8201_phy_ops = { 417 - init:cis8201_init, 418 - setup_aneg:genmii_setup_aneg, 419 - setup_forced:genmii_setup_forced, 420 - poll_link:genmii_poll_link, 421 - read_link:cis8201_read_link 422 - }; 423 - 424 - /* Generic implementation for most 10/100 PHYs */ 425 - static struct mii_phy_ops generic_phy_ops = { 426 - setup_aneg:genmii_setup_aneg, 427 - setup_forced:genmii_setup_forced, 428 - poll_link:genmii_poll_link, 429 - read_link:genmii_read_link 82 + .init = cis8201_init, 83 + .setup_aneg = genmii_setup_aneg, 84 + .setup_forced = genmii_setup_forced, 85 + .poll_link = genmii_poll_link, 86 + .read_link = genmii_read_link 430 87 }; 431 88 432 89 static struct mii_phy_def cis8201_phy_def = { 433 - phy_id:0x000fc410, 434 - phy_id_mask:0x000ffff0, 435 - name:"CIS8201 Gigabit Ethernet", 436 - features:MII_GBIT_FEATURES, 437 - magic_aneg:0, 438 - ops:&cis8201_phy_ops 439 - }; 440 - 441 - static struct mii_phy_def genmii_phy_def = { 442 - phy_id:0x00000000, 443 - phy_id_mask:0x00000000, 444 - name:"Generic MII", 445 - features:MII_BASIC_FEATURES, 446 - magic_aneg:0, 447 - ops:&generic_phy_ops 90 + .phy_id = 0x000fc410, 91 + .phy_id_mask = 0x000ffff0, 92 + .name = "CIS8201 Gigabit Ethernet", 93 + .ops = &cis8201_phy_ops 448 94 }; 449 95 450 96 static struct mii_phy_def *mii_phy_table[] = { ··· 294 258 NULL 295 259 }; 296 260 297 - int mii_phy_probe(struct mii_phy *phy, int mii_id) 261 + int mii_phy_probe(struct mii_phy *phy, int address) 298 262 { 299 - int rc; 300 - u32 id; 301 263 struct mii_phy_def *def; 302 264 int i; 265 + u32 id; 303 266 304 - phy->autoneg = 0; 267 + phy->autoneg = AUTONEG_DISABLE; 305 268 phy->advertising = 0; 306 - phy->mii_id = mii_id; 307 - phy->speed = 0; 308 - phy->duplex = 0; 309 - phy->pause = 0; 269 + phy->address = address; 270 + phy->speed = SPEED_10; 271 + phy->duplex = DUPLEX_HALF; 272 + phy->pause = phy->asym_pause = 0; 310 273 311 - /* Take PHY out of isloate mode and reset it. */ 312 - rc = reset_one_mii_phy(phy, mii_id); 313 - if (rc) 274 + /* Take PHY out of isolate mode and reset it. */ 275 + if (mii_reset_phy(phy)) 314 276 return -ENODEV; 315 277 316 278 /* Read ID and find matching entry */ 317 - id = (phy_read(phy, MII_PHYSID1) << 16 | phy_read(phy, MII_PHYSID2)) 318 - & 0xfffffff0; 279 + id = (phy_read(phy, MII_PHYSID1) << 16) | phy_read(phy, MII_PHYSID2); 319 280 for (i = 0; (def = mii_phy_table[i]) != NULL; i++) 320 281 if ((id & def->phy_id_mask) == def->phy_id) 321 282 break; 322 283 /* Should never be NULL (we have a generic entry), but... */ 323 - if (def == NULL) 284 + if (!def) 324 285 return -ENODEV; 325 286 326 287 phy->def = def; 327 288 289 + /* Determine PHY features if needed */ 290 + phy->features = def->features; 291 + if (!phy->features) { 292 + u16 bmsr = phy_read(phy, MII_BMSR); 293 + if (bmsr & BMSR_ANEGCAPABLE) 294 + phy->features |= SUPPORTED_Autoneg; 295 + if (bmsr & BMSR_10HALF) 296 + phy->features |= SUPPORTED_10baseT_Half; 297 + if (bmsr & BMSR_10FULL) 298 + phy->features |= SUPPORTED_10baseT_Full; 299 + if (bmsr & BMSR_100HALF) 300 + phy->features |= SUPPORTED_100baseT_Half; 301 + if (bmsr & BMSR_100FULL) 302 + phy->features |= SUPPORTED_100baseT_Full; 303 + if (bmsr & BMSR_ESTATEN) { 304 + u16 esr = phy_read(phy, MII_ESTATUS); 305 + if (esr & ESTATUS_1000_TFULL) 306 + phy->features |= SUPPORTED_1000baseT_Full; 307 + if (esr & ESTATUS_1000_THALF) 308 + phy->features |= SUPPORTED_1000baseT_Half; 309 + } 310 + phy->features |= SUPPORTED_MII; 311 + } 312 + 328 313 /* Setup default advertising */ 329 - phy->advertising = def->features; 314 + phy->advertising = phy->features; 330 315 331 316 return 0; 332 317 }
+24 -81
drivers/net/ibm_emac/ibm_emac_phy.h
··· 1 - 2 1 /* 3 - * ibm_emac_phy.h 2 + * drivers/net/ibm_emac/ibm_emac_phy.h 4 3 * 4 + * Driver for PowerPC 4xx on-chip ethernet controller, PHY support 5 5 * 6 - * Benjamin Herrenschmidt <benh@kernel.crashing.org> 7 - * February 2003 6 + * Benjamin Herrenschmidt <benh@kernel.crashing.org> 7 + * February 2003 8 + * 9 + * Minor additions by Eugene Surovegin <ebs@ebshome.net>, 2004 8 10 * 9 11 * This program is free software; you can redistribute it and/or modify it 10 - * under the terms of the GNU General Public License as published by the 11 - * Free Software Foundation; either version 2 of the License, or (at your 12 - * option) any later version. 13 - * 14 - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 16 - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 17 - * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 20 - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 21 - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 - * 25 - * You should have received a copy of the GNU General Public License along 26 - * with this program; if not, write to the Free Software Foundation, Inc., 27 - * 675 Mass Ave, Cambridge, MA 02139, USA. 28 - * 12 + * under the terms of the GNU General Public License as published by the 13 + * Free Software Foundation; either version 2 of the License, or (at your 14 + * option) any later version. 29 15 * 30 16 * This file basically duplicates sungem_phy.{c,h} with different PHYs 31 17 * supported. I'm looking into merging that in a single mii layer more 32 18 * flexible than mii.c 33 19 */ 34 20 35 - #ifndef _IBM_EMAC_PHY_H_ 36 - #define _IBM_EMAC_PHY_H_ 37 - 38 - /* 39 - * PHY mode settings 40 - * Used for multi-mode capable PHYs 41 - */ 42 - #define PHY_MODE_NA 0 43 - #define PHY_MODE_MII 1 44 - #define PHY_MODE_RMII 2 45 - #define PHY_MODE_SMII 3 46 - #define PHY_MODE_RGMII 4 47 - #define PHY_MODE_TBI 5 48 - #define PHY_MODE_GMII 6 49 - #define PHY_MODE_RTBI 7 50 - #define PHY_MODE_SGMII 8 51 - 52 - /* 53 - * PHY specific registers/values 54 - */ 55 - 56 - /* CIS8201 */ 57 - #define MII_CIS8201_EPCR 0x17 58 - #define EPCR_MODE_MASK 0x3000 59 - #define EPCR_GMII_MODE 0x0000 60 - #define EPCR_RGMII_MODE 0x1000 61 - #define EPCR_TBI_MODE 0x2000 62 - #define EPCR_RTBI_MODE 0x3000 21 + #ifndef _IBM_OCP_PHY_H_ 22 + #define _IBM_OCP_PHY_H_ 63 23 64 24 struct mii_phy; 65 25 ··· 37 77 struct mii_phy_def { 38 78 u32 phy_id; /* Concatenated ID1 << 16 | ID2 */ 39 79 u32 phy_id_mask; /* Significant bits */ 40 - u32 features; /* Ethtool SUPPORTED_* defines */ 80 + u32 features; /* Ethtool SUPPORTED_* defines or 81 + 0 for autodetect */ 41 82 int magic_aneg; /* Autoneg does all speed test for us */ 42 83 const char *name; 43 84 const struct mii_phy_ops *ops; ··· 47 86 /* An instance of a PHY, partially borrowed from mii_if_info */ 48 87 struct mii_phy { 49 88 struct mii_phy_def *def; 50 - int advertising; 51 - int mii_id; 89 + u32 advertising; /* Ethtool ADVERTISED_* defines */ 90 + u32 features; /* Copied from mii_phy_def.features 91 + or determined automaticaly */ 92 + int address; /* PHY address */ 93 + int mode; /* PHY mode */ 52 94 53 95 /* 1: autoneg enabled, 0: disabled */ 54 96 int autoneg; ··· 62 98 int speed; 63 99 int duplex; 64 100 int pause; 65 - 66 - /* PHY mode - if needed */ 67 - int mode; 101 + int asym_pause; 68 102 69 103 /* Provided by host chip */ 70 104 struct net_device *dev; 71 - int (*mdio_read) (struct net_device * dev, int mii_id, int reg); 72 - void (*mdio_write) (struct net_device * dev, int mii_id, int reg, 105 + int (*mdio_read) (struct net_device * dev, int addr, int reg); 106 + void (*mdio_write) (struct net_device * dev, int addr, int reg, 73 107 int val); 74 108 }; 75 109 76 110 /* Pass in a struct mii_phy with dev, mdio_read and mdio_write 77 111 * filled, the remaining fields will be filled on return 78 112 */ 79 - extern int mii_phy_probe(struct mii_phy *phy, int mii_id); 113 + int mii_phy_probe(struct mii_phy *phy, int address); 114 + int mii_reset_phy(struct mii_phy *phy); 80 115 81 - static inline int __phy_read(struct mii_phy *phy, int id, int reg) 82 - { 83 - return phy->mdio_read(phy->dev, id, reg); 84 - } 85 - 86 - static inline void __phy_write(struct mii_phy *phy, int id, int reg, int val) 87 - { 88 - phy->mdio_write(phy->dev, id, reg, val); 89 - } 90 - 91 - static inline int phy_read(struct mii_phy *phy, int reg) 92 - { 93 - return phy->mdio_read(phy->dev, phy->mii_id, reg); 94 - } 95 - 96 - static inline void phy_write(struct mii_phy *phy, int reg, int val) 97 - { 98 - phy->mdio_write(phy->dev, phy->mii_id, reg, val); 99 - } 100 - 101 - #endif /* _IBM_EMAC_PHY_H_ */ 116 + #endif /* _IBM_OCP_PHY_H_ */
+201
drivers/net/ibm_emac/ibm_emac_rgmii.c
··· 1 + /* 2 + * drivers/net/ibm_emac/ibm_emac_rgmii.c 3 + * 4 + * Driver for PowerPC 4xx on-chip ethernet controller, RGMII bridge support. 5 + * 6 + * Copyright (c) 2004, 2005 Zultys Technologies. 7 + * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net> 8 + * 9 + * Based on original work by 10 + * Matt Porter <mporter@kernel.crashing.org> 11 + * Copyright 2004 MontaVista Software, Inc. 12 + * 13 + * This program is free software; you can redistribute it and/or modify it 14 + * under the terms of the GNU General Public License as published by the 15 + * Free Software Foundation; either version 2 of the License, or (at your 16 + * option) any later version. 17 + * 18 + */ 19 + #include <linux/config.h> 20 + #include <linux/kernel.h> 21 + #include <linux/ethtool.h> 22 + #include <asm/io.h> 23 + 24 + #include "ibm_emac_core.h" 25 + #include "ibm_emac_debug.h" 26 + 27 + /* RGMIIx_FER */ 28 + #define RGMII_FER_MASK(idx) (0x7 << ((idx) * 4)) 29 + #define RGMII_FER_RTBI(idx) (0x4 << ((idx) * 4)) 30 + #define RGMII_FER_RGMII(idx) (0x5 << ((idx) * 4)) 31 + #define RGMII_FER_TBI(idx) (0x6 << ((idx) * 4)) 32 + #define RGMII_FER_GMII(idx) (0x7 << ((idx) * 4)) 33 + 34 + /* RGMIIx_SSR */ 35 + #define RGMII_SSR_MASK(idx) (0x7 << ((idx) * 8)) 36 + #define RGMII_SSR_100(idx) (0x2 << ((idx) * 8)) 37 + #define RGMII_SSR_1000(idx) (0x4 << ((idx) * 8)) 38 + 39 + /* RGMII bridge supports only GMII/TBI and RGMII/RTBI PHYs */ 40 + static inline int rgmii_valid_mode(int phy_mode) 41 + { 42 + return phy_mode == PHY_MODE_GMII || 43 + phy_mode == PHY_MODE_RGMII || 44 + phy_mode == PHY_MODE_TBI || 45 + phy_mode == PHY_MODE_RTBI; 46 + } 47 + 48 + static inline const char *rgmii_mode_name(int mode) 49 + { 50 + switch (mode) { 51 + case PHY_MODE_RGMII: 52 + return "RGMII"; 53 + case PHY_MODE_TBI: 54 + return "TBI"; 55 + case PHY_MODE_GMII: 56 + return "GMII"; 57 + case PHY_MODE_RTBI: 58 + return "RTBI"; 59 + default: 60 + BUG(); 61 + } 62 + } 63 + 64 + static inline u32 rgmii_mode_mask(int mode, int input) 65 + { 66 + switch (mode) { 67 + case PHY_MODE_RGMII: 68 + return RGMII_FER_RGMII(input); 69 + case PHY_MODE_TBI: 70 + return RGMII_FER_TBI(input); 71 + case PHY_MODE_GMII: 72 + return RGMII_FER_GMII(input); 73 + case PHY_MODE_RTBI: 74 + return RGMII_FER_RTBI(input); 75 + default: 76 + BUG(); 77 + } 78 + } 79 + 80 + static int __init rgmii_init(struct ocp_device *ocpdev, int input, int mode) 81 + { 82 + struct ibm_ocp_rgmii *dev = ocp_get_drvdata(ocpdev); 83 + struct rgmii_regs *p; 84 + 85 + RGMII_DBG("%d: init(%d, %d)" NL, ocpdev->def->index, input, mode); 86 + 87 + if (!dev) { 88 + dev = kzalloc(sizeof(struct ibm_ocp_rgmii), GFP_KERNEL); 89 + if (!dev) { 90 + printk(KERN_ERR 91 + "rgmii%d: couldn't allocate device structure!\n", 92 + ocpdev->def->index); 93 + return -ENOMEM; 94 + } 95 + 96 + p = (struct rgmii_regs *)ioremap(ocpdev->def->paddr, 97 + sizeof(struct rgmii_regs)); 98 + if (!p) { 99 + printk(KERN_ERR 100 + "rgmii%d: could not ioremap device registers!\n", 101 + ocpdev->def->index); 102 + kfree(dev); 103 + return -ENOMEM; 104 + } 105 + 106 + dev->base = p; 107 + ocp_set_drvdata(ocpdev, dev); 108 + 109 + /* Disable all inputs by default */ 110 + out_be32(&p->fer, 0); 111 + } else 112 + p = dev->base; 113 + 114 + /* Enable this input */ 115 + out_be32(&p->fer, in_be32(&p->fer) | rgmii_mode_mask(mode, input)); 116 + 117 + printk(KERN_NOTICE "rgmii%d: input %d in %s mode\n", 118 + ocpdev->def->index, input, rgmii_mode_name(mode)); 119 + 120 + ++dev->users; 121 + return 0; 122 + } 123 + 124 + int __init rgmii_attach(void *emac) 125 + { 126 + struct ocp_enet_private *dev = emac; 127 + struct ocp_func_emac_data *emacdata = dev->def->additions; 128 + 129 + /* Check if we need to attach to a RGMII */ 130 + if (emacdata->rgmii_idx >= 0 && rgmii_valid_mode(emacdata->phy_mode)) { 131 + dev->rgmii_input = emacdata->rgmii_mux; 132 + dev->rgmii_dev = 133 + ocp_find_device(OCP_VENDOR_IBM, OCP_FUNC_RGMII, 134 + emacdata->rgmii_idx); 135 + if (!dev->rgmii_dev) { 136 + printk(KERN_ERR "emac%d: unknown rgmii%d!\n", 137 + dev->def->index, emacdata->rgmii_idx); 138 + return -ENODEV; 139 + } 140 + if (rgmii_init 141 + (dev->rgmii_dev, dev->rgmii_input, emacdata->phy_mode)) { 142 + printk(KERN_ERR 143 + "emac%d: rgmii%d initialization failed!\n", 144 + dev->def->index, emacdata->rgmii_idx); 145 + return -ENODEV; 146 + } 147 + } 148 + return 0; 149 + } 150 + 151 + void rgmii_set_speed(struct ocp_device *ocpdev, int input, int speed) 152 + { 153 + struct ibm_ocp_rgmii *dev = ocp_get_drvdata(ocpdev); 154 + u32 ssr = in_be32(&dev->base->ssr) & ~RGMII_SSR_MASK(input); 155 + 156 + RGMII_DBG("%d: speed(%d, %d)" NL, ocpdev->def->index, input, speed); 157 + 158 + if (speed == SPEED_1000) 159 + ssr |= RGMII_SSR_1000(input); 160 + else if (speed == SPEED_100) 161 + ssr |= RGMII_SSR_100(input); 162 + 163 + out_be32(&dev->base->ssr, ssr); 164 + } 165 + 166 + void __exit __rgmii_fini(struct ocp_device *ocpdev, int input) 167 + { 168 + struct ibm_ocp_rgmii *dev = ocp_get_drvdata(ocpdev); 169 + BUG_ON(!dev || dev->users == 0); 170 + 171 + RGMII_DBG("%d: fini(%d)" NL, ocpdev->def->index, input); 172 + 173 + /* Disable this input */ 174 + out_be32(&dev->base->fer, 175 + in_be32(&dev->base->fer) & ~RGMII_FER_MASK(input)); 176 + 177 + if (!--dev->users) { 178 + /* Free everything if this is the last user */ 179 + ocp_set_drvdata(ocpdev, NULL); 180 + iounmap((void *)dev->base); 181 + kfree(dev); 182 + } 183 + } 184 + 185 + int __rgmii_get_regs_len(struct ocp_device *ocpdev) 186 + { 187 + return sizeof(struct emac_ethtool_regs_subhdr) + 188 + sizeof(struct rgmii_regs); 189 + } 190 + 191 + void *rgmii_dump_regs(struct ocp_device *ocpdev, void *buf) 192 + { 193 + struct ibm_ocp_rgmii *dev = ocp_get_drvdata(ocpdev); 194 + struct emac_ethtool_regs_subhdr *hdr = buf; 195 + struct rgmii_regs *regs = (struct rgmii_regs *)(hdr + 1); 196 + 197 + hdr->version = 0; 198 + hdr->index = ocpdev->def->index; 199 + memcpy_fromio(regs, dev->base, sizeof(struct rgmii_regs)); 200 + return regs + 1; 201 + }
+30 -30
drivers/net/ibm_emac/ibm_emac_rgmii.h
··· 1 1 /* 2 - * Defines for the IBM RGMII bridge 2 + * drivers/net/ibm_emac/ibm_emac_rgmii.c 3 + * 4 + * Driver for PowerPC 4xx on-chip ethernet controller, RGMII bridge support. 3 5 * 4 6 * Based on ocp_zmii.h/ibm_emac_zmii.h 5 7 * Armin Kuster akuster@mvista.com 6 8 * 7 9 * Copyright 2004 MontaVista Software, Inc. 8 10 * Matt Porter <mporter@kernel.crashing.org> 11 + * 12 + * Copyright (c) 2004, 2005 Zultys Technologies. 13 + * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net> 9 14 * 10 15 * This program is free software; you can redistribute it and/or modify it 11 16 * under the terms of the GNU General Public License as published by the ··· 24 19 #include <linux/config.h> 25 20 26 21 /* RGMII bridge */ 27 - typedef struct rgmii_regs { 22 + struct rgmii_regs { 28 23 u32 fer; /* Function enable register */ 29 24 u32 ssr; /* Speed select register */ 30 - } rgmii_t; 31 - 32 - #define RGMII_INPUTS 4 25 + }; 33 26 34 27 /* RGMII device */ 35 28 struct ibm_ocp_rgmii { 36 29 struct rgmii_regs *base; 37 - int mode[RGMII_INPUTS]; 38 30 int users; /* number of EMACs using this RGMII bridge */ 39 31 }; 40 32 41 - /* Fuctional Enable Reg */ 42 - #define RGMII_FER_MASK(x) (0x00000007 << (4*x)) 43 - #define RGMII_RTBI 0x00000004 44 - #define RGMII_RGMII 0x00000005 45 - #define RGMII_TBI 0x00000006 46 - #define RGMII_GMII 0x00000007 33 + #ifdef CONFIG_IBM_EMAC_RGMII 34 + int rgmii_attach(void *emac) __init; 47 35 48 - /* Speed Selection reg */ 36 + void __rgmii_fini(struct ocp_device *ocpdev, int input) __exit; 37 + static inline void rgmii_fini(struct ocp_device *ocpdev, int input) 38 + { 39 + if (ocpdev) 40 + __rgmii_fini(ocpdev, input); 41 + } 49 42 50 - #define RGMII_SP2_100 0x00000002 51 - #define RGMII_SP2_1000 0x00000004 52 - #define RGMII_SP3_100 0x00000200 53 - #define RGMII_SP3_1000 0x00000400 43 + void rgmii_set_speed(struct ocp_device *ocpdev, int input, int speed); 54 44 55 - #define RGMII_MII2_SPDMASK 0x00000007 56 - #define RGMII_MII3_SPDMASK 0x00000700 45 + int __rgmii_get_regs_len(struct ocp_device *ocpdev); 46 + static inline int rgmii_get_regs_len(struct ocp_device *ocpdev) 47 + { 48 + return ocpdev ? __rgmii_get_regs_len(ocpdev) : 0; 49 + } 57 50 58 - #define RGMII_MII2_100MB RGMII_SP2_100 & ~RGMII_SP2_1000 59 - #define RGMII_MII2_1000MB RGMII_SP2_1000 & ~RGMII_SP2_100 60 - #define RGMII_MII2_10MB ~(RGMII_SP2_100 | RGMII_SP2_1000) 61 - #define RGMII_MII3_100MB RGMII_SP3_100 & ~RGMII_SP3_1000 62 - #define RGMII_MII3_1000MB RGMII_SP3_1000 & ~RGMII_SP3_100 63 - #define RGMII_MII3_10MB ~(RGMII_SP3_100 | RGMII_SP3_1000) 64 - 65 - #define RTBI 0 66 - #define RGMII 1 67 - #define TBI 2 68 - #define GMII 3 51 + void *rgmii_dump_regs(struct ocp_device *ocpdev, void *buf); 52 + #else 53 + # define rgmii_attach(x) 0 54 + # define rgmii_fini(x,y) ((void)0) 55 + # define rgmii_set_speed(x,y,z) ((void)0) 56 + # define rgmii_get_regs_len(x) 0 57 + # define rgmii_dump_regs(x,buf) (buf) 58 + #endif /* !CONFIG_IBM_EMAC_RGMII */ 69 59 70 60 #endif /* _IBM_EMAC_RGMII_H_ */
+111
drivers/net/ibm_emac/ibm_emac_tah.c
··· 1 + /* 2 + * drivers/net/ibm_emac/ibm_emac_tah.c 3 + * 4 + * Driver for PowerPC 4xx on-chip ethernet controller, TAH support. 5 + * 6 + * Copyright 2004 MontaVista Software, Inc. 7 + * Matt Porter <mporter@kernel.crashing.org> 8 + * 9 + * Copyright (c) 2005 Eugene Surovegin <ebs@ebshome.net> 10 + * 11 + * This program is free software; you can redistribute it and/or modify it 12 + * under the terms of the GNU General Public License as published by the 13 + * Free Software Foundation; either version 2 of the License, or (at your 14 + * option) any later version. 15 + */ 16 + #include <linux/config.h> 17 + #include <asm/io.h> 18 + 19 + #include "ibm_emac_core.h" 20 + 21 + static int __init tah_init(struct ocp_device *ocpdev) 22 + { 23 + struct tah_regs *p; 24 + 25 + if (ocp_get_drvdata(ocpdev)) { 26 + printk(KERN_ERR "tah%d: already in use!\n", ocpdev->def->index); 27 + return -EBUSY; 28 + } 29 + 30 + /* Initialize TAH and enable IPv4 checksum verification, no TSO yet */ 31 + p = (struct tah_regs *)ioremap(ocpdev->def->paddr, sizeof(*p)); 32 + if (!p) { 33 + printk(KERN_ERR "tah%d: could not ioremap device registers!\n", 34 + ocpdev->def->index); 35 + return -ENOMEM; 36 + } 37 + ocp_set_drvdata(ocpdev, p); 38 + __tah_reset(ocpdev); 39 + 40 + return 0; 41 + } 42 + 43 + int __init tah_attach(void *emac) 44 + { 45 + struct ocp_enet_private *dev = emac; 46 + struct ocp_func_emac_data *emacdata = dev->def->additions; 47 + 48 + /* Check if we need to attach to a TAH */ 49 + if (emacdata->tah_idx >= 0) { 50 + dev->tah_dev = ocp_find_device(OCP_ANY_ID, OCP_FUNC_TAH, 51 + emacdata->tah_idx); 52 + if (!dev->tah_dev) { 53 + printk(KERN_ERR "emac%d: unknown tah%d!\n", 54 + dev->def->index, emacdata->tah_idx); 55 + return -ENODEV; 56 + } 57 + if (tah_init(dev->tah_dev)) { 58 + printk(KERN_ERR 59 + "emac%d: tah%d initialization failed!\n", 60 + dev->def->index, emacdata->tah_idx); 61 + return -ENODEV; 62 + } 63 + } 64 + return 0; 65 + } 66 + 67 + void __exit __tah_fini(struct ocp_device *ocpdev) 68 + { 69 + struct tah_regs *p = ocp_get_drvdata(ocpdev); 70 + BUG_ON(!p); 71 + ocp_set_drvdata(ocpdev, NULL); 72 + iounmap((void *)p); 73 + } 74 + 75 + void __tah_reset(struct ocp_device *ocpdev) 76 + { 77 + struct tah_regs *p = ocp_get_drvdata(ocpdev); 78 + int n; 79 + 80 + /* Reset TAH */ 81 + out_be32(&p->mr, TAH_MR_SR); 82 + n = 100; 83 + while ((in_be32(&p->mr) & TAH_MR_SR) && n) 84 + --n; 85 + 86 + if (unlikely(!n)) 87 + printk(KERN_ERR "tah%d: reset timeout\n", ocpdev->def->index); 88 + 89 + /* 10KB TAH TX FIFO accomodates the max MTU of 9000 */ 90 + out_be32(&p->mr, 91 + TAH_MR_CVR | TAH_MR_ST_768 | TAH_MR_TFS_10KB | TAH_MR_DTFP | 92 + TAH_MR_DIG); 93 + } 94 + 95 + int __tah_get_regs_len(struct ocp_device *ocpdev) 96 + { 97 + return sizeof(struct emac_ethtool_regs_subhdr) + 98 + sizeof(struct tah_regs); 99 + } 100 + 101 + void *tah_dump_regs(struct ocp_device *ocpdev, void *buf) 102 + { 103 + struct tah_regs *dev = ocp_get_drvdata(ocpdev); 104 + struct emac_ethtool_regs_subhdr *hdr = buf; 105 + struct tah_regs *regs = (struct tah_regs *)(hdr + 1); 106 + 107 + hdr->version = 0; 108 + hdr->index = ocpdev->def->index; 109 + memcpy_fromio(regs, dev, sizeof(struct tah_regs)); 110 + return regs + 1; 111 + }
+68 -28
drivers/net/ibm_emac/ibm_emac_tah.h
··· 1 1 /* 2 - * Defines for the IBM TAH 2 + * drivers/net/ibm_emac/ibm_emac_tah.h 3 + * 4 + * Driver for PowerPC 4xx on-chip ethernet controller, TAH support. 3 5 * 4 6 * Copyright 2004 MontaVista Software, Inc. 5 7 * Matt Porter <mporter@kernel.crashing.org> 8 + * 9 + * Copyright (c) 2005 Eugene Surovegin <ebs@ebshome.net> 6 10 * 7 11 * This program is free software; you can redistribute it and/or modify it 8 12 * under the terms of the GNU General Public License as published by the ··· 17 13 #ifndef _IBM_EMAC_TAH_H 18 14 #define _IBM_EMAC_TAH_H 19 15 16 + #include <linux/config.h> 17 + #include <linux/init.h> 18 + #include <asm/ocp.h> 19 + 20 20 /* TAH */ 21 - typedef struct tah_regs { 22 - u32 tah_revid; 21 + struct tah_regs { 22 + u32 revid; 23 23 u32 pad[3]; 24 - u32 tah_mr; 25 - u32 tah_ssr0; 26 - u32 tah_ssr1; 27 - u32 tah_ssr2; 28 - u32 tah_ssr3; 29 - u32 tah_ssr4; 30 - u32 tah_ssr5; 31 - u32 tah_tsr; 32 - } tah_t; 24 + u32 mr; 25 + u32 ssr0; 26 + u32 ssr1; 27 + u32 ssr2; 28 + u32 ssr3; 29 + u32 ssr4; 30 + u32 ssr5; 31 + u32 tsr; 32 + }; 33 33 34 34 /* TAH engine */ 35 - #define TAH_MR_CVR 0x80000000 36 - #define TAH_MR_SR 0x40000000 37 - #define TAH_MR_ST_256 0x01000000 38 - #define TAH_MR_ST_512 0x02000000 39 - #define TAH_MR_ST_768 0x03000000 40 - #define TAH_MR_ST_1024 0x04000000 41 - #define TAH_MR_ST_1280 0x05000000 42 - #define TAH_MR_ST_1536 0x06000000 43 - #define TAH_MR_TFS_16KB 0x00000000 44 - #define TAH_MR_TFS_2KB 0x00200000 45 - #define TAH_MR_TFS_4KB 0x00400000 46 - #define TAH_MR_TFS_6KB 0x00600000 47 - #define TAH_MR_TFS_8KB 0x00800000 48 - #define TAH_MR_TFS_10KB 0x00a00000 49 - #define TAH_MR_DTFP 0x00100000 50 - #define TAH_MR_DIG 0x00080000 35 + #define TAH_MR_CVR 0x80000000 36 + #define TAH_MR_SR 0x40000000 37 + #define TAH_MR_ST_256 0x01000000 38 + #define TAH_MR_ST_512 0x02000000 39 + #define TAH_MR_ST_768 0x03000000 40 + #define TAH_MR_ST_1024 0x04000000 41 + #define TAH_MR_ST_1280 0x05000000 42 + #define TAH_MR_ST_1536 0x06000000 43 + #define TAH_MR_TFS_16KB 0x00000000 44 + #define TAH_MR_TFS_2KB 0x00200000 45 + #define TAH_MR_TFS_4KB 0x00400000 46 + #define TAH_MR_TFS_6KB 0x00600000 47 + #define TAH_MR_TFS_8KB 0x00800000 48 + #define TAH_MR_TFS_10KB 0x00a00000 49 + #define TAH_MR_DTFP 0x00100000 50 + #define TAH_MR_DIG 0x00080000 51 + 52 + #ifdef CONFIG_IBM_EMAC_TAH 53 + int tah_attach(void *emac) __init; 54 + 55 + void __tah_fini(struct ocp_device *ocpdev) __exit; 56 + static inline void tah_fini(struct ocp_device *ocpdev) 57 + { 58 + if (ocpdev) 59 + __tah_fini(ocpdev); 60 + } 61 + 62 + void __tah_reset(struct ocp_device *ocpdev); 63 + static inline void tah_reset(struct ocp_device *ocpdev) 64 + { 65 + if (ocpdev) 66 + __tah_reset(ocpdev); 67 + } 68 + 69 + int __tah_get_regs_len(struct ocp_device *ocpdev); 70 + static inline int tah_get_regs_len(struct ocp_device *ocpdev) 71 + { 72 + return ocpdev ? __tah_get_regs_len(ocpdev) : 0; 73 + } 74 + 75 + void *tah_dump_regs(struct ocp_device *ocpdev, void *buf); 76 + #else 77 + # define tah_attach(x) 0 78 + # define tah_fini(x) ((void)0) 79 + # define tah_reset(x) ((void)0) 80 + # define tah_get_regs_len(x) 0 81 + # define tah_dump_regs(x,buf) (buf) 82 + #endif /* !CONFIG_IBM_EMAC_TAH */ 51 83 52 84 #endif /* _IBM_EMAC_TAH_H */
+255
drivers/net/ibm_emac/ibm_emac_zmii.c
··· 1 + /* 2 + * drivers/net/ibm_emac/ibm_emac_zmii.c 3 + * 4 + * Driver for PowerPC 4xx on-chip ethernet controller, ZMII bridge support. 5 + * 6 + * Copyright (c) 2004, 2005 Zultys Technologies. 7 + * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net> 8 + * 9 + * Based on original work by 10 + * Armin Kuster <akuster@mvista.com> 11 + * Copyright 2001 MontaVista Softare Inc. 12 + * 13 + * This program is free software; you can redistribute it and/or modify it 14 + * under the terms of the GNU General Public License as published by the 15 + * Free Software Foundation; either version 2 of the License, or (at your 16 + * option) any later version. 17 + * 18 + */ 19 + #include <linux/config.h> 20 + #include <linux/kernel.h> 21 + #include <linux/ethtool.h> 22 + #include <asm/io.h> 23 + 24 + #include "ibm_emac_core.h" 25 + #include "ibm_emac_debug.h" 26 + 27 + /* ZMIIx_FER */ 28 + #define ZMII_FER_MDI(idx) (0x80000000 >> ((idx) * 4)) 29 + #define ZMII_FER_MDI_ALL (ZMII_FER_MDI(0) | ZMII_FER_MDI(1) | \ 30 + ZMII_FER_MDI(2) | ZMII_FER_MDI(3)) 31 + 32 + #define ZMII_FER_SMII(idx) (0x40000000 >> ((idx) * 4)) 33 + #define ZMII_FER_RMII(idx) (0x20000000 >> ((idx) * 4)) 34 + #define ZMII_FER_MII(idx) (0x10000000 >> ((idx) * 4)) 35 + 36 + /* ZMIIx_SSR */ 37 + #define ZMII_SSR_SCI(idx) (0x40000000 >> ((idx) * 4)) 38 + #define ZMII_SSR_FSS(idx) (0x20000000 >> ((idx) * 4)) 39 + #define ZMII_SSR_SP(idx) (0x10000000 >> ((idx) * 4)) 40 + 41 + /* ZMII only supports MII, RMII and SMII 42 + * we also support autodetection for backward compatibility 43 + */ 44 + static inline int zmii_valid_mode(int mode) 45 + { 46 + return mode == PHY_MODE_MII || 47 + mode == PHY_MODE_RMII || 48 + mode == PHY_MODE_SMII || 49 + mode == PHY_MODE_NA; 50 + } 51 + 52 + static inline const char *zmii_mode_name(int mode) 53 + { 54 + switch (mode) { 55 + case PHY_MODE_MII: 56 + return "MII"; 57 + case PHY_MODE_RMII: 58 + return "RMII"; 59 + case PHY_MODE_SMII: 60 + return "SMII"; 61 + default: 62 + BUG(); 63 + } 64 + } 65 + 66 + static inline u32 zmii_mode_mask(int mode, int input) 67 + { 68 + switch (mode) { 69 + case PHY_MODE_MII: 70 + return ZMII_FER_MII(input); 71 + case PHY_MODE_RMII: 72 + return ZMII_FER_RMII(input); 73 + case PHY_MODE_SMII: 74 + return ZMII_FER_SMII(input); 75 + default: 76 + return 0; 77 + } 78 + } 79 + 80 + static int __init zmii_init(struct ocp_device *ocpdev, int input, int *mode) 81 + { 82 + struct ibm_ocp_zmii *dev = ocp_get_drvdata(ocpdev); 83 + struct zmii_regs *p; 84 + 85 + ZMII_DBG("%d: init(%d, %d)" NL, ocpdev->def->index, input, *mode); 86 + 87 + if (!dev) { 88 + dev = kzalloc(sizeof(struct ibm_ocp_zmii), GFP_KERNEL); 89 + if (!dev) { 90 + printk(KERN_ERR 91 + "zmii%d: couldn't allocate device structure!\n", 92 + ocpdev->def->index); 93 + return -ENOMEM; 94 + } 95 + dev->mode = PHY_MODE_NA; 96 + 97 + p = (struct zmii_regs *)ioremap(ocpdev->def->paddr, 98 + sizeof(struct zmii_regs)); 99 + if (!p) { 100 + printk(KERN_ERR 101 + "zmii%d: could not ioremap device registers!\n", 102 + ocpdev->def->index); 103 + kfree(dev); 104 + return -ENOMEM; 105 + } 106 + dev->base = p; 107 + ocp_set_drvdata(ocpdev, dev); 108 + 109 + /* We may need FER value for autodetection later */ 110 + dev->fer_save = in_be32(&p->fer); 111 + 112 + /* Disable all inputs by default */ 113 + out_be32(&p->fer, 0); 114 + } else 115 + p = dev->base; 116 + 117 + if (!zmii_valid_mode(*mode)) { 118 + /* Probably an EMAC connected to RGMII, 119 + * but it still may need ZMII for MDIO 120 + */ 121 + goto out; 122 + } 123 + 124 + /* Autodetect ZMII mode if not specified. 125 + * This is only for backward compatibility with the old driver. 126 + * Please, always specify PHY mode in your board port to avoid 127 + * any surprises. 128 + */ 129 + if (dev->mode == PHY_MODE_NA) { 130 + if (*mode == PHY_MODE_NA) { 131 + u32 r = dev->fer_save; 132 + 133 + ZMII_DBG("%d: autodetecting mode, FER = 0x%08x" NL, 134 + ocpdev->def->index, r); 135 + 136 + if (r & (ZMII_FER_MII(0) | ZMII_FER_MII(1))) 137 + dev->mode = PHY_MODE_MII; 138 + else if (r & (ZMII_FER_RMII(0) | ZMII_FER_RMII(1))) 139 + dev->mode = PHY_MODE_RMII; 140 + else 141 + dev->mode = PHY_MODE_SMII; 142 + } else 143 + dev->mode = *mode; 144 + 145 + printk(KERN_NOTICE "zmii%d: bridge in %s mode\n", 146 + ocpdev->def->index, zmii_mode_name(dev->mode)); 147 + } else { 148 + /* All inputs must use the same mode */ 149 + if (*mode != PHY_MODE_NA && *mode != dev->mode) { 150 + printk(KERN_ERR 151 + "zmii%d: invalid mode %d specified for input %d\n", 152 + ocpdev->def->index, *mode, input); 153 + return -EINVAL; 154 + } 155 + } 156 + 157 + /* Report back correct PHY mode, 158 + * it may be used during PHY initialization. 159 + */ 160 + *mode = dev->mode; 161 + 162 + /* Enable this input */ 163 + out_be32(&p->fer, in_be32(&p->fer) | zmii_mode_mask(dev->mode, input)); 164 + out: 165 + ++dev->users; 166 + return 0; 167 + } 168 + 169 + int __init zmii_attach(void *emac) 170 + { 171 + struct ocp_enet_private *dev = emac; 172 + struct ocp_func_emac_data *emacdata = dev->def->additions; 173 + 174 + if (emacdata->zmii_idx >= 0) { 175 + dev->zmii_input = emacdata->zmii_mux; 176 + dev->zmii_dev = 177 + ocp_find_device(OCP_VENDOR_IBM, OCP_FUNC_ZMII, 178 + emacdata->zmii_idx); 179 + if (!dev->zmii_dev) { 180 + printk(KERN_ERR "emac%d: unknown zmii%d!\n", 181 + dev->def->index, emacdata->zmii_idx); 182 + return -ENODEV; 183 + } 184 + if (zmii_init 185 + (dev->zmii_dev, dev->zmii_input, &emacdata->phy_mode)) { 186 + printk(KERN_ERR 187 + "emac%d: zmii%d initialization failed!\n", 188 + dev->def->index, emacdata->zmii_idx); 189 + return -ENODEV; 190 + } 191 + } 192 + return 0; 193 + } 194 + 195 + void __zmii_enable_mdio(struct ocp_device *ocpdev, int input) 196 + { 197 + struct ibm_ocp_zmii *dev = ocp_get_drvdata(ocpdev); 198 + u32 fer = in_be32(&dev->base->fer) & ~ZMII_FER_MDI_ALL; 199 + 200 + ZMII_DBG2("%d: mdio(%d)" NL, ocpdev->def->index, input); 201 + 202 + out_be32(&dev->base->fer, fer | ZMII_FER_MDI(input)); 203 + } 204 + 205 + void __zmii_set_speed(struct ocp_device *ocpdev, int input, int speed) 206 + { 207 + struct ibm_ocp_zmii *dev = ocp_get_drvdata(ocpdev); 208 + u32 ssr = in_be32(&dev->base->ssr); 209 + 210 + ZMII_DBG("%d: speed(%d, %d)" NL, ocpdev->def->index, input, speed); 211 + 212 + if (speed == SPEED_100) 213 + ssr |= ZMII_SSR_SP(input); 214 + else 215 + ssr &= ~ZMII_SSR_SP(input); 216 + 217 + out_be32(&dev->base->ssr, ssr); 218 + } 219 + 220 + void __exit __zmii_fini(struct ocp_device *ocpdev, int input) 221 + { 222 + struct ibm_ocp_zmii *dev = ocp_get_drvdata(ocpdev); 223 + BUG_ON(!dev || dev->users == 0); 224 + 225 + ZMII_DBG("%d: fini(%d)" NL, ocpdev->def->index, input); 226 + 227 + /* Disable this input */ 228 + out_be32(&dev->base->fer, 229 + in_be32(&dev->base->fer) & ~zmii_mode_mask(dev->mode, input)); 230 + 231 + if (!--dev->users) { 232 + /* Free everything if this is the last user */ 233 + ocp_set_drvdata(ocpdev, NULL); 234 + iounmap((void *)dev->base); 235 + kfree(dev); 236 + } 237 + } 238 + 239 + int __zmii_get_regs_len(struct ocp_device *ocpdev) 240 + { 241 + return sizeof(struct emac_ethtool_regs_subhdr) + 242 + sizeof(struct zmii_regs); 243 + } 244 + 245 + void *zmii_dump_regs(struct ocp_device *ocpdev, void *buf) 246 + { 247 + struct ibm_ocp_zmii *dev = ocp_get_drvdata(ocpdev); 248 + struct emac_ethtool_regs_subhdr *hdr = buf; 249 + struct zmii_regs *regs = (struct zmii_regs *)(hdr + 1); 250 + 251 + hdr->version = 0; 252 + hdr->index = ocpdev->def->index; 253 + memcpy_fromio(regs, dev->base, sizeof(struct zmii_regs)); 254 + return regs + 1; 255 + }
+47 -57
drivers/net/ibm_emac/ibm_emac_zmii.h
··· 1 1 /* 2 - * ocp_zmii.h 2 + * drivers/net/ibm_emac/ibm_emac_zmii.h 3 3 * 4 - * Defines for the IBM ZMII bridge 4 + * Driver for PowerPC 4xx on-chip ethernet controller, ZMII bridge support. 5 5 * 6 - * Armin Kuster akuster@mvista.com 7 - * Dec, 2001 6 + * Copyright (c) 2004, 2005 Zultys Technologies. 7 + * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net> 8 8 * 9 - * Copyright 2001 MontaVista Softare Inc. 9 + * Based on original work by 10 + * Armin Kuster <akuster@mvista.com> 11 + * Copyright 2001 MontaVista Softare Inc. 10 12 * 11 13 * This program is free software; you can redistribute it and/or modify it 12 14 * under the terms of the GNU General Public License as published by the 13 15 * Free Software Foundation; either version 2 of the License, or (at your 14 16 * option) any later version. 17 + * 15 18 */ 16 - 17 19 #ifndef _IBM_EMAC_ZMII_H_ 18 20 #define _IBM_EMAC_ZMII_H_ 19 21 20 22 #include <linux/config.h> 23 + #include <linux/init.h> 24 + #include <asm/ocp.h> 21 25 22 26 /* ZMII bridge registers */ 23 27 struct zmii_regs { ··· 30 26 u32 smiirs; /* SMII status reg */ 31 27 }; 32 28 33 - #define ZMII_INPUTS 4 34 - 35 29 /* ZMII device */ 36 30 struct ibm_ocp_zmii { 37 31 struct zmii_regs *base; 38 - int mode[ZMII_INPUTS]; 32 + int mode; /* subset of PHY_MODE_XXXX */ 39 33 int users; /* number of EMACs using this ZMII bridge */ 34 + u32 fer_save; /* FER value left by firmware */ 40 35 }; 41 36 42 - /* Fuctional Enable Reg */ 37 + #ifdef CONFIG_IBM_EMAC_ZMII 38 + int zmii_attach(void *emac) __init; 43 39 44 - #define ZMII_FER_MASK(x) (0xf0000000 >> (4*x)) 40 + void __zmii_fini(struct ocp_device *ocpdev, int input) __exit; 41 + static inline void zmii_fini(struct ocp_device *ocpdev, int input) 42 + { 43 + if (ocpdev) 44 + __zmii_fini(ocpdev, input); 45 + } 45 46 46 - #define ZMII_MDI0 0x80000000 47 - #define ZMII_SMII0 0x40000000 48 - #define ZMII_RMII0 0x20000000 49 - #define ZMII_MII0 0x10000000 50 - #define ZMII_MDI1 0x08000000 51 - #define ZMII_SMII1 0x04000000 52 - #define ZMII_RMII1 0x02000000 53 - #define ZMII_MII1 0x01000000 54 - #define ZMII_MDI2 0x00800000 55 - #define ZMII_SMII2 0x00400000 56 - #define ZMII_RMII2 0x00200000 57 - #define ZMII_MII2 0x00100000 58 - #define ZMII_MDI3 0x00080000 59 - #define ZMII_SMII3 0x00040000 60 - #define ZMII_RMII3 0x00020000 61 - #define ZMII_MII3 0x00010000 47 + void __zmii_enable_mdio(struct ocp_device *ocpdev, int input); 48 + static inline void zmii_enable_mdio(struct ocp_device *ocpdev, int input) 49 + { 50 + if (ocpdev) 51 + __zmii_enable_mdio(ocpdev, input); 52 + } 62 53 63 - /* Speed Selection reg */ 54 + void __zmii_set_speed(struct ocp_device *ocpdev, int input, int speed); 55 + static inline void zmii_set_speed(struct ocp_device *ocpdev, int input, 56 + int speed) 57 + { 58 + if (ocpdev) 59 + __zmii_set_speed(ocpdev, input, speed); 60 + } 64 61 65 - #define ZMII_SCI0 0x40000000 66 - #define ZMII_FSS0 0x20000000 67 - #define ZMII_SP0 0x10000000 68 - #define ZMII_SCI1 0x04000000 69 - #define ZMII_FSS1 0x02000000 70 - #define ZMII_SP1 0x01000000 71 - #define ZMII_SCI2 0x00400000 72 - #define ZMII_FSS2 0x00200000 73 - #define ZMII_SP2 0x00100000 74 - #define ZMII_SCI3 0x00040000 75 - #define ZMII_FSS3 0x00020000 76 - #define ZMII_SP3 0x00010000 62 + int __zmii_get_regs_len(struct ocp_device *ocpdev); 63 + static inline int zmii_get_regs_len(struct ocp_device *ocpdev) 64 + { 65 + return ocpdev ? __zmii_get_regs_len(ocpdev) : 0; 66 + } 77 67 78 - #define ZMII_MII0_100MB ZMII_SP0 79 - #define ZMII_MII0_10MB ~ZMII_SP0 80 - #define ZMII_MII1_100MB ZMII_SP1 81 - #define ZMII_MII1_10MB ~ZMII_SP1 82 - #define ZMII_MII2_100MB ZMII_SP2 83 - #define ZMII_MII2_10MB ~ZMII_SP2 84 - #define ZMII_MII3_100MB ZMII_SP3 85 - #define ZMII_MII3_10MB ~ZMII_SP3 68 + void *zmii_dump_regs(struct ocp_device *ocpdev, void *buf); 86 69 87 - /* SMII Status reg */ 88 - 89 - #define ZMII_STS0 0xFF000000 /* EMAC0 smii status mask */ 90 - #define ZMII_STS1 0x00FF0000 /* EMAC1 smii status mask */ 91 - 92 - #define SMII 0 93 - #define RMII 1 94 - #define MII 2 95 - #define MDI 3 70 + #else 71 + # define zmii_attach(x) 0 72 + # define zmii_fini(x,y) ((void)0) 73 + # define zmii_enable_mdio(x,y) ((void)0) 74 + # define zmii_set_speed(x,y,z) ((void)0) 75 + # define zmii_get_regs_len(x) 0 76 + # define zmii_dump_regs(x,buf) (buf) 77 + #endif /* !CONFIG_IBM_EMAC_ZMII */ 96 78 97 79 #endif /* _IBM_EMAC_ZMII_H_ */