diff options
author | Jeff Kirsher <jeffrey.t.kirsher@intel.com> | 2011-04-08 22:06:30 -0400 |
---|---|---|
committer | Jeff Kirsher <jeffrey.t.kirsher@intel.com> | 2011-08-10 23:03:49 -0400 |
commit | aa43c2158d5ae1dc76cccb08cd57a3ffd32c3825 (patch) | |
tree | cdb471f2b2440d551e634f9cbeacf1675daf3ba8 /drivers/net/ethernet/qlogic/netxen | |
parent | dee1ad47f2ee75f5146d83ca757c1b7861c34c3b (diff) |
qlogic: Move the QLogic drivers
Moves the QLogic drivers into drivers/net/ethernet/qlogic/ and
the necessary Kconfig and Makefile changes.
CC: Ron Mercer <ron.mercer@qlogic.com>
CC: Amit Kumar Salecha <amit.salecha@qlogic.com>
CC: Anirban Chakraborty <anirban.chakraborty@qlogic.com>
Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
Acked-by: Anirban Chakraborty <anirban.chakraborty@qlogic.com>
Diffstat (limited to 'drivers/net/ethernet/qlogic/netxen')
-rw-r--r-- | drivers/net/ethernet/qlogic/netxen/Makefile | 29 | ||||
-rw-r--r-- | drivers/net/ethernet/qlogic/netxen/netxen_nic.h | 1441 | ||||
-rw-r--r-- | drivers/net/ethernet/qlogic/netxen/netxen_nic_ctx.c | 793 | ||||
-rw-r--r-- | drivers/net/ethernet/qlogic/netxen/netxen_nic_ethtool.c | 835 | ||||
-rw-r--r-- | drivers/net/ethernet/qlogic/netxen/netxen_nic_hdr.h | 1050 | ||||
-rw-r--r-- | drivers/net/ethernet/qlogic/netxen/netxen_nic_hw.c | 1976 | ||||
-rw-r--r-- | drivers/net/ethernet/qlogic/netxen/netxen_nic_hw.h | 287 | ||||
-rw-r--r-- | drivers/net/ethernet/qlogic/netxen/netxen_nic_init.c | 1949 | ||||
-rw-r--r-- | drivers/net/ethernet/qlogic/netxen/netxen_nic_main.c | 3100 |
9 files changed, 11460 insertions, 0 deletions
diff --git a/drivers/net/ethernet/qlogic/netxen/Makefile b/drivers/net/ethernet/qlogic/netxen/Makefile new file mode 100644 index 000000000000..861a0590b1f4 --- /dev/null +++ b/drivers/net/ethernet/qlogic/netxen/Makefile | |||
@@ -0,0 +1,29 @@ | |||
1 | # Copyright (C) 2003 - 2009 NetXen, Inc. | ||
2 | # Copyright (C) 2009 - QLogic Corporation. | ||
3 | # All rights reserved. | ||
4 | # | ||
5 | # This program is free software; you can redistribute it and/or | ||
6 | # modify it under the terms of the GNU General Public License | ||
7 | # as published by the Free Software Foundation; either version 2 | ||
8 | # of the License, or (at your option) any later version. | ||
9 | # | ||
10 | # This program is distributed in the hope that it will be useful, but | ||
11 | # WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | # GNU General Public License for more details. | ||
14 | # | ||
15 | # You should have received a copy of the GNU General Public License | ||
16 | # along with this program; if not, write to the Free Software | ||
17 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, | ||
18 | # MA 02111-1307, USA. | ||
19 | # | ||
20 | # The full GNU General Public License is included in this distribution | ||
21 | # in the file called "COPYING". | ||
22 | # | ||
23 | # | ||
24 | |||
25 | |||
26 | obj-$(CONFIG_NETXEN_NIC) := netxen_nic.o | ||
27 | |||
28 | netxen_nic-y := netxen_nic_hw.o netxen_nic_main.o netxen_nic_init.o \ | ||
29 | netxen_nic_ethtool.o netxen_nic_ctx.o | ||
diff --git a/drivers/net/ethernet/qlogic/netxen/netxen_nic.h b/drivers/net/ethernet/qlogic/netxen/netxen_nic.h new file mode 100644 index 000000000000..196b660e1d91 --- /dev/null +++ b/drivers/net/ethernet/qlogic/netxen/netxen_nic.h | |||
@@ -0,0 +1,1441 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2003 - 2009 NetXen, Inc. | ||
3 | * Copyright (C) 2009 - QLogic Corporation. | ||
4 | * All rights reserved. | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or | ||
7 | * modify it under the terms of the GNU General Public License | ||
8 | * as published by the Free Software Foundation; either version 2 | ||
9 | * of the License, or (at your option) any later version. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, but | ||
12 | * 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, | ||
19 | * MA 02111-1307, USA. | ||
20 | * | ||
21 | * The full GNU General Public License is included in this distribution | ||
22 | * in the file called "COPYING". | ||
23 | * | ||
24 | */ | ||
25 | |||
26 | #ifndef _NETXEN_NIC_H_ | ||
27 | #define _NETXEN_NIC_H_ | ||
28 | |||
29 | #include <linux/module.h> | ||
30 | #include <linux/kernel.h> | ||
31 | #include <linux/types.h> | ||
32 | #include <linux/ioport.h> | ||
33 | #include <linux/pci.h> | ||
34 | #include <linux/netdevice.h> | ||
35 | #include <linux/etherdevice.h> | ||
36 | #include <linux/ip.h> | ||
37 | #include <linux/in.h> | ||
38 | #include <linux/tcp.h> | ||
39 | #include <linux/skbuff.h> | ||
40 | #include <linux/firmware.h> | ||
41 | |||
42 | #include <linux/ethtool.h> | ||
43 | #include <linux/mii.h> | ||
44 | #include <linux/timer.h> | ||
45 | |||
46 | #include <linux/vmalloc.h> | ||
47 | |||
48 | #include <asm/io.h> | ||
49 | #include <asm/byteorder.h> | ||
50 | |||
51 | #include "netxen_nic_hdr.h" | ||
52 | #include "netxen_nic_hw.h" | ||
53 | |||
54 | #define _NETXEN_NIC_LINUX_MAJOR 4 | ||
55 | #define _NETXEN_NIC_LINUX_MINOR 0 | ||
56 | #define _NETXEN_NIC_LINUX_SUBVERSION 76 | ||
57 | #define NETXEN_NIC_LINUX_VERSIONID "4.0.76" | ||
58 | |||
59 | #define NETXEN_VERSION_CODE(a, b, c) (((a) << 24) + ((b) << 16) + (c)) | ||
60 | #define _major(v) (((v) >> 24) & 0xff) | ||
61 | #define _minor(v) (((v) >> 16) & 0xff) | ||
62 | #define _build(v) ((v) & 0xffff) | ||
63 | |||
64 | /* version in image has weird encoding: | ||
65 | * 7:0 - major | ||
66 | * 15:8 - minor | ||
67 | * 31:16 - build (little endian) | ||
68 | */ | ||
69 | #define NETXEN_DECODE_VERSION(v) \ | ||
70 | NETXEN_VERSION_CODE(((v) & 0xff), (((v) >> 8) & 0xff), ((v) >> 16)) | ||
71 | |||
72 | #define NETXEN_NUM_FLASH_SECTORS (64) | ||
73 | #define NETXEN_FLASH_SECTOR_SIZE (64 * 1024) | ||
74 | #define NETXEN_FLASH_TOTAL_SIZE (NETXEN_NUM_FLASH_SECTORS \ | ||
75 | * NETXEN_FLASH_SECTOR_SIZE) | ||
76 | |||
77 | #define RCV_DESC_RINGSIZE(rds_ring) \ | ||
78 | (sizeof(struct rcv_desc) * (rds_ring)->num_desc) | ||
79 | #define RCV_BUFF_RINGSIZE(rds_ring) \ | ||
80 | (sizeof(struct netxen_rx_buffer) * rds_ring->num_desc) | ||
81 | #define STATUS_DESC_RINGSIZE(sds_ring) \ | ||
82 | (sizeof(struct status_desc) * (sds_ring)->num_desc) | ||
83 | #define TX_BUFF_RINGSIZE(tx_ring) \ | ||
84 | (sizeof(struct netxen_cmd_buffer) * tx_ring->num_desc) | ||
85 | #define TX_DESC_RINGSIZE(tx_ring) \ | ||
86 | (sizeof(struct cmd_desc_type0) * tx_ring->num_desc) | ||
87 | |||
88 | #define find_diff_among(a,b,range) ((a)<(b)?((b)-(a)):((b)+(range)-(a))) | ||
89 | |||
90 | #define NETXEN_RCV_PRODUCER_OFFSET 0 | ||
91 | #define NETXEN_RCV_PEG_DB_ID 2 | ||
92 | #define NETXEN_HOST_DUMMY_DMA_SIZE 1024 | ||
93 | #define FLASH_SUCCESS 0 | ||
94 | |||
95 | #define ADDR_IN_WINDOW1(off) \ | ||
96 | ((off > NETXEN_CRB_PCIX_HOST2) && (off < NETXEN_CRB_MAX)) ? 1 : 0 | ||
97 | |||
98 | #define ADDR_IN_RANGE(addr, low, high) \ | ||
99 | (((addr) < (high)) && ((addr) >= (low))) | ||
100 | |||
101 | /* | ||
102 | * normalize a 64MB crb address to 32MB PCI window | ||
103 | * To use NETXEN_CRB_NORMALIZE, window _must_ be set to 1 | ||
104 | */ | ||
105 | #define NETXEN_CRB_NORMAL(reg) \ | ||
106 | ((reg) - NETXEN_CRB_PCIX_HOST2 + NETXEN_CRB_PCIX_HOST) | ||
107 | |||
108 | #define NETXEN_CRB_NORMALIZE(adapter, reg) \ | ||
109 | pci_base_offset(adapter, NETXEN_CRB_NORMAL(reg)) | ||
110 | |||
111 | #define DB_NORMALIZE(adapter, off) \ | ||
112 | (adapter->ahw.db_base + (off)) | ||
113 | |||
114 | #define NX_P2_C0 0x24 | ||
115 | #define NX_P2_C1 0x25 | ||
116 | #define NX_P3_A0 0x30 | ||
117 | #define NX_P3_A2 0x30 | ||
118 | #define NX_P3_B0 0x40 | ||
119 | #define NX_P3_B1 0x41 | ||
120 | #define NX_P3_B2 0x42 | ||
121 | #define NX_P3P_A0 0x50 | ||
122 | |||
123 | #define NX_IS_REVISION_P2(REVISION) (REVISION <= NX_P2_C1) | ||
124 | #define NX_IS_REVISION_P3(REVISION) (REVISION >= NX_P3_A0) | ||
125 | #define NX_IS_REVISION_P3P(REVISION) (REVISION >= NX_P3P_A0) | ||
126 | |||
127 | #define FIRST_PAGE_GROUP_START 0 | ||
128 | #define FIRST_PAGE_GROUP_END 0x100000 | ||
129 | |||
130 | #define SECOND_PAGE_GROUP_START 0x6000000 | ||
131 | #define SECOND_PAGE_GROUP_END 0x68BC000 | ||
132 | |||
133 | #define THIRD_PAGE_GROUP_START 0x70E4000 | ||
134 | #define THIRD_PAGE_GROUP_END 0x8000000 | ||
135 | |||
136 | #define FIRST_PAGE_GROUP_SIZE FIRST_PAGE_GROUP_END - FIRST_PAGE_GROUP_START | ||
137 | #define SECOND_PAGE_GROUP_SIZE SECOND_PAGE_GROUP_END - SECOND_PAGE_GROUP_START | ||
138 | #define THIRD_PAGE_GROUP_SIZE THIRD_PAGE_GROUP_END - THIRD_PAGE_GROUP_START | ||
139 | |||
140 | #define P2_MAX_MTU (8000) | ||
141 | #define P3_MAX_MTU (9600) | ||
142 | #define NX_ETHERMTU 1500 | ||
143 | #define NX_MAX_ETHERHDR 32 /* This contains some padding */ | ||
144 | |||
145 | #define NX_P2_RX_BUF_MAX_LEN 1760 | ||
146 | #define NX_P3_RX_BUF_MAX_LEN (NX_MAX_ETHERHDR + NX_ETHERMTU) | ||
147 | #define NX_P2_RX_JUMBO_BUF_MAX_LEN (NX_MAX_ETHERHDR + P2_MAX_MTU) | ||
148 | #define NX_P3_RX_JUMBO_BUF_MAX_LEN (NX_MAX_ETHERHDR + P3_MAX_MTU) | ||
149 | #define NX_CT_DEFAULT_RX_BUF_LEN 2048 | ||
150 | #define NX_LRO_BUFFER_EXTRA 2048 | ||
151 | |||
152 | #define NX_RX_LRO_BUFFER_LENGTH (8060) | ||
153 | |||
154 | /* | ||
155 | * Maximum number of ring contexts | ||
156 | */ | ||
157 | #define MAX_RING_CTX 1 | ||
158 | |||
159 | /* Opcodes to be used with the commands */ | ||
160 | #define TX_ETHER_PKT 0x01 | ||
161 | #define TX_TCP_PKT 0x02 | ||
162 | #define TX_UDP_PKT 0x03 | ||
163 | #define TX_IP_PKT 0x04 | ||
164 | #define TX_TCP_LSO 0x05 | ||
165 | #define TX_TCP_LSO6 0x06 | ||
166 | #define TX_IPSEC 0x07 | ||
167 | #define TX_IPSEC_CMD 0x0a | ||
168 | #define TX_TCPV6_PKT 0x0b | ||
169 | #define TX_UDPV6_PKT 0x0c | ||
170 | |||
171 | /* The following opcodes are for internal consumption. */ | ||
172 | #define NETXEN_CONTROL_OP 0x10 | ||
173 | #define PEGNET_REQUEST 0x11 | ||
174 | |||
175 | #define MAX_NUM_CARDS 4 | ||
176 | |||
177 | #define NETXEN_MAX_FRAGS_PER_TX 14 | ||
178 | #define MAX_TSO_HEADER_DESC 2 | ||
179 | #define MGMT_CMD_DESC_RESV 4 | ||
180 | #define TX_STOP_THRESH ((MAX_SKB_FRAGS >> 2) + MAX_TSO_HEADER_DESC \ | ||
181 | + MGMT_CMD_DESC_RESV) | ||
182 | #define NX_MAX_TX_TIMEOUTS 2 | ||
183 | |||
184 | /* | ||
185 | * Following are the states of the Phantom. Phantom will set them and | ||
186 | * Host will read to check if the fields are correct. | ||
187 | */ | ||
188 | #define PHAN_INITIALIZE_START 0xff00 | ||
189 | #define PHAN_INITIALIZE_FAILED 0xffff | ||
190 | #define PHAN_INITIALIZE_COMPLETE 0xff01 | ||
191 | |||
192 | /* Host writes the following to notify that it has done the init-handshake */ | ||
193 | #define PHAN_INITIALIZE_ACK 0xf00f | ||
194 | |||
195 | #define NUM_RCV_DESC_RINGS 3 | ||
196 | #define NUM_STS_DESC_RINGS 4 | ||
197 | |||
198 | #define RCV_RING_NORMAL 0 | ||
199 | #define RCV_RING_JUMBO 1 | ||
200 | #define RCV_RING_LRO 2 | ||
201 | |||
202 | #define MIN_CMD_DESCRIPTORS 64 | ||
203 | #define MIN_RCV_DESCRIPTORS 64 | ||
204 | #define MIN_JUMBO_DESCRIPTORS 32 | ||
205 | |||
206 | #define MAX_CMD_DESCRIPTORS 1024 | ||
207 | #define MAX_RCV_DESCRIPTORS_1G 4096 | ||
208 | #define MAX_RCV_DESCRIPTORS_10G 8192 | ||
209 | #define MAX_JUMBO_RCV_DESCRIPTORS_1G 512 | ||
210 | #define MAX_JUMBO_RCV_DESCRIPTORS_10G 1024 | ||
211 | #define MAX_LRO_RCV_DESCRIPTORS 8 | ||
212 | |||
213 | #define DEFAULT_RCV_DESCRIPTORS_1G 2048 | ||
214 | #define DEFAULT_RCV_DESCRIPTORS_10G 4096 | ||
215 | |||
216 | #define NETXEN_CTX_SIGNATURE 0xdee0 | ||
217 | #define NETXEN_CTX_SIGNATURE_V2 0x0002dee0 | ||
218 | #define NETXEN_CTX_RESET 0xbad0 | ||
219 | #define NETXEN_CTX_D3_RESET 0xacc0 | ||
220 | #define NETXEN_RCV_PRODUCER(ringid) (ringid) | ||
221 | |||
222 | #define PHAN_PEG_RCV_INITIALIZED 0xff01 | ||
223 | #define PHAN_PEG_RCV_START_INITIALIZE 0xff00 | ||
224 | |||
225 | #define get_next_index(index, length) \ | ||
226 | (((index) + 1) & ((length) - 1)) | ||
227 | |||
228 | #define get_index_range(index,length,count) \ | ||
229 | (((index) + (count)) & ((length) - 1)) | ||
230 | |||
231 | #define MPORT_SINGLE_FUNCTION_MODE 0x1111 | ||
232 | #define MPORT_MULTI_FUNCTION_MODE 0x2222 | ||
233 | |||
234 | #define NX_MAX_PCI_FUNC 8 | ||
235 | |||
236 | /* | ||
237 | * NetXen host-peg signal message structure | ||
238 | * | ||
239 | * Bit 0-1 : peg_id => 0x2 for tx and 01 for rx | ||
240 | * Bit 2 : priv_id => must be 1 | ||
241 | * Bit 3-17 : count => for doorbell | ||
242 | * Bit 18-27 : ctx_id => Context id | ||
243 | * Bit 28-31 : opcode | ||
244 | */ | ||
245 | |||
246 | typedef u32 netxen_ctx_msg; | ||
247 | |||
248 | #define netxen_set_msg_peg_id(config_word, val) \ | ||
249 | ((config_word) &= ~3, (config_word) |= val & 3) | ||
250 | #define netxen_set_msg_privid(config_word) \ | ||
251 | ((config_word) |= 1 << 2) | ||
252 | #define netxen_set_msg_count(config_word, val) \ | ||
253 | ((config_word) &= ~(0x7fff<<3), (config_word) |= (val & 0x7fff) << 3) | ||
254 | #define netxen_set_msg_ctxid(config_word, val) \ | ||
255 | ((config_word) &= ~(0x3ff<<18), (config_word) |= (val & 0x3ff) << 18) | ||
256 | #define netxen_set_msg_opcode(config_word, val) \ | ||
257 | ((config_word) &= ~(0xf<<28), (config_word) |= (val & 0xf) << 28) | ||
258 | |||
259 | struct netxen_rcv_ring { | ||
260 | __le64 addr; | ||
261 | __le32 size; | ||
262 | __le32 rsrvd; | ||
263 | }; | ||
264 | |||
265 | struct netxen_sts_ring { | ||
266 | __le64 addr; | ||
267 | __le32 size; | ||
268 | __le16 msi_index; | ||
269 | __le16 rsvd; | ||
270 | } ; | ||
271 | |||
272 | struct netxen_ring_ctx { | ||
273 | |||
274 | /* one command ring */ | ||
275 | __le64 cmd_consumer_offset; | ||
276 | __le64 cmd_ring_addr; | ||
277 | __le32 cmd_ring_size; | ||
278 | __le32 rsrvd; | ||
279 | |||
280 | /* three receive rings */ | ||
281 | struct netxen_rcv_ring rcv_rings[NUM_RCV_DESC_RINGS]; | ||
282 | |||
283 | __le64 sts_ring_addr; | ||
284 | __le32 sts_ring_size; | ||
285 | |||
286 | __le32 ctx_id; | ||
287 | |||
288 | __le64 rsrvd_2[3]; | ||
289 | __le32 sts_ring_count; | ||
290 | __le32 rsrvd_3; | ||
291 | struct netxen_sts_ring sts_rings[NUM_STS_DESC_RINGS]; | ||
292 | |||
293 | } __attribute__ ((aligned(64))); | ||
294 | |||
295 | /* | ||
296 | * Following data structures describe the descriptors that will be used. | ||
297 | * Added fileds of tcpHdrSize and ipHdrSize, The driver needs to do it only when | ||
298 | * we are doing LSO (above the 1500 size packet) only. | ||
299 | */ | ||
300 | |||
301 | /* | ||
302 | * The size of reference handle been changed to 16 bits to pass the MSS fields | ||
303 | * for the LSO packet | ||
304 | */ | ||
305 | |||
306 | #define FLAGS_CHECKSUM_ENABLED 0x01 | ||
307 | #define FLAGS_LSO_ENABLED 0x02 | ||
308 | #define FLAGS_IPSEC_SA_ADD 0x04 | ||
309 | #define FLAGS_IPSEC_SA_DELETE 0x08 | ||
310 | #define FLAGS_VLAN_TAGGED 0x10 | ||
311 | #define FLAGS_VLAN_OOB 0x40 | ||
312 | |||
313 | #define netxen_set_tx_vlan_tci(cmd_desc, v) \ | ||
314 | (cmd_desc)->vlan_TCI = cpu_to_le16(v); | ||
315 | |||
316 | #define netxen_set_cmd_desc_port(cmd_desc, var) \ | ||
317 | ((cmd_desc)->port_ctxid |= ((var) & 0x0F)) | ||
318 | #define netxen_set_cmd_desc_ctxid(cmd_desc, var) \ | ||
319 | ((cmd_desc)->port_ctxid |= ((var) << 4 & 0xF0)) | ||
320 | |||
321 | #define netxen_set_tx_port(_desc, _port) \ | ||
322 | (_desc)->port_ctxid = ((_port) & 0xf) | (((_port) << 4) & 0xf0) | ||
323 | |||
324 | #define netxen_set_tx_flags_opcode(_desc, _flags, _opcode) \ | ||
325 | (_desc)->flags_opcode = \ | ||
326 | cpu_to_le16(((_flags) & 0x7f) | (((_opcode) & 0x3f) << 7)) | ||
327 | |||
328 | #define netxen_set_tx_frags_len(_desc, _frags, _len) \ | ||
329 | (_desc)->nfrags__length = \ | ||
330 | cpu_to_le32(((_frags) & 0xff) | (((_len) & 0xffffff) << 8)) | ||
331 | |||
332 | struct cmd_desc_type0 { | ||
333 | u8 tcp_hdr_offset; /* For LSO only */ | ||
334 | u8 ip_hdr_offset; /* For LSO only */ | ||
335 | __le16 flags_opcode; /* 15:13 unused, 12:7 opcode, 6:0 flags */ | ||
336 | __le32 nfrags__length; /* 31:8 total len, 7:0 frag count */ | ||
337 | |||
338 | __le64 addr_buffer2; | ||
339 | |||
340 | __le16 reference_handle; | ||
341 | __le16 mss; | ||
342 | u8 port_ctxid; /* 7:4 ctxid 3:0 port */ | ||
343 | u8 total_hdr_length; /* LSO only : MAC+IP+TCP Hdr size */ | ||
344 | __le16 conn_id; /* IPSec offoad only */ | ||
345 | |||
346 | __le64 addr_buffer3; | ||
347 | __le64 addr_buffer1; | ||
348 | |||
349 | __le16 buffer_length[4]; | ||
350 | |||
351 | __le64 addr_buffer4; | ||
352 | |||
353 | __le32 reserved2; | ||
354 | __le16 reserved; | ||
355 | __le16 vlan_TCI; | ||
356 | |||
357 | } __attribute__ ((aligned(64))); | ||
358 | |||
359 | /* Note: sizeof(rcv_desc) should always be a mutliple of 2 */ | ||
360 | struct rcv_desc { | ||
361 | __le16 reference_handle; | ||
362 | __le16 reserved; | ||
363 | __le32 buffer_length; /* allocated buffer length (usually 2K) */ | ||
364 | __le64 addr_buffer; | ||
365 | }; | ||
366 | |||
367 | /* opcode field in status_desc */ | ||
368 | #define NETXEN_NIC_SYN_OFFLOAD 0x03 | ||
369 | #define NETXEN_NIC_RXPKT_DESC 0x04 | ||
370 | #define NETXEN_OLD_RXPKT_DESC 0x3f | ||
371 | #define NETXEN_NIC_RESPONSE_DESC 0x05 | ||
372 | #define NETXEN_NIC_LRO_DESC 0x12 | ||
373 | |||
374 | /* for status field in status_desc */ | ||
375 | #define STATUS_NEED_CKSUM (1) | ||
376 | #define STATUS_CKSUM_OK (2) | ||
377 | |||
378 | /* owner bits of status_desc */ | ||
379 | #define STATUS_OWNER_HOST (0x1ULL << 56) | ||
380 | #define STATUS_OWNER_PHANTOM (0x2ULL << 56) | ||
381 | |||
382 | /* Status descriptor: | ||
383 | 0-3 port, 4-7 status, 8-11 type, 12-27 total_length | ||
384 | 28-43 reference_handle, 44-47 protocol, 48-52 pkt_offset | ||
385 | 53-55 desc_cnt, 56-57 owner, 58-63 opcode | ||
386 | */ | ||
387 | #define netxen_get_sts_port(sts_data) \ | ||
388 | ((sts_data) & 0x0F) | ||
389 | #define netxen_get_sts_status(sts_data) \ | ||
390 | (((sts_data) >> 4) & 0x0F) | ||
391 | #define netxen_get_sts_type(sts_data) \ | ||
392 | (((sts_data) >> 8) & 0x0F) | ||
393 | #define netxen_get_sts_totallength(sts_data) \ | ||
394 | (((sts_data) >> 12) & 0xFFFF) | ||
395 | #define netxen_get_sts_refhandle(sts_data) \ | ||
396 | (((sts_data) >> 28) & 0xFFFF) | ||
397 | #define netxen_get_sts_prot(sts_data) \ | ||
398 | (((sts_data) >> 44) & 0x0F) | ||
399 | #define netxen_get_sts_pkt_offset(sts_data) \ | ||
400 | (((sts_data) >> 48) & 0x1F) | ||
401 | #define netxen_get_sts_desc_cnt(sts_data) \ | ||
402 | (((sts_data) >> 53) & 0x7) | ||
403 | #define netxen_get_sts_opcode(sts_data) \ | ||
404 | (((sts_data) >> 58) & 0x03F) | ||
405 | |||
406 | #define netxen_get_lro_sts_refhandle(sts_data) \ | ||
407 | ((sts_data) & 0x0FFFF) | ||
408 | #define netxen_get_lro_sts_length(sts_data) \ | ||
409 | (((sts_data) >> 16) & 0x0FFFF) | ||
410 | #define netxen_get_lro_sts_l2_hdr_offset(sts_data) \ | ||
411 | (((sts_data) >> 32) & 0x0FF) | ||
412 | #define netxen_get_lro_sts_l4_hdr_offset(sts_data) \ | ||
413 | (((sts_data) >> 40) & 0x0FF) | ||
414 | #define netxen_get_lro_sts_timestamp(sts_data) \ | ||
415 | (((sts_data) >> 48) & 0x1) | ||
416 | #define netxen_get_lro_sts_type(sts_data) \ | ||
417 | (((sts_data) >> 49) & 0x7) | ||
418 | #define netxen_get_lro_sts_push_flag(sts_data) \ | ||
419 | (((sts_data) >> 52) & 0x1) | ||
420 | #define netxen_get_lro_sts_seq_number(sts_data) \ | ||
421 | ((sts_data) & 0x0FFFFFFFF) | ||
422 | |||
423 | |||
424 | struct status_desc { | ||
425 | __le64 status_desc_data[2]; | ||
426 | } __attribute__ ((aligned(16))); | ||
427 | |||
428 | /* UNIFIED ROMIMAGE *************************/ | ||
429 | #define NX_UNI_DIR_SECT_PRODUCT_TBL 0x0 | ||
430 | #define NX_UNI_DIR_SECT_BOOTLD 0x6 | ||
431 | #define NX_UNI_DIR_SECT_FW 0x7 | ||
432 | |||
433 | /*Offsets */ | ||
434 | #define NX_UNI_CHIP_REV_OFF 10 | ||
435 | #define NX_UNI_FLAGS_OFF 11 | ||
436 | #define NX_UNI_BIOS_VERSION_OFF 12 | ||
437 | #define NX_UNI_BOOTLD_IDX_OFF 27 | ||
438 | #define NX_UNI_FIRMWARE_IDX_OFF 29 | ||
439 | |||
440 | struct uni_table_desc{ | ||
441 | uint32_t findex; | ||
442 | uint32_t num_entries; | ||
443 | uint32_t entry_size; | ||
444 | uint32_t reserved[5]; | ||
445 | }; | ||
446 | |||
447 | struct uni_data_desc{ | ||
448 | uint32_t findex; | ||
449 | uint32_t size; | ||
450 | uint32_t reserved[5]; | ||
451 | }; | ||
452 | |||
453 | /* UNIFIED ROMIMAGE *************************/ | ||
454 | |||
455 | /* The version of the main data structure */ | ||
456 | #define NETXEN_BDINFO_VERSION 1 | ||
457 | |||
458 | /* Magic number to let user know flash is programmed */ | ||
459 | #define NETXEN_BDINFO_MAGIC 0x12345678 | ||
460 | |||
461 | /* Max number of Gig ports on a Phantom board */ | ||
462 | #define NETXEN_MAX_PORTS 4 | ||
463 | |||
464 | #define NETXEN_BRDTYPE_P1_BD 0x0000 | ||
465 | #define NETXEN_BRDTYPE_P1_SB 0x0001 | ||
466 | #define NETXEN_BRDTYPE_P1_SMAX 0x0002 | ||
467 | #define NETXEN_BRDTYPE_P1_SOCK 0x0003 | ||
468 | |||
469 | #define NETXEN_BRDTYPE_P2_SOCK_31 0x0008 | ||
470 | #define NETXEN_BRDTYPE_P2_SOCK_35 0x0009 | ||
471 | #define NETXEN_BRDTYPE_P2_SB35_4G 0x000a | ||
472 | #define NETXEN_BRDTYPE_P2_SB31_10G 0x000b | ||
473 | #define NETXEN_BRDTYPE_P2_SB31_2G 0x000c | ||
474 | |||
475 | #define NETXEN_BRDTYPE_P2_SB31_10G_IMEZ 0x000d | ||
476 | #define NETXEN_BRDTYPE_P2_SB31_10G_HMEZ 0x000e | ||
477 | #define NETXEN_BRDTYPE_P2_SB31_10G_CX4 0x000f | ||
478 | |||
479 | #define NETXEN_BRDTYPE_P3_REF_QG 0x0021 | ||
480 | #define NETXEN_BRDTYPE_P3_HMEZ 0x0022 | ||
481 | #define NETXEN_BRDTYPE_P3_10G_CX4_LP 0x0023 | ||
482 | #define NETXEN_BRDTYPE_P3_4_GB 0x0024 | ||
483 | #define NETXEN_BRDTYPE_P3_IMEZ 0x0025 | ||
484 | #define NETXEN_BRDTYPE_P3_10G_SFP_PLUS 0x0026 | ||
485 | #define NETXEN_BRDTYPE_P3_10000_BASE_T 0x0027 | ||
486 | #define NETXEN_BRDTYPE_P3_XG_LOM 0x0028 | ||
487 | #define NETXEN_BRDTYPE_P3_4_GB_MM 0x0029 | ||
488 | #define NETXEN_BRDTYPE_P3_10G_SFP_CT 0x002a | ||
489 | #define NETXEN_BRDTYPE_P3_10G_SFP_QT 0x002b | ||
490 | #define NETXEN_BRDTYPE_P3_10G_CX4 0x0031 | ||
491 | #define NETXEN_BRDTYPE_P3_10G_XFP 0x0032 | ||
492 | #define NETXEN_BRDTYPE_P3_10G_TP 0x0080 | ||
493 | |||
494 | /* Flash memory map */ | ||
495 | #define NETXEN_CRBINIT_START 0 /* crbinit section */ | ||
496 | #define NETXEN_BRDCFG_START 0x4000 /* board config */ | ||
497 | #define NETXEN_INITCODE_START 0x6000 /* pegtune code */ | ||
498 | #define NETXEN_BOOTLD_START 0x10000 /* bootld */ | ||
499 | #define NETXEN_IMAGE_START 0x43000 /* compressed image */ | ||
500 | #define NETXEN_SECONDARY_START 0x200000 /* backup images */ | ||
501 | #define NETXEN_PXE_START 0x3E0000 /* PXE boot rom */ | ||
502 | #define NETXEN_USER_START 0x3E8000 /* Firmare info */ | ||
503 | #define NETXEN_FIXED_START 0x3F0000 /* backup of crbinit */ | ||
504 | #define NETXEN_USER_START_OLD NETXEN_PXE_START /* very old flash */ | ||
505 | |||
506 | #define NX_OLD_MAC_ADDR_OFFSET (NETXEN_USER_START) | ||
507 | #define NX_FW_VERSION_OFFSET (NETXEN_USER_START+0x408) | ||
508 | #define NX_FW_SIZE_OFFSET (NETXEN_USER_START+0x40c) | ||
509 | #define NX_FW_MAC_ADDR_OFFSET (NETXEN_USER_START+0x418) | ||
510 | #define NX_FW_SERIAL_NUM_OFFSET (NETXEN_USER_START+0x81c) | ||
511 | #define NX_BIOS_VERSION_OFFSET (NETXEN_USER_START+0x83c) | ||
512 | |||
513 | #define NX_HDR_VERSION_OFFSET (NETXEN_BRDCFG_START) | ||
514 | #define NX_BRDTYPE_OFFSET (NETXEN_BRDCFG_START+0x8) | ||
515 | #define NX_FW_MAGIC_OFFSET (NETXEN_BRDCFG_START+0x128) | ||
516 | |||
517 | #define NX_FW_MIN_SIZE (0x3fffff) | ||
518 | #define NX_P2_MN_ROMIMAGE 0 | ||
519 | #define NX_P3_CT_ROMIMAGE 1 | ||
520 | #define NX_P3_MN_ROMIMAGE 2 | ||
521 | #define NX_UNIFIED_ROMIMAGE 3 | ||
522 | #define NX_FLASH_ROMIMAGE 4 | ||
523 | #define NX_UNKNOWN_ROMIMAGE 0xff | ||
524 | |||
525 | #define NX_P2_MN_ROMIMAGE_NAME "nxromimg.bin" | ||
526 | #define NX_P3_CT_ROMIMAGE_NAME "nx3fwct.bin" | ||
527 | #define NX_P3_MN_ROMIMAGE_NAME "nx3fwmn.bin" | ||
528 | #define NX_UNIFIED_ROMIMAGE_NAME "phanfw.bin" | ||
529 | #define NX_FLASH_ROMIMAGE_NAME "flash" | ||
530 | |||
531 | extern char netxen_nic_driver_name[]; | ||
532 | |||
533 | /* Number of status descriptors to handle per interrupt */ | ||
534 | #define MAX_STATUS_HANDLE (64) | ||
535 | |||
536 | /* | ||
537 | * netxen_skb_frag{} is to contain mapping info for each SG list. This | ||
538 | * has to be freed when DMA is complete. This is part of netxen_tx_buffer{}. | ||
539 | */ | ||
540 | struct netxen_skb_frag { | ||
541 | u64 dma; | ||
542 | u64 length; | ||
543 | }; | ||
544 | |||
545 | struct netxen_recv_crb { | ||
546 | u32 crb_rcv_producer[NUM_RCV_DESC_RINGS]; | ||
547 | u32 crb_sts_consumer[NUM_STS_DESC_RINGS]; | ||
548 | u32 sw_int_mask[NUM_STS_DESC_RINGS]; | ||
549 | }; | ||
550 | |||
551 | /* Following defines are for the state of the buffers */ | ||
552 | #define NETXEN_BUFFER_FREE 0 | ||
553 | #define NETXEN_BUFFER_BUSY 1 | ||
554 | |||
555 | /* | ||
556 | * There will be one netxen_buffer per skb packet. These will be | ||
557 | * used to save the dma info for pci_unmap_page() | ||
558 | */ | ||
559 | struct netxen_cmd_buffer { | ||
560 | struct sk_buff *skb; | ||
561 | struct netxen_skb_frag frag_array[MAX_SKB_FRAGS + 1]; | ||
562 | u32 frag_count; | ||
563 | }; | ||
564 | |||
565 | /* In rx_buffer, we do not need multiple fragments as is a single buffer */ | ||
566 | struct netxen_rx_buffer { | ||
567 | struct list_head list; | ||
568 | struct sk_buff *skb; | ||
569 | u64 dma; | ||
570 | u16 ref_handle; | ||
571 | u16 state; | ||
572 | }; | ||
573 | |||
574 | /* Board types */ | ||
575 | #define NETXEN_NIC_GBE 0x01 | ||
576 | #define NETXEN_NIC_XGBE 0x02 | ||
577 | |||
578 | /* | ||
579 | * One hardware_context{} per adapter | ||
580 | * contains interrupt info as well shared hardware info. | ||
581 | */ | ||
582 | struct netxen_hardware_context { | ||
583 | void __iomem *pci_base0; | ||
584 | void __iomem *pci_base1; | ||
585 | void __iomem *pci_base2; | ||
586 | void __iomem *db_base; | ||
587 | void __iomem *ocm_win_crb; | ||
588 | |||
589 | unsigned long db_len; | ||
590 | unsigned long pci_len0; | ||
591 | |||
592 | u32 ocm_win; | ||
593 | u32 crb_win; | ||
594 | |||
595 | rwlock_t crb_lock; | ||
596 | spinlock_t mem_lock; | ||
597 | |||
598 | u8 cut_through; | ||
599 | u8 revision_id; | ||
600 | u8 pci_func; | ||
601 | u8 linkup; | ||
602 | u16 port_type; | ||
603 | u16 board_type; | ||
604 | }; | ||
605 | |||
606 | #define MINIMUM_ETHERNET_FRAME_SIZE 64 /* With FCS */ | ||
607 | #define ETHERNET_FCS_SIZE 4 | ||
608 | |||
609 | struct netxen_adapter_stats { | ||
610 | u64 xmitcalled; | ||
611 | u64 xmitfinished; | ||
612 | u64 rxdropped; | ||
613 | u64 txdropped; | ||
614 | u64 csummed; | ||
615 | u64 rx_pkts; | ||
616 | u64 lro_pkts; | ||
617 | u64 rxbytes; | ||
618 | u64 txbytes; | ||
619 | }; | ||
620 | |||
621 | /* | ||
622 | * Rcv Descriptor Context. One such per Rcv Descriptor. There may | ||
623 | * be one Rcv Descriptor for normal packets, one for jumbo and may be others. | ||
624 | */ | ||
625 | struct nx_host_rds_ring { | ||
626 | u32 producer; | ||
627 | u32 num_desc; | ||
628 | u32 dma_size; | ||
629 | u32 skb_size; | ||
630 | u32 flags; | ||
631 | void __iomem *crb_rcv_producer; | ||
632 | struct rcv_desc *desc_head; | ||
633 | struct netxen_rx_buffer *rx_buf_arr; | ||
634 | struct list_head free_list; | ||
635 | spinlock_t lock; | ||
636 | dma_addr_t phys_addr; | ||
637 | }; | ||
638 | |||
639 | struct nx_host_sds_ring { | ||
640 | u32 consumer; | ||
641 | u32 num_desc; | ||
642 | void __iomem *crb_sts_consumer; | ||
643 | void __iomem *crb_intr_mask; | ||
644 | |||
645 | struct status_desc *desc_head; | ||
646 | struct netxen_adapter *adapter; | ||
647 | struct napi_struct napi; | ||
648 | struct list_head free_list[NUM_RCV_DESC_RINGS]; | ||
649 | |||
650 | int irq; | ||
651 | |||
652 | dma_addr_t phys_addr; | ||
653 | char name[IFNAMSIZ+4]; | ||
654 | }; | ||
655 | |||
656 | struct nx_host_tx_ring { | ||
657 | u32 producer; | ||
658 | __le32 *hw_consumer; | ||
659 | u32 sw_consumer; | ||
660 | void __iomem *crb_cmd_producer; | ||
661 | void __iomem *crb_cmd_consumer; | ||
662 | u32 num_desc; | ||
663 | |||
664 | struct netdev_queue *txq; | ||
665 | |||
666 | struct netxen_cmd_buffer *cmd_buf_arr; | ||
667 | struct cmd_desc_type0 *desc_head; | ||
668 | dma_addr_t phys_addr; | ||
669 | }; | ||
670 | |||
671 | /* | ||
672 | * Receive context. There is one such structure per instance of the | ||
673 | * receive processing. Any state information that is relevant to | ||
674 | * the receive, and is must be in this structure. The global data may be | ||
675 | * present elsewhere. | ||
676 | */ | ||
677 | struct netxen_recv_context { | ||
678 | u32 state; | ||
679 | u16 context_id; | ||
680 | u16 virt_port; | ||
681 | |||
682 | struct nx_host_rds_ring *rds_rings; | ||
683 | struct nx_host_sds_ring *sds_rings; | ||
684 | |||
685 | struct netxen_ring_ctx *hwctx; | ||
686 | dma_addr_t phys_addr; | ||
687 | }; | ||
688 | |||
689 | /* New HW context creation */ | ||
690 | |||
691 | #define NX_OS_CRB_RETRY_COUNT 4000 | ||
692 | #define NX_CDRP_SIGNATURE_MAKE(pcifn, version) \ | ||
693 | (((pcifn) & 0xff) | (((version) & 0xff) << 8) | (0xcafe << 16)) | ||
694 | |||
695 | #define NX_CDRP_CLEAR 0x00000000 | ||
696 | #define NX_CDRP_CMD_BIT 0x80000000 | ||
697 | |||
698 | /* | ||
699 | * All responses must have the NX_CDRP_CMD_BIT cleared | ||
700 | * in the crb NX_CDRP_CRB_OFFSET. | ||
701 | */ | ||
702 | #define NX_CDRP_FORM_RSP(rsp) (rsp) | ||
703 | #define NX_CDRP_IS_RSP(rsp) (((rsp) & NX_CDRP_CMD_BIT) == 0) | ||
704 | |||
705 | #define NX_CDRP_RSP_OK 0x00000001 | ||
706 | #define NX_CDRP_RSP_FAIL 0x00000002 | ||
707 | #define NX_CDRP_RSP_TIMEOUT 0x00000003 | ||
708 | |||
709 | /* | ||
710 | * All commands must have the NX_CDRP_CMD_BIT set in | ||
711 | * the crb NX_CDRP_CRB_OFFSET. | ||
712 | */ | ||
713 | #define NX_CDRP_FORM_CMD(cmd) (NX_CDRP_CMD_BIT | (cmd)) | ||
714 | #define NX_CDRP_IS_CMD(cmd) (((cmd) & NX_CDRP_CMD_BIT) != 0) | ||
715 | |||
716 | #define NX_CDRP_CMD_SUBMIT_CAPABILITIES 0x00000001 | ||
717 | #define NX_CDRP_CMD_READ_MAX_RDS_PER_CTX 0x00000002 | ||
718 | #define NX_CDRP_CMD_READ_MAX_SDS_PER_CTX 0x00000003 | ||
719 | #define NX_CDRP_CMD_READ_MAX_RULES_PER_CTX 0x00000004 | ||
720 | #define NX_CDRP_CMD_READ_MAX_RX_CTX 0x00000005 | ||
721 | #define NX_CDRP_CMD_READ_MAX_TX_CTX 0x00000006 | ||
722 | #define NX_CDRP_CMD_CREATE_RX_CTX 0x00000007 | ||
723 | #define NX_CDRP_CMD_DESTROY_RX_CTX 0x00000008 | ||
724 | #define NX_CDRP_CMD_CREATE_TX_CTX 0x00000009 | ||
725 | #define NX_CDRP_CMD_DESTROY_TX_CTX 0x0000000a | ||
726 | #define NX_CDRP_CMD_SETUP_STATISTICS 0x0000000e | ||
727 | #define NX_CDRP_CMD_GET_STATISTICS 0x0000000f | ||
728 | #define NX_CDRP_CMD_DELETE_STATISTICS 0x00000010 | ||
729 | #define NX_CDRP_CMD_SET_MTU 0x00000012 | ||
730 | #define NX_CDRP_CMD_READ_PHY 0x00000013 | ||
731 | #define NX_CDRP_CMD_WRITE_PHY 0x00000014 | ||
732 | #define NX_CDRP_CMD_READ_HW_REG 0x00000015 | ||
733 | #define NX_CDRP_CMD_GET_FLOW_CTL 0x00000016 | ||
734 | #define NX_CDRP_CMD_SET_FLOW_CTL 0x00000017 | ||
735 | #define NX_CDRP_CMD_READ_MAX_MTU 0x00000018 | ||
736 | #define NX_CDRP_CMD_READ_MAX_LRO 0x00000019 | ||
737 | #define NX_CDRP_CMD_CONFIGURE_TOE 0x0000001a | ||
738 | #define NX_CDRP_CMD_FUNC_ATTRIB 0x0000001b | ||
739 | #define NX_CDRP_CMD_READ_PEXQ_PARAMETERS 0x0000001c | ||
740 | #define NX_CDRP_CMD_GET_LIC_CAPABILITIES 0x0000001d | ||
741 | #define NX_CDRP_CMD_READ_MAX_LRO_PER_BOARD 0x0000001e | ||
742 | #define NX_CDRP_CMD_CONFIG_GBE_PORT 0x0000001f | ||
743 | #define NX_CDRP_CMD_MAX 0x00000020 | ||
744 | |||
745 | #define NX_RCODE_SUCCESS 0 | ||
746 | #define NX_RCODE_NO_HOST_MEM 1 | ||
747 | #define NX_RCODE_NO_HOST_RESOURCE 2 | ||
748 | #define NX_RCODE_NO_CARD_CRB 3 | ||
749 | #define NX_RCODE_NO_CARD_MEM 4 | ||
750 | #define NX_RCODE_NO_CARD_RESOURCE 5 | ||
751 | #define NX_RCODE_INVALID_ARGS 6 | ||
752 | #define NX_RCODE_INVALID_ACTION 7 | ||
753 | #define NX_RCODE_INVALID_STATE 8 | ||
754 | #define NX_RCODE_NOT_SUPPORTED 9 | ||
755 | #define NX_RCODE_NOT_PERMITTED 10 | ||
756 | #define NX_RCODE_NOT_READY 11 | ||
757 | #define NX_RCODE_DOES_NOT_EXIST 12 | ||
758 | #define NX_RCODE_ALREADY_EXISTS 13 | ||
759 | #define NX_RCODE_BAD_SIGNATURE 14 | ||
760 | #define NX_RCODE_CMD_NOT_IMPL 15 | ||
761 | #define NX_RCODE_CMD_INVALID 16 | ||
762 | #define NX_RCODE_TIMEOUT 17 | ||
763 | #define NX_RCODE_CMD_FAILED 18 | ||
764 | #define NX_RCODE_MAX_EXCEEDED 19 | ||
765 | #define NX_RCODE_MAX 20 | ||
766 | |||
767 | #define NX_DESTROY_CTX_RESET 0 | ||
768 | #define NX_DESTROY_CTX_D3_RESET 1 | ||
769 | #define NX_DESTROY_CTX_MAX 2 | ||
770 | |||
771 | /* | ||
772 | * Capabilities | ||
773 | */ | ||
774 | #define NX_CAP_BIT(class, bit) (1 << bit) | ||
775 | #define NX_CAP0_LEGACY_CONTEXT NX_CAP_BIT(0, 0) | ||
776 | #define NX_CAP0_MULTI_CONTEXT NX_CAP_BIT(0, 1) | ||
777 | #define NX_CAP0_LEGACY_MN NX_CAP_BIT(0, 2) | ||
778 | #define NX_CAP0_LEGACY_MS NX_CAP_BIT(0, 3) | ||
779 | #define NX_CAP0_CUT_THROUGH NX_CAP_BIT(0, 4) | ||
780 | #define NX_CAP0_LRO NX_CAP_BIT(0, 5) | ||
781 | #define NX_CAP0_LSO NX_CAP_BIT(0, 6) | ||
782 | #define NX_CAP0_JUMBO_CONTIGUOUS NX_CAP_BIT(0, 7) | ||
783 | #define NX_CAP0_LRO_CONTIGUOUS NX_CAP_BIT(0, 8) | ||
784 | #define NX_CAP0_HW_LRO NX_CAP_BIT(0, 10) | ||
785 | |||
786 | /* | ||
787 | * Context state | ||
788 | */ | ||
789 | #define NX_HOST_CTX_STATE_FREED 0 | ||
790 | #define NX_HOST_CTX_STATE_ALLOCATED 1 | ||
791 | #define NX_HOST_CTX_STATE_ACTIVE 2 | ||
792 | #define NX_HOST_CTX_STATE_DISABLED 3 | ||
793 | #define NX_HOST_CTX_STATE_QUIESCED 4 | ||
794 | #define NX_HOST_CTX_STATE_MAX 5 | ||
795 | |||
796 | /* | ||
797 | * Rx context | ||
798 | */ | ||
799 | |||
800 | typedef struct { | ||
801 | __le64 host_phys_addr; /* Ring base addr */ | ||
802 | __le32 ring_size; /* Ring entries */ | ||
803 | __le16 msi_index; | ||
804 | __le16 rsvd; /* Padding */ | ||
805 | } nx_hostrq_sds_ring_t; | ||
806 | |||
807 | typedef struct { | ||
808 | __le64 host_phys_addr; /* Ring base addr */ | ||
809 | __le64 buff_size; /* Packet buffer size */ | ||
810 | __le32 ring_size; /* Ring entries */ | ||
811 | __le32 ring_kind; /* Class of ring */ | ||
812 | } nx_hostrq_rds_ring_t; | ||
813 | |||
814 | typedef struct { | ||
815 | __le64 host_rsp_dma_addr; /* Response dma'd here */ | ||
816 | __le32 capabilities[4]; /* Flag bit vector */ | ||
817 | __le32 host_int_crb_mode; /* Interrupt crb usage */ | ||
818 | __le32 host_rds_crb_mode; /* RDS crb usage */ | ||
819 | /* These ring offsets are relative to data[0] below */ | ||
820 | __le32 rds_ring_offset; /* Offset to RDS config */ | ||
821 | __le32 sds_ring_offset; /* Offset to SDS config */ | ||
822 | __le16 num_rds_rings; /* Count of RDS rings */ | ||
823 | __le16 num_sds_rings; /* Count of SDS rings */ | ||
824 | __le16 rsvd1; /* Padding */ | ||
825 | __le16 rsvd2; /* Padding */ | ||
826 | u8 reserved[128]; /* reserve space for future expansion*/ | ||
827 | /* MUST BE 64-bit aligned. | ||
828 | The following is packed: | ||
829 | - N hostrq_rds_rings | ||
830 | - N hostrq_sds_rings */ | ||
831 | char data[0]; | ||
832 | } nx_hostrq_rx_ctx_t; | ||
833 | |||
834 | typedef struct { | ||
835 | __le32 host_producer_crb; /* Crb to use */ | ||
836 | __le32 rsvd1; /* Padding */ | ||
837 | } nx_cardrsp_rds_ring_t; | ||
838 | |||
839 | typedef struct { | ||
840 | __le32 host_consumer_crb; /* Crb to use */ | ||
841 | __le32 interrupt_crb; /* Crb to use */ | ||
842 | } nx_cardrsp_sds_ring_t; | ||
843 | |||
844 | typedef struct { | ||
845 | /* These ring offsets are relative to data[0] below */ | ||
846 | __le32 rds_ring_offset; /* Offset to RDS config */ | ||
847 | __le32 sds_ring_offset; /* Offset to SDS config */ | ||
848 | __le32 host_ctx_state; /* Starting State */ | ||
849 | __le32 num_fn_per_port; /* How many PCI fn share the port */ | ||
850 | __le16 num_rds_rings; /* Count of RDS rings */ | ||
851 | __le16 num_sds_rings; /* Count of SDS rings */ | ||
852 | __le16 context_id; /* Handle for context */ | ||
853 | u8 phys_port; /* Physical id of port */ | ||
854 | u8 virt_port; /* Virtual/Logical id of port */ | ||
855 | u8 reserved[128]; /* save space for future expansion */ | ||
856 | /* MUST BE 64-bit aligned. | ||
857 | The following is packed: | ||
858 | - N cardrsp_rds_rings | ||
859 | - N cardrs_sds_rings */ | ||
860 | char data[0]; | ||
861 | } nx_cardrsp_rx_ctx_t; | ||
862 | |||
863 | #define SIZEOF_HOSTRQ_RX(HOSTRQ_RX, rds_rings, sds_rings) \ | ||
864 | (sizeof(HOSTRQ_RX) + \ | ||
865 | (rds_rings)*(sizeof(nx_hostrq_rds_ring_t)) + \ | ||
866 | (sds_rings)*(sizeof(nx_hostrq_sds_ring_t))) | ||
867 | |||
868 | #define SIZEOF_CARDRSP_RX(CARDRSP_RX, rds_rings, sds_rings) \ | ||
869 | (sizeof(CARDRSP_RX) + \ | ||
870 | (rds_rings)*(sizeof(nx_cardrsp_rds_ring_t)) + \ | ||
871 | (sds_rings)*(sizeof(nx_cardrsp_sds_ring_t))) | ||
872 | |||
873 | /* | ||
874 | * Tx context | ||
875 | */ | ||
876 | |||
877 | typedef struct { | ||
878 | __le64 host_phys_addr; /* Ring base addr */ | ||
879 | __le32 ring_size; /* Ring entries */ | ||
880 | __le32 rsvd; /* Padding */ | ||
881 | } nx_hostrq_cds_ring_t; | ||
882 | |||
883 | typedef struct { | ||
884 | __le64 host_rsp_dma_addr; /* Response dma'd here */ | ||
885 | __le64 cmd_cons_dma_addr; /* */ | ||
886 | __le64 dummy_dma_addr; /* */ | ||
887 | __le32 capabilities[4]; /* Flag bit vector */ | ||
888 | __le32 host_int_crb_mode; /* Interrupt crb usage */ | ||
889 | __le32 rsvd1; /* Padding */ | ||
890 | __le16 rsvd2; /* Padding */ | ||
891 | __le16 interrupt_ctl; | ||
892 | __le16 msi_index; | ||
893 | __le16 rsvd3; /* Padding */ | ||
894 | nx_hostrq_cds_ring_t cds_ring; /* Desc of cds ring */ | ||
895 | u8 reserved[128]; /* future expansion */ | ||
896 | } nx_hostrq_tx_ctx_t; | ||
897 | |||
898 | typedef struct { | ||
899 | __le32 host_producer_crb; /* Crb to use */ | ||
900 | __le32 interrupt_crb; /* Crb to use */ | ||
901 | } nx_cardrsp_cds_ring_t; | ||
902 | |||
903 | typedef struct { | ||
904 | __le32 host_ctx_state; /* Starting state */ | ||
905 | __le16 context_id; /* Handle for context */ | ||
906 | u8 phys_port; /* Physical id of port */ | ||
907 | u8 virt_port; /* Virtual/Logical id of port */ | ||
908 | nx_cardrsp_cds_ring_t cds_ring; /* Card cds settings */ | ||
909 | u8 reserved[128]; /* future expansion */ | ||
910 | } nx_cardrsp_tx_ctx_t; | ||
911 | |||
912 | #define SIZEOF_HOSTRQ_TX(HOSTRQ_TX) (sizeof(HOSTRQ_TX)) | ||
913 | #define SIZEOF_CARDRSP_TX(CARDRSP_TX) (sizeof(CARDRSP_TX)) | ||
914 | |||
915 | /* CRB */ | ||
916 | |||
917 | #define NX_HOST_RDS_CRB_MODE_UNIQUE 0 | ||
918 | #define NX_HOST_RDS_CRB_MODE_SHARED 1 | ||
919 | #define NX_HOST_RDS_CRB_MODE_CUSTOM 2 | ||
920 | #define NX_HOST_RDS_CRB_MODE_MAX 3 | ||
921 | |||
922 | #define NX_HOST_INT_CRB_MODE_UNIQUE 0 | ||
923 | #define NX_HOST_INT_CRB_MODE_SHARED 1 | ||
924 | #define NX_HOST_INT_CRB_MODE_NORX 2 | ||
925 | #define NX_HOST_INT_CRB_MODE_NOTX 3 | ||
926 | #define NX_HOST_INT_CRB_MODE_NORXTX 4 | ||
927 | |||
928 | |||
929 | /* MAC */ | ||
930 | |||
931 | #define MC_COUNT_P2 16 | ||
932 | #define MC_COUNT_P3 38 | ||
933 | |||
934 | #define NETXEN_MAC_NOOP 0 | ||
935 | #define NETXEN_MAC_ADD 1 | ||
936 | #define NETXEN_MAC_DEL 2 | ||
937 | |||
938 | typedef struct nx_mac_list_s { | ||
939 | struct list_head list; | ||
940 | uint8_t mac_addr[ETH_ALEN+2]; | ||
941 | } nx_mac_list_t; | ||
942 | |||
943 | struct nx_vlan_ip_list { | ||
944 | struct list_head list; | ||
945 | u32 ip_addr; | ||
946 | }; | ||
947 | |||
948 | /* | ||
949 | * Interrupt coalescing defaults. The defaults are for 1500 MTU. It is | ||
950 | * adjusted based on configured MTU. | ||
951 | */ | ||
952 | #define NETXEN_DEFAULT_INTR_COALESCE_RX_TIME_US 3 | ||
953 | #define NETXEN_DEFAULT_INTR_COALESCE_RX_PACKETS 256 | ||
954 | #define NETXEN_DEFAULT_INTR_COALESCE_TX_PACKETS 64 | ||
955 | #define NETXEN_DEFAULT_INTR_COALESCE_TX_TIME_US 4 | ||
956 | |||
957 | #define NETXEN_NIC_INTR_DEFAULT 0x04 | ||
958 | |||
959 | typedef union { | ||
960 | struct { | ||
961 | uint16_t rx_packets; | ||
962 | uint16_t rx_time_us; | ||
963 | uint16_t tx_packets; | ||
964 | uint16_t tx_time_us; | ||
965 | } data; | ||
966 | uint64_t word; | ||
967 | } nx_nic_intr_coalesce_data_t; | ||
968 | |||
969 | typedef struct { | ||
970 | uint16_t stats_time_us; | ||
971 | uint16_t rate_sample_time; | ||
972 | uint16_t flags; | ||
973 | uint16_t rsvd_1; | ||
974 | uint32_t low_threshold; | ||
975 | uint32_t high_threshold; | ||
976 | nx_nic_intr_coalesce_data_t normal; | ||
977 | nx_nic_intr_coalesce_data_t low; | ||
978 | nx_nic_intr_coalesce_data_t high; | ||
979 | nx_nic_intr_coalesce_data_t irq; | ||
980 | } nx_nic_intr_coalesce_t; | ||
981 | |||
982 | #define NX_HOST_REQUEST 0x13 | ||
983 | #define NX_NIC_REQUEST 0x14 | ||
984 | |||
985 | #define NX_MAC_EVENT 0x1 | ||
986 | |||
987 | #define NX_IP_UP 2 | ||
988 | #define NX_IP_DOWN 3 | ||
989 | |||
990 | /* | ||
991 | * Driver --> Firmware | ||
992 | */ | ||
993 | #define NX_NIC_H2C_OPCODE_START 0 | ||
994 | #define NX_NIC_H2C_OPCODE_CONFIG_RSS 1 | ||
995 | #define NX_NIC_H2C_OPCODE_CONFIG_RSS_TBL 2 | ||
996 | #define NX_NIC_H2C_OPCODE_CONFIG_INTR_COALESCE 3 | ||
997 | #define NX_NIC_H2C_OPCODE_CONFIG_LED 4 | ||
998 | #define NX_NIC_H2C_OPCODE_CONFIG_PROMISCUOUS 5 | ||
999 | #define NX_NIC_H2C_OPCODE_CONFIG_L2_MAC 6 | ||
1000 | #define NX_NIC_H2C_OPCODE_LRO_REQUEST 7 | ||
1001 | #define NX_NIC_H2C_OPCODE_GET_SNMP_STATS 8 | ||
1002 | #define NX_NIC_H2C_OPCODE_PROXY_START_REQUEST 9 | ||
1003 | #define NX_NIC_H2C_OPCODE_PROXY_STOP_REQUEST 10 | ||
1004 | #define NX_NIC_H2C_OPCODE_PROXY_SET_MTU 11 | ||
1005 | #define NX_NIC_H2C_OPCODE_PROXY_SET_VPORT_MISS_MODE 12 | ||
1006 | #define NX_NIC_H2C_OPCODE_GET_FINGER_PRINT_REQUEST 13 | ||
1007 | #define NX_NIC_H2C_OPCODE_INSTALL_LICENSE_REQUEST 14 | ||
1008 | #define NX_NIC_H2C_OPCODE_GET_LICENSE_CAPABILITY_REQUEST 15 | ||
1009 | #define NX_NIC_H2C_OPCODE_GET_NET_STATS 16 | ||
1010 | #define NX_NIC_H2C_OPCODE_PROXY_UPDATE_P2V 17 | ||
1011 | #define NX_NIC_H2C_OPCODE_CONFIG_IPADDR 18 | ||
1012 | #define NX_NIC_H2C_OPCODE_CONFIG_LOOPBACK 19 | ||
1013 | #define NX_NIC_H2C_OPCODE_PROXY_STOP_DONE 20 | ||
1014 | #define NX_NIC_H2C_OPCODE_GET_LINKEVENT 21 | ||
1015 | #define NX_NIC_C2C_OPCODE 22 | ||
1016 | #define NX_NIC_H2C_OPCODE_CONFIG_BRIDGING 23 | ||
1017 | #define NX_NIC_H2C_OPCODE_CONFIG_HW_LRO 24 | ||
1018 | #define NX_NIC_H2C_OPCODE_LAST 25 | ||
1019 | |||
1020 | /* | ||
1021 | * Firmware --> Driver | ||
1022 | */ | ||
1023 | |||
1024 | #define NX_NIC_C2H_OPCODE_START 128 | ||
1025 | #define NX_NIC_C2H_OPCODE_CONFIG_RSS_RESPONSE 129 | ||
1026 | #define NX_NIC_C2H_OPCODE_CONFIG_RSS_TBL_RESPONSE 130 | ||
1027 | #define NX_NIC_C2H_OPCODE_CONFIG_MAC_RESPONSE 131 | ||
1028 | #define NX_NIC_C2H_OPCODE_CONFIG_PROMISCUOUS_RESPONSE 132 | ||
1029 | #define NX_NIC_C2H_OPCODE_CONFIG_L2_MAC_RESPONSE 133 | ||
1030 | #define NX_NIC_C2H_OPCODE_LRO_DELETE_RESPONSE 134 | ||
1031 | #define NX_NIC_C2H_OPCODE_LRO_ADD_FAILURE_RESPONSE 135 | ||
1032 | #define NX_NIC_C2H_OPCODE_GET_SNMP_STATS 136 | ||
1033 | #define NX_NIC_C2H_OPCODE_GET_FINGER_PRINT_REPLY 137 | ||
1034 | #define NX_NIC_C2H_OPCODE_INSTALL_LICENSE_REPLY 138 | ||
1035 | #define NX_NIC_C2H_OPCODE_GET_LICENSE_CAPABILITIES_REPLY 139 | ||
1036 | #define NX_NIC_C2H_OPCODE_GET_NET_STATS_RESPONSE 140 | ||
1037 | #define NX_NIC_C2H_OPCODE_GET_LINKEVENT_RESPONSE 141 | ||
1038 | #define NX_NIC_C2H_OPCODE_LAST 142 | ||
1039 | |||
1040 | #define VPORT_MISS_MODE_DROP 0 /* drop all unmatched */ | ||
1041 | #define VPORT_MISS_MODE_ACCEPT_ALL 1 /* accept all packets */ | ||
1042 | #define VPORT_MISS_MODE_ACCEPT_MULTI 2 /* accept unmatched multicast */ | ||
1043 | |||
1044 | #define NX_NIC_LRO_REQUEST_FIRST 0 | ||
1045 | #define NX_NIC_LRO_REQUEST_ADD_FLOW 1 | ||
1046 | #define NX_NIC_LRO_REQUEST_DELETE_FLOW 2 | ||
1047 | #define NX_NIC_LRO_REQUEST_TIMER 3 | ||
1048 | #define NX_NIC_LRO_REQUEST_CLEANUP 4 | ||
1049 | #define NX_NIC_LRO_REQUEST_ADD_FLOW_SCHEDULED 5 | ||
1050 | #define NX_TOE_LRO_REQUEST_ADD_FLOW 6 | ||
1051 | #define NX_TOE_LRO_REQUEST_ADD_FLOW_RESPONSE 7 | ||
1052 | #define NX_TOE_LRO_REQUEST_DELETE_FLOW 8 | ||
1053 | #define NX_TOE_LRO_REQUEST_DELETE_FLOW_RESPONSE 9 | ||
1054 | #define NX_TOE_LRO_REQUEST_TIMER 10 | ||
1055 | #define NX_NIC_LRO_REQUEST_LAST 11 | ||
1056 | |||
1057 | #define NX_FW_CAPABILITY_LINK_NOTIFICATION (1 << 5) | ||
1058 | #define NX_FW_CAPABILITY_SWITCHING (1 << 6) | ||
1059 | #define NX_FW_CAPABILITY_PEXQ (1 << 7) | ||
1060 | #define NX_FW_CAPABILITY_BDG (1 << 8) | ||
1061 | #define NX_FW_CAPABILITY_FVLANTX (1 << 9) | ||
1062 | #define NX_FW_CAPABILITY_HW_LRO (1 << 10) | ||
1063 | #define NX_FW_CAPABILITY_GBE_LINK_CFG (1 << 11) | ||
1064 | |||
1065 | /* module types */ | ||
1066 | #define LINKEVENT_MODULE_NOT_PRESENT 1 | ||
1067 | #define LINKEVENT_MODULE_OPTICAL_UNKNOWN 2 | ||
1068 | #define LINKEVENT_MODULE_OPTICAL_SRLR 3 | ||
1069 | #define LINKEVENT_MODULE_OPTICAL_LRM 4 | ||
1070 | #define LINKEVENT_MODULE_OPTICAL_SFP_1G 5 | ||
1071 | #define LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLE 6 | ||
1072 | #define LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLELEN 7 | ||
1073 | #define LINKEVENT_MODULE_TWINAX 8 | ||
1074 | |||
1075 | #define LINKSPEED_10GBPS 10000 | ||
1076 | #define LINKSPEED_1GBPS 1000 | ||
1077 | #define LINKSPEED_100MBPS 100 | ||
1078 | #define LINKSPEED_10MBPS 10 | ||
1079 | |||
1080 | #define LINKSPEED_ENCODED_10MBPS 0 | ||
1081 | #define LINKSPEED_ENCODED_100MBPS 1 | ||
1082 | #define LINKSPEED_ENCODED_1GBPS 2 | ||
1083 | |||
1084 | #define LINKEVENT_AUTONEG_DISABLED 0 | ||
1085 | #define LINKEVENT_AUTONEG_ENABLED 1 | ||
1086 | |||
1087 | #define LINKEVENT_HALF_DUPLEX 0 | ||
1088 | #define LINKEVENT_FULL_DUPLEX 1 | ||
1089 | |||
1090 | #define LINKEVENT_LINKSPEED_MBPS 0 | ||
1091 | #define LINKEVENT_LINKSPEED_ENCODED 1 | ||
1092 | |||
1093 | #define AUTO_FW_RESET_ENABLED 0xEF10AF12 | ||
1094 | #define AUTO_FW_RESET_DISABLED 0xDCBAAF12 | ||
1095 | |||
1096 | /* firmware response header: | ||
1097 | * 63:58 - message type | ||
1098 | * 57:56 - owner | ||
1099 | * 55:53 - desc count | ||
1100 | * 52:48 - reserved | ||
1101 | * 47:40 - completion id | ||
1102 | * 39:32 - opcode | ||
1103 | * 31:16 - error code | ||
1104 | * 15:00 - reserved | ||
1105 | */ | ||
1106 | #define netxen_get_nic_msgtype(msg_hdr) \ | ||
1107 | ((msg_hdr >> 58) & 0x3F) | ||
1108 | #define netxen_get_nic_msg_compid(msg_hdr) \ | ||
1109 | ((msg_hdr >> 40) & 0xFF) | ||
1110 | #define netxen_get_nic_msg_opcode(msg_hdr) \ | ||
1111 | ((msg_hdr >> 32) & 0xFF) | ||
1112 | #define netxen_get_nic_msg_errcode(msg_hdr) \ | ||
1113 | ((msg_hdr >> 16) & 0xFFFF) | ||
1114 | |||
1115 | typedef struct { | ||
1116 | union { | ||
1117 | struct { | ||
1118 | u64 hdr; | ||
1119 | u64 body[7]; | ||
1120 | }; | ||
1121 | u64 words[8]; | ||
1122 | }; | ||
1123 | } nx_fw_msg_t; | ||
1124 | |||
1125 | typedef struct { | ||
1126 | __le64 qhdr; | ||
1127 | __le64 req_hdr; | ||
1128 | __le64 words[6]; | ||
1129 | } nx_nic_req_t; | ||
1130 | |||
1131 | typedef struct { | ||
1132 | u8 op; | ||
1133 | u8 tag; | ||
1134 | u8 mac_addr[6]; | ||
1135 | } nx_mac_req_t; | ||
1136 | |||
1137 | #define MAX_PENDING_DESC_BLOCK_SIZE 64 | ||
1138 | |||
1139 | #define NETXEN_NIC_MSI_ENABLED 0x02 | ||
1140 | #define NETXEN_NIC_MSIX_ENABLED 0x04 | ||
1141 | #define NETXEN_NIC_LRO_ENABLED 0x08 | ||
1142 | #define NETXEN_NIC_LRO_DISABLED 0x00 | ||
1143 | #define NETXEN_NIC_BRIDGE_ENABLED 0X10 | ||
1144 | #define NETXEN_NIC_DIAG_ENABLED 0x20 | ||
1145 | #define NETXEN_IS_MSI_FAMILY(adapter) \ | ||
1146 | ((adapter)->flags & (NETXEN_NIC_MSI_ENABLED | NETXEN_NIC_MSIX_ENABLED)) | ||
1147 | |||
1148 | #define MSIX_ENTRIES_PER_ADAPTER NUM_STS_DESC_RINGS | ||
1149 | #define NETXEN_MSIX_TBL_SPACE 8192 | ||
1150 | #define NETXEN_PCI_REG_MSIX_TBL 0x44 | ||
1151 | |||
1152 | #define NETXEN_DB_MAPSIZE_BYTES 0x1000 | ||
1153 | |||
1154 | #define NETXEN_NETDEV_WEIGHT 128 | ||
1155 | #define NETXEN_ADAPTER_UP_MAGIC 777 | ||
1156 | #define NETXEN_NIC_PEG_TUNE 0 | ||
1157 | |||
1158 | #define __NX_FW_ATTACHED 0 | ||
1159 | #define __NX_DEV_UP 1 | ||
1160 | #define __NX_RESETTING 2 | ||
1161 | |||
1162 | struct netxen_dummy_dma { | ||
1163 | void *addr; | ||
1164 | dma_addr_t phys_addr; | ||
1165 | }; | ||
1166 | |||
1167 | struct netxen_adapter { | ||
1168 | struct netxen_hardware_context ahw; | ||
1169 | |||
1170 | struct net_device *netdev; | ||
1171 | struct pci_dev *pdev; | ||
1172 | struct list_head mac_list; | ||
1173 | struct list_head vlan_ip_list; | ||
1174 | |||
1175 | spinlock_t tx_clean_lock; | ||
1176 | |||
1177 | u16 num_txd; | ||
1178 | u16 num_rxd; | ||
1179 | u16 num_jumbo_rxd; | ||
1180 | u16 num_lro_rxd; | ||
1181 | |||
1182 | u8 max_rds_rings; | ||
1183 | u8 max_sds_rings; | ||
1184 | u8 driver_mismatch; | ||
1185 | u8 msix_supported; | ||
1186 | u8 __pad; | ||
1187 | u8 pci_using_dac; | ||
1188 | u8 portnum; | ||
1189 | u8 physical_port; | ||
1190 | |||
1191 | u8 mc_enabled; | ||
1192 | u8 max_mc_count; | ||
1193 | u8 rss_supported; | ||
1194 | u8 link_changed; | ||
1195 | u8 fw_wait_cnt; | ||
1196 | u8 fw_fail_cnt; | ||
1197 | u8 tx_timeo_cnt; | ||
1198 | u8 need_fw_reset; | ||
1199 | |||
1200 | u8 has_link_events; | ||
1201 | u8 fw_type; | ||
1202 | u16 tx_context_id; | ||
1203 | u16 mtu; | ||
1204 | u16 is_up; | ||
1205 | |||
1206 | u16 link_speed; | ||
1207 | u16 link_duplex; | ||
1208 | u16 link_autoneg; | ||
1209 | u16 module_type; | ||
1210 | |||
1211 | u32 capabilities; | ||
1212 | u32 flags; | ||
1213 | u32 irq; | ||
1214 | u32 temp; | ||
1215 | |||
1216 | u32 int_vec_bit; | ||
1217 | u32 heartbit; | ||
1218 | |||
1219 | u8 mac_addr[ETH_ALEN]; | ||
1220 | |||
1221 | struct netxen_adapter_stats stats; | ||
1222 | |||
1223 | struct netxen_recv_context recv_ctx; | ||
1224 | struct nx_host_tx_ring *tx_ring; | ||
1225 | |||
1226 | int (*macaddr_set) (struct netxen_adapter *, u8 *); | ||
1227 | int (*set_mtu) (struct netxen_adapter *, int); | ||
1228 | int (*set_promisc) (struct netxen_adapter *, u32); | ||
1229 | void (*set_multi) (struct net_device *); | ||
1230 | int (*phy_read) (struct netxen_adapter *, u32 reg, u32 *); | ||
1231 | int (*phy_write) (struct netxen_adapter *, u32 reg, u32 val); | ||
1232 | int (*init_port) (struct netxen_adapter *, int); | ||
1233 | int (*stop_port) (struct netxen_adapter *); | ||
1234 | |||
1235 | u32 (*crb_read)(struct netxen_adapter *, ulong); | ||
1236 | int (*crb_write)(struct netxen_adapter *, ulong, u32); | ||
1237 | |||
1238 | int (*pci_mem_read)(struct netxen_adapter *, u64, u64 *); | ||
1239 | int (*pci_mem_write)(struct netxen_adapter *, u64, u64); | ||
1240 | |||
1241 | int (*pci_set_window)(struct netxen_adapter *, u64, u32 *); | ||
1242 | |||
1243 | u32 (*io_read)(struct netxen_adapter *, void __iomem *); | ||
1244 | void (*io_write)(struct netxen_adapter *, void __iomem *, u32); | ||
1245 | |||
1246 | void __iomem *tgt_mask_reg; | ||
1247 | void __iomem *pci_int_reg; | ||
1248 | void __iomem *tgt_status_reg; | ||
1249 | void __iomem *crb_int_state_reg; | ||
1250 | void __iomem *isr_int_vec; | ||
1251 | |||
1252 | struct msix_entry msix_entries[MSIX_ENTRIES_PER_ADAPTER]; | ||
1253 | |||
1254 | struct netxen_dummy_dma dummy_dma; | ||
1255 | |||
1256 | struct delayed_work fw_work; | ||
1257 | |||
1258 | struct work_struct tx_timeout_task; | ||
1259 | |||
1260 | nx_nic_intr_coalesce_t coal; | ||
1261 | |||
1262 | unsigned long state; | ||
1263 | __le32 file_prd_off; /*File fw product offset*/ | ||
1264 | u32 fw_version; | ||
1265 | const struct firmware *fw; | ||
1266 | }; | ||
1267 | |||
1268 | int nx_fw_cmd_query_phy(struct netxen_adapter *adapter, u32 reg, u32 *val); | ||
1269 | int nx_fw_cmd_set_phy(struct netxen_adapter *adapter, u32 reg, u32 val); | ||
1270 | |||
1271 | #define NXRD32(adapter, off) \ | ||
1272 | (adapter->crb_read(adapter, off)) | ||
1273 | #define NXWR32(adapter, off, val) \ | ||
1274 | (adapter->crb_write(adapter, off, val)) | ||
1275 | #define NXRDIO(adapter, addr) \ | ||
1276 | (adapter->io_read(adapter, addr)) | ||
1277 | #define NXWRIO(adapter, addr, val) \ | ||
1278 | (adapter->io_write(adapter, addr, val)) | ||
1279 | |||
1280 | int netxen_pcie_sem_lock(struct netxen_adapter *, int, u32); | ||
1281 | void netxen_pcie_sem_unlock(struct netxen_adapter *, int); | ||
1282 | |||
1283 | #define netxen_rom_lock(a) \ | ||
1284 | netxen_pcie_sem_lock((a), 2, NETXEN_ROM_LOCK_ID) | ||
1285 | #define netxen_rom_unlock(a) \ | ||
1286 | netxen_pcie_sem_unlock((a), 2) | ||
1287 | #define netxen_phy_lock(a) \ | ||
1288 | netxen_pcie_sem_lock((a), 3, NETXEN_PHY_LOCK_ID) | ||
1289 | #define netxen_phy_unlock(a) \ | ||
1290 | netxen_pcie_sem_unlock((a), 3) | ||
1291 | #define netxen_api_lock(a) \ | ||
1292 | netxen_pcie_sem_lock((a), 5, 0) | ||
1293 | #define netxen_api_unlock(a) \ | ||
1294 | netxen_pcie_sem_unlock((a), 5) | ||
1295 | #define netxen_sw_lock(a) \ | ||
1296 | netxen_pcie_sem_lock((a), 6, 0) | ||
1297 | #define netxen_sw_unlock(a) \ | ||
1298 | netxen_pcie_sem_unlock((a), 6) | ||
1299 | #define crb_win_lock(a) \ | ||
1300 | netxen_pcie_sem_lock((a), 7, NETXEN_CRB_WIN_LOCK_ID) | ||
1301 | #define crb_win_unlock(a) \ | ||
1302 | netxen_pcie_sem_unlock((a), 7) | ||
1303 | |||
1304 | int netxen_nic_get_board_info(struct netxen_adapter *adapter); | ||
1305 | int netxen_nic_wol_supported(struct netxen_adapter *adapter); | ||
1306 | |||
1307 | /* Functions from netxen_nic_init.c */ | ||
1308 | int netxen_init_dummy_dma(struct netxen_adapter *adapter); | ||
1309 | void netxen_free_dummy_dma(struct netxen_adapter *adapter); | ||
1310 | |||
1311 | int netxen_check_flash_fw_compatibility(struct netxen_adapter *adapter); | ||
1312 | int netxen_phantom_init(struct netxen_adapter *adapter, int pegtune_val); | ||
1313 | int netxen_load_firmware(struct netxen_adapter *adapter); | ||
1314 | int netxen_need_fw_reset(struct netxen_adapter *adapter); | ||
1315 | void netxen_request_firmware(struct netxen_adapter *adapter); | ||
1316 | void netxen_release_firmware(struct netxen_adapter *adapter); | ||
1317 | int netxen_pinit_from_rom(struct netxen_adapter *adapter); | ||
1318 | |||
1319 | int netxen_rom_fast_read(struct netxen_adapter *adapter, int addr, int *valp); | ||
1320 | int netxen_rom_fast_read_words(struct netxen_adapter *adapter, int addr, | ||
1321 | u8 *bytes, size_t size); | ||
1322 | int netxen_rom_fast_write_words(struct netxen_adapter *adapter, int addr, | ||
1323 | u8 *bytes, size_t size); | ||
1324 | int netxen_flash_unlock(struct netxen_adapter *adapter); | ||
1325 | int netxen_backup_crbinit(struct netxen_adapter *adapter); | ||
1326 | int netxen_flash_erase_secondary(struct netxen_adapter *adapter); | ||
1327 | int netxen_flash_erase_primary(struct netxen_adapter *adapter); | ||
1328 | void netxen_halt_pegs(struct netxen_adapter *adapter); | ||
1329 | |||
1330 | int netxen_rom_se(struct netxen_adapter *adapter, int addr); | ||
1331 | |||
1332 | int netxen_alloc_sw_resources(struct netxen_adapter *adapter); | ||
1333 | void netxen_free_sw_resources(struct netxen_adapter *adapter); | ||
1334 | |||
1335 | void netxen_setup_hwops(struct netxen_adapter *adapter); | ||
1336 | void __iomem *netxen_get_ioaddr(struct netxen_adapter *, u32); | ||
1337 | |||
1338 | int netxen_alloc_hw_resources(struct netxen_adapter *adapter); | ||
1339 | void netxen_free_hw_resources(struct netxen_adapter *adapter); | ||
1340 | |||
1341 | void netxen_release_rx_buffers(struct netxen_adapter *adapter); | ||
1342 | void netxen_release_tx_buffers(struct netxen_adapter *adapter); | ||
1343 | |||
1344 | int netxen_init_firmware(struct netxen_adapter *adapter); | ||
1345 | void netxen_nic_clear_stats(struct netxen_adapter *adapter); | ||
1346 | void netxen_watchdog_task(struct work_struct *work); | ||
1347 | void netxen_post_rx_buffers(struct netxen_adapter *adapter, u32 ringid, | ||
1348 | struct nx_host_rds_ring *rds_ring); | ||
1349 | int netxen_process_cmd_ring(struct netxen_adapter *adapter); | ||
1350 | int netxen_process_rcv_ring(struct nx_host_sds_ring *sds_ring, int max); | ||
1351 | |||
1352 | void netxen_p3_free_mac_list(struct netxen_adapter *adapter); | ||
1353 | int netxen_config_intr_coalesce(struct netxen_adapter *adapter); | ||
1354 | int netxen_config_rss(struct netxen_adapter *adapter, int enable); | ||
1355 | int netxen_config_ipaddr(struct netxen_adapter *adapter, u32 ip, int cmd); | ||
1356 | int netxen_linkevent_request(struct netxen_adapter *adapter, int enable); | ||
1357 | void netxen_advert_link_change(struct netxen_adapter *adapter, int linkup); | ||
1358 | void netxen_pci_camqm_read_2M(struct netxen_adapter *, u64, u64 *); | ||
1359 | void netxen_pci_camqm_write_2M(struct netxen_adapter *, u64, u64); | ||
1360 | |||
1361 | int nx_fw_cmd_set_gbe_port(struct netxen_adapter *adapter, | ||
1362 | u32 speed, u32 duplex, u32 autoneg); | ||
1363 | int nx_fw_cmd_set_mtu(struct netxen_adapter *adapter, int mtu); | ||
1364 | int netxen_nic_change_mtu(struct net_device *netdev, int new_mtu); | ||
1365 | int netxen_config_hw_lro(struct netxen_adapter *adapter, int enable); | ||
1366 | int netxen_config_bridged_mode(struct netxen_adapter *adapter, int enable); | ||
1367 | int netxen_send_lro_cleanup(struct netxen_adapter *adapter); | ||
1368 | |||
1369 | void netxen_nic_update_cmd_producer(struct netxen_adapter *adapter, | ||
1370 | struct nx_host_tx_ring *tx_ring); | ||
1371 | |||
1372 | /* Functions from netxen_nic_main.c */ | ||
1373 | int netxen_nic_reset_context(struct netxen_adapter *); | ||
1374 | |||
1375 | /* | ||
1376 | * NetXen Board information | ||
1377 | */ | ||
1378 | |||
1379 | #define NETXEN_MAX_SHORT_NAME 32 | ||
1380 | struct netxen_brdinfo { | ||
1381 | int brdtype; /* type of board */ | ||
1382 | long ports; /* max no of physical ports */ | ||
1383 | char short_name[NETXEN_MAX_SHORT_NAME]; | ||
1384 | }; | ||
1385 | |||
1386 | static const struct netxen_brdinfo netxen_boards[] = { | ||
1387 | {NETXEN_BRDTYPE_P2_SB31_10G_CX4, 1, "XGb CX4"}, | ||
1388 | {NETXEN_BRDTYPE_P2_SB31_10G_HMEZ, 1, "XGb HMEZ"}, | ||
1389 | {NETXEN_BRDTYPE_P2_SB31_10G_IMEZ, 2, "XGb IMEZ"}, | ||
1390 | {NETXEN_BRDTYPE_P2_SB31_10G, 1, "XGb XFP"}, | ||
1391 | {NETXEN_BRDTYPE_P2_SB35_4G, 4, "Quad Gb"}, | ||
1392 | {NETXEN_BRDTYPE_P2_SB31_2G, 2, "Dual Gb"}, | ||
1393 | {NETXEN_BRDTYPE_P3_REF_QG, 4, "Reference Quad Gig "}, | ||
1394 | {NETXEN_BRDTYPE_P3_HMEZ, 2, "Dual XGb HMEZ"}, | ||
1395 | {NETXEN_BRDTYPE_P3_10G_CX4_LP, 2, "Dual XGb CX4 LP"}, | ||
1396 | {NETXEN_BRDTYPE_P3_4_GB, 4, "Quad Gig LP"}, | ||
1397 | {NETXEN_BRDTYPE_P3_IMEZ, 2, "Dual XGb IMEZ"}, | ||
1398 | {NETXEN_BRDTYPE_P3_10G_SFP_PLUS, 2, "Dual XGb SFP+ LP"}, | ||
1399 | {NETXEN_BRDTYPE_P3_10000_BASE_T, 1, "XGB 10G BaseT LP"}, | ||
1400 | {NETXEN_BRDTYPE_P3_XG_LOM, 2, "Dual XGb LOM"}, | ||
1401 | {NETXEN_BRDTYPE_P3_4_GB_MM, 4, "NX3031 Gigabit Ethernet"}, | ||
1402 | {NETXEN_BRDTYPE_P3_10G_SFP_CT, 2, "NX3031 10 Gigabit Ethernet"}, | ||
1403 | {NETXEN_BRDTYPE_P3_10G_SFP_QT, 2, "Quanta Dual XGb SFP+"}, | ||
1404 | {NETXEN_BRDTYPE_P3_10G_CX4, 2, "Reference Dual CX4 Option"}, | ||
1405 | {NETXEN_BRDTYPE_P3_10G_XFP, 1, "Reference Single XFP Option"} | ||
1406 | }; | ||
1407 | |||
1408 | #define NUM_SUPPORTED_BOARDS ARRAY_SIZE(netxen_boards) | ||
1409 | |||
1410 | static inline void get_brd_name_by_type(u32 type, char *name) | ||
1411 | { | ||
1412 | int i, found = 0; | ||
1413 | for (i = 0; i < NUM_SUPPORTED_BOARDS; ++i) { | ||
1414 | if (netxen_boards[i].brdtype == type) { | ||
1415 | strcpy(name, netxen_boards[i].short_name); | ||
1416 | found = 1; | ||
1417 | break; | ||
1418 | } | ||
1419 | |||
1420 | } | ||
1421 | if (!found) | ||
1422 | name = "Unknown"; | ||
1423 | } | ||
1424 | |||
1425 | static inline u32 netxen_tx_avail(struct nx_host_tx_ring *tx_ring) | ||
1426 | { | ||
1427 | smp_mb(); | ||
1428 | return find_diff_among(tx_ring->producer, | ||
1429 | tx_ring->sw_consumer, tx_ring->num_desc); | ||
1430 | |||
1431 | } | ||
1432 | |||
1433 | int netxen_get_flash_mac_addr(struct netxen_adapter *adapter, u64 *mac); | ||
1434 | int netxen_p3_get_mac_addr(struct netxen_adapter *adapter, u64 *mac); | ||
1435 | extern void netxen_change_ringparam(struct netxen_adapter *adapter); | ||
1436 | extern int netxen_rom_fast_read(struct netxen_adapter *adapter, int addr, | ||
1437 | int *valp); | ||
1438 | |||
1439 | extern const struct ethtool_ops netxen_nic_ethtool_ops; | ||
1440 | |||
1441 | #endif /* __NETXEN_NIC_H_ */ | ||
diff --git a/drivers/net/ethernet/qlogic/netxen/netxen_nic_ctx.c b/drivers/net/ethernet/qlogic/netxen/netxen_nic_ctx.c new file mode 100644 index 000000000000..a925392abd6f --- /dev/null +++ b/drivers/net/ethernet/qlogic/netxen/netxen_nic_ctx.c | |||
@@ -0,0 +1,793 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2003 - 2009 NetXen, Inc. | ||
3 | * Copyright (C) 2009 - QLogic Corporation. | ||
4 | * All rights reserved. | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or | ||
7 | * modify it under the terms of the GNU General Public License | ||
8 | * as published by the Free Software Foundation; either version 2 | ||
9 | * of the License, or (at your option) any later version. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, but | ||
12 | * 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, | ||
19 | * MA 02111-1307, USA. | ||
20 | * | ||
21 | * The full GNU General Public License is included in this distribution | ||
22 | * in the file called "COPYING". | ||
23 | * | ||
24 | */ | ||
25 | |||
26 | #include "netxen_nic_hw.h" | ||
27 | #include "netxen_nic.h" | ||
28 | |||
29 | #define NXHAL_VERSION 1 | ||
30 | |||
31 | static u32 | ||
32 | netxen_poll_rsp(struct netxen_adapter *adapter) | ||
33 | { | ||
34 | u32 rsp = NX_CDRP_RSP_OK; | ||
35 | int timeout = 0; | ||
36 | |||
37 | do { | ||
38 | /* give atleast 1ms for firmware to respond */ | ||
39 | msleep(1); | ||
40 | |||
41 | if (++timeout > NX_OS_CRB_RETRY_COUNT) | ||
42 | return NX_CDRP_RSP_TIMEOUT; | ||
43 | |||
44 | rsp = NXRD32(adapter, NX_CDRP_CRB_OFFSET); | ||
45 | } while (!NX_CDRP_IS_RSP(rsp)); | ||
46 | |||
47 | return rsp; | ||
48 | } | ||
49 | |||
50 | static u32 | ||
51 | netxen_issue_cmd(struct netxen_adapter *adapter, | ||
52 | u32 pci_fn, u32 version, u32 arg1, u32 arg2, u32 arg3, u32 cmd) | ||
53 | { | ||
54 | u32 rsp; | ||
55 | u32 signature = 0; | ||
56 | u32 rcode = NX_RCODE_SUCCESS; | ||
57 | |||
58 | signature = NX_CDRP_SIGNATURE_MAKE(pci_fn, version); | ||
59 | |||
60 | /* Acquire semaphore before accessing CRB */ | ||
61 | if (netxen_api_lock(adapter)) | ||
62 | return NX_RCODE_TIMEOUT; | ||
63 | |||
64 | NXWR32(adapter, NX_SIGN_CRB_OFFSET, signature); | ||
65 | |||
66 | NXWR32(adapter, NX_ARG1_CRB_OFFSET, arg1); | ||
67 | |||
68 | NXWR32(adapter, NX_ARG2_CRB_OFFSET, arg2); | ||
69 | |||
70 | NXWR32(adapter, NX_ARG3_CRB_OFFSET, arg3); | ||
71 | |||
72 | NXWR32(adapter, NX_CDRP_CRB_OFFSET, NX_CDRP_FORM_CMD(cmd)); | ||
73 | |||
74 | rsp = netxen_poll_rsp(adapter); | ||
75 | |||
76 | if (rsp == NX_CDRP_RSP_TIMEOUT) { | ||
77 | printk(KERN_ERR "%s: card response timeout.\n", | ||
78 | netxen_nic_driver_name); | ||
79 | |||
80 | rcode = NX_RCODE_TIMEOUT; | ||
81 | } else if (rsp == NX_CDRP_RSP_FAIL) { | ||
82 | rcode = NXRD32(adapter, NX_ARG1_CRB_OFFSET); | ||
83 | |||
84 | printk(KERN_ERR "%s: failed card response code:0x%x\n", | ||
85 | netxen_nic_driver_name, rcode); | ||
86 | } | ||
87 | |||
88 | /* Release semaphore */ | ||
89 | netxen_api_unlock(adapter); | ||
90 | |||
91 | return rcode; | ||
92 | } | ||
93 | |||
94 | int | ||
95 | nx_fw_cmd_set_mtu(struct netxen_adapter *adapter, int mtu) | ||
96 | { | ||
97 | u32 rcode = NX_RCODE_SUCCESS; | ||
98 | struct netxen_recv_context *recv_ctx = &adapter->recv_ctx; | ||
99 | |||
100 | if (recv_ctx->state == NX_HOST_CTX_STATE_ACTIVE) | ||
101 | rcode = netxen_issue_cmd(adapter, | ||
102 | adapter->ahw.pci_func, | ||
103 | NXHAL_VERSION, | ||
104 | recv_ctx->context_id, | ||
105 | mtu, | ||
106 | 0, | ||
107 | NX_CDRP_CMD_SET_MTU); | ||
108 | |||
109 | if (rcode != NX_RCODE_SUCCESS) | ||
110 | return -EIO; | ||
111 | |||
112 | return 0; | ||
113 | } | ||
114 | |||
115 | int | ||
116 | nx_fw_cmd_set_gbe_port(struct netxen_adapter *adapter, | ||
117 | u32 speed, u32 duplex, u32 autoneg) | ||
118 | { | ||
119 | |||
120 | return netxen_issue_cmd(adapter, | ||
121 | adapter->ahw.pci_func, | ||
122 | NXHAL_VERSION, | ||
123 | speed, | ||
124 | duplex, | ||
125 | autoneg, | ||
126 | NX_CDRP_CMD_CONFIG_GBE_PORT); | ||
127 | |||
128 | } | ||
129 | |||
130 | static int | ||
131 | nx_fw_cmd_create_rx_ctx(struct netxen_adapter *adapter) | ||
132 | { | ||
133 | void *addr; | ||
134 | nx_hostrq_rx_ctx_t *prq; | ||
135 | nx_cardrsp_rx_ctx_t *prsp; | ||
136 | nx_hostrq_rds_ring_t *prq_rds; | ||
137 | nx_hostrq_sds_ring_t *prq_sds; | ||
138 | nx_cardrsp_rds_ring_t *prsp_rds; | ||
139 | nx_cardrsp_sds_ring_t *prsp_sds; | ||
140 | struct nx_host_rds_ring *rds_ring; | ||
141 | struct nx_host_sds_ring *sds_ring; | ||
142 | |||
143 | dma_addr_t hostrq_phys_addr, cardrsp_phys_addr; | ||
144 | u64 phys_addr; | ||
145 | |||
146 | int i, nrds_rings, nsds_rings; | ||
147 | size_t rq_size, rsp_size; | ||
148 | u32 cap, reg, val; | ||
149 | |||
150 | int err; | ||
151 | |||
152 | struct netxen_recv_context *recv_ctx = &adapter->recv_ctx; | ||
153 | |||
154 | nrds_rings = adapter->max_rds_rings; | ||
155 | nsds_rings = adapter->max_sds_rings; | ||
156 | |||
157 | rq_size = | ||
158 | SIZEOF_HOSTRQ_RX(nx_hostrq_rx_ctx_t, nrds_rings, nsds_rings); | ||
159 | rsp_size = | ||
160 | SIZEOF_CARDRSP_RX(nx_cardrsp_rx_ctx_t, nrds_rings, nsds_rings); | ||
161 | |||
162 | addr = pci_alloc_consistent(adapter->pdev, | ||
163 | rq_size, &hostrq_phys_addr); | ||
164 | if (addr == NULL) | ||
165 | return -ENOMEM; | ||
166 | prq = addr; | ||
167 | |||
168 | addr = pci_alloc_consistent(adapter->pdev, | ||
169 | rsp_size, &cardrsp_phys_addr); | ||
170 | if (addr == NULL) { | ||
171 | err = -ENOMEM; | ||
172 | goto out_free_rq; | ||
173 | } | ||
174 | prsp = addr; | ||
175 | |||
176 | prq->host_rsp_dma_addr = cpu_to_le64(cardrsp_phys_addr); | ||
177 | |||
178 | cap = (NX_CAP0_LEGACY_CONTEXT | NX_CAP0_LEGACY_MN); | ||
179 | cap |= (NX_CAP0_JUMBO_CONTIGUOUS | NX_CAP0_LRO_CONTIGUOUS); | ||
180 | |||
181 | prq->capabilities[0] = cpu_to_le32(cap); | ||
182 | prq->host_int_crb_mode = | ||
183 | cpu_to_le32(NX_HOST_INT_CRB_MODE_SHARED); | ||
184 | prq->host_rds_crb_mode = | ||
185 | cpu_to_le32(NX_HOST_RDS_CRB_MODE_UNIQUE); | ||
186 | |||
187 | prq->num_rds_rings = cpu_to_le16(nrds_rings); | ||
188 | prq->num_sds_rings = cpu_to_le16(nsds_rings); | ||
189 | prq->rds_ring_offset = cpu_to_le32(0); | ||
190 | |||
191 | val = le32_to_cpu(prq->rds_ring_offset) + | ||
192 | (sizeof(nx_hostrq_rds_ring_t) * nrds_rings); | ||
193 | prq->sds_ring_offset = cpu_to_le32(val); | ||
194 | |||
195 | prq_rds = (nx_hostrq_rds_ring_t *)(prq->data + | ||
196 | le32_to_cpu(prq->rds_ring_offset)); | ||
197 | |||
198 | for (i = 0; i < nrds_rings; i++) { | ||
199 | |||
200 | rds_ring = &recv_ctx->rds_rings[i]; | ||
201 | |||
202 | prq_rds[i].host_phys_addr = cpu_to_le64(rds_ring->phys_addr); | ||
203 | prq_rds[i].ring_size = cpu_to_le32(rds_ring->num_desc); | ||
204 | prq_rds[i].ring_kind = cpu_to_le32(i); | ||
205 | prq_rds[i].buff_size = cpu_to_le64(rds_ring->dma_size); | ||
206 | } | ||
207 | |||
208 | prq_sds = (nx_hostrq_sds_ring_t *)(prq->data + | ||
209 | le32_to_cpu(prq->sds_ring_offset)); | ||
210 | |||
211 | for (i = 0; i < nsds_rings; i++) { | ||
212 | |||
213 | sds_ring = &recv_ctx->sds_rings[i]; | ||
214 | |||
215 | prq_sds[i].host_phys_addr = cpu_to_le64(sds_ring->phys_addr); | ||
216 | prq_sds[i].ring_size = cpu_to_le32(sds_ring->num_desc); | ||
217 | prq_sds[i].msi_index = cpu_to_le16(i); | ||
218 | } | ||
219 | |||
220 | phys_addr = hostrq_phys_addr; | ||
221 | err = netxen_issue_cmd(adapter, | ||
222 | adapter->ahw.pci_func, | ||
223 | NXHAL_VERSION, | ||
224 | (u32)(phys_addr >> 32), | ||
225 | (u32)(phys_addr & 0xffffffff), | ||
226 | rq_size, | ||
227 | NX_CDRP_CMD_CREATE_RX_CTX); | ||
228 | if (err) { | ||
229 | printk(KERN_WARNING | ||
230 | "Failed to create rx ctx in firmware%d\n", err); | ||
231 | goto out_free_rsp; | ||
232 | } | ||
233 | |||
234 | |||
235 | prsp_rds = ((nx_cardrsp_rds_ring_t *) | ||
236 | &prsp->data[le32_to_cpu(prsp->rds_ring_offset)]); | ||
237 | |||
238 | for (i = 0; i < le16_to_cpu(prsp->num_rds_rings); i++) { | ||
239 | rds_ring = &recv_ctx->rds_rings[i]; | ||
240 | |||
241 | reg = le32_to_cpu(prsp_rds[i].host_producer_crb); | ||
242 | rds_ring->crb_rcv_producer = netxen_get_ioaddr(adapter, | ||
243 | NETXEN_NIC_REG(reg - 0x200)); | ||
244 | } | ||
245 | |||
246 | prsp_sds = ((nx_cardrsp_sds_ring_t *) | ||
247 | &prsp->data[le32_to_cpu(prsp->sds_ring_offset)]); | ||
248 | |||
249 | for (i = 0; i < le16_to_cpu(prsp->num_sds_rings); i++) { | ||
250 | sds_ring = &recv_ctx->sds_rings[i]; | ||
251 | |||
252 | reg = le32_to_cpu(prsp_sds[i].host_consumer_crb); | ||
253 | sds_ring->crb_sts_consumer = netxen_get_ioaddr(adapter, | ||
254 | NETXEN_NIC_REG(reg - 0x200)); | ||
255 | |||
256 | reg = le32_to_cpu(prsp_sds[i].interrupt_crb); | ||
257 | sds_ring->crb_intr_mask = netxen_get_ioaddr(adapter, | ||
258 | NETXEN_NIC_REG(reg - 0x200)); | ||
259 | } | ||
260 | |||
261 | recv_ctx->state = le32_to_cpu(prsp->host_ctx_state); | ||
262 | recv_ctx->context_id = le16_to_cpu(prsp->context_id); | ||
263 | recv_ctx->virt_port = prsp->virt_port; | ||
264 | |||
265 | out_free_rsp: | ||
266 | pci_free_consistent(adapter->pdev, rsp_size, prsp, cardrsp_phys_addr); | ||
267 | out_free_rq: | ||
268 | pci_free_consistent(adapter->pdev, rq_size, prq, hostrq_phys_addr); | ||
269 | return err; | ||
270 | } | ||
271 | |||
272 | static void | ||
273 | nx_fw_cmd_destroy_rx_ctx(struct netxen_adapter *adapter) | ||
274 | { | ||
275 | struct netxen_recv_context *recv_ctx = &adapter->recv_ctx; | ||
276 | |||
277 | if (netxen_issue_cmd(adapter, | ||
278 | adapter->ahw.pci_func, | ||
279 | NXHAL_VERSION, | ||
280 | recv_ctx->context_id, | ||
281 | NX_DESTROY_CTX_RESET, | ||
282 | 0, | ||
283 | NX_CDRP_CMD_DESTROY_RX_CTX)) { | ||
284 | |||
285 | printk(KERN_WARNING | ||
286 | "%s: Failed to destroy rx ctx in firmware\n", | ||
287 | netxen_nic_driver_name); | ||
288 | } | ||
289 | } | ||
290 | |||
291 | static int | ||
292 | nx_fw_cmd_create_tx_ctx(struct netxen_adapter *adapter) | ||
293 | { | ||
294 | nx_hostrq_tx_ctx_t *prq; | ||
295 | nx_hostrq_cds_ring_t *prq_cds; | ||
296 | nx_cardrsp_tx_ctx_t *prsp; | ||
297 | void *rq_addr, *rsp_addr; | ||
298 | size_t rq_size, rsp_size; | ||
299 | u32 temp; | ||
300 | int err = 0; | ||
301 | u64 offset, phys_addr; | ||
302 | dma_addr_t rq_phys_addr, rsp_phys_addr; | ||
303 | struct nx_host_tx_ring *tx_ring = adapter->tx_ring; | ||
304 | struct netxen_recv_context *recv_ctx = &adapter->recv_ctx; | ||
305 | |||
306 | rq_size = SIZEOF_HOSTRQ_TX(nx_hostrq_tx_ctx_t); | ||
307 | rq_addr = pci_alloc_consistent(adapter->pdev, | ||
308 | rq_size, &rq_phys_addr); | ||
309 | if (!rq_addr) | ||
310 | return -ENOMEM; | ||
311 | |||
312 | rsp_size = SIZEOF_CARDRSP_TX(nx_cardrsp_tx_ctx_t); | ||
313 | rsp_addr = pci_alloc_consistent(adapter->pdev, | ||
314 | rsp_size, &rsp_phys_addr); | ||
315 | if (!rsp_addr) { | ||
316 | err = -ENOMEM; | ||
317 | goto out_free_rq; | ||
318 | } | ||
319 | |||
320 | memset(rq_addr, 0, rq_size); | ||
321 | prq = rq_addr; | ||
322 | |||
323 | memset(rsp_addr, 0, rsp_size); | ||
324 | prsp = rsp_addr; | ||
325 | |||
326 | prq->host_rsp_dma_addr = cpu_to_le64(rsp_phys_addr); | ||
327 | |||
328 | temp = (NX_CAP0_LEGACY_CONTEXT | NX_CAP0_LEGACY_MN | NX_CAP0_LSO); | ||
329 | prq->capabilities[0] = cpu_to_le32(temp); | ||
330 | |||
331 | prq->host_int_crb_mode = | ||
332 | cpu_to_le32(NX_HOST_INT_CRB_MODE_SHARED); | ||
333 | |||
334 | prq->interrupt_ctl = 0; | ||
335 | prq->msi_index = 0; | ||
336 | |||
337 | prq->dummy_dma_addr = cpu_to_le64(adapter->dummy_dma.phys_addr); | ||
338 | |||
339 | offset = recv_ctx->phys_addr + sizeof(struct netxen_ring_ctx); | ||
340 | prq->cmd_cons_dma_addr = cpu_to_le64(offset); | ||
341 | |||
342 | prq_cds = &prq->cds_ring; | ||
343 | |||
344 | prq_cds->host_phys_addr = cpu_to_le64(tx_ring->phys_addr); | ||
345 | prq_cds->ring_size = cpu_to_le32(tx_ring->num_desc); | ||
346 | |||
347 | phys_addr = rq_phys_addr; | ||
348 | err = netxen_issue_cmd(adapter, | ||
349 | adapter->ahw.pci_func, | ||
350 | NXHAL_VERSION, | ||
351 | (u32)(phys_addr >> 32), | ||
352 | ((u32)phys_addr & 0xffffffff), | ||
353 | rq_size, | ||
354 | NX_CDRP_CMD_CREATE_TX_CTX); | ||
355 | |||
356 | if (err == NX_RCODE_SUCCESS) { | ||
357 | temp = le32_to_cpu(prsp->cds_ring.host_producer_crb); | ||
358 | tx_ring->crb_cmd_producer = netxen_get_ioaddr(adapter, | ||
359 | NETXEN_NIC_REG(temp - 0x200)); | ||
360 | #if 0 | ||
361 | adapter->tx_state = | ||
362 | le32_to_cpu(prsp->host_ctx_state); | ||
363 | #endif | ||
364 | adapter->tx_context_id = | ||
365 | le16_to_cpu(prsp->context_id); | ||
366 | } else { | ||
367 | printk(KERN_WARNING | ||
368 | "Failed to create tx ctx in firmware%d\n", err); | ||
369 | err = -EIO; | ||
370 | } | ||
371 | |||
372 | pci_free_consistent(adapter->pdev, rsp_size, rsp_addr, rsp_phys_addr); | ||
373 | |||
374 | out_free_rq: | ||
375 | pci_free_consistent(adapter->pdev, rq_size, rq_addr, rq_phys_addr); | ||
376 | |||
377 | return err; | ||
378 | } | ||
379 | |||
380 | static void | ||
381 | nx_fw_cmd_destroy_tx_ctx(struct netxen_adapter *adapter) | ||
382 | { | ||
383 | if (netxen_issue_cmd(adapter, | ||
384 | adapter->ahw.pci_func, | ||
385 | NXHAL_VERSION, | ||
386 | adapter->tx_context_id, | ||
387 | NX_DESTROY_CTX_RESET, | ||
388 | 0, | ||
389 | NX_CDRP_CMD_DESTROY_TX_CTX)) { | ||
390 | |||
391 | printk(KERN_WARNING | ||
392 | "%s: Failed to destroy tx ctx in firmware\n", | ||
393 | netxen_nic_driver_name); | ||
394 | } | ||
395 | } | ||
396 | |||
397 | int | ||
398 | nx_fw_cmd_query_phy(struct netxen_adapter *adapter, u32 reg, u32 *val) | ||
399 | { | ||
400 | u32 rcode; | ||
401 | |||
402 | rcode = netxen_issue_cmd(adapter, | ||
403 | adapter->ahw.pci_func, | ||
404 | NXHAL_VERSION, | ||
405 | reg, | ||
406 | 0, | ||
407 | 0, | ||
408 | NX_CDRP_CMD_READ_PHY); | ||
409 | |||
410 | if (rcode != NX_RCODE_SUCCESS) | ||
411 | return -EIO; | ||
412 | |||
413 | return NXRD32(adapter, NX_ARG1_CRB_OFFSET); | ||
414 | } | ||
415 | |||
416 | int | ||
417 | nx_fw_cmd_set_phy(struct netxen_adapter *adapter, u32 reg, u32 val) | ||
418 | { | ||
419 | u32 rcode; | ||
420 | |||
421 | rcode = netxen_issue_cmd(adapter, | ||
422 | adapter->ahw.pci_func, | ||
423 | NXHAL_VERSION, | ||
424 | reg, | ||
425 | val, | ||
426 | 0, | ||
427 | NX_CDRP_CMD_WRITE_PHY); | ||
428 | |||
429 | if (rcode != NX_RCODE_SUCCESS) | ||
430 | return -EIO; | ||
431 | |||
432 | return 0; | ||
433 | } | ||
434 | |||
435 | static u64 ctx_addr_sig_regs[][3] = { | ||
436 | {NETXEN_NIC_REG(0x188), NETXEN_NIC_REG(0x18c), NETXEN_NIC_REG(0x1c0)}, | ||
437 | {NETXEN_NIC_REG(0x190), NETXEN_NIC_REG(0x194), NETXEN_NIC_REG(0x1c4)}, | ||
438 | {NETXEN_NIC_REG(0x198), NETXEN_NIC_REG(0x19c), NETXEN_NIC_REG(0x1c8)}, | ||
439 | {NETXEN_NIC_REG(0x1a0), NETXEN_NIC_REG(0x1a4), NETXEN_NIC_REG(0x1cc)} | ||
440 | }; | ||
441 | |||
442 | #define CRB_CTX_ADDR_REG_LO(FUNC_ID) (ctx_addr_sig_regs[FUNC_ID][0]) | ||
443 | #define CRB_CTX_ADDR_REG_HI(FUNC_ID) (ctx_addr_sig_regs[FUNC_ID][2]) | ||
444 | #define CRB_CTX_SIGNATURE_REG(FUNC_ID) (ctx_addr_sig_regs[FUNC_ID][1]) | ||
445 | |||
446 | #define lower32(x) ((u32)((x) & 0xffffffff)) | ||
447 | #define upper32(x) ((u32)(((u64)(x) >> 32) & 0xffffffff)) | ||
448 | |||
449 | static struct netxen_recv_crb recv_crb_registers[] = { | ||
450 | /* Instance 0 */ | ||
451 | { | ||
452 | /* crb_rcv_producer: */ | ||
453 | { | ||
454 | NETXEN_NIC_REG(0x100), | ||
455 | /* Jumbo frames */ | ||
456 | NETXEN_NIC_REG(0x110), | ||
457 | /* LRO */ | ||
458 | NETXEN_NIC_REG(0x120) | ||
459 | }, | ||
460 | /* crb_sts_consumer: */ | ||
461 | { | ||
462 | NETXEN_NIC_REG(0x138), | ||
463 | NETXEN_NIC_REG_2(0x000), | ||
464 | NETXEN_NIC_REG_2(0x004), | ||
465 | NETXEN_NIC_REG_2(0x008), | ||
466 | }, | ||
467 | /* sw_int_mask */ | ||
468 | { | ||
469 | CRB_SW_INT_MASK_0, | ||
470 | NETXEN_NIC_REG_2(0x044), | ||
471 | NETXEN_NIC_REG_2(0x048), | ||
472 | NETXEN_NIC_REG_2(0x04c), | ||
473 | }, | ||
474 | }, | ||
475 | /* Instance 1 */ | ||
476 | { | ||
477 | /* crb_rcv_producer: */ | ||
478 | { | ||
479 | NETXEN_NIC_REG(0x144), | ||
480 | /* Jumbo frames */ | ||
481 | NETXEN_NIC_REG(0x154), | ||
482 | /* LRO */ | ||
483 | NETXEN_NIC_REG(0x164) | ||
484 | }, | ||
485 | /* crb_sts_consumer: */ | ||
486 | { | ||
487 | NETXEN_NIC_REG(0x17c), | ||
488 | NETXEN_NIC_REG_2(0x020), | ||
489 | NETXEN_NIC_REG_2(0x024), | ||
490 | NETXEN_NIC_REG_2(0x028), | ||
491 | }, | ||
492 | /* sw_int_mask */ | ||
493 | { | ||
494 | CRB_SW_INT_MASK_1, | ||
495 | NETXEN_NIC_REG_2(0x064), | ||
496 | NETXEN_NIC_REG_2(0x068), | ||
497 | NETXEN_NIC_REG_2(0x06c), | ||
498 | }, | ||
499 | }, | ||
500 | /* Instance 2 */ | ||
501 | { | ||
502 | /* crb_rcv_producer: */ | ||
503 | { | ||
504 | NETXEN_NIC_REG(0x1d8), | ||
505 | /* Jumbo frames */ | ||
506 | NETXEN_NIC_REG(0x1f8), | ||
507 | /* LRO */ | ||
508 | NETXEN_NIC_REG(0x208) | ||
509 | }, | ||
510 | /* crb_sts_consumer: */ | ||
511 | { | ||
512 | NETXEN_NIC_REG(0x220), | ||
513 | NETXEN_NIC_REG_2(0x03c), | ||
514 | NETXEN_NIC_REG_2(0x03c), | ||
515 | NETXEN_NIC_REG_2(0x03c), | ||
516 | }, | ||
517 | /* sw_int_mask */ | ||
518 | { | ||
519 | CRB_SW_INT_MASK_2, | ||
520 | NETXEN_NIC_REG_2(0x03c), | ||
521 | NETXEN_NIC_REG_2(0x03c), | ||
522 | NETXEN_NIC_REG_2(0x03c), | ||
523 | }, | ||
524 | }, | ||
525 | /* Instance 3 */ | ||
526 | { | ||
527 | /* crb_rcv_producer: */ | ||
528 | { | ||
529 | NETXEN_NIC_REG(0x22c), | ||
530 | /* Jumbo frames */ | ||
531 | NETXEN_NIC_REG(0x23c), | ||
532 | /* LRO */ | ||
533 | NETXEN_NIC_REG(0x24c) | ||
534 | }, | ||
535 | /* crb_sts_consumer: */ | ||
536 | { | ||
537 | NETXEN_NIC_REG(0x264), | ||
538 | NETXEN_NIC_REG_2(0x03c), | ||
539 | NETXEN_NIC_REG_2(0x03c), | ||
540 | NETXEN_NIC_REG_2(0x03c), | ||
541 | }, | ||
542 | /* sw_int_mask */ | ||
543 | { | ||
544 | CRB_SW_INT_MASK_3, | ||
545 | NETXEN_NIC_REG_2(0x03c), | ||
546 | NETXEN_NIC_REG_2(0x03c), | ||
547 | NETXEN_NIC_REG_2(0x03c), | ||
548 | }, | ||
549 | }, | ||
550 | }; | ||
551 | |||
552 | static int | ||
553 | netxen_init_old_ctx(struct netxen_adapter *adapter) | ||
554 | { | ||
555 | struct netxen_recv_context *recv_ctx; | ||
556 | struct nx_host_rds_ring *rds_ring; | ||
557 | struct nx_host_sds_ring *sds_ring; | ||
558 | struct nx_host_tx_ring *tx_ring; | ||
559 | int ring; | ||
560 | int port = adapter->portnum; | ||
561 | struct netxen_ring_ctx *hwctx; | ||
562 | u32 signature; | ||
563 | |||
564 | tx_ring = adapter->tx_ring; | ||
565 | recv_ctx = &adapter->recv_ctx; | ||
566 | hwctx = recv_ctx->hwctx; | ||
567 | |||
568 | hwctx->cmd_ring_addr = cpu_to_le64(tx_ring->phys_addr); | ||
569 | hwctx->cmd_ring_size = cpu_to_le32(tx_ring->num_desc); | ||
570 | |||
571 | |||
572 | for (ring = 0; ring < adapter->max_rds_rings; ring++) { | ||
573 | rds_ring = &recv_ctx->rds_rings[ring]; | ||
574 | |||
575 | hwctx->rcv_rings[ring].addr = | ||
576 | cpu_to_le64(rds_ring->phys_addr); | ||
577 | hwctx->rcv_rings[ring].size = | ||
578 | cpu_to_le32(rds_ring->num_desc); | ||
579 | } | ||
580 | |||
581 | for (ring = 0; ring < adapter->max_sds_rings; ring++) { | ||
582 | sds_ring = &recv_ctx->sds_rings[ring]; | ||
583 | |||
584 | if (ring == 0) { | ||
585 | hwctx->sts_ring_addr = cpu_to_le64(sds_ring->phys_addr); | ||
586 | hwctx->sts_ring_size = cpu_to_le32(sds_ring->num_desc); | ||
587 | } | ||
588 | hwctx->sts_rings[ring].addr = cpu_to_le64(sds_ring->phys_addr); | ||
589 | hwctx->sts_rings[ring].size = cpu_to_le32(sds_ring->num_desc); | ||
590 | hwctx->sts_rings[ring].msi_index = cpu_to_le16(ring); | ||
591 | } | ||
592 | hwctx->sts_ring_count = cpu_to_le32(adapter->max_sds_rings); | ||
593 | |||
594 | signature = (adapter->max_sds_rings > 1) ? | ||
595 | NETXEN_CTX_SIGNATURE_V2 : NETXEN_CTX_SIGNATURE; | ||
596 | |||
597 | NXWR32(adapter, CRB_CTX_ADDR_REG_LO(port), | ||
598 | lower32(recv_ctx->phys_addr)); | ||
599 | NXWR32(adapter, CRB_CTX_ADDR_REG_HI(port), | ||
600 | upper32(recv_ctx->phys_addr)); | ||
601 | NXWR32(adapter, CRB_CTX_SIGNATURE_REG(port), | ||
602 | signature | port); | ||
603 | return 0; | ||
604 | } | ||
605 | |||
606 | int netxen_alloc_hw_resources(struct netxen_adapter *adapter) | ||
607 | { | ||
608 | void *addr; | ||
609 | int err = 0; | ||
610 | int ring; | ||
611 | struct netxen_recv_context *recv_ctx; | ||
612 | struct nx_host_rds_ring *rds_ring; | ||
613 | struct nx_host_sds_ring *sds_ring; | ||
614 | struct nx_host_tx_ring *tx_ring; | ||
615 | |||
616 | struct pci_dev *pdev = adapter->pdev; | ||
617 | struct net_device *netdev = adapter->netdev; | ||
618 | int port = adapter->portnum; | ||
619 | |||
620 | recv_ctx = &adapter->recv_ctx; | ||
621 | tx_ring = adapter->tx_ring; | ||
622 | |||
623 | addr = pci_alloc_consistent(pdev, | ||
624 | sizeof(struct netxen_ring_ctx) + sizeof(uint32_t), | ||
625 | &recv_ctx->phys_addr); | ||
626 | if (addr == NULL) { | ||
627 | dev_err(&pdev->dev, "failed to allocate hw context\n"); | ||
628 | return -ENOMEM; | ||
629 | } | ||
630 | |||
631 | memset(addr, 0, sizeof(struct netxen_ring_ctx)); | ||
632 | recv_ctx->hwctx = addr; | ||
633 | recv_ctx->hwctx->ctx_id = cpu_to_le32(port); | ||
634 | recv_ctx->hwctx->cmd_consumer_offset = | ||
635 | cpu_to_le64(recv_ctx->phys_addr + | ||
636 | sizeof(struct netxen_ring_ctx)); | ||
637 | tx_ring->hw_consumer = | ||
638 | (__le32 *)(((char *)addr) + sizeof(struct netxen_ring_ctx)); | ||
639 | |||
640 | /* cmd desc ring */ | ||
641 | addr = pci_alloc_consistent(pdev, TX_DESC_RINGSIZE(tx_ring), | ||
642 | &tx_ring->phys_addr); | ||
643 | |||
644 | if (addr == NULL) { | ||
645 | dev_err(&pdev->dev, "%s: failed to allocate tx desc ring\n", | ||
646 | netdev->name); | ||
647 | err = -ENOMEM; | ||
648 | goto err_out_free; | ||
649 | } | ||
650 | |||
651 | tx_ring->desc_head = addr; | ||
652 | |||
653 | for (ring = 0; ring < adapter->max_rds_rings; ring++) { | ||
654 | rds_ring = &recv_ctx->rds_rings[ring]; | ||
655 | addr = pci_alloc_consistent(adapter->pdev, | ||
656 | RCV_DESC_RINGSIZE(rds_ring), | ||
657 | &rds_ring->phys_addr); | ||
658 | if (addr == NULL) { | ||
659 | dev_err(&pdev->dev, | ||
660 | "%s: failed to allocate rds ring [%d]\n", | ||
661 | netdev->name, ring); | ||
662 | err = -ENOMEM; | ||
663 | goto err_out_free; | ||
664 | } | ||
665 | rds_ring->desc_head = addr; | ||
666 | |||
667 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) | ||
668 | rds_ring->crb_rcv_producer = | ||
669 | netxen_get_ioaddr(adapter, | ||
670 | recv_crb_registers[port].crb_rcv_producer[ring]); | ||
671 | } | ||
672 | |||
673 | for (ring = 0; ring < adapter->max_sds_rings; ring++) { | ||
674 | sds_ring = &recv_ctx->sds_rings[ring]; | ||
675 | |||
676 | addr = pci_alloc_consistent(adapter->pdev, | ||
677 | STATUS_DESC_RINGSIZE(sds_ring), | ||
678 | &sds_ring->phys_addr); | ||
679 | if (addr == NULL) { | ||
680 | dev_err(&pdev->dev, | ||
681 | "%s: failed to allocate sds ring [%d]\n", | ||
682 | netdev->name, ring); | ||
683 | err = -ENOMEM; | ||
684 | goto err_out_free; | ||
685 | } | ||
686 | sds_ring->desc_head = addr; | ||
687 | |||
688 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) { | ||
689 | sds_ring->crb_sts_consumer = | ||
690 | netxen_get_ioaddr(adapter, | ||
691 | recv_crb_registers[port].crb_sts_consumer[ring]); | ||
692 | |||
693 | sds_ring->crb_intr_mask = | ||
694 | netxen_get_ioaddr(adapter, | ||
695 | recv_crb_registers[port].sw_int_mask[ring]); | ||
696 | } | ||
697 | } | ||
698 | |||
699 | |||
700 | if (!NX_IS_REVISION_P2(adapter->ahw.revision_id)) { | ||
701 | if (test_and_set_bit(__NX_FW_ATTACHED, &adapter->state)) | ||
702 | goto done; | ||
703 | err = nx_fw_cmd_create_rx_ctx(adapter); | ||
704 | if (err) | ||
705 | goto err_out_free; | ||
706 | err = nx_fw_cmd_create_tx_ctx(adapter); | ||
707 | if (err) | ||
708 | goto err_out_free; | ||
709 | } else { | ||
710 | err = netxen_init_old_ctx(adapter); | ||
711 | if (err) | ||
712 | goto err_out_free; | ||
713 | } | ||
714 | |||
715 | done: | ||
716 | return 0; | ||
717 | |||
718 | err_out_free: | ||
719 | netxen_free_hw_resources(adapter); | ||
720 | return err; | ||
721 | } | ||
722 | |||
723 | void netxen_free_hw_resources(struct netxen_adapter *adapter) | ||
724 | { | ||
725 | struct netxen_recv_context *recv_ctx; | ||
726 | struct nx_host_rds_ring *rds_ring; | ||
727 | struct nx_host_sds_ring *sds_ring; | ||
728 | struct nx_host_tx_ring *tx_ring; | ||
729 | int ring; | ||
730 | |||
731 | int port = adapter->portnum; | ||
732 | |||
733 | if (!NX_IS_REVISION_P2(adapter->ahw.revision_id)) { | ||
734 | if (!test_and_clear_bit(__NX_FW_ATTACHED, &adapter->state)) | ||
735 | goto done; | ||
736 | |||
737 | nx_fw_cmd_destroy_rx_ctx(adapter); | ||
738 | nx_fw_cmd_destroy_tx_ctx(adapter); | ||
739 | } else { | ||
740 | netxen_api_lock(adapter); | ||
741 | NXWR32(adapter, CRB_CTX_SIGNATURE_REG(port), | ||
742 | NETXEN_CTX_D3_RESET | port); | ||
743 | netxen_api_unlock(adapter); | ||
744 | } | ||
745 | |||
746 | /* Allow dma queues to drain after context reset */ | ||
747 | msleep(20); | ||
748 | |||
749 | done: | ||
750 | recv_ctx = &adapter->recv_ctx; | ||
751 | |||
752 | if (recv_ctx->hwctx != NULL) { | ||
753 | pci_free_consistent(adapter->pdev, | ||
754 | sizeof(struct netxen_ring_ctx) + | ||
755 | sizeof(uint32_t), | ||
756 | recv_ctx->hwctx, | ||
757 | recv_ctx->phys_addr); | ||
758 | recv_ctx->hwctx = NULL; | ||
759 | } | ||
760 | |||
761 | tx_ring = adapter->tx_ring; | ||
762 | if (tx_ring->desc_head != NULL) { | ||
763 | pci_free_consistent(adapter->pdev, | ||
764 | TX_DESC_RINGSIZE(tx_ring), | ||
765 | tx_ring->desc_head, tx_ring->phys_addr); | ||
766 | tx_ring->desc_head = NULL; | ||
767 | } | ||
768 | |||
769 | for (ring = 0; ring < adapter->max_rds_rings; ring++) { | ||
770 | rds_ring = &recv_ctx->rds_rings[ring]; | ||
771 | |||
772 | if (rds_ring->desc_head != NULL) { | ||
773 | pci_free_consistent(adapter->pdev, | ||
774 | RCV_DESC_RINGSIZE(rds_ring), | ||
775 | rds_ring->desc_head, | ||
776 | rds_ring->phys_addr); | ||
777 | rds_ring->desc_head = NULL; | ||
778 | } | ||
779 | } | ||
780 | |||
781 | for (ring = 0; ring < adapter->max_sds_rings; ring++) { | ||
782 | sds_ring = &recv_ctx->sds_rings[ring]; | ||
783 | |||
784 | if (sds_ring->desc_head != NULL) { | ||
785 | pci_free_consistent(adapter->pdev, | ||
786 | STATUS_DESC_RINGSIZE(sds_ring), | ||
787 | sds_ring->desc_head, | ||
788 | sds_ring->phys_addr); | ||
789 | sds_ring->desc_head = NULL; | ||
790 | } | ||
791 | } | ||
792 | } | ||
793 | |||
diff --git a/drivers/net/ethernet/qlogic/netxen/netxen_nic_ethtool.c b/drivers/net/ethernet/qlogic/netxen/netxen_nic_ethtool.c new file mode 100644 index 000000000000..b34fb74d07e3 --- /dev/null +++ b/drivers/net/ethernet/qlogic/netxen/netxen_nic_ethtool.c | |||
@@ -0,0 +1,835 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2003 - 2009 NetXen, Inc. | ||
3 | * Copyright (C) 2009 - QLogic Corporation. | ||
4 | * All rights reserved. | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or | ||
7 | * modify it under the terms of the GNU General Public License | ||
8 | * as published by the Free Software Foundation; either version 2 | ||
9 | * of the License, or (at your option) any later version. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, but | ||
12 | * 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, | ||
19 | * MA 02111-1307, USA. | ||
20 | * | ||
21 | * The full GNU General Public License is included in this distribution | ||
22 | * in the file called "COPYING". | ||
23 | * | ||
24 | */ | ||
25 | |||
26 | #include <linux/types.h> | ||
27 | #include <linux/delay.h> | ||
28 | #include <linux/pci.h> | ||
29 | #include <asm/io.h> | ||
30 | #include <linux/netdevice.h> | ||
31 | #include <linux/ethtool.h> | ||
32 | |||
33 | #include "netxen_nic.h" | ||
34 | #include "netxen_nic_hw.h" | ||
35 | |||
36 | struct netxen_nic_stats { | ||
37 | char stat_string[ETH_GSTRING_LEN]; | ||
38 | int sizeof_stat; | ||
39 | int stat_offset; | ||
40 | }; | ||
41 | |||
42 | #define NETXEN_NIC_STAT(m) sizeof(((struct netxen_adapter *)0)->m), \ | ||
43 | offsetof(struct netxen_adapter, m) | ||
44 | |||
45 | #define NETXEN_NIC_PORT_WINDOW 0x10000 | ||
46 | #define NETXEN_NIC_INVALID_DATA 0xDEADBEEF | ||
47 | |||
48 | static const struct netxen_nic_stats netxen_nic_gstrings_stats[] = { | ||
49 | {"xmit_called", NETXEN_NIC_STAT(stats.xmitcalled)}, | ||
50 | {"xmit_finished", NETXEN_NIC_STAT(stats.xmitfinished)}, | ||
51 | {"rx_dropped", NETXEN_NIC_STAT(stats.rxdropped)}, | ||
52 | {"tx_dropped", NETXEN_NIC_STAT(stats.txdropped)}, | ||
53 | {"csummed", NETXEN_NIC_STAT(stats.csummed)}, | ||
54 | {"rx_pkts", NETXEN_NIC_STAT(stats.rx_pkts)}, | ||
55 | {"lro_pkts", NETXEN_NIC_STAT(stats.lro_pkts)}, | ||
56 | {"rx_bytes", NETXEN_NIC_STAT(stats.rxbytes)}, | ||
57 | {"tx_bytes", NETXEN_NIC_STAT(stats.txbytes)}, | ||
58 | }; | ||
59 | |||
60 | #define NETXEN_NIC_STATS_LEN ARRAY_SIZE(netxen_nic_gstrings_stats) | ||
61 | |||
62 | static const char netxen_nic_gstrings_test[][ETH_GSTRING_LEN] = { | ||
63 | "Register_Test_on_offline", | ||
64 | "Link_Test_on_offline" | ||
65 | }; | ||
66 | |||
67 | #define NETXEN_NIC_TEST_LEN ARRAY_SIZE(netxen_nic_gstrings_test) | ||
68 | |||
69 | #define NETXEN_NIC_REGS_COUNT 30 | ||
70 | #define NETXEN_NIC_REGS_LEN (NETXEN_NIC_REGS_COUNT * sizeof(__le32)) | ||
71 | #define NETXEN_MAX_EEPROM_LEN 1024 | ||
72 | |||
73 | static int netxen_nic_get_eeprom_len(struct net_device *dev) | ||
74 | { | ||
75 | return NETXEN_FLASH_TOTAL_SIZE; | ||
76 | } | ||
77 | |||
78 | static void | ||
79 | netxen_nic_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *drvinfo) | ||
80 | { | ||
81 | struct netxen_adapter *adapter = netdev_priv(dev); | ||
82 | u32 fw_major = 0; | ||
83 | u32 fw_minor = 0; | ||
84 | u32 fw_build = 0; | ||
85 | |||
86 | strncpy(drvinfo->driver, netxen_nic_driver_name, 32); | ||
87 | strncpy(drvinfo->version, NETXEN_NIC_LINUX_VERSIONID, 32); | ||
88 | fw_major = NXRD32(adapter, NETXEN_FW_VERSION_MAJOR); | ||
89 | fw_minor = NXRD32(adapter, NETXEN_FW_VERSION_MINOR); | ||
90 | fw_build = NXRD32(adapter, NETXEN_FW_VERSION_SUB); | ||
91 | sprintf(drvinfo->fw_version, "%d.%d.%d", fw_major, fw_minor, fw_build); | ||
92 | |||
93 | strncpy(drvinfo->bus_info, pci_name(adapter->pdev), 32); | ||
94 | drvinfo->regdump_len = NETXEN_NIC_REGS_LEN; | ||
95 | drvinfo->eedump_len = netxen_nic_get_eeprom_len(dev); | ||
96 | } | ||
97 | |||
98 | static int | ||
99 | netxen_nic_get_settings(struct net_device *dev, struct ethtool_cmd *ecmd) | ||
100 | { | ||
101 | struct netxen_adapter *adapter = netdev_priv(dev); | ||
102 | int check_sfp_module = 0; | ||
103 | |||
104 | /* read which mode */ | ||
105 | if (adapter->ahw.port_type == NETXEN_NIC_GBE) { | ||
106 | ecmd->supported = (SUPPORTED_10baseT_Half | | ||
107 | SUPPORTED_10baseT_Full | | ||
108 | SUPPORTED_100baseT_Half | | ||
109 | SUPPORTED_100baseT_Full | | ||
110 | SUPPORTED_1000baseT_Half | | ||
111 | SUPPORTED_1000baseT_Full); | ||
112 | |||
113 | ecmd->advertising = (ADVERTISED_100baseT_Half | | ||
114 | ADVERTISED_100baseT_Full | | ||
115 | ADVERTISED_1000baseT_Half | | ||
116 | ADVERTISED_1000baseT_Full); | ||
117 | |||
118 | ecmd->port = PORT_TP; | ||
119 | |||
120 | ethtool_cmd_speed_set(ecmd, adapter->link_speed); | ||
121 | ecmd->duplex = adapter->link_duplex; | ||
122 | ecmd->autoneg = adapter->link_autoneg; | ||
123 | |||
124 | } else if (adapter->ahw.port_type == NETXEN_NIC_XGBE) { | ||
125 | u32 val; | ||
126 | |||
127 | val = NXRD32(adapter, NETXEN_PORT_MODE_ADDR); | ||
128 | if (val == NETXEN_PORT_MODE_802_3_AP) { | ||
129 | ecmd->supported = SUPPORTED_1000baseT_Full; | ||
130 | ecmd->advertising = ADVERTISED_1000baseT_Full; | ||
131 | } else { | ||
132 | ecmd->supported = SUPPORTED_10000baseT_Full; | ||
133 | ecmd->advertising = ADVERTISED_10000baseT_Full; | ||
134 | } | ||
135 | |||
136 | if (netif_running(dev) && adapter->has_link_events) { | ||
137 | ethtool_cmd_speed_set(ecmd, adapter->link_speed); | ||
138 | ecmd->autoneg = adapter->link_autoneg; | ||
139 | ecmd->duplex = adapter->link_duplex; | ||
140 | goto skip; | ||
141 | } | ||
142 | |||
143 | ecmd->port = PORT_TP; | ||
144 | |||
145 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) { | ||
146 | u16 pcifn = adapter->ahw.pci_func; | ||
147 | |||
148 | val = NXRD32(adapter, P3_LINK_SPEED_REG(pcifn)); | ||
149 | ethtool_cmd_speed_set(ecmd, P3_LINK_SPEED_MHZ * | ||
150 | P3_LINK_SPEED_VAL(pcifn, val)); | ||
151 | } else | ||
152 | ethtool_cmd_speed_set(ecmd, SPEED_10000); | ||
153 | |||
154 | ecmd->duplex = DUPLEX_FULL; | ||
155 | ecmd->autoneg = AUTONEG_DISABLE; | ||
156 | } else | ||
157 | return -EIO; | ||
158 | |||
159 | skip: | ||
160 | ecmd->phy_address = adapter->physical_port; | ||
161 | ecmd->transceiver = XCVR_EXTERNAL; | ||
162 | |||
163 | switch (adapter->ahw.board_type) { | ||
164 | case NETXEN_BRDTYPE_P2_SB35_4G: | ||
165 | case NETXEN_BRDTYPE_P2_SB31_2G: | ||
166 | case NETXEN_BRDTYPE_P3_REF_QG: | ||
167 | case NETXEN_BRDTYPE_P3_4_GB: | ||
168 | case NETXEN_BRDTYPE_P3_4_GB_MM: | ||
169 | |||
170 | ecmd->supported |= SUPPORTED_Autoneg; | ||
171 | ecmd->advertising |= ADVERTISED_Autoneg; | ||
172 | case NETXEN_BRDTYPE_P2_SB31_10G_CX4: | ||
173 | case NETXEN_BRDTYPE_P3_10G_CX4: | ||
174 | case NETXEN_BRDTYPE_P3_10G_CX4_LP: | ||
175 | case NETXEN_BRDTYPE_P3_10000_BASE_T: | ||
176 | ecmd->supported |= SUPPORTED_TP; | ||
177 | ecmd->advertising |= ADVERTISED_TP; | ||
178 | ecmd->port = PORT_TP; | ||
179 | ecmd->autoneg = (adapter->ahw.board_type == | ||
180 | NETXEN_BRDTYPE_P2_SB31_10G_CX4) ? | ||
181 | (AUTONEG_DISABLE) : (adapter->link_autoneg); | ||
182 | break; | ||
183 | case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ: | ||
184 | case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ: | ||
185 | case NETXEN_BRDTYPE_P3_IMEZ: | ||
186 | case NETXEN_BRDTYPE_P3_XG_LOM: | ||
187 | case NETXEN_BRDTYPE_P3_HMEZ: | ||
188 | ecmd->supported |= SUPPORTED_MII; | ||
189 | ecmd->advertising |= ADVERTISED_MII; | ||
190 | ecmd->port = PORT_MII; | ||
191 | ecmd->autoneg = AUTONEG_DISABLE; | ||
192 | break; | ||
193 | case NETXEN_BRDTYPE_P3_10G_SFP_PLUS: | ||
194 | case NETXEN_BRDTYPE_P3_10G_SFP_CT: | ||
195 | case NETXEN_BRDTYPE_P3_10G_SFP_QT: | ||
196 | ecmd->advertising |= ADVERTISED_TP; | ||
197 | ecmd->supported |= SUPPORTED_TP; | ||
198 | check_sfp_module = netif_running(dev) && | ||
199 | adapter->has_link_events; | ||
200 | case NETXEN_BRDTYPE_P2_SB31_10G: | ||
201 | case NETXEN_BRDTYPE_P3_10G_XFP: | ||
202 | ecmd->supported |= SUPPORTED_FIBRE; | ||
203 | ecmd->advertising |= ADVERTISED_FIBRE; | ||
204 | ecmd->port = PORT_FIBRE; | ||
205 | ecmd->autoneg = AUTONEG_DISABLE; | ||
206 | break; | ||
207 | case NETXEN_BRDTYPE_P3_10G_TP: | ||
208 | if (adapter->ahw.port_type == NETXEN_NIC_XGBE) { | ||
209 | ecmd->autoneg = AUTONEG_DISABLE; | ||
210 | ecmd->supported |= (SUPPORTED_FIBRE | SUPPORTED_TP); | ||
211 | ecmd->advertising |= | ||
212 | (ADVERTISED_FIBRE | ADVERTISED_TP); | ||
213 | ecmd->port = PORT_FIBRE; | ||
214 | check_sfp_module = netif_running(dev) && | ||
215 | adapter->has_link_events; | ||
216 | } else { | ||
217 | ecmd->supported |= (SUPPORTED_TP |SUPPORTED_Autoneg); | ||
218 | ecmd->advertising |= | ||
219 | (ADVERTISED_TP | ADVERTISED_Autoneg); | ||
220 | ecmd->port = PORT_TP; | ||
221 | } | ||
222 | break; | ||
223 | default: | ||
224 | printk(KERN_ERR "netxen-nic: Unsupported board model %d\n", | ||
225 | adapter->ahw.board_type); | ||
226 | return -EIO; | ||
227 | } | ||
228 | |||
229 | if (check_sfp_module) { | ||
230 | switch (adapter->module_type) { | ||
231 | case LINKEVENT_MODULE_OPTICAL_UNKNOWN: | ||
232 | case LINKEVENT_MODULE_OPTICAL_SRLR: | ||
233 | case LINKEVENT_MODULE_OPTICAL_LRM: | ||
234 | case LINKEVENT_MODULE_OPTICAL_SFP_1G: | ||
235 | ecmd->port = PORT_FIBRE; | ||
236 | break; | ||
237 | case LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLE: | ||
238 | case LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLELEN: | ||
239 | case LINKEVENT_MODULE_TWINAX: | ||
240 | ecmd->port = PORT_TP; | ||
241 | break; | ||
242 | default: | ||
243 | ecmd->port = -1; | ||
244 | } | ||
245 | } | ||
246 | |||
247 | return 0; | ||
248 | } | ||
249 | |||
250 | static int | ||
251 | netxen_nic_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd) | ||
252 | { | ||
253 | struct netxen_adapter *adapter = netdev_priv(dev); | ||
254 | u32 speed = ethtool_cmd_speed(ecmd); | ||
255 | int ret; | ||
256 | |||
257 | if (adapter->ahw.port_type != NETXEN_NIC_GBE) | ||
258 | return -EOPNOTSUPP; | ||
259 | |||
260 | if (!(adapter->capabilities & NX_FW_CAPABILITY_GBE_LINK_CFG)) | ||
261 | return -EOPNOTSUPP; | ||
262 | |||
263 | ret = nx_fw_cmd_set_gbe_port(adapter, speed, ecmd->duplex, | ||
264 | ecmd->autoneg); | ||
265 | if (ret == NX_RCODE_NOT_SUPPORTED) | ||
266 | return -EOPNOTSUPP; | ||
267 | else if (ret) | ||
268 | return -EIO; | ||
269 | |||
270 | adapter->link_speed = speed; | ||
271 | adapter->link_duplex = ecmd->duplex; | ||
272 | adapter->link_autoneg = ecmd->autoneg; | ||
273 | |||
274 | if (!netif_running(dev)) | ||
275 | return 0; | ||
276 | |||
277 | dev->netdev_ops->ndo_stop(dev); | ||
278 | return dev->netdev_ops->ndo_open(dev); | ||
279 | } | ||
280 | |||
281 | static int netxen_nic_get_regs_len(struct net_device *dev) | ||
282 | { | ||
283 | return NETXEN_NIC_REGS_LEN; | ||
284 | } | ||
285 | |||
286 | static void | ||
287 | netxen_nic_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *p) | ||
288 | { | ||
289 | struct netxen_adapter *adapter = netdev_priv(dev); | ||
290 | struct netxen_recv_context *recv_ctx = &adapter->recv_ctx; | ||
291 | struct nx_host_sds_ring *sds_ring; | ||
292 | u32 *regs_buff = p; | ||
293 | int ring, i = 0; | ||
294 | int port = adapter->physical_port; | ||
295 | |||
296 | memset(p, 0, NETXEN_NIC_REGS_LEN); | ||
297 | |||
298 | regs->version = (1 << 24) | (adapter->ahw.revision_id << 16) | | ||
299 | (adapter->pdev)->device; | ||
300 | |||
301 | if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC) | ||
302 | return; | ||
303 | |||
304 | regs_buff[i++] = NXRD32(adapter, CRB_CMDPEG_STATE); | ||
305 | regs_buff[i++] = NXRD32(adapter, CRB_RCVPEG_STATE); | ||
306 | regs_buff[i++] = NXRD32(adapter, CRB_FW_CAPABILITIES_1); | ||
307 | regs_buff[i++] = NXRDIO(adapter, adapter->crb_int_state_reg); | ||
308 | regs_buff[i++] = NXRD32(adapter, NX_CRB_DEV_REF_COUNT); | ||
309 | regs_buff[i++] = NXRD32(adapter, NX_CRB_DEV_STATE); | ||
310 | regs_buff[i++] = NXRD32(adapter, NETXEN_PEG_ALIVE_COUNTER); | ||
311 | regs_buff[i++] = NXRD32(adapter, NETXEN_PEG_HALT_STATUS1); | ||
312 | regs_buff[i++] = NXRD32(adapter, NETXEN_PEG_HALT_STATUS2); | ||
313 | |||
314 | regs_buff[i++] = NXRD32(adapter, NETXEN_CRB_PEG_NET_0+0x3c); | ||
315 | regs_buff[i++] = NXRD32(adapter, NETXEN_CRB_PEG_NET_1+0x3c); | ||
316 | regs_buff[i++] = NXRD32(adapter, NETXEN_CRB_PEG_NET_2+0x3c); | ||
317 | regs_buff[i++] = NXRD32(adapter, NETXEN_CRB_PEG_NET_3+0x3c); | ||
318 | |||
319 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) { | ||
320 | |||
321 | regs_buff[i++] = NXRD32(adapter, NETXEN_CRB_PEG_NET_4+0x3c); | ||
322 | i += 2; | ||
323 | |||
324 | regs_buff[i++] = NXRD32(adapter, CRB_XG_STATE_P3); | ||
325 | regs_buff[i++] = le32_to_cpu(*(adapter->tx_ring->hw_consumer)); | ||
326 | |||
327 | } else { | ||
328 | i++; | ||
329 | |||
330 | regs_buff[i++] = NXRD32(adapter, | ||
331 | NETXEN_NIU_XGE_CONFIG_0+(0x10000*port)); | ||
332 | regs_buff[i++] = NXRD32(adapter, | ||
333 | NETXEN_NIU_XGE_CONFIG_1+(0x10000*port)); | ||
334 | |||
335 | regs_buff[i++] = NXRD32(adapter, CRB_XG_STATE); | ||
336 | regs_buff[i++] = NXRDIO(adapter, | ||
337 | adapter->tx_ring->crb_cmd_consumer); | ||
338 | } | ||
339 | |||
340 | regs_buff[i++] = NXRDIO(adapter, adapter->tx_ring->crb_cmd_producer); | ||
341 | |||
342 | regs_buff[i++] = NXRDIO(adapter, | ||
343 | recv_ctx->rds_rings[0].crb_rcv_producer); | ||
344 | regs_buff[i++] = NXRDIO(adapter, | ||
345 | recv_ctx->rds_rings[1].crb_rcv_producer); | ||
346 | |||
347 | regs_buff[i++] = adapter->max_sds_rings; | ||
348 | |||
349 | for (ring = 0; ring < adapter->max_sds_rings; ring++) { | ||
350 | sds_ring = &(recv_ctx->sds_rings[ring]); | ||
351 | regs_buff[i++] = NXRDIO(adapter, | ||
352 | sds_ring->crb_sts_consumer); | ||
353 | } | ||
354 | } | ||
355 | |||
356 | static u32 netxen_nic_test_link(struct net_device *dev) | ||
357 | { | ||
358 | struct netxen_adapter *adapter = netdev_priv(dev); | ||
359 | u32 val, port; | ||
360 | |||
361 | port = adapter->physical_port; | ||
362 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) { | ||
363 | val = NXRD32(adapter, CRB_XG_STATE_P3); | ||
364 | val = XG_LINK_STATE_P3(adapter->ahw.pci_func, val); | ||
365 | return (val == XG_LINK_UP_P3) ? 0 : 1; | ||
366 | } else { | ||
367 | val = NXRD32(adapter, CRB_XG_STATE); | ||
368 | val = (val >> port*8) & 0xff; | ||
369 | return (val == XG_LINK_UP) ? 0 : 1; | ||
370 | } | ||
371 | } | ||
372 | |||
373 | static int | ||
374 | netxen_nic_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, | ||
375 | u8 * bytes) | ||
376 | { | ||
377 | struct netxen_adapter *adapter = netdev_priv(dev); | ||
378 | int offset; | ||
379 | int ret; | ||
380 | |||
381 | if (eeprom->len == 0) | ||
382 | return -EINVAL; | ||
383 | |||
384 | eeprom->magic = (adapter->pdev)->vendor | | ||
385 | ((adapter->pdev)->device << 16); | ||
386 | offset = eeprom->offset; | ||
387 | |||
388 | ret = netxen_rom_fast_read_words(adapter, offset, bytes, | ||
389 | eeprom->len); | ||
390 | if (ret < 0) | ||
391 | return ret; | ||
392 | |||
393 | return 0; | ||
394 | } | ||
395 | |||
396 | static void | ||
397 | netxen_nic_get_ringparam(struct net_device *dev, | ||
398 | struct ethtool_ringparam *ring) | ||
399 | { | ||
400 | struct netxen_adapter *adapter = netdev_priv(dev); | ||
401 | |||
402 | ring->rx_pending = adapter->num_rxd; | ||
403 | ring->rx_jumbo_pending = adapter->num_jumbo_rxd; | ||
404 | ring->rx_jumbo_pending += adapter->num_lro_rxd; | ||
405 | ring->tx_pending = adapter->num_txd; | ||
406 | |||
407 | if (adapter->ahw.port_type == NETXEN_NIC_GBE) { | ||
408 | ring->rx_max_pending = MAX_RCV_DESCRIPTORS_1G; | ||
409 | ring->rx_jumbo_max_pending = MAX_JUMBO_RCV_DESCRIPTORS_1G; | ||
410 | } else { | ||
411 | ring->rx_max_pending = MAX_RCV_DESCRIPTORS_10G; | ||
412 | ring->rx_jumbo_max_pending = MAX_JUMBO_RCV_DESCRIPTORS_10G; | ||
413 | } | ||
414 | |||
415 | ring->tx_max_pending = MAX_CMD_DESCRIPTORS; | ||
416 | |||
417 | ring->rx_mini_max_pending = 0; | ||
418 | ring->rx_mini_pending = 0; | ||
419 | } | ||
420 | |||
421 | static u32 | ||
422 | netxen_validate_ringparam(u32 val, u32 min, u32 max, char *r_name) | ||
423 | { | ||
424 | u32 num_desc; | ||
425 | num_desc = max(val, min); | ||
426 | num_desc = min(num_desc, max); | ||
427 | num_desc = roundup_pow_of_two(num_desc); | ||
428 | |||
429 | if (val != num_desc) { | ||
430 | printk(KERN_INFO "%s: setting %s ring size %d instead of %d\n", | ||
431 | netxen_nic_driver_name, r_name, num_desc, val); | ||
432 | } | ||
433 | |||
434 | return num_desc; | ||
435 | } | ||
436 | |||
437 | static int | ||
438 | netxen_nic_set_ringparam(struct net_device *dev, | ||
439 | struct ethtool_ringparam *ring) | ||
440 | { | ||
441 | struct netxen_adapter *adapter = netdev_priv(dev); | ||
442 | u16 max_rcv_desc = MAX_RCV_DESCRIPTORS_10G; | ||
443 | u16 max_jumbo_desc = MAX_JUMBO_RCV_DESCRIPTORS_10G; | ||
444 | u16 num_rxd, num_jumbo_rxd, num_txd; | ||
445 | |||
446 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) | ||
447 | return -EOPNOTSUPP; | ||
448 | |||
449 | if (ring->rx_mini_pending) | ||
450 | return -EOPNOTSUPP; | ||
451 | |||
452 | if (adapter->ahw.port_type == NETXEN_NIC_GBE) { | ||
453 | max_rcv_desc = MAX_RCV_DESCRIPTORS_1G; | ||
454 | max_jumbo_desc = MAX_JUMBO_RCV_DESCRIPTORS_10G; | ||
455 | } | ||
456 | |||
457 | num_rxd = netxen_validate_ringparam(ring->rx_pending, | ||
458 | MIN_RCV_DESCRIPTORS, max_rcv_desc, "rx"); | ||
459 | |||
460 | num_jumbo_rxd = netxen_validate_ringparam(ring->rx_jumbo_pending, | ||
461 | MIN_JUMBO_DESCRIPTORS, max_jumbo_desc, "rx jumbo"); | ||
462 | |||
463 | num_txd = netxen_validate_ringparam(ring->tx_pending, | ||
464 | MIN_CMD_DESCRIPTORS, MAX_CMD_DESCRIPTORS, "tx"); | ||
465 | |||
466 | if (num_rxd == adapter->num_rxd && num_txd == adapter->num_txd && | ||
467 | num_jumbo_rxd == adapter->num_jumbo_rxd) | ||
468 | return 0; | ||
469 | |||
470 | adapter->num_rxd = num_rxd; | ||
471 | adapter->num_jumbo_rxd = num_jumbo_rxd; | ||
472 | adapter->num_txd = num_txd; | ||
473 | |||
474 | return netxen_nic_reset_context(adapter); | ||
475 | } | ||
476 | |||
477 | static void | ||
478 | netxen_nic_get_pauseparam(struct net_device *dev, | ||
479 | struct ethtool_pauseparam *pause) | ||
480 | { | ||
481 | struct netxen_adapter *adapter = netdev_priv(dev); | ||
482 | __u32 val; | ||
483 | int port = adapter->physical_port; | ||
484 | |||
485 | if (adapter->ahw.port_type == NETXEN_NIC_GBE) { | ||
486 | if ((port < 0) || (port > NETXEN_NIU_MAX_GBE_PORTS)) | ||
487 | return; | ||
488 | /* get flow control settings */ | ||
489 | val = NXRD32(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(port)); | ||
490 | pause->rx_pause = netxen_gb_get_rx_flowctl(val); | ||
491 | val = NXRD32(adapter, NETXEN_NIU_GB_PAUSE_CTL); | ||
492 | switch (port) { | ||
493 | case 0: | ||
494 | pause->tx_pause = !(netxen_gb_get_gb0_mask(val)); | ||
495 | break; | ||
496 | case 1: | ||
497 | pause->tx_pause = !(netxen_gb_get_gb1_mask(val)); | ||
498 | break; | ||
499 | case 2: | ||
500 | pause->tx_pause = !(netxen_gb_get_gb2_mask(val)); | ||
501 | break; | ||
502 | case 3: | ||
503 | default: | ||
504 | pause->tx_pause = !(netxen_gb_get_gb3_mask(val)); | ||
505 | break; | ||
506 | } | ||
507 | } else if (adapter->ahw.port_type == NETXEN_NIC_XGBE) { | ||
508 | if ((port < 0) || (port > NETXEN_NIU_MAX_XG_PORTS)) | ||
509 | return; | ||
510 | pause->rx_pause = 1; | ||
511 | val = NXRD32(adapter, NETXEN_NIU_XG_PAUSE_CTL); | ||
512 | if (port == 0) | ||
513 | pause->tx_pause = !(netxen_xg_get_xg0_mask(val)); | ||
514 | else | ||
515 | pause->tx_pause = !(netxen_xg_get_xg1_mask(val)); | ||
516 | } else { | ||
517 | printk(KERN_ERR"%s: Unknown board type: %x\n", | ||
518 | netxen_nic_driver_name, adapter->ahw.port_type); | ||
519 | } | ||
520 | } | ||
521 | |||
522 | static int | ||
523 | netxen_nic_set_pauseparam(struct net_device *dev, | ||
524 | struct ethtool_pauseparam *pause) | ||
525 | { | ||
526 | struct netxen_adapter *adapter = netdev_priv(dev); | ||
527 | __u32 val; | ||
528 | int port = adapter->physical_port; | ||
529 | /* read mode */ | ||
530 | if (adapter->ahw.port_type == NETXEN_NIC_GBE) { | ||
531 | if ((port < 0) || (port > NETXEN_NIU_MAX_GBE_PORTS)) | ||
532 | return -EIO; | ||
533 | /* set flow control */ | ||
534 | val = NXRD32(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(port)); | ||
535 | |||
536 | if (pause->rx_pause) | ||
537 | netxen_gb_rx_flowctl(val); | ||
538 | else | ||
539 | netxen_gb_unset_rx_flowctl(val); | ||
540 | |||
541 | NXWR32(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(port), | ||
542 | val); | ||
543 | /* set autoneg */ | ||
544 | val = NXRD32(adapter, NETXEN_NIU_GB_PAUSE_CTL); | ||
545 | switch (port) { | ||
546 | case 0: | ||
547 | if (pause->tx_pause) | ||
548 | netxen_gb_unset_gb0_mask(val); | ||
549 | else | ||
550 | netxen_gb_set_gb0_mask(val); | ||
551 | break; | ||
552 | case 1: | ||
553 | if (pause->tx_pause) | ||
554 | netxen_gb_unset_gb1_mask(val); | ||
555 | else | ||
556 | netxen_gb_set_gb1_mask(val); | ||
557 | break; | ||
558 | case 2: | ||
559 | if (pause->tx_pause) | ||
560 | netxen_gb_unset_gb2_mask(val); | ||
561 | else | ||
562 | netxen_gb_set_gb2_mask(val); | ||
563 | break; | ||
564 | case 3: | ||
565 | default: | ||
566 | if (pause->tx_pause) | ||
567 | netxen_gb_unset_gb3_mask(val); | ||
568 | else | ||
569 | netxen_gb_set_gb3_mask(val); | ||
570 | break; | ||
571 | } | ||
572 | NXWR32(adapter, NETXEN_NIU_GB_PAUSE_CTL, val); | ||
573 | } else if (adapter->ahw.port_type == NETXEN_NIC_XGBE) { | ||
574 | if ((port < 0) || (port > NETXEN_NIU_MAX_XG_PORTS)) | ||
575 | return -EIO; | ||
576 | val = NXRD32(adapter, NETXEN_NIU_XG_PAUSE_CTL); | ||
577 | if (port == 0) { | ||
578 | if (pause->tx_pause) | ||
579 | netxen_xg_unset_xg0_mask(val); | ||
580 | else | ||
581 | netxen_xg_set_xg0_mask(val); | ||
582 | } else { | ||
583 | if (pause->tx_pause) | ||
584 | netxen_xg_unset_xg1_mask(val); | ||
585 | else | ||
586 | netxen_xg_set_xg1_mask(val); | ||
587 | } | ||
588 | NXWR32(adapter, NETXEN_NIU_XG_PAUSE_CTL, val); | ||
589 | } else { | ||
590 | printk(KERN_ERR "%s: Unknown board type: %x\n", | ||
591 | netxen_nic_driver_name, | ||
592 | adapter->ahw.port_type); | ||
593 | } | ||
594 | return 0; | ||
595 | } | ||
596 | |||
597 | static int netxen_nic_reg_test(struct net_device *dev) | ||
598 | { | ||
599 | struct netxen_adapter *adapter = netdev_priv(dev); | ||
600 | u32 data_read, data_written; | ||
601 | |||
602 | data_read = NXRD32(adapter, NETXEN_PCIX_PH_REG(0)); | ||
603 | if ((data_read & 0xffff) != adapter->pdev->vendor) | ||
604 | return 1; | ||
605 | |||
606 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) | ||
607 | return 0; | ||
608 | |||
609 | data_written = (u32)0xa5a5a5a5; | ||
610 | |||
611 | NXWR32(adapter, CRB_SCRATCHPAD_TEST, data_written); | ||
612 | data_read = NXRD32(adapter, CRB_SCRATCHPAD_TEST); | ||
613 | if (data_written != data_read) | ||
614 | return 1; | ||
615 | |||
616 | return 0; | ||
617 | } | ||
618 | |||
619 | static int netxen_get_sset_count(struct net_device *dev, int sset) | ||
620 | { | ||
621 | switch (sset) { | ||
622 | case ETH_SS_TEST: | ||
623 | return NETXEN_NIC_TEST_LEN; | ||
624 | case ETH_SS_STATS: | ||
625 | return NETXEN_NIC_STATS_LEN; | ||
626 | default: | ||
627 | return -EOPNOTSUPP; | ||
628 | } | ||
629 | } | ||
630 | |||
631 | static void | ||
632 | netxen_nic_diag_test(struct net_device *dev, struct ethtool_test *eth_test, | ||
633 | u64 * data) | ||
634 | { | ||
635 | memset(data, 0, sizeof(uint64_t) * NETXEN_NIC_TEST_LEN); | ||
636 | if ((data[0] = netxen_nic_reg_test(dev))) | ||
637 | eth_test->flags |= ETH_TEST_FL_FAILED; | ||
638 | /* link test */ | ||
639 | if ((data[1] = (u64) netxen_nic_test_link(dev))) | ||
640 | eth_test->flags |= ETH_TEST_FL_FAILED; | ||
641 | } | ||
642 | |||
643 | static void | ||
644 | netxen_nic_get_strings(struct net_device *dev, u32 stringset, u8 * data) | ||
645 | { | ||
646 | int index; | ||
647 | |||
648 | switch (stringset) { | ||
649 | case ETH_SS_TEST: | ||
650 | memcpy(data, *netxen_nic_gstrings_test, | ||
651 | NETXEN_NIC_TEST_LEN * ETH_GSTRING_LEN); | ||
652 | break; | ||
653 | case ETH_SS_STATS: | ||
654 | for (index = 0; index < NETXEN_NIC_STATS_LEN; index++) { | ||
655 | memcpy(data + index * ETH_GSTRING_LEN, | ||
656 | netxen_nic_gstrings_stats[index].stat_string, | ||
657 | ETH_GSTRING_LEN); | ||
658 | } | ||
659 | break; | ||
660 | } | ||
661 | } | ||
662 | |||
663 | static void | ||
664 | netxen_nic_get_ethtool_stats(struct net_device *dev, | ||
665 | struct ethtool_stats *stats, u64 * data) | ||
666 | { | ||
667 | struct netxen_adapter *adapter = netdev_priv(dev); | ||
668 | int index; | ||
669 | |||
670 | for (index = 0; index < NETXEN_NIC_STATS_LEN; index++) { | ||
671 | char *p = | ||
672 | (char *)adapter + | ||
673 | netxen_nic_gstrings_stats[index].stat_offset; | ||
674 | data[index] = | ||
675 | (netxen_nic_gstrings_stats[index].sizeof_stat == | ||
676 | sizeof(u64)) ? *(u64 *) p : *(u32 *) p; | ||
677 | } | ||
678 | } | ||
679 | |||
680 | static void | ||
681 | netxen_nic_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) | ||
682 | { | ||
683 | struct netxen_adapter *adapter = netdev_priv(dev); | ||
684 | u32 wol_cfg = 0; | ||
685 | |||
686 | wol->supported = 0; | ||
687 | wol->wolopts = 0; | ||
688 | |||
689 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) | ||
690 | return; | ||
691 | |||
692 | wol_cfg = NXRD32(adapter, NETXEN_WOL_CONFIG_NV); | ||
693 | if (wol_cfg & (1UL << adapter->portnum)) | ||
694 | wol->supported |= WAKE_MAGIC; | ||
695 | |||
696 | wol_cfg = NXRD32(adapter, NETXEN_WOL_CONFIG); | ||
697 | if (wol_cfg & (1UL << adapter->portnum)) | ||
698 | wol->wolopts |= WAKE_MAGIC; | ||
699 | } | ||
700 | |||
701 | static int | ||
702 | netxen_nic_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol) | ||
703 | { | ||
704 | struct netxen_adapter *adapter = netdev_priv(dev); | ||
705 | u32 wol_cfg = 0; | ||
706 | |||
707 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) | ||
708 | return -EOPNOTSUPP; | ||
709 | |||
710 | if (wol->wolopts & ~WAKE_MAGIC) | ||
711 | return -EOPNOTSUPP; | ||
712 | |||
713 | wol_cfg = NXRD32(adapter, NETXEN_WOL_CONFIG_NV); | ||
714 | if (!(wol_cfg & (1 << adapter->portnum))) | ||
715 | return -EOPNOTSUPP; | ||
716 | |||
717 | wol_cfg = NXRD32(adapter, NETXEN_WOL_CONFIG); | ||
718 | if (wol->wolopts & WAKE_MAGIC) | ||
719 | wol_cfg |= 1UL << adapter->portnum; | ||
720 | else | ||
721 | wol_cfg &= ~(1UL << adapter->portnum); | ||
722 | NXWR32(adapter, NETXEN_WOL_CONFIG, wol_cfg); | ||
723 | |||
724 | return 0; | ||
725 | } | ||
726 | |||
727 | /* | ||
728 | * Set the coalescing parameters. Currently only normal is supported. | ||
729 | * If rx_coalesce_usecs == 0 or rx_max_coalesced_frames == 0 then set the | ||
730 | * firmware coalescing to default. | ||
731 | */ | ||
732 | static int netxen_set_intr_coalesce(struct net_device *netdev, | ||
733 | struct ethtool_coalesce *ethcoal) | ||
734 | { | ||
735 | struct netxen_adapter *adapter = netdev_priv(netdev); | ||
736 | |||
737 | if (!NX_IS_REVISION_P3(adapter->ahw.revision_id)) | ||
738 | return -EINVAL; | ||
739 | |||
740 | if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC) | ||
741 | return -EINVAL; | ||
742 | |||
743 | /* | ||
744 | * Return Error if unsupported values or | ||
745 | * unsupported parameters are set. | ||
746 | */ | ||
747 | if (ethcoal->rx_coalesce_usecs > 0xffff || | ||
748 | ethcoal->rx_max_coalesced_frames > 0xffff || | ||
749 | ethcoal->tx_coalesce_usecs > 0xffff || | ||
750 | ethcoal->tx_max_coalesced_frames > 0xffff || | ||
751 | ethcoal->rx_coalesce_usecs_irq || | ||
752 | ethcoal->rx_max_coalesced_frames_irq || | ||
753 | ethcoal->tx_coalesce_usecs_irq || | ||
754 | ethcoal->tx_max_coalesced_frames_irq || | ||
755 | ethcoal->stats_block_coalesce_usecs || | ||
756 | ethcoal->use_adaptive_rx_coalesce || | ||
757 | ethcoal->use_adaptive_tx_coalesce || | ||
758 | ethcoal->pkt_rate_low || | ||
759 | ethcoal->rx_coalesce_usecs_low || | ||
760 | ethcoal->rx_max_coalesced_frames_low || | ||
761 | ethcoal->tx_coalesce_usecs_low || | ||
762 | ethcoal->tx_max_coalesced_frames_low || | ||
763 | ethcoal->pkt_rate_high || | ||
764 | ethcoal->rx_coalesce_usecs_high || | ||
765 | ethcoal->rx_max_coalesced_frames_high || | ||
766 | ethcoal->tx_coalesce_usecs_high || | ||
767 | ethcoal->tx_max_coalesced_frames_high) | ||
768 | return -EINVAL; | ||
769 | |||
770 | if (!ethcoal->rx_coalesce_usecs || | ||
771 | !ethcoal->rx_max_coalesced_frames) { | ||
772 | adapter->coal.flags = NETXEN_NIC_INTR_DEFAULT; | ||
773 | adapter->coal.normal.data.rx_time_us = | ||
774 | NETXEN_DEFAULT_INTR_COALESCE_RX_TIME_US; | ||
775 | adapter->coal.normal.data.rx_packets = | ||
776 | NETXEN_DEFAULT_INTR_COALESCE_RX_PACKETS; | ||
777 | } else { | ||
778 | adapter->coal.flags = 0; | ||
779 | adapter->coal.normal.data.rx_time_us = | ||
780 | ethcoal->rx_coalesce_usecs; | ||
781 | adapter->coal.normal.data.rx_packets = | ||
782 | ethcoal->rx_max_coalesced_frames; | ||
783 | } | ||
784 | adapter->coal.normal.data.tx_time_us = ethcoal->tx_coalesce_usecs; | ||
785 | adapter->coal.normal.data.tx_packets = | ||
786 | ethcoal->tx_max_coalesced_frames; | ||
787 | |||
788 | netxen_config_intr_coalesce(adapter); | ||
789 | |||
790 | return 0; | ||
791 | } | ||
792 | |||
793 | static int netxen_get_intr_coalesce(struct net_device *netdev, | ||
794 | struct ethtool_coalesce *ethcoal) | ||
795 | { | ||
796 | struct netxen_adapter *adapter = netdev_priv(netdev); | ||
797 | |||
798 | if (!NX_IS_REVISION_P3(adapter->ahw.revision_id)) | ||
799 | return -EINVAL; | ||
800 | |||
801 | if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC) | ||
802 | return -EINVAL; | ||
803 | |||
804 | ethcoal->rx_coalesce_usecs = adapter->coal.normal.data.rx_time_us; | ||
805 | ethcoal->tx_coalesce_usecs = adapter->coal.normal.data.tx_time_us; | ||
806 | ethcoal->rx_max_coalesced_frames = | ||
807 | adapter->coal.normal.data.rx_packets; | ||
808 | ethcoal->tx_max_coalesced_frames = | ||
809 | adapter->coal.normal.data.tx_packets; | ||
810 | |||
811 | return 0; | ||
812 | } | ||
813 | |||
814 | const struct ethtool_ops netxen_nic_ethtool_ops = { | ||
815 | .get_settings = netxen_nic_get_settings, | ||
816 | .set_settings = netxen_nic_set_settings, | ||
817 | .get_drvinfo = netxen_nic_get_drvinfo, | ||
818 | .get_regs_len = netxen_nic_get_regs_len, | ||
819 | .get_regs = netxen_nic_get_regs, | ||
820 | .get_link = ethtool_op_get_link, | ||
821 | .get_eeprom_len = netxen_nic_get_eeprom_len, | ||
822 | .get_eeprom = netxen_nic_get_eeprom, | ||
823 | .get_ringparam = netxen_nic_get_ringparam, | ||
824 | .set_ringparam = netxen_nic_set_ringparam, | ||
825 | .get_pauseparam = netxen_nic_get_pauseparam, | ||
826 | .set_pauseparam = netxen_nic_set_pauseparam, | ||
827 | .get_wol = netxen_nic_get_wol, | ||
828 | .set_wol = netxen_nic_set_wol, | ||
829 | .self_test = netxen_nic_diag_test, | ||
830 | .get_strings = netxen_nic_get_strings, | ||
831 | .get_ethtool_stats = netxen_nic_get_ethtool_stats, | ||
832 | .get_sset_count = netxen_get_sset_count, | ||
833 | .get_coalesce = netxen_get_intr_coalesce, | ||
834 | .set_coalesce = netxen_set_intr_coalesce, | ||
835 | }; | ||
diff --git a/drivers/net/ethernet/qlogic/netxen/netxen_nic_hdr.h b/drivers/net/ethernet/qlogic/netxen/netxen_nic_hdr.h new file mode 100644 index 000000000000..dc1967c1f312 --- /dev/null +++ b/drivers/net/ethernet/qlogic/netxen/netxen_nic_hdr.h | |||
@@ -0,0 +1,1050 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2003 - 2009 NetXen, Inc. | ||
3 | * Copyright (C) 2009 - QLogic Corporation. | ||
4 | * All rights reserved. | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or | ||
7 | * modify it under the terms of the GNU General Public License | ||
8 | * as published by the Free Software Foundation; either version 2 | ||
9 | * of the License, or (at your option) any later version. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, but | ||
12 | * 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, | ||
19 | * MA 02111-1307, USA. | ||
20 | * | ||
21 | * The full GNU General Public License is included in this distribution | ||
22 | * in the file called "COPYING". | ||
23 | * | ||
24 | */ | ||
25 | |||
26 | #ifndef __NETXEN_NIC_HDR_H_ | ||
27 | #define __NETXEN_NIC_HDR_H_ | ||
28 | |||
29 | #include <linux/kernel.h> | ||
30 | #include <linux/types.h> | ||
31 | |||
32 | /* | ||
33 | * The basic unit of access when reading/writing control registers. | ||
34 | */ | ||
35 | |||
36 | typedef __le32 netxen_crbword_t; /* single word in CRB space */ | ||
37 | |||
38 | enum { | ||
39 | NETXEN_HW_H0_CH_HUB_ADR = 0x05, | ||
40 | NETXEN_HW_H1_CH_HUB_ADR = 0x0E, | ||
41 | NETXEN_HW_H2_CH_HUB_ADR = 0x03, | ||
42 | NETXEN_HW_H3_CH_HUB_ADR = 0x01, | ||
43 | NETXEN_HW_H4_CH_HUB_ADR = 0x06, | ||
44 | NETXEN_HW_H5_CH_HUB_ADR = 0x07, | ||
45 | NETXEN_HW_H6_CH_HUB_ADR = 0x08 | ||
46 | }; | ||
47 | |||
48 | /* Hub 0 */ | ||
49 | enum { | ||
50 | NETXEN_HW_MN_CRB_AGT_ADR = 0x15, | ||
51 | NETXEN_HW_MS_CRB_AGT_ADR = 0x25 | ||
52 | }; | ||
53 | |||
54 | /* Hub 1 */ | ||
55 | enum { | ||
56 | NETXEN_HW_PS_CRB_AGT_ADR = 0x73, | ||
57 | NETXEN_HW_SS_CRB_AGT_ADR = 0x20, | ||
58 | NETXEN_HW_RPMX3_CRB_AGT_ADR = 0x0b, | ||
59 | NETXEN_HW_QMS_CRB_AGT_ADR = 0x00, | ||
60 | NETXEN_HW_SQGS0_CRB_AGT_ADR = 0x01, | ||
61 | NETXEN_HW_SQGS1_CRB_AGT_ADR = 0x02, | ||
62 | NETXEN_HW_SQGS2_CRB_AGT_ADR = 0x03, | ||
63 | NETXEN_HW_SQGS3_CRB_AGT_ADR = 0x04, | ||
64 | NETXEN_HW_C2C0_CRB_AGT_ADR = 0x58, | ||
65 | NETXEN_HW_C2C1_CRB_AGT_ADR = 0x59, | ||
66 | NETXEN_HW_C2C2_CRB_AGT_ADR = 0x5a, | ||
67 | NETXEN_HW_RPMX2_CRB_AGT_ADR = 0x0a, | ||
68 | NETXEN_HW_RPMX4_CRB_AGT_ADR = 0x0c, | ||
69 | NETXEN_HW_RPMX7_CRB_AGT_ADR = 0x0f, | ||
70 | NETXEN_HW_RPMX9_CRB_AGT_ADR = 0x12, | ||
71 | NETXEN_HW_SMB_CRB_AGT_ADR = 0x18 | ||
72 | }; | ||
73 | |||
74 | /* Hub 2 */ | ||
75 | enum { | ||
76 | NETXEN_HW_NIU_CRB_AGT_ADR = 0x31, | ||
77 | NETXEN_HW_I2C0_CRB_AGT_ADR = 0x19, | ||
78 | NETXEN_HW_I2C1_CRB_AGT_ADR = 0x29, | ||
79 | |||
80 | NETXEN_HW_SN_CRB_AGT_ADR = 0x10, | ||
81 | NETXEN_HW_I2Q_CRB_AGT_ADR = 0x20, | ||
82 | NETXEN_HW_LPC_CRB_AGT_ADR = 0x22, | ||
83 | NETXEN_HW_ROMUSB_CRB_AGT_ADR = 0x21, | ||
84 | NETXEN_HW_QM_CRB_AGT_ADR = 0x66, | ||
85 | NETXEN_HW_SQG0_CRB_AGT_ADR = 0x60, | ||
86 | NETXEN_HW_SQG1_CRB_AGT_ADR = 0x61, | ||
87 | NETXEN_HW_SQG2_CRB_AGT_ADR = 0x62, | ||
88 | NETXEN_HW_SQG3_CRB_AGT_ADR = 0x63, | ||
89 | NETXEN_HW_RPMX1_CRB_AGT_ADR = 0x09, | ||
90 | NETXEN_HW_RPMX5_CRB_AGT_ADR = 0x0d, | ||
91 | NETXEN_HW_RPMX6_CRB_AGT_ADR = 0x0e, | ||
92 | NETXEN_HW_RPMX8_CRB_AGT_ADR = 0x11 | ||
93 | }; | ||
94 | |||
95 | /* Hub 3 */ | ||
96 | enum { | ||
97 | NETXEN_HW_PH_CRB_AGT_ADR = 0x1A, | ||
98 | NETXEN_HW_SRE_CRB_AGT_ADR = 0x50, | ||
99 | NETXEN_HW_EG_CRB_AGT_ADR = 0x51, | ||
100 | NETXEN_HW_RPMX0_CRB_AGT_ADR = 0x08 | ||
101 | }; | ||
102 | |||
103 | /* Hub 4 */ | ||
104 | enum { | ||
105 | NETXEN_HW_PEGN0_CRB_AGT_ADR = 0x40, | ||
106 | NETXEN_HW_PEGN1_CRB_AGT_ADR, | ||
107 | NETXEN_HW_PEGN2_CRB_AGT_ADR, | ||
108 | NETXEN_HW_PEGN3_CRB_AGT_ADR, | ||
109 | NETXEN_HW_PEGNI_CRB_AGT_ADR, | ||
110 | NETXEN_HW_PEGND_CRB_AGT_ADR, | ||
111 | NETXEN_HW_PEGNC_CRB_AGT_ADR, | ||
112 | NETXEN_HW_PEGR0_CRB_AGT_ADR, | ||
113 | NETXEN_HW_PEGR1_CRB_AGT_ADR, | ||
114 | NETXEN_HW_PEGR2_CRB_AGT_ADR, | ||
115 | NETXEN_HW_PEGR3_CRB_AGT_ADR, | ||
116 | NETXEN_HW_PEGN4_CRB_AGT_ADR | ||
117 | }; | ||
118 | |||
119 | /* Hub 5 */ | ||
120 | enum { | ||
121 | NETXEN_HW_PEGS0_CRB_AGT_ADR = 0x40, | ||
122 | NETXEN_HW_PEGS1_CRB_AGT_ADR, | ||
123 | NETXEN_HW_PEGS2_CRB_AGT_ADR, | ||
124 | NETXEN_HW_PEGS3_CRB_AGT_ADR, | ||
125 | NETXEN_HW_PEGSI_CRB_AGT_ADR, | ||
126 | NETXEN_HW_PEGSD_CRB_AGT_ADR, | ||
127 | NETXEN_HW_PEGSC_CRB_AGT_ADR | ||
128 | }; | ||
129 | |||
130 | /* Hub 6 */ | ||
131 | enum { | ||
132 | NETXEN_HW_CAS0_CRB_AGT_ADR = 0x46, | ||
133 | NETXEN_HW_CAS1_CRB_AGT_ADR = 0x47, | ||
134 | NETXEN_HW_CAS2_CRB_AGT_ADR = 0x48, | ||
135 | NETXEN_HW_CAS3_CRB_AGT_ADR = 0x49, | ||
136 | NETXEN_HW_NCM_CRB_AGT_ADR = 0x16, | ||
137 | NETXEN_HW_TMR_CRB_AGT_ADR = 0x17, | ||
138 | NETXEN_HW_XDMA_CRB_AGT_ADR = 0x05, | ||
139 | NETXEN_HW_OCM0_CRB_AGT_ADR = 0x06, | ||
140 | NETXEN_HW_OCM1_CRB_AGT_ADR = 0x07 | ||
141 | }; | ||
142 | |||
143 | /* Floaters - non existent modules */ | ||
144 | #define NETXEN_HW_EFC_RPMX0_CRB_AGT_ADR 0x67 | ||
145 | |||
146 | /* This field defines PCI/X adr [25:20] of agents on the CRB */ | ||
147 | enum { | ||
148 | NETXEN_HW_PX_MAP_CRB_PH = 0, | ||
149 | NETXEN_HW_PX_MAP_CRB_PS, | ||
150 | NETXEN_HW_PX_MAP_CRB_MN, | ||
151 | NETXEN_HW_PX_MAP_CRB_MS, | ||
152 | NETXEN_HW_PX_MAP_CRB_PGR1, | ||
153 | NETXEN_HW_PX_MAP_CRB_SRE, | ||
154 | NETXEN_HW_PX_MAP_CRB_NIU, | ||
155 | NETXEN_HW_PX_MAP_CRB_QMN, | ||
156 | NETXEN_HW_PX_MAP_CRB_SQN0, | ||
157 | NETXEN_HW_PX_MAP_CRB_SQN1, | ||
158 | NETXEN_HW_PX_MAP_CRB_SQN2, | ||
159 | NETXEN_HW_PX_MAP_CRB_SQN3, | ||
160 | NETXEN_HW_PX_MAP_CRB_QMS, | ||
161 | NETXEN_HW_PX_MAP_CRB_SQS0, | ||
162 | NETXEN_HW_PX_MAP_CRB_SQS1, | ||
163 | NETXEN_HW_PX_MAP_CRB_SQS2, | ||
164 | NETXEN_HW_PX_MAP_CRB_SQS3, | ||
165 | NETXEN_HW_PX_MAP_CRB_PGN0, | ||
166 | NETXEN_HW_PX_MAP_CRB_PGN1, | ||
167 | NETXEN_HW_PX_MAP_CRB_PGN2, | ||
168 | NETXEN_HW_PX_MAP_CRB_PGN3, | ||
169 | NETXEN_HW_PX_MAP_CRB_PGND, | ||
170 | NETXEN_HW_PX_MAP_CRB_PGNI, | ||
171 | NETXEN_HW_PX_MAP_CRB_PGS0, | ||
172 | NETXEN_HW_PX_MAP_CRB_PGS1, | ||
173 | NETXEN_HW_PX_MAP_CRB_PGS2, | ||
174 | NETXEN_HW_PX_MAP_CRB_PGS3, | ||
175 | NETXEN_HW_PX_MAP_CRB_PGSD, | ||
176 | NETXEN_HW_PX_MAP_CRB_PGSI, | ||
177 | NETXEN_HW_PX_MAP_CRB_SN, | ||
178 | NETXEN_HW_PX_MAP_CRB_PGR2, | ||
179 | NETXEN_HW_PX_MAP_CRB_EG, | ||
180 | NETXEN_HW_PX_MAP_CRB_PH2, | ||
181 | NETXEN_HW_PX_MAP_CRB_PS2, | ||
182 | NETXEN_HW_PX_MAP_CRB_CAM, | ||
183 | NETXEN_HW_PX_MAP_CRB_CAS0, | ||
184 | NETXEN_HW_PX_MAP_CRB_CAS1, | ||
185 | NETXEN_HW_PX_MAP_CRB_CAS2, | ||
186 | NETXEN_HW_PX_MAP_CRB_C2C0, | ||
187 | NETXEN_HW_PX_MAP_CRB_C2C1, | ||
188 | NETXEN_HW_PX_MAP_CRB_TIMR, | ||
189 | NETXEN_HW_PX_MAP_CRB_PGR3, | ||
190 | NETXEN_HW_PX_MAP_CRB_RPMX1, | ||
191 | NETXEN_HW_PX_MAP_CRB_RPMX2, | ||
192 | NETXEN_HW_PX_MAP_CRB_RPMX3, | ||
193 | NETXEN_HW_PX_MAP_CRB_RPMX4, | ||
194 | NETXEN_HW_PX_MAP_CRB_RPMX5, | ||
195 | NETXEN_HW_PX_MAP_CRB_RPMX6, | ||
196 | NETXEN_HW_PX_MAP_CRB_RPMX7, | ||
197 | NETXEN_HW_PX_MAP_CRB_XDMA, | ||
198 | NETXEN_HW_PX_MAP_CRB_I2Q, | ||
199 | NETXEN_HW_PX_MAP_CRB_ROMUSB, | ||
200 | NETXEN_HW_PX_MAP_CRB_CAS3, | ||
201 | NETXEN_HW_PX_MAP_CRB_RPMX0, | ||
202 | NETXEN_HW_PX_MAP_CRB_RPMX8, | ||
203 | NETXEN_HW_PX_MAP_CRB_RPMX9, | ||
204 | NETXEN_HW_PX_MAP_CRB_OCM0, | ||
205 | NETXEN_HW_PX_MAP_CRB_OCM1, | ||
206 | NETXEN_HW_PX_MAP_CRB_SMB, | ||
207 | NETXEN_HW_PX_MAP_CRB_I2C0, | ||
208 | NETXEN_HW_PX_MAP_CRB_I2C1, | ||
209 | NETXEN_HW_PX_MAP_CRB_LPC, | ||
210 | NETXEN_HW_PX_MAP_CRB_PGNC, | ||
211 | NETXEN_HW_PX_MAP_CRB_PGR0 | ||
212 | }; | ||
213 | |||
214 | /* This field defines CRB adr [31:20] of the agents */ | ||
215 | |||
216 | #define NETXEN_HW_CRB_HUB_AGT_ADR_MN \ | ||
217 | ((NETXEN_HW_H0_CH_HUB_ADR << 7) | NETXEN_HW_MN_CRB_AGT_ADR) | ||
218 | #define NETXEN_HW_CRB_HUB_AGT_ADR_PH \ | ||
219 | ((NETXEN_HW_H0_CH_HUB_ADR << 7) | NETXEN_HW_PH_CRB_AGT_ADR) | ||
220 | #define NETXEN_HW_CRB_HUB_AGT_ADR_MS \ | ||
221 | ((NETXEN_HW_H0_CH_HUB_ADR << 7) | NETXEN_HW_MS_CRB_AGT_ADR) | ||
222 | |||
223 | #define NETXEN_HW_CRB_HUB_AGT_ADR_PS \ | ||
224 | ((NETXEN_HW_H1_CH_HUB_ADR << 7) | NETXEN_HW_PS_CRB_AGT_ADR) | ||
225 | #define NETXEN_HW_CRB_HUB_AGT_ADR_SS \ | ||
226 | ((NETXEN_HW_H1_CH_HUB_ADR << 7) | NETXEN_HW_SS_CRB_AGT_ADR) | ||
227 | #define NETXEN_HW_CRB_HUB_AGT_ADR_RPMX3 \ | ||
228 | ((NETXEN_HW_H1_CH_HUB_ADR << 7) | NETXEN_HW_RPMX3_CRB_AGT_ADR) | ||
229 | #define NETXEN_HW_CRB_HUB_AGT_ADR_QMS \ | ||
230 | ((NETXEN_HW_H1_CH_HUB_ADR << 7) | NETXEN_HW_QMS_CRB_AGT_ADR) | ||
231 | #define NETXEN_HW_CRB_HUB_AGT_ADR_SQS0 \ | ||
232 | ((NETXEN_HW_H1_CH_HUB_ADR << 7) | NETXEN_HW_SQGS0_CRB_AGT_ADR) | ||
233 | #define NETXEN_HW_CRB_HUB_AGT_ADR_SQS1 \ | ||
234 | ((NETXEN_HW_H1_CH_HUB_ADR << 7) | NETXEN_HW_SQGS1_CRB_AGT_ADR) | ||
235 | #define NETXEN_HW_CRB_HUB_AGT_ADR_SQS2 \ | ||
236 | ((NETXEN_HW_H1_CH_HUB_ADR << 7) | NETXEN_HW_SQGS2_CRB_AGT_ADR) | ||
237 | #define NETXEN_HW_CRB_HUB_AGT_ADR_SQS3 \ | ||
238 | ((NETXEN_HW_H1_CH_HUB_ADR << 7) | NETXEN_HW_SQGS3_CRB_AGT_ADR) | ||
239 | #define NETXEN_HW_CRB_HUB_AGT_ADR_C2C0 \ | ||
240 | ((NETXEN_HW_H1_CH_HUB_ADR << 7) | NETXEN_HW_C2C0_CRB_AGT_ADR) | ||
241 | #define NETXEN_HW_CRB_HUB_AGT_ADR_C2C1 \ | ||
242 | ((NETXEN_HW_H1_CH_HUB_ADR << 7) | NETXEN_HW_C2C1_CRB_AGT_ADR) | ||
243 | #define NETXEN_HW_CRB_HUB_AGT_ADR_RPMX2 \ | ||
244 | ((NETXEN_HW_H1_CH_HUB_ADR << 7) | NETXEN_HW_RPMX2_CRB_AGT_ADR) | ||
245 | #define NETXEN_HW_CRB_HUB_AGT_ADR_RPMX4 \ | ||
246 | ((NETXEN_HW_H1_CH_HUB_ADR << 7) | NETXEN_HW_RPMX4_CRB_AGT_ADR) | ||
247 | #define NETXEN_HW_CRB_HUB_AGT_ADR_RPMX7 \ | ||
248 | ((NETXEN_HW_H1_CH_HUB_ADR << 7) | NETXEN_HW_RPMX7_CRB_AGT_ADR) | ||
249 | #define NETXEN_HW_CRB_HUB_AGT_ADR_RPMX9 \ | ||
250 | ((NETXEN_HW_H1_CH_HUB_ADR << 7) | NETXEN_HW_RPMX9_CRB_AGT_ADR) | ||
251 | #define NETXEN_HW_CRB_HUB_AGT_ADR_SMB \ | ||
252 | ((NETXEN_HW_H1_CH_HUB_ADR << 7) | NETXEN_HW_SMB_CRB_AGT_ADR) | ||
253 | |||
254 | #define NETXEN_HW_CRB_HUB_AGT_ADR_NIU \ | ||
255 | ((NETXEN_HW_H2_CH_HUB_ADR << 7) | NETXEN_HW_NIU_CRB_AGT_ADR) | ||
256 | #define NETXEN_HW_CRB_HUB_AGT_ADR_I2C0 \ | ||
257 | ((NETXEN_HW_H2_CH_HUB_ADR << 7) | NETXEN_HW_I2C0_CRB_AGT_ADR) | ||
258 | #define NETXEN_HW_CRB_HUB_AGT_ADR_I2C1 \ | ||
259 | ((NETXEN_HW_H2_CH_HUB_ADR << 7) | NETXEN_HW_I2C1_CRB_AGT_ADR) | ||
260 | |||
261 | #define NETXEN_HW_CRB_HUB_AGT_ADR_SRE \ | ||
262 | ((NETXEN_HW_H3_CH_HUB_ADR << 7) | NETXEN_HW_SRE_CRB_AGT_ADR) | ||
263 | #define NETXEN_HW_CRB_HUB_AGT_ADR_EG \ | ||
264 | ((NETXEN_HW_H3_CH_HUB_ADR << 7) | NETXEN_HW_EG_CRB_AGT_ADR) | ||
265 | #define NETXEN_HW_CRB_HUB_AGT_ADR_RPMX0 \ | ||
266 | ((NETXEN_HW_H3_CH_HUB_ADR << 7) | NETXEN_HW_RPMX0_CRB_AGT_ADR) | ||
267 | #define NETXEN_HW_CRB_HUB_AGT_ADR_QMN \ | ||
268 | ((NETXEN_HW_H3_CH_HUB_ADR << 7) | NETXEN_HW_QM_CRB_AGT_ADR) | ||
269 | #define NETXEN_HW_CRB_HUB_AGT_ADR_SQN0 \ | ||
270 | ((NETXEN_HW_H3_CH_HUB_ADR << 7) | NETXEN_HW_SQG0_CRB_AGT_ADR) | ||
271 | #define NETXEN_HW_CRB_HUB_AGT_ADR_SQN1 \ | ||
272 | ((NETXEN_HW_H3_CH_HUB_ADR << 7) | NETXEN_HW_SQG1_CRB_AGT_ADR) | ||
273 | #define NETXEN_HW_CRB_HUB_AGT_ADR_SQN2 \ | ||
274 | ((NETXEN_HW_H3_CH_HUB_ADR << 7) | NETXEN_HW_SQG2_CRB_AGT_ADR) | ||
275 | #define NETXEN_HW_CRB_HUB_AGT_ADR_SQN3 \ | ||
276 | ((NETXEN_HW_H3_CH_HUB_ADR << 7) | NETXEN_HW_SQG3_CRB_AGT_ADR) | ||
277 | #define NETXEN_HW_CRB_HUB_AGT_ADR_RPMX1 \ | ||
278 | ((NETXEN_HW_H3_CH_HUB_ADR << 7) | NETXEN_HW_RPMX1_CRB_AGT_ADR) | ||
279 | #define NETXEN_HW_CRB_HUB_AGT_ADR_RPMX5 \ | ||
280 | ((NETXEN_HW_H3_CH_HUB_ADR << 7) | NETXEN_HW_RPMX5_CRB_AGT_ADR) | ||
281 | #define NETXEN_HW_CRB_HUB_AGT_ADR_RPMX6 \ | ||
282 | ((NETXEN_HW_H3_CH_HUB_ADR << 7) | NETXEN_HW_RPMX6_CRB_AGT_ADR) | ||
283 | #define NETXEN_HW_CRB_HUB_AGT_ADR_RPMX8 \ | ||
284 | ((NETXEN_HW_H3_CH_HUB_ADR << 7) | NETXEN_HW_RPMX8_CRB_AGT_ADR) | ||
285 | #define NETXEN_HW_CRB_HUB_AGT_ADR_CAS0 \ | ||
286 | ((NETXEN_HW_H3_CH_HUB_ADR << 7) | NETXEN_HW_CAS0_CRB_AGT_ADR) | ||
287 | #define NETXEN_HW_CRB_HUB_AGT_ADR_CAS1 \ | ||
288 | ((NETXEN_HW_H3_CH_HUB_ADR << 7) | NETXEN_HW_CAS1_CRB_AGT_ADR) | ||
289 | #define NETXEN_HW_CRB_HUB_AGT_ADR_CAS2 \ | ||
290 | ((NETXEN_HW_H3_CH_HUB_ADR << 7) | NETXEN_HW_CAS2_CRB_AGT_ADR) | ||
291 | #define NETXEN_HW_CRB_HUB_AGT_ADR_CAS3 \ | ||
292 | ((NETXEN_HW_H3_CH_HUB_ADR << 7) | NETXEN_HW_CAS3_CRB_AGT_ADR) | ||
293 | |||
294 | #define NETXEN_HW_CRB_HUB_AGT_ADR_PGNI \ | ||
295 | ((NETXEN_HW_H4_CH_HUB_ADR << 7) | NETXEN_HW_PEGNI_CRB_AGT_ADR) | ||
296 | #define NETXEN_HW_CRB_HUB_AGT_ADR_PGND \ | ||
297 | ((NETXEN_HW_H4_CH_HUB_ADR << 7) | NETXEN_HW_PEGND_CRB_AGT_ADR) | ||
298 | #define NETXEN_HW_CRB_HUB_AGT_ADR_PGN0 \ | ||
299 | ((NETXEN_HW_H4_CH_HUB_ADR << 7) | NETXEN_HW_PEGN0_CRB_AGT_ADR) | ||
300 | #define NETXEN_HW_CRB_HUB_AGT_ADR_PGN1 \ | ||
301 | ((NETXEN_HW_H4_CH_HUB_ADR << 7) | NETXEN_HW_PEGN1_CRB_AGT_ADR) | ||
302 | #define NETXEN_HW_CRB_HUB_AGT_ADR_PGN2 \ | ||
303 | ((NETXEN_HW_H4_CH_HUB_ADR << 7) | NETXEN_HW_PEGN2_CRB_AGT_ADR) | ||
304 | #define NETXEN_HW_CRB_HUB_AGT_ADR_PGN3 \ | ||
305 | ((NETXEN_HW_H4_CH_HUB_ADR << 7) | NETXEN_HW_PEGN3_CRB_AGT_ADR) | ||
306 | #define NETXEN_HW_CRB_HUB_AGT_ADR_PGN4 \ | ||
307 | ((NETXEN_HW_H4_CH_HUB_ADR << 7) | NETXEN_HW_PEGN4_CRB_AGT_ADR) | ||
308 | #define NETXEN_HW_CRB_HUB_AGT_ADR_PGNC \ | ||
309 | ((NETXEN_HW_H4_CH_HUB_ADR << 7) | NETXEN_HW_PEGNC_CRB_AGT_ADR) | ||
310 | #define NETXEN_HW_CRB_HUB_AGT_ADR_PGR0 \ | ||
311 | ((NETXEN_HW_H4_CH_HUB_ADR << 7) | NETXEN_HW_PEGR0_CRB_AGT_ADR) | ||
312 | #define NETXEN_HW_CRB_HUB_AGT_ADR_PGR1 \ | ||
313 | ((NETXEN_HW_H4_CH_HUB_ADR << 7) | NETXEN_HW_PEGR1_CRB_AGT_ADR) | ||
314 | #define NETXEN_HW_CRB_HUB_AGT_ADR_PGR2 \ | ||
315 | ((NETXEN_HW_H4_CH_HUB_ADR << 7) | NETXEN_HW_PEGR2_CRB_AGT_ADR) | ||
316 | #define NETXEN_HW_CRB_HUB_AGT_ADR_PGR3 \ | ||
317 | ((NETXEN_HW_H4_CH_HUB_ADR << 7) | NETXEN_HW_PEGR3_CRB_AGT_ADR) | ||
318 | |||
319 | #define NETXEN_HW_CRB_HUB_AGT_ADR_PGSI \ | ||
320 | ((NETXEN_HW_H5_CH_HUB_ADR << 7) | NETXEN_HW_PEGSI_CRB_AGT_ADR) | ||
321 | #define NETXEN_HW_CRB_HUB_AGT_ADR_PGSD \ | ||
322 | ((NETXEN_HW_H5_CH_HUB_ADR << 7) | NETXEN_HW_PEGSD_CRB_AGT_ADR) | ||
323 | #define NETXEN_HW_CRB_HUB_AGT_ADR_PGS0 \ | ||
324 | ((NETXEN_HW_H5_CH_HUB_ADR << 7) | NETXEN_HW_PEGS0_CRB_AGT_ADR) | ||
325 | #define NETXEN_HW_CRB_HUB_AGT_ADR_PGS1 \ | ||
326 | ((NETXEN_HW_H5_CH_HUB_ADR << 7) | NETXEN_HW_PEGS1_CRB_AGT_ADR) | ||
327 | #define NETXEN_HW_CRB_HUB_AGT_ADR_PGS2 \ | ||
328 | ((NETXEN_HW_H5_CH_HUB_ADR << 7) | NETXEN_HW_PEGS2_CRB_AGT_ADR) | ||
329 | #define NETXEN_HW_CRB_HUB_AGT_ADR_PGS3 \ | ||
330 | ((NETXEN_HW_H5_CH_HUB_ADR << 7) | NETXEN_HW_PEGS3_CRB_AGT_ADR) | ||
331 | #define NETXEN_HW_CRB_HUB_AGT_ADR_PGSC \ | ||
332 | ((NETXEN_HW_H5_CH_HUB_ADR << 7) | NETXEN_HW_PEGSC_CRB_AGT_ADR) | ||
333 | |||
334 | #define NETXEN_HW_CRB_HUB_AGT_ADR_CAM \ | ||
335 | ((NETXEN_HW_H6_CH_HUB_ADR << 7) | NETXEN_HW_NCM_CRB_AGT_ADR) | ||
336 | #define NETXEN_HW_CRB_HUB_AGT_ADR_TIMR \ | ||
337 | ((NETXEN_HW_H6_CH_HUB_ADR << 7) | NETXEN_HW_TMR_CRB_AGT_ADR) | ||
338 | #define NETXEN_HW_CRB_HUB_AGT_ADR_XDMA \ | ||
339 | ((NETXEN_HW_H6_CH_HUB_ADR << 7) | NETXEN_HW_XDMA_CRB_AGT_ADR) | ||
340 | #define NETXEN_HW_CRB_HUB_AGT_ADR_SN \ | ||
341 | ((NETXEN_HW_H6_CH_HUB_ADR << 7) | NETXEN_HW_SN_CRB_AGT_ADR) | ||
342 | #define NETXEN_HW_CRB_HUB_AGT_ADR_I2Q \ | ||
343 | ((NETXEN_HW_H6_CH_HUB_ADR << 7) | NETXEN_HW_I2Q_CRB_AGT_ADR) | ||
344 | #define NETXEN_HW_CRB_HUB_AGT_ADR_ROMUSB \ | ||
345 | ((NETXEN_HW_H6_CH_HUB_ADR << 7) | NETXEN_HW_ROMUSB_CRB_AGT_ADR) | ||
346 | #define NETXEN_HW_CRB_HUB_AGT_ADR_OCM0 \ | ||
347 | ((NETXEN_HW_H6_CH_HUB_ADR << 7) | NETXEN_HW_OCM0_CRB_AGT_ADR) | ||
348 | #define NETXEN_HW_CRB_HUB_AGT_ADR_OCM1 \ | ||
349 | ((NETXEN_HW_H6_CH_HUB_ADR << 7) | NETXEN_HW_OCM1_CRB_AGT_ADR) | ||
350 | #define NETXEN_HW_CRB_HUB_AGT_ADR_LPC \ | ||
351 | ((NETXEN_HW_H6_CH_HUB_ADR << 7) | NETXEN_HW_LPC_CRB_AGT_ADR) | ||
352 | |||
353 | #define NETXEN_SRE_MISC (NETXEN_CRB_SRE + 0x0002c) | ||
354 | #define NETXEN_SRE_INT_STATUS (NETXEN_CRB_SRE + 0x00034) | ||
355 | #define NETXEN_SRE_PBI_ACTIVE_STATUS (NETXEN_CRB_SRE + 0x01014) | ||
356 | #define NETXEN_SRE_L1RE_CTL (NETXEN_CRB_SRE + 0x03000) | ||
357 | #define NETXEN_SRE_L2RE_CTL (NETXEN_CRB_SRE + 0x05000) | ||
358 | #define NETXEN_SRE_BUF_CTL (NETXEN_CRB_SRE + 0x01000) | ||
359 | |||
360 | #define NETXEN_DMA_BASE(U) (NETXEN_CRB_PCIX_MD + 0x20000 + ((U)<<16)) | ||
361 | #define NETXEN_DMA_COMMAND(U) (NETXEN_DMA_BASE(U) + 0x00008) | ||
362 | |||
363 | #define NETXEN_I2Q_CLR_PCI_HI (NETXEN_CRB_I2Q + 0x00034) | ||
364 | |||
365 | #define PEG_NETWORK_BASE(N) (NETXEN_CRB_PEG_NET_0 + (((N)&3) << 20)) | ||
366 | #define CRB_REG_EX_PC 0x3c | ||
367 | |||
368 | #define ROMUSB_GLB (NETXEN_CRB_ROMUSB + 0x00000) | ||
369 | #define ROMUSB_ROM (NETXEN_CRB_ROMUSB + 0x10000) | ||
370 | |||
371 | #define NETXEN_ROMUSB_GLB_STATUS (ROMUSB_GLB + 0x0004) | ||
372 | #define NETXEN_ROMUSB_GLB_SW_RESET (ROMUSB_GLB + 0x0008) | ||
373 | #define NETXEN_ROMUSB_GLB_PAD_GPIO_I (ROMUSB_GLB + 0x000c) | ||
374 | #define NETXEN_ROMUSB_GLB_CAS_RST (ROMUSB_GLB + 0x0038) | ||
375 | #define NETXEN_ROMUSB_GLB_TEST_MUX_SEL (ROMUSB_GLB + 0x0044) | ||
376 | #define NETXEN_ROMUSB_GLB_PEGTUNE_DONE (ROMUSB_GLB + 0x005c) | ||
377 | #define NETXEN_ROMUSB_GLB_CHIP_CLK_CTRL (ROMUSB_GLB + 0x00A8) | ||
378 | |||
379 | #define NETXEN_ROMUSB_GPIO(n) (ROMUSB_GLB + 0x60 + (4 * (n))) | ||
380 | |||
381 | #define NETXEN_ROMUSB_ROM_INSTR_OPCODE (ROMUSB_ROM + 0x0004) | ||
382 | #define NETXEN_ROMUSB_ROM_ADDRESS (ROMUSB_ROM + 0x0008) | ||
383 | #define NETXEN_ROMUSB_ROM_WDATA (ROMUSB_ROM + 0x000c) | ||
384 | #define NETXEN_ROMUSB_ROM_ABYTE_CNT (ROMUSB_ROM + 0x0010) | ||
385 | #define NETXEN_ROMUSB_ROM_DUMMY_BYTE_CNT (ROMUSB_ROM + 0x0014) | ||
386 | #define NETXEN_ROMUSB_ROM_RDATA (ROMUSB_ROM + 0x0018) | ||
387 | |||
388 | /* Lock IDs for ROM lock */ | ||
389 | #define ROM_LOCK_DRIVER 0x0d417340 | ||
390 | |||
391 | /****************************************************************************** | ||
392 | * | ||
393 | * Definitions specific to M25P flash | ||
394 | * | ||
395 | ******************************************************************************* | ||
396 | * Instructions | ||
397 | */ | ||
398 | #define M25P_INSTR_WREN 0x06 | ||
399 | #define M25P_INSTR_WRDI 0x04 | ||
400 | #define M25P_INSTR_RDID 0x9f | ||
401 | #define M25P_INSTR_RDSR 0x05 | ||
402 | #define M25P_INSTR_WRSR 0x01 | ||
403 | #define M25P_INSTR_READ 0x03 | ||
404 | #define M25P_INSTR_FAST_READ 0x0b | ||
405 | #define M25P_INSTR_PP 0x02 | ||
406 | #define M25P_INSTR_SE 0xd8 | ||
407 | #define M25P_INSTR_BE 0xc7 | ||
408 | #define M25P_INSTR_DP 0xb9 | ||
409 | #define M25P_INSTR_RES 0xab | ||
410 | |||
411 | /* all are 1MB windows */ | ||
412 | |||
413 | #define NETXEN_PCI_CRB_WINDOWSIZE 0x00100000 | ||
414 | #define NETXEN_PCI_CRB_WINDOW(A) \ | ||
415 | (NETXEN_PCI_CRBSPACE + (A)*NETXEN_PCI_CRB_WINDOWSIZE) | ||
416 | |||
417 | #define NETXEN_CRB_NIU NETXEN_PCI_CRB_WINDOW(NETXEN_HW_PX_MAP_CRB_NIU) | ||
418 | #define NETXEN_CRB_SRE NETXEN_PCI_CRB_WINDOW(NETXEN_HW_PX_MAP_CRB_SRE) | ||
419 | #define NETXEN_CRB_ROMUSB \ | ||
420 | NETXEN_PCI_CRB_WINDOW(NETXEN_HW_PX_MAP_CRB_ROMUSB) | ||
421 | #define NETXEN_CRB_I2Q NETXEN_PCI_CRB_WINDOW(NETXEN_HW_PX_MAP_CRB_I2Q) | ||
422 | #define NETXEN_CRB_I2C0 NETXEN_PCI_CRB_WINDOW(NETXEN_HW_PX_MAP_CRB_I2C0) | ||
423 | #define NETXEN_CRB_SMB NETXEN_PCI_CRB_WINDOW(NETXEN_HW_PX_MAP_CRB_SMB) | ||
424 | #define NETXEN_CRB_MAX NETXEN_PCI_CRB_WINDOW(64) | ||
425 | |||
426 | #define NETXEN_CRB_PCIX_HOST NETXEN_PCI_CRB_WINDOW(NETXEN_HW_PX_MAP_CRB_PH) | ||
427 | #define NETXEN_CRB_PCIX_HOST2 NETXEN_PCI_CRB_WINDOW(NETXEN_HW_PX_MAP_CRB_PH2) | ||
428 | #define NETXEN_CRB_PEG_NET_0 NETXEN_PCI_CRB_WINDOW(NETXEN_HW_PX_MAP_CRB_PGN0) | ||
429 | #define NETXEN_CRB_PEG_NET_1 NETXEN_PCI_CRB_WINDOW(NETXEN_HW_PX_MAP_CRB_PGN1) | ||
430 | #define NETXEN_CRB_PEG_NET_2 NETXEN_PCI_CRB_WINDOW(NETXEN_HW_PX_MAP_CRB_PGN2) | ||
431 | #define NETXEN_CRB_PEG_NET_3 NETXEN_PCI_CRB_WINDOW(NETXEN_HW_PX_MAP_CRB_PGN3) | ||
432 | #define NETXEN_CRB_PEG_NET_4 NETXEN_PCI_CRB_WINDOW(NETXEN_HW_PX_MAP_CRB_SQS2) | ||
433 | #define NETXEN_CRB_PEG_NET_D NETXEN_PCI_CRB_WINDOW(NETXEN_HW_PX_MAP_CRB_PGND) | ||
434 | #define NETXEN_CRB_PEG_NET_I NETXEN_PCI_CRB_WINDOW(NETXEN_HW_PX_MAP_CRB_PGNI) | ||
435 | #define NETXEN_CRB_DDR_NET NETXEN_PCI_CRB_WINDOW(NETXEN_HW_PX_MAP_CRB_MN) | ||
436 | #define NETXEN_CRB_QDR_NET NETXEN_PCI_CRB_WINDOW(NETXEN_HW_PX_MAP_CRB_SN) | ||
437 | |||
438 | #define NETXEN_CRB_PCIX_MD NETXEN_PCI_CRB_WINDOW(NETXEN_HW_PX_MAP_CRB_PS) | ||
439 | #define NETXEN_CRB_PCIE NETXEN_CRB_PCIX_MD | ||
440 | |||
441 | #define ISR_INT_VECTOR (NETXEN_PCIX_PS_REG(PCIX_INT_VECTOR)) | ||
442 | #define ISR_INT_MASK (NETXEN_PCIX_PS_REG(PCIX_INT_MASK)) | ||
443 | #define ISR_INT_MASK_SLOW (NETXEN_PCIX_PS_REG(PCIX_INT_MASK)) | ||
444 | #define ISR_INT_TARGET_STATUS (NETXEN_PCIX_PS_REG(PCIX_TARGET_STATUS)) | ||
445 | #define ISR_INT_TARGET_MASK (NETXEN_PCIX_PS_REG(PCIX_TARGET_MASK)) | ||
446 | #define ISR_INT_TARGET_STATUS_F1 (NETXEN_PCIX_PS_REG(PCIX_TARGET_STATUS_F1)) | ||
447 | #define ISR_INT_TARGET_MASK_F1 (NETXEN_PCIX_PS_REG(PCIX_TARGET_MASK_F1)) | ||
448 | #define ISR_INT_TARGET_STATUS_F2 (NETXEN_PCIX_PS_REG(PCIX_TARGET_STATUS_F2)) | ||
449 | #define ISR_INT_TARGET_MASK_F2 (NETXEN_PCIX_PS_REG(PCIX_TARGET_MASK_F2)) | ||
450 | #define ISR_INT_TARGET_STATUS_F3 (NETXEN_PCIX_PS_REG(PCIX_TARGET_STATUS_F3)) | ||
451 | #define ISR_INT_TARGET_MASK_F3 (NETXEN_PCIX_PS_REG(PCIX_TARGET_MASK_F3)) | ||
452 | #define ISR_INT_TARGET_STATUS_F4 (NETXEN_PCIX_PS_REG(PCIX_TARGET_STATUS_F4)) | ||
453 | #define ISR_INT_TARGET_MASK_F4 (NETXEN_PCIX_PS_REG(PCIX_TARGET_MASK_F4)) | ||
454 | #define ISR_INT_TARGET_STATUS_F5 (NETXEN_PCIX_PS_REG(PCIX_TARGET_STATUS_F5)) | ||
455 | #define ISR_INT_TARGET_MASK_F5 (NETXEN_PCIX_PS_REG(PCIX_TARGET_MASK_F5)) | ||
456 | #define ISR_INT_TARGET_STATUS_F6 (NETXEN_PCIX_PS_REG(PCIX_TARGET_STATUS_F6)) | ||
457 | #define ISR_INT_TARGET_MASK_F6 (NETXEN_PCIX_PS_REG(PCIX_TARGET_MASK_F6)) | ||
458 | #define ISR_INT_TARGET_STATUS_F7 (NETXEN_PCIX_PS_REG(PCIX_TARGET_STATUS_F7)) | ||
459 | #define ISR_INT_TARGET_MASK_F7 (NETXEN_PCIX_PS_REG(PCIX_TARGET_MASK_F7)) | ||
460 | |||
461 | #define NETXEN_PCI_MAPSIZE 128 | ||
462 | #define NETXEN_PCI_DDR_NET (0x00000000UL) | ||
463 | #define NETXEN_PCI_QDR_NET (0x04000000UL) | ||
464 | #define NETXEN_PCI_DIRECT_CRB (0x04400000UL) | ||
465 | #define NETXEN_PCI_CAMQM (0x04800000UL) | ||
466 | #define NETXEN_PCI_CAMQM_MAX (0x04ffffffUL) | ||
467 | #define NETXEN_PCI_OCM0 (0x05000000UL) | ||
468 | #define NETXEN_PCI_OCM0_MAX (0x050fffffUL) | ||
469 | #define NETXEN_PCI_OCM1 (0x05100000UL) | ||
470 | #define NETXEN_PCI_OCM1_MAX (0x051fffffUL) | ||
471 | #define NETXEN_PCI_CRBSPACE (0x06000000UL) | ||
472 | #define NETXEN_PCI_128MB_SIZE (0x08000000UL) | ||
473 | #define NETXEN_PCI_32MB_SIZE (0x02000000UL) | ||
474 | #define NETXEN_PCI_2MB_SIZE (0x00200000UL) | ||
475 | |||
476 | #define NETXEN_PCI_MN_2M (0) | ||
477 | #define NETXEN_PCI_MS_2M (0x80000) | ||
478 | #define NETXEN_PCI_OCM0_2M (0x000c0000UL) | ||
479 | #define NETXEN_PCI_CAMQM_2M_BASE (0x000ff800UL) | ||
480 | #define NETXEN_PCI_CAMQM_2M_END (0x04800800UL) | ||
481 | |||
482 | #define NETXEN_CRB_CAM NETXEN_PCI_CRB_WINDOW(NETXEN_HW_PX_MAP_CRB_CAM) | ||
483 | |||
484 | #define NETXEN_ADDR_DDR_NET (0x0000000000000000ULL) | ||
485 | #define NETXEN_ADDR_DDR_NET_MAX (0x000000000fffffffULL) | ||
486 | #define NETXEN_ADDR_OCM0 (0x0000000200000000ULL) | ||
487 | #define NETXEN_ADDR_OCM0_MAX (0x00000002000fffffULL) | ||
488 | #define NETXEN_ADDR_OCM1 (0x0000000200400000ULL) | ||
489 | #define NETXEN_ADDR_OCM1_MAX (0x00000002004fffffULL) | ||
490 | #define NETXEN_ADDR_QDR_NET (0x0000000300000000ULL) | ||
491 | #define NETXEN_ADDR_QDR_NET_MAX_P2 (0x00000003003fffffULL) | ||
492 | #define NETXEN_ADDR_QDR_NET_MAX_P3 (0x0000000303ffffffULL) | ||
493 | |||
494 | /* | ||
495 | * Register offsets for MN | ||
496 | */ | ||
497 | #define NETXEN_MIU_CONTROL (0x000) | ||
498 | #define NETXEN_MIU_MN_CONTROL (NETXEN_CRB_DDR_NET+NETXEN_MIU_CONTROL) | ||
499 | |||
500 | /* 200ms delay in each loop */ | ||
501 | #define NETXEN_NIU_PHY_WAITLEN 200000 | ||
502 | /* 10 seconds before we give up */ | ||
503 | #define NETXEN_NIU_PHY_WAITMAX 50 | ||
504 | #define NETXEN_NIU_MAX_GBE_PORTS 4 | ||
505 | #define NETXEN_NIU_MAX_XG_PORTS 2 | ||
506 | |||
507 | #define NETXEN_NIU_MODE (NETXEN_CRB_NIU + 0x00000) | ||
508 | |||
509 | #define NETXEN_NIU_XG_SINGLE_TERM (NETXEN_CRB_NIU + 0x00004) | ||
510 | #define NETXEN_NIU_XG_DRIVE_HI (NETXEN_CRB_NIU + 0x00008) | ||
511 | #define NETXEN_NIU_XG_DRIVE_LO (NETXEN_CRB_NIU + 0x0000c) | ||
512 | #define NETXEN_NIU_XG_DTX (NETXEN_CRB_NIU + 0x00010) | ||
513 | #define NETXEN_NIU_XG_DEQ (NETXEN_CRB_NIU + 0x00014) | ||
514 | #define NETXEN_NIU_XG_WORD_ALIGN (NETXEN_CRB_NIU + 0x00018) | ||
515 | #define NETXEN_NIU_XG_RESET (NETXEN_CRB_NIU + 0x0001c) | ||
516 | #define NETXEN_NIU_XG_POWER_DOWN (NETXEN_CRB_NIU + 0x00020) | ||
517 | #define NETXEN_NIU_XG_RESET_PLL (NETXEN_CRB_NIU + 0x00024) | ||
518 | #define NETXEN_NIU_XG_SERDES_LOOPBACK (NETXEN_CRB_NIU + 0x00028) | ||
519 | #define NETXEN_NIU_XG_DO_BYTE_ALIGN (NETXEN_CRB_NIU + 0x0002c) | ||
520 | #define NETXEN_NIU_XG_TX_ENABLE (NETXEN_CRB_NIU + 0x00030) | ||
521 | #define NETXEN_NIU_XG_RX_ENABLE (NETXEN_CRB_NIU + 0x00034) | ||
522 | #define NETXEN_NIU_XG_STATUS (NETXEN_CRB_NIU + 0x00038) | ||
523 | #define NETXEN_NIU_XG_PAUSE_THRESHOLD (NETXEN_CRB_NIU + 0x0003c) | ||
524 | #define NETXEN_NIU_INT_MASK (NETXEN_CRB_NIU + 0x00040) | ||
525 | #define NETXEN_NIU_ACTIVE_INT (NETXEN_CRB_NIU + 0x00044) | ||
526 | #define NETXEN_NIU_MASKABLE_INT (NETXEN_CRB_NIU + 0x00048) | ||
527 | |||
528 | #define NETXEN_NIU_STRAP_VALUE_SAVE_HIGHER (NETXEN_CRB_NIU + 0x0004c) | ||
529 | |||
530 | #define NETXEN_NIU_GB_SERDES_RESET (NETXEN_CRB_NIU + 0x00050) | ||
531 | #define NETXEN_NIU_GB0_GMII_MODE (NETXEN_CRB_NIU + 0x00054) | ||
532 | #define NETXEN_NIU_GB0_MII_MODE (NETXEN_CRB_NIU + 0x00058) | ||
533 | #define NETXEN_NIU_GB1_GMII_MODE (NETXEN_CRB_NIU + 0x0005c) | ||
534 | #define NETXEN_NIU_GB1_MII_MODE (NETXEN_CRB_NIU + 0x00060) | ||
535 | #define NETXEN_NIU_GB2_GMII_MODE (NETXEN_CRB_NIU + 0x00064) | ||
536 | #define NETXEN_NIU_GB2_MII_MODE (NETXEN_CRB_NIU + 0x00068) | ||
537 | #define NETXEN_NIU_GB3_GMII_MODE (NETXEN_CRB_NIU + 0x0006c) | ||
538 | #define NETXEN_NIU_GB3_MII_MODE (NETXEN_CRB_NIU + 0x00070) | ||
539 | #define NETXEN_NIU_REMOTE_LOOPBACK (NETXEN_CRB_NIU + 0x00074) | ||
540 | #define NETXEN_NIU_GB0_HALF_DUPLEX (NETXEN_CRB_NIU + 0x00078) | ||
541 | #define NETXEN_NIU_GB1_HALF_DUPLEX (NETXEN_CRB_NIU + 0x0007c) | ||
542 | #define NETXEN_NIU_RESET_SYS_FIFOS (NETXEN_CRB_NIU + 0x00088) | ||
543 | #define NETXEN_NIU_GB_CRC_DROP (NETXEN_CRB_NIU + 0x0008c) | ||
544 | #define NETXEN_NIU_GB_DROP_WRONGADDR (NETXEN_CRB_NIU + 0x00090) | ||
545 | #define NETXEN_NIU_TEST_MUX_CTL (NETXEN_CRB_NIU + 0x00094) | ||
546 | #define NETXEN_NIU_XG_PAUSE_CTL (NETXEN_CRB_NIU + 0x00098) | ||
547 | #define NETXEN_NIU_XG_PAUSE_LEVEL (NETXEN_CRB_NIU + 0x000dc) | ||
548 | #define NETXEN_NIU_FRAME_COUNT_SELECT (NETXEN_CRB_NIU + 0x000ac) | ||
549 | #define NETXEN_NIU_FRAME_COUNT (NETXEN_CRB_NIU + 0x000b0) | ||
550 | #define NETXEN_NIU_XG_SEL (NETXEN_CRB_NIU + 0x00128) | ||
551 | #define NETXEN_NIU_GB_PAUSE_CTL (NETXEN_CRB_NIU + 0x0030c) | ||
552 | |||
553 | #define NETXEN_NIU_FULL_LEVEL_XG (NETXEN_CRB_NIU + 0x00450) | ||
554 | |||
555 | #define NETXEN_NIU_XG1_RESET (NETXEN_CRB_NIU + 0x0011c) | ||
556 | #define NETXEN_NIU_XG1_POWER_DOWN (NETXEN_CRB_NIU + 0x00120) | ||
557 | #define NETXEN_NIU_XG1_RESET_PLL (NETXEN_CRB_NIU + 0x00124) | ||
558 | |||
559 | #define NETXEN_MAC_ADDR_CNTL_REG (NETXEN_CRB_NIU + 0x1000) | ||
560 | |||
561 | #define NETXEN_MULTICAST_ADDR_HI_0 (NETXEN_CRB_NIU + 0x1010) | ||
562 | #define NETXEN_MULTICAST_ADDR_HI_1 (NETXEN_CRB_NIU + 0x1014) | ||
563 | #define NETXEN_MULTICAST_ADDR_HI_2 (NETXEN_CRB_NIU + 0x1018) | ||
564 | #define NETXEN_MULTICAST_ADDR_HI_3 (NETXEN_CRB_NIU + 0x101c) | ||
565 | |||
566 | #define NETXEN_UNICAST_ADDR_BASE (NETXEN_CRB_NIU + 0x1080) | ||
567 | #define NETXEN_MULTICAST_ADDR_BASE (NETXEN_CRB_NIU + 0x1100) | ||
568 | |||
569 | #define NETXEN_NIU_GB_MAC_CONFIG_0(I) \ | ||
570 | (NETXEN_CRB_NIU + 0x30000 + (I)*0x10000) | ||
571 | #define NETXEN_NIU_GB_MAC_CONFIG_1(I) \ | ||
572 | (NETXEN_CRB_NIU + 0x30004 + (I)*0x10000) | ||
573 | #define NETXEN_NIU_GB_MAC_IPG_IFG(I) \ | ||
574 | (NETXEN_CRB_NIU + 0x30008 + (I)*0x10000) | ||
575 | #define NETXEN_NIU_GB_HALF_DUPLEX_CTRL(I) \ | ||
576 | (NETXEN_CRB_NIU + 0x3000c + (I)*0x10000) | ||
577 | #define NETXEN_NIU_GB_MAX_FRAME_SIZE(I) \ | ||
578 | (NETXEN_CRB_NIU + 0x30010 + (I)*0x10000) | ||
579 | #define NETXEN_NIU_GB_TEST_REG(I) \ | ||
580 | (NETXEN_CRB_NIU + 0x3001c + (I)*0x10000) | ||
581 | #define NETXEN_NIU_GB_MII_MGMT_CONFIG(I) \ | ||
582 | (NETXEN_CRB_NIU + 0x30020 + (I)*0x10000) | ||
583 | #define NETXEN_NIU_GB_MII_MGMT_COMMAND(I) \ | ||
584 | (NETXEN_CRB_NIU + 0x30024 + (I)*0x10000) | ||
585 | #define NETXEN_NIU_GB_MII_MGMT_ADDR(I) \ | ||
586 | (NETXEN_CRB_NIU + 0x30028 + (I)*0x10000) | ||
587 | #define NETXEN_NIU_GB_MII_MGMT_CTRL(I) \ | ||
588 | (NETXEN_CRB_NIU + 0x3002c + (I)*0x10000) | ||
589 | #define NETXEN_NIU_GB_MII_MGMT_STATUS(I) \ | ||
590 | (NETXEN_CRB_NIU + 0x30030 + (I)*0x10000) | ||
591 | #define NETXEN_NIU_GB_MII_MGMT_INDICATE(I) \ | ||
592 | (NETXEN_CRB_NIU + 0x30034 + (I)*0x10000) | ||
593 | #define NETXEN_NIU_GB_INTERFACE_CTRL(I) \ | ||
594 | (NETXEN_CRB_NIU + 0x30038 + (I)*0x10000) | ||
595 | #define NETXEN_NIU_GB_INTERFACE_STATUS(I) \ | ||
596 | (NETXEN_CRB_NIU + 0x3003c + (I)*0x10000) | ||
597 | #define NETXEN_NIU_GB_STATION_ADDR_0(I) \ | ||
598 | (NETXEN_CRB_NIU + 0x30040 + (I)*0x10000) | ||
599 | #define NETXEN_NIU_GB_STATION_ADDR_1(I) \ | ||
600 | (NETXEN_CRB_NIU + 0x30044 + (I)*0x10000) | ||
601 | |||
602 | #define NETXEN_NIU_XGE_CONFIG_0 (NETXEN_CRB_NIU + 0x70000) | ||
603 | #define NETXEN_NIU_XGE_CONFIG_1 (NETXEN_CRB_NIU + 0x70004) | ||
604 | #define NETXEN_NIU_XGE_IPG (NETXEN_CRB_NIU + 0x70008) | ||
605 | #define NETXEN_NIU_XGE_STATION_ADDR_0_HI (NETXEN_CRB_NIU + 0x7000c) | ||
606 | #define NETXEN_NIU_XGE_STATION_ADDR_0_1 (NETXEN_CRB_NIU + 0x70010) | ||
607 | #define NETXEN_NIU_XGE_STATION_ADDR_1_LO (NETXEN_CRB_NIU + 0x70014) | ||
608 | #define NETXEN_NIU_XGE_STATUS (NETXEN_CRB_NIU + 0x70018) | ||
609 | #define NETXEN_NIU_XGE_MAX_FRAME_SIZE (NETXEN_CRB_NIU + 0x7001c) | ||
610 | #define NETXEN_NIU_XGE_PAUSE_FRAME_VALUE (NETXEN_CRB_NIU + 0x70020) | ||
611 | #define NETXEN_NIU_XGE_TX_BYTE_CNT (NETXEN_CRB_NIU + 0x70024) | ||
612 | #define NETXEN_NIU_XGE_TX_FRAME_CNT (NETXEN_CRB_NIU + 0x70028) | ||
613 | #define NETXEN_NIU_XGE_RX_BYTE_CNT (NETXEN_CRB_NIU + 0x7002c) | ||
614 | #define NETXEN_NIU_XGE_RX_FRAME_CNT (NETXEN_CRB_NIU + 0x70030) | ||
615 | #define NETXEN_NIU_XGE_AGGR_ERROR_CNT (NETXEN_CRB_NIU + 0x70034) | ||
616 | #define NETXEN_NIU_XGE_MULTICAST_FRAME_CNT (NETXEN_CRB_NIU + 0x70038) | ||
617 | #define NETXEN_NIU_XGE_UNICAST_FRAME_CNT (NETXEN_CRB_NIU + 0x7003c) | ||
618 | #define NETXEN_NIU_XGE_CRC_ERROR_CNT (NETXEN_CRB_NIU + 0x70040) | ||
619 | #define NETXEN_NIU_XGE_OVERSIZE_FRAME_ERR (NETXEN_CRB_NIU + 0x70044) | ||
620 | #define NETXEN_NIU_XGE_UNDERSIZE_FRAME_ERR (NETXEN_CRB_NIU + 0x70048) | ||
621 | #define NETXEN_NIU_XGE_LOCAL_ERROR_CNT (NETXEN_CRB_NIU + 0x7004c) | ||
622 | #define NETXEN_NIU_XGE_REMOTE_ERROR_CNT (NETXEN_CRB_NIU + 0x70050) | ||
623 | #define NETXEN_NIU_XGE_CONTROL_CHAR_CNT (NETXEN_CRB_NIU + 0x70054) | ||
624 | #define NETXEN_NIU_XGE_PAUSE_FRAME_CNT (NETXEN_CRB_NIU + 0x70058) | ||
625 | #define NETXEN_NIU_XG1_CONFIG_0 (NETXEN_CRB_NIU + 0x80000) | ||
626 | #define NETXEN_NIU_XG1_CONFIG_1 (NETXEN_CRB_NIU + 0x80004) | ||
627 | #define NETXEN_NIU_XG1_IPG (NETXEN_CRB_NIU + 0x80008) | ||
628 | #define NETXEN_NIU_XG1_STATION_ADDR_0_HI (NETXEN_CRB_NIU + 0x8000c) | ||
629 | #define NETXEN_NIU_XG1_STATION_ADDR_0_1 (NETXEN_CRB_NIU + 0x80010) | ||
630 | #define NETXEN_NIU_XG1_STATION_ADDR_1_LO (NETXEN_CRB_NIU + 0x80014) | ||
631 | #define NETXEN_NIU_XG1_STATUS (NETXEN_CRB_NIU + 0x80018) | ||
632 | #define NETXEN_NIU_XG1_MAX_FRAME_SIZE (NETXEN_CRB_NIU + 0x8001c) | ||
633 | #define NETXEN_NIU_XG1_PAUSE_FRAME_VALUE (NETXEN_CRB_NIU + 0x80020) | ||
634 | #define NETXEN_NIU_XG1_TX_BYTE_CNT (NETXEN_CRB_NIU + 0x80024) | ||
635 | #define NETXEN_NIU_XG1_TX_FRAME_CNT (NETXEN_CRB_NIU + 0x80028) | ||
636 | #define NETXEN_NIU_XG1_RX_BYTE_CNT (NETXEN_CRB_NIU + 0x8002c) | ||
637 | #define NETXEN_NIU_XG1_RX_FRAME_CNT (NETXEN_CRB_NIU + 0x80030) | ||
638 | #define NETXEN_NIU_XG1_AGGR_ERROR_CNT (NETXEN_CRB_NIU + 0x80034) | ||
639 | #define NETXEN_NIU_XG1_MULTICAST_FRAME_CNT (NETXEN_CRB_NIU + 0x80038) | ||
640 | #define NETXEN_NIU_XG1_UNICAST_FRAME_CNT (NETXEN_CRB_NIU + 0x8003c) | ||
641 | #define NETXEN_NIU_XG1_CRC_ERROR_CNT (NETXEN_CRB_NIU + 0x80040) | ||
642 | #define NETXEN_NIU_XG1_OVERSIZE_FRAME_ERR (NETXEN_CRB_NIU + 0x80044) | ||
643 | #define NETXEN_NIU_XG1_UNDERSIZE_FRAME_ERR (NETXEN_CRB_NIU + 0x80048) | ||
644 | #define NETXEN_NIU_XG1_LOCAL_ERROR_CNT (NETXEN_CRB_NIU + 0x8004c) | ||
645 | #define NETXEN_NIU_XG1_REMOTE_ERROR_CNT (NETXEN_CRB_NIU + 0x80050) | ||
646 | #define NETXEN_NIU_XG1_CONTROL_CHAR_CNT (NETXEN_CRB_NIU + 0x80054) | ||
647 | #define NETXEN_NIU_XG1_PAUSE_FRAME_CNT (NETXEN_CRB_NIU + 0x80058) | ||
648 | |||
649 | /* P3 802.3ap */ | ||
650 | #define NETXEN_NIU_AP_MAC_CONFIG_0(I) (NETXEN_CRB_NIU+0xa0000+(I)*0x10000) | ||
651 | #define NETXEN_NIU_AP_MAC_CONFIG_1(I) (NETXEN_CRB_NIU+0xa0004+(I)*0x10000) | ||
652 | #define NETXEN_NIU_AP_MAC_IPG_IFG(I) (NETXEN_CRB_NIU+0xa0008+(I)*0x10000) | ||
653 | #define NETXEN_NIU_AP_HALF_DUPLEX_CTRL(I) (NETXEN_CRB_NIU+0xa000c+(I)*0x10000) | ||
654 | #define NETXEN_NIU_AP_MAX_FRAME_SIZE(I) (NETXEN_CRB_NIU+0xa0010+(I)*0x10000) | ||
655 | #define NETXEN_NIU_AP_TEST_REG(I) (NETXEN_CRB_NIU+0xa001c+(I)*0x10000) | ||
656 | #define NETXEN_NIU_AP_MII_MGMT_CONFIG(I) (NETXEN_CRB_NIU+0xa0020+(I)*0x10000) | ||
657 | #define NETXEN_NIU_AP_MII_MGMT_COMMAND(I) (NETXEN_CRB_NIU+0xa0024+(I)*0x10000) | ||
658 | #define NETXEN_NIU_AP_MII_MGMT_ADDR(I) (NETXEN_CRB_NIU+0xa0028+(I)*0x10000) | ||
659 | #define NETXEN_NIU_AP_MII_MGMT_CTRL(I) (NETXEN_CRB_NIU+0xa002c+(I)*0x10000) | ||
660 | #define NETXEN_NIU_AP_MII_MGMT_STATUS(I) (NETXEN_CRB_NIU+0xa0030+(I)*0x10000) | ||
661 | #define NETXEN_NIU_AP_MII_MGMT_INDICATE(I) (NETXEN_CRB_NIU+0xa0034+(I)*0x10000) | ||
662 | #define NETXEN_NIU_AP_INTERFACE_CTRL(I) (NETXEN_CRB_NIU+0xa0038+(I)*0x10000) | ||
663 | #define NETXEN_NIU_AP_INTERFACE_STATUS(I) (NETXEN_CRB_NIU+0xa003c+(I)*0x10000) | ||
664 | #define NETXEN_NIU_AP_STATION_ADDR_0(I) (NETXEN_CRB_NIU+0xa0040+(I)*0x10000) | ||
665 | #define NETXEN_NIU_AP_STATION_ADDR_1(I) (NETXEN_CRB_NIU+0xa0044+(I)*0x10000) | ||
666 | |||
667 | |||
668 | #define TEST_AGT_CTRL (0x00) | ||
669 | |||
670 | #define TA_CTL_START 1 | ||
671 | #define TA_CTL_ENABLE 2 | ||
672 | #define TA_CTL_WRITE 4 | ||
673 | #define TA_CTL_BUSY 8 | ||
674 | |||
675 | /* | ||
676 | * Register offsets for MN | ||
677 | */ | ||
678 | #define MIU_TEST_AGT_BASE (0x90) | ||
679 | |||
680 | #define MIU_TEST_AGT_ADDR_LO (0x04) | ||
681 | #define MIU_TEST_AGT_ADDR_HI (0x08) | ||
682 | #define MIU_TEST_AGT_WRDATA_LO (0x10) | ||
683 | #define MIU_TEST_AGT_WRDATA_HI (0x14) | ||
684 | #define MIU_TEST_AGT_RDDATA_LO (0x18) | ||
685 | #define MIU_TEST_AGT_RDDATA_HI (0x1c) | ||
686 | |||
687 | #define MIU_TEST_AGT_ADDR_MASK 0xfffffff8 | ||
688 | #define MIU_TEST_AGT_UPPER_ADDR(off) (0) | ||
689 | |||
690 | /* | ||
691 | * Register offsets for MS | ||
692 | */ | ||
693 | #define SIU_TEST_AGT_BASE (0x60) | ||
694 | |||
695 | #define SIU_TEST_AGT_ADDR_LO (0x04) | ||
696 | #define SIU_TEST_AGT_ADDR_HI (0x18) | ||
697 | #define SIU_TEST_AGT_WRDATA_LO (0x08) | ||
698 | #define SIU_TEST_AGT_WRDATA_HI (0x0c) | ||
699 | #define SIU_TEST_AGT_WRDATA(i) (0x08+(4*(i))) | ||
700 | #define SIU_TEST_AGT_RDDATA_LO (0x10) | ||
701 | #define SIU_TEST_AGT_RDDATA_HI (0x14) | ||
702 | #define SIU_TEST_AGT_RDDATA(i) (0x10+(4*(i))) | ||
703 | |||
704 | #define SIU_TEST_AGT_ADDR_MASK 0x3ffff8 | ||
705 | #define SIU_TEST_AGT_UPPER_ADDR(off) ((off)>>22) | ||
706 | |||
707 | /* XG Link status */ | ||
708 | #define XG_LINK_UP 0x10 | ||
709 | #define XG_LINK_DOWN 0x20 | ||
710 | |||
711 | #define XG_LINK_UP_P3 0x01 | ||
712 | #define XG_LINK_DOWN_P3 0x02 | ||
713 | #define XG_LINK_STATE_P3_MASK 0xf | ||
714 | #define XG_LINK_STATE_P3(pcifn,val) \ | ||
715 | (((val) >> ((pcifn) * 4)) & XG_LINK_STATE_P3_MASK) | ||
716 | |||
717 | #define P3_LINK_SPEED_MHZ 100 | ||
718 | #define P3_LINK_SPEED_MASK 0xff | ||
719 | #define P3_LINK_SPEED_REG(pcifn) \ | ||
720 | (CRB_PF_LINK_SPEED_1 + (((pcifn) / 4) * 4)) | ||
721 | #define P3_LINK_SPEED_VAL(pcifn, reg) \ | ||
722 | (((reg) >> (8 * ((pcifn) & 0x3))) & P3_LINK_SPEED_MASK) | ||
723 | |||
724 | #define NETXEN_CAM_RAM_BASE (NETXEN_CRB_CAM + 0x02000) | ||
725 | #define NETXEN_CAM_RAM(reg) (NETXEN_CAM_RAM_BASE + (reg)) | ||
726 | #define NETXEN_FW_VERSION_MAJOR (NETXEN_CAM_RAM(0x150)) | ||
727 | #define NETXEN_FW_VERSION_MINOR (NETXEN_CAM_RAM(0x154)) | ||
728 | #define NETXEN_FW_VERSION_SUB (NETXEN_CAM_RAM(0x158)) | ||
729 | #define NETXEN_ROM_LOCK_ID (NETXEN_CAM_RAM(0x100)) | ||
730 | #define NETXEN_PHY_LOCK_ID (NETXEN_CAM_RAM(0x120)) | ||
731 | #define NETXEN_CRB_WIN_LOCK_ID (NETXEN_CAM_RAM(0x124)) | ||
732 | |||
733 | #define NIC_CRB_BASE (NETXEN_CAM_RAM(0x200)) | ||
734 | #define NIC_CRB_BASE_2 (NETXEN_CAM_RAM(0x700)) | ||
735 | #define NETXEN_NIC_REG(X) (NIC_CRB_BASE+(X)) | ||
736 | #define NETXEN_NIC_REG_2(X) (NIC_CRB_BASE_2+(X)) | ||
737 | |||
738 | #define NX_CDRP_CRB_OFFSET (NETXEN_NIC_REG(0x18)) | ||
739 | #define NX_ARG1_CRB_OFFSET (NETXEN_NIC_REG(0x1c)) | ||
740 | #define NX_ARG2_CRB_OFFSET (NETXEN_NIC_REG(0x20)) | ||
741 | #define NX_ARG3_CRB_OFFSET (NETXEN_NIC_REG(0x24)) | ||
742 | #define NX_SIGN_CRB_OFFSET (NETXEN_NIC_REG(0x28)) | ||
743 | |||
744 | #define CRB_HOST_DUMMY_BUF_ADDR_HI (NETXEN_NIC_REG(0x3c)) | ||
745 | #define CRB_HOST_DUMMY_BUF_ADDR_LO (NETXEN_NIC_REG(0x40)) | ||
746 | |||
747 | #define CRB_CMDPEG_STATE (NETXEN_NIC_REG(0x50)) | ||
748 | #define CRB_RCVPEG_STATE (NETXEN_NIC_REG(0x13c)) | ||
749 | |||
750 | #define CRB_XG_STATE (NETXEN_NIC_REG(0x94)) | ||
751 | #define CRB_XG_STATE_P3 (NETXEN_NIC_REG(0x98)) | ||
752 | #define CRB_PF_LINK_SPEED_1 (NETXEN_NIC_REG(0xe8)) | ||
753 | #define CRB_PF_LINK_SPEED_2 (NETXEN_NIC_REG(0xec)) | ||
754 | |||
755 | #define CRB_MPORT_MODE (NETXEN_NIC_REG(0xc4)) | ||
756 | #define CRB_DMA_SHIFT (NETXEN_NIC_REG(0xcc)) | ||
757 | #define CRB_INT_VECTOR (NETXEN_NIC_REG(0xd4)) | ||
758 | |||
759 | #define CRB_CMD_PRODUCER_OFFSET (NETXEN_NIC_REG(0x08)) | ||
760 | #define CRB_CMD_CONSUMER_OFFSET (NETXEN_NIC_REG(0x0c)) | ||
761 | #define CRB_CMD_PRODUCER_OFFSET_1 (NETXEN_NIC_REG(0x1ac)) | ||
762 | #define CRB_CMD_CONSUMER_OFFSET_1 (NETXEN_NIC_REG(0x1b0)) | ||
763 | #define CRB_CMD_PRODUCER_OFFSET_2 (NETXEN_NIC_REG(0x1b8)) | ||
764 | #define CRB_CMD_CONSUMER_OFFSET_2 (NETXEN_NIC_REG(0x1bc)) | ||
765 | #define CRB_CMD_PRODUCER_OFFSET_3 (NETXEN_NIC_REG(0x1d0)) | ||
766 | #define CRB_CMD_CONSUMER_OFFSET_3 (NETXEN_NIC_REG(0x1d4)) | ||
767 | #define CRB_TEMP_STATE (NETXEN_NIC_REG(0x1b4)) | ||
768 | |||
769 | #define CRB_V2P_0 (NETXEN_NIC_REG(0x290)) | ||
770 | #define CRB_V2P(port) (CRB_V2P_0+((port)*4)) | ||
771 | #define CRB_DRIVER_VERSION (NETXEN_NIC_REG(0x2a0)) | ||
772 | |||
773 | #define CRB_SW_INT_MASK_0 (NETXEN_NIC_REG(0x1d8)) | ||
774 | #define CRB_SW_INT_MASK_1 (NETXEN_NIC_REG(0x1e0)) | ||
775 | #define CRB_SW_INT_MASK_2 (NETXEN_NIC_REG(0x1e4)) | ||
776 | #define CRB_SW_INT_MASK_3 (NETXEN_NIC_REG(0x1e8)) | ||
777 | |||
778 | #define CRB_FW_CAPABILITIES_1 (NETXEN_CAM_RAM(0x128)) | ||
779 | #define CRB_MAC_BLOCK_START (NETXEN_CAM_RAM(0x1c0)) | ||
780 | |||
781 | /* | ||
782 | * capabilities register, can be used to selectively enable/disable features | ||
783 | * for backward compatibility | ||
784 | */ | ||
785 | #define CRB_NIC_CAPABILITIES_HOST NETXEN_NIC_REG(0x1a8) | ||
786 | #define CRB_NIC_MSI_MODE_HOST NETXEN_NIC_REG(0x270) | ||
787 | |||
788 | #define INTR_SCHEME_PERPORT 0x1 | ||
789 | #define MSI_MODE_MULTIFUNC 0x1 | ||
790 | |||
791 | /* used for ethtool tests */ | ||
792 | #define CRB_SCRATCHPAD_TEST NETXEN_NIC_REG(0x280) | ||
793 | |||
794 | /* | ||
795 | * CrbPortPhanCntrHi/Lo is used to pass the address of HostPhantomIndex address | ||
796 | * which can be read by the Phantom host to get producer/consumer indexes from | ||
797 | * Phantom/Casper. If it is not HOST_SHARED_MEMORY, then the following | ||
798 | * registers will be used for the addresses of the ring's shared memory | ||
799 | * on the Phantom. | ||
800 | */ | ||
801 | |||
802 | #define nx_get_temp_val(x) ((x) >> 16) | ||
803 | #define nx_get_temp_state(x) ((x) & 0xffff) | ||
804 | #define nx_encode_temp(val, state) (((val) << 16) | (state)) | ||
805 | |||
806 | /* | ||
807 | * Temperature control. | ||
808 | */ | ||
809 | enum { | ||
810 | NX_TEMP_NORMAL = 0x1, /* Normal operating range */ | ||
811 | NX_TEMP_WARN, /* Sound alert, temperature getting high */ | ||
812 | NX_TEMP_PANIC /* Fatal error, hardware has shut down. */ | ||
813 | }; | ||
814 | |||
815 | /* Lock IDs for PHY lock */ | ||
816 | #define PHY_LOCK_DRIVER 0x44524956 | ||
817 | |||
818 | /* Used for PS PCI Memory access */ | ||
819 | #define PCIX_PS_OP_ADDR_LO (0x10000) | ||
820 | /* via CRB (PS side only) */ | ||
821 | #define PCIX_PS_OP_ADDR_HI (0x10004) | ||
822 | |||
823 | #define PCIX_INT_VECTOR (0x10100) | ||
824 | #define PCIX_INT_MASK (0x10104) | ||
825 | |||
826 | #define PCIX_CRB_WINDOW (0x10210) | ||
827 | #define PCIX_CRB_WINDOW_F0 (0x10210) | ||
828 | #define PCIX_CRB_WINDOW_F1 (0x10230) | ||
829 | #define PCIX_CRB_WINDOW_F2 (0x10250) | ||
830 | #define PCIX_CRB_WINDOW_F3 (0x10270) | ||
831 | #define PCIX_CRB_WINDOW_F4 (0x102ac) | ||
832 | #define PCIX_CRB_WINDOW_F5 (0x102bc) | ||
833 | #define PCIX_CRB_WINDOW_F6 (0x102cc) | ||
834 | #define PCIX_CRB_WINDOW_F7 (0x102dc) | ||
835 | #define PCIE_CRB_WINDOW_REG(func) (((func) < 4) ? \ | ||
836 | (PCIX_CRB_WINDOW_F0 + (0x20 * (func))) :\ | ||
837 | (PCIX_CRB_WINDOW_F4 + (0x10 * ((func)-4)))) | ||
838 | |||
839 | #define PCIX_MN_WINDOW (0x10200) | ||
840 | #define PCIX_MN_WINDOW_F0 (0x10200) | ||
841 | #define PCIX_MN_WINDOW_F1 (0x10220) | ||
842 | #define PCIX_MN_WINDOW_F2 (0x10240) | ||
843 | #define PCIX_MN_WINDOW_F3 (0x10260) | ||
844 | #define PCIX_MN_WINDOW_F4 (0x102a0) | ||
845 | #define PCIX_MN_WINDOW_F5 (0x102b0) | ||
846 | #define PCIX_MN_WINDOW_F6 (0x102c0) | ||
847 | #define PCIX_MN_WINDOW_F7 (0x102d0) | ||
848 | #define PCIE_MN_WINDOW_REG(func) (((func) < 4) ? \ | ||
849 | (PCIX_MN_WINDOW_F0 + (0x20 * (func))) :\ | ||
850 | (PCIX_MN_WINDOW_F4 + (0x10 * ((func)-4)))) | ||
851 | |||
852 | #define PCIX_SN_WINDOW (0x10208) | ||
853 | #define PCIX_SN_WINDOW_F0 (0x10208) | ||
854 | #define PCIX_SN_WINDOW_F1 (0x10228) | ||
855 | #define PCIX_SN_WINDOW_F2 (0x10248) | ||
856 | #define PCIX_SN_WINDOW_F3 (0x10268) | ||
857 | #define PCIX_SN_WINDOW_F4 (0x102a8) | ||
858 | #define PCIX_SN_WINDOW_F5 (0x102b8) | ||
859 | #define PCIX_SN_WINDOW_F6 (0x102c8) | ||
860 | #define PCIX_SN_WINDOW_F7 (0x102d8) | ||
861 | #define PCIE_SN_WINDOW_REG(func) (((func) < 4) ? \ | ||
862 | (PCIX_SN_WINDOW_F0 + (0x20 * (func))) :\ | ||
863 | (PCIX_SN_WINDOW_F4 + (0x10 * ((func)-4)))) | ||
864 | |||
865 | #define PCIX_OCM_WINDOW (0x10800) | ||
866 | #define PCIX_OCM_WINDOW_REG(func) (PCIX_OCM_WINDOW + 0x20 * (func)) | ||
867 | |||
868 | #define PCIX_TARGET_STATUS (0x10118) | ||
869 | #define PCIX_TARGET_STATUS_F1 (0x10160) | ||
870 | #define PCIX_TARGET_STATUS_F2 (0x10164) | ||
871 | #define PCIX_TARGET_STATUS_F3 (0x10168) | ||
872 | #define PCIX_TARGET_STATUS_F4 (0x10360) | ||
873 | #define PCIX_TARGET_STATUS_F5 (0x10364) | ||
874 | #define PCIX_TARGET_STATUS_F6 (0x10368) | ||
875 | #define PCIX_TARGET_STATUS_F7 (0x1036c) | ||
876 | |||
877 | #define PCIX_TARGET_MASK (0x10128) | ||
878 | #define PCIX_TARGET_MASK_F1 (0x10170) | ||
879 | #define PCIX_TARGET_MASK_F2 (0x10174) | ||
880 | #define PCIX_TARGET_MASK_F3 (0x10178) | ||
881 | #define PCIX_TARGET_MASK_F4 (0x10370) | ||
882 | #define PCIX_TARGET_MASK_F5 (0x10374) | ||
883 | #define PCIX_TARGET_MASK_F6 (0x10378) | ||
884 | #define PCIX_TARGET_MASK_F7 (0x1037c) | ||
885 | |||
886 | #define PCIX_MSI_F0 (0x13000) | ||
887 | #define PCIX_MSI_F1 (0x13004) | ||
888 | #define PCIX_MSI_F2 (0x13008) | ||
889 | #define PCIX_MSI_F3 (0x1300c) | ||
890 | #define PCIX_MSI_F4 (0x13010) | ||
891 | #define PCIX_MSI_F5 (0x13014) | ||
892 | #define PCIX_MSI_F6 (0x13018) | ||
893 | #define PCIX_MSI_F7 (0x1301c) | ||
894 | #define PCIX_MSI_F(i) (0x13000+((i)*4)) | ||
895 | |||
896 | #define PCIX_PS_MEM_SPACE (0x90000) | ||
897 | |||
898 | #define NETXEN_PCIX_PH_REG(reg) (NETXEN_CRB_PCIE + (reg)) | ||
899 | #define NETXEN_PCIX_PS_REG(reg) (NETXEN_CRB_PCIX_MD + (reg)) | ||
900 | |||
901 | #define NETXEN_PCIE_REG(reg) (NETXEN_CRB_PCIE + (reg)) | ||
902 | |||
903 | #define PCIE_MAX_DMA_XFER_SIZE (0x1404c) | ||
904 | |||
905 | #define PCIE_DCR 0x00d8 | ||
906 | |||
907 | #define PCIE_SEM0_LOCK (0x1c000) | ||
908 | #define PCIE_SEM0_UNLOCK (0x1c004) | ||
909 | #define PCIE_SEM1_LOCK (0x1c008) | ||
910 | #define PCIE_SEM1_UNLOCK (0x1c00c) | ||
911 | #define PCIE_SEM2_LOCK (0x1c010) /* Flash lock */ | ||
912 | #define PCIE_SEM2_UNLOCK (0x1c014) /* Flash unlock */ | ||
913 | #define PCIE_SEM3_LOCK (0x1c018) /* Phy lock */ | ||
914 | #define PCIE_SEM3_UNLOCK (0x1c01c) /* Phy unlock */ | ||
915 | #define PCIE_SEM4_LOCK (0x1c020) | ||
916 | #define PCIE_SEM4_UNLOCK (0x1c024) | ||
917 | #define PCIE_SEM5_LOCK (0x1c028) /* API lock */ | ||
918 | #define PCIE_SEM5_UNLOCK (0x1c02c) /* API unlock */ | ||
919 | #define PCIE_SEM6_LOCK (0x1c030) /* sw lock */ | ||
920 | #define PCIE_SEM6_UNLOCK (0x1c034) /* sw unlock */ | ||
921 | #define PCIE_SEM7_LOCK (0x1c038) /* crb win lock */ | ||
922 | #define PCIE_SEM7_UNLOCK (0x1c03c) /* crbwin unlock*/ | ||
923 | #define PCIE_SEM_LOCK(N) (PCIE_SEM0_LOCK + 8*(N)) | ||
924 | #define PCIE_SEM_UNLOCK(N) (PCIE_SEM0_UNLOCK + 8*(N)) | ||
925 | |||
926 | #define PCIE_SETUP_FUNCTION (0x12040) | ||
927 | #define PCIE_SETUP_FUNCTION2 (0x12048) | ||
928 | #define PCIE_MISCCFG_RC (0x1206c) | ||
929 | #define PCIE_TGT_SPLIT_CHICKEN (0x12080) | ||
930 | #define PCIE_CHICKEN3 (0x120c8) | ||
931 | |||
932 | #define ISR_INT_STATE_REG (NETXEN_PCIX_PS_REG(PCIE_MISCCFG_RC)) | ||
933 | #define PCIE_MAX_MASTER_SPLIT (0x14048) | ||
934 | |||
935 | #define NETXEN_PORT_MODE_NONE 0 | ||
936 | #define NETXEN_PORT_MODE_XG 1 | ||
937 | #define NETXEN_PORT_MODE_GB 2 | ||
938 | #define NETXEN_PORT_MODE_802_3_AP 3 | ||
939 | #define NETXEN_PORT_MODE_AUTO_NEG 4 | ||
940 | #define NETXEN_PORT_MODE_AUTO_NEG_1G 5 | ||
941 | #define NETXEN_PORT_MODE_AUTO_NEG_XG 6 | ||
942 | #define NETXEN_PORT_MODE_ADDR (NETXEN_CAM_RAM(0x24)) | ||
943 | #define NETXEN_WOL_PORT_MODE (NETXEN_CAM_RAM(0x198)) | ||
944 | |||
945 | #define NETXEN_WOL_CONFIG_NV (NETXEN_CAM_RAM(0x184)) | ||
946 | #define NETXEN_WOL_CONFIG (NETXEN_CAM_RAM(0x188)) | ||
947 | |||
948 | #define NX_PEG_TUNE_MN_PRESENT 0x1 | ||
949 | #define NX_PEG_TUNE_CAPABILITY (NETXEN_CAM_RAM(0x02c)) | ||
950 | |||
951 | #define NETXEN_DMA_WATCHDOG_CTRL (NETXEN_CAM_RAM(0x14)) | ||
952 | #define NETXEN_PEG_ALIVE_COUNTER (NETXEN_CAM_RAM(0xb0)) | ||
953 | #define NETXEN_PEG_HALT_STATUS1 (NETXEN_CAM_RAM(0xa8)) | ||
954 | #define NETXEN_PEG_HALT_STATUS2 (NETXEN_CAM_RAM(0xac)) | ||
955 | #define NX_CRB_DEV_REF_COUNT (NETXEN_CAM_RAM(0x138)) | ||
956 | #define NX_CRB_DEV_STATE (NETXEN_CAM_RAM(0x140)) | ||
957 | |||
958 | /* Device State */ | ||
959 | #define NX_DEV_COLD 1 | ||
960 | #define NX_DEV_INITALIZING 2 | ||
961 | #define NX_DEV_READY 3 | ||
962 | #define NX_DEV_NEED_RESET 4 | ||
963 | #define NX_DEV_NEED_QUISCENT 5 | ||
964 | #define NX_DEV_NEED_AER 6 | ||
965 | #define NX_DEV_FAILED 7 | ||
966 | |||
967 | #define NX_RCODE_DRIVER_INFO 0x20000000 | ||
968 | #define NX_RCODE_DRIVER_CAN_RELOAD 0x40000000 | ||
969 | #define NX_RCODE_FATAL_ERROR 0x80000000 | ||
970 | #define NX_FWERROR_PEGNUM(code) ((code) & 0xff) | ||
971 | #define NX_FWERROR_CODE(code) ((code >> 8) & 0xfffff) | ||
972 | |||
973 | #define FW_POLL_DELAY (2 * HZ) | ||
974 | #define FW_FAIL_THRESH 3 | ||
975 | #define FW_POLL_THRESH 10 | ||
976 | |||
977 | #define ISR_MSI_INT_TRIGGER(FUNC) (NETXEN_PCIX_PS_REG(PCIX_MSI_F(FUNC))) | ||
978 | #define ISR_LEGACY_INT_TRIGGERED(VAL) (((VAL) & 0x300) == 0x200) | ||
979 | |||
980 | /* | ||
981 | * PCI Interrupt Vector Values. | ||
982 | */ | ||
983 | #define PCIX_INT_VECTOR_BIT_F0 0x0080 | ||
984 | #define PCIX_INT_VECTOR_BIT_F1 0x0100 | ||
985 | #define PCIX_INT_VECTOR_BIT_F2 0x0200 | ||
986 | #define PCIX_INT_VECTOR_BIT_F3 0x0400 | ||
987 | #define PCIX_INT_VECTOR_BIT_F4 0x0800 | ||
988 | #define PCIX_INT_VECTOR_BIT_F5 0x1000 | ||
989 | #define PCIX_INT_VECTOR_BIT_F6 0x2000 | ||
990 | #define PCIX_INT_VECTOR_BIT_F7 0x4000 | ||
991 | |||
992 | struct netxen_legacy_intr_set { | ||
993 | uint32_t int_vec_bit; | ||
994 | uint32_t tgt_status_reg; | ||
995 | uint32_t tgt_mask_reg; | ||
996 | uint32_t pci_int_reg; | ||
997 | }; | ||
998 | |||
999 | #define NX_LEGACY_INTR_CONFIG \ | ||
1000 | { \ | ||
1001 | { \ | ||
1002 | .int_vec_bit = PCIX_INT_VECTOR_BIT_F0, \ | ||
1003 | .tgt_status_reg = ISR_INT_TARGET_STATUS, \ | ||
1004 | .tgt_mask_reg = ISR_INT_TARGET_MASK, \ | ||
1005 | .pci_int_reg = ISR_MSI_INT_TRIGGER(0) }, \ | ||
1006 | \ | ||
1007 | { \ | ||
1008 | .int_vec_bit = PCIX_INT_VECTOR_BIT_F1, \ | ||
1009 | .tgt_status_reg = ISR_INT_TARGET_STATUS_F1, \ | ||
1010 | .tgt_mask_reg = ISR_INT_TARGET_MASK_F1, \ | ||
1011 | .pci_int_reg = ISR_MSI_INT_TRIGGER(1) }, \ | ||
1012 | \ | ||
1013 | { \ | ||
1014 | .int_vec_bit = PCIX_INT_VECTOR_BIT_F2, \ | ||
1015 | .tgt_status_reg = ISR_INT_TARGET_STATUS_F2, \ | ||
1016 | .tgt_mask_reg = ISR_INT_TARGET_MASK_F2, \ | ||
1017 | .pci_int_reg = ISR_MSI_INT_TRIGGER(2) }, \ | ||
1018 | \ | ||
1019 | { \ | ||
1020 | .int_vec_bit = PCIX_INT_VECTOR_BIT_F3, \ | ||
1021 | .tgt_status_reg = ISR_INT_TARGET_STATUS_F3, \ | ||
1022 | .tgt_mask_reg = ISR_INT_TARGET_MASK_F3, \ | ||
1023 | .pci_int_reg = ISR_MSI_INT_TRIGGER(3) }, \ | ||
1024 | \ | ||
1025 | { \ | ||
1026 | .int_vec_bit = PCIX_INT_VECTOR_BIT_F4, \ | ||
1027 | .tgt_status_reg = ISR_INT_TARGET_STATUS_F4, \ | ||
1028 | .tgt_mask_reg = ISR_INT_TARGET_MASK_F4, \ | ||
1029 | .pci_int_reg = ISR_MSI_INT_TRIGGER(4) }, \ | ||
1030 | \ | ||
1031 | { \ | ||
1032 | .int_vec_bit = PCIX_INT_VECTOR_BIT_F5, \ | ||
1033 | .tgt_status_reg = ISR_INT_TARGET_STATUS_F5, \ | ||
1034 | .tgt_mask_reg = ISR_INT_TARGET_MASK_F5, \ | ||
1035 | .pci_int_reg = ISR_MSI_INT_TRIGGER(5) }, \ | ||
1036 | \ | ||
1037 | { \ | ||
1038 | .int_vec_bit = PCIX_INT_VECTOR_BIT_F6, \ | ||
1039 | .tgt_status_reg = ISR_INT_TARGET_STATUS_F6, \ | ||
1040 | .tgt_mask_reg = ISR_INT_TARGET_MASK_F6, \ | ||
1041 | .pci_int_reg = ISR_MSI_INT_TRIGGER(6) }, \ | ||
1042 | \ | ||
1043 | { \ | ||
1044 | .int_vec_bit = PCIX_INT_VECTOR_BIT_F7, \ | ||
1045 | .tgt_status_reg = ISR_INT_TARGET_STATUS_F7, \ | ||
1046 | .tgt_mask_reg = ISR_INT_TARGET_MASK_F7, \ | ||
1047 | .pci_int_reg = ISR_MSI_INT_TRIGGER(7) }, \ | ||
1048 | } | ||
1049 | |||
1050 | #endif /* __NETXEN_NIC_HDR_H_ */ | ||
diff --git a/drivers/net/ethernet/qlogic/netxen/netxen_nic_hw.c b/drivers/net/ethernet/qlogic/netxen/netxen_nic_hw.c new file mode 100644 index 000000000000..3f89e57cae50 --- /dev/null +++ b/drivers/net/ethernet/qlogic/netxen/netxen_nic_hw.c | |||
@@ -0,0 +1,1976 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2003 - 2009 NetXen, Inc. | ||
3 | * Copyright (C) 2009 - QLogic Corporation. | ||
4 | * All rights reserved. | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or | ||
7 | * modify it under the terms of the GNU General Public License | ||
8 | * as published by the Free Software Foundation; either version 2 | ||
9 | * of the License, or (at your option) any later version. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, but | ||
12 | * 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, | ||
19 | * MA 02111-1307, USA. | ||
20 | * | ||
21 | * The full GNU General Public License is included in this distribution | ||
22 | * in the file called "COPYING". | ||
23 | * | ||
24 | */ | ||
25 | |||
26 | #include <linux/slab.h> | ||
27 | #include "netxen_nic.h" | ||
28 | #include "netxen_nic_hw.h" | ||
29 | |||
30 | #include <net/ip.h> | ||
31 | |||
32 | #define MASK(n) ((1ULL<<(n))-1) | ||
33 | #define MN_WIN(addr) (((addr & 0x1fc0000) >> 1) | ((addr >> 25) & 0x3ff)) | ||
34 | #define OCM_WIN(addr) (((addr & 0x1ff0000) >> 1) | ((addr >> 25) & 0x3ff)) | ||
35 | #define MS_WIN(addr) (addr & 0x0ffc0000) | ||
36 | |||
37 | #define GET_MEM_OFFS_2M(addr) (addr & MASK(18)) | ||
38 | |||
39 | #define CRB_BLK(off) ((off >> 20) & 0x3f) | ||
40 | #define CRB_SUBBLK(off) ((off >> 16) & 0xf) | ||
41 | #define CRB_WINDOW_2M (0x130060) | ||
42 | #define CRB_HI(off) ((crb_hub_agt[CRB_BLK(off)] << 20) | ((off) & 0xf0000)) | ||
43 | #define CRB_INDIRECT_2M (0x1e0000UL) | ||
44 | |||
45 | static void netxen_nic_io_write_128M(struct netxen_adapter *adapter, | ||
46 | void __iomem *addr, u32 data); | ||
47 | static u32 netxen_nic_io_read_128M(struct netxen_adapter *adapter, | ||
48 | void __iomem *addr); | ||
49 | |||
50 | #ifndef readq | ||
51 | static inline u64 readq(void __iomem *addr) | ||
52 | { | ||
53 | return readl(addr) | (((u64) readl(addr + 4)) << 32LL); | ||
54 | } | ||
55 | #endif | ||
56 | |||
57 | #ifndef writeq | ||
58 | static inline void writeq(u64 val, void __iomem *addr) | ||
59 | { | ||
60 | writel(((u32) (val)), (addr)); | ||
61 | writel(((u32) (val >> 32)), (addr + 4)); | ||
62 | } | ||
63 | #endif | ||
64 | |||
65 | #define PCI_OFFSET_FIRST_RANGE(adapter, off) \ | ||
66 | ((adapter)->ahw.pci_base0 + (off)) | ||
67 | #define PCI_OFFSET_SECOND_RANGE(adapter, off) \ | ||
68 | ((adapter)->ahw.pci_base1 + (off) - SECOND_PAGE_GROUP_START) | ||
69 | #define PCI_OFFSET_THIRD_RANGE(adapter, off) \ | ||
70 | ((adapter)->ahw.pci_base2 + (off) - THIRD_PAGE_GROUP_START) | ||
71 | |||
72 | static void __iomem *pci_base_offset(struct netxen_adapter *adapter, | ||
73 | unsigned long off) | ||
74 | { | ||
75 | if (ADDR_IN_RANGE(off, FIRST_PAGE_GROUP_START, FIRST_PAGE_GROUP_END)) | ||
76 | return PCI_OFFSET_FIRST_RANGE(adapter, off); | ||
77 | |||
78 | if (ADDR_IN_RANGE(off, SECOND_PAGE_GROUP_START, SECOND_PAGE_GROUP_END)) | ||
79 | return PCI_OFFSET_SECOND_RANGE(adapter, off); | ||
80 | |||
81 | if (ADDR_IN_RANGE(off, THIRD_PAGE_GROUP_START, THIRD_PAGE_GROUP_END)) | ||
82 | return PCI_OFFSET_THIRD_RANGE(adapter, off); | ||
83 | |||
84 | return NULL; | ||
85 | } | ||
86 | |||
87 | static crb_128M_2M_block_map_t | ||
88 | crb_128M_2M_map[64] __cacheline_aligned_in_smp = { | ||
89 | {{{0, 0, 0, 0} } }, /* 0: PCI */ | ||
90 | {{{1, 0x0100000, 0x0102000, 0x120000}, /* 1: PCIE */ | ||
91 | {1, 0x0110000, 0x0120000, 0x130000}, | ||
92 | {1, 0x0120000, 0x0122000, 0x124000}, | ||
93 | {1, 0x0130000, 0x0132000, 0x126000}, | ||
94 | {1, 0x0140000, 0x0142000, 0x128000}, | ||
95 | {1, 0x0150000, 0x0152000, 0x12a000}, | ||
96 | {1, 0x0160000, 0x0170000, 0x110000}, | ||
97 | {1, 0x0170000, 0x0172000, 0x12e000}, | ||
98 | {0, 0x0000000, 0x0000000, 0x000000}, | ||
99 | {0, 0x0000000, 0x0000000, 0x000000}, | ||
100 | {0, 0x0000000, 0x0000000, 0x000000}, | ||
101 | {0, 0x0000000, 0x0000000, 0x000000}, | ||
102 | {0, 0x0000000, 0x0000000, 0x000000}, | ||
103 | {0, 0x0000000, 0x0000000, 0x000000}, | ||
104 | {1, 0x01e0000, 0x01e0800, 0x122000}, | ||
105 | {0, 0x0000000, 0x0000000, 0x000000} } }, | ||
106 | {{{1, 0x0200000, 0x0210000, 0x180000} } },/* 2: MN */ | ||
107 | {{{0, 0, 0, 0} } }, /* 3: */ | ||
108 | {{{1, 0x0400000, 0x0401000, 0x169000} } },/* 4: P2NR1 */ | ||
109 | {{{1, 0x0500000, 0x0510000, 0x140000} } },/* 5: SRE */ | ||
110 | {{{1, 0x0600000, 0x0610000, 0x1c0000} } },/* 6: NIU */ | ||
111 | {{{1, 0x0700000, 0x0704000, 0x1b8000} } },/* 7: QM */ | ||
112 | {{{1, 0x0800000, 0x0802000, 0x170000}, /* 8: SQM0 */ | ||
113 | {0, 0x0000000, 0x0000000, 0x000000}, | ||
114 | {0, 0x0000000, 0x0000000, 0x000000}, | ||
115 | {0, 0x0000000, 0x0000000, 0x000000}, | ||
116 | {0, 0x0000000, 0x0000000, 0x000000}, | ||
117 | {0, 0x0000000, 0x0000000, 0x000000}, | ||
118 | {0, 0x0000000, 0x0000000, 0x000000}, | ||
119 | {0, 0x0000000, 0x0000000, 0x000000}, | ||
120 | {0, 0x0000000, 0x0000000, 0x000000}, | ||
121 | {0, 0x0000000, 0x0000000, 0x000000}, | ||
122 | {0, 0x0000000, 0x0000000, 0x000000}, | ||
123 | {0, 0x0000000, 0x0000000, 0x000000}, | ||
124 | {0, 0x0000000, 0x0000000, 0x000000}, | ||
125 | {0, 0x0000000, 0x0000000, 0x000000}, | ||
126 | {0, 0x0000000, 0x0000000, 0x000000}, | ||
127 | {1, 0x08f0000, 0x08f2000, 0x172000} } }, | ||
128 | {{{1, 0x0900000, 0x0902000, 0x174000}, /* 9: SQM1*/ | ||
129 | {0, 0x0000000, 0x0000000, 0x000000}, | ||
130 | {0, 0x0000000, 0x0000000, 0x000000}, | ||
131 | {0, 0x0000000, 0x0000000, 0x000000}, | ||
132 | {0, 0x0000000, 0x0000000, 0x000000}, | ||
133 | {0, 0x0000000, 0x0000000, 0x000000}, | ||
134 | {0, 0x0000000, 0x0000000, 0x000000}, | ||
135 | {0, 0x0000000, 0x0000000, 0x000000}, | ||
136 | {0, 0x0000000, 0x0000000, 0x000000}, | ||
137 | {0, 0x0000000, 0x0000000, 0x000000}, | ||
138 | {0, 0x0000000, 0x0000000, 0x000000}, | ||
139 | {0, 0x0000000, 0x0000000, 0x000000}, | ||
140 | {0, 0x0000000, 0x0000000, 0x000000}, | ||
141 | {0, 0x0000000, 0x0000000, 0x000000}, | ||
142 | {0, 0x0000000, 0x0000000, 0x000000}, | ||
143 | {1, 0x09f0000, 0x09f2000, 0x176000} } }, | ||
144 | {{{0, 0x0a00000, 0x0a02000, 0x178000}, /* 10: SQM2*/ | ||
145 | {0, 0x0000000, 0x0000000, 0x000000}, | ||
146 | {0, 0x0000000, 0x0000000, 0x000000}, | ||
147 | {0, 0x0000000, 0x0000000, 0x000000}, | ||
148 | {0, 0x0000000, 0x0000000, 0x000000}, | ||
149 | {0, 0x0000000, 0x0000000, 0x000000}, | ||
150 | {0, 0x0000000, 0x0000000, 0x000000}, | ||
151 | {0, 0x0000000, 0x0000000, 0x000000}, | ||
152 | {0, 0x0000000, 0x0000000, 0x000000}, | ||
153 | {0, 0x0000000, 0x0000000, 0x000000}, | ||
154 | {0, 0x0000000, 0x0000000, 0x000000}, | ||
155 | {0, 0x0000000, 0x0000000, 0x000000}, | ||
156 | {0, 0x0000000, 0x0000000, 0x000000}, | ||
157 | {0, 0x0000000, 0x0000000, 0x000000}, | ||
158 | {0, 0x0000000, 0x0000000, 0x000000}, | ||
159 | {1, 0x0af0000, 0x0af2000, 0x17a000} } }, | ||
160 | {{{0, 0x0b00000, 0x0b02000, 0x17c000}, /* 11: SQM3*/ | ||
161 | {0, 0x0000000, 0x0000000, 0x000000}, | ||
162 | {0, 0x0000000, 0x0000000, 0x000000}, | ||
163 | {0, 0x0000000, 0x0000000, 0x000000}, | ||
164 | {0, 0x0000000, 0x0000000, 0x000000}, | ||
165 | {0, 0x0000000, 0x0000000, 0x000000}, | ||
166 | {0, 0x0000000, 0x0000000, 0x000000}, | ||
167 | {0, 0x0000000, 0x0000000, 0x000000}, | ||
168 | {0, 0x0000000, 0x0000000, 0x000000}, | ||
169 | {0, 0x0000000, 0x0000000, 0x000000}, | ||
170 | {0, 0x0000000, 0x0000000, 0x000000}, | ||
171 | {0, 0x0000000, 0x0000000, 0x000000}, | ||
172 | {0, 0x0000000, 0x0000000, 0x000000}, | ||
173 | {0, 0x0000000, 0x0000000, 0x000000}, | ||
174 | {0, 0x0000000, 0x0000000, 0x000000}, | ||
175 | {1, 0x0bf0000, 0x0bf2000, 0x17e000} } }, | ||
176 | {{{1, 0x0c00000, 0x0c04000, 0x1d4000} } },/* 12: I2Q */ | ||
177 | {{{1, 0x0d00000, 0x0d04000, 0x1a4000} } },/* 13: TMR */ | ||
178 | {{{1, 0x0e00000, 0x0e04000, 0x1a0000} } },/* 14: ROMUSB */ | ||
179 | {{{1, 0x0f00000, 0x0f01000, 0x164000} } },/* 15: PEG4 */ | ||
180 | {{{0, 0x1000000, 0x1004000, 0x1a8000} } },/* 16: XDMA */ | ||
181 | {{{1, 0x1100000, 0x1101000, 0x160000} } },/* 17: PEG0 */ | ||
182 | {{{1, 0x1200000, 0x1201000, 0x161000} } },/* 18: PEG1 */ | ||
183 | {{{1, 0x1300000, 0x1301000, 0x162000} } },/* 19: PEG2 */ | ||
184 | {{{1, 0x1400000, 0x1401000, 0x163000} } },/* 20: PEG3 */ | ||
185 | {{{1, 0x1500000, 0x1501000, 0x165000} } },/* 21: P2ND */ | ||
186 | {{{1, 0x1600000, 0x1601000, 0x166000} } },/* 22: P2NI */ | ||
187 | {{{0, 0, 0, 0} } }, /* 23: */ | ||
188 | {{{0, 0, 0, 0} } }, /* 24: */ | ||
189 | {{{0, 0, 0, 0} } }, /* 25: */ | ||
190 | {{{0, 0, 0, 0} } }, /* 26: */ | ||
191 | {{{0, 0, 0, 0} } }, /* 27: */ | ||
192 | {{{0, 0, 0, 0} } }, /* 28: */ | ||
193 | {{{1, 0x1d00000, 0x1d10000, 0x190000} } },/* 29: MS */ | ||
194 | {{{1, 0x1e00000, 0x1e01000, 0x16a000} } },/* 30: P2NR2 */ | ||
195 | {{{1, 0x1f00000, 0x1f10000, 0x150000} } },/* 31: EPG */ | ||
196 | {{{0} } }, /* 32: PCI */ | ||
197 | {{{1, 0x2100000, 0x2102000, 0x120000}, /* 33: PCIE */ | ||
198 | {1, 0x2110000, 0x2120000, 0x130000}, | ||
199 | {1, 0x2120000, 0x2122000, 0x124000}, | ||
200 | {1, 0x2130000, 0x2132000, 0x126000}, | ||
201 | {1, 0x2140000, 0x2142000, 0x128000}, | ||
202 | {1, 0x2150000, 0x2152000, 0x12a000}, | ||
203 | {1, 0x2160000, 0x2170000, 0x110000}, | ||
204 | {1, 0x2170000, 0x2172000, 0x12e000}, | ||
205 | {0, 0x0000000, 0x0000000, 0x000000}, | ||
206 | {0, 0x0000000, 0x0000000, 0x000000}, | ||
207 | {0, 0x0000000, 0x0000000, 0x000000}, | ||
208 | {0, 0x0000000, 0x0000000, 0x000000}, | ||
209 | {0, 0x0000000, 0x0000000, 0x000000}, | ||
210 | {0, 0x0000000, 0x0000000, 0x000000}, | ||
211 | {0, 0x0000000, 0x0000000, 0x000000}, | ||
212 | {0, 0x0000000, 0x0000000, 0x000000} } }, | ||
213 | {{{1, 0x2200000, 0x2204000, 0x1b0000} } },/* 34: CAM */ | ||
214 | {{{0} } }, /* 35: */ | ||
215 | {{{0} } }, /* 36: */ | ||
216 | {{{0} } }, /* 37: */ | ||
217 | {{{0} } }, /* 38: */ | ||
218 | {{{0} } }, /* 39: */ | ||
219 | {{{1, 0x2800000, 0x2804000, 0x1a4000} } },/* 40: TMR */ | ||
220 | {{{1, 0x2900000, 0x2901000, 0x16b000} } },/* 41: P2NR3 */ | ||
221 | {{{1, 0x2a00000, 0x2a00400, 0x1ac400} } },/* 42: RPMX1 */ | ||
222 | {{{1, 0x2b00000, 0x2b00400, 0x1ac800} } },/* 43: RPMX2 */ | ||
223 | {{{1, 0x2c00000, 0x2c00400, 0x1acc00} } },/* 44: RPMX3 */ | ||
224 | {{{1, 0x2d00000, 0x2d00400, 0x1ad000} } },/* 45: RPMX4 */ | ||
225 | {{{1, 0x2e00000, 0x2e00400, 0x1ad400} } },/* 46: RPMX5 */ | ||
226 | {{{1, 0x2f00000, 0x2f00400, 0x1ad800} } },/* 47: RPMX6 */ | ||
227 | {{{1, 0x3000000, 0x3000400, 0x1adc00} } },/* 48: RPMX7 */ | ||
228 | {{{0, 0x3100000, 0x3104000, 0x1a8000} } },/* 49: XDMA */ | ||
229 | {{{1, 0x3200000, 0x3204000, 0x1d4000} } },/* 50: I2Q */ | ||
230 | {{{1, 0x3300000, 0x3304000, 0x1a0000} } },/* 51: ROMUSB */ | ||
231 | {{{0} } }, /* 52: */ | ||
232 | {{{1, 0x3500000, 0x3500400, 0x1ac000} } },/* 53: RPMX0 */ | ||
233 | {{{1, 0x3600000, 0x3600400, 0x1ae000} } },/* 54: RPMX8 */ | ||
234 | {{{1, 0x3700000, 0x3700400, 0x1ae400} } },/* 55: RPMX9 */ | ||
235 | {{{1, 0x3800000, 0x3804000, 0x1d0000} } },/* 56: OCM0 */ | ||
236 | {{{1, 0x3900000, 0x3904000, 0x1b4000} } },/* 57: CRYPTO */ | ||
237 | {{{1, 0x3a00000, 0x3a04000, 0x1d8000} } },/* 58: SMB */ | ||
238 | {{{0} } }, /* 59: I2C0 */ | ||
239 | {{{0} } }, /* 60: I2C1 */ | ||
240 | {{{1, 0x3d00000, 0x3d04000, 0x1d8000} } },/* 61: LPC */ | ||
241 | {{{1, 0x3e00000, 0x3e01000, 0x167000} } },/* 62: P2NC */ | ||
242 | {{{1, 0x3f00000, 0x3f01000, 0x168000} } } /* 63: P2NR0 */ | ||
243 | }; | ||
244 | |||
245 | /* | ||
246 | * top 12 bits of crb internal address (hub, agent) | ||
247 | */ | ||
248 | static unsigned crb_hub_agt[64] = | ||
249 | { | ||
250 | 0, | ||
251 | NETXEN_HW_CRB_HUB_AGT_ADR_PS, | ||
252 | NETXEN_HW_CRB_HUB_AGT_ADR_MN, | ||
253 | NETXEN_HW_CRB_HUB_AGT_ADR_MS, | ||
254 | 0, | ||
255 | NETXEN_HW_CRB_HUB_AGT_ADR_SRE, | ||
256 | NETXEN_HW_CRB_HUB_AGT_ADR_NIU, | ||
257 | NETXEN_HW_CRB_HUB_AGT_ADR_QMN, | ||
258 | NETXEN_HW_CRB_HUB_AGT_ADR_SQN0, | ||
259 | NETXEN_HW_CRB_HUB_AGT_ADR_SQN1, | ||
260 | NETXEN_HW_CRB_HUB_AGT_ADR_SQN2, | ||
261 | NETXEN_HW_CRB_HUB_AGT_ADR_SQN3, | ||
262 | NETXEN_HW_CRB_HUB_AGT_ADR_I2Q, | ||
263 | NETXEN_HW_CRB_HUB_AGT_ADR_TIMR, | ||
264 | NETXEN_HW_CRB_HUB_AGT_ADR_ROMUSB, | ||
265 | NETXEN_HW_CRB_HUB_AGT_ADR_PGN4, | ||
266 | NETXEN_HW_CRB_HUB_AGT_ADR_XDMA, | ||
267 | NETXEN_HW_CRB_HUB_AGT_ADR_PGN0, | ||
268 | NETXEN_HW_CRB_HUB_AGT_ADR_PGN1, | ||
269 | NETXEN_HW_CRB_HUB_AGT_ADR_PGN2, | ||
270 | NETXEN_HW_CRB_HUB_AGT_ADR_PGN3, | ||
271 | NETXEN_HW_CRB_HUB_AGT_ADR_PGND, | ||
272 | NETXEN_HW_CRB_HUB_AGT_ADR_PGNI, | ||
273 | NETXEN_HW_CRB_HUB_AGT_ADR_PGS0, | ||
274 | NETXEN_HW_CRB_HUB_AGT_ADR_PGS1, | ||
275 | NETXEN_HW_CRB_HUB_AGT_ADR_PGS2, | ||
276 | NETXEN_HW_CRB_HUB_AGT_ADR_PGS3, | ||
277 | 0, | ||
278 | NETXEN_HW_CRB_HUB_AGT_ADR_PGSI, | ||
279 | NETXEN_HW_CRB_HUB_AGT_ADR_SN, | ||
280 | 0, | ||
281 | NETXEN_HW_CRB_HUB_AGT_ADR_EG, | ||
282 | 0, | ||
283 | NETXEN_HW_CRB_HUB_AGT_ADR_PS, | ||
284 | NETXEN_HW_CRB_HUB_AGT_ADR_CAM, | ||
285 | 0, | ||
286 | 0, | ||
287 | 0, | ||
288 | 0, | ||
289 | 0, | ||
290 | NETXEN_HW_CRB_HUB_AGT_ADR_TIMR, | ||
291 | 0, | ||
292 | NETXEN_HW_CRB_HUB_AGT_ADR_RPMX1, | ||
293 | NETXEN_HW_CRB_HUB_AGT_ADR_RPMX2, | ||
294 | NETXEN_HW_CRB_HUB_AGT_ADR_RPMX3, | ||
295 | NETXEN_HW_CRB_HUB_AGT_ADR_RPMX4, | ||
296 | NETXEN_HW_CRB_HUB_AGT_ADR_RPMX5, | ||
297 | NETXEN_HW_CRB_HUB_AGT_ADR_RPMX6, | ||
298 | NETXEN_HW_CRB_HUB_AGT_ADR_RPMX7, | ||
299 | NETXEN_HW_CRB_HUB_AGT_ADR_XDMA, | ||
300 | NETXEN_HW_CRB_HUB_AGT_ADR_I2Q, | ||
301 | NETXEN_HW_CRB_HUB_AGT_ADR_ROMUSB, | ||
302 | 0, | ||
303 | NETXEN_HW_CRB_HUB_AGT_ADR_RPMX0, | ||
304 | NETXEN_HW_CRB_HUB_AGT_ADR_RPMX8, | ||
305 | NETXEN_HW_CRB_HUB_AGT_ADR_RPMX9, | ||
306 | NETXEN_HW_CRB_HUB_AGT_ADR_OCM0, | ||
307 | 0, | ||
308 | NETXEN_HW_CRB_HUB_AGT_ADR_SMB, | ||
309 | NETXEN_HW_CRB_HUB_AGT_ADR_I2C0, | ||
310 | NETXEN_HW_CRB_HUB_AGT_ADR_I2C1, | ||
311 | 0, | ||
312 | NETXEN_HW_CRB_HUB_AGT_ADR_PGNC, | ||
313 | 0, | ||
314 | }; | ||
315 | |||
316 | /* PCI Windowing for DDR regions. */ | ||
317 | |||
318 | #define NETXEN_WINDOW_ONE 0x2000000 /*CRB Window: bit 25 of CRB address */ | ||
319 | |||
320 | #define NETXEN_PCIE_SEM_TIMEOUT 10000 | ||
321 | |||
322 | static int netxen_nic_set_mtu_xgb(struct netxen_adapter *adapter, int new_mtu); | ||
323 | |||
324 | int | ||
325 | netxen_pcie_sem_lock(struct netxen_adapter *adapter, int sem, u32 id_reg) | ||
326 | { | ||
327 | int done = 0, timeout = 0; | ||
328 | |||
329 | while (!done) { | ||
330 | done = NXRD32(adapter, NETXEN_PCIE_REG(PCIE_SEM_LOCK(sem))); | ||
331 | if (done == 1) | ||
332 | break; | ||
333 | if (++timeout >= NETXEN_PCIE_SEM_TIMEOUT) | ||
334 | return -EIO; | ||
335 | msleep(1); | ||
336 | } | ||
337 | |||
338 | if (id_reg) | ||
339 | NXWR32(adapter, id_reg, adapter->portnum); | ||
340 | |||
341 | return 0; | ||
342 | } | ||
343 | |||
344 | void | ||
345 | netxen_pcie_sem_unlock(struct netxen_adapter *adapter, int sem) | ||
346 | { | ||
347 | NXRD32(adapter, NETXEN_PCIE_REG(PCIE_SEM_UNLOCK(sem))); | ||
348 | } | ||
349 | |||
350 | static int netxen_niu_xg_init_port(struct netxen_adapter *adapter, int port) | ||
351 | { | ||
352 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) { | ||
353 | NXWR32(adapter, NETXEN_NIU_XGE_CONFIG_1+(0x10000*port), 0x1447); | ||
354 | NXWR32(adapter, NETXEN_NIU_XGE_CONFIG_0+(0x10000*port), 0x5); | ||
355 | } | ||
356 | |||
357 | return 0; | ||
358 | } | ||
359 | |||
360 | /* Disable an XG interface */ | ||
361 | static int netxen_niu_disable_xg_port(struct netxen_adapter *adapter) | ||
362 | { | ||
363 | __u32 mac_cfg; | ||
364 | u32 port = adapter->physical_port; | ||
365 | |||
366 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) | ||
367 | return 0; | ||
368 | |||
369 | if (port > NETXEN_NIU_MAX_XG_PORTS) | ||
370 | return -EINVAL; | ||
371 | |||
372 | mac_cfg = 0; | ||
373 | if (NXWR32(adapter, | ||
374 | NETXEN_NIU_XGE_CONFIG_0 + (0x10000 * port), mac_cfg)) | ||
375 | return -EIO; | ||
376 | return 0; | ||
377 | } | ||
378 | |||
379 | #define NETXEN_UNICAST_ADDR(port, index) \ | ||
380 | (NETXEN_UNICAST_ADDR_BASE+(port*32)+(index*8)) | ||
381 | #define NETXEN_MCAST_ADDR(port, index) \ | ||
382 | (NETXEN_MULTICAST_ADDR_BASE+(port*0x80)+(index*8)) | ||
383 | #define MAC_HI(addr) \ | ||
384 | ((addr[2] << 16) | (addr[1] << 8) | (addr[0])) | ||
385 | #define MAC_LO(addr) \ | ||
386 | ((addr[5] << 16) | (addr[4] << 8) | (addr[3])) | ||
387 | |||
388 | static int netxen_p2_nic_set_promisc(struct netxen_adapter *adapter, u32 mode) | ||
389 | { | ||
390 | u32 mac_cfg; | ||
391 | u32 cnt = 0; | ||
392 | __u32 reg = 0x0200; | ||
393 | u32 port = adapter->physical_port; | ||
394 | u16 board_type = adapter->ahw.board_type; | ||
395 | |||
396 | if (port > NETXEN_NIU_MAX_XG_PORTS) | ||
397 | return -EINVAL; | ||
398 | |||
399 | mac_cfg = NXRD32(adapter, NETXEN_NIU_XGE_CONFIG_0 + (0x10000 * port)); | ||
400 | mac_cfg &= ~0x4; | ||
401 | NXWR32(adapter, NETXEN_NIU_XGE_CONFIG_0 + (0x10000 * port), mac_cfg); | ||
402 | |||
403 | if ((board_type == NETXEN_BRDTYPE_P2_SB31_10G_IMEZ) || | ||
404 | (board_type == NETXEN_BRDTYPE_P2_SB31_10G_HMEZ)) | ||
405 | reg = (0x20 << port); | ||
406 | |||
407 | NXWR32(adapter, NETXEN_NIU_FRAME_COUNT_SELECT, reg); | ||
408 | |||
409 | mdelay(10); | ||
410 | |||
411 | while (NXRD32(adapter, NETXEN_NIU_FRAME_COUNT) && ++cnt < 20) | ||
412 | mdelay(10); | ||
413 | |||
414 | if (cnt < 20) { | ||
415 | |||
416 | reg = NXRD32(adapter, | ||
417 | NETXEN_NIU_XGE_CONFIG_1 + (0x10000 * port)); | ||
418 | |||
419 | if (mode == NETXEN_NIU_PROMISC_MODE) | ||
420 | reg = (reg | 0x2000UL); | ||
421 | else | ||
422 | reg = (reg & ~0x2000UL); | ||
423 | |||
424 | if (mode == NETXEN_NIU_ALLMULTI_MODE) | ||
425 | reg = (reg | 0x1000UL); | ||
426 | else | ||
427 | reg = (reg & ~0x1000UL); | ||
428 | |||
429 | NXWR32(adapter, | ||
430 | NETXEN_NIU_XGE_CONFIG_1 + (0x10000 * port), reg); | ||
431 | } | ||
432 | |||
433 | mac_cfg |= 0x4; | ||
434 | NXWR32(adapter, NETXEN_NIU_XGE_CONFIG_0 + (0x10000 * port), mac_cfg); | ||
435 | |||
436 | return 0; | ||
437 | } | ||
438 | |||
439 | static int netxen_p2_nic_set_mac_addr(struct netxen_adapter *adapter, u8 *addr) | ||
440 | { | ||
441 | u32 mac_hi, mac_lo; | ||
442 | u32 reg_hi, reg_lo; | ||
443 | |||
444 | u8 phy = adapter->physical_port; | ||
445 | |||
446 | if (phy >= NETXEN_NIU_MAX_XG_PORTS) | ||
447 | return -EINVAL; | ||
448 | |||
449 | mac_lo = ((u32)addr[0] << 16) | ((u32)addr[1] << 24); | ||
450 | mac_hi = addr[2] | ((u32)addr[3] << 8) | | ||
451 | ((u32)addr[4] << 16) | ((u32)addr[5] << 24); | ||
452 | |||
453 | reg_lo = NETXEN_NIU_XGE_STATION_ADDR_0_1 + (0x10000 * phy); | ||
454 | reg_hi = NETXEN_NIU_XGE_STATION_ADDR_0_HI + (0x10000 * phy); | ||
455 | |||
456 | /* write twice to flush */ | ||
457 | if (NXWR32(adapter, reg_lo, mac_lo) || NXWR32(adapter, reg_hi, mac_hi)) | ||
458 | return -EIO; | ||
459 | if (NXWR32(adapter, reg_lo, mac_lo) || NXWR32(adapter, reg_hi, mac_hi)) | ||
460 | return -EIO; | ||
461 | |||
462 | return 0; | ||
463 | } | ||
464 | |||
465 | static int | ||
466 | netxen_nic_enable_mcast_filter(struct netxen_adapter *adapter) | ||
467 | { | ||
468 | u32 val = 0; | ||
469 | u16 port = adapter->physical_port; | ||
470 | u8 *addr = adapter->mac_addr; | ||
471 | |||
472 | if (adapter->mc_enabled) | ||
473 | return 0; | ||
474 | |||
475 | val = NXRD32(adapter, NETXEN_MAC_ADDR_CNTL_REG); | ||
476 | val |= (1UL << (28+port)); | ||
477 | NXWR32(adapter, NETXEN_MAC_ADDR_CNTL_REG, val); | ||
478 | |||
479 | /* add broadcast addr to filter */ | ||
480 | val = 0xffffff; | ||
481 | NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 0), val); | ||
482 | NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 0)+4, val); | ||
483 | |||
484 | /* add station addr to filter */ | ||
485 | val = MAC_HI(addr); | ||
486 | NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 1), val); | ||
487 | val = MAC_LO(addr); | ||
488 | NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 1)+4, val); | ||
489 | |||
490 | adapter->mc_enabled = 1; | ||
491 | return 0; | ||
492 | } | ||
493 | |||
494 | static int | ||
495 | netxen_nic_disable_mcast_filter(struct netxen_adapter *adapter) | ||
496 | { | ||
497 | u32 val = 0; | ||
498 | u16 port = adapter->physical_port; | ||
499 | u8 *addr = adapter->mac_addr; | ||
500 | |||
501 | if (!adapter->mc_enabled) | ||
502 | return 0; | ||
503 | |||
504 | val = NXRD32(adapter, NETXEN_MAC_ADDR_CNTL_REG); | ||
505 | val &= ~(1UL << (28+port)); | ||
506 | NXWR32(adapter, NETXEN_MAC_ADDR_CNTL_REG, val); | ||
507 | |||
508 | val = MAC_HI(addr); | ||
509 | NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 0), val); | ||
510 | val = MAC_LO(addr); | ||
511 | NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 0)+4, val); | ||
512 | |||
513 | NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 1), 0); | ||
514 | NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 1)+4, 0); | ||
515 | |||
516 | adapter->mc_enabled = 0; | ||
517 | return 0; | ||
518 | } | ||
519 | |||
520 | static int | ||
521 | netxen_nic_set_mcast_addr(struct netxen_adapter *adapter, | ||
522 | int index, u8 *addr) | ||
523 | { | ||
524 | u32 hi = 0, lo = 0; | ||
525 | u16 port = adapter->physical_port; | ||
526 | |||
527 | lo = MAC_LO(addr); | ||
528 | hi = MAC_HI(addr); | ||
529 | |||
530 | NXWR32(adapter, NETXEN_MCAST_ADDR(port, index), hi); | ||
531 | NXWR32(adapter, NETXEN_MCAST_ADDR(port, index)+4, lo); | ||
532 | |||
533 | return 0; | ||
534 | } | ||
535 | |||
536 | static void netxen_p2_nic_set_multi(struct net_device *netdev) | ||
537 | { | ||
538 | struct netxen_adapter *adapter = netdev_priv(netdev); | ||
539 | struct netdev_hw_addr *ha; | ||
540 | u8 null_addr[6]; | ||
541 | int i; | ||
542 | |||
543 | memset(null_addr, 0, 6); | ||
544 | |||
545 | if (netdev->flags & IFF_PROMISC) { | ||
546 | |||
547 | adapter->set_promisc(adapter, | ||
548 | NETXEN_NIU_PROMISC_MODE); | ||
549 | |||
550 | /* Full promiscuous mode */ | ||
551 | netxen_nic_disable_mcast_filter(adapter); | ||
552 | |||
553 | return; | ||
554 | } | ||
555 | |||
556 | if (netdev_mc_empty(netdev)) { | ||
557 | adapter->set_promisc(adapter, | ||
558 | NETXEN_NIU_NON_PROMISC_MODE); | ||
559 | netxen_nic_disable_mcast_filter(adapter); | ||
560 | return; | ||
561 | } | ||
562 | |||
563 | adapter->set_promisc(adapter, NETXEN_NIU_ALLMULTI_MODE); | ||
564 | if (netdev->flags & IFF_ALLMULTI || | ||
565 | netdev_mc_count(netdev) > adapter->max_mc_count) { | ||
566 | netxen_nic_disable_mcast_filter(adapter); | ||
567 | return; | ||
568 | } | ||
569 | |||
570 | netxen_nic_enable_mcast_filter(adapter); | ||
571 | |||
572 | i = 0; | ||
573 | netdev_for_each_mc_addr(ha, netdev) | ||
574 | netxen_nic_set_mcast_addr(adapter, i++, ha->addr); | ||
575 | |||
576 | /* Clear out remaining addresses */ | ||
577 | while (i < adapter->max_mc_count) | ||
578 | netxen_nic_set_mcast_addr(adapter, i++, null_addr); | ||
579 | } | ||
580 | |||
581 | static int | ||
582 | netxen_send_cmd_descs(struct netxen_adapter *adapter, | ||
583 | struct cmd_desc_type0 *cmd_desc_arr, int nr_desc) | ||
584 | { | ||
585 | u32 i, producer, consumer; | ||
586 | struct netxen_cmd_buffer *pbuf; | ||
587 | struct cmd_desc_type0 *cmd_desc; | ||
588 | struct nx_host_tx_ring *tx_ring; | ||
589 | |||
590 | i = 0; | ||
591 | |||
592 | if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC) | ||
593 | return -EIO; | ||
594 | |||
595 | tx_ring = adapter->tx_ring; | ||
596 | __netif_tx_lock_bh(tx_ring->txq); | ||
597 | |||
598 | producer = tx_ring->producer; | ||
599 | consumer = tx_ring->sw_consumer; | ||
600 | |||
601 | if (nr_desc >= netxen_tx_avail(tx_ring)) { | ||
602 | netif_tx_stop_queue(tx_ring->txq); | ||
603 | smp_mb(); | ||
604 | if (netxen_tx_avail(tx_ring) > nr_desc) { | ||
605 | if (netxen_tx_avail(tx_ring) > TX_STOP_THRESH) | ||
606 | netif_tx_wake_queue(tx_ring->txq); | ||
607 | } else { | ||
608 | __netif_tx_unlock_bh(tx_ring->txq); | ||
609 | return -EBUSY; | ||
610 | } | ||
611 | } | ||
612 | |||
613 | do { | ||
614 | cmd_desc = &cmd_desc_arr[i]; | ||
615 | |||
616 | pbuf = &tx_ring->cmd_buf_arr[producer]; | ||
617 | pbuf->skb = NULL; | ||
618 | pbuf->frag_count = 0; | ||
619 | |||
620 | memcpy(&tx_ring->desc_head[producer], | ||
621 | &cmd_desc_arr[i], sizeof(struct cmd_desc_type0)); | ||
622 | |||
623 | producer = get_next_index(producer, tx_ring->num_desc); | ||
624 | i++; | ||
625 | |||
626 | } while (i != nr_desc); | ||
627 | |||
628 | tx_ring->producer = producer; | ||
629 | |||
630 | netxen_nic_update_cmd_producer(adapter, tx_ring); | ||
631 | |||
632 | __netif_tx_unlock_bh(tx_ring->txq); | ||
633 | |||
634 | return 0; | ||
635 | } | ||
636 | |||
637 | static int | ||
638 | nx_p3_sre_macaddr_change(struct netxen_adapter *adapter, u8 *addr, unsigned op) | ||
639 | { | ||
640 | nx_nic_req_t req; | ||
641 | nx_mac_req_t *mac_req; | ||
642 | u64 word; | ||
643 | |||
644 | memset(&req, 0, sizeof(nx_nic_req_t)); | ||
645 | req.qhdr = cpu_to_le64(NX_NIC_REQUEST << 23); | ||
646 | |||
647 | word = NX_MAC_EVENT | ((u64)adapter->portnum << 16); | ||
648 | req.req_hdr = cpu_to_le64(word); | ||
649 | |||
650 | mac_req = (nx_mac_req_t *)&req.words[0]; | ||
651 | mac_req->op = op; | ||
652 | memcpy(mac_req->mac_addr, addr, 6); | ||
653 | |||
654 | return netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1); | ||
655 | } | ||
656 | |||
657 | static int nx_p3_nic_add_mac(struct netxen_adapter *adapter, | ||
658 | const u8 *addr, struct list_head *del_list) | ||
659 | { | ||
660 | struct list_head *head; | ||
661 | nx_mac_list_t *cur; | ||
662 | |||
663 | /* look up if already exists */ | ||
664 | list_for_each(head, del_list) { | ||
665 | cur = list_entry(head, nx_mac_list_t, list); | ||
666 | |||
667 | if (memcmp(addr, cur->mac_addr, ETH_ALEN) == 0) { | ||
668 | list_move_tail(head, &adapter->mac_list); | ||
669 | return 0; | ||
670 | } | ||
671 | } | ||
672 | |||
673 | cur = kzalloc(sizeof(nx_mac_list_t), GFP_ATOMIC); | ||
674 | if (cur == NULL) { | ||
675 | printk(KERN_ERR "%s: failed to add mac address filter\n", | ||
676 | adapter->netdev->name); | ||
677 | return -ENOMEM; | ||
678 | } | ||
679 | memcpy(cur->mac_addr, addr, ETH_ALEN); | ||
680 | list_add_tail(&cur->list, &adapter->mac_list); | ||
681 | return nx_p3_sre_macaddr_change(adapter, | ||
682 | cur->mac_addr, NETXEN_MAC_ADD); | ||
683 | } | ||
684 | |||
685 | static void netxen_p3_nic_set_multi(struct net_device *netdev) | ||
686 | { | ||
687 | struct netxen_adapter *adapter = netdev_priv(netdev); | ||
688 | struct netdev_hw_addr *ha; | ||
689 | static const u8 bcast_addr[ETH_ALEN] = { | ||
690 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff | ||
691 | }; | ||
692 | u32 mode = VPORT_MISS_MODE_DROP; | ||
693 | LIST_HEAD(del_list); | ||
694 | struct list_head *head; | ||
695 | nx_mac_list_t *cur; | ||
696 | |||
697 | if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC) | ||
698 | return; | ||
699 | |||
700 | list_splice_tail_init(&adapter->mac_list, &del_list); | ||
701 | |||
702 | nx_p3_nic_add_mac(adapter, adapter->mac_addr, &del_list); | ||
703 | nx_p3_nic_add_mac(adapter, bcast_addr, &del_list); | ||
704 | |||
705 | if (netdev->flags & IFF_PROMISC) { | ||
706 | mode = VPORT_MISS_MODE_ACCEPT_ALL; | ||
707 | goto send_fw_cmd; | ||
708 | } | ||
709 | |||
710 | if ((netdev->flags & IFF_ALLMULTI) || | ||
711 | (netdev_mc_count(netdev) > adapter->max_mc_count)) { | ||
712 | mode = VPORT_MISS_MODE_ACCEPT_MULTI; | ||
713 | goto send_fw_cmd; | ||
714 | } | ||
715 | |||
716 | if (!netdev_mc_empty(netdev)) { | ||
717 | netdev_for_each_mc_addr(ha, netdev) | ||
718 | nx_p3_nic_add_mac(adapter, ha->addr, &del_list); | ||
719 | } | ||
720 | |||
721 | send_fw_cmd: | ||
722 | adapter->set_promisc(adapter, mode); | ||
723 | head = &del_list; | ||
724 | while (!list_empty(head)) { | ||
725 | cur = list_entry(head->next, nx_mac_list_t, list); | ||
726 | |||
727 | nx_p3_sre_macaddr_change(adapter, | ||
728 | cur->mac_addr, NETXEN_MAC_DEL); | ||
729 | list_del(&cur->list); | ||
730 | kfree(cur); | ||
731 | } | ||
732 | } | ||
733 | |||
734 | static int netxen_p3_nic_set_promisc(struct netxen_adapter *adapter, u32 mode) | ||
735 | { | ||
736 | nx_nic_req_t req; | ||
737 | u64 word; | ||
738 | |||
739 | memset(&req, 0, sizeof(nx_nic_req_t)); | ||
740 | |||
741 | req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23); | ||
742 | |||
743 | word = NX_NIC_H2C_OPCODE_PROXY_SET_VPORT_MISS_MODE | | ||
744 | ((u64)adapter->portnum << 16); | ||
745 | req.req_hdr = cpu_to_le64(word); | ||
746 | |||
747 | req.words[0] = cpu_to_le64(mode); | ||
748 | |||
749 | return netxen_send_cmd_descs(adapter, | ||
750 | (struct cmd_desc_type0 *)&req, 1); | ||
751 | } | ||
752 | |||
753 | void netxen_p3_free_mac_list(struct netxen_adapter *adapter) | ||
754 | { | ||
755 | nx_mac_list_t *cur; | ||
756 | struct list_head *head = &adapter->mac_list; | ||
757 | |||
758 | while (!list_empty(head)) { | ||
759 | cur = list_entry(head->next, nx_mac_list_t, list); | ||
760 | nx_p3_sre_macaddr_change(adapter, | ||
761 | cur->mac_addr, NETXEN_MAC_DEL); | ||
762 | list_del(&cur->list); | ||
763 | kfree(cur); | ||
764 | } | ||
765 | } | ||
766 | |||
767 | static int netxen_p3_nic_set_mac_addr(struct netxen_adapter *adapter, u8 *addr) | ||
768 | { | ||
769 | /* assuming caller has already copied new addr to netdev */ | ||
770 | netxen_p3_nic_set_multi(adapter->netdev); | ||
771 | return 0; | ||
772 | } | ||
773 | |||
774 | #define NETXEN_CONFIG_INTR_COALESCE 3 | ||
775 | |||
776 | /* | ||
777 | * Send the interrupt coalescing parameter set by ethtool to the card. | ||
778 | */ | ||
779 | int netxen_config_intr_coalesce(struct netxen_adapter *adapter) | ||
780 | { | ||
781 | nx_nic_req_t req; | ||
782 | u64 word[6]; | ||
783 | int rv, i; | ||
784 | |||
785 | memset(&req, 0, sizeof(nx_nic_req_t)); | ||
786 | memset(word, 0, sizeof(word)); | ||
787 | |||
788 | req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23); | ||
789 | |||
790 | word[0] = NETXEN_CONFIG_INTR_COALESCE | ((u64)adapter->portnum << 16); | ||
791 | req.req_hdr = cpu_to_le64(word[0]); | ||
792 | |||
793 | memcpy(&word[0], &adapter->coal, sizeof(adapter->coal)); | ||
794 | for (i = 0; i < 6; i++) | ||
795 | req.words[i] = cpu_to_le64(word[i]); | ||
796 | |||
797 | rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1); | ||
798 | if (rv != 0) { | ||
799 | printk(KERN_ERR "ERROR. Could not send " | ||
800 | "interrupt coalescing parameters\n"); | ||
801 | } | ||
802 | |||
803 | return rv; | ||
804 | } | ||
805 | |||
806 | int netxen_config_hw_lro(struct netxen_adapter *adapter, int enable) | ||
807 | { | ||
808 | nx_nic_req_t req; | ||
809 | u64 word; | ||
810 | int rv = 0; | ||
811 | |||
812 | if (!test_bit(__NX_FW_ATTACHED, &adapter->state)) | ||
813 | return 0; | ||
814 | |||
815 | memset(&req, 0, sizeof(nx_nic_req_t)); | ||
816 | |||
817 | req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23); | ||
818 | |||
819 | word = NX_NIC_H2C_OPCODE_CONFIG_HW_LRO | ((u64)adapter->portnum << 16); | ||
820 | req.req_hdr = cpu_to_le64(word); | ||
821 | |||
822 | req.words[0] = cpu_to_le64(enable); | ||
823 | |||
824 | rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1); | ||
825 | if (rv != 0) { | ||
826 | printk(KERN_ERR "ERROR. Could not send " | ||
827 | "configure hw lro request\n"); | ||
828 | } | ||
829 | |||
830 | return rv; | ||
831 | } | ||
832 | |||
833 | int netxen_config_bridged_mode(struct netxen_adapter *adapter, int enable) | ||
834 | { | ||
835 | nx_nic_req_t req; | ||
836 | u64 word; | ||
837 | int rv = 0; | ||
838 | |||
839 | if (!!(adapter->flags & NETXEN_NIC_BRIDGE_ENABLED) == enable) | ||
840 | return rv; | ||
841 | |||
842 | memset(&req, 0, sizeof(nx_nic_req_t)); | ||
843 | |||
844 | req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23); | ||
845 | |||
846 | word = NX_NIC_H2C_OPCODE_CONFIG_BRIDGING | | ||
847 | ((u64)adapter->portnum << 16); | ||
848 | req.req_hdr = cpu_to_le64(word); | ||
849 | |||
850 | req.words[0] = cpu_to_le64(enable); | ||
851 | |||
852 | rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1); | ||
853 | if (rv != 0) { | ||
854 | printk(KERN_ERR "ERROR. Could not send " | ||
855 | "configure bridge mode request\n"); | ||
856 | } | ||
857 | |||
858 | adapter->flags ^= NETXEN_NIC_BRIDGE_ENABLED; | ||
859 | |||
860 | return rv; | ||
861 | } | ||
862 | |||
863 | |||
864 | #define RSS_HASHTYPE_IP_TCP 0x3 | ||
865 | |||
866 | int netxen_config_rss(struct netxen_adapter *adapter, int enable) | ||
867 | { | ||
868 | nx_nic_req_t req; | ||
869 | u64 word; | ||
870 | int i, rv; | ||
871 | |||
872 | static const u64 key[] = { | ||
873 | 0xbeac01fa6a42b73bULL, 0x8030f20c77cb2da3ULL, | ||
874 | 0xae7b30b4d0ca2bcbULL, 0x43a38fb04167253dULL, | ||
875 | 0x255b0ec26d5a56daULL | ||
876 | }; | ||
877 | |||
878 | |||
879 | memset(&req, 0, sizeof(nx_nic_req_t)); | ||
880 | req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23); | ||
881 | |||
882 | word = NX_NIC_H2C_OPCODE_CONFIG_RSS | ((u64)adapter->portnum << 16); | ||
883 | req.req_hdr = cpu_to_le64(word); | ||
884 | |||
885 | /* | ||
886 | * RSS request: | ||
887 | * bits 3-0: hash_method | ||
888 | * 5-4: hash_type_ipv4 | ||
889 | * 7-6: hash_type_ipv6 | ||
890 | * 8: enable | ||
891 | * 9: use indirection table | ||
892 | * 47-10: reserved | ||
893 | * 63-48: indirection table mask | ||
894 | */ | ||
895 | word = ((u64)(RSS_HASHTYPE_IP_TCP & 0x3) << 4) | | ||
896 | ((u64)(RSS_HASHTYPE_IP_TCP & 0x3) << 6) | | ||
897 | ((u64)(enable & 0x1) << 8) | | ||
898 | ((0x7ULL) << 48); | ||
899 | req.words[0] = cpu_to_le64(word); | ||
900 | for (i = 0; i < ARRAY_SIZE(key); i++) | ||
901 | req.words[i+1] = cpu_to_le64(key[i]); | ||
902 | |||
903 | |||
904 | rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1); | ||
905 | if (rv != 0) { | ||
906 | printk(KERN_ERR "%s: could not configure RSS\n", | ||
907 | adapter->netdev->name); | ||
908 | } | ||
909 | |||
910 | return rv; | ||
911 | } | ||
912 | |||
913 | int netxen_config_ipaddr(struct netxen_adapter *adapter, u32 ip, int cmd) | ||
914 | { | ||
915 | nx_nic_req_t req; | ||
916 | u64 word; | ||
917 | int rv; | ||
918 | |||
919 | memset(&req, 0, sizeof(nx_nic_req_t)); | ||
920 | req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23); | ||
921 | |||
922 | word = NX_NIC_H2C_OPCODE_CONFIG_IPADDR | ((u64)adapter->portnum << 16); | ||
923 | req.req_hdr = cpu_to_le64(word); | ||
924 | |||
925 | req.words[0] = cpu_to_le64(cmd); | ||
926 | req.words[1] = cpu_to_le64(ip); | ||
927 | |||
928 | rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1); | ||
929 | if (rv != 0) { | ||
930 | printk(KERN_ERR "%s: could not notify %s IP 0x%x reuqest\n", | ||
931 | adapter->netdev->name, | ||
932 | (cmd == NX_IP_UP) ? "Add" : "Remove", ip); | ||
933 | } | ||
934 | return rv; | ||
935 | } | ||
936 | |||
937 | int netxen_linkevent_request(struct netxen_adapter *adapter, int enable) | ||
938 | { | ||
939 | nx_nic_req_t req; | ||
940 | u64 word; | ||
941 | int rv; | ||
942 | |||
943 | memset(&req, 0, sizeof(nx_nic_req_t)); | ||
944 | req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23); | ||
945 | |||
946 | word = NX_NIC_H2C_OPCODE_GET_LINKEVENT | ((u64)adapter->portnum << 16); | ||
947 | req.req_hdr = cpu_to_le64(word); | ||
948 | req.words[0] = cpu_to_le64(enable | (enable << 8)); | ||
949 | |||
950 | rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1); | ||
951 | if (rv != 0) { | ||
952 | printk(KERN_ERR "%s: could not configure link notification\n", | ||
953 | adapter->netdev->name); | ||
954 | } | ||
955 | |||
956 | return rv; | ||
957 | } | ||
958 | |||
959 | int netxen_send_lro_cleanup(struct netxen_adapter *adapter) | ||
960 | { | ||
961 | nx_nic_req_t req; | ||
962 | u64 word; | ||
963 | int rv; | ||
964 | |||
965 | if (!test_bit(__NX_FW_ATTACHED, &adapter->state)) | ||
966 | return 0; | ||
967 | |||
968 | memset(&req, 0, sizeof(nx_nic_req_t)); | ||
969 | req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23); | ||
970 | |||
971 | word = NX_NIC_H2C_OPCODE_LRO_REQUEST | | ||
972 | ((u64)adapter->portnum << 16) | | ||
973 | ((u64)NX_NIC_LRO_REQUEST_CLEANUP << 56) ; | ||
974 | |||
975 | req.req_hdr = cpu_to_le64(word); | ||
976 | |||
977 | rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1); | ||
978 | if (rv != 0) { | ||
979 | printk(KERN_ERR "%s: could not cleanup lro flows\n", | ||
980 | adapter->netdev->name); | ||
981 | } | ||
982 | return rv; | ||
983 | } | ||
984 | |||
985 | /* | ||
986 | * netxen_nic_change_mtu - Change the Maximum Transfer Unit | ||
987 | * @returns 0 on success, negative on failure | ||
988 | */ | ||
989 | |||
990 | #define MTU_FUDGE_FACTOR 100 | ||
991 | |||
992 | int netxen_nic_change_mtu(struct net_device *netdev, int mtu) | ||
993 | { | ||
994 | struct netxen_adapter *adapter = netdev_priv(netdev); | ||
995 | int max_mtu; | ||
996 | int rc = 0; | ||
997 | |||
998 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) | ||
999 | max_mtu = P3_MAX_MTU; | ||
1000 | else | ||
1001 | max_mtu = P2_MAX_MTU; | ||
1002 | |||
1003 | if (mtu > max_mtu) { | ||
1004 | printk(KERN_ERR "%s: mtu > %d bytes unsupported\n", | ||
1005 | netdev->name, max_mtu); | ||
1006 | return -EINVAL; | ||
1007 | } | ||
1008 | |||
1009 | if (adapter->set_mtu) | ||
1010 | rc = adapter->set_mtu(adapter, mtu); | ||
1011 | |||
1012 | if (!rc) | ||
1013 | netdev->mtu = mtu; | ||
1014 | |||
1015 | return rc; | ||
1016 | } | ||
1017 | |||
1018 | static int netxen_get_flash_block(struct netxen_adapter *adapter, int base, | ||
1019 | int size, __le32 * buf) | ||
1020 | { | ||
1021 | int i, v, addr; | ||
1022 | __le32 *ptr32; | ||
1023 | |||
1024 | addr = base; | ||
1025 | ptr32 = buf; | ||
1026 | for (i = 0; i < size / sizeof(u32); i++) { | ||
1027 | if (netxen_rom_fast_read(adapter, addr, &v) == -1) | ||
1028 | return -1; | ||
1029 | *ptr32 = cpu_to_le32(v); | ||
1030 | ptr32++; | ||
1031 | addr += sizeof(u32); | ||
1032 | } | ||
1033 | if ((char *)buf + size > (char *)ptr32) { | ||
1034 | __le32 local; | ||
1035 | if (netxen_rom_fast_read(adapter, addr, &v) == -1) | ||
1036 | return -1; | ||
1037 | local = cpu_to_le32(v); | ||
1038 | memcpy(ptr32, &local, (char *)buf + size - (char *)ptr32); | ||
1039 | } | ||
1040 | |||
1041 | return 0; | ||
1042 | } | ||
1043 | |||
1044 | int netxen_get_flash_mac_addr(struct netxen_adapter *adapter, u64 *mac) | ||
1045 | { | ||
1046 | __le32 *pmac = (__le32 *) mac; | ||
1047 | u32 offset; | ||
1048 | |||
1049 | offset = NX_FW_MAC_ADDR_OFFSET + (adapter->portnum * sizeof(u64)); | ||
1050 | |||
1051 | if (netxen_get_flash_block(adapter, offset, sizeof(u64), pmac) == -1) | ||
1052 | return -1; | ||
1053 | |||
1054 | if (*mac == cpu_to_le64(~0ULL)) { | ||
1055 | |||
1056 | offset = NX_OLD_MAC_ADDR_OFFSET + | ||
1057 | (adapter->portnum * sizeof(u64)); | ||
1058 | |||
1059 | if (netxen_get_flash_block(adapter, | ||
1060 | offset, sizeof(u64), pmac) == -1) | ||
1061 | return -1; | ||
1062 | |||
1063 | if (*mac == cpu_to_le64(~0ULL)) | ||
1064 | return -1; | ||
1065 | } | ||
1066 | return 0; | ||
1067 | } | ||
1068 | |||
1069 | int netxen_p3_get_mac_addr(struct netxen_adapter *adapter, u64 *mac) | ||
1070 | { | ||
1071 | uint32_t crbaddr, mac_hi, mac_lo; | ||
1072 | int pci_func = adapter->ahw.pci_func; | ||
1073 | |||
1074 | crbaddr = CRB_MAC_BLOCK_START + | ||
1075 | (4 * ((pci_func/2) * 3)) + (4 * (pci_func & 1)); | ||
1076 | |||
1077 | mac_lo = NXRD32(adapter, crbaddr); | ||
1078 | mac_hi = NXRD32(adapter, crbaddr+4); | ||
1079 | |||
1080 | if (pci_func & 1) | ||
1081 | *mac = le64_to_cpu((mac_lo >> 16) | ((u64)mac_hi << 16)); | ||
1082 | else | ||
1083 | *mac = le64_to_cpu((u64)mac_lo | ((u64)mac_hi << 32)); | ||
1084 | |||
1085 | return 0; | ||
1086 | } | ||
1087 | |||
1088 | /* | ||
1089 | * Changes the CRB window to the specified window. | ||
1090 | */ | ||
1091 | static void | ||
1092 | netxen_nic_pci_set_crbwindow_128M(struct netxen_adapter *adapter, | ||
1093 | u32 window) | ||
1094 | { | ||
1095 | void __iomem *offset; | ||
1096 | int count = 10; | ||
1097 | u8 func = adapter->ahw.pci_func; | ||
1098 | |||
1099 | if (adapter->ahw.crb_win == window) | ||
1100 | return; | ||
1101 | |||
1102 | offset = PCI_OFFSET_SECOND_RANGE(adapter, | ||
1103 | NETXEN_PCIX_PH_REG(PCIE_CRB_WINDOW_REG(func))); | ||
1104 | |||
1105 | writel(window, offset); | ||
1106 | do { | ||
1107 | if (window == readl(offset)) | ||
1108 | break; | ||
1109 | |||
1110 | if (printk_ratelimit()) | ||
1111 | dev_warn(&adapter->pdev->dev, | ||
1112 | "failed to set CRB window to %d\n", | ||
1113 | (window == NETXEN_WINDOW_ONE)); | ||
1114 | udelay(1); | ||
1115 | |||
1116 | } while (--count > 0); | ||
1117 | |||
1118 | if (count > 0) | ||
1119 | adapter->ahw.crb_win = window; | ||
1120 | } | ||
1121 | |||
1122 | /* | ||
1123 | * Returns < 0 if off is not valid, | ||
1124 | * 1 if window access is needed. 'off' is set to offset from | ||
1125 | * CRB space in 128M pci map | ||
1126 | * 0 if no window access is needed. 'off' is set to 2M addr | ||
1127 | * In: 'off' is offset from base in 128M pci map | ||
1128 | */ | ||
1129 | static int | ||
1130 | netxen_nic_pci_get_crb_addr_2M(struct netxen_adapter *adapter, | ||
1131 | ulong off, void __iomem **addr) | ||
1132 | { | ||
1133 | crb_128M_2M_sub_block_map_t *m; | ||
1134 | |||
1135 | |||
1136 | if ((off >= NETXEN_CRB_MAX) || (off < NETXEN_PCI_CRBSPACE)) | ||
1137 | return -EINVAL; | ||
1138 | |||
1139 | off -= NETXEN_PCI_CRBSPACE; | ||
1140 | |||
1141 | /* | ||
1142 | * Try direct map | ||
1143 | */ | ||
1144 | m = &crb_128M_2M_map[CRB_BLK(off)].sub_block[CRB_SUBBLK(off)]; | ||
1145 | |||
1146 | if (m->valid && (m->start_128M <= off) && (m->end_128M > off)) { | ||
1147 | *addr = adapter->ahw.pci_base0 + m->start_2M + | ||
1148 | (off - m->start_128M); | ||
1149 | return 0; | ||
1150 | } | ||
1151 | |||
1152 | /* | ||
1153 | * Not in direct map, use crb window | ||
1154 | */ | ||
1155 | *addr = adapter->ahw.pci_base0 + CRB_INDIRECT_2M + | ||
1156 | (off & MASK(16)); | ||
1157 | return 1; | ||
1158 | } | ||
1159 | |||
1160 | /* | ||
1161 | * In: 'off' is offset from CRB space in 128M pci map | ||
1162 | * Out: 'off' is 2M pci map addr | ||
1163 | * side effect: lock crb window | ||
1164 | */ | ||
1165 | static void | ||
1166 | netxen_nic_pci_set_crbwindow_2M(struct netxen_adapter *adapter, ulong off) | ||
1167 | { | ||
1168 | u32 window; | ||
1169 | void __iomem *addr = adapter->ahw.pci_base0 + CRB_WINDOW_2M; | ||
1170 | |||
1171 | off -= NETXEN_PCI_CRBSPACE; | ||
1172 | |||
1173 | window = CRB_HI(off); | ||
1174 | |||
1175 | writel(window, addr); | ||
1176 | if (readl(addr) != window) { | ||
1177 | if (printk_ratelimit()) | ||
1178 | dev_warn(&adapter->pdev->dev, | ||
1179 | "failed to set CRB window to %d off 0x%lx\n", | ||
1180 | window, off); | ||
1181 | } | ||
1182 | } | ||
1183 | |||
1184 | static void __iomem * | ||
1185 | netxen_nic_map_indirect_address_128M(struct netxen_adapter *adapter, | ||
1186 | ulong win_off, void __iomem **mem_ptr) | ||
1187 | { | ||
1188 | ulong off = win_off; | ||
1189 | void __iomem *addr; | ||
1190 | resource_size_t mem_base; | ||
1191 | |||
1192 | if (ADDR_IN_WINDOW1(win_off)) | ||
1193 | off = NETXEN_CRB_NORMAL(win_off); | ||
1194 | |||
1195 | addr = pci_base_offset(adapter, off); | ||
1196 | if (addr) | ||
1197 | return addr; | ||
1198 | |||
1199 | if (adapter->ahw.pci_len0 == 0) | ||
1200 | off -= NETXEN_PCI_CRBSPACE; | ||
1201 | |||
1202 | mem_base = pci_resource_start(adapter->pdev, 0); | ||
1203 | *mem_ptr = ioremap(mem_base + (off & PAGE_MASK), PAGE_SIZE); | ||
1204 | if (*mem_ptr) | ||
1205 | addr = *mem_ptr + (off & (PAGE_SIZE - 1)); | ||
1206 | |||
1207 | return addr; | ||
1208 | } | ||
1209 | |||
1210 | static int | ||
1211 | netxen_nic_hw_write_wx_128M(struct netxen_adapter *adapter, ulong off, u32 data) | ||
1212 | { | ||
1213 | unsigned long flags; | ||
1214 | void __iomem *addr, *mem_ptr = NULL; | ||
1215 | |||
1216 | addr = netxen_nic_map_indirect_address_128M(adapter, off, &mem_ptr); | ||
1217 | if (!addr) | ||
1218 | return -EIO; | ||
1219 | |||
1220 | if (ADDR_IN_WINDOW1(off)) { /* Window 1 */ | ||
1221 | netxen_nic_io_write_128M(adapter, addr, data); | ||
1222 | } else { /* Window 0 */ | ||
1223 | write_lock_irqsave(&adapter->ahw.crb_lock, flags); | ||
1224 | netxen_nic_pci_set_crbwindow_128M(adapter, 0); | ||
1225 | writel(data, addr); | ||
1226 | netxen_nic_pci_set_crbwindow_128M(adapter, | ||
1227 | NETXEN_WINDOW_ONE); | ||
1228 | write_unlock_irqrestore(&adapter->ahw.crb_lock, flags); | ||
1229 | } | ||
1230 | |||
1231 | if (mem_ptr) | ||
1232 | iounmap(mem_ptr); | ||
1233 | |||
1234 | return 0; | ||
1235 | } | ||
1236 | |||
1237 | static u32 | ||
1238 | netxen_nic_hw_read_wx_128M(struct netxen_adapter *adapter, ulong off) | ||
1239 | { | ||
1240 | unsigned long flags; | ||
1241 | void __iomem *addr, *mem_ptr = NULL; | ||
1242 | u32 data; | ||
1243 | |||
1244 | addr = netxen_nic_map_indirect_address_128M(adapter, off, &mem_ptr); | ||
1245 | if (!addr) | ||
1246 | return -EIO; | ||
1247 | |||
1248 | if (ADDR_IN_WINDOW1(off)) { /* Window 1 */ | ||
1249 | data = netxen_nic_io_read_128M(adapter, addr); | ||
1250 | } else { /* Window 0 */ | ||
1251 | write_lock_irqsave(&adapter->ahw.crb_lock, flags); | ||
1252 | netxen_nic_pci_set_crbwindow_128M(adapter, 0); | ||
1253 | data = readl(addr); | ||
1254 | netxen_nic_pci_set_crbwindow_128M(adapter, | ||
1255 | NETXEN_WINDOW_ONE); | ||
1256 | write_unlock_irqrestore(&adapter->ahw.crb_lock, flags); | ||
1257 | } | ||
1258 | |||
1259 | if (mem_ptr) | ||
1260 | iounmap(mem_ptr); | ||
1261 | |||
1262 | return data; | ||
1263 | } | ||
1264 | |||
1265 | static int | ||
1266 | netxen_nic_hw_write_wx_2M(struct netxen_adapter *adapter, ulong off, u32 data) | ||
1267 | { | ||
1268 | unsigned long flags; | ||
1269 | int rv; | ||
1270 | void __iomem *addr = NULL; | ||
1271 | |||
1272 | rv = netxen_nic_pci_get_crb_addr_2M(adapter, off, &addr); | ||
1273 | |||
1274 | if (rv == 0) { | ||
1275 | writel(data, addr); | ||
1276 | return 0; | ||
1277 | } | ||
1278 | |||
1279 | if (rv > 0) { | ||
1280 | /* indirect access */ | ||
1281 | write_lock_irqsave(&adapter->ahw.crb_lock, flags); | ||
1282 | crb_win_lock(adapter); | ||
1283 | netxen_nic_pci_set_crbwindow_2M(adapter, off); | ||
1284 | writel(data, addr); | ||
1285 | crb_win_unlock(adapter); | ||
1286 | write_unlock_irqrestore(&adapter->ahw.crb_lock, flags); | ||
1287 | return 0; | ||
1288 | } | ||
1289 | |||
1290 | dev_err(&adapter->pdev->dev, | ||
1291 | "%s: invalid offset: 0x%016lx\n", __func__, off); | ||
1292 | dump_stack(); | ||
1293 | return -EIO; | ||
1294 | } | ||
1295 | |||
1296 | static u32 | ||
1297 | netxen_nic_hw_read_wx_2M(struct netxen_adapter *adapter, ulong off) | ||
1298 | { | ||
1299 | unsigned long flags; | ||
1300 | int rv; | ||
1301 | u32 data; | ||
1302 | void __iomem *addr = NULL; | ||
1303 | |||
1304 | rv = netxen_nic_pci_get_crb_addr_2M(adapter, off, &addr); | ||
1305 | |||
1306 | if (rv == 0) | ||
1307 | return readl(addr); | ||
1308 | |||
1309 | if (rv > 0) { | ||
1310 | /* indirect access */ | ||
1311 | write_lock_irqsave(&adapter->ahw.crb_lock, flags); | ||
1312 | crb_win_lock(adapter); | ||
1313 | netxen_nic_pci_set_crbwindow_2M(adapter, off); | ||
1314 | data = readl(addr); | ||
1315 | crb_win_unlock(adapter); | ||
1316 | write_unlock_irqrestore(&adapter->ahw.crb_lock, flags); | ||
1317 | return data; | ||
1318 | } | ||
1319 | |||
1320 | dev_err(&adapter->pdev->dev, | ||
1321 | "%s: invalid offset: 0x%016lx\n", __func__, off); | ||
1322 | dump_stack(); | ||
1323 | return -1; | ||
1324 | } | ||
1325 | |||
1326 | /* window 1 registers only */ | ||
1327 | static void netxen_nic_io_write_128M(struct netxen_adapter *adapter, | ||
1328 | void __iomem *addr, u32 data) | ||
1329 | { | ||
1330 | read_lock(&adapter->ahw.crb_lock); | ||
1331 | writel(data, addr); | ||
1332 | read_unlock(&adapter->ahw.crb_lock); | ||
1333 | } | ||
1334 | |||
1335 | static u32 netxen_nic_io_read_128M(struct netxen_adapter *adapter, | ||
1336 | void __iomem *addr) | ||
1337 | { | ||
1338 | u32 val; | ||
1339 | |||
1340 | read_lock(&adapter->ahw.crb_lock); | ||
1341 | val = readl(addr); | ||
1342 | read_unlock(&adapter->ahw.crb_lock); | ||
1343 | |||
1344 | return val; | ||
1345 | } | ||
1346 | |||
1347 | static void netxen_nic_io_write_2M(struct netxen_adapter *adapter, | ||
1348 | void __iomem *addr, u32 data) | ||
1349 | { | ||
1350 | writel(data, addr); | ||
1351 | } | ||
1352 | |||
1353 | static u32 netxen_nic_io_read_2M(struct netxen_adapter *adapter, | ||
1354 | void __iomem *addr) | ||
1355 | { | ||
1356 | return readl(addr); | ||
1357 | } | ||
1358 | |||
1359 | void __iomem * | ||
1360 | netxen_get_ioaddr(struct netxen_adapter *adapter, u32 offset) | ||
1361 | { | ||
1362 | void __iomem *addr = NULL; | ||
1363 | |||
1364 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) { | ||
1365 | if ((offset < NETXEN_CRB_PCIX_HOST2) && | ||
1366 | (offset > NETXEN_CRB_PCIX_HOST)) | ||
1367 | addr = PCI_OFFSET_SECOND_RANGE(adapter, offset); | ||
1368 | else | ||
1369 | addr = NETXEN_CRB_NORMALIZE(adapter, offset); | ||
1370 | } else { | ||
1371 | WARN_ON(netxen_nic_pci_get_crb_addr_2M(adapter, | ||
1372 | offset, &addr)); | ||
1373 | } | ||
1374 | |||
1375 | return addr; | ||
1376 | } | ||
1377 | |||
1378 | static int | ||
1379 | netxen_nic_pci_set_window_128M(struct netxen_adapter *adapter, | ||
1380 | u64 addr, u32 *start) | ||
1381 | { | ||
1382 | if (ADDR_IN_RANGE(addr, NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX)) { | ||
1383 | *start = (addr - NETXEN_ADDR_OCM0 + NETXEN_PCI_OCM0); | ||
1384 | return 0; | ||
1385 | } else if (ADDR_IN_RANGE(addr, | ||
1386 | NETXEN_ADDR_OCM1, NETXEN_ADDR_OCM1_MAX)) { | ||
1387 | *start = (addr - NETXEN_ADDR_OCM1 + NETXEN_PCI_OCM1); | ||
1388 | return 0; | ||
1389 | } | ||
1390 | |||
1391 | return -EIO; | ||
1392 | } | ||
1393 | |||
1394 | static int | ||
1395 | netxen_nic_pci_set_window_2M(struct netxen_adapter *adapter, | ||
1396 | u64 addr, u32 *start) | ||
1397 | { | ||
1398 | u32 window; | ||
1399 | |||
1400 | window = OCM_WIN(addr); | ||
1401 | |||
1402 | writel(window, adapter->ahw.ocm_win_crb); | ||
1403 | /* read back to flush */ | ||
1404 | readl(adapter->ahw.ocm_win_crb); | ||
1405 | |||
1406 | adapter->ahw.ocm_win = window; | ||
1407 | *start = NETXEN_PCI_OCM0_2M + GET_MEM_OFFS_2M(addr); | ||
1408 | return 0; | ||
1409 | } | ||
1410 | |||
1411 | static int | ||
1412 | netxen_nic_pci_mem_access_direct(struct netxen_adapter *adapter, u64 off, | ||
1413 | u64 *data, int op) | ||
1414 | { | ||
1415 | void __iomem *addr, *mem_ptr = NULL; | ||
1416 | resource_size_t mem_base; | ||
1417 | int ret; | ||
1418 | u32 start; | ||
1419 | |||
1420 | spin_lock(&adapter->ahw.mem_lock); | ||
1421 | |||
1422 | ret = adapter->pci_set_window(adapter, off, &start); | ||
1423 | if (ret != 0) | ||
1424 | goto unlock; | ||
1425 | |||
1426 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) { | ||
1427 | addr = adapter->ahw.pci_base0 + start; | ||
1428 | } else { | ||
1429 | addr = pci_base_offset(adapter, start); | ||
1430 | if (addr) | ||
1431 | goto noremap; | ||
1432 | |||
1433 | mem_base = pci_resource_start(adapter->pdev, 0) + | ||
1434 | (start & PAGE_MASK); | ||
1435 | mem_ptr = ioremap(mem_base, PAGE_SIZE); | ||
1436 | if (mem_ptr == NULL) { | ||
1437 | ret = -EIO; | ||
1438 | goto unlock; | ||
1439 | } | ||
1440 | |||
1441 | addr = mem_ptr + (start & (PAGE_SIZE-1)); | ||
1442 | } | ||
1443 | noremap: | ||
1444 | if (op == 0) /* read */ | ||
1445 | *data = readq(addr); | ||
1446 | else /* write */ | ||
1447 | writeq(*data, addr); | ||
1448 | |||
1449 | unlock: | ||
1450 | spin_unlock(&adapter->ahw.mem_lock); | ||
1451 | |||
1452 | if (mem_ptr) | ||
1453 | iounmap(mem_ptr); | ||
1454 | return ret; | ||
1455 | } | ||
1456 | |||
1457 | void | ||
1458 | netxen_pci_camqm_read_2M(struct netxen_adapter *adapter, u64 off, u64 *data) | ||
1459 | { | ||
1460 | void __iomem *addr = adapter->ahw.pci_base0 + | ||
1461 | NETXEN_PCI_CAMQM_2M_BASE + (off - NETXEN_PCI_CAMQM); | ||
1462 | |||
1463 | spin_lock(&adapter->ahw.mem_lock); | ||
1464 | *data = readq(addr); | ||
1465 | spin_unlock(&adapter->ahw.mem_lock); | ||
1466 | } | ||
1467 | |||
1468 | void | ||
1469 | netxen_pci_camqm_write_2M(struct netxen_adapter *adapter, u64 off, u64 data) | ||
1470 | { | ||
1471 | void __iomem *addr = adapter->ahw.pci_base0 + | ||
1472 | NETXEN_PCI_CAMQM_2M_BASE + (off - NETXEN_PCI_CAMQM); | ||
1473 | |||
1474 | spin_lock(&adapter->ahw.mem_lock); | ||
1475 | writeq(data, addr); | ||
1476 | spin_unlock(&adapter->ahw.mem_lock); | ||
1477 | } | ||
1478 | |||
1479 | #define MAX_CTL_CHECK 1000 | ||
1480 | |||
1481 | static int | ||
1482 | netxen_nic_pci_mem_write_128M(struct netxen_adapter *adapter, | ||
1483 | u64 off, u64 data) | ||
1484 | { | ||
1485 | int j, ret; | ||
1486 | u32 temp, off_lo, off_hi, addr_hi, data_hi, data_lo; | ||
1487 | void __iomem *mem_crb; | ||
1488 | |||
1489 | /* Only 64-bit aligned access */ | ||
1490 | if (off & 7) | ||
1491 | return -EIO; | ||
1492 | |||
1493 | /* P2 has different SIU and MIU test agent base addr */ | ||
1494 | if (ADDR_IN_RANGE(off, NETXEN_ADDR_QDR_NET, | ||
1495 | NETXEN_ADDR_QDR_NET_MAX_P2)) { | ||
1496 | mem_crb = pci_base_offset(adapter, | ||
1497 | NETXEN_CRB_QDR_NET+SIU_TEST_AGT_BASE); | ||
1498 | addr_hi = SIU_TEST_AGT_ADDR_HI; | ||
1499 | data_lo = SIU_TEST_AGT_WRDATA_LO; | ||
1500 | data_hi = SIU_TEST_AGT_WRDATA_HI; | ||
1501 | off_lo = off & SIU_TEST_AGT_ADDR_MASK; | ||
1502 | off_hi = SIU_TEST_AGT_UPPER_ADDR(off); | ||
1503 | goto correct; | ||
1504 | } | ||
1505 | |||
1506 | if (ADDR_IN_RANGE(off, NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX)) { | ||
1507 | mem_crb = pci_base_offset(adapter, | ||
1508 | NETXEN_CRB_DDR_NET+MIU_TEST_AGT_BASE); | ||
1509 | addr_hi = MIU_TEST_AGT_ADDR_HI; | ||
1510 | data_lo = MIU_TEST_AGT_WRDATA_LO; | ||
1511 | data_hi = MIU_TEST_AGT_WRDATA_HI; | ||
1512 | off_lo = off & MIU_TEST_AGT_ADDR_MASK; | ||
1513 | off_hi = 0; | ||
1514 | goto correct; | ||
1515 | } | ||
1516 | |||
1517 | if (ADDR_IN_RANGE(off, NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX) || | ||
1518 | ADDR_IN_RANGE(off, NETXEN_ADDR_OCM1, NETXEN_ADDR_OCM1_MAX)) { | ||
1519 | if (adapter->ahw.pci_len0 != 0) { | ||
1520 | return netxen_nic_pci_mem_access_direct(adapter, | ||
1521 | off, &data, 1); | ||
1522 | } | ||
1523 | } | ||
1524 | |||
1525 | return -EIO; | ||
1526 | |||
1527 | correct: | ||
1528 | spin_lock(&adapter->ahw.mem_lock); | ||
1529 | netxen_nic_pci_set_crbwindow_128M(adapter, 0); | ||
1530 | |||
1531 | writel(off_lo, (mem_crb + MIU_TEST_AGT_ADDR_LO)); | ||
1532 | writel(off_hi, (mem_crb + addr_hi)); | ||
1533 | writel(data & 0xffffffff, (mem_crb + data_lo)); | ||
1534 | writel((data >> 32) & 0xffffffff, (mem_crb + data_hi)); | ||
1535 | writel((TA_CTL_ENABLE | TA_CTL_WRITE), (mem_crb + TEST_AGT_CTRL)); | ||
1536 | writel((TA_CTL_START | TA_CTL_ENABLE | TA_CTL_WRITE), | ||
1537 | (mem_crb + TEST_AGT_CTRL)); | ||
1538 | |||
1539 | for (j = 0; j < MAX_CTL_CHECK; j++) { | ||
1540 | temp = readl((mem_crb + TEST_AGT_CTRL)); | ||
1541 | if ((temp & TA_CTL_BUSY) == 0) | ||
1542 | break; | ||
1543 | } | ||
1544 | |||
1545 | if (j >= MAX_CTL_CHECK) { | ||
1546 | if (printk_ratelimit()) | ||
1547 | dev_err(&adapter->pdev->dev, | ||
1548 | "failed to write through agent\n"); | ||
1549 | ret = -EIO; | ||
1550 | } else | ||
1551 | ret = 0; | ||
1552 | |||
1553 | netxen_nic_pci_set_crbwindow_128M(adapter, NETXEN_WINDOW_ONE); | ||
1554 | spin_unlock(&adapter->ahw.mem_lock); | ||
1555 | return ret; | ||
1556 | } | ||
1557 | |||
1558 | static int | ||
1559 | netxen_nic_pci_mem_read_128M(struct netxen_adapter *adapter, | ||
1560 | u64 off, u64 *data) | ||
1561 | { | ||
1562 | int j, ret; | ||
1563 | u32 temp, off_lo, off_hi, addr_hi, data_hi, data_lo; | ||
1564 | u64 val; | ||
1565 | void __iomem *mem_crb; | ||
1566 | |||
1567 | /* Only 64-bit aligned access */ | ||
1568 | if (off & 7) | ||
1569 | return -EIO; | ||
1570 | |||
1571 | /* P2 has different SIU and MIU test agent base addr */ | ||
1572 | if (ADDR_IN_RANGE(off, NETXEN_ADDR_QDR_NET, | ||
1573 | NETXEN_ADDR_QDR_NET_MAX_P2)) { | ||
1574 | mem_crb = pci_base_offset(adapter, | ||
1575 | NETXEN_CRB_QDR_NET+SIU_TEST_AGT_BASE); | ||
1576 | addr_hi = SIU_TEST_AGT_ADDR_HI; | ||
1577 | data_lo = SIU_TEST_AGT_RDDATA_LO; | ||
1578 | data_hi = SIU_TEST_AGT_RDDATA_HI; | ||
1579 | off_lo = off & SIU_TEST_AGT_ADDR_MASK; | ||
1580 | off_hi = SIU_TEST_AGT_UPPER_ADDR(off); | ||
1581 | goto correct; | ||
1582 | } | ||
1583 | |||
1584 | if (ADDR_IN_RANGE(off, NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX)) { | ||
1585 | mem_crb = pci_base_offset(adapter, | ||
1586 | NETXEN_CRB_DDR_NET+MIU_TEST_AGT_BASE); | ||
1587 | addr_hi = MIU_TEST_AGT_ADDR_HI; | ||
1588 | data_lo = MIU_TEST_AGT_RDDATA_LO; | ||
1589 | data_hi = MIU_TEST_AGT_RDDATA_HI; | ||
1590 | off_lo = off & MIU_TEST_AGT_ADDR_MASK; | ||
1591 | off_hi = 0; | ||
1592 | goto correct; | ||
1593 | } | ||
1594 | |||
1595 | if (ADDR_IN_RANGE(off, NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX) || | ||
1596 | ADDR_IN_RANGE(off, NETXEN_ADDR_OCM1, NETXEN_ADDR_OCM1_MAX)) { | ||
1597 | if (adapter->ahw.pci_len0 != 0) { | ||
1598 | return netxen_nic_pci_mem_access_direct(adapter, | ||
1599 | off, data, 0); | ||
1600 | } | ||
1601 | } | ||
1602 | |||
1603 | return -EIO; | ||
1604 | |||
1605 | correct: | ||
1606 | spin_lock(&adapter->ahw.mem_lock); | ||
1607 | netxen_nic_pci_set_crbwindow_128M(adapter, 0); | ||
1608 | |||
1609 | writel(off_lo, (mem_crb + MIU_TEST_AGT_ADDR_LO)); | ||
1610 | writel(off_hi, (mem_crb + addr_hi)); | ||
1611 | writel(TA_CTL_ENABLE, (mem_crb + TEST_AGT_CTRL)); | ||
1612 | writel((TA_CTL_START|TA_CTL_ENABLE), (mem_crb + TEST_AGT_CTRL)); | ||
1613 | |||
1614 | for (j = 0; j < MAX_CTL_CHECK; j++) { | ||
1615 | temp = readl(mem_crb + TEST_AGT_CTRL); | ||
1616 | if ((temp & TA_CTL_BUSY) == 0) | ||
1617 | break; | ||
1618 | } | ||
1619 | |||
1620 | if (j >= MAX_CTL_CHECK) { | ||
1621 | if (printk_ratelimit()) | ||
1622 | dev_err(&adapter->pdev->dev, | ||
1623 | "failed to read through agent\n"); | ||
1624 | ret = -EIO; | ||
1625 | } else { | ||
1626 | |||
1627 | temp = readl(mem_crb + data_hi); | ||
1628 | val = ((u64)temp << 32); | ||
1629 | val |= readl(mem_crb + data_lo); | ||
1630 | *data = val; | ||
1631 | ret = 0; | ||
1632 | } | ||
1633 | |||
1634 | netxen_nic_pci_set_crbwindow_128M(adapter, NETXEN_WINDOW_ONE); | ||
1635 | spin_unlock(&adapter->ahw.mem_lock); | ||
1636 | |||
1637 | return ret; | ||
1638 | } | ||
1639 | |||
1640 | static int | ||
1641 | netxen_nic_pci_mem_write_2M(struct netxen_adapter *adapter, | ||
1642 | u64 off, u64 data) | ||
1643 | { | ||
1644 | int j, ret; | ||
1645 | u32 temp, off8; | ||
1646 | void __iomem *mem_crb; | ||
1647 | |||
1648 | /* Only 64-bit aligned access */ | ||
1649 | if (off & 7) | ||
1650 | return -EIO; | ||
1651 | |||
1652 | /* P3 onward, test agent base for MIU and SIU is same */ | ||
1653 | if (ADDR_IN_RANGE(off, NETXEN_ADDR_QDR_NET, | ||
1654 | NETXEN_ADDR_QDR_NET_MAX_P3)) { | ||
1655 | mem_crb = netxen_get_ioaddr(adapter, | ||
1656 | NETXEN_CRB_QDR_NET+MIU_TEST_AGT_BASE); | ||
1657 | goto correct; | ||
1658 | } | ||
1659 | |||
1660 | if (ADDR_IN_RANGE(off, NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX)) { | ||
1661 | mem_crb = netxen_get_ioaddr(adapter, | ||
1662 | NETXEN_CRB_DDR_NET+MIU_TEST_AGT_BASE); | ||
1663 | goto correct; | ||
1664 | } | ||
1665 | |||
1666 | if (ADDR_IN_RANGE(off, NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX)) | ||
1667 | return netxen_nic_pci_mem_access_direct(adapter, off, &data, 1); | ||
1668 | |||
1669 | return -EIO; | ||
1670 | |||
1671 | correct: | ||
1672 | off8 = off & 0xfffffff8; | ||
1673 | |||
1674 | spin_lock(&adapter->ahw.mem_lock); | ||
1675 | |||
1676 | writel(off8, (mem_crb + MIU_TEST_AGT_ADDR_LO)); | ||
1677 | writel(0, (mem_crb + MIU_TEST_AGT_ADDR_HI)); | ||
1678 | |||
1679 | writel(data & 0xffffffff, | ||
1680 | mem_crb + MIU_TEST_AGT_WRDATA_LO); | ||
1681 | writel((data >> 32) & 0xffffffff, | ||
1682 | mem_crb + MIU_TEST_AGT_WRDATA_HI); | ||
1683 | |||
1684 | writel((TA_CTL_ENABLE | TA_CTL_WRITE), (mem_crb + TEST_AGT_CTRL)); | ||
1685 | writel((TA_CTL_START | TA_CTL_ENABLE | TA_CTL_WRITE), | ||
1686 | (mem_crb + TEST_AGT_CTRL)); | ||
1687 | |||
1688 | for (j = 0; j < MAX_CTL_CHECK; j++) { | ||
1689 | temp = readl(mem_crb + TEST_AGT_CTRL); | ||
1690 | if ((temp & TA_CTL_BUSY) == 0) | ||
1691 | break; | ||
1692 | } | ||
1693 | |||
1694 | if (j >= MAX_CTL_CHECK) { | ||
1695 | if (printk_ratelimit()) | ||
1696 | dev_err(&adapter->pdev->dev, | ||
1697 | "failed to write through agent\n"); | ||
1698 | ret = -EIO; | ||
1699 | } else | ||
1700 | ret = 0; | ||
1701 | |||
1702 | spin_unlock(&adapter->ahw.mem_lock); | ||
1703 | |||
1704 | return ret; | ||
1705 | } | ||
1706 | |||
1707 | static int | ||
1708 | netxen_nic_pci_mem_read_2M(struct netxen_adapter *adapter, | ||
1709 | u64 off, u64 *data) | ||
1710 | { | ||
1711 | int j, ret; | ||
1712 | u32 temp, off8; | ||
1713 | u64 val; | ||
1714 | void __iomem *mem_crb; | ||
1715 | |||
1716 | /* Only 64-bit aligned access */ | ||
1717 | if (off & 7) | ||
1718 | return -EIO; | ||
1719 | |||
1720 | /* P3 onward, test agent base for MIU and SIU is same */ | ||
1721 | if (ADDR_IN_RANGE(off, NETXEN_ADDR_QDR_NET, | ||
1722 | NETXEN_ADDR_QDR_NET_MAX_P3)) { | ||
1723 | mem_crb = netxen_get_ioaddr(adapter, | ||
1724 | NETXEN_CRB_QDR_NET+MIU_TEST_AGT_BASE); | ||
1725 | goto correct; | ||
1726 | } | ||
1727 | |||
1728 | if (ADDR_IN_RANGE(off, NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX)) { | ||
1729 | mem_crb = netxen_get_ioaddr(adapter, | ||
1730 | NETXEN_CRB_DDR_NET+MIU_TEST_AGT_BASE); | ||
1731 | goto correct; | ||
1732 | } | ||
1733 | |||
1734 | if (ADDR_IN_RANGE(off, NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX)) { | ||
1735 | return netxen_nic_pci_mem_access_direct(adapter, | ||
1736 | off, data, 0); | ||
1737 | } | ||
1738 | |||
1739 | return -EIO; | ||
1740 | |||
1741 | correct: | ||
1742 | off8 = off & 0xfffffff8; | ||
1743 | |||
1744 | spin_lock(&adapter->ahw.mem_lock); | ||
1745 | |||
1746 | writel(off8, (mem_crb + MIU_TEST_AGT_ADDR_LO)); | ||
1747 | writel(0, (mem_crb + MIU_TEST_AGT_ADDR_HI)); | ||
1748 | writel(TA_CTL_ENABLE, (mem_crb + TEST_AGT_CTRL)); | ||
1749 | writel((TA_CTL_START | TA_CTL_ENABLE), (mem_crb + TEST_AGT_CTRL)); | ||
1750 | |||
1751 | for (j = 0; j < MAX_CTL_CHECK; j++) { | ||
1752 | temp = readl(mem_crb + TEST_AGT_CTRL); | ||
1753 | if ((temp & TA_CTL_BUSY) == 0) | ||
1754 | break; | ||
1755 | } | ||
1756 | |||
1757 | if (j >= MAX_CTL_CHECK) { | ||
1758 | if (printk_ratelimit()) | ||
1759 | dev_err(&adapter->pdev->dev, | ||
1760 | "failed to read through agent\n"); | ||
1761 | ret = -EIO; | ||
1762 | } else { | ||
1763 | val = (u64)(readl(mem_crb + MIU_TEST_AGT_RDDATA_HI)) << 32; | ||
1764 | val |= readl(mem_crb + MIU_TEST_AGT_RDDATA_LO); | ||
1765 | *data = val; | ||
1766 | ret = 0; | ||
1767 | } | ||
1768 | |||
1769 | spin_unlock(&adapter->ahw.mem_lock); | ||
1770 | |||
1771 | return ret; | ||
1772 | } | ||
1773 | |||
1774 | void | ||
1775 | netxen_setup_hwops(struct netxen_adapter *adapter) | ||
1776 | { | ||
1777 | adapter->init_port = netxen_niu_xg_init_port; | ||
1778 | adapter->stop_port = netxen_niu_disable_xg_port; | ||
1779 | |||
1780 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) { | ||
1781 | adapter->crb_read = netxen_nic_hw_read_wx_128M, | ||
1782 | adapter->crb_write = netxen_nic_hw_write_wx_128M, | ||
1783 | adapter->pci_set_window = netxen_nic_pci_set_window_128M, | ||
1784 | adapter->pci_mem_read = netxen_nic_pci_mem_read_128M, | ||
1785 | adapter->pci_mem_write = netxen_nic_pci_mem_write_128M, | ||
1786 | adapter->io_read = netxen_nic_io_read_128M, | ||
1787 | adapter->io_write = netxen_nic_io_write_128M, | ||
1788 | |||
1789 | adapter->macaddr_set = netxen_p2_nic_set_mac_addr; | ||
1790 | adapter->set_multi = netxen_p2_nic_set_multi; | ||
1791 | adapter->set_mtu = netxen_nic_set_mtu_xgb; | ||
1792 | adapter->set_promisc = netxen_p2_nic_set_promisc; | ||
1793 | |||
1794 | } else { | ||
1795 | adapter->crb_read = netxen_nic_hw_read_wx_2M, | ||
1796 | adapter->crb_write = netxen_nic_hw_write_wx_2M, | ||
1797 | adapter->pci_set_window = netxen_nic_pci_set_window_2M, | ||
1798 | adapter->pci_mem_read = netxen_nic_pci_mem_read_2M, | ||
1799 | adapter->pci_mem_write = netxen_nic_pci_mem_write_2M, | ||
1800 | adapter->io_read = netxen_nic_io_read_2M, | ||
1801 | adapter->io_write = netxen_nic_io_write_2M, | ||
1802 | |||
1803 | adapter->set_mtu = nx_fw_cmd_set_mtu; | ||
1804 | adapter->set_promisc = netxen_p3_nic_set_promisc; | ||
1805 | adapter->macaddr_set = netxen_p3_nic_set_mac_addr; | ||
1806 | adapter->set_multi = netxen_p3_nic_set_multi; | ||
1807 | |||
1808 | adapter->phy_read = nx_fw_cmd_query_phy; | ||
1809 | adapter->phy_write = nx_fw_cmd_set_phy; | ||
1810 | } | ||
1811 | } | ||
1812 | |||
1813 | int netxen_nic_get_board_info(struct netxen_adapter *adapter) | ||
1814 | { | ||
1815 | int offset, board_type, magic; | ||
1816 | struct pci_dev *pdev = adapter->pdev; | ||
1817 | |||
1818 | offset = NX_FW_MAGIC_OFFSET; | ||
1819 | if (netxen_rom_fast_read(adapter, offset, &magic)) | ||
1820 | return -EIO; | ||
1821 | |||
1822 | if (magic != NETXEN_BDINFO_MAGIC) { | ||
1823 | dev_err(&pdev->dev, "invalid board config, magic=%08x\n", | ||
1824 | magic); | ||
1825 | return -EIO; | ||
1826 | } | ||
1827 | |||
1828 | offset = NX_BRDTYPE_OFFSET; | ||
1829 | if (netxen_rom_fast_read(adapter, offset, &board_type)) | ||
1830 | return -EIO; | ||
1831 | |||
1832 | if (board_type == NETXEN_BRDTYPE_P3_4_GB_MM) { | ||
1833 | u32 gpio = NXRD32(adapter, NETXEN_ROMUSB_GLB_PAD_GPIO_I); | ||
1834 | if ((gpio & 0x8000) == 0) | ||
1835 | board_type = NETXEN_BRDTYPE_P3_10G_TP; | ||
1836 | } | ||
1837 | |||
1838 | adapter->ahw.board_type = board_type; | ||
1839 | |||
1840 | switch (board_type) { | ||
1841 | case NETXEN_BRDTYPE_P2_SB35_4G: | ||
1842 | adapter->ahw.port_type = NETXEN_NIC_GBE; | ||
1843 | break; | ||
1844 | case NETXEN_BRDTYPE_P2_SB31_10G: | ||
1845 | case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ: | ||
1846 | case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ: | ||
1847 | case NETXEN_BRDTYPE_P2_SB31_10G_CX4: | ||
1848 | case NETXEN_BRDTYPE_P3_HMEZ: | ||
1849 | case NETXEN_BRDTYPE_P3_XG_LOM: | ||
1850 | case NETXEN_BRDTYPE_P3_10G_CX4: | ||
1851 | case NETXEN_BRDTYPE_P3_10G_CX4_LP: | ||
1852 | case NETXEN_BRDTYPE_P3_IMEZ: | ||
1853 | case NETXEN_BRDTYPE_P3_10G_SFP_PLUS: | ||
1854 | case NETXEN_BRDTYPE_P3_10G_SFP_CT: | ||
1855 | case NETXEN_BRDTYPE_P3_10G_SFP_QT: | ||
1856 | case NETXEN_BRDTYPE_P3_10G_XFP: | ||
1857 | case NETXEN_BRDTYPE_P3_10000_BASE_T: | ||
1858 | adapter->ahw.port_type = NETXEN_NIC_XGBE; | ||
1859 | break; | ||
1860 | case NETXEN_BRDTYPE_P1_BD: | ||
1861 | case NETXEN_BRDTYPE_P1_SB: | ||
1862 | case NETXEN_BRDTYPE_P1_SMAX: | ||
1863 | case NETXEN_BRDTYPE_P1_SOCK: | ||
1864 | case NETXEN_BRDTYPE_P3_REF_QG: | ||
1865 | case NETXEN_BRDTYPE_P3_4_GB: | ||
1866 | case NETXEN_BRDTYPE_P3_4_GB_MM: | ||
1867 | adapter->ahw.port_type = NETXEN_NIC_GBE; | ||
1868 | break; | ||
1869 | case NETXEN_BRDTYPE_P3_10G_TP: | ||
1870 | adapter->ahw.port_type = (adapter->portnum < 2) ? | ||
1871 | NETXEN_NIC_XGBE : NETXEN_NIC_GBE; | ||
1872 | break; | ||
1873 | default: | ||
1874 | dev_err(&pdev->dev, "unknown board type %x\n", board_type); | ||
1875 | adapter->ahw.port_type = NETXEN_NIC_XGBE; | ||
1876 | break; | ||
1877 | } | ||
1878 | |||
1879 | return 0; | ||
1880 | } | ||
1881 | |||
1882 | /* NIU access sections */ | ||
1883 | static int netxen_nic_set_mtu_xgb(struct netxen_adapter *adapter, int new_mtu) | ||
1884 | { | ||
1885 | new_mtu += MTU_FUDGE_FACTOR; | ||
1886 | if (adapter->physical_port == 0) | ||
1887 | NXWR32(adapter, NETXEN_NIU_XGE_MAX_FRAME_SIZE, new_mtu); | ||
1888 | else | ||
1889 | NXWR32(adapter, NETXEN_NIU_XG1_MAX_FRAME_SIZE, new_mtu); | ||
1890 | return 0; | ||
1891 | } | ||
1892 | |||
1893 | void netxen_nic_set_link_parameters(struct netxen_adapter *adapter) | ||
1894 | { | ||
1895 | __u32 status; | ||
1896 | __u32 autoneg; | ||
1897 | __u32 port_mode; | ||
1898 | |||
1899 | if (!netif_carrier_ok(adapter->netdev)) { | ||
1900 | adapter->link_speed = 0; | ||
1901 | adapter->link_duplex = -1; | ||
1902 | adapter->link_autoneg = AUTONEG_ENABLE; | ||
1903 | return; | ||
1904 | } | ||
1905 | |||
1906 | if (adapter->ahw.port_type == NETXEN_NIC_GBE) { | ||
1907 | port_mode = NXRD32(adapter, NETXEN_PORT_MODE_ADDR); | ||
1908 | if (port_mode == NETXEN_PORT_MODE_802_3_AP) { | ||
1909 | adapter->link_speed = SPEED_1000; | ||
1910 | adapter->link_duplex = DUPLEX_FULL; | ||
1911 | adapter->link_autoneg = AUTONEG_DISABLE; | ||
1912 | return; | ||
1913 | } | ||
1914 | |||
1915 | if (adapter->phy_read && | ||
1916 | adapter->phy_read(adapter, | ||
1917 | NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS, | ||
1918 | &status) == 0) { | ||
1919 | if (netxen_get_phy_link(status)) { | ||
1920 | switch (netxen_get_phy_speed(status)) { | ||
1921 | case 0: | ||
1922 | adapter->link_speed = SPEED_10; | ||
1923 | break; | ||
1924 | case 1: | ||
1925 | adapter->link_speed = SPEED_100; | ||
1926 | break; | ||
1927 | case 2: | ||
1928 | adapter->link_speed = SPEED_1000; | ||
1929 | break; | ||
1930 | default: | ||
1931 | adapter->link_speed = 0; | ||
1932 | break; | ||
1933 | } | ||
1934 | switch (netxen_get_phy_duplex(status)) { | ||
1935 | case 0: | ||
1936 | adapter->link_duplex = DUPLEX_HALF; | ||
1937 | break; | ||
1938 | case 1: | ||
1939 | adapter->link_duplex = DUPLEX_FULL; | ||
1940 | break; | ||
1941 | default: | ||
1942 | adapter->link_duplex = -1; | ||
1943 | break; | ||
1944 | } | ||
1945 | if (adapter->phy_read && | ||
1946 | adapter->phy_read(adapter, | ||
1947 | NETXEN_NIU_GB_MII_MGMT_ADDR_AUTONEG, | ||
1948 | &autoneg) != 0) | ||
1949 | adapter->link_autoneg = autoneg; | ||
1950 | } else | ||
1951 | goto link_down; | ||
1952 | } else { | ||
1953 | link_down: | ||
1954 | adapter->link_speed = 0; | ||
1955 | adapter->link_duplex = -1; | ||
1956 | } | ||
1957 | } | ||
1958 | } | ||
1959 | |||
1960 | int | ||
1961 | netxen_nic_wol_supported(struct netxen_adapter *adapter) | ||
1962 | { | ||
1963 | u32 wol_cfg; | ||
1964 | |||
1965 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) | ||
1966 | return 0; | ||
1967 | |||
1968 | wol_cfg = NXRD32(adapter, NETXEN_WOL_CONFIG_NV); | ||
1969 | if (wol_cfg & (1UL << adapter->portnum)) { | ||
1970 | wol_cfg = NXRD32(adapter, NETXEN_WOL_CONFIG); | ||
1971 | if (wol_cfg & (1 << adapter->portnum)) | ||
1972 | return 1; | ||
1973 | } | ||
1974 | |||
1975 | return 0; | ||
1976 | } | ||
diff --git a/drivers/net/ethernet/qlogic/netxen/netxen_nic_hw.h b/drivers/net/ethernet/qlogic/netxen/netxen_nic_hw.h new file mode 100644 index 000000000000..e2c5b6f2df03 --- /dev/null +++ b/drivers/net/ethernet/qlogic/netxen/netxen_nic_hw.h | |||
@@ -0,0 +1,287 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2003 - 2009 NetXen, Inc. | ||
3 | * Copyright (C) 2009 - QLogic Corporation. | ||
4 | * All rights reserved. | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or | ||
7 | * modify it under the terms of the GNU General Public License | ||
8 | * as published by the Free Software Foundation; either version 2 | ||
9 | * of the License, or (at your option) any later version. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, but | ||
12 | * 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, | ||
19 | * MA 02111-1307, USA. | ||
20 | * | ||
21 | * The full GNU General Public License is included in this distribution | ||
22 | * in the file called "COPYING". | ||
23 | * | ||
24 | */ | ||
25 | |||
26 | #ifndef __NETXEN_NIC_HW_H_ | ||
27 | #define __NETXEN_NIC_HW_H_ | ||
28 | |||
29 | /* Hardware memory size of 128 meg */ | ||
30 | #define NETXEN_MEMADDR_MAX (128 * 1024 * 1024) | ||
31 | |||
32 | struct netxen_adapter; | ||
33 | |||
34 | #define NETXEN_PCI_MAPSIZE_BYTES (NETXEN_PCI_MAPSIZE << 20) | ||
35 | |||
36 | void netxen_nic_set_link_parameters(struct netxen_adapter *adapter); | ||
37 | |||
38 | /* Nibble or Byte mode for phy interface (GbE mode only) */ | ||
39 | |||
40 | #define _netxen_crb_get_bit(var, bit) ((var >> bit) & 0x1) | ||
41 | |||
42 | /* | ||
43 | * NIU GB MAC Config Register 0 (applies to GB0, GB1, GB2, GB3) | ||
44 | * | ||
45 | * Bit 0 : enable_tx => 1:enable frame xmit, 0:disable | ||
46 | * Bit 1 : tx_synced => R/O: xmit enable synched to xmit stream | ||
47 | * Bit 2 : enable_rx => 1:enable frame recv, 0:disable | ||
48 | * Bit 3 : rx_synced => R/O: recv enable synched to recv stream | ||
49 | * Bit 4 : tx_flowctl => 1:enable pause frame generation, 0:disable | ||
50 | * Bit 5 : rx_flowctl => 1:act on recv'd pause frames, 0:ignore | ||
51 | * Bit 8 : loopback => 1:loop MAC xmits to MAC recvs, 0:normal | ||
52 | * Bit 16: tx_reset_pb => 1:reset frame xmit protocol blk, 0:no-op | ||
53 | * Bit 17: rx_reset_pb => 1:reset frame recv protocol blk, 0:no-op | ||
54 | * Bit 18: tx_reset_mac => 1:reset data/ctl multiplexer blk, 0:no-op | ||
55 | * Bit 19: rx_reset_mac => 1:reset ctl frames & timers blk, 0:no-op | ||
56 | * Bit 31: soft_reset => 1:reset the MAC and the SERDES, 0:no-op | ||
57 | */ | ||
58 | |||
59 | #define netxen_gb_tx_flowctl(config_word) \ | ||
60 | ((config_word) |= 1 << 4) | ||
61 | #define netxen_gb_rx_flowctl(config_word) \ | ||
62 | ((config_word) |= 1 << 5) | ||
63 | #define netxen_gb_tx_reset_pb(config_word) \ | ||
64 | ((config_word) |= 1 << 16) | ||
65 | #define netxen_gb_rx_reset_pb(config_word) \ | ||
66 | ((config_word) |= 1 << 17) | ||
67 | #define netxen_gb_tx_reset_mac(config_word) \ | ||
68 | ((config_word) |= 1 << 18) | ||
69 | #define netxen_gb_rx_reset_mac(config_word) \ | ||
70 | ((config_word) |= 1 << 19) | ||
71 | |||
72 | #define netxen_gb_unset_tx_flowctl(config_word) \ | ||
73 | ((config_word) &= ~(1 << 4)) | ||
74 | #define netxen_gb_unset_rx_flowctl(config_word) \ | ||
75 | ((config_word) &= ~(1 << 5)) | ||
76 | |||
77 | #define netxen_gb_get_tx_synced(config_word) \ | ||
78 | _netxen_crb_get_bit((config_word), 1) | ||
79 | #define netxen_gb_get_rx_synced(config_word) \ | ||
80 | _netxen_crb_get_bit((config_word), 3) | ||
81 | #define netxen_gb_get_tx_flowctl(config_word) \ | ||
82 | _netxen_crb_get_bit((config_word), 4) | ||
83 | #define netxen_gb_get_rx_flowctl(config_word) \ | ||
84 | _netxen_crb_get_bit((config_word), 5) | ||
85 | #define netxen_gb_get_soft_reset(config_word) \ | ||
86 | _netxen_crb_get_bit((config_word), 31) | ||
87 | |||
88 | #define netxen_gb_get_stationaddress_low(config_word) ((config_word) >> 16) | ||
89 | |||
90 | #define netxen_gb_set_mii_mgmt_clockselect(config_word, val) \ | ||
91 | ((config_word) |= ((val) & 0x07)) | ||
92 | #define netxen_gb_mii_mgmt_reset(config_word) \ | ||
93 | ((config_word) |= 1 << 31) | ||
94 | #define netxen_gb_mii_mgmt_unset(config_word) \ | ||
95 | ((config_word) &= ~(1 << 31)) | ||
96 | |||
97 | /* | ||
98 | * NIU GB MII Mgmt Command Register (applies to GB0, GB1, GB2, GB3) | ||
99 | * Bit 0 : read_cycle => 1:perform single read cycle, 0:no-op | ||
100 | * Bit 1 : scan_cycle => 1:perform continuous read cycles, 0:no-op | ||
101 | */ | ||
102 | |||
103 | #define netxen_gb_mii_mgmt_set_read_cycle(config_word) \ | ||
104 | ((config_word) |= 1 << 0) | ||
105 | #define netxen_gb_mii_mgmt_reg_addr(config_word, val) \ | ||
106 | ((config_word) |= ((val) & 0x1F)) | ||
107 | #define netxen_gb_mii_mgmt_phy_addr(config_word, val) \ | ||
108 | ((config_word) |= (((val) & 0x1F) << 8)) | ||
109 | |||
110 | /* | ||
111 | * NIU GB MII Mgmt Indicators Register (applies to GB0, GB1, GB2, GB3) | ||
112 | * Read-only register. | ||
113 | * Bit 0 : busy => 1:performing an MII mgmt cycle, 0:idle | ||
114 | * Bit 1 : scanning => 1:scan operation in progress, 0:idle | ||
115 | * Bit 2 : notvalid => :mgmt result data not yet valid, 0:idle | ||
116 | */ | ||
117 | #define netxen_get_gb_mii_mgmt_busy(config_word) \ | ||
118 | _netxen_crb_get_bit(config_word, 0) | ||
119 | #define netxen_get_gb_mii_mgmt_scanning(config_word) \ | ||
120 | _netxen_crb_get_bit(config_word, 1) | ||
121 | #define netxen_get_gb_mii_mgmt_notvalid(config_word) \ | ||
122 | _netxen_crb_get_bit(config_word, 2) | ||
123 | /* | ||
124 | * NIU XG Pause Ctl Register | ||
125 | * | ||
126 | * Bit 0 : xg0_mask => 1:disable tx pause frames | ||
127 | * Bit 1 : xg0_request => 1:request single pause frame | ||
128 | * Bit 2 : xg0_on_off => 1:request is pause on, 0:off | ||
129 | * Bit 3 : xg1_mask => 1:disable tx pause frames | ||
130 | * Bit 4 : xg1_request => 1:request single pause frame | ||
131 | * Bit 5 : xg1_on_off => 1:request is pause on, 0:off | ||
132 | */ | ||
133 | |||
134 | #define netxen_xg_set_xg0_mask(config_word) \ | ||
135 | ((config_word) |= 1 << 0) | ||
136 | #define netxen_xg_set_xg1_mask(config_word) \ | ||
137 | ((config_word) |= 1 << 3) | ||
138 | |||
139 | #define netxen_xg_get_xg0_mask(config_word) \ | ||
140 | _netxen_crb_get_bit((config_word), 0) | ||
141 | #define netxen_xg_get_xg1_mask(config_word) \ | ||
142 | _netxen_crb_get_bit((config_word), 3) | ||
143 | |||
144 | #define netxen_xg_unset_xg0_mask(config_word) \ | ||
145 | ((config_word) &= ~(1 << 0)) | ||
146 | #define netxen_xg_unset_xg1_mask(config_word) \ | ||
147 | ((config_word) &= ~(1 << 3)) | ||
148 | |||
149 | /* | ||
150 | * NIU XG Pause Ctl Register | ||
151 | * | ||
152 | * Bit 0 : xg0_mask => 1:disable tx pause frames | ||
153 | * Bit 1 : xg0_request => 1:request single pause frame | ||
154 | * Bit 2 : xg0_on_off => 1:request is pause on, 0:off | ||
155 | * Bit 3 : xg1_mask => 1:disable tx pause frames | ||
156 | * Bit 4 : xg1_request => 1:request single pause frame | ||
157 | * Bit 5 : xg1_on_off => 1:request is pause on, 0:off | ||
158 | */ | ||
159 | #define netxen_gb_set_gb0_mask(config_word) \ | ||
160 | ((config_word) |= 1 << 0) | ||
161 | #define netxen_gb_set_gb1_mask(config_word) \ | ||
162 | ((config_word) |= 1 << 2) | ||
163 | #define netxen_gb_set_gb2_mask(config_word) \ | ||
164 | ((config_word) |= 1 << 4) | ||
165 | #define netxen_gb_set_gb3_mask(config_word) \ | ||
166 | ((config_word) |= 1 << 6) | ||
167 | |||
168 | #define netxen_gb_get_gb0_mask(config_word) \ | ||
169 | _netxen_crb_get_bit((config_word), 0) | ||
170 | #define netxen_gb_get_gb1_mask(config_word) \ | ||
171 | _netxen_crb_get_bit((config_word), 2) | ||
172 | #define netxen_gb_get_gb2_mask(config_word) \ | ||
173 | _netxen_crb_get_bit((config_word), 4) | ||
174 | #define netxen_gb_get_gb3_mask(config_word) \ | ||
175 | _netxen_crb_get_bit((config_word), 6) | ||
176 | |||
177 | #define netxen_gb_unset_gb0_mask(config_word) \ | ||
178 | ((config_word) &= ~(1 << 0)) | ||
179 | #define netxen_gb_unset_gb1_mask(config_word) \ | ||
180 | ((config_word) &= ~(1 << 2)) | ||
181 | #define netxen_gb_unset_gb2_mask(config_word) \ | ||
182 | ((config_word) &= ~(1 << 4)) | ||
183 | #define netxen_gb_unset_gb3_mask(config_word) \ | ||
184 | ((config_word) &= ~(1 << 6)) | ||
185 | |||
186 | |||
187 | /* | ||
188 | * PHY-Specific MII control/status registers. | ||
189 | */ | ||
190 | #define NETXEN_NIU_GB_MII_MGMT_ADDR_CONTROL 0 | ||
191 | #define NETXEN_NIU_GB_MII_MGMT_ADDR_STATUS 1 | ||
192 | #define NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_ID_0 2 | ||
193 | #define NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_ID_1 3 | ||
194 | #define NETXEN_NIU_GB_MII_MGMT_ADDR_AUTONEG 4 | ||
195 | #define NETXEN_NIU_GB_MII_MGMT_ADDR_LNKPART 5 | ||
196 | #define NETXEN_NIU_GB_MII_MGMT_ADDR_AUTONEG_MORE 6 | ||
197 | #define NETXEN_NIU_GB_MII_MGMT_ADDR_NEXTPAGE_XMIT 7 | ||
198 | #define NETXEN_NIU_GB_MII_MGMT_ADDR_LNKPART_NEXTPAGE 8 | ||
199 | #define NETXEN_NIU_GB_MII_MGMT_ADDR_1000BT_CONTROL 9 | ||
200 | #define NETXEN_NIU_GB_MII_MGMT_ADDR_1000BT_STATUS 10 | ||
201 | #define NETXEN_NIU_GB_MII_MGMT_ADDR_EXTENDED_STATUS 15 | ||
202 | #define NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_CONTROL 16 | ||
203 | #define NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS 17 | ||
204 | #define NETXEN_NIU_GB_MII_MGMT_ADDR_INT_ENABLE 18 | ||
205 | #define NETXEN_NIU_GB_MII_MGMT_ADDR_INT_STATUS 19 | ||
206 | #define NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_CONTROL_MORE 20 | ||
207 | #define NETXEN_NIU_GB_MII_MGMT_ADDR_RECV_ERROR_COUNT 21 | ||
208 | #define NETXEN_NIU_GB_MII_MGMT_ADDR_LED_CONTROL 24 | ||
209 | #define NETXEN_NIU_GB_MII_MGMT_ADDR_LED_OVERRIDE 25 | ||
210 | #define NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_CONTROL_MORE_YET 26 | ||
211 | #define NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS_MORE 27 | ||
212 | |||
213 | /* | ||
214 | * PHY-Specific Status Register (reg 17). | ||
215 | * | ||
216 | * Bit 0 : jabber => 1:jabber detected, 0:not | ||
217 | * Bit 1 : polarity => 1:polarity reversed, 0:normal | ||
218 | * Bit 2 : recvpause => 1:receive pause enabled, 0:disabled | ||
219 | * Bit 3 : xmitpause => 1:transmit pause enabled, 0:disabled | ||
220 | * Bit 4 : energydetect => 1:sleep, 0:active | ||
221 | * Bit 5 : downshift => 1:downshift, 0:no downshift | ||
222 | * Bit 6 : crossover => 1:MDIX (crossover), 0:MDI (no crossover) | ||
223 | * Bits 7-9 : cablelen => not valid in 10Mb/s mode | ||
224 | * 0:<50m, 1:50-80m, 2:80-110m, 3:110-140m, 4:>140m | ||
225 | * Bit 10 : link => 1:link up, 0:link down | ||
226 | * Bit 11 : resolved => 1:speed and duplex resolved, 0:not yet | ||
227 | * Bit 12 : pagercvd => 1:page received, 0:page not received | ||
228 | * Bit 13 : duplex => 1:full duplex, 0:half duplex | ||
229 | * Bits 14-15 : speed => 0:10Mb/s, 1:100Mb/s, 2:1000Mb/s, 3:rsvd | ||
230 | */ | ||
231 | |||
232 | #define netxen_get_phy_speed(config_word) (((config_word) >> 14) & 0x03) | ||
233 | |||
234 | #define netxen_set_phy_speed(config_word, val) \ | ||
235 | ((config_word) |= ((val & 0x03) << 14)) | ||
236 | #define netxen_set_phy_duplex(config_word) \ | ||
237 | ((config_word) |= 1 << 13) | ||
238 | #define netxen_clear_phy_duplex(config_word) \ | ||
239 | ((config_word) &= ~(1 << 13)) | ||
240 | |||
241 | #define netxen_get_phy_link(config_word) \ | ||
242 | _netxen_crb_get_bit(config_word, 10) | ||
243 | #define netxen_get_phy_duplex(config_word) \ | ||
244 | _netxen_crb_get_bit(config_word, 13) | ||
245 | |||
246 | /* | ||
247 | * NIU Mode Register. | ||
248 | * Bit 0 : enable FibreChannel | ||
249 | * Bit 1 : enable 10/100/1000 Ethernet | ||
250 | * Bit 2 : enable 10Gb Ethernet | ||
251 | */ | ||
252 | |||
253 | #define netxen_get_niu_enable_ge(config_word) \ | ||
254 | _netxen_crb_get_bit(config_word, 1) | ||
255 | |||
256 | #define NETXEN_NIU_NON_PROMISC_MODE 0 | ||
257 | #define NETXEN_NIU_PROMISC_MODE 1 | ||
258 | #define NETXEN_NIU_ALLMULTI_MODE 2 | ||
259 | |||
260 | /* | ||
261 | * NIU XG MAC Config Register | ||
262 | * | ||
263 | * Bit 0 : tx_enable => 1:enable frame xmit, 0:disable | ||
264 | * Bit 2 : rx_enable => 1:enable frame recv, 0:disable | ||
265 | * Bit 4 : soft_reset => 1:reset the MAC , 0:no-op | ||
266 | * Bit 27: xaui_framer_reset | ||
267 | * Bit 28: xaui_rx_reset | ||
268 | * Bit 29: xaui_tx_reset | ||
269 | * Bit 30: xg_ingress_afifo_reset | ||
270 | * Bit 31: xg_egress_afifo_reset | ||
271 | */ | ||
272 | |||
273 | #define netxen_xg_soft_reset(config_word) \ | ||
274 | ((config_word) |= 1 << 4) | ||
275 | |||
276 | typedef struct { | ||
277 | unsigned valid; | ||
278 | unsigned start_128M; | ||
279 | unsigned end_128M; | ||
280 | unsigned start_2M; | ||
281 | } crb_128M_2M_sub_block_map_t; | ||
282 | |||
283 | typedef struct { | ||
284 | crb_128M_2M_sub_block_map_t sub_block[16]; | ||
285 | } crb_128M_2M_block_map_t; | ||
286 | |||
287 | #endif /* __NETXEN_NIC_HW_H_ */ | ||
diff --git a/drivers/net/ethernet/qlogic/netxen/netxen_nic_init.c b/drivers/net/ethernet/qlogic/netxen/netxen_nic_init.c new file mode 100644 index 000000000000..d6c6357de6aa --- /dev/null +++ b/drivers/net/ethernet/qlogic/netxen/netxen_nic_init.c | |||
@@ -0,0 +1,1949 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2003 - 2009 NetXen, Inc. | ||
3 | * Copyright (C) 2009 - QLogic Corporation. | ||
4 | * All rights reserved. | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or | ||
7 | * modify it under the terms of the GNU General Public License | ||
8 | * as published by the Free Software Foundation; either version 2 | ||
9 | * of the License, or (at your option) any later version. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, but | ||
12 | * 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, | ||
19 | * MA 02111-1307, USA. | ||
20 | * | ||
21 | * The full GNU General Public License is included in this distribution | ||
22 | * in the file called "COPYING". | ||
23 | * | ||
24 | */ | ||
25 | |||
26 | #include <linux/netdevice.h> | ||
27 | #include <linux/delay.h> | ||
28 | #include <linux/slab.h> | ||
29 | #include <linux/if_vlan.h> | ||
30 | #include "netxen_nic.h" | ||
31 | #include "netxen_nic_hw.h" | ||
32 | |||
33 | struct crb_addr_pair { | ||
34 | u32 addr; | ||
35 | u32 data; | ||
36 | }; | ||
37 | |||
38 | #define NETXEN_MAX_CRB_XFORM 60 | ||
39 | static unsigned int crb_addr_xform[NETXEN_MAX_CRB_XFORM]; | ||
40 | #define NETXEN_ADDR_ERROR (0xffffffff) | ||
41 | |||
42 | #define crb_addr_transform(name) \ | ||
43 | crb_addr_xform[NETXEN_HW_PX_MAP_CRB_##name] = \ | ||
44 | NETXEN_HW_CRB_HUB_AGT_ADR_##name << 20 | ||
45 | |||
46 | #define NETXEN_NIC_XDMA_RESET 0x8000ff | ||
47 | |||
48 | static void | ||
49 | netxen_post_rx_buffers_nodb(struct netxen_adapter *adapter, | ||
50 | struct nx_host_rds_ring *rds_ring); | ||
51 | static int netxen_p3_has_mn(struct netxen_adapter *adapter); | ||
52 | |||
53 | static void crb_addr_transform_setup(void) | ||
54 | { | ||
55 | crb_addr_transform(XDMA); | ||
56 | crb_addr_transform(TIMR); | ||
57 | crb_addr_transform(SRE); | ||
58 | crb_addr_transform(SQN3); | ||
59 | crb_addr_transform(SQN2); | ||
60 | crb_addr_transform(SQN1); | ||
61 | crb_addr_transform(SQN0); | ||
62 | crb_addr_transform(SQS3); | ||
63 | crb_addr_transform(SQS2); | ||
64 | crb_addr_transform(SQS1); | ||
65 | crb_addr_transform(SQS0); | ||
66 | crb_addr_transform(RPMX7); | ||
67 | crb_addr_transform(RPMX6); | ||
68 | crb_addr_transform(RPMX5); | ||
69 | crb_addr_transform(RPMX4); | ||
70 | crb_addr_transform(RPMX3); | ||
71 | crb_addr_transform(RPMX2); | ||
72 | crb_addr_transform(RPMX1); | ||
73 | crb_addr_transform(RPMX0); | ||
74 | crb_addr_transform(ROMUSB); | ||
75 | crb_addr_transform(SN); | ||
76 | crb_addr_transform(QMN); | ||
77 | crb_addr_transform(QMS); | ||
78 | crb_addr_transform(PGNI); | ||
79 | crb_addr_transform(PGND); | ||
80 | crb_addr_transform(PGN3); | ||
81 | crb_addr_transform(PGN2); | ||
82 | crb_addr_transform(PGN1); | ||
83 | crb_addr_transform(PGN0); | ||
84 | crb_addr_transform(PGSI); | ||
85 | crb_addr_transform(PGSD); | ||
86 | crb_addr_transform(PGS3); | ||
87 | crb_addr_transform(PGS2); | ||
88 | crb_addr_transform(PGS1); | ||
89 | crb_addr_transform(PGS0); | ||
90 | crb_addr_transform(PS); | ||
91 | crb_addr_transform(PH); | ||
92 | crb_addr_transform(NIU); | ||
93 | crb_addr_transform(I2Q); | ||
94 | crb_addr_transform(EG); | ||
95 | crb_addr_transform(MN); | ||
96 | crb_addr_transform(MS); | ||
97 | crb_addr_transform(CAS2); | ||
98 | crb_addr_transform(CAS1); | ||
99 | crb_addr_transform(CAS0); | ||
100 | crb_addr_transform(CAM); | ||
101 | crb_addr_transform(C2C1); | ||
102 | crb_addr_transform(C2C0); | ||
103 | crb_addr_transform(SMB); | ||
104 | crb_addr_transform(OCM0); | ||
105 | crb_addr_transform(I2C0); | ||
106 | } | ||
107 | |||
108 | void netxen_release_rx_buffers(struct netxen_adapter *adapter) | ||
109 | { | ||
110 | struct netxen_recv_context *recv_ctx; | ||
111 | struct nx_host_rds_ring *rds_ring; | ||
112 | struct netxen_rx_buffer *rx_buf; | ||
113 | int i, ring; | ||
114 | |||
115 | recv_ctx = &adapter->recv_ctx; | ||
116 | for (ring = 0; ring < adapter->max_rds_rings; ring++) { | ||
117 | rds_ring = &recv_ctx->rds_rings[ring]; | ||
118 | for (i = 0; i < rds_ring->num_desc; ++i) { | ||
119 | rx_buf = &(rds_ring->rx_buf_arr[i]); | ||
120 | if (rx_buf->state == NETXEN_BUFFER_FREE) | ||
121 | continue; | ||
122 | pci_unmap_single(adapter->pdev, | ||
123 | rx_buf->dma, | ||
124 | rds_ring->dma_size, | ||
125 | PCI_DMA_FROMDEVICE); | ||
126 | if (rx_buf->skb != NULL) | ||
127 | dev_kfree_skb_any(rx_buf->skb); | ||
128 | } | ||
129 | } | ||
130 | } | ||
131 | |||
132 | void netxen_release_tx_buffers(struct netxen_adapter *adapter) | ||
133 | { | ||
134 | struct netxen_cmd_buffer *cmd_buf; | ||
135 | struct netxen_skb_frag *buffrag; | ||
136 | int i, j; | ||
137 | struct nx_host_tx_ring *tx_ring = adapter->tx_ring; | ||
138 | |||
139 | cmd_buf = tx_ring->cmd_buf_arr; | ||
140 | for (i = 0; i < tx_ring->num_desc; i++) { | ||
141 | buffrag = cmd_buf->frag_array; | ||
142 | if (buffrag->dma) { | ||
143 | pci_unmap_single(adapter->pdev, buffrag->dma, | ||
144 | buffrag->length, PCI_DMA_TODEVICE); | ||
145 | buffrag->dma = 0ULL; | ||
146 | } | ||
147 | for (j = 0; j < cmd_buf->frag_count; j++) { | ||
148 | buffrag++; | ||
149 | if (buffrag->dma) { | ||
150 | pci_unmap_page(adapter->pdev, buffrag->dma, | ||
151 | buffrag->length, | ||
152 | PCI_DMA_TODEVICE); | ||
153 | buffrag->dma = 0ULL; | ||
154 | } | ||
155 | } | ||
156 | if (cmd_buf->skb) { | ||
157 | dev_kfree_skb_any(cmd_buf->skb); | ||
158 | cmd_buf->skb = NULL; | ||
159 | } | ||
160 | cmd_buf++; | ||
161 | } | ||
162 | } | ||
163 | |||
164 | void netxen_free_sw_resources(struct netxen_adapter *adapter) | ||
165 | { | ||
166 | struct netxen_recv_context *recv_ctx; | ||
167 | struct nx_host_rds_ring *rds_ring; | ||
168 | struct nx_host_tx_ring *tx_ring; | ||
169 | int ring; | ||
170 | |||
171 | recv_ctx = &adapter->recv_ctx; | ||
172 | |||
173 | if (recv_ctx->rds_rings == NULL) | ||
174 | goto skip_rds; | ||
175 | |||
176 | for (ring = 0; ring < adapter->max_rds_rings; ring++) { | ||
177 | rds_ring = &recv_ctx->rds_rings[ring]; | ||
178 | vfree(rds_ring->rx_buf_arr); | ||
179 | rds_ring->rx_buf_arr = NULL; | ||
180 | } | ||
181 | kfree(recv_ctx->rds_rings); | ||
182 | |||
183 | skip_rds: | ||
184 | if (adapter->tx_ring == NULL) | ||
185 | return; | ||
186 | |||
187 | tx_ring = adapter->tx_ring; | ||
188 | vfree(tx_ring->cmd_buf_arr); | ||
189 | kfree(tx_ring); | ||
190 | adapter->tx_ring = NULL; | ||
191 | } | ||
192 | |||
193 | int netxen_alloc_sw_resources(struct netxen_adapter *adapter) | ||
194 | { | ||
195 | struct netxen_recv_context *recv_ctx; | ||
196 | struct nx_host_rds_ring *rds_ring; | ||
197 | struct nx_host_sds_ring *sds_ring; | ||
198 | struct nx_host_tx_ring *tx_ring; | ||
199 | struct netxen_rx_buffer *rx_buf; | ||
200 | int ring, i, size; | ||
201 | |||
202 | struct netxen_cmd_buffer *cmd_buf_arr; | ||
203 | struct net_device *netdev = adapter->netdev; | ||
204 | struct pci_dev *pdev = adapter->pdev; | ||
205 | |||
206 | size = sizeof(struct nx_host_tx_ring); | ||
207 | tx_ring = kzalloc(size, GFP_KERNEL); | ||
208 | if (tx_ring == NULL) { | ||
209 | dev_err(&pdev->dev, "%s: failed to allocate tx ring struct\n", | ||
210 | netdev->name); | ||
211 | return -ENOMEM; | ||
212 | } | ||
213 | adapter->tx_ring = tx_ring; | ||
214 | |||
215 | tx_ring->num_desc = adapter->num_txd; | ||
216 | tx_ring->txq = netdev_get_tx_queue(netdev, 0); | ||
217 | |||
218 | cmd_buf_arr = vzalloc(TX_BUFF_RINGSIZE(tx_ring)); | ||
219 | if (cmd_buf_arr == NULL) { | ||
220 | dev_err(&pdev->dev, "%s: failed to allocate cmd buffer ring\n", | ||
221 | netdev->name); | ||
222 | goto err_out; | ||
223 | } | ||
224 | tx_ring->cmd_buf_arr = cmd_buf_arr; | ||
225 | |||
226 | recv_ctx = &adapter->recv_ctx; | ||
227 | |||
228 | size = adapter->max_rds_rings * sizeof (struct nx_host_rds_ring); | ||
229 | rds_ring = kzalloc(size, GFP_KERNEL); | ||
230 | if (rds_ring == NULL) { | ||
231 | dev_err(&pdev->dev, "%s: failed to allocate rds ring struct\n", | ||
232 | netdev->name); | ||
233 | goto err_out; | ||
234 | } | ||
235 | recv_ctx->rds_rings = rds_ring; | ||
236 | |||
237 | for (ring = 0; ring < adapter->max_rds_rings; ring++) { | ||
238 | rds_ring = &recv_ctx->rds_rings[ring]; | ||
239 | switch (ring) { | ||
240 | case RCV_RING_NORMAL: | ||
241 | rds_ring->num_desc = adapter->num_rxd; | ||
242 | if (adapter->ahw.cut_through) { | ||
243 | rds_ring->dma_size = | ||
244 | NX_CT_DEFAULT_RX_BUF_LEN; | ||
245 | rds_ring->skb_size = | ||
246 | NX_CT_DEFAULT_RX_BUF_LEN; | ||
247 | } else { | ||
248 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) | ||
249 | rds_ring->dma_size = | ||
250 | NX_P3_RX_BUF_MAX_LEN; | ||
251 | else | ||
252 | rds_ring->dma_size = | ||
253 | NX_P2_RX_BUF_MAX_LEN; | ||
254 | rds_ring->skb_size = | ||
255 | rds_ring->dma_size + NET_IP_ALIGN; | ||
256 | } | ||
257 | break; | ||
258 | |||
259 | case RCV_RING_JUMBO: | ||
260 | rds_ring->num_desc = adapter->num_jumbo_rxd; | ||
261 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) | ||
262 | rds_ring->dma_size = | ||
263 | NX_P3_RX_JUMBO_BUF_MAX_LEN; | ||
264 | else | ||
265 | rds_ring->dma_size = | ||
266 | NX_P2_RX_JUMBO_BUF_MAX_LEN; | ||
267 | |||
268 | if (adapter->capabilities & NX_CAP0_HW_LRO) | ||
269 | rds_ring->dma_size += NX_LRO_BUFFER_EXTRA; | ||
270 | |||
271 | rds_ring->skb_size = | ||
272 | rds_ring->dma_size + NET_IP_ALIGN; | ||
273 | break; | ||
274 | |||
275 | case RCV_RING_LRO: | ||
276 | rds_ring->num_desc = adapter->num_lro_rxd; | ||
277 | rds_ring->dma_size = NX_RX_LRO_BUFFER_LENGTH; | ||
278 | rds_ring->skb_size = rds_ring->dma_size + NET_IP_ALIGN; | ||
279 | break; | ||
280 | |||
281 | } | ||
282 | rds_ring->rx_buf_arr = vzalloc(RCV_BUFF_RINGSIZE(rds_ring)); | ||
283 | if (rds_ring->rx_buf_arr == NULL) { | ||
284 | printk(KERN_ERR "%s: Failed to allocate " | ||
285 | "rx buffer ring %d\n", | ||
286 | netdev->name, ring); | ||
287 | /* free whatever was already allocated */ | ||
288 | goto err_out; | ||
289 | } | ||
290 | INIT_LIST_HEAD(&rds_ring->free_list); | ||
291 | /* | ||
292 | * Now go through all of them, set reference handles | ||
293 | * and put them in the queues. | ||
294 | */ | ||
295 | rx_buf = rds_ring->rx_buf_arr; | ||
296 | for (i = 0; i < rds_ring->num_desc; i++) { | ||
297 | list_add_tail(&rx_buf->list, | ||
298 | &rds_ring->free_list); | ||
299 | rx_buf->ref_handle = i; | ||
300 | rx_buf->state = NETXEN_BUFFER_FREE; | ||
301 | rx_buf++; | ||
302 | } | ||
303 | spin_lock_init(&rds_ring->lock); | ||
304 | } | ||
305 | |||
306 | for (ring = 0; ring < adapter->max_sds_rings; ring++) { | ||
307 | sds_ring = &recv_ctx->sds_rings[ring]; | ||
308 | sds_ring->irq = adapter->msix_entries[ring].vector; | ||
309 | sds_ring->adapter = adapter; | ||
310 | sds_ring->num_desc = adapter->num_rxd; | ||
311 | |||
312 | for (i = 0; i < NUM_RCV_DESC_RINGS; i++) | ||
313 | INIT_LIST_HEAD(&sds_ring->free_list[i]); | ||
314 | } | ||
315 | |||
316 | return 0; | ||
317 | |||
318 | err_out: | ||
319 | netxen_free_sw_resources(adapter); | ||
320 | return -ENOMEM; | ||
321 | } | ||
322 | |||
323 | /* | ||
324 | * netxen_decode_crb_addr(0 - utility to translate from internal Phantom CRB | ||
325 | * address to external PCI CRB address. | ||
326 | */ | ||
327 | static u32 netxen_decode_crb_addr(u32 addr) | ||
328 | { | ||
329 | int i; | ||
330 | u32 base_addr, offset, pci_base; | ||
331 | |||
332 | crb_addr_transform_setup(); | ||
333 | |||
334 | pci_base = NETXEN_ADDR_ERROR; | ||
335 | base_addr = addr & 0xfff00000; | ||
336 | offset = addr & 0x000fffff; | ||
337 | |||
338 | for (i = 0; i < NETXEN_MAX_CRB_XFORM; i++) { | ||
339 | if (crb_addr_xform[i] == base_addr) { | ||
340 | pci_base = i << 20; | ||
341 | break; | ||
342 | } | ||
343 | } | ||
344 | if (pci_base == NETXEN_ADDR_ERROR) | ||
345 | return pci_base; | ||
346 | else | ||
347 | return pci_base + offset; | ||
348 | } | ||
349 | |||
350 | #define NETXEN_MAX_ROM_WAIT_USEC 100 | ||
351 | |||
352 | static int netxen_wait_rom_done(struct netxen_adapter *adapter) | ||
353 | { | ||
354 | long timeout = 0; | ||
355 | long done = 0; | ||
356 | |||
357 | cond_resched(); | ||
358 | |||
359 | while (done == 0) { | ||
360 | done = NXRD32(adapter, NETXEN_ROMUSB_GLB_STATUS); | ||
361 | done &= 2; | ||
362 | if (++timeout >= NETXEN_MAX_ROM_WAIT_USEC) { | ||
363 | dev_err(&adapter->pdev->dev, | ||
364 | "Timeout reached waiting for rom done"); | ||
365 | return -EIO; | ||
366 | } | ||
367 | udelay(1); | ||
368 | } | ||
369 | return 0; | ||
370 | } | ||
371 | |||
372 | static int do_rom_fast_read(struct netxen_adapter *adapter, | ||
373 | int addr, int *valp) | ||
374 | { | ||
375 | NXWR32(adapter, NETXEN_ROMUSB_ROM_ADDRESS, addr); | ||
376 | NXWR32(adapter, NETXEN_ROMUSB_ROM_DUMMY_BYTE_CNT, 0); | ||
377 | NXWR32(adapter, NETXEN_ROMUSB_ROM_ABYTE_CNT, 3); | ||
378 | NXWR32(adapter, NETXEN_ROMUSB_ROM_INSTR_OPCODE, 0xb); | ||
379 | if (netxen_wait_rom_done(adapter)) { | ||
380 | printk("Error waiting for rom done\n"); | ||
381 | return -EIO; | ||
382 | } | ||
383 | /* reset abyte_cnt and dummy_byte_cnt */ | ||
384 | NXWR32(adapter, NETXEN_ROMUSB_ROM_ABYTE_CNT, 0); | ||
385 | udelay(10); | ||
386 | NXWR32(adapter, NETXEN_ROMUSB_ROM_DUMMY_BYTE_CNT, 0); | ||
387 | |||
388 | *valp = NXRD32(adapter, NETXEN_ROMUSB_ROM_RDATA); | ||
389 | return 0; | ||
390 | } | ||
391 | |||
392 | static int do_rom_fast_read_words(struct netxen_adapter *adapter, int addr, | ||
393 | u8 *bytes, size_t size) | ||
394 | { | ||
395 | int addridx; | ||
396 | int ret = 0; | ||
397 | |||
398 | for (addridx = addr; addridx < (addr + size); addridx += 4) { | ||
399 | int v; | ||
400 | ret = do_rom_fast_read(adapter, addridx, &v); | ||
401 | if (ret != 0) | ||
402 | break; | ||
403 | *(__le32 *)bytes = cpu_to_le32(v); | ||
404 | bytes += 4; | ||
405 | } | ||
406 | |||
407 | return ret; | ||
408 | } | ||
409 | |||
410 | int | ||
411 | netxen_rom_fast_read_words(struct netxen_adapter *adapter, int addr, | ||
412 | u8 *bytes, size_t size) | ||
413 | { | ||
414 | int ret; | ||
415 | |||
416 | ret = netxen_rom_lock(adapter); | ||
417 | if (ret < 0) | ||
418 | return ret; | ||
419 | |||
420 | ret = do_rom_fast_read_words(adapter, addr, bytes, size); | ||
421 | |||
422 | netxen_rom_unlock(adapter); | ||
423 | return ret; | ||
424 | } | ||
425 | |||
426 | int netxen_rom_fast_read(struct netxen_adapter *adapter, int addr, int *valp) | ||
427 | { | ||
428 | int ret; | ||
429 | |||
430 | if (netxen_rom_lock(adapter) != 0) | ||
431 | return -EIO; | ||
432 | |||
433 | ret = do_rom_fast_read(adapter, addr, valp); | ||
434 | netxen_rom_unlock(adapter); | ||
435 | return ret; | ||
436 | } | ||
437 | |||
438 | #define NETXEN_BOARDTYPE 0x4008 | ||
439 | #define NETXEN_BOARDNUM 0x400c | ||
440 | #define NETXEN_CHIPNUM 0x4010 | ||
441 | |||
442 | int netxen_pinit_from_rom(struct netxen_adapter *adapter) | ||
443 | { | ||
444 | int addr, val; | ||
445 | int i, n, init_delay = 0; | ||
446 | struct crb_addr_pair *buf; | ||
447 | unsigned offset; | ||
448 | u32 off; | ||
449 | |||
450 | /* resetall */ | ||
451 | netxen_rom_lock(adapter); | ||
452 | NXWR32(adapter, NETXEN_ROMUSB_GLB_SW_RESET, 0xffffffff); | ||
453 | netxen_rom_unlock(adapter); | ||
454 | |||
455 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) { | ||
456 | if (netxen_rom_fast_read(adapter, 0, &n) != 0 || | ||
457 | (n != 0xcafecafe) || | ||
458 | netxen_rom_fast_read(adapter, 4, &n) != 0) { | ||
459 | printk(KERN_ERR "%s: ERROR Reading crb_init area: " | ||
460 | "n: %08x\n", netxen_nic_driver_name, n); | ||
461 | return -EIO; | ||
462 | } | ||
463 | offset = n & 0xffffU; | ||
464 | n = (n >> 16) & 0xffffU; | ||
465 | } else { | ||
466 | if (netxen_rom_fast_read(adapter, 0, &n) != 0 || | ||
467 | !(n & 0x80000000)) { | ||
468 | printk(KERN_ERR "%s: ERROR Reading crb_init area: " | ||
469 | "n: %08x\n", netxen_nic_driver_name, n); | ||
470 | return -EIO; | ||
471 | } | ||
472 | offset = 1; | ||
473 | n &= ~0x80000000; | ||
474 | } | ||
475 | |||
476 | if (n >= 1024) { | ||
477 | printk(KERN_ERR "%s:n=0x%x Error! NetXen card flash not" | ||
478 | " initialized.\n", __func__, n); | ||
479 | return -EIO; | ||
480 | } | ||
481 | |||
482 | buf = kcalloc(n, sizeof(struct crb_addr_pair), GFP_KERNEL); | ||
483 | if (buf == NULL) { | ||
484 | printk("%s: netxen_pinit_from_rom: Unable to calloc memory.\n", | ||
485 | netxen_nic_driver_name); | ||
486 | return -ENOMEM; | ||
487 | } | ||
488 | |||
489 | for (i = 0; i < n; i++) { | ||
490 | if (netxen_rom_fast_read(adapter, 8*i + 4*offset, &val) != 0 || | ||
491 | netxen_rom_fast_read(adapter, 8*i + 4*offset + 4, &addr) != 0) { | ||
492 | kfree(buf); | ||
493 | return -EIO; | ||
494 | } | ||
495 | |||
496 | buf[i].addr = addr; | ||
497 | buf[i].data = val; | ||
498 | |||
499 | } | ||
500 | |||
501 | for (i = 0; i < n; i++) { | ||
502 | |||
503 | off = netxen_decode_crb_addr(buf[i].addr); | ||
504 | if (off == NETXEN_ADDR_ERROR) { | ||
505 | printk(KERN_ERR"CRB init value out of range %x\n", | ||
506 | buf[i].addr); | ||
507 | continue; | ||
508 | } | ||
509 | off += NETXEN_PCI_CRBSPACE; | ||
510 | |||
511 | if (off & 1) | ||
512 | continue; | ||
513 | |||
514 | /* skipping cold reboot MAGIC */ | ||
515 | if (off == NETXEN_CAM_RAM(0x1fc)) | ||
516 | continue; | ||
517 | |||
518 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) { | ||
519 | if (off == (NETXEN_CRB_I2C0 + 0x1c)) | ||
520 | continue; | ||
521 | /* do not reset PCI */ | ||
522 | if (off == (ROMUSB_GLB + 0xbc)) | ||
523 | continue; | ||
524 | if (off == (ROMUSB_GLB + 0xa8)) | ||
525 | continue; | ||
526 | if (off == (ROMUSB_GLB + 0xc8)) /* core clock */ | ||
527 | continue; | ||
528 | if (off == (ROMUSB_GLB + 0x24)) /* MN clock */ | ||
529 | continue; | ||
530 | if (off == (ROMUSB_GLB + 0x1c)) /* MS clock */ | ||
531 | continue; | ||
532 | if ((off & 0x0ff00000) == NETXEN_CRB_DDR_NET) | ||
533 | continue; | ||
534 | if (off == (NETXEN_CRB_PEG_NET_1 + 0x18) && | ||
535 | !NX_IS_REVISION_P3P(adapter->ahw.revision_id)) | ||
536 | buf[i].data = 0x1020; | ||
537 | /* skip the function enable register */ | ||
538 | if (off == NETXEN_PCIE_REG(PCIE_SETUP_FUNCTION)) | ||
539 | continue; | ||
540 | if (off == NETXEN_PCIE_REG(PCIE_SETUP_FUNCTION2)) | ||
541 | continue; | ||
542 | if ((off & 0x0ff00000) == NETXEN_CRB_SMB) | ||
543 | continue; | ||
544 | } | ||
545 | |||
546 | init_delay = 1; | ||
547 | /* After writing this register, HW needs time for CRB */ | ||
548 | /* to quiet down (else crb_window returns 0xffffffff) */ | ||
549 | if (off == NETXEN_ROMUSB_GLB_SW_RESET) { | ||
550 | init_delay = 1000; | ||
551 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) { | ||
552 | /* hold xdma in reset also */ | ||
553 | buf[i].data = NETXEN_NIC_XDMA_RESET; | ||
554 | buf[i].data = 0x8000ff; | ||
555 | } | ||
556 | } | ||
557 | |||
558 | NXWR32(adapter, off, buf[i].data); | ||
559 | |||
560 | msleep(init_delay); | ||
561 | } | ||
562 | kfree(buf); | ||
563 | |||
564 | /* disable_peg_cache_all */ | ||
565 | |||
566 | /* unreset_net_cache */ | ||
567 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) { | ||
568 | val = NXRD32(adapter, NETXEN_ROMUSB_GLB_SW_RESET); | ||
569 | NXWR32(adapter, NETXEN_ROMUSB_GLB_SW_RESET, (val & 0xffffff0f)); | ||
570 | } | ||
571 | |||
572 | /* p2dn replyCount */ | ||
573 | NXWR32(adapter, NETXEN_CRB_PEG_NET_D + 0xec, 0x1e); | ||
574 | /* disable_peg_cache 0 */ | ||
575 | NXWR32(adapter, NETXEN_CRB_PEG_NET_D + 0x4c, 8); | ||
576 | /* disable_peg_cache 1 */ | ||
577 | NXWR32(adapter, NETXEN_CRB_PEG_NET_I + 0x4c, 8); | ||
578 | |||
579 | /* peg_clr_all */ | ||
580 | |||
581 | /* peg_clr 0 */ | ||
582 | NXWR32(adapter, NETXEN_CRB_PEG_NET_0 + 0x8, 0); | ||
583 | NXWR32(adapter, NETXEN_CRB_PEG_NET_0 + 0xc, 0); | ||
584 | /* peg_clr 1 */ | ||
585 | NXWR32(adapter, NETXEN_CRB_PEG_NET_1 + 0x8, 0); | ||
586 | NXWR32(adapter, NETXEN_CRB_PEG_NET_1 + 0xc, 0); | ||
587 | /* peg_clr 2 */ | ||
588 | NXWR32(adapter, NETXEN_CRB_PEG_NET_2 + 0x8, 0); | ||
589 | NXWR32(adapter, NETXEN_CRB_PEG_NET_2 + 0xc, 0); | ||
590 | /* peg_clr 3 */ | ||
591 | NXWR32(adapter, NETXEN_CRB_PEG_NET_3 + 0x8, 0); | ||
592 | NXWR32(adapter, NETXEN_CRB_PEG_NET_3 + 0xc, 0); | ||
593 | return 0; | ||
594 | } | ||
595 | |||
596 | static struct uni_table_desc *nx_get_table_desc(const u8 *unirom, int section) | ||
597 | { | ||
598 | uint32_t i; | ||
599 | struct uni_table_desc *directory = (struct uni_table_desc *) &unirom[0]; | ||
600 | __le32 entries = cpu_to_le32(directory->num_entries); | ||
601 | |||
602 | for (i = 0; i < entries; i++) { | ||
603 | |||
604 | __le32 offs = cpu_to_le32(directory->findex) + | ||
605 | (i * cpu_to_le32(directory->entry_size)); | ||
606 | __le32 tab_type = cpu_to_le32(*((u32 *)&unirom[offs] + 8)); | ||
607 | |||
608 | if (tab_type == section) | ||
609 | return (struct uni_table_desc *) &unirom[offs]; | ||
610 | } | ||
611 | |||
612 | return NULL; | ||
613 | } | ||
614 | |||
615 | #define QLCNIC_FILEHEADER_SIZE (14 * 4) | ||
616 | |||
617 | static int | ||
618 | netxen_nic_validate_header(struct netxen_adapter *adapter) | ||
619 | { | ||
620 | const u8 *unirom = adapter->fw->data; | ||
621 | struct uni_table_desc *directory = (struct uni_table_desc *) &unirom[0]; | ||
622 | u32 fw_file_size = adapter->fw->size; | ||
623 | u32 tab_size; | ||
624 | __le32 entries; | ||
625 | __le32 entry_size; | ||
626 | |||
627 | if (fw_file_size < QLCNIC_FILEHEADER_SIZE) | ||
628 | return -EINVAL; | ||
629 | |||
630 | entries = cpu_to_le32(directory->num_entries); | ||
631 | entry_size = cpu_to_le32(directory->entry_size); | ||
632 | tab_size = cpu_to_le32(directory->findex) + (entries * entry_size); | ||
633 | |||
634 | if (fw_file_size < tab_size) | ||
635 | return -EINVAL; | ||
636 | |||
637 | return 0; | ||
638 | } | ||
639 | |||
640 | static int | ||
641 | netxen_nic_validate_bootld(struct netxen_adapter *adapter) | ||
642 | { | ||
643 | struct uni_table_desc *tab_desc; | ||
644 | struct uni_data_desc *descr; | ||
645 | const u8 *unirom = adapter->fw->data; | ||
646 | __le32 idx = cpu_to_le32(*((int *)&unirom[adapter->file_prd_off] + | ||
647 | NX_UNI_BOOTLD_IDX_OFF)); | ||
648 | u32 offs; | ||
649 | u32 tab_size; | ||
650 | u32 data_size; | ||
651 | |||
652 | tab_desc = nx_get_table_desc(unirom, NX_UNI_DIR_SECT_BOOTLD); | ||
653 | |||
654 | if (!tab_desc) | ||
655 | return -EINVAL; | ||
656 | |||
657 | tab_size = cpu_to_le32(tab_desc->findex) + | ||
658 | (cpu_to_le32(tab_desc->entry_size) * (idx + 1)); | ||
659 | |||
660 | if (adapter->fw->size < tab_size) | ||
661 | return -EINVAL; | ||
662 | |||
663 | offs = cpu_to_le32(tab_desc->findex) + | ||
664 | (cpu_to_le32(tab_desc->entry_size) * (idx)); | ||
665 | descr = (struct uni_data_desc *)&unirom[offs]; | ||
666 | |||
667 | data_size = cpu_to_le32(descr->findex) + cpu_to_le32(descr->size); | ||
668 | |||
669 | if (adapter->fw->size < data_size) | ||
670 | return -EINVAL; | ||
671 | |||
672 | return 0; | ||
673 | } | ||
674 | |||
675 | static int | ||
676 | netxen_nic_validate_fw(struct netxen_adapter *adapter) | ||
677 | { | ||
678 | struct uni_table_desc *tab_desc; | ||
679 | struct uni_data_desc *descr; | ||
680 | const u8 *unirom = adapter->fw->data; | ||
681 | __le32 idx = cpu_to_le32(*((int *)&unirom[adapter->file_prd_off] + | ||
682 | NX_UNI_FIRMWARE_IDX_OFF)); | ||
683 | u32 offs; | ||
684 | u32 tab_size; | ||
685 | u32 data_size; | ||
686 | |||
687 | tab_desc = nx_get_table_desc(unirom, NX_UNI_DIR_SECT_FW); | ||
688 | |||
689 | if (!tab_desc) | ||
690 | return -EINVAL; | ||
691 | |||
692 | tab_size = cpu_to_le32(tab_desc->findex) + | ||
693 | (cpu_to_le32(tab_desc->entry_size) * (idx + 1)); | ||
694 | |||
695 | if (adapter->fw->size < tab_size) | ||
696 | return -EINVAL; | ||
697 | |||
698 | offs = cpu_to_le32(tab_desc->findex) + | ||
699 | (cpu_to_le32(tab_desc->entry_size) * (idx)); | ||
700 | descr = (struct uni_data_desc *)&unirom[offs]; | ||
701 | data_size = cpu_to_le32(descr->findex) + cpu_to_le32(descr->size); | ||
702 | |||
703 | if (adapter->fw->size < data_size) | ||
704 | return -EINVAL; | ||
705 | |||
706 | return 0; | ||
707 | } | ||
708 | |||
709 | |||
710 | static int | ||
711 | netxen_nic_validate_product_offs(struct netxen_adapter *adapter) | ||
712 | { | ||
713 | struct uni_table_desc *ptab_descr; | ||
714 | const u8 *unirom = adapter->fw->data; | ||
715 | int mn_present = (NX_IS_REVISION_P2(adapter->ahw.revision_id)) ? | ||
716 | 1 : netxen_p3_has_mn(adapter); | ||
717 | __le32 entries; | ||
718 | __le32 entry_size; | ||
719 | u32 tab_size; | ||
720 | u32 i; | ||
721 | |||
722 | ptab_descr = nx_get_table_desc(unirom, NX_UNI_DIR_SECT_PRODUCT_TBL); | ||
723 | if (ptab_descr == NULL) | ||
724 | return -EINVAL; | ||
725 | |||
726 | entries = cpu_to_le32(ptab_descr->num_entries); | ||
727 | entry_size = cpu_to_le32(ptab_descr->entry_size); | ||
728 | tab_size = cpu_to_le32(ptab_descr->findex) + (entries * entry_size); | ||
729 | |||
730 | if (adapter->fw->size < tab_size) | ||
731 | return -EINVAL; | ||
732 | |||
733 | nomn: | ||
734 | for (i = 0; i < entries; i++) { | ||
735 | |||
736 | __le32 flags, file_chiprev, offs; | ||
737 | u8 chiprev = adapter->ahw.revision_id; | ||
738 | uint32_t flagbit; | ||
739 | |||
740 | offs = cpu_to_le32(ptab_descr->findex) + | ||
741 | (i * cpu_to_le32(ptab_descr->entry_size)); | ||
742 | flags = cpu_to_le32(*((int *)&unirom[offs] + NX_UNI_FLAGS_OFF)); | ||
743 | file_chiprev = cpu_to_le32(*((int *)&unirom[offs] + | ||
744 | NX_UNI_CHIP_REV_OFF)); | ||
745 | |||
746 | flagbit = mn_present ? 1 : 2; | ||
747 | |||
748 | if ((chiprev == file_chiprev) && | ||
749 | ((1ULL << flagbit) & flags)) { | ||
750 | adapter->file_prd_off = offs; | ||
751 | return 0; | ||
752 | } | ||
753 | } | ||
754 | |||
755 | if (mn_present && NX_IS_REVISION_P3(adapter->ahw.revision_id)) { | ||
756 | mn_present = 0; | ||
757 | goto nomn; | ||
758 | } | ||
759 | |||
760 | return -EINVAL; | ||
761 | } | ||
762 | |||
763 | static int | ||
764 | netxen_nic_validate_unified_romimage(struct netxen_adapter *adapter) | ||
765 | { | ||
766 | if (netxen_nic_validate_header(adapter)) { | ||
767 | dev_err(&adapter->pdev->dev, | ||
768 | "unified image: header validation failed\n"); | ||
769 | return -EINVAL; | ||
770 | } | ||
771 | |||
772 | if (netxen_nic_validate_product_offs(adapter)) { | ||
773 | dev_err(&adapter->pdev->dev, | ||
774 | "unified image: product validation failed\n"); | ||
775 | return -EINVAL; | ||
776 | } | ||
777 | |||
778 | if (netxen_nic_validate_bootld(adapter)) { | ||
779 | dev_err(&adapter->pdev->dev, | ||
780 | "unified image: bootld validation failed\n"); | ||
781 | return -EINVAL; | ||
782 | } | ||
783 | |||
784 | if (netxen_nic_validate_fw(adapter)) { | ||
785 | dev_err(&adapter->pdev->dev, | ||
786 | "unified image: firmware validation failed\n"); | ||
787 | return -EINVAL; | ||
788 | } | ||
789 | |||
790 | return 0; | ||
791 | } | ||
792 | |||
793 | static struct uni_data_desc *nx_get_data_desc(struct netxen_adapter *adapter, | ||
794 | u32 section, u32 idx_offset) | ||
795 | { | ||
796 | const u8 *unirom = adapter->fw->data; | ||
797 | int idx = cpu_to_le32(*((int *)&unirom[adapter->file_prd_off] + | ||
798 | idx_offset)); | ||
799 | struct uni_table_desc *tab_desc; | ||
800 | __le32 offs; | ||
801 | |||
802 | tab_desc = nx_get_table_desc(unirom, section); | ||
803 | |||
804 | if (tab_desc == NULL) | ||
805 | return NULL; | ||
806 | |||
807 | offs = cpu_to_le32(tab_desc->findex) + | ||
808 | (cpu_to_le32(tab_desc->entry_size) * idx); | ||
809 | |||
810 | return (struct uni_data_desc *)&unirom[offs]; | ||
811 | } | ||
812 | |||
813 | static u8 * | ||
814 | nx_get_bootld_offs(struct netxen_adapter *adapter) | ||
815 | { | ||
816 | u32 offs = NETXEN_BOOTLD_START; | ||
817 | |||
818 | if (adapter->fw_type == NX_UNIFIED_ROMIMAGE) | ||
819 | offs = cpu_to_le32((nx_get_data_desc(adapter, | ||
820 | NX_UNI_DIR_SECT_BOOTLD, | ||
821 | NX_UNI_BOOTLD_IDX_OFF))->findex); | ||
822 | |||
823 | return (u8 *)&adapter->fw->data[offs]; | ||
824 | } | ||
825 | |||
826 | static u8 * | ||
827 | nx_get_fw_offs(struct netxen_adapter *adapter) | ||
828 | { | ||
829 | u32 offs = NETXEN_IMAGE_START; | ||
830 | |||
831 | if (adapter->fw_type == NX_UNIFIED_ROMIMAGE) | ||
832 | offs = cpu_to_le32((nx_get_data_desc(adapter, | ||
833 | NX_UNI_DIR_SECT_FW, | ||
834 | NX_UNI_FIRMWARE_IDX_OFF))->findex); | ||
835 | |||
836 | return (u8 *)&adapter->fw->data[offs]; | ||
837 | } | ||
838 | |||
839 | static __le32 | ||
840 | nx_get_fw_size(struct netxen_adapter *adapter) | ||
841 | { | ||
842 | if (adapter->fw_type == NX_UNIFIED_ROMIMAGE) | ||
843 | return cpu_to_le32((nx_get_data_desc(adapter, | ||
844 | NX_UNI_DIR_SECT_FW, | ||
845 | NX_UNI_FIRMWARE_IDX_OFF))->size); | ||
846 | else | ||
847 | return cpu_to_le32( | ||
848 | *(u32 *)&adapter->fw->data[NX_FW_SIZE_OFFSET]); | ||
849 | } | ||
850 | |||
851 | static __le32 | ||
852 | nx_get_fw_version(struct netxen_adapter *adapter) | ||
853 | { | ||
854 | struct uni_data_desc *fw_data_desc; | ||
855 | const struct firmware *fw = adapter->fw; | ||
856 | __le32 major, minor, sub; | ||
857 | const u8 *ver_str; | ||
858 | int i, ret = 0; | ||
859 | |||
860 | if (adapter->fw_type == NX_UNIFIED_ROMIMAGE) { | ||
861 | |||
862 | fw_data_desc = nx_get_data_desc(adapter, | ||
863 | NX_UNI_DIR_SECT_FW, NX_UNI_FIRMWARE_IDX_OFF); | ||
864 | ver_str = fw->data + cpu_to_le32(fw_data_desc->findex) + | ||
865 | cpu_to_le32(fw_data_desc->size) - 17; | ||
866 | |||
867 | for (i = 0; i < 12; i++) { | ||
868 | if (!strncmp(&ver_str[i], "REV=", 4)) { | ||
869 | ret = sscanf(&ver_str[i+4], "%u.%u.%u ", | ||
870 | &major, &minor, &sub); | ||
871 | break; | ||
872 | } | ||
873 | } | ||
874 | |||
875 | if (ret != 3) | ||
876 | return 0; | ||
877 | |||
878 | return major + (minor << 8) + (sub << 16); | ||
879 | |||
880 | } else | ||
881 | return cpu_to_le32(*(u32 *)&fw->data[NX_FW_VERSION_OFFSET]); | ||
882 | } | ||
883 | |||
884 | static __le32 | ||
885 | nx_get_bios_version(struct netxen_adapter *adapter) | ||
886 | { | ||
887 | const struct firmware *fw = adapter->fw; | ||
888 | __le32 bios_ver, prd_off = adapter->file_prd_off; | ||
889 | |||
890 | if (adapter->fw_type == NX_UNIFIED_ROMIMAGE) { | ||
891 | bios_ver = cpu_to_le32(*((u32 *) (&fw->data[prd_off]) | ||
892 | + NX_UNI_BIOS_VERSION_OFF)); | ||
893 | return (bios_ver << 16) + ((bios_ver >> 8) & 0xff00) + | ||
894 | (bios_ver >> 24); | ||
895 | } else | ||
896 | return cpu_to_le32(*(u32 *)&fw->data[NX_BIOS_VERSION_OFFSET]); | ||
897 | |||
898 | } | ||
899 | |||
900 | int | ||
901 | netxen_need_fw_reset(struct netxen_adapter *adapter) | ||
902 | { | ||
903 | u32 count, old_count; | ||
904 | u32 val, version, major, minor, build; | ||
905 | int i, timeout; | ||
906 | u8 fw_type; | ||
907 | |||
908 | /* NX2031 firmware doesn't support heartbit */ | ||
909 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) | ||
910 | return 1; | ||
911 | |||
912 | if (adapter->need_fw_reset) | ||
913 | return 1; | ||
914 | |||
915 | /* last attempt had failed */ | ||
916 | if (NXRD32(adapter, CRB_CMDPEG_STATE) == PHAN_INITIALIZE_FAILED) | ||
917 | return 1; | ||
918 | |||
919 | old_count = NXRD32(adapter, NETXEN_PEG_ALIVE_COUNTER); | ||
920 | |||
921 | for (i = 0; i < 10; i++) { | ||
922 | |||
923 | timeout = msleep_interruptible(200); | ||
924 | if (timeout) { | ||
925 | NXWR32(adapter, CRB_CMDPEG_STATE, | ||
926 | PHAN_INITIALIZE_FAILED); | ||
927 | return -EINTR; | ||
928 | } | ||
929 | |||
930 | count = NXRD32(adapter, NETXEN_PEG_ALIVE_COUNTER); | ||
931 | if (count != old_count) | ||
932 | break; | ||
933 | } | ||
934 | |||
935 | /* firmware is dead */ | ||
936 | if (count == old_count) | ||
937 | return 1; | ||
938 | |||
939 | /* check if we have got newer or different file firmware */ | ||
940 | if (adapter->fw) { | ||
941 | |||
942 | val = nx_get_fw_version(adapter); | ||
943 | |||
944 | version = NETXEN_DECODE_VERSION(val); | ||
945 | |||
946 | major = NXRD32(adapter, NETXEN_FW_VERSION_MAJOR); | ||
947 | minor = NXRD32(adapter, NETXEN_FW_VERSION_MINOR); | ||
948 | build = NXRD32(adapter, NETXEN_FW_VERSION_SUB); | ||
949 | |||
950 | if (version > NETXEN_VERSION_CODE(major, minor, build)) | ||
951 | return 1; | ||
952 | |||
953 | if (version == NETXEN_VERSION_CODE(major, minor, build) && | ||
954 | adapter->fw_type != NX_UNIFIED_ROMIMAGE) { | ||
955 | |||
956 | val = NXRD32(adapter, NETXEN_MIU_MN_CONTROL); | ||
957 | fw_type = (val & 0x4) ? | ||
958 | NX_P3_CT_ROMIMAGE : NX_P3_MN_ROMIMAGE; | ||
959 | |||
960 | if (adapter->fw_type != fw_type) | ||
961 | return 1; | ||
962 | } | ||
963 | } | ||
964 | |||
965 | return 0; | ||
966 | } | ||
967 | |||
968 | #define NETXEN_MIN_P3_FW_SUPP NETXEN_VERSION_CODE(4, 0, 505) | ||
969 | |||
970 | int | ||
971 | netxen_check_flash_fw_compatibility(struct netxen_adapter *adapter) | ||
972 | { | ||
973 | u32 flash_fw_ver, min_fw_ver; | ||
974 | |||
975 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) | ||
976 | return 0; | ||
977 | |||
978 | if (netxen_rom_fast_read(adapter, | ||
979 | NX_FW_VERSION_OFFSET, (int *)&flash_fw_ver)) { | ||
980 | dev_err(&adapter->pdev->dev, "Unable to read flash fw" | ||
981 | "version\n"); | ||
982 | return -EIO; | ||
983 | } | ||
984 | |||
985 | flash_fw_ver = NETXEN_DECODE_VERSION(flash_fw_ver); | ||
986 | min_fw_ver = NETXEN_MIN_P3_FW_SUPP; | ||
987 | if (flash_fw_ver >= min_fw_ver) | ||
988 | return 0; | ||
989 | |||
990 | dev_info(&adapter->pdev->dev, "Flash fw[%d.%d.%d] is < min fw supported" | ||
991 | "[4.0.505]. Please update firmware on flash\n", | ||
992 | _major(flash_fw_ver), _minor(flash_fw_ver), | ||
993 | _build(flash_fw_ver)); | ||
994 | return -EINVAL; | ||
995 | } | ||
996 | |||
997 | static char *fw_name[] = { | ||
998 | NX_P2_MN_ROMIMAGE_NAME, | ||
999 | NX_P3_CT_ROMIMAGE_NAME, | ||
1000 | NX_P3_MN_ROMIMAGE_NAME, | ||
1001 | NX_UNIFIED_ROMIMAGE_NAME, | ||
1002 | NX_FLASH_ROMIMAGE_NAME, | ||
1003 | }; | ||
1004 | |||
1005 | int | ||
1006 | netxen_load_firmware(struct netxen_adapter *adapter) | ||
1007 | { | ||
1008 | u64 *ptr64; | ||
1009 | u32 i, flashaddr, size; | ||
1010 | const struct firmware *fw = adapter->fw; | ||
1011 | struct pci_dev *pdev = adapter->pdev; | ||
1012 | |||
1013 | dev_info(&pdev->dev, "loading firmware from %s\n", | ||
1014 | fw_name[adapter->fw_type]); | ||
1015 | |||
1016 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) | ||
1017 | NXWR32(adapter, NETXEN_ROMUSB_GLB_CAS_RST, 1); | ||
1018 | |||
1019 | if (fw) { | ||
1020 | __le64 data; | ||
1021 | |||
1022 | size = (NETXEN_IMAGE_START - NETXEN_BOOTLD_START) / 8; | ||
1023 | |||
1024 | ptr64 = (u64 *)nx_get_bootld_offs(adapter); | ||
1025 | flashaddr = NETXEN_BOOTLD_START; | ||
1026 | |||
1027 | for (i = 0; i < size; i++) { | ||
1028 | data = cpu_to_le64(ptr64[i]); | ||
1029 | |||
1030 | if (adapter->pci_mem_write(adapter, flashaddr, data)) | ||
1031 | return -EIO; | ||
1032 | |||
1033 | flashaddr += 8; | ||
1034 | } | ||
1035 | |||
1036 | size = (__force u32)nx_get_fw_size(adapter) / 8; | ||
1037 | |||
1038 | ptr64 = (u64 *)nx_get_fw_offs(adapter); | ||
1039 | flashaddr = NETXEN_IMAGE_START; | ||
1040 | |||
1041 | for (i = 0; i < size; i++) { | ||
1042 | data = cpu_to_le64(ptr64[i]); | ||
1043 | |||
1044 | if (adapter->pci_mem_write(adapter, | ||
1045 | flashaddr, data)) | ||
1046 | return -EIO; | ||
1047 | |||
1048 | flashaddr += 8; | ||
1049 | } | ||
1050 | |||
1051 | size = (__force u32)nx_get_fw_size(adapter) % 8; | ||
1052 | if (size) { | ||
1053 | data = cpu_to_le64(ptr64[i]); | ||
1054 | |||
1055 | if (adapter->pci_mem_write(adapter, | ||
1056 | flashaddr, data)) | ||
1057 | return -EIO; | ||
1058 | } | ||
1059 | |||
1060 | } else { | ||
1061 | u64 data; | ||
1062 | u32 hi, lo; | ||
1063 | |||
1064 | size = (NETXEN_IMAGE_START - NETXEN_BOOTLD_START) / 8; | ||
1065 | flashaddr = NETXEN_BOOTLD_START; | ||
1066 | |||
1067 | for (i = 0; i < size; i++) { | ||
1068 | if (netxen_rom_fast_read(adapter, | ||
1069 | flashaddr, (int *)&lo) != 0) | ||
1070 | return -EIO; | ||
1071 | if (netxen_rom_fast_read(adapter, | ||
1072 | flashaddr + 4, (int *)&hi) != 0) | ||
1073 | return -EIO; | ||
1074 | |||
1075 | /* hi, lo are already in host endian byteorder */ | ||
1076 | data = (((u64)hi << 32) | lo); | ||
1077 | |||
1078 | if (adapter->pci_mem_write(adapter, | ||
1079 | flashaddr, data)) | ||
1080 | return -EIO; | ||
1081 | |||
1082 | flashaddr += 8; | ||
1083 | } | ||
1084 | } | ||
1085 | msleep(1); | ||
1086 | |||
1087 | if (NX_IS_REVISION_P3P(adapter->ahw.revision_id)) { | ||
1088 | NXWR32(adapter, NETXEN_CRB_PEG_NET_0 + 0x18, 0x1020); | ||
1089 | NXWR32(adapter, NETXEN_ROMUSB_GLB_SW_RESET, 0x80001e); | ||
1090 | } else if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) | ||
1091 | NXWR32(adapter, NETXEN_ROMUSB_GLB_SW_RESET, 0x80001d); | ||
1092 | else { | ||
1093 | NXWR32(adapter, NETXEN_ROMUSB_GLB_CHIP_CLK_CTRL, 0x3fff); | ||
1094 | NXWR32(adapter, NETXEN_ROMUSB_GLB_CAS_RST, 0); | ||
1095 | } | ||
1096 | |||
1097 | return 0; | ||
1098 | } | ||
1099 | |||
1100 | static int | ||
1101 | netxen_validate_firmware(struct netxen_adapter *adapter) | ||
1102 | { | ||
1103 | __le32 val; | ||
1104 | __le32 flash_fw_ver; | ||
1105 | u32 file_fw_ver, min_ver, bios; | ||
1106 | struct pci_dev *pdev = adapter->pdev; | ||
1107 | const struct firmware *fw = adapter->fw; | ||
1108 | u8 fw_type = adapter->fw_type; | ||
1109 | u32 crbinit_fix_fw; | ||
1110 | |||
1111 | if (fw_type == NX_UNIFIED_ROMIMAGE) { | ||
1112 | if (netxen_nic_validate_unified_romimage(adapter)) | ||
1113 | return -EINVAL; | ||
1114 | } else { | ||
1115 | val = cpu_to_le32(*(u32 *)&fw->data[NX_FW_MAGIC_OFFSET]); | ||
1116 | if ((__force u32)val != NETXEN_BDINFO_MAGIC) | ||
1117 | return -EINVAL; | ||
1118 | |||
1119 | if (fw->size < NX_FW_MIN_SIZE) | ||
1120 | return -EINVAL; | ||
1121 | } | ||
1122 | |||
1123 | val = nx_get_fw_version(adapter); | ||
1124 | |||
1125 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) | ||
1126 | min_ver = NETXEN_MIN_P3_FW_SUPP; | ||
1127 | else | ||
1128 | min_ver = NETXEN_VERSION_CODE(3, 4, 216); | ||
1129 | |||
1130 | file_fw_ver = NETXEN_DECODE_VERSION(val); | ||
1131 | |||
1132 | if ((_major(file_fw_ver) > _NETXEN_NIC_LINUX_MAJOR) || | ||
1133 | (file_fw_ver < min_ver)) { | ||
1134 | dev_err(&pdev->dev, | ||
1135 | "%s: firmware version %d.%d.%d unsupported\n", | ||
1136 | fw_name[fw_type], _major(file_fw_ver), _minor(file_fw_ver), | ||
1137 | _build(file_fw_ver)); | ||
1138 | return -EINVAL; | ||
1139 | } | ||
1140 | |||
1141 | val = nx_get_bios_version(adapter); | ||
1142 | netxen_rom_fast_read(adapter, NX_BIOS_VERSION_OFFSET, (int *)&bios); | ||
1143 | if ((__force u32)val != bios) { | ||
1144 | dev_err(&pdev->dev, "%s: firmware bios is incompatible\n", | ||
1145 | fw_name[fw_type]); | ||
1146 | return -EINVAL; | ||
1147 | } | ||
1148 | |||
1149 | if (netxen_rom_fast_read(adapter, | ||
1150 | NX_FW_VERSION_OFFSET, (int *)&flash_fw_ver)) { | ||
1151 | dev_err(&pdev->dev, "Unable to read flash fw version\n"); | ||
1152 | return -EIO; | ||
1153 | } | ||
1154 | flash_fw_ver = NETXEN_DECODE_VERSION(flash_fw_ver); | ||
1155 | |||
1156 | /* New fw from file is not allowed, if fw on flash is < 4.0.554 */ | ||
1157 | crbinit_fix_fw = NETXEN_VERSION_CODE(4, 0, 554); | ||
1158 | if (file_fw_ver >= crbinit_fix_fw && flash_fw_ver < crbinit_fix_fw && | ||
1159 | NX_IS_REVISION_P3(adapter->ahw.revision_id)) { | ||
1160 | dev_err(&pdev->dev, "Incompatibility detected between driver " | ||
1161 | "and firmware version on flash. This configuration " | ||
1162 | "is not recommended. Please update the firmware on " | ||
1163 | "flash immediately\n"); | ||
1164 | return -EINVAL; | ||
1165 | } | ||
1166 | |||
1167 | /* check if flashed firmware is newer only for no-mn and P2 case*/ | ||
1168 | if (!netxen_p3_has_mn(adapter) || | ||
1169 | NX_IS_REVISION_P2(adapter->ahw.revision_id)) { | ||
1170 | if (flash_fw_ver > file_fw_ver) { | ||
1171 | dev_info(&pdev->dev, "%s: firmware is older than flash\n", | ||
1172 | fw_name[fw_type]); | ||
1173 | return -EINVAL; | ||
1174 | } | ||
1175 | } | ||
1176 | |||
1177 | NXWR32(adapter, NETXEN_CAM_RAM(0x1fc), NETXEN_BDINFO_MAGIC); | ||
1178 | return 0; | ||
1179 | } | ||
1180 | |||
1181 | static void | ||
1182 | nx_get_next_fwtype(struct netxen_adapter *adapter) | ||
1183 | { | ||
1184 | u8 fw_type; | ||
1185 | |||
1186 | switch (adapter->fw_type) { | ||
1187 | case NX_UNKNOWN_ROMIMAGE: | ||
1188 | fw_type = NX_UNIFIED_ROMIMAGE; | ||
1189 | break; | ||
1190 | |||
1191 | case NX_UNIFIED_ROMIMAGE: | ||
1192 | if (NX_IS_REVISION_P3P(adapter->ahw.revision_id)) | ||
1193 | fw_type = NX_FLASH_ROMIMAGE; | ||
1194 | else if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) | ||
1195 | fw_type = NX_P2_MN_ROMIMAGE; | ||
1196 | else if (netxen_p3_has_mn(adapter)) | ||
1197 | fw_type = NX_P3_MN_ROMIMAGE; | ||
1198 | else | ||
1199 | fw_type = NX_P3_CT_ROMIMAGE; | ||
1200 | break; | ||
1201 | |||
1202 | case NX_P3_MN_ROMIMAGE: | ||
1203 | fw_type = NX_P3_CT_ROMIMAGE; | ||
1204 | break; | ||
1205 | |||
1206 | case NX_P2_MN_ROMIMAGE: | ||
1207 | case NX_P3_CT_ROMIMAGE: | ||
1208 | default: | ||
1209 | fw_type = NX_FLASH_ROMIMAGE; | ||
1210 | break; | ||
1211 | } | ||
1212 | |||
1213 | adapter->fw_type = fw_type; | ||
1214 | } | ||
1215 | |||
1216 | static int | ||
1217 | netxen_p3_has_mn(struct netxen_adapter *adapter) | ||
1218 | { | ||
1219 | u32 capability, flashed_ver; | ||
1220 | capability = 0; | ||
1221 | |||
1222 | /* NX2031 always had MN */ | ||
1223 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) | ||
1224 | return 1; | ||
1225 | |||
1226 | netxen_rom_fast_read(adapter, | ||
1227 | NX_FW_VERSION_OFFSET, (int *)&flashed_ver); | ||
1228 | flashed_ver = NETXEN_DECODE_VERSION(flashed_ver); | ||
1229 | |||
1230 | if (flashed_ver >= NETXEN_VERSION_CODE(4, 0, 220)) { | ||
1231 | |||
1232 | capability = NXRD32(adapter, NX_PEG_TUNE_CAPABILITY); | ||
1233 | if (capability & NX_PEG_TUNE_MN_PRESENT) | ||
1234 | return 1; | ||
1235 | } | ||
1236 | return 0; | ||
1237 | } | ||
1238 | |||
1239 | void netxen_request_firmware(struct netxen_adapter *adapter) | ||
1240 | { | ||
1241 | struct pci_dev *pdev = adapter->pdev; | ||
1242 | int rc = 0; | ||
1243 | |||
1244 | adapter->fw_type = NX_UNKNOWN_ROMIMAGE; | ||
1245 | |||
1246 | next: | ||
1247 | nx_get_next_fwtype(adapter); | ||
1248 | |||
1249 | if (adapter->fw_type == NX_FLASH_ROMIMAGE) { | ||
1250 | adapter->fw = NULL; | ||
1251 | } else { | ||
1252 | rc = request_firmware(&adapter->fw, | ||
1253 | fw_name[adapter->fw_type], &pdev->dev); | ||
1254 | if (rc != 0) | ||
1255 | goto next; | ||
1256 | |||
1257 | rc = netxen_validate_firmware(adapter); | ||
1258 | if (rc != 0) { | ||
1259 | release_firmware(adapter->fw); | ||
1260 | msleep(1); | ||
1261 | goto next; | ||
1262 | } | ||
1263 | } | ||
1264 | } | ||
1265 | |||
1266 | |||
1267 | void | ||
1268 | netxen_release_firmware(struct netxen_adapter *adapter) | ||
1269 | { | ||
1270 | if (adapter->fw) | ||
1271 | release_firmware(adapter->fw); | ||
1272 | adapter->fw = NULL; | ||
1273 | } | ||
1274 | |||
1275 | int netxen_init_dummy_dma(struct netxen_adapter *adapter) | ||
1276 | { | ||
1277 | u64 addr; | ||
1278 | u32 hi, lo; | ||
1279 | |||
1280 | if (!NX_IS_REVISION_P2(adapter->ahw.revision_id)) | ||
1281 | return 0; | ||
1282 | |||
1283 | adapter->dummy_dma.addr = pci_alloc_consistent(adapter->pdev, | ||
1284 | NETXEN_HOST_DUMMY_DMA_SIZE, | ||
1285 | &adapter->dummy_dma.phys_addr); | ||
1286 | if (adapter->dummy_dma.addr == NULL) { | ||
1287 | dev_err(&adapter->pdev->dev, | ||
1288 | "ERROR: Could not allocate dummy DMA memory\n"); | ||
1289 | return -ENOMEM; | ||
1290 | } | ||
1291 | |||
1292 | addr = (uint64_t) adapter->dummy_dma.phys_addr; | ||
1293 | hi = (addr >> 32) & 0xffffffff; | ||
1294 | lo = addr & 0xffffffff; | ||
1295 | |||
1296 | NXWR32(adapter, CRB_HOST_DUMMY_BUF_ADDR_HI, hi); | ||
1297 | NXWR32(adapter, CRB_HOST_DUMMY_BUF_ADDR_LO, lo); | ||
1298 | |||
1299 | return 0; | ||
1300 | } | ||
1301 | |||
1302 | /* | ||
1303 | * NetXen DMA watchdog control: | ||
1304 | * | ||
1305 | * Bit 0 : enabled => R/O: 1 watchdog active, 0 inactive | ||
1306 | * Bit 1 : disable_request => 1 req disable dma watchdog | ||
1307 | * Bit 2 : enable_request => 1 req enable dma watchdog | ||
1308 | * Bit 3-31 : unused | ||
1309 | */ | ||
1310 | void netxen_free_dummy_dma(struct netxen_adapter *adapter) | ||
1311 | { | ||
1312 | int i = 100; | ||
1313 | u32 ctrl; | ||
1314 | |||
1315 | if (!NX_IS_REVISION_P2(adapter->ahw.revision_id)) | ||
1316 | return; | ||
1317 | |||
1318 | if (!adapter->dummy_dma.addr) | ||
1319 | return; | ||
1320 | |||
1321 | ctrl = NXRD32(adapter, NETXEN_DMA_WATCHDOG_CTRL); | ||
1322 | if ((ctrl & 0x1) != 0) { | ||
1323 | NXWR32(adapter, NETXEN_DMA_WATCHDOG_CTRL, (ctrl | 0x2)); | ||
1324 | |||
1325 | while ((ctrl & 0x1) != 0) { | ||
1326 | |||
1327 | msleep(50); | ||
1328 | |||
1329 | ctrl = NXRD32(adapter, NETXEN_DMA_WATCHDOG_CTRL); | ||
1330 | |||
1331 | if (--i == 0) | ||
1332 | break; | ||
1333 | } | ||
1334 | } | ||
1335 | |||
1336 | if (i) { | ||
1337 | pci_free_consistent(adapter->pdev, | ||
1338 | NETXEN_HOST_DUMMY_DMA_SIZE, | ||
1339 | adapter->dummy_dma.addr, | ||
1340 | adapter->dummy_dma.phys_addr); | ||
1341 | adapter->dummy_dma.addr = NULL; | ||
1342 | } else | ||
1343 | dev_err(&adapter->pdev->dev, "dma_watchdog_shutdown failed\n"); | ||
1344 | } | ||
1345 | |||
1346 | int netxen_phantom_init(struct netxen_adapter *adapter, int pegtune_val) | ||
1347 | { | ||
1348 | u32 val = 0; | ||
1349 | int retries = 60; | ||
1350 | |||
1351 | if (pegtune_val) | ||
1352 | return 0; | ||
1353 | |||
1354 | do { | ||
1355 | val = NXRD32(adapter, CRB_CMDPEG_STATE); | ||
1356 | |||
1357 | switch (val) { | ||
1358 | case PHAN_INITIALIZE_COMPLETE: | ||
1359 | case PHAN_INITIALIZE_ACK: | ||
1360 | return 0; | ||
1361 | case PHAN_INITIALIZE_FAILED: | ||
1362 | goto out_err; | ||
1363 | default: | ||
1364 | break; | ||
1365 | } | ||
1366 | |||
1367 | msleep(500); | ||
1368 | |||
1369 | } while (--retries); | ||
1370 | |||
1371 | NXWR32(adapter, CRB_CMDPEG_STATE, PHAN_INITIALIZE_FAILED); | ||
1372 | |||
1373 | out_err: | ||
1374 | dev_warn(&adapter->pdev->dev, "firmware init failed\n"); | ||
1375 | return -EIO; | ||
1376 | } | ||
1377 | |||
1378 | static int | ||
1379 | netxen_receive_peg_ready(struct netxen_adapter *adapter) | ||
1380 | { | ||
1381 | u32 val = 0; | ||
1382 | int retries = 2000; | ||
1383 | |||
1384 | do { | ||
1385 | val = NXRD32(adapter, CRB_RCVPEG_STATE); | ||
1386 | |||
1387 | if (val == PHAN_PEG_RCV_INITIALIZED) | ||
1388 | return 0; | ||
1389 | |||
1390 | msleep(10); | ||
1391 | |||
1392 | } while (--retries); | ||
1393 | |||
1394 | if (!retries) { | ||
1395 | printk(KERN_ERR "Receive Peg initialization not " | ||
1396 | "complete, state: 0x%x.\n", val); | ||
1397 | return -EIO; | ||
1398 | } | ||
1399 | |||
1400 | return 0; | ||
1401 | } | ||
1402 | |||
1403 | int netxen_init_firmware(struct netxen_adapter *adapter) | ||
1404 | { | ||
1405 | int err; | ||
1406 | |||
1407 | err = netxen_receive_peg_ready(adapter); | ||
1408 | if (err) | ||
1409 | return err; | ||
1410 | |||
1411 | NXWR32(adapter, CRB_NIC_CAPABILITIES_HOST, INTR_SCHEME_PERPORT); | ||
1412 | NXWR32(adapter, CRB_MPORT_MODE, MPORT_MULTI_FUNCTION_MODE); | ||
1413 | NXWR32(adapter, CRB_CMDPEG_STATE, PHAN_INITIALIZE_ACK); | ||
1414 | |||
1415 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) | ||
1416 | NXWR32(adapter, CRB_NIC_MSI_MODE_HOST, MSI_MODE_MULTIFUNC); | ||
1417 | |||
1418 | return err; | ||
1419 | } | ||
1420 | |||
1421 | static void | ||
1422 | netxen_handle_linkevent(struct netxen_adapter *adapter, nx_fw_msg_t *msg) | ||
1423 | { | ||
1424 | u32 cable_OUI; | ||
1425 | u16 cable_len; | ||
1426 | u16 link_speed; | ||
1427 | u8 link_status, module, duplex, autoneg; | ||
1428 | struct net_device *netdev = adapter->netdev; | ||
1429 | |||
1430 | adapter->has_link_events = 1; | ||
1431 | |||
1432 | cable_OUI = msg->body[1] & 0xffffffff; | ||
1433 | cable_len = (msg->body[1] >> 32) & 0xffff; | ||
1434 | link_speed = (msg->body[1] >> 48) & 0xffff; | ||
1435 | |||
1436 | link_status = msg->body[2] & 0xff; | ||
1437 | duplex = (msg->body[2] >> 16) & 0xff; | ||
1438 | autoneg = (msg->body[2] >> 24) & 0xff; | ||
1439 | |||
1440 | module = (msg->body[2] >> 8) & 0xff; | ||
1441 | if (module == LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLE) { | ||
1442 | printk(KERN_INFO "%s: unsupported cable: OUI 0x%x, length %d\n", | ||
1443 | netdev->name, cable_OUI, cable_len); | ||
1444 | } else if (module == LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLELEN) { | ||
1445 | printk(KERN_INFO "%s: unsupported cable length %d\n", | ||
1446 | netdev->name, cable_len); | ||
1447 | } | ||
1448 | |||
1449 | netxen_advert_link_change(adapter, link_status); | ||
1450 | |||
1451 | /* update link parameters */ | ||
1452 | if (duplex == LINKEVENT_FULL_DUPLEX) | ||
1453 | adapter->link_duplex = DUPLEX_FULL; | ||
1454 | else | ||
1455 | adapter->link_duplex = DUPLEX_HALF; | ||
1456 | adapter->module_type = module; | ||
1457 | adapter->link_autoneg = autoneg; | ||
1458 | adapter->link_speed = link_speed; | ||
1459 | } | ||
1460 | |||
1461 | static void | ||
1462 | netxen_handle_fw_message(int desc_cnt, int index, | ||
1463 | struct nx_host_sds_ring *sds_ring) | ||
1464 | { | ||
1465 | nx_fw_msg_t msg; | ||
1466 | struct status_desc *desc; | ||
1467 | int i = 0, opcode; | ||
1468 | |||
1469 | while (desc_cnt > 0 && i < 8) { | ||
1470 | desc = &sds_ring->desc_head[index]; | ||
1471 | msg.words[i++] = le64_to_cpu(desc->status_desc_data[0]); | ||
1472 | msg.words[i++] = le64_to_cpu(desc->status_desc_data[1]); | ||
1473 | |||
1474 | index = get_next_index(index, sds_ring->num_desc); | ||
1475 | desc_cnt--; | ||
1476 | } | ||
1477 | |||
1478 | opcode = netxen_get_nic_msg_opcode(msg.body[0]); | ||
1479 | switch (opcode) { | ||
1480 | case NX_NIC_C2H_OPCODE_GET_LINKEVENT_RESPONSE: | ||
1481 | netxen_handle_linkevent(sds_ring->adapter, &msg); | ||
1482 | break; | ||
1483 | default: | ||
1484 | break; | ||
1485 | } | ||
1486 | } | ||
1487 | |||
1488 | static int | ||
1489 | netxen_alloc_rx_skb(struct netxen_adapter *adapter, | ||
1490 | struct nx_host_rds_ring *rds_ring, | ||
1491 | struct netxen_rx_buffer *buffer) | ||
1492 | { | ||
1493 | struct sk_buff *skb; | ||
1494 | dma_addr_t dma; | ||
1495 | struct pci_dev *pdev = adapter->pdev; | ||
1496 | |||
1497 | buffer->skb = dev_alloc_skb(rds_ring->skb_size); | ||
1498 | if (!buffer->skb) | ||
1499 | return 1; | ||
1500 | |||
1501 | skb = buffer->skb; | ||
1502 | |||
1503 | if (!adapter->ahw.cut_through) | ||
1504 | skb_reserve(skb, 2); | ||
1505 | |||
1506 | dma = pci_map_single(pdev, skb->data, | ||
1507 | rds_ring->dma_size, PCI_DMA_FROMDEVICE); | ||
1508 | |||
1509 | if (pci_dma_mapping_error(pdev, dma)) { | ||
1510 | dev_kfree_skb_any(skb); | ||
1511 | buffer->skb = NULL; | ||
1512 | return 1; | ||
1513 | } | ||
1514 | |||
1515 | buffer->skb = skb; | ||
1516 | buffer->dma = dma; | ||
1517 | buffer->state = NETXEN_BUFFER_BUSY; | ||
1518 | |||
1519 | return 0; | ||
1520 | } | ||
1521 | |||
1522 | static struct sk_buff *netxen_process_rxbuf(struct netxen_adapter *adapter, | ||
1523 | struct nx_host_rds_ring *rds_ring, u16 index, u16 cksum) | ||
1524 | { | ||
1525 | struct netxen_rx_buffer *buffer; | ||
1526 | struct sk_buff *skb; | ||
1527 | |||
1528 | buffer = &rds_ring->rx_buf_arr[index]; | ||
1529 | |||
1530 | pci_unmap_single(adapter->pdev, buffer->dma, rds_ring->dma_size, | ||
1531 | PCI_DMA_FROMDEVICE); | ||
1532 | |||
1533 | skb = buffer->skb; | ||
1534 | if (!skb) | ||
1535 | goto no_skb; | ||
1536 | |||
1537 | if (likely((adapter->netdev->features & NETIF_F_RXCSUM) | ||
1538 | && cksum == STATUS_CKSUM_OK)) { | ||
1539 | adapter->stats.csummed++; | ||
1540 | skb->ip_summed = CHECKSUM_UNNECESSARY; | ||
1541 | } else | ||
1542 | skb->ip_summed = CHECKSUM_NONE; | ||
1543 | |||
1544 | skb->dev = adapter->netdev; | ||
1545 | |||
1546 | buffer->skb = NULL; | ||
1547 | no_skb: | ||
1548 | buffer->state = NETXEN_BUFFER_FREE; | ||
1549 | return skb; | ||
1550 | } | ||
1551 | |||
1552 | static struct netxen_rx_buffer * | ||
1553 | netxen_process_rcv(struct netxen_adapter *adapter, | ||
1554 | struct nx_host_sds_ring *sds_ring, | ||
1555 | int ring, u64 sts_data0) | ||
1556 | { | ||
1557 | struct net_device *netdev = adapter->netdev; | ||
1558 | struct netxen_recv_context *recv_ctx = &adapter->recv_ctx; | ||
1559 | struct netxen_rx_buffer *buffer; | ||
1560 | struct sk_buff *skb; | ||
1561 | struct nx_host_rds_ring *rds_ring; | ||
1562 | int index, length, cksum, pkt_offset; | ||
1563 | |||
1564 | if (unlikely(ring >= adapter->max_rds_rings)) | ||
1565 | return NULL; | ||
1566 | |||
1567 | rds_ring = &recv_ctx->rds_rings[ring]; | ||
1568 | |||
1569 | index = netxen_get_sts_refhandle(sts_data0); | ||
1570 | if (unlikely(index >= rds_ring->num_desc)) | ||
1571 | return NULL; | ||
1572 | |||
1573 | buffer = &rds_ring->rx_buf_arr[index]; | ||
1574 | |||
1575 | length = netxen_get_sts_totallength(sts_data0); | ||
1576 | cksum = netxen_get_sts_status(sts_data0); | ||
1577 | pkt_offset = netxen_get_sts_pkt_offset(sts_data0); | ||
1578 | |||
1579 | skb = netxen_process_rxbuf(adapter, rds_ring, index, cksum); | ||
1580 | if (!skb) | ||
1581 | return buffer; | ||
1582 | |||
1583 | if (length > rds_ring->skb_size) | ||
1584 | skb_put(skb, rds_ring->skb_size); | ||
1585 | else | ||
1586 | skb_put(skb, length); | ||
1587 | |||
1588 | |||
1589 | if (pkt_offset) | ||
1590 | skb_pull(skb, pkt_offset); | ||
1591 | |||
1592 | skb->protocol = eth_type_trans(skb, netdev); | ||
1593 | |||
1594 | napi_gro_receive(&sds_ring->napi, skb); | ||
1595 | |||
1596 | adapter->stats.rx_pkts++; | ||
1597 | adapter->stats.rxbytes += length; | ||
1598 | |||
1599 | return buffer; | ||
1600 | } | ||
1601 | |||
1602 | #define TCP_HDR_SIZE 20 | ||
1603 | #define TCP_TS_OPTION_SIZE 12 | ||
1604 | #define TCP_TS_HDR_SIZE (TCP_HDR_SIZE + TCP_TS_OPTION_SIZE) | ||
1605 | |||
1606 | static struct netxen_rx_buffer * | ||
1607 | netxen_process_lro(struct netxen_adapter *adapter, | ||
1608 | struct nx_host_sds_ring *sds_ring, | ||
1609 | int ring, u64 sts_data0, u64 sts_data1) | ||
1610 | { | ||
1611 | struct net_device *netdev = adapter->netdev; | ||
1612 | struct netxen_recv_context *recv_ctx = &adapter->recv_ctx; | ||
1613 | struct netxen_rx_buffer *buffer; | ||
1614 | struct sk_buff *skb; | ||
1615 | struct nx_host_rds_ring *rds_ring; | ||
1616 | struct iphdr *iph; | ||
1617 | struct tcphdr *th; | ||
1618 | bool push, timestamp; | ||
1619 | int l2_hdr_offset, l4_hdr_offset; | ||
1620 | int index; | ||
1621 | u16 lro_length, length, data_offset; | ||
1622 | u32 seq_number; | ||
1623 | u8 vhdr_len; | ||
1624 | |||
1625 | if (unlikely(ring > adapter->max_rds_rings)) | ||
1626 | return NULL; | ||
1627 | |||
1628 | rds_ring = &recv_ctx->rds_rings[ring]; | ||
1629 | |||
1630 | index = netxen_get_lro_sts_refhandle(sts_data0); | ||
1631 | if (unlikely(index > rds_ring->num_desc)) | ||
1632 | return NULL; | ||
1633 | |||
1634 | buffer = &rds_ring->rx_buf_arr[index]; | ||
1635 | |||
1636 | timestamp = netxen_get_lro_sts_timestamp(sts_data0); | ||
1637 | lro_length = netxen_get_lro_sts_length(sts_data0); | ||
1638 | l2_hdr_offset = netxen_get_lro_sts_l2_hdr_offset(sts_data0); | ||
1639 | l4_hdr_offset = netxen_get_lro_sts_l4_hdr_offset(sts_data0); | ||
1640 | push = netxen_get_lro_sts_push_flag(sts_data0); | ||
1641 | seq_number = netxen_get_lro_sts_seq_number(sts_data1); | ||
1642 | |||
1643 | skb = netxen_process_rxbuf(adapter, rds_ring, index, STATUS_CKSUM_OK); | ||
1644 | if (!skb) | ||
1645 | return buffer; | ||
1646 | |||
1647 | if (timestamp) | ||
1648 | data_offset = l4_hdr_offset + TCP_TS_HDR_SIZE; | ||
1649 | else | ||
1650 | data_offset = l4_hdr_offset + TCP_HDR_SIZE; | ||
1651 | |||
1652 | skb_put(skb, lro_length + data_offset); | ||
1653 | |||
1654 | skb_pull(skb, l2_hdr_offset); | ||
1655 | skb->protocol = eth_type_trans(skb, netdev); | ||
1656 | |||
1657 | if (skb->protocol == htons(ETH_P_8021Q)) | ||
1658 | vhdr_len = VLAN_HLEN; | ||
1659 | iph = (struct iphdr *)(skb->data + vhdr_len); | ||
1660 | th = (struct tcphdr *)((skb->data + vhdr_len) + (iph->ihl << 2)); | ||
1661 | |||
1662 | length = (iph->ihl << 2) + (th->doff << 2) + lro_length; | ||
1663 | iph->tot_len = htons(length); | ||
1664 | iph->check = 0; | ||
1665 | iph->check = ip_fast_csum((unsigned char *)iph, iph->ihl); | ||
1666 | th->psh = push; | ||
1667 | th->seq = htonl(seq_number); | ||
1668 | |||
1669 | length = skb->len; | ||
1670 | |||
1671 | netif_receive_skb(skb); | ||
1672 | |||
1673 | adapter->stats.lro_pkts++; | ||
1674 | adapter->stats.rxbytes += length; | ||
1675 | |||
1676 | return buffer; | ||
1677 | } | ||
1678 | |||
1679 | #define netxen_merge_rx_buffers(list, head) \ | ||
1680 | do { list_splice_tail_init(list, head); } while (0); | ||
1681 | |||
1682 | int | ||
1683 | netxen_process_rcv_ring(struct nx_host_sds_ring *sds_ring, int max) | ||
1684 | { | ||
1685 | struct netxen_adapter *adapter = sds_ring->adapter; | ||
1686 | |||
1687 | struct list_head *cur; | ||
1688 | |||
1689 | struct status_desc *desc; | ||
1690 | struct netxen_rx_buffer *rxbuf; | ||
1691 | |||
1692 | u32 consumer = sds_ring->consumer; | ||
1693 | |||
1694 | int count = 0; | ||
1695 | u64 sts_data0, sts_data1; | ||
1696 | int opcode, ring = 0, desc_cnt; | ||
1697 | |||
1698 | while (count < max) { | ||
1699 | desc = &sds_ring->desc_head[consumer]; | ||
1700 | sts_data0 = le64_to_cpu(desc->status_desc_data[0]); | ||
1701 | |||
1702 | if (!(sts_data0 & STATUS_OWNER_HOST)) | ||
1703 | break; | ||
1704 | |||
1705 | desc_cnt = netxen_get_sts_desc_cnt(sts_data0); | ||
1706 | |||
1707 | opcode = netxen_get_sts_opcode(sts_data0); | ||
1708 | |||
1709 | switch (opcode) { | ||
1710 | case NETXEN_NIC_RXPKT_DESC: | ||
1711 | case NETXEN_OLD_RXPKT_DESC: | ||
1712 | case NETXEN_NIC_SYN_OFFLOAD: | ||
1713 | ring = netxen_get_sts_type(sts_data0); | ||
1714 | rxbuf = netxen_process_rcv(adapter, sds_ring, | ||
1715 | ring, sts_data0); | ||
1716 | break; | ||
1717 | case NETXEN_NIC_LRO_DESC: | ||
1718 | ring = netxen_get_lro_sts_type(sts_data0); | ||
1719 | sts_data1 = le64_to_cpu(desc->status_desc_data[1]); | ||
1720 | rxbuf = netxen_process_lro(adapter, sds_ring, | ||
1721 | ring, sts_data0, sts_data1); | ||
1722 | break; | ||
1723 | case NETXEN_NIC_RESPONSE_DESC: | ||
1724 | netxen_handle_fw_message(desc_cnt, consumer, sds_ring); | ||
1725 | default: | ||
1726 | goto skip; | ||
1727 | } | ||
1728 | |||
1729 | WARN_ON(desc_cnt > 1); | ||
1730 | |||
1731 | if (rxbuf) | ||
1732 | list_add_tail(&rxbuf->list, &sds_ring->free_list[ring]); | ||
1733 | |||
1734 | skip: | ||
1735 | for (; desc_cnt > 0; desc_cnt--) { | ||
1736 | desc = &sds_ring->desc_head[consumer]; | ||
1737 | desc->status_desc_data[0] = | ||
1738 | cpu_to_le64(STATUS_OWNER_PHANTOM); | ||
1739 | consumer = get_next_index(consumer, sds_ring->num_desc); | ||
1740 | } | ||
1741 | count++; | ||
1742 | } | ||
1743 | |||
1744 | for (ring = 0; ring < adapter->max_rds_rings; ring++) { | ||
1745 | struct nx_host_rds_ring *rds_ring = | ||
1746 | &adapter->recv_ctx.rds_rings[ring]; | ||
1747 | |||
1748 | if (!list_empty(&sds_ring->free_list[ring])) { | ||
1749 | list_for_each(cur, &sds_ring->free_list[ring]) { | ||
1750 | rxbuf = list_entry(cur, | ||
1751 | struct netxen_rx_buffer, list); | ||
1752 | netxen_alloc_rx_skb(adapter, rds_ring, rxbuf); | ||
1753 | } | ||
1754 | spin_lock(&rds_ring->lock); | ||
1755 | netxen_merge_rx_buffers(&sds_ring->free_list[ring], | ||
1756 | &rds_ring->free_list); | ||
1757 | spin_unlock(&rds_ring->lock); | ||
1758 | } | ||
1759 | |||
1760 | netxen_post_rx_buffers_nodb(adapter, rds_ring); | ||
1761 | } | ||
1762 | |||
1763 | if (count) { | ||
1764 | sds_ring->consumer = consumer; | ||
1765 | NXWRIO(adapter, sds_ring->crb_sts_consumer, consumer); | ||
1766 | } | ||
1767 | |||
1768 | return count; | ||
1769 | } | ||
1770 | |||
1771 | /* Process Command status ring */ | ||
1772 | int netxen_process_cmd_ring(struct netxen_adapter *adapter) | ||
1773 | { | ||
1774 | u32 sw_consumer, hw_consumer; | ||
1775 | int count = 0, i; | ||
1776 | struct netxen_cmd_buffer *buffer; | ||
1777 | struct pci_dev *pdev = adapter->pdev; | ||
1778 | struct net_device *netdev = adapter->netdev; | ||
1779 | struct netxen_skb_frag *frag; | ||
1780 | int done = 0; | ||
1781 | struct nx_host_tx_ring *tx_ring = adapter->tx_ring; | ||
1782 | |||
1783 | if (!spin_trylock(&adapter->tx_clean_lock)) | ||
1784 | return 1; | ||
1785 | |||
1786 | sw_consumer = tx_ring->sw_consumer; | ||
1787 | hw_consumer = le32_to_cpu(*(tx_ring->hw_consumer)); | ||
1788 | |||
1789 | while (sw_consumer != hw_consumer) { | ||
1790 | buffer = &tx_ring->cmd_buf_arr[sw_consumer]; | ||
1791 | if (buffer->skb) { | ||
1792 | frag = &buffer->frag_array[0]; | ||
1793 | pci_unmap_single(pdev, frag->dma, frag->length, | ||
1794 | PCI_DMA_TODEVICE); | ||
1795 | frag->dma = 0ULL; | ||
1796 | for (i = 1; i < buffer->frag_count; i++) { | ||
1797 | frag++; /* Get the next frag */ | ||
1798 | pci_unmap_page(pdev, frag->dma, frag->length, | ||
1799 | PCI_DMA_TODEVICE); | ||
1800 | frag->dma = 0ULL; | ||
1801 | } | ||
1802 | |||
1803 | adapter->stats.xmitfinished++; | ||
1804 | dev_kfree_skb_any(buffer->skb); | ||
1805 | buffer->skb = NULL; | ||
1806 | } | ||
1807 | |||
1808 | sw_consumer = get_next_index(sw_consumer, tx_ring->num_desc); | ||
1809 | if (++count >= MAX_STATUS_HANDLE) | ||
1810 | break; | ||
1811 | } | ||
1812 | |||
1813 | if (count && netif_running(netdev)) { | ||
1814 | tx_ring->sw_consumer = sw_consumer; | ||
1815 | |||
1816 | smp_mb(); | ||
1817 | |||
1818 | if (netif_queue_stopped(netdev) && netif_carrier_ok(netdev)) | ||
1819 | if (netxen_tx_avail(tx_ring) > TX_STOP_THRESH) | ||
1820 | netif_wake_queue(netdev); | ||
1821 | adapter->tx_timeo_cnt = 0; | ||
1822 | } | ||
1823 | /* | ||
1824 | * If everything is freed up to consumer then check if the ring is full | ||
1825 | * If the ring is full then check if more needs to be freed and | ||
1826 | * schedule the call back again. | ||
1827 | * | ||
1828 | * This happens when there are 2 CPUs. One could be freeing and the | ||
1829 | * other filling it. If the ring is full when we get out of here and | ||
1830 | * the card has already interrupted the host then the host can miss the | ||
1831 | * interrupt. | ||
1832 | * | ||
1833 | * There is still a possible race condition and the host could miss an | ||
1834 | * interrupt. The card has to take care of this. | ||
1835 | */ | ||
1836 | hw_consumer = le32_to_cpu(*(tx_ring->hw_consumer)); | ||
1837 | done = (sw_consumer == hw_consumer); | ||
1838 | spin_unlock(&adapter->tx_clean_lock); | ||
1839 | |||
1840 | return done; | ||
1841 | } | ||
1842 | |||
1843 | void | ||
1844 | netxen_post_rx_buffers(struct netxen_adapter *adapter, u32 ringid, | ||
1845 | struct nx_host_rds_ring *rds_ring) | ||
1846 | { | ||
1847 | struct rcv_desc *pdesc; | ||
1848 | struct netxen_rx_buffer *buffer; | ||
1849 | int producer, count = 0; | ||
1850 | netxen_ctx_msg msg = 0; | ||
1851 | struct list_head *head; | ||
1852 | |||
1853 | producer = rds_ring->producer; | ||
1854 | |||
1855 | head = &rds_ring->free_list; | ||
1856 | while (!list_empty(head)) { | ||
1857 | |||
1858 | buffer = list_entry(head->next, struct netxen_rx_buffer, list); | ||
1859 | |||
1860 | if (!buffer->skb) { | ||
1861 | if (netxen_alloc_rx_skb(adapter, rds_ring, buffer)) | ||
1862 | break; | ||
1863 | } | ||
1864 | |||
1865 | count++; | ||
1866 | list_del(&buffer->list); | ||
1867 | |||
1868 | /* make a rcv descriptor */ | ||
1869 | pdesc = &rds_ring->desc_head[producer]; | ||
1870 | pdesc->addr_buffer = cpu_to_le64(buffer->dma); | ||
1871 | pdesc->reference_handle = cpu_to_le16(buffer->ref_handle); | ||
1872 | pdesc->buffer_length = cpu_to_le32(rds_ring->dma_size); | ||
1873 | |||
1874 | producer = get_next_index(producer, rds_ring->num_desc); | ||
1875 | } | ||
1876 | |||
1877 | if (count) { | ||
1878 | rds_ring->producer = producer; | ||
1879 | NXWRIO(adapter, rds_ring->crb_rcv_producer, | ||
1880 | (producer-1) & (rds_ring->num_desc-1)); | ||
1881 | |||
1882 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) { | ||
1883 | /* | ||
1884 | * Write a doorbell msg to tell phanmon of change in | ||
1885 | * receive ring producer | ||
1886 | * Only for firmware version < 4.0.0 | ||
1887 | */ | ||
1888 | netxen_set_msg_peg_id(msg, NETXEN_RCV_PEG_DB_ID); | ||
1889 | netxen_set_msg_privid(msg); | ||
1890 | netxen_set_msg_count(msg, | ||
1891 | ((producer - 1) & | ||
1892 | (rds_ring->num_desc - 1))); | ||
1893 | netxen_set_msg_ctxid(msg, adapter->portnum); | ||
1894 | netxen_set_msg_opcode(msg, NETXEN_RCV_PRODUCER(ringid)); | ||
1895 | NXWRIO(adapter, DB_NORMALIZE(adapter, | ||
1896 | NETXEN_RCV_PRODUCER_OFFSET), msg); | ||
1897 | } | ||
1898 | } | ||
1899 | } | ||
1900 | |||
1901 | static void | ||
1902 | netxen_post_rx_buffers_nodb(struct netxen_adapter *adapter, | ||
1903 | struct nx_host_rds_ring *rds_ring) | ||
1904 | { | ||
1905 | struct rcv_desc *pdesc; | ||
1906 | struct netxen_rx_buffer *buffer; | ||
1907 | int producer, count = 0; | ||
1908 | struct list_head *head; | ||
1909 | |||
1910 | if (!spin_trylock(&rds_ring->lock)) | ||
1911 | return; | ||
1912 | |||
1913 | producer = rds_ring->producer; | ||
1914 | |||
1915 | head = &rds_ring->free_list; | ||
1916 | while (!list_empty(head)) { | ||
1917 | |||
1918 | buffer = list_entry(head->next, struct netxen_rx_buffer, list); | ||
1919 | |||
1920 | if (!buffer->skb) { | ||
1921 | if (netxen_alloc_rx_skb(adapter, rds_ring, buffer)) | ||
1922 | break; | ||
1923 | } | ||
1924 | |||
1925 | count++; | ||
1926 | list_del(&buffer->list); | ||
1927 | |||
1928 | /* make a rcv descriptor */ | ||
1929 | pdesc = &rds_ring->desc_head[producer]; | ||
1930 | pdesc->reference_handle = cpu_to_le16(buffer->ref_handle); | ||
1931 | pdesc->buffer_length = cpu_to_le32(rds_ring->dma_size); | ||
1932 | pdesc->addr_buffer = cpu_to_le64(buffer->dma); | ||
1933 | |||
1934 | producer = get_next_index(producer, rds_ring->num_desc); | ||
1935 | } | ||
1936 | |||
1937 | if (count) { | ||
1938 | rds_ring->producer = producer; | ||
1939 | NXWRIO(adapter, rds_ring->crb_rcv_producer, | ||
1940 | (producer - 1) & (rds_ring->num_desc - 1)); | ||
1941 | } | ||
1942 | spin_unlock(&rds_ring->lock); | ||
1943 | } | ||
1944 | |||
1945 | void netxen_nic_clear_stats(struct netxen_adapter *adapter) | ||
1946 | { | ||
1947 | memset(&adapter->stats, 0, sizeof(adapter->stats)); | ||
1948 | } | ||
1949 | |||
diff --git a/drivers/net/ethernet/qlogic/netxen/netxen_nic_main.c b/drivers/net/ethernet/qlogic/netxen/netxen_nic_main.c new file mode 100644 index 000000000000..8c7fc32d781f --- /dev/null +++ b/drivers/net/ethernet/qlogic/netxen/netxen_nic_main.c | |||
@@ -0,0 +1,3100 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2003 - 2009 NetXen, Inc. | ||
3 | * Copyright (C) 2009 - QLogic Corporation. | ||
4 | * All rights reserved. | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or | ||
7 | * modify it under the terms of the GNU General Public License | ||
8 | * as published by the Free Software Foundation; either version 2 | ||
9 | * of the License, or (at your option) any later version. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, but | ||
12 | * 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, | ||
19 | * MA 02111-1307, USA. | ||
20 | * | ||
21 | * The full GNU General Public License is included in this distribution | ||
22 | * in the file called "COPYING". | ||
23 | * | ||
24 | */ | ||
25 | |||
26 | #include <linux/slab.h> | ||
27 | #include <linux/vmalloc.h> | ||
28 | #include <linux/interrupt.h> | ||
29 | #include "netxen_nic_hw.h" | ||
30 | |||
31 | #include "netxen_nic.h" | ||
32 | |||
33 | #include <linux/dma-mapping.h> | ||
34 | #include <linux/if_vlan.h> | ||
35 | #include <net/ip.h> | ||
36 | #include <linux/ipv6.h> | ||
37 | #include <linux/inetdevice.h> | ||
38 | #include <linux/sysfs.h> | ||
39 | #include <linux/aer.h> | ||
40 | |||
41 | MODULE_DESCRIPTION("QLogic/NetXen (1/10) GbE Intelligent Ethernet Driver"); | ||
42 | MODULE_LICENSE("GPL"); | ||
43 | MODULE_VERSION(NETXEN_NIC_LINUX_VERSIONID); | ||
44 | MODULE_FIRMWARE(NX_UNIFIED_ROMIMAGE_NAME); | ||
45 | |||
46 | char netxen_nic_driver_name[] = "netxen_nic"; | ||
47 | static char netxen_nic_driver_string[] = "QLogic/NetXen Network Driver v" | ||
48 | NETXEN_NIC_LINUX_VERSIONID; | ||
49 | |||
50 | static int port_mode = NETXEN_PORT_MODE_AUTO_NEG; | ||
51 | |||
52 | /* Default to restricted 1G auto-neg mode */ | ||
53 | static int wol_port_mode = 5; | ||
54 | |||
55 | static int use_msi = 1; | ||
56 | |||
57 | static int use_msi_x = 1; | ||
58 | |||
59 | static int auto_fw_reset = AUTO_FW_RESET_ENABLED; | ||
60 | module_param(auto_fw_reset, int, 0644); | ||
61 | MODULE_PARM_DESC(auto_fw_reset,"Auto firmware reset (0=disabled, 1=enabled"); | ||
62 | |||
63 | static int __devinit netxen_nic_probe(struct pci_dev *pdev, | ||
64 | const struct pci_device_id *ent); | ||
65 | static void __devexit netxen_nic_remove(struct pci_dev *pdev); | ||
66 | static int netxen_nic_open(struct net_device *netdev); | ||
67 | static int netxen_nic_close(struct net_device *netdev); | ||
68 | static netdev_tx_t netxen_nic_xmit_frame(struct sk_buff *, | ||
69 | struct net_device *); | ||
70 | static void netxen_tx_timeout(struct net_device *netdev); | ||
71 | static void netxen_tx_timeout_task(struct work_struct *work); | ||
72 | static void netxen_fw_poll_work(struct work_struct *work); | ||
73 | static void netxen_schedule_work(struct netxen_adapter *adapter, | ||
74 | work_func_t func, int delay); | ||
75 | static void netxen_cancel_fw_work(struct netxen_adapter *adapter); | ||
76 | static int netxen_nic_poll(struct napi_struct *napi, int budget); | ||
77 | #ifdef CONFIG_NET_POLL_CONTROLLER | ||
78 | static void netxen_nic_poll_controller(struct net_device *netdev); | ||
79 | #endif | ||
80 | |||
81 | static void netxen_create_sysfs_entries(struct netxen_adapter *adapter); | ||
82 | static void netxen_remove_sysfs_entries(struct netxen_adapter *adapter); | ||
83 | static void netxen_create_diag_entries(struct netxen_adapter *adapter); | ||
84 | static void netxen_remove_diag_entries(struct netxen_adapter *adapter); | ||
85 | |||
86 | static int nx_dev_request_aer(struct netxen_adapter *adapter); | ||
87 | static int nx_decr_dev_ref_cnt(struct netxen_adapter *adapter); | ||
88 | static int netxen_can_start_firmware(struct netxen_adapter *adapter); | ||
89 | |||
90 | static irqreturn_t netxen_intr(int irq, void *data); | ||
91 | static irqreturn_t netxen_msi_intr(int irq, void *data); | ||
92 | static irqreturn_t netxen_msix_intr(int irq, void *data); | ||
93 | |||
94 | static void netxen_free_vlan_ip_list(struct netxen_adapter *); | ||
95 | static void netxen_restore_indev_addr(struct net_device *dev, unsigned long); | ||
96 | static struct rtnl_link_stats64 *netxen_nic_get_stats(struct net_device *dev, | ||
97 | struct rtnl_link_stats64 *stats); | ||
98 | static int netxen_nic_set_mac(struct net_device *netdev, void *p); | ||
99 | |||
100 | /* PCI Device ID Table */ | ||
101 | #define ENTRY(device) \ | ||
102 | {PCI_DEVICE(PCI_VENDOR_ID_NETXEN, (device)), \ | ||
103 | .class = PCI_CLASS_NETWORK_ETHERNET << 8, .class_mask = ~0} | ||
104 | |||
105 | static DEFINE_PCI_DEVICE_TABLE(netxen_pci_tbl) = { | ||
106 | ENTRY(PCI_DEVICE_ID_NX2031_10GXSR), | ||
107 | ENTRY(PCI_DEVICE_ID_NX2031_10GCX4), | ||
108 | ENTRY(PCI_DEVICE_ID_NX2031_4GCU), | ||
109 | ENTRY(PCI_DEVICE_ID_NX2031_IMEZ), | ||
110 | ENTRY(PCI_DEVICE_ID_NX2031_HMEZ), | ||
111 | ENTRY(PCI_DEVICE_ID_NX2031_XG_MGMT), | ||
112 | ENTRY(PCI_DEVICE_ID_NX2031_XG_MGMT2), | ||
113 | ENTRY(PCI_DEVICE_ID_NX3031), | ||
114 | {0,} | ||
115 | }; | ||
116 | |||
117 | MODULE_DEVICE_TABLE(pci, netxen_pci_tbl); | ||
118 | |||
119 | static uint32_t crb_cmd_producer[4] = { | ||
120 | CRB_CMD_PRODUCER_OFFSET, CRB_CMD_PRODUCER_OFFSET_1, | ||
121 | CRB_CMD_PRODUCER_OFFSET_2, CRB_CMD_PRODUCER_OFFSET_3 | ||
122 | }; | ||
123 | |||
124 | void | ||
125 | netxen_nic_update_cmd_producer(struct netxen_adapter *adapter, | ||
126 | struct nx_host_tx_ring *tx_ring) | ||
127 | { | ||
128 | NXWRIO(adapter, tx_ring->crb_cmd_producer, tx_ring->producer); | ||
129 | } | ||
130 | |||
131 | static uint32_t crb_cmd_consumer[4] = { | ||
132 | CRB_CMD_CONSUMER_OFFSET, CRB_CMD_CONSUMER_OFFSET_1, | ||
133 | CRB_CMD_CONSUMER_OFFSET_2, CRB_CMD_CONSUMER_OFFSET_3 | ||
134 | }; | ||
135 | |||
136 | static inline void | ||
137 | netxen_nic_update_cmd_consumer(struct netxen_adapter *adapter, | ||
138 | struct nx_host_tx_ring *tx_ring) | ||
139 | { | ||
140 | NXWRIO(adapter, tx_ring->crb_cmd_consumer, tx_ring->sw_consumer); | ||
141 | } | ||
142 | |||
143 | static uint32_t msi_tgt_status[8] = { | ||
144 | ISR_INT_TARGET_STATUS, ISR_INT_TARGET_STATUS_F1, | ||
145 | ISR_INT_TARGET_STATUS_F2, ISR_INT_TARGET_STATUS_F3, | ||
146 | ISR_INT_TARGET_STATUS_F4, ISR_INT_TARGET_STATUS_F5, | ||
147 | ISR_INT_TARGET_STATUS_F6, ISR_INT_TARGET_STATUS_F7 | ||
148 | }; | ||
149 | |||
150 | static struct netxen_legacy_intr_set legacy_intr[] = NX_LEGACY_INTR_CONFIG; | ||
151 | |||
152 | static inline void netxen_nic_disable_int(struct nx_host_sds_ring *sds_ring) | ||
153 | { | ||
154 | struct netxen_adapter *adapter = sds_ring->adapter; | ||
155 | |||
156 | NXWRIO(adapter, sds_ring->crb_intr_mask, 0); | ||
157 | } | ||
158 | |||
159 | static inline void netxen_nic_enable_int(struct nx_host_sds_ring *sds_ring) | ||
160 | { | ||
161 | struct netxen_adapter *adapter = sds_ring->adapter; | ||
162 | |||
163 | NXWRIO(adapter, sds_ring->crb_intr_mask, 0x1); | ||
164 | |||
165 | if (!NETXEN_IS_MSI_FAMILY(adapter)) | ||
166 | NXWRIO(adapter, adapter->tgt_mask_reg, 0xfbff); | ||
167 | } | ||
168 | |||
169 | static int | ||
170 | netxen_alloc_sds_rings(struct netxen_recv_context *recv_ctx, int count) | ||
171 | { | ||
172 | int size = sizeof(struct nx_host_sds_ring) * count; | ||
173 | |||
174 | recv_ctx->sds_rings = kzalloc(size, GFP_KERNEL); | ||
175 | |||
176 | return recv_ctx->sds_rings == NULL; | ||
177 | } | ||
178 | |||
179 | static void | ||
180 | netxen_free_sds_rings(struct netxen_recv_context *recv_ctx) | ||
181 | { | ||
182 | if (recv_ctx->sds_rings != NULL) | ||
183 | kfree(recv_ctx->sds_rings); | ||
184 | |||
185 | recv_ctx->sds_rings = NULL; | ||
186 | } | ||
187 | |||
188 | static int | ||
189 | netxen_napi_add(struct netxen_adapter *adapter, struct net_device *netdev) | ||
190 | { | ||
191 | int ring; | ||
192 | struct nx_host_sds_ring *sds_ring; | ||
193 | struct netxen_recv_context *recv_ctx = &adapter->recv_ctx; | ||
194 | |||
195 | if (netxen_alloc_sds_rings(recv_ctx, adapter->max_sds_rings)) | ||
196 | return -ENOMEM; | ||
197 | |||
198 | for (ring = 0; ring < adapter->max_sds_rings; ring++) { | ||
199 | sds_ring = &recv_ctx->sds_rings[ring]; | ||
200 | netif_napi_add(netdev, &sds_ring->napi, | ||
201 | netxen_nic_poll, NETXEN_NETDEV_WEIGHT); | ||
202 | } | ||
203 | |||
204 | return 0; | ||
205 | } | ||
206 | |||
207 | static void | ||
208 | netxen_napi_del(struct netxen_adapter *adapter) | ||
209 | { | ||
210 | int ring; | ||
211 | struct nx_host_sds_ring *sds_ring; | ||
212 | struct netxen_recv_context *recv_ctx = &adapter->recv_ctx; | ||
213 | |||
214 | for (ring = 0; ring < adapter->max_sds_rings; ring++) { | ||
215 | sds_ring = &recv_ctx->sds_rings[ring]; | ||
216 | netif_napi_del(&sds_ring->napi); | ||
217 | } | ||
218 | |||
219 | netxen_free_sds_rings(&adapter->recv_ctx); | ||
220 | } | ||
221 | |||
222 | static void | ||
223 | netxen_napi_enable(struct netxen_adapter *adapter) | ||
224 | { | ||
225 | int ring; | ||
226 | struct nx_host_sds_ring *sds_ring; | ||
227 | struct netxen_recv_context *recv_ctx = &adapter->recv_ctx; | ||
228 | |||
229 | for (ring = 0; ring < adapter->max_sds_rings; ring++) { | ||
230 | sds_ring = &recv_ctx->sds_rings[ring]; | ||
231 | napi_enable(&sds_ring->napi); | ||
232 | netxen_nic_enable_int(sds_ring); | ||
233 | } | ||
234 | } | ||
235 | |||
236 | static void | ||
237 | netxen_napi_disable(struct netxen_adapter *adapter) | ||
238 | { | ||
239 | int ring; | ||
240 | struct nx_host_sds_ring *sds_ring; | ||
241 | struct netxen_recv_context *recv_ctx = &adapter->recv_ctx; | ||
242 | |||
243 | for (ring = 0; ring < adapter->max_sds_rings; ring++) { | ||
244 | sds_ring = &recv_ctx->sds_rings[ring]; | ||
245 | netxen_nic_disable_int(sds_ring); | ||
246 | napi_synchronize(&sds_ring->napi); | ||
247 | napi_disable(&sds_ring->napi); | ||
248 | } | ||
249 | } | ||
250 | |||
251 | static int nx_set_dma_mask(struct netxen_adapter *adapter) | ||
252 | { | ||
253 | struct pci_dev *pdev = adapter->pdev; | ||
254 | uint64_t mask, cmask; | ||
255 | |||
256 | adapter->pci_using_dac = 0; | ||
257 | |||
258 | mask = DMA_BIT_MASK(32); | ||
259 | cmask = DMA_BIT_MASK(32); | ||
260 | |||
261 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) { | ||
262 | #ifndef CONFIG_IA64 | ||
263 | mask = DMA_BIT_MASK(35); | ||
264 | #endif | ||
265 | } else { | ||
266 | mask = DMA_BIT_MASK(39); | ||
267 | cmask = mask; | ||
268 | } | ||
269 | |||
270 | if (pci_set_dma_mask(pdev, mask) == 0 && | ||
271 | pci_set_consistent_dma_mask(pdev, cmask) == 0) { | ||
272 | adapter->pci_using_dac = 1; | ||
273 | return 0; | ||
274 | } | ||
275 | |||
276 | return -EIO; | ||
277 | } | ||
278 | |||
279 | /* Update addressable range if firmware supports it */ | ||
280 | static int | ||
281 | nx_update_dma_mask(struct netxen_adapter *adapter) | ||
282 | { | ||
283 | int change, shift, err; | ||
284 | uint64_t mask, old_mask, old_cmask; | ||
285 | struct pci_dev *pdev = adapter->pdev; | ||
286 | |||
287 | change = 0; | ||
288 | |||
289 | shift = NXRD32(adapter, CRB_DMA_SHIFT); | ||
290 | if (shift > 32) | ||
291 | return 0; | ||
292 | |||
293 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id) && (shift > 9)) | ||
294 | change = 1; | ||
295 | else if ((adapter->ahw.revision_id == NX_P2_C1) && (shift <= 4)) | ||
296 | change = 1; | ||
297 | |||
298 | if (change) { | ||
299 | old_mask = pdev->dma_mask; | ||
300 | old_cmask = pdev->dev.coherent_dma_mask; | ||
301 | |||
302 | mask = DMA_BIT_MASK(32+shift); | ||
303 | |||
304 | err = pci_set_dma_mask(pdev, mask); | ||
305 | if (err) | ||
306 | goto err_out; | ||
307 | |||
308 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) { | ||
309 | |||
310 | err = pci_set_consistent_dma_mask(pdev, mask); | ||
311 | if (err) | ||
312 | goto err_out; | ||
313 | } | ||
314 | dev_info(&pdev->dev, "using %d-bit dma mask\n", 32+shift); | ||
315 | } | ||
316 | |||
317 | return 0; | ||
318 | |||
319 | err_out: | ||
320 | pci_set_dma_mask(pdev, old_mask); | ||
321 | pci_set_consistent_dma_mask(pdev, old_cmask); | ||
322 | return err; | ||
323 | } | ||
324 | |||
325 | static int | ||
326 | netxen_check_hw_init(struct netxen_adapter *adapter, int first_boot) | ||
327 | { | ||
328 | u32 val, timeout; | ||
329 | |||
330 | if (first_boot == 0x55555555) { | ||
331 | /* This is the first boot after power up */ | ||
332 | NXWR32(adapter, NETXEN_CAM_RAM(0x1fc), NETXEN_BDINFO_MAGIC); | ||
333 | |||
334 | if (!NX_IS_REVISION_P2(adapter->ahw.revision_id)) | ||
335 | return 0; | ||
336 | |||
337 | /* PCI bus master workaround */ | ||
338 | first_boot = NXRD32(adapter, NETXEN_PCIE_REG(0x4)); | ||
339 | if (!(first_boot & 0x4)) { | ||
340 | first_boot |= 0x4; | ||
341 | NXWR32(adapter, NETXEN_PCIE_REG(0x4), first_boot); | ||
342 | NXRD32(adapter, NETXEN_PCIE_REG(0x4)); | ||
343 | } | ||
344 | |||
345 | /* This is the first boot after power up */ | ||
346 | first_boot = NXRD32(adapter, NETXEN_ROMUSB_GLB_SW_RESET); | ||
347 | if (first_boot != 0x80000f) { | ||
348 | /* clear the register for future unloads/loads */ | ||
349 | NXWR32(adapter, NETXEN_CAM_RAM(0x1fc), 0); | ||
350 | return -EIO; | ||
351 | } | ||
352 | |||
353 | /* Start P2 boot loader */ | ||
354 | val = NXRD32(adapter, NETXEN_ROMUSB_GLB_PEGTUNE_DONE); | ||
355 | NXWR32(adapter, NETXEN_ROMUSB_GLB_PEGTUNE_DONE, val | 0x1); | ||
356 | timeout = 0; | ||
357 | do { | ||
358 | msleep(1); | ||
359 | val = NXRD32(adapter, NETXEN_CAM_RAM(0x1fc)); | ||
360 | |||
361 | if (++timeout > 5000) | ||
362 | return -EIO; | ||
363 | |||
364 | } while (val == NETXEN_BDINFO_MAGIC); | ||
365 | } | ||
366 | return 0; | ||
367 | } | ||
368 | |||
369 | static void netxen_set_port_mode(struct netxen_adapter *adapter) | ||
370 | { | ||
371 | u32 val, data; | ||
372 | |||
373 | val = adapter->ahw.board_type; | ||
374 | if ((val == NETXEN_BRDTYPE_P3_HMEZ) || | ||
375 | (val == NETXEN_BRDTYPE_P3_XG_LOM)) { | ||
376 | if (port_mode == NETXEN_PORT_MODE_802_3_AP) { | ||
377 | data = NETXEN_PORT_MODE_802_3_AP; | ||
378 | NXWR32(adapter, NETXEN_PORT_MODE_ADDR, data); | ||
379 | } else if (port_mode == NETXEN_PORT_MODE_XG) { | ||
380 | data = NETXEN_PORT_MODE_XG; | ||
381 | NXWR32(adapter, NETXEN_PORT_MODE_ADDR, data); | ||
382 | } else if (port_mode == NETXEN_PORT_MODE_AUTO_NEG_1G) { | ||
383 | data = NETXEN_PORT_MODE_AUTO_NEG_1G; | ||
384 | NXWR32(adapter, NETXEN_PORT_MODE_ADDR, data); | ||
385 | } else if (port_mode == NETXEN_PORT_MODE_AUTO_NEG_XG) { | ||
386 | data = NETXEN_PORT_MODE_AUTO_NEG_XG; | ||
387 | NXWR32(adapter, NETXEN_PORT_MODE_ADDR, data); | ||
388 | } else { | ||
389 | data = NETXEN_PORT_MODE_AUTO_NEG; | ||
390 | NXWR32(adapter, NETXEN_PORT_MODE_ADDR, data); | ||
391 | } | ||
392 | |||
393 | if ((wol_port_mode != NETXEN_PORT_MODE_802_3_AP) && | ||
394 | (wol_port_mode != NETXEN_PORT_MODE_XG) && | ||
395 | (wol_port_mode != NETXEN_PORT_MODE_AUTO_NEG_1G) && | ||
396 | (wol_port_mode != NETXEN_PORT_MODE_AUTO_NEG_XG)) { | ||
397 | wol_port_mode = NETXEN_PORT_MODE_AUTO_NEG; | ||
398 | } | ||
399 | NXWR32(adapter, NETXEN_WOL_PORT_MODE, wol_port_mode); | ||
400 | } | ||
401 | } | ||
402 | |||
403 | static void netxen_set_msix_bit(struct pci_dev *pdev, int enable) | ||
404 | { | ||
405 | u32 control; | ||
406 | int pos; | ||
407 | |||
408 | pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX); | ||
409 | if (pos) { | ||
410 | pci_read_config_dword(pdev, pos, &control); | ||
411 | if (enable) | ||
412 | control |= PCI_MSIX_FLAGS_ENABLE; | ||
413 | else | ||
414 | control = 0; | ||
415 | pci_write_config_dword(pdev, pos, control); | ||
416 | } | ||
417 | } | ||
418 | |||
419 | static void netxen_init_msix_entries(struct netxen_adapter *adapter, int count) | ||
420 | { | ||
421 | int i; | ||
422 | |||
423 | for (i = 0; i < count; i++) | ||
424 | adapter->msix_entries[i].entry = i; | ||
425 | } | ||
426 | |||
427 | static int | ||
428 | netxen_read_mac_addr(struct netxen_adapter *adapter) | ||
429 | { | ||
430 | int i; | ||
431 | unsigned char *p; | ||
432 | u64 mac_addr; | ||
433 | struct net_device *netdev = adapter->netdev; | ||
434 | struct pci_dev *pdev = adapter->pdev; | ||
435 | |||
436 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) { | ||
437 | if (netxen_p3_get_mac_addr(adapter, &mac_addr) != 0) | ||
438 | return -EIO; | ||
439 | } else { | ||
440 | if (netxen_get_flash_mac_addr(adapter, &mac_addr) != 0) | ||
441 | return -EIO; | ||
442 | } | ||
443 | |||
444 | p = (unsigned char *)&mac_addr; | ||
445 | for (i = 0; i < 6; i++) | ||
446 | netdev->dev_addr[i] = *(p + 5 - i); | ||
447 | |||
448 | memcpy(netdev->perm_addr, netdev->dev_addr, netdev->addr_len); | ||
449 | memcpy(adapter->mac_addr, netdev->dev_addr, netdev->addr_len); | ||
450 | |||
451 | /* set station address */ | ||
452 | |||
453 | if (!is_valid_ether_addr(netdev->perm_addr)) | ||
454 | dev_warn(&pdev->dev, "Bad MAC address %pM.\n", netdev->dev_addr); | ||
455 | |||
456 | return 0; | ||
457 | } | ||
458 | |||
459 | static int netxen_nic_set_mac(struct net_device *netdev, void *p) | ||
460 | { | ||
461 | struct netxen_adapter *adapter = netdev_priv(netdev); | ||
462 | struct sockaddr *addr = p; | ||
463 | |||
464 | if (!is_valid_ether_addr(addr->sa_data)) | ||
465 | return -EINVAL; | ||
466 | |||
467 | if (netif_running(netdev)) { | ||
468 | netif_device_detach(netdev); | ||
469 | netxen_napi_disable(adapter); | ||
470 | } | ||
471 | |||
472 | memcpy(adapter->mac_addr, addr->sa_data, netdev->addr_len); | ||
473 | memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); | ||
474 | adapter->macaddr_set(adapter, addr->sa_data); | ||
475 | |||
476 | if (netif_running(netdev)) { | ||
477 | netif_device_attach(netdev); | ||
478 | netxen_napi_enable(adapter); | ||
479 | } | ||
480 | return 0; | ||
481 | } | ||
482 | |||
483 | static void netxen_set_multicast_list(struct net_device *dev) | ||
484 | { | ||
485 | struct netxen_adapter *adapter = netdev_priv(dev); | ||
486 | |||
487 | adapter->set_multi(dev); | ||
488 | } | ||
489 | |||
490 | static u32 netxen_fix_features(struct net_device *dev, u32 features) | ||
491 | { | ||
492 | if (!(features & NETIF_F_RXCSUM)) { | ||
493 | netdev_info(dev, "disabling LRO as RXCSUM is off\n"); | ||
494 | |||
495 | features &= ~NETIF_F_LRO; | ||
496 | } | ||
497 | |||
498 | return features; | ||
499 | } | ||
500 | |||
501 | static int netxen_set_features(struct net_device *dev, u32 features) | ||
502 | { | ||
503 | struct netxen_adapter *adapter = netdev_priv(dev); | ||
504 | int hw_lro; | ||
505 | |||
506 | if (!((dev->features ^ features) & NETIF_F_LRO)) | ||
507 | return 0; | ||
508 | |||
509 | hw_lro = (features & NETIF_F_LRO) ? NETXEN_NIC_LRO_ENABLED | ||
510 | : NETXEN_NIC_LRO_DISABLED; | ||
511 | |||
512 | if (netxen_config_hw_lro(adapter, hw_lro)) | ||
513 | return -EIO; | ||
514 | |||
515 | if (!(features & NETIF_F_LRO) && netxen_send_lro_cleanup(adapter)) | ||
516 | return -EIO; | ||
517 | |||
518 | return 0; | ||
519 | } | ||
520 | |||
521 | static const struct net_device_ops netxen_netdev_ops = { | ||
522 | .ndo_open = netxen_nic_open, | ||
523 | .ndo_stop = netxen_nic_close, | ||
524 | .ndo_start_xmit = netxen_nic_xmit_frame, | ||
525 | .ndo_get_stats64 = netxen_nic_get_stats, | ||
526 | .ndo_validate_addr = eth_validate_addr, | ||
527 | .ndo_set_multicast_list = netxen_set_multicast_list, | ||
528 | .ndo_set_mac_address = netxen_nic_set_mac, | ||
529 | .ndo_change_mtu = netxen_nic_change_mtu, | ||
530 | .ndo_tx_timeout = netxen_tx_timeout, | ||
531 | .ndo_fix_features = netxen_fix_features, | ||
532 | .ndo_set_features = netxen_set_features, | ||
533 | #ifdef CONFIG_NET_POLL_CONTROLLER | ||
534 | .ndo_poll_controller = netxen_nic_poll_controller, | ||
535 | #endif | ||
536 | }; | ||
537 | |||
538 | static void | ||
539 | netxen_setup_intr(struct netxen_adapter *adapter) | ||
540 | { | ||
541 | struct netxen_legacy_intr_set *legacy_intrp; | ||
542 | struct pci_dev *pdev = adapter->pdev; | ||
543 | int err, num_msix; | ||
544 | |||
545 | if (adapter->rss_supported) { | ||
546 | num_msix = (num_online_cpus() >= MSIX_ENTRIES_PER_ADAPTER) ? | ||
547 | MSIX_ENTRIES_PER_ADAPTER : 2; | ||
548 | } else | ||
549 | num_msix = 1; | ||
550 | |||
551 | adapter->max_sds_rings = 1; | ||
552 | |||
553 | adapter->flags &= ~(NETXEN_NIC_MSI_ENABLED | NETXEN_NIC_MSIX_ENABLED); | ||
554 | |||
555 | if (adapter->ahw.revision_id >= NX_P3_B0) | ||
556 | legacy_intrp = &legacy_intr[adapter->ahw.pci_func]; | ||
557 | else | ||
558 | legacy_intrp = &legacy_intr[0]; | ||
559 | |||
560 | adapter->int_vec_bit = legacy_intrp->int_vec_bit; | ||
561 | adapter->tgt_status_reg = netxen_get_ioaddr(adapter, | ||
562 | legacy_intrp->tgt_status_reg); | ||
563 | adapter->tgt_mask_reg = netxen_get_ioaddr(adapter, | ||
564 | legacy_intrp->tgt_mask_reg); | ||
565 | adapter->pci_int_reg = netxen_get_ioaddr(adapter, | ||
566 | legacy_intrp->pci_int_reg); | ||
567 | adapter->isr_int_vec = netxen_get_ioaddr(adapter, ISR_INT_VECTOR); | ||
568 | |||
569 | if (adapter->ahw.revision_id >= NX_P3_B1) | ||
570 | adapter->crb_int_state_reg = netxen_get_ioaddr(adapter, | ||
571 | ISR_INT_STATE_REG); | ||
572 | else | ||
573 | adapter->crb_int_state_reg = netxen_get_ioaddr(adapter, | ||
574 | CRB_INT_VECTOR); | ||
575 | |||
576 | netxen_set_msix_bit(pdev, 0); | ||
577 | |||
578 | if (adapter->msix_supported) { | ||
579 | |||
580 | netxen_init_msix_entries(adapter, num_msix); | ||
581 | err = pci_enable_msix(pdev, adapter->msix_entries, num_msix); | ||
582 | if (err == 0) { | ||
583 | adapter->flags |= NETXEN_NIC_MSIX_ENABLED; | ||
584 | netxen_set_msix_bit(pdev, 1); | ||
585 | |||
586 | if (adapter->rss_supported) | ||
587 | adapter->max_sds_rings = num_msix; | ||
588 | |||
589 | dev_info(&pdev->dev, "using msi-x interrupts\n"); | ||
590 | return; | ||
591 | } | ||
592 | |||
593 | if (err > 0) | ||
594 | pci_disable_msix(pdev); | ||
595 | |||
596 | /* fall through for msi */ | ||
597 | } | ||
598 | |||
599 | if (use_msi && !pci_enable_msi(pdev)) { | ||
600 | adapter->flags |= NETXEN_NIC_MSI_ENABLED; | ||
601 | adapter->tgt_status_reg = netxen_get_ioaddr(adapter, | ||
602 | msi_tgt_status[adapter->ahw.pci_func]); | ||
603 | dev_info(&pdev->dev, "using msi interrupts\n"); | ||
604 | adapter->msix_entries[0].vector = pdev->irq; | ||
605 | return; | ||
606 | } | ||
607 | |||
608 | dev_info(&pdev->dev, "using legacy interrupts\n"); | ||
609 | adapter->msix_entries[0].vector = pdev->irq; | ||
610 | } | ||
611 | |||
612 | static void | ||
613 | netxen_teardown_intr(struct netxen_adapter *adapter) | ||
614 | { | ||
615 | if (adapter->flags & NETXEN_NIC_MSIX_ENABLED) | ||
616 | pci_disable_msix(adapter->pdev); | ||
617 | if (adapter->flags & NETXEN_NIC_MSI_ENABLED) | ||
618 | pci_disable_msi(adapter->pdev); | ||
619 | } | ||
620 | |||
621 | static void | ||
622 | netxen_cleanup_pci_map(struct netxen_adapter *adapter) | ||
623 | { | ||
624 | if (adapter->ahw.db_base != NULL) | ||
625 | iounmap(adapter->ahw.db_base); | ||
626 | if (adapter->ahw.pci_base0 != NULL) | ||
627 | iounmap(adapter->ahw.pci_base0); | ||
628 | if (adapter->ahw.pci_base1 != NULL) | ||
629 | iounmap(adapter->ahw.pci_base1); | ||
630 | if (adapter->ahw.pci_base2 != NULL) | ||
631 | iounmap(adapter->ahw.pci_base2); | ||
632 | } | ||
633 | |||
634 | static int | ||
635 | netxen_setup_pci_map(struct netxen_adapter *adapter) | ||
636 | { | ||
637 | void __iomem *db_ptr = NULL; | ||
638 | |||
639 | resource_size_t mem_base, db_base; | ||
640 | unsigned long mem_len, db_len = 0; | ||
641 | |||
642 | struct pci_dev *pdev = adapter->pdev; | ||
643 | int pci_func = adapter->ahw.pci_func; | ||
644 | struct netxen_hardware_context *ahw = &adapter->ahw; | ||
645 | |||
646 | int err = 0; | ||
647 | |||
648 | /* | ||
649 | * Set the CRB window to invalid. If any register in window 0 is | ||
650 | * accessed it should set the window to 0 and then reset it to 1. | ||
651 | */ | ||
652 | adapter->ahw.crb_win = -1; | ||
653 | adapter->ahw.ocm_win = -1; | ||
654 | |||
655 | /* remap phys address */ | ||
656 | mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */ | ||
657 | mem_len = pci_resource_len(pdev, 0); | ||
658 | |||
659 | /* 128 Meg of memory */ | ||
660 | if (mem_len == NETXEN_PCI_128MB_SIZE) { | ||
661 | |||
662 | ahw->pci_base0 = ioremap(mem_base, FIRST_PAGE_GROUP_SIZE); | ||
663 | ahw->pci_base1 = ioremap(mem_base + SECOND_PAGE_GROUP_START, | ||
664 | SECOND_PAGE_GROUP_SIZE); | ||
665 | ahw->pci_base2 = ioremap(mem_base + THIRD_PAGE_GROUP_START, | ||
666 | THIRD_PAGE_GROUP_SIZE); | ||
667 | if (ahw->pci_base0 == NULL || ahw->pci_base1 == NULL || | ||
668 | ahw->pci_base2 == NULL) { | ||
669 | dev_err(&pdev->dev, "failed to map PCI bar 0\n"); | ||
670 | err = -EIO; | ||
671 | goto err_out; | ||
672 | } | ||
673 | |||
674 | ahw->pci_len0 = FIRST_PAGE_GROUP_SIZE; | ||
675 | |||
676 | } else if (mem_len == NETXEN_PCI_32MB_SIZE) { | ||
677 | |||
678 | ahw->pci_base1 = ioremap(mem_base, SECOND_PAGE_GROUP_SIZE); | ||
679 | ahw->pci_base2 = ioremap(mem_base + THIRD_PAGE_GROUP_START - | ||
680 | SECOND_PAGE_GROUP_START, THIRD_PAGE_GROUP_SIZE); | ||
681 | if (ahw->pci_base1 == NULL || ahw->pci_base2 == NULL) { | ||
682 | dev_err(&pdev->dev, "failed to map PCI bar 0\n"); | ||
683 | err = -EIO; | ||
684 | goto err_out; | ||
685 | } | ||
686 | |||
687 | } else if (mem_len == NETXEN_PCI_2MB_SIZE) { | ||
688 | |||
689 | ahw->pci_base0 = pci_ioremap_bar(pdev, 0); | ||
690 | if (ahw->pci_base0 == NULL) { | ||
691 | dev_err(&pdev->dev, "failed to map PCI bar 0\n"); | ||
692 | return -EIO; | ||
693 | } | ||
694 | ahw->pci_len0 = mem_len; | ||
695 | } else { | ||
696 | return -EIO; | ||
697 | } | ||
698 | |||
699 | netxen_setup_hwops(adapter); | ||
700 | |||
701 | dev_info(&pdev->dev, "%dMB memory map\n", (int)(mem_len>>20)); | ||
702 | |||
703 | if (NX_IS_REVISION_P3P(adapter->ahw.revision_id)) { | ||
704 | adapter->ahw.ocm_win_crb = netxen_get_ioaddr(adapter, | ||
705 | NETXEN_PCIX_PS_REG(PCIX_OCM_WINDOW_REG(pci_func))); | ||
706 | |||
707 | } else if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) { | ||
708 | adapter->ahw.ocm_win_crb = netxen_get_ioaddr(adapter, | ||
709 | NETXEN_PCIX_PS_REG(PCIE_MN_WINDOW_REG(pci_func))); | ||
710 | } | ||
711 | |||
712 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) | ||
713 | goto skip_doorbell; | ||
714 | |||
715 | db_base = pci_resource_start(pdev, 4); /* doorbell is on bar 4 */ | ||
716 | db_len = pci_resource_len(pdev, 4); | ||
717 | |||
718 | if (db_len == 0) { | ||
719 | printk(KERN_ERR "%s: doorbell is disabled\n", | ||
720 | netxen_nic_driver_name); | ||
721 | err = -EIO; | ||
722 | goto err_out; | ||
723 | } | ||
724 | |||
725 | db_ptr = ioremap(db_base, NETXEN_DB_MAPSIZE_BYTES); | ||
726 | if (!db_ptr) { | ||
727 | printk(KERN_ERR "%s: Failed to allocate doorbell map.", | ||
728 | netxen_nic_driver_name); | ||
729 | err = -EIO; | ||
730 | goto err_out; | ||
731 | } | ||
732 | |||
733 | skip_doorbell: | ||
734 | adapter->ahw.db_base = db_ptr; | ||
735 | adapter->ahw.db_len = db_len; | ||
736 | return 0; | ||
737 | |||
738 | err_out: | ||
739 | netxen_cleanup_pci_map(adapter); | ||
740 | return err; | ||
741 | } | ||
742 | |||
743 | static void | ||
744 | netxen_check_options(struct netxen_adapter *adapter) | ||
745 | { | ||
746 | u32 fw_major, fw_minor, fw_build; | ||
747 | char brd_name[NETXEN_MAX_SHORT_NAME]; | ||
748 | char serial_num[32]; | ||
749 | int i, offset, val; | ||
750 | int *ptr32; | ||
751 | struct pci_dev *pdev = adapter->pdev; | ||
752 | |||
753 | adapter->driver_mismatch = 0; | ||
754 | |||
755 | ptr32 = (int *)&serial_num; | ||
756 | offset = NX_FW_SERIAL_NUM_OFFSET; | ||
757 | for (i = 0; i < 8; i++) { | ||
758 | if (netxen_rom_fast_read(adapter, offset, &val) == -1) { | ||
759 | dev_err(&pdev->dev, "error reading board info\n"); | ||
760 | adapter->driver_mismatch = 1; | ||
761 | return; | ||
762 | } | ||
763 | ptr32[i] = cpu_to_le32(val); | ||
764 | offset += sizeof(u32); | ||
765 | } | ||
766 | |||
767 | fw_major = NXRD32(adapter, NETXEN_FW_VERSION_MAJOR); | ||
768 | fw_minor = NXRD32(adapter, NETXEN_FW_VERSION_MINOR); | ||
769 | fw_build = NXRD32(adapter, NETXEN_FW_VERSION_SUB); | ||
770 | |||
771 | adapter->fw_version = NETXEN_VERSION_CODE(fw_major, fw_minor, fw_build); | ||
772 | |||
773 | if (adapter->portnum == 0) { | ||
774 | get_brd_name_by_type(adapter->ahw.board_type, brd_name); | ||
775 | |||
776 | pr_info("%s: %s Board S/N %s Chip rev 0x%x\n", | ||
777 | module_name(THIS_MODULE), | ||
778 | brd_name, serial_num, adapter->ahw.revision_id); | ||
779 | } | ||
780 | |||
781 | if (adapter->fw_version < NETXEN_VERSION_CODE(3, 4, 216)) { | ||
782 | adapter->driver_mismatch = 1; | ||
783 | dev_warn(&pdev->dev, "firmware version %d.%d.%d unsupported\n", | ||
784 | fw_major, fw_minor, fw_build); | ||
785 | return; | ||
786 | } | ||
787 | |||
788 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) { | ||
789 | i = NXRD32(adapter, NETXEN_SRE_MISC); | ||
790 | adapter->ahw.cut_through = (i & 0x8000) ? 1 : 0; | ||
791 | } | ||
792 | |||
793 | dev_info(&pdev->dev, "firmware v%d.%d.%d [%s]\n", | ||
794 | fw_major, fw_minor, fw_build, | ||
795 | adapter->ahw.cut_through ? "cut-through" : "legacy"); | ||
796 | |||
797 | if (adapter->fw_version >= NETXEN_VERSION_CODE(4, 0, 222)) | ||
798 | adapter->capabilities = NXRD32(adapter, CRB_FW_CAPABILITIES_1); | ||
799 | |||
800 | if (adapter->ahw.port_type == NETXEN_NIC_XGBE) { | ||
801 | adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_10G; | ||
802 | adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_10G; | ||
803 | } else if (adapter->ahw.port_type == NETXEN_NIC_GBE) { | ||
804 | adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_1G; | ||
805 | adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_1G; | ||
806 | } | ||
807 | |||
808 | adapter->msix_supported = 0; | ||
809 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) { | ||
810 | adapter->msix_supported = !!use_msi_x; | ||
811 | adapter->rss_supported = !!use_msi_x; | ||
812 | } else { | ||
813 | u32 flashed_ver = 0; | ||
814 | netxen_rom_fast_read(adapter, | ||
815 | NX_FW_VERSION_OFFSET, (int *)&flashed_ver); | ||
816 | flashed_ver = NETXEN_DECODE_VERSION(flashed_ver); | ||
817 | |||
818 | if (flashed_ver >= NETXEN_VERSION_CODE(3, 4, 336)) { | ||
819 | switch (adapter->ahw.board_type) { | ||
820 | case NETXEN_BRDTYPE_P2_SB31_10G: | ||
821 | case NETXEN_BRDTYPE_P2_SB31_10G_CX4: | ||
822 | adapter->msix_supported = !!use_msi_x; | ||
823 | adapter->rss_supported = !!use_msi_x; | ||
824 | break; | ||
825 | default: | ||
826 | break; | ||
827 | } | ||
828 | } | ||
829 | } | ||
830 | |||
831 | adapter->num_txd = MAX_CMD_DESCRIPTORS; | ||
832 | |||
833 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) { | ||
834 | adapter->num_lro_rxd = MAX_LRO_RCV_DESCRIPTORS; | ||
835 | adapter->max_rds_rings = 3; | ||
836 | } else { | ||
837 | adapter->num_lro_rxd = 0; | ||
838 | adapter->max_rds_rings = 2; | ||
839 | } | ||
840 | } | ||
841 | |||
842 | static int | ||
843 | netxen_start_firmware(struct netxen_adapter *adapter) | ||
844 | { | ||
845 | int val, err, first_boot; | ||
846 | struct pci_dev *pdev = adapter->pdev; | ||
847 | |||
848 | /* required for NX2031 dummy dma */ | ||
849 | err = nx_set_dma_mask(adapter); | ||
850 | if (err) | ||
851 | return err; | ||
852 | |||
853 | if (!netxen_can_start_firmware(adapter)) | ||
854 | goto wait_init; | ||
855 | |||
856 | first_boot = NXRD32(adapter, NETXEN_CAM_RAM(0x1fc)); | ||
857 | |||
858 | err = netxen_check_hw_init(adapter, first_boot); | ||
859 | if (err) { | ||
860 | dev_err(&pdev->dev, "error in init HW init sequence\n"); | ||
861 | return err; | ||
862 | } | ||
863 | |||
864 | netxen_request_firmware(adapter); | ||
865 | |||
866 | err = netxen_need_fw_reset(adapter); | ||
867 | if (err < 0) | ||
868 | goto err_out; | ||
869 | if (err == 0) | ||
870 | goto wait_init; | ||
871 | |||
872 | if (first_boot != 0x55555555) { | ||
873 | NXWR32(adapter, CRB_CMDPEG_STATE, 0); | ||
874 | netxen_pinit_from_rom(adapter); | ||
875 | msleep(1); | ||
876 | } | ||
877 | |||
878 | NXWR32(adapter, CRB_DMA_SHIFT, 0x55555555); | ||
879 | NXWR32(adapter, NETXEN_PEG_HALT_STATUS1, 0); | ||
880 | NXWR32(adapter, NETXEN_PEG_HALT_STATUS2, 0); | ||
881 | |||
882 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) | ||
883 | netxen_set_port_mode(adapter); | ||
884 | |||
885 | err = netxen_load_firmware(adapter); | ||
886 | if (err) | ||
887 | goto err_out; | ||
888 | |||
889 | netxen_release_firmware(adapter); | ||
890 | |||
891 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) { | ||
892 | |||
893 | /* Initialize multicast addr pool owners */ | ||
894 | val = 0x7654; | ||
895 | if (adapter->ahw.port_type == NETXEN_NIC_XGBE) | ||
896 | val |= 0x0f000000; | ||
897 | NXWR32(adapter, NETXEN_MAC_ADDR_CNTL_REG, val); | ||
898 | |||
899 | } | ||
900 | |||
901 | err = netxen_init_dummy_dma(adapter); | ||
902 | if (err) | ||
903 | goto err_out; | ||
904 | |||
905 | /* | ||
906 | * Tell the hardware our version number. | ||
907 | */ | ||
908 | val = (_NETXEN_NIC_LINUX_MAJOR << 16) | ||
909 | | ((_NETXEN_NIC_LINUX_MINOR << 8)) | ||
910 | | (_NETXEN_NIC_LINUX_SUBVERSION); | ||
911 | NXWR32(adapter, CRB_DRIVER_VERSION, val); | ||
912 | |||
913 | wait_init: | ||
914 | /* Handshake with the card before we register the devices. */ | ||
915 | err = netxen_phantom_init(adapter, NETXEN_NIC_PEG_TUNE); | ||
916 | if (err) { | ||
917 | netxen_free_dummy_dma(adapter); | ||
918 | goto err_out; | ||
919 | } | ||
920 | |||
921 | NXWR32(adapter, NX_CRB_DEV_STATE, NX_DEV_READY); | ||
922 | |||
923 | nx_update_dma_mask(adapter); | ||
924 | |||
925 | netxen_check_options(adapter); | ||
926 | |||
927 | adapter->need_fw_reset = 0; | ||
928 | |||
929 | /* fall through and release firmware */ | ||
930 | |||
931 | err_out: | ||
932 | netxen_release_firmware(adapter); | ||
933 | return err; | ||
934 | } | ||
935 | |||
936 | static int | ||
937 | netxen_nic_request_irq(struct netxen_adapter *adapter) | ||
938 | { | ||
939 | irq_handler_t handler; | ||
940 | struct nx_host_sds_ring *sds_ring; | ||
941 | int err, ring; | ||
942 | |||
943 | unsigned long flags = 0; | ||
944 | struct net_device *netdev = adapter->netdev; | ||
945 | struct netxen_recv_context *recv_ctx = &adapter->recv_ctx; | ||
946 | |||
947 | if (adapter->flags & NETXEN_NIC_MSIX_ENABLED) | ||
948 | handler = netxen_msix_intr; | ||
949 | else if (adapter->flags & NETXEN_NIC_MSI_ENABLED) | ||
950 | handler = netxen_msi_intr; | ||
951 | else { | ||
952 | flags |= IRQF_SHARED; | ||
953 | handler = netxen_intr; | ||
954 | } | ||
955 | adapter->irq = netdev->irq; | ||
956 | |||
957 | for (ring = 0; ring < adapter->max_sds_rings; ring++) { | ||
958 | sds_ring = &recv_ctx->sds_rings[ring]; | ||
959 | sprintf(sds_ring->name, "%s[%d]", netdev->name, ring); | ||
960 | err = request_irq(sds_ring->irq, handler, | ||
961 | flags, sds_ring->name, sds_ring); | ||
962 | if (err) | ||
963 | return err; | ||
964 | } | ||
965 | |||
966 | return 0; | ||
967 | } | ||
968 | |||
969 | static void | ||
970 | netxen_nic_free_irq(struct netxen_adapter *adapter) | ||
971 | { | ||
972 | int ring; | ||
973 | struct nx_host_sds_ring *sds_ring; | ||
974 | |||
975 | struct netxen_recv_context *recv_ctx = &adapter->recv_ctx; | ||
976 | |||
977 | for (ring = 0; ring < adapter->max_sds_rings; ring++) { | ||
978 | sds_ring = &recv_ctx->sds_rings[ring]; | ||
979 | free_irq(sds_ring->irq, sds_ring); | ||
980 | } | ||
981 | } | ||
982 | |||
983 | static void | ||
984 | netxen_nic_init_coalesce_defaults(struct netxen_adapter *adapter) | ||
985 | { | ||
986 | adapter->coal.flags = NETXEN_NIC_INTR_DEFAULT; | ||
987 | adapter->coal.normal.data.rx_time_us = | ||
988 | NETXEN_DEFAULT_INTR_COALESCE_RX_TIME_US; | ||
989 | adapter->coal.normal.data.rx_packets = | ||
990 | NETXEN_DEFAULT_INTR_COALESCE_RX_PACKETS; | ||
991 | adapter->coal.normal.data.tx_time_us = | ||
992 | NETXEN_DEFAULT_INTR_COALESCE_TX_TIME_US; | ||
993 | adapter->coal.normal.data.tx_packets = | ||
994 | NETXEN_DEFAULT_INTR_COALESCE_TX_PACKETS; | ||
995 | } | ||
996 | |||
997 | /* with rtnl_lock */ | ||
998 | static int | ||
999 | __netxen_nic_up(struct netxen_adapter *adapter, struct net_device *netdev) | ||
1000 | { | ||
1001 | int err; | ||
1002 | |||
1003 | if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC) | ||
1004 | return -EIO; | ||
1005 | |||
1006 | err = adapter->init_port(adapter, adapter->physical_port); | ||
1007 | if (err) { | ||
1008 | printk(KERN_ERR "%s: Failed to initialize port %d\n", | ||
1009 | netxen_nic_driver_name, adapter->portnum); | ||
1010 | return err; | ||
1011 | } | ||
1012 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) | ||
1013 | adapter->macaddr_set(adapter, adapter->mac_addr); | ||
1014 | |||
1015 | adapter->set_multi(netdev); | ||
1016 | adapter->set_mtu(adapter, netdev->mtu); | ||
1017 | |||
1018 | adapter->ahw.linkup = 0; | ||
1019 | |||
1020 | if (adapter->max_sds_rings > 1) | ||
1021 | netxen_config_rss(adapter, 1); | ||
1022 | |||
1023 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) | ||
1024 | netxen_config_intr_coalesce(adapter); | ||
1025 | |||
1026 | if (netdev->features & NETIF_F_LRO) | ||
1027 | netxen_config_hw_lro(adapter, NETXEN_NIC_LRO_ENABLED); | ||
1028 | |||
1029 | netxen_napi_enable(adapter); | ||
1030 | |||
1031 | if (adapter->capabilities & NX_FW_CAPABILITY_LINK_NOTIFICATION) | ||
1032 | netxen_linkevent_request(adapter, 1); | ||
1033 | else | ||
1034 | netxen_nic_set_link_parameters(adapter); | ||
1035 | |||
1036 | set_bit(__NX_DEV_UP, &adapter->state); | ||
1037 | return 0; | ||
1038 | } | ||
1039 | |||
1040 | /* Usage: During resume and firmware recovery module.*/ | ||
1041 | |||
1042 | static inline int | ||
1043 | netxen_nic_up(struct netxen_adapter *adapter, struct net_device *netdev) | ||
1044 | { | ||
1045 | int err = 0; | ||
1046 | |||
1047 | rtnl_lock(); | ||
1048 | if (netif_running(netdev)) | ||
1049 | err = __netxen_nic_up(adapter, netdev); | ||
1050 | rtnl_unlock(); | ||
1051 | |||
1052 | return err; | ||
1053 | } | ||
1054 | |||
1055 | /* with rtnl_lock */ | ||
1056 | static void | ||
1057 | __netxen_nic_down(struct netxen_adapter *adapter, struct net_device *netdev) | ||
1058 | { | ||
1059 | if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC) | ||
1060 | return; | ||
1061 | |||
1062 | if (!test_and_clear_bit(__NX_DEV_UP, &adapter->state)) | ||
1063 | return; | ||
1064 | |||
1065 | smp_mb(); | ||
1066 | spin_lock(&adapter->tx_clean_lock); | ||
1067 | netif_carrier_off(netdev); | ||
1068 | netif_tx_disable(netdev); | ||
1069 | |||
1070 | if (adapter->capabilities & NX_FW_CAPABILITY_LINK_NOTIFICATION) | ||
1071 | netxen_linkevent_request(adapter, 0); | ||
1072 | |||
1073 | if (adapter->stop_port) | ||
1074 | adapter->stop_port(adapter); | ||
1075 | |||
1076 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) | ||
1077 | netxen_p3_free_mac_list(adapter); | ||
1078 | |||
1079 | adapter->set_promisc(adapter, NETXEN_NIU_NON_PROMISC_MODE); | ||
1080 | |||
1081 | netxen_napi_disable(adapter); | ||
1082 | |||
1083 | netxen_release_tx_buffers(adapter); | ||
1084 | spin_unlock(&adapter->tx_clean_lock); | ||
1085 | } | ||
1086 | |||
1087 | /* Usage: During suspend and firmware recovery module */ | ||
1088 | |||
1089 | static inline void | ||
1090 | netxen_nic_down(struct netxen_adapter *adapter, struct net_device *netdev) | ||
1091 | { | ||
1092 | rtnl_lock(); | ||
1093 | if (netif_running(netdev)) | ||
1094 | __netxen_nic_down(adapter, netdev); | ||
1095 | rtnl_unlock(); | ||
1096 | |||
1097 | } | ||
1098 | |||
1099 | static int | ||
1100 | netxen_nic_attach(struct netxen_adapter *adapter) | ||
1101 | { | ||
1102 | struct net_device *netdev = adapter->netdev; | ||
1103 | struct pci_dev *pdev = adapter->pdev; | ||
1104 | int err, ring; | ||
1105 | struct nx_host_rds_ring *rds_ring; | ||
1106 | struct nx_host_tx_ring *tx_ring; | ||
1107 | |||
1108 | if (adapter->is_up == NETXEN_ADAPTER_UP_MAGIC) | ||
1109 | return 0; | ||
1110 | |||
1111 | err = netxen_init_firmware(adapter); | ||
1112 | if (err) | ||
1113 | return err; | ||
1114 | |||
1115 | err = netxen_napi_add(adapter, netdev); | ||
1116 | if (err) | ||
1117 | return err; | ||
1118 | |||
1119 | err = netxen_alloc_sw_resources(adapter); | ||
1120 | if (err) { | ||
1121 | printk(KERN_ERR "%s: Error in setting sw resources\n", | ||
1122 | netdev->name); | ||
1123 | return err; | ||
1124 | } | ||
1125 | |||
1126 | err = netxen_alloc_hw_resources(adapter); | ||
1127 | if (err) { | ||
1128 | printk(KERN_ERR "%s: Error in setting hw resources\n", | ||
1129 | netdev->name); | ||
1130 | goto err_out_free_sw; | ||
1131 | } | ||
1132 | |||
1133 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) { | ||
1134 | tx_ring = adapter->tx_ring; | ||
1135 | tx_ring->crb_cmd_producer = netxen_get_ioaddr(adapter, | ||
1136 | crb_cmd_producer[adapter->portnum]); | ||
1137 | tx_ring->crb_cmd_consumer = netxen_get_ioaddr(adapter, | ||
1138 | crb_cmd_consumer[adapter->portnum]); | ||
1139 | |||
1140 | tx_ring->producer = 0; | ||
1141 | tx_ring->sw_consumer = 0; | ||
1142 | |||
1143 | netxen_nic_update_cmd_producer(adapter, tx_ring); | ||
1144 | netxen_nic_update_cmd_consumer(adapter, tx_ring); | ||
1145 | } | ||
1146 | |||
1147 | for (ring = 0; ring < adapter->max_rds_rings; ring++) { | ||
1148 | rds_ring = &adapter->recv_ctx.rds_rings[ring]; | ||
1149 | netxen_post_rx_buffers(adapter, ring, rds_ring); | ||
1150 | } | ||
1151 | |||
1152 | err = netxen_nic_request_irq(adapter); | ||
1153 | if (err) { | ||
1154 | dev_err(&pdev->dev, "%s: failed to setup interrupt\n", | ||
1155 | netdev->name); | ||
1156 | goto err_out_free_rxbuf; | ||
1157 | } | ||
1158 | |||
1159 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) | ||
1160 | netxen_nic_init_coalesce_defaults(adapter); | ||
1161 | |||
1162 | netxen_create_sysfs_entries(adapter); | ||
1163 | |||
1164 | adapter->is_up = NETXEN_ADAPTER_UP_MAGIC; | ||
1165 | return 0; | ||
1166 | |||
1167 | err_out_free_rxbuf: | ||
1168 | netxen_release_rx_buffers(adapter); | ||
1169 | netxen_free_hw_resources(adapter); | ||
1170 | err_out_free_sw: | ||
1171 | netxen_free_sw_resources(adapter); | ||
1172 | return err; | ||
1173 | } | ||
1174 | |||
1175 | static void | ||
1176 | netxen_nic_detach(struct netxen_adapter *adapter) | ||
1177 | { | ||
1178 | if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC) | ||
1179 | return; | ||
1180 | |||
1181 | netxen_remove_sysfs_entries(adapter); | ||
1182 | |||
1183 | netxen_free_hw_resources(adapter); | ||
1184 | netxen_release_rx_buffers(adapter); | ||
1185 | netxen_nic_free_irq(adapter); | ||
1186 | netxen_napi_del(adapter); | ||
1187 | netxen_free_sw_resources(adapter); | ||
1188 | |||
1189 | adapter->is_up = 0; | ||
1190 | } | ||
1191 | |||
1192 | int | ||
1193 | netxen_nic_reset_context(struct netxen_adapter *adapter) | ||
1194 | { | ||
1195 | int err = 0; | ||
1196 | struct net_device *netdev = adapter->netdev; | ||
1197 | |||
1198 | if (test_and_set_bit(__NX_RESETTING, &adapter->state)) | ||
1199 | return -EBUSY; | ||
1200 | |||
1201 | if (adapter->is_up == NETXEN_ADAPTER_UP_MAGIC) { | ||
1202 | |||
1203 | netif_device_detach(netdev); | ||
1204 | |||
1205 | if (netif_running(netdev)) | ||
1206 | __netxen_nic_down(adapter, netdev); | ||
1207 | |||
1208 | netxen_nic_detach(adapter); | ||
1209 | |||
1210 | if (netif_running(netdev)) { | ||
1211 | err = netxen_nic_attach(adapter); | ||
1212 | if (!err) | ||
1213 | err = __netxen_nic_up(adapter, netdev); | ||
1214 | |||
1215 | if (err) | ||
1216 | goto done; | ||
1217 | } | ||
1218 | |||
1219 | netif_device_attach(netdev); | ||
1220 | } | ||
1221 | |||
1222 | done: | ||
1223 | clear_bit(__NX_RESETTING, &adapter->state); | ||
1224 | return err; | ||
1225 | } | ||
1226 | |||
1227 | static int | ||
1228 | netxen_setup_netdev(struct netxen_adapter *adapter, | ||
1229 | struct net_device *netdev) | ||
1230 | { | ||
1231 | int err = 0; | ||
1232 | struct pci_dev *pdev = adapter->pdev; | ||
1233 | |||
1234 | adapter->mc_enabled = 0; | ||
1235 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) | ||
1236 | adapter->max_mc_count = 38; | ||
1237 | else | ||
1238 | adapter->max_mc_count = 16; | ||
1239 | |||
1240 | netdev->netdev_ops = &netxen_netdev_ops; | ||
1241 | netdev->watchdog_timeo = 5*HZ; | ||
1242 | |||
1243 | netxen_nic_change_mtu(netdev, netdev->mtu); | ||
1244 | |||
1245 | SET_ETHTOOL_OPS(netdev, &netxen_nic_ethtool_ops); | ||
1246 | |||
1247 | netdev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO | | ||
1248 | NETIF_F_RXCSUM; | ||
1249 | |||
1250 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) | ||
1251 | netdev->hw_features |= NETIF_F_IPV6_CSUM | NETIF_F_TSO6; | ||
1252 | |||
1253 | netdev->vlan_features |= netdev->hw_features; | ||
1254 | |||
1255 | if (adapter->pci_using_dac) { | ||
1256 | netdev->features |= NETIF_F_HIGHDMA; | ||
1257 | netdev->vlan_features |= NETIF_F_HIGHDMA; | ||
1258 | } | ||
1259 | |||
1260 | if (adapter->capabilities & NX_FW_CAPABILITY_FVLANTX) | ||
1261 | netdev->hw_features |= NETIF_F_HW_VLAN_TX; | ||
1262 | |||
1263 | if (adapter->capabilities & NX_FW_CAPABILITY_HW_LRO) | ||
1264 | netdev->hw_features |= NETIF_F_LRO; | ||
1265 | |||
1266 | netdev->features |= netdev->hw_features; | ||
1267 | |||
1268 | netdev->irq = adapter->msix_entries[0].vector; | ||
1269 | |||
1270 | INIT_WORK(&adapter->tx_timeout_task, netxen_tx_timeout_task); | ||
1271 | |||
1272 | if (netxen_read_mac_addr(adapter)) | ||
1273 | dev_warn(&pdev->dev, "failed to read mac addr\n"); | ||
1274 | |||
1275 | netif_carrier_off(netdev); | ||
1276 | |||
1277 | err = register_netdev(netdev); | ||
1278 | if (err) { | ||
1279 | dev_err(&pdev->dev, "failed to register net device\n"); | ||
1280 | return err; | ||
1281 | } | ||
1282 | |||
1283 | return 0; | ||
1284 | } | ||
1285 | |||
1286 | #ifdef CONFIG_PCIEAER | ||
1287 | static void netxen_mask_aer_correctable(struct netxen_adapter *adapter) | ||
1288 | { | ||
1289 | struct pci_dev *pdev = adapter->pdev; | ||
1290 | struct pci_dev *root = pdev->bus->self; | ||
1291 | u32 aer_pos; | ||
1292 | |||
1293 | if (adapter->ahw.board_type != NETXEN_BRDTYPE_P3_4_GB_MM && | ||
1294 | adapter->ahw.board_type != NETXEN_BRDTYPE_P3_10G_TP) | ||
1295 | return; | ||
1296 | |||
1297 | if (root->pcie_type != PCI_EXP_TYPE_ROOT_PORT) | ||
1298 | return; | ||
1299 | |||
1300 | aer_pos = pci_find_ext_capability(root, PCI_EXT_CAP_ID_ERR); | ||
1301 | if (!aer_pos) | ||
1302 | return; | ||
1303 | |||
1304 | pci_write_config_dword(root, aer_pos + PCI_ERR_COR_MASK, 0xffff); | ||
1305 | } | ||
1306 | #endif | ||
1307 | |||
1308 | static int __devinit | ||
1309 | netxen_nic_probe(struct pci_dev *pdev, const struct pci_device_id *ent) | ||
1310 | { | ||
1311 | struct net_device *netdev = NULL; | ||
1312 | struct netxen_adapter *adapter = NULL; | ||
1313 | int i = 0, err; | ||
1314 | int pci_func_id = PCI_FUNC(pdev->devfn); | ||
1315 | uint8_t revision_id; | ||
1316 | u32 val; | ||
1317 | |||
1318 | if (pdev->revision >= NX_P3_A0 && pdev->revision <= NX_P3_B1) { | ||
1319 | pr_warning("%s: chip revisions between 0x%x-0x%x " | ||
1320 | "will not be enabled.\n", | ||
1321 | module_name(THIS_MODULE), NX_P3_A0, NX_P3_B1); | ||
1322 | return -ENODEV; | ||
1323 | } | ||
1324 | |||
1325 | if ((err = pci_enable_device(pdev))) | ||
1326 | return err; | ||
1327 | |||
1328 | if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) { | ||
1329 | err = -ENODEV; | ||
1330 | goto err_out_disable_pdev; | ||
1331 | } | ||
1332 | |||
1333 | if ((err = pci_request_regions(pdev, netxen_nic_driver_name))) | ||
1334 | goto err_out_disable_pdev; | ||
1335 | |||
1336 | if (NX_IS_REVISION_P3(pdev->revision)) | ||
1337 | pci_enable_pcie_error_reporting(pdev); | ||
1338 | |||
1339 | pci_set_master(pdev); | ||
1340 | |||
1341 | netdev = alloc_etherdev(sizeof(struct netxen_adapter)); | ||
1342 | if(!netdev) { | ||
1343 | dev_err(&pdev->dev, "failed to allocate net_device\n"); | ||
1344 | err = -ENOMEM; | ||
1345 | goto err_out_free_res; | ||
1346 | } | ||
1347 | |||
1348 | SET_NETDEV_DEV(netdev, &pdev->dev); | ||
1349 | |||
1350 | adapter = netdev_priv(netdev); | ||
1351 | adapter->netdev = netdev; | ||
1352 | adapter->pdev = pdev; | ||
1353 | adapter->ahw.pci_func = pci_func_id; | ||
1354 | |||
1355 | revision_id = pdev->revision; | ||
1356 | adapter->ahw.revision_id = revision_id; | ||
1357 | |||
1358 | rwlock_init(&adapter->ahw.crb_lock); | ||
1359 | spin_lock_init(&adapter->ahw.mem_lock); | ||
1360 | |||
1361 | spin_lock_init(&adapter->tx_clean_lock); | ||
1362 | INIT_LIST_HEAD(&adapter->mac_list); | ||
1363 | INIT_LIST_HEAD(&adapter->vlan_ip_list); | ||
1364 | |||
1365 | err = netxen_setup_pci_map(adapter); | ||
1366 | if (err) | ||
1367 | goto err_out_free_netdev; | ||
1368 | |||
1369 | /* This will be reset for mezz cards */ | ||
1370 | adapter->portnum = pci_func_id; | ||
1371 | |||
1372 | err = netxen_nic_get_board_info(adapter); | ||
1373 | if (err) { | ||
1374 | dev_err(&pdev->dev, "Error getting board config info.\n"); | ||
1375 | goto err_out_iounmap; | ||
1376 | } | ||
1377 | |||
1378 | #ifdef CONFIG_PCIEAER | ||
1379 | netxen_mask_aer_correctable(adapter); | ||
1380 | #endif | ||
1381 | |||
1382 | /* Mezz cards have PCI function 0,2,3 enabled */ | ||
1383 | switch (adapter->ahw.board_type) { | ||
1384 | case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ: | ||
1385 | case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ: | ||
1386 | if (pci_func_id >= 2) | ||
1387 | adapter->portnum = pci_func_id - 2; | ||
1388 | break; | ||
1389 | default: | ||
1390 | break; | ||
1391 | } | ||
1392 | |||
1393 | err = netxen_check_flash_fw_compatibility(adapter); | ||
1394 | if (err) | ||
1395 | goto err_out_iounmap; | ||
1396 | |||
1397 | if (adapter->portnum == 0) { | ||
1398 | val = NXRD32(adapter, NX_CRB_DEV_REF_COUNT); | ||
1399 | if (val != 0xffffffff && val != 0) { | ||
1400 | NXWR32(adapter, NX_CRB_DEV_REF_COUNT, 0); | ||
1401 | adapter->need_fw_reset = 1; | ||
1402 | } | ||
1403 | } | ||
1404 | |||
1405 | err = netxen_start_firmware(adapter); | ||
1406 | if (err) | ||
1407 | goto err_out_decr_ref; | ||
1408 | |||
1409 | /* | ||
1410 | * See if the firmware gave us a virtual-physical port mapping. | ||
1411 | */ | ||
1412 | adapter->physical_port = adapter->portnum; | ||
1413 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) { | ||
1414 | i = NXRD32(adapter, CRB_V2P(adapter->portnum)); | ||
1415 | if (i != 0x55555555) | ||
1416 | adapter->physical_port = i; | ||
1417 | } | ||
1418 | |||
1419 | netxen_nic_clear_stats(adapter); | ||
1420 | |||
1421 | netxen_setup_intr(adapter); | ||
1422 | |||
1423 | err = netxen_setup_netdev(adapter, netdev); | ||
1424 | if (err) | ||
1425 | goto err_out_disable_msi; | ||
1426 | |||
1427 | pci_set_drvdata(pdev, adapter); | ||
1428 | |||
1429 | netxen_schedule_work(adapter, netxen_fw_poll_work, FW_POLL_DELAY); | ||
1430 | |||
1431 | switch (adapter->ahw.port_type) { | ||
1432 | case NETXEN_NIC_GBE: | ||
1433 | dev_info(&adapter->pdev->dev, "%s: GbE port initialized\n", | ||
1434 | adapter->netdev->name); | ||
1435 | break; | ||
1436 | case NETXEN_NIC_XGBE: | ||
1437 | dev_info(&adapter->pdev->dev, "%s: XGbE port initialized\n", | ||
1438 | adapter->netdev->name); | ||
1439 | break; | ||
1440 | } | ||
1441 | |||
1442 | netxen_create_diag_entries(adapter); | ||
1443 | |||
1444 | return 0; | ||
1445 | |||
1446 | err_out_disable_msi: | ||
1447 | netxen_teardown_intr(adapter); | ||
1448 | |||
1449 | netxen_free_dummy_dma(adapter); | ||
1450 | |||
1451 | err_out_decr_ref: | ||
1452 | nx_decr_dev_ref_cnt(adapter); | ||
1453 | |||
1454 | err_out_iounmap: | ||
1455 | netxen_cleanup_pci_map(adapter); | ||
1456 | |||
1457 | err_out_free_netdev: | ||
1458 | free_netdev(netdev); | ||
1459 | |||
1460 | err_out_free_res: | ||
1461 | pci_release_regions(pdev); | ||
1462 | |||
1463 | err_out_disable_pdev: | ||
1464 | pci_set_drvdata(pdev, NULL); | ||
1465 | pci_disable_device(pdev); | ||
1466 | return err; | ||
1467 | } | ||
1468 | |||
1469 | static void __devexit netxen_nic_remove(struct pci_dev *pdev) | ||
1470 | { | ||
1471 | struct netxen_adapter *adapter; | ||
1472 | struct net_device *netdev; | ||
1473 | |||
1474 | adapter = pci_get_drvdata(pdev); | ||
1475 | if (adapter == NULL) | ||
1476 | return; | ||
1477 | |||
1478 | netdev = adapter->netdev; | ||
1479 | |||
1480 | netxen_cancel_fw_work(adapter); | ||
1481 | |||
1482 | unregister_netdev(netdev); | ||
1483 | |||
1484 | cancel_work_sync(&adapter->tx_timeout_task); | ||
1485 | |||
1486 | netxen_free_vlan_ip_list(adapter); | ||
1487 | netxen_nic_detach(adapter); | ||
1488 | |||
1489 | nx_decr_dev_ref_cnt(adapter); | ||
1490 | |||
1491 | if (adapter->portnum == 0) | ||
1492 | netxen_free_dummy_dma(adapter); | ||
1493 | |||
1494 | clear_bit(__NX_RESETTING, &adapter->state); | ||
1495 | |||
1496 | netxen_teardown_intr(adapter); | ||
1497 | |||
1498 | netxen_remove_diag_entries(adapter); | ||
1499 | |||
1500 | netxen_cleanup_pci_map(adapter); | ||
1501 | |||
1502 | netxen_release_firmware(adapter); | ||
1503 | |||
1504 | if (NX_IS_REVISION_P3(pdev->revision)) | ||
1505 | pci_disable_pcie_error_reporting(pdev); | ||
1506 | |||
1507 | pci_release_regions(pdev); | ||
1508 | pci_disable_device(pdev); | ||
1509 | pci_set_drvdata(pdev, NULL); | ||
1510 | |||
1511 | free_netdev(netdev); | ||
1512 | } | ||
1513 | |||
1514 | static void netxen_nic_detach_func(struct netxen_adapter *adapter) | ||
1515 | { | ||
1516 | struct net_device *netdev = adapter->netdev; | ||
1517 | |||
1518 | netif_device_detach(netdev); | ||
1519 | |||
1520 | netxen_cancel_fw_work(adapter); | ||
1521 | |||
1522 | if (netif_running(netdev)) | ||
1523 | netxen_nic_down(adapter, netdev); | ||
1524 | |||
1525 | cancel_work_sync(&adapter->tx_timeout_task); | ||
1526 | |||
1527 | netxen_nic_detach(adapter); | ||
1528 | |||
1529 | if (adapter->portnum == 0) | ||
1530 | netxen_free_dummy_dma(adapter); | ||
1531 | |||
1532 | nx_decr_dev_ref_cnt(adapter); | ||
1533 | |||
1534 | clear_bit(__NX_RESETTING, &adapter->state); | ||
1535 | } | ||
1536 | |||
1537 | static int netxen_nic_attach_func(struct pci_dev *pdev) | ||
1538 | { | ||
1539 | struct netxen_adapter *adapter = pci_get_drvdata(pdev); | ||
1540 | struct net_device *netdev = adapter->netdev; | ||
1541 | int err; | ||
1542 | |||
1543 | err = pci_enable_device(pdev); | ||
1544 | if (err) | ||
1545 | return err; | ||
1546 | |||
1547 | pci_set_power_state(pdev, PCI_D0); | ||
1548 | pci_set_master(pdev); | ||
1549 | pci_restore_state(pdev); | ||
1550 | |||
1551 | adapter->ahw.crb_win = -1; | ||
1552 | adapter->ahw.ocm_win = -1; | ||
1553 | |||
1554 | err = netxen_start_firmware(adapter); | ||
1555 | if (err) { | ||
1556 | dev_err(&pdev->dev, "failed to start firmware\n"); | ||
1557 | return err; | ||
1558 | } | ||
1559 | |||
1560 | if (netif_running(netdev)) { | ||
1561 | err = netxen_nic_attach(adapter); | ||
1562 | if (err) | ||
1563 | goto err_out; | ||
1564 | |||
1565 | err = netxen_nic_up(adapter, netdev); | ||
1566 | if (err) | ||
1567 | goto err_out_detach; | ||
1568 | |||
1569 | netxen_restore_indev_addr(netdev, NETDEV_UP); | ||
1570 | } | ||
1571 | |||
1572 | netif_device_attach(netdev); | ||
1573 | netxen_schedule_work(adapter, netxen_fw_poll_work, FW_POLL_DELAY); | ||
1574 | return 0; | ||
1575 | |||
1576 | err_out_detach: | ||
1577 | netxen_nic_detach(adapter); | ||
1578 | err_out: | ||
1579 | nx_decr_dev_ref_cnt(adapter); | ||
1580 | return err; | ||
1581 | } | ||
1582 | |||
1583 | static pci_ers_result_t netxen_io_error_detected(struct pci_dev *pdev, | ||
1584 | pci_channel_state_t state) | ||
1585 | { | ||
1586 | struct netxen_adapter *adapter = pci_get_drvdata(pdev); | ||
1587 | |||
1588 | if (state == pci_channel_io_perm_failure) | ||
1589 | return PCI_ERS_RESULT_DISCONNECT; | ||
1590 | |||
1591 | if (nx_dev_request_aer(adapter)) | ||
1592 | return PCI_ERS_RESULT_RECOVERED; | ||
1593 | |||
1594 | netxen_nic_detach_func(adapter); | ||
1595 | |||
1596 | pci_disable_device(pdev); | ||
1597 | |||
1598 | return PCI_ERS_RESULT_NEED_RESET; | ||
1599 | } | ||
1600 | |||
1601 | static pci_ers_result_t netxen_io_slot_reset(struct pci_dev *pdev) | ||
1602 | { | ||
1603 | int err = 0; | ||
1604 | |||
1605 | err = netxen_nic_attach_func(pdev); | ||
1606 | |||
1607 | return err ? PCI_ERS_RESULT_DISCONNECT : PCI_ERS_RESULT_RECOVERED; | ||
1608 | } | ||
1609 | |||
1610 | static void netxen_io_resume(struct pci_dev *pdev) | ||
1611 | { | ||
1612 | pci_cleanup_aer_uncorrect_error_status(pdev); | ||
1613 | } | ||
1614 | |||
1615 | static void netxen_nic_shutdown(struct pci_dev *pdev) | ||
1616 | { | ||
1617 | struct netxen_adapter *adapter = pci_get_drvdata(pdev); | ||
1618 | |||
1619 | netxen_nic_detach_func(adapter); | ||
1620 | |||
1621 | if (pci_save_state(pdev)) | ||
1622 | return; | ||
1623 | |||
1624 | if (netxen_nic_wol_supported(adapter)) { | ||
1625 | pci_enable_wake(pdev, PCI_D3cold, 1); | ||
1626 | pci_enable_wake(pdev, PCI_D3hot, 1); | ||
1627 | } | ||
1628 | |||
1629 | pci_disable_device(pdev); | ||
1630 | } | ||
1631 | |||
1632 | #ifdef CONFIG_PM | ||
1633 | static int | ||
1634 | netxen_nic_suspend(struct pci_dev *pdev, pm_message_t state) | ||
1635 | { | ||
1636 | struct netxen_adapter *adapter = pci_get_drvdata(pdev); | ||
1637 | int retval; | ||
1638 | |||
1639 | netxen_nic_detach_func(adapter); | ||
1640 | |||
1641 | retval = pci_save_state(pdev); | ||
1642 | if (retval) | ||
1643 | return retval; | ||
1644 | |||
1645 | if (netxen_nic_wol_supported(adapter)) { | ||
1646 | pci_enable_wake(pdev, PCI_D3cold, 1); | ||
1647 | pci_enable_wake(pdev, PCI_D3hot, 1); | ||
1648 | } | ||
1649 | |||
1650 | pci_disable_device(pdev); | ||
1651 | pci_set_power_state(pdev, pci_choose_state(pdev, state)); | ||
1652 | |||
1653 | return 0; | ||
1654 | } | ||
1655 | |||
1656 | static int | ||
1657 | netxen_nic_resume(struct pci_dev *pdev) | ||
1658 | { | ||
1659 | return netxen_nic_attach_func(pdev); | ||
1660 | } | ||
1661 | #endif | ||
1662 | |||
1663 | static int netxen_nic_open(struct net_device *netdev) | ||
1664 | { | ||
1665 | struct netxen_adapter *adapter = netdev_priv(netdev); | ||
1666 | int err = 0; | ||
1667 | |||
1668 | if (adapter->driver_mismatch) | ||
1669 | return -EIO; | ||
1670 | |||
1671 | err = netxen_nic_attach(adapter); | ||
1672 | if (err) | ||
1673 | return err; | ||
1674 | |||
1675 | err = __netxen_nic_up(adapter, netdev); | ||
1676 | if (err) | ||
1677 | goto err_out; | ||
1678 | |||
1679 | netif_start_queue(netdev); | ||
1680 | |||
1681 | return 0; | ||
1682 | |||
1683 | err_out: | ||
1684 | netxen_nic_detach(adapter); | ||
1685 | return err; | ||
1686 | } | ||
1687 | |||
1688 | /* | ||
1689 | * netxen_nic_close - Disables a network interface entry point | ||
1690 | */ | ||
1691 | static int netxen_nic_close(struct net_device *netdev) | ||
1692 | { | ||
1693 | struct netxen_adapter *adapter = netdev_priv(netdev); | ||
1694 | |||
1695 | __netxen_nic_down(adapter, netdev); | ||
1696 | return 0; | ||
1697 | } | ||
1698 | |||
1699 | static void | ||
1700 | netxen_tso_check(struct net_device *netdev, | ||
1701 | struct nx_host_tx_ring *tx_ring, | ||
1702 | struct cmd_desc_type0 *first_desc, | ||
1703 | struct sk_buff *skb) | ||
1704 | { | ||
1705 | u8 opcode = TX_ETHER_PKT; | ||
1706 | __be16 protocol = skb->protocol; | ||
1707 | u16 flags = 0, vid = 0; | ||
1708 | u32 producer; | ||
1709 | int copied, offset, copy_len, hdr_len = 0, tso = 0, vlan_oob = 0; | ||
1710 | struct cmd_desc_type0 *hwdesc; | ||
1711 | struct vlan_ethhdr *vh; | ||
1712 | |||
1713 | if (protocol == cpu_to_be16(ETH_P_8021Q)) { | ||
1714 | |||
1715 | vh = (struct vlan_ethhdr *)skb->data; | ||
1716 | protocol = vh->h_vlan_encapsulated_proto; | ||
1717 | flags = FLAGS_VLAN_TAGGED; | ||
1718 | |||
1719 | } else if (vlan_tx_tag_present(skb)) { | ||
1720 | |||
1721 | flags = FLAGS_VLAN_OOB; | ||
1722 | vid = vlan_tx_tag_get(skb); | ||
1723 | netxen_set_tx_vlan_tci(first_desc, vid); | ||
1724 | vlan_oob = 1; | ||
1725 | } | ||
1726 | |||
1727 | if ((netdev->features & (NETIF_F_TSO | NETIF_F_TSO6)) && | ||
1728 | skb_shinfo(skb)->gso_size > 0) { | ||
1729 | |||
1730 | hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb); | ||
1731 | |||
1732 | first_desc->mss = cpu_to_le16(skb_shinfo(skb)->gso_size); | ||
1733 | first_desc->total_hdr_length = hdr_len; | ||
1734 | if (vlan_oob) { | ||
1735 | first_desc->total_hdr_length += VLAN_HLEN; | ||
1736 | first_desc->tcp_hdr_offset = VLAN_HLEN; | ||
1737 | first_desc->ip_hdr_offset = VLAN_HLEN; | ||
1738 | /* Only in case of TSO on vlan device */ | ||
1739 | flags |= FLAGS_VLAN_TAGGED; | ||
1740 | } | ||
1741 | |||
1742 | opcode = (protocol == cpu_to_be16(ETH_P_IPV6)) ? | ||
1743 | TX_TCP_LSO6 : TX_TCP_LSO; | ||
1744 | tso = 1; | ||
1745 | |||
1746 | } else if (skb->ip_summed == CHECKSUM_PARTIAL) { | ||
1747 | u8 l4proto; | ||
1748 | |||
1749 | if (protocol == cpu_to_be16(ETH_P_IP)) { | ||
1750 | l4proto = ip_hdr(skb)->protocol; | ||
1751 | |||
1752 | if (l4proto == IPPROTO_TCP) | ||
1753 | opcode = TX_TCP_PKT; | ||
1754 | else if(l4proto == IPPROTO_UDP) | ||
1755 | opcode = TX_UDP_PKT; | ||
1756 | } else if (protocol == cpu_to_be16(ETH_P_IPV6)) { | ||
1757 | l4proto = ipv6_hdr(skb)->nexthdr; | ||
1758 | |||
1759 | if (l4proto == IPPROTO_TCP) | ||
1760 | opcode = TX_TCPV6_PKT; | ||
1761 | else if(l4proto == IPPROTO_UDP) | ||
1762 | opcode = TX_UDPV6_PKT; | ||
1763 | } | ||
1764 | } | ||
1765 | |||
1766 | first_desc->tcp_hdr_offset += skb_transport_offset(skb); | ||
1767 | first_desc->ip_hdr_offset += skb_network_offset(skb); | ||
1768 | netxen_set_tx_flags_opcode(first_desc, flags, opcode); | ||
1769 | |||
1770 | if (!tso) | ||
1771 | return; | ||
1772 | |||
1773 | /* For LSO, we need to copy the MAC/IP/TCP headers into | ||
1774 | * the descriptor ring | ||
1775 | */ | ||
1776 | producer = tx_ring->producer; | ||
1777 | copied = 0; | ||
1778 | offset = 2; | ||
1779 | |||
1780 | if (vlan_oob) { | ||
1781 | /* Create a TSO vlan header template for firmware */ | ||
1782 | |||
1783 | hwdesc = &tx_ring->desc_head[producer]; | ||
1784 | tx_ring->cmd_buf_arr[producer].skb = NULL; | ||
1785 | |||
1786 | copy_len = min((int)sizeof(struct cmd_desc_type0) - offset, | ||
1787 | hdr_len + VLAN_HLEN); | ||
1788 | |||
1789 | vh = (struct vlan_ethhdr *)((char *)hwdesc + 2); | ||
1790 | skb_copy_from_linear_data(skb, vh, 12); | ||
1791 | vh->h_vlan_proto = htons(ETH_P_8021Q); | ||
1792 | vh->h_vlan_TCI = htons(vid); | ||
1793 | skb_copy_from_linear_data_offset(skb, 12, | ||
1794 | (char *)vh + 16, copy_len - 16); | ||
1795 | |||
1796 | copied = copy_len - VLAN_HLEN; | ||
1797 | offset = 0; | ||
1798 | |||
1799 | producer = get_next_index(producer, tx_ring->num_desc); | ||
1800 | } | ||
1801 | |||
1802 | while (copied < hdr_len) { | ||
1803 | |||
1804 | copy_len = min((int)sizeof(struct cmd_desc_type0) - offset, | ||
1805 | (hdr_len - copied)); | ||
1806 | |||
1807 | hwdesc = &tx_ring->desc_head[producer]; | ||
1808 | tx_ring->cmd_buf_arr[producer].skb = NULL; | ||
1809 | |||
1810 | skb_copy_from_linear_data_offset(skb, copied, | ||
1811 | (char *)hwdesc + offset, copy_len); | ||
1812 | |||
1813 | copied += copy_len; | ||
1814 | offset = 0; | ||
1815 | |||
1816 | producer = get_next_index(producer, tx_ring->num_desc); | ||
1817 | } | ||
1818 | |||
1819 | tx_ring->producer = producer; | ||
1820 | barrier(); | ||
1821 | } | ||
1822 | |||
1823 | static int | ||
1824 | netxen_map_tx_skb(struct pci_dev *pdev, | ||
1825 | struct sk_buff *skb, struct netxen_cmd_buffer *pbuf) | ||
1826 | { | ||
1827 | struct netxen_skb_frag *nf; | ||
1828 | struct skb_frag_struct *frag; | ||
1829 | int i, nr_frags; | ||
1830 | dma_addr_t map; | ||
1831 | |||
1832 | nr_frags = skb_shinfo(skb)->nr_frags; | ||
1833 | nf = &pbuf->frag_array[0]; | ||
1834 | |||
1835 | map = pci_map_single(pdev, skb->data, | ||
1836 | skb_headlen(skb), PCI_DMA_TODEVICE); | ||
1837 | if (pci_dma_mapping_error(pdev, map)) | ||
1838 | goto out_err; | ||
1839 | |||
1840 | nf->dma = map; | ||
1841 | nf->length = skb_headlen(skb); | ||
1842 | |||
1843 | for (i = 0; i < nr_frags; i++) { | ||
1844 | frag = &skb_shinfo(skb)->frags[i]; | ||
1845 | nf = &pbuf->frag_array[i+1]; | ||
1846 | |||
1847 | map = pci_map_page(pdev, frag->page, frag->page_offset, | ||
1848 | frag->size, PCI_DMA_TODEVICE); | ||
1849 | if (pci_dma_mapping_error(pdev, map)) | ||
1850 | goto unwind; | ||
1851 | |||
1852 | nf->dma = map; | ||
1853 | nf->length = frag->size; | ||
1854 | } | ||
1855 | |||
1856 | return 0; | ||
1857 | |||
1858 | unwind: | ||
1859 | while (--i >= 0) { | ||
1860 | nf = &pbuf->frag_array[i+1]; | ||
1861 | pci_unmap_page(pdev, nf->dma, nf->length, PCI_DMA_TODEVICE); | ||
1862 | } | ||
1863 | |||
1864 | nf = &pbuf->frag_array[0]; | ||
1865 | pci_unmap_single(pdev, nf->dma, skb_headlen(skb), PCI_DMA_TODEVICE); | ||
1866 | |||
1867 | out_err: | ||
1868 | return -ENOMEM; | ||
1869 | } | ||
1870 | |||
1871 | static inline void | ||
1872 | netxen_clear_cmddesc(u64 *desc) | ||
1873 | { | ||
1874 | desc[0] = 0ULL; | ||
1875 | desc[2] = 0ULL; | ||
1876 | } | ||
1877 | |||
1878 | static netdev_tx_t | ||
1879 | netxen_nic_xmit_frame(struct sk_buff *skb, struct net_device *netdev) | ||
1880 | { | ||
1881 | struct netxen_adapter *adapter = netdev_priv(netdev); | ||
1882 | struct nx_host_tx_ring *tx_ring = adapter->tx_ring; | ||
1883 | struct netxen_cmd_buffer *pbuf; | ||
1884 | struct netxen_skb_frag *buffrag; | ||
1885 | struct cmd_desc_type0 *hwdesc, *first_desc; | ||
1886 | struct pci_dev *pdev; | ||
1887 | int i, k; | ||
1888 | int delta = 0; | ||
1889 | struct skb_frag_struct *frag; | ||
1890 | |||
1891 | u32 producer; | ||
1892 | int frag_count, no_of_desc; | ||
1893 | u32 num_txd = tx_ring->num_desc; | ||
1894 | |||
1895 | frag_count = skb_shinfo(skb)->nr_frags + 1; | ||
1896 | |||
1897 | /* 14 frags supported for normal packet and | ||
1898 | * 32 frags supported for TSO packet | ||
1899 | */ | ||
1900 | if (!skb_is_gso(skb) && frag_count > NETXEN_MAX_FRAGS_PER_TX) { | ||
1901 | |||
1902 | for (i = 0; i < (frag_count - NETXEN_MAX_FRAGS_PER_TX); i++) { | ||
1903 | frag = &skb_shinfo(skb)->frags[i]; | ||
1904 | delta += frag->size; | ||
1905 | } | ||
1906 | |||
1907 | if (!__pskb_pull_tail(skb, delta)) | ||
1908 | goto drop_packet; | ||
1909 | |||
1910 | frag_count = 1 + skb_shinfo(skb)->nr_frags; | ||
1911 | } | ||
1912 | /* 4 fragments per cmd des */ | ||
1913 | no_of_desc = (frag_count + 3) >> 2; | ||
1914 | |||
1915 | if (unlikely(netxen_tx_avail(tx_ring) <= TX_STOP_THRESH)) { | ||
1916 | netif_stop_queue(netdev); | ||
1917 | smp_mb(); | ||
1918 | if (netxen_tx_avail(tx_ring) > TX_STOP_THRESH) | ||
1919 | netif_start_queue(netdev); | ||
1920 | else | ||
1921 | return NETDEV_TX_BUSY; | ||
1922 | } | ||
1923 | |||
1924 | producer = tx_ring->producer; | ||
1925 | pbuf = &tx_ring->cmd_buf_arr[producer]; | ||
1926 | |||
1927 | pdev = adapter->pdev; | ||
1928 | |||
1929 | if (netxen_map_tx_skb(pdev, skb, pbuf)) | ||
1930 | goto drop_packet; | ||
1931 | |||
1932 | pbuf->skb = skb; | ||
1933 | pbuf->frag_count = frag_count; | ||
1934 | |||
1935 | first_desc = hwdesc = &tx_ring->desc_head[producer]; | ||
1936 | netxen_clear_cmddesc((u64 *)hwdesc); | ||
1937 | |||
1938 | netxen_set_tx_frags_len(first_desc, frag_count, skb->len); | ||
1939 | netxen_set_tx_port(first_desc, adapter->portnum); | ||
1940 | |||
1941 | for (i = 0; i < frag_count; i++) { | ||
1942 | |||
1943 | k = i % 4; | ||
1944 | |||
1945 | if ((k == 0) && (i > 0)) { | ||
1946 | /* move to next desc.*/ | ||
1947 | producer = get_next_index(producer, num_txd); | ||
1948 | hwdesc = &tx_ring->desc_head[producer]; | ||
1949 | netxen_clear_cmddesc((u64 *)hwdesc); | ||
1950 | tx_ring->cmd_buf_arr[producer].skb = NULL; | ||
1951 | } | ||
1952 | |||
1953 | buffrag = &pbuf->frag_array[i]; | ||
1954 | |||
1955 | hwdesc->buffer_length[k] = cpu_to_le16(buffrag->length); | ||
1956 | switch (k) { | ||
1957 | case 0: | ||
1958 | hwdesc->addr_buffer1 = cpu_to_le64(buffrag->dma); | ||
1959 | break; | ||
1960 | case 1: | ||
1961 | hwdesc->addr_buffer2 = cpu_to_le64(buffrag->dma); | ||
1962 | break; | ||
1963 | case 2: | ||
1964 | hwdesc->addr_buffer3 = cpu_to_le64(buffrag->dma); | ||
1965 | break; | ||
1966 | case 3: | ||
1967 | hwdesc->addr_buffer4 = cpu_to_le64(buffrag->dma); | ||
1968 | break; | ||
1969 | } | ||
1970 | } | ||
1971 | |||
1972 | tx_ring->producer = get_next_index(producer, num_txd); | ||
1973 | |||
1974 | netxen_tso_check(netdev, tx_ring, first_desc, skb); | ||
1975 | |||
1976 | adapter->stats.txbytes += skb->len; | ||
1977 | adapter->stats.xmitcalled++; | ||
1978 | |||
1979 | netxen_nic_update_cmd_producer(adapter, tx_ring); | ||
1980 | |||
1981 | return NETDEV_TX_OK; | ||
1982 | |||
1983 | drop_packet: | ||
1984 | adapter->stats.txdropped++; | ||
1985 | dev_kfree_skb_any(skb); | ||
1986 | return NETDEV_TX_OK; | ||
1987 | } | ||
1988 | |||
1989 | static int netxen_nic_check_temp(struct netxen_adapter *adapter) | ||
1990 | { | ||
1991 | struct net_device *netdev = adapter->netdev; | ||
1992 | uint32_t temp, temp_state, temp_val; | ||
1993 | int rv = 0; | ||
1994 | |||
1995 | temp = NXRD32(adapter, CRB_TEMP_STATE); | ||
1996 | |||
1997 | temp_state = nx_get_temp_state(temp); | ||
1998 | temp_val = nx_get_temp_val(temp); | ||
1999 | |||
2000 | if (temp_state == NX_TEMP_PANIC) { | ||
2001 | printk(KERN_ALERT | ||
2002 | "%s: Device temperature %d degrees C exceeds" | ||
2003 | " maximum allowed. Hardware has been shut down.\n", | ||
2004 | netdev->name, temp_val); | ||
2005 | rv = 1; | ||
2006 | } else if (temp_state == NX_TEMP_WARN) { | ||
2007 | if (adapter->temp == NX_TEMP_NORMAL) { | ||
2008 | printk(KERN_ALERT | ||
2009 | "%s: Device temperature %d degrees C " | ||
2010 | "exceeds operating range." | ||
2011 | " Immediate action needed.\n", | ||
2012 | netdev->name, temp_val); | ||
2013 | } | ||
2014 | } else { | ||
2015 | if (adapter->temp == NX_TEMP_WARN) { | ||
2016 | printk(KERN_INFO | ||
2017 | "%s: Device temperature is now %d degrees C" | ||
2018 | " in normal range.\n", netdev->name, | ||
2019 | temp_val); | ||
2020 | } | ||
2021 | } | ||
2022 | adapter->temp = temp_state; | ||
2023 | return rv; | ||
2024 | } | ||
2025 | |||
2026 | void netxen_advert_link_change(struct netxen_adapter *adapter, int linkup) | ||
2027 | { | ||
2028 | struct net_device *netdev = adapter->netdev; | ||
2029 | |||
2030 | if (adapter->ahw.linkup && !linkup) { | ||
2031 | printk(KERN_INFO "%s: %s NIC Link is down\n", | ||
2032 | netxen_nic_driver_name, netdev->name); | ||
2033 | adapter->ahw.linkup = 0; | ||
2034 | if (netif_running(netdev)) { | ||
2035 | netif_carrier_off(netdev); | ||
2036 | netif_stop_queue(netdev); | ||
2037 | } | ||
2038 | adapter->link_changed = !adapter->has_link_events; | ||
2039 | } else if (!adapter->ahw.linkup && linkup) { | ||
2040 | printk(KERN_INFO "%s: %s NIC Link is up\n", | ||
2041 | netxen_nic_driver_name, netdev->name); | ||
2042 | adapter->ahw.linkup = 1; | ||
2043 | if (netif_running(netdev)) { | ||
2044 | netif_carrier_on(netdev); | ||
2045 | netif_wake_queue(netdev); | ||
2046 | } | ||
2047 | adapter->link_changed = !adapter->has_link_events; | ||
2048 | } | ||
2049 | } | ||
2050 | |||
2051 | static void netxen_nic_handle_phy_intr(struct netxen_adapter *adapter) | ||
2052 | { | ||
2053 | u32 val, port, linkup; | ||
2054 | |||
2055 | port = adapter->physical_port; | ||
2056 | |||
2057 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) { | ||
2058 | val = NXRD32(adapter, CRB_XG_STATE_P3); | ||
2059 | val = XG_LINK_STATE_P3(adapter->ahw.pci_func, val); | ||
2060 | linkup = (val == XG_LINK_UP_P3); | ||
2061 | } else { | ||
2062 | val = NXRD32(adapter, CRB_XG_STATE); | ||
2063 | val = (val >> port*8) & 0xff; | ||
2064 | linkup = (val == XG_LINK_UP); | ||
2065 | } | ||
2066 | |||
2067 | netxen_advert_link_change(adapter, linkup); | ||
2068 | } | ||
2069 | |||
2070 | static void netxen_tx_timeout(struct net_device *netdev) | ||
2071 | { | ||
2072 | struct netxen_adapter *adapter = netdev_priv(netdev); | ||
2073 | |||
2074 | if (test_bit(__NX_RESETTING, &adapter->state)) | ||
2075 | return; | ||
2076 | |||
2077 | dev_err(&netdev->dev, "transmit timeout, resetting.\n"); | ||
2078 | schedule_work(&adapter->tx_timeout_task); | ||
2079 | } | ||
2080 | |||
2081 | static void netxen_tx_timeout_task(struct work_struct *work) | ||
2082 | { | ||
2083 | struct netxen_adapter *adapter = | ||
2084 | container_of(work, struct netxen_adapter, tx_timeout_task); | ||
2085 | |||
2086 | if (!netif_running(adapter->netdev)) | ||
2087 | return; | ||
2088 | |||
2089 | if (test_and_set_bit(__NX_RESETTING, &adapter->state)) | ||
2090 | return; | ||
2091 | |||
2092 | if (++adapter->tx_timeo_cnt >= NX_MAX_TX_TIMEOUTS) | ||
2093 | goto request_reset; | ||
2094 | |||
2095 | rtnl_lock(); | ||
2096 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) { | ||
2097 | /* try to scrub interrupt */ | ||
2098 | netxen_napi_disable(adapter); | ||
2099 | |||
2100 | netxen_napi_enable(adapter); | ||
2101 | |||
2102 | netif_wake_queue(adapter->netdev); | ||
2103 | |||
2104 | clear_bit(__NX_RESETTING, &adapter->state); | ||
2105 | } else { | ||
2106 | clear_bit(__NX_RESETTING, &adapter->state); | ||
2107 | if (netxen_nic_reset_context(adapter)) { | ||
2108 | rtnl_unlock(); | ||
2109 | goto request_reset; | ||
2110 | } | ||
2111 | } | ||
2112 | adapter->netdev->trans_start = jiffies; | ||
2113 | rtnl_unlock(); | ||
2114 | return; | ||
2115 | |||
2116 | request_reset: | ||
2117 | adapter->need_fw_reset = 1; | ||
2118 | clear_bit(__NX_RESETTING, &adapter->state); | ||
2119 | } | ||
2120 | |||
2121 | static struct rtnl_link_stats64 *netxen_nic_get_stats(struct net_device *netdev, | ||
2122 | struct rtnl_link_stats64 *stats) | ||
2123 | { | ||
2124 | struct netxen_adapter *adapter = netdev_priv(netdev); | ||
2125 | |||
2126 | stats->rx_packets = adapter->stats.rx_pkts + adapter->stats.lro_pkts; | ||
2127 | stats->tx_packets = adapter->stats.xmitfinished; | ||
2128 | stats->rx_bytes = adapter->stats.rxbytes; | ||
2129 | stats->tx_bytes = adapter->stats.txbytes; | ||
2130 | stats->rx_dropped = adapter->stats.rxdropped; | ||
2131 | stats->tx_dropped = adapter->stats.txdropped; | ||
2132 | |||
2133 | return stats; | ||
2134 | } | ||
2135 | |||
2136 | static irqreturn_t netxen_intr(int irq, void *data) | ||
2137 | { | ||
2138 | struct nx_host_sds_ring *sds_ring = data; | ||
2139 | struct netxen_adapter *adapter = sds_ring->adapter; | ||
2140 | u32 status = 0; | ||
2141 | |||
2142 | status = readl(adapter->isr_int_vec); | ||
2143 | |||
2144 | if (!(status & adapter->int_vec_bit)) | ||
2145 | return IRQ_NONE; | ||
2146 | |||
2147 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) { | ||
2148 | /* check interrupt state machine, to be sure */ | ||
2149 | status = readl(adapter->crb_int_state_reg); | ||
2150 | if (!ISR_LEGACY_INT_TRIGGERED(status)) | ||
2151 | return IRQ_NONE; | ||
2152 | |||
2153 | } else { | ||
2154 | unsigned long our_int = 0; | ||
2155 | |||
2156 | our_int = readl(adapter->crb_int_state_reg); | ||
2157 | |||
2158 | /* not our interrupt */ | ||
2159 | if (!test_and_clear_bit((7 + adapter->portnum), &our_int)) | ||
2160 | return IRQ_NONE; | ||
2161 | |||
2162 | /* claim interrupt */ | ||
2163 | writel((our_int & 0xffffffff), adapter->crb_int_state_reg); | ||
2164 | |||
2165 | /* clear interrupt */ | ||
2166 | netxen_nic_disable_int(sds_ring); | ||
2167 | } | ||
2168 | |||
2169 | writel(0xffffffff, adapter->tgt_status_reg); | ||
2170 | /* read twice to ensure write is flushed */ | ||
2171 | readl(adapter->isr_int_vec); | ||
2172 | readl(adapter->isr_int_vec); | ||
2173 | |||
2174 | napi_schedule(&sds_ring->napi); | ||
2175 | |||
2176 | return IRQ_HANDLED; | ||
2177 | } | ||
2178 | |||
2179 | static irqreturn_t netxen_msi_intr(int irq, void *data) | ||
2180 | { | ||
2181 | struct nx_host_sds_ring *sds_ring = data; | ||
2182 | struct netxen_adapter *adapter = sds_ring->adapter; | ||
2183 | |||
2184 | /* clear interrupt */ | ||
2185 | writel(0xffffffff, adapter->tgt_status_reg); | ||
2186 | |||
2187 | napi_schedule(&sds_ring->napi); | ||
2188 | return IRQ_HANDLED; | ||
2189 | } | ||
2190 | |||
2191 | static irqreturn_t netxen_msix_intr(int irq, void *data) | ||
2192 | { | ||
2193 | struct nx_host_sds_ring *sds_ring = data; | ||
2194 | |||
2195 | napi_schedule(&sds_ring->napi); | ||
2196 | return IRQ_HANDLED; | ||
2197 | } | ||
2198 | |||
2199 | static int netxen_nic_poll(struct napi_struct *napi, int budget) | ||
2200 | { | ||
2201 | struct nx_host_sds_ring *sds_ring = | ||
2202 | container_of(napi, struct nx_host_sds_ring, napi); | ||
2203 | |||
2204 | struct netxen_adapter *adapter = sds_ring->adapter; | ||
2205 | |||
2206 | int tx_complete; | ||
2207 | int work_done; | ||
2208 | |||
2209 | tx_complete = netxen_process_cmd_ring(adapter); | ||
2210 | |||
2211 | work_done = netxen_process_rcv_ring(sds_ring, budget); | ||
2212 | |||
2213 | if ((work_done < budget) && tx_complete) { | ||
2214 | napi_complete(&sds_ring->napi); | ||
2215 | if (test_bit(__NX_DEV_UP, &adapter->state)) | ||
2216 | netxen_nic_enable_int(sds_ring); | ||
2217 | } | ||
2218 | |||
2219 | return work_done; | ||
2220 | } | ||
2221 | |||
2222 | #ifdef CONFIG_NET_POLL_CONTROLLER | ||
2223 | static void netxen_nic_poll_controller(struct net_device *netdev) | ||
2224 | { | ||
2225 | int ring; | ||
2226 | struct nx_host_sds_ring *sds_ring; | ||
2227 | struct netxen_adapter *adapter = netdev_priv(netdev); | ||
2228 | struct netxen_recv_context *recv_ctx = &adapter->recv_ctx; | ||
2229 | |||
2230 | disable_irq(adapter->irq); | ||
2231 | for (ring = 0; ring < adapter->max_sds_rings; ring++) { | ||
2232 | sds_ring = &recv_ctx->sds_rings[ring]; | ||
2233 | netxen_intr(adapter->irq, sds_ring); | ||
2234 | } | ||
2235 | enable_irq(adapter->irq); | ||
2236 | } | ||
2237 | #endif | ||
2238 | |||
2239 | static int | ||
2240 | nx_incr_dev_ref_cnt(struct netxen_adapter *adapter) | ||
2241 | { | ||
2242 | int count; | ||
2243 | if (netxen_api_lock(adapter)) | ||
2244 | return -EIO; | ||
2245 | |||
2246 | count = NXRD32(adapter, NX_CRB_DEV_REF_COUNT); | ||
2247 | |||
2248 | NXWR32(adapter, NX_CRB_DEV_REF_COUNT, ++count); | ||
2249 | |||
2250 | netxen_api_unlock(adapter); | ||
2251 | return count; | ||
2252 | } | ||
2253 | |||
2254 | static int | ||
2255 | nx_decr_dev_ref_cnt(struct netxen_adapter *adapter) | ||
2256 | { | ||
2257 | int count; | ||
2258 | if (netxen_api_lock(adapter)) | ||
2259 | return -EIO; | ||
2260 | |||
2261 | count = NXRD32(adapter, NX_CRB_DEV_REF_COUNT); | ||
2262 | WARN_ON(count == 0); | ||
2263 | |||
2264 | NXWR32(adapter, NX_CRB_DEV_REF_COUNT, --count); | ||
2265 | |||
2266 | if (count == 0) | ||
2267 | NXWR32(adapter, NX_CRB_DEV_STATE, NX_DEV_COLD); | ||
2268 | |||
2269 | netxen_api_unlock(adapter); | ||
2270 | return count; | ||
2271 | } | ||
2272 | |||
2273 | static int | ||
2274 | nx_dev_request_aer(struct netxen_adapter *adapter) | ||
2275 | { | ||
2276 | u32 state; | ||
2277 | int ret = -EINVAL; | ||
2278 | |||
2279 | if (netxen_api_lock(adapter)) | ||
2280 | return ret; | ||
2281 | |||
2282 | state = NXRD32(adapter, NX_CRB_DEV_STATE); | ||
2283 | |||
2284 | if (state == NX_DEV_NEED_AER) | ||
2285 | ret = 0; | ||
2286 | else if (state == NX_DEV_READY) { | ||
2287 | NXWR32(adapter, NX_CRB_DEV_STATE, NX_DEV_NEED_AER); | ||
2288 | ret = 0; | ||
2289 | } | ||
2290 | |||
2291 | netxen_api_unlock(adapter); | ||
2292 | return ret; | ||
2293 | } | ||
2294 | |||
2295 | static int | ||
2296 | nx_dev_request_reset(struct netxen_adapter *adapter) | ||
2297 | { | ||
2298 | u32 state; | ||
2299 | int ret = -EINVAL; | ||
2300 | |||
2301 | if (netxen_api_lock(adapter)) | ||
2302 | return ret; | ||
2303 | |||
2304 | state = NXRD32(adapter, NX_CRB_DEV_STATE); | ||
2305 | |||
2306 | if (state == NX_DEV_NEED_RESET) | ||
2307 | ret = 0; | ||
2308 | else if (state != NX_DEV_INITALIZING && state != NX_DEV_NEED_AER) { | ||
2309 | NXWR32(adapter, NX_CRB_DEV_STATE, NX_DEV_NEED_RESET); | ||
2310 | ret = 0; | ||
2311 | } | ||
2312 | |||
2313 | netxen_api_unlock(adapter); | ||
2314 | |||
2315 | return ret; | ||
2316 | } | ||
2317 | |||
2318 | static int | ||
2319 | netxen_can_start_firmware(struct netxen_adapter *adapter) | ||
2320 | { | ||
2321 | int count; | ||
2322 | int can_start = 0; | ||
2323 | |||
2324 | if (netxen_api_lock(adapter)) | ||
2325 | return 0; | ||
2326 | |||
2327 | count = NXRD32(adapter, NX_CRB_DEV_REF_COUNT); | ||
2328 | |||
2329 | if ((count < 0) || (count >= NX_MAX_PCI_FUNC)) | ||
2330 | count = 0; | ||
2331 | |||
2332 | if (count == 0) { | ||
2333 | can_start = 1; | ||
2334 | NXWR32(adapter, NX_CRB_DEV_STATE, NX_DEV_INITALIZING); | ||
2335 | } | ||
2336 | |||
2337 | NXWR32(adapter, NX_CRB_DEV_REF_COUNT, ++count); | ||
2338 | |||
2339 | netxen_api_unlock(adapter); | ||
2340 | |||
2341 | return can_start; | ||
2342 | } | ||
2343 | |||
2344 | static void | ||
2345 | netxen_schedule_work(struct netxen_adapter *adapter, | ||
2346 | work_func_t func, int delay) | ||
2347 | { | ||
2348 | INIT_DELAYED_WORK(&adapter->fw_work, func); | ||
2349 | schedule_delayed_work(&adapter->fw_work, delay); | ||
2350 | } | ||
2351 | |||
2352 | static void | ||
2353 | netxen_cancel_fw_work(struct netxen_adapter *adapter) | ||
2354 | { | ||
2355 | while (test_and_set_bit(__NX_RESETTING, &adapter->state)) | ||
2356 | msleep(10); | ||
2357 | |||
2358 | cancel_delayed_work_sync(&adapter->fw_work); | ||
2359 | } | ||
2360 | |||
2361 | static void | ||
2362 | netxen_attach_work(struct work_struct *work) | ||
2363 | { | ||
2364 | struct netxen_adapter *adapter = container_of(work, | ||
2365 | struct netxen_adapter, fw_work.work); | ||
2366 | struct net_device *netdev = adapter->netdev; | ||
2367 | int err = 0; | ||
2368 | |||
2369 | if (netif_running(netdev)) { | ||
2370 | err = netxen_nic_attach(adapter); | ||
2371 | if (err) | ||
2372 | goto done; | ||
2373 | |||
2374 | err = netxen_nic_up(adapter, netdev); | ||
2375 | if (err) { | ||
2376 | netxen_nic_detach(adapter); | ||
2377 | goto done; | ||
2378 | } | ||
2379 | |||
2380 | netxen_restore_indev_addr(netdev, NETDEV_UP); | ||
2381 | } | ||
2382 | |||
2383 | netif_device_attach(netdev); | ||
2384 | |||
2385 | done: | ||
2386 | adapter->fw_fail_cnt = 0; | ||
2387 | clear_bit(__NX_RESETTING, &adapter->state); | ||
2388 | netxen_schedule_work(adapter, netxen_fw_poll_work, FW_POLL_DELAY); | ||
2389 | } | ||
2390 | |||
2391 | static void | ||
2392 | netxen_fwinit_work(struct work_struct *work) | ||
2393 | { | ||
2394 | struct netxen_adapter *adapter = container_of(work, | ||
2395 | struct netxen_adapter, fw_work.work); | ||
2396 | int dev_state; | ||
2397 | |||
2398 | dev_state = NXRD32(adapter, NX_CRB_DEV_STATE); | ||
2399 | |||
2400 | switch (dev_state) { | ||
2401 | case NX_DEV_COLD: | ||
2402 | case NX_DEV_READY: | ||
2403 | if (!netxen_start_firmware(adapter)) { | ||
2404 | netxen_schedule_work(adapter, netxen_attach_work, 0); | ||
2405 | return; | ||
2406 | } | ||
2407 | break; | ||
2408 | |||
2409 | case NX_DEV_NEED_RESET: | ||
2410 | case NX_DEV_INITALIZING: | ||
2411 | if (++adapter->fw_wait_cnt < FW_POLL_THRESH) { | ||
2412 | netxen_schedule_work(adapter, | ||
2413 | netxen_fwinit_work, 2 * FW_POLL_DELAY); | ||
2414 | return; | ||
2415 | } | ||
2416 | |||
2417 | case NX_DEV_FAILED: | ||
2418 | default: | ||
2419 | nx_incr_dev_ref_cnt(adapter); | ||
2420 | break; | ||
2421 | } | ||
2422 | |||
2423 | clear_bit(__NX_RESETTING, &adapter->state); | ||
2424 | } | ||
2425 | |||
2426 | static void | ||
2427 | netxen_detach_work(struct work_struct *work) | ||
2428 | { | ||
2429 | struct netxen_adapter *adapter = container_of(work, | ||
2430 | struct netxen_adapter, fw_work.work); | ||
2431 | struct net_device *netdev = adapter->netdev; | ||
2432 | int ref_cnt, delay; | ||
2433 | u32 status; | ||
2434 | |||
2435 | netif_device_detach(netdev); | ||
2436 | |||
2437 | netxen_nic_down(adapter, netdev); | ||
2438 | |||
2439 | rtnl_lock(); | ||
2440 | netxen_nic_detach(adapter); | ||
2441 | rtnl_unlock(); | ||
2442 | |||
2443 | status = NXRD32(adapter, NETXEN_PEG_HALT_STATUS1); | ||
2444 | |||
2445 | if (status & NX_RCODE_FATAL_ERROR) | ||
2446 | goto err_ret; | ||
2447 | |||
2448 | if (adapter->temp == NX_TEMP_PANIC) | ||
2449 | goto err_ret; | ||
2450 | |||
2451 | ref_cnt = nx_decr_dev_ref_cnt(adapter); | ||
2452 | |||
2453 | if (ref_cnt == -EIO) | ||
2454 | goto err_ret; | ||
2455 | |||
2456 | delay = (ref_cnt == 0) ? 0 : (2 * FW_POLL_DELAY); | ||
2457 | |||
2458 | adapter->fw_wait_cnt = 0; | ||
2459 | netxen_schedule_work(adapter, netxen_fwinit_work, delay); | ||
2460 | |||
2461 | return; | ||
2462 | |||
2463 | err_ret: | ||
2464 | clear_bit(__NX_RESETTING, &adapter->state); | ||
2465 | } | ||
2466 | |||
2467 | static int | ||
2468 | netxen_check_health(struct netxen_adapter *adapter) | ||
2469 | { | ||
2470 | u32 state, heartbit; | ||
2471 | struct net_device *netdev = adapter->netdev; | ||
2472 | |||
2473 | state = NXRD32(adapter, NX_CRB_DEV_STATE); | ||
2474 | if (state == NX_DEV_NEED_AER) | ||
2475 | return 0; | ||
2476 | |||
2477 | if (netxen_nic_check_temp(adapter)) | ||
2478 | goto detach; | ||
2479 | |||
2480 | if (adapter->need_fw_reset) { | ||
2481 | if (nx_dev_request_reset(adapter)) | ||
2482 | return 0; | ||
2483 | goto detach; | ||
2484 | } | ||
2485 | |||
2486 | /* NX_DEV_NEED_RESET, this state can be marked in two cases | ||
2487 | * 1. Tx timeout 2. Fw hang | ||
2488 | * Send request to destroy context in case of tx timeout only | ||
2489 | * and doesn't required in case of Fw hang | ||
2490 | */ | ||
2491 | if (state == NX_DEV_NEED_RESET) { | ||
2492 | adapter->need_fw_reset = 1; | ||
2493 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) | ||
2494 | goto detach; | ||
2495 | } | ||
2496 | |||
2497 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) | ||
2498 | return 0; | ||
2499 | |||
2500 | heartbit = NXRD32(adapter, NETXEN_PEG_ALIVE_COUNTER); | ||
2501 | if (heartbit != adapter->heartbit) { | ||
2502 | adapter->heartbit = heartbit; | ||
2503 | adapter->fw_fail_cnt = 0; | ||
2504 | if (adapter->need_fw_reset) | ||
2505 | goto detach; | ||
2506 | return 0; | ||
2507 | } | ||
2508 | |||
2509 | if (++adapter->fw_fail_cnt < FW_FAIL_THRESH) | ||
2510 | return 0; | ||
2511 | |||
2512 | if (nx_dev_request_reset(adapter)) | ||
2513 | return 0; | ||
2514 | |||
2515 | clear_bit(__NX_FW_ATTACHED, &adapter->state); | ||
2516 | |||
2517 | dev_info(&netdev->dev, "firmware hang detected\n"); | ||
2518 | |||
2519 | detach: | ||
2520 | if ((auto_fw_reset == AUTO_FW_RESET_ENABLED) && | ||
2521 | !test_and_set_bit(__NX_RESETTING, &adapter->state)) | ||
2522 | netxen_schedule_work(adapter, netxen_detach_work, 0); | ||
2523 | return 1; | ||
2524 | } | ||
2525 | |||
2526 | static void | ||
2527 | netxen_fw_poll_work(struct work_struct *work) | ||
2528 | { | ||
2529 | struct netxen_adapter *adapter = container_of(work, | ||
2530 | struct netxen_adapter, fw_work.work); | ||
2531 | |||
2532 | if (test_bit(__NX_RESETTING, &adapter->state)) | ||
2533 | goto reschedule; | ||
2534 | |||
2535 | if (test_bit(__NX_DEV_UP, &adapter->state)) { | ||
2536 | if (!adapter->has_link_events) { | ||
2537 | |||
2538 | netxen_nic_handle_phy_intr(adapter); | ||
2539 | |||
2540 | if (adapter->link_changed) | ||
2541 | netxen_nic_set_link_parameters(adapter); | ||
2542 | } | ||
2543 | } | ||
2544 | |||
2545 | if (netxen_check_health(adapter)) | ||
2546 | return; | ||
2547 | |||
2548 | reschedule: | ||
2549 | netxen_schedule_work(adapter, netxen_fw_poll_work, FW_POLL_DELAY); | ||
2550 | } | ||
2551 | |||
2552 | static ssize_t | ||
2553 | netxen_store_bridged_mode(struct device *dev, | ||
2554 | struct device_attribute *attr, const char *buf, size_t len) | ||
2555 | { | ||
2556 | struct net_device *net = to_net_dev(dev); | ||
2557 | struct netxen_adapter *adapter = netdev_priv(net); | ||
2558 | unsigned long new; | ||
2559 | int ret = -EINVAL; | ||
2560 | |||
2561 | if (!(adapter->capabilities & NX_FW_CAPABILITY_BDG)) | ||
2562 | goto err_out; | ||
2563 | |||
2564 | if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC) | ||
2565 | goto err_out; | ||
2566 | |||
2567 | if (strict_strtoul(buf, 2, &new)) | ||
2568 | goto err_out; | ||
2569 | |||
2570 | if (!netxen_config_bridged_mode(adapter, !!new)) | ||
2571 | ret = len; | ||
2572 | |||
2573 | err_out: | ||
2574 | return ret; | ||
2575 | } | ||
2576 | |||
2577 | static ssize_t | ||
2578 | netxen_show_bridged_mode(struct device *dev, | ||
2579 | struct device_attribute *attr, char *buf) | ||
2580 | { | ||
2581 | struct net_device *net = to_net_dev(dev); | ||
2582 | struct netxen_adapter *adapter; | ||
2583 | int bridged_mode = 0; | ||
2584 | |||
2585 | adapter = netdev_priv(net); | ||
2586 | |||
2587 | if (adapter->capabilities & NX_FW_CAPABILITY_BDG) | ||
2588 | bridged_mode = !!(adapter->flags & NETXEN_NIC_BRIDGE_ENABLED); | ||
2589 | |||
2590 | return sprintf(buf, "%d\n", bridged_mode); | ||
2591 | } | ||
2592 | |||
2593 | static struct device_attribute dev_attr_bridged_mode = { | ||
2594 | .attr = {.name = "bridged_mode", .mode = (S_IRUGO | S_IWUSR)}, | ||
2595 | .show = netxen_show_bridged_mode, | ||
2596 | .store = netxen_store_bridged_mode, | ||
2597 | }; | ||
2598 | |||
2599 | static ssize_t | ||
2600 | netxen_store_diag_mode(struct device *dev, | ||
2601 | struct device_attribute *attr, const char *buf, size_t len) | ||
2602 | { | ||
2603 | struct netxen_adapter *adapter = dev_get_drvdata(dev); | ||
2604 | unsigned long new; | ||
2605 | |||
2606 | if (strict_strtoul(buf, 2, &new)) | ||
2607 | return -EINVAL; | ||
2608 | |||
2609 | if (!!new != !!(adapter->flags & NETXEN_NIC_DIAG_ENABLED)) | ||
2610 | adapter->flags ^= NETXEN_NIC_DIAG_ENABLED; | ||
2611 | |||
2612 | return len; | ||
2613 | } | ||
2614 | |||
2615 | static ssize_t | ||
2616 | netxen_show_diag_mode(struct device *dev, | ||
2617 | struct device_attribute *attr, char *buf) | ||
2618 | { | ||
2619 | struct netxen_adapter *adapter = dev_get_drvdata(dev); | ||
2620 | |||
2621 | return sprintf(buf, "%d\n", | ||
2622 | !!(adapter->flags & NETXEN_NIC_DIAG_ENABLED)); | ||
2623 | } | ||
2624 | |||
2625 | static struct device_attribute dev_attr_diag_mode = { | ||
2626 | .attr = {.name = "diag_mode", .mode = (S_IRUGO | S_IWUSR)}, | ||
2627 | .show = netxen_show_diag_mode, | ||
2628 | .store = netxen_store_diag_mode, | ||
2629 | }; | ||
2630 | |||
2631 | static int | ||
2632 | netxen_sysfs_validate_crb(struct netxen_adapter *adapter, | ||
2633 | loff_t offset, size_t size) | ||
2634 | { | ||
2635 | size_t crb_size = 4; | ||
2636 | |||
2637 | if (!(adapter->flags & NETXEN_NIC_DIAG_ENABLED)) | ||
2638 | return -EIO; | ||
2639 | |||
2640 | if (offset < NETXEN_PCI_CRBSPACE) { | ||
2641 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) | ||
2642 | return -EINVAL; | ||
2643 | |||
2644 | if (ADDR_IN_RANGE(offset, NETXEN_PCI_CAMQM, | ||
2645 | NETXEN_PCI_CAMQM_2M_END)) | ||
2646 | crb_size = 8; | ||
2647 | else | ||
2648 | return -EINVAL; | ||
2649 | } | ||
2650 | |||
2651 | if ((size != crb_size) || (offset & (crb_size-1))) | ||
2652 | return -EINVAL; | ||
2653 | |||
2654 | return 0; | ||
2655 | } | ||
2656 | |||
2657 | static ssize_t | ||
2658 | netxen_sysfs_read_crb(struct file *filp, struct kobject *kobj, | ||
2659 | struct bin_attribute *attr, | ||
2660 | char *buf, loff_t offset, size_t size) | ||
2661 | { | ||
2662 | struct device *dev = container_of(kobj, struct device, kobj); | ||
2663 | struct netxen_adapter *adapter = dev_get_drvdata(dev); | ||
2664 | u32 data; | ||
2665 | u64 qmdata; | ||
2666 | int ret; | ||
2667 | |||
2668 | ret = netxen_sysfs_validate_crb(adapter, offset, size); | ||
2669 | if (ret != 0) | ||
2670 | return ret; | ||
2671 | |||
2672 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id) && | ||
2673 | ADDR_IN_RANGE(offset, NETXEN_PCI_CAMQM, | ||
2674 | NETXEN_PCI_CAMQM_2M_END)) { | ||
2675 | netxen_pci_camqm_read_2M(adapter, offset, &qmdata); | ||
2676 | memcpy(buf, &qmdata, size); | ||
2677 | } else { | ||
2678 | data = NXRD32(adapter, offset); | ||
2679 | memcpy(buf, &data, size); | ||
2680 | } | ||
2681 | |||
2682 | return size; | ||
2683 | } | ||
2684 | |||
2685 | static ssize_t | ||
2686 | netxen_sysfs_write_crb(struct file *filp, struct kobject *kobj, | ||
2687 | struct bin_attribute *attr, | ||
2688 | char *buf, loff_t offset, size_t size) | ||
2689 | { | ||
2690 | struct device *dev = container_of(kobj, struct device, kobj); | ||
2691 | struct netxen_adapter *adapter = dev_get_drvdata(dev); | ||
2692 | u32 data; | ||
2693 | u64 qmdata; | ||
2694 | int ret; | ||
2695 | |||
2696 | ret = netxen_sysfs_validate_crb(adapter, offset, size); | ||
2697 | if (ret != 0) | ||
2698 | return ret; | ||
2699 | |||
2700 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id) && | ||
2701 | ADDR_IN_RANGE(offset, NETXEN_PCI_CAMQM, | ||
2702 | NETXEN_PCI_CAMQM_2M_END)) { | ||
2703 | memcpy(&qmdata, buf, size); | ||
2704 | netxen_pci_camqm_write_2M(adapter, offset, qmdata); | ||
2705 | } else { | ||
2706 | memcpy(&data, buf, size); | ||
2707 | NXWR32(adapter, offset, data); | ||
2708 | } | ||
2709 | |||
2710 | return size; | ||
2711 | } | ||
2712 | |||
2713 | static int | ||
2714 | netxen_sysfs_validate_mem(struct netxen_adapter *adapter, | ||
2715 | loff_t offset, size_t size) | ||
2716 | { | ||
2717 | if (!(adapter->flags & NETXEN_NIC_DIAG_ENABLED)) | ||
2718 | return -EIO; | ||
2719 | |||
2720 | if ((size != 8) || (offset & 0x7)) | ||
2721 | return -EIO; | ||
2722 | |||
2723 | return 0; | ||
2724 | } | ||
2725 | |||
2726 | static ssize_t | ||
2727 | netxen_sysfs_read_mem(struct file *filp, struct kobject *kobj, | ||
2728 | struct bin_attribute *attr, | ||
2729 | char *buf, loff_t offset, size_t size) | ||
2730 | { | ||
2731 | struct device *dev = container_of(kobj, struct device, kobj); | ||
2732 | struct netxen_adapter *adapter = dev_get_drvdata(dev); | ||
2733 | u64 data; | ||
2734 | int ret; | ||
2735 | |||
2736 | ret = netxen_sysfs_validate_mem(adapter, offset, size); | ||
2737 | if (ret != 0) | ||
2738 | return ret; | ||
2739 | |||
2740 | if (adapter->pci_mem_read(adapter, offset, &data)) | ||
2741 | return -EIO; | ||
2742 | |||
2743 | memcpy(buf, &data, size); | ||
2744 | |||
2745 | return size; | ||
2746 | } | ||
2747 | |||
2748 | static ssize_t netxen_sysfs_write_mem(struct file *filp, struct kobject *kobj, | ||
2749 | struct bin_attribute *attr, char *buf, | ||
2750 | loff_t offset, size_t size) | ||
2751 | { | ||
2752 | struct device *dev = container_of(kobj, struct device, kobj); | ||
2753 | struct netxen_adapter *adapter = dev_get_drvdata(dev); | ||
2754 | u64 data; | ||
2755 | int ret; | ||
2756 | |||
2757 | ret = netxen_sysfs_validate_mem(adapter, offset, size); | ||
2758 | if (ret != 0) | ||
2759 | return ret; | ||
2760 | |||
2761 | memcpy(&data, buf, size); | ||
2762 | |||
2763 | if (adapter->pci_mem_write(adapter, offset, data)) | ||
2764 | return -EIO; | ||
2765 | |||
2766 | return size; | ||
2767 | } | ||
2768 | |||
2769 | |||
2770 | static struct bin_attribute bin_attr_crb = { | ||
2771 | .attr = {.name = "crb", .mode = (S_IRUGO | S_IWUSR)}, | ||
2772 | .size = 0, | ||
2773 | .read = netxen_sysfs_read_crb, | ||
2774 | .write = netxen_sysfs_write_crb, | ||
2775 | }; | ||
2776 | |||
2777 | static struct bin_attribute bin_attr_mem = { | ||
2778 | .attr = {.name = "mem", .mode = (S_IRUGO | S_IWUSR)}, | ||
2779 | .size = 0, | ||
2780 | .read = netxen_sysfs_read_mem, | ||
2781 | .write = netxen_sysfs_write_mem, | ||
2782 | }; | ||
2783 | |||
2784 | |||
2785 | static void | ||
2786 | netxen_create_sysfs_entries(struct netxen_adapter *adapter) | ||
2787 | { | ||
2788 | struct net_device *netdev = adapter->netdev; | ||
2789 | struct device *dev = &netdev->dev; | ||
2790 | |||
2791 | if (adapter->capabilities & NX_FW_CAPABILITY_BDG) { | ||
2792 | /* bridged_mode control */ | ||
2793 | if (device_create_file(dev, &dev_attr_bridged_mode)) { | ||
2794 | dev_warn(&netdev->dev, | ||
2795 | "failed to create bridged_mode sysfs entry\n"); | ||
2796 | } | ||
2797 | } | ||
2798 | } | ||
2799 | |||
2800 | static void | ||
2801 | netxen_remove_sysfs_entries(struct netxen_adapter *adapter) | ||
2802 | { | ||
2803 | struct net_device *netdev = adapter->netdev; | ||
2804 | struct device *dev = &netdev->dev; | ||
2805 | |||
2806 | if (adapter->capabilities & NX_FW_CAPABILITY_BDG) | ||
2807 | device_remove_file(dev, &dev_attr_bridged_mode); | ||
2808 | } | ||
2809 | |||
2810 | static void | ||
2811 | netxen_create_diag_entries(struct netxen_adapter *adapter) | ||
2812 | { | ||
2813 | struct pci_dev *pdev = adapter->pdev; | ||
2814 | struct device *dev; | ||
2815 | |||
2816 | dev = &pdev->dev; | ||
2817 | if (device_create_file(dev, &dev_attr_diag_mode)) | ||
2818 | dev_info(dev, "failed to create diag_mode sysfs entry\n"); | ||
2819 | if (device_create_bin_file(dev, &bin_attr_crb)) | ||
2820 | dev_info(dev, "failed to create crb sysfs entry\n"); | ||
2821 | if (device_create_bin_file(dev, &bin_attr_mem)) | ||
2822 | dev_info(dev, "failed to create mem sysfs entry\n"); | ||
2823 | } | ||
2824 | |||
2825 | |||
2826 | static void | ||
2827 | netxen_remove_diag_entries(struct netxen_adapter *adapter) | ||
2828 | { | ||
2829 | struct pci_dev *pdev = adapter->pdev; | ||
2830 | struct device *dev = &pdev->dev; | ||
2831 | |||
2832 | device_remove_file(dev, &dev_attr_diag_mode); | ||
2833 | device_remove_bin_file(dev, &bin_attr_crb); | ||
2834 | device_remove_bin_file(dev, &bin_attr_mem); | ||
2835 | } | ||
2836 | |||
2837 | #ifdef CONFIG_INET | ||
2838 | |||
2839 | #define is_netxen_netdev(dev) (dev->netdev_ops == &netxen_netdev_ops) | ||
2840 | |||
2841 | static int | ||
2842 | netxen_destip_supported(struct netxen_adapter *adapter) | ||
2843 | { | ||
2844 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) | ||
2845 | return 0; | ||
2846 | |||
2847 | if (adapter->ahw.cut_through) | ||
2848 | return 0; | ||
2849 | |||
2850 | return 1; | ||
2851 | } | ||
2852 | |||
2853 | static void | ||
2854 | netxen_free_vlan_ip_list(struct netxen_adapter *adapter) | ||
2855 | { | ||
2856 | struct nx_vlan_ip_list *cur; | ||
2857 | struct list_head *head = &adapter->vlan_ip_list; | ||
2858 | |||
2859 | while (!list_empty(head)) { | ||
2860 | cur = list_entry(head->next, struct nx_vlan_ip_list, list); | ||
2861 | netxen_config_ipaddr(adapter, cur->ip_addr, NX_IP_DOWN); | ||
2862 | list_del(&cur->list); | ||
2863 | kfree(cur); | ||
2864 | } | ||
2865 | |||
2866 | } | ||
2867 | static void | ||
2868 | netxen_list_config_vlan_ip(struct netxen_adapter *adapter, | ||
2869 | struct in_ifaddr *ifa, unsigned long event) | ||
2870 | { | ||
2871 | struct net_device *dev; | ||
2872 | struct nx_vlan_ip_list *cur, *tmp_cur; | ||
2873 | struct list_head *head; | ||
2874 | |||
2875 | dev = ifa->ifa_dev ? ifa->ifa_dev->dev : NULL; | ||
2876 | |||
2877 | if (dev == NULL) | ||
2878 | return; | ||
2879 | |||
2880 | if (!is_vlan_dev(dev)) | ||
2881 | return; | ||
2882 | |||
2883 | switch (event) { | ||
2884 | case NX_IP_UP: | ||
2885 | list_for_each(head, &adapter->vlan_ip_list) { | ||
2886 | cur = list_entry(head, struct nx_vlan_ip_list, list); | ||
2887 | |||
2888 | if (cur->ip_addr == ifa->ifa_address) | ||
2889 | return; | ||
2890 | } | ||
2891 | |||
2892 | cur = kzalloc(sizeof(struct nx_vlan_ip_list), GFP_ATOMIC); | ||
2893 | if (cur == NULL) { | ||
2894 | printk(KERN_ERR "%s: failed to add vlan ip to list\n", | ||
2895 | adapter->netdev->name); | ||
2896 | return; | ||
2897 | } | ||
2898 | |||
2899 | cur->ip_addr = ifa->ifa_address; | ||
2900 | list_add_tail(&cur->list, &adapter->vlan_ip_list); | ||
2901 | break; | ||
2902 | case NX_IP_DOWN: | ||
2903 | list_for_each_entry_safe(cur, tmp_cur, | ||
2904 | &adapter->vlan_ip_list, list) { | ||
2905 | if (cur->ip_addr == ifa->ifa_address) { | ||
2906 | list_del(&cur->list); | ||
2907 | kfree(cur); | ||
2908 | break; | ||
2909 | } | ||
2910 | } | ||
2911 | } | ||
2912 | } | ||
2913 | static void | ||
2914 | netxen_config_indev_addr(struct netxen_adapter *adapter, | ||
2915 | struct net_device *dev, unsigned long event) | ||
2916 | { | ||
2917 | struct in_device *indev; | ||
2918 | |||
2919 | if (!netxen_destip_supported(adapter)) | ||
2920 | return; | ||
2921 | |||
2922 | indev = in_dev_get(dev); | ||
2923 | if (!indev) | ||
2924 | return; | ||
2925 | |||
2926 | for_ifa(indev) { | ||
2927 | switch (event) { | ||
2928 | case NETDEV_UP: | ||
2929 | netxen_config_ipaddr(adapter, | ||
2930 | ifa->ifa_address, NX_IP_UP); | ||
2931 | netxen_list_config_vlan_ip(adapter, ifa, NX_IP_UP); | ||
2932 | break; | ||
2933 | case NETDEV_DOWN: | ||
2934 | netxen_config_ipaddr(adapter, | ||
2935 | ifa->ifa_address, NX_IP_DOWN); | ||
2936 | netxen_list_config_vlan_ip(adapter, ifa, NX_IP_DOWN); | ||
2937 | break; | ||
2938 | default: | ||
2939 | break; | ||
2940 | } | ||
2941 | } endfor_ifa(indev); | ||
2942 | |||
2943 | in_dev_put(indev); | ||
2944 | } | ||
2945 | |||
2946 | static void | ||
2947 | netxen_restore_indev_addr(struct net_device *netdev, unsigned long event) | ||
2948 | |||
2949 | { | ||
2950 | struct netxen_adapter *adapter = netdev_priv(netdev); | ||
2951 | struct nx_vlan_ip_list *pos, *tmp_pos; | ||
2952 | unsigned long ip_event; | ||
2953 | |||
2954 | ip_event = (event == NETDEV_UP) ? NX_IP_UP : NX_IP_DOWN; | ||
2955 | netxen_config_indev_addr(adapter, netdev, event); | ||
2956 | |||
2957 | list_for_each_entry_safe(pos, tmp_pos, &adapter->vlan_ip_list, list) { | ||
2958 | netxen_config_ipaddr(adapter, pos->ip_addr, ip_event); | ||
2959 | } | ||
2960 | } | ||
2961 | |||
2962 | static int netxen_netdev_event(struct notifier_block *this, | ||
2963 | unsigned long event, void *ptr) | ||
2964 | { | ||
2965 | struct netxen_adapter *adapter; | ||
2966 | struct net_device *dev = (struct net_device *)ptr; | ||
2967 | struct net_device *orig_dev = dev; | ||
2968 | |||
2969 | recheck: | ||
2970 | if (dev == NULL) | ||
2971 | goto done; | ||
2972 | |||
2973 | if (dev->priv_flags & IFF_802_1Q_VLAN) { | ||
2974 | dev = vlan_dev_real_dev(dev); | ||
2975 | goto recheck; | ||
2976 | } | ||
2977 | |||
2978 | if (!is_netxen_netdev(dev)) | ||
2979 | goto done; | ||
2980 | |||
2981 | adapter = netdev_priv(dev); | ||
2982 | |||
2983 | if (!adapter) | ||
2984 | goto done; | ||
2985 | |||
2986 | if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC) | ||
2987 | goto done; | ||
2988 | |||
2989 | netxen_config_indev_addr(adapter, orig_dev, event); | ||
2990 | done: | ||
2991 | return NOTIFY_DONE; | ||
2992 | } | ||
2993 | |||
2994 | static int | ||
2995 | netxen_inetaddr_event(struct notifier_block *this, | ||
2996 | unsigned long event, void *ptr) | ||
2997 | { | ||
2998 | struct netxen_adapter *adapter; | ||
2999 | struct net_device *dev; | ||
3000 | |||
3001 | struct in_ifaddr *ifa = (struct in_ifaddr *)ptr; | ||
3002 | |||
3003 | dev = ifa->ifa_dev ? ifa->ifa_dev->dev : NULL; | ||
3004 | |||
3005 | recheck: | ||
3006 | if (dev == NULL) | ||
3007 | goto done; | ||
3008 | |||
3009 | if (dev->priv_flags & IFF_802_1Q_VLAN) { | ||
3010 | dev = vlan_dev_real_dev(dev); | ||
3011 | goto recheck; | ||
3012 | } | ||
3013 | |||
3014 | if (!is_netxen_netdev(dev)) | ||
3015 | goto done; | ||
3016 | |||
3017 | adapter = netdev_priv(dev); | ||
3018 | |||
3019 | if (!adapter || !netxen_destip_supported(adapter)) | ||
3020 | goto done; | ||
3021 | |||
3022 | if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC) | ||
3023 | goto done; | ||
3024 | |||
3025 | switch (event) { | ||
3026 | case NETDEV_UP: | ||
3027 | netxen_config_ipaddr(adapter, ifa->ifa_address, NX_IP_UP); | ||
3028 | netxen_list_config_vlan_ip(adapter, ifa, NX_IP_UP); | ||
3029 | break; | ||
3030 | case NETDEV_DOWN: | ||
3031 | netxen_config_ipaddr(adapter, ifa->ifa_address, NX_IP_DOWN); | ||
3032 | netxen_list_config_vlan_ip(adapter, ifa, NX_IP_DOWN); | ||
3033 | break; | ||
3034 | default: | ||
3035 | break; | ||
3036 | } | ||
3037 | |||
3038 | done: | ||
3039 | return NOTIFY_DONE; | ||
3040 | } | ||
3041 | |||
3042 | static struct notifier_block netxen_netdev_cb = { | ||
3043 | .notifier_call = netxen_netdev_event, | ||
3044 | }; | ||
3045 | |||
3046 | static struct notifier_block netxen_inetaddr_cb = { | ||
3047 | .notifier_call = netxen_inetaddr_event, | ||
3048 | }; | ||
3049 | #else | ||
3050 | static void | ||
3051 | netxen_restore_indev_addr(struct net_device *dev, unsigned long event) | ||
3052 | { } | ||
3053 | static void | ||
3054 | netxen_free_vlan_ip_list(struct netxen_adapter *adapter) | ||
3055 | { } | ||
3056 | #endif | ||
3057 | |||
3058 | static struct pci_error_handlers netxen_err_handler = { | ||
3059 | .error_detected = netxen_io_error_detected, | ||
3060 | .slot_reset = netxen_io_slot_reset, | ||
3061 | .resume = netxen_io_resume, | ||
3062 | }; | ||
3063 | |||
3064 | static struct pci_driver netxen_driver = { | ||
3065 | .name = netxen_nic_driver_name, | ||
3066 | .id_table = netxen_pci_tbl, | ||
3067 | .probe = netxen_nic_probe, | ||
3068 | .remove = __devexit_p(netxen_nic_remove), | ||
3069 | #ifdef CONFIG_PM | ||
3070 | .suspend = netxen_nic_suspend, | ||
3071 | .resume = netxen_nic_resume, | ||
3072 | #endif | ||
3073 | .shutdown = netxen_nic_shutdown, | ||
3074 | .err_handler = &netxen_err_handler | ||
3075 | }; | ||
3076 | |||
3077 | static int __init netxen_init_module(void) | ||
3078 | { | ||
3079 | printk(KERN_INFO "%s\n", netxen_nic_driver_string); | ||
3080 | |||
3081 | #ifdef CONFIG_INET | ||
3082 | register_netdevice_notifier(&netxen_netdev_cb); | ||
3083 | register_inetaddr_notifier(&netxen_inetaddr_cb); | ||
3084 | #endif | ||
3085 | return pci_register_driver(&netxen_driver); | ||
3086 | } | ||
3087 | |||
3088 | module_init(netxen_init_module); | ||
3089 | |||
3090 | static void __exit netxen_exit_module(void) | ||
3091 | { | ||
3092 | pci_unregister_driver(&netxen_driver); | ||
3093 | |||
3094 | #ifdef CONFIG_INET | ||
3095 | unregister_inetaddr_notifier(&netxen_inetaddr_cb); | ||
3096 | unregister_netdevice_notifier(&netxen_netdev_cb); | ||
3097 | #endif | ||
3098 | } | ||
3099 | |||
3100 | module_exit(netxen_exit_module); | ||