blob: fa1fbab65621267b6de9c1bfd3d5ee4751570f71 [file] [log] [blame]
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001/*
2 * Copyright (C) 2003 - 2006 NetXen, Inc.
3 * All rights reserved.
Amit S. Kale80922fb2006-12-04 09:18:00 -08004 *
Amit S. Kale3d396eb2006-10-21 15:33:03 -04005 * 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.
Amit S. Kale80922fb2006-12-04 09:18:00 -08009 *
Amit S. Kale3d396eb2006-10-21 15:33:03 -040010 * 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.
Amit S. Kale80922fb2006-12-04 09:18:00 -080014 *
Amit S. Kale3d396eb2006-10-21 15:33:03 -040015 * 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.
Amit S. Kale80922fb2006-12-04 09:18:00 -080019 *
Amit S. Kale3d396eb2006-10-21 15:33:03 -040020 * The full GNU General Public License is included in this distribution
21 * in the file called LICENSE.
Amit S. Kale80922fb2006-12-04 09:18:00 -080022 *
Amit S. Kale3d396eb2006-10-21 15:33:03 -040023 * 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
Amit S. Kale3d396eb2006-10-21 15:33:03 -040033#include <linux/module.h>
34#include <linux/kernel.h>
35#include <linux/types.h>
36#include <linux/compiler.h>
37#include <linux/slab.h>
38#include <linux/delay.h>
39#include <linux/init.h>
40#include <linux/ioport.h>
41#include <linux/pci.h>
42#include <linux/netdevice.h>
43#include <linux/etherdevice.h>
44#include <linux/ip.h>
45#include <linux/in.h>
46#include <linux/tcp.h>
47#include <linux/skbuff.h>
48#include <linux/version.h>
49
50#include <linux/ethtool.h>
51#include <linux/mii.h>
52#include <linux/interrupt.h>
53#include <linux/timer.h>
54
55#include <linux/mm.h>
56#include <linux/mman.h>
57
58#include <asm/system.h>
59#include <asm/io.h>
60#include <asm/byteorder.h>
61#include <asm/uaccess.h>
62#include <asm/pgtable.h>
63
64#include "netxen_nic_hw.h"
65
Amit S. Kaleed25ffa2006-12-04 09:23:25 -080066#define _NETXEN_NIC_LINUX_MAJOR 3
Mithlesh Thukral6d1495f2007-04-20 07:56:42 -070067#define _NETXEN_NIC_LINUX_MINOR 4
dhananjay@netxen.com001a7312007-12-26 10:23:54 -080068#define _NETXEN_NIC_LINUX_SUBVERSION 18
69#define NETXEN_NIC_LINUX_VERSIONID "3.4.18"
Amit S. Kale27d2ab52007-02-05 07:40:49 -080070
Mithlesh Thukral0d047612007-06-07 04:36:36 -070071#define NETXEN_NUM_FLASH_SECTORS (64)
72#define NETXEN_FLASH_SECTOR_SIZE (64 * 1024)
73#define NETXEN_FLASH_TOTAL_SIZE (NETXEN_NUM_FLASH_SECTORS \
74 * NETXEN_FLASH_SECTOR_SIZE)
Amit S. Kale3d396eb2006-10-21 15:33:03 -040075
Linsys Contractor Mithlesh Thukral0c25cfe2007-02-28 05:14:07 -080076#define PHAN_VENDOR_ID 0x4040
77
Amit S. Kale3d396eb2006-10-21 15:33:03 -040078#define RCV_DESC_RINGSIZE \
79 (sizeof(struct rcv_desc) * adapter->max_rx_desc_count)
80#define STATUS_DESC_RINGSIZE \
81 (sizeof(struct status_desc)* adapter->max_rx_desc_count)
Amit S. Kaleed25ffa2006-12-04 09:23:25 -080082#define LRO_DESC_RINGSIZE \
83 (sizeof(rcvDesc_t) * adapter->max_lro_rx_desc_count)
Amit S. Kale3d396eb2006-10-21 15:33:03 -040084#define TX_RINGSIZE \
85 (sizeof(struct netxen_cmd_buffer) * adapter->max_tx_desc_count)
86#define RCV_BUFFSIZE \
87 (sizeof(struct netxen_rx_buffer) * rcv_desc->max_rx_desc_count)
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -070088#define find_diff_among(a,b,range) ((a)<(b)?((b)-(a)):((b)+(range)-(a)))
Amit S. Kale3d396eb2006-10-21 15:33:03 -040089
Amit S. Kaleed25ffa2006-12-04 09:23:25 -080090#define NETXEN_NETDEV_STATUS 0x1
91#define NETXEN_RCV_PRODUCER_OFFSET 0
92#define NETXEN_RCV_PEG_DB_ID 2
93#define NETXEN_HOST_DUMMY_DMA_SIZE 1024
Amit S. Kale27d2ab52007-02-05 07:40:49 -080094#define FLASH_SUCCESS 0
Amit S. Kale3d396eb2006-10-21 15:33:03 -040095
96#define ADDR_IN_WINDOW1(off) \
97 ((off > NETXEN_CRB_PCIX_HOST2) && (off < NETXEN_CRB_MAX)) ? 1 : 0
98
Jeff Garzik47906542007-11-23 21:23:36 -050099/*
100 * normalize a 64MB crb address to 32MB PCI window
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400101 * To use NETXEN_CRB_NORMALIZE, window _must_ be set to 1
102 */
Amit S. Kale80922fb2006-12-04 09:18:00 -0800103#define NETXEN_CRB_NORMAL(reg) \
104 ((reg) - NETXEN_CRB_PCIX_HOST2 + NETXEN_CRB_PCIX_HOST)
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800105
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400106#define NETXEN_CRB_NORMALIZE(adapter, reg) \
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800107 pci_base_offset(adapter, NETXEN_CRB_NORMAL(reg))
108
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800109#define DB_NORMALIZE(adapter, off) \
110 (adapter->ahw.db_base + (off))
111
112#define NX_P2_C0 0x24
113#define NX_P2_C1 0x25
114
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800115#define FIRST_PAGE_GROUP_START 0
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800116#define FIRST_PAGE_GROUP_END 0x100000
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800117
Mithlesh Thukral78403a92007-04-20 07:57:26 -0700118#define SECOND_PAGE_GROUP_START 0x6000000
119#define SECOND_PAGE_GROUP_END 0x68BC000
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800120
121#define THIRD_PAGE_GROUP_START 0x70E4000
122#define THIRD_PAGE_GROUP_END 0x8000000
123
124#define FIRST_PAGE_GROUP_SIZE FIRST_PAGE_GROUP_END - FIRST_PAGE_GROUP_START
125#define SECOND_PAGE_GROUP_SIZE SECOND_PAGE_GROUP_END - SECOND_PAGE_GROUP_START
126#define THIRD_PAGE_GROUP_SIZE THIRD_PAGE_GROUP_END - THIRD_PAGE_GROUP_START
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400127
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800128#define MAX_RX_BUFFER_LENGTH 1760
Amit S. Kalebd56c6b2006-12-18 05:54:36 -0800129#define MAX_RX_JUMBO_BUFFER_LENGTH 8062
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800130#define MAX_RX_LRO_BUFFER_LENGTH ((48*1024)-512)
131#define RX_DMA_MAP_LEN (MAX_RX_BUFFER_LENGTH - 2)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400132#define RX_JUMBO_DMA_MAP_LEN \
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800133 (MAX_RX_JUMBO_BUFFER_LENGTH - 2)
134#define RX_LRO_DMA_MAP_LEN (MAX_RX_LRO_BUFFER_LENGTH - 2)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400135
136/*
137 * Maximum number of ring contexts
138 */
139#define MAX_RING_CTX 1
140
141/* Opcodes to be used with the commands */
142enum {
143 TX_ETHER_PKT = 0x01,
144/* The following opcodes are for IP checksum */
145 TX_TCP_PKT,
146 TX_UDP_PKT,
147 TX_IP_PKT,
148 TX_TCP_LSO,
149 TX_IPSEC,
150 TX_IPSEC_CMD
151};
152
153/* The following opcodes are for internal consumption. */
154#define NETXEN_CONTROL_OP 0x10
155#define PEGNET_REQUEST 0x11
156
157#define MAX_NUM_CARDS 4
158
159#define MAX_BUFFERS_PER_CMD 32
160
161/*
162 * Following are the states of the Phantom. Phantom will set them and
163 * Host will read to check if the fields are correct.
164 */
165#define PHAN_INITIALIZE_START 0xff00
166#define PHAN_INITIALIZE_FAILED 0xffff
167#define PHAN_INITIALIZE_COMPLETE 0xff01
168
169/* Host writes the following to notify that it has done the init-handshake */
170#define PHAN_INITIALIZE_ACK 0xf00f
171
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800172#define NUM_RCV_DESC_RINGS 3 /* No of Rcv Descriptor contexts */
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400173
174/* descriptor types */
175#define RCV_DESC_NORMAL 0x01
176#define RCV_DESC_JUMBO 0x02
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800177#define RCV_DESC_LRO 0x04
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400178#define RCV_DESC_NORMAL_CTXID 0
179#define RCV_DESC_JUMBO_CTXID 1
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800180#define RCV_DESC_LRO_CTXID 2
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400181
182#define RCV_DESC_TYPE(ID) \
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800183 ((ID == RCV_DESC_JUMBO_CTXID) \
184 ? RCV_DESC_JUMBO \
185 : ((ID == RCV_DESC_LRO_CTXID) \
186 ? RCV_DESC_LRO : \
187 (RCV_DESC_NORMAL)))
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400188
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -0700189#define MAX_CMD_DESCRIPTORS 4096
Amit S. Kalebd56c6b2006-12-18 05:54:36 -0800190#define MAX_RCV_DESCRIPTORS 16384
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700191#define MAX_CMD_DESCRIPTORS_HOST (MAX_CMD_DESCRIPTORS / 4)
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700192#define MAX_RCV_DESCRIPTORS_1G (MAX_RCV_DESCRIPTORS / 4)
Amit S. Kalebd56c6b2006-12-18 05:54:36 -0800193#define MAX_JUMBO_RCV_DESCRIPTORS 1024
194#define MAX_LRO_RCV_DESCRIPTORS 64
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400195#define MAX_RCVSTATUS_DESCRIPTORS MAX_RCV_DESCRIPTORS
196#define MAX_JUMBO_RCV_DESC MAX_JUMBO_RCV_DESCRIPTORS
197#define MAX_RCV_DESC MAX_RCV_DESCRIPTORS
198#define MAX_RCVSTATUS_DESC MAX_RCV_DESCRIPTORS
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400199#define MAX_EPG_DESCRIPTORS (MAX_CMD_DESCRIPTORS * 8)
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800200#define NUM_RCV_DESC (MAX_RCV_DESC + MAX_JUMBO_RCV_DESCRIPTORS + \
201 MAX_LRO_RCV_DESCRIPTORS)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400202#define MIN_TX_COUNT 4096
203#define MIN_RX_COUNT 4096
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800204#define NETXEN_CTX_SIGNATURE 0xdee0
205#define NETXEN_RCV_PRODUCER(ringid) (ringid)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400206#define MAX_FRAME_SIZE 0x10000 /* 64K MAX size for LSO */
207
208#define PHAN_PEG_RCV_INITIALIZED 0xff01
209#define PHAN_PEG_RCV_START_INITIALIZE 0xff00
210
211#define get_next_index(index, length) \
212 (((index) + 1) & ((length) - 1))
213
214#define get_index_range(index,length,count) \
215 (((index) + (count)) & ((length) - 1))
216
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800217#define MPORT_SINGLE_FUNCTION_MODE 0x1111
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700218#define MPORT_MULTI_FUNCTION_MODE 0x2222
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800219
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700220#include "netxen_nic_phan_reg.h"
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800221
222/*
223 * NetXen host-peg signal message structure
224 *
225 * Bit 0-1 : peg_id => 0x2 for tx and 01 for rx
226 * Bit 2 : priv_id => must be 1
227 * Bit 3-17 : count => for doorbell
228 * Bit 18-27 : ctx_id => Context id
229 * Bit 28-31 : opcode
230 */
231
232typedef u32 netxen_ctx_msg;
233
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800234#define netxen_set_msg_peg_id(config_word, val) \
Al Viroa608ab9c2007-01-02 10:39:10 +0000235 ((config_word) &= ~3, (config_word) |= val & 3)
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800236#define netxen_set_msg_privid(config_word) \
Al Viroa608ab9c2007-01-02 10:39:10 +0000237 ((config_word) |= 1 << 2)
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800238#define netxen_set_msg_count(config_word, val) \
Al Viroa608ab9c2007-01-02 10:39:10 +0000239 ((config_word) &= ~(0x7fff<<3), (config_word) |= (val & 0x7fff) << 3)
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800240#define netxen_set_msg_ctxid(config_word, val) \
Al Viroa608ab9c2007-01-02 10:39:10 +0000241 ((config_word) &= ~(0x3ff<<18), (config_word) |= (val & 0x3ff) << 18)
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800242#define netxen_set_msg_opcode(config_word, val) \
Amit S. Kale82581172007-02-12 04:33:38 -0800243 ((config_word) &= ~(0xf<<28), (config_word) |= (val & 0xf) << 28)
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800244
245struct netxen_rcv_context {
Al Viroa608ab9c2007-01-02 10:39:10 +0000246 __le64 rcv_ring_addr;
247 __le32 rcv_ring_size;
248 __le32 rsrvd;
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800249};
250
251struct netxen_ring_ctx {
252
253 /* one command ring */
Al Viroa608ab9c2007-01-02 10:39:10 +0000254 __le64 cmd_consumer_offset;
255 __le64 cmd_ring_addr;
256 __le32 cmd_ring_size;
257 __le32 rsrvd;
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800258
259 /* three receive rings */
260 struct netxen_rcv_context rcv_ctx[3];
261
262 /* one status ring */
Al Viroa608ab9c2007-01-02 10:39:10 +0000263 __le64 sts_ring_addr;
264 __le32 sts_ring_size;
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800265
Al Viroa608ab9c2007-01-02 10:39:10 +0000266 __le32 ctx_id;
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800267} __attribute__ ((aligned(64)));
268
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400269/*
270 * Following data structures describe the descriptors that will be used.
271 * Added fileds of tcpHdrSize and ipHdrSize, The driver needs to do it only when
272 * we are doing LSO (above the 1500 size packet) only.
273 */
274
275/*
276 * The size of reference handle been changed to 16 bits to pass the MSS fields
277 * for the LSO packet
278 */
279
280#define FLAGS_CHECKSUM_ENABLED 0x01
281#define FLAGS_LSO_ENABLED 0x02
282#define FLAGS_IPSEC_SA_ADD 0x04
283#define FLAGS_IPSEC_SA_DELETE 0x08
284#define FLAGS_VLAN_TAGGED 0x10
285
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800286#define netxen_set_cmd_desc_port(cmd_desc, var) \
287 ((cmd_desc)->port_ctxid |= ((var) & 0x0F))
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700288#define netxen_set_cmd_desc_ctxid(cmd_desc, var) \
289 ((cmd_desc)->port_ctxid |= ((var) & 0xF0))
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400290
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800291#define netxen_set_cmd_desc_flags(cmd_desc, val) \
Dhananjay Phadke5dc16262007-12-31 10:08:57 -0800292 (cmd_desc)->flags_opcode = ((cmd_desc)->flags_opcode & \
293 ~cpu_to_le16(0x7f)) | cpu_to_le16((val) & 0x7f)
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800294#define netxen_set_cmd_desc_opcode(cmd_desc, val) \
Dhananjay Phadke5dc16262007-12-31 10:08:57 -0800295 (cmd_desc)->flags_opcode = ((cmd_desc)->flags_opcode & \
296 ~cpu_to_le16((u16)0x3f << 7)) | cpu_to_le16(((val) & 0x3f) << 7)
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800297
298#define netxen_set_cmd_desc_num_of_buff(cmd_desc, val) \
Dhananjay Phadke5dc16262007-12-31 10:08:57 -0800299 (cmd_desc)->num_of_buffers_total_length = \
300 ((cmd_desc)->num_of_buffers_total_length & \
301 ~cpu_to_le32(0xff)) | cpu_to_le32((val) & 0xff)
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800302#define netxen_set_cmd_desc_totallength(cmd_desc, val) \
Dhananjay Phadke5dc16262007-12-31 10:08:57 -0800303 (cmd_desc)->num_of_buffers_total_length = \
304 ((cmd_desc)->num_of_buffers_total_length & \
305 ~cpu_to_le32((u32)0xffffff << 8)) | \
306 cpu_to_le32(((val) & 0xffffff) << 8)
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800307
308#define netxen_get_cmd_desc_opcode(cmd_desc) \
Dhananjay Phadke5dc16262007-12-31 10:08:57 -0800309 ((le16_to_cpu((cmd_desc)->flags_opcode) >> 7) & 0x003f)
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800310#define netxen_get_cmd_desc_totallength(cmd_desc) \
Dhananjay Phadke5dc16262007-12-31 10:08:57 -0800311 ((le32_to_cpu((cmd_desc)->num_of_buffers_total_length) >> 8) & 0xffffff)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400312
313struct cmd_desc_type0 {
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800314 u8 tcp_hdr_offset; /* For LSO only */
315 u8 ip_hdr_offset; /* For LSO only */
316 /* Bit pattern: 0-6 flags, 7-12 opcode, 13-15 unused */
Al Viroa608ab9c2007-01-02 10:39:10 +0000317 __le16 flags_opcode;
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800318 /* Bit pattern: 0-7 total number of segments,
319 8-31 Total size of the packet */
Al Viroa608ab9c2007-01-02 10:39:10 +0000320 __le32 num_of_buffers_total_length;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400321 union {
322 struct {
Al Viroa608ab9c2007-01-02 10:39:10 +0000323 __le32 addr_low_part2;
324 __le32 addr_high_part2;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400325 };
Al Viroa608ab9c2007-01-02 10:39:10 +0000326 __le64 addr_buffer2;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400327 };
328
Al Viroa608ab9c2007-01-02 10:39:10 +0000329 __le16 reference_handle; /* changed to u16 to add mss */
330 __le16 mss; /* passed by NDIS_PACKET for LSO */
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400331 /* Bit pattern 0-3 port, 0-3 ctx id */
332 u8 port_ctxid;
333 u8 total_hdr_length; /* LSO only : MAC+IP+TCP Hdr size */
Al Viroa608ab9c2007-01-02 10:39:10 +0000334 __le16 conn_id; /* IPSec offoad only */
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400335
336 union {
337 struct {
Al Viroa608ab9c2007-01-02 10:39:10 +0000338 __le32 addr_low_part3;
339 __le32 addr_high_part3;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400340 };
Al Viroa608ab9c2007-01-02 10:39:10 +0000341 __le64 addr_buffer3;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400342 };
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400343 union {
344 struct {
Al Viroa608ab9c2007-01-02 10:39:10 +0000345 __le32 addr_low_part1;
346 __le32 addr_high_part1;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400347 };
Al Viroa608ab9c2007-01-02 10:39:10 +0000348 __le64 addr_buffer1;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400349 };
350
Al Viroa608ab9c2007-01-02 10:39:10 +0000351 __le16 buffer1_length;
352 __le16 buffer2_length;
353 __le16 buffer3_length;
354 __le16 buffer4_length;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400355
356 union {
357 struct {
Al Viroa608ab9c2007-01-02 10:39:10 +0000358 __le32 addr_low_part4;
359 __le32 addr_high_part4;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400360 };
Al Viroa608ab9c2007-01-02 10:39:10 +0000361 __le64 addr_buffer4;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400362 };
363
Al Viroa608ab9c2007-01-02 10:39:10 +0000364 __le64 unused;
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800365
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400366} __attribute__ ((aligned(64)));
367
368/* Note: sizeof(rcv_desc) should always be a mutliple of 2 */
369struct rcv_desc {
Al Viroa608ab9c2007-01-02 10:39:10 +0000370 __le16 reference_handle;
371 __le16 reserved;
372 __le32 buffer_length; /* allocated buffer length (usually 2K) */
373 __le64 addr_buffer;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400374};
375
376/* opcode field in status_desc */
377#define RCV_NIC_PKT (0xA)
378#define STATUS_NIC_PKT ((RCV_NIC_PKT) << 12)
379
380/* for status field in status_desc */
381#define STATUS_NEED_CKSUM (1)
382#define STATUS_CKSUM_OK (2)
383
384/* owner bits of status_desc */
385#define STATUS_OWNER_HOST (0x1)
386#define STATUS_OWNER_PHANTOM (0x2)
387
388#define NETXEN_PROT_IP (1)
389#define NETXEN_PROT_UNKNOWN (0)
390
391/* Note: sizeof(status_desc) should always be a mutliple of 2 */
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800392
393#define netxen_get_sts_desc_lro_cnt(status_desc) \
394 ((status_desc)->lro & 0x7F)
395#define netxen_get_sts_desc_lro_last_frag(status_desc) \
396 (((status_desc)->lro & 0x80) >> 7)
397
Dhananjay Phadke5dc16262007-12-31 10:08:57 -0800398#define netxen_get_sts_port(sts_data) \
399 ((sts_data) & 0x0F)
400#define netxen_get_sts_status(sts_data) \
401 (((sts_data) >> 4) & 0x0F)
402#define netxen_get_sts_type(sts_data) \
403 (((sts_data) >> 8) & 0x0F)
404#define netxen_get_sts_totallength(sts_data) \
405 (((sts_data) >> 12) & 0xFFFF)
406#define netxen_get_sts_refhandle(sts_data) \
407 (((sts_data) >> 28) & 0xFFFF)
408#define netxen_get_sts_prot(sts_data) \
409 (((sts_data) >> 44) & 0x0F)
410#define netxen_get_sts_opcode(sts_data) \
411 (((sts_data) >> 58) & 0x03F)
412
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800413#define netxen_get_sts_owner(status_desc) \
Al Viroa608ab9c2007-01-02 10:39:10 +0000414 ((le64_to_cpu((status_desc)->status_desc_data) >> 56) & 0x03)
Dhananjay Phadke5dc16262007-12-31 10:08:57 -0800415#define netxen_set_sts_owner(status_desc, val) { \
416 (status_desc)->status_desc_data = \
417 ((status_desc)->status_desc_data & \
418 ~cpu_to_le64(0x3ULL << 56)) | \
419 cpu_to_le64((u64)((val) & 0x3) << 56); \
420}
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400421
422struct status_desc {
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800423 /* Bit pattern: 0-3 port, 4-7 status, 8-11 type, 12-27 total_length
424 28-43 reference_handle, 44-47 protocol, 48-52 unused
425 53-55 desc_cnt, 56-57 owner, 58-63 opcode
426 */
Al Viroa608ab9c2007-01-02 10:39:10 +0000427 __le64 status_desc_data;
428 __le32 hash_value;
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800429 u8 hash_type;
430 u8 msg_type;
431 u8 unused;
432 /* Bit pattern: 0-6 lro_count indicates frag sequence,
433 7 last_frag indicates last frag */
434 u8 lro;
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700435} __attribute__ ((aligned(16)));
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400436
437enum {
438 NETXEN_RCV_PEG_0 = 0,
439 NETXEN_RCV_PEG_1
440};
441/* The version of the main data structure */
442#define NETXEN_BDINFO_VERSION 1
443
444/* Magic number to let user know flash is programmed */
445#define NETXEN_BDINFO_MAGIC 0x12345678
446
447/* Max number of Gig ports on a Phantom board */
448#define NETXEN_MAX_PORTS 4
449
450typedef enum {
451 NETXEN_BRDTYPE_P1_BD = 0x0000,
452 NETXEN_BRDTYPE_P1_SB = 0x0001,
453 NETXEN_BRDTYPE_P1_SMAX = 0x0002,
454 NETXEN_BRDTYPE_P1_SOCK = 0x0003,
455
456 NETXEN_BRDTYPE_P2_SOCK_31 = 0x0008,
457 NETXEN_BRDTYPE_P2_SOCK_35 = 0x0009,
458 NETXEN_BRDTYPE_P2_SB35_4G = 0x000a,
459 NETXEN_BRDTYPE_P2_SB31_10G = 0x000b,
460 NETXEN_BRDTYPE_P2_SB31_2G = 0x000c,
461
462 NETXEN_BRDTYPE_P2_SB31_10G_IMEZ = 0x000d,
463 NETXEN_BRDTYPE_P2_SB31_10G_HMEZ = 0x000e,
464 NETXEN_BRDTYPE_P2_SB31_10G_CX4 = 0x000f
465} netxen_brdtype_t;
466
467typedef enum {
468 NETXEN_BRDMFG_INVENTEC = 1
469} netxen_brdmfg;
470
471typedef enum {
472 MEM_ORG_128Mbx4 = 0x0, /* DDR1 only */
473 MEM_ORG_128Mbx8 = 0x1, /* DDR1 only */
474 MEM_ORG_128Mbx16 = 0x2, /* DDR1 only */
475 MEM_ORG_256Mbx4 = 0x3,
476 MEM_ORG_256Mbx8 = 0x4,
477 MEM_ORG_256Mbx16 = 0x5,
478 MEM_ORG_512Mbx4 = 0x6,
479 MEM_ORG_512Mbx8 = 0x7,
480 MEM_ORG_512Mbx16 = 0x8,
481 MEM_ORG_1Gbx4 = 0x9,
482 MEM_ORG_1Gbx8 = 0xa,
483 MEM_ORG_1Gbx16 = 0xb,
484 MEM_ORG_2Gbx4 = 0xc,
485 MEM_ORG_2Gbx8 = 0xd,
486 MEM_ORG_2Gbx16 = 0xe,
487 MEM_ORG_128Mbx32 = 0x10002, /* GDDR only */
488 MEM_ORG_256Mbx32 = 0x10005 /* GDDR only */
489} netxen_mn_mem_org_t;
490
491typedef enum {
492 MEM_ORG_512Kx36 = 0x0,
493 MEM_ORG_1Mx36 = 0x1,
494 MEM_ORG_2Mx36 = 0x2
495} netxen_sn_mem_org_t;
496
497typedef enum {
498 MEM_DEPTH_4MB = 0x1,
499 MEM_DEPTH_8MB = 0x2,
500 MEM_DEPTH_16MB = 0x3,
501 MEM_DEPTH_32MB = 0x4,
502 MEM_DEPTH_64MB = 0x5,
503 MEM_DEPTH_128MB = 0x6,
504 MEM_DEPTH_256MB = 0x7,
505 MEM_DEPTH_512MB = 0x8,
506 MEM_DEPTH_1GB = 0x9,
507 MEM_DEPTH_2GB = 0xa,
508 MEM_DEPTH_4GB = 0xb,
509 MEM_DEPTH_8GB = 0xc,
510 MEM_DEPTH_16GB = 0xd,
511 MEM_DEPTH_32GB = 0xe
512} netxen_mem_depth_t;
513
514struct netxen_board_info {
515 u32 header_version;
516
517 u32 board_mfg;
518 u32 board_type;
519 u32 board_num;
520 u32 chip_id;
521 u32 chip_minor;
522 u32 chip_major;
523 u32 chip_pkg;
524 u32 chip_lot;
525
526 u32 port_mask; /* available niu ports */
527 u32 peg_mask; /* available pegs */
528 u32 icache_ok; /* can we run with icache? */
529 u32 dcache_ok; /* can we run with dcache? */
530 u32 casper_ok;
531
532 u32 mac_addr_lo_0;
533 u32 mac_addr_lo_1;
534 u32 mac_addr_lo_2;
535 u32 mac_addr_lo_3;
536
537 /* MN-related config */
538 u32 mn_sync_mode; /* enable/ sync shift cclk/ sync shift mclk */
539 u32 mn_sync_shift_cclk;
540 u32 mn_sync_shift_mclk;
541 u32 mn_wb_en;
542 u32 mn_crystal_freq; /* in MHz */
543 u32 mn_speed; /* in MHz */
544 u32 mn_org;
545 u32 mn_depth;
546 u32 mn_ranks_0; /* ranks per slot */
547 u32 mn_ranks_1; /* ranks per slot */
548 u32 mn_rd_latency_0;
549 u32 mn_rd_latency_1;
550 u32 mn_rd_latency_2;
551 u32 mn_rd_latency_3;
552 u32 mn_rd_latency_4;
553 u32 mn_rd_latency_5;
554 u32 mn_rd_latency_6;
555 u32 mn_rd_latency_7;
556 u32 mn_rd_latency_8;
557 u32 mn_dll_val[18];
558 u32 mn_mode_reg; /* MIU DDR Mode Register */
559 u32 mn_ext_mode_reg; /* MIU DDR Extended Mode Register */
560 u32 mn_timing_0; /* MIU Memory Control Timing Rgister */
561 u32 mn_timing_1; /* MIU Extended Memory Ctrl Timing Register */
562 u32 mn_timing_2; /* MIU Extended Memory Ctrl Timing2 Register */
563
564 /* SN-related config */
565 u32 sn_sync_mode; /* enable/ sync shift cclk / sync shift mclk */
566 u32 sn_pt_mode; /* pass through mode */
567 u32 sn_ecc_en;
568 u32 sn_wb_en;
569 u32 sn_crystal_freq;
570 u32 sn_speed;
571 u32 sn_org;
572 u32 sn_depth;
573 u32 sn_dll_tap;
574 u32 sn_rd_latency;
575
576 u32 mac_addr_hi_0;
577 u32 mac_addr_hi_1;
578 u32 mac_addr_hi_2;
579 u32 mac_addr_hi_3;
580
581 u32 magic; /* indicates flash has been initialized */
582
583 u32 mn_rdimm;
584 u32 mn_dll_override;
585
586};
587
588#define FLASH_NUM_PORTS (4)
589
590struct netxen_flash_mac_addr {
591 u32 flash_addr[32];
592};
593
594struct netxen_user_old_info {
595 u8 flash_md5[16];
596 u8 crbinit_md5[16];
597 u8 brdcfg_md5[16];
598 /* bootloader */
599 u32 bootld_version;
600 u32 bootld_size;
601 u8 bootld_md5[16];
602 /* image */
603 u32 image_version;
604 u32 image_size;
605 u8 image_md5[16];
606 /* primary image status */
607 u32 primary_status;
608 u32 secondary_present;
609
610 /* MAC address , 4 ports */
611 struct netxen_flash_mac_addr mac_addr[FLASH_NUM_PORTS];
612};
613#define FLASH_NUM_MAC_PER_PORT 32
614struct netxen_user_info {
615 u8 flash_md5[16 * 64];
616 /* bootloader */
617 u32 bootld_version;
618 u32 bootld_size;
619 /* image */
620 u32 image_version;
621 u32 image_size;
622 /* primary image status */
623 u32 primary_status;
624 u32 secondary_present;
625
626 /* MAC address , 4 ports, 32 address per port */
627 u64 mac_addr[FLASH_NUM_PORTS * FLASH_NUM_MAC_PER_PORT];
628 u32 sub_sys_id;
629 u8 serial_num[32];
630
631 /* Any user defined data */
632};
633
634/*
635 * Flash Layout - new format.
636 */
637struct netxen_new_user_info {
638 u8 flash_md5[16 * 64];
639 /* bootloader */
640 u32 bootld_version;
641 u32 bootld_size;
642 /* image */
643 u32 image_version;
644 u32 image_size;
645 /* primary image status */
646 u32 primary_status;
647 u32 secondary_present;
648
649 /* MAC address , 4 ports, 32 address per port */
650 u64 mac_addr[FLASH_NUM_PORTS * FLASH_NUM_MAC_PER_PORT];
651 u32 sub_sys_id;
652 u8 serial_num[32];
653
654 /* Any user defined data */
655};
656
657#define SECONDARY_IMAGE_PRESENT 0xb3b4b5b6
658#define SECONDARY_IMAGE_ABSENT 0xffffffff
659#define PRIMARY_IMAGE_GOOD 0x5a5a5a5a
660#define PRIMARY_IMAGE_BAD 0xffffffff
661
662/* Flash memory map */
663typedef enum {
Mithlesh Thukral0d047612007-06-07 04:36:36 -0700664 NETXEN_CRBINIT_START = 0, /* Crbinit section */
665 NETXEN_BRDCFG_START = 0x4000, /* board config */
666 NETXEN_INITCODE_START = 0x6000, /* pegtune code */
667 NETXEN_BOOTLD_START = 0x10000, /* bootld */
668 NETXEN_IMAGE_START = 0x43000, /* compressed image */
669 NETXEN_SECONDARY_START = 0x200000, /* backup images */
670 NETXEN_PXE_START = 0x3E0000, /* user defined region */
671 NETXEN_USER_START = 0x3E8000, /* User defined region for new boards */
672 NETXEN_FIXED_START = 0x3F0000 /* backup of crbinit */
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400673} netxen_flash_map_t;
674
Mithlesh Thukral0d047612007-06-07 04:36:36 -0700675#define NETXEN_USER_START_OLD NETXEN_PXE_START /* for backward compatibility */
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400676
Mithlesh Thukral0d047612007-06-07 04:36:36 -0700677#define NETXEN_FLASH_START (NETXEN_CRBINIT_START)
678#define NETXEN_INIT_SECTOR (0)
679#define NETXEN_PRIMARY_START (NETXEN_BOOTLD_START)
680#define NETXEN_FLASH_CRBINIT_SIZE (0x4000)
681#define NETXEN_FLASH_BRDCFG_SIZE (sizeof(struct netxen_board_info))
682#define NETXEN_FLASH_USER_SIZE (sizeof(struct netxen_user_info)/sizeof(u32))
683#define NETXEN_FLASH_SECONDARY_SIZE (NETXEN_USER_START-NETXEN_SECONDARY_START)
684#define NETXEN_NUM_PRIMARY_SECTORS (0x20)
685#define NETXEN_NUM_CONFIG_SECTORS (1)
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800686#define PFX "NetXen: "
687extern char netxen_nic_driver_name[];
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400688
689/* Note: Make sure to not call this before adapter->port is valid */
690#if !defined(NETXEN_DEBUG)
691#define DPRINTK(klevel, fmt, args...) do { \
692 } while (0)
693#else
694#define DPRINTK(klevel, fmt, args...) do { \
695 printk(KERN_##klevel PFX "%s: %s: " fmt, __FUNCTION__,\
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700696 (adapter != NULL && adapter->netdev != NULL) ? \
697 adapter->netdev->name : NULL, \
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400698 ## args); } while(0)
699#endif
700
701/* Number of status descriptors to handle per interrupt */
702#define MAX_STATUS_HANDLE (128)
703
704/*
705 * netxen_skb_frag{} is to contain mapping info for each SG list. This
706 * has to be freed when DMA is complete. This is part of netxen_tx_buffer{}.
707 */
708struct netxen_skb_frag {
709 u64 dma;
710 u32 length;
711};
712
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700713#define _netxen_set_bits(config_word, start, bits, val) {\
714 unsigned long long __tmask = (((1ULL << (bits)) - 1) << (start));\
715 unsigned long long __tvalue = (val); \
716 (config_word) &= ~__tmask; \
717 (config_word) |= (((__tvalue) << (start)) & __tmask); \
718}
Jeff Garzik47906542007-11-23 21:23:36 -0500719
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700720#define _netxen_clear_bits(config_word, start, bits) {\
721 unsigned long long __tmask = (((1ULL << (bits)) - 1) << (start)); \
722 (config_word) &= ~__tmask; \
Jeff Garzik47906542007-11-23 21:23:36 -0500723}
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700724
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400725/* Following defines are for the state of the buffers */
726#define NETXEN_BUFFER_FREE 0
727#define NETXEN_BUFFER_BUSY 1
728
729/*
730 * There will be one netxen_buffer per skb packet. These will be
731 * used to save the dma info for pci_unmap_page()
732 */
733struct netxen_cmd_buffer {
734 struct sk_buff *skb;
735 struct netxen_skb_frag frag_array[MAX_BUFFERS_PER_CMD + 1];
736 u32 total_length;
737 u32 mss;
738 u16 port;
739 u8 cmd;
740 u8 frag_count;
741 unsigned long time_stamp;
742 u32 state;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400743};
744
745/* In rx_buffer, we do not need multiple fragments as is a single buffer */
746struct netxen_rx_buffer {
747 struct sk_buff *skb;
748 u64 dma;
749 u16 ref_handle;
750 u16 state;
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800751 u32 lro_expected_frags;
752 u32 lro_current_frags;
753 u32 lro_length;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400754};
755
756/* Board types */
757#define NETXEN_NIC_GBE 0x01
758#define NETXEN_NIC_XGBE 0x02
759
760/*
761 * One hardware_context{} per adapter
762 * contains interrupt info as well shared hardware info.
763 */
764struct netxen_hardware_context {
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800765 void __iomem *pci_base0;
766 void __iomem *pci_base1;
767 void __iomem *pci_base2;
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700768 unsigned long first_page_group_end;
769 unsigned long first_page_group_start;
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800770 void __iomem *db_base;
771 unsigned long db_len;
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800772
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400773 u8 revision_id;
774 u16 board_type;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400775 struct netxen_board_info boardcfg;
776 u32 xg_linkup;
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800777 u32 qg_linksup;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400778 /* Address of cmd ring in Phantom */
779 struct cmd_desc_type0 *cmd_desc_head;
780 dma_addr_t cmd_desc_phys_addr;
781 struct netxen_adapter *adapter;
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700782 int pci_func;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400783};
784
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800785#define RCV_RING_LRO RCV_DESC_LRO
786
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400787#define MINIMUM_ETHERNET_FRAME_SIZE 64 /* With FCS */
788#define ETHERNET_FCS_SIZE 4
789
790struct netxen_adapter_stats {
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700791 u64 rcvdbadskb;
792 u64 xmitcalled;
793 u64 xmitedframes;
794 u64 xmitfinished;
795 u64 badskblen;
796 u64 nocmddescriptor;
797 u64 polled;
Dhananjay Phadked1847a72008-03-17 19:59:51 -0700798 u64 rxdropped;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700799 u64 txdropped;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700800 u64 csummed;
801 u64 no_rcv;
802 u64 rxbytes;
803 u64 txbytes;
804 u64 ints;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400805};
806
807/*
808 * Rcv Descriptor Context. One such per Rcv Descriptor. There may
809 * be one Rcv Descriptor for normal packets, one for jumbo and may be others.
810 */
811struct netxen_rcv_desc_ctx {
812 u32 flags;
813 u32 producer;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400814 dma_addr_t phys_addr;
Dhananjay Phadke7830b222008-07-21 19:44:00 -0700815 u32 crb_rcv_producer; /* reg offset */
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400816 struct rcv_desc *desc_head; /* address of rx ring in Phantom */
817 u32 max_rx_desc_count;
818 u32 dma_size;
819 u32 skb_size;
820 struct netxen_rx_buffer *rx_buf_arr; /* rx buffers for receive */
821 int begin_alloc;
822};
823
824/*
825 * Receive context. There is one such structure per instance of the
826 * receive processing. Any state information that is relevant to
827 * the receive, and is must be in this structure. The global data may be
828 * present elsewhere.
829 */
830struct netxen_recv_context {
831 struct netxen_rcv_desc_ctx rcv_desc[NUM_RCV_DESC_RINGS];
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400832 u32 status_rx_consumer;
Dhananjay Phadke7830b222008-07-21 19:44:00 -0700833 u32 crb_sts_consumer; /* reg offset */
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400834 dma_addr_t rcv_status_desc_phys_addr;
835 struct status_desc *rcv_status_desc_head;
836};
837
838#define NETXEN_NIC_MSI_ENABLED 0x02
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800839#define NETXEN_DMA_MASK 0xfffffffe
840#define NETXEN_DB_MAPSIZE_BYTES 0x1000
841
842struct netxen_dummy_dma {
843 void *addr;
844 dma_addr_t phys_addr;
845};
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400846
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400847struct netxen_adapter {
848 struct netxen_hardware_context ahw;
Jeff Garzik47906542007-11-23 21:23:36 -0500849
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700850 struct net_device *netdev;
851 struct pci_dev *pdev;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700852 struct napi_struct napi;
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700853 struct net_device_stats net_stats;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700854 unsigned char mac_addr[ETH_ALEN];
855 int mtu;
856 int portnum;
Dhananjay Phadke3276fba2008-06-15 22:59:44 -0700857 u8 physical_port;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700858
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700859 uint8_t mc_enabled;
860 uint8_t max_mc_count;
861
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400862 struct work_struct watchdog_task;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400863 struct timer_list watchdog_timer;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700864 struct work_struct tx_timeout_task;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400865
866 u32 curr_window;
867
868 u32 cmd_producer;
Al Virof305f782007-12-22 19:44:00 +0000869 __le32 *cmd_consumer;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400870 u32 last_cmd_consumer;
Dhananjay Phadke7830b222008-07-21 19:44:00 -0700871 u32 crb_addr_cmd_producer;
872 u32 crb_addr_cmd_consumer;
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -0700873
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400874 u32 max_tx_desc_count;
875 u32 max_rx_desc_count;
876 u32 max_jumbo_rx_desc_count;
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800877 u32 max_lro_rx_desc_count;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400878
879 u32 flags;
880 u32 irq;
881 int driver_mismatch;
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800882 u32 temp;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400883
884 struct netxen_adapter_stats stats;
Jeff Garzik47906542007-11-23 21:23:36 -0500885
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700886 u16 link_speed;
887 u16 link_duplex;
888 u16 state;
889 u16 link_autoneg;
Dhananjay Phadke200eef22007-09-03 10:33:35 +0530890 int rx_csum;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700891 int status;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400892
893 struct netxen_cmd_buffer *cmd_buf_arr; /* Command buffers for xmit */
894
895 /*
896 * Receive instances. These can be either one per port,
897 * or one per peg, etc.
898 */
899 struct netxen_recv_context recv_ctx[MAX_RCV_CTX];
900
901 int is_up;
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800902 struct netxen_dummy_dma dummy_dma;
903
904 /* Context interface shared between card and host */
905 struct netxen_ring_ctx *ctx_desc;
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800906 dma_addr_t ctx_desc_phys_addr;
dhananjay.phadke@gmail.com2d1a3bb2007-07-02 00:26:00 +0530907 int intr_scheme;
Dhananjay Phadke443be792008-03-17 19:59:48 -0700908 int msi_mode;
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700909 int (*enable_phy_interrupts) (struct netxen_adapter *);
910 int (*disable_phy_interrupts) (struct netxen_adapter *);
Amit S. Kale80922fb2006-12-04 09:18:00 -0800911 void (*handle_phy_intr) (struct netxen_adapter *);
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700912 int (*macaddr_set) (struct netxen_adapter *, netxen_ethernet_macaddr_t);
913 int (*set_mtu) (struct netxen_adapter *, int);
914 int (*set_promisc) (struct netxen_adapter *, netxen_niu_prom_mode_t);
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700915 int (*phy_read) (struct netxen_adapter *, long reg, u32 *);
916 int (*phy_write) (struct netxen_adapter *, long reg, u32 val);
Amit S. Kale80922fb2006-12-04 09:18:00 -0800917 int (*init_port) (struct netxen_adapter *, int);
918 void (*init_niu) (struct netxen_adapter *);
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700919 int (*stop_port) (struct netxen_adapter *);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400920}; /* netxen_adapter structure */
921
Dhananjay Phadke96acb6e2007-07-02 09:37:57 +0530922/*
923 * NetXen dma watchdog control structure
924 *
925 * Bit 0 : enabled => R/O: 1 watchdog active, 0 inactive
926 * Bit 1 : disable_request => 1 req disable dma watchdog
927 * Bit 2 : enable_request => 1 req enable dma watchdog
928 * Bit 3-31 : unused
929 */
930
931#define netxen_set_dma_watchdog_disable_req(config_word) \
932 _netxen_set_bits(config_word, 1, 1, 1)
933#define netxen_set_dma_watchdog_enable_req(config_word) \
934 _netxen_set_bits(config_word, 2, 1, 1)
935#define netxen_get_dma_watchdog_enabled(config_word) \
936 ((config_word) & 0x1)
937#define netxen_get_dma_watchdog_disabled(config_word) \
938 (((config_word) >> 1) & 0x1)
939
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400940/* Max number of xmit producer threads that can run simultaneously */
941#define MAX_XMIT_PRODUCERS 16
942
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800943#define PCI_OFFSET_FIRST_RANGE(adapter, off) \
944 ((adapter)->ahw.pci_base0 + (off))
945#define PCI_OFFSET_SECOND_RANGE(adapter, off) \
946 ((adapter)->ahw.pci_base1 + (off) - SECOND_PAGE_GROUP_START)
947#define PCI_OFFSET_THIRD_RANGE(adapter, off) \
948 ((adapter)->ahw.pci_base2 + (off) - THIRD_PAGE_GROUP_START)
949
950static inline void __iomem *pci_base_offset(struct netxen_adapter *adapter,
951 unsigned long off)
952{
953 if ((off < FIRST_PAGE_GROUP_END) && (off >= FIRST_PAGE_GROUP_START)) {
954 return (adapter->ahw.pci_base0 + off);
955 } else if ((off < SECOND_PAGE_GROUP_END) &&
956 (off >= SECOND_PAGE_GROUP_START)) {
957 return (adapter->ahw.pci_base1 + off - SECOND_PAGE_GROUP_START);
958 } else if ((off < THIRD_PAGE_GROUP_END) &&
959 (off >= THIRD_PAGE_GROUP_START)) {
960 return (adapter->ahw.pci_base2 + off - THIRD_PAGE_GROUP_START);
961 }
962 return NULL;
963}
964
965static inline void __iomem *pci_base(struct netxen_adapter *adapter,
966 unsigned long off)
967{
968 if ((off < FIRST_PAGE_GROUP_END) && (off >= FIRST_PAGE_GROUP_START)) {
969 return adapter->ahw.pci_base0;
970 } else if ((off < SECOND_PAGE_GROUP_END) &&
971 (off >= SECOND_PAGE_GROUP_START)) {
972 return adapter->ahw.pci_base1;
973 } else if ((off < THIRD_PAGE_GROUP_END) &&
974 (off >= THIRD_PAGE_GROUP_START)) {
975 return adapter->ahw.pci_base2;
976 }
977 return NULL;
978}
979
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700980int netxen_niu_xgbe_enable_phy_interrupts(struct netxen_adapter *adapter);
981int netxen_niu_gbe_enable_phy_interrupts(struct netxen_adapter *adapter);
982int netxen_niu_xgbe_disable_phy_interrupts(struct netxen_adapter *adapter);
983int netxen_niu_gbe_disable_phy_interrupts(struct netxen_adapter *adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400984void netxen_nic_xgbe_handle_phy_intr(struct netxen_adapter *adapter);
985void netxen_nic_gbe_handle_phy_intr(struct netxen_adapter *adapter);
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700986int netxen_niu_gbe_phy_read(struct netxen_adapter *adapter, long reg,
Al Viroa608ab9c2007-01-02 10:39:10 +0000987 __u32 * readval);
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700988int netxen_niu_gbe_phy_write(struct netxen_adapter *adapter,
Al Viroa608ab9c2007-01-02 10:39:10 +0000989 long reg, __u32 val);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400990
991/* Functions available from netxen_nic_hw.c */
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700992int netxen_nic_set_mtu_xgb(struct netxen_adapter *adapter, int new_mtu);
993int netxen_nic_set_mtu_gb(struct netxen_adapter *adapter, int new_mtu);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400994void netxen_nic_init_niu_gb(struct netxen_adapter *adapter);
995void netxen_nic_pci_change_crbwindow(struct netxen_adapter *adapter, u32 wndw);
996void netxen_nic_reg_write(struct netxen_adapter *adapter, u64 off, u32 val);
997int netxen_nic_reg_read(struct netxen_adapter *adapter, u64 off);
998void netxen_nic_write_w0(struct netxen_adapter *adapter, u32 index, u32 value);
999void netxen_nic_read_w0(struct netxen_adapter *adapter, u32 index, u32 * value);
1000
1001int netxen_nic_get_board_info(struct netxen_adapter *adapter);
1002int netxen_nic_hw_read_wx(struct netxen_adapter *adapter, u64 off, void *data,
1003 int len);
1004int netxen_nic_hw_write_wx(struct netxen_adapter *adapter, u64 off, void *data,
1005 int len);
1006void netxen_crb_writelit_adapter(struct netxen_adapter *adapter,
1007 unsigned long off, int data);
1008
1009/* Functions from netxen_nic_init.c */
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001010void netxen_free_adapter_offload(struct netxen_adapter *adapter);
1011int netxen_initialize_adapter_offload(struct netxen_adapter *adapter);
Dhananjay Phadke96acb6e2007-07-02 09:37:57 +05301012int netxen_phantom_init(struct netxen_adapter *adapter, int pegtune_val);
1013int netxen_load_firmware(struct netxen_adapter *adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001014int netxen_pinit_from_rom(struct netxen_adapter *adapter, int verbose);
1015int netxen_rom_fast_read(struct netxen_adapter *adapter, int addr, int *valp);
Jeff Garzik47906542007-11-23 21:23:36 -05001016int netxen_rom_fast_read_words(struct netxen_adapter *adapter, int addr,
Amit S. Kale27d2ab52007-02-05 07:40:49 -08001017 u8 *bytes, size_t size);
Jeff Garzik47906542007-11-23 21:23:36 -05001018int netxen_rom_fast_write_words(struct netxen_adapter *adapter, int addr,
Amit S. Kale27d2ab52007-02-05 07:40:49 -08001019 u8 *bytes, size_t size);
1020int netxen_flash_unlock(struct netxen_adapter *adapter);
1021int netxen_backup_crbinit(struct netxen_adapter *adapter);
1022int netxen_flash_erase_secondary(struct netxen_adapter *adapter);
1023int netxen_flash_erase_primary(struct netxen_adapter *adapter);
Amit S. Kalee45d9ab2007-02-09 05:49:08 -08001024void netxen_halt_pegs(struct netxen_adapter *adapter);
Amit S. Kale27d2ab52007-02-05 07:40:49 -08001025
Amit S. Kalecb8011a2006-11-29 09:00:10 -08001026int netxen_rom_se(struct netxen_adapter *adapter, int addr);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001027
1028/* Functions from netxen_nic_isr.c */
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001029void netxen_initialize_adapter_sw(struct netxen_adapter *adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001030void netxen_initialize_adapter_ops(struct netxen_adapter *adapter);
1031int netxen_init_firmware(struct netxen_adapter *adapter);
1032void netxen_free_hw_resources(struct netxen_adapter *adapter);
1033void netxen_tso_check(struct netxen_adapter *adapter,
1034 struct cmd_desc_type0 *desc, struct sk_buff *skb);
1035int netxen_nic_hw_resources(struct netxen_adapter *adapter);
1036void netxen_nic_clear_stats(struct netxen_adapter *adapter);
David Howells6d5aefb2006-12-05 19:36:26 +00001037void netxen_watchdog_task(struct work_struct *work);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001038void netxen_post_rx_buffers(struct netxen_adapter *adapter, u32 ctx,
1039 u32 ringid);
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001040int netxen_process_cmd_ring(struct netxen_adapter *adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001041u32 netxen_process_rcv_ring(struct netxen_adapter *adapter, int ctx, int max);
1042void netxen_nic_set_multi(struct net_device *netdev);
1043int netxen_nic_change_mtu(struct net_device *netdev, int new_mtu);
1044int netxen_nic_set_mac(struct net_device *netdev, void *p);
1045struct net_device_stats *netxen_nic_get_stats(struct net_device *netdev);
1046
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001047
Amit S. Kalecb8011a2006-11-29 09:00:10 -08001048/*
1049 * NetXen Board information
1050 */
1051
1052#define NETXEN_MAX_SHORT_NAME 16
Amit S. Kale71bd7872006-12-01 05:36:22 -08001053struct netxen_brdinfo {
Amit S. Kalecb8011a2006-11-29 09:00:10 -08001054 netxen_brdtype_t brdtype; /* type of board */
1055 long ports; /* max no of physical ports */
1056 char short_name[NETXEN_MAX_SHORT_NAME];
Amit S. Kale71bd7872006-12-01 05:36:22 -08001057};
Amit S. Kalecb8011a2006-11-29 09:00:10 -08001058
Amit S. Kale71bd7872006-12-01 05:36:22 -08001059static const struct netxen_brdinfo netxen_boards[] = {
Amit S. Kalecb8011a2006-11-29 09:00:10 -08001060 {NETXEN_BRDTYPE_P2_SB31_10G_CX4, 1, "XGb CX4"},
1061 {NETXEN_BRDTYPE_P2_SB31_10G_HMEZ, 1, "XGb HMEZ"},
1062 {NETXEN_BRDTYPE_P2_SB31_10G_IMEZ, 2, "XGb IMEZ"},
1063 {NETXEN_BRDTYPE_P2_SB31_10G, 1, "XGb XFP"},
1064 {NETXEN_BRDTYPE_P2_SB35_4G, 4, "Quad Gb"},
1065 {NETXEN_BRDTYPE_P2_SB31_2G, 2, "Dual Gb"},
1066};
1067
Denis Chengff8ac602007-09-02 18:30:18 +08001068#define NUM_SUPPORTED_BOARDS ARRAY_SIZE(netxen_boards)
Amit S. Kalecb8011a2006-11-29 09:00:10 -08001069
Amit S. Kalecb8011a2006-11-29 09:00:10 -08001070static inline void get_brd_name_by_type(u32 type, char *name)
1071{
1072 int i, found = 0;
1073 for (i = 0; i < NUM_SUPPORTED_BOARDS; ++i) {
1074 if (netxen_boards[i].brdtype == type) {
1075 strcpy(name, netxen_boards[i].short_name);
1076 found = 1;
1077 break;
1078 }
1079
1080 }
1081 if (!found)
1082 name = "Unknown";
1083}
1084
Dhananjay Phadke96acb6e2007-07-02 09:37:57 +05301085static inline int
1086dma_watchdog_shutdown_request(struct netxen_adapter *adapter)
1087{
1088 u32 ctrl;
1089
1090 /* check if already inactive */
1091 if (netxen_nic_hw_read_wx(adapter,
1092 NETXEN_CAM_RAM(NETXEN_CAM_RAM_DMA_WATCHDOG_CTRL), &ctrl, 4))
1093 printk(KERN_ERR "failed to read dma watchdog status\n");
1094
1095 if (netxen_get_dma_watchdog_enabled(ctrl) == 0)
1096 return 1;
1097
1098 /* Send the disable request */
1099 netxen_set_dma_watchdog_disable_req(ctrl);
1100 netxen_crb_writelit_adapter(adapter,
1101 NETXEN_CAM_RAM(NETXEN_CAM_RAM_DMA_WATCHDOG_CTRL), ctrl);
1102
1103 return 0;
1104}
1105
1106static inline int
1107dma_watchdog_shutdown_poll_result(struct netxen_adapter *adapter)
1108{
1109 u32 ctrl;
1110
1111 if (netxen_nic_hw_read_wx(adapter,
1112 NETXEN_CAM_RAM(NETXEN_CAM_RAM_DMA_WATCHDOG_CTRL), &ctrl, 4))
1113 printk(KERN_ERR "failed to read dma watchdog status\n");
1114
dhananjay@netxen.comceded322007-07-19 14:41:09 +05301115 return (netxen_get_dma_watchdog_enabled(ctrl) == 0);
Dhananjay Phadke96acb6e2007-07-02 09:37:57 +05301116}
1117
1118static inline int
1119dma_watchdog_wakeup(struct netxen_adapter *adapter)
1120{
1121 u32 ctrl;
1122
1123 if (netxen_nic_hw_read_wx(adapter,
1124 NETXEN_CAM_RAM(NETXEN_CAM_RAM_DMA_WATCHDOG_CTRL), &ctrl, 4))
1125 printk(KERN_ERR "failed to read dma watchdog status\n");
1126
1127 if (netxen_get_dma_watchdog_enabled(ctrl))
1128 return 1;
1129
1130 /* send the wakeup request */
1131 netxen_set_dma_watchdog_enable_req(ctrl);
1132
1133 netxen_crb_writelit_adapter(adapter,
1134 NETXEN_CAM_RAM(NETXEN_CAM_RAM_DMA_WATCHDOG_CTRL), ctrl);
1135
1136 return 0;
1137}
1138
1139
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001140int netxen_is_flash_supported(struct netxen_adapter *adapter);
Al Virof305f782007-12-22 19:44:00 +00001141int netxen_get_flash_mac_addr(struct netxen_adapter *adapter, __le64 mac[]);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001142extern void netxen_change_ringparam(struct netxen_adapter *adapter);
1143extern int netxen_rom_fast_read(struct netxen_adapter *adapter, int addr,
1144 int *valp);
1145
1146extern struct ethtool_ops netxen_nic_ethtool_ops;
1147
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001148#endif /* __NETXEN_NIC_H_ */