if_mxge_var.h revision 159571
1/*******************************************************************************
2
3Copyright (c) 2006, Myricom Inc.
4All rights reserved.
5
6Redistribution and use in source and binary forms, with or without
7modification, 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
20THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30POSSIBILITY OF SUCH DAMAGE.
31
32$FreeBSD: head/sys/dev/mxge/if_mxge_var.h 159571 2006-06-13 13:53:52Z gallatin $
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_NUM_INTRQS 2
47
48typedef 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
55typedef struct mxge_intrq
56{
57  mcp_slot_t *q[MXGE_NUM_INTRQS];
58  int intrq;
59  int slot;
60  int maxslots;
61  uint32_t seqnum;
62  uint32_t spurious;
63  uint32_t cnt;
64  mxge_dma_t dma[MXGE_NUM_INTRQS];
65} mxge_intrq_t;
66
67
68typedef struct
69{
70  uint32_t data0;
71  uint32_t data1;
72  uint32_t data2;
73} mxge_cmd_t;
74
75struct mxge_buffer_state {
76	struct mbuf *m;
77	bus_dmamap_t map;
78};
79
80typedef struct
81{
82	volatile mcp_kreq_ether_recv_t *lanai;	/* lanai ptr for recv ring */
83	volatile uint8_t *wc_fifo;	/* w/c rx dma addr fifo address */
84	mcp_kreq_ether_recv_t *shadow;	/* host shadow of recv ring */
85	struct mxge_buffer_state *info;
86	bus_dma_tag_t dmat;
87	bus_dmamap_t extra_map;
88	int cnt;
89	int alloc_fail;
90	int mask;			/* number of rx slots -1 */
91} mxge_rx_buf_t;
92
93typedef struct
94{
95	volatile mcp_kreq_ether_send_t *lanai;	/* lanai ptr for sendq	*/
96	volatile uint8_t *wc_fifo;		/* w/c send fifo address */
97	mcp_kreq_ether_send_t *req_list;	/* host shadow of sendq */
98	char *req_bytes;
99	struct mxge_buffer_state *info;
100	bus_dma_tag_t dmat;
101	int req;			/* transmits submitted	*/
102	int mask;			/* number of transmit slots -1 */
103	int done;			/* transmits completed	*/
104	int boundary;			/* boundary transmits cannot cross*/
105} mxge_tx_buf_t;
106
107typedef struct {
108	struct ifnet* ifp;
109	int big_bytes;
110	struct mtx tx_lock;
111	int csum_flag;			/* rx_csums? 		*/
112	uint8_t	mac_addr[6];		/* eeprom mac address */
113	mxge_tx_buf_t tx;	/* transmit ring 	*/
114	mxge_rx_buf_t rx_small;
115	mxge_rx_buf_t rx_big;
116	bus_dma_tag_t	parent_dmat;
117	volatile uint8_t *sram;
118	int sram_size;
119	volatile uint32_t *irq_claim;
120	char *mac_addr_string;
121	char *product_code_string;
122	mcp_cmd_response_t *cmd;
123	mxge_dma_t cmd_dma;
124	mxge_dma_t zeropad_dma;
125	mcp_stats_t *fw_stats;
126	mxge_dma_t fw_stats_dma;
127	struct pci_dev *pdev;
128	int msi_enabled;
129	mxge_intrq_t intr;
130	int link_state;
131	unsigned int rdma_tags_available;
132	int intr_coal_delay;
133	int wc;
134	struct mtx cmd_lock;
135	struct sx driver_lock;
136	int wake_queue;
137	int stop_queue;
138	int down_cnt;
139	int watchdog_resets;
140	int tx_defragged;
141	int pause;
142	struct resource *mem_res;
143	struct resource *irq_res;
144	void *ih;
145	char *fw_name;
146	char eeprom_strings[MXGE_EEPROM_STRINGS_SIZE];
147	char fw_version[128];
148	device_t dev;
149	struct ifmedia media;
150
151} mxge_softc_t;
152
153#define MXGE_PCI_VENDOR_MYRICOM 	0x14c1
154#define MXGE_PCI_DEVICE_Z8E 	0x0008
155
156#define MXGE_HIGHPART_TO_U32(X) \
157(sizeof (X) == 8) ? ((uint32_t)((uint64_t)(X) >> 32)) : (0)
158#define MXGE_LOWPART_TO_U32(X) ((uint32_t)(X))
159
160
161/* implement our own memory barriers, since bus_space_barrier
162   cannot handle write-combining regions */
163
164#if defined (__GNUC__)
165  #if #cpu(i386) || defined __i386 || defined i386 || defined __i386__ || #cpu(x86_64) || defined __x86_64__
166    #define mb()  __asm__ __volatile__ ("sfence;": : :"memory")
167  #elif #cpu(sparc64) || defined sparc64 || defined __sparcv9
168    #define mb()  __asm__ __volatile__ ("membar #MemIssue": : :"memory")
169  #elif #cpu(sparc) || defined sparc || defined __sparc__
170    #define mb()  __asm__ __volatile__ ("stbar;": : :"memory")
171  #else
172    #define mb() 	/* XXX just to make this compile */
173  #endif
174#else
175  #error "unknown compiler"
176#endif
177
178static inline void
179mxge_pio_copy(volatile void *to_v, void *from_v, size_t size)
180{
181  register volatile uintptr_t *to;
182  volatile uintptr_t *from;
183  size_t i;
184
185  to = (volatile uintptr_t *) to_v;
186  from = from_v;
187  for (i = (size / sizeof (uintptr_t)); i; i--) {
188	  *to = *from;
189	  to++;
190	  from++;
191  }
192
193}
194
195
196/*
197  This file uses Myri10GE driver indentation.
198
199  Local Variables:
200  c-file-style:"linux"
201  tab-width:8
202  End:
203*/
204