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