blob: bcc551ef851968be8ce0a2dfbfb2290a2d20d6e1 [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 \
Dhananjay Phadke48bfd1e2008-07-21 19:44:06 -070087 (sizeof(struct netxen_rx_buffer) * rds_ring->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
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -0700114#define NX_P3_A0 0x30
115#define NX_P3_A2 0x30
116#define NX_P3_B0 0x40
117#define NX_P3_B1 0x41
118
119#define NX_IS_REVISION_P2(REVISION) (REVISION <= NX_P2_C1)
120#define NX_IS_REVISION_P3(REVISION) (REVISION >= NX_P3_A0)
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800121
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800122#define FIRST_PAGE_GROUP_START 0
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800123#define FIRST_PAGE_GROUP_END 0x100000
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800124
Mithlesh Thukral78403a92007-04-20 07:57:26 -0700125#define SECOND_PAGE_GROUP_START 0x6000000
126#define SECOND_PAGE_GROUP_END 0x68BC000
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800127
128#define THIRD_PAGE_GROUP_START 0x70E4000
129#define THIRD_PAGE_GROUP_END 0x8000000
130
131#define FIRST_PAGE_GROUP_SIZE FIRST_PAGE_GROUP_END - FIRST_PAGE_GROUP_START
132#define SECOND_PAGE_GROUP_SIZE SECOND_PAGE_GROUP_END - SECOND_PAGE_GROUP_START
133#define THIRD_PAGE_GROUP_SIZE THIRD_PAGE_GROUP_END - THIRD_PAGE_GROUP_START
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400134
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -0700135#define P2_MAX_MTU (8000)
136#define P3_MAX_MTU (9600)
137#define NX_ETHERMTU 1500
138#define NX_MAX_ETHERHDR 32 /* This contains some padding */
139
140#define NX_RX_NORMAL_BUF_MAX_LEN (NX_MAX_ETHERHDR + NX_ETHERMTU)
141#define NX_P2_RX_JUMBO_BUF_MAX_LEN (NX_MAX_ETHERHDR + P2_MAX_MTU)
142#define NX_P3_RX_JUMBO_BUF_MAX_LEN (NX_MAX_ETHERHDR + P3_MAX_MTU)
Dhananjay Phadked9e651b2008-07-21 19:44:08 -0700143#define NX_CT_DEFAULT_RX_BUF_LEN 2048
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -0700144
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800145#define MAX_RX_BUFFER_LENGTH 1760
Amit S. Kalebd56c6b2006-12-18 05:54:36 -0800146#define MAX_RX_JUMBO_BUFFER_LENGTH 8062
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800147#define MAX_RX_LRO_BUFFER_LENGTH ((48*1024)-512)
148#define RX_DMA_MAP_LEN (MAX_RX_BUFFER_LENGTH - 2)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400149#define RX_JUMBO_DMA_MAP_LEN \
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800150 (MAX_RX_JUMBO_BUFFER_LENGTH - 2)
151#define RX_LRO_DMA_MAP_LEN (MAX_RX_LRO_BUFFER_LENGTH - 2)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400152
153/*
154 * Maximum number of ring contexts
155 */
156#define MAX_RING_CTX 1
157
158/* Opcodes to be used with the commands */
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -0700159#define TX_ETHER_PKT 0x01
160#define TX_TCP_PKT 0x02
161#define TX_UDP_PKT 0x03
162#define TX_IP_PKT 0x04
163#define TX_TCP_LSO 0x05
164#define TX_TCP_LSO6 0x06
165#define TX_IPSEC 0x07
166#define TX_IPSEC_CMD 0x0a
167#define TX_TCPV6_PKT 0x0b
168#define TX_UDPV6_PKT 0x0c
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400169
170/* The following opcodes are for internal consumption. */
171#define NETXEN_CONTROL_OP 0x10
172#define PEGNET_REQUEST 0x11
173
174#define MAX_NUM_CARDS 4
175
176#define MAX_BUFFERS_PER_CMD 32
177
178/*
179 * Following are the states of the Phantom. Phantom will set them and
180 * Host will read to check if the fields are correct.
181 */
182#define PHAN_INITIALIZE_START 0xff00
183#define PHAN_INITIALIZE_FAILED 0xffff
184#define PHAN_INITIALIZE_COMPLETE 0xff01
185
186/* Host writes the following to notify that it has done the init-handshake */
187#define PHAN_INITIALIZE_ACK 0xf00f
188
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800189#define NUM_RCV_DESC_RINGS 3 /* No of Rcv Descriptor contexts */
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400190
191/* descriptor types */
192#define RCV_DESC_NORMAL 0x01
193#define RCV_DESC_JUMBO 0x02
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800194#define RCV_DESC_LRO 0x04
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400195#define RCV_DESC_NORMAL_CTXID 0
196#define RCV_DESC_JUMBO_CTXID 1
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800197#define RCV_DESC_LRO_CTXID 2
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400198
199#define RCV_DESC_TYPE(ID) \
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800200 ((ID == RCV_DESC_JUMBO_CTXID) \
201 ? RCV_DESC_JUMBO \
202 : ((ID == RCV_DESC_LRO_CTXID) \
203 ? RCV_DESC_LRO : \
204 (RCV_DESC_NORMAL)))
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400205
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -0700206#define MAX_CMD_DESCRIPTORS 4096
Amit S. Kalebd56c6b2006-12-18 05:54:36 -0800207#define MAX_RCV_DESCRIPTORS 16384
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700208#define MAX_CMD_DESCRIPTORS_HOST (MAX_CMD_DESCRIPTORS / 4)
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700209#define MAX_RCV_DESCRIPTORS_1G (MAX_RCV_DESCRIPTORS / 4)
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -0700210#define MAX_RCV_DESCRIPTORS_10G 8192
Amit S. Kalebd56c6b2006-12-18 05:54:36 -0800211#define MAX_JUMBO_RCV_DESCRIPTORS 1024
212#define MAX_LRO_RCV_DESCRIPTORS 64
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400213#define MAX_RCVSTATUS_DESCRIPTORS MAX_RCV_DESCRIPTORS
214#define MAX_JUMBO_RCV_DESC MAX_JUMBO_RCV_DESCRIPTORS
215#define MAX_RCV_DESC MAX_RCV_DESCRIPTORS
216#define MAX_RCVSTATUS_DESC MAX_RCV_DESCRIPTORS
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400217#define MAX_EPG_DESCRIPTORS (MAX_CMD_DESCRIPTORS * 8)
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800218#define NUM_RCV_DESC (MAX_RCV_DESC + MAX_JUMBO_RCV_DESCRIPTORS + \
219 MAX_LRO_RCV_DESCRIPTORS)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400220#define MIN_TX_COUNT 4096
221#define MIN_RX_COUNT 4096
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800222#define NETXEN_CTX_SIGNATURE 0xdee0
223#define NETXEN_RCV_PRODUCER(ringid) (ringid)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400224#define MAX_FRAME_SIZE 0x10000 /* 64K MAX size for LSO */
225
226#define PHAN_PEG_RCV_INITIALIZED 0xff01
227#define PHAN_PEG_RCV_START_INITIALIZE 0xff00
228
229#define get_next_index(index, length) \
230 (((index) + 1) & ((length) - 1))
231
232#define get_index_range(index,length,count) \
233 (((index) + (count)) & ((length) - 1))
234
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800235#define MPORT_SINGLE_FUNCTION_MODE 0x1111
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700236#define MPORT_MULTI_FUNCTION_MODE 0x2222
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800237
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700238#include "netxen_nic_phan_reg.h"
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800239
240/*
241 * NetXen host-peg signal message structure
242 *
243 * Bit 0-1 : peg_id => 0x2 for tx and 01 for rx
244 * Bit 2 : priv_id => must be 1
245 * Bit 3-17 : count => for doorbell
246 * Bit 18-27 : ctx_id => Context id
247 * Bit 28-31 : opcode
248 */
249
250typedef u32 netxen_ctx_msg;
251
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800252#define netxen_set_msg_peg_id(config_word, val) \
Al Viroa608ab9c2007-01-02 10:39:10 +0000253 ((config_word) &= ~3, (config_word) |= val & 3)
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800254#define netxen_set_msg_privid(config_word) \
Al Viroa608ab9c2007-01-02 10:39:10 +0000255 ((config_word) |= 1 << 2)
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800256#define netxen_set_msg_count(config_word, val) \
Al Viroa608ab9c2007-01-02 10:39:10 +0000257 ((config_word) &= ~(0x7fff<<3), (config_word) |= (val & 0x7fff) << 3)
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800258#define netxen_set_msg_ctxid(config_word, val) \
Al Viroa608ab9c2007-01-02 10:39:10 +0000259 ((config_word) &= ~(0x3ff<<18), (config_word) |= (val & 0x3ff) << 18)
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800260#define netxen_set_msg_opcode(config_word, val) \
Amit S. Kale82581172007-02-12 04:33:38 -0800261 ((config_word) &= ~(0xf<<28), (config_word) |= (val & 0xf) << 28)
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800262
263struct netxen_rcv_context {
Al Viroa608ab9c2007-01-02 10:39:10 +0000264 __le64 rcv_ring_addr;
265 __le32 rcv_ring_size;
266 __le32 rsrvd;
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800267};
268
269struct netxen_ring_ctx {
270
271 /* one command ring */
Al Viroa608ab9c2007-01-02 10:39:10 +0000272 __le64 cmd_consumer_offset;
273 __le64 cmd_ring_addr;
274 __le32 cmd_ring_size;
275 __le32 rsrvd;
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800276
277 /* three receive rings */
278 struct netxen_rcv_context rcv_ctx[3];
279
280 /* one status ring */
Al Viroa608ab9c2007-01-02 10:39:10 +0000281 __le64 sts_ring_addr;
282 __le32 sts_ring_size;
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800283
Al Viroa608ab9c2007-01-02 10:39:10 +0000284 __le32 ctx_id;
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800285} __attribute__ ((aligned(64)));
286
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400287/*
288 * Following data structures describe the descriptors that will be used.
289 * Added fileds of tcpHdrSize and ipHdrSize, The driver needs to do it only when
290 * we are doing LSO (above the 1500 size packet) only.
291 */
292
293/*
294 * The size of reference handle been changed to 16 bits to pass the MSS fields
295 * for the LSO packet
296 */
297
298#define FLAGS_CHECKSUM_ENABLED 0x01
299#define FLAGS_LSO_ENABLED 0x02
300#define FLAGS_IPSEC_SA_ADD 0x04
301#define FLAGS_IPSEC_SA_DELETE 0x08
302#define FLAGS_VLAN_TAGGED 0x10
303
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800304#define netxen_set_cmd_desc_port(cmd_desc, var) \
305 ((cmd_desc)->port_ctxid |= ((var) & 0x0F))
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700306#define netxen_set_cmd_desc_ctxid(cmd_desc, var) \
Dhananjay Phadke48bfd1e2008-07-21 19:44:06 -0700307 ((cmd_desc)->port_ctxid |= ((var) << 4 & 0xF0))
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400308
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800309#define netxen_set_cmd_desc_flags(cmd_desc, val) \
Dhananjay Phadke5dc16262007-12-31 10:08:57 -0800310 (cmd_desc)->flags_opcode = ((cmd_desc)->flags_opcode & \
311 ~cpu_to_le16(0x7f)) | cpu_to_le16((val) & 0x7f)
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800312#define netxen_set_cmd_desc_opcode(cmd_desc, val) \
Dhananjay Phadke5dc16262007-12-31 10:08:57 -0800313 (cmd_desc)->flags_opcode = ((cmd_desc)->flags_opcode & \
314 ~cpu_to_le16((u16)0x3f << 7)) | cpu_to_le16(((val) & 0x3f) << 7)
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800315
316#define netxen_set_cmd_desc_num_of_buff(cmd_desc, val) \
Dhananjay Phadke5dc16262007-12-31 10:08:57 -0800317 (cmd_desc)->num_of_buffers_total_length = \
318 ((cmd_desc)->num_of_buffers_total_length & \
319 ~cpu_to_le32(0xff)) | cpu_to_le32((val) & 0xff)
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800320#define netxen_set_cmd_desc_totallength(cmd_desc, val) \
Dhananjay Phadke5dc16262007-12-31 10:08:57 -0800321 (cmd_desc)->num_of_buffers_total_length = \
322 ((cmd_desc)->num_of_buffers_total_length & \
323 ~cpu_to_le32((u32)0xffffff << 8)) | \
324 cpu_to_le32(((val) & 0xffffff) << 8)
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800325
326#define netxen_get_cmd_desc_opcode(cmd_desc) \
Dhananjay Phadke5dc16262007-12-31 10:08:57 -0800327 ((le16_to_cpu((cmd_desc)->flags_opcode) >> 7) & 0x003f)
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800328#define netxen_get_cmd_desc_totallength(cmd_desc) \
Dhananjay Phadke5dc16262007-12-31 10:08:57 -0800329 ((le32_to_cpu((cmd_desc)->num_of_buffers_total_length) >> 8) & 0xffffff)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400330
331struct cmd_desc_type0 {
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800332 u8 tcp_hdr_offset; /* For LSO only */
333 u8 ip_hdr_offset; /* For LSO only */
334 /* Bit pattern: 0-6 flags, 7-12 opcode, 13-15 unused */
Al Viroa608ab9c2007-01-02 10:39:10 +0000335 __le16 flags_opcode;
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800336 /* Bit pattern: 0-7 total number of segments,
337 8-31 Total size of the packet */
Al Viroa608ab9c2007-01-02 10:39:10 +0000338 __le32 num_of_buffers_total_length;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400339 union {
340 struct {
Al Viroa608ab9c2007-01-02 10:39:10 +0000341 __le32 addr_low_part2;
342 __le32 addr_high_part2;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400343 };
Al Viroa608ab9c2007-01-02 10:39:10 +0000344 __le64 addr_buffer2;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400345 };
346
Al Viroa608ab9c2007-01-02 10:39:10 +0000347 __le16 reference_handle; /* changed to u16 to add mss */
348 __le16 mss; /* passed by NDIS_PACKET for LSO */
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400349 /* Bit pattern 0-3 port, 0-3 ctx id */
350 u8 port_ctxid;
351 u8 total_hdr_length; /* LSO only : MAC+IP+TCP Hdr size */
Al Viroa608ab9c2007-01-02 10:39:10 +0000352 __le16 conn_id; /* IPSec offoad only */
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400353
354 union {
355 struct {
Al Viroa608ab9c2007-01-02 10:39:10 +0000356 __le32 addr_low_part3;
357 __le32 addr_high_part3;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400358 };
Al Viroa608ab9c2007-01-02 10:39:10 +0000359 __le64 addr_buffer3;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400360 };
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400361 union {
362 struct {
Al Viroa608ab9c2007-01-02 10:39:10 +0000363 __le32 addr_low_part1;
364 __le32 addr_high_part1;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400365 };
Al Viroa608ab9c2007-01-02 10:39:10 +0000366 __le64 addr_buffer1;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400367 };
368
Al Viroa608ab9c2007-01-02 10:39:10 +0000369 __le16 buffer1_length;
370 __le16 buffer2_length;
371 __le16 buffer3_length;
372 __le16 buffer4_length;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400373
374 union {
375 struct {
Al Viroa608ab9c2007-01-02 10:39:10 +0000376 __le32 addr_low_part4;
377 __le32 addr_high_part4;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400378 };
Al Viroa608ab9c2007-01-02 10:39:10 +0000379 __le64 addr_buffer4;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400380 };
381
Al Viroa608ab9c2007-01-02 10:39:10 +0000382 __le64 unused;
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800383
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400384} __attribute__ ((aligned(64)));
385
386/* Note: sizeof(rcv_desc) should always be a mutliple of 2 */
387struct rcv_desc {
Al Viroa608ab9c2007-01-02 10:39:10 +0000388 __le16 reference_handle;
389 __le16 reserved;
390 __le32 buffer_length; /* allocated buffer length (usually 2K) */
391 __le64 addr_buffer;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400392};
393
394/* opcode field in status_desc */
Dhananjay Phadked9e651b2008-07-21 19:44:08 -0700395#define NETXEN_NIC_RXPKT_DESC 0x04
396#define NETXEN_OLD_RXPKT_DESC 0x3f
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400397
398/* for status field in status_desc */
399#define STATUS_NEED_CKSUM (1)
400#define STATUS_CKSUM_OK (2)
401
402/* owner bits of status_desc */
403#define STATUS_OWNER_HOST (0x1)
404#define STATUS_OWNER_PHANTOM (0x2)
405
406#define NETXEN_PROT_IP (1)
407#define NETXEN_PROT_UNKNOWN (0)
408
409/* Note: sizeof(status_desc) should always be a mutliple of 2 */
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800410
411#define netxen_get_sts_desc_lro_cnt(status_desc) \
412 ((status_desc)->lro & 0x7F)
413#define netxen_get_sts_desc_lro_last_frag(status_desc) \
414 (((status_desc)->lro & 0x80) >> 7)
415
Dhananjay Phadke5dc16262007-12-31 10:08:57 -0800416#define netxen_get_sts_port(sts_data) \
417 ((sts_data) & 0x0F)
418#define netxen_get_sts_status(sts_data) \
419 (((sts_data) >> 4) & 0x0F)
420#define netxen_get_sts_type(sts_data) \
421 (((sts_data) >> 8) & 0x0F)
422#define netxen_get_sts_totallength(sts_data) \
423 (((sts_data) >> 12) & 0xFFFF)
424#define netxen_get_sts_refhandle(sts_data) \
425 (((sts_data) >> 28) & 0xFFFF)
426#define netxen_get_sts_prot(sts_data) \
427 (((sts_data) >> 44) & 0x0F)
Dhananjay Phadked9e651b2008-07-21 19:44:08 -0700428#define netxen_get_sts_pkt_offset(sts_data) \
429 (((sts_data) >> 48) & 0x1F)
Dhananjay Phadke5dc16262007-12-31 10:08:57 -0800430#define netxen_get_sts_opcode(sts_data) \
431 (((sts_data) >> 58) & 0x03F)
432
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800433#define netxen_get_sts_owner(status_desc) \
Al Viroa608ab9c2007-01-02 10:39:10 +0000434 ((le64_to_cpu((status_desc)->status_desc_data) >> 56) & 0x03)
Dhananjay Phadke5dc16262007-12-31 10:08:57 -0800435#define netxen_set_sts_owner(status_desc, val) { \
436 (status_desc)->status_desc_data = \
437 ((status_desc)->status_desc_data & \
438 ~cpu_to_le64(0x3ULL << 56)) | \
439 cpu_to_le64((u64)((val) & 0x3) << 56); \
440}
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400441
442struct status_desc {
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800443 /* Bit pattern: 0-3 port, 4-7 status, 8-11 type, 12-27 total_length
Dhananjay Phadked9e651b2008-07-21 19:44:08 -0700444 28-43 reference_handle, 44-47 protocol, 48-52 pkt_offset
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800445 53-55 desc_cnt, 56-57 owner, 58-63 opcode
446 */
Al Viroa608ab9c2007-01-02 10:39:10 +0000447 __le64 status_desc_data;
Dhananjay Phadked9e651b2008-07-21 19:44:08 -0700448 union {
449 struct {
450 __le32 hash_value;
451 u8 hash_type;
452 u8 msg_type;
453 u8 unused;
454 union {
455 /* Bit pattern: 0-6 lro_count indicates frag
456 * sequence, 7 last_frag indicates last frag
457 */
458 u8 lro;
459
460 /* chained buffers */
461 u8 nr_frags;
462 };
463 };
464 struct {
465 __le16 frag_handles[4];
466 };
467 };
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700468} __attribute__ ((aligned(16)));
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400469
470enum {
471 NETXEN_RCV_PEG_0 = 0,
472 NETXEN_RCV_PEG_1
473};
474/* The version of the main data structure */
475#define NETXEN_BDINFO_VERSION 1
476
477/* Magic number to let user know flash is programmed */
478#define NETXEN_BDINFO_MAGIC 0x12345678
479
480/* Max number of Gig ports on a Phantom board */
481#define NETXEN_MAX_PORTS 4
482
483typedef enum {
484 NETXEN_BRDTYPE_P1_BD = 0x0000,
485 NETXEN_BRDTYPE_P1_SB = 0x0001,
486 NETXEN_BRDTYPE_P1_SMAX = 0x0002,
487 NETXEN_BRDTYPE_P1_SOCK = 0x0003,
488
489 NETXEN_BRDTYPE_P2_SOCK_31 = 0x0008,
490 NETXEN_BRDTYPE_P2_SOCK_35 = 0x0009,
491 NETXEN_BRDTYPE_P2_SB35_4G = 0x000a,
492 NETXEN_BRDTYPE_P2_SB31_10G = 0x000b,
493 NETXEN_BRDTYPE_P2_SB31_2G = 0x000c,
494
495 NETXEN_BRDTYPE_P2_SB31_10G_IMEZ = 0x000d,
496 NETXEN_BRDTYPE_P2_SB31_10G_HMEZ = 0x000e,
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -0700497 NETXEN_BRDTYPE_P2_SB31_10G_CX4 = 0x000f,
498
499 NETXEN_BRDTYPE_P3_REF_QG = 0x0021,
500 NETXEN_BRDTYPE_P3_HMEZ = 0x0022,
501 NETXEN_BRDTYPE_P3_10G_CX4_LP = 0x0023,
502 NETXEN_BRDTYPE_P3_4_GB = 0x0024,
503 NETXEN_BRDTYPE_P3_IMEZ = 0x0025,
504 NETXEN_BRDTYPE_P3_10G_SFP_PLUS = 0x0026,
505 NETXEN_BRDTYPE_P3_10000_BASE_T = 0x0027,
506 NETXEN_BRDTYPE_P3_XG_LOM = 0x0028,
507 NETXEN_BRDTYPE_P3_4_GB_MM = 0x0029,
508 NETXEN_BRDTYPE_P3_10G_CX4 = 0x0031,
509 NETXEN_BRDTYPE_P3_10G_XFP = 0x0032
510
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400511} netxen_brdtype_t;
512
513typedef enum {
514 NETXEN_BRDMFG_INVENTEC = 1
515} netxen_brdmfg;
516
517typedef enum {
518 MEM_ORG_128Mbx4 = 0x0, /* DDR1 only */
519 MEM_ORG_128Mbx8 = 0x1, /* DDR1 only */
520 MEM_ORG_128Mbx16 = 0x2, /* DDR1 only */
521 MEM_ORG_256Mbx4 = 0x3,
522 MEM_ORG_256Mbx8 = 0x4,
523 MEM_ORG_256Mbx16 = 0x5,
524 MEM_ORG_512Mbx4 = 0x6,
525 MEM_ORG_512Mbx8 = 0x7,
526 MEM_ORG_512Mbx16 = 0x8,
527 MEM_ORG_1Gbx4 = 0x9,
528 MEM_ORG_1Gbx8 = 0xa,
529 MEM_ORG_1Gbx16 = 0xb,
530 MEM_ORG_2Gbx4 = 0xc,
531 MEM_ORG_2Gbx8 = 0xd,
532 MEM_ORG_2Gbx16 = 0xe,
533 MEM_ORG_128Mbx32 = 0x10002, /* GDDR only */
534 MEM_ORG_256Mbx32 = 0x10005 /* GDDR only */
535} netxen_mn_mem_org_t;
536
537typedef enum {
538 MEM_ORG_512Kx36 = 0x0,
539 MEM_ORG_1Mx36 = 0x1,
540 MEM_ORG_2Mx36 = 0x2
541} netxen_sn_mem_org_t;
542
543typedef enum {
544 MEM_DEPTH_4MB = 0x1,
545 MEM_DEPTH_8MB = 0x2,
546 MEM_DEPTH_16MB = 0x3,
547 MEM_DEPTH_32MB = 0x4,
548 MEM_DEPTH_64MB = 0x5,
549 MEM_DEPTH_128MB = 0x6,
550 MEM_DEPTH_256MB = 0x7,
551 MEM_DEPTH_512MB = 0x8,
552 MEM_DEPTH_1GB = 0x9,
553 MEM_DEPTH_2GB = 0xa,
554 MEM_DEPTH_4GB = 0xb,
555 MEM_DEPTH_8GB = 0xc,
556 MEM_DEPTH_16GB = 0xd,
557 MEM_DEPTH_32GB = 0xe
558} netxen_mem_depth_t;
559
560struct netxen_board_info {
561 u32 header_version;
562
563 u32 board_mfg;
564 u32 board_type;
565 u32 board_num;
566 u32 chip_id;
567 u32 chip_minor;
568 u32 chip_major;
569 u32 chip_pkg;
570 u32 chip_lot;
571
572 u32 port_mask; /* available niu ports */
573 u32 peg_mask; /* available pegs */
574 u32 icache_ok; /* can we run with icache? */
575 u32 dcache_ok; /* can we run with dcache? */
576 u32 casper_ok;
577
578 u32 mac_addr_lo_0;
579 u32 mac_addr_lo_1;
580 u32 mac_addr_lo_2;
581 u32 mac_addr_lo_3;
582
583 /* MN-related config */
584 u32 mn_sync_mode; /* enable/ sync shift cclk/ sync shift mclk */
585 u32 mn_sync_shift_cclk;
586 u32 mn_sync_shift_mclk;
587 u32 mn_wb_en;
588 u32 mn_crystal_freq; /* in MHz */
589 u32 mn_speed; /* in MHz */
590 u32 mn_org;
591 u32 mn_depth;
592 u32 mn_ranks_0; /* ranks per slot */
593 u32 mn_ranks_1; /* ranks per slot */
594 u32 mn_rd_latency_0;
595 u32 mn_rd_latency_1;
596 u32 mn_rd_latency_2;
597 u32 mn_rd_latency_3;
598 u32 mn_rd_latency_4;
599 u32 mn_rd_latency_5;
600 u32 mn_rd_latency_6;
601 u32 mn_rd_latency_7;
602 u32 mn_rd_latency_8;
603 u32 mn_dll_val[18];
604 u32 mn_mode_reg; /* MIU DDR Mode Register */
605 u32 mn_ext_mode_reg; /* MIU DDR Extended Mode Register */
606 u32 mn_timing_0; /* MIU Memory Control Timing Rgister */
607 u32 mn_timing_1; /* MIU Extended Memory Ctrl Timing Register */
608 u32 mn_timing_2; /* MIU Extended Memory Ctrl Timing2 Register */
609
610 /* SN-related config */
611 u32 sn_sync_mode; /* enable/ sync shift cclk / sync shift mclk */
612 u32 sn_pt_mode; /* pass through mode */
613 u32 sn_ecc_en;
614 u32 sn_wb_en;
615 u32 sn_crystal_freq;
616 u32 sn_speed;
617 u32 sn_org;
618 u32 sn_depth;
619 u32 sn_dll_tap;
620 u32 sn_rd_latency;
621
622 u32 mac_addr_hi_0;
623 u32 mac_addr_hi_1;
624 u32 mac_addr_hi_2;
625 u32 mac_addr_hi_3;
626
627 u32 magic; /* indicates flash has been initialized */
628
629 u32 mn_rdimm;
630 u32 mn_dll_override;
631
632};
633
634#define FLASH_NUM_PORTS (4)
635
636struct netxen_flash_mac_addr {
637 u32 flash_addr[32];
638};
639
640struct netxen_user_old_info {
641 u8 flash_md5[16];
642 u8 crbinit_md5[16];
643 u8 brdcfg_md5[16];
644 /* bootloader */
645 u32 bootld_version;
646 u32 bootld_size;
647 u8 bootld_md5[16];
648 /* image */
649 u32 image_version;
650 u32 image_size;
651 u8 image_md5[16];
652 /* primary image status */
653 u32 primary_status;
654 u32 secondary_present;
655
656 /* MAC address , 4 ports */
657 struct netxen_flash_mac_addr mac_addr[FLASH_NUM_PORTS];
658};
659#define FLASH_NUM_MAC_PER_PORT 32
660struct netxen_user_info {
661 u8 flash_md5[16 * 64];
662 /* bootloader */
663 u32 bootld_version;
664 u32 bootld_size;
665 /* image */
666 u32 image_version;
667 u32 image_size;
668 /* primary image status */
669 u32 primary_status;
670 u32 secondary_present;
671
672 /* MAC address , 4 ports, 32 address per port */
673 u64 mac_addr[FLASH_NUM_PORTS * FLASH_NUM_MAC_PER_PORT];
674 u32 sub_sys_id;
675 u8 serial_num[32];
676
677 /* Any user defined data */
678};
679
680/*
681 * Flash Layout - new format.
682 */
683struct netxen_new_user_info {
684 u8 flash_md5[16 * 64];
685 /* bootloader */
686 u32 bootld_version;
687 u32 bootld_size;
688 /* image */
689 u32 image_version;
690 u32 image_size;
691 /* primary image status */
692 u32 primary_status;
693 u32 secondary_present;
694
695 /* MAC address , 4 ports, 32 address per port */
696 u64 mac_addr[FLASH_NUM_PORTS * FLASH_NUM_MAC_PER_PORT];
697 u32 sub_sys_id;
698 u8 serial_num[32];
699
700 /* Any user defined data */
701};
702
703#define SECONDARY_IMAGE_PRESENT 0xb3b4b5b6
704#define SECONDARY_IMAGE_ABSENT 0xffffffff
705#define PRIMARY_IMAGE_GOOD 0x5a5a5a5a
706#define PRIMARY_IMAGE_BAD 0xffffffff
707
708/* Flash memory map */
709typedef enum {
Mithlesh Thukral0d047612007-06-07 04:36:36 -0700710 NETXEN_CRBINIT_START = 0, /* Crbinit section */
711 NETXEN_BRDCFG_START = 0x4000, /* board config */
712 NETXEN_INITCODE_START = 0x6000, /* pegtune code */
713 NETXEN_BOOTLD_START = 0x10000, /* bootld */
714 NETXEN_IMAGE_START = 0x43000, /* compressed image */
715 NETXEN_SECONDARY_START = 0x200000, /* backup images */
716 NETXEN_PXE_START = 0x3E0000, /* user defined region */
717 NETXEN_USER_START = 0x3E8000, /* User defined region for new boards */
718 NETXEN_FIXED_START = 0x3F0000 /* backup of crbinit */
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400719} netxen_flash_map_t;
720
Mithlesh Thukral0d047612007-06-07 04:36:36 -0700721#define NETXEN_USER_START_OLD NETXEN_PXE_START /* for backward compatibility */
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400722
Mithlesh Thukral0d047612007-06-07 04:36:36 -0700723#define NETXEN_FLASH_START (NETXEN_CRBINIT_START)
724#define NETXEN_INIT_SECTOR (0)
725#define NETXEN_PRIMARY_START (NETXEN_BOOTLD_START)
726#define NETXEN_FLASH_CRBINIT_SIZE (0x4000)
727#define NETXEN_FLASH_BRDCFG_SIZE (sizeof(struct netxen_board_info))
728#define NETXEN_FLASH_USER_SIZE (sizeof(struct netxen_user_info)/sizeof(u32))
729#define NETXEN_FLASH_SECONDARY_SIZE (NETXEN_USER_START-NETXEN_SECONDARY_START)
730#define NETXEN_NUM_PRIMARY_SECTORS (0x20)
731#define NETXEN_NUM_CONFIG_SECTORS (1)
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800732#define PFX "NetXen: "
733extern char netxen_nic_driver_name[];
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400734
735/* Note: Make sure to not call this before adapter->port is valid */
736#if !defined(NETXEN_DEBUG)
737#define DPRINTK(klevel, fmt, args...) do { \
738 } while (0)
739#else
740#define DPRINTK(klevel, fmt, args...) do { \
741 printk(KERN_##klevel PFX "%s: %s: " fmt, __FUNCTION__,\
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700742 (adapter != NULL && adapter->netdev != NULL) ? \
743 adapter->netdev->name : NULL, \
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400744 ## args); } while(0)
745#endif
746
747/* Number of status descriptors to handle per interrupt */
748#define MAX_STATUS_HANDLE (128)
749
750/*
751 * netxen_skb_frag{} is to contain mapping info for each SG list. This
752 * has to be freed when DMA is complete. This is part of netxen_tx_buffer{}.
753 */
754struct netxen_skb_frag {
755 u64 dma;
756 u32 length;
757};
758
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700759#define _netxen_set_bits(config_word, start, bits, val) {\
760 unsigned long long __tmask = (((1ULL << (bits)) - 1) << (start));\
761 unsigned long long __tvalue = (val); \
762 (config_word) &= ~__tmask; \
763 (config_word) |= (((__tvalue) << (start)) & __tmask); \
764}
Jeff Garzik47906542007-11-23 21:23:36 -0500765
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700766#define _netxen_clear_bits(config_word, start, bits) {\
767 unsigned long long __tmask = (((1ULL << (bits)) - 1) << (start)); \
768 (config_word) &= ~__tmask; \
Jeff Garzik47906542007-11-23 21:23:36 -0500769}
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700770
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400771/* Following defines are for the state of the buffers */
772#define NETXEN_BUFFER_FREE 0
773#define NETXEN_BUFFER_BUSY 1
774
775/*
776 * There will be one netxen_buffer per skb packet. These will be
777 * used to save the dma info for pci_unmap_page()
778 */
779struct netxen_cmd_buffer {
780 struct sk_buff *skb;
781 struct netxen_skb_frag frag_array[MAX_BUFFERS_PER_CMD + 1];
782 u32 total_length;
783 u32 mss;
784 u16 port;
785 u8 cmd;
786 u8 frag_count;
787 unsigned long time_stamp;
788 u32 state;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400789};
790
791/* In rx_buffer, we do not need multiple fragments as is a single buffer */
792struct netxen_rx_buffer {
Dhananjay Phadked9e651b2008-07-21 19:44:08 -0700793 struct list_head list;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400794 struct sk_buff *skb;
795 u64 dma;
796 u16 ref_handle;
797 u16 state;
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800798 u32 lro_expected_frags;
799 u32 lro_current_frags;
800 u32 lro_length;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400801};
802
803/* Board types */
804#define NETXEN_NIC_GBE 0x01
805#define NETXEN_NIC_XGBE 0x02
806
807/*
808 * One hardware_context{} per adapter
809 * contains interrupt info as well shared hardware info.
810 */
811struct netxen_hardware_context {
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800812 void __iomem *pci_base0;
813 void __iomem *pci_base1;
814 void __iomem *pci_base2;
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700815 unsigned long first_page_group_end;
816 unsigned long first_page_group_start;
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800817 void __iomem *db_base;
818 unsigned long db_len;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700819 unsigned long pci_len0;
820
Dhananjay Phadke29566402008-07-21 19:44:04 -0700821 u8 cut_through;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700822 int qdr_sn_window;
823 int ddr_mn_window;
824 unsigned long mn_win_crb;
825 unsigned long ms_win_crb;
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800826
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400827 u8 revision_id;
828 u16 board_type;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400829 struct netxen_board_info boardcfg;
Dhananjay Phadkea97342f2008-07-21 19:44:05 -0700830 u32 linkup;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400831 /* Address of cmd ring in Phantom */
832 struct cmd_desc_type0 *cmd_desc_head;
833 dma_addr_t cmd_desc_phys_addr;
834 struct netxen_adapter *adapter;
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700835 int pci_func;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400836};
837
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800838#define RCV_RING_LRO RCV_DESC_LRO
839
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400840#define MINIMUM_ETHERNET_FRAME_SIZE 64 /* With FCS */
841#define ETHERNET_FCS_SIZE 4
842
843struct netxen_adapter_stats {
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700844 u64 rcvdbadskb;
845 u64 xmitcalled;
846 u64 xmitedframes;
847 u64 xmitfinished;
848 u64 badskblen;
849 u64 nocmddescriptor;
850 u64 polled;
Dhananjay Phadked1847a72008-03-17 19:59:51 -0700851 u64 rxdropped;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700852 u64 txdropped;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700853 u64 csummed;
854 u64 no_rcv;
855 u64 rxbytes;
856 u64 txbytes;
857 u64 ints;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400858};
859
860/*
861 * Rcv Descriptor Context. One such per Rcv Descriptor. There may
862 * be one Rcv Descriptor for normal packets, one for jumbo and may be others.
863 */
Dhananjay Phadke48bfd1e2008-07-21 19:44:06 -0700864struct nx_host_rds_ring {
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400865 u32 flags;
866 u32 producer;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400867 dma_addr_t phys_addr;
Dhananjay Phadke7830b222008-07-21 19:44:00 -0700868 u32 crb_rcv_producer; /* reg offset */
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400869 struct rcv_desc *desc_head; /* address of rx ring in Phantom */
870 u32 max_rx_desc_count;
871 u32 dma_size;
872 u32 skb_size;
873 struct netxen_rx_buffer *rx_buf_arr; /* rx buffers for receive */
Dhananjay Phadked9e651b2008-07-21 19:44:08 -0700874 struct list_head free_list;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400875 int begin_alloc;
876};
877
878/*
879 * Receive context. There is one such structure per instance of the
880 * receive processing. Any state information that is relevant to
881 * the receive, and is must be in this structure. The global data may be
882 * present elsewhere.
883 */
884struct netxen_recv_context {
Dhananjay Phadke48bfd1e2008-07-21 19:44:06 -0700885 u32 state;
886 u16 context_id;
887 u16 virt_port;
888
889 struct nx_host_rds_ring rds_rings[NUM_RCV_DESC_RINGS];
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400890 u32 status_rx_consumer;
Dhananjay Phadke7830b222008-07-21 19:44:00 -0700891 u32 crb_sts_consumer; /* reg offset */
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400892 dma_addr_t rcv_status_desc_phys_addr;
893 struct status_desc *rcv_status_desc_head;
894};
895
Dhananjay Phadke48bfd1e2008-07-21 19:44:06 -0700896/* New HW context creation */
897
898#define NX_OS_CRB_RETRY_COUNT 4000
899#define NX_CDRP_SIGNATURE_MAKE(pcifn, version) \
900 (((pcifn) & 0xff) | (((version) & 0xff) << 8) | (0xcafe << 16))
901
902#define NX_CDRP_CLEAR 0x00000000
903#define NX_CDRP_CMD_BIT 0x80000000
904
905/*
906 * All responses must have the NX_CDRP_CMD_BIT cleared
907 * in the crb NX_CDRP_CRB_OFFSET.
908 */
909#define NX_CDRP_FORM_RSP(rsp) (rsp)
910#define NX_CDRP_IS_RSP(rsp) (((rsp) & NX_CDRP_CMD_BIT) == 0)
911
912#define NX_CDRP_RSP_OK 0x00000001
913#define NX_CDRP_RSP_FAIL 0x00000002
914#define NX_CDRP_RSP_TIMEOUT 0x00000003
915
916/*
917 * All commands must have the NX_CDRP_CMD_BIT set in
918 * the crb NX_CDRP_CRB_OFFSET.
919 */
920#define NX_CDRP_FORM_CMD(cmd) (NX_CDRP_CMD_BIT | (cmd))
921#define NX_CDRP_IS_CMD(cmd) (((cmd) & NX_CDRP_CMD_BIT) != 0)
922
923#define NX_CDRP_CMD_SUBMIT_CAPABILITIES 0x00000001
924#define NX_CDRP_CMD_READ_MAX_RDS_PER_CTX 0x00000002
925#define NX_CDRP_CMD_READ_MAX_SDS_PER_CTX 0x00000003
926#define NX_CDRP_CMD_READ_MAX_RULES_PER_CTX 0x00000004
927#define NX_CDRP_CMD_READ_MAX_RX_CTX 0x00000005
928#define NX_CDRP_CMD_READ_MAX_TX_CTX 0x00000006
929#define NX_CDRP_CMD_CREATE_RX_CTX 0x00000007
930#define NX_CDRP_CMD_DESTROY_RX_CTX 0x00000008
931#define NX_CDRP_CMD_CREATE_TX_CTX 0x00000009
932#define NX_CDRP_CMD_DESTROY_TX_CTX 0x0000000a
933#define NX_CDRP_CMD_SETUP_STATISTICS 0x0000000e
934#define NX_CDRP_CMD_GET_STATISTICS 0x0000000f
935#define NX_CDRP_CMD_DELETE_STATISTICS 0x00000010
936#define NX_CDRP_CMD_SET_MTU 0x00000012
937#define NX_CDRP_CMD_MAX 0x00000013
938
939#define NX_RCODE_SUCCESS 0
940#define NX_RCODE_NO_HOST_MEM 1
941#define NX_RCODE_NO_HOST_RESOURCE 2
942#define NX_RCODE_NO_CARD_CRB 3
943#define NX_RCODE_NO_CARD_MEM 4
944#define NX_RCODE_NO_CARD_RESOURCE 5
945#define NX_RCODE_INVALID_ARGS 6
946#define NX_RCODE_INVALID_ACTION 7
947#define NX_RCODE_INVALID_STATE 8
948#define NX_RCODE_NOT_SUPPORTED 9
949#define NX_RCODE_NOT_PERMITTED 10
950#define NX_RCODE_NOT_READY 11
951#define NX_RCODE_DOES_NOT_EXIST 12
952#define NX_RCODE_ALREADY_EXISTS 13
953#define NX_RCODE_BAD_SIGNATURE 14
954#define NX_RCODE_CMD_NOT_IMPL 15
955#define NX_RCODE_CMD_INVALID 16
956#define NX_RCODE_TIMEOUT 17
957#define NX_RCODE_CMD_FAILED 18
958#define NX_RCODE_MAX_EXCEEDED 19
959#define NX_RCODE_MAX 20
960
961#define NX_DESTROY_CTX_RESET 0
962#define NX_DESTROY_CTX_D3_RESET 1
963#define NX_DESTROY_CTX_MAX 2
964
965/*
966 * Capabilities
967 */
968#define NX_CAP_BIT(class, bit) (1 << bit)
969#define NX_CAP0_LEGACY_CONTEXT NX_CAP_BIT(0, 0)
970#define NX_CAP0_MULTI_CONTEXT NX_CAP_BIT(0, 1)
971#define NX_CAP0_LEGACY_MN NX_CAP_BIT(0, 2)
972#define NX_CAP0_LEGACY_MS NX_CAP_BIT(0, 3)
973#define NX_CAP0_CUT_THROUGH NX_CAP_BIT(0, 4)
974#define NX_CAP0_LRO NX_CAP_BIT(0, 5)
975#define NX_CAP0_LSO NX_CAP_BIT(0, 6)
976#define NX_CAP0_JUMBO_CONTIGUOUS NX_CAP_BIT(0, 7)
977#define NX_CAP0_LRO_CONTIGUOUS NX_CAP_BIT(0, 8)
978
979/*
980 * Context state
981 */
982#define NX_HOST_CTX_STATE_FREED 0
983#define NX_HOST_CTX_STATE_ALLOCATED 1
984#define NX_HOST_CTX_STATE_ACTIVE 2
985#define NX_HOST_CTX_STATE_DISABLED 3
986#define NX_HOST_CTX_STATE_QUIESCED 4
987#define NX_HOST_CTX_STATE_MAX 5
988
989/*
990 * Rx context
991 */
992
993typedef struct {
994 u64 host_phys_addr; /* Ring base addr */
995 u32 ring_size; /* Ring entries */
996 u16 msi_index;
997 u16 rsvd; /* Padding */
998} nx_hostrq_sds_ring_t;
999
1000typedef struct {
1001 u64 host_phys_addr; /* Ring base addr */
1002 u64 buff_size; /* Packet buffer size */
1003 u32 ring_size; /* Ring entries */
1004 u32 ring_kind; /* Class of ring */
1005} nx_hostrq_rds_ring_t;
1006
1007typedef struct {
1008 u64 host_rsp_dma_addr; /* Response dma'd here */
1009 u32 capabilities[4]; /* Flag bit vector */
1010 u32 host_int_crb_mode; /* Interrupt crb usage */
1011 u32 host_rds_crb_mode; /* RDS crb usage */
1012 /* These ring offsets are relative to data[0] below */
1013 u32 rds_ring_offset; /* Offset to RDS config */
1014 u32 sds_ring_offset; /* Offset to SDS config */
1015 u16 num_rds_rings; /* Count of RDS rings */
1016 u16 num_sds_rings; /* Count of SDS rings */
1017 u16 rsvd1; /* Padding */
1018 u16 rsvd2; /* Padding */
1019 u8 reserved[128]; /* reserve space for future expansion*/
1020 /* MUST BE 64-bit aligned.
1021 The following is packed:
1022 - N hostrq_rds_rings
1023 - N hostrq_sds_rings */
1024 char data[0];
1025} nx_hostrq_rx_ctx_t;
1026
1027typedef struct {
1028 u32 host_producer_crb; /* Crb to use */
1029 u32 rsvd1; /* Padding */
1030} nx_cardrsp_rds_ring_t;
1031
1032typedef struct {
1033 u32 host_consumer_crb; /* Crb to use */
1034 u32 interrupt_crb; /* Crb to use */
1035} nx_cardrsp_sds_ring_t;
1036
1037typedef struct {
1038 /* These ring offsets are relative to data[0] below */
1039 u32 rds_ring_offset; /* Offset to RDS config */
1040 u32 sds_ring_offset; /* Offset to SDS config */
1041 u32 host_ctx_state; /* Starting State */
1042 u32 num_fn_per_port; /* How many PCI fn share the port */
1043 u16 num_rds_rings; /* Count of RDS rings */
1044 u16 num_sds_rings; /* Count of SDS rings */
1045 u16 context_id; /* Handle for context */
1046 u8 phys_port; /* Physical id of port */
1047 u8 virt_port; /* Virtual/Logical id of port */
1048 u8 reserved[128]; /* save space for future expansion */
1049 /* MUST BE 64-bit aligned.
1050 The following is packed:
1051 - N cardrsp_rds_rings
1052 - N cardrs_sds_rings */
1053 char data[0];
1054} nx_cardrsp_rx_ctx_t;
1055
1056#define SIZEOF_HOSTRQ_RX(HOSTRQ_RX, rds_rings, sds_rings) \
1057 (sizeof(HOSTRQ_RX) + \
1058 (rds_rings)*(sizeof(nx_hostrq_rds_ring_t)) + \
1059 (sds_rings)*(sizeof(nx_hostrq_sds_ring_t)))
1060
1061#define SIZEOF_CARDRSP_RX(CARDRSP_RX, rds_rings, sds_rings) \
1062 (sizeof(CARDRSP_RX) + \
1063 (rds_rings)*(sizeof(nx_cardrsp_rds_ring_t)) + \
1064 (sds_rings)*(sizeof(nx_cardrsp_sds_ring_t)))
1065
1066/*
1067 * Tx context
1068 */
1069
1070typedef struct {
1071 u64 host_phys_addr; /* Ring base addr */
1072 u32 ring_size; /* Ring entries */
1073 u32 rsvd; /* Padding */
1074} nx_hostrq_cds_ring_t;
1075
1076typedef struct {
1077 u64 host_rsp_dma_addr; /* Response dma'd here */
1078 u64 cmd_cons_dma_addr; /* */
1079 u64 dummy_dma_addr; /* */
1080 u32 capabilities[4]; /* Flag bit vector */
1081 u32 host_int_crb_mode; /* Interrupt crb usage */
1082 u32 rsvd1; /* Padding */
1083 u16 rsvd2; /* Padding */
1084 u16 interrupt_ctl;
1085 u16 msi_index;
1086 u16 rsvd3; /* Padding */
1087 nx_hostrq_cds_ring_t cds_ring; /* Desc of cds ring */
1088 u8 reserved[128]; /* future expansion */
1089} nx_hostrq_tx_ctx_t;
1090
1091typedef struct {
1092 u32 host_producer_crb; /* Crb to use */
1093 u32 interrupt_crb; /* Crb to use */
1094} nx_cardrsp_cds_ring_t;
1095
1096typedef struct {
1097 u32 host_ctx_state; /* Starting state */
1098 u16 context_id; /* Handle for context */
1099 u8 phys_port; /* Physical id of port */
1100 u8 virt_port; /* Virtual/Logical id of port */
1101 nx_cardrsp_cds_ring_t cds_ring; /* Card cds settings */
1102 u8 reserved[128]; /* future expansion */
1103} nx_cardrsp_tx_ctx_t;
1104
1105#define SIZEOF_HOSTRQ_TX(HOSTRQ_TX) (sizeof(HOSTRQ_TX))
1106#define SIZEOF_CARDRSP_TX(CARDRSP_TX) (sizeof(CARDRSP_TX))
1107
1108/* CRB */
1109
1110#define NX_HOST_RDS_CRB_MODE_UNIQUE 0
1111#define NX_HOST_RDS_CRB_MODE_SHARED 1
1112#define NX_HOST_RDS_CRB_MODE_CUSTOM 2
1113#define NX_HOST_RDS_CRB_MODE_MAX 3
1114
1115#define NX_HOST_INT_CRB_MODE_UNIQUE 0
1116#define NX_HOST_INT_CRB_MODE_SHARED 1
1117#define NX_HOST_INT_CRB_MODE_NORX 2
1118#define NX_HOST_INT_CRB_MODE_NOTX 3
1119#define NX_HOST_INT_CRB_MODE_NORXTX 4
1120
1121
1122/* MAC */
1123
1124#define MC_COUNT_P2 16
1125#define MC_COUNT_P3 38
1126
1127#define NETXEN_MAC_NOOP 0
1128#define NETXEN_MAC_ADD 1
1129#define NETXEN_MAC_DEL 2
1130
1131typedef struct nx_mac_list_s {
1132 struct nx_mac_list_s *next;
1133 uint8_t mac_addr[MAX_ADDR_LEN];
1134} nx_mac_list_t;
1135
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001136/*
1137 * Interrupt coalescing defaults. The defaults are for 1500 MTU. It is
1138 * adjusted based on configured MTU.
1139 */
1140#define NETXEN_DEFAULT_INTR_COALESCE_RX_TIME_US 3
1141#define NETXEN_DEFAULT_INTR_COALESCE_RX_PACKETS 256
1142#define NETXEN_DEFAULT_INTR_COALESCE_TX_PACKETS 64
1143#define NETXEN_DEFAULT_INTR_COALESCE_TX_TIME_US 4
1144
1145#define NETXEN_NIC_INTR_DEFAULT 0x04
1146
1147typedef union {
1148 struct {
1149 uint16_t rx_packets;
1150 uint16_t rx_time_us;
1151 uint16_t tx_packets;
1152 uint16_t tx_time_us;
1153 } data;
1154 uint64_t word;
1155} nx_nic_intr_coalesce_data_t;
1156
1157typedef struct {
1158 uint16_t stats_time_us;
1159 uint16_t rate_sample_time;
1160 uint16_t flags;
1161 uint16_t rsvd_1;
1162 uint32_t low_threshold;
1163 uint32_t high_threshold;
1164 nx_nic_intr_coalesce_data_t normal;
1165 nx_nic_intr_coalesce_data_t low;
1166 nx_nic_intr_coalesce_data_t high;
1167 nx_nic_intr_coalesce_data_t irq;
1168} nx_nic_intr_coalesce_t;
1169
Dhananjay Phadke48bfd1e2008-07-21 19:44:06 -07001170typedef struct {
1171 u64 qhdr;
1172 u64 req_hdr;
1173 u64 words[6];
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -07001174} nx_nic_req_t;
Dhananjay Phadke48bfd1e2008-07-21 19:44:06 -07001175
1176typedef struct {
1177 u8 op;
1178 u8 tag;
1179 u8 mac_addr[6];
1180} nx_mac_req_t;
1181
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -07001182#define MAX_PENDING_DESC_BLOCK_SIZE 64
Dhananjay Phadke48bfd1e2008-07-21 19:44:06 -07001183
Dhananjay Phadke29566402008-07-21 19:44:04 -07001184#define NETXEN_NIC_MSI_ENABLED 0x02
1185#define NETXEN_NIC_MSIX_ENABLED 0x04
1186#define NETXEN_IS_MSI_FAMILY(adapter) \
1187 ((adapter)->flags & (NETXEN_NIC_MSI_ENABLED | NETXEN_NIC_MSIX_ENABLED))
1188
1189#define MSIX_ENTRIES_PER_ADAPTER 8
1190#define NETXEN_MSIX_TBL_SPACE 8192
1191#define NETXEN_PCI_REG_MSIX_TBL 0x44
1192
1193#define NETXEN_DB_MAPSIZE_BYTES 0x1000
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001194
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001195#define NETXEN_NETDEV_WEIGHT 120
1196#define NETXEN_ADAPTER_UP_MAGIC 777
1197#define NETXEN_NIC_PEG_TUNE 0
1198
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001199struct netxen_dummy_dma {
1200 void *addr;
1201 dma_addr_t phys_addr;
1202};
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001203
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001204struct netxen_adapter {
1205 struct netxen_hardware_context ahw;
Jeff Garzik47906542007-11-23 21:23:36 -05001206
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001207 struct net_device *netdev;
1208 struct pci_dev *pdev;
Dhananjay Phadke29566402008-07-21 19:44:04 -07001209 int pci_using_dac;
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001210 struct napi_struct napi;
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001211 struct net_device_stats net_stats;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001212 int mtu;
1213 int portnum;
Dhananjay Phadke3276fba2008-06-15 22:59:44 -07001214 u8 physical_port;
Dhananjay Phadke48bfd1e2008-07-21 19:44:06 -07001215 u16 tx_context_id;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001216
Dhananjay Phadke623621b2008-07-21 19:44:01 -07001217 uint8_t mc_enabled;
1218 uint8_t max_mc_count;
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -07001219 nx_mac_list_t *mac_list;
Dhananjay Phadke623621b2008-07-21 19:44:01 -07001220
Dhananjay Phadke29566402008-07-21 19:44:04 -07001221 struct netxen_legacy_intr_set legacy_intr;
Dhananjay Phadke48bfd1e2008-07-21 19:44:06 -07001222 u32 crb_intr_mask;
Dhananjay Phadke29566402008-07-21 19:44:04 -07001223
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001224 struct work_struct watchdog_task;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001225 struct timer_list watchdog_timer;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001226 struct work_struct tx_timeout_task;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001227
1228 u32 curr_window;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001229 u32 crb_win;
1230 rwlock_t adapter_lock;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001231
Dhananjay Phadke29566402008-07-21 19:44:04 -07001232 uint64_t dma_mask;
1233
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001234 u32 cmd_producer;
Al Virof305f782007-12-22 19:44:00 +00001235 __le32 *cmd_consumer;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001236 u32 last_cmd_consumer;
Dhananjay Phadke7830b222008-07-21 19:44:00 -07001237 u32 crb_addr_cmd_producer;
1238 u32 crb_addr_cmd_consumer;
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001239
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001240 u32 max_tx_desc_count;
1241 u32 max_rx_desc_count;
1242 u32 max_jumbo_rx_desc_count;
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001243 u32 max_lro_rx_desc_count;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001244
Dhananjay Phadke48bfd1e2008-07-21 19:44:06 -07001245 int max_rds_rings;
1246
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001247 u32 flags;
1248 u32 irq;
1249 int driver_mismatch;
Amit S. Kalecb8011a2006-11-29 09:00:10 -08001250 u32 temp;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001251
Dhananjay Phadke29566402008-07-21 19:44:04 -07001252 u32 fw_major;
1253
1254 u8 msix_supported;
1255 u8 max_possible_rss_rings;
1256 struct msix_entry msix_entries[MSIX_ENTRIES_PER_ADAPTER];
1257
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001258 struct netxen_adapter_stats stats;
Jeff Garzik47906542007-11-23 21:23:36 -05001259
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001260 u16 link_speed;
1261 u16 link_duplex;
1262 u16 state;
1263 u16 link_autoneg;
Dhananjay Phadke200eef22007-09-03 10:33:35 +05301264 int rx_csum;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001265 int status;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001266
1267 struct netxen_cmd_buffer *cmd_buf_arr; /* Command buffers for xmit */
1268
1269 /*
1270 * Receive instances. These can be either one per port,
1271 * or one per peg, etc.
1272 */
1273 struct netxen_recv_context recv_ctx[MAX_RCV_CTX];
1274
1275 int is_up;
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001276 struct netxen_dummy_dma dummy_dma;
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001277 nx_nic_intr_coalesce_t coal;
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001278
1279 /* Context interface shared between card and host */
1280 struct netxen_ring_ctx *ctx_desc;
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001281 dma_addr_t ctx_desc_phys_addr;
dhananjay.phadke@gmail.com2d1a3bb2007-07-02 00:26:00 +05301282 int intr_scheme;
Dhananjay Phadke443be792008-03-17 19:59:48 -07001283 int msi_mode;
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -07001284 int (*enable_phy_interrupts) (struct netxen_adapter *);
1285 int (*disable_phy_interrupts) (struct netxen_adapter *);
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001286 int (*macaddr_set) (struct netxen_adapter *, netxen_ethernet_macaddr_t);
1287 int (*set_mtu) (struct netxen_adapter *, int);
1288 int (*set_promisc) (struct netxen_adapter *, netxen_niu_prom_mode_t);
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -07001289 int (*phy_read) (struct netxen_adapter *, long reg, u32 *);
1290 int (*phy_write) (struct netxen_adapter *, long reg, u32 val);
Amit S. Kale80922fb2006-12-04 09:18:00 -08001291 int (*init_port) (struct netxen_adapter *, int);
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001292 int (*stop_port) (struct netxen_adapter *);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001293
1294 int (*hw_read_wx)(struct netxen_adapter *, ulong, void *, int);
1295 int (*hw_write_wx)(struct netxen_adapter *, ulong, void *, int);
1296 int (*pci_mem_read)(struct netxen_adapter *, u64, void *, int);
1297 int (*pci_mem_write)(struct netxen_adapter *, u64, void *, int);
1298 int (*pci_write_immediate)(struct netxen_adapter *, u64, u32);
1299 u32 (*pci_read_immediate)(struct netxen_adapter *, u64);
1300 void (*pci_write_normalize)(struct netxen_adapter *, u64, u32);
1301 u32 (*pci_read_normalize)(struct netxen_adapter *, u64);
1302 unsigned long (*pci_set_window)(struct netxen_adapter *,
1303 unsigned long long);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001304}; /* netxen_adapter structure */
1305
Dhananjay Phadke96acb6e2007-07-02 09:37:57 +05301306/*
1307 * NetXen dma watchdog control structure
1308 *
1309 * Bit 0 : enabled => R/O: 1 watchdog active, 0 inactive
1310 * Bit 1 : disable_request => 1 req disable dma watchdog
1311 * Bit 2 : enable_request => 1 req enable dma watchdog
1312 * Bit 3-31 : unused
1313 */
1314
1315#define netxen_set_dma_watchdog_disable_req(config_word) \
1316 _netxen_set_bits(config_word, 1, 1, 1)
1317#define netxen_set_dma_watchdog_enable_req(config_word) \
1318 _netxen_set_bits(config_word, 2, 1, 1)
1319#define netxen_get_dma_watchdog_enabled(config_word) \
1320 ((config_word) & 0x1)
1321#define netxen_get_dma_watchdog_disabled(config_word) \
1322 (((config_word) >> 1) & 0x1)
1323
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001324/* Max number of xmit producer threads that can run simultaneously */
1325#define MAX_XMIT_PRODUCERS 16
1326
Amit S. Kalecb8011a2006-11-29 09:00:10 -08001327#define PCI_OFFSET_FIRST_RANGE(adapter, off) \
1328 ((adapter)->ahw.pci_base0 + (off))
1329#define PCI_OFFSET_SECOND_RANGE(adapter, off) \
1330 ((adapter)->ahw.pci_base1 + (off) - SECOND_PAGE_GROUP_START)
1331#define PCI_OFFSET_THIRD_RANGE(adapter, off) \
1332 ((adapter)->ahw.pci_base2 + (off) - THIRD_PAGE_GROUP_START)
1333
1334static inline void __iomem *pci_base_offset(struct netxen_adapter *adapter,
1335 unsigned long off)
1336{
1337 if ((off < FIRST_PAGE_GROUP_END) && (off >= FIRST_PAGE_GROUP_START)) {
1338 return (adapter->ahw.pci_base0 + off);
1339 } else if ((off < SECOND_PAGE_GROUP_END) &&
1340 (off >= SECOND_PAGE_GROUP_START)) {
1341 return (adapter->ahw.pci_base1 + off - SECOND_PAGE_GROUP_START);
1342 } else if ((off < THIRD_PAGE_GROUP_END) &&
1343 (off >= THIRD_PAGE_GROUP_START)) {
1344 return (adapter->ahw.pci_base2 + off - THIRD_PAGE_GROUP_START);
1345 }
1346 return NULL;
1347}
1348
1349static inline void __iomem *pci_base(struct netxen_adapter *adapter,
1350 unsigned long off)
1351{
1352 if ((off < FIRST_PAGE_GROUP_END) && (off >= FIRST_PAGE_GROUP_START)) {
1353 return adapter->ahw.pci_base0;
1354 } else if ((off < SECOND_PAGE_GROUP_END) &&
1355 (off >= SECOND_PAGE_GROUP_START)) {
1356 return adapter->ahw.pci_base1;
1357 } else if ((off < THIRD_PAGE_GROUP_END) &&
1358 (off >= THIRD_PAGE_GROUP_START)) {
1359 return adapter->ahw.pci_base2;
1360 }
1361 return NULL;
1362}
1363
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -07001364int netxen_niu_xgbe_enable_phy_interrupts(struct netxen_adapter *adapter);
1365int netxen_niu_gbe_enable_phy_interrupts(struct netxen_adapter *adapter);
1366int netxen_niu_xgbe_disable_phy_interrupts(struct netxen_adapter *adapter);
1367int netxen_niu_gbe_disable_phy_interrupts(struct netxen_adapter *adapter);
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -07001368int netxen_niu_gbe_phy_read(struct netxen_adapter *adapter, long reg,
Al Viroa608ab9c2007-01-02 10:39:10 +00001369 __u32 * readval);
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -07001370int netxen_niu_gbe_phy_write(struct netxen_adapter *adapter,
Al Viroa608ab9c2007-01-02 10:39:10 +00001371 long reg, __u32 val);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001372
1373/* Functions available from netxen_nic_hw.c */
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001374int netxen_nic_set_mtu_xgb(struct netxen_adapter *adapter, int new_mtu);
1375int netxen_nic_set_mtu_gb(struct netxen_adapter *adapter, int new_mtu);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001376void netxen_nic_reg_write(struct netxen_adapter *adapter, u64 off, u32 val);
1377int netxen_nic_reg_read(struct netxen_adapter *adapter, u64 off);
1378void netxen_nic_write_w0(struct netxen_adapter *adapter, u32 index, u32 value);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001379void netxen_nic_read_w0(struct netxen_adapter *adapter, u32 index, u32 *value);
1380void netxen_nic_write_w1(struct netxen_adapter *adapter, u32 index, u32 value);
1381void netxen_nic_read_w1(struct netxen_adapter *adapter, u32 index, u32 *value);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001382
1383int netxen_nic_get_board_info(struct netxen_adapter *adapter);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001384
1385int netxen_nic_hw_read_wx_128M(struct netxen_adapter *adapter,
1386 ulong off, void *data, int len);
1387int netxen_nic_hw_write_wx_128M(struct netxen_adapter *adapter,
1388 ulong off, void *data, int len);
1389int netxen_nic_pci_mem_read_128M(struct netxen_adapter *adapter,
1390 u64 off, void *data, int size);
1391int netxen_nic_pci_mem_write_128M(struct netxen_adapter *adapter,
1392 u64 off, void *data, int size);
1393int netxen_nic_pci_write_immediate_128M(struct netxen_adapter *adapter,
1394 u64 off, u32 data);
1395u32 netxen_nic_pci_read_immediate_128M(struct netxen_adapter *adapter, u64 off);
1396void netxen_nic_pci_write_normalize_128M(struct netxen_adapter *adapter,
1397 u64 off, u32 data);
1398u32 netxen_nic_pci_read_normalize_128M(struct netxen_adapter *adapter, u64 off);
1399unsigned long netxen_nic_pci_set_window_128M(struct netxen_adapter *adapter,
1400 unsigned long long addr);
1401void netxen_nic_pci_change_crbwindow_128M(struct netxen_adapter *adapter,
1402 u32 wndw);
1403
1404int netxen_nic_hw_read_wx_2M(struct netxen_adapter *adapter,
1405 ulong off, void *data, int len);
1406int netxen_nic_hw_write_wx_2M(struct netxen_adapter *adapter,
1407 ulong off, void *data, int len);
1408int netxen_nic_pci_mem_read_2M(struct netxen_adapter *adapter,
1409 u64 off, void *data, int size);
1410int netxen_nic_pci_mem_write_2M(struct netxen_adapter *adapter,
1411 u64 off, void *data, int size);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001412void netxen_crb_writelit_adapter(struct netxen_adapter *adapter,
1413 unsigned long off, int data);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001414int netxen_nic_pci_write_immediate_2M(struct netxen_adapter *adapter,
1415 u64 off, u32 data);
1416u32 netxen_nic_pci_read_immediate_2M(struct netxen_adapter *adapter, u64 off);
1417void netxen_nic_pci_write_normalize_2M(struct netxen_adapter *adapter,
1418 u64 off, u32 data);
1419u32 netxen_nic_pci_read_normalize_2M(struct netxen_adapter *adapter, u64 off);
1420unsigned long netxen_nic_pci_set_window_2M(struct netxen_adapter *adapter,
1421 unsigned long long addr);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001422
1423/* Functions from netxen_nic_init.c */
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001424void netxen_free_adapter_offload(struct netxen_adapter *adapter);
1425int netxen_initialize_adapter_offload(struct netxen_adapter *adapter);
Dhananjay Phadke96acb6e2007-07-02 09:37:57 +05301426int netxen_phantom_init(struct netxen_adapter *adapter, int pegtune_val);
Dhananjay Phadke29566402008-07-21 19:44:04 -07001427int netxen_receive_peg_ready(struct netxen_adapter *adapter);
Dhananjay Phadke96acb6e2007-07-02 09:37:57 +05301428int netxen_load_firmware(struct netxen_adapter *adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001429int netxen_pinit_from_rom(struct netxen_adapter *adapter, int verbose);
Dhananjay Phadke29566402008-07-21 19:44:04 -07001430
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001431int netxen_rom_fast_read(struct netxen_adapter *adapter, int addr, int *valp);
Jeff Garzik47906542007-11-23 21:23:36 -05001432int netxen_rom_fast_read_words(struct netxen_adapter *adapter, int addr,
Amit S. Kale27d2ab52007-02-05 07:40:49 -08001433 u8 *bytes, size_t size);
Jeff Garzik47906542007-11-23 21:23:36 -05001434int netxen_rom_fast_write_words(struct netxen_adapter *adapter, int addr,
Amit S. Kale27d2ab52007-02-05 07:40:49 -08001435 u8 *bytes, size_t size);
1436int netxen_flash_unlock(struct netxen_adapter *adapter);
1437int netxen_backup_crbinit(struct netxen_adapter *adapter);
1438int netxen_flash_erase_secondary(struct netxen_adapter *adapter);
1439int netxen_flash_erase_primary(struct netxen_adapter *adapter);
Amit S. Kalee45d9ab2007-02-09 05:49:08 -08001440void netxen_halt_pegs(struct netxen_adapter *adapter);
Amit S. Kale27d2ab52007-02-05 07:40:49 -08001441
Amit S. Kalecb8011a2006-11-29 09:00:10 -08001442int netxen_rom_se(struct netxen_adapter *adapter, int addr);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001443
Dhananjay Phadke29566402008-07-21 19:44:04 -07001444int netxen_alloc_sw_resources(struct netxen_adapter *adapter);
1445void netxen_free_sw_resources(struct netxen_adapter *adapter);
1446
1447int netxen_alloc_hw_resources(struct netxen_adapter *adapter);
1448void netxen_free_hw_resources(struct netxen_adapter *adapter);
1449
1450void netxen_release_rx_buffers(struct netxen_adapter *adapter);
1451void netxen_release_tx_buffers(struct netxen_adapter *adapter);
1452
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001453void netxen_initialize_adapter_ops(struct netxen_adapter *adapter);
1454int netxen_init_firmware(struct netxen_adapter *adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001455void netxen_tso_check(struct netxen_adapter *adapter,
1456 struct cmd_desc_type0 *desc, struct sk_buff *skb);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001457void netxen_nic_clear_stats(struct netxen_adapter *adapter);
David Howells6d5aefb2006-12-05 19:36:26 +00001458void netxen_watchdog_task(struct work_struct *work);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001459void netxen_post_rx_buffers(struct netxen_adapter *adapter, u32 ctx,
1460 u32 ringid);
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001461int netxen_process_cmd_ring(struct netxen_adapter *adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001462u32 netxen_process_rcv_ring(struct netxen_adapter *adapter, int ctx, int max);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -07001463void netxen_p2_nic_set_multi(struct net_device *netdev);
1464void netxen_p3_nic_set_multi(struct net_device *netdev);
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001465int netxen_config_intr_coalesce(struct netxen_adapter *adapter);
Dhananjay Phadke48bfd1e2008-07-21 19:44:06 -07001466
1467u32 nx_fw_cmd_set_mtu(struct netxen_adapter *adapter, u32 mtu);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001468int netxen_nic_change_mtu(struct net_device *netdev, int new_mtu);
Dhananjay Phadke48bfd1e2008-07-21 19:44:06 -07001469
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001470int netxen_nic_set_mac(struct net_device *netdev, void *p);
1471struct net_device_stats *netxen_nic_get_stats(struct net_device *netdev);
1472
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -07001473void netxen_nic_update_cmd_producer(struct netxen_adapter *adapter,
1474 uint32_t crb_producer);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001475
Amit S. Kalecb8011a2006-11-29 09:00:10 -08001476/*
1477 * NetXen Board information
1478 */
1479
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07001480#define NETXEN_MAX_SHORT_NAME 32
Amit S. Kale71bd7872006-12-01 05:36:22 -08001481struct netxen_brdinfo {
Amit S. Kalecb8011a2006-11-29 09:00:10 -08001482 netxen_brdtype_t brdtype; /* type of board */
1483 long ports; /* max no of physical ports */
1484 char short_name[NETXEN_MAX_SHORT_NAME];
Amit S. Kale71bd7872006-12-01 05:36:22 -08001485};
Amit S. Kalecb8011a2006-11-29 09:00:10 -08001486
Amit S. Kale71bd7872006-12-01 05:36:22 -08001487static const struct netxen_brdinfo netxen_boards[] = {
Amit S. Kalecb8011a2006-11-29 09:00:10 -08001488 {NETXEN_BRDTYPE_P2_SB31_10G_CX4, 1, "XGb CX4"},
1489 {NETXEN_BRDTYPE_P2_SB31_10G_HMEZ, 1, "XGb HMEZ"},
1490 {NETXEN_BRDTYPE_P2_SB31_10G_IMEZ, 2, "XGb IMEZ"},
1491 {NETXEN_BRDTYPE_P2_SB31_10G, 1, "XGb XFP"},
1492 {NETXEN_BRDTYPE_P2_SB35_4G, 4, "Quad Gb"},
1493 {NETXEN_BRDTYPE_P2_SB31_2G, 2, "Dual Gb"},
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07001494 {NETXEN_BRDTYPE_P3_REF_QG, 4, "Reference Quad Gig "},
1495 {NETXEN_BRDTYPE_P3_HMEZ, 2, "Dual XGb HMEZ"},
1496 {NETXEN_BRDTYPE_P3_10G_CX4_LP, 2, "Dual XGb CX4 LP"},
1497 {NETXEN_BRDTYPE_P3_4_GB, 4, "Quad Gig LP"},
1498 {NETXEN_BRDTYPE_P3_IMEZ, 2, "Dual XGb IMEZ"},
1499 {NETXEN_BRDTYPE_P3_10G_SFP_PLUS, 2, "Dual XGb SFP+ LP"},
1500 {NETXEN_BRDTYPE_P3_10000_BASE_T, 1, "XGB 10G BaseT LP"},
1501 {NETXEN_BRDTYPE_P3_XG_LOM, 2, "Dual XGb LOM"},
1502 {NETXEN_BRDTYPE_P3_4_GB_MM, 4, "Quad GB - March Madness"},
1503 {NETXEN_BRDTYPE_P3_10G_CX4, 2, "Reference Dual CX4 Option"},
1504 {NETXEN_BRDTYPE_P3_10G_XFP, 1, "Reference Single XFP Option"}
Amit S. Kalecb8011a2006-11-29 09:00:10 -08001505};
1506
Denis Chengff8ac602007-09-02 18:30:18 +08001507#define NUM_SUPPORTED_BOARDS ARRAY_SIZE(netxen_boards)
Amit S. Kalecb8011a2006-11-29 09:00:10 -08001508
Amit S. Kalecb8011a2006-11-29 09:00:10 -08001509static inline void get_brd_name_by_type(u32 type, char *name)
1510{
1511 int i, found = 0;
1512 for (i = 0; i < NUM_SUPPORTED_BOARDS; ++i) {
1513 if (netxen_boards[i].brdtype == type) {
1514 strcpy(name, netxen_boards[i].short_name);
1515 found = 1;
1516 break;
1517 }
1518
1519 }
1520 if (!found)
1521 name = "Unknown";
1522}
1523
Dhananjay Phadke96acb6e2007-07-02 09:37:57 +05301524static inline int
1525dma_watchdog_shutdown_request(struct netxen_adapter *adapter)
1526{
1527 u32 ctrl;
1528
1529 /* check if already inactive */
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001530 if (adapter->hw_read_wx(adapter,
Dhananjay Phadke96acb6e2007-07-02 09:37:57 +05301531 NETXEN_CAM_RAM(NETXEN_CAM_RAM_DMA_WATCHDOG_CTRL), &ctrl, 4))
1532 printk(KERN_ERR "failed to read dma watchdog status\n");
1533
1534 if (netxen_get_dma_watchdog_enabled(ctrl) == 0)
1535 return 1;
1536
1537 /* Send the disable request */
1538 netxen_set_dma_watchdog_disable_req(ctrl);
1539 netxen_crb_writelit_adapter(adapter,
1540 NETXEN_CAM_RAM(NETXEN_CAM_RAM_DMA_WATCHDOG_CTRL), ctrl);
1541
1542 return 0;
1543}
1544
1545static inline int
1546dma_watchdog_shutdown_poll_result(struct netxen_adapter *adapter)
1547{
1548 u32 ctrl;
1549
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001550 if (adapter->hw_read_wx(adapter,
Dhananjay Phadke96acb6e2007-07-02 09:37:57 +05301551 NETXEN_CAM_RAM(NETXEN_CAM_RAM_DMA_WATCHDOG_CTRL), &ctrl, 4))
1552 printk(KERN_ERR "failed to read dma watchdog status\n");
1553
dhananjay@netxen.comceded322007-07-19 14:41:09 +05301554 return (netxen_get_dma_watchdog_enabled(ctrl) == 0);
Dhananjay Phadke96acb6e2007-07-02 09:37:57 +05301555}
1556
1557static inline int
1558dma_watchdog_wakeup(struct netxen_adapter *adapter)
1559{
1560 u32 ctrl;
1561
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001562 if (adapter->hw_read_wx(adapter,
Dhananjay Phadke96acb6e2007-07-02 09:37:57 +05301563 NETXEN_CAM_RAM(NETXEN_CAM_RAM_DMA_WATCHDOG_CTRL), &ctrl, 4))
1564 printk(KERN_ERR "failed to read dma watchdog status\n");
1565
1566 if (netxen_get_dma_watchdog_enabled(ctrl))
1567 return 1;
1568
1569 /* send the wakeup request */
1570 netxen_set_dma_watchdog_enable_req(ctrl);
1571
1572 netxen_crb_writelit_adapter(adapter,
1573 NETXEN_CAM_RAM(NETXEN_CAM_RAM_DMA_WATCHDOG_CTRL), ctrl);
1574
1575 return 0;
1576}
1577
1578
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001579int netxen_is_flash_supported(struct netxen_adapter *adapter);
Al Virof305f782007-12-22 19:44:00 +00001580int netxen_get_flash_mac_addr(struct netxen_adapter *adapter, __le64 mac[]);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001581extern void netxen_change_ringparam(struct netxen_adapter *adapter);
1582extern int netxen_rom_fast_read(struct netxen_adapter *adapter, int addr,
1583 int *valp);
1584
1585extern struct ethtool_ops netxen_nic_ethtool_ops;
1586
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001587#endif /* __NETXEN_NIC_H_ */