Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Lennert Buytenhek | 9c1bbdf | 2007-10-19 04:11:03 +0200 | [diff] [blame] | 2 | * Driver for Marvell Discovery (MV643XX) and Marvell Orion ethernet ports |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * Copyright (C) 2002 Matthew Dharm <mdharm@momenco.com> |
| 4 | * |
| 5 | * Based on the 64360 driver from: |
Lennert Buytenhek | 4547fa6 | 2008-03-18 11:40:14 -0700 | [diff] [blame] | 6 | * Copyright (C) 2002 Rabeeh Khoury <rabeeh@galileo.co.il> |
| 7 | * Rabeeh Khoury <rabeeh@marvell.com> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | * |
| 9 | * Copyright (C) 2003 PMC-Sierra, Inc., |
Olaf Hering | 3bb8a18a | 2006-01-05 22:45:45 -0800 | [diff] [blame] | 10 | * written by Manish Lachwani |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | * |
| 12 | * Copyright (C) 2003 Ralf Baechle <ralf@linux-mips.org> |
| 13 | * |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 14 | * Copyright (C) 2004-2006 MontaVista Software, Inc. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | * Dale Farnsworth <dale@farnsworth.org> |
| 16 | * |
| 17 | * Copyright (C) 2004 Steven J. Hill <sjhill1@rockwellcollins.com> |
| 18 | * <sjhill@realitydiluted.com> |
| 19 | * |
Lennert Buytenhek | 4547fa6 | 2008-03-18 11:40:14 -0700 | [diff] [blame] | 20 | * Copyright (C) 2007-2008 Marvell Semiconductor |
| 21 | * Lennert Buytenhek <buytenh@marvell.com> |
| 22 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | * This program is free software; you can redistribute it and/or |
| 24 | * modify it under the terms of the GNU General Public License |
| 25 | * as published by the Free Software Foundation; either version 2 |
| 26 | * of the License, or (at your option) any later version. |
| 27 | * |
| 28 | * This program is distributed in the hope that it will be useful, |
| 29 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 30 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 31 | * GNU General Public License for more details. |
| 32 | * |
| 33 | * You should have received a copy of the GNU General Public License |
| 34 | * along with this program; if not, write to the Free Software |
| 35 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 36 | */ |
Lennert Buytenhek | a779d38 | 2008-06-01 00:54:05 +0200 | [diff] [blame] | 37 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | #include <linux/init.h> |
| 39 | #include <linux/dma-mapping.h> |
Al Viro | b6298c2 | 2006-01-18 19:35:54 -0500 | [diff] [blame] | 40 | #include <linux/in.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | #include <linux/tcp.h> |
| 42 | #include <linux/udp.h> |
| 43 | #include <linux/etherdevice.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | #include <linux/delay.h> |
| 45 | #include <linux/ethtool.h> |
Russell King | d052d1b | 2005-10-29 19:07:23 +0100 | [diff] [blame] | 46 | #include <linux/platform_device.h> |
Lennert Buytenhek | fbd6a75 | 2007-10-19 16:03:46 +0200 | [diff] [blame] | 47 | #include <linux/module.h> |
| 48 | #include <linux/kernel.h> |
| 49 | #include <linux/spinlock.h> |
| 50 | #include <linux/workqueue.h> |
| 51 | #include <linux/mii.h> |
Lennert Buytenhek | fbd6a75 | 2007-10-19 16:03:46 +0200 | [diff] [blame] | 52 | #include <linux/mv643xx_eth.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | #include <asm/io.h> |
| 54 | #include <asm/types.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | #include <asm/system.h> |
Lennert Buytenhek | fbd6a75 | 2007-10-19 16:03:46 +0200 | [diff] [blame] | 56 | |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 57 | static char mv643xx_driver_name[] = "mv643xx_eth"; |
| 58 | static char mv643xx_driver_version[] = "1.0"; |
| 59 | |
Lennert Buytenhek | fbd6a75 | 2007-10-19 16:03:46 +0200 | [diff] [blame] | 60 | #define MV643XX_CHECKSUM_OFFLOAD_TX |
| 61 | #define MV643XX_NAPI |
| 62 | #define MV643XX_TX_FAST_REFILL |
| 63 | #undef MV643XX_COAL |
| 64 | |
Lennert Buytenhek | fbd6a75 | 2007-10-19 16:03:46 +0200 | [diff] [blame] | 65 | #define MV643XX_TX_COAL 100 |
| 66 | #ifdef MV643XX_COAL |
| 67 | #define MV643XX_RX_COAL 100 |
| 68 | #endif |
| 69 | |
| 70 | #ifdef MV643XX_CHECKSUM_OFFLOAD_TX |
| 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)) |
| 106 | #define TXQ_COMMAND(p) (0x0448 + ((p) << 10)) |
| 107 | #define TX_BW_MTU(p) (0x0458 + ((p) << 10)) |
| 108 | #define INT_CAUSE(p) (0x0460 + ((p) << 10)) |
Lennert Buytenhek | 073a345 | 2008-06-01 02:00:31 +0200 | [diff] [blame] | 109 | #define INT_RX 0x00000804 |
| 110 | #define INT_EXT 0x00000002 |
Lennert Buytenhek | 3cb4667 | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 111 | #define INT_CAUSE_EXT(p) (0x0464 + ((p) << 10)) |
Lennert Buytenhek | 073a345 | 2008-06-01 02:00:31 +0200 | [diff] [blame] | 112 | #define INT_EXT_LINK 0x00100000 |
| 113 | #define INT_EXT_PHY 0x00010000 |
| 114 | #define INT_EXT_TX_ERROR_0 0x00000100 |
| 115 | #define INT_EXT_TX_0 0x00000001 |
| 116 | #define INT_EXT_TX 0x00000101 |
Lennert Buytenhek | 3cb4667 | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 117 | #define INT_MASK(p) (0x0468 + ((p) << 10)) |
| 118 | #define INT_MASK_EXT(p) (0x046c + ((p) << 10)) |
| 119 | #define TX_FIFO_URGENT_THRESHOLD(p) (0x0474 + ((p) << 10)) |
| 120 | #define RXQ_CURRENT_DESC_PTR(p) (0x060c + ((p) << 10)) |
| 121 | #define RXQ_COMMAND(p) (0x0680 + ((p) << 10)) |
| 122 | #define TXQ_CURRENT_DESC_PTR(p) (0x06c0 + ((p) << 10)) |
| 123 | #define MIB_COUNTERS(p) (0x1000 + ((p) << 7)) |
| 124 | #define SPECIAL_MCAST_TABLE(p) (0x1400 + ((p) << 10)) |
| 125 | #define OTHER_MCAST_TABLE(p) (0x1500 + ((p) << 10)) |
| 126 | #define UNICAST_TABLE(p) (0x1600 + ((p) << 10)) |
Lennert Buytenhek | fbd6a75 | 2007-10-19 16:03:46 +0200 | [diff] [blame] | 127 | |
Lennert Buytenhek | 2679a55 | 2008-06-01 01:18:58 +0200 | [diff] [blame] | 128 | |
| 129 | /* |
| 130 | * SDMA configuration register. |
| 131 | */ |
Lennert Buytenhek | fbd6a75 | 2007-10-19 16:03:46 +0200 | [diff] [blame] | 132 | #define RX_BURST_SIZE_4_64BIT (2 << 1) |
Lennert Buytenhek | fbd6a75 | 2007-10-19 16:03:46 +0200 | [diff] [blame] | 133 | #define BLM_RX_NO_SWAP (1 << 4) |
Lennert Buytenhek | fbd6a75 | 2007-10-19 16:03:46 +0200 | [diff] [blame] | 134 | #define BLM_TX_NO_SWAP (1 << 5) |
Lennert Buytenhek | fbd6a75 | 2007-10-19 16:03:46 +0200 | [diff] [blame] | 135 | #define TX_BURST_SIZE_4_64BIT (2 << 22) |
Lennert Buytenhek | fbd6a75 | 2007-10-19 16:03:46 +0200 | [diff] [blame] | 136 | |
| 137 | #if defined(__BIG_ENDIAN) |
| 138 | #define PORT_SDMA_CONFIG_DEFAULT_VALUE \ |
| 139 | RX_BURST_SIZE_4_64BIT | \ |
Lennert Buytenhek | fbd6a75 | 2007-10-19 16:03:46 +0200 | [diff] [blame] | 140 | TX_BURST_SIZE_4_64BIT |
| 141 | #elif defined(__LITTLE_ENDIAN) |
| 142 | #define PORT_SDMA_CONFIG_DEFAULT_VALUE \ |
| 143 | RX_BURST_SIZE_4_64BIT | \ |
| 144 | BLM_RX_NO_SWAP | \ |
| 145 | BLM_TX_NO_SWAP | \ |
Lennert Buytenhek | fbd6a75 | 2007-10-19 16:03:46 +0200 | [diff] [blame] | 146 | TX_BURST_SIZE_4_64BIT |
| 147 | #else |
| 148 | #error One of __BIG_ENDIAN or __LITTLE_ENDIAN must be defined |
| 149 | #endif |
| 150 | |
Lennert Buytenhek | 2beff77 | 2008-06-01 01:22:37 +0200 | [diff] [blame] | 151 | |
| 152 | /* |
| 153 | * Port serial control register. |
| 154 | */ |
| 155 | #define SET_MII_SPEED_TO_100 (1 << 24) |
| 156 | #define SET_GMII_SPEED_TO_1000 (1 << 23) |
| 157 | #define SET_FULL_DUPLEX_MODE (1 << 21) |
Lennert Buytenhek | fbd6a75 | 2007-10-19 16:03:46 +0200 | [diff] [blame] | 158 | #define MAX_RX_PACKET_1522BYTE (1 << 17) |
Lennert Buytenhek | fbd6a75 | 2007-10-19 16:03:46 +0200 | [diff] [blame] | 159 | #define MAX_RX_PACKET_9700BYTE (5 << 17) |
| 160 | #define MAX_RX_PACKET_MASK (7 << 17) |
Lennert Buytenhek | 2beff77 | 2008-06-01 01:22:37 +0200 | [diff] [blame] | 161 | #define DISABLE_AUTO_NEG_SPEED_GMII (1 << 13) |
| 162 | #define DO_NOT_FORCE_LINK_FAIL (1 << 10) |
| 163 | #define SERIAL_PORT_CONTROL_RESERVED (1 << 9) |
| 164 | #define DISABLE_AUTO_NEG_FOR_FLOW_CTRL (1 << 3) |
| 165 | #define DISABLE_AUTO_NEG_FOR_DUPLEX (1 << 2) |
| 166 | #define FORCE_LINK_PASS (1 << 1) |
| 167 | #define SERIAL_PORT_ENABLE (1 << 0) |
Lennert Buytenhek | fbd6a75 | 2007-10-19 16:03:46 +0200 | [diff] [blame] | 168 | |
Lennert Buytenhek | fbd6a75 | 2007-10-19 16:03:46 +0200 | [diff] [blame] | 169 | #define PORT_DEFAULT_TRANSMIT_QUEUE_SIZE 800 |
| 170 | #define PORT_DEFAULT_RECEIVE_QUEUE_SIZE 400 |
| 171 | |
Lennert Buytenhek | fbd6a75 | 2007-10-19 16:03:46 +0200 | [diff] [blame] | 172 | /* Port serial status reg (PSR) */ |
| 173 | #define ETH_INTERFACE_PCM 0x00000001 |
| 174 | #define ETH_LINK_IS_UP 0x00000002 |
| 175 | #define ETH_PORT_AT_FULL_DUPLEX 0x00000004 |
| 176 | #define ETH_RX_FLOW_CTRL_ENABLED 0x00000008 |
| 177 | #define ETH_GMII_SPEED_1000 0x00000010 |
| 178 | #define ETH_MII_SPEED_100 0x00000020 |
| 179 | #define ETH_TX_IN_PROGRESS 0x00000080 |
| 180 | #define ETH_BYPASS_ACTIVE 0x00000100 |
| 181 | #define ETH_PORT_AT_PARTITION_STATE 0x00000200 |
| 182 | #define ETH_PORT_TX_FIFO_EMPTY 0x00000400 |
| 183 | |
| 184 | /* SMI reg */ |
| 185 | #define ETH_SMI_BUSY 0x10000000 /* 0 - Write, 1 - Read */ |
| 186 | #define ETH_SMI_READ_VALID 0x08000000 /* 0 - Write, 1 - Read */ |
| 187 | #define ETH_SMI_OPCODE_WRITE 0 /* Completion of Read */ |
| 188 | #define ETH_SMI_OPCODE_READ 0x04000000 /* Operation is in progress */ |
| 189 | |
| 190 | /* Interrupt Cause Register Bit Definitions */ |
| 191 | |
| 192 | /* SDMA command status fields macros */ |
| 193 | |
| 194 | /* Tx & Rx descriptors status */ |
| 195 | #define ETH_ERROR_SUMMARY 0x00000001 |
| 196 | |
| 197 | /* Tx & Rx descriptors command */ |
| 198 | #define ETH_BUFFER_OWNED_BY_DMA 0x80000000 |
| 199 | |
| 200 | /* Tx descriptors status */ |
| 201 | #define ETH_LC_ERROR 0 |
| 202 | #define ETH_UR_ERROR 0x00000002 |
| 203 | #define ETH_RL_ERROR 0x00000004 |
| 204 | #define ETH_LLC_SNAP_FORMAT 0x00000200 |
| 205 | |
| 206 | /* Rx descriptors status */ |
| 207 | #define ETH_OVERRUN_ERROR 0x00000002 |
| 208 | #define ETH_MAX_FRAME_LENGTH_ERROR 0x00000004 |
| 209 | #define ETH_RESOURCE_ERROR 0x00000006 |
| 210 | #define ETH_VLAN_TAGGED 0x00080000 |
| 211 | #define ETH_BPDU_FRAME 0x00100000 |
| 212 | #define ETH_UDP_FRAME_OVER_IP_V_4 0x00200000 |
| 213 | #define ETH_OTHER_FRAME_TYPE 0x00400000 |
| 214 | #define ETH_LAYER_2_IS_ETH_V_2 0x00800000 |
| 215 | #define ETH_FRAME_TYPE_IP_V_4 0x01000000 |
| 216 | #define ETH_FRAME_HEADER_OK 0x02000000 |
| 217 | #define ETH_RX_LAST_DESC 0x04000000 |
| 218 | #define ETH_RX_FIRST_DESC 0x08000000 |
| 219 | #define ETH_UNKNOWN_DESTINATION_ADDR 0x10000000 |
| 220 | #define ETH_RX_ENABLE_INTERRUPT 0x20000000 |
| 221 | #define ETH_LAYER_4_CHECKSUM_OK 0x40000000 |
| 222 | |
| 223 | /* Rx descriptors byte count */ |
| 224 | #define ETH_FRAME_FRAGMENTED 0x00000004 |
| 225 | |
| 226 | /* Tx descriptors command */ |
| 227 | #define ETH_LAYER_4_CHECKSUM_FIRST_DESC 0x00000400 |
| 228 | #define ETH_FRAME_SET_TO_VLAN 0x00008000 |
| 229 | #define ETH_UDP_FRAME 0x00010000 |
| 230 | #define ETH_GEN_TCP_UDP_CHECKSUM 0x00020000 |
| 231 | #define ETH_GEN_IP_V_4_CHECKSUM 0x00040000 |
| 232 | #define ETH_ZERO_PADDING 0x00080000 |
| 233 | #define ETH_TX_LAST_DESC 0x00100000 |
| 234 | #define ETH_TX_FIRST_DESC 0x00200000 |
| 235 | #define ETH_GEN_CRC 0x00400000 |
| 236 | #define ETH_TX_ENABLE_INTERRUPT 0x00800000 |
| 237 | #define ETH_AUTO_MODE 0x40000000 |
| 238 | |
| 239 | #define ETH_TX_IHL_SHIFT 11 |
| 240 | |
| 241 | /* typedefs */ |
| 242 | |
| 243 | typedef enum _eth_func_ret_status { |
| 244 | ETH_OK, /* Returned as expected. */ |
| 245 | ETH_ERROR, /* Fundamental error. */ |
| 246 | ETH_RETRY, /* Could not process request. Try later.*/ |
| 247 | ETH_END_OF_JOB, /* Ring has nothing to process. */ |
| 248 | ETH_QUEUE_FULL, /* Ring resource error. */ |
| 249 | ETH_QUEUE_LAST_RESOURCE /* Ring resources about to exhaust. */ |
| 250 | } ETH_FUNC_RET_STATUS; |
| 251 | |
Lennert Buytenhek | fbd6a75 | 2007-10-19 16:03:46 +0200 | [diff] [blame] | 252 | /* These are for big-endian machines. Little endian needs different |
| 253 | * definitions. |
| 254 | */ |
| 255 | #if defined(__BIG_ENDIAN) |
| 256 | struct eth_rx_desc { |
| 257 | u16 byte_cnt; /* Descriptor buffer byte count */ |
| 258 | u16 buf_size; /* Buffer size */ |
| 259 | u32 cmd_sts; /* Descriptor command status */ |
| 260 | u32 next_desc_ptr; /* Next descriptor pointer */ |
| 261 | u32 buf_ptr; /* Descriptor buffer pointer */ |
| 262 | }; |
| 263 | |
| 264 | struct eth_tx_desc { |
| 265 | u16 byte_cnt; /* buffer byte count */ |
| 266 | u16 l4i_chk; /* CPU provided TCP checksum */ |
| 267 | u32 cmd_sts; /* Command/status field */ |
| 268 | u32 next_desc_ptr; /* Pointer to next descriptor */ |
| 269 | u32 buf_ptr; /* pointer to buffer for this descriptor*/ |
| 270 | }; |
| 271 | #elif defined(__LITTLE_ENDIAN) |
| 272 | struct eth_rx_desc { |
| 273 | u32 cmd_sts; /* Descriptor command status */ |
| 274 | u16 buf_size; /* Buffer size */ |
| 275 | u16 byte_cnt; /* Descriptor buffer byte count */ |
| 276 | u32 buf_ptr; /* Descriptor buffer pointer */ |
| 277 | u32 next_desc_ptr; /* Next descriptor pointer */ |
| 278 | }; |
| 279 | |
| 280 | struct eth_tx_desc { |
| 281 | u32 cmd_sts; /* Command/status field */ |
| 282 | u16 l4i_chk; /* CPU provided TCP checksum */ |
| 283 | u16 byte_cnt; /* buffer byte count */ |
| 284 | u32 buf_ptr; /* pointer to buffer for this descriptor*/ |
| 285 | u32 next_desc_ptr; /* Pointer to next descriptor */ |
| 286 | }; |
| 287 | #else |
| 288 | #error One of __BIG_ENDIAN or __LITTLE_ENDIAN must be defined |
| 289 | #endif |
| 290 | |
| 291 | /* Unified struct for Rx and Tx operations. The user is not required to */ |
| 292 | /* be familier with neither Tx nor Rx descriptors. */ |
| 293 | struct pkt_info { |
| 294 | unsigned short byte_cnt; /* Descriptor buffer byte count */ |
| 295 | unsigned short l4i_chk; /* Tx CPU provided TCP Checksum */ |
| 296 | unsigned int cmd_sts; /* Descriptor command status */ |
| 297 | dma_addr_t buf_ptr; /* Descriptor buffer pointer */ |
| 298 | struct sk_buff *return_info; /* User resource return information */ |
| 299 | }; |
| 300 | |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 301 | |
| 302 | /* global *******************************************************************/ |
| 303 | struct mv643xx_shared_private { |
| 304 | void __iomem *eth_base; |
| 305 | |
| 306 | /* used to protect SMI_REG, which is shared across ports */ |
| 307 | spinlock_t phy_lock; |
| 308 | |
| 309 | u32 win_protect; |
| 310 | |
| 311 | unsigned int t_clk; |
| 312 | }; |
| 313 | |
| 314 | |
| 315 | /* per-port *****************************************************************/ |
Lennert Buytenhek | fbd6a75 | 2007-10-19 16:03:46 +0200 | [diff] [blame] | 316 | struct mv643xx_mib_counters { |
| 317 | u64 good_octets_received; |
| 318 | u32 bad_octets_received; |
| 319 | u32 internal_mac_transmit_err; |
| 320 | u32 good_frames_received; |
| 321 | u32 bad_frames_received; |
| 322 | u32 broadcast_frames_received; |
| 323 | u32 multicast_frames_received; |
| 324 | u32 frames_64_octets; |
| 325 | u32 frames_65_to_127_octets; |
| 326 | u32 frames_128_to_255_octets; |
| 327 | u32 frames_256_to_511_octets; |
| 328 | u32 frames_512_to_1023_octets; |
| 329 | u32 frames_1024_to_max_octets; |
| 330 | u64 good_octets_sent; |
| 331 | u32 good_frames_sent; |
| 332 | u32 excessive_collision; |
| 333 | u32 multicast_frames_sent; |
| 334 | u32 broadcast_frames_sent; |
| 335 | u32 unrec_mac_control_received; |
| 336 | u32 fc_sent; |
| 337 | u32 good_fc_received; |
| 338 | u32 bad_fc_received; |
| 339 | u32 undersize_received; |
| 340 | u32 fragments_received; |
| 341 | u32 oversize_received; |
| 342 | u32 jabber_received; |
| 343 | u32 mac_receive_error; |
| 344 | u32 bad_crc_event; |
| 345 | u32 collision; |
| 346 | u32 late_collision; |
| 347 | }; |
| 348 | |
| 349 | struct mv643xx_private { |
Lennert Buytenhek | fa3959f | 2008-04-24 01:27:02 +0200 | [diff] [blame] | 350 | struct mv643xx_shared_private *shared; |
Lennert Buytenhek | fbd6a75 | 2007-10-19 16:03:46 +0200 | [diff] [blame] | 351 | int port_num; /* User Ethernet port number */ |
| 352 | |
Lennert Buytenhek | ce4e2e4 | 2008-04-24 01:29:59 +0200 | [diff] [blame] | 353 | struct mv643xx_shared_private *shared_smi; |
| 354 | |
Lennert Buytenhek | fbd6a75 | 2007-10-19 16:03:46 +0200 | [diff] [blame] | 355 | u32 rx_sram_addr; /* Base address of rx sram area */ |
| 356 | u32 rx_sram_size; /* Size of rx sram area */ |
| 357 | u32 tx_sram_addr; /* Base address of tx sram area */ |
| 358 | u32 tx_sram_size; /* Size of tx sram area */ |
| 359 | |
| 360 | int rx_resource_err; /* Rx ring resource error flag */ |
| 361 | |
| 362 | /* Tx/Rx rings managment indexes fields. For driver use */ |
| 363 | |
| 364 | /* Next available and first returning Rx resource */ |
| 365 | int rx_curr_desc_q, rx_used_desc_q; |
| 366 | |
| 367 | /* Next available and first returning Tx resource */ |
| 368 | int tx_curr_desc_q, tx_used_desc_q; |
| 369 | |
| 370 | #ifdef MV643XX_TX_FAST_REFILL |
| 371 | u32 tx_clean_threshold; |
| 372 | #endif |
| 373 | |
| 374 | struct eth_rx_desc *p_rx_desc_area; |
| 375 | dma_addr_t rx_desc_dma; |
| 376 | int rx_desc_area_size; |
| 377 | struct sk_buff **rx_skb; |
| 378 | |
| 379 | struct eth_tx_desc *p_tx_desc_area; |
| 380 | dma_addr_t tx_desc_dma; |
| 381 | int tx_desc_area_size; |
| 382 | struct sk_buff **tx_skb; |
| 383 | |
| 384 | struct work_struct tx_timeout_task; |
| 385 | |
| 386 | struct net_device *dev; |
| 387 | struct napi_struct napi; |
| 388 | struct net_device_stats stats; |
| 389 | struct mv643xx_mib_counters mib_counters; |
| 390 | spinlock_t lock; |
| 391 | /* Size of Tx Ring per queue */ |
| 392 | int tx_ring_size; |
| 393 | /* Number of tx descriptors in use */ |
| 394 | int tx_desc_count; |
| 395 | /* Size of Rx Ring per queue */ |
| 396 | int rx_ring_size; |
| 397 | /* Number of rx descriptors in use */ |
| 398 | int rx_desc_count; |
| 399 | |
| 400 | /* |
| 401 | * Used in case RX Ring is empty, which can be caused when |
| 402 | * system does not have resources (skb's) |
| 403 | */ |
| 404 | struct timer_list timeout; |
| 405 | |
| 406 | u32 rx_int_coal; |
| 407 | u32 tx_int_coal; |
| 408 | struct mii_if_info mii; |
| 409 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | |
Lennert Buytenhek | fbd6a75 | 2007-10-19 16:03:46 +0200 | [diff] [blame] | 411 | |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 412 | /* port register accessors **************************************************/ |
Lennert Buytenhek | ec69d65 | 2008-03-18 11:38:05 -0700 | [diff] [blame] | 413 | static inline u32 rdl(struct mv643xx_private *mp, int offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | { |
Lennert Buytenhek | fa3959f | 2008-04-24 01:27:02 +0200 | [diff] [blame] | 415 | return readl(mp->shared->eth_base + offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | } |
| 417 | |
Lennert Buytenhek | ec69d65 | 2008-03-18 11:38:05 -0700 | [diff] [blame] | 418 | static inline void wrl(struct mv643xx_private *mp, int offset, u32 data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | { |
Lennert Buytenhek | fa3959f | 2008-04-24 01:27:02 +0200 | [diff] [blame] | 420 | writel(data, mp->shared->eth_base + offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | } |
| 422 | |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 423 | |
| 424 | /* rxq/txq helper functions *************************************************/ |
| 425 | static void mv643xx_eth_port_enable_rx(struct mv643xx_private *mp, |
| 426 | unsigned int queues) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | { |
Lennert Buytenhek | 3cb4667 | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 428 | wrl(mp, RXQ_COMMAND(mp->port_num), queues); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 429 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 431 | static unsigned int mv643xx_eth_port_disable_rx(struct mv643xx_private *mp) |
| 432 | { |
| 433 | unsigned int port_num = mp->port_num; |
| 434 | u32 queues; |
Lennert Buytenhek | c0d0f2c | 2008-03-18 11:34:34 -0700 | [diff] [blame] | 435 | |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 436 | /* Stop Rx port activity. Check port Rx activity. */ |
Lennert Buytenhek | 3cb4667 | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 437 | queues = rdl(mp, RXQ_COMMAND(port_num)) & 0xFF; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 438 | if (queues) { |
| 439 | /* Issue stop command for active queues only */ |
Lennert Buytenhek | 3cb4667 | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 440 | wrl(mp, RXQ_COMMAND(port_num), (queues << 8)); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 441 | |
| 442 | /* Wait for all Rx activity to terminate. */ |
| 443 | /* Check port cause register that all Rx queues are stopped */ |
Lennert Buytenhek | 3cb4667 | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 444 | while (rdl(mp, RXQ_COMMAND(port_num)) & 0xFF) |
Lennert Buytenhek | e1bea50 | 2008-06-01 01:29:14 +0200 | [diff] [blame] | 445 | udelay(10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | } |
| 447 | |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 448 | return queues; |
| 449 | } |
| 450 | |
| 451 | static void mv643xx_eth_port_enable_tx(struct mv643xx_private *mp, |
| 452 | unsigned int queues) |
| 453 | { |
Lennert Buytenhek | 3cb4667 | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 454 | wrl(mp, TXQ_COMMAND(mp->port_num), queues); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | static unsigned int mv643xx_eth_port_disable_tx(struct mv643xx_private *mp) |
| 458 | { |
| 459 | unsigned int port_num = mp->port_num; |
| 460 | u32 queues; |
| 461 | |
| 462 | /* Stop Tx port activity. Check port Tx activity. */ |
Lennert Buytenhek | 3cb4667 | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 463 | queues = rdl(mp, TXQ_COMMAND(port_num)) & 0xFF; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 464 | if (queues) { |
| 465 | /* Issue stop command for active queues only */ |
Lennert Buytenhek | 3cb4667 | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 466 | wrl(mp, TXQ_COMMAND(port_num), (queues << 8)); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 467 | |
| 468 | /* Wait for all Tx activity to terminate. */ |
| 469 | /* Check port cause register that all Tx queues are stopped */ |
Lennert Buytenhek | 3cb4667 | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 470 | while (rdl(mp, TXQ_COMMAND(port_num)) & 0xFF) |
Lennert Buytenhek | e1bea50 | 2008-06-01 01:29:14 +0200 | [diff] [blame] | 471 | udelay(10); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 472 | |
| 473 | /* Wait for Tx FIFO to empty */ |
Lennert Buytenhek | 3cb4667 | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 474 | while (rdl(mp, PORT_STATUS(port_num)) & ETH_PORT_TX_FIFO_EMPTY) |
Lennert Buytenhek | e1bea50 | 2008-06-01 01:29:14 +0200 | [diff] [blame] | 475 | udelay(10); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 476 | } |
| 477 | |
| 478 | return queues; |
| 479 | } |
| 480 | |
| 481 | |
| 482 | /* rx ***********************************************************************/ |
| 483 | static void mv643xx_eth_free_completed_tx_descs(struct net_device *dev); |
| 484 | |
| 485 | /* |
| 486 | * eth_rx_return_buff - Returns a Rx buffer back to the Rx ring. |
| 487 | * |
| 488 | * DESCRIPTION: |
| 489 | * This routine returns a Rx buffer back to the Rx ring. It retrieves the |
| 490 | * next 'used' descriptor and attached the returned buffer to it. |
| 491 | * In case the Rx ring was in "resource error" condition, where there are |
| 492 | * no available Rx resources, the function resets the resource error flag. |
| 493 | * |
| 494 | * INPUT: |
| 495 | * struct mv643xx_private *mp Ethernet Port Control srtuct. |
| 496 | * struct pkt_info *p_pkt_info Information on returned buffer. |
| 497 | * |
| 498 | * OUTPUT: |
| 499 | * New available Rx resource in Rx descriptor ring. |
| 500 | * |
| 501 | * RETURN: |
| 502 | * ETH_ERROR in case the routine can not access Rx desc ring. |
| 503 | * ETH_OK otherwise. |
| 504 | */ |
| 505 | static ETH_FUNC_RET_STATUS eth_rx_return_buff(struct mv643xx_private *mp, |
| 506 | struct pkt_info *p_pkt_info) |
| 507 | { |
| 508 | int used_rx_desc; /* Where to return Rx resource */ |
| 509 | volatile struct eth_rx_desc *p_used_rx_desc; |
| 510 | unsigned long flags; |
| 511 | |
| 512 | spin_lock_irqsave(&mp->lock, flags); |
| 513 | |
| 514 | /* Get 'used' Rx descriptor */ |
| 515 | used_rx_desc = mp->rx_used_desc_q; |
| 516 | p_used_rx_desc = &mp->p_rx_desc_area[used_rx_desc]; |
| 517 | |
| 518 | p_used_rx_desc->buf_ptr = p_pkt_info->buf_ptr; |
| 519 | p_used_rx_desc->buf_size = p_pkt_info->byte_cnt; |
| 520 | mp->rx_skb[used_rx_desc] = p_pkt_info->return_info; |
| 521 | |
| 522 | /* Flush the write pipe */ |
| 523 | |
| 524 | /* Return the descriptor to DMA ownership */ |
| 525 | wmb(); |
| 526 | p_used_rx_desc->cmd_sts = |
| 527 | ETH_BUFFER_OWNED_BY_DMA | ETH_RX_ENABLE_INTERRUPT; |
| 528 | wmb(); |
| 529 | |
| 530 | /* Move the used descriptor pointer to the next descriptor */ |
| 531 | mp->rx_used_desc_q = (used_rx_desc + 1) % mp->rx_ring_size; |
| 532 | |
| 533 | /* Any Rx return cancels the Rx resource error status */ |
| 534 | mp->rx_resource_err = 0; |
| 535 | |
| 536 | spin_unlock_irqrestore(&mp->lock, flags); |
| 537 | |
| 538 | return ETH_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | } |
| 540 | |
| 541 | /* |
Dale Farnsworth | f78fb47 | 2006-03-03 10:05:26 -0700 | [diff] [blame] | 542 | * mv643xx_eth_rx_refill_descs |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | * |
| 544 | * Fills / refills RX queue on a certain gigabit ethernet port |
| 545 | * |
| 546 | * Input : pointer to ethernet interface network device structure |
| 547 | * Output : N/A |
| 548 | */ |
Dale Farnsworth | f78fb47 | 2006-03-03 10:05:26 -0700 | [diff] [blame] | 549 | static void mv643xx_eth_rx_refill_descs(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | struct mv643xx_private *mp = netdev_priv(dev); |
| 552 | struct pkt_info pkt_info; |
| 553 | struct sk_buff *skb; |
Dale Farnsworth | b44cd57 | 2006-01-16 16:51:22 -0700 | [diff] [blame] | 554 | int unaligned; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | |
Dale Farnsworth | f78fb47 | 2006-03-03 10:05:26 -0700 | [diff] [blame] | 556 | while (mp->rx_desc_count < mp->rx_ring_size) { |
Ralf Baechle | 908b637 | 2007-02-26 19:52:06 +0000 | [diff] [blame] | 557 | skb = dev_alloc_skb(ETH_RX_SKB_SIZE + dma_get_cache_alignment()); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | if (!skb) |
| 559 | break; |
Dale Farnsworth | f98e36f1 | 2006-01-27 01:09:18 -0700 | [diff] [blame] | 560 | mp->rx_desc_count++; |
Ralf Baechle | 908b637 | 2007-02-26 19:52:06 +0000 | [diff] [blame] | 561 | unaligned = (u32)skb->data & (dma_get_cache_alignment() - 1); |
Dale Farnsworth | b44cd57 | 2006-01-16 16:51:22 -0700 | [diff] [blame] | 562 | if (unaligned) |
Ralf Baechle | 908b637 | 2007-02-26 19:52:06 +0000 | [diff] [blame] | 563 | skb_reserve(skb, dma_get_cache_alignment() - unaligned); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | pkt_info.cmd_sts = ETH_RX_ENABLE_INTERRUPT; |
Dale Farnsworth | 7303fde | 2006-03-03 10:03:36 -0700 | [diff] [blame] | 565 | pkt_info.byte_cnt = ETH_RX_SKB_SIZE; |
| 566 | pkt_info.buf_ptr = dma_map_single(NULL, skb->data, |
| 567 | ETH_RX_SKB_SIZE, DMA_FROM_DEVICE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | pkt_info.return_info = skb; |
| 569 | if (eth_rx_return_buff(mp, &pkt_info) != ETH_OK) { |
| 570 | printk(KERN_ERR |
| 571 | "%s: Error allocating RX Ring\n", dev->name); |
| 572 | break; |
| 573 | } |
Dale Farnsworth | 7303fde | 2006-03-03 10:03:36 -0700 | [diff] [blame] | 574 | skb_reserve(skb, ETH_HW_IP_ALIGN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | /* |
| 577 | * If RX ring is empty of SKB, set a timer to try allocating |
Dale Farnsworth | f78fb47 | 2006-03-03 10:05:26 -0700 | [diff] [blame] | 578 | * again at a later time. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | */ |
Dale Farnsworth | f78fb47 | 2006-03-03 10:05:26 -0700 | [diff] [blame] | 580 | if (mp->rx_desc_count == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | printk(KERN_INFO "%s: Rx ring is empty\n", dev->name); |
Dale Farnsworth | f78fb47 | 2006-03-03 10:05:26 -0700 | [diff] [blame] | 582 | mp->timeout.expires = jiffies + (HZ / 10); /* 100 mSec */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | add_timer(&mp->timeout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | } |
| 586 | |
| 587 | /* |
Dale Farnsworth | f78fb47 | 2006-03-03 10:05:26 -0700 | [diff] [blame] | 588 | * mv643xx_eth_rx_refill_descs_timer_wrapper |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | * |
| 590 | * Timer routine to wake up RX queue filling task. This function is |
| 591 | * used only in case the RX queue is empty, and all alloc_skb has |
| 592 | * failed (due to out of memory event). |
| 593 | * |
| 594 | * Input : pointer to ethernet interface network device structure |
| 595 | * Output : N/A |
| 596 | */ |
Dale Farnsworth | f78fb47 | 2006-03-03 10:05:26 -0700 | [diff] [blame] | 597 | 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] | 598 | { |
Dale Farnsworth | f78fb47 | 2006-03-03 10:05:26 -0700 | [diff] [blame] | 599 | mv643xx_eth_rx_refill_descs((struct net_device *)data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 600 | } |
| 601 | |
| 602 | /* |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 603 | * eth_port_receive - Get received information from Rx ring. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | * |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 605 | * DESCRIPTION: |
| 606 | * This routine returns the received data to the caller. There is no |
| 607 | * data copying during routine operation. All information is returned |
| 608 | * using pointer to packet information struct passed from the caller. |
| 609 | * If the routine exhausts Rx ring resources then the resource error flag |
| 610 | * is set. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | * |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 612 | * INPUT: |
| 613 | * struct mv643xx_private *mp Ethernet Port Control srtuct. |
| 614 | * struct pkt_info *p_pkt_info User packet buffer. |
| 615 | * |
| 616 | * OUTPUT: |
| 617 | * Rx ring current and used indexes are updated. |
| 618 | * |
| 619 | * RETURN: |
| 620 | * ETH_ERROR in case the routine can not access Rx desc ring. |
| 621 | * ETH_QUEUE_FULL if Rx ring resources are exhausted. |
| 622 | * ETH_END_OF_JOB if there is no received data. |
| 623 | * ETH_OK otherwise. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | */ |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 625 | static ETH_FUNC_RET_STATUS eth_port_receive(struct mv643xx_private *mp, |
| 626 | struct pkt_info *p_pkt_info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | { |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 628 | int rx_next_curr_desc, rx_curr_desc, rx_used_desc; |
| 629 | volatile struct eth_rx_desc *p_rx_desc; |
| 630 | unsigned int command_status; |
Dale Farnsworth | ff561ee | 2006-03-03 10:02:51 -0700 | [diff] [blame] | 631 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 633 | /* Do not process Rx ring in case of Rx ring resource error */ |
| 634 | if (mp->rx_resource_err) |
| 635 | return ETH_QUEUE_FULL; |
Dale Farnsworth | d344bff | 2007-01-23 09:52:25 -0700 | [diff] [blame] | 636 | |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 637 | spin_lock_irqsave(&mp->lock, flags); |
Dale Farnsworth | d344bff | 2007-01-23 09:52:25 -0700 | [diff] [blame] | 638 | |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 639 | /* Get the Rx Desc ring 'curr and 'used' indexes */ |
| 640 | rx_curr_desc = mp->rx_curr_desc_q; |
| 641 | rx_used_desc = mp->rx_used_desc_q; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 643 | p_rx_desc = &mp->p_rx_desc_area[rx_curr_desc]; |
Dale Farnsworth | ff561ee | 2006-03-03 10:02:51 -0700 | [diff] [blame] | 644 | |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 645 | /* The following parameters are used to save readings from memory */ |
| 646 | command_status = p_rx_desc->cmd_sts; |
| 647 | rmb(); |
Dale Farnsworth | ff561ee | 2006-03-03 10:02:51 -0700 | [diff] [blame] | 648 | |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 649 | /* Nothing to receive... */ |
| 650 | if (command_status & (ETH_BUFFER_OWNED_BY_DMA)) { |
Dale Farnsworth | d344bff | 2007-01-23 09:52:25 -0700 | [diff] [blame] | 651 | spin_unlock_irqrestore(&mp->lock, flags); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 652 | return ETH_END_OF_JOB; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | } |
| 654 | |
Lennert Buytenhek | 0a6cf74d | 2008-06-01 11:16:21 +0200 | [diff] [blame] | 655 | p_pkt_info->byte_cnt = p_rx_desc->byte_cnt - ETH_HW_IP_ALIGN; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 656 | p_pkt_info->cmd_sts = command_status; |
Lennert Buytenhek | 0a6cf74d | 2008-06-01 11:16:21 +0200 | [diff] [blame] | 657 | p_pkt_info->buf_ptr = p_rx_desc->buf_ptr + ETH_HW_IP_ALIGN; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 658 | p_pkt_info->return_info = mp->rx_skb[rx_curr_desc]; |
| 659 | p_pkt_info->l4i_chk = p_rx_desc->buf_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 661 | /* |
| 662 | * Clean the return info field to indicate that the |
| 663 | * packet has been moved to the upper layers |
| 664 | */ |
| 665 | mp->rx_skb[rx_curr_desc] = NULL; |
Dale Farnsworth | ff561ee | 2006-03-03 10:02:51 -0700 | [diff] [blame] | 666 | |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 667 | /* Update current index in data structure */ |
| 668 | rx_next_curr_desc = (rx_curr_desc + 1) % mp->rx_ring_size; |
| 669 | mp->rx_curr_desc_q = rx_next_curr_desc; |
Dale Farnsworth | ff561ee | 2006-03-03 10:02:51 -0700 | [diff] [blame] | 670 | |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 671 | /* Rx descriptors exhausted. Set the Rx ring resource error flag */ |
| 672 | if (rx_next_curr_desc == rx_used_desc) |
| 673 | mp->rx_resource_err = 1; |
| 674 | |
| 675 | spin_unlock_irqrestore(&mp->lock, flags); |
| 676 | |
| 677 | return ETH_OK; |
Dale Farnsworth | ff561ee | 2006-03-03 10:02:51 -0700 | [diff] [blame] | 678 | } |
| 679 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 680 | /* |
| 681 | * mv643xx_eth_receive |
| 682 | * |
| 683 | * This function is forward packets that are received from the port's |
| 684 | * queues toward kernel core or FastRoute them to another interface. |
| 685 | * |
| 686 | * Input : dev - a pointer to the required interface |
| 687 | * max - maximum number to receive (0 means unlimted) |
| 688 | * |
| 689 | * Output : number of served packets |
| 690 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | static int mv643xx_eth_receive_queue(struct net_device *dev, int budget) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 | { |
| 693 | struct mv643xx_private *mp = netdev_priv(dev); |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 694 | struct net_device_stats *stats = &dev->stats; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 695 | unsigned int received_packets = 0; |
| 696 | struct sk_buff *skb; |
| 697 | struct pkt_info pkt_info; |
| 698 | |
Dale Farnsworth | b1dd9ca | 2005-09-01 09:59:23 -0700 | [diff] [blame] | 699 | while (budget-- > 0 && eth_port_receive(mp, &pkt_info) == ETH_OK) { |
Jeff Garzik | 54caf44 | 2006-09-21 00:08:10 -0400 | [diff] [blame] | 700 | dma_unmap_single(NULL, pkt_info.buf_ptr, ETH_RX_SKB_SIZE, |
Dale Farnsworth | 71d2872 | 2006-09-13 09:21:08 -0700 | [diff] [blame] | 701 | DMA_FROM_DEVICE); |
Dale Farnsworth | f98e36f1 | 2006-01-27 01:09:18 -0700 | [diff] [blame] | 702 | mp->rx_desc_count--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | received_packets++; |
Dale Farnsworth | b1dd9ca | 2005-09-01 09:59:23 -0700 | [diff] [blame] | 704 | |
Dale Farnsworth | 468d09f | 2006-03-03 10:04:39 -0700 | [diff] [blame] | 705 | /* |
| 706 | * Update statistics. |
| 707 | * Note byte count includes 4 byte CRC count |
| 708 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 709 | stats->rx_packets++; |
| 710 | stats->rx_bytes += pkt_info.byte_cnt; |
| 711 | skb = pkt_info.return_info; |
| 712 | /* |
| 713 | * In case received a packet without first / last bits on OR |
| 714 | * the error summary bit is on, the packets needs to be dropeed. |
| 715 | */ |
| 716 | if (((pkt_info.cmd_sts |
| 717 | & (ETH_RX_FIRST_DESC | ETH_RX_LAST_DESC)) != |
| 718 | (ETH_RX_FIRST_DESC | ETH_RX_LAST_DESC)) |
| 719 | || (pkt_info.cmd_sts & ETH_ERROR_SUMMARY)) { |
| 720 | stats->rx_dropped++; |
| 721 | if ((pkt_info.cmd_sts & (ETH_RX_FIRST_DESC | |
| 722 | ETH_RX_LAST_DESC)) != |
| 723 | (ETH_RX_FIRST_DESC | ETH_RX_LAST_DESC)) { |
| 724 | if (net_ratelimit()) |
| 725 | printk(KERN_ERR |
| 726 | "%s: Received packet spread " |
| 727 | "on multiple descriptors\n", |
| 728 | dev->name); |
| 729 | } |
| 730 | if (pkt_info.cmd_sts & ETH_ERROR_SUMMARY) |
| 731 | stats->rx_errors++; |
| 732 | |
| 733 | dev_kfree_skb_irq(skb); |
| 734 | } else { |
| 735 | /* |
| 736 | * The -4 is for the CRC in the trailer of the |
| 737 | * received packet |
| 738 | */ |
| 739 | skb_put(skb, pkt_info.byte_cnt - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 740 | |
| 741 | if (pkt_info.cmd_sts & ETH_LAYER_4_CHECKSUM_OK) { |
| 742 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 743 | skb->csum = htons( |
| 744 | (pkt_info.cmd_sts & 0x0007fff8) >> 3); |
| 745 | } |
| 746 | skb->protocol = eth_type_trans(skb, dev); |
| 747 | #ifdef MV643XX_NAPI |
| 748 | netif_receive_skb(skb); |
| 749 | #else |
| 750 | netif_rx(skb); |
| 751 | #endif |
| 752 | } |
Paolo Galtieri | 12ad74f | 2006-01-27 01:03:38 -0700 | [diff] [blame] | 753 | dev->last_rx = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | } |
Dale Farnsworth | f78fb47 | 2006-03-03 10:05:26 -0700 | [diff] [blame] | 755 | mv643xx_eth_rx_refill_descs(dev); /* Fill RX ring with skb's */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | |
| 757 | return received_packets; |
| 758 | } |
| 759 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | #ifdef MV643XX_NAPI |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | /* |
| 762 | * mv643xx_poll |
| 763 | * |
| 764 | * This function is used in case of NAPI |
| 765 | */ |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 766 | static int mv643xx_poll(struct napi_struct *napi, int budget) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 | { |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 768 | struct mv643xx_private *mp = container_of(napi, struct mv643xx_private, napi); |
| 769 | struct net_device *dev = mp->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | unsigned int port_num = mp->port_num; |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 771 | int work_done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | |
| 773 | #ifdef MV643XX_TX_FAST_REFILL |
| 774 | if (++mp->tx_clean_threshold > 5) { |
Dale Farnsworth | ff561ee | 2006-03-03 10:02:51 -0700 | [diff] [blame] | 775 | mv643xx_eth_free_completed_tx_descs(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 776 | mp->tx_clean_threshold = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | } |
| 778 | #endif |
| 779 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 780 | work_done = 0; |
Lennert Buytenhek | 3cb4667 | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 781 | if ((rdl(mp, RXQ_CURRENT_DESC_PTR(port_num))) |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 782 | != (u32) mp->rx_used_desc_q) |
| 783 | work_done = mv643xx_eth_receive_queue(dev, budget); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 784 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 785 | if (work_done < budget) { |
| 786 | netif_rx_complete(dev, napi); |
Lennert Buytenhek | 3cb4667 | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 787 | wrl(mp, INT_CAUSE(port_num), 0); |
| 788 | wrl(mp, INT_CAUSE_EXT(port_num), 0); |
Lennert Buytenhek | 073a345 | 2008-06-01 02:00:31 +0200 | [diff] [blame] | 789 | wrl(mp, INT_MASK(port_num), INT_RX | INT_EXT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | } |
| 791 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 792 | return work_done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 793 | } |
| 794 | #endif |
| 795 | |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 796 | |
| 797 | /* tx ***********************************************************************/ |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 798 | /** |
| 799 | * has_tiny_unaligned_frags - check if skb has any small, unaligned fragments |
| 800 | * |
| 801 | * Hardware can't handle unaligned fragments smaller than 9 bytes. |
Paul Janzen | f7ea333 | 2006-01-16 16:52:13 -0700 | [diff] [blame] | 802 | * This helper function detects that case. |
| 803 | */ |
| 804 | |
| 805 | static inline unsigned int has_tiny_unaligned_frags(struct sk_buff *skb) |
| 806 | { |
Dale Farnsworth | b4de905 | 2006-01-27 01:04:43 -0700 | [diff] [blame] | 807 | unsigned int frag; |
| 808 | skb_frag_t *fragp; |
Paul Janzen | f7ea333 | 2006-01-16 16:52:13 -0700 | [diff] [blame] | 809 | |
Dale Farnsworth | b4de905 | 2006-01-27 01:04:43 -0700 | [diff] [blame] | 810 | for (frag = 0; frag < skb_shinfo(skb)->nr_frags; frag++) { |
| 811 | fragp = &skb_shinfo(skb)->frags[frag]; |
| 812 | if (fragp->size <= 8 && fragp->page_offset & 0x7) |
| 813 | return 1; |
| 814 | } |
| 815 | return 0; |
Paul Janzen | f7ea333 | 2006-01-16 16:52:13 -0700 | [diff] [blame] | 816 | } |
| 817 | |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 818 | /** |
| 819 | * eth_alloc_tx_desc_index - return the index of the next available tx desc |
| 820 | */ |
| 821 | static int eth_alloc_tx_desc_index(struct mv643xx_private *mp) |
| 822 | { |
| 823 | int tx_desc_curr; |
Paul Janzen | f7ea333 | 2006-01-16 16:52:13 -0700 | [diff] [blame] | 824 | |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 825 | BUG_ON(mp->tx_desc_count >= mp->tx_ring_size); |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 826 | |
Dale Farnsworth | ff561ee | 2006-03-03 10:02:51 -0700 | [diff] [blame] | 827 | tx_desc_curr = mp->tx_curr_desc_q; |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 828 | mp->tx_curr_desc_q = (tx_desc_curr + 1) % mp->tx_ring_size; |
| 829 | |
| 830 | BUG_ON(mp->tx_curr_desc_q == mp->tx_used_desc_q); |
| 831 | |
| 832 | return tx_desc_curr; |
| 833 | } |
| 834 | |
| 835 | /** |
| 836 | * eth_tx_fill_frag_descs - fill tx hw descriptors for an skb's fragments. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 837 | * |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 838 | * Ensure the data for each fragment to be transmitted is mapped properly, |
| 839 | * then fill in descriptors in the tx hw queue. |
| 840 | */ |
| 841 | static void eth_tx_fill_frag_descs(struct mv643xx_private *mp, |
| 842 | struct sk_buff *skb) |
| 843 | { |
| 844 | int frag; |
| 845 | int tx_index; |
| 846 | struct eth_tx_desc *desc; |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 847 | |
| 848 | for (frag = 0; frag < skb_shinfo(skb)->nr_frags; frag++) { |
| 849 | skb_frag_t *this_frag = &skb_shinfo(skb)->frags[frag]; |
| 850 | |
| 851 | tx_index = eth_alloc_tx_desc_index(mp); |
| 852 | desc = &mp->p_tx_desc_area[tx_index]; |
| 853 | |
| 854 | desc->cmd_sts = ETH_BUFFER_OWNED_BY_DMA; |
| 855 | /* Last Frag enables interrupt and frees the skb */ |
| 856 | if (frag == (skb_shinfo(skb)->nr_frags - 1)) { |
| 857 | desc->cmd_sts |= ETH_ZERO_PADDING | |
| 858 | ETH_TX_LAST_DESC | |
| 859 | ETH_TX_ENABLE_INTERRUPT; |
| 860 | mp->tx_skb[tx_index] = skb; |
| 861 | } else |
Al Viro | 0598077 | 2006-05-30 23:59:09 -0400 | [diff] [blame] | 862 | mp->tx_skb[tx_index] = NULL; |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 863 | |
| 864 | desc = &mp->p_tx_desc_area[tx_index]; |
| 865 | desc->l4i_chk = 0; |
| 866 | desc->byte_cnt = this_frag->size; |
| 867 | desc->buf_ptr = dma_map_page(NULL, this_frag->page, |
| 868 | this_frag->page_offset, |
| 869 | this_frag->size, |
| 870 | DMA_TO_DEVICE); |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 871 | } |
| 872 | } |
| 873 | |
Byron Bradley | 324ff2c | 2008-02-04 23:47:15 -0800 | [diff] [blame] | 874 | static inline __be16 sum16_as_be(__sum16 sum) |
| 875 | { |
| 876 | return (__force __be16)sum; |
| 877 | } |
| 878 | |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 879 | /** |
| 880 | * eth_tx_submit_descs_for_skb - submit data from an skb to the tx hw |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 881 | * |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 882 | * Ensure the data for an skb to be transmitted is mapped properly, |
| 883 | * then fill in descriptors in the tx hw queue and start the hardware. |
| 884 | */ |
Dale Farnsworth | ff561ee | 2006-03-03 10:02:51 -0700 | [diff] [blame] | 885 | static void eth_tx_submit_descs_for_skb(struct mv643xx_private *mp, |
| 886 | struct sk_buff *skb) |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 887 | { |
| 888 | int tx_index; |
| 889 | struct eth_tx_desc *desc; |
| 890 | u32 cmd_sts; |
| 891 | int length; |
Dale Farnsworth | ff561ee | 2006-03-03 10:02:51 -0700 | [diff] [blame] | 892 | int nr_frags = skb_shinfo(skb)->nr_frags; |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 893 | |
| 894 | cmd_sts = ETH_TX_FIRST_DESC | ETH_GEN_CRC | ETH_BUFFER_OWNED_BY_DMA; |
| 895 | |
| 896 | tx_index = eth_alloc_tx_desc_index(mp); |
| 897 | desc = &mp->p_tx_desc_area[tx_index]; |
| 898 | |
Dale Farnsworth | ff561ee | 2006-03-03 10:02:51 -0700 | [diff] [blame] | 899 | if (nr_frags) { |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 900 | eth_tx_fill_frag_descs(mp, skb); |
| 901 | |
| 902 | length = skb_headlen(skb); |
Al Viro | 0598077 | 2006-05-30 23:59:09 -0400 | [diff] [blame] | 903 | mp->tx_skb[tx_index] = NULL; |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 904 | } else { |
| 905 | cmd_sts |= ETH_ZERO_PADDING | |
| 906 | ETH_TX_LAST_DESC | |
| 907 | ETH_TX_ENABLE_INTERRUPT; |
| 908 | length = skb->len; |
| 909 | mp->tx_skb[tx_index] = skb; |
| 910 | } |
| 911 | |
| 912 | desc->byte_cnt = length; |
| 913 | 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] | 914 | |
Patrick McHardy | 84fa793 | 2006-08-29 16:44:56 -0700 | [diff] [blame] | 915 | if (skb->ip_summed == CHECKSUM_PARTIAL) { |
Byron Bradley | 324ff2c | 2008-02-04 23:47:15 -0800 | [diff] [blame] | 916 | BUG_ON(skb->protocol != htons(ETH_P_IP)); |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 917 | |
| 918 | cmd_sts |= ETH_GEN_TCP_UDP_CHECKSUM | |
| 919 | ETH_GEN_IP_V_4_CHECKSUM | |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 920 | ip_hdr(skb)->ihl << ETH_TX_IHL_SHIFT; |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 921 | |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 922 | switch (ip_hdr(skb)->protocol) { |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 923 | case IPPROTO_UDP: |
| 924 | cmd_sts |= ETH_UDP_FRAME; |
Byron Bradley | 324ff2c | 2008-02-04 23:47:15 -0800 | [diff] [blame] | 925 | desc->l4i_chk = ntohs(sum16_as_be(udp_hdr(skb)->check)); |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 926 | break; |
| 927 | case IPPROTO_TCP: |
Byron Bradley | 324ff2c | 2008-02-04 23:47:15 -0800 | [diff] [blame] | 928 | desc->l4i_chk = ntohs(sum16_as_be(tcp_hdr(skb)->check)); |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 929 | break; |
| 930 | default: |
| 931 | BUG(); |
| 932 | } |
| 933 | } else { |
| 934 | /* Errata BTS #50, IHL must be 5 if no HW checksum */ |
| 935 | cmd_sts |= 5 << ETH_TX_IHL_SHIFT; |
| 936 | desc->l4i_chk = 0; |
| 937 | } |
| 938 | |
| 939 | /* ensure all other descriptors are written before first cmd_sts */ |
| 940 | wmb(); |
| 941 | desc->cmd_sts = cmd_sts; |
| 942 | |
| 943 | /* ensure all descriptors are written before poking hardware */ |
| 944 | wmb(); |
Lennert Buytenhek | 073a345 | 2008-06-01 02:00:31 +0200 | [diff] [blame] | 945 | mv643xx_eth_port_enable_tx(mp, 1); |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 946 | |
Dale Farnsworth | ff561ee | 2006-03-03 10:02:51 -0700 | [diff] [blame] | 947 | mp->tx_desc_count += nr_frags + 1; |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 948 | } |
| 949 | |
| 950 | /** |
| 951 | * mv643xx_eth_start_xmit - queue an skb to the hardware for transmission |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 952 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 953 | */ |
| 954 | static int mv643xx_eth_start_xmit(struct sk_buff *skb, struct net_device *dev) |
| 955 | { |
| 956 | struct mv643xx_private *mp = netdev_priv(dev); |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 957 | struct net_device_stats *stats = &dev->stats; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 958 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 959 | |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 960 | BUG_ON(netif_queue_stopped(dev)); |
Dale Farnsworth | 9484356 | 2006-04-11 18:24:26 -0700 | [diff] [blame] | 961 | |
Lennert Buytenhek | 4d64e71 | 2008-03-18 11:32:41 -0700 | [diff] [blame] | 962 | if (has_tiny_unaligned_frags(skb) && __skb_linearize(skb)) { |
| 963 | stats->tx_dropped++; |
| 964 | printk(KERN_DEBUG "%s: failed to linearize tiny " |
| 965 | "unaligned fragment\n", dev->name); |
Lennert Buytenhek | c0d0f2c | 2008-03-18 11:34:34 -0700 | [diff] [blame] | 966 | return NETDEV_TX_BUSY; |
Dale Farnsworth | 9484356 | 2006-04-11 18:24:26 -0700 | [diff] [blame] | 967 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 968 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 969 | spin_lock_irqsave(&mp->lock, flags); |
| 970 | |
Lennert Buytenhek | 4d64e71 | 2008-03-18 11:32:41 -0700 | [diff] [blame] | 971 | if (mp->tx_ring_size - mp->tx_desc_count < MAX_DESCS_PER_SKB) { |
| 972 | printk(KERN_ERR "%s: transmit with queue full\n", dev->name); |
| 973 | netif_stop_queue(dev); |
| 974 | spin_unlock_irqrestore(&mp->lock, flags); |
Lennert Buytenhek | c0d0f2c | 2008-03-18 11:34:34 -0700 | [diff] [blame] | 975 | return NETDEV_TX_BUSY; |
Lennert Buytenhek | 4d64e71 | 2008-03-18 11:32:41 -0700 | [diff] [blame] | 976 | } |
| 977 | |
Dale Farnsworth | ff561ee | 2006-03-03 10:02:51 -0700 | [diff] [blame] | 978 | eth_tx_submit_descs_for_skb(mp, skb); |
Dale Farnsworth | e7e381f | 2007-09-14 11:23:16 -0700 | [diff] [blame] | 979 | stats->tx_bytes += skb->len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 980 | stats->tx_packets++; |
| 981 | dev->trans_start = jiffies; |
| 982 | |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 983 | if (mp->tx_ring_size - mp->tx_desc_count < MAX_DESCS_PER_SKB) |
| 984 | netif_stop_queue(dev); |
| 985 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 986 | spin_unlock_irqrestore(&mp->lock, flags); |
| 987 | |
Lennert Buytenhek | c0d0f2c | 2008-03-18 11:34:34 -0700 | [diff] [blame] | 988 | return NETDEV_TX_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 989 | } |
| 990 | |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 991 | |
| 992 | /* mii management interface *************************************************/ |
| 993 | static int ethernet_phy_get(struct mv643xx_private *mp); |
| 994 | |
| 995 | /* |
| 996 | * eth_port_read_smi_reg - Read PHY registers |
| 997 | * |
| 998 | * DESCRIPTION: |
| 999 | * This routine utilize the SMI interface to interact with the PHY in |
| 1000 | * order to perform PHY register read. |
| 1001 | * |
| 1002 | * INPUT: |
| 1003 | * struct mv643xx_private *mp Ethernet Port. |
| 1004 | * unsigned int phy_reg PHY register address offset. |
| 1005 | * unsigned int *value Register value buffer. |
| 1006 | * |
| 1007 | * OUTPUT: |
| 1008 | * Write the value of a specified PHY register into given buffer. |
| 1009 | * |
| 1010 | * RETURN: |
| 1011 | * false if the PHY is busy or read data is not in valid state. |
| 1012 | * true otherwise. |
| 1013 | * |
| 1014 | */ |
| 1015 | static void eth_port_read_smi_reg(struct mv643xx_private *mp, |
| 1016 | unsigned int phy_reg, unsigned int *value) |
| 1017 | { |
| 1018 | void __iomem *smi_reg = mp->shared_smi->eth_base + SMI_REG; |
| 1019 | int phy_addr = ethernet_phy_get(mp); |
| 1020 | unsigned long flags; |
| 1021 | int i; |
| 1022 | |
| 1023 | /* the SMI register is a shared resource */ |
| 1024 | spin_lock_irqsave(&mp->shared_smi->phy_lock, flags); |
| 1025 | |
| 1026 | /* wait for the SMI register to become available */ |
| 1027 | for (i = 0; readl(smi_reg) & ETH_SMI_BUSY; i++) { |
Lennert Buytenhek | e1bea50 | 2008-06-01 01:29:14 +0200 | [diff] [blame] | 1028 | if (i == 1000) { |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1029 | printk("%s: PHY busy timeout\n", mp->dev->name); |
| 1030 | goto out; |
| 1031 | } |
Lennert Buytenhek | e1bea50 | 2008-06-01 01:29:14 +0200 | [diff] [blame] | 1032 | udelay(10); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1033 | } |
| 1034 | |
| 1035 | writel((phy_addr << 16) | (phy_reg << 21) | ETH_SMI_OPCODE_READ, |
| 1036 | smi_reg); |
| 1037 | |
| 1038 | /* now wait for the data to be valid */ |
| 1039 | for (i = 0; !(readl(smi_reg) & ETH_SMI_READ_VALID); i++) { |
Lennert Buytenhek | e1bea50 | 2008-06-01 01:29:14 +0200 | [diff] [blame] | 1040 | if (i == 1000) { |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1041 | printk("%s: PHY read timeout\n", mp->dev->name); |
| 1042 | goto out; |
| 1043 | } |
Lennert Buytenhek | e1bea50 | 2008-06-01 01:29:14 +0200 | [diff] [blame] | 1044 | udelay(10); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1045 | } |
| 1046 | |
| 1047 | *value = readl(smi_reg) & 0xffff; |
| 1048 | out: |
| 1049 | spin_unlock_irqrestore(&mp->shared_smi->phy_lock, flags); |
| 1050 | } |
| 1051 | |
| 1052 | /* |
| 1053 | * eth_port_write_smi_reg - Write to PHY registers |
| 1054 | * |
| 1055 | * DESCRIPTION: |
| 1056 | * This routine utilize the SMI interface to interact with the PHY in |
| 1057 | * order to perform writes to PHY registers. |
| 1058 | * |
| 1059 | * INPUT: |
| 1060 | * struct mv643xx_private *mp Ethernet Port. |
| 1061 | * unsigned int phy_reg PHY register address offset. |
| 1062 | * unsigned int value Register value. |
| 1063 | * |
| 1064 | * OUTPUT: |
| 1065 | * Write the given value to the specified PHY register. |
| 1066 | * |
| 1067 | * RETURN: |
| 1068 | * false if the PHY is busy. |
| 1069 | * true otherwise. |
| 1070 | * |
| 1071 | */ |
| 1072 | static void eth_port_write_smi_reg(struct mv643xx_private *mp, |
| 1073 | unsigned int phy_reg, unsigned int value) |
| 1074 | { |
| 1075 | void __iomem *smi_reg = mp->shared_smi->eth_base + SMI_REG; |
| 1076 | int phy_addr = ethernet_phy_get(mp); |
| 1077 | unsigned long flags; |
| 1078 | int i; |
| 1079 | |
| 1080 | /* the SMI register is a shared resource */ |
| 1081 | spin_lock_irqsave(&mp->shared_smi->phy_lock, flags); |
| 1082 | |
| 1083 | /* wait for the SMI register to become available */ |
| 1084 | for (i = 0; readl(smi_reg) & ETH_SMI_BUSY; i++) { |
Lennert Buytenhek | e1bea50 | 2008-06-01 01:29:14 +0200 | [diff] [blame] | 1085 | if (i == 1000) { |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1086 | printk("%s: PHY busy timeout\n", mp->dev->name); |
| 1087 | goto out; |
| 1088 | } |
Lennert Buytenhek | e1bea50 | 2008-06-01 01:29:14 +0200 | [diff] [blame] | 1089 | udelay(10); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1090 | } |
| 1091 | |
| 1092 | writel((phy_addr << 16) | (phy_reg << 21) | |
| 1093 | ETH_SMI_OPCODE_WRITE | (value & 0xffff), smi_reg); |
| 1094 | out: |
| 1095 | spin_unlock_irqrestore(&mp->shared_smi->phy_lock, flags); |
| 1096 | } |
| 1097 | |
| 1098 | |
| 1099 | /* mib counters *************************************************************/ |
| 1100 | /* |
| 1101 | * eth_clear_mib_counters - Clear all MIB counters |
| 1102 | * |
| 1103 | * DESCRIPTION: |
| 1104 | * This function clears all MIB counters of a specific ethernet port. |
| 1105 | * A read from the MIB counter will reset the counter. |
| 1106 | * |
| 1107 | * INPUT: |
| 1108 | * struct mv643xx_private *mp Ethernet Port. |
| 1109 | * |
| 1110 | * OUTPUT: |
| 1111 | * After reading all MIB counters, the counters resets. |
| 1112 | * |
| 1113 | * RETURN: |
| 1114 | * MIB counter value. |
| 1115 | * |
| 1116 | */ |
| 1117 | static void eth_clear_mib_counters(struct mv643xx_private *mp) |
| 1118 | { |
| 1119 | unsigned int port_num = mp->port_num; |
| 1120 | int i; |
| 1121 | |
| 1122 | /* Perform dummy reads from MIB counters */ |
Lennert Buytenhek | 4b8e365 | 2008-06-01 01:29:58 +0200 | [diff] [blame^] | 1123 | for (i = 0; i < 0x80; i += 4) |
Lennert Buytenhek | 3cb4667 | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 1124 | rdl(mp, MIB_COUNTERS(port_num) + i); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1125 | } |
| 1126 | |
| 1127 | static inline u32 read_mib(struct mv643xx_private *mp, int offset) |
| 1128 | { |
Lennert Buytenhek | 3cb4667 | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 1129 | return rdl(mp, MIB_COUNTERS(mp->port_num) + offset); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1130 | } |
| 1131 | |
| 1132 | static void eth_update_mib_counters(struct mv643xx_private *mp) |
| 1133 | { |
| 1134 | struct mv643xx_mib_counters *p = &mp->mib_counters; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1135 | |
Lennert Buytenhek | 4b8e365 | 2008-06-01 01:29:58 +0200 | [diff] [blame^] | 1136 | p->good_octets_received += read_mib(mp, 0x00); |
| 1137 | p->good_octets_received += (u64)read_mib(mp, 0x04) << 32; |
| 1138 | p->bad_octets_received += read_mib(mp, 0x08); |
| 1139 | p->internal_mac_transmit_err += read_mib(mp, 0x0c); |
| 1140 | p->good_frames_received += read_mib(mp, 0x10); |
| 1141 | p->bad_frames_received += read_mib(mp, 0x14); |
| 1142 | p->broadcast_frames_received += read_mib(mp, 0x18); |
| 1143 | p->multicast_frames_received += read_mib(mp, 0x1c); |
| 1144 | p->frames_64_octets += read_mib(mp, 0x20); |
| 1145 | p->frames_65_to_127_octets += read_mib(mp, 0x24); |
| 1146 | p->frames_128_to_255_octets += read_mib(mp, 0x28); |
| 1147 | p->frames_256_to_511_octets += read_mib(mp, 0x2c); |
| 1148 | p->frames_512_to_1023_octets += read_mib(mp, 0x30); |
| 1149 | p->frames_1024_to_max_octets += read_mib(mp, 0x34); |
| 1150 | p->good_octets_sent += read_mib(mp, 0x38); |
| 1151 | p->good_octets_sent += (u64)read_mib(mp, 0x3c) << 32; |
| 1152 | p->good_frames_sent += read_mib(mp, 0x40); |
| 1153 | p->excessive_collision += read_mib(mp, 0x44); |
| 1154 | p->multicast_frames_sent += read_mib(mp, 0x48); |
| 1155 | p->broadcast_frames_sent += read_mib(mp, 0x4c); |
| 1156 | p->unrec_mac_control_received += read_mib(mp, 0x50); |
| 1157 | p->fc_sent += read_mib(mp, 0x54); |
| 1158 | p->good_fc_received += read_mib(mp, 0x58); |
| 1159 | p->bad_fc_received += read_mib(mp, 0x5c); |
| 1160 | p->undersize_received += read_mib(mp, 0x60); |
| 1161 | p->fragments_received += read_mib(mp, 0x64); |
| 1162 | p->oversize_received += read_mib(mp, 0x68); |
| 1163 | p->jabber_received += read_mib(mp, 0x6c); |
| 1164 | p->mac_receive_error += read_mib(mp, 0x70); |
| 1165 | p->bad_crc_event += read_mib(mp, 0x74); |
| 1166 | p->collision += read_mib(mp, 0x78); |
| 1167 | p->late_collision += read_mib(mp, 0x7c); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1168 | } |
| 1169 | |
| 1170 | |
| 1171 | /* ethtool ******************************************************************/ |
| 1172 | struct mv643xx_stats { |
| 1173 | char stat_string[ETH_GSTRING_LEN]; |
| 1174 | int sizeof_stat; |
| 1175 | int stat_offset; |
| 1176 | }; |
| 1177 | |
| 1178 | #define MV643XX_STAT(m) FIELD_SIZEOF(struct mv643xx_private, m), \ |
| 1179 | offsetof(struct mv643xx_private, m) |
| 1180 | |
| 1181 | static const struct mv643xx_stats mv643xx_gstrings_stats[] = { |
| 1182 | { "rx_packets", MV643XX_STAT(stats.rx_packets) }, |
| 1183 | { "tx_packets", MV643XX_STAT(stats.tx_packets) }, |
| 1184 | { "rx_bytes", MV643XX_STAT(stats.rx_bytes) }, |
| 1185 | { "tx_bytes", MV643XX_STAT(stats.tx_bytes) }, |
| 1186 | { "rx_errors", MV643XX_STAT(stats.rx_errors) }, |
| 1187 | { "tx_errors", MV643XX_STAT(stats.tx_errors) }, |
| 1188 | { "rx_dropped", MV643XX_STAT(stats.rx_dropped) }, |
| 1189 | { "tx_dropped", MV643XX_STAT(stats.tx_dropped) }, |
| 1190 | { "good_octets_received", MV643XX_STAT(mib_counters.good_octets_received) }, |
| 1191 | { "bad_octets_received", MV643XX_STAT(mib_counters.bad_octets_received) }, |
| 1192 | { "internal_mac_transmit_err", MV643XX_STAT(mib_counters.internal_mac_transmit_err) }, |
| 1193 | { "good_frames_received", MV643XX_STAT(mib_counters.good_frames_received) }, |
| 1194 | { "bad_frames_received", MV643XX_STAT(mib_counters.bad_frames_received) }, |
| 1195 | { "broadcast_frames_received", MV643XX_STAT(mib_counters.broadcast_frames_received) }, |
| 1196 | { "multicast_frames_received", MV643XX_STAT(mib_counters.multicast_frames_received) }, |
| 1197 | { "frames_64_octets", MV643XX_STAT(mib_counters.frames_64_octets) }, |
| 1198 | { "frames_65_to_127_octets", MV643XX_STAT(mib_counters.frames_65_to_127_octets) }, |
| 1199 | { "frames_128_to_255_octets", MV643XX_STAT(mib_counters.frames_128_to_255_octets) }, |
| 1200 | { "frames_256_to_511_octets", MV643XX_STAT(mib_counters.frames_256_to_511_octets) }, |
| 1201 | { "frames_512_to_1023_octets", MV643XX_STAT(mib_counters.frames_512_to_1023_octets) }, |
| 1202 | { "frames_1024_to_max_octets", MV643XX_STAT(mib_counters.frames_1024_to_max_octets) }, |
| 1203 | { "good_octets_sent", MV643XX_STAT(mib_counters.good_octets_sent) }, |
| 1204 | { "good_frames_sent", MV643XX_STAT(mib_counters.good_frames_sent) }, |
| 1205 | { "excessive_collision", MV643XX_STAT(mib_counters.excessive_collision) }, |
| 1206 | { "multicast_frames_sent", MV643XX_STAT(mib_counters.multicast_frames_sent) }, |
| 1207 | { "broadcast_frames_sent", MV643XX_STAT(mib_counters.broadcast_frames_sent) }, |
| 1208 | { "unrec_mac_control_received", MV643XX_STAT(mib_counters.unrec_mac_control_received) }, |
| 1209 | { "fc_sent", MV643XX_STAT(mib_counters.fc_sent) }, |
| 1210 | { "good_fc_received", MV643XX_STAT(mib_counters.good_fc_received) }, |
| 1211 | { "bad_fc_received", MV643XX_STAT(mib_counters.bad_fc_received) }, |
| 1212 | { "undersize_received", MV643XX_STAT(mib_counters.undersize_received) }, |
| 1213 | { "fragments_received", MV643XX_STAT(mib_counters.fragments_received) }, |
| 1214 | { "oversize_received", MV643XX_STAT(mib_counters.oversize_received) }, |
| 1215 | { "jabber_received", MV643XX_STAT(mib_counters.jabber_received) }, |
| 1216 | { "mac_receive_error", MV643XX_STAT(mib_counters.mac_receive_error) }, |
| 1217 | { "bad_crc_event", MV643XX_STAT(mib_counters.bad_crc_event) }, |
| 1218 | { "collision", MV643XX_STAT(mib_counters.collision) }, |
| 1219 | { "late_collision", MV643XX_STAT(mib_counters.late_collision) }, |
| 1220 | }; |
| 1221 | |
| 1222 | #define MV643XX_STATS_LEN ARRAY_SIZE(mv643xx_gstrings_stats) |
| 1223 | |
| 1224 | static int mv643xx_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) |
| 1225 | { |
| 1226 | struct mv643xx_private *mp = netdev_priv(dev); |
| 1227 | int err; |
| 1228 | |
| 1229 | spin_lock_irq(&mp->lock); |
| 1230 | err = mii_ethtool_gset(&mp->mii, cmd); |
| 1231 | spin_unlock_irq(&mp->lock); |
| 1232 | |
| 1233 | /* The PHY may support 1000baseT_Half, but the mv643xx does not */ |
| 1234 | cmd->supported &= ~SUPPORTED_1000baseT_Half; |
| 1235 | cmd->advertising &= ~ADVERTISED_1000baseT_Half; |
| 1236 | |
| 1237 | return err; |
| 1238 | } |
| 1239 | |
| 1240 | static int mv643xx_set_settings(struct net_device *dev, struct ethtool_cmd *cmd) |
| 1241 | { |
| 1242 | struct mv643xx_private *mp = netdev_priv(dev); |
| 1243 | int err; |
| 1244 | |
| 1245 | spin_lock_irq(&mp->lock); |
| 1246 | err = mii_ethtool_sset(&mp->mii, cmd); |
| 1247 | spin_unlock_irq(&mp->lock); |
| 1248 | |
| 1249 | return err; |
| 1250 | } |
| 1251 | |
| 1252 | static void mv643xx_get_drvinfo(struct net_device *netdev, |
| 1253 | struct ethtool_drvinfo *drvinfo) |
| 1254 | { |
| 1255 | strncpy(drvinfo->driver, mv643xx_driver_name, 32); |
| 1256 | strncpy(drvinfo->version, mv643xx_driver_version, 32); |
| 1257 | strncpy(drvinfo->fw_version, "N/A", 32); |
| 1258 | strncpy(drvinfo->bus_info, "mv643xx", 32); |
| 1259 | drvinfo->n_stats = MV643XX_STATS_LEN; |
| 1260 | } |
| 1261 | |
| 1262 | static int mv643xx_eth_nway_restart(struct net_device *dev) |
| 1263 | { |
| 1264 | struct mv643xx_private *mp = netdev_priv(dev); |
| 1265 | |
| 1266 | return mii_nway_restart(&mp->mii); |
| 1267 | } |
| 1268 | |
| 1269 | static u32 mv643xx_eth_get_link(struct net_device *dev) |
| 1270 | { |
| 1271 | struct mv643xx_private *mp = netdev_priv(dev); |
| 1272 | |
| 1273 | return mii_link_ok(&mp->mii); |
| 1274 | } |
| 1275 | |
| 1276 | static void mv643xx_get_strings(struct net_device *netdev, uint32_t stringset, |
| 1277 | uint8_t *data) |
| 1278 | { |
| 1279 | int i; |
| 1280 | |
| 1281 | switch(stringset) { |
| 1282 | case ETH_SS_STATS: |
| 1283 | for (i=0; i < MV643XX_STATS_LEN; i++) { |
| 1284 | memcpy(data + i * ETH_GSTRING_LEN, |
| 1285 | mv643xx_gstrings_stats[i].stat_string, |
| 1286 | ETH_GSTRING_LEN); |
| 1287 | } |
| 1288 | break; |
| 1289 | } |
| 1290 | } |
| 1291 | |
| 1292 | static void mv643xx_get_ethtool_stats(struct net_device *netdev, |
| 1293 | struct ethtool_stats *stats, uint64_t *data) |
| 1294 | { |
| 1295 | struct mv643xx_private *mp = netdev->priv; |
| 1296 | int i; |
| 1297 | |
| 1298 | eth_update_mib_counters(mp); |
| 1299 | |
| 1300 | for (i = 0; i < MV643XX_STATS_LEN; i++) { |
| 1301 | char *p = (char *)mp+mv643xx_gstrings_stats[i].stat_offset; |
| 1302 | data[i] = (mv643xx_gstrings_stats[i].sizeof_stat == |
| 1303 | sizeof(uint64_t)) ? *(uint64_t *)p : *(uint32_t *)p; |
| 1304 | } |
| 1305 | } |
| 1306 | |
| 1307 | static int mv643xx_get_sset_count(struct net_device *netdev, int sset) |
| 1308 | { |
| 1309 | switch (sset) { |
| 1310 | case ETH_SS_STATS: |
| 1311 | return MV643XX_STATS_LEN; |
| 1312 | default: |
| 1313 | return -EOPNOTSUPP; |
| 1314 | } |
| 1315 | } |
| 1316 | |
| 1317 | static const struct ethtool_ops mv643xx_ethtool_ops = { |
| 1318 | .get_settings = mv643xx_get_settings, |
| 1319 | .set_settings = mv643xx_set_settings, |
| 1320 | .get_drvinfo = mv643xx_get_drvinfo, |
| 1321 | .get_link = mv643xx_eth_get_link, |
| 1322 | .set_sg = ethtool_op_set_sg, |
| 1323 | .get_sset_count = mv643xx_get_sset_count, |
| 1324 | .get_ethtool_stats = mv643xx_get_ethtool_stats, |
| 1325 | .get_strings = mv643xx_get_strings, |
| 1326 | .nway_reset = mv643xx_eth_nway_restart, |
| 1327 | }; |
| 1328 | |
| 1329 | |
| 1330 | /* address handling *********************************************************/ |
| 1331 | /* |
| 1332 | * eth_port_uc_addr_get - Read the MAC address from the port's hw registers |
| 1333 | */ |
| 1334 | static void eth_port_uc_addr_get(struct mv643xx_private *mp, |
| 1335 | unsigned char *p_addr) |
| 1336 | { |
| 1337 | unsigned int port_num = mp->port_num; |
| 1338 | unsigned int mac_h; |
| 1339 | unsigned int mac_l; |
| 1340 | |
| 1341 | mac_h = rdl(mp, MAC_ADDR_HIGH(port_num)); |
| 1342 | mac_l = rdl(mp, MAC_ADDR_LOW(port_num)); |
| 1343 | |
| 1344 | p_addr[0] = (mac_h >> 24) & 0xff; |
| 1345 | p_addr[1] = (mac_h >> 16) & 0xff; |
| 1346 | p_addr[2] = (mac_h >> 8) & 0xff; |
| 1347 | p_addr[3] = mac_h & 0xff; |
| 1348 | p_addr[4] = (mac_l >> 8) & 0xff; |
| 1349 | p_addr[5] = mac_l & 0xff; |
| 1350 | } |
| 1351 | |
| 1352 | /* |
| 1353 | * eth_port_init_mac_tables - Clear all entrance in the UC, SMC and OMC tables |
| 1354 | * |
| 1355 | * DESCRIPTION: |
| 1356 | * Go through all the DA filter tables (Unicast, Special Multicast & |
| 1357 | * Other Multicast) and set each entry to 0. |
| 1358 | * |
| 1359 | * INPUT: |
| 1360 | * struct mv643xx_private *mp Ethernet Port. |
| 1361 | * |
| 1362 | * OUTPUT: |
| 1363 | * Multicast and Unicast packets are rejected. |
| 1364 | * |
| 1365 | * RETURN: |
| 1366 | * None. |
| 1367 | */ |
| 1368 | static void eth_port_init_mac_tables(struct mv643xx_private *mp) |
| 1369 | { |
| 1370 | unsigned int port_num = mp->port_num; |
| 1371 | int table_index; |
| 1372 | |
| 1373 | /* Clear DA filter unicast table (Ex_dFUT) */ |
| 1374 | for (table_index = 0; table_index <= 0xC; table_index += 4) |
Lennert Buytenhek | 3cb4667 | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 1375 | wrl(mp, UNICAST_TABLE(port_num) + table_index, 0); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1376 | |
| 1377 | for (table_index = 0; table_index <= 0xFC; table_index += 4) { |
| 1378 | /* Clear DA filter special multicast table (Ex_dFSMT) */ |
Lennert Buytenhek | 3cb4667 | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 1379 | wrl(mp, SPECIAL_MCAST_TABLE(port_num) + table_index, 0); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1380 | /* Clear DA filter other multicast table (Ex_dFOMT) */ |
Lennert Buytenhek | 3cb4667 | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 1381 | wrl(mp, OTHER_MCAST_TABLE(port_num) + table_index, 0); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1382 | } |
| 1383 | } |
| 1384 | |
| 1385 | /* |
| 1386 | * The entries in each table are indexed by a hash of a packet's MAC |
| 1387 | * address. One bit in each entry determines whether the packet is |
| 1388 | * accepted. There are 4 entries (each 8 bits wide) in each register |
| 1389 | * of the table. The bits in each entry are defined as follows: |
| 1390 | * 0 Accept=1, Drop=0 |
| 1391 | * 3-1 Queue (ETH_Q0=0) |
| 1392 | * 7-4 Reserved = 0; |
| 1393 | */ |
| 1394 | static void eth_port_set_filter_table_entry(struct mv643xx_private *mp, |
| 1395 | int table, unsigned char entry) |
| 1396 | { |
| 1397 | unsigned int table_reg; |
| 1398 | unsigned int tbl_offset; |
| 1399 | unsigned int reg_offset; |
| 1400 | |
| 1401 | tbl_offset = (entry / 4) * 4; /* Register offset of DA table entry */ |
| 1402 | reg_offset = entry % 4; /* Entry offset within the register */ |
| 1403 | |
| 1404 | /* Set "accepts frame bit" at specified table entry */ |
| 1405 | table_reg = rdl(mp, table + tbl_offset); |
| 1406 | table_reg |= 0x01 << (8 * reg_offset); |
| 1407 | wrl(mp, table + tbl_offset, table_reg); |
| 1408 | } |
| 1409 | |
| 1410 | /* |
| 1411 | * eth_port_uc_addr_set - Write a MAC address into the port's hw registers |
| 1412 | */ |
| 1413 | static void eth_port_uc_addr_set(struct mv643xx_private *mp, |
| 1414 | unsigned char *p_addr) |
| 1415 | { |
| 1416 | unsigned int port_num = mp->port_num; |
| 1417 | unsigned int mac_h; |
| 1418 | unsigned int mac_l; |
| 1419 | int table; |
| 1420 | |
| 1421 | mac_l = (p_addr[4] << 8) | (p_addr[5]); |
| 1422 | mac_h = (p_addr[0] << 24) | (p_addr[1] << 16) | (p_addr[2] << 8) | |
| 1423 | (p_addr[3] << 0); |
| 1424 | |
| 1425 | wrl(mp, MAC_ADDR_LOW(port_num), mac_l); |
| 1426 | wrl(mp, MAC_ADDR_HIGH(port_num), mac_h); |
| 1427 | |
| 1428 | /* Accept frames with this address */ |
Lennert Buytenhek | 3cb4667 | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 1429 | table = UNICAST_TABLE(port_num); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1430 | eth_port_set_filter_table_entry(mp, table, p_addr[5] & 0x0f); |
| 1431 | } |
| 1432 | |
| 1433 | /* |
| 1434 | * mv643xx_eth_update_mac_address |
| 1435 | * |
| 1436 | * Update the MAC address of the port in the address table |
| 1437 | * |
| 1438 | * Input : pointer to ethernet interface network device structure |
| 1439 | * Output : N/A |
| 1440 | */ |
| 1441 | static void mv643xx_eth_update_mac_address(struct net_device *dev) |
| 1442 | { |
| 1443 | struct mv643xx_private *mp = netdev_priv(dev); |
| 1444 | |
| 1445 | eth_port_init_mac_tables(mp); |
| 1446 | eth_port_uc_addr_set(mp, dev->dev_addr); |
| 1447 | } |
| 1448 | |
| 1449 | /* |
| 1450 | * mv643xx_eth_set_mac_address |
| 1451 | * |
| 1452 | * Change the interface's mac address. |
| 1453 | * No special hardware thing should be done because interface is always |
| 1454 | * put in promiscuous mode. |
| 1455 | * |
| 1456 | * Input : pointer to ethernet interface network device structure and |
| 1457 | * a pointer to the designated entry to be added to the cache. |
| 1458 | * Output : zero upon success, negative upon failure |
| 1459 | */ |
| 1460 | static int mv643xx_eth_set_mac_address(struct net_device *dev, void *addr) |
| 1461 | { |
| 1462 | int i; |
| 1463 | |
| 1464 | for (i = 0; i < 6; i++) |
| 1465 | /* +2 is for the offset of the HW addr type */ |
| 1466 | dev->dev_addr[i] = ((unsigned char *)addr)[i + 2]; |
| 1467 | mv643xx_eth_update_mac_address(dev); |
| 1468 | return 0; |
| 1469 | } |
| 1470 | |
| 1471 | /* |
| 1472 | * eth_port_mc_addr - Multicast address settings. |
| 1473 | * |
| 1474 | * The MV device supports multicast using two tables: |
| 1475 | * 1) Special Multicast Table for MAC addresses of the form |
| 1476 | * 0x01-00-5E-00-00-XX (where XX is between 0x00 and 0x_FF). |
| 1477 | * The MAC DA[7:0] bits are used as a pointer to the Special Multicast |
| 1478 | * Table entries in the DA-Filter table. |
| 1479 | * 2) Other Multicast Table for multicast of another type. A CRC-8bit |
| 1480 | * is used as an index to the Other Multicast Table entries in the |
| 1481 | * DA-Filter table. This function calculates the CRC-8bit value. |
| 1482 | * In either case, eth_port_set_filter_table_entry() is then called |
| 1483 | * to set to set the actual table entry. |
| 1484 | */ |
| 1485 | static void eth_port_mc_addr(struct mv643xx_private *mp, unsigned char *p_addr) |
| 1486 | { |
| 1487 | unsigned int port_num = mp->port_num; |
| 1488 | unsigned int mac_h; |
| 1489 | unsigned int mac_l; |
| 1490 | unsigned char crc_result = 0; |
| 1491 | int table; |
| 1492 | int mac_array[48]; |
| 1493 | int crc[8]; |
| 1494 | int i; |
| 1495 | |
| 1496 | if ((p_addr[0] == 0x01) && (p_addr[1] == 0x00) && |
| 1497 | (p_addr[2] == 0x5E) && (p_addr[3] == 0x00) && (p_addr[4] == 0x00)) { |
Lennert Buytenhek | 3cb4667 | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 1498 | table = SPECIAL_MCAST_TABLE(port_num); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1499 | eth_port_set_filter_table_entry(mp, table, p_addr[5]); |
| 1500 | return; |
| 1501 | } |
| 1502 | |
| 1503 | /* Calculate CRC-8 out of the given address */ |
| 1504 | mac_h = (p_addr[0] << 8) | (p_addr[1]); |
| 1505 | mac_l = (p_addr[2] << 24) | (p_addr[3] << 16) | |
| 1506 | (p_addr[4] << 8) | (p_addr[5] << 0); |
| 1507 | |
| 1508 | for (i = 0; i < 32; i++) |
| 1509 | mac_array[i] = (mac_l >> i) & 0x1; |
| 1510 | for (i = 32; i < 48; i++) |
| 1511 | mac_array[i] = (mac_h >> (i - 32)) & 0x1; |
| 1512 | |
| 1513 | crc[0] = mac_array[45] ^ mac_array[43] ^ mac_array[40] ^ mac_array[39] ^ |
| 1514 | mac_array[35] ^ mac_array[34] ^ mac_array[31] ^ mac_array[30] ^ |
| 1515 | mac_array[28] ^ mac_array[23] ^ mac_array[21] ^ mac_array[19] ^ |
| 1516 | mac_array[18] ^ mac_array[16] ^ mac_array[14] ^ mac_array[12] ^ |
| 1517 | mac_array[8] ^ mac_array[7] ^ mac_array[6] ^ mac_array[0]; |
| 1518 | |
| 1519 | crc[1] = mac_array[46] ^ mac_array[45] ^ mac_array[44] ^ mac_array[43] ^ |
| 1520 | mac_array[41] ^ mac_array[39] ^ mac_array[36] ^ mac_array[34] ^ |
| 1521 | mac_array[32] ^ mac_array[30] ^ mac_array[29] ^ mac_array[28] ^ |
| 1522 | mac_array[24] ^ mac_array[23] ^ mac_array[22] ^ mac_array[21] ^ |
| 1523 | mac_array[20] ^ mac_array[18] ^ mac_array[17] ^ mac_array[16] ^ |
| 1524 | mac_array[15] ^ mac_array[14] ^ mac_array[13] ^ mac_array[12] ^ |
| 1525 | mac_array[9] ^ mac_array[6] ^ mac_array[1] ^ mac_array[0]; |
| 1526 | |
| 1527 | crc[2] = mac_array[47] ^ mac_array[46] ^ mac_array[44] ^ mac_array[43] ^ |
| 1528 | mac_array[42] ^ mac_array[39] ^ mac_array[37] ^ mac_array[34] ^ |
| 1529 | mac_array[33] ^ mac_array[29] ^ mac_array[28] ^ mac_array[25] ^ |
| 1530 | mac_array[24] ^ mac_array[22] ^ mac_array[17] ^ mac_array[15] ^ |
| 1531 | mac_array[13] ^ mac_array[12] ^ mac_array[10] ^ mac_array[8] ^ |
| 1532 | mac_array[6] ^ mac_array[2] ^ mac_array[1] ^ mac_array[0]; |
| 1533 | |
| 1534 | crc[3] = mac_array[47] ^ mac_array[45] ^ mac_array[44] ^ mac_array[43] ^ |
| 1535 | mac_array[40] ^ mac_array[38] ^ mac_array[35] ^ mac_array[34] ^ |
| 1536 | mac_array[30] ^ mac_array[29] ^ mac_array[26] ^ mac_array[25] ^ |
| 1537 | mac_array[23] ^ mac_array[18] ^ mac_array[16] ^ mac_array[14] ^ |
| 1538 | mac_array[13] ^ mac_array[11] ^ mac_array[9] ^ mac_array[7] ^ |
| 1539 | mac_array[3] ^ mac_array[2] ^ mac_array[1]; |
| 1540 | |
| 1541 | crc[4] = mac_array[46] ^ mac_array[45] ^ mac_array[44] ^ mac_array[41] ^ |
| 1542 | mac_array[39] ^ mac_array[36] ^ mac_array[35] ^ mac_array[31] ^ |
| 1543 | mac_array[30] ^ mac_array[27] ^ mac_array[26] ^ mac_array[24] ^ |
| 1544 | mac_array[19] ^ mac_array[17] ^ mac_array[15] ^ mac_array[14] ^ |
| 1545 | mac_array[12] ^ mac_array[10] ^ mac_array[8] ^ mac_array[4] ^ |
| 1546 | mac_array[3] ^ mac_array[2]; |
| 1547 | |
| 1548 | crc[5] = mac_array[47] ^ mac_array[46] ^ mac_array[45] ^ mac_array[42] ^ |
| 1549 | mac_array[40] ^ mac_array[37] ^ mac_array[36] ^ mac_array[32] ^ |
| 1550 | mac_array[31] ^ mac_array[28] ^ mac_array[27] ^ mac_array[25] ^ |
| 1551 | mac_array[20] ^ mac_array[18] ^ mac_array[16] ^ mac_array[15] ^ |
| 1552 | mac_array[13] ^ mac_array[11] ^ mac_array[9] ^ mac_array[5] ^ |
| 1553 | mac_array[4] ^ mac_array[3]; |
| 1554 | |
| 1555 | crc[6] = mac_array[47] ^ mac_array[46] ^ mac_array[43] ^ mac_array[41] ^ |
| 1556 | mac_array[38] ^ mac_array[37] ^ mac_array[33] ^ mac_array[32] ^ |
| 1557 | mac_array[29] ^ mac_array[28] ^ mac_array[26] ^ mac_array[21] ^ |
| 1558 | mac_array[19] ^ mac_array[17] ^ mac_array[16] ^ mac_array[14] ^ |
| 1559 | mac_array[12] ^ mac_array[10] ^ mac_array[6] ^ mac_array[5] ^ |
| 1560 | mac_array[4]; |
| 1561 | |
| 1562 | crc[7] = mac_array[47] ^ mac_array[44] ^ mac_array[42] ^ mac_array[39] ^ |
| 1563 | mac_array[38] ^ mac_array[34] ^ mac_array[33] ^ mac_array[30] ^ |
| 1564 | mac_array[29] ^ mac_array[27] ^ mac_array[22] ^ mac_array[20] ^ |
| 1565 | mac_array[18] ^ mac_array[17] ^ mac_array[15] ^ mac_array[13] ^ |
| 1566 | mac_array[11] ^ mac_array[7] ^ mac_array[6] ^ mac_array[5]; |
| 1567 | |
| 1568 | for (i = 0; i < 8; i++) |
| 1569 | crc_result = crc_result | (crc[i] << i); |
| 1570 | |
Lennert Buytenhek | 3cb4667 | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 1571 | table = OTHER_MCAST_TABLE(port_num); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1572 | eth_port_set_filter_table_entry(mp, table, crc_result); |
| 1573 | } |
| 1574 | |
| 1575 | /* |
| 1576 | * Set the entire multicast list based on dev->mc_list. |
| 1577 | */ |
| 1578 | static void eth_port_set_multicast_list(struct net_device *dev) |
| 1579 | { |
| 1580 | |
| 1581 | struct dev_mc_list *mc_list; |
| 1582 | int i; |
| 1583 | int table_index; |
| 1584 | struct mv643xx_private *mp = netdev_priv(dev); |
| 1585 | unsigned int eth_port_num = mp->port_num; |
| 1586 | |
| 1587 | /* If the device is in promiscuous mode or in all multicast mode, |
| 1588 | * we will fully populate both multicast tables with accept. |
| 1589 | * This is guaranteed to yield a match on all multicast addresses... |
| 1590 | */ |
| 1591 | if ((dev->flags & IFF_PROMISC) || (dev->flags & IFF_ALLMULTI)) { |
| 1592 | for (table_index = 0; table_index <= 0xFC; table_index += 4) { |
| 1593 | /* Set all entries in DA filter special multicast |
| 1594 | * table (Ex_dFSMT) |
| 1595 | * Set for ETH_Q0 for now |
| 1596 | * Bits |
| 1597 | * 0 Accept=1, Drop=0 |
| 1598 | * 3-1 Queue ETH_Q0=0 |
| 1599 | * 7-4 Reserved = 0; |
| 1600 | */ |
Lennert Buytenhek | 3cb4667 | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 1601 | wrl(mp, SPECIAL_MCAST_TABLE(eth_port_num) + table_index, 0x01010101); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1602 | |
| 1603 | /* Set all entries in DA filter other multicast |
| 1604 | * table (Ex_dFOMT) |
| 1605 | * Set for ETH_Q0 for now |
| 1606 | * Bits |
| 1607 | * 0 Accept=1, Drop=0 |
| 1608 | * 3-1 Queue ETH_Q0=0 |
| 1609 | * 7-4 Reserved = 0; |
| 1610 | */ |
Lennert Buytenhek | 3cb4667 | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 1611 | wrl(mp, OTHER_MCAST_TABLE(eth_port_num) + table_index, 0x01010101); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1612 | } |
| 1613 | return; |
| 1614 | } |
| 1615 | |
| 1616 | /* We will clear out multicast tables every time we get the list. |
| 1617 | * Then add the entire new list... |
| 1618 | */ |
| 1619 | for (table_index = 0; table_index <= 0xFC; table_index += 4) { |
| 1620 | /* Clear DA filter special multicast table (Ex_dFSMT) */ |
Lennert Buytenhek | 3cb4667 | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 1621 | wrl(mp, SPECIAL_MCAST_TABLE(eth_port_num) + table_index, 0); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1622 | |
| 1623 | /* Clear DA filter other multicast table (Ex_dFOMT) */ |
Lennert Buytenhek | 3cb4667 | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 1624 | wrl(mp, OTHER_MCAST_TABLE(eth_port_num) + table_index, 0); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1625 | } |
| 1626 | |
| 1627 | /* Get pointer to net_device multicast list and add each one... */ |
| 1628 | for (i = 0, mc_list = dev->mc_list; |
| 1629 | (i < 256) && (mc_list != NULL) && (i < dev->mc_count); |
| 1630 | i++, mc_list = mc_list->next) |
| 1631 | if (mc_list->dmi_addrlen == 6) |
| 1632 | eth_port_mc_addr(mp, mc_list->dmi_addr); |
| 1633 | } |
| 1634 | |
| 1635 | /* |
| 1636 | * mv643xx_eth_set_rx_mode |
| 1637 | * |
| 1638 | * Change from promiscuos to regular rx mode |
| 1639 | * |
| 1640 | * Input : pointer to ethernet interface network device structure |
| 1641 | * Output : N/A |
| 1642 | */ |
| 1643 | static void mv643xx_eth_set_rx_mode(struct net_device *dev) |
| 1644 | { |
| 1645 | struct mv643xx_private *mp = netdev_priv(dev); |
| 1646 | u32 config_reg; |
| 1647 | |
Lennert Buytenhek | 3cb4667 | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 1648 | config_reg = rdl(mp, PORT_CONFIG(mp->port_num)); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1649 | if (dev->flags & IFF_PROMISC) |
Lennert Buytenhek | d9a073e | 2008-06-01 01:22:06 +0200 | [diff] [blame] | 1650 | config_reg |= UNICAST_PROMISCUOUS_MODE; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1651 | else |
Lennert Buytenhek | d9a073e | 2008-06-01 01:22:06 +0200 | [diff] [blame] | 1652 | config_reg &= ~UNICAST_PROMISCUOUS_MODE; |
Lennert Buytenhek | 3cb4667 | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 1653 | wrl(mp, PORT_CONFIG(mp->port_num), config_reg); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1654 | |
| 1655 | eth_port_set_multicast_list(dev); |
| 1656 | } |
| 1657 | |
| 1658 | |
| 1659 | /* rx/tx queue initialisation ***********************************************/ |
| 1660 | /* |
| 1661 | * ether_init_rx_desc_ring - Curve a Rx chain desc list and buffer in memory. |
| 1662 | * |
| 1663 | * DESCRIPTION: |
| 1664 | * This function prepares a Rx chained list of descriptors and packet |
| 1665 | * buffers in a form of a ring. The routine must be called after port |
| 1666 | * initialization routine and before port start routine. |
| 1667 | * The Ethernet SDMA engine uses CPU bus addresses to access the various |
| 1668 | * devices in the system (i.e. DRAM). This function uses the ethernet |
| 1669 | * struct 'virtual to physical' routine (set by the user) to set the ring |
| 1670 | * with physical addresses. |
| 1671 | * |
| 1672 | * INPUT: |
| 1673 | * struct mv643xx_private *mp Ethernet Port Control srtuct. |
| 1674 | * |
| 1675 | * OUTPUT: |
| 1676 | * The routine updates the Ethernet port control struct with information |
| 1677 | * regarding the Rx descriptors and buffers. |
| 1678 | * |
| 1679 | * RETURN: |
| 1680 | * None. |
| 1681 | */ |
| 1682 | static void ether_init_rx_desc_ring(struct mv643xx_private *mp) |
| 1683 | { |
| 1684 | volatile struct eth_rx_desc *p_rx_desc; |
| 1685 | int rx_desc_num = mp->rx_ring_size; |
| 1686 | int i; |
| 1687 | |
| 1688 | /* initialize the next_desc_ptr links in the Rx descriptors ring */ |
| 1689 | p_rx_desc = (struct eth_rx_desc *)mp->p_rx_desc_area; |
| 1690 | for (i = 0; i < rx_desc_num; i++) { |
| 1691 | p_rx_desc[i].next_desc_ptr = mp->rx_desc_dma + |
| 1692 | ((i + 1) % rx_desc_num) * sizeof(struct eth_rx_desc); |
| 1693 | } |
| 1694 | |
| 1695 | /* Save Rx desc pointer to driver struct. */ |
| 1696 | mp->rx_curr_desc_q = 0; |
| 1697 | mp->rx_used_desc_q = 0; |
| 1698 | |
| 1699 | mp->rx_desc_area_size = rx_desc_num * sizeof(struct eth_rx_desc); |
| 1700 | } |
| 1701 | |
| 1702 | static void mv643xx_eth_free_rx_rings(struct net_device *dev) |
| 1703 | { |
| 1704 | struct mv643xx_private *mp = netdev_priv(dev); |
| 1705 | int curr; |
| 1706 | |
| 1707 | /* Stop RX Queues */ |
| 1708 | mv643xx_eth_port_disable_rx(mp); |
| 1709 | |
| 1710 | /* Free preallocated skb's on RX rings */ |
| 1711 | for (curr = 0; mp->rx_desc_count && curr < mp->rx_ring_size; curr++) { |
| 1712 | if (mp->rx_skb[curr]) { |
| 1713 | dev_kfree_skb(mp->rx_skb[curr]); |
| 1714 | mp->rx_desc_count--; |
| 1715 | } |
| 1716 | } |
| 1717 | |
| 1718 | if (mp->rx_desc_count) |
| 1719 | printk(KERN_ERR |
| 1720 | "%s: Error in freeing Rx Ring. %d skb's still" |
| 1721 | " stuck in RX Ring - ignoring them\n", dev->name, |
| 1722 | mp->rx_desc_count); |
| 1723 | /* Free RX ring */ |
| 1724 | if (mp->rx_sram_size) |
| 1725 | iounmap(mp->p_rx_desc_area); |
| 1726 | else |
| 1727 | dma_free_coherent(NULL, mp->rx_desc_area_size, |
| 1728 | mp->p_rx_desc_area, mp->rx_desc_dma); |
| 1729 | } |
| 1730 | |
| 1731 | /* |
| 1732 | * ether_init_tx_desc_ring - Curve a Tx chain desc list and buffer in memory. |
| 1733 | * |
| 1734 | * DESCRIPTION: |
| 1735 | * This function prepares a Tx chained list of descriptors and packet |
| 1736 | * buffers in a form of a ring. The routine must be called after port |
| 1737 | * initialization routine and before port start routine. |
| 1738 | * The Ethernet SDMA engine uses CPU bus addresses to access the various |
| 1739 | * devices in the system (i.e. DRAM). This function uses the ethernet |
| 1740 | * struct 'virtual to physical' routine (set by the user) to set the ring |
| 1741 | * with physical addresses. |
| 1742 | * |
| 1743 | * INPUT: |
| 1744 | * struct mv643xx_private *mp Ethernet Port Control srtuct. |
| 1745 | * |
| 1746 | * OUTPUT: |
| 1747 | * The routine updates the Ethernet port control struct with information |
| 1748 | * regarding the Tx descriptors and buffers. |
| 1749 | * |
| 1750 | * RETURN: |
| 1751 | * None. |
| 1752 | */ |
| 1753 | static void ether_init_tx_desc_ring(struct mv643xx_private *mp) |
| 1754 | { |
| 1755 | int tx_desc_num = mp->tx_ring_size; |
| 1756 | struct eth_tx_desc *p_tx_desc; |
| 1757 | int i; |
| 1758 | |
| 1759 | /* Initialize the next_desc_ptr links in the Tx descriptors ring */ |
| 1760 | p_tx_desc = (struct eth_tx_desc *)mp->p_tx_desc_area; |
| 1761 | for (i = 0; i < tx_desc_num; i++) { |
| 1762 | p_tx_desc[i].next_desc_ptr = mp->tx_desc_dma + |
| 1763 | ((i + 1) % tx_desc_num) * sizeof(struct eth_tx_desc); |
| 1764 | } |
| 1765 | |
| 1766 | mp->tx_curr_desc_q = 0; |
| 1767 | mp->tx_used_desc_q = 0; |
| 1768 | |
| 1769 | mp->tx_desc_area_size = tx_desc_num * sizeof(struct eth_tx_desc); |
| 1770 | } |
| 1771 | |
| 1772 | /** |
| 1773 | * mv643xx_eth_free_tx_descs - Free the tx desc data for completed descriptors |
| 1774 | * |
| 1775 | * If force is non-zero, frees uncompleted descriptors as well |
| 1776 | */ |
| 1777 | static int mv643xx_eth_free_tx_descs(struct net_device *dev, int force) |
| 1778 | { |
| 1779 | struct mv643xx_private *mp = netdev_priv(dev); |
| 1780 | struct eth_tx_desc *desc; |
| 1781 | u32 cmd_sts; |
| 1782 | struct sk_buff *skb; |
| 1783 | unsigned long flags; |
| 1784 | int tx_index; |
| 1785 | dma_addr_t addr; |
| 1786 | int count; |
| 1787 | int released = 0; |
| 1788 | |
| 1789 | while (mp->tx_desc_count > 0) { |
| 1790 | spin_lock_irqsave(&mp->lock, flags); |
| 1791 | |
| 1792 | /* tx_desc_count might have changed before acquiring the lock */ |
| 1793 | if (mp->tx_desc_count <= 0) { |
| 1794 | spin_unlock_irqrestore(&mp->lock, flags); |
| 1795 | return released; |
| 1796 | } |
| 1797 | |
| 1798 | tx_index = mp->tx_used_desc_q; |
| 1799 | desc = &mp->p_tx_desc_area[tx_index]; |
| 1800 | cmd_sts = desc->cmd_sts; |
| 1801 | |
| 1802 | if (!force && (cmd_sts & ETH_BUFFER_OWNED_BY_DMA)) { |
| 1803 | spin_unlock_irqrestore(&mp->lock, flags); |
| 1804 | return released; |
| 1805 | } |
| 1806 | |
| 1807 | mp->tx_used_desc_q = (tx_index + 1) % mp->tx_ring_size; |
| 1808 | mp->tx_desc_count--; |
| 1809 | |
| 1810 | addr = desc->buf_ptr; |
| 1811 | count = desc->byte_cnt; |
| 1812 | skb = mp->tx_skb[tx_index]; |
| 1813 | if (skb) |
| 1814 | mp->tx_skb[tx_index] = NULL; |
| 1815 | |
| 1816 | if (cmd_sts & ETH_ERROR_SUMMARY) { |
| 1817 | printk("%s: Error in TX\n", dev->name); |
| 1818 | dev->stats.tx_errors++; |
| 1819 | } |
| 1820 | |
| 1821 | spin_unlock_irqrestore(&mp->lock, flags); |
| 1822 | |
| 1823 | if (cmd_sts & ETH_TX_FIRST_DESC) |
| 1824 | dma_unmap_single(NULL, addr, count, DMA_TO_DEVICE); |
| 1825 | else |
| 1826 | dma_unmap_page(NULL, addr, count, DMA_TO_DEVICE); |
| 1827 | |
| 1828 | if (skb) |
| 1829 | dev_kfree_skb_irq(skb); |
| 1830 | |
| 1831 | released = 1; |
| 1832 | } |
| 1833 | |
| 1834 | return released; |
| 1835 | } |
| 1836 | |
| 1837 | static void mv643xx_eth_free_completed_tx_descs(struct net_device *dev) |
| 1838 | { |
| 1839 | struct mv643xx_private *mp = netdev_priv(dev); |
| 1840 | |
| 1841 | if (mv643xx_eth_free_tx_descs(dev, 0) && |
| 1842 | mp->tx_ring_size - mp->tx_desc_count >= MAX_DESCS_PER_SKB) |
| 1843 | netif_wake_queue(dev); |
| 1844 | } |
| 1845 | |
| 1846 | static void mv643xx_eth_free_all_tx_descs(struct net_device *dev) |
| 1847 | { |
| 1848 | mv643xx_eth_free_tx_descs(dev, 1); |
| 1849 | } |
| 1850 | |
| 1851 | static void mv643xx_eth_free_tx_rings(struct net_device *dev) |
| 1852 | { |
| 1853 | struct mv643xx_private *mp = netdev_priv(dev); |
| 1854 | |
| 1855 | /* Stop Tx Queues */ |
| 1856 | mv643xx_eth_port_disable_tx(mp); |
| 1857 | |
| 1858 | /* Free outstanding skb's on TX ring */ |
| 1859 | mv643xx_eth_free_all_tx_descs(dev); |
| 1860 | |
| 1861 | BUG_ON(mp->tx_used_desc_q != mp->tx_curr_desc_q); |
| 1862 | |
| 1863 | /* Free TX ring */ |
| 1864 | if (mp->tx_sram_size) |
| 1865 | iounmap(mp->p_tx_desc_area); |
| 1866 | else |
| 1867 | dma_free_coherent(NULL, mp->tx_desc_area_size, |
| 1868 | mp->p_tx_desc_area, mp->tx_desc_dma); |
| 1869 | } |
| 1870 | |
| 1871 | |
| 1872 | /* netdev ops and related ***************************************************/ |
| 1873 | static void eth_port_reset(struct mv643xx_private *mp); |
| 1874 | |
| 1875 | /* Set the mv643xx port configuration register for the speed/duplex mode. */ |
| 1876 | static void mv643xx_eth_update_pscr(struct net_device *dev, |
| 1877 | struct ethtool_cmd *ecmd) |
| 1878 | { |
| 1879 | struct mv643xx_private *mp = netdev_priv(dev); |
| 1880 | int port_num = mp->port_num; |
| 1881 | u32 o_pscr, n_pscr; |
| 1882 | unsigned int queues; |
| 1883 | |
Lennert Buytenhek | 3cb4667 | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 1884 | o_pscr = rdl(mp, PORT_SERIAL_CONTROL(port_num)); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1885 | n_pscr = o_pscr; |
| 1886 | |
| 1887 | /* clear speed, duplex and rx buffer size fields */ |
| 1888 | n_pscr &= ~(SET_MII_SPEED_TO_100 | |
| 1889 | SET_GMII_SPEED_TO_1000 | |
| 1890 | SET_FULL_DUPLEX_MODE | |
| 1891 | MAX_RX_PACKET_MASK); |
| 1892 | |
| 1893 | if (ecmd->duplex == DUPLEX_FULL) |
| 1894 | n_pscr |= SET_FULL_DUPLEX_MODE; |
| 1895 | |
| 1896 | if (ecmd->speed == SPEED_1000) |
| 1897 | n_pscr |= SET_GMII_SPEED_TO_1000 | |
| 1898 | MAX_RX_PACKET_9700BYTE; |
| 1899 | else { |
| 1900 | if (ecmd->speed == SPEED_100) |
| 1901 | n_pscr |= SET_MII_SPEED_TO_100; |
| 1902 | n_pscr |= MAX_RX_PACKET_1522BYTE; |
| 1903 | } |
| 1904 | |
| 1905 | if (n_pscr != o_pscr) { |
| 1906 | if ((o_pscr & SERIAL_PORT_ENABLE) == 0) |
Lennert Buytenhek | 3cb4667 | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 1907 | wrl(mp, PORT_SERIAL_CONTROL(port_num), n_pscr); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1908 | else { |
| 1909 | queues = mv643xx_eth_port_disable_tx(mp); |
| 1910 | |
| 1911 | o_pscr &= ~SERIAL_PORT_ENABLE; |
Lennert Buytenhek | 3cb4667 | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 1912 | wrl(mp, PORT_SERIAL_CONTROL(port_num), o_pscr); |
| 1913 | wrl(mp, PORT_SERIAL_CONTROL(port_num), n_pscr); |
| 1914 | wrl(mp, PORT_SERIAL_CONTROL(port_num), n_pscr); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1915 | if (queues) |
| 1916 | mv643xx_eth_port_enable_tx(mp, queues); |
| 1917 | } |
| 1918 | } |
| 1919 | } |
| 1920 | |
| 1921 | /* |
| 1922 | * mv643xx_eth_int_handler |
| 1923 | * |
| 1924 | * Main interrupt handler for the gigbit ethernet ports |
| 1925 | * |
| 1926 | * Input : irq - irq number (not used) |
| 1927 | * dev_id - a pointer to the required interface's data structure |
| 1928 | * regs - not used |
| 1929 | * Output : N/A |
| 1930 | */ |
| 1931 | |
| 1932 | static irqreturn_t mv643xx_eth_int_handler(int irq, void *dev_id) |
| 1933 | { |
| 1934 | struct net_device *dev = (struct net_device *)dev_id; |
| 1935 | struct mv643xx_private *mp = netdev_priv(dev); |
| 1936 | u32 eth_int_cause, eth_int_cause_ext = 0; |
| 1937 | unsigned int port_num = mp->port_num; |
| 1938 | |
| 1939 | /* Read interrupt cause registers */ |
Lennert Buytenhek | 073a345 | 2008-06-01 02:00:31 +0200 | [diff] [blame] | 1940 | eth_int_cause = rdl(mp, INT_CAUSE(port_num)) & (INT_RX | INT_EXT); |
| 1941 | if (eth_int_cause & INT_EXT) { |
Lennert Buytenhek | 3cb4667 | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 1942 | eth_int_cause_ext = rdl(mp, INT_CAUSE_EXT(port_num)) |
Lennert Buytenhek | 073a345 | 2008-06-01 02:00:31 +0200 | [diff] [blame] | 1943 | & (INT_EXT_LINK | INT_EXT_PHY | INT_EXT_TX); |
Lennert Buytenhek | 3cb4667 | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 1944 | wrl(mp, INT_CAUSE_EXT(port_num), ~eth_int_cause_ext); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1945 | } |
| 1946 | |
| 1947 | /* PHY status changed */ |
Lennert Buytenhek | 073a345 | 2008-06-01 02:00:31 +0200 | [diff] [blame] | 1948 | if (eth_int_cause_ext & (INT_EXT_LINK | INT_EXT_PHY)) { |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1949 | struct ethtool_cmd cmd; |
| 1950 | |
| 1951 | if (mii_link_ok(&mp->mii)) { |
| 1952 | mii_ethtool_gset(&mp->mii, &cmd); |
| 1953 | mv643xx_eth_update_pscr(dev, &cmd); |
Lennert Buytenhek | 073a345 | 2008-06-01 02:00:31 +0200 | [diff] [blame] | 1954 | mv643xx_eth_port_enable_tx(mp, 1); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1955 | if (!netif_carrier_ok(dev)) { |
| 1956 | netif_carrier_on(dev); |
| 1957 | if (mp->tx_ring_size - mp->tx_desc_count >= |
| 1958 | MAX_DESCS_PER_SKB) |
| 1959 | netif_wake_queue(dev); |
| 1960 | } |
| 1961 | } else if (netif_carrier_ok(dev)) { |
| 1962 | netif_stop_queue(dev); |
| 1963 | netif_carrier_off(dev); |
| 1964 | } |
| 1965 | } |
| 1966 | |
| 1967 | #ifdef MV643XX_NAPI |
Lennert Buytenhek | 073a345 | 2008-06-01 02:00:31 +0200 | [diff] [blame] | 1968 | if (eth_int_cause & INT_RX) { |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1969 | /* schedule the NAPI poll routine to maintain port */ |
Lennert Buytenhek | 073a345 | 2008-06-01 02:00:31 +0200 | [diff] [blame] | 1970 | wrl(mp, INT_MASK(port_num), 0x00000000); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1971 | |
| 1972 | /* wait for previous write to complete */ |
Lennert Buytenhek | 3cb4667 | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 1973 | rdl(mp, INT_MASK(port_num)); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1974 | |
| 1975 | netif_rx_schedule(dev, &mp->napi); |
| 1976 | } |
| 1977 | #else |
Lennert Buytenhek | 073a345 | 2008-06-01 02:00:31 +0200 | [diff] [blame] | 1978 | if (eth_int_cause & INT_RX) |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1979 | mv643xx_eth_receive_queue(dev, INT_MAX); |
| 1980 | #endif |
Lennert Buytenhek | 073a345 | 2008-06-01 02:00:31 +0200 | [diff] [blame] | 1981 | if (eth_int_cause_ext & INT_EXT_TX) |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1982 | mv643xx_eth_free_completed_tx_descs(dev); |
| 1983 | |
| 1984 | /* |
| 1985 | * If no real interrupt occured, exit. |
| 1986 | * This can happen when using gigE interrupt coalescing mechanism. |
| 1987 | */ |
| 1988 | if ((eth_int_cause == 0x0) && (eth_int_cause_ext == 0x0)) |
| 1989 | return IRQ_NONE; |
| 1990 | |
| 1991 | return IRQ_HANDLED; |
| 1992 | } |
| 1993 | |
| 1994 | /* |
| 1995 | * ethernet_phy_reset - Reset Ethernet port PHY. |
| 1996 | * |
| 1997 | * DESCRIPTION: |
| 1998 | * This routine utilizes the SMI interface to reset the ethernet port PHY. |
| 1999 | * |
| 2000 | * INPUT: |
| 2001 | * struct mv643xx_private *mp Ethernet Port. |
| 2002 | * |
| 2003 | * OUTPUT: |
| 2004 | * The PHY is reset. |
| 2005 | * |
| 2006 | * RETURN: |
| 2007 | * None. |
| 2008 | * |
| 2009 | */ |
| 2010 | static void ethernet_phy_reset(struct mv643xx_private *mp) |
| 2011 | { |
| 2012 | unsigned int phy_reg_data; |
| 2013 | |
| 2014 | /* Reset the PHY */ |
| 2015 | eth_port_read_smi_reg(mp, 0, &phy_reg_data); |
| 2016 | phy_reg_data |= 0x8000; /* Set bit 15 to reset the PHY */ |
| 2017 | eth_port_write_smi_reg(mp, 0, phy_reg_data); |
| 2018 | |
| 2019 | /* wait for PHY to come out of reset */ |
| 2020 | do { |
| 2021 | udelay(1); |
| 2022 | eth_port_read_smi_reg(mp, 0, &phy_reg_data); |
| 2023 | } while (phy_reg_data & 0x8000); |
| 2024 | } |
| 2025 | |
| 2026 | /* |
| 2027 | * eth_port_start - Start the Ethernet port activity. |
| 2028 | * |
| 2029 | * DESCRIPTION: |
| 2030 | * This routine prepares the Ethernet port for Rx and Tx activity: |
| 2031 | * 1. Initialize Tx and Rx Current Descriptor Pointer for each queue that |
| 2032 | * has been initialized a descriptor's ring (using |
| 2033 | * ether_init_tx_desc_ring for Tx and ether_init_rx_desc_ring for Rx) |
| 2034 | * 2. Initialize and enable the Ethernet configuration port by writing to |
| 2035 | * the port's configuration and command registers. |
| 2036 | * 3. Initialize and enable the SDMA by writing to the SDMA's |
| 2037 | * configuration and command registers. After completing these steps, |
| 2038 | * the ethernet port SDMA can starts to perform Rx and Tx activities. |
| 2039 | * |
| 2040 | * Note: Each Rx and Tx queue descriptor's list must be initialized prior |
| 2041 | * to calling this function (use ether_init_tx_desc_ring for Tx queues |
| 2042 | * and ether_init_rx_desc_ring for Rx queues). |
| 2043 | * |
| 2044 | * INPUT: |
| 2045 | * dev - a pointer to the required interface |
| 2046 | * |
| 2047 | * OUTPUT: |
| 2048 | * Ethernet port is ready to receive and transmit. |
| 2049 | * |
| 2050 | * RETURN: |
| 2051 | * None. |
| 2052 | */ |
| 2053 | static void eth_port_start(struct net_device *dev) |
| 2054 | { |
| 2055 | struct mv643xx_private *mp = netdev_priv(dev); |
| 2056 | unsigned int port_num = mp->port_num; |
| 2057 | int tx_curr_desc, rx_curr_desc; |
| 2058 | u32 pscr; |
| 2059 | struct ethtool_cmd ethtool_cmd; |
| 2060 | |
| 2061 | /* Assignment of Tx CTRP of given queue */ |
| 2062 | tx_curr_desc = mp->tx_curr_desc_q; |
Lennert Buytenhek | 3cb4667 | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 2063 | wrl(mp, TXQ_CURRENT_DESC_PTR(port_num), |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2064 | (u32)((struct eth_tx_desc *)mp->tx_desc_dma + tx_curr_desc)); |
| 2065 | |
| 2066 | /* Assignment of Rx CRDP of given queue */ |
| 2067 | rx_curr_desc = mp->rx_curr_desc_q; |
Lennert Buytenhek | 3cb4667 | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 2068 | wrl(mp, RXQ_CURRENT_DESC_PTR(port_num), |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2069 | (u32)((struct eth_rx_desc *)mp->rx_desc_dma + rx_curr_desc)); |
| 2070 | |
| 2071 | /* Add the assigned Ethernet address to the port's address table */ |
| 2072 | eth_port_uc_addr_set(mp, dev->dev_addr); |
| 2073 | |
Lennert Buytenhek | d9a073e | 2008-06-01 01:22:06 +0200 | [diff] [blame] | 2074 | /* |
| 2075 | * Receive all unmatched unicast, TCP, UDP, BPDU and broadcast |
| 2076 | * frames to RX queue #0. |
| 2077 | */ |
| 2078 | wrl(mp, PORT_CONFIG(port_num), 0x00000000); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2079 | |
Lennert Buytenhek | 376489a | 2008-06-01 01:17:44 +0200 | [diff] [blame] | 2080 | /* |
| 2081 | * Treat BPDUs as normal multicasts, and disable partition mode. |
| 2082 | */ |
| 2083 | wrl(mp, PORT_CONFIG_EXT(port_num), 0x00000000); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2084 | |
Lennert Buytenhek | 3cb4667 | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 2085 | pscr = rdl(mp, PORT_SERIAL_CONTROL(port_num)); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2086 | |
| 2087 | pscr &= ~(SERIAL_PORT_ENABLE | FORCE_LINK_PASS); |
Lennert Buytenhek | 3cb4667 | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 2088 | wrl(mp, PORT_SERIAL_CONTROL(port_num), pscr); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2089 | |
| 2090 | pscr |= DISABLE_AUTO_NEG_FOR_FLOW_CTRL | |
| 2091 | DISABLE_AUTO_NEG_SPEED_GMII | |
Lennert Buytenhek | 2beff77 | 2008-06-01 01:22:37 +0200 | [diff] [blame] | 2092 | DISABLE_AUTO_NEG_FOR_DUPLEX | |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2093 | DO_NOT_FORCE_LINK_FAIL | |
| 2094 | SERIAL_PORT_CONTROL_RESERVED; |
| 2095 | |
Lennert Buytenhek | 3cb4667 | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 2096 | wrl(mp, PORT_SERIAL_CONTROL(port_num), pscr); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2097 | |
| 2098 | pscr |= SERIAL_PORT_ENABLE; |
Lennert Buytenhek | 3cb4667 | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 2099 | wrl(mp, PORT_SERIAL_CONTROL(port_num), pscr); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2100 | |
| 2101 | /* Assign port SDMA configuration */ |
Lennert Buytenhek | 3cb4667 | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 2102 | wrl(mp, SDMA_CONFIG(port_num), PORT_SDMA_CONFIG_DEFAULT_VALUE); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2103 | |
| 2104 | /* Enable port Rx. */ |
Lennert Buytenhek | 073a345 | 2008-06-01 02:00:31 +0200 | [diff] [blame] | 2105 | mv643xx_eth_port_enable_rx(mp, 1); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2106 | |
| 2107 | /* Disable port bandwidth limits by clearing MTU register */ |
Lennert Buytenhek | 3cb4667 | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 2108 | wrl(mp, TX_BW_MTU(port_num), 0); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2109 | |
| 2110 | /* save phy settings across reset */ |
| 2111 | mv643xx_get_settings(dev, ðtool_cmd); |
| 2112 | ethernet_phy_reset(mp); |
| 2113 | mv643xx_set_settings(dev, ðtool_cmd); |
| 2114 | } |
| 2115 | |
| 2116 | #ifdef MV643XX_COAL |
| 2117 | |
| 2118 | /* |
| 2119 | * eth_port_set_rx_coal - Sets coalescing interrupt mechanism on RX path |
| 2120 | * |
| 2121 | * DESCRIPTION: |
| 2122 | * This routine sets the RX coalescing interrupt mechanism parameter. |
| 2123 | * This parameter is a timeout counter, that counts in 64 t_clk |
| 2124 | * chunks ; that when timeout event occurs a maskable interrupt |
| 2125 | * occurs. |
| 2126 | * The parameter is calculated using the tClk of the MV-643xx chip |
| 2127 | * , and the required delay of the interrupt in usec. |
| 2128 | * |
| 2129 | * INPUT: |
| 2130 | * struct mv643xx_private *mp Ethernet port |
| 2131 | * unsigned int delay Delay in usec |
| 2132 | * |
| 2133 | * OUTPUT: |
| 2134 | * Interrupt coalescing mechanism value is set in MV-643xx chip. |
| 2135 | * |
| 2136 | * RETURN: |
| 2137 | * The interrupt coalescing value set in the gigE port. |
| 2138 | * |
| 2139 | */ |
| 2140 | static unsigned int eth_port_set_rx_coal(struct mv643xx_private *mp, |
| 2141 | unsigned int delay) |
| 2142 | { |
| 2143 | unsigned int port_num = mp->port_num; |
| 2144 | unsigned int coal = ((mp->shared->t_clk / 1000000) * delay) / 64; |
| 2145 | |
| 2146 | /* Set RX Coalescing mechanism */ |
Lennert Buytenhek | 3cb4667 | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 2147 | wrl(mp, SDMA_CONFIG(port_num), |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2148 | ((coal & 0x3fff) << 8) | |
Lennert Buytenhek | 3cb4667 | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 2149 | (rdl(mp, SDMA_CONFIG(port_num)) |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2150 | & 0xffc000ff)); |
| 2151 | |
| 2152 | return coal; |
| 2153 | } |
| 2154 | #endif |
| 2155 | |
| 2156 | /* |
| 2157 | * eth_port_set_tx_coal - Sets coalescing interrupt mechanism on TX path |
| 2158 | * |
| 2159 | * DESCRIPTION: |
| 2160 | * This routine sets the TX coalescing interrupt mechanism parameter. |
| 2161 | * This parameter is a timeout counter, that counts in 64 t_clk |
| 2162 | * chunks ; that when timeout event occurs a maskable interrupt |
| 2163 | * occurs. |
| 2164 | * The parameter is calculated using the t_cLK frequency of the |
| 2165 | * MV-643xx chip and the required delay in the interrupt in uSec |
| 2166 | * |
| 2167 | * INPUT: |
| 2168 | * struct mv643xx_private *mp Ethernet port |
| 2169 | * unsigned int delay Delay in uSeconds |
| 2170 | * |
| 2171 | * OUTPUT: |
| 2172 | * Interrupt coalescing mechanism value is set in MV-643xx chip. |
| 2173 | * |
| 2174 | * RETURN: |
| 2175 | * The interrupt coalescing value set in the gigE port. |
| 2176 | * |
| 2177 | */ |
| 2178 | static unsigned int eth_port_set_tx_coal(struct mv643xx_private *mp, |
| 2179 | unsigned int delay) |
| 2180 | { |
| 2181 | unsigned int coal = ((mp->shared->t_clk / 1000000) * delay) / 64; |
| 2182 | |
| 2183 | /* Set TX Coalescing mechanism */ |
Lennert Buytenhek | 3cb4667 | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 2184 | wrl(mp, TX_FIFO_URGENT_THRESHOLD(mp->port_num), coal << 4); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2185 | |
| 2186 | return coal; |
| 2187 | } |
| 2188 | |
| 2189 | /* |
| 2190 | * eth_port_init - Initialize the Ethernet port driver |
| 2191 | * |
| 2192 | * DESCRIPTION: |
| 2193 | * This function prepares the ethernet port to start its activity: |
| 2194 | * 1) Completes the ethernet port driver struct initialization toward port |
| 2195 | * start routine. |
| 2196 | * 2) Resets the device to a quiescent state in case of warm reboot. |
| 2197 | * 3) Enable SDMA access to all four DRAM banks as well as internal SRAM. |
| 2198 | * 4) Clean MAC tables. The reset status of those tables is unknown. |
| 2199 | * 5) Set PHY address. |
| 2200 | * Note: Call this routine prior to eth_port_start routine and after |
| 2201 | * setting user values in the user fields of Ethernet port control |
| 2202 | * struct. |
| 2203 | * |
| 2204 | * INPUT: |
| 2205 | * struct mv643xx_private *mp Ethernet port control struct |
| 2206 | * |
| 2207 | * OUTPUT: |
| 2208 | * See description. |
| 2209 | * |
| 2210 | * RETURN: |
| 2211 | * None. |
| 2212 | */ |
| 2213 | static void eth_port_init(struct mv643xx_private *mp) |
| 2214 | { |
| 2215 | mp->rx_resource_err = 0; |
| 2216 | |
| 2217 | eth_port_reset(mp); |
| 2218 | |
| 2219 | eth_port_init_mac_tables(mp); |
| 2220 | } |
| 2221 | |
| 2222 | /* |
| 2223 | * mv643xx_eth_open |
| 2224 | * |
| 2225 | * This function is called when openning the network device. The function |
| 2226 | * should initialize all the hardware, initialize cyclic Rx/Tx |
| 2227 | * descriptors chain and buffers and allocate an IRQ to the network |
| 2228 | * device. |
| 2229 | * |
| 2230 | * Input : a pointer to the network device structure |
| 2231 | * |
| 2232 | * Output : zero of success , nonzero if fails. |
| 2233 | */ |
| 2234 | |
| 2235 | static int mv643xx_eth_open(struct net_device *dev) |
| 2236 | { |
| 2237 | struct mv643xx_private *mp = netdev_priv(dev); |
| 2238 | unsigned int port_num = mp->port_num; |
| 2239 | unsigned int size; |
| 2240 | int err; |
| 2241 | |
| 2242 | /* Clear any pending ethernet port interrupts */ |
Lennert Buytenhek | 3cb4667 | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 2243 | wrl(mp, INT_CAUSE(port_num), 0); |
| 2244 | wrl(mp, INT_CAUSE_EXT(port_num), 0); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2245 | /* wait for previous write to complete */ |
Lennert Buytenhek | 3cb4667 | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 2246 | rdl(mp, INT_CAUSE_EXT(port_num)); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2247 | |
| 2248 | err = request_irq(dev->irq, mv643xx_eth_int_handler, |
| 2249 | IRQF_SHARED | IRQF_SAMPLE_RANDOM, dev->name, dev); |
| 2250 | if (err) { |
| 2251 | printk(KERN_ERR "%s: Can not assign IRQ\n", dev->name); |
| 2252 | return -EAGAIN; |
| 2253 | } |
| 2254 | |
| 2255 | eth_port_init(mp); |
| 2256 | |
| 2257 | memset(&mp->timeout, 0, sizeof(struct timer_list)); |
| 2258 | mp->timeout.function = mv643xx_eth_rx_refill_descs_timer_wrapper; |
| 2259 | mp->timeout.data = (unsigned long)dev; |
| 2260 | |
| 2261 | /* Allocate RX and TX skb rings */ |
| 2262 | mp->rx_skb = kmalloc(sizeof(*mp->rx_skb) * mp->rx_ring_size, |
| 2263 | GFP_KERNEL); |
| 2264 | if (!mp->rx_skb) { |
| 2265 | printk(KERN_ERR "%s: Cannot allocate Rx skb ring\n", dev->name); |
| 2266 | err = -ENOMEM; |
| 2267 | goto out_free_irq; |
| 2268 | } |
| 2269 | mp->tx_skb = kmalloc(sizeof(*mp->tx_skb) * mp->tx_ring_size, |
| 2270 | GFP_KERNEL); |
| 2271 | if (!mp->tx_skb) { |
| 2272 | printk(KERN_ERR "%s: Cannot allocate Tx skb ring\n", dev->name); |
| 2273 | err = -ENOMEM; |
| 2274 | goto out_free_rx_skb; |
| 2275 | } |
| 2276 | |
| 2277 | /* Allocate TX ring */ |
| 2278 | mp->tx_desc_count = 0; |
| 2279 | size = mp->tx_ring_size * sizeof(struct eth_tx_desc); |
| 2280 | mp->tx_desc_area_size = size; |
| 2281 | |
| 2282 | if (mp->tx_sram_size) { |
| 2283 | mp->p_tx_desc_area = ioremap(mp->tx_sram_addr, |
| 2284 | mp->tx_sram_size); |
| 2285 | mp->tx_desc_dma = mp->tx_sram_addr; |
| 2286 | } else |
| 2287 | mp->p_tx_desc_area = dma_alloc_coherent(NULL, size, |
| 2288 | &mp->tx_desc_dma, |
| 2289 | GFP_KERNEL); |
| 2290 | |
| 2291 | if (!mp->p_tx_desc_area) { |
| 2292 | printk(KERN_ERR "%s: Cannot allocate Tx Ring (size %d bytes)\n", |
| 2293 | dev->name, size); |
| 2294 | err = -ENOMEM; |
| 2295 | goto out_free_tx_skb; |
| 2296 | } |
| 2297 | BUG_ON((u32) mp->p_tx_desc_area & 0xf); /* check 16-byte alignment */ |
| 2298 | memset((void *)mp->p_tx_desc_area, 0, mp->tx_desc_area_size); |
| 2299 | |
| 2300 | ether_init_tx_desc_ring(mp); |
| 2301 | |
| 2302 | /* Allocate RX ring */ |
| 2303 | mp->rx_desc_count = 0; |
| 2304 | size = mp->rx_ring_size * sizeof(struct eth_rx_desc); |
| 2305 | mp->rx_desc_area_size = size; |
| 2306 | |
| 2307 | if (mp->rx_sram_size) { |
| 2308 | mp->p_rx_desc_area = ioremap(mp->rx_sram_addr, |
| 2309 | mp->rx_sram_size); |
| 2310 | mp->rx_desc_dma = mp->rx_sram_addr; |
| 2311 | } else |
| 2312 | mp->p_rx_desc_area = dma_alloc_coherent(NULL, size, |
| 2313 | &mp->rx_desc_dma, |
| 2314 | GFP_KERNEL); |
| 2315 | |
| 2316 | if (!mp->p_rx_desc_area) { |
| 2317 | printk(KERN_ERR "%s: Cannot allocate Rx ring (size %d bytes)\n", |
| 2318 | dev->name, size); |
| 2319 | printk(KERN_ERR "%s: Freeing previously allocated TX queues...", |
| 2320 | dev->name); |
| 2321 | if (mp->rx_sram_size) |
| 2322 | iounmap(mp->p_tx_desc_area); |
| 2323 | else |
| 2324 | dma_free_coherent(NULL, mp->tx_desc_area_size, |
| 2325 | mp->p_tx_desc_area, mp->tx_desc_dma); |
| 2326 | err = -ENOMEM; |
| 2327 | goto out_free_tx_skb; |
| 2328 | } |
| 2329 | memset((void *)mp->p_rx_desc_area, 0, size); |
| 2330 | |
| 2331 | ether_init_rx_desc_ring(mp); |
| 2332 | |
| 2333 | mv643xx_eth_rx_refill_descs(dev); /* Fill RX ring with skb's */ |
| 2334 | |
| 2335 | #ifdef MV643XX_NAPI |
| 2336 | napi_enable(&mp->napi); |
| 2337 | #endif |
| 2338 | |
| 2339 | eth_port_start(dev); |
| 2340 | |
| 2341 | /* Interrupt Coalescing */ |
| 2342 | |
| 2343 | #ifdef MV643XX_COAL |
| 2344 | mp->rx_int_coal = |
| 2345 | eth_port_set_rx_coal(mp, MV643XX_RX_COAL); |
| 2346 | #endif |
| 2347 | |
| 2348 | mp->tx_int_coal = |
| 2349 | eth_port_set_tx_coal(mp, MV643XX_TX_COAL); |
| 2350 | |
| 2351 | /* Unmask phy and link status changes interrupts */ |
Lennert Buytenhek | 073a345 | 2008-06-01 02:00:31 +0200 | [diff] [blame] | 2352 | 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] | 2353 | |
| 2354 | /* Unmask RX buffer and TX end interrupt */ |
Lennert Buytenhek | 073a345 | 2008-06-01 02:00:31 +0200 | [diff] [blame] | 2355 | wrl(mp, INT_MASK(port_num), INT_RX | INT_EXT); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2356 | |
| 2357 | return 0; |
| 2358 | |
| 2359 | out_free_tx_skb: |
| 2360 | kfree(mp->tx_skb); |
| 2361 | out_free_rx_skb: |
| 2362 | kfree(mp->rx_skb); |
| 2363 | out_free_irq: |
| 2364 | free_irq(dev->irq, dev); |
| 2365 | |
| 2366 | return err; |
| 2367 | } |
| 2368 | |
| 2369 | /* |
| 2370 | * eth_port_reset - Reset Ethernet port |
| 2371 | * |
| 2372 | * DESCRIPTION: |
| 2373 | * This routine resets the chip by aborting any SDMA engine activity and |
| 2374 | * clearing the MIB counters. The Receiver and the Transmit unit are in |
| 2375 | * idle state after this command is performed and the port is disabled. |
| 2376 | * |
| 2377 | * INPUT: |
| 2378 | * struct mv643xx_private *mp Ethernet Port. |
| 2379 | * |
| 2380 | * OUTPUT: |
| 2381 | * Channel activity is halted. |
| 2382 | * |
| 2383 | * RETURN: |
| 2384 | * None. |
| 2385 | * |
| 2386 | */ |
| 2387 | static void eth_port_reset(struct mv643xx_private *mp) |
| 2388 | { |
| 2389 | unsigned int port_num = mp->port_num; |
| 2390 | unsigned int reg_data; |
| 2391 | |
| 2392 | mv643xx_eth_port_disable_tx(mp); |
| 2393 | mv643xx_eth_port_disable_rx(mp); |
| 2394 | |
| 2395 | /* Clear all MIB counters */ |
| 2396 | eth_clear_mib_counters(mp); |
| 2397 | |
| 2398 | /* Reset the Enable bit in the Configuration Register */ |
Lennert Buytenhek | 3cb4667 | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 2399 | reg_data = rdl(mp, PORT_SERIAL_CONTROL(port_num)); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2400 | reg_data &= ~(SERIAL_PORT_ENABLE | |
| 2401 | DO_NOT_FORCE_LINK_FAIL | |
| 2402 | FORCE_LINK_PASS); |
Lennert Buytenhek | 3cb4667 | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 2403 | wrl(mp, PORT_SERIAL_CONTROL(port_num), reg_data); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2404 | } |
| 2405 | |
| 2406 | /* |
| 2407 | * mv643xx_eth_stop |
| 2408 | * |
| 2409 | * This function is used when closing the network device. |
| 2410 | * It updates the hardware, |
| 2411 | * release all memory that holds buffers and descriptors and release the IRQ. |
| 2412 | * Input : a pointer to the device structure |
| 2413 | * Output : zero if success , nonzero if fails |
| 2414 | */ |
| 2415 | |
| 2416 | static int mv643xx_eth_stop(struct net_device *dev) |
| 2417 | { |
| 2418 | struct mv643xx_private *mp = netdev_priv(dev); |
| 2419 | unsigned int port_num = mp->port_num; |
| 2420 | |
| 2421 | /* Mask all interrupts on ethernet port */ |
Lennert Buytenhek | 073a345 | 2008-06-01 02:00:31 +0200 | [diff] [blame] | 2422 | wrl(mp, INT_MASK(port_num), 0x00000000); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2423 | /* wait for previous write to complete */ |
Lennert Buytenhek | 3cb4667 | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 2424 | rdl(mp, INT_MASK(port_num)); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2425 | |
| 2426 | #ifdef MV643XX_NAPI |
| 2427 | napi_disable(&mp->napi); |
| 2428 | #endif |
| 2429 | netif_carrier_off(dev); |
| 2430 | netif_stop_queue(dev); |
| 2431 | |
| 2432 | eth_port_reset(mp); |
| 2433 | |
| 2434 | mv643xx_eth_free_tx_rings(dev); |
| 2435 | mv643xx_eth_free_rx_rings(dev); |
| 2436 | |
| 2437 | free_irq(dev->irq, dev); |
| 2438 | |
| 2439 | return 0; |
| 2440 | } |
| 2441 | |
| 2442 | static int mv643xx_eth_do_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) |
| 2443 | { |
| 2444 | struct mv643xx_private *mp = netdev_priv(dev); |
| 2445 | |
| 2446 | return generic_mii_ioctl(&mp->mii, if_mii(ifr), cmd, NULL); |
| 2447 | } |
| 2448 | |
| 2449 | /* |
| 2450 | * Changes MTU (maximum transfer unit) of the gigabit ethenret port |
| 2451 | * |
| 2452 | * Input : pointer to ethernet interface network device structure |
| 2453 | * new mtu size |
| 2454 | * Output : 0 upon success, -EINVAL upon failure |
| 2455 | */ |
| 2456 | static int mv643xx_eth_change_mtu(struct net_device *dev, int new_mtu) |
| 2457 | { |
| 2458 | if ((new_mtu > 9500) || (new_mtu < 64)) |
| 2459 | return -EINVAL; |
| 2460 | |
| 2461 | dev->mtu = new_mtu; |
| 2462 | if (!netif_running(dev)) |
| 2463 | return 0; |
| 2464 | |
| 2465 | /* |
| 2466 | * Stop and then re-open the interface. This will allocate RX |
| 2467 | * skbs of the new MTU. |
| 2468 | * There is a possible danger that the open will not succeed, |
| 2469 | * due to memory being full, which might fail the open function. |
| 2470 | */ |
| 2471 | mv643xx_eth_stop(dev); |
| 2472 | if (mv643xx_eth_open(dev)) { |
| 2473 | printk(KERN_ERR "%s: Fatal error on opening device\n", |
| 2474 | dev->name); |
| 2475 | } |
| 2476 | |
| 2477 | return 0; |
| 2478 | } |
| 2479 | |
| 2480 | /* |
| 2481 | * mv643xx_eth_tx_timeout_task |
| 2482 | * |
| 2483 | * Actual routine to reset the adapter when a timeout on Tx has occurred |
| 2484 | */ |
| 2485 | static void mv643xx_eth_tx_timeout_task(struct work_struct *ugly) |
| 2486 | { |
| 2487 | struct mv643xx_private *mp = container_of(ugly, struct mv643xx_private, |
| 2488 | tx_timeout_task); |
| 2489 | struct net_device *dev = mp->dev; |
| 2490 | |
| 2491 | if (!netif_running(dev)) |
| 2492 | return; |
| 2493 | |
| 2494 | netif_stop_queue(dev); |
| 2495 | |
| 2496 | eth_port_reset(mp); |
| 2497 | eth_port_start(dev); |
| 2498 | |
| 2499 | if (mp->tx_ring_size - mp->tx_desc_count >= MAX_DESCS_PER_SKB) |
| 2500 | netif_wake_queue(dev); |
| 2501 | } |
| 2502 | |
| 2503 | /* |
| 2504 | * mv643xx_eth_tx_timeout |
| 2505 | * |
| 2506 | * Called upon a timeout on transmitting a packet |
| 2507 | * |
| 2508 | * Input : pointer to ethernet interface network device structure. |
| 2509 | * Output : N/A |
| 2510 | */ |
| 2511 | static void mv643xx_eth_tx_timeout(struct net_device *dev) |
| 2512 | { |
| 2513 | struct mv643xx_private *mp = netdev_priv(dev); |
| 2514 | |
| 2515 | printk(KERN_INFO "%s: TX timeout ", dev->name); |
| 2516 | |
| 2517 | /* Do the reset outside of interrupt context */ |
| 2518 | schedule_work(&mp->tx_timeout_task); |
| 2519 | } |
| 2520 | |
Dale Farnsworth | 63c9e54 | 2005-09-02 13:49:10 -0700 | [diff] [blame] | 2521 | #ifdef CONFIG_NET_POLL_CONTROLLER |
Dale Farnsworth | 63c9e54 | 2005-09-02 13:49:10 -0700 | [diff] [blame] | 2522 | static void mv643xx_netpoll(struct net_device *netdev) |
| 2523 | { |
| 2524 | struct mv643xx_private *mp = netdev_priv(netdev); |
Dale Farnsworth | c2e5b35 | 2006-01-16 17:00:24 -0700 | [diff] [blame] | 2525 | int port_num = mp->port_num; |
Dale Farnsworth | 63c9e54 | 2005-09-02 13:49:10 -0700 | [diff] [blame] | 2526 | |
Lennert Buytenhek | 073a345 | 2008-06-01 02:00:31 +0200 | [diff] [blame] | 2527 | wrl(mp, INT_MASK(port_num), 0x00000000); |
Dale Farnsworth | c2e5b35 | 2006-01-16 17:00:24 -0700 | [diff] [blame] | 2528 | /* wait for previous write to complete */ |
Lennert Buytenhek | 3cb4667 | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 2529 | rdl(mp, INT_MASK(port_num)); |
Dale Farnsworth | c2e5b35 | 2006-01-16 17:00:24 -0700 | [diff] [blame] | 2530 | |
Al Viro | 9da3b1a | 2006-10-08 15:00:44 +0100 | [diff] [blame] | 2531 | mv643xx_eth_int_handler(netdev->irq, netdev); |
Dale Farnsworth | c2e5b35 | 2006-01-16 17:00:24 -0700 | [diff] [blame] | 2532 | |
Lennert Buytenhek | 073a345 | 2008-06-01 02:00:31 +0200 | [diff] [blame] | 2533 | wrl(mp, INT_MASK(port_num), INT_RX | INT_CAUSE_EXT); |
Dale Farnsworth | 63c9e54 | 2005-09-02 13:49:10 -0700 | [diff] [blame] | 2534 | } |
| 2535 | #endif |
| 2536 | |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2537 | /* |
| 2538 | * Wrappers for MII support library. |
| 2539 | */ |
| 2540 | static int mv643xx_mdio_read(struct net_device *dev, int phy_id, int location) |
| 2541 | { |
| 2542 | struct mv643xx_private *mp = netdev_priv(dev); |
| 2543 | int val; |
| 2544 | |
| 2545 | eth_port_read_smi_reg(mp, location, &val); |
| 2546 | return val; |
| 2547 | } |
| 2548 | |
| 2549 | static void mv643xx_mdio_write(struct net_device *dev, int phy_id, int location, int val) |
| 2550 | { |
| 2551 | struct mv643xx_private *mp = netdev_priv(dev); |
| 2552 | eth_port_write_smi_reg(mp, location, val); |
| 2553 | } |
| 2554 | |
| 2555 | |
| 2556 | /* platform glue ************************************************************/ |
| 2557 | static void mv643xx_eth_conf_mbus_windows(struct mv643xx_shared_private *msp, |
| 2558 | struct mbus_dram_target_info *dram) |
| 2559 | { |
| 2560 | void __iomem *base = msp->eth_base; |
| 2561 | u32 win_enable; |
| 2562 | u32 win_protect; |
| 2563 | int i; |
| 2564 | |
| 2565 | for (i = 0; i < 6; i++) { |
| 2566 | writel(0, base + WINDOW_BASE(i)); |
| 2567 | writel(0, base + WINDOW_SIZE(i)); |
| 2568 | if (i < 4) |
| 2569 | writel(0, base + WINDOW_REMAP_HIGH(i)); |
| 2570 | } |
| 2571 | |
| 2572 | win_enable = 0x3f; |
| 2573 | win_protect = 0; |
| 2574 | |
| 2575 | for (i = 0; i < dram->num_cs; i++) { |
| 2576 | struct mbus_dram_window *cs = dram->cs + i; |
| 2577 | |
| 2578 | writel((cs->base & 0xffff0000) | |
| 2579 | (cs->mbus_attr << 8) | |
| 2580 | dram->mbus_dram_target_id, base + WINDOW_BASE(i)); |
| 2581 | writel((cs->size - 1) & 0xffff0000, base + WINDOW_SIZE(i)); |
| 2582 | |
| 2583 | win_enable &= ~(1 << i); |
| 2584 | win_protect |= 3 << (2 * i); |
| 2585 | } |
| 2586 | |
| 2587 | writel(win_enable, base + WINDOW_BAR_ENABLE); |
| 2588 | msp->win_protect = win_protect; |
| 2589 | } |
| 2590 | |
| 2591 | static int mv643xx_eth_shared_probe(struct platform_device *pdev) |
| 2592 | { |
| 2593 | static int mv643xx_version_printed = 0; |
| 2594 | struct mv643xx_eth_shared_platform_data *pd = pdev->dev.platform_data; |
| 2595 | struct mv643xx_shared_private *msp; |
| 2596 | struct resource *res; |
| 2597 | int ret; |
| 2598 | |
| 2599 | if (!mv643xx_version_printed++) |
| 2600 | printk(KERN_NOTICE "MV-643xx 10/100/1000 Ethernet Driver\n"); |
| 2601 | |
| 2602 | ret = -EINVAL; |
| 2603 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 2604 | if (res == NULL) |
| 2605 | goto out; |
| 2606 | |
| 2607 | ret = -ENOMEM; |
| 2608 | msp = kmalloc(sizeof(*msp), GFP_KERNEL); |
| 2609 | if (msp == NULL) |
| 2610 | goto out; |
| 2611 | memset(msp, 0, sizeof(*msp)); |
| 2612 | |
| 2613 | msp->eth_base = ioremap(res->start, res->end - res->start + 1); |
| 2614 | if (msp->eth_base == NULL) |
| 2615 | goto out_free; |
| 2616 | |
| 2617 | spin_lock_init(&msp->phy_lock); |
| 2618 | msp->t_clk = (pd != NULL && pd->t_clk != 0) ? pd->t_clk : 133000000; |
| 2619 | |
| 2620 | platform_set_drvdata(pdev, msp); |
| 2621 | |
| 2622 | /* |
| 2623 | * (Re-)program MBUS remapping windows if we are asked to. |
| 2624 | */ |
| 2625 | if (pd != NULL && pd->dram != NULL) |
| 2626 | mv643xx_eth_conf_mbus_windows(msp, pd->dram); |
| 2627 | |
| 2628 | return 0; |
| 2629 | |
| 2630 | out_free: |
| 2631 | kfree(msp); |
| 2632 | out: |
| 2633 | return ret; |
| 2634 | } |
| 2635 | |
| 2636 | static int mv643xx_eth_shared_remove(struct platform_device *pdev) |
| 2637 | { |
| 2638 | struct mv643xx_shared_private *msp = platform_get_drvdata(pdev); |
| 2639 | |
| 2640 | iounmap(msp->eth_base); |
| 2641 | kfree(msp); |
| 2642 | |
| 2643 | return 0; |
| 2644 | } |
| 2645 | |
| 2646 | static struct platform_driver mv643xx_eth_shared_driver = { |
| 2647 | .probe = mv643xx_eth_shared_probe, |
| 2648 | .remove = mv643xx_eth_shared_remove, |
| 2649 | .driver = { |
| 2650 | .name = MV643XX_ETH_SHARED_NAME, |
| 2651 | .owner = THIS_MODULE, |
| 2652 | }, |
| 2653 | }; |
| 2654 | |
| 2655 | /* |
| 2656 | * ethernet_phy_set - Set the ethernet port PHY address. |
| 2657 | * |
| 2658 | * DESCRIPTION: |
| 2659 | * This routine sets the given ethernet port PHY address. |
| 2660 | * |
| 2661 | * INPUT: |
| 2662 | * struct mv643xx_private *mp Ethernet Port. |
| 2663 | * int phy_addr PHY address. |
| 2664 | * |
| 2665 | * OUTPUT: |
| 2666 | * None. |
| 2667 | * |
| 2668 | * RETURN: |
| 2669 | * None. |
| 2670 | * |
| 2671 | */ |
| 2672 | static void ethernet_phy_set(struct mv643xx_private *mp, int phy_addr) |
| 2673 | { |
| 2674 | u32 reg_data; |
| 2675 | int addr_shift = 5 * mp->port_num; |
| 2676 | |
Lennert Buytenhek | 3cb4667 | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 2677 | reg_data = rdl(mp, PHY_ADDR); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2678 | reg_data &= ~(0x1f << addr_shift); |
| 2679 | reg_data |= (phy_addr & 0x1f) << addr_shift; |
Lennert Buytenhek | 3cb4667 | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 2680 | wrl(mp, PHY_ADDR, reg_data); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2681 | } |
| 2682 | |
| 2683 | /* |
| 2684 | * ethernet_phy_get - Get the ethernet port PHY address. |
| 2685 | * |
| 2686 | * DESCRIPTION: |
| 2687 | * This routine returns the given ethernet port PHY address. |
| 2688 | * |
| 2689 | * INPUT: |
| 2690 | * struct mv643xx_private *mp Ethernet Port. |
| 2691 | * |
| 2692 | * OUTPUT: |
| 2693 | * None. |
| 2694 | * |
| 2695 | * RETURN: |
| 2696 | * PHY address. |
| 2697 | * |
| 2698 | */ |
| 2699 | static int ethernet_phy_get(struct mv643xx_private *mp) |
| 2700 | { |
| 2701 | unsigned int reg_data; |
| 2702 | |
Lennert Buytenhek | 3cb4667 | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 2703 | reg_data = rdl(mp, PHY_ADDR); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2704 | |
| 2705 | return ((reg_data >> (5 * mp->port_num)) & 0x1f); |
| 2706 | } |
| 2707 | |
| 2708 | /* |
| 2709 | * ethernet_phy_detect - Detect whether a phy is present |
| 2710 | * |
| 2711 | * DESCRIPTION: |
| 2712 | * This function tests whether there is a PHY present on |
| 2713 | * the specified port. |
| 2714 | * |
| 2715 | * INPUT: |
| 2716 | * struct mv643xx_private *mp Ethernet Port. |
| 2717 | * |
| 2718 | * OUTPUT: |
| 2719 | * None |
| 2720 | * |
| 2721 | * RETURN: |
| 2722 | * 0 on success |
| 2723 | * -ENODEV on failure |
| 2724 | * |
| 2725 | */ |
| 2726 | static int ethernet_phy_detect(struct mv643xx_private *mp) |
| 2727 | { |
| 2728 | unsigned int phy_reg_data0; |
| 2729 | int auto_neg; |
| 2730 | |
| 2731 | eth_port_read_smi_reg(mp, 0, &phy_reg_data0); |
| 2732 | auto_neg = phy_reg_data0 & 0x1000; |
| 2733 | phy_reg_data0 ^= 0x1000; /* invert auto_neg */ |
| 2734 | eth_port_write_smi_reg(mp, 0, phy_reg_data0); |
| 2735 | |
| 2736 | eth_port_read_smi_reg(mp, 0, &phy_reg_data0); |
| 2737 | if ((phy_reg_data0 & 0x1000) == auto_neg) |
| 2738 | return -ENODEV; /* change didn't take */ |
| 2739 | |
| 2740 | phy_reg_data0 ^= 0x1000; |
| 2741 | eth_port_write_smi_reg(mp, 0, phy_reg_data0); |
| 2742 | return 0; |
| 2743 | } |
| 2744 | |
James Chapman | d0412d9 | 2006-01-27 01:15:30 -0700 | [diff] [blame] | 2745 | static void mv643xx_init_ethtool_cmd(struct net_device *dev, int phy_address, |
| 2746 | int speed, int duplex, |
| 2747 | struct ethtool_cmd *cmd) |
| 2748 | { |
| 2749 | struct mv643xx_private *mp = netdev_priv(dev); |
| 2750 | |
| 2751 | memset(cmd, 0, sizeof(*cmd)); |
| 2752 | |
| 2753 | cmd->port = PORT_MII; |
| 2754 | cmd->transceiver = XCVR_INTERNAL; |
| 2755 | cmd->phy_address = phy_address; |
| 2756 | |
| 2757 | if (speed == 0) { |
| 2758 | cmd->autoneg = AUTONEG_ENABLE; |
| 2759 | /* mii lib checks, but doesn't use speed on AUTONEG_ENABLE */ |
| 2760 | cmd->speed = SPEED_100; |
| 2761 | cmd->advertising = ADVERTISED_10baseT_Half | |
| 2762 | ADVERTISED_10baseT_Full | |
| 2763 | ADVERTISED_100baseT_Half | |
| 2764 | ADVERTISED_100baseT_Full; |
| 2765 | if (mp->mii.supports_gmii) |
| 2766 | cmd->advertising |= ADVERTISED_1000baseT_Full; |
| 2767 | } else { |
| 2768 | cmd->autoneg = AUTONEG_DISABLE; |
| 2769 | cmd->speed = speed; |
| 2770 | cmd->duplex = duplex; |
| 2771 | } |
| 2772 | } |
| 2773 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2774 | /*/ |
| 2775 | * mv643xx_eth_probe |
| 2776 | * |
| 2777 | * First function called after registering the network device. |
| 2778 | * It's purpose is to initialize the device as an ethernet device, |
| 2779 | * fill the ethernet device structure with pointers * to functions, |
| 2780 | * and set the MAC address of the interface |
| 2781 | * |
| 2782 | * Input : struct device * |
| 2783 | * Output : -ENOMEM if failed , 0 if success |
| 2784 | */ |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 2785 | static int mv643xx_eth_probe(struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2786 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2787 | struct mv643xx_eth_platform_data *pd; |
Dale Farnsworth | 84dd619 | 2007-03-03 06:40:28 -0700 | [diff] [blame] | 2788 | int port_num; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2789 | struct mv643xx_private *mp; |
| 2790 | struct net_device *dev; |
| 2791 | u8 *p; |
| 2792 | struct resource *res; |
| 2793 | int err; |
James Chapman | d0412d9 | 2006-01-27 01:15:30 -0700 | [diff] [blame] | 2794 | struct ethtool_cmd cmd; |
Dale Farnsworth | 0199987 | 2006-01-27 01:18:01 -0700 | [diff] [blame] | 2795 | int duplex = DUPLEX_HALF; |
| 2796 | int speed = 0; /* default to auto-negotiation */ |
Al Viro | c5d6471 | 2007-10-13 08:30:26 +0100 | [diff] [blame] | 2797 | DECLARE_MAC_BUF(mac); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2798 | |
Dale Farnsworth | 84dd619 | 2007-03-03 06:40:28 -0700 | [diff] [blame] | 2799 | pd = pdev->dev.platform_data; |
| 2800 | if (pd == NULL) { |
| 2801 | printk(KERN_ERR "No mv643xx_eth_platform_data\n"); |
| 2802 | return -ENODEV; |
| 2803 | } |
| 2804 | |
Lennert Buytenhek | fa3959f | 2008-04-24 01:27:02 +0200 | [diff] [blame] | 2805 | if (pd->shared == NULL) { |
| 2806 | printk(KERN_ERR "No mv643xx_eth_platform_data->shared\n"); |
| 2807 | return -ENODEV; |
| 2808 | } |
| 2809 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2810 | dev = alloc_etherdev(sizeof(struct mv643xx_private)); |
| 2811 | if (!dev) |
| 2812 | return -ENOMEM; |
| 2813 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 2814 | platform_set_drvdata(pdev, dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2815 | |
| 2816 | mp = netdev_priv(dev); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 2817 | mp->dev = dev; |
| 2818 | #ifdef MV643XX_NAPI |
| 2819 | netif_napi_add(dev, &mp->napi, mv643xx_poll, 64); |
| 2820 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2821 | |
| 2822 | res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); |
| 2823 | BUG_ON(!res); |
| 2824 | dev->irq = res->start; |
| 2825 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2826 | dev->open = mv643xx_eth_open; |
| 2827 | dev->stop = mv643xx_eth_stop; |
| 2828 | dev->hard_start_xmit = mv643xx_eth_start_xmit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2829 | dev->set_mac_address = mv643xx_eth_set_mac_address; |
| 2830 | dev->set_multicast_list = mv643xx_eth_set_rx_mode; |
| 2831 | |
| 2832 | /* No need to Tx Timeout */ |
| 2833 | dev->tx_timeout = mv643xx_eth_tx_timeout; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2834 | |
Dale Farnsworth | 63c9e54 | 2005-09-02 13:49:10 -0700 | [diff] [blame] | 2835 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 2836 | dev->poll_controller = mv643xx_netpoll; |
| 2837 | #endif |
| 2838 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2839 | dev->watchdog_timeo = 2 * HZ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2840 | dev->base_addr = 0; |
| 2841 | dev->change_mtu = mv643xx_eth_change_mtu; |
James Chapman | d0412d9 | 2006-01-27 01:15:30 -0700 | [diff] [blame] | 2842 | dev->do_ioctl = mv643xx_eth_do_ioctl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2843 | SET_ETHTOOL_OPS(dev, &mv643xx_ethtool_ops); |
| 2844 | |
| 2845 | #ifdef MV643XX_CHECKSUM_OFFLOAD_TX |
| 2846 | #ifdef MAX_SKB_FRAGS |
| 2847 | /* |
| 2848 | * Zero copy can only work if we use Discovery II memory. Else, we will |
| 2849 | * have to map the buffers to ISA memory which is only 16 MB |
| 2850 | */ |
Wolfram Joost | 6389057 | 2006-01-16 16:57:41 -0700 | [diff] [blame] | 2851 | dev->features = NETIF_F_SG | NETIF_F_IP_CSUM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2852 | #endif |
| 2853 | #endif |
| 2854 | |
| 2855 | /* Configure the timeout task */ |
Al Viro | 91c7c56 | 2006-12-06 19:50:06 +0000 | [diff] [blame] | 2856 | INIT_WORK(&mp->tx_timeout_task, mv643xx_eth_tx_timeout_task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2857 | |
| 2858 | spin_lock_init(&mp->lock); |
| 2859 | |
Lennert Buytenhek | fa3959f | 2008-04-24 01:27:02 +0200 | [diff] [blame] | 2860 | mp->shared = platform_get_drvdata(pd->shared); |
Gabriel Paubert | fadac40 | 2007-03-23 12:03:52 -0700 | [diff] [blame] | 2861 | port_num = mp->port_num = pd->port_number; |
Dale Farnsworth | 84dd619 | 2007-03-03 06:40:28 -0700 | [diff] [blame] | 2862 | |
Lennert Buytenhek | f2ce825 | 2008-04-24 01:27:17 +0200 | [diff] [blame] | 2863 | if (mp->shared->win_protect) |
| 2864 | wrl(mp, WINDOW_PROTECT(port_num), mp->shared->win_protect); |
| 2865 | |
Lennert Buytenhek | ce4e2e4 | 2008-04-24 01:29:59 +0200 | [diff] [blame] | 2866 | mp->shared_smi = mp->shared; |
| 2867 | if (pd->shared_smi != NULL) |
| 2868 | mp->shared_smi = platform_get_drvdata(pd->shared_smi); |
| 2869 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2870 | /* set default config values */ |
Lennert Buytenhek | afdb57a | 2008-03-18 11:36:08 -0700 | [diff] [blame] | 2871 | eth_port_uc_addr_get(mp, dev->dev_addr); |
Lennert Buytenhek | e4d00fa | 2007-10-19 04:11:28 +0200 | [diff] [blame] | 2872 | mp->rx_ring_size = PORT_DEFAULT_RECEIVE_QUEUE_SIZE; |
| 2873 | mp->tx_ring_size = PORT_DEFAULT_TRANSMIT_QUEUE_SIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2874 | |
Dale Farnsworth | 84dd619 | 2007-03-03 06:40:28 -0700 | [diff] [blame] | 2875 | if (is_valid_ether_addr(pd->mac_addr)) |
| 2876 | memcpy(dev->dev_addr, pd->mac_addr, 6); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2877 | |
Dale Farnsworth | 84dd619 | 2007-03-03 06:40:28 -0700 | [diff] [blame] | 2878 | if (pd->phy_addr || pd->force_phy_addr) |
Lennert Buytenhek | afdb57a | 2008-03-18 11:36:08 -0700 | [diff] [blame] | 2879 | ethernet_phy_set(mp, pd->phy_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2880 | |
Dale Farnsworth | 84dd619 | 2007-03-03 06:40:28 -0700 | [diff] [blame] | 2881 | if (pd->rx_queue_size) |
| 2882 | mp->rx_ring_size = pd->rx_queue_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2883 | |
Dale Farnsworth | 84dd619 | 2007-03-03 06:40:28 -0700 | [diff] [blame] | 2884 | if (pd->tx_queue_size) |
| 2885 | mp->tx_ring_size = pd->tx_queue_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2886 | |
Dale Farnsworth | 84dd619 | 2007-03-03 06:40:28 -0700 | [diff] [blame] | 2887 | if (pd->tx_sram_size) { |
| 2888 | mp->tx_sram_size = pd->tx_sram_size; |
| 2889 | mp->tx_sram_addr = pd->tx_sram_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2890 | } |
| 2891 | |
Dale Farnsworth | 84dd619 | 2007-03-03 06:40:28 -0700 | [diff] [blame] | 2892 | if (pd->rx_sram_size) { |
| 2893 | mp->rx_sram_size = pd->rx_sram_size; |
| 2894 | mp->rx_sram_addr = pd->rx_sram_addr; |
| 2895 | } |
| 2896 | |
| 2897 | duplex = pd->duplex; |
| 2898 | speed = pd->speed; |
| 2899 | |
James Chapman | c28a4f8 | 2006-01-27 01:13:15 -0700 | [diff] [blame] | 2900 | /* Hook up MII support for ethtool */ |
| 2901 | mp->mii.dev = dev; |
| 2902 | mp->mii.mdio_read = mv643xx_mdio_read; |
| 2903 | mp->mii.mdio_write = mv643xx_mdio_write; |
Lennert Buytenhek | afdb57a | 2008-03-18 11:36:08 -0700 | [diff] [blame] | 2904 | mp->mii.phy_id = ethernet_phy_get(mp); |
James Chapman | c28a4f8 | 2006-01-27 01:13:15 -0700 | [diff] [blame] | 2905 | mp->mii.phy_id_mask = 0x3f; |
| 2906 | mp->mii.reg_num_mask = 0x1f; |
| 2907 | |
Lennert Buytenhek | afdb57a | 2008-03-18 11:36:08 -0700 | [diff] [blame] | 2908 | err = ethernet_phy_detect(mp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2909 | if (err) { |
Lennert Buytenhek | c1b35a2 | 2008-03-18 11:37:19 -0700 | [diff] [blame] | 2910 | pr_debug("%s: No PHY detected at addr %d\n", |
| 2911 | dev->name, ethernet_phy_get(mp)); |
James Chapman | d0412d9 | 2006-01-27 01:15:30 -0700 | [diff] [blame] | 2912 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2913 | } |
| 2914 | |
Lennert Buytenhek | afdb57a | 2008-03-18 11:36:08 -0700 | [diff] [blame] | 2915 | ethernet_phy_reset(mp); |
James Chapman | c28a4f8 | 2006-01-27 01:13:15 -0700 | [diff] [blame] | 2916 | mp->mii.supports_gmii = mii_check_gmii_support(&mp->mii); |
James Chapman | d0412d9 | 2006-01-27 01:15:30 -0700 | [diff] [blame] | 2917 | mv643xx_init_ethtool_cmd(dev, mp->mii.phy_id, speed, duplex, &cmd); |
| 2918 | mv643xx_eth_update_pscr(dev, &cmd); |
| 2919 | mv643xx_set_settings(dev, &cmd); |
James Chapman | c28a4f8 | 2006-01-27 01:13:15 -0700 | [diff] [blame] | 2920 | |
Olaf Hering | b0b8dab | 2006-04-27 18:23:49 -0700 | [diff] [blame] | 2921 | SET_NETDEV_DEV(dev, &pdev->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2922 | err = register_netdev(dev); |
| 2923 | if (err) |
| 2924 | goto out; |
| 2925 | |
| 2926 | p = dev->dev_addr; |
| 2927 | printk(KERN_NOTICE |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2928 | "%s: port %d with MAC address %s\n", |
| 2929 | dev->name, port_num, print_mac(mac, p)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2930 | |
| 2931 | if (dev->features & NETIF_F_SG) |
| 2932 | printk(KERN_NOTICE "%s: Scatter Gather Enabled\n", dev->name); |
| 2933 | |
| 2934 | if (dev->features & NETIF_F_IP_CSUM) |
| 2935 | printk(KERN_NOTICE "%s: TX TCP/IP Checksumming Supported\n", |
| 2936 | dev->name); |
| 2937 | |
| 2938 | #ifdef MV643XX_CHECKSUM_OFFLOAD_TX |
| 2939 | printk(KERN_NOTICE "%s: RX TCP/UDP Checksum Offload ON \n", dev->name); |
| 2940 | #endif |
| 2941 | |
| 2942 | #ifdef MV643XX_COAL |
| 2943 | printk(KERN_NOTICE "%s: TX and RX Interrupt Coalescing ON \n", |
| 2944 | dev->name); |
| 2945 | #endif |
| 2946 | |
| 2947 | #ifdef MV643XX_NAPI |
| 2948 | printk(KERN_NOTICE "%s: RX NAPI Enabled \n", dev->name); |
| 2949 | #endif |
| 2950 | |
Nicolas DET | b152987 | 2005-10-28 17:46:30 -0700 | [diff] [blame] | 2951 | if (mp->tx_sram_size > 0) |
| 2952 | printk(KERN_NOTICE "%s: Using SRAM\n", dev->name); |
| 2953 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2954 | return 0; |
| 2955 | |
| 2956 | out: |
| 2957 | free_netdev(dev); |
| 2958 | |
| 2959 | return err; |
| 2960 | } |
| 2961 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 2962 | static int mv643xx_eth_remove(struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2963 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 2964 | struct net_device *dev = platform_get_drvdata(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2965 | |
| 2966 | unregister_netdev(dev); |
| 2967 | flush_scheduled_work(); |
| 2968 | |
| 2969 | free_netdev(dev); |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 2970 | platform_set_drvdata(pdev, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2971 | return 0; |
| 2972 | } |
| 2973 | |
Dale Farnsworth | d57ab6f | 2007-03-20 16:38:04 -0700 | [diff] [blame] | 2974 | static void mv643xx_eth_shutdown(struct platform_device *pdev) |
| 2975 | { |
| 2976 | struct net_device *dev = platform_get_drvdata(pdev); |
| 2977 | struct mv643xx_private *mp = netdev_priv(dev); |
| 2978 | unsigned int port_num = mp->port_num; |
| 2979 | |
| 2980 | /* Mask all interrupts on ethernet port */ |
Lennert Buytenhek | 3cb4667 | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 2981 | wrl(mp, INT_MASK(port_num), 0); |
| 2982 | rdl(mp, INT_MASK(port_num)); |
Dale Farnsworth | d57ab6f | 2007-03-20 16:38:04 -0700 | [diff] [blame] | 2983 | |
Lennert Buytenhek | afdb57a | 2008-03-18 11:36:08 -0700 | [diff] [blame] | 2984 | eth_port_reset(mp); |
Dale Farnsworth | d57ab6f | 2007-03-20 16:38:04 -0700 | [diff] [blame] | 2985 | } |
| 2986 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 2987 | static struct platform_driver mv643xx_eth_driver = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2988 | .probe = mv643xx_eth_probe, |
| 2989 | .remove = mv643xx_eth_remove, |
Dale Farnsworth | d57ab6f | 2007-03-20 16:38:04 -0700 | [diff] [blame] | 2990 | .shutdown = mv643xx_eth_shutdown, |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 2991 | .driver = { |
| 2992 | .name = MV643XX_ETH_NAME, |
Kay Sievers | 72abb46 | 2008-04-18 13:50:44 -0700 | [diff] [blame] | 2993 | .owner = THIS_MODULE, |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 2994 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2995 | }; |
| 2996 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2997 | /* |
| 2998 | * mv643xx_init_module |
| 2999 | * |
| 3000 | * Registers the network drivers into the Linux kernel |
| 3001 | * |
| 3002 | * Input : N/A |
| 3003 | * |
| 3004 | * Output : N/A |
| 3005 | */ |
| 3006 | static int __init mv643xx_init_module(void) |
| 3007 | { |
| 3008 | int rc; |
| 3009 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 3010 | rc = platform_driver_register(&mv643xx_eth_shared_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3011 | if (!rc) { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 3012 | rc = platform_driver_register(&mv643xx_eth_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3013 | if (rc) |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 3014 | platform_driver_unregister(&mv643xx_eth_shared_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3015 | } |
| 3016 | return rc; |
| 3017 | } |
| 3018 | |
| 3019 | /* |
| 3020 | * mv643xx_cleanup_module |
| 3021 | * |
| 3022 | * Registers the network drivers into the Linux kernel |
| 3023 | * |
| 3024 | * Input : N/A |
| 3025 | * |
| 3026 | * Output : N/A |
| 3027 | */ |
| 3028 | static void __exit mv643xx_cleanup_module(void) |
| 3029 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 3030 | platform_driver_unregister(&mv643xx_eth_driver); |
| 3031 | platform_driver_unregister(&mv643xx_eth_shared_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3032 | } |
| 3033 | |
| 3034 | module_init(mv643xx_init_module); |
| 3035 | module_exit(mv643xx_cleanup_module); |
| 3036 | |
| 3037 | MODULE_LICENSE("GPL"); |
| 3038 | MODULE_AUTHOR( "Rabeeh Khoury, Assaf Hoffman, Matthew Dharm, Manish Lachwani" |
| 3039 | " and Dale Farnsworth"); |
| 3040 | MODULE_DESCRIPTION("Ethernet driver for Marvell MV643XX"); |
Kay Sievers | 72abb46 | 2008-04-18 13:50:44 -0700 | [diff] [blame] | 3041 | MODULE_ALIAS("platform:" MV643XX_ETH_NAME); |
| 3042 | MODULE_ALIAS("platform:" MV643XX_ETH_SHARED_NAME); |