1*10253Sxiuyan.wang@Sun.COM /* 2*10253Sxiuyan.wang@Sun.COM * CDDL HEADER START 3*10253Sxiuyan.wang@Sun.COM * 4*10253Sxiuyan.wang@Sun.COM * The contents of this file are subject to the terms of the 5*10253Sxiuyan.wang@Sun.COM * Common Development and Distribution License (the "License"). 6*10253Sxiuyan.wang@Sun.COM * You may not use this file except in compliance with the License. 7*10253Sxiuyan.wang@Sun.COM * 8*10253Sxiuyan.wang@Sun.COM * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9*10253Sxiuyan.wang@Sun.COM * or http://www.opensolaris.org/os/licensing. 10*10253Sxiuyan.wang@Sun.COM * See the License for the specific language governing permissions 11*10253Sxiuyan.wang@Sun.COM * and limitations under the License. 12*10253Sxiuyan.wang@Sun.COM * 13*10253Sxiuyan.wang@Sun.COM * When distributing Covered Code, include this CDDL HEADER in each 14*10253Sxiuyan.wang@Sun.COM * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15*10253Sxiuyan.wang@Sun.COM * If applicable, add the following below this CDDL HEADER, with the 16*10253Sxiuyan.wang@Sun.COM * fields enclosed by brackets "[]" replaced with your own identifying 17*10253Sxiuyan.wang@Sun.COM * information: Portions Copyright [yyyy] [name of copyright owner] 18*10253Sxiuyan.wang@Sun.COM * 19*10253Sxiuyan.wang@Sun.COM * CDDL HEADER END 20*10253Sxiuyan.wang@Sun.COM */ 21*10253Sxiuyan.wang@Sun.COM 22*10253Sxiuyan.wang@Sun.COM /* 23*10253Sxiuyan.wang@Sun.COM * Copyright 2007-2009 Myricom, Inc. All rights reserved. 24*10253Sxiuyan.wang@Sun.COM * Use is subject to license terms. 25*10253Sxiuyan.wang@Sun.COM */ 26*10253Sxiuyan.wang@Sun.COM 27*10253Sxiuyan.wang@Sun.COM #ifndef MYRI10GE_VAR_H 28*10253Sxiuyan.wang@Sun.COM #define MYRI10GE_VAR_H 29*10253Sxiuyan.wang@Sun.COM 30*10253Sxiuyan.wang@Sun.COM #ifdef __cplusplus 31*10253Sxiuyan.wang@Sun.COM extern "C" { 32*10253Sxiuyan.wang@Sun.COM #endif 33*10253Sxiuyan.wang@Sun.COM 34*10253Sxiuyan.wang@Sun.COM #include <sys/types.h> 35*10253Sxiuyan.wang@Sun.COM #include <sys/errno.h> 36*10253Sxiuyan.wang@Sun.COM #include <sys/param.h> 37*10253Sxiuyan.wang@Sun.COM #include <sys/atomic.h> 38*10253Sxiuyan.wang@Sun.COM #include <sys/stropts.h> 39*10253Sxiuyan.wang@Sun.COM #include <sys/stream.h> 40*10253Sxiuyan.wang@Sun.COM #include <sys/kmem.h> 41*10253Sxiuyan.wang@Sun.COM #include <sys/ksynch.h> 42*10253Sxiuyan.wang@Sun.COM #include <sys/stat.h> 43*10253Sxiuyan.wang@Sun.COM #include <sys/modctl.h> 44*10253Sxiuyan.wang@Sun.COM #include <sys/debug.h> 45*10253Sxiuyan.wang@Sun.COM #include <sys/dlpi.h> 46*10253Sxiuyan.wang@Sun.COM #include <sys/ethernet.h> 47*10253Sxiuyan.wang@Sun.COM #include <sys/mac_provider.h> 48*10253Sxiuyan.wang@Sun.COM #define MAC_CAPAB_POLL 0 49*10253Sxiuyan.wang@Sun.COM #define MC_RESOURCES 0 50*10253Sxiuyan.wang@Sun.COM #include <sys/mac_ether.h> 51*10253Sxiuyan.wang@Sun.COM #ifndef MYRICOM_PRIV 52*10253Sxiuyan.wang@Sun.COM #include <sys/vlan.h> 53*10253Sxiuyan.wang@Sun.COM #endif 54*10253Sxiuyan.wang@Sun.COM #include <sys/pci.h> 55*10253Sxiuyan.wang@Sun.COM #include <sys/pcie.h> 56*10253Sxiuyan.wang@Sun.COM #include <sys/ddi.h> 57*10253Sxiuyan.wang@Sun.COM #include <sys/sunddi.h> 58*10253Sxiuyan.wang@Sun.COM #include <sys/strsubr.h> /* for hw cksum stuff */ 59*10253Sxiuyan.wang@Sun.COM #include <sys/pattr.h> /* for hw cksum stuff */ 60*10253Sxiuyan.wang@Sun.COM #include <netinet/in.h> /* for hw cksum stuff */ 61*10253Sxiuyan.wang@Sun.COM #include <netinet/ip.h> /* for hw cksum stuff */ 62*10253Sxiuyan.wang@Sun.COM #include <netinet/ip6.h> /* for hw cksum stuff */ 63*10253Sxiuyan.wang@Sun.COM #include <netinet/tcp.h> /* for hw cksum stuff */ 64*10253Sxiuyan.wang@Sun.COM #include <netinet/udp.h> /* for hw cksum stuff */ 65*10253Sxiuyan.wang@Sun.COM #include <sys/strsun.h> 66*10253Sxiuyan.wang@Sun.COM #include <inet/common.h> 67*10253Sxiuyan.wang@Sun.COM #include <inet/mi.h> 68*10253Sxiuyan.wang@Sun.COM #include <inet/nd.h> 69*10253Sxiuyan.wang@Sun.COM #include <sys/zmod.h> 70*10253Sxiuyan.wang@Sun.COM #include <sys/cpuvar.h> 71*10253Sxiuyan.wang@Sun.COM #include <sys/proc.h> 72*10253Sxiuyan.wang@Sun.COM #include <sys/callb.h> 73*10253Sxiuyan.wang@Sun.COM 74*10253Sxiuyan.wang@Sun.COM #include "myri10ge_mcp.h" 75*10253Sxiuyan.wang@Sun.COM #include "myri10ge_version.h" 76*10253Sxiuyan.wang@Sun.COM 77*10253Sxiuyan.wang@Sun.COM #define MYRI10GE_FW_OFFSET 1024*1024 78*10253Sxiuyan.wang@Sun.COM #define MYRI10GE_EEPROM_STRINGS_SIZE 256 79*10253Sxiuyan.wang@Sun.COM #define MYRI10GE_HIGHPART_TO_U32(X) \ 80*10253Sxiuyan.wang@Sun.COM (sizeof (X) == 8) ? ((uint32_t)((uint64_t)(X) >> 32)) : (0) 81*10253Sxiuyan.wang@Sun.COM #define MYRI10GE_LOWPART_TO_U32(X) ((uint32_t)(X)) 82*10253Sxiuyan.wang@Sun.COM 83*10253Sxiuyan.wang@Sun.COM #define MYRI10GE_DDI_REG_SET_32_BIT_MEMORY_SPACE 2 84*10253Sxiuyan.wang@Sun.COM #define MYRI10GE_DDI_REG_SET_64_BIT_MEMORY_SPACE 3 85*10253Sxiuyan.wang@Sun.COM 86*10253Sxiuyan.wang@Sun.COM /* 87*10253Sxiuyan.wang@Sun.COM * Max descriptors a TSO send can use; worst case is every descriptor 88*10253Sxiuyan.wang@Sun.COM * crosses a 2KB boundary, as do the headers 89*10253Sxiuyan.wang@Sun.COM */ 90*10253Sxiuyan.wang@Sun.COM 91*10253Sxiuyan.wang@Sun.COM #define MYRI10GE_MAX_SEND_DESC_TSO (2 + (65536 / 2048) * 2) 92*10253Sxiuyan.wang@Sun.COM 93*10253Sxiuyan.wang@Sun.COM #ifdef MYRICOM_PRIV 94*10253Sxiuyan.wang@Sun.COM #define VLAN_TAGSZ 4 95*10253Sxiuyan.wang@Sun.COM #endif 96*10253Sxiuyan.wang@Sun.COM 97*10253Sxiuyan.wang@Sun.COM #if defined DDI_INTR_IS_MSI_OR_MSIX 98*10253Sxiuyan.wang@Sun.COM #define MYRI10GE_USE_MSI 1 99*10253Sxiuyan.wang@Sun.COM #else 100*10253Sxiuyan.wang@Sun.COM #define MYRI10GE_USE_MSI 0 101*10253Sxiuyan.wang@Sun.COM #endif 102*10253Sxiuyan.wang@Sun.COM 103*10253Sxiuyan.wang@Sun.COM 104*10253Sxiuyan.wang@Sun.COM struct myri10ge_dma_stuff { 105*10253Sxiuyan.wang@Sun.COM ddi_dma_handle_t handle; 106*10253Sxiuyan.wang@Sun.COM ddi_acc_handle_t acc_handle; 107*10253Sxiuyan.wang@Sun.COM uint32_t low; 108*10253Sxiuyan.wang@Sun.COM uint32_t high; 109*10253Sxiuyan.wang@Sun.COM }; 110*10253Sxiuyan.wang@Sun.COM 111*10253Sxiuyan.wang@Sun.COM typedef struct myri10ge_mblkq { 112*10253Sxiuyan.wang@Sun.COM struct myri10ge_priv *mgp; 113*10253Sxiuyan.wang@Sun.COM kmutex_t lock; 114*10253Sxiuyan.wang@Sun.COM mblk_t *head; 115*10253Sxiuyan.wang@Sun.COM mblk_t *tail; 116*10253Sxiuyan.wang@Sun.COM unsigned long cnt; 117*10253Sxiuyan.wang@Sun.COM } myri10ge_mblkq_t; 118*10253Sxiuyan.wang@Sun.COM 119*10253Sxiuyan.wang@Sun.COM typedef struct { 120*10253Sxiuyan.wang@Sun.COM mcp_slot_t *entry; 121*10253Sxiuyan.wang@Sun.COM struct myri10ge_dma_stuff dma; 122*10253Sxiuyan.wang@Sun.COM int cnt; 123*10253Sxiuyan.wang@Sun.COM int idx; 124*10253Sxiuyan.wang@Sun.COM } myri10ge_rx_done_t; 125*10253Sxiuyan.wang@Sun.COM 126*10253Sxiuyan.wang@Sun.COM 127*10253Sxiuyan.wang@Sun.COM typedef struct 128*10253Sxiuyan.wang@Sun.COM { 129*10253Sxiuyan.wang@Sun.COM uint32_t data0; 130*10253Sxiuyan.wang@Sun.COM uint32_t data1; 131*10253Sxiuyan.wang@Sun.COM uint32_t data2; 132*10253Sxiuyan.wang@Sun.COM } myri10ge_cmd_t; 133*10253Sxiuyan.wang@Sun.COM 134*10253Sxiuyan.wang@Sun.COM struct myri10ge_pci_saved_state { 135*10253Sxiuyan.wang@Sun.COM uint32_t base[16]; 136*10253Sxiuyan.wang@Sun.COM uint32_t msi_addr_low; 137*10253Sxiuyan.wang@Sun.COM uint32_t msi_addr_high; 138*10253Sxiuyan.wang@Sun.COM uint16_t msi_data_32; 139*10253Sxiuyan.wang@Sun.COM uint16_t msi_data_64; 140*10253Sxiuyan.wang@Sun.COM uint16_t msi_ctrl; 141*10253Sxiuyan.wang@Sun.COM }; 142*10253Sxiuyan.wang@Sun.COM 143*10253Sxiuyan.wang@Sun.COM struct myri10ge_jpool_entry; 144*10253Sxiuyan.wang@Sun.COM 145*10253Sxiuyan.wang@Sun.COM struct myri10ge_jpool_entry { 146*10253Sxiuyan.wang@Sun.COM struct myri10ge_jpool_entry *next; 147*10253Sxiuyan.wang@Sun.COM ddi_dma_handle_t dma_handle; 148*10253Sxiuyan.wang@Sun.COM ddi_acc_handle_t acc_handle; 149*10253Sxiuyan.wang@Sun.COM caddr_t buf; 150*10253Sxiuyan.wang@Sun.COM struct myri10ge_slice_state *ss; 151*10253Sxiuyan.wang@Sun.COM mcp_dma_addr_t dma; /* Kept in network byte order */ 152*10253Sxiuyan.wang@Sun.COM frtn_t free_func; 153*10253Sxiuyan.wang@Sun.COM }; 154*10253Sxiuyan.wang@Sun.COM 155*10253Sxiuyan.wang@Sun.COM #define MYRI10GE_CPU_CACHE_SZ 64 156*10253Sxiuyan.wang@Sun.COM struct myri10ge_per_cpu_jpool { 157*10253Sxiuyan.wang@Sun.COM struct myri10ge_jpool_entry *head; 158*10253Sxiuyan.wang@Sun.COM uint8_t _pad[MYRI10GE_CPU_CACHE_SZ - sizeof (void *)]; 159*10253Sxiuyan.wang@Sun.COM }; 160*10253Sxiuyan.wang@Sun.COM 161*10253Sxiuyan.wang@Sun.COM #define MYRI10GE_MAX_CPUS 64 162*10253Sxiuyan.wang@Sun.COM #define MYRI10GE_MAX_CPU_MASK (64 - 1) 163*10253Sxiuyan.wang@Sun.COM 164*10253Sxiuyan.wang@Sun.COM struct myri10ge_jpool_stuff { 165*10253Sxiuyan.wang@Sun.COM struct myri10ge_jpool_entry *head; 166*10253Sxiuyan.wang@Sun.COM struct myri10ge_per_cpu_jpool cpu[MYRI10GE_MAX_CPUS]; 167*10253Sxiuyan.wang@Sun.COM kmutex_t mtx; 168*10253Sxiuyan.wang@Sun.COM int num_alloc; 169*10253Sxiuyan.wang@Sun.COM int low_water; 170*10253Sxiuyan.wang@Sun.COM }; 171*10253Sxiuyan.wang@Sun.COM 172*10253Sxiuyan.wang@Sun.COM struct myri10ge_tx_ring_stats 173*10253Sxiuyan.wang@Sun.COM { 174*10253Sxiuyan.wang@Sun.COM uint64_t multixmt; 175*10253Sxiuyan.wang@Sun.COM uint64_t brdcstxmt; 176*10253Sxiuyan.wang@Sun.COM uint64_t opackets; 177*10253Sxiuyan.wang@Sun.COM uint64_t obytes; 178*10253Sxiuyan.wang@Sun.COM }; 179*10253Sxiuyan.wang@Sun.COM 180*10253Sxiuyan.wang@Sun.COM struct myri10ge_rx_ring_stats 181*10253Sxiuyan.wang@Sun.COM { 182*10253Sxiuyan.wang@Sun.COM uint64_t multircv; 183*10253Sxiuyan.wang@Sun.COM uint64_t brdcstrcv; 184*10253Sxiuyan.wang@Sun.COM uint64_t ipackets; 185*10253Sxiuyan.wang@Sun.COM uint64_t ibytes; 186*10253Sxiuyan.wang@Sun.COM }; 187*10253Sxiuyan.wang@Sun.COM 188*10253Sxiuyan.wang@Sun.COM struct myri10ge_tx_ring_entry_stats 189*10253Sxiuyan.wang@Sun.COM { 190*10253Sxiuyan.wang@Sun.COM uint32_t obytes; 191*10253Sxiuyan.wang@Sun.COM uint16_t opackets; 192*10253Sxiuyan.wang@Sun.COM uint8_t brdcstxmt; 193*10253Sxiuyan.wang@Sun.COM uint8_t multixmt; 194*10253Sxiuyan.wang@Sun.COM }; 195*10253Sxiuyan.wang@Sun.COM 196*10253Sxiuyan.wang@Sun.COM struct myri10ge_tx_pkt_stats { 197*10253Sxiuyan.wang@Sun.COM union { 198*10253Sxiuyan.wang@Sun.COM uint64_t all; 199*10253Sxiuyan.wang@Sun.COM struct myri10ge_tx_ring_entry_stats s; 200*10253Sxiuyan.wang@Sun.COM } un; 201*10253Sxiuyan.wang@Sun.COM }; 202*10253Sxiuyan.wang@Sun.COM 203*10253Sxiuyan.wang@Sun.COM #define ostat stat.un.s 204*10253Sxiuyan.wang@Sun.COM 205*10253Sxiuyan.wang@Sun.COM struct myri10ge_tx_dma_handle { 206*10253Sxiuyan.wang@Sun.COM struct myri10ge_tx_dma_handle *next; 207*10253Sxiuyan.wang@Sun.COM ddi_dma_handle_t h; 208*10253Sxiuyan.wang@Sun.COM }; 209*10253Sxiuyan.wang@Sun.COM 210*10253Sxiuyan.wang@Sun.COM struct myri10ge_tx_dma_handle_head { 211*10253Sxiuyan.wang@Sun.COM struct myri10ge_tx_dma_handle *head; 212*10253Sxiuyan.wang@Sun.COM struct myri10ge_tx_dma_handle *tail; 213*10253Sxiuyan.wang@Sun.COM }; 214*10253Sxiuyan.wang@Sun.COM 215*10253Sxiuyan.wang@Sun.COM struct myri10ge_rx_buffer_state { 216*10253Sxiuyan.wang@Sun.COM caddr_t ptr; 217*10253Sxiuyan.wang@Sun.COM struct myri10ge_jpool_entry *j; 218*10253Sxiuyan.wang@Sun.COM }; 219*10253Sxiuyan.wang@Sun.COM 220*10253Sxiuyan.wang@Sun.COM struct myri10ge_tx_buffer_state { 221*10253Sxiuyan.wang@Sun.COM mblk_t *m; 222*10253Sxiuyan.wang@Sun.COM struct myri10ge_tx_dma_handle *handle; 223*10253Sxiuyan.wang@Sun.COM struct myri10ge_tx_pkt_stats stat; 224*10253Sxiuyan.wang@Sun.COM }; 225*10253Sxiuyan.wang@Sun.COM 226*10253Sxiuyan.wang@Sun.COM struct myri10ge_nic_stat { 227*10253Sxiuyan.wang@Sun.COM struct kstat_named dma_force_physical; 228*10253Sxiuyan.wang@Sun.COM struct kstat_named dma_read_bw_MBs; 229*10253Sxiuyan.wang@Sun.COM struct kstat_named dma_write_bw_MBs; 230*10253Sxiuyan.wang@Sun.COM struct kstat_named dma_read_write_bw_MBs; 231*10253Sxiuyan.wang@Sun.COM struct kstat_named lanes; 232*10253Sxiuyan.wang@Sun.COM struct kstat_named dropped_bad_crc32; 233*10253Sxiuyan.wang@Sun.COM struct kstat_named dropped_bad_phy; 234*10253Sxiuyan.wang@Sun.COM struct kstat_named dropped_link_error_or_filtered; 235*10253Sxiuyan.wang@Sun.COM struct kstat_named dropped_link_overflow; 236*10253Sxiuyan.wang@Sun.COM struct kstat_named dropped_multicast_filtered; 237*10253Sxiuyan.wang@Sun.COM struct kstat_named dropped_no_big_buffer; 238*10253Sxiuyan.wang@Sun.COM struct kstat_named dropped_no_small_buffer; 239*10253Sxiuyan.wang@Sun.COM struct kstat_named dropped_overrun; 240*10253Sxiuyan.wang@Sun.COM struct kstat_named dropped_pause; 241*10253Sxiuyan.wang@Sun.COM struct kstat_named dropped_runt; 242*10253Sxiuyan.wang@Sun.COM struct kstat_named dropped_unicast_filtered; 243*10253Sxiuyan.wang@Sun.COM struct kstat_named link_changes; 244*10253Sxiuyan.wang@Sun.COM struct kstat_named link_up; 245*10253Sxiuyan.wang@Sun.COM }; 246*10253Sxiuyan.wang@Sun.COM 247*10253Sxiuyan.wang@Sun.COM struct myri10ge_slice_stat { 248*10253Sxiuyan.wang@Sun.COM struct kstat_named lro_bad_csum; 249*10253Sxiuyan.wang@Sun.COM struct kstat_named lro_flushed; 250*10253Sxiuyan.wang@Sun.COM struct kstat_named lro_queued; 251*10253Sxiuyan.wang@Sun.COM struct kstat_named rx_big; 252*10253Sxiuyan.wang@Sun.COM struct kstat_named rx_bigbuf_firmware; 253*10253Sxiuyan.wang@Sun.COM struct kstat_named rx_bigbuf_pool; 254*10253Sxiuyan.wang@Sun.COM struct kstat_named rx_bigbuf_smalls; 255*10253Sxiuyan.wang@Sun.COM struct kstat_named rx_copy; 256*10253Sxiuyan.wang@Sun.COM struct kstat_named rx_small; 257*10253Sxiuyan.wang@Sun.COM struct kstat_named rx_big_nobuf; 258*10253Sxiuyan.wang@Sun.COM struct kstat_named rx_small_nobuf; 259*10253Sxiuyan.wang@Sun.COM struct kstat_named tx_activate; 260*10253Sxiuyan.wang@Sun.COM struct kstat_named tx_done; 261*10253Sxiuyan.wang@Sun.COM struct kstat_named tx_handles_alloced; 262*10253Sxiuyan.wang@Sun.COM struct kstat_named tx_req; 263*10253Sxiuyan.wang@Sun.COM struct kstat_named xmit_err; 264*10253Sxiuyan.wang@Sun.COM struct kstat_named xmit_lowbuf; 265*10253Sxiuyan.wang@Sun.COM struct kstat_named xmit_lsobadflags; 266*10253Sxiuyan.wang@Sun.COM struct kstat_named xmit_pullup; 267*10253Sxiuyan.wang@Sun.COM struct kstat_named xmit_pullup_first; 268*10253Sxiuyan.wang@Sun.COM struct kstat_named xmit_sched; 269*10253Sxiuyan.wang@Sun.COM struct kstat_named xmit_stall; 270*10253Sxiuyan.wang@Sun.COM struct kstat_named xmit_stall_early; 271*10253Sxiuyan.wang@Sun.COM struct kstat_named xmit_stall_late; 272*10253Sxiuyan.wang@Sun.COM struct kstat_named xmit_zero_len; 273*10253Sxiuyan.wang@Sun.COM }; 274*10253Sxiuyan.wang@Sun.COM 275*10253Sxiuyan.wang@Sun.COM struct myri10ge_info { 276*10253Sxiuyan.wang@Sun.COM struct kstat_named driver_version; 277*10253Sxiuyan.wang@Sun.COM struct kstat_named firmware_version; 278*10253Sxiuyan.wang@Sun.COM struct kstat_named firmware_name; 279*10253Sxiuyan.wang@Sun.COM struct kstat_named interrupt_type; 280*10253Sxiuyan.wang@Sun.COM struct kstat_named product_code; 281*10253Sxiuyan.wang@Sun.COM struct kstat_named serial_number; 282*10253Sxiuyan.wang@Sun.COM }; 283*10253Sxiuyan.wang@Sun.COM 284*10253Sxiuyan.wang@Sun.COM 285*10253Sxiuyan.wang@Sun.COM #define MYRI10GE_NIC_STAT_INC(field) \ 286*10253Sxiuyan.wang@Sun.COM (((struct myri10ge_nic_stat *)mgp->ksp_stat->ks_data)->field.value.ul)++ 287*10253Sxiuyan.wang@Sun.COM #define MYRI10GE_SLICE_STAT_INC(field) \ 288*10253Sxiuyan.wang@Sun.COM (((struct myri10ge_slice_stat *)ss->ksp_stat->ks_data)->field.value.ul)++ 289*10253Sxiuyan.wang@Sun.COM #define MYRI10GE_SLICE_STAT_ADD(field, val) \ 290*10253Sxiuyan.wang@Sun.COM (((struct myri10ge_slice_stat *)ss->ksp_stat->ks_data)->field.value.ul) += val 291*10253Sxiuyan.wang@Sun.COM #define MYRI10GE_SLICE_STAT_DEC(field) \ 292*10253Sxiuyan.wang@Sun.COM (((struct myri10ge_slice_stat *)ss->ksp_stat->ks_data)->field.value.ul)-- 293*10253Sxiuyan.wang@Sun.COM #define MYRI10GE_ATOMIC_SLICE_STAT_INC(field) \ 294*10253Sxiuyan.wang@Sun.COM atomic_add_long(&(((struct myri10ge_slice_stat *) \ 295*10253Sxiuyan.wang@Sun.COM ss->ksp_stat->ks_data)->field.value.ul), 1) 296*10253Sxiuyan.wang@Sun.COM #define MYRI10GE_ATOMIC_SLICE_STAT_DEC(field) \ 297*10253Sxiuyan.wang@Sun.COM atomic_add_long(&(((struct myri10ge_slice_stat *) \ 298*10253Sxiuyan.wang@Sun.COM ss->ksp_stat->ks_data)->field.value.ul), -1) 299*10253Sxiuyan.wang@Sun.COM #define MYRI10GE_SLICE_STAT(field) \ 300*10253Sxiuyan.wang@Sun.COM (((struct myri10ge_slice_stat *)ss->ksp_stat->ks_data)->field.value.ul) 301*10253Sxiuyan.wang@Sun.COM 302*10253Sxiuyan.wang@Sun.COM 303*10253Sxiuyan.wang@Sun.COM struct myri10ge_tx_copybuf 304*10253Sxiuyan.wang@Sun.COM { 305*10253Sxiuyan.wang@Sun.COM caddr_t va; 306*10253Sxiuyan.wang@Sun.COM int len; 307*10253Sxiuyan.wang@Sun.COM struct myri10ge_dma_stuff dma; 308*10253Sxiuyan.wang@Sun.COM }; 309*10253Sxiuyan.wang@Sun.COM 310*10253Sxiuyan.wang@Sun.COM typedef struct 311*10253Sxiuyan.wang@Sun.COM { 312*10253Sxiuyan.wang@Sun.COM mcp_kreq_ether_recv_t *lanai; /* lanai ptr for recv ring */ 313*10253Sxiuyan.wang@Sun.COM mcp_kreq_ether_recv_t *shadow; /* host shadow of recv ring */ 314*10253Sxiuyan.wang@Sun.COM struct myri10ge_rx_buffer_state *info; 315*10253Sxiuyan.wang@Sun.COM int cnt; 316*10253Sxiuyan.wang@Sun.COM int alloc_fail; 317*10253Sxiuyan.wang@Sun.COM int mask; /* number of rx slots -1 */ 318*10253Sxiuyan.wang@Sun.COM boolean_t polling; 319*10253Sxiuyan.wang@Sun.COM } myri10ge_rx_ring_t; 320*10253Sxiuyan.wang@Sun.COM 321*10253Sxiuyan.wang@Sun.COM typedef struct 322*10253Sxiuyan.wang@Sun.COM { 323*10253Sxiuyan.wang@Sun.COM mcp_kreq_ether_send_t *lanai; /* lanai ptr for sendq */ 324*10253Sxiuyan.wang@Sun.COM char *go; /* doorbell to poll sendq */ 325*10253Sxiuyan.wang@Sun.COM char *stop; /* doorbell to !poll sendq */ 326*10253Sxiuyan.wang@Sun.COM struct myri10ge_tx_buffer_state *info; 327*10253Sxiuyan.wang@Sun.COM struct myri10ge_tx_copybuf *cp; 328*10253Sxiuyan.wang@Sun.COM int req; /* transmits submitted */ 329*10253Sxiuyan.wang@Sun.COM int mask; /* number of transmit slots -1 */ 330*10253Sxiuyan.wang@Sun.COM int done; /* transmits completed */ 331*10253Sxiuyan.wang@Sun.COM int pkt_done; /* packets completed */ 332*10253Sxiuyan.wang@Sun.COM int active; 333*10253Sxiuyan.wang@Sun.COM uint32_t stall; 334*10253Sxiuyan.wang@Sun.COM uint32_t stall_early; 335*10253Sxiuyan.wang@Sun.COM uint32_t stall_late; 336*10253Sxiuyan.wang@Sun.COM int sched; 337*10253Sxiuyan.wang@Sun.COM kmutex_t lock; 338*10253Sxiuyan.wang@Sun.COM struct myri10ge_tx_ring_stats stats; 339*10253Sxiuyan.wang@Sun.COM int watchdog_req; 340*10253Sxiuyan.wang@Sun.COM int watchdog_done; 341*10253Sxiuyan.wang@Sun.COM unsigned long activate; 342*10253Sxiuyan.wang@Sun.COM kmutex_t handle_lock; 343*10253Sxiuyan.wang@Sun.COM struct myri10ge_tx_dma_handle *free_tx_handles; 344*10253Sxiuyan.wang@Sun.COM mac_ring_handle_t rh; 345*10253Sxiuyan.wang@Sun.COM } myri10ge_tx_ring_t; 346*10253Sxiuyan.wang@Sun.COM 347*10253Sxiuyan.wang@Sun.COM struct lro_entry; 348*10253Sxiuyan.wang@Sun.COM 349*10253Sxiuyan.wang@Sun.COM struct lro_entry 350*10253Sxiuyan.wang@Sun.COM { 351*10253Sxiuyan.wang@Sun.COM struct lro_entry *next; 352*10253Sxiuyan.wang@Sun.COM mblk_t *m_head; 353*10253Sxiuyan.wang@Sun.COM mblk_t *m_tail; 354*10253Sxiuyan.wang@Sun.COM int timestamp; 355*10253Sxiuyan.wang@Sun.COM struct ip *ip; 356*10253Sxiuyan.wang@Sun.COM uint32_t tsval; 357*10253Sxiuyan.wang@Sun.COM uint32_t tsecr; 358*10253Sxiuyan.wang@Sun.COM uint32_t source_ip; 359*10253Sxiuyan.wang@Sun.COM uint32_t dest_ip; 360*10253Sxiuyan.wang@Sun.COM uint32_t next_seq; 361*10253Sxiuyan.wang@Sun.COM uint32_t ack_seq; 362*10253Sxiuyan.wang@Sun.COM uint32_t len; 363*10253Sxiuyan.wang@Sun.COM uint32_t data_csum; 364*10253Sxiuyan.wang@Sun.COM uint16_t window; 365*10253Sxiuyan.wang@Sun.COM uint16_t source_port; 366*10253Sxiuyan.wang@Sun.COM uint16_t dest_port; 367*10253Sxiuyan.wang@Sun.COM uint16_t append_cnt; 368*10253Sxiuyan.wang@Sun.COM uint16_t mss; 369*10253Sxiuyan.wang@Sun.COM uint8_t flags; 370*10253Sxiuyan.wang@Sun.COM }; 371*10253Sxiuyan.wang@Sun.COM 372*10253Sxiuyan.wang@Sun.COM struct myri10ge_mblk_list 373*10253Sxiuyan.wang@Sun.COM { 374*10253Sxiuyan.wang@Sun.COM mblk_t *head; 375*10253Sxiuyan.wang@Sun.COM mblk_t **tail; 376*10253Sxiuyan.wang@Sun.COM int cnt; 377*10253Sxiuyan.wang@Sun.COM }; 378*10253Sxiuyan.wang@Sun.COM 379*10253Sxiuyan.wang@Sun.COM struct myri10ge_priv; 380*10253Sxiuyan.wang@Sun.COM 381*10253Sxiuyan.wang@Sun.COM struct myri10ge_slice_state { 382*10253Sxiuyan.wang@Sun.COM struct myri10ge_priv *mgp; 383*10253Sxiuyan.wang@Sun.COM myri10ge_tx_ring_t tx; /* transmit ring */ 384*10253Sxiuyan.wang@Sun.COM myri10ge_rx_ring_t rx_small; 385*10253Sxiuyan.wang@Sun.COM myri10ge_rx_ring_t rx_big; 386*10253Sxiuyan.wang@Sun.COM myri10ge_rx_done_t rx_done; 387*10253Sxiuyan.wang@Sun.COM struct myri10ge_jpool_stuff jpool; 388*10253Sxiuyan.wang@Sun.COM struct myri10ge_rx_ring_stats rx_stats; 389*10253Sxiuyan.wang@Sun.COM volatile uint32_t *irq_claim; 390*10253Sxiuyan.wang@Sun.COM mcp_irq_data_t *fw_stats; 391*10253Sxiuyan.wang@Sun.COM struct lro_entry *lro_active; 392*10253Sxiuyan.wang@Sun.COM struct lro_entry *lro_free; 393*10253Sxiuyan.wang@Sun.COM struct myri10ge_dma_stuff fw_stats_dma; 394*10253Sxiuyan.wang@Sun.COM int jbufs_for_smalls; 395*10253Sxiuyan.wang@Sun.COM struct myri10ge_jpool_entry *small_jpool; 396*10253Sxiuyan.wang@Sun.COM int j_rx_cnt; 397*10253Sxiuyan.wang@Sun.COM mac_resource_handle_t mrh; 398*10253Sxiuyan.wang@Sun.COM kstat_t *ksp_stat; 399*10253Sxiuyan.wang@Sun.COM mac_ring_handle_t rx_rh; 400*10253Sxiuyan.wang@Sun.COM kmutex_t rx_lock; 401*10253Sxiuyan.wang@Sun.COM kmutex_t poll_lock; 402*10253Sxiuyan.wang@Sun.COM uint64_t rx_gen_num; 403*10253Sxiuyan.wang@Sun.COM boolean_t rx_polling; 404*10253Sxiuyan.wang@Sun.COM int rx_token; 405*10253Sxiuyan.wang@Sun.COM int watchdog_rx_copy; 406*10253Sxiuyan.wang@Sun.COM }; 407*10253Sxiuyan.wang@Sun.COM 408*10253Sxiuyan.wang@Sun.COM struct myri10ge_priv { 409*10253Sxiuyan.wang@Sun.COM struct myri10ge_slice_state *ss; 410*10253Sxiuyan.wang@Sun.COM int max_intr_slots; 411*10253Sxiuyan.wang@Sun.COM int num_slices; 412*10253Sxiuyan.wang@Sun.COM dev_info_t *dip; 413*10253Sxiuyan.wang@Sun.COM mac_handle_t mh; 414*10253Sxiuyan.wang@Sun.COM ddi_acc_handle_t io_handle; 415*10253Sxiuyan.wang@Sun.COM int tx_boundary; 416*10253Sxiuyan.wang@Sun.COM int watchdog_rx_pause; 417*10253Sxiuyan.wang@Sun.COM kstat_t *ksp_stat; 418*10253Sxiuyan.wang@Sun.COM kstat_t *ksp_info; 419*10253Sxiuyan.wang@Sun.COM int running; /* running? */ 420*10253Sxiuyan.wang@Sun.COM int csum_flag; /* rx_csums? */ 421*10253Sxiuyan.wang@Sun.COM uint8_t mac_addr[6]; /* eeprom mac address */ 422*10253Sxiuyan.wang@Sun.COM volatile uint8_t *sram; 423*10253Sxiuyan.wang@Sun.COM int sram_size; 424*10253Sxiuyan.wang@Sun.COM unsigned long board_span; 425*10253Sxiuyan.wang@Sun.COM unsigned long iomem_base; 426*10253Sxiuyan.wang@Sun.COM volatile uint32_t *irq_deassert; 427*10253Sxiuyan.wang@Sun.COM char *mac_addr_string; 428*10253Sxiuyan.wang@Sun.COM mcp_cmd_response_t *cmd; 429*10253Sxiuyan.wang@Sun.COM struct myri10ge_dma_stuff cmd_dma; 430*10253Sxiuyan.wang@Sun.COM int msi_enabled; 431*10253Sxiuyan.wang@Sun.COM int link_state; 432*10253Sxiuyan.wang@Sun.COM int rdma_tags_available; 433*10253Sxiuyan.wang@Sun.COM int intr_coal_delay; 434*10253Sxiuyan.wang@Sun.COM volatile uint32_t *intr_coal_delay_ptr; 435*10253Sxiuyan.wang@Sun.COM kmutex_t cmd_lock; 436*10253Sxiuyan.wang@Sun.COM kmutex_t intrlock; 437*10253Sxiuyan.wang@Sun.COM int down_cnt; 438*10253Sxiuyan.wang@Sun.COM int watchdog_resets; 439*10253Sxiuyan.wang@Sun.COM unsigned char *eth_z8e; 440*10253Sxiuyan.wang@Sun.COM unsigned int eth_z8e_length; 441*10253Sxiuyan.wang@Sun.COM ddi_iblock_cookie_t icookie; 442*10253Sxiuyan.wang@Sun.COM ddi_intr_handle_t *htable; 443*10253Sxiuyan.wang@Sun.COM int intr_size; 444*10253Sxiuyan.wang@Sun.COM int intr_cnt; 445*10253Sxiuyan.wang@Sun.COM int intr_cap; 446*10253Sxiuyan.wang@Sun.COM unsigned int intr_pri; 447*10253Sxiuyan.wang@Sun.COM int ddi_intr_type; 448*10253Sxiuyan.wang@Sun.COM int pause; 449*10253Sxiuyan.wang@Sun.COM timeout_id_t timer_id; 450*10253Sxiuyan.wang@Sun.COM clock_t timer_ticks; 451*10253Sxiuyan.wang@Sun.COM int vso; 452*10253Sxiuyan.wang@Sun.COM uint32_t mcp_index; 453*10253Sxiuyan.wang@Sun.COM char fw_version[128]; 454*10253Sxiuyan.wang@Sun.COM char name[32]; 455*10253Sxiuyan.wang@Sun.COM char *fw_name; 456*10253Sxiuyan.wang@Sun.COM char *intr_type; 457*10253Sxiuyan.wang@Sun.COM char eeprom_strings[MYRI10GE_EEPROM_STRINGS_SIZE]; 458*10253Sxiuyan.wang@Sun.COM char *sn_str; 459*10253Sxiuyan.wang@Sun.COM char *pc_str; 460*10253Sxiuyan.wang@Sun.COM uint32_t read_dma; 461*10253Sxiuyan.wang@Sun.COM uint32_t write_dma; 462*10253Sxiuyan.wang@Sun.COM uint32_t read_write_dma; 463*10253Sxiuyan.wang@Sun.COM uint32_t pcie_link_width; 464*10253Sxiuyan.wang@Sun.COM int max_read_request_4k; 465*10253Sxiuyan.wang@Sun.COM caddr_t nd_head; 466*10253Sxiuyan.wang@Sun.COM struct myri10ge_priv *next; 467*10253Sxiuyan.wang@Sun.COM uint_t refcnt; 468*10253Sxiuyan.wang@Sun.COM int reg_set; 469*10253Sxiuyan.wang@Sun.COM int features; 470*10253Sxiuyan.wang@Sun.COM struct myri10ge_pci_saved_state pci_saved_state; 471*10253Sxiuyan.wang@Sun.COM uint32_t *toeplitz_hash_table; 472*10253Sxiuyan.wang@Sun.COM uint32_t rss_key[8]; 473*10253Sxiuyan.wang@Sun.COM ddi_acc_handle_t cfg_hdl; 474*10253Sxiuyan.wang@Sun.COM int macaddr_cnt; 475*10253Sxiuyan.wang@Sun.COM }; 476*10253Sxiuyan.wang@Sun.COM 477*10253Sxiuyan.wang@Sun.COM /* features bitmask */ 478*10253Sxiuyan.wang@Sun.COM #define MYRI10GE_TSO 1 479*10253Sxiuyan.wang@Sun.COM 480*10253Sxiuyan.wang@Sun.COM #if defined(__GNUC__) 481*10253Sxiuyan.wang@Sun.COM #define likely(x) __builtin_expect((x), 1) 482*10253Sxiuyan.wang@Sun.COM #define unlikely(x) __builtin_expect((x), 0) 483*10253Sxiuyan.wang@Sun.COM #else 484*10253Sxiuyan.wang@Sun.COM #define likely(x) (x) 485*10253Sxiuyan.wang@Sun.COM #define unlikely(x) (x) 486*10253Sxiuyan.wang@Sun.COM #endif /* defined(__GNUC__) */ 487*10253Sxiuyan.wang@Sun.COM 488*10253Sxiuyan.wang@Sun.COM #define mb membar_producer 489*10253Sxiuyan.wang@Sun.COM 490*10253Sxiuyan.wang@Sun.COM struct myri10ge_priv *myri10ge_get_instance(uint_t unit); 491*10253Sxiuyan.wang@Sun.COM void myri10ge_put_instance(struct myri10ge_priv *); 492*10253Sxiuyan.wang@Sun.COM int myri10ge_send_cmd(struct myri10ge_priv *mgp, uint32_t cmd, 493*10253Sxiuyan.wang@Sun.COM myri10ge_cmd_t *data); 494*10253Sxiuyan.wang@Sun.COM caddr_t myri10ge_dma_alloc(dev_info_t *dip, size_t len, 495*10253Sxiuyan.wang@Sun.COM ddi_dma_attr_t *attr, ddi_device_acc_attr_t *accattr, 496*10253Sxiuyan.wang@Sun.COM uint_t alloc_flags, int bind_flags, struct myri10ge_dma_stuff *dma, 497*10253Sxiuyan.wang@Sun.COM int warn, int (*waitfp)(caddr_t)); 498*10253Sxiuyan.wang@Sun.COM void myri10ge_dma_free(struct myri10ge_dma_stuff *dma); 499*10253Sxiuyan.wang@Sun.COM 500*10253Sxiuyan.wang@Sun.COM void myri10ge_lro_flush(struct myri10ge_slice_state *ss, 501*10253Sxiuyan.wang@Sun.COM struct lro_entry *lro, struct myri10ge_mblk_list *mbl); 502*10253Sxiuyan.wang@Sun.COM int myri10ge_lro_rx(struct myri10ge_slice_state *ss, mblk_t *m_head, 503*10253Sxiuyan.wang@Sun.COM uint32_t csum, struct myri10ge_mblk_list *mbl); 504*10253Sxiuyan.wang@Sun.COM void myri10ge_mbl_append(struct myri10ge_slice_state *ss, 505*10253Sxiuyan.wang@Sun.COM struct myri10ge_mblk_list *mbl, mblk_t *mp); 506*10253Sxiuyan.wang@Sun.COM uint16_t myri10ge_csum_generic(uint16_t *raw, int len); 507*10253Sxiuyan.wang@Sun.COM extern int myri10ge_lro_max_aggr; 508*10253Sxiuyan.wang@Sun.COM extern int myri10ge_mtu; 509*10253Sxiuyan.wang@Sun.COM 510*10253Sxiuyan.wang@Sun.COM #ifndef ETHERNET_HEADER_SIZE 511*10253Sxiuyan.wang@Sun.COM #define ETHERNET_HEADER_SIZE 14 512*10253Sxiuyan.wang@Sun.COM #endif 513*10253Sxiuyan.wang@Sun.COM 514*10253Sxiuyan.wang@Sun.COM #define MYRI10GE_TOEPLITZ_HASH (MXGEFW_RSS_HASH_TYPE_TCP_IPV4|\ 515*10253Sxiuyan.wang@Sun.COM MXGEFW_RSS_HASH_TYPE_IPV4) 516*10253Sxiuyan.wang@Sun.COM #define MYRI10GE_POLL_NULL INT_MAX 517*10253Sxiuyan.wang@Sun.COM 518*10253Sxiuyan.wang@Sun.COM /* 519*10253Sxiuyan.wang@Sun.COM * This file uses MyriGE driver indentation. 520*10253Sxiuyan.wang@Sun.COM * 521*10253Sxiuyan.wang@Sun.COM * Local Variables: 522*10253Sxiuyan.wang@Sun.COM * c-file-style:"sun" 523*10253Sxiuyan.wang@Sun.COM * tab-width:8 524*10253Sxiuyan.wang@Sun.COM * End: 525*10253Sxiuyan.wang@Sun.COM */ 526*10253Sxiuyan.wang@Sun.COM 527*10253Sxiuyan.wang@Sun.COM #ifdef __cplusplus 528*10253Sxiuyan.wang@Sun.COM } 529*10253Sxiuyan.wang@Sun.COM #endif 530*10253Sxiuyan.wang@Sun.COM 531*10253Sxiuyan.wang@Sun.COM #endif /* MYRI10GE_VAR_H */ 532