4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2007-2009 Myricom, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #ifndef MYRI10GE_VAR_H
28 #define MYRI10GE_VAR_H
34 #include <sys/types.h>
35 #include <sys/errno.h>
36 #include <sys/param.h>
37 #include <sys/atomic.h>
38 #include <sys/stropts.h>
39 #include <sys/stream.h>
41 #include <sys/ksynch.h>
43 #include <sys/modctl.h>
44 #include <sys/debug.h>
46 #include <sys/ethernet.h>
47 #include <sys/mac_provider.h>
48 #define MAC_CAPAB_POLL 0
49 #define MC_RESOURCES 0
50 #include <sys/mac_ether.h>
57 #include <sys/sunddi.h>
58 #include <sys/strsubr.h> /* for hw cksum stuff */
59 #include <sys/pattr.h> /* for hw cksum stuff */
60 #include <netinet/in.h> /* for hw cksum stuff */
61 #include <netinet/ip.h> /* for hw cksum stuff */
62 #include <netinet/ip6.h> /* for hw cksum stuff */
63 #include <netinet/tcp.h> /* for hw cksum stuff */
64 #include <netinet/udp.h> /* for hw cksum stuff */
65 #include <sys/strsun.h>
66 #include <inet/common.h>
70 #include <sys/cpuvar.h>
72 #include <sys/callb.h>
74 #include "myri10ge_mcp.h"
75 #include "myri10ge_version.h"
77 #define MYRI10GE_FW_OFFSET 1024*1024
78 #define MYRI10GE_EEPROM_STRINGS_SIZE 256
79 #define MYRI10GE_HIGHPART_TO_U32(X) \
80 (sizeof (X) == 8) ? ((uint32_t)((uint64_t)(X) >> 32)) : (0)
81 #define MYRI10GE_LOWPART_TO_U32(X) ((uint32_t)(X))
83 #define MYRI10GE_DDI_REG_SET_32_BIT_MEMORY_SPACE 2
84 #define MYRI10GE_DDI_REG_SET_64_BIT_MEMORY_SPACE 3
87 * Max descriptors a TSO send can use; worst case is every descriptor
88 * crosses a 2KB boundary, as do the headers
91 #define MYRI10GE_MAX_SEND_DESC_TSO (2 + (65536 / 2048) * 2)
97 #if defined DDI_INTR_IS_MSI_OR_MSIX
98 #define MYRI10GE_USE_MSI 1
100 #define MYRI10GE_USE_MSI 0
104 struct myri10ge_dma_stuff
{
105 ddi_dma_handle_t handle
;
106 ddi_acc_handle_t acc_handle
;
111 typedef struct myri10ge_mblkq
{
112 struct myri10ge_priv
*mgp
;
121 struct myri10ge_dma_stuff dma
;
124 } myri10ge_rx_done_t
;
134 struct myri10ge_pci_saved_state
{
136 uint32_t msi_addr_low
;
137 uint32_t msi_addr_high
;
138 uint16_t msi_data_32
;
139 uint16_t msi_data_64
;
143 struct myri10ge_jpool_entry
;
145 struct myri10ge_jpool_entry
{
146 struct myri10ge_jpool_entry
*next
;
147 ddi_dma_handle_t dma_handle
;
148 ddi_acc_handle_t acc_handle
;
150 struct myri10ge_slice_state
*ss
;
151 mcp_dma_addr_t dma
; /* Kept in network byte order */
155 #define MYRI10GE_CPU_CACHE_SZ 64
156 struct myri10ge_per_cpu_jpool
{
157 struct myri10ge_jpool_entry
*head
;
158 uint8_t _pad
[MYRI10GE_CPU_CACHE_SZ
- sizeof (void *)];
161 #define MYRI10GE_MAX_CPUS 64
162 #define MYRI10GE_MAX_CPU_MASK (64 - 1)
164 struct myri10ge_jpool_stuff
{
165 struct myri10ge_jpool_entry
*head
;
166 struct myri10ge_per_cpu_jpool cpu
[MYRI10GE_MAX_CPUS
];
172 struct myri10ge_tx_ring_stats
180 struct myri10ge_rx_ring_stats
188 struct myri10ge_tx_ring_entry_stats
196 struct myri10ge_tx_pkt_stats
{
199 struct myri10ge_tx_ring_entry_stats s
;
203 #define ostat stat.un.s
205 struct myri10ge_tx_dma_handle
{
206 struct myri10ge_tx_dma_handle
*next
;
210 struct myri10ge_tx_dma_handle_head
{
211 struct myri10ge_tx_dma_handle
*head
;
212 struct myri10ge_tx_dma_handle
*tail
;
215 struct myri10ge_rx_buffer_state
{
217 struct myri10ge_jpool_entry
*j
;
220 struct myri10ge_tx_buffer_state
{
222 struct myri10ge_tx_dma_handle
*handle
;
223 struct myri10ge_tx_pkt_stats stat
;
226 struct myri10ge_nic_stat
{
227 struct kstat_named dma_force_physical
;
228 struct kstat_named dma_read_bw_MBs
;
229 struct kstat_named dma_write_bw_MBs
;
230 struct kstat_named dma_read_write_bw_MBs
;
231 struct kstat_named lanes
;
232 struct kstat_named dropped_bad_crc32
;
233 struct kstat_named dropped_bad_phy
;
234 struct kstat_named dropped_link_error_or_filtered
;
235 struct kstat_named dropped_link_overflow
;
236 struct kstat_named dropped_multicast_filtered
;
237 struct kstat_named dropped_no_big_buffer
;
238 struct kstat_named dropped_no_small_buffer
;
239 struct kstat_named dropped_overrun
;
240 struct kstat_named dropped_pause
;
241 struct kstat_named dropped_runt
;
242 struct kstat_named dropped_unicast_filtered
;
243 struct kstat_named link_changes
;
244 struct kstat_named link_up
;
247 struct myri10ge_slice_stat
{
248 struct kstat_named lro_bad_csum
;
249 struct kstat_named lro_flushed
;
250 struct kstat_named lro_queued
;
251 struct kstat_named rx_big
;
252 struct kstat_named rx_bigbuf_firmware
;
253 struct kstat_named rx_bigbuf_pool
;
254 struct kstat_named rx_bigbuf_smalls
;
255 struct kstat_named rx_copy
;
256 struct kstat_named rx_small
;
257 struct kstat_named rx_big_nobuf
;
258 struct kstat_named rx_small_nobuf
;
259 struct kstat_named tx_activate
;
260 struct kstat_named tx_done
;
261 struct kstat_named tx_handles_alloced
;
262 struct kstat_named tx_req
;
263 struct kstat_named xmit_err
;
264 struct kstat_named xmit_lowbuf
;
265 struct kstat_named xmit_lsobadflags
;
266 struct kstat_named xmit_pullup
;
267 struct kstat_named xmit_pullup_first
;
268 struct kstat_named xmit_sched
;
269 struct kstat_named xmit_stall
;
270 struct kstat_named xmit_stall_early
;
271 struct kstat_named xmit_stall_late
;
272 struct kstat_named xmit_zero_len
;
275 struct myri10ge_info
{
276 struct kstat_named driver_version
;
277 struct kstat_named firmware_version
;
278 struct kstat_named firmware_name
;
279 struct kstat_named interrupt_type
;
280 struct kstat_named product_code
;
281 struct kstat_named serial_number
;
285 #define MYRI10GE_NIC_STAT_INC(field) \
286 (((struct myri10ge_nic_stat *)mgp->ksp_stat->ks_data)->field.value.ul)++
287 #define MYRI10GE_SLICE_STAT_INC(field) \
288 (((struct myri10ge_slice_stat *)ss->ksp_stat->ks_data)->field.value.ul)++
289 #define MYRI10GE_SLICE_STAT_ADD(field, val) \
290 (((struct myri10ge_slice_stat *)ss->ksp_stat->ks_data)->field.value.ul) += val
291 #define MYRI10GE_SLICE_STAT_DEC(field) \
292 (((struct myri10ge_slice_stat *)ss->ksp_stat->ks_data)->field.value.ul)--
293 #define MYRI10GE_ATOMIC_SLICE_STAT_INC(field) \
294 atomic_inc_ulong(&(((struct myri10ge_slice_stat *) \
295 ss->ksp_stat->ks_data)->field.value.ul))
296 #define MYRI10GE_ATOMIC_SLICE_STAT_DEC(field) \
297 atomic_dec_ulong(&(((struct myri10ge_slice_stat *) \
298 ss->ksp_stat->ks_data)->field.value.ul))
299 #define MYRI10GE_SLICE_STAT(field) \
300 (((struct myri10ge_slice_stat *)ss->ksp_stat->ks_data)->field.value.ul)
303 struct myri10ge_tx_copybuf
307 struct myri10ge_dma_stuff dma
;
312 mcp_kreq_ether_recv_t
*lanai
; /* lanai ptr for recv ring */
313 mcp_kreq_ether_recv_t
*shadow
; /* host shadow of recv ring */
314 struct myri10ge_rx_buffer_state
*info
;
317 int mask
; /* number of rx slots -1 */
319 } myri10ge_rx_ring_t
;
323 mcp_kreq_ether_send_t
*lanai
; /* lanai ptr for sendq */
324 char *go
; /* doorbell to poll sendq */
325 char *stop
; /* doorbell to !poll sendq */
326 struct myri10ge_tx_buffer_state
*info
;
327 struct myri10ge_tx_copybuf
*cp
;
328 int req
; /* transmits submitted */
329 int mask
; /* number of transmit slots -1 */
330 int done
; /* transmits completed */
331 int pkt_done
; /* packets completed */
334 uint32_t stall_early
;
338 struct myri10ge_tx_ring_stats stats
;
341 unsigned long activate
;
342 kmutex_t handle_lock
;
343 struct myri10ge_tx_dma_handle
*free_tx_handles
;
344 mac_ring_handle_t rh
;
345 } myri10ge_tx_ring_t
;
351 struct lro_entry
*next
;
365 uint16_t source_port
;
372 struct myri10ge_mblk_list
379 struct myri10ge_priv
;
381 struct myri10ge_slice_state
{
382 struct myri10ge_priv
*mgp
;
383 myri10ge_tx_ring_t tx
; /* transmit ring */
384 myri10ge_rx_ring_t rx_small
;
385 myri10ge_rx_ring_t rx_big
;
386 myri10ge_rx_done_t rx_done
;
387 struct myri10ge_jpool_stuff jpool
;
388 struct myri10ge_rx_ring_stats rx_stats
;
389 volatile uint32_t *irq_claim
;
390 mcp_irq_data_t
*fw_stats
;
391 struct lro_entry
*lro_active
;
392 struct lro_entry
*lro_free
;
393 struct myri10ge_dma_stuff fw_stats_dma
;
394 int jbufs_for_smalls
;
395 struct myri10ge_jpool_entry
*small_jpool
;
397 mac_resource_handle_t mrh
;
399 mac_ring_handle_t rx_rh
;
403 boolean_t rx_polling
;
405 int watchdog_rx_copy
;
408 struct myri10ge_priv
{
409 struct myri10ge_slice_state
*ss
;
414 ddi_acc_handle_t io_handle
;
416 int watchdog_rx_pause
;
419 int running
; /* running? */
420 int csum_flag
; /* rx_csums? */
421 uint8_t mac_addr
[6]; /* eeprom mac address */
422 volatile uint8_t *sram
;
424 unsigned long board_span
;
425 unsigned long iomem_base
;
426 volatile uint32_t *irq_deassert
;
427 char *mac_addr_string
;
428 mcp_cmd_response_t
*cmd
;
429 struct myri10ge_dma_stuff cmd_dma
;
432 int rdma_tags_available
;
434 volatile uint32_t *intr_coal_delay_ptr
;
439 unsigned char *eth_z8e
;
440 unsigned int eth_z8e_length
;
441 ddi_iblock_cookie_t icookie
;
442 ddi_intr_handle_t
*htable
;
446 unsigned int intr_pri
;
449 timeout_id_t timer_id
;
453 char fw_version
[128];
457 char eeprom_strings
[MYRI10GE_EEPROM_STRINGS_SIZE
];
462 uint32_t read_write_dma
;
463 uint32_t pcie_link_width
;
464 int max_read_request_4k
;
466 struct myri10ge_priv
*next
;
470 struct myri10ge_pci_saved_state pci_saved_state
;
471 uint32_t *toeplitz_hash_table
;
473 ddi_acc_handle_t cfg_hdl
;
477 /* features bitmask */
478 #define MYRI10GE_TSO 1
480 #if defined(__GNUC__)
481 #define likely(x) __builtin_expect((x), 1)
482 #define unlikely(x) __builtin_expect((x), 0)
484 #define likely(x) (x)
485 #define unlikely(x) (x)
486 #endif /* defined(__GNUC__) */
488 #define mb membar_producer
490 struct myri10ge_priv
*myri10ge_get_instance(uint_t unit
);
491 void myri10ge_put_instance(struct myri10ge_priv
*);
492 int myri10ge_send_cmd(struct myri10ge_priv
*mgp
, uint32_t cmd
,
493 myri10ge_cmd_t
*data
);
494 caddr_t
myri10ge_dma_alloc(dev_info_t
*dip
, size_t len
,
495 ddi_dma_attr_t
*attr
, ddi_device_acc_attr_t
*accattr
,
496 uint_t alloc_flags
, int bind_flags
, struct myri10ge_dma_stuff
*dma
,
497 int warn
, int (*waitfp
)(caddr_t
));
498 void myri10ge_dma_free(struct myri10ge_dma_stuff
*dma
);
500 void myri10ge_lro_flush(struct myri10ge_slice_state
*ss
,
501 struct lro_entry
*lro
, struct myri10ge_mblk_list
*mbl
);
502 int myri10ge_lro_rx(struct myri10ge_slice_state
*ss
, mblk_t
*m_head
,
503 uint32_t csum
, struct myri10ge_mblk_list
*mbl
);
504 void myri10ge_mbl_append(struct myri10ge_slice_state
*ss
,
505 struct myri10ge_mblk_list
*mbl
, mblk_t
*mp
);
506 uint16_t myri10ge_csum_generic(uint16_t *raw
, int len
);
507 extern int myri10ge_lro_max_aggr
;
508 extern int myri10ge_mtu
;
510 #ifndef ETHERNET_HEADER_SIZE
511 #define ETHERNET_HEADER_SIZE 14
514 #define MYRI10GE_TOEPLITZ_HASH (MXGEFW_RSS_HASH_TYPE_TCP_IPV4|\
515 MXGEFW_RSS_HASH_TYPE_IPV4)
516 #define MYRI10GE_POLL_NULL INT_MAX
519 * This file uses MyriGE driver indentation.
531 #endif /* MYRI10GE_VAR_H */