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