diff options
author | Jeff Kirsher <jeffrey.t.kirsher@intel.com> | 2011-04-09 04:06:30 +0200 |
---|---|---|
committer | Jeff Kirsher <jeffrey.t.kirsher@intel.com> | 2011-08-11 05:03:49 +0200 |
commit | aa43c2158d5ae1dc76cccb08cd57a3ffd32c3825 (patch) | |
tree | cdb471f2b2440d551e634f9cbeacf1675daf3ba8 /drivers/net/netxen | |
parent | intel: Move the Intel wired LAN drivers (diff) | |
download | linux-aa43c2158d5ae1dc76cccb08cd57a3ffd32c3825.tar.xz linux-aa43c2158d5ae1dc76cccb08cd57a3ffd32c3825.zip |
qlogic: Move the QLogic drivers
Moves the QLogic drivers into drivers/net/ethernet/qlogic/ and
the necessary Kconfig and Makefile changes.
CC: Ron Mercer <ron.mercer@qlogic.com>
CC: Amit Kumar Salecha <amit.salecha@qlogic.com>
CC: Anirban Chakraborty <anirban.chakraborty@qlogic.com>
Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
Acked-by: Anirban Chakraborty <anirban.chakraborty@qlogic.com>
Diffstat (limited to 'drivers/net/netxen')
-rw-r--r-- | drivers/net/netxen/Makefile | 29 | ||||
-rw-r--r-- | drivers/net/netxen/netxen_nic.h | 1441 | ||||
-rw-r--r-- | drivers/net/netxen/netxen_nic_ctx.c | 793 | ||||
-rw-r--r-- | drivers/net/netxen/netxen_nic_ethtool.c | 835 | ||||
-rw-r--r-- | drivers/net/netxen/netxen_nic_hdr.h | 1050 | ||||
-rw-r--r-- | drivers/net/netxen/netxen_nic_hw.c | 1976 | ||||
-rw-r--r-- | drivers/net/netxen/netxen_nic_hw.h | 287 | ||||
-rw-r--r-- | drivers/net/netxen/netxen_nic_init.c | 1949 | ||||
-rw-r--r-- | drivers/net/netxen/netxen_nic_main.c | 3100 |
9 files changed, 0 insertions, 11460 deletions
diff --git a/drivers/net/netxen/Makefile b/drivers/net/netxen/Makefile deleted file mode 100644 index 861a0590b1f4..000000000000 --- a/drivers/net/netxen/Makefile +++ /dev/null @@ -1,29 +0,0 @@ -# Copyright (C) 2003 - 2009 NetXen, Inc. -# Copyright (C) 2009 - QLogic Corporation. -# All rights reserved. -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, -# MA 02111-1307, USA. -# -# The full GNU General Public License is included in this distribution -# in the file called "COPYING". -# -# - - -obj-$(CONFIG_NETXEN_NIC) := netxen_nic.o - -netxen_nic-y := netxen_nic_hw.o netxen_nic_main.o netxen_nic_init.o \ - netxen_nic_ethtool.o netxen_nic_ctx.o diff --git a/drivers/net/netxen/netxen_nic.h b/drivers/net/netxen/netxen_nic.h deleted file mode 100644 index 196b660e1d91..000000000000 --- a/drivers/net/netxen/netxen_nic.h +++ /dev/null @@ -1,1441 +0,0 @@ -/* - * Copyright (C) 2003 - 2009 NetXen, Inc. - * Copyright (C) 2009 - QLogic Corporation. - * All rights reserved. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, - * MA 02111-1307, USA. - * - * The full GNU General Public License is included in this distribution - * in the file called "COPYING". - * - */ - -#ifndef _NETXEN_NIC_H_ -#define _NETXEN_NIC_H_ - -#include <linux/module.h> -#include <linux/kernel.h> -#include <linux/types.h> -#include <linux/ioport.h> -#include <linux/pci.h> -#include <linux/netdevice.h> -#include <linux/etherdevice.h> -#include <linux/ip.h> -#include <linux/in.h> -#include <linux/tcp.h> -#include <linux/skbuff.h> -#include <linux/firmware.h> - -#include <linux/ethtool.h> -#include <linux/mii.h> -#include <linux/timer.h> - -#include <linux/vmalloc.h> - -#include <asm/io.h> -#include <asm/byteorder.h> - -#include "netxen_nic_hdr.h" -#include "netxen_nic_hw.h" - -#define _NETXEN_NIC_LINUX_MAJOR 4 -#define _NETXEN_NIC_LINUX_MINOR 0 -#define _NETXEN_NIC_LINUX_SUBVERSION 76 -#define NETXEN_NIC_LINUX_VERSIONID "4.0.76" - -#define NETXEN_VERSION_CODE(a, b, c) (((a) << 24) + ((b) << 16) + (c)) -#define _major(v) (((v) >> 24) & 0xff) -#define _minor(v) (((v) >> 16) & 0xff) -#define _build(v) ((v) & 0xffff) - -/* version in image has weird encoding: - * 7:0 - major - * 15:8 - minor - * 31:16 - build (little endian) - */ -#define NETXEN_DECODE_VERSION(v) \ - NETXEN_VERSION_CODE(((v) & 0xff), (((v) >> 8) & 0xff), ((v) >> 16)) - -#define NETXEN_NUM_FLASH_SECTORS (64) -#define NETXEN_FLASH_SECTOR_SIZE (64 * 1024) -#define NETXEN_FLASH_TOTAL_SIZE (NETXEN_NUM_FLASH_SECTORS \ - * NETXEN_FLASH_SECTOR_SIZE) - -#define RCV_DESC_RINGSIZE(rds_ring) \ - (sizeof(struct rcv_desc) * (rds_ring)->num_desc) -#define RCV_BUFF_RINGSIZE(rds_ring) \ - (sizeof(struct netxen_rx_buffer) * rds_ring->num_desc) -#define STATUS_DESC_RINGSIZE(sds_ring) \ - (sizeof(struct status_desc) * (sds_ring)->num_desc) -#define TX_BUFF_RINGSIZE(tx_ring) \ - (sizeof(struct netxen_cmd_buffer) * tx_ring->num_desc) -#define TX_DESC_RINGSIZE(tx_ring) \ - (sizeof(struct cmd_desc_type0) * tx_ring->num_desc) - -#define find_diff_among(a,b,range) ((a)<(b)?((b)-(a)):((b)+(range)-(a))) - -#define NETXEN_RCV_PRODUCER_OFFSET 0 -#define NETXEN_RCV_PEG_DB_ID 2 -#define NETXEN_HOST_DUMMY_DMA_SIZE 1024 -#define FLASH_SUCCESS 0 - -#define ADDR_IN_WINDOW1(off) \ - ((off > NETXEN_CRB_PCIX_HOST2) && (off < NETXEN_CRB_MAX)) ? 1 : 0 - -#define ADDR_IN_RANGE(addr, low, high) \ - (((addr) < (high)) && ((addr) >= (low))) - -/* - * normalize a 64MB crb address to 32MB PCI window - * To use NETXEN_CRB_NORMALIZE, window _must_ be set to 1 - */ -#define NETXEN_CRB_NORMAL(reg) \ - ((reg) - NETXEN_CRB_PCIX_HOST2 + NETXEN_CRB_PCIX_HOST) - -#define NETXEN_CRB_NORMALIZE(adapter, reg) \ - pci_base_offset(adapter, NETXEN_CRB_NORMAL(reg)) - -#define DB_NORMALIZE(adapter, off) \ - (adapter->ahw.db_base + (off)) - -#define NX_P2_C0 0x24 -#define NX_P2_C1 0x25 -#define NX_P3_A0 0x30 -#define NX_P3_A2 0x30 -#define NX_P3_B0 0x40 -#define NX_P3_B1 0x41 -#define NX_P3_B2 0x42 -#define NX_P3P_A0 0x50 - -#define NX_IS_REVISION_P2(REVISION) (REVISION <= NX_P2_C1) -#define NX_IS_REVISION_P3(REVISION) (REVISION >= NX_P3_A0) -#define NX_IS_REVISION_P3P(REVISION) (REVISION >= NX_P3P_A0) - -#define FIRST_PAGE_GROUP_START 0 -#define FIRST_PAGE_GROUP_END 0x100000 - -#define SECOND_PAGE_GROUP_START 0x6000000 -#define SECOND_PAGE_GROUP_END 0x68BC000 - -#define THIRD_PAGE_GROUP_START 0x70E4000 -#define THIRD_PAGE_GROUP_END 0x8000000 - -#define FIRST_PAGE_GROUP_SIZE FIRST_PAGE_GROUP_END - FIRST_PAGE_GROUP_START -#define SECOND_PAGE_GROUP_SIZE SECOND_PAGE_GROUP_END - SECOND_PAGE_GROUP_START -#define THIRD_PAGE_GROUP_SIZE THIRD_PAGE_GROUP_END - THIRD_PAGE_GROUP_START - -#define P2_MAX_MTU (8000) -#define P3_MAX_MTU (9600) -#define NX_ETHERMTU 1500 -#define NX_MAX_ETHERHDR 32 /* This contains some padding */ - -#define NX_P2_RX_BUF_MAX_LEN 1760 -#define NX_P3_RX_BUF_MAX_LEN (NX_MAX_ETHERHDR + NX_ETHERMTU) -#define NX_P2_RX_JUMBO_BUF_MAX_LEN (NX_MAX_ETHERHDR + P2_MAX_MTU) -#define NX_P3_RX_JUMBO_BUF_MAX_LEN (NX_MAX_ETHERHDR + P3_MAX_MTU) -#define NX_CT_DEFAULT_RX_BUF_LEN 2048 -#define NX_LRO_BUFFER_EXTRA 2048 - -#define NX_RX_LRO_BUFFER_LENGTH (8060) - -/* - * Maximum number of ring contexts - */ -#define MAX_RING_CTX 1 - -/* Opcodes to be used with the commands */ -#define TX_ETHER_PKT 0x01 -#define TX_TCP_PKT 0x02 -#define TX_UDP_PKT 0x03 -#define TX_IP_PKT 0x04 -#define TX_TCP_LSO 0x05 -#define TX_TCP_LSO6 0x06 -#define TX_IPSEC 0x07 -#define TX_IPSEC_CMD 0x0a -#define TX_TCPV6_PKT 0x0b -#define TX_UDPV6_PKT 0x0c - -/* The following opcodes are for internal consumption. */ -#define NETXEN_CONTROL_OP 0x10 -#define PEGNET_REQUEST 0x11 - -#define MAX_NUM_CARDS 4 - -#define NETXEN_MAX_FRAGS_PER_TX 14 -#define MAX_TSO_HEADER_DESC 2 -#define MGMT_CMD_DESC_RESV 4 -#define TX_STOP_THRESH ((MAX_SKB_FRAGS >> 2) + MAX_TSO_HEADER_DESC \ - + MGMT_CMD_DESC_RESV) -#define NX_MAX_TX_TIMEOUTS 2 - -/* - * Following are the states of the Phantom. Phantom will set them and - * Host will read to check if the fields are correct. - */ -#define PHAN_INITIALIZE_START 0xff00 -#define PHAN_INITIALIZE_FAILED 0xffff -#define PHAN_INITIALIZE_COMPLETE 0xff01 - -/* Host writes the following to notify that it has done the init-handshake */ -#define PHAN_INITIALIZE_ACK 0xf00f - -#define NUM_RCV_DESC_RINGS 3 -#define NUM_STS_DESC_RINGS 4 - -#define RCV_RING_NORMAL 0 -#define RCV_RING_JUMBO 1 -#define RCV_RING_LRO 2 - -#define MIN_CMD_DESCRIPTORS 64 -#define MIN_RCV_DESCRIPTORS 64 -#define MIN_JUMBO_DESCRIPTORS 32 - -#define MAX_CMD_DESCRIPTORS 1024 -#define MAX_RCV_DESCRIPTORS_1G 4096 -#define MAX_RCV_DESCRIPTORS_10G 8192 -#define MAX_JUMBO_RCV_DESCRIPTORS_1G 512 -#define MAX_JUMBO_RCV_DESCRIPTORS_10G 1024 -#define MAX_LRO_RCV_DESCRIPTORS 8 - -#define DEFAULT_RCV_DESCRIPTORS_1G 2048 -#define DEFAULT_RCV_DESCRIPTORS_10G 4096 - -#define NETXEN_CTX_SIGNATURE 0xdee0 -#define NETXEN_CTX_SIGNATURE_V2 0x0002dee0 -#define NETXEN_CTX_RESET 0xbad0 -#define NETXEN_CTX_D3_RESET 0xacc0 -#define NETXEN_RCV_PRODUCER(ringid) (ringid) - -#define PHAN_PEG_RCV_INITIALIZED 0xff01 -#define PHAN_PEG_RCV_START_INITIALIZE 0xff00 - -#define get_next_index(index, length) \ - (((index) + 1) & ((length) - 1)) - -#define get_index_range(index,length,count) \ - (((index) + (count)) & ((length) - 1)) - -#define MPORT_SINGLE_FUNCTION_MODE 0x1111 -#define MPORT_MULTI_FUNCTION_MODE 0x2222 - -#define NX_MAX_PCI_FUNC 8 - -/* - * NetXen host-peg signal message structure - * - * Bit 0-1 : peg_id => 0x2 for tx and 01 for rx - * Bit 2 : priv_id => must be 1 - * Bit 3-17 : count => for doorbell - * Bit 18-27 : ctx_id => Context id - * Bit 28-31 : opcode - */ - -typedef u32 netxen_ctx_msg; - -#define netxen_set_msg_peg_id(config_word, val) \ - ((config_word) &= ~3, (config_word) |= val & 3) -#define netxen_set_msg_privid(config_word) \ - ((config_word) |= 1 << 2) -#define netxen_set_msg_count(config_word, val) \ - ((config_word) &= ~(0x7fff<<3), (config_word) |= (val & 0x7fff) << 3) -#define netxen_set_msg_ctxid(config_word, val) \ - ((config_word) &= ~(0x3ff<<18), (config_word) |= (val & 0x3ff) << 18) -#define netxen_set_msg_opcode(config_word, val) \ - ((config_word) &= ~(0xf<<28), (config_word) |= (val & 0xf) << 28) - -struct netxen_rcv_ring { - __le64 addr; - __le32 size; - __le32 rsrvd; -}; - -struct netxen_sts_ring { - __le64 addr; - __le32 size; - __le16 msi_index; - __le16 rsvd; -} ; - -struct netxen_ring_ctx { - - /* one command ring */ - __le64 cmd_consumer_offset; - __le64 cmd_ring_addr; - __le32 cmd_ring_size; - __le32 rsrvd; - - /* three receive rings */ - struct netxen_rcv_ring rcv_rings[NUM_RCV_DESC_RINGS]; - - __le64 sts_ring_addr; - __le32 sts_ring_size; - - __le32 ctx_id; - - __le64 rsrvd_2[3]; - __le32 sts_ring_count; - __le32 rsrvd_3; - struct netxen_sts_ring sts_rings[NUM_STS_DESC_RINGS]; - -} __attribute__ ((aligned(64))); - -/* - * Following data structures describe the descriptors that will be used. - * Added fileds of tcpHdrSize and ipHdrSize, The driver needs to do it only when - * we are doing LSO (above the 1500 size packet) only. - */ - -/* - * The size of reference handle been changed to 16 bits to pass the MSS fields - * for the LSO packet - */ - -#define FLAGS_CHECKSUM_ENABLED 0x01 -#define FLAGS_LSO_ENABLED 0x02 -#define FLAGS_IPSEC_SA_ADD 0x04 -#define FLAGS_IPSEC_SA_DELETE 0x08 -#define FLAGS_VLAN_TAGGED 0x10 -#define FLAGS_VLAN_OOB 0x40 - -#define netxen_set_tx_vlan_tci(cmd_desc, v) \ - (cmd_desc)->vlan_TCI = cpu_to_le16(v); - -#define netxen_set_cmd_desc_port(cmd_desc, var) \ - ((cmd_desc)->port_ctxid |= ((var) & 0x0F)) -#define netxen_set_cmd_desc_ctxid(cmd_desc, var) \ - ((cmd_desc)->port_ctxid |= ((var) << 4 & 0xF0)) - -#define netxen_set_tx_port(_desc, _port) \ - (_desc)->port_ctxid = ((_port) & 0xf) | (((_port) << 4) & 0xf0) - -#define netxen_set_tx_flags_opcode(_desc, _flags, _opcode) \ - (_desc)->flags_opcode = \ - cpu_to_le16(((_flags) & 0x7f) | (((_opcode) & 0x3f) << 7)) - -#define netxen_set_tx_frags_len(_desc, _frags, _len) \ - (_desc)->nfrags__length = \ - cpu_to_le32(((_frags) & 0xff) | (((_len) & 0xffffff) << 8)) - -struct cmd_desc_type0 { - u8 tcp_hdr_offset; /* For LSO only */ - u8 ip_hdr_offset; /* For LSO only */ - __le16 flags_opcode; /* 15:13 unused, 12:7 opcode, 6:0 flags */ - __le32 nfrags__length; /* 31:8 total len, 7:0 frag count */ - - __le64 addr_buffer2; - - __le16 reference_handle; - __le16 mss; - u8 port_ctxid; /* 7:4 ctxid 3:0 port */ - u8 total_hdr_length; /* LSO only : MAC+IP+TCP Hdr size */ - __le16 conn_id; /* IPSec offoad only */ - - __le64 addr_buffer3; - __le64 addr_buffer1; - - __le16 buffer_length[4]; - - __le64 addr_buffer4; - - __le32 reserved2; - __le16 reserved; - __le16 vlan_TCI; - -} __attribute__ ((aligned(64))); - -/* Note: sizeof(rcv_desc) should always be a mutliple of 2 */ -struct rcv_desc { - __le16 reference_handle; - __le16 reserved; - __le32 buffer_length; /* allocated buffer length (usually 2K) */ - __le64 addr_buffer; -}; - -/* opcode field in status_desc */ -#define NETXEN_NIC_SYN_OFFLOAD 0x03 -#define NETXEN_NIC_RXPKT_DESC 0x04 -#define NETXEN_OLD_RXPKT_DESC 0x3f -#define NETXEN_NIC_RESPONSE_DESC 0x05 -#define NETXEN_NIC_LRO_DESC 0x12 - -/* for status field in status_desc */ -#define STATUS_NEED_CKSUM (1) -#define STATUS_CKSUM_OK (2) - -/* owner bits of status_desc */ -#define STATUS_OWNER_HOST (0x1ULL << 56) -#define STATUS_OWNER_PHANTOM (0x2ULL << 56) - -/* Status descriptor: - 0-3 port, 4-7 status, 8-11 type, 12-27 total_length - 28-43 reference_handle, 44-47 protocol, 48-52 pkt_offset - 53-55 desc_cnt, 56-57 owner, 58-63 opcode - */ -#define netxen_get_sts_port(sts_data) \ - ((sts_data) & 0x0F) -#define netxen_get_sts_status(sts_data) \ - (((sts_data) >> 4) & 0x0F) -#define netxen_get_sts_type(sts_data) \ - (((sts_data) >> 8) & 0x0F) -#define netxen_get_sts_totallength(sts_data) \ - (((sts_data) >> 12) & 0xFFFF) -#define netxen_get_sts_refhandle(sts_data) \ - (((sts_data) >> 28) & 0xFFFF) -#define netxen_get_sts_prot(sts_data) \ - (((sts_data) >> 44) & 0x0F) -#define netxen_get_sts_pkt_offset(sts_data) \ - (((sts_data) >> 48) & 0x1F) -#define netxen_get_sts_desc_cnt(sts_data) \ - (((sts_data) >> 53) & 0x7) -#define netxen_get_sts_opcode(sts_data) \ - (((sts_data) >> 58) & 0x03F) - -#define netxen_get_lro_sts_refhandle(sts_data) \ - ((sts_data) & 0x0FFFF) -#define netxen_get_lro_sts_length(sts_data) \ - (((sts_data) >> 16) & 0x0FFFF) -#define netxen_get_lro_sts_l2_hdr_offset(sts_data) \ - (((sts_data) >> 32) & 0x0FF) -#define netxen_get_lro_sts_l4_hdr_offset(sts_data) \ - (((sts_data) >> 40) & 0x0FF) -#define netxen_get_lro_sts_timestamp(sts_data) \ - (((sts_data) >> 48) & 0x1) -#define netxen_get_lro_sts_type(sts_data) \ - (((sts_data) >> 49) & 0x7) -#define netxen_get_lro_sts_push_flag(sts_data) \ - (((sts_data) >> 52) & 0x1) -#define netxen_get_lro_sts_seq_number(sts_data) \ - ((sts_data) & 0x0FFFFFFFF) - - -struct status_desc { - __le64 status_desc_data[2]; -} __attribute__ ((aligned(16))); - -/* UNIFIED ROMIMAGE *************************/ -#define NX_UNI_DIR_SECT_PRODUCT_TBL 0x0 -#define NX_UNI_DIR_SECT_BOOTLD 0x6 -#define NX_UNI_DIR_SECT_FW 0x7 - -/*Offsets */ -#define NX_UNI_CHIP_REV_OFF 10 -#define NX_UNI_FLAGS_OFF 11 -#define NX_UNI_BIOS_VERSION_OFF 12 -#define NX_UNI_BOOTLD_IDX_OFF 27 -#define NX_UNI_FIRMWARE_IDX_OFF 29 - -struct uni_table_desc{ - uint32_t findex; - uint32_t num_entries; - uint32_t entry_size; - uint32_t reserved[5]; -}; - -struct uni_data_desc{ - uint32_t findex; - uint32_t size; - uint32_t reserved[5]; -}; - -/* UNIFIED ROMIMAGE *************************/ - -/* The version of the main data structure */ -#define NETXEN_BDINFO_VERSION 1 - -/* Magic number to let user know flash is programmed */ -#define NETXEN_BDINFO_MAGIC 0x12345678 - -/* Max number of Gig ports on a Phantom board */ -#define NETXEN_MAX_PORTS 4 - -#define NETXEN_BRDTYPE_P1_BD 0x0000 -#define NETXEN_BRDTYPE_P1_SB 0x0001 -#define NETXEN_BRDTYPE_P1_SMAX 0x0002 -#define NETXEN_BRDTYPE_P1_SOCK 0x0003 - -#define NETXEN_BRDTYPE_P2_SOCK_31 0x0008 -#define NETXEN_BRDTYPE_P2_SOCK_35 0x0009 -#define NETXEN_BRDTYPE_P2_SB35_4G 0x000a -#define NETXEN_BRDTYPE_P2_SB31_10G 0x000b -#define NETXEN_BRDTYPE_P2_SB31_2G 0x000c - -#define NETXEN_BRDTYPE_P2_SB31_10G_IMEZ 0x000d -#define NETXEN_BRDTYPE_P2_SB31_10G_HMEZ 0x000e -#define NETXEN_BRDTYPE_P2_SB31_10G_CX4 0x000f - -#define NETXEN_BRDTYPE_P3_REF_QG 0x0021 -#define NETXEN_BRDTYPE_P3_HMEZ 0x0022 -#define NETXEN_BRDTYPE_P3_10G_CX4_LP 0x0023 -#define NETXEN_BRDTYPE_P3_4_GB 0x0024 -#define NETXEN_BRDTYPE_P3_IMEZ 0x0025 -#define NETXEN_BRDTYPE_P3_10G_SFP_PLUS 0x0026 -#define NETXEN_BRDTYPE_P3_10000_BASE_T 0x0027 -#define NETXEN_BRDTYPE_P3_XG_LOM 0x0028 -#define NETXEN_BRDTYPE_P3_4_GB_MM 0x0029 -#define NETXEN_BRDTYPE_P3_10G_SFP_CT 0x002a -#define NETXEN_BRDTYPE_P3_10G_SFP_QT 0x002b -#define NETXEN_BRDTYPE_P3_10G_CX4 0x0031 -#define NETXEN_BRDTYPE_P3_10G_XFP 0x0032 -#define NETXEN_BRDTYPE_P3_10G_TP 0x0080 - -/* Flash memory map */ -#define NETXEN_CRBINIT_START 0 /* crbinit section */ -#define NETXEN_BRDCFG_START 0x4000 /* board config */ -#define NETXEN_INITCODE_START 0x6000 /* pegtune code */ -#define NETXEN_BOOTLD_START 0x10000 /* bootld */ -#define NETXEN_IMAGE_START 0x43000 /* compressed image */ -#define NETXEN_SECONDARY_START 0x200000 /* backup images */ -#define NETXEN_PXE_START 0x3E0000 /* PXE boot rom */ -#define NETXEN_USER_START 0x3E8000 /* Firmare info */ -#define NETXEN_FIXED_START 0x3F0000 /* backup of crbinit */ -#define NETXEN_USER_START_OLD NETXEN_PXE_START /* very old flash */ - -#define NX_OLD_MAC_ADDR_OFFSET (NETXEN_USER_START) -#define NX_FW_VERSION_OFFSET (NETXEN_USER_START+0x408) -#define NX_FW_SIZE_OFFSET (NETXEN_USER_START+0x40c) -#define NX_FW_MAC_ADDR_OFFSET (NETXEN_USER_START+0x418) -#define NX_FW_SERIAL_NUM_OFFSET (NETXEN_USER_START+0x81c) -#define NX_BIOS_VERSION_OFFSET (NETXEN_USER_START+0x83c) - -#define NX_HDR_VERSION_OFFSET (NETXEN_BRDCFG_START) -#define NX_BRDTYPE_OFFSET (NETXEN_BRDCFG_START+0x8) -#define NX_FW_MAGIC_OFFSET (NETXEN_BRDCFG_START+0x128) - -#define NX_FW_MIN_SIZE (0x3fffff) -#define NX_P2_MN_ROMIMAGE 0 -#define NX_P3_CT_ROMIMAGE 1 -#define NX_P3_MN_ROMIMAGE 2 -#define NX_UNIFIED_ROMIMAGE 3 -#define NX_FLASH_ROMIMAGE 4 -#define NX_UNKNOWN_ROMIMAGE 0xff - -#define NX_P2_MN_ROMIMAGE_NAME "nxromimg.bin" -#define NX_P3_CT_ROMIMAGE_NAME "nx3fwct.bin" -#define NX_P3_MN_ROMIMAGE_NAME "nx3fwmn.bin" -#define NX_UNIFIED_ROMIMAGE_NAME "phanfw.bin" -#define NX_FLASH_ROMIMAGE_NAME "flash" - -extern char netxen_nic_driver_name[]; - -/* Number of status descriptors to handle per interrupt */ -#define MAX_STATUS_HANDLE (64) - -/* - * netxen_skb_frag{} is to contain mapping info for each SG list. This - * has to be freed when DMA is complete. This is part of netxen_tx_buffer{}. - */ -struct netxen_skb_frag { - u64 dma; - u64 length; -}; - -struct netxen_recv_crb { - u32 crb_rcv_producer[NUM_RCV_DESC_RINGS]; - u32 crb_sts_consumer[NUM_STS_DESC_RINGS]; - u32 sw_int_mask[NUM_STS_DESC_RINGS]; -}; - -/* Following defines are for the state of the buffers */ -#define NETXEN_BUFFER_FREE 0 -#define NETXEN_BUFFER_BUSY 1 - -/* - * There will be one netxen_buffer per skb packet. These will be - * used to save the dma info for pci_unmap_page() - */ -struct netxen_cmd_buffer { - struct sk_buff *skb; - struct netxen_skb_frag frag_array[MAX_SKB_FRAGS + 1]; - u32 frag_count; -}; - -/* In rx_buffer, we do not need multiple fragments as is a single buffer */ -struct netxen_rx_buffer { - struct list_head list; - struct sk_buff *skb; - u64 dma; - u16 ref_handle; - u16 state; -}; - -/* Board types */ -#define NETXEN_NIC_GBE 0x01 -#define NETXEN_NIC_XGBE 0x02 - -/* - * One hardware_context{} per adapter - * contains interrupt info as well shared hardware info. - */ -struct netxen_hardware_context { - void __iomem *pci_base0; - void __iomem *pci_base1; - void __iomem *pci_base2; - void __iomem *db_base; - void __iomem *ocm_win_crb; - - unsigned long db_len; - unsigned long pci_len0; - - u32 ocm_win; - u32 crb_win; - - rwlock_t crb_lock; - spinlock_t mem_lock; - - u8 cut_through; - u8 revision_id; - u8 pci_func; - u8 linkup; - u16 port_type; - u16 board_type; -}; - -#define MINIMUM_ETHERNET_FRAME_SIZE 64 /* With FCS */ -#define ETHERNET_FCS_SIZE 4 - -struct netxen_adapter_stats { - u64 xmitcalled; - u64 xmitfinished; - u64 rxdropped; - u64 txdropped; - u64 csummed; - u64 rx_pkts; - u64 lro_pkts; - u64 rxbytes; - u64 txbytes; -}; - -/* - * Rcv Descriptor Context. One such per Rcv Descriptor. There may - * be one Rcv Descriptor for normal packets, one for jumbo and may be others. - */ -struct nx_host_rds_ring { - u32 producer; - u32 num_desc; - u32 dma_size; - u32 skb_size; - u32 flags; - void __iomem *crb_rcv_producer; - struct rcv_desc *desc_head; - struct netxen_rx_buffer *rx_buf_arr; - struct list_head free_list; - spinlock_t lock; - dma_addr_t phys_addr; -}; - -struct nx_host_sds_ring { - u32 consumer; - u32 num_desc; - void __iomem *crb_sts_consumer; - void __iomem *crb_intr_mask; - - struct status_desc *desc_head; - struct netxen_adapter *adapter; - struct napi_struct napi; - struct list_head free_list[NUM_RCV_DESC_RINGS]; - - int irq; - - dma_addr_t phys_addr; - char name[IFNAMSIZ+4]; -}; - -struct nx_host_tx_ring { - u32 producer; - __le32 *hw_consumer; - u32 sw_consumer; - void __iomem *crb_cmd_producer; - void __iomem *crb_cmd_consumer; - u32 num_desc; - - struct netdev_queue *txq; - - struct netxen_cmd_buffer *cmd_buf_arr; - struct cmd_desc_type0 *desc_head; - dma_addr_t phys_addr; -}; - -/* - * Receive context. There is one such structure per instance of the - * receive processing. Any state information that is relevant to - * the receive, and is must be in this structure. The global data may be - * present elsewhere. - */ -struct netxen_recv_context { - u32 state; - u16 context_id; - u16 virt_port; - - struct nx_host_rds_ring *rds_rings; - struct nx_host_sds_ring *sds_rings; - - struct netxen_ring_ctx *hwctx; - dma_addr_t phys_addr; -}; - -/* New HW context creation */ - -#define NX_OS_CRB_RETRY_COUNT 4000 -#define NX_CDRP_SIGNATURE_MAKE(pcifn, version) \ - (((pcifn) & 0xff) | (((version) & 0xff) << 8) | (0xcafe << 16)) - -#define NX_CDRP_CLEAR 0x00000000 -#define NX_CDRP_CMD_BIT 0x80000000 - -/* - * All responses must have the NX_CDRP_CMD_BIT cleared - * in the crb NX_CDRP_CRB_OFFSET. - */ -#define NX_CDRP_FORM_RSP(rsp) (rsp) -#define NX_CDRP_IS_RSP(rsp) (((rsp) & NX_CDRP_CMD_BIT) == 0) - -#define NX_CDRP_RSP_OK 0x00000001 -#define NX_CDRP_RSP_FAIL 0x00000002 -#define NX_CDRP_RSP_TIMEOUT 0x00000003 - -/* - * All commands must have the NX_CDRP_CMD_BIT set in - * the crb NX_CDRP_CRB_OFFSET. - */ -#define NX_CDRP_FORM_CMD(cmd) (NX_CDRP_CMD_BIT | (cmd)) -#define NX_CDRP_IS_CMD(cmd) (((cmd) & NX_CDRP_CMD_BIT) != 0) - -#define NX_CDRP_CMD_SUBMIT_CAPABILITIES 0x00000001 -#define NX_CDRP_CMD_READ_MAX_RDS_PER_CTX 0x00000002 -#define NX_CDRP_CMD_READ_MAX_SDS_PER_CTX 0x00000003 -#define NX_CDRP_CMD_READ_MAX_RULES_PER_CTX 0x00000004 -#define NX_CDRP_CMD_READ_MAX_RX_CTX 0x00000005 -#define NX_CDRP_CMD_READ_MAX_TX_CTX 0x00000006 -#define NX_CDRP_CMD_CREATE_RX_CTX 0x00000007 -#define NX_CDRP_CMD_DESTROY_RX_CTX 0x00000008 -#define NX_CDRP_CMD_CREATE_TX_CTX 0x00000009 -#define NX_CDRP_CMD_DESTROY_TX_CTX 0x0000000a -#define NX_CDRP_CMD_SETUP_STATISTICS 0x0000000e -#define NX_CDRP_CMD_GET_STATISTICS 0x0000000f -#define NX_CDRP_CMD_DELETE_STATISTICS 0x00000010 -#define NX_CDRP_CMD_SET_MTU 0x00000012 -#define NX_CDRP_CMD_READ_PHY 0x00000013 -#define NX_CDRP_CMD_WRITE_PHY 0x00000014 -#define NX_CDRP_CMD_READ_HW_REG 0x00000015 -#define NX_CDRP_CMD_GET_FLOW_CTL 0x00000016 -#define NX_CDRP_CMD_SET_FLOW_CTL 0x00000017 -#define NX_CDRP_CMD_READ_MAX_MTU 0x00000018 -#define NX_CDRP_CMD_READ_MAX_LRO 0x00000019 -#define NX_CDRP_CMD_CONFIGURE_TOE 0x0000001a -#define NX_CDRP_CMD_FUNC_ATTRIB 0x0000001b -#define NX_CDRP_CMD_READ_PEXQ_PARAMETERS 0x0000001c -#define NX_CDRP_CMD_GET_LIC_CAPABILITIES 0x0000001d -#define NX_CDRP_CMD_READ_MAX_LRO_PER_BOARD 0x0000001e -#define NX_CDRP_CMD_CONFIG_GBE_PORT 0x0000001f -#define NX_CDRP_CMD_MAX 0x00000020 - -#define NX_RCODE_SUCCESS 0 -#define NX_RCODE_NO_HOST_MEM 1 -#define NX_RCODE_NO_HOST_RESOURCE 2 -#define NX_RCODE_NO_CARD_CRB 3 -#define NX_RCODE_NO_CARD_MEM 4 -#define NX_RCODE_NO_CARD_RESOURCE 5 -#define NX_RCODE_INVALID_ARGS 6 -#define NX_RCODE_INVALID_ACTION 7 -#define NX_RCODE_INVALID_STATE 8 -#define NX_RCODE_NOT_SUPPORTED 9 -#define NX_RCODE_NOT_PERMITTED 10 -#define NX_RCODE_NOT_READY 11 -#define NX_RCODE_DOES_NOT_EXIST 12 -#define NX_RCODE_ALREADY_EXISTS 13 -#define NX_RCODE_BAD_SIGNATURE 14 -#define NX_RCODE_CMD_NOT_IMPL 15 -#define NX_RCODE_CMD_INVALID 16 -#define NX_RCODE_TIMEOUT 17 -#define NX_RCODE_CMD_FAILED 18 -#define NX_RCODE_MAX_EXCEEDED 19 -#define NX_RCODE_MAX 20 - -#define NX_DESTROY_CTX_RESET 0 -#define NX_DESTROY_CTX_D3_RESET 1 -#define NX_DESTROY_CTX_MAX 2 - -/* - * Capabilities - */ -#define NX_CAP_BIT(class, bit) (1 << bit) -#define NX_CAP0_LEGACY_CONTEXT NX_CAP_BIT(0, 0) -#define NX_CAP0_MULTI_CONTEXT NX_CAP_BIT(0, 1) -#define NX_CAP0_LEGACY_MN NX_CAP_BIT(0, 2) -#define NX_CAP0_LEGACY_MS NX_CAP_BIT(0, 3) -#define NX_CAP0_CUT_THROUGH NX_CAP_BIT(0, 4) -#define NX_CAP0_LRO NX_CAP_BIT(0, 5) -#define NX_CAP0_LSO NX_CAP_BIT(0, 6) -#define NX_CAP0_JUMBO_CONTIGUOUS NX_CAP_BIT(0, 7) -#define NX_CAP0_LRO_CONTIGUOUS NX_CAP_BIT(0, 8) -#define NX_CAP0_HW_LRO NX_CAP_BIT(0, 10) - -/* - * Context state - */ -#define NX_HOST_CTX_STATE_FREED 0 -#define NX_HOST_CTX_STATE_ALLOCATED 1 -#define NX_HOST_CTX_STATE_ACTIVE 2 -#define NX_HOST_CTX_STATE_DISABLED 3 -#define NX_HOST_CTX_STATE_QUIESCED 4 -#define NX_HOST_CTX_STATE_MAX 5 - -/* - * Rx context - */ - -typedef struct { - __le64 host_phys_addr; /* Ring base addr */ - __le32 ring_size; /* Ring entries */ - __le16 msi_index; - __le16 rsvd; /* Padding */ -} nx_hostrq_sds_ring_t; - -typedef struct { - __le64 host_phys_addr; /* Ring base addr */ - __le64 buff_size; /* Packet buffer size */ - __le32 ring_size; /* Ring entries */ - __le32 ring_kind; /* Class of ring */ -} nx_hostrq_rds_ring_t; - -typedef struct { - __le64 host_rsp_dma_addr; /* Response dma'd here */ - __le32 capabilities[4]; /* Flag bit vector */ - __le32 host_int_crb_mode; /* Interrupt crb usage */ - __le32 host_rds_crb_mode; /* RDS crb usage */ - /* These ring offsets are relative to data[0] below */ - __le32 rds_ring_offset; /* Offset to RDS config */ - __le32 sds_ring_offset; /* Offset to SDS config */ - __le16 num_rds_rings; /* Count of RDS rings */ - __le16 num_sds_rings; /* Count of SDS rings */ - __le16 rsvd1; /* Padding */ - __le16 rsvd2; /* Padding */ - u8 reserved[128]; /* reserve space for future expansion*/ - /* MUST BE 64-bit aligned. - The following is packed: - - N hostrq_rds_rings - - N hostrq_sds_rings */ - char data[0]; -} nx_hostrq_rx_ctx_t; - -typedef struct { - __le32 host_producer_crb; /* Crb to use */ - __le32 rsvd1; /* Padding */ -} nx_cardrsp_rds_ring_t; - -typedef struct { - __le32 host_consumer_crb; /* Crb to use */ - __le32 interrupt_crb; /* Crb to use */ -} nx_cardrsp_sds_ring_t; - -typedef struct { - /* These ring offsets are relative to data[0] below */ - __le32 rds_ring_offset; /* Offset to RDS config */ - __le32 sds_ring_offset; /* Offset to SDS config */ - __le32 host_ctx_state; /* Starting State */ - __le32 num_fn_per_port; /* How many PCI fn share the port */ - __le16 num_rds_rings; /* Count of RDS rings */ - __le16 num_sds_rings; /* Count of SDS rings */ - __le16 context_id; /* Handle for context */ - u8 phys_port; /* Physical id of port */ - u8 virt_port; /* Virtual/Logical id of port */ - u8 reserved[128]; /* save space for future expansion */ - /* MUST BE 64-bit aligned. - The following is packed: - - N cardrsp_rds_rings - - N cardrs_sds_rings */ - char data[0]; -} nx_cardrsp_rx_ctx_t; - -#define SIZEOF_HOSTRQ_RX(HOSTRQ_RX, rds_rings, sds_rings) \ - (sizeof(HOSTRQ_RX) + \ - (rds_rings)*(sizeof(nx_hostrq_rds_ring_t)) + \ - (sds_rings)*(sizeof(nx_hostrq_sds_ring_t))) - -#define SIZEOF_CARDRSP_RX(CARDRSP_RX, rds_rings, sds_rings) \ - (sizeof(CARDRSP_RX) + \ - (rds_rings)*(sizeof(nx_cardrsp_rds_ring_t)) + \ - (sds_rings)*(sizeof(nx_cardrsp_sds_ring_t))) - -/* - * Tx context - */ - -typedef struct { - __le64 host_phys_addr; /* Ring base addr */ - __le32 ring_size; /* Ring entries */ - __le32 rsvd; /* Padding */ -} nx_hostrq_cds_ring_t; - -typedef struct { - __le64 host_rsp_dma_addr; /* Response dma'd here */ - __le64 cmd_cons_dma_addr; /* */ - __le64 dummy_dma_addr; /* */ - __le32 capabilities[4]; /* Flag bit vector */ - __le32 host_int_crb_mode; /* Interrupt crb usage */ - __le32 rsvd1; /* Padding */ - __le16 rsvd2; /* Padding */ - __le16 interrupt_ctl; - __le16 msi_index; - __le16 rsvd3; /* Padding */ - nx_hostrq_cds_ring_t cds_ring; /* Desc of cds ring */ - u8 reserved[128]; /* future expansion */ -} nx_hostrq_tx_ctx_t; - -typedef struct { - __le32 host_producer_crb; /* Crb to use */ - __le32 interrupt_crb; /* Crb to use */ -} nx_cardrsp_cds_ring_t; - -typedef struct { - __le32 host_ctx_state; /* Starting state */ - __le16 context_id; /* Handle for context */ - u8 phys_port; /* Physical id of port */ - u8 virt_port; /* Virtual/Logical id of port */ - nx_cardrsp_cds_ring_t cds_ring; /* Card cds settings */ - u8 reserved[128]; /* future expansion */ -} nx_cardrsp_tx_ctx_t; - -#define SIZEOF_HOSTRQ_TX(HOSTRQ_TX) (sizeof(HOSTRQ_TX)) -#define SIZEOF_CARDRSP_TX(CARDRSP_TX) (sizeof(CARDRSP_TX)) - -/* CRB */ - -#define NX_HOST_RDS_CRB_MODE_UNIQUE 0 -#define NX_HOST_RDS_CRB_MODE_SHARED 1 -#define NX_HOST_RDS_CRB_MODE_CUSTOM 2 -#define NX_HOST_RDS_CRB_MODE_MAX 3 - -#define NX_HOST_INT_CRB_MODE_UNIQUE 0 -#define NX_HOST_INT_CRB_MODE_SHARED 1 -#define NX_HOST_INT_CRB_MODE_NORX 2 -#define NX_HOST_INT_CRB_MODE_NOTX 3 -#define NX_HOST_INT_CRB_MODE_NORXTX 4 - - -/* MAC */ - -#define MC_COUNT_P2 16 -#define MC_COUNT_P3 38 - -#define NETXEN_MAC_NOOP 0 -#define NETXEN_MAC_ADD 1 -#define NETXEN_MAC_DEL 2 - -typedef struct nx_mac_list_s { - struct list_head list; - uint8_t mac_addr[ETH_ALEN+2]; -} nx_mac_list_t; - -struct nx_vlan_ip_list { - struct list_head list; - u32 ip_addr; -}; - -/* - * Interrupt coalescing defaults. The defaults are for 1500 MTU. It is - * adjusted based on configured MTU. - */ -#define NETXEN_DEFAULT_INTR_COALESCE_RX_TIME_US 3 -#define NETXEN_DEFAULT_INTR_COALESCE_RX_PACKETS 256 -#define NETXEN_DEFAULT_INTR_COALESCE_TX_PACKETS 64 -#define NETXEN_DEFAULT_INTR_COALESCE_TX_TIME_US 4 - -#define NETXEN_NIC_INTR_DEFAULT 0x04 - -typedef union { - struct { - uint16_t rx_packets; - uint16_t rx_time_us; - uint16_t tx_packets; - uint16_t tx_time_us; - } data; - uint64_t word; -} nx_nic_intr_coalesce_data_t; - -typedef struct { - uint16_t stats_time_us; - uint16_t rate_sample_time; - uint16_t flags; - uint16_t rsvd_1; - uint32_t low_threshold; - uint32_t high_threshold; - nx_nic_intr_coalesce_data_t normal; - nx_nic_intr_coalesce_data_t low; - nx_nic_intr_coalesce_data_t high; - nx_nic_intr_coalesce_data_t irq; -} nx_nic_intr_coalesce_t; - -#define NX_HOST_REQUEST 0x13 -#define NX_NIC_REQUEST 0x14 - -#define NX_MAC_EVENT 0x1 - -#define NX_IP_UP 2 -#define NX_IP_DOWN 3 - -/* - * Driver --> Firmware - */ -#define NX_NIC_H2C_OPCODE_START 0 -#define NX_NIC_H2C_OPCODE_CONFIG_RSS 1 -#define NX_NIC_H2C_OPCODE_CONFIG_RSS_TBL 2 -#define NX_NIC_H2C_OPCODE_CONFIG_INTR_COALESCE 3 -#define NX_NIC_H2C_OPCODE_CONFIG_LED 4 -#define NX_NIC_H2C_OPCODE_CONFIG_PROMISCUOUS 5 -#define NX_NIC_H2C_OPCODE_CONFIG_L2_MAC 6 -#define NX_NIC_H2C_OPCODE_LRO_REQUEST 7 -#define NX_NIC_H2C_OPCODE_GET_SNMP_STATS 8 -#define NX_NIC_H2C_OPCODE_PROXY_START_REQUEST 9 -#define NX_NIC_H2C_OPCODE_PROXY_STOP_REQUEST 10 -#define NX_NIC_H2C_OPCODE_PROXY_SET_MTU 11 -#define NX_NIC_H2C_OPCODE_PROXY_SET_VPORT_MISS_MODE 12 -#define NX_NIC_H2C_OPCODE_GET_FINGER_PRINT_REQUEST 13 -#define NX_NIC_H2C_OPCODE_INSTALL_LICENSE_REQUEST 14 -#define NX_NIC_H2C_OPCODE_GET_LICENSE_CAPABILITY_REQUEST 15 -#define NX_NIC_H2C_OPCODE_GET_NET_STATS 16 -#define NX_NIC_H2C_OPCODE_PROXY_UPDATE_P2V 17 -#define NX_NIC_H2C_OPCODE_CONFIG_IPADDR 18 -#define NX_NIC_H2C_OPCODE_CONFIG_LOOPBACK 19 -#define NX_NIC_H2C_OPCODE_PROXY_STOP_DONE 20 -#define NX_NIC_H2C_OPCODE_GET_LINKEVENT 21 -#define NX_NIC_C2C_OPCODE 22 -#define NX_NIC_H2C_OPCODE_CONFIG_BRIDGING 23 -#define NX_NIC_H2C_OPCODE_CONFIG_HW_LRO 24 -#define NX_NIC_H2C_OPCODE_LAST 25 - -/* - * Firmware --> Driver - */ - -#define NX_NIC_C2H_OPCODE_START 128 -#define NX_NIC_C2H_OPCODE_CONFIG_RSS_RESPONSE 129 -#define NX_NIC_C2H_OPCODE_CONFIG_RSS_TBL_RESPONSE 130 -#define NX_NIC_C2H_OPCODE_CONFIG_MAC_RESPONSE 131 -#define NX_NIC_C2H_OPCODE_CONFIG_PROMISCUOUS_RESPONSE 132 -#define NX_NIC_C2H_OPCODE_CONFIG_L2_MAC_RESPONSE 133 -#define NX_NIC_C2H_OPCODE_LRO_DELETE_RESPONSE 134 -#define NX_NIC_C2H_OPCODE_LRO_ADD_FAILURE_RESPONSE 135 -#define NX_NIC_C2H_OPCODE_GET_SNMP_STATS 136 -#define NX_NIC_C2H_OPCODE_GET_FINGER_PRINT_REPLY 137 -#define NX_NIC_C2H_OPCODE_INSTALL_LICENSE_REPLY 138 -#define NX_NIC_C2H_OPCODE_GET_LICENSE_CAPABILITIES_REPLY 139 -#define NX_NIC_C2H_OPCODE_GET_NET_STATS_RESPONSE 140 -#define NX_NIC_C2H_OPCODE_GET_LINKEVENT_RESPONSE 141 -#define NX_NIC_C2H_OPCODE_LAST 142 - -#define VPORT_MISS_MODE_DROP 0 /* drop all unmatched */ -#define VPORT_MISS_MODE_ACCEPT_ALL 1 /* accept all packets */ -#define VPORT_MISS_MODE_ACCEPT_MULTI 2 /* accept unmatched multicast */ - -#define NX_NIC_LRO_REQUEST_FIRST 0 -#define NX_NIC_LRO_REQUEST_ADD_FLOW 1 -#define NX_NIC_LRO_REQUEST_DELETE_FLOW 2 -#define NX_NIC_LRO_REQUEST_TIMER 3 -#define NX_NIC_LRO_REQUEST_CLEANUP 4 -#define NX_NIC_LRO_REQUEST_ADD_FLOW_SCHEDULED 5 -#define NX_TOE_LRO_REQUEST_ADD_FLOW 6 -#define NX_TOE_LRO_REQUEST_ADD_FLOW_RESPONSE 7 -#define NX_TOE_LRO_REQUEST_DELETE_FLOW 8 -#define NX_TOE_LRO_REQUEST_DELETE_FLOW_RESPONSE 9 -#define NX_TOE_LRO_REQUEST_TIMER 10 -#define NX_NIC_LRO_REQUEST_LAST 11 - -#define NX_FW_CAPABILITY_LINK_NOTIFICATION (1 << 5) -#define NX_FW_CAPABILITY_SWITCHING (1 << 6) -#define NX_FW_CAPABILITY_PEXQ (1 << 7) -#define NX_FW_CAPABILITY_BDG (1 << 8) -#define NX_FW_CAPABILITY_FVLANTX (1 << 9) -#define NX_FW_CAPABILITY_HW_LRO (1 << 10) -#define NX_FW_CAPABILITY_GBE_LINK_CFG (1 << 11) - -/* module types */ -#define LINKEVENT_MODULE_NOT_PRESENT 1 -#define LINKEVENT_MODULE_OPTICAL_UNKNOWN 2 -#define LINKEVENT_MODULE_OPTICAL_SRLR 3 -#define LINKEVENT_MODULE_OPTICAL_LRM 4 -#define LINKEVENT_MODULE_OPTICAL_SFP_1G 5 -#define LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLE 6 -#define LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLELEN 7 -#define LINKEVENT_MODULE_TWINAX 8 - -#define LINKSPEED_10GBPS 10000 -#define LINKSPEED_1GBPS 1000 -#define LINKSPEED_100MBPS 100 -#define LINKSPEED_10MBPS 10 - -#define LINKSPEED_ENCODED_10MBPS 0 -#define LINKSPEED_ENCODED_100MBPS 1 -#define LINKSPEED_ENCODED_1GBPS 2 - -#define LINKEVENT_AUTONEG_DISABLED 0 -#define LINKEVENT_AUTONEG_ENABLED 1 - -#define LINKEVENT_HALF_DUPLEX 0 -#define LINKEVENT_FULL_DUPLEX 1 - -#define LINKEVENT_LINKSPEED_MBPS 0 -#define LINKEVENT_LINKSPEED_ENCODED 1 - -#define AUTO_FW_RESET_ENABLED 0xEF10AF12 -#define AUTO_FW_RESET_DISABLED 0xDCBAAF12 - -/* firmware response header: - * 63:58 - message type - * 57:56 - owner - * 55:53 - desc count - * 52:48 - reserved - * 47:40 - completion id - * 39:32 - opcode - * 31:16 - error code - * 15:00 - reserved - */ -#define netxen_get_nic_msgtype(msg_hdr) \ - ((msg_hdr >> 58) & 0x3F) -#define netxen_get_nic_msg_compid(msg_hdr) \ - ((msg_hdr >> 40) & 0xFF) -#define netxen_get_nic_msg_opcode(msg_hdr) \ - ((msg_hdr >> 32) & 0xFF) -#define netxen_get_nic_msg_errcode(msg_hdr) \ - ((msg_hdr >> 16) & 0xFFFF) - -typedef struct { - union { - struct { - u64 hdr; - u64 body[7]; - }; - u64 words[8]; - }; -} nx_fw_msg_t; - -typedef struct { - __le64 qhdr; - __le64 req_hdr; - __le64 words[6]; -} nx_nic_req_t; - -typedef struct { - u8 op; - u8 tag; - u8 mac_addr[6]; -} nx_mac_req_t; - -#define MAX_PENDING_DESC_BLOCK_SIZE 64 - -#define NETXEN_NIC_MSI_ENABLED 0x02 -#define NETXEN_NIC_MSIX_ENABLED 0x04 -#define NETXEN_NIC_LRO_ENABLED 0x08 -#define NETXEN_NIC_LRO_DISABLED 0x00 -#define NETXEN_NIC_BRIDGE_ENABLED 0X10 -#define NETXEN_NIC_DIAG_ENABLED 0x20 -#define NETXEN_IS_MSI_FAMILY(adapter) \ - ((adapter)->flags & (NETXEN_NIC_MSI_ENABLED | NETXEN_NIC_MSIX_ENABLED)) - -#define MSIX_ENTRIES_PER_ADAPTER NUM_STS_DESC_RINGS -#define NETXEN_MSIX_TBL_SPACE 8192 -#define NETXEN_PCI_REG_MSIX_TBL 0x44 - -#define NETXEN_DB_MAPSIZE_BYTES 0x1000 - -#define NETXEN_NETDEV_WEIGHT 128 -#define NETXEN_ADAPTER_UP_MAGIC 777 -#define NETXEN_NIC_PEG_TUNE 0 - -#define __NX_FW_ATTACHED 0 -#define __NX_DEV_UP 1 -#define __NX_RESETTING 2 - -struct netxen_dummy_dma { - void *addr; - dma_addr_t phys_addr; -}; - -struct netxen_adapter { - struct netxen_hardware_context ahw; - - struct net_device *netdev; - struct pci_dev *pdev; - struct list_head mac_list; - struct list_head vlan_ip_list; - - spinlock_t tx_clean_lock; - - u16 num_txd; - u16 num_rxd; - u16 num_jumbo_rxd; - u16 num_lro_rxd; - - u8 max_rds_rings; - u8 max_sds_rings; - u8 driver_mismatch; - u8 msix_supported; - u8 __pad; - u8 pci_using_dac; - u8 portnum; - u8 physical_port; - - u8 mc_enabled; - u8 max_mc_count; - u8 rss_supported; - u8 link_changed; - u8 fw_wait_cnt; - u8 fw_fail_cnt; - u8 tx_timeo_cnt; - u8 need_fw_reset; - - u8 has_link_events; - u8 fw_type; - u16 tx_context_id; - u16 mtu; - u16 is_up; - - u16 link_speed; - u16 link_duplex; - u16 link_autoneg; - u16 module_type; - - u32 capabilities; - u32 flags; - u32 irq; - u32 temp; - - u32 int_vec_bit; - u32 heartbit; - - u8 mac_addr[ETH_ALEN]; - - struct netxen_adapter_stats stats; - - struct netxen_recv_context recv_ctx; - struct nx_host_tx_ring *tx_ring; - - int (*macaddr_set) (struct netxen_adapter *, u8 *); - int (*set_mtu) (struct netxen_adapter *, int); - int (*set_promisc) (struct netxen_adapter *, u32); - void (*set_multi) (struct net_device *); - int (*phy_read) (struct netxen_adapter *, u32 reg, u32 *); - int (*phy_write) (struct netxen_adapter *, u32 reg, u32 val); - int (*init_port) (struct netxen_adapter *, int); - int (*stop_port) (struct netxen_adapter *); - - u32 (*crb_read)(struct netxen_adapter *, ulong); - int (*crb_write)(struct netxen_adapter *, ulong, u32); - - int (*pci_mem_read)(struct netxen_adapter *, u64, u64 *); - int (*pci_mem_write)(struct netxen_adapter *, u64, u64); - - int (*pci_set_window)(struct netxen_adapter *, u64, u32 *); - - u32 (*io_read)(struct netxen_adapter *, void __iomem *); - void (*io_write)(struct netxen_adapter *, void __iomem *, u32); - - void __iomem *tgt_mask_reg; - void __iomem *pci_int_reg; - void __iomem *tgt_status_reg; - void __iomem *crb_int_state_reg; - void __iomem *isr_int_vec; - - struct msix_entry msix_entries[MSIX_ENTRIES_PER_ADAPTER]; - - struct netxen_dummy_dma dummy_dma; - - struct delayed_work fw_work; - - struct work_struct tx_timeout_task; - - nx_nic_intr_coalesce_t coal; - - unsigned long state; - __le32 file_prd_off; /*File fw product offset*/ - u32 fw_version; - const struct firmware *fw; -}; - -int nx_fw_cmd_query_phy(struct netxen_adapter *adapter, u32 reg, u32 *val); -int nx_fw_cmd_set_phy(struct netxen_adapter *adapter, u32 reg, u32 val); - -#define NXRD32(adapter, off) \ - (adapter->crb_read(adapter, off)) -#define NXWR32(adapter, off, val) \ - (adapter->crb_write(adapter, off, val)) -#define NXRDIO(adapter, addr) \ - (adapter->io_read(adapter, addr)) -#define NXWRIO(adapter, addr, val) \ - (adapter->io_write(adapter, addr, val)) - -int netxen_pcie_sem_lock(struct netxen_adapter *, int, u32); -void netxen_pcie_sem_unlock(struct netxen_adapter *, int); - -#define netxen_rom_lock(a) \ - netxen_pcie_sem_lock((a), 2, NETXEN_ROM_LOCK_ID) -#define netxen_rom_unlock(a) \ - netxen_pcie_sem_unlock((a), 2) -#define netxen_phy_lock(a) \ - netxen_pcie_sem_lock((a), 3, NETXEN_PHY_LOCK_ID) -#define netxen_phy_unlock(a) \ - netxen_pcie_sem_unlock((a), 3) -#define netxen_api_lock(a) \ - netxen_pcie_sem_lock((a), 5, 0) -#define netxen_api_unlock(a) \ - netxen_pcie_sem_unlock((a), 5) -#define netxen_sw_lock(a) \ - netxen_pcie_sem_lock((a), 6, 0) -#define netxen_sw_unlock(a) \ - netxen_pcie_sem_unlock((a), 6) -#define crb_win_lock(a) \ - netxen_pcie_sem_lock((a), 7, NETXEN_CRB_WIN_LOCK_ID) -#define crb_win_unlock(a) \ - netxen_pcie_sem_unlock((a), 7) - -int netxen_nic_get_board_info(struct netxen_adapter *adapter); -int netxen_nic_wol_supported(struct netxen_adapter *adapter); - -/* Functions from netxen_nic_init.c */ -int netxen_init_dummy_dma(struct netxen_adapter *adapter); -void netxen_free_dummy_dma(struct netxen_adapter *adapter); - -int netxen_check_flash_fw_compatibility(struct netxen_adapter *adapter); -int netxen_phantom_init(struct netxen_adapter *adapter, int pegtune_val); -int netxen_load_firmware(struct netxen_adapter *adapter); -int netxen_need_fw_reset(struct netxen_adapter *adapter); -void netxen_request_firmware(struct netxen_adapter *adapter); -void netxen_release_firmware(struct netxen_adapter *adapter); -int netxen_pinit_from_rom(struct netxen_adapter *adapter); - -int netxen_rom_fast_read(struct netxen_adapter *adapter, int addr, int *valp); -int netxen_rom_fast_read_words(struct netxen_adapter *adapter, int addr, - u8 *bytes, size_t size); -int netxen_rom_fast_write_words(struct netxen_adapter *adapter, int addr, - u8 *bytes, size_t size); -int netxen_flash_unlock(struct netxen_adapter *adapter); -int netxen_backup_crbinit(struct netxen_adapter *adapter); -int netxen_flash_erase_secondary(struct netxen_adapter *adapter); -int netxen_flash_erase_primary(struct netxen_adapter *adapter); -void netxen_halt_pegs(struct netxen_adapter *adapter); - -int netxen_rom_se(struct netxen_adapter *adapter, int addr); - -int netxen_alloc_sw_resources(struct netxen_adapter *adapter); -void netxen_free_sw_resources(struct netxen_adapter *adapter); - -void netxen_setup_hwops(struct netxen_adapter *adapter); -void __iomem *netxen_get_ioaddr(struct netxen_adapter *, u32); - -int netxen_alloc_hw_resources(struct netxen_adapter *adapter); -void netxen_free_hw_resources(struct netxen_adapter *adapter); - -void netxen_release_rx_buffers(struct netxen_adapter *adapter); -void netxen_release_tx_buffers(struct netxen_adapter *adapter); - -int netxen_init_firmware(struct netxen_adapter *adapter); -void netxen_nic_clear_stats(struct netxen_adapter *adapter); -void netxen_watchdog_task(struct work_struct *work); -void netxen_post_rx_buffers(struct netxen_adapter *adapter, u32 ringid, - struct nx_host_rds_ring *rds_ring); -int netxen_process_cmd_ring(struct netxen_adapter *adapter); -int netxen_process_rcv_ring(struct nx_host_sds_ring *sds_ring, int max); - -void netxen_p3_free_mac_list(struct netxen_adapter *adapter); -int netxen_config_intr_coalesce(struct netxen_adapter *adapter); -int netxen_config_rss(struct netxen_adapter *adapter, int enable); -int netxen_config_ipaddr(struct netxen_adapter *adapter, u32 ip, int cmd); -int netxen_linkevent_request(struct netxen_adapter *adapter, int enable); -void netxen_advert_link_change(struct netxen_adapter *adapter, int linkup); -void netxen_pci_camqm_read_2M(struct netxen_adapter *, u64, u64 *); -void netxen_pci_camqm_write_2M(struct netxen_adapter *, u64, u64); - -int nx_fw_cmd_set_gbe_port(struct netxen_adapter *adapter, - u32 speed, u32 duplex, u32 autoneg); -int nx_fw_cmd_set_mtu(struct netxen_adapter *adapter, int mtu); -int netxen_nic_change_mtu(struct net_device *netdev, int new_mtu); -int netxen_config_hw_lro(struct netxen_adapter *adapter, int enable); -int netxen_config_bridged_mode(struct netxen_adapter *adapter, int enable); -int netxen_send_lro_cleanup(struct netxen_adapter *adapter); - -void netxen_nic_update_cmd_producer(struct netxen_adapter *adapter, - struct nx_host_tx_ring *tx_ring); - -/* Functions from netxen_nic_main.c */ -int netxen_nic_reset_context(struct netxen_adapter *); - -/* - * NetXen Board information - */ - -#define NETXEN_MAX_SHORT_NAME 32 -struct netxen_brdinfo { - int brdtype; /* type of board */ - long ports; /* max no of physical ports */ - char short_name[NETXEN_MAX_SHORT_NAME]; -}; - -static const struct netxen_brdinfo netxen_boards[] = { - {NETXEN_BRDTYPE_P2_SB31_10G_CX4, 1, "XGb CX4"}, - {NETXEN_BRDTYPE_P2_SB31_10G_HMEZ, 1, "XGb HMEZ"}, - {NETXEN_BRDTYPE_P2_SB31_10G_IMEZ, 2, "XGb IMEZ"}, - {NETXEN_BRDTYPE_P2_SB31_10G, 1, "XGb XFP"}, - {NETXEN_BRDTYPE_P2_SB35_4G, 4, "Quad Gb"}, - {NETXEN_BRDTYPE_P2_SB31_2G, 2, "Dual Gb"}, - {NETXEN_BRDTYPE_P3_REF_QG, 4, "Reference Quad Gig "}, - {NETXEN_BRDTYPE_P3_HMEZ, 2, "Dual XGb HMEZ"}, - {NETXEN_BRDTYPE_P3_10G_CX4_LP, 2, "Dual XGb CX4 LP"}, - {NETXEN_BRDTYPE_P3_4_GB, 4, "Quad Gig LP"}, - {NETXEN_BRDTYPE_P3_IMEZ, 2, "Dual XGb IMEZ"}, - {NETXEN_BRDTYPE_P3_10G_SFP_PLUS, 2, "Dual XGb SFP+ LP"}, - {NETXEN_BRDTYPE_P3_10000_BASE_T, 1, "XGB 10G BaseT LP"}, - {NETXEN_BRDTYPE_P3_XG_LOM, 2, "Dual XGb LOM"}, - {NETXEN_BRDTYPE_P3_4_GB_MM, 4, "NX3031 Gigabit Ethernet"}, - {NETXEN_BRDTYPE_P3_10G_SFP_CT, 2, "NX3031 10 Gigabit Ethernet"}, - {NETXEN_BRDTYPE_P3_10G_SFP_QT, 2, "Quanta Dual XGb SFP+"}, - {NETXEN_BRDTYPE_P3_10G_CX4, 2, "Reference Dual CX4 Option"}, - {NETXEN_BRDTYPE_P3_10G_XFP, 1, "Reference Single XFP Option"} -}; - -#define NUM_SUPPORTED_BOARDS ARRAY_SIZE(netxen_boards) - -static inline void get_brd_name_by_type(u32 type, char *name) -{ - int i, found = 0; - for (i = 0; i < NUM_SUPPORTED_BOARDS; ++i) { - if (netxen_boards[i].brdtype == type) { - strcpy(name, netxen_boards[i].short_name); - found = 1; - break; - } - - } - if (!found) - name = "Unknown"; -} - -static inline u32 netxen_tx_avail(struct nx_host_tx_ring *tx_ring) -{ - smp_mb(); - return find_diff_among(tx_ring->producer, - tx_ring->sw_consumer, tx_ring->num_desc); - -} - -int netxen_get_flash_mac_addr(struct netxen_adapter *adapter, u64 *mac); -int netxen_p3_get_mac_addr(struct netxen_adapter *adapter, u64 *mac); -extern void netxen_change_ringparam(struct netxen_adapter *adapter); -extern int netxen_rom_fast_read(struct netxen_adapter *adapter, int addr, - int *valp); - -extern const struct ethtool_ops netxen_nic_ethtool_ops; - -#endif /* __NETXEN_NIC_H_ */ diff --git a/drivers/net/netxen/netxen_nic_ctx.c b/drivers/net/netxen/netxen_nic_ctx.c deleted file mode 100644 index a925392abd6f..000000000000 --- a/drivers/net/netxen/netxen_nic_ctx.c +++ /dev/null @@ -1,793 +0,0 @@ -/* - * Copyright (C) 2003 - 2009 NetXen, Inc. - * Copyright (C) 2009 - QLogic Corporation. - * All rights reserved. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, - * MA 02111-1307, USA. - * - * The full GNU General Public License is included in this distribution - * in the file called "COPYING". - * - */ - -#include "netxen_nic_hw.h" -#include "netxen_nic.h" - -#define NXHAL_VERSION 1 - -static u32 -netxen_poll_rsp(struct netxen_adapter *adapter) -{ - u32 rsp = NX_CDRP_RSP_OK; - int timeout = 0; - - do { - /* give atleast 1ms for firmware to respond */ - msleep(1); - - if (++timeout > NX_OS_CRB_RETRY_COUNT) - return NX_CDRP_RSP_TIMEOUT; - - rsp = NXRD32(adapter, NX_CDRP_CRB_OFFSET); - } while (!NX_CDRP_IS_RSP(rsp)); - - return rsp; -} - -static u32 -netxen_issue_cmd(struct netxen_adapter *adapter, - u32 pci_fn, u32 version, u32 arg1, u32 arg2, u32 arg3, u32 cmd) -{ - u32 rsp; - u32 signature = 0; - u32 rcode = NX_RCODE_SUCCESS; - - signature = NX_CDRP_SIGNATURE_MAKE(pci_fn, version); - - /* Acquire semaphore before accessing CRB */ - if (netxen_api_lock(adapter)) - return NX_RCODE_TIMEOUT; - - NXWR32(adapter, NX_SIGN_CRB_OFFSET, signature); - - NXWR32(adapter, NX_ARG1_CRB_OFFSET, arg1); - - NXWR32(adapter, NX_ARG2_CRB_OFFSET, arg2); - - NXWR32(adapter, NX_ARG3_CRB_OFFSET, arg3); - - NXWR32(adapter, NX_CDRP_CRB_OFFSET, NX_CDRP_FORM_CMD(cmd)); - - rsp = netxen_poll_rsp(adapter); - - if (rsp == NX_CDRP_RSP_TIMEOUT) { - printk(KERN_ERR "%s: card response timeout.\n", - netxen_nic_driver_name); - - rcode = NX_RCODE_TIMEOUT; - } else if (rsp == NX_CDRP_RSP_FAIL) { - rcode = NXRD32(adapter, NX_ARG1_CRB_OFFSET); - - printk(KERN_ERR "%s: failed card response code:0x%x\n", - netxen_nic_driver_name, rcode); - } - - /* Release semaphore */ - netxen_api_unlock(adapter); - - return rcode; -} - -int -nx_fw_cmd_set_mtu(struct netxen_adapter *adapter, int mtu) -{ - u32 rcode = NX_RCODE_SUCCESS; - struct netxen_recv_context *recv_ctx = &adapter->recv_ctx; - - if (recv_ctx->state == NX_HOST_CTX_STATE_ACTIVE) - rcode = netxen_issue_cmd(adapter, - adapter->ahw.pci_func, - NXHAL_VERSION, - recv_ctx->context_id, - mtu, - 0, - NX_CDRP_CMD_SET_MTU); - - if (rcode != NX_RCODE_SUCCESS) - return -EIO; - - return 0; -} - -int -nx_fw_cmd_set_gbe_port(struct netxen_adapter *adapter, - u32 speed, u32 duplex, u32 autoneg) -{ - - return netxen_issue_cmd(adapter, - adapter->ahw.pci_func, - NXHAL_VERSION, - speed, - duplex, - autoneg, - NX_CDRP_CMD_CONFIG_GBE_PORT); - -} - -static int -nx_fw_cmd_create_rx_ctx(struct netxen_adapter *adapter) -{ - void *addr; - nx_hostrq_rx_ctx_t *prq; - nx_cardrsp_rx_ctx_t *prsp; - nx_hostrq_rds_ring_t *prq_rds; - nx_hostrq_sds_ring_t *prq_sds; - nx_cardrsp_rds_ring_t *prsp_rds; - nx_cardrsp_sds_ring_t *prsp_sds; - struct nx_host_rds_ring *rds_ring; - struct nx_host_sds_ring *sds_ring; - - dma_addr_t hostrq_phys_addr, cardrsp_phys_addr; - u64 phys_addr; - - int i, nrds_rings, nsds_rings; - size_t rq_size, rsp_size; - u32 cap, reg, val; - - int err; - - struct netxen_recv_context *recv_ctx = &adapter->recv_ctx; - - nrds_rings = adapter->max_rds_rings; - nsds_rings = adapter->max_sds_rings; - - rq_size = - SIZEOF_HOSTRQ_RX(nx_hostrq_rx_ctx_t, nrds_rings, nsds_rings); - rsp_size = - SIZEOF_CARDRSP_RX(nx_cardrsp_rx_ctx_t, nrds_rings, nsds_rings); - - addr = pci_alloc_consistent(adapter->pdev, - rq_size, &hostrq_phys_addr); - if (addr == NULL) - return -ENOMEM; - prq = addr; - - addr = pci_alloc_consistent(adapter->pdev, - rsp_size, &cardrsp_phys_addr); - if (addr == NULL) { - err = -ENOMEM; - goto out_free_rq; - } - prsp = addr; - - prq->host_rsp_dma_addr = cpu_to_le64(cardrsp_phys_addr); - - cap = (NX_CAP0_LEGACY_CONTEXT | NX_CAP0_LEGACY_MN); - cap |= (NX_CAP0_JUMBO_CONTIGUOUS | NX_CAP0_LRO_CONTIGUOUS); - - prq->capabilities[0] = cpu_to_le32(cap); - prq->host_int_crb_mode = - cpu_to_le32(NX_HOST_INT_CRB_MODE_SHARED); - prq->host_rds_crb_mode = - cpu_to_le32(NX_HOST_RDS_CRB_MODE_UNIQUE); - - prq->num_rds_rings = cpu_to_le16(nrds_rings); - prq->num_sds_rings = cpu_to_le16(nsds_rings); - prq->rds_ring_offset = cpu_to_le32(0); - - val = le32_to_cpu(prq->rds_ring_offset) + - (sizeof(nx_hostrq_rds_ring_t) * nrds_rings); - prq->sds_ring_offset = cpu_to_le32(val); - - prq_rds = (nx_hostrq_rds_ring_t *)(prq->data + - le32_to_cpu(prq->rds_ring_offset)); - - for (i = 0; i < nrds_rings; i++) { - - rds_ring = &recv_ctx->rds_rings[i]; - - prq_rds[i].host_phys_addr = cpu_to_le64(rds_ring->phys_addr); - prq_rds[i].ring_size = cpu_to_le32(rds_ring->num_desc); - prq_rds[i].ring_kind = cpu_to_le32(i); - prq_rds[i].buff_size = cpu_to_le64(rds_ring->dma_size); - } - - prq_sds = (nx_hostrq_sds_ring_t *)(prq->data + - le32_to_cpu(prq->sds_ring_offset)); - - for (i = 0; i < nsds_rings; i++) { - - sds_ring = &recv_ctx->sds_rings[i]; - - prq_sds[i].host_phys_addr = cpu_to_le64(sds_ring->phys_addr); - prq_sds[i].ring_size = cpu_to_le32(sds_ring->num_desc); - prq_sds[i].msi_index = cpu_to_le16(i); - } - - phys_addr = hostrq_phys_addr; - err = netxen_issue_cmd(adapter, - adapter->ahw.pci_func, - NXHAL_VERSION, - (u32)(phys_addr >> 32), - (u32)(phys_addr & 0xffffffff), - rq_size, - NX_CDRP_CMD_CREATE_RX_CTX); - if (err) { - printk(KERN_WARNING - "Failed to create rx ctx in firmware%d\n", err); - goto out_free_rsp; - } - - - prsp_rds = ((nx_cardrsp_rds_ring_t *) - &prsp->data[le32_to_cpu(prsp->rds_ring_offset)]); - - for (i = 0; i < le16_to_cpu(prsp->num_rds_rings); i++) { - rds_ring = &recv_ctx->rds_rings[i]; - - reg = le32_to_cpu(prsp_rds[i].host_producer_crb); - rds_ring->crb_rcv_producer = netxen_get_ioaddr(adapter, - NETXEN_NIC_REG(reg - 0x200)); - } - - prsp_sds = ((nx_cardrsp_sds_ring_t *) - &prsp->data[le32_to_cpu(prsp->sds_ring_offset)]); - - for (i = 0; i < le16_to_cpu(prsp->num_sds_rings); i++) { - sds_ring = &recv_ctx->sds_rings[i]; - - reg = le32_to_cpu(prsp_sds[i].host_consumer_crb); - sds_ring->crb_sts_consumer = netxen_get_ioaddr(adapter, - NETXEN_NIC_REG(reg - 0x200)); - - reg = le32_to_cpu(prsp_sds[i].interrupt_crb); - sds_ring->crb_intr_mask = netxen_get_ioaddr(adapter, - NETXEN_NIC_REG(reg - 0x200)); - } - - recv_ctx->state = le32_to_cpu(prsp->host_ctx_state); - recv_ctx->context_id = le16_to_cpu(prsp->context_id); - recv_ctx->virt_port = prsp->virt_port; - -out_free_rsp: - pci_free_consistent(adapter->pdev, rsp_size, prsp, cardrsp_phys_addr); -out_free_rq: - pci_free_consistent(adapter->pdev, rq_size, prq, hostrq_phys_addr); - return err; -} - -static void -nx_fw_cmd_destroy_rx_ctx(struct netxen_adapter *adapter) -{ - struct netxen_recv_context *recv_ctx = &adapter->recv_ctx; - - if (netxen_issue_cmd(adapter, - adapter->ahw.pci_func, - NXHAL_VERSION, - recv_ctx->context_id, - NX_DESTROY_CTX_RESET, - 0, - NX_CDRP_CMD_DESTROY_RX_CTX)) { - - printk(KERN_WARNING - "%s: Failed to destroy rx ctx in firmware\n", - netxen_nic_driver_name); - } -} - -static int -nx_fw_cmd_create_tx_ctx(struct netxen_adapter *adapter) -{ - nx_hostrq_tx_ctx_t *prq; - nx_hostrq_cds_ring_t *prq_cds; - nx_cardrsp_tx_ctx_t *prsp; - void *rq_addr, *rsp_addr; - size_t rq_size, rsp_size; - u32 temp; - int err = 0; - u64 offset, phys_addr; - dma_addr_t rq_phys_addr, rsp_phys_addr; - struct nx_host_tx_ring *tx_ring = adapter->tx_ring; - struct netxen_recv_context *recv_ctx = &adapter->recv_ctx; - - rq_size = SIZEOF_HOSTRQ_TX(nx_hostrq_tx_ctx_t); - rq_addr = pci_alloc_consistent(adapter->pdev, - rq_size, &rq_phys_addr); - if (!rq_addr) - return -ENOMEM; - - rsp_size = SIZEOF_CARDRSP_TX(nx_cardrsp_tx_ctx_t); - rsp_addr = pci_alloc_consistent(adapter->pdev, - rsp_size, &rsp_phys_addr); - if (!rsp_addr) { - err = -ENOMEM; - goto out_free_rq; - } - - memset(rq_addr, 0, rq_size); - prq = rq_addr; - - memset(rsp_addr, 0, rsp_size); - prsp = rsp_addr; - - prq->host_rsp_dma_addr = cpu_to_le64(rsp_phys_addr); - - temp = (NX_CAP0_LEGACY_CONTEXT | NX_CAP0_LEGACY_MN | NX_CAP0_LSO); - prq->capabilities[0] = cpu_to_le32(temp); - - prq->host_int_crb_mode = - cpu_to_le32(NX_HOST_INT_CRB_MODE_SHARED); - - prq->interrupt_ctl = 0; - prq->msi_index = 0; - - prq->dummy_dma_addr = cpu_to_le64(adapter->dummy_dma.phys_addr); - - offset = recv_ctx->phys_addr + sizeof(struct netxen_ring_ctx); - prq->cmd_cons_dma_addr = cpu_to_le64(offset); - - prq_cds = &prq->cds_ring; - - prq_cds->host_phys_addr = cpu_to_le64(tx_ring->phys_addr); - prq_cds->ring_size = cpu_to_le32(tx_ring->num_desc); - - phys_addr = rq_phys_addr; - err = netxen_issue_cmd(adapter, - adapter->ahw.pci_func, - NXHAL_VERSION, - (u32)(phys_addr >> 32), - ((u32)phys_addr & 0xffffffff), - rq_size, - NX_CDRP_CMD_CREATE_TX_CTX); - - if (err == NX_RCODE_SUCCESS) { - temp = le32_to_cpu(prsp->cds_ring.host_producer_crb); - tx_ring->crb_cmd_producer = netxen_get_ioaddr(adapter, - NETXEN_NIC_REG(temp - 0x200)); -#if 0 - adapter->tx_state = - le32_to_cpu(prsp->host_ctx_state); -#endif - adapter->tx_context_id = - le16_to_cpu(prsp->context_id); - } else { - printk(KERN_WARNING - "Failed to create tx ctx in firmware%d\n", err); - err = -EIO; - } - - pci_free_consistent(adapter->pdev, rsp_size, rsp_addr, rsp_phys_addr); - -out_free_rq: - pci_free_consistent(adapter->pdev, rq_size, rq_addr, rq_phys_addr); - - return err; -} - -static void -nx_fw_cmd_destroy_tx_ctx(struct netxen_adapter *adapter) -{ - if (netxen_issue_cmd(adapter, - adapter->ahw.pci_func, - NXHAL_VERSION, - adapter->tx_context_id, - NX_DESTROY_CTX_RESET, - 0, - NX_CDRP_CMD_DESTROY_TX_CTX)) { - - printk(KERN_WARNING - "%s: Failed to destroy tx ctx in firmware\n", - netxen_nic_driver_name); - } -} - -int -nx_fw_cmd_query_phy(struct netxen_adapter *adapter, u32 reg, u32 *val) -{ - u32 rcode; - - rcode = netxen_issue_cmd(adapter, - adapter->ahw.pci_func, - NXHAL_VERSION, - reg, - 0, - 0, - NX_CDRP_CMD_READ_PHY); - - if (rcode != NX_RCODE_SUCCESS) - return -EIO; - - return NXRD32(adapter, NX_ARG1_CRB_OFFSET); -} - -int -nx_fw_cmd_set_phy(struct netxen_adapter *adapter, u32 reg, u32 val) -{ - u32 rcode; - - rcode = netxen_issue_cmd(adapter, - adapter->ahw.pci_func, - NXHAL_VERSION, - reg, - val, - 0, - NX_CDRP_CMD_WRITE_PHY); - - if (rcode != NX_RCODE_SUCCESS) - return -EIO; - - return 0; -} - -static u64 ctx_addr_sig_regs[][3] = { - {NETXEN_NIC_REG(0x188), NETXEN_NIC_REG(0x18c), NETXEN_NIC_REG(0x1c0)}, - {NETXEN_NIC_REG(0x190), NETXEN_NIC_REG(0x194), NETXEN_NIC_REG(0x1c4)}, - {NETXEN_NIC_REG(0x198), NETXEN_NIC_REG(0x19c), NETXEN_NIC_REG(0x1c8)}, - {NETXEN_NIC_REG(0x1a0), NETXEN_NIC_REG(0x1a4), NETXEN_NIC_REG(0x1cc)} -}; - -#define CRB_CTX_ADDR_REG_LO(FUNC_ID) (ctx_addr_sig_regs[FUNC_ID][0]) -#define CRB_CTX_ADDR_REG_HI(FUNC_ID) (ctx_addr_sig_regs[FUNC_ID][2]) -#define CRB_CTX_SIGNATURE_REG(FUNC_ID) (ctx_addr_sig_regs[FUNC_ID][1]) - -#define lower32(x) ((u32)((x) & 0xffffffff)) -#define upper32(x) ((u32)(((u64)(x) >> 32) & 0xffffffff)) - -static struct netxen_recv_crb recv_crb_registers[] = { - /* Instance 0 */ - { - /* crb_rcv_producer: */ - { - NETXEN_NIC_REG(0x100), - /* Jumbo frames */ - NETXEN_NIC_REG(0x110), - /* LRO */ - NETXEN_NIC_REG(0x120) - }, - /* crb_sts_consumer: */ - { - NETXEN_NIC_REG(0x138), - NETXEN_NIC_REG_2(0x000), - NETXEN_NIC_REG_2(0x004), - NETXEN_NIC_REG_2(0x008), - }, - /* sw_int_mask */ - { - CRB_SW_INT_MASK_0, - NETXEN_NIC_REG_2(0x044), - NETXEN_NIC_REG_2(0x048), - NETXEN_NIC_REG_2(0x04c), - }, - }, - /* Instance 1 */ - { - /* crb_rcv_producer: */ - { - NETXEN_NIC_REG(0x144), - /* Jumbo frames */ - NETXEN_NIC_REG(0x154), - /* LRO */ - NETXEN_NIC_REG(0x164) - }, - /* crb_sts_consumer: */ - { - NETXEN_NIC_REG(0x17c), - NETXEN_NIC_REG_2(0x020), - NETXEN_NIC_REG_2(0x024), - NETXEN_NIC_REG_2(0x028), - }, - /* sw_int_mask */ - { - CRB_SW_INT_MASK_1, - NETXEN_NIC_REG_2(0x064), - NETXEN_NIC_REG_2(0x068), - NETXEN_NIC_REG_2(0x06c), - }, - }, - /* Instance 2 */ - { - /* crb_rcv_producer: */ - { - NETXEN_NIC_REG(0x1d8), - /* Jumbo frames */ - NETXEN_NIC_REG(0x1f8), - /* LRO */ - NETXEN_NIC_REG(0x208) - }, - /* crb_sts_consumer: */ - { - NETXEN_NIC_REG(0x220), - NETXEN_NIC_REG_2(0x03c), - NETXEN_NIC_REG_2(0x03c), - NETXEN_NIC_REG_2(0x03c), - }, - /* sw_int_mask */ - { - CRB_SW_INT_MASK_2, - NETXEN_NIC_REG_2(0x03c), - NETXEN_NIC_REG_2(0x03c), - NETXEN_NIC_REG_2(0x03c), - }, - }, - /* Instance 3 */ - { - /* crb_rcv_producer: */ - { - NETXEN_NIC_REG(0x22c), - /* Jumbo frames */ - NETXEN_NIC_REG(0x23c), - /* LRO */ - NETXEN_NIC_REG(0x24c) - }, - /* crb_sts_consumer: */ - { - NETXEN_NIC_REG(0x264), - NETXEN_NIC_REG_2(0x03c), - NETXEN_NIC_REG_2(0x03c), - NETXEN_NIC_REG_2(0x03c), - }, - /* sw_int_mask */ - { - CRB_SW_INT_MASK_3, - NETXEN_NIC_REG_2(0x03c), - NETXEN_NIC_REG_2(0x03c), - NETXEN_NIC_REG_2(0x03c), - }, - }, -}; - -static int -netxen_init_old_ctx(struct netxen_adapter *adapter) -{ - struct netxen_recv_context *recv_ctx; - struct nx_host_rds_ring *rds_ring; - struct nx_host_sds_ring *sds_ring; - struct nx_host_tx_ring *tx_ring; - int ring; - int port = adapter->portnum; - struct netxen_ring_ctx *hwctx; - u32 signature; - - tx_ring = adapter->tx_ring; - recv_ctx = &adapter->recv_ctx; - hwctx = recv_ctx->hwctx; - - hwctx->cmd_ring_addr = cpu_to_le64(tx_ring->phys_addr); - hwctx->cmd_ring_size = cpu_to_le32(tx_ring->num_desc); - - - for (ring = 0; ring < adapter->max_rds_rings; ring++) { - rds_ring = &recv_ctx->rds_rings[ring]; - - hwctx->rcv_rings[ring].addr = - cpu_to_le64(rds_ring->phys_addr); - hwctx->rcv_rings[ring].size = - cpu_to_le32(rds_ring->num_desc); - } - - for (ring = 0; ring < adapter->max_sds_rings; ring++) { - sds_ring = &recv_ctx->sds_rings[ring]; - - if (ring == 0) { - hwctx->sts_ring_addr = cpu_to_le64(sds_ring->phys_addr); - hwctx->sts_ring_size = cpu_to_le32(sds_ring->num_desc); - } - hwctx->sts_rings[ring].addr = cpu_to_le64(sds_ring->phys_addr); - hwctx->sts_rings[ring].size = cpu_to_le32(sds_ring->num_desc); - hwctx->sts_rings[ring].msi_index = cpu_to_le16(ring); - } - hwctx->sts_ring_count = cpu_to_le32(adapter->max_sds_rings); - - signature = (adapter->max_sds_rings > 1) ? - NETXEN_CTX_SIGNATURE_V2 : NETXEN_CTX_SIGNATURE; - - NXWR32(adapter, CRB_CTX_ADDR_REG_LO(port), - lower32(recv_ctx->phys_addr)); - NXWR32(adapter, CRB_CTX_ADDR_REG_HI(port), - upper32(recv_ctx->phys_addr)); - NXWR32(adapter, CRB_CTX_SIGNATURE_REG(port), - signature | port); - return 0; -} - -int netxen_alloc_hw_resources(struct netxen_adapter *adapter) -{ - void *addr; - int err = 0; - int ring; - struct netxen_recv_context *recv_ctx; - struct nx_host_rds_ring *rds_ring; - struct nx_host_sds_ring *sds_ring; - struct nx_host_tx_ring *tx_ring; - - struct pci_dev *pdev = adapter->pdev; - struct net_device *netdev = adapter->netdev; - int port = adapter->portnum; - - recv_ctx = &adapter->recv_ctx; - tx_ring = adapter->tx_ring; - - addr = pci_alloc_consistent(pdev, - sizeof(struct netxen_ring_ctx) + sizeof(uint32_t), - &recv_ctx->phys_addr); - if (addr == NULL) { - dev_err(&pdev->dev, "failed to allocate hw context\n"); - return -ENOMEM; - } - - memset(addr, 0, sizeof(struct netxen_ring_ctx)); - recv_ctx->hwctx = addr; - recv_ctx->hwctx->ctx_id = cpu_to_le32(port); - recv_ctx->hwctx->cmd_consumer_offset = - cpu_to_le64(recv_ctx->phys_addr + - sizeof(struct netxen_ring_ctx)); - tx_ring->hw_consumer = - (__le32 *)(((char *)addr) + sizeof(struct netxen_ring_ctx)); - - /* cmd desc ring */ - addr = pci_alloc_consistent(pdev, TX_DESC_RINGSIZE(tx_ring), - &tx_ring->phys_addr); - - if (addr == NULL) { - dev_err(&pdev->dev, "%s: failed to allocate tx desc ring\n", - netdev->name); - err = -ENOMEM; - goto err_out_free; - } - - tx_ring->desc_head = addr; - - for (ring = 0; ring < adapter->max_rds_rings; ring++) { - rds_ring = &recv_ctx->rds_rings[ring]; - addr = pci_alloc_consistent(adapter->pdev, - RCV_DESC_RINGSIZE(rds_ring), - &rds_ring->phys_addr); - if (addr == NULL) { - dev_err(&pdev->dev, - "%s: failed to allocate rds ring [%d]\n", - netdev->name, ring); - err = -ENOMEM; - goto err_out_free; - } - rds_ring->desc_head = addr; - - if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) - rds_ring->crb_rcv_producer = - netxen_get_ioaddr(adapter, - recv_crb_registers[port].crb_rcv_producer[ring]); - } - - for (ring = 0; ring < adapter->max_sds_rings; ring++) { - sds_ring = &recv_ctx->sds_rings[ring]; - - addr = pci_alloc_consistent(adapter->pdev, - STATUS_DESC_RINGSIZE(sds_ring), - &sds_ring->phys_addr); - if (addr == NULL) { - dev_err(&pdev->dev, - "%s: failed to allocate sds ring [%d]\n", - netdev->name, ring); - err = -ENOMEM; - goto err_out_free; - } - sds_ring->desc_head = addr; - - if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) { - sds_ring->crb_sts_consumer = - netxen_get_ioaddr(adapter, - recv_crb_registers[port].crb_sts_consumer[ring]); - - sds_ring->crb_intr_mask = - netxen_get_ioaddr(adapter, - recv_crb_registers[port].sw_int_mask[ring]); - } - } - - - if (!NX_IS_REVISION_P2(adapter->ahw.revision_id)) { - if (test_and_set_bit(__NX_FW_ATTACHED, &adapter->state)) - goto done; - err = nx_fw_cmd_create_rx_ctx(adapter); - if (err) - goto err_out_free; - err = nx_fw_cmd_create_tx_ctx(adapter); - if (err) - goto err_out_free; - } else { - err = netxen_init_old_ctx(adapter); - if (err) - goto err_out_free; - } - -done: - return 0; - -err_out_free: - netxen_free_hw_resources(adapter); - return err; -} - -void netxen_free_hw_resources(struct netxen_adapter *adapter) -{ - struct netxen_recv_context *recv_ctx; - struct nx_host_rds_ring *rds_ring; - struct nx_host_sds_ring *sds_ring; - struct nx_host_tx_ring *tx_ring; - int ring; - - int port = adapter->portnum; - - if (!NX_IS_REVISION_P2(adapter->ahw.revision_id)) { - if (!test_and_clear_bit(__NX_FW_ATTACHED, &adapter->state)) - goto done; - - nx_fw_cmd_destroy_rx_ctx(adapter); - nx_fw_cmd_destroy_tx_ctx(adapter); - } else { - netxen_api_lock(adapter); - NXWR32(adapter, CRB_CTX_SIGNATURE_REG(port), - NETXEN_CTX_D3_RESET | port); - netxen_api_unlock(adapter); - } - - /* Allow dma queues to drain after context reset */ - msleep(20); - -done: - recv_ctx = &adapter->recv_ctx; - - if (recv_ctx->hwctx != NULL) { - pci_free_consistent(adapter->pdev, - sizeof(struct netxen_ring_ctx) + - sizeof(uint32_t), - recv_ctx->hwctx, - recv_ctx->phys_addr); - recv_ctx->hwctx = NULL; - } - - tx_ring = adapter->tx_ring; - if (tx_ring->desc_head != NULL) { - pci_free_consistent(adapter->pdev, - TX_DESC_RINGSIZE(tx_ring), - tx_ring->desc_head, tx_ring->phys_addr); - tx_ring->desc_head = NULL; - } - - for (ring = 0; ring < adapter->max_rds_rings; ring++) { - rds_ring = &recv_ctx->rds_rings[ring]; - - if (rds_ring->desc_head != NULL) { - pci_free_consistent(adapter->pdev, - RCV_DESC_RINGSIZE(rds_ring), - rds_ring->desc_head, - rds_ring->phys_addr); - rds_ring->desc_head = NULL; - } - } - - for (ring = 0; ring < adapter->max_sds_rings; ring++) { - sds_ring = &recv_ctx->sds_rings[ring]; - - if (sds_ring->desc_head != NULL) { - pci_free_consistent(adapter->pdev, - STATUS_DESC_RINGSIZE(sds_ring), - sds_ring->desc_head, - sds_ring->phys_addr); - sds_ring->desc_head = NULL; - } - } -} - diff --git a/drivers/net/netxen/netxen_nic_ethtool.c b/drivers/net/netxen/netxen_nic_ethtool.c deleted file mode 100644 index b34fb74d07e3..000000000000 --- a/drivers/net/netxen/netxen_nic_ethtool.c +++ /dev/null @@ -1,835 +0,0 @@ -/* - * Copyright (C) 2003 - 2009 NetXen, Inc. - * Copyright (C) 2009 - QLogic Corporation. - * All rights reserved. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, - * MA 02111-1307, USA. - * - * The full GNU General Public License is included in this distribution - * in the file called "COPYING". - * - */ - -#include <linux/types.h> -#include <linux/delay.h> -#include <linux/pci.h> -#include <asm/io.h> -#include <linux/netdevice.h> -#include <linux/ethtool.h> - -#include "netxen_nic.h" -#include "netxen_nic_hw.h" - -struct netxen_nic_stats { - char stat_string[ETH_GSTRING_LEN]; - int sizeof_stat; - int stat_offset; -}; - -#define NETXEN_NIC_STAT(m) sizeof(((struct netxen_adapter *)0)->m), \ - offsetof(struct netxen_adapter, m) - -#define NETXEN_NIC_PORT_WINDOW 0x10000 -#define NETXEN_NIC_INVALID_DATA 0xDEADBEEF - -static const struct netxen_nic_stats netxen_nic_gstrings_stats[] = { - {"xmit_called", NETXEN_NIC_STAT(stats.xmitcalled)}, - {"xmit_finished", NETXEN_NIC_STAT(stats.xmitfinished)}, - {"rx_dropped", NETXEN_NIC_STAT(stats.rxdropped)}, - {"tx_dropped", NETXEN_NIC_STAT(stats.txdropped)}, - {"csummed", NETXEN_NIC_STAT(stats.csummed)}, - {"rx_pkts", NETXEN_NIC_STAT(stats.rx_pkts)}, - {"lro_pkts", NETXEN_NIC_STAT(stats.lro_pkts)}, - {"rx_bytes", NETXEN_NIC_STAT(stats.rxbytes)}, - {"tx_bytes", NETXEN_NIC_STAT(stats.txbytes)}, -}; - -#define NETXEN_NIC_STATS_LEN ARRAY_SIZE(netxen_nic_gstrings_stats) - -static const char netxen_nic_gstrings_test[][ETH_GSTRING_LEN] = { - "Register_Test_on_offline", - "Link_Test_on_offline" -}; - -#define NETXEN_NIC_TEST_LEN ARRAY_SIZE(netxen_nic_gstrings_test) - -#define NETXEN_NIC_REGS_COUNT 30 -#define NETXEN_NIC_REGS_LEN (NETXEN_NIC_REGS_COUNT * sizeof(__le32)) -#define NETXEN_MAX_EEPROM_LEN 1024 - -static int netxen_nic_get_eeprom_len(struct net_device *dev) -{ - return NETXEN_FLASH_TOTAL_SIZE; -} - -static void -netxen_nic_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *drvinfo) -{ - struct netxen_adapter *adapter = netdev_priv(dev); - u32 fw_major = 0; - u32 fw_minor = 0; - u32 fw_build = 0; - - strncpy(drvinfo->driver, netxen_nic_driver_name, 32); - strncpy(drvinfo->version, NETXEN_NIC_LINUX_VERSIONID, 32); - fw_major = NXRD32(adapter, NETXEN_FW_VERSION_MAJOR); - fw_minor = NXRD32(adapter, NETXEN_FW_VERSION_MINOR); - fw_build = NXRD32(adapter, NETXEN_FW_VERSION_SUB); - sprintf(drvinfo->fw_version, "%d.%d.%d", fw_major, fw_minor, fw_build); - - strncpy(drvinfo->bus_info, pci_name(adapter->pdev), 32); - drvinfo->regdump_len = NETXEN_NIC_REGS_LEN; - drvinfo->eedump_len = netxen_nic_get_eeprom_len(dev); -} - -static int -netxen_nic_get_settings(struct net_device *dev, struct ethtool_cmd *ecmd) -{ - struct netxen_adapter *adapter = netdev_priv(dev); - int check_sfp_module = 0; - - /* read which mode */ - if (adapter->ahw.port_type == NETXEN_NIC_GBE) { - ecmd->supported = (SUPPORTED_10baseT_Half | - SUPPORTED_10baseT_Full | - SUPPORTED_100baseT_Half | - SUPPORTED_100baseT_Full | - SUPPORTED_1000baseT_Half | - SUPPORTED_1000baseT_Full); - - ecmd->advertising = (ADVERTISED_100baseT_Half | - ADVERTISED_100baseT_Full | - ADVERTISED_1000baseT_Half | - ADVERTISED_1000baseT_Full); - - ecmd->port = PORT_TP; - - ethtool_cmd_speed_set(ecmd, adapter->link_speed); - ecmd->duplex = adapter->link_duplex; - ecmd->autoneg = adapter->link_autoneg; - - } else if (adapter->ahw.port_type == NETXEN_NIC_XGBE) { - u32 val; - - val = NXRD32(adapter, NETXEN_PORT_MODE_ADDR); - if (val == NETXEN_PORT_MODE_802_3_AP) { - ecmd->supported = SUPPORTED_1000baseT_Full; - ecmd->advertising = ADVERTISED_1000baseT_Full; - } else { - ecmd->supported = SUPPORTED_10000baseT_Full; - ecmd->advertising = ADVERTISED_10000baseT_Full; - } - - if (netif_running(dev) && adapter->has_link_events) { - ethtool_cmd_speed_set(ecmd, adapter->link_speed); - ecmd->autoneg = adapter->link_autoneg; - ecmd->duplex = adapter->link_duplex; - goto skip; - } - - ecmd->port = PORT_TP; - - if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) { - u16 pcifn = adapter->ahw.pci_func; - - val = NXRD32(adapter, P3_LINK_SPEED_REG(pcifn)); - ethtool_cmd_speed_set(ecmd, P3_LINK_SPEED_MHZ * - P3_LINK_SPEED_VAL(pcifn, val)); - } else - ethtool_cmd_speed_set(ecmd, SPEED_10000); - - ecmd->duplex = DUPLEX_FULL; - ecmd->autoneg = AUTONEG_DISABLE; - } else - return -EIO; - -skip: - ecmd->phy_address = adapter->physical_port; - ecmd->transceiver = XCVR_EXTERNAL; - - switch (adapter->ahw.board_type) { - case NETXEN_BRDTYPE_P2_SB35_4G: - case NETXEN_BRDTYPE_P2_SB31_2G: - case NETXEN_BRDTYPE_P3_REF_QG: - case NETXEN_BRDTYPE_P3_4_GB: - case NETXEN_BRDTYPE_P3_4_GB_MM: - - ecmd->supported |= SUPPORTED_Autoneg; - ecmd->advertising |= ADVERTISED_Autoneg; - case NETXEN_BRDTYPE_P2_SB31_10G_CX4: - case NETXEN_BRDTYPE_P3_10G_CX4: - case NETXEN_BRDTYPE_P3_10G_CX4_LP: - case NETXEN_BRDTYPE_P3_10000_BASE_T: - ecmd->supported |= SUPPORTED_TP; - ecmd->advertising |= ADVERTISED_TP; - ecmd->port = PORT_TP; - ecmd->autoneg = (adapter->ahw.board_type == - NETXEN_BRDTYPE_P2_SB31_10G_CX4) ? - (AUTONEG_DISABLE) : (adapter->link_autoneg); - break; - case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ: - case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ: - case NETXEN_BRDTYPE_P3_IMEZ: - case NETXEN_BRDTYPE_P3_XG_LOM: - case NETXEN_BRDTYPE_P3_HMEZ: - ecmd->supported |= SUPPORTED_MII; - ecmd->advertising |= ADVERTISED_MII; - ecmd->port = PORT_MII; - ecmd->autoneg = AUTONEG_DISABLE; - break; - case NETXEN_BRDTYPE_P3_10G_SFP_PLUS: - case NETXEN_BRDTYPE_P3_10G_SFP_CT: - case NETXEN_BRDTYPE_P3_10G_SFP_QT: - ecmd->advertising |= ADVERTISED_TP; - ecmd->supported |= SUPPORTED_TP; - check_sfp_module = netif_running(dev) && - adapter->has_link_events; - case NETXEN_BRDTYPE_P2_SB31_10G: - case NETXEN_BRDTYPE_P3_10G_XFP: - ecmd->supported |= SUPPORTED_FIBRE; - ecmd->advertising |= ADVERTISED_FIBRE; - ecmd->port = PORT_FIBRE; - ecmd->autoneg = AUTONEG_DISABLE; - break; - case NETXEN_BRDTYPE_P3_10G_TP: - if (adapter->ahw.port_type == NETXEN_NIC_XGBE) { - ecmd->autoneg = AUTONEG_DISABLE; - ecmd->supported |= (SUPPORTED_FIBRE | SUPPORTED_TP); - ecmd->advertising |= - (ADVERTISED_FIBRE | ADVERTISED_TP); - ecmd->port = PORT_FIBRE; - check_sfp_module = netif_running(dev) && - adapter->has_link_events; - } else { - ecmd->supported |= (SUPPORTED_TP |SUPPORTED_Autoneg); - ecmd->advertising |= - (ADVERTISED_TP | ADVERTISED_Autoneg); - ecmd->port = PORT_TP; - } - break; - default: - printk(KERN_ERR "netxen-nic: Unsupported board model %d\n", - adapter->ahw.board_type); - return -EIO; - } - - if (check_sfp_module) { - switch (adapter->module_type) { - case LINKEVENT_MODULE_OPTICAL_UNKNOWN: - case LINKEVENT_MODULE_OPTICAL_SRLR: - case LINKEVENT_MODULE_OPTICAL_LRM: - case LINKEVENT_MODULE_OPTICAL_SFP_1G: - ecmd->port = PORT_FIBRE; - break; - case LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLE: - case LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLELEN: - case LINKEVENT_MODULE_TWINAX: - ecmd->port = PORT_TP; - break; - default: - ecmd->port = -1; - } - } - - return 0; -} - -static int -netxen_nic_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd) -{ - struct netxen_adapter *adapter = netdev_priv(dev); - u32 speed = ethtool_cmd_speed(ecmd); - int ret; - - if (adapter->ahw.port_type != NETXEN_NIC_GBE) - return -EOPNOTSUPP; - - if (!(adapter->capabilities & NX_FW_CAPABILITY_GBE_LINK_CFG)) - return -EOPNOTSUPP; - - ret = nx_fw_cmd_set_gbe_port(adapter, speed, ecmd->duplex, - ecmd->autoneg); - if (ret == NX_RCODE_NOT_SUPPORTED) - return -EOPNOTSUPP; - else if (ret) - return -EIO; - - adapter->link_speed = speed; - adapter->link_duplex = ecmd->duplex; - adapter->link_autoneg = ecmd->autoneg; - - if (!netif_running(dev)) - return 0; - - dev->netdev_ops->ndo_stop(dev); - return dev->netdev_ops->ndo_open(dev); -} - -static int netxen_nic_get_regs_len(struct net_device *dev) -{ - return NETXEN_NIC_REGS_LEN; -} - -static void -netxen_nic_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *p) -{ - struct netxen_adapter *adapter = netdev_priv(dev); - struct netxen_recv_context *recv_ctx = &adapter->recv_ctx; - struct nx_host_sds_ring *sds_ring; - u32 *regs_buff = p; - int ring, i = 0; - int port = adapter->physical_port; - - memset(p, 0, NETXEN_NIC_REGS_LEN); - - regs->version = (1 << 24) | (adapter->ahw.revision_id << 16) | - (adapter->pdev)->device; - - if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC) - return; - - regs_buff[i++] = NXRD32(adapter, CRB_CMDPEG_STATE); - regs_buff[i++] = NXRD32(adapter, CRB_RCVPEG_STATE); - regs_buff[i++] = NXRD32(adapter, CRB_FW_CAPABILITIES_1); - regs_buff[i++] = NXRDIO(adapter, adapter->crb_int_state_reg); - regs_buff[i++] = NXRD32(adapter, NX_CRB_DEV_REF_COUNT); - regs_buff[i++] = NXRD32(adapter, NX_CRB_DEV_STATE); - regs_buff[i++] = NXRD32(adapter, NETXEN_PEG_ALIVE_COUNTER); - regs_buff[i++] = NXRD32(adapter, NETXEN_PEG_HALT_STATUS1); - regs_buff[i++] = NXRD32(adapter, NETXEN_PEG_HALT_STATUS2); - - regs_buff[i++] = NXRD32(adapter, NETXEN_CRB_PEG_NET_0+0x3c); - regs_buff[i++] = NXRD32(adapter, NETXEN_CRB_PEG_NET_1+0x3c); - regs_buff[i++] = NXRD32(adapter, NETXEN_CRB_PEG_NET_2+0x3c); - regs_buff[i++] = NXRD32(adapter, NETXEN_CRB_PEG_NET_3+0x3c); - - if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) { - - regs_buff[i++] = NXRD32(adapter, NETXEN_CRB_PEG_NET_4+0x3c); - i += 2; - - regs_buff[i++] = NXRD32(adapter, CRB_XG_STATE_P3); - regs_buff[i++] = le32_to_cpu(*(adapter->tx_ring->hw_consumer)); - - } else { - i++; - - regs_buff[i++] = NXRD32(adapter, - NETXEN_NIU_XGE_CONFIG_0+(0x10000*port)); - regs_buff[i++] = NXRD32(adapter, - NETXEN_NIU_XGE_CONFIG_1+(0x10000*port)); - - regs_buff[i++] = NXRD32(adapter, CRB_XG_STATE); - regs_buff[i++] = NXRDIO(adapter, - adapter->tx_ring->crb_cmd_consumer); - } - - regs_buff[i++] = NXRDIO(adapter, adapter->tx_ring->crb_cmd_producer); - - regs_buff[i++] = NXRDIO(adapter, - recv_ctx->rds_rings[0].crb_rcv_producer); - regs_buff[i++] = NXRDIO(adapter, - recv_ctx->rds_rings[1].crb_rcv_producer); - - regs_buff[i++] = adapter->max_sds_rings; - - for (ring = 0; ring < adapter->max_sds_rings; ring++) { - sds_ring = &(recv_ctx->sds_rings[ring]); - regs_buff[i++] = NXRDIO(adapter, - sds_ring->crb_sts_consumer); - } -} - -static u32 netxen_nic_test_link(struct net_device *dev) -{ - struct netxen_adapter *adapter = netdev_priv(dev); - u32 val, port; - - port = adapter->physical_port; - if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) { - val = NXRD32(adapter, CRB_XG_STATE_P3); - val = XG_LINK_STATE_P3(adapter->ahw.pci_func, val); - return (val == XG_LINK_UP_P3) ? 0 : 1; - } else { - val = NXRD32(adapter, CRB_XG_STATE); - val = (val >> port*8) & 0xff; - return (val == XG_LINK_UP) ? 0 : 1; - } -} - -static int -netxen_nic_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, - u8 * bytes) -{ - struct netxen_adapter *adapter = netdev_priv(dev); - int offset; - int ret; - - if (eeprom->len == 0) - return -EINVAL; - - eeprom->magic = (adapter->pdev)->vendor | - ((adapter->pdev)->device << 16); - offset = eeprom->offset; - - ret = netxen_rom_fast_read_words(adapter, offset, bytes, - eeprom->len); - if (ret < 0) - return ret; - - return 0; -} - -static void -netxen_nic_get_ringparam(struct net_device *dev, - struct ethtool_ringparam *ring) -{ - struct netxen_adapter *adapter = netdev_priv(dev); - - ring->rx_pending = adapter->num_rxd; - ring->rx_jumbo_pending = adapter->num_jumbo_rxd; - ring->rx_jumbo_pending += adapter->num_lro_rxd; - ring->tx_pending = adapter->num_txd; - - if (adapter->ahw.port_type == NETXEN_NIC_GBE) { - ring->rx_max_pending = MAX_RCV_DESCRIPTORS_1G; - ring->rx_jumbo_max_pending = MAX_JUMBO_RCV_DESCRIPTORS_1G; - } else { - ring->rx_max_pending = MAX_RCV_DESCRIPTORS_10G; - ring->rx_jumbo_max_pending = MAX_JUMBO_RCV_DESCRIPTORS_10G; - } - - ring->tx_max_pending = MAX_CMD_DESCRIPTORS; - - ring->rx_mini_max_pending = 0; - ring->rx_mini_pending = 0; -} - -static u32 -netxen_validate_ringparam(u32 val, u32 min, u32 max, char *r_name) -{ - u32 num_desc; - num_desc = max(val, min); - num_desc = min(num_desc, max); - num_desc = roundup_pow_of_two(num_desc); - - if (val != num_desc) { - printk(KERN_INFO "%s: setting %s ring size %d instead of %d\n", - netxen_nic_driver_name, r_name, num_desc, val); - } - - return num_desc; -} - -static int -netxen_nic_set_ringparam(struct net_device *dev, - struct ethtool_ringparam *ring) -{ - struct netxen_adapter *adapter = netdev_priv(dev); - u16 max_rcv_desc = MAX_RCV_DESCRIPTORS_10G; - u16 max_jumbo_desc = MAX_JUMBO_RCV_DESCRIPTORS_10G; - u16 num_rxd, num_jumbo_rxd, num_txd; - - if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) - return -EOPNOTSUPP; - - if (ring->rx_mini_pending) - return -EOPNOTSUPP; - - if (adapter->ahw.port_type == NETXEN_NIC_GBE) { - max_rcv_desc = MAX_RCV_DESCRIPTORS_1G; - max_jumbo_desc = MAX_JUMBO_RCV_DESCRIPTORS_10G; - } - - num_rxd = netxen_validate_ringparam(ring->rx_pending, - MIN_RCV_DESCRIPTORS, max_rcv_desc, "rx"); - - num_jumbo_rxd = netxen_validate_ringparam(ring->rx_jumbo_pending, - MIN_JUMBO_DESCRIPTORS, max_jumbo_desc, "rx jumbo"); - - num_txd = netxen_validate_ringparam(ring->tx_pending, - MIN_CMD_DESCRIPTORS, MAX_CMD_DESCRIPTORS, "tx"); - - if (num_rxd == adapter->num_rxd && num_txd == adapter->num_txd && - num_jumbo_rxd == adapter->num_jumbo_rxd) - return 0; - - adapter->num_rxd = num_rxd; - adapter->num_jumbo_rxd = num_jumbo_rxd; - adapter->num_txd = num_txd; - - return netxen_nic_reset_context(adapter); -} - -static void -netxen_nic_get_pauseparam(struct net_device *dev, - struct ethtool_pauseparam *pause) -{ - struct netxen_adapter *adapter = netdev_priv(dev); - __u32 val; - int port = adapter->physical_port; - - if (adapter->ahw.port_type == NETXEN_NIC_GBE) { - if ((port < 0) || (port > NETXEN_NIU_MAX_GBE_PORTS)) - return; - /* get flow control settings */ - val = NXRD32(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(port)); - pause->rx_pause = netxen_gb_get_rx_flowctl(val); - val = NXRD32(adapter, NETXEN_NIU_GB_PAUSE_CTL); - switch (port) { - case 0: - pause->tx_pause = !(netxen_gb_get_gb0_mask(val)); - break; - case 1: - pause->tx_pause = !(netxen_gb_get_gb1_mask(val)); - break; - case 2: - pause->tx_pause = !(netxen_gb_get_gb2_mask(val)); - break; - case 3: - default: - pause->tx_pause = !(netxen_gb_get_gb3_mask(val)); - break; - } - } else if (adapter->ahw.port_type == NETXEN_NIC_XGBE) { - if ((port < 0) || (port > NETXEN_NIU_MAX_XG_PORTS)) - return; - pause->rx_pause = 1; - val = NXRD32(adapter, NETXEN_NIU_XG_PAUSE_CTL); - if (port == 0) - pause->tx_pause = !(netxen_xg_get_xg0_mask(val)); - else - pause->tx_pause = !(netxen_xg_get_xg1_mask(val)); - } else { - printk(KERN_ERR"%s: Unknown board type: %x\n", - netxen_nic_driver_name, adapter->ahw.port_type); - } -} - -static int -netxen_nic_set_pauseparam(struct net_device *dev, - struct ethtool_pauseparam *pause) -{ - struct netxen_adapter *adapter = netdev_priv(dev); - __u32 val; - int port = adapter->physical_port; - /* read mode */ - if (adapter->ahw.port_type == NETXEN_NIC_GBE) { - if ((port < 0) || (port > NETXEN_NIU_MAX_GBE_PORTS)) - return -EIO; - /* set flow control */ - val = NXRD32(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(port)); - - if (pause->rx_pause) - netxen_gb_rx_flowctl(val); - else - netxen_gb_unset_rx_flowctl(val); - - NXWR32(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(port), - val); - /* set autoneg */ - val = NXRD32(adapter, NETXEN_NIU_GB_PAUSE_CTL); - switch (port) { - case 0: - if (pause->tx_pause) - netxen_gb_unset_gb0_mask(val); - else - netxen_gb_set_gb0_mask(val); - break; - case 1: - if (pause->tx_pause) - netxen_gb_unset_gb1_mask(val); - else - netxen_gb_set_gb1_mask(val); - break; - case 2: - if (pause->tx_pause) - netxen_gb_unset_gb2_mask(val); - else - netxen_gb_set_gb2_mask(val); - break; - case 3: - default: - if (pause->tx_pause) - netxen_gb_unset_gb3_mask(val); - else - netxen_gb_set_gb3_mask(val); - break; - } - NXWR32(adapter, NETXEN_NIU_GB_PAUSE_CTL, val); - } else if (adapter->ahw.port_type == NETXEN_NIC_XGBE) { - if ((port < 0) || (port > NETXEN_NIU_MAX_XG_PORTS)) - return -EIO; - val = NXRD32(adapter, NETXEN_NIU_XG_PAUSE_CTL); - if (port == 0) { - if (pause->tx_pause) - netxen_xg_unset_xg0_mask(val); - else - netxen_xg_set_xg0_mask(val); - } else { - if (pause->tx_pause) - netxen_xg_unset_xg1_mask(val); - else - netxen_xg_set_xg1_mask(val); - } - NXWR32(adapter, NETXEN_NIU_XG_PAUSE_CTL, val); - } else { - printk(KERN_ERR "%s: Unknown board type: %x\n", - netxen_nic_driver_name, - adapter->ahw.port_type); - } - return 0; -} - -static int netxen_nic_reg_test(struct net_device *dev) -{ - struct netxen_adapter *adapter = netdev_priv(dev); - u32 data_read, data_written; - - data_read = NXRD32(adapter, NETXEN_PCIX_PH_REG(0)); - if ((data_read & 0xffff) != adapter->pdev->vendor) - return 1; - - if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) - return 0; - - data_written = (u32)0xa5a5a5a5; - - NXWR32(adapter, CRB_SCRATCHPAD_TEST, data_written); - data_read = NXRD32(adapter, CRB_SCRATCHPAD_TEST); - if (data_written != data_read) - return 1; - - return 0; -} - -static int netxen_get_sset_count(struct net_device *dev, int sset) -{ - switch (sset) { - case ETH_SS_TEST: - return NETXEN_NIC_TEST_LEN; - case ETH_SS_STATS: - return NETXEN_NIC_STATS_LEN; - default: - return -EOPNOTSUPP; - } -} - -static void -netxen_nic_diag_test(struct net_device *dev, struct ethtool_test *eth_test, - u64 * data) -{ - memset(data, 0, sizeof(uint64_t) * NETXEN_NIC_TEST_LEN); - if ((data[0] = netxen_nic_reg_test(dev))) - eth_test->flags |= ETH_TEST_FL_FAILED; - /* link test */ - if ((data[1] = (u64) netxen_nic_test_link(dev))) - eth_test->flags |= ETH_TEST_FL_FAILED; -} - -static void -netxen_nic_get_strings(struct net_device *dev, u32 stringset, u8 * data) -{ - int index; - - switch (stringset) { - case ETH_SS_TEST: - memcpy(data, *netxen_nic_gstrings_test, - NETXEN_NIC_TEST_LEN * ETH_GSTRING_LEN); - break; - case ETH_SS_STATS: - for (index = 0; index < NETXEN_NIC_STATS_LEN; index++) { - memcpy(data + index * ETH_GSTRING_LEN, - netxen_nic_gstrings_stats[index].stat_string, - ETH_GSTRING_LEN); - } - break; - } -} - -static void -netxen_nic_get_ethtool_stats(struct net_device *dev, - struct ethtool_stats *stats, u64 * data) -{ - struct netxen_adapter *adapter = netdev_priv(dev); - int index; - - for (index = 0; index < NETXEN_NIC_STATS_LEN; index++) { - char *p = - (char *)adapter + - netxen_nic_gstrings_stats[index].stat_offset; - data[index] = - (netxen_nic_gstrings_stats[index].sizeof_stat == - sizeof(u64)) ? *(u64 *) p : *(u32 *) p; - } -} - -static void -netxen_nic_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) -{ - struct netxen_adapter *adapter = netdev_priv(dev); - u32 wol_cfg = 0; - - wol->supported = 0; - wol->wolopts = 0; - - if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) - return; - - wol_cfg = NXRD32(adapter, NETXEN_WOL_CONFIG_NV); - if (wol_cfg & (1UL << adapter->portnum)) - wol->supported |= WAKE_MAGIC; - - wol_cfg = NXRD32(adapter, NETXEN_WOL_CONFIG); - if (wol_cfg & (1UL << adapter->portnum)) - wol->wolopts |= WAKE_MAGIC; -} - -static int -netxen_nic_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol) -{ - struct netxen_adapter *adapter = netdev_priv(dev); - u32 wol_cfg = 0; - - if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) - return -EOPNOTSUPP; - - if (wol->wolopts & ~WAKE_MAGIC) - return -EOPNOTSUPP; - - wol_cfg = NXRD32(adapter, NETXEN_WOL_CONFIG_NV); - if (!(wol_cfg & (1 << adapter->portnum))) - return -EOPNOTSUPP; - - wol_cfg = NXRD32(adapter, NETXEN_WOL_CONFIG); - if (wol->wolopts & WAKE_MAGIC) - wol_cfg |= 1UL << adapter->portnum; - else - wol_cfg &= ~(1UL << adapter->portnum); - NXWR32(adapter, NETXEN_WOL_CONFIG, wol_cfg); - - return 0; -} - -/* - * Set the coalescing parameters. Currently only normal is supported. - * If rx_coalesce_usecs == 0 or rx_max_coalesced_frames == 0 then set the - * firmware coalescing to default. - */ -static int netxen_set_intr_coalesce(struct net_device *netdev, - struct ethtool_coalesce *ethcoal) -{ - struct netxen_adapter *adapter = netdev_priv(netdev); - - if (!NX_IS_REVISION_P3(adapter->ahw.revision_id)) - return -EINVAL; - - if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC) - return -EINVAL; - - /* - * Return Error if unsupported values or - * unsupported parameters are set. - */ - if (ethcoal->rx_coalesce_usecs > 0xffff || - ethcoal->rx_max_coalesced_frames > 0xffff || - ethcoal->tx_coalesce_usecs > 0xffff || - ethcoal->tx_max_coalesced_frames > 0xffff || - ethcoal->rx_coalesce_usecs_irq || - ethcoal->rx_max_coalesced_frames_irq || - ethcoal->tx_coalesce_usecs_irq || - ethcoal->tx_max_coalesced_frames_irq || - ethcoal->stats_block_coalesce_usecs || - ethcoal->use_adaptive_rx_coalesce || - ethcoal->use_adaptive_tx_coalesce || - ethcoal->pkt_rate_low || - ethcoal->rx_coalesce_usecs_low || - ethcoal->rx_max_coalesced_frames_low || - ethcoal->tx_coalesce_usecs_low || - ethcoal->tx_max_coalesced_frames_low || - ethcoal->pkt_rate_high || - ethcoal->rx_coalesce_usecs_high || - ethcoal->rx_max_coalesced_frames_high || - ethcoal->tx_coalesce_usecs_high || - ethcoal->tx_max_coalesced_frames_high) - return -EINVAL; - - if (!ethcoal->rx_coalesce_usecs || - !ethcoal->rx_max_coalesced_frames) { - adapter->coal.flags = NETXEN_NIC_INTR_DEFAULT; - adapter->coal.normal.data.rx_time_us = - NETXEN_DEFAULT_INTR_COALESCE_RX_TIME_US; - adapter->coal.normal.data.rx_packets = - NETXEN_DEFAULT_INTR_COALESCE_RX_PACKETS; - } else { - adapter->coal.flags = 0; - adapter->coal.normal.data.rx_time_us = - ethcoal->rx_coalesce_usecs; - adapter->coal.normal.data.rx_packets = - ethcoal->rx_max_coalesced_frames; - } - adapter->coal.normal.data.tx_time_us = ethcoal->tx_coalesce_usecs; - adapter->coal.normal.data.tx_packets = - ethcoal->tx_max_coalesced_frames; - - netxen_config_intr_coalesce(adapter); - - return 0; -} - -static int netxen_get_intr_coalesce(struct net_device *netdev, - struct ethtool_coalesce *ethcoal) -{ - struct netxen_adapter *adapter = netdev_priv(netdev); - - if (!NX_IS_REVISION_P3(adapter->ahw.revision_id)) - return -EINVAL; - - if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC) - return -EINVAL; - - ethcoal->rx_coalesce_usecs = adapter->coal.normal.data.rx_time_us; - ethcoal->tx_coalesce_usecs = adapter->coal.normal.data.tx_time_us; - ethcoal->rx_max_coalesced_frames = - adapter->coal.normal.data.rx_packets; - ethcoal->tx_max_coalesced_frames = - adapter->coal.normal.data.tx_packets; - - return 0; -} - -const struct ethtool_ops netxen_nic_ethtool_ops = { - .get_settings = netxen_nic_get_settings, - .set_settings = netxen_nic_set_settings, - .get_drvinfo = netxen_nic_get_drvinfo, - .get_regs_len = netxen_nic_get_regs_len, - .get_regs = netxen_nic_get_regs, - .get_link = ethtool_op_get_link, - .get_eeprom_len = netxen_nic_get_eeprom_len, - .get_eeprom = netxen_nic_get_eeprom, - .get_ringparam = netxen_nic_get_ringparam, - .set_ringparam = netxen_nic_set_ringparam, - .get_pauseparam = netxen_nic_get_pauseparam, - .set_pauseparam = netxen_nic_set_pauseparam, - .get_wol = netxen_nic_get_wol, - .set_wol = netxen_nic_set_wol, - .self_test = netxen_nic_diag_test, - .get_strings = netxen_nic_get_strings, - .get_ethtool_stats = netxen_nic_get_ethtool_stats, - .get_sset_count = netxen_get_sset_count, - .get_coalesce = netxen_get_intr_coalesce, - .set_coalesce = netxen_set_intr_coalesce, -}; diff --git a/drivers/net/netxen/netxen_nic_hdr.h b/drivers/net/netxen/netxen_nic_hdr.h deleted file mode 100644 index dc1967c1f312..000000000000 --- a/drivers/net/netxen/netxen_nic_hdr.h +++ /dev/null @@ -1,1050 +0,0 @@ -/* - * Copyright (C) 2003 - 2009 NetXen, Inc. - * Copyright (C) 2009 - QLogic Corporation. - * All rights reserved. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, - * MA 02111-1307, USA. - * - * The full GNU General Public License is included in this distribution - * in the file called "COPYING". - * - */ - -#ifndef __NETXEN_NIC_HDR_H_ -#define __NETXEN_NIC_HDR_H_ - -#include <linux/kernel.h> -#include <linux/types.h> - -/* - * The basic unit of access when reading/writing control registers. - */ - -typedef __le32 netxen_crbword_t; /* single word in CRB space */ - -enum { - NETXEN_HW_H0_CH_HUB_ADR = 0x05, - NETXEN_HW_H1_CH_HUB_ADR = 0x0E, - NETXEN_HW_H2_CH_HUB_ADR = 0x03, - NETXEN_HW_H3_CH_HUB_ADR = 0x01, - NETXEN_HW_H4_CH_HUB_ADR = 0x06, - NETXEN_HW_H5_CH_HUB_ADR = 0x07, - NETXEN_HW_H6_CH_HUB_ADR = 0x08 -}; - -/* Hub 0 */ -enum { - NETXEN_HW_MN_CRB_AGT_ADR = 0x15, - NETXEN_HW_MS_CRB_AGT_ADR = 0x25 -}; - -/* Hub 1 */ -enum { - NETXEN_HW_PS_CRB_AGT_ADR = 0x73, - NETXEN_HW_SS_CRB_AGT_ADR = 0x20, - NETXEN_HW_RPMX3_CRB_AGT_ADR = 0x0b, - NETXEN_HW_QMS_CRB_AGT_ADR = 0x00, - NETXEN_HW_SQGS0_CRB_AGT_ADR = 0x01, - NETXEN_HW_SQGS1_CRB_AGT_ADR = 0x02, - NETXEN_HW_SQGS2_CRB_AGT_ADR = 0x03, - NETXEN_HW_SQGS3_CRB_AGT_ADR = 0x04, - NETXEN_HW_C2C0_CRB_AGT_ADR = 0x58, - NETXEN_HW_C2C1_CRB_AGT_ADR = 0x59, - NETXEN_HW_C2C2_CRB_AGT_ADR = 0x5a, - NETXEN_HW_RPMX2_CRB_AGT_ADR = 0x0a, - NETXEN_HW_RPMX4_CRB_AGT_ADR = 0x0c, - NETXEN_HW_RPMX7_CRB_AGT_ADR = 0x0f, - NETXEN_HW_RPMX9_CRB_AGT_ADR = 0x12, - NETXEN_HW_SMB_CRB_AGT_ADR = 0x18 -}; - -/* Hub 2 */ -enum { - NETXEN_HW_NIU_CRB_AGT_ADR = 0x31, - NETXEN_HW_I2C0_CRB_AGT_ADR = 0x19, - NETXEN_HW_I2C1_CRB_AGT_ADR = 0x29, - - NETXEN_HW_SN_CRB_AGT_ADR = 0x10, - NETXEN_HW_I2Q_CRB_AGT_ADR = 0x20, - NETXEN_HW_LPC_CRB_AGT_ADR = 0x22, - NETXEN_HW_ROMUSB_CRB_AGT_ADR = 0x21, - NETXEN_HW_QM_CRB_AGT_ADR = 0x66, - NETXEN_HW_SQG0_CRB_AGT_ADR = 0x60, - NETXEN_HW_SQG1_CRB_AGT_ADR = 0x61, - NETXEN_HW_SQG2_CRB_AGT_ADR = 0x62, - NETXEN_HW_SQG3_CRB_AGT_ADR = 0x63, - NETXEN_HW_RPMX1_CRB_AGT_ADR = 0x09, - NETXEN_HW_RPMX5_CRB_AGT_ADR = 0x0d, - NETXEN_HW_RPMX6_CRB_AGT_ADR = 0x0e, - NETXEN_HW_RPMX8_CRB_AGT_ADR = 0x11 -}; - -/* Hub 3 */ -enum { - NETXEN_HW_PH_CRB_AGT_ADR = 0x1A, - NETXEN_HW_SRE_CRB_AGT_ADR = 0x50, - NETXEN_HW_EG_CRB_AGT_ADR = 0x51, - NETXEN_HW_RPMX0_CRB_AGT_ADR = 0x08 -}; - -/* Hub 4 */ -enum { - NETXEN_HW_PEGN0_CRB_AGT_ADR = 0x40, - NETXEN_HW_PEGN1_CRB_AGT_ADR, - NETXEN_HW_PEGN2_CRB_AGT_ADR, - NETXEN_HW_PEGN3_CRB_AGT_ADR, - NETXEN_HW_PEGNI_CRB_AGT_ADR, - NETXEN_HW_PEGND_CRB_AGT_ADR, - NETXEN_HW_PEGNC_CRB_AGT_ADR, - NETXEN_HW_PEGR0_CRB_AGT_ADR, - NETXEN_HW_PEGR1_CRB_AGT_ADR, - NETXEN_HW_PEGR2_CRB_AGT_ADR, - NETXEN_HW_PEGR3_CRB_AGT_ADR, - NETXEN_HW_PEGN4_CRB_AGT_ADR -}; - -/* Hub 5 */ -enum { - NETXEN_HW_PEGS0_CRB_AGT_ADR = 0x40, - NETXEN_HW_PEGS1_CRB_AGT_ADR, - NETXEN_HW_PEGS2_CRB_AGT_ADR, - NETXEN_HW_PEGS3_CRB_AGT_ADR, - NETXEN_HW_PEGSI_CRB_AGT_ADR, - NETXEN_HW_PEGSD_CRB_AGT_ADR, - NETXEN_HW_PEGSC_CRB_AGT_ADR -}; - -/* Hub 6 */ -enum { - NETXEN_HW_CAS0_CRB_AGT_ADR = 0x46, - NETXEN_HW_CAS1_CRB_AGT_ADR = 0x47, - NETXEN_HW_CAS2_CRB_AGT_ADR = 0x48, - NETXEN_HW_CAS3_CRB_AGT_ADR = 0x49, - NETXEN_HW_NCM_CRB_AGT_ADR = 0x16, - NETXEN_HW_TMR_CRB_AGT_ADR = 0x17, - NETXEN_HW_XDMA_CRB_AGT_ADR = 0x05, - NETXEN_HW_OCM0_CRB_AGT_ADR = 0x06, - NETXEN_HW_OCM1_CRB_AGT_ADR = 0x07 -}; - -/* Floaters - non existent modules */ -#define NETXEN_HW_EFC_RPMX0_CRB_AGT_ADR 0x67 - -/* This field defines PCI/X adr [25:20] of agents on the CRB */ -enum { - NETXEN_HW_PX_MAP_CRB_PH = 0, - NETXEN_HW_PX_MAP_CRB_PS, - NETXEN_HW_PX_MAP_CRB_MN, - NETXEN_HW_PX_MAP_CRB_MS, - NETXEN_HW_PX_MAP_CRB_PGR1, - NETXEN_HW_PX_MAP_CRB_SRE, - NETXEN_HW_PX_MAP_CRB_NIU, - NETXEN_HW_PX_MAP_CRB_QMN, - NETXEN_HW_PX_MAP_CRB_SQN0, - NETXEN_HW_PX_MAP_CRB_SQN1, - NETXEN_HW_PX_MAP_CRB_SQN2, - NETXEN_HW_PX_MAP_CRB_SQN3, - NETXEN_HW_PX_MAP_CRB_QMS, - NETXEN_HW_PX_MAP_CRB_SQS0, - NETXEN_HW_PX_MAP_CRB_SQS1, - NETXEN_HW_PX_MAP_CRB_SQS2, - NETXEN_HW_PX_MAP_CRB_SQS3, - NETXEN_HW_PX_MAP_CRB_PGN0, - NETXEN_HW_PX_MAP_CRB_PGN1, - NETXEN_HW_PX_MAP_CRB_PGN2, - NETXEN_HW_PX_MAP_CRB_PGN3, - NETXEN_HW_PX_MAP_CRB_PGND, - NETXEN_HW_PX_MAP_CRB_PGNI, - NETXEN_HW_PX_MAP_CRB_PGS0, - NETXEN_HW_PX_MAP_CRB_PGS1, - NETXEN_HW_PX_MAP_CRB_PGS2, - NETXEN_HW_PX_MAP_CRB_PGS3, - NETXEN_HW_PX_MAP_CRB_PGSD, - NETXEN_HW_PX_MAP_CRB_PGSI, - NETXEN_HW_PX_MAP_CRB_SN, - NETXEN_HW_PX_MAP_CRB_PGR2, - NETXEN_HW_PX_MAP_CRB_EG, - NETXEN_HW_PX_MAP_CRB_PH2, - NETXEN_HW_PX_MAP_CRB_PS2, - NETXEN_HW_PX_MAP_CRB_CAM, - NETXEN_HW_PX_MAP_CRB_CAS0, - NETXEN_HW_PX_MAP_CRB_CAS1, - NETXEN_HW_PX_MAP_CRB_CAS2, - NETXEN_HW_PX_MAP_CRB_C2C0, - NETXEN_HW_PX_MAP_CRB_C2C1, - NETXEN_HW_PX_MAP_CRB_TIMR, - NETXEN_HW_PX_MAP_CRB_PGR3, - NETXEN_HW_PX_MAP_CRB_RPMX1, - NETXEN_HW_PX_MAP_CRB_RPMX2, - NETXEN_HW_PX_MAP_CRB_RPMX3, - NETXEN_HW_PX_MAP_CRB_RPMX4, - NETXEN_HW_PX_MAP_CRB_RPMX5, - NETXEN_HW_PX_MAP_CRB_RPMX6, - NETXEN_HW_PX_MAP_CRB_RPMX7, - NETXEN_HW_PX_MAP_CRB_XDMA, - NETXEN_HW_PX_MAP_CRB_I2Q, - NETXEN_HW_PX_MAP_CRB_ROMUSB, - NETXEN_HW_PX_MAP_CRB_CAS3, - NETXEN_HW_PX_MAP_CRB_RPMX0, - NETXEN_HW_PX_MAP_CRB_RPMX8, - NETXEN_HW_PX_MAP_CRB_RPMX9, - NETXEN_HW_PX_MAP_CRB_OCM0, - NETXEN_HW_PX_MAP_CRB_OCM1, - NETXEN_HW_PX_MAP_CRB_SMB, - NETXEN_HW_PX_MAP_CRB_I2C0, - NETXEN_HW_PX_MAP_CRB_I2C1, - NETXEN_HW_PX_MAP_CRB_LPC, - NETXEN_HW_PX_MAP_CRB_PGNC, - NETXEN_HW_PX_MAP_CRB_PGR0 -}; - -/* This field defines CRB adr [31:20] of the agents */ - -#define NETXEN_HW_CRB_HUB_AGT_ADR_MN \ - ((NETXEN_HW_H0_CH_HUB_ADR << 7) | NETXEN_HW_MN_CRB_AGT_ADR) -#define NETXEN_HW_CRB_HUB_AGT_ADR_PH \ - ((NETXEN_HW_H0_CH_HUB_ADR << 7) | NETXEN_HW_PH_CRB_AGT_ADR) -#define NETXEN_HW_CRB_HUB_AGT_ADR_MS \ - ((NETXEN_HW_H0_CH_HUB_ADR << 7) | NETXEN_HW_MS_CRB_AGT_ADR) - -#define NETXEN_HW_CRB_HUB_AGT_ADR_PS \ - ((NETXEN_HW_H1_CH_HUB_ADR << 7) | NETXEN_HW_PS_CRB_AGT_ADR) -#define NETXEN_HW_CRB_HUB_AGT_ADR_SS \ - ((NETXEN_HW_H1_CH_HUB_ADR << 7) | NETXEN_HW_SS_CRB_AGT_ADR) -#define NETXEN_HW_CRB_HUB_AGT_ADR_RPMX3 \ - ((NETXEN_HW_H1_CH_HUB_ADR << 7) | NETXEN_HW_RPMX3_CRB_AGT_ADR) -#define NETXEN_HW_CRB_HUB_AGT_ADR_QMS \ - ((NETXEN_HW_H1_CH_HUB_ADR << 7) | NETXEN_HW_QMS_CRB_AGT_ADR) -#define NETXEN_HW_CRB_HUB_AGT_ADR_SQS0 \ - ((NETXEN_HW_H1_CH_HUB_ADR << 7) | NETXEN_HW_SQGS0_CRB_AGT_ADR) -#define NETXEN_HW_CRB_HUB_AGT_ADR_SQS1 \ - ((NETXEN_HW_H1_CH_HUB_ADR << 7) | NETXEN_HW_SQGS1_CRB_AGT_ADR) -#define NETXEN_HW_CRB_HUB_AGT_ADR_SQS2 \ - ((NETXEN_HW_H1_CH_HUB_ADR << 7) | NETXEN_HW_SQGS2_CRB_AGT_ADR) -#define NETXEN_HW_CRB_HUB_AGT_ADR_SQS3 \ - ((NETXEN_HW_H1_CH_HUB_ADR << 7) | NETXEN_HW_SQGS3_CRB_AGT_ADR) -#define NETXEN_HW_CRB_HUB_AGT_ADR_C2C0 \ - ((NETXEN_HW_H1_CH_HUB_ADR << 7) | NETXEN_HW_C2C0_CRB_AGT_ADR) -#define NETXEN_HW_CRB_HUB_AGT_ADR_C2C1 \ - ((NETXEN_HW_H1_CH_HUB_ADR << 7) | NETXEN_HW_C2C1_CRB_AGT_ADR) -#define NETXEN_HW_CRB_HUB_AGT_ADR_RPMX2 \ - ((NETXEN_HW_H1_CH_HUB_ADR << 7) | NETXEN_HW_RPMX2_CRB_AGT_ADR) -#define NETXEN_HW_CRB_HUB_AGT_ADR_RPMX4 \ - ((NETXEN_HW_H1_CH_HUB_ADR << 7) | NETXEN_HW_RPMX4_CRB_AGT_ADR) -#define NETXEN_HW_CRB_HUB_AGT_ADR_RPMX7 \ - ((NETXEN_HW_H1_CH_HUB_ADR << 7) | NETXEN_HW_RPMX7_CRB_AGT_ADR) -#define NETXEN_HW_CRB_HUB_AGT_ADR_RPMX9 \ - ((NETXEN_HW_H1_CH_HUB_ADR << 7) | NETXEN_HW_RPMX9_CRB_AGT_ADR) -#define NETXEN_HW_CRB_HUB_AGT_ADR_SMB \ - ((NETXEN_HW_H1_CH_HUB_ADR << 7) | NETXEN_HW_SMB_CRB_AGT_ADR) - -#define NETXEN_HW_CRB_HUB_AGT_ADR_NIU \ - ((NETXEN_HW_H2_CH_HUB_ADR << 7) | NETXEN_HW_NIU_CRB_AGT_ADR) -#define NETXEN_HW_CRB_HUB_AGT_ADR_I2C0 \ - ((NETXEN_HW_H2_CH_HUB_ADR << 7) | NETXEN_HW_I2C0_CRB_AGT_ADR) -#define NETXEN_HW_CRB_HUB_AGT_ADR_I2C1 \ - ((NETXEN_HW_H2_CH_HUB_ADR << 7) | NETXEN_HW_I2C1_CRB_AGT_ADR) - -#define NETXEN_HW_CRB_HUB_AGT_ADR_SRE \ - ((NETXEN_HW_H3_CH_HUB_ADR << 7) | NETXEN_HW_SRE_CRB_AGT_ADR) -#define NETXEN_HW_CRB_HUB_AGT_ADR_EG \ - ((NETXEN_HW_H3_CH_HUB_ADR << 7) | NETXEN_HW_EG_CRB_AGT_ADR) -#define NETXEN_HW_CRB_HUB_AGT_ADR_RPMX0 \ - ((NETXEN_HW_H3_CH_HUB_ADR << 7) | NETXEN_HW_RPMX0_CRB_AGT_ADR) -#define NETXEN_HW_CRB_HUB_AGT_ADR_QMN \ - ((NETXEN_HW_H3_CH_HUB_ADR << 7) | NETXEN_HW_QM_CRB_AGT_ADR) -#define NETXEN_HW_CRB_HUB_AGT_ADR_SQN0 \ - ((NETXEN_HW_H3_CH_HUB_ADR << 7) | NETXEN_HW_SQG0_CRB_AGT_ADR) -#define NETXEN_HW_CRB_HUB_AGT_ADR_SQN1 \ - ((NETXEN_HW_H3_CH_HUB_ADR << 7) | NETXEN_HW_SQG1_CRB_AGT_ADR) -#define NETXEN_HW_CRB_HUB_AGT_ADR_SQN2 \ - ((NETXEN_HW_H3_CH_HUB_ADR << 7) | NETXEN_HW_SQG2_CRB_AGT_ADR) -#define NETXEN_HW_CRB_HUB_AGT_ADR_SQN3 \ - ((NETXEN_HW_H3_CH_HUB_ADR << 7) | NETXEN_HW_SQG3_CRB_AGT_ADR) -#define NETXEN_HW_CRB_HUB_AGT_ADR_RPMX1 \ - ((NETXEN_HW_H3_CH_HUB_ADR << 7) | NETXEN_HW_RPMX1_CRB_AGT_ADR) -#define NETXEN_HW_CRB_HUB_AGT_ADR_RPMX5 \ - ((NETXEN_HW_H3_CH_HUB_ADR << 7) | NETXEN_HW_RPMX5_CRB_AGT_ADR) -#define NETXEN_HW_CRB_HUB_AGT_ADR_RPMX6 \ - ((NETXEN_HW_H3_CH_HUB_ADR << 7) | NETXEN_HW_RPMX6_CRB_AGT_ADR) -#define NETXEN_HW_CRB_HUB_AGT_ADR_RPMX8 \ - ((NETXEN_HW_H3_CH_HUB_ADR << 7) | NETXEN_HW_RPMX8_CRB_AGT_ADR) -#define NETXEN_HW_CRB_HUB_AGT_ADR_CAS0 \ - ((NETXEN_HW_H3_CH_HUB_ADR << 7) | NETXEN_HW_CAS0_CRB_AGT_ADR) -#define NETXEN_HW_CRB_HUB_AGT_ADR_CAS1 \ - ((NETXEN_HW_H3_CH_HUB_ADR << 7) | NETXEN_HW_CAS1_CRB_AGT_ADR) -#define NETXEN_HW_CRB_HUB_AGT_ADR_CAS2 \ - ((NETXEN_HW_H3_CH_HUB_ADR << 7) | NETXEN_HW_CAS2_CRB_AGT_ADR) -#define NETXEN_HW_CRB_HUB_AGT_ADR_CAS3 \ - ((NETXEN_HW_H3_CH_HUB_ADR << 7) | NETXEN_HW_CAS3_CRB_AGT_ADR) - -#define NETXEN_HW_CRB_HUB_AGT_ADR_PGNI \ - ((NETXEN_HW_H4_CH_HUB_ADR << 7) | NETXEN_HW_PEGNI_CRB_AGT_ADR) -#define NETXEN_HW_CRB_HUB_AGT_ADR_PGND \ - ((NETXEN_HW_H4_CH_HUB_ADR << 7) | NETXEN_HW_PEGND_CRB_AGT_ADR) -#define NETXEN_HW_CRB_HUB_AGT_ADR_PGN0 \ - ((NETXEN_HW_H4_CH_HUB_ADR << 7) | NETXEN_HW_PEGN0_CRB_AGT_ADR) -#define NETXEN_HW_CRB_HUB_AGT_ADR_PGN1 \ - ((NETXEN_HW_H4_CH_HUB_ADR << 7) | NETXEN_HW_PEGN1_CRB_AGT_ADR) -#define NETXEN_HW_CRB_HUB_AGT_ADR_PGN2 \ - ((NETXEN_HW_H4_CH_HUB_ADR << 7) | NETXEN_HW_PEGN2_CRB_AGT_ADR) -#define NETXEN_HW_CRB_HUB_AGT_ADR_PGN3 \ - ((NETXEN_HW_H4_CH_HUB_ADR << 7) | NETXEN_HW_PEGN3_CRB_AGT_ADR) -#define NETXEN_HW_CRB_HUB_AGT_ADR_PGN4 \ - ((NETXEN_HW_H4_CH_HUB_ADR << 7) | NETXEN_HW_PEGN4_CRB_AGT_ADR) -#define NETXEN_HW_CRB_HUB_AGT_ADR_PGNC \ - ((NETXEN_HW_H4_CH_HUB_ADR << 7) | NETXEN_HW_PEGNC_CRB_AGT_ADR) -#define NETXEN_HW_CRB_HUB_AGT_ADR_PGR0 \ - ((NETXEN_HW_H4_CH_HUB_ADR << 7) | NETXEN_HW_PEGR0_CRB_AGT_ADR) -#define NETXEN_HW_CRB_HUB_AGT_ADR_PGR1 \ - ((NETXEN_HW_H4_CH_HUB_ADR << 7) | NETXEN_HW_PEGR1_CRB_AGT_ADR) -#define NETXEN_HW_CRB_HUB_AGT_ADR_PGR2 \ - ((NETXEN_HW_H4_CH_HUB_ADR << 7) | NETXEN_HW_PEGR2_CRB_AGT_ADR) -#define NETXEN_HW_CRB_HUB_AGT_ADR_PGR3 \ - ((NETXEN_HW_H4_CH_HUB_ADR << 7) | NETXEN_HW_PEGR3_CRB_AGT_ADR) - -#define NETXEN_HW_CRB_HUB_AGT_ADR_PGSI \ - ((NETXEN_HW_H5_CH_HUB_ADR << 7) | NETXEN_HW_PEGSI_CRB_AGT_ADR) -#define NETXEN_HW_CRB_HUB_AGT_ADR_PGSD \ - ((NETXEN_HW_H5_CH_HUB_ADR << 7) | NETXEN_HW_PEGSD_CRB_AGT_ADR) -#define NETXEN_HW_CRB_HUB_AGT_ADR_PGS0 \ - ((NETXEN_HW_H5_CH_HUB_ADR << 7) | NETXEN_HW_PEGS0_CRB_AGT_ADR) -#define NETXEN_HW_CRB_HUB_AGT_ADR_PGS1 \ - ((NETXEN_HW_H5_CH_HUB_ADR << 7) | NETXEN_HW_PEGS1_CRB_AGT_ADR) -#define NETXEN_HW_CRB_HUB_AGT_ADR_PGS2 \ - ((NETXEN_HW_H5_CH_HUB_ADR << 7) | NETXEN_HW_PEGS2_CRB_AGT_ADR) -#define NETXEN_HW_CRB_HUB_AGT_ADR_PGS3 \ - ((NETXEN_HW_H5_CH_HUB_ADR << 7) | NETXEN_HW_PEGS3_CRB_AGT_ADR) -#define NETXEN_HW_CRB_HUB_AGT_ADR_PGSC \ - ((NETXEN_HW_H5_CH_HUB_ADR << 7) | NETXEN_HW_PEGSC_CRB_AGT_ADR) - -#define NETXEN_HW_CRB_HUB_AGT_ADR_CAM \ - ((NETXEN_HW_H6_CH_HUB_ADR << 7) | NETXEN_HW_NCM_CRB_AGT_ADR) -#define NETXEN_HW_CRB_HUB_AGT_ADR_TIMR \ - ((NETXEN_HW_H6_CH_HUB_ADR << 7) | NETXEN_HW_TMR_CRB_AGT_ADR) -#define NETXEN_HW_CRB_HUB_AGT_ADR_XDMA \ - ((NETXEN_HW_H6_CH_HUB_ADR << 7) | NETXEN_HW_XDMA_CRB_AGT_ADR) -#define NETXEN_HW_CRB_HUB_AGT_ADR_SN \ - ((NETXEN_HW_H6_CH_HUB_ADR << 7) | NETXEN_HW_SN_CRB_AGT_ADR) -#define NETXEN_HW_CRB_HUB_AGT_ADR_I2Q \ - ((NETXEN_HW_H6_CH_HUB_ADR << 7) | NETXEN_HW_I2Q_CRB_AGT_ADR) -#define NETXEN_HW_CRB_HUB_AGT_ADR_ROMUSB \ - ((NETXEN_HW_H6_CH_HUB_ADR << 7) | NETXEN_HW_ROMUSB_CRB_AGT_ADR) -#define NETXEN_HW_CRB_HUB_AGT_ADR_OCM0 \ - ((NETXEN_HW_H6_CH_HUB_ADR << 7) | NETXEN_HW_OCM0_CRB_AGT_ADR) -#define NETXEN_HW_CRB_HUB_AGT_ADR_OCM1 \ - ((NETXEN_HW_H6_CH_HUB_ADR << 7) | NETXEN_HW_OCM1_CRB_AGT_ADR) -#define NETXEN_HW_CRB_HUB_AGT_ADR_LPC \ - ((NETXEN_HW_H6_CH_HUB_ADR << 7) | NETXEN_HW_LPC_CRB_AGT_ADR) - -#define NETXEN_SRE_MISC (NETXEN_CRB_SRE + 0x0002c) -#define NETXEN_SRE_INT_STATUS (NETXEN_CRB_SRE + 0x00034) -#define NETXEN_SRE_PBI_ACTIVE_STATUS (NETXEN_CRB_SRE + 0x01014) -#define NETXEN_SRE_L1RE_CTL (NETXEN_CRB_SRE + 0x03000) -#define NETXEN_SRE_L2RE_CTL (NETXEN_CRB_SRE + 0x05000) -#define NETXEN_SRE_BUF_CTL (NETXEN_CRB_SRE + 0x01000) - -#define NETXEN_DMA_BASE(U) (NETXEN_CRB_PCIX_MD + 0x20000 + ((U)<<16)) -#define NETXEN_DMA_COMMAND(U) (NETXEN_DMA_BASE(U) + 0x00008) - -#define NETXEN_I2Q_CLR_PCI_HI (NETXEN_CRB_I2Q + 0x00034) - -#define PEG_NETWORK_BASE(N) (NETXEN_CRB_PEG_NET_0 + (((N)&3) << 20)) -#define CRB_REG_EX_PC 0x3c - -#define ROMUSB_GLB (NETXEN_CRB_ROMUSB + 0x00000) -#define ROMUSB_ROM (NETXEN_CRB_ROMUSB + 0x10000) - -#define NETXEN_ROMUSB_GLB_STATUS (ROMUSB_GLB + 0x0004) -#define NETXEN_ROMUSB_GLB_SW_RESET (ROMUSB_GLB + 0x0008) -#define NETXEN_ROMUSB_GLB_PAD_GPIO_I (ROMUSB_GLB + 0x000c) -#define NETXEN_ROMUSB_GLB_CAS_RST (ROMUSB_GLB + 0x0038) -#define NETXEN_ROMUSB_GLB_TEST_MUX_SEL (ROMUSB_GLB + 0x0044) -#define NETXEN_ROMUSB_GLB_PEGTUNE_DONE (ROMUSB_GLB + 0x005c) -#define NETXEN_ROMUSB_GLB_CHIP_CLK_CTRL (ROMUSB_GLB + 0x00A8) - -#define NETXEN_ROMUSB_GPIO(n) (ROMUSB_GLB + 0x60 + (4 * (n))) - -#define NETXEN_ROMUSB_ROM_INSTR_OPCODE (ROMUSB_ROM + 0x0004) -#define NETXEN_ROMUSB_ROM_ADDRESS (ROMUSB_ROM + 0x0008) -#define NETXEN_ROMUSB_ROM_WDATA (ROMUSB_ROM + 0x000c) -#define NETXEN_ROMUSB_ROM_ABYTE_CNT (ROMUSB_ROM + 0x0010) -#define NETXEN_ROMUSB_ROM_DUMMY_BYTE_CNT (ROMUSB_ROM + 0x0014) -#define NETXEN_ROMUSB_ROM_RDATA (ROMUSB_ROM + 0x0018) - -/* Lock IDs for ROM lock */ -#define ROM_LOCK_DRIVER 0x0d417340 - -/****************************************************************************** -* -* Definitions specific to M25P flash -* -******************************************************************************* -* Instructions -*/ -#define M25P_INSTR_WREN 0x06 -#define M25P_INSTR_WRDI 0x04 -#define M25P_INSTR_RDID 0x9f -#define M25P_INSTR_RDSR 0x05 -#define M25P_INSTR_WRSR 0x01 -#define M25P_INSTR_READ 0x03 -#define M25P_INSTR_FAST_READ 0x0b -#define M25P_INSTR_PP 0x02 -#define M25P_INSTR_SE 0xd8 -#define M25P_INSTR_BE 0xc7 -#define M25P_INSTR_DP 0xb9 -#define M25P_INSTR_RES 0xab - -/* all are 1MB windows */ - -#define NETXEN_PCI_CRB_WINDOWSIZE 0x00100000 -#define NETXEN_PCI_CRB_WINDOW(A) \ - (NETXEN_PCI_CRBSPACE + (A)*NETXEN_PCI_CRB_WINDOWSIZE) - -#define NETXEN_CRB_NIU NETXEN_PCI_CRB_WINDOW(NETXEN_HW_PX_MAP_CRB_NIU) -#define NETXEN_CRB_SRE NETXEN_PCI_CRB_WINDOW(NETXEN_HW_PX_MAP_CRB_SRE) -#define NETXEN_CRB_ROMUSB \ - NETXEN_PCI_CRB_WINDOW(NETXEN_HW_PX_MAP_CRB_ROMUSB) -#define NETXEN_CRB_I2Q NETXEN_PCI_CRB_WINDOW(NETXEN_HW_PX_MAP_CRB_I2Q) -#define NETXEN_CRB_I2C0 NETXEN_PCI_CRB_WINDOW(NETXEN_HW_PX_MAP_CRB_I2C0) -#define NETXEN_CRB_SMB NETXEN_PCI_CRB_WINDOW(NETXEN_HW_PX_MAP_CRB_SMB) -#define NETXEN_CRB_MAX NETXEN_PCI_CRB_WINDOW(64) - -#define NETXEN_CRB_PCIX_HOST NETXEN_PCI_CRB_WINDOW(NETXEN_HW_PX_MAP_CRB_PH) -#define NETXEN_CRB_PCIX_HOST2 NETXEN_PCI_CRB_WINDOW(NETXEN_HW_PX_MAP_CRB_PH2) -#define NETXEN_CRB_PEG_NET_0 NETXEN_PCI_CRB_WINDOW(NETXEN_HW_PX_MAP_CRB_PGN0) -#define NETXEN_CRB_PEG_NET_1 NETXEN_PCI_CRB_WINDOW(NETXEN_HW_PX_MAP_CRB_PGN1) -#define NETXEN_CRB_PEG_NET_2 NETXEN_PCI_CRB_WINDOW(NETXEN_HW_PX_MAP_CRB_PGN2) -#define NETXEN_CRB_PEG_NET_3 NETXEN_PCI_CRB_WINDOW(NETXEN_HW_PX_MAP_CRB_PGN3) -#define NETXEN_CRB_PEG_NET_4 NETXEN_PCI_CRB_WINDOW(NETXEN_HW_PX_MAP_CRB_SQS2) -#define NETXEN_CRB_PEG_NET_D NETXEN_PCI_CRB_WINDOW(NETXEN_HW_PX_MAP_CRB_PGND) -#define NETXEN_CRB_PEG_NET_I NETXEN_PCI_CRB_WINDOW(NETXEN_HW_PX_MAP_CRB_PGNI) -#define NETXEN_CRB_DDR_NET NETXEN_PCI_CRB_WINDOW(NETXEN_HW_PX_MAP_CRB_MN) -#define NETXEN_CRB_QDR_NET NETXEN_PCI_CRB_WINDOW(NETXEN_HW_PX_MAP_CRB_SN) - -#define NETXEN_CRB_PCIX_MD NETXEN_PCI_CRB_WINDOW(NETXEN_HW_PX_MAP_CRB_PS) -#define NETXEN_CRB_PCIE NETXEN_CRB_PCIX_MD - -#define ISR_INT_VECTOR (NETXEN_PCIX_PS_REG(PCIX_INT_VECTOR)) -#define ISR_INT_MASK (NETXEN_PCIX_PS_REG(PCIX_INT_MASK)) -#define ISR_INT_MASK_SLOW (NETXEN_PCIX_PS_REG(PCIX_INT_MASK)) -#define ISR_INT_TARGET_STATUS (NETXEN_PCIX_PS_REG(PCIX_TARGET_STATUS)) -#define ISR_INT_TARGET_MASK (NETXEN_PCIX_PS_REG(PCIX_TARGET_MASK)) -#define ISR_INT_TARGET_STATUS_F1 (NETXEN_PCIX_PS_REG(PCIX_TARGET_STATUS_F1)) -#define ISR_INT_TARGET_MASK_F1 (NETXEN_PCIX_PS_REG(PCIX_TARGET_MASK_F1)) -#define ISR_INT_TARGET_STATUS_F2 (NETXEN_PCIX_PS_REG(PCIX_TARGET_STATUS_F2)) -#define ISR_INT_TARGET_MASK_F2 (NETXEN_PCIX_PS_REG(PCIX_TARGET_MASK_F2)) -#define ISR_INT_TARGET_STATUS_F3 (NETXEN_PCIX_PS_REG(PCIX_TARGET_STATUS_F3)) -#define ISR_INT_TARGET_MASK_F3 (NETXEN_PCIX_PS_REG(PCIX_TARGET_MASK_F3)) -#define ISR_INT_TARGET_STATUS_F4 (NETXEN_PCIX_PS_REG(PCIX_TARGET_STATUS_F4)) -#define ISR_INT_TARGET_MASK_F4 (NETXEN_PCIX_PS_REG(PCIX_TARGET_MASK_F4)) -#define ISR_INT_TARGET_STATUS_F5 (NETXEN_PCIX_PS_REG(PCIX_TARGET_STATUS_F5)) -#define ISR_INT_TARGET_MASK_F5 (NETXEN_PCIX_PS_REG(PCIX_TARGET_MASK_F5)) -#define ISR_INT_TARGET_STATUS_F6 (NETXEN_PCIX_PS_REG(PCIX_TARGET_STATUS_F6)) -#define ISR_INT_TARGET_MASK_F6 (NETXEN_PCIX_PS_REG(PCIX_TARGET_MASK_F6)) -#define ISR_INT_TARGET_STATUS_F7 (NETXEN_PCIX_PS_REG(PCIX_TARGET_STATUS_F7)) -#define ISR_INT_TARGET_MASK_F7 (NETXEN_PCIX_PS_REG(PCIX_TARGET_MASK_F7)) - -#define NETXEN_PCI_MAPSIZE 128 -#define NETXEN_PCI_DDR_NET (0x00000000UL) -#define NETXEN_PCI_QDR_NET (0x04000000UL) -#define NETXEN_PCI_DIRECT_CRB (0x04400000UL) -#define NETXEN_PCI_CAMQM (0x04800000UL) -#define NETXEN_PCI_CAMQM_MAX (0x04ffffffUL) -#define NETXEN_PCI_OCM0 (0x05000000UL) -#define NETXEN_PCI_OCM0_MAX (0x050fffffUL) -#define NETXEN_PCI_OCM1 (0x05100000UL) -#define NETXEN_PCI_OCM1_MAX (0x051fffffUL) -#define NETXEN_PCI_CRBSPACE (0x06000000UL) -#define NETXEN_PCI_128MB_SIZE (0x08000000UL) -#define NETXEN_PCI_32MB_SIZE (0x02000000UL) -#define NETXEN_PCI_2MB_SIZE (0x00200000UL) - -#define NETXEN_PCI_MN_2M (0) -#define NETXEN_PCI_MS_2M (0x80000) -#define NETXEN_PCI_OCM0_2M (0x000c0000UL) -#define NETXEN_PCI_CAMQM_2M_BASE (0x000ff800UL) -#define NETXEN_PCI_CAMQM_2M_END (0x04800800UL) - -#define NETXEN_CRB_CAM NETXEN_PCI_CRB_WINDOW(NETXEN_HW_PX_MAP_CRB_CAM) - -#define NETXEN_ADDR_DDR_NET (0x0000000000000000ULL) -#define NETXEN_ADDR_DDR_NET_MAX (0x000000000fffffffULL) -#define NETXEN_ADDR_OCM0 (0x0000000200000000ULL) -#define NETXEN_ADDR_OCM0_MAX (0x00000002000fffffULL) -#define NETXEN_ADDR_OCM1 (0x0000000200400000ULL) -#define NETXEN_ADDR_OCM1_MAX (0x00000002004fffffULL) -#define NETXEN_ADDR_QDR_NET (0x0000000300000000ULL) -#define NETXEN_ADDR_QDR_NET_MAX_P2 (0x00000003003fffffULL) -#define NETXEN_ADDR_QDR_NET_MAX_P3 (0x0000000303ffffffULL) - -/* - * Register offsets for MN - */ -#define NETXEN_MIU_CONTROL (0x000) -#define NETXEN_MIU_MN_CONTROL (NETXEN_CRB_DDR_NET+NETXEN_MIU_CONTROL) - - /* 200ms delay in each loop */ -#define NETXEN_NIU_PHY_WAITLEN 200000 - /* 10 seconds before we give up */ -#define NETXEN_NIU_PHY_WAITMAX 50 -#define NETXEN_NIU_MAX_GBE_PORTS 4 -#define NETXEN_NIU_MAX_XG_PORTS 2 - -#define NETXEN_NIU_MODE (NETXEN_CRB_NIU + 0x00000) - -#define NETXEN_NIU_XG_SINGLE_TERM (NETXEN_CRB_NIU + 0x00004) -#define NETXEN_NIU_XG_DRIVE_HI (NETXEN_CRB_NIU + 0x00008) -#define NETXEN_NIU_XG_DRIVE_LO (NETXEN_CRB_NIU + 0x0000c) -#define NETXEN_NIU_XG_DTX (NETXEN_CRB_NIU + 0x00010) -#define NETXEN_NIU_XG_DEQ (NETXEN_CRB_NIU + 0x00014) -#define NETXEN_NIU_XG_WORD_ALIGN (NETXEN_CRB_NIU + 0x00018) -#define NETXEN_NIU_XG_RESET (NETXEN_CRB_NIU + 0x0001c) -#define NETXEN_NIU_XG_POWER_DOWN (NETXEN_CRB_NIU + 0x00020) -#define NETXEN_NIU_XG_RESET_PLL (NETXEN_CRB_NIU + 0x00024) -#define NETXEN_NIU_XG_SERDES_LOOPBACK (NETXEN_CRB_NIU + 0x00028) -#define NETXEN_NIU_XG_DO_BYTE_ALIGN (NETXEN_CRB_NIU + 0x0002c) -#define NETXEN_NIU_XG_TX_ENABLE (NETXEN_CRB_NIU + 0x00030) -#define NETXEN_NIU_XG_RX_ENABLE (NETXEN_CRB_NIU + 0x00034) -#define NETXEN_NIU_XG_STATUS (NETXEN_CRB_NIU + 0x00038) -#define NETXEN_NIU_XG_PAUSE_THRESHOLD (NETXEN_CRB_NIU + 0x0003c) -#define NETXEN_NIU_INT_MASK (NETXEN_CRB_NIU + 0x00040) -#define NETXEN_NIU_ACTIVE_INT (NETXEN_CRB_NIU + 0x00044) -#define NETXEN_NIU_MASKABLE_INT (NETXEN_CRB_NIU + 0x00048) - -#define NETXEN_NIU_STRAP_VALUE_SAVE_HIGHER (NETXEN_CRB_NIU + 0x0004c) - -#define NETXEN_NIU_GB_SERDES_RESET (NETXEN_CRB_NIU + 0x00050) -#define NETXEN_NIU_GB0_GMII_MODE (NETXEN_CRB_NIU + 0x00054) -#define NETXEN_NIU_GB0_MII_MODE (NETXEN_CRB_NIU + 0x00058) -#define NETXEN_NIU_GB1_GMII_MODE (NETXEN_CRB_NIU + 0x0005c) -#define NETXEN_NIU_GB1_MII_MODE (NETXEN_CRB_NIU + 0x00060) -#define NETXEN_NIU_GB2_GMII_MODE (NETXEN_CRB_NIU + 0x00064) -#define NETXEN_NIU_GB2_MII_MODE (NETXEN_CRB_NIU + 0x00068) -#define NETXEN_NIU_GB3_GMII_MODE (NETXEN_CRB_NIU + 0x0006c) -#define NETXEN_NIU_GB3_MII_MODE (NETXEN_CRB_NIU + 0x00070) -#define NETXEN_NIU_REMOTE_LOOPBACK (NETXEN_CRB_NIU + 0x00074) -#define NETXEN_NIU_GB0_HALF_DUPLEX (NETXEN_CRB_NIU + 0x00078) -#define NETXEN_NIU_GB1_HALF_DUPLEX (NETXEN_CRB_NIU + 0x0007c) -#define NETXEN_NIU_RESET_SYS_FIFOS (NETXEN_CRB_NIU + 0x00088) -#define NETXEN_NIU_GB_CRC_DROP (NETXEN_CRB_NIU + 0x0008c) -#define NETXEN_NIU_GB_DROP_WRONGADDR (NETXEN_CRB_NIU + 0x00090) -#define NETXEN_NIU_TEST_MUX_CTL (NETXEN_CRB_NIU + 0x00094) -#define NETXEN_NIU_XG_PAUSE_CTL (NETXEN_CRB_NIU + 0x00098) -#define NETXEN_NIU_XG_PAUSE_LEVEL (NETXEN_CRB_NIU + 0x000dc) -#define NETXEN_NIU_FRAME_COUNT_SELECT (NETXEN_CRB_NIU + 0x000ac) -#define NETXEN_NIU_FRAME_COUNT (NETXEN_CRB_NIU + 0x000b0) -#define NETXEN_NIU_XG_SEL (NETXEN_CRB_NIU + 0x00128) -#define NETXEN_NIU_GB_PAUSE_CTL (NETXEN_CRB_NIU + 0x0030c) - -#define NETXEN_NIU_FULL_LEVEL_XG (NETXEN_CRB_NIU + 0x00450) - -#define NETXEN_NIU_XG1_RESET (NETXEN_CRB_NIU + 0x0011c) -#define NETXEN_NIU_XG1_POWER_DOWN (NETXEN_CRB_NIU + 0x00120) -#define NETXEN_NIU_XG1_RESET_PLL (NETXEN_CRB_NIU + 0x00124) - -#define NETXEN_MAC_ADDR_CNTL_REG (NETXEN_CRB_NIU + 0x1000) - -#define NETXEN_MULTICAST_ADDR_HI_0 (NETXEN_CRB_NIU + 0x1010) -#define NETXEN_MULTICAST_ADDR_HI_1 (NETXEN_CRB_NIU + 0x1014) -#define NETXEN_MULTICAST_ADDR_HI_2 (NETXEN_CRB_NIU + 0x1018) -#define NETXEN_MULTICAST_ADDR_HI_3 (NETXEN_CRB_NIU + 0x101c) - -#define NETXEN_UNICAST_ADDR_BASE (NETXEN_CRB_NIU + 0x1080) -#define NETXEN_MULTICAST_ADDR_BASE (NETXEN_CRB_NIU + 0x1100) - -#define NETXEN_NIU_GB_MAC_CONFIG_0(I) \ - (NETXEN_CRB_NIU + 0x30000 + (I)*0x10000) -#define NETXEN_NIU_GB_MAC_CONFIG_1(I) \ - (NETXEN_CRB_NIU + 0x30004 + (I)*0x10000) -#define NETXEN_NIU_GB_MAC_IPG_IFG(I) \ - (NETXEN_CRB_NIU + 0x30008 + (I)*0x10000) -#define NETXEN_NIU_GB_HALF_DUPLEX_CTRL(I) \ - (NETXEN_CRB_NIU + 0x3000c + (I)*0x10000) -#define NETXEN_NIU_GB_MAX_FRAME_SIZE(I) \ - (NETXEN_CRB_NIU + 0x30010 + (I)*0x10000) -#define NETXEN_NIU_GB_TEST_REG(I) \ - (NETXEN_CRB_NIU + 0x3001c + (I)*0x10000) -#define NETXEN_NIU_GB_MII_MGMT_CONFIG(I) \ - (NETXEN_CRB_NIU + 0x30020 + (I)*0x10000) -#define NETXEN_NIU_GB_MII_MGMT_COMMAND(I) \ - (NETXEN_CRB_NIU + 0x30024 + (I)*0x10000) -#define NETXEN_NIU_GB_MII_MGMT_ADDR(I) \ - (NETXEN_CRB_NIU + 0x30028 + (I)*0x10000) -#define NETXEN_NIU_GB_MII_MGMT_CTRL(I) \ - (NETXEN_CRB_NIU + 0x3002c + (I)*0x10000) -#define NETXEN_NIU_GB_MII_MGMT_STATUS(I) \ - (NETXEN_CRB_NIU + 0x30030 + (I)*0x10000) -#define NETXEN_NIU_GB_MII_MGMT_INDICATE(I) \ - (NETXEN_CRB_NIU + 0x30034 + (I)*0x10000) -#define NETXEN_NIU_GB_INTERFACE_CTRL(I) \ - (NETXEN_CRB_NIU + 0x30038 + (I)*0x10000) -#define NETXEN_NIU_GB_INTERFACE_STATUS(I) \ - (NETXEN_CRB_NIU + 0x3003c + (I)*0x10000) -#define NETXEN_NIU_GB_STATION_ADDR_0(I) \ - (NETXEN_CRB_NIU + 0x30040 + (I)*0x10000) -#define NETXEN_NIU_GB_STATION_ADDR_1(I) \ - (NETXEN_CRB_NIU + 0x30044 + (I)*0x10000) - -#define NETXEN_NIU_XGE_CONFIG_0 (NETXEN_CRB_NIU + 0x70000) -#define NETXEN_NIU_XGE_CONFIG_1 (NETXEN_CRB_NIU + 0x70004) -#define NETXEN_NIU_XGE_IPG (NETXEN_CRB_NIU + 0x70008) -#define NETXEN_NIU_XGE_STATION_ADDR_0_HI (NETXEN_CRB_NIU + 0x7000c) -#define NETXEN_NIU_XGE_STATION_ADDR_0_1 (NETXEN_CRB_NIU + 0x70010) -#define NETXEN_NIU_XGE_STATION_ADDR_1_LO (NETXEN_CRB_NIU + 0x70014) -#define NETXEN_NIU_XGE_STATUS (NETXEN_CRB_NIU + 0x70018) -#define NETXEN_NIU_XGE_MAX_FRAME_SIZE (NETXEN_CRB_NIU + 0x7001c) -#define NETXEN_NIU_XGE_PAUSE_FRAME_VALUE (NETXEN_CRB_NIU + 0x70020) -#define NETXEN_NIU_XGE_TX_BYTE_CNT (NETXEN_CRB_NIU + 0x70024) -#define NETXEN_NIU_XGE_TX_FRAME_CNT (NETXEN_CRB_NIU + 0x70028) -#define NETXEN_NIU_XGE_RX_BYTE_CNT (NETXEN_CRB_NIU + 0x7002c) -#define NETXEN_NIU_XGE_RX_FRAME_CNT (NETXEN_CRB_NIU + 0x70030) -#define NETXEN_NIU_XGE_AGGR_ERROR_CNT (NETXEN_CRB_NIU + 0x70034) -#define NETXEN_NIU_XGE_MULTICAST_FRAME_CNT (NETXEN_CRB_NIU + 0x70038) -#define NETXEN_NIU_XGE_UNICAST_FRAME_CNT (NETXEN_CRB_NIU + 0x7003c) -#define NETXEN_NIU_XGE_CRC_ERROR_CNT (NETXEN_CRB_NIU + 0x70040) -#define NETXEN_NIU_XGE_OVERSIZE_FRAME_ERR (NETXEN_CRB_NIU + 0x70044) -#define NETXEN_NIU_XGE_UNDERSIZE_FRAME_ERR (NETXEN_CRB_NIU + 0x70048) -#define NETXEN_NIU_XGE_LOCAL_ERROR_CNT (NETXEN_CRB_NIU + 0x7004c) -#define NETXEN_NIU_XGE_REMOTE_ERROR_CNT (NETXEN_CRB_NIU + 0x70050) -#define NETXEN_NIU_XGE_CONTROL_CHAR_CNT (NETXEN_CRB_NIU + 0x70054) -#define NETXEN_NIU_XGE_PAUSE_FRAME_CNT (NETXEN_CRB_NIU + 0x70058) -#define NETXEN_NIU_XG1_CONFIG_0 (NETXEN_CRB_NIU + 0x80000) -#define NETXEN_NIU_XG1_CONFIG_1 (NETXEN_CRB_NIU + 0x80004) -#define NETXEN_NIU_XG1_IPG (NETXEN_CRB_NIU + 0x80008) -#define NETXEN_NIU_XG1_STATION_ADDR_0_HI (NETXEN_CRB_NIU + 0x8000c) -#define NETXEN_NIU_XG1_STATION_ADDR_0_1 (NETXEN_CRB_NIU + 0x80010) -#define NETXEN_NIU_XG1_STATION_ADDR_1_LO (NETXEN_CRB_NIU + 0x80014) -#define NETXEN_NIU_XG1_STATUS (NETXEN_CRB_NIU + 0x80018) -#define NETXEN_NIU_XG1_MAX_FRAME_SIZE (NETXEN_CRB_NIU + 0x8001c) -#define NETXEN_NIU_XG1_PAUSE_FRAME_VALUE (NETXEN_CRB_NIU + 0x80020) -#define NETXEN_NIU_XG1_TX_BYTE_CNT (NETXEN_CRB_NIU + 0x80024) -#define NETXEN_NIU_XG1_TX_FRAME_CNT (NETXEN_CRB_NIU + 0x80028) -#define NETXEN_NIU_XG1_RX_BYTE_CNT (NETXEN_CRB_NIU + 0x8002c) -#define NETXEN_NIU_XG1_RX_FRAME_CNT (NETXEN_CRB_NIU + 0x80030) -#define NETXEN_NIU_XG1_AGGR_ERROR_CNT (NETXEN_CRB_NIU + 0x80034) -#define NETXEN_NIU_XG1_MULTICAST_FRAME_CNT (NETXEN_CRB_NIU + 0x80038) -#define NETXEN_NIU_XG1_UNICAST_FRAME_CNT (NETXEN_CRB_NIU + 0x8003c) -#define NETXEN_NIU_XG1_CRC_ERROR_CNT (NETXEN_CRB_NIU + 0x80040) -#define NETXEN_NIU_XG1_OVERSIZE_FRAME_ERR (NETXEN_CRB_NIU + 0x80044) -#define NETXEN_NIU_XG1_UNDERSIZE_FRAME_ERR (NETXEN_CRB_NIU + 0x80048) -#define NETXEN_NIU_XG1_LOCAL_ERROR_CNT (NETXEN_CRB_NIU + 0x8004c) -#define NETXEN_NIU_XG1_REMOTE_ERROR_CNT (NETXEN_CRB_NIU + 0x80050) -#define NETXEN_NIU_XG1_CONTROL_CHAR_CNT (NETXEN_CRB_NIU + 0x80054) -#define NETXEN_NIU_XG1_PAUSE_FRAME_CNT (NETXEN_CRB_NIU + 0x80058) - -/* P3 802.3ap */ -#define NETXEN_NIU_AP_MAC_CONFIG_0(I) (NETXEN_CRB_NIU+0xa0000+(I)*0x10000) -#define NETXEN_NIU_AP_MAC_CONFIG_1(I) (NETXEN_CRB_NIU+0xa0004+(I)*0x10000) -#define NETXEN_NIU_AP_MAC_IPG_IFG(I) (NETXEN_CRB_NIU+0xa0008+(I)*0x10000) -#define NETXEN_NIU_AP_HALF_DUPLEX_CTRL(I) (NETXEN_CRB_NIU+0xa000c+(I)*0x10000) -#define NETXEN_NIU_AP_MAX_FRAME_SIZE(I) (NETXEN_CRB_NIU+0xa0010+(I)*0x10000) -#define NETXEN_NIU_AP_TEST_REG(I) (NETXEN_CRB_NIU+0xa001c+(I)*0x10000) -#define NETXEN_NIU_AP_MII_MGMT_CONFIG(I) (NETXEN_CRB_NIU+0xa0020+(I)*0x10000) -#define NETXEN_NIU_AP_MII_MGMT_COMMAND(I) (NETXEN_CRB_NIU+0xa0024+(I)*0x10000) -#define NETXEN_NIU_AP_MII_MGMT_ADDR(I) (NETXEN_CRB_NIU+0xa0028+(I)*0x10000) -#define NETXEN_NIU_AP_MII_MGMT_CTRL(I) (NETXEN_CRB_NIU+0xa002c+(I)*0x10000) -#define NETXEN_NIU_AP_MII_MGMT_STATUS(I) (NETXEN_CRB_NIU+0xa0030+(I)*0x10000) -#define NETXEN_NIU_AP_MII_MGMT_INDICATE(I) (NETXEN_CRB_NIU+0xa0034+(I)*0x10000) -#define NETXEN_NIU_AP_INTERFACE_CTRL(I) (NETXEN_CRB_NIU+0xa0038+(I)*0x10000) -#define NETXEN_NIU_AP_INTERFACE_STATUS(I) (NETXEN_CRB_NIU+0xa003c+(I)*0x10000) -#define NETXEN_NIU_AP_STATION_ADDR_0(I) (NETXEN_CRB_NIU+0xa0040+(I)*0x10000) -#define NETXEN_NIU_AP_STATION_ADDR_1(I) (NETXEN_CRB_NIU+0xa0044+(I)*0x10000) - - -#define TEST_AGT_CTRL (0x00) - -#define TA_CTL_START 1 -#define TA_CTL_ENABLE 2 -#define TA_CTL_WRITE 4 -#define TA_CTL_BUSY 8 - -/* - * Register offsets for MN - */ -#define MIU_TEST_AGT_BASE (0x90) - -#define MIU_TEST_AGT_ADDR_LO (0x04) -#define MIU_TEST_AGT_ADDR_HI (0x08) -#define MIU_TEST_AGT_WRDATA_LO (0x10) -#define MIU_TEST_AGT_WRDATA_HI (0x14) -#define MIU_TEST_AGT_RDDATA_LO (0x18) -#define MIU_TEST_AGT_RDDATA_HI (0x1c) - -#define MIU_TEST_AGT_ADDR_MASK 0xfffffff8 -#define MIU_TEST_AGT_UPPER_ADDR(off) (0) - -/* - * Register offsets for MS - */ -#define SIU_TEST_AGT_BASE (0x60) - -#define SIU_TEST_AGT_ADDR_LO (0x04) -#define SIU_TEST_AGT_ADDR_HI (0x18) -#define SIU_TEST_AGT_WRDATA_LO (0x08) -#define SIU_TEST_AGT_WRDATA_HI (0x0c) -#define SIU_TEST_AGT_WRDATA(i) (0x08+(4*(i))) -#define SIU_TEST_AGT_RDDATA_LO (0x10) -#define SIU_TEST_AGT_RDDATA_HI (0x14) -#define SIU_TEST_AGT_RDDATA(i) (0x10+(4*(i))) - -#define SIU_TEST_AGT_ADDR_MASK 0x3ffff8 -#define SIU_TEST_AGT_UPPER_ADDR(off) ((off)>>22) - -/* XG Link status */ -#define XG_LINK_UP 0x10 -#define XG_LINK_DOWN 0x20 - -#define XG_LINK_UP_P3 0x01 -#define XG_LINK_DOWN_P3 0x02 -#define XG_LINK_STATE_P3_MASK 0xf -#define XG_LINK_STATE_P3(pcifn,val) \ - (((val) >> ((pcifn) * 4)) & XG_LINK_STATE_P3_MASK) - -#define P3_LINK_SPEED_MHZ 100 -#define P3_LINK_SPEED_MASK 0xff -#define P3_LINK_SPEED_REG(pcifn) \ - (CRB_PF_LINK_SPEED_1 + (((pcifn) / 4) * 4)) -#define P3_LINK_SPEED_VAL(pcifn, reg) \ - (((reg) >> (8 * ((pcifn) & 0x3))) & P3_LINK_SPEED_MASK) - -#define NETXEN_CAM_RAM_BASE (NETXEN_CRB_CAM + 0x02000) -#define NETXEN_CAM_RAM(reg) (NETXEN_CAM_RAM_BASE + (reg)) -#define NETXEN_FW_VERSION_MAJOR (NETXEN_CAM_RAM(0x150)) -#define NETXEN_FW_VERSION_MINOR (NETXEN_CAM_RAM(0x154)) -#define NETXEN_FW_VERSION_SUB (NETXEN_CAM_RAM(0x158)) -#define NETXEN_ROM_LOCK_ID (NETXEN_CAM_RAM(0x100)) -#define NETXEN_PHY_LOCK_ID (NETXEN_CAM_RAM(0x120)) -#define NETXEN_CRB_WIN_LOCK_ID (NETXEN_CAM_RAM(0x124)) - -#define NIC_CRB_BASE (NETXEN_CAM_RAM(0x200)) -#define NIC_CRB_BASE_2 (NETXEN_CAM_RAM(0x700)) -#define NETXEN_NIC_REG(X) (NIC_CRB_BASE+(X)) -#define NETXEN_NIC_REG_2(X) (NIC_CRB_BASE_2+(X)) - -#define NX_CDRP_CRB_OFFSET (NETXEN_NIC_REG(0x18)) -#define NX_ARG1_CRB_OFFSET (NETXEN_NIC_REG(0x1c)) -#define NX_ARG2_CRB_OFFSET (NETXEN_NIC_REG(0x20)) -#define NX_ARG3_CRB_OFFSET (NETXEN_NIC_REG(0x24)) -#define NX_SIGN_CRB_OFFSET (NETXEN_NIC_REG(0x28)) - -#define CRB_HOST_DUMMY_BUF_ADDR_HI (NETXEN_NIC_REG(0x3c)) -#define CRB_HOST_DUMMY_BUF_ADDR_LO (NETXEN_NIC_REG(0x40)) - -#define CRB_CMDPEG_STATE (NETXEN_NIC_REG(0x50)) -#define CRB_RCVPEG_STATE (NETXEN_NIC_REG(0x13c)) - -#define CRB_XG_STATE (NETXEN_NIC_REG(0x94)) -#define CRB_XG_STATE_P3 (NETXEN_NIC_REG(0x98)) -#define CRB_PF_LINK_SPEED_1 (NETXEN_NIC_REG(0xe8)) -#define CRB_PF_LINK_SPEED_2 (NETXEN_NIC_REG(0xec)) - -#define CRB_MPORT_MODE (NETXEN_NIC_REG(0xc4)) -#define CRB_DMA_SHIFT (NETXEN_NIC_REG(0xcc)) -#define CRB_INT_VECTOR (NETXEN_NIC_REG(0xd4)) - -#define CRB_CMD_PRODUCER_OFFSET (NETXEN_NIC_REG(0x08)) -#define CRB_CMD_CONSUMER_OFFSET (NETXEN_NIC_REG(0x0c)) -#define CRB_CMD_PRODUCER_OFFSET_1 (NETXEN_NIC_REG(0x1ac)) -#define CRB_CMD_CONSUMER_OFFSET_1 (NETXEN_NIC_REG(0x1b0)) -#define CRB_CMD_PRODUCER_OFFSET_2 (NETXEN_NIC_REG(0x1b8)) -#define CRB_CMD_CONSUMER_OFFSET_2 (NETXEN_NIC_REG(0x1bc)) -#define CRB_CMD_PRODUCER_OFFSET_3 (NETXEN_NIC_REG(0x1d0)) -#define CRB_CMD_CONSUMER_OFFSET_3 (NETXEN_NIC_REG(0x1d4)) -#define CRB_TEMP_STATE (NETXEN_NIC_REG(0x1b4)) - -#define CRB_V2P_0 (NETXEN_NIC_REG(0x290)) -#define CRB_V2P(port) (CRB_V2P_0+((port)*4)) -#define CRB_DRIVER_VERSION (NETXEN_NIC_REG(0x2a0)) - -#define CRB_SW_INT_MASK_0 (NETXEN_NIC_REG(0x1d8)) -#define CRB_SW_INT_MASK_1 (NETXEN_NIC_REG(0x1e0)) -#define CRB_SW_INT_MASK_2 (NETXEN_NIC_REG(0x1e4)) -#define CRB_SW_INT_MASK_3 (NETXEN_NIC_REG(0x1e8)) - -#define CRB_FW_CAPABILITIES_1 (NETXEN_CAM_RAM(0x128)) -#define CRB_MAC_BLOCK_START (NETXEN_CAM_RAM(0x1c0)) - -/* - * capabilities register, can be used to selectively enable/disable features - * for backward compatibility - */ -#define CRB_NIC_CAPABILITIES_HOST NETXEN_NIC_REG(0x1a8) -#define CRB_NIC_MSI_MODE_HOST NETXEN_NIC_REG(0x270) - -#define INTR_SCHEME_PERPORT 0x1 -#define MSI_MODE_MULTIFUNC 0x1 - -/* used for ethtool tests */ -#define CRB_SCRATCHPAD_TEST NETXEN_NIC_REG(0x280) - -/* - * CrbPortPhanCntrHi/Lo is used to pass the address of HostPhantomIndex address - * which can be read by the Phantom host to get producer/consumer indexes from - * Phantom/Casper. If it is not HOST_SHARED_MEMORY, then the following - * registers will be used for the addresses of the ring's shared memory - * on the Phantom. - */ - -#define nx_get_temp_val(x) ((x) >> 16) -#define nx_get_temp_state(x) ((x) & 0xffff) -#define nx_encode_temp(val, state) (((val) << 16) | (state)) - -/* - * Temperature control. - */ -enum { - NX_TEMP_NORMAL = 0x1, /* Normal operating range */ - NX_TEMP_WARN, /* Sound alert, temperature getting high */ - NX_TEMP_PANIC /* Fatal error, hardware has shut down. */ -}; - -/* Lock IDs for PHY lock */ -#define PHY_LOCK_DRIVER 0x44524956 - -/* Used for PS PCI Memory access */ -#define PCIX_PS_OP_ADDR_LO (0x10000) -/* via CRB (PS side only) */ -#define PCIX_PS_OP_ADDR_HI (0x10004) - -#define PCIX_INT_VECTOR (0x10100) -#define PCIX_INT_MASK (0x10104) - -#define PCIX_CRB_WINDOW (0x10210) -#define PCIX_CRB_WINDOW_F0 (0x10210) -#define PCIX_CRB_WINDOW_F1 (0x10230) -#define PCIX_CRB_WINDOW_F2 (0x10250) -#define PCIX_CRB_WINDOW_F3 (0x10270) -#define PCIX_CRB_WINDOW_F4 (0x102ac) -#define PCIX_CRB_WINDOW_F5 (0x102bc) -#define PCIX_CRB_WINDOW_F6 (0x102cc) -#define PCIX_CRB_WINDOW_F7 (0x102dc) -#define PCIE_CRB_WINDOW_REG(func) (((func) < 4) ? \ - (PCIX_CRB_WINDOW_F0 + (0x20 * (func))) :\ - (PCIX_CRB_WINDOW_F4 + (0x10 * ((func)-4)))) - -#define PCIX_MN_WINDOW (0x10200) -#define PCIX_MN_WINDOW_F0 (0x10200) -#define PCIX_MN_WINDOW_F1 (0x10220) -#define PCIX_MN_WINDOW_F2 (0x10240) -#define PCIX_MN_WINDOW_F3 (0x10260) -#define PCIX_MN_WINDOW_F4 (0x102a0) -#define PCIX_MN_WINDOW_F5 (0x102b0) -#define PCIX_MN_WINDOW_F6 (0x102c0) -#define PCIX_MN_WINDOW_F7 (0x102d0) -#define PCIE_MN_WINDOW_REG(func) (((func) < 4) ? \ - (PCIX_MN_WINDOW_F0 + (0x20 * (func))) :\ - (PCIX_MN_WINDOW_F4 + (0x10 * ((func)-4)))) - -#define PCIX_SN_WINDOW (0x10208) -#define PCIX_SN_WINDOW_F0 (0x10208) -#define PCIX_SN_WINDOW_F1 (0x10228) -#define PCIX_SN_WINDOW_F2 (0x10248) -#define PCIX_SN_WINDOW_F3 (0x10268) -#define PCIX_SN_WINDOW_F4 (0x102a8) -#define PCIX_SN_WINDOW_F5 (0x102b8) -#define PCIX_SN_WINDOW_F6 (0x102c8) -#define PCIX_SN_WINDOW_F7 (0x102d8) -#define PCIE_SN_WINDOW_REG(func) (((func) < 4) ? \ - (PCIX_SN_WINDOW_F0 + (0x20 * (func))) :\ - (PCIX_SN_WINDOW_F4 + (0x10 * ((func)-4)))) - -#define PCIX_OCM_WINDOW (0x10800) -#define PCIX_OCM_WINDOW_REG(func) (PCIX_OCM_WINDOW + 0x20 * (func)) - -#define PCIX_TARGET_STATUS (0x10118) -#define PCIX_TARGET_STATUS_F1 (0x10160) -#define PCIX_TARGET_STATUS_F2 (0x10164) -#define PCIX_TARGET_STATUS_F3 (0x10168) -#define PCIX_TARGET_STATUS_F4 (0x10360) -#define PCIX_TARGET_STATUS_F5 (0x10364) -#define PCIX_TARGET_STATUS_F6 (0x10368) -#define PCIX_TARGET_STATUS_F7 (0x1036c) - -#define PCIX_TARGET_MASK (0x10128) -#define PCIX_TARGET_MASK_F1 (0x10170) -#define PCIX_TARGET_MASK_F2 (0x10174) -#define PCIX_TARGET_MASK_F3 (0x10178) -#define PCIX_TARGET_MASK_F4 (0x10370) -#define PCIX_TARGET_MASK_F5 (0x10374) -#define PCIX_TARGET_MASK_F6 (0x10378) -#define PCIX_TARGET_MASK_F7 (0x1037c) - -#define PCIX_MSI_F0 (0x13000) -#define PCIX_MSI_F1 (0x13004) -#define PCIX_MSI_F2 (0x13008) -#define PCIX_MSI_F3 (0x1300c) -#define PCIX_MSI_F4 (0x13010) -#define PCIX_MSI_F5 (0x13014) -#define PCIX_MSI_F6 (0x13018) -#define PCIX_MSI_F7 (0x1301c) -#define PCIX_MSI_F(i) (0x13000+((i)*4)) - -#define PCIX_PS_MEM_SPACE (0x90000) - -#define NETXEN_PCIX_PH_REG(reg) (NETXEN_CRB_PCIE + (reg)) -#define NETXEN_PCIX_PS_REG(reg) (NETXEN_CRB_PCIX_MD + (reg)) - -#define NETXEN_PCIE_REG(reg) (NETXEN_CRB_PCIE + (reg)) - -#define PCIE_MAX_DMA_XFER_SIZE (0x1404c) - -#define PCIE_DCR 0x00d8 - -#define PCIE_SEM0_LOCK (0x1c000) -#define PCIE_SEM0_UNLOCK (0x1c004) -#define PCIE_SEM1_LOCK (0x1c008) -#define PCIE_SEM1_UNLOCK (0x1c00c) -#define PCIE_SEM2_LOCK (0x1c010) /* Flash lock */ -#define PCIE_SEM2_UNLOCK (0x1c014) /* Flash unlock */ -#define PCIE_SEM3_LOCK (0x1c018) /* Phy lock */ -#define PCIE_SEM3_UNLOCK (0x1c01c) /* Phy unlock */ -#define PCIE_SEM4_LOCK (0x1c020) -#define PCIE_SEM4_UNLOCK (0x1c024) -#define PCIE_SEM5_LOCK (0x1c028) /* API lock */ -#define PCIE_SEM5_UNLOCK (0x1c02c) /* API unlock */ -#define PCIE_SEM6_LOCK (0x1c030) /* sw lock */ -#define PCIE_SEM6_UNLOCK (0x1c034) /* sw unlock */ -#define PCIE_SEM7_LOCK (0x1c038) /* crb win lock */ -#define PCIE_SEM7_UNLOCK (0x1c03c) /* crbwin unlock*/ -#define PCIE_SEM_LOCK(N) (PCIE_SEM0_LOCK + 8*(N)) -#define PCIE_SEM_UNLOCK(N) (PCIE_SEM0_UNLOCK + 8*(N)) - -#define PCIE_SETUP_FUNCTION (0x12040) -#define PCIE_SETUP_FUNCTION2 (0x12048) -#define PCIE_MISCCFG_RC (0x1206c) -#define PCIE_TGT_SPLIT_CHICKEN (0x12080) -#define PCIE_CHICKEN3 (0x120c8) - -#define ISR_INT_STATE_REG (NETXEN_PCIX_PS_REG(PCIE_MISCCFG_RC)) -#define PCIE_MAX_MASTER_SPLIT (0x14048) - -#define NETXEN_PORT_MODE_NONE 0 -#define NETXEN_PORT_MODE_XG 1 -#define NETXEN_PORT_MODE_GB 2 -#define NETXEN_PORT_MODE_802_3_AP 3 -#define NETXEN_PORT_MODE_AUTO_NEG 4 -#define NETXEN_PORT_MODE_AUTO_NEG_1G 5 -#define NETXEN_PORT_MODE_AUTO_NEG_XG 6 -#define NETXEN_PORT_MODE_ADDR (NETXEN_CAM_RAM(0x24)) -#define NETXEN_WOL_PORT_MODE (NETXEN_CAM_RAM(0x198)) - -#define NETXEN_WOL_CONFIG_NV (NETXEN_CAM_RAM(0x184)) -#define NETXEN_WOL_CONFIG (NETXEN_CAM_RAM(0x188)) - -#define NX_PEG_TUNE_MN_PRESENT 0x1 -#define NX_PEG_TUNE_CAPABILITY (NETXEN_CAM_RAM(0x02c)) - -#define NETXEN_DMA_WATCHDOG_CTRL (NETXEN_CAM_RAM(0x14)) -#define NETXEN_PEG_ALIVE_COUNTER (NETXEN_CAM_RAM(0xb0)) -#define NETXEN_PEG_HALT_STATUS1 (NETXEN_CAM_RAM(0xa8)) -#define NETXEN_PEG_HALT_STATUS2 (NETXEN_CAM_RAM(0xac)) -#define NX_CRB_DEV_REF_COUNT (NETXEN_CAM_RAM(0x138)) -#define NX_CRB_DEV_STATE (NETXEN_CAM_RAM(0x140)) - -/* Device State */ -#define NX_DEV_COLD 1 -#define NX_DEV_INITALIZING 2 -#define NX_DEV_READY 3 -#define NX_DEV_NEED_RESET 4 -#define NX_DEV_NEED_QUISCENT 5 -#define NX_DEV_NEED_AER 6 -#define NX_DEV_FAILED 7 - -#define NX_RCODE_DRIVER_INFO 0x20000000 -#define NX_RCODE_DRIVER_CAN_RELOAD 0x40000000 -#define NX_RCODE_FATAL_ERROR 0x80000000 -#define NX_FWERROR_PEGNUM(code) ((code) & 0xff) -#define NX_FWERROR_CODE(code) ((code >> 8) & 0xfffff) - -#define FW_POLL_DELAY (2 * HZ) -#define FW_FAIL_THRESH 3 -#define FW_POLL_THRESH 10 - -#define ISR_MSI_INT_TRIGGER(FUNC) (NETXEN_PCIX_PS_REG(PCIX_MSI_F(FUNC))) -#define ISR_LEGACY_INT_TRIGGERED(VAL) (((VAL) & 0x300) == 0x200) - -/* - * PCI Interrupt Vector Values. - */ -#define PCIX_INT_VECTOR_BIT_F0 0x0080 -#define PCIX_INT_VECTOR_BIT_F1 0x0100 -#define PCIX_INT_VECTOR_BIT_F2 0x0200 -#define PCIX_INT_VECTOR_BIT_F3 0x0400 -#define PCIX_INT_VECTOR_BIT_F4 0x0800 -#define PCIX_INT_VECTOR_BIT_F5 0x1000 -#define PCIX_INT_VECTOR_BIT_F6 0x2000 -#define PCIX_INT_VECTOR_BIT_F7 0x4000 - -struct netxen_legacy_intr_set { - uint32_t int_vec_bit; - uint32_t tgt_status_reg; - uint32_t tgt_mask_reg; - uint32_t pci_int_reg; -}; - -#define NX_LEGACY_INTR_CONFIG \ -{ \ - { \ - .int_vec_bit = PCIX_INT_VECTOR_BIT_F0, \ - .tgt_status_reg = ISR_INT_TARGET_STATUS, \ - .tgt_mask_reg = ISR_INT_TARGET_MASK, \ - .pci_int_reg = ISR_MSI_INT_TRIGGER(0) }, \ - \ - { \ - .int_vec_bit = PCIX_INT_VECTOR_BIT_F1, \ - .tgt_status_reg = ISR_INT_TARGET_STATUS_F1, \ - .tgt_mask_reg = ISR_INT_TARGET_MASK_F1, \ - .pci_int_reg = ISR_MSI_INT_TRIGGER(1) }, \ - \ - { \ - .int_vec_bit = PCIX_INT_VECTOR_BIT_F2, \ - .tgt_status_reg = ISR_INT_TARGET_STATUS_F2, \ - .tgt_mask_reg = ISR_INT_TARGET_MASK_F2, \ - .pci_int_reg = ISR_MSI_INT_TRIGGER(2) }, \ - \ - { \ - .int_vec_bit = PCIX_INT_VECTOR_BIT_F3, \ - .tgt_status_reg = ISR_INT_TARGET_STATUS_F3, \ - .tgt_mask_reg = ISR_INT_TARGET_MASK_F3, \ - .pci_int_reg = ISR_MSI_INT_TRIGGER(3) }, \ - \ - { \ - .int_vec_bit = PCIX_INT_VECTOR_BIT_F4, \ - .tgt_status_reg = ISR_INT_TARGET_STATUS_F4, \ - .tgt_mask_reg = ISR_INT_TARGET_MASK_F4, \ - .pci_int_reg = ISR_MSI_INT_TRIGGER(4) }, \ - \ - { \ - .int_vec_bit = PCIX_INT_VECTOR_BIT_F5, \ - .tgt_status_reg = ISR_INT_TARGET_STATUS_F5, \ - .tgt_mask_reg = ISR_INT_TARGET_MASK_F5, \ - .pci_int_reg = ISR_MSI_INT_TRIGGER(5) }, \ - \ - { \ - .int_vec_bit = PCIX_INT_VECTOR_BIT_F6, \ - .tgt_status_reg = ISR_INT_TARGET_STATUS_F6, \ - .tgt_mask_reg = ISR_INT_TARGET_MASK_F6, \ - .pci_int_reg = ISR_MSI_INT_TRIGGER(6) }, \ - \ - { \ - .int_vec_bit = PCIX_INT_VECTOR_BIT_F7, \ - .tgt_status_reg = ISR_INT_TARGET_STATUS_F7, \ - .tgt_mask_reg = ISR_INT_TARGET_MASK_F7, \ - .pci_int_reg = ISR_MSI_INT_TRIGGER(7) }, \ -} - -#endif /* __NETXEN_NIC_HDR_H_ */ diff --git a/drivers/net/netxen/netxen_nic_hw.c b/drivers/net/netxen/netxen_nic_hw.c deleted file mode 100644 index 3f89e57cae50..000000000000 --- a/drivers/net/netxen/netxen_nic_hw.c +++ /dev/null @@ -1,1976 +0,0 @@ -/* - * Copyright (C) 2003 - 2009 NetXen, Inc. - * Copyright (C) 2009 - QLogic Corporation. - * All rights reserved. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, - * MA 02111-1307, USA. - * - * The full GNU General Public License is included in this distribution - * in the file called "COPYING". - * - */ - -#include <linux/slab.h> -#include "netxen_nic.h" -#include "netxen_nic_hw.h" - -#include <net/ip.h> - -#define MASK(n) ((1ULL<<(n))-1) -#define MN_WIN(addr) (((addr & 0x1fc0000) >> 1) | ((addr >> 25) & 0x3ff)) -#define OCM_WIN(addr) (((addr & 0x1ff0000) >> 1) | ((addr >> 25) & 0x3ff)) -#define MS_WIN(addr) (addr & 0x0ffc0000) - -#define GET_MEM_OFFS_2M(addr) (addr & MASK(18)) - -#define CRB_BLK(off) ((off >> 20) & 0x3f) -#define CRB_SUBBLK(off) ((off >> 16) & 0xf) -#define CRB_WINDOW_2M (0x130060) -#define CRB_HI(off) ((crb_hub_agt[CRB_BLK(off)] << 20) | ((off) & 0xf0000)) -#define CRB_INDIRECT_2M (0x1e0000UL) - -static void netxen_nic_io_write_128M(struct netxen_adapter *adapter, - void __iomem *addr, u32 data); -static u32 netxen_nic_io_read_128M(struct netxen_adapter *adapter, - void __iomem *addr); - -#ifndef readq -static inline u64 readq(void __iomem *addr) -{ - return readl(addr) | (((u64) readl(addr + 4)) << 32LL); -} -#endif - -#ifndef writeq -static inline void writeq(u64 val, void __iomem *addr) -{ - writel(((u32) (val)), (addr)); - writel(((u32) (val >> 32)), (addr + 4)); -} -#endif - -#define PCI_OFFSET_FIRST_RANGE(adapter, off) \ - ((adapter)->ahw.pci_base0 + (off)) -#define PCI_OFFSET_SECOND_RANGE(adapter, off) \ - ((adapter)->ahw.pci_base1 + (off) - SECOND_PAGE_GROUP_START) -#define PCI_OFFSET_THIRD_RANGE(adapter, off) \ - ((adapter)->ahw.pci_base2 + (off) - THIRD_PAGE_GROUP_START) - -static void __iomem *pci_base_offset(struct netxen_adapter *adapter, - unsigned long off) -{ - if (ADDR_IN_RANGE(off, FIRST_PAGE_GROUP_START, FIRST_PAGE_GROUP_END)) - return PCI_OFFSET_FIRST_RANGE(adapter, off); - - if (ADDR_IN_RANGE(off, SECOND_PAGE_GROUP_START, SECOND_PAGE_GROUP_END)) - return PCI_OFFSET_SECOND_RANGE(adapter, off); - - if (ADDR_IN_RANGE(off, THIRD_PAGE_GROUP_START, THIRD_PAGE_GROUP_END)) - return PCI_OFFSET_THIRD_RANGE(adapter, off); - - return NULL; -} - -static crb_128M_2M_block_map_t -crb_128M_2M_map[64] __cacheline_aligned_in_smp = { - {{{0, 0, 0, 0} } }, /* 0: PCI */ - {{{1, 0x0100000, 0x0102000, 0x120000}, /* 1: PCIE */ - {1, 0x0110000, 0x0120000, 0x130000}, - {1, 0x0120000, 0x0122000, 0x124000}, - {1, 0x0130000, 0x0132000, 0x126000}, - {1, 0x0140000, 0x0142000, 0x128000}, - {1, 0x0150000, 0x0152000, 0x12a000}, - {1, 0x0160000, 0x0170000, 0x110000}, - {1, 0x0170000, 0x0172000, 0x12e000}, - {0, 0x0000000, 0x0000000, 0x000000}, - {0, 0x0000000, 0x0000000, 0x000000}, - {0, 0x0000000, 0x0000000, 0x000000}, - {0, 0x0000000, 0x0000000, 0x000000}, - {0, 0x0000000, 0x0000000, 0x000000}, - {0, 0x0000000, 0x0000000, 0x000000}, - {1, 0x01e0000, 0x01e0800, 0x122000}, - {0, 0x0000000, 0x0000000, 0x000000} } }, - {{{1, 0x0200000, 0x0210000, 0x180000} } },/* 2: MN */ - {{{0, 0, 0, 0} } }, /* 3: */ - {{{1, 0x0400000, 0x0401000, 0x169000} } },/* 4: P2NR1 */ - {{{1, 0x0500000, 0x0510000, 0x140000} } },/* 5: SRE */ - {{{1, 0x0600000, 0x0610000, 0x1c0000} } },/* 6: NIU */ - {{{1, 0x0700000, 0x0704000, 0x1b8000} } },/* 7: QM */ - {{{1, 0x0800000, 0x0802000, 0x170000}, /* 8: SQM0 */ - {0, 0x0000000, 0x0000000, 0x000000}, - {0, 0x0000000, 0x0000000, 0x000000}, - {0, 0x0000000, 0x0000000, 0x000000}, - {0, 0x0000000, 0x0000000, 0x000000}, - {0, 0x0000000, 0x0000000, 0x000000}, - {0, 0x0000000, 0x0000000, 0x000000}, - {0, 0x0000000, 0x0000000, 0x000000}, - {0, 0x0000000, 0x0000000, 0x000000}, - {0, 0x0000000, 0x0000000, 0x000000}, - {0, 0x0000000, 0x0000000, 0x000000}, - {0, 0x0000000, 0x0000000, 0x000000}, - {0, 0x0000000, 0x0000000, 0x000000}, - {0, 0x0000000, 0x0000000, 0x000000}, - {0, 0x0000000, 0x0000000, 0x000000}, - {1, 0x08f0000, 0x08f2000, 0x172000} } }, - {{{1, 0x0900000, 0x0902000, 0x174000}, /* 9: SQM1*/ - {0, 0x0000000, 0x0000000, 0x000000}, - {0, 0x0000000, 0x0000000, 0x000000}, - {0, 0x0000000, 0x0000000, 0x000000}, - {0, 0x0000000, 0x0000000, 0x000000}, - {0, 0x0000000, 0x0000000, 0x000000}, - {0, 0x0000000, 0x0000000, 0x000000}, - {0, 0x0000000, 0x0000000, 0x000000}, - {0, 0x0000000, 0x0000000, 0x000000}, - {0, 0x0000000, 0x0000000, 0x000000}, - {0, 0x0000000, 0x0000000, 0x000000}, - {0, 0x0000000, 0x0000000, 0x000000}, - {0, 0x0000000, 0x0000000, 0x000000}, - {0, 0x0000000, 0x0000000, 0x000000}, - {0, 0x0000000, 0x0000000, 0x000000}, - {1, 0x09f0000, 0x09f2000, 0x176000} } }, - {{{0, 0x0a00000, 0x0a02000, 0x178000}, /* 10: SQM2*/ - {0, 0x0000000, 0x0000000, 0x000000}, - {0, 0x0000000, 0x0000000, 0x000000}, - {0, 0x0000000, 0x0000000, 0x000000}, - {0, 0x0000000, 0x0000000, 0x000000}, - {0, 0x0000000, 0x0000000, 0x000000}, - {0, 0x0000000, 0x0000000, 0x000000}, - {0, 0x0000000, 0x0000000, 0x000000}, - {0, 0x0000000, 0x0000000, 0x000000}, - {0, 0x0000000, 0x0000000, 0x000000}, - {0, 0x0000000, 0x0000000, 0x000000}, - {0, 0x0000000, 0x0000000, 0x000000}, - {0, 0x0000000, 0x0000000, 0x000000}, - {0, 0x0000000, 0x0000000, 0x000000}, - {0, 0x0000000, 0x0000000, 0x000000}, - {1, 0x0af0000, 0x0af2000, 0x17a000} } }, - {{{0, 0x0b00000, 0x0b02000, 0x17c000}, /* 11: SQM3*/ - {0, 0x0000000, 0x0000000, 0x000000}, - {0, 0x0000000, 0x0000000, 0x000000}, - {0, 0x0000000, 0x0000000, 0x000000}, - {0, 0x0000000, 0x0000000, 0x000000}, - {0, 0x0000000, 0x0000000, 0x000000}, - {0, 0x0000000, 0x0000000, 0x000000}, - {0, 0x0000000, 0x0000000, 0x000000}, - {0, 0x0000000, 0x0000000, 0x000000}, - {0, 0x0000000, 0x0000000, 0x000000}, - {0, 0x0000000, 0x0000000, 0x000000}, - {0, 0x0000000, 0x0000000, 0x000000}, - {0, 0x0000000, 0x0000000, 0x000000}, - {0, 0x0000000, 0x0000000, 0x000000}, - {0, 0x0000000, 0x0000000, 0x000000}, - {1, 0x0bf0000, 0x0bf2000, 0x17e000} } }, - {{{1, 0x0c00000, 0x0c04000, 0x1d4000} } },/* 12: I2Q */ - {{{1, 0x0d00000, 0x0d04000, 0x1a4000} } },/* 13: TMR */ - {{{1, 0x0e00000, 0x0e04000, 0x1a0000} } },/* 14: ROMUSB */ - {{{1, 0x0f00000, 0x0f01000, 0x164000} } },/* 15: PEG4 */ - {{{0, 0x1000000, 0x1004000, 0x1a8000} } },/* 16: XDMA */ - {{{1, 0x1100000, 0x1101000, 0x160000} } },/* 17: PEG0 */ - {{{1, 0x1200000, 0x1201000, 0x161000} } },/* 18: PEG1 */ - {{{1, 0x1300000, 0x1301000, 0x162000} } },/* 19: PEG2 */ - {{{1, 0x1400000, 0x1401000, 0x163000} } },/* 20: PEG3 */ - {{{1, 0x1500000, 0x1501000, 0x165000} } },/* 21: P2ND */ - {{{1, 0x1600000, 0x1601000, 0x166000} } },/* 22: P2NI */ - {{{0, 0, 0, 0} } }, /* 23: */ - {{{0, 0, 0, 0} } }, /* 24: */ - {{{0, 0, 0, 0} } }, /* 25: */ - {{{0, 0, 0, 0} } }, /* 26: */ - {{{0, 0, 0, 0} } }, /* 27: */ - {{{0, 0, 0, 0} } }, /* 28: */ - {{{1, 0x1d00000, 0x1d10000, 0x190000} } },/* 29: MS */ - {{{1, 0x1e00000, 0x1e01000, 0x16a000} } },/* 30: P2NR2 */ - {{{1, 0x1f00000, 0x1f10000, 0x150000} } },/* 31: EPG */ - {{{0} } }, /* 32: PCI */ - {{{1, 0x2100000, 0x2102000, 0x120000}, /* 33: PCIE */ - {1, 0x2110000, 0x2120000, 0x130000}, - {1, 0x2120000, 0x2122000, 0x124000}, - {1, 0x2130000, 0x2132000, 0x126000}, - {1, 0x2140000, 0x2142000, 0x128000}, - {1, 0x2150000, 0x2152000, 0x12a000}, - {1, 0x2160000, 0x2170000, 0x110000}, - {1, 0x2170000, 0x2172000, 0x12e000}, - {0, 0x0000000, 0x0000000, 0x000000}, - {0, 0x0000000, 0x0000000, 0x000000}, - {0, 0x0000000, 0x0000000, 0x000000}, - {0, 0x0000000, 0x0000000, 0x000000}, - {0, 0x0000000, 0x0000000, 0x000000}, - {0, 0x0000000, 0x0000000, 0x000000}, - {0, 0x0000000, 0x0000000, 0x000000}, - {0, 0x0000000, 0x0000000, 0x000000} } }, - {{{1, 0x2200000, 0x2204000, 0x1b0000} } },/* 34: CAM */ - {{{0} } }, /* 35: */ - {{{0} } }, /* 36: */ - {{{0} } }, /* 37: */ - {{{0} } }, /* 38: */ - {{{0} } }, /* 39: */ - {{{1, 0x2800000, 0x2804000, 0x1a4000} } },/* 40: TMR */ - {{{1, 0x2900000, 0x2901000, 0x16b000} } },/* 41: P2NR3 */ - {{{1, 0x2a00000, 0x2a00400, 0x1ac400} } },/* 42: RPMX1 */ - {{{1, 0x2b00000, 0x2b00400, 0x1ac800} } },/* 43: RPMX2 */ - {{{1, 0x2c00000, 0x2c00400, 0x1acc00} } },/* 44: RPMX3 */ - {{{1, 0x2d00000, 0x2d00400, 0x1ad000} } },/* 45: RPMX4 */ - {{{1, 0x2e00000, 0x2e00400, 0x1ad400} } },/* 46: RPMX5 */ - {{{1, 0x2f00000, 0x2f00400, 0x1ad800} } },/* 47: RPMX6 */ - {{{1, 0x3000000, 0x3000400, 0x1adc00} } },/* 48: RPMX7 */ - {{{0, 0x3100000, 0x3104000, 0x1a8000} } },/* 49: XDMA */ - {{{1, 0x3200000, 0x3204000, 0x1d4000} } },/* 50: I2Q */ - {{{1, 0x3300000, 0x3304000, 0x1a0000} } },/* 51: ROMUSB */ - {{{0} } }, /* 52: */ - {{{1, 0x3500000, 0x3500400, 0x1ac000} } },/* 53: RPMX0 */ - {{{1, 0x3600000, 0x3600400, 0x1ae000} } },/* 54: RPMX8 */ - {{{1, 0x3700000, 0x3700400, 0x1ae400} } },/* 55: RPMX9 */ - {{{1, 0x3800000, 0x3804000, 0x1d0000} } },/* 56: OCM0 */ - {{{1, 0x3900000, 0x3904000, 0x1b4000} } },/* 57: CRYPTO */ - {{{1, 0x3a00000, 0x3a04000, 0x1d8000} } },/* 58: SMB */ - {{{0} } }, /* 59: I2C0 */ - {{{0} } }, /* 60: I2C1 */ - {{{1, 0x3d00000, 0x3d04000, 0x1d8000} } },/* 61: LPC */ - {{{1, 0x3e00000, 0x3e01000, 0x167000} } },/* 62: P2NC */ - {{{1, 0x3f00000, 0x3f01000, 0x168000} } } /* 63: P2NR0 */ -}; - -/* - * top 12 bits of crb internal address (hub, agent) - */ -static unsigned crb_hub_agt[64] = -{ - 0, - NETXEN_HW_CRB_HUB_AGT_ADR_PS, - NETXEN_HW_CRB_HUB_AGT_ADR_MN, - NETXEN_HW_CRB_HUB_AGT_ADR_MS, - 0, - NETXEN_HW_CRB_HUB_AGT_ADR_SRE, - NETXEN_HW_CRB_HUB_AGT_ADR_NIU, - NETXEN_HW_CRB_HUB_AGT_ADR_QMN, - NETXEN_HW_CRB_HUB_AGT_ADR_SQN0, - NETXEN_HW_CRB_HUB_AGT_ADR_SQN1, - NETXEN_HW_CRB_HUB_AGT_ADR_SQN2, - NETXEN_HW_CRB_HUB_AGT_ADR_SQN3, - NETXEN_HW_CRB_HUB_AGT_ADR_I2Q, - NETXEN_HW_CRB_HUB_AGT_ADR_TIMR, - NETXEN_HW_CRB_HUB_AGT_ADR_ROMUSB, - NETXEN_HW_CRB_HUB_AGT_ADR_PGN4, - NETXEN_HW_CRB_HUB_AGT_ADR_XDMA, - NETXEN_HW_CRB_HUB_AGT_ADR_PGN0, - NETXEN_HW_CRB_HUB_AGT_ADR_PGN1, - NETXEN_HW_CRB_HUB_AGT_ADR_PGN2, - NETXEN_HW_CRB_HUB_AGT_ADR_PGN3, - NETXEN_HW_CRB_HUB_AGT_ADR_PGND, - NETXEN_HW_CRB_HUB_AGT_ADR_PGNI, - NETXEN_HW_CRB_HUB_AGT_ADR_PGS0, - NETXEN_HW_CRB_HUB_AGT_ADR_PGS1, - NETXEN_HW_CRB_HUB_AGT_ADR_PGS2, - NETXEN_HW_CRB_HUB_AGT_ADR_PGS3, - 0, - NETXEN_HW_CRB_HUB_AGT_ADR_PGSI, - NETXEN_HW_CRB_HUB_AGT_ADR_SN, - 0, - NETXEN_HW_CRB_HUB_AGT_ADR_EG, - 0, - NETXEN_HW_CRB_HUB_AGT_ADR_PS, - NETXEN_HW_CRB_HUB_AGT_ADR_CAM, - 0, - 0, - 0, - 0, - 0, - NETXEN_HW_CRB_HUB_AGT_ADR_TIMR, - 0, - NETXEN_HW_CRB_HUB_AGT_ADR_RPMX1, - NETXEN_HW_CRB_HUB_AGT_ADR_RPMX2, - NETXEN_HW_CRB_HUB_AGT_ADR_RPMX3, - NETXEN_HW_CRB_HUB_AGT_ADR_RPMX4, - NETXEN_HW_CRB_HUB_AGT_ADR_RPMX5, - NETXEN_HW_CRB_HUB_AGT_ADR_RPMX6, - NETXEN_HW_CRB_HUB_AGT_ADR_RPMX7, - NETXEN_HW_CRB_HUB_AGT_ADR_XDMA, - NETXEN_HW_CRB_HUB_AGT_ADR_I2Q, - NETXEN_HW_CRB_HUB_AGT_ADR_ROMUSB, - 0, - NETXEN_HW_CRB_HUB_AGT_ADR_RPMX0, - NETXEN_HW_CRB_HUB_AGT_ADR_RPMX8, - NETXEN_HW_CRB_HUB_AGT_ADR_RPMX9, - NETXEN_HW_CRB_HUB_AGT_ADR_OCM0, - 0, - NETXEN_HW_CRB_HUB_AGT_ADR_SMB, - NETXEN_HW_CRB_HUB_AGT_ADR_I2C0, - NETXEN_HW_CRB_HUB_AGT_ADR_I2C1, - 0, - NETXEN_HW_CRB_HUB_AGT_ADR_PGNC, - 0, -}; - -/* PCI Windowing for DDR regions. */ - -#define NETXEN_WINDOW_ONE 0x2000000 /*CRB Window: bit 25 of CRB address */ - -#define NETXEN_PCIE_SEM_TIMEOUT 10000 - -static int netxen_nic_set_mtu_xgb(struct netxen_adapter *adapter, int new_mtu); - -int -netxen_pcie_sem_lock(struct netxen_adapter *adapter, int sem, u32 id_reg) -{ - int done = 0, timeout = 0; - - while (!done) { - done = NXRD32(adapter, NETXEN_PCIE_REG(PCIE_SEM_LOCK(sem))); - if (done == 1) - break; - if (++timeout >= NETXEN_PCIE_SEM_TIMEOUT) - return -EIO; - msleep(1); - } - - if (id_reg) - NXWR32(adapter, id_reg, adapter->portnum); - - return 0; -} - -void -netxen_pcie_sem_unlock(struct netxen_adapter *adapter, int sem) -{ - NXRD32(adapter, NETXEN_PCIE_REG(PCIE_SEM_UNLOCK(sem))); -} - -static int netxen_niu_xg_init_port(struct netxen_adapter *adapter, int port) -{ - if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) { - NXWR32(adapter, NETXEN_NIU_XGE_CONFIG_1+(0x10000*port), 0x1447); - NXWR32(adapter, NETXEN_NIU_XGE_CONFIG_0+(0x10000*port), 0x5); - } - - return 0; -} - -/* Disable an XG interface */ -static int netxen_niu_disable_xg_port(struct netxen_adapter *adapter) -{ - __u32 mac_cfg; - u32 port = adapter->physical_port; - - if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) - return 0; - - if (port > NETXEN_NIU_MAX_XG_PORTS) - return -EINVAL; - - mac_cfg = 0; - if (NXWR32(adapter, - NETXEN_NIU_XGE_CONFIG_0 + (0x10000 * port), mac_cfg)) - return -EIO; - return 0; -} - -#define NETXEN_UNICAST_ADDR(port, index) \ - (NETXEN_UNICAST_ADDR_BASE+(port*32)+(index*8)) -#define NETXEN_MCAST_ADDR(port, index) \ - (NETXEN_MULTICAST_ADDR_BASE+(port*0x80)+(index*8)) -#define MAC_HI(addr) \ - ((addr[2] << 16) | (addr[1] << 8) | (addr[0])) -#define MAC_LO(addr) \ - ((addr[5] << 16) | (addr[4] << 8) | (addr[3])) - -static int netxen_p2_nic_set_promisc(struct netxen_adapter *adapter, u32 mode) -{ - u32 mac_cfg; - u32 cnt = 0; - __u32 reg = 0x0200; - u32 port = adapter->physical_port; - u16 board_type = adapter->ahw.board_type; - - if (port > NETXEN_NIU_MAX_XG_PORTS) - return -EINVAL; - - mac_cfg = NXRD32(adapter, NETXEN_NIU_XGE_CONFIG_0 + (0x10000 * port)); - mac_cfg &= ~0x4; - NXWR32(adapter, NETXEN_NIU_XGE_CONFIG_0 + (0x10000 * port), mac_cfg); - - if ((board_type == NETXEN_BRDTYPE_P2_SB31_10G_IMEZ) || - (board_type == NETXEN_BRDTYPE_P2_SB31_10G_HMEZ)) - reg = (0x20 << port); - - NXWR32(adapter, NETXEN_NIU_FRAME_COUNT_SELECT, reg); - - mdelay(10); - - while (NXRD32(adapter, NETXEN_NIU_FRAME_COUNT) && ++cnt < 20) - mdelay(10); - - if (cnt < 20) { - - reg = NXRD32(adapter, - NETXEN_NIU_XGE_CONFIG_1 + (0x10000 * port)); - - if (mode == NETXEN_NIU_PROMISC_MODE) - reg = (reg | 0x2000UL); - else - reg = (reg & ~0x2000UL); - - if (mode == NETXEN_NIU_ALLMULTI_MODE) - reg = (reg | 0x1000UL); - else - reg = (reg & ~0x1000UL); - - NXWR32(adapter, - NETXEN_NIU_XGE_CONFIG_1 + (0x10000 * port), reg); - } - - mac_cfg |= 0x4; - NXWR32(adapter, NETXEN_NIU_XGE_CONFIG_0 + (0x10000 * port), mac_cfg); - - return 0; -} - -static int netxen_p2_nic_set_mac_addr(struct netxen_adapter *adapter, u8 *addr) -{ - u32 mac_hi, mac_lo; - u32 reg_hi, reg_lo; - - u8 phy = adapter->physical_port; - - if (phy >= NETXEN_NIU_MAX_XG_PORTS) - return -EINVAL; - - mac_lo = ((u32)addr[0] << 16) | ((u32)addr[1] << 24); - mac_hi = addr[2] | ((u32)addr[3] << 8) | - ((u32)addr[4] << 16) | ((u32)addr[5] << 24); - - reg_lo = NETXEN_NIU_XGE_STATION_ADDR_0_1 + (0x10000 * phy); - reg_hi = NETXEN_NIU_XGE_STATION_ADDR_0_HI + (0x10000 * phy); - - /* write twice to flush */ - if (NXWR32(adapter, reg_lo, mac_lo) || NXWR32(adapter, reg_hi, mac_hi)) - return -EIO; - if (NXWR32(adapter, reg_lo, mac_lo) || NXWR32(adapter, reg_hi, mac_hi)) - return -EIO; - - return 0; -} - -static int -netxen_nic_enable_mcast_filter(struct netxen_adapter *adapter) -{ - u32 val = 0; - u16 port = adapter->physical_port; - u8 *addr = adapter->mac_addr; - - if (adapter->mc_enabled) - return 0; - - val = NXRD32(adapter, NETXEN_MAC_ADDR_CNTL_REG); - val |= (1UL << (28+port)); - NXWR32(adapter, NETXEN_MAC_ADDR_CNTL_REG, val); - - /* add broadcast addr to filter */ - val = 0xffffff; - NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 0), val); - NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 0)+4, val); - - /* add station addr to filter */ - val = MAC_HI(addr); - NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 1), val); - val = MAC_LO(addr); - NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 1)+4, val); - - adapter->mc_enabled = 1; - return 0; -} - -static int -netxen_nic_disable_mcast_filter(struct netxen_adapter *adapter) -{ - u32 val = 0; - u16 port = adapter->physical_port; - u8 *addr = adapter->mac_addr; - - if (!adapter->mc_enabled) - return 0; - - val = NXRD32(adapter, NETXEN_MAC_ADDR_CNTL_REG); - val &= ~(1UL << (28+port)); - NXWR32(adapter, NETXEN_MAC_ADDR_CNTL_REG, val); - - val = MAC_HI(addr); - NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 0), val); - val = MAC_LO(addr); - NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 0)+4, val); - - NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 1), 0); - NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 1)+4, 0); - - adapter->mc_enabled = 0; - return 0; -} - -static int -netxen_nic_set_mcast_addr(struct netxen_adapter *adapter, - int index, u8 *addr) -{ - u32 hi = 0, lo = 0; - u16 port = adapter->physical_port; - - lo = MAC_LO(addr); - hi = MAC_HI(addr); - - NXWR32(adapter, NETXEN_MCAST_ADDR(port, index), hi); - NXWR32(adapter, NETXEN_MCAST_ADDR(port, index)+4, lo); - - return 0; -} - -static void netxen_p2_nic_set_multi(struct net_device *netdev) -{ - struct netxen_adapter *adapter = netdev_priv(netdev); - struct netdev_hw_addr *ha; - u8 null_addr[6]; - int i; - - memset(null_addr, 0, 6); - - if (netdev->flags & IFF_PROMISC) { - - adapter->set_promisc(adapter, - NETXEN_NIU_PROMISC_MODE); - - /* Full promiscuous mode */ - netxen_nic_disable_mcast_filter(adapter); - - return; - } - - if (netdev_mc_empty(netdev)) { - adapter->set_promisc(adapter, - NETXEN_NIU_NON_PROMISC_MODE); - netxen_nic_disable_mcast_filter(adapter); - return; - } - - adapter->set_promisc(adapter, NETXEN_NIU_ALLMULTI_MODE); - if (netdev->flags & IFF_ALLMULTI || - netdev_mc_count(netdev) > adapter->max_mc_count) { - netxen_nic_disable_mcast_filter(adapter); - return; - } - - netxen_nic_enable_mcast_filter(adapter); - - i = 0; - netdev_for_each_mc_addr(ha, netdev) - netxen_nic_set_mcast_addr(adapter, i++, ha->addr); - - /* Clear out remaining addresses */ - while (i < adapter->max_mc_count) - netxen_nic_set_mcast_addr(adapter, i++, null_addr); -} - -static int -netxen_send_cmd_descs(struct netxen_adapter *adapter, - struct cmd_desc_type0 *cmd_desc_arr, int nr_desc) -{ - u32 i, producer, consumer; - struct netxen_cmd_buffer *pbuf; - struct cmd_desc_type0 *cmd_desc; - struct nx_host_tx_ring *tx_ring; - - i = 0; - - if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC) - return -EIO; - - tx_ring = adapter->tx_ring; - __netif_tx_lock_bh(tx_ring->txq); - - producer = tx_ring->producer; - consumer = tx_ring->sw_consumer; - - if (nr_desc >= netxen_tx_avail(tx_ring)) { - netif_tx_stop_queue(tx_ring->txq); - smp_mb(); - if (netxen_tx_avail(tx_ring) > nr_desc) { - if (netxen_tx_avail(tx_ring) > TX_STOP_THRESH) - netif_tx_wake_queue(tx_ring->txq); - } else { - __netif_tx_unlock_bh(tx_ring->txq); - return -EBUSY; - } - } - - do { - cmd_desc = &cmd_desc_arr[i]; - - pbuf = &tx_ring->cmd_buf_arr[producer]; - pbuf->skb = NULL; - pbuf->frag_count = 0; - - memcpy(&tx_ring->desc_head[producer], - &cmd_desc_arr[i], sizeof(struct cmd_desc_type0)); - - producer = get_next_index(producer, tx_ring->num_desc); - i++; - - } while (i != nr_desc); - - tx_ring->producer = producer; - - netxen_nic_update_cmd_producer(adapter, tx_ring); - - __netif_tx_unlock_bh(tx_ring->txq); - - return 0; -} - -static int -nx_p3_sre_macaddr_change(struct netxen_adapter *adapter, u8 *addr, unsigned op) -{ - nx_nic_req_t req; - nx_mac_req_t *mac_req; - u64 word; - - memset(&req, 0, sizeof(nx_nic_req_t)); - req.qhdr = cpu_to_le64(NX_NIC_REQUEST << 23); - - word = NX_MAC_EVENT | ((u64)adapter->portnum << 16); - req.req_hdr = cpu_to_le64(word); - - mac_req = (nx_mac_req_t *)&req.words[0]; - mac_req->op = op; - memcpy(mac_req->mac_addr, addr, 6); - - return netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1); -} - -static int nx_p3_nic_add_mac(struct netxen_adapter *adapter, - const u8 *addr, struct list_head *del_list) -{ - struct list_head *head; - nx_mac_list_t *cur; - - /* look up if already exists */ - list_for_each(head, del_list) { - cur = list_entry(head, nx_mac_list_t, list); - - if (memcmp(addr, cur->mac_addr, ETH_ALEN) == 0) { - list_move_tail(head, &adapter->mac_list); - return 0; - } - } - - cur = kzalloc(sizeof(nx_mac_list_t), GFP_ATOMIC); - if (cur == NULL) { - printk(KERN_ERR "%s: failed to add mac address filter\n", - adapter->netdev->name); - return -ENOMEM; - } - memcpy(cur->mac_addr, addr, ETH_ALEN); - list_add_tail(&cur->list, &adapter->mac_list); - return nx_p3_sre_macaddr_change(adapter, - cur->mac_addr, NETXEN_MAC_ADD); -} - -static void netxen_p3_nic_set_multi(struct net_device *netdev) -{ - struct netxen_adapter *adapter = netdev_priv(netdev); - struct netdev_hw_addr *ha; - static const u8 bcast_addr[ETH_ALEN] = { - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff - }; - u32 mode = VPORT_MISS_MODE_DROP; - LIST_HEAD(del_list); - struct list_head *head; - nx_mac_list_t *cur; - - if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC) - return; - - list_splice_tail_init(&adapter->mac_list, &del_list); - - nx_p3_nic_add_mac(adapter, adapter->mac_addr, &del_list); - nx_p3_nic_add_mac(adapter, bcast_addr, &del_list); - - if (netdev->flags & IFF_PROMISC) { - mode = VPORT_MISS_MODE_ACCEPT_ALL; - goto send_fw_cmd; - } - - if ((netdev->flags & IFF_ALLMULTI) || - (netdev_mc_count(netdev) > adapter->max_mc_count)) { - mode = VPORT_MISS_MODE_ACCEPT_MULTI; - goto send_fw_cmd; - } - - if (!netdev_mc_empty(netdev)) { - netdev_for_each_mc_addr(ha, netdev) - nx_p3_nic_add_mac(adapter, ha->addr, &del_list); - } - -send_fw_cmd: - adapter->set_promisc(adapter, mode); - head = &del_list; - while (!list_empty(head)) { - cur = list_entry(head->next, nx_mac_list_t, list); - - nx_p3_sre_macaddr_change(adapter, - cur->mac_addr, NETXEN_MAC_DEL); - list_del(&cur->list); - kfree(cur); - } -} - -static int netxen_p3_nic_set_promisc(struct netxen_adapter *adapter, u32 mode) -{ - nx_nic_req_t req; - u64 word; - - memset(&req, 0, sizeof(nx_nic_req_t)); - - req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23); - - word = NX_NIC_H2C_OPCODE_PROXY_SET_VPORT_MISS_MODE | - ((u64)adapter->portnum << 16); - req.req_hdr = cpu_to_le64(word); - - req.words[0] = cpu_to_le64(mode); - - return netxen_send_cmd_descs(adapter, - (struct cmd_desc_type0 *)&req, 1); -} - -void netxen_p3_free_mac_list(struct netxen_adapter *adapter) -{ - nx_mac_list_t *cur; - struct list_head *head = &adapter->mac_list; - - while (!list_empty(head)) { - cur = list_entry(head->next, nx_mac_list_t, list); - nx_p3_sre_macaddr_change(adapter, - cur->mac_addr, NETXEN_MAC_DEL); - list_del(&cur->list); - kfree(cur); - } -} - -static int netxen_p3_nic_set_mac_addr(struct netxen_adapter *adapter, u8 *addr) -{ - /* assuming caller has already copied new addr to netdev */ - netxen_p3_nic_set_multi(adapter->netdev); - return 0; -} - -#define NETXEN_CONFIG_INTR_COALESCE 3 - -/* - * Send the interrupt coalescing parameter set by ethtool to the card. - */ -int netxen_config_intr_coalesce(struct netxen_adapter *adapter) -{ - nx_nic_req_t req; - u64 word[6]; - int rv, i; - - memset(&req, 0, sizeof(nx_nic_req_t)); - memset(word, 0, sizeof(word)); - - req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23); - - word[0] = NETXEN_CONFIG_INTR_COALESCE | ((u64)adapter->portnum << 16); - req.req_hdr = cpu_to_le64(word[0]); - - memcpy(&word[0], &adapter->coal, sizeof(adapter->coal)); - for (i = 0; i < 6; i++) - req.words[i] = cpu_to_le64(word[i]); - - rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1); - if (rv != 0) { - printk(KERN_ERR "ERROR. Could not send " - "interrupt coalescing parameters\n"); - } - - return rv; -} - -int netxen_config_hw_lro(struct netxen_adapter *adapter, int enable) -{ - nx_nic_req_t req; - u64 word; - int rv = 0; - - if (!test_bit(__NX_FW_ATTACHED, &adapter->state)) - return 0; - - memset(&req, 0, sizeof(nx_nic_req_t)); - - req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23); - - word = NX_NIC_H2C_OPCODE_CONFIG_HW_LRO | ((u64)adapter->portnum << 16); - req.req_hdr = cpu_to_le64(word); - - req.words[0] = cpu_to_le64(enable); - - rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1); - if (rv != 0) { - printk(KERN_ERR "ERROR. Could not send " - "configure hw lro request\n"); - } - - return rv; -} - -int netxen_config_bridged_mode(struct netxen_adapter *adapter, int enable) -{ - nx_nic_req_t req; - u64 word; - int rv = 0; - - if (!!(adapter->flags & NETXEN_NIC_BRIDGE_ENABLED) == enable) - return rv; - - memset(&req, 0, sizeof(nx_nic_req_t)); - - req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23); - - word = NX_NIC_H2C_OPCODE_CONFIG_BRIDGING | - ((u64)adapter->portnum << 16); - req.req_hdr = cpu_to_le64(word); - - req.words[0] = cpu_to_le64(enable); - - rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1); - if (rv != 0) { - printk(KERN_ERR "ERROR. Could not send " - "configure bridge mode request\n"); - } - - adapter->flags ^= NETXEN_NIC_BRIDGE_ENABLED; - - return rv; -} - - -#define RSS_HASHTYPE_IP_TCP 0x3 - -int netxen_config_rss(struct netxen_adapter *adapter, int enable) -{ - nx_nic_req_t req; - u64 word; - int i, rv; - - static const u64 key[] = { - 0xbeac01fa6a42b73bULL, 0x8030f20c77cb2da3ULL, - 0xae7b30b4d0ca2bcbULL, 0x43a38fb04167253dULL, - 0x255b0ec26d5a56daULL - }; - - - memset(&req, 0, sizeof(nx_nic_req_t)); - req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23); - - word = NX_NIC_H2C_OPCODE_CONFIG_RSS | ((u64)adapter->portnum << 16); - req.req_hdr = cpu_to_le64(word); - - /* - * RSS request: - * bits 3-0: hash_method - * 5-4: hash_type_ipv4 - * 7-6: hash_type_ipv6 - * 8: enable - * 9: use indirection table - * 47-10: reserved - * 63-48: indirection table mask - */ - word = ((u64)(RSS_HASHTYPE_IP_TCP & 0x3) << 4) | - ((u64)(RSS_HASHTYPE_IP_TCP & 0x3) << 6) | - ((u64)(enable & 0x1) << 8) | - ((0x7ULL) << 48); - req.words[0] = cpu_to_le64(word); - for (i = 0; i < ARRAY_SIZE(key); i++) - req.words[i+1] = cpu_to_le64(key[i]); - - - rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1); - if (rv != 0) { - printk(KERN_ERR "%s: could not configure RSS\n", - adapter->netdev->name); - } - - return rv; -} - -int netxen_config_ipaddr(struct netxen_adapter *adapter, u32 ip, int cmd) -{ - nx_nic_req_t req; - u64 word; - int rv; - - memset(&req, 0, sizeof(nx_nic_req_t)); - req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23); - - word = NX_NIC_H2C_OPCODE_CONFIG_IPADDR | ((u64)adapter->portnum << 16); - req.req_hdr = cpu_to_le64(word); - - req.words[0] = cpu_to_le64(cmd); - req.words[1] = cpu_to_le64(ip); - - rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1); - if (rv != 0) { - printk(KERN_ERR "%s: could not notify %s IP 0x%x reuqest\n", - adapter->netdev->name, - (cmd == NX_IP_UP) ? "Add" : "Remove", ip); - } - return rv; -} - -int netxen_linkevent_request(struct netxen_adapter *adapter, int enable) -{ - nx_nic_req_t req; - u64 word; - int rv; - - memset(&req, 0, sizeof(nx_nic_req_t)); - req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23); - - word = NX_NIC_H2C_OPCODE_GET_LINKEVENT | ((u64)adapter->portnum << 16); - req.req_hdr = cpu_to_le64(word); - req.words[0] = cpu_to_le64(enable | (enable << 8)); - - rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1); - if (rv != 0) { - printk(KERN_ERR "%s: could not configure link notification\n", - adapter->netdev->name); - } - - return rv; -} - -int netxen_send_lro_cleanup(struct netxen_adapter *adapter) -{ - nx_nic_req_t req; - u64 word; - int rv; - - if (!test_bit(__NX_FW_ATTACHED, &adapter->state)) - return 0; - - memset(&req, 0, sizeof(nx_nic_req_t)); - req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23); - - word = NX_NIC_H2C_OPCODE_LRO_REQUEST | - ((u64)adapter->portnum << 16) | - ((u64)NX_NIC_LRO_REQUEST_CLEANUP << 56) ; - - req.req_hdr = cpu_to_le64(word); - - rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1); - if (rv != 0) { - printk(KERN_ERR "%s: could not cleanup lro flows\n", - adapter->netdev->name); - } - return rv; -} - -/* - * netxen_nic_change_mtu - Change the Maximum Transfer Unit - * @returns 0 on success, negative on failure - */ - -#define MTU_FUDGE_FACTOR 100 - -int netxen_nic_change_mtu(struct net_device *netdev, int mtu) -{ - struct netxen_adapter *adapter = netdev_priv(netdev); - int max_mtu; - int rc = 0; - - if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) - max_mtu = P3_MAX_MTU; - else - max_mtu = P2_MAX_MTU; - - if (mtu > max_mtu) { - printk(KERN_ERR "%s: mtu > %d bytes unsupported\n", - netdev->name, max_mtu); - return -EINVAL; - } - - if (adapter->set_mtu) - rc = adapter->set_mtu(adapter, mtu); - - if (!rc) - netdev->mtu = mtu; - - return rc; -} - -static int netxen_get_flash_block(struct netxen_adapter *adapter, int base, - int size, __le32 * buf) -{ - int i, v, addr; - __le32 *ptr32; - - addr = base; - ptr32 = buf; - for (i = 0; i < size / sizeof(u32); i++) { - if (netxen_rom_fast_read(adapter, addr, &v) == -1) - return -1; - *ptr32 = cpu_to_le32(v); - ptr32++; - addr += sizeof(u32); - } - if ((char *)buf + size > (char *)ptr32) { - __le32 local; - if (netxen_rom_fast_read(adapter, addr, &v) == -1) - return -1; - local = cpu_to_le32(v); - memcpy(ptr32, &local, (char *)buf + size - (char *)ptr32); - } - - return 0; -} - -int netxen_get_flash_mac_addr(struct netxen_adapter *adapter, u64 *mac) -{ - __le32 *pmac = (__le32 *) mac; - u32 offset; - - offset = NX_FW_MAC_ADDR_OFFSET + (adapter->portnum * sizeof(u64)); - - if (netxen_get_flash_block(adapter, offset, sizeof(u64), pmac) == -1) - return -1; - - if (*mac == cpu_to_le64(~0ULL)) { - - offset = NX_OLD_MAC_ADDR_OFFSET + - (adapter->portnum * sizeof(u64)); - - if (netxen_get_flash_block(adapter, - offset, sizeof(u64), pmac) == -1) - return -1; - - if (*mac == cpu_to_le64(~0ULL)) - return -1; - } - return 0; -} - -int netxen_p3_get_mac_addr(struct netxen_adapter *adapter, u64 *mac) -{ - uint32_t crbaddr, mac_hi, mac_lo; - int pci_func = adapter->ahw.pci_func; - - crbaddr = CRB_MAC_BLOCK_START + - (4 * ((pci_func/2) * 3)) + (4 * (pci_func & 1)); - - mac_lo = NXRD32(adapter, crbaddr); - mac_hi = NXRD32(adapter, crbaddr+4); - - if (pci_func & 1) - *mac = le64_to_cpu((mac_lo >> 16) | ((u64)mac_hi << 16)); - else - *mac = le64_to_cpu((u64)mac_lo | ((u64)mac_hi << 32)); - - return 0; -} - -/* - * Changes the CRB window to the specified window. - */ -static void -netxen_nic_pci_set_crbwindow_128M(struct netxen_adapter *adapter, - u32 window) -{ - void __iomem *offset; - int count = 10; - u8 func = adapter->ahw.pci_func; - - if (adapter->ahw.crb_win == window) - return; - - offset = PCI_OFFSET_SECOND_RANGE(adapter, - NETXEN_PCIX_PH_REG(PCIE_CRB_WINDOW_REG(func))); - - writel(window, offset); - do { - if (window == readl(offset)) - break; - - if (printk_ratelimit()) - dev_warn(&adapter->pdev->dev, - "failed to set CRB window to %d\n", - (window == NETXEN_WINDOW_ONE)); - udelay(1); - - } while (--count > 0); - - if (count > 0) - adapter->ahw.crb_win = window; -} - -/* - * Returns < 0 if off is not valid, - * 1 if window access is needed. 'off' is set to offset from - * CRB space in 128M pci map - * 0 if no window access is needed. 'off' is set to 2M addr - * In: 'off' is offset from base in 128M pci map - */ -static int -netxen_nic_pci_get_crb_addr_2M(struct netxen_adapter *adapter, - ulong off, void __iomem **addr) -{ - crb_128M_2M_sub_block_map_t *m; - - - if ((off >= NETXEN_CRB_MAX) || (off < NETXEN_PCI_CRBSPACE)) - return -EINVAL; - - off -= NETXEN_PCI_CRBSPACE; - - /* - * Try direct map - */ - m = &crb_128M_2M_map[CRB_BLK(off)].sub_block[CRB_SUBBLK(off)]; - - if (m->valid && (m->start_128M <= off) && (m->end_128M > off)) { - *addr = adapter->ahw.pci_base0 + m->start_2M + - (off - m->start_128M); - return 0; - } - - /* - * Not in direct map, use crb window - */ - *addr = adapter->ahw.pci_base0 + CRB_INDIRECT_2M + - (off & MASK(16)); - return 1; -} - -/* - * In: 'off' is offset from CRB space in 128M pci map - * Out: 'off' is 2M pci map addr - * side effect: lock crb window - */ -static void -netxen_nic_pci_set_crbwindow_2M(struct netxen_adapter *adapter, ulong off) -{ - u32 window; - void __iomem *addr = adapter->ahw.pci_base0 + CRB_WINDOW_2M; - - off -= NETXEN_PCI_CRBSPACE; - - window = CRB_HI(off); - - writel(window, addr); - if (readl(addr) != window) { - if (printk_ratelimit()) - dev_warn(&adapter->pdev->dev, - "failed to set CRB window to %d off 0x%lx\n", - window, off); - } -} - -static void __iomem * -netxen_nic_map_indirect_address_128M(struct netxen_adapter *adapter, - ulong win_off, void __iomem **mem_ptr) -{ - ulong off = win_off; - void __iomem *addr; - resource_size_t mem_base; - - if (ADDR_IN_WINDOW1(win_off)) - off = NETXEN_CRB_NORMAL(win_off); - - addr = pci_base_offset(adapter, off); - if (addr) - return addr; - - if (adapter->ahw.pci_len0 == 0) - off -= NETXEN_PCI_CRBSPACE; - - mem_base = pci_resource_start(adapter->pdev, 0); - *mem_ptr = ioremap(mem_base + (off & PAGE_MASK), PAGE_SIZE); - if (*mem_ptr) - addr = *mem_ptr + (off & (PAGE_SIZE - 1)); - - return addr; -} - -static int -netxen_nic_hw_write_wx_128M(struct netxen_adapter *adapter, ulong off, u32 data) -{ - unsigned long flags; - void __iomem *addr, *mem_ptr = NULL; - - addr = netxen_nic_map_indirect_address_128M(adapter, off, &mem_ptr); - if (!addr) - return -EIO; - - if (ADDR_IN_WINDOW1(off)) { /* Window 1 */ - netxen_nic_io_write_128M(adapter, addr, data); - } else { /* Window 0 */ - write_lock_irqsave(&adapter->ahw.crb_lock, flags); - netxen_nic_pci_set_crbwindow_128M(adapter, 0); - writel(data, addr); - netxen_nic_pci_set_crbwindow_128M(adapter, - NETXEN_WINDOW_ONE); - write_unlock_irqrestore(&adapter->ahw.crb_lock, flags); - } - - if (mem_ptr) - iounmap(mem_ptr); - - return 0; -} - -static u32 -netxen_nic_hw_read_wx_128M(struct netxen_adapter *adapter, ulong off) -{ - unsigned long flags; - void __iomem *addr, *mem_ptr = NULL; - u32 data; - - addr = netxen_nic_map_indirect_address_128M(adapter, off, &mem_ptr); - if (!addr) - return -EIO; - - if (ADDR_IN_WINDOW1(off)) { /* Window 1 */ - data = netxen_nic_io_read_128M(adapter, addr); - } else { /* Window 0 */ - write_lock_irqsave(&adapter->ahw.crb_lock, flags); - netxen_nic_pci_set_crbwindow_128M(adapter, 0); - data = readl(addr); - netxen_nic_pci_set_crbwindow_128M(adapter, - NETXEN_WINDOW_ONE); - write_unlock_irqrestore(&adapter->ahw.crb_lock, flags); - } - - if (mem_ptr) - iounmap(mem_ptr); - - return data; -} - -static int -netxen_nic_hw_write_wx_2M(struct netxen_adapter *adapter, ulong off, u32 data) -{ - unsigned long flags; - int rv; - void __iomem *addr = NULL; - - rv = netxen_nic_pci_get_crb_addr_2M(adapter, off, &addr); - - if (rv == 0) { - writel(data, addr); - return 0; - } - - if (rv > 0) { - /* indirect access */ - write_lock_irqsave(&adapter->ahw.crb_lock, flags); - crb_win_lock(adapter); - netxen_nic_pci_set_crbwindow_2M(adapter, off); - writel(data, addr); - crb_win_unlock(adapter); - write_unlock_irqrestore(&adapter->ahw.crb_lock, flags); - return 0; - } - - dev_err(&adapter->pdev->dev, - "%s: invalid offset: 0x%016lx\n", __func__, off); - dump_stack(); - return -EIO; -} - -static u32 -netxen_nic_hw_read_wx_2M(struct netxen_adapter *adapter, ulong off) -{ - unsigned long flags; - int rv; - u32 data; - void __iomem *addr = NULL; - - rv = netxen_nic_pci_get_crb_addr_2M(adapter, off, &addr); - - if (rv == 0) - return readl(addr); - - if (rv > 0) { - /* indirect access */ - write_lock_irqsave(&adapter->ahw.crb_lock, flags); - crb_win_lock(adapter); - netxen_nic_pci_set_crbwindow_2M(adapter, off); - data = readl(addr); - crb_win_unlock(adapter); - write_unlock_irqrestore(&adapter->ahw.crb_lock, flags); - return data; - } - - dev_err(&adapter->pdev->dev, - "%s: invalid offset: 0x%016lx\n", __func__, off); - dump_stack(); - return -1; -} - -/* window 1 registers only */ -static void netxen_nic_io_write_128M(struct netxen_adapter *adapter, - void __iomem *addr, u32 data) -{ - read_lock(&adapter->ahw.crb_lock); - writel(data, addr); - read_unlock(&adapter->ahw.crb_lock); -} - -static u32 netxen_nic_io_read_128M(struct netxen_adapter *adapter, - void __iomem *addr) -{ - u32 val; - - read_lock(&adapter->ahw.crb_lock); - val = readl(addr); - read_unlock(&adapter->ahw.crb_lock); - - return val; -} - -static void netxen_nic_io_write_2M(struct netxen_adapter *adapter, - void __iomem *addr, u32 data) -{ - writel(data, addr); -} - -static u32 netxen_nic_io_read_2M(struct netxen_adapter *adapter, - void __iomem *addr) -{ - return readl(addr); -} - -void __iomem * -netxen_get_ioaddr(struct netxen_adapter *adapter, u32 offset) -{ - void __iomem *addr = NULL; - - if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) { - if ((offset < NETXEN_CRB_PCIX_HOST2) && - (offset > NETXEN_CRB_PCIX_HOST)) - addr = PCI_OFFSET_SECOND_RANGE(adapter, offset); - else - addr = NETXEN_CRB_NORMALIZE(adapter, offset); - } else { - WARN_ON(netxen_nic_pci_get_crb_addr_2M(adapter, - offset, &addr)); - } - - return addr; -} - -static int -netxen_nic_pci_set_window_128M(struct netxen_adapter *adapter, - u64 addr, u32 *start) -{ - if (ADDR_IN_RANGE(addr, NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX)) { - *start = (addr - NETXEN_ADDR_OCM0 + NETXEN_PCI_OCM0); - return 0; - } else if (ADDR_IN_RANGE(addr, - NETXEN_ADDR_OCM1, NETXEN_ADDR_OCM1_MAX)) { - *start = (addr - NETXEN_ADDR_OCM1 + NETXEN_PCI_OCM1); - return 0; - } - - return -EIO; -} - -static int -netxen_nic_pci_set_window_2M(struct netxen_adapter *adapter, - u64 addr, u32 *start) -{ - u32 window; - - window = OCM_WIN(addr); - - writel(window, adapter->ahw.ocm_win_crb); - /* read back to flush */ - readl(adapter->ahw.ocm_win_crb); - - adapter->ahw.ocm_win = window; - *start = NETXEN_PCI_OCM0_2M + GET_MEM_OFFS_2M(addr); - return 0; -} - -static int -netxen_nic_pci_mem_access_direct(struct netxen_adapter *adapter, u64 off, - u64 *data, int op) -{ - void __iomem *addr, *mem_ptr = NULL; - resource_size_t mem_base; - int ret; - u32 start; - - spin_lock(&adapter->ahw.mem_lock); - - ret = adapter->pci_set_window(adapter, off, &start); - if (ret != 0) - goto unlock; - - if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) { - addr = adapter->ahw.pci_base0 + start; - } else { - addr = pci_base_offset(adapter, start); - if (addr) - goto noremap; - - mem_base = pci_resource_start(adapter->pdev, 0) + - (start & PAGE_MASK); - mem_ptr = ioremap(mem_base, PAGE_SIZE); - if (mem_ptr == NULL) { - ret = -EIO; - goto unlock; - } - - addr = mem_ptr + (start & (PAGE_SIZE-1)); - } -noremap: - if (op == 0) /* read */ - *data = readq(addr); - else /* write */ - writeq(*data, addr); - -unlock: - spin_unlock(&adapter->ahw.mem_lock); - - if (mem_ptr) - iounmap(mem_ptr); - return ret; -} - -void -netxen_pci_camqm_read_2M(struct netxen_adapter *adapter, u64 off, u64 *data) -{ - void __iomem *addr = adapter->ahw.pci_base0 + - NETXEN_PCI_CAMQM_2M_BASE + (off - NETXEN_PCI_CAMQM); - - spin_lock(&adapter->ahw.mem_lock); - *data = readq(addr); - spin_unlock(&adapter->ahw.mem_lock); -} - -void -netxen_pci_camqm_write_2M(struct netxen_adapter *adapter, u64 off, u64 data) -{ - void __iomem *addr = adapter->ahw.pci_base0 + - NETXEN_PCI_CAMQM_2M_BASE + (off - NETXEN_PCI_CAMQM); - - spin_lock(&adapter->ahw.mem_lock); - writeq(data, addr); - spin_unlock(&adapter->ahw.mem_lock); -} - -#define MAX_CTL_CHECK 1000 - -static int -netxen_nic_pci_mem_write_128M(struct netxen_adapter *adapter, - u64 off, u64 data) -{ - int j, ret; - u32 temp, off_lo, off_hi, addr_hi, data_hi, data_lo; - void __iomem *mem_crb; - - /* Only 64-bit aligned access */ - if (off & 7) - return -EIO; - - /* P2 has different SIU and MIU test agent base addr */ - if (ADDR_IN_RANGE(off, NETXEN_ADDR_QDR_NET, - NETXEN_ADDR_QDR_NET_MAX_P2)) { - mem_crb = pci_base_offset(adapter, - NETXEN_CRB_QDR_NET+SIU_TEST_AGT_BASE); - addr_hi = SIU_TEST_AGT_ADDR_HI; - data_lo = SIU_TEST_AGT_WRDATA_LO; - data_hi = SIU_TEST_AGT_WRDATA_HI; - off_lo = off & SIU_TEST_AGT_ADDR_MASK; - off_hi = SIU_TEST_AGT_UPPER_ADDR(off); - goto correct; - } - - if (ADDR_IN_RANGE(off, NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX)) { - mem_crb = pci_base_offset(adapter, - NETXEN_CRB_DDR_NET+MIU_TEST_AGT_BASE); - addr_hi = MIU_TEST_AGT_ADDR_HI; - data_lo = MIU_TEST_AGT_WRDATA_LO; - data_hi = MIU_TEST_AGT_WRDATA_HI; - off_lo = off & MIU_TEST_AGT_ADDR_MASK; - off_hi = 0; - goto correct; - } - - if (ADDR_IN_RANGE(off, NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX) || - ADDR_IN_RANGE(off, NETXEN_ADDR_OCM1, NETXEN_ADDR_OCM1_MAX)) { - if (adapter->ahw.pci_len0 != 0) { - return netxen_nic_pci_mem_access_direct(adapter, - off, &data, 1); - } - } - - return -EIO; - -correct: - spin_lock(&adapter->ahw.mem_lock); - netxen_nic_pci_set_crbwindow_128M(adapter, 0); - - writel(off_lo, (mem_crb + MIU_TEST_AGT_ADDR_LO)); - writel(off_hi, (mem_crb + addr_hi)); - writel(data & 0xffffffff, (mem_crb + data_lo)); - writel((data >> 32) & 0xffffffff, (mem_crb + data_hi)); - writel((TA_CTL_ENABLE | TA_CTL_WRITE), (mem_crb + TEST_AGT_CTRL)); - writel((TA_CTL_START | TA_CTL_ENABLE | TA_CTL_WRITE), - (mem_crb + TEST_AGT_CTRL)); - - for (j = 0; j < MAX_CTL_CHECK; j++) { - temp = readl((mem_crb + TEST_AGT_CTRL)); - if ((temp & TA_CTL_BUSY) == 0) - break; - } - - if (j >= MAX_CTL_CHECK) { - if (printk_ratelimit()) - dev_err(&adapter->pdev->dev, - "failed to write through agent\n"); - ret = -EIO; - } else - ret = 0; - - netxen_nic_pci_set_crbwindow_128M(adapter, NETXEN_WINDOW_ONE); - spin_unlock(&adapter->ahw.mem_lock); - return ret; -} - -static int -netxen_nic_pci_mem_read_128M(struct netxen_adapter *adapter, - u64 off, u64 *data) -{ - int j, ret; - u32 temp, off_lo, off_hi, addr_hi, data_hi, data_lo; - u64 val; - void __iomem *mem_crb; - - /* Only 64-bit aligned access */ - if (off & 7) - return -EIO; - - /* P2 has different SIU and MIU test agent base addr */ - if (ADDR_IN_RANGE(off, NETXEN_ADDR_QDR_NET, - NETXEN_ADDR_QDR_NET_MAX_P2)) { - mem_crb = pci_base_offset(adapter, - NETXEN_CRB_QDR_NET+SIU_TEST_AGT_BASE); - addr_hi = SIU_TEST_AGT_ADDR_HI; - data_lo = SIU_TEST_AGT_RDDATA_LO; - data_hi = SIU_TEST_AGT_RDDATA_HI; - off_lo = off & SIU_TEST_AGT_ADDR_MASK; - off_hi = SIU_TEST_AGT_UPPER_ADDR(off); - goto correct; - } - - if (ADDR_IN_RANGE(off, NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX)) { - mem_crb = pci_base_offset(adapter, - NETXEN_CRB_DDR_NET+MIU_TEST_AGT_BASE); - addr_hi = MIU_TEST_AGT_ADDR_HI; - data_lo = MIU_TEST_AGT_RDDATA_LO; - data_hi = MIU_TEST_AGT_RDDATA_HI; - off_lo = off & MIU_TEST_AGT_ADDR_MASK; - off_hi = 0; - goto correct; - } - - if (ADDR_IN_RANGE(off, NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX) || - ADDR_IN_RANGE(off, NETXEN_ADDR_OCM1, NETXEN_ADDR_OCM1_MAX)) { - if (adapter->ahw.pci_len0 != 0) { - return netxen_nic_pci_mem_access_direct(adapter, - off, data, 0); - } - } - - return -EIO; - -correct: - spin_lock(&adapter->ahw.mem_lock); - netxen_nic_pci_set_crbwindow_128M(adapter, 0); - - writel(off_lo, (mem_crb + MIU_TEST_AGT_ADDR_LO)); - writel(off_hi, (mem_crb + addr_hi)); - writel(TA_CTL_ENABLE, (mem_crb + TEST_AGT_CTRL)); - writel((TA_CTL_START|TA_CTL_ENABLE), (mem_crb + TEST_AGT_CTRL)); - - for (j = 0; j < MAX_CTL_CHECK; j++) { - temp = readl(mem_crb + TEST_AGT_CTRL); - if ((temp & TA_CTL_BUSY) == 0) - break; - } - - if (j >= MAX_CTL_CHECK) { - if (printk_ratelimit()) - dev_err(&adapter->pdev->dev, - "failed to read through agent\n"); - ret = -EIO; - } else { - - temp = readl(mem_crb + data_hi); - val = ((u64)temp << 32); - val |= readl(mem_crb + data_lo); - *data = val; - ret = 0; - } - - netxen_nic_pci_set_crbwindow_128M(adapter, NETXEN_WINDOW_ONE); - spin_unlock(&adapter->ahw.mem_lock); - - return ret; -} - -static int -netxen_nic_pci_mem_write_2M(struct netxen_adapter *adapter, - u64 off, u64 data) -{ - int j, ret; - u32 temp, off8; - void __iomem *mem_crb; - - /* Only 64-bit aligned access */ - if (off & 7) - return -EIO; - - /* P3 onward, test agent base for MIU and SIU is same */ - if (ADDR_IN_RANGE(off, NETXEN_ADDR_QDR_NET, - NETXEN_ADDR_QDR_NET_MAX_P3)) { - mem_crb = netxen_get_ioaddr(adapter, - NETXEN_CRB_QDR_NET+MIU_TEST_AGT_BASE); - goto correct; - } - - if (ADDR_IN_RANGE(off, NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX)) { - mem_crb = netxen_get_ioaddr(adapter, - NETXEN_CRB_DDR_NET+MIU_TEST_AGT_BASE); - goto correct; - } - - if (ADDR_IN_RANGE(off, NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX)) - return netxen_nic_pci_mem_access_direct(adapter, off, &data, 1); - - return -EIO; - -correct: - off8 = off & 0xfffffff8; - - spin_lock(&adapter->ahw.mem_lock); - - writel(off8, (mem_crb + MIU_TEST_AGT_ADDR_LO)); - writel(0, (mem_crb + MIU_TEST_AGT_ADDR_HI)); - - writel(data & 0xffffffff, - mem_crb + MIU_TEST_AGT_WRDATA_LO); - writel((data >> 32) & 0xffffffff, - mem_crb + MIU_TEST_AGT_WRDATA_HI); - - writel((TA_CTL_ENABLE | TA_CTL_WRITE), (mem_crb + TEST_AGT_CTRL)); - writel((TA_CTL_START | TA_CTL_ENABLE | TA_CTL_WRITE), - (mem_crb + TEST_AGT_CTRL)); - - for (j = 0; j < MAX_CTL_CHECK; j++) { - temp = readl(mem_crb + TEST_AGT_CTRL); - if ((temp & TA_CTL_BUSY) == 0) - break; - } - - if (j >= MAX_CTL_CHECK) { - if (printk_ratelimit()) - dev_err(&adapter->pdev->dev, - "failed to write through agent\n"); - ret = -EIO; - } else - ret = 0; - - spin_unlock(&adapter->ahw.mem_lock); - - return ret; -} - -static int -netxen_nic_pci_mem_read_2M(struct netxen_adapter *adapter, - u64 off, u64 *data) -{ - int j, ret; - u32 temp, off8; - u64 val; - void __iomem *mem_crb; - - /* Only 64-bit aligned access */ - if (off & 7) - return -EIO; - - /* P3 onward, test agent base for MIU and SIU is same */ - if (ADDR_IN_RANGE(off, NETXEN_ADDR_QDR_NET, - NETXEN_ADDR_QDR_NET_MAX_P3)) { - mem_crb = netxen_get_ioaddr(adapter, - NETXEN_CRB_QDR_NET+MIU_TEST_AGT_BASE); - goto correct; - } - - if (ADDR_IN_RANGE(off, NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX)) { - mem_crb = netxen_get_ioaddr(adapter, - NETXEN_CRB_DDR_NET+MIU_TEST_AGT_BASE); - goto correct; - } - - if (ADDR_IN_RANGE(off, NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX)) { - return netxen_nic_pci_mem_access_direct(adapter, - off, data, 0); - } - - return -EIO; - -correct: - off8 = off & 0xfffffff8; - - spin_lock(&adapter->ahw.mem_lock); - - writel(off8, (mem_crb + MIU_TEST_AGT_ADDR_LO)); - writel(0, (mem_crb + MIU_TEST_AGT_ADDR_HI)); - writel(TA_CTL_ENABLE, (mem_crb + TEST_AGT_CTRL)); - writel((TA_CTL_START | TA_CTL_ENABLE), (mem_crb + TEST_AGT_CTRL)); - - for (j = 0; j < MAX_CTL_CHECK; j++) { - temp = readl(mem_crb + TEST_AGT_CTRL); - if ((temp & TA_CTL_BUSY) == 0) - break; - } - - if (j >= MAX_CTL_CHECK) { - if (printk_ratelimit()) - dev_err(&adapter->pdev->dev, - "failed to read through agent\n"); - ret = -EIO; - } else { - val = (u64)(readl(mem_crb + MIU_TEST_AGT_RDDATA_HI)) << 32; - val |= readl(mem_crb + MIU_TEST_AGT_RDDATA_LO); - *data = val; - ret = 0; - } - - spin_unlock(&adapter->ahw.mem_lock); - - return ret; -} - -void -netxen_setup_hwops(struct netxen_adapter *adapter) -{ - adapter->init_port = netxen_niu_xg_init_port; - adapter->stop_port = netxen_niu_disable_xg_port; - - if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) { - adapter->crb_read = netxen_nic_hw_read_wx_128M, - adapter->crb_write = netxen_nic_hw_write_wx_128M, - adapter->pci_set_window = netxen_nic_pci_set_window_128M, - adapter->pci_mem_read = netxen_nic_pci_mem_read_128M, - adapter->pci_mem_write = netxen_nic_pci_mem_write_128M, - adapter->io_read = netxen_nic_io_read_128M, - adapter->io_write = netxen_nic_io_write_128M, - - adapter->macaddr_set = netxen_p2_nic_set_mac_addr; - adapter->set_multi = netxen_p2_nic_set_multi; - adapter->set_mtu = netxen_nic_set_mtu_xgb; - adapter->set_promisc = netxen_p2_nic_set_promisc; - - } else { - adapter->crb_read = netxen_nic_hw_read_wx_2M, - adapter->crb_write = netxen_nic_hw_write_wx_2M, - adapter->pci_set_window = netxen_nic_pci_set_window_2M, - adapter->pci_mem_read = netxen_nic_pci_mem_read_2M, - adapter->pci_mem_write = netxen_nic_pci_mem_write_2M, - adapter->io_read = netxen_nic_io_read_2M, - adapter->io_write = netxen_nic_io_write_2M, - - adapter->set_mtu = nx_fw_cmd_set_mtu; - adapter->set_promisc = netxen_p3_nic_set_promisc; - adapter->macaddr_set = netxen_p3_nic_set_mac_addr; - adapter->set_multi = netxen_p3_nic_set_multi; - - adapter->phy_read = nx_fw_cmd_query_phy; - adapter->phy_write = nx_fw_cmd_set_phy; - } -} - -int netxen_nic_get_board_info(struct netxen_adapter *adapter) -{ - int offset, board_type, magic; - struct pci_dev *pdev = adapter->pdev; - - offset = NX_FW_MAGIC_OFFSET; - if (netxen_rom_fast_read(adapter, offset, &magic)) - return -EIO; - - if (magic != NETXEN_BDINFO_MAGIC) { - dev_err(&pdev->dev, "invalid board config, magic=%08x\n", - magic); - return -EIO; - } - - offset = NX_BRDTYPE_OFFSET; - if (netxen_rom_fast_read(adapter, offset, &board_type)) - return -EIO; - - if (board_type == NETXEN_BRDTYPE_P3_4_GB_MM) { - u32 gpio = NXRD32(adapter, NETXEN_ROMUSB_GLB_PAD_GPIO_I); - if ((gpio & 0x8000) == 0) - board_type = NETXEN_BRDTYPE_P3_10G_TP; - } - - adapter->ahw.board_type = board_type; - - switch (board_type) { - case NETXEN_BRDTYPE_P2_SB35_4G: - adapter->ahw.port_type = NETXEN_NIC_GBE; - break; - case NETXEN_BRDTYPE_P2_SB31_10G: - case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ: - case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ: - case NETXEN_BRDTYPE_P2_SB31_10G_CX4: - case NETXEN_BRDTYPE_P3_HMEZ: - case NETXEN_BRDTYPE_P3_XG_LOM: - case NETXEN_BRDTYPE_P3_10G_CX4: - case NETXEN_BRDTYPE_P3_10G_CX4_LP: - case NETXEN_BRDTYPE_P3_IMEZ: - case NETXEN_BRDTYPE_P3_10G_SFP_PLUS: - case NETXEN_BRDTYPE_P3_10G_SFP_CT: - case NETXEN_BRDTYPE_P3_10G_SFP_QT: - case NETXEN_BRDTYPE_P3_10G_XFP: - case NETXEN_BRDTYPE_P3_10000_BASE_T: - adapter->ahw.port_type = NETXEN_NIC_XGBE; - break; - case NETXEN_BRDTYPE_P1_BD: - case NETXEN_BRDTYPE_P1_SB: - case NETXEN_BRDTYPE_P1_SMAX: - case NETXEN_BRDTYPE_P1_SOCK: - case NETXEN_BRDTYPE_P3_REF_QG: - case NETXEN_BRDTYPE_P3_4_GB: - case NETXEN_BRDTYPE_P3_4_GB_MM: - adapter->ahw.port_type = NETXEN_NIC_GBE; - break; - case NETXEN_BRDTYPE_P3_10G_TP: - adapter->ahw.port_type = (adapter->portnum < 2) ? - NETXEN_NIC_XGBE : NETXEN_NIC_GBE; - break; - default: - dev_err(&pdev->dev, "unknown board type %x\n", board_type); - adapter->ahw.port_type = NETXEN_NIC_XGBE; - break; - } - - return 0; -} - -/* NIU access sections */ -static int netxen_nic_set_mtu_xgb(struct netxen_adapter *adapter, int new_mtu) -{ - new_mtu += MTU_FUDGE_FACTOR; - if (adapter->physical_port == 0) - NXWR32(adapter, NETXEN_NIU_XGE_MAX_FRAME_SIZE, new_mtu); - else - NXWR32(adapter, NETXEN_NIU_XG1_MAX_FRAME_SIZE, new_mtu); - return 0; -} - -void netxen_nic_set_link_parameters(struct netxen_adapter *adapter) -{ - __u32 status; - __u32 autoneg; - __u32 port_mode; - - if (!netif_carrier_ok(adapter->netdev)) { - adapter->link_speed = 0; - adapter->link_duplex = -1; - adapter->link_autoneg = AUTONEG_ENABLE; - return; - } - - if (adapter->ahw.port_type == NETXEN_NIC_GBE) { - port_mode = NXRD32(adapter, NETXEN_PORT_MODE_ADDR); - if (port_mode == NETXEN_PORT_MODE_802_3_AP) { - adapter->link_speed = SPEED_1000; - adapter->link_duplex = DUPLEX_FULL; - adapter->link_autoneg = AUTONEG_DISABLE; - return; - } - - if (adapter->phy_read && - adapter->phy_read(adapter, - NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS, - &status) == 0) { - if (netxen_get_phy_link(status)) { - switch (netxen_get_phy_speed(status)) { - case 0: - adapter->link_speed = SPEED_10; - break; - case 1: - adapter->link_speed = SPEED_100; - break; - case 2: - adapter->link_speed = SPEED_1000; - break; - default: - adapter->link_speed = 0; - break; - } - switch (netxen_get_phy_duplex(status)) { - case 0: - adapter->link_duplex = DUPLEX_HALF; - break; - case 1: - adapter->link_duplex = DUPLEX_FULL; - break; - default: - adapter->link_duplex = -1; - break; - } - if (adapter->phy_read && - adapter->phy_read(adapter, - NETXEN_NIU_GB_MII_MGMT_ADDR_AUTONEG, - &autoneg) != 0) - adapter->link_autoneg = autoneg; - } else - goto link_down; - } else { - link_down: - adapter->link_speed = 0; - adapter->link_duplex = -1; - } - } -} - -int -netxen_nic_wol_supported(struct netxen_adapter *adapter) -{ - u32 wol_cfg; - - if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) - return 0; - - wol_cfg = NXRD32(adapter, NETXEN_WOL_CONFIG_NV); - if (wol_cfg & (1UL << adapter->portnum)) { - wol_cfg = NXRD32(adapter, NETXEN_WOL_CONFIG); - if (wol_cfg & (1 << adapter->portnum)) - return 1; - } - - return 0; -} diff --git a/drivers/net/netxen/netxen_nic_hw.h b/drivers/net/netxen/netxen_nic_hw.h deleted file mode 100644 index e2c5b6f2df03..000000000000 --- a/drivers/net/netxen/netxen_nic_hw.h +++ /dev/null @@ -1,287 +0,0 @@ -/* - * Copyright (C) 2003 - 2009 NetXen, Inc. - * Copyright (C) 2009 - QLogic Corporation. - * All rights reserved. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, - * MA 02111-1307, USA. - * - * The full GNU General Public License is included in this distribution - * in the file called "COPYING". - * - */ - -#ifndef __NETXEN_NIC_HW_H_ -#define __NETXEN_NIC_HW_H_ - -/* Hardware memory size of 128 meg */ -#define NETXEN_MEMADDR_MAX (128 * 1024 * 1024) - -struct netxen_adapter; - -#define NETXEN_PCI_MAPSIZE_BYTES (NETXEN_PCI_MAPSIZE << 20) - -void netxen_nic_set_link_parameters(struct netxen_adapter *adapter); - -/* Nibble or Byte mode for phy interface (GbE mode only) */ - -#define _netxen_crb_get_bit(var, bit) ((var >> bit) & 0x1) - -/* - * NIU GB MAC Config Register 0 (applies to GB0, GB1, GB2, GB3) - * - * Bit 0 : enable_tx => 1:enable frame xmit, 0:disable - * Bit 1 : tx_synced => R/O: xmit enable synched to xmit stream - * Bit 2 : enable_rx => 1:enable frame recv, 0:disable - * Bit 3 : rx_synced => R/O: recv enable synched to recv stream - * Bit 4 : tx_flowctl => 1:enable pause frame generation, 0:disable - * Bit 5 : rx_flowctl => 1:act on recv'd pause frames, 0:ignore - * Bit 8 : loopback => 1:loop MAC xmits to MAC recvs, 0:normal - * Bit 16: tx_reset_pb => 1:reset frame xmit protocol blk, 0:no-op - * Bit 17: rx_reset_pb => 1:reset frame recv protocol blk, 0:no-op - * Bit 18: tx_reset_mac => 1:reset data/ctl multiplexer blk, 0:no-op - * Bit 19: rx_reset_mac => 1:reset ctl frames & timers blk, 0:no-op - * Bit 31: soft_reset => 1:reset the MAC and the SERDES, 0:no-op - */ - -#define netxen_gb_tx_flowctl(config_word) \ - ((config_word) |= 1 << 4) -#define netxen_gb_rx_flowctl(config_word) \ - ((config_word) |= 1 << 5) -#define netxen_gb_tx_reset_pb(config_word) \ - ((config_word) |= 1 << 16) -#define netxen_gb_rx_reset_pb(config_word) \ - ((config_word) |= 1 << 17) -#define netxen_gb_tx_reset_mac(config_word) \ - ((config_word) |= 1 << 18) -#define netxen_gb_rx_reset_mac(config_word) \ - ((config_word) |= 1 << 19) - -#define netxen_gb_unset_tx_flowctl(config_word) \ - ((config_word) &= ~(1 << 4)) -#define netxen_gb_unset_rx_flowctl(config_word) \ - ((config_word) &= ~(1 << 5)) - -#define netxen_gb_get_tx_synced(config_word) \ - _netxen_crb_get_bit((config_word), 1) -#define netxen_gb_get_rx_synced(config_word) \ - _netxen_crb_get_bit((config_word), 3) -#define netxen_gb_get_tx_flowctl(config_word) \ - _netxen_crb_get_bit((config_word), 4) -#define netxen_gb_get_rx_flowctl(config_word) \ - _netxen_crb_get_bit((config_word), 5) -#define netxen_gb_get_soft_reset(config_word) \ - _netxen_crb_get_bit((config_word), 31) - -#define netxen_gb_get_stationaddress_low(config_word) ((config_word) >> 16) - -#define netxen_gb_set_mii_mgmt_clockselect(config_word, val) \ - ((config_word) |= ((val) & 0x07)) -#define netxen_gb_mii_mgmt_reset(config_word) \ - ((config_word) |= 1 << 31) -#define netxen_gb_mii_mgmt_unset(config_word) \ - ((config_word) &= ~(1 << 31)) - -/* - * NIU GB MII Mgmt Command Register (applies to GB0, GB1, GB2, GB3) - * Bit 0 : read_cycle => 1:perform single read cycle, 0:no-op - * Bit 1 : scan_cycle => 1:perform continuous read cycles, 0:no-op - */ - -#define netxen_gb_mii_mgmt_set_read_cycle(config_word) \ - ((config_word) |= 1 << 0) -#define netxen_gb_mii_mgmt_reg_addr(config_word, val) \ - ((config_word) |= ((val) & 0x1F)) -#define netxen_gb_mii_mgmt_phy_addr(config_word, val) \ - ((config_word) |= (((val) & 0x1F) << 8)) - -/* - * NIU GB MII Mgmt Indicators Register (applies to GB0, GB1, GB2, GB3) - * Read-only register. - * Bit 0 : busy => 1:performing an MII mgmt cycle, 0:idle - * Bit 1 : scanning => 1:scan operation in progress, 0:idle - * Bit 2 : notvalid => :mgmt result data not yet valid, 0:idle - */ -#define netxen_get_gb_mii_mgmt_busy(config_word) \ - _netxen_crb_get_bit(config_word, 0) -#define netxen_get_gb_mii_mgmt_scanning(config_word) \ - _netxen_crb_get_bit(config_word, 1) -#define netxen_get_gb_mii_mgmt_notvalid(config_word) \ - _netxen_crb_get_bit(config_word, 2) -/* - * NIU XG Pause Ctl Register - * - * Bit 0 : xg0_mask => 1:disable tx pause frames - * Bit 1 : xg0_request => 1:request single pause frame - * Bit 2 : xg0_on_off => 1:request is pause on, 0:off - * Bit 3 : xg1_mask => 1:disable tx pause frames - * Bit 4 : xg1_request => 1:request single pause frame - * Bit 5 : xg1_on_off => 1:request is pause on, 0:off - */ - -#define netxen_xg_set_xg0_mask(config_word) \ - ((config_word) |= 1 << 0) -#define netxen_xg_set_xg1_mask(config_word) \ - ((config_word) |= 1 << 3) - -#define netxen_xg_get_xg0_mask(config_word) \ - _netxen_crb_get_bit((config_word), 0) -#define netxen_xg_get_xg1_mask(config_word) \ - _netxen_crb_get_bit((config_word), 3) - -#define netxen_xg_unset_xg0_mask(config_word) \ - ((config_word) &= ~(1 << 0)) -#define netxen_xg_unset_xg1_mask(config_word) \ - ((config_word) &= ~(1 << 3)) - -/* - * NIU XG Pause Ctl Register - * - * Bit 0 : xg0_mask => 1:disable tx pause frames - * Bit 1 : xg0_request => 1:request single pause frame - * Bit 2 : xg0_on_off => 1:request is pause on, 0:off - * Bit 3 : xg1_mask => 1:disable tx pause frames - * Bit 4 : xg1_request => 1:request single pause frame - * Bit 5 : xg1_on_off => 1:request is pause on, 0:off - */ -#define netxen_gb_set_gb0_mask(config_word) \ - ((config_word) |= 1 << 0) -#define netxen_gb_set_gb1_mask(config_word) \ - ((config_word) |= 1 << 2) -#define netxen_gb_set_gb2_mask(config_word) \ - ((config_word) |= 1 << 4) -#define netxen_gb_set_gb3_mask(config_word) \ - ((config_word) |= 1 << 6) - -#define netxen_gb_get_gb0_mask(config_word) \ - _netxen_crb_get_bit((config_word), 0) -#define netxen_gb_get_gb1_mask(config_word) \ - _netxen_crb_get_bit((config_word), 2) -#define netxen_gb_get_gb2_mask(config_word) \ - _netxen_crb_get_bit((config_word), 4) -#define netxen_gb_get_gb3_mask(config_word) \ - _netxen_crb_get_bit((config_word), 6) - -#define netxen_gb_unset_gb0_mask(config_word) \ - ((config_word) &= ~(1 << 0)) -#define netxen_gb_unset_gb1_mask(config_word) \ - ((config_word) &= ~(1 << 2)) -#define netxen_gb_unset_gb2_mask(config_word) \ - ((config_word) &= ~(1 << 4)) -#define netxen_gb_unset_gb3_mask(config_word) \ - ((config_word) &= ~(1 << 6)) - - -/* - * PHY-Specific MII control/status registers. - */ -#define NETXEN_NIU_GB_MII_MGMT_ADDR_CONTROL 0 -#define NETXEN_NIU_GB_MII_MGMT_ADDR_STATUS 1 -#define NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_ID_0 2 -#define NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_ID_1 3 -#define NETXEN_NIU_GB_MII_MGMT_ADDR_AUTONEG 4 -#define NETXEN_NIU_GB_MII_MGMT_ADDR_LNKPART 5 -#define NETXEN_NIU_GB_MII_MGMT_ADDR_AUTONEG_MORE 6 -#define NETXEN_NIU_GB_MII_MGMT_ADDR_NEXTPAGE_XMIT 7 -#define NETXEN_NIU_GB_MII_MGMT_ADDR_LNKPART_NEXTPAGE 8 -#define NETXEN_NIU_GB_MII_MGMT_ADDR_1000BT_CONTROL 9 -#define NETXEN_NIU_GB_MII_MGMT_ADDR_1000BT_STATUS 10 -#define NETXEN_NIU_GB_MII_MGMT_ADDR_EXTENDED_STATUS 15 -#define NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_CONTROL 16 -#define NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS 17 -#define NETXEN_NIU_GB_MII_MGMT_ADDR_INT_ENABLE 18 -#define NETXEN_NIU_GB_MII_MGMT_ADDR_INT_STATUS 19 -#define NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_CONTROL_MORE 20 -#define NETXEN_NIU_GB_MII_MGMT_ADDR_RECV_ERROR_COUNT 21 -#define NETXEN_NIU_GB_MII_MGMT_ADDR_LED_CONTROL 24 -#define NETXEN_NIU_GB_MII_MGMT_ADDR_LED_OVERRIDE 25 -#define NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_CONTROL_MORE_YET 26 -#define NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS_MORE 27 - -/* - * PHY-Specific Status Register (reg 17). - * - * Bit 0 : jabber => 1:jabber detected, 0:not - * Bit 1 : polarity => 1:polarity reversed, 0:normal - * Bit 2 : recvpause => 1:receive pause enabled, 0:disabled - * Bit 3 : xmitpause => 1:transmit pause enabled, 0:disabled - * Bit 4 : energydetect => 1:sleep, 0:active - * Bit 5 : downshift => 1:downshift, 0:no downshift - * Bit 6 : crossover => 1:MDIX (crossover), 0:MDI (no crossover) - * Bits 7-9 : cablelen => not valid in 10Mb/s mode - * 0:<50m, 1:50-80m, 2:80-110m, 3:110-140m, 4:>140m - * Bit 10 : link => 1:link up, 0:link down - * Bit 11 : resolved => 1:speed and duplex resolved, 0:not yet - * Bit 12 : pagercvd => 1:page received, 0:page not received - * Bit 13 : duplex => 1:full duplex, 0:half duplex - * Bits 14-15 : speed => 0:10Mb/s, 1:100Mb/s, 2:1000Mb/s, 3:rsvd - */ - -#define netxen_get_phy_speed(config_word) (((config_word) >> 14) & 0x03) - -#define netxen_set_phy_speed(config_word, val) \ - ((config_word) |= ((val & 0x03) << 14)) -#define netxen_set_phy_duplex(config_word) \ - ((config_word) |= 1 << 13) -#define netxen_clear_phy_duplex(config_word) \ - ((config_word) &= ~(1 << 13)) - -#define netxen_get_phy_link(config_word) \ - _netxen_crb_get_bit(config_word, 10) -#define netxen_get_phy_duplex(config_word) \ - _netxen_crb_get_bit(config_word, 13) - -/* - * NIU Mode Register. - * Bit 0 : enable FibreChannel - * Bit 1 : enable 10/100/1000 Ethernet - * Bit 2 : enable 10Gb Ethernet - */ - -#define netxen_get_niu_enable_ge(config_word) \ - _netxen_crb_get_bit(config_word, 1) - -#define NETXEN_NIU_NON_PROMISC_MODE 0 -#define NETXEN_NIU_PROMISC_MODE 1 -#define NETXEN_NIU_ALLMULTI_MODE 2 - -/* - * NIU XG MAC Config Register - * - * Bit 0 : tx_enable => 1:enable frame xmit, 0:disable - * Bit 2 : rx_enable => 1:enable frame recv, 0:disable - * Bit 4 : soft_reset => 1:reset the MAC , 0:no-op - * Bit 27: xaui_framer_reset - * Bit 28: xaui_rx_reset - * Bit 29: xaui_tx_reset - * Bit 30: xg_ingress_afifo_reset - * Bit 31: xg_egress_afifo_reset - */ - -#define netxen_xg_soft_reset(config_word) \ - ((config_word) |= 1 << 4) - -typedef struct { - unsigned valid; - unsigned start_128M; - unsigned end_128M; - unsigned start_2M; -} crb_128M_2M_sub_block_map_t; - -typedef struct { - crb_128M_2M_sub_block_map_t sub_block[16]; -} crb_128M_2M_block_map_t; - -#endif /* __NETXEN_NIC_HW_H_ */ diff --git a/drivers/net/netxen/netxen_nic_init.c b/drivers/net/netxen/netxen_nic_init.c deleted file mode 100644 index d6c6357de6aa..000000000000 --- a/drivers/net/netxen/netxen_nic_init.c +++ /dev/null @@ -1,1949 +0,0 @@ -/* - * Copyright (C) 2003 - 2009 NetXen, Inc. - * Copyright (C) 2009 - QLogic Corporation. - * All rights reserved. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, - * MA 02111-1307, USA. - * - * The full GNU General Public License is included in this distribution - * in the file called "COPYING". - * - */ - -#include <linux/netdevice.h> -#include <linux/delay.h> -#include <linux/slab.h> -#include <linux/if_vlan.h> -#include "netxen_nic.h" -#include "netxen_nic_hw.h" - -struct crb_addr_pair { - u32 addr; - u32 data; -}; - -#define NETXEN_MAX_CRB_XFORM 60 -static unsigned int crb_addr_xform[NETXEN_MAX_CRB_XFORM]; -#define NETXEN_ADDR_ERROR (0xffffffff) - -#define crb_addr_transform(name) \ - crb_addr_xform[NETXEN_HW_PX_MAP_CRB_##name] = \ - NETXEN_HW_CRB_HUB_AGT_ADR_##name << 20 - -#define NETXEN_NIC_XDMA_RESET 0x8000ff - -static void -netxen_post_rx_buffers_nodb(struct netxen_adapter *adapter, - struct nx_host_rds_ring *rds_ring); -static int netxen_p3_has_mn(struct netxen_adapter *adapter); - -static void crb_addr_transform_setup(void) -{ - crb_addr_transform(XDMA); - crb_addr_transform(TIMR); - crb_addr_transform(SRE); - crb_addr_transform(SQN3); - crb_addr_transform(SQN2); - crb_addr_transform(SQN1); - crb_addr_transform(SQN0); - crb_addr_transform(SQS3); - crb_addr_transform(SQS2); - crb_addr_transform(SQS1); - crb_addr_transform(SQS0); - crb_addr_transform(RPMX7); - crb_addr_transform(RPMX6); - crb_addr_transform(RPMX5); - crb_addr_transform(RPMX4); - crb_addr_transform(RPMX3); - crb_addr_transform(RPMX2); - crb_addr_transform(RPMX1); - crb_addr_transform(RPMX0); - crb_addr_transform(ROMUSB); - crb_addr_transform(SN); - crb_addr_transform(QMN); - crb_addr_transform(QMS); - crb_addr_transform(PGNI); - crb_addr_transform(PGND); - crb_addr_transform(PGN3); - crb_addr_transform(PGN2); - crb_addr_transform(PGN1); - crb_addr_transform(PGN0); - crb_addr_transform(PGSI); - crb_addr_transform(PGSD); - crb_addr_transform(PGS3); - crb_addr_transform(PGS2); - crb_addr_transform(PGS1); - crb_addr_transform(PGS0); - crb_addr_transform(PS); - crb_addr_transform(PH); - crb_addr_transform(NIU); - crb_addr_transform(I2Q); - crb_addr_transform(EG); - crb_addr_transform(MN); - crb_addr_transform(MS); - crb_addr_transform(CAS2); - crb_addr_transform(CAS1); - crb_addr_transform(CAS0); - crb_addr_transform(CAM); - crb_addr_transform(C2C1); - crb_addr_transform(C2C0); - crb_addr_transform(SMB); - crb_addr_transform(OCM0); - crb_addr_transform(I2C0); -} - -void netxen_release_rx_buffers(struct netxen_adapter *adapter) -{ - struct netxen_recv_context *recv_ctx; - struct nx_host_rds_ring *rds_ring; - struct netxen_rx_buffer *rx_buf; - int i, ring; - - recv_ctx = &adapter->recv_ctx; - for (ring = 0; ring < adapter->max_rds_rings; ring++) { - rds_ring = &recv_ctx->rds_rings[ring]; - for (i = 0; i < rds_ring->num_desc; ++i) { - rx_buf = &(rds_ring->rx_buf_arr[i]); - if (rx_buf->state == NETXEN_BUFFER_FREE) - continue; - pci_unmap_single(adapter->pdev, - rx_buf->dma, - rds_ring->dma_size, - PCI_DMA_FROMDEVICE); - if (rx_buf->skb != NULL) - dev_kfree_skb_any(rx_buf->skb); - } - } -} - -void netxen_release_tx_buffers(struct netxen_adapter *adapter) -{ - struct netxen_cmd_buffer *cmd_buf; - struct netxen_skb_frag *buffrag; - int i, j; - struct nx_host_tx_ring *tx_ring = adapter->tx_ring; - - cmd_buf = tx_ring->cmd_buf_arr; - for (i = 0; i < tx_ring->num_desc; i++) { - buffrag = cmd_buf->frag_array; - if (buffrag->dma) { - pci_unmap_single(adapter->pdev, buffrag->dma, - buffrag->length, PCI_DMA_TODEVICE); - buffrag->dma = 0ULL; - } - for (j = 0; j < cmd_buf->frag_count; j++) { - buffrag++; - if (buffrag->dma) { - pci_unmap_page(adapter->pdev, buffrag->dma, - buffrag->length, - PCI_DMA_TODEVICE); - buffrag->dma = 0ULL; - } - } - if (cmd_buf->skb) { - dev_kfree_skb_any(cmd_buf->skb); - cmd_buf->skb = NULL; - } - cmd_buf++; - } -} - -void netxen_free_sw_resources(struct netxen_adapter *adapter) -{ - struct netxen_recv_context *recv_ctx; - struct nx_host_rds_ring *rds_ring; - struct nx_host_tx_ring *tx_ring; - int ring; - - recv_ctx = &adapter->recv_ctx; - - if (recv_ctx->rds_rings == NULL) - goto skip_rds; - - for (ring = 0; ring < adapter->max_rds_rings; ring++) { - rds_ring = &recv_ctx->rds_rings[ring]; - vfree(rds_ring->rx_buf_arr); - rds_ring->rx_buf_arr = NULL; - } - kfree(recv_ctx->rds_rings); - -skip_rds: - if (adapter->tx_ring == NULL) - return; - - tx_ring = adapter->tx_ring; - vfree(tx_ring->cmd_buf_arr); - kfree(tx_ring); - adapter->tx_ring = NULL; -} - -int netxen_alloc_sw_resources(struct netxen_adapter *adapter) -{ - struct netxen_recv_context *recv_ctx; - struct nx_host_rds_ring *rds_ring; - struct nx_host_sds_ring *sds_ring; - struct nx_host_tx_ring *tx_ring; - struct netxen_rx_buffer *rx_buf; - int ring, i, size; - - struct netxen_cmd_buffer *cmd_buf_arr; - struct net_device *netdev = adapter->netdev; - struct pci_dev *pdev = adapter->pdev; - - size = sizeof(struct nx_host_tx_ring); - tx_ring = kzalloc(size, GFP_KERNEL); - if (tx_ring == NULL) { - dev_err(&pdev->dev, "%s: failed to allocate tx ring struct\n", - netdev->name); - return -ENOMEM; - } - adapter->tx_ring = tx_ring; - - tx_ring->num_desc = adapter->num_txd; - tx_ring->txq = netdev_get_tx_queue(netdev, 0); - - cmd_buf_arr = vzalloc(TX_BUFF_RINGSIZE(tx_ring)); - if (cmd_buf_arr == NULL) { - dev_err(&pdev->dev, "%s: failed to allocate cmd buffer ring\n", - netdev->name); - goto err_out; - } - tx_ring->cmd_buf_arr = cmd_buf_arr; - - recv_ctx = &adapter->recv_ctx; - - size = adapter->max_rds_rings * sizeof (struct nx_host_rds_ring); - rds_ring = kzalloc(size, GFP_KERNEL); - if (rds_ring == NULL) { - dev_err(&pdev->dev, "%s: failed to allocate rds ring struct\n", - netdev->name); - goto err_out; - } - recv_ctx->rds_rings = rds_ring; - - for (ring = 0; ring < adapter->max_rds_rings; ring++) { - rds_ring = &recv_ctx->rds_rings[ring]; - switch (ring) { - case RCV_RING_NORMAL: - rds_ring->num_desc = adapter->num_rxd; - if (adapter->ahw.cut_through) { - rds_ring->dma_size = - NX_CT_DEFAULT_RX_BUF_LEN; - rds_ring->skb_size = - NX_CT_DEFAULT_RX_BUF_LEN; - } else { - if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) - rds_ring->dma_size = - NX_P3_RX_BUF_MAX_LEN; - else - rds_ring->dma_size = - NX_P2_RX_BUF_MAX_LEN; - rds_ring->skb_size = - rds_ring->dma_size + NET_IP_ALIGN; - } - break; - - case RCV_RING_JUMBO: - rds_ring->num_desc = adapter->num_jumbo_rxd; - if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) - rds_ring->dma_size = - NX_P3_RX_JUMBO_BUF_MAX_LEN; - else - rds_ring->dma_size = - NX_P2_RX_JUMBO_BUF_MAX_LEN; - - if (adapter->capabilities & NX_CAP0_HW_LRO) - rds_ring->dma_size += NX_LRO_BUFFER_EXTRA; - - rds_ring->skb_size = - rds_ring->dma_size + NET_IP_ALIGN; - break; - - case RCV_RING_LRO: - rds_ring->num_desc = adapter->num_lro_rxd; - rds_ring->dma_size = NX_RX_LRO_BUFFER_LENGTH; - rds_ring->skb_size = rds_ring->dma_size + NET_IP_ALIGN; - break; - - } - rds_ring->rx_buf_arr = vzalloc(RCV_BUFF_RINGSIZE(rds_ring)); - if (rds_ring->rx_buf_arr == NULL) { - printk(KERN_ERR "%s: Failed to allocate " - "rx buffer ring %d\n", - netdev->name, ring); - /* free whatever was already allocated */ - goto err_out; - } - INIT_LIST_HEAD(&rds_ring->free_list); - /* - * Now go through all of them, set reference handles - * and put them in the queues. - */ - rx_buf = rds_ring->rx_buf_arr; - for (i = 0; i < rds_ring->num_desc; i++) { - list_add_tail(&rx_buf->list, - &rds_ring->free_list); - rx_buf->ref_handle = i; - rx_buf->state = NETXEN_BUFFER_FREE; - rx_buf++; - } - spin_lock_init(&rds_ring->lock); - } - - for (ring = 0; ring < adapter->max_sds_rings; ring++) { - sds_ring = &recv_ctx->sds_rings[ring]; - sds_ring->irq = adapter->msix_entries[ring].vector; - sds_ring->adapter = adapter; - sds_ring->num_desc = adapter->num_rxd; - - for (i = 0; i < NUM_RCV_DESC_RINGS; i++) - INIT_LIST_HEAD(&sds_ring->free_list[i]); - } - - return 0; - -err_out: - netxen_free_sw_resources(adapter); - return -ENOMEM; -} - -/* - * netxen_decode_crb_addr(0 - utility to translate from internal Phantom CRB - * address to external PCI CRB address. - */ -static u32 netxen_decode_crb_addr(u32 addr) -{ - int i; - u32 base_addr, offset, pci_base; - - crb_addr_transform_setup(); - - pci_base = NETXEN_ADDR_ERROR; - base_addr = addr & 0xfff00000; - offset = addr & 0x000fffff; - - for (i = 0; i < NETXEN_MAX_CRB_XFORM; i++) { - if (crb_addr_xform[i] == base_addr) { - pci_base = i << 20; - break; - } - } - if (pci_base == NETXEN_ADDR_ERROR) - return pci_base; - else - return pci_base + offset; -} - -#define NETXEN_MAX_ROM_WAIT_USEC 100 - -static int netxen_wait_rom_done(struct netxen_adapter *adapter) -{ - long timeout = 0; - long done = 0; - - cond_resched(); - - while (done == 0) { - done = NXRD32(adapter, NETXEN_ROMUSB_GLB_STATUS); - done &= 2; - if (++timeout >= NETXEN_MAX_ROM_WAIT_USEC) { - dev_err(&adapter->pdev->dev, - "Timeout reached waiting for rom done"); - return -EIO; - } - udelay(1); - } - return 0; -} - -static int do_rom_fast_read(struct netxen_adapter *adapter, - int addr, int *valp) -{ - NXWR32(adapter, NETXEN_ROMUSB_ROM_ADDRESS, addr); - NXWR32(adapter, NETXEN_ROMUSB_ROM_DUMMY_BYTE_CNT, 0); - NXWR32(adapter, NETXEN_ROMUSB_ROM_ABYTE_CNT, 3); - NXWR32(adapter, NETXEN_ROMUSB_ROM_INSTR_OPCODE, 0xb); - if (netxen_wait_rom_done(adapter)) { - printk("Error waiting for rom done\n"); - return -EIO; - } - /* reset abyte_cnt and dummy_byte_cnt */ - NXWR32(adapter, NETXEN_ROMUSB_ROM_ABYTE_CNT, 0); - udelay(10); - NXWR32(adapter, NETXEN_ROMUSB_ROM_DUMMY_BYTE_CNT, 0); - - *valp = NXRD32(adapter, NETXEN_ROMUSB_ROM_RDATA); - return 0; -} - -static int do_rom_fast_read_words(struct netxen_adapter *adapter, int addr, - u8 *bytes, size_t size) -{ - int addridx; - int ret = 0; - - for (addridx = addr; addridx < (addr + size); addridx += 4) { - int v; - ret = do_rom_fast_read(adapter, addridx, &v); - if (ret != 0) - break; - *(__le32 *)bytes = cpu_to_le32(v); - bytes += 4; - } - - return ret; -} - -int -netxen_rom_fast_read_words(struct netxen_adapter *adapter, int addr, - u8 *bytes, size_t size) -{ - int ret; - - ret = netxen_rom_lock(adapter); - if (ret < 0) - return ret; - - ret = do_rom_fast_read_words(adapter, addr, bytes, size); - - netxen_rom_unlock(adapter); - return ret; -} - -int netxen_rom_fast_read(struct netxen_adapter *adapter, int addr, int *valp) -{ - int ret; - - if (netxen_rom_lock(adapter) != 0) - return -EIO; - - ret = do_rom_fast_read(adapter, addr, valp); - netxen_rom_unlock(adapter); - return ret; -} - -#define NETXEN_BOARDTYPE 0x4008 -#define NETXEN_BOARDNUM 0x400c -#define NETXEN_CHIPNUM 0x4010 - -int netxen_pinit_from_rom(struct netxen_adapter *adapter) -{ - int addr, val; - int i, n, init_delay = 0; - struct crb_addr_pair *buf; - unsigned offset; - u32 off; - - /* resetall */ - netxen_rom_lock(adapter); - NXWR32(adapter, NETXEN_ROMUSB_GLB_SW_RESET, 0xffffffff); - netxen_rom_unlock(adapter); - - if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) { - if (netxen_rom_fast_read(adapter, 0, &n) != 0 || - (n != 0xcafecafe) || - netxen_rom_fast_read(adapter, 4, &n) != 0) { - printk(KERN_ERR "%s: ERROR Reading crb_init area: " - "n: %08x\n", netxen_nic_driver_name, n); - return -EIO; - } - offset = n & 0xffffU; - n = (n >> 16) & 0xffffU; - } else { - if (netxen_rom_fast_read(adapter, 0, &n) != 0 || - !(n & 0x80000000)) { - printk(KERN_ERR "%s: ERROR Reading crb_init area: " - "n: %08x\n", netxen_nic_driver_name, n); - return -EIO; - } - offset = 1; - n &= ~0x80000000; - } - - if (n >= 1024) { - printk(KERN_ERR "%s:n=0x%x Error! NetXen card flash not" - " initialized.\n", __func__, n); - return -EIO; - } - - buf = kcalloc(n, sizeof(struct crb_addr_pair), GFP_KERNEL); - if (buf == NULL) { - printk("%s: netxen_pinit_from_rom: Unable to calloc memory.\n", - netxen_nic_driver_name); - return -ENOMEM; - } - - for (i = 0; i < n; i++) { - if (netxen_rom_fast_read(adapter, 8*i + 4*offset, &val) != 0 || - netxen_rom_fast_read(adapter, 8*i + 4*offset + 4, &addr) != 0) { - kfree(buf); - return -EIO; - } - - buf[i].addr = addr; - buf[i].data = val; - - } - - for (i = 0; i < n; i++) { - - off = netxen_decode_crb_addr(buf[i].addr); - if (off == NETXEN_ADDR_ERROR) { - printk(KERN_ERR"CRB init value out of range %x\n", - buf[i].addr); - continue; - } - off += NETXEN_PCI_CRBSPACE; - - if (off & 1) - continue; - - /* skipping cold reboot MAGIC */ - if (off == NETXEN_CAM_RAM(0x1fc)) - continue; - - if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) { - if (off == (NETXEN_CRB_I2C0 + 0x1c)) - continue; - /* do not reset PCI */ - if (off == (ROMUSB_GLB + 0xbc)) - continue; - if (off == (ROMUSB_GLB + 0xa8)) - continue; - if (off == (ROMUSB_GLB + 0xc8)) /* core clock */ - continue; - if (off == (ROMUSB_GLB + 0x24)) /* MN clock */ - continue; - if (off == (ROMUSB_GLB + 0x1c)) /* MS clock */ - continue; - if ((off & 0x0ff00000) == NETXEN_CRB_DDR_NET) - continue; - if (off == (NETXEN_CRB_PEG_NET_1 + 0x18) && - !NX_IS_REVISION_P3P(adapter->ahw.revision_id)) - buf[i].data = 0x1020; - /* skip the function enable register */ - if (off == NETXEN_PCIE_REG(PCIE_SETUP_FUNCTION)) - continue; - if (off == NETXEN_PCIE_REG(PCIE_SETUP_FUNCTION2)) - continue; - if ((off & 0x0ff00000) == NETXEN_CRB_SMB) - continue; - } - - init_delay = 1; - /* After writing this register, HW needs time for CRB */ - /* to quiet down (else crb_window returns 0xffffffff) */ - if (off == NETXEN_ROMUSB_GLB_SW_RESET) { - init_delay = 1000; - if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) { - /* hold xdma in reset also */ - buf[i].data = NETXEN_NIC_XDMA_RESET; - buf[i].data = 0x8000ff; - } - } - - NXWR32(adapter, off, buf[i].data); - - msleep(init_delay); - } - kfree(buf); - - /* disable_peg_cache_all */ - - /* unreset_net_cache */ - if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) { - val = NXRD32(adapter, NETXEN_ROMUSB_GLB_SW_RESET); - NXWR32(adapter, NETXEN_ROMUSB_GLB_SW_RESET, (val & 0xffffff0f)); - } - - /* p2dn replyCount */ - NXWR32(adapter, NETXEN_CRB_PEG_NET_D + 0xec, 0x1e); - /* disable_peg_cache 0 */ - NXWR32(adapter, NETXEN_CRB_PEG_NET_D + 0x4c, 8); - /* disable_peg_cache 1 */ - NXWR32(adapter, NETXEN_CRB_PEG_NET_I + 0x4c, 8); - - /* peg_clr_all */ - - /* peg_clr 0 */ - NXWR32(adapter, NETXEN_CRB_PEG_NET_0 + 0x8, 0); - NXWR32(adapter, NETXEN_CRB_PEG_NET_0 + 0xc, 0); - /* peg_clr 1 */ - NXWR32(adapter, NETXEN_CRB_PEG_NET_1 + 0x8, 0); - NXWR32(adapter, NETXEN_CRB_PEG_NET_1 + 0xc, 0); - /* peg_clr 2 */ - NXWR32(adapter, NETXEN_CRB_PEG_NET_2 + 0x8, 0); - NXWR32(adapter, NETXEN_CRB_PEG_NET_2 + 0xc, 0); - /* peg_clr 3 */ - NXWR32(adapter, NETXEN_CRB_PEG_NET_3 + 0x8, 0); - NXWR32(adapter, NETXEN_CRB_PEG_NET_3 + 0xc, 0); - return 0; -} - -static struct uni_table_desc *nx_get_table_desc(const u8 *unirom, int section) -{ - uint32_t i; - struct uni_table_desc *directory = (struct uni_table_desc *) &unirom[0]; - __le32 entries = cpu_to_le32(directory->num_entries); - - for (i = 0; i < entries; i++) { - - __le32 offs = cpu_to_le32(directory->findex) + - (i * cpu_to_le32(directory->entry_size)); - __le32 tab_type = cpu_to_le32(*((u32 *)&unirom[offs] + 8)); - - if (tab_type == section) - return (struct uni_table_desc *) &unirom[offs]; - } - - return NULL; -} - -#define QLCNIC_FILEHEADER_SIZE (14 * 4) - -static int -netxen_nic_validate_header(struct netxen_adapter *adapter) - { - const u8 *unirom = adapter->fw->data; - struct uni_table_desc *directory = (struct uni_table_desc *) &unirom[0]; - u32 fw_file_size = adapter->fw->size; - u32 tab_size; - __le32 entries; - __le32 entry_size; - - if (fw_file_size < QLCNIC_FILEHEADER_SIZE) - return -EINVAL; - - entries = cpu_to_le32(directory->num_entries); - entry_size = cpu_to_le32(directory->entry_size); - tab_size = cpu_to_le32(directory->findex) + (entries * entry_size); - - if (fw_file_size < tab_size) - return -EINVAL; - - return 0; -} - -static int -netxen_nic_validate_bootld(struct netxen_adapter *adapter) -{ - struct uni_table_desc *tab_desc; - struct uni_data_desc *descr; - const u8 *unirom = adapter->fw->data; - __le32 idx = cpu_to_le32(*((int *)&unirom[adapter->file_prd_off] + - NX_UNI_BOOTLD_IDX_OFF)); - u32 offs; - u32 tab_size; - u32 data_size; - - tab_desc = nx_get_table_desc(unirom, NX_UNI_DIR_SECT_BOOTLD); - - if (!tab_desc) - return -EINVAL; - - tab_size = cpu_to_le32(tab_desc->findex) + - (cpu_to_le32(tab_desc->entry_size) * (idx + 1)); - - if (adapter->fw->size < tab_size) - return -EINVAL; - - offs = cpu_to_le32(tab_desc->findex) + - (cpu_to_le32(tab_desc->entry_size) * (idx)); - descr = (struct uni_data_desc *)&unirom[offs]; - - data_size = cpu_to_le32(descr->findex) + cpu_to_le32(descr->size); - - if (adapter->fw->size < data_size) - return -EINVAL; - - return 0; -} - -static int -netxen_nic_validate_fw(struct netxen_adapter *adapter) -{ - struct uni_table_desc *tab_desc; - struct uni_data_desc *descr; - const u8 *unirom = adapter->fw->data; - __le32 idx = cpu_to_le32(*((int *)&unirom[adapter->file_prd_off] + - NX_UNI_FIRMWARE_IDX_OFF)); - u32 offs; - u32 tab_size; - u32 data_size; - - tab_desc = nx_get_table_desc(unirom, NX_UNI_DIR_SECT_FW); - - if (!tab_desc) - return -EINVAL; - - tab_size = cpu_to_le32(tab_desc->findex) + - (cpu_to_le32(tab_desc->entry_size) * (idx + 1)); - - if (adapter->fw->size < tab_size) - return -EINVAL; - - offs = cpu_to_le32(tab_desc->findex) + - (cpu_to_le32(tab_desc->entry_size) * (idx)); - descr = (struct uni_data_desc *)&unirom[offs]; - data_size = cpu_to_le32(descr->findex) + cpu_to_le32(descr->size); - - if (adapter->fw->size < data_size) - return -EINVAL; - - return 0; -} - - -static int -netxen_nic_validate_product_offs(struct netxen_adapter *adapter) -{ - struct uni_table_desc *ptab_descr; - const u8 *unirom = adapter->fw->data; - int mn_present = (NX_IS_REVISION_P2(adapter->ahw.revision_id)) ? - 1 : netxen_p3_has_mn(adapter); - __le32 entries; - __le32 entry_size; - u32 tab_size; - u32 i; - - ptab_descr = nx_get_table_desc(unirom, NX_UNI_DIR_SECT_PRODUCT_TBL); - if (ptab_descr == NULL) - return -EINVAL; - - entries = cpu_to_le32(ptab_descr->num_entries); - entry_size = cpu_to_le32(ptab_descr->entry_size); - tab_size = cpu_to_le32(ptab_descr->findex) + (entries * entry_size); - - if (adapter->fw->size < tab_size) - return -EINVAL; - -nomn: - for (i = 0; i < entries; i++) { - - __le32 flags, file_chiprev, offs; - u8 chiprev = adapter->ahw.revision_id; - uint32_t flagbit; - - offs = cpu_to_le32(ptab_descr->findex) + - (i * cpu_to_le32(ptab_descr->entry_size)); - flags = cpu_to_le32(*((int *)&unirom[offs] + NX_UNI_FLAGS_OFF)); - file_chiprev = cpu_to_le32(*((int *)&unirom[offs] + - NX_UNI_CHIP_REV_OFF)); - - flagbit = mn_present ? 1 : 2; - - if ((chiprev == file_chiprev) && - ((1ULL << flagbit) & flags)) { - adapter->file_prd_off = offs; - return 0; - } - } - - if (mn_present && NX_IS_REVISION_P3(adapter->ahw.revision_id)) { - mn_present = 0; - goto nomn; - } - - return -EINVAL; -} - -static int -netxen_nic_validate_unified_romimage(struct netxen_adapter *adapter) -{ - if (netxen_nic_validate_header(adapter)) { - dev_err(&adapter->pdev->dev, - "unified image: header validation failed\n"); - return -EINVAL; - } - - if (netxen_nic_validate_product_offs(adapter)) { - dev_err(&adapter->pdev->dev, - "unified image: product validation failed\n"); - return -EINVAL; - } - - if (netxen_nic_validate_bootld(adapter)) { - dev_err(&adapter->pdev->dev, - "unified image: bootld validation failed\n"); - return -EINVAL; - } - - if (netxen_nic_validate_fw(adapter)) { - dev_err(&adapter->pdev->dev, - "unified image: firmware validation failed\n"); - return -EINVAL; - } - - return 0; -} - -static struct uni_data_desc *nx_get_data_desc(struct netxen_adapter *adapter, - u32 section, u32 idx_offset) -{ - const u8 *unirom = adapter->fw->data; - int idx = cpu_to_le32(*((int *)&unirom[adapter->file_prd_off] + - idx_offset)); - struct uni_table_desc *tab_desc; - __le32 offs; - - tab_desc = nx_get_table_desc(unirom, section); - - if (tab_desc == NULL) - return NULL; - - offs = cpu_to_le32(tab_desc->findex) + - (cpu_to_le32(tab_desc->entry_size) * idx); - - return (struct uni_data_desc *)&unirom[offs]; -} - -static u8 * -nx_get_bootld_offs(struct netxen_adapter *adapter) -{ - u32 offs = NETXEN_BOOTLD_START; - - if (adapter->fw_type == NX_UNIFIED_ROMIMAGE) - offs = cpu_to_le32((nx_get_data_desc(adapter, - NX_UNI_DIR_SECT_BOOTLD, - NX_UNI_BOOTLD_IDX_OFF))->findex); - - return (u8 *)&adapter->fw->data[offs]; -} - -static u8 * -nx_get_fw_offs(struct netxen_adapter *adapter) -{ - u32 offs = NETXEN_IMAGE_START; - - if (adapter->fw_type == NX_UNIFIED_ROMIMAGE) - offs = cpu_to_le32((nx_get_data_desc(adapter, - NX_UNI_DIR_SECT_FW, - NX_UNI_FIRMWARE_IDX_OFF))->findex); - - return (u8 *)&adapter->fw->data[offs]; -} - -static __le32 -nx_get_fw_size(struct netxen_adapter *adapter) -{ - if (adapter->fw_type == NX_UNIFIED_ROMIMAGE) - return cpu_to_le32((nx_get_data_desc(adapter, - NX_UNI_DIR_SECT_FW, - NX_UNI_FIRMWARE_IDX_OFF))->size); - else - return cpu_to_le32( - *(u32 *)&adapter->fw->data[NX_FW_SIZE_OFFSET]); -} - -static __le32 -nx_get_fw_version(struct netxen_adapter *adapter) -{ - struct uni_data_desc *fw_data_desc; - const struct firmware *fw = adapter->fw; - __le32 major, minor, sub; - const u8 *ver_str; - int i, ret = 0; - - if (adapter->fw_type == NX_UNIFIED_ROMIMAGE) { - - fw_data_desc = nx_get_data_desc(adapter, - NX_UNI_DIR_SECT_FW, NX_UNI_FIRMWARE_IDX_OFF); - ver_str = fw->data + cpu_to_le32(fw_data_desc->findex) + - cpu_to_le32(fw_data_desc->size) - 17; - - for (i = 0; i < 12; i++) { - if (!strncmp(&ver_str[i], "REV=", 4)) { - ret = sscanf(&ver_str[i+4], "%u.%u.%u ", - &major, &minor, &sub); - break; - } - } - - if (ret != 3) - return 0; - - return major + (minor << 8) + (sub << 16); - - } else - return cpu_to_le32(*(u32 *)&fw->data[NX_FW_VERSION_OFFSET]); -} - -static __le32 -nx_get_bios_version(struct netxen_adapter *adapter) -{ - const struct firmware *fw = adapter->fw; - __le32 bios_ver, prd_off = adapter->file_prd_off; - - if (adapter->fw_type == NX_UNIFIED_ROMIMAGE) { - bios_ver = cpu_to_le32(*((u32 *) (&fw->data[prd_off]) - + NX_UNI_BIOS_VERSION_OFF)); - return (bios_ver << 16) + ((bios_ver >> 8) & 0xff00) + - (bios_ver >> 24); - } else - return cpu_to_le32(*(u32 *)&fw->data[NX_BIOS_VERSION_OFFSET]); - -} - -int -netxen_need_fw_reset(struct netxen_adapter *adapter) -{ - u32 count, old_count; - u32 val, version, major, minor, build; - int i, timeout; - u8 fw_type; - - /* NX2031 firmware doesn't support heartbit */ - if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) - return 1; - - if (adapter->need_fw_reset) - return 1; - - /* last attempt had failed */ - if (NXRD32(adapter, CRB_CMDPEG_STATE) == PHAN_INITIALIZE_FAILED) - return 1; - - old_count = NXRD32(adapter, NETXEN_PEG_ALIVE_COUNTER); - - for (i = 0; i < 10; i++) { - - timeout = msleep_interruptible(200); - if (timeout) { - NXWR32(adapter, CRB_CMDPEG_STATE, - PHAN_INITIALIZE_FAILED); - return -EINTR; - } - - count = NXRD32(adapter, NETXEN_PEG_ALIVE_COUNTER); - if (count != old_count) - break; - } - - /* firmware is dead */ - if (count == old_count) - return 1; - - /* check if we have got newer or different file firmware */ - if (adapter->fw) { - - val = nx_get_fw_version(adapter); - - version = NETXEN_DECODE_VERSION(val); - - major = NXRD32(adapter, NETXEN_FW_VERSION_MAJOR); - minor = NXRD32(adapter, NETXEN_FW_VERSION_MINOR); - build = NXRD32(adapter, NETXEN_FW_VERSION_SUB); - - if (version > NETXEN_VERSION_CODE(major, minor, build)) - return 1; - - if (version == NETXEN_VERSION_CODE(major, minor, build) && - adapter->fw_type != NX_UNIFIED_ROMIMAGE) { - - val = NXRD32(adapter, NETXEN_MIU_MN_CONTROL); - fw_type = (val & 0x4) ? - NX_P3_CT_ROMIMAGE : NX_P3_MN_ROMIMAGE; - - if (adapter->fw_type != fw_type) - return 1; - } - } - - return 0; -} - -#define NETXEN_MIN_P3_FW_SUPP NETXEN_VERSION_CODE(4, 0, 505) - -int -netxen_check_flash_fw_compatibility(struct netxen_adapter *adapter) -{ - u32 flash_fw_ver, min_fw_ver; - - if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) - return 0; - - if (netxen_rom_fast_read(adapter, - NX_FW_VERSION_OFFSET, (int *)&flash_fw_ver)) { - dev_err(&adapter->pdev->dev, "Unable to read flash fw" - "version\n"); - return -EIO; - } - - flash_fw_ver = NETXEN_DECODE_VERSION(flash_fw_ver); - min_fw_ver = NETXEN_MIN_P3_FW_SUPP; - if (flash_fw_ver >= min_fw_ver) - return 0; - - dev_info(&adapter->pdev->dev, "Flash fw[%d.%d.%d] is < min fw supported" - "[4.0.505]. Please update firmware on flash\n", - _major(flash_fw_ver), _minor(flash_fw_ver), - _build(flash_fw_ver)); - return -EINVAL; -} - -static char *fw_name[] = { - NX_P2_MN_ROMIMAGE_NAME, - NX_P3_CT_ROMIMAGE_NAME, - NX_P3_MN_ROMIMAGE_NAME, - NX_UNIFIED_ROMIMAGE_NAME, - NX_FLASH_ROMIMAGE_NAME, -}; - -int -netxen_load_firmware(struct netxen_adapter *adapter) -{ - u64 *ptr64; - u32 i, flashaddr, size; - const struct firmware *fw = adapter->fw; - struct pci_dev *pdev = adapter->pdev; - - dev_info(&pdev->dev, "loading firmware from %s\n", - fw_name[adapter->fw_type]); - - if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) - NXWR32(adapter, NETXEN_ROMUSB_GLB_CAS_RST, 1); - - if (fw) { - __le64 data; - - size = (NETXEN_IMAGE_START - NETXEN_BOOTLD_START) / 8; - - ptr64 = (u64 *)nx_get_bootld_offs(adapter); - flashaddr = NETXEN_BOOTLD_START; - - for (i = 0; i < size; i++) { - data = cpu_to_le64(ptr64[i]); - - if (adapter->pci_mem_write(adapter, flashaddr, data)) - return -EIO; - - flashaddr += 8; - } - - size = (__force u32)nx_get_fw_size(adapter) / 8; - - ptr64 = (u64 *)nx_get_fw_offs(adapter); - flashaddr = NETXEN_IMAGE_START; - - for (i = 0; i < size; i++) { - data = cpu_to_le64(ptr64[i]); - - if (adapter->pci_mem_write(adapter, - flashaddr, data)) - return -EIO; - - flashaddr += 8; - } - - size = (__force u32)nx_get_fw_size(adapter) % 8; - if (size) { - data = cpu_to_le64(ptr64[i]); - - if (adapter->pci_mem_write(adapter, - flashaddr, data)) - return -EIO; - } - - } else { - u64 data; - u32 hi, lo; - - size = (NETXEN_IMAGE_START - NETXEN_BOOTLD_START) / 8; - flashaddr = NETXEN_BOOTLD_START; - - for (i = 0; i < size; i++) { - if (netxen_rom_fast_read(adapter, - flashaddr, (int *)&lo) != 0) - return -EIO; - if (netxen_rom_fast_read(adapter, - flashaddr + 4, (int *)&hi) != 0) - return -EIO; - - /* hi, lo are already in host endian byteorder */ - data = (((u64)hi << 32) | lo); - - if (adapter->pci_mem_write(adapter, - flashaddr, data)) - return -EIO; - - flashaddr += 8; - } - } - msleep(1); - - if (NX_IS_REVISION_P3P(adapter->ahw.revision_id)) { - NXWR32(adapter, NETXEN_CRB_PEG_NET_0 + 0x18, 0x1020); - NXWR32(adapter, NETXEN_ROMUSB_GLB_SW_RESET, 0x80001e); - } else if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) - NXWR32(adapter, NETXEN_ROMUSB_GLB_SW_RESET, 0x80001d); - else { - NXWR32(adapter, NETXEN_ROMUSB_GLB_CHIP_CLK_CTRL, 0x3fff); - NXWR32(adapter, NETXEN_ROMUSB_GLB_CAS_RST, 0); - } - - return 0; -} - -static int -netxen_validate_firmware(struct netxen_adapter *adapter) -{ - __le32 val; - __le32 flash_fw_ver; - u32 file_fw_ver, min_ver, bios; - struct pci_dev *pdev = adapter->pdev; - const struct firmware *fw = adapter->fw; - u8 fw_type = adapter->fw_type; - u32 crbinit_fix_fw; - - if (fw_type == NX_UNIFIED_ROMIMAGE) { - if (netxen_nic_validate_unified_romimage(adapter)) - return -EINVAL; - } else { - val = cpu_to_le32(*(u32 *)&fw->data[NX_FW_MAGIC_OFFSET]); - if ((__force u32)val != NETXEN_BDINFO_MAGIC) - return -EINVAL; - - if (fw->size < NX_FW_MIN_SIZE) - return -EINVAL; - } - - val = nx_get_fw_version(adapter); - - if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) - min_ver = NETXEN_MIN_P3_FW_SUPP; - else - min_ver = NETXEN_VERSION_CODE(3, 4, 216); - - file_fw_ver = NETXEN_DECODE_VERSION(val); - - if ((_major(file_fw_ver) > _NETXEN_NIC_LINUX_MAJOR) || - (file_fw_ver < min_ver)) { - dev_err(&pdev->dev, - "%s: firmware version %d.%d.%d unsupported\n", - fw_name[fw_type], _major(file_fw_ver), _minor(file_fw_ver), - _build(file_fw_ver)); - return -EINVAL; - } - - val = nx_get_bios_version(adapter); - netxen_rom_fast_read(adapter, NX_BIOS_VERSION_OFFSET, (int *)&bios); - if ((__force u32)val != bios) { - dev_err(&pdev->dev, "%s: firmware bios is incompatible\n", - fw_name[fw_type]); - return -EINVAL; - } - - if (netxen_rom_fast_read(adapter, - NX_FW_VERSION_OFFSET, (int *)&flash_fw_ver)) { - dev_err(&pdev->dev, "Unable to read flash fw version\n"); - return -EIO; - } - flash_fw_ver = NETXEN_DECODE_VERSION(flash_fw_ver); - - /* New fw from file is not allowed, if fw on flash is < 4.0.554 */ - crbinit_fix_fw = NETXEN_VERSION_CODE(4, 0, 554); - if (file_fw_ver >= crbinit_fix_fw && flash_fw_ver < crbinit_fix_fw && - NX_IS_REVISION_P3(adapter->ahw.revision_id)) { - dev_err(&pdev->dev, "Incompatibility detected between driver " - "and firmware version on flash. This configuration " - "is not recommended. Please update the firmware on " - "flash immediately\n"); - return -EINVAL; - } - - /* check if flashed firmware is newer only for no-mn and P2 case*/ - if (!netxen_p3_has_mn(adapter) || - NX_IS_REVISION_P2(adapter->ahw.revision_id)) { - if (flash_fw_ver > file_fw_ver) { - dev_info(&pdev->dev, "%s: firmware is older than flash\n", - fw_name[fw_type]); - return -EINVAL; - } - } - - NXWR32(adapter, NETXEN_CAM_RAM(0x1fc), NETXEN_BDINFO_MAGIC); - return 0; -} - -static void -nx_get_next_fwtype(struct netxen_adapter *adapter) -{ - u8 fw_type; - - switch (adapter->fw_type) { - case NX_UNKNOWN_ROMIMAGE: - fw_type = NX_UNIFIED_ROMIMAGE; - break; - - case NX_UNIFIED_ROMIMAGE: - if (NX_IS_REVISION_P3P(adapter->ahw.revision_id)) - fw_type = NX_FLASH_ROMIMAGE; - else if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) - fw_type = NX_P2_MN_ROMIMAGE; - else if (netxen_p3_has_mn(adapter)) - fw_type = NX_P3_MN_ROMIMAGE; - else - fw_type = NX_P3_CT_ROMIMAGE; - break; - - case NX_P3_MN_ROMIMAGE: - fw_type = NX_P3_CT_ROMIMAGE; - break; - - case NX_P2_MN_ROMIMAGE: - case NX_P3_CT_ROMIMAGE: - default: - fw_type = NX_FLASH_ROMIMAGE; - break; - } - - adapter->fw_type = fw_type; -} - -static int -netxen_p3_has_mn(struct netxen_adapter *adapter) -{ - u32 capability, flashed_ver; - capability = 0; - - /* NX2031 always had MN */ - if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) - return 1; - - netxen_rom_fast_read(adapter, - NX_FW_VERSION_OFFSET, (int *)&flashed_ver); - flashed_ver = NETXEN_DECODE_VERSION(flashed_ver); - - if (flashed_ver >= NETXEN_VERSION_CODE(4, 0, 220)) { - - capability = NXRD32(adapter, NX_PEG_TUNE_CAPABILITY); - if (capability & NX_PEG_TUNE_MN_PRESENT) - return 1; - } - return 0; -} - -void netxen_request_firmware(struct netxen_adapter *adapter) -{ - struct pci_dev *pdev = adapter->pdev; - int rc = 0; - - adapter->fw_type = NX_UNKNOWN_ROMIMAGE; - -next: - nx_get_next_fwtype(adapter); - - if (adapter->fw_type == NX_FLASH_ROMIMAGE) { - adapter->fw = NULL; - } else { - rc = request_firmware(&adapter->fw, - fw_name[adapter->fw_type], &pdev->dev); - if (rc != 0) - goto next; - - rc = netxen_validate_firmware(adapter); - if (rc != 0) { - release_firmware(adapter->fw); - msleep(1); - goto next; - } - } -} - - -void -netxen_release_firmware(struct netxen_adapter *adapter) -{ - if (adapter->fw) - release_firmware(adapter->fw); - adapter->fw = NULL; -} - -int netxen_init_dummy_dma(struct netxen_adapter *adapter) -{ - u64 addr; - u32 hi, lo; - - if (!NX_IS_REVISION_P2(adapter->ahw.revision_id)) - return 0; - - adapter->dummy_dma.addr = pci_alloc_consistent(adapter->pdev, - NETXEN_HOST_DUMMY_DMA_SIZE, - &adapter->dummy_dma.phys_addr); - if (adapter->dummy_dma.addr == NULL) { - dev_err(&adapter->pdev->dev, - "ERROR: Could not allocate dummy DMA memory\n"); - return -ENOMEM; - } - - addr = (uint64_t) adapter->dummy_dma.phys_addr; - hi = (addr >> 32) & 0xffffffff; - lo = addr & 0xffffffff; - - NXWR32(adapter, CRB_HOST_DUMMY_BUF_ADDR_HI, hi); - NXWR32(adapter, CRB_HOST_DUMMY_BUF_ADDR_LO, lo); - - return 0; -} - -/* - * NetXen DMA watchdog control: - * - * Bit 0 : enabled => R/O: 1 watchdog active, 0 inactive - * Bit 1 : disable_request => 1 req disable dma watchdog - * Bit 2 : enable_request => 1 req enable dma watchdog - * Bit 3-31 : unused - */ -void netxen_free_dummy_dma(struct netxen_adapter *adapter) -{ - int i = 100; - u32 ctrl; - - if (!NX_IS_REVISION_P2(adapter->ahw.revision_id)) - return; - - if (!adapter->dummy_dma.addr) - return; - - ctrl = NXRD32(adapter, NETXEN_DMA_WATCHDOG_CTRL); - if ((ctrl & 0x1) != 0) { - NXWR32(adapter, NETXEN_DMA_WATCHDOG_CTRL, (ctrl | 0x2)); - - while ((ctrl & 0x1) != 0) { - - msleep(50); - - ctrl = NXRD32(adapter, NETXEN_DMA_WATCHDOG_CTRL); - - if (--i == 0) - break; - } - } - - if (i) { - pci_free_consistent(adapter->pdev, - NETXEN_HOST_DUMMY_DMA_SIZE, - adapter->dummy_dma.addr, - adapter->dummy_dma.phys_addr); - adapter->dummy_dma.addr = NULL; - } else - dev_err(&adapter->pdev->dev, "dma_watchdog_shutdown failed\n"); -} - -int netxen_phantom_init(struct netxen_adapter *adapter, int pegtune_val) -{ - u32 val = 0; - int retries = 60; - - if (pegtune_val) - return 0; - - do { - val = NXRD32(adapter, CRB_CMDPEG_STATE); - - switch (val) { - case PHAN_INITIALIZE_COMPLETE: - case PHAN_INITIALIZE_ACK: - return 0; - case PHAN_INITIALIZE_FAILED: - goto out_err; - default: - break; - } - - msleep(500); - - } while (--retries); - - NXWR32(adapter, CRB_CMDPEG_STATE, PHAN_INITIALIZE_FAILED); - -out_err: - dev_warn(&adapter->pdev->dev, "firmware init failed\n"); - return -EIO; -} - -static int -netxen_receive_peg_ready(struct netxen_adapter *adapter) -{ - u32 val = 0; - int retries = 2000; - - do { - val = NXRD32(adapter, CRB_RCVPEG_STATE); - - if (val == PHAN_PEG_RCV_INITIALIZED) - return 0; - - msleep(10); - - } while (--retries); - - if (!retries) { - printk(KERN_ERR "Receive Peg initialization not " - "complete, state: 0x%x.\n", val); - return -EIO; - } - - return 0; -} - -int netxen_init_firmware(struct netxen_adapter *adapter) -{ - int err; - - err = netxen_receive_peg_ready(adapter); - if (err) - return err; - - NXWR32(adapter, CRB_NIC_CAPABILITIES_HOST, INTR_SCHEME_PERPORT); - NXWR32(adapter, CRB_MPORT_MODE, MPORT_MULTI_FUNCTION_MODE); - NXWR32(adapter, CRB_CMDPEG_STATE, PHAN_INITIALIZE_ACK); - - if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) - NXWR32(adapter, CRB_NIC_MSI_MODE_HOST, MSI_MODE_MULTIFUNC); - - return err; -} - -static void -netxen_handle_linkevent(struct netxen_adapter *adapter, nx_fw_msg_t *msg) -{ - u32 cable_OUI; - u16 cable_len; - u16 link_speed; - u8 link_status, module, duplex, autoneg; - struct net_device *netdev = adapter->netdev; - - adapter->has_link_events = 1; - - cable_OUI = msg->body[1] & 0xffffffff; - cable_len = (msg->body[1] >> 32) & 0xffff; - link_speed = (msg->body[1] >> 48) & 0xffff; - - link_status = msg->body[2] & 0xff; - duplex = (msg->body[2] >> 16) & 0xff; - autoneg = (msg->body[2] >> 24) & 0xff; - - module = (msg->body[2] >> 8) & 0xff; - if (module == LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLE) { - printk(KERN_INFO "%s: unsupported cable: OUI 0x%x, length %d\n", - netdev->name, cable_OUI, cable_len); - } else if (module == LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLELEN) { - printk(KERN_INFO "%s: unsupported cable length %d\n", - netdev->name, cable_len); - } - - netxen_advert_link_change(adapter, link_status); - - /* update link parameters */ - if (duplex == LINKEVENT_FULL_DUPLEX) - adapter->link_duplex = DUPLEX_FULL; - else - adapter->link_duplex = DUPLEX_HALF; - adapter->module_type = module; - adapter->link_autoneg = autoneg; - adapter->link_speed = link_speed; -} - -static void -netxen_handle_fw_message(int desc_cnt, int index, - struct nx_host_sds_ring *sds_ring) -{ - nx_fw_msg_t msg; - struct status_desc *desc; - int i = 0, opcode; - - while (desc_cnt > 0 && i < 8) { - desc = &sds_ring->desc_head[index]; - msg.words[i++] = le64_to_cpu(desc->status_desc_data[0]); - msg.words[i++] = le64_to_cpu(desc->status_desc_data[1]); - - index = get_next_index(index, sds_ring->num_desc); - desc_cnt--; - } - - opcode = netxen_get_nic_msg_opcode(msg.body[0]); - switch (opcode) { - case NX_NIC_C2H_OPCODE_GET_LINKEVENT_RESPONSE: - netxen_handle_linkevent(sds_ring->adapter, &msg); - break; - default: - break; - } -} - -static int -netxen_alloc_rx_skb(struct netxen_adapter *adapter, - struct nx_host_rds_ring *rds_ring, - struct netxen_rx_buffer *buffer) -{ - struct sk_buff *skb; - dma_addr_t dma; - struct pci_dev *pdev = adapter->pdev; - - buffer->skb = dev_alloc_skb(rds_ring->skb_size); - if (!buffer->skb) - return 1; - - skb = buffer->skb; - - if (!adapter->ahw.cut_through) - skb_reserve(skb, 2); - - dma = pci_map_single(pdev, skb->data, - rds_ring->dma_size, PCI_DMA_FROMDEVICE); - - if (pci_dma_mapping_error(pdev, dma)) { - dev_kfree_skb_any(skb); - buffer->skb = NULL; - return 1; - } - - buffer->skb = skb; - buffer->dma = dma; - buffer->state = NETXEN_BUFFER_BUSY; - - return 0; -} - -static struct sk_buff *netxen_process_rxbuf(struct netxen_adapter *adapter, - struct nx_host_rds_ring *rds_ring, u16 index, u16 cksum) -{ - struct netxen_rx_buffer *buffer; - struct sk_buff *skb; - - buffer = &rds_ring->rx_buf_arr[index]; - - pci_unmap_single(adapter->pdev, buffer->dma, rds_ring->dma_size, - PCI_DMA_FROMDEVICE); - - skb = buffer->skb; - if (!skb) - goto no_skb; - - if (likely((adapter->netdev->features & NETIF_F_RXCSUM) - && cksum == STATUS_CKSUM_OK)) { - adapter->stats.csummed++; - skb->ip_summed = CHECKSUM_UNNECESSARY; - } else - skb->ip_summed = CHECKSUM_NONE; - - skb->dev = adapter->netdev; - - buffer->skb = NULL; -no_skb: - buffer->state = NETXEN_BUFFER_FREE; - return skb; -} - -static struct netxen_rx_buffer * -netxen_process_rcv(struct netxen_adapter *adapter, - struct nx_host_sds_ring *sds_ring, - int ring, u64 sts_data0) -{ - struct net_device *netdev = adapter->netdev; - struct netxen_recv_context *recv_ctx = &adapter->recv_ctx; - struct netxen_rx_buffer *buffer; - struct sk_buff *skb; - struct nx_host_rds_ring *rds_ring; - int index, length, cksum, pkt_offset; - - if (unlikely(ring >= adapter->max_rds_rings)) - return NULL; - - rds_ring = &recv_ctx->rds_rings[ring]; - - index = netxen_get_sts_refhandle(sts_data0); - if (unlikely(index >= rds_ring->num_desc)) - return NULL; - - buffer = &rds_ring->rx_buf_arr[index]; - - length = netxen_get_sts_totallength(sts_data0); - cksum = netxen_get_sts_status(sts_data0); - pkt_offset = netxen_get_sts_pkt_offset(sts_data0); - - skb = netxen_process_rxbuf(adapter, rds_ring, index, cksum); - if (!skb) - return buffer; - - if (length > rds_ring->skb_size) - skb_put(skb, rds_ring->skb_size); - else - skb_put(skb, length); - - - if (pkt_offset) - skb_pull(skb, pkt_offset); - - skb->protocol = eth_type_trans(skb, netdev); - - napi_gro_receive(&sds_ring->napi, skb); - - adapter->stats.rx_pkts++; - adapter->stats.rxbytes += length; - - return buffer; -} - -#define TCP_HDR_SIZE 20 -#define TCP_TS_OPTION_SIZE 12 -#define TCP_TS_HDR_SIZE (TCP_HDR_SIZE + TCP_TS_OPTION_SIZE) - -static struct netxen_rx_buffer * -netxen_process_lro(struct netxen_adapter *adapter, - struct nx_host_sds_ring *sds_ring, - int ring, u64 sts_data0, u64 sts_data1) -{ - struct net_device *netdev = adapter->netdev; - struct netxen_recv_context *recv_ctx = &adapter->recv_ctx; - struct netxen_rx_buffer *buffer; - struct sk_buff *skb; - struct nx_host_rds_ring *rds_ring; - struct iphdr *iph; - struct tcphdr *th; - bool push, timestamp; - int l2_hdr_offset, l4_hdr_offset; - int index; - u16 lro_length, length, data_offset; - u32 seq_number; - u8 vhdr_len; - - if (unlikely(ring > adapter->max_rds_rings)) - return NULL; - - rds_ring = &recv_ctx->rds_rings[ring]; - - index = netxen_get_lro_sts_refhandle(sts_data0); - if (unlikely(index > rds_ring->num_desc)) - return NULL; - - buffer = &rds_ring->rx_buf_arr[index]; - - timestamp = netxen_get_lro_sts_timestamp(sts_data0); - lro_length = netxen_get_lro_sts_length(sts_data0); - l2_hdr_offset = netxen_get_lro_sts_l2_hdr_offset(sts_data0); - l4_hdr_offset = netxen_get_lro_sts_l4_hdr_offset(sts_data0); - push = netxen_get_lro_sts_push_flag(sts_data0); - seq_number = netxen_get_lro_sts_seq_number(sts_data1); - - skb = netxen_process_rxbuf(adapter, rds_ring, index, STATUS_CKSUM_OK); - if (!skb) - return buffer; - - if (timestamp) - data_offset = l4_hdr_offset + TCP_TS_HDR_SIZE; - else - data_offset = l4_hdr_offset + TCP_HDR_SIZE; - - skb_put(skb, lro_length + data_offset); - - skb_pull(skb, l2_hdr_offset); - skb->protocol = eth_type_trans(skb, netdev); - - if (skb->protocol == htons(ETH_P_8021Q)) - vhdr_len = VLAN_HLEN; - iph = (struct iphdr *)(skb->data + vhdr_len); - th = (struct tcphdr *)((skb->data + vhdr_len) + (iph->ihl << 2)); - - length = (iph->ihl << 2) + (th->doff << 2) + lro_length; - iph->tot_len = htons(length); - iph->check = 0; - iph->check = ip_fast_csum((unsigned char *)iph, iph->ihl); - th->psh = push; - th->seq = htonl(seq_number); - - length = skb->len; - - netif_receive_skb(skb); - - adapter->stats.lro_pkts++; - adapter->stats.rxbytes += length; - - return buffer; -} - -#define netxen_merge_rx_buffers(list, head) \ - do { list_splice_tail_init(list, head); } while (0); - -int -netxen_process_rcv_ring(struct nx_host_sds_ring *sds_ring, int max) -{ - struct netxen_adapter *adapter = sds_ring->adapter; - - struct list_head *cur; - - struct status_desc *desc; - struct netxen_rx_buffer *rxbuf; - - u32 consumer = sds_ring->consumer; - - int count = 0; - u64 sts_data0, sts_data1; - int opcode, ring = 0, desc_cnt; - - while (count < max) { - desc = &sds_ring->desc_head[consumer]; - sts_data0 = le64_to_cpu(desc->status_desc_data[0]); - - if (!(sts_data0 & STATUS_OWNER_HOST)) - break; - - desc_cnt = netxen_get_sts_desc_cnt(sts_data0); - - opcode = netxen_get_sts_opcode(sts_data0); - - switch (opcode) { - case NETXEN_NIC_RXPKT_DESC: - case NETXEN_OLD_RXPKT_DESC: - case NETXEN_NIC_SYN_OFFLOAD: - ring = netxen_get_sts_type(sts_data0); - rxbuf = netxen_process_rcv(adapter, sds_ring, - ring, sts_data0); - break; - case NETXEN_NIC_LRO_DESC: - ring = netxen_get_lro_sts_type(sts_data0); - sts_data1 = le64_to_cpu(desc->status_desc_data[1]); - rxbuf = netxen_process_lro(adapter, sds_ring, - ring, sts_data0, sts_data1); - break; - case NETXEN_NIC_RESPONSE_DESC: - netxen_handle_fw_message(desc_cnt, consumer, sds_ring); - default: - goto skip; - } - - WARN_ON(desc_cnt > 1); - - if (rxbuf) - list_add_tail(&rxbuf->list, &sds_ring->free_list[ring]); - -skip: - for (; desc_cnt > 0; desc_cnt--) { - desc = &sds_ring->desc_head[consumer]; - desc->status_desc_data[0] = - cpu_to_le64(STATUS_OWNER_PHANTOM); - consumer = get_next_index(consumer, sds_ring->num_desc); - } - count++; - } - - for (ring = 0; ring < adapter->max_rds_rings; ring++) { - struct nx_host_rds_ring *rds_ring = - &adapter->recv_ctx.rds_rings[ring]; - - if (!list_empty(&sds_ring->free_list[ring])) { - list_for_each(cur, &sds_ring->free_list[ring]) { - rxbuf = list_entry(cur, - struct netxen_rx_buffer, list); - netxen_alloc_rx_skb(adapter, rds_ring, rxbuf); - } - spin_lock(&rds_ring->lock); - netxen_merge_rx_buffers(&sds_ring->free_list[ring], - &rds_ring->free_list); - spin_unlock(&rds_ring->lock); - } - - netxen_post_rx_buffers_nodb(adapter, rds_ring); - } - - if (count) { - sds_ring->consumer = consumer; - NXWRIO(adapter, sds_ring->crb_sts_consumer, consumer); - } - - return count; -} - -/* Process Command status ring */ -int netxen_process_cmd_ring(struct netxen_adapter *adapter) -{ - u32 sw_consumer, hw_consumer; - int count = 0, i; - struct netxen_cmd_buffer *buffer; - struct pci_dev *pdev = adapter->pdev; - struct net_device *netdev = adapter->netdev; - struct netxen_skb_frag *frag; - int done = 0; - struct nx_host_tx_ring *tx_ring = adapter->tx_ring; - - if (!spin_trylock(&adapter->tx_clean_lock)) - return 1; - - sw_consumer = tx_ring->sw_consumer; - hw_consumer = le32_to_cpu(*(tx_ring->hw_consumer)); - - while (sw_consumer != hw_consumer) { - buffer = &tx_ring->cmd_buf_arr[sw_consumer]; - if (buffer->skb) { - frag = &buffer->frag_array[0]; - pci_unmap_single(pdev, frag->dma, frag->length, - PCI_DMA_TODEVICE); - frag->dma = 0ULL; - for (i = 1; i < buffer->frag_count; i++) { - frag++; /* Get the next frag */ - pci_unmap_page(pdev, frag->dma, frag->length, - PCI_DMA_TODEVICE); - frag->dma = 0ULL; - } - - adapter->stats.xmitfinished++; - dev_kfree_skb_any(buffer->skb); - buffer->skb = NULL; - } - - sw_consumer = get_next_index(sw_consumer, tx_ring->num_desc); - if (++count >= MAX_STATUS_HANDLE) - break; - } - - if (count && netif_running(netdev)) { - tx_ring->sw_consumer = sw_consumer; - - smp_mb(); - - if (netif_queue_stopped(netdev) && netif_carrier_ok(netdev)) - if (netxen_tx_avail(tx_ring) > TX_STOP_THRESH) - netif_wake_queue(netdev); - adapter->tx_timeo_cnt = 0; - } - /* - * If everything is freed up to consumer then check if the ring is full - * If the ring is full then check if more needs to be freed and - * schedule the call back again. - * - * This happens when there are 2 CPUs. One could be freeing and the - * other filling it. If the ring is full when we get out of here and - * the card has already interrupted the host then the host can miss the - * interrupt. - * - * There is still a possible race condition and the host could miss an - * interrupt. The card has to take care of this. - */ - hw_consumer = le32_to_cpu(*(tx_ring->hw_consumer)); - done = (sw_consumer == hw_consumer); - spin_unlock(&adapter->tx_clean_lock); - - return done; -} - -void -netxen_post_rx_buffers(struct netxen_adapter *adapter, u32 ringid, - struct nx_host_rds_ring *rds_ring) -{ - struct rcv_desc *pdesc; - struct netxen_rx_buffer *buffer; - int producer, count = 0; - netxen_ctx_msg msg = 0; - struct list_head *head; - - producer = rds_ring->producer; - - head = &rds_ring->free_list; - while (!list_empty(head)) { - - buffer = list_entry(head->next, struct netxen_rx_buffer, list); - - if (!buffer->skb) { - if (netxen_alloc_rx_skb(adapter, rds_ring, buffer)) - break; - } - - count++; - list_del(&buffer->list); - - /* make a rcv descriptor */ - pdesc = &rds_ring->desc_head[producer]; - pdesc->addr_buffer = cpu_to_le64(buffer->dma); - pdesc->reference_handle = cpu_to_le16(buffer->ref_handle); - pdesc->buffer_length = cpu_to_le32(rds_ring->dma_size); - - producer = get_next_index(producer, rds_ring->num_desc); - } - - if (count) { - rds_ring->producer = producer; - NXWRIO(adapter, rds_ring->crb_rcv_producer, - (producer-1) & (rds_ring->num_desc-1)); - - if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) { - /* - * Write a doorbell msg to tell phanmon of change in - * receive ring producer - * Only for firmware version < 4.0.0 - */ - netxen_set_msg_peg_id(msg, NETXEN_RCV_PEG_DB_ID); - netxen_set_msg_privid(msg); - netxen_set_msg_count(msg, - ((producer - 1) & - (rds_ring->num_desc - 1))); - netxen_set_msg_ctxid(msg, adapter->portnum); - netxen_set_msg_opcode(msg, NETXEN_RCV_PRODUCER(ringid)); - NXWRIO(adapter, DB_NORMALIZE(adapter, - NETXEN_RCV_PRODUCER_OFFSET), msg); - } - } -} - -static void -netxen_post_rx_buffers_nodb(struct netxen_adapter *adapter, - struct nx_host_rds_ring *rds_ring) -{ - struct rcv_desc *pdesc; - struct netxen_rx_buffer *buffer; - int producer, count = 0; - struct list_head *head; - - if (!spin_trylock(&rds_ring->lock)) - return; - - producer = rds_ring->producer; - - head = &rds_ring->free_list; - while (!list_empty(head)) { - - buffer = list_entry(head->next, struct netxen_rx_buffer, list); - - if (!buffer->skb) { - if (netxen_alloc_rx_skb(adapter, rds_ring, buffer)) - break; - } - - count++; - list_del(&buffer->list); - - /* make a rcv descriptor */ - pdesc = &rds_ring->desc_head[producer]; - pdesc->reference_handle = cpu_to_le16(buffer->ref_handle); - pdesc->buffer_length = cpu_to_le32(rds_ring->dma_size); - pdesc->addr_buffer = cpu_to_le64(buffer->dma); - - producer = get_next_index(producer, rds_ring->num_desc); - } - - if (count) { - rds_ring->producer = producer; - NXWRIO(adapter, rds_ring->crb_rcv_producer, - (producer - 1) & (rds_ring->num_desc - 1)); - } - spin_unlock(&rds_ring->lock); -} - -void netxen_nic_clear_stats(struct netxen_adapter *adapter) -{ - memset(&adapter->stats, 0, sizeof(adapter->stats)); -} - diff --git a/drivers/net/netxen/netxen_nic_main.c b/drivers/net/netxen/netxen_nic_main.c deleted file mode 100644 index 8c7fc32d781f..000000000000 --- a/drivers/net/netxen/netxen_nic_main.c +++ /dev/null @@ -1,3100 +0,0 @@ -/* - * Copyright (C) 2003 - 2009 NetXen, Inc. - * Copyright (C) 2009 - QLogic Corporation. - * All rights reserved. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, - * MA 02111-1307, USA. - * - * The full GNU General Public License is included in this distribution - * in the file called "COPYING". - * - */ - -#include <linux/slab.h> -#include <linux/vmalloc.h> -#include <linux/interrupt.h> -#include "netxen_nic_hw.h" - -#include "netxen_nic.h" - -#include <linux/dma-mapping.h> -#include <linux/if_vlan.h> -#include <net/ip.h> -#include <linux/ipv6.h> -#include <linux/inetdevice.h> -#include <linux/sysfs.h> -#include <linux/aer.h> - -MODULE_DESCRIPTION("QLogic/NetXen (1/10) GbE Intelligent Ethernet Driver"); -MODULE_LICENSE("GPL"); -MODULE_VERSION(NETXEN_NIC_LINUX_VERSIONID); -MODULE_FIRMWARE(NX_UNIFIED_ROMIMAGE_NAME); - -char netxen_nic_driver_name[] = "netxen_nic"; -static char netxen_nic_driver_string[] = "QLogic/NetXen Network Driver v" - NETXEN_NIC_LINUX_VERSIONID; - -static int port_mode = NETXEN_PORT_MODE_AUTO_NEG; - -/* Default to restricted 1G auto-neg mode */ -static int wol_port_mode = 5; - -static int use_msi = 1; - -static int use_msi_x = 1; - -static int auto_fw_reset = AUTO_FW_RESET_ENABLED; -module_param(auto_fw_reset, int, 0644); -MODULE_PARM_DESC(auto_fw_reset,"Auto firmware reset (0=disabled, 1=enabled"); - -static int __devinit netxen_nic_probe(struct pci_dev *pdev, - const struct pci_device_id *ent); -static void __devexit netxen_nic_remove(struct pci_dev *pdev); -static int netxen_nic_open(struct net_device *netdev); -static int netxen_nic_close(struct net_device *netdev); -static netdev_tx_t netxen_nic_xmit_frame(struct sk_buff *, - struct net_device *); -static void netxen_tx_timeout(struct net_device *netdev); -static void netxen_tx_timeout_task(struct work_struct *work); -static void netxen_fw_poll_work(struct work_struct *work); -static void netxen_schedule_work(struct netxen_adapter *adapter, - work_func_t func, int delay); -static void netxen_cancel_fw_work(struct netxen_adapter *adapter); -static int netxen_nic_poll(struct napi_struct *napi, int budget); -#ifdef CONFIG_NET_POLL_CONTROLLER -static void netxen_nic_poll_controller(struct net_device *netdev); -#endif - -static void netxen_create_sysfs_entries(struct netxen_adapter *adapter); -static void netxen_remove_sysfs_entries(struct netxen_adapter *adapter); -static void netxen_create_diag_entries(struct netxen_adapter *adapter); -static void netxen_remove_diag_entries(struct netxen_adapter *adapter); - -static int nx_dev_request_aer(struct netxen_adapter *adapter); -static int nx_decr_dev_ref_cnt(struct netxen_adapter *adapter); -static int netxen_can_start_firmware(struct netxen_adapter *adapter); - -static irqreturn_t netxen_intr(int irq, void *data); -static irqreturn_t netxen_msi_intr(int irq, void *data); -static irqreturn_t netxen_msix_intr(int irq, void *data); - -static void netxen_free_vlan_ip_list(struct netxen_adapter *); -static void netxen_restore_indev_addr(struct net_device *dev, unsigned long); -static struct rtnl_link_stats64 *netxen_nic_get_stats(struct net_device *dev, - struct rtnl_link_stats64 *stats); -static int netxen_nic_set_mac(struct net_device *netdev, void *p); - -/* PCI Device ID Table */ -#define ENTRY(device) \ - {PCI_DEVICE(PCI_VENDOR_ID_NETXEN, (device)), \ - .class = PCI_CLASS_NETWORK_ETHERNET << 8, .class_mask = ~0} - -static DEFINE_PCI_DEVICE_TABLE(netxen_pci_tbl) = { - ENTRY(PCI_DEVICE_ID_NX2031_10GXSR), - ENTRY(PCI_DEVICE_ID_NX2031_10GCX4), - ENTRY(PCI_DEVICE_ID_NX2031_4GCU), - ENTRY(PCI_DEVICE_ID_NX2031_IMEZ), - ENTRY(PCI_DEVICE_ID_NX2031_HMEZ), - ENTRY(PCI_DEVICE_ID_NX2031_XG_MGMT), - ENTRY(PCI_DEVICE_ID_NX2031_XG_MGMT2), - ENTRY(PCI_DEVICE_ID_NX3031), - {0,} -}; - -MODULE_DEVICE_TABLE(pci, netxen_pci_tbl); - -static uint32_t crb_cmd_producer[4] = { - CRB_CMD_PRODUCER_OFFSET, CRB_CMD_PRODUCER_OFFSET_1, - CRB_CMD_PRODUCER_OFFSET_2, CRB_CMD_PRODUCER_OFFSET_3 -}; - -void -netxen_nic_update_cmd_producer(struct netxen_adapter *adapter, - struct nx_host_tx_ring *tx_ring) -{ - NXWRIO(adapter, tx_ring->crb_cmd_producer, tx_ring->producer); -} - -static uint32_t crb_cmd_consumer[4] = { - CRB_CMD_CONSUMER_OFFSET, CRB_CMD_CONSUMER_OFFSET_1, - CRB_CMD_CONSUMER_OFFSET_2, CRB_CMD_CONSUMER_OFFSET_3 -}; - -static inline void -netxen_nic_update_cmd_consumer(struct netxen_adapter *adapter, - struct nx_host_tx_ring *tx_ring) -{ - NXWRIO(adapter, tx_ring->crb_cmd_consumer, tx_ring->sw_consumer); -} - -static uint32_t msi_tgt_status[8] = { - ISR_INT_TARGET_STATUS, ISR_INT_TARGET_STATUS_F1, - ISR_INT_TARGET_STATUS_F2, ISR_INT_TARGET_STATUS_F3, - ISR_INT_TARGET_STATUS_F4, ISR_INT_TARGET_STATUS_F5, - ISR_INT_TARGET_STATUS_F6, ISR_INT_TARGET_STATUS_F7 -}; - -static struct netxen_legacy_intr_set legacy_intr[] = NX_LEGACY_INTR_CONFIG; - -static inline void netxen_nic_disable_int(struct nx_host_sds_ring *sds_ring) -{ - struct netxen_adapter *adapter = sds_ring->adapter; - - NXWRIO(adapter, sds_ring->crb_intr_mask, 0); -} - -static inline void netxen_nic_enable_int(struct nx_host_sds_ring *sds_ring) -{ - struct netxen_adapter *adapter = sds_ring->adapter; - - NXWRIO(adapter, sds_ring->crb_intr_mask, 0x1); - - if (!NETXEN_IS_MSI_FAMILY(adapter)) - NXWRIO(adapter, adapter->tgt_mask_reg, 0xfbff); -} - -static int -netxen_alloc_sds_rings(struct netxen_recv_context *recv_ctx, int count) -{ - int size = sizeof(struct nx_host_sds_ring) * count; - - recv_ctx->sds_rings = kzalloc(size, GFP_KERNEL); - - return recv_ctx->sds_rings == NULL; -} - -static void -netxen_free_sds_rings(struct netxen_recv_context *recv_ctx) -{ - if (recv_ctx->sds_rings != NULL) - kfree(recv_ctx->sds_rings); - - recv_ctx->sds_rings = NULL; -} - -static int -netxen_napi_add(struct netxen_adapter *adapter, struct net_device *netdev) -{ - int ring; - struct nx_host_sds_ring *sds_ring; - struct netxen_recv_context *recv_ctx = &adapter->recv_ctx; - - if (netxen_alloc_sds_rings(recv_ctx, adapter->max_sds_rings)) - return -ENOMEM; - - for (ring = 0; ring < adapter->max_sds_rings; ring++) { - sds_ring = &recv_ctx->sds_rings[ring]; - netif_napi_add(netdev, &sds_ring->napi, - netxen_nic_poll, NETXEN_NETDEV_WEIGHT); - } - - return 0; -} - -static void -netxen_napi_del(struct netxen_adapter *adapter) -{ - int ring; - struct nx_host_sds_ring *sds_ring; - struct netxen_recv_context *recv_ctx = &adapter->recv_ctx; - - for (ring = 0; ring < adapter->max_sds_rings; ring++) { - sds_ring = &recv_ctx->sds_rings[ring]; - netif_napi_del(&sds_ring->napi); - } - - netxen_free_sds_rings(&adapter->recv_ctx); -} - -static void -netxen_napi_enable(struct netxen_adapter *adapter) -{ - int ring; - struct nx_host_sds_ring *sds_ring; - struct netxen_recv_context *recv_ctx = &adapter->recv_ctx; - - for (ring = 0; ring < adapter->max_sds_rings; ring++) { - sds_ring = &recv_ctx->sds_rings[ring]; - napi_enable(&sds_ring->napi); - netxen_nic_enable_int(sds_ring); - } -} - -static void -netxen_napi_disable(struct netxen_adapter *adapter) -{ - int ring; - struct nx_host_sds_ring *sds_ring; - struct netxen_recv_context *recv_ctx = &adapter->recv_ctx; - - for (ring = 0; ring < adapter->max_sds_rings; ring++) { - sds_ring = &recv_ctx->sds_rings[ring]; - netxen_nic_disable_int(sds_ring); - napi_synchronize(&sds_ring->napi); - napi_disable(&sds_ring->napi); - } -} - -static int nx_set_dma_mask(struct netxen_adapter *adapter) -{ - struct pci_dev *pdev = adapter->pdev; - uint64_t mask, cmask; - - adapter->pci_using_dac = 0; - - mask = DMA_BIT_MASK(32); - cmask = DMA_BIT_MASK(32); - - if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) { -#ifndef CONFIG_IA64 - mask = DMA_BIT_MASK(35); -#endif - } else { - mask = DMA_BIT_MASK(39); - cmask = mask; - } - - if (pci_set_dma_mask(pdev, mask) == 0 && - pci_set_consistent_dma_mask(pdev, cmask) == 0) { - adapter->pci_using_dac = 1; - return 0; - } - - return -EIO; -} - -/* Update addressable range if firmware supports it */ -static int -nx_update_dma_mask(struct netxen_adapter *adapter) -{ - int change, shift, err; - uint64_t mask, old_mask, old_cmask; - struct pci_dev *pdev = adapter->pdev; - - change = 0; - - shift = NXRD32(adapter, CRB_DMA_SHIFT); - if (shift > 32) - return 0; - - if (NX_IS_REVISION_P3(adapter->ahw.revision_id) && (shift > 9)) - change = 1; - else if ((adapter->ahw.revision_id == NX_P2_C1) && (shift <= 4)) - change = 1; - - if (change) { - old_mask = pdev->dma_mask; - old_cmask = pdev->dev.coherent_dma_mask; - - mask = DMA_BIT_MASK(32+shift); - - err = pci_set_dma_mask(pdev, mask); - if (err) - goto err_out; - - if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) { - - err = pci_set_consistent_dma_mask(pdev, mask); - if (err) - goto err_out; - } - dev_info(&pdev->dev, "using %d-bit dma mask\n", 32+shift); - } - - return 0; - -err_out: - pci_set_dma_mask(pdev, old_mask); - pci_set_consistent_dma_mask(pdev, old_cmask); - return err; -} - -static int -netxen_check_hw_init(struct netxen_adapter *adapter, int first_boot) -{ - u32 val, timeout; - - if (first_boot == 0x55555555) { - /* This is the first boot after power up */ - NXWR32(adapter, NETXEN_CAM_RAM(0x1fc), NETXEN_BDINFO_MAGIC); - - if (!NX_IS_REVISION_P2(adapter->ahw.revision_id)) - return 0; - - /* PCI bus master workaround */ - first_boot = NXRD32(adapter, NETXEN_PCIE_REG(0x4)); - if (!(first_boot & 0x4)) { - first_boot |= 0x4; - NXWR32(adapter, NETXEN_PCIE_REG(0x4), first_boot); - NXRD32(adapter, NETXEN_PCIE_REG(0x4)); - } - - /* This is the first boot after power up */ - first_boot = NXRD32(adapter, NETXEN_ROMUSB_GLB_SW_RESET); - if (first_boot != 0x80000f) { - /* clear the register for future unloads/loads */ - NXWR32(adapter, NETXEN_CAM_RAM(0x1fc), 0); - return -EIO; - } - - /* Start P2 boot loader */ - val = NXRD32(adapter, NETXEN_ROMUSB_GLB_PEGTUNE_DONE); - NXWR32(adapter, NETXEN_ROMUSB_GLB_PEGTUNE_DONE, val | 0x1); - timeout = 0; - do { - msleep(1); - val = NXRD32(adapter, NETXEN_CAM_RAM(0x1fc)); - - if (++timeout > 5000) - return -EIO; - - } while (val == NETXEN_BDINFO_MAGIC); - } - return 0; -} - -static void netxen_set_port_mode(struct netxen_adapter *adapter) -{ - u32 val, data; - - val = adapter->ahw.board_type; - if ((val == NETXEN_BRDTYPE_P3_HMEZ) || - (val == NETXEN_BRDTYPE_P3_XG_LOM)) { - if (port_mode == NETXEN_PORT_MODE_802_3_AP) { - data = NETXEN_PORT_MODE_802_3_AP; - NXWR32(adapter, NETXEN_PORT_MODE_ADDR, data); - } else if (port_mode == NETXEN_PORT_MODE_XG) { - data = NETXEN_PORT_MODE_XG; - NXWR32(adapter, NETXEN_PORT_MODE_ADDR, data); - } else if (port_mode == NETXEN_PORT_MODE_AUTO_NEG_1G) { - data = NETXEN_PORT_MODE_AUTO_NEG_1G; - NXWR32(adapter, NETXEN_PORT_MODE_ADDR, data); - } else if (port_mode == NETXEN_PORT_MODE_AUTO_NEG_XG) { - data = NETXEN_PORT_MODE_AUTO_NEG_XG; - NXWR32(adapter, NETXEN_PORT_MODE_ADDR, data); - } else { - data = NETXEN_PORT_MODE_AUTO_NEG; - NXWR32(adapter, NETXEN_PORT_MODE_ADDR, data); - } - - if ((wol_port_mode != NETXEN_PORT_MODE_802_3_AP) && - (wol_port_mode != NETXEN_PORT_MODE_XG) && - (wol_port_mode != NETXEN_PORT_MODE_AUTO_NEG_1G) && - (wol_port_mode != NETXEN_PORT_MODE_AUTO_NEG_XG)) { - wol_port_mode = NETXEN_PORT_MODE_AUTO_NEG; - } - NXWR32(adapter, NETXEN_WOL_PORT_MODE, wol_port_mode); - } -} - -static void netxen_set_msix_bit(struct pci_dev *pdev, int enable) -{ - u32 control; - int pos; - - pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX); - if (pos) { - pci_read_config_dword(pdev, pos, &control); - if (enable) - control |= PCI_MSIX_FLAGS_ENABLE; - else - control = 0; - pci_write_config_dword(pdev, pos, control); - } -} - -static void netxen_init_msix_entries(struct netxen_adapter *adapter, int count) -{ - int i; - - for (i = 0; i < count; i++) - adapter->msix_entries[i].entry = i; -} - -static int -netxen_read_mac_addr(struct netxen_adapter *adapter) -{ - int i; - unsigned char *p; - u64 mac_addr; - struct net_device *netdev = adapter->netdev; - struct pci_dev *pdev = adapter->pdev; - - if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) { - if (netxen_p3_get_mac_addr(adapter, &mac_addr) != 0) - return -EIO; - } else { - if (netxen_get_flash_mac_addr(adapter, &mac_addr) != 0) - return -EIO; - } - - p = (unsigned char *)&mac_addr; - for (i = 0; i < 6; i++) - netdev->dev_addr[i] = *(p + 5 - i); - - memcpy(netdev->perm_addr, netdev->dev_addr, netdev->addr_len); - memcpy(adapter->mac_addr, netdev->dev_addr, netdev->addr_len); - - /* set station address */ - - if (!is_valid_ether_addr(netdev->perm_addr)) - dev_warn(&pdev->dev, "Bad MAC address %pM.\n", netdev->dev_addr); - - return 0; -} - -static int netxen_nic_set_mac(struct net_device *netdev, void *p) -{ - struct netxen_adapter *adapter = netdev_priv(netdev); - struct sockaddr *addr = p; - - if (!is_valid_ether_addr(addr->sa_data)) - return -EINVAL; - - if (netif_running(netdev)) { - netif_device_detach(netdev); - netxen_napi_disable(adapter); - } - - memcpy(adapter->mac_addr, addr->sa_data, netdev->addr_len); - memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); - adapter->macaddr_set(adapter, addr->sa_data); - - if (netif_running(netdev)) { - netif_device_attach(netdev); - netxen_napi_enable(adapter); - } - return 0; -} - -static void netxen_set_multicast_list(struct net_device *dev) -{ - struct netxen_adapter *adapter = netdev_priv(dev); - - adapter->set_multi(dev); -} - -static u32 netxen_fix_features(struct net_device *dev, u32 features) -{ - if (!(features & NETIF_F_RXCSUM)) { - netdev_info(dev, "disabling LRO as RXCSUM is off\n"); - - features &= ~NETIF_F_LRO; - } - - return features; -} - -static int netxen_set_features(struct net_device *dev, u32 features) -{ - struct netxen_adapter *adapter = netdev_priv(dev); - int hw_lro; - - if (!((dev->features ^ features) & NETIF_F_LRO)) - return 0; - - hw_lro = (features & NETIF_F_LRO) ? NETXEN_NIC_LRO_ENABLED - : NETXEN_NIC_LRO_DISABLED; - - if (netxen_config_hw_lro(adapter, hw_lro)) - return -EIO; - - if (!(features & NETIF_F_LRO) && netxen_send_lro_cleanup(adapter)) - return -EIO; - - return 0; -} - -static const struct net_device_ops netxen_netdev_ops = { - .ndo_open = netxen_nic_open, - .ndo_stop = netxen_nic_close, - .ndo_start_xmit = netxen_nic_xmit_frame, - .ndo_get_stats64 = netxen_nic_get_stats, - .ndo_validate_addr = eth_validate_addr, - .ndo_set_multicast_list = netxen_set_multicast_list, - .ndo_set_mac_address = netxen_nic_set_mac, - .ndo_change_mtu = netxen_nic_change_mtu, - .ndo_tx_timeout = netxen_tx_timeout, - .ndo_fix_features = netxen_fix_features, - .ndo_set_features = netxen_set_features, -#ifdef CONFIG_NET_POLL_CONTROLLER - .ndo_poll_controller = netxen_nic_poll_controller, -#endif -}; - -static void -netxen_setup_intr(struct netxen_adapter *adapter) -{ - struct netxen_legacy_intr_set *legacy_intrp; - struct pci_dev *pdev = adapter->pdev; - int err, num_msix; - - if (adapter->rss_supported) { - num_msix = (num_online_cpus() >= MSIX_ENTRIES_PER_ADAPTER) ? - MSIX_ENTRIES_PER_ADAPTER : 2; - } else - num_msix = 1; - - adapter->max_sds_rings = 1; - - adapter->flags &= ~(NETXEN_NIC_MSI_ENABLED | NETXEN_NIC_MSIX_ENABLED); - - if (adapter->ahw.revision_id >= NX_P3_B0) - legacy_intrp = &legacy_intr[adapter->ahw.pci_func]; - else - legacy_intrp = &legacy_intr[0]; - - adapter->int_vec_bit = legacy_intrp->int_vec_bit; - adapter->tgt_status_reg = netxen_get_ioaddr(adapter, - legacy_intrp->tgt_status_reg); - adapter->tgt_mask_reg = netxen_get_ioaddr(adapter, - legacy_intrp->tgt_mask_reg); - adapter->pci_int_reg = netxen_get_ioaddr(adapter, - legacy_intrp->pci_int_reg); - adapter->isr_int_vec = netxen_get_ioaddr(adapter, ISR_INT_VECTOR); - - if (adapter->ahw.revision_id >= NX_P3_B1) - adapter->crb_int_state_reg = netxen_get_ioaddr(adapter, - ISR_INT_STATE_REG); - else - adapter->crb_int_state_reg = netxen_get_ioaddr(adapter, - CRB_INT_VECTOR); - - netxen_set_msix_bit(pdev, 0); - - if (adapter->msix_supported) { - - netxen_init_msix_entries(adapter, num_msix); - err = pci_enable_msix(pdev, adapter->msix_entries, num_msix); - if (err == 0) { - adapter->flags |= NETXEN_NIC_MSIX_ENABLED; - netxen_set_msix_bit(pdev, 1); - - if (adapter->rss_supported) - adapter->max_sds_rings = num_msix; - - dev_info(&pdev->dev, "using msi-x interrupts\n"); - return; - } - - if (err > 0) - pci_disable_msix(pdev); - - /* fall through for msi */ - } - - if (use_msi && !pci_enable_msi(pdev)) { - adapter->flags |= NETXEN_NIC_MSI_ENABLED; - adapter->tgt_status_reg = netxen_get_ioaddr(adapter, - msi_tgt_status[adapter->ahw.pci_func]); - dev_info(&pdev->dev, "using msi interrupts\n"); - adapter->msix_entries[0].vector = pdev->irq; - return; - } - - dev_info(&pdev->dev, "using legacy interrupts\n"); - adapter->msix_entries[0].vector = pdev->irq; -} - -static void -netxen_teardown_intr(struct netxen_adapter *adapter) -{ - if (adapter->flags & NETXEN_NIC_MSIX_ENABLED) - pci_disable_msix(adapter->pdev); - if (adapter->flags & NETXEN_NIC_MSI_ENABLED) - pci_disable_msi(adapter->pdev); -} - -static void -netxen_cleanup_pci_map(struct netxen_adapter *adapter) -{ - if (adapter->ahw.db_base != NULL) - iounmap(adapter->ahw.db_base); - if (adapter->ahw.pci_base0 != NULL) - iounmap(adapter->ahw.pci_base0); - if (adapter->ahw.pci_base1 != NULL) - iounmap(adapter->ahw.pci_base1); - if (adapter->ahw.pci_base2 != NULL) - iounmap(adapter->ahw.pci_base2); -} - -static int -netxen_setup_pci_map(struct netxen_adapter *adapter) -{ - void __iomem *db_ptr = NULL; - - resource_size_t mem_base, db_base; - unsigned long mem_len, db_len = 0; - - struct pci_dev *pdev = adapter->pdev; - int pci_func = adapter->ahw.pci_func; - struct netxen_hardware_context *ahw = &adapter->ahw; - - int err = 0; - - /* - * Set the CRB window to invalid. If any register in window 0 is - * accessed it should set the window to 0 and then reset it to 1. - */ - adapter->ahw.crb_win = -1; - adapter->ahw.ocm_win = -1; - - /* remap phys address */ - mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */ - mem_len = pci_resource_len(pdev, 0); - - /* 128 Meg of memory */ - if (mem_len == NETXEN_PCI_128MB_SIZE) { - - ahw->pci_base0 = ioremap(mem_base, FIRST_PAGE_GROUP_SIZE); - ahw->pci_base1 = ioremap(mem_base + SECOND_PAGE_GROUP_START, - SECOND_PAGE_GROUP_SIZE); - ahw->pci_base2 = ioremap(mem_base + THIRD_PAGE_GROUP_START, - THIRD_PAGE_GROUP_SIZE); - if (ahw->pci_base0 == NULL || ahw->pci_base1 == NULL || - ahw->pci_base2 == NULL) { - dev_err(&pdev->dev, "failed to map PCI bar 0\n"); - err = -EIO; - goto err_out; - } - - ahw->pci_len0 = FIRST_PAGE_GROUP_SIZE; - - } else if (mem_len == NETXEN_PCI_32MB_SIZE) { - - ahw->pci_base1 = ioremap(mem_base, SECOND_PAGE_GROUP_SIZE); - ahw->pci_base2 = ioremap(mem_base + THIRD_PAGE_GROUP_START - - SECOND_PAGE_GROUP_START, THIRD_PAGE_GROUP_SIZE); - if (ahw->pci_base1 == NULL || ahw->pci_base2 == NULL) { - dev_err(&pdev->dev, "failed to map PCI bar 0\n"); - err = -EIO; - goto err_out; - } - - } else if (mem_len == NETXEN_PCI_2MB_SIZE) { - - ahw->pci_base0 = pci_ioremap_bar(pdev, 0); - if (ahw->pci_base0 == NULL) { - dev_err(&pdev->dev, "failed to map PCI bar 0\n"); - return -EIO; - } - ahw->pci_len0 = mem_len; - } else { - return -EIO; - } - - netxen_setup_hwops(adapter); - - dev_info(&pdev->dev, "%dMB memory map\n", (int)(mem_len>>20)); - - if (NX_IS_REVISION_P3P(adapter->ahw.revision_id)) { - adapter->ahw.ocm_win_crb = netxen_get_ioaddr(adapter, - NETXEN_PCIX_PS_REG(PCIX_OCM_WINDOW_REG(pci_func))); - - } else if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) { - adapter->ahw.ocm_win_crb = netxen_get_ioaddr(adapter, - NETXEN_PCIX_PS_REG(PCIE_MN_WINDOW_REG(pci_func))); - } - - if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) - goto skip_doorbell; - - db_base = pci_resource_start(pdev, 4); /* doorbell is on bar 4 */ - db_len = pci_resource_len(pdev, 4); - - if (db_len == 0) { - printk(KERN_ERR "%s: doorbell is disabled\n", - netxen_nic_driver_name); - err = -EIO; - goto err_out; - } - - db_ptr = ioremap(db_base, NETXEN_DB_MAPSIZE_BYTES); - if (!db_ptr) { - printk(KERN_ERR "%s: Failed to allocate doorbell map.", - netxen_nic_driver_name); - err = -EIO; - goto err_out; - } - -skip_doorbell: - adapter->ahw.db_base = db_ptr; - adapter->ahw.db_len = db_len; - return 0; - -err_out: - netxen_cleanup_pci_map(adapter); - return err; -} - -static void -netxen_check_options(struct netxen_adapter *adapter) -{ - u32 fw_major, fw_minor, fw_build; - char brd_name[NETXEN_MAX_SHORT_NAME]; - char serial_num[32]; - int i, offset, val; - int *ptr32; - struct pci_dev *pdev = adapter->pdev; - - adapter->driver_mismatch = 0; - - ptr32 = (int *)&serial_num; - offset = NX_FW_SERIAL_NUM_OFFSET; - for (i = 0; i < 8; i++) { - if (netxen_rom_fast_read(adapter, offset, &val) == -1) { - dev_err(&pdev->dev, "error reading board info\n"); - adapter->driver_mismatch = 1; - return; - } - ptr32[i] = cpu_to_le32(val); - offset += sizeof(u32); - } - - fw_major = NXRD32(adapter, NETXEN_FW_VERSION_MAJOR); - fw_minor = NXRD32(adapter, NETXEN_FW_VERSION_MINOR); - fw_build = NXRD32(adapter, NETXEN_FW_VERSION_SUB); - - adapter->fw_version = NETXEN_VERSION_CODE(fw_major, fw_minor, fw_build); - - if (adapter->portnum == 0) { - get_brd_name_by_type(adapter->ahw.board_type, brd_name); - - pr_info("%s: %s Board S/N %s Chip rev 0x%x\n", - module_name(THIS_MODULE), - brd_name, serial_num, adapter->ahw.revision_id); - } - - if (adapter->fw_version < NETXEN_VERSION_CODE(3, 4, 216)) { - adapter->driver_mismatch = 1; - dev_warn(&pdev->dev, "firmware version %d.%d.%d unsupported\n", - fw_major, fw_minor, fw_build); - return; - } - - if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) { - i = NXRD32(adapter, NETXEN_SRE_MISC); - adapter->ahw.cut_through = (i & 0x8000) ? 1 : 0; - } - - dev_info(&pdev->dev, "firmware v%d.%d.%d [%s]\n", - fw_major, fw_minor, fw_build, - adapter->ahw.cut_through ? "cut-through" : "legacy"); - - if (adapter->fw_version >= NETXEN_VERSION_CODE(4, 0, 222)) - adapter->capabilities = NXRD32(adapter, CRB_FW_CAPABILITIES_1); - - if (adapter->ahw.port_type == NETXEN_NIC_XGBE) { - adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_10G; - adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_10G; - } else if (adapter->ahw.port_type == NETXEN_NIC_GBE) { - adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_1G; - adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_1G; - } - - adapter->msix_supported = 0; - if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) { - adapter->msix_supported = !!use_msi_x; - adapter->rss_supported = !!use_msi_x; - } else { - u32 flashed_ver = 0; - netxen_rom_fast_read(adapter, - NX_FW_VERSION_OFFSET, (int *)&flashed_ver); - flashed_ver = NETXEN_DECODE_VERSION(flashed_ver); - - if (flashed_ver >= NETXEN_VERSION_CODE(3, 4, 336)) { - switch (adapter->ahw.board_type) { - case NETXEN_BRDTYPE_P2_SB31_10G: - case NETXEN_BRDTYPE_P2_SB31_10G_CX4: - adapter->msix_supported = !!use_msi_x; - adapter->rss_supported = !!use_msi_x; - break; - default: - break; - } - } - } - - adapter->num_txd = MAX_CMD_DESCRIPTORS; - - if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) { - adapter->num_lro_rxd = MAX_LRO_RCV_DESCRIPTORS; - adapter->max_rds_rings = 3; - } else { - adapter->num_lro_rxd = 0; - adapter->max_rds_rings = 2; - } -} - -static int -netxen_start_firmware(struct netxen_adapter *adapter) -{ - int val, err, first_boot; - struct pci_dev *pdev = adapter->pdev; - - /* required for NX2031 dummy dma */ - err = nx_set_dma_mask(adapter); - if (err) - return err; - - if (!netxen_can_start_firmware(adapter)) - goto wait_init; - - first_boot = NXRD32(adapter, NETXEN_CAM_RAM(0x1fc)); - - err = netxen_check_hw_init(adapter, first_boot); - if (err) { - dev_err(&pdev->dev, "error in init HW init sequence\n"); - return err; - } - - netxen_request_firmware(adapter); - - err = netxen_need_fw_reset(adapter); - if (err < 0) - goto err_out; - if (err == 0) - goto wait_init; - - if (first_boot != 0x55555555) { - NXWR32(adapter, CRB_CMDPEG_STATE, 0); - netxen_pinit_from_rom(adapter); - msleep(1); - } - - NXWR32(adapter, CRB_DMA_SHIFT, 0x55555555); - NXWR32(adapter, NETXEN_PEG_HALT_STATUS1, 0); - NXWR32(adapter, NETXEN_PEG_HALT_STATUS2, 0); - - if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) - netxen_set_port_mode(adapter); - - err = netxen_load_firmware(adapter); - if (err) - goto err_out; - - netxen_release_firmware(adapter); - - if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) { - - /* Initialize multicast addr pool owners */ - val = 0x7654; - if (adapter->ahw.port_type == NETXEN_NIC_XGBE) - val |= 0x0f000000; - NXWR32(adapter, NETXEN_MAC_ADDR_CNTL_REG, val); - - } - - err = netxen_init_dummy_dma(adapter); - if (err) - goto err_out; - - /* - * Tell the hardware our version number. - */ - val = (_NETXEN_NIC_LINUX_MAJOR << 16) - | ((_NETXEN_NIC_LINUX_MINOR << 8)) - | (_NETXEN_NIC_LINUX_SUBVERSION); - NXWR32(adapter, CRB_DRIVER_VERSION, val); - -wait_init: - /* Handshake with the card before we register the devices. */ - err = netxen_phantom_init(adapter, NETXEN_NIC_PEG_TUNE); - if (err) { - netxen_free_dummy_dma(adapter); - goto err_out; - } - - NXWR32(adapter, NX_CRB_DEV_STATE, NX_DEV_READY); - - nx_update_dma_mask(adapter); - - netxen_check_options(adapter); - - adapter->need_fw_reset = 0; - - /* fall through and release firmware */ - -err_out: - netxen_release_firmware(adapter); - return err; -} - -static int -netxen_nic_request_irq(struct netxen_adapter *adapter) -{ - irq_handler_t handler; - struct nx_host_sds_ring *sds_ring; - int err, ring; - - unsigned long flags = 0; - struct net_device *netdev = adapter->netdev; - struct netxen_recv_context *recv_ctx = &adapter->recv_ctx; - - if (adapter->flags & NETXEN_NIC_MSIX_ENABLED) - handler = netxen_msix_intr; - else if (adapter->flags & NETXEN_NIC_MSI_ENABLED) - handler = netxen_msi_intr; - else { - flags |= IRQF_SHARED; - handler = netxen_intr; - } - adapter->irq = netdev->irq; - - for (ring = 0; ring < adapter->max_sds_rings; ring++) { - sds_ring = &recv_ctx->sds_rings[ring]; - sprintf(sds_ring->name, "%s[%d]", netdev->name, ring); - err = request_irq(sds_ring->irq, handler, - flags, sds_ring->name, sds_ring); - if (err) - return err; - } - - return 0; -} - -static void -netxen_nic_free_irq(struct netxen_adapter *adapter) -{ - int ring; - struct nx_host_sds_ring *sds_ring; - - struct netxen_recv_context *recv_ctx = &adapter->recv_ctx; - - for (ring = 0; ring < adapter->max_sds_rings; ring++) { - sds_ring = &recv_ctx->sds_rings[ring]; - free_irq(sds_ring->irq, sds_ring); - } -} - -static void -netxen_nic_init_coalesce_defaults(struct netxen_adapter *adapter) -{ - adapter->coal.flags = NETXEN_NIC_INTR_DEFAULT; - adapter->coal.normal.data.rx_time_us = - NETXEN_DEFAULT_INTR_COALESCE_RX_TIME_US; - adapter->coal.normal.data.rx_packets = - NETXEN_DEFAULT_INTR_COALESCE_RX_PACKETS; - adapter->coal.normal.data.tx_time_us = - NETXEN_DEFAULT_INTR_COALESCE_TX_TIME_US; - adapter->coal.normal.data.tx_packets = - NETXEN_DEFAULT_INTR_COALESCE_TX_PACKETS; -} - -/* with rtnl_lock */ -static int -__netxen_nic_up(struct netxen_adapter *adapter, struct net_device *netdev) -{ - int err; - - if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC) - return -EIO; - - err = adapter->init_port(adapter, adapter->physical_port); - if (err) { - printk(KERN_ERR "%s: Failed to initialize port %d\n", - netxen_nic_driver_name, adapter->portnum); - return err; - } - if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) - adapter->macaddr_set(adapter, adapter->mac_addr); - - adapter->set_multi(netdev); - adapter->set_mtu(adapter, netdev->mtu); - - adapter->ahw.linkup = 0; - - if (adapter->max_sds_rings > 1) - netxen_config_rss(adapter, 1); - - if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) - netxen_config_intr_coalesce(adapter); - - if (netdev->features & NETIF_F_LRO) - netxen_config_hw_lro(adapter, NETXEN_NIC_LRO_ENABLED); - - netxen_napi_enable(adapter); - - if (adapter->capabilities & NX_FW_CAPABILITY_LINK_NOTIFICATION) - netxen_linkevent_request(adapter, 1); - else - netxen_nic_set_link_parameters(adapter); - - set_bit(__NX_DEV_UP, &adapter->state); - return 0; -} - -/* Usage: During resume and firmware recovery module.*/ - -static inline int -netxen_nic_up(struct netxen_adapter *adapter, struct net_device *netdev) -{ - int err = 0; - - rtnl_lock(); - if (netif_running(netdev)) - err = __netxen_nic_up(adapter, netdev); - rtnl_unlock(); - - return err; -} - -/* with rtnl_lock */ -static void -__netxen_nic_down(struct netxen_adapter *adapter, struct net_device *netdev) -{ - if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC) - return; - - if (!test_and_clear_bit(__NX_DEV_UP, &adapter->state)) - return; - - smp_mb(); - spin_lock(&adapter->tx_clean_lock); - netif_carrier_off(netdev); - netif_tx_disable(netdev); - - if (adapter->capabilities & NX_FW_CAPABILITY_LINK_NOTIFICATION) - netxen_linkevent_request(adapter, 0); - - if (adapter->stop_port) - adapter->stop_port(adapter); - - if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) - netxen_p3_free_mac_list(adapter); - - adapter->set_promisc(adapter, NETXEN_NIU_NON_PROMISC_MODE); - - netxen_napi_disable(adapter); - - netxen_release_tx_buffers(adapter); - spin_unlock(&adapter->tx_clean_lock); -} - -/* Usage: During suspend and firmware recovery module */ - -static inline void -netxen_nic_down(struct netxen_adapter *adapter, struct net_device *netdev) -{ - rtnl_lock(); - if (netif_running(netdev)) - __netxen_nic_down(adapter, netdev); - rtnl_unlock(); - -} - -static int -netxen_nic_attach(struct netxen_adapter *adapter) -{ - struct net_device *netdev = adapter->netdev; - struct pci_dev *pdev = adapter->pdev; - int err, ring; - struct nx_host_rds_ring *rds_ring; - struct nx_host_tx_ring *tx_ring; - - if (adapter->is_up == NETXEN_ADAPTER_UP_MAGIC) - return 0; - - err = netxen_init_firmware(adapter); - if (err) - return err; - - err = netxen_napi_add(adapter, netdev); - if (err) - return err; - - err = netxen_alloc_sw_resources(adapter); - if (err) { - printk(KERN_ERR "%s: Error in setting sw resources\n", - netdev->name); - return err; - } - - err = netxen_alloc_hw_resources(adapter); - if (err) { - printk(KERN_ERR "%s: Error in setting hw resources\n", - netdev->name); - goto err_out_free_sw; - } - - if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) { - tx_ring = adapter->tx_ring; - tx_ring->crb_cmd_producer = netxen_get_ioaddr(adapter, - crb_cmd_producer[adapter->portnum]); - tx_ring->crb_cmd_consumer = netxen_get_ioaddr(adapter, - crb_cmd_consumer[adapter->portnum]); - - tx_ring->producer = 0; - tx_ring->sw_consumer = 0; - - netxen_nic_update_cmd_producer(adapter, tx_ring); - netxen_nic_update_cmd_consumer(adapter, tx_ring); - } - - for (ring = 0; ring < adapter->max_rds_rings; ring++) { - rds_ring = &adapter->recv_ctx.rds_rings[ring]; - netxen_post_rx_buffers(adapter, ring, rds_ring); - } - - err = netxen_nic_request_irq(adapter); - if (err) { - dev_err(&pdev->dev, "%s: failed to setup interrupt\n", - netdev->name); - goto err_out_free_rxbuf; - } - - if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) - netxen_nic_init_coalesce_defaults(adapter); - - netxen_create_sysfs_entries(adapter); - - adapter->is_up = NETXEN_ADAPTER_UP_MAGIC; - return 0; - -err_out_free_rxbuf: - netxen_release_rx_buffers(adapter); - netxen_free_hw_resources(adapter); -err_out_free_sw: - netxen_free_sw_resources(adapter); - return err; -} - -static void -netxen_nic_detach(struct netxen_adapter *adapter) -{ - if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC) - return; - - netxen_remove_sysfs_entries(adapter); - - netxen_free_hw_resources(adapter); - netxen_release_rx_buffers(adapter); - netxen_nic_free_irq(adapter); - netxen_napi_del(adapter); - netxen_free_sw_resources(adapter); - - adapter->is_up = 0; -} - -int -netxen_nic_reset_context(struct netxen_adapter *adapter) -{ - int err = 0; - struct net_device *netdev = adapter->netdev; - - if (test_and_set_bit(__NX_RESETTING, &adapter->state)) - return -EBUSY; - - if (adapter->is_up == NETXEN_ADAPTER_UP_MAGIC) { - - netif_device_detach(netdev); - - if (netif_running(netdev)) - __netxen_nic_down(adapter, netdev); - - netxen_nic_detach(adapter); - - if (netif_running(netdev)) { - err = netxen_nic_attach(adapter); - if (!err) - err = __netxen_nic_up(adapter, netdev); - - if (err) - goto done; - } - - netif_device_attach(netdev); - } - -done: - clear_bit(__NX_RESETTING, &adapter->state); - return err; -} - -static int -netxen_setup_netdev(struct netxen_adapter *adapter, - struct net_device *netdev) -{ - int err = 0; - struct pci_dev *pdev = adapter->pdev; - - adapter->mc_enabled = 0; - if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) - adapter->max_mc_count = 38; - else - adapter->max_mc_count = 16; - - netdev->netdev_ops = &netxen_netdev_ops; - netdev->watchdog_timeo = 5*HZ; - - netxen_nic_change_mtu(netdev, netdev->mtu); - - SET_ETHTOOL_OPS(netdev, &netxen_nic_ethtool_ops); - - netdev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO | - NETIF_F_RXCSUM; - - if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) - netdev->hw_features |= NETIF_F_IPV6_CSUM | NETIF_F_TSO6; - - netdev->vlan_features |= netdev->hw_features; - - if (adapter->pci_using_dac) { - netdev->features |= NETIF_F_HIGHDMA; - netdev->vlan_features |= NETIF_F_HIGHDMA; - } - - if (adapter->capabilities & NX_FW_CAPABILITY_FVLANTX) - netdev->hw_features |= NETIF_F_HW_VLAN_TX; - - if (adapter->capabilities & NX_FW_CAPABILITY_HW_LRO) - netdev->hw_features |= NETIF_F_LRO; - - netdev->features |= netdev->hw_features; - - netdev->irq = adapter->msix_entries[0].vector; - - INIT_WORK(&adapter->tx_timeout_task, netxen_tx_timeout_task); - - if (netxen_read_mac_addr(adapter)) - dev_warn(&pdev->dev, "failed to read mac addr\n"); - - netif_carrier_off(netdev); - - err = register_netdev(netdev); - if (err) { - dev_err(&pdev->dev, "failed to register net device\n"); - return err; - } - - return 0; -} - -#ifdef CONFIG_PCIEAER -static void netxen_mask_aer_correctable(struct netxen_adapter *adapter) -{ - struct pci_dev *pdev = adapter->pdev; - struct pci_dev *root = pdev->bus->self; - u32 aer_pos; - - if (adapter->ahw.board_type != NETXEN_BRDTYPE_P3_4_GB_MM && - adapter->ahw.board_type != NETXEN_BRDTYPE_P3_10G_TP) - return; - - if (root->pcie_type != PCI_EXP_TYPE_ROOT_PORT) - return; - - aer_pos = pci_find_ext_capability(root, PCI_EXT_CAP_ID_ERR); - if (!aer_pos) - return; - - pci_write_config_dword(root, aer_pos + PCI_ERR_COR_MASK, 0xffff); -} -#endif - -static int __devinit -netxen_nic_probe(struct pci_dev *pdev, const struct pci_device_id *ent) -{ - struct net_device *netdev = NULL; - struct netxen_adapter *adapter = NULL; - int i = 0, err; - int pci_func_id = PCI_FUNC(pdev->devfn); - uint8_t revision_id; - u32 val; - - if (pdev->revision >= NX_P3_A0 && pdev->revision <= NX_P3_B1) { - pr_warning("%s: chip revisions between 0x%x-0x%x " - "will not be enabled.\n", - module_name(THIS_MODULE), NX_P3_A0, NX_P3_B1); - return -ENODEV; - } - - if ((err = pci_enable_device(pdev))) - return err; - - if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) { - err = -ENODEV; - goto err_out_disable_pdev; - } - - if ((err = pci_request_regions(pdev, netxen_nic_driver_name))) - goto err_out_disable_pdev; - - if (NX_IS_REVISION_P3(pdev->revision)) - pci_enable_pcie_error_reporting(pdev); - - pci_set_master(pdev); - - netdev = alloc_etherdev(sizeof(struct netxen_adapter)); - if(!netdev) { - dev_err(&pdev->dev, "failed to allocate net_device\n"); - err = -ENOMEM; - goto err_out_free_res; - } - - SET_NETDEV_DEV(netdev, &pdev->dev); - - adapter = netdev_priv(netdev); - adapter->netdev = netdev; - adapter->pdev = pdev; - adapter->ahw.pci_func = pci_func_id; - - revision_id = pdev->revision; - adapter->ahw.revision_id = revision_id; - - rwlock_init(&adapter->ahw.crb_lock); - spin_lock_init(&adapter->ahw.mem_lock); - - spin_lock_init(&adapter->tx_clean_lock); - INIT_LIST_HEAD(&adapter->mac_list); - INIT_LIST_HEAD(&adapter->vlan_ip_list); - - err = netxen_setup_pci_map(adapter); - if (err) - goto err_out_free_netdev; - - /* This will be reset for mezz cards */ - adapter->portnum = pci_func_id; - - err = netxen_nic_get_board_info(adapter); - if (err) { - dev_err(&pdev->dev, "Error getting board config info.\n"); - goto err_out_iounmap; - } - -#ifdef CONFIG_PCIEAER - netxen_mask_aer_correctable(adapter); -#endif - - /* Mezz cards have PCI function 0,2,3 enabled */ - switch (adapter->ahw.board_type) { - case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ: - case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ: - if (pci_func_id >= 2) - adapter->portnum = pci_func_id - 2; - break; - default: - break; - } - - err = netxen_check_flash_fw_compatibility(adapter); - if (err) - goto err_out_iounmap; - - if (adapter->portnum == 0) { - val = NXRD32(adapter, NX_CRB_DEV_REF_COUNT); - if (val != 0xffffffff && val != 0) { - NXWR32(adapter, NX_CRB_DEV_REF_COUNT, 0); - adapter->need_fw_reset = 1; - } - } - - err = netxen_start_firmware(adapter); - if (err) - goto err_out_decr_ref; - - /* - * See if the firmware gave us a virtual-physical port mapping. - */ - adapter->physical_port = adapter->portnum; - if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) { - i = NXRD32(adapter, CRB_V2P(adapter->portnum)); - if (i != 0x55555555) - adapter->physical_port = i; - } - - netxen_nic_clear_stats(adapter); - - netxen_setup_intr(adapter); - - err = netxen_setup_netdev(adapter, netdev); - if (err) - goto err_out_disable_msi; - - pci_set_drvdata(pdev, adapter); - - netxen_schedule_work(adapter, netxen_fw_poll_work, FW_POLL_DELAY); - - switch (adapter->ahw.port_type) { - case NETXEN_NIC_GBE: - dev_info(&adapter->pdev->dev, "%s: GbE port initialized\n", - adapter->netdev->name); - break; - case NETXEN_NIC_XGBE: - dev_info(&adapter->pdev->dev, "%s: XGbE port initialized\n", - adapter->netdev->name); - break; - } - - netxen_create_diag_entries(adapter); - - return 0; - -err_out_disable_msi: - netxen_teardown_intr(adapter); - - netxen_free_dummy_dma(adapter); - -err_out_decr_ref: - nx_decr_dev_ref_cnt(adapter); - -err_out_iounmap: - netxen_cleanup_pci_map(adapter); - -err_out_free_netdev: - free_netdev(netdev); - -err_out_free_res: - pci_release_regions(pdev); - -err_out_disable_pdev: - pci_set_drvdata(pdev, NULL); - pci_disable_device(pdev); - return err; -} - -static void __devexit netxen_nic_remove(struct pci_dev *pdev) -{ - struct netxen_adapter *adapter; - struct net_device *netdev; - - adapter = pci_get_drvdata(pdev); - if (adapter == NULL) - return; - - netdev = adapter->netdev; - - netxen_cancel_fw_work(adapter); - - unregister_netdev(netdev); - - cancel_work_sync(&adapter->tx_timeout_task); - - netxen_free_vlan_ip_list(adapter); - netxen_nic_detach(adapter); - - nx_decr_dev_ref_cnt(adapter); - - if (adapter->portnum == 0) - netxen_free_dummy_dma(adapter); - - clear_bit(__NX_RESETTING, &adapter->state); - - netxen_teardown_intr(adapter); - - netxen_remove_diag_entries(adapter); - - netxen_cleanup_pci_map(adapter); - - netxen_release_firmware(adapter); - - if (NX_IS_REVISION_P3(pdev->revision)) - pci_disable_pcie_error_reporting(pdev); - - pci_release_regions(pdev); - pci_disable_device(pdev); - pci_set_drvdata(pdev, NULL); - - free_netdev(netdev); -} - -static void netxen_nic_detach_func(struct netxen_adapter *adapter) -{ - struct net_device *netdev = adapter->netdev; - - netif_device_detach(netdev); - - netxen_cancel_fw_work(adapter); - - if (netif_running(netdev)) - netxen_nic_down(adapter, netdev); - - cancel_work_sync(&adapter->tx_timeout_task); - - netxen_nic_detach(adapter); - - if (adapter->portnum == 0) - netxen_free_dummy_dma(adapter); - - nx_decr_dev_ref_cnt(adapter); - - clear_bit(__NX_RESETTING, &adapter->state); -} - -static int netxen_nic_attach_func(struct pci_dev *pdev) -{ - struct netxen_adapter *adapter = pci_get_drvdata(pdev); - struct net_device *netdev = adapter->netdev; - int err; - - err = pci_enable_device(pdev); - if (err) - return err; - - pci_set_power_state(pdev, PCI_D0); - pci_set_master(pdev); - pci_restore_state(pdev); - - adapter->ahw.crb_win = -1; - adapter->ahw.ocm_win = -1; - - err = netxen_start_firmware(adapter); - if (err) { - dev_err(&pdev->dev, "failed to start firmware\n"); - return err; - } - - if (netif_running(netdev)) { - err = netxen_nic_attach(adapter); - if (err) - goto err_out; - - err = netxen_nic_up(adapter, netdev); - if (err) - goto err_out_detach; - - netxen_restore_indev_addr(netdev, NETDEV_UP); - } - - netif_device_attach(netdev); - netxen_schedule_work(adapter, netxen_fw_poll_work, FW_POLL_DELAY); - return 0; - -err_out_detach: - netxen_nic_detach(adapter); -err_out: - nx_decr_dev_ref_cnt(adapter); - return err; -} - -static pci_ers_result_t netxen_io_error_detected(struct pci_dev *pdev, - pci_channel_state_t state) -{ - struct netxen_adapter *adapter = pci_get_drvdata(pdev); - - if (state == pci_channel_io_perm_failure) - return PCI_ERS_RESULT_DISCONNECT; - - if (nx_dev_request_aer(adapter)) - return PCI_ERS_RESULT_RECOVERED; - - netxen_nic_detach_func(adapter); - - pci_disable_device(pdev); - - return PCI_ERS_RESULT_NEED_RESET; -} - -static pci_ers_result_t netxen_io_slot_reset(struct pci_dev *pdev) -{ - int err = 0; - - err = netxen_nic_attach_func(pdev); - - return err ? PCI_ERS_RESULT_DISCONNECT : PCI_ERS_RESULT_RECOVERED; -} - -static void netxen_io_resume(struct pci_dev *pdev) -{ - pci_cleanup_aer_uncorrect_error_status(pdev); -} - -static void netxen_nic_shutdown(struct pci_dev *pdev) -{ - struct netxen_adapter *adapter = pci_get_drvdata(pdev); - - netxen_nic_detach_func(adapter); - - if (pci_save_state(pdev)) - return; - - if (netxen_nic_wol_supported(adapter)) { - pci_enable_wake(pdev, PCI_D3cold, 1); - pci_enable_wake(pdev, PCI_D3hot, 1); - } - - pci_disable_device(pdev); -} - -#ifdef CONFIG_PM -static int -netxen_nic_suspend(struct pci_dev *pdev, pm_message_t state) -{ - struct netxen_adapter *adapter = pci_get_drvdata(pdev); - int retval; - - netxen_nic_detach_func(adapter); - - retval = pci_save_state(pdev); - if (retval) - return retval; - - if (netxen_nic_wol_supported(adapter)) { - pci_enable_wake(pdev, PCI_D3cold, 1); - pci_enable_wake(pdev, PCI_D3hot, 1); - } - - pci_disable_device(pdev); - pci_set_power_state(pdev, pci_choose_state(pdev, state)); - - return 0; -} - -static int -netxen_nic_resume(struct pci_dev *pdev) -{ - return netxen_nic_attach_func(pdev); -} -#endif - -static int netxen_nic_open(struct net_device *netdev) -{ - struct netxen_adapter *adapter = netdev_priv(netdev); - int err = 0; - - if (adapter->driver_mismatch) - return -EIO; - - err = netxen_nic_attach(adapter); - if (err) - return err; - - err = __netxen_nic_up(adapter, netdev); - if (err) - goto err_out; - - netif_start_queue(netdev); - - return 0; - -err_out: - netxen_nic_detach(adapter); - return err; -} - -/* - * netxen_nic_close - Disables a network interface entry point - */ -static int netxen_nic_close(struct net_device *netdev) -{ - struct netxen_adapter *adapter = netdev_priv(netdev); - - __netxen_nic_down(adapter, netdev); - return 0; -} - -static void -netxen_tso_check(struct net_device *netdev, - struct nx_host_tx_ring *tx_ring, - struct cmd_desc_type0 *first_desc, - struct sk_buff *skb) -{ - u8 opcode = TX_ETHER_PKT; - __be16 protocol = skb->protocol; - u16 flags = 0, vid = 0; - u32 producer; - int copied, offset, copy_len, hdr_len = 0, tso = 0, vlan_oob = 0; - struct cmd_desc_type0 *hwdesc; - struct vlan_ethhdr *vh; - - if (protocol == cpu_to_be16(ETH_P_8021Q)) { - - vh = (struct vlan_ethhdr *)skb->data; - protocol = vh->h_vlan_encapsulated_proto; - flags = FLAGS_VLAN_TAGGED; - - } else if (vlan_tx_tag_present(skb)) { - - flags = FLAGS_VLAN_OOB; - vid = vlan_tx_tag_get(skb); - netxen_set_tx_vlan_tci(first_desc, vid); - vlan_oob = 1; - } - - if ((netdev->features & (NETIF_F_TSO | NETIF_F_TSO6)) && - skb_shinfo(skb)->gso_size > 0) { - - hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb); - - first_desc->mss = cpu_to_le16(skb_shinfo(skb)->gso_size); - first_desc->total_hdr_length = hdr_len; - if (vlan_oob) { - first_desc->total_hdr_length += VLAN_HLEN; - first_desc->tcp_hdr_offset = VLAN_HLEN; - first_desc->ip_hdr_offset = VLAN_HLEN; - /* Only in case of TSO on vlan device */ - flags |= FLAGS_VLAN_TAGGED; - } - - opcode = (protocol == cpu_to_be16(ETH_P_IPV6)) ? - TX_TCP_LSO6 : TX_TCP_LSO; - tso = 1; - - } else if (skb->ip_summed == CHECKSUM_PARTIAL) { - u8 l4proto; - - if (protocol == cpu_to_be16(ETH_P_IP)) { - l4proto = ip_hdr(skb)->protocol; - - if (l4proto == IPPROTO_TCP) - opcode = TX_TCP_PKT; - else if(l4proto == IPPROTO_UDP) - opcode = TX_UDP_PKT; - } else if (protocol == cpu_to_be16(ETH_P_IPV6)) { - l4proto = ipv6_hdr(skb)->nexthdr; - - if (l4proto == IPPROTO_TCP) - opcode = TX_TCPV6_PKT; - else if(l4proto == IPPROTO_UDP) - opcode = TX_UDPV6_PKT; - } - } - - first_desc->tcp_hdr_offset += skb_transport_offset(skb); - first_desc->ip_hdr_offset += skb_network_offset(skb); - netxen_set_tx_flags_opcode(first_desc, flags, opcode); - - if (!tso) - return; - - /* For LSO, we need to copy the MAC/IP/TCP headers into - * the descriptor ring - */ - producer = tx_ring->producer; - copied = 0; - offset = 2; - - if (vlan_oob) { - /* Create a TSO vlan header template for firmware */ - - hwdesc = &tx_ring->desc_head[producer]; - tx_ring->cmd_buf_arr[producer].skb = NULL; - - copy_len = min((int)sizeof(struct cmd_desc_type0) - offset, - hdr_len + VLAN_HLEN); - - vh = (struct vlan_ethhdr *)((char *)hwdesc + 2); - skb_copy_from_linear_data(skb, vh, 12); - vh->h_vlan_proto = htons(ETH_P_8021Q); - vh->h_vlan_TCI = htons(vid); - skb_copy_from_linear_data_offset(skb, 12, - (char *)vh + 16, copy_len - 16); - - copied = copy_len - VLAN_HLEN; - offset = 0; - - producer = get_next_index(producer, tx_ring->num_desc); - } - - while (copied < hdr_len) { - - copy_len = min((int)sizeof(struct cmd_desc_type0) - offset, - (hdr_len - copied)); - - hwdesc = &tx_ring->desc_head[producer]; - tx_ring->cmd_buf_arr[producer].skb = NULL; - - skb_copy_from_linear_data_offset(skb, copied, - (char *)hwdesc + offset, copy_len); - - copied += copy_len; - offset = 0; - - producer = get_next_index(producer, tx_ring->num_desc); - } - - tx_ring->producer = producer; - barrier(); -} - -static int -netxen_map_tx_skb(struct pci_dev *pdev, - struct sk_buff *skb, struct netxen_cmd_buffer *pbuf) -{ - struct netxen_skb_frag *nf; - struct skb_frag_struct *frag; - int i, nr_frags; - dma_addr_t map; - - nr_frags = skb_shinfo(skb)->nr_frags; - nf = &pbuf->frag_array[0]; - - map = pci_map_single(pdev, skb->data, - skb_headlen(skb), PCI_DMA_TODEVICE); - if (pci_dma_mapping_error(pdev, map)) - goto out_err; - - nf->dma = map; - nf->length = skb_headlen(skb); - - for (i = 0; i < nr_frags; i++) { - frag = &skb_shinfo(skb)->frags[i]; - nf = &pbuf->frag_array[i+1]; - - map = pci_map_page(pdev, frag->page, frag->page_offset, - frag->size, PCI_DMA_TODEVICE); - if (pci_dma_mapping_error(pdev, map)) - goto unwind; - - nf->dma = map; - nf->length = frag->size; - } - - return 0; - -unwind: - while (--i >= 0) { - nf = &pbuf->frag_array[i+1]; - pci_unmap_page(pdev, nf->dma, nf->length, PCI_DMA_TODEVICE); - } - - nf = &pbuf->frag_array[0]; - pci_unmap_single(pdev, nf->dma, skb_headlen(skb), PCI_DMA_TODEVICE); - -out_err: - return -ENOMEM; -} - -static inline void -netxen_clear_cmddesc(u64 *desc) -{ - desc[0] = 0ULL; - desc[2] = 0ULL; -} - -static netdev_tx_t -netxen_nic_xmit_frame(struct sk_buff *skb, struct net_device *netdev) -{ - struct netxen_adapter *adapter = netdev_priv(netdev); - struct nx_host_tx_ring *tx_ring = adapter->tx_ring; - struct netxen_cmd_buffer *pbuf; - struct netxen_skb_frag *buffrag; - struct cmd_desc_type0 *hwdesc, *first_desc; - struct pci_dev *pdev; - int i, k; - int delta = 0; - struct skb_frag_struct *frag; - - u32 producer; - int frag_count, no_of_desc; - u32 num_txd = tx_ring->num_desc; - - frag_count = skb_shinfo(skb)->nr_frags + 1; - - /* 14 frags supported for normal packet and - * 32 frags supported for TSO packet - */ - if (!skb_is_gso(skb) && frag_count > NETXEN_MAX_FRAGS_PER_TX) { - - for (i = 0; i < (frag_count - NETXEN_MAX_FRAGS_PER_TX); i++) { - frag = &skb_shinfo(skb)->frags[i]; - delta += frag->size; - } - - if (!__pskb_pull_tail(skb, delta)) - goto drop_packet; - - frag_count = 1 + skb_shinfo(skb)->nr_frags; - } - /* 4 fragments per cmd des */ - no_of_desc = (frag_count + 3) >> 2; - - if (unlikely(netxen_tx_avail(tx_ring) <= TX_STOP_THRESH)) { - netif_stop_queue(netdev); - smp_mb(); - if (netxen_tx_avail(tx_ring) > TX_STOP_THRESH) - netif_start_queue(netdev); - else - return NETDEV_TX_BUSY; - } - - producer = tx_ring->producer; - pbuf = &tx_ring->cmd_buf_arr[producer]; - - pdev = adapter->pdev; - - if (netxen_map_tx_skb(pdev, skb, pbuf)) - goto drop_packet; - - pbuf->skb = skb; - pbuf->frag_count = frag_count; - - first_desc = hwdesc = &tx_ring->desc_head[producer]; - netxen_clear_cmddesc((u64 *)hwdesc); - - netxen_set_tx_frags_len(first_desc, frag_count, skb->len); - netxen_set_tx_port(first_desc, adapter->portnum); - - for (i = 0; i < frag_count; i++) { - - k = i % 4; - - if ((k == 0) && (i > 0)) { - /* move to next desc.*/ - producer = get_next_index(producer, num_txd); - hwdesc = &tx_ring->desc_head[producer]; - netxen_clear_cmddesc((u64 *)hwdesc); - tx_ring->cmd_buf_arr[producer].skb = NULL; - } - - buffrag = &pbuf->frag_array[i]; - - hwdesc->buffer_length[k] = cpu_to_le16(buffrag->length); - switch (k) { - case 0: - hwdesc->addr_buffer1 = cpu_to_le64(buffrag->dma); - break; - case 1: - hwdesc->addr_buffer2 = cpu_to_le64(buffrag->dma); - break; - case 2: - hwdesc->addr_buffer3 = cpu_to_le64(buffrag->dma); - break; - case 3: - hwdesc->addr_buffer4 = cpu_to_le64(buffrag->dma); - break; - } - } - - tx_ring->producer = get_next_index(producer, num_txd); - - netxen_tso_check(netdev, tx_ring, first_desc, skb); - - adapter->stats.txbytes += skb->len; - adapter->stats.xmitcalled++; - - netxen_nic_update_cmd_producer(adapter, tx_ring); - - return NETDEV_TX_OK; - -drop_packet: - adapter->stats.txdropped++; - dev_kfree_skb_any(skb); - return NETDEV_TX_OK; -} - -static int netxen_nic_check_temp(struct netxen_adapter *adapter) -{ - struct net_device *netdev = adapter->netdev; - uint32_t temp, temp_state, temp_val; - int rv = 0; - - temp = NXRD32(adapter, CRB_TEMP_STATE); - - temp_state = nx_get_temp_state(temp); - temp_val = nx_get_temp_val(temp); - - if (temp_state == NX_TEMP_PANIC) { - printk(KERN_ALERT - "%s: Device temperature %d degrees C exceeds" - " maximum allowed. Hardware has been shut down.\n", - netdev->name, temp_val); - rv = 1; - } else if (temp_state == NX_TEMP_WARN) { - if (adapter->temp == NX_TEMP_NORMAL) { - printk(KERN_ALERT - "%s: Device temperature %d degrees C " - "exceeds operating range." - " Immediate action needed.\n", - netdev->name, temp_val); - } - } else { - if (adapter->temp == NX_TEMP_WARN) { - printk(KERN_INFO - "%s: Device temperature is now %d degrees C" - " in normal range.\n", netdev->name, - temp_val); - } - } - adapter->temp = temp_state; - return rv; -} - -void netxen_advert_link_change(struct netxen_adapter *adapter, int linkup) -{ - struct net_device *netdev = adapter->netdev; - - if (adapter->ahw.linkup && !linkup) { - printk(KERN_INFO "%s: %s NIC Link is down\n", - netxen_nic_driver_name, netdev->name); - adapter->ahw.linkup = 0; - if (netif_running(netdev)) { - netif_carrier_off(netdev); - netif_stop_queue(netdev); - } - adapter->link_changed = !adapter->has_link_events; - } else if (!adapter->ahw.linkup && linkup) { - printk(KERN_INFO "%s: %s NIC Link is up\n", - netxen_nic_driver_name, netdev->name); - adapter->ahw.linkup = 1; - if (netif_running(netdev)) { - netif_carrier_on(netdev); - netif_wake_queue(netdev); - } - adapter->link_changed = !adapter->has_link_events; - } -} - -static void netxen_nic_handle_phy_intr(struct netxen_adapter *adapter) -{ - u32 val, port, linkup; - - port = adapter->physical_port; - - if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) { - val = NXRD32(adapter, CRB_XG_STATE_P3); - val = XG_LINK_STATE_P3(adapter->ahw.pci_func, val); - linkup = (val == XG_LINK_UP_P3); - } else { - val = NXRD32(adapter, CRB_XG_STATE); - val = (val >> port*8) & 0xff; - linkup = (val == XG_LINK_UP); - } - - netxen_advert_link_change(adapter, linkup); -} - -static void netxen_tx_timeout(struct net_device *netdev) -{ - struct netxen_adapter *adapter = netdev_priv(netdev); - - if (test_bit(__NX_RESETTING, &adapter->state)) - return; - - dev_err(&netdev->dev, "transmit timeout, resetting.\n"); - schedule_work(&adapter->tx_timeout_task); -} - -static void netxen_tx_timeout_task(struct work_struct *work) -{ - struct netxen_adapter *adapter = - container_of(work, struct netxen_adapter, tx_timeout_task); - - if (!netif_running(adapter->netdev)) - return; - - if (test_and_set_bit(__NX_RESETTING, &adapter->state)) - return; - - if (++adapter->tx_timeo_cnt >= NX_MAX_TX_TIMEOUTS) - goto request_reset; - - rtnl_lock(); - if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) { - /* try to scrub interrupt */ - netxen_napi_disable(adapter); - - netxen_napi_enable(adapter); - - netif_wake_queue(adapter->netdev); - - clear_bit(__NX_RESETTING, &adapter->state); - } else { - clear_bit(__NX_RESETTING, &adapter->state); - if (netxen_nic_reset_context(adapter)) { - rtnl_unlock(); - goto request_reset; - } - } - adapter->netdev->trans_start = jiffies; - rtnl_unlock(); - return; - -request_reset: - adapter->need_fw_reset = 1; - clear_bit(__NX_RESETTING, &adapter->state); -} - -static struct rtnl_link_stats64 *netxen_nic_get_stats(struct net_device *netdev, - struct rtnl_link_stats64 *stats) -{ - struct netxen_adapter *adapter = netdev_priv(netdev); - - stats->rx_packets = adapter->stats.rx_pkts + adapter->stats.lro_pkts; - stats->tx_packets = adapter->stats.xmitfinished; - stats->rx_bytes = adapter->stats.rxbytes; - stats->tx_bytes = adapter->stats.txbytes; - stats->rx_dropped = adapter->stats.rxdropped; - stats->tx_dropped = adapter->stats.txdropped; - - return stats; -} - -static irqreturn_t netxen_intr(int irq, void *data) -{ - struct nx_host_sds_ring *sds_ring = data; - struct netxen_adapter *adapter = sds_ring->adapter; - u32 status = 0; - - status = readl(adapter->isr_int_vec); - - if (!(status & adapter->int_vec_bit)) - return IRQ_NONE; - - if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) { - /* check interrupt state machine, to be sure */ - status = readl(adapter->crb_int_state_reg); - if (!ISR_LEGACY_INT_TRIGGERED(status)) - return IRQ_NONE; - - } else { - unsigned long our_int = 0; - - our_int = readl(adapter->crb_int_state_reg); - - /* not our interrupt */ - if (!test_and_clear_bit((7 + adapter->portnum), &our_int)) - return IRQ_NONE; - - /* claim interrupt */ - writel((our_int & 0xffffffff), adapter->crb_int_state_reg); - - /* clear interrupt */ - netxen_nic_disable_int(sds_ring); - } - - writel(0xffffffff, adapter->tgt_status_reg); - /* read twice to ensure write is flushed */ - readl(adapter->isr_int_vec); - readl(adapter->isr_int_vec); - - napi_schedule(&sds_ring->napi); - - return IRQ_HANDLED; -} - -static irqreturn_t netxen_msi_intr(int irq, void *data) -{ - struct nx_host_sds_ring *sds_ring = data; - struct netxen_adapter *adapter = sds_ring->adapter; - - /* clear interrupt */ - writel(0xffffffff, adapter->tgt_status_reg); - - napi_schedule(&sds_ring->napi); - return IRQ_HANDLED; -} - -static irqreturn_t netxen_msix_intr(int irq, void *data) -{ - struct nx_host_sds_ring *sds_ring = data; - - napi_schedule(&sds_ring->napi); - return IRQ_HANDLED; -} - -static int netxen_nic_poll(struct napi_struct *napi, int budget) -{ - struct nx_host_sds_ring *sds_ring = - container_of(napi, struct nx_host_sds_ring, napi); - - struct netxen_adapter *adapter = sds_ring->adapter; - - int tx_complete; - int work_done; - - tx_complete = netxen_process_cmd_ring(adapter); - - work_done = netxen_process_rcv_ring(sds_ring, budget); - - if ((work_done < budget) && tx_complete) { - napi_complete(&sds_ring->napi); - if (test_bit(__NX_DEV_UP, &adapter->state)) - netxen_nic_enable_int(sds_ring); - } - - return work_done; -} - -#ifdef CONFIG_NET_POLL_CONTROLLER -static void netxen_nic_poll_controller(struct net_device *netdev) -{ - int ring; - struct nx_host_sds_ring *sds_ring; - struct netxen_adapter *adapter = netdev_priv(netdev); - struct netxen_recv_context *recv_ctx = &adapter->recv_ctx; - - disable_irq(adapter->irq); - for (ring = 0; ring < adapter->max_sds_rings; ring++) { - sds_ring = &recv_ctx->sds_rings[ring]; - netxen_intr(adapter->irq, sds_ring); - } - enable_irq(adapter->irq); -} -#endif - -static int -nx_incr_dev_ref_cnt(struct netxen_adapter *adapter) -{ - int count; - if (netxen_api_lock(adapter)) - return -EIO; - - count = NXRD32(adapter, NX_CRB_DEV_REF_COUNT); - - NXWR32(adapter, NX_CRB_DEV_REF_COUNT, ++count); - - netxen_api_unlock(adapter); - return count; -} - -static int -nx_decr_dev_ref_cnt(struct netxen_adapter *adapter) -{ - int count; - if (netxen_api_lock(adapter)) - return -EIO; - - count = NXRD32(adapter, NX_CRB_DEV_REF_COUNT); - WARN_ON(count == 0); - - NXWR32(adapter, NX_CRB_DEV_REF_COUNT, --count); - - if (count == 0) - NXWR32(adapter, NX_CRB_DEV_STATE, NX_DEV_COLD); - - netxen_api_unlock(adapter); - return count; -} - -static int -nx_dev_request_aer(struct netxen_adapter *adapter) -{ - u32 state; - int ret = -EINVAL; - - if (netxen_api_lock(adapter)) - return ret; - - state = NXRD32(adapter, NX_CRB_DEV_STATE); - - if (state == NX_DEV_NEED_AER) - ret = 0; - else if (state == NX_DEV_READY) { - NXWR32(adapter, NX_CRB_DEV_STATE, NX_DEV_NEED_AER); - ret = 0; - } - - netxen_api_unlock(adapter); - return ret; -} - -static int -nx_dev_request_reset(struct netxen_adapter *adapter) -{ - u32 state; - int ret = -EINVAL; - - if (netxen_api_lock(adapter)) - return ret; - - state = NXRD32(adapter, NX_CRB_DEV_STATE); - - if (state == NX_DEV_NEED_RESET) - ret = 0; - else if (state != NX_DEV_INITALIZING && state != NX_DEV_NEED_AER) { - NXWR32(adapter, NX_CRB_DEV_STATE, NX_DEV_NEED_RESET); - ret = 0; - } - - netxen_api_unlock(adapter); - - return ret; -} - -static int -netxen_can_start_firmware(struct netxen_adapter *adapter) -{ - int count; - int can_start = 0; - - if (netxen_api_lock(adapter)) - return 0; - - count = NXRD32(adapter, NX_CRB_DEV_REF_COUNT); - - if ((count < 0) || (count >= NX_MAX_PCI_FUNC)) - count = 0; - - if (count == 0) { - can_start = 1; - NXWR32(adapter, NX_CRB_DEV_STATE, NX_DEV_INITALIZING); - } - - NXWR32(adapter, NX_CRB_DEV_REF_COUNT, ++count); - - netxen_api_unlock(adapter); - - return can_start; -} - -static void -netxen_schedule_work(struct netxen_adapter *adapter, - work_func_t func, int delay) -{ - INIT_DELAYED_WORK(&adapter->fw_work, func); - schedule_delayed_work(&adapter->fw_work, delay); -} - -static void -netxen_cancel_fw_work(struct netxen_adapter *adapter) -{ - while (test_and_set_bit(__NX_RESETTING, &adapter->state)) - msleep(10); - - cancel_delayed_work_sync(&adapter->fw_work); -} - -static void -netxen_attach_work(struct work_struct *work) -{ - struct netxen_adapter *adapter = container_of(work, - struct netxen_adapter, fw_work.work); - struct net_device *netdev = adapter->netdev; - int err = 0; - - if (netif_running(netdev)) { - err = netxen_nic_attach(adapter); - if (err) - goto done; - - err = netxen_nic_up(adapter, netdev); - if (err) { - netxen_nic_detach(adapter); - goto done; - } - - netxen_restore_indev_addr(netdev, NETDEV_UP); - } - - netif_device_attach(netdev); - -done: - adapter->fw_fail_cnt = 0; - clear_bit(__NX_RESETTING, &adapter->state); - netxen_schedule_work(adapter, netxen_fw_poll_work, FW_POLL_DELAY); -} - -static void -netxen_fwinit_work(struct work_struct *work) -{ - struct netxen_adapter *adapter = container_of(work, - struct netxen_adapter, fw_work.work); - int dev_state; - - dev_state = NXRD32(adapter, NX_CRB_DEV_STATE); - - switch (dev_state) { - case NX_DEV_COLD: - case NX_DEV_READY: - if (!netxen_start_firmware(adapter)) { - netxen_schedule_work(adapter, netxen_attach_work, 0); - return; - } - break; - - case NX_DEV_NEED_RESET: - case NX_DEV_INITALIZING: - if (++adapter->fw_wait_cnt < FW_POLL_THRESH) { - netxen_schedule_work(adapter, - netxen_fwinit_work, 2 * FW_POLL_DELAY); - return; - } - - case NX_DEV_FAILED: - default: - nx_incr_dev_ref_cnt(adapter); - break; - } - - clear_bit(__NX_RESETTING, &adapter->state); -} - -static void -netxen_detach_work(struct work_struct *work) -{ - struct netxen_adapter *adapter = container_of(work, - struct netxen_adapter, fw_work.work); - struct net_device *netdev = adapter->netdev; - int ref_cnt, delay; - u32 status; - - netif_device_detach(netdev); - - netxen_nic_down(adapter, netdev); - - rtnl_lock(); - netxen_nic_detach(adapter); - rtnl_unlock(); - - status = NXRD32(adapter, NETXEN_PEG_HALT_STATUS1); - - if (status & NX_RCODE_FATAL_ERROR) - goto err_ret; - - if (adapter->temp == NX_TEMP_PANIC) - goto err_ret; - - ref_cnt = nx_decr_dev_ref_cnt(adapter); - - if (ref_cnt == -EIO) - goto err_ret; - - delay = (ref_cnt == 0) ? 0 : (2 * FW_POLL_DELAY); - - adapter->fw_wait_cnt = 0; - netxen_schedule_work(adapter, netxen_fwinit_work, delay); - - return; - -err_ret: - clear_bit(__NX_RESETTING, &adapter->state); -} - -static int -netxen_check_health(struct netxen_adapter *adapter) -{ - u32 state, heartbit; - struct net_device *netdev = adapter->netdev; - - state = NXRD32(adapter, NX_CRB_DEV_STATE); - if (state == NX_DEV_NEED_AER) - return 0; - - if (netxen_nic_check_temp(adapter)) - goto detach; - - if (adapter->need_fw_reset) { - if (nx_dev_request_reset(adapter)) - return 0; - goto detach; - } - - /* NX_DEV_NEED_RESET, this state can be marked in two cases - * 1. Tx timeout 2. Fw hang - * Send request to destroy context in case of tx timeout only - * and doesn't required in case of Fw hang - */ - if (state == NX_DEV_NEED_RESET) { - adapter->need_fw_reset = 1; - if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) - goto detach; - } - - if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) - return 0; - - heartbit = NXRD32(adapter, NETXEN_PEG_ALIVE_COUNTER); - if (heartbit != adapter->heartbit) { - adapter->heartbit = heartbit; - adapter->fw_fail_cnt = 0; - if (adapter->need_fw_reset) - goto detach; - return 0; - } - - if (++adapter->fw_fail_cnt < FW_FAIL_THRESH) - return 0; - - if (nx_dev_request_reset(adapter)) - return 0; - - clear_bit(__NX_FW_ATTACHED, &adapter->state); - - dev_info(&netdev->dev, "firmware hang detected\n"); - -detach: - if ((auto_fw_reset == AUTO_FW_RESET_ENABLED) && - !test_and_set_bit(__NX_RESETTING, &adapter->state)) - netxen_schedule_work(adapter, netxen_detach_work, 0); - return 1; -} - -static void -netxen_fw_poll_work(struct work_struct *work) -{ - struct netxen_adapter *adapter = container_of(work, - struct netxen_adapter, fw_work.work); - - if (test_bit(__NX_RESETTING, &adapter->state)) - goto reschedule; - - if (test_bit(__NX_DEV_UP, &adapter->state)) { - if (!adapter->has_link_events) { - - netxen_nic_handle_phy_intr(adapter); - - if (adapter->link_changed) - netxen_nic_set_link_parameters(adapter); - } - } - - if (netxen_check_health(adapter)) - return; - -reschedule: - netxen_schedule_work(adapter, netxen_fw_poll_work, FW_POLL_DELAY); -} - -static ssize_t -netxen_store_bridged_mode(struct device *dev, - struct device_attribute *attr, const char *buf, size_t len) -{ - struct net_device *net = to_net_dev(dev); - struct netxen_adapter *adapter = netdev_priv(net); - unsigned long new; - int ret = -EINVAL; - - if (!(adapter->capabilities & NX_FW_CAPABILITY_BDG)) - goto err_out; - - if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC) - goto err_out; - - if (strict_strtoul(buf, 2, &new)) - goto err_out; - - if (!netxen_config_bridged_mode(adapter, !!new)) - ret = len; - -err_out: - return ret; -} - -static ssize_t -netxen_show_bridged_mode(struct device *dev, - struct device_attribute *attr, char *buf) -{ - struct net_device *net = to_net_dev(dev); - struct netxen_adapter *adapter; - int bridged_mode = 0; - - adapter = netdev_priv(net); - - if (adapter->capabilities & NX_FW_CAPABILITY_BDG) - bridged_mode = !!(adapter->flags & NETXEN_NIC_BRIDGE_ENABLED); - - return sprintf(buf, "%d\n", bridged_mode); -} - -static struct device_attribute dev_attr_bridged_mode = { - .attr = {.name = "bridged_mode", .mode = (S_IRUGO | S_IWUSR)}, - .show = netxen_show_bridged_mode, - .store = netxen_store_bridged_mode, -}; - -static ssize_t -netxen_store_diag_mode(struct device *dev, - struct device_attribute *attr, const char *buf, size_t len) -{ - struct netxen_adapter *adapter = dev_get_drvdata(dev); - unsigned long new; - - if (strict_strtoul(buf, 2, &new)) - return -EINVAL; - - if (!!new != !!(adapter->flags & NETXEN_NIC_DIAG_ENABLED)) - adapter->flags ^= NETXEN_NIC_DIAG_ENABLED; - - return len; -} - -static ssize_t -netxen_show_diag_mode(struct device *dev, - struct device_attribute *attr, char *buf) -{ - struct netxen_adapter *adapter = dev_get_drvdata(dev); - - return sprintf(buf, "%d\n", - !!(adapter->flags & NETXEN_NIC_DIAG_ENABLED)); -} - -static struct device_attribute dev_attr_diag_mode = { - .attr = {.name = "diag_mode", .mode = (S_IRUGO | S_IWUSR)}, - .show = netxen_show_diag_mode, - .store = netxen_store_diag_mode, -}; - -static int -netxen_sysfs_validate_crb(struct netxen_adapter *adapter, - loff_t offset, size_t size) -{ - size_t crb_size = 4; - - if (!(adapter->flags & NETXEN_NIC_DIAG_ENABLED)) - return -EIO; - - if (offset < NETXEN_PCI_CRBSPACE) { - if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) - return -EINVAL; - - if (ADDR_IN_RANGE(offset, NETXEN_PCI_CAMQM, - NETXEN_PCI_CAMQM_2M_END)) - crb_size = 8; - else - return -EINVAL; - } - - if ((size != crb_size) || (offset & (crb_size-1))) - return -EINVAL; - - return 0; -} - -static ssize_t -netxen_sysfs_read_crb(struct file *filp, struct kobject *kobj, - struct bin_attribute *attr, - char *buf, loff_t offset, size_t size) -{ - struct device *dev = container_of(kobj, struct device, kobj); - struct netxen_adapter *adapter = dev_get_drvdata(dev); - u32 data; - u64 qmdata; - int ret; - - ret = netxen_sysfs_validate_crb(adapter, offset, size); - if (ret != 0) - return ret; - - if (NX_IS_REVISION_P3(adapter->ahw.revision_id) && - ADDR_IN_RANGE(offset, NETXEN_PCI_CAMQM, - NETXEN_PCI_CAMQM_2M_END)) { - netxen_pci_camqm_read_2M(adapter, offset, &qmdata); - memcpy(buf, &qmdata, size); - } else { - data = NXRD32(adapter, offset); - memcpy(buf, &data, size); - } - - return size; -} - -static ssize_t -netxen_sysfs_write_crb(struct file *filp, struct kobject *kobj, - struct bin_attribute *attr, - char *buf, loff_t offset, size_t size) -{ - struct device *dev = container_of(kobj, struct device, kobj); - struct netxen_adapter *adapter = dev_get_drvdata(dev); - u32 data; - u64 qmdata; - int ret; - - ret = netxen_sysfs_validate_crb(adapter, offset, size); - if (ret != 0) - return ret; - - if (NX_IS_REVISION_P3(adapter->ahw.revision_id) && - ADDR_IN_RANGE(offset, NETXEN_PCI_CAMQM, - NETXEN_PCI_CAMQM_2M_END)) { - memcpy(&qmdata, buf, size); - netxen_pci_camqm_write_2M(adapter, offset, qmdata); - } else { - memcpy(&data, buf, size); - NXWR32(adapter, offset, data); - } - - return size; -} - -static int -netxen_sysfs_validate_mem(struct netxen_adapter *adapter, - loff_t offset, size_t size) -{ - if (!(adapter->flags & NETXEN_NIC_DIAG_ENABLED)) - return -EIO; - - if ((size != 8) || (offset & 0x7)) - return -EIO; - - return 0; -} - -static ssize_t -netxen_sysfs_read_mem(struct file *filp, struct kobject *kobj, - struct bin_attribute *attr, - char *buf, loff_t offset, size_t size) -{ - struct device *dev = container_of(kobj, struct device, kobj); - struct netxen_adapter *adapter = dev_get_drvdata(dev); - u64 data; - int ret; - - ret = netxen_sysfs_validate_mem(adapter, offset, size); - if (ret != 0) - return ret; - - if (adapter->pci_mem_read(adapter, offset, &data)) - return -EIO; - - memcpy(buf, &data, size); - - return size; -} - -static ssize_t netxen_sysfs_write_mem(struct file *filp, struct kobject *kobj, - struct bin_attribute *attr, char *buf, - loff_t offset, size_t size) -{ - struct device *dev = container_of(kobj, struct device, kobj); - struct netxen_adapter *adapter = dev_get_drvdata(dev); - u64 data; - int ret; - - ret = netxen_sysfs_validate_mem(adapter, offset, size); - if (ret != 0) - return ret; - - memcpy(&data, buf, size); - - if (adapter->pci_mem_write(adapter, offset, data)) - return -EIO; - - return size; -} - - -static struct bin_attribute bin_attr_crb = { - .attr = {.name = "crb", .mode = (S_IRUGO | S_IWUSR)}, - .size = 0, - .read = netxen_sysfs_read_crb, - .write = netxen_sysfs_write_crb, -}; - -static struct bin_attribute bin_attr_mem = { - .attr = {.name = "mem", .mode = (S_IRUGO | S_IWUSR)}, - .size = 0, - .read = netxen_sysfs_read_mem, - .write = netxen_sysfs_write_mem, -}; - - -static void -netxen_create_sysfs_entries(struct netxen_adapter *adapter) -{ - struct net_device *netdev = adapter->netdev; - struct device *dev = &netdev->dev; - - if (adapter->capabilities & NX_FW_CAPABILITY_BDG) { - /* bridged_mode control */ - if (device_create_file(dev, &dev_attr_bridged_mode)) { - dev_warn(&netdev->dev, - "failed to create bridged_mode sysfs entry\n"); - } - } -} - -static void -netxen_remove_sysfs_entries(struct netxen_adapter *adapter) -{ - struct net_device *netdev = adapter->netdev; - struct device *dev = &netdev->dev; - - if (adapter->capabilities & NX_FW_CAPABILITY_BDG) - device_remove_file(dev, &dev_attr_bridged_mode); -} - -static void -netxen_create_diag_entries(struct netxen_adapter *adapter) -{ - struct pci_dev *pdev = adapter->pdev; - struct device *dev; - - dev = &pdev->dev; - if (device_create_file(dev, &dev_attr_diag_mode)) - dev_info(dev, "failed to create diag_mode sysfs entry\n"); - if (device_create_bin_file(dev, &bin_attr_crb)) - dev_info(dev, "failed to create crb sysfs entry\n"); - if (device_create_bin_file(dev, &bin_attr_mem)) - dev_info(dev, "failed to create mem sysfs entry\n"); -} - - -static void -netxen_remove_diag_entries(struct netxen_adapter *adapter) -{ - struct pci_dev *pdev = adapter->pdev; - struct device *dev = &pdev->dev; - - device_remove_file(dev, &dev_attr_diag_mode); - device_remove_bin_file(dev, &bin_attr_crb); - device_remove_bin_file(dev, &bin_attr_mem); -} - -#ifdef CONFIG_INET - -#define is_netxen_netdev(dev) (dev->netdev_ops == &netxen_netdev_ops) - -static int -netxen_destip_supported(struct netxen_adapter *adapter) -{ - if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) - return 0; - - if (adapter->ahw.cut_through) - return 0; - - return 1; -} - -static void -netxen_free_vlan_ip_list(struct netxen_adapter *adapter) -{ - struct nx_vlan_ip_list *cur; - struct list_head *head = &adapter->vlan_ip_list; - - while (!list_empty(head)) { - cur = list_entry(head->next, struct nx_vlan_ip_list, list); - netxen_config_ipaddr(adapter, cur->ip_addr, NX_IP_DOWN); - list_del(&cur->list); - kfree(cur); - } - -} -static void -netxen_list_config_vlan_ip(struct netxen_adapter *adapter, - struct in_ifaddr *ifa, unsigned long event) -{ - struct net_device *dev; - struct nx_vlan_ip_list *cur, *tmp_cur; - struct list_head *head; - - dev = ifa->ifa_dev ? ifa->ifa_dev->dev : NULL; - - if (dev == NULL) - return; - - if (!is_vlan_dev(dev)) - return; - - switch (event) { - case NX_IP_UP: - list_for_each(head, &adapter->vlan_ip_list) { - cur = list_entry(head, struct nx_vlan_ip_list, list); - - if (cur->ip_addr == ifa->ifa_address) - return; - } - - cur = kzalloc(sizeof(struct nx_vlan_ip_list), GFP_ATOMIC); - if (cur == NULL) { - printk(KERN_ERR "%s: failed to add vlan ip to list\n", - adapter->netdev->name); - return; - } - - cur->ip_addr = ifa->ifa_address; - list_add_tail(&cur->list, &adapter->vlan_ip_list); - break; - case NX_IP_DOWN: - list_for_each_entry_safe(cur, tmp_cur, - &adapter->vlan_ip_list, list) { - if (cur->ip_addr == ifa->ifa_address) { - list_del(&cur->list); - kfree(cur); - break; - } - } - } -} -static void -netxen_config_indev_addr(struct netxen_adapter *adapter, - struct net_device *dev, unsigned long event) -{ - struct in_device *indev; - - if (!netxen_destip_supported(adapter)) - return; - - indev = in_dev_get(dev); - if (!indev) - return; - - for_ifa(indev) { - switch (event) { - case NETDEV_UP: - netxen_config_ipaddr(adapter, - ifa->ifa_address, NX_IP_UP); - netxen_list_config_vlan_ip(adapter, ifa, NX_IP_UP); - break; - case NETDEV_DOWN: - netxen_config_ipaddr(adapter, - ifa->ifa_address, NX_IP_DOWN); - netxen_list_config_vlan_ip(adapter, ifa, NX_IP_DOWN); - break; - default: - break; - } - } endfor_ifa(indev); - - in_dev_put(indev); -} - -static void -netxen_restore_indev_addr(struct net_device *netdev, unsigned long event) - -{ - struct netxen_adapter *adapter = netdev_priv(netdev); - struct nx_vlan_ip_list *pos, *tmp_pos; - unsigned long ip_event; - - ip_event = (event == NETDEV_UP) ? NX_IP_UP : NX_IP_DOWN; - netxen_config_indev_addr(adapter, netdev, event); - - list_for_each_entry_safe(pos, tmp_pos, &adapter->vlan_ip_list, list) { - netxen_config_ipaddr(adapter, pos->ip_addr, ip_event); - } -} - -static int netxen_netdev_event(struct notifier_block *this, - unsigned long event, void *ptr) -{ - struct netxen_adapter *adapter; - struct net_device *dev = (struct net_device *)ptr; - struct net_device *orig_dev = dev; - -recheck: - if (dev == NULL) - goto done; - - if (dev->priv_flags & IFF_802_1Q_VLAN) { - dev = vlan_dev_real_dev(dev); - goto recheck; - } - - if (!is_netxen_netdev(dev)) - goto done; - - adapter = netdev_priv(dev); - - if (!adapter) - goto done; - - if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC) - goto done; - - netxen_config_indev_addr(adapter, orig_dev, event); -done: - return NOTIFY_DONE; -} - -static int -netxen_inetaddr_event(struct notifier_block *this, - unsigned long event, void *ptr) -{ - struct netxen_adapter *adapter; - struct net_device *dev; - - struct in_ifaddr *ifa = (struct in_ifaddr *)ptr; - - dev = ifa->ifa_dev ? ifa->ifa_dev->dev : NULL; - -recheck: - if (dev == NULL) - goto done; - - if (dev->priv_flags & IFF_802_1Q_VLAN) { - dev = vlan_dev_real_dev(dev); - goto recheck; - } - - if (!is_netxen_netdev(dev)) - goto done; - - adapter = netdev_priv(dev); - - if (!adapter || !netxen_destip_supported(adapter)) - goto done; - - if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC) - goto done; - - switch (event) { - case NETDEV_UP: - netxen_config_ipaddr(adapter, ifa->ifa_address, NX_IP_UP); - netxen_list_config_vlan_ip(adapter, ifa, NX_IP_UP); - break; - case NETDEV_DOWN: - netxen_config_ipaddr(adapter, ifa->ifa_address, NX_IP_DOWN); - netxen_list_config_vlan_ip(adapter, ifa, NX_IP_DOWN); - break; - default: - break; - } - -done: - return NOTIFY_DONE; -} - -static struct notifier_block netxen_netdev_cb = { - .notifier_call = netxen_netdev_event, -}; - -static struct notifier_block netxen_inetaddr_cb = { - .notifier_call = netxen_inetaddr_event, -}; -#else -static void -netxen_restore_indev_addr(struct net_device *dev, unsigned long event) -{ } -static void -netxen_free_vlan_ip_list(struct netxen_adapter *adapter) -{ } -#endif - -static struct pci_error_handlers netxen_err_handler = { - .error_detected = netxen_io_error_detected, - .slot_reset = netxen_io_slot_reset, - .resume = netxen_io_resume, -}; - -static struct pci_driver netxen_driver = { - .name = netxen_nic_driver_name, - .id_table = netxen_pci_tbl, - .probe = netxen_nic_probe, - .remove = __devexit_p(netxen_nic_remove), -#ifdef CONFIG_PM - .suspend = netxen_nic_suspend, - .resume = netxen_nic_resume, -#endif - .shutdown = netxen_nic_shutdown, - .err_handler = &netxen_err_handler -}; - -static int __init netxen_init_module(void) -{ - printk(KERN_INFO "%s\n", netxen_nic_driver_string); - -#ifdef CONFIG_INET - register_netdevice_notifier(&netxen_netdev_cb); - register_inetaddr_notifier(&netxen_inetaddr_cb); -#endif - return pci_register_driver(&netxen_driver); -} - -module_init(netxen_init_module); - -static void __exit netxen_exit_module(void) -{ - pci_unregister_driver(&netxen_driver); - -#ifdef CONFIG_INET - unregister_inetaddr_notifier(&netxen_inetaddr_cb); - unregister_netdevice_notifier(&netxen_netdev_cb); -#endif -} - -module_exit(netxen_exit_module); |