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