xref: /onnv-gate/usr/src/uts/intel/io/amd8111s/amd8111s_main.h (revision 8275:7c223a798022)
15256Slh155975 /*
2*8275SEric Cheng  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
35256Slh155975  * Use is subject to license terms.
45256Slh155975  */
55256Slh155975 
65256Slh155975 #ifndef AMD8111S_MAIN_H
75256Slh155975 #define	AMD8111S_MAIN_H
85256Slh155975 
95256Slh155975 /*
105256Slh155975  * Copyright (c) 2001-2006 Advanced Micro Devices, Inc.  All rights reserved.
115256Slh155975  *
125256Slh155975  * Redistribution and use in source and binary forms, with or without
135256Slh155975  * modification, are permitted provided that the following conditions are met:
145256Slh155975  *
155256Slh155975  * + Redistributions of source code must retain the above copyright notice,
165256Slh155975  * + this list of conditions and the following disclaimer.
175256Slh155975  *
185256Slh155975  * + Redistributions in binary form must reproduce the above copyright
195256Slh155975  * + notice, this list of conditions and the following disclaimer in the
205256Slh155975  * + documentation and/or other materials provided with the distribution.
215256Slh155975  *
225256Slh155975  * + Neither the name of Advanced Micro Devices, Inc. nor the names of its
235256Slh155975  * + contributors may be used to endorse or promote products derived from
245256Slh155975  * + this software without specific prior written permission.
255256Slh155975  *
265256Slh155975  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
275256Slh155975  * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
285256Slh155975  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
295256Slh155975  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
305256Slh155975  * DISCLAIMED. IN NO EVENT SHALL ADVANCED MICRO DEVICES, INC. OR
315256Slh155975  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
325256Slh155975  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
335256Slh155975  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
345256Slh155975  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
355256Slh155975  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
365256Slh155975  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
375256Slh155975  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
385256Slh155975  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
395256Slh155975  *
405256Slh155975  * Import/Export/Re-Export/Use/Release/Transfer Restrictions and
415256Slh155975  * Compliance with Applicable Laws.  Notice is hereby given that
425256Slh155975  * the software may be subject to restrictions on use, release,
435256Slh155975  * transfer, importation, exportation and/or re-exportation under
445256Slh155975  * the laws and regulations of the United States or other
455256Slh155975  * countries ("Applicable Laws"), which include but are not
465256Slh155975  * limited to U.S. export control laws such as the Export
475256Slh155975  * Administration Regulations and national security controls as
485256Slh155975  * defined thereunder, as well as State Department controls under
495256Slh155975  * the U.S. Munitions List.  Permission to use and/or
505256Slh155975  * redistribute the software is conditioned upon compliance with
515256Slh155975  * all Applicable Laws, including U.S. export control laws
525256Slh155975  * regarding specifically designated persons, countries and
535256Slh155975  * nationals of countries subject to national security controls.
545256Slh155975  */
555256Slh155975 
565256Slh155975 #include <sys/types.h>
575256Slh155975 #include <sys/errno.h>
585256Slh155975 #include <sys/kmem.h>
595256Slh155975 #include <sys/conf.h>
605256Slh155975 #include <sys/stat.h>
615256Slh155975 #include <sys/note.h>
625256Slh155975 #include <sys/modctl.h>
635256Slh155975 
645256Slh155975 #include <sys/stream.h>
655256Slh155975 #include <sys/strsubr.h>
665256Slh155975 #include <sys/strsun.h>
675256Slh155975 
685256Slh155975 #include <sys/dditypes.h>
695256Slh155975 #include <sys/ddi.h>
705256Slh155975 #include <sys/sunddi.h>
715256Slh155975 
725256Slh155975 #include <sys/pci.h>
735256Slh155975 
745256Slh155975 #include <sys/ethernet.h>
755256Slh155975 #include <sys/dlpi.h>
76*8275SEric Cheng #include <sys/mac_provider.h>
775256Slh155975 #include <sys/mac_ether.h>
785256Slh155975 #include <sys/netlb.h>
795256Slh155975 #include "amd8111s_hw.h"
805256Slh155975 
815256Slh155975 #define	MEM_REQ_MAX		100
825256Slh155975 #define	MEMSET			4
835256Slh155975 
845256Slh155975 #define	IOC_LINESIZE	40
855256Slh155975 
865256Slh155975 /*
875256Slh155975  * Loopback definitions
885256Slh155975  */
895256Slh155975 #define	AMD8111S_LB_NONE			0
905256Slh155975 #define	AMD8111S_LB_EXTERNAL_1000		1
915256Slh155975 #define	AMD8111S_LB_EXTERNAL_100		2
925256Slh155975 #define	AMD8111S_LB_EXTERNAL_10			3
935256Slh155975 #define	AMD8111S_LB_INTERNAL_PHY		4
945256Slh155975 #define	AMD8111S_LB_INTERNAL_MAC		5
955256Slh155975 
965256Slh155975 /* ((2 ^ (32 - 1)) * 8) / (10 ^ 8) >= 100 */
975256Slh155975 #define	AMD8111S_DUMP_MIB_SECONDS_THRESHOLD	100
985256Slh155975 #define	AMD8111S_DUMP_MIB_BYTES_THRESHOLD	0x80000000
995256Slh155975 
1005256Slh155975 /* Bit flags for 'attach_progress' */
1015256Slh155975 #define	AMD8111S_ATTACH_PCI		0x0001	/* pci_config_setup() */
1025256Slh155975 #define	AMD8111S_ATTACH_RESOURCE	0x0002	/* odlInit() */
1035256Slh155975 #define	AMD8111S_ATTACH_REGS		0x0004	/* ddi_regs_map_setup() */
1045256Slh155975 #define	AMD8111S_ATTACH_INTRADDED	0x0010	/* intr_add() */
1055256Slh155975 #define	AMD8111S_ATTACH_MACREGED	0x0020	/* mac_register() */
1065256Slh155975 #define	AMD8111S_ATTACH_RESCHED		0x0040	/* soft_intr() */
1075256Slh155975 
1085256Slh155975 #define	AMD8111S_TRY_SEND		0x0001
1095256Slh155975 #define	AMD8111S_SEND_READY		0x0002
1105256Slh155975 
1115256Slh155975 #define	NEXT(buf, ptr) \
1125256Slh155975 	(buf.ptr + 1 >= buf.msg_buf + \
1135256Slh155975 	buf.ring_size ? \
1145256Slh155975 	buf.msg_buf : \
1155256Slh155975 	buf.ptr + 1)
1165256Slh155975 /*
1175256Slh155975  * (Internal) return values from ioctl subroutines
1185256Slh155975  */
1195256Slh155975 enum ioc_reply {
1205256Slh155975 	IOC_INVAL = -1,				/* bad, NAK with EINVAL	*/
1215256Slh155975 	IOC_DONE,				/* OK, reply sent	*/
1225256Slh155975 	IOC_ACK,				/* OK, just send ACK	*/
1235256Slh155975 	IOC_REPLY,				/* OK, just send reply	*/
1245256Slh155975 	IOC_RESTART_ACK,			/* OK, restart & ACK	*/
1255256Slh155975 	IOC_RESTART_REPLY			/* OK, restart & reply	*/
1265256Slh155975 };
1275256Slh155975 
1285256Slh155975 typedef int (*TIMERfUNC) (struct LayerPointers *);
1295256Slh155975 
1305256Slh155975 struct TimerStructure {
1315256Slh155975 	int Type;
1325256Slh155975 	int Period;	/* in milliseconds */
1335256Slh155975 	timeout_id_t TimerHandle;
1345256Slh155975 	int (*TimerFunptr)(struct LayerPointers *);
1355256Slh155975 	struct LayerPointers *pLayerPointers;
1365256Slh155975 };
1375256Slh155975 
1385256Slh155975 struct amd8111s_statistics
1395256Slh155975 {
1405256Slh155975 	uint64_t intr_TINT0;	/* # of TINT0 (Tx interrupts) */
1415256Slh155975 	uint64_t intr_RINT0;	/* # of RINT0 (Rx interrupts) */
1425256Slh155975 	uint64_t intr_STINT;	/* # of STINT (Software Timer Intr) */
1435256Slh155975 	uint64_t intr_OTHER;	/* Intr caused by other device */
1445256Slh155975 
1455256Slh155975 	uint64_t tx_ok_packets;
1465256Slh155975 	uint64_t tx_no_descriptor;
1475256Slh155975 	uint64_t tx_no_buffer;
1485256Slh155975 	uint64_t tx_rescheduled;
1495256Slh155975 	uint64_t tx_unrescheduled;
1505256Slh155975 
1515256Slh155975 	/* # of call amd8111s_dump_mib function */
1525256Slh155975 	uint64_t mib_dump_counter;
1535256Slh155975 
1545256Slh155975 	/*
1555256Slh155975 	 * From MIB registers (TX)
1565256Slh155975 	 */
1575256Slh155975 	uint64_t tx_mib_packets;		/* # of packets */
1585256Slh155975 	uint64_t tx_mib_multicst_packets;	/* # of multicast packets */
1595256Slh155975 	uint64_t tx_mib_broadcst_packets;	/* # of broadcast packets */
1605256Slh155975 	uint64_t tx_mib_flowctrl_packets;	/* # of flow ctrl packets */
1615256Slh155975 
1625256Slh155975 	uint64_t tx_mib_bytes;			/* # of all Tx bytes */
1635256Slh155975 
1645256Slh155975 	/* Packet drop due to Tx FIFO underrun */
1655256Slh155975 	uint64_t tx_mib_underrun_packets;
1665256Slh155975 	uint64_t tx_mib_collision_packets;
1675256Slh155975 	/* Packets successfully transmitted after experiencing one collision */
1685256Slh155975 	uint64_t tx_mib_one_coll_packets;
1695256Slh155975 	uint64_t tx_mib_multi_coll_packets;
1705256Slh155975 	/* # of late collisions that occur */
1715256Slh155975 	uint64_t tx_mib_late_coll_packets;
1725256Slh155975 	uint64_t tx_mib_ex_coll_packets;	/* excessive collision */
1735256Slh155975 	uint64_t tx_mib_oversize_packets;
1745256Slh155975 	uint64_t tx_mib_defer_trans_packets;	/* defer transmit */
1755256Slh155975 
1765256Slh155975 
1775256Slh155975 	/*
1785256Slh155975 	 * Some error counter after "ifconfig amd8111sX unplumb"
1795256Slh155975 	 */
1805256Slh155975 	/*
1815256Slh155975 	 * Count Tx mp number from GLD even after NIC has been unplumbed.
1825256Slh155975 	 * This value should always be 0.
1835256Slh155975 	 */
1845256Slh155975 	uint64_t tx_afterunplumb;
1855256Slh155975 	/*
1865256Slh155975 	 * We drain all pending tx packets during unplumb operation. This
1875256Slh155975 	 * variable is to count the drain time.
1885256Slh155975 	 *	30 means success; =30 means fail
1895256Slh155975 	 */
1905256Slh155975 	uint64_t tx_draintime;
1915256Slh155975 
1925256Slh155975 	uint64_t rx_ok_packets;		/* # of all good packets */
1935256Slh155975 	uint64_t rx_allocfail;		/* alloc memory fail during Rx */
1945256Slh155975 	uint64_t rx_error_zerosize;
1955256Slh155975 
1965256Slh155975 	uint64_t rx_0_packets;
1975256Slh155975 	uint64_t rx_1_15_packets;
1985256Slh155975 	uint64_t rx_16_31_packets;
1995256Slh155975 	uint64_t rx_32_47_packets;
2005256Slh155975 	uint64_t rx_48_63_packets;
2015256Slh155975 	uint64_t rx_double_overflow;
2025256Slh155975 
2035256Slh155975 	uint64_t rx_desc_err;
2045256Slh155975 	uint64_t rx_desc_err_FRAM;	/* Framing error */
2055256Slh155975 	uint64_t rx_desc_err_OFLO;	/* Overflow error */
2065256Slh155975 	uint64_t rx_desc_err_CRC;	/* CRC error */
2075256Slh155975 	uint64_t rx_desc_err_BUFF;	/* BCRC error */
2085256Slh155975 
2095256Slh155975 	/*
2105256Slh155975 	 * From MIB registers (RX)
2115256Slh155975 	 */
2125256Slh155975 	uint64_t rx_mib_unicst_packets;		/* # of unicast packets */
2135256Slh155975 	uint64_t rx_mib_multicst_packets;	/* # of multicast packets */
2145256Slh155975 	uint64_t rx_mib_broadcst_packets;	/* # of broadcast packets */
2155256Slh155975 	uint64_t rx_mib_macctrl_packets;	/* # of mac ctrl packets */
2165256Slh155975 	uint64_t rx_mib_flowctrl_packets;	/* # of flow ctrl packets */
2175256Slh155975 
2185256Slh155975 	uint64_t rx_mib_bytes;			/* # of all Rx bytes */
2195256Slh155975 	uint64_t rx_mib_good_bytes;			/* # of all Rx bytes */
2205256Slh155975 	/*
2215256Slh155975 	 * The total number of valid frames received that are less than 64
2225256Slh155975 	 * bytes long (include the FCS).
2235256Slh155975 	 */
2245256Slh155975 	uint64_t rx_mib_undersize_packets;
2255256Slh155975 	/*
2265256Slh155975 	 * The total number of valid frames received that are greater than the
2275256Slh155975 	 * maximum valid frame size (include the FCS).
2285256Slh155975 	 */
2295256Slh155975 	uint64_t rx_mib_oversize_packets;
2305256Slh155975 
2315256Slh155975 	uint64_t rx_mib_align_err_packets;
2325256Slh155975 	uint64_t rx_mib_fcs_err_packets;	/* has a bad FCS */
2335256Slh155975 	/* Invalid data symbol (RX_ER) */
2345256Slh155975 	uint64_t rx_mib_symbol_err_packets;
2355256Slh155975 	/* Packets that were dropped because no descriptor was available */
2365256Slh155975 	uint64_t rx_mib_drop_packets;
2375256Slh155975 	/*
2385256Slh155975 	 * Packets that were dropped due to lack of resources. This includes
2395256Slh155975 	 * the number of times a packet was dropped due to receive FIFO
2405256Slh155975 	 * overflow and lack of receive descriptor.
2415256Slh155975 	 */
2425256Slh155975 	uint64_t rx_mib_miss_packets;
2435256Slh155975 };
2445256Slh155975 
2455256Slh155975 struct amd8111s_msgbuf {
2465256Slh155975 	uint64_t phy_addr;
2475256Slh155975 	caddr_t vir_addr;
2485256Slh155975 	uint32_t msg_size;
2495256Slh155975 	ddi_dma_handle_t p_hdl;
2505256Slh155975 	uint32_t offset;
2515256Slh155975 };
2525256Slh155975 
2535256Slh155975 struct amd8111s_dma_ringbuf {
2545256Slh155975 	ddi_dma_handle_t *dma_hdl;
2555256Slh155975 	ddi_acc_handle_t *acc_hdl;
2565256Slh155975 	ddi_dma_cookie_t *dma_cookie;
2575256Slh155975 	caddr_t		 *trunk_addr;
2585256Slh155975 	uint32_t buf_sz;
2595256Slh155975 	uint32_t trunk_sz;
2605256Slh155975 	uint32_t trunk_num;
2615256Slh155975 	struct amd8111s_msgbuf	*msg_buf;
2625256Slh155975 	uint32_t ring_size;
2635256Slh155975 	uint32_t dma_buf_sz;
2645256Slh155975 	struct amd8111s_msgbuf *free;
2655256Slh155975 	struct amd8111s_msgbuf *next;
2665256Slh155975 	struct amd8111s_msgbuf *curr;
2675256Slh155975 
2685256Slh155975 	kmutex_t ring_lock;
2695256Slh155975 };
2705256Slh155975 
2715256Slh155975 struct odl {
2725256Slh155975 	dev_info_t *devinfo;
2735256Slh155975 
2745256Slh155975 	mac_handle_t mh;		/* mac module handle */
2755256Slh155975 
2765256Slh155975 	struct amd8111s_statistics statistics;
2775256Slh155975 
2785256Slh155975 	/* Locks */
2795256Slh155975 	kmutex_t mdlSendLock;
2805256Slh155975 	kmutex_t mdlRcvLock;
2815256Slh155975 	kmutex_t timer_lock;
2825256Slh155975 	kmutex_t send_cv_lock;
2835256Slh155975 	kcondvar_t send_cv;
2845256Slh155975 
2855256Slh155975 	ddi_softintr_t drain_id;
2865256Slh155975 	/*
2875256Slh155975 	 * The chip_lock assures that the Rx/Tx process must be stopped while
2885256Slh155975 	 * other functions change the hardware configuration, such as attach()
2895256Slh155975 	 * detach() etc are executed.
2905256Slh155975 	 */
2915256Slh155975 	krwlock_t chip_lock;
2925256Slh155975 
2935256Slh155975 	/*
2945256Slh155975 	 * HW operators and parameters on attach period
2955256Slh155975 	 */
2965256Slh155975 	ddi_iblock_cookie_t iblock;	/* HW: interrupt block cookie */
2975256Slh155975 	ddi_acc_handle_t MemBasehandle;
2985256Slh155975 
2995256Slh155975 	/* For pci configuration */
3005256Slh155975 	ddi_acc_handle_t pci_handle;	/* HW: access handle of PCI space */
3015256Slh155975 	uint16_t vendor_id;
3025256Slh155975 	uint16_t device_id;
3035256Slh155975 
3045256Slh155975 	/*
3055256Slh155975 	 * FreeQ: Transfer Rx Buffer parameters from top layer to low layers.
3065256Slh155975 	 * Format of parameter:
3075256Slh155975 	 *	(struct RxBufInfo *, physical address)
3085256Slh155975 	 */
3095256Slh155975 	unsigned long FreeQ[2 * RX_RING_SIZE];
3105256Slh155975 	unsigned long *FreeQStart;
3115256Slh155975 	unsigned long *FreeQEnd;
3125256Slh155975 	long *FreeQWrite;
3135256Slh155975 	long *FreeQRead;
3145256Slh155975 
3155256Slh155975 	/* For Rx descriptors */
3165256Slh155975 	ddi_dma_handle_t rx_desc_dma_handle;
3175256Slh155975 	ddi_acc_handle_t rx_desc_acc_handle;
3185256Slh155975 	ddi_dma_cookie_t rx_desc_dma_cookie;
3195256Slh155975 
3205256Slh155975 	/* For Tx descriptors */
3215256Slh155975 	ddi_dma_handle_t tx_desc_dma_handle;
3225256Slh155975 	ddi_acc_handle_t tx_desc_acc_handle;
3235256Slh155975 	ddi_dma_cookie_t tx_desc_dma_cookie;
3245256Slh155975 
3255256Slh155975 	/* For Tx buffers */
3265256Slh155975 	struct amd8111s_dma_ringbuf tx_buf;
3275256Slh155975 
3285256Slh155975 	/* For Rx buffers */
3295256Slh155975 	struct amd8111s_dma_ringbuf rx_buf;
3305256Slh155975 
3315256Slh155975 	ether_addr_t MacAddress;	/* Mac address */
3325256Slh155975 
3335256Slh155975 	/* Multicast addresses table */
3345256Slh155975 	UCHAR MulticastAddresses
3355256Slh155975 	    [MAX_MULTICAST_ADDRESSES][ETH_LENGTH_OF_ADDRESS];
3365256Slh155975 
3375256Slh155975 	link_state_t LinkStatus;
3385256Slh155975 
3395256Slh155975 	/* Timer */
3405256Slh155975 	timeout_id_t Timer_id;
3415256Slh155975 	int (*TimerFunc)(struct LayerPointers *);
3425256Slh155975 	int timer_run;
3435256Slh155975 	int timer_linkdown;
3445256Slh155975 
3455256Slh155975 	unsigned int dump_mib_seconds;
3465256Slh155975 
3475256Slh155975 	uint32_t loopback_mode;
3485256Slh155975 	unsigned int rx_fcs_stripped;
3495256Slh155975 
3505256Slh155975 	unsigned int rx_overflow_counter;
3515256Slh155975 	unsigned int pause_interval;
3525256Slh155975 
3535256Slh155975 };
3545256Slh155975 
3555256Slh155975 #endif	/* AMD8111S_MAIN_H */
356