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