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