xref: /freebsd/sys/dev/mxge/if_mxge_var.h (revision d056fa046c6a91b90cd98165face0e42a33a5173)
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 12
47 
48 typedef struct {
49 	void *addr;
50 	bus_addr_t bus_addr;
51 	bus_dma_tag_t dmat;
52 	bus_dmamap_t map;
53 } mxge_dma_t;
54 
55 
56 typedef struct {
57 	mcp_slot_t *entry;
58 	mxge_dma_t dma;
59 	int cnt;
60 	int idx;
61 } mxge_rx_done_t;
62 
63 typedef struct
64 {
65   uint32_t data0;
66   uint32_t data1;
67   uint32_t data2;
68 } mxge_cmd_t;
69 
70 struct mxge_rx_buffer_state {
71 	struct mbuf *m;
72 	bus_dmamap_t map;
73 };
74 
75 struct mxge_tx_buffer_state {
76 	struct mbuf *m;
77 	bus_dmamap_t map;
78 	int flag;
79 };
80 
81 typedef struct
82 {
83 	volatile mcp_kreq_ether_recv_t *lanai;	/* lanai ptr for recv ring */
84 	volatile uint8_t *wc_fifo;	/* w/c rx dma addr fifo address */
85 	mcp_kreq_ether_recv_t *shadow;	/* host shadow of recv ring */
86 	struct mxge_rx_buffer_state *info;
87 	bus_dma_tag_t dmat;
88 	bus_dmamap_t extra_map;
89 	int cnt;
90 	int alloc_fail;
91 	int mask;			/* number of rx slots -1 */
92 } mxge_rx_buf_t;
93 
94 typedef struct
95 {
96 	volatile mcp_kreq_ether_send_t *lanai;	/* lanai ptr for sendq	*/
97 	volatile uint8_t *wc_fifo;		/* w/c send fifo address */
98 	mcp_kreq_ether_send_t *req_list;	/* host shadow of sendq */
99 	char *req_bytes;
100 	struct mxge_tx_buffer_state *info;
101 	bus_dma_tag_t dmat;
102 	int req;			/* transmits submitted	*/
103 	int mask;			/* number of transmit slots -1 */
104 	int done;			/* transmits completed	*/
105 	int pkt_done;			/* packets completed */
106 	int boundary;			/* boundary transmits cannot cross*/
107 } mxge_tx_buf_t;
108 
109 typedef struct {
110 	struct ifnet* ifp;
111 	int big_bytes;
112 	struct mtx tx_lock;
113 	int csum_flag;			/* rx_csums? 		*/
114 	uint8_t	mac_addr[6];		/* eeprom mac address */
115 	mxge_tx_buf_t tx;	/* transmit ring 	*/
116 	mxge_rx_buf_t rx_small;
117 	mxge_rx_buf_t rx_big;
118 	mxge_rx_done_t rx_done;
119 	mcp_irq_data_t *fw_stats;
120 	bus_dma_tag_t	parent_dmat;
121 	volatile uint8_t *sram;
122 	int sram_size;
123 	volatile uint32_t *irq_deassert;
124 	volatile uint32_t *irq_claim;
125 	mcp_cmd_response_t *cmd;
126 	mxge_dma_t cmd_dma;
127 	mxge_dma_t zeropad_dma;
128 	mxge_dma_t fw_stats_dma;
129 	struct pci_dev *pdev;
130 	int msi_enabled;
131 	int link_state;
132 	unsigned int rdma_tags_available;
133 	int intr_coal_delay;
134 	volatile uint32_t *intr_coal_delay_ptr;
135 	int wc;
136 	struct mtx cmd_lock;
137 	struct sx driver_lock;
138 	int wake_queue;
139 	int stop_queue;
140 	int down_cnt;
141 	int watchdog_resets;
142 	int tx_defragged;
143 	int pause;
144 	struct resource *mem_res;
145 	struct resource *irq_res;
146 	void *ih;
147 	char *fw_name;
148 	char eeprom_strings[MXGE_EEPROM_STRINGS_SIZE];
149 	char fw_version[128];
150 	device_t dev;
151 	struct ifmedia media;
152 	int read_dma;
153 	int write_dma;
154 	int read_write_dma;
155 	char *mac_addr_string;
156 	char product_code_string[64];
157 	char serial_number_string[64];
158 
159 } mxge_softc_t;
160 
161 #define MXGE_PCI_VENDOR_MYRICOM 	0x14c1
162 #define MXGE_PCI_DEVICE_Z8E 	0x0008
163 
164 #define MXGE_HIGHPART_TO_U32(X) \
165 (sizeof (X) == 8) ? ((uint32_t)((uint64_t)(X) >> 32)) : (0)
166 #define MXGE_LOWPART_TO_U32(X) ((uint32_t)(X))
167 
168 
169 /* implement our own memory barriers, since bus_space_barrier
170    cannot handle write-combining regions */
171 
172 #if defined (__GNUC__)
173   #if #cpu(i386) || defined __i386 || defined i386 || defined __i386__ || #cpu(x86_64) || defined __x86_64__
174     #define mb()  __asm__ __volatile__ ("sfence;": : :"memory")
175   #elif #cpu(sparc64) || defined sparc64 || defined __sparcv9
176     #define mb()  __asm__ __volatile__ ("membar #MemIssue": : :"memory")
177   #elif #cpu(sparc) || defined sparc || defined __sparc__
178     #define mb()  __asm__ __volatile__ ("stbar;": : :"memory")
179   #else
180     #define mb() 	/* XXX just to make this compile */
181   #endif
182 #else
183   #error "unknown compiler"
184 #endif
185 
186 static inline void
187 mxge_pio_copy(volatile void *to_v, void *from_v, size_t size)
188 {
189   register volatile uintptr_t *to;
190   volatile uintptr_t *from;
191   size_t i;
192 
193   to = (volatile uintptr_t *) to_v;
194   from = from_v;
195   for (i = (size / sizeof (uintptr_t)); i; i--) {
196 	  *to = *from;
197 	  to++;
198 	  from++;
199   }
200 
201 }
202 
203 
204 /*
205   This file uses Myri10GE driver indentation.
206 
207   Local Variables:
208   c-file-style:"linux"
209   tab-width:8
210   End:
211 */
212