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