diff options
Diffstat (limited to 'drivers/net/netxen')
-rw-r--r-- | drivers/net/netxen/Makefile | 35 | ||||
-rw-r--r-- | drivers/net/netxen/netxen_nic.h | 1028 | ||||
-rw-r--r-- | drivers/net/netxen/netxen_nic_ethtool.c | 741 | ||||
-rw-r--r-- | drivers/net/netxen/netxen_nic_hdr.h | 678 | ||||
-rw-r--r-- | drivers/net/netxen/netxen_nic_hw.c | 1010 | ||||
-rw-r--r-- | drivers/net/netxen/netxen_nic_hw.h | 482 | ||||
-rw-r--r-- | drivers/net/netxen/netxen_nic_init.c | 1304 | ||||
-rw-r--r-- | drivers/net/netxen/netxen_nic_ioctl.h | 77 | ||||
-rw-r--r-- | drivers/net/netxen/netxen_nic_isr.c | 215 | ||||
-rw-r--r-- | drivers/net/netxen/netxen_nic_main.c | 1161 | ||||
-rw-r--r-- | drivers/net/netxen/netxen_nic_niu.c | 894 | ||||
-rw-r--r-- | drivers/net/netxen/netxen_nic_phan_reg.h | 215 |
12 files changed, 7840 insertions, 0 deletions
diff --git a/drivers/net/netxen/Makefile b/drivers/net/netxen/Makefile new file mode 100644 index 000000000000..a07cdc6f7384 --- /dev/null +++ b/drivers/net/netxen/Makefile | |||
@@ -0,0 +1,35 @@ | |||
1 | # Copyright (C) 2003 - 2006 NetXen, Inc. | ||
2 | # All rights reserved. | ||
3 | # | ||
4 | # This program is free software; you can redistribute it and/or | ||
5 | # modify it under the terms of the GNU General Public License | ||
6 | # as published by the Free Software Foundation; either version 2 | ||
7 | # of the License, or (at your option) any later version. | ||
8 | # | ||
9 | # This program is distributed in the hope that it will be useful, but | ||
10 | # WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | # GNU General Public License for more details. | ||
13 | # | ||
14 | # You should have received a copy of the GNU General Public License | ||
15 | # along with this program; if not, write to the Free Software | ||
16 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, | ||
17 | # MA 02111-1307, USA. | ||
18 | # | ||
19 | # The full GNU General Public License is included in this distribution | ||
20 | # in the file called LICENSE. | ||
21 | # | ||
22 | # Contact Information: | ||
23 | # info@netxen.com | ||
24 | # NetXen, | ||
25 | # 3965 Freedom Circle, Fourth floor, | ||
26 | # Santa Clara, CA 95054 | ||
27 | # | ||
28 | # Makefile for the NetXen NIC Driver | ||
29 | # | ||
30 | |||
31 | |||
32 | obj-$(CONFIG_NETXEN_NIC) := netxen_nic.o | ||
33 | |||
34 | netxen_nic-y := netxen_nic_hw.o netxen_nic_main.o netxen_nic_init.o \ | ||
35 | netxen_nic_isr.o netxen_nic_ethtool.o netxen_nic_niu.o | ||
diff --git a/drivers/net/netxen/netxen_nic.h b/drivers/net/netxen/netxen_nic.h new file mode 100644 index 000000000000..d925053fe597 --- /dev/null +++ b/drivers/net/netxen/netxen_nic.h | |||
@@ -0,0 +1,1028 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2003 - 2006 NetXen, Inc. | ||
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 LICENSE. | ||
22 | * | ||
23 | * Contact Information: | ||
24 | * info@netxen.com | ||
25 | * NetXen, | ||
26 | * 3965 Freedom Circle, Fourth floor, | ||
27 | * Santa Clara, CA 95054 | ||
28 | */ | ||
29 | |||
30 | #ifndef _NETXEN_NIC_H_ | ||
31 | #define _NETXEN_NIC_H_ | ||
32 | |||
33 | #include <linux/module.h> | ||
34 | #include <linux/kernel.h> | ||
35 | #include <linux/types.h> | ||
36 | #include <linux/compiler.h> | ||
37 | #include <linux/slab.h> | ||
38 | #include <linux/delay.h> | ||
39 | #include <linux/init.h> | ||
40 | #include <linux/ioport.h> | ||
41 | #include <linux/pci.h> | ||
42 | #include <linux/netdevice.h> | ||
43 | #include <linux/etherdevice.h> | ||
44 | #include <linux/ip.h> | ||
45 | #include <linux/in.h> | ||
46 | #include <linux/tcp.h> | ||
47 | #include <linux/skbuff.h> | ||
48 | #include <linux/version.h> | ||
49 | |||
50 | #include <linux/ethtool.h> | ||
51 | #include <linux/mii.h> | ||
52 | #include <linux/interrupt.h> | ||
53 | #include <linux/timer.h> | ||
54 | |||
55 | #include <linux/mm.h> | ||
56 | #include <linux/mman.h> | ||
57 | |||
58 | #include <asm/system.h> | ||
59 | #include <asm/io.h> | ||
60 | #include <asm/byteorder.h> | ||
61 | #include <asm/uaccess.h> | ||
62 | #include <asm/pgtable.h> | ||
63 | |||
64 | #include "netxen_nic_hw.h" | ||
65 | |||
66 | #define NETXEN_NIC_BUILD_NO "5" | ||
67 | #define _NETXEN_NIC_LINUX_MAJOR 2 | ||
68 | #define _NETXEN_NIC_LINUX_MINOR 3 | ||
69 | #define _NETXEN_NIC_LINUX_SUBVERSION 59 | ||
70 | #define NETXEN_NIC_LINUX_VERSIONID "2.3.59" "-" NETXEN_NIC_BUILD_NO | ||
71 | #define NETXEN_NIC_FW_VERSIONID "2.3.59" | ||
72 | |||
73 | #define RCV_DESC_RINGSIZE \ | ||
74 | (sizeof(struct rcv_desc) * adapter->max_rx_desc_count) | ||
75 | #define STATUS_DESC_RINGSIZE \ | ||
76 | (sizeof(struct status_desc)* adapter->max_rx_desc_count) | ||
77 | #define TX_RINGSIZE \ | ||
78 | (sizeof(struct netxen_cmd_buffer) * adapter->max_tx_desc_count) | ||
79 | #define RCV_BUFFSIZE \ | ||
80 | (sizeof(struct netxen_rx_buffer) * rcv_desc->max_rx_desc_count) | ||
81 | #define find_diff_among(a,b,range) ((a)<(b)?((b)-(a)):((b)+(range)-(a))) | ||
82 | |||
83 | #define NETXEN_NETDEV_STATUS 0x1 | ||
84 | |||
85 | #define ADDR_IN_WINDOW1(off) \ | ||
86 | ((off > NETXEN_CRB_PCIX_HOST2) && (off < NETXEN_CRB_MAX)) ? 1 : 0 | ||
87 | |||
88 | /* | ||
89 | * normalize a 64MB crb address to 32MB PCI window | ||
90 | * To use NETXEN_CRB_NORMALIZE, window _must_ be set to 1 | ||
91 | */ | ||
92 | #define NETXEN_CRB_NORMAL(reg) \ | ||
93 | (reg) - NETXEN_CRB_PCIX_HOST2 + NETXEN_CRB_PCIX_HOST | ||
94 | |||
95 | #define NETXEN_CRB_NORMALIZE(adapter, reg) \ | ||
96 | pci_base_offset(adapter, NETXEN_CRB_NORMAL(reg)) | ||
97 | |||
98 | #define FIRST_PAGE_GROUP_START 0 | ||
99 | #define FIRST_PAGE_GROUP_END 0x400000 | ||
100 | |||
101 | #define SECOND_PAGE_GROUP_START 0x4000000 | ||
102 | #define SECOND_PAGE_GROUP_END 0x66BC000 | ||
103 | |||
104 | #define THIRD_PAGE_GROUP_START 0x70E4000 | ||
105 | #define THIRD_PAGE_GROUP_END 0x8000000 | ||
106 | |||
107 | #define FIRST_PAGE_GROUP_SIZE FIRST_PAGE_GROUP_END - FIRST_PAGE_GROUP_START | ||
108 | #define SECOND_PAGE_GROUP_SIZE SECOND_PAGE_GROUP_END - SECOND_PAGE_GROUP_START | ||
109 | #define THIRD_PAGE_GROUP_SIZE THIRD_PAGE_GROUP_END - THIRD_PAGE_GROUP_START | ||
110 | |||
111 | #define MAX_RX_BUFFER_LENGTH 2000 | ||
112 | #define MAX_RX_JUMBO_BUFFER_LENGTH 9046 | ||
113 | #define RX_DMA_MAP_LEN (MAX_RX_BUFFER_LENGTH - NET_IP_ALIGN) | ||
114 | #define RX_JUMBO_DMA_MAP_LEN \ | ||
115 | (MAX_RX_JUMBO_BUFFER_LENGTH - NET_IP_ALIGN) | ||
116 | #define NETXEN_ROM_ROUNDUP 0x80000000ULL | ||
117 | |||
118 | /* | ||
119 | * Maximum number of ring contexts | ||
120 | */ | ||
121 | #define MAX_RING_CTX 1 | ||
122 | |||
123 | /* Opcodes to be used with the commands */ | ||
124 | enum { | ||
125 | TX_ETHER_PKT = 0x01, | ||
126 | /* The following opcodes are for IP checksum */ | ||
127 | TX_TCP_PKT, | ||
128 | TX_UDP_PKT, | ||
129 | TX_IP_PKT, | ||
130 | TX_TCP_LSO, | ||
131 | TX_IPSEC, | ||
132 | TX_IPSEC_CMD | ||
133 | }; | ||
134 | |||
135 | /* The following opcodes are for internal consumption. */ | ||
136 | #define NETXEN_CONTROL_OP 0x10 | ||
137 | #define PEGNET_REQUEST 0x11 | ||
138 | |||
139 | #define MAX_NUM_CARDS 4 | ||
140 | |||
141 | #define MAX_BUFFERS_PER_CMD 32 | ||
142 | |||
143 | /* | ||
144 | * Following are the states of the Phantom. Phantom will set them and | ||
145 | * Host will read to check if the fields are correct. | ||
146 | */ | ||
147 | #define PHAN_INITIALIZE_START 0xff00 | ||
148 | #define PHAN_INITIALIZE_FAILED 0xffff | ||
149 | #define PHAN_INITIALIZE_COMPLETE 0xff01 | ||
150 | |||
151 | /* Host writes the following to notify that it has done the init-handshake */ | ||
152 | #define PHAN_INITIALIZE_ACK 0xf00f | ||
153 | |||
154 | #define NUM_RCV_DESC_RINGS 2 /* No of Rcv Descriptor contexts */ | ||
155 | |||
156 | /* descriptor types */ | ||
157 | #define RCV_DESC_NORMAL 0x01 | ||
158 | #define RCV_DESC_JUMBO 0x02 | ||
159 | #define RCV_DESC_NORMAL_CTXID 0 | ||
160 | #define RCV_DESC_JUMBO_CTXID 1 | ||
161 | |||
162 | #define RCV_DESC_TYPE(ID) \ | ||
163 | ((ID == RCV_DESC_JUMBO_CTXID) ? RCV_DESC_JUMBO : RCV_DESC_NORMAL) | ||
164 | |||
165 | #define MAX_CMD_DESCRIPTORS 1024 | ||
166 | #define MAX_RCV_DESCRIPTORS 32768 | ||
167 | #define MAX_JUMBO_RCV_DESCRIPTORS 1024 | ||
168 | #define MAX_RCVSTATUS_DESCRIPTORS MAX_RCV_DESCRIPTORS | ||
169 | #define MAX_JUMBO_RCV_DESC MAX_JUMBO_RCV_DESCRIPTORS | ||
170 | #define MAX_RCV_DESC MAX_RCV_DESCRIPTORS | ||
171 | #define MAX_RCVSTATUS_DESC MAX_RCV_DESCRIPTORS | ||
172 | #define NUM_RCV_DESC (MAX_RCV_DESC + MAX_JUMBO_RCV_DESCRIPTORS) | ||
173 | #define MAX_EPG_DESCRIPTORS (MAX_CMD_DESCRIPTORS * 8) | ||
174 | |||
175 | #define MIN_TX_COUNT 4096 | ||
176 | #define MIN_RX_COUNT 4096 | ||
177 | |||
178 | #define MAX_FRAME_SIZE 0x10000 /* 64K MAX size for LSO */ | ||
179 | |||
180 | #define PHAN_PEG_RCV_INITIALIZED 0xff01 | ||
181 | #define PHAN_PEG_RCV_START_INITIALIZE 0xff00 | ||
182 | |||
183 | #define get_next_index(index, length) \ | ||
184 | (((index) + 1) & ((length) - 1)) | ||
185 | |||
186 | #define get_index_range(index,length,count) \ | ||
187 | (((index) + (count)) & ((length) - 1)) | ||
188 | |||
189 | /* | ||
190 | * Following data structures describe the descriptors that will be used. | ||
191 | * Added fileds of tcpHdrSize and ipHdrSize, The driver needs to do it only when | ||
192 | * we are doing LSO (above the 1500 size packet) only. | ||
193 | */ | ||
194 | |||
195 | /* | ||
196 | * The size of reference handle been changed to 16 bits to pass the MSS fields | ||
197 | * for the LSO packet | ||
198 | */ | ||
199 | |||
200 | #define FLAGS_CHECKSUM_ENABLED 0x01 | ||
201 | #define FLAGS_LSO_ENABLED 0x02 | ||
202 | #define FLAGS_IPSEC_SA_ADD 0x04 | ||
203 | #define FLAGS_IPSEC_SA_DELETE 0x08 | ||
204 | #define FLAGS_VLAN_TAGGED 0x10 | ||
205 | |||
206 | #define CMD_DESC_TOTAL_LENGTH(cmd_desc) \ | ||
207 | ((cmd_desc)->length_tcp_hdr & 0x00FFFFFF) | ||
208 | #define CMD_DESC_TCP_HDR_OFFSET(cmd_desc) \ | ||
209 | (((cmd_desc)->length_tcp_hdr >> 24) & 0x0FF) | ||
210 | #define CMD_DESC_PORT(cmd_desc) ((cmd_desc)->port_ctxid & 0x0F) | ||
211 | #define CMD_DESC_CTX_ID(cmd_desc) (((cmd_desc)->port_ctxid >> 4) & 0x0F) | ||
212 | |||
213 | #define CMD_DESC_TOTAL_LENGTH_WRT(cmd_desc, var) \ | ||
214 | ((cmd_desc)->length_tcp_hdr |= ((var) & 0x00FFFFFF)) | ||
215 | #define CMD_DESC_TCP_HDR_OFFSET_WRT(cmd_desc, var) \ | ||
216 | ((cmd_desc)->length_tcp_hdr |= (((var) << 24) & 0xFF000000)) | ||
217 | #define CMD_DESC_PORT_WRT(cmd_desc, var) \ | ||
218 | ((cmd_desc)->port_ctxid |= ((var) & 0x0F)) | ||
219 | |||
220 | struct cmd_desc_type0 { | ||
221 | u64 netxen_next; /* for fragments handled by Phantom */ | ||
222 | union { | ||
223 | struct { | ||
224 | u32 addr_low_part2; | ||
225 | u32 addr_high_part2; | ||
226 | }; | ||
227 | u64 addr_buffer2; | ||
228 | }; | ||
229 | |||
230 | /* Bit pattern: 0-23 total length, 24-32 tcp header offset */ | ||
231 | u32 length_tcp_hdr; | ||
232 | u8 ip_hdr_offset; /* For LSO only */ | ||
233 | u8 num_of_buffers; /* total number of segments */ | ||
234 | u8 flags; /* as defined above */ | ||
235 | u8 opcode; | ||
236 | |||
237 | u16 reference_handle; /* changed to u16 to add mss */ | ||
238 | u16 mss; /* passed by NDIS_PACKET for LSO */ | ||
239 | /* Bit pattern 0-3 port, 0-3 ctx id */ | ||
240 | u8 port_ctxid; | ||
241 | u8 total_hdr_length; /* LSO only : MAC+IP+TCP Hdr size */ | ||
242 | u16 conn_id; /* IPSec offoad only */ | ||
243 | |||
244 | union { | ||
245 | struct { | ||
246 | u32 addr_low_part3; | ||
247 | u32 addr_high_part3; | ||
248 | }; | ||
249 | u64 addr_buffer3; | ||
250 | }; | ||
251 | |||
252 | union { | ||
253 | struct { | ||
254 | u32 addr_low_part1; | ||
255 | u32 addr_high_part1; | ||
256 | }; | ||
257 | u64 addr_buffer1; | ||
258 | }; | ||
259 | |||
260 | u16 buffer1_length; | ||
261 | u16 buffer2_length; | ||
262 | u16 buffer3_length; | ||
263 | u16 buffer4_length; | ||
264 | |||
265 | union { | ||
266 | struct { | ||
267 | u32 addr_low_part4; | ||
268 | u32 addr_high_part4; | ||
269 | }; | ||
270 | u64 addr_buffer4; | ||
271 | }; | ||
272 | |||
273 | } __attribute__ ((aligned(64))); | ||
274 | |||
275 | /* Note: sizeof(rcv_desc) should always be a mutliple of 2 */ | ||
276 | struct rcv_desc { | ||
277 | u16 reference_handle; | ||
278 | u16 reserved; | ||
279 | u32 buffer_length; /* allocated buffer length (usually 2K) */ | ||
280 | u64 addr_buffer; | ||
281 | }; | ||
282 | |||
283 | /* opcode field in status_desc */ | ||
284 | #define RCV_NIC_PKT (0xA) | ||
285 | #define STATUS_NIC_PKT ((RCV_NIC_PKT) << 12) | ||
286 | |||
287 | /* for status field in status_desc */ | ||
288 | #define STATUS_NEED_CKSUM (1) | ||
289 | #define STATUS_CKSUM_OK (2) | ||
290 | |||
291 | /* owner bits of status_desc */ | ||
292 | #define STATUS_OWNER_HOST (0x1) | ||
293 | #define STATUS_OWNER_PHANTOM (0x2) | ||
294 | |||
295 | #define NETXEN_PROT_IP (1) | ||
296 | #define NETXEN_PROT_UNKNOWN (0) | ||
297 | |||
298 | /* Note: sizeof(status_desc) should always be a mutliple of 2 */ | ||
299 | #define STATUS_DESC_PORT(status_desc) \ | ||
300 | ((status_desc)->port_status_type_op & 0x0F) | ||
301 | #define STATUS_DESC_STATUS(status_desc) \ | ||
302 | (((status_desc)->port_status_type_op >> 4) & 0x0F) | ||
303 | #define STATUS_DESC_TYPE(status_desc) \ | ||
304 | (((status_desc)->port_status_type_op >> 8) & 0x0F) | ||
305 | #define STATUS_DESC_OPCODE(status_desc) \ | ||
306 | (((status_desc)->port_status_type_op >> 12) & 0x0F) | ||
307 | |||
308 | struct status_desc { | ||
309 | /* Bit pattern: 0-3 port, 4-7 status, 8-11 type, 12-15 opcode */ | ||
310 | u16 port_status_type_op; | ||
311 | u16 total_length; /* NIC mode */ | ||
312 | u16 reference_handle; /* handle for the associated packet */ | ||
313 | /* Bit pattern: 0-1 owner, 2-5 protocol */ | ||
314 | u16 owner; /* Owner of the descriptor */ | ||
315 | } __attribute__ ((aligned(8))); | ||
316 | |||
317 | enum { | ||
318 | NETXEN_RCV_PEG_0 = 0, | ||
319 | NETXEN_RCV_PEG_1 | ||
320 | }; | ||
321 | /* The version of the main data structure */ | ||
322 | #define NETXEN_BDINFO_VERSION 1 | ||
323 | |||
324 | /* Magic number to let user know flash is programmed */ | ||
325 | #define NETXEN_BDINFO_MAGIC 0x12345678 | ||
326 | |||
327 | /* Max number of Gig ports on a Phantom board */ | ||
328 | #define NETXEN_MAX_PORTS 4 | ||
329 | |||
330 | typedef enum { | ||
331 | NETXEN_BRDTYPE_P1_BD = 0x0000, | ||
332 | NETXEN_BRDTYPE_P1_SB = 0x0001, | ||
333 | NETXEN_BRDTYPE_P1_SMAX = 0x0002, | ||
334 | NETXEN_BRDTYPE_P1_SOCK = 0x0003, | ||
335 | |||
336 | NETXEN_BRDTYPE_P2_SOCK_31 = 0x0008, | ||
337 | NETXEN_BRDTYPE_P2_SOCK_35 = 0x0009, | ||
338 | NETXEN_BRDTYPE_P2_SB35_4G = 0x000a, | ||
339 | NETXEN_BRDTYPE_P2_SB31_10G = 0x000b, | ||
340 | NETXEN_BRDTYPE_P2_SB31_2G = 0x000c, | ||
341 | |||
342 | NETXEN_BRDTYPE_P2_SB31_10G_IMEZ = 0x000d, | ||
343 | NETXEN_BRDTYPE_P2_SB31_10G_HMEZ = 0x000e, | ||
344 | NETXEN_BRDTYPE_P2_SB31_10G_CX4 = 0x000f | ||
345 | } netxen_brdtype_t; | ||
346 | |||
347 | typedef enum { | ||
348 | NETXEN_BRDMFG_INVENTEC = 1 | ||
349 | } netxen_brdmfg; | ||
350 | |||
351 | typedef enum { | ||
352 | MEM_ORG_128Mbx4 = 0x0, /* DDR1 only */ | ||
353 | MEM_ORG_128Mbx8 = 0x1, /* DDR1 only */ | ||
354 | MEM_ORG_128Mbx16 = 0x2, /* DDR1 only */ | ||
355 | MEM_ORG_256Mbx4 = 0x3, | ||
356 | MEM_ORG_256Mbx8 = 0x4, | ||
357 | MEM_ORG_256Mbx16 = 0x5, | ||
358 | MEM_ORG_512Mbx4 = 0x6, | ||
359 | MEM_ORG_512Mbx8 = 0x7, | ||
360 | MEM_ORG_512Mbx16 = 0x8, | ||
361 | MEM_ORG_1Gbx4 = 0x9, | ||
362 | MEM_ORG_1Gbx8 = 0xa, | ||
363 | MEM_ORG_1Gbx16 = 0xb, | ||
364 | MEM_ORG_2Gbx4 = 0xc, | ||
365 | MEM_ORG_2Gbx8 = 0xd, | ||
366 | MEM_ORG_2Gbx16 = 0xe, | ||
367 | MEM_ORG_128Mbx32 = 0x10002, /* GDDR only */ | ||
368 | MEM_ORG_256Mbx32 = 0x10005 /* GDDR only */ | ||
369 | } netxen_mn_mem_org_t; | ||
370 | |||
371 | typedef enum { | ||
372 | MEM_ORG_512Kx36 = 0x0, | ||
373 | MEM_ORG_1Mx36 = 0x1, | ||
374 | MEM_ORG_2Mx36 = 0x2 | ||
375 | } netxen_sn_mem_org_t; | ||
376 | |||
377 | typedef enum { | ||
378 | MEM_DEPTH_4MB = 0x1, | ||
379 | MEM_DEPTH_8MB = 0x2, | ||
380 | MEM_DEPTH_16MB = 0x3, | ||
381 | MEM_DEPTH_32MB = 0x4, | ||
382 | MEM_DEPTH_64MB = 0x5, | ||
383 | MEM_DEPTH_128MB = 0x6, | ||
384 | MEM_DEPTH_256MB = 0x7, | ||
385 | MEM_DEPTH_512MB = 0x8, | ||
386 | MEM_DEPTH_1GB = 0x9, | ||
387 | MEM_DEPTH_2GB = 0xa, | ||
388 | MEM_DEPTH_4GB = 0xb, | ||
389 | MEM_DEPTH_8GB = 0xc, | ||
390 | MEM_DEPTH_16GB = 0xd, | ||
391 | MEM_DEPTH_32GB = 0xe | ||
392 | } netxen_mem_depth_t; | ||
393 | |||
394 | struct netxen_board_info { | ||
395 | u32 header_version; | ||
396 | |||
397 | u32 board_mfg; | ||
398 | u32 board_type; | ||
399 | u32 board_num; | ||
400 | u32 chip_id; | ||
401 | u32 chip_minor; | ||
402 | u32 chip_major; | ||
403 | u32 chip_pkg; | ||
404 | u32 chip_lot; | ||
405 | |||
406 | u32 port_mask; /* available niu ports */ | ||
407 | u32 peg_mask; /* available pegs */ | ||
408 | u32 icache_ok; /* can we run with icache? */ | ||
409 | u32 dcache_ok; /* can we run with dcache? */ | ||
410 | u32 casper_ok; | ||
411 | |||
412 | u32 mac_addr_lo_0; | ||
413 | u32 mac_addr_lo_1; | ||
414 | u32 mac_addr_lo_2; | ||
415 | u32 mac_addr_lo_3; | ||
416 | |||
417 | /* MN-related config */ | ||
418 | u32 mn_sync_mode; /* enable/ sync shift cclk/ sync shift mclk */ | ||
419 | u32 mn_sync_shift_cclk; | ||
420 | u32 mn_sync_shift_mclk; | ||
421 | u32 mn_wb_en; | ||
422 | u32 mn_crystal_freq; /* in MHz */ | ||
423 | u32 mn_speed; /* in MHz */ | ||
424 | u32 mn_org; | ||
425 | u32 mn_depth; | ||
426 | u32 mn_ranks_0; /* ranks per slot */ | ||
427 | u32 mn_ranks_1; /* ranks per slot */ | ||
428 | u32 mn_rd_latency_0; | ||
429 | u32 mn_rd_latency_1; | ||
430 | u32 mn_rd_latency_2; | ||
431 | u32 mn_rd_latency_3; | ||
432 | u32 mn_rd_latency_4; | ||
433 | u32 mn_rd_latency_5; | ||
434 | u32 mn_rd_latency_6; | ||
435 | u32 mn_rd_latency_7; | ||
436 | u32 mn_rd_latency_8; | ||
437 | u32 mn_dll_val[18]; | ||
438 | u32 mn_mode_reg; /* MIU DDR Mode Register */ | ||
439 | u32 mn_ext_mode_reg; /* MIU DDR Extended Mode Register */ | ||
440 | u32 mn_timing_0; /* MIU Memory Control Timing Rgister */ | ||
441 | u32 mn_timing_1; /* MIU Extended Memory Ctrl Timing Register */ | ||
442 | u32 mn_timing_2; /* MIU Extended Memory Ctrl Timing2 Register */ | ||
443 | |||
444 | /* SN-related config */ | ||
445 | u32 sn_sync_mode; /* enable/ sync shift cclk / sync shift mclk */ | ||
446 | u32 sn_pt_mode; /* pass through mode */ | ||
447 | u32 sn_ecc_en; | ||
448 | u32 sn_wb_en; | ||
449 | u32 sn_crystal_freq; | ||
450 | u32 sn_speed; | ||
451 | u32 sn_org; | ||
452 | u32 sn_depth; | ||
453 | u32 sn_dll_tap; | ||
454 | u32 sn_rd_latency; | ||
455 | |||
456 | u32 mac_addr_hi_0; | ||
457 | u32 mac_addr_hi_1; | ||
458 | u32 mac_addr_hi_2; | ||
459 | u32 mac_addr_hi_3; | ||
460 | |||
461 | u32 magic; /* indicates flash has been initialized */ | ||
462 | |||
463 | u32 mn_rdimm; | ||
464 | u32 mn_dll_override; | ||
465 | |||
466 | }; | ||
467 | |||
468 | #define FLASH_NUM_PORTS (4) | ||
469 | |||
470 | struct netxen_flash_mac_addr { | ||
471 | u32 flash_addr[32]; | ||
472 | }; | ||
473 | |||
474 | struct netxen_user_old_info { | ||
475 | u8 flash_md5[16]; | ||
476 | u8 crbinit_md5[16]; | ||
477 | u8 brdcfg_md5[16]; | ||
478 | /* bootloader */ | ||
479 | u32 bootld_version; | ||
480 | u32 bootld_size; | ||
481 | u8 bootld_md5[16]; | ||
482 | /* image */ | ||
483 | u32 image_version; | ||
484 | u32 image_size; | ||
485 | u8 image_md5[16]; | ||
486 | /* primary image status */ | ||
487 | u32 primary_status; | ||
488 | u32 secondary_present; | ||
489 | |||
490 | /* MAC address , 4 ports */ | ||
491 | struct netxen_flash_mac_addr mac_addr[FLASH_NUM_PORTS]; | ||
492 | }; | ||
493 | #define FLASH_NUM_MAC_PER_PORT 32 | ||
494 | struct netxen_user_info { | ||
495 | u8 flash_md5[16 * 64]; | ||
496 | /* bootloader */ | ||
497 | u32 bootld_version; | ||
498 | u32 bootld_size; | ||
499 | /* image */ | ||
500 | u32 image_version; | ||
501 | u32 image_size; | ||
502 | /* primary image status */ | ||
503 | u32 primary_status; | ||
504 | u32 secondary_present; | ||
505 | |||
506 | /* MAC address , 4 ports, 32 address per port */ | ||
507 | u64 mac_addr[FLASH_NUM_PORTS * FLASH_NUM_MAC_PER_PORT]; | ||
508 | u32 sub_sys_id; | ||
509 | u8 serial_num[32]; | ||
510 | |||
511 | /* Any user defined data */ | ||
512 | }; | ||
513 | |||
514 | /* | ||
515 | * Flash Layout - new format. | ||
516 | */ | ||
517 | struct netxen_new_user_info { | ||
518 | u8 flash_md5[16 * 64]; | ||
519 | /* bootloader */ | ||
520 | u32 bootld_version; | ||
521 | u32 bootld_size; | ||
522 | /* image */ | ||
523 | u32 image_version; | ||
524 | u32 image_size; | ||
525 | /* primary image status */ | ||
526 | u32 primary_status; | ||
527 | u32 secondary_present; | ||
528 | |||
529 | /* MAC address , 4 ports, 32 address per port */ | ||
530 | u64 mac_addr[FLASH_NUM_PORTS * FLASH_NUM_MAC_PER_PORT]; | ||
531 | u32 sub_sys_id; | ||
532 | u8 serial_num[32]; | ||
533 | |||
534 | /* Any user defined data */ | ||
535 | }; | ||
536 | |||
537 | #define SECONDARY_IMAGE_PRESENT 0xb3b4b5b6 | ||
538 | #define SECONDARY_IMAGE_ABSENT 0xffffffff | ||
539 | #define PRIMARY_IMAGE_GOOD 0x5a5a5a5a | ||
540 | #define PRIMARY_IMAGE_BAD 0xffffffff | ||
541 | |||
542 | /* Flash memory map */ | ||
543 | typedef enum { | ||
544 | CRBINIT_START = 0, /* Crbinit section */ | ||
545 | BRDCFG_START = 0x4000, /* board config */ | ||
546 | INITCODE_START = 0x6000, /* pegtune code */ | ||
547 | BOOTLD_START = 0x10000, /* bootld */ | ||
548 | IMAGE_START = 0x43000, /* compressed image */ | ||
549 | SECONDARY_START = 0x200000, /* backup images */ | ||
550 | PXE_START = 0x3E0000, /* user defined region */ | ||
551 | USER_START = 0x3E8000, /* User defined region for new boards */ | ||
552 | FIXED_START = 0x3F0000 /* backup of crbinit */ | ||
553 | } netxen_flash_map_t; | ||
554 | |||
555 | #define USER_START_OLD PXE_START /* for backward compatibility */ | ||
556 | |||
557 | #define FLASH_START (CRBINIT_START) | ||
558 | #define INIT_SECTOR (0) | ||
559 | #define PRIMARY_START (BOOTLD_START) | ||
560 | #define FLASH_CRBINIT_SIZE (0x4000) | ||
561 | #define FLASH_BRDCFG_SIZE (sizeof(struct netxen_board_info)) | ||
562 | #define FLASH_USER_SIZE (sizeof(netxen_user_info)/sizeof(u32)) | ||
563 | #define FLASH_SECONDARY_SIZE (USER_START-SECONDARY_START) | ||
564 | #define NUM_PRIMARY_SECTORS (0x20) | ||
565 | #define NUM_CONFIG_SECTORS (1) | ||
566 | #define PFX "netxen: " | ||
567 | |||
568 | /* Note: Make sure to not call this before adapter->port is valid */ | ||
569 | #if !defined(NETXEN_DEBUG) | ||
570 | #define DPRINTK(klevel, fmt, args...) do { \ | ||
571 | } while (0) | ||
572 | #else | ||
573 | #define DPRINTK(klevel, fmt, args...) do { \ | ||
574 | printk(KERN_##klevel PFX "%s: %s: " fmt, __FUNCTION__,\ | ||
575 | (adapter != NULL && adapter->port != NULL && \ | ||
576 | adapter->port[0] != NULL && \ | ||
577 | adapter->port[0]->netdev != NULL) ? \ | ||
578 | adapter->port[0]->netdev->name : NULL, \ | ||
579 | ## args); } while(0) | ||
580 | #endif | ||
581 | |||
582 | /* Number of status descriptors to handle per interrupt */ | ||
583 | #define MAX_STATUS_HANDLE (128) | ||
584 | |||
585 | /* | ||
586 | * netxen_skb_frag{} is to contain mapping info for each SG list. This | ||
587 | * has to be freed when DMA is complete. This is part of netxen_tx_buffer{}. | ||
588 | */ | ||
589 | struct netxen_skb_frag { | ||
590 | u64 dma; | ||
591 | u32 length; | ||
592 | }; | ||
593 | |||
594 | /* Following defines are for the state of the buffers */ | ||
595 | #define NETXEN_BUFFER_FREE 0 | ||
596 | #define NETXEN_BUFFER_BUSY 1 | ||
597 | |||
598 | /* | ||
599 | * There will be one netxen_buffer per skb packet. These will be | ||
600 | * used to save the dma info for pci_unmap_page() | ||
601 | */ | ||
602 | struct netxen_cmd_buffer { | ||
603 | struct sk_buff *skb; | ||
604 | struct netxen_skb_frag frag_array[MAX_BUFFERS_PER_CMD + 1]; | ||
605 | u32 total_length; | ||
606 | u32 mss; | ||
607 | u16 port; | ||
608 | u8 cmd; | ||
609 | u8 frag_count; | ||
610 | unsigned long time_stamp; | ||
611 | u32 state; | ||
612 | u32 no_of_descriptors; | ||
613 | }; | ||
614 | |||
615 | /* In rx_buffer, we do not need multiple fragments as is a single buffer */ | ||
616 | struct netxen_rx_buffer { | ||
617 | struct sk_buff *skb; | ||
618 | u64 dma; | ||
619 | u16 ref_handle; | ||
620 | u16 state; | ||
621 | }; | ||
622 | |||
623 | /* Board types */ | ||
624 | #define NETXEN_NIC_GBE 0x01 | ||
625 | #define NETXEN_NIC_XGBE 0x02 | ||
626 | |||
627 | /* | ||
628 | * One hardware_context{} per adapter | ||
629 | * contains interrupt info as well shared hardware info. | ||
630 | */ | ||
631 | struct netxen_hardware_context { | ||
632 | struct pci_dev *pdev; | ||
633 | void __iomem *pci_base0; | ||
634 | void __iomem *pci_base1; | ||
635 | void __iomem *pci_base2; | ||
636 | |||
637 | u8 revision_id; | ||
638 | u16 board_type; | ||
639 | u16 max_ports; | ||
640 | struct netxen_board_info boardcfg; | ||
641 | u32 xg_linkup; | ||
642 | u32 qg_linksup; | ||
643 | /* Address of cmd ring in Phantom */ | ||
644 | struct cmd_desc_type0 *cmd_desc_head; | ||
645 | char *pauseaddr; | ||
646 | struct pci_dev *cmd_desc_pdev; | ||
647 | dma_addr_t cmd_desc_phys_addr; | ||
648 | dma_addr_t pause_physaddr; | ||
649 | struct pci_dev *pause_pdev; | ||
650 | struct netxen_adapter *adapter; | ||
651 | }; | ||
652 | |||
653 | #define MINIMUM_ETHERNET_FRAME_SIZE 64 /* With FCS */ | ||
654 | #define ETHERNET_FCS_SIZE 4 | ||
655 | |||
656 | struct netxen_adapter_stats { | ||
657 | u64 ints; | ||
658 | u64 hostints; | ||
659 | u64 otherints; | ||
660 | u64 process_rcv; | ||
661 | u64 process_xmit; | ||
662 | u64 noxmitdone; | ||
663 | u64 xmitcsummed; | ||
664 | u64 post_called; | ||
665 | u64 posted; | ||
666 | u64 lastposted; | ||
667 | u64 goodskbposts; | ||
668 | }; | ||
669 | |||
670 | /* | ||
671 | * Rcv Descriptor Context. One such per Rcv Descriptor. There may | ||
672 | * be one Rcv Descriptor for normal packets, one for jumbo and may be others. | ||
673 | */ | ||
674 | struct netxen_rcv_desc_ctx { | ||
675 | u32 flags; | ||
676 | u32 producer; | ||
677 | u32 rcv_pending; /* Num of bufs posted in phantom */ | ||
678 | u32 rcv_free; /* Num of bufs in free list */ | ||
679 | dma_addr_t phys_addr; | ||
680 | struct pci_dev *phys_pdev; | ||
681 | struct rcv_desc *desc_head; /* address of rx ring in Phantom */ | ||
682 | u32 max_rx_desc_count; | ||
683 | u32 dma_size; | ||
684 | u32 skb_size; | ||
685 | struct netxen_rx_buffer *rx_buf_arr; /* rx buffers for receive */ | ||
686 | int begin_alloc; | ||
687 | }; | ||
688 | |||
689 | /* | ||
690 | * Receive context. There is one such structure per instance of the | ||
691 | * receive processing. Any state information that is relevant to | ||
692 | * the receive, and is must be in this structure. The global data may be | ||
693 | * present elsewhere. | ||
694 | */ | ||
695 | struct netxen_recv_context { | ||
696 | struct netxen_rcv_desc_ctx rcv_desc[NUM_RCV_DESC_RINGS]; | ||
697 | u32 status_rx_producer; | ||
698 | u32 status_rx_consumer; | ||
699 | dma_addr_t rcv_status_desc_phys_addr; | ||
700 | struct pci_dev *rcv_status_desc_pdev; | ||
701 | struct status_desc *rcv_status_desc_head; | ||
702 | }; | ||
703 | |||
704 | #define NETXEN_NIC_MSI_ENABLED 0x02 | ||
705 | |||
706 | struct netxen_drvops; | ||
707 | |||
708 | struct netxen_adapter { | ||
709 | struct netxen_hardware_context ahw; | ||
710 | int port_count; /* Number of configured ports */ | ||
711 | int active_ports; /* Number of open ports */ | ||
712 | struct netxen_port *port[NETXEN_MAX_PORTS]; /* ptr to each port */ | ||
713 | spinlock_t tx_lock; | ||
714 | spinlock_t lock; | ||
715 | struct work_struct watchdog_task; | ||
716 | struct work_struct tx_timeout_task; | ||
717 | struct timer_list watchdog_timer; | ||
718 | |||
719 | u32 curr_window; | ||
720 | |||
721 | u32 cmd_producer; | ||
722 | u32 cmd_consumer; | ||
723 | |||
724 | u32 last_cmd_consumer; | ||
725 | u32 max_tx_desc_count; | ||
726 | u32 max_rx_desc_count; | ||
727 | u32 max_jumbo_rx_desc_count; | ||
728 | /* Num of instances active on cmd buffer ring */ | ||
729 | u32 proc_cmd_buf_counter; | ||
730 | |||
731 | u32 num_threads, total_threads; /*Use to keep track of xmit threads */ | ||
732 | |||
733 | u32 flags; | ||
734 | u32 irq; | ||
735 | int driver_mismatch; | ||
736 | u32 temp; | ||
737 | |||
738 | struct netxen_adapter_stats stats; | ||
739 | |||
740 | struct netxen_cmd_buffer *cmd_buf_arr; /* Command buffers for xmit */ | ||
741 | |||
742 | /* | ||
743 | * Receive instances. These can be either one per port, | ||
744 | * or one per peg, etc. | ||
745 | */ | ||
746 | struct netxen_recv_context recv_ctx[MAX_RCV_CTX]; | ||
747 | |||
748 | int is_up; | ||
749 | int work_done; | ||
750 | struct netxen_drvops *ops; | ||
751 | }; /* netxen_adapter structure */ | ||
752 | |||
753 | /* Max number of xmit producer threads that can run simultaneously */ | ||
754 | #define MAX_XMIT_PRODUCERS 16 | ||
755 | |||
756 | struct netxen_port_stats { | ||
757 | u64 rcvdbadskb; | ||
758 | u64 xmitcalled; | ||
759 | u64 xmitedframes; | ||
760 | u64 xmitfinished; | ||
761 | u64 badskblen; | ||
762 | u64 nocmddescriptor; | ||
763 | u64 polled; | ||
764 | u64 uphappy; | ||
765 | u64 updropped; | ||
766 | u64 uplcong; | ||
767 | u64 uphcong; | ||
768 | u64 upmcong; | ||
769 | u64 updunno; | ||
770 | u64 skbfreed; | ||
771 | u64 txdropped; | ||
772 | u64 txnullskb; | ||
773 | u64 csummed; | ||
774 | u64 no_rcv; | ||
775 | u64 rxbytes; | ||
776 | u64 txbytes; | ||
777 | }; | ||
778 | |||
779 | struct netxen_port { | ||
780 | struct netxen_adapter *adapter; | ||
781 | |||
782 | u16 portnum; /* GBE port number */ | ||
783 | u16 link_speed; | ||
784 | u16 link_duplex; | ||
785 | u16 link_autoneg; | ||
786 | |||
787 | int flags; | ||
788 | |||
789 | struct net_device *netdev; | ||
790 | struct pci_dev *pdev; | ||
791 | struct net_device_stats net_stats; | ||
792 | struct netxen_port_stats stats; | ||
793 | }; | ||
794 | |||
795 | #define PCI_OFFSET_FIRST_RANGE(adapter, off) \ | ||
796 | ((adapter)->ahw.pci_base0 + (off)) | ||
797 | #define PCI_OFFSET_SECOND_RANGE(adapter, off) \ | ||
798 | ((adapter)->ahw.pci_base1 + (off) - SECOND_PAGE_GROUP_START) | ||
799 | #define PCI_OFFSET_THIRD_RANGE(adapter, off) \ | ||
800 | ((adapter)->ahw.pci_base2 + (off) - THIRD_PAGE_GROUP_START) | ||
801 | |||
802 | static inline void __iomem *pci_base_offset(struct netxen_adapter *adapter, | ||
803 | unsigned long off) | ||
804 | { | ||
805 | if ((off < FIRST_PAGE_GROUP_END) && (off >= FIRST_PAGE_GROUP_START)) { | ||
806 | return (adapter->ahw.pci_base0 + off); | ||
807 | } else if ((off < SECOND_PAGE_GROUP_END) && | ||
808 | (off >= SECOND_PAGE_GROUP_START)) { | ||
809 | return (adapter->ahw.pci_base1 + off - SECOND_PAGE_GROUP_START); | ||
810 | } else if ((off < THIRD_PAGE_GROUP_END) && | ||
811 | (off >= THIRD_PAGE_GROUP_START)) { | ||
812 | return (adapter->ahw.pci_base2 + off - THIRD_PAGE_GROUP_START); | ||
813 | } | ||
814 | return NULL; | ||
815 | } | ||
816 | |||
817 | static inline void __iomem *pci_base(struct netxen_adapter *adapter, | ||
818 | unsigned long off) | ||
819 | { | ||
820 | if ((off < FIRST_PAGE_GROUP_END) && (off >= FIRST_PAGE_GROUP_START)) { | ||
821 | return adapter->ahw.pci_base0; | ||
822 | } else if ((off < SECOND_PAGE_GROUP_END) && | ||
823 | (off >= SECOND_PAGE_GROUP_START)) { | ||
824 | return adapter->ahw.pci_base1; | ||
825 | } else if ((off < THIRD_PAGE_GROUP_END) && | ||
826 | (off >= THIRD_PAGE_GROUP_START)) { | ||
827 | return adapter->ahw.pci_base2; | ||
828 | } | ||
829 | return NULL; | ||
830 | } | ||
831 | |||
832 | struct netxen_drvops { | ||
833 | int (*enable_phy_interrupts) (struct netxen_adapter *, int); | ||
834 | int (*disable_phy_interrupts) (struct netxen_adapter *, int); | ||
835 | void (*handle_phy_intr) (struct netxen_adapter *); | ||
836 | int (*macaddr_set) (struct netxen_port *, netxen_ethernet_macaddr_t); | ||
837 | int (*set_mtu) (struct netxen_port *, int); | ||
838 | int (*set_promisc) (struct netxen_adapter *, int, | ||
839 | netxen_niu_prom_mode_t); | ||
840 | int (*unset_promisc) (struct netxen_adapter *, int, | ||
841 | netxen_niu_prom_mode_t); | ||
842 | int (*phy_read) (struct netxen_adapter *, long phy, long reg, u32 *); | ||
843 | int (*phy_write) (struct netxen_adapter *, long phy, long reg, u32 val); | ||
844 | int (*init_port) (struct netxen_adapter *, int); | ||
845 | void (*init_niu) (struct netxen_adapter *); | ||
846 | int (*stop_port) (struct netxen_adapter *, int); | ||
847 | }; | ||
848 | |||
849 | extern char netxen_nic_driver_name[]; | ||
850 | |||
851 | int netxen_niu_xgbe_enable_phy_interrupts(struct netxen_adapter *adapter, | ||
852 | int port); | ||
853 | int netxen_niu_gbe_enable_phy_interrupts(struct netxen_adapter *adapter, | ||
854 | int port); | ||
855 | int netxen_niu_xgbe_disable_phy_interrupts(struct netxen_adapter *adapter, | ||
856 | int port); | ||
857 | int netxen_niu_gbe_disable_phy_interrupts(struct netxen_adapter *adapter, | ||
858 | int port); | ||
859 | int netxen_niu_xgbe_clear_phy_interrupts(struct netxen_adapter *adapter, | ||
860 | int port); | ||
861 | int netxen_niu_gbe_clear_phy_interrupts(struct netxen_adapter *adapter, | ||
862 | int port); | ||
863 | void netxen_nic_xgbe_handle_phy_intr(struct netxen_adapter *adapter); | ||
864 | void netxen_nic_gbe_handle_phy_intr(struct netxen_adapter *adapter); | ||
865 | void netxen_niu_gbe_set_mii_mode(struct netxen_adapter *adapter, int port, | ||
866 | long enable); | ||
867 | void netxen_niu_gbe_set_gmii_mode(struct netxen_adapter *adapter, int port, | ||
868 | long enable); | ||
869 | int netxen_niu_gbe_phy_read(struct netxen_adapter *adapter, long phy, long reg, | ||
870 | __le32 * readval); | ||
871 | int netxen_niu_gbe_phy_write(struct netxen_adapter *adapter, long phy, | ||
872 | long reg, __le32 val); | ||
873 | |||
874 | /* Functions available from netxen_nic_hw.c */ | ||
875 | int netxen_nic_set_mtu_xgb(struct netxen_port *port, int new_mtu); | ||
876 | int netxen_nic_set_mtu_gb(struct netxen_port *port, int new_mtu); | ||
877 | void netxen_nic_init_niu_gb(struct netxen_adapter *adapter); | ||
878 | void netxen_nic_pci_change_crbwindow(struct netxen_adapter *adapter, u32 wndw); | ||
879 | void netxen_nic_reg_write(struct netxen_adapter *adapter, u64 off, u32 val); | ||
880 | int netxen_nic_reg_read(struct netxen_adapter *adapter, u64 off); | ||
881 | void netxen_nic_write_w0(struct netxen_adapter *adapter, u32 index, u32 value); | ||
882 | void netxen_nic_read_w0(struct netxen_adapter *adapter, u32 index, u32 * value); | ||
883 | |||
884 | int netxen_nic_get_board_info(struct netxen_adapter *adapter); | ||
885 | int netxen_nic_hw_read_wx(struct netxen_adapter *adapter, u64 off, void *data, | ||
886 | int len); | ||
887 | int netxen_nic_hw_write_wx(struct netxen_adapter *adapter, u64 off, void *data, | ||
888 | int len); | ||
889 | void netxen_crb_writelit_adapter(struct netxen_adapter *adapter, | ||
890 | unsigned long off, int data); | ||
891 | |||
892 | /* Functions from netxen_nic_init.c */ | ||
893 | void netxen_phantom_init(struct netxen_adapter *adapter, int pegtune_val); | ||
894 | void netxen_load_firmware(struct netxen_adapter *adapter); | ||
895 | int netxen_pinit_from_rom(struct netxen_adapter *adapter, int verbose); | ||
896 | int netxen_rom_fast_read(struct netxen_adapter *adapter, int addr, int *valp); | ||
897 | int netxen_rom_fast_write(struct netxen_adapter *adapter, int addr, int data); | ||
898 | int netxen_rom_se(struct netxen_adapter *adapter, int addr); | ||
899 | int netxen_do_rom_se(struct netxen_adapter *adapter, int addr); | ||
900 | |||
901 | /* Functions from netxen_nic_isr.c */ | ||
902 | void netxen_nic_isr_other(struct netxen_adapter *adapter); | ||
903 | void netxen_indicate_link_status(struct netxen_adapter *adapter, u32 port, | ||
904 | u32 link); | ||
905 | void netxen_handle_port_int(struct netxen_adapter *adapter, u32 port, | ||
906 | u32 enable); | ||
907 | void netxen_nic_stop_all_ports(struct netxen_adapter *adapter); | ||
908 | void netxen_initialize_adapter_sw(struct netxen_adapter *adapter); | ||
909 | void netxen_initialize_adapter_hw(struct netxen_adapter *adapter); | ||
910 | void *netxen_alloc(struct pci_dev *pdev, size_t sz, dma_addr_t * ptr, | ||
911 | struct pci_dev **used_dev); | ||
912 | void netxen_initialize_adapter_ops(struct netxen_adapter *adapter); | ||
913 | int netxen_init_firmware(struct netxen_adapter *adapter); | ||
914 | void netxen_free_hw_resources(struct netxen_adapter *adapter); | ||
915 | void netxen_tso_check(struct netxen_adapter *adapter, | ||
916 | struct cmd_desc_type0 *desc, struct sk_buff *skb); | ||
917 | int netxen_nic_hw_resources(struct netxen_adapter *adapter); | ||
918 | void netxen_nic_clear_stats(struct netxen_adapter *adapter); | ||
919 | int | ||
920 | netxen_nic_do_ioctl(struct netxen_adapter *adapter, void *u_data, | ||
921 | struct netxen_port *port); | ||
922 | int netxen_nic_rx_has_work(struct netxen_adapter *adapter); | ||
923 | int netxen_nic_tx_has_work(struct netxen_adapter *adapter); | ||
924 | void netxen_watchdog_task(unsigned long v); | ||
925 | void netxen_post_rx_buffers(struct netxen_adapter *adapter, u32 ctx, | ||
926 | u32 ringid); | ||
927 | void netxen_process_cmd_ring(unsigned long data); | ||
928 | u32 netxen_process_rcv_ring(struct netxen_adapter *adapter, int ctx, int max); | ||
929 | void netxen_nic_set_multi(struct net_device *netdev); | ||
930 | int netxen_nic_change_mtu(struct net_device *netdev, int new_mtu); | ||
931 | int netxen_nic_set_mac(struct net_device *netdev, void *p); | ||
932 | struct net_device_stats *netxen_nic_get_stats(struct net_device *netdev); | ||
933 | |||
934 | static inline void netxen_nic_disable_int(struct netxen_adapter *adapter) | ||
935 | { | ||
936 | /* | ||
937 | * ISR_INT_MASK: Can be read from window 0 or 1. | ||
938 | */ | ||
939 | writel(0x7ff, PCI_OFFSET_SECOND_RANGE(adapter, ISR_INT_MASK)); | ||
940 | |||
941 | } | ||
942 | |||
943 | static inline void netxen_nic_enable_int(struct netxen_adapter *adapter) | ||
944 | { | ||
945 | u32 mask; | ||
946 | |||
947 | switch (adapter->ahw.board_type) { | ||
948 | case NETXEN_NIC_GBE: | ||
949 | mask = 0x77b; | ||
950 | break; | ||
951 | case NETXEN_NIC_XGBE: | ||
952 | mask = 0x77f; | ||
953 | break; | ||
954 | default: | ||
955 | mask = 0x7ff; | ||
956 | break; | ||
957 | } | ||
958 | |||
959 | writel(mask, PCI_OFFSET_SECOND_RANGE(adapter, ISR_INT_MASK)); | ||
960 | |||
961 | if (!(adapter->flags & NETXEN_NIC_MSI_ENABLED)) { | ||
962 | mask = 0xbff; | ||
963 | writel(mask, PCI_OFFSET_SECOND_RANGE(adapter, | ||
964 | ISR_INT_TARGET_MASK)); | ||
965 | } | ||
966 | } | ||
967 | |||
968 | /* | ||
969 | * NetXen Board information | ||
970 | */ | ||
971 | |||
972 | #define NETXEN_MAX_SHORT_NAME 16 | ||
973 | struct netxen_brdinfo { | ||
974 | netxen_brdtype_t brdtype; /* type of board */ | ||
975 | long ports; /* max no of physical ports */ | ||
976 | char short_name[NETXEN_MAX_SHORT_NAME]; | ||
977 | }; | ||
978 | |||
979 | static const struct netxen_brdinfo netxen_boards[] = { | ||
980 | {NETXEN_BRDTYPE_P2_SB31_10G_CX4, 1, "XGb CX4"}, | ||
981 | {NETXEN_BRDTYPE_P2_SB31_10G_HMEZ, 1, "XGb HMEZ"}, | ||
982 | {NETXEN_BRDTYPE_P2_SB31_10G_IMEZ, 2, "XGb IMEZ"}, | ||
983 | {NETXEN_BRDTYPE_P2_SB31_10G, 1, "XGb XFP"}, | ||
984 | {NETXEN_BRDTYPE_P2_SB35_4G, 4, "Quad Gb"}, | ||
985 | {NETXEN_BRDTYPE_P2_SB31_2G, 2, "Dual Gb"}, | ||
986 | }; | ||
987 | |||
988 | #define NUM_SUPPORTED_BOARDS (sizeof(netxen_boards)/sizeof(struct netxen_brdinfo)) | ||
989 | |||
990 | static inline void get_brd_port_by_type(u32 type, int *ports) | ||
991 | { | ||
992 | int i, found = 0; | ||
993 | for (i = 0; i < NUM_SUPPORTED_BOARDS; ++i) { | ||
994 | if (netxen_boards[i].brdtype == type) { | ||
995 | *ports = netxen_boards[i].ports; | ||
996 | found = 1; | ||
997 | break; | ||
998 | } | ||
999 | } | ||
1000 | if (!found) | ||
1001 | *ports = 0; | ||
1002 | } | ||
1003 | |||
1004 | static inline void get_brd_name_by_type(u32 type, char *name) | ||
1005 | { | ||
1006 | int i, found = 0; | ||
1007 | for (i = 0; i < NUM_SUPPORTED_BOARDS; ++i) { | ||
1008 | if (netxen_boards[i].brdtype == type) { | ||
1009 | strcpy(name, netxen_boards[i].short_name); | ||
1010 | found = 1; | ||
1011 | break; | ||
1012 | } | ||
1013 | |||
1014 | } | ||
1015 | if (!found) | ||
1016 | name = "Unknown"; | ||
1017 | } | ||
1018 | |||
1019 | int netxen_is_flash_supported(struct netxen_adapter *adapter); | ||
1020 | int netxen_get_flash_mac_addr(struct netxen_adapter *adapter, u64 mac[]); | ||
1021 | |||
1022 | extern void netxen_change_ringparam(struct netxen_adapter *adapter); | ||
1023 | extern int netxen_rom_fast_read(struct netxen_adapter *adapter, int addr, | ||
1024 | int *valp); | ||
1025 | |||
1026 | extern struct ethtool_ops netxen_nic_ethtool_ops; | ||
1027 | |||
1028 | #endif /* __NETXEN_NIC_H_ */ | ||
diff --git a/drivers/net/netxen/netxen_nic_ethtool.c b/drivers/net/netxen/netxen_nic_ethtool.c new file mode 100644 index 000000000000..9a914aeba5bc --- /dev/null +++ b/drivers/net/netxen/netxen_nic_ethtool.c | |||
@@ -0,0 +1,741 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2003 - 2006 NetXen, Inc. | ||
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 LICENSE. | ||
22 | * | ||
23 | * Contact Information: | ||
24 | * info@netxen.com | ||
25 | * NetXen, | ||
26 | * 3965 Freedom Circle, Fourth floor, | ||
27 | * Santa Clara, CA 95054 | ||
28 | * | ||
29 | * | ||
30 | * ethtool support for netxen nic | ||
31 | * | ||
32 | */ | ||
33 | |||
34 | #include <linux/types.h> | ||
35 | #include <asm/uaccess.h> | ||
36 | #include <linux/pci.h> | ||
37 | #include <asm/io.h> | ||
38 | #include <linux/netdevice.h> | ||
39 | #include <linux/ethtool.h> | ||
40 | #include <linux/version.h> | ||
41 | |||
42 | #include "netxen_nic_hw.h" | ||
43 | #include "netxen_nic.h" | ||
44 | #include "netxen_nic_phan_reg.h" | ||
45 | #include "netxen_nic_ioctl.h" | ||
46 | |||
47 | struct netxen_nic_stats { | ||
48 | char stat_string[ETH_GSTRING_LEN]; | ||
49 | int sizeof_stat; | ||
50 | int stat_offset; | ||
51 | }; | ||
52 | |||
53 | #define NETXEN_NIC_STAT(m) sizeof(((struct netxen_port *)0)->m), \ | ||
54 | offsetof(struct netxen_port, m) | ||
55 | |||
56 | #define NETXEN_NIC_PORT_WINDOW 0x10000 | ||
57 | #define NETXEN_NIC_INVALID_DATA 0xDEADBEEF | ||
58 | |||
59 | static const struct netxen_nic_stats netxen_nic_gstrings_stats[] = { | ||
60 | {"rcvd_bad_skb", NETXEN_NIC_STAT(stats.rcvdbadskb)}, | ||
61 | {"xmit_called", NETXEN_NIC_STAT(stats.xmitcalled)}, | ||
62 | {"xmited_frames", NETXEN_NIC_STAT(stats.xmitedframes)}, | ||
63 | {"xmit_finished", NETXEN_NIC_STAT(stats.xmitfinished)}, | ||
64 | {"bad_skb_len", NETXEN_NIC_STAT(stats.badskblen)}, | ||
65 | {"no_cmd_desc", NETXEN_NIC_STAT(stats.nocmddescriptor)}, | ||
66 | {"polled", NETXEN_NIC_STAT(stats.polled)}, | ||
67 | {"uphappy", NETXEN_NIC_STAT(stats.uphappy)}, | ||
68 | {"updropped", NETXEN_NIC_STAT(stats.updropped)}, | ||
69 | {"uplcong", NETXEN_NIC_STAT(stats.uplcong)}, | ||
70 | {"uphcong", NETXEN_NIC_STAT(stats.uphcong)}, | ||
71 | {"upmcong", NETXEN_NIC_STAT(stats.upmcong)}, | ||
72 | {"updunno", NETXEN_NIC_STAT(stats.updunno)}, | ||
73 | {"skb_freed", NETXEN_NIC_STAT(stats.skbfreed)}, | ||
74 | {"tx_dropped", NETXEN_NIC_STAT(stats.txdropped)}, | ||
75 | {"tx_null_skb", NETXEN_NIC_STAT(stats.txnullskb)}, | ||
76 | {"csummed", NETXEN_NIC_STAT(stats.csummed)}, | ||
77 | {"no_rcv", NETXEN_NIC_STAT(stats.no_rcv)}, | ||
78 | {"rx_bytes", NETXEN_NIC_STAT(stats.rxbytes)}, | ||
79 | {"tx_bytes", NETXEN_NIC_STAT(stats.txbytes)}, | ||
80 | }; | ||
81 | |||
82 | #define NETXEN_NIC_STATS_LEN \ | ||
83 | sizeof(netxen_nic_gstrings_stats) / sizeof(struct netxen_nic_stats) | ||
84 | |||
85 | static const char netxen_nic_gstrings_test[][ETH_GSTRING_LEN] = { | ||
86 | "Register_Test_offline", "EEPROM_Test_offline", | ||
87 | "Interrupt_Test_offline", "Loopback_Test_offline", | ||
88 | "Link_Test_on_offline" | ||
89 | }; | ||
90 | |||
91 | #define NETXEN_NIC_TEST_LEN sizeof(netxen_nic_gstrings_test) / ETH_GSTRING_LEN | ||
92 | |||
93 | #define NETXEN_NIC_REGS_COUNT 42 | ||
94 | #define NETXEN_NIC_REGS_LEN (NETXEN_NIC_REGS_COUNT * sizeof(__le32)) | ||
95 | #define NETXEN_MAX_EEPROM_LEN 1024 | ||
96 | |||
97 | static int netxen_nic_get_eeprom_len(struct net_device *dev) | ||
98 | { | ||
99 | struct netxen_port *port = netdev_priv(dev); | ||
100 | struct netxen_adapter *adapter = port->adapter; | ||
101 | int n; | ||
102 | |||
103 | if ((netxen_rom_fast_read(adapter, 0, &n) == 0) | ||
104 | && (n & NETXEN_ROM_ROUNDUP)) { | ||
105 | n &= ~NETXEN_ROM_ROUNDUP; | ||
106 | if (n < NETXEN_MAX_EEPROM_LEN) | ||
107 | return n; | ||
108 | } | ||
109 | return 0; | ||
110 | } | ||
111 | |||
112 | static void | ||
113 | netxen_nic_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *drvinfo) | ||
114 | { | ||
115 | struct netxen_port *port = netdev_priv(dev); | ||
116 | struct netxen_adapter *adapter = port->adapter; | ||
117 | u32 fw_major = 0; | ||
118 | u32 fw_minor = 0; | ||
119 | u32 fw_build = 0; | ||
120 | |||
121 | strncpy(drvinfo->driver, "netxen_nic", 32); | ||
122 | strncpy(drvinfo->version, NETXEN_NIC_LINUX_VERSIONID, 32); | ||
123 | fw_major = readl(NETXEN_CRB_NORMALIZE(adapter, | ||
124 | NETXEN_FW_VERSION_MAJOR)); | ||
125 | fw_minor = readl(NETXEN_CRB_NORMALIZE(adapter, | ||
126 | NETXEN_FW_VERSION_MINOR)); | ||
127 | fw_build = readl(NETXEN_CRB_NORMALIZE(adapter, NETXEN_FW_VERSION_SUB)); | ||
128 | sprintf(drvinfo->fw_version, "%d.%d.%d", fw_major, fw_minor, fw_build); | ||
129 | |||
130 | strncpy(drvinfo->bus_info, pci_name(port->pdev), 32); | ||
131 | drvinfo->n_stats = NETXEN_NIC_STATS_LEN; | ||
132 | drvinfo->testinfo_len = NETXEN_NIC_TEST_LEN; | ||
133 | drvinfo->regdump_len = NETXEN_NIC_REGS_LEN; | ||
134 | drvinfo->eedump_len = netxen_nic_get_eeprom_len(dev); | ||
135 | } | ||
136 | |||
137 | static int | ||
138 | netxen_nic_get_settings(struct net_device *dev, struct ethtool_cmd *ecmd) | ||
139 | { | ||
140 | struct netxen_port *port = netdev_priv(dev); | ||
141 | struct netxen_adapter *adapter = port->adapter; | ||
142 | struct netxen_board_info *boardinfo = &adapter->ahw.boardcfg; | ||
143 | |||
144 | /* read which mode */ | ||
145 | if (adapter->ahw.board_type == NETXEN_NIC_GBE) { | ||
146 | ecmd->supported = (SUPPORTED_10baseT_Half | | ||
147 | SUPPORTED_10baseT_Full | | ||
148 | SUPPORTED_100baseT_Half | | ||
149 | SUPPORTED_100baseT_Full | | ||
150 | SUPPORTED_1000baseT_Half | | ||
151 | SUPPORTED_1000baseT_Full); | ||
152 | |||
153 | ecmd->advertising = (ADVERTISED_100baseT_Half | | ||
154 | ADVERTISED_100baseT_Full | | ||
155 | ADVERTISED_1000baseT_Half | | ||
156 | ADVERTISED_1000baseT_Full); | ||
157 | |||
158 | ecmd->port = PORT_TP; | ||
159 | |||
160 | if (netif_running(dev)) { | ||
161 | ecmd->speed = port->link_speed; | ||
162 | ecmd->duplex = port->link_duplex; | ||
163 | } else | ||
164 | return -EIO; /* link absent */ | ||
165 | } else if (adapter->ahw.board_type == NETXEN_NIC_XGBE) { | ||
166 | ecmd->supported = (SUPPORTED_TP | | ||
167 | SUPPORTED_1000baseT_Full | | ||
168 | SUPPORTED_10000baseT_Full); | ||
169 | ecmd->advertising = (ADVERTISED_TP | | ||
170 | ADVERTISED_1000baseT_Full | | ||
171 | ADVERTISED_10000baseT_Full); | ||
172 | ecmd->port = PORT_TP; | ||
173 | |||
174 | ecmd->speed = SPEED_10000; | ||
175 | ecmd->duplex = DUPLEX_FULL; | ||
176 | ecmd->autoneg = AUTONEG_DISABLE; | ||
177 | } else | ||
178 | return -EIO; | ||
179 | |||
180 | ecmd->phy_address = port->portnum; | ||
181 | ecmd->transceiver = XCVR_EXTERNAL; | ||
182 | |||
183 | switch ((netxen_brdtype_t) boardinfo->board_type) { | ||
184 | case NETXEN_BRDTYPE_P2_SB35_4G: | ||
185 | case NETXEN_BRDTYPE_P2_SB31_2G: | ||
186 | ecmd->supported |= SUPPORTED_Autoneg; | ||
187 | ecmd->advertising |= ADVERTISED_Autoneg; | ||
188 | case NETXEN_BRDTYPE_P2_SB31_10G_CX4: | ||
189 | ecmd->supported |= SUPPORTED_TP; | ||
190 | ecmd->advertising |= ADVERTISED_TP; | ||
191 | ecmd->port = PORT_TP; | ||
192 | ecmd->autoneg = (boardinfo->board_type == | ||
193 | NETXEN_BRDTYPE_P2_SB31_10G_CX4) ? | ||
194 | (AUTONEG_DISABLE) : (port->link_autoneg); | ||
195 | break; | ||
196 | case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ: | ||
197 | case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ: | ||
198 | ecmd->supported |= SUPPORTED_MII; | ||
199 | ecmd->advertising |= ADVERTISED_MII; | ||
200 | ecmd->port = PORT_FIBRE; | ||
201 | ecmd->autoneg = AUTONEG_DISABLE; | ||
202 | break; | ||
203 | case NETXEN_BRDTYPE_P2_SB31_10G: | ||
204 | ecmd->supported |= SUPPORTED_FIBRE; | ||
205 | ecmd->advertising |= ADVERTISED_FIBRE; | ||
206 | ecmd->port = PORT_FIBRE; | ||
207 | ecmd->autoneg = AUTONEG_DISABLE; | ||
208 | break; | ||
209 | default: | ||
210 | printk(KERN_ERR "netxen-nic: Unsupported board model %d\n", | ||
211 | (netxen_brdtype_t) boardinfo->board_type); | ||
212 | return -EIO; | ||
213 | |||
214 | } | ||
215 | |||
216 | return 0; | ||
217 | } | ||
218 | |||
219 | static int | ||
220 | netxen_nic_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd) | ||
221 | { | ||
222 | struct netxen_port *port = netdev_priv(dev); | ||
223 | struct netxen_adapter *adapter = port->adapter; | ||
224 | __le32 status; | ||
225 | |||
226 | /* read which mode */ | ||
227 | if (adapter->ahw.board_type == NETXEN_NIC_GBE) { | ||
228 | /* autonegotiation */ | ||
229 | if (adapter->ops->phy_write | ||
230 | && adapter->ops->phy_write(adapter, port->portnum, | ||
231 | NETXEN_NIU_GB_MII_MGMT_ADDR_AUTONEG, | ||
232 | (__le32) ecmd->autoneg) != 0) | ||
233 | return -EIO; | ||
234 | else | ||
235 | port->link_autoneg = ecmd->autoneg; | ||
236 | |||
237 | if (adapter->ops->phy_read | ||
238 | && adapter->ops->phy_read(adapter, port->portnum, | ||
239 | NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS, | ||
240 | &status) != 0) | ||
241 | return -EIO; | ||
242 | |||
243 | /* speed */ | ||
244 | switch (ecmd->speed) { | ||
245 | case SPEED_10: | ||
246 | netxen_set_phy_speed(status, 0); | ||
247 | break; | ||
248 | case SPEED_100: | ||
249 | netxen_set_phy_speed(status, 1); | ||
250 | break; | ||
251 | case SPEED_1000: | ||
252 | netxen_set_phy_speed(status, 2); | ||
253 | break; | ||
254 | } | ||
255 | /* set duplex mode */ | ||
256 | if (ecmd->duplex == DUPLEX_HALF) | ||
257 | netxen_clear_phy_duplex(status); | ||
258 | if (ecmd->duplex == DUPLEX_FULL) | ||
259 | netxen_set_phy_duplex(status); | ||
260 | if (adapter->ops->phy_write | ||
261 | && adapter->ops->phy_write(adapter, port->portnum, | ||
262 | NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS, | ||
263 | *((int *)&status)) != 0) | ||
264 | return -EIO; | ||
265 | else { | ||
266 | port->link_speed = ecmd->speed; | ||
267 | port->link_duplex = ecmd->duplex; | ||
268 | } | ||
269 | } else | ||
270 | return -EOPNOTSUPP; | ||
271 | |||
272 | if (netif_running(dev)) { | ||
273 | dev->stop(dev); | ||
274 | dev->open(dev); | ||
275 | } | ||
276 | return 0; | ||
277 | } | ||
278 | |||
279 | static int netxen_nic_get_regs_len(struct net_device *dev) | ||
280 | { | ||
281 | return NETXEN_NIC_REGS_LEN; | ||
282 | } | ||
283 | |||
284 | struct netxen_niu_regs { | ||
285 | __le32 reg[NETXEN_NIC_REGS_COUNT]; | ||
286 | }; | ||
287 | |||
288 | static struct netxen_niu_regs niu_registers[] = { | ||
289 | { | ||
290 | /* GB Mode */ | ||
291 | { | ||
292 | NETXEN_NIU_GB_SERDES_RESET, | ||
293 | NETXEN_NIU_GB0_MII_MODE, | ||
294 | NETXEN_NIU_GB1_MII_MODE, | ||
295 | NETXEN_NIU_GB2_MII_MODE, | ||
296 | NETXEN_NIU_GB3_MII_MODE, | ||
297 | NETXEN_NIU_GB0_GMII_MODE, | ||
298 | NETXEN_NIU_GB1_GMII_MODE, | ||
299 | NETXEN_NIU_GB2_GMII_MODE, | ||
300 | NETXEN_NIU_GB3_GMII_MODE, | ||
301 | NETXEN_NIU_REMOTE_LOOPBACK, | ||
302 | NETXEN_NIU_GB0_HALF_DUPLEX, | ||
303 | NETXEN_NIU_GB1_HALF_DUPLEX, | ||
304 | NETXEN_NIU_RESET_SYS_FIFOS, | ||
305 | NETXEN_NIU_GB_CRC_DROP, | ||
306 | NETXEN_NIU_GB_DROP_WRONGADDR, | ||
307 | NETXEN_NIU_TEST_MUX_CTL, | ||
308 | |||
309 | NETXEN_NIU_GB_MAC_CONFIG_0(0), | ||
310 | NETXEN_NIU_GB_MAC_CONFIG_1(0), | ||
311 | NETXEN_NIU_GB_HALF_DUPLEX_CTRL(0), | ||
312 | NETXEN_NIU_GB_MAX_FRAME_SIZE(0), | ||
313 | NETXEN_NIU_GB_TEST_REG(0), | ||
314 | NETXEN_NIU_GB_MII_MGMT_CONFIG(0), | ||
315 | NETXEN_NIU_GB_MII_MGMT_COMMAND(0), | ||
316 | NETXEN_NIU_GB_MII_MGMT_ADDR(0), | ||
317 | NETXEN_NIU_GB_MII_MGMT_CTRL(0), | ||
318 | NETXEN_NIU_GB_MII_MGMT_STATUS(0), | ||
319 | NETXEN_NIU_GB_MII_MGMT_INDICATE(0), | ||
320 | NETXEN_NIU_GB_INTERFACE_CTRL(0), | ||
321 | NETXEN_NIU_GB_INTERFACE_STATUS(0), | ||
322 | NETXEN_NIU_GB_STATION_ADDR_0(0), | ||
323 | NETXEN_NIU_GB_STATION_ADDR_1(0), | ||
324 | -1, | ||
325 | } | ||
326 | }, | ||
327 | { | ||
328 | /* XG Mode */ | ||
329 | { | ||
330 | NETXEN_NIU_XG_SINGLE_TERM, | ||
331 | NETXEN_NIU_XG_DRIVE_HI, | ||
332 | NETXEN_NIU_XG_DRIVE_LO, | ||
333 | NETXEN_NIU_XG_DTX, | ||
334 | NETXEN_NIU_XG_DEQ, | ||
335 | NETXEN_NIU_XG_WORD_ALIGN, | ||
336 | NETXEN_NIU_XG_RESET, | ||
337 | NETXEN_NIU_XG_POWER_DOWN, | ||
338 | NETXEN_NIU_XG_RESET_PLL, | ||
339 | NETXEN_NIU_XG_SERDES_LOOPBACK, | ||
340 | NETXEN_NIU_XG_DO_BYTE_ALIGN, | ||
341 | NETXEN_NIU_XG_TX_ENABLE, | ||
342 | NETXEN_NIU_XG_RX_ENABLE, | ||
343 | NETXEN_NIU_XG_STATUS, | ||
344 | NETXEN_NIU_XG_PAUSE_THRESHOLD, | ||
345 | NETXEN_NIU_XGE_CONFIG_0, | ||
346 | NETXEN_NIU_XGE_CONFIG_1, | ||
347 | NETXEN_NIU_XGE_IPG, | ||
348 | NETXEN_NIU_XGE_STATION_ADDR_0_HI, | ||
349 | NETXEN_NIU_XGE_STATION_ADDR_0_1, | ||
350 | NETXEN_NIU_XGE_STATION_ADDR_1_LO, | ||
351 | NETXEN_NIU_XGE_STATUS, | ||
352 | NETXEN_NIU_XGE_MAX_FRAME_SIZE, | ||
353 | NETXEN_NIU_XGE_PAUSE_FRAME_VALUE, | ||
354 | NETXEN_NIU_XGE_TX_BYTE_CNT, | ||
355 | NETXEN_NIU_XGE_TX_FRAME_CNT, | ||
356 | NETXEN_NIU_XGE_RX_BYTE_CNT, | ||
357 | NETXEN_NIU_XGE_RX_FRAME_CNT, | ||
358 | NETXEN_NIU_XGE_AGGR_ERROR_CNT, | ||
359 | NETXEN_NIU_XGE_MULTICAST_FRAME_CNT, | ||
360 | NETXEN_NIU_XGE_UNICAST_FRAME_CNT, | ||
361 | NETXEN_NIU_XGE_CRC_ERROR_CNT, | ||
362 | NETXEN_NIU_XGE_OVERSIZE_FRAME_ERR, | ||
363 | NETXEN_NIU_XGE_UNDERSIZE_FRAME_ERR, | ||
364 | NETXEN_NIU_XGE_LOCAL_ERROR_CNT, | ||
365 | NETXEN_NIU_XGE_REMOTE_ERROR_CNT, | ||
366 | NETXEN_NIU_XGE_CONTROL_CHAR_CNT, | ||
367 | NETXEN_NIU_XGE_PAUSE_FRAME_CNT, | ||
368 | -1, | ||
369 | } | ||
370 | } | ||
371 | }; | ||
372 | |||
373 | static void | ||
374 | netxen_nic_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *p) | ||
375 | { | ||
376 | struct netxen_port *port = netdev_priv(dev); | ||
377 | struct netxen_adapter *adapter = port->adapter; | ||
378 | __le32 mode, *regs_buff = p; | ||
379 | void __iomem *addr; | ||
380 | int i, window; | ||
381 | |||
382 | memset(p, 0, NETXEN_NIC_REGS_LEN); | ||
383 | regs->version = (1 << 24) | (adapter->ahw.revision_id << 16) | | ||
384 | (port->pdev)->device; | ||
385 | /* which mode */ | ||
386 | NETXEN_NIC_LOCKED_READ_REG(NETXEN_NIU_MODE, ®s_buff[0]); | ||
387 | mode = regs_buff[0]; | ||
388 | |||
389 | /* Common registers to all the modes */ | ||
390 | NETXEN_NIC_LOCKED_READ_REG(NETXEN_NIU_STRAP_VALUE_SAVE_HIGHER, | ||
391 | ®s_buff[2]); | ||
392 | /* GB/XGB Mode */ | ||
393 | mode = (mode / 2) - 1; | ||
394 | window = 0; | ||
395 | if (mode <= 1) { | ||
396 | for (i = 3; niu_registers[mode].reg[i - 3] != -1; i++) { | ||
397 | /* GB: port specific registers */ | ||
398 | if (mode == 0 && i >= 19) | ||
399 | window = port->portnum * NETXEN_NIC_PORT_WINDOW; | ||
400 | |||
401 | NETXEN_NIC_LOCKED_READ_REG(niu_registers[mode]. | ||
402 | reg[i - 3] + window, | ||
403 | ®s_buff[i]); | ||
404 | } | ||
405 | |||
406 | } | ||
407 | } | ||
408 | |||
409 | static void | ||
410 | netxen_nic_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) | ||
411 | { | ||
412 | wol->supported = WAKE_UCAST | WAKE_MCAST | WAKE_BCAST | WAKE_MAGIC; | ||
413 | /* options can be added depending upon the mode */ | ||
414 | wol->wolopts = 0; | ||
415 | } | ||
416 | |||
417 | static u32 netxen_nic_get_link(struct net_device *dev) | ||
418 | { | ||
419 | struct netxen_port *port = netdev_priv(dev); | ||
420 | struct netxen_adapter *adapter = port->adapter; | ||
421 | __le32 status; | ||
422 | |||
423 | /* read which mode */ | ||
424 | if (adapter->ahw.board_type == NETXEN_NIC_GBE) { | ||
425 | if (adapter->ops->phy_read | ||
426 | && adapter->ops->phy_read(adapter, port->portnum, | ||
427 | NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS, | ||
428 | &status) != 0) | ||
429 | return -EIO; | ||
430 | else | ||
431 | return (netxen_get_phy_link(status)); | ||
432 | } else if (adapter->ahw.board_type == NETXEN_NIC_XGBE) { | ||
433 | int val = readl(NETXEN_CRB_NORMALIZE(adapter, CRB_XG_STATE)); | ||
434 | return val == XG_LINK_UP; | ||
435 | } | ||
436 | return -EIO; | ||
437 | } | ||
438 | |||
439 | static int | ||
440 | netxen_nic_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, | ||
441 | u8 * bytes) | ||
442 | { | ||
443 | struct netxen_port *port = netdev_priv(dev); | ||
444 | struct netxen_adapter *adapter = port->adapter; | ||
445 | int offset; | ||
446 | |||
447 | if (eeprom->len == 0) | ||
448 | return -EINVAL; | ||
449 | |||
450 | eeprom->magic = (port->pdev)->vendor | ((port->pdev)->device << 16); | ||
451 | for (offset = 0; offset < eeprom->len; offset++) | ||
452 | if (netxen_rom_fast_read | ||
453 | (adapter, (8 * offset) + 8, (int *)eeprom->data) == -1) | ||
454 | return -EIO; | ||
455 | return 0; | ||
456 | } | ||
457 | |||
458 | static void | ||
459 | netxen_nic_get_ringparam(struct net_device *dev, struct ethtool_ringparam *ring) | ||
460 | { | ||
461 | struct netxen_port *port = netdev_priv(dev); | ||
462 | struct netxen_adapter *adapter = port->adapter; | ||
463 | int i, j; | ||
464 | |||
465 | ring->rx_pending = 0; | ||
466 | for (i = 0; i < MAX_RCV_CTX; ++i) { | ||
467 | for (j = 0; j < NUM_RCV_DESC_RINGS; j++) | ||
468 | ring->rx_pending += | ||
469 | adapter->recv_ctx[i].rcv_desc[j].rcv_pending; | ||
470 | } | ||
471 | |||
472 | ring->rx_max_pending = adapter->max_rx_desc_count; | ||
473 | ring->tx_max_pending = adapter->max_tx_desc_count; | ||
474 | ring->rx_mini_max_pending = 0; | ||
475 | ring->rx_mini_pending = 0; | ||
476 | ring->rx_jumbo_max_pending = 0; | ||
477 | ring->rx_jumbo_pending = 0; | ||
478 | } | ||
479 | |||
480 | static void | ||
481 | netxen_nic_get_pauseparam(struct net_device *dev, | ||
482 | struct ethtool_pauseparam *pause) | ||
483 | { | ||
484 | struct netxen_port *port = netdev_priv(dev); | ||
485 | struct netxen_adapter *adapter = port->adapter; | ||
486 | __le32 val; | ||
487 | |||
488 | if (adapter->ahw.board_type == NETXEN_NIC_GBE) { | ||
489 | /* get flow control settings */ | ||
490 | netxen_nic_read_w0(adapter, | ||
491 | NETXEN_NIU_GB_MAC_CONFIG_0(port->portnum), | ||
492 | (u32 *) & val); | ||
493 | pause->rx_pause = netxen_gb_get_rx_flowctl(val); | ||
494 | pause->tx_pause = netxen_gb_get_tx_flowctl(val); | ||
495 | /* get autoneg settings */ | ||
496 | pause->autoneg = port->link_autoneg; | ||
497 | } | ||
498 | } | ||
499 | |||
500 | static int | ||
501 | netxen_nic_set_pauseparam(struct net_device *dev, | ||
502 | struct ethtool_pauseparam *pause) | ||
503 | { | ||
504 | struct netxen_port *port = netdev_priv(dev); | ||
505 | struct netxen_adapter *adapter = port->adapter; | ||
506 | __le32 val; | ||
507 | unsigned int autoneg; | ||
508 | |||
509 | /* read mode */ | ||
510 | if (adapter->ahw.board_type == NETXEN_NIC_GBE) { | ||
511 | /* set flow control */ | ||
512 | netxen_nic_read_w0(adapter, | ||
513 | NETXEN_NIU_GB_MAC_CONFIG_0(port->portnum), | ||
514 | (u32 *) & val); | ||
515 | if (pause->tx_pause) | ||
516 | netxen_gb_tx_flowctl(val); | ||
517 | else | ||
518 | netxen_gb_unset_tx_flowctl(val); | ||
519 | if (pause->rx_pause) | ||
520 | netxen_gb_rx_flowctl(val); | ||
521 | else | ||
522 | netxen_gb_unset_rx_flowctl(val); | ||
523 | |||
524 | netxen_nic_write_w0(adapter, | ||
525 | NETXEN_NIU_GB_MAC_CONFIG_0(port->portnum), | ||
526 | *(u32 *) (&val)); | ||
527 | /* set autoneg */ | ||
528 | autoneg = pause->autoneg; | ||
529 | if (adapter->ops->phy_write | ||
530 | && adapter->ops->phy_write(adapter, port->portnum, | ||
531 | NETXEN_NIU_GB_MII_MGMT_ADDR_AUTONEG, | ||
532 | (__le32) autoneg) != 0) | ||
533 | return -EIO; | ||
534 | else { | ||
535 | port->link_autoneg = pause->autoneg; | ||
536 | return 0; | ||
537 | } | ||
538 | } else | ||
539 | return -EOPNOTSUPP; | ||
540 | } | ||
541 | |||
542 | static int netxen_nic_reg_test(struct net_device *dev) | ||
543 | { | ||
544 | struct netxen_port *port = netdev_priv(dev); | ||
545 | struct netxen_adapter *adapter = port->adapter; | ||
546 | u32 data_read, data_written, save; | ||
547 | __le32 mode; | ||
548 | |||
549 | /* | ||
550 | * first test the "Read Only" registers by writing which mode | ||
551 | */ | ||
552 | netxen_nic_read_w0(adapter, NETXEN_NIU_MODE, &mode); | ||
553 | if (netxen_get_niu_enable_ge(mode)) { /* GB Mode */ | ||
554 | netxen_nic_read_w0(adapter, | ||
555 | NETXEN_NIU_GB_MII_MGMT_STATUS(port->portnum), | ||
556 | &data_read); | ||
557 | |||
558 | save = data_read; | ||
559 | if (data_read) | ||
560 | data_written = data_read & NETXEN_NIC_INVALID_DATA; | ||
561 | else | ||
562 | data_written = NETXEN_NIC_INVALID_DATA; | ||
563 | netxen_nic_write_w0(adapter, | ||
564 | NETXEN_NIU_GB_MII_MGMT_STATUS(port-> | ||
565 | portnum), | ||
566 | data_written); | ||
567 | netxen_nic_read_w0(adapter, | ||
568 | NETXEN_NIU_GB_MII_MGMT_STATUS(port->portnum), | ||
569 | &data_read); | ||
570 | |||
571 | if (data_written == data_read) { | ||
572 | netxen_nic_write_w0(adapter, | ||
573 | NETXEN_NIU_GB_MII_MGMT_STATUS(port-> | ||
574 | portnum), | ||
575 | save); | ||
576 | |||
577 | return 0; | ||
578 | } | ||
579 | |||
580 | /* netxen_niu_gb_mii_mgmt_indicators is read only */ | ||
581 | netxen_nic_read_w0(adapter, | ||
582 | NETXEN_NIU_GB_MII_MGMT_INDICATE(port-> | ||
583 | portnum), | ||
584 | &data_read); | ||
585 | |||
586 | save = data_read; | ||
587 | if (data_read) | ||
588 | data_written = data_read & NETXEN_NIC_INVALID_DATA; | ||
589 | else | ||
590 | data_written = NETXEN_NIC_INVALID_DATA; | ||
591 | netxen_nic_write_w0(adapter, | ||
592 | NETXEN_NIU_GB_MII_MGMT_INDICATE(port-> | ||
593 | portnum), | ||
594 | data_written); | ||
595 | |||
596 | netxen_nic_read_w0(adapter, | ||
597 | NETXEN_NIU_GB_MII_MGMT_INDICATE(port-> | ||
598 | portnum), | ||
599 | &data_read); | ||
600 | |||
601 | if (data_written == data_read) { | ||
602 | netxen_nic_write_w0(adapter, | ||
603 | NETXEN_NIU_GB_MII_MGMT_INDICATE | ||
604 | (port->portnum), save); | ||
605 | return 0; | ||
606 | } | ||
607 | |||
608 | /* netxen_niu_gb_interface_status is read only */ | ||
609 | netxen_nic_read_w0(adapter, | ||
610 | NETXEN_NIU_GB_INTERFACE_STATUS(port-> | ||
611 | portnum), | ||
612 | &data_read); | ||
613 | |||
614 | save = data_read; | ||
615 | if (data_read) | ||
616 | data_written = data_read & NETXEN_NIC_INVALID_DATA; | ||
617 | else | ||
618 | data_written = NETXEN_NIC_INVALID_DATA; | ||
619 | netxen_nic_write_w0(adapter, | ||
620 | NETXEN_NIU_GB_INTERFACE_STATUS(port-> | ||
621 | portnum), | ||
622 | data_written); | ||
623 | |||
624 | netxen_nic_read_w0(adapter, | ||
625 | NETXEN_NIU_GB_INTERFACE_STATUS(port-> | ||
626 | portnum), | ||
627 | &data_read); | ||
628 | |||
629 | if (data_written == data_read) { | ||
630 | netxen_nic_write_w0(adapter, | ||
631 | NETXEN_NIU_GB_INTERFACE_STATUS | ||
632 | (port->portnum), save); | ||
633 | |||
634 | return 0; | ||
635 | } | ||
636 | } /* GB Mode */ | ||
637 | return 1; | ||
638 | } | ||
639 | |||
640 | static int netxen_nic_diag_test_count(struct net_device *dev) | ||
641 | { | ||
642 | return NETXEN_NIC_TEST_LEN; | ||
643 | } | ||
644 | |||
645 | static void | ||
646 | netxen_nic_diag_test(struct net_device *dev, struct ethtool_test *eth_test, | ||
647 | u64 * data) | ||
648 | { | ||
649 | if (eth_test->flags == ETH_TEST_FL_OFFLINE) { /* offline tests */ | ||
650 | /* link test */ | ||
651 | if (!(data[4] = (u64) netxen_nic_get_link(dev))) | ||
652 | eth_test->flags |= ETH_TEST_FL_FAILED; | ||
653 | |||
654 | if (netif_running(dev)) | ||
655 | dev->stop(dev); | ||
656 | |||
657 | /* register tests */ | ||
658 | if (!(data[0] = netxen_nic_reg_test(dev))) | ||
659 | eth_test->flags |= ETH_TEST_FL_FAILED; | ||
660 | /* other tests pass as of now */ | ||
661 | data[1] = data[2] = data[3] = 1; | ||
662 | if (netif_running(dev)) | ||
663 | dev->open(dev); | ||
664 | } else { /* online tests */ | ||
665 | /* link test */ | ||
666 | if (!(data[4] = (u64) netxen_nic_get_link(dev))) | ||
667 | eth_test->flags |= ETH_TEST_FL_FAILED; | ||
668 | |||
669 | /* other tests pass by default */ | ||
670 | data[0] = data[1] = data[2] = data[3] = 1; | ||
671 | } | ||
672 | } | ||
673 | |||
674 | static void | ||
675 | netxen_nic_get_strings(struct net_device *dev, u32 stringset, u8 * data) | ||
676 | { | ||
677 | int index; | ||
678 | |||
679 | switch (stringset) { | ||
680 | case ETH_SS_TEST: | ||
681 | memcpy(data, *netxen_nic_gstrings_test, | ||
682 | NETXEN_NIC_TEST_LEN * ETH_GSTRING_LEN); | ||
683 | break; | ||
684 | case ETH_SS_STATS: | ||
685 | for (index = 0; index < NETXEN_NIC_STATS_LEN; index++) { | ||
686 | memcpy(data + index * ETH_GSTRING_LEN, | ||
687 | netxen_nic_gstrings_stats[index].stat_string, | ||
688 | ETH_GSTRING_LEN); | ||
689 | } | ||
690 | break; | ||
691 | } | ||
692 | } | ||
693 | |||
694 | static int netxen_nic_get_stats_count(struct net_device *dev) | ||
695 | { | ||
696 | return NETXEN_NIC_STATS_LEN; | ||
697 | } | ||
698 | |||
699 | static void | ||
700 | netxen_nic_get_ethtool_stats(struct net_device *dev, | ||
701 | struct ethtool_stats *stats, u64 * data) | ||
702 | { | ||
703 | struct netxen_port *port = netdev_priv(dev); | ||
704 | int index; | ||
705 | |||
706 | for (index = 0; index < NETXEN_NIC_STATS_LEN; index++) { | ||
707 | char *p = | ||
708 | (char *)port + netxen_nic_gstrings_stats[index].stat_offset; | ||
709 | data[index] = | ||
710 | (netxen_nic_gstrings_stats[index].sizeof_stat == | ||
711 | sizeof(u64)) ? *(u64 *) p : *(u32 *) p; | ||
712 | } | ||
713 | |||
714 | } | ||
715 | |||
716 | struct ethtool_ops netxen_nic_ethtool_ops = { | ||
717 | .get_settings = netxen_nic_get_settings, | ||
718 | .set_settings = netxen_nic_set_settings, | ||
719 | .get_drvinfo = netxen_nic_get_drvinfo, | ||
720 | .get_regs_len = netxen_nic_get_regs_len, | ||
721 | .get_regs = netxen_nic_get_regs, | ||
722 | .get_wol = netxen_nic_get_wol, | ||
723 | .get_link = netxen_nic_get_link, | ||
724 | .get_eeprom_len = netxen_nic_get_eeprom_len, | ||
725 | .get_eeprom = netxen_nic_get_eeprom, | ||
726 | .get_ringparam = netxen_nic_get_ringparam, | ||
727 | .get_pauseparam = netxen_nic_get_pauseparam, | ||
728 | .set_pauseparam = netxen_nic_set_pauseparam, | ||
729 | .get_tx_csum = ethtool_op_get_tx_csum, | ||
730 | .set_tx_csum = ethtool_op_set_tx_csum, | ||
731 | .get_sg = ethtool_op_get_sg, | ||
732 | .set_sg = ethtool_op_set_sg, | ||
733 | .get_tso = ethtool_op_get_tso, | ||
734 | .set_tso = ethtool_op_set_tso, | ||
735 | .self_test_count = netxen_nic_diag_test_count, | ||
736 | .self_test = netxen_nic_diag_test, | ||
737 | .get_strings = netxen_nic_get_strings, | ||
738 | .get_stats_count = netxen_nic_get_stats_count, | ||
739 | .get_ethtool_stats = netxen_nic_get_ethtool_stats, | ||
740 | .get_perm_addr = ethtool_op_get_perm_addr, | ||
741 | }; | ||
diff --git a/drivers/net/netxen/netxen_nic_hdr.h b/drivers/net/netxen/netxen_nic_hdr.h new file mode 100644 index 000000000000..72c6ec4ee2a0 --- /dev/null +++ b/drivers/net/netxen/netxen_nic_hdr.h | |||
@@ -0,0 +1,678 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2003 - 2006 NetXen, Inc. | ||
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 LICENSE. | ||
22 | * | ||
23 | * Contact Information: | ||
24 | * info@netxen.com | ||
25 | * NetXen, | ||
26 | * 3965 Freedom Circle, Fourth floor, | ||
27 | * Santa Clara, CA 95054 | ||
28 | */ | ||
29 | |||
30 | #ifndef __NETXEN_NIC_HDR_H_ | ||
31 | #define __NETXEN_NIC_HDR_H_ | ||
32 | |||
33 | #include <linux/module.h> | ||
34 | #include <linux/kernel.h> | ||
35 | #include <linux/version.h> | ||
36 | |||
37 | #include <asm/semaphore.h> | ||
38 | #include <linux/spinlock.h> | ||
39 | #include <asm/irq.h> | ||
40 | #include <linux/init.h> | ||
41 | #include <linux/errno.h> | ||
42 | #include <linux/pci.h> | ||
43 | #include <linux/types.h> | ||
44 | #include <asm/uaccess.h> | ||
45 | #include <asm/string.h> /* for memset */ | ||
46 | |||
47 | /* | ||
48 | * The basic unit of access when reading/writing control registers. | ||
49 | */ | ||
50 | |||
51 | typedef __le32 netxen_crbword_t; /* single word in CRB space */ | ||
52 | |||
53 | enum { | ||
54 | NETXEN_HW_H0_CH_HUB_ADR = 0x05, | ||
55 | NETXEN_HW_H1_CH_HUB_ADR = 0x0E, | ||
56 | NETXEN_HW_H2_CH_HUB_ADR = 0x03, | ||
57 | NETXEN_HW_H3_CH_HUB_ADR = 0x01, | ||
58 | NETXEN_HW_H4_CH_HUB_ADR = 0x06, | ||
59 | NETXEN_HW_H5_CH_HUB_ADR = 0x07, | ||
60 | NETXEN_HW_H6_CH_HUB_ADR = 0x08 | ||
61 | }; | ||
62 | |||
63 | /* Hub 0 */ | ||
64 | enum { | ||
65 | NETXEN_HW_MN_CRB_AGT_ADR = 0x15, | ||
66 | NETXEN_HW_MS_CRB_AGT_ADR = 0x25 | ||
67 | }; | ||
68 | |||
69 | /* Hub 1 */ | ||
70 | enum { | ||
71 | NETXEN_HW_PS_CRB_AGT_ADR = 0x73, | ||
72 | NETXEN_HW_SS_CRB_AGT_ADR = 0x20, | ||
73 | NETXEN_HW_RPMX3_CRB_AGT_ADR = 0x0b, | ||
74 | NETXEN_HW_QMS_CRB_AGT_ADR = 0x00, | ||
75 | NETXEN_HW_SQGS0_CRB_AGT_ADR = 0x01, | ||
76 | NETXEN_HW_SQGS1_CRB_AGT_ADR = 0x02, | ||
77 | NETXEN_HW_SQGS2_CRB_AGT_ADR = 0x03, | ||
78 | NETXEN_HW_SQGS3_CRB_AGT_ADR = 0x04, | ||
79 | NETXEN_HW_C2C0_CRB_AGT_ADR = 0x58, | ||
80 | NETXEN_HW_C2C1_CRB_AGT_ADR = 0x59, | ||
81 | NETXEN_HW_C2C2_CRB_AGT_ADR = 0x5a, | ||
82 | NETXEN_HW_RPMX2_CRB_AGT_ADR = 0x0a, | ||
83 | NETXEN_HW_RPMX4_CRB_AGT_ADR = 0x0c, | ||
84 | NETXEN_HW_RPMX7_CRB_AGT_ADR = 0x0f, | ||
85 | NETXEN_HW_RPMX9_CRB_AGT_ADR = 0x12, | ||
86 | NETXEN_HW_SMB_CRB_AGT_ADR = 0x18 | ||
87 | }; | ||
88 | |||
89 | /* Hub 2 */ | ||
90 | enum { | ||
91 | NETXEN_HW_NIU_CRB_AGT_ADR = 0x31, | ||
92 | NETXEN_HW_I2C0_CRB_AGT_ADR = 0x19, | ||
93 | NETXEN_HW_I2C1_CRB_AGT_ADR = 0x29, | ||
94 | |||
95 | NETXEN_HW_SN_CRB_AGT_ADR = 0x10, | ||
96 | NETXEN_HW_I2Q_CRB_AGT_ADR = 0x20, | ||
97 | NETXEN_HW_LPC_CRB_AGT_ADR = 0x22, | ||
98 | NETXEN_HW_ROMUSB_CRB_AGT_ADR = 0x21, | ||
99 | NETXEN_HW_QM_CRB_AGT_ADR = 0x66, | ||
100 | NETXEN_HW_SQG0_CRB_AGT_ADR = 0x60, | ||
101 | NETXEN_HW_SQG1_CRB_AGT_ADR = 0x61, | ||
102 | NETXEN_HW_SQG2_CRB_AGT_ADR = 0x62, | ||
103 | NETXEN_HW_SQG3_CRB_AGT_ADR = 0x63, | ||
104 | NETXEN_HW_RPMX1_CRB_AGT_ADR = 0x09, | ||
105 | NETXEN_HW_RPMX5_CRB_AGT_ADR = 0x0d, | ||
106 | NETXEN_HW_RPMX6_CRB_AGT_ADR = 0x0e, | ||
107 | NETXEN_HW_RPMX8_CRB_AGT_ADR = 0x11 | ||
108 | }; | ||
109 | |||
110 | /* Hub 3 */ | ||
111 | enum { | ||
112 | NETXEN_HW_PH_CRB_AGT_ADR = 0x1A, | ||
113 | NETXEN_HW_SRE_CRB_AGT_ADR = 0x50, | ||
114 | NETXEN_HW_EG_CRB_AGT_ADR = 0x51, | ||
115 | NETXEN_HW_RPMX0_CRB_AGT_ADR = 0x08 | ||
116 | }; | ||
117 | |||
118 | /* Hub 4 */ | ||
119 | enum { | ||
120 | NETXEN_HW_PEGN0_CRB_AGT_ADR = 0x40, | ||
121 | NETXEN_HW_PEGN1_CRB_AGT_ADR, | ||
122 | NETXEN_HW_PEGN2_CRB_AGT_ADR, | ||
123 | NETXEN_HW_PEGN3_CRB_AGT_ADR, | ||
124 | NETXEN_HW_PEGNI_CRB_AGT_ADR, | ||
125 | NETXEN_HW_PEGND_CRB_AGT_ADR, | ||
126 | NETXEN_HW_PEGNC_CRB_AGT_ADR, | ||
127 | NETXEN_HW_PEGR0_CRB_AGT_ADR, | ||
128 | NETXEN_HW_PEGR1_CRB_AGT_ADR, | ||
129 | NETXEN_HW_PEGR2_CRB_AGT_ADR, | ||
130 | NETXEN_HW_PEGR3_CRB_AGT_ADR | ||
131 | }; | ||
132 | |||
133 | /* Hub 5 */ | ||
134 | enum { | ||
135 | NETXEN_HW_PEGS0_CRB_AGT_ADR = 0x40, | ||
136 | NETXEN_HW_PEGS1_CRB_AGT_ADR, | ||
137 | NETXEN_HW_PEGS2_CRB_AGT_ADR, | ||
138 | NETXEN_HW_PEGS3_CRB_AGT_ADR, | ||
139 | NETXEN_HW_PEGSI_CRB_AGT_ADR, | ||
140 | NETXEN_HW_PEGSD_CRB_AGT_ADR, | ||
141 | NETXEN_HW_PEGSC_CRB_AGT_ADR | ||
142 | }; | ||
143 | |||
144 | /* Hub 6 */ | ||
145 | enum { | ||
146 | NETXEN_HW_CAS0_CRB_AGT_ADR = 0x46, | ||
147 | NETXEN_HW_CAS1_CRB_AGT_ADR = 0x47, | ||
148 | NETXEN_HW_CAS2_CRB_AGT_ADR = 0x48, | ||
149 | NETXEN_HW_CAS3_CRB_AGT_ADR = 0x49, | ||
150 | NETXEN_HW_NCM_CRB_AGT_ADR = 0x16, | ||
151 | NETXEN_HW_TMR_CRB_AGT_ADR = 0x17, | ||
152 | NETXEN_HW_XDMA_CRB_AGT_ADR = 0x05, | ||
153 | NETXEN_HW_OCM0_CRB_AGT_ADR = 0x06, | ||
154 | NETXEN_HW_OCM1_CRB_AGT_ADR = 0x07 | ||
155 | }; | ||
156 | |||
157 | /* Floaters - non existent modules */ | ||
158 | #define NETXEN_HW_EFC_RPMX0_CRB_AGT_ADR 0x67 | ||
159 | |||
160 | /* This field defines PCI/X adr [25:20] of agents on the CRB */ | ||
161 | enum { | ||
162 | NETXEN_HW_PX_MAP_CRB_PH = 0, | ||
163 | NETXEN_HW_PX_MAP_CRB_PS, | ||
164 | NETXEN_HW_PX_MAP_CRB_MN, | ||
165 | NETXEN_HW_PX_MAP_CRB_MS, | ||
166 | NETXEN_HW_PX_MAP_CRB_PGR1, | ||
167 | NETXEN_HW_PX_MAP_CRB_SRE, | ||
168 | NETXEN_HW_PX_MAP_CRB_NIU, | ||
169 | NETXEN_HW_PX_MAP_CRB_QMN, | ||
170 | NETXEN_HW_PX_MAP_CRB_SQN0, | ||
171 | NETXEN_HW_PX_MAP_CRB_SQN1, | ||
172 | NETXEN_HW_PX_MAP_CRB_SQN2, | ||
173 | NETXEN_HW_PX_MAP_CRB_SQN3, | ||
174 | NETXEN_HW_PX_MAP_CRB_QMS, | ||
175 | NETXEN_HW_PX_MAP_CRB_SQS0, | ||
176 | NETXEN_HW_PX_MAP_CRB_SQS1, | ||
177 | NETXEN_HW_PX_MAP_CRB_SQS2, | ||
178 | NETXEN_HW_PX_MAP_CRB_SQS3, | ||
179 | NETXEN_HW_PX_MAP_CRB_PGN0, | ||
180 | NETXEN_HW_PX_MAP_CRB_PGN1, | ||
181 | NETXEN_HW_PX_MAP_CRB_PGN2, | ||
182 | NETXEN_HW_PX_MAP_CRB_PGN3, | ||
183 | NETXEN_HW_PX_MAP_CRB_PGND, | ||
184 | NETXEN_HW_PX_MAP_CRB_PGNI, | ||
185 | NETXEN_HW_PX_MAP_CRB_PGS0, | ||
186 | NETXEN_HW_PX_MAP_CRB_PGS1, | ||
187 | NETXEN_HW_PX_MAP_CRB_PGS2, | ||
188 | NETXEN_HW_PX_MAP_CRB_PGS3, | ||
189 | NETXEN_HW_PX_MAP_CRB_PGSD, | ||
190 | NETXEN_HW_PX_MAP_CRB_PGSI, | ||
191 | NETXEN_HW_PX_MAP_CRB_SN, | ||
192 | NETXEN_HW_PX_MAP_CRB_PGR2, | ||
193 | NETXEN_HW_PX_MAP_CRB_EG, | ||
194 | NETXEN_HW_PX_MAP_CRB_PH2, | ||
195 | NETXEN_HW_PX_MAP_CRB_PS2, | ||
196 | NETXEN_HW_PX_MAP_CRB_CAM, | ||
197 | NETXEN_HW_PX_MAP_CRB_CAS0, | ||
198 | NETXEN_HW_PX_MAP_CRB_CAS1, | ||
199 | NETXEN_HW_PX_MAP_CRB_CAS2, | ||
200 | NETXEN_HW_PX_MAP_CRB_C2C0, | ||
201 | NETXEN_HW_PX_MAP_CRB_C2C1, | ||
202 | NETXEN_HW_PX_MAP_CRB_TIMR, | ||
203 | NETXEN_HW_PX_MAP_CRB_PGR3, | ||
204 | NETXEN_HW_PX_MAP_CRB_RPMX1, | ||
205 | NETXEN_HW_PX_MAP_CRB_RPMX2, | ||
206 | NETXEN_HW_PX_MAP_CRB_RPMX3, | ||
207 | NETXEN_HW_PX_MAP_CRB_RPMX4, | ||
208 | NETXEN_HW_PX_MAP_CRB_RPMX5, | ||
209 | NETXEN_HW_PX_MAP_CRB_RPMX6, | ||
210 | NETXEN_HW_PX_MAP_CRB_RPMX7, | ||
211 | NETXEN_HW_PX_MAP_CRB_XDMA, | ||
212 | NETXEN_HW_PX_MAP_CRB_I2Q, | ||
213 | NETXEN_HW_PX_MAP_CRB_ROMUSB, | ||
214 | NETXEN_HW_PX_MAP_CRB_CAS3, | ||
215 | NETXEN_HW_PX_MAP_CRB_RPMX0, | ||
216 | NETXEN_HW_PX_MAP_CRB_RPMX8, | ||
217 | NETXEN_HW_PX_MAP_CRB_RPMX9, | ||
218 | NETXEN_HW_PX_MAP_CRB_OCM0, | ||
219 | NETXEN_HW_PX_MAP_CRB_OCM1, | ||
220 | NETXEN_HW_PX_MAP_CRB_SMB, | ||
221 | NETXEN_HW_PX_MAP_CRB_I2C0, | ||
222 | NETXEN_HW_PX_MAP_CRB_I2C1, | ||
223 | NETXEN_HW_PX_MAP_CRB_LPC, | ||
224 | NETXEN_HW_PX_MAP_CRB_PGNC, | ||
225 | NETXEN_HW_PX_MAP_CRB_PGR0 | ||
226 | }; | ||
227 | |||
228 | /* This field defines CRB adr [31:20] of the agents */ | ||
229 | |||
230 | #define NETXEN_HW_CRB_HUB_AGT_ADR_MN \ | ||
231 | ((NETXEN_HW_H0_CH_HUB_ADR << 7) | NETXEN_HW_MN_CRB_AGT_ADR) | ||
232 | #define NETXEN_HW_CRB_HUB_AGT_ADR_PH \ | ||
233 | ((NETXEN_HW_H0_CH_HUB_ADR << 7) | NETXEN_HW_PH_CRB_AGT_ADR) | ||
234 | #define NETXEN_HW_CRB_HUB_AGT_ADR_MS \ | ||
235 | ((NETXEN_HW_H0_CH_HUB_ADR << 7) | NETXEN_HW_MS_CRB_AGT_ADR) | ||
236 | |||
237 | #define NETXEN_HW_CRB_HUB_AGT_ADR_PS \ | ||
238 | ((NETXEN_HW_H1_CH_HUB_ADR << 7) | NETXEN_HW_PS_CRB_AGT_ADR) | ||
239 | #define NETXEN_HW_CRB_HUB_AGT_ADR_SS \ | ||
240 | ((NETXEN_HW_H1_CH_HUB_ADR << 7) | NETXEN_HW_SS_CRB_AGT_ADR) | ||
241 | #define NETXEN_HW_CRB_HUB_AGT_ADR_RPMX3 \ | ||
242 | ((NETXEN_HW_H1_CH_HUB_ADR << 7) | NETXEN_HW_RPMX3_CRB_AGT_ADR) | ||
243 | #define NETXEN_HW_CRB_HUB_AGT_ADR_QMS \ | ||
244 | ((NETXEN_HW_H1_CH_HUB_ADR << 7) | NETXEN_HW_QMS_CRB_AGT_ADR) | ||
245 | #define NETXEN_HW_CRB_HUB_AGT_ADR_SQS0 \ | ||
246 | ((NETXEN_HW_H1_CH_HUB_ADR << 7) | NETXEN_HW_SQGS0_CRB_AGT_ADR) | ||
247 | #define NETXEN_HW_CRB_HUB_AGT_ADR_SQS1 \ | ||
248 | ((NETXEN_HW_H1_CH_HUB_ADR << 7) | NETXEN_HW_SQGS1_CRB_AGT_ADR) | ||
249 | #define NETXEN_HW_CRB_HUB_AGT_ADR_SQS2 \ | ||
250 | ((NETXEN_HW_H1_CH_HUB_ADR << 7) | NETXEN_HW_SQGS2_CRB_AGT_ADR) | ||
251 | #define NETXEN_HW_CRB_HUB_AGT_ADR_SQS3 \ | ||
252 | ((NETXEN_HW_H1_CH_HUB_ADR << 7) | NETXEN_HW_SQGS3_CRB_AGT_ADR) | ||
253 | #define NETXEN_HW_CRB_HUB_AGT_ADR_C2C0 \ | ||
254 | ((NETXEN_HW_H1_CH_HUB_ADR << 7) | NETXEN_HW_C2C0_CRB_AGT_ADR) | ||
255 | #define NETXEN_HW_CRB_HUB_AGT_ADR_C2C1 \ | ||
256 | ((NETXEN_HW_H1_CH_HUB_ADR << 7) | NETXEN_HW_C2C1_CRB_AGT_ADR) | ||
257 | #define NETXEN_HW_CRB_HUB_AGT_ADR_RPMX2 \ | ||
258 | ((NETXEN_HW_H1_CH_HUB_ADR << 7) | NETXEN_HW_RPMX2_CRB_AGT_ADR) | ||
259 | #define NETXEN_HW_CRB_HUB_AGT_ADR_RPMX4 \ | ||
260 | ((NETXEN_HW_H1_CH_HUB_ADR << 7) | NETXEN_HW_RPMX4_CRB_AGT_ADR) | ||
261 | #define NETXEN_HW_CRB_HUB_AGT_ADR_RPMX7 \ | ||
262 | ((NETXEN_HW_H1_CH_HUB_ADR << 7) | NETXEN_HW_RPMX7_CRB_AGT_ADR) | ||
263 | #define NETXEN_HW_CRB_HUB_AGT_ADR_RPMX9 \ | ||
264 | ((NETXEN_HW_H1_CH_HUB_ADR << 7) | NETXEN_HW_RPMX9_CRB_AGT_ADR) | ||
265 | #define NETXEN_HW_CRB_HUB_AGT_ADR_SMB \ | ||
266 | ((NETXEN_HW_H1_CH_HUB_ADR << 7) | NETXEN_HW_SMB_CRB_AGT_ADR) | ||
267 | |||
268 | #define NETXEN_HW_CRB_HUB_AGT_ADR_NIU \ | ||
269 | ((NETXEN_HW_H2_CH_HUB_ADR << 7) | NETXEN_HW_NIU_CRB_AGT_ADR) | ||
270 | #define NETXEN_HW_CRB_HUB_AGT_ADR_I2C0 \ | ||
271 | ((NETXEN_HW_H2_CH_HUB_ADR << 7) | NETXEN_HW_I2C0_CRB_AGT_ADR) | ||
272 | #define NETXEN_HW_CRB_HUB_AGT_ADR_I2C1 \ | ||
273 | ((NETXEN_HW_H2_CH_HUB_ADR << 7) | NETXEN_HW_I2C1_CRB_AGT_ADR) | ||
274 | |||
275 | #define NETXEN_HW_CRB_HUB_AGT_ADR_SRE \ | ||
276 | ((NETXEN_HW_H3_CH_HUB_ADR << 7) | NETXEN_HW_SRE_CRB_AGT_ADR) | ||
277 | #define NETXEN_HW_CRB_HUB_AGT_ADR_EG \ | ||
278 | ((NETXEN_HW_H3_CH_HUB_ADR << 7) | NETXEN_HW_EG_CRB_AGT_ADR) | ||
279 | #define NETXEN_HW_CRB_HUB_AGT_ADR_RPMX0 \ | ||
280 | ((NETXEN_HW_H3_CH_HUB_ADR << 7) | NETXEN_HW_RPMX0_CRB_AGT_ADR) | ||
281 | #define NETXEN_HW_CRB_HUB_AGT_ADR_QMN \ | ||
282 | ((NETXEN_HW_H3_CH_HUB_ADR << 7) | NETXEN_HW_QM_CRB_AGT_ADR) | ||
283 | #define NETXEN_HW_CRB_HUB_AGT_ADR_SQN0 \ | ||
284 | ((NETXEN_HW_H3_CH_HUB_ADR << 7) | NETXEN_HW_SQG0_CRB_AGT_ADR) | ||
285 | #define NETXEN_HW_CRB_HUB_AGT_ADR_SQN1 \ | ||
286 | ((NETXEN_HW_H3_CH_HUB_ADR << 7) | NETXEN_HW_SQG1_CRB_AGT_ADR) | ||
287 | #define NETXEN_HW_CRB_HUB_AGT_ADR_SQN2 \ | ||
288 | ((NETXEN_HW_H3_CH_HUB_ADR << 7) | NETXEN_HW_SQG2_CRB_AGT_ADR) | ||
289 | #define NETXEN_HW_CRB_HUB_AGT_ADR_SQN3 \ | ||
290 | ((NETXEN_HW_H3_CH_HUB_ADR << 7) | NETXEN_HW_SQG3_CRB_AGT_ADR) | ||
291 | #define NETXEN_HW_CRB_HUB_AGT_ADR_RPMX1 \ | ||
292 | ((NETXEN_HW_H3_CH_HUB_ADR << 7) | NETXEN_HW_RPMX1_CRB_AGT_ADR) | ||
293 | #define NETXEN_HW_CRB_HUB_AGT_ADR_RPMX5 \ | ||
294 | ((NETXEN_HW_H3_CH_HUB_ADR << 7) | NETXEN_HW_RPMX5_CRB_AGT_ADR) | ||
295 | #define NETXEN_HW_CRB_HUB_AGT_ADR_RPMX6 \ | ||
296 | ((NETXEN_HW_H3_CH_HUB_ADR << 7) | NETXEN_HW_RPMX6_CRB_AGT_ADR) | ||
297 | #define NETXEN_HW_CRB_HUB_AGT_ADR_RPMX8 \ | ||
298 | ((NETXEN_HW_H3_CH_HUB_ADR << 7) | NETXEN_HW_RPMX8_CRB_AGT_ADR) | ||
299 | #define NETXEN_HW_CRB_HUB_AGT_ADR_CAS0 \ | ||
300 | ((NETXEN_HW_H3_CH_HUB_ADR << 7) | NETXEN_HW_CAS0_CRB_AGT_ADR) | ||
301 | #define NETXEN_HW_CRB_HUB_AGT_ADR_CAS1 \ | ||
302 | ((NETXEN_HW_H3_CH_HUB_ADR << 7) | NETXEN_HW_CAS1_CRB_AGT_ADR) | ||
303 | #define NETXEN_HW_CRB_HUB_AGT_ADR_CAS2 \ | ||
304 | ((NETXEN_HW_H3_CH_HUB_ADR << 7) | NETXEN_HW_CAS2_CRB_AGT_ADR) | ||
305 | #define NETXEN_HW_CRB_HUB_AGT_ADR_CAS3 \ | ||
306 | ((NETXEN_HW_H3_CH_HUB_ADR << 7) | NETXEN_HW_CAS3_CRB_AGT_ADR) | ||
307 | |||
308 | #define NETXEN_HW_CRB_HUB_AGT_ADR_PGNI \ | ||
309 | ((NETXEN_HW_H4_CH_HUB_ADR << 7) | NETXEN_HW_PEGNI_CRB_AGT_ADR) | ||
310 | #define NETXEN_HW_CRB_HUB_AGT_ADR_PGND \ | ||
311 | ((NETXEN_HW_H4_CH_HUB_ADR << 7) | NETXEN_HW_PEGND_CRB_AGT_ADR) | ||
312 | #define NETXEN_HW_CRB_HUB_AGT_ADR_PGN0 \ | ||
313 | ((NETXEN_HW_H4_CH_HUB_ADR << 7) | NETXEN_HW_PEGN0_CRB_AGT_ADR) | ||
314 | #define NETXEN_HW_CRB_HUB_AGT_ADR_PGN1 \ | ||
315 | ((NETXEN_HW_H4_CH_HUB_ADR << 7) | NETXEN_HW_PEGN1_CRB_AGT_ADR) | ||
316 | #define NETXEN_HW_CRB_HUB_AGT_ADR_PGN2 \ | ||
317 | ((NETXEN_HW_H4_CH_HUB_ADR << 7) | NETXEN_HW_PEGN2_CRB_AGT_ADR) | ||
318 | #define NETXEN_HW_CRB_HUB_AGT_ADR_PGN3 \ | ||
319 | ((NETXEN_HW_H4_CH_HUB_ADR << 7) | NETXEN_HW_PEGN3_CRB_AGT_ADR) | ||
320 | #define NETXEN_HW_CRB_HUB_AGT_ADR_PGNC \ | ||
321 | ((NETXEN_HW_H4_CH_HUB_ADR << 7) | NETXEN_HW_PEGNC_CRB_AGT_ADR) | ||
322 | #define NETXEN_HW_CRB_HUB_AGT_ADR_PGR0 \ | ||
323 | ((NETXEN_HW_H4_CH_HUB_ADR << 7) | NETXEN_HW_PEGR0_CRB_AGT_ADR) | ||
324 | #define NETXEN_HW_CRB_HUB_AGT_ADR_PGR1 \ | ||
325 | ((NETXEN_HW_H4_CH_HUB_ADR << 7) | NETXEN_HW_PEGR1_CRB_AGT_ADR) | ||
326 | #define NETXEN_HW_CRB_HUB_AGT_ADR_PGR2 \ | ||
327 | ((NETXEN_HW_H4_CH_HUB_ADR << 7) | NETXEN_HW_PEGR2_CRB_AGT_ADR) | ||
328 | #define NETXEN_HW_CRB_HUB_AGT_ADR_PGR3 \ | ||
329 | ((NETXEN_HW_H4_CH_HUB_ADR << 7) | NETXEN_HW_PEGR3_CRB_AGT_ADR) | ||
330 | |||
331 | #define NETXEN_HW_CRB_HUB_AGT_ADR_PGSI \ | ||
332 | ((NETXEN_HW_H5_CH_HUB_ADR << 7) | NETXEN_HW_PEGSI_CRB_AGT_ADR) | ||
333 | #define NETXEN_HW_CRB_HUB_AGT_ADR_PGSD \ | ||
334 | ((NETXEN_HW_H5_CH_HUB_ADR << 7) | NETXEN_HW_PEGSD_CRB_AGT_ADR) | ||
335 | #define NETXEN_HW_CRB_HUB_AGT_ADR_PGS0 \ | ||
336 | ((NETXEN_HW_H5_CH_HUB_ADR << 7) | NETXEN_HW_PEGS0_CRB_AGT_ADR) | ||
337 | #define NETXEN_HW_CRB_HUB_AGT_ADR_PGS1 \ | ||
338 | ((NETXEN_HW_H5_CH_HUB_ADR << 7) | NETXEN_HW_PEGS1_CRB_AGT_ADR) | ||
339 | #define NETXEN_HW_CRB_HUB_AGT_ADR_PGS2 \ | ||
340 | ((NETXEN_HW_H5_CH_HUB_ADR << 7) | NETXEN_HW_PEGS2_CRB_AGT_ADR) | ||
341 | #define NETXEN_HW_CRB_HUB_AGT_ADR_PGS3 \ | ||
342 | ((NETXEN_HW_H5_CH_HUB_ADR << 7) | NETXEN_HW_PEGS3_CRB_AGT_ADR) | ||
343 | #define NETXEN_HW_CRB_HUB_AGT_ADR_PGSC \ | ||
344 | ((NETXEN_HW_H5_CH_HUB_ADR << 7) | NETXEN_HW_PEGSC_CRB_AGT_ADR) | ||
345 | |||
346 | #define NETXEN_HW_CRB_HUB_AGT_ADR_CAM \ | ||
347 | ((NETXEN_HW_H6_CH_HUB_ADR << 7) | NETXEN_HW_NCM_CRB_AGT_ADR) | ||
348 | #define NETXEN_HW_CRB_HUB_AGT_ADR_TIMR \ | ||
349 | ((NETXEN_HW_H6_CH_HUB_ADR << 7) | NETXEN_HW_TMR_CRB_AGT_ADR) | ||
350 | #define NETXEN_HW_CRB_HUB_AGT_ADR_XDMA \ | ||
351 | ((NETXEN_HW_H6_CH_HUB_ADR << 7) | NETXEN_HW_XDMA_CRB_AGT_ADR) | ||
352 | #define NETXEN_HW_CRB_HUB_AGT_ADR_SN \ | ||
353 | ((NETXEN_HW_H6_CH_HUB_ADR << 7) | NETXEN_HW_SN_CRB_AGT_ADR) | ||
354 | #define NETXEN_HW_CRB_HUB_AGT_ADR_I2Q \ | ||
355 | ((NETXEN_HW_H6_CH_HUB_ADR << 7) | NETXEN_HW_I2Q_CRB_AGT_ADR) | ||
356 | #define NETXEN_HW_CRB_HUB_AGT_ADR_ROMUSB \ | ||
357 | ((NETXEN_HW_H6_CH_HUB_ADR << 7) | NETXEN_HW_ROMUSB_CRB_AGT_ADR) | ||
358 | #define NETXEN_HW_CRB_HUB_AGT_ADR_OCM0 \ | ||
359 | ((NETXEN_HW_H6_CH_HUB_ADR << 7) | NETXEN_HW_OCM0_CRB_AGT_ADR) | ||
360 | #define NETXEN_HW_CRB_HUB_AGT_ADR_OCM1 \ | ||
361 | ((NETXEN_HW_H6_CH_HUB_ADR << 7) | NETXEN_HW_OCM1_CRB_AGT_ADR) | ||
362 | #define NETXEN_HW_CRB_HUB_AGT_ADR_LPC \ | ||
363 | ((NETXEN_HW_H6_CH_HUB_ADR << 7) | NETXEN_HW_LPC_CRB_AGT_ADR) | ||
364 | |||
365 | /* | ||
366 | * MAX_RCV_CTX : The number of receive contexts that are available on | ||
367 | * the phantom. | ||
368 | */ | ||
369 | #define MAX_RCV_CTX 1 | ||
370 | |||
371 | #define NETXEN_SRE_INT_STATUS (NETXEN_CRB_SRE + 0x00034) | ||
372 | #define NETXEN_SRE_PBI_ACTIVE_STATUS (NETXEN_CRB_SRE + 0x01014) | ||
373 | #define NETXEN_SRE_L1RE_CTL (NETXEN_CRB_SRE + 0x03000) | ||
374 | #define NETXEN_SRE_L2RE_CTL (NETXEN_CRB_SRE + 0x05000) | ||
375 | #define NETXEN_SRE_BUF_CTL (NETXEN_CRB_SRE + 0x01000) | ||
376 | |||
377 | #define NETXEN_DMA_BASE(U) (NETXEN_CRB_PCIX_MD + 0x20000 + ((U)<<16)) | ||
378 | #define NETXEN_DMA_COMMAND(U) (NETXEN_DMA_BASE(U) + 0x00008) | ||
379 | |||
380 | #define NETXEN_I2Q_CLR_PCI_HI (NETXEN_CRB_I2Q + 0x00034) | ||
381 | |||
382 | #define PEG_NETWORK_BASE(N) (NETXEN_CRB_PEG_NET_0 + (((N)&3) << 20)) | ||
383 | #define CRB_REG_EX_PC 0x3c | ||
384 | |||
385 | #define ROMUSB_GLB (NETXEN_CRB_ROMUSB + 0x00000) | ||
386 | #define ROMUSB_ROM (NETXEN_CRB_ROMUSB + 0x10000) | ||
387 | |||
388 | #define NETXEN_ROMUSB_GLB_STATUS (ROMUSB_GLB + 0x0004) | ||
389 | #define NETXEN_ROMUSB_GLB_SW_RESET (ROMUSB_GLB + 0x0008) | ||
390 | #define NETXEN_ROMUSB_GLB_PAD_GPIO_I (ROMUSB_GLB + 0x000c) | ||
391 | #define NETXEN_ROMUSB_GLB_CAS_RST (ROMUSB_GLB + 0x0038) | ||
392 | #define NETXEN_ROMUSB_GLB_TEST_MUX_SEL (ROMUSB_GLB + 0x0044) | ||
393 | #define NETXEN_ROMUSB_GLB_PEGTUNE_DONE (ROMUSB_GLB + 0x005c) | ||
394 | #define NETXEN_ROMUSB_GLB_CHIP_CLK_CTRL (ROMUSB_GLB + 0x00A8) | ||
395 | |||
396 | #define NETXEN_ROMUSB_GPIO(n) (ROMUSB_GLB + 0x60 + (4 * (n))) | ||
397 | |||
398 | #define NETXEN_ROMUSB_ROM_INSTR_OPCODE (ROMUSB_ROM + 0x0004) | ||
399 | #define NETXEN_ROMUSB_ROM_ADDRESS (ROMUSB_ROM + 0x0008) | ||
400 | #define NETXEN_ROMUSB_ROM_WDATA (ROMUSB_ROM + 0x000c) | ||
401 | #define NETXEN_ROMUSB_ROM_ABYTE_CNT (ROMUSB_ROM + 0x0010) | ||
402 | #define NETXEN_ROMUSB_ROM_DUMMY_BYTE_CNT (ROMUSB_ROM + 0x0014) | ||
403 | #define NETXEN_ROMUSB_ROM_RDATA (ROMUSB_ROM + 0x0018) | ||
404 | |||
405 | /* Lock IDs for ROM lock */ | ||
406 | #define ROM_LOCK_DRIVER 0x0d417340 | ||
407 | |||
408 | /****************************************************************************** | ||
409 | * | ||
410 | * Definitions specific to M25P flash | ||
411 | * | ||
412 | ******************************************************************************* | ||
413 | * Instructions | ||
414 | */ | ||
415 | #define M25P_INSTR_WREN 0x06 | ||
416 | #define M25P_INSTR_WRDI 0x04 | ||
417 | #define M25P_INSTR_RDID 0x9f | ||
418 | #define M25P_INSTR_RDSR 0x05 | ||
419 | #define M25P_INSTR_WRSR 0x01 | ||
420 | #define M25P_INSTR_READ 0x03 | ||
421 | #define M25P_INSTR_FAST_READ 0x0b | ||
422 | #define M25P_INSTR_PP 0x02 | ||
423 | #define M25P_INSTR_SE 0xd8 | ||
424 | #define M25P_INSTR_BE 0xc7 | ||
425 | #define M25P_INSTR_DP 0xb9 | ||
426 | #define M25P_INSTR_RES 0xab | ||
427 | |||
428 | /* all are 1MB windows */ | ||
429 | |||
430 | #define NETXEN_PCI_CRB_WINDOWSIZE 0x00100000 | ||
431 | #define NETXEN_PCI_CRB_WINDOW(A) \ | ||
432 | (NETXEN_PCI_CRBSPACE + (A)*NETXEN_PCI_CRB_WINDOWSIZE) | ||
433 | |||
434 | #define NETXEN_CRB_NIU NETXEN_PCI_CRB_WINDOW(NETXEN_HW_PX_MAP_CRB_NIU) | ||
435 | #define NETXEN_CRB_SRE NETXEN_PCI_CRB_WINDOW(NETXEN_HW_PX_MAP_CRB_SRE) | ||
436 | #define NETXEN_CRB_ROMUSB \ | ||
437 | NETXEN_PCI_CRB_WINDOW(NETXEN_HW_PX_MAP_CRB_ROMUSB) | ||
438 | #define NETXEN_CRB_I2Q NETXEN_PCI_CRB_WINDOW(NETXEN_HW_PX_MAP_CRB_I2Q) | ||
439 | #define NETXEN_CRB_MAX NETXEN_PCI_CRB_WINDOW(64) | ||
440 | |||
441 | #define NETXEN_CRB_PCIX_HOST NETXEN_PCI_CRB_WINDOW(NETXEN_HW_PX_MAP_CRB_PH) | ||
442 | #define NETXEN_CRB_PCIX_HOST2 NETXEN_PCI_CRB_WINDOW(NETXEN_HW_PX_MAP_CRB_PH2) | ||
443 | #define NETXEN_CRB_PEG_NET_0 NETXEN_PCI_CRB_WINDOW(NETXEN_HW_PX_MAP_CRB_PGN0) | ||
444 | #define NETXEN_CRB_PEG_NET_1 NETXEN_PCI_CRB_WINDOW(NETXEN_HW_PX_MAP_CRB_PGN1) | ||
445 | #define NETXEN_CRB_PEG_NET_2 NETXEN_PCI_CRB_WINDOW(NETXEN_HW_PX_MAP_CRB_PGN2) | ||
446 | #define NETXEN_CRB_PEG_NET_3 NETXEN_PCI_CRB_WINDOW(NETXEN_HW_PX_MAP_CRB_PGN3) | ||
447 | #define NETXEN_CRB_PEG_NET_D NETXEN_PCI_CRB_WINDOW(NETXEN_HW_PX_MAP_CRB_PGND) | ||
448 | #define NETXEN_CRB_PEG_NET_I NETXEN_PCI_CRB_WINDOW(NETXEN_HW_PX_MAP_CRB_PGNI) | ||
449 | #define NETXEN_CRB_DDR_NET NETXEN_PCI_CRB_WINDOW(NETXEN_HW_PX_MAP_CRB_MN) | ||
450 | |||
451 | #define NETXEN_CRB_PCIX_MD NETXEN_PCI_CRB_WINDOW(NETXEN_HW_PX_MAP_CRB_PS) | ||
452 | #define NETXEN_CRB_PCIE NETXEN_CRB_PCIX_MD | ||
453 | |||
454 | #define ISR_INT_VECTOR (NETXEN_PCIX_PS_REG(PCIX_INT_VECTOR)) | ||
455 | #define ISR_INT_MASK (NETXEN_PCIX_PS_REG(PCIX_INT_MASK)) | ||
456 | #define ISR_INT_MASK_SLOW (NETXEN_PCIX_PS_REG(PCIX_INT_MASK)) | ||
457 | #define ISR_INT_TARGET_STATUS (NETXEN_PCIX_PS_REG(PCIX_TARGET_STATUS)) | ||
458 | #define ISR_INT_TARGET_MASK (NETXEN_PCIX_PS_REG(PCIX_TARGET_MASK)) | ||
459 | |||
460 | #define NETXEN_PCI_MAPSIZE 128 | ||
461 | #define NETXEN_PCI_DDR_NET (0x00000000UL) | ||
462 | #define NETXEN_PCI_QDR_NET (0x04000000UL) | ||
463 | #define NETXEN_PCI_DIRECT_CRB (0x04400000UL) | ||
464 | #define NETXEN_PCI_CAMQM_MAX (0x04ffffffUL) | ||
465 | #define NETXEN_PCI_OCM0 (0x05000000UL) | ||
466 | #define NETXEN_PCI_OCM0_MAX (0x050fffffUL) | ||
467 | #define NETXEN_PCI_OCM1 (0x05100000UL) | ||
468 | #define NETXEN_PCI_OCM1_MAX (0x051fffffUL) | ||
469 | #define NETXEN_PCI_CRBSPACE (0x06000000UL) | ||
470 | |||
471 | #define NETXEN_CRB_CAM NETXEN_PCI_CRB_WINDOW(NETXEN_HW_PX_MAP_CRB_CAM) | ||
472 | |||
473 | #define NETXEN_ADDR_DDR_NET (0x0000000000000000ULL) | ||
474 | #define NETXEN_ADDR_DDR_NET_MAX (0x000000000fffffffULL) | ||
475 | #define NETXEN_ADDR_OCM0 (0x0000000200000000ULL) | ||
476 | #define NETXEN_ADDR_OCM0_MAX (0x00000002000fffffULL) | ||
477 | #define NETXEN_ADDR_OCM1 (0x0000000200400000ULL) | ||
478 | #define NETXEN_ADDR_OCM1_MAX (0x00000002004fffffULL) | ||
479 | #define NETXEN_ADDR_QDR_NET (0x0000000300000000ULL) | ||
480 | #define NETXEN_ADDR_QDR_NET_MAX (0x00000003003fffffULL) | ||
481 | |||
482 | /* 200ms delay in each loop */ | ||
483 | #define NETXEN_NIU_PHY_WAITLEN 200000 | ||
484 | /* 10 seconds before we give up */ | ||
485 | #define NETXEN_NIU_PHY_WAITMAX 50 | ||
486 | #define NETXEN_NIU_MAX_GBE_PORTS 4 | ||
487 | |||
488 | #define NETXEN_NIU_MODE (NETXEN_CRB_NIU + 0x00000) | ||
489 | |||
490 | #define NETXEN_NIU_XG_SINGLE_TERM (NETXEN_CRB_NIU + 0x00004) | ||
491 | #define NETXEN_NIU_XG_DRIVE_HI (NETXEN_CRB_NIU + 0x00008) | ||
492 | #define NETXEN_NIU_XG_DRIVE_LO (NETXEN_CRB_NIU + 0x0000c) | ||
493 | #define NETXEN_NIU_XG_DTX (NETXEN_CRB_NIU + 0x00010) | ||
494 | #define NETXEN_NIU_XG_DEQ (NETXEN_CRB_NIU + 0x00014) | ||
495 | #define NETXEN_NIU_XG_WORD_ALIGN (NETXEN_CRB_NIU + 0x00018) | ||
496 | #define NETXEN_NIU_XG_RESET (NETXEN_CRB_NIU + 0x0001c) | ||
497 | #define NETXEN_NIU_XG_POWER_DOWN (NETXEN_CRB_NIU + 0x00020) | ||
498 | #define NETXEN_NIU_XG_RESET_PLL (NETXEN_CRB_NIU + 0x00024) | ||
499 | #define NETXEN_NIU_XG_SERDES_LOOPBACK (NETXEN_CRB_NIU + 0x00028) | ||
500 | #define NETXEN_NIU_XG_DO_BYTE_ALIGN (NETXEN_CRB_NIU + 0x0002c) | ||
501 | #define NETXEN_NIU_XG_TX_ENABLE (NETXEN_CRB_NIU + 0x00030) | ||
502 | #define NETXEN_NIU_XG_RX_ENABLE (NETXEN_CRB_NIU + 0x00034) | ||
503 | #define NETXEN_NIU_XG_STATUS (NETXEN_CRB_NIU + 0x00038) | ||
504 | #define NETXEN_NIU_XG_PAUSE_THRESHOLD (NETXEN_CRB_NIU + 0x0003c) | ||
505 | #define NETXEN_NIU_INT_MASK (NETXEN_CRB_NIU + 0x00040) | ||
506 | #define NETXEN_NIU_ACTIVE_INT (NETXEN_CRB_NIU + 0x00044) | ||
507 | #define NETXEN_NIU_MASKABLE_INT (NETXEN_CRB_NIU + 0x00048) | ||
508 | |||
509 | #define NETXEN_NIU_STRAP_VALUE_SAVE_HIGHER (NETXEN_CRB_NIU + 0x0004c) | ||
510 | |||
511 | #define NETXEN_NIU_GB_SERDES_RESET (NETXEN_CRB_NIU + 0x00050) | ||
512 | #define NETXEN_NIU_GB0_GMII_MODE (NETXEN_CRB_NIU + 0x00054) | ||
513 | #define NETXEN_NIU_GB0_MII_MODE (NETXEN_CRB_NIU + 0x00058) | ||
514 | #define NETXEN_NIU_GB1_GMII_MODE (NETXEN_CRB_NIU + 0x0005c) | ||
515 | #define NETXEN_NIU_GB1_MII_MODE (NETXEN_CRB_NIU + 0x00060) | ||
516 | #define NETXEN_NIU_GB2_GMII_MODE (NETXEN_CRB_NIU + 0x00064) | ||
517 | #define NETXEN_NIU_GB2_MII_MODE (NETXEN_CRB_NIU + 0x00068) | ||
518 | #define NETXEN_NIU_GB3_GMII_MODE (NETXEN_CRB_NIU + 0x0006c) | ||
519 | #define NETXEN_NIU_GB3_MII_MODE (NETXEN_CRB_NIU + 0x00070) | ||
520 | #define NETXEN_NIU_REMOTE_LOOPBACK (NETXEN_CRB_NIU + 0x00074) | ||
521 | #define NETXEN_NIU_GB0_HALF_DUPLEX (NETXEN_CRB_NIU + 0x00078) | ||
522 | #define NETXEN_NIU_GB1_HALF_DUPLEX (NETXEN_CRB_NIU + 0x0007c) | ||
523 | #define NETXEN_NIU_RESET_SYS_FIFOS (NETXEN_CRB_NIU + 0x00088) | ||
524 | #define NETXEN_NIU_GB_CRC_DROP (NETXEN_CRB_NIU + 0x0008c) | ||
525 | #define NETXEN_NIU_GB_DROP_WRONGADDR (NETXEN_CRB_NIU + 0x00090) | ||
526 | #define NETXEN_NIU_TEST_MUX_CTL (NETXEN_CRB_NIU + 0x00094) | ||
527 | #define NETXEN_NIU_XG_PAUSE_CTL (NETXEN_CRB_NIU + 0x00098) | ||
528 | #define NETXEN_NIU_XG_PAUSE_LEVEL (NETXEN_CRB_NIU + 0x000dc) | ||
529 | #define NETXEN_NIU_XG_SEL (NETXEN_CRB_NIU + 0x00128) | ||
530 | |||
531 | #define NETXEN_NIU_FULL_LEVEL_XG (NETXEN_CRB_NIU + 0x00450) | ||
532 | |||
533 | #define NETXEN_NIU_XG1_RESET (NETXEN_CRB_NIU + 0x0011c) | ||
534 | #define NETXEN_NIU_XG1_POWER_DOWN (NETXEN_CRB_NIU + 0x00120) | ||
535 | #define NETXEN_NIU_XG1_RESET_PLL (NETXEN_CRB_NIU + 0x00124) | ||
536 | |||
537 | #define NETXEN_MAC_ADDR_CNTL_REG (NETXEN_CRB_NIU + 0x1000) | ||
538 | |||
539 | #define NETXEN_MULTICAST_ADDR_HI_0 (NETXEN_CRB_NIU + 0x1010) | ||
540 | #define NETXEN_MULTICAST_ADDR_HI_1 (NETXEN_CRB_NIU + 0x1014) | ||
541 | #define NETXEN_MULTICAST_ADDR_HI_2 (NETXEN_CRB_NIU + 0x1018) | ||
542 | #define NETXEN_MULTICAST_ADDR_HI_3 (NETXEN_CRB_NIU + 0x101c) | ||
543 | |||
544 | #define NETXEN_NIU_GB_MAC_CONFIG_0(I) \ | ||
545 | (NETXEN_CRB_NIU + 0x30000 + (I)*0x10000) | ||
546 | #define NETXEN_NIU_GB_MAC_CONFIG_1(I) \ | ||
547 | (NETXEN_CRB_NIU + 0x30004 + (I)*0x10000) | ||
548 | #define NETXEN_NIU_GB_MAC_IPG_IFG(I) \ | ||
549 | (NETXEN_CRB_NIU + 0x30008 + (I)*0x10000) | ||
550 | #define NETXEN_NIU_GB_HALF_DUPLEX_CTRL(I) \ | ||
551 | (NETXEN_CRB_NIU + 0x3000c + (I)*0x10000) | ||
552 | #define NETXEN_NIU_GB_MAX_FRAME_SIZE(I) \ | ||
553 | (NETXEN_CRB_NIU + 0x30010 + (I)*0x10000) | ||
554 | #define NETXEN_NIU_GB_TEST_REG(I) \ | ||
555 | (NETXEN_CRB_NIU + 0x3001c + (I)*0x10000) | ||
556 | #define NETXEN_NIU_GB_MII_MGMT_CONFIG(I) \ | ||
557 | (NETXEN_CRB_NIU + 0x30020 + (I)*0x10000) | ||
558 | #define NETXEN_NIU_GB_MII_MGMT_COMMAND(I) \ | ||
559 | (NETXEN_CRB_NIU + 0x30024 + (I)*0x10000) | ||
560 | #define NETXEN_NIU_GB_MII_MGMT_ADDR(I) \ | ||
561 | (NETXEN_CRB_NIU + 0x30028 + (I)*0x10000) | ||
562 | #define NETXEN_NIU_GB_MII_MGMT_CTRL(I) \ | ||
563 | (NETXEN_CRB_NIU + 0x3002c + (I)*0x10000) | ||
564 | #define NETXEN_NIU_GB_MII_MGMT_STATUS(I) \ | ||
565 | (NETXEN_CRB_NIU + 0x30030 + (I)*0x10000) | ||
566 | #define NETXEN_NIU_GB_MII_MGMT_INDICATE(I) \ | ||
567 | (NETXEN_CRB_NIU + 0x30034 + (I)*0x10000) | ||
568 | #define NETXEN_NIU_GB_INTERFACE_CTRL(I) \ | ||
569 | (NETXEN_CRB_NIU + 0x30038 + (I)*0x10000) | ||
570 | #define NETXEN_NIU_GB_INTERFACE_STATUS(I) \ | ||
571 | (NETXEN_CRB_NIU + 0x3003c + (I)*0x10000) | ||
572 | #define NETXEN_NIU_GB_STATION_ADDR_0(I) \ | ||
573 | (NETXEN_CRB_NIU + 0x30040 + (I)*0x10000) | ||
574 | #define NETXEN_NIU_GB_STATION_ADDR_1(I) \ | ||
575 | (NETXEN_CRB_NIU + 0x30044 + (I)*0x10000) | ||
576 | |||
577 | #define NETXEN_NIU_XGE_CONFIG_0 (NETXEN_CRB_NIU + 0x70000) | ||
578 | #define NETXEN_NIU_XGE_CONFIG_1 (NETXEN_CRB_NIU + 0x70004) | ||
579 | #define NETXEN_NIU_XGE_IPG (NETXEN_CRB_NIU + 0x70008) | ||
580 | #define NETXEN_NIU_XGE_STATION_ADDR_0_HI (NETXEN_CRB_NIU + 0x7000c) | ||
581 | #define NETXEN_NIU_XGE_STATION_ADDR_0_1 (NETXEN_CRB_NIU + 0x70010) | ||
582 | #define NETXEN_NIU_XGE_STATION_ADDR_1_LO (NETXEN_CRB_NIU + 0x70014) | ||
583 | #define NETXEN_NIU_XGE_STATUS (NETXEN_CRB_NIU + 0x70018) | ||
584 | #define NETXEN_NIU_XGE_MAX_FRAME_SIZE (NETXEN_CRB_NIU + 0x7001c) | ||
585 | #define NETXEN_NIU_XGE_PAUSE_FRAME_VALUE (NETXEN_CRB_NIU + 0x70020) | ||
586 | #define NETXEN_NIU_XGE_TX_BYTE_CNT (NETXEN_CRB_NIU + 0x70024) | ||
587 | #define NETXEN_NIU_XGE_TX_FRAME_CNT (NETXEN_CRB_NIU + 0x70028) | ||
588 | #define NETXEN_NIU_XGE_RX_BYTE_CNT (NETXEN_CRB_NIU + 0x7002c) | ||
589 | #define NETXEN_NIU_XGE_RX_FRAME_CNT (NETXEN_CRB_NIU + 0x70030) | ||
590 | #define NETXEN_NIU_XGE_AGGR_ERROR_CNT (NETXEN_CRB_NIU + 0x70034) | ||
591 | #define NETXEN_NIU_XGE_MULTICAST_FRAME_CNT (NETXEN_CRB_NIU + 0x70038) | ||
592 | #define NETXEN_NIU_XGE_UNICAST_FRAME_CNT (NETXEN_CRB_NIU + 0x7003c) | ||
593 | #define NETXEN_NIU_XGE_CRC_ERROR_CNT (NETXEN_CRB_NIU + 0x70040) | ||
594 | #define NETXEN_NIU_XGE_OVERSIZE_FRAME_ERR (NETXEN_CRB_NIU + 0x70044) | ||
595 | #define NETXEN_NIU_XGE_UNDERSIZE_FRAME_ERR (NETXEN_CRB_NIU + 0x70048) | ||
596 | #define NETXEN_NIU_XGE_LOCAL_ERROR_CNT (NETXEN_CRB_NIU + 0x7004c) | ||
597 | #define NETXEN_NIU_XGE_REMOTE_ERROR_CNT (NETXEN_CRB_NIU + 0x70050) | ||
598 | #define NETXEN_NIU_XGE_CONTROL_CHAR_CNT (NETXEN_CRB_NIU + 0x70054) | ||
599 | #define NETXEN_NIU_XGE_PAUSE_FRAME_CNT (NETXEN_CRB_NIU + 0x70058) | ||
600 | #define NETXEN_NIU_XG1_CONFIG_0 (NETXEN_CRB_NIU + 0x80000) | ||
601 | #define NETXEN_NIU_XG1_CONFIG_1 (NETXEN_CRB_NIU + 0x80004) | ||
602 | #define NETXEN_NIU_XG1_IPG (NETXEN_CRB_NIU + 0x80008) | ||
603 | #define NETXEN_NIU_XG1_STATION_ADDR_0_HI (NETXEN_CRB_NIU + 0x8000c) | ||
604 | #define NETXEN_NIU_XG1_STATION_ADDR_0_1 (NETXEN_CRB_NIU + 0x80010) | ||
605 | #define NETXEN_NIU_XG1_STATION_ADDR_1_LO (NETXEN_CRB_NIU + 0x80014) | ||
606 | #define NETXEN_NIU_XG1_STATUS (NETXEN_CRB_NIU + 0x80018) | ||
607 | #define NETXEN_NIU_XG1_MAX_FRAME_SIZE (NETXEN_CRB_NIU + 0x8001c) | ||
608 | #define NETXEN_NIU_XG1_PAUSE_FRAME_VALUE (NETXEN_CRB_NIU + 0x80020) | ||
609 | #define NETXEN_NIU_XG1_TX_BYTE_CNT (NETXEN_CRB_NIU + 0x80024) | ||
610 | #define NETXEN_NIU_XG1_TX_FRAME_CNT (NETXEN_CRB_NIU + 0x80028) | ||
611 | #define NETXEN_NIU_XG1_RX_BYTE_CNT (NETXEN_CRB_NIU + 0x8002c) | ||
612 | #define NETXEN_NIU_XG1_RX_FRAME_CNT (NETXEN_CRB_NIU + 0x80030) | ||
613 | #define NETXEN_NIU_XG1_AGGR_ERROR_CNT (NETXEN_CRB_NIU + 0x80034) | ||
614 | #define NETXEN_NIU_XG1_MULTICAST_FRAME_CNT (NETXEN_CRB_NIU + 0x80038) | ||
615 | #define NETXEN_NIU_XG1_UNICAST_FRAME_CNT (NETXEN_CRB_NIU + 0x8003c) | ||
616 | #define NETXEN_NIU_XG1_CRC_ERROR_CNT (NETXEN_CRB_NIU + 0x80040) | ||
617 | #define NETXEN_NIU_XG1_OVERSIZE_FRAME_ERR (NETXEN_CRB_NIU + 0x80044) | ||
618 | #define NETXEN_NIU_XG1_UNDERSIZE_FRAME_ERR (NETXEN_CRB_NIU + 0x80048) | ||
619 | #define NETXEN_NIU_XG1_LOCAL_ERROR_CNT (NETXEN_CRB_NIU + 0x8004c) | ||
620 | #define NETXEN_NIU_XG1_REMOTE_ERROR_CNT (NETXEN_CRB_NIU + 0x80050) | ||
621 | #define NETXEN_NIU_XG1_CONTROL_CHAR_CNT (NETXEN_CRB_NIU + 0x80054) | ||
622 | #define NETXEN_NIU_XG1_PAUSE_FRAME_CNT (NETXEN_CRB_NIU + 0x80058) | ||
623 | |||
624 | /* XG Link status */ | ||
625 | #define XG_LINK_UP 0x10 | ||
626 | #define XG_LINK_DOWN 0x20 | ||
627 | |||
628 | #define NETXEN_CAM_RAM_BASE (NETXEN_CRB_CAM + 0x02000) | ||
629 | #define NETXEN_CAM_RAM(reg) (NETXEN_CAM_RAM_BASE + (reg)) | ||
630 | #define NETXEN_FW_VERSION_MAJOR (NETXEN_CAM_RAM(0x150)) | ||
631 | #define NETXEN_FW_VERSION_MINOR (NETXEN_CAM_RAM(0x154)) | ||
632 | #define NETXEN_FW_VERSION_SUB (NETXEN_CAM_RAM(0x158)) | ||
633 | #define NETXEN_ROM_LOCK_ID (NETXEN_CAM_RAM(0x100)) | ||
634 | |||
635 | #define NETXEN_PHY_LOCK_ID (NETXEN_CAM_RAM(0x120)) | ||
636 | |||
637 | /* Lock IDs for PHY lock */ | ||
638 | #define PHY_LOCK_DRIVER 0x44524956 | ||
639 | |||
640 | /* Used for PS PCI Memory access */ | ||
641 | #define PCIX_PS_OP_ADDR_LO (0x10000) | ||
642 | /* via CRB (PS side only) */ | ||
643 | #define PCIX_PS_OP_ADDR_HI (0x10004) | ||
644 | |||
645 | #define PCIX_INT_VECTOR (0x10100) | ||
646 | #define PCIX_INT_MASK (0x10104) | ||
647 | |||
648 | #define PCIX_MN_WINDOW (0x10200) | ||
649 | #define PCIX_MS_WINDOW (0x10204) | ||
650 | #define PCIX_SN_WINDOW (0x10208) | ||
651 | #define PCIX_CRB_WINDOW (0x10210) | ||
652 | |||
653 | #define PCIX_TARGET_STATUS (0x10118) | ||
654 | #define PCIX_TARGET_MASK (0x10128) | ||
655 | |||
656 | #define PCIX_MSI_F0 (0x13000) | ||
657 | |||
658 | #define PCIX_PS_MEM_SPACE (0x90000) | ||
659 | |||
660 | #define NETXEN_PCIX_PH_REG(reg) (NETXEN_CRB_PCIE + (reg)) | ||
661 | #define NETXEN_PCIX_PS_REG(reg) (NETXEN_CRB_PCIX_MD + (reg)) | ||
662 | |||
663 | #define NETXEN_PCIE_REG(reg) (NETXEN_CRB_PCIE + (reg)) | ||
664 | |||
665 | #define PCIE_MAX_DMA_XFER_SIZE (0x1404c) | ||
666 | |||
667 | #define PCIE_DCR 0x00d8 | ||
668 | |||
669 | #define PCIE_SEM2_LOCK (0x1c010) /* Flash lock */ | ||
670 | #define PCIE_SEM2_UNLOCK (0x1c014) /* Flash unlock */ | ||
671 | #define PCIE_SEM3_LOCK (0x1c018) /* Phy lock */ | ||
672 | #define PCIE_SEM3_UNLOCK (0x1c01c) /* Phy unlock */ | ||
673 | |||
674 | #define PCIE_TGT_SPLIT_CHICKEN (0x12080) | ||
675 | |||
676 | #define PCIE_MAX_MASTER_SPLIT (0x14048) | ||
677 | |||
678 | #endif /* __NETXEN_NIC_HDR_H_ */ | ||
diff --git a/drivers/net/netxen/netxen_nic_hw.c b/drivers/net/netxen/netxen_nic_hw.c new file mode 100644 index 000000000000..105c24f0ad4c --- /dev/null +++ b/drivers/net/netxen/netxen_nic_hw.c | |||
@@ -0,0 +1,1010 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2003 - 2006 NetXen, Inc. | ||
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 LICENSE. | ||
22 | * | ||
23 | * Contact Information: | ||
24 | * info@netxen.com | ||
25 | * NetXen, | ||
26 | * 3965 Freedom Circle, Fourth floor, | ||
27 | * Santa Clara, CA 95054 | ||
28 | * | ||
29 | * | ||
30 | * Source file for NIC routines to access the Phantom hardware | ||
31 | * | ||
32 | */ | ||
33 | |||
34 | #include "netxen_nic.h" | ||
35 | #include "netxen_nic_hw.h" | ||
36 | #include "netxen_nic_phan_reg.h" | ||
37 | |||
38 | /* PCI Windowing for DDR regions. */ | ||
39 | |||
40 | #define ADDR_IN_RANGE(addr, low, high) \ | ||
41 | (((addr) <= (high)) && ((addr) >= (low))) | ||
42 | |||
43 | #define NETXEN_FLASH_BASE (BOOTLD_START) | ||
44 | #define NETXEN_PHANTOM_MEM_BASE (NETXEN_FLASH_BASE) | ||
45 | #define NETXEN_MAX_MTU 8000 | ||
46 | #define NETXEN_MIN_MTU 64 | ||
47 | #define NETXEN_ETH_FCS_SIZE 4 | ||
48 | #define NETXEN_ENET_HEADER_SIZE 14 | ||
49 | #define NETXEN_WINDOW_ONE 0x2000000 /*CRB Window: bit 25 of CRB address */ | ||
50 | #define NETXEN_FIRMWARE_LEN ((16 * 1024) / 4) | ||
51 | #define NETXEN_NIU_HDRSIZE (0x1 << 6) | ||
52 | #define NETXEN_NIU_TLRSIZE (0x1 << 5) | ||
53 | |||
54 | #define lower32(x) ((u32)((x) & 0xffffffff)) | ||
55 | #define upper32(x) \ | ||
56 | ((u32)(((unsigned long long)(x) >> 32) & 0xffffffff)) | ||
57 | |||
58 | #define NETXEN_NIC_ZERO_PAUSE_ADDR 0ULL | ||
59 | #define NETXEN_NIC_UNIT_PAUSE_ADDR 0x200ULL | ||
60 | #define NETXEN_NIC_EPG_PAUSE_ADDR1 0x2200010000c28001ULL | ||
61 | #define NETXEN_NIC_EPG_PAUSE_ADDR2 0x0100088866554433ULL | ||
62 | |||
63 | #define NETXEN_NIC_WINDOW_MARGIN 0x100000 | ||
64 | |||
65 | unsigned long netxen_nic_pci_set_window(struct netxen_adapter *adapter, | ||
66 | unsigned long long addr); | ||
67 | void netxen_free_hw_resources(struct netxen_adapter *adapter); | ||
68 | |||
69 | int netxen_nic_set_mac(struct net_device *netdev, void *p) | ||
70 | { | ||
71 | struct netxen_port *port = netdev_priv(netdev); | ||
72 | struct netxen_adapter *adapter = port->adapter; | ||
73 | struct sockaddr *addr = p; | ||
74 | |||
75 | if (netif_running(netdev)) | ||
76 | return -EBUSY; | ||
77 | |||
78 | if (!is_valid_ether_addr(addr->sa_data)) | ||
79 | return -EADDRNOTAVAIL; | ||
80 | |||
81 | DPRINTK(INFO, "valid ether addr\n"); | ||
82 | memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); | ||
83 | |||
84 | if (adapter->ops->macaddr_set) | ||
85 | adapter->ops->macaddr_set(port, addr->sa_data); | ||
86 | |||
87 | return 0; | ||
88 | } | ||
89 | |||
90 | /* | ||
91 | * netxen_nic_set_multi - Multicast | ||
92 | */ | ||
93 | void netxen_nic_set_multi(struct net_device *netdev) | ||
94 | { | ||
95 | struct netxen_port *port = netdev_priv(netdev); | ||
96 | struct netxen_adapter *adapter = port->adapter; | ||
97 | struct dev_mc_list *mc_ptr; | ||
98 | __le32 netxen_mac_addr_cntl_data = 0; | ||
99 | |||
100 | mc_ptr = netdev->mc_list; | ||
101 | if (netdev->flags & IFF_PROMISC) { | ||
102 | if (adapter->ops->set_promisc) | ||
103 | adapter->ops->set_promisc(adapter, | ||
104 | port->portnum, | ||
105 | NETXEN_NIU_PROMISC_MODE); | ||
106 | } else { | ||
107 | if (adapter->ops->unset_promisc && | ||
108 | adapter->ahw.boardcfg.board_type | ||
109 | != NETXEN_BRDTYPE_P2_SB31_10G_IMEZ) | ||
110 | adapter->ops->unset_promisc(adapter, | ||
111 | port->portnum, | ||
112 | NETXEN_NIU_NON_PROMISC_MODE); | ||
113 | } | ||
114 | if (adapter->ahw.board_type == NETXEN_NIC_XGBE) { | ||
115 | netxen_nic_mcr_set_mode_select(netxen_mac_addr_cntl_data, 0x03); | ||
116 | netxen_nic_mcr_set_id_pool0(netxen_mac_addr_cntl_data, 0x00); | ||
117 | netxen_nic_mcr_set_id_pool1(netxen_mac_addr_cntl_data, 0x00); | ||
118 | netxen_nic_mcr_set_id_pool2(netxen_mac_addr_cntl_data, 0x00); | ||
119 | netxen_nic_mcr_set_id_pool3(netxen_mac_addr_cntl_data, 0x00); | ||
120 | netxen_nic_mcr_set_enable_xtnd0(netxen_mac_addr_cntl_data); | ||
121 | netxen_nic_mcr_set_enable_xtnd1(netxen_mac_addr_cntl_data); | ||
122 | netxen_nic_mcr_set_enable_xtnd2(netxen_mac_addr_cntl_data); | ||
123 | netxen_nic_mcr_set_enable_xtnd3(netxen_mac_addr_cntl_data); | ||
124 | } else { | ||
125 | netxen_nic_mcr_set_mode_select(netxen_mac_addr_cntl_data, 0x00); | ||
126 | netxen_nic_mcr_set_id_pool0(netxen_mac_addr_cntl_data, 0x00); | ||
127 | netxen_nic_mcr_set_id_pool1(netxen_mac_addr_cntl_data, 0x01); | ||
128 | netxen_nic_mcr_set_id_pool2(netxen_mac_addr_cntl_data, 0x02); | ||
129 | netxen_nic_mcr_set_id_pool3(netxen_mac_addr_cntl_data, 0x03); | ||
130 | } | ||
131 | writel(netxen_mac_addr_cntl_data, | ||
132 | NETXEN_CRB_NORMALIZE(adapter, NETXEN_MAC_ADDR_CNTL_REG)); | ||
133 | if (adapter->ahw.board_type == NETXEN_NIC_XGBE) { | ||
134 | writel(netxen_mac_addr_cntl_data, | ||
135 | NETXEN_CRB_NORMALIZE(adapter, | ||
136 | NETXEN_MULTICAST_ADDR_HI_0)); | ||
137 | } else { | ||
138 | writel(netxen_mac_addr_cntl_data, | ||
139 | NETXEN_CRB_NORMALIZE(adapter, | ||
140 | NETXEN_MULTICAST_ADDR_HI_1)); | ||
141 | } | ||
142 | netxen_mac_addr_cntl_data = 0; | ||
143 | writel(netxen_mac_addr_cntl_data, | ||
144 | NETXEN_CRB_NORMALIZE(adapter, NETXEN_NIU_GB_DROP_WRONGADDR)); | ||
145 | } | ||
146 | |||
147 | /* | ||
148 | * netxen_nic_change_mtu - Change the Maximum Transfer Unit | ||
149 | * @returns 0 on success, negative on failure | ||
150 | */ | ||
151 | int netxen_nic_change_mtu(struct net_device *netdev, int mtu) | ||
152 | { | ||
153 | struct netxen_port *port = netdev_priv(netdev); | ||
154 | struct netxen_adapter *adapter = port->adapter; | ||
155 | int eff_mtu = mtu + NETXEN_ENET_HEADER_SIZE + NETXEN_ETH_FCS_SIZE; | ||
156 | |||
157 | if ((eff_mtu > NETXEN_MAX_MTU) || (eff_mtu < NETXEN_MIN_MTU)) { | ||
158 | printk(KERN_ERR "%s: %s %d is not supported.\n", | ||
159 | netxen_nic_driver_name, netdev->name, mtu); | ||
160 | return -EINVAL; | ||
161 | } | ||
162 | |||
163 | if (adapter->ops->set_mtu) | ||
164 | adapter->ops->set_mtu(port, mtu); | ||
165 | netdev->mtu = mtu; | ||
166 | |||
167 | return 0; | ||
168 | } | ||
169 | |||
170 | /* | ||
171 | * check if the firmware has been downloaded and ready to run and | ||
172 | * setup the address for the descriptors in the adapter | ||
173 | */ | ||
174 | int netxen_nic_hw_resources(struct netxen_adapter *adapter) | ||
175 | { | ||
176 | struct netxen_hardware_context *hw = &adapter->ahw; | ||
177 | u32 state = 0; | ||
178 | void *addr; | ||
179 | void *pause_addr; | ||
180 | int loops = 0, err = 0; | ||
181 | int ctx, ring; | ||
182 | u32 card_cmdring = 0; | ||
183 | struct netxen_rcv_desc_crb *rcv_desc_crb = NULL; | ||
184 | struct netxen_recv_context *recv_ctx; | ||
185 | struct netxen_rcv_desc_ctx *rcv_desc; | ||
186 | |||
187 | DPRINTK(INFO, "crb_base: %lx %lx", NETXEN_PCI_CRBSPACE, | ||
188 | PCI_OFFSET_SECOND_RANGE(adapter, NETXEN_PCI_CRBSPACE)); | ||
189 | DPRINTK(INFO, "cam base: %lx %lx", NETXEN_CRB_CAM, | ||
190 | pci_base_offset(adapter, NETXEN_CRB_CAM)); | ||
191 | DPRINTK(INFO, "cam RAM: %lx %lx", NETXEN_CAM_RAM_BASE, | ||
192 | pci_base_offset(adapter, NETXEN_CAM_RAM_BASE)); | ||
193 | DPRINTK(INFO, "NIC base:%lx %lx\n", NIC_CRB_BASE_PORT1, | ||
194 | pci_base_offset(adapter, NIC_CRB_BASE_PORT1)); | ||
195 | |||
196 | /* Window 1 call */ | ||
197 | card_cmdring = readl(NETXEN_CRB_NORMALIZE(adapter, CRB_CMDPEG_CMDRING)); | ||
198 | |||
199 | DPRINTK(INFO, "Command Peg sends 0x%x for cmdring base\n", | ||
200 | card_cmdring); | ||
201 | |||
202 | for (ctx = 0; ctx < MAX_RCV_CTX; ++ctx) { | ||
203 | DPRINTK(INFO, "Command Peg ready..waiting for rcv peg\n"); | ||
204 | loops = 0; | ||
205 | state = 0; | ||
206 | /* Window 1 call */ | ||
207 | state = readl(NETXEN_CRB_NORMALIZE(adapter, | ||
208 | recv_crb_registers[ctx]. | ||
209 | crb_rcvpeg_state)); | ||
210 | while (state != PHAN_PEG_RCV_INITIALIZED && loops < 20) { | ||
211 | udelay(100); | ||
212 | /* Window 1 call */ | ||
213 | state = readl(NETXEN_CRB_NORMALIZE(adapter, | ||
214 | recv_crb_registers | ||
215 | [ctx]. | ||
216 | crb_rcvpeg_state)); | ||
217 | loops++; | ||
218 | } | ||
219 | if (loops >= 20) { | ||
220 | printk(KERN_ERR "Rcv Peg initialization not complete:" | ||
221 | "%x.\n", state); | ||
222 | err = -EIO; | ||
223 | return err; | ||
224 | } | ||
225 | } | ||
226 | DPRINTK(INFO, "Recieve Peg ready too. starting stuff\n"); | ||
227 | |||
228 | addr = netxen_alloc(adapter->ahw.pdev, | ||
229 | sizeof(struct cmd_desc_type0) * | ||
230 | adapter->max_tx_desc_count, | ||
231 | &hw->cmd_desc_phys_addr, &hw->cmd_desc_pdev); | ||
232 | |||
233 | if (addr == NULL) { | ||
234 | DPRINTK(ERR, "bad return from pci_alloc_consistent\n"); | ||
235 | return -ENOMEM; | ||
236 | } | ||
237 | |||
238 | pause_addr = netxen_alloc(adapter->ahw.pdev, 512, | ||
239 | (dma_addr_t *) & hw->pause_physaddr, | ||
240 | &hw->pause_pdev); | ||
241 | if (pause_addr == NULL) { | ||
242 | DPRINTK(1, ERR, "bad return from pci_alloc_consistent\n"); | ||
243 | return -ENOMEM; | ||
244 | } | ||
245 | |||
246 | hw->pauseaddr = (char *)pause_addr; | ||
247 | { | ||
248 | u64 *ptr = (u64 *) pause_addr; | ||
249 | *ptr++ = NETXEN_NIC_ZERO_PAUSE_ADDR; | ||
250 | *ptr++ = NETXEN_NIC_ZERO_PAUSE_ADDR; | ||
251 | *ptr++ = NETXEN_NIC_UNIT_PAUSE_ADDR; | ||
252 | *ptr++ = NETXEN_NIC_ZERO_PAUSE_ADDR; | ||
253 | *ptr++ = NETXEN_NIC_EPG_PAUSE_ADDR1; | ||
254 | *ptr++ = NETXEN_NIC_EPG_PAUSE_ADDR2; | ||
255 | } | ||
256 | |||
257 | hw->cmd_desc_head = (struct cmd_desc_type0 *)addr; | ||
258 | |||
259 | for (ctx = 0; ctx < MAX_RCV_CTX; ++ctx) { | ||
260 | recv_ctx = &adapter->recv_ctx[ctx]; | ||
261 | |||
262 | for (ring = 0; ring < NUM_RCV_DESC_RINGS; ring++) { | ||
263 | rcv_desc = &recv_ctx->rcv_desc[ring]; | ||
264 | addr = netxen_alloc(adapter->ahw.pdev, | ||
265 | RCV_DESC_RINGSIZE, | ||
266 | &rcv_desc->phys_addr, | ||
267 | &rcv_desc->phys_pdev); | ||
268 | if (addr == NULL) { | ||
269 | DPRINTK(ERR, "bad return from " | ||
270 | "pci_alloc_consistent\n"); | ||
271 | netxen_free_hw_resources(adapter); | ||
272 | err = -ENOMEM; | ||
273 | return err; | ||
274 | } | ||
275 | rcv_desc->desc_head = (struct rcv_desc *)addr; | ||
276 | } | ||
277 | |||
278 | addr = netxen_alloc(adapter->ahw.pdev, STATUS_DESC_RINGSIZE, | ||
279 | &recv_ctx->rcv_status_desc_phys_addr, | ||
280 | &recv_ctx->rcv_status_desc_pdev); | ||
281 | if (addr == NULL) { | ||
282 | DPRINTK(ERR, "bad return from" | ||
283 | " pci_alloc_consistent\n"); | ||
284 | netxen_free_hw_resources(adapter); | ||
285 | err = -ENOMEM; | ||
286 | return err; | ||
287 | } | ||
288 | recv_ctx->rcv_status_desc_head = (struct status_desc *)addr; | ||
289 | for (ring = 0; ring < NUM_RCV_DESC_RINGS; ring++) { | ||
290 | rcv_desc = &recv_ctx->rcv_desc[ring]; | ||
291 | rcv_desc_crb = | ||
292 | &recv_crb_registers[ctx].rcv_desc_crb[ring]; | ||
293 | DPRINTK(INFO, "ring #%d crb global ring reg 0x%x\n", | ||
294 | ring, rcv_desc_crb->crb_globalrcv_ring); | ||
295 | /* Window = 1 */ | ||
296 | writel(lower32(rcv_desc->phys_addr), | ||
297 | NETXEN_CRB_NORMALIZE(adapter, | ||
298 | rcv_desc_crb-> | ||
299 | crb_globalrcv_ring)); | ||
300 | DPRINTK(INFO, "GLOBAL_RCV_RING ctx %d, addr 0x%x" | ||
301 | " val 0x%llx," | ||
302 | " virt %p\n", ctx, | ||
303 | rcv_desc_crb->crb_globalrcv_ring, | ||
304 | (unsigned long long)rcv_desc->phys_addr, | ||
305 | +rcv_desc->desc_head); | ||
306 | } | ||
307 | |||
308 | /* Window = 1 */ | ||
309 | writel(lower32(recv_ctx->rcv_status_desc_phys_addr), | ||
310 | NETXEN_CRB_NORMALIZE(adapter, | ||
311 | recv_crb_registers[ctx]. | ||
312 | crb_rcvstatus_ring)); | ||
313 | DPRINTK(INFO, "RCVSTATUS_RING, ctx %d, addr 0x%x," | ||
314 | " val 0x%x,virt%p\n", | ||
315 | ctx, | ||
316 | recv_crb_registers[ctx].crb_rcvstatus_ring, | ||
317 | (unsigned long long)recv_ctx->rcv_status_desc_phys_addr, | ||
318 | recv_ctx->rcv_status_desc_head); | ||
319 | } | ||
320 | /* Window = 1 */ | ||
321 | writel(lower32(hw->pause_physaddr), | ||
322 | NETXEN_CRB_NORMALIZE(adapter, CRB_PAUSE_ADDR_LO)); | ||
323 | writel(upper32(hw->pause_physaddr), | ||
324 | NETXEN_CRB_NORMALIZE(adapter, CRB_PAUSE_ADDR_HI)); | ||
325 | |||
326 | writel(lower32(hw->cmd_desc_phys_addr), | ||
327 | NETXEN_CRB_NORMALIZE(adapter, CRB_HOST_CMD_ADDR_LO)); | ||
328 | writel(upper32(hw->cmd_desc_phys_addr), | ||
329 | NETXEN_CRB_NORMALIZE(adapter, CRB_HOST_CMD_ADDR_HI)); | ||
330 | return err; | ||
331 | } | ||
332 | |||
333 | void netxen_free_hw_resources(struct netxen_adapter *adapter) | ||
334 | { | ||
335 | struct netxen_recv_context *recv_ctx; | ||
336 | struct netxen_rcv_desc_ctx *rcv_desc; | ||
337 | int ctx, ring; | ||
338 | |||
339 | if (adapter->ahw.cmd_desc_head != NULL) { | ||
340 | pci_free_consistent(adapter->ahw.cmd_desc_pdev, | ||
341 | sizeof(struct cmd_desc_type0) * | ||
342 | adapter->max_tx_desc_count, | ||
343 | adapter->ahw.cmd_desc_head, | ||
344 | adapter->ahw.cmd_desc_phys_addr); | ||
345 | adapter->ahw.cmd_desc_head = NULL; | ||
346 | } | ||
347 | if (adapter->ahw.pauseaddr != NULL) { | ||
348 | pci_free_consistent(adapter->ahw.pause_pdev, 512, | ||
349 | adapter->ahw.pauseaddr, | ||
350 | adapter->ahw.pause_physaddr); | ||
351 | adapter->ahw.pauseaddr = NULL; | ||
352 | } | ||
353 | |||
354 | for (ctx = 0; ctx < MAX_RCV_CTX; ++ctx) { | ||
355 | recv_ctx = &adapter->recv_ctx[ctx]; | ||
356 | for (ring = 0; ring < NUM_RCV_DESC_RINGS; ring++) { | ||
357 | rcv_desc = &recv_ctx->rcv_desc[ring]; | ||
358 | |||
359 | if (rcv_desc->desc_head != NULL) { | ||
360 | pci_free_consistent(rcv_desc->phys_pdev, | ||
361 | RCV_DESC_RINGSIZE, | ||
362 | rcv_desc->desc_head, | ||
363 | rcv_desc->phys_addr); | ||
364 | rcv_desc->desc_head = NULL; | ||
365 | } | ||
366 | } | ||
367 | |||
368 | if (recv_ctx->rcv_status_desc_head != NULL) { | ||
369 | pci_free_consistent(recv_ctx->rcv_status_desc_pdev, | ||
370 | STATUS_DESC_RINGSIZE, | ||
371 | recv_ctx->rcv_status_desc_head, | ||
372 | recv_ctx-> | ||
373 | rcv_status_desc_phys_addr); | ||
374 | recv_ctx->rcv_status_desc_head = NULL; | ||
375 | } | ||
376 | } | ||
377 | } | ||
378 | |||
379 | void netxen_tso_check(struct netxen_adapter *adapter, | ||
380 | struct cmd_desc_type0 *desc, struct sk_buff *skb) | ||
381 | { | ||
382 | if (desc->mss) { | ||
383 | desc->total_hdr_length = sizeof(struct ethhdr) + | ||
384 | ((skb->nh.iph)->ihl * sizeof(u32)) + | ||
385 | ((skb->h.th)->doff * sizeof(u32)); | ||
386 | desc->opcode = TX_TCP_LSO; | ||
387 | } else if (skb->ip_summed == CHECKSUM_COMPLETE) { | ||
388 | if (skb->nh.iph->protocol == IPPROTO_TCP) { | ||
389 | desc->opcode = TX_TCP_PKT; | ||
390 | } else if (skb->nh.iph->protocol == IPPROTO_UDP) { | ||
391 | desc->opcode = TX_UDP_PKT; | ||
392 | } else { | ||
393 | return; | ||
394 | } | ||
395 | } | ||
396 | adapter->stats.xmitcsummed++; | ||
397 | CMD_DESC_TCP_HDR_OFFSET_WRT(desc, skb->h.raw - skb->data); | ||
398 | desc->length_tcp_hdr = cpu_to_le32(desc->length_tcp_hdr); | ||
399 | desc->ip_hdr_offset = skb->nh.raw - skb->data; | ||
400 | } | ||
401 | |||
402 | int netxen_is_flash_supported(struct netxen_adapter *adapter) | ||
403 | { | ||
404 | const int locs[] = { 0, 0x4, 0x100, 0x4000, 0x4128 }; | ||
405 | int addr, val01, val02, i, j; | ||
406 | |||
407 | /* if the flash size less than 4Mb, make huge war cry and die */ | ||
408 | for (j = 1; j < 4; j++) { | ||
409 | addr = j * NETXEN_NIC_WINDOW_MARGIN; | ||
410 | for (i = 0; i < (sizeof(locs) / sizeof(locs[0])); i++) { | ||
411 | if (netxen_rom_fast_read(adapter, locs[i], &val01) == 0 | ||
412 | && netxen_rom_fast_read(adapter, (addr + locs[i]), | ||
413 | &val02) == 0) { | ||
414 | if (val01 == val02) | ||
415 | return -1; | ||
416 | } else | ||
417 | return -1; | ||
418 | } | ||
419 | } | ||
420 | |||
421 | return 0; | ||
422 | } | ||
423 | |||
424 | static int netxen_get_flash_block(struct netxen_adapter *adapter, int base, | ||
425 | int size, u32 * buf) | ||
426 | { | ||
427 | int i, addr; | ||
428 | u32 *ptr32; | ||
429 | |||
430 | addr = base; | ||
431 | ptr32 = buf; | ||
432 | for (i = 0; i < size / sizeof(u32); i++) { | ||
433 | if (netxen_rom_fast_read(adapter, addr, ptr32) == -1) | ||
434 | return -1; | ||
435 | ptr32++; | ||
436 | addr += sizeof(u32); | ||
437 | } | ||
438 | if ((char *)buf + size > (char *)ptr32) { | ||
439 | u32 local; | ||
440 | |||
441 | if (netxen_rom_fast_read(adapter, addr, &local) == -1) | ||
442 | return -1; | ||
443 | memcpy(ptr32, &local, (char *)buf + size - (char *)ptr32); | ||
444 | } | ||
445 | |||
446 | return 0; | ||
447 | } | ||
448 | |||
449 | int netxen_get_flash_mac_addr(struct netxen_adapter *adapter, u64 mac[]) | ||
450 | { | ||
451 | u32 *pmac = (u32 *) & mac[0]; | ||
452 | |||
453 | if (netxen_get_flash_block(adapter, | ||
454 | USER_START + | ||
455 | offsetof(struct netxen_new_user_info, | ||
456 | mac_addr), | ||
457 | FLASH_NUM_PORTS * sizeof(u64), pmac) == -1) { | ||
458 | return -1; | ||
459 | } | ||
460 | if (*mac == ~0ULL) { | ||
461 | if (netxen_get_flash_block(adapter, | ||
462 | USER_START_OLD + | ||
463 | offsetof(struct netxen_user_old_info, | ||
464 | mac_addr), | ||
465 | FLASH_NUM_PORTS * sizeof(u64), | ||
466 | pmac) == -1) | ||
467 | return -1; | ||
468 | if (*mac == ~0ULL) | ||
469 | return -1; | ||
470 | } | ||
471 | return 0; | ||
472 | } | ||
473 | |||
474 | /* | ||
475 | * Changes the CRB window to the specified window. | ||
476 | */ | ||
477 | void netxen_nic_pci_change_crbwindow(struct netxen_adapter *adapter, u32 wndw) | ||
478 | { | ||
479 | void __iomem *offset; | ||
480 | u32 tmp; | ||
481 | int count = 0; | ||
482 | |||
483 | if (adapter->curr_window == wndw) | ||
484 | return; | ||
485 | |||
486 | /* | ||
487 | * Move the CRB window. | ||
488 | * We need to write to the "direct access" region of PCI | ||
489 | * to avoid a race condition where the window register has | ||
490 | * not been successfully written across CRB before the target | ||
491 | * register address is received by PCI. The direct region bypasses | ||
492 | * the CRB bus. | ||
493 | */ | ||
494 | offset = | ||
495 | PCI_OFFSET_SECOND_RANGE(adapter, | ||
496 | NETXEN_PCIX_PH_REG(PCIX_CRB_WINDOW)); | ||
497 | |||
498 | if (wndw & 0x1) | ||
499 | wndw = NETXEN_WINDOW_ONE; | ||
500 | |||
501 | writel(wndw, offset); | ||
502 | |||
503 | /* MUST make sure window is set before we forge on... */ | ||
504 | while ((tmp = readl(offset)) != wndw) { | ||
505 | printk(KERN_WARNING "%s: %s WARNING: CRB window value not " | ||
506 | "registered properly: 0x%08x.\n", | ||
507 | netxen_nic_driver_name, __FUNCTION__, tmp); | ||
508 | mdelay(1); | ||
509 | if (count >= 10) | ||
510 | break; | ||
511 | count++; | ||
512 | } | ||
513 | |||
514 | adapter->curr_window = wndw; | ||
515 | } | ||
516 | |||
517 | void netxen_load_firmware(struct netxen_adapter *adapter) | ||
518 | { | ||
519 | int i; | ||
520 | long data, size = 0; | ||
521 | long flashaddr = NETXEN_FLASH_BASE, memaddr = NETXEN_PHANTOM_MEM_BASE; | ||
522 | u64 off; | ||
523 | void __iomem *addr; | ||
524 | |||
525 | size = NETXEN_FIRMWARE_LEN; | ||
526 | writel(1, NETXEN_CRB_NORMALIZE(adapter, NETXEN_ROMUSB_GLB_CAS_RST)); | ||
527 | |||
528 | for (i = 0; i < size; i++) { | ||
529 | if (netxen_rom_fast_read(adapter, flashaddr, (int *)&data) != 0) { | ||
530 | DPRINTK(ERR, | ||
531 | "Error in netxen_rom_fast_read(). Will skip" | ||
532 | "loading flash image\n"); | ||
533 | return; | ||
534 | } | ||
535 | off = netxen_nic_pci_set_window(adapter, memaddr); | ||
536 | addr = pci_base_offset(adapter, off); | ||
537 | writel(data, addr); | ||
538 | flashaddr += 4; | ||
539 | memaddr += 4; | ||
540 | } | ||
541 | udelay(100); | ||
542 | /* make sure Casper is powered on */ | ||
543 | writel(0x3fff, | ||
544 | NETXEN_CRB_NORMALIZE(adapter, NETXEN_ROMUSB_GLB_CHIP_CLK_CTRL)); | ||
545 | writel(0, NETXEN_CRB_NORMALIZE(adapter, NETXEN_ROMUSB_GLB_CAS_RST)); | ||
546 | |||
547 | udelay(100); | ||
548 | } | ||
549 | |||
550 | int | ||
551 | netxen_nic_hw_write_wx(struct netxen_adapter *adapter, u64 off, void *data, | ||
552 | int len) | ||
553 | { | ||
554 | void __iomem *addr; | ||
555 | |||
556 | if (ADDR_IN_WINDOW1(off)) { | ||
557 | addr = NETXEN_CRB_NORMALIZE(adapter, off); | ||
558 | } else { /* Window 0 */ | ||
559 | addr = pci_base_offset(adapter, off); | ||
560 | netxen_nic_pci_change_crbwindow(adapter, 0); | ||
561 | } | ||
562 | |||
563 | DPRINTK(INFO, "writing to base %lx offset %llx addr %p" | ||
564 | " data %llx len %d\n", | ||
565 | pci_base(adapter, off), off, addr, | ||
566 | *(unsigned long long *)data, len); | ||
567 | if (!addr) { | ||
568 | netxen_nic_pci_change_crbwindow(adapter, 1); | ||
569 | return 1; | ||
570 | } | ||
571 | |||
572 | switch (len) { | ||
573 | case 1: | ||
574 | writeb(*(u8 *) data, addr); | ||
575 | break; | ||
576 | case 2: | ||
577 | writew(*(u16 *) data, addr); | ||
578 | break; | ||
579 | case 4: | ||
580 | writel(*(u32 *) data, addr); | ||
581 | break; | ||
582 | case 8: | ||
583 | writeq(*(u64 *) data, addr); | ||
584 | break; | ||
585 | default: | ||
586 | DPRINTK(INFO, | ||
587 | "writing data %lx to offset %llx, num words=%d\n", | ||
588 | *(unsigned long *)data, off, (len >> 3)); | ||
589 | |||
590 | netxen_nic_hw_block_write64((u64 __iomem *) data, addr, | ||
591 | (len >> 3)); | ||
592 | break; | ||
593 | } | ||
594 | if (!ADDR_IN_WINDOW1(off)) | ||
595 | netxen_nic_pci_change_crbwindow(adapter, 1); | ||
596 | |||
597 | return 0; | ||
598 | } | ||
599 | |||
600 | int | ||
601 | netxen_nic_hw_read_wx(struct netxen_adapter *adapter, u64 off, void *data, | ||
602 | int len) | ||
603 | { | ||
604 | void __iomem *addr; | ||
605 | |||
606 | if (ADDR_IN_WINDOW1(off)) { /* Window 1 */ | ||
607 | addr = NETXEN_CRB_NORMALIZE(adapter, off); | ||
608 | } else { /* Window 0 */ | ||
609 | addr = pci_base_offset(adapter, off); | ||
610 | netxen_nic_pci_change_crbwindow(adapter, 0); | ||
611 | } | ||
612 | |||
613 | DPRINTK(INFO, "reading from base %lx offset %llx addr %p\n", | ||
614 | pci_base(adapter, off), off, addr); | ||
615 | if (!addr) { | ||
616 | netxen_nic_pci_change_crbwindow(adapter, 1); | ||
617 | return 1; | ||
618 | } | ||
619 | switch (len) { | ||
620 | case 1: | ||
621 | *(u8 *) data = readb(addr); | ||
622 | break; | ||
623 | case 2: | ||
624 | *(u16 *) data = readw(addr); | ||
625 | break; | ||
626 | case 4: | ||
627 | *(u32 *) data = readl(addr); | ||
628 | break; | ||
629 | case 8: | ||
630 | *(u64 *) data = readq(addr); | ||
631 | break; | ||
632 | default: | ||
633 | netxen_nic_hw_block_read64((u64 __iomem *) data, addr, | ||
634 | (len >> 3)); | ||
635 | break; | ||
636 | } | ||
637 | DPRINTK(INFO, "read %lx\n", *(unsigned long *)data); | ||
638 | |||
639 | if (!ADDR_IN_WINDOW1(off)) | ||
640 | netxen_nic_pci_change_crbwindow(adapter, 1); | ||
641 | |||
642 | return 0; | ||
643 | } | ||
644 | |||
645 | void netxen_nic_reg_write(struct netxen_adapter *adapter, u64 off, u32 val) | ||
646 | { /* Only for window 1 */ | ||
647 | void __iomem *addr; | ||
648 | |||
649 | addr = NETXEN_CRB_NORMALIZE(adapter, off); | ||
650 | DPRINTK(INFO, "writing to base %lx offset %llx addr %p data %x\n", | ||
651 | pci_base(adapter, off), off, addr); | ||
652 | writel(val, addr); | ||
653 | |||
654 | } | ||
655 | |||
656 | int netxen_nic_reg_read(struct netxen_adapter *adapter, u64 off) | ||
657 | { /* Only for window 1 */ | ||
658 | void __iomem *addr; | ||
659 | int val; | ||
660 | |||
661 | addr = NETXEN_CRB_NORMALIZE(adapter, off); | ||
662 | DPRINTK(INFO, "reading from base %lx offset %llx addr %p\n", | ||
663 | adapter->ahw.pci_base, off, addr); | ||
664 | val = readl(addr); | ||
665 | writel(val, addr); | ||
666 | |||
667 | return val; | ||
668 | } | ||
669 | |||
670 | /* Change the window to 0, write and change back to window 1. */ | ||
671 | void netxen_nic_write_w0(struct netxen_adapter *adapter, u32 index, u32 value) | ||
672 | { | ||
673 | void __iomem *addr; | ||
674 | |||
675 | netxen_nic_pci_change_crbwindow(adapter, 0); | ||
676 | addr = pci_base_offset(adapter, index); | ||
677 | writel(value, addr); | ||
678 | netxen_nic_pci_change_crbwindow(adapter, 1); | ||
679 | } | ||
680 | |||
681 | /* Change the window to 0, read and change back to window 1. */ | ||
682 | void netxen_nic_read_w0(struct netxen_adapter *adapter, u32 index, u32 * value) | ||
683 | { | ||
684 | void __iomem *addr; | ||
685 | |||
686 | addr = pci_base_offset(adapter, index); | ||
687 | |||
688 | netxen_nic_pci_change_crbwindow(adapter, 0); | ||
689 | *value = readl(addr); | ||
690 | netxen_nic_pci_change_crbwindow(adapter, 1); | ||
691 | } | ||
692 | |||
693 | int netxen_pci_set_window_warning_count = 0; | ||
694 | |||
695 | unsigned long | ||
696 | netxen_nic_pci_set_window(struct netxen_adapter *adapter, | ||
697 | unsigned long long addr) | ||
698 | { | ||
699 | static int ddr_mn_window = -1; | ||
700 | static int qdr_sn_window = -1; | ||
701 | int window; | ||
702 | |||
703 | if (ADDR_IN_RANGE(addr, NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX)) { | ||
704 | /* DDR network side */ | ||
705 | addr -= NETXEN_ADDR_DDR_NET; | ||
706 | window = (addr >> 25) & 0x3ff; | ||
707 | if (ddr_mn_window != window) { | ||
708 | ddr_mn_window = window; | ||
709 | writel(window, PCI_OFFSET_SECOND_RANGE(adapter, | ||
710 | NETXEN_PCIX_PH_REG | ||
711 | (PCIX_MN_WINDOW))); | ||
712 | /* MUST make sure window is set before we forge on... */ | ||
713 | readl(PCI_OFFSET_SECOND_RANGE(adapter, | ||
714 | NETXEN_PCIX_PH_REG | ||
715 | (PCIX_MN_WINDOW))); | ||
716 | } | ||
717 | addr -= (window * NETXEN_WINDOW_ONE); | ||
718 | addr += NETXEN_PCI_DDR_NET; | ||
719 | } else if (ADDR_IN_RANGE(addr, NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX)) { | ||
720 | addr -= NETXEN_ADDR_OCM0; | ||
721 | addr += NETXEN_PCI_OCM0; | ||
722 | } else if (ADDR_IN_RANGE(addr, NETXEN_ADDR_OCM1, NETXEN_ADDR_OCM1_MAX)) { | ||
723 | addr -= NETXEN_ADDR_OCM1; | ||
724 | addr += NETXEN_PCI_OCM1; | ||
725 | } else | ||
726 | if (ADDR_IN_RANGE | ||
727 | (addr, NETXEN_ADDR_QDR_NET, NETXEN_ADDR_QDR_NET_MAX)) { | ||
728 | /* QDR network side */ | ||
729 | addr -= NETXEN_ADDR_QDR_NET; | ||
730 | window = (addr >> 22) & 0x3f; | ||
731 | if (qdr_sn_window != window) { | ||
732 | qdr_sn_window = window; | ||
733 | writel((window << 22), | ||
734 | PCI_OFFSET_SECOND_RANGE(adapter, | ||
735 | NETXEN_PCIX_PH_REG | ||
736 | (PCIX_SN_WINDOW))); | ||
737 | /* MUST make sure window is set before we forge on... */ | ||
738 | readl(PCI_OFFSET_SECOND_RANGE(adapter, | ||
739 | NETXEN_PCIX_PH_REG | ||
740 | (PCIX_SN_WINDOW))); | ||
741 | } | ||
742 | addr -= (window * 0x400000); | ||
743 | addr += NETXEN_PCI_QDR_NET; | ||
744 | } else { | ||
745 | /* | ||
746 | * peg gdb frequently accesses memory that doesn't exist, | ||
747 | * this limits the chit chat so debugging isn't slowed down. | ||
748 | */ | ||
749 | if ((netxen_pci_set_window_warning_count++ < 8) | ||
750 | || (netxen_pci_set_window_warning_count % 64 == 0)) | ||
751 | printk("%s: Warning:netxen_nic_pci_set_window()" | ||
752 | " Unknown address range!\n", | ||
753 | netxen_nic_driver_name); | ||
754 | |||
755 | } | ||
756 | return addr; | ||
757 | } | ||
758 | |||
759 | int netxen_nic_get_board_info(struct netxen_adapter *adapter) | ||
760 | { | ||
761 | int rv = 0; | ||
762 | int addr = BRDCFG_START; | ||
763 | struct netxen_board_info *boardinfo; | ||
764 | int index; | ||
765 | u32 *ptr32; | ||
766 | |||
767 | boardinfo = &adapter->ahw.boardcfg; | ||
768 | ptr32 = (u32 *) boardinfo; | ||
769 | |||
770 | for (index = 0; index < sizeof(struct netxen_board_info) / sizeof(u32); | ||
771 | index++) { | ||
772 | if (netxen_rom_fast_read(adapter, addr, ptr32) == -1) { | ||
773 | return -EIO; | ||
774 | } | ||
775 | ptr32++; | ||
776 | addr += sizeof(u32); | ||
777 | } | ||
778 | if (boardinfo->magic != NETXEN_BDINFO_MAGIC) { | ||
779 | printk("%s: ERROR reading %s board config." | ||
780 | " Read %x, expected %x\n", netxen_nic_driver_name, | ||
781 | netxen_nic_driver_name, | ||
782 | boardinfo->magic, NETXEN_BDINFO_MAGIC); | ||
783 | rv = -1; | ||
784 | } | ||
785 | if (boardinfo->header_version != NETXEN_BDINFO_VERSION) { | ||
786 | printk("%s: Unknown board config version." | ||
787 | " Read %x, expected %x\n", netxen_nic_driver_name, | ||
788 | boardinfo->header_version, NETXEN_BDINFO_VERSION); | ||
789 | rv = -1; | ||
790 | } | ||
791 | |||
792 | DPRINTK(INFO, "Discovered board type:0x%x ", boardinfo->board_type); | ||
793 | switch ((netxen_brdtype_t) boardinfo->board_type) { | ||
794 | case NETXEN_BRDTYPE_P2_SB35_4G: | ||
795 | adapter->ahw.board_type = NETXEN_NIC_GBE; | ||
796 | break; | ||
797 | case NETXEN_BRDTYPE_P2_SB31_10G: | ||
798 | case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ: | ||
799 | case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ: | ||
800 | case NETXEN_BRDTYPE_P2_SB31_10G_CX4: | ||
801 | adapter->ahw.board_type = NETXEN_NIC_XGBE; | ||
802 | break; | ||
803 | case NETXEN_BRDTYPE_P1_BD: | ||
804 | case NETXEN_BRDTYPE_P1_SB: | ||
805 | case NETXEN_BRDTYPE_P1_SMAX: | ||
806 | case NETXEN_BRDTYPE_P1_SOCK: | ||
807 | adapter->ahw.board_type = NETXEN_NIC_GBE; | ||
808 | break; | ||
809 | default: | ||
810 | printk("%s: Unknown(%x)\n", netxen_nic_driver_name, | ||
811 | boardinfo->board_type); | ||
812 | break; | ||
813 | } | ||
814 | |||
815 | return rv; | ||
816 | } | ||
817 | |||
818 | /* NIU access sections */ | ||
819 | |||
820 | int netxen_nic_set_mtu_gb(struct netxen_port *port, int new_mtu) | ||
821 | { | ||
822 | struct netxen_adapter *adapter = port->adapter; | ||
823 | netxen_nic_write_w0(adapter, | ||
824 | NETXEN_NIU_GB_MAX_FRAME_SIZE(port->portnum), | ||
825 | new_mtu); | ||
826 | return 0; | ||
827 | } | ||
828 | |||
829 | int netxen_nic_set_mtu_xgb(struct netxen_port *port, int new_mtu) | ||
830 | { | ||
831 | struct netxen_adapter *adapter = port->adapter; | ||
832 | new_mtu += NETXEN_NIU_HDRSIZE + NETXEN_NIU_TLRSIZE; | ||
833 | netxen_nic_write_w0(adapter, NETXEN_NIU_XGE_MAX_FRAME_SIZE, new_mtu); | ||
834 | return 0; | ||
835 | } | ||
836 | |||
837 | void netxen_nic_init_niu_gb(struct netxen_adapter *adapter) | ||
838 | { | ||
839 | int portno; | ||
840 | for (portno = 0; portno < NETXEN_NIU_MAX_GBE_PORTS; portno++) | ||
841 | netxen_niu_gbe_init_port(adapter, portno); | ||
842 | } | ||
843 | |||
844 | void netxen_nic_stop_all_ports(struct netxen_adapter *adapter) | ||
845 | { | ||
846 | int port_nr; | ||
847 | struct netxen_port *port; | ||
848 | |||
849 | for (port_nr = 0; port_nr < adapter->ahw.max_ports; port_nr++) { | ||
850 | port = adapter->port[port_nr]; | ||
851 | if (adapter->ops->stop_port) | ||
852 | adapter->ops->stop_port(adapter, port->portnum); | ||
853 | } | ||
854 | } | ||
855 | |||
856 | void | ||
857 | netxen_crb_writelit_adapter(struct netxen_adapter *adapter, unsigned long off, | ||
858 | int data) | ||
859 | { | ||
860 | void __iomem *addr; | ||
861 | |||
862 | if (ADDR_IN_WINDOW1(off)) { | ||
863 | writel(data, NETXEN_CRB_NORMALIZE(adapter, off)); | ||
864 | } else { | ||
865 | netxen_nic_pci_change_crbwindow(adapter, 0); | ||
866 | addr = pci_base_offset(adapter, off); | ||
867 | writel(data, addr); | ||
868 | netxen_nic_pci_change_crbwindow(adapter, 1); | ||
869 | } | ||
870 | } | ||
871 | |||
872 | void netxen_nic_set_link_parameters(struct netxen_port *port) | ||
873 | { | ||
874 | struct netxen_adapter *adapter = port->adapter; | ||
875 | __le32 status; | ||
876 | u16 autoneg; | ||
877 | __le32 mode; | ||
878 | |||
879 | netxen_nic_read_w0(adapter, NETXEN_NIU_MODE, &mode); | ||
880 | if (netxen_get_niu_enable_ge(mode)) { /* Gb 10/100/1000 Mbps mode */ | ||
881 | if (adapter->ops->phy_read | ||
882 | && adapter->ops-> | ||
883 | phy_read(adapter, port->portnum, | ||
884 | NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS, | ||
885 | &status) == 0) { | ||
886 | if (netxen_get_phy_link(status)) { | ||
887 | switch (netxen_get_phy_speed(status)) { | ||
888 | case 0: | ||
889 | port->link_speed = SPEED_10; | ||
890 | break; | ||
891 | case 1: | ||
892 | port->link_speed = SPEED_100; | ||
893 | break; | ||
894 | case 2: | ||
895 | port->link_speed = SPEED_1000; | ||
896 | break; | ||
897 | default: | ||
898 | port->link_speed = -1; | ||
899 | break; | ||
900 | } | ||
901 | switch (netxen_get_phy_duplex(status)) { | ||
902 | case 0: | ||
903 | port->link_duplex = DUPLEX_HALF; | ||
904 | break; | ||
905 | case 1: | ||
906 | port->link_duplex = DUPLEX_FULL; | ||
907 | break; | ||
908 | default: | ||
909 | port->link_duplex = -1; | ||
910 | break; | ||
911 | } | ||
912 | if (adapter->ops->phy_read | ||
913 | && adapter->ops-> | ||
914 | phy_read(adapter, port->portnum, | ||
915 | NETXEN_NIU_GB_MII_MGMT_ADDR_AUTONEG, | ||
916 | (__le32 *) & autoneg) != 0) | ||
917 | port->link_autoneg = autoneg; | ||
918 | } else | ||
919 | goto link_down; | ||
920 | } else { | ||
921 | link_down: | ||
922 | port->link_speed = -1; | ||
923 | port->link_duplex = -1; | ||
924 | } | ||
925 | } | ||
926 | } | ||
927 | |||
928 | void netxen_nic_flash_print(struct netxen_adapter *adapter) | ||
929 | { | ||
930 | int valid = 1; | ||
931 | u32 fw_major = 0; | ||
932 | u32 fw_minor = 0; | ||
933 | u32 fw_build = 0; | ||
934 | char brd_name[NETXEN_MAX_SHORT_NAME]; | ||
935 | struct netxen_new_user_info user_info; | ||
936 | int i, addr = USER_START; | ||
937 | u32 *ptr32; | ||
938 | |||
939 | struct netxen_board_info *board_info = &(adapter->ahw.boardcfg); | ||
940 | if (board_info->magic != NETXEN_BDINFO_MAGIC) { | ||
941 | printk | ||
942 | ("NetXen Unknown board config, Read 0x%x expected as 0x%x\n", | ||
943 | board_info->magic, NETXEN_BDINFO_MAGIC); | ||
944 | valid = 0; | ||
945 | } | ||
946 | if (board_info->header_version != NETXEN_BDINFO_VERSION) { | ||
947 | printk("NetXen Unknown board config version." | ||
948 | " Read %x, expected %x\n", | ||
949 | board_info->header_version, NETXEN_BDINFO_VERSION); | ||
950 | valid = 0; | ||
951 | } | ||
952 | if (valid) { | ||
953 | ptr32 = (u32 *) & user_info; | ||
954 | for (i = 0; | ||
955 | i < sizeof(struct netxen_new_user_info) / sizeof(u32); | ||
956 | i++) { | ||
957 | if (netxen_rom_fast_read(adapter, addr, ptr32) == -1) { | ||
958 | printk("%s: ERROR reading %s board userarea.\n", | ||
959 | netxen_nic_driver_name, | ||
960 | netxen_nic_driver_name); | ||
961 | return; | ||
962 | } | ||
963 | ptr32++; | ||
964 | addr += sizeof(u32); | ||
965 | } | ||
966 | get_brd_name_by_type(board_info->board_type, brd_name); | ||
967 | |||
968 | printk("NetXen %s Board S/N %s Chip id 0x%x\n", | ||
969 | brd_name, user_info.serial_num, board_info->chip_id); | ||
970 | |||
971 | printk("NetXen %s Board #%d, Chip id 0x%x\n", | ||
972 | board_info->board_type == 0x0b ? "XGB" : "GBE", | ||
973 | board_info->board_num, board_info->chip_id); | ||
974 | fw_major = readl(NETXEN_CRB_NORMALIZE(adapter, | ||
975 | NETXEN_FW_VERSION_MAJOR)); | ||
976 | fw_minor = readl(NETXEN_CRB_NORMALIZE(adapter, | ||
977 | NETXEN_FW_VERSION_MINOR)); | ||
978 | fw_build = | ||
979 | readl(NETXEN_CRB_NORMALIZE(adapter, NETXEN_FW_VERSION_SUB)); | ||
980 | |||
981 | printk("NetXen Firmware version %d.%d.%d\n", fw_major, fw_minor, | ||
982 | fw_build); | ||
983 | } | ||
984 | if (fw_major != _NETXEN_NIC_LINUX_MAJOR) { | ||
985 | printk(KERN_ERR "The mismatch in driver version and firmware " | ||
986 | "version major number\n" | ||
987 | "Driver version major number = %d \t" | ||
988 | "Firmware version major number = %d \n", | ||
989 | _NETXEN_NIC_LINUX_MAJOR, fw_major); | ||
990 | adapter->driver_mismatch = 1; | ||
991 | } | ||
992 | if (fw_minor != _NETXEN_NIC_LINUX_MINOR) { | ||
993 | printk(KERN_ERR "The mismatch in driver version and firmware " | ||
994 | "version minor number\n" | ||
995 | "Driver version minor number = %d \t" | ||
996 | "Firmware version minor number = %d \n", | ||
997 | _NETXEN_NIC_LINUX_MINOR, fw_minor); | ||
998 | adapter->driver_mismatch = 1; | ||
999 | } | ||
1000 | if (adapter->driver_mismatch) | ||
1001 | printk(KERN_INFO "Use the driver with version no %d.%d.xxx\n", | ||
1002 | fw_major, fw_minor); | ||
1003 | } | ||
1004 | |||
1005 | int netxen_crb_read_val(struct netxen_adapter *adapter, unsigned long off) | ||
1006 | { | ||
1007 | int data; | ||
1008 | netxen_nic_hw_read_wx(adapter, off, &data, 4); | ||
1009 | return data; | ||
1010 | } | ||
diff --git a/drivers/net/netxen/netxen_nic_hw.h b/drivers/net/netxen/netxen_nic_hw.h new file mode 100644 index 000000000000..201a636b7ab8 --- /dev/null +++ b/drivers/net/netxen/netxen_nic_hw.h | |||
@@ -0,0 +1,482 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2003 - 2006 NetXen, Inc. | ||
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 LICENSE. | ||
22 | * | ||
23 | * Contact Information: | ||
24 | * info@netxen.com | ||
25 | * NetXen, | ||
26 | * 3965 Freedom Circle, Fourth floor, | ||
27 | * Santa Clara, CA 95054 | ||
28 | * | ||
29 | * | ||
30 | * Structures, enums, and macros for the MAC | ||
31 | * | ||
32 | */ | ||
33 | |||
34 | #ifndef __NETXEN_NIC_HW_H_ | ||
35 | #define __NETXEN_NIC_HW_H_ | ||
36 | |||
37 | #include "netxen_nic_hdr.h" | ||
38 | |||
39 | /* Hardware memory size of 128 meg */ | ||
40 | #define NETXEN_MEMADDR_MAX (128 * 1024 * 1024) | ||
41 | |||
42 | #ifndef readq | ||
43 | static inline u64 readq(void __iomem * addr) | ||
44 | { | ||
45 | return readl(addr) | (((u64) readl(addr + 4)) << 32LL); | ||
46 | } | ||
47 | #endif | ||
48 | |||
49 | #ifndef writeq | ||
50 | static inline void writeq(u64 val, void __iomem * addr) | ||
51 | { | ||
52 | writel(((u32) (val)), (addr)); | ||
53 | writel(((u32) (val >> 32)), (addr + 4)); | ||
54 | } | ||
55 | #endif | ||
56 | |||
57 | static inline void netxen_nic_hw_block_write64(u64 __iomem * data_ptr, | ||
58 | u64 __iomem * addr, | ||
59 | int num_words) | ||
60 | { | ||
61 | int num; | ||
62 | for (num = 0; num < num_words; num++) { | ||
63 | writeq(readq((void __iomem *)data_ptr), addr); | ||
64 | addr++; | ||
65 | data_ptr++; | ||
66 | } | ||
67 | } | ||
68 | |||
69 | static inline void netxen_nic_hw_block_read64(u64 __iomem * data_ptr, | ||
70 | u64 __iomem * addr, int num_words) | ||
71 | { | ||
72 | int num; | ||
73 | for (num = 0; num < num_words; num++) { | ||
74 | writeq(readq((void __iomem *)addr), data_ptr); | ||
75 | addr++; | ||
76 | data_ptr++; | ||
77 | } | ||
78 | |||
79 | } | ||
80 | |||
81 | struct netxen_adapter; | ||
82 | |||
83 | #define NETXEN_PCI_MAPSIZE_BYTES (NETXEN_PCI_MAPSIZE << 20) | ||
84 | |||
85 | #define NETXEN_NIC_LOCKED_READ_REG(X, Y) \ | ||
86 | addr = pci_base_offset(adapter, (X)); \ | ||
87 | *(u32 *)Y = readl(addr); | ||
88 | |||
89 | struct netxen_port; | ||
90 | void netxen_nic_set_link_parameters(struct netxen_port *port); | ||
91 | void netxen_nic_flash_print(struct netxen_adapter *adapter); | ||
92 | int netxen_nic_hw_write_wx(struct netxen_adapter *adapter, u64 off, | ||
93 | void *data, int len); | ||
94 | void netxen_crb_writelit_adapter(struct netxen_adapter *adapter, | ||
95 | unsigned long off, int data); | ||
96 | int netxen_nic_hw_read_wx(struct netxen_adapter *adapter, u64 off, | ||
97 | void *data, int len); | ||
98 | |||
99 | typedef u8 netxen_ethernet_macaddr_t[6]; | ||
100 | |||
101 | /* Nibble or Byte mode for phy interface (GbE mode only) */ | ||
102 | typedef enum { | ||
103 | NETXEN_NIU_10_100_MB = 0, | ||
104 | NETXEN_NIU_1000_MB | ||
105 | } netxen_niu_gbe_ifmode_t; | ||
106 | |||
107 | #define _netxen_crb_get_bit(var, bit) ((var >> bit) & 0x1) | ||
108 | |||
109 | /* | ||
110 | * NIU GB MAC Config Register 0 (applies to GB0, GB1, GB2, GB3) | ||
111 | * | ||
112 | * Bit 0 : enable_tx => 1:enable frame xmit, 0:disable | ||
113 | * Bit 1 : tx_synced => R/O: xmit enable synched to xmit stream | ||
114 | * Bit 2 : enable_rx => 1:enable frame recv, 0:disable | ||
115 | * Bit 3 : rx_synced => R/O: recv enable synched to recv stream | ||
116 | * Bit 4 : tx_flowctl => 1:enable pause frame generation, 0:disable | ||
117 | * Bit 5 : rx_flowctl => 1:act on recv'd pause frames, 0:ignore | ||
118 | * Bit 8 : loopback => 1:loop MAC xmits to MAC recvs, 0:normal | ||
119 | * Bit 16: tx_reset_pb => 1:reset frame xmit protocol blk, 0:no-op | ||
120 | * Bit 17: rx_reset_pb => 1:reset frame recv protocol blk, 0:no-op | ||
121 | * Bit 18: tx_reset_mac => 1:reset data/ctl multiplexer blk, 0:no-op | ||
122 | * Bit 19: rx_reset_mac => 1:reset ctl frames & timers blk, 0:no-op | ||
123 | * Bit 31: soft_reset => 1:reset the MAC and the SERDES, 0:no-op | ||
124 | */ | ||
125 | |||
126 | #define netxen_gb_enable_tx(config_word) \ | ||
127 | set_bit(0, (unsigned long*)(&config_word)) | ||
128 | #define netxen_gb_enable_rx(config_word) \ | ||
129 | set_bit(2, (unsigned long*)(&config_word)) | ||
130 | #define netxen_gb_tx_flowctl(config_word) \ | ||
131 | set_bit(4, (unsigned long*)(&config_word)) | ||
132 | #define netxen_gb_rx_flowctl(config_word) \ | ||
133 | set_bit(5, (unsigned long*)(&config_word)) | ||
134 | #define netxen_gb_tx_reset_pb(config_word) \ | ||
135 | set_bit(16, (unsigned long*)(&config_word)) | ||
136 | #define netxen_gb_rx_reset_pb(config_word) \ | ||
137 | set_bit(17, (unsigned long*)(&config_word)) | ||
138 | #define netxen_gb_tx_reset_mac(config_word) \ | ||
139 | set_bit(18, (unsigned long*)(&config_word)) | ||
140 | #define netxen_gb_rx_reset_mac(config_word) \ | ||
141 | set_bit(19, (unsigned long*)(&config_word)) | ||
142 | #define netxen_gb_soft_reset(config_word) \ | ||
143 | set_bit(31, (unsigned long*)(&config_word)) | ||
144 | |||
145 | #define netxen_gb_unset_tx_flowctl(config_word) \ | ||
146 | clear_bit(4, (unsigned long *)(&config_word)) | ||
147 | #define netxen_gb_unset_rx_flowctl(config_word) \ | ||
148 | clear_bit(5, (unsigned long*)(&config_word)) | ||
149 | |||
150 | #define netxen_gb_get_tx_synced(config_word) \ | ||
151 | _netxen_crb_get_bit((config_word), 1) | ||
152 | #define netxen_gb_get_rx_synced(config_word) \ | ||
153 | _netxen_crb_get_bit((config_word), 3) | ||
154 | #define netxen_gb_get_tx_flowctl(config_word) \ | ||
155 | _netxen_crb_get_bit((config_word), 4) | ||
156 | #define netxen_gb_get_rx_flowctl(config_word) \ | ||
157 | _netxen_crb_get_bit((config_word), 5) | ||
158 | #define netxen_gb_get_soft_reset(config_word) \ | ||
159 | _netxen_crb_get_bit((config_word), 31) | ||
160 | |||
161 | /* | ||
162 | * NIU GB MAC Config Register 1 (applies to GB0, GB1, GB2, GB3) | ||
163 | * | ||
164 | * Bit 0 : duplex => 1:full duplex mode, 0:half duplex | ||
165 | * Bit 1 : crc_enable => 1:append CRC to xmit frames, 0:dont append | ||
166 | * Bit 2 : padshort => 1:pad short frames and add CRC, 0:dont pad | ||
167 | * Bit 4 : checklength => 1:check framelen with actual,0:dont check | ||
168 | * Bit 5 : hugeframes => 1:allow oversize xmit frames, 0:dont allow | ||
169 | * Bits 8-9 : intfmode => 01:nibble (10/100), 10:byte (1000) | ||
170 | * Bits 12-15 : preamblelen => preamble field length in bytes, default 7 | ||
171 | */ | ||
172 | |||
173 | #define netxen_gb_set_duplex(config_word) \ | ||
174 | set_bit(0, (unsigned long*)&config_word) | ||
175 | #define netxen_gb_set_crc_enable(config_word) \ | ||
176 | set_bit(1, (unsigned long*)&config_word) | ||
177 | #define netxen_gb_set_padshort(config_word) \ | ||
178 | set_bit(2, (unsigned long*)&config_word) | ||
179 | #define netxen_gb_set_checklength(config_word) \ | ||
180 | set_bit(4, (unsigned long*)&config_word) | ||
181 | #define netxen_gb_set_hugeframes(config_word) \ | ||
182 | set_bit(5, (unsigned long*)&config_word) | ||
183 | #define netxen_gb_set_preamblelen(config_word, val) \ | ||
184 | ((config_word) |= ((val) << 12) & 0xF000) | ||
185 | #define netxen_gb_set_intfmode(config_word, val) \ | ||
186 | ((config_word) |= ((val) << 8) & 0x300) | ||
187 | |||
188 | #define netxen_gb_get_stationaddress_low(config_word) ((config_word) >> 16) | ||
189 | |||
190 | #define netxen_gb_set_mii_mgmt_clockselect(config_word, val) \ | ||
191 | ((config_word) |= ((val) & 0x07)) | ||
192 | #define netxen_gb_mii_mgmt_reset(config_word) \ | ||
193 | set_bit(31, (unsigned long*)&config_word) | ||
194 | #define netxen_gb_mii_mgmt_unset(config_word) \ | ||
195 | clear_bit(31, (unsigned long*)&config_word) | ||
196 | |||
197 | /* | ||
198 | * NIU GB MII Mgmt Command Register (applies to GB0, GB1, GB2, GB3) | ||
199 | * Bit 0 : read_cycle => 1:perform single read cycle, 0:no-op | ||
200 | * Bit 1 : scan_cycle => 1:perform continuous read cycles, 0:no-op | ||
201 | */ | ||
202 | |||
203 | #define netxen_gb_mii_mgmt_set_read_cycle(config_word) \ | ||
204 | set_bit(0, (unsigned long*)&config_word) | ||
205 | #define netxen_gb_mii_mgmt_reg_addr(config_word, val) \ | ||
206 | ((config_word) |= ((val) & 0x1F)) | ||
207 | #define netxen_gb_mii_mgmt_phy_addr(config_word, val) \ | ||
208 | ((config_word) |= (((val) & 0x1F) << 8)) | ||
209 | |||
210 | /* | ||
211 | * NIU GB MII Mgmt Indicators Register (applies to GB0, GB1, GB2, GB3) | ||
212 | * Read-only register. | ||
213 | * Bit 0 : busy => 1:performing an MII mgmt cycle, 0:idle | ||
214 | * Bit 1 : scanning => 1:scan operation in progress, 0:idle | ||
215 | * Bit 2 : notvalid => :mgmt result data not yet valid, 0:idle | ||
216 | */ | ||
217 | #define netxen_get_gb_mii_mgmt_busy(config_word) \ | ||
218 | _netxen_crb_get_bit(config_word, 0) | ||
219 | #define netxen_get_gb_mii_mgmt_scanning(config_word) \ | ||
220 | _netxen_crb_get_bit(config_word, 1) | ||
221 | #define netxen_get_gb_mii_mgmt_notvalid(config_word) \ | ||
222 | _netxen_crb_get_bit(config_word, 2) | ||
223 | |||
224 | /* | ||
225 | * PHY-Specific MII control/status registers. | ||
226 | */ | ||
227 | typedef enum { | ||
228 | NETXEN_NIU_GB_MII_MGMT_ADDR_CONTROL = 0, | ||
229 | NETXEN_NIU_GB_MII_MGMT_ADDR_STATUS = 1, | ||
230 | NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_ID_0 = 2, | ||
231 | NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_ID_1 = 3, | ||
232 | NETXEN_NIU_GB_MII_MGMT_ADDR_AUTONEG = 4, | ||
233 | NETXEN_NIU_GB_MII_MGMT_ADDR_LNKPART = 5, | ||
234 | NETXEN_NIU_GB_MII_MGMT_ADDR_AUTONEG_MORE = 6, | ||
235 | NETXEN_NIU_GB_MII_MGMT_ADDR_NEXTPAGE_XMIT = 7, | ||
236 | NETXEN_NIU_GB_MII_MGMT_ADDR_LNKPART_NEXTPAGE = 8, | ||
237 | NETXEN_NIU_GB_MII_MGMT_ADDR_1000BT_CONTROL = 9, | ||
238 | NETXEN_NIU_GB_MII_MGMT_ADDR_1000BT_STATUS = 10, | ||
239 | NETXEN_NIU_GB_MII_MGMT_ADDR_EXTENDED_STATUS = 15, | ||
240 | NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_CONTROL = 16, | ||
241 | NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS = 17, | ||
242 | NETXEN_NIU_GB_MII_MGMT_ADDR_INT_ENABLE = 18, | ||
243 | NETXEN_NIU_GB_MII_MGMT_ADDR_INT_STATUS = 19, | ||
244 | NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_CONTROL_MORE = 20, | ||
245 | NETXEN_NIU_GB_MII_MGMT_ADDR_RECV_ERROR_COUNT = 21, | ||
246 | NETXEN_NIU_GB_MII_MGMT_ADDR_LED_CONTROL = 24, | ||
247 | NETXEN_NIU_GB_MII_MGMT_ADDR_LED_OVERRIDE = 25, | ||
248 | NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_CONTROL_MORE_YET = 26, | ||
249 | NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS_MORE = 27 | ||
250 | } netxen_niu_phy_register_t; | ||
251 | |||
252 | /* | ||
253 | * PHY-Specific Status Register (reg 17). | ||
254 | * | ||
255 | * Bit 0 : jabber => 1:jabber detected, 0:not | ||
256 | * Bit 1 : polarity => 1:polarity reversed, 0:normal | ||
257 | * Bit 2 : recvpause => 1:receive pause enabled, 0:disabled | ||
258 | * Bit 3 : xmitpause => 1:transmit pause enabled, 0:disabled | ||
259 | * Bit 4 : energydetect => 1:sleep, 0:active | ||
260 | * Bit 5 : downshift => 1:downshift, 0:no downshift | ||
261 | * Bit 6 : crossover => 1:MDIX (crossover), 0:MDI (no crossover) | ||
262 | * Bits 7-9 : cablelen => not valid in 10Mb/s mode | ||
263 | * 0:<50m, 1:50-80m, 2:80-110m, 3:110-140m, 4:>140m | ||
264 | * Bit 10 : link => 1:link up, 0:link down | ||
265 | * Bit 11 : resolved => 1:speed and duplex resolved, 0:not yet | ||
266 | * Bit 12 : pagercvd => 1:page received, 0:page not received | ||
267 | * Bit 13 : duplex => 1:full duplex, 0:half duplex | ||
268 | * Bits 14-15 : speed => 0:10Mb/s, 1:100Mb/s, 2:1000Mb/s, 3:rsvd | ||
269 | */ | ||
270 | |||
271 | #define netxen_get_phy_cablelen(config_word) (((config_word) >> 7) & 0x07) | ||
272 | #define netxen_get_phy_speed(config_word) (((config_word) >> 14) & 0x03) | ||
273 | |||
274 | #define netxen_set_phy_speed(config_word, val) \ | ||
275 | ((config_word) |= ((val & 0x03) << 14)) | ||
276 | #define netxen_set_phy_duplex(config_word) \ | ||
277 | set_bit(13, (unsigned long*)&config_word) | ||
278 | #define netxen_clear_phy_duplex(config_word) \ | ||
279 | clear_bit(13, (unsigned long*)&config_word) | ||
280 | |||
281 | #define netxen_get_phy_jabber(config_word) \ | ||
282 | _netxen_crb_get_bit(config_word, 0) | ||
283 | #define netxen_get_phy_polarity(config_word) \ | ||
284 | _netxen_crb_get_bit(config_word, 1) | ||
285 | #define netxen_get_phy_recvpause(config_word) \ | ||
286 | _netxen_crb_get_bit(config_word, 2) | ||
287 | #define netxen_get_phy_xmitpause(config_word) \ | ||
288 | _netxen_crb_get_bit(config_word, 3) | ||
289 | #define netxen_get_phy_energydetect(config_word) \ | ||
290 | _netxen_crb_get_bit(config_word, 4) | ||
291 | #define netxen_get_phy_downshift(config_word) \ | ||
292 | _netxen_crb_get_bit(config_word, 5) | ||
293 | #define netxen_get_phy_crossover(config_word) \ | ||
294 | _netxen_crb_get_bit(config_word, 6) | ||
295 | #define netxen_get_phy_link(config_word) \ | ||
296 | _netxen_crb_get_bit(config_word, 10) | ||
297 | #define netxen_get_phy_resolved(config_word) \ | ||
298 | _netxen_crb_get_bit(config_word, 11) | ||
299 | #define netxen_get_phy_pagercvd(config_word) \ | ||
300 | _netxen_crb_get_bit(config_word, 12) | ||
301 | #define netxen_get_phy_duplex(config_word) \ | ||
302 | _netxen_crb_get_bit(config_word, 13) | ||
303 | |||
304 | /* | ||
305 | * Interrupt Register definition | ||
306 | * This definition applies to registers 18 and 19 (int enable and int status). | ||
307 | * Bit 0 : jabber | ||
308 | * Bit 1 : polarity_changed | ||
309 | * Bit 4 : energy_detect | ||
310 | * Bit 5 : downshift | ||
311 | * Bit 6 : mdi_xover_changed | ||
312 | * Bit 7 : fifo_over_underflow | ||
313 | * Bit 8 : false_carrier | ||
314 | * Bit 9 : symbol_error | ||
315 | * Bit 10: link_status_changed | ||
316 | * Bit 11: autoneg_completed | ||
317 | * Bit 12: page_received | ||
318 | * Bit 13: duplex_changed | ||
319 | * Bit 14: speed_changed | ||
320 | * Bit 15: autoneg_error | ||
321 | */ | ||
322 | |||
323 | #define netxen_get_phy_int_jabber(config_word) \ | ||
324 | _netxen_crb_get_bit(config_word, 0) | ||
325 | #define netxen_get_phy_int_polarity_changed(config_word) \ | ||
326 | _netxen_crb_get_bit(config_word, 1) | ||
327 | #define netxen_get_phy_int_energy_detect(config_word) \ | ||
328 | _netxen_crb_get_bit(config_word, 4) | ||
329 | #define netxen_get_phy_int_downshift(config_word) \ | ||
330 | _netxen_crb_get_bit(config_word, 5) | ||
331 | #define netxen_get_phy_int_mdi_xover_changed(config_word) \ | ||
332 | _netxen_crb_get_bit(config_word, 6) | ||
333 | #define netxen_get_phy_int_fifo_over_underflow(config_word) \ | ||
334 | _netxen_crb_get_bit(config_word, 7) | ||
335 | #define netxen_get_phy_int_false_carrier(config_word) \ | ||
336 | _netxen_crb_get_bit(config_word, 8) | ||
337 | #define netxen_get_phy_int_symbol_error(config_word) \ | ||
338 | _netxen_crb_get_bit(config_word, 9) | ||
339 | #define netxen_get_phy_int_link_status_changed(config_word) \ | ||
340 | _netxen_crb_get_bit(config_word, 10) | ||
341 | #define netxen_get_phy_int_autoneg_completed(config_word) \ | ||
342 | _netxen_crb_get_bit(config_word, 11) | ||
343 | #define netxen_get_phy_int_page_received(config_word) \ | ||
344 | _netxen_crb_get_bit(config_word, 12) | ||
345 | #define netxen_get_phy_int_duplex_changed(config_word) \ | ||
346 | _netxen_crb_get_bit(config_word, 13) | ||
347 | #define netxen_get_phy_int_speed_changed(config_word) \ | ||
348 | _netxen_crb_get_bit(config_word, 14) | ||
349 | #define netxen_get_phy_int_autoneg_error(config_word) \ | ||
350 | _netxen_crb_get_bit(config_word, 15) | ||
351 | |||
352 | #define netxen_set_phy_int_link_status_changed(config_word) \ | ||
353 | set_bit(10, (unsigned long*)&config_word) | ||
354 | #define netxen_set_phy_int_autoneg_completed(config_word) \ | ||
355 | set_bit(11, (unsigned long*)&config_word) | ||
356 | #define netxen_set_phy_int_speed_changed(config_word) \ | ||
357 | set_bit(14, (unsigned long*)&config_word) | ||
358 | |||
359 | /* | ||
360 | * NIU Mode Register. | ||
361 | * Bit 0 : enable FibreChannel | ||
362 | * Bit 1 : enable 10/100/1000 Ethernet | ||
363 | * Bit 2 : enable 10Gb Ethernet | ||
364 | */ | ||
365 | |||
366 | #define netxen_get_niu_enable_ge(config_word) \ | ||
367 | _netxen_crb_get_bit(config_word, 1) | ||
368 | |||
369 | /* Promiscous mode options (GbE mode only) */ | ||
370 | typedef enum { | ||
371 | NETXEN_NIU_PROMISC_MODE = 0, | ||
372 | NETXEN_NIU_NON_PROMISC_MODE | ||
373 | } netxen_niu_prom_mode_t; | ||
374 | |||
375 | /* | ||
376 | * NIU GB Drop CRC Register | ||
377 | * | ||
378 | * Bit 0 : drop_gb0 => 1:drop pkts with bad CRCs, 0:pass them on | ||
379 | * Bit 1 : drop_gb1 => 1:drop pkts with bad CRCs, 0:pass them on | ||
380 | * Bit 2 : drop_gb2 => 1:drop pkts with bad CRCs, 0:pass them on | ||
381 | * Bit 3 : drop_gb3 => 1:drop pkts with bad CRCs, 0:pass them on | ||
382 | */ | ||
383 | |||
384 | #define netxen_set_gb_drop_gb0(config_word) \ | ||
385 | set_bit(0, (unsigned long*)&config_word) | ||
386 | #define netxen_set_gb_drop_gb1(config_word) \ | ||
387 | set_bit(1, (unsigned long*)&config_word) | ||
388 | #define netxen_set_gb_drop_gb2(config_word) \ | ||
389 | set_bit(2, (unsigned long*)&config_word) | ||
390 | #define netxen_set_gb_drop_gb3(config_word) \ | ||
391 | set_bit(3, (unsigned long*)&config_word) | ||
392 | |||
393 | #define netxen_clear_gb_drop_gb0(config_word) \ | ||
394 | clear_bit(0, (unsigned long*)&config_word) | ||
395 | #define netxen_clear_gb_drop_gb1(config_word) \ | ||
396 | clear_bit(1, (unsigned long*)&config_word) | ||
397 | #define netxen_clear_gb_drop_gb2(config_word) \ | ||
398 | clear_bit(2, (unsigned long*)&config_word) | ||
399 | #define netxen_clear_gb_drop_gb3(config_word) \ | ||
400 | clear_bit(3, (unsigned long*)&config_word) | ||
401 | |||
402 | /* | ||
403 | * NIU XG MAC Config Register | ||
404 | * | ||
405 | * Bit 0 : tx_enable => 1:enable frame xmit, 0:disable | ||
406 | * Bit 2 : rx_enable => 1:enable frame recv, 0:disable | ||
407 | * Bit 4 : soft_reset => 1:reset the MAC , 0:no-op | ||
408 | * Bit 27: xaui_framer_reset | ||
409 | * Bit 28: xaui_rx_reset | ||
410 | * Bit 29: xaui_tx_reset | ||
411 | * Bit 30: xg_ingress_afifo_reset | ||
412 | * Bit 31: xg_egress_afifo_reset | ||
413 | */ | ||
414 | |||
415 | #define netxen_xg_soft_reset(config_word) \ | ||
416 | set_bit(4, (unsigned long*)&config_word) | ||
417 | |||
418 | /* | ||
419 | * MAC Control Register | ||
420 | * | ||
421 | * Bit 0-1 : id_pool0 | ||
422 | * Bit 2 : enable_xtnd0 | ||
423 | * Bit 4-5 : id_pool1 | ||
424 | * Bit 6 : enable_xtnd1 | ||
425 | * Bit 8-9 : id_pool2 | ||
426 | * Bit 10 : enable_xtnd2 | ||
427 | * Bit 12-13 : id_pool3 | ||
428 | * Bit 14 : enable_xtnd3 | ||
429 | * Bit 24-25 : mode_select | ||
430 | * Bit 28-31 : enable_pool | ||
431 | */ | ||
432 | |||
433 | #define netxen_nic_mcr_set_id_pool0(config, val) \ | ||
434 | ((config) |= ((val) &0x03)) | ||
435 | #define netxen_nic_mcr_set_enable_xtnd0(config) \ | ||
436 | (set_bit(3, (unsigned long *)&(config))) | ||
437 | #define netxen_nic_mcr_set_id_pool1(config, val) \ | ||
438 | ((config) |= (((val) & 0x03) << 4)) | ||
439 | #define netxen_nic_mcr_set_enable_xtnd1(config) \ | ||
440 | (set_bit(6, (unsigned long *)&(config))) | ||
441 | #define netxen_nic_mcr_set_id_pool2(config, val) \ | ||
442 | ((config) |= (((val) & 0x03) << 8)) | ||
443 | #define netxen_nic_mcr_set_enable_xtnd2(config) \ | ||
444 | (set_bit(10, (unsigned long *)&(config))) | ||
445 | #define netxen_nic_mcr_set_id_pool3(config, val) \ | ||
446 | ((config) |= (((val) & 0x03) << 12)) | ||
447 | #define netxen_nic_mcr_set_enable_xtnd3(config) \ | ||
448 | (set_bit(14, (unsigned long *)&(config))) | ||
449 | #define netxen_nic_mcr_set_mode_select(config, val) \ | ||
450 | ((config) |= (((val) & 0x03) << 24)) | ||
451 | #define netxen_nic_mcr_set_enable_pool(config, val) \ | ||
452 | ((config) |= (((val) & 0x0f) << 28)) | ||
453 | |||
454 | /* Set promiscuous mode for a GbE interface */ | ||
455 | int netxen_niu_set_promiscuous_mode(struct netxen_adapter *adapter, int port, | ||
456 | netxen_niu_prom_mode_t mode); | ||
457 | int netxen_niu_xg_set_promiscuous_mode(struct netxen_adapter *adapter, | ||
458 | int port, netxen_niu_prom_mode_t mode); | ||
459 | |||
460 | /* get/set the MAC address for a given MAC */ | ||
461 | int netxen_niu_macaddr_get(struct netxen_adapter *adapter, int port, | ||
462 | netxen_ethernet_macaddr_t * addr); | ||
463 | int netxen_niu_macaddr_set(struct netxen_port *port, | ||
464 | netxen_ethernet_macaddr_t addr); | ||
465 | |||
466 | /* XG versons */ | ||
467 | int netxen_niu_xg_macaddr_get(struct netxen_adapter *adapter, int port, | ||
468 | netxen_ethernet_macaddr_t * addr); | ||
469 | int netxen_niu_xg_macaddr_set(struct netxen_port *port, | ||
470 | netxen_ethernet_macaddr_t addr); | ||
471 | |||
472 | /* Generic enable for GbE ports. Will detect the speed of the link. */ | ||
473 | int netxen_niu_gbe_init_port(struct netxen_adapter *adapter, int port); | ||
474 | |||
475 | int netxen_niu_xg_init_port(struct netxen_adapter *adapter, int port); | ||
476 | |||
477 | /* Disable a GbE interface */ | ||
478 | int netxen_niu_disable_gbe_port(struct netxen_adapter *adapter, int port); | ||
479 | |||
480 | int netxen_niu_disable_xg_port(struct netxen_adapter *adapter, int port); | ||
481 | |||
482 | #endif /* __NETXEN_NIC_HW_H_ */ | ||
diff --git a/drivers/net/netxen/netxen_nic_init.c b/drivers/net/netxen/netxen_nic_init.c new file mode 100644 index 000000000000..0dca029bc3e5 --- /dev/null +++ b/drivers/net/netxen/netxen_nic_init.c | |||
@@ -0,0 +1,1304 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2003 - 2006 NetXen, Inc. | ||
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 LICENSE. | ||
22 | * | ||
23 | * Contact Information: | ||
24 | * info@netxen.com | ||
25 | * NetXen, | ||
26 | * 3965 Freedom Circle, Fourth floor, | ||
27 | * Santa Clara, CA 95054 | ||
28 | * | ||
29 | * | ||
30 | * Source file for NIC routines to initialize the Phantom Hardware | ||
31 | * | ||
32 | */ | ||
33 | |||
34 | #include <linux/netdevice.h> | ||
35 | #include <linux/delay.h> | ||
36 | #include "netxen_nic.h" | ||
37 | #include "netxen_nic_hw.h" | ||
38 | #include "netxen_nic_ioctl.h" | ||
39 | #include "netxen_nic_phan_reg.h" | ||
40 | |||
41 | struct crb_addr_pair { | ||
42 | long addr; | ||
43 | long data; | ||
44 | }; | ||
45 | |||
46 | #define NETXEN_MAX_CRB_XFORM 60 | ||
47 | static unsigned int crb_addr_xform[NETXEN_MAX_CRB_XFORM]; | ||
48 | #define NETXEN_ADDR_ERROR ((unsigned long ) 0xffffffff ) | ||
49 | |||
50 | #define crb_addr_transform(name) \ | ||
51 | crb_addr_xform[NETXEN_HW_PX_MAP_CRB_##name] = \ | ||
52 | NETXEN_HW_CRB_HUB_AGT_ADR_##name << 20 | ||
53 | |||
54 | #define NETXEN_NIC_XDMA_RESET 0x8000ff | ||
55 | |||
56 | static inline void | ||
57 | netxen_nic_locked_write_reg(struct netxen_adapter *adapter, | ||
58 | unsigned long off, int *data) | ||
59 | { | ||
60 | void __iomem *addr = pci_base_offset(adapter, off); | ||
61 | writel(*data, addr); | ||
62 | } | ||
63 | |||
64 | static void crb_addr_transform_setup(void) | ||
65 | { | ||
66 | crb_addr_transform(XDMA); | ||
67 | crb_addr_transform(TIMR); | ||
68 | crb_addr_transform(SRE); | ||
69 | crb_addr_transform(SQN3); | ||
70 | crb_addr_transform(SQN2); | ||
71 | crb_addr_transform(SQN1); | ||
72 | crb_addr_transform(SQN0); | ||
73 | crb_addr_transform(SQS3); | ||
74 | crb_addr_transform(SQS2); | ||
75 | crb_addr_transform(SQS1); | ||
76 | crb_addr_transform(SQS0); | ||
77 | crb_addr_transform(RPMX7); | ||
78 | crb_addr_transform(RPMX6); | ||
79 | crb_addr_transform(RPMX5); | ||
80 | crb_addr_transform(RPMX4); | ||
81 | crb_addr_transform(RPMX3); | ||
82 | crb_addr_transform(RPMX2); | ||
83 | crb_addr_transform(RPMX1); | ||
84 | crb_addr_transform(RPMX0); | ||
85 | crb_addr_transform(ROMUSB); | ||
86 | crb_addr_transform(SN); | ||
87 | crb_addr_transform(QMN); | ||
88 | crb_addr_transform(QMS); | ||
89 | crb_addr_transform(PGNI); | ||
90 | crb_addr_transform(PGND); | ||
91 | crb_addr_transform(PGN3); | ||
92 | crb_addr_transform(PGN2); | ||
93 | crb_addr_transform(PGN1); | ||
94 | crb_addr_transform(PGN0); | ||
95 | crb_addr_transform(PGSI); | ||
96 | crb_addr_transform(PGSD); | ||
97 | crb_addr_transform(PGS3); | ||
98 | crb_addr_transform(PGS2); | ||
99 | crb_addr_transform(PGS1); | ||
100 | crb_addr_transform(PGS0); | ||
101 | crb_addr_transform(PS); | ||
102 | crb_addr_transform(PH); | ||
103 | crb_addr_transform(NIU); | ||
104 | crb_addr_transform(I2Q); | ||
105 | crb_addr_transform(EG); | ||
106 | crb_addr_transform(MN); | ||
107 | crb_addr_transform(MS); | ||
108 | crb_addr_transform(CAS2); | ||
109 | crb_addr_transform(CAS1); | ||
110 | crb_addr_transform(CAS0); | ||
111 | crb_addr_transform(CAM); | ||
112 | crb_addr_transform(C2C1); | ||
113 | crb_addr_transform(C2C0); | ||
114 | } | ||
115 | |||
116 | int netxen_init_firmware(struct netxen_adapter *adapter) | ||
117 | { | ||
118 | u32 state = 0, loops = 0, err = 0; | ||
119 | |||
120 | /* Window 1 call */ | ||
121 | state = readl(NETXEN_CRB_NORMALIZE(adapter, CRB_CMDPEG_STATE)); | ||
122 | |||
123 | if (state == PHAN_INITIALIZE_ACK) | ||
124 | return 0; | ||
125 | |||
126 | while (state != PHAN_INITIALIZE_COMPLETE && loops < 2000) { | ||
127 | udelay(100); | ||
128 | /* Window 1 call */ | ||
129 | state = readl(NETXEN_CRB_NORMALIZE(adapter, CRB_CMDPEG_STATE)); | ||
130 | |||
131 | loops++; | ||
132 | } | ||
133 | if (loops >= 2000) { | ||
134 | printk(KERN_ERR "Cmd Peg initialization not complete:%x.\n", | ||
135 | state); | ||
136 | err = -EIO; | ||
137 | return err; | ||
138 | } | ||
139 | /* Window 1 call */ | ||
140 | writel(PHAN_INITIALIZE_ACK, | ||
141 | NETXEN_CRB_NORMALIZE(adapter, CRB_CMDPEG_STATE)); | ||
142 | |||
143 | return err; | ||
144 | } | ||
145 | |||
146 | #define NETXEN_ADDR_LIMIT 0xffffffffULL | ||
147 | |||
148 | void *netxen_alloc(struct pci_dev *pdev, size_t sz, dma_addr_t * ptr, | ||
149 | struct pci_dev **used_dev) | ||
150 | { | ||
151 | void *addr; | ||
152 | |||
153 | addr = pci_alloc_consistent(pdev, sz, ptr); | ||
154 | if ((unsigned long long)(*ptr) < NETXEN_ADDR_LIMIT) { | ||
155 | *used_dev = pdev; | ||
156 | return addr; | ||
157 | } | ||
158 | pci_free_consistent(pdev, sz, addr, *ptr); | ||
159 | addr = pci_alloc_consistent(NULL, sz, ptr); | ||
160 | *used_dev = NULL; | ||
161 | return addr; | ||
162 | } | ||
163 | |||
164 | void netxen_initialize_adapter_sw(struct netxen_adapter *adapter) | ||
165 | { | ||
166 | int ctxid, ring; | ||
167 | u32 i; | ||
168 | u32 num_rx_bufs = 0; | ||
169 | struct netxen_rcv_desc_ctx *rcv_desc; | ||
170 | |||
171 | DPRINTK(INFO, "initializing some queues: %p\n", adapter); | ||
172 | for (ctxid = 0; ctxid < MAX_RCV_CTX; ++ctxid) { | ||
173 | for (ring = 0; ring < NUM_RCV_DESC_RINGS; ring++) { | ||
174 | struct netxen_rx_buffer *rx_buf; | ||
175 | rcv_desc = &adapter->recv_ctx[ctxid].rcv_desc[ring]; | ||
176 | rcv_desc->rcv_free = rcv_desc->max_rx_desc_count; | ||
177 | rcv_desc->begin_alloc = 0; | ||
178 | rx_buf = rcv_desc->rx_buf_arr; | ||
179 | num_rx_bufs = rcv_desc->max_rx_desc_count; | ||
180 | /* | ||
181 | * Now go through all of them, set reference handles | ||
182 | * and put them in the queues. | ||
183 | */ | ||
184 | for (i = 0; i < num_rx_bufs; i++) { | ||
185 | rx_buf->ref_handle = i; | ||
186 | rx_buf->state = NETXEN_BUFFER_FREE; | ||
187 | |||
188 | DPRINTK(INFO, "Rx buf:ctx%d i(%d) rx_buf:" | ||
189 | "%p\n", ctxid, i, rx_buf); | ||
190 | rx_buf++; | ||
191 | } | ||
192 | } | ||
193 | } | ||
194 | DPRINTK(INFO, "initialized buffers for %s and %s\n", | ||
195 | "adapter->free_cmd_buf_list", "adapter->free_rxbuf"); | ||
196 | } | ||
197 | |||
198 | void netxen_initialize_adapter_hw(struct netxen_adapter *adapter) | ||
199 | { | ||
200 | int ports = 0; | ||
201 | struct netxen_board_info *board_info = &(adapter->ahw.boardcfg); | ||
202 | |||
203 | if (netxen_nic_get_board_info(adapter) != 0) | ||
204 | printk("%s: Error getting board config info.\n", | ||
205 | netxen_nic_driver_name); | ||
206 | get_brd_port_by_type(board_info->board_type, &ports); | ||
207 | if (ports == 0) | ||
208 | printk(KERN_ERR "%s: Unknown board type\n", | ||
209 | netxen_nic_driver_name); | ||
210 | adapter->ahw.max_ports = ports; | ||
211 | } | ||
212 | |||
213 | void netxen_initialize_adapter_ops(struct netxen_adapter *adapter) | ||
214 | { | ||
215 | struct netxen_drvops *ops = adapter->ops; | ||
216 | switch (adapter->ahw.board_type) { | ||
217 | case NETXEN_NIC_GBE: | ||
218 | ops->enable_phy_interrupts = | ||
219 | netxen_niu_gbe_enable_phy_interrupts; | ||
220 | ops->disable_phy_interrupts = | ||
221 | netxen_niu_gbe_disable_phy_interrupts; | ||
222 | ops->handle_phy_intr = netxen_nic_gbe_handle_phy_intr; | ||
223 | ops->macaddr_set = netxen_niu_macaddr_set; | ||
224 | ops->set_mtu = netxen_nic_set_mtu_gb; | ||
225 | ops->set_promisc = netxen_niu_set_promiscuous_mode; | ||
226 | ops->unset_promisc = netxen_niu_set_promiscuous_mode; | ||
227 | ops->phy_read = netxen_niu_gbe_phy_read; | ||
228 | ops->phy_write = netxen_niu_gbe_phy_write; | ||
229 | ops->init_port = netxen_niu_gbe_init_port; | ||
230 | ops->init_niu = netxen_nic_init_niu_gb; | ||
231 | ops->stop_port = netxen_niu_disable_gbe_port; | ||
232 | break; | ||
233 | |||
234 | case NETXEN_NIC_XGBE: | ||
235 | ops->enable_phy_interrupts = | ||
236 | netxen_niu_xgbe_enable_phy_interrupts; | ||
237 | ops->disable_phy_interrupts = | ||
238 | netxen_niu_xgbe_disable_phy_interrupts; | ||
239 | ops->handle_phy_intr = netxen_nic_xgbe_handle_phy_intr; | ||
240 | ops->macaddr_set = netxen_niu_xg_macaddr_set; | ||
241 | ops->set_mtu = netxen_nic_set_mtu_xgb; | ||
242 | ops->init_port = netxen_niu_xg_init_port; | ||
243 | ops->set_promisc = netxen_niu_xg_set_promiscuous_mode; | ||
244 | ops->unset_promisc = netxen_niu_xg_set_promiscuous_mode; | ||
245 | ops->stop_port = netxen_niu_disable_xg_port; | ||
246 | break; | ||
247 | |||
248 | default: | ||
249 | break; | ||
250 | } | ||
251 | } | ||
252 | |||
253 | /* | ||
254 | * netxen_decode_crb_addr(0 - utility to translate from internal Phantom CRB | ||
255 | * address to external PCI CRB address. | ||
256 | */ | ||
257 | unsigned long netxen_decode_crb_addr(unsigned long addr) | ||
258 | { | ||
259 | int i; | ||
260 | unsigned long base_addr, offset, pci_base; | ||
261 | |||
262 | crb_addr_transform_setup(); | ||
263 | |||
264 | pci_base = NETXEN_ADDR_ERROR; | ||
265 | base_addr = addr & 0xfff00000; | ||
266 | offset = addr & 0x000fffff; | ||
267 | |||
268 | for (i = 0; i < NETXEN_MAX_CRB_XFORM; i++) { | ||
269 | if (crb_addr_xform[i] == base_addr) { | ||
270 | pci_base = i << 20; | ||
271 | break; | ||
272 | } | ||
273 | } | ||
274 | if (pci_base == NETXEN_ADDR_ERROR) | ||
275 | return pci_base; | ||
276 | else | ||
277 | return (pci_base + offset); | ||
278 | } | ||
279 | |||
280 | static long rom_max_timeout = 10000; | ||
281 | static long rom_lock_timeout = 1000000; | ||
282 | |||
283 | static inline int rom_lock(struct netxen_adapter *adapter) | ||
284 | { | ||
285 | int iter; | ||
286 | u32 done = 0; | ||
287 | int timeout = 0; | ||
288 | |||
289 | while (!done) { | ||
290 | /* acquire semaphore2 from PCI HW block */ | ||
291 | netxen_nic_read_w0(adapter, NETXEN_PCIE_REG(PCIE_SEM2_LOCK), | ||
292 | &done); | ||
293 | if (done == 1) | ||
294 | break; | ||
295 | if (timeout >= rom_lock_timeout) | ||
296 | return -EIO; | ||
297 | |||
298 | timeout++; | ||
299 | /* | ||
300 | * Yield CPU | ||
301 | */ | ||
302 | if (!in_atomic()) | ||
303 | schedule(); | ||
304 | else { | ||
305 | for (iter = 0; iter < 20; iter++) | ||
306 | cpu_relax(); /*This a nop instr on i386 */ | ||
307 | } | ||
308 | } | ||
309 | netxen_nic_reg_write(adapter, NETXEN_ROM_LOCK_ID, ROM_LOCK_DRIVER); | ||
310 | return 0; | ||
311 | } | ||
312 | |||
313 | int netxen_wait_rom_done(struct netxen_adapter *adapter) | ||
314 | { | ||
315 | long timeout = 0; | ||
316 | long done = 0; | ||
317 | |||
318 | while (done == 0) { | ||
319 | done = netxen_nic_reg_read(adapter, NETXEN_ROMUSB_GLB_STATUS); | ||
320 | done &= 2; | ||
321 | timeout++; | ||
322 | if (timeout >= rom_max_timeout) { | ||
323 | printk("Timeout reached waiting for rom done"); | ||
324 | return -EIO; | ||
325 | } | ||
326 | } | ||
327 | return 0; | ||
328 | } | ||
329 | |||
330 | static inline int netxen_rom_wren(struct netxen_adapter *adapter) | ||
331 | { | ||
332 | /* Set write enable latch in ROM status register */ | ||
333 | netxen_nic_reg_write(adapter, NETXEN_ROMUSB_ROM_ABYTE_CNT, 0); | ||
334 | netxen_nic_reg_write(adapter, NETXEN_ROMUSB_ROM_INSTR_OPCODE, | ||
335 | M25P_INSTR_WREN); | ||
336 | if (netxen_wait_rom_done(adapter)) { | ||
337 | return -1; | ||
338 | } | ||
339 | return 0; | ||
340 | } | ||
341 | |||
342 | static inline unsigned int netxen_rdcrbreg(struct netxen_adapter *adapter, | ||
343 | unsigned int addr) | ||
344 | { | ||
345 | unsigned int data = 0xdeaddead; | ||
346 | data = netxen_nic_reg_read(adapter, addr); | ||
347 | return data; | ||
348 | } | ||
349 | |||
350 | static inline int netxen_do_rom_rdsr(struct netxen_adapter *adapter) | ||
351 | { | ||
352 | netxen_nic_reg_write(adapter, NETXEN_ROMUSB_ROM_INSTR_OPCODE, | ||
353 | M25P_INSTR_RDSR); | ||
354 | if (netxen_wait_rom_done(adapter)) { | ||
355 | return -1; | ||
356 | } | ||
357 | return netxen_rdcrbreg(adapter, NETXEN_ROMUSB_ROM_RDATA); | ||
358 | } | ||
359 | |||
360 | static inline void netxen_rom_unlock(struct netxen_adapter *adapter) | ||
361 | { | ||
362 | u32 val; | ||
363 | |||
364 | /* release semaphore2 */ | ||
365 | netxen_nic_read_w0(adapter, NETXEN_PCIE_REG(PCIE_SEM2_UNLOCK), &val); | ||
366 | |||
367 | } | ||
368 | |||
369 | int netxen_rom_wip_poll(struct netxen_adapter *adapter) | ||
370 | { | ||
371 | long timeout = 0; | ||
372 | long wip = 1; | ||
373 | int val; | ||
374 | netxen_nic_reg_write(adapter, NETXEN_ROMUSB_ROM_ABYTE_CNT, 0); | ||
375 | while (wip != 0) { | ||
376 | val = netxen_do_rom_rdsr(adapter); | ||
377 | wip = val & 1; | ||
378 | timeout++; | ||
379 | if (timeout > rom_max_timeout) { | ||
380 | return -1; | ||
381 | } | ||
382 | } | ||
383 | return 0; | ||
384 | } | ||
385 | |||
386 | static inline int do_rom_fast_write(struct netxen_adapter *adapter, | ||
387 | int addr, int data) | ||
388 | { | ||
389 | if (netxen_rom_wren(adapter)) { | ||
390 | return -1; | ||
391 | } | ||
392 | netxen_nic_reg_write(adapter, NETXEN_ROMUSB_ROM_WDATA, data); | ||
393 | netxen_nic_reg_write(adapter, NETXEN_ROMUSB_ROM_ADDRESS, addr); | ||
394 | netxen_nic_reg_write(adapter, NETXEN_ROMUSB_ROM_ABYTE_CNT, 3); | ||
395 | netxen_nic_reg_write(adapter, NETXEN_ROMUSB_ROM_INSTR_OPCODE, | ||
396 | M25P_INSTR_PP); | ||
397 | if (netxen_wait_rom_done(adapter)) { | ||
398 | netxen_nic_reg_write(adapter, NETXEN_ROMUSB_ROM_ABYTE_CNT, 0); | ||
399 | return -1; | ||
400 | } | ||
401 | |||
402 | return netxen_rom_wip_poll(adapter); | ||
403 | } | ||
404 | |||
405 | static inline int | ||
406 | do_rom_fast_read(struct netxen_adapter *adapter, int addr, int *valp) | ||
407 | { | ||
408 | netxen_nic_reg_write(adapter, NETXEN_ROMUSB_ROM_ADDRESS, addr); | ||
409 | netxen_nic_reg_write(adapter, NETXEN_ROMUSB_ROM_ABYTE_CNT, 3); | ||
410 | udelay(100); /* prevent bursting on CRB */ | ||
411 | netxen_nic_reg_write(adapter, NETXEN_ROMUSB_ROM_DUMMY_BYTE_CNT, 0); | ||
412 | netxen_nic_reg_write(adapter, NETXEN_ROMUSB_ROM_INSTR_OPCODE, 0xb); | ||
413 | if (netxen_wait_rom_done(adapter)) { | ||
414 | printk("Error waiting for rom done\n"); | ||
415 | return -EIO; | ||
416 | } | ||
417 | /* reset abyte_cnt and dummy_byte_cnt */ | ||
418 | netxen_nic_reg_write(adapter, NETXEN_ROMUSB_ROM_ABYTE_CNT, 0); | ||
419 | udelay(100); /* prevent bursting on CRB */ | ||
420 | netxen_nic_reg_write(adapter, NETXEN_ROMUSB_ROM_DUMMY_BYTE_CNT, 0); | ||
421 | |||
422 | *valp = netxen_nic_reg_read(adapter, NETXEN_ROMUSB_ROM_RDATA); | ||
423 | return 0; | ||
424 | } | ||
425 | |||
426 | int netxen_rom_fast_read(struct netxen_adapter *adapter, int addr, int *valp) | ||
427 | { | ||
428 | int ret; | ||
429 | |||
430 | if (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 | int netxen_rom_fast_write(struct netxen_adapter *adapter, int addr, int data) | ||
439 | { | ||
440 | int ret = 0; | ||
441 | |||
442 | if (rom_lock(adapter) != 0) { | ||
443 | return -1; | ||
444 | } | ||
445 | ret = do_rom_fast_write(adapter, addr, data); | ||
446 | netxen_rom_unlock(adapter); | ||
447 | return ret; | ||
448 | } | ||
449 | int netxen_do_rom_se(struct netxen_adapter *adapter, int addr) | ||
450 | { | ||
451 | netxen_rom_wren(adapter); | ||
452 | netxen_nic_reg_write(adapter, NETXEN_ROMUSB_ROM_ADDRESS, addr); | ||
453 | netxen_nic_reg_write(adapter, NETXEN_ROMUSB_ROM_ABYTE_CNT, 3); | ||
454 | netxen_nic_reg_write(adapter, NETXEN_ROMUSB_ROM_INSTR_OPCODE, | ||
455 | M25P_INSTR_SE); | ||
456 | if (netxen_wait_rom_done(adapter)) { | ||
457 | netxen_nic_reg_write(adapter, NETXEN_ROMUSB_ROM_ABYTE_CNT, 0); | ||
458 | return -1; | ||
459 | } | ||
460 | return netxen_rom_wip_poll(adapter); | ||
461 | } | ||
462 | |||
463 | int netxen_rom_se(struct netxen_adapter *adapter, int addr) | ||
464 | { | ||
465 | int ret = 0; | ||
466 | if (rom_lock(adapter) != 0) { | ||
467 | return -1; | ||
468 | } | ||
469 | ret = netxen_do_rom_se(adapter, addr); | ||
470 | netxen_rom_unlock(adapter); | ||
471 | return ret; | ||
472 | } | ||
473 | |||
474 | #define NETXEN_BOARDTYPE 0x4008 | ||
475 | #define NETXEN_BOARDNUM 0x400c | ||
476 | #define NETXEN_CHIPNUM 0x4010 | ||
477 | #define NETXEN_ROMBUS_RESET 0xFFFFFFFF | ||
478 | #define NETXEN_ROM_FIRST_BARRIER 0x800000000ULL | ||
479 | #define NETXEN_ROM_FOUND_INIT 0x400 | ||
480 | |||
481 | int netxen_pinit_from_rom(struct netxen_adapter *adapter, int verbose) | ||
482 | { | ||
483 | int addr, val, status; | ||
484 | int n, i; | ||
485 | int init_delay = 0; | ||
486 | struct crb_addr_pair *buf; | ||
487 | unsigned long off; | ||
488 | |||
489 | /* resetall */ | ||
490 | status = netxen_nic_get_board_info(adapter); | ||
491 | if (status) | ||
492 | printk("%s: netxen_pinit_from_rom: Error getting board info\n", | ||
493 | netxen_nic_driver_name); | ||
494 | |||
495 | netxen_crb_writelit_adapter(adapter, NETXEN_ROMUSB_GLB_SW_RESET, | ||
496 | NETXEN_ROMBUS_RESET); | ||
497 | |||
498 | if (verbose) { | ||
499 | int val; | ||
500 | if (netxen_rom_fast_read(adapter, NETXEN_BOARDTYPE, &val) == 0) | ||
501 | printk("P2 ROM board type: 0x%08x\n", val); | ||
502 | else | ||
503 | printk("Could not read board type\n"); | ||
504 | if (netxen_rom_fast_read(adapter, NETXEN_BOARDNUM, &val) == 0) | ||
505 | printk("P2 ROM board num: 0x%08x\n", val); | ||
506 | else | ||
507 | printk("Could not read board number\n"); | ||
508 | if (netxen_rom_fast_read(adapter, NETXEN_CHIPNUM, &val) == 0) | ||
509 | printk("P2 ROM chip num: 0x%08x\n", val); | ||
510 | else | ||
511 | printk("Could not read chip number\n"); | ||
512 | } | ||
513 | |||
514 | if (netxen_rom_fast_read(adapter, 0, &n) == 0 | ||
515 | && (n & NETXEN_ROM_FIRST_BARRIER)) { | ||
516 | n &= ~NETXEN_ROM_ROUNDUP; | ||
517 | if (n < NETXEN_ROM_FOUND_INIT) { | ||
518 | if (verbose) | ||
519 | printk("%s: %d CRB init values found" | ||
520 | " in ROM.\n", netxen_nic_driver_name, n); | ||
521 | } else { | ||
522 | printk("%s:n=0x%x Error! NetXen card flash not" | ||
523 | " initialized.\n", __FUNCTION__, n); | ||
524 | return -EIO; | ||
525 | } | ||
526 | buf = kcalloc(n, sizeof(struct crb_addr_pair), GFP_KERNEL); | ||
527 | if (buf == NULL) { | ||
528 | printk("%s: netxen_pinit_from_rom: Unable to calloc " | ||
529 | "memory.\n", netxen_nic_driver_name); | ||
530 | return -ENOMEM; | ||
531 | } | ||
532 | for (i = 0; i < n; i++) { | ||
533 | if (netxen_rom_fast_read(adapter, 8 * i + 4, &val) != 0 | ||
534 | || netxen_rom_fast_read(adapter, 8 * i + 8, | ||
535 | &addr) != 0) | ||
536 | return -EIO; | ||
537 | |||
538 | buf[i].addr = addr; | ||
539 | buf[i].data = val; | ||
540 | |||
541 | if (verbose) | ||
542 | printk("%s: PCI: 0x%08x == 0x%08x\n", | ||
543 | netxen_nic_driver_name, (unsigned int) | ||
544 | netxen_decode_crb_addr((unsigned long) | ||
545 | addr), val); | ||
546 | } | ||
547 | for (i = 0; i < n; i++) { | ||
548 | |||
549 | off = | ||
550 | netxen_decode_crb_addr((unsigned long)buf[i].addr) + | ||
551 | NETXEN_PCI_CRBSPACE; | ||
552 | /* skipping cold reboot MAGIC */ | ||
553 | if (off == NETXEN_CAM_RAM(0x1fc)) | ||
554 | continue; | ||
555 | |||
556 | /* After writing this register, HW needs time for CRB */ | ||
557 | /* to quiet down (else crb_window returns 0xffffffff) */ | ||
558 | if (off == NETXEN_ROMUSB_GLB_SW_RESET) { | ||
559 | init_delay = 1; | ||
560 | /* hold xdma in reset also */ | ||
561 | buf[i].data = NETXEN_NIC_XDMA_RESET; | ||
562 | } | ||
563 | |||
564 | if (ADDR_IN_WINDOW1(off)) { | ||
565 | writel(buf[i].data, | ||
566 | NETXEN_CRB_NORMALIZE(adapter, off)); | ||
567 | } else { | ||
568 | netxen_nic_pci_change_crbwindow(adapter, 0); | ||
569 | writel(buf[i].data, | ||
570 | pci_base_offset(adapter, off)); | ||
571 | |||
572 | netxen_nic_pci_change_crbwindow(adapter, 1); | ||
573 | } | ||
574 | if (init_delay == 1) { | ||
575 | ssleep(1); | ||
576 | init_delay = 0; | ||
577 | } | ||
578 | msleep(1); | ||
579 | } | ||
580 | kfree(buf); | ||
581 | |||
582 | /* disable_peg_cache_all */ | ||
583 | |||
584 | /* unreset_net_cache */ | ||
585 | netxen_nic_hw_read_wx(adapter, NETXEN_ROMUSB_GLB_SW_RESET, &val, | ||
586 | 4); | ||
587 | netxen_crb_writelit_adapter(adapter, NETXEN_ROMUSB_GLB_SW_RESET, | ||
588 | (val & 0xffffff0f)); | ||
589 | /* p2dn replyCount */ | ||
590 | netxen_crb_writelit_adapter(adapter, | ||
591 | NETXEN_CRB_PEG_NET_D + 0xec, 0x1e); | ||
592 | /* disable_peg_cache 0 */ | ||
593 | netxen_crb_writelit_adapter(adapter, | ||
594 | NETXEN_CRB_PEG_NET_D + 0x4c, 8); | ||
595 | /* disable_peg_cache 1 */ | ||
596 | netxen_crb_writelit_adapter(adapter, | ||
597 | NETXEN_CRB_PEG_NET_I + 0x4c, 8); | ||
598 | |||
599 | /* peg_clr_all */ | ||
600 | |||
601 | /* peg_clr 0 */ | ||
602 | netxen_crb_writelit_adapter(adapter, NETXEN_CRB_PEG_NET_0 + 0x8, | ||
603 | 0); | ||
604 | netxen_crb_writelit_adapter(adapter, NETXEN_CRB_PEG_NET_0 + 0xc, | ||
605 | 0); | ||
606 | /* peg_clr 1 */ | ||
607 | netxen_crb_writelit_adapter(adapter, NETXEN_CRB_PEG_NET_1 + 0x8, | ||
608 | 0); | ||
609 | netxen_crb_writelit_adapter(adapter, NETXEN_CRB_PEG_NET_1 + 0xc, | ||
610 | 0); | ||
611 | /* peg_clr 2 */ | ||
612 | netxen_crb_writelit_adapter(adapter, NETXEN_CRB_PEG_NET_2 + 0x8, | ||
613 | 0); | ||
614 | netxen_crb_writelit_adapter(adapter, NETXEN_CRB_PEG_NET_2 + 0xc, | ||
615 | 0); | ||
616 | /* peg_clr 3 */ | ||
617 | netxen_crb_writelit_adapter(adapter, NETXEN_CRB_PEG_NET_3 + 0x8, | ||
618 | 0); | ||
619 | netxen_crb_writelit_adapter(adapter, NETXEN_CRB_PEG_NET_3 + 0xc, | ||
620 | 0); | ||
621 | } | ||
622 | return 0; | ||
623 | } | ||
624 | |||
625 | void netxen_phantom_init(struct netxen_adapter *adapter, int pegtune_val) | ||
626 | { | ||
627 | u32 val = 0; | ||
628 | int loops = 0; | ||
629 | |||
630 | if (!pegtune_val) { | ||
631 | while (val != PHAN_INITIALIZE_COMPLETE && loops < 200000) { | ||
632 | udelay(100); | ||
633 | schedule(); | ||
634 | val = | ||
635 | readl(NETXEN_CRB_NORMALIZE | ||
636 | (adapter, CRB_CMDPEG_STATE)); | ||
637 | loops++; | ||
638 | } | ||
639 | if (val != PHAN_INITIALIZE_COMPLETE) | ||
640 | printk("WARNING: Initial boot wait loop failed...\n"); | ||
641 | } | ||
642 | } | ||
643 | |||
644 | int netxen_nic_rx_has_work(struct netxen_adapter *adapter) | ||
645 | { | ||
646 | int ctx; | ||
647 | |||
648 | for (ctx = 0; ctx < MAX_RCV_CTX; ++ctx) { | ||
649 | struct netxen_recv_context *recv_ctx = | ||
650 | &(adapter->recv_ctx[ctx]); | ||
651 | u32 consumer; | ||
652 | struct status_desc *desc_head; | ||
653 | struct status_desc *desc; | ||
654 | |||
655 | consumer = recv_ctx->status_rx_consumer; | ||
656 | desc_head = recv_ctx->rcv_status_desc_head; | ||
657 | desc = &desc_head[consumer]; | ||
658 | |||
659 | if (((le16_to_cpu(desc->owner)) & STATUS_OWNER_HOST)) | ||
660 | return 1; | ||
661 | } | ||
662 | |||
663 | return 0; | ||
664 | } | ||
665 | |||
666 | static inline int netxen_nic_check_temp(struct netxen_adapter *adapter) | ||
667 | { | ||
668 | int port_num; | ||
669 | struct netxen_port *port; | ||
670 | struct net_device *netdev; | ||
671 | uint32_t temp, temp_state, temp_val; | ||
672 | int rv = 0; | ||
673 | |||
674 | temp = readl(NETXEN_CRB_NORMALIZE(adapter, CRB_TEMP_STATE)); | ||
675 | |||
676 | temp_state = nx_get_temp_state(temp); | ||
677 | temp_val = nx_get_temp_val(temp); | ||
678 | |||
679 | if (temp_state == NX_TEMP_PANIC) { | ||
680 | printk(KERN_ALERT | ||
681 | "%s: Device temperature %d degrees C exceeds" | ||
682 | " maximum allowed. Hardware has been shut down.\n", | ||
683 | netxen_nic_driver_name, temp_val); | ||
684 | for (port_num = 0; port_num < adapter->ahw.max_ports; | ||
685 | port_num++) { | ||
686 | port = adapter->port[port_num]; | ||
687 | netdev = port->netdev; | ||
688 | |||
689 | netif_carrier_off(netdev); | ||
690 | netif_stop_queue(netdev); | ||
691 | } | ||
692 | rv = 1; | ||
693 | } else if (temp_state == NX_TEMP_WARN) { | ||
694 | if (adapter->temp == NX_TEMP_NORMAL) { | ||
695 | printk(KERN_ALERT | ||
696 | "%s: Device temperature %d degrees C " | ||
697 | "exceeds operating range." | ||
698 | " Immediate action needed.\n", | ||
699 | netxen_nic_driver_name, temp_val); | ||
700 | } | ||
701 | } else { | ||
702 | if (adapter->temp == NX_TEMP_WARN) { | ||
703 | printk(KERN_INFO | ||
704 | "%s: Device temperature is now %d degrees C" | ||
705 | " in normal range.\n", netxen_nic_driver_name, | ||
706 | temp_val); | ||
707 | } | ||
708 | } | ||
709 | adapter->temp = temp_state; | ||
710 | return rv; | ||
711 | } | ||
712 | |||
713 | void netxen_watchdog_task(unsigned long v) | ||
714 | { | ||
715 | int port_num; | ||
716 | struct netxen_port *port; | ||
717 | struct net_device *netdev; | ||
718 | struct netxen_adapter *adapter = (struct netxen_adapter *)v; | ||
719 | |||
720 | if (netxen_nic_check_temp(adapter)) | ||
721 | return; | ||
722 | |||
723 | for (port_num = 0; port_num < adapter->ahw.max_ports; port_num++) { | ||
724 | port = adapter->port[port_num]; | ||
725 | netdev = port->netdev; | ||
726 | |||
727 | if ((netif_running(netdev)) && !netif_carrier_ok(netdev)) { | ||
728 | printk(KERN_INFO "%s port %d, %s carrier is now ok\n", | ||
729 | netxen_nic_driver_name, port_num, netdev->name); | ||
730 | netif_carrier_on(netdev); | ||
731 | } | ||
732 | |||
733 | if (netif_queue_stopped(netdev)) | ||
734 | netif_wake_queue(netdev); | ||
735 | } | ||
736 | |||
737 | if (adapter->ops->handle_phy_intr) | ||
738 | adapter->ops->handle_phy_intr(adapter); | ||
739 | mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ); | ||
740 | } | ||
741 | |||
742 | /* | ||
743 | * netxen_process_rcv() send the received packet to the protocol stack. | ||
744 | * and if the number of receives exceeds RX_BUFFERS_REFILL, then we | ||
745 | * invoke the routine to send more rx buffers to the Phantom... | ||
746 | */ | ||
747 | void | ||
748 | netxen_process_rcv(struct netxen_adapter *adapter, int ctxid, | ||
749 | struct status_desc *desc) | ||
750 | { | ||
751 | struct netxen_port *port = adapter->port[STATUS_DESC_PORT(desc)]; | ||
752 | struct pci_dev *pdev = port->pdev; | ||
753 | struct net_device *netdev = port->netdev; | ||
754 | int index = le16_to_cpu(desc->reference_handle); | ||
755 | struct netxen_recv_context *recv_ctx = &(adapter->recv_ctx[ctxid]); | ||
756 | struct netxen_rx_buffer *buffer; | ||
757 | struct sk_buff *skb; | ||
758 | u32 length = le16_to_cpu(desc->total_length); | ||
759 | u32 desc_ctx; | ||
760 | struct netxen_rcv_desc_ctx *rcv_desc; | ||
761 | int ret; | ||
762 | |||
763 | desc_ctx = STATUS_DESC_TYPE(desc); | ||
764 | if (unlikely(desc_ctx >= NUM_RCV_DESC_RINGS)) { | ||
765 | printk("%s: %s Bad Rcv descriptor ring\n", | ||
766 | netxen_nic_driver_name, netdev->name); | ||
767 | return; | ||
768 | } | ||
769 | |||
770 | rcv_desc = &recv_ctx->rcv_desc[desc_ctx]; | ||
771 | buffer = &rcv_desc->rx_buf_arr[index]; | ||
772 | |||
773 | pci_unmap_single(pdev, buffer->dma, rcv_desc->dma_size, | ||
774 | PCI_DMA_FROMDEVICE); | ||
775 | |||
776 | skb = (struct sk_buff *)buffer->skb; | ||
777 | |||
778 | if (likely(STATUS_DESC_STATUS(desc) == STATUS_CKSUM_OK)) { | ||
779 | port->stats.csummed++; | ||
780 | skb->ip_summed = CHECKSUM_UNNECESSARY; | ||
781 | } else | ||
782 | skb->ip_summed = CHECKSUM_NONE; | ||
783 | skb->dev = netdev; | ||
784 | skb_put(skb, length); | ||
785 | skb->protocol = eth_type_trans(skb, netdev); | ||
786 | |||
787 | ret = netif_receive_skb(skb); | ||
788 | |||
789 | /* | ||
790 | * RH: Do we need these stats on a regular basis. Can we get it from | ||
791 | * Linux stats. | ||
792 | */ | ||
793 | switch (ret) { | ||
794 | case NET_RX_SUCCESS: | ||
795 | port->stats.uphappy++; | ||
796 | break; | ||
797 | |||
798 | case NET_RX_CN_LOW: | ||
799 | port->stats.uplcong++; | ||
800 | break; | ||
801 | |||
802 | case NET_RX_CN_MOD: | ||
803 | port->stats.upmcong++; | ||
804 | break; | ||
805 | |||
806 | case NET_RX_CN_HIGH: | ||
807 | port->stats.uphcong++; | ||
808 | break; | ||
809 | |||
810 | case NET_RX_DROP: | ||
811 | port->stats.updropped++; | ||
812 | break; | ||
813 | |||
814 | default: | ||
815 | port->stats.updunno++; | ||
816 | break; | ||
817 | } | ||
818 | |||
819 | netdev->last_rx = jiffies; | ||
820 | |||
821 | rcv_desc->rcv_free++; | ||
822 | rcv_desc->rcv_pending--; | ||
823 | |||
824 | /* | ||
825 | * We just consumed one buffer so post a buffer. | ||
826 | */ | ||
827 | adapter->stats.post_called++; | ||
828 | buffer->skb = NULL; | ||
829 | buffer->state = NETXEN_BUFFER_FREE; | ||
830 | |||
831 | port->stats.no_rcv++; | ||
832 | port->stats.rxbytes += length; | ||
833 | } | ||
834 | |||
835 | /* Process Receive status ring */ | ||
836 | u32 netxen_process_rcv_ring(struct netxen_adapter *adapter, int ctxid, int max) | ||
837 | { | ||
838 | struct netxen_recv_context *recv_ctx = &(adapter->recv_ctx[ctxid]); | ||
839 | struct status_desc *desc_head = recv_ctx->rcv_status_desc_head; | ||
840 | struct status_desc *desc; /* used to read status desc here */ | ||
841 | u32 consumer = recv_ctx->status_rx_consumer; | ||
842 | int count = 0, ring; | ||
843 | |||
844 | DPRINTK(INFO, "procesing receive\n"); | ||
845 | /* | ||
846 | * we assume in this case that there is only one port and that is | ||
847 | * port #1...changes need to be done in firmware to indicate port | ||
848 | * number as part of the descriptor. This way we will be able to get | ||
849 | * the netdev which is associated with that device. | ||
850 | */ | ||
851 | while (count < max) { | ||
852 | desc = &desc_head[consumer]; | ||
853 | if (!((le16_to_cpu(desc->owner)) & STATUS_OWNER_HOST)) { | ||
854 | DPRINTK(ERR, "desc %p ownedby %x\n", desc, desc->owner); | ||
855 | break; | ||
856 | } | ||
857 | netxen_process_rcv(adapter, ctxid, desc); | ||
858 | desc->owner = STATUS_OWNER_PHANTOM; | ||
859 | consumer = (consumer + 1) & (adapter->max_rx_desc_count - 1); | ||
860 | count++; | ||
861 | } | ||
862 | if (count) { | ||
863 | for (ring = 0; ring < NUM_RCV_DESC_RINGS; ring++) { | ||
864 | netxen_post_rx_buffers(adapter, ctxid, ring); | ||
865 | } | ||
866 | } | ||
867 | |||
868 | /* update the consumer index in phantom */ | ||
869 | if (count) { | ||
870 | adapter->stats.process_rcv++; | ||
871 | recv_ctx->status_rx_consumer = consumer; | ||
872 | |||
873 | /* Window = 1 */ | ||
874 | writel(consumer, | ||
875 | NETXEN_CRB_NORMALIZE(adapter, | ||
876 | recv_crb_registers[ctxid]. | ||
877 | crb_rcv_status_consumer)); | ||
878 | } | ||
879 | |||
880 | return count; | ||
881 | } | ||
882 | |||
883 | /* Process Command status ring */ | ||
884 | void netxen_process_cmd_ring(unsigned long data) | ||
885 | { | ||
886 | u32 last_consumer; | ||
887 | u32 consumer; | ||
888 | struct netxen_adapter *adapter = (struct netxen_adapter *)data; | ||
889 | int count = 0; | ||
890 | struct netxen_cmd_buffer *buffer; | ||
891 | struct netxen_port *port; /* port #1 */ | ||
892 | struct netxen_port *nport; | ||
893 | struct pci_dev *pdev; | ||
894 | struct netxen_skb_frag *frag; | ||
895 | u32 i; | ||
896 | struct sk_buff *skb = NULL; | ||
897 | int p; | ||
898 | |||
899 | spin_lock(&adapter->tx_lock); | ||
900 | last_consumer = adapter->last_cmd_consumer; | ||
901 | DPRINTK(INFO, "procesing xmit complete\n"); | ||
902 | /* we assume in this case that there is only one port and that is | ||
903 | * port #1...changes need to be done in firmware to indicate port | ||
904 | * number as part of the descriptor. This way we will be able to get | ||
905 | * the netdev which is associated with that device. | ||
906 | */ | ||
907 | consumer = | ||
908 | readl(NETXEN_CRB_NORMALIZE(adapter, CRB_CMD_CONSUMER_OFFSET)); | ||
909 | |||
910 | if (last_consumer == consumer) { /* Ring is empty */ | ||
911 | DPRINTK(INFO, "last_consumer %d == consumer %d\n", | ||
912 | last_consumer, consumer); | ||
913 | spin_unlock(&adapter->tx_lock); | ||
914 | return; | ||
915 | } | ||
916 | |||
917 | adapter->proc_cmd_buf_counter++; | ||
918 | adapter->stats.process_xmit++; | ||
919 | /* | ||
920 | * Not needed - does not seem to be used anywhere. | ||
921 | * adapter->cmd_consumer = consumer; | ||
922 | */ | ||
923 | spin_unlock(&adapter->tx_lock); | ||
924 | |||
925 | while ((last_consumer != consumer) && (count < MAX_STATUS_HANDLE)) { | ||
926 | buffer = &adapter->cmd_buf_arr[last_consumer]; | ||
927 | port = adapter->port[buffer->port]; | ||
928 | pdev = port->pdev; | ||
929 | frag = &buffer->frag_array[0]; | ||
930 | skb = buffer->skb; | ||
931 | if (skb && (cmpxchg(&buffer->skb, skb, 0) == skb)) { | ||
932 | pci_unmap_single(pdev, frag->dma, frag->length, | ||
933 | PCI_DMA_TODEVICE); | ||
934 | for (i = 1; i < buffer->frag_count; i++) { | ||
935 | DPRINTK(INFO, "getting fragment no %d\n", i); | ||
936 | frag++; /* Get the next frag */ | ||
937 | pci_unmap_page(pdev, frag->dma, frag->length, | ||
938 | PCI_DMA_TODEVICE); | ||
939 | } | ||
940 | |||
941 | port->stats.skbfreed++; | ||
942 | dev_kfree_skb_any(skb); | ||
943 | skb = NULL; | ||
944 | } else if (adapter->proc_cmd_buf_counter == 1) { | ||
945 | port->stats.txnullskb++; | ||
946 | } | ||
947 | if (unlikely(netif_queue_stopped(port->netdev) | ||
948 | && netif_carrier_ok(port->netdev)) | ||
949 | && ((jiffies - port->netdev->trans_start) > | ||
950 | port->netdev->watchdog_timeo)) { | ||
951 | schedule_work(&port->adapter->tx_timeout_task); | ||
952 | } | ||
953 | |||
954 | last_consumer = get_next_index(last_consumer, | ||
955 | adapter->max_tx_desc_count); | ||
956 | count++; | ||
957 | } | ||
958 | adapter->stats.noxmitdone += count; | ||
959 | |||
960 | count = 0; | ||
961 | spin_lock(&adapter->tx_lock); | ||
962 | if ((--adapter->proc_cmd_buf_counter) == 0) { | ||
963 | adapter->last_cmd_consumer = last_consumer; | ||
964 | while ((adapter->last_cmd_consumer != consumer) | ||
965 | && (count < MAX_STATUS_HANDLE)) { | ||
966 | buffer = | ||
967 | &adapter->cmd_buf_arr[adapter->last_cmd_consumer]; | ||
968 | count++; | ||
969 | if (buffer->skb) | ||
970 | break; | ||
971 | else | ||
972 | adapter->last_cmd_consumer = | ||
973 | get_next_index(adapter->last_cmd_consumer, | ||
974 | adapter->max_tx_desc_count); | ||
975 | } | ||
976 | } | ||
977 | if (count) { | ||
978 | for (p = 0; p < adapter->ahw.max_ports; p++) { | ||
979 | nport = adapter->port[p]; | ||
980 | if (netif_queue_stopped(nport->netdev) | ||
981 | && (nport->flags & NETXEN_NETDEV_STATUS)) { | ||
982 | netif_wake_queue(nport->netdev); | ||
983 | nport->flags &= ~NETXEN_NETDEV_STATUS; | ||
984 | } | ||
985 | } | ||
986 | } | ||
987 | |||
988 | spin_unlock(&adapter->tx_lock); | ||
989 | DPRINTK(INFO, "last consumer is %d in %s\n", last_consumer, | ||
990 | __FUNCTION__); | ||
991 | } | ||
992 | |||
993 | /* | ||
994 | * netxen_post_rx_buffers puts buffer in the Phantom memory | ||
995 | */ | ||
996 | void netxen_post_rx_buffers(struct netxen_adapter *adapter, u32 ctx, u32 ringid) | ||
997 | { | ||
998 | struct pci_dev *pdev = adapter->ahw.pdev; | ||
999 | struct sk_buff *skb; | ||
1000 | struct netxen_recv_context *recv_ctx = &(adapter->recv_ctx[ctx]); | ||
1001 | struct netxen_rcv_desc_ctx *rcv_desc = NULL; | ||
1002 | struct netxen_recv_crb *crbarea = &recv_crb_registers[ctx]; | ||
1003 | struct netxen_rcv_desc_crb *rcv_desc_crb = NULL; | ||
1004 | u32 producer; | ||
1005 | struct rcv_desc *pdesc; | ||
1006 | struct netxen_rx_buffer *buffer; | ||
1007 | int count = 0; | ||
1008 | int index = 0; | ||
1009 | |||
1010 | adapter->stats.post_called++; | ||
1011 | rcv_desc = &recv_ctx->rcv_desc[ringid]; | ||
1012 | rcv_desc_crb = &crbarea->rcv_desc_crb[ringid]; | ||
1013 | |||
1014 | producer = rcv_desc->producer; | ||
1015 | index = rcv_desc->begin_alloc; | ||
1016 | buffer = &rcv_desc->rx_buf_arr[index]; | ||
1017 | /* We can start writing rx descriptors into the phantom memory. */ | ||
1018 | while (buffer->state == NETXEN_BUFFER_FREE) { | ||
1019 | skb = dev_alloc_skb(rcv_desc->skb_size); | ||
1020 | if (unlikely(!skb)) { | ||
1021 | /* | ||
1022 | * We need to schedule the posting of buffers to the pegs. | ||
1023 | */ | ||
1024 | rcv_desc->begin_alloc = index; | ||
1025 | DPRINTK(ERR, "netxen_post_rx_buffers: " | ||
1026 | " allocated only %d buffers\n", count); | ||
1027 | break; | ||
1028 | } | ||
1029 | count++; /* now there should be no failure */ | ||
1030 | pdesc = &rcv_desc->desc_head[producer]; | ||
1031 | skb_reserve(skb, NET_IP_ALIGN); | ||
1032 | /* | ||
1033 | * This will be setup when we receive the | ||
1034 | * buffer after it has been filled | ||
1035 | * skb->dev = netdev; | ||
1036 | */ | ||
1037 | buffer->skb = skb; | ||
1038 | buffer->state = NETXEN_BUFFER_BUSY; | ||
1039 | buffer->dma = pci_map_single(pdev, skb->data, | ||
1040 | rcv_desc->dma_size, | ||
1041 | PCI_DMA_FROMDEVICE); | ||
1042 | /* make a rcv descriptor */ | ||
1043 | pdesc->reference_handle = le16_to_cpu(buffer->ref_handle); | ||
1044 | pdesc->buffer_length = le16_to_cpu(rcv_desc->dma_size); | ||
1045 | pdesc->addr_buffer = cpu_to_le64(buffer->dma); | ||
1046 | DPRINTK(INFO, "done writing descripter\n"); | ||
1047 | producer = | ||
1048 | get_next_index(producer, rcv_desc->max_rx_desc_count); | ||
1049 | index = get_next_index(index, rcv_desc->max_rx_desc_count); | ||
1050 | buffer = &rcv_desc->rx_buf_arr[index]; | ||
1051 | } | ||
1052 | |||
1053 | /* if we did allocate buffers, then write the count to Phantom */ | ||
1054 | if (count) { | ||
1055 | rcv_desc->begin_alloc = index; | ||
1056 | rcv_desc->rcv_pending += count; | ||
1057 | adapter->stats.lastposted = count; | ||
1058 | adapter->stats.posted += count; | ||
1059 | rcv_desc->producer = producer; | ||
1060 | if (rcv_desc->rcv_free >= 32) { | ||
1061 | rcv_desc->rcv_free = 0; | ||
1062 | /* Window = 1 */ | ||
1063 | writel((producer - 1) & | ||
1064 | (rcv_desc->max_rx_desc_count - 1), | ||
1065 | NETXEN_CRB_NORMALIZE(adapter, | ||
1066 | rcv_desc_crb-> | ||
1067 | crb_rcv_producer_offset)); | ||
1068 | wmb(); | ||
1069 | } | ||
1070 | } | ||
1071 | } | ||
1072 | |||
1073 | int netxen_nic_tx_has_work(struct netxen_adapter *adapter) | ||
1074 | { | ||
1075 | if (find_diff_among(adapter->last_cmd_consumer, | ||
1076 | adapter->cmd_producer, | ||
1077 | adapter->max_tx_desc_count) > 0) | ||
1078 | return 1; | ||
1079 | |||
1080 | return 0; | ||
1081 | } | ||
1082 | |||
1083 | int | ||
1084 | netxen_nic_fill_statistics(struct netxen_adapter *adapter, | ||
1085 | struct netxen_port *port, | ||
1086 | struct netxen_statistics *netxen_stats) | ||
1087 | { | ||
1088 | void __iomem *addr; | ||
1089 | |||
1090 | if (adapter->ahw.board_type == NETXEN_NIC_XGBE) { | ||
1091 | netxen_nic_pci_change_crbwindow(adapter, 0); | ||
1092 | NETXEN_NIC_LOCKED_READ_REG(NETXEN_NIU_XGE_TX_BYTE_CNT, | ||
1093 | &(netxen_stats->tx_bytes)); | ||
1094 | NETXEN_NIC_LOCKED_READ_REG(NETXEN_NIU_XGE_TX_FRAME_CNT, | ||
1095 | &(netxen_stats->tx_packets)); | ||
1096 | NETXEN_NIC_LOCKED_READ_REG(NETXEN_NIU_XGE_RX_BYTE_CNT, | ||
1097 | &(netxen_stats->rx_bytes)); | ||
1098 | NETXEN_NIC_LOCKED_READ_REG(NETXEN_NIU_XGE_RX_FRAME_CNT, | ||
1099 | &(netxen_stats->rx_packets)); | ||
1100 | NETXEN_NIC_LOCKED_READ_REG(NETXEN_NIU_XGE_AGGR_ERROR_CNT, | ||
1101 | &(netxen_stats->rx_errors)); | ||
1102 | NETXEN_NIC_LOCKED_READ_REG(NETXEN_NIU_XGE_CRC_ERROR_CNT, | ||
1103 | &(netxen_stats->rx_crc_errors)); | ||
1104 | NETXEN_NIC_LOCKED_READ_REG(NETXEN_NIU_XGE_OVERSIZE_FRAME_ERR, | ||
1105 | &(netxen_stats-> | ||
1106 | rx_long_length_error)); | ||
1107 | NETXEN_NIC_LOCKED_READ_REG(NETXEN_NIU_XGE_UNDERSIZE_FRAME_ERR, | ||
1108 | &(netxen_stats-> | ||
1109 | rx_short_length_error)); | ||
1110 | |||
1111 | netxen_nic_pci_change_crbwindow(adapter, 1); | ||
1112 | } else { | ||
1113 | spin_lock_bh(&adapter->tx_lock); | ||
1114 | netxen_stats->tx_bytes = port->stats.txbytes; | ||
1115 | netxen_stats->tx_packets = port->stats.xmitedframes + | ||
1116 | port->stats.xmitfinished; | ||
1117 | netxen_stats->rx_bytes = port->stats.rxbytes; | ||
1118 | netxen_stats->rx_packets = port->stats.no_rcv; | ||
1119 | netxen_stats->rx_errors = port->stats.rcvdbadskb; | ||
1120 | netxen_stats->tx_errors = port->stats.nocmddescriptor; | ||
1121 | netxen_stats->rx_short_length_error = port->stats.uplcong; | ||
1122 | netxen_stats->rx_long_length_error = port->stats.uphcong; | ||
1123 | netxen_stats->rx_crc_errors = 0; | ||
1124 | netxen_stats->rx_mac_errors = 0; | ||
1125 | spin_unlock_bh(&adapter->tx_lock); | ||
1126 | } | ||
1127 | return 0; | ||
1128 | } | ||
1129 | |||
1130 | void netxen_nic_clear_stats(struct netxen_adapter *adapter) | ||
1131 | { | ||
1132 | struct netxen_port *port; | ||
1133 | int port_num; | ||
1134 | |||
1135 | memset(&adapter->stats, 0, sizeof(adapter->stats)); | ||
1136 | for (port_num = 0; port_num < adapter->ahw.max_ports; port_num++) { | ||
1137 | port = adapter->port[port_num]; | ||
1138 | memset(&port->stats, 0, sizeof(port->stats)); | ||
1139 | } | ||
1140 | } | ||
1141 | |||
1142 | int | ||
1143 | netxen_nic_clear_statistics(struct netxen_adapter *adapter, | ||
1144 | struct netxen_port *port) | ||
1145 | { | ||
1146 | int data = 0; | ||
1147 | |||
1148 | netxen_nic_pci_change_crbwindow(adapter, 0); | ||
1149 | |||
1150 | netxen_nic_locked_write_reg(adapter, NETXEN_NIU_XGE_TX_BYTE_CNT, &data); | ||
1151 | netxen_nic_locked_write_reg(adapter, NETXEN_NIU_XGE_TX_FRAME_CNT, | ||
1152 | &data); | ||
1153 | netxen_nic_locked_write_reg(adapter, NETXEN_NIU_XGE_RX_BYTE_CNT, &data); | ||
1154 | netxen_nic_locked_write_reg(adapter, NETXEN_NIU_XGE_RX_FRAME_CNT, | ||
1155 | &data); | ||
1156 | netxen_nic_locked_write_reg(adapter, NETXEN_NIU_XGE_AGGR_ERROR_CNT, | ||
1157 | &data); | ||
1158 | netxen_nic_locked_write_reg(adapter, NETXEN_NIU_XGE_CRC_ERROR_CNT, | ||
1159 | &data); | ||
1160 | netxen_nic_locked_write_reg(adapter, NETXEN_NIU_XGE_OVERSIZE_FRAME_ERR, | ||
1161 | &data); | ||
1162 | netxen_nic_locked_write_reg(adapter, NETXEN_NIU_XGE_UNDERSIZE_FRAME_ERR, | ||
1163 | &data); | ||
1164 | |||
1165 | netxen_nic_pci_change_crbwindow(adapter, 1); | ||
1166 | netxen_nic_clear_stats(adapter); | ||
1167 | return 0; | ||
1168 | } | ||
1169 | |||
1170 | int | ||
1171 | netxen_nic_do_ioctl(struct netxen_adapter *adapter, void *u_data, | ||
1172 | struct netxen_port *port) | ||
1173 | { | ||
1174 | struct netxen_nic_ioctl_data data; | ||
1175 | struct netxen_nic_ioctl_data *up_data; | ||
1176 | int retval = 0; | ||
1177 | struct netxen_statistics netxen_stats; | ||
1178 | |||
1179 | up_data = (void *)u_data; | ||
1180 | |||
1181 | DPRINTK(INFO, "doing ioctl for %p\n", adapter); | ||
1182 | if (copy_from_user(&data, (void __user *)up_data, sizeof(data))) { | ||
1183 | /* evil user tried to crash the kernel */ | ||
1184 | DPRINTK(ERR, "bad copy from userland: %d\n", (int)sizeof(data)); | ||
1185 | retval = -EFAULT; | ||
1186 | goto error_out; | ||
1187 | } | ||
1188 | |||
1189 | /* Shouldn't access beyond legal limits of "char u[64];" member */ | ||
1190 | if (!data.ptr && (data.size > sizeof(data.u))) { | ||
1191 | /* evil user tried to crash the kernel */ | ||
1192 | DPRINTK(ERR, "bad size: %d\n", data.size); | ||
1193 | retval = -EFAULT; | ||
1194 | goto error_out; | ||
1195 | } | ||
1196 | |||
1197 | switch (data.cmd) { | ||
1198 | case netxen_nic_cmd_pci_read: | ||
1199 | if ((retval = netxen_nic_hw_read_wx(adapter, data.off, | ||
1200 | &(data.u), data.size))) | ||
1201 | goto error_out; | ||
1202 | if (copy_to_user | ||
1203 | ((void __user *)&(up_data->u), &(data.u), data.size)) { | ||
1204 | DPRINTK(ERR, "bad copy to userland: %d\n", | ||
1205 | (int)sizeof(data)); | ||
1206 | retval = -EFAULT; | ||
1207 | goto error_out; | ||
1208 | } | ||
1209 | data.rv = 0; | ||
1210 | break; | ||
1211 | |||
1212 | case netxen_nic_cmd_pci_write: | ||
1213 | data.rv = netxen_nic_hw_write_wx(adapter, data.off, &(data.u), | ||
1214 | data.size); | ||
1215 | break; | ||
1216 | |||
1217 | case netxen_nic_cmd_pci_config_read: | ||
1218 | switch (data.size) { | ||
1219 | case 1: | ||
1220 | data.rv = pci_read_config_byte(adapter->ahw.pdev, | ||
1221 | data.off, | ||
1222 | (char *)&(data.u)); | ||
1223 | break; | ||
1224 | case 2: | ||
1225 | data.rv = pci_read_config_word(adapter->ahw.pdev, | ||
1226 | data.off, | ||
1227 | (short *)&(data.u)); | ||
1228 | break; | ||
1229 | case 4: | ||
1230 | data.rv = pci_read_config_dword(adapter->ahw.pdev, | ||
1231 | data.off, | ||
1232 | (u32 *) & (data.u)); | ||
1233 | break; | ||
1234 | } | ||
1235 | if (copy_to_user | ||
1236 | ((void __user *)&(up_data->u), &(data.u), data.size)) { | ||
1237 | DPRINTK(ERR, "bad copy to userland: %d\n", | ||
1238 | (int)sizeof(data)); | ||
1239 | retval = -EFAULT; | ||
1240 | goto error_out; | ||
1241 | } | ||
1242 | break; | ||
1243 | |||
1244 | case netxen_nic_cmd_pci_config_write: | ||
1245 | switch (data.size) { | ||
1246 | case 1: | ||
1247 | data.rv = pci_write_config_byte(adapter->ahw.pdev, | ||
1248 | data.off, | ||
1249 | *(char *)&(data.u)); | ||
1250 | break; | ||
1251 | case 2: | ||
1252 | data.rv = pci_write_config_word(adapter->ahw.pdev, | ||
1253 | data.off, | ||
1254 | *(short *)&(data.u)); | ||
1255 | break; | ||
1256 | case 4: | ||
1257 | data.rv = pci_write_config_dword(adapter->ahw.pdev, | ||
1258 | data.off, | ||
1259 | *(u32 *) & (data.u)); | ||
1260 | break; | ||
1261 | } | ||
1262 | break; | ||
1263 | |||
1264 | case netxen_nic_cmd_get_stats: | ||
1265 | data.rv = | ||
1266 | netxen_nic_fill_statistics(adapter, port, &netxen_stats); | ||
1267 | if (copy_to_user | ||
1268 | ((void __user *)(up_data->ptr), (void *)&netxen_stats, | ||
1269 | sizeof(struct netxen_statistics))) { | ||
1270 | DPRINTK(ERR, "bad copy to userland: %d\n", | ||
1271 | (int)sizeof(netxen_stats)); | ||
1272 | retval = -EFAULT; | ||
1273 | goto error_out; | ||
1274 | } | ||
1275 | up_data->rv = data.rv; | ||
1276 | break; | ||
1277 | |||
1278 | case netxen_nic_cmd_clear_stats: | ||
1279 | data.rv = netxen_nic_clear_statistics(adapter, port); | ||
1280 | up_data->rv = data.rv; | ||
1281 | break; | ||
1282 | |||
1283 | case netxen_nic_cmd_get_version: | ||
1284 | if (copy_to_user | ||
1285 | ((void __user *)&(up_data->u), NETXEN_NIC_LINUX_VERSIONID, | ||
1286 | sizeof(NETXEN_NIC_LINUX_VERSIONID))) { | ||
1287 | DPRINTK(ERR, "bad copy to userland: %d\n", | ||
1288 | (int)sizeof(data)); | ||
1289 | retval = -EFAULT; | ||
1290 | goto error_out; | ||
1291 | } | ||
1292 | break; | ||
1293 | |||
1294 | default: | ||
1295 | DPRINTK(INFO, "bad command %d for %p\n", data.cmd, adapter); | ||
1296 | retval = -EOPNOTSUPP; | ||
1297 | goto error_out; | ||
1298 | } | ||
1299 | put_user(data.rv, (u16 __user *) (&(up_data->rv))); | ||
1300 | DPRINTK(INFO, "done ioctl for %p well.\n", adapter); | ||
1301 | |||
1302 | error_out: | ||
1303 | return retval; | ||
1304 | } | ||
diff --git a/drivers/net/netxen/netxen_nic_ioctl.h b/drivers/net/netxen/netxen_nic_ioctl.h new file mode 100644 index 000000000000..23e53adbf123 --- /dev/null +++ b/drivers/net/netxen/netxen_nic_ioctl.h | |||
@@ -0,0 +1,77 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2003 - 2006 NetXen, Inc. | ||
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 LICENSE. | ||
22 | * | ||
23 | * Contact Information: | ||
24 | * info@netxen.com | ||
25 | * NetXen, | ||
26 | * 3965 Freedom Circle, Fourth floor, | ||
27 | * Santa Clara, CA 95054 | ||
28 | */ | ||
29 | |||
30 | #ifndef __NETXEN_NIC_IOCTL_H__ | ||
31 | #define __NETXEN_NIC_IOCTL_H__ | ||
32 | |||
33 | #include <linux/sockios.h> | ||
34 | |||
35 | #define NETXEN_CMD_START SIOCDEVPRIVATE | ||
36 | #define NETXEN_NIC_CMD (NETXEN_CMD_START + 1) | ||
37 | #define NETXEN_NIC_NAME (NETXEN_CMD_START + 2) | ||
38 | #define NETXEN_NIC_NAME_LEN 16 | ||
39 | #define NETXEN_NIC_NAME_RSP "NETXEN" | ||
40 | |||
41 | typedef enum { | ||
42 | netxen_nic_cmd_none = 0, | ||
43 | netxen_nic_cmd_pci_read, | ||
44 | netxen_nic_cmd_pci_write, | ||
45 | netxen_nic_cmd_pci_mem_read, | ||
46 | netxen_nic_cmd_pci_mem_write, | ||
47 | netxen_nic_cmd_pci_config_read, | ||
48 | netxen_nic_cmd_pci_config_write, | ||
49 | netxen_nic_cmd_get_stats, | ||
50 | netxen_nic_cmd_clear_stats, | ||
51 | netxen_nic_cmd_get_version | ||
52 | } netxen_nic_ioctl_cmd_t; | ||
53 | |||
54 | struct netxen_nic_ioctl_data { | ||
55 | u32 cmd; | ||
56 | u32 unused1; | ||
57 | u64 off; | ||
58 | u32 size; | ||
59 | u32 rv; | ||
60 | char u[64]; | ||
61 | void *ptr; | ||
62 | }; | ||
63 | |||
64 | struct netxen_statistics { | ||
65 | u64 rx_packets; | ||
66 | u64 tx_packets; | ||
67 | u64 rx_bytes; | ||
68 | u64 rx_errors; | ||
69 | u64 tx_bytes; | ||
70 | u64 tx_errors; | ||
71 | u64 rx_crc_errors; | ||
72 | u64 rx_short_length_error; | ||
73 | u64 rx_long_length_error; | ||
74 | u64 rx_mac_errors; | ||
75 | }; | ||
76 | |||
77 | #endif /* __NETXEN_NIC_IOCTL_H_ */ | ||
diff --git a/drivers/net/netxen/netxen_nic_isr.c b/drivers/net/netxen/netxen_nic_isr.c new file mode 100644 index 000000000000..ae180fee8008 --- /dev/null +++ b/drivers/net/netxen/netxen_nic_isr.c | |||
@@ -0,0 +1,215 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2003 - 2006 NetXen, Inc. | ||
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 LICENSE. | ||
22 | * | ||
23 | * Contact Information: | ||
24 | * info@netxen.com | ||
25 | * NetXen, | ||
26 | * 3965 Freedom Circle, Fourth floor, | ||
27 | * Santa Clara, CA 95054 | ||
28 | */ | ||
29 | |||
30 | #include <linux/netdevice.h> | ||
31 | #include <linux/delay.h> | ||
32 | |||
33 | #include "netxen_nic.h" | ||
34 | #include "netxen_nic_hw.h" | ||
35 | #include "netxen_nic_phan_reg.h" | ||
36 | |||
37 | /* | ||
38 | * netxen_nic_get_stats - Get System Network Statistics | ||
39 | * @netdev: network interface device structure | ||
40 | */ | ||
41 | struct net_device_stats *netxen_nic_get_stats(struct net_device *netdev) | ||
42 | { | ||
43 | struct netxen_port *port = netdev_priv(netdev); | ||
44 | struct net_device_stats *stats = &port->net_stats; | ||
45 | |||
46 | memset(stats, 0, sizeof(*stats)); | ||
47 | |||
48 | /* total packets received */ | ||
49 | stats->rx_packets = port->stats.no_rcv; | ||
50 | /* total packets transmitted */ | ||
51 | stats->tx_packets = port->stats.xmitedframes + port->stats.xmitfinished; | ||
52 | /* total bytes received */ | ||
53 | stats->rx_bytes = port->stats.rxbytes; | ||
54 | /* total bytes transmitted */ | ||
55 | stats->tx_bytes = port->stats.txbytes; | ||
56 | /* bad packets received */ | ||
57 | stats->rx_errors = port->stats.rcvdbadskb; | ||
58 | /* packet transmit problems */ | ||
59 | stats->tx_errors = port->stats.nocmddescriptor; | ||
60 | /* no space in linux buffers */ | ||
61 | stats->rx_dropped = port->stats.updropped; | ||
62 | /* no space available in linux */ | ||
63 | stats->tx_dropped = port->stats.txdropped; | ||
64 | |||
65 | return stats; | ||
66 | } | ||
67 | |||
68 | void netxen_indicate_link_status(struct netxen_adapter *adapter, u32 portno, | ||
69 | u32 link) | ||
70 | { | ||
71 | struct netxen_port *pport = adapter->port[portno]; | ||
72 | struct net_device *netdev = pport->netdev; | ||
73 | |||
74 | if (link) | ||
75 | netif_carrier_on(netdev); | ||
76 | else | ||
77 | netif_carrier_off(netdev); | ||
78 | } | ||
79 | |||
80 | void netxen_handle_port_int(struct netxen_adapter *adapter, u32 portno, | ||
81 | u32 enable) | ||
82 | { | ||
83 | __le32 int_src; | ||
84 | struct netxen_port *port; | ||
85 | |||
86 | /* This should clear the interrupt source */ | ||
87 | if (adapter->ops->phy_read) | ||
88 | adapter->ops->phy_read(adapter, portno, | ||
89 | NETXEN_NIU_GB_MII_MGMT_ADDR_INT_STATUS, | ||
90 | &int_src); | ||
91 | if (int_src == 0) { | ||
92 | DPRINTK(INFO, "No phy interrupts for port #%d\n", portno); | ||
93 | return; | ||
94 | } | ||
95 | if (adapter->ops->disable_phy_interrupts) | ||
96 | adapter->ops->disable_phy_interrupts(adapter, portno); | ||
97 | |||
98 | port = adapter->port[portno]; | ||
99 | |||
100 | if (netxen_get_phy_int_jabber(int_src)) | ||
101 | DPRINTK(INFO, "NetXen: %s Jabber interrupt \n", | ||
102 | port->netdev->name); | ||
103 | |||
104 | if (netxen_get_phy_int_polarity_changed(int_src)) | ||
105 | DPRINTK(INFO, "NetXen: %s POLARITY CHANGED int \n", | ||
106 | port->netdev->name); | ||
107 | |||
108 | if (netxen_get_phy_int_energy_detect(int_src)) | ||
109 | DPRINTK(INFO, "NetXen: %s ENERGY DETECT INT \n", | ||
110 | port->netdev->name); | ||
111 | |||
112 | if (netxen_get_phy_int_downshift(int_src)) | ||
113 | DPRINTK(INFO, "NetXen: %s DOWNSHIFT INT \n", | ||
114 | port->netdev->name); | ||
115 | /* write it down later.. */ | ||
116 | if ((netxen_get_phy_int_speed_changed(int_src)) | ||
117 | || (netxen_get_phy_int_link_status_changed(int_src))) { | ||
118 | __le32 status; | ||
119 | |||
120 | DPRINTK(INFO, "NetXen: %s SPEED CHANGED OR" | ||
121 | " LINK STATUS CHANGED \n", port->netdev->name); | ||
122 | |||
123 | if (adapter->ops->phy_read | ||
124 | && adapter->ops->phy_read(adapter, portno, | ||
125 | NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS, | ||
126 | &status) == 0) { | ||
127 | if (netxen_get_phy_int_link_status_changed(int_src)) { | ||
128 | if (netxen_get_phy_link(status)) { | ||
129 | netxen_niu_gbe_init_port(adapter, | ||
130 | portno); | ||
131 | printk("%s: %s Link UP\n", | ||
132 | netxen_nic_driver_name, | ||
133 | port->netdev->name); | ||
134 | |||
135 | } else { | ||
136 | printk("%s: %s Link DOWN\n", | ||
137 | netxen_nic_driver_name, | ||
138 | port->netdev->name); | ||
139 | } | ||
140 | netxen_indicate_link_status(adapter, portno, | ||
141 | netxen_get_phy_link | ||
142 | (status)); | ||
143 | } | ||
144 | } | ||
145 | } | ||
146 | if (adapter->ops->enable_phy_interrupts) | ||
147 | adapter->ops->enable_phy_interrupts(adapter, portno); | ||
148 | } | ||
149 | |||
150 | void netxen_nic_isr_other(struct netxen_adapter *adapter) | ||
151 | { | ||
152 | u32 portno; | ||
153 | u32 val, linkup, qg_linksup; | ||
154 | |||
155 | /* verify the offset */ | ||
156 | val = readl(NETXEN_CRB_NORMALIZE(adapter, CRB_XG_STATE)); | ||
157 | if (val == adapter->ahw.qg_linksup) | ||
158 | return; | ||
159 | |||
160 | qg_linksup = adapter->ahw.qg_linksup; | ||
161 | adapter->ahw.qg_linksup = val; | ||
162 | DPRINTK(1, INFO, "%s: link update 0x%08x\n", netxen_nic_driver_name, | ||
163 | val); | ||
164 | for (portno = 0; portno < NETXEN_NIU_MAX_GBE_PORTS; portno++) { | ||
165 | linkup = val & 1; | ||
166 | if (linkup != (qg_linksup & 1)) { | ||
167 | printk(KERN_INFO "%s: PORT %d link %s\n", | ||
168 | netxen_nic_driver_name, portno, | ||
169 | ((linkup == 0) ? "down" : "up")); | ||
170 | netxen_indicate_link_status(adapter, portno, linkup); | ||
171 | if (linkup) | ||
172 | netxen_nic_set_link_parameters(adapter-> | ||
173 | port[portno]); | ||
174 | |||
175 | } | ||
176 | val = val >> 1; | ||
177 | qg_linksup = qg_linksup >> 1; | ||
178 | } | ||
179 | |||
180 | adapter->stats.otherints++; | ||
181 | |||
182 | } | ||
183 | |||
184 | void netxen_nic_gbe_handle_phy_intr(struct netxen_adapter *adapter) | ||
185 | { | ||
186 | netxen_nic_isr_other(adapter); | ||
187 | } | ||
188 | |||
189 | void netxen_nic_xgbe_handle_phy_intr(struct netxen_adapter *adapter) | ||
190 | { | ||
191 | struct net_device *netdev = adapter->port[0]->netdev; | ||
192 | u32 val; | ||
193 | |||
194 | /* WINDOW = 1 */ | ||
195 | val = readl(NETXEN_CRB_NORMALIZE(adapter, CRB_XG_STATE)); | ||
196 | |||
197 | if (adapter->ahw.xg_linkup == 1 && val != XG_LINK_UP) { | ||
198 | printk(KERN_INFO "%s: %s NIC Link is down\n", | ||
199 | netxen_nic_driver_name, netdev->name); | ||
200 | adapter->ahw.xg_linkup = 0; | ||
201 | /* read twice to clear sticky bits */ | ||
202 | /* WINDOW = 0 */ | ||
203 | netxen_nic_read_w0(adapter, NETXEN_NIU_XG_STATUS, &val); | ||
204 | netxen_nic_read_w0(adapter, NETXEN_NIU_XG_STATUS, &val); | ||
205 | |||
206 | if ((val & 0xffb) != 0xffb) { | ||
207 | printk(KERN_INFO "%s ISR: Sync/Align BAD: 0x%08x\n", | ||
208 | netxen_nic_driver_name, val); | ||
209 | } | ||
210 | } else if (adapter->ahw.xg_linkup == 0 && val == XG_LINK_UP) { | ||
211 | printk(KERN_INFO "%s: %s NIC Link is up\n", | ||
212 | netxen_nic_driver_name, netdev->name); | ||
213 | adapter->ahw.xg_linkup = 1; | ||
214 | } | ||
215 | } | ||
diff --git a/drivers/net/netxen/netxen_nic_main.c b/drivers/net/netxen/netxen_nic_main.c new file mode 100644 index 000000000000..1cb662d5bd76 --- /dev/null +++ b/drivers/net/netxen/netxen_nic_main.c | |||
@@ -0,0 +1,1161 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2003 - 2006 NetXen, Inc. | ||
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 LICENSE. | ||
22 | * | ||
23 | * Contact Information: | ||
24 | * info@netxen.com | ||
25 | * NetXen, | ||
26 | * 3965 Freedom Circle, Fourth floor, | ||
27 | * Santa Clara, CA 95054 | ||
28 | * | ||
29 | * | ||
30 | * Main source file for NetXen NIC Driver on Linux | ||
31 | * | ||
32 | */ | ||
33 | |||
34 | #include <linux/vmalloc.h> | ||
35 | #include "netxen_nic_hw.h" | ||
36 | |||
37 | #include "netxen_nic.h" | ||
38 | #define DEFINE_GLOBAL_RECV_CRB | ||
39 | #include "netxen_nic_phan_reg.h" | ||
40 | #include "netxen_nic_ioctl.h" | ||
41 | |||
42 | #include <linux/dma-mapping.h> | ||
43 | #include <linux/vmalloc.h> | ||
44 | |||
45 | #define PHAN_VENDOR_ID 0x4040 | ||
46 | |||
47 | MODULE_DESCRIPTION("NetXen Multi port (1/10) Gigabit Network Driver"); | ||
48 | MODULE_LICENSE("GPL"); | ||
49 | MODULE_VERSION(NETXEN_NIC_LINUX_VERSIONID); | ||
50 | |||
51 | char netxen_nic_driver_name[] = "netxen"; | ||
52 | static char netxen_nic_driver_string[] = "NetXen Network Driver version " | ||
53 | NETXEN_NIC_LINUX_VERSIONID; | ||
54 | |||
55 | #define NETXEN_NETDEV_WEIGHT 120 | ||
56 | #define NETXEN_ADAPTER_UP_MAGIC 777 | ||
57 | #define NETXEN_NIC_PEG_TUNE 0 | ||
58 | |||
59 | /* Local functions to NetXen NIC driver */ | ||
60 | static int __devinit netxen_nic_probe(struct pci_dev *pdev, | ||
61 | const struct pci_device_id *ent); | ||
62 | static void __devexit netxen_nic_remove(struct pci_dev *pdev); | ||
63 | static int netxen_nic_open(struct net_device *netdev); | ||
64 | static int netxen_nic_close(struct net_device *netdev); | ||
65 | static int netxen_nic_xmit_frame(struct sk_buff *, struct net_device *); | ||
66 | static void netxen_tx_timeout(struct net_device *netdev); | ||
67 | static void netxen_tx_timeout_task(struct net_device *netdev); | ||
68 | static void netxen_watchdog(unsigned long); | ||
69 | static int netxen_handle_int(struct netxen_adapter *, struct net_device *); | ||
70 | static int netxen_nic_ioctl(struct net_device *netdev, | ||
71 | struct ifreq *ifr, int cmd); | ||
72 | static int netxen_nic_poll(struct net_device *dev, int *budget); | ||
73 | #ifdef CONFIG_NET_POLL_CONTROLLER | ||
74 | static void netxen_nic_poll_controller(struct net_device *netdev); | ||
75 | #endif | ||
76 | static irqreturn_t netxen_intr(int irq, void *data); | ||
77 | |||
78 | /* PCI Device ID Table */ | ||
79 | static struct pci_device_id netxen_pci_tbl[] __devinitdata = { | ||
80 | {PCI_DEVICE(0x4040, 0x0001)}, | ||
81 | {PCI_DEVICE(0x4040, 0x0002)}, | ||
82 | {PCI_DEVICE(0x4040, 0x0003)}, | ||
83 | {PCI_DEVICE(0x4040, 0x0004)}, | ||
84 | {PCI_DEVICE(0x4040, 0x0005)}, | ||
85 | {0,} | ||
86 | }; | ||
87 | |||
88 | MODULE_DEVICE_TABLE(pci, netxen_pci_tbl); | ||
89 | |||
90 | /* | ||
91 | * netxen_nic_probe() | ||
92 | * | ||
93 | * The Linux system will invoke this after identifying the vendor ID and | ||
94 | * device Id in the pci_tbl supported by this module. | ||
95 | * | ||
96 | * A quad port card has one operational PCI config space, (function 0), | ||
97 | * which is used to access all four ports. | ||
98 | * | ||
99 | * This routine will initialize the adapter, and setup the global parameters | ||
100 | * along with the port's specific structure. | ||
101 | */ | ||
102 | static int __devinit | ||
103 | netxen_nic_probe(struct pci_dev *pdev, const struct pci_device_id *ent) | ||
104 | { | ||
105 | struct net_device *netdev = NULL; | ||
106 | struct netxen_adapter *adapter = NULL; | ||
107 | struct netxen_port *port = NULL; | ||
108 | u8 *mem_ptr0 = NULL; | ||
109 | u8 *mem_ptr1 = NULL; | ||
110 | u8 *mem_ptr2 = NULL; | ||
111 | |||
112 | unsigned long mem_base, mem_len; | ||
113 | int pci_using_dac, i, err; | ||
114 | int ring; | ||
115 | struct netxen_recv_context *recv_ctx = NULL; | ||
116 | struct netxen_rcv_desc_ctx *rcv_desc = NULL; | ||
117 | struct netxen_cmd_buffer *cmd_buf_arr = NULL; | ||
118 | u64 mac_addr[FLASH_NUM_PORTS + 1]; | ||
119 | int valid_mac; | ||
120 | |||
121 | printk(KERN_INFO "%s \n", netxen_nic_driver_string); | ||
122 | if ((err = pci_enable_device(pdev))) | ||
123 | return err; | ||
124 | if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) { | ||
125 | err = -ENODEV; | ||
126 | goto err_out_disable_pdev; | ||
127 | } | ||
128 | |||
129 | if ((err = pci_request_regions(pdev, netxen_nic_driver_name))) | ||
130 | goto err_out_disable_pdev; | ||
131 | |||
132 | pci_set_master(pdev); | ||
133 | if ((pci_set_dma_mask(pdev, DMA_64BIT_MASK) == 0) && | ||
134 | (pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK) == 0)) | ||
135 | pci_using_dac = 1; | ||
136 | else { | ||
137 | if ((err = pci_set_dma_mask(pdev, DMA_32BIT_MASK)) || | ||
138 | (err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK))) | ||
139 | goto err_out_free_res; | ||
140 | |||
141 | pci_using_dac = 0; | ||
142 | } | ||
143 | |||
144 | /* remap phys address */ | ||
145 | mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */ | ||
146 | mem_len = pci_resource_len(pdev, 0); | ||
147 | |||
148 | /* 128 Meg of memory */ | ||
149 | mem_ptr0 = ioremap(mem_base, FIRST_PAGE_GROUP_SIZE); | ||
150 | mem_ptr1 = | ||
151 | ioremap(mem_base + SECOND_PAGE_GROUP_START, SECOND_PAGE_GROUP_SIZE); | ||
152 | mem_ptr2 = | ||
153 | ioremap(mem_base + THIRD_PAGE_GROUP_START, THIRD_PAGE_GROUP_SIZE); | ||
154 | |||
155 | if ((mem_ptr0 == 0UL) || (mem_ptr1 == 0UL) || (mem_ptr2 == 0UL)) { | ||
156 | DPRINTK(1, ERR, | ||
157 | "Cannot remap adapter memory aborting.:" | ||
158 | "0 -> %p, 1 -> %p, 2 -> %p\n", | ||
159 | mem_ptr0, mem_ptr1, mem_ptr2); | ||
160 | |||
161 | err = -EIO; | ||
162 | if (mem_ptr0) | ||
163 | iounmap(mem_ptr0); | ||
164 | if (mem_ptr1) | ||
165 | iounmap(mem_ptr1); | ||
166 | if (mem_ptr2) | ||
167 | iounmap(mem_ptr2); | ||
168 | |||
169 | goto err_out_free_res; | ||
170 | } | ||
171 | |||
172 | /* | ||
173 | * Allocate a adapter structure which will manage all the initialization | ||
174 | * as well as the common resources for all ports... | ||
175 | * all the ports will have pointer to this adapter as well as Adapter | ||
176 | * will have pointers of all the ports structures. | ||
177 | */ | ||
178 | |||
179 | /* One adapter structure for all 4 ports.... */ | ||
180 | adapter = kzalloc(sizeof(struct netxen_adapter), GFP_KERNEL); | ||
181 | if (adapter == NULL) { | ||
182 | printk(KERN_ERR "%s: Could not allocate adapter memory:%d\n", | ||
183 | netxen_nic_driver_name, | ||
184 | (int)sizeof(struct netxen_adapter)); | ||
185 | err = -ENOMEM; | ||
186 | goto err_out_iounmap; | ||
187 | } | ||
188 | |||
189 | adapter->max_tx_desc_count = MAX_CMD_DESCRIPTORS; | ||
190 | adapter->max_rx_desc_count = MAX_RCV_DESCRIPTORS; | ||
191 | adapter->max_jumbo_rx_desc_count = MAX_JUMBO_RCV_DESCRIPTORS; | ||
192 | |||
193 | pci_set_drvdata(pdev, adapter); | ||
194 | |||
195 | cmd_buf_arr = (struct netxen_cmd_buffer *)vmalloc(TX_RINGSIZE); | ||
196 | if (cmd_buf_arr == NULL) { | ||
197 | err = -ENOMEM; | ||
198 | goto err_out_free_adapter; | ||
199 | } | ||
200 | memset(cmd_buf_arr, 0, TX_RINGSIZE); | ||
201 | |||
202 | for (i = 0; i < MAX_RCV_CTX; ++i) { | ||
203 | recv_ctx = &adapter->recv_ctx[i]; | ||
204 | for (ring = 0; ring < NUM_RCV_DESC_RINGS; ring++) { | ||
205 | rcv_desc = &recv_ctx->rcv_desc[ring]; | ||
206 | switch (RCV_DESC_TYPE(ring)) { | ||
207 | case RCV_DESC_NORMAL: | ||
208 | rcv_desc->max_rx_desc_count = | ||
209 | adapter->max_rx_desc_count; | ||
210 | rcv_desc->flags = RCV_DESC_NORMAL; | ||
211 | rcv_desc->dma_size = RX_DMA_MAP_LEN; | ||
212 | rcv_desc->skb_size = MAX_RX_BUFFER_LENGTH; | ||
213 | break; | ||
214 | |||
215 | case RCV_DESC_JUMBO: | ||
216 | rcv_desc->max_rx_desc_count = | ||
217 | adapter->max_jumbo_rx_desc_count; | ||
218 | rcv_desc->flags = RCV_DESC_JUMBO; | ||
219 | rcv_desc->dma_size = RX_JUMBO_DMA_MAP_LEN; | ||
220 | rcv_desc->skb_size = MAX_RX_JUMBO_BUFFER_LENGTH; | ||
221 | break; | ||
222 | |||
223 | } | ||
224 | rcv_desc->rx_buf_arr = (struct netxen_rx_buffer *) | ||
225 | vmalloc(RCV_BUFFSIZE); | ||
226 | |||
227 | if (rcv_desc->rx_buf_arr == NULL) { | ||
228 | err = -ENOMEM; | ||
229 | goto err_out_free_rx_buffer; | ||
230 | } | ||
231 | memset(rcv_desc->rx_buf_arr, 0, RCV_BUFFSIZE); | ||
232 | } | ||
233 | |||
234 | } | ||
235 | |||
236 | adapter->ops = kzalloc(sizeof(struct netxen_drvops), GFP_KERNEL); | ||
237 | if (adapter->ops == NULL) { | ||
238 | printk(KERN_ERR | ||
239 | "%s: Could not allocate memory for adapter->ops:%d\n", | ||
240 | netxen_nic_driver_name, | ||
241 | (int)sizeof(struct netxen_adapter)); | ||
242 | err = -ENOMEM; | ||
243 | goto err_out_free_rx_buffer; | ||
244 | } | ||
245 | |||
246 | adapter->cmd_buf_arr = cmd_buf_arr; | ||
247 | adapter->ahw.pci_base0 = mem_ptr0; | ||
248 | adapter->ahw.pci_base1 = mem_ptr1; | ||
249 | adapter->ahw.pci_base2 = mem_ptr2; | ||
250 | spin_lock_init(&adapter->tx_lock); | ||
251 | spin_lock_init(&adapter->lock); | ||
252 | #ifdef CONFIG_IA64 | ||
253 | netxen_pinit_from_rom(adapter, 0); | ||
254 | udelay(500); | ||
255 | netxen_load_firmware(adapter); | ||
256 | #endif | ||
257 | |||
258 | /* initialize the buffers in adapter */ | ||
259 | netxen_initialize_adapter_sw(adapter); | ||
260 | /* | ||
261 | * Set the CRB window to invalid. If any register in window 0 is | ||
262 | * accessed it should set the window to 0 and then reset it to 1. | ||
263 | */ | ||
264 | adapter->curr_window = 255; | ||
265 | /* | ||
266 | * Adapter in our case is quad port so initialize it before | ||
267 | * initializing the ports | ||
268 | */ | ||
269 | netxen_initialize_adapter_hw(adapter); /* initialize the adapter */ | ||
270 | |||
271 | netxen_initialize_adapter_ops(adapter); | ||
272 | |||
273 | init_timer(&adapter->watchdog_timer); | ||
274 | adapter->ahw.xg_linkup = 0; | ||
275 | adapter->watchdog_timer.function = &netxen_watchdog; | ||
276 | adapter->watchdog_timer.data = (unsigned long)adapter; | ||
277 | INIT_WORK(&adapter->watchdog_task, | ||
278 | (void (*)(void *))netxen_watchdog_task, adapter); | ||
279 | adapter->ahw.pdev = pdev; | ||
280 | adapter->proc_cmd_buf_counter = 0; | ||
281 | pci_read_config_byte(pdev, PCI_REVISION_ID, &adapter->ahw.revision_id); | ||
282 | |||
283 | if (pci_enable_msi(pdev)) { | ||
284 | adapter->flags &= ~NETXEN_NIC_MSI_ENABLED; | ||
285 | printk(KERN_WARNING "%s: unable to allocate MSI interrupt" | ||
286 | " error\n", netxen_nic_driver_name); | ||
287 | } else | ||
288 | adapter->flags |= NETXEN_NIC_MSI_ENABLED; | ||
289 | |||
290 | if (netxen_is_flash_supported(adapter) == 0 && | ||
291 | netxen_get_flash_mac_addr(adapter, mac_addr) == 0) | ||
292 | valid_mac = 1; | ||
293 | else | ||
294 | valid_mac = 0; | ||
295 | |||
296 | /* | ||
297 | * Initialize all the CRB registers here. | ||
298 | */ | ||
299 | writel(0, NETXEN_CRB_NORMALIZE(adapter, CRB_CMD_PRODUCER_OFFSET)); | ||
300 | writel(0, NETXEN_CRB_NORMALIZE(adapter, CRB_CMD_CONSUMER_OFFSET)); | ||
301 | writel(0, NETXEN_CRB_NORMALIZE(adapter, CRB_HOST_CMD_ADDR_LO)); | ||
302 | |||
303 | /* Unlock the HW, prompting the boot sequence */ | ||
304 | writel(1, | ||
305 | NETXEN_CRB_NORMALIZE(adapter, NETXEN_ROMUSB_GLB_PEGTUNE_DONE)); | ||
306 | |||
307 | /* Handshake with the card before we register the devices. */ | ||
308 | netxen_phantom_init(adapter, NETXEN_NIC_PEG_TUNE); | ||
309 | |||
310 | /* initialize the all the ports */ | ||
311 | |||
312 | for (i = 0; i < adapter->ahw.max_ports; i++) { | ||
313 | netdev = alloc_etherdev(sizeof(struct netxen_port)); | ||
314 | if (!netdev) { | ||
315 | printk(KERN_ERR "%s: could not allocate netdev for port" | ||
316 | " %d\n", netxen_nic_driver_name, i + 1); | ||
317 | goto err_out_free_dev; | ||
318 | } | ||
319 | |||
320 | SET_MODULE_OWNER(netdev); | ||
321 | SET_NETDEV_DEV(netdev, &pdev->dev); | ||
322 | |||
323 | port = netdev_priv(netdev); | ||
324 | port->netdev = netdev; | ||
325 | port->pdev = pdev; | ||
326 | port->adapter = adapter; | ||
327 | port->portnum = i; /* Gigabit port number from 0-3 */ | ||
328 | |||
329 | netdev->open = netxen_nic_open; | ||
330 | netdev->stop = netxen_nic_close; | ||
331 | netdev->hard_start_xmit = netxen_nic_xmit_frame; | ||
332 | netdev->get_stats = netxen_nic_get_stats; | ||
333 | netdev->set_multicast_list = netxen_nic_set_multi; | ||
334 | netdev->set_mac_address = netxen_nic_set_mac; | ||
335 | netdev->change_mtu = netxen_nic_change_mtu; | ||
336 | netdev->do_ioctl = netxen_nic_ioctl; | ||
337 | netdev->tx_timeout = netxen_tx_timeout; | ||
338 | netdev->watchdog_timeo = HZ; | ||
339 | |||
340 | SET_ETHTOOL_OPS(netdev, &netxen_nic_ethtool_ops); | ||
341 | netdev->poll = netxen_nic_poll; | ||
342 | netdev->weight = NETXEN_NETDEV_WEIGHT; | ||
343 | #ifdef CONFIG_NET_POLL_CONTROLLER | ||
344 | netdev->poll_controller = netxen_nic_poll_controller; | ||
345 | #endif | ||
346 | /* ScatterGather support */ | ||
347 | netdev->features = NETIF_F_SG; | ||
348 | netdev->features |= NETIF_F_IP_CSUM; | ||
349 | netdev->features |= NETIF_F_TSO; | ||
350 | |||
351 | if (pci_using_dac) | ||
352 | netdev->features |= NETIF_F_HIGHDMA; | ||
353 | |||
354 | if (valid_mac) { | ||
355 | unsigned char *p = (unsigned char *)&mac_addr[i]; | ||
356 | netdev->dev_addr[0] = *(p + 5); | ||
357 | netdev->dev_addr[1] = *(p + 4); | ||
358 | netdev->dev_addr[2] = *(p + 3); | ||
359 | netdev->dev_addr[3] = *(p + 2); | ||
360 | netdev->dev_addr[4] = *(p + 1); | ||
361 | netdev->dev_addr[5] = *(p + 0); | ||
362 | |||
363 | memcpy(netdev->perm_addr, netdev->dev_addr, | ||
364 | netdev->addr_len); | ||
365 | if (!is_valid_ether_addr(netdev->perm_addr)) { | ||
366 | printk(KERN_ERR "%s: Bad MAC address " | ||
367 | "%02x:%02x:%02x:%02x:%02x:%02x.\n", | ||
368 | netxen_nic_driver_name, | ||
369 | netdev->dev_addr[0], | ||
370 | netdev->dev_addr[1], | ||
371 | netdev->dev_addr[2], | ||
372 | netdev->dev_addr[3], | ||
373 | netdev->dev_addr[4], | ||
374 | netdev->dev_addr[5]); | ||
375 | } else { | ||
376 | if (adapter->ops->macaddr_set) | ||
377 | adapter->ops->macaddr_set(port, | ||
378 | netdev-> | ||
379 | dev_addr); | ||
380 | } | ||
381 | } | ||
382 | INIT_WORK(&adapter->tx_timeout_task, | ||
383 | (void (*)(void *))netxen_tx_timeout_task, netdev); | ||
384 | netif_carrier_off(netdev); | ||
385 | netif_stop_queue(netdev); | ||
386 | |||
387 | if ((err = register_netdev(netdev))) { | ||
388 | printk(KERN_ERR "%s: register_netdev failed port #%d" | ||
389 | " aborting\n", netxen_nic_driver_name, i + 1); | ||
390 | err = -EIO; | ||
391 | free_netdev(netdev); | ||
392 | goto err_out_free_dev; | ||
393 | } | ||
394 | adapter->port_count++; | ||
395 | adapter->active_ports = 0; | ||
396 | adapter->port[i] = port; | ||
397 | } | ||
398 | |||
399 | /* | ||
400 | * delay a while to ensure that the Pegs are up & running. | ||
401 | * Otherwise, we might see some flaky behaviour. | ||
402 | */ | ||
403 | udelay(100); | ||
404 | |||
405 | switch (adapter->ahw.board_type) { | ||
406 | case NETXEN_NIC_GBE: | ||
407 | printk("%s: QUAD GbE board initialized\n", | ||
408 | netxen_nic_driver_name); | ||
409 | break; | ||
410 | |||
411 | case NETXEN_NIC_XGBE: | ||
412 | printk("%s: XGbE board initialized\n", netxen_nic_driver_name); | ||
413 | break; | ||
414 | } | ||
415 | |||
416 | adapter->driver_mismatch = 0; | ||
417 | |||
418 | return 0; | ||
419 | |||
420 | err_out_free_dev: | ||
421 | if (adapter->flags & NETXEN_NIC_MSI_ENABLED) | ||
422 | pci_disable_msi(pdev); | ||
423 | for (i = 0; i < adapter->port_count; i++) { | ||
424 | port = adapter->port[i]; | ||
425 | if ((port) && (port->netdev)) { | ||
426 | unregister_netdev(port->netdev); | ||
427 | free_netdev(port->netdev); | ||
428 | } | ||
429 | } | ||
430 | kfree(adapter->ops); | ||
431 | |||
432 | err_out_free_rx_buffer: | ||
433 | for (i = 0; i < MAX_RCV_CTX; ++i) { | ||
434 | recv_ctx = &adapter->recv_ctx[i]; | ||
435 | for (ring = 0; ring < NUM_RCV_DESC_RINGS; ring++) { | ||
436 | rcv_desc = &recv_ctx->rcv_desc[ring]; | ||
437 | if (rcv_desc->rx_buf_arr != NULL) { | ||
438 | vfree(rcv_desc->rx_buf_arr); | ||
439 | rcv_desc->rx_buf_arr = NULL; | ||
440 | } | ||
441 | } | ||
442 | } | ||
443 | |||
444 | vfree(cmd_buf_arr); | ||
445 | |||
446 | kfree(adapter->port); | ||
447 | |||
448 | err_out_free_adapter: | ||
449 | pci_set_drvdata(pdev, NULL); | ||
450 | kfree(adapter); | ||
451 | |||
452 | err_out_iounmap: | ||
453 | iounmap(mem_ptr0); | ||
454 | iounmap(mem_ptr1); | ||
455 | iounmap(mem_ptr2); | ||
456 | |||
457 | err_out_free_res: | ||
458 | pci_release_regions(pdev); | ||
459 | err_out_disable_pdev: | ||
460 | pci_disable_device(pdev); | ||
461 | return err; | ||
462 | } | ||
463 | |||
464 | static void __devexit netxen_nic_remove(struct pci_dev *pdev) | ||
465 | { | ||
466 | struct netxen_adapter *adapter; | ||
467 | struct netxen_port *port; | ||
468 | struct netxen_rx_buffer *buffer; | ||
469 | struct netxen_recv_context *recv_ctx; | ||
470 | struct netxen_rcv_desc_ctx *rcv_desc; | ||
471 | int i; | ||
472 | int ctxid, ring; | ||
473 | |||
474 | adapter = pci_get_drvdata(pdev); | ||
475 | if (adapter == NULL) | ||
476 | return; | ||
477 | |||
478 | netxen_nic_stop_all_ports(adapter); | ||
479 | /* leave the hw in the same state as reboot */ | ||
480 | netxen_pinit_from_rom(adapter, 0); | ||
481 | udelay(500); | ||
482 | netxen_load_firmware(adapter); | ||
483 | |||
484 | if ((adapter->flags & NETXEN_NIC_MSI_ENABLED)) | ||
485 | netxen_nic_disable_int(adapter); | ||
486 | |||
487 | udelay(500); /* Delay for a while to drain the DMA engines */ | ||
488 | for (i = 0; i < adapter->port_count; i++) { | ||
489 | port = adapter->port[i]; | ||
490 | if ((port) && (port->netdev)) { | ||
491 | unregister_netdev(port->netdev); | ||
492 | free_netdev(port->netdev); | ||
493 | } | ||
494 | } | ||
495 | |||
496 | if ((adapter->flags & NETXEN_NIC_MSI_ENABLED)) | ||
497 | pci_disable_msi(pdev); | ||
498 | pci_set_drvdata(pdev, NULL); | ||
499 | if (adapter->is_up == NETXEN_ADAPTER_UP_MAGIC) | ||
500 | netxen_free_hw_resources(adapter); | ||
501 | |||
502 | iounmap(adapter->ahw.pci_base0); | ||
503 | iounmap(adapter->ahw.pci_base1); | ||
504 | iounmap(adapter->ahw.pci_base2); | ||
505 | |||
506 | pci_release_regions(pdev); | ||
507 | pci_disable_device(pdev); | ||
508 | |||
509 | for (ctxid = 0; ctxid < MAX_RCV_CTX; ++ctxid) { | ||
510 | recv_ctx = &adapter->recv_ctx[ctxid]; | ||
511 | for (ring = 0; ring < NUM_RCV_DESC_RINGS; ring++) { | ||
512 | rcv_desc = &recv_ctx->rcv_desc[ring]; | ||
513 | for (i = 0; i < rcv_desc->max_rx_desc_count; ++i) { | ||
514 | buffer = &(rcv_desc->rx_buf_arr[i]); | ||
515 | if (buffer->state == NETXEN_BUFFER_FREE) | ||
516 | continue; | ||
517 | pci_unmap_single(pdev, buffer->dma, | ||
518 | rcv_desc->dma_size, | ||
519 | PCI_DMA_FROMDEVICE); | ||
520 | if (buffer->skb != NULL) | ||
521 | dev_kfree_skb_any(buffer->skb); | ||
522 | } | ||
523 | vfree(rcv_desc->rx_buf_arr); | ||
524 | } | ||
525 | } | ||
526 | |||
527 | vfree(adapter->cmd_buf_arr); | ||
528 | kfree(adapter->ops); | ||
529 | kfree(adapter); | ||
530 | } | ||
531 | |||
532 | /* | ||
533 | * Called when a network interface is made active | ||
534 | * @returns 0 on success, negative value on failure | ||
535 | */ | ||
536 | static int netxen_nic_open(struct net_device *netdev) | ||
537 | { | ||
538 | struct netxen_port *port = netdev_priv(netdev); | ||
539 | struct netxen_adapter *adapter = port->adapter; | ||
540 | int err = 0; | ||
541 | int ctx, ring; | ||
542 | |||
543 | if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC) { | ||
544 | err = netxen_init_firmware(adapter); | ||
545 | if (err != 0) { | ||
546 | printk(KERN_ERR "Failed to init firmware\n"); | ||
547 | return -EIO; | ||
548 | } | ||
549 | netxen_nic_flash_print(adapter); | ||
550 | |||
551 | /* setup all the resources for the Phantom... */ | ||
552 | /* this include the descriptors for rcv, tx, and status */ | ||
553 | netxen_nic_clear_stats(adapter); | ||
554 | err = netxen_nic_hw_resources(adapter); | ||
555 | if (err) { | ||
556 | printk(KERN_ERR "Error in setting hw resources:%d\n", | ||
557 | err); | ||
558 | return err; | ||
559 | } | ||
560 | if (adapter->ops->init_port | ||
561 | && adapter->ops->init_port(adapter, port->portnum) != 0) { | ||
562 | printk(KERN_ERR "%s: Failed to initialize port %d\n", | ||
563 | netxen_nic_driver_name, port->portnum); | ||
564 | netxen_free_hw_resources(adapter); | ||
565 | return -EIO; | ||
566 | } | ||
567 | if (adapter->ops->init_niu) | ||
568 | adapter->ops->init_niu(adapter); | ||
569 | for (ctx = 0; ctx < MAX_RCV_CTX; ++ctx) { | ||
570 | for (ring = 0; ring < NUM_RCV_DESC_RINGS; ring++) | ||
571 | netxen_post_rx_buffers(adapter, ctx, ring); | ||
572 | } | ||
573 | adapter->is_up = NETXEN_ADAPTER_UP_MAGIC; | ||
574 | } | ||
575 | adapter->active_ports++; | ||
576 | if (adapter->active_ports == 1) { | ||
577 | err = request_irq(adapter->ahw.pdev->irq, &netxen_intr, | ||
578 | SA_SHIRQ | SA_SAMPLE_RANDOM, netdev->name, | ||
579 | adapter); | ||
580 | if (err) { | ||
581 | printk(KERN_ERR "request_irq failed with: %d\n", err); | ||
582 | adapter->active_ports--; | ||
583 | return err; | ||
584 | } | ||
585 | adapter->irq = adapter->ahw.pdev->irq; | ||
586 | if (!adapter->driver_mismatch) | ||
587 | mod_timer(&adapter->watchdog_timer, jiffies); | ||
588 | |||
589 | netxen_nic_enable_int(adapter); | ||
590 | } | ||
591 | |||
592 | /* Done here again so that even if phantom sw overwrote it, | ||
593 | * we set it */ | ||
594 | if (adapter->ops->macaddr_set) | ||
595 | adapter->ops->macaddr_set(port, netdev->dev_addr); | ||
596 | netxen_nic_set_link_parameters(port); | ||
597 | |||
598 | netxen_nic_set_multi(netdev); | ||
599 | if (!adapter->driver_mismatch) | ||
600 | netif_start_queue(netdev); | ||
601 | |||
602 | return 0; | ||
603 | } | ||
604 | |||
605 | /* | ||
606 | * netxen_nic_close - Disables a network interface entry point | ||
607 | */ | ||
608 | static int netxen_nic_close(struct net_device *netdev) | ||
609 | { | ||
610 | struct netxen_port *port = netdev_priv(netdev); | ||
611 | struct netxen_adapter *adapter = port->adapter; | ||
612 | int i, j; | ||
613 | struct netxen_cmd_buffer *cmd_buff; | ||
614 | struct netxen_skb_frag *buffrag; | ||
615 | |||
616 | netif_carrier_off(netdev); | ||
617 | netif_stop_queue(netdev); | ||
618 | |||
619 | adapter->active_ports--; | ||
620 | |||
621 | if (!adapter->active_ports) { | ||
622 | netxen_nic_disable_int(adapter); | ||
623 | if (adapter->irq) | ||
624 | free_irq(adapter->irq, adapter); | ||
625 | cmd_buff = adapter->cmd_buf_arr; | ||
626 | for (i = 0; i < adapter->max_tx_desc_count; i++) { | ||
627 | buffrag = cmd_buff->frag_array; | ||
628 | if (buffrag->dma) { | ||
629 | pci_unmap_single(port->pdev, buffrag->dma, | ||
630 | buffrag->length, | ||
631 | PCI_DMA_TODEVICE); | ||
632 | buffrag->dma = (u64) NULL; | ||
633 | } | ||
634 | for (j = 0; j < cmd_buff->frag_count; j++) { | ||
635 | buffrag++; | ||
636 | if (buffrag->dma) { | ||
637 | pci_unmap_page(port->pdev, | ||
638 | buffrag->dma, | ||
639 | buffrag->length, | ||
640 | PCI_DMA_TODEVICE); | ||
641 | buffrag->dma = (u64) NULL; | ||
642 | } | ||
643 | } | ||
644 | /* Free the skb we received in netxen_nic_xmit_frame */ | ||
645 | if (cmd_buff->skb) { | ||
646 | dev_kfree_skb_any(cmd_buff->skb); | ||
647 | cmd_buff->skb = NULL; | ||
648 | } | ||
649 | cmd_buff++; | ||
650 | } | ||
651 | del_timer_sync(&adapter->watchdog_timer); | ||
652 | } | ||
653 | |||
654 | return 0; | ||
655 | } | ||
656 | |||
657 | static int netxen_nic_xmit_frame(struct sk_buff *skb, struct net_device *netdev) | ||
658 | { | ||
659 | struct netxen_port *port = netdev_priv(netdev); | ||
660 | struct netxen_adapter *adapter = port->adapter; | ||
661 | struct netxen_hardware_context *hw = &adapter->ahw; | ||
662 | unsigned int first_seg_len = skb->len - skb->data_len; | ||
663 | struct netxen_skb_frag *buffrag; | ||
664 | unsigned int i; | ||
665 | |||
666 | u32 producer = 0; | ||
667 | u32 saved_producer = 0; | ||
668 | struct cmd_desc_type0 *hwdesc; | ||
669 | int k; | ||
670 | struct netxen_cmd_buffer *pbuf = NULL; | ||
671 | unsigned int tries = 0; | ||
672 | static int dropped_packet = 0; | ||
673 | int frag_count; | ||
674 | u32 local_producer = 0; | ||
675 | u32 max_tx_desc_count = 0; | ||
676 | u32 last_cmd_consumer = 0; | ||
677 | int no_of_desc; | ||
678 | |||
679 | port->stats.xmitcalled++; | ||
680 | frag_count = skb_shinfo(skb)->nr_frags + 1; | ||
681 | |||
682 | if (unlikely(skb->len <= 0)) { | ||
683 | dev_kfree_skb_any(skb); | ||
684 | port->stats.badskblen++; | ||
685 | return NETDEV_TX_OK; | ||
686 | } | ||
687 | |||
688 | if (frag_count > MAX_BUFFERS_PER_CMD) { | ||
689 | printk("%s: %s netxen_nic_xmit_frame: frag_count (%d)" | ||
690 | "too large, can handle only %d frags\n", | ||
691 | netxen_nic_driver_name, netdev->name, | ||
692 | frag_count, MAX_BUFFERS_PER_CMD); | ||
693 | port->stats.txdropped++; | ||
694 | if ((++dropped_packet & 0xff) == 0xff) | ||
695 | printk("%s: %s droppped packets = %d\n", | ||
696 | netxen_nic_driver_name, netdev->name, | ||
697 | dropped_packet); | ||
698 | |||
699 | return NETDEV_TX_OK; | ||
700 | } | ||
701 | |||
702 | /* | ||
703 | * Everything is set up. Now, we just need to transmit it out. | ||
704 | * Note that we have to copy the contents of buffer over to | ||
705 | * right place. Later on, this can be optimized out by de-coupling the | ||
706 | * producer index from the buffer index. | ||
707 | */ | ||
708 | retry_getting_window: | ||
709 | spin_lock_bh(&adapter->tx_lock); | ||
710 | if (adapter->total_threads == MAX_XMIT_PRODUCERS) { | ||
711 | spin_unlock_bh(&adapter->tx_lock); | ||
712 | /* | ||
713 | * Yield CPU | ||
714 | */ | ||
715 | if (!in_atomic()) | ||
716 | schedule(); | ||
717 | else { | ||
718 | for (i = 0; i < 20; i++) | ||
719 | cpu_relax(); /*This a nop instr on i386 */ | ||
720 | } | ||
721 | goto retry_getting_window; | ||
722 | } | ||
723 | local_producer = adapter->cmd_producer; | ||
724 | /* There 4 fragments per descriptor */ | ||
725 | no_of_desc = (frag_count + 3) >> 2; | ||
726 | if (netdev->features & NETIF_F_TSO) { | ||
727 | if (skb_shinfo(skb)->gso_size > 0) { | ||
728 | |||
729 | no_of_desc++; | ||
730 | if (((skb->nh.iph)->ihl * sizeof(u32)) + | ||
731 | ((skb->h.th)->doff * sizeof(u32)) + | ||
732 | sizeof(struct ethhdr) > | ||
733 | (sizeof(struct cmd_desc_type0) - NET_IP_ALIGN)) { | ||
734 | no_of_desc++; | ||
735 | } | ||
736 | } | ||
737 | } | ||
738 | k = adapter->cmd_producer; | ||
739 | max_tx_desc_count = adapter->max_tx_desc_count; | ||
740 | last_cmd_consumer = adapter->last_cmd_consumer; | ||
741 | if ((k + no_of_desc) >= | ||
742 | ((last_cmd_consumer <= k) ? last_cmd_consumer + max_tx_desc_count : | ||
743 | last_cmd_consumer)) { | ||
744 | spin_unlock_bh(&adapter->tx_lock); | ||
745 | if (tries == 0) { | ||
746 | local_bh_disable(); | ||
747 | netxen_process_cmd_ring((unsigned long)adapter); | ||
748 | local_bh_enable(); | ||
749 | ++tries; | ||
750 | goto retry_getting_window; | ||
751 | } else { | ||
752 | port->stats.nocmddescriptor++; | ||
753 | DPRINTK(ERR, "No command descriptors available," | ||
754 | " producer = %d, consumer = %d count=%llu," | ||
755 | " dropping packet\n", producer, | ||
756 | adapter->last_cmd_consumer, | ||
757 | port->stats.nocmddescriptor); | ||
758 | |||
759 | spin_lock_bh(&adapter->tx_lock); | ||
760 | netif_stop_queue(netdev); | ||
761 | port->flags |= NETXEN_NETDEV_STATUS; | ||
762 | spin_unlock_bh(&adapter->tx_lock); | ||
763 | return NETDEV_TX_BUSY; | ||
764 | } | ||
765 | } | ||
766 | k = get_index_range(k, max_tx_desc_count, no_of_desc); | ||
767 | adapter->cmd_producer = k; | ||
768 | adapter->total_threads++; | ||
769 | adapter->num_threads++; | ||
770 | |||
771 | spin_unlock_bh(&adapter->tx_lock); | ||
772 | /* Copy the descriptors into the hardware */ | ||
773 | producer = local_producer; | ||
774 | saved_producer = producer; | ||
775 | hwdesc = &hw->cmd_desc_head[producer]; | ||
776 | memset(hwdesc, 0, sizeof(struct cmd_desc_type0)); | ||
777 | /* Take skb->data itself */ | ||
778 | pbuf = &adapter->cmd_buf_arr[producer]; | ||
779 | if ((netdev->features & NETIF_F_TSO) && skb_shinfo(skb)->gso_size > 0) { | ||
780 | pbuf->mss = skb_shinfo(skb)->gso_size; | ||
781 | hwdesc->mss = skb_shinfo(skb)->gso_size; | ||
782 | } else { | ||
783 | pbuf->mss = 0; | ||
784 | hwdesc->mss = 0; | ||
785 | } | ||
786 | pbuf->no_of_descriptors = no_of_desc; | ||
787 | pbuf->total_length = skb->len; | ||
788 | pbuf->skb = skb; | ||
789 | pbuf->cmd = TX_ETHER_PKT; | ||
790 | pbuf->frag_count = frag_count; | ||
791 | pbuf->port = port->portnum; | ||
792 | buffrag = &pbuf->frag_array[0]; | ||
793 | buffrag->dma = pci_map_single(port->pdev, skb->data, first_seg_len, | ||
794 | PCI_DMA_TODEVICE); | ||
795 | buffrag->length = first_seg_len; | ||
796 | CMD_DESC_TOTAL_LENGTH_WRT(hwdesc, skb->len); | ||
797 | hwdesc->num_of_buffers = frag_count; | ||
798 | hwdesc->opcode = TX_ETHER_PKT; | ||
799 | |||
800 | CMD_DESC_PORT_WRT(hwdesc, port->portnum); | ||
801 | hwdesc->buffer1_length = cpu_to_le16(first_seg_len); | ||
802 | hwdesc->addr_buffer1 = cpu_to_le64(buffrag->dma); | ||
803 | |||
804 | for (i = 1, k = 1; i < frag_count; i++, k++) { | ||
805 | struct skb_frag_struct *frag; | ||
806 | int len, temp_len; | ||
807 | unsigned long offset; | ||
808 | dma_addr_t temp_dma; | ||
809 | |||
810 | /* move to next desc. if there is a need */ | ||
811 | if ((i & 0x3) == 0) { | ||
812 | k = 0; | ||
813 | producer = get_next_index(producer, | ||
814 | adapter->max_tx_desc_count); | ||
815 | hwdesc = &hw->cmd_desc_head[producer]; | ||
816 | memset(hwdesc, 0, sizeof(struct cmd_desc_type0)); | ||
817 | } | ||
818 | frag = &skb_shinfo(skb)->frags[i - 1]; | ||
819 | len = frag->size; | ||
820 | offset = frag->page_offset; | ||
821 | |||
822 | temp_len = len; | ||
823 | temp_dma = pci_map_page(port->pdev, frag->page, offset, | ||
824 | len, PCI_DMA_TODEVICE); | ||
825 | |||
826 | buffrag++; | ||
827 | buffrag->dma = temp_dma; | ||
828 | buffrag->length = temp_len; | ||
829 | |||
830 | DPRINTK(INFO, "for loop. i=%d k=%d\n", i, k); | ||
831 | switch (k) { | ||
832 | case 0: | ||
833 | hwdesc->buffer1_length = cpu_to_le16(temp_len); | ||
834 | hwdesc->addr_buffer1 = cpu_to_le64(temp_dma); | ||
835 | break; | ||
836 | case 1: | ||
837 | hwdesc->buffer2_length = cpu_to_le16(temp_len); | ||
838 | hwdesc->addr_buffer2 = cpu_to_le64(temp_dma); | ||
839 | break; | ||
840 | case 2: | ||
841 | hwdesc->buffer3_length = cpu_to_le16(temp_len); | ||
842 | hwdesc->addr_buffer3 = cpu_to_le64(temp_dma); | ||
843 | break; | ||
844 | case 3: | ||
845 | hwdesc->buffer4_length = temp_len; | ||
846 | hwdesc->addr_buffer4 = cpu_to_le64(temp_dma); | ||
847 | break; | ||
848 | } | ||
849 | frag++; | ||
850 | } | ||
851 | producer = get_next_index(producer, adapter->max_tx_desc_count); | ||
852 | |||
853 | /* might change opcode to TX_TCP_LSO */ | ||
854 | netxen_tso_check(adapter, &hw->cmd_desc_head[saved_producer], skb); | ||
855 | |||
856 | /* For LSO, we need to copy the MAC/IP/TCP headers into | ||
857 | * the descriptor ring | ||
858 | */ | ||
859 | if (hw->cmd_desc_head[saved_producer].opcode == TX_TCP_LSO) { | ||
860 | int hdr_len, first_hdr_len, more_hdr; | ||
861 | hdr_len = hw->cmd_desc_head[saved_producer].total_hdr_length; | ||
862 | if (hdr_len > (sizeof(struct cmd_desc_type0) - NET_IP_ALIGN)) { | ||
863 | first_hdr_len = | ||
864 | sizeof(struct cmd_desc_type0) - NET_IP_ALIGN; | ||
865 | more_hdr = 1; | ||
866 | } else { | ||
867 | first_hdr_len = hdr_len; | ||
868 | more_hdr = 0; | ||
869 | } | ||
870 | /* copy the MAC/IP/TCP headers to the cmd descriptor list */ | ||
871 | hwdesc = &hw->cmd_desc_head[producer]; | ||
872 | |||
873 | /* copy the first 64 bytes */ | ||
874 | memcpy(((void *)hwdesc) + NET_IP_ALIGN, | ||
875 | (void *)(skb->data), first_hdr_len); | ||
876 | producer = get_next_index(producer, max_tx_desc_count); | ||
877 | |||
878 | if (more_hdr) { | ||
879 | hwdesc = &hw->cmd_desc_head[producer]; | ||
880 | /* copy the next 64 bytes - should be enough except | ||
881 | * for pathological case | ||
882 | */ | ||
883 | memcpy((void *)hwdesc, (void *)(skb->data) + | ||
884 | first_hdr_len, hdr_len - first_hdr_len); | ||
885 | producer = get_next_index(producer, max_tx_desc_count); | ||
886 | } | ||
887 | } | ||
888 | spin_lock_bh(&adapter->tx_lock); | ||
889 | port->stats.txbytes += | ||
890 | CMD_DESC_TOTAL_LENGTH(&hw->cmd_desc_head[saved_producer]); | ||
891 | /* Code to update the adapter considering how many producer threads | ||
892 | are currently working */ | ||
893 | if ((--adapter->num_threads) == 0) { | ||
894 | /* This is the last thread */ | ||
895 | u32 crb_producer = adapter->cmd_producer; | ||
896 | writel(crb_producer, | ||
897 | NETXEN_CRB_NORMALIZE(adapter, CRB_CMD_PRODUCER_OFFSET)); | ||
898 | wmb(); | ||
899 | adapter->total_threads = 0; | ||
900 | } else { | ||
901 | u32 crb_producer = 0; | ||
902 | crb_producer = | ||
903 | readl(NETXEN_CRB_NORMALIZE | ||
904 | (adapter, CRB_CMD_PRODUCER_OFFSET)); | ||
905 | if (crb_producer == local_producer) { | ||
906 | crb_producer = get_index_range(crb_producer, | ||
907 | max_tx_desc_count, | ||
908 | no_of_desc); | ||
909 | writel(crb_producer, | ||
910 | NETXEN_CRB_NORMALIZE(adapter, | ||
911 | CRB_CMD_PRODUCER_OFFSET)); | ||
912 | wmb(); | ||
913 | } | ||
914 | } | ||
915 | |||
916 | port->stats.xmitfinished++; | ||
917 | spin_unlock_bh(&adapter->tx_lock); | ||
918 | |||
919 | netdev->trans_start = jiffies; | ||
920 | |||
921 | DPRINTK(INFO, "wrote CMD producer %x to phantom\n", producer); | ||
922 | |||
923 | DPRINTK(INFO, "Done. Send\n"); | ||
924 | return NETDEV_TX_OK; | ||
925 | } | ||
926 | |||
927 | static void netxen_watchdog(unsigned long v) | ||
928 | { | ||
929 | struct netxen_adapter *adapter = (struct netxen_adapter *)v; | ||
930 | schedule_work(&adapter->watchdog_task); | ||
931 | } | ||
932 | |||
933 | static void netxen_tx_timeout(struct net_device *netdev) | ||
934 | { | ||
935 | struct netxen_port *port = (struct netxen_port *)netdev_priv(netdev); | ||
936 | struct netxen_adapter *adapter = port->adapter; | ||
937 | |||
938 | schedule_work(&adapter->tx_timeout_task); | ||
939 | } | ||
940 | |||
941 | static void netxen_tx_timeout_task(struct net_device *netdev) | ||
942 | { | ||
943 | struct netxen_port *port = (struct netxen_port *)netdev_priv(netdev); | ||
944 | unsigned long flags; | ||
945 | |||
946 | printk(KERN_ERR "%s %s: transmit timeout, resetting.\n", | ||
947 | netxen_nic_driver_name, netdev->name); | ||
948 | |||
949 | spin_lock_irqsave(&port->adapter->lock, flags); | ||
950 | netxen_nic_close(netdev); | ||
951 | netxen_nic_open(netdev); | ||
952 | spin_unlock_irqrestore(&port->adapter->lock, flags); | ||
953 | netdev->trans_start = jiffies; | ||
954 | netif_wake_queue(netdev); | ||
955 | } | ||
956 | |||
957 | static int | ||
958 | netxen_handle_int(struct netxen_adapter *adapter, struct net_device *netdev) | ||
959 | { | ||
960 | u32 ret = 0; | ||
961 | |||
962 | DPRINTK(INFO, "Entered handle ISR\n"); | ||
963 | |||
964 | adapter->stats.ints++; | ||
965 | |||
966 | if (!(adapter->flags & NETXEN_NIC_MSI_ENABLED)) { | ||
967 | int count = 0; | ||
968 | u32 mask; | ||
969 | netxen_nic_disable_int(adapter); | ||
970 | /* Window = 0 or 1 */ | ||
971 | do { | ||
972 | writel(0xffffffff, PCI_OFFSET_SECOND_RANGE(adapter, | ||
973 | ISR_INT_TARGET_STATUS)); | ||
974 | mask = readl(pci_base_offset(adapter, ISR_INT_VECTOR)); | ||
975 | } while (((mask & 0x80) != 0) && (++count < 32)); | ||
976 | if ((mask & 0x80) != 0) | ||
977 | printk("Could not disable interrupt completely\n"); | ||
978 | |||
979 | } | ||
980 | adapter->stats.hostints++; | ||
981 | |||
982 | if (netxen_nic_rx_has_work(adapter) || netxen_nic_tx_has_work(adapter)) { | ||
983 | if (netif_rx_schedule_prep(netdev)) { | ||
984 | /* | ||
985 | * Interrupts are already disabled. | ||
986 | */ | ||
987 | __netif_rx_schedule(netdev); | ||
988 | } else { | ||
989 | static unsigned int intcount = 0; | ||
990 | if ((++intcount & 0xfff) == 0xfff) | ||
991 | printk(KERN_ERR | ||
992 | "%s: %s interrupt %d while in poll\n", | ||
993 | netxen_nic_driver_name, netdev->name, | ||
994 | intcount); | ||
995 | } | ||
996 | ret = 1; | ||
997 | } | ||
998 | |||
999 | if (ret == 0) { | ||
1000 | netxen_nic_enable_int(adapter); | ||
1001 | } | ||
1002 | |||
1003 | return ret; | ||
1004 | } | ||
1005 | |||
1006 | /* | ||
1007 | * netxen_intr - Interrupt Handler | ||
1008 | * @irq: interrupt number | ||
1009 | * data points to adapter stucture (which may be handling more than 1 port | ||
1010 | */ | ||
1011 | irqreturn_t netxen_intr(int irq, void *data) | ||
1012 | { | ||
1013 | struct netxen_adapter *adapter; | ||
1014 | struct netxen_port *port; | ||
1015 | struct net_device *netdev; | ||
1016 | int i; | ||
1017 | |||
1018 | if (unlikely(!irq)) { | ||
1019 | return IRQ_NONE; /* Not our interrupt */ | ||
1020 | } | ||
1021 | |||
1022 | adapter = (struct netxen_adapter *)data; | ||
1023 | for (i = 0; i < adapter->ahw.max_ports; i++) { | ||
1024 | port = adapter->port[i]; | ||
1025 | netdev = port->netdev; | ||
1026 | |||
1027 | /* process our status queue (for all 4 ports) */ | ||
1028 | netxen_handle_int(adapter, netdev); | ||
1029 | } | ||
1030 | |||
1031 | return IRQ_HANDLED; | ||
1032 | } | ||
1033 | |||
1034 | static int netxen_nic_poll(struct net_device *netdev, int *budget) | ||
1035 | { | ||
1036 | struct netxen_port *port = (struct netxen_port *)netdev_priv(netdev); | ||
1037 | struct netxen_adapter *adapter = port->adapter; | ||
1038 | int work_to_do = min(*budget, netdev->quota); | ||
1039 | int done = 1; | ||
1040 | int ctx; | ||
1041 | int this_work_done; | ||
1042 | |||
1043 | DPRINTK(INFO, "polling for %d descriptors\n", *budget); | ||
1044 | port->stats.polled++; | ||
1045 | |||
1046 | adapter->work_done = 0; | ||
1047 | for (ctx = 0; ctx < MAX_RCV_CTX; ++ctx) { | ||
1048 | /* | ||
1049 | * Fairness issue. This will give undue weight to the | ||
1050 | * receive context 0. | ||
1051 | */ | ||
1052 | |||
1053 | /* | ||
1054 | * To avoid starvation, we give each of our receivers, | ||
1055 | * a fraction of the quota. Sometimes, it might happen that we | ||
1056 | * have enough quota to process every packet, but since all the | ||
1057 | * packets are on one context, it gets only half of the quota, | ||
1058 | * and ends up not processing it. | ||
1059 | */ | ||
1060 | this_work_done = netxen_process_rcv_ring(adapter, ctx, | ||
1061 | work_to_do / | ||
1062 | MAX_RCV_CTX); | ||
1063 | adapter->work_done += this_work_done; | ||
1064 | } | ||
1065 | |||
1066 | netdev->quota -= adapter->work_done; | ||
1067 | *budget -= adapter->work_done; | ||
1068 | |||
1069 | if (adapter->work_done >= work_to_do | ||
1070 | && netxen_nic_rx_has_work(adapter) != 0) | ||
1071 | done = 0; | ||
1072 | |||
1073 | netxen_process_cmd_ring((unsigned long)adapter); | ||
1074 | |||
1075 | DPRINTK(INFO, "new work_done: %d work_to_do: %d\n", | ||
1076 | adapter->work_done, work_to_do); | ||
1077 | if (done) { | ||
1078 | netif_rx_complete(netdev); | ||
1079 | netxen_nic_enable_int(adapter); | ||
1080 | } | ||
1081 | |||
1082 | return !done; | ||
1083 | } | ||
1084 | |||
1085 | #ifdef CONFIG_NET_POLL_CONTROLLER | ||
1086 | static void netxen_nic_poll_controller(struct net_device *netdev) | ||
1087 | { | ||
1088 | struct netxen_port *port = netdev_priv(netdev); | ||
1089 | struct netxen_adapter *adapter = port->adapter; | ||
1090 | disable_irq(adapter->irq); | ||
1091 | netxen_intr(adapter->irq, adapter); | ||
1092 | enable_irq(adapter->irq); | ||
1093 | } | ||
1094 | #endif | ||
1095 | /* | ||
1096 | * netxen_nic_ioctl () We provide the tcl/phanmon support through these | ||
1097 | * ioctls. | ||
1098 | */ | ||
1099 | static int | ||
1100 | netxen_nic_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) | ||
1101 | { | ||
1102 | int err = 0; | ||
1103 | unsigned long nr_bytes = 0; | ||
1104 | struct netxen_port *port = netdev_priv(netdev); | ||
1105 | struct netxen_adapter *adapter = port->adapter; | ||
1106 | char dev_name[NETXEN_NIC_NAME_LEN]; | ||
1107 | |||
1108 | DPRINTK(INFO, "doing ioctl for %s\n", netdev->name); | ||
1109 | switch (cmd) { | ||
1110 | case NETXEN_NIC_CMD: | ||
1111 | err = netxen_nic_do_ioctl(adapter, (void *)ifr->ifr_data, port); | ||
1112 | break; | ||
1113 | |||
1114 | case NETXEN_NIC_NAME: | ||
1115 | DPRINTK(INFO, "ioctl cmd for NetXen\n"); | ||
1116 | if (ifr->ifr_data) { | ||
1117 | sprintf(dev_name, "%s-%d", NETXEN_NIC_NAME_RSP, | ||
1118 | port->portnum); | ||
1119 | nr_bytes = copy_to_user((char *)ifr->ifr_data, dev_name, | ||
1120 | NETXEN_NIC_NAME_LEN); | ||
1121 | if (nr_bytes) | ||
1122 | err = -EIO; | ||
1123 | |||
1124 | } | ||
1125 | break; | ||
1126 | |||
1127 | default: | ||
1128 | DPRINTK(INFO, "ioctl cmd %x not supported\n", cmd); | ||
1129 | err = -EOPNOTSUPP; | ||
1130 | break; | ||
1131 | } | ||
1132 | |||
1133 | return err; | ||
1134 | } | ||
1135 | |||
1136 | static struct pci_driver netxen_driver = { | ||
1137 | .name = netxen_nic_driver_name, | ||
1138 | .id_table = netxen_pci_tbl, | ||
1139 | .probe = netxen_nic_probe, | ||
1140 | .remove = __devexit_p(netxen_nic_remove) | ||
1141 | }; | ||
1142 | |||
1143 | /* Driver Registration on NetXen card */ | ||
1144 | |||
1145 | static int __init netxen_init_module(void) | ||
1146 | { | ||
1147 | return pci_module_init(&netxen_driver); | ||
1148 | } | ||
1149 | |||
1150 | module_init(netxen_init_module); | ||
1151 | |||
1152 | static void __exit netxen_exit_module(void) | ||
1153 | { | ||
1154 | /* | ||
1155 | * Wait for some time to allow the dma to drain, if any. | ||
1156 | */ | ||
1157 | mdelay(5); | ||
1158 | pci_unregister_driver(&netxen_driver); | ||
1159 | } | ||
1160 | |||
1161 | module_exit(netxen_exit_module); | ||
diff --git a/drivers/net/netxen/netxen_nic_niu.c b/drivers/net/netxen/netxen_nic_niu.c new file mode 100644 index 000000000000..7950a04532e6 --- /dev/null +++ b/drivers/net/netxen/netxen_nic_niu.c | |||
@@ -0,0 +1,894 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2003 - 2006 NetXen, Inc. | ||
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 LICENSE. | ||
22 | * | ||
23 | * Contact Information: | ||
24 | * info@netxen.com | ||
25 | * NetXen, | ||
26 | * 3965 Freedom Circle, Fourth floor, | ||
27 | * Santa Clara, CA 95054 | ||
28 | * | ||
29 | * | ||
30 | * Provides access to the Network Interface Unit h/w block. | ||
31 | * | ||
32 | */ | ||
33 | |||
34 | #include "netxen_nic.h" | ||
35 | |||
36 | #define NETXEN_GB_MAC_SOFT_RESET 0x80000000 | ||
37 | #define NETXEN_GB_MAC_RESET_PROT_BLK 0x000F0000 | ||
38 | #define NETXEN_GB_MAC_ENABLE_TX_RX 0x00000005 | ||
39 | #define NETXEN_GB_MAC_PAUSED_FRMS 0x00000020 | ||
40 | |||
41 | static long phy_lock_timeout = 100000000; | ||
42 | |||
43 | static inline int phy_lock(void) | ||
44 | { | ||
45 | int i; | ||
46 | int done = 0, timeout = 0; | ||
47 | |||
48 | while (!done) { | ||
49 | done = readl((void __iomem *)NETXEN_PCIE_REG(PCIE_SEM3_LOCK)); | ||
50 | if (done == 1) | ||
51 | break; | ||
52 | if (timeout >= phy_lock_timeout) { | ||
53 | return -1; | ||
54 | } | ||
55 | timeout++; | ||
56 | if (!in_atomic()) | ||
57 | schedule(); | ||
58 | else { | ||
59 | for (i = 0; i < 20; i++) | ||
60 | cpu_relax(); | ||
61 | } | ||
62 | } | ||
63 | |||
64 | writel(NETXEN_PHY_LOCK_ID, (void __iomem *)PHY_LOCK_DRIVER); | ||
65 | return 0; | ||
66 | } | ||
67 | |||
68 | static inline int phy_unlock(void) | ||
69 | { | ||
70 | readl((void __iomem *)NETXEN_PCIE_REG(PCIE_SEM3_UNLOCK)); | ||
71 | return 0; | ||
72 | } | ||
73 | |||
74 | /* | ||
75 | * netxen_niu_gbe_phy_read - read a register from the GbE PHY via | ||
76 | * mii management interface. | ||
77 | * | ||
78 | * Note: The MII management interface goes through port 0. | ||
79 | * Individual phys are addressed as follows: | ||
80 | * @param phy [15:8] phy id | ||
81 | * @param reg [7:0] register number | ||
82 | * | ||
83 | * @returns 0 on success | ||
84 | * -1 on error | ||
85 | * | ||
86 | */ | ||
87 | int netxen_niu_gbe_phy_read(struct netxen_adapter *adapter, long phy, | ||
88 | long reg, __le32 * readval) | ||
89 | { | ||
90 | long timeout = 0; | ||
91 | long result = 0; | ||
92 | long restore = 0; | ||
93 | __le32 address; | ||
94 | __le32 command; | ||
95 | __le32 status; | ||
96 | __le32 mac_cfg0; | ||
97 | |||
98 | if (phy_lock() != 0) { | ||
99 | return -1; | ||
100 | } | ||
101 | |||
102 | /* | ||
103 | * MII mgmt all goes through port 0 MAC interface, | ||
104 | * so it cannot be in reset | ||
105 | */ | ||
106 | |||
107 | if (netxen_nic_hw_read_wx(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(0), | ||
108 | &mac_cfg0, 4)) | ||
109 | return -EIO; | ||
110 | if (netxen_gb_get_soft_reset(mac_cfg0)) { | ||
111 | __le32 temp; | ||
112 | temp = 0; | ||
113 | netxen_gb_tx_reset_pb(temp); | ||
114 | netxen_gb_rx_reset_pb(temp); | ||
115 | netxen_gb_tx_reset_mac(temp); | ||
116 | netxen_gb_rx_reset_mac(temp); | ||
117 | if (netxen_nic_hw_write_wx(adapter, | ||
118 | NETXEN_NIU_GB_MAC_CONFIG_0(0), | ||
119 | &temp, 4)) | ||
120 | return -EIO; | ||
121 | restore = 1; | ||
122 | } | ||
123 | |||
124 | address = 0; | ||
125 | netxen_gb_mii_mgmt_reg_addr(address, reg); | ||
126 | netxen_gb_mii_mgmt_phy_addr(address, phy); | ||
127 | if (netxen_nic_hw_write_wx(adapter, NETXEN_NIU_GB_MII_MGMT_ADDR(0), | ||
128 | &address, 4)) | ||
129 | return -EIO; | ||
130 | command = 0; /* turn off any prior activity */ | ||
131 | if (netxen_nic_hw_write_wx(adapter, NETXEN_NIU_GB_MII_MGMT_COMMAND(0), | ||
132 | &command, 4)) | ||
133 | return -EIO; | ||
134 | /* send read command */ | ||
135 | netxen_gb_mii_mgmt_set_read_cycle(command); | ||
136 | if (netxen_nic_hw_write_wx(adapter, NETXEN_NIU_GB_MII_MGMT_COMMAND(0), | ||
137 | &command, 4)) | ||
138 | return -EIO; | ||
139 | |||
140 | status = 0; | ||
141 | do { | ||
142 | if (netxen_nic_hw_read_wx(adapter, | ||
143 | NETXEN_NIU_GB_MII_MGMT_INDICATE(0), | ||
144 | &status, 4)) | ||
145 | return -EIO; | ||
146 | timeout++; | ||
147 | } while ((netxen_get_gb_mii_mgmt_busy(status) | ||
148 | || netxen_get_gb_mii_mgmt_notvalid(status)) | ||
149 | && (timeout++ < NETXEN_NIU_PHY_WAITMAX)); | ||
150 | |||
151 | if (timeout < NETXEN_NIU_PHY_WAITMAX) { | ||
152 | if (netxen_nic_hw_read_wx(adapter, | ||
153 | NETXEN_NIU_GB_MII_MGMT_STATUS(0), | ||
154 | readval, 4)) | ||
155 | return -EIO; | ||
156 | result = 0; | ||
157 | } else | ||
158 | result = -1; | ||
159 | |||
160 | if (restore) | ||
161 | if (netxen_nic_hw_write_wx(adapter, | ||
162 | NETXEN_NIU_GB_MAC_CONFIG_0(0), | ||
163 | &mac_cfg0, 4)) | ||
164 | return -EIO; | ||
165 | phy_unlock(); | ||
166 | return result; | ||
167 | } | ||
168 | |||
169 | /* | ||
170 | * netxen_niu_gbe_phy_write - write a register to the GbE PHY via | ||
171 | * mii management interface. | ||
172 | * | ||
173 | * Note: The MII management interface goes through port 0. | ||
174 | * Individual phys are addressed as follows: | ||
175 | * @param phy [15:8] phy id | ||
176 | * @param reg [7:0] register number | ||
177 | * | ||
178 | * @returns 0 on success | ||
179 | * -1 on error | ||
180 | * | ||
181 | */ | ||
182 | int netxen_niu_gbe_phy_write(struct netxen_adapter *adapter, | ||
183 | long phy, long reg, __le32 val) | ||
184 | { | ||
185 | long timeout = 0; | ||
186 | long result = 0; | ||
187 | long restore = 0; | ||
188 | __le32 address; | ||
189 | __le32 command; | ||
190 | __le32 status; | ||
191 | __le32 mac_cfg0; | ||
192 | |||
193 | /* | ||
194 | * MII mgmt all goes through port 0 MAC interface, so it | ||
195 | * cannot be in reset | ||
196 | */ | ||
197 | |||
198 | if (netxen_nic_hw_read_wx(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(0), | ||
199 | &mac_cfg0, 4)) | ||
200 | return -EIO; | ||
201 | if (netxen_gb_get_soft_reset(mac_cfg0)) { | ||
202 | __le32 temp; | ||
203 | temp = 0; | ||
204 | netxen_gb_tx_reset_pb(temp); | ||
205 | netxen_gb_rx_reset_pb(temp); | ||
206 | netxen_gb_tx_reset_mac(temp); | ||
207 | netxen_gb_rx_reset_mac(temp); | ||
208 | |||
209 | if (netxen_nic_hw_write_wx(adapter, | ||
210 | NETXEN_NIU_GB_MAC_CONFIG_0(0), | ||
211 | &temp, 4)) | ||
212 | return -EIO; | ||
213 | restore = 1; | ||
214 | } | ||
215 | |||
216 | command = 0; /* turn off any prior activity */ | ||
217 | if (netxen_nic_hw_write_wx(adapter, NETXEN_NIU_GB_MII_MGMT_COMMAND(0), | ||
218 | &command, 4)) | ||
219 | return -EIO; | ||
220 | |||
221 | address = 0; | ||
222 | netxen_gb_mii_mgmt_reg_addr(address, reg); | ||
223 | netxen_gb_mii_mgmt_phy_addr(address, phy); | ||
224 | if (netxen_nic_hw_write_wx(adapter, NETXEN_NIU_GB_MII_MGMT_ADDR(0), | ||
225 | &address, 4)) | ||
226 | return -EIO; | ||
227 | |||
228 | if (netxen_nic_hw_write_wx(adapter, NETXEN_NIU_GB_MII_MGMT_CTRL(0), | ||
229 | &val, 4)) | ||
230 | return -EIO; | ||
231 | |||
232 | status = 0; | ||
233 | do { | ||
234 | if (netxen_nic_hw_read_wx(adapter, | ||
235 | NETXEN_NIU_GB_MII_MGMT_INDICATE(0), | ||
236 | &status, 4)) | ||
237 | return -EIO; | ||
238 | timeout++; | ||
239 | } while ((netxen_get_gb_mii_mgmt_busy(status)) | ||
240 | && (timeout++ < NETXEN_NIU_PHY_WAITMAX)); | ||
241 | |||
242 | if (timeout < NETXEN_NIU_PHY_WAITMAX) | ||
243 | result = 0; | ||
244 | else | ||
245 | result = -EIO; | ||
246 | |||
247 | /* restore the state of port 0 MAC in case we tampered with it */ | ||
248 | if (restore) | ||
249 | if (netxen_nic_hw_write_wx(adapter, | ||
250 | NETXEN_NIU_GB_MAC_CONFIG_0(0), | ||
251 | &mac_cfg0, 4)) | ||
252 | return -EIO; | ||
253 | |||
254 | return result; | ||
255 | } | ||
256 | |||
257 | int netxen_niu_xgbe_enable_phy_interrupts(struct netxen_adapter *adapter, | ||
258 | int port) | ||
259 | { | ||
260 | netxen_crb_writelit_adapter(adapter, NETXEN_NIU_INT_MASK, 0x3f); | ||
261 | return 0; | ||
262 | } | ||
263 | |||
264 | int netxen_niu_gbe_enable_phy_interrupts(struct netxen_adapter *adapter, | ||
265 | int port) | ||
266 | { | ||
267 | int result = 0; | ||
268 | __le32 enable = 0; | ||
269 | netxen_set_phy_int_link_status_changed(enable); | ||
270 | netxen_set_phy_int_autoneg_completed(enable); | ||
271 | netxen_set_phy_int_speed_changed(enable); | ||
272 | |||
273 | if (0 != | ||
274 | netxen_niu_gbe_phy_write(adapter, port, | ||
275 | NETXEN_NIU_GB_MII_MGMT_ADDR_INT_ENABLE, | ||
276 | enable)) | ||
277 | result = -EIO; | ||
278 | |||
279 | return result; | ||
280 | } | ||
281 | |||
282 | int netxen_niu_xgbe_disable_phy_interrupts(struct netxen_adapter *adapter, | ||
283 | int port) | ||
284 | { | ||
285 | netxen_crb_writelit_adapter(adapter, NETXEN_NIU_INT_MASK, 0x7f); | ||
286 | return 0; | ||
287 | } | ||
288 | |||
289 | int netxen_niu_gbe_disable_phy_interrupts(struct netxen_adapter *adapter, | ||
290 | int port) | ||
291 | { | ||
292 | int result = 0; | ||
293 | if (0 != | ||
294 | netxen_niu_gbe_phy_write(adapter, port, | ||
295 | NETXEN_NIU_GB_MII_MGMT_ADDR_INT_ENABLE, 0)) | ||
296 | result = -EIO; | ||
297 | |||
298 | return result; | ||
299 | } | ||
300 | |||
301 | int netxen_niu_xgbe_clear_phy_interrupts(struct netxen_adapter *adapter, | ||
302 | int port) | ||
303 | { | ||
304 | netxen_crb_writelit_adapter(adapter, NETXEN_NIU_ACTIVE_INT, -1); | ||
305 | return 0; | ||
306 | } | ||
307 | |||
308 | int netxen_niu_gbe_clear_phy_interrupts(struct netxen_adapter *adapter, | ||
309 | int port) | ||
310 | { | ||
311 | int result = 0; | ||
312 | if (0 != | ||
313 | netxen_niu_gbe_phy_write(adapter, port, | ||
314 | NETXEN_NIU_GB_MII_MGMT_ADDR_INT_STATUS, | ||
315 | -EIO)) | ||
316 | result = -EIO; | ||
317 | |||
318 | return result; | ||
319 | } | ||
320 | |||
321 | /* | ||
322 | * netxen_niu_gbe_set_mii_mode- Set 10/100 Mbit Mode for GbE MAC | ||
323 | * | ||
324 | */ | ||
325 | void netxen_niu_gbe_set_mii_mode(struct netxen_adapter *adapter, | ||
326 | int port, long enable) | ||
327 | { | ||
328 | netxen_crb_writelit_adapter(adapter, NETXEN_NIU_MODE, 0x2); | ||
329 | netxen_crb_writelit_adapter(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(port), | ||
330 | 0x80000000); | ||
331 | netxen_crb_writelit_adapter(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(port), | ||
332 | 0x0000f0025); | ||
333 | netxen_crb_writelit_adapter(adapter, NETXEN_NIU_GB_MAC_CONFIG_1(port), | ||
334 | 0xf1ff); | ||
335 | netxen_crb_writelit_adapter(adapter, | ||
336 | NETXEN_NIU_GB0_GMII_MODE + (port << 3), 0); | ||
337 | netxen_crb_writelit_adapter(adapter, | ||
338 | NETXEN_NIU_GB0_MII_MODE + (port << 3), 1); | ||
339 | netxen_crb_writelit_adapter(adapter, | ||
340 | (NETXEN_NIU_GB0_HALF_DUPLEX + port * 4), 0); | ||
341 | netxen_crb_writelit_adapter(adapter, | ||
342 | NETXEN_NIU_GB_MII_MGMT_CONFIG(port), 0x7); | ||
343 | |||
344 | if (enable) { | ||
345 | /* | ||
346 | * Do NOT enable flow control until a suitable solution for | ||
347 | * shutting down pause frames is found. | ||
348 | */ | ||
349 | netxen_crb_writelit_adapter(adapter, | ||
350 | NETXEN_NIU_GB_MAC_CONFIG_0(port), | ||
351 | 0x5); | ||
352 | } | ||
353 | |||
354 | if (netxen_niu_gbe_enable_phy_interrupts(adapter, port)) | ||
355 | printk(KERN_ERR PFX "ERROR enabling PHY interrupts\n"); | ||
356 | if (netxen_niu_gbe_clear_phy_interrupts(adapter, port)) | ||
357 | printk(KERN_ERR PFX "ERROR clearing PHY interrupts\n"); | ||
358 | } | ||
359 | |||
360 | /* | ||
361 | * netxen_niu_gbe_set_gmii_mode- Set GbE Mode for GbE MAC | ||
362 | */ | ||
363 | void netxen_niu_gbe_set_gmii_mode(struct netxen_adapter *adapter, | ||
364 | int port, long enable) | ||
365 | { | ||
366 | netxen_crb_writelit_adapter(adapter, NETXEN_NIU_MODE, 0x2); | ||
367 | netxen_crb_writelit_adapter(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(port), | ||
368 | 0x80000000); | ||
369 | netxen_crb_writelit_adapter(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(port), | ||
370 | 0x0000f0025); | ||
371 | netxen_crb_writelit_adapter(adapter, NETXEN_NIU_GB_MAC_CONFIG_1(port), | ||
372 | 0xf2ff); | ||
373 | netxen_crb_writelit_adapter(adapter, | ||
374 | NETXEN_NIU_GB0_MII_MODE + (port << 3), 0); | ||
375 | netxen_crb_writelit_adapter(adapter, | ||
376 | NETXEN_NIU_GB0_GMII_MODE + (port << 3), 1); | ||
377 | netxen_crb_writelit_adapter(adapter, | ||
378 | (NETXEN_NIU_GB0_HALF_DUPLEX + port * 4), 0); | ||
379 | netxen_crb_writelit_adapter(adapter, | ||
380 | NETXEN_NIU_GB_MII_MGMT_CONFIG(port), 0x7); | ||
381 | |||
382 | if (enable) { | ||
383 | /* | ||
384 | * Do NOT enable flow control until a suitable solution for | ||
385 | * shutting down pause frames is found. | ||
386 | */ | ||
387 | netxen_crb_writelit_adapter(adapter, | ||
388 | NETXEN_NIU_GB_MAC_CONFIG_0(port), | ||
389 | 0x5); | ||
390 | } | ||
391 | |||
392 | if (netxen_niu_gbe_enable_phy_interrupts(adapter, port)) | ||
393 | printk(KERN_ERR PFX "ERROR enabling PHY interrupts\n"); | ||
394 | if (netxen_niu_gbe_clear_phy_interrupts(adapter, port)) | ||
395 | printk(KERN_ERR PFX "ERROR clearing PHY interrupts\n"); | ||
396 | } | ||
397 | |||
398 | int netxen_niu_gbe_init_port(struct netxen_adapter *adapter, int port) | ||
399 | { | ||
400 | int result = 0; | ||
401 | __le32 status; | ||
402 | if (adapter->ops->disable_phy_interrupts) | ||
403 | adapter->ops->disable_phy_interrupts(adapter, port); | ||
404 | mdelay(2); | ||
405 | |||
406 | if (0 == | ||
407 | netxen_niu_gbe_phy_read(adapter, port, | ||
408 | NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS, | ||
409 | (__le32 *) & status)) { | ||
410 | if (netxen_get_phy_link(status)) { | ||
411 | if (netxen_get_phy_speed(status) == 2) { | ||
412 | netxen_niu_gbe_set_gmii_mode(adapter, port, 1); | ||
413 | } else if ((netxen_get_phy_speed(status) == 1) | ||
414 | || (netxen_get_phy_speed(status) == 0)) { | ||
415 | netxen_niu_gbe_set_mii_mode(adapter, port, 1); | ||
416 | } else { | ||
417 | result = -1; | ||
418 | } | ||
419 | |||
420 | } else { | ||
421 | /* | ||
422 | * We don't have link. Cable must be unconnected. | ||
423 | * Enable phy interrupts so we take action when | ||
424 | * plugged in. | ||
425 | */ | ||
426 | |||
427 | netxen_crb_writelit_adapter(adapter, | ||
428 | NETXEN_NIU_GB_MAC_CONFIG_0 | ||
429 | (port), | ||
430 | NETXEN_GB_MAC_SOFT_RESET); | ||
431 | netxen_crb_writelit_adapter(adapter, | ||
432 | NETXEN_NIU_GB_MAC_CONFIG_0 | ||
433 | (port), | ||
434 | NETXEN_GB_MAC_RESET_PROT_BLK | ||
435 | | NETXEN_GB_MAC_ENABLE_TX_RX | ||
436 | | | ||
437 | NETXEN_GB_MAC_PAUSED_FRMS); | ||
438 | if (netxen_niu_gbe_clear_phy_interrupts(adapter, port)) | ||
439 | printk(KERN_ERR PFX | ||
440 | "ERROR clearing PHY interrupts\n"); | ||
441 | if (netxen_niu_gbe_enable_phy_interrupts(adapter, port)) | ||
442 | printk(KERN_ERR PFX | ||
443 | "ERROR enabling PHY interrupts\n"); | ||
444 | if (netxen_niu_gbe_clear_phy_interrupts(adapter, port)) | ||
445 | printk(KERN_ERR PFX | ||
446 | "ERROR clearing PHY interrupts\n"); | ||
447 | result = -1; | ||
448 | } | ||
449 | } else { | ||
450 | result = -EIO; | ||
451 | } | ||
452 | return result; | ||
453 | } | ||
454 | |||
455 | int netxen_niu_xg_init_port(struct netxen_adapter *adapter, int port) | ||
456 | { | ||
457 | long reg = 0, ret = 0; | ||
458 | |||
459 | if (adapter->ahw.boardcfg.board_type == NETXEN_BRDTYPE_P2_SB31_10G_IMEZ) { | ||
460 | netxen_crb_writelit_adapter(adapter, | ||
461 | NETXEN_NIU_XG1_CONFIG_0, 0x5); | ||
462 | /* XXX hack for Mez cards: both ports in promisc mode */ | ||
463 | netxen_nic_hw_read_wx(adapter, | ||
464 | NETXEN_NIU_XGE_CONFIG_1, ®, 4); | ||
465 | reg = (reg | 0x2000UL); | ||
466 | netxen_crb_writelit_adapter(adapter, | ||
467 | NETXEN_NIU_XGE_CONFIG_1, reg); | ||
468 | reg = 0; | ||
469 | netxen_nic_hw_read_wx(adapter, | ||
470 | NETXEN_NIU_XG1_CONFIG_1, ®, 4); | ||
471 | reg = (reg | 0x2000UL); | ||
472 | netxen_crb_writelit_adapter(adapter, | ||
473 | NETXEN_NIU_XG1_CONFIG_1, reg); | ||
474 | } | ||
475 | |||
476 | return ret; | ||
477 | } | ||
478 | |||
479 | /* | ||
480 | * netxen_niu_gbe_handle_phy_interrupt - Handles GbE PHY interrupts | ||
481 | * @param enable 0 means don't enable the port | ||
482 | * 1 means enable (or re-enable) the port | ||
483 | */ | ||
484 | int netxen_niu_gbe_handle_phy_interrupt(struct netxen_adapter *adapter, | ||
485 | int port, long enable) | ||
486 | { | ||
487 | int result = 0; | ||
488 | __le32 int_src; | ||
489 | |||
490 | printk(KERN_INFO PFX "NETXEN: Handling PHY interrupt on port %d" | ||
491 | " (device enable = %d)\n", (int)port, (int)enable); | ||
492 | |||
493 | /* | ||
494 | * The read of the PHY INT status will clear the pending | ||
495 | * interrupt status | ||
496 | */ | ||
497 | if (netxen_niu_gbe_phy_read(adapter, port, | ||
498 | NETXEN_NIU_GB_MII_MGMT_ADDR_INT_STATUS, | ||
499 | &int_src) != 0) | ||
500 | result = -EINVAL; | ||
501 | else { | ||
502 | printk(KERN_INFO PFX "PHY Interrupt source = 0x%x \n", int_src); | ||
503 | if (netxen_get_phy_int_jabber(int_src)) | ||
504 | printk(KERN_INFO PFX "jabber Interrupt "); | ||
505 | if (netxen_get_phy_int_polarity_changed(int_src)) | ||
506 | printk(KERN_INFO PFX "polarity changed "); | ||
507 | if (netxen_get_phy_int_energy_detect(int_src)) | ||
508 | printk(KERN_INFO PFX "energy detect \n"); | ||
509 | if (netxen_get_phy_int_downshift(int_src)) | ||
510 | printk(KERN_INFO PFX "downshift \n"); | ||
511 | if (netxen_get_phy_int_mdi_xover_changed(int_src)) | ||
512 | printk(KERN_INFO PFX "mdi_xover_changed "); | ||
513 | if (netxen_get_phy_int_fifo_over_underflow(int_src)) | ||
514 | printk(KERN_INFO PFX "fifo_over_underflow "); | ||
515 | if (netxen_get_phy_int_false_carrier(int_src)) | ||
516 | printk(KERN_INFO PFX "false_carrier "); | ||
517 | if (netxen_get_phy_int_symbol_error(int_src)) | ||
518 | printk(KERN_INFO PFX "symbol_error "); | ||
519 | if (netxen_get_phy_int_autoneg_completed(int_src)) | ||
520 | printk(KERN_INFO PFX "autoneg_completed "); | ||
521 | if (netxen_get_phy_int_page_received(int_src)) | ||
522 | printk(KERN_INFO PFX "page_received "); | ||
523 | if (netxen_get_phy_int_duplex_changed(int_src)) | ||
524 | printk(KERN_INFO PFX "duplex_changed "); | ||
525 | if (netxen_get_phy_int_autoneg_error(int_src)) | ||
526 | printk(KERN_INFO PFX "autoneg_error "); | ||
527 | if ((netxen_get_phy_int_speed_changed(int_src)) | ||
528 | || (netxen_get_phy_int_link_status_changed(int_src))) { | ||
529 | __le32 status; | ||
530 | |||
531 | printk(KERN_INFO PFX | ||
532 | "speed_changed or link status changed"); | ||
533 | if (netxen_niu_gbe_phy_read | ||
534 | (adapter, port, | ||
535 | NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS, | ||
536 | &status) == 0) { | ||
537 | if (netxen_get_phy_speed(status) == 2) { | ||
538 | printk | ||
539 | (KERN_INFO PFX "Link speed changed" | ||
540 | " to 1000 Mbps\n"); | ||
541 | netxen_niu_gbe_set_gmii_mode(adapter, | ||
542 | port, | ||
543 | enable); | ||
544 | } else if (netxen_get_phy_speed(status) == 1) { | ||
545 | printk | ||
546 | (KERN_INFO PFX "Link speed changed" | ||
547 | " to 100 Mbps\n"); | ||
548 | netxen_niu_gbe_set_mii_mode(adapter, | ||
549 | port, | ||
550 | enable); | ||
551 | } else if (netxen_get_phy_speed(status) == 0) { | ||
552 | printk | ||
553 | (KERN_INFO PFX "Link speed changed" | ||
554 | " to 10 Mbps\n"); | ||
555 | netxen_niu_gbe_set_mii_mode(adapter, | ||
556 | port, | ||
557 | enable); | ||
558 | } else { | ||
559 | printk(KERN_ERR PFX "ERROR reading" | ||
560 | "PHY status. Illegal speed.\n"); | ||
561 | result = -1; | ||
562 | } | ||
563 | } else { | ||
564 | printk(KERN_ERR PFX | ||
565 | "ERROR reading PHY status.\n"); | ||
566 | result = -1; | ||
567 | } | ||
568 | |||
569 | } | ||
570 | printk(KERN_INFO "\n"); | ||
571 | } | ||
572 | return result; | ||
573 | } | ||
574 | |||
575 | /* | ||
576 | * Return the current station MAC address. | ||
577 | * Note that the passed-in value must already be in network byte order. | ||
578 | */ | ||
579 | int netxen_niu_macaddr_get(struct netxen_adapter *adapter, | ||
580 | int phy, netxen_ethernet_macaddr_t * addr) | ||
581 | { | ||
582 | u64 result = 0; | ||
583 | __le32 stationhigh; | ||
584 | __le32 stationlow; | ||
585 | |||
586 | if (addr == NULL) | ||
587 | return -EINVAL; | ||
588 | if ((phy < 0) || (phy > 3)) | ||
589 | return -EINVAL; | ||
590 | |||
591 | if (netxen_nic_hw_read_wx(adapter, NETXEN_NIU_GB_STATION_ADDR_0(phy), | ||
592 | &stationhigh, 4)) | ||
593 | return -EIO; | ||
594 | if (netxen_nic_hw_read_wx(adapter, NETXEN_NIU_GB_STATION_ADDR_1(phy), | ||
595 | &stationlow, 4)) | ||
596 | return -EIO; | ||
597 | |||
598 | result = (u64) netxen_gb_get_stationaddress_low(stationlow); | ||
599 | result |= (u64) stationhigh << 16; | ||
600 | memcpy(*addr, &result, sizeof(netxen_ethernet_macaddr_t)); | ||
601 | |||
602 | return 0; | ||
603 | } | ||
604 | |||
605 | /* | ||
606 | * Set the station MAC address. | ||
607 | * Note that the passed-in value must already be in network byte order. | ||
608 | */ | ||
609 | int netxen_niu_macaddr_set(struct netxen_port *port, | ||
610 | netxen_ethernet_macaddr_t addr) | ||
611 | { | ||
612 | __le32 temp = 0; | ||
613 | struct netxen_adapter *adapter = port->adapter; | ||
614 | int phy = port->portnum; | ||
615 | unsigned char mac_addr[MAX_ADDR_LEN]; | ||
616 | int i; | ||
617 | |||
618 | for (i = 0; i < 10; i++) { | ||
619 | memcpy(&temp, addr, 2); | ||
620 | temp <<= 16; | ||
621 | if (netxen_nic_hw_write_wx | ||
622 | (adapter, NETXEN_NIU_GB_STATION_ADDR_1(phy), &temp, 4)) | ||
623 | return -EIO; | ||
624 | |||
625 | temp = 0; | ||
626 | |||
627 | memcpy(&temp, ((u8 *) addr) + 2, sizeof(__le32)); | ||
628 | if (netxen_nic_hw_write_wx | ||
629 | (adapter, NETXEN_NIU_GB_STATION_ADDR_0(phy), &temp, 4)) | ||
630 | return -2; | ||
631 | |||
632 | netxen_niu_macaddr_get(adapter, phy, | ||
633 | (netxen_ethernet_macaddr_t *) mac_addr); | ||
634 | if (memcmp(mac_addr, addr, MAX_ADDR_LEN == 0)) | ||
635 | break; | ||
636 | } | ||
637 | |||
638 | if (i == 10) { | ||
639 | printk(KERN_ERR "%s: cannot set Mac addr for %s\n", | ||
640 | netxen_nic_driver_name, port->netdev->name); | ||
641 | printk(KERN_ERR "MAC address set: " | ||
642 | "%02x:%02x:%02x:%02x:%02x:%02x.\n", | ||
643 | addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]); | ||
644 | |||
645 | printk(KERN_ERR "MAC address get: " | ||
646 | "%02x:%02x:%02x:%02x:%02x:%02x.\n", | ||
647 | mac_addr[0], | ||
648 | mac_addr[1], | ||
649 | mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]); | ||
650 | } | ||
651 | return 0; | ||
652 | } | ||
653 | |||
654 | /* Enable a GbE interface */ | ||
655 | int netxen_niu_enable_gbe_port(struct netxen_adapter *adapter, | ||
656 | int port, netxen_niu_gbe_ifmode_t mode) | ||
657 | { | ||
658 | __le32 mac_cfg0; | ||
659 | __le32 mac_cfg1; | ||
660 | __le32 mii_cfg; | ||
661 | |||
662 | if ((port < 0) || (port > NETXEN_NIU_MAX_GBE_PORTS)) | ||
663 | return -EINVAL; | ||
664 | |||
665 | mac_cfg0 = 0; | ||
666 | netxen_gb_soft_reset(mac_cfg0); | ||
667 | if (netxen_nic_hw_write_wx(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(port), | ||
668 | &mac_cfg0, 4)) | ||
669 | return -EIO; | ||
670 | mac_cfg0 = 0; | ||
671 | netxen_gb_enable_tx(mac_cfg0); | ||
672 | netxen_gb_enable_rx(mac_cfg0); | ||
673 | netxen_gb_unset_rx_flowctl(mac_cfg0); | ||
674 | netxen_gb_tx_reset_pb(mac_cfg0); | ||
675 | netxen_gb_rx_reset_pb(mac_cfg0); | ||
676 | netxen_gb_tx_reset_mac(mac_cfg0); | ||
677 | netxen_gb_rx_reset_mac(mac_cfg0); | ||
678 | |||
679 | if (netxen_nic_hw_write_wx(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(port), | ||
680 | &mac_cfg0, 4)) | ||
681 | return -EIO; | ||
682 | mac_cfg1 = 0; | ||
683 | netxen_gb_set_preamblelen(mac_cfg1, 0xf); | ||
684 | netxen_gb_set_duplex(mac_cfg1); | ||
685 | netxen_gb_set_crc_enable(mac_cfg1); | ||
686 | netxen_gb_set_padshort(mac_cfg1); | ||
687 | netxen_gb_set_checklength(mac_cfg1); | ||
688 | netxen_gb_set_hugeframes(mac_cfg1); | ||
689 | |||
690 | if (mode == NETXEN_NIU_10_100_MB) { | ||
691 | netxen_gb_set_intfmode(mac_cfg1, 1); | ||
692 | if (netxen_nic_hw_write_wx(adapter, | ||
693 | NETXEN_NIU_GB_MAC_CONFIG_1(port), | ||
694 | &mac_cfg1, 4)) | ||
695 | return -EIO; | ||
696 | |||
697 | /* set mii mode */ | ||
698 | netxen_crb_writelit_adapter(adapter, NETXEN_NIU_GB0_GMII_MODE + | ||
699 | (port << 3), 0); | ||
700 | netxen_crb_writelit_adapter(adapter, NETXEN_NIU_GB0_MII_MODE + | ||
701 | (port << 3), 1); | ||
702 | |||
703 | } else if (mode == NETXEN_NIU_1000_MB) { | ||
704 | netxen_gb_set_intfmode(mac_cfg1, 2); | ||
705 | if (netxen_nic_hw_write_wx(adapter, | ||
706 | NETXEN_NIU_GB_MAC_CONFIG_1(port), | ||
707 | &mac_cfg1, 4)) | ||
708 | return -EIO; | ||
709 | /* set gmii mode */ | ||
710 | netxen_crb_writelit_adapter(adapter, NETXEN_NIU_GB0_MII_MODE + | ||
711 | (port << 3), 0); | ||
712 | netxen_crb_writelit_adapter(adapter, NETXEN_NIU_GB0_GMII_MODE + | ||
713 | (port << 3), 1); | ||
714 | } | ||
715 | mii_cfg = 0; | ||
716 | netxen_gb_set_mii_mgmt_clockselect(mii_cfg, 7); | ||
717 | if (netxen_nic_hw_write_wx(adapter, NETXEN_NIU_GB_MII_MGMT_CONFIG(port), | ||
718 | &mii_cfg, 4)) | ||
719 | return -EIO; | ||
720 | mac_cfg0 = 0; | ||
721 | netxen_gb_enable_tx(mac_cfg0); | ||
722 | netxen_gb_enable_rx(mac_cfg0); | ||
723 | netxen_gb_unset_rx_flowctl(mac_cfg0); | ||
724 | netxen_gb_unset_tx_flowctl(mac_cfg0); | ||
725 | |||
726 | if (netxen_nic_hw_write_wx(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(port), | ||
727 | &mac_cfg0, 4)) | ||
728 | return -EIO; | ||
729 | return 0; | ||
730 | } | ||
731 | |||
732 | /* Disable a GbE interface */ | ||
733 | int netxen_niu_disable_gbe_port(struct netxen_adapter *adapter, int port) | ||
734 | { | ||
735 | __le32 mac_cfg0; | ||
736 | |||
737 | if ((port < 0) || (port > NETXEN_NIU_MAX_GBE_PORTS)) | ||
738 | return -EINVAL; | ||
739 | |||
740 | mac_cfg0 = 0; | ||
741 | netxen_gb_soft_reset(mac_cfg0); | ||
742 | if (netxen_nic_hw_write_wx(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(port), | ||
743 | &mac_cfg0, 4)) | ||
744 | return -EIO; | ||
745 | return 0; | ||
746 | } | ||
747 | |||
748 | /* Disable an XG interface */ | ||
749 | int netxen_niu_disable_xg_port(struct netxen_adapter *adapter, int port) | ||
750 | { | ||
751 | __le32 mac_cfg; | ||
752 | |||
753 | if (port != 0) | ||
754 | return -EINVAL; | ||
755 | |||
756 | mac_cfg = 0; | ||
757 | netxen_xg_soft_reset(mac_cfg); | ||
758 | if (netxen_nic_hw_write_wx(adapter, NETXEN_NIU_XGE_CONFIG_0, | ||
759 | &mac_cfg, 4)) | ||
760 | return -EIO; | ||
761 | return 0; | ||
762 | } | ||
763 | |||
764 | /* Set promiscuous mode for a GbE interface */ | ||
765 | int netxen_niu_set_promiscuous_mode(struct netxen_adapter *adapter, int port, | ||
766 | netxen_niu_prom_mode_t mode) | ||
767 | { | ||
768 | __le32 reg; | ||
769 | |||
770 | if ((port < 0) || (port > NETXEN_NIU_MAX_GBE_PORTS)) | ||
771 | return -EINVAL; | ||
772 | |||
773 | /* save previous contents */ | ||
774 | if (netxen_nic_hw_read_wx(adapter, NETXEN_NIU_GB_DROP_WRONGADDR, | ||
775 | ®, 4)) | ||
776 | return -EIO; | ||
777 | if (mode == NETXEN_NIU_PROMISC_MODE) { | ||
778 | switch (port) { | ||
779 | case 0: | ||
780 | netxen_clear_gb_drop_gb0(reg); | ||
781 | break; | ||
782 | case 1: | ||
783 | netxen_clear_gb_drop_gb1(reg); | ||
784 | break; | ||
785 | case 2: | ||
786 | netxen_clear_gb_drop_gb2(reg); | ||
787 | break; | ||
788 | case 3: | ||
789 | netxen_clear_gb_drop_gb3(reg); | ||
790 | break; | ||
791 | default: | ||
792 | return -EIO; | ||
793 | } | ||
794 | } else { | ||
795 | switch (port) { | ||
796 | case 0: | ||
797 | netxen_set_gb_drop_gb0(reg); | ||
798 | break; | ||
799 | case 1: | ||
800 | netxen_set_gb_drop_gb1(reg); | ||
801 | break; | ||
802 | case 2: | ||
803 | netxen_set_gb_drop_gb2(reg); | ||
804 | break; | ||
805 | case 3: | ||
806 | netxen_set_gb_drop_gb3(reg); | ||
807 | break; | ||
808 | default: | ||
809 | return -EIO; | ||
810 | } | ||
811 | } | ||
812 | if (netxen_nic_hw_write_wx(adapter, NETXEN_NIU_GB_DROP_WRONGADDR, | ||
813 | ®, 4)) | ||
814 | return -EIO; | ||
815 | return 0; | ||
816 | } | ||
817 | |||
818 | /* | ||
819 | * Set the MAC address for an XG port | ||
820 | * Note that the passed-in value must already be in network byte order. | ||
821 | */ | ||
822 | int netxen_niu_xg_macaddr_set(struct netxen_port *port, | ||
823 | netxen_ethernet_macaddr_t addr) | ||
824 | { | ||
825 | __le32 temp = 0; | ||
826 | struct netxen_adapter *adapter = port->adapter; | ||
827 | |||
828 | memcpy(&temp, addr, 2); | ||
829 | temp = cpu_to_le32(temp); | ||
830 | temp <<= 16; | ||
831 | if (netxen_nic_hw_write_wx(adapter, NETXEN_NIU_XGE_STATION_ADDR_0_1, | ||
832 | &temp, 4)) | ||
833 | return -EIO; | ||
834 | |||
835 | temp = 0; | ||
836 | |||
837 | memcpy(&temp, ((u8 *) addr) + 2, sizeof(__le32)); | ||
838 | temp = cpu_to_le32(temp); | ||
839 | if (netxen_nic_hw_write_wx(adapter, NETXEN_NIU_XGE_STATION_ADDR_0_HI, | ||
840 | &temp, 4)) | ||
841 | return -EIO; | ||
842 | |||
843 | return 0; | ||
844 | } | ||
845 | |||
846 | /* | ||
847 | * Return the current station MAC address. | ||
848 | * Note that the passed-in value must already be in network byte order. | ||
849 | */ | ||
850 | int netxen_niu_xg_macaddr_get(struct netxen_adapter *adapter, int phy, | ||
851 | netxen_ethernet_macaddr_t * addr) | ||
852 | { | ||
853 | __le32 stationhigh; | ||
854 | __le32 stationlow; | ||
855 | u64 result; | ||
856 | |||
857 | if (addr == NULL) | ||
858 | return -EINVAL; | ||
859 | if (phy != 0) | ||
860 | return -EINVAL; | ||
861 | |||
862 | if (netxen_nic_hw_read_wx(adapter, NETXEN_NIU_XGE_STATION_ADDR_0_HI, | ||
863 | &stationhigh, 4)) | ||
864 | return -EIO; | ||
865 | if (netxen_nic_hw_read_wx(adapter, NETXEN_NIU_XGE_STATION_ADDR_0_1, | ||
866 | &stationlow, 4)) | ||
867 | return -EIO; | ||
868 | |||
869 | result = ((u64) stationlow) >> 16; | ||
870 | result |= (u64) stationhigh << 16; | ||
871 | memcpy(*addr, &result, sizeof(netxen_ethernet_macaddr_t)); | ||
872 | |||
873 | return 0; | ||
874 | } | ||
875 | |||
876 | int netxen_niu_xg_set_promiscuous_mode(struct netxen_adapter *adapter, | ||
877 | int port, netxen_niu_prom_mode_t mode) | ||
878 | { | ||
879 | __le32 reg; | ||
880 | |||
881 | if ((port < 0) || (port > NETXEN_NIU_MAX_GBE_PORTS)) | ||
882 | return -EINVAL; | ||
883 | |||
884 | if (netxen_nic_hw_read_wx(adapter, NETXEN_NIU_XGE_CONFIG_1, ®, 4)) | ||
885 | return -EIO; | ||
886 | if (mode == NETXEN_NIU_PROMISC_MODE) | ||
887 | reg = (reg | 0x2000UL); | ||
888 | else | ||
889 | reg = (reg & ~0x2000UL); | ||
890 | |||
891 | netxen_crb_writelit_adapter(adapter, NETXEN_NIU_XGE_CONFIG_1, reg); | ||
892 | |||
893 | return 0; | ||
894 | } | ||
diff --git a/drivers/net/netxen/netxen_nic_phan_reg.h b/drivers/net/netxen/netxen_nic_phan_reg.h new file mode 100644 index 000000000000..8181d436783f --- /dev/null +++ b/drivers/net/netxen/netxen_nic_phan_reg.h | |||
@@ -0,0 +1,215 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2003 - 2006 NetXen, Inc. | ||
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 LICENSE. | ||
22 | * | ||
23 | * Contact Information: | ||
24 | * info@netxen.com | ||
25 | * NetXen, | ||
26 | * 3965 Freedom Circle, Fourth floor, | ||
27 | * Santa Clara, CA 95054 | ||
28 | */ | ||
29 | |||
30 | #ifndef __NIC_PHAN_REG_H_ | ||
31 | #define __NIC_PHAN_REG_H_ | ||
32 | |||
33 | /* | ||
34 | * CRB Registers or queue message done only at initialization time. | ||
35 | */ | ||
36 | |||
37 | /* | ||
38 | * The following 2 are the base adresses for the CRB registers and their | ||
39 | * offsets will be added to get addresses for the index addresses. | ||
40 | */ | ||
41 | #define NIC_CRB_BASE_PORT1 NETXEN_CAM_RAM(0x200) | ||
42 | #define NIC_CRB_BASE_PORT2 NETXEN_CAM_RAM(0x250) | ||
43 | |||
44 | #define NETXEN_NIC_REG(X) (NIC_CRB_BASE_PORT1+(X)) | ||
45 | |||
46 | /* | ||
47 | * CrbPortPhanCntrHi/Lo is used to pass the address of HostPhantomIndex address | ||
48 | * which can be read by the Phantom host to get producer/consumer indexes from | ||
49 | * Phantom/Casper. If it is not HOST_SHARED_MEMORY, then the following | ||
50 | * registers will be used for the addresses of the ring's shared memory | ||
51 | * on the Phantom. | ||
52 | */ | ||
53 | |||
54 | #define CRB_PHAN_CNTRL_LO_OFFSET NETXEN_NIC_REG(0x00) | ||
55 | #define CRB_PHAN_CNTRL_HI_OFFSET NETXEN_NIC_REG(0x04) | ||
56 | |||
57 | /* point to the indexes */ | ||
58 | #define CRB_CMD_PRODUCER_OFFSET NETXEN_NIC_REG(0x08) | ||
59 | #define CRB_CMD_CONSUMER_OFFSET NETXEN_NIC_REG(0x0c) | ||
60 | |||
61 | #define CRB_PAUSE_ADDR_LO NETXEN_NIC_REG(0x10) | ||
62 | #define CRB_PAUSE_ADDR_HI NETXEN_NIC_REG(0x14) | ||
63 | |||
64 | /* address of command descriptors in the host memory */ | ||
65 | #define CRB_HOST_CMD_ADDR_HI NETXEN_NIC_REG(0x30) | ||
66 | #define CRB_HOST_CMD_ADDR_LO NETXEN_NIC_REG(0x34) | ||
67 | |||
68 | /* The following 4 CRB registers are for doing performance coal */ | ||
69 | #define CRB_CMD_INTR_LOOP NETXEN_NIC_REG(0x38) | ||
70 | #define CRB_CMD_DMA_LOOP NETXEN_NIC_REG(0x3c) | ||
71 | #define CRB_RCV_INTR_LOOP NETXEN_NIC_REG(0x40) | ||
72 | #define CRB_RCV_DMA_LOOP NETXEN_NIC_REG(0x44) | ||
73 | |||
74 | /* Needed by the host to find out the state of Phantom's initialization */ | ||
75 | #define CRB_ENABLE_TX_INTR NETXEN_NIC_REG(0x4c) | ||
76 | #define CRB_CMDPEG_STATE NETXEN_NIC_REG(0x50) | ||
77 | #define CRB_CMDPEG_CMDRING NETXEN_NIC_REG(0x54) | ||
78 | |||
79 | /* Interrupt coalescing parameters */ | ||
80 | #define CRB_GLOBAL_INT_COAL NETXEN_NIC_REG(0x80) | ||
81 | #define CRB_INT_COAL_MODE NETXEN_NIC_REG(0x84) | ||
82 | #define CRB_MAX_RCV_BUFS NETXEN_NIC_REG(0x88) | ||
83 | #define CRB_TX_INT_THRESHOLD NETXEN_NIC_REG(0x8c) | ||
84 | #define CRB_RX_PKT_TIMER NETXEN_NIC_REG(0x90) | ||
85 | #define CRB_TX_PKT_TIMER NETXEN_NIC_REG(0x94) | ||
86 | #define CRB_RX_PKT_CNT NETXEN_NIC_REG(0x98) | ||
87 | #define CRB_RX_TMR_CNT NETXEN_NIC_REG(0x9c) | ||
88 | #define CRB_INT_THRESH NETXEN_NIC_REG(0xa4) | ||
89 | |||
90 | /* Register for communicating XG link status */ | ||
91 | #define CRB_XG_STATE NETXEN_NIC_REG(0xa0) | ||
92 | |||
93 | /* Register for communicating card temperature */ | ||
94 | /* Upper 16 bits are temperature value. Lower 16 bits are the state */ | ||
95 | #define CRB_TEMP_STATE NETXEN_NIC_REG(0xa8) | ||
96 | #define nx_get_temp_val(x) ((x) >> 16) | ||
97 | #define nx_get_temp_state(x) ((x) & 0xffff) | ||
98 | #define nx_encode_temp(val, state) (((val) << 16) | (state)) | ||
99 | |||
100 | /* Debug registers for controlling NIC pkt gen agent */ | ||
101 | #define CRB_AGENT_GO NETXEN_NIC_REG(0xb0) | ||
102 | #define CRB_AGENT_TX_SIZE NETXEN_NIC_REG(0xb4) | ||
103 | #define CRB_AGENT_TX_TYPE NETXEN_NIC_REG(0xb8) | ||
104 | #define CRB_AGENT_TX_ADDR NETXEN_NIC_REG(0xbc) | ||
105 | #define CRB_AGENT_TX_MSS NETXEN_NIC_REG(0xc0) | ||
106 | |||
107 | /* Debug registers for observing NIC performance */ | ||
108 | #define CRB_TX_STATE NETXEN_NIC_REG(0xd0) | ||
109 | #define CRB_TX_COUNT NETXEN_NIC_REG(0xd4) | ||
110 | #define CRB_RX_STATE NETXEN_NIC_REG(0xd8) | ||
111 | |||
112 | /* CRB registers per Rcv Descriptor ring */ | ||
113 | struct netxen_rcv_desc_crb { | ||
114 | u32 crb_rcv_producer_offset __attribute__ ((aligned(512))); | ||
115 | u32 crb_rcv_consumer_offset; | ||
116 | u32 crb_globalrcv_ring; | ||
117 | }; | ||
118 | |||
119 | /* | ||
120 | * CRB registers used by the receive peg logic. One instance of these | ||
121 | * needs to be instantiated per instance of the receive peg. | ||
122 | */ | ||
123 | |||
124 | struct netxen_recv_crb { | ||
125 | struct netxen_rcv_desc_crb rcv_desc_crb[NUM_RCV_DESC_RINGS]; | ||
126 | u32 crb_rcvstatus_ring; | ||
127 | u32 crb_rcv_status_producer; | ||
128 | u32 crb_rcv_status_consumer; | ||
129 | u32 crb_rcvpeg_state; | ||
130 | }; | ||
131 | |||
132 | #if defined(DEFINE_GLOBAL_RECV_CRB) | ||
133 | struct netxen_recv_crb recv_crb_registers[] = { | ||
134 | /* | ||
135 | * Instance 0. | ||
136 | */ | ||
137 | { | ||
138 | /* rcv_desc_crb: */ | ||
139 | { | ||
140 | { | ||
141 | /* crb_rcv_producer_offset: */ | ||
142 | NETXEN_NIC_REG(0x18), | ||
143 | /* crb_rcv_consumer_offset: */ | ||
144 | NETXEN_NIC_REG(0x1c), | ||
145 | /* crb_gloablrcv_ring: */ | ||
146 | NETXEN_NIC_REG(0x20), | ||
147 | }, | ||
148 | /* Jumbo frames */ | ||
149 | { | ||
150 | /* crb_rcv_producer_offset: */ | ||
151 | NETXEN_NIC_REG(0x100), | ||
152 | /* crb_rcv_consumer_offset: */ | ||
153 | NETXEN_NIC_REG(0x104), | ||
154 | /* crb_gloablrcv_ring: */ | ||
155 | NETXEN_NIC_REG(0x108), | ||
156 | } | ||
157 | }, | ||
158 | /* crb_rcvstatus_ring: */ | ||
159 | NETXEN_NIC_REG(0x24), | ||
160 | /* crb_rcv_status_producer: */ | ||
161 | NETXEN_NIC_REG(0x28), | ||
162 | /* crb_rcv_status_consumer: */ | ||
163 | NETXEN_NIC_REG(0x2c), | ||
164 | /* crb_rcvpeg_state: */ | ||
165 | NETXEN_NIC_REG(0x48), | ||
166 | |||
167 | }, | ||
168 | /* | ||
169 | * Instance 1, | ||
170 | */ | ||
171 | { | ||
172 | /* rcv_desc_crb: */ | ||
173 | { | ||
174 | { | ||
175 | /* crb_rcv_producer_offset: */ | ||
176 | NETXEN_NIC_REG(0x80), | ||
177 | /* crb_rcv_consumer_offset: */ | ||
178 | NETXEN_NIC_REG(0x84), | ||
179 | /* crb_globalrcv_ring: */ | ||
180 | NETXEN_NIC_REG(0x88), | ||
181 | }, | ||
182 | /* Jumbo frames */ | ||
183 | { | ||
184 | /* crb_rcv_producer_offset: */ | ||
185 | NETXEN_NIC_REG(0x10C), | ||
186 | /* crb_rcv_consumer_offset: */ | ||
187 | NETXEN_NIC_REG(0x110), | ||
188 | /* crb_globalrcv_ring: */ | ||
189 | NETXEN_NIC_REG(0x114), | ||
190 | } | ||
191 | }, | ||
192 | /* crb_rcvstatus_ring: */ | ||
193 | NETXEN_NIC_REG(0x8c), | ||
194 | /* crb_rcv_status_producer: */ | ||
195 | NETXEN_NIC_REG(0x90), | ||
196 | /* crb_rcv_status_consumer: */ | ||
197 | NETXEN_NIC_REG(0x94), | ||
198 | /* crb_rcvpeg_state: */ | ||
199 | NETXEN_NIC_REG(0x98), | ||
200 | }, | ||
201 | }; | ||
202 | #else | ||
203 | extern struct netxen_recv_crb recv_crb_registers[]; | ||
204 | #endif /* DEFINE_GLOBAL_RECEIVE_CRB */ | ||
205 | |||
206 | /* | ||
207 | * Temperature control. | ||
208 | */ | ||
209 | enum { | ||
210 | NX_TEMP_NORMAL = 0x1, /* Normal operating range */ | ||
211 | NX_TEMP_WARN, /* Sound alert, temperature getting high */ | ||
212 | NX_TEMP_PANIC /* Fatal error, hardware has shut down. */ | ||
213 | }; | ||
214 | |||
215 | #endif /* __NIC_PHAN_REG_H_ */ | ||