1 /******************************************************************************* 2 3 Copyright (c) 2006, Myricom Inc. 4 All rights reserved. 5 6 Redistribution and use in source and binary forms, with or without 7 modification, are permitted provided that the following conditions are met: 8 9 1. Redistributions of source code must retain the above copyright notice, 10 this list of conditions and the following disclaimer. 11 12 2. Redistributions in binary form must reproduce the above copyright 13 notice, this list of conditions and the following disclaimer in the 14 documentation and/or other materials provided with the distribution. 15 16 3. Neither the name of the Myricom Inc, nor the names of its 17 contributors may be used to endorse or promote products derived from 18 this software without specific prior written permission. 19 20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 24 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 POSSIBILITY OF SUCH DAMAGE. 31 32 $FreeBSD$ 33 34 ***************************************************************************/ 35 36 #define MXGE_MAX_ETHER_MTU 9014 37 38 #define MXGE_ETH_STOPPED 0 39 #define MXGE_ETH_STOPPING 1 40 #define MXGE_ETH_STARTING 2 41 #define MXGE_ETH_RUNNING 3 42 #define MXGE_ETH_OPEN_FAILED 4 43 44 #define MXGE_FW_OFFSET 1024*1024 45 #define MXGE_EEPROM_STRINGS_SIZE 256 46 #define MXGE_MAX_SEND_DESC 64 /* should be large enough for 47 any TSO packet */ 48 49 typedef struct { 50 void *addr; 51 bus_addr_t bus_addr; 52 bus_dma_tag_t dmat; 53 bus_dmamap_t map; 54 } mxge_dma_t; 55 56 57 typedef struct { 58 mcp_slot_t *entry; 59 mxge_dma_t dma; 60 int cnt; 61 int idx; 62 } mxge_rx_done_t; 63 64 typedef struct 65 { 66 uint32_t data0; 67 uint32_t data1; 68 uint32_t data2; 69 } mxge_cmd_t; 70 71 struct mxge_rx_buffer_state { 72 struct mbuf *m; 73 bus_dmamap_t map; 74 }; 75 76 struct mxge_tx_buffer_state { 77 struct mbuf *m; 78 bus_dmamap_t map; 79 int flag; 80 }; 81 82 typedef struct 83 { 84 volatile mcp_kreq_ether_recv_t *lanai; /* lanai ptr for recv ring */ 85 volatile uint8_t *wc_fifo; /* w/c rx dma addr fifo address */ 86 mcp_kreq_ether_recv_t *shadow; /* host shadow of recv ring */ 87 struct mxge_rx_buffer_state *info; 88 bus_dma_tag_t dmat; 89 bus_dmamap_t extra_map; 90 int cnt; 91 int alloc_fail; 92 int mask; /* number of rx slots -1 */ 93 } mxge_rx_buf_t; 94 95 typedef struct 96 { 97 volatile mcp_kreq_ether_send_t *lanai; /* lanai ptr for sendq */ 98 volatile uint8_t *wc_fifo; /* w/c send fifo address */ 99 mcp_kreq_ether_send_t *req_list; /* host shadow of sendq */ 100 char *req_bytes; 101 bus_dma_segment_t *seg_list; 102 struct mxge_tx_buffer_state *info; 103 bus_dma_tag_t dmat; 104 int req; /* transmits submitted */ 105 int mask; /* number of transmit slots -1 */ 106 int done; /* transmits completed */ 107 int pkt_done; /* packets completed */ 108 int boundary; /* boundary transmits cannot cross*/ 109 int stall; /* #times hw queue exhausted */ 110 int wake; /* #times irq re-enabled xmit */ 111 int watchdog_req; /* cache of req */ 112 int watchdog_done; /* cache of done */ 113 } mxge_tx_buf_t; 114 115 typedef struct { 116 struct ifnet* ifp; 117 int big_bytes; 118 struct mtx tx_mtx; 119 int csum_flag; /* rx_csums? */ 120 uint8_t mac_addr[6]; /* eeprom mac address */ 121 mxge_tx_buf_t tx; /* transmit ring */ 122 mxge_rx_buf_t rx_small; 123 mxge_rx_buf_t rx_big; 124 mxge_rx_done_t rx_done; 125 mcp_irq_data_t *fw_stats; 126 bus_dma_tag_t parent_dmat; 127 volatile uint8_t *sram; 128 int sram_size; 129 volatile uint32_t *irq_deassert; 130 volatile uint32_t *irq_claim; 131 mcp_cmd_response_t *cmd; 132 mxge_dma_t cmd_dma; 133 mxge_dma_t zeropad_dma; 134 mxge_dma_t fw_stats_dma; 135 struct pci_dev *pdev; 136 int msi_enabled; 137 int link_state; 138 unsigned int rdma_tags_available; 139 int intr_coal_delay; 140 volatile uint32_t *intr_coal_delay_ptr; 141 int wc; 142 struct mtx cmd_mtx; 143 struct mtx driver_mtx; 144 int wake_queue; 145 int stop_queue; 146 int down_cnt; 147 int watchdog_resets; 148 int tx_defragged; 149 int pause; 150 struct resource *mem_res; 151 struct resource *irq_res; 152 void *ih; 153 char *fw_name; 154 char eeprom_strings[MXGE_EEPROM_STRINGS_SIZE]; 155 char fw_version[128]; 156 int fw_ver_major; 157 int fw_ver_minor; 158 int fw_ver_tiny; 159 int adopted_rx_filter_bug; 160 device_t dev; 161 struct ifmedia media; 162 int read_dma; 163 int write_dma; 164 int read_write_dma; 165 int fw_multicast_support; 166 int link_width; 167 mxge_dma_t dmabench_dma; 168 struct callout co_hdl; 169 char *mac_addr_string; 170 char product_code_string[64]; 171 char serial_number_string[64]; 172 char scratch[256]; 173 char tx_mtx_name[16]; 174 char cmd_mtx_name[16]; 175 char driver_mtx_name[16]; 176 } mxge_softc_t; 177 178 #define MXGE_PCI_VENDOR_MYRICOM 0x14c1 179 #define MXGE_PCI_DEVICE_Z8E 0x0008 180 181 #define MXGE_HIGHPART_TO_U32(X) \ 182 (sizeof (X) == 8) ? ((uint32_t)((uint64_t)(X) >> 32)) : (0) 183 #define MXGE_LOWPART_TO_U32(X) ((uint32_t)(X)) 184 185 186 /* implement our own memory barriers, since bus_space_barrier 187 cannot handle write-combining regions */ 188 189 #if defined (__GNUC__) 190 #if #cpu(i386) || defined __i386 || defined i386 || defined __i386__ || #cpu(x86_64) || defined __x86_64__ 191 #define mb() __asm__ __volatile__ ("sfence;": : :"memory") 192 #elif #cpu(sparc64) || defined sparc64 || defined __sparcv9 193 #define mb() __asm__ __volatile__ ("membar #MemIssue": : :"memory") 194 #elif #cpu(sparc) || defined sparc || defined __sparc__ 195 #define mb() __asm__ __volatile__ ("stbar;": : :"memory") 196 #else 197 #define mb() /* XXX just to make this compile */ 198 #endif 199 #else 200 #error "unknown compiler" 201 #endif 202 203 static inline void 204 mxge_pio_copy(volatile void *to_v, void *from_v, size_t size) 205 { 206 register volatile uintptr_t *to; 207 volatile uintptr_t *from; 208 size_t i; 209 210 to = (volatile uintptr_t *) to_v; 211 from = from_v; 212 for (i = (size / sizeof (uintptr_t)); i; i--) { 213 *to = *from; 214 to++; 215 from++; 216 } 217 218 } 219 220 221 /* 222 This file uses Myri10GE driver indentation. 223 224 Local Variables: 225 c-file-style:"linux" 226 tab-width:8 227 End: 228 */ 229