Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Lennert Buytenhek | 9c1bbdf | 2007-10-19 04:11:03 +0200 | [diff] [blame] | 2 | * Driver for Marvell Discovery (MV643XX) and Marvell Orion ethernet ports |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * Copyright (C) 2002 Matthew Dharm <mdharm@momenco.com> |
| 4 | * |
| 5 | * Based on the 64360 driver from: |
Lennert Buytenhek | 4547fa6 | 2008-03-18 11:40:14 -0700 | [diff] [blame] | 6 | * Copyright (C) 2002 Rabeeh Khoury <rabeeh@galileo.co.il> |
| 7 | * Rabeeh Khoury <rabeeh@marvell.com> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | * |
| 9 | * Copyright (C) 2003 PMC-Sierra, Inc., |
Olaf Hering | 3bb8a18a | 2006-01-05 22:45:45 -0800 | [diff] [blame] | 10 | * written by Manish Lachwani |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | * |
| 12 | * Copyright (C) 2003 Ralf Baechle <ralf@linux-mips.org> |
| 13 | * |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 14 | * Copyright (C) 2004-2006 MontaVista Software, Inc. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | * Dale Farnsworth <dale@farnsworth.org> |
| 16 | * |
| 17 | * Copyright (C) 2004 Steven J. Hill <sjhill1@rockwellcollins.com> |
| 18 | * <sjhill@realitydiluted.com> |
| 19 | * |
Lennert Buytenhek | 4547fa6 | 2008-03-18 11:40:14 -0700 | [diff] [blame] | 20 | * Copyright (C) 2007-2008 Marvell Semiconductor |
| 21 | * Lennert Buytenhek <buytenh@marvell.com> |
| 22 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | * This program is free software; you can redistribute it and/or |
| 24 | * modify it under the terms of the GNU General Public License |
| 25 | * as published by the Free Software Foundation; either version 2 |
| 26 | * of the License, or (at your option) any later version. |
| 27 | * |
| 28 | * This program is distributed in the hope that it will be useful, |
| 29 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 30 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 31 | * GNU General Public License for more details. |
| 32 | * |
| 33 | * You should have received a copy of the GNU General Public License |
| 34 | * along with this program; if not, write to the Free Software |
| 35 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 36 | */ |
Lennert Buytenhek | a779d38 | 2008-06-01 00:54:05 +0200 | [diff] [blame] | 37 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | #include <linux/init.h> |
| 39 | #include <linux/dma-mapping.h> |
Al Viro | b6298c2 | 2006-01-18 19:35:54 -0500 | [diff] [blame] | 40 | #include <linux/in.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | #include <linux/tcp.h> |
| 42 | #include <linux/udp.h> |
| 43 | #include <linux/etherdevice.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | #include <linux/delay.h> |
| 45 | #include <linux/ethtool.h> |
Russell King | d052d1b | 2005-10-29 19:07:23 +0100 | [diff] [blame] | 46 | #include <linux/platform_device.h> |
Lennert Buytenhek | fbd6a75 | 2007-10-19 16:03:46 +0200 | [diff] [blame] | 47 | #include <linux/module.h> |
| 48 | #include <linux/kernel.h> |
| 49 | #include <linux/spinlock.h> |
| 50 | #include <linux/workqueue.h> |
| 51 | #include <linux/mii.h> |
Lennert Buytenhek | fbd6a75 | 2007-10-19 16:03:46 +0200 | [diff] [blame] | 52 | #include <linux/mv643xx_eth.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | #include <asm/io.h> |
| 54 | #include <asm/types.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | #include <asm/system.h> |
Lennert Buytenhek | fbd6a75 | 2007-10-19 16:03:46 +0200 | [diff] [blame] | 56 | |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 57 | static char mv643xx_eth_driver_name[] = "mv643xx_eth"; |
| 58 | static char mv643xx_eth_driver_version[] = "1.0"; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 59 | |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 60 | #define MV643XX_ETH_CHECKSUM_OFFLOAD_TX |
| 61 | #define MV643XX_ETH_NAPI |
| 62 | #define MV643XX_ETH_TX_FAST_REFILL |
Lennert Buytenhek | fbd6a75 | 2007-10-19 16:03:46 +0200 | [diff] [blame] | 63 | |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 64 | #ifdef MV643XX_ETH_CHECKSUM_OFFLOAD_TX |
Lennert Buytenhek | fbd6a75 | 2007-10-19 16:03:46 +0200 | [diff] [blame] | 65 | #define MAX_DESCS_PER_SKB (MAX_SKB_FRAGS + 1) |
| 66 | #else |
| 67 | #define MAX_DESCS_PER_SKB 1 |
| 68 | #endif |
| 69 | |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 70 | #define ETH_HW_IP_ALIGN 2 |
Lennert Buytenhek | fbd6a75 | 2007-10-19 16:03:46 +0200 | [diff] [blame] | 71 | |
| 72 | /* |
| 73 | * Registers shared between all ports. |
| 74 | */ |
Lennert Buytenhek | 3cb4667c | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 75 | #define PHY_ADDR 0x0000 |
| 76 | #define SMI_REG 0x0004 |
| 77 | #define WINDOW_BASE(w) (0x0200 + ((w) << 3)) |
| 78 | #define WINDOW_SIZE(w) (0x0204 + ((w) << 3)) |
| 79 | #define WINDOW_REMAP_HIGH(w) (0x0280 + ((w) << 2)) |
| 80 | #define WINDOW_BAR_ENABLE 0x0290 |
| 81 | #define WINDOW_PROTECT(w) (0x0294 + ((w) << 4)) |
Lennert Buytenhek | fbd6a75 | 2007-10-19 16:03:46 +0200 | [diff] [blame] | 82 | |
| 83 | /* |
| 84 | * Per-port registers. |
| 85 | */ |
Lennert Buytenhek | 3cb4667c | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 86 | #define PORT_CONFIG(p) (0x0400 + ((p) << 10)) |
Lennert Buytenhek | d9a073e | 2008-06-01 01:22:06 +0200 | [diff] [blame] | 87 | #define UNICAST_PROMISCUOUS_MODE 0x00000001 |
Lennert Buytenhek | 3cb4667c | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 88 | #define PORT_CONFIG_EXT(p) (0x0404 + ((p) << 10)) |
| 89 | #define MAC_ADDR_LOW(p) (0x0414 + ((p) << 10)) |
| 90 | #define MAC_ADDR_HIGH(p) (0x0418 + ((p) << 10)) |
| 91 | #define SDMA_CONFIG(p) (0x041c + ((p) << 10)) |
| 92 | #define PORT_SERIAL_CONTROL(p) (0x043c + ((p) << 10)) |
| 93 | #define PORT_STATUS(p) (0x0444 + ((p) << 10)) |
Lennert Buytenhek | a2a4168 | 2008-06-01 01:30:42 +0200 | [diff] [blame] | 94 | #define TX_FIFO_EMPTY 0x00000400 |
Lennert Buytenhek | 3cb4667c | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 95 | #define TXQ_COMMAND(p) (0x0448 + ((p) << 10)) |
| 96 | #define TX_BW_MTU(p) (0x0458 + ((p) << 10)) |
| 97 | #define INT_CAUSE(p) (0x0460 + ((p) << 10)) |
Lennert Buytenhek | 073a345 | 2008-06-01 02:00:31 +0200 | [diff] [blame] | 98 | #define INT_RX 0x00000804 |
| 99 | #define INT_EXT 0x00000002 |
Lennert Buytenhek | 3cb4667c | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 100 | #define INT_CAUSE_EXT(p) (0x0464 + ((p) << 10)) |
Lennert Buytenhek | 073a345 | 2008-06-01 02:00:31 +0200 | [diff] [blame] | 101 | #define INT_EXT_LINK 0x00100000 |
| 102 | #define INT_EXT_PHY 0x00010000 |
| 103 | #define INT_EXT_TX_ERROR_0 0x00000100 |
| 104 | #define INT_EXT_TX_0 0x00000001 |
| 105 | #define INT_EXT_TX 0x00000101 |
Lennert Buytenhek | 3cb4667c | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 106 | #define INT_MASK(p) (0x0468 + ((p) << 10)) |
| 107 | #define INT_MASK_EXT(p) (0x046c + ((p) << 10)) |
| 108 | #define TX_FIFO_URGENT_THRESHOLD(p) (0x0474 + ((p) << 10)) |
| 109 | #define RXQ_CURRENT_DESC_PTR(p) (0x060c + ((p) << 10)) |
| 110 | #define RXQ_COMMAND(p) (0x0680 + ((p) << 10)) |
| 111 | #define TXQ_CURRENT_DESC_PTR(p) (0x06c0 + ((p) << 10)) |
| 112 | #define MIB_COUNTERS(p) (0x1000 + ((p) << 7)) |
| 113 | #define SPECIAL_MCAST_TABLE(p) (0x1400 + ((p) << 10)) |
| 114 | #define OTHER_MCAST_TABLE(p) (0x1500 + ((p) << 10)) |
| 115 | #define UNICAST_TABLE(p) (0x1600 + ((p) << 10)) |
Lennert Buytenhek | fbd6a75 | 2007-10-19 16:03:46 +0200 | [diff] [blame] | 116 | |
Lennert Buytenhek | 2679a55 | 2008-06-01 01:18:58 +0200 | [diff] [blame] | 117 | |
| 118 | /* |
| 119 | * SDMA configuration register. |
| 120 | */ |
Lennert Buytenhek | fbd6a75 | 2007-10-19 16:03:46 +0200 | [diff] [blame] | 121 | #define RX_BURST_SIZE_4_64BIT (2 << 1) |
Lennert Buytenhek | fbd6a75 | 2007-10-19 16:03:46 +0200 | [diff] [blame] | 122 | #define BLM_RX_NO_SWAP (1 << 4) |
Lennert Buytenhek | fbd6a75 | 2007-10-19 16:03:46 +0200 | [diff] [blame] | 123 | #define BLM_TX_NO_SWAP (1 << 5) |
Lennert Buytenhek | fbd6a75 | 2007-10-19 16:03:46 +0200 | [diff] [blame] | 124 | #define TX_BURST_SIZE_4_64BIT (2 << 22) |
Lennert Buytenhek | fbd6a75 | 2007-10-19 16:03:46 +0200 | [diff] [blame] | 125 | |
| 126 | #if defined(__BIG_ENDIAN) |
| 127 | #define PORT_SDMA_CONFIG_DEFAULT_VALUE \ |
| 128 | RX_BURST_SIZE_4_64BIT | \ |
Lennert Buytenhek | fbd6a75 | 2007-10-19 16:03:46 +0200 | [diff] [blame] | 129 | TX_BURST_SIZE_4_64BIT |
| 130 | #elif defined(__LITTLE_ENDIAN) |
| 131 | #define PORT_SDMA_CONFIG_DEFAULT_VALUE \ |
| 132 | RX_BURST_SIZE_4_64BIT | \ |
| 133 | BLM_RX_NO_SWAP | \ |
| 134 | BLM_TX_NO_SWAP | \ |
Lennert Buytenhek | fbd6a75 | 2007-10-19 16:03:46 +0200 | [diff] [blame] | 135 | TX_BURST_SIZE_4_64BIT |
| 136 | #else |
| 137 | #error One of __BIG_ENDIAN or __LITTLE_ENDIAN must be defined |
| 138 | #endif |
| 139 | |
Lennert Buytenhek | 2beff77 | 2008-06-01 01:22:37 +0200 | [diff] [blame] | 140 | |
| 141 | /* |
| 142 | * Port serial control register. |
| 143 | */ |
| 144 | #define SET_MII_SPEED_TO_100 (1 << 24) |
| 145 | #define SET_GMII_SPEED_TO_1000 (1 << 23) |
| 146 | #define SET_FULL_DUPLEX_MODE (1 << 21) |
Lennert Buytenhek | fbd6a75 | 2007-10-19 16:03:46 +0200 | [diff] [blame] | 147 | #define MAX_RX_PACKET_1522BYTE (1 << 17) |
Lennert Buytenhek | fbd6a75 | 2007-10-19 16:03:46 +0200 | [diff] [blame] | 148 | #define MAX_RX_PACKET_9700BYTE (5 << 17) |
| 149 | #define MAX_RX_PACKET_MASK (7 << 17) |
Lennert Buytenhek | 2beff77 | 2008-06-01 01:22:37 +0200 | [diff] [blame] | 150 | #define DISABLE_AUTO_NEG_SPEED_GMII (1 << 13) |
| 151 | #define DO_NOT_FORCE_LINK_FAIL (1 << 10) |
| 152 | #define SERIAL_PORT_CONTROL_RESERVED (1 << 9) |
| 153 | #define DISABLE_AUTO_NEG_FOR_FLOW_CTRL (1 << 3) |
| 154 | #define DISABLE_AUTO_NEG_FOR_DUPLEX (1 << 2) |
| 155 | #define FORCE_LINK_PASS (1 << 1) |
| 156 | #define SERIAL_PORT_ENABLE (1 << 0) |
Lennert Buytenhek | fbd6a75 | 2007-10-19 16:03:46 +0200 | [diff] [blame] | 157 | |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 158 | #define DEFAULT_RX_QUEUE_SIZE 400 |
| 159 | #define DEFAULT_TX_QUEUE_SIZE 800 |
Lennert Buytenhek | fbd6a75 | 2007-10-19 16:03:46 +0200 | [diff] [blame] | 160 | |
Lennert Buytenhek | fbd6a75 | 2007-10-19 16:03:46 +0200 | [diff] [blame] | 161 | /* SMI reg */ |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 162 | #define SMI_BUSY 0x10000000 /* 0 - Write, 1 - Read */ |
| 163 | #define SMI_READ_VALID 0x08000000 /* 0 - Write, 1 - Read */ |
| 164 | #define SMI_OPCODE_WRITE 0 /* Completion of Read */ |
| 165 | #define SMI_OPCODE_READ 0x04000000 /* Operation is in progress */ |
Lennert Buytenhek | fbd6a75 | 2007-10-19 16:03:46 +0200 | [diff] [blame] | 166 | |
Lennert Buytenhek | fbd6a75 | 2007-10-19 16:03:46 +0200 | [diff] [blame] | 167 | |
Lennert Buytenhek | 7ca72a3 | 2008-06-01 01:41:29 +0200 | [diff] [blame] | 168 | /* |
| 169 | * RX/TX descriptors. |
Lennert Buytenhek | fbd6a75 | 2007-10-19 16:03:46 +0200 | [diff] [blame] | 170 | */ |
| 171 | #if defined(__BIG_ENDIAN) |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 172 | struct rx_desc { |
Lennert Buytenhek | fbd6a75 | 2007-10-19 16:03:46 +0200 | [diff] [blame] | 173 | u16 byte_cnt; /* Descriptor buffer byte count */ |
| 174 | u16 buf_size; /* Buffer size */ |
| 175 | u32 cmd_sts; /* Descriptor command status */ |
| 176 | u32 next_desc_ptr; /* Next descriptor pointer */ |
| 177 | u32 buf_ptr; /* Descriptor buffer pointer */ |
| 178 | }; |
| 179 | |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 180 | struct tx_desc { |
Lennert Buytenhek | fbd6a75 | 2007-10-19 16:03:46 +0200 | [diff] [blame] | 181 | u16 byte_cnt; /* buffer byte count */ |
| 182 | u16 l4i_chk; /* CPU provided TCP checksum */ |
| 183 | u32 cmd_sts; /* Command/status field */ |
| 184 | u32 next_desc_ptr; /* Pointer to next descriptor */ |
| 185 | u32 buf_ptr; /* pointer to buffer for this descriptor*/ |
| 186 | }; |
| 187 | #elif defined(__LITTLE_ENDIAN) |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 188 | struct rx_desc { |
Lennert Buytenhek | fbd6a75 | 2007-10-19 16:03:46 +0200 | [diff] [blame] | 189 | u32 cmd_sts; /* Descriptor command status */ |
| 190 | u16 buf_size; /* Buffer size */ |
| 191 | u16 byte_cnt; /* Descriptor buffer byte count */ |
| 192 | u32 buf_ptr; /* Descriptor buffer pointer */ |
| 193 | u32 next_desc_ptr; /* Next descriptor pointer */ |
| 194 | }; |
| 195 | |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 196 | struct tx_desc { |
Lennert Buytenhek | fbd6a75 | 2007-10-19 16:03:46 +0200 | [diff] [blame] | 197 | u32 cmd_sts; /* Command/status field */ |
| 198 | u16 l4i_chk; /* CPU provided TCP checksum */ |
| 199 | u16 byte_cnt; /* buffer byte count */ |
| 200 | u32 buf_ptr; /* pointer to buffer for this descriptor*/ |
| 201 | u32 next_desc_ptr; /* Pointer to next descriptor */ |
| 202 | }; |
| 203 | #else |
| 204 | #error One of __BIG_ENDIAN or __LITTLE_ENDIAN must be defined |
| 205 | #endif |
| 206 | |
Lennert Buytenhek | 7ca72a3 | 2008-06-01 01:41:29 +0200 | [diff] [blame] | 207 | /* RX & TX descriptor command */ |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 208 | #define BUFFER_OWNED_BY_DMA 0x80000000 |
Lennert Buytenhek | 7ca72a3 | 2008-06-01 01:41:29 +0200 | [diff] [blame] | 209 | |
| 210 | /* RX & TX descriptor status */ |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 211 | #define ERROR_SUMMARY 0x00000001 |
Lennert Buytenhek | 7ca72a3 | 2008-06-01 01:41:29 +0200 | [diff] [blame] | 212 | |
| 213 | /* RX descriptor status */ |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 214 | #define LAYER_4_CHECKSUM_OK 0x40000000 |
| 215 | #define RX_ENABLE_INTERRUPT 0x20000000 |
| 216 | #define RX_FIRST_DESC 0x08000000 |
| 217 | #define RX_LAST_DESC 0x04000000 |
Lennert Buytenhek | 7ca72a3 | 2008-06-01 01:41:29 +0200 | [diff] [blame] | 218 | |
| 219 | /* TX descriptor command */ |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 220 | #define TX_ENABLE_INTERRUPT 0x00800000 |
| 221 | #define GEN_CRC 0x00400000 |
| 222 | #define TX_FIRST_DESC 0x00200000 |
| 223 | #define TX_LAST_DESC 0x00100000 |
| 224 | #define ZERO_PADDING 0x00080000 |
| 225 | #define GEN_IP_V4_CHECKSUM 0x00040000 |
| 226 | #define GEN_TCP_UDP_CHECKSUM 0x00020000 |
| 227 | #define UDP_FRAME 0x00010000 |
Lennert Buytenhek | 7ca72a3 | 2008-06-01 01:41:29 +0200 | [diff] [blame] | 228 | |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 229 | #define TX_IHL_SHIFT 11 |
Lennert Buytenhek | 7ca72a3 | 2008-06-01 01:41:29 +0200 | [diff] [blame] | 230 | |
| 231 | |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 232 | /* global *******************************************************************/ |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 233 | struct mv643xx_eth_shared_private { |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 234 | void __iomem *base; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 235 | |
| 236 | /* used to protect SMI_REG, which is shared across ports */ |
| 237 | spinlock_t phy_lock; |
| 238 | |
| 239 | u32 win_protect; |
| 240 | |
| 241 | unsigned int t_clk; |
| 242 | }; |
| 243 | |
| 244 | |
| 245 | /* per-port *****************************************************************/ |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 246 | struct mib_counters { |
Lennert Buytenhek | fbd6a75 | 2007-10-19 16:03:46 +0200 | [diff] [blame] | 247 | u64 good_octets_received; |
| 248 | u32 bad_octets_received; |
| 249 | u32 internal_mac_transmit_err; |
| 250 | u32 good_frames_received; |
| 251 | u32 bad_frames_received; |
| 252 | u32 broadcast_frames_received; |
| 253 | u32 multicast_frames_received; |
| 254 | u32 frames_64_octets; |
| 255 | u32 frames_65_to_127_octets; |
| 256 | u32 frames_128_to_255_octets; |
| 257 | u32 frames_256_to_511_octets; |
| 258 | u32 frames_512_to_1023_octets; |
| 259 | u32 frames_1024_to_max_octets; |
| 260 | u64 good_octets_sent; |
| 261 | u32 good_frames_sent; |
| 262 | u32 excessive_collision; |
| 263 | u32 multicast_frames_sent; |
| 264 | u32 broadcast_frames_sent; |
| 265 | u32 unrec_mac_control_received; |
| 266 | u32 fc_sent; |
| 267 | u32 good_fc_received; |
| 268 | u32 bad_fc_received; |
| 269 | u32 undersize_received; |
| 270 | u32 fragments_received; |
| 271 | u32 oversize_received; |
| 272 | u32 jabber_received; |
| 273 | u32 mac_receive_error; |
| 274 | u32 bad_crc_event; |
| 275 | u32 collision; |
| 276 | u32 late_collision; |
| 277 | }; |
| 278 | |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 279 | struct rx_queue { |
| 280 | int rx_ring_size; |
| 281 | |
| 282 | int rx_desc_count; |
| 283 | int rx_curr_desc; |
| 284 | int rx_used_desc; |
| 285 | |
| 286 | struct rx_desc *rx_desc_area; |
| 287 | dma_addr_t rx_desc_dma; |
| 288 | int rx_desc_area_size; |
| 289 | struct sk_buff **rx_skb; |
| 290 | |
| 291 | struct timer_list rx_oom; |
| 292 | }; |
| 293 | |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 294 | struct tx_queue { |
| 295 | int tx_ring_size; |
| 296 | |
| 297 | int tx_desc_count; |
| 298 | int tx_curr_desc; |
| 299 | int tx_used_desc; |
| 300 | |
| 301 | struct tx_desc *tx_desc_area; |
| 302 | dma_addr_t tx_desc_dma; |
| 303 | int tx_desc_area_size; |
| 304 | struct sk_buff **tx_skb; |
| 305 | }; |
| 306 | |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 307 | struct mv643xx_eth_private { |
| 308 | struct mv643xx_eth_shared_private *shared; |
Lennert Buytenhek | fbd6a75 | 2007-10-19 16:03:46 +0200 | [diff] [blame] | 309 | int port_num; /* User Ethernet port number */ |
| 310 | |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 311 | struct mv643xx_eth_shared_private *shared_smi; |
Lennert Buytenhek | ce4e2e4 | 2008-04-24 01:29:59 +0200 | [diff] [blame] | 312 | |
Lennert Buytenhek | fbd6a75 | 2007-10-19 16:03:46 +0200 | [diff] [blame] | 313 | struct work_struct tx_timeout_task; |
| 314 | |
| 315 | struct net_device *dev; |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 316 | struct mib_counters mib_counters; |
Lennert Buytenhek | fbd6a75 | 2007-10-19 16:03:46 +0200 | [diff] [blame] | 317 | spinlock_t lock; |
Lennert Buytenhek | fbd6a75 | 2007-10-19 16:03:46 +0200 | [diff] [blame] | 318 | |
Lennert Buytenhek | fbd6a75 | 2007-10-19 16:03:46 +0200 | [diff] [blame] | 319 | struct mii_if_info mii; |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 320 | |
| 321 | /* |
| 322 | * RX state. |
| 323 | */ |
| 324 | int default_rx_ring_size; |
| 325 | unsigned long rx_desc_sram_addr; |
| 326 | int rx_desc_sram_size; |
| 327 | struct napi_struct napi; |
| 328 | struct rx_queue rxq[1]; |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 329 | |
| 330 | /* |
| 331 | * TX state. |
| 332 | */ |
| 333 | int default_tx_ring_size; |
| 334 | unsigned long tx_desc_sram_addr; |
| 335 | int tx_desc_sram_size; |
| 336 | struct tx_queue txq[1]; |
| 337 | #ifdef MV643XX_ETH_TX_FAST_REFILL |
| 338 | int tx_clean_threshold; |
| 339 | #endif |
Lennert Buytenhek | fbd6a75 | 2007-10-19 16:03:46 +0200 | [diff] [blame] | 340 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | |
Lennert Buytenhek | fbd6a75 | 2007-10-19 16:03:46 +0200 | [diff] [blame] | 342 | |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 343 | /* port register accessors **************************************************/ |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 344 | static inline u32 rdl(struct mv643xx_eth_private *mp, int offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | { |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 346 | return readl(mp->shared->base + offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | } |
| 348 | |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 349 | static inline void wrl(struct mv643xx_eth_private *mp, int offset, u32 data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | { |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 351 | writel(data, mp->shared->base + offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | } |
| 353 | |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 354 | |
| 355 | /* rxq/txq helper functions *************************************************/ |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 356 | static struct mv643xx_eth_private *rxq_to_mp(struct rx_queue *rxq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | { |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 358 | return container_of(rxq, struct mv643xx_eth_private, rxq[0]); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 359 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 361 | static struct mv643xx_eth_private *txq_to_mp(struct tx_queue *txq) |
| 362 | { |
| 363 | return container_of(txq, struct mv643xx_eth_private, txq[0]); |
| 364 | } |
| 365 | |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 366 | static void rxq_enable(struct rx_queue *rxq) |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 367 | { |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 368 | struct mv643xx_eth_private *mp = rxq_to_mp(rxq); |
| 369 | wrl(mp, RXQ_COMMAND(mp->port_num), 1); |
| 370 | } |
Lennert Buytenhek | c0d0f2c | 2008-03-18 11:34:34 -0700 | [diff] [blame] | 371 | |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 372 | static void rxq_disable(struct rx_queue *rxq) |
| 373 | { |
| 374 | struct mv643xx_eth_private *mp = rxq_to_mp(rxq); |
| 375 | u8 mask = 1; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 376 | |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 377 | wrl(mp, RXQ_COMMAND(mp->port_num), mask << 8); |
| 378 | while (rdl(mp, RXQ_COMMAND(mp->port_num)) & mask) |
| 379 | udelay(10); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 380 | } |
| 381 | |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 382 | static void txq_enable(struct tx_queue *txq) |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 383 | { |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 384 | struct mv643xx_eth_private *mp = txq_to_mp(txq); |
| 385 | wrl(mp, TXQ_COMMAND(mp->port_num), 1); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 386 | } |
| 387 | |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 388 | static void txq_disable(struct tx_queue *txq) |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 389 | { |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 390 | struct mv643xx_eth_private *mp = txq_to_mp(txq); |
| 391 | u8 mask = 1; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 392 | |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 393 | wrl(mp, TXQ_COMMAND(mp->port_num), mask << 8); |
| 394 | while (rdl(mp, TXQ_COMMAND(mp->port_num)) & mask) |
| 395 | udelay(10); |
| 396 | } |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 397 | |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 398 | static void __txq_maybe_wake(struct tx_queue *txq) |
| 399 | { |
| 400 | struct mv643xx_eth_private *mp = txq_to_mp(txq); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 401 | |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 402 | if (txq->tx_ring_size - txq->tx_desc_count >= MAX_DESCS_PER_SKB) |
| 403 | netif_wake_queue(mp->dev); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 404 | } |
| 405 | |
| 406 | |
| 407 | /* rx ***********************************************************************/ |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 408 | static void txq_reclaim(struct tx_queue *txq, int force); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 409 | |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 410 | static void rxq_refill(struct rx_queue *rxq) |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 411 | { |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 412 | struct mv643xx_eth_private *mp = rxq_to_mp(rxq); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 413 | unsigned long flags; |
| 414 | |
| 415 | spin_lock_irqsave(&mp->lock, flags); |
| 416 | |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 417 | while (rxq->rx_desc_count < rxq->rx_ring_size) { |
| 418 | int skb_size; |
Lennert Buytenhek | de34f22 | 2008-06-01 10:07:49 +0200 | [diff] [blame] | 419 | struct sk_buff *skb; |
| 420 | int unaligned; |
| 421 | int rx; |
| 422 | |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 423 | /* |
| 424 | * Reserve 2+14 bytes for an ethernet header (the |
| 425 | * hardware automatically prepends 2 bytes of dummy |
| 426 | * data to each received packet), 4 bytes for a VLAN |
| 427 | * header, and 4 bytes for the trailing FCS -- 24 |
| 428 | * bytes total. |
| 429 | */ |
| 430 | skb_size = mp->dev->mtu + 24; |
| 431 | |
| 432 | skb = dev_alloc_skb(skb_size + dma_get_cache_alignment() - 1); |
Lennert Buytenhek | de34f22 | 2008-06-01 10:07:49 +0200 | [diff] [blame] | 433 | if (skb == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | break; |
Lennert Buytenhek | de34f22 | 2008-06-01 10:07:49 +0200 | [diff] [blame] | 435 | |
Ralf Baechle | 908b637 | 2007-02-26 19:52:06 +0000 | [diff] [blame] | 436 | unaligned = (u32)skb->data & (dma_get_cache_alignment() - 1); |
Dale Farnsworth | b44cd57 | 2006-01-16 16:51:22 -0700 | [diff] [blame] | 437 | if (unaligned) |
Ralf Baechle | 908b637 | 2007-02-26 19:52:06 +0000 | [diff] [blame] | 438 | skb_reserve(skb, dma_get_cache_alignment() - unaligned); |
Lennert Buytenhek | de34f22 | 2008-06-01 10:07:49 +0200 | [diff] [blame] | 439 | |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 440 | rxq->rx_desc_count++; |
| 441 | rx = rxq->rx_used_desc; |
| 442 | rxq->rx_used_desc = (rx + 1) % rxq->rx_ring_size; |
Lennert Buytenhek | de34f22 | 2008-06-01 10:07:49 +0200 | [diff] [blame] | 443 | |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 444 | rxq->rx_desc_area[rx].buf_ptr = dma_map_single(NULL, skb->data, |
| 445 | skb_size, DMA_FROM_DEVICE); |
| 446 | rxq->rx_desc_area[rx].buf_size = skb_size; |
| 447 | rxq->rx_skb[rx] = skb; |
Lennert Buytenhek | de34f22 | 2008-06-01 10:07:49 +0200 | [diff] [blame] | 448 | wmb(); |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 449 | rxq->rx_desc_area[rx].cmd_sts = BUFFER_OWNED_BY_DMA | |
Lennert Buytenhek | de34f22 | 2008-06-01 10:07:49 +0200 | [diff] [blame] | 450 | RX_ENABLE_INTERRUPT; |
| 451 | wmb(); |
| 452 | |
Dale Farnsworth | 7303fde | 2006-03-03 10:03:36 -0700 | [diff] [blame] | 453 | skb_reserve(skb, ETH_HW_IP_ALIGN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | } |
Lennert Buytenhek | de34f22 | 2008-06-01 10:07:49 +0200 | [diff] [blame] | 455 | |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 456 | if (rxq->rx_desc_count == 0) { |
| 457 | rxq->rx_oom.expires = jiffies + (HZ / 10); |
| 458 | add_timer(&rxq->rx_oom); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | } |
Lennert Buytenhek | de34f22 | 2008-06-01 10:07:49 +0200 | [diff] [blame] | 460 | |
| 461 | spin_unlock_irqrestore(&mp->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | } |
| 463 | |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 464 | static inline void rxq_refill_timer_wrapper(unsigned long data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | { |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 466 | rxq_refill((struct rx_queue *)data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | } |
| 468 | |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 469 | static int rxq_process(struct rx_queue *rxq, int budget) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | { |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 471 | struct mv643xx_eth_private *mp = rxq_to_mp(rxq); |
| 472 | struct net_device_stats *stats = &mp->dev->stats; |
| 473 | int rx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 475 | rx = 0; |
| 476 | while (rx < budget) { |
Lennert Buytenhek | 9658766 | 2008-06-01 10:31:56 +0200 | [diff] [blame] | 477 | struct sk_buff *skb; |
| 478 | volatile struct rx_desc *rx_desc; |
| 479 | unsigned int cmd_sts; |
| 480 | unsigned long flags; |
| 481 | |
| 482 | spin_lock_irqsave(&mp->lock, flags); |
| 483 | |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 484 | rx_desc = &rxq->rx_desc_area[rxq->rx_curr_desc]; |
Lennert Buytenhek | 9658766 | 2008-06-01 10:31:56 +0200 | [diff] [blame] | 485 | |
| 486 | cmd_sts = rx_desc->cmd_sts; |
| 487 | if (cmd_sts & BUFFER_OWNED_BY_DMA) { |
| 488 | spin_unlock_irqrestore(&mp->lock, flags); |
| 489 | break; |
| 490 | } |
| 491 | rmb(); |
| 492 | |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 493 | skb = rxq->rx_skb[rxq->rx_curr_desc]; |
| 494 | rxq->rx_skb[rxq->rx_curr_desc] = NULL; |
Lennert Buytenhek | 9658766 | 2008-06-01 10:31:56 +0200 | [diff] [blame] | 495 | |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 496 | rxq->rx_curr_desc = (rxq->rx_curr_desc + 1) % rxq->rx_ring_size; |
Lennert Buytenhek | 9658766 | 2008-06-01 10:31:56 +0200 | [diff] [blame] | 497 | |
| 498 | spin_unlock_irqrestore(&mp->lock, flags); |
| 499 | |
| 500 | dma_unmap_single(NULL, rx_desc->buf_ptr + ETH_HW_IP_ALIGN, |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 501 | mp->dev->mtu + 24, DMA_FROM_DEVICE); |
| 502 | rxq->rx_desc_count--; |
| 503 | rx++; |
Dale Farnsworth | b1dd9ca | 2005-09-01 09:59:23 -0700 | [diff] [blame] | 504 | |
Dale Farnsworth | 468d09f | 2006-03-03 10:04:39 -0700 | [diff] [blame] | 505 | /* |
| 506 | * Update statistics. |
| 507 | * Note byte count includes 4 byte CRC count |
| 508 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | stats->rx_packets++; |
Lennert Buytenhek | 9658766 | 2008-06-01 10:31:56 +0200 | [diff] [blame] | 510 | stats->rx_bytes += rx_desc->byte_cnt - ETH_HW_IP_ALIGN; |
| 511 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | /* |
| 513 | * In case received a packet without first / last bits on OR |
| 514 | * the error summary bit is on, the packets needs to be dropeed. |
| 515 | */ |
Lennert Buytenhek | 9658766 | 2008-06-01 10:31:56 +0200 | [diff] [blame] | 516 | if (((cmd_sts & (RX_FIRST_DESC | RX_LAST_DESC)) != |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 517 | (RX_FIRST_DESC | RX_LAST_DESC)) |
Lennert Buytenhek | 9658766 | 2008-06-01 10:31:56 +0200 | [diff] [blame] | 518 | || (cmd_sts & ERROR_SUMMARY)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | stats->rx_dropped++; |
Lennert Buytenhek | 9658766 | 2008-06-01 10:31:56 +0200 | [diff] [blame] | 520 | if ((cmd_sts & (RX_FIRST_DESC | RX_LAST_DESC)) != |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 521 | (RX_FIRST_DESC | RX_LAST_DESC)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | if (net_ratelimit()) |
| 523 | printk(KERN_ERR |
| 524 | "%s: Received packet spread " |
| 525 | "on multiple descriptors\n", |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 526 | mp->dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | } |
Lennert Buytenhek | 9658766 | 2008-06-01 10:31:56 +0200 | [diff] [blame] | 528 | if (cmd_sts & ERROR_SUMMARY) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | stats->rx_errors++; |
| 530 | |
| 531 | dev_kfree_skb_irq(skb); |
| 532 | } else { |
| 533 | /* |
| 534 | * The -4 is for the CRC in the trailer of the |
| 535 | * received packet |
| 536 | */ |
Lennert Buytenhek | 9658766 | 2008-06-01 10:31:56 +0200 | [diff] [blame] | 537 | skb_put(skb, rx_desc->byte_cnt - ETH_HW_IP_ALIGN - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | |
Lennert Buytenhek | 9658766 | 2008-06-01 10:31:56 +0200 | [diff] [blame] | 539 | if (cmd_sts & LAYER_4_CHECKSUM_OK) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 541 | skb->csum = htons( |
Lennert Buytenhek | 9658766 | 2008-06-01 10:31:56 +0200 | [diff] [blame] | 542 | (cmd_sts & 0x0007fff8) >> 3); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | } |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 544 | skb->protocol = eth_type_trans(skb, mp->dev); |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 545 | #ifdef MV643XX_ETH_NAPI |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | netif_receive_skb(skb); |
| 547 | #else |
| 548 | netif_rx(skb); |
| 549 | #endif |
| 550 | } |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 551 | mp->dev->last_rx = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | } |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 553 | rxq_refill(rxq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 555 | return rx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | } |
| 557 | |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 558 | #ifdef MV643XX_ETH_NAPI |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 559 | static int mv643xx_eth_poll(struct napi_struct *napi, int budget) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | { |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 561 | struct mv643xx_eth_private *mp; |
| 562 | int rx; |
| 563 | |
| 564 | mp = container_of(napi, struct mv643xx_eth_private, napi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 566 | #ifdef MV643XX_ETH_TX_FAST_REFILL |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | if (++mp->tx_clean_threshold > 5) { |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 568 | txq_reclaim(mp->txq, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | mp->tx_clean_threshold = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | } |
| 571 | #endif |
| 572 | |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 573 | rx = rxq_process(mp->rxq, budget); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 575 | if (rx < budget) { |
| 576 | netif_rx_complete(mp->dev, napi); |
| 577 | wrl(mp, INT_CAUSE(mp->port_num), 0); |
| 578 | wrl(mp, INT_CAUSE_EXT(mp->port_num), 0); |
| 579 | wrl(mp, INT_MASK(mp->port_num), INT_RX | INT_EXT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | } |
| 581 | |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 582 | return rx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | } |
| 584 | #endif |
| 585 | |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 586 | |
| 587 | /* tx ***********************************************************************/ |
Paul Janzen | f7ea333 | 2006-01-16 16:52:13 -0700 | [diff] [blame] | 588 | static inline unsigned int has_tiny_unaligned_frags(struct sk_buff *skb) |
| 589 | { |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 590 | int frag; |
Paul Janzen | f7ea333 | 2006-01-16 16:52:13 -0700 | [diff] [blame] | 591 | |
Dale Farnsworth | b4de905 | 2006-01-27 01:04:43 -0700 | [diff] [blame] | 592 | for (frag = 0; frag < skb_shinfo(skb)->nr_frags; frag++) { |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 593 | skb_frag_t *fragp = &skb_shinfo(skb)->frags[frag]; |
| 594 | if (fragp->size <= 8 && fragp->page_offset & 7) |
Dale Farnsworth | b4de905 | 2006-01-27 01:04:43 -0700 | [diff] [blame] | 595 | return 1; |
| 596 | } |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 597 | |
Dale Farnsworth | b4de905 | 2006-01-27 01:04:43 -0700 | [diff] [blame] | 598 | return 0; |
Paul Janzen | f7ea333 | 2006-01-16 16:52:13 -0700 | [diff] [blame] | 599 | } |
| 600 | |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 601 | static int txq_alloc_desc_index(struct tx_queue *txq) |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 602 | { |
| 603 | int tx_desc_curr; |
Paul Janzen | f7ea333 | 2006-01-16 16:52:13 -0700 | [diff] [blame] | 604 | |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 605 | BUG_ON(txq->tx_desc_count >= txq->tx_ring_size); |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 606 | |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 607 | tx_desc_curr = txq->tx_curr_desc; |
| 608 | txq->tx_curr_desc = (tx_desc_curr + 1) % txq->tx_ring_size; |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 609 | |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 610 | BUG_ON(txq->tx_curr_desc == txq->tx_used_desc); |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 611 | |
| 612 | return tx_desc_curr; |
| 613 | } |
| 614 | |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 615 | static void txq_submit_frag_skb(struct tx_queue *txq, struct sk_buff *skb) |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 616 | { |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 617 | int nr_frags = skb_shinfo(skb)->nr_frags; |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 618 | int frag; |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 619 | |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 620 | for (frag = 0; frag < nr_frags; frag++) { |
| 621 | skb_frag_t *this_frag; |
| 622 | int tx_index; |
| 623 | struct tx_desc *desc; |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 624 | |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 625 | this_frag = &skb_shinfo(skb)->frags[frag]; |
| 626 | tx_index = txq_alloc_desc_index(txq); |
| 627 | desc = &txq->tx_desc_area[tx_index]; |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 628 | |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 629 | /* |
| 630 | * The last fragment will generate an interrupt |
| 631 | * which will free the skb on TX completion. |
| 632 | */ |
| 633 | if (frag == nr_frags - 1) { |
| 634 | desc->cmd_sts = BUFFER_OWNED_BY_DMA | |
| 635 | ZERO_PADDING | TX_LAST_DESC | |
| 636 | TX_ENABLE_INTERRUPT; |
| 637 | txq->tx_skb[tx_index] = skb; |
| 638 | } else { |
| 639 | desc->cmd_sts = BUFFER_OWNED_BY_DMA; |
| 640 | txq->tx_skb[tx_index] = NULL; |
| 641 | } |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 642 | |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 643 | desc->l4i_chk = 0; |
| 644 | desc->byte_cnt = this_frag->size; |
| 645 | desc->buf_ptr = dma_map_page(NULL, this_frag->page, |
| 646 | this_frag->page_offset, |
| 647 | this_frag->size, |
| 648 | DMA_TO_DEVICE); |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 649 | } |
| 650 | } |
| 651 | |
Byron Bradley | 324ff2c | 2008-02-04 23:47:15 -0800 | [diff] [blame] | 652 | static inline __be16 sum16_as_be(__sum16 sum) |
| 653 | { |
| 654 | return (__force __be16)sum; |
| 655 | } |
| 656 | |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 657 | static void txq_submit_skb(struct tx_queue *txq, struct sk_buff *skb) |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 658 | { |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 659 | int nr_frags = skb_shinfo(skb)->nr_frags; |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 660 | int tx_index; |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 661 | struct tx_desc *desc; |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 662 | u32 cmd_sts; |
| 663 | int length; |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 664 | |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 665 | cmd_sts = TX_FIRST_DESC | GEN_CRC | BUFFER_OWNED_BY_DMA; |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 666 | |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 667 | tx_index = txq_alloc_desc_index(txq); |
| 668 | desc = &txq->tx_desc_area[tx_index]; |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 669 | |
Dale Farnsworth | ff561ee | 2006-03-03 10:02:51 -0700 | [diff] [blame] | 670 | if (nr_frags) { |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 671 | txq_submit_frag_skb(txq, skb); |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 672 | |
| 673 | length = skb_headlen(skb); |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 674 | txq->tx_skb[tx_index] = NULL; |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 675 | } else { |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 676 | cmd_sts |= ZERO_PADDING | TX_LAST_DESC | TX_ENABLE_INTERRUPT; |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 677 | length = skb->len; |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 678 | txq->tx_skb[tx_index] = skb; |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 679 | } |
| 680 | |
| 681 | desc->byte_cnt = length; |
| 682 | desc->buf_ptr = dma_map_single(NULL, skb->data, length, DMA_TO_DEVICE); |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 683 | |
Patrick McHardy | 84fa793 | 2006-08-29 16:44:56 -0700 | [diff] [blame] | 684 | if (skb->ip_summed == CHECKSUM_PARTIAL) { |
Byron Bradley | 324ff2c | 2008-02-04 23:47:15 -0800 | [diff] [blame] | 685 | BUG_ON(skb->protocol != htons(ETH_P_IP)); |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 686 | |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 687 | cmd_sts |= GEN_TCP_UDP_CHECKSUM | |
| 688 | GEN_IP_V4_CHECKSUM | |
| 689 | ip_hdr(skb)->ihl << TX_IHL_SHIFT; |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 690 | |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 691 | switch (ip_hdr(skb)->protocol) { |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 692 | case IPPROTO_UDP: |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 693 | cmd_sts |= UDP_FRAME; |
Byron Bradley | 324ff2c | 2008-02-04 23:47:15 -0800 | [diff] [blame] | 694 | desc->l4i_chk = ntohs(sum16_as_be(udp_hdr(skb)->check)); |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 695 | break; |
| 696 | case IPPROTO_TCP: |
Byron Bradley | 324ff2c | 2008-02-04 23:47:15 -0800 | [diff] [blame] | 697 | desc->l4i_chk = ntohs(sum16_as_be(tcp_hdr(skb)->check)); |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 698 | break; |
| 699 | default: |
| 700 | BUG(); |
| 701 | } |
| 702 | } else { |
| 703 | /* Errata BTS #50, IHL must be 5 if no HW checksum */ |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 704 | cmd_sts |= 5 << TX_IHL_SHIFT; |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 705 | desc->l4i_chk = 0; |
| 706 | } |
| 707 | |
| 708 | /* ensure all other descriptors are written before first cmd_sts */ |
| 709 | wmb(); |
| 710 | desc->cmd_sts = cmd_sts; |
| 711 | |
| 712 | /* ensure all descriptors are written before poking hardware */ |
| 713 | wmb(); |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 714 | txq_enable(txq); |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 715 | |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 716 | txq->tx_desc_count += nr_frags + 1; |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 717 | } |
| 718 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | static int mv643xx_eth_start_xmit(struct sk_buff *skb, struct net_device *dev) |
| 720 | { |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 721 | struct mv643xx_eth_private *mp = netdev_priv(dev); |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 722 | struct net_device_stats *stats = &dev->stats; |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 723 | struct tx_queue *txq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 724 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 725 | |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 726 | BUG_ON(netif_queue_stopped(dev)); |
Dale Farnsworth | 9484356 | 2006-04-11 18:24:26 -0700 | [diff] [blame] | 727 | |
Lennert Buytenhek | 4d64e71 | 2008-03-18 11:32:41 -0700 | [diff] [blame] | 728 | if (has_tiny_unaligned_frags(skb) && __skb_linearize(skb)) { |
| 729 | stats->tx_dropped++; |
| 730 | printk(KERN_DEBUG "%s: failed to linearize tiny " |
| 731 | "unaligned fragment\n", dev->name); |
Lennert Buytenhek | c0d0f2c | 2008-03-18 11:34:34 -0700 | [diff] [blame] | 732 | return NETDEV_TX_BUSY; |
Dale Farnsworth | 9484356 | 2006-04-11 18:24:26 -0700 | [diff] [blame] | 733 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 734 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | spin_lock_irqsave(&mp->lock, flags); |
| 736 | |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 737 | txq = mp->txq; |
| 738 | |
| 739 | if (txq->tx_ring_size - txq->tx_desc_count < MAX_DESCS_PER_SKB) { |
Lennert Buytenhek | 4d64e71 | 2008-03-18 11:32:41 -0700 | [diff] [blame] | 740 | printk(KERN_ERR "%s: transmit with queue full\n", dev->name); |
| 741 | netif_stop_queue(dev); |
| 742 | spin_unlock_irqrestore(&mp->lock, flags); |
Lennert Buytenhek | c0d0f2c | 2008-03-18 11:34:34 -0700 | [diff] [blame] | 743 | return NETDEV_TX_BUSY; |
Lennert Buytenhek | 4d64e71 | 2008-03-18 11:32:41 -0700 | [diff] [blame] | 744 | } |
| 745 | |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 746 | txq_submit_skb(txq, skb); |
Dale Farnsworth | e7e381f | 2007-09-14 11:23:16 -0700 | [diff] [blame] | 747 | stats->tx_bytes += skb->len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 748 | stats->tx_packets++; |
| 749 | dev->trans_start = jiffies; |
| 750 | |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 751 | if (txq->tx_ring_size - txq->tx_desc_count < MAX_DESCS_PER_SKB) |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 752 | netif_stop_queue(dev); |
| 753 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | spin_unlock_irqrestore(&mp->lock, flags); |
| 755 | |
Lennert Buytenhek | c0d0f2c | 2008-03-18 11:34:34 -0700 | [diff] [blame] | 756 | return NETDEV_TX_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 757 | } |
| 758 | |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 759 | |
| 760 | /* mii management interface *************************************************/ |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 761 | static int phy_addr_get(struct mv643xx_eth_private *mp); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 762 | |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 763 | static void read_smi_reg(struct mv643xx_eth_private *mp, |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 764 | unsigned int phy_reg, unsigned int *value) |
| 765 | { |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 766 | void __iomem *smi_reg = mp->shared_smi->base + SMI_REG; |
| 767 | int phy_addr = phy_addr_get(mp); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 768 | unsigned long flags; |
| 769 | int i; |
| 770 | |
| 771 | /* the SMI register is a shared resource */ |
| 772 | spin_lock_irqsave(&mp->shared_smi->phy_lock, flags); |
| 773 | |
| 774 | /* wait for the SMI register to become available */ |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 775 | for (i = 0; readl(smi_reg) & SMI_BUSY; i++) { |
Lennert Buytenhek | e1bea50 | 2008-06-01 01:29:14 +0200 | [diff] [blame] | 776 | if (i == 1000) { |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 777 | printk("%s: PHY busy timeout\n", mp->dev->name); |
| 778 | goto out; |
| 779 | } |
Lennert Buytenhek | e1bea50 | 2008-06-01 01:29:14 +0200 | [diff] [blame] | 780 | udelay(10); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 781 | } |
| 782 | |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 783 | writel((phy_addr << 16) | (phy_reg << 21) | SMI_OPCODE_READ, smi_reg); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 784 | |
| 785 | /* now wait for the data to be valid */ |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 786 | for (i = 0; !(readl(smi_reg) & SMI_READ_VALID); i++) { |
Lennert Buytenhek | e1bea50 | 2008-06-01 01:29:14 +0200 | [diff] [blame] | 787 | if (i == 1000) { |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 788 | printk("%s: PHY read timeout\n", mp->dev->name); |
| 789 | goto out; |
| 790 | } |
Lennert Buytenhek | e1bea50 | 2008-06-01 01:29:14 +0200 | [diff] [blame] | 791 | udelay(10); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 792 | } |
| 793 | |
| 794 | *value = readl(smi_reg) & 0xffff; |
| 795 | out: |
| 796 | spin_unlock_irqrestore(&mp->shared_smi->phy_lock, flags); |
| 797 | } |
| 798 | |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 799 | static void write_smi_reg(struct mv643xx_eth_private *mp, |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 800 | unsigned int phy_reg, unsigned int value) |
| 801 | { |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 802 | void __iomem *smi_reg = mp->shared_smi->base + SMI_REG; |
| 803 | int phy_addr = phy_addr_get(mp); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 804 | unsigned long flags; |
| 805 | int i; |
| 806 | |
| 807 | /* the SMI register is a shared resource */ |
| 808 | spin_lock_irqsave(&mp->shared_smi->phy_lock, flags); |
| 809 | |
| 810 | /* wait for the SMI register to become available */ |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 811 | for (i = 0; readl(smi_reg) & SMI_BUSY; i++) { |
Lennert Buytenhek | e1bea50 | 2008-06-01 01:29:14 +0200 | [diff] [blame] | 812 | if (i == 1000) { |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 813 | printk("%s: PHY busy timeout\n", mp->dev->name); |
| 814 | goto out; |
| 815 | } |
Lennert Buytenhek | e1bea50 | 2008-06-01 01:29:14 +0200 | [diff] [blame] | 816 | udelay(10); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 817 | } |
| 818 | |
| 819 | writel((phy_addr << 16) | (phy_reg << 21) | |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 820 | SMI_OPCODE_WRITE | (value & 0xffff), smi_reg); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 821 | out: |
| 822 | spin_unlock_irqrestore(&mp->shared_smi->phy_lock, flags); |
| 823 | } |
| 824 | |
| 825 | |
| 826 | /* mib counters *************************************************************/ |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 827 | static void clear_mib_counters(struct mv643xx_eth_private *mp) |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 828 | { |
| 829 | unsigned int port_num = mp->port_num; |
| 830 | int i; |
| 831 | |
| 832 | /* Perform dummy reads from MIB counters */ |
Lennert Buytenhek | 4b8e365 | 2008-06-01 01:29:58 +0200 | [diff] [blame] | 833 | for (i = 0; i < 0x80; i += 4) |
Lennert Buytenhek | 3cb4667c | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 834 | rdl(mp, MIB_COUNTERS(port_num) + i); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 835 | } |
| 836 | |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 837 | static inline u32 read_mib(struct mv643xx_eth_private *mp, int offset) |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 838 | { |
Lennert Buytenhek | 3cb4667c | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 839 | return rdl(mp, MIB_COUNTERS(mp->port_num) + offset); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 840 | } |
| 841 | |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 842 | static void update_mib_counters(struct mv643xx_eth_private *mp) |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 843 | { |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 844 | struct mib_counters *p = &mp->mib_counters; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 845 | |
Lennert Buytenhek | 4b8e365 | 2008-06-01 01:29:58 +0200 | [diff] [blame] | 846 | p->good_octets_received += read_mib(mp, 0x00); |
| 847 | p->good_octets_received += (u64)read_mib(mp, 0x04) << 32; |
| 848 | p->bad_octets_received += read_mib(mp, 0x08); |
| 849 | p->internal_mac_transmit_err += read_mib(mp, 0x0c); |
| 850 | p->good_frames_received += read_mib(mp, 0x10); |
| 851 | p->bad_frames_received += read_mib(mp, 0x14); |
| 852 | p->broadcast_frames_received += read_mib(mp, 0x18); |
| 853 | p->multicast_frames_received += read_mib(mp, 0x1c); |
| 854 | p->frames_64_octets += read_mib(mp, 0x20); |
| 855 | p->frames_65_to_127_octets += read_mib(mp, 0x24); |
| 856 | p->frames_128_to_255_octets += read_mib(mp, 0x28); |
| 857 | p->frames_256_to_511_octets += read_mib(mp, 0x2c); |
| 858 | p->frames_512_to_1023_octets += read_mib(mp, 0x30); |
| 859 | p->frames_1024_to_max_octets += read_mib(mp, 0x34); |
| 860 | p->good_octets_sent += read_mib(mp, 0x38); |
| 861 | p->good_octets_sent += (u64)read_mib(mp, 0x3c) << 32; |
| 862 | p->good_frames_sent += read_mib(mp, 0x40); |
| 863 | p->excessive_collision += read_mib(mp, 0x44); |
| 864 | p->multicast_frames_sent += read_mib(mp, 0x48); |
| 865 | p->broadcast_frames_sent += read_mib(mp, 0x4c); |
| 866 | p->unrec_mac_control_received += read_mib(mp, 0x50); |
| 867 | p->fc_sent += read_mib(mp, 0x54); |
| 868 | p->good_fc_received += read_mib(mp, 0x58); |
| 869 | p->bad_fc_received += read_mib(mp, 0x5c); |
| 870 | p->undersize_received += read_mib(mp, 0x60); |
| 871 | p->fragments_received += read_mib(mp, 0x64); |
| 872 | p->oversize_received += read_mib(mp, 0x68); |
| 873 | p->jabber_received += read_mib(mp, 0x6c); |
| 874 | p->mac_receive_error += read_mib(mp, 0x70); |
| 875 | p->bad_crc_event += read_mib(mp, 0x74); |
| 876 | p->collision += read_mib(mp, 0x78); |
| 877 | p->late_collision += read_mib(mp, 0x7c); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 878 | } |
| 879 | |
| 880 | |
| 881 | /* ethtool ******************************************************************/ |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 882 | struct mv643xx_eth_stats { |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 883 | char stat_string[ETH_GSTRING_LEN]; |
| 884 | int sizeof_stat; |
Lennert Buytenhek | 1682005 | 2008-06-01 11:40:29 +0200 | [diff] [blame] | 885 | int netdev_off; |
| 886 | int mp_off; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 887 | }; |
| 888 | |
Lennert Buytenhek | 1682005 | 2008-06-01 11:40:29 +0200 | [diff] [blame] | 889 | #define SSTAT(m) \ |
| 890 | { #m, FIELD_SIZEOF(struct net_device_stats, m), \ |
| 891 | offsetof(struct net_device, stats.m), -1 } |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 892 | |
Lennert Buytenhek | 1682005 | 2008-06-01 11:40:29 +0200 | [diff] [blame] | 893 | #define MIBSTAT(m) \ |
| 894 | { #m, FIELD_SIZEOF(struct mib_counters, m), \ |
| 895 | -1, offsetof(struct mv643xx_eth_private, mib_counters.m) } |
| 896 | |
| 897 | static const struct mv643xx_eth_stats mv643xx_eth_stats[] = { |
| 898 | SSTAT(rx_packets), |
| 899 | SSTAT(tx_packets), |
| 900 | SSTAT(rx_bytes), |
| 901 | SSTAT(tx_bytes), |
| 902 | SSTAT(rx_errors), |
| 903 | SSTAT(tx_errors), |
| 904 | SSTAT(rx_dropped), |
| 905 | SSTAT(tx_dropped), |
| 906 | MIBSTAT(good_octets_received), |
| 907 | MIBSTAT(bad_octets_received), |
| 908 | MIBSTAT(internal_mac_transmit_err), |
| 909 | MIBSTAT(good_frames_received), |
| 910 | MIBSTAT(bad_frames_received), |
| 911 | MIBSTAT(broadcast_frames_received), |
| 912 | MIBSTAT(multicast_frames_received), |
| 913 | MIBSTAT(frames_64_octets), |
| 914 | MIBSTAT(frames_65_to_127_octets), |
| 915 | MIBSTAT(frames_128_to_255_octets), |
| 916 | MIBSTAT(frames_256_to_511_octets), |
| 917 | MIBSTAT(frames_512_to_1023_octets), |
| 918 | MIBSTAT(frames_1024_to_max_octets), |
| 919 | MIBSTAT(good_octets_sent), |
| 920 | MIBSTAT(good_frames_sent), |
| 921 | MIBSTAT(excessive_collision), |
| 922 | MIBSTAT(multicast_frames_sent), |
| 923 | MIBSTAT(broadcast_frames_sent), |
| 924 | MIBSTAT(unrec_mac_control_received), |
| 925 | MIBSTAT(fc_sent), |
| 926 | MIBSTAT(good_fc_received), |
| 927 | MIBSTAT(bad_fc_received), |
| 928 | MIBSTAT(undersize_received), |
| 929 | MIBSTAT(fragments_received), |
| 930 | MIBSTAT(oversize_received), |
| 931 | MIBSTAT(jabber_received), |
| 932 | MIBSTAT(mac_receive_error), |
| 933 | MIBSTAT(bad_crc_event), |
| 934 | MIBSTAT(collision), |
| 935 | MIBSTAT(late_collision), |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 936 | }; |
| 937 | |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 938 | static int mv643xx_eth_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 939 | { |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 940 | struct mv643xx_eth_private *mp = netdev_priv(dev); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 941 | int err; |
| 942 | |
| 943 | spin_lock_irq(&mp->lock); |
| 944 | err = mii_ethtool_gset(&mp->mii, cmd); |
| 945 | spin_unlock_irq(&mp->lock); |
| 946 | |
| 947 | /* The PHY may support 1000baseT_Half, but the mv643xx does not */ |
| 948 | cmd->supported &= ~SUPPORTED_1000baseT_Half; |
| 949 | cmd->advertising &= ~ADVERTISED_1000baseT_Half; |
| 950 | |
| 951 | return err; |
| 952 | } |
| 953 | |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 954 | static int mv643xx_eth_set_settings(struct net_device *dev, struct ethtool_cmd *cmd) |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 955 | { |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 956 | struct mv643xx_eth_private *mp = netdev_priv(dev); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 957 | int err; |
| 958 | |
| 959 | spin_lock_irq(&mp->lock); |
| 960 | err = mii_ethtool_sset(&mp->mii, cmd); |
| 961 | spin_unlock_irq(&mp->lock); |
| 962 | |
| 963 | return err; |
| 964 | } |
| 965 | |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 966 | static void mv643xx_eth_get_drvinfo(struct net_device *netdev, |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 967 | struct ethtool_drvinfo *drvinfo) |
| 968 | { |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 969 | strncpy(drvinfo->driver, mv643xx_eth_driver_name, 32); |
| 970 | strncpy(drvinfo->version, mv643xx_eth_driver_version, 32); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 971 | strncpy(drvinfo->fw_version, "N/A", 32); |
| 972 | strncpy(drvinfo->bus_info, "mv643xx", 32); |
Lennert Buytenhek | 1682005 | 2008-06-01 11:40:29 +0200 | [diff] [blame] | 973 | drvinfo->n_stats = ARRAY_SIZE(mv643xx_eth_stats); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 974 | } |
| 975 | |
| 976 | static int mv643xx_eth_nway_restart(struct net_device *dev) |
| 977 | { |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 978 | struct mv643xx_eth_private *mp = netdev_priv(dev); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 979 | |
| 980 | return mii_nway_restart(&mp->mii); |
| 981 | } |
| 982 | |
| 983 | static u32 mv643xx_eth_get_link(struct net_device *dev) |
| 984 | { |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 985 | struct mv643xx_eth_private *mp = netdev_priv(dev); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 986 | |
| 987 | return mii_link_ok(&mp->mii); |
| 988 | } |
| 989 | |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 990 | static void mv643xx_eth_get_strings(struct net_device *netdev, uint32_t stringset, |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 991 | uint8_t *data) |
| 992 | { |
| 993 | int i; |
| 994 | |
| 995 | switch(stringset) { |
| 996 | case ETH_SS_STATS: |
Lennert Buytenhek | 1682005 | 2008-06-01 11:40:29 +0200 | [diff] [blame] | 997 | for (i=0; i < ARRAY_SIZE(mv643xx_eth_stats); i++) { |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 998 | memcpy(data + i * ETH_GSTRING_LEN, |
Lennert Buytenhek | 1682005 | 2008-06-01 11:40:29 +0200 | [diff] [blame] | 999 | mv643xx_eth_stats[i].stat_string, |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 1000 | ETH_GSTRING_LEN); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1001 | } |
| 1002 | break; |
| 1003 | } |
| 1004 | } |
| 1005 | |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 1006 | static void mv643xx_eth_get_ethtool_stats(struct net_device *netdev, |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1007 | struct ethtool_stats *stats, uint64_t *data) |
| 1008 | { |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 1009 | struct mv643xx_eth_private *mp = netdev->priv; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1010 | int i; |
| 1011 | |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 1012 | update_mib_counters(mp); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1013 | |
Lennert Buytenhek | 1682005 | 2008-06-01 11:40:29 +0200 | [diff] [blame] | 1014 | for (i = 0; i < ARRAY_SIZE(mv643xx_eth_stats); i++) { |
| 1015 | const struct mv643xx_eth_stats *stat; |
| 1016 | void *p; |
| 1017 | |
| 1018 | stat = mv643xx_eth_stats + i; |
| 1019 | |
| 1020 | if (stat->netdev_off >= 0) |
| 1021 | p = ((void *)mp->dev) + stat->netdev_off; |
| 1022 | else |
| 1023 | p = ((void *)mp) + stat->mp_off; |
| 1024 | |
| 1025 | data[i] = (stat->sizeof_stat == 8) ? |
| 1026 | *(uint64_t *)p : *(uint32_t *)p; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1027 | } |
| 1028 | } |
| 1029 | |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 1030 | static int mv643xx_eth_get_sset_count(struct net_device *netdev, int sset) |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1031 | { |
| 1032 | switch (sset) { |
| 1033 | case ETH_SS_STATS: |
Lennert Buytenhek | 1682005 | 2008-06-01 11:40:29 +0200 | [diff] [blame] | 1034 | return ARRAY_SIZE(mv643xx_eth_stats); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1035 | default: |
| 1036 | return -EOPNOTSUPP; |
| 1037 | } |
| 1038 | } |
| 1039 | |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 1040 | static const struct ethtool_ops mv643xx_eth_ethtool_ops = { |
| 1041 | .get_settings = mv643xx_eth_get_settings, |
| 1042 | .set_settings = mv643xx_eth_set_settings, |
| 1043 | .get_drvinfo = mv643xx_eth_get_drvinfo, |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1044 | .get_link = mv643xx_eth_get_link, |
| 1045 | .set_sg = ethtool_op_set_sg, |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 1046 | .get_sset_count = mv643xx_eth_get_sset_count, |
| 1047 | .get_ethtool_stats = mv643xx_eth_get_ethtool_stats, |
| 1048 | .get_strings = mv643xx_eth_get_strings, |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1049 | .nway_reset = mv643xx_eth_nway_restart, |
| 1050 | }; |
| 1051 | |
| 1052 | |
| 1053 | /* address handling *********************************************************/ |
Lennert Buytenhek | 5daffe9 | 2008-06-01 02:52:41 +0200 | [diff] [blame] | 1054 | static void uc_addr_get(struct mv643xx_eth_private *mp, unsigned char *addr) |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1055 | { |
| 1056 | unsigned int port_num = mp->port_num; |
| 1057 | unsigned int mac_h; |
| 1058 | unsigned int mac_l; |
| 1059 | |
| 1060 | mac_h = rdl(mp, MAC_ADDR_HIGH(port_num)); |
| 1061 | mac_l = rdl(mp, MAC_ADDR_LOW(port_num)); |
| 1062 | |
Lennert Buytenhek | 5daffe9 | 2008-06-01 02:52:41 +0200 | [diff] [blame] | 1063 | addr[0] = (mac_h >> 24) & 0xff; |
| 1064 | addr[1] = (mac_h >> 16) & 0xff; |
| 1065 | addr[2] = (mac_h >> 8) & 0xff; |
| 1066 | addr[3] = mac_h & 0xff; |
| 1067 | addr[4] = (mac_l >> 8) & 0xff; |
| 1068 | addr[5] = mac_l & 0xff; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1069 | } |
| 1070 | |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 1071 | static void init_mac_tables(struct mv643xx_eth_private *mp) |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1072 | { |
| 1073 | unsigned int port_num = mp->port_num; |
| 1074 | int table_index; |
| 1075 | |
| 1076 | /* Clear DA filter unicast table (Ex_dFUT) */ |
| 1077 | for (table_index = 0; table_index <= 0xC; table_index += 4) |
Lennert Buytenhek | 3cb4667c | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 1078 | wrl(mp, UNICAST_TABLE(port_num) + table_index, 0); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1079 | |
| 1080 | for (table_index = 0; table_index <= 0xFC; table_index += 4) { |
| 1081 | /* Clear DA filter special multicast table (Ex_dFSMT) */ |
Lennert Buytenhek | 3cb4667c | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 1082 | wrl(mp, SPECIAL_MCAST_TABLE(port_num) + table_index, 0); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1083 | /* Clear DA filter other multicast table (Ex_dFOMT) */ |
Lennert Buytenhek | 3cb4667c | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 1084 | wrl(mp, OTHER_MCAST_TABLE(port_num) + table_index, 0); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1085 | } |
| 1086 | } |
| 1087 | |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 1088 | static void set_filter_table_entry(struct mv643xx_eth_private *mp, |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1089 | int table, unsigned char entry) |
| 1090 | { |
| 1091 | unsigned int table_reg; |
| 1092 | unsigned int tbl_offset; |
| 1093 | unsigned int reg_offset; |
| 1094 | |
| 1095 | tbl_offset = (entry / 4) * 4; /* Register offset of DA table entry */ |
| 1096 | reg_offset = entry % 4; /* Entry offset within the register */ |
| 1097 | |
| 1098 | /* Set "accepts frame bit" at specified table entry */ |
| 1099 | table_reg = rdl(mp, table + tbl_offset); |
| 1100 | table_reg |= 0x01 << (8 * reg_offset); |
| 1101 | wrl(mp, table + tbl_offset, table_reg); |
| 1102 | } |
| 1103 | |
Lennert Buytenhek | 5daffe9 | 2008-06-01 02:52:41 +0200 | [diff] [blame] | 1104 | static void uc_addr_set(struct mv643xx_eth_private *mp, unsigned char *addr) |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1105 | { |
| 1106 | unsigned int port_num = mp->port_num; |
| 1107 | unsigned int mac_h; |
| 1108 | unsigned int mac_l; |
| 1109 | int table; |
| 1110 | |
Lennert Buytenhek | 5daffe9 | 2008-06-01 02:52:41 +0200 | [diff] [blame] | 1111 | mac_l = (addr[4] << 8) | (addr[5]); |
| 1112 | mac_h = (addr[0] << 24) | (addr[1] << 16) | (addr[2] << 8) | |
| 1113 | (addr[3] << 0); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1114 | |
| 1115 | wrl(mp, MAC_ADDR_LOW(port_num), mac_l); |
| 1116 | wrl(mp, MAC_ADDR_HIGH(port_num), mac_h); |
| 1117 | |
| 1118 | /* Accept frames with this address */ |
Lennert Buytenhek | 3cb4667c | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 1119 | table = UNICAST_TABLE(port_num); |
Lennert Buytenhek | 5daffe9 | 2008-06-01 02:52:41 +0200 | [diff] [blame] | 1120 | set_filter_table_entry(mp, table, addr[5] & 0x0f); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1121 | } |
| 1122 | |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1123 | static void mv643xx_eth_update_mac_address(struct net_device *dev) |
| 1124 | { |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 1125 | struct mv643xx_eth_private *mp = netdev_priv(dev); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1126 | |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 1127 | init_mac_tables(mp); |
| 1128 | uc_addr_set(mp, dev->dev_addr); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1129 | } |
| 1130 | |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1131 | static int mv643xx_eth_set_mac_address(struct net_device *dev, void *addr) |
| 1132 | { |
| 1133 | int i; |
| 1134 | |
| 1135 | for (i = 0; i < 6; i++) |
| 1136 | /* +2 is for the offset of the HW addr type */ |
| 1137 | dev->dev_addr[i] = ((unsigned char *)addr)[i + 2]; |
| 1138 | mv643xx_eth_update_mac_address(dev); |
| 1139 | return 0; |
| 1140 | } |
| 1141 | |
Lennert Buytenhek | 6987656 | 2008-06-01 11:43:32 +0200 | [diff] [blame] | 1142 | static int addr_crc(unsigned char *addr) |
| 1143 | { |
| 1144 | int crc = 0; |
| 1145 | int i; |
| 1146 | |
| 1147 | for (i = 0; i < 6; i++) { |
| 1148 | int j; |
| 1149 | |
| 1150 | crc = (crc ^ addr[i]) << 8; |
| 1151 | for (j = 7; j >= 0; j--) { |
| 1152 | if (crc & (0x100 << j)) |
| 1153 | crc ^= 0x107 << j; |
| 1154 | } |
| 1155 | } |
| 1156 | |
| 1157 | return crc; |
| 1158 | } |
| 1159 | |
Lennert Buytenhek | 5daffe9 | 2008-06-01 02:52:41 +0200 | [diff] [blame] | 1160 | static void mc_addr(struct mv643xx_eth_private *mp, unsigned char *addr) |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1161 | { |
| 1162 | unsigned int port_num = mp->port_num; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1163 | int table; |
Lennert Buytenhek | 6987656 | 2008-06-01 11:43:32 +0200 | [diff] [blame] | 1164 | int crc; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1165 | |
Lennert Buytenhek | 5daffe9 | 2008-06-01 02:52:41 +0200 | [diff] [blame] | 1166 | if ((addr[0] == 0x01) && (addr[1] == 0x00) && |
| 1167 | (addr[2] == 0x5E) && (addr[3] == 0x00) && (addr[4] == 0x00)) { |
Lennert Buytenhek | 3cb4667c | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 1168 | table = SPECIAL_MCAST_TABLE(port_num); |
Lennert Buytenhek | 5daffe9 | 2008-06-01 02:52:41 +0200 | [diff] [blame] | 1169 | set_filter_table_entry(mp, table, addr[5]); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1170 | return; |
| 1171 | } |
| 1172 | |
Lennert Buytenhek | 6987656 | 2008-06-01 11:43:32 +0200 | [diff] [blame] | 1173 | crc = addr_crc(addr); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1174 | |
Lennert Buytenhek | 3cb4667c | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 1175 | table = OTHER_MCAST_TABLE(port_num); |
Lennert Buytenhek | 6987656 | 2008-06-01 11:43:32 +0200 | [diff] [blame] | 1176 | set_filter_table_entry(mp, table, crc); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1177 | } |
| 1178 | |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 1179 | static void set_multicast_list(struct net_device *dev) |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1180 | { |
| 1181 | |
| 1182 | struct dev_mc_list *mc_list; |
| 1183 | int i; |
| 1184 | int table_index; |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 1185 | struct mv643xx_eth_private *mp = netdev_priv(dev); |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 1186 | unsigned int port_num = mp->port_num; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1187 | |
| 1188 | /* If the device is in promiscuous mode or in all multicast mode, |
| 1189 | * we will fully populate both multicast tables with accept. |
| 1190 | * This is guaranteed to yield a match on all multicast addresses... |
| 1191 | */ |
| 1192 | if ((dev->flags & IFF_PROMISC) || (dev->flags & IFF_ALLMULTI)) { |
| 1193 | for (table_index = 0; table_index <= 0xFC; table_index += 4) { |
| 1194 | /* Set all entries in DA filter special multicast |
| 1195 | * table (Ex_dFSMT) |
| 1196 | * Set for ETH_Q0 for now |
| 1197 | * Bits |
| 1198 | * 0 Accept=1, Drop=0 |
| 1199 | * 3-1 Queue ETH_Q0=0 |
| 1200 | * 7-4 Reserved = 0; |
| 1201 | */ |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 1202 | wrl(mp, SPECIAL_MCAST_TABLE(port_num) + table_index, 0x01010101); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1203 | |
| 1204 | /* Set all entries in DA filter other multicast |
| 1205 | * table (Ex_dFOMT) |
| 1206 | * Set for ETH_Q0 for now |
| 1207 | * Bits |
| 1208 | * 0 Accept=1, Drop=0 |
| 1209 | * 3-1 Queue ETH_Q0=0 |
| 1210 | * 7-4 Reserved = 0; |
| 1211 | */ |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 1212 | wrl(mp, OTHER_MCAST_TABLE(port_num) + table_index, 0x01010101); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1213 | } |
| 1214 | return; |
| 1215 | } |
| 1216 | |
| 1217 | /* We will clear out multicast tables every time we get the list. |
| 1218 | * Then add the entire new list... |
| 1219 | */ |
| 1220 | for (table_index = 0; table_index <= 0xFC; table_index += 4) { |
| 1221 | /* Clear DA filter special multicast table (Ex_dFSMT) */ |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 1222 | wrl(mp, SPECIAL_MCAST_TABLE(port_num) + table_index, 0); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1223 | |
| 1224 | /* Clear DA filter other multicast table (Ex_dFOMT) */ |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 1225 | wrl(mp, OTHER_MCAST_TABLE(port_num) + table_index, 0); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1226 | } |
| 1227 | |
| 1228 | /* Get pointer to net_device multicast list and add each one... */ |
| 1229 | for (i = 0, mc_list = dev->mc_list; |
| 1230 | (i < 256) && (mc_list != NULL) && (i < dev->mc_count); |
| 1231 | i++, mc_list = mc_list->next) |
| 1232 | if (mc_list->dmi_addrlen == 6) |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 1233 | mc_addr(mp, mc_list->dmi_addr); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1234 | } |
| 1235 | |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1236 | static void mv643xx_eth_set_rx_mode(struct net_device *dev) |
| 1237 | { |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 1238 | struct mv643xx_eth_private *mp = netdev_priv(dev); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1239 | u32 config_reg; |
| 1240 | |
Lennert Buytenhek | 3cb4667c | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 1241 | config_reg = rdl(mp, PORT_CONFIG(mp->port_num)); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1242 | if (dev->flags & IFF_PROMISC) |
Lennert Buytenhek | d9a073e | 2008-06-01 01:22:06 +0200 | [diff] [blame] | 1243 | config_reg |= UNICAST_PROMISCUOUS_MODE; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1244 | else |
Lennert Buytenhek | d9a073e | 2008-06-01 01:22:06 +0200 | [diff] [blame] | 1245 | config_reg &= ~UNICAST_PROMISCUOUS_MODE; |
Lennert Buytenhek | 3cb4667c | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 1246 | wrl(mp, PORT_CONFIG(mp->port_num), config_reg); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1247 | |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 1248 | set_multicast_list(dev); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1249 | } |
| 1250 | |
| 1251 | |
| 1252 | /* rx/tx queue initialisation ***********************************************/ |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 1253 | static int rxq_init(struct mv643xx_eth_private *mp) |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1254 | { |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 1255 | struct rx_queue *rxq = mp->rxq; |
| 1256 | struct rx_desc *rx_desc; |
| 1257 | int size; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1258 | int i; |
| 1259 | |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 1260 | rxq->rx_ring_size = mp->default_rx_ring_size; |
| 1261 | |
| 1262 | rxq->rx_desc_count = 0; |
| 1263 | rxq->rx_curr_desc = 0; |
| 1264 | rxq->rx_used_desc = 0; |
| 1265 | |
| 1266 | size = rxq->rx_ring_size * sizeof(struct rx_desc); |
| 1267 | |
| 1268 | if (size <= mp->rx_desc_sram_size) { |
| 1269 | rxq->rx_desc_area = ioremap(mp->rx_desc_sram_addr, |
| 1270 | mp->rx_desc_sram_size); |
| 1271 | rxq->rx_desc_dma = mp->rx_desc_sram_addr; |
| 1272 | } else { |
| 1273 | rxq->rx_desc_area = dma_alloc_coherent(NULL, size, |
| 1274 | &rxq->rx_desc_dma, |
| 1275 | GFP_KERNEL); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1276 | } |
| 1277 | |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 1278 | if (rxq->rx_desc_area == NULL) { |
| 1279 | dev_printk(KERN_ERR, &mp->dev->dev, |
| 1280 | "can't allocate rx ring (%d bytes)\n", size); |
| 1281 | goto out; |
| 1282 | } |
| 1283 | memset(rxq->rx_desc_area, 0, size); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1284 | |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 1285 | rxq->rx_desc_area_size = size; |
| 1286 | rxq->rx_skb = kmalloc(rxq->rx_ring_size * sizeof(*rxq->rx_skb), |
| 1287 | GFP_KERNEL); |
| 1288 | if (rxq->rx_skb == NULL) { |
| 1289 | dev_printk(KERN_ERR, &mp->dev->dev, |
| 1290 | "can't allocate rx skb ring\n"); |
| 1291 | goto out_free; |
| 1292 | } |
| 1293 | |
| 1294 | rx_desc = (struct rx_desc *)rxq->rx_desc_area; |
| 1295 | for (i = 0; i < rxq->rx_ring_size; i++) { |
| 1296 | int nexti = (i + 1) % rxq->rx_ring_size; |
| 1297 | rx_desc[i].next_desc_ptr = rxq->rx_desc_dma + |
| 1298 | nexti * sizeof(struct rx_desc); |
| 1299 | } |
| 1300 | |
| 1301 | init_timer(&rxq->rx_oom); |
| 1302 | rxq->rx_oom.data = (unsigned long)rxq; |
| 1303 | rxq->rx_oom.function = rxq_refill_timer_wrapper; |
| 1304 | |
| 1305 | return 0; |
| 1306 | |
| 1307 | |
| 1308 | out_free: |
| 1309 | if (size <= mp->rx_desc_sram_size) |
| 1310 | iounmap(rxq->rx_desc_area); |
| 1311 | else |
| 1312 | dma_free_coherent(NULL, size, |
| 1313 | rxq->rx_desc_area, |
| 1314 | rxq->rx_desc_dma); |
| 1315 | |
| 1316 | out: |
| 1317 | return -ENOMEM; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1318 | } |
| 1319 | |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 1320 | static void rxq_deinit(struct rx_queue *rxq) |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1321 | { |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 1322 | struct mv643xx_eth_private *mp = rxq_to_mp(rxq); |
| 1323 | int i; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1324 | |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 1325 | rxq_disable(rxq); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1326 | |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 1327 | del_timer_sync(&rxq->rx_oom); |
| 1328 | |
| 1329 | for (i = 0; i < rxq->rx_ring_size; i++) { |
| 1330 | if (rxq->rx_skb[i]) { |
| 1331 | dev_kfree_skb(rxq->rx_skb[i]); |
| 1332 | rxq->rx_desc_count--; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1333 | } |
| 1334 | } |
| 1335 | |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 1336 | if (rxq->rx_desc_count) { |
| 1337 | dev_printk(KERN_ERR, &mp->dev->dev, |
| 1338 | "error freeing rx ring -- %d skbs stuck\n", |
| 1339 | rxq->rx_desc_count); |
| 1340 | } |
| 1341 | |
| 1342 | if (rxq->rx_desc_area_size <= mp->rx_desc_sram_size) |
| 1343 | iounmap(rxq->rx_desc_area); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1344 | else |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 1345 | dma_free_coherent(NULL, rxq->rx_desc_area_size, |
| 1346 | rxq->rx_desc_area, rxq->rx_desc_dma); |
| 1347 | |
| 1348 | kfree(rxq->rx_skb); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1349 | } |
| 1350 | |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 1351 | static int txq_init(struct mv643xx_eth_private *mp) |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1352 | { |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 1353 | struct tx_queue *txq = mp->txq; |
| 1354 | struct tx_desc *tx_desc; |
| 1355 | int size; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1356 | int i; |
| 1357 | |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 1358 | txq->tx_ring_size = mp->default_tx_ring_size; |
| 1359 | |
| 1360 | txq->tx_desc_count = 0; |
| 1361 | txq->tx_curr_desc = 0; |
| 1362 | txq->tx_used_desc = 0; |
| 1363 | |
| 1364 | size = txq->tx_ring_size * sizeof(struct tx_desc); |
| 1365 | |
| 1366 | if (size <= mp->tx_desc_sram_size) { |
| 1367 | txq->tx_desc_area = ioremap(mp->tx_desc_sram_addr, |
| 1368 | mp->tx_desc_sram_size); |
| 1369 | txq->tx_desc_dma = mp->tx_desc_sram_addr; |
| 1370 | } else { |
| 1371 | txq->tx_desc_area = dma_alloc_coherent(NULL, size, |
| 1372 | &txq->tx_desc_dma, |
| 1373 | GFP_KERNEL); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1374 | } |
| 1375 | |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 1376 | if (txq->tx_desc_area == NULL) { |
| 1377 | dev_printk(KERN_ERR, &mp->dev->dev, |
| 1378 | "can't allocate tx ring (%d bytes)\n", size); |
| 1379 | goto out; |
| 1380 | } |
| 1381 | memset(txq->tx_desc_area, 0, size); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1382 | |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 1383 | txq->tx_desc_area_size = size; |
| 1384 | txq->tx_skb = kmalloc(txq->tx_ring_size * sizeof(*txq->tx_skb), |
| 1385 | GFP_KERNEL); |
| 1386 | if (txq->tx_skb == NULL) { |
| 1387 | dev_printk(KERN_ERR, &mp->dev->dev, |
| 1388 | "can't allocate tx skb ring\n"); |
| 1389 | goto out_free; |
| 1390 | } |
| 1391 | |
| 1392 | tx_desc = (struct tx_desc *)txq->tx_desc_area; |
| 1393 | for (i = 0; i < txq->tx_ring_size; i++) { |
| 1394 | int nexti = (i + 1) % txq->tx_ring_size; |
| 1395 | tx_desc[i].next_desc_ptr = txq->tx_desc_dma + |
| 1396 | nexti * sizeof(struct tx_desc); |
| 1397 | } |
| 1398 | |
| 1399 | return 0; |
| 1400 | |
| 1401 | |
| 1402 | out_free: |
| 1403 | if (size <= mp->tx_desc_sram_size) |
| 1404 | iounmap(txq->tx_desc_area); |
| 1405 | else |
| 1406 | dma_free_coherent(NULL, size, |
| 1407 | txq->tx_desc_area, |
| 1408 | txq->tx_desc_dma); |
| 1409 | |
| 1410 | out: |
| 1411 | return -ENOMEM; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1412 | } |
| 1413 | |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 1414 | static void txq_reclaim(struct tx_queue *txq, int force) |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1415 | { |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 1416 | struct mv643xx_eth_private *mp = txq_to_mp(txq); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1417 | unsigned long flags; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1418 | |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 1419 | spin_lock_irqsave(&mp->lock, flags); |
| 1420 | while (txq->tx_desc_count > 0) { |
| 1421 | int tx_index; |
| 1422 | struct tx_desc *desc; |
| 1423 | u32 cmd_sts; |
| 1424 | struct sk_buff *skb; |
| 1425 | dma_addr_t addr; |
| 1426 | int count; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1427 | |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 1428 | tx_index = txq->tx_used_desc; |
| 1429 | desc = &txq->tx_desc_area[tx_index]; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1430 | cmd_sts = desc->cmd_sts; |
| 1431 | |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 1432 | if (!force && (cmd_sts & BUFFER_OWNED_BY_DMA)) |
| 1433 | break; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1434 | |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 1435 | txq->tx_used_desc = (tx_index + 1) % txq->tx_ring_size; |
| 1436 | txq->tx_desc_count--; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1437 | |
| 1438 | addr = desc->buf_ptr; |
| 1439 | count = desc->byte_cnt; |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 1440 | skb = txq->tx_skb[tx_index]; |
| 1441 | txq->tx_skb[tx_index] = NULL; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1442 | |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 1443 | if (cmd_sts & ERROR_SUMMARY) { |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 1444 | dev_printk(KERN_INFO, &mp->dev->dev, "tx error\n"); |
| 1445 | mp->dev->stats.tx_errors++; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1446 | } |
| 1447 | |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 1448 | /* |
| 1449 | * Drop mp->lock while we free the skb. |
| 1450 | */ |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1451 | spin_unlock_irqrestore(&mp->lock, flags); |
| 1452 | |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 1453 | if (cmd_sts & TX_FIRST_DESC) |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1454 | dma_unmap_single(NULL, addr, count, DMA_TO_DEVICE); |
| 1455 | else |
| 1456 | dma_unmap_page(NULL, addr, count, DMA_TO_DEVICE); |
| 1457 | |
| 1458 | if (skb) |
| 1459 | dev_kfree_skb_irq(skb); |
| 1460 | |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 1461 | spin_lock_irqsave(&mp->lock, flags); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1462 | } |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 1463 | spin_unlock_irqrestore(&mp->lock, flags); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1464 | } |
| 1465 | |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 1466 | static void txq_deinit(struct tx_queue *txq) |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1467 | { |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 1468 | struct mv643xx_eth_private *mp = txq_to_mp(txq); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1469 | |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 1470 | txq_disable(txq); |
| 1471 | txq_reclaim(txq, 1); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1472 | |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 1473 | BUG_ON(txq->tx_used_desc != txq->tx_curr_desc); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1474 | |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 1475 | if (txq->tx_desc_area_size <= mp->tx_desc_sram_size) |
| 1476 | iounmap(txq->tx_desc_area); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1477 | else |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 1478 | dma_free_coherent(NULL, txq->tx_desc_area_size, |
| 1479 | txq->tx_desc_area, txq->tx_desc_dma); |
| 1480 | |
| 1481 | kfree(txq->tx_skb); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1482 | } |
| 1483 | |
| 1484 | |
| 1485 | /* netdev ops and related ***************************************************/ |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 1486 | static void port_reset(struct mv643xx_eth_private *mp); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1487 | |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 1488 | static void mv643xx_eth_update_pscr(struct mv643xx_eth_private *mp, |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1489 | struct ethtool_cmd *ecmd) |
| 1490 | { |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 1491 | u32 pscr_o; |
| 1492 | u32 pscr_n; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1493 | |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 1494 | pscr_o = rdl(mp, PORT_SERIAL_CONTROL(mp->port_num)); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1495 | |
| 1496 | /* clear speed, duplex and rx buffer size fields */ |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 1497 | pscr_n = pscr_o & ~(SET_MII_SPEED_TO_100 | |
| 1498 | SET_GMII_SPEED_TO_1000 | |
| 1499 | SET_FULL_DUPLEX_MODE | |
| 1500 | MAX_RX_PACKET_MASK); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1501 | |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 1502 | if (ecmd->speed == SPEED_1000) { |
| 1503 | pscr_n |= SET_GMII_SPEED_TO_1000 | MAX_RX_PACKET_9700BYTE; |
| 1504 | } else { |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1505 | if (ecmd->speed == SPEED_100) |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 1506 | pscr_n |= SET_MII_SPEED_TO_100; |
| 1507 | pscr_n |= MAX_RX_PACKET_1522BYTE; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1508 | } |
| 1509 | |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 1510 | if (ecmd->duplex == DUPLEX_FULL) |
| 1511 | pscr_n |= SET_FULL_DUPLEX_MODE; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1512 | |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 1513 | if (pscr_n != pscr_o) { |
| 1514 | if ((pscr_o & SERIAL_PORT_ENABLE) == 0) |
| 1515 | wrl(mp, PORT_SERIAL_CONTROL(mp->port_num), pscr_n); |
| 1516 | else { |
| 1517 | txq_disable(mp->txq); |
| 1518 | pscr_o &= ~SERIAL_PORT_ENABLE; |
| 1519 | wrl(mp, PORT_SERIAL_CONTROL(mp->port_num), pscr_o); |
| 1520 | wrl(mp, PORT_SERIAL_CONTROL(mp->port_num), pscr_n); |
| 1521 | wrl(mp, PORT_SERIAL_CONTROL(mp->port_num), pscr_n); |
| 1522 | txq_enable(mp->txq); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1523 | } |
| 1524 | } |
| 1525 | } |
| 1526 | |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1527 | static irqreturn_t mv643xx_eth_int_handler(int irq, void *dev_id) |
| 1528 | { |
| 1529 | struct net_device *dev = (struct net_device *)dev_id; |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 1530 | struct mv643xx_eth_private *mp = netdev_priv(dev); |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 1531 | u32 int_cause, int_cause_ext = 0; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1532 | |
| 1533 | /* Read interrupt cause registers */ |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 1534 | int_cause = rdl(mp, INT_CAUSE(mp->port_num)) & (INT_RX | INT_EXT); |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 1535 | if (int_cause & INT_EXT) { |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 1536 | int_cause_ext = rdl(mp, INT_CAUSE_EXT(mp->port_num)) |
Lennert Buytenhek | 073a345 | 2008-06-01 02:00:31 +0200 | [diff] [blame] | 1537 | & (INT_EXT_LINK | INT_EXT_PHY | INT_EXT_TX); |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 1538 | wrl(mp, INT_CAUSE_EXT(mp->port_num), ~int_cause_ext); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1539 | } |
| 1540 | |
| 1541 | /* PHY status changed */ |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 1542 | if (int_cause_ext & (INT_EXT_LINK | INT_EXT_PHY)) { |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1543 | if (mii_link_ok(&mp->mii)) { |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 1544 | struct ethtool_cmd cmd; |
| 1545 | |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1546 | mii_ethtool_gset(&mp->mii, &cmd); |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 1547 | mv643xx_eth_update_pscr(mp, &cmd); |
| 1548 | txq_enable(mp->txq); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1549 | if (!netif_carrier_ok(dev)) { |
| 1550 | netif_carrier_on(dev); |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 1551 | __txq_maybe_wake(mp->txq); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1552 | } |
| 1553 | } else if (netif_carrier_ok(dev)) { |
| 1554 | netif_stop_queue(dev); |
| 1555 | netif_carrier_off(dev); |
| 1556 | } |
| 1557 | } |
| 1558 | |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 1559 | #ifdef MV643XX_ETH_NAPI |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 1560 | if (int_cause & INT_RX) { |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1561 | /* schedule the NAPI poll routine to maintain port */ |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 1562 | wrl(mp, INT_MASK(mp->port_num), 0x00000000); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1563 | |
| 1564 | /* wait for previous write to complete */ |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 1565 | rdl(mp, INT_MASK(mp->port_num)); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1566 | |
| 1567 | netif_rx_schedule(dev, &mp->napi); |
| 1568 | } |
| 1569 | #else |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 1570 | if (int_cause & INT_RX) |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 1571 | rxq_process(mp->rxq, INT_MAX); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1572 | #endif |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 1573 | if (int_cause_ext & INT_EXT_TX) { |
| 1574 | txq_reclaim(mp->txq, 0); |
| 1575 | __txq_maybe_wake(mp->txq); |
| 1576 | } |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1577 | |
| 1578 | /* |
| 1579 | * If no real interrupt occured, exit. |
| 1580 | * This can happen when using gigE interrupt coalescing mechanism. |
| 1581 | */ |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 1582 | if ((int_cause == 0x0) && (int_cause_ext == 0x0)) |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1583 | return IRQ_NONE; |
| 1584 | |
| 1585 | return IRQ_HANDLED; |
| 1586 | } |
| 1587 | |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 1588 | static void phy_reset(struct mv643xx_eth_private *mp) |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1589 | { |
| 1590 | unsigned int phy_reg_data; |
| 1591 | |
| 1592 | /* Reset the PHY */ |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 1593 | read_smi_reg(mp, 0, &phy_reg_data); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1594 | phy_reg_data |= 0x8000; /* Set bit 15 to reset the PHY */ |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 1595 | write_smi_reg(mp, 0, phy_reg_data); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1596 | |
| 1597 | /* wait for PHY to come out of reset */ |
| 1598 | do { |
| 1599 | udelay(1); |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 1600 | read_smi_reg(mp, 0, &phy_reg_data); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1601 | } while (phy_reg_data & 0x8000); |
| 1602 | } |
| 1603 | |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 1604 | static void port_start(struct net_device *dev) |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1605 | { |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 1606 | struct mv643xx_eth_private *mp = netdev_priv(dev); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1607 | u32 pscr; |
| 1608 | struct ethtool_cmd ethtool_cmd; |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 1609 | int i; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1610 | |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 1611 | /* |
| 1612 | * Configure basic link parameters. |
| 1613 | */ |
| 1614 | pscr = rdl(mp, PORT_SERIAL_CONTROL(mp->port_num)); |
| 1615 | pscr &= ~(SERIAL_PORT_ENABLE | FORCE_LINK_PASS); |
| 1616 | wrl(mp, PORT_SERIAL_CONTROL(mp->port_num), pscr); |
| 1617 | pscr |= DISABLE_AUTO_NEG_FOR_FLOW_CTRL | |
| 1618 | DISABLE_AUTO_NEG_SPEED_GMII | |
| 1619 | DISABLE_AUTO_NEG_FOR_DUPLEX | |
| 1620 | DO_NOT_FORCE_LINK_FAIL | |
| 1621 | SERIAL_PORT_CONTROL_RESERVED; |
| 1622 | wrl(mp, PORT_SERIAL_CONTROL(mp->port_num), pscr); |
| 1623 | pscr |= SERIAL_PORT_ENABLE; |
| 1624 | wrl(mp, PORT_SERIAL_CONTROL(mp->port_num), pscr); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1625 | |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 1626 | wrl(mp, SDMA_CONFIG(mp->port_num), PORT_SDMA_CONFIG_DEFAULT_VALUE); |
| 1627 | |
| 1628 | mv643xx_eth_get_settings(dev, ðtool_cmd); |
| 1629 | phy_reset(mp); |
| 1630 | mv643xx_eth_set_settings(dev, ðtool_cmd); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1631 | |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 1632 | /* |
| 1633 | * Configure TX path and queues. |
| 1634 | */ |
| 1635 | wrl(mp, TX_BW_MTU(mp->port_num), 0); |
| 1636 | for (i = 0; i < 1; i++) { |
| 1637 | struct tx_queue *txq = mp->txq; |
| 1638 | int off = TXQ_CURRENT_DESC_PTR(mp->port_num); |
| 1639 | u32 addr; |
| 1640 | |
| 1641 | addr = (u32)txq->tx_desc_dma; |
| 1642 | addr += txq->tx_curr_desc * sizeof(struct tx_desc); |
| 1643 | wrl(mp, off, addr); |
| 1644 | } |
| 1645 | |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1646 | /* Add the assigned Ethernet address to the port's address table */ |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 1647 | uc_addr_set(mp, dev->dev_addr); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1648 | |
Lennert Buytenhek | d9a073e | 2008-06-01 01:22:06 +0200 | [diff] [blame] | 1649 | /* |
| 1650 | * Receive all unmatched unicast, TCP, UDP, BPDU and broadcast |
| 1651 | * frames to RX queue #0. |
| 1652 | */ |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 1653 | wrl(mp, PORT_CONFIG(mp->port_num), 0x00000000); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1654 | |
Lennert Buytenhek | 376489a | 2008-06-01 01:17:44 +0200 | [diff] [blame] | 1655 | /* |
| 1656 | * Treat BPDUs as normal multicasts, and disable partition mode. |
| 1657 | */ |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 1658 | wrl(mp, PORT_CONFIG_EXT(mp->port_num), 0x00000000); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1659 | |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 1660 | /* |
| 1661 | * Enable the receive queue. |
| 1662 | */ |
| 1663 | for (i = 0; i < 1; i++) { |
| 1664 | struct rx_queue *rxq = mp->rxq; |
| 1665 | int off = RXQ_CURRENT_DESC_PTR(mp->port_num); |
| 1666 | u32 addr; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1667 | |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 1668 | addr = (u32)rxq->rx_desc_dma; |
| 1669 | addr += rxq->rx_curr_desc * sizeof(struct rx_desc); |
| 1670 | wrl(mp, off, addr); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1671 | |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 1672 | rxq_enable(rxq); |
| 1673 | } |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1674 | } |
| 1675 | |
Lennert Buytenhek | ffd86bb | 2008-06-01 21:59:27 +0200 | [diff] [blame^] | 1676 | static void set_rx_coal(struct mv643xx_eth_private *mp, unsigned int delay) |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1677 | { |
| 1678 | unsigned int port_num = mp->port_num; |
| 1679 | unsigned int coal = ((mp->shared->t_clk / 1000000) * delay) / 64; |
| 1680 | |
| 1681 | /* Set RX Coalescing mechanism */ |
Lennert Buytenhek | 3cb4667c | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 1682 | wrl(mp, SDMA_CONFIG(port_num), |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1683 | ((coal & 0x3fff) << 8) | |
Lennert Buytenhek | 3cb4667c | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 1684 | (rdl(mp, SDMA_CONFIG(port_num)) |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1685 | & 0xffc000ff)); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1686 | } |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1687 | |
Lennert Buytenhek | ffd86bb | 2008-06-01 21:59:27 +0200 | [diff] [blame^] | 1688 | static void set_tx_coal(struct mv643xx_eth_private *mp, unsigned int delay) |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1689 | { |
| 1690 | unsigned int coal = ((mp->shared->t_clk / 1000000) * delay) / 64; |
| 1691 | |
| 1692 | /* Set TX Coalescing mechanism */ |
Lennert Buytenhek | 3cb4667c | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 1693 | wrl(mp, TX_FIFO_URGENT_THRESHOLD(mp->port_num), coal << 4); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1694 | } |
| 1695 | |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 1696 | static void port_init(struct mv643xx_eth_private *mp) |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1697 | { |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 1698 | port_reset(mp); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1699 | |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 1700 | init_mac_tables(mp); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1701 | } |
| 1702 | |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1703 | static int mv643xx_eth_open(struct net_device *dev) |
| 1704 | { |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 1705 | struct mv643xx_eth_private *mp = netdev_priv(dev); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1706 | unsigned int port_num = mp->port_num; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1707 | int err; |
| 1708 | |
| 1709 | /* Clear any pending ethernet port interrupts */ |
Lennert Buytenhek | 3cb4667c | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 1710 | wrl(mp, INT_CAUSE(port_num), 0); |
| 1711 | wrl(mp, INT_CAUSE_EXT(port_num), 0); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1712 | /* wait for previous write to complete */ |
Lennert Buytenhek | 3cb4667c | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 1713 | rdl(mp, INT_CAUSE_EXT(port_num)); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1714 | |
| 1715 | err = request_irq(dev->irq, mv643xx_eth_int_handler, |
| 1716 | IRQF_SHARED | IRQF_SAMPLE_RANDOM, dev->name, dev); |
| 1717 | if (err) { |
| 1718 | printk(KERN_ERR "%s: Can not assign IRQ\n", dev->name); |
| 1719 | return -EAGAIN; |
| 1720 | } |
| 1721 | |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 1722 | port_init(mp); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1723 | |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 1724 | err = rxq_init(mp); |
| 1725 | if (err) |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1726 | goto out_free_irq; |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 1727 | rxq_refill(mp->rxq); |
| 1728 | |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 1729 | err = txq_init(mp); |
| 1730 | if (err) |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1731 | goto out_free_rx_skb; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1732 | |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 1733 | #ifdef MV643XX_ETH_NAPI |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1734 | napi_enable(&mp->napi); |
| 1735 | #endif |
| 1736 | |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 1737 | port_start(dev); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1738 | |
Lennert Buytenhek | ffd86bb | 2008-06-01 21:59:27 +0200 | [diff] [blame^] | 1739 | set_rx_coal(mp, 0); |
| 1740 | set_tx_coal(mp, 0); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1741 | |
| 1742 | /* Unmask phy and link status changes interrupts */ |
Lennert Buytenhek | 073a345 | 2008-06-01 02:00:31 +0200 | [diff] [blame] | 1743 | wrl(mp, INT_MASK_EXT(port_num), INT_EXT_LINK | INT_EXT_PHY | INT_EXT_TX); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1744 | |
| 1745 | /* Unmask RX buffer and TX end interrupt */ |
Lennert Buytenhek | 073a345 | 2008-06-01 02:00:31 +0200 | [diff] [blame] | 1746 | wrl(mp, INT_MASK(port_num), INT_RX | INT_EXT); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1747 | |
| 1748 | return 0; |
| 1749 | |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 1750 | |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1751 | out_free_rx_skb: |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 1752 | rxq_deinit(mp->rxq); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1753 | out_free_irq: |
| 1754 | free_irq(dev->irq, dev); |
| 1755 | |
| 1756 | return err; |
| 1757 | } |
| 1758 | |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 1759 | static void port_reset(struct mv643xx_eth_private *mp) |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1760 | { |
| 1761 | unsigned int port_num = mp->port_num; |
| 1762 | unsigned int reg_data; |
| 1763 | |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 1764 | txq_disable(mp->txq); |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 1765 | rxq_disable(mp->rxq); |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 1766 | while (!(rdl(mp, PORT_STATUS(mp->port_num)) & TX_FIFO_EMPTY)) |
| 1767 | udelay(10); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1768 | |
| 1769 | /* Clear all MIB counters */ |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 1770 | clear_mib_counters(mp); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1771 | |
| 1772 | /* Reset the Enable bit in the Configuration Register */ |
Lennert Buytenhek | 3cb4667c | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 1773 | reg_data = rdl(mp, PORT_SERIAL_CONTROL(port_num)); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1774 | reg_data &= ~(SERIAL_PORT_ENABLE | |
| 1775 | DO_NOT_FORCE_LINK_FAIL | |
| 1776 | FORCE_LINK_PASS); |
Lennert Buytenhek | 3cb4667c | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 1777 | wrl(mp, PORT_SERIAL_CONTROL(port_num), reg_data); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1778 | } |
| 1779 | |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1780 | static int mv643xx_eth_stop(struct net_device *dev) |
| 1781 | { |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 1782 | struct mv643xx_eth_private *mp = netdev_priv(dev); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1783 | unsigned int port_num = mp->port_num; |
| 1784 | |
| 1785 | /* Mask all interrupts on ethernet port */ |
Lennert Buytenhek | 073a345 | 2008-06-01 02:00:31 +0200 | [diff] [blame] | 1786 | wrl(mp, INT_MASK(port_num), 0x00000000); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1787 | /* wait for previous write to complete */ |
Lennert Buytenhek | 3cb4667c | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 1788 | rdl(mp, INT_MASK(port_num)); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1789 | |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 1790 | #ifdef MV643XX_ETH_NAPI |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1791 | napi_disable(&mp->napi); |
| 1792 | #endif |
| 1793 | netif_carrier_off(dev); |
| 1794 | netif_stop_queue(dev); |
| 1795 | |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 1796 | port_reset(mp); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1797 | |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 1798 | txq_deinit(mp->txq); |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 1799 | rxq_deinit(mp->rxq); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1800 | |
| 1801 | free_irq(dev->irq, dev); |
| 1802 | |
| 1803 | return 0; |
| 1804 | } |
| 1805 | |
| 1806 | static int mv643xx_eth_do_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) |
| 1807 | { |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 1808 | struct mv643xx_eth_private *mp = netdev_priv(dev); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1809 | |
| 1810 | return generic_mii_ioctl(&mp->mii, if_mii(ifr), cmd, NULL); |
| 1811 | } |
| 1812 | |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1813 | static int mv643xx_eth_change_mtu(struct net_device *dev, int new_mtu) |
| 1814 | { |
| 1815 | if ((new_mtu > 9500) || (new_mtu < 64)) |
| 1816 | return -EINVAL; |
| 1817 | |
| 1818 | dev->mtu = new_mtu; |
| 1819 | if (!netif_running(dev)) |
| 1820 | return 0; |
| 1821 | |
| 1822 | /* |
| 1823 | * Stop and then re-open the interface. This will allocate RX |
| 1824 | * skbs of the new MTU. |
| 1825 | * There is a possible danger that the open will not succeed, |
| 1826 | * due to memory being full, which might fail the open function. |
| 1827 | */ |
| 1828 | mv643xx_eth_stop(dev); |
| 1829 | if (mv643xx_eth_open(dev)) { |
| 1830 | printk(KERN_ERR "%s: Fatal error on opening device\n", |
| 1831 | dev->name); |
| 1832 | } |
| 1833 | |
| 1834 | return 0; |
| 1835 | } |
| 1836 | |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1837 | static void mv643xx_eth_tx_timeout_task(struct work_struct *ugly) |
| 1838 | { |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 1839 | struct mv643xx_eth_private *mp = container_of(ugly, struct mv643xx_eth_private, |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1840 | tx_timeout_task); |
| 1841 | struct net_device *dev = mp->dev; |
| 1842 | |
| 1843 | if (!netif_running(dev)) |
| 1844 | return; |
| 1845 | |
| 1846 | netif_stop_queue(dev); |
| 1847 | |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 1848 | port_reset(mp); |
| 1849 | port_start(dev); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1850 | |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 1851 | __txq_maybe_wake(mp->txq); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1852 | } |
| 1853 | |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1854 | static void mv643xx_eth_tx_timeout(struct net_device *dev) |
| 1855 | { |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 1856 | struct mv643xx_eth_private *mp = netdev_priv(dev); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1857 | |
| 1858 | printk(KERN_INFO "%s: TX timeout ", dev->name); |
| 1859 | |
| 1860 | /* Do the reset outside of interrupt context */ |
| 1861 | schedule_work(&mp->tx_timeout_task); |
| 1862 | } |
| 1863 | |
Dale Farnsworth | 63c9e54 | 2005-09-02 13:49:10 -0700 | [diff] [blame] | 1864 | #ifdef CONFIG_NET_POLL_CONTROLLER |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 1865 | static void mv643xx_eth_netpoll(struct net_device *netdev) |
Dale Farnsworth | 63c9e54 | 2005-09-02 13:49:10 -0700 | [diff] [blame] | 1866 | { |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 1867 | struct mv643xx_eth_private *mp = netdev_priv(netdev); |
Dale Farnsworth | c2e5b35 | 2006-01-16 17:00:24 -0700 | [diff] [blame] | 1868 | int port_num = mp->port_num; |
Dale Farnsworth | 63c9e54 | 2005-09-02 13:49:10 -0700 | [diff] [blame] | 1869 | |
Lennert Buytenhek | 073a345 | 2008-06-01 02:00:31 +0200 | [diff] [blame] | 1870 | wrl(mp, INT_MASK(port_num), 0x00000000); |
Dale Farnsworth | c2e5b35 | 2006-01-16 17:00:24 -0700 | [diff] [blame] | 1871 | /* wait for previous write to complete */ |
Lennert Buytenhek | 3cb4667c | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 1872 | rdl(mp, INT_MASK(port_num)); |
Dale Farnsworth | c2e5b35 | 2006-01-16 17:00:24 -0700 | [diff] [blame] | 1873 | |
Al Viro | 9da3b1a | 2006-10-08 15:00:44 +0100 | [diff] [blame] | 1874 | mv643xx_eth_int_handler(netdev->irq, netdev); |
Dale Farnsworth | c2e5b35 | 2006-01-16 17:00:24 -0700 | [diff] [blame] | 1875 | |
Lennert Buytenhek | 073a345 | 2008-06-01 02:00:31 +0200 | [diff] [blame] | 1876 | wrl(mp, INT_MASK(port_num), INT_RX | INT_CAUSE_EXT); |
Dale Farnsworth | 63c9e54 | 2005-09-02 13:49:10 -0700 | [diff] [blame] | 1877 | } |
| 1878 | #endif |
| 1879 | |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 1880 | static int mv643xx_eth_mdio_read(struct net_device *dev, int phy_id, int location) |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1881 | { |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 1882 | struct mv643xx_eth_private *mp = netdev_priv(dev); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1883 | int val; |
| 1884 | |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 1885 | read_smi_reg(mp, location, &val); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1886 | return val; |
| 1887 | } |
| 1888 | |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 1889 | static void mv643xx_eth_mdio_write(struct net_device *dev, int phy_id, int location, int val) |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1890 | { |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 1891 | struct mv643xx_eth_private *mp = netdev_priv(dev); |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 1892 | write_smi_reg(mp, location, val); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1893 | } |
| 1894 | |
| 1895 | |
| 1896 | /* platform glue ************************************************************/ |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 1897 | static void |
| 1898 | mv643xx_eth_conf_mbus_windows(struct mv643xx_eth_shared_private *msp, |
| 1899 | struct mbus_dram_target_info *dram) |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1900 | { |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 1901 | void __iomem *base = msp->base; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1902 | u32 win_enable; |
| 1903 | u32 win_protect; |
| 1904 | int i; |
| 1905 | |
| 1906 | for (i = 0; i < 6; i++) { |
| 1907 | writel(0, base + WINDOW_BASE(i)); |
| 1908 | writel(0, base + WINDOW_SIZE(i)); |
| 1909 | if (i < 4) |
| 1910 | writel(0, base + WINDOW_REMAP_HIGH(i)); |
| 1911 | } |
| 1912 | |
| 1913 | win_enable = 0x3f; |
| 1914 | win_protect = 0; |
| 1915 | |
| 1916 | for (i = 0; i < dram->num_cs; i++) { |
| 1917 | struct mbus_dram_window *cs = dram->cs + i; |
| 1918 | |
| 1919 | writel((cs->base & 0xffff0000) | |
| 1920 | (cs->mbus_attr << 8) | |
| 1921 | dram->mbus_dram_target_id, base + WINDOW_BASE(i)); |
| 1922 | writel((cs->size - 1) & 0xffff0000, base + WINDOW_SIZE(i)); |
| 1923 | |
| 1924 | win_enable &= ~(1 << i); |
| 1925 | win_protect |= 3 << (2 * i); |
| 1926 | } |
| 1927 | |
| 1928 | writel(win_enable, base + WINDOW_BAR_ENABLE); |
| 1929 | msp->win_protect = win_protect; |
| 1930 | } |
| 1931 | |
| 1932 | static int mv643xx_eth_shared_probe(struct platform_device *pdev) |
| 1933 | { |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 1934 | static int mv643xx_eth_version_printed = 0; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1935 | struct mv643xx_eth_shared_platform_data *pd = pdev->dev.platform_data; |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 1936 | struct mv643xx_eth_shared_private *msp; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1937 | struct resource *res; |
| 1938 | int ret; |
| 1939 | |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 1940 | if (!mv643xx_eth_version_printed++) |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1941 | printk(KERN_NOTICE "MV-643xx 10/100/1000 Ethernet Driver\n"); |
| 1942 | |
| 1943 | ret = -EINVAL; |
| 1944 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 1945 | if (res == NULL) |
| 1946 | goto out; |
| 1947 | |
| 1948 | ret = -ENOMEM; |
| 1949 | msp = kmalloc(sizeof(*msp), GFP_KERNEL); |
| 1950 | if (msp == NULL) |
| 1951 | goto out; |
| 1952 | memset(msp, 0, sizeof(*msp)); |
| 1953 | |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 1954 | msp->base = ioremap(res->start, res->end - res->start + 1); |
| 1955 | if (msp->base == NULL) |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1956 | goto out_free; |
| 1957 | |
| 1958 | spin_lock_init(&msp->phy_lock); |
| 1959 | msp->t_clk = (pd != NULL && pd->t_clk != 0) ? pd->t_clk : 133000000; |
| 1960 | |
| 1961 | platform_set_drvdata(pdev, msp); |
| 1962 | |
| 1963 | /* |
| 1964 | * (Re-)program MBUS remapping windows if we are asked to. |
| 1965 | */ |
| 1966 | if (pd != NULL && pd->dram != NULL) |
| 1967 | mv643xx_eth_conf_mbus_windows(msp, pd->dram); |
| 1968 | |
| 1969 | return 0; |
| 1970 | |
| 1971 | out_free: |
| 1972 | kfree(msp); |
| 1973 | out: |
| 1974 | return ret; |
| 1975 | } |
| 1976 | |
| 1977 | static int mv643xx_eth_shared_remove(struct platform_device *pdev) |
| 1978 | { |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 1979 | struct mv643xx_eth_shared_private *msp = platform_get_drvdata(pdev); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1980 | |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 1981 | iounmap(msp->base); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1982 | kfree(msp); |
| 1983 | |
| 1984 | return 0; |
| 1985 | } |
| 1986 | |
| 1987 | static struct platform_driver mv643xx_eth_shared_driver = { |
| 1988 | .probe = mv643xx_eth_shared_probe, |
| 1989 | .remove = mv643xx_eth_shared_remove, |
| 1990 | .driver = { |
| 1991 | .name = MV643XX_ETH_SHARED_NAME, |
| 1992 | .owner = THIS_MODULE, |
| 1993 | }, |
| 1994 | }; |
| 1995 | |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 1996 | static void phy_addr_set(struct mv643xx_eth_private *mp, int phy_addr) |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1997 | { |
| 1998 | u32 reg_data; |
| 1999 | int addr_shift = 5 * mp->port_num; |
| 2000 | |
Lennert Buytenhek | 3cb4667c | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 2001 | reg_data = rdl(mp, PHY_ADDR); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2002 | reg_data &= ~(0x1f << addr_shift); |
| 2003 | reg_data |= (phy_addr & 0x1f) << addr_shift; |
Lennert Buytenhek | 3cb4667c | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 2004 | wrl(mp, PHY_ADDR, reg_data); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2005 | } |
| 2006 | |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 2007 | static int phy_addr_get(struct mv643xx_eth_private *mp) |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2008 | { |
| 2009 | unsigned int reg_data; |
| 2010 | |
Lennert Buytenhek | 3cb4667c | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 2011 | reg_data = rdl(mp, PHY_ADDR); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2012 | |
| 2013 | return ((reg_data >> (5 * mp->port_num)) & 0x1f); |
| 2014 | } |
| 2015 | |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 2016 | static int phy_detect(struct mv643xx_eth_private *mp) |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2017 | { |
| 2018 | unsigned int phy_reg_data0; |
| 2019 | int auto_neg; |
| 2020 | |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 2021 | read_smi_reg(mp, 0, &phy_reg_data0); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2022 | auto_neg = phy_reg_data0 & 0x1000; |
| 2023 | phy_reg_data0 ^= 0x1000; /* invert auto_neg */ |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 2024 | write_smi_reg(mp, 0, phy_reg_data0); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2025 | |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 2026 | read_smi_reg(mp, 0, &phy_reg_data0); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2027 | if ((phy_reg_data0 & 0x1000) == auto_neg) |
| 2028 | return -ENODEV; /* change didn't take */ |
| 2029 | |
| 2030 | phy_reg_data0 ^= 0x1000; |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 2031 | write_smi_reg(mp, 0, phy_reg_data0); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2032 | return 0; |
| 2033 | } |
| 2034 | |
James Chapman | d0412d9 | 2006-01-27 01:15:30 -0700 | [diff] [blame] | 2035 | static void mv643xx_init_ethtool_cmd(struct net_device *dev, int phy_address, |
| 2036 | int speed, int duplex, |
| 2037 | struct ethtool_cmd *cmd) |
| 2038 | { |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 2039 | struct mv643xx_eth_private *mp = netdev_priv(dev); |
James Chapman | d0412d9 | 2006-01-27 01:15:30 -0700 | [diff] [blame] | 2040 | |
| 2041 | memset(cmd, 0, sizeof(*cmd)); |
| 2042 | |
| 2043 | cmd->port = PORT_MII; |
| 2044 | cmd->transceiver = XCVR_INTERNAL; |
| 2045 | cmd->phy_address = phy_address; |
| 2046 | |
| 2047 | if (speed == 0) { |
| 2048 | cmd->autoneg = AUTONEG_ENABLE; |
| 2049 | /* mii lib checks, but doesn't use speed on AUTONEG_ENABLE */ |
| 2050 | cmd->speed = SPEED_100; |
| 2051 | cmd->advertising = ADVERTISED_10baseT_Half | |
| 2052 | ADVERTISED_10baseT_Full | |
| 2053 | ADVERTISED_100baseT_Half | |
| 2054 | ADVERTISED_100baseT_Full; |
| 2055 | if (mp->mii.supports_gmii) |
| 2056 | cmd->advertising |= ADVERTISED_1000baseT_Full; |
| 2057 | } else { |
| 2058 | cmd->autoneg = AUTONEG_DISABLE; |
| 2059 | cmd->speed = speed; |
| 2060 | cmd->duplex = duplex; |
| 2061 | } |
| 2062 | } |
| 2063 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 2064 | static int mv643xx_eth_probe(struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2065 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2066 | struct mv643xx_eth_platform_data *pd; |
Dale Farnsworth | 84dd619 | 2007-03-03 06:40:28 -0700 | [diff] [blame] | 2067 | int port_num; |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 2068 | struct mv643xx_eth_private *mp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2069 | struct net_device *dev; |
| 2070 | u8 *p; |
| 2071 | struct resource *res; |
| 2072 | int err; |
James Chapman | d0412d9 | 2006-01-27 01:15:30 -0700 | [diff] [blame] | 2073 | struct ethtool_cmd cmd; |
Dale Farnsworth | 0199987 | 2006-01-27 01:18:01 -0700 | [diff] [blame] | 2074 | int duplex = DUPLEX_HALF; |
| 2075 | int speed = 0; /* default to auto-negotiation */ |
Al Viro | c5d6471 | 2007-10-13 08:30:26 +0100 | [diff] [blame] | 2076 | DECLARE_MAC_BUF(mac); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2077 | |
Dale Farnsworth | 84dd619 | 2007-03-03 06:40:28 -0700 | [diff] [blame] | 2078 | pd = pdev->dev.platform_data; |
| 2079 | if (pd == NULL) { |
| 2080 | printk(KERN_ERR "No mv643xx_eth_platform_data\n"); |
| 2081 | return -ENODEV; |
| 2082 | } |
| 2083 | |
Lennert Buytenhek | fa3959f | 2008-04-24 01:27:02 +0200 | [diff] [blame] | 2084 | if (pd->shared == NULL) { |
| 2085 | printk(KERN_ERR "No mv643xx_eth_platform_data->shared\n"); |
| 2086 | return -ENODEV; |
| 2087 | } |
| 2088 | |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 2089 | dev = alloc_etherdev(sizeof(struct mv643xx_eth_private)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2090 | if (!dev) |
| 2091 | return -ENOMEM; |
| 2092 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 2093 | platform_set_drvdata(pdev, dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2094 | |
| 2095 | mp = netdev_priv(dev); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 2096 | mp->dev = dev; |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 2097 | #ifdef MV643XX_ETH_NAPI |
| 2098 | netif_napi_add(dev, &mp->napi, mv643xx_eth_poll, 64); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 2099 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2100 | |
| 2101 | res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); |
| 2102 | BUG_ON(!res); |
| 2103 | dev->irq = res->start; |
| 2104 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2105 | dev->open = mv643xx_eth_open; |
| 2106 | dev->stop = mv643xx_eth_stop; |
| 2107 | dev->hard_start_xmit = mv643xx_eth_start_xmit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2108 | dev->set_mac_address = mv643xx_eth_set_mac_address; |
| 2109 | dev->set_multicast_list = mv643xx_eth_set_rx_mode; |
| 2110 | |
| 2111 | /* No need to Tx Timeout */ |
| 2112 | dev->tx_timeout = mv643xx_eth_tx_timeout; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2113 | |
Dale Farnsworth | 63c9e54 | 2005-09-02 13:49:10 -0700 | [diff] [blame] | 2114 | #ifdef CONFIG_NET_POLL_CONTROLLER |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 2115 | dev->poll_controller = mv643xx_eth_netpoll; |
Dale Farnsworth | 63c9e54 | 2005-09-02 13:49:10 -0700 | [diff] [blame] | 2116 | #endif |
| 2117 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2118 | dev->watchdog_timeo = 2 * HZ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2119 | dev->base_addr = 0; |
| 2120 | dev->change_mtu = mv643xx_eth_change_mtu; |
James Chapman | d0412d9 | 2006-01-27 01:15:30 -0700 | [diff] [blame] | 2121 | dev->do_ioctl = mv643xx_eth_do_ioctl; |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 2122 | SET_ETHTOOL_OPS(dev, &mv643xx_eth_ethtool_ops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2123 | |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 2124 | #ifdef MV643XX_ETH_CHECKSUM_OFFLOAD_TX |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2125 | #ifdef MAX_SKB_FRAGS |
| 2126 | /* |
| 2127 | * Zero copy can only work if we use Discovery II memory. Else, we will |
| 2128 | * have to map the buffers to ISA memory which is only 16 MB |
| 2129 | */ |
Wolfram Joost | 6389057 | 2006-01-16 16:57:41 -0700 | [diff] [blame] | 2130 | dev->features = NETIF_F_SG | NETIF_F_IP_CSUM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2131 | #endif |
| 2132 | #endif |
| 2133 | |
| 2134 | /* Configure the timeout task */ |
Al Viro | 91c7c56 | 2006-12-06 19:50:06 +0000 | [diff] [blame] | 2135 | INIT_WORK(&mp->tx_timeout_task, mv643xx_eth_tx_timeout_task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2136 | |
| 2137 | spin_lock_init(&mp->lock); |
| 2138 | |
Lennert Buytenhek | fa3959f | 2008-04-24 01:27:02 +0200 | [diff] [blame] | 2139 | mp->shared = platform_get_drvdata(pd->shared); |
Gabriel Paubert | fadac40 | 2007-03-23 12:03:52 -0700 | [diff] [blame] | 2140 | port_num = mp->port_num = pd->port_number; |
Dale Farnsworth | 84dd619 | 2007-03-03 06:40:28 -0700 | [diff] [blame] | 2141 | |
Lennert Buytenhek | f2ce825 | 2008-04-24 01:27:17 +0200 | [diff] [blame] | 2142 | if (mp->shared->win_protect) |
| 2143 | wrl(mp, WINDOW_PROTECT(port_num), mp->shared->win_protect); |
| 2144 | |
Lennert Buytenhek | ce4e2e4 | 2008-04-24 01:29:59 +0200 | [diff] [blame] | 2145 | mp->shared_smi = mp->shared; |
| 2146 | if (pd->shared_smi != NULL) |
| 2147 | mp->shared_smi = platform_get_drvdata(pd->shared_smi); |
| 2148 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2149 | /* set default config values */ |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 2150 | uc_addr_get(mp, dev->dev_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2151 | |
Dale Farnsworth | 84dd619 | 2007-03-03 06:40:28 -0700 | [diff] [blame] | 2152 | if (is_valid_ether_addr(pd->mac_addr)) |
| 2153 | memcpy(dev->dev_addr, pd->mac_addr, 6); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2154 | |
Dale Farnsworth | 84dd619 | 2007-03-03 06:40:28 -0700 | [diff] [blame] | 2155 | if (pd->phy_addr || pd->force_phy_addr) |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 2156 | phy_addr_set(mp, pd->phy_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2157 | |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 2158 | mp->default_rx_ring_size = DEFAULT_RX_QUEUE_SIZE; |
Dale Farnsworth | 84dd619 | 2007-03-03 06:40:28 -0700 | [diff] [blame] | 2159 | if (pd->rx_queue_size) |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 2160 | mp->default_rx_ring_size = pd->rx_queue_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2161 | |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 2162 | mp->default_tx_ring_size = DEFAULT_TX_QUEUE_SIZE; |
Dale Farnsworth | 84dd619 | 2007-03-03 06:40:28 -0700 | [diff] [blame] | 2163 | if (pd->tx_queue_size) |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 2164 | mp->default_tx_ring_size = pd->tx_queue_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2165 | |
Dale Farnsworth | 84dd619 | 2007-03-03 06:40:28 -0700 | [diff] [blame] | 2166 | if (pd->tx_sram_size) { |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 2167 | mp->tx_desc_sram_size = pd->tx_sram_size; |
| 2168 | mp->tx_desc_sram_addr = pd->tx_sram_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2169 | } |
| 2170 | |
Dale Farnsworth | 84dd619 | 2007-03-03 06:40:28 -0700 | [diff] [blame] | 2171 | if (pd->rx_sram_size) { |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 2172 | mp->rx_desc_sram_addr = pd->rx_sram_addr; |
| 2173 | mp->rx_desc_sram_size = pd->rx_sram_size; |
Dale Farnsworth | 84dd619 | 2007-03-03 06:40:28 -0700 | [diff] [blame] | 2174 | } |
| 2175 | |
| 2176 | duplex = pd->duplex; |
| 2177 | speed = pd->speed; |
| 2178 | |
James Chapman | c28a4f8 | 2006-01-27 01:13:15 -0700 | [diff] [blame] | 2179 | /* Hook up MII support for ethtool */ |
| 2180 | mp->mii.dev = dev; |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 2181 | mp->mii.mdio_read = mv643xx_eth_mdio_read; |
| 2182 | mp->mii.mdio_write = mv643xx_eth_mdio_write; |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 2183 | mp->mii.phy_id = phy_addr_get(mp); |
James Chapman | c28a4f8 | 2006-01-27 01:13:15 -0700 | [diff] [blame] | 2184 | mp->mii.phy_id_mask = 0x3f; |
| 2185 | mp->mii.reg_num_mask = 0x1f; |
| 2186 | |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 2187 | err = phy_detect(mp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2188 | if (err) { |
Lennert Buytenhek | c1b35a2 | 2008-03-18 11:37:19 -0700 | [diff] [blame] | 2189 | pr_debug("%s: No PHY detected at addr %d\n", |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 2190 | dev->name, phy_addr_get(mp)); |
James Chapman | d0412d9 | 2006-01-27 01:15:30 -0700 | [diff] [blame] | 2191 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2192 | } |
| 2193 | |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 2194 | phy_reset(mp); |
James Chapman | c28a4f8 | 2006-01-27 01:13:15 -0700 | [diff] [blame] | 2195 | mp->mii.supports_gmii = mii_check_gmii_support(&mp->mii); |
James Chapman | d0412d9 | 2006-01-27 01:15:30 -0700 | [diff] [blame] | 2196 | mv643xx_init_ethtool_cmd(dev, mp->mii.phy_id, speed, duplex, &cmd); |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 2197 | mv643xx_eth_update_pscr(mp, &cmd); |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 2198 | mv643xx_eth_set_settings(dev, &cmd); |
James Chapman | c28a4f8 | 2006-01-27 01:13:15 -0700 | [diff] [blame] | 2199 | |
Olaf Hering | b0b8dab | 2006-04-27 18:23:49 -0700 | [diff] [blame] | 2200 | SET_NETDEV_DEV(dev, &pdev->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2201 | err = register_netdev(dev); |
| 2202 | if (err) |
| 2203 | goto out; |
| 2204 | |
| 2205 | p = dev->dev_addr; |
| 2206 | printk(KERN_NOTICE |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2207 | "%s: port %d with MAC address %s\n", |
| 2208 | dev->name, port_num, print_mac(mac, p)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2209 | |
| 2210 | if (dev->features & NETIF_F_SG) |
| 2211 | printk(KERN_NOTICE "%s: Scatter Gather Enabled\n", dev->name); |
| 2212 | |
| 2213 | if (dev->features & NETIF_F_IP_CSUM) |
| 2214 | printk(KERN_NOTICE "%s: TX TCP/IP Checksumming Supported\n", |
| 2215 | dev->name); |
| 2216 | |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 2217 | #ifdef MV643XX_ETH_CHECKSUM_OFFLOAD_TX |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2218 | printk(KERN_NOTICE "%s: RX TCP/UDP Checksum Offload ON \n", dev->name); |
| 2219 | #endif |
| 2220 | |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 2221 | #ifdef MV643XX_ETH_COAL |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2222 | printk(KERN_NOTICE "%s: TX and RX Interrupt Coalescing ON \n", |
| 2223 | dev->name); |
| 2224 | #endif |
| 2225 | |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 2226 | #ifdef MV643XX_ETH_NAPI |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2227 | printk(KERN_NOTICE "%s: RX NAPI Enabled \n", dev->name); |
| 2228 | #endif |
| 2229 | |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 2230 | if (mp->tx_desc_sram_size > 0) |
Nicolas DET | b152987 | 2005-10-28 17:46:30 -0700 | [diff] [blame] | 2231 | printk(KERN_NOTICE "%s: Using SRAM\n", dev->name); |
| 2232 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2233 | return 0; |
| 2234 | |
| 2235 | out: |
| 2236 | free_netdev(dev); |
| 2237 | |
| 2238 | return err; |
| 2239 | } |
| 2240 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 2241 | static int mv643xx_eth_remove(struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2242 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 2243 | struct net_device *dev = platform_get_drvdata(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2244 | |
| 2245 | unregister_netdev(dev); |
| 2246 | flush_scheduled_work(); |
| 2247 | |
| 2248 | free_netdev(dev); |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 2249 | platform_set_drvdata(pdev, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2250 | return 0; |
| 2251 | } |
| 2252 | |
Dale Farnsworth | d57ab6f | 2007-03-20 16:38:04 -0700 | [diff] [blame] | 2253 | static void mv643xx_eth_shutdown(struct platform_device *pdev) |
| 2254 | { |
| 2255 | struct net_device *dev = platform_get_drvdata(pdev); |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 2256 | struct mv643xx_eth_private *mp = netdev_priv(dev); |
Dale Farnsworth | d57ab6f | 2007-03-20 16:38:04 -0700 | [diff] [blame] | 2257 | unsigned int port_num = mp->port_num; |
| 2258 | |
| 2259 | /* Mask all interrupts on ethernet port */ |
Lennert Buytenhek | 3cb4667c | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 2260 | wrl(mp, INT_MASK(port_num), 0); |
| 2261 | rdl(mp, INT_MASK(port_num)); |
Dale Farnsworth | d57ab6f | 2007-03-20 16:38:04 -0700 | [diff] [blame] | 2262 | |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 2263 | port_reset(mp); |
Dale Farnsworth | d57ab6f | 2007-03-20 16:38:04 -0700 | [diff] [blame] | 2264 | } |
| 2265 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 2266 | static struct platform_driver mv643xx_eth_driver = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2267 | .probe = mv643xx_eth_probe, |
| 2268 | .remove = mv643xx_eth_remove, |
Dale Farnsworth | d57ab6f | 2007-03-20 16:38:04 -0700 | [diff] [blame] | 2269 | .shutdown = mv643xx_eth_shutdown, |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 2270 | .driver = { |
| 2271 | .name = MV643XX_ETH_NAME, |
Kay Sievers | 72abb46 | 2008-04-18 13:50:44 -0700 | [diff] [blame] | 2272 | .owner = THIS_MODULE, |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 2273 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2274 | }; |
| 2275 | |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 2276 | static int __init mv643xx_eth_init_module(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2277 | { |
| 2278 | int rc; |
| 2279 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 2280 | rc = platform_driver_register(&mv643xx_eth_shared_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2281 | if (!rc) { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 2282 | rc = platform_driver_register(&mv643xx_eth_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2283 | if (rc) |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 2284 | platform_driver_unregister(&mv643xx_eth_shared_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2285 | } |
| 2286 | return rc; |
| 2287 | } |
| 2288 | |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 2289 | static void __exit mv643xx_eth_cleanup_module(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2290 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 2291 | platform_driver_unregister(&mv643xx_eth_driver); |
| 2292 | platform_driver_unregister(&mv643xx_eth_shared_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2293 | } |
| 2294 | |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 2295 | module_init(mv643xx_eth_init_module); |
| 2296 | module_exit(mv643xx_eth_cleanup_module); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2297 | |
| 2298 | MODULE_LICENSE("GPL"); |
| 2299 | MODULE_AUTHOR( "Rabeeh Khoury, Assaf Hoffman, Matthew Dharm, Manish Lachwani" |
| 2300 | " and Dale Farnsworth"); |
| 2301 | MODULE_DESCRIPTION("Ethernet driver for Marvell MV643XX"); |
Kay Sievers | 72abb46 | 2008-04-18 13:50:44 -0700 | [diff] [blame] | 2302 | MODULE_ALIAS("platform:" MV643XX_ETH_NAME); |
| 2303 | MODULE_ALIAS("platform:" MV643XX_ETH_SHARED_NAME); |