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