Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Lennert Buytenhek | 9c1bbdf | 2007-10-19 04:11:03 +0200 | [diff] [blame] | 2 | * Driver for Marvell Discovery (MV643XX) and Marvell Orion ethernet ports |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * Copyright (C) 2002 Matthew Dharm <mdharm@momenco.com> |
| 4 | * |
| 5 | * Based on the 64360 driver from: |
Lennert Buytenhek | 4547fa6 | 2008-03-18 11:40:14 -0700 | [diff] [blame] | 6 | * Copyright (C) 2002 Rabeeh Khoury <rabeeh@galileo.co.il> |
| 7 | * Rabeeh Khoury <rabeeh@marvell.com> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | * |
| 9 | * Copyright (C) 2003 PMC-Sierra, Inc., |
Olaf Hering | 3bb8a18a | 2006-01-05 22:45:45 -0800 | [diff] [blame] | 10 | * written by Manish Lachwani |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | * |
| 12 | * Copyright (C) 2003 Ralf Baechle <ralf@linux-mips.org> |
| 13 | * |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 14 | * Copyright (C) 2004-2006 MontaVista Software, Inc. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | * Dale Farnsworth <dale@farnsworth.org> |
| 16 | * |
| 17 | * Copyright (C) 2004 Steven J. Hill <sjhill1@rockwellcollins.com> |
| 18 | * <sjhill@realitydiluted.com> |
| 19 | * |
Lennert Buytenhek | 4547fa6 | 2008-03-18 11:40:14 -0700 | [diff] [blame] | 20 | * Copyright (C) 2007-2008 Marvell Semiconductor |
| 21 | * Lennert Buytenhek <buytenh@marvell.com> |
| 22 | * |
Michael Stapelberg | 3871c38 | 2013-03-11 13:56:45 +0000 | [diff] [blame^] | 23 | * Copyright (C) 2013 Michael Stapelberg <michael@stapelberg.de> |
| 24 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | * This program is free software; you can redistribute it and/or |
| 26 | * modify it under the terms of the GNU General Public License |
| 27 | * as published by the Free Software Foundation; either version 2 |
| 28 | * of the License, or (at your option) any later version. |
| 29 | * |
| 30 | * This program is distributed in the hope that it will be useful, |
| 31 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 32 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 33 | * GNU General Public License for more details. |
| 34 | * |
| 35 | * You should have received a copy of the GNU General Public License |
| 36 | * along with this program; if not, write to the Free Software |
| 37 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 38 | */ |
Lennert Buytenhek | a779d38 | 2008-06-01 00:54:05 +0200 | [diff] [blame] | 39 | |
Joe Perches | 7542db8 | 2011-03-02 17:50:35 +0000 | [diff] [blame] | 40 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 41 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | #include <linux/init.h> |
| 43 | #include <linux/dma-mapping.h> |
Al Viro | b6298c2 | 2006-01-18 19:35:54 -0500 | [diff] [blame] | 44 | #include <linux/in.h> |
Lennert Buytenhek | c3efab8 | 2008-10-02 00:52:39 +0000 | [diff] [blame] | 45 | #include <linux/ip.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | #include <linux/tcp.h> |
| 47 | #include <linux/udp.h> |
| 48 | #include <linux/etherdevice.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | #include <linux/delay.h> |
| 50 | #include <linux/ethtool.h> |
Russell King | d052d1b | 2005-10-29 19:07:23 +0100 | [diff] [blame] | 51 | #include <linux/platform_device.h> |
Lennert Buytenhek | fbd6a75 | 2007-10-19 16:03:46 +0200 | [diff] [blame] | 52 | #include <linux/module.h> |
| 53 | #include <linux/kernel.h> |
| 54 | #include <linux/spinlock.h> |
| 55 | #include <linux/workqueue.h> |
Lennert Buytenhek | ed94493 | 2008-08-26 13:34:19 +0200 | [diff] [blame] | 56 | #include <linux/phy.h> |
Lennert Buytenhek | fbd6a75 | 2007-10-19 16:03:46 +0200 | [diff] [blame] | 57 | #include <linux/mv643xx_eth.h> |
Lennert Buytenhek | 10a9948 | 2008-11-20 03:57:16 -0800 | [diff] [blame] | 58 | #include <linux/io.h> |
| 59 | #include <linux/types.h> |
Lennert Buytenhek | eaf5d59 | 2009-02-12 14:08:39 +0000 | [diff] [blame] | 60 | #include <linux/inet_lro.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 61 | #include <linux/slab.h> |
Andrew Lunn | 452503e | 2011-12-24 01:24:24 +0100 | [diff] [blame] | 62 | #include <linux/clk.h> |
Lennert Buytenhek | fbd6a75 | 2007-10-19 16:03:46 +0200 | [diff] [blame] | 63 | |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 64 | static char mv643xx_eth_driver_name[] = "mv643xx_eth"; |
Lennert Buytenhek | 042af53 | 2008-08-24 09:01:57 +0200 | [diff] [blame] | 65 | static char mv643xx_eth_driver_version[] = "1.4"; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 66 | |
Lennert Buytenhek | fbd6a75 | 2007-10-19 16:03:46 +0200 | [diff] [blame] | 67 | |
Lennert Buytenhek | fbd6a75 | 2007-10-19 16:03:46 +0200 | [diff] [blame] | 68 | /* |
| 69 | * Registers shared between all ports. |
| 70 | */ |
Lennert Buytenhek | 3cb4667 | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 71 | #define PHY_ADDR 0x0000 |
| 72 | #define SMI_REG 0x0004 |
Lennert Buytenhek | 45c5d3b | 2008-08-26 04:42:59 +0200 | [diff] [blame] | 73 | #define SMI_BUSY 0x10000000 |
| 74 | #define SMI_READ_VALID 0x08000000 |
| 75 | #define SMI_OPCODE_READ 0x04000000 |
| 76 | #define SMI_OPCODE_WRITE 0x00000000 |
| 77 | #define ERR_INT_CAUSE 0x0080 |
| 78 | #define ERR_INT_SMI_DONE 0x00000010 |
| 79 | #define ERR_INT_MASK 0x0084 |
Lennert Buytenhek | 3cb4667 | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 80 | #define WINDOW_BASE(w) (0x0200 + ((w) << 3)) |
| 81 | #define WINDOW_SIZE(w) (0x0204 + ((w) << 3)) |
| 82 | #define WINDOW_REMAP_HIGH(w) (0x0280 + ((w) << 2)) |
| 83 | #define WINDOW_BAR_ENABLE 0x0290 |
| 84 | #define WINDOW_PROTECT(w) (0x0294 + ((w) << 4)) |
Lennert Buytenhek | fbd6a75 | 2007-10-19 16:03:46 +0200 | [diff] [blame] | 85 | |
| 86 | /* |
Lennert Buytenhek | 37a6084 | 2008-11-20 03:57:36 -0800 | [diff] [blame] | 87 | * Main per-port registers. These live at offset 0x0400 for |
| 88 | * port #0, 0x0800 for port #1, and 0x0c00 for port #2. |
Lennert Buytenhek | fbd6a75 | 2007-10-19 16:03:46 +0200 | [diff] [blame] | 89 | */ |
Lennert Buytenhek | 37a6084 | 2008-11-20 03:57:36 -0800 | [diff] [blame] | 90 | #define PORT_CONFIG 0x0000 |
Lennert Buytenhek | d9a073e | 2008-06-01 01:22:06 +0200 | [diff] [blame] | 91 | #define UNICAST_PROMISCUOUS_MODE 0x00000001 |
Lennert Buytenhek | 37a6084 | 2008-11-20 03:57:36 -0800 | [diff] [blame] | 92 | #define PORT_CONFIG_EXT 0x0004 |
| 93 | #define MAC_ADDR_LOW 0x0014 |
| 94 | #define MAC_ADDR_HIGH 0x0018 |
| 95 | #define SDMA_CONFIG 0x001c |
Lennert Buytenhek | becfad9 | 2009-05-06 03:01:17 +0000 | [diff] [blame] | 96 | #define TX_BURST_SIZE_16_64BIT 0x01000000 |
| 97 | #define TX_BURST_SIZE_4_64BIT 0x00800000 |
| 98 | #define BLM_TX_NO_SWAP 0x00000020 |
| 99 | #define BLM_RX_NO_SWAP 0x00000010 |
| 100 | #define RX_BURST_SIZE_16_64BIT 0x00000008 |
| 101 | #define RX_BURST_SIZE_4_64BIT 0x00000004 |
Lennert Buytenhek | 37a6084 | 2008-11-20 03:57:36 -0800 | [diff] [blame] | 102 | #define PORT_SERIAL_CONTROL 0x003c |
Lennert Buytenhek | becfad9 | 2009-05-06 03:01:17 +0000 | [diff] [blame] | 103 | #define SET_MII_SPEED_TO_100 0x01000000 |
| 104 | #define SET_GMII_SPEED_TO_1000 0x00800000 |
| 105 | #define SET_FULL_DUPLEX_MODE 0x00200000 |
| 106 | #define MAX_RX_PACKET_9700BYTE 0x000a0000 |
| 107 | #define DISABLE_AUTO_NEG_SPEED_GMII 0x00002000 |
| 108 | #define DO_NOT_FORCE_LINK_FAIL 0x00000400 |
| 109 | #define SERIAL_PORT_CONTROL_RESERVED 0x00000200 |
| 110 | #define DISABLE_AUTO_NEG_FOR_FLOW_CTRL 0x00000008 |
| 111 | #define DISABLE_AUTO_NEG_FOR_DUPLEX 0x00000004 |
| 112 | #define FORCE_LINK_PASS 0x00000002 |
| 113 | #define SERIAL_PORT_ENABLE 0x00000001 |
Lennert Buytenhek | 37a6084 | 2008-11-20 03:57:36 -0800 | [diff] [blame] | 114 | #define PORT_STATUS 0x0044 |
Lennert Buytenhek | a2a4168 | 2008-06-01 01:30:42 +0200 | [diff] [blame] | 115 | #define TX_FIFO_EMPTY 0x00000400 |
Lennert Buytenhek | ae9ae06 | 2008-07-15 02:15:24 +0200 | [diff] [blame] | 116 | #define TX_IN_PROGRESS 0x00000080 |
Lennert Buytenhek | 2f7eb47 | 2008-07-24 06:22:59 +0200 | [diff] [blame] | 117 | #define PORT_SPEED_MASK 0x00000030 |
| 118 | #define PORT_SPEED_1000 0x00000010 |
| 119 | #define PORT_SPEED_100 0x00000020 |
| 120 | #define PORT_SPEED_10 0x00000000 |
| 121 | #define FLOW_CONTROL_ENABLED 0x00000008 |
| 122 | #define FULL_DUPLEX 0x00000004 |
Lennert Buytenhek | 81600eea9 | 2008-07-14 14:29:40 +0200 | [diff] [blame] | 123 | #define LINK_UP 0x00000002 |
Lennert Buytenhek | 37a6084 | 2008-11-20 03:57:36 -0800 | [diff] [blame] | 124 | #define TXQ_COMMAND 0x0048 |
| 125 | #define TXQ_FIX_PRIO_CONF 0x004c |
| 126 | #define TX_BW_RATE 0x0050 |
| 127 | #define TX_BW_MTU 0x0058 |
| 128 | #define TX_BW_BURST 0x005c |
| 129 | #define INT_CAUSE 0x0060 |
Lennert Buytenhek | 226bb6b | 2008-06-02 01:47:21 +0200 | [diff] [blame] | 130 | #define INT_TX_END 0x07f80000 |
Saeed Bishara | e0ca841 | 2009-05-06 03:02:01 +0000 | [diff] [blame] | 131 | #define INT_TX_END_0 0x00080000 |
Lennert Buytenhek | befefe2 | 2008-08-28 06:10:04 +0200 | [diff] [blame] | 132 | #define INT_RX 0x000003fc |
Saeed Bishara | e0ca841 | 2009-05-06 03:02:01 +0000 | [diff] [blame] | 133 | #define INT_RX_0 0x00000004 |
Lennert Buytenhek | 073a345 | 2008-06-01 02:00:31 +0200 | [diff] [blame] | 134 | #define INT_EXT 0x00000002 |
Lennert Buytenhek | 37a6084 | 2008-11-20 03:57:36 -0800 | [diff] [blame] | 135 | #define INT_CAUSE_EXT 0x0064 |
Lennert Buytenhek | befefe2 | 2008-08-28 06:10:04 +0200 | [diff] [blame] | 136 | #define INT_EXT_LINK_PHY 0x00110000 |
| 137 | #define INT_EXT_TX 0x000000ff |
Lennert Buytenhek | 37a6084 | 2008-11-20 03:57:36 -0800 | [diff] [blame] | 138 | #define INT_MASK 0x0068 |
| 139 | #define INT_MASK_EXT 0x006c |
| 140 | #define TX_FIFO_URGENT_THRESHOLD 0x0074 |
Paulius Zaleckas | 302476c | 2012-01-23 01:16:35 +0000 | [diff] [blame] | 141 | #define RX_DISCARD_FRAME_CNT 0x0084 |
| 142 | #define RX_OVERRUN_FRAME_CNT 0x0088 |
Lennert Buytenhek | 37a6084 | 2008-11-20 03:57:36 -0800 | [diff] [blame] | 143 | #define TXQ_FIX_PRIO_CONF_MOVED 0x00dc |
| 144 | #define TX_BW_RATE_MOVED 0x00e0 |
| 145 | #define TX_BW_MTU_MOVED 0x00e8 |
| 146 | #define TX_BW_BURST_MOVED 0x00ec |
| 147 | #define RXQ_CURRENT_DESC_PTR(q) (0x020c + ((q) << 4)) |
| 148 | #define RXQ_COMMAND 0x0280 |
| 149 | #define TXQ_CURRENT_DESC_PTR(q) (0x02c0 + ((q) << 2)) |
| 150 | #define TXQ_BW_TOKENS(q) (0x0300 + ((q) << 4)) |
| 151 | #define TXQ_BW_CONF(q) (0x0304 + ((q) << 4)) |
| 152 | #define TXQ_BW_WRR_CONF(q) (0x0308 + ((q) << 4)) |
| 153 | |
| 154 | /* |
| 155 | * Misc per-port registers. |
| 156 | */ |
Lennert Buytenhek | 3cb4667 | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 157 | #define MIB_COUNTERS(p) (0x1000 + ((p) << 7)) |
| 158 | #define SPECIAL_MCAST_TABLE(p) (0x1400 + ((p) << 10)) |
| 159 | #define OTHER_MCAST_TABLE(p) (0x1500 + ((p) << 10)) |
| 160 | #define UNICAST_TABLE(p) (0x1600 + ((p) << 10)) |
Lennert Buytenhek | fbd6a75 | 2007-10-19 16:03:46 +0200 | [diff] [blame] | 161 | |
Lennert Buytenhek | 2679a55 | 2008-06-01 01:18:58 +0200 | [diff] [blame] | 162 | |
| 163 | /* |
Lennert Buytenhek | becfad9 | 2009-05-06 03:01:17 +0000 | [diff] [blame] | 164 | * SDMA configuration register default value. |
Lennert Buytenhek | 2679a55 | 2008-06-01 01:18:58 +0200 | [diff] [blame] | 165 | */ |
Lennert Buytenhek | fbd6a75 | 2007-10-19 16:03:46 +0200 | [diff] [blame] | 166 | #if defined(__BIG_ENDIAN) |
| 167 | #define PORT_SDMA_CONFIG_DEFAULT_VALUE \ |
Lennert Buytenhek | e0c6ef9 | 2009-01-19 17:16:00 -0800 | [diff] [blame] | 168 | (RX_BURST_SIZE_4_64BIT | \ |
| 169 | TX_BURST_SIZE_4_64BIT) |
Lennert Buytenhek | fbd6a75 | 2007-10-19 16:03:46 +0200 | [diff] [blame] | 170 | #elif defined(__LITTLE_ENDIAN) |
| 171 | #define PORT_SDMA_CONFIG_DEFAULT_VALUE \ |
Lennert Buytenhek | e0c6ef9 | 2009-01-19 17:16:00 -0800 | [diff] [blame] | 172 | (RX_BURST_SIZE_4_64BIT | \ |
| 173 | BLM_RX_NO_SWAP | \ |
| 174 | BLM_TX_NO_SWAP | \ |
| 175 | TX_BURST_SIZE_4_64BIT) |
Lennert Buytenhek | fbd6a75 | 2007-10-19 16:03:46 +0200 | [diff] [blame] | 176 | #else |
| 177 | #error One of __BIG_ENDIAN or __LITTLE_ENDIAN must be defined |
| 178 | #endif |
| 179 | |
Lennert Buytenhek | 2beff77 | 2008-06-01 01:22:37 +0200 | [diff] [blame] | 180 | |
| 181 | /* |
Lennert Buytenhek | becfad9 | 2009-05-06 03:01:17 +0000 | [diff] [blame] | 182 | * Misc definitions. |
Lennert Buytenhek | 2beff77 | 2008-06-01 01:22:37 +0200 | [diff] [blame] | 183 | */ |
Lennert Buytenhek | becfad9 | 2009-05-06 03:01:17 +0000 | [diff] [blame] | 184 | #define DEFAULT_RX_QUEUE_SIZE 128 |
| 185 | #define DEFAULT_TX_QUEUE_SIZE 256 |
Lennert Buytenhek | 7fd96ce | 2009-05-06 03:01:22 +0000 | [diff] [blame] | 186 | #define SKB_DMA_REALIGN ((PAGE_SIZE - NET_SKB_PAD) % SMP_CACHE_BYTES) |
Lennert Buytenhek | fbd6a75 | 2007-10-19 16:03:46 +0200 | [diff] [blame] | 187 | |
Lennert Buytenhek | fbd6a75 | 2007-10-19 16:03:46 +0200 | [diff] [blame] | 188 | |
Lennert Buytenhek | 7ca72a3 | 2008-06-01 01:41:29 +0200 | [diff] [blame] | 189 | /* |
| 190 | * RX/TX descriptors. |
Lennert Buytenhek | fbd6a75 | 2007-10-19 16:03:46 +0200 | [diff] [blame] | 191 | */ |
| 192 | #if defined(__BIG_ENDIAN) |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 193 | struct rx_desc { |
Lennert Buytenhek | fbd6a75 | 2007-10-19 16:03:46 +0200 | [diff] [blame] | 194 | u16 byte_cnt; /* Descriptor buffer byte count */ |
| 195 | u16 buf_size; /* Buffer size */ |
| 196 | u32 cmd_sts; /* Descriptor command status */ |
| 197 | u32 next_desc_ptr; /* Next descriptor pointer */ |
| 198 | u32 buf_ptr; /* Descriptor buffer pointer */ |
| 199 | }; |
| 200 | |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 201 | struct tx_desc { |
Lennert Buytenhek | fbd6a75 | 2007-10-19 16:03:46 +0200 | [diff] [blame] | 202 | u16 byte_cnt; /* buffer byte count */ |
| 203 | u16 l4i_chk; /* CPU provided TCP checksum */ |
| 204 | u32 cmd_sts; /* Command/status field */ |
| 205 | u32 next_desc_ptr; /* Pointer to next descriptor */ |
| 206 | u32 buf_ptr; /* pointer to buffer for this descriptor*/ |
| 207 | }; |
| 208 | #elif defined(__LITTLE_ENDIAN) |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 209 | struct rx_desc { |
Lennert Buytenhek | fbd6a75 | 2007-10-19 16:03:46 +0200 | [diff] [blame] | 210 | u32 cmd_sts; /* Descriptor command status */ |
| 211 | u16 buf_size; /* Buffer size */ |
| 212 | u16 byte_cnt; /* Descriptor buffer byte count */ |
| 213 | u32 buf_ptr; /* Descriptor buffer pointer */ |
| 214 | u32 next_desc_ptr; /* Next descriptor pointer */ |
| 215 | }; |
| 216 | |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 217 | struct tx_desc { |
Lennert Buytenhek | fbd6a75 | 2007-10-19 16:03:46 +0200 | [diff] [blame] | 218 | u32 cmd_sts; /* Command/status field */ |
| 219 | u16 l4i_chk; /* CPU provided TCP checksum */ |
| 220 | u16 byte_cnt; /* buffer byte count */ |
| 221 | u32 buf_ptr; /* pointer to buffer for this descriptor*/ |
| 222 | u32 next_desc_ptr; /* Pointer to next descriptor */ |
| 223 | }; |
| 224 | #else |
| 225 | #error One of __BIG_ENDIAN or __LITTLE_ENDIAN must be defined |
| 226 | #endif |
| 227 | |
Lennert Buytenhek | 7ca72a3 | 2008-06-01 01:41:29 +0200 | [diff] [blame] | 228 | /* RX & TX descriptor command */ |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 229 | #define BUFFER_OWNED_BY_DMA 0x80000000 |
Lennert Buytenhek | 7ca72a3 | 2008-06-01 01:41:29 +0200 | [diff] [blame] | 230 | |
| 231 | /* RX & TX descriptor status */ |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 232 | #define ERROR_SUMMARY 0x00000001 |
Lennert Buytenhek | 7ca72a3 | 2008-06-01 01:41:29 +0200 | [diff] [blame] | 233 | |
| 234 | /* RX descriptor status */ |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 235 | #define LAYER_4_CHECKSUM_OK 0x40000000 |
| 236 | #define RX_ENABLE_INTERRUPT 0x20000000 |
| 237 | #define RX_FIRST_DESC 0x08000000 |
| 238 | #define RX_LAST_DESC 0x04000000 |
Lennert Buytenhek | eaf5d59 | 2009-02-12 14:08:39 +0000 | [diff] [blame] | 239 | #define RX_IP_HDR_OK 0x02000000 |
| 240 | #define RX_PKT_IS_IPV4 0x01000000 |
| 241 | #define RX_PKT_IS_ETHERNETV2 0x00800000 |
| 242 | #define RX_PKT_LAYER4_TYPE_MASK 0x00600000 |
| 243 | #define RX_PKT_LAYER4_TYPE_TCP_IPV4 0x00000000 |
| 244 | #define RX_PKT_IS_VLAN_TAGGED 0x00080000 |
Lennert Buytenhek | 7ca72a3 | 2008-06-01 01:41:29 +0200 | [diff] [blame] | 245 | |
| 246 | /* TX descriptor command */ |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 247 | #define TX_ENABLE_INTERRUPT 0x00800000 |
| 248 | #define GEN_CRC 0x00400000 |
| 249 | #define TX_FIRST_DESC 0x00200000 |
| 250 | #define TX_LAST_DESC 0x00100000 |
| 251 | #define ZERO_PADDING 0x00080000 |
| 252 | #define GEN_IP_V4_CHECKSUM 0x00040000 |
| 253 | #define GEN_TCP_UDP_CHECKSUM 0x00020000 |
| 254 | #define UDP_FRAME 0x00010000 |
Lennert Buytenhek | e32b661 | 2008-07-24 06:22:59 +0200 | [diff] [blame] | 255 | #define MAC_HDR_EXTRA_4_BYTES 0x00008000 |
| 256 | #define MAC_HDR_EXTRA_8_BYTES 0x00000200 |
Lennert Buytenhek | 7ca72a3 | 2008-06-01 01:41:29 +0200 | [diff] [blame] | 257 | |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 258 | #define TX_IHL_SHIFT 11 |
Lennert Buytenhek | 7ca72a3 | 2008-06-01 01:41:29 +0200 | [diff] [blame] | 259 | |
| 260 | |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 261 | /* global *******************************************************************/ |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 262 | struct mv643xx_eth_shared_private { |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 263 | /* |
| 264 | * Ethernet controller base address. |
| 265 | */ |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 266 | void __iomem *base; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 267 | |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 268 | /* |
Lennert Buytenhek | fc0eb9f | 2008-08-26 12:56:56 +0200 | [diff] [blame] | 269 | * Points at the right SMI instance to use. |
| 270 | */ |
| 271 | struct mv643xx_eth_shared_private *smi; |
| 272 | |
| 273 | /* |
Lennert Buytenhek | ed94493 | 2008-08-26 13:34:19 +0200 | [diff] [blame] | 274 | * Provides access to local SMI interface. |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 275 | */ |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 276 | struct mii_bus *smi_bus; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 277 | |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 278 | /* |
Lennert Buytenhek | 45c5d3b | 2008-08-26 04:42:59 +0200 | [diff] [blame] | 279 | * If we have access to the error interrupt pin (which is |
| 280 | * somewhat misnamed as it not only reflects internal errors |
| 281 | * but also reflects SMI completion), use that to wait for |
| 282 | * SMI access completion instead of polling the SMI busy bit. |
| 283 | */ |
| 284 | int err_interrupt; |
| 285 | wait_queue_head_t smi_busy_wait; |
| 286 | |
| 287 | /* |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 288 | * Per-port MBUS window access register value. |
| 289 | */ |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 290 | u32 win_protect; |
| 291 | |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 292 | /* |
| 293 | * Hardware-specific parameters. |
| 294 | */ |
Lennert Buytenhek | 773fc3e | 2008-06-02 01:54:16 +0200 | [diff] [blame] | 295 | int extended_rx_coal_limit; |
Lennert Buytenhek | 457b1d5 | 2008-09-04 12:22:34 +0200 | [diff] [blame] | 296 | int tx_bw_control; |
Saeed Bishara | 9b2c2ff | 2010-06-27 00:26:43 +0000 | [diff] [blame] | 297 | int tx_csum_limit; |
Andrew Lunn | 452503e | 2011-12-24 01:24:24 +0100 | [diff] [blame] | 298 | |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 299 | }; |
| 300 | |
Lennert Buytenhek | 457b1d5 | 2008-09-04 12:22:34 +0200 | [diff] [blame] | 301 | #define TX_BW_CONTROL_ABSENT 0 |
| 302 | #define TX_BW_CONTROL_OLD_LAYOUT 1 |
| 303 | #define TX_BW_CONTROL_NEW_LAYOUT 2 |
| 304 | |
Lennert Buytenhek | e7d2f4d | 2009-02-12 14:07:37 +0000 | [diff] [blame] | 305 | static int mv643xx_eth_open(struct net_device *dev); |
| 306 | static int mv643xx_eth_stop(struct net_device *dev); |
| 307 | |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 308 | |
| 309 | /* per-port *****************************************************************/ |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 310 | struct mib_counters { |
Lennert Buytenhek | fbd6a75 | 2007-10-19 16:03:46 +0200 | [diff] [blame] | 311 | u64 good_octets_received; |
| 312 | u32 bad_octets_received; |
| 313 | u32 internal_mac_transmit_err; |
| 314 | u32 good_frames_received; |
| 315 | u32 bad_frames_received; |
| 316 | u32 broadcast_frames_received; |
| 317 | u32 multicast_frames_received; |
| 318 | u32 frames_64_octets; |
| 319 | u32 frames_65_to_127_octets; |
| 320 | u32 frames_128_to_255_octets; |
| 321 | u32 frames_256_to_511_octets; |
| 322 | u32 frames_512_to_1023_octets; |
| 323 | u32 frames_1024_to_max_octets; |
| 324 | u64 good_octets_sent; |
| 325 | u32 good_frames_sent; |
| 326 | u32 excessive_collision; |
| 327 | u32 multicast_frames_sent; |
| 328 | u32 broadcast_frames_sent; |
| 329 | u32 unrec_mac_control_received; |
| 330 | u32 fc_sent; |
| 331 | u32 good_fc_received; |
| 332 | u32 bad_fc_received; |
| 333 | u32 undersize_received; |
| 334 | u32 fragments_received; |
| 335 | u32 oversize_received; |
| 336 | u32 jabber_received; |
| 337 | u32 mac_receive_error; |
| 338 | u32 bad_crc_event; |
| 339 | u32 collision; |
| 340 | u32 late_collision; |
Paulius Zaleckas | 302476c | 2012-01-23 01:16:35 +0000 | [diff] [blame] | 341 | /* Non MIB hardware counters */ |
| 342 | u32 rx_discard; |
| 343 | u32 rx_overrun; |
Lennert Buytenhek | fbd6a75 | 2007-10-19 16:03:46 +0200 | [diff] [blame] | 344 | }; |
| 345 | |
Lennert Buytenhek | eaf5d59 | 2009-02-12 14:08:39 +0000 | [diff] [blame] | 346 | struct lro_counters { |
| 347 | u32 lro_aggregated; |
| 348 | u32 lro_flushed; |
| 349 | u32 lro_no_desc; |
| 350 | }; |
| 351 | |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 352 | struct rx_queue { |
Lennert Buytenhek | 64da80a | 2008-06-02 01:01:26 +0200 | [diff] [blame] | 353 | int index; |
| 354 | |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 355 | int rx_ring_size; |
| 356 | |
| 357 | int rx_desc_count; |
| 358 | int rx_curr_desc; |
| 359 | int rx_used_desc; |
| 360 | |
| 361 | struct rx_desc *rx_desc_area; |
| 362 | dma_addr_t rx_desc_dma; |
| 363 | int rx_desc_area_size; |
| 364 | struct sk_buff **rx_skb; |
Lennert Buytenhek | eaf5d59 | 2009-02-12 14:08:39 +0000 | [diff] [blame] | 365 | |
Lennert Buytenhek | eaf5d59 | 2009-02-12 14:08:39 +0000 | [diff] [blame] | 366 | struct net_lro_mgr lro_mgr; |
| 367 | struct net_lro_desc lro_arr[8]; |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 368 | }; |
| 369 | |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 370 | struct tx_queue { |
Lennert Buytenhek | 3d6b35b | 2008-06-02 01:28:22 +0200 | [diff] [blame] | 371 | int index; |
| 372 | |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 373 | int tx_ring_size; |
| 374 | |
| 375 | int tx_desc_count; |
| 376 | int tx_curr_desc; |
| 377 | int tx_used_desc; |
| 378 | |
| 379 | struct tx_desc *tx_desc_area; |
| 380 | dma_addr_t tx_desc_dma; |
| 381 | int tx_desc_area_size; |
Lennert Buytenhek | 99ab08e | 2008-08-28 05:53:18 +0200 | [diff] [blame] | 382 | |
| 383 | struct sk_buff_head tx_skb; |
Lennert Buytenhek | 8fd8921 | 2008-08-28 08:26:28 +0200 | [diff] [blame] | 384 | |
| 385 | unsigned long tx_packets; |
| 386 | unsigned long tx_bytes; |
| 387 | unsigned long tx_dropped; |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 388 | }; |
| 389 | |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 390 | struct mv643xx_eth_private { |
| 391 | struct mv643xx_eth_shared_private *shared; |
Lennert Buytenhek | 37a6084 | 2008-11-20 03:57:36 -0800 | [diff] [blame] | 392 | void __iomem *base; |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 393 | int port_num; |
Lennert Buytenhek | fbd6a75 | 2007-10-19 16:03:46 +0200 | [diff] [blame] | 394 | |
| 395 | struct net_device *dev; |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 396 | |
Lennert Buytenhek | ed94493 | 2008-08-26 13:34:19 +0200 | [diff] [blame] | 397 | struct phy_device *phy; |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 398 | |
Lennert Buytenhek | 4ff3495 | 2008-09-19 05:04:57 +0200 | [diff] [blame] | 399 | struct timer_list mib_counters_timer; |
| 400 | spinlock_t mib_counters_lock; |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 401 | struct mib_counters mib_counters; |
Lennert Buytenhek | 4ff3495 | 2008-09-19 05:04:57 +0200 | [diff] [blame] | 402 | |
Lennert Buytenhek | eaf5d59 | 2009-02-12 14:08:39 +0000 | [diff] [blame] | 403 | struct lro_counters lro_counters; |
| 404 | |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 405 | struct work_struct tx_timeout_task; |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 406 | |
Lennert Buytenhek | 1fa38c5 | 2008-08-28 08:09:10 +0200 | [diff] [blame] | 407 | struct napi_struct napi; |
Saeed Bishara | e0ca841 | 2009-05-06 03:02:01 +0000 | [diff] [blame] | 408 | u32 int_mask; |
Lennert Buytenhek | 1319eba | 2009-04-29 11:57:34 +0000 | [diff] [blame] | 409 | u8 oom; |
Lennert Buytenhek | 1fa38c5 | 2008-08-28 08:09:10 +0200 | [diff] [blame] | 410 | u8 work_link; |
| 411 | u8 work_tx; |
| 412 | u8 work_tx_end; |
| 413 | u8 work_rx; |
| 414 | u8 work_rx_refill; |
Lennert Buytenhek | 1fa38c5 | 2008-08-28 08:09:10 +0200 | [diff] [blame] | 415 | |
Lennert Buytenhek | 2bcb4b0 | 2008-10-01 02:33:57 -0700 | [diff] [blame] | 416 | int skb_size; |
Lennert Buytenhek | 2bcb4b0 | 2008-10-01 02:33:57 -0700 | [diff] [blame] | 417 | |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 418 | /* |
| 419 | * RX state. |
| 420 | */ |
Lennert Buytenhek | e7d2f4d | 2009-02-12 14:07:37 +0000 | [diff] [blame] | 421 | int rx_ring_size; |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 422 | unsigned long rx_desc_sram_addr; |
| 423 | int rx_desc_sram_size; |
Lennert Buytenhek | f7981c1 | 2008-08-26 10:23:22 +0200 | [diff] [blame] | 424 | int rxq_count; |
Lennert Buytenhek | 2257e05 | 2008-08-24 04:33:36 +0200 | [diff] [blame] | 425 | struct timer_list rx_oom; |
Lennert Buytenhek | 64da80a | 2008-06-02 01:01:26 +0200 | [diff] [blame] | 426 | struct rx_queue rxq[8]; |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 427 | |
| 428 | /* |
| 429 | * TX state. |
| 430 | */ |
Lennert Buytenhek | e7d2f4d | 2009-02-12 14:07:37 +0000 | [diff] [blame] | 431 | int tx_ring_size; |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 432 | unsigned long tx_desc_sram_addr; |
| 433 | int tx_desc_sram_size; |
Lennert Buytenhek | f7981c1 | 2008-08-26 10:23:22 +0200 | [diff] [blame] | 434 | int txq_count; |
Lennert Buytenhek | 3d6b35b | 2008-06-02 01:28:22 +0200 | [diff] [blame] | 435 | struct tx_queue txq[8]; |
Andrew Lunn | 452503e | 2011-12-24 01:24:24 +0100 | [diff] [blame] | 436 | |
| 437 | /* |
| 438 | * Hardware-specific parameters. |
| 439 | */ |
Andrew Lunn | 9a43a02 | 2012-06-06 06:40:43 +0000 | [diff] [blame] | 440 | #if defined(CONFIG_HAVE_CLK) |
Andrew Lunn | 452503e | 2011-12-24 01:24:24 +0100 | [diff] [blame] | 441 | struct clk *clk; |
Andrew Lunn | 9a43a02 | 2012-06-06 06:40:43 +0000 | [diff] [blame] | 442 | #endif |
Andrew Lunn | 452503e | 2011-12-24 01:24:24 +0100 | [diff] [blame] | 443 | unsigned int t_clk; |
Lennert Buytenhek | fbd6a75 | 2007-10-19 16:03:46 +0200 | [diff] [blame] | 444 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | |
Lennert Buytenhek | fbd6a75 | 2007-10-19 16:03:46 +0200 | [diff] [blame] | 446 | |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 447 | /* port register accessors **************************************************/ |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 448 | static inline u32 rdl(struct mv643xx_eth_private *mp, int offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | { |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 450 | return readl(mp->shared->base + offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | } |
| 452 | |
Lennert Buytenhek | 37a6084 | 2008-11-20 03:57:36 -0800 | [diff] [blame] | 453 | static inline u32 rdlp(struct mv643xx_eth_private *mp, int offset) |
| 454 | { |
| 455 | return readl(mp->base + offset); |
| 456 | } |
| 457 | |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 458 | static inline void wrl(struct mv643xx_eth_private *mp, int offset, u32 data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | { |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 460 | writel(data, mp->shared->base + offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | } |
| 462 | |
Lennert Buytenhek | 37a6084 | 2008-11-20 03:57:36 -0800 | [diff] [blame] | 463 | static inline void wrlp(struct mv643xx_eth_private *mp, int offset, u32 data) |
| 464 | { |
| 465 | writel(data, mp->base + offset); |
| 466 | } |
| 467 | |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 468 | |
| 469 | /* rxq/txq helper functions *************************************************/ |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 470 | static struct mv643xx_eth_private *rxq_to_mp(struct rx_queue *rxq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | { |
Lennert Buytenhek | 64da80a | 2008-06-02 01:01:26 +0200 | [diff] [blame] | 472 | return container_of(rxq, struct mv643xx_eth_private, rxq[rxq->index]); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 473 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 475 | static struct mv643xx_eth_private *txq_to_mp(struct tx_queue *txq) |
| 476 | { |
Lennert Buytenhek | 3d6b35b | 2008-06-02 01:28:22 +0200 | [diff] [blame] | 477 | return container_of(txq, struct mv643xx_eth_private, txq[txq->index]); |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 478 | } |
| 479 | |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 480 | static void rxq_enable(struct rx_queue *rxq) |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 481 | { |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 482 | struct mv643xx_eth_private *mp = rxq_to_mp(rxq); |
Lennert Buytenhek | 37a6084 | 2008-11-20 03:57:36 -0800 | [diff] [blame] | 483 | wrlp(mp, RXQ_COMMAND, 1 << rxq->index); |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 484 | } |
Lennert Buytenhek | c0d0f2c | 2008-03-18 11:34:34 -0700 | [diff] [blame] | 485 | |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 486 | static void rxq_disable(struct rx_queue *rxq) |
| 487 | { |
| 488 | struct mv643xx_eth_private *mp = rxq_to_mp(rxq); |
Lennert Buytenhek | 64da80a | 2008-06-02 01:01:26 +0200 | [diff] [blame] | 489 | u8 mask = 1 << rxq->index; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 490 | |
Lennert Buytenhek | 37a6084 | 2008-11-20 03:57:36 -0800 | [diff] [blame] | 491 | wrlp(mp, RXQ_COMMAND, mask << 8); |
| 492 | while (rdlp(mp, RXQ_COMMAND) & mask) |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 493 | udelay(10); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 494 | } |
| 495 | |
Lennert Buytenhek | 6b368f6 | 2008-07-11 19:38:34 +0200 | [diff] [blame] | 496 | static void txq_reset_hw_ptr(struct tx_queue *txq) |
| 497 | { |
| 498 | struct mv643xx_eth_private *mp = txq_to_mp(txq); |
Lennert Buytenhek | 6b368f6 | 2008-07-11 19:38:34 +0200 | [diff] [blame] | 499 | u32 addr; |
| 500 | |
| 501 | addr = (u32)txq->tx_desc_dma; |
| 502 | addr += txq->tx_curr_desc * sizeof(struct tx_desc); |
Lennert Buytenhek | 37a6084 | 2008-11-20 03:57:36 -0800 | [diff] [blame] | 503 | wrlp(mp, TXQ_CURRENT_DESC_PTR(txq->index), addr); |
Lennert Buytenhek | 6b368f6 | 2008-07-11 19:38:34 +0200 | [diff] [blame] | 504 | } |
| 505 | |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 506 | static void txq_enable(struct tx_queue *txq) |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 507 | { |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 508 | struct mv643xx_eth_private *mp = txq_to_mp(txq); |
Lennert Buytenhek | 37a6084 | 2008-11-20 03:57:36 -0800 | [diff] [blame] | 509 | wrlp(mp, TXQ_COMMAND, 1 << txq->index); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 510 | } |
| 511 | |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 512 | static void txq_disable(struct tx_queue *txq) |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 513 | { |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 514 | struct mv643xx_eth_private *mp = txq_to_mp(txq); |
Lennert Buytenhek | 3d6b35b | 2008-06-02 01:28:22 +0200 | [diff] [blame] | 515 | u8 mask = 1 << txq->index; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 516 | |
Lennert Buytenhek | 37a6084 | 2008-11-20 03:57:36 -0800 | [diff] [blame] | 517 | wrlp(mp, TXQ_COMMAND, mask << 8); |
| 518 | while (rdlp(mp, TXQ_COMMAND) & mask) |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 519 | udelay(10); |
| 520 | } |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 521 | |
Lennert Buytenhek | 1fa38c5 | 2008-08-28 08:09:10 +0200 | [diff] [blame] | 522 | static void txq_maybe_wake(struct tx_queue *txq) |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 523 | { |
| 524 | struct mv643xx_eth_private *mp = txq_to_mp(txq); |
Lennert Buytenhek | e5ef1de | 2008-08-28 06:26:23 +0200 | [diff] [blame] | 525 | struct netdev_queue *nq = netdev_get_tx_queue(mp->dev, txq->index); |
Lennert Buytenhek | 3d6b35b | 2008-06-02 01:28:22 +0200 | [diff] [blame] | 526 | |
Lennert Buytenhek | 8fd8921 | 2008-08-28 08:26:28 +0200 | [diff] [blame] | 527 | if (netif_tx_queue_stopped(nq)) { |
| 528 | __netif_tx_lock(nq, smp_processor_id()); |
| 529 | if (txq->tx_ring_size - txq->tx_desc_count >= MAX_SKB_FRAGS + 1) |
| 530 | netif_tx_wake_queue(nq); |
| 531 | __netif_tx_unlock(nq); |
| 532 | } |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 533 | } |
| 534 | |
| 535 | |
Lennert Buytenhek | 1fa38c5 | 2008-08-28 08:09:10 +0200 | [diff] [blame] | 536 | /* rx napi ******************************************************************/ |
Lennert Buytenhek | eaf5d59 | 2009-02-12 14:08:39 +0000 | [diff] [blame] | 537 | static int |
| 538 | mv643xx_get_skb_header(struct sk_buff *skb, void **iphdr, void **tcph, |
| 539 | u64 *hdr_flags, void *priv) |
| 540 | { |
| 541 | unsigned long cmd_sts = (unsigned long)priv; |
| 542 | |
| 543 | /* |
| 544 | * Make sure that this packet is Ethernet II, is not VLAN |
| 545 | * tagged, is IPv4, has a valid IP header, and is TCP. |
| 546 | */ |
| 547 | if ((cmd_sts & (RX_IP_HDR_OK | RX_PKT_IS_IPV4 | |
| 548 | RX_PKT_IS_ETHERNETV2 | RX_PKT_LAYER4_TYPE_MASK | |
| 549 | RX_PKT_IS_VLAN_TAGGED)) != |
| 550 | (RX_IP_HDR_OK | RX_PKT_IS_IPV4 | |
| 551 | RX_PKT_IS_ETHERNETV2 | RX_PKT_LAYER4_TYPE_TCP_IPV4)) |
| 552 | return -1; |
| 553 | |
| 554 | skb_reset_network_header(skb); |
| 555 | skb_set_transport_header(skb, ip_hdrlen(skb)); |
| 556 | *iphdr = ip_hdr(skb); |
| 557 | *tcph = tcp_hdr(skb); |
| 558 | *hdr_flags = LRO_IPV4 | LRO_TCP; |
| 559 | |
| 560 | return 0; |
| 561 | } |
Lennert Buytenhek | eaf5d59 | 2009-02-12 14:08:39 +0000 | [diff] [blame] | 562 | |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 563 | static int rxq_process(struct rx_queue *rxq, int budget) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | { |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 565 | struct mv643xx_eth_private *mp = rxq_to_mp(rxq); |
| 566 | struct net_device_stats *stats = &mp->dev->stats; |
Lennert Buytenhek | eaf5d59 | 2009-02-12 14:08:39 +0000 | [diff] [blame] | 567 | int lro_flush_needed; |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 568 | int rx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | |
Lennert Buytenhek | eaf5d59 | 2009-02-12 14:08:39 +0000 | [diff] [blame] | 570 | lro_flush_needed = 0; |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 571 | rx = 0; |
Lennert Buytenhek | 9e1f377 | 2008-08-24 02:33:47 +0200 | [diff] [blame] | 572 | while (rx < budget && rxq->rx_desc_count) { |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 573 | struct rx_desc *rx_desc; |
Lennert Buytenhek | 9658766 | 2008-06-01 10:31:56 +0200 | [diff] [blame] | 574 | unsigned int cmd_sts; |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 575 | struct sk_buff *skb; |
Lennert Buytenhek | 6b8f90c | 2008-09-14 15:50:32 +0200 | [diff] [blame] | 576 | u16 byte_cnt; |
Lennert Buytenhek | 9658766 | 2008-06-01 10:31:56 +0200 | [diff] [blame] | 577 | |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 578 | rx_desc = &rxq->rx_desc_area[rxq->rx_curr_desc]; |
Lennert Buytenhek | 9658766 | 2008-06-01 10:31:56 +0200 | [diff] [blame] | 579 | |
| 580 | cmd_sts = rx_desc->cmd_sts; |
Lennert Buytenhek | 2257e05 | 2008-08-24 04:33:36 +0200 | [diff] [blame] | 581 | if (cmd_sts & BUFFER_OWNED_BY_DMA) |
Lennert Buytenhek | 9658766 | 2008-06-01 10:31:56 +0200 | [diff] [blame] | 582 | break; |
Lennert Buytenhek | 9658766 | 2008-06-01 10:31:56 +0200 | [diff] [blame] | 583 | rmb(); |
| 584 | |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 585 | skb = rxq->rx_skb[rxq->rx_curr_desc]; |
| 586 | rxq->rx_skb[rxq->rx_curr_desc] = NULL; |
Lennert Buytenhek | 9658766 | 2008-06-01 10:31:56 +0200 | [diff] [blame] | 587 | |
Lennert Buytenhek | 9da7874 | 2008-08-23 23:45:28 +0200 | [diff] [blame] | 588 | rxq->rx_curr_desc++; |
| 589 | if (rxq->rx_curr_desc == rxq->rx_ring_size) |
| 590 | rxq->rx_curr_desc = 0; |
Lennert Buytenhek | 9658766 | 2008-06-01 10:31:56 +0200 | [diff] [blame] | 591 | |
Gabriel Paubert | eb0519b | 2009-05-17 21:16:47 -0700 | [diff] [blame] | 592 | dma_unmap_single(mp->dev->dev.parent, rx_desc->buf_ptr, |
Lennert Buytenhek | abe7871 | 2008-08-24 03:00:20 +0200 | [diff] [blame] | 593 | rx_desc->buf_size, DMA_FROM_DEVICE); |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 594 | rxq->rx_desc_count--; |
| 595 | rx++; |
Dale Farnsworth | b1dd9ca | 2005-09-01 09:59:23 -0700 | [diff] [blame] | 596 | |
Lennert Buytenhek | 1fa38c5 | 2008-08-28 08:09:10 +0200 | [diff] [blame] | 597 | mp->work_rx_refill |= 1 << rxq->index; |
| 598 | |
Lennert Buytenhek | 6b8f90c | 2008-09-14 15:50:32 +0200 | [diff] [blame] | 599 | byte_cnt = rx_desc->byte_cnt; |
| 600 | |
Dale Farnsworth | 468d09f | 2006-03-03 10:04:39 -0700 | [diff] [blame] | 601 | /* |
| 602 | * Update statistics. |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 603 | * |
| 604 | * Note that the descriptor byte count includes 2 dummy |
| 605 | * bytes automatically inserted by the hardware at the |
| 606 | * start of the packet (which we don't count), and a 4 |
| 607 | * byte CRC at the end of the packet (which we do count). |
Dale Farnsworth | 468d09f | 2006-03-03 10:04:39 -0700 | [diff] [blame] | 608 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | stats->rx_packets++; |
Lennert Buytenhek | 6b8f90c | 2008-09-14 15:50:32 +0200 | [diff] [blame] | 610 | stats->rx_bytes += byte_cnt - 2; |
Lennert Buytenhek | 9658766 | 2008-06-01 10:31:56 +0200 | [diff] [blame] | 611 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | /* |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 613 | * In case we received a packet without first / last bits |
| 614 | * on, or the error summary bit is set, the packet needs |
| 615 | * to be dropped. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | */ |
Lennert Buytenhek | f61e554 | 2008-11-20 03:58:46 -0800 | [diff] [blame] | 617 | if ((cmd_sts & (RX_FIRST_DESC | RX_LAST_DESC | ERROR_SUMMARY)) |
| 618 | != (RX_FIRST_DESC | RX_LAST_DESC)) |
| 619 | goto err; |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 620 | |
Lennert Buytenhek | f61e554 | 2008-11-20 03:58:46 -0800 | [diff] [blame] | 621 | /* |
| 622 | * The -4 is for the CRC in the trailer of the |
| 623 | * received packet |
| 624 | */ |
| 625 | skb_put(skb, byte_cnt - 2 - 4); |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 626 | |
Lennert Buytenhek | f61e554 | 2008-11-20 03:58:46 -0800 | [diff] [blame] | 627 | if (cmd_sts & LAYER_4_CHECKSUM_OK) |
| 628 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 629 | skb->protocol = eth_type_trans(skb, mp->dev); |
Lennert Buytenhek | eaf5d59 | 2009-02-12 14:08:39 +0000 | [diff] [blame] | 630 | |
Lennert Buytenhek | eaf5d59 | 2009-02-12 14:08:39 +0000 | [diff] [blame] | 631 | if (skb->dev->features & NETIF_F_LRO && |
| 632 | skb->ip_summed == CHECKSUM_UNNECESSARY) { |
| 633 | lro_receive_skb(&rxq->lro_mgr, skb, (void *)cmd_sts); |
| 634 | lro_flush_needed = 1; |
| 635 | } else |
Lennert Buytenhek | eaf5d59 | 2009-02-12 14:08:39 +0000 | [diff] [blame] | 636 | netif_receive_skb(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 | |
Lennert Buytenhek | f61e554 | 2008-11-20 03:58:46 -0800 | [diff] [blame] | 638 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | |
Lennert Buytenhek | f61e554 | 2008-11-20 03:58:46 -0800 | [diff] [blame] | 640 | err: |
| 641 | stats->rx_dropped++; |
| 642 | |
| 643 | if ((cmd_sts & (RX_FIRST_DESC | RX_LAST_DESC)) != |
| 644 | (RX_FIRST_DESC | RX_LAST_DESC)) { |
| 645 | if (net_ratelimit()) |
Joe Perches | 7542db8 | 2011-03-02 17:50:35 +0000 | [diff] [blame] | 646 | netdev_err(mp->dev, |
| 647 | "received packet spanning multiple descriptors\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | } |
Lennert Buytenhek | f61e554 | 2008-11-20 03:58:46 -0800 | [diff] [blame] | 649 | |
| 650 | if (cmd_sts & ERROR_SUMMARY) |
| 651 | stats->rx_errors++; |
| 652 | |
| 653 | dev_kfree_skb(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | } |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 655 | |
Lennert Buytenhek | eaf5d59 | 2009-02-12 14:08:39 +0000 | [diff] [blame] | 656 | if (lro_flush_needed) |
| 657 | lro_flush_all(&rxq->lro_mgr); |
Lennert Buytenhek | eaf5d59 | 2009-02-12 14:08:39 +0000 | [diff] [blame] | 658 | |
Lennert Buytenhek | 1fa38c5 | 2008-08-28 08:09:10 +0200 | [diff] [blame] | 659 | if (rx < budget) |
| 660 | mp->work_rx &= ~(1 << rxq->index); |
| 661 | |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 662 | return rx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 | } |
| 664 | |
Lennert Buytenhek | 1fa38c5 | 2008-08-28 08:09:10 +0200 | [diff] [blame] | 665 | static int rxq_refill(struct rx_queue *rxq, int budget) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | { |
Lennert Buytenhek | 1fa38c5 | 2008-08-28 08:09:10 +0200 | [diff] [blame] | 667 | struct mv643xx_eth_private *mp = rxq_to_mp(rxq); |
Lennert Buytenhek | 1fa38c5 | 2008-08-28 08:09:10 +0200 | [diff] [blame] | 668 | int refilled; |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 669 | |
Lennert Buytenhek | 1fa38c5 | 2008-08-28 08:09:10 +0200 | [diff] [blame] | 670 | refilled = 0; |
| 671 | while (refilled < budget && rxq->rx_desc_count < rxq->rx_ring_size) { |
| 672 | struct sk_buff *skb; |
Lennert Buytenhek | 1fa38c5 | 2008-08-28 08:09:10 +0200 | [diff] [blame] | 673 | int rx; |
Lennert Buytenhek | 5377152 | 2008-11-20 03:59:04 -0800 | [diff] [blame] | 674 | struct rx_desc *rx_desc; |
Saeed Bishara | 530e557 | 2010-01-05 09:15:32 +0000 | [diff] [blame] | 675 | int size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | |
Eric Dumazet | acb600d | 2012-10-05 06:23:55 +0000 | [diff] [blame] | 677 | skb = netdev_alloc_skb(mp->dev, mp->skb_size); |
Lennert Buytenhek | 2bcb4b0 | 2008-10-01 02:33:57 -0700 | [diff] [blame] | 678 | |
Lennert Buytenhek | 1fa38c5 | 2008-08-28 08:09:10 +0200 | [diff] [blame] | 679 | if (skb == NULL) { |
Lennert Buytenhek | 1319eba | 2009-04-29 11:57:34 +0000 | [diff] [blame] | 680 | mp->oom = 1; |
Lennert Buytenhek | 1fa38c5 | 2008-08-28 08:09:10 +0200 | [diff] [blame] | 681 | goto oom; |
| 682 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | |
Lennert Buytenhek | 7fd96ce | 2009-05-06 03:01:22 +0000 | [diff] [blame] | 684 | if (SKB_DMA_REALIGN) |
| 685 | skb_reserve(skb, SKB_DMA_REALIGN); |
Lennert Buytenhek | 1fa38c5 | 2008-08-28 08:09:10 +0200 | [diff] [blame] | 686 | |
| 687 | refilled++; |
| 688 | rxq->rx_desc_count++; |
| 689 | |
| 690 | rx = rxq->rx_used_desc++; |
| 691 | if (rxq->rx_used_desc == rxq->rx_ring_size) |
| 692 | rxq->rx_used_desc = 0; |
| 693 | |
Lennert Buytenhek | 5377152 | 2008-11-20 03:59:04 -0800 | [diff] [blame] | 694 | rx_desc = rxq->rx_desc_area + rx; |
| 695 | |
Saeed Bishara | 530e557 | 2010-01-05 09:15:32 +0000 | [diff] [blame] | 696 | size = skb->end - skb->data; |
Gabriel Paubert | eb0519b | 2009-05-17 21:16:47 -0700 | [diff] [blame] | 697 | rx_desc->buf_ptr = dma_map_single(mp->dev->dev.parent, |
Saeed Bishara | 530e557 | 2010-01-05 09:15:32 +0000 | [diff] [blame] | 698 | skb->data, size, |
Gabriel Paubert | eb0519b | 2009-05-17 21:16:47 -0700 | [diff] [blame] | 699 | DMA_FROM_DEVICE); |
Saeed Bishara | 530e557 | 2010-01-05 09:15:32 +0000 | [diff] [blame] | 700 | rx_desc->buf_size = size; |
Lennert Buytenhek | 1fa38c5 | 2008-08-28 08:09:10 +0200 | [diff] [blame] | 701 | rxq->rx_skb[rx] = skb; |
| 702 | wmb(); |
Lennert Buytenhek | 5377152 | 2008-11-20 03:59:04 -0800 | [diff] [blame] | 703 | rx_desc->cmd_sts = BUFFER_OWNED_BY_DMA | RX_ENABLE_INTERRUPT; |
Lennert Buytenhek | 1fa38c5 | 2008-08-28 08:09:10 +0200 | [diff] [blame] | 704 | wmb(); |
| 705 | |
| 706 | /* |
| 707 | * The hardware automatically prepends 2 bytes of |
| 708 | * dummy data to each received packet, so that the |
| 709 | * IP header ends up 16-byte aligned. |
| 710 | */ |
| 711 | skb_reserve(skb, 2); |
Lennert Buytenhek | 2257e05 | 2008-08-24 04:33:36 +0200 | [diff] [blame] | 712 | } |
| 713 | |
Lennert Buytenhek | 1fa38c5 | 2008-08-28 08:09:10 +0200 | [diff] [blame] | 714 | if (refilled < budget) |
| 715 | mp->work_rx_refill &= ~(1 << rxq->index); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | |
Lennert Buytenhek | 1fa38c5 | 2008-08-28 08:09:10 +0200 | [diff] [blame] | 717 | oom: |
| 718 | return refilled; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 721 | |
| 722 | /* tx ***********************************************************************/ |
Paul Janzen | f7ea333 | 2006-01-16 16:52:13 -0700 | [diff] [blame] | 723 | static inline unsigned int has_tiny_unaligned_frags(struct sk_buff *skb) |
| 724 | { |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 725 | int frag; |
Paul Janzen | f7ea333 | 2006-01-16 16:52:13 -0700 | [diff] [blame] | 726 | |
Dale Farnsworth | b4de905 | 2006-01-27 01:04:43 -0700 | [diff] [blame] | 727 | for (frag = 0; frag < skb_shinfo(skb)->nr_frags; frag++) { |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 728 | const skb_frag_t *fragp = &skb_shinfo(skb)->frags[frag]; |
| 729 | |
| 730 | if (skb_frag_size(fragp) <= 8 && fragp->page_offset & 7) |
Dale Farnsworth | b4de905 | 2006-01-27 01:04:43 -0700 | [diff] [blame] | 731 | return 1; |
| 732 | } |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 733 | |
Dale Farnsworth | b4de905 | 2006-01-27 01:04:43 -0700 | [diff] [blame] | 734 | return 0; |
Paul Janzen | f7ea333 | 2006-01-16 16:52:13 -0700 | [diff] [blame] | 735 | } |
| 736 | |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 737 | static void txq_submit_frag_skb(struct tx_queue *txq, struct sk_buff *skb) |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 738 | { |
Gabriel Paubert | eb0519b | 2009-05-17 21:16:47 -0700 | [diff] [blame] | 739 | struct mv643xx_eth_private *mp = txq_to_mp(txq); |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 740 | int nr_frags = skb_shinfo(skb)->nr_frags; |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 741 | int frag; |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 742 | |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 743 | for (frag = 0; frag < nr_frags; frag++) { |
| 744 | skb_frag_t *this_frag; |
| 745 | int tx_index; |
| 746 | struct tx_desc *desc; |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 747 | |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 748 | this_frag = &skb_shinfo(skb)->frags[frag]; |
Lennert Buytenhek | 66823b9 | 2008-11-20 03:58:09 -0800 | [diff] [blame] | 749 | tx_index = txq->tx_curr_desc++; |
| 750 | if (txq->tx_curr_desc == txq->tx_ring_size) |
| 751 | txq->tx_curr_desc = 0; |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 752 | desc = &txq->tx_desc_area[tx_index]; |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 753 | |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 754 | /* |
| 755 | * The last fragment will generate an interrupt |
| 756 | * which will free the skb on TX completion. |
| 757 | */ |
| 758 | if (frag == nr_frags - 1) { |
| 759 | desc->cmd_sts = BUFFER_OWNED_BY_DMA | |
| 760 | ZERO_PADDING | TX_LAST_DESC | |
| 761 | TX_ENABLE_INTERRUPT; |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 762 | } else { |
| 763 | desc->cmd_sts = BUFFER_OWNED_BY_DMA; |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 764 | } |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 765 | |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 766 | desc->l4i_chk = 0; |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 767 | desc->byte_cnt = skb_frag_size(this_frag); |
Ian Campbell | f106358 | 2011-08-31 00:46:57 +0000 | [diff] [blame] | 768 | desc->buf_ptr = skb_frag_dma_map(mp->dev->dev.parent, |
| 769 | this_frag, 0, |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 770 | skb_frag_size(this_frag), |
Ian Campbell | f106358 | 2011-08-31 00:46:57 +0000 | [diff] [blame] | 771 | DMA_TO_DEVICE); |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 772 | } |
| 773 | } |
| 774 | |
Byron Bradley | 324ff2c | 2008-02-04 23:47:15 -0800 | [diff] [blame] | 775 | static inline __be16 sum16_as_be(__sum16 sum) |
| 776 | { |
| 777 | return (__force __be16)sum; |
| 778 | } |
| 779 | |
Lennert Buytenhek | 4df89bd | 2008-09-19 04:05:00 +0200 | [diff] [blame] | 780 | static int txq_submit_skb(struct tx_queue *txq, struct sk_buff *skb) |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 781 | { |
Lennert Buytenhek | 8fa89bf | 2008-07-14 22:56:55 +0200 | [diff] [blame] | 782 | struct mv643xx_eth_private *mp = txq_to_mp(txq); |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 783 | int nr_frags = skb_shinfo(skb)->nr_frags; |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 784 | int tx_index; |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 785 | struct tx_desc *desc; |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 786 | u32 cmd_sts; |
Lennert Buytenhek | 4df89bd | 2008-09-19 04:05:00 +0200 | [diff] [blame] | 787 | u16 l4i_chk; |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 788 | int length; |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 789 | |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 790 | cmd_sts = TX_FIRST_DESC | GEN_CRC | BUFFER_OWNED_BY_DMA; |
Lennert Buytenhek | 4df89bd | 2008-09-19 04:05:00 +0200 | [diff] [blame] | 791 | l4i_chk = 0; |
| 792 | |
| 793 | if (skb->ip_summed == CHECKSUM_PARTIAL) { |
Saeed Bishara | 9b2c2ff | 2010-06-27 00:26:43 +0000 | [diff] [blame] | 794 | int hdr_len; |
Lennert Buytenhek | 4df89bd | 2008-09-19 04:05:00 +0200 | [diff] [blame] | 795 | int tag_bytes; |
| 796 | |
| 797 | BUG_ON(skb->protocol != htons(ETH_P_IP) && |
| 798 | skb->protocol != htons(ETH_P_8021Q)); |
| 799 | |
Saeed Bishara | 9b2c2ff | 2010-06-27 00:26:43 +0000 | [diff] [blame] | 800 | hdr_len = (void *)ip_hdr(skb) - (void *)skb->data; |
| 801 | tag_bytes = hdr_len - ETH_HLEN; |
| 802 | if (skb->len - hdr_len > mp->shared->tx_csum_limit || |
| 803 | unlikely(tag_bytes & ~12)) { |
Lennert Buytenhek | 4df89bd | 2008-09-19 04:05:00 +0200 | [diff] [blame] | 804 | if (skb_checksum_help(skb) == 0) |
| 805 | goto no_csum; |
| 806 | kfree_skb(skb); |
| 807 | return 1; |
| 808 | } |
| 809 | |
| 810 | if (tag_bytes & 4) |
| 811 | cmd_sts |= MAC_HDR_EXTRA_4_BYTES; |
| 812 | if (tag_bytes & 8) |
| 813 | cmd_sts |= MAC_HDR_EXTRA_8_BYTES; |
| 814 | |
| 815 | cmd_sts |= GEN_TCP_UDP_CHECKSUM | |
| 816 | GEN_IP_V4_CHECKSUM | |
| 817 | ip_hdr(skb)->ihl << TX_IHL_SHIFT; |
| 818 | |
| 819 | switch (ip_hdr(skb)->protocol) { |
| 820 | case IPPROTO_UDP: |
| 821 | cmd_sts |= UDP_FRAME; |
| 822 | l4i_chk = ntohs(sum16_as_be(udp_hdr(skb)->check)); |
| 823 | break; |
| 824 | case IPPROTO_TCP: |
| 825 | l4i_chk = ntohs(sum16_as_be(tcp_hdr(skb)->check)); |
| 826 | break; |
| 827 | default: |
| 828 | BUG(); |
| 829 | } |
| 830 | } else { |
| 831 | no_csum: |
| 832 | /* Errata BTS #50, IHL must be 5 if no HW checksum */ |
| 833 | cmd_sts |= 5 << TX_IHL_SHIFT; |
| 834 | } |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 835 | |
Lennert Buytenhek | 66823b9 | 2008-11-20 03:58:09 -0800 | [diff] [blame] | 836 | tx_index = txq->tx_curr_desc++; |
| 837 | if (txq->tx_curr_desc == txq->tx_ring_size) |
| 838 | txq->tx_curr_desc = 0; |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 839 | desc = &txq->tx_desc_area[tx_index]; |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 840 | |
Dale Farnsworth | ff561ee | 2006-03-03 10:02:51 -0700 | [diff] [blame] | 841 | if (nr_frags) { |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 842 | txq_submit_frag_skb(txq, skb); |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 843 | length = skb_headlen(skb); |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 844 | } else { |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 845 | cmd_sts |= ZERO_PADDING | TX_LAST_DESC | TX_ENABLE_INTERRUPT; |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 846 | length = skb->len; |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 847 | } |
| 848 | |
Lennert Buytenhek | 4df89bd | 2008-09-19 04:05:00 +0200 | [diff] [blame] | 849 | desc->l4i_chk = l4i_chk; |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 850 | desc->byte_cnt = length; |
Gabriel Paubert | eb0519b | 2009-05-17 21:16:47 -0700 | [diff] [blame] | 851 | desc->buf_ptr = dma_map_single(mp->dev->dev.parent, skb->data, |
| 852 | length, DMA_TO_DEVICE); |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 853 | |
Lennert Buytenhek | 99ab08e | 2008-08-28 05:53:18 +0200 | [diff] [blame] | 854 | __skb_queue_tail(&txq->tx_skb, skb); |
| 855 | |
Richard Cochran | 3b182d7 | 2011-06-21 16:01:11 -0700 | [diff] [blame] | 856 | skb_tx_timestamp(skb); |
| 857 | |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 858 | /* ensure all other descriptors are written before first cmd_sts */ |
| 859 | wmb(); |
| 860 | desc->cmd_sts = cmd_sts; |
| 861 | |
Lennert Buytenhek | 1fa38c5 | 2008-08-28 08:09:10 +0200 | [diff] [blame] | 862 | /* clear TX_END status */ |
| 863 | mp->work_tx_end &= ~(1 << txq->index); |
Lennert Buytenhek | 8fa89bf | 2008-07-14 22:56:55 +0200 | [diff] [blame] | 864 | |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 865 | /* ensure all descriptors are written before poking hardware */ |
| 866 | wmb(); |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 867 | txq_enable(txq); |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 868 | |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 869 | txq->tx_desc_count += nr_frags + 1; |
Lennert Buytenhek | 4df89bd | 2008-09-19 04:05:00 +0200 | [diff] [blame] | 870 | |
| 871 | return 0; |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 872 | } |
| 873 | |
Denis Kirjanov | 0ccfe64 | 2009-11-29 17:04:31 -0800 | [diff] [blame] | 874 | static netdev_tx_t mv643xx_eth_xmit(struct sk_buff *skb, struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 875 | { |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 876 | struct mv643xx_eth_private *mp = netdev_priv(dev); |
Richard Cochran | 73151ce | 2011-06-21 16:00:24 -0700 | [diff] [blame] | 877 | int length, queue; |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 878 | struct tx_queue *txq; |
Lennert Buytenhek | e5ef1de | 2008-08-28 06:26:23 +0200 | [diff] [blame] | 879 | struct netdev_queue *nq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 880 | |
Lennert Buytenhek | 8fd8921 | 2008-08-28 08:26:28 +0200 | [diff] [blame] | 881 | queue = skb_get_queue_mapping(skb); |
| 882 | txq = mp->txq + queue; |
| 883 | nq = netdev_get_tx_queue(dev, queue); |
| 884 | |
Lennert Buytenhek | 4d64e71 | 2008-03-18 11:32:41 -0700 | [diff] [blame] | 885 | if (has_tiny_unaligned_frags(skb) && __skb_linearize(skb)) { |
Lennert Buytenhek | 8fd8921 | 2008-08-28 08:26:28 +0200 | [diff] [blame] | 886 | txq->tx_dropped++; |
Joe Perches | 7542db8 | 2011-03-02 17:50:35 +0000 | [diff] [blame] | 887 | netdev_printk(KERN_DEBUG, dev, |
| 888 | "failed to linearize skb with tiny unaligned fragment\n"); |
Lennert Buytenhek | c0d0f2c | 2008-03-18 11:34:34 -0700 | [diff] [blame] | 889 | return NETDEV_TX_BUSY; |
Dale Farnsworth | 9484356 | 2006-04-11 18:24:26 -0700 | [diff] [blame] | 890 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 891 | |
Lennert Buytenhek | 17cd0a5 | 2008-08-24 05:33:55 +0200 | [diff] [blame] | 892 | if (txq->tx_ring_size - txq->tx_desc_count < MAX_SKB_FRAGS + 1) { |
Lennert Buytenhek | e5ef1de | 2008-08-28 06:26:23 +0200 | [diff] [blame] | 893 | if (net_ratelimit()) |
Joe Perches | 7542db8 | 2011-03-02 17:50:35 +0000 | [diff] [blame] | 894 | netdev_err(dev, "tx queue full?!\n"); |
Lennert Buytenhek | 3d6b35b | 2008-06-02 01:28:22 +0200 | [diff] [blame] | 895 | kfree_skb(skb); |
| 896 | return NETDEV_TX_OK; |
Lennert Buytenhek | 4d64e71 | 2008-03-18 11:32:41 -0700 | [diff] [blame] | 897 | } |
| 898 | |
Richard Cochran | 73151ce | 2011-06-21 16:00:24 -0700 | [diff] [blame] | 899 | length = skb->len; |
| 900 | |
Lennert Buytenhek | 4df89bd | 2008-09-19 04:05:00 +0200 | [diff] [blame] | 901 | if (!txq_submit_skb(txq, skb)) { |
| 902 | int entries_left; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 903 | |
Richard Cochran | 73151ce | 2011-06-21 16:00:24 -0700 | [diff] [blame] | 904 | txq->tx_bytes += length; |
Lennert Buytenhek | 4df89bd | 2008-09-19 04:05:00 +0200 | [diff] [blame] | 905 | txq->tx_packets++; |
Lennert Buytenhek | 4df89bd | 2008-09-19 04:05:00 +0200 | [diff] [blame] | 906 | |
| 907 | entries_left = txq->tx_ring_size - txq->tx_desc_count; |
| 908 | if (entries_left < MAX_SKB_FRAGS + 1) |
| 909 | netif_tx_stop_queue(nq); |
| 910 | } |
Dale Farnsworth | c8aaea2 | 2006-03-03 10:02:05 -0700 | [diff] [blame] | 911 | |
Lennert Buytenhek | c0d0f2c | 2008-03-18 11:34:34 -0700 | [diff] [blame] | 912 | return NETDEV_TX_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 913 | } |
| 914 | |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 915 | |
Lennert Buytenhek | 1fa38c5 | 2008-08-28 08:09:10 +0200 | [diff] [blame] | 916 | /* tx napi ******************************************************************/ |
| 917 | static void txq_kick(struct tx_queue *txq) |
| 918 | { |
| 919 | struct mv643xx_eth_private *mp = txq_to_mp(txq); |
Lennert Buytenhek | 8fd8921 | 2008-08-28 08:26:28 +0200 | [diff] [blame] | 920 | struct netdev_queue *nq = netdev_get_tx_queue(mp->dev, txq->index); |
Lennert Buytenhek | 1fa38c5 | 2008-08-28 08:09:10 +0200 | [diff] [blame] | 921 | u32 hw_desc_ptr; |
| 922 | u32 expected_ptr; |
| 923 | |
Lennert Buytenhek | 8fd8921 | 2008-08-28 08:26:28 +0200 | [diff] [blame] | 924 | __netif_tx_lock(nq, smp_processor_id()); |
Lennert Buytenhek | 1fa38c5 | 2008-08-28 08:09:10 +0200 | [diff] [blame] | 925 | |
Lennert Buytenhek | 37a6084 | 2008-11-20 03:57:36 -0800 | [diff] [blame] | 926 | if (rdlp(mp, TXQ_COMMAND) & (1 << txq->index)) |
Lennert Buytenhek | 1fa38c5 | 2008-08-28 08:09:10 +0200 | [diff] [blame] | 927 | goto out; |
| 928 | |
Lennert Buytenhek | 37a6084 | 2008-11-20 03:57:36 -0800 | [diff] [blame] | 929 | hw_desc_ptr = rdlp(mp, TXQ_CURRENT_DESC_PTR(txq->index)); |
Lennert Buytenhek | 1fa38c5 | 2008-08-28 08:09:10 +0200 | [diff] [blame] | 930 | expected_ptr = (u32)txq->tx_desc_dma + |
| 931 | txq->tx_curr_desc * sizeof(struct tx_desc); |
| 932 | |
| 933 | if (hw_desc_ptr != expected_ptr) |
| 934 | txq_enable(txq); |
| 935 | |
| 936 | out: |
Lennert Buytenhek | 8fd8921 | 2008-08-28 08:26:28 +0200 | [diff] [blame] | 937 | __netif_tx_unlock(nq); |
Lennert Buytenhek | 1fa38c5 | 2008-08-28 08:09:10 +0200 | [diff] [blame] | 938 | |
| 939 | mp->work_tx_end &= ~(1 << txq->index); |
| 940 | } |
| 941 | |
| 942 | static int txq_reclaim(struct tx_queue *txq, int budget, int force) |
| 943 | { |
| 944 | struct mv643xx_eth_private *mp = txq_to_mp(txq); |
Lennert Buytenhek | 8fd8921 | 2008-08-28 08:26:28 +0200 | [diff] [blame] | 945 | struct netdev_queue *nq = netdev_get_tx_queue(mp->dev, txq->index); |
Lennert Buytenhek | 1fa38c5 | 2008-08-28 08:09:10 +0200 | [diff] [blame] | 946 | int reclaimed; |
| 947 | |
Lennert Buytenhek | 8fd8921 | 2008-08-28 08:26:28 +0200 | [diff] [blame] | 948 | __netif_tx_lock(nq, smp_processor_id()); |
Lennert Buytenhek | 1fa38c5 | 2008-08-28 08:09:10 +0200 | [diff] [blame] | 949 | |
| 950 | reclaimed = 0; |
| 951 | while (reclaimed < budget && txq->tx_desc_count > 0) { |
| 952 | int tx_index; |
| 953 | struct tx_desc *desc; |
| 954 | u32 cmd_sts; |
| 955 | struct sk_buff *skb; |
Lennert Buytenhek | 1fa38c5 | 2008-08-28 08:09:10 +0200 | [diff] [blame] | 956 | |
| 957 | tx_index = txq->tx_used_desc; |
| 958 | desc = &txq->tx_desc_area[tx_index]; |
| 959 | cmd_sts = desc->cmd_sts; |
| 960 | |
| 961 | if (cmd_sts & BUFFER_OWNED_BY_DMA) { |
| 962 | if (!force) |
| 963 | break; |
| 964 | desc->cmd_sts = cmd_sts & ~BUFFER_OWNED_BY_DMA; |
| 965 | } |
| 966 | |
| 967 | txq->tx_used_desc = tx_index + 1; |
| 968 | if (txq->tx_used_desc == txq->tx_ring_size) |
| 969 | txq->tx_used_desc = 0; |
| 970 | |
| 971 | reclaimed++; |
| 972 | txq->tx_desc_count--; |
| 973 | |
Lennert Buytenhek | 99ab08e | 2008-08-28 05:53:18 +0200 | [diff] [blame] | 974 | skb = NULL; |
| 975 | if (cmd_sts & TX_LAST_DESC) |
| 976 | skb = __skb_dequeue(&txq->tx_skb); |
Lennert Buytenhek | 1fa38c5 | 2008-08-28 08:09:10 +0200 | [diff] [blame] | 977 | |
| 978 | if (cmd_sts & ERROR_SUMMARY) { |
Joe Perches | 7542db8 | 2011-03-02 17:50:35 +0000 | [diff] [blame] | 979 | netdev_info(mp->dev, "tx error\n"); |
Lennert Buytenhek | 1fa38c5 | 2008-08-28 08:09:10 +0200 | [diff] [blame] | 980 | mp->dev->stats.tx_errors++; |
| 981 | } |
| 982 | |
Lennert Buytenhek | a418950 | 2008-09-13 04:16:15 +0200 | [diff] [blame] | 983 | if (cmd_sts & TX_FIRST_DESC) { |
Gabriel Paubert | eb0519b | 2009-05-17 21:16:47 -0700 | [diff] [blame] | 984 | dma_unmap_single(mp->dev->dev.parent, desc->buf_ptr, |
Lennert Buytenhek | a418950 | 2008-09-13 04:16:15 +0200 | [diff] [blame] | 985 | desc->byte_cnt, DMA_TO_DEVICE); |
| 986 | } else { |
Gabriel Paubert | eb0519b | 2009-05-17 21:16:47 -0700 | [diff] [blame] | 987 | dma_unmap_page(mp->dev->dev.parent, desc->buf_ptr, |
Lennert Buytenhek | a418950 | 2008-09-13 04:16:15 +0200 | [diff] [blame] | 988 | desc->byte_cnt, DMA_TO_DEVICE); |
| 989 | } |
Lennert Buytenhek | 1fa38c5 | 2008-08-28 08:09:10 +0200 | [diff] [blame] | 990 | |
Eric Dumazet | acb600d | 2012-10-05 06:23:55 +0000 | [diff] [blame] | 991 | dev_kfree_skb(skb); |
Lennert Buytenhek | 1fa38c5 | 2008-08-28 08:09:10 +0200 | [diff] [blame] | 992 | } |
| 993 | |
Lennert Buytenhek | 8fd8921 | 2008-08-28 08:26:28 +0200 | [diff] [blame] | 994 | __netif_tx_unlock(nq); |
| 995 | |
Lennert Buytenhek | 1fa38c5 | 2008-08-28 08:09:10 +0200 | [diff] [blame] | 996 | if (reclaimed < budget) |
| 997 | mp->work_tx &= ~(1 << txq->index); |
| 998 | |
Lennert Buytenhek | 1fa38c5 | 2008-08-28 08:09:10 +0200 | [diff] [blame] | 999 | return reclaimed; |
| 1000 | } |
| 1001 | |
| 1002 | |
Lennert Buytenhek | 89df5fd | 2008-06-02 00:51:05 +0200 | [diff] [blame] | 1003 | /* tx rate control **********************************************************/ |
| 1004 | /* |
| 1005 | * Set total maximum TX rate (shared by all TX queues for this port) |
| 1006 | * to 'rate' bits per second, with a maximum burst of 'burst' bytes. |
| 1007 | */ |
| 1008 | static void tx_set_rate(struct mv643xx_eth_private *mp, int rate, int burst) |
| 1009 | { |
| 1010 | int token_rate; |
| 1011 | int mtu; |
| 1012 | int bucket_size; |
| 1013 | |
Andrew Lunn | 452503e | 2011-12-24 01:24:24 +0100 | [diff] [blame] | 1014 | token_rate = ((rate / 1000) * 64) / (mp->t_clk / 1000); |
Lennert Buytenhek | 89df5fd | 2008-06-02 00:51:05 +0200 | [diff] [blame] | 1015 | if (token_rate > 1023) |
| 1016 | token_rate = 1023; |
| 1017 | |
| 1018 | mtu = (mp->dev->mtu + 255) >> 8; |
| 1019 | if (mtu > 63) |
| 1020 | mtu = 63; |
| 1021 | |
| 1022 | bucket_size = (burst + 255) >> 8; |
| 1023 | if (bucket_size > 65535) |
| 1024 | bucket_size = 65535; |
| 1025 | |
Lennert Buytenhek | 457b1d5 | 2008-09-04 12:22:34 +0200 | [diff] [blame] | 1026 | switch (mp->shared->tx_bw_control) { |
| 1027 | case TX_BW_CONTROL_OLD_LAYOUT: |
Lennert Buytenhek | 37a6084 | 2008-11-20 03:57:36 -0800 | [diff] [blame] | 1028 | wrlp(mp, TX_BW_RATE, token_rate); |
| 1029 | wrlp(mp, TX_BW_MTU, mtu); |
| 1030 | wrlp(mp, TX_BW_BURST, bucket_size); |
Lennert Buytenhek | 457b1d5 | 2008-09-04 12:22:34 +0200 | [diff] [blame] | 1031 | break; |
| 1032 | case TX_BW_CONTROL_NEW_LAYOUT: |
Lennert Buytenhek | 37a6084 | 2008-11-20 03:57:36 -0800 | [diff] [blame] | 1033 | wrlp(mp, TX_BW_RATE_MOVED, token_rate); |
| 1034 | wrlp(mp, TX_BW_MTU_MOVED, mtu); |
| 1035 | wrlp(mp, TX_BW_BURST_MOVED, bucket_size); |
Lennert Buytenhek | 457b1d5 | 2008-09-04 12:22:34 +0200 | [diff] [blame] | 1036 | break; |
Lennert Buytenhek | 1e88159 | 2008-06-02 01:57:36 +0200 | [diff] [blame] | 1037 | } |
Lennert Buytenhek | 89df5fd | 2008-06-02 00:51:05 +0200 | [diff] [blame] | 1038 | } |
| 1039 | |
| 1040 | static void txq_set_rate(struct tx_queue *txq, int rate, int burst) |
| 1041 | { |
| 1042 | struct mv643xx_eth_private *mp = txq_to_mp(txq); |
| 1043 | int token_rate; |
| 1044 | int bucket_size; |
| 1045 | |
Andrew Lunn | 452503e | 2011-12-24 01:24:24 +0100 | [diff] [blame] | 1046 | token_rate = ((rate / 1000) * 64) / (mp->t_clk / 1000); |
Lennert Buytenhek | 89df5fd | 2008-06-02 00:51:05 +0200 | [diff] [blame] | 1047 | if (token_rate > 1023) |
| 1048 | token_rate = 1023; |
| 1049 | |
| 1050 | bucket_size = (burst + 255) >> 8; |
| 1051 | if (bucket_size > 65535) |
| 1052 | bucket_size = 65535; |
| 1053 | |
Lennert Buytenhek | 37a6084 | 2008-11-20 03:57:36 -0800 | [diff] [blame] | 1054 | wrlp(mp, TXQ_BW_TOKENS(txq->index), token_rate << 14); |
| 1055 | wrlp(mp, TXQ_BW_CONF(txq->index), (bucket_size << 10) | token_rate); |
Lennert Buytenhek | 89df5fd | 2008-06-02 00:51:05 +0200 | [diff] [blame] | 1056 | } |
| 1057 | |
| 1058 | static void txq_set_fixed_prio_mode(struct tx_queue *txq) |
| 1059 | { |
| 1060 | struct mv643xx_eth_private *mp = txq_to_mp(txq); |
| 1061 | int off; |
| 1062 | u32 val; |
| 1063 | |
| 1064 | /* |
| 1065 | * Turn on fixed priority mode. |
| 1066 | */ |
Lennert Buytenhek | 457b1d5 | 2008-09-04 12:22:34 +0200 | [diff] [blame] | 1067 | off = 0; |
| 1068 | switch (mp->shared->tx_bw_control) { |
| 1069 | case TX_BW_CONTROL_OLD_LAYOUT: |
Lennert Buytenhek | 37a6084 | 2008-11-20 03:57:36 -0800 | [diff] [blame] | 1070 | off = TXQ_FIX_PRIO_CONF; |
Lennert Buytenhek | 457b1d5 | 2008-09-04 12:22:34 +0200 | [diff] [blame] | 1071 | break; |
| 1072 | case TX_BW_CONTROL_NEW_LAYOUT: |
Lennert Buytenhek | 37a6084 | 2008-11-20 03:57:36 -0800 | [diff] [blame] | 1073 | off = TXQ_FIX_PRIO_CONF_MOVED; |
Lennert Buytenhek | 457b1d5 | 2008-09-04 12:22:34 +0200 | [diff] [blame] | 1074 | break; |
| 1075 | } |
Lennert Buytenhek | 89df5fd | 2008-06-02 00:51:05 +0200 | [diff] [blame] | 1076 | |
Lennert Buytenhek | 457b1d5 | 2008-09-04 12:22:34 +0200 | [diff] [blame] | 1077 | if (off) { |
Lennert Buytenhek | 37a6084 | 2008-11-20 03:57:36 -0800 | [diff] [blame] | 1078 | val = rdlp(mp, off); |
Lennert Buytenhek | 457b1d5 | 2008-09-04 12:22:34 +0200 | [diff] [blame] | 1079 | val |= 1 << txq->index; |
Lennert Buytenhek | 37a6084 | 2008-11-20 03:57:36 -0800 | [diff] [blame] | 1080 | wrlp(mp, off, val); |
Lennert Buytenhek | 457b1d5 | 2008-09-04 12:22:34 +0200 | [diff] [blame] | 1081 | } |
Lennert Buytenhek | 89df5fd | 2008-06-02 00:51:05 +0200 | [diff] [blame] | 1082 | } |
| 1083 | |
Lennert Buytenhek | 89df5fd | 2008-06-02 00:51:05 +0200 | [diff] [blame] | 1084 | |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1085 | /* mii management interface *************************************************/ |
Phil Sutter | 260055b | 2013-03-06 07:49:02 +0000 | [diff] [blame] | 1086 | static void mv643xx_adjust_pscr(struct mv643xx_eth_private *mp) |
| 1087 | { |
| 1088 | u32 pscr = rdlp(mp, PORT_SERIAL_CONTROL); |
| 1089 | u32 autoneg_disable = FORCE_LINK_PASS | |
| 1090 | DISABLE_AUTO_NEG_SPEED_GMII | |
| 1091 | DISABLE_AUTO_NEG_FOR_FLOW_CTRL | |
| 1092 | DISABLE_AUTO_NEG_FOR_DUPLEX; |
| 1093 | |
| 1094 | if (mp->phy->autoneg == AUTONEG_ENABLE) { |
| 1095 | /* enable auto negotiation */ |
| 1096 | pscr &= ~autoneg_disable; |
| 1097 | goto out_write; |
| 1098 | } |
| 1099 | |
| 1100 | pscr |= autoneg_disable; |
| 1101 | |
| 1102 | if (mp->phy->speed == SPEED_1000) { |
| 1103 | /* force gigabit, half duplex not supported */ |
| 1104 | pscr |= SET_GMII_SPEED_TO_1000; |
| 1105 | pscr |= SET_FULL_DUPLEX_MODE; |
| 1106 | goto out_write; |
| 1107 | } |
| 1108 | |
| 1109 | pscr &= ~SET_GMII_SPEED_TO_1000; |
| 1110 | |
| 1111 | if (mp->phy->speed == SPEED_100) |
| 1112 | pscr |= SET_MII_SPEED_TO_100; |
| 1113 | else |
| 1114 | pscr &= ~SET_MII_SPEED_TO_100; |
| 1115 | |
| 1116 | if (mp->phy->duplex == DUPLEX_FULL) |
| 1117 | pscr |= SET_FULL_DUPLEX_MODE; |
| 1118 | else |
| 1119 | pscr &= ~SET_FULL_DUPLEX_MODE; |
| 1120 | |
| 1121 | out_write: |
| 1122 | wrlp(mp, PORT_SERIAL_CONTROL, pscr); |
| 1123 | } |
| 1124 | |
Lennert Buytenhek | 45c5d3b | 2008-08-26 04:42:59 +0200 | [diff] [blame] | 1125 | static irqreturn_t mv643xx_eth_err_irq(int irq, void *dev_id) |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1126 | { |
Lennert Buytenhek | 45c5d3b | 2008-08-26 04:42:59 +0200 | [diff] [blame] | 1127 | struct mv643xx_eth_shared_private *msp = dev_id; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1128 | |
Lennert Buytenhek | 45c5d3b | 2008-08-26 04:42:59 +0200 | [diff] [blame] | 1129 | if (readl(msp->base + ERR_INT_CAUSE) & ERR_INT_SMI_DONE) { |
| 1130 | writel(~ERR_INT_SMI_DONE, msp->base + ERR_INT_CAUSE); |
| 1131 | wake_up(&msp->smi_busy_wait); |
| 1132 | return IRQ_HANDLED; |
| 1133 | } |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1134 | |
Lennert Buytenhek | 45c5d3b | 2008-08-26 04:42:59 +0200 | [diff] [blame] | 1135 | return IRQ_NONE; |
| 1136 | } |
| 1137 | |
| 1138 | static int smi_is_done(struct mv643xx_eth_shared_private *msp) |
| 1139 | { |
| 1140 | return !(readl(msp->base + SMI_REG) & SMI_BUSY); |
| 1141 | } |
| 1142 | |
| 1143 | static int smi_wait_ready(struct mv643xx_eth_shared_private *msp) |
| 1144 | { |
| 1145 | if (msp->err_interrupt == NO_IRQ) { |
| 1146 | int i; |
| 1147 | |
| 1148 | for (i = 0; !smi_is_done(msp); i++) { |
| 1149 | if (i == 10) |
| 1150 | return -ETIMEDOUT; |
| 1151 | msleep(10); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1152 | } |
Lennert Buytenhek | 45c5d3b | 2008-08-26 04:42:59 +0200 | [diff] [blame] | 1153 | |
| 1154 | return 0; |
| 1155 | } |
| 1156 | |
Lennert Buytenhek | ee04448 | 2008-11-01 06:32:20 +0100 | [diff] [blame] | 1157 | if (!smi_is_done(msp)) { |
| 1158 | wait_event_timeout(msp->smi_busy_wait, smi_is_done(msp), |
| 1159 | msecs_to_jiffies(100)); |
| 1160 | if (!smi_is_done(msp)) |
| 1161 | return -ETIMEDOUT; |
| 1162 | } |
Lennert Buytenhek | 45c5d3b | 2008-08-26 04:42:59 +0200 | [diff] [blame] | 1163 | |
| 1164 | return 0; |
| 1165 | } |
| 1166 | |
Lennert Buytenhek | ed94493 | 2008-08-26 13:34:19 +0200 | [diff] [blame] | 1167 | static int smi_bus_read(struct mii_bus *bus, int addr, int reg) |
Lennert Buytenhek | 45c5d3b | 2008-08-26 04:42:59 +0200 | [diff] [blame] | 1168 | { |
Lennert Buytenhek | ed94493 | 2008-08-26 13:34:19 +0200 | [diff] [blame] | 1169 | struct mv643xx_eth_shared_private *msp = bus->priv; |
Lennert Buytenhek | 45c5d3b | 2008-08-26 04:42:59 +0200 | [diff] [blame] | 1170 | void __iomem *smi_reg = msp->base + SMI_REG; |
| 1171 | int ret; |
| 1172 | |
Lennert Buytenhek | 45c5d3b | 2008-08-26 04:42:59 +0200 | [diff] [blame] | 1173 | if (smi_wait_ready(msp)) { |
Joe Perches | 7542db8 | 2011-03-02 17:50:35 +0000 | [diff] [blame] | 1174 | pr_warn("SMI bus busy timeout\n"); |
Lennert Buytenhek | ed94493 | 2008-08-26 13:34:19 +0200 | [diff] [blame] | 1175 | return -ETIMEDOUT; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1176 | } |
| 1177 | |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 1178 | writel(SMI_OPCODE_READ | (reg << 21) | (addr << 16), smi_reg); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1179 | |
Lennert Buytenhek | 45c5d3b | 2008-08-26 04:42:59 +0200 | [diff] [blame] | 1180 | if (smi_wait_ready(msp)) { |
Joe Perches | 7542db8 | 2011-03-02 17:50:35 +0000 | [diff] [blame] | 1181 | pr_warn("SMI bus busy timeout\n"); |
Lennert Buytenhek | ed94493 | 2008-08-26 13:34:19 +0200 | [diff] [blame] | 1182 | return -ETIMEDOUT; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1183 | } |
| 1184 | |
Lennert Buytenhek | 45c5d3b | 2008-08-26 04:42:59 +0200 | [diff] [blame] | 1185 | ret = readl(smi_reg); |
| 1186 | if (!(ret & SMI_READ_VALID)) { |
Joe Perches | 7542db8 | 2011-03-02 17:50:35 +0000 | [diff] [blame] | 1187 | pr_warn("SMI bus read not valid\n"); |
Lennert Buytenhek | ed94493 | 2008-08-26 13:34:19 +0200 | [diff] [blame] | 1188 | return -ENODEV; |
Lennert Buytenhek | 45c5d3b | 2008-08-26 04:42:59 +0200 | [diff] [blame] | 1189 | } |
| 1190 | |
Lennert Buytenhek | ed94493 | 2008-08-26 13:34:19 +0200 | [diff] [blame] | 1191 | return ret & 0xffff; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1192 | } |
| 1193 | |
Lennert Buytenhek | ed94493 | 2008-08-26 13:34:19 +0200 | [diff] [blame] | 1194 | static int smi_bus_write(struct mii_bus *bus, int addr, int reg, u16 val) |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1195 | { |
Lennert Buytenhek | ed94493 | 2008-08-26 13:34:19 +0200 | [diff] [blame] | 1196 | struct mv643xx_eth_shared_private *msp = bus->priv; |
Lennert Buytenhek | 45c5d3b | 2008-08-26 04:42:59 +0200 | [diff] [blame] | 1197 | void __iomem *smi_reg = msp->base + SMI_REG; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1198 | |
Lennert Buytenhek | 45c5d3b | 2008-08-26 04:42:59 +0200 | [diff] [blame] | 1199 | if (smi_wait_ready(msp)) { |
Joe Perches | 7542db8 | 2011-03-02 17:50:35 +0000 | [diff] [blame] | 1200 | pr_warn("SMI bus busy timeout\n"); |
Lennert Buytenhek | 45c5d3b | 2008-08-26 04:42:59 +0200 | [diff] [blame] | 1201 | return -ETIMEDOUT; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1202 | } |
| 1203 | |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 1204 | writel(SMI_OPCODE_WRITE | (reg << 21) | |
Lennert Buytenhek | ed94493 | 2008-08-26 13:34:19 +0200 | [diff] [blame] | 1205 | (addr << 16) | (val & 0xffff), smi_reg); |
Lennert Buytenhek | 45c5d3b | 2008-08-26 04:42:59 +0200 | [diff] [blame] | 1206 | |
Lennert Buytenhek | ed94493 | 2008-08-26 13:34:19 +0200 | [diff] [blame] | 1207 | if (smi_wait_ready(msp)) { |
Joe Perches | 7542db8 | 2011-03-02 17:50:35 +0000 | [diff] [blame] | 1208 | pr_warn("SMI bus busy timeout\n"); |
Lennert Buytenhek | ed94493 | 2008-08-26 13:34:19 +0200 | [diff] [blame] | 1209 | return -ETIMEDOUT; |
| 1210 | } |
Lennert Buytenhek | 45c5d3b | 2008-08-26 04:42:59 +0200 | [diff] [blame] | 1211 | |
| 1212 | return 0; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1213 | } |
| 1214 | |
| 1215 | |
Lennert Buytenhek | 8fd8921 | 2008-08-28 08:26:28 +0200 | [diff] [blame] | 1216 | /* statistics ***************************************************************/ |
| 1217 | static struct net_device_stats *mv643xx_eth_get_stats(struct net_device *dev) |
| 1218 | { |
| 1219 | struct mv643xx_eth_private *mp = netdev_priv(dev); |
| 1220 | struct net_device_stats *stats = &dev->stats; |
| 1221 | unsigned long tx_packets = 0; |
| 1222 | unsigned long tx_bytes = 0; |
| 1223 | unsigned long tx_dropped = 0; |
| 1224 | int i; |
| 1225 | |
| 1226 | for (i = 0; i < mp->txq_count; i++) { |
| 1227 | struct tx_queue *txq = mp->txq + i; |
| 1228 | |
| 1229 | tx_packets += txq->tx_packets; |
| 1230 | tx_bytes += txq->tx_bytes; |
| 1231 | tx_dropped += txq->tx_dropped; |
| 1232 | } |
| 1233 | |
| 1234 | stats->tx_packets = tx_packets; |
| 1235 | stats->tx_bytes = tx_bytes; |
| 1236 | stats->tx_dropped = tx_dropped; |
| 1237 | |
| 1238 | return stats; |
| 1239 | } |
| 1240 | |
Lennert Buytenhek | eaf5d59 | 2009-02-12 14:08:39 +0000 | [diff] [blame] | 1241 | static void mv643xx_eth_grab_lro_stats(struct mv643xx_eth_private *mp) |
| 1242 | { |
| 1243 | u32 lro_aggregated = 0; |
| 1244 | u32 lro_flushed = 0; |
| 1245 | u32 lro_no_desc = 0; |
| 1246 | int i; |
| 1247 | |
Lennert Buytenhek | eaf5d59 | 2009-02-12 14:08:39 +0000 | [diff] [blame] | 1248 | for (i = 0; i < mp->rxq_count; i++) { |
| 1249 | struct rx_queue *rxq = mp->rxq + i; |
| 1250 | |
| 1251 | lro_aggregated += rxq->lro_mgr.stats.aggregated; |
| 1252 | lro_flushed += rxq->lro_mgr.stats.flushed; |
| 1253 | lro_no_desc += rxq->lro_mgr.stats.no_desc; |
| 1254 | } |
Lennert Buytenhek | eaf5d59 | 2009-02-12 14:08:39 +0000 | [diff] [blame] | 1255 | |
| 1256 | mp->lro_counters.lro_aggregated = lro_aggregated; |
| 1257 | mp->lro_counters.lro_flushed = lro_flushed; |
| 1258 | mp->lro_counters.lro_no_desc = lro_no_desc; |
| 1259 | } |
| 1260 | |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 1261 | static inline u32 mib_read(struct mv643xx_eth_private *mp, int offset) |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1262 | { |
Lennert Buytenhek | 3cb4667 | 2008-06-01 01:03:23 +0200 | [diff] [blame] | 1263 | return rdl(mp, MIB_COUNTERS(mp->port_num) + offset); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1264 | } |
| 1265 | |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 1266 | static void mib_counters_clear(struct mv643xx_eth_private *mp) |
| 1267 | { |
| 1268 | int i; |
| 1269 | |
| 1270 | for (i = 0; i < 0x80; i += 4) |
| 1271 | mib_read(mp, i); |
Paulius Zaleckas | 302476c | 2012-01-23 01:16:35 +0000 | [diff] [blame] | 1272 | |
| 1273 | /* Clear non MIB hw counters also */ |
| 1274 | rdlp(mp, RX_DISCARD_FRAME_CNT); |
| 1275 | rdlp(mp, RX_OVERRUN_FRAME_CNT); |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 1276 | } |
| 1277 | |
| 1278 | static void mib_counters_update(struct mv643xx_eth_private *mp) |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1279 | { |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 1280 | struct mib_counters *p = &mp->mib_counters; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1281 | |
Sebastian Siewior | 57e8f26 | 2009-02-16 11:28:15 +0000 | [diff] [blame] | 1282 | spin_lock_bh(&mp->mib_counters_lock); |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 1283 | p->good_octets_received += mib_read(mp, 0x00); |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 1284 | p->bad_octets_received += mib_read(mp, 0x08); |
| 1285 | p->internal_mac_transmit_err += mib_read(mp, 0x0c); |
| 1286 | p->good_frames_received += mib_read(mp, 0x10); |
| 1287 | p->bad_frames_received += mib_read(mp, 0x14); |
| 1288 | p->broadcast_frames_received += mib_read(mp, 0x18); |
| 1289 | p->multicast_frames_received += mib_read(mp, 0x1c); |
| 1290 | p->frames_64_octets += mib_read(mp, 0x20); |
| 1291 | p->frames_65_to_127_octets += mib_read(mp, 0x24); |
| 1292 | p->frames_128_to_255_octets += mib_read(mp, 0x28); |
| 1293 | p->frames_256_to_511_octets += mib_read(mp, 0x2c); |
| 1294 | p->frames_512_to_1023_octets += mib_read(mp, 0x30); |
| 1295 | p->frames_1024_to_max_octets += mib_read(mp, 0x34); |
| 1296 | p->good_octets_sent += mib_read(mp, 0x38); |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 1297 | p->good_frames_sent += mib_read(mp, 0x40); |
| 1298 | p->excessive_collision += mib_read(mp, 0x44); |
| 1299 | p->multicast_frames_sent += mib_read(mp, 0x48); |
| 1300 | p->broadcast_frames_sent += mib_read(mp, 0x4c); |
| 1301 | p->unrec_mac_control_received += mib_read(mp, 0x50); |
| 1302 | p->fc_sent += mib_read(mp, 0x54); |
| 1303 | p->good_fc_received += mib_read(mp, 0x58); |
| 1304 | p->bad_fc_received += mib_read(mp, 0x5c); |
| 1305 | p->undersize_received += mib_read(mp, 0x60); |
| 1306 | p->fragments_received += mib_read(mp, 0x64); |
| 1307 | p->oversize_received += mib_read(mp, 0x68); |
| 1308 | p->jabber_received += mib_read(mp, 0x6c); |
| 1309 | p->mac_receive_error += mib_read(mp, 0x70); |
| 1310 | p->bad_crc_event += mib_read(mp, 0x74); |
| 1311 | p->collision += mib_read(mp, 0x78); |
| 1312 | p->late_collision += mib_read(mp, 0x7c); |
Paulius Zaleckas | 302476c | 2012-01-23 01:16:35 +0000 | [diff] [blame] | 1313 | /* Non MIB hardware counters */ |
| 1314 | p->rx_discard += rdlp(mp, RX_DISCARD_FRAME_CNT); |
| 1315 | p->rx_overrun += rdlp(mp, RX_OVERRUN_FRAME_CNT); |
Sebastian Siewior | 57e8f26 | 2009-02-16 11:28:15 +0000 | [diff] [blame] | 1316 | spin_unlock_bh(&mp->mib_counters_lock); |
Lennert Buytenhek | 4ff3495 | 2008-09-19 05:04:57 +0200 | [diff] [blame] | 1317 | |
| 1318 | mod_timer(&mp->mib_counters_timer, jiffies + 30 * HZ); |
| 1319 | } |
| 1320 | |
| 1321 | static void mib_counters_timer_wrapper(unsigned long _mp) |
| 1322 | { |
| 1323 | struct mv643xx_eth_private *mp = (void *)_mp; |
| 1324 | |
| 1325 | mib_counters_update(mp); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1326 | } |
| 1327 | |
| 1328 | |
Lennert Buytenhek | 3e50803 | 2009-02-12 14:07:09 +0000 | [diff] [blame] | 1329 | /* interrupt coalescing *****************************************************/ |
| 1330 | /* |
| 1331 | * Hardware coalescing parameters are set in units of 64 t_clk |
| 1332 | * cycles. I.e.: |
| 1333 | * |
| 1334 | * coal_delay_in_usec = 64000000 * register_value / t_clk_rate |
| 1335 | * |
| 1336 | * register_value = coal_delay_in_usec * t_clk_rate / 64000000 |
| 1337 | * |
| 1338 | * In the ->set*() methods, we round the computed register value |
| 1339 | * to the nearest integer. |
| 1340 | */ |
| 1341 | static unsigned int get_rx_coal(struct mv643xx_eth_private *mp) |
| 1342 | { |
| 1343 | u32 val = rdlp(mp, SDMA_CONFIG); |
| 1344 | u64 temp; |
| 1345 | |
| 1346 | if (mp->shared->extended_rx_coal_limit) |
| 1347 | temp = ((val & 0x02000000) >> 10) | ((val & 0x003fff80) >> 7); |
| 1348 | else |
| 1349 | temp = (val & 0x003fff00) >> 8; |
| 1350 | |
| 1351 | temp *= 64000000; |
Andrew Lunn | 452503e | 2011-12-24 01:24:24 +0100 | [diff] [blame] | 1352 | do_div(temp, mp->t_clk); |
Lennert Buytenhek | 3e50803 | 2009-02-12 14:07:09 +0000 | [diff] [blame] | 1353 | |
| 1354 | return (unsigned int)temp; |
| 1355 | } |
| 1356 | |
| 1357 | static void set_rx_coal(struct mv643xx_eth_private *mp, unsigned int usec) |
| 1358 | { |
| 1359 | u64 temp; |
| 1360 | u32 val; |
| 1361 | |
Andrew Lunn | 452503e | 2011-12-24 01:24:24 +0100 | [diff] [blame] | 1362 | temp = (u64)usec * mp->t_clk; |
Lennert Buytenhek | 3e50803 | 2009-02-12 14:07:09 +0000 | [diff] [blame] | 1363 | temp += 31999999; |
| 1364 | do_div(temp, 64000000); |
| 1365 | |
| 1366 | val = rdlp(mp, SDMA_CONFIG); |
| 1367 | if (mp->shared->extended_rx_coal_limit) { |
| 1368 | if (temp > 0xffff) |
| 1369 | temp = 0xffff; |
| 1370 | val &= ~0x023fff80; |
| 1371 | val |= (temp & 0x8000) << 10; |
| 1372 | val |= (temp & 0x7fff) << 7; |
| 1373 | } else { |
| 1374 | if (temp > 0x3fff) |
| 1375 | temp = 0x3fff; |
| 1376 | val &= ~0x003fff00; |
| 1377 | val |= (temp & 0x3fff) << 8; |
| 1378 | } |
| 1379 | wrlp(mp, SDMA_CONFIG, val); |
| 1380 | } |
| 1381 | |
| 1382 | static unsigned int get_tx_coal(struct mv643xx_eth_private *mp) |
| 1383 | { |
| 1384 | u64 temp; |
| 1385 | |
| 1386 | temp = (rdlp(mp, TX_FIFO_URGENT_THRESHOLD) & 0x3fff0) >> 4; |
| 1387 | temp *= 64000000; |
Andrew Lunn | 452503e | 2011-12-24 01:24:24 +0100 | [diff] [blame] | 1388 | do_div(temp, mp->t_clk); |
Lennert Buytenhek | 3e50803 | 2009-02-12 14:07:09 +0000 | [diff] [blame] | 1389 | |
| 1390 | return (unsigned int)temp; |
| 1391 | } |
| 1392 | |
| 1393 | static void set_tx_coal(struct mv643xx_eth_private *mp, unsigned int usec) |
| 1394 | { |
| 1395 | u64 temp; |
| 1396 | |
Andrew Lunn | 452503e | 2011-12-24 01:24:24 +0100 | [diff] [blame] | 1397 | temp = (u64)usec * mp->t_clk; |
Lennert Buytenhek | 3e50803 | 2009-02-12 14:07:09 +0000 | [diff] [blame] | 1398 | temp += 31999999; |
| 1399 | do_div(temp, 64000000); |
| 1400 | |
| 1401 | if (temp > 0x3fff) |
| 1402 | temp = 0x3fff; |
| 1403 | |
| 1404 | wrlp(mp, TX_FIFO_URGENT_THRESHOLD, temp << 4); |
| 1405 | } |
| 1406 | |
| 1407 | |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1408 | /* ethtool ******************************************************************/ |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 1409 | struct mv643xx_eth_stats { |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1410 | char stat_string[ETH_GSTRING_LEN]; |
| 1411 | int sizeof_stat; |
Lennert Buytenhek | 1682005 | 2008-06-01 11:40:29 +0200 | [diff] [blame] | 1412 | int netdev_off; |
| 1413 | int mp_off; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1414 | }; |
| 1415 | |
Lennert Buytenhek | 1682005 | 2008-06-01 11:40:29 +0200 | [diff] [blame] | 1416 | #define SSTAT(m) \ |
| 1417 | { #m, FIELD_SIZEOF(struct net_device_stats, m), \ |
| 1418 | offsetof(struct net_device, stats.m), -1 } |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1419 | |
Lennert Buytenhek | 1682005 | 2008-06-01 11:40:29 +0200 | [diff] [blame] | 1420 | #define MIBSTAT(m) \ |
| 1421 | { #m, FIELD_SIZEOF(struct mib_counters, m), \ |
| 1422 | -1, offsetof(struct mv643xx_eth_private, mib_counters.m) } |
| 1423 | |
Lennert Buytenhek | eaf5d59 | 2009-02-12 14:08:39 +0000 | [diff] [blame] | 1424 | #define LROSTAT(m) \ |
| 1425 | { #m, FIELD_SIZEOF(struct lro_counters, m), \ |
| 1426 | -1, offsetof(struct mv643xx_eth_private, lro_counters.m) } |
| 1427 | |
Lennert Buytenhek | 1682005 | 2008-06-01 11:40:29 +0200 | [diff] [blame] | 1428 | static const struct mv643xx_eth_stats mv643xx_eth_stats[] = { |
| 1429 | SSTAT(rx_packets), |
| 1430 | SSTAT(tx_packets), |
| 1431 | SSTAT(rx_bytes), |
| 1432 | SSTAT(tx_bytes), |
| 1433 | SSTAT(rx_errors), |
| 1434 | SSTAT(tx_errors), |
| 1435 | SSTAT(rx_dropped), |
| 1436 | SSTAT(tx_dropped), |
| 1437 | MIBSTAT(good_octets_received), |
| 1438 | MIBSTAT(bad_octets_received), |
| 1439 | MIBSTAT(internal_mac_transmit_err), |
| 1440 | MIBSTAT(good_frames_received), |
| 1441 | MIBSTAT(bad_frames_received), |
| 1442 | MIBSTAT(broadcast_frames_received), |
| 1443 | MIBSTAT(multicast_frames_received), |
| 1444 | MIBSTAT(frames_64_octets), |
| 1445 | MIBSTAT(frames_65_to_127_octets), |
| 1446 | MIBSTAT(frames_128_to_255_octets), |
| 1447 | MIBSTAT(frames_256_to_511_octets), |
| 1448 | MIBSTAT(frames_512_to_1023_octets), |
| 1449 | MIBSTAT(frames_1024_to_max_octets), |
| 1450 | MIBSTAT(good_octets_sent), |
| 1451 | MIBSTAT(good_frames_sent), |
| 1452 | MIBSTAT(excessive_collision), |
| 1453 | MIBSTAT(multicast_frames_sent), |
| 1454 | MIBSTAT(broadcast_frames_sent), |
| 1455 | MIBSTAT(unrec_mac_control_received), |
| 1456 | MIBSTAT(fc_sent), |
| 1457 | MIBSTAT(good_fc_received), |
| 1458 | MIBSTAT(bad_fc_received), |
| 1459 | MIBSTAT(undersize_received), |
| 1460 | MIBSTAT(fragments_received), |
| 1461 | MIBSTAT(oversize_received), |
| 1462 | MIBSTAT(jabber_received), |
| 1463 | MIBSTAT(mac_receive_error), |
| 1464 | MIBSTAT(bad_crc_event), |
| 1465 | MIBSTAT(collision), |
| 1466 | MIBSTAT(late_collision), |
Paulius Zaleckas | 302476c | 2012-01-23 01:16:35 +0000 | [diff] [blame] | 1467 | MIBSTAT(rx_discard), |
| 1468 | MIBSTAT(rx_overrun), |
Lennert Buytenhek | eaf5d59 | 2009-02-12 14:08:39 +0000 | [diff] [blame] | 1469 | LROSTAT(lro_aggregated), |
| 1470 | LROSTAT(lro_flushed), |
| 1471 | LROSTAT(lro_no_desc), |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1472 | }; |
| 1473 | |
Lennert Buytenhek | 10a9948 | 2008-11-20 03:57:16 -0800 | [diff] [blame] | 1474 | static int |
Lennert Buytenhek | 6bdf576 | 2009-02-12 14:06:46 +0000 | [diff] [blame] | 1475 | mv643xx_eth_get_settings_phy(struct mv643xx_eth_private *mp, |
| 1476 | struct ethtool_cmd *cmd) |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1477 | { |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1478 | int err; |
| 1479 | |
Lennert Buytenhek | ed94493 | 2008-08-26 13:34:19 +0200 | [diff] [blame] | 1480 | err = phy_read_status(mp->phy); |
| 1481 | if (err == 0) |
| 1482 | err = phy_ethtool_gset(mp->phy, cmd); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1483 | |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 1484 | /* |
| 1485 | * The MAC does not support 1000baseT_Half. |
| 1486 | */ |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1487 | cmd->supported &= ~SUPPORTED_1000baseT_Half; |
| 1488 | cmd->advertising &= ~ADVERTISED_1000baseT_Half; |
| 1489 | |
| 1490 | return err; |
| 1491 | } |
| 1492 | |
Lennert Buytenhek | 10a9948 | 2008-11-20 03:57:16 -0800 | [diff] [blame] | 1493 | static int |
Lennert Buytenhek | 6bdf576 | 2009-02-12 14:06:46 +0000 | [diff] [blame] | 1494 | mv643xx_eth_get_settings_phyless(struct mv643xx_eth_private *mp, |
Lennert Buytenhek | 10a9948 | 2008-11-20 03:57:16 -0800 | [diff] [blame] | 1495 | struct ethtool_cmd *cmd) |
Lennert Buytenhek | bedfe32 | 2008-06-02 02:13:03 +0200 | [diff] [blame] | 1496 | { |
Lennert Buytenhek | 81600eea9 | 2008-07-14 14:29:40 +0200 | [diff] [blame] | 1497 | u32 port_status; |
| 1498 | |
Lennert Buytenhek | 37a6084 | 2008-11-20 03:57:36 -0800 | [diff] [blame] | 1499 | port_status = rdlp(mp, PORT_STATUS); |
Lennert Buytenhek | 81600eea9 | 2008-07-14 14:29:40 +0200 | [diff] [blame] | 1500 | |
Lennert Buytenhek | bedfe32 | 2008-06-02 02:13:03 +0200 | [diff] [blame] | 1501 | cmd->supported = SUPPORTED_MII; |
| 1502 | cmd->advertising = ADVERTISED_MII; |
Lennert Buytenhek | 81600eea9 | 2008-07-14 14:29:40 +0200 | [diff] [blame] | 1503 | switch (port_status & PORT_SPEED_MASK) { |
| 1504 | case PORT_SPEED_10: |
David Decotigny | 7073949 | 2011-04-27 18:32:40 +0000 | [diff] [blame] | 1505 | ethtool_cmd_speed_set(cmd, SPEED_10); |
Lennert Buytenhek | 81600eea9 | 2008-07-14 14:29:40 +0200 | [diff] [blame] | 1506 | break; |
| 1507 | case PORT_SPEED_100: |
David Decotigny | 7073949 | 2011-04-27 18:32:40 +0000 | [diff] [blame] | 1508 | ethtool_cmd_speed_set(cmd, SPEED_100); |
Lennert Buytenhek | 81600eea9 | 2008-07-14 14:29:40 +0200 | [diff] [blame] | 1509 | break; |
| 1510 | case PORT_SPEED_1000: |
David Decotigny | 7073949 | 2011-04-27 18:32:40 +0000 | [diff] [blame] | 1511 | ethtool_cmd_speed_set(cmd, SPEED_1000); |
Lennert Buytenhek | 81600eea9 | 2008-07-14 14:29:40 +0200 | [diff] [blame] | 1512 | break; |
| 1513 | default: |
| 1514 | cmd->speed = -1; |
| 1515 | break; |
| 1516 | } |
| 1517 | cmd->duplex = (port_status & FULL_DUPLEX) ? DUPLEX_FULL : DUPLEX_HALF; |
Lennert Buytenhek | bedfe32 | 2008-06-02 02:13:03 +0200 | [diff] [blame] | 1518 | cmd->port = PORT_MII; |
| 1519 | cmd->phy_address = 0; |
| 1520 | cmd->transceiver = XCVR_INTERNAL; |
| 1521 | cmd->autoneg = AUTONEG_DISABLE; |
| 1522 | cmd->maxtxpkt = 1; |
| 1523 | cmd->maxrxpkt = 1; |
| 1524 | |
| 1525 | return 0; |
| 1526 | } |
| 1527 | |
Michael Stapelberg | 3871c38 | 2013-03-11 13:56:45 +0000 | [diff] [blame^] | 1528 | static void |
| 1529 | mv643xx_eth_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
| 1530 | { |
| 1531 | struct mv643xx_eth_private *mp = netdev_priv(dev); |
| 1532 | wol->supported = 0; |
| 1533 | wol->wolopts = 0; |
| 1534 | if (mp->phy) |
| 1535 | phy_ethtool_get_wol(mp->phy, wol); |
| 1536 | } |
| 1537 | |
| 1538 | static int |
| 1539 | mv643xx_eth_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
| 1540 | { |
| 1541 | struct mv643xx_eth_private *mp = netdev_priv(dev); |
| 1542 | int err; |
| 1543 | |
| 1544 | if (mp->phy == NULL) |
| 1545 | return -EOPNOTSUPP; |
| 1546 | |
| 1547 | err = phy_ethtool_set_wol(mp->phy, wol); |
| 1548 | /* Given that mv643xx_eth works without the marvell-specific PHY driver, |
| 1549 | * this debugging hint is useful to have. |
| 1550 | */ |
| 1551 | if (err == -EOPNOTSUPP) |
| 1552 | netdev_info(dev, "The PHY does not support set_wol, was CONFIG_MARVELL_PHY enabled?\n"); |
| 1553 | return err; |
| 1554 | } |
| 1555 | |
Lennert Buytenhek | 10a9948 | 2008-11-20 03:57:16 -0800 | [diff] [blame] | 1556 | static int |
Lennert Buytenhek | 6bdf576 | 2009-02-12 14:06:46 +0000 | [diff] [blame] | 1557 | mv643xx_eth_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) |
| 1558 | { |
| 1559 | struct mv643xx_eth_private *mp = netdev_priv(dev); |
| 1560 | |
| 1561 | if (mp->phy != NULL) |
| 1562 | return mv643xx_eth_get_settings_phy(mp, cmd); |
| 1563 | else |
| 1564 | return mv643xx_eth_get_settings_phyless(mp, cmd); |
| 1565 | } |
| 1566 | |
| 1567 | static int |
Lennert Buytenhek | 10a9948 | 2008-11-20 03:57:16 -0800 | [diff] [blame] | 1568 | mv643xx_eth_set_settings(struct net_device *dev, struct ethtool_cmd *cmd) |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1569 | { |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 1570 | struct mv643xx_eth_private *mp = netdev_priv(dev); |
Phil Sutter | 260055b | 2013-03-06 07:49:02 +0000 | [diff] [blame] | 1571 | int ret; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1572 | |
Lennert Buytenhek | 6bdf576 | 2009-02-12 14:06:46 +0000 | [diff] [blame] | 1573 | if (mp->phy == NULL) |
| 1574 | return -EINVAL; |
| 1575 | |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 1576 | /* |
| 1577 | * The MAC does not support 1000baseT_Half. |
| 1578 | */ |
| 1579 | cmd->advertising &= ~ADVERTISED_1000baseT_Half; |
| 1580 | |
Phil Sutter | 260055b | 2013-03-06 07:49:02 +0000 | [diff] [blame] | 1581 | ret = phy_ethtool_sset(mp->phy, cmd); |
| 1582 | if (!ret) |
| 1583 | mv643xx_adjust_pscr(mp); |
| 1584 | return ret; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1585 | } |
| 1586 | |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 1587 | static void mv643xx_eth_get_drvinfo(struct net_device *dev, |
| 1588 | struct ethtool_drvinfo *drvinfo) |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1589 | { |
Axel Lin | 6f39da2 | 2011-11-24 00:41:55 -0500 | [diff] [blame] | 1590 | strlcpy(drvinfo->driver, mv643xx_eth_driver_name, |
| 1591 | sizeof(drvinfo->driver)); |
Rick Jones | 68aad78 | 2011-11-07 13:29:27 +0000 | [diff] [blame] | 1592 | strlcpy(drvinfo->version, mv643xx_eth_driver_version, |
Axel Lin | 6f39da2 | 2011-11-24 00:41:55 -0500 | [diff] [blame] | 1593 | sizeof(drvinfo->version)); |
| 1594 | strlcpy(drvinfo->fw_version, "N/A", sizeof(drvinfo->fw_version)); |
| 1595 | strlcpy(drvinfo->bus_info, "platform", sizeof(drvinfo->bus_info)); |
Lennert Buytenhek | 1682005 | 2008-06-01 11:40:29 +0200 | [diff] [blame] | 1596 | drvinfo->n_stats = ARRAY_SIZE(mv643xx_eth_stats); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1597 | } |
| 1598 | |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 1599 | static int mv643xx_eth_nway_reset(struct net_device *dev) |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1600 | { |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 1601 | struct mv643xx_eth_private *mp = netdev_priv(dev); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1602 | |
Lennert Buytenhek | 6bdf576 | 2009-02-12 14:06:46 +0000 | [diff] [blame] | 1603 | if (mp->phy == NULL) |
| 1604 | return -EINVAL; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1605 | |
Lennert Buytenhek | 6bdf576 | 2009-02-12 14:06:46 +0000 | [diff] [blame] | 1606 | return genphy_restart_aneg(mp->phy); |
Lennert Buytenhek | bedfe32 | 2008-06-02 02:13:03 +0200 | [diff] [blame] | 1607 | } |
| 1608 | |
Lennert Buytenhek | 3e50803 | 2009-02-12 14:07:09 +0000 | [diff] [blame] | 1609 | static int |
| 1610 | mv643xx_eth_get_coalesce(struct net_device *dev, struct ethtool_coalesce *ec) |
| 1611 | { |
| 1612 | struct mv643xx_eth_private *mp = netdev_priv(dev); |
| 1613 | |
| 1614 | ec->rx_coalesce_usecs = get_rx_coal(mp); |
| 1615 | ec->tx_coalesce_usecs = get_tx_coal(mp); |
| 1616 | |
| 1617 | return 0; |
| 1618 | } |
| 1619 | |
| 1620 | static int |
| 1621 | mv643xx_eth_set_coalesce(struct net_device *dev, struct ethtool_coalesce *ec) |
| 1622 | { |
| 1623 | struct mv643xx_eth_private *mp = netdev_priv(dev); |
| 1624 | |
| 1625 | set_rx_coal(mp, ec->rx_coalesce_usecs); |
| 1626 | set_tx_coal(mp, ec->tx_coalesce_usecs); |
| 1627 | |
| 1628 | return 0; |
| 1629 | } |
| 1630 | |
Lennert Buytenhek | e7d2f4d | 2009-02-12 14:07:37 +0000 | [diff] [blame] | 1631 | static void |
| 1632 | mv643xx_eth_get_ringparam(struct net_device *dev, struct ethtool_ringparam *er) |
| 1633 | { |
| 1634 | struct mv643xx_eth_private *mp = netdev_priv(dev); |
| 1635 | |
| 1636 | er->rx_max_pending = 4096; |
| 1637 | er->tx_max_pending = 4096; |
Lennert Buytenhek | e7d2f4d | 2009-02-12 14:07:37 +0000 | [diff] [blame] | 1638 | |
| 1639 | er->rx_pending = mp->rx_ring_size; |
| 1640 | er->tx_pending = mp->tx_ring_size; |
Lennert Buytenhek | e7d2f4d | 2009-02-12 14:07:37 +0000 | [diff] [blame] | 1641 | } |
| 1642 | |
| 1643 | static int |
| 1644 | mv643xx_eth_set_ringparam(struct net_device *dev, struct ethtool_ringparam *er) |
| 1645 | { |
| 1646 | struct mv643xx_eth_private *mp = netdev_priv(dev); |
| 1647 | |
| 1648 | if (er->rx_mini_pending || er->rx_jumbo_pending) |
| 1649 | return -EINVAL; |
| 1650 | |
| 1651 | mp->rx_ring_size = er->rx_pending < 4096 ? er->rx_pending : 4096; |
| 1652 | mp->tx_ring_size = er->tx_pending < 4096 ? er->tx_pending : 4096; |
| 1653 | |
| 1654 | if (netif_running(dev)) { |
| 1655 | mv643xx_eth_stop(dev); |
| 1656 | if (mv643xx_eth_open(dev)) { |
Joe Perches | 7542db8 | 2011-03-02 17:50:35 +0000 | [diff] [blame] | 1657 | netdev_err(dev, |
| 1658 | "fatal error on re-opening device after ring param change\n"); |
Lennert Buytenhek | e7d2f4d | 2009-02-12 14:07:37 +0000 | [diff] [blame] | 1659 | return -ENOMEM; |
| 1660 | } |
| 1661 | } |
| 1662 | |
| 1663 | return 0; |
| 1664 | } |
| 1665 | |
Lennert Buytenhek | d888b37 | 2009-02-12 14:07:56 +0000 | [diff] [blame] | 1666 | |
| 1667 | static int |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 1668 | mv643xx_eth_set_features(struct net_device *dev, netdev_features_t features) |
Lennert Buytenhek | d888b37 | 2009-02-12 14:07:56 +0000 | [diff] [blame] | 1669 | { |
| 1670 | struct mv643xx_eth_private *mp = netdev_priv(dev); |
Michał Mirosław | 3ad9b35 | 2011-11-16 14:05:33 +0000 | [diff] [blame] | 1671 | bool rx_csum = features & NETIF_F_RXCSUM; |
Lennert Buytenhek | d888b37 | 2009-02-12 14:07:56 +0000 | [diff] [blame] | 1672 | |
| 1673 | wrlp(mp, PORT_CONFIG, rx_csum ? 0x02000000 : 0x00000000); |
| 1674 | |
| 1675 | return 0; |
| 1676 | } |
| 1677 | |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 1678 | static void mv643xx_eth_get_strings(struct net_device *dev, |
| 1679 | uint32_t stringset, uint8_t *data) |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1680 | { |
| 1681 | int i; |
| 1682 | |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 1683 | if (stringset == ETH_SS_STATS) { |
| 1684 | for (i = 0; i < ARRAY_SIZE(mv643xx_eth_stats); i++) { |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1685 | memcpy(data + i * ETH_GSTRING_LEN, |
Lennert Buytenhek | 1682005 | 2008-06-01 11:40:29 +0200 | [diff] [blame] | 1686 | mv643xx_eth_stats[i].stat_string, |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 1687 | ETH_GSTRING_LEN); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1688 | } |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1689 | } |
| 1690 | } |
| 1691 | |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 1692 | static void mv643xx_eth_get_ethtool_stats(struct net_device *dev, |
| 1693 | struct ethtool_stats *stats, |
| 1694 | uint64_t *data) |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1695 | { |
Lennert Buytenhek | b987384 | 2008-08-24 05:59:16 +0200 | [diff] [blame] | 1696 | struct mv643xx_eth_private *mp = netdev_priv(dev); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1697 | int i; |
| 1698 | |
Lennert Buytenhek | 8fd8921 | 2008-08-28 08:26:28 +0200 | [diff] [blame] | 1699 | mv643xx_eth_get_stats(dev); |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 1700 | mib_counters_update(mp); |
Lennert Buytenhek | eaf5d59 | 2009-02-12 14:08:39 +0000 | [diff] [blame] | 1701 | mv643xx_eth_grab_lro_stats(mp); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1702 | |
Lennert Buytenhek | 1682005 | 2008-06-01 11:40:29 +0200 | [diff] [blame] | 1703 | for (i = 0; i < ARRAY_SIZE(mv643xx_eth_stats); i++) { |
| 1704 | const struct mv643xx_eth_stats *stat; |
| 1705 | void *p; |
| 1706 | |
| 1707 | stat = mv643xx_eth_stats + i; |
| 1708 | |
| 1709 | if (stat->netdev_off >= 0) |
| 1710 | p = ((void *)mp->dev) + stat->netdev_off; |
| 1711 | else |
| 1712 | p = ((void *)mp) + stat->mp_off; |
| 1713 | |
| 1714 | data[i] = (stat->sizeof_stat == 8) ? |
| 1715 | *(uint64_t *)p : *(uint32_t *)p; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1716 | } |
| 1717 | } |
| 1718 | |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 1719 | static int mv643xx_eth_get_sset_count(struct net_device *dev, int sset) |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1720 | { |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 1721 | if (sset == ETH_SS_STATS) |
Lennert Buytenhek | 1682005 | 2008-06-01 11:40:29 +0200 | [diff] [blame] | 1722 | return ARRAY_SIZE(mv643xx_eth_stats); |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 1723 | |
| 1724 | return -EOPNOTSUPP; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1725 | } |
| 1726 | |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 1727 | static const struct ethtool_ops mv643xx_eth_ethtool_ops = { |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 1728 | .get_settings = mv643xx_eth_get_settings, |
| 1729 | .set_settings = mv643xx_eth_set_settings, |
| 1730 | .get_drvinfo = mv643xx_eth_get_drvinfo, |
| 1731 | .nway_reset = mv643xx_eth_nway_reset, |
Ben Hutchings | ed4ba4b | 2010-12-09 12:10:25 +0000 | [diff] [blame] | 1732 | .get_link = ethtool_op_get_link, |
Lennert Buytenhek | 3e50803 | 2009-02-12 14:07:09 +0000 | [diff] [blame] | 1733 | .get_coalesce = mv643xx_eth_get_coalesce, |
| 1734 | .set_coalesce = mv643xx_eth_set_coalesce, |
Lennert Buytenhek | e7d2f4d | 2009-02-12 14:07:37 +0000 | [diff] [blame] | 1735 | .get_ringparam = mv643xx_eth_get_ringparam, |
| 1736 | .set_ringparam = mv643xx_eth_set_ringparam, |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 1737 | .get_strings = mv643xx_eth_get_strings, |
| 1738 | .get_ethtool_stats = mv643xx_eth_get_ethtool_stats, |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 1739 | .get_sset_count = mv643xx_eth_get_sset_count, |
Richard Cochran | ebad0a8 | 2012-04-03 22:59:32 +0000 | [diff] [blame] | 1740 | .get_ts_info = ethtool_op_get_ts_info, |
Michael Stapelberg | 3871c38 | 2013-03-11 13:56:45 +0000 | [diff] [blame^] | 1741 | .get_wol = mv643xx_eth_get_wol, |
| 1742 | .set_wol = mv643xx_eth_set_wol, |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1743 | }; |
| 1744 | |
| 1745 | |
| 1746 | /* address handling *********************************************************/ |
Lennert Buytenhek | 5daffe9 | 2008-06-01 02:52:41 +0200 | [diff] [blame] | 1747 | static void uc_addr_get(struct mv643xx_eth_private *mp, unsigned char *addr) |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1748 | { |
Lennert Buytenhek | 66e63ff | 2008-11-20 03:58:27 -0800 | [diff] [blame] | 1749 | unsigned int mac_h = rdlp(mp, MAC_ADDR_HIGH); |
| 1750 | unsigned int mac_l = rdlp(mp, MAC_ADDR_LOW); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1751 | |
Lennert Buytenhek | 5daffe9 | 2008-06-01 02:52:41 +0200 | [diff] [blame] | 1752 | addr[0] = (mac_h >> 24) & 0xff; |
| 1753 | addr[1] = (mac_h >> 16) & 0xff; |
| 1754 | addr[2] = (mac_h >> 8) & 0xff; |
| 1755 | addr[3] = mac_h & 0xff; |
| 1756 | addr[4] = (mac_l >> 8) & 0xff; |
| 1757 | addr[5] = mac_l & 0xff; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1758 | } |
| 1759 | |
Lennert Buytenhek | 5daffe9 | 2008-06-01 02:52:41 +0200 | [diff] [blame] | 1760 | static void uc_addr_set(struct mv643xx_eth_private *mp, unsigned char *addr) |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1761 | { |
Lennert Buytenhek | 66e63ff | 2008-11-20 03:58:27 -0800 | [diff] [blame] | 1762 | wrlp(mp, MAC_ADDR_HIGH, |
| 1763 | (addr[0] << 24) | (addr[1] << 16) | (addr[2] << 8) | addr[3]); |
| 1764 | wrlp(mp, MAC_ADDR_LOW, (addr[4] << 8) | addr[5]); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1765 | } |
| 1766 | |
Lennert Buytenhek | 66e63ff | 2008-11-20 03:58:27 -0800 | [diff] [blame] | 1767 | static u32 uc_addr_filter_mask(struct net_device *dev) |
| 1768 | { |
Jiri Pirko | ccffad25 | 2009-05-22 23:22:17 +0000 | [diff] [blame] | 1769 | struct netdev_hw_addr *ha; |
Lennert Buytenhek | 66e63ff | 2008-11-20 03:58:27 -0800 | [diff] [blame] | 1770 | u32 nibbles; |
| 1771 | |
| 1772 | if (dev->flags & IFF_PROMISC) |
| 1773 | return 0; |
| 1774 | |
| 1775 | nibbles = 1 << (dev->dev_addr[5] & 0x0f); |
Jiri Pirko | 32e7bfc | 2010-01-25 13:36:10 -0800 | [diff] [blame] | 1776 | netdev_for_each_uc_addr(ha, dev) { |
Jiri Pirko | ccffad25 | 2009-05-22 23:22:17 +0000 | [diff] [blame] | 1777 | if (memcmp(dev->dev_addr, ha->addr, 5)) |
Lennert Buytenhek | 66e63ff | 2008-11-20 03:58:27 -0800 | [diff] [blame] | 1778 | return 0; |
Jiri Pirko | ccffad25 | 2009-05-22 23:22:17 +0000 | [diff] [blame] | 1779 | if ((dev->dev_addr[5] ^ ha->addr[5]) & 0xf0) |
Lennert Buytenhek | 66e63ff | 2008-11-20 03:58:27 -0800 | [diff] [blame] | 1780 | return 0; |
| 1781 | |
Jiri Pirko | ccffad25 | 2009-05-22 23:22:17 +0000 | [diff] [blame] | 1782 | nibbles |= 1 << (ha->addr[5] & 0x0f); |
Lennert Buytenhek | 66e63ff | 2008-11-20 03:58:27 -0800 | [diff] [blame] | 1783 | } |
| 1784 | |
| 1785 | return nibbles; |
| 1786 | } |
| 1787 | |
| 1788 | static void mv643xx_eth_program_unicast_filter(struct net_device *dev) |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1789 | { |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 1790 | struct mv643xx_eth_private *mp = netdev_priv(dev); |
Lennert Buytenhek | 66e63ff | 2008-11-20 03:58:27 -0800 | [diff] [blame] | 1791 | u32 port_config; |
| 1792 | u32 nibbles; |
| 1793 | int i; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1794 | |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 1795 | uc_addr_set(mp, dev->dev_addr); |
| 1796 | |
Prabhanjan Sarnaik | 6877f54 | 2009-06-18 11:35:02 +0000 | [diff] [blame] | 1797 | port_config = rdlp(mp, PORT_CONFIG) & ~UNICAST_PROMISCUOUS_MODE; |
| 1798 | |
Lennert Buytenhek | 66e63ff | 2008-11-20 03:58:27 -0800 | [diff] [blame] | 1799 | nibbles = uc_addr_filter_mask(dev); |
| 1800 | if (!nibbles) { |
| 1801 | port_config |= UNICAST_PROMISCUOUS_MODE; |
Prabhanjan Sarnaik | 6877f54 | 2009-06-18 11:35:02 +0000 | [diff] [blame] | 1802 | nibbles = 0xffff; |
Lennert Buytenhek | 66e63ff | 2008-11-20 03:58:27 -0800 | [diff] [blame] | 1803 | } |
| 1804 | |
| 1805 | for (i = 0; i < 16; i += 4) { |
| 1806 | int off = UNICAST_TABLE(mp->port_num) + i; |
| 1807 | u32 v; |
| 1808 | |
| 1809 | v = 0; |
| 1810 | if (nibbles & 1) |
| 1811 | v |= 0x00000001; |
| 1812 | if (nibbles & 2) |
| 1813 | v |= 0x00000100; |
| 1814 | if (nibbles & 4) |
| 1815 | v |= 0x00010000; |
| 1816 | if (nibbles & 8) |
| 1817 | v |= 0x01000000; |
| 1818 | nibbles >>= 4; |
| 1819 | |
| 1820 | wrl(mp, off, v); |
| 1821 | } |
| 1822 | |
Lennert Buytenhek | 66e63ff | 2008-11-20 03:58:27 -0800 | [diff] [blame] | 1823 | wrlp(mp, PORT_CONFIG, port_config); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1824 | } |
| 1825 | |
Lennert Buytenhek | 6987656 | 2008-06-01 11:43:32 +0200 | [diff] [blame] | 1826 | static int addr_crc(unsigned char *addr) |
| 1827 | { |
| 1828 | int crc = 0; |
| 1829 | int i; |
| 1830 | |
| 1831 | for (i = 0; i < 6; i++) { |
| 1832 | int j; |
| 1833 | |
| 1834 | crc = (crc ^ addr[i]) << 8; |
| 1835 | for (j = 7; j >= 0; j--) { |
| 1836 | if (crc & (0x100 << j)) |
| 1837 | crc ^= 0x107 << j; |
| 1838 | } |
| 1839 | } |
| 1840 | |
| 1841 | return crc; |
| 1842 | } |
| 1843 | |
Lennert Buytenhek | 66e63ff | 2008-11-20 03:58:27 -0800 | [diff] [blame] | 1844 | static void mv643xx_eth_program_multicast_filter(struct net_device *dev) |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1845 | { |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 1846 | struct mv643xx_eth_private *mp = netdev_priv(dev); |
Lennert Buytenhek | 66e63ff | 2008-11-20 03:58:27 -0800 | [diff] [blame] | 1847 | u32 *mc_spec; |
| 1848 | u32 *mc_other; |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 1849 | struct netdev_hw_addr *ha; |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 1850 | int i; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1851 | |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 1852 | if (dev->flags & (IFF_PROMISC | IFF_ALLMULTI)) { |
Lennert Buytenhek | 66e63ff | 2008-11-20 03:58:27 -0800 | [diff] [blame] | 1853 | int port_num; |
| 1854 | u32 accept; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1855 | |
Lennert Buytenhek | 66e63ff | 2008-11-20 03:58:27 -0800 | [diff] [blame] | 1856 | oom: |
| 1857 | port_num = mp->port_num; |
| 1858 | accept = 0x01010101; |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 1859 | for (i = 0; i < 0x100; i += 4) { |
| 1860 | wrl(mp, SPECIAL_MCAST_TABLE(port_num) + i, accept); |
| 1861 | wrl(mp, OTHER_MCAST_TABLE(port_num) + i, accept); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1862 | } |
| 1863 | return; |
| 1864 | } |
| 1865 | |
Sebastian Siewior | 82a5bd6 | 2009-02-14 23:26:18 +0000 | [diff] [blame] | 1866 | mc_spec = kmalloc(0x200, GFP_ATOMIC); |
Lennert Buytenhek | 66e63ff | 2008-11-20 03:58:27 -0800 | [diff] [blame] | 1867 | if (mc_spec == NULL) |
| 1868 | goto oom; |
| 1869 | mc_other = mc_spec + (0x100 >> 2); |
| 1870 | |
| 1871 | memset(mc_spec, 0, 0x100); |
| 1872 | memset(mc_other, 0, 0x100); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1873 | |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 1874 | netdev_for_each_mc_addr(ha, dev) { |
| 1875 | u8 *a = ha->addr; |
Lennert Buytenhek | 66e63ff | 2008-11-20 03:58:27 -0800 | [diff] [blame] | 1876 | u32 *table; |
| 1877 | int entry; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1878 | |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 1879 | if (memcmp(a, "\x01\x00\x5e\x00\x00", 5) == 0) { |
Lennert Buytenhek | 66e63ff | 2008-11-20 03:58:27 -0800 | [diff] [blame] | 1880 | table = mc_spec; |
| 1881 | entry = a[5]; |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 1882 | } else { |
Lennert Buytenhek | 66e63ff | 2008-11-20 03:58:27 -0800 | [diff] [blame] | 1883 | table = mc_other; |
| 1884 | entry = addr_crc(a); |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 1885 | } |
Lennert Buytenhek | 66e63ff | 2008-11-20 03:58:27 -0800 | [diff] [blame] | 1886 | |
Lennert Buytenhek | 2b44833 | 2009-01-19 17:17:18 -0800 | [diff] [blame] | 1887 | table[entry >> 2] |= 1 << (8 * (entry & 3)); |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 1888 | } |
Lennert Buytenhek | 66e63ff | 2008-11-20 03:58:27 -0800 | [diff] [blame] | 1889 | |
| 1890 | for (i = 0; i < 0x100; i += 4) { |
| 1891 | wrl(mp, SPECIAL_MCAST_TABLE(mp->port_num) + i, mc_spec[i >> 2]); |
| 1892 | wrl(mp, OTHER_MCAST_TABLE(mp->port_num) + i, mc_other[i >> 2]); |
| 1893 | } |
| 1894 | |
| 1895 | kfree(mc_spec); |
| 1896 | } |
| 1897 | |
| 1898 | static void mv643xx_eth_set_rx_mode(struct net_device *dev) |
| 1899 | { |
| 1900 | mv643xx_eth_program_unicast_filter(dev); |
| 1901 | mv643xx_eth_program_multicast_filter(dev); |
| 1902 | } |
| 1903 | |
| 1904 | static int mv643xx_eth_set_mac_address(struct net_device *dev, void *addr) |
| 1905 | { |
| 1906 | struct sockaddr *sa = addr; |
| 1907 | |
Denis Kirjanov | a29ec08 | 2009-12-08 20:36:00 -0800 | [diff] [blame] | 1908 | if (!is_valid_ether_addr(sa->sa_data)) |
Danny Kukawka | 504f9b5 | 2012-02-21 02:07:49 +0000 | [diff] [blame] | 1909 | return -EADDRNOTAVAIL; |
Denis Kirjanov | a29ec08 | 2009-12-08 20:36:00 -0800 | [diff] [blame] | 1910 | |
Lennert Buytenhek | 66e63ff | 2008-11-20 03:58:27 -0800 | [diff] [blame] | 1911 | memcpy(dev->dev_addr, sa->sa_data, ETH_ALEN); |
| 1912 | |
| 1913 | netif_addr_lock_bh(dev); |
| 1914 | mv643xx_eth_program_unicast_filter(dev); |
| 1915 | netif_addr_unlock_bh(dev); |
| 1916 | |
| 1917 | return 0; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1918 | } |
| 1919 | |
| 1920 | |
| 1921 | /* rx/tx queue initialisation ***********************************************/ |
Lennert Buytenhek | 64da80a | 2008-06-02 01:01:26 +0200 | [diff] [blame] | 1922 | static int rxq_init(struct mv643xx_eth_private *mp, int index) |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1923 | { |
Lennert Buytenhek | 64da80a | 2008-06-02 01:01:26 +0200 | [diff] [blame] | 1924 | struct rx_queue *rxq = mp->rxq + index; |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 1925 | struct rx_desc *rx_desc; |
| 1926 | int size; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1927 | int i; |
| 1928 | |
Lennert Buytenhek | 64da80a | 2008-06-02 01:01:26 +0200 | [diff] [blame] | 1929 | rxq->index = index; |
| 1930 | |
Lennert Buytenhek | e7d2f4d | 2009-02-12 14:07:37 +0000 | [diff] [blame] | 1931 | rxq->rx_ring_size = mp->rx_ring_size; |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 1932 | |
| 1933 | rxq->rx_desc_count = 0; |
| 1934 | rxq->rx_curr_desc = 0; |
| 1935 | rxq->rx_used_desc = 0; |
| 1936 | |
| 1937 | size = rxq->rx_ring_size * sizeof(struct rx_desc); |
| 1938 | |
Lennert Buytenhek | f7981c1 | 2008-08-26 10:23:22 +0200 | [diff] [blame] | 1939 | if (index == 0 && size <= mp->rx_desc_sram_size) { |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 1940 | rxq->rx_desc_area = ioremap(mp->rx_desc_sram_addr, |
| 1941 | mp->rx_desc_sram_size); |
| 1942 | rxq->rx_desc_dma = mp->rx_desc_sram_addr; |
| 1943 | } else { |
Gabriel Paubert | eb0519b | 2009-05-17 21:16:47 -0700 | [diff] [blame] | 1944 | rxq->rx_desc_area = dma_alloc_coherent(mp->dev->dev.parent, |
| 1945 | size, &rxq->rx_desc_dma, |
| 1946 | GFP_KERNEL); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1947 | } |
| 1948 | |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 1949 | if (rxq->rx_desc_area == NULL) { |
Joe Perches | 7542db8 | 2011-03-02 17:50:35 +0000 | [diff] [blame] | 1950 | netdev_err(mp->dev, |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 1951 | "can't allocate rx ring (%d bytes)\n", size); |
| 1952 | goto out; |
| 1953 | } |
| 1954 | memset(rxq->rx_desc_area, 0, size); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 1955 | |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 1956 | rxq->rx_desc_area_size = size; |
Joe Perches | b2adaca | 2013-02-03 17:43:58 +0000 | [diff] [blame] | 1957 | rxq->rx_skb = kmalloc_array(rxq->rx_ring_size, sizeof(*rxq->rx_skb), |
| 1958 | GFP_KERNEL); |
| 1959 | if (rxq->rx_skb == NULL) |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 1960 | goto out_free; |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 1961 | |
Joe Perches | 6469933 | 2012-06-04 12:44:16 +0000 | [diff] [blame] | 1962 | rx_desc = rxq->rx_desc_area; |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 1963 | for (i = 0; i < rxq->rx_ring_size; i++) { |
Lennert Buytenhek | 9da7874 | 2008-08-23 23:45:28 +0200 | [diff] [blame] | 1964 | int nexti; |
| 1965 | |
| 1966 | nexti = i + 1; |
| 1967 | if (nexti == rxq->rx_ring_size) |
| 1968 | nexti = 0; |
| 1969 | |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 1970 | rx_desc[i].next_desc_ptr = rxq->rx_desc_dma + |
| 1971 | nexti * sizeof(struct rx_desc); |
| 1972 | } |
| 1973 | |
Lennert Buytenhek | eaf5d59 | 2009-02-12 14:08:39 +0000 | [diff] [blame] | 1974 | rxq->lro_mgr.dev = mp->dev; |
| 1975 | memset(&rxq->lro_mgr.stats, 0, sizeof(rxq->lro_mgr.stats)); |
| 1976 | rxq->lro_mgr.features = LRO_F_NAPI; |
| 1977 | rxq->lro_mgr.ip_summed = CHECKSUM_UNNECESSARY; |
| 1978 | rxq->lro_mgr.ip_summed_aggr = CHECKSUM_UNNECESSARY; |
| 1979 | rxq->lro_mgr.max_desc = ARRAY_SIZE(rxq->lro_arr); |
| 1980 | rxq->lro_mgr.max_aggr = 32; |
| 1981 | rxq->lro_mgr.frag_align_pad = 0; |
| 1982 | rxq->lro_mgr.lro_arr = rxq->lro_arr; |
| 1983 | rxq->lro_mgr.get_skb_header = mv643xx_get_skb_header; |
| 1984 | |
| 1985 | memset(&rxq->lro_arr, 0, sizeof(rxq->lro_arr)); |
Lennert Buytenhek | eaf5d59 | 2009-02-12 14:08:39 +0000 | [diff] [blame] | 1986 | |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 1987 | return 0; |
| 1988 | |
| 1989 | |
| 1990 | out_free: |
Lennert Buytenhek | f7981c1 | 2008-08-26 10:23:22 +0200 | [diff] [blame] | 1991 | if (index == 0 && size <= mp->rx_desc_sram_size) |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 1992 | iounmap(rxq->rx_desc_area); |
| 1993 | else |
Gabriel Paubert | eb0519b | 2009-05-17 21:16:47 -0700 | [diff] [blame] | 1994 | dma_free_coherent(mp->dev->dev.parent, size, |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 1995 | rxq->rx_desc_area, |
| 1996 | rxq->rx_desc_dma); |
| 1997 | |
| 1998 | out: |
| 1999 | return -ENOMEM; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2000 | } |
| 2001 | |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 2002 | static void rxq_deinit(struct rx_queue *rxq) |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2003 | { |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 2004 | struct mv643xx_eth_private *mp = rxq_to_mp(rxq); |
| 2005 | int i; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2006 | |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 2007 | rxq_disable(rxq); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2008 | |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 2009 | for (i = 0; i < rxq->rx_ring_size; i++) { |
| 2010 | if (rxq->rx_skb[i]) { |
| 2011 | dev_kfree_skb(rxq->rx_skb[i]); |
| 2012 | rxq->rx_desc_count--; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2013 | } |
| 2014 | } |
| 2015 | |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 2016 | if (rxq->rx_desc_count) { |
Joe Perches | 7542db8 | 2011-03-02 17:50:35 +0000 | [diff] [blame] | 2017 | netdev_err(mp->dev, "error freeing rx ring -- %d skbs stuck\n", |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 2018 | rxq->rx_desc_count); |
| 2019 | } |
| 2020 | |
Lennert Buytenhek | f7981c1 | 2008-08-26 10:23:22 +0200 | [diff] [blame] | 2021 | if (rxq->index == 0 && |
Lennert Buytenhek | 64da80a | 2008-06-02 01:01:26 +0200 | [diff] [blame] | 2022 | rxq->rx_desc_area_size <= mp->rx_desc_sram_size) |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 2023 | iounmap(rxq->rx_desc_area); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2024 | else |
Gabriel Paubert | eb0519b | 2009-05-17 21:16:47 -0700 | [diff] [blame] | 2025 | dma_free_coherent(mp->dev->dev.parent, rxq->rx_desc_area_size, |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 2026 | rxq->rx_desc_area, rxq->rx_desc_dma); |
| 2027 | |
| 2028 | kfree(rxq->rx_skb); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2029 | } |
| 2030 | |
Lennert Buytenhek | 3d6b35b | 2008-06-02 01:28:22 +0200 | [diff] [blame] | 2031 | static int txq_init(struct mv643xx_eth_private *mp, int index) |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2032 | { |
Lennert Buytenhek | 3d6b35b | 2008-06-02 01:28:22 +0200 | [diff] [blame] | 2033 | struct tx_queue *txq = mp->txq + index; |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 2034 | struct tx_desc *tx_desc; |
| 2035 | int size; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2036 | int i; |
| 2037 | |
Lennert Buytenhek | 3d6b35b | 2008-06-02 01:28:22 +0200 | [diff] [blame] | 2038 | txq->index = index; |
| 2039 | |
Lennert Buytenhek | e7d2f4d | 2009-02-12 14:07:37 +0000 | [diff] [blame] | 2040 | txq->tx_ring_size = mp->tx_ring_size; |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 2041 | |
| 2042 | txq->tx_desc_count = 0; |
| 2043 | txq->tx_curr_desc = 0; |
| 2044 | txq->tx_used_desc = 0; |
| 2045 | |
| 2046 | size = txq->tx_ring_size * sizeof(struct tx_desc); |
| 2047 | |
Lennert Buytenhek | f7981c1 | 2008-08-26 10:23:22 +0200 | [diff] [blame] | 2048 | if (index == 0 && size <= mp->tx_desc_sram_size) { |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 2049 | txq->tx_desc_area = ioremap(mp->tx_desc_sram_addr, |
| 2050 | mp->tx_desc_sram_size); |
| 2051 | txq->tx_desc_dma = mp->tx_desc_sram_addr; |
| 2052 | } else { |
Gabriel Paubert | eb0519b | 2009-05-17 21:16:47 -0700 | [diff] [blame] | 2053 | txq->tx_desc_area = dma_alloc_coherent(mp->dev->dev.parent, |
| 2054 | size, &txq->tx_desc_dma, |
| 2055 | GFP_KERNEL); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2056 | } |
| 2057 | |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 2058 | if (txq->tx_desc_area == NULL) { |
Joe Perches | 7542db8 | 2011-03-02 17:50:35 +0000 | [diff] [blame] | 2059 | netdev_err(mp->dev, |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 2060 | "can't allocate tx ring (%d bytes)\n", size); |
Lennert Buytenhek | 99ab08e | 2008-08-28 05:53:18 +0200 | [diff] [blame] | 2061 | return -ENOMEM; |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 2062 | } |
| 2063 | memset(txq->tx_desc_area, 0, size); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2064 | |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 2065 | txq->tx_desc_area_size = size; |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 2066 | |
Joe Perches | 6469933 | 2012-06-04 12:44:16 +0000 | [diff] [blame] | 2067 | tx_desc = txq->tx_desc_area; |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 2068 | for (i = 0; i < txq->tx_ring_size; i++) { |
Lennert Buytenhek | 6b368f6 | 2008-07-11 19:38:34 +0200 | [diff] [blame] | 2069 | struct tx_desc *txd = tx_desc + i; |
Lennert Buytenhek | 9da7874 | 2008-08-23 23:45:28 +0200 | [diff] [blame] | 2070 | int nexti; |
| 2071 | |
| 2072 | nexti = i + 1; |
| 2073 | if (nexti == txq->tx_ring_size) |
| 2074 | nexti = 0; |
Lennert Buytenhek | 6b368f6 | 2008-07-11 19:38:34 +0200 | [diff] [blame] | 2075 | |
| 2076 | txd->cmd_sts = 0; |
| 2077 | txd->next_desc_ptr = txq->tx_desc_dma + |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 2078 | nexti * sizeof(struct tx_desc); |
| 2079 | } |
| 2080 | |
Lennert Buytenhek | 99ab08e | 2008-08-28 05:53:18 +0200 | [diff] [blame] | 2081 | skb_queue_head_init(&txq->tx_skb); |
| 2082 | |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 2083 | return 0; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2084 | } |
| 2085 | |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 2086 | static void txq_deinit(struct tx_queue *txq) |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2087 | { |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 2088 | struct mv643xx_eth_private *mp = txq_to_mp(txq); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2089 | |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 2090 | txq_disable(txq); |
Lennert Buytenhek | 1fa38c5 | 2008-08-28 08:09:10 +0200 | [diff] [blame] | 2091 | txq_reclaim(txq, txq->tx_ring_size, 1); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2092 | |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 2093 | BUG_ON(txq->tx_used_desc != txq->tx_curr_desc); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2094 | |
Lennert Buytenhek | f7981c1 | 2008-08-26 10:23:22 +0200 | [diff] [blame] | 2095 | if (txq->index == 0 && |
Lennert Buytenhek | 3d6b35b | 2008-06-02 01:28:22 +0200 | [diff] [blame] | 2096 | txq->tx_desc_area_size <= mp->tx_desc_sram_size) |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 2097 | iounmap(txq->tx_desc_area); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2098 | else |
Gabriel Paubert | eb0519b | 2009-05-17 21:16:47 -0700 | [diff] [blame] | 2099 | dma_free_coherent(mp->dev->dev.parent, txq->tx_desc_area_size, |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 2100 | txq->tx_desc_area, txq->tx_desc_dma); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2101 | } |
| 2102 | |
| 2103 | |
| 2104 | /* netdev ops and related ***************************************************/ |
Lennert Buytenhek | 1fa38c5 | 2008-08-28 08:09:10 +0200 | [diff] [blame] | 2105 | static int mv643xx_eth_collect_events(struct mv643xx_eth_private *mp) |
| 2106 | { |
| 2107 | u32 int_cause; |
| 2108 | u32 int_cause_ext; |
| 2109 | |
Saeed Bishara | e0ca841 | 2009-05-06 03:02:01 +0000 | [diff] [blame] | 2110 | int_cause = rdlp(mp, INT_CAUSE) & mp->int_mask; |
Lennert Buytenhek | 1fa38c5 | 2008-08-28 08:09:10 +0200 | [diff] [blame] | 2111 | if (int_cause == 0) |
| 2112 | return 0; |
| 2113 | |
| 2114 | int_cause_ext = 0; |
Saeed Bishara | e0ca841 | 2009-05-06 03:02:01 +0000 | [diff] [blame] | 2115 | if (int_cause & INT_EXT) { |
| 2116 | int_cause &= ~INT_EXT; |
Lennert Buytenhek | 37a6084 | 2008-11-20 03:57:36 -0800 | [diff] [blame] | 2117 | int_cause_ext = rdlp(mp, INT_CAUSE_EXT); |
Saeed Bishara | e0ca841 | 2009-05-06 03:02:01 +0000 | [diff] [blame] | 2118 | } |
Lennert Buytenhek | 1fa38c5 | 2008-08-28 08:09:10 +0200 | [diff] [blame] | 2119 | |
Lennert Buytenhek | 1fa38c5 | 2008-08-28 08:09:10 +0200 | [diff] [blame] | 2120 | if (int_cause) { |
Lennert Buytenhek | 37a6084 | 2008-11-20 03:57:36 -0800 | [diff] [blame] | 2121 | wrlp(mp, INT_CAUSE, ~int_cause); |
Lennert Buytenhek | 1fa38c5 | 2008-08-28 08:09:10 +0200 | [diff] [blame] | 2122 | mp->work_tx_end |= ((int_cause & INT_TX_END) >> 19) & |
Lennert Buytenhek | 37a6084 | 2008-11-20 03:57:36 -0800 | [diff] [blame] | 2123 | ~(rdlp(mp, TXQ_COMMAND) & 0xff); |
Lennert Buytenhek | 1fa38c5 | 2008-08-28 08:09:10 +0200 | [diff] [blame] | 2124 | mp->work_rx |= (int_cause & INT_RX) >> 2; |
| 2125 | } |
| 2126 | |
| 2127 | int_cause_ext &= INT_EXT_LINK_PHY | INT_EXT_TX; |
| 2128 | if (int_cause_ext) { |
Lennert Buytenhek | 37a6084 | 2008-11-20 03:57:36 -0800 | [diff] [blame] | 2129 | wrlp(mp, INT_CAUSE_EXT, ~int_cause_ext); |
Lennert Buytenhek | 1fa38c5 | 2008-08-28 08:09:10 +0200 | [diff] [blame] | 2130 | if (int_cause_ext & INT_EXT_LINK_PHY) |
| 2131 | mp->work_link = 1; |
| 2132 | mp->work_tx |= int_cause_ext & INT_EXT_TX; |
| 2133 | } |
| 2134 | |
| 2135 | return 1; |
| 2136 | } |
| 2137 | |
| 2138 | static irqreturn_t mv643xx_eth_irq(int irq, void *dev_id) |
| 2139 | { |
| 2140 | struct net_device *dev = (struct net_device *)dev_id; |
| 2141 | struct mv643xx_eth_private *mp = netdev_priv(dev); |
| 2142 | |
| 2143 | if (unlikely(!mv643xx_eth_collect_events(mp))) |
| 2144 | return IRQ_NONE; |
| 2145 | |
Lennert Buytenhek | 37a6084 | 2008-11-20 03:57:36 -0800 | [diff] [blame] | 2146 | wrlp(mp, INT_MASK, 0); |
Lennert Buytenhek | 1fa38c5 | 2008-08-28 08:09:10 +0200 | [diff] [blame] | 2147 | napi_schedule(&mp->napi); |
| 2148 | |
| 2149 | return IRQ_HANDLED; |
| 2150 | } |
| 2151 | |
Lennert Buytenhek | 2f7eb47 | 2008-07-24 06:22:59 +0200 | [diff] [blame] | 2152 | static void handle_link_event(struct mv643xx_eth_private *mp) |
| 2153 | { |
| 2154 | struct net_device *dev = mp->dev; |
| 2155 | u32 port_status; |
| 2156 | int speed; |
| 2157 | int duplex; |
| 2158 | int fc; |
| 2159 | |
Lennert Buytenhek | 37a6084 | 2008-11-20 03:57:36 -0800 | [diff] [blame] | 2160 | port_status = rdlp(mp, PORT_STATUS); |
Lennert Buytenhek | 2f7eb47 | 2008-07-24 06:22:59 +0200 | [diff] [blame] | 2161 | if (!(port_status & LINK_UP)) { |
| 2162 | if (netif_carrier_ok(dev)) { |
| 2163 | int i; |
| 2164 | |
Joe Perches | 7542db8 | 2011-03-02 17:50:35 +0000 | [diff] [blame] | 2165 | netdev_info(dev, "link down\n"); |
Lennert Buytenhek | 2f7eb47 | 2008-07-24 06:22:59 +0200 | [diff] [blame] | 2166 | |
| 2167 | netif_carrier_off(dev); |
Lennert Buytenhek | 2f7eb47 | 2008-07-24 06:22:59 +0200 | [diff] [blame] | 2168 | |
Lennert Buytenhek | f7981c1 | 2008-08-26 10:23:22 +0200 | [diff] [blame] | 2169 | for (i = 0; i < mp->txq_count; i++) { |
Lennert Buytenhek | 2f7eb47 | 2008-07-24 06:22:59 +0200 | [diff] [blame] | 2170 | struct tx_queue *txq = mp->txq + i; |
| 2171 | |
Lennert Buytenhek | 1fa38c5 | 2008-08-28 08:09:10 +0200 | [diff] [blame] | 2172 | txq_reclaim(txq, txq->tx_ring_size, 1); |
Lennert Buytenhek | f7981c1 | 2008-08-26 10:23:22 +0200 | [diff] [blame] | 2173 | txq_reset_hw_ptr(txq); |
Lennert Buytenhek | 2f7eb47 | 2008-07-24 06:22:59 +0200 | [diff] [blame] | 2174 | } |
| 2175 | } |
| 2176 | return; |
| 2177 | } |
| 2178 | |
| 2179 | switch (port_status & PORT_SPEED_MASK) { |
| 2180 | case PORT_SPEED_10: |
| 2181 | speed = 10; |
| 2182 | break; |
| 2183 | case PORT_SPEED_100: |
| 2184 | speed = 100; |
| 2185 | break; |
| 2186 | case PORT_SPEED_1000: |
| 2187 | speed = 1000; |
| 2188 | break; |
| 2189 | default: |
| 2190 | speed = -1; |
| 2191 | break; |
| 2192 | } |
| 2193 | duplex = (port_status & FULL_DUPLEX) ? 1 : 0; |
| 2194 | fc = (port_status & FLOW_CONTROL_ENABLED) ? 1 : 0; |
| 2195 | |
Joe Perches | 7542db8 | 2011-03-02 17:50:35 +0000 | [diff] [blame] | 2196 | netdev_info(dev, "link up, %d Mb/s, %s duplex, flow control %sabled\n", |
| 2197 | speed, duplex ? "full" : "half", fc ? "en" : "dis"); |
Lennert Buytenhek | 2f7eb47 | 2008-07-24 06:22:59 +0200 | [diff] [blame] | 2198 | |
Lennert Buytenhek | 4fdeca3 | 2008-08-28 05:39:13 +0200 | [diff] [blame] | 2199 | if (!netif_carrier_ok(dev)) |
Lennert Buytenhek | 2f7eb47 | 2008-07-24 06:22:59 +0200 | [diff] [blame] | 2200 | netif_carrier_on(dev); |
Lennert Buytenhek | 2f7eb47 | 2008-07-24 06:22:59 +0200 | [diff] [blame] | 2201 | } |
| 2202 | |
Lennert Buytenhek | 1fa38c5 | 2008-08-28 08:09:10 +0200 | [diff] [blame] | 2203 | static int mv643xx_eth_poll(struct napi_struct *napi, int budget) |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2204 | { |
Lennert Buytenhek | 1fa38c5 | 2008-08-28 08:09:10 +0200 | [diff] [blame] | 2205 | struct mv643xx_eth_private *mp; |
| 2206 | int work_done; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2207 | |
Lennert Buytenhek | 1fa38c5 | 2008-08-28 08:09:10 +0200 | [diff] [blame] | 2208 | mp = container_of(napi, struct mv643xx_eth_private, napi); |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 2209 | |
Lennert Buytenhek | 1319eba | 2009-04-29 11:57:34 +0000 | [diff] [blame] | 2210 | if (unlikely(mp->oom)) { |
| 2211 | mp->oom = 0; |
| 2212 | del_timer(&mp->rx_oom); |
| 2213 | } |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2214 | |
Lennert Buytenhek | 1fa38c5 | 2008-08-28 08:09:10 +0200 | [diff] [blame] | 2215 | work_done = 0; |
| 2216 | while (work_done < budget) { |
| 2217 | u8 queue_mask; |
| 2218 | int queue; |
| 2219 | int work_tbd; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2220 | |
Lennert Buytenhek | 1fa38c5 | 2008-08-28 08:09:10 +0200 | [diff] [blame] | 2221 | if (mp->work_link) { |
| 2222 | mp->work_link = 0; |
| 2223 | handle_link_event(mp); |
Lennert Buytenhek | 26ef1f1 | 2009-05-06 03:01:10 +0000 | [diff] [blame] | 2224 | work_done++; |
Lennert Buytenhek | 1fa38c5 | 2008-08-28 08:09:10 +0200 | [diff] [blame] | 2225 | continue; |
Lennert Buytenhek | 226bb6b | 2008-06-02 01:47:21 +0200 | [diff] [blame] | 2226 | } |
Lennert Buytenhek | 1fa38c5 | 2008-08-28 08:09:10 +0200 | [diff] [blame] | 2227 | |
Lennert Buytenhek | 1319eba | 2009-04-29 11:57:34 +0000 | [diff] [blame] | 2228 | queue_mask = mp->work_tx | mp->work_tx_end | mp->work_rx; |
| 2229 | if (likely(!mp->oom)) |
| 2230 | queue_mask |= mp->work_rx_refill; |
| 2231 | |
Lennert Buytenhek | 1fa38c5 | 2008-08-28 08:09:10 +0200 | [diff] [blame] | 2232 | if (!queue_mask) { |
| 2233 | if (mv643xx_eth_collect_events(mp)) |
| 2234 | continue; |
| 2235 | break; |
| 2236 | } |
| 2237 | |
| 2238 | queue = fls(queue_mask) - 1; |
| 2239 | queue_mask = 1 << queue; |
| 2240 | |
| 2241 | work_tbd = budget - work_done; |
| 2242 | if (work_tbd > 16) |
| 2243 | work_tbd = 16; |
| 2244 | |
| 2245 | if (mp->work_tx_end & queue_mask) { |
| 2246 | txq_kick(mp->txq + queue); |
| 2247 | } else if (mp->work_tx & queue_mask) { |
| 2248 | work_done += txq_reclaim(mp->txq + queue, work_tbd, 0); |
| 2249 | txq_maybe_wake(mp->txq + queue); |
| 2250 | } else if (mp->work_rx & queue_mask) { |
| 2251 | work_done += rxq_process(mp->rxq + queue, work_tbd); |
Lennert Buytenhek | 1319eba | 2009-04-29 11:57:34 +0000 | [diff] [blame] | 2252 | } else if (!mp->oom && (mp->work_rx_refill & queue_mask)) { |
Lennert Buytenhek | 1fa38c5 | 2008-08-28 08:09:10 +0200 | [diff] [blame] | 2253 | work_done += rxq_refill(mp->rxq + queue, work_tbd); |
| 2254 | } else { |
| 2255 | BUG(); |
| 2256 | } |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 2257 | } |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2258 | |
Lennert Buytenhek | 1fa38c5 | 2008-08-28 08:09:10 +0200 | [diff] [blame] | 2259 | if (work_done < budget) { |
Lennert Buytenhek | 1319eba | 2009-04-29 11:57:34 +0000 | [diff] [blame] | 2260 | if (mp->oom) |
Lennert Buytenhek | 1fa38c5 | 2008-08-28 08:09:10 +0200 | [diff] [blame] | 2261 | mod_timer(&mp->rx_oom, jiffies + (HZ / 10)); |
| 2262 | napi_complete(napi); |
Saeed Bishara | e0ca841 | 2009-05-06 03:02:01 +0000 | [diff] [blame] | 2263 | wrlp(mp, INT_MASK, mp->int_mask); |
Lennert Buytenhek | 1fa38c5 | 2008-08-28 08:09:10 +0200 | [diff] [blame] | 2264 | } |
| 2265 | |
| 2266 | return work_done; |
| 2267 | } |
| 2268 | |
| 2269 | static inline void oom_timer_wrapper(unsigned long data) |
| 2270 | { |
| 2271 | struct mv643xx_eth_private *mp = (void *)data; |
| 2272 | |
| 2273 | napi_schedule(&mp->napi); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2274 | } |
| 2275 | |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 2276 | static void phy_reset(struct mv643xx_eth_private *mp) |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2277 | { |
Lennert Buytenhek | 45c5d3b | 2008-08-26 04:42:59 +0200 | [diff] [blame] | 2278 | int data; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2279 | |
Lennert Buytenhek | ed94493 | 2008-08-26 13:34:19 +0200 | [diff] [blame] | 2280 | data = phy_read(mp->phy, MII_BMCR); |
Lennert Buytenhek | 45c5d3b | 2008-08-26 04:42:59 +0200 | [diff] [blame] | 2281 | if (data < 0) |
| 2282 | return; |
| 2283 | |
Lennert Buytenhek | 7f106c1 | 2008-07-15 02:28:47 +0200 | [diff] [blame] | 2284 | data |= BMCR_RESET; |
Lennert Buytenhek | ed94493 | 2008-08-26 13:34:19 +0200 | [diff] [blame] | 2285 | if (phy_write(mp->phy, MII_BMCR, data) < 0) |
Lennert Buytenhek | 45c5d3b | 2008-08-26 04:42:59 +0200 | [diff] [blame] | 2286 | return; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2287 | |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2288 | do { |
Lennert Buytenhek | ed94493 | 2008-08-26 13:34:19 +0200 | [diff] [blame] | 2289 | data = phy_read(mp->phy, MII_BMCR); |
Lennert Buytenhek | 45c5d3b | 2008-08-26 04:42:59 +0200 | [diff] [blame] | 2290 | } while (data >= 0 && data & BMCR_RESET); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2291 | } |
| 2292 | |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 2293 | static void port_start(struct mv643xx_eth_private *mp) |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2294 | { |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2295 | u32 pscr; |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 2296 | int i; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2297 | |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 2298 | /* |
Lennert Buytenhek | bedfe32 | 2008-06-02 02:13:03 +0200 | [diff] [blame] | 2299 | * Perform PHY reset, if there is a PHY. |
| 2300 | */ |
Lennert Buytenhek | ed94493 | 2008-08-26 13:34:19 +0200 | [diff] [blame] | 2301 | if (mp->phy != NULL) { |
Lennert Buytenhek | bedfe32 | 2008-06-02 02:13:03 +0200 | [diff] [blame] | 2302 | struct ethtool_cmd cmd; |
| 2303 | |
| 2304 | mv643xx_eth_get_settings(mp->dev, &cmd); |
| 2305 | phy_reset(mp); |
| 2306 | mv643xx_eth_set_settings(mp->dev, &cmd); |
| 2307 | } |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2308 | |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 2309 | /* |
Lennert Buytenhek | 81600eea9 | 2008-07-14 14:29:40 +0200 | [diff] [blame] | 2310 | * Configure basic link parameters. |
| 2311 | */ |
Lennert Buytenhek | 37a6084 | 2008-11-20 03:57:36 -0800 | [diff] [blame] | 2312 | pscr = rdlp(mp, PORT_SERIAL_CONTROL); |
Lennert Buytenhek | 81600eea9 | 2008-07-14 14:29:40 +0200 | [diff] [blame] | 2313 | |
| 2314 | pscr |= SERIAL_PORT_ENABLE; |
Lennert Buytenhek | 37a6084 | 2008-11-20 03:57:36 -0800 | [diff] [blame] | 2315 | wrlp(mp, PORT_SERIAL_CONTROL, pscr); |
Lennert Buytenhek | 81600eea9 | 2008-07-14 14:29:40 +0200 | [diff] [blame] | 2316 | |
| 2317 | pscr |= DO_NOT_FORCE_LINK_FAIL; |
Lennert Buytenhek | ed94493 | 2008-08-26 13:34:19 +0200 | [diff] [blame] | 2318 | if (mp->phy == NULL) |
Lennert Buytenhek | 81600eea9 | 2008-07-14 14:29:40 +0200 | [diff] [blame] | 2319 | pscr |= FORCE_LINK_PASS; |
Lennert Buytenhek | 37a6084 | 2008-11-20 03:57:36 -0800 | [diff] [blame] | 2320 | wrlp(mp, PORT_SERIAL_CONTROL, pscr); |
Lennert Buytenhek | 81600eea9 | 2008-07-14 14:29:40 +0200 | [diff] [blame] | 2321 | |
Lennert Buytenhek | 81600eea9 | 2008-07-14 14:29:40 +0200 | [diff] [blame] | 2322 | /* |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 2323 | * Configure TX path and queues. |
| 2324 | */ |
Lennert Buytenhek | 89df5fd | 2008-06-02 00:51:05 +0200 | [diff] [blame] | 2325 | tx_set_rate(mp, 1000000000, 16777216); |
Lennert Buytenhek | f7981c1 | 2008-08-26 10:23:22 +0200 | [diff] [blame] | 2326 | for (i = 0; i < mp->txq_count; i++) { |
Lennert Buytenhek | 3d6b35b | 2008-06-02 01:28:22 +0200 | [diff] [blame] | 2327 | struct tx_queue *txq = mp->txq + i; |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 2328 | |
Lennert Buytenhek | 6b368f6 | 2008-07-11 19:38:34 +0200 | [diff] [blame] | 2329 | txq_reset_hw_ptr(txq); |
Lennert Buytenhek | 89df5fd | 2008-06-02 00:51:05 +0200 | [diff] [blame] | 2330 | txq_set_rate(txq, 1000000000, 16777216); |
| 2331 | txq_set_fixed_prio_mode(txq); |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 2332 | } |
| 2333 | |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 2334 | /* |
Lennert Buytenhek | d9a073e | 2008-06-01 01:22:06 +0200 | [diff] [blame] | 2335 | * Receive all unmatched unicast, TCP, UDP, BPDU and broadcast |
Lennert Buytenhek | 170e710 | 2008-09-19 02:58:50 +0200 | [diff] [blame] | 2336 | * frames to RX queue #0, and include the pseudo-header when |
| 2337 | * calculating receive checksums. |
Lennert Buytenhek | d9a073e | 2008-06-01 01:22:06 +0200 | [diff] [blame] | 2338 | */ |
David S. Miller | e138f96 | 2011-04-21 15:19:02 -0700 | [diff] [blame] | 2339 | mv643xx_eth_set_features(mp->dev, mp->dev->features); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2340 | |
Lennert Buytenhek | 376489a | 2008-06-01 01:17:44 +0200 | [diff] [blame] | 2341 | /* |
| 2342 | * Treat BPDUs as normal multicasts, and disable partition mode. |
| 2343 | */ |
Lennert Buytenhek | 37a6084 | 2008-11-20 03:57:36 -0800 | [diff] [blame] | 2344 | wrlp(mp, PORT_CONFIG_EXT, 0x00000000); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2345 | |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 2346 | /* |
Lennert Buytenhek | 5a89392 | 2009-03-13 15:48:02 -0700 | [diff] [blame] | 2347 | * Add configured unicast addresses to address filter table. |
| 2348 | */ |
| 2349 | mv643xx_eth_program_unicast_filter(mp->dev); |
| 2350 | |
| 2351 | /* |
Lennert Buytenhek | 64da80a | 2008-06-02 01:01:26 +0200 | [diff] [blame] | 2352 | * Enable the receive queues. |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 2353 | */ |
Lennert Buytenhek | f7981c1 | 2008-08-26 10:23:22 +0200 | [diff] [blame] | 2354 | for (i = 0; i < mp->rxq_count; i++) { |
Lennert Buytenhek | 64da80a | 2008-06-02 01:01:26 +0200 | [diff] [blame] | 2355 | struct rx_queue *rxq = mp->rxq + i; |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 2356 | u32 addr; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2357 | |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 2358 | addr = (u32)rxq->rx_desc_dma; |
| 2359 | addr += rxq->rx_curr_desc * sizeof(struct rx_desc); |
Lennert Buytenhek | 37a6084 | 2008-11-20 03:57:36 -0800 | [diff] [blame] | 2360 | wrlp(mp, RXQ_CURRENT_DESC_PTR(i), addr); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2361 | |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 2362 | rxq_enable(rxq); |
| 2363 | } |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2364 | } |
| 2365 | |
Lennert Buytenhek | 2bcb4b0 | 2008-10-01 02:33:57 -0700 | [diff] [blame] | 2366 | static void mv643xx_eth_recalc_skb_size(struct mv643xx_eth_private *mp) |
| 2367 | { |
| 2368 | int skb_size; |
| 2369 | |
| 2370 | /* |
| 2371 | * Reserve 2+14 bytes for an ethernet header (the hardware |
| 2372 | * automatically prepends 2 bytes of dummy data to each |
| 2373 | * received packet), 16 bytes for up to four VLAN tags, and |
| 2374 | * 4 bytes for the trailing FCS -- 36 bytes total. |
| 2375 | */ |
| 2376 | skb_size = mp->dev->mtu + 36; |
| 2377 | |
| 2378 | /* |
| 2379 | * Make sure that the skb size is a multiple of 8 bytes, as |
| 2380 | * the lower three bits of the receive descriptor's buffer |
| 2381 | * size field are ignored by the hardware. |
| 2382 | */ |
| 2383 | mp->skb_size = (skb_size + 7) & ~7; |
Lennert Buytenhek | 7fd96ce | 2009-05-06 03:01:22 +0000 | [diff] [blame] | 2384 | |
| 2385 | /* |
| 2386 | * If NET_SKB_PAD is smaller than a cache line, |
| 2387 | * netdev_alloc_skb() will cause skb->data to be misaligned |
| 2388 | * to a cache line boundary. If this is the case, include |
| 2389 | * some extra space to allow re-aligning the data area. |
| 2390 | */ |
| 2391 | mp->skb_size += SKB_DMA_REALIGN; |
Lennert Buytenhek | 2bcb4b0 | 2008-10-01 02:33:57 -0700 | [diff] [blame] | 2392 | } |
| 2393 | |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2394 | static int mv643xx_eth_open(struct net_device *dev) |
| 2395 | { |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 2396 | struct mv643xx_eth_private *mp = netdev_priv(dev); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2397 | int err; |
Lennert Buytenhek | 64da80a | 2008-06-02 01:01:26 +0200 | [diff] [blame] | 2398 | int i; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2399 | |
Lennert Buytenhek | 37a6084 | 2008-11-20 03:57:36 -0800 | [diff] [blame] | 2400 | wrlp(mp, INT_CAUSE, 0); |
| 2401 | wrlp(mp, INT_CAUSE_EXT, 0); |
| 2402 | rdlp(mp, INT_CAUSE_EXT); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2403 | |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 2404 | err = request_irq(dev->irq, mv643xx_eth_irq, |
Lennert Buytenhek | 2a1867a | 2008-08-23 23:43:38 +0200 | [diff] [blame] | 2405 | IRQF_SHARED, dev->name, dev); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2406 | if (err) { |
Joe Perches | 7542db8 | 2011-03-02 17:50:35 +0000 | [diff] [blame] | 2407 | netdev_err(dev, "can't assign irq\n"); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2408 | return -EAGAIN; |
| 2409 | } |
| 2410 | |
Lennert Buytenhek | 2bcb4b0 | 2008-10-01 02:33:57 -0700 | [diff] [blame] | 2411 | mv643xx_eth_recalc_skb_size(mp); |
| 2412 | |
Lennert Buytenhek | 2257e05 | 2008-08-24 04:33:36 +0200 | [diff] [blame] | 2413 | napi_enable(&mp->napi); |
| 2414 | |
Saeed Bishara | e0ca841 | 2009-05-06 03:02:01 +0000 | [diff] [blame] | 2415 | mp->int_mask = INT_EXT; |
| 2416 | |
Lennert Buytenhek | f7981c1 | 2008-08-26 10:23:22 +0200 | [diff] [blame] | 2417 | for (i = 0; i < mp->rxq_count; i++) { |
Lennert Buytenhek | 64da80a | 2008-06-02 01:01:26 +0200 | [diff] [blame] | 2418 | err = rxq_init(mp, i); |
| 2419 | if (err) { |
| 2420 | while (--i >= 0) |
Lennert Buytenhek | f7981c1 | 2008-08-26 10:23:22 +0200 | [diff] [blame] | 2421 | rxq_deinit(mp->rxq + i); |
Lennert Buytenhek | 64da80a | 2008-06-02 01:01:26 +0200 | [diff] [blame] | 2422 | goto out; |
| 2423 | } |
| 2424 | |
Lennert Buytenhek | 1fa38c5 | 2008-08-28 08:09:10 +0200 | [diff] [blame] | 2425 | rxq_refill(mp->rxq + i, INT_MAX); |
Saeed Bishara | e0ca841 | 2009-05-06 03:02:01 +0000 | [diff] [blame] | 2426 | mp->int_mask |= INT_RX_0 << i; |
Lennert Buytenhek | 2257e05 | 2008-08-24 04:33:36 +0200 | [diff] [blame] | 2427 | } |
| 2428 | |
Lennert Buytenhek | 1319eba | 2009-04-29 11:57:34 +0000 | [diff] [blame] | 2429 | if (mp->oom) { |
Lennert Buytenhek | 2257e05 | 2008-08-24 04:33:36 +0200 | [diff] [blame] | 2430 | mp->rx_oom.expires = jiffies + (HZ / 10); |
| 2431 | add_timer(&mp->rx_oom); |
Lennert Buytenhek | 64da80a | 2008-06-02 01:01:26 +0200 | [diff] [blame] | 2432 | } |
Lennert Buytenhek | 8a57811 | 2008-06-01 18:09:35 +0200 | [diff] [blame] | 2433 | |
Lennert Buytenhek | f7981c1 | 2008-08-26 10:23:22 +0200 | [diff] [blame] | 2434 | for (i = 0; i < mp->txq_count; i++) { |
Lennert Buytenhek | 3d6b35b | 2008-06-02 01:28:22 +0200 | [diff] [blame] | 2435 | err = txq_init(mp, i); |
| 2436 | if (err) { |
| 2437 | while (--i >= 0) |
Lennert Buytenhek | f7981c1 | 2008-08-26 10:23:22 +0200 | [diff] [blame] | 2438 | txq_deinit(mp->txq + i); |
Lennert Buytenhek | 3d6b35b | 2008-06-02 01:28:22 +0200 | [diff] [blame] | 2439 | goto out_free; |
| 2440 | } |
Saeed Bishara | e0ca841 | 2009-05-06 03:02:01 +0000 | [diff] [blame] | 2441 | mp->int_mask |= INT_TX_END_0 << i; |
Lennert Buytenhek | 3d6b35b | 2008-06-02 01:28:22 +0200 | [diff] [blame] | 2442 | } |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2443 | |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 2444 | port_start(mp); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2445 | |
Lennert Buytenhek | 37a6084 | 2008-11-20 03:57:36 -0800 | [diff] [blame] | 2446 | wrlp(mp, INT_MASK_EXT, INT_EXT_LINK_PHY | INT_EXT_TX); |
Saeed Bishara | e0ca841 | 2009-05-06 03:02:01 +0000 | [diff] [blame] | 2447 | wrlp(mp, INT_MASK, mp->int_mask); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2448 | |
| 2449 | return 0; |
| 2450 | |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 2451 | |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 2452 | out_free: |
Lennert Buytenhek | f7981c1 | 2008-08-26 10:23:22 +0200 | [diff] [blame] | 2453 | for (i = 0; i < mp->rxq_count; i++) |
| 2454 | rxq_deinit(mp->rxq + i); |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 2455 | out: |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2456 | free_irq(dev->irq, dev); |
| 2457 | |
| 2458 | return err; |
| 2459 | } |
| 2460 | |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 2461 | static void port_reset(struct mv643xx_eth_private *mp) |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2462 | { |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 2463 | unsigned int data; |
Lennert Buytenhek | 64da80a | 2008-06-02 01:01:26 +0200 | [diff] [blame] | 2464 | int i; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2465 | |
Lennert Buytenhek | f7981c1 | 2008-08-26 10:23:22 +0200 | [diff] [blame] | 2466 | for (i = 0; i < mp->rxq_count; i++) |
| 2467 | rxq_disable(mp->rxq + i); |
| 2468 | for (i = 0; i < mp->txq_count; i++) |
| 2469 | txq_disable(mp->txq + i); |
Lennert Buytenhek | ae9ae06 | 2008-07-15 02:15:24 +0200 | [diff] [blame] | 2470 | |
| 2471 | while (1) { |
Lennert Buytenhek | 37a6084 | 2008-11-20 03:57:36 -0800 | [diff] [blame] | 2472 | u32 ps = rdlp(mp, PORT_STATUS); |
Lennert Buytenhek | ae9ae06 | 2008-07-15 02:15:24 +0200 | [diff] [blame] | 2473 | |
| 2474 | if ((ps & (TX_IN_PROGRESS | TX_FIFO_EMPTY)) == TX_FIFO_EMPTY) |
| 2475 | break; |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 2476 | udelay(10); |
Lennert Buytenhek | ae9ae06 | 2008-07-15 02:15:24 +0200 | [diff] [blame] | 2477 | } |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2478 | |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2479 | /* Reset the Enable bit in the Configuration Register */ |
Lennert Buytenhek | 37a6084 | 2008-11-20 03:57:36 -0800 | [diff] [blame] | 2480 | data = rdlp(mp, PORT_SERIAL_CONTROL); |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 2481 | data &= ~(SERIAL_PORT_ENABLE | |
| 2482 | DO_NOT_FORCE_LINK_FAIL | |
| 2483 | FORCE_LINK_PASS); |
Lennert Buytenhek | 37a6084 | 2008-11-20 03:57:36 -0800 | [diff] [blame] | 2484 | wrlp(mp, PORT_SERIAL_CONTROL, data); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2485 | } |
| 2486 | |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2487 | static int mv643xx_eth_stop(struct net_device *dev) |
| 2488 | { |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 2489 | struct mv643xx_eth_private *mp = netdev_priv(dev); |
Lennert Buytenhek | 64da80a | 2008-06-02 01:01:26 +0200 | [diff] [blame] | 2490 | int i; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2491 | |
Gabriel Paubert | fe65e70 | 2009-01-19 17:18:09 -0800 | [diff] [blame] | 2492 | wrlp(mp, INT_MASK_EXT, 0x00000000); |
Lennert Buytenhek | 37a6084 | 2008-11-20 03:57:36 -0800 | [diff] [blame] | 2493 | wrlp(mp, INT_MASK, 0x00000000); |
| 2494 | rdlp(mp, INT_MASK); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2495 | |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2496 | napi_disable(&mp->napi); |
Lennert Buytenhek | 78fff83 | 2008-08-24 01:03:57 +0200 | [diff] [blame] | 2497 | |
Lennert Buytenhek | 2257e05 | 2008-08-24 04:33:36 +0200 | [diff] [blame] | 2498 | del_timer_sync(&mp->rx_oom); |
| 2499 | |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2500 | netif_carrier_off(dev); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2501 | |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 2502 | free_irq(dev->irq, dev); |
| 2503 | |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 2504 | port_reset(mp); |
Lennert Buytenhek | 8fd8921 | 2008-08-28 08:26:28 +0200 | [diff] [blame] | 2505 | mv643xx_eth_get_stats(dev); |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 2506 | mib_counters_update(mp); |
Sebastian Siewior | 57e8f26 | 2009-02-16 11:28:15 +0000 | [diff] [blame] | 2507 | del_timer_sync(&mp->mib_counters_timer); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2508 | |
Lennert Buytenhek | f7981c1 | 2008-08-26 10:23:22 +0200 | [diff] [blame] | 2509 | for (i = 0; i < mp->rxq_count; i++) |
| 2510 | rxq_deinit(mp->rxq + i); |
| 2511 | for (i = 0; i < mp->txq_count; i++) |
| 2512 | txq_deinit(mp->txq + i); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2513 | |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2514 | return 0; |
| 2515 | } |
| 2516 | |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 2517 | static int mv643xx_eth_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2518 | { |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 2519 | struct mv643xx_eth_private *mp = netdev_priv(dev); |
Phil Sutter | 260055b | 2013-03-06 07:49:02 +0000 | [diff] [blame] | 2520 | int ret; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2521 | |
Phil Sutter | 260055b | 2013-03-06 07:49:02 +0000 | [diff] [blame] | 2522 | if (mp->phy == NULL) |
| 2523 | return -ENOTSUPP; |
Lennert Buytenhek | bedfe32 | 2008-06-02 02:13:03 +0200 | [diff] [blame] | 2524 | |
Phil Sutter | 260055b | 2013-03-06 07:49:02 +0000 | [diff] [blame] | 2525 | ret = phy_mii_ioctl(mp->phy, ifr, cmd); |
| 2526 | if (!ret) |
| 2527 | mv643xx_adjust_pscr(mp); |
| 2528 | return ret; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2529 | } |
| 2530 | |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2531 | static int mv643xx_eth_change_mtu(struct net_device *dev, int new_mtu) |
| 2532 | { |
Lennert Buytenhek | 89df5fd | 2008-06-02 00:51:05 +0200 | [diff] [blame] | 2533 | struct mv643xx_eth_private *mp = netdev_priv(dev); |
| 2534 | |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 2535 | if (new_mtu < 64 || new_mtu > 9500) |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2536 | return -EINVAL; |
| 2537 | |
| 2538 | dev->mtu = new_mtu; |
Lennert Buytenhek | 2bcb4b0 | 2008-10-01 02:33:57 -0700 | [diff] [blame] | 2539 | mv643xx_eth_recalc_skb_size(mp); |
Lennert Buytenhek | 89df5fd | 2008-06-02 00:51:05 +0200 | [diff] [blame] | 2540 | tx_set_rate(mp, 1000000000, 16777216); |
| 2541 | |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2542 | if (!netif_running(dev)) |
| 2543 | return 0; |
| 2544 | |
| 2545 | /* |
| 2546 | * Stop and then re-open the interface. This will allocate RX |
| 2547 | * skbs of the new MTU. |
| 2548 | * There is a possible danger that the open will not succeed, |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 2549 | * due to memory being full. |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2550 | */ |
| 2551 | mv643xx_eth_stop(dev); |
| 2552 | if (mv643xx_eth_open(dev)) { |
Joe Perches | 7542db8 | 2011-03-02 17:50:35 +0000 | [diff] [blame] | 2553 | netdev_err(dev, |
| 2554 | "fatal error on re-opening device after MTU change\n"); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2555 | } |
| 2556 | |
| 2557 | return 0; |
| 2558 | } |
| 2559 | |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 2560 | static void tx_timeout_task(struct work_struct *ugly) |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2561 | { |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 2562 | struct mv643xx_eth_private *mp; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2563 | |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 2564 | mp = container_of(ugly, struct mv643xx_eth_private, tx_timeout_task); |
| 2565 | if (netif_running(mp->dev)) { |
Lennert Buytenhek | e5ef1de | 2008-08-28 06:26:23 +0200 | [diff] [blame] | 2566 | netif_tx_stop_all_queues(mp->dev); |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 2567 | port_reset(mp); |
| 2568 | port_start(mp); |
Lennert Buytenhek | e5ef1de | 2008-08-28 06:26:23 +0200 | [diff] [blame] | 2569 | netif_tx_wake_all_queues(mp->dev); |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 2570 | } |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2571 | } |
| 2572 | |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2573 | static void mv643xx_eth_tx_timeout(struct net_device *dev) |
| 2574 | { |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 2575 | struct mv643xx_eth_private *mp = netdev_priv(dev); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2576 | |
Joe Perches | 7542db8 | 2011-03-02 17:50:35 +0000 | [diff] [blame] | 2577 | netdev_info(dev, "tx timeout\n"); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2578 | |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2579 | schedule_work(&mp->tx_timeout_task); |
| 2580 | } |
| 2581 | |
Dale Farnsworth | 63c9e54 | 2005-09-02 13:49:10 -0700 | [diff] [blame] | 2582 | #ifdef CONFIG_NET_POLL_CONTROLLER |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 2583 | static void mv643xx_eth_netpoll(struct net_device *dev) |
Dale Farnsworth | 63c9e54 | 2005-09-02 13:49:10 -0700 | [diff] [blame] | 2584 | { |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 2585 | struct mv643xx_eth_private *mp = netdev_priv(dev); |
Dale Farnsworth | 63c9e54 | 2005-09-02 13:49:10 -0700 | [diff] [blame] | 2586 | |
Lennert Buytenhek | 37a6084 | 2008-11-20 03:57:36 -0800 | [diff] [blame] | 2587 | wrlp(mp, INT_MASK, 0x00000000); |
| 2588 | rdlp(mp, INT_MASK); |
Dale Farnsworth | c2e5b35 | 2006-01-16 17:00:24 -0700 | [diff] [blame] | 2589 | |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 2590 | mv643xx_eth_irq(dev->irq, dev); |
Dale Farnsworth | c2e5b35 | 2006-01-16 17:00:24 -0700 | [diff] [blame] | 2591 | |
Saeed Bishara | e0ca841 | 2009-05-06 03:02:01 +0000 | [diff] [blame] | 2592 | wrlp(mp, INT_MASK, mp->int_mask); |
Dale Farnsworth | 63c9e54 | 2005-09-02 13:49:10 -0700 | [diff] [blame] | 2593 | } |
| 2594 | #endif |
| 2595 | |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2596 | |
| 2597 | /* platform glue ************************************************************/ |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 2598 | static void |
| 2599 | mv643xx_eth_conf_mbus_windows(struct mv643xx_eth_shared_private *msp, |
Andrew Lunn | 63a9332 | 2011-12-07 21:48:07 +0100 | [diff] [blame] | 2600 | const struct mbus_dram_target_info *dram) |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2601 | { |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 2602 | void __iomem *base = msp->base; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2603 | u32 win_enable; |
| 2604 | u32 win_protect; |
| 2605 | int i; |
| 2606 | |
| 2607 | for (i = 0; i < 6; i++) { |
| 2608 | writel(0, base + WINDOW_BASE(i)); |
| 2609 | writel(0, base + WINDOW_SIZE(i)); |
| 2610 | if (i < 4) |
| 2611 | writel(0, base + WINDOW_REMAP_HIGH(i)); |
| 2612 | } |
| 2613 | |
| 2614 | win_enable = 0x3f; |
| 2615 | win_protect = 0; |
| 2616 | |
| 2617 | for (i = 0; i < dram->num_cs; i++) { |
Andrew Lunn | 63a9332 | 2011-12-07 21:48:07 +0100 | [diff] [blame] | 2618 | const struct mbus_dram_window *cs = dram->cs + i; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2619 | |
| 2620 | writel((cs->base & 0xffff0000) | |
| 2621 | (cs->mbus_attr << 8) | |
| 2622 | dram->mbus_dram_target_id, base + WINDOW_BASE(i)); |
| 2623 | writel((cs->size - 1) & 0xffff0000, base + WINDOW_SIZE(i)); |
| 2624 | |
| 2625 | win_enable &= ~(1 << i); |
| 2626 | win_protect |= 3 << (2 * i); |
| 2627 | } |
| 2628 | |
| 2629 | writel(win_enable, base + WINDOW_BAR_ENABLE); |
| 2630 | msp->win_protect = win_protect; |
| 2631 | } |
| 2632 | |
Lennert Buytenhek | 773fc3e | 2008-06-02 01:54:16 +0200 | [diff] [blame] | 2633 | static void infer_hw_params(struct mv643xx_eth_shared_private *msp) |
| 2634 | { |
| 2635 | /* |
| 2636 | * Check whether we have a 14-bit coal limit field in bits |
| 2637 | * [21:8], or a 16-bit coal limit in bits [25,21:7] of the |
| 2638 | * SDMA config register. |
| 2639 | */ |
Lennert Buytenhek | 37a6084 | 2008-11-20 03:57:36 -0800 | [diff] [blame] | 2640 | writel(0x02000000, msp->base + 0x0400 + SDMA_CONFIG); |
| 2641 | if (readl(msp->base + 0x0400 + SDMA_CONFIG) & 0x02000000) |
Lennert Buytenhek | 773fc3e | 2008-06-02 01:54:16 +0200 | [diff] [blame] | 2642 | msp->extended_rx_coal_limit = 1; |
| 2643 | else |
| 2644 | msp->extended_rx_coal_limit = 0; |
Lennert Buytenhek | 1e88159 | 2008-06-02 01:57:36 +0200 | [diff] [blame] | 2645 | |
| 2646 | /* |
Lennert Buytenhek | 457b1d5 | 2008-09-04 12:22:34 +0200 | [diff] [blame] | 2647 | * Check whether the MAC supports TX rate control, and if |
| 2648 | * yes, whether its associated registers are in the old or |
| 2649 | * the new place. |
Lennert Buytenhek | 1e88159 | 2008-06-02 01:57:36 +0200 | [diff] [blame] | 2650 | */ |
Lennert Buytenhek | 37a6084 | 2008-11-20 03:57:36 -0800 | [diff] [blame] | 2651 | writel(1, msp->base + 0x0400 + TX_BW_MTU_MOVED); |
| 2652 | if (readl(msp->base + 0x0400 + TX_BW_MTU_MOVED) & 1) { |
Lennert Buytenhek | 457b1d5 | 2008-09-04 12:22:34 +0200 | [diff] [blame] | 2653 | msp->tx_bw_control = TX_BW_CONTROL_NEW_LAYOUT; |
| 2654 | } else { |
Lennert Buytenhek | 37a6084 | 2008-11-20 03:57:36 -0800 | [diff] [blame] | 2655 | writel(7, msp->base + 0x0400 + TX_BW_RATE); |
| 2656 | if (readl(msp->base + 0x0400 + TX_BW_RATE) & 7) |
Lennert Buytenhek | 457b1d5 | 2008-09-04 12:22:34 +0200 | [diff] [blame] | 2657 | msp->tx_bw_control = TX_BW_CONTROL_OLD_LAYOUT; |
| 2658 | else |
| 2659 | msp->tx_bw_control = TX_BW_CONTROL_ABSENT; |
| 2660 | } |
Lennert Buytenhek | 773fc3e | 2008-06-02 01:54:16 +0200 | [diff] [blame] | 2661 | } |
| 2662 | |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2663 | static int mv643xx_eth_shared_probe(struct platform_device *pdev) |
| 2664 | { |
Lennert Buytenhek | 10a9948 | 2008-11-20 03:57:16 -0800 | [diff] [blame] | 2665 | static int mv643xx_eth_version_printed; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2666 | struct mv643xx_eth_shared_platform_data *pd = pdev->dev.platform_data; |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 2667 | struct mv643xx_eth_shared_private *msp; |
Andrew Lunn | 63a9332 | 2011-12-07 21:48:07 +0100 | [diff] [blame] | 2668 | const struct mbus_dram_target_info *dram; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2669 | struct resource *res; |
| 2670 | int ret; |
| 2671 | |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 2672 | if (!mv643xx_eth_version_printed++) |
Joe Perches | 7542db8 | 2011-03-02 17:50:35 +0000 | [diff] [blame] | 2673 | pr_notice("MV-643xx 10/100/1000 ethernet driver version %s\n", |
| 2674 | mv643xx_eth_driver_version); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2675 | |
| 2676 | ret = -EINVAL; |
| 2677 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 2678 | if (res == NULL) |
| 2679 | goto out; |
| 2680 | |
| 2681 | ret = -ENOMEM; |
Julia Lawall | beae22e | 2010-05-13 10:00:22 +0000 | [diff] [blame] | 2682 | msp = kzalloc(sizeof(*msp), GFP_KERNEL); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2683 | if (msp == NULL) |
| 2684 | goto out; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2685 | |
Joe Perches | 28f65c11 | 2011-06-09 09:13:32 -0700 | [diff] [blame] | 2686 | msp->base = ioremap(res->start, resource_size(res)); |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 2687 | if (msp->base == NULL) |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2688 | goto out_free; |
| 2689 | |
Lennert Buytenhek | ed94493 | 2008-08-26 13:34:19 +0200 | [diff] [blame] | 2690 | /* |
| 2691 | * Set up and register SMI bus. |
| 2692 | */ |
| 2693 | if (pd == NULL || pd->shared_smi == NULL) { |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 2694 | msp->smi_bus = mdiobus_alloc(); |
| 2695 | if (msp->smi_bus == NULL) |
Lennert Buytenhek | ed94493 | 2008-08-26 13:34:19 +0200 | [diff] [blame] | 2696 | goto out_unmap; |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 2697 | |
| 2698 | msp->smi_bus->priv = msp; |
| 2699 | msp->smi_bus->name = "mv643xx_eth smi"; |
| 2700 | msp->smi_bus->read = smi_bus_read; |
| 2701 | msp->smi_bus->write = smi_bus_write, |
Florian Fainelli | 1232243 | 2012-01-09 23:59:15 +0000 | [diff] [blame] | 2702 | snprintf(msp->smi_bus->id, MII_BUS_ID_SIZE, "%s-%d", |
| 2703 | pdev->name, pdev->id); |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 2704 | msp->smi_bus->parent = &pdev->dev; |
| 2705 | msp->smi_bus->phy_mask = 0xffffffff; |
| 2706 | if (mdiobus_register(msp->smi_bus) < 0) |
| 2707 | goto out_free_mii_bus; |
Lennert Buytenhek | ed94493 | 2008-08-26 13:34:19 +0200 | [diff] [blame] | 2708 | msp->smi = msp; |
| 2709 | } else { |
Lennert Buytenhek | fc0eb9f | 2008-08-26 12:56:56 +0200 | [diff] [blame] | 2710 | msp->smi = platform_get_drvdata(pd->shared_smi); |
Lennert Buytenhek | ed94493 | 2008-08-26 13:34:19 +0200 | [diff] [blame] | 2711 | } |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2712 | |
Lennert Buytenhek | 45c5d3b | 2008-08-26 04:42:59 +0200 | [diff] [blame] | 2713 | msp->err_interrupt = NO_IRQ; |
| 2714 | init_waitqueue_head(&msp->smi_busy_wait); |
| 2715 | |
| 2716 | /* |
| 2717 | * Check whether the error interrupt is hooked up. |
| 2718 | */ |
| 2719 | res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); |
| 2720 | if (res != NULL) { |
| 2721 | int err; |
| 2722 | |
| 2723 | err = request_irq(res->start, mv643xx_eth_err_irq, |
| 2724 | IRQF_SHARED, "mv643xx_eth", msp); |
| 2725 | if (!err) { |
| 2726 | writel(ERR_INT_SMI_DONE, msp->base + ERR_INT_MASK); |
| 2727 | msp->err_interrupt = res->start; |
| 2728 | } |
| 2729 | } |
| 2730 | |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2731 | /* |
| 2732 | * (Re-)program MBUS remapping windows if we are asked to. |
| 2733 | */ |
Andrew Lunn | 63a9332 | 2011-12-07 21:48:07 +0100 | [diff] [blame] | 2734 | dram = mv_mbus_dram_info(); |
| 2735 | if (dram) |
| 2736 | mv643xx_eth_conf_mbus_windows(msp, dram); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2737 | |
Dan Carpenter | 50a749c | 2010-07-23 01:05:05 +0000 | [diff] [blame] | 2738 | msp->tx_csum_limit = (pd != NULL && pd->tx_csum_limit) ? |
| 2739 | pd->tx_csum_limit : 9 * 1024; |
Lennert Buytenhek | 773fc3e | 2008-06-02 01:54:16 +0200 | [diff] [blame] | 2740 | infer_hw_params(msp); |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 2741 | |
| 2742 | platform_set_drvdata(pdev, msp); |
| 2743 | |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2744 | return 0; |
| 2745 | |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 2746 | out_free_mii_bus: |
| 2747 | mdiobus_free(msp->smi_bus); |
Lennert Buytenhek | ed94493 | 2008-08-26 13:34:19 +0200 | [diff] [blame] | 2748 | out_unmap: |
| 2749 | iounmap(msp->base); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2750 | out_free: |
| 2751 | kfree(msp); |
| 2752 | out: |
| 2753 | return ret; |
| 2754 | } |
| 2755 | |
| 2756 | static int mv643xx_eth_shared_remove(struct platform_device *pdev) |
| 2757 | { |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 2758 | struct mv643xx_eth_shared_private *msp = platform_get_drvdata(pdev); |
Lennert Buytenhek | ed94493 | 2008-08-26 13:34:19 +0200 | [diff] [blame] | 2759 | struct mv643xx_eth_shared_platform_data *pd = pdev->dev.platform_data; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2760 | |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 2761 | if (pd == NULL || pd->shared_smi == NULL) { |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 2762 | mdiobus_unregister(msp->smi_bus); |
Lennert Buytenhek | bcb3336 | 2008-11-18 04:28:35 +0000 | [diff] [blame] | 2763 | mdiobus_free(msp->smi_bus); |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 2764 | } |
Lennert Buytenhek | 45c5d3b | 2008-08-26 04:42:59 +0200 | [diff] [blame] | 2765 | if (msp->err_interrupt != NO_IRQ) |
| 2766 | free_irq(msp->err_interrupt, msp); |
Lennert Buytenhek | cc9754b3 | 2008-06-01 02:10:27 +0200 | [diff] [blame] | 2767 | iounmap(msp->base); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2768 | kfree(msp); |
| 2769 | |
| 2770 | return 0; |
| 2771 | } |
| 2772 | |
| 2773 | static struct platform_driver mv643xx_eth_shared_driver = { |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 2774 | .probe = mv643xx_eth_shared_probe, |
| 2775 | .remove = mv643xx_eth_shared_remove, |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2776 | .driver = { |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 2777 | .name = MV643XX_ETH_SHARED_NAME, |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2778 | .owner = THIS_MODULE, |
| 2779 | }, |
| 2780 | }; |
| 2781 | |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 2782 | static void phy_addr_set(struct mv643xx_eth_private *mp, int phy_addr) |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2783 | { |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2784 | int addr_shift = 5 * mp->port_num; |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 2785 | u32 data; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2786 | |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 2787 | data = rdl(mp, PHY_ADDR); |
| 2788 | data &= ~(0x1f << addr_shift); |
| 2789 | data |= (phy_addr & 0x1f) << addr_shift; |
| 2790 | wrl(mp, PHY_ADDR, data); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2791 | } |
| 2792 | |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 2793 | static int phy_addr_get(struct mv643xx_eth_private *mp) |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2794 | { |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 2795 | unsigned int data; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2796 | |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 2797 | data = rdl(mp, PHY_ADDR); |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2798 | |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 2799 | return (data >> (5 * mp->port_num)) & 0x1f; |
| 2800 | } |
| 2801 | |
| 2802 | static void set_params(struct mv643xx_eth_private *mp, |
| 2803 | struct mv643xx_eth_platform_data *pd) |
| 2804 | { |
| 2805 | struct net_device *dev = mp->dev; |
| 2806 | |
| 2807 | if (is_valid_ether_addr(pd->mac_addr)) |
| 2808 | memcpy(dev->dev_addr, pd->mac_addr, 6); |
| 2809 | else |
| 2810 | uc_addr_get(mp, dev->dev_addr); |
| 2811 | |
Lennert Buytenhek | e7d2f4d | 2009-02-12 14:07:37 +0000 | [diff] [blame] | 2812 | mp->rx_ring_size = DEFAULT_RX_QUEUE_SIZE; |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 2813 | if (pd->rx_queue_size) |
Lennert Buytenhek | e7d2f4d | 2009-02-12 14:07:37 +0000 | [diff] [blame] | 2814 | mp->rx_ring_size = pd->rx_queue_size; |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 2815 | mp->rx_desc_sram_addr = pd->rx_sram_addr; |
| 2816 | mp->rx_desc_sram_size = pd->rx_sram_size; |
| 2817 | |
Lennert Buytenhek | f7981c1 | 2008-08-26 10:23:22 +0200 | [diff] [blame] | 2818 | mp->rxq_count = pd->rx_queue_count ? : 1; |
Lennert Buytenhek | 64da80a | 2008-06-02 01:01:26 +0200 | [diff] [blame] | 2819 | |
Lennert Buytenhek | e7d2f4d | 2009-02-12 14:07:37 +0000 | [diff] [blame] | 2820 | mp->tx_ring_size = DEFAULT_TX_QUEUE_SIZE; |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 2821 | if (pd->tx_queue_size) |
Lennert Buytenhek | e7d2f4d | 2009-02-12 14:07:37 +0000 | [diff] [blame] | 2822 | mp->tx_ring_size = pd->tx_queue_size; |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 2823 | mp->tx_desc_sram_addr = pd->tx_sram_addr; |
| 2824 | mp->tx_desc_sram_size = pd->tx_sram_size; |
Lennert Buytenhek | 3d6b35b | 2008-06-02 01:28:22 +0200 | [diff] [blame] | 2825 | |
Lennert Buytenhek | f7981c1 | 2008-08-26 10:23:22 +0200 | [diff] [blame] | 2826 | mp->txq_count = pd->tx_queue_count ? : 1; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2827 | } |
| 2828 | |
Lennert Buytenhek | ed94493 | 2008-08-26 13:34:19 +0200 | [diff] [blame] | 2829 | static struct phy_device *phy_scan(struct mv643xx_eth_private *mp, |
| 2830 | int phy_addr) |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2831 | { |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 2832 | struct mii_bus *bus = mp->shared->smi->smi_bus; |
Lennert Buytenhek | ed94493 | 2008-08-26 13:34:19 +0200 | [diff] [blame] | 2833 | struct phy_device *phydev; |
| 2834 | int start; |
| 2835 | int num; |
| 2836 | int i; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2837 | |
Lennert Buytenhek | ed94493 | 2008-08-26 13:34:19 +0200 | [diff] [blame] | 2838 | if (phy_addr == MV643XX_ETH_PHY_ADDR_DEFAULT) { |
| 2839 | start = phy_addr_get(mp) & 0x1f; |
| 2840 | num = 32; |
| 2841 | } else { |
| 2842 | start = phy_addr & 0x1f; |
| 2843 | num = 1; |
| 2844 | } |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2845 | |
Lennert Buytenhek | ed94493 | 2008-08-26 13:34:19 +0200 | [diff] [blame] | 2846 | phydev = NULL; |
| 2847 | for (i = 0; i < num; i++) { |
| 2848 | int addr = (start + i) & 0x1f; |
Lennert Buytenhek | 45c5d3b | 2008-08-26 04:42:59 +0200 | [diff] [blame] | 2849 | |
Lennert Buytenhek | ed94493 | 2008-08-26 13:34:19 +0200 | [diff] [blame] | 2850 | if (bus->phy_map[addr] == NULL) |
| 2851 | mdiobus_scan(bus, addr); |
Lennert Buytenhek | 45c5d3b | 2008-08-26 04:42:59 +0200 | [diff] [blame] | 2852 | |
Lennert Buytenhek | ed94493 | 2008-08-26 13:34:19 +0200 | [diff] [blame] | 2853 | if (phydev == NULL) { |
| 2854 | phydev = bus->phy_map[addr]; |
| 2855 | if (phydev != NULL) |
| 2856 | phy_addr_set(mp, addr); |
| 2857 | } |
| 2858 | } |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2859 | |
Lennert Buytenhek | ed94493 | 2008-08-26 13:34:19 +0200 | [diff] [blame] | 2860 | return phydev; |
Lennert Buytenhek | c9df406f | 2008-06-01 00:48:39 +0200 | [diff] [blame] | 2861 | } |
| 2862 | |
Lennert Buytenhek | ed94493 | 2008-08-26 13:34:19 +0200 | [diff] [blame] | 2863 | static void phy_init(struct mv643xx_eth_private *mp, int speed, int duplex) |
James Chapman | d0412d9 | 2006-01-27 01:15:30 -0700 | [diff] [blame] | 2864 | { |
Lennert Buytenhek | ed94493 | 2008-08-26 13:34:19 +0200 | [diff] [blame] | 2865 | struct phy_device *phy = mp->phy; |
James Chapman | d0412d9 | 2006-01-27 01:15:30 -0700 | [diff] [blame] | 2866 | |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 2867 | phy_reset(mp); |
| 2868 | |
Florian Fainelli | f9a8f83 | 2013-01-14 00:52:52 +0000 | [diff] [blame] | 2869 | phy_attach(mp->dev, dev_name(&phy->dev), PHY_INTERFACE_MODE_GMII); |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 2870 | |
Lennert Buytenhek | ed94493 | 2008-08-26 13:34:19 +0200 | [diff] [blame] | 2871 | if (speed == 0) { |
| 2872 | phy->autoneg = AUTONEG_ENABLE; |
| 2873 | phy->speed = 0; |
| 2874 | phy->duplex = 0; |
| 2875 | phy->advertising = phy->supported | ADVERTISED_Autoneg; |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 2876 | } else { |
Lennert Buytenhek | ed94493 | 2008-08-26 13:34:19 +0200 | [diff] [blame] | 2877 | phy->autoneg = AUTONEG_DISABLE; |
| 2878 | phy->advertising = 0; |
| 2879 | phy->speed = speed; |
| 2880 | phy->duplex = duplex; |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 2881 | } |
Lennert Buytenhek | ed94493 | 2008-08-26 13:34:19 +0200 | [diff] [blame] | 2882 | phy_start_aneg(phy); |
James Chapman | d0412d9 | 2006-01-27 01:15:30 -0700 | [diff] [blame] | 2883 | } |
| 2884 | |
Lennert Buytenhek | 81600eea9 | 2008-07-14 14:29:40 +0200 | [diff] [blame] | 2885 | static void init_pscr(struct mv643xx_eth_private *mp, int speed, int duplex) |
| 2886 | { |
| 2887 | u32 pscr; |
| 2888 | |
Lennert Buytenhek | 37a6084 | 2008-11-20 03:57:36 -0800 | [diff] [blame] | 2889 | pscr = rdlp(mp, PORT_SERIAL_CONTROL); |
Lennert Buytenhek | 81600eea9 | 2008-07-14 14:29:40 +0200 | [diff] [blame] | 2890 | if (pscr & SERIAL_PORT_ENABLE) { |
| 2891 | pscr &= ~SERIAL_PORT_ENABLE; |
Lennert Buytenhek | 37a6084 | 2008-11-20 03:57:36 -0800 | [diff] [blame] | 2892 | wrlp(mp, PORT_SERIAL_CONTROL, pscr); |
Lennert Buytenhek | 81600eea9 | 2008-07-14 14:29:40 +0200 | [diff] [blame] | 2893 | } |
| 2894 | |
| 2895 | pscr = MAX_RX_PACKET_9700BYTE | SERIAL_PORT_CONTROL_RESERVED; |
Lennert Buytenhek | ed94493 | 2008-08-26 13:34:19 +0200 | [diff] [blame] | 2896 | if (mp->phy == NULL) { |
Lennert Buytenhek | 81600eea9 | 2008-07-14 14:29:40 +0200 | [diff] [blame] | 2897 | pscr |= DISABLE_AUTO_NEG_SPEED_GMII; |
| 2898 | if (speed == SPEED_1000) |
| 2899 | pscr |= SET_GMII_SPEED_TO_1000; |
| 2900 | else if (speed == SPEED_100) |
| 2901 | pscr |= SET_MII_SPEED_TO_100; |
| 2902 | |
| 2903 | pscr |= DISABLE_AUTO_NEG_FOR_FLOW_CTRL; |
| 2904 | |
| 2905 | pscr |= DISABLE_AUTO_NEG_FOR_DUPLEX; |
| 2906 | if (duplex == DUPLEX_FULL) |
| 2907 | pscr |= SET_FULL_DUPLEX_MODE; |
| 2908 | } |
| 2909 | |
Lennert Buytenhek | 37a6084 | 2008-11-20 03:57:36 -0800 | [diff] [blame] | 2910 | wrlp(mp, PORT_SERIAL_CONTROL, pscr); |
Lennert Buytenhek | 81600eea9 | 2008-07-14 14:29:40 +0200 | [diff] [blame] | 2911 | } |
| 2912 | |
Lennert Buytenhek | ea8a864 | 2009-02-24 15:41:40 +0000 | [diff] [blame] | 2913 | static const struct net_device_ops mv643xx_eth_netdev_ops = { |
| 2914 | .ndo_open = mv643xx_eth_open, |
| 2915 | .ndo_stop = mv643xx_eth_stop, |
| 2916 | .ndo_start_xmit = mv643xx_eth_xmit, |
| 2917 | .ndo_set_rx_mode = mv643xx_eth_set_rx_mode, |
| 2918 | .ndo_set_mac_address = mv643xx_eth_set_mac_address, |
kirjanov@gmail.com | 1d4bd94 | 2010-02-16 20:40:11 +0000 | [diff] [blame] | 2919 | .ndo_validate_addr = eth_validate_addr, |
Lennert Buytenhek | ea8a864 | 2009-02-24 15:41:40 +0000 | [diff] [blame] | 2920 | .ndo_do_ioctl = mv643xx_eth_ioctl, |
| 2921 | .ndo_change_mtu = mv643xx_eth_change_mtu, |
Michał Mirosław | aad59c4 | 2011-04-17 00:15:46 +0000 | [diff] [blame] | 2922 | .ndo_set_features = mv643xx_eth_set_features, |
Lennert Buytenhek | ea8a864 | 2009-02-24 15:41:40 +0000 | [diff] [blame] | 2923 | .ndo_tx_timeout = mv643xx_eth_tx_timeout, |
| 2924 | .ndo_get_stats = mv643xx_eth_get_stats, |
| 2925 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 2926 | .ndo_poll_controller = mv643xx_eth_netpoll, |
| 2927 | #endif |
| 2928 | }; |
| 2929 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 2930 | static int mv643xx_eth_probe(struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2931 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2932 | struct mv643xx_eth_platform_data *pd; |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 2933 | struct mv643xx_eth_private *mp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2934 | struct net_device *dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2935 | struct resource *res; |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 2936 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2937 | |
Dale Farnsworth | 84dd619 | 2007-03-03 06:40:28 -0700 | [diff] [blame] | 2938 | pd = pdev->dev.platform_data; |
| 2939 | if (pd == NULL) { |
Joe Perches | 7542db8 | 2011-03-02 17:50:35 +0000 | [diff] [blame] | 2940 | dev_err(&pdev->dev, "no mv643xx_eth_platform_data\n"); |
Dale Farnsworth | 84dd619 | 2007-03-03 06:40:28 -0700 | [diff] [blame] | 2941 | return -ENODEV; |
| 2942 | } |
| 2943 | |
Lennert Buytenhek | fa3959f | 2008-04-24 01:27:02 +0200 | [diff] [blame] | 2944 | if (pd->shared == NULL) { |
Joe Perches | 7542db8 | 2011-03-02 17:50:35 +0000 | [diff] [blame] | 2945 | dev_err(&pdev->dev, "no mv643xx_eth_platform_data->shared\n"); |
Lennert Buytenhek | fa3959f | 2008-04-24 01:27:02 +0200 | [diff] [blame] | 2946 | return -ENODEV; |
| 2947 | } |
| 2948 | |
Lennert Buytenhek | e5ef1de | 2008-08-28 06:26:23 +0200 | [diff] [blame] | 2949 | dev = alloc_etherdev_mq(sizeof(struct mv643xx_eth_private), 8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2950 | if (!dev) |
| 2951 | return -ENOMEM; |
| 2952 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2953 | mp = netdev_priv(dev); |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 2954 | platform_set_drvdata(pdev, mp); |
| 2955 | |
| 2956 | mp->shared = platform_get_drvdata(pd->shared); |
Lennert Buytenhek | 37a6084 | 2008-11-20 03:57:36 -0800 | [diff] [blame] | 2957 | mp->base = mp->shared->base + 0x0400 + (pd->port_number << 10); |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 2958 | mp->port_num = pd->port_number; |
| 2959 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 2960 | mp->dev = dev; |
Lennert Buytenhek | 78fff83 | 2008-08-24 01:03:57 +0200 | [diff] [blame] | 2961 | |
Andrew Lunn | 452503e | 2011-12-24 01:24:24 +0100 | [diff] [blame] | 2962 | /* |
Andrew Lunn | 9a43a02 | 2012-06-06 06:40:43 +0000 | [diff] [blame] | 2963 | * Start with a default rate, and if there is a clock, allow |
| 2964 | * it to override the default. |
Andrew Lunn | 452503e | 2011-12-24 01:24:24 +0100 | [diff] [blame] | 2965 | */ |
Andrew Lunn | 9a43a02 | 2012-06-06 06:40:43 +0000 | [diff] [blame] | 2966 | mp->t_clk = 133000000; |
| 2967 | #if defined(CONFIG_HAVE_CLK) |
Andrew Lunn | 452503e | 2011-12-24 01:24:24 +0100 | [diff] [blame] | 2968 | mp->clk = clk_get(&pdev->dev, (pdev->id ? "1" : "0")); |
| 2969 | if (!IS_ERR(mp->clk)) { |
| 2970 | clk_prepare_enable(mp->clk); |
| 2971 | mp->t_clk = clk_get_rate(mp->clk); |
Andrew Lunn | 452503e | 2011-12-24 01:24:24 +0100 | [diff] [blame] | 2972 | } |
Andrew Lunn | 9a43a02 | 2012-06-06 06:40:43 +0000 | [diff] [blame] | 2973 | #endif |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 2974 | set_params(mp, pd); |
Ben Hutchings | 206d6b3 | 2010-09-27 08:30:05 +0000 | [diff] [blame] | 2975 | netif_set_real_num_tx_queues(dev, mp->txq_count); |
| 2976 | netif_set_real_num_rx_queues(dev, mp->rxq_count); |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 2977 | |
Lennert Buytenhek | ed94493 | 2008-08-26 13:34:19 +0200 | [diff] [blame] | 2978 | if (pd->phy_addr != MV643XX_ETH_PHY_NONE) |
| 2979 | mp->phy = phy_scan(mp, pd->phy_addr); |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 2980 | |
Lennert Buytenhek | 6bdf576 | 2009-02-12 14:06:46 +0000 | [diff] [blame] | 2981 | if (mp->phy != NULL) |
Lennert Buytenhek | ed94493 | 2008-08-26 13:34:19 +0200 | [diff] [blame] | 2982 | phy_init(mp, pd->speed, pd->duplex); |
Lennert Buytenhek | 6bdf576 | 2009-02-12 14:06:46 +0000 | [diff] [blame] | 2983 | |
| 2984 | SET_ETHTOOL_OPS(dev, &mv643xx_eth_ethtool_ops); |
Lennert Buytenhek | ed94493 | 2008-08-26 13:34:19 +0200 | [diff] [blame] | 2985 | |
Lennert Buytenhek | 81600eea9 | 2008-07-14 14:29:40 +0200 | [diff] [blame] | 2986 | init_pscr(mp, pd->speed, pd->duplex); |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 2987 | |
Lennert Buytenhek | 4ff3495 | 2008-09-19 05:04:57 +0200 | [diff] [blame] | 2988 | |
| 2989 | mib_counters_clear(mp); |
| 2990 | |
| 2991 | init_timer(&mp->mib_counters_timer); |
| 2992 | mp->mib_counters_timer.data = (unsigned long)mp; |
| 2993 | mp->mib_counters_timer.function = mib_counters_timer_wrapper; |
| 2994 | mp->mib_counters_timer.expires = jiffies + 30 * HZ; |
| 2995 | add_timer(&mp->mib_counters_timer); |
| 2996 | |
| 2997 | spin_lock_init(&mp->mib_counters_lock); |
| 2998 | |
| 2999 | INIT_WORK(&mp->tx_timeout_task, tx_timeout_task); |
| 3000 | |
Lennert Buytenhek | 2257e05 | 2008-08-24 04:33:36 +0200 | [diff] [blame] | 3001 | netif_napi_add(dev, &mp->napi, mv643xx_eth_poll, 128); |
| 3002 | |
| 3003 | init_timer(&mp->rx_oom); |
| 3004 | mp->rx_oom.data = (unsigned long)mp; |
| 3005 | mp->rx_oom.function = oom_timer_wrapper; |
| 3006 | |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 3007 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3008 | res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); |
| 3009 | BUG_ON(!res); |
| 3010 | dev->irq = res->start; |
| 3011 | |
Lennert Buytenhek | ea8a864 | 2009-02-24 15:41:40 +0000 | [diff] [blame] | 3012 | dev->netdev_ops = &mv643xx_eth_netdev_ops; |
| 3013 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3014 | dev->watchdog_timeo = 2 * HZ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3015 | dev->base_addr = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3016 | |
Michał Mirosław | aad59c4 | 2011-04-17 00:15:46 +0000 | [diff] [blame] | 3017 | dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | |
| 3018 | NETIF_F_RXCSUM | NETIF_F_LRO; |
| 3019 | dev->features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_RXCSUM; |
Lennert Buytenhek | e32b661 | 2008-07-24 06:22:59 +0200 | [diff] [blame] | 3020 | dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM; |
James Chapman | c28a4f8 | 2006-01-27 01:13:15 -0700 | [diff] [blame] | 3021 | |
Jiri Pirko | 0178934 | 2011-08-16 06:29:00 +0000 | [diff] [blame] | 3022 | dev->priv_flags |= IFF_UNICAST_FLT; |
| 3023 | |
Olaf Hering | b0b8dab | 2006-04-27 18:23:49 -0700 | [diff] [blame] | 3024 | SET_NETDEV_DEV(dev, &pdev->dev); |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 3025 | |
| 3026 | if (mp->shared->win_protect) |
| 3027 | wrl(mp, WINDOW_PROTECT(mp->port_num), mp->shared->win_protect); |
| 3028 | |
Lennert Buytenhek | a5fe361 | 2009-02-24 15:41:47 +0000 | [diff] [blame] | 3029 | netif_carrier_off(dev); |
| 3030 | |
Lennert Buytenhek | b5e86db | 2009-04-08 15:42:46 -0700 | [diff] [blame] | 3031 | wrlp(mp, SDMA_CONFIG, PORT_SDMA_CONFIG_DEFAULT_VALUE); |
| 3032 | |
Lennert Buytenhek | 4fb0a54 | 2009-02-24 15:42:05 +0000 | [diff] [blame] | 3033 | set_rx_coal(mp, 250); |
Lennert Buytenhek | a5fe361 | 2009-02-24 15:41:47 +0000 | [diff] [blame] | 3034 | set_tx_coal(mp, 0); |
| 3035 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3036 | err = register_netdev(dev); |
| 3037 | if (err) |
| 3038 | goto out; |
| 3039 | |
Joe Perches | 7542db8 | 2011-03-02 17:50:35 +0000 | [diff] [blame] | 3040 | netdev_notice(dev, "port %d with MAC address %pM\n", |
| 3041 | mp->port_num, dev->dev_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3042 | |
Lennert Buytenhek | 13d6428 | 2008-06-01 20:51:22 +0200 | [diff] [blame] | 3043 | if (mp->tx_desc_sram_size > 0) |
Joe Perches | 7542db8 | 2011-03-02 17:50:35 +0000 | [diff] [blame] | 3044 | netdev_notice(dev, "configured with sram\n"); |
Nicolas DET | b152987 | 2005-10-28 17:46:30 -0700 | [diff] [blame] | 3045 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3046 | return 0; |
| 3047 | |
| 3048 | out: |
Simon Baatz | baffab2 | 2012-07-19 00:04:09 +0200 | [diff] [blame] | 3049 | #if defined(CONFIG_HAVE_CLK) |
| 3050 | if (!IS_ERR(mp->clk)) { |
| 3051 | clk_disable_unprepare(mp->clk); |
| 3052 | clk_put(mp->clk); |
| 3053 | } |
| 3054 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3055 | free_netdev(dev); |
| 3056 | |
| 3057 | return err; |
| 3058 | } |
| 3059 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 3060 | static int mv643xx_eth_remove(struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3061 | { |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 3062 | struct mv643xx_eth_private *mp = platform_get_drvdata(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3063 | |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 3064 | unregister_netdev(mp->dev); |
Lennert Buytenhek | ed94493 | 2008-08-26 13:34:19 +0200 | [diff] [blame] | 3065 | if (mp->phy != NULL) |
| 3066 | phy_detach(mp->phy); |
Tejun Heo | 23f333a | 2010-12-12 16:45:14 +0100 | [diff] [blame] | 3067 | cancel_work_sync(&mp->tx_timeout_task); |
Andrew Lunn | 452503e | 2011-12-24 01:24:24 +0100 | [diff] [blame] | 3068 | |
Andrew Lunn | 9a43a02 | 2012-06-06 06:40:43 +0000 | [diff] [blame] | 3069 | #if defined(CONFIG_HAVE_CLK) |
Andrew Lunn | 452503e | 2011-12-24 01:24:24 +0100 | [diff] [blame] | 3070 | if (!IS_ERR(mp->clk)) { |
| 3071 | clk_disable_unprepare(mp->clk); |
| 3072 | clk_put(mp->clk); |
| 3073 | } |
Andrew Lunn | 9a43a02 | 2012-06-06 06:40:43 +0000 | [diff] [blame] | 3074 | #endif |
| 3075 | |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 3076 | free_netdev(mp->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3077 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 3078 | platform_set_drvdata(pdev, NULL); |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 3079 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3080 | return 0; |
| 3081 | } |
| 3082 | |
Dale Farnsworth | d57ab6f | 2007-03-20 16:38:04 -0700 | [diff] [blame] | 3083 | static void mv643xx_eth_shutdown(struct platform_device *pdev) |
| 3084 | { |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 3085 | struct mv643xx_eth_private *mp = platform_get_drvdata(pdev); |
Dale Farnsworth | d57ab6f | 2007-03-20 16:38:04 -0700 | [diff] [blame] | 3086 | |
| 3087 | /* Mask all interrupts on ethernet port */ |
Lennert Buytenhek | 37a6084 | 2008-11-20 03:57:36 -0800 | [diff] [blame] | 3088 | wrlp(mp, INT_MASK, 0); |
| 3089 | rdlp(mp, INT_MASK); |
Dale Farnsworth | d57ab6f | 2007-03-20 16:38:04 -0700 | [diff] [blame] | 3090 | |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 3091 | if (netif_running(mp->dev)) |
| 3092 | port_reset(mp); |
Dale Farnsworth | d57ab6f | 2007-03-20 16:38:04 -0700 | [diff] [blame] | 3093 | } |
| 3094 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 3095 | static struct platform_driver mv643xx_eth_driver = { |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 3096 | .probe = mv643xx_eth_probe, |
| 3097 | .remove = mv643xx_eth_remove, |
| 3098 | .shutdown = mv643xx_eth_shutdown, |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 3099 | .driver = { |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 3100 | .name = MV643XX_ETH_NAME, |
Kay Sievers | 72abb46 | 2008-04-18 13:50:44 -0700 | [diff] [blame] | 3101 | .owner = THIS_MODULE, |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 3102 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3103 | }; |
| 3104 | |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 3105 | static int __init mv643xx_eth_init_module(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3106 | { |
| 3107 | int rc; |
| 3108 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 3109 | rc = platform_driver_register(&mv643xx_eth_shared_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3110 | if (!rc) { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 3111 | rc = platform_driver_register(&mv643xx_eth_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3112 | if (rc) |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 3113 | platform_driver_unregister(&mv643xx_eth_shared_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3114 | } |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 3115 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3116 | return rc; |
| 3117 | } |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 3118 | module_init(mv643xx_eth_init_module); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3119 | |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 3120 | static void __exit mv643xx_eth_cleanup_module(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3121 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 3122 | platform_driver_unregister(&mv643xx_eth_driver); |
| 3123 | platform_driver_unregister(&mv643xx_eth_shared_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3124 | } |
Lennert Buytenhek | e537149 | 2008-06-01 02:18:13 +0200 | [diff] [blame] | 3125 | module_exit(mv643xx_eth_cleanup_module); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3126 | |
Lennert Buytenhek | 45675bc | 2008-06-02 02:02:30 +0200 | [diff] [blame] | 3127 | MODULE_AUTHOR("Rabeeh Khoury, Assaf Hoffman, Matthew Dharm, " |
| 3128 | "Manish Lachwani, Dale Farnsworth and Lennert Buytenhek"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3129 | MODULE_DESCRIPTION("Ethernet driver for Marvell MV643XX"); |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 3130 | MODULE_LICENSE("GPL"); |
Kay Sievers | 72abb46 | 2008-04-18 13:50:44 -0700 | [diff] [blame] | 3131 | MODULE_ALIAS("platform:" MV643XX_ETH_SHARED_NAME); |
Lennert Buytenhek | fc32b0e | 2008-06-02 00:28:40 +0200 | [diff] [blame] | 3132 | MODULE_ALIAS("platform:" MV643XX_ETH_NAME); |