aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/pch_gbe
diff options
context:
space:
mode:
authorJonathan Herman <hermanjl@cs.unc.edu>2013-01-22 10:38:37 -0500
committerJonathan Herman <hermanjl@cs.unc.edu>2013-01-22 10:38:37 -0500
commitfcc9d2e5a6c89d22b8b773a64fb4ad21ac318446 (patch)
treea57612d1888735a2ec7972891b68c1ac5ec8faea /drivers/net/pch_gbe
parent8dea78da5cee153b8af9c07a2745f6c55057fe12 (diff)
Added missing tegra files.HEADmaster
Diffstat (limited to 'drivers/net/pch_gbe')
-rw-r--r--drivers/net/pch_gbe/Makefile4
-rw-r--r--drivers/net/pch_gbe/pch_gbe.h663
-rw-r--r--drivers/net/pch_gbe/pch_gbe_api.c245
-rw-r--r--drivers/net/pch_gbe/pch_gbe_api.h36
-rw-r--r--drivers/net/pch_gbe/pch_gbe_ethtool.c517
-rw-r--r--drivers/net/pch_gbe/pch_gbe_main.c2605
-rw-r--r--drivers/net/pch_gbe/pch_gbe_param.c503
-rw-r--r--drivers/net/pch_gbe/pch_gbe_phy.c274
-rw-r--r--drivers/net/pch_gbe/pch_gbe_phy.h37
9 files changed, 4884 insertions, 0 deletions
diff --git a/drivers/net/pch_gbe/Makefile b/drivers/net/pch_gbe/Makefile
new file mode 100644
index 00000000000..31288d4ad24
--- /dev/null
+++ b/drivers/net/pch_gbe/Makefile
@@ -0,0 +1,4 @@
1obj-$(CONFIG_PCH_GBE) += pch_gbe.o
2
3pch_gbe-y := pch_gbe_phy.o pch_gbe_ethtool.o pch_gbe_param.o
4pch_gbe-y += pch_gbe_api.o pch_gbe_main.o
diff --git a/drivers/net/pch_gbe/pch_gbe.h b/drivers/net/pch_gbe/pch_gbe.h
new file mode 100644
index 00000000000..a09a07197eb
--- /dev/null
+++ b/drivers/net/pch_gbe/pch_gbe.h
@@ -0,0 +1,663 @@
1/*
2 * Copyright (C) 1999 - 2010 Intel Corporation.
3 * Copyright (C) 2010 OKI SEMICONDUCTOR Co., LTD.
4 *
5 * This code was derived from the Intel e1000e Linux driver.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
19 */
20
21#ifndef _PCH_GBE_H_
22#define _PCH_GBE_H_
23
24#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
25
26#include <linux/mii.h>
27#include <linux/delay.h>
28#include <linux/pci.h>
29#include <linux/netdevice.h>
30#include <linux/etherdevice.h>
31#include <linux/ethtool.h>
32#include <linux/vmalloc.h>
33#include <net/ip.h>
34#include <net/tcp.h>
35#include <net/udp.h>
36
37/**
38 * pch_gbe_regs_mac_adr - Structure holding values of mac address registers
39 * @high Denotes the 1st to 4th byte from the initial of MAC address
40 * @low Denotes the 5th to 6th byte from the initial of MAC address
41 */
42struct pch_gbe_regs_mac_adr {
43 u32 high;
44 u32 low;
45};
46/**
47 * pch_udc_regs - Structure holding values of MAC registers
48 */
49struct pch_gbe_regs {
50 u32 INT_ST;
51 u32 INT_EN;
52 u32 MODE;
53 u32 RESET;
54 u32 TCPIP_ACC;
55 u32 EX_LIST;
56 u32 INT_ST_HOLD;
57 u32 PHY_INT_CTRL;
58 u32 MAC_RX_EN;
59 u32 RX_FCTRL;
60 u32 PAUSE_REQ;
61 u32 RX_MODE;
62 u32 TX_MODE;
63 u32 RX_FIFO_ST;
64 u32 TX_FIFO_ST;
65 u32 TX_FID;
66 u32 TX_RESULT;
67 u32 PAUSE_PKT1;
68 u32 PAUSE_PKT2;
69 u32 PAUSE_PKT3;
70 u32 PAUSE_PKT4;
71 u32 PAUSE_PKT5;
72 u32 reserve[2];
73 struct pch_gbe_regs_mac_adr mac_adr[16];
74 u32 ADDR_MASK;
75 u32 MIIM;
76 u32 MAC_ADDR_LOAD;
77 u32 RGMII_ST;
78 u32 RGMII_CTRL;
79 u32 reserve3[3];
80 u32 DMA_CTRL;
81 u32 reserve4[3];
82 u32 RX_DSC_BASE;
83 u32 RX_DSC_SIZE;
84 u32 RX_DSC_HW_P;
85 u32 RX_DSC_HW_P_HLD;
86 u32 RX_DSC_SW_P;
87 u32 reserve5[3];
88 u32 TX_DSC_BASE;
89 u32 TX_DSC_SIZE;
90 u32 TX_DSC_HW_P;
91 u32 TX_DSC_HW_P_HLD;
92 u32 TX_DSC_SW_P;
93 u32 reserve6[3];
94 u32 RX_DMA_ST;
95 u32 TX_DMA_ST;
96 u32 reserve7[2];
97 u32 WOL_ST;
98 u32 WOL_CTRL;
99 u32 WOL_ADDR_MASK;
100};
101
102/* Interrupt Status */
103/* Interrupt Status Hold */
104/* Interrupt Enable */
105#define PCH_GBE_INT_RX_DMA_CMPLT 0x00000001 /* Receive DMA Transfer Complete */
106#define PCH_GBE_INT_RX_VALID 0x00000002 /* MAC Normal Receive Complete */
107#define PCH_GBE_INT_RX_FRAME_ERR 0x00000004 /* Receive frame error */
108#define PCH_GBE_INT_RX_FIFO_ERR 0x00000008 /* Receive FIFO Overflow */
109#define PCH_GBE_INT_RX_DMA_ERR 0x00000010 /* Receive DMA Transfer Error */
110#define PCH_GBE_INT_RX_DSC_EMP 0x00000020 /* Receive Descriptor Empty */
111#define PCH_GBE_INT_TX_CMPLT 0x00000100 /* MAC Transmission Complete */
112#define PCH_GBE_INT_TX_DMA_CMPLT 0x00000200 /* DMA Transfer Complete */
113#define PCH_GBE_INT_TX_FIFO_ERR 0x00000400 /* Transmission FIFO underflow. */
114#define PCH_GBE_INT_TX_DMA_ERR 0x00000800 /* Transmission DMA Error */
115#define PCH_GBE_INT_PAUSE_CMPLT 0x00001000 /* Pause Transmission complete */
116#define PCH_GBE_INT_MIIM_CMPLT 0x00010000 /* MIIM I/F Read completion */
117#define PCH_GBE_INT_PHY_INT 0x00100000 /* Interruption from PHY */
118#define PCH_GBE_INT_WOL_DET 0x01000000 /* Wake On LAN Event detection. */
119#define PCH_GBE_INT_TCPIP_ERR 0x10000000 /* TCP/IP Accelerator Error */
120
121/* Mode */
122#define PCH_GBE_MODE_MII_ETHER 0x00000000 /* GIGA Ethernet Mode [MII] */
123#define PCH_GBE_MODE_GMII_ETHER 0x80000000 /* GIGA Ethernet Mode [GMII] */
124#define PCH_GBE_MODE_HALF_DUPLEX 0x00000000 /* Duplex Mode [half duplex] */
125#define PCH_GBE_MODE_FULL_DUPLEX 0x40000000 /* Duplex Mode [full duplex] */
126#define PCH_GBE_MODE_FR_BST 0x04000000 /* Frame bursting is done */
127
128/* Reset */
129#define PCH_GBE_ALL_RST 0x80000000 /* All reset */
130#define PCH_GBE_TX_RST 0x00008000 /* TX MAC, TX FIFO, TX DMA reset */
131#define PCH_GBE_RX_RST 0x00004000 /* RX MAC, RX FIFO, RX DMA reset */
132
133/* TCP/IP Accelerator Control */
134#define PCH_GBE_EX_LIST_EN 0x00000008 /* External List Enable */
135#define PCH_GBE_RX_TCPIPACC_OFF 0x00000004 /* RX TCP/IP ACC Disabled */
136#define PCH_GBE_TX_TCPIPACC_EN 0x00000002 /* TX TCP/IP ACC Enable */
137#define PCH_GBE_RX_TCPIPACC_EN 0x00000001 /* RX TCP/IP ACC Enable */
138
139/* MAC RX Enable */
140#define PCH_GBE_MRE_MAC_RX_EN 0x00000001 /* MAC Receive Enable */
141
142/* RX Flow Control */
143#define PCH_GBE_FL_CTRL_EN 0x80000000 /* Pause packet is enabled */
144
145/* Pause Packet Request */
146#define PCH_GBE_PS_PKT_RQ 0x80000000 /* Pause packet Request */
147
148/* RX Mode */
149#define PCH_GBE_ADD_FIL_EN 0x80000000 /* Address Filtering Enable */
150/* Multicast Filtering Enable */
151#define PCH_GBE_MLT_FIL_EN 0x40000000
152/* Receive Almost Empty Threshold */
153#define PCH_GBE_RH_ALM_EMP_4 0x00000000 /* 4 words */
154#define PCH_GBE_RH_ALM_EMP_8 0x00004000 /* 8 words */
155#define PCH_GBE_RH_ALM_EMP_16 0x00008000 /* 16 words */
156#define PCH_GBE_RH_ALM_EMP_32 0x0000C000 /* 32 words */
157/* Receive Almost Full Threshold */
158#define PCH_GBE_RH_ALM_FULL_4 0x00000000 /* 4 words */
159#define PCH_GBE_RH_ALM_FULL_8 0x00001000 /* 8 words */
160#define PCH_GBE_RH_ALM_FULL_16 0x00002000 /* 16 words */
161#define PCH_GBE_RH_ALM_FULL_32 0x00003000 /* 32 words */
162/* RX FIFO Read Triger Threshold */
163#define PCH_GBE_RH_RD_TRG_4 0x00000000 /* 4 words */
164#define PCH_GBE_RH_RD_TRG_8 0x00000200 /* 8 words */
165#define PCH_GBE_RH_RD_TRG_16 0x00000400 /* 16 words */
166#define PCH_GBE_RH_RD_TRG_32 0x00000600 /* 32 words */
167#define PCH_GBE_RH_RD_TRG_64 0x00000800 /* 64 words */
168#define PCH_GBE_RH_RD_TRG_128 0x00000A00 /* 128 words */
169#define PCH_GBE_RH_RD_TRG_256 0x00000C00 /* 256 words */
170#define PCH_GBE_RH_RD_TRG_512 0x00000E00 /* 512 words */
171
172/* Receive Descriptor bit definitions */
173#define PCH_GBE_RXD_ACC_STAT_BCAST 0x00000400
174#define PCH_GBE_RXD_ACC_STAT_MCAST 0x00000200
175#define PCH_GBE_RXD_ACC_STAT_UCAST 0x00000100
176#define PCH_GBE_RXD_ACC_STAT_TCPIPOK 0x000000C0
177#define PCH_GBE_RXD_ACC_STAT_IPOK 0x00000080
178#define PCH_GBE_RXD_ACC_STAT_TCPOK 0x00000040
179#define PCH_GBE_RXD_ACC_STAT_IP6ERR 0x00000020
180#define PCH_GBE_RXD_ACC_STAT_OFLIST 0x00000010
181#define PCH_GBE_RXD_ACC_STAT_TYPEIP 0x00000008
182#define PCH_GBE_RXD_ACC_STAT_MACL 0x00000004
183#define PCH_GBE_RXD_ACC_STAT_PPPOE 0x00000002
184#define PCH_GBE_RXD_ACC_STAT_VTAGT 0x00000001
185#define PCH_GBE_RXD_GMAC_STAT_PAUSE 0x0200
186#define PCH_GBE_RXD_GMAC_STAT_MARBR 0x0100
187#define PCH_GBE_RXD_GMAC_STAT_MARMLT 0x0080
188#define PCH_GBE_RXD_GMAC_STAT_MARIND 0x0040
189#define PCH_GBE_RXD_GMAC_STAT_MARNOTMT 0x0020
190#define PCH_GBE_RXD_GMAC_STAT_TLONG 0x0010
191#define PCH_GBE_RXD_GMAC_STAT_TSHRT 0x0008
192#define PCH_GBE_RXD_GMAC_STAT_NOTOCTAL 0x0004
193#define PCH_GBE_RXD_GMAC_STAT_NBLERR 0x0002
194#define PCH_GBE_RXD_GMAC_STAT_CRCERR 0x0001
195
196/* Transmit Descriptor bit definitions */
197#define PCH_GBE_TXD_CTRL_TCPIP_ACC_OFF 0x0008
198#define PCH_GBE_TXD_CTRL_ITAG 0x0004
199#define PCH_GBE_TXD_CTRL_ICRC 0x0002
200#define PCH_GBE_TXD_CTRL_APAD 0x0001
201#define PCH_GBE_TXD_WORDS_SHIFT 2
202#define PCH_GBE_TXD_GMAC_STAT_CMPLT 0x2000
203#define PCH_GBE_TXD_GMAC_STAT_ABT 0x1000
204#define PCH_GBE_TXD_GMAC_STAT_EXCOL 0x0800
205#define PCH_GBE_TXD_GMAC_STAT_SNGCOL 0x0400
206#define PCH_GBE_TXD_GMAC_STAT_MLTCOL 0x0200
207#define PCH_GBE_TXD_GMAC_STAT_CRSER 0x0100
208#define PCH_GBE_TXD_GMAC_STAT_TLNG 0x0080
209#define PCH_GBE_TXD_GMAC_STAT_TSHRT 0x0040
210#define PCH_GBE_TXD_GMAC_STAT_LTCOL 0x0020
211#define PCH_GBE_TXD_GMAC_STAT_TFUNDFLW 0x0010
212#define PCH_GBE_TXD_GMAC_STAT_RTYCNT_MASK 0x000F
213
214/* TX Mode */
215#define PCH_GBE_TM_NO_RTRY 0x80000000 /* No Retransmission */
216#define PCH_GBE_TM_LONG_PKT 0x40000000 /* Long Packt TX Enable */
217#define PCH_GBE_TM_ST_AND_FD 0x20000000 /* Stare and Forward */
218#define PCH_GBE_TM_SHORT_PKT 0x10000000 /* Short Packet TX Enable */
219#define PCH_GBE_TM_LTCOL_RETX 0x08000000 /* Retransmission at Late Collision */
220/* Frame Start Threshold */
221#define PCH_GBE_TM_TH_TX_STRT_4 0x00000000 /* 4 words */
222#define PCH_GBE_TM_TH_TX_STRT_8 0x00004000 /* 8 words */
223#define PCH_GBE_TM_TH_TX_STRT_16 0x00008000 /* 16 words */
224#define PCH_GBE_TM_TH_TX_STRT_32 0x0000C000 /* 32 words */
225/* Transmit Almost Empty Threshold */
226#define PCH_GBE_TM_TH_ALM_EMP_4 0x00000000 /* 4 words */
227#define PCH_GBE_TM_TH_ALM_EMP_8 0x00000800 /* 8 words */
228#define PCH_GBE_TM_TH_ALM_EMP_16 0x00001000 /* 16 words */
229#define PCH_GBE_TM_TH_ALM_EMP_32 0x00001800 /* 32 words */
230#define PCH_GBE_TM_TH_ALM_EMP_64 0x00002000 /* 64 words */
231#define PCH_GBE_TM_TH_ALM_EMP_128 0x00002800 /* 128 words */
232#define PCH_GBE_TM_TH_ALM_EMP_256 0x00003000 /* 256 words */
233#define PCH_GBE_TM_TH_ALM_EMP_512 0x00003800 /* 512 words */
234/* Transmit Almost Full Threshold */
235#define PCH_GBE_TM_TH_ALM_FULL_4 0x00000000 /* 4 words */
236#define PCH_GBE_TM_TH_ALM_FULL_8 0x00000200 /* 8 words */
237#define PCH_GBE_TM_TH_ALM_FULL_16 0x00000400 /* 16 words */
238#define PCH_GBE_TM_TH_ALM_FULL_32 0x00000600 /* 32 words */
239
240/* RX FIFO Status */
241#define PCH_GBE_RF_ALM_FULL 0x80000000 /* RX FIFO is almost full. */
242#define PCH_GBE_RF_ALM_EMP 0x40000000 /* RX FIFO is almost empty. */
243#define PCH_GBE_RF_RD_TRG 0x20000000 /* Become more than RH_RD_TRG. */
244#define PCH_GBE_RF_STRWD 0x1FFE0000 /* The word count of RX FIFO. */
245#define PCH_GBE_RF_RCVING 0x00010000 /* Stored in RX FIFO. */
246
247/* MAC Address Mask */
248#define PCH_GBE_BUSY 0x80000000
249
250/* MIIM */
251#define PCH_GBE_MIIM_OPER_WRITE 0x04000000
252#define PCH_GBE_MIIM_OPER_READ 0x00000000
253#define PCH_GBE_MIIM_OPER_READY 0x04000000
254#define PCH_GBE_MIIM_PHY_ADDR_SHIFT 21
255#define PCH_GBE_MIIM_REG_ADDR_SHIFT 16
256
257/* RGMII Status */
258#define PCH_GBE_LINK_UP 0x80000008
259#define PCH_GBE_RXC_SPEED_MSK 0x00000006
260#define PCH_GBE_RXC_SPEED_2_5M 0x00000000 /* 2.5MHz */
261#define PCH_GBE_RXC_SPEED_25M 0x00000002 /* 25MHz */
262#define PCH_GBE_RXC_SPEED_125M 0x00000004 /* 100MHz */
263#define PCH_GBE_DUPLEX_FULL 0x00000001
264
265/* RGMII Control */
266#define PCH_GBE_CRS_SEL 0x00000010
267#define PCH_GBE_RGMII_RATE_125M 0x00000000
268#define PCH_GBE_RGMII_RATE_25M 0x00000008
269#define PCH_GBE_RGMII_RATE_2_5M 0x0000000C
270#define PCH_GBE_RGMII_MODE_GMII 0x00000000
271#define PCH_GBE_RGMII_MODE_RGMII 0x00000002
272#define PCH_GBE_CHIP_TYPE_EXTERNAL 0x00000000
273#define PCH_GBE_CHIP_TYPE_INTERNAL 0x00000001
274
275/* DMA Control */
276#define PCH_GBE_RX_DMA_EN 0x00000002 /* Enables Receive DMA */
277#define PCH_GBE_TX_DMA_EN 0x00000001 /* Enables Transmission DMA */
278
279/* RX DMA STATUS */
280#define PCH_GBE_IDLE_CHECK 0xFFFFFFFE
281
282/* Wake On LAN Status */
283#define PCH_GBE_WLS_BR 0x00000008 /* Broadcas Address */
284#define PCH_GBE_WLS_MLT 0x00000004 /* Multicast Address */
285
286/* The Frame registered in Address Recognizer */
287#define PCH_GBE_WLS_IND 0x00000002
288#define PCH_GBE_WLS_MP 0x00000001 /* Magic packet Address */
289
290/* Wake On LAN Control */
291#define PCH_GBE_WLC_WOL_MODE 0x00010000
292#define PCH_GBE_WLC_IGN_TLONG 0x00000100
293#define PCH_GBE_WLC_IGN_TSHRT 0x00000080
294#define PCH_GBE_WLC_IGN_OCTER 0x00000040
295#define PCH_GBE_WLC_IGN_NBLER 0x00000020
296#define PCH_GBE_WLC_IGN_CRCER 0x00000010
297#define PCH_GBE_WLC_BR 0x00000008
298#define PCH_GBE_WLC_MLT 0x00000004
299#define PCH_GBE_WLC_IND 0x00000002
300#define PCH_GBE_WLC_MP 0x00000001
301
302/* Wake On LAN Address Mask */
303#define PCH_GBE_WLA_BUSY 0x80000000
304
305
306
307/* TX/RX descriptor defines */
308#define PCH_GBE_MAX_TXD 4096
309#define PCH_GBE_DEFAULT_TXD 256
310#define PCH_GBE_MIN_TXD 8
311#define PCH_GBE_MAX_RXD 4096
312#define PCH_GBE_DEFAULT_RXD 256
313#define PCH_GBE_MIN_RXD 8
314
315/* Number of Transmit and Receive Descriptors must be a multiple of 8 */
316#define PCH_GBE_TX_DESC_MULTIPLE 8
317#define PCH_GBE_RX_DESC_MULTIPLE 8
318
319/* Read/Write operation is done through MII Management IF */
320#define PCH_GBE_HAL_MIIM_READ ((u32)0x00000000)
321#define PCH_GBE_HAL_MIIM_WRITE ((u32)0x04000000)
322
323/* flow control values */
324#define PCH_GBE_FC_NONE 0
325#define PCH_GBE_FC_RX_PAUSE 1
326#define PCH_GBE_FC_TX_PAUSE 2
327#define PCH_GBE_FC_FULL 3
328#define PCH_GBE_FC_DEFAULT PCH_GBE_FC_FULL
329
330
331struct pch_gbe_hw;
332/**
333 * struct pch_gbe_functions - HAL APi function pointer
334 * @get_bus_info: for pch_gbe_hal_get_bus_info
335 * @init_hw: for pch_gbe_hal_init_hw
336 * @read_phy_reg: for pch_gbe_hal_read_phy_reg
337 * @write_phy_reg: for pch_gbe_hal_write_phy_reg
338 * @reset_phy: for pch_gbe_hal_phy_hw_reset
339 * @sw_reset_phy: for pch_gbe_hal_phy_sw_reset
340 * @power_up_phy: for pch_gbe_hal_power_up_phy
341 * @power_down_phy: for pch_gbe_hal_power_down_phy
342 * @read_mac_addr: for pch_gbe_hal_read_mac_addr
343 */
344struct pch_gbe_functions {
345 void (*get_bus_info) (struct pch_gbe_hw *);
346 s32 (*init_hw) (struct pch_gbe_hw *);
347 s32 (*read_phy_reg) (struct pch_gbe_hw *, u32, u16 *);
348 s32 (*write_phy_reg) (struct pch_gbe_hw *, u32, u16);
349 void (*reset_phy) (struct pch_gbe_hw *);
350 void (*sw_reset_phy) (struct pch_gbe_hw *);
351 void (*power_up_phy) (struct pch_gbe_hw *hw);
352 void (*power_down_phy) (struct pch_gbe_hw *hw);
353 s32 (*read_mac_addr) (struct pch_gbe_hw *);
354};
355
356/**
357 * struct pch_gbe_mac_info - MAC information
358 * @addr[6]: Store the MAC address
359 * @fc: Mode of flow control
360 * @fc_autoneg: Auto negotiation enable for flow control setting
361 * @tx_fc_enable: Enable flag of Transmit flow control
362 * @max_frame_size: Max transmit frame size
363 * @min_frame_size: Min transmit frame size
364 * @autoneg: Auto negotiation enable
365 * @link_speed: Link speed
366 * @link_duplex: Link duplex
367 */
368struct pch_gbe_mac_info {
369 u8 addr[6];
370 u8 fc;
371 u8 fc_autoneg;
372 u8 tx_fc_enable;
373 u32 max_frame_size;
374 u32 min_frame_size;
375 u8 autoneg;
376 u16 link_speed;
377 u16 link_duplex;
378};
379
380/**
381 * struct pch_gbe_phy_info - PHY information
382 * @addr: PHY address
383 * @id: PHY's identifier
384 * @revision: PHY's revision
385 * @reset_delay_us: HW reset delay time[us]
386 * @autoneg_advertised: Autoneg advertised
387 */
388struct pch_gbe_phy_info {
389 u32 addr;
390 u32 id;
391 u32 revision;
392 u32 reset_delay_us;
393 u16 autoneg_advertised;
394};
395
396/*!
397 * @ingroup Gigabit Ether driver Layer
398 * @struct pch_gbe_bus_info
399 * @brief Bus information
400 */
401struct pch_gbe_bus_info {
402 u8 type;
403 u8 speed;
404 u8 width;
405};
406
407/*!
408 * @ingroup Gigabit Ether driver Layer
409 * @struct pch_gbe_hw
410 * @brief Hardware information
411 */
412struct pch_gbe_hw {
413 void *back;
414
415 struct pch_gbe_regs __iomem *reg;
416 spinlock_t miim_lock;
417
418 const struct pch_gbe_functions *func;
419 struct pch_gbe_mac_info mac;
420 struct pch_gbe_phy_info phy;
421 struct pch_gbe_bus_info bus;
422};
423
424/**
425 * struct pch_gbe_rx_desc - Receive Descriptor
426 * @buffer_addr: RX Frame Buffer Address
427 * @tcp_ip_status: TCP/IP Accelerator Status
428 * @rx_words_eob: RX word count and Byte position
429 * @gbec_status: GMAC Status
430 * @dma_status: DMA Status
431 * @reserved1: Reserved
432 * @reserved2: Reserved
433 */
434struct pch_gbe_rx_desc {
435 u32 buffer_addr;
436 u32 tcp_ip_status;
437 u16 rx_words_eob;
438 u16 gbec_status;
439 u8 dma_status;
440 u8 reserved1;
441 u16 reserved2;
442};
443
444/**
445 * struct pch_gbe_tx_desc - Transmit Descriptor
446 * @buffer_addr: TX Frame Buffer Address
447 * @length: Data buffer length
448 * @reserved1: Reserved
449 * @tx_words_eob: TX word count and Byte position
450 * @tx_frame_ctrl: TX Frame Control
451 * @dma_status: DMA Status
452 * @reserved2: Reserved
453 * @gbec_status: GMAC Status
454 */
455struct pch_gbe_tx_desc {
456 u32 buffer_addr;
457 u16 length;
458 u16 reserved1;
459 u16 tx_words_eob;
460 u16 tx_frame_ctrl;
461 u8 dma_status;
462 u8 reserved2;
463 u16 gbec_status;
464};
465
466
467/**
468 * struct pch_gbe_buffer - Buffer information
469 * @skb: pointer to a socket buffer
470 * @dma: DMA address
471 * @time_stamp: time stamp
472 * @length: data size
473 */
474struct pch_gbe_buffer {
475 struct sk_buff *skb;
476 dma_addr_t dma;
477 unsigned char *rx_buffer;
478 unsigned long time_stamp;
479 u16 length;
480 bool mapped;
481};
482
483/**
484 * struct pch_gbe_tx_ring - tx ring information
485 * @tx_lock: spinlock structs
486 * @desc: pointer to the descriptor ring memory
487 * @dma: physical address of the descriptor ring
488 * @size: length of descriptor ring in bytes
489 * @count: number of descriptors in the ring
490 * @next_to_use: next descriptor to associate a buffer with
491 * @next_to_clean: next descriptor to check for DD status bit
492 * @buffer_info: array of buffer information structs
493 */
494struct pch_gbe_tx_ring {
495 spinlock_t tx_lock;
496 struct pch_gbe_tx_desc *desc;
497 dma_addr_t dma;
498 unsigned int size;
499 unsigned int count;
500 unsigned int next_to_use;
501 unsigned int next_to_clean;
502 struct pch_gbe_buffer *buffer_info;
503};
504
505/**
506 * struct pch_gbe_rx_ring - rx ring information
507 * @desc: pointer to the descriptor ring memory
508 * @dma: physical address of the descriptor ring
509 * @size: length of descriptor ring in bytes
510 * @count: number of descriptors in the ring
511 * @next_to_use: next descriptor to associate a buffer with
512 * @next_to_clean: next descriptor to check for DD status bit
513 * @buffer_info: array of buffer information structs
514 */
515struct pch_gbe_rx_ring {
516 struct pch_gbe_rx_desc *desc;
517 dma_addr_t dma;
518 unsigned char *rx_buff_pool;
519 dma_addr_t rx_buff_pool_logic;
520 unsigned int rx_buff_pool_size;
521 unsigned int size;
522 unsigned int count;
523 unsigned int next_to_use;
524 unsigned int next_to_clean;
525 struct pch_gbe_buffer *buffer_info;
526};
527
528/**
529 * struct pch_gbe_hw_stats - Statistics counters collected by the MAC
530 * @rx_packets: total packets received
531 * @tx_packets: total packets transmitted
532 * @rx_bytes: total bytes received
533 * @tx_bytes: total bytes transmitted
534 * @rx_errors: bad packets received
535 * @tx_errors: packet transmit problems
536 * @rx_dropped: no space in Linux buffers
537 * @tx_dropped: no space available in Linux
538 * @multicast: multicast packets received
539 * @collisions: collisions
540 * @rx_crc_errors: received packet with crc error
541 * @rx_frame_errors: received frame alignment error
542 * @rx_alloc_buff_failed: allocate failure of a receive buffer
543 * @tx_length_errors: transmit length error
544 * @tx_aborted_errors: transmit aborted error
545 * @tx_carrier_errors: transmit carrier error
546 * @tx_timeout_count: Number of transmit timeout
547 * @tx_restart_count: Number of transmit restert
548 * @intr_rx_dsc_empty_count: Interrupt count of receive descriptor empty
549 * @intr_rx_frame_err_count: Interrupt count of receive frame error
550 * @intr_rx_fifo_err_count: Interrupt count of receive FIFO error
551 * @intr_rx_dma_err_count: Interrupt count of receive DMA error
552 * @intr_tx_fifo_err_count: Interrupt count of transmit FIFO error
553 * @intr_tx_dma_err_count: Interrupt count of transmit DMA error
554 * @intr_tcpip_err_count: Interrupt count of TCP/IP Accelerator
555 */
556struct pch_gbe_hw_stats {
557 u32 rx_packets;
558 u32 tx_packets;
559 u32 rx_bytes;
560 u32 tx_bytes;
561 u32 rx_errors;
562 u32 tx_errors;
563 u32 rx_dropped;
564 u32 tx_dropped;
565 u32 multicast;
566 u32 collisions;
567 u32 rx_crc_errors;
568 u32 rx_frame_errors;
569 u32 rx_alloc_buff_failed;
570 u32 tx_length_errors;
571 u32 tx_aborted_errors;
572 u32 tx_carrier_errors;
573 u32 tx_timeout_count;
574 u32 tx_restart_count;
575 u32 intr_rx_dsc_empty_count;
576 u32 intr_rx_frame_err_count;
577 u32 intr_rx_fifo_err_count;
578 u32 intr_rx_dma_err_count;
579 u32 intr_tx_fifo_err_count;
580 u32 intr_tx_dma_err_count;
581 u32 intr_tcpip_err_count;
582};
583
584/**
585 * struct pch_gbe_adapter - board specific private data structure
586 * @stats_lock: Spinlock structure for status
587 * @tx_queue_lock: Spinlock structure for transmit
588 * @ethtool_lock: Spinlock structure for ethtool
589 * @irq_sem: Semaphore for interrupt
590 * @netdev: Pointer of network device structure
591 * @pdev: Pointer of pci device structure
592 * @polling_netdev: Pointer of polling network device structure
593 * @napi: NAPI structure
594 * @hw: Pointer of hardware structure
595 * @stats: Hardware status
596 * @reset_task: Reset task
597 * @mii: MII information structure
598 * @watchdog_timer: Watchdog timer list
599 * @wake_up_evt: Wake up event
600 * @config_space: Configuration space
601 * @msg_enable: Driver message level
602 * @led_status: LED status
603 * @tx_ring: Pointer of Tx descriptor ring structure
604 * @rx_ring: Pointer of Rx descriptor ring structure
605 * @rx_buffer_len: Receive buffer length
606 * @tx_queue_len: Transmit queue length
607 * @have_msi: PCI MSI mode flag
608 */
609
610struct pch_gbe_adapter {
611 spinlock_t stats_lock;
612 spinlock_t tx_queue_lock;
613 spinlock_t ethtool_lock;
614 atomic_t irq_sem;
615 struct net_device *netdev;
616 struct pci_dev *pdev;
617 struct net_device *polling_netdev;
618 struct napi_struct napi;
619 struct pch_gbe_hw hw;
620 struct pch_gbe_hw_stats stats;
621 struct work_struct reset_task;
622 struct mii_if_info mii;
623 struct timer_list watchdog_timer;
624 u32 wake_up_evt;
625 u32 *config_space;
626 unsigned long led_status;
627 struct pch_gbe_tx_ring *tx_ring;
628 struct pch_gbe_rx_ring *rx_ring;
629 unsigned long rx_buffer_len;
630 unsigned long tx_queue_len;
631 bool have_msi;
632 bool rx_stop_flag;
633};
634
635extern const char pch_driver_version[];
636
637/* pch_gbe_main.c */
638extern int pch_gbe_up(struct pch_gbe_adapter *adapter);
639extern void pch_gbe_down(struct pch_gbe_adapter *adapter);
640extern void pch_gbe_reinit_locked(struct pch_gbe_adapter *adapter);
641extern void pch_gbe_reset(struct pch_gbe_adapter *adapter);
642extern int pch_gbe_setup_tx_resources(struct pch_gbe_adapter *adapter,
643 struct pch_gbe_tx_ring *txdr);
644extern int pch_gbe_setup_rx_resources(struct pch_gbe_adapter *adapter,
645 struct pch_gbe_rx_ring *rxdr);
646extern void pch_gbe_free_tx_resources(struct pch_gbe_adapter *adapter,
647 struct pch_gbe_tx_ring *tx_ring);
648extern void pch_gbe_free_rx_resources(struct pch_gbe_adapter *adapter,
649 struct pch_gbe_rx_ring *rx_ring);
650extern void pch_gbe_update_stats(struct pch_gbe_adapter *adapter);
651
652/* pch_gbe_param.c */
653extern void pch_gbe_check_options(struct pch_gbe_adapter *adapter);
654
655/* pch_gbe_ethtool.c */
656extern void pch_gbe_set_ethtool_ops(struct net_device *netdev);
657
658/* pch_gbe_mac.c */
659extern s32 pch_gbe_mac_force_mac_fc(struct pch_gbe_hw *hw);
660extern s32 pch_gbe_mac_read_mac_addr(struct pch_gbe_hw *hw);
661extern u16 pch_gbe_mac_ctrl_miim(struct pch_gbe_hw *hw,
662 u32 addr, u32 dir, u32 reg, u16 data);
663#endif /* _PCH_GBE_H_ */
diff --git a/drivers/net/pch_gbe/pch_gbe_api.c b/drivers/net/pch_gbe/pch_gbe_api.c
new file mode 100644
index 00000000000..e48f084ad22
--- /dev/null
+++ b/drivers/net/pch_gbe/pch_gbe_api.c
@@ -0,0 +1,245 @@
1/*
2 * Copyright (C) 1999 - 2010 Intel Corporation.
3 * Copyright (C) 2010 OKI SEMICONDUCTOR Co., LTD.
4 *
5 * This code was derived from the Intel e1000e Linux driver.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
19 */
20#include "pch_gbe.h"
21#include "pch_gbe_phy.h"
22
23/* bus type values */
24#define pch_gbe_bus_type_unknown 0
25#define pch_gbe_bus_type_pci 1
26#define pch_gbe_bus_type_pcix 2
27#define pch_gbe_bus_type_pci_express 3
28#define pch_gbe_bus_type_reserved 4
29
30/* bus speed values */
31#define pch_gbe_bus_speed_unknown 0
32#define pch_gbe_bus_speed_33 1
33#define pch_gbe_bus_speed_66 2
34#define pch_gbe_bus_speed_100 3
35#define pch_gbe_bus_speed_120 4
36#define pch_gbe_bus_speed_133 5
37#define pch_gbe_bus_speed_2500 6
38#define pch_gbe_bus_speed_reserved 7
39
40/* bus width values */
41#define pch_gbe_bus_width_unknown 0
42#define pch_gbe_bus_width_pcie_x1 1
43#define pch_gbe_bus_width_pcie_x2 2
44#define pch_gbe_bus_width_pcie_x4 4
45#define pch_gbe_bus_width_32 5
46#define pch_gbe_bus_width_64 6
47#define pch_gbe_bus_width_reserved 7
48
49/**
50 * pch_gbe_plat_get_bus_info - Obtain bus information for adapter
51 * @hw: Pointer to the HW structure
52 */
53static void pch_gbe_plat_get_bus_info(struct pch_gbe_hw *hw)
54{
55 hw->bus.type = pch_gbe_bus_type_pci_express;
56 hw->bus.speed = pch_gbe_bus_speed_2500;
57 hw->bus.width = pch_gbe_bus_width_pcie_x1;
58}
59
60/**
61 * pch_gbe_plat_init_hw - Initialize hardware
62 * @hw: Pointer to the HW structure
63 * Returns
64 * 0: Successfully
65 * Negative value: Failed-EBUSY
66 */
67static s32 pch_gbe_plat_init_hw(struct pch_gbe_hw *hw)
68{
69 s32 ret_val;
70
71 ret_val = pch_gbe_phy_get_id(hw);
72 if (ret_val) {
73 pr_err("pch_gbe_phy_get_id error\n");
74 return ret_val;
75 }
76 pch_gbe_phy_init_setting(hw);
77 /* Setup Mac interface option RGMII */
78#ifdef PCH_GBE_MAC_IFOP_RGMII
79 pch_gbe_phy_set_rgmii(hw);
80#endif
81 return ret_val;
82}
83
84static const struct pch_gbe_functions pch_gbe_ops = {
85 .get_bus_info = pch_gbe_plat_get_bus_info,
86 .init_hw = pch_gbe_plat_init_hw,
87 .read_phy_reg = pch_gbe_phy_read_reg_miic,
88 .write_phy_reg = pch_gbe_phy_write_reg_miic,
89 .reset_phy = pch_gbe_phy_hw_reset,
90 .sw_reset_phy = pch_gbe_phy_sw_reset,
91 .power_up_phy = pch_gbe_phy_power_up,
92 .power_down_phy = pch_gbe_phy_power_down,
93 .read_mac_addr = pch_gbe_mac_read_mac_addr
94};
95
96/**
97 * pch_gbe_plat_init_function_pointers - Init func ptrs
98 * @hw: Pointer to the HW structure
99 */
100static void pch_gbe_plat_init_function_pointers(struct pch_gbe_hw *hw)
101{
102 /* Set PHY parameter */
103 hw->phy.reset_delay_us = PCH_GBE_PHY_RESET_DELAY_US;
104 /* Set function pointers */
105 hw->func = &pch_gbe_ops;
106}
107
108/**
109 * pch_gbe_hal_setup_init_funcs - Initializes function pointers
110 * @hw: Pointer to the HW structure
111 * Returns
112 * 0: Successfully
113 * ENOSYS: Function is not registered
114 */
115inline s32 pch_gbe_hal_setup_init_funcs(struct pch_gbe_hw *hw)
116{
117 if (!hw->reg) {
118 pr_err("ERROR: Registers not mapped\n");
119 return -ENOSYS;
120 }
121 pch_gbe_plat_init_function_pointers(hw);
122 return 0;
123}
124
125/**
126 * pch_gbe_hal_get_bus_info - Obtain bus information for adapter
127 * @hw: Pointer to the HW structure
128 */
129inline void pch_gbe_hal_get_bus_info(struct pch_gbe_hw *hw)
130{
131 if (!hw->func->get_bus_info)
132 pr_err("ERROR: configuration\n");
133 else
134 hw->func->get_bus_info(hw);
135}
136
137/**
138 * pch_gbe_hal_init_hw - Initialize hardware
139 * @hw: Pointer to the HW structure
140 * Returns
141 * 0: Successfully
142 * ENOSYS: Function is not registered
143 */
144inline s32 pch_gbe_hal_init_hw(struct pch_gbe_hw *hw)
145{
146 if (!hw->func->init_hw) {
147 pr_err("ERROR: configuration\n");
148 return -ENOSYS;
149 }
150 return hw->func->init_hw(hw);
151}
152
153/**
154 * pch_gbe_hal_read_phy_reg - Reads PHY register
155 * @hw: Pointer to the HW structure
156 * @offset: The register to read
157 * @data: The buffer to store the 16-bit read.
158 * Returns
159 * 0: Successfully
160 * Negative value: Failed
161 */
162inline s32 pch_gbe_hal_read_phy_reg(struct pch_gbe_hw *hw, u32 offset,
163 u16 *data)
164{
165 if (!hw->func->read_phy_reg)
166 return 0;
167 return hw->func->read_phy_reg(hw, offset, data);
168}
169
170/**
171 * pch_gbe_hal_write_phy_reg - Writes PHY register
172 * @hw: Pointer to the HW structure
173 * @offset: The register to read
174 * @data: The value to write.
175 * Returns
176 * 0: Successfully
177 * Negative value: Failed
178 */
179inline s32 pch_gbe_hal_write_phy_reg(struct pch_gbe_hw *hw, u32 offset,
180 u16 data)
181{
182 if (!hw->func->write_phy_reg)
183 return 0;
184 return hw->func->write_phy_reg(hw, offset, data);
185}
186
187/**
188 * pch_gbe_hal_phy_hw_reset - Hard PHY reset
189 * @hw: Pointer to the HW structure
190 */
191inline void pch_gbe_hal_phy_hw_reset(struct pch_gbe_hw *hw)
192{
193 if (!hw->func->reset_phy)
194 pr_err("ERROR: configuration\n");
195 else
196 hw->func->reset_phy(hw);
197}
198
199/**
200 * pch_gbe_hal_phy_sw_reset - Soft PHY reset
201 * @hw: Pointer to the HW structure
202 */
203inline void pch_gbe_hal_phy_sw_reset(struct pch_gbe_hw *hw)
204{
205 if (!hw->func->sw_reset_phy)
206 pr_err("ERROR: configuration\n");
207 else
208 hw->func->sw_reset_phy(hw);
209}
210
211/**
212 * pch_gbe_hal_read_mac_addr - Reads MAC address
213 * @hw: Pointer to the HW structure
214 * Returns
215 * 0: Successfully
216 * ENOSYS: Function is not registered
217 */
218inline s32 pch_gbe_hal_read_mac_addr(struct pch_gbe_hw *hw)
219{
220 if (!hw->func->read_mac_addr) {
221 pr_err("ERROR: configuration\n");
222 return -ENOSYS;
223 }
224 return hw->func->read_mac_addr(hw);
225}
226
227/**
228 * pch_gbe_hal_power_up_phy - Power up PHY
229 * @hw: Pointer to the HW structure
230 */
231inline void pch_gbe_hal_power_up_phy(struct pch_gbe_hw *hw)
232{
233 if (hw->func->power_up_phy)
234 hw->func->power_up_phy(hw);
235}
236
237/**
238 * pch_gbe_hal_power_down_phy - Power down PHY
239 * @hw: Pointer to the HW structure
240 */
241inline void pch_gbe_hal_power_down_phy(struct pch_gbe_hw *hw)
242{
243 if (hw->func->power_down_phy)
244 hw->func->power_down_phy(hw);
245}
diff --git a/drivers/net/pch_gbe/pch_gbe_api.h b/drivers/net/pch_gbe/pch_gbe_api.h
new file mode 100644
index 00000000000..94aaac5b057
--- /dev/null
+++ b/drivers/net/pch_gbe/pch_gbe_api.h
@@ -0,0 +1,36 @@
1/*
2 * Copyright (C) 1999 - 2010 Intel Corporation.
3 * Copyright (C) 2010 OKI SEMICONDUCTOR Co., LTD.
4 *
5 * This code was derived from the Intel e1000e Linux driver.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
19 */
20#ifndef _PCH_GBE_API_H_
21#define _PCH_GBE_API_H_
22
23#include "pch_gbe_phy.h"
24
25s32 pch_gbe_hal_setup_init_funcs(struct pch_gbe_hw *hw);
26void pch_gbe_hal_get_bus_info(struct pch_gbe_hw *hw);
27s32 pch_gbe_hal_init_hw(struct pch_gbe_hw *hw);
28s32 pch_gbe_hal_read_phy_reg(struct pch_gbe_hw *hw, u32 offset, u16 *data);
29s32 pch_gbe_hal_write_phy_reg(struct pch_gbe_hw *hw, u32 offset, u16 data);
30void pch_gbe_hal_phy_hw_reset(struct pch_gbe_hw *hw);
31void pch_gbe_hal_phy_sw_reset(struct pch_gbe_hw *hw);
32s32 pch_gbe_hal_read_mac_addr(struct pch_gbe_hw *hw);
33void pch_gbe_hal_power_up_phy(struct pch_gbe_hw *hw);
34void pch_gbe_hal_power_down_phy(struct pch_gbe_hw *hw);
35
36#endif
diff --git a/drivers/net/pch_gbe/pch_gbe_ethtool.c b/drivers/net/pch_gbe/pch_gbe_ethtool.c
new file mode 100644
index 00000000000..ea2d8e41887
--- /dev/null
+++ b/drivers/net/pch_gbe/pch_gbe_ethtool.c
@@ -0,0 +1,517 @@
1/*
2 * Copyright (C) 1999 - 2010 Intel Corporation.
3 * Copyright (C) 2010 OKI SEMICONDUCTOR Co., LTD.
4 *
5 * This code was derived from the Intel e1000e Linux driver.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
19 */
20#include "pch_gbe.h"
21#include "pch_gbe_api.h"
22
23/**
24 * pch_gbe_stats - Stats item information
25 */
26struct pch_gbe_stats {
27 char string[ETH_GSTRING_LEN];
28 size_t size;
29 size_t offset;
30};
31
32#define PCH_GBE_STAT(m) \
33{ \
34 .string = #m, \
35 .size = FIELD_SIZEOF(struct pch_gbe_hw_stats, m), \
36 .offset = offsetof(struct pch_gbe_hw_stats, m), \
37}
38
39/**
40 * pch_gbe_gstrings_stats - ethtool information status name list
41 */
42static const struct pch_gbe_stats pch_gbe_gstrings_stats[] = {
43 PCH_GBE_STAT(rx_packets),
44 PCH_GBE_STAT(tx_packets),
45 PCH_GBE_STAT(rx_bytes),
46 PCH_GBE_STAT(tx_bytes),
47 PCH_GBE_STAT(rx_errors),
48 PCH_GBE_STAT(tx_errors),
49 PCH_GBE_STAT(rx_dropped),
50 PCH_GBE_STAT(tx_dropped),
51 PCH_GBE_STAT(multicast),
52 PCH_GBE_STAT(collisions),
53 PCH_GBE_STAT(rx_crc_errors),
54 PCH_GBE_STAT(rx_frame_errors),
55 PCH_GBE_STAT(rx_alloc_buff_failed),
56 PCH_GBE_STAT(tx_length_errors),
57 PCH_GBE_STAT(tx_aborted_errors),
58 PCH_GBE_STAT(tx_carrier_errors),
59 PCH_GBE_STAT(tx_timeout_count),
60 PCH_GBE_STAT(tx_restart_count),
61 PCH_GBE_STAT(intr_rx_dsc_empty_count),
62 PCH_GBE_STAT(intr_rx_frame_err_count),
63 PCH_GBE_STAT(intr_rx_fifo_err_count),
64 PCH_GBE_STAT(intr_rx_dma_err_count),
65 PCH_GBE_STAT(intr_tx_fifo_err_count),
66 PCH_GBE_STAT(intr_tx_dma_err_count),
67 PCH_GBE_STAT(intr_tcpip_err_count)
68};
69
70#define PCH_GBE_QUEUE_STATS_LEN 0
71#define PCH_GBE_GLOBAL_STATS_LEN ARRAY_SIZE(pch_gbe_gstrings_stats)
72#define PCH_GBE_STATS_LEN (PCH_GBE_GLOBAL_STATS_LEN + PCH_GBE_QUEUE_STATS_LEN)
73
74#define PCH_GBE_MAC_REGS_LEN (sizeof(struct pch_gbe_regs) / 4)
75#define PCH_GBE_REGS_LEN (PCH_GBE_MAC_REGS_LEN + PCH_GBE_PHY_REGS_LEN)
76/**
77 * pch_gbe_get_settings - Get device-specific settings
78 * @netdev: Network interface device structure
79 * @ecmd: Ethtool command
80 * Returns
81 * 0: Successful.
82 * Negative value: Failed.
83 */
84static int pch_gbe_get_settings(struct net_device *netdev,
85 struct ethtool_cmd *ecmd)
86{
87 struct pch_gbe_adapter *adapter = netdev_priv(netdev);
88 int ret;
89
90 ret = mii_ethtool_gset(&adapter->mii, ecmd);
91 ecmd->supported &= ~(SUPPORTED_TP | SUPPORTED_1000baseT_Half);
92 ecmd->advertising &= ~(ADVERTISED_TP | ADVERTISED_1000baseT_Half);
93
94 if (!netif_carrier_ok(adapter->netdev))
95 ethtool_cmd_speed_set(ecmd, -1);
96 return ret;
97}
98
99/**
100 * pch_gbe_set_settings - Set device-specific settings
101 * @netdev: Network interface device structure
102 * @ecmd: Ethtool command
103 * Returns
104 * 0: Successful.
105 * Negative value: Failed.
106 */
107static int pch_gbe_set_settings(struct net_device *netdev,
108 struct ethtool_cmd *ecmd)
109{
110 struct pch_gbe_adapter *adapter = netdev_priv(netdev);
111 struct pch_gbe_hw *hw = &adapter->hw;
112 u32 speed = ethtool_cmd_speed(ecmd);
113 int ret;
114
115 pch_gbe_hal_write_phy_reg(hw, MII_BMCR, BMCR_RESET);
116
117 /* when set_settings() is called with a ethtool_cmd previously
118 * filled by get_settings() on a down link, speed is -1: */
119 if (speed == UINT_MAX) {
120 speed = SPEED_1000;
121 ecmd->duplex = DUPLEX_FULL;
122 }
123 ret = mii_ethtool_sset(&adapter->mii, ecmd);
124 if (ret) {
125 pr_err("Error: mii_ethtool_sset\n");
126 return ret;
127 }
128 hw->mac.link_speed = speed;
129 hw->mac.link_duplex = ecmd->duplex;
130 hw->phy.autoneg_advertised = ecmd->advertising;
131 hw->mac.autoneg = ecmd->autoneg;
132 pch_gbe_hal_phy_sw_reset(hw);
133
134 /* reset the link */
135 if (netif_running(adapter->netdev)) {
136 pch_gbe_down(adapter);
137 ret = pch_gbe_up(adapter);
138 } else {
139 pch_gbe_reset(adapter);
140 }
141 return ret;
142}
143
144/**
145 * pch_gbe_get_regs_len - Report the size of device registers
146 * @netdev: Network interface device structure
147 * Returns: the size of device registers.
148 */
149static int pch_gbe_get_regs_len(struct net_device *netdev)
150{
151 return PCH_GBE_REGS_LEN * (int)sizeof(u32);
152}
153
154/**
155 * pch_gbe_get_drvinfo - Report driver information
156 * @netdev: Network interface device structure
157 * @drvinfo: Driver information structure
158 */
159static void pch_gbe_get_drvinfo(struct net_device *netdev,
160 struct ethtool_drvinfo *drvinfo)
161{
162 struct pch_gbe_adapter *adapter = netdev_priv(netdev);
163
164 strcpy(drvinfo->driver, KBUILD_MODNAME);
165 strcpy(drvinfo->version, pch_driver_version);
166 strcpy(drvinfo->fw_version, "N/A");
167 strcpy(drvinfo->bus_info, pci_name(adapter->pdev));
168 drvinfo->regdump_len = pch_gbe_get_regs_len(netdev);
169}
170
171/**
172 * pch_gbe_get_regs - Get device registers
173 * @netdev: Network interface device structure
174 * @regs: Ethtool register structure
175 * @p: Buffer pointer of read device register date
176 */
177static void pch_gbe_get_regs(struct net_device *netdev,
178 struct ethtool_regs *regs, void *p)
179{
180 struct pch_gbe_adapter *adapter = netdev_priv(netdev);
181 struct pch_gbe_hw *hw = &adapter->hw;
182 struct pci_dev *pdev = adapter->pdev;
183 u32 *regs_buff = p;
184 u16 i, tmp;
185
186 regs->version = 0x1000000 | (__u32)pdev->revision << 16 | pdev->device;
187 for (i = 0; i < PCH_GBE_MAC_REGS_LEN; i++)
188 *regs_buff++ = ioread32(&hw->reg->INT_ST + i);
189 /* PHY register */
190 for (i = 0; i < PCH_GBE_PHY_REGS_LEN; i++) {
191 pch_gbe_hal_read_phy_reg(&adapter->hw, i, &tmp);
192 *regs_buff++ = tmp;
193 }
194}
195
196/**
197 * pch_gbe_get_wol - Report whether Wake-on-Lan is enabled
198 * @netdev: Network interface device structure
199 * @wol: Wake-on-Lan information
200 */
201static void pch_gbe_get_wol(struct net_device *netdev,
202 struct ethtool_wolinfo *wol)
203{
204 struct pch_gbe_adapter *adapter = netdev_priv(netdev);
205
206 wol->supported = WAKE_UCAST | WAKE_MCAST | WAKE_BCAST | WAKE_MAGIC;
207 wol->wolopts = 0;
208
209 if ((adapter->wake_up_evt & PCH_GBE_WLC_IND))
210 wol->wolopts |= WAKE_UCAST;
211 if ((adapter->wake_up_evt & PCH_GBE_WLC_MLT))
212 wol->wolopts |= WAKE_MCAST;
213 if ((adapter->wake_up_evt & PCH_GBE_WLC_BR))
214 wol->wolopts |= WAKE_BCAST;
215 if ((adapter->wake_up_evt & PCH_GBE_WLC_MP))
216 wol->wolopts |= WAKE_MAGIC;
217}
218
219/**
220 * pch_gbe_set_wol - Turn Wake-on-Lan on or off
221 * @netdev: Network interface device structure
222 * @wol: Pointer of wake-on-Lan information straucture
223 * Returns
224 * 0: Successful.
225 * Negative value: Failed.
226 */
227static int pch_gbe_set_wol(struct net_device *netdev,
228 struct ethtool_wolinfo *wol)
229{
230 struct pch_gbe_adapter *adapter = netdev_priv(netdev);
231
232 if ((wol->wolopts & (WAKE_PHY | WAKE_ARP | WAKE_MAGICSECURE)))
233 return -EOPNOTSUPP;
234 /* these settings will always override what we currently have */
235 adapter->wake_up_evt = 0;
236
237 if ((wol->wolopts & WAKE_UCAST))
238 adapter->wake_up_evt |= PCH_GBE_WLC_IND;
239 if ((wol->wolopts & WAKE_MCAST))
240 adapter->wake_up_evt |= PCH_GBE_WLC_MLT;
241 if ((wol->wolopts & WAKE_BCAST))
242 adapter->wake_up_evt |= PCH_GBE_WLC_BR;
243 if ((wol->wolopts & WAKE_MAGIC))
244 adapter->wake_up_evt |= PCH_GBE_WLC_MP;
245 return 0;
246}
247
248/**
249 * pch_gbe_nway_reset - Restart autonegotiation
250 * @netdev: Network interface device structure
251 * Returns
252 * 0: Successful.
253 * Negative value: Failed.
254 */
255static int pch_gbe_nway_reset(struct net_device *netdev)
256{
257 struct pch_gbe_adapter *adapter = netdev_priv(netdev);
258
259 return mii_nway_restart(&adapter->mii);
260}
261
262/**
263 * pch_gbe_get_ringparam - Report ring sizes
264 * @netdev: Network interface device structure
265 * @ring: Ring param structure
266 */
267static void pch_gbe_get_ringparam(struct net_device *netdev,
268 struct ethtool_ringparam *ring)
269{
270 struct pch_gbe_adapter *adapter = netdev_priv(netdev);
271 struct pch_gbe_tx_ring *txdr = adapter->tx_ring;
272 struct pch_gbe_rx_ring *rxdr = adapter->rx_ring;
273
274 ring->rx_max_pending = PCH_GBE_MAX_RXD;
275 ring->tx_max_pending = PCH_GBE_MAX_TXD;
276 ring->rx_mini_max_pending = 0;
277 ring->rx_jumbo_max_pending = 0;
278 ring->rx_pending = rxdr->count;
279 ring->tx_pending = txdr->count;
280 ring->rx_mini_pending = 0;
281 ring->rx_jumbo_pending = 0;
282}
283
284/**
285 * pch_gbe_set_ringparam - Set ring sizes
286 * @netdev: Network interface device structure
287 * @ring: Ring param structure
288 * Returns
289 * 0: Successful.
290 * Negative value: Failed.
291 */
292static int pch_gbe_set_ringparam(struct net_device *netdev,
293 struct ethtool_ringparam *ring)
294{
295 struct pch_gbe_adapter *adapter = netdev_priv(netdev);
296 struct pch_gbe_tx_ring *txdr, *tx_old;
297 struct pch_gbe_rx_ring *rxdr, *rx_old;
298 int tx_ring_size, rx_ring_size;
299 int err = 0;
300
301 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
302 return -EINVAL;
303 tx_ring_size = (int)sizeof(struct pch_gbe_tx_ring);
304 rx_ring_size = (int)sizeof(struct pch_gbe_rx_ring);
305
306 if ((netif_running(adapter->netdev)))
307 pch_gbe_down(adapter);
308 tx_old = adapter->tx_ring;
309 rx_old = adapter->rx_ring;
310
311 txdr = kzalloc(tx_ring_size, GFP_KERNEL);
312 if (!txdr) {
313 err = -ENOMEM;
314 goto err_alloc_tx;
315 }
316 rxdr = kzalloc(rx_ring_size, GFP_KERNEL);
317 if (!rxdr) {
318 err = -ENOMEM;
319 goto err_alloc_rx;
320 }
321 adapter->tx_ring = txdr;
322 adapter->rx_ring = rxdr;
323
324 rxdr->count =
325 clamp_val(ring->rx_pending, PCH_GBE_MIN_RXD, PCH_GBE_MAX_RXD);
326 rxdr->count = roundup(rxdr->count, PCH_GBE_RX_DESC_MULTIPLE);
327
328 txdr->count =
329 clamp_val(ring->tx_pending, PCH_GBE_MIN_RXD, PCH_GBE_MAX_RXD);
330 txdr->count = roundup(txdr->count, PCH_GBE_TX_DESC_MULTIPLE);
331
332 if ((netif_running(adapter->netdev))) {
333 /* Try to get new resources before deleting old */
334 err = pch_gbe_setup_rx_resources(adapter, adapter->rx_ring);
335 if (err)
336 goto err_setup_rx;
337 err = pch_gbe_setup_tx_resources(adapter, adapter->tx_ring);
338 if (err)
339 goto err_setup_tx;
340 /* save the new, restore the old in order to free it,
341 * then restore the new back again */
342#ifdef RINGFREE
343 adapter->rx_ring = rx_old;
344 adapter->tx_ring = tx_old;
345 pch_gbe_free_rx_resources(adapter, adapter->rx_ring);
346 pch_gbe_free_tx_resources(adapter, adapter->tx_ring);
347 kfree(tx_old);
348 kfree(rx_old);
349 adapter->rx_ring = rxdr;
350 adapter->tx_ring = txdr;
351#else
352 pch_gbe_free_rx_resources(adapter, rx_old);
353 pch_gbe_free_tx_resources(adapter, tx_old);
354 kfree(tx_old);
355 kfree(rx_old);
356 adapter->rx_ring = rxdr;
357 adapter->tx_ring = txdr;
358#endif
359 err = pch_gbe_up(adapter);
360 }
361 return err;
362
363err_setup_tx:
364 pch_gbe_free_rx_resources(adapter, adapter->rx_ring);
365err_setup_rx:
366 adapter->rx_ring = rx_old;
367 adapter->tx_ring = tx_old;
368 kfree(rxdr);
369err_alloc_rx:
370 kfree(txdr);
371err_alloc_tx:
372 if (netif_running(adapter->netdev))
373 pch_gbe_up(adapter);
374 return err;
375}
376
377/**
378 * pch_gbe_get_pauseparam - Report pause parameters
379 * @netdev: Network interface device structure
380 * @pause: Pause parameters structure
381 */
382static void pch_gbe_get_pauseparam(struct net_device *netdev,
383 struct ethtool_pauseparam *pause)
384{
385 struct pch_gbe_adapter *adapter = netdev_priv(netdev);
386 struct pch_gbe_hw *hw = &adapter->hw;
387
388 pause->autoneg =
389 ((hw->mac.fc_autoneg) ? AUTONEG_ENABLE : AUTONEG_DISABLE);
390
391 if (hw->mac.fc == PCH_GBE_FC_RX_PAUSE) {
392 pause->rx_pause = 1;
393 } else if (hw->mac.fc == PCH_GBE_FC_TX_PAUSE) {
394 pause->tx_pause = 1;
395 } else if (hw->mac.fc == PCH_GBE_FC_FULL) {
396 pause->rx_pause = 1;
397 pause->tx_pause = 1;
398 }
399}
400
401/**
402 * pch_gbe_set_pauseparam - Set pause paramters
403 * @netdev: Network interface device structure
404 * @pause: Pause parameters structure
405 * Returns
406 * 0: Successful.
407 * Negative value: Failed.
408 */
409static int pch_gbe_set_pauseparam(struct net_device *netdev,
410 struct ethtool_pauseparam *pause)
411{
412 struct pch_gbe_adapter *adapter = netdev_priv(netdev);
413 struct pch_gbe_hw *hw = &adapter->hw;
414 int ret = 0;
415
416 hw->mac.fc_autoneg = pause->autoneg;
417 if ((pause->rx_pause) && (pause->tx_pause))
418 hw->mac.fc = PCH_GBE_FC_FULL;
419 else if ((pause->rx_pause) && (!pause->tx_pause))
420 hw->mac.fc = PCH_GBE_FC_RX_PAUSE;
421 else if ((!pause->rx_pause) && (pause->tx_pause))
422 hw->mac.fc = PCH_GBE_FC_TX_PAUSE;
423 else if ((!pause->rx_pause) && (!pause->tx_pause))
424 hw->mac.fc = PCH_GBE_FC_NONE;
425
426 if (hw->mac.fc_autoneg == AUTONEG_ENABLE) {
427 if ((netif_running(adapter->netdev))) {
428 pch_gbe_down(adapter);
429 ret = pch_gbe_up(adapter);
430 } else {
431 pch_gbe_reset(adapter);
432 }
433 } else {
434 ret = pch_gbe_mac_force_mac_fc(hw);
435 }
436 return ret;
437}
438
439/**
440 * pch_gbe_get_strings - Return a set of strings that describe the requested
441 * objects
442 * @netdev: Network interface device structure
443 * @stringset: Select the stringset. [ETH_SS_TEST] [ETH_SS_STATS]
444 * @data: Pointer of read string data.
445 */
446static void pch_gbe_get_strings(struct net_device *netdev, u32 stringset,
447 u8 *data)
448{
449 u8 *p = data;
450 int i;
451
452 switch (stringset) {
453 case (u32) ETH_SS_STATS:
454 for (i = 0; i < PCH_GBE_GLOBAL_STATS_LEN; i++) {
455 memcpy(p, pch_gbe_gstrings_stats[i].string,
456 ETH_GSTRING_LEN);
457 p += ETH_GSTRING_LEN;
458 }
459 break;
460 }
461}
462
463/**
464 * pch_gbe_get_ethtool_stats - Return statistics about the device
465 * @netdev: Network interface device structure
466 * @stats: Ethtool statue structure
467 * @data: Pointer of read status area
468 */
469static void pch_gbe_get_ethtool_stats(struct net_device *netdev,
470 struct ethtool_stats *stats, u64 *data)
471{
472 struct pch_gbe_adapter *adapter = netdev_priv(netdev);
473 int i;
474 const struct pch_gbe_stats *gstats = pch_gbe_gstrings_stats;
475 char *hw_stats = (char *)&adapter->stats;
476
477 pch_gbe_update_stats(adapter);
478 for (i = 0; i < PCH_GBE_GLOBAL_STATS_LEN; i++) {
479 char *p = hw_stats + gstats->offset;
480 data[i] = gstats->size == sizeof(u64) ? *(u64 *)p:(*(u32 *)p);
481 gstats++;
482 }
483}
484
485static int pch_gbe_get_sset_count(struct net_device *netdev, int sset)
486{
487 switch (sset) {
488 case ETH_SS_STATS:
489 return PCH_GBE_STATS_LEN;
490 default:
491 return -EOPNOTSUPP;
492 }
493}
494
495static const struct ethtool_ops pch_gbe_ethtool_ops = {
496 .get_settings = pch_gbe_get_settings,
497 .set_settings = pch_gbe_set_settings,
498 .get_drvinfo = pch_gbe_get_drvinfo,
499 .get_regs_len = pch_gbe_get_regs_len,
500 .get_regs = pch_gbe_get_regs,
501 .get_wol = pch_gbe_get_wol,
502 .set_wol = pch_gbe_set_wol,
503 .nway_reset = pch_gbe_nway_reset,
504 .get_link = ethtool_op_get_link,
505 .get_ringparam = pch_gbe_get_ringparam,
506 .set_ringparam = pch_gbe_set_ringparam,
507 .get_pauseparam = pch_gbe_get_pauseparam,
508 .set_pauseparam = pch_gbe_set_pauseparam,
509 .get_strings = pch_gbe_get_strings,
510 .get_ethtool_stats = pch_gbe_get_ethtool_stats,
511 .get_sset_count = pch_gbe_get_sset_count,
512};
513
514void pch_gbe_set_ethtool_ops(struct net_device *netdev)
515{
516 SET_ETHTOOL_OPS(netdev, &pch_gbe_ethtool_ops);
517}
diff --git a/drivers/net/pch_gbe/pch_gbe_main.c b/drivers/net/pch_gbe/pch_gbe_main.c
new file mode 100644
index 00000000000..b8b4ba27b0e
--- /dev/null
+++ b/drivers/net/pch_gbe/pch_gbe_main.c
@@ -0,0 +1,2605 @@
1/*
2 * Copyright (C) 1999 - 2010 Intel Corporation.
3 * Copyright (C) 2010 OKI SEMICONDUCTOR CO., LTD.
4 *
5 * This code was derived from the Intel e1000e Linux driver.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
19 */
20
21#include "pch_gbe.h"
22#include "pch_gbe_api.h"
23
24#define DRV_VERSION "1.00"
25const char pch_driver_version[] = DRV_VERSION;
26
27#define PCI_DEVICE_ID_INTEL_IOH1_GBE 0x8802 /* Pci device ID */
28#define PCH_GBE_MAR_ENTRIES 16
29#define PCH_GBE_SHORT_PKT 64
30#define DSC_INIT16 0xC000
31#define PCH_GBE_DMA_ALIGN 0
32#define PCH_GBE_DMA_PADDING 2
33#define PCH_GBE_WATCHDOG_PERIOD (1 * HZ) /* watchdog time */
34#define PCH_GBE_COPYBREAK_DEFAULT 256
35#define PCH_GBE_PCI_BAR 1
36#define PCH_GBE_RESERVE_MEMORY 0x200000 /* 2MB */
37
38/* Macros for ML7223 */
39#define PCI_VENDOR_ID_ROHM 0x10db
40#define PCI_DEVICE_ID_ROHM_ML7223_GBE 0x8013
41
42/* Macros for ML7831 */
43#define PCI_DEVICE_ID_ROHM_ML7831_GBE 0x8802
44
45#define PCH_GBE_TX_WEIGHT 64
46#define PCH_GBE_RX_WEIGHT 64
47#define PCH_GBE_RX_BUFFER_WRITE 16
48
49/* Initialize the wake-on-LAN settings */
50#define PCH_GBE_WL_INIT_SETTING (PCH_GBE_WLC_MP)
51
52#define PCH_GBE_MAC_RGMII_CTRL_SETTING ( \
53 PCH_GBE_CHIP_TYPE_INTERNAL | \
54 PCH_GBE_RGMII_MODE_RGMII \
55 )
56
57/* Ethertype field values */
58#define PCH_GBE_MAX_RX_BUFFER_SIZE 0x2880
59#define PCH_GBE_MAX_JUMBO_FRAME_SIZE 10318
60#define PCH_GBE_FRAME_SIZE_2048 2048
61#define PCH_GBE_FRAME_SIZE_4096 4096
62#define PCH_GBE_FRAME_SIZE_8192 8192
63
64#define PCH_GBE_GET_DESC(R, i, type) (&(((struct type *)((R).desc))[i]))
65#define PCH_GBE_RX_DESC(R, i) PCH_GBE_GET_DESC(R, i, pch_gbe_rx_desc)
66#define PCH_GBE_TX_DESC(R, i) PCH_GBE_GET_DESC(R, i, pch_gbe_tx_desc)
67#define PCH_GBE_DESC_UNUSED(R) \
68 ((((R)->next_to_clean > (R)->next_to_use) ? 0 : (R)->count) + \
69 (R)->next_to_clean - (R)->next_to_use - 1)
70
71/* Pause packet value */
72#define PCH_GBE_PAUSE_PKT1_VALUE 0x00C28001
73#define PCH_GBE_PAUSE_PKT2_VALUE 0x00000100
74#define PCH_GBE_PAUSE_PKT4_VALUE 0x01000888
75#define PCH_GBE_PAUSE_PKT5_VALUE 0x0000FFFF
76
77#define PCH_GBE_ETH_ALEN 6
78
79/* This defines the bits that are set in the Interrupt Mask
80 * Set/Read Register. Each bit is documented below:
81 * o RXT0 = Receiver Timer Interrupt (ring 0)
82 * o TXDW = Transmit Descriptor Written Back
83 * o RXDMT0 = Receive Descriptor Minimum Threshold hit (ring 0)
84 * o RXSEQ = Receive Sequence Error
85 * o LSC = Link Status Change
86 */
87#define PCH_GBE_INT_ENABLE_MASK ( \
88 PCH_GBE_INT_RX_DMA_CMPLT | \
89 PCH_GBE_INT_RX_DSC_EMP | \
90 PCH_GBE_INT_RX_FIFO_ERR | \
91 PCH_GBE_INT_WOL_DET | \
92 PCH_GBE_INT_TX_CMPLT \
93 )
94
95#define PCH_GBE_INT_DISABLE_ALL 0
96
97static unsigned int copybreak __read_mostly = PCH_GBE_COPYBREAK_DEFAULT;
98
99static int pch_gbe_mdio_read(struct net_device *netdev, int addr, int reg);
100static void pch_gbe_mdio_write(struct net_device *netdev, int addr, int reg,
101 int data);
102
103inline void pch_gbe_mac_load_mac_addr(struct pch_gbe_hw *hw)
104{
105 iowrite32(0x01, &hw->reg->MAC_ADDR_LOAD);
106}
107
108/**
109 * pch_gbe_mac_read_mac_addr - Read MAC address
110 * @hw: Pointer to the HW structure
111 * Returns
112 * 0: Successful.
113 */
114s32 pch_gbe_mac_read_mac_addr(struct pch_gbe_hw *hw)
115{
116 u32 adr1a, adr1b;
117
118 adr1a = ioread32(&hw->reg->mac_adr[0].high);
119 adr1b = ioread32(&hw->reg->mac_adr[0].low);
120
121 hw->mac.addr[0] = (u8)(adr1a & 0xFF);
122 hw->mac.addr[1] = (u8)((adr1a >> 8) & 0xFF);
123 hw->mac.addr[2] = (u8)((adr1a >> 16) & 0xFF);
124 hw->mac.addr[3] = (u8)((adr1a >> 24) & 0xFF);
125 hw->mac.addr[4] = (u8)(adr1b & 0xFF);
126 hw->mac.addr[5] = (u8)((adr1b >> 8) & 0xFF);
127
128 pr_debug("hw->mac.addr : %pM\n", hw->mac.addr);
129 return 0;
130}
131
132/**
133 * pch_gbe_wait_clr_bit - Wait to clear a bit
134 * @reg: Pointer of register
135 * @busy: Busy bit
136 */
137static void pch_gbe_wait_clr_bit(void *reg, u32 bit)
138{
139 u32 tmp;
140 /* wait busy */
141 tmp = 1000;
142 while ((ioread32(reg) & bit) && --tmp)
143 cpu_relax();
144 if (!tmp)
145 pr_err("Error: busy bit is not cleared\n");
146}
147
148/**
149 * pch_gbe_wait_clr_bit_irq - Wait to clear a bit for interrupt context
150 * @reg: Pointer of register
151 * @busy: Busy bit
152 */
153static int pch_gbe_wait_clr_bit_irq(void *reg, u32 bit)
154{
155 u32 tmp;
156 int ret = -1;
157 /* wait busy */
158 tmp = 20;
159 while ((ioread32(reg) & bit) && --tmp)
160 udelay(5);
161 if (!tmp)
162 pr_err("Error: busy bit is not cleared\n");
163 else
164 ret = 0;
165 return ret;
166}
167
168/**
169 * pch_gbe_mac_mar_set - Set MAC address register
170 * @hw: Pointer to the HW structure
171 * @addr: Pointer to the MAC address
172 * @index: MAC address array register
173 */
174static void pch_gbe_mac_mar_set(struct pch_gbe_hw *hw, u8 * addr, u32 index)
175{
176 u32 mar_low, mar_high, adrmask;
177
178 pr_debug("index : 0x%x\n", index);
179
180 /*
181 * HW expects these in little endian so we reverse the byte order
182 * from network order (big endian) to little endian
183 */
184 mar_high = ((u32) addr[0] | ((u32) addr[1] << 8) |
185 ((u32) addr[2] << 16) | ((u32) addr[3] << 24));
186 mar_low = ((u32) addr[4] | ((u32) addr[5] << 8));
187 /* Stop the MAC Address of index. */
188 adrmask = ioread32(&hw->reg->ADDR_MASK);
189 iowrite32((adrmask | (0x0001 << index)), &hw->reg->ADDR_MASK);
190 /* wait busy */
191 pch_gbe_wait_clr_bit(&hw->reg->ADDR_MASK, PCH_GBE_BUSY);
192 /* Set the MAC address to the MAC address 1A/1B register */
193 iowrite32(mar_high, &hw->reg->mac_adr[index].high);
194 iowrite32(mar_low, &hw->reg->mac_adr[index].low);
195 /* Start the MAC address of index */
196 iowrite32((adrmask & ~(0x0001 << index)), &hw->reg->ADDR_MASK);
197 /* wait busy */
198 pch_gbe_wait_clr_bit(&hw->reg->ADDR_MASK, PCH_GBE_BUSY);
199}
200
201/**
202 * pch_gbe_mac_reset_hw - Reset hardware
203 * @hw: Pointer to the HW structure
204 */
205static void pch_gbe_mac_reset_hw(struct pch_gbe_hw *hw)
206{
207 /* Read the MAC address. and store to the private data */
208 pch_gbe_mac_read_mac_addr(hw);
209 iowrite32(PCH_GBE_ALL_RST, &hw->reg->RESET);
210#ifdef PCH_GBE_MAC_IFOP_RGMII
211 iowrite32(PCH_GBE_MODE_GMII_ETHER, &hw->reg->MODE);
212#endif
213 pch_gbe_wait_clr_bit(&hw->reg->RESET, PCH_GBE_ALL_RST);
214 /* Setup the receive address */
215 pch_gbe_mac_mar_set(hw, hw->mac.addr, 0);
216 return;
217}
218
219static void pch_gbe_mac_reset_rx(struct pch_gbe_hw *hw)
220{
221 /* Read the MAC address. and store to the private data */
222 pch_gbe_mac_read_mac_addr(hw);
223 iowrite32(PCH_GBE_RX_RST, &hw->reg->RESET);
224 pch_gbe_wait_clr_bit_irq(&hw->reg->RESET, PCH_GBE_RX_RST);
225 /* Setup the MAC address */
226 pch_gbe_mac_mar_set(hw, hw->mac.addr, 0);
227 return;
228}
229
230/**
231 * pch_gbe_mac_init_rx_addrs - Initialize receive address's
232 * @hw: Pointer to the HW structure
233 * @mar_count: Receive address registers
234 */
235static void pch_gbe_mac_init_rx_addrs(struct pch_gbe_hw *hw, u16 mar_count)
236{
237 u32 i;
238
239 /* Setup the receive address */
240 pch_gbe_mac_mar_set(hw, hw->mac.addr, 0);
241
242 /* Zero out the other receive addresses */
243 for (i = 1; i < mar_count; i++) {
244 iowrite32(0, &hw->reg->mac_adr[i].high);
245 iowrite32(0, &hw->reg->mac_adr[i].low);
246 }
247 iowrite32(0xFFFE, &hw->reg->ADDR_MASK);
248 /* wait busy */
249 pch_gbe_wait_clr_bit(&hw->reg->ADDR_MASK, PCH_GBE_BUSY);
250}
251
252
253/**
254 * pch_gbe_mac_mc_addr_list_update - Update Multicast addresses
255 * @hw: Pointer to the HW structure
256 * @mc_addr_list: Array of multicast addresses to program
257 * @mc_addr_count: Number of multicast addresses to program
258 * @mar_used_count: The first MAC Address register free to program
259 * @mar_total_num: Total number of supported MAC Address Registers
260 */
261static void pch_gbe_mac_mc_addr_list_update(struct pch_gbe_hw *hw,
262 u8 *mc_addr_list, u32 mc_addr_count,
263 u32 mar_used_count, u32 mar_total_num)
264{
265 u32 i, adrmask;
266
267 /* Load the first set of multicast addresses into the exact
268 * filters (RAR). If there are not enough to fill the RAR
269 * array, clear the filters.
270 */
271 for (i = mar_used_count; i < mar_total_num; i++) {
272 if (mc_addr_count) {
273 pch_gbe_mac_mar_set(hw, mc_addr_list, i);
274 mc_addr_count--;
275 mc_addr_list += PCH_GBE_ETH_ALEN;
276 } else {
277 /* Clear MAC address mask */
278 adrmask = ioread32(&hw->reg->ADDR_MASK);
279 iowrite32((adrmask | (0x0001 << i)),
280 &hw->reg->ADDR_MASK);
281 /* wait busy */
282 pch_gbe_wait_clr_bit(&hw->reg->ADDR_MASK, PCH_GBE_BUSY);
283 /* Clear MAC address */
284 iowrite32(0, &hw->reg->mac_adr[i].high);
285 iowrite32(0, &hw->reg->mac_adr[i].low);
286 }
287 }
288}
289
290/**
291 * pch_gbe_mac_force_mac_fc - Force the MAC's flow control settings
292 * @hw: Pointer to the HW structure
293 * Returns
294 * 0: Successful.
295 * Negative value: Failed.
296 */
297s32 pch_gbe_mac_force_mac_fc(struct pch_gbe_hw *hw)
298{
299 struct pch_gbe_mac_info *mac = &hw->mac;
300 u32 rx_fctrl;
301
302 pr_debug("mac->fc = %u\n", mac->fc);
303
304 rx_fctrl = ioread32(&hw->reg->RX_FCTRL);
305
306 switch (mac->fc) {
307 case PCH_GBE_FC_NONE:
308 rx_fctrl &= ~PCH_GBE_FL_CTRL_EN;
309 mac->tx_fc_enable = false;
310 break;
311 case PCH_GBE_FC_RX_PAUSE:
312 rx_fctrl |= PCH_GBE_FL_CTRL_EN;
313 mac->tx_fc_enable = false;
314 break;
315 case PCH_GBE_FC_TX_PAUSE:
316 rx_fctrl &= ~PCH_GBE_FL_CTRL_EN;
317 mac->tx_fc_enable = true;
318 break;
319 case PCH_GBE_FC_FULL:
320 rx_fctrl |= PCH_GBE_FL_CTRL_EN;
321 mac->tx_fc_enable = true;
322 break;
323 default:
324 pr_err("Flow control param set incorrectly\n");
325 return -EINVAL;
326 }
327 if (mac->link_duplex == DUPLEX_HALF)
328 rx_fctrl &= ~PCH_GBE_FL_CTRL_EN;
329 iowrite32(rx_fctrl, &hw->reg->RX_FCTRL);
330 pr_debug("RX_FCTRL reg : 0x%08x mac->tx_fc_enable : %d\n",
331 ioread32(&hw->reg->RX_FCTRL), mac->tx_fc_enable);
332 return 0;
333}
334
335/**
336 * pch_gbe_mac_set_wol_event - Set wake-on-lan event
337 * @hw: Pointer to the HW structure
338 * @wu_evt: Wake up event
339 */
340static void pch_gbe_mac_set_wol_event(struct pch_gbe_hw *hw, u32 wu_evt)
341{
342 u32 addr_mask;
343
344 pr_debug("wu_evt : 0x%08x ADDR_MASK reg : 0x%08x\n",
345 wu_evt, ioread32(&hw->reg->ADDR_MASK));
346
347 if (wu_evt) {
348 /* Set Wake-On-Lan address mask */
349 addr_mask = ioread32(&hw->reg->ADDR_MASK);
350 iowrite32(addr_mask, &hw->reg->WOL_ADDR_MASK);
351 /* wait busy */
352 pch_gbe_wait_clr_bit(&hw->reg->WOL_ADDR_MASK, PCH_GBE_WLA_BUSY);
353 iowrite32(0, &hw->reg->WOL_ST);
354 iowrite32((wu_evt | PCH_GBE_WLC_WOL_MODE), &hw->reg->WOL_CTRL);
355 iowrite32(0x02, &hw->reg->TCPIP_ACC);
356 iowrite32(PCH_GBE_INT_ENABLE_MASK, &hw->reg->INT_EN);
357 } else {
358 iowrite32(0, &hw->reg->WOL_CTRL);
359 iowrite32(0, &hw->reg->WOL_ST);
360 }
361 return;
362}
363
364/**
365 * pch_gbe_mac_ctrl_miim - Control MIIM interface
366 * @hw: Pointer to the HW structure
367 * @addr: Address of PHY
368 * @dir: Operetion. (Write or Read)
369 * @reg: Access register of PHY
370 * @data: Write data.
371 *
372 * Returns: Read date.
373 */
374u16 pch_gbe_mac_ctrl_miim(struct pch_gbe_hw *hw, u32 addr, u32 dir, u32 reg,
375 u16 data)
376{
377 u32 data_out = 0;
378 unsigned int i;
379 unsigned long flags;
380
381 spin_lock_irqsave(&hw->miim_lock, flags);
382
383 for (i = 100; i; --i) {
384 if ((ioread32(&hw->reg->MIIM) & PCH_GBE_MIIM_OPER_READY))
385 break;
386 udelay(20);
387 }
388 if (i == 0) {
389 pr_err("pch-gbe.miim won't go Ready\n");
390 spin_unlock_irqrestore(&hw->miim_lock, flags);
391 return 0; /* No way to indicate timeout error */
392 }
393 iowrite32(((reg << PCH_GBE_MIIM_REG_ADDR_SHIFT) |
394 (addr << PCH_GBE_MIIM_PHY_ADDR_SHIFT) |
395 dir | data), &hw->reg->MIIM);
396 for (i = 0; i < 100; i++) {
397 udelay(20);
398 data_out = ioread32(&hw->reg->MIIM);
399 if ((data_out & PCH_GBE_MIIM_OPER_READY))
400 break;
401 }
402 spin_unlock_irqrestore(&hw->miim_lock, flags);
403
404 pr_debug("PHY %s: reg=%d, data=0x%04X\n",
405 dir == PCH_GBE_MIIM_OPER_READ ? "READ" : "WRITE", reg,
406 dir == PCH_GBE_MIIM_OPER_READ ? data_out : data);
407 return (u16) data_out;
408}
409
410/**
411 * pch_gbe_mac_set_pause_packet - Set pause packet
412 * @hw: Pointer to the HW structure
413 */
414static void pch_gbe_mac_set_pause_packet(struct pch_gbe_hw *hw)
415{
416 unsigned long tmp2, tmp3;
417
418 /* Set Pause packet */
419 tmp2 = hw->mac.addr[1];
420 tmp2 = (tmp2 << 8) | hw->mac.addr[0];
421 tmp2 = PCH_GBE_PAUSE_PKT2_VALUE | (tmp2 << 16);
422
423 tmp3 = hw->mac.addr[5];
424 tmp3 = (tmp3 << 8) | hw->mac.addr[4];
425 tmp3 = (tmp3 << 8) | hw->mac.addr[3];
426 tmp3 = (tmp3 << 8) | hw->mac.addr[2];
427
428 iowrite32(PCH_GBE_PAUSE_PKT1_VALUE, &hw->reg->PAUSE_PKT1);
429 iowrite32(tmp2, &hw->reg->PAUSE_PKT2);
430 iowrite32(tmp3, &hw->reg->PAUSE_PKT3);
431 iowrite32(PCH_GBE_PAUSE_PKT4_VALUE, &hw->reg->PAUSE_PKT4);
432 iowrite32(PCH_GBE_PAUSE_PKT5_VALUE, &hw->reg->PAUSE_PKT5);
433
434 /* Transmit Pause Packet */
435 iowrite32(PCH_GBE_PS_PKT_RQ, &hw->reg->PAUSE_REQ);
436
437 pr_debug("PAUSE_PKT1-5 reg : 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
438 ioread32(&hw->reg->PAUSE_PKT1), ioread32(&hw->reg->PAUSE_PKT2),
439 ioread32(&hw->reg->PAUSE_PKT3), ioread32(&hw->reg->PAUSE_PKT4),
440 ioread32(&hw->reg->PAUSE_PKT5));
441
442 return;
443}
444
445
446/**
447 * pch_gbe_alloc_queues - Allocate memory for all rings
448 * @adapter: Board private structure to initialize
449 * Returns
450 * 0: Successfully
451 * Negative value: Failed
452 */
453static int pch_gbe_alloc_queues(struct pch_gbe_adapter *adapter)
454{
455 int size;
456
457 size = (int)sizeof(struct pch_gbe_tx_ring);
458 adapter->tx_ring = kzalloc(size, GFP_KERNEL);
459 if (!adapter->tx_ring)
460 return -ENOMEM;
461 size = (int)sizeof(struct pch_gbe_rx_ring);
462 adapter->rx_ring = kzalloc(size, GFP_KERNEL);
463 if (!adapter->rx_ring) {
464 kfree(adapter->tx_ring);
465 return -ENOMEM;
466 }
467 return 0;
468}
469
470/**
471 * pch_gbe_init_stats - Initialize status
472 * @adapter: Board private structure to initialize
473 */
474static void pch_gbe_init_stats(struct pch_gbe_adapter *adapter)
475{
476 memset(&adapter->stats, 0, sizeof(adapter->stats));
477 return;
478}
479
480/**
481 * pch_gbe_init_phy - Initialize PHY
482 * @adapter: Board private structure to initialize
483 * Returns
484 * 0: Successfully
485 * Negative value: Failed
486 */
487static int pch_gbe_init_phy(struct pch_gbe_adapter *adapter)
488{
489 struct net_device *netdev = adapter->netdev;
490 u32 addr;
491 u16 bmcr, stat;
492
493 /* Discover phy addr by searching addrs in order {1,0,2,..., 31} */
494 for (addr = 0; addr < PCH_GBE_PHY_REGS_LEN; addr++) {
495 adapter->mii.phy_id = (addr == 0) ? 1 : (addr == 1) ? 0 : addr;
496 bmcr = pch_gbe_mdio_read(netdev, adapter->mii.phy_id, MII_BMCR);
497 stat = pch_gbe_mdio_read(netdev, adapter->mii.phy_id, MII_BMSR);
498 stat = pch_gbe_mdio_read(netdev, adapter->mii.phy_id, MII_BMSR);
499 if (!((bmcr == 0xFFFF) || ((stat == 0) && (bmcr == 0))))
500 break;
501 }
502 adapter->hw.phy.addr = adapter->mii.phy_id;
503 pr_debug("phy_addr = %d\n", adapter->mii.phy_id);
504 if (addr == 32)
505 return -EAGAIN;
506 /* Selected the phy and isolate the rest */
507 for (addr = 0; addr < PCH_GBE_PHY_REGS_LEN; addr++) {
508 if (addr != adapter->mii.phy_id) {
509 pch_gbe_mdio_write(netdev, addr, MII_BMCR,
510 BMCR_ISOLATE);
511 } else {
512 bmcr = pch_gbe_mdio_read(netdev, addr, MII_BMCR);
513 pch_gbe_mdio_write(netdev, addr, MII_BMCR,
514 bmcr & ~BMCR_ISOLATE);
515 }
516 }
517
518 /* MII setup */
519 adapter->mii.phy_id_mask = 0x1F;
520 adapter->mii.reg_num_mask = 0x1F;
521 adapter->mii.dev = adapter->netdev;
522 adapter->mii.mdio_read = pch_gbe_mdio_read;
523 adapter->mii.mdio_write = pch_gbe_mdio_write;
524 adapter->mii.supports_gmii = mii_check_gmii_support(&adapter->mii);
525 return 0;
526}
527
528/**
529 * pch_gbe_mdio_read - The read function for mii
530 * @netdev: Network interface device structure
531 * @addr: Phy ID
532 * @reg: Access location
533 * Returns
534 * 0: Successfully
535 * Negative value: Failed
536 */
537static int pch_gbe_mdio_read(struct net_device *netdev, int addr, int reg)
538{
539 struct pch_gbe_adapter *adapter = netdev_priv(netdev);
540 struct pch_gbe_hw *hw = &adapter->hw;
541
542 return pch_gbe_mac_ctrl_miim(hw, addr, PCH_GBE_HAL_MIIM_READ, reg,
543 (u16) 0);
544}
545
546/**
547 * pch_gbe_mdio_write - The write function for mii
548 * @netdev: Network interface device structure
549 * @addr: Phy ID (not used)
550 * @reg: Access location
551 * @data: Write data
552 */
553static void pch_gbe_mdio_write(struct net_device *netdev,
554 int addr, int reg, int data)
555{
556 struct pch_gbe_adapter *adapter = netdev_priv(netdev);
557 struct pch_gbe_hw *hw = &adapter->hw;
558
559 pch_gbe_mac_ctrl_miim(hw, addr, PCH_GBE_HAL_MIIM_WRITE, reg, data);
560}
561
562/**
563 * pch_gbe_reset_task - Reset processing at the time of transmission timeout
564 * @work: Pointer of board private structure
565 */
566static void pch_gbe_reset_task(struct work_struct *work)
567{
568 struct pch_gbe_adapter *adapter;
569 adapter = container_of(work, struct pch_gbe_adapter, reset_task);
570
571 rtnl_lock();
572 pch_gbe_reinit_locked(adapter);
573 rtnl_unlock();
574}
575
576/**
577 * pch_gbe_reinit_locked- Re-initialization
578 * @adapter: Board private structure
579 */
580void pch_gbe_reinit_locked(struct pch_gbe_adapter *adapter)
581{
582 pch_gbe_down(adapter);
583 pch_gbe_up(adapter);
584}
585
586/**
587 * pch_gbe_reset - Reset GbE
588 * @adapter: Board private structure
589 */
590void pch_gbe_reset(struct pch_gbe_adapter *adapter)
591{
592 pch_gbe_mac_reset_hw(&adapter->hw);
593 /* Setup the receive address. */
594 pch_gbe_mac_init_rx_addrs(&adapter->hw, PCH_GBE_MAR_ENTRIES);
595 if (pch_gbe_hal_init_hw(&adapter->hw))
596 pr_err("Hardware Error\n");
597}
598
599/**
600 * pch_gbe_free_irq - Free an interrupt
601 * @adapter: Board private structure
602 */
603static void pch_gbe_free_irq(struct pch_gbe_adapter *adapter)
604{
605 struct net_device *netdev = adapter->netdev;
606
607 free_irq(adapter->pdev->irq, netdev);
608 if (adapter->have_msi) {
609 pci_disable_msi(adapter->pdev);
610 pr_debug("call pci_disable_msi\n");
611 }
612}
613
614/**
615 * pch_gbe_irq_disable - Mask off interrupt generation on the NIC
616 * @adapter: Board private structure
617 */
618static void pch_gbe_irq_disable(struct pch_gbe_adapter *adapter)
619{
620 struct pch_gbe_hw *hw = &adapter->hw;
621
622 atomic_inc(&adapter->irq_sem);
623 iowrite32(0, &hw->reg->INT_EN);
624 ioread32(&hw->reg->INT_ST);
625 synchronize_irq(adapter->pdev->irq);
626
627 pr_debug("INT_EN reg : 0x%08x\n", ioread32(&hw->reg->INT_EN));
628}
629
630/**
631 * pch_gbe_irq_enable - Enable default interrupt generation settings
632 * @adapter: Board private structure
633 */
634static void pch_gbe_irq_enable(struct pch_gbe_adapter *adapter)
635{
636 struct pch_gbe_hw *hw = &adapter->hw;
637
638 if (likely(atomic_dec_and_test(&adapter->irq_sem)))
639 iowrite32(PCH_GBE_INT_ENABLE_MASK, &hw->reg->INT_EN);
640 ioread32(&hw->reg->INT_ST);
641 pr_debug("INT_EN reg : 0x%08x\n", ioread32(&hw->reg->INT_EN));
642}
643
644
645
646/**
647 * pch_gbe_setup_tctl - configure the Transmit control registers
648 * @adapter: Board private structure
649 */
650static void pch_gbe_setup_tctl(struct pch_gbe_adapter *adapter)
651{
652 struct pch_gbe_hw *hw = &adapter->hw;
653 u32 tx_mode, tcpip;
654
655 tx_mode = PCH_GBE_TM_LONG_PKT |
656 PCH_GBE_TM_ST_AND_FD |
657 PCH_GBE_TM_SHORT_PKT |
658 PCH_GBE_TM_TH_TX_STRT_8 |
659 PCH_GBE_TM_TH_ALM_EMP_4 | PCH_GBE_TM_TH_ALM_FULL_8;
660
661 iowrite32(tx_mode, &hw->reg->TX_MODE);
662
663 tcpip = ioread32(&hw->reg->TCPIP_ACC);
664 tcpip |= PCH_GBE_TX_TCPIPACC_EN;
665 iowrite32(tcpip, &hw->reg->TCPIP_ACC);
666 return;
667}
668
669/**
670 * pch_gbe_configure_tx - Configure Transmit Unit after Reset
671 * @adapter: Board private structure
672 */
673static void pch_gbe_configure_tx(struct pch_gbe_adapter *adapter)
674{
675 struct pch_gbe_hw *hw = &adapter->hw;
676 u32 tdba, tdlen, dctrl;
677
678 pr_debug("dma addr = 0x%08llx size = 0x%08x\n",
679 (unsigned long long)adapter->tx_ring->dma,
680 adapter->tx_ring->size);
681
682 /* Setup the HW Tx Head and Tail descriptor pointers */
683 tdba = adapter->tx_ring->dma;
684 tdlen = adapter->tx_ring->size - 0x10;
685 iowrite32(tdba, &hw->reg->TX_DSC_BASE);
686 iowrite32(tdlen, &hw->reg->TX_DSC_SIZE);
687 iowrite32(tdba, &hw->reg->TX_DSC_SW_P);
688
689 /* Enables Transmission DMA */
690 dctrl = ioread32(&hw->reg->DMA_CTRL);
691 dctrl |= PCH_GBE_TX_DMA_EN;
692 iowrite32(dctrl, &hw->reg->DMA_CTRL);
693}
694
695/**
696 * pch_gbe_setup_rctl - Configure the receive control registers
697 * @adapter: Board private structure
698 */
699static void pch_gbe_setup_rctl(struct pch_gbe_adapter *adapter)
700{
701 struct net_device *netdev = adapter->netdev;
702 struct pch_gbe_hw *hw = &adapter->hw;
703 u32 rx_mode, tcpip;
704
705 rx_mode = PCH_GBE_ADD_FIL_EN | PCH_GBE_MLT_FIL_EN |
706 PCH_GBE_RH_ALM_EMP_4 | PCH_GBE_RH_ALM_FULL_4 | PCH_GBE_RH_RD_TRG_8;
707
708 iowrite32(rx_mode, &hw->reg->RX_MODE);
709
710 tcpip = ioread32(&hw->reg->TCPIP_ACC);
711
712 tcpip |= PCH_GBE_RX_TCPIPACC_OFF;
713 tcpip &= ~PCH_GBE_RX_TCPIPACC_EN;
714 iowrite32(tcpip, &hw->reg->TCPIP_ACC);
715 return;
716}
717
718/**
719 * pch_gbe_configure_rx - Configure Receive Unit after Reset
720 * @adapter: Board private structure
721 */
722static void pch_gbe_configure_rx(struct pch_gbe_adapter *adapter)
723{
724 struct pch_gbe_hw *hw = &adapter->hw;
725 u32 rdba, rdlen, rctl, rxdma;
726
727 pr_debug("dma adr = 0x%08llx size = 0x%08x\n",
728 (unsigned long long)adapter->rx_ring->dma,
729 adapter->rx_ring->size);
730
731 pch_gbe_mac_force_mac_fc(hw);
732
733 /* Disables Receive MAC */
734 rctl = ioread32(&hw->reg->MAC_RX_EN);
735 iowrite32((rctl & ~PCH_GBE_MRE_MAC_RX_EN), &hw->reg->MAC_RX_EN);
736
737 /* Disables Receive DMA */
738 rxdma = ioread32(&hw->reg->DMA_CTRL);
739 rxdma &= ~PCH_GBE_RX_DMA_EN;
740 iowrite32(rxdma, &hw->reg->DMA_CTRL);
741
742 pr_debug("MAC_RX_EN reg = 0x%08x DMA_CTRL reg = 0x%08x\n",
743 ioread32(&hw->reg->MAC_RX_EN),
744 ioread32(&hw->reg->DMA_CTRL));
745
746 /* Setup the HW Rx Head and Tail Descriptor Pointers and
747 * the Base and Length of the Rx Descriptor Ring */
748 rdba = adapter->rx_ring->dma;
749 rdlen = adapter->rx_ring->size - 0x10;
750 iowrite32(rdba, &hw->reg->RX_DSC_BASE);
751 iowrite32(rdlen, &hw->reg->RX_DSC_SIZE);
752 iowrite32((rdba + rdlen), &hw->reg->RX_DSC_SW_P);
753}
754
755/**
756 * pch_gbe_unmap_and_free_tx_resource - Unmap and free tx socket buffer
757 * @adapter: Board private structure
758 * @buffer_info: Buffer information structure
759 */
760static void pch_gbe_unmap_and_free_tx_resource(
761 struct pch_gbe_adapter *adapter, struct pch_gbe_buffer *buffer_info)
762{
763 if (buffer_info->mapped) {
764 dma_unmap_single(&adapter->pdev->dev, buffer_info->dma,
765 buffer_info->length, DMA_TO_DEVICE);
766 buffer_info->mapped = false;
767 }
768 if (buffer_info->skb) {
769 dev_kfree_skb_any(buffer_info->skb);
770 buffer_info->skb = NULL;
771 }
772}
773
774/**
775 * pch_gbe_unmap_and_free_rx_resource - Unmap and free rx socket buffer
776 * @adapter: Board private structure
777 * @buffer_info: Buffer information structure
778 */
779static void pch_gbe_unmap_and_free_rx_resource(
780 struct pch_gbe_adapter *adapter,
781 struct pch_gbe_buffer *buffer_info)
782{
783 if (buffer_info->mapped) {
784 dma_unmap_single(&adapter->pdev->dev, buffer_info->dma,
785 buffer_info->length, DMA_FROM_DEVICE);
786 buffer_info->mapped = false;
787 }
788 if (buffer_info->skb) {
789 dev_kfree_skb_any(buffer_info->skb);
790 buffer_info->skb = NULL;
791 }
792}
793
794/**
795 * pch_gbe_clean_tx_ring - Free Tx Buffers
796 * @adapter: Board private structure
797 * @tx_ring: Ring to be cleaned
798 */
799static void pch_gbe_clean_tx_ring(struct pch_gbe_adapter *adapter,
800 struct pch_gbe_tx_ring *tx_ring)
801{
802 struct pch_gbe_hw *hw = &adapter->hw;
803 struct pch_gbe_buffer *buffer_info;
804 unsigned long size;
805 unsigned int i;
806
807 /* Free all the Tx ring sk_buffs */
808 for (i = 0; i < tx_ring->count; i++) {
809 buffer_info = &tx_ring->buffer_info[i];
810 pch_gbe_unmap_and_free_tx_resource(adapter, buffer_info);
811 }
812 pr_debug("call pch_gbe_unmap_and_free_tx_resource() %d count\n", i);
813
814 size = (unsigned long)sizeof(struct pch_gbe_buffer) * tx_ring->count;
815 memset(tx_ring->buffer_info, 0, size);
816
817 /* Zero out the descriptor ring */
818 memset(tx_ring->desc, 0, tx_ring->size);
819 tx_ring->next_to_use = 0;
820 tx_ring->next_to_clean = 0;
821 iowrite32(tx_ring->dma, &hw->reg->TX_DSC_HW_P);
822 iowrite32((tx_ring->size - 0x10), &hw->reg->TX_DSC_SIZE);
823}
824
825/**
826 * pch_gbe_clean_rx_ring - Free Rx Buffers
827 * @adapter: Board private structure
828 * @rx_ring: Ring to free buffers from
829 */
830static void
831pch_gbe_clean_rx_ring(struct pch_gbe_adapter *adapter,
832 struct pch_gbe_rx_ring *rx_ring)
833{
834 struct pch_gbe_hw *hw = &adapter->hw;
835 struct pch_gbe_buffer *buffer_info;
836 unsigned long size;
837 unsigned int i;
838
839 /* Free all the Rx ring sk_buffs */
840 for (i = 0; i < rx_ring->count; i++) {
841 buffer_info = &rx_ring->buffer_info[i];
842 pch_gbe_unmap_and_free_rx_resource(adapter, buffer_info);
843 }
844 pr_debug("call pch_gbe_unmap_and_free_rx_resource() %d count\n", i);
845 size = (unsigned long)sizeof(struct pch_gbe_buffer) * rx_ring->count;
846 memset(rx_ring->buffer_info, 0, size);
847
848 /* Zero out the descriptor ring */
849 memset(rx_ring->desc, 0, rx_ring->size);
850 rx_ring->next_to_clean = 0;
851 rx_ring->next_to_use = 0;
852 iowrite32(rx_ring->dma, &hw->reg->RX_DSC_HW_P);
853 iowrite32((rx_ring->size - 0x10), &hw->reg->RX_DSC_SIZE);
854}
855
856static void pch_gbe_set_rgmii_ctrl(struct pch_gbe_adapter *adapter, u16 speed,
857 u16 duplex)
858{
859 struct pch_gbe_hw *hw = &adapter->hw;
860 unsigned long rgmii = 0;
861
862 /* Set the RGMII control. */
863#ifdef PCH_GBE_MAC_IFOP_RGMII
864 switch (speed) {
865 case SPEED_10:
866 rgmii = (PCH_GBE_RGMII_RATE_2_5M |
867 PCH_GBE_MAC_RGMII_CTRL_SETTING);
868 break;
869 case SPEED_100:
870 rgmii = (PCH_GBE_RGMII_RATE_25M |
871 PCH_GBE_MAC_RGMII_CTRL_SETTING);
872 break;
873 case SPEED_1000:
874 rgmii = (PCH_GBE_RGMII_RATE_125M |
875 PCH_GBE_MAC_RGMII_CTRL_SETTING);
876 break;
877 }
878 iowrite32(rgmii, &hw->reg->RGMII_CTRL);
879#else /* GMII */
880 rgmii = 0;
881 iowrite32(rgmii, &hw->reg->RGMII_CTRL);
882#endif
883}
884static void pch_gbe_set_mode(struct pch_gbe_adapter *adapter, u16 speed,
885 u16 duplex)
886{
887 struct net_device *netdev = adapter->netdev;
888 struct pch_gbe_hw *hw = &adapter->hw;
889 unsigned long mode = 0;
890
891 /* Set the communication mode */
892 switch (speed) {
893 case SPEED_10:
894 mode = PCH_GBE_MODE_MII_ETHER;
895 netdev->tx_queue_len = 10;
896 break;
897 case SPEED_100:
898 mode = PCH_GBE_MODE_MII_ETHER;
899 netdev->tx_queue_len = 100;
900 break;
901 case SPEED_1000:
902 mode = PCH_GBE_MODE_GMII_ETHER;
903 break;
904 }
905 if (duplex == DUPLEX_FULL)
906 mode |= PCH_GBE_MODE_FULL_DUPLEX;
907 else
908 mode |= PCH_GBE_MODE_HALF_DUPLEX;
909 iowrite32(mode, &hw->reg->MODE);
910}
911
912/**
913 * pch_gbe_watchdog - Watchdog process
914 * @data: Board private structure
915 */
916static void pch_gbe_watchdog(unsigned long data)
917{
918 struct pch_gbe_adapter *adapter = (struct pch_gbe_adapter *)data;
919 struct net_device *netdev = adapter->netdev;
920 struct pch_gbe_hw *hw = &adapter->hw;
921
922 pr_debug("right now = %ld\n", jiffies);
923
924 pch_gbe_update_stats(adapter);
925 if ((mii_link_ok(&adapter->mii)) && (!netif_carrier_ok(netdev))) {
926 struct ethtool_cmd cmd = { .cmd = ETHTOOL_GSET };
927 netdev->tx_queue_len = adapter->tx_queue_len;
928 /* mii library handles link maintenance tasks */
929 if (mii_ethtool_gset(&adapter->mii, &cmd)) {
930 pr_err("ethtool get setting Error\n");
931 mod_timer(&adapter->watchdog_timer,
932 round_jiffies(jiffies +
933 PCH_GBE_WATCHDOG_PERIOD));
934 return;
935 }
936 hw->mac.link_speed = ethtool_cmd_speed(&cmd);
937 hw->mac.link_duplex = cmd.duplex;
938 /* Set the RGMII control. */
939 pch_gbe_set_rgmii_ctrl(adapter, hw->mac.link_speed,
940 hw->mac.link_duplex);
941 /* Set the communication mode */
942 pch_gbe_set_mode(adapter, hw->mac.link_speed,
943 hw->mac.link_duplex);
944 netdev_dbg(netdev,
945 "Link is Up %d Mbps %s-Duplex\n",
946 hw->mac.link_speed,
947 cmd.duplex == DUPLEX_FULL ? "Full" : "Half");
948 netif_carrier_on(netdev);
949 netif_wake_queue(netdev);
950 } else if ((!mii_link_ok(&adapter->mii)) &&
951 (netif_carrier_ok(netdev))) {
952 netdev_dbg(netdev, "NIC Link is Down\n");
953 hw->mac.link_speed = SPEED_10;
954 hw->mac.link_duplex = DUPLEX_HALF;
955 netif_carrier_off(netdev);
956 netif_stop_queue(netdev);
957 }
958 mod_timer(&adapter->watchdog_timer,
959 round_jiffies(jiffies + PCH_GBE_WATCHDOG_PERIOD));
960}
961
962/**
963 * pch_gbe_tx_queue - Carry out queuing of the transmission data
964 * @adapter: Board private structure
965 * @tx_ring: Tx descriptor ring structure
966 * @skb: Sockt buffer structure
967 */
968static void pch_gbe_tx_queue(struct pch_gbe_adapter *adapter,
969 struct pch_gbe_tx_ring *tx_ring,
970 struct sk_buff *skb)
971{
972 struct pch_gbe_hw *hw = &adapter->hw;
973 struct pch_gbe_tx_desc *tx_desc;
974 struct pch_gbe_buffer *buffer_info;
975 struct sk_buff *tmp_skb;
976 unsigned int frame_ctrl;
977 unsigned int ring_num;
978 unsigned long flags;
979
980 /*-- Set frame control --*/
981 frame_ctrl = 0;
982 if (unlikely(skb->len < PCH_GBE_SHORT_PKT))
983 frame_ctrl |= PCH_GBE_TXD_CTRL_APAD;
984 if (skb->ip_summed == CHECKSUM_NONE)
985 frame_ctrl |= PCH_GBE_TXD_CTRL_TCPIP_ACC_OFF;
986
987 /* Performs checksum processing */
988 /*
989 * It is because the hardware accelerator does not support a checksum,
990 * when the received data size is less than 64 bytes.
991 */
992 if (skb->len < PCH_GBE_SHORT_PKT && skb->ip_summed != CHECKSUM_NONE) {
993 frame_ctrl |= PCH_GBE_TXD_CTRL_APAD |
994 PCH_GBE_TXD_CTRL_TCPIP_ACC_OFF;
995 if (skb->protocol == htons(ETH_P_IP)) {
996 struct iphdr *iph = ip_hdr(skb);
997 unsigned int offset;
998 iph->check = 0;
999 iph->check = ip_fast_csum((u8 *) iph, iph->ihl);
1000 offset = skb_transport_offset(skb);
1001 if (iph->protocol == IPPROTO_TCP) {
1002 skb->csum = 0;
1003 tcp_hdr(skb)->check = 0;
1004 skb->csum = skb_checksum(skb, offset,
1005 skb->len - offset, 0);
1006 tcp_hdr(skb)->check =
1007 csum_tcpudp_magic(iph->saddr,
1008 iph->daddr,
1009 skb->len - offset,
1010 IPPROTO_TCP,
1011 skb->csum);
1012 } else if (iph->protocol == IPPROTO_UDP) {
1013 skb->csum = 0;
1014 udp_hdr(skb)->check = 0;
1015 skb->csum =
1016 skb_checksum(skb, offset,
1017 skb->len - offset, 0);
1018 udp_hdr(skb)->check =
1019 csum_tcpudp_magic(iph->saddr,
1020 iph->daddr,
1021 skb->len - offset,
1022 IPPROTO_UDP,
1023 skb->csum);
1024 }
1025 }
1026 }
1027 spin_lock_irqsave(&tx_ring->tx_lock, flags);
1028 ring_num = tx_ring->next_to_use;
1029 if (unlikely((ring_num + 1) == tx_ring->count))
1030 tx_ring->next_to_use = 0;
1031 else
1032 tx_ring->next_to_use = ring_num + 1;
1033
1034 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
1035 buffer_info = &tx_ring->buffer_info[ring_num];
1036 tmp_skb = buffer_info->skb;
1037
1038 /* [Header:14][payload] ---> [Header:14][paddong:2][payload] */
1039 memcpy(tmp_skb->data, skb->data, ETH_HLEN);
1040 tmp_skb->data[ETH_HLEN] = 0x00;
1041 tmp_skb->data[ETH_HLEN + 1] = 0x00;
1042 tmp_skb->len = skb->len;
1043 memcpy(&tmp_skb->data[ETH_HLEN + 2], &skb->data[ETH_HLEN],
1044 (skb->len - ETH_HLEN));
1045 /*-- Set Buffer information --*/
1046 buffer_info->length = tmp_skb->len;
1047 buffer_info->dma = dma_map_single(&adapter->pdev->dev, tmp_skb->data,
1048 buffer_info->length,
1049 DMA_TO_DEVICE);
1050 if (dma_mapping_error(&adapter->pdev->dev, buffer_info->dma)) {
1051 pr_err("TX DMA map failed\n");
1052 buffer_info->dma = 0;
1053 buffer_info->time_stamp = 0;
1054 tx_ring->next_to_use = ring_num;
1055 return;
1056 }
1057 buffer_info->mapped = true;
1058 buffer_info->time_stamp = jiffies;
1059
1060 /*-- Set Tx descriptor --*/
1061 tx_desc = PCH_GBE_TX_DESC(*tx_ring, ring_num);
1062 tx_desc->buffer_addr = (buffer_info->dma);
1063 tx_desc->length = (tmp_skb->len);
1064 tx_desc->tx_words_eob = ((tmp_skb->len + 3));
1065 tx_desc->tx_frame_ctrl = (frame_ctrl);
1066 tx_desc->gbec_status = (DSC_INIT16);
1067
1068 if (unlikely(++ring_num == tx_ring->count))
1069 ring_num = 0;
1070
1071 /* Update software pointer of TX descriptor */
1072 iowrite32(tx_ring->dma +
1073 (int)sizeof(struct pch_gbe_tx_desc) * ring_num,
1074 &hw->reg->TX_DSC_SW_P);
1075 dev_kfree_skb_any(skb);
1076}
1077
1078/**
1079 * pch_gbe_update_stats - Update the board statistics counters
1080 * @adapter: Board private structure
1081 */
1082void pch_gbe_update_stats(struct pch_gbe_adapter *adapter)
1083{
1084 struct net_device *netdev = adapter->netdev;
1085 struct pci_dev *pdev = adapter->pdev;
1086 struct pch_gbe_hw_stats *stats = &adapter->stats;
1087 unsigned long flags;
1088
1089 /*
1090 * Prevent stats update while adapter is being reset, or if the pci
1091 * connection is down.
1092 */
1093 if ((pdev->error_state) && (pdev->error_state != pci_channel_io_normal))
1094 return;
1095
1096 spin_lock_irqsave(&adapter->stats_lock, flags);
1097
1098 /* Update device status "adapter->stats" */
1099 stats->rx_errors = stats->rx_crc_errors + stats->rx_frame_errors;
1100 stats->tx_errors = stats->tx_length_errors +
1101 stats->tx_aborted_errors +
1102 stats->tx_carrier_errors + stats->tx_timeout_count;
1103
1104 /* Update network device status "adapter->net_stats" */
1105 netdev->stats.rx_packets = stats->rx_packets;
1106 netdev->stats.rx_bytes = stats->rx_bytes;
1107 netdev->stats.rx_dropped = stats->rx_dropped;
1108 netdev->stats.tx_packets = stats->tx_packets;
1109 netdev->stats.tx_bytes = stats->tx_bytes;
1110 netdev->stats.tx_dropped = stats->tx_dropped;
1111 /* Fill out the OS statistics structure */
1112 netdev->stats.multicast = stats->multicast;
1113 netdev->stats.collisions = stats->collisions;
1114 /* Rx Errors */
1115 netdev->stats.rx_errors = stats->rx_errors;
1116 netdev->stats.rx_crc_errors = stats->rx_crc_errors;
1117 netdev->stats.rx_frame_errors = stats->rx_frame_errors;
1118 /* Tx Errors */
1119 netdev->stats.tx_errors = stats->tx_errors;
1120 netdev->stats.tx_aborted_errors = stats->tx_aborted_errors;
1121 netdev->stats.tx_carrier_errors = stats->tx_carrier_errors;
1122
1123 spin_unlock_irqrestore(&adapter->stats_lock, flags);
1124}
1125
1126static void pch_gbe_stop_receive(struct pch_gbe_adapter *adapter)
1127{
1128 struct pch_gbe_hw *hw = &adapter->hw;
1129 u32 rxdma;
1130 u16 value;
1131 int ret;
1132
1133 /* Disable Receive DMA */
1134 rxdma = ioread32(&hw->reg->DMA_CTRL);
1135 rxdma &= ~PCH_GBE_RX_DMA_EN;
1136 iowrite32(rxdma, &hw->reg->DMA_CTRL);
1137 /* Wait Rx DMA BUS is IDLE */
1138 ret = pch_gbe_wait_clr_bit_irq(&hw->reg->RX_DMA_ST, PCH_GBE_IDLE_CHECK);
1139 if (ret) {
1140 /* Disable Bus master */
1141 pci_read_config_word(adapter->pdev, PCI_COMMAND, &value);
1142 value &= ~PCI_COMMAND_MASTER;
1143 pci_write_config_word(adapter->pdev, PCI_COMMAND, value);
1144 /* Stop Receive */
1145 pch_gbe_mac_reset_rx(hw);
1146 /* Enable Bus master */
1147 value |= PCI_COMMAND_MASTER;
1148 pci_write_config_word(adapter->pdev, PCI_COMMAND, value);
1149 } else {
1150 /* Stop Receive */
1151 pch_gbe_mac_reset_rx(hw);
1152 }
1153}
1154
1155static void pch_gbe_start_receive(struct pch_gbe_hw *hw)
1156{
1157 u32 rxdma;
1158
1159 /* Enables Receive DMA */
1160 rxdma = ioread32(&hw->reg->DMA_CTRL);
1161 rxdma |= PCH_GBE_RX_DMA_EN;
1162 iowrite32(rxdma, &hw->reg->DMA_CTRL);
1163 /* Enables Receive */
1164 iowrite32(PCH_GBE_MRE_MAC_RX_EN, &hw->reg->MAC_RX_EN);
1165 return;
1166}
1167
1168/**
1169 * pch_gbe_intr - Interrupt Handler
1170 * @irq: Interrupt number
1171 * @data: Pointer to a network interface device structure
1172 * Returns
1173 * - IRQ_HANDLED: Our interrupt
1174 * - IRQ_NONE: Not our interrupt
1175 */
1176static irqreturn_t pch_gbe_intr(int irq, void *data)
1177{
1178 struct net_device *netdev = data;
1179 struct pch_gbe_adapter *adapter = netdev_priv(netdev);
1180 struct pch_gbe_hw *hw = &adapter->hw;
1181 u32 int_st;
1182 u32 int_en;
1183
1184 /* Check request status */
1185 int_st = ioread32(&hw->reg->INT_ST);
1186 int_st = int_st & ioread32(&hw->reg->INT_EN);
1187 /* When request status is no interruption factor */
1188 if (unlikely(!int_st))
1189 return IRQ_NONE; /* Not our interrupt. End processing. */
1190 pr_debug("%s occur int_st = 0x%08x\n", __func__, int_st);
1191 if (int_st & PCH_GBE_INT_RX_FRAME_ERR)
1192 adapter->stats.intr_rx_frame_err_count++;
1193 if (int_st & PCH_GBE_INT_RX_FIFO_ERR)
1194 if (!adapter->rx_stop_flag) {
1195 adapter->stats.intr_rx_fifo_err_count++;
1196 pr_debug("Rx fifo over run\n");
1197 adapter->rx_stop_flag = true;
1198 int_en = ioread32(&hw->reg->INT_EN);
1199 iowrite32((int_en & ~PCH_GBE_INT_RX_FIFO_ERR),
1200 &hw->reg->INT_EN);
1201 pch_gbe_stop_receive(adapter);
1202 int_st |= ioread32(&hw->reg->INT_ST);
1203 int_st = int_st & ioread32(&hw->reg->INT_EN);
1204 }
1205 if (int_st & PCH_GBE_INT_RX_DMA_ERR)
1206 adapter->stats.intr_rx_dma_err_count++;
1207 if (int_st & PCH_GBE_INT_TX_FIFO_ERR)
1208 adapter->stats.intr_tx_fifo_err_count++;
1209 if (int_st & PCH_GBE_INT_TX_DMA_ERR)
1210 adapter->stats.intr_tx_dma_err_count++;
1211 if (int_st & PCH_GBE_INT_TCPIP_ERR)
1212 adapter->stats.intr_tcpip_err_count++;
1213 /* When Rx descriptor is empty */
1214 if ((int_st & PCH_GBE_INT_RX_DSC_EMP)) {
1215 adapter->stats.intr_rx_dsc_empty_count++;
1216 pr_debug("Rx descriptor is empty\n");
1217 int_en = ioread32(&hw->reg->INT_EN);
1218 iowrite32((int_en & ~PCH_GBE_INT_RX_DSC_EMP), &hw->reg->INT_EN);
1219 if (hw->mac.tx_fc_enable) {
1220 /* Set Pause packet */
1221 pch_gbe_mac_set_pause_packet(hw);
1222 }
1223 }
1224
1225 /* When request status is Receive interruption */
1226 if ((int_st & (PCH_GBE_INT_RX_DMA_CMPLT | PCH_GBE_INT_TX_CMPLT)) ||
1227 (adapter->rx_stop_flag == true)) {
1228 if (likely(napi_schedule_prep(&adapter->napi))) {
1229 /* Enable only Rx Descriptor empty */
1230 atomic_inc(&adapter->irq_sem);
1231 int_en = ioread32(&hw->reg->INT_EN);
1232 int_en &=
1233 ~(PCH_GBE_INT_RX_DMA_CMPLT | PCH_GBE_INT_TX_CMPLT);
1234 iowrite32(int_en, &hw->reg->INT_EN);
1235 /* Start polling for NAPI */
1236 __napi_schedule(&adapter->napi);
1237 }
1238 }
1239 pr_debug("return = 0x%08x INT_EN reg = 0x%08x\n",
1240 IRQ_HANDLED, ioread32(&hw->reg->INT_EN));
1241 return IRQ_HANDLED;
1242}
1243
1244/**
1245 * pch_gbe_alloc_rx_buffers - Replace used receive buffers; legacy & extended
1246 * @adapter: Board private structure
1247 * @rx_ring: Rx descriptor ring
1248 * @cleaned_count: Cleaned count
1249 */
1250static void
1251pch_gbe_alloc_rx_buffers(struct pch_gbe_adapter *adapter,
1252 struct pch_gbe_rx_ring *rx_ring, int cleaned_count)
1253{
1254 struct net_device *netdev = adapter->netdev;
1255 struct pci_dev *pdev = adapter->pdev;
1256 struct pch_gbe_hw *hw = &adapter->hw;
1257 struct pch_gbe_rx_desc *rx_desc;
1258 struct pch_gbe_buffer *buffer_info;
1259 struct sk_buff *skb;
1260 unsigned int i;
1261 unsigned int bufsz;
1262
1263 bufsz = adapter->rx_buffer_len + NET_IP_ALIGN;
1264 i = rx_ring->next_to_use;
1265
1266 while ((cleaned_count--)) {
1267 buffer_info = &rx_ring->buffer_info[i];
1268 skb = netdev_alloc_skb(netdev, bufsz);
1269 if (unlikely(!skb)) {
1270 /* Better luck next round */
1271 adapter->stats.rx_alloc_buff_failed++;
1272 break;
1273 }
1274 /* align */
1275 skb_reserve(skb, NET_IP_ALIGN);
1276 buffer_info->skb = skb;
1277
1278 buffer_info->dma = dma_map_single(&pdev->dev,
1279 buffer_info->rx_buffer,
1280 buffer_info->length,
1281 DMA_FROM_DEVICE);
1282 if (dma_mapping_error(&adapter->pdev->dev, buffer_info->dma)) {
1283 dev_kfree_skb(skb);
1284 buffer_info->skb = NULL;
1285 buffer_info->dma = 0;
1286 adapter->stats.rx_alloc_buff_failed++;
1287 break; /* while !buffer_info->skb */
1288 }
1289 buffer_info->mapped = true;
1290 rx_desc = PCH_GBE_RX_DESC(*rx_ring, i);
1291 rx_desc->buffer_addr = (buffer_info->dma);
1292 rx_desc->gbec_status = DSC_INIT16;
1293
1294 pr_debug("i = %d buffer_info->dma = 0x08%llx buffer_info->length = 0x%x\n",
1295 i, (unsigned long long)buffer_info->dma,
1296 buffer_info->length);
1297
1298 if (unlikely(++i == rx_ring->count))
1299 i = 0;
1300 }
1301 if (likely(rx_ring->next_to_use != i)) {
1302 rx_ring->next_to_use = i;
1303 if (unlikely(i-- == 0))
1304 i = (rx_ring->count - 1);
1305 iowrite32(rx_ring->dma +
1306 (int)sizeof(struct pch_gbe_rx_desc) * i,
1307 &hw->reg->RX_DSC_SW_P);
1308 }
1309 return;
1310}
1311
1312static int
1313pch_gbe_alloc_rx_buffers_pool(struct pch_gbe_adapter *adapter,
1314 struct pch_gbe_rx_ring *rx_ring, int cleaned_count)
1315{
1316 struct pci_dev *pdev = adapter->pdev;
1317 struct pch_gbe_buffer *buffer_info;
1318 unsigned int i;
1319 unsigned int bufsz;
1320 unsigned int size;
1321
1322 bufsz = adapter->rx_buffer_len;
1323
1324 size = rx_ring->count * bufsz + PCH_GBE_RESERVE_MEMORY;
1325 rx_ring->rx_buff_pool = dma_alloc_coherent(&pdev->dev, size,
1326 &rx_ring->rx_buff_pool_logic,
1327 GFP_KERNEL);
1328 if (!rx_ring->rx_buff_pool) {
1329 pr_err("Unable to allocate memory for the receive poll buffer\n");
1330 return -ENOMEM;
1331 }
1332 memset(rx_ring->rx_buff_pool, 0, size);
1333 rx_ring->rx_buff_pool_size = size;
1334 for (i = 0; i < rx_ring->count; i++) {
1335 buffer_info = &rx_ring->buffer_info[i];
1336 buffer_info->rx_buffer = rx_ring->rx_buff_pool + bufsz * i;
1337 buffer_info->length = bufsz;
1338 }
1339 return 0;
1340}
1341
1342/**
1343 * pch_gbe_alloc_tx_buffers - Allocate transmit buffers
1344 * @adapter: Board private structure
1345 * @tx_ring: Tx descriptor ring
1346 */
1347static void pch_gbe_alloc_tx_buffers(struct pch_gbe_adapter *adapter,
1348 struct pch_gbe_tx_ring *tx_ring)
1349{
1350 struct pch_gbe_buffer *buffer_info;
1351 struct sk_buff *skb;
1352 unsigned int i;
1353 unsigned int bufsz;
1354 struct pch_gbe_tx_desc *tx_desc;
1355
1356 bufsz =
1357 adapter->hw.mac.max_frame_size + PCH_GBE_DMA_ALIGN + NET_IP_ALIGN;
1358
1359 for (i = 0; i < tx_ring->count; i++) {
1360 buffer_info = &tx_ring->buffer_info[i];
1361 skb = netdev_alloc_skb(adapter->netdev, bufsz);
1362 skb_reserve(skb, PCH_GBE_DMA_ALIGN);
1363 buffer_info->skb = skb;
1364 tx_desc = PCH_GBE_TX_DESC(*tx_ring, i);
1365 tx_desc->gbec_status = (DSC_INIT16);
1366 }
1367 return;
1368}
1369
1370/**
1371 * pch_gbe_clean_tx - Reclaim resources after transmit completes
1372 * @adapter: Board private structure
1373 * @tx_ring: Tx descriptor ring
1374 * Returns
1375 * true: Cleaned the descriptor
1376 * false: Not cleaned the descriptor
1377 */
1378static bool
1379pch_gbe_clean_tx(struct pch_gbe_adapter *adapter,
1380 struct pch_gbe_tx_ring *tx_ring)
1381{
1382 struct pch_gbe_tx_desc *tx_desc;
1383 struct pch_gbe_buffer *buffer_info;
1384 struct sk_buff *skb;
1385 unsigned int i;
1386 unsigned int cleaned_count = 0;
1387 bool cleaned = true;
1388
1389 pr_debug("next_to_clean : %d\n", tx_ring->next_to_clean);
1390
1391 i = tx_ring->next_to_clean;
1392 tx_desc = PCH_GBE_TX_DESC(*tx_ring, i);
1393 pr_debug("gbec_status:0x%04x dma_status:0x%04x\n",
1394 tx_desc->gbec_status, tx_desc->dma_status);
1395
1396 while ((tx_desc->gbec_status & DSC_INIT16) == 0x0000) {
1397 pr_debug("gbec_status:0x%04x\n", tx_desc->gbec_status);
1398 buffer_info = &tx_ring->buffer_info[i];
1399 skb = buffer_info->skb;
1400
1401 if ((tx_desc->gbec_status & PCH_GBE_TXD_GMAC_STAT_ABT)) {
1402 adapter->stats.tx_aborted_errors++;
1403 pr_err("Transfer Abort Error\n");
1404 } else if ((tx_desc->gbec_status & PCH_GBE_TXD_GMAC_STAT_CRSER)
1405 ) {
1406 adapter->stats.tx_carrier_errors++;
1407 pr_err("Transfer Carrier Sense Error\n");
1408 } else if ((tx_desc->gbec_status & PCH_GBE_TXD_GMAC_STAT_EXCOL)
1409 ) {
1410 adapter->stats.tx_aborted_errors++;
1411 pr_err("Transfer Collision Abort Error\n");
1412 } else if ((tx_desc->gbec_status &
1413 (PCH_GBE_TXD_GMAC_STAT_SNGCOL |
1414 PCH_GBE_TXD_GMAC_STAT_MLTCOL))) {
1415 adapter->stats.collisions++;
1416 adapter->stats.tx_packets++;
1417 adapter->stats.tx_bytes += skb->len;
1418 pr_debug("Transfer Collision\n");
1419 } else if ((tx_desc->gbec_status & PCH_GBE_TXD_GMAC_STAT_CMPLT)
1420 ) {
1421 adapter->stats.tx_packets++;
1422 adapter->stats.tx_bytes += skb->len;
1423 }
1424 if (buffer_info->mapped) {
1425 pr_debug("unmap buffer_info->dma : %d\n", i);
1426 dma_unmap_single(&adapter->pdev->dev, buffer_info->dma,
1427 buffer_info->length, DMA_TO_DEVICE);
1428 buffer_info->mapped = false;
1429 }
1430 if (buffer_info->skb) {
1431 pr_debug("trim buffer_info->skb : %d\n", i);
1432 skb_trim(buffer_info->skb, 0);
1433 }
1434 tx_desc->gbec_status = DSC_INIT16;
1435 if (unlikely(++i == tx_ring->count))
1436 i = 0;
1437 tx_desc = PCH_GBE_TX_DESC(*tx_ring, i);
1438
1439 /* weight of a sort for tx, to avoid endless transmit cleanup */
1440 if (cleaned_count++ == PCH_GBE_TX_WEIGHT) {
1441 cleaned = false;
1442 break;
1443 }
1444 }
1445 pr_debug("called pch_gbe_unmap_and_free_tx_resource() %d count\n",
1446 cleaned_count);
1447 /* Recover from running out of Tx resources in xmit_frame */
1448 if (unlikely(cleaned && (netif_queue_stopped(adapter->netdev)))) {
1449 netif_wake_queue(adapter->netdev);
1450 adapter->stats.tx_restart_count++;
1451 pr_debug("Tx wake queue\n");
1452 }
1453 spin_lock(&adapter->tx_queue_lock);
1454 tx_ring->next_to_clean = i;
1455 spin_unlock(&adapter->tx_queue_lock);
1456 pr_debug("next_to_clean : %d\n", tx_ring->next_to_clean);
1457 return cleaned;
1458}
1459
1460/**
1461 * pch_gbe_clean_rx - Send received data up the network stack; legacy
1462 * @adapter: Board private structure
1463 * @rx_ring: Rx descriptor ring
1464 * @work_done: Completed count
1465 * @work_to_do: Request count
1466 * Returns
1467 * true: Cleaned the descriptor
1468 * false: Not cleaned the descriptor
1469 */
1470static bool
1471pch_gbe_clean_rx(struct pch_gbe_adapter *adapter,
1472 struct pch_gbe_rx_ring *rx_ring,
1473 int *work_done, int work_to_do)
1474{
1475 struct net_device *netdev = adapter->netdev;
1476 struct pci_dev *pdev = adapter->pdev;
1477 struct pch_gbe_buffer *buffer_info;
1478 struct pch_gbe_rx_desc *rx_desc;
1479 u32 length;
1480 unsigned int i;
1481 unsigned int cleaned_count = 0;
1482 bool cleaned = false;
1483 struct sk_buff *skb;
1484 u8 dma_status;
1485 u16 gbec_status;
1486 u32 tcp_ip_status;
1487
1488 i = rx_ring->next_to_clean;
1489
1490 while (*work_done < work_to_do) {
1491 /* Check Rx descriptor status */
1492 rx_desc = PCH_GBE_RX_DESC(*rx_ring, i);
1493 if (rx_desc->gbec_status == DSC_INIT16)
1494 break;
1495 cleaned = true;
1496 cleaned_count++;
1497
1498 dma_status = rx_desc->dma_status;
1499 gbec_status = rx_desc->gbec_status;
1500 tcp_ip_status = rx_desc->tcp_ip_status;
1501 rx_desc->gbec_status = DSC_INIT16;
1502 buffer_info = &rx_ring->buffer_info[i];
1503 skb = buffer_info->skb;
1504 buffer_info->skb = NULL;
1505
1506 /* unmap dma */
1507 dma_unmap_single(&pdev->dev, buffer_info->dma,
1508 buffer_info->length, DMA_FROM_DEVICE);
1509 buffer_info->mapped = false;
1510
1511 pr_debug("RxDecNo = 0x%04x Status[DMA:0x%02x GBE:0x%04x "
1512 "TCP:0x%08x] BufInf = 0x%p\n",
1513 i, dma_status, gbec_status, tcp_ip_status,
1514 buffer_info);
1515 /* Error check */
1516 if (unlikely(gbec_status & PCH_GBE_RXD_GMAC_STAT_NOTOCTAL)) {
1517 adapter->stats.rx_frame_errors++;
1518 pr_err("Receive Not Octal Error\n");
1519 } else if (unlikely(gbec_status &
1520 PCH_GBE_RXD_GMAC_STAT_NBLERR)) {
1521 adapter->stats.rx_frame_errors++;
1522 pr_err("Receive Nibble Error\n");
1523 } else if (unlikely(gbec_status &
1524 PCH_GBE_RXD_GMAC_STAT_CRCERR)) {
1525 adapter->stats.rx_crc_errors++;
1526 pr_err("Receive CRC Error\n");
1527 } else {
1528 /* get receive length */
1529 /* length convert[-3], length includes FCS length */
1530 length = (rx_desc->rx_words_eob) - 3 - ETH_FCS_LEN;
1531 if (rx_desc->rx_words_eob & 0x02)
1532 length = length - 4;
1533 /*
1534 * buffer_info->rx_buffer: [Header:14][payload]
1535 * skb->data: [Reserve:2][Header:14][payload]
1536 */
1537 memcpy(skb->data, buffer_info->rx_buffer, length);
1538
1539 /* update status of driver */
1540 adapter->stats.rx_bytes += length;
1541 adapter->stats.rx_packets++;
1542 if ((gbec_status & PCH_GBE_RXD_GMAC_STAT_MARMLT))
1543 adapter->stats.multicast++;
1544 /* Write meta date of skb */
1545 skb_put(skb, length);
1546 skb->protocol = eth_type_trans(skb, netdev);
1547 if (tcp_ip_status & PCH_GBE_RXD_ACC_STAT_TCPIPOK)
1548 skb->ip_summed = CHECKSUM_NONE;
1549 else
1550 skb->ip_summed = CHECKSUM_UNNECESSARY;
1551
1552 napi_gro_receive(&adapter->napi, skb);
1553 (*work_done)++;
1554 pr_debug("Receive skb->ip_summed: %d length: %d\n",
1555 skb->ip_summed, length);
1556 }
1557 /* return some buffers to hardware, one at a time is too slow */
1558 if (unlikely(cleaned_count >= PCH_GBE_RX_BUFFER_WRITE)) {
1559 pch_gbe_alloc_rx_buffers(adapter, rx_ring,
1560 cleaned_count);
1561 cleaned_count = 0;
1562 }
1563 if (++i == rx_ring->count)
1564 i = 0;
1565 }
1566 rx_ring->next_to_clean = i;
1567 if (cleaned_count)
1568 pch_gbe_alloc_rx_buffers(adapter, rx_ring, cleaned_count);
1569 return cleaned;
1570}
1571
1572/**
1573 * pch_gbe_setup_tx_resources - Allocate Tx resources (Descriptors)
1574 * @adapter: Board private structure
1575 * @tx_ring: Tx descriptor ring (for a specific queue) to setup
1576 * Returns
1577 * 0: Successfully
1578 * Negative value: Failed
1579 */
1580int pch_gbe_setup_tx_resources(struct pch_gbe_adapter *adapter,
1581 struct pch_gbe_tx_ring *tx_ring)
1582{
1583 struct pci_dev *pdev = adapter->pdev;
1584 struct pch_gbe_tx_desc *tx_desc;
1585 int size;
1586 int desNo;
1587
1588 size = (int)sizeof(struct pch_gbe_buffer) * tx_ring->count;
1589 tx_ring->buffer_info = vzalloc(size);
1590 if (!tx_ring->buffer_info) {
1591 pr_err("Unable to allocate memory for the buffer information\n");
1592 return -ENOMEM;
1593 }
1594
1595 tx_ring->size = tx_ring->count * (int)sizeof(struct pch_gbe_tx_desc);
1596
1597 tx_ring->desc = dma_alloc_coherent(&pdev->dev, tx_ring->size,
1598 &tx_ring->dma, GFP_KERNEL);
1599 if (!tx_ring->desc) {
1600 vfree(tx_ring->buffer_info);
1601 pr_err("Unable to allocate memory for the transmit descriptor ring\n");
1602 return -ENOMEM;
1603 }
1604 memset(tx_ring->desc, 0, tx_ring->size);
1605
1606 tx_ring->next_to_use = 0;
1607 tx_ring->next_to_clean = 0;
1608 spin_lock_init(&tx_ring->tx_lock);
1609
1610 for (desNo = 0; desNo < tx_ring->count; desNo++) {
1611 tx_desc = PCH_GBE_TX_DESC(*tx_ring, desNo);
1612 tx_desc->gbec_status = DSC_INIT16;
1613 }
1614 pr_debug("tx_ring->desc = 0x%p tx_ring->dma = 0x%08llx\n"
1615 "next_to_clean = 0x%08x next_to_use = 0x%08x\n",
1616 tx_ring->desc, (unsigned long long)tx_ring->dma,
1617 tx_ring->next_to_clean, tx_ring->next_to_use);
1618 return 0;
1619}
1620
1621/**
1622 * pch_gbe_setup_rx_resources - Allocate Rx resources (Descriptors)
1623 * @adapter: Board private structure
1624 * @rx_ring: Rx descriptor ring (for a specific queue) to setup
1625 * Returns
1626 * 0: Successfully
1627 * Negative value: Failed
1628 */
1629int pch_gbe_setup_rx_resources(struct pch_gbe_adapter *adapter,
1630 struct pch_gbe_rx_ring *rx_ring)
1631{
1632 struct pci_dev *pdev = adapter->pdev;
1633 struct pch_gbe_rx_desc *rx_desc;
1634 int size;
1635 int desNo;
1636
1637 size = (int)sizeof(struct pch_gbe_buffer) * rx_ring->count;
1638 rx_ring->buffer_info = vzalloc(size);
1639 if (!rx_ring->buffer_info) {
1640 pr_err("Unable to allocate memory for the receive descriptor ring\n");
1641 return -ENOMEM;
1642 }
1643 rx_ring->size = rx_ring->count * (int)sizeof(struct pch_gbe_rx_desc);
1644 rx_ring->desc = dma_alloc_coherent(&pdev->dev, rx_ring->size,
1645 &rx_ring->dma, GFP_KERNEL);
1646
1647 if (!rx_ring->desc) {
1648 pr_err("Unable to allocate memory for the receive descriptor ring\n");
1649 vfree(rx_ring->buffer_info);
1650 return -ENOMEM;
1651 }
1652 memset(rx_ring->desc, 0, rx_ring->size);
1653 rx_ring->next_to_clean = 0;
1654 rx_ring->next_to_use = 0;
1655 for (desNo = 0; desNo < rx_ring->count; desNo++) {
1656 rx_desc = PCH_GBE_RX_DESC(*rx_ring, desNo);
1657 rx_desc->gbec_status = DSC_INIT16;
1658 }
1659 pr_debug("rx_ring->desc = 0x%p rx_ring->dma = 0x%08llx "
1660 "next_to_clean = 0x%08x next_to_use = 0x%08x\n",
1661 rx_ring->desc, (unsigned long long)rx_ring->dma,
1662 rx_ring->next_to_clean, rx_ring->next_to_use);
1663 return 0;
1664}
1665
1666/**
1667 * pch_gbe_free_tx_resources - Free Tx Resources
1668 * @adapter: Board private structure
1669 * @tx_ring: Tx descriptor ring for a specific queue
1670 */
1671void pch_gbe_free_tx_resources(struct pch_gbe_adapter *adapter,
1672 struct pch_gbe_tx_ring *tx_ring)
1673{
1674 struct pci_dev *pdev = adapter->pdev;
1675
1676 pch_gbe_clean_tx_ring(adapter, tx_ring);
1677 vfree(tx_ring->buffer_info);
1678 tx_ring->buffer_info = NULL;
1679 pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma);
1680 tx_ring->desc = NULL;
1681}
1682
1683/**
1684 * pch_gbe_free_rx_resources - Free Rx Resources
1685 * @adapter: Board private structure
1686 * @rx_ring: Ring to clean the resources from
1687 */
1688void pch_gbe_free_rx_resources(struct pch_gbe_adapter *adapter,
1689 struct pch_gbe_rx_ring *rx_ring)
1690{
1691 struct pci_dev *pdev = adapter->pdev;
1692
1693 pch_gbe_clean_rx_ring(adapter, rx_ring);
1694 vfree(rx_ring->buffer_info);
1695 rx_ring->buffer_info = NULL;
1696 pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
1697 rx_ring->desc = NULL;
1698}
1699
1700/**
1701 * pch_gbe_request_irq - Allocate an interrupt line
1702 * @adapter: Board private structure
1703 * Returns
1704 * 0: Successfully
1705 * Negative value: Failed
1706 */
1707static int pch_gbe_request_irq(struct pch_gbe_adapter *adapter)
1708{
1709 struct net_device *netdev = adapter->netdev;
1710 int err;
1711 int flags;
1712
1713 flags = IRQF_SHARED;
1714 adapter->have_msi = false;
1715 err = pci_enable_msi(adapter->pdev);
1716 pr_debug("call pci_enable_msi\n");
1717 if (err) {
1718 pr_debug("call pci_enable_msi - Error: %d\n", err);
1719 } else {
1720 flags = 0;
1721 adapter->have_msi = true;
1722 }
1723 err = request_irq(adapter->pdev->irq, &pch_gbe_intr,
1724 flags, netdev->name, netdev);
1725 if (err)
1726 pr_err("Unable to allocate interrupt Error: %d\n", err);
1727 pr_debug("adapter->have_msi : %d flags : 0x%04x return : 0x%04x\n",
1728 adapter->have_msi, flags, err);
1729 return err;
1730}
1731
1732
1733static void pch_gbe_set_multi(struct net_device *netdev);
1734/**
1735 * pch_gbe_up - Up GbE network device
1736 * @adapter: Board private structure
1737 * Returns
1738 * 0: Successfully
1739 * Negative value: Failed
1740 */
1741int pch_gbe_up(struct pch_gbe_adapter *adapter)
1742{
1743 struct net_device *netdev = adapter->netdev;
1744 struct pch_gbe_tx_ring *tx_ring = adapter->tx_ring;
1745 struct pch_gbe_rx_ring *rx_ring = adapter->rx_ring;
1746 int err;
1747
1748 /* hardware has been reset, we need to reload some things */
1749 pch_gbe_set_multi(netdev);
1750
1751 pch_gbe_setup_tctl(adapter);
1752 pch_gbe_configure_tx(adapter);
1753 pch_gbe_setup_rctl(adapter);
1754 pch_gbe_configure_rx(adapter);
1755
1756 err = pch_gbe_request_irq(adapter);
1757 if (err) {
1758 pr_err("Error: can't bring device up\n");
1759 return err;
1760 }
1761 err = pch_gbe_alloc_rx_buffers_pool(adapter, rx_ring, rx_ring->count);
1762 if (err) {
1763 pr_err("Error: can't bring device up\n");
1764 return err;
1765 }
1766 pch_gbe_alloc_tx_buffers(adapter, tx_ring);
1767 pch_gbe_alloc_rx_buffers(adapter, rx_ring, rx_ring->count);
1768 adapter->tx_queue_len = netdev->tx_queue_len;
1769 pch_gbe_start_receive(&adapter->hw);
1770
1771 mod_timer(&adapter->watchdog_timer, jiffies);
1772
1773 napi_enable(&adapter->napi);
1774 pch_gbe_irq_enable(adapter);
1775 netif_start_queue(adapter->netdev);
1776
1777 return 0;
1778}
1779
1780/**
1781 * pch_gbe_down - Down GbE network device
1782 * @adapter: Board private structure
1783 */
1784void pch_gbe_down(struct pch_gbe_adapter *adapter)
1785{
1786 struct net_device *netdev = adapter->netdev;
1787 struct pch_gbe_rx_ring *rx_ring = adapter->rx_ring;
1788
1789 /* signal that we're down so the interrupt handler does not
1790 * reschedule our watchdog timer */
1791 napi_disable(&adapter->napi);
1792 atomic_set(&adapter->irq_sem, 0);
1793
1794 pch_gbe_irq_disable(adapter);
1795 pch_gbe_free_irq(adapter);
1796
1797 del_timer_sync(&adapter->watchdog_timer);
1798
1799 netdev->tx_queue_len = adapter->tx_queue_len;
1800 netif_carrier_off(netdev);
1801 netif_stop_queue(netdev);
1802
1803 pch_gbe_reset(adapter);
1804 pch_gbe_clean_tx_ring(adapter, adapter->tx_ring);
1805 pch_gbe_clean_rx_ring(adapter, adapter->rx_ring);
1806
1807 pci_free_consistent(adapter->pdev, rx_ring->rx_buff_pool_size,
1808 rx_ring->rx_buff_pool, rx_ring->rx_buff_pool_logic);
1809 rx_ring->rx_buff_pool_logic = 0;
1810 rx_ring->rx_buff_pool_size = 0;
1811 rx_ring->rx_buff_pool = NULL;
1812}
1813
1814/**
1815 * pch_gbe_sw_init - Initialize general software structures (struct pch_gbe_adapter)
1816 * @adapter: Board private structure to initialize
1817 * Returns
1818 * 0: Successfully
1819 * Negative value: Failed
1820 */
1821static int pch_gbe_sw_init(struct pch_gbe_adapter *adapter)
1822{
1823 struct pch_gbe_hw *hw = &adapter->hw;
1824 struct net_device *netdev = adapter->netdev;
1825
1826 adapter->rx_buffer_len = PCH_GBE_FRAME_SIZE_2048;
1827 hw->mac.max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
1828 hw->mac.min_frame_size = ETH_ZLEN + ETH_FCS_LEN;
1829
1830 /* Initialize the hardware-specific values */
1831 if (pch_gbe_hal_setup_init_funcs(hw)) {
1832 pr_err("Hardware Initialization Failure\n");
1833 return -EIO;
1834 }
1835 if (pch_gbe_alloc_queues(adapter)) {
1836 pr_err("Unable to allocate memory for queues\n");
1837 return -ENOMEM;
1838 }
1839 spin_lock_init(&adapter->hw.miim_lock);
1840 spin_lock_init(&adapter->tx_queue_lock);
1841 spin_lock_init(&adapter->stats_lock);
1842 spin_lock_init(&adapter->ethtool_lock);
1843 atomic_set(&adapter->irq_sem, 0);
1844 pch_gbe_irq_disable(adapter);
1845
1846 pch_gbe_init_stats(adapter);
1847
1848 pr_debug("rx_buffer_len : %d mac.min_frame_size : %d mac.max_frame_size : %d\n",
1849 (u32) adapter->rx_buffer_len,
1850 hw->mac.min_frame_size, hw->mac.max_frame_size);
1851 return 0;
1852}
1853
1854/**
1855 * pch_gbe_open - Called when a network interface is made active
1856 * @netdev: Network interface device structure
1857 * Returns
1858 * 0: Successfully
1859 * Negative value: Failed
1860 */
1861static int pch_gbe_open(struct net_device *netdev)
1862{
1863 struct pch_gbe_adapter *adapter = netdev_priv(netdev);
1864 struct pch_gbe_hw *hw = &adapter->hw;
1865 int err;
1866
1867 /* allocate transmit descriptors */
1868 err = pch_gbe_setup_tx_resources(adapter, adapter->tx_ring);
1869 if (err)
1870 goto err_setup_tx;
1871 /* allocate receive descriptors */
1872 err = pch_gbe_setup_rx_resources(adapter, adapter->rx_ring);
1873 if (err)
1874 goto err_setup_rx;
1875 pch_gbe_hal_power_up_phy(hw);
1876 err = pch_gbe_up(adapter);
1877 if (err)
1878 goto err_up;
1879 pr_debug("Success End\n");
1880 return 0;
1881
1882err_up:
1883 if (!adapter->wake_up_evt)
1884 pch_gbe_hal_power_down_phy(hw);
1885 pch_gbe_free_rx_resources(adapter, adapter->rx_ring);
1886err_setup_rx:
1887 pch_gbe_free_tx_resources(adapter, adapter->tx_ring);
1888err_setup_tx:
1889 pch_gbe_reset(adapter);
1890 pr_err("Error End\n");
1891 return err;
1892}
1893
1894/**
1895 * pch_gbe_stop - Disables a network interface
1896 * @netdev: Network interface device structure
1897 * Returns
1898 * 0: Successfully
1899 */
1900static int pch_gbe_stop(struct net_device *netdev)
1901{
1902 struct pch_gbe_adapter *adapter = netdev_priv(netdev);
1903 struct pch_gbe_hw *hw = &adapter->hw;
1904
1905 pch_gbe_down(adapter);
1906 if (!adapter->wake_up_evt)
1907 pch_gbe_hal_power_down_phy(hw);
1908 pch_gbe_free_tx_resources(adapter, adapter->tx_ring);
1909 pch_gbe_free_rx_resources(adapter, adapter->rx_ring);
1910 return 0;
1911}
1912
1913/**
1914 * pch_gbe_xmit_frame - Packet transmitting start
1915 * @skb: Socket buffer structure
1916 * @netdev: Network interface device structure
1917 * Returns
1918 * - NETDEV_TX_OK: Normal end
1919 * - NETDEV_TX_BUSY: Error end
1920 */
1921static int pch_gbe_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
1922{
1923 struct pch_gbe_adapter *adapter = netdev_priv(netdev);
1924 struct pch_gbe_tx_ring *tx_ring = adapter->tx_ring;
1925 unsigned long flags;
1926
1927 if (unlikely(skb->len > (adapter->hw.mac.max_frame_size - 4))) {
1928 pr_err("Transfer length Error: skb len: %d > max: %d\n",
1929 skb->len, adapter->hw.mac.max_frame_size);
1930 dev_kfree_skb_any(skb);
1931 adapter->stats.tx_length_errors++;
1932 return NETDEV_TX_OK;
1933 }
1934 if (!spin_trylock_irqsave(&tx_ring->tx_lock, flags)) {
1935 /* Collision - tell upper layer to requeue */
1936 return NETDEV_TX_LOCKED;
1937 }
1938 if (unlikely(!PCH_GBE_DESC_UNUSED(tx_ring))) {
1939 netif_stop_queue(netdev);
1940 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
1941 pr_debug("Return : BUSY next_to use : 0x%08x next_to clean : 0x%08x\n",
1942 tx_ring->next_to_use, tx_ring->next_to_clean);
1943 return NETDEV_TX_BUSY;
1944 }
1945 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
1946
1947 /* CRC,ITAG no support */
1948 pch_gbe_tx_queue(adapter, tx_ring, skb);
1949 return NETDEV_TX_OK;
1950}
1951
1952/**
1953 * pch_gbe_get_stats - Get System Network Statistics
1954 * @netdev: Network interface device structure
1955 * Returns: The current stats
1956 */
1957static struct net_device_stats *pch_gbe_get_stats(struct net_device *netdev)
1958{
1959 /* only return the current stats */
1960 return &netdev->stats;
1961}
1962
1963/**
1964 * pch_gbe_set_multi - Multicast and Promiscuous mode set
1965 * @netdev: Network interface device structure
1966 */
1967static void pch_gbe_set_multi(struct net_device *netdev)
1968{
1969 struct pch_gbe_adapter *adapter = netdev_priv(netdev);
1970 struct pch_gbe_hw *hw = &adapter->hw;
1971 struct netdev_hw_addr *ha;
1972 u8 *mta_list;
1973 u32 rctl;
1974 int i;
1975 int mc_count;
1976
1977 pr_debug("netdev->flags : 0x%08x\n", netdev->flags);
1978
1979 /* Check for Promiscuous and All Multicast modes */
1980 rctl = ioread32(&hw->reg->RX_MODE);
1981 mc_count = netdev_mc_count(netdev);
1982 if ((netdev->flags & IFF_PROMISC)) {
1983 rctl &= ~PCH_GBE_ADD_FIL_EN;
1984 rctl &= ~PCH_GBE_MLT_FIL_EN;
1985 } else if ((netdev->flags & IFF_ALLMULTI)) {
1986 /* all the multicasting receive permissions */
1987 rctl |= PCH_GBE_ADD_FIL_EN;
1988 rctl &= ~PCH_GBE_MLT_FIL_EN;
1989 } else {
1990 if (mc_count >= PCH_GBE_MAR_ENTRIES) {
1991 /* all the multicasting receive permissions */
1992 rctl |= PCH_GBE_ADD_FIL_EN;
1993 rctl &= ~PCH_GBE_MLT_FIL_EN;
1994 } else {
1995 rctl |= (PCH_GBE_ADD_FIL_EN | PCH_GBE_MLT_FIL_EN);
1996 }
1997 }
1998 iowrite32(rctl, &hw->reg->RX_MODE);
1999
2000 if (mc_count >= PCH_GBE_MAR_ENTRIES)
2001 return;
2002 mta_list = kmalloc(mc_count * ETH_ALEN, GFP_ATOMIC);
2003 if (!mta_list)
2004 return;
2005
2006 /* The shared function expects a packed array of only addresses. */
2007 i = 0;
2008 netdev_for_each_mc_addr(ha, netdev) {
2009 if (i == mc_count)
2010 break;
2011 memcpy(mta_list + (i++ * ETH_ALEN), &ha->addr, ETH_ALEN);
2012 }
2013 pch_gbe_mac_mc_addr_list_update(hw, mta_list, i, 1,
2014 PCH_GBE_MAR_ENTRIES);
2015 kfree(mta_list);
2016
2017 pr_debug("RX_MODE reg(check bit31,30 ADD,MLT) : 0x%08x netdev->mc_count : 0x%08x\n",
2018 ioread32(&hw->reg->RX_MODE), mc_count);
2019}
2020
2021/**
2022 * pch_gbe_set_mac - Change the Ethernet Address of the NIC
2023 * @netdev: Network interface device structure
2024 * @addr: Pointer to an address structure
2025 * Returns
2026 * 0: Successfully
2027 * -EADDRNOTAVAIL: Failed
2028 */
2029static int pch_gbe_set_mac(struct net_device *netdev, void *addr)
2030{
2031 struct pch_gbe_adapter *adapter = netdev_priv(netdev);
2032 struct sockaddr *skaddr = addr;
2033 int ret_val;
2034
2035 if (!is_valid_ether_addr(skaddr->sa_data)) {
2036 ret_val = -EADDRNOTAVAIL;
2037 } else {
2038 memcpy(netdev->dev_addr, skaddr->sa_data, netdev->addr_len);
2039 memcpy(adapter->hw.mac.addr, skaddr->sa_data, netdev->addr_len);
2040 pch_gbe_mac_mar_set(&adapter->hw, adapter->hw.mac.addr, 0);
2041 ret_val = 0;
2042 }
2043 pr_debug("ret_val : 0x%08x\n", ret_val);
2044 pr_debug("dev_addr : %pM\n", netdev->dev_addr);
2045 pr_debug("mac_addr : %pM\n", adapter->hw.mac.addr);
2046 pr_debug("MAC_ADR1AB reg : 0x%08x 0x%08x\n",
2047 ioread32(&adapter->hw.reg->mac_adr[0].high),
2048 ioread32(&adapter->hw.reg->mac_adr[0].low));
2049 return ret_val;
2050}
2051
2052/**
2053 * pch_gbe_change_mtu - Change the Maximum Transfer Unit
2054 * @netdev: Network interface device structure
2055 * @new_mtu: New value for maximum frame size
2056 * Returns
2057 * 0: Successfully
2058 * -EINVAL: Failed
2059 */
2060static int pch_gbe_change_mtu(struct net_device *netdev, int new_mtu)
2061{
2062 struct pch_gbe_adapter *adapter = netdev_priv(netdev);
2063 int max_frame;
2064 unsigned long old_rx_buffer_len = adapter->rx_buffer_len;
2065 int err;
2066
2067 max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
2068 if ((max_frame < ETH_ZLEN + ETH_FCS_LEN) ||
2069 (max_frame > PCH_GBE_MAX_JUMBO_FRAME_SIZE)) {
2070 pr_err("Invalid MTU setting\n");
2071 return -EINVAL;
2072 }
2073 if (max_frame <= PCH_GBE_FRAME_SIZE_2048)
2074 adapter->rx_buffer_len = PCH_GBE_FRAME_SIZE_2048;
2075 else if (max_frame <= PCH_GBE_FRAME_SIZE_4096)
2076 adapter->rx_buffer_len = PCH_GBE_FRAME_SIZE_4096;
2077 else if (max_frame <= PCH_GBE_FRAME_SIZE_8192)
2078 adapter->rx_buffer_len = PCH_GBE_FRAME_SIZE_8192;
2079 else
2080 adapter->rx_buffer_len = PCH_GBE_MAX_RX_BUFFER_SIZE;
2081
2082 if (netif_running(netdev)) {
2083 pch_gbe_down(adapter);
2084 err = pch_gbe_up(adapter);
2085 if (err) {
2086 adapter->rx_buffer_len = old_rx_buffer_len;
2087 pch_gbe_up(adapter);
2088 return -ENOMEM;
2089 } else {
2090 netdev->mtu = new_mtu;
2091 adapter->hw.mac.max_frame_size = max_frame;
2092 }
2093 } else {
2094 pch_gbe_reset(adapter);
2095 netdev->mtu = new_mtu;
2096 adapter->hw.mac.max_frame_size = max_frame;
2097 }
2098
2099 pr_debug("max_frame : %d rx_buffer_len : %d mtu : %d max_frame_size : %d\n",
2100 max_frame, (u32) adapter->rx_buffer_len, netdev->mtu,
2101 adapter->hw.mac.max_frame_size);
2102 return 0;
2103}
2104
2105/**
2106 * pch_gbe_set_features - Reset device after features changed
2107 * @netdev: Network interface device structure
2108 * @features: New features
2109 * Returns
2110 * 0: HW state updated successfully
2111 */
2112static int pch_gbe_set_features(struct net_device *netdev, u32 features)
2113{
2114 struct pch_gbe_adapter *adapter = netdev_priv(netdev);
2115 u32 changed = features ^ netdev->features;
2116
2117 if (!(changed & NETIF_F_RXCSUM))
2118 return 0;
2119
2120 if (netif_running(netdev))
2121 pch_gbe_reinit_locked(adapter);
2122 else
2123 pch_gbe_reset(adapter);
2124
2125 return 0;
2126}
2127
2128/**
2129 * pch_gbe_ioctl - Controls register through a MII interface
2130 * @netdev: Network interface device structure
2131 * @ifr: Pointer to ifr structure
2132 * @cmd: Control command
2133 * Returns
2134 * 0: Successfully
2135 * Negative value: Failed
2136 */
2137static int pch_gbe_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
2138{
2139 struct pch_gbe_adapter *adapter = netdev_priv(netdev);
2140
2141 pr_debug("cmd : 0x%04x\n", cmd);
2142
2143 return generic_mii_ioctl(&adapter->mii, if_mii(ifr), cmd, NULL);
2144}
2145
2146/**
2147 * pch_gbe_tx_timeout - Respond to a Tx Hang
2148 * @netdev: Network interface device structure
2149 */
2150static void pch_gbe_tx_timeout(struct net_device *netdev)
2151{
2152 struct pch_gbe_adapter *adapter = netdev_priv(netdev);
2153
2154 /* Do the reset outside of interrupt context */
2155 adapter->stats.tx_timeout_count++;
2156 schedule_work(&adapter->reset_task);
2157}
2158
2159/**
2160 * pch_gbe_napi_poll - NAPI receive and transfer polling callback
2161 * @napi: Pointer of polling device struct
2162 * @budget: The maximum number of a packet
2163 * Returns
2164 * false: Exit the polling mode
2165 * true: Continue the polling mode
2166 */
2167static int pch_gbe_napi_poll(struct napi_struct *napi, int budget)
2168{
2169 struct pch_gbe_adapter *adapter =
2170 container_of(napi, struct pch_gbe_adapter, napi);
2171 int work_done = 0;
2172 bool poll_end_flag = false;
2173 bool cleaned = false;
2174 u32 int_en;
2175
2176 pr_debug("budget : %d\n", budget);
2177
2178 pch_gbe_clean_rx(adapter, adapter->rx_ring, &work_done, budget);
2179 cleaned = pch_gbe_clean_tx(adapter, adapter->tx_ring);
2180
2181 if (!cleaned)
2182 work_done = budget;
2183 /* If no Tx and not enough Rx work done,
2184 * exit the polling mode
2185 */
2186 if (work_done < budget)
2187 poll_end_flag = true;
2188
2189 if (poll_end_flag) {
2190 napi_complete(napi);
2191 if (adapter->rx_stop_flag) {
2192 adapter->rx_stop_flag = false;
2193 pch_gbe_start_receive(&adapter->hw);
2194 }
2195 pch_gbe_irq_enable(adapter);
2196 } else
2197 if (adapter->rx_stop_flag) {
2198 adapter->rx_stop_flag = false;
2199 pch_gbe_start_receive(&adapter->hw);
2200 int_en = ioread32(&adapter->hw.reg->INT_EN);
2201 iowrite32((int_en | PCH_GBE_INT_RX_FIFO_ERR),
2202 &adapter->hw.reg->INT_EN);
2203 }
2204
2205 pr_debug("poll_end_flag : %d work_done : %d budget : %d\n",
2206 poll_end_flag, work_done, budget);
2207
2208 return work_done;
2209}
2210
2211#ifdef CONFIG_NET_POLL_CONTROLLER
2212/**
2213 * pch_gbe_netpoll - Used by things like netconsole to send skbs
2214 * @netdev: Network interface device structure
2215 */
2216static void pch_gbe_netpoll(struct net_device *netdev)
2217{
2218 struct pch_gbe_adapter *adapter = netdev_priv(netdev);
2219
2220 disable_irq(adapter->pdev->irq);
2221 pch_gbe_intr(adapter->pdev->irq, netdev);
2222 enable_irq(adapter->pdev->irq);
2223}
2224#endif
2225
2226static const struct net_device_ops pch_gbe_netdev_ops = {
2227 .ndo_open = pch_gbe_open,
2228 .ndo_stop = pch_gbe_stop,
2229 .ndo_start_xmit = pch_gbe_xmit_frame,
2230 .ndo_get_stats = pch_gbe_get_stats,
2231 .ndo_set_mac_address = pch_gbe_set_mac,
2232 .ndo_tx_timeout = pch_gbe_tx_timeout,
2233 .ndo_change_mtu = pch_gbe_change_mtu,
2234 .ndo_set_features = pch_gbe_set_features,
2235 .ndo_do_ioctl = pch_gbe_ioctl,
2236 .ndo_set_multicast_list = &pch_gbe_set_multi,
2237#ifdef CONFIG_NET_POLL_CONTROLLER
2238 .ndo_poll_controller = pch_gbe_netpoll,
2239#endif
2240};
2241
2242static pci_ers_result_t pch_gbe_io_error_detected(struct pci_dev *pdev,
2243 pci_channel_state_t state)
2244{
2245 struct net_device *netdev = pci_get_drvdata(pdev);
2246 struct pch_gbe_adapter *adapter = netdev_priv(netdev);
2247
2248 netif_device_detach(netdev);
2249 if (netif_running(netdev))
2250 pch_gbe_down(adapter);
2251 pci_disable_device(pdev);
2252 /* Request a slot slot reset. */
2253 return PCI_ERS_RESULT_NEED_RESET;
2254}
2255
2256static pci_ers_result_t pch_gbe_io_slot_reset(struct pci_dev *pdev)
2257{
2258 struct net_device *netdev = pci_get_drvdata(pdev);
2259 struct pch_gbe_adapter *adapter = netdev_priv(netdev);
2260 struct pch_gbe_hw *hw = &adapter->hw;
2261
2262 if (pci_enable_device(pdev)) {
2263 pr_err("Cannot re-enable PCI device after reset\n");
2264 return PCI_ERS_RESULT_DISCONNECT;
2265 }
2266 pci_set_master(pdev);
2267 pci_enable_wake(pdev, PCI_D0, 0);
2268 pch_gbe_hal_power_up_phy(hw);
2269 pch_gbe_reset(adapter);
2270 /* Clear wake up status */
2271 pch_gbe_mac_set_wol_event(hw, 0);
2272
2273 return PCI_ERS_RESULT_RECOVERED;
2274}
2275
2276static void pch_gbe_io_resume(struct pci_dev *pdev)
2277{
2278 struct net_device *netdev = pci_get_drvdata(pdev);
2279 struct pch_gbe_adapter *adapter = netdev_priv(netdev);
2280
2281 if (netif_running(netdev)) {
2282 if (pch_gbe_up(adapter)) {
2283 pr_debug("can't bring device back up after reset\n");
2284 return;
2285 }
2286 }
2287 netif_device_attach(netdev);
2288}
2289
2290static int __pch_gbe_suspend(struct pci_dev *pdev)
2291{
2292 struct net_device *netdev = pci_get_drvdata(pdev);
2293 struct pch_gbe_adapter *adapter = netdev_priv(netdev);
2294 struct pch_gbe_hw *hw = &adapter->hw;
2295 u32 wufc = adapter->wake_up_evt;
2296 int retval = 0;
2297
2298 netif_device_detach(netdev);
2299 if (netif_running(netdev))
2300 pch_gbe_down(adapter);
2301 if (wufc) {
2302 pch_gbe_set_multi(netdev);
2303 pch_gbe_setup_rctl(adapter);
2304 pch_gbe_configure_rx(adapter);
2305 pch_gbe_set_rgmii_ctrl(adapter, hw->mac.link_speed,
2306 hw->mac.link_duplex);
2307 pch_gbe_set_mode(adapter, hw->mac.link_speed,
2308 hw->mac.link_duplex);
2309 pch_gbe_mac_set_wol_event(hw, wufc);
2310 pci_disable_device(pdev);
2311 } else {
2312 pch_gbe_hal_power_down_phy(hw);
2313 pch_gbe_mac_set_wol_event(hw, wufc);
2314 pci_disable_device(pdev);
2315 }
2316 return retval;
2317}
2318
2319#ifdef CONFIG_PM
2320static int pch_gbe_suspend(struct device *device)
2321{
2322 struct pci_dev *pdev = to_pci_dev(device);
2323
2324 return __pch_gbe_suspend(pdev);
2325}
2326
2327static int pch_gbe_resume(struct device *device)
2328{
2329 struct pci_dev *pdev = to_pci_dev(device);
2330 struct net_device *netdev = pci_get_drvdata(pdev);
2331 struct pch_gbe_adapter *adapter = netdev_priv(netdev);
2332 struct pch_gbe_hw *hw = &adapter->hw;
2333 u32 err;
2334
2335 err = pci_enable_device(pdev);
2336 if (err) {
2337 pr_err("Cannot enable PCI device from suspend\n");
2338 return err;
2339 }
2340 pci_set_master(pdev);
2341 pch_gbe_hal_power_up_phy(hw);
2342 pch_gbe_reset(adapter);
2343 /* Clear wake on lan control and status */
2344 pch_gbe_mac_set_wol_event(hw, 0);
2345
2346 if (netif_running(netdev))
2347 pch_gbe_up(adapter);
2348 netif_device_attach(netdev);
2349
2350 return 0;
2351}
2352#endif /* CONFIG_PM */
2353
2354static void pch_gbe_shutdown(struct pci_dev *pdev)
2355{
2356 __pch_gbe_suspend(pdev);
2357 if (system_state == SYSTEM_POWER_OFF) {
2358 pci_wake_from_d3(pdev, true);
2359 pci_set_power_state(pdev, PCI_D3hot);
2360 }
2361}
2362
2363static void pch_gbe_remove(struct pci_dev *pdev)
2364{
2365 struct net_device *netdev = pci_get_drvdata(pdev);
2366 struct pch_gbe_adapter *adapter = netdev_priv(netdev);
2367
2368 cancel_work_sync(&adapter->reset_task);
2369 unregister_netdev(netdev);
2370
2371 pch_gbe_hal_phy_hw_reset(&adapter->hw);
2372
2373 kfree(adapter->tx_ring);
2374 kfree(adapter->rx_ring);
2375
2376 iounmap(adapter->hw.reg);
2377 pci_release_regions(pdev);
2378 free_netdev(netdev);
2379 pci_disable_device(pdev);
2380}
2381
2382static int pch_gbe_probe(struct pci_dev *pdev,
2383 const struct pci_device_id *pci_id)
2384{
2385 struct net_device *netdev;
2386 struct pch_gbe_adapter *adapter;
2387 int ret;
2388
2389 ret = pci_enable_device(pdev);
2390 if (ret)
2391 return ret;
2392
2393 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64))
2394 || pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64))) {
2395 ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
2396 if (ret) {
2397 ret = pci_set_consistent_dma_mask(pdev,
2398 DMA_BIT_MASK(32));
2399 if (ret) {
2400 dev_err(&pdev->dev, "ERR: No usable DMA "
2401 "configuration, aborting\n");
2402 goto err_disable_device;
2403 }
2404 }
2405 }
2406
2407 ret = pci_request_regions(pdev, KBUILD_MODNAME);
2408 if (ret) {
2409 dev_err(&pdev->dev,
2410 "ERR: Can't reserve PCI I/O and memory resources\n");
2411 goto err_disable_device;
2412 }
2413 pci_set_master(pdev);
2414
2415 netdev = alloc_etherdev((int)sizeof(struct pch_gbe_adapter));
2416 if (!netdev) {
2417 ret = -ENOMEM;
2418 dev_err(&pdev->dev,
2419 "ERR: Can't allocate and set up an Ethernet device\n");
2420 goto err_release_pci;
2421 }
2422 SET_NETDEV_DEV(netdev, &pdev->dev);
2423
2424 pci_set_drvdata(pdev, netdev);
2425 adapter = netdev_priv(netdev);
2426 adapter->netdev = netdev;
2427 adapter->pdev = pdev;
2428 adapter->hw.back = adapter;
2429 adapter->hw.reg = pci_iomap(pdev, PCH_GBE_PCI_BAR, 0);
2430 if (!adapter->hw.reg) {
2431 ret = -EIO;
2432 dev_err(&pdev->dev, "Can't ioremap\n");
2433 goto err_free_netdev;
2434 }
2435
2436 netdev->netdev_ops = &pch_gbe_netdev_ops;
2437 netdev->watchdog_timeo = PCH_GBE_WATCHDOG_PERIOD;
2438 netif_napi_add(netdev, &adapter->napi,
2439 pch_gbe_napi_poll, PCH_GBE_RX_WEIGHT);
2440 netdev->hw_features = NETIF_F_RXCSUM |
2441 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
2442 netdev->features = netdev->hw_features;
2443 pch_gbe_set_ethtool_ops(netdev);
2444
2445 pch_gbe_mac_load_mac_addr(&adapter->hw);
2446 pch_gbe_mac_reset_hw(&adapter->hw);
2447
2448 /* setup the private structure */
2449 ret = pch_gbe_sw_init(adapter);
2450 if (ret)
2451 goto err_iounmap;
2452
2453 /* Initialize PHY */
2454 ret = pch_gbe_init_phy(adapter);
2455 if (ret) {
2456 dev_err(&pdev->dev, "PHY initialize error\n");
2457 goto err_free_adapter;
2458 }
2459 pch_gbe_hal_get_bus_info(&adapter->hw);
2460
2461 /* Read the MAC address. and store to the private data */
2462 ret = pch_gbe_hal_read_mac_addr(&adapter->hw);
2463 if (ret) {
2464 dev_err(&pdev->dev, "MAC address Read Error\n");
2465 goto err_free_adapter;
2466 }
2467
2468 memcpy(netdev->dev_addr, adapter->hw.mac.addr, netdev->addr_len);
2469 if (!is_valid_ether_addr(netdev->dev_addr)) {
2470 dev_err(&pdev->dev, "Invalid MAC Address\n");
2471 ret = -EIO;
2472 goto err_free_adapter;
2473 }
2474 setup_timer(&adapter->watchdog_timer, pch_gbe_watchdog,
2475 (unsigned long)adapter);
2476
2477 INIT_WORK(&adapter->reset_task, pch_gbe_reset_task);
2478
2479 pch_gbe_check_options(adapter);
2480
2481 /* initialize the wol settings based on the eeprom settings */
2482 adapter->wake_up_evt = PCH_GBE_WL_INIT_SETTING;
2483 dev_info(&pdev->dev, "MAC address : %pM\n", netdev->dev_addr);
2484
2485 /* reset the hardware with the new settings */
2486 pch_gbe_reset(adapter);
2487
2488 ret = register_netdev(netdev);
2489 if (ret)
2490 goto err_free_adapter;
2491 /* tell the stack to leave us alone until pch_gbe_open() is called */
2492 netif_carrier_off(netdev);
2493 netif_stop_queue(netdev);
2494
2495 dev_dbg(&pdev->dev, "OKIsemi(R) PCH Network Connection\n");
2496
2497 device_set_wakeup_enable(&pdev->dev, 1);
2498 return 0;
2499
2500err_free_adapter:
2501 pch_gbe_hal_phy_hw_reset(&adapter->hw);
2502 kfree(adapter->tx_ring);
2503 kfree(adapter->rx_ring);
2504err_iounmap:
2505 iounmap(adapter->hw.reg);
2506err_free_netdev:
2507 free_netdev(netdev);
2508err_release_pci:
2509 pci_release_regions(pdev);
2510err_disable_device:
2511 pci_disable_device(pdev);
2512 return ret;
2513}
2514
2515static DEFINE_PCI_DEVICE_TABLE(pch_gbe_pcidev_id) = {
2516 {.vendor = PCI_VENDOR_ID_INTEL,
2517 .device = PCI_DEVICE_ID_INTEL_IOH1_GBE,
2518 .subvendor = PCI_ANY_ID,
2519 .subdevice = PCI_ANY_ID,
2520 .class = (PCI_CLASS_NETWORK_ETHERNET << 8),
2521 .class_mask = (0xFFFF00)
2522 },
2523 {.vendor = PCI_VENDOR_ID_ROHM,
2524 .device = PCI_DEVICE_ID_ROHM_ML7223_GBE,
2525 .subvendor = PCI_ANY_ID,
2526 .subdevice = PCI_ANY_ID,
2527 .class = (PCI_CLASS_NETWORK_ETHERNET << 8),
2528 .class_mask = (0xFFFF00)
2529 },
2530 {.vendor = PCI_VENDOR_ID_ROHM,
2531 .device = PCI_DEVICE_ID_ROHM_ML7831_GBE,
2532 .subvendor = PCI_ANY_ID,
2533 .subdevice = PCI_ANY_ID,
2534 .class = (PCI_CLASS_NETWORK_ETHERNET << 8),
2535 .class_mask = (0xFFFF00)
2536 },
2537 /* required last entry */
2538 {0}
2539};
2540
2541#ifdef CONFIG_PM
2542static const struct dev_pm_ops pch_gbe_pm_ops = {
2543 .suspend = pch_gbe_suspend,
2544 .resume = pch_gbe_resume,
2545 .freeze = pch_gbe_suspend,
2546 .thaw = pch_gbe_resume,
2547 .poweroff = pch_gbe_suspend,
2548 .restore = pch_gbe_resume,
2549};
2550#endif
2551
2552static struct pci_error_handlers pch_gbe_err_handler = {
2553 .error_detected = pch_gbe_io_error_detected,
2554 .slot_reset = pch_gbe_io_slot_reset,
2555 .resume = pch_gbe_io_resume
2556};
2557
2558static struct pci_driver pch_gbe_driver = {
2559 .name = KBUILD_MODNAME,
2560 .id_table = pch_gbe_pcidev_id,
2561 .probe = pch_gbe_probe,
2562 .remove = pch_gbe_remove,
2563#ifdef CONFIG_PM
2564 .driver.pm = &pch_gbe_pm_ops,
2565#endif
2566 .shutdown = pch_gbe_shutdown,
2567 .err_handler = &pch_gbe_err_handler
2568};
2569
2570
2571static int __init pch_gbe_init_module(void)
2572{
2573 int ret;
2574
2575 ret = pci_register_driver(&pch_gbe_driver);
2576 if (copybreak != PCH_GBE_COPYBREAK_DEFAULT) {
2577 if (copybreak == 0) {
2578 pr_info("copybreak disabled\n");
2579 } else {
2580 pr_info("copybreak enabled for packets <= %u bytes\n",
2581 copybreak);
2582 }
2583 }
2584 return ret;
2585}
2586
2587static void __exit pch_gbe_exit_module(void)
2588{
2589 pci_unregister_driver(&pch_gbe_driver);
2590}
2591
2592module_init(pch_gbe_init_module);
2593module_exit(pch_gbe_exit_module);
2594
2595MODULE_DESCRIPTION("EG20T PCH Gigabit ethernet Driver");
2596MODULE_AUTHOR("OKI SEMICONDUCTOR, <toshiharu-linux@dsn.okisemi.com>");
2597MODULE_LICENSE("GPL");
2598MODULE_VERSION(DRV_VERSION);
2599MODULE_DEVICE_TABLE(pci, pch_gbe_pcidev_id);
2600
2601module_param(copybreak, uint, 0644);
2602MODULE_PARM_DESC(copybreak,
2603 "Maximum size of packet that is copied to a new buffer on receive");
2604
2605/* pch_gbe_main.c */
diff --git a/drivers/net/pch_gbe/pch_gbe_param.c b/drivers/net/pch_gbe/pch_gbe_param.c
new file mode 100644
index 00000000000..5b5d90a47e2
--- /dev/null
+++ b/drivers/net/pch_gbe/pch_gbe_param.c
@@ -0,0 +1,503 @@
1/*
2 * Copyright (C) 1999 - 2010 Intel Corporation.
3 * Copyright (C) 2010 OKI SEMICONDUCTOR Co., LTD.
4 *
5 * This code was derived from the Intel e1000e Linux driver.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
19 */
20
21#include "pch_gbe.h"
22
23#define OPTION_UNSET -1
24#define OPTION_DISABLED 0
25#define OPTION_ENABLED 1
26
27/**
28 * TxDescriptors - Transmit Descriptor Count
29 * @Valid Range: PCH_GBE_MIN_TXD - PCH_GBE_MAX_TXD
30 * @Default Value: PCH_GBE_DEFAULT_TXD
31 */
32static int TxDescriptors = OPTION_UNSET;
33module_param(TxDescriptors, int, 0);
34MODULE_PARM_DESC(TxDescriptors, "Number of transmit descriptors");
35
36/**
37 * RxDescriptors -Receive Descriptor Count
38 * @Valid Range: PCH_GBE_MIN_RXD - PCH_GBE_MAX_RXD
39 * @Default Value: PCH_GBE_DEFAULT_RXD
40 */
41static int RxDescriptors = OPTION_UNSET;
42module_param(RxDescriptors, int, 0);
43MODULE_PARM_DESC(RxDescriptors, "Number of receive descriptors");
44
45/**
46 * Speed - User Specified Speed Override
47 * @Valid Range: 0, 10, 100, 1000
48 * - 0: auto-negotiate at all supported speeds
49 * - 10: only link at 10 Mbps
50 * - 100: only link at 100 Mbps
51 * - 1000: only link at 1000 Mbps
52 * @Default Value: 0
53 */
54static int Speed = OPTION_UNSET;
55module_param(Speed, int, 0);
56MODULE_PARM_DESC(Speed, "Speed setting");
57
58/**
59 * Duplex - User Specified Duplex Override
60 * @Valid Range: 0-2
61 * - 0: auto-negotiate for duplex
62 * - 1: only link at half duplex
63 * - 2: only link at full duplex
64 * @Default Value: 0
65 */
66static int Duplex = OPTION_UNSET;
67module_param(Duplex, int, 0);
68MODULE_PARM_DESC(Duplex, "Duplex setting");
69
70#define HALF_DUPLEX 1
71#define FULL_DUPLEX 2
72
73/**
74 * AutoNeg - Auto-negotiation Advertisement Override
75 * @Valid Range: 0x01-0x0F, 0x20-0x2F
76 *
77 * The AutoNeg value is a bit mask describing which speed and duplex
78 * combinations should be advertised during auto-negotiation.
79 * The supported speed and duplex modes are listed below
80 *
81 * Bit 7 6 5 4 3 2 1 0
82 * Speed (Mbps) N/A N/A 1000 N/A 100 100 10 10
83 * Duplex Full Full Half Full Half
84 *
85 * @Default Value: 0x2F (copper)
86 */
87static int AutoNeg = OPTION_UNSET;
88module_param(AutoNeg, int, 0);
89MODULE_PARM_DESC(AutoNeg, "Advertised auto-negotiation setting");
90
91#define PHY_ADVERTISE_10_HALF 0x0001
92#define PHY_ADVERTISE_10_FULL 0x0002
93#define PHY_ADVERTISE_100_HALF 0x0004
94#define PHY_ADVERTISE_100_FULL 0x0008
95#define PHY_ADVERTISE_1000_HALF 0x0010 /* Not used, just FYI */
96#define PHY_ADVERTISE_1000_FULL 0x0020
97#define PCH_AUTONEG_ADVERTISE_DEFAULT 0x2F
98
99/**
100 * FlowControl - User Specified Flow Control Override
101 * @Valid Range: 0-3
102 * - 0: No Flow Control
103 * - 1: Rx only, respond to PAUSE frames but do not generate them
104 * - 2: Tx only, generate PAUSE frames but ignore them on receive
105 * - 3: Full Flow Control Support
106 * @Default Value: Read flow control settings from the EEPROM
107 */
108static int FlowControl = OPTION_UNSET;
109module_param(FlowControl, int, 0);
110MODULE_PARM_DESC(FlowControl, "Flow Control setting");
111
112/*
113 * XsumRX - Receive Checksum Offload Enable/Disable
114 * @Valid Range: 0, 1
115 * - 0: disables all checksum offload
116 * - 1: enables receive IP/TCP/UDP checksum offload
117 * @Default Value: PCH_GBE_DEFAULT_RX_CSUM
118 */
119static int XsumRX = OPTION_UNSET;
120module_param(XsumRX, int, 0);
121MODULE_PARM_DESC(XsumRX, "Disable or enable Receive Checksum offload");
122
123#define PCH_GBE_DEFAULT_RX_CSUM true /* trueorfalse */
124
125/*
126 * XsumTX - Transmit Checksum Offload Enable/Disable
127 * @Valid Range: 0, 1
128 * - 0: disables all checksum offload
129 * - 1: enables transmit IP/TCP/UDP checksum offload
130 * @Default Value: PCH_GBE_DEFAULT_TX_CSUM
131 */
132static int XsumTX = OPTION_UNSET;
133module_param(XsumTX, int, 0);
134MODULE_PARM_DESC(XsumTX, "Disable or enable Transmit Checksum offload");
135
136#define PCH_GBE_DEFAULT_TX_CSUM true /* trueorfalse */
137
138/**
139 * pch_gbe_option - Force the MAC's flow control settings
140 * @hw: Pointer to the HW structure
141 * Returns
142 * 0: Successful.
143 * Negative value: Failed.
144 */
145struct pch_gbe_option {
146 enum { enable_option, range_option, list_option } type;
147 char *name;
148 char *err;
149 int def;
150 union {
151 struct { /* range_option info */
152 int min;
153 int max;
154 } r;
155 struct { /* list_option info */
156 int nr;
157 const struct pch_gbe_opt_list { int i; char *str; } *p;
158 } l;
159 } arg;
160};
161
162static const struct pch_gbe_opt_list speed_list[] = {
163 { 0, "" },
164 { SPEED_10, "" },
165 { SPEED_100, "" },
166 { SPEED_1000, "" }
167};
168
169static const struct pch_gbe_opt_list dplx_list[] = {
170 { 0, "" },
171 { HALF_DUPLEX, "" },
172 { FULL_DUPLEX, "" }
173};
174
175static const struct pch_gbe_opt_list an_list[] =
176 #define AA "AutoNeg advertising "
177 {{ 0x01, AA "10/HD" },
178 { 0x02, AA "10/FD" },
179 { 0x03, AA "10/FD, 10/HD" },
180 { 0x04, AA "100/HD" },
181 { 0x05, AA "100/HD, 10/HD" },
182 { 0x06, AA "100/HD, 10/FD" },
183 { 0x07, AA "100/HD, 10/FD, 10/HD" },
184 { 0x08, AA "100/FD" },
185 { 0x09, AA "100/FD, 10/HD" },
186 { 0x0a, AA "100/FD, 10/FD" },
187 { 0x0b, AA "100/FD, 10/FD, 10/HD" },
188 { 0x0c, AA "100/FD, 100/HD" },
189 { 0x0d, AA "100/FD, 100/HD, 10/HD" },
190 { 0x0e, AA "100/FD, 100/HD, 10/FD" },
191 { 0x0f, AA "100/FD, 100/HD, 10/FD, 10/HD" },
192 { 0x20, AA "1000/FD" },
193 { 0x21, AA "1000/FD, 10/HD" },
194 { 0x22, AA "1000/FD, 10/FD" },
195 { 0x23, AA "1000/FD, 10/FD, 10/HD" },
196 { 0x24, AA "1000/FD, 100/HD" },
197 { 0x25, AA "1000/FD, 100/HD, 10/HD" },
198 { 0x26, AA "1000/FD, 100/HD, 10/FD" },
199 { 0x27, AA "1000/FD, 100/HD, 10/FD, 10/HD" },
200 { 0x28, AA "1000/FD, 100/FD" },
201 { 0x29, AA "1000/FD, 100/FD, 10/HD" },
202 { 0x2a, AA "1000/FD, 100/FD, 10/FD" },
203 { 0x2b, AA "1000/FD, 100/FD, 10/FD, 10/HD" },
204 { 0x2c, AA "1000/FD, 100/FD, 100/HD" },
205 { 0x2d, AA "1000/FD, 100/FD, 100/HD, 10/HD" },
206 { 0x2e, AA "1000/FD, 100/FD, 100/HD, 10/FD" },
207 { 0x2f, AA "1000/FD, 100/FD, 100/HD, 10/FD, 10/HD" }
208};
209
210static const struct pch_gbe_opt_list fc_list[] = {
211 { PCH_GBE_FC_NONE, "Flow Control Disabled" },
212 { PCH_GBE_FC_RX_PAUSE, "Flow Control Receive Only" },
213 { PCH_GBE_FC_TX_PAUSE, "Flow Control Transmit Only" },
214 { PCH_GBE_FC_FULL, "Flow Control Enabled" }
215};
216
217/**
218 * pch_gbe_validate_option - Validate option
219 * @value: value
220 * @opt: option
221 * @adapter: Board private structure
222 * Returns
223 * 0: Successful.
224 * Negative value: Failed.
225 */
226static int pch_gbe_validate_option(int *value,
227 const struct pch_gbe_option *opt,
228 struct pch_gbe_adapter *adapter)
229{
230 if (*value == OPTION_UNSET) {
231 *value = opt->def;
232 return 0;
233 }
234
235 switch (opt->type) {
236 case enable_option:
237 switch (*value) {
238 case OPTION_ENABLED:
239 pr_debug("%s Enabled\n", opt->name);
240 return 0;
241 case OPTION_DISABLED:
242 pr_debug("%s Disabled\n", opt->name);
243 return 0;
244 }
245 break;
246 case range_option:
247 if (*value >= opt->arg.r.min && *value <= opt->arg.r.max) {
248 pr_debug("%s set to %i\n", opt->name, *value);
249 return 0;
250 }
251 break;
252 case list_option: {
253 int i;
254 const struct pch_gbe_opt_list *ent;
255
256 for (i = 0; i < opt->arg.l.nr; i++) {
257 ent = &opt->arg.l.p[i];
258 if (*value == ent->i) {
259 if (ent->str[0] != '\0')
260 pr_debug("%s\n", ent->str);
261 return 0;
262 }
263 }
264 }
265 break;
266 default:
267 BUG();
268 }
269
270 pr_debug("Invalid %s value specified (%i) %s\n",
271 opt->name, *value, opt->err);
272 *value = opt->def;
273 return -1;
274}
275
276/**
277 * pch_gbe_check_copper_options - Range Checking for Link Options, Copper Version
278 * @adapter: Board private structure
279 */
280static void pch_gbe_check_copper_options(struct pch_gbe_adapter *adapter)
281{
282 struct pch_gbe_hw *hw = &adapter->hw;
283 int speed, dplx;
284
285 { /* Speed */
286 static const struct pch_gbe_option opt = {
287 .type = list_option,
288 .name = "Speed",
289 .err = "parameter ignored",
290 .def = 0,
291 .arg = { .l = { .nr = (int)ARRAY_SIZE(speed_list),
292 .p = speed_list } }
293 };
294 speed = Speed;
295 pch_gbe_validate_option(&speed, &opt, adapter);
296 }
297 { /* Duplex */
298 static const struct pch_gbe_option opt = {
299 .type = list_option,
300 .name = "Duplex",
301 .err = "parameter ignored",
302 .def = 0,
303 .arg = { .l = { .nr = (int)ARRAY_SIZE(dplx_list),
304 .p = dplx_list } }
305 };
306 dplx = Duplex;
307 pch_gbe_validate_option(&dplx, &opt, adapter);
308 }
309
310 { /* Autoneg */
311 static const struct pch_gbe_option opt = {
312 .type = list_option,
313 .name = "AutoNeg",
314 .err = "parameter ignored",
315 .def = PCH_AUTONEG_ADVERTISE_DEFAULT,
316 .arg = { .l = { .nr = (int)ARRAY_SIZE(an_list),
317 .p = an_list} }
318 };
319 if (speed || dplx) {
320 pr_debug("AutoNeg specified along with Speed or Duplex, AutoNeg parameter ignored\n");
321 hw->phy.autoneg_advertised = opt.def;
322 } else {
323 hw->phy.autoneg_advertised = AutoNeg;
324 pch_gbe_validate_option(
325 (int *)(&hw->phy.autoneg_advertised),
326 &opt, adapter);
327 }
328 }
329
330 switch (speed + dplx) {
331 case 0:
332 hw->mac.autoneg = hw->mac.fc_autoneg = 1;
333 if ((speed || dplx))
334 pr_debug("Speed and duplex autonegotiation enabled\n");
335 hw->mac.link_speed = SPEED_10;
336 hw->mac.link_duplex = DUPLEX_HALF;
337 break;
338 case HALF_DUPLEX:
339 pr_debug("Half Duplex specified without Speed\n");
340 pr_debug("Using Autonegotiation at Half Duplex only\n");
341 hw->mac.autoneg = hw->mac.fc_autoneg = 1;
342 hw->phy.autoneg_advertised = PHY_ADVERTISE_10_HALF |
343 PHY_ADVERTISE_100_HALF;
344 hw->mac.link_speed = SPEED_10;
345 hw->mac.link_duplex = DUPLEX_HALF;
346 break;
347 case FULL_DUPLEX:
348 pr_debug("Full Duplex specified without Speed\n");
349 pr_debug("Using Autonegotiation at Full Duplex only\n");
350 hw->mac.autoneg = hw->mac.fc_autoneg = 1;
351 hw->phy.autoneg_advertised = PHY_ADVERTISE_10_FULL |
352 PHY_ADVERTISE_100_FULL |
353 PHY_ADVERTISE_1000_FULL;
354 hw->mac.link_speed = SPEED_10;
355 hw->mac.link_duplex = DUPLEX_FULL;
356 break;
357 case SPEED_10:
358 pr_debug("10 Mbps Speed specified without Duplex\n");
359 pr_debug("Using Autonegotiation at 10 Mbps only\n");
360 hw->mac.autoneg = hw->mac.fc_autoneg = 1;
361 hw->phy.autoneg_advertised = PHY_ADVERTISE_10_HALF |
362 PHY_ADVERTISE_10_FULL;
363 hw->mac.link_speed = SPEED_10;
364 hw->mac.link_duplex = DUPLEX_HALF;
365 break;
366 case SPEED_10 + HALF_DUPLEX:
367 pr_debug("Forcing to 10 Mbps Half Duplex\n");
368 hw->mac.autoneg = hw->mac.fc_autoneg = 0;
369 hw->phy.autoneg_advertised = 0;
370 hw->mac.link_speed = SPEED_10;
371 hw->mac.link_duplex = DUPLEX_HALF;
372 break;
373 case SPEED_10 + FULL_DUPLEX:
374 pr_debug("Forcing to 10 Mbps Full Duplex\n");
375 hw->mac.autoneg = hw->mac.fc_autoneg = 0;
376 hw->phy.autoneg_advertised = 0;
377 hw->mac.link_speed = SPEED_10;
378 hw->mac.link_duplex = DUPLEX_FULL;
379 break;
380 case SPEED_100:
381 pr_debug("100 Mbps Speed specified without Duplex\n");
382 pr_debug("Using Autonegotiation at 100 Mbps only\n");
383 hw->mac.autoneg = hw->mac.fc_autoneg = 1;
384 hw->phy.autoneg_advertised = PHY_ADVERTISE_100_HALF |
385 PHY_ADVERTISE_100_FULL;
386 hw->mac.link_speed = SPEED_100;
387 hw->mac.link_duplex = DUPLEX_HALF;
388 break;
389 case SPEED_100 + HALF_DUPLEX:
390 pr_debug("Forcing to 100 Mbps Half Duplex\n");
391 hw->mac.autoneg = hw->mac.fc_autoneg = 0;
392 hw->phy.autoneg_advertised = 0;
393 hw->mac.link_speed = SPEED_100;
394 hw->mac.link_duplex = DUPLEX_HALF;
395 break;
396 case SPEED_100 + FULL_DUPLEX:
397 pr_debug("Forcing to 100 Mbps Full Duplex\n");
398 hw->mac.autoneg = hw->mac.fc_autoneg = 0;
399 hw->phy.autoneg_advertised = 0;
400 hw->mac.link_speed = SPEED_100;
401 hw->mac.link_duplex = DUPLEX_FULL;
402 break;
403 case SPEED_1000:
404 pr_debug("1000 Mbps Speed specified without Duplex\n");
405 goto full_duplex_only;
406 case SPEED_1000 + HALF_DUPLEX:
407 pr_debug("Half Duplex is not supported at 1000 Mbps\n");
408 /* fall through */
409 case SPEED_1000 + FULL_DUPLEX:
410full_duplex_only:
411 pr_debug("Using Autonegotiation at 1000 Mbps Full Duplex only\n");
412 hw->mac.autoneg = hw->mac.fc_autoneg = 1;
413 hw->phy.autoneg_advertised = PHY_ADVERTISE_1000_FULL;
414 hw->mac.link_speed = SPEED_1000;
415 hw->mac.link_duplex = DUPLEX_FULL;
416 break;
417 default:
418 BUG();
419 }
420}
421
422/**
423 * pch_gbe_check_options - Range Checking for Command Line Parameters
424 * @adapter: Board private structure
425 */
426void pch_gbe_check_options(struct pch_gbe_adapter *adapter)
427{
428 struct pch_gbe_hw *hw = &adapter->hw;
429 struct net_device *dev = adapter->netdev;
430 int val;
431
432 { /* Transmit Descriptor Count */
433 static const struct pch_gbe_option opt = {
434 .type = range_option,
435 .name = "Transmit Descriptors",
436 .err = "using default of "
437 __MODULE_STRING(PCH_GBE_DEFAULT_TXD),
438 .def = PCH_GBE_DEFAULT_TXD,
439 .arg = { .r = { .min = PCH_GBE_MIN_TXD,
440 .max = PCH_GBE_MAX_TXD } }
441 };
442 struct pch_gbe_tx_ring *tx_ring = adapter->tx_ring;
443 tx_ring->count = TxDescriptors;
444 pch_gbe_validate_option(&tx_ring->count, &opt, adapter);
445 tx_ring->count = roundup(tx_ring->count,
446 PCH_GBE_TX_DESC_MULTIPLE);
447 }
448 { /* Receive Descriptor Count */
449 static const struct pch_gbe_option opt = {
450 .type = range_option,
451 .name = "Receive Descriptors",
452 .err = "using default of "
453 __MODULE_STRING(PCH_GBE_DEFAULT_RXD),
454 .def = PCH_GBE_DEFAULT_RXD,
455 .arg = { .r = { .min = PCH_GBE_MIN_RXD,
456 .max = PCH_GBE_MAX_RXD } }
457 };
458 struct pch_gbe_rx_ring *rx_ring = adapter->rx_ring;
459 rx_ring->count = RxDescriptors;
460 pch_gbe_validate_option(&rx_ring->count, &opt, adapter);
461 rx_ring->count = roundup(rx_ring->count,
462 PCH_GBE_RX_DESC_MULTIPLE);
463 }
464 { /* Checksum Offload Enable/Disable */
465 static const struct pch_gbe_option opt = {
466 .type = enable_option,
467 .name = "Checksum Offload",
468 .err = "defaulting to Enabled",
469 .def = PCH_GBE_DEFAULT_RX_CSUM
470 };
471 val = XsumRX;
472 pch_gbe_validate_option(&val, &opt, adapter);
473 if (!val)
474 dev->features &= ~NETIF_F_RXCSUM;
475 }
476 { /* Checksum Offload Enable/Disable */
477 static const struct pch_gbe_option opt = {
478 .type = enable_option,
479 .name = "Checksum Offload",
480 .err = "defaulting to Enabled",
481 .def = PCH_GBE_DEFAULT_TX_CSUM
482 };
483 val = XsumTX;
484 pch_gbe_validate_option(&val, &opt, adapter);
485 if (!val)
486 dev->features &= ~NETIF_F_ALL_CSUM;
487 }
488 { /* Flow Control */
489 static const struct pch_gbe_option opt = {
490 .type = list_option,
491 .name = "Flow Control",
492 .err = "reading default settings from EEPROM",
493 .def = PCH_GBE_FC_DEFAULT,
494 .arg = { .l = { .nr = (int)ARRAY_SIZE(fc_list),
495 .p = fc_list } }
496 };
497 hw->mac.fc = FlowControl;
498 pch_gbe_validate_option((int *)(&hw->mac.fc),
499 &opt, adapter);
500 }
501
502 pch_gbe_check_copper_options(adapter);
503}
diff --git a/drivers/net/pch_gbe/pch_gbe_phy.c b/drivers/net/pch_gbe/pch_gbe_phy.c
new file mode 100644
index 00000000000..28bb9603d73
--- /dev/null
+++ b/drivers/net/pch_gbe/pch_gbe_phy.c
@@ -0,0 +1,274 @@
1/*
2 * Copyright (C) 1999 - 2010 Intel Corporation.
3 * Copyright (C) 2010 OKI SEMICONDUCTOR Co., LTD.
4 *
5 * This code was derived from the Intel e1000e Linux driver.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
19 */
20
21#include "pch_gbe.h"
22#include "pch_gbe_phy.h"
23
24#define PHY_MAX_REG_ADDRESS 0x1F /* 5 bit address bus (0-0x1F) */
25
26/* PHY 1000 MII Register/Bit Definitions */
27/* PHY Registers defined by IEEE */
28#define PHY_CONTROL 0x00 /* Control Register */
29#define PHY_STATUS 0x01 /* Status Regiser */
30#define PHY_ID1 0x02 /* Phy Id Register (word 1) */
31#define PHY_ID2 0x03 /* Phy Id Register (word 2) */
32#define PHY_AUTONEG_ADV 0x04 /* Autoneg Advertisement */
33#define PHY_LP_ABILITY 0x05 /* Link Partner Ability (Base Page) */
34#define PHY_AUTONEG_EXP 0x06 /* Autoneg Expansion Register */
35#define PHY_NEXT_PAGE_TX 0x07 /* Next Page TX */
36#define PHY_LP_NEXT_PAGE 0x08 /* Link Partner Next Page */
37#define PHY_1000T_CTRL 0x09 /* 1000Base-T Control Register */
38#define PHY_1000T_STATUS 0x0A /* 1000Base-T Status Register */
39#define PHY_EXT_STATUS 0x0F /* Extended Status Register */
40#define PHY_PHYSP_CONTROL 0x10 /* PHY Specific Control Register */
41#define PHY_EXT_PHYSP_CONTROL 0x14 /* Extended PHY Specific Control Register */
42#define PHY_LED_CONTROL 0x18 /* LED Control Register */
43#define PHY_EXT_PHYSP_STATUS 0x1B /* Extended PHY Specific Status Register */
44
45/* PHY Control Register */
46#define MII_CR_SPEED_SELECT_MSB 0x0040 /* bits 6,13: 10=1000, 01=100, 00=10 */
47#define MII_CR_COLL_TEST_ENABLE 0x0080 /* Collision test enable */
48#define MII_CR_FULL_DUPLEX 0x0100 /* FDX =1, half duplex =0 */
49#define MII_CR_RESTART_AUTO_NEG 0x0200 /* Restart auto negotiation */
50#define MII_CR_ISOLATE 0x0400 /* Isolate PHY from MII */
51#define MII_CR_POWER_DOWN 0x0800 /* Power down */
52#define MII_CR_AUTO_NEG_EN 0x1000 /* Auto Neg Enable */
53#define MII_CR_SPEED_SELECT_LSB 0x2000 /* bits 6,13: 10=1000, 01=100, 00=10 */
54#define MII_CR_LOOPBACK 0x4000 /* 0 = normal, 1 = loopback */
55#define MII_CR_RESET 0x8000 /* 0 = normal, 1 = PHY reset */
56#define MII_CR_SPEED_1000 0x0040
57#define MII_CR_SPEED_100 0x2000
58#define MII_CR_SPEED_10 0x0000
59
60/* PHY Status Register */
61#define MII_SR_EXTENDED_CAPS 0x0001 /* Extended register capabilities */
62#define MII_SR_JABBER_DETECT 0x0002 /* Jabber Detected */
63#define MII_SR_LINK_STATUS 0x0004 /* Link Status 1 = link */
64#define MII_SR_AUTONEG_CAPS 0x0008 /* Auto Neg Capable */
65#define MII_SR_REMOTE_FAULT 0x0010 /* Remote Fault Detect */
66#define MII_SR_AUTONEG_COMPLETE 0x0020 /* Auto Neg Complete */
67#define MII_SR_PREAMBLE_SUPPRESS 0x0040 /* Preamble may be suppressed */
68#define MII_SR_EXTENDED_STATUS 0x0100 /* Ext. status info in Reg 0x0F */
69#define MII_SR_100T2_HD_CAPS 0x0200 /* 100T2 Half Duplex Capable */
70#define MII_SR_100T2_FD_CAPS 0x0400 /* 100T2 Full Duplex Capable */
71#define MII_SR_10T_HD_CAPS 0x0800 /* 10T Half Duplex Capable */
72#define MII_SR_10T_FD_CAPS 0x1000 /* 10T Full Duplex Capable */
73#define MII_SR_100X_HD_CAPS 0x2000 /* 100X Half Duplex Capable */
74#define MII_SR_100X_FD_CAPS 0x4000 /* 100X Full Duplex Capable */
75#define MII_SR_100T4_CAPS 0x8000 /* 100T4 Capable */
76
77/* Phy Id Register (word 2) */
78#define PHY_REVISION_MASK 0x000F
79
80/* PHY Specific Control Register */
81#define PHYSP_CTRL_ASSERT_CRS_TX 0x0800
82
83
84/* Default value of PHY register */
85#define PHY_CONTROL_DEFAULT 0x1140 /* Control Register */
86#define PHY_AUTONEG_ADV_DEFAULT 0x01e0 /* Autoneg Advertisement */
87#define PHY_NEXT_PAGE_TX_DEFAULT 0x2001 /* Next Page TX */
88#define PHY_1000T_CTRL_DEFAULT 0x0300 /* 1000Base-T Control Register */
89#define PHY_PHYSP_CONTROL_DEFAULT 0x01EE /* PHY Specific Control Register */
90
91/**
92 * pch_gbe_phy_get_id - Retrieve the PHY ID and revision
93 * @hw: Pointer to the HW structure
94 * Returns
95 * 0: Successful.
96 * Negative value: Failed.
97 */
98s32 pch_gbe_phy_get_id(struct pch_gbe_hw *hw)
99{
100 struct pch_gbe_phy_info *phy = &hw->phy;
101 s32 ret;
102 u16 phy_id1;
103 u16 phy_id2;
104
105 ret = pch_gbe_phy_read_reg_miic(hw, PHY_ID1, &phy_id1);
106 if (ret)
107 return ret;
108 ret = pch_gbe_phy_read_reg_miic(hw, PHY_ID2, &phy_id2);
109 if (ret)
110 return ret;
111 /*
112 * PHY_ID1: [bit15-0:ID(21-6)]
113 * PHY_ID2: [bit15-10:ID(5-0)][bit9-4:Model][bit3-0:revision]
114 */
115 phy->id = (u32)phy_id1;
116 phy->id = ((phy->id << 6) | ((phy_id2 & 0xFC00) >> 10));
117 phy->revision = (u32) (phy_id2 & 0x000F);
118 pr_debug("phy->id : 0x%08x phy->revision : 0x%08x\n",
119 phy->id, phy->revision);
120 return 0;
121}
122
123/**
124 * pch_gbe_phy_read_reg_miic - Read MII control register
125 * @hw: Pointer to the HW structure
126 * @offset: Register offset to be read
127 * @data: Pointer to the read data
128 * Returns
129 * 0: Successful.
130 * -EINVAL: Invalid argument.
131 */
132s32 pch_gbe_phy_read_reg_miic(struct pch_gbe_hw *hw, u32 offset, u16 *data)
133{
134 struct pch_gbe_phy_info *phy = &hw->phy;
135
136 if (offset > PHY_MAX_REG_ADDRESS) {
137 pr_err("PHY Address %d is out of range\n", offset);
138 return -EINVAL;
139 }
140 *data = pch_gbe_mac_ctrl_miim(hw, phy->addr, PCH_GBE_HAL_MIIM_READ,
141 offset, (u16)0);
142 return 0;
143}
144
145/**
146 * pch_gbe_phy_write_reg_miic - Write MII control register
147 * @hw: Pointer to the HW structure
148 * @offset: Register offset to be read
149 * @data: data to write to register at offset
150 * Returns
151 * 0: Successful.
152 * -EINVAL: Invalid argument.
153 */
154s32 pch_gbe_phy_write_reg_miic(struct pch_gbe_hw *hw, u32 offset, u16 data)
155{
156 struct pch_gbe_phy_info *phy = &hw->phy;
157
158 if (offset > PHY_MAX_REG_ADDRESS) {
159 pr_err("PHY Address %d is out of range\n", offset);
160 return -EINVAL;
161 }
162 pch_gbe_mac_ctrl_miim(hw, phy->addr, PCH_GBE_HAL_MIIM_WRITE,
163 offset, data);
164 return 0;
165}
166
167/**
168 * pch_gbe_phy_sw_reset - PHY software reset
169 * @hw: Pointer to the HW structure
170 */
171void pch_gbe_phy_sw_reset(struct pch_gbe_hw *hw)
172{
173 u16 phy_ctrl;
174
175 pch_gbe_phy_read_reg_miic(hw, PHY_CONTROL, &phy_ctrl);
176 phy_ctrl |= MII_CR_RESET;
177 pch_gbe_phy_write_reg_miic(hw, PHY_CONTROL, phy_ctrl);
178 udelay(1);
179}
180
181/**
182 * pch_gbe_phy_hw_reset - PHY hardware reset
183 * @hw: Pointer to the HW structure
184 */
185void pch_gbe_phy_hw_reset(struct pch_gbe_hw *hw)
186{
187 pch_gbe_phy_write_reg_miic(hw, PHY_CONTROL, PHY_CONTROL_DEFAULT);
188 pch_gbe_phy_write_reg_miic(hw, PHY_AUTONEG_ADV,
189 PHY_AUTONEG_ADV_DEFAULT);
190 pch_gbe_phy_write_reg_miic(hw, PHY_NEXT_PAGE_TX,
191 PHY_NEXT_PAGE_TX_DEFAULT);
192 pch_gbe_phy_write_reg_miic(hw, PHY_1000T_CTRL, PHY_1000T_CTRL_DEFAULT);
193 pch_gbe_phy_write_reg_miic(hw, PHY_PHYSP_CONTROL,
194 PHY_PHYSP_CONTROL_DEFAULT);
195}
196
197/**
198 * pch_gbe_phy_power_up - restore link in case the phy was powered down
199 * @hw: Pointer to the HW structure
200 */
201void pch_gbe_phy_power_up(struct pch_gbe_hw *hw)
202{
203 u16 mii_reg;
204
205 mii_reg = 0;
206 /* Just clear the power down bit to wake the phy back up */
207 /* according to the manual, the phy will retain its
208 * settings across a power-down/up cycle */
209 pch_gbe_phy_read_reg_miic(hw, PHY_CONTROL, &mii_reg);
210 mii_reg &= ~MII_CR_POWER_DOWN;
211 pch_gbe_phy_write_reg_miic(hw, PHY_CONTROL, mii_reg);
212}
213
214/**
215 * pch_gbe_phy_power_down - Power down PHY
216 * @hw: Pointer to the HW structure
217 */
218void pch_gbe_phy_power_down(struct pch_gbe_hw *hw)
219{
220 u16 mii_reg;
221
222 mii_reg = 0;
223 /* Power down the PHY so no link is implied when interface is down *
224 * The PHY cannot be powered down if any of the following is TRUE *
225 * (a) WoL is enabled
226 * (b) AMT is active
227 */
228 pch_gbe_phy_read_reg_miic(hw, PHY_CONTROL, &mii_reg);
229 mii_reg |= MII_CR_POWER_DOWN;
230 pch_gbe_phy_write_reg_miic(hw, PHY_CONTROL, mii_reg);
231 mdelay(1);
232}
233
234/**
235 * pch_gbe_phy_set_rgmii - RGMII interface setting
236 * @hw: Pointer to the HW structure
237 */
238inline void pch_gbe_phy_set_rgmii(struct pch_gbe_hw *hw)
239{
240 pch_gbe_phy_sw_reset(hw);
241}
242
243/**
244 * pch_gbe_phy_init_setting - PHY initial setting
245 * @hw: Pointer to the HW structure
246 */
247void pch_gbe_phy_init_setting(struct pch_gbe_hw *hw)
248{
249 struct pch_gbe_adapter *adapter;
250 struct ethtool_cmd cmd = { .cmd = ETHTOOL_GSET };
251 int ret;
252 u16 mii_reg;
253
254 adapter = container_of(hw, struct pch_gbe_adapter, hw);
255 ret = mii_ethtool_gset(&adapter->mii, &cmd);
256 if (ret)
257 pr_err("Error: mii_ethtool_gset\n");
258
259 ethtool_cmd_speed_set(&cmd, hw->mac.link_speed);
260 cmd.duplex = hw->mac.link_duplex;
261 cmd.advertising = hw->phy.autoneg_advertised;
262 cmd.autoneg = hw->mac.autoneg;
263 pch_gbe_phy_write_reg_miic(hw, MII_BMCR, BMCR_RESET);
264 ret = mii_ethtool_sset(&adapter->mii, &cmd);
265 if (ret)
266 pr_err("Error: mii_ethtool_sset\n");
267
268 pch_gbe_phy_sw_reset(hw);
269
270 pch_gbe_phy_read_reg_miic(hw, PHY_PHYSP_CONTROL, &mii_reg);
271 mii_reg |= PHYSP_CTRL_ASSERT_CRS_TX;
272 pch_gbe_phy_write_reg_miic(hw, PHY_PHYSP_CONTROL, mii_reg);
273
274}
diff --git a/drivers/net/pch_gbe/pch_gbe_phy.h b/drivers/net/pch_gbe/pch_gbe_phy.h
new file mode 100644
index 00000000000..03264dc7b5e
--- /dev/null
+++ b/drivers/net/pch_gbe/pch_gbe_phy.h
@@ -0,0 +1,37 @@
1/*
2 * Copyright (C) 1999 - 2010 Intel Corporation.
3 * Copyright (C) 2010 OKI SEMICONDUCTOR Co., LTD.
4 *
5 * This code was derived from the Intel e1000e Linux driver.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
19 */
20#ifndef _PCH_GBE_PHY_H_
21#define _PCH_GBE_PHY_H_
22
23#define PCH_GBE_PHY_REGS_LEN 32
24#define PCH_GBE_PHY_RESET_DELAY_US 10
25#define PCH_GBE_MAC_IFOP_RGMII
26
27s32 pch_gbe_phy_get_id(struct pch_gbe_hw *hw);
28s32 pch_gbe_phy_read_reg_miic(struct pch_gbe_hw *hw, u32 offset, u16 *data);
29s32 pch_gbe_phy_write_reg_miic(struct pch_gbe_hw *hw, u32 offset, u16 data);
30void pch_gbe_phy_sw_reset(struct pch_gbe_hw *hw);
31void pch_gbe_phy_hw_reset(struct pch_gbe_hw *hw);
32void pch_gbe_phy_power_up(struct pch_gbe_hw *hw);
33void pch_gbe_phy_power_down(struct pch_gbe_hw *hw);
34void pch_gbe_phy_set_rgmii(struct pch_gbe_hw *hw);
35void pch_gbe_phy_init_setting(struct pch_gbe_hw *hw);
36
37#endif /* _PCH_GBE_PHY_H_ */