175ab5f91Slh155975 /* 2*da14cebeSEric Cheng * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 375ab5f91Slh155975 * Use is subject to license terms. 475ab5f91Slh155975 */ 575ab5f91Slh155975 675ab5f91Slh155975 #ifndef AMD8111S_MAIN_H 775ab5f91Slh155975 #define AMD8111S_MAIN_H 875ab5f91Slh155975 975ab5f91Slh155975 /* 1075ab5f91Slh155975 * Copyright (c) 2001-2006 Advanced Micro Devices, Inc. All rights reserved. 1175ab5f91Slh155975 * 1275ab5f91Slh155975 * Redistribution and use in source and binary forms, with or without 1375ab5f91Slh155975 * modification, are permitted provided that the following conditions are met: 1475ab5f91Slh155975 * 1575ab5f91Slh155975 * + Redistributions of source code must retain the above copyright notice, 1675ab5f91Slh155975 * + this list of conditions and the following disclaimer. 1775ab5f91Slh155975 * 1875ab5f91Slh155975 * + Redistributions in binary form must reproduce the above copyright 1975ab5f91Slh155975 * + notice, this list of conditions and the following disclaimer in the 2075ab5f91Slh155975 * + documentation and/or other materials provided with the distribution. 2175ab5f91Slh155975 * 2275ab5f91Slh155975 * + Neither the name of Advanced Micro Devices, Inc. nor the names of its 2375ab5f91Slh155975 * + contributors may be used to endorse or promote products derived from 2475ab5f91Slh155975 * + this software without specific prior written permission. 2575ab5f91Slh155975 * 2675ab5f91Slh155975 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 2775ab5f91Slh155975 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 2875ab5f91Slh155975 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 2975ab5f91Slh155975 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 3075ab5f91Slh155975 * DISCLAIMED. IN NO EVENT SHALL ADVANCED MICRO DEVICES, INC. OR 3175ab5f91Slh155975 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 3275ab5f91Slh155975 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 3375ab5f91Slh155975 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 3475ab5f91Slh155975 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 3575ab5f91Slh155975 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 3675ab5f91Slh155975 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 3775ab5f91Slh155975 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 3875ab5f91Slh155975 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 3975ab5f91Slh155975 * 4075ab5f91Slh155975 * Import/Export/Re-Export/Use/Release/Transfer Restrictions and 4175ab5f91Slh155975 * Compliance with Applicable Laws. Notice is hereby given that 4275ab5f91Slh155975 * the software may be subject to restrictions on use, release, 4375ab5f91Slh155975 * transfer, importation, exportation and/or re-exportation under 4475ab5f91Slh155975 * the laws and regulations of the United States or other 4575ab5f91Slh155975 * countries ("Applicable Laws"), which include but are not 4675ab5f91Slh155975 * limited to U.S. export control laws such as the Export 4775ab5f91Slh155975 * Administration Regulations and national security controls as 4875ab5f91Slh155975 * defined thereunder, as well as State Department controls under 4975ab5f91Slh155975 * the U.S. Munitions List. Permission to use and/or 5075ab5f91Slh155975 * redistribute the software is conditioned upon compliance with 5175ab5f91Slh155975 * all Applicable Laws, including U.S. export control laws 5275ab5f91Slh155975 * regarding specifically designated persons, countries and 5375ab5f91Slh155975 * nationals of countries subject to national security controls. 5475ab5f91Slh155975 */ 5575ab5f91Slh155975 5675ab5f91Slh155975 #include <sys/types.h> 5775ab5f91Slh155975 #include <sys/errno.h> 5875ab5f91Slh155975 #include <sys/kmem.h> 5975ab5f91Slh155975 #include <sys/conf.h> 6075ab5f91Slh155975 #include <sys/stat.h> 6175ab5f91Slh155975 #include <sys/note.h> 6275ab5f91Slh155975 #include <sys/modctl.h> 6375ab5f91Slh155975 6475ab5f91Slh155975 #include <sys/stream.h> 6575ab5f91Slh155975 #include <sys/strsubr.h> 6675ab5f91Slh155975 #include <sys/strsun.h> 6775ab5f91Slh155975 6875ab5f91Slh155975 #include <sys/dditypes.h> 6975ab5f91Slh155975 #include <sys/ddi.h> 7075ab5f91Slh155975 #include <sys/sunddi.h> 7175ab5f91Slh155975 7275ab5f91Slh155975 #include <sys/pci.h> 7375ab5f91Slh155975 7475ab5f91Slh155975 #include <sys/ethernet.h> 7575ab5f91Slh155975 #include <sys/dlpi.h> 76*da14cebeSEric Cheng #include <sys/mac_provider.h> 7775ab5f91Slh155975 #include <sys/mac_ether.h> 7875ab5f91Slh155975 #include <sys/netlb.h> 7975ab5f91Slh155975 #include "amd8111s_hw.h" 8075ab5f91Slh155975 8175ab5f91Slh155975 #define MEM_REQ_MAX 100 8275ab5f91Slh155975 #define MEMSET 4 8375ab5f91Slh155975 8475ab5f91Slh155975 #define IOC_LINESIZE 40 8575ab5f91Slh155975 8675ab5f91Slh155975 /* 8775ab5f91Slh155975 * Loopback definitions 8875ab5f91Slh155975 */ 8975ab5f91Slh155975 #define AMD8111S_LB_NONE 0 9075ab5f91Slh155975 #define AMD8111S_LB_EXTERNAL_1000 1 9175ab5f91Slh155975 #define AMD8111S_LB_EXTERNAL_100 2 9275ab5f91Slh155975 #define AMD8111S_LB_EXTERNAL_10 3 9375ab5f91Slh155975 #define AMD8111S_LB_INTERNAL_PHY 4 9475ab5f91Slh155975 #define AMD8111S_LB_INTERNAL_MAC 5 9575ab5f91Slh155975 9675ab5f91Slh155975 /* ((2 ^ (32 - 1)) * 8) / (10 ^ 8) >= 100 */ 9775ab5f91Slh155975 #define AMD8111S_DUMP_MIB_SECONDS_THRESHOLD 100 9875ab5f91Slh155975 #define AMD8111S_DUMP_MIB_BYTES_THRESHOLD 0x80000000 9975ab5f91Slh155975 10075ab5f91Slh155975 /* Bit flags for 'attach_progress' */ 10175ab5f91Slh155975 #define AMD8111S_ATTACH_PCI 0x0001 /* pci_config_setup() */ 10275ab5f91Slh155975 #define AMD8111S_ATTACH_RESOURCE 0x0002 /* odlInit() */ 10375ab5f91Slh155975 #define AMD8111S_ATTACH_REGS 0x0004 /* ddi_regs_map_setup() */ 10475ab5f91Slh155975 #define AMD8111S_ATTACH_INTRADDED 0x0010 /* intr_add() */ 10575ab5f91Slh155975 #define AMD8111S_ATTACH_MACREGED 0x0020 /* mac_register() */ 10675ab5f91Slh155975 #define AMD8111S_ATTACH_RESCHED 0x0040 /* soft_intr() */ 10775ab5f91Slh155975 10875ab5f91Slh155975 #define AMD8111S_TRY_SEND 0x0001 10975ab5f91Slh155975 #define AMD8111S_SEND_READY 0x0002 11075ab5f91Slh155975 11175ab5f91Slh155975 #define NEXT(buf, ptr) \ 11275ab5f91Slh155975 (buf.ptr + 1 >= buf.msg_buf + \ 11375ab5f91Slh155975 buf.ring_size ? \ 11475ab5f91Slh155975 buf.msg_buf : \ 11575ab5f91Slh155975 buf.ptr + 1) 11675ab5f91Slh155975 /* 11775ab5f91Slh155975 * (Internal) return values from ioctl subroutines 11875ab5f91Slh155975 */ 11975ab5f91Slh155975 enum ioc_reply { 12075ab5f91Slh155975 IOC_INVAL = -1, /* bad, NAK with EINVAL */ 12175ab5f91Slh155975 IOC_DONE, /* OK, reply sent */ 12275ab5f91Slh155975 IOC_ACK, /* OK, just send ACK */ 12375ab5f91Slh155975 IOC_REPLY, /* OK, just send reply */ 12475ab5f91Slh155975 IOC_RESTART_ACK, /* OK, restart & ACK */ 12575ab5f91Slh155975 IOC_RESTART_REPLY /* OK, restart & reply */ 12675ab5f91Slh155975 }; 12775ab5f91Slh155975 12875ab5f91Slh155975 typedef int (*TIMERfUNC) (struct LayerPointers *); 12975ab5f91Slh155975 13075ab5f91Slh155975 struct TimerStructure { 13175ab5f91Slh155975 int Type; 13275ab5f91Slh155975 int Period; /* in milliseconds */ 13375ab5f91Slh155975 timeout_id_t TimerHandle; 13475ab5f91Slh155975 int (*TimerFunptr)(struct LayerPointers *); 13575ab5f91Slh155975 struct LayerPointers *pLayerPointers; 13675ab5f91Slh155975 }; 13775ab5f91Slh155975 13875ab5f91Slh155975 struct amd8111s_statistics 13975ab5f91Slh155975 { 14075ab5f91Slh155975 uint64_t intr_TINT0; /* # of TINT0 (Tx interrupts) */ 14175ab5f91Slh155975 uint64_t intr_RINT0; /* # of RINT0 (Rx interrupts) */ 14275ab5f91Slh155975 uint64_t intr_STINT; /* # of STINT (Software Timer Intr) */ 14375ab5f91Slh155975 uint64_t intr_OTHER; /* Intr caused by other device */ 14475ab5f91Slh155975 14575ab5f91Slh155975 uint64_t tx_ok_packets; 14675ab5f91Slh155975 uint64_t tx_no_descriptor; 14775ab5f91Slh155975 uint64_t tx_no_buffer; 14875ab5f91Slh155975 uint64_t tx_rescheduled; 14975ab5f91Slh155975 uint64_t tx_unrescheduled; 15075ab5f91Slh155975 15175ab5f91Slh155975 /* # of call amd8111s_dump_mib function */ 15275ab5f91Slh155975 uint64_t mib_dump_counter; 15375ab5f91Slh155975 15475ab5f91Slh155975 /* 15575ab5f91Slh155975 * From MIB registers (TX) 15675ab5f91Slh155975 */ 15775ab5f91Slh155975 uint64_t tx_mib_packets; /* # of packets */ 15875ab5f91Slh155975 uint64_t tx_mib_multicst_packets; /* # of multicast packets */ 15975ab5f91Slh155975 uint64_t tx_mib_broadcst_packets; /* # of broadcast packets */ 16075ab5f91Slh155975 uint64_t tx_mib_flowctrl_packets; /* # of flow ctrl packets */ 16175ab5f91Slh155975 16275ab5f91Slh155975 uint64_t tx_mib_bytes; /* # of all Tx bytes */ 16375ab5f91Slh155975 16475ab5f91Slh155975 /* Packet drop due to Tx FIFO underrun */ 16575ab5f91Slh155975 uint64_t tx_mib_underrun_packets; 16675ab5f91Slh155975 uint64_t tx_mib_collision_packets; 16775ab5f91Slh155975 /* Packets successfully transmitted after experiencing one collision */ 16875ab5f91Slh155975 uint64_t tx_mib_one_coll_packets; 16975ab5f91Slh155975 uint64_t tx_mib_multi_coll_packets; 17075ab5f91Slh155975 /* # of late collisions that occur */ 17175ab5f91Slh155975 uint64_t tx_mib_late_coll_packets; 17275ab5f91Slh155975 uint64_t tx_mib_ex_coll_packets; /* excessive collision */ 17375ab5f91Slh155975 uint64_t tx_mib_oversize_packets; 17475ab5f91Slh155975 uint64_t tx_mib_defer_trans_packets; /* defer transmit */ 17575ab5f91Slh155975 17675ab5f91Slh155975 17775ab5f91Slh155975 /* 17875ab5f91Slh155975 * Some error counter after "ifconfig amd8111sX unplumb" 17975ab5f91Slh155975 */ 18075ab5f91Slh155975 /* 18175ab5f91Slh155975 * Count Tx mp number from GLD even after NIC has been unplumbed. 18275ab5f91Slh155975 * This value should always be 0. 18375ab5f91Slh155975 */ 18475ab5f91Slh155975 uint64_t tx_afterunplumb; 18575ab5f91Slh155975 /* 18675ab5f91Slh155975 * We drain all pending tx packets during unplumb operation. This 18775ab5f91Slh155975 * variable is to count the drain time. 18875ab5f91Slh155975 * 30 means success; =30 means fail 18975ab5f91Slh155975 */ 19075ab5f91Slh155975 uint64_t tx_draintime; 19175ab5f91Slh155975 19275ab5f91Slh155975 uint64_t rx_ok_packets; /* # of all good packets */ 19375ab5f91Slh155975 uint64_t rx_allocfail; /* alloc memory fail during Rx */ 19475ab5f91Slh155975 uint64_t rx_error_zerosize; 19575ab5f91Slh155975 19675ab5f91Slh155975 uint64_t rx_0_packets; 19775ab5f91Slh155975 uint64_t rx_1_15_packets; 19875ab5f91Slh155975 uint64_t rx_16_31_packets; 19975ab5f91Slh155975 uint64_t rx_32_47_packets; 20075ab5f91Slh155975 uint64_t rx_48_63_packets; 20175ab5f91Slh155975 uint64_t rx_double_overflow; 20275ab5f91Slh155975 20375ab5f91Slh155975 uint64_t rx_desc_err; 20475ab5f91Slh155975 uint64_t rx_desc_err_FRAM; /* Framing error */ 20575ab5f91Slh155975 uint64_t rx_desc_err_OFLO; /* Overflow error */ 20675ab5f91Slh155975 uint64_t rx_desc_err_CRC; /* CRC error */ 20775ab5f91Slh155975 uint64_t rx_desc_err_BUFF; /* BCRC error */ 20875ab5f91Slh155975 20975ab5f91Slh155975 /* 21075ab5f91Slh155975 * From MIB registers (RX) 21175ab5f91Slh155975 */ 21275ab5f91Slh155975 uint64_t rx_mib_unicst_packets; /* # of unicast packets */ 21375ab5f91Slh155975 uint64_t rx_mib_multicst_packets; /* # of multicast packets */ 21475ab5f91Slh155975 uint64_t rx_mib_broadcst_packets; /* # of broadcast packets */ 21575ab5f91Slh155975 uint64_t rx_mib_macctrl_packets; /* # of mac ctrl packets */ 21675ab5f91Slh155975 uint64_t rx_mib_flowctrl_packets; /* # of flow ctrl packets */ 21775ab5f91Slh155975 21875ab5f91Slh155975 uint64_t rx_mib_bytes; /* # of all Rx bytes */ 21975ab5f91Slh155975 uint64_t rx_mib_good_bytes; /* # of all Rx bytes */ 22075ab5f91Slh155975 /* 22175ab5f91Slh155975 * The total number of valid frames received that are less than 64 22275ab5f91Slh155975 * bytes long (include the FCS). 22375ab5f91Slh155975 */ 22475ab5f91Slh155975 uint64_t rx_mib_undersize_packets; 22575ab5f91Slh155975 /* 22675ab5f91Slh155975 * The total number of valid frames received that are greater than the 22775ab5f91Slh155975 * maximum valid frame size (include the FCS). 22875ab5f91Slh155975 */ 22975ab5f91Slh155975 uint64_t rx_mib_oversize_packets; 23075ab5f91Slh155975 23175ab5f91Slh155975 uint64_t rx_mib_align_err_packets; 23275ab5f91Slh155975 uint64_t rx_mib_fcs_err_packets; /* has a bad FCS */ 23375ab5f91Slh155975 /* Invalid data symbol (RX_ER) */ 23475ab5f91Slh155975 uint64_t rx_mib_symbol_err_packets; 23575ab5f91Slh155975 /* Packets that were dropped because no descriptor was available */ 23675ab5f91Slh155975 uint64_t rx_mib_drop_packets; 23775ab5f91Slh155975 /* 23875ab5f91Slh155975 * Packets that were dropped due to lack of resources. This includes 23975ab5f91Slh155975 * the number of times a packet was dropped due to receive FIFO 24075ab5f91Slh155975 * overflow and lack of receive descriptor. 24175ab5f91Slh155975 */ 24275ab5f91Slh155975 uint64_t rx_mib_miss_packets; 24375ab5f91Slh155975 }; 24475ab5f91Slh155975 24575ab5f91Slh155975 struct amd8111s_msgbuf { 24675ab5f91Slh155975 uint64_t phy_addr; 24775ab5f91Slh155975 caddr_t vir_addr; 24875ab5f91Slh155975 uint32_t msg_size; 24975ab5f91Slh155975 ddi_dma_handle_t p_hdl; 25075ab5f91Slh155975 uint32_t offset; 25175ab5f91Slh155975 }; 25275ab5f91Slh155975 25375ab5f91Slh155975 struct amd8111s_dma_ringbuf { 25475ab5f91Slh155975 ddi_dma_handle_t *dma_hdl; 25575ab5f91Slh155975 ddi_acc_handle_t *acc_hdl; 25675ab5f91Slh155975 ddi_dma_cookie_t *dma_cookie; 25775ab5f91Slh155975 caddr_t *trunk_addr; 25875ab5f91Slh155975 uint32_t buf_sz; 25975ab5f91Slh155975 uint32_t trunk_sz; 26075ab5f91Slh155975 uint32_t trunk_num; 26175ab5f91Slh155975 struct amd8111s_msgbuf *msg_buf; 26275ab5f91Slh155975 uint32_t ring_size; 26375ab5f91Slh155975 uint32_t dma_buf_sz; 26475ab5f91Slh155975 struct amd8111s_msgbuf *free; 26575ab5f91Slh155975 struct amd8111s_msgbuf *next; 26675ab5f91Slh155975 struct amd8111s_msgbuf *curr; 26775ab5f91Slh155975 26875ab5f91Slh155975 kmutex_t ring_lock; 26975ab5f91Slh155975 }; 27075ab5f91Slh155975 27175ab5f91Slh155975 struct odl { 27275ab5f91Slh155975 dev_info_t *devinfo; 27375ab5f91Slh155975 27475ab5f91Slh155975 mac_handle_t mh; /* mac module handle */ 27575ab5f91Slh155975 27675ab5f91Slh155975 struct amd8111s_statistics statistics; 27775ab5f91Slh155975 27875ab5f91Slh155975 /* Locks */ 27975ab5f91Slh155975 kmutex_t mdlSendLock; 28075ab5f91Slh155975 kmutex_t mdlRcvLock; 28175ab5f91Slh155975 kmutex_t timer_lock; 28275ab5f91Slh155975 kmutex_t send_cv_lock; 28375ab5f91Slh155975 kcondvar_t send_cv; 28475ab5f91Slh155975 28575ab5f91Slh155975 ddi_softintr_t drain_id; 28675ab5f91Slh155975 /* 28775ab5f91Slh155975 * The chip_lock assures that the Rx/Tx process must be stopped while 28875ab5f91Slh155975 * other functions change the hardware configuration, such as attach() 28975ab5f91Slh155975 * detach() etc are executed. 29075ab5f91Slh155975 */ 29175ab5f91Slh155975 krwlock_t chip_lock; 29275ab5f91Slh155975 29375ab5f91Slh155975 /* 29475ab5f91Slh155975 * HW operators and parameters on attach period 29575ab5f91Slh155975 */ 29675ab5f91Slh155975 ddi_iblock_cookie_t iblock; /* HW: interrupt block cookie */ 29775ab5f91Slh155975 ddi_acc_handle_t MemBasehandle; 29875ab5f91Slh155975 29975ab5f91Slh155975 /* For pci configuration */ 30075ab5f91Slh155975 ddi_acc_handle_t pci_handle; /* HW: access handle of PCI space */ 30175ab5f91Slh155975 uint16_t vendor_id; 30275ab5f91Slh155975 uint16_t device_id; 30375ab5f91Slh155975 30475ab5f91Slh155975 /* 30575ab5f91Slh155975 * FreeQ: Transfer Rx Buffer parameters from top layer to low layers. 30675ab5f91Slh155975 * Format of parameter: 30775ab5f91Slh155975 * (struct RxBufInfo *, physical address) 30875ab5f91Slh155975 */ 30975ab5f91Slh155975 unsigned long FreeQ[2 * RX_RING_SIZE]; 31075ab5f91Slh155975 unsigned long *FreeQStart; 31175ab5f91Slh155975 unsigned long *FreeQEnd; 31275ab5f91Slh155975 long *FreeQWrite; 31375ab5f91Slh155975 long *FreeQRead; 31475ab5f91Slh155975 31575ab5f91Slh155975 /* For Rx descriptors */ 31675ab5f91Slh155975 ddi_dma_handle_t rx_desc_dma_handle; 31775ab5f91Slh155975 ddi_acc_handle_t rx_desc_acc_handle; 31875ab5f91Slh155975 ddi_dma_cookie_t rx_desc_dma_cookie; 31975ab5f91Slh155975 32075ab5f91Slh155975 /* For Tx descriptors */ 32175ab5f91Slh155975 ddi_dma_handle_t tx_desc_dma_handle; 32275ab5f91Slh155975 ddi_acc_handle_t tx_desc_acc_handle; 32375ab5f91Slh155975 ddi_dma_cookie_t tx_desc_dma_cookie; 32475ab5f91Slh155975 32575ab5f91Slh155975 /* For Tx buffers */ 32675ab5f91Slh155975 struct amd8111s_dma_ringbuf tx_buf; 32775ab5f91Slh155975 32875ab5f91Slh155975 /* For Rx buffers */ 32975ab5f91Slh155975 struct amd8111s_dma_ringbuf rx_buf; 33075ab5f91Slh155975 33175ab5f91Slh155975 ether_addr_t MacAddress; /* Mac address */ 33275ab5f91Slh155975 33375ab5f91Slh155975 /* Multicast addresses table */ 33475ab5f91Slh155975 UCHAR MulticastAddresses 33575ab5f91Slh155975 [MAX_MULTICAST_ADDRESSES][ETH_LENGTH_OF_ADDRESS]; 33675ab5f91Slh155975 33775ab5f91Slh155975 link_state_t LinkStatus; 33875ab5f91Slh155975 33975ab5f91Slh155975 /* Timer */ 34075ab5f91Slh155975 timeout_id_t Timer_id; 34175ab5f91Slh155975 int (*TimerFunc)(struct LayerPointers *); 34275ab5f91Slh155975 int timer_run; 34375ab5f91Slh155975 int timer_linkdown; 34475ab5f91Slh155975 34575ab5f91Slh155975 unsigned int dump_mib_seconds; 34675ab5f91Slh155975 34775ab5f91Slh155975 uint32_t loopback_mode; 34875ab5f91Slh155975 unsigned int rx_fcs_stripped; 34975ab5f91Slh155975 35075ab5f91Slh155975 unsigned int rx_overflow_counter; 35175ab5f91Slh155975 unsigned int pause_interval; 35275ab5f91Slh155975 35375ab5f91Slh155975 }; 35475ab5f91Slh155975 35575ab5f91Slh155975 #endif /* AMD8111S_MAIN_H */ 356