1/*
2 * CDDL HEADER START
3 *
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.
7 *
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.
12 *
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]
18 *
19 * CDDL HEADER END
20 */
21
22/*
23 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
24 */
25
26#ifndef	_SYS_IB_ADAPTERS_HERMON_MISC_H
27#define	_SYS_IB_ADAPTERS_HERMON_MISC_H
28
29/*
30 * hermon_misc.h
31 *    Contains all of the prototypes, #defines, and structures necessary
32 *    for the Hermon Miscellaneous routines - Address Handle, Multicast,
33 *    Protection Domain, port-related, statistics (kstat) routines, and
34 *    extra VTS related routines.
35 *    Many of these functions are called by other parts of the Hermon driver
36 *    (and several routines are directly exposed through the IBTF CI
37 *    interface and/or kstat interface).
38 */
39
40#include <sys/types.h>
41#include <sys/conf.h>
42#include <sys/ddi.h>
43#include <sys/sunddi.h>
44
45#include <sys/ib/adapters/hermon/hermon_typedef.h>
46#include <sys/ib/adapters/hermon/hermon_ioctl.h>
47#include <sys/ib/adapters/hermon/hermon_rsrc.h>
48#include <sys/ib/adapters/hermon/hermon_hw.h>
49
50
51#ifdef __cplusplus
52extern "C" {
53#endif
54
55/*
56 * The following defines specify the default number of Address Handles (AH)
57 * and their size (in the hardware).  By default the maximum number of address
58 * handles is set to 32K.  This value is controllable through the
59 * "hermon_log_num_ah" configuration variable.  Note:  Hermon Address Handles
60 * are also referred to as UD Address Vectors (UDAV).
61 */
62#define	HERMON_NUM_AH_SHIFT		0xF
63#define	HERMON_NUM_AH			(1 << HERMON_NUM_AH_SHIFT)
64#define	HERMON_UDAV_SIZE_SHIFT		0x5
65#define	HERMON_UDAV_SIZE			(1 << HERMON_UDAV_SIZE_SHIFT)
66
67/*
68 * The following macro determines whether the contents of a UDAV need to be
69 * sync'd (with ddi_dma_sync()).  This decision is based on whether the
70 * UDAV is in DDR memory (no sync) or system memory (sync required).
71 */
72
73#define	HERMON_UDAV_IS_SYNC_REQ(state)					\
74	(((&((state)->ts_rsrc_hdl[HERMON_UDAV]))->rsrc_loc ==		\
75	HERMON_IN_DDR) ? 0 : 1)
76
77/*
78 * These defines are used by hermon_get_addr_path() and hermon_set_addr_path()
79 * below.  They indicate the type of hardware context being passed in the
80 * "path" argument.  Because the Hermon hardware formats for the QP address
81 * path and UDAV address path structures is so similar, but not exactly the
82 * same, we use these flags to indicate which type of structure is being
83 * read from or written to.
84 */
85#define	HERMON_ADDRPATH_QP		0x0
86#define	HERMON_ADDRPATH_UDAV		0x1
87
88/*
89 * The following defines specify the default number of Multicast Groups (MCG)
90 * and the maximum number of QP which can be associated with each.  By default
91 * the maximum number of multicast groups is set to 256, and the maximum number
92 * of QP per multicast group is set to 248 (256 4-byte slots minus the 8 slots
93 * in the header).  The first of these values is controllable through the
94 * "hermon_log_num_mcg" configuration variable.  "hermon_num_qp_per_mcg" is
95 * also available if the customer needs such a large capability.
96 */
97#define	HERMON_NUM_MCG_SHIFT		0x8
98#define	HERMON_NUM_QP_PER_MCG_MIN	0x8
99#define	HERMON_NUM_QP_PER_MCG		0xf8
100
101#define	HERMON_MCGMEM_SZ(state)						\
102	((((state)->hs_cfg_profile->cp_num_qp_per_mcg) + 8) << 2)
103
104/*
105 * Macro to compute the offset of the QP list in a given MCG entry.
106 */
107#define	HERMON_MCG_GET_QPLIST_PTR(mcg)					\
108	((hermon_hw_mcg_qp_list_t *)((uintptr_t)(mcg) +			\
109	sizeof (hermon_hw_mcg_t)))
110
111/*
112 * The following defines specify the characteristics of the Hermon multicast
113 * group hash table.  The HERMON_NUM_MCG_HASH_SHIFT defines the size of the
114 * hash table (as a power-of-2), which is set to 16 by default.  This value
115 * is controllable through the "hermon_log_num_mcg_hash" configuration variable,
116 * but serious consideration should be taken before changing this value.  Note:
117 * its appropriate size should be a function of the entire table size (as
118 * defined by "hermon_log_num_mcg" and HERMON_NUM_MCG_SHIFT above).
119 */
120#define	HERMON_NUM_MCG_HASH_SHIFT	0x4
121
122/*
123 * The following defines are used by the multicast routines to determine
124 * if a given "multicast GID" is valid or not (see hermon_mcg_is_mgid_valid
125 * for more details.  These values are pulled from the IBA specification,
126 * rev. 1.1
127 */
128#define	HERMON_MCG_TOPBITS_SHIFT	56
129#define	HERMON_MCG_TOPBITS_MASK		0xFF
130#define	HERMON_MCG_TOPBITS		0xFF
131
132#define	HERMON_MCG_FLAGS_SHIFT		52
133#define	HERMON_MCG_FLAGS_MASK		0xF
134#define	HERMON_MCG_FLAGS_PERM		0x0
135#define	HERMON_MCG_FLAGS_NONPERM	0x1
136
137#define	HERMON_MCG_SCOPE_SHIFT		48
138#define	HERMON_MCG_SCOPE_MASK		0xF
139#define	HERMON_MCG_SCOPE_LINKLOC	0x2
140#define	HERMON_MCG_SCOPE_SITELOC	0x5
141#define	HERMON_MCG_SCOPE_ORGLOC		0x8
142#define	HERMON_MCG_SCOPE_GLOBAL		0xE
143
144
145/*
146 * The following defines specify the default number of Protection Domains (PD).
147 * By default the maximum number of protection domains is set to 64K.  This
148 * value is controllable through the "hermon_log_num_pd" configuration variable.
149 */
150#define	HERMON_NUM_PD_SHIFT		0x10
151
152/*
153 * The following defines specify the default number of Partition Keys (PKey)
154 * per port.  By default the maximum number of PKeys is set to 32 per port, for
155 * a total of 64 (assuming two ports) .  This value is controllable through the
156 * "hermon_log_max_pkeytbl" configuration variable.
157 */
158#define	HERMON_NUM_PKEYTBL_SHIFT		0x5
159#define	HERMON_NUM_PKEYTBL		(1 << HERMON_NUM_PKEYTBL_SHIFT)
160
161/*
162 * The following defines specify the default number of SGIDs per port.  By
163 * default the maximum number of GIDS per port is set to 16.  This value
164 * is controllable through the "hermon_log_max_gidtbl" configuration variable.
165 */
166#define	HERMON_NUM_GIDTBL_SHIFT		0x4
167#define	HERMON_NUM_GIDTBL		(1 << HERMON_NUM_GIDTBL_SHIFT)
168
169/*
170 * Below is a define which is the default number of UAR pages.  By default, the
171 * maximum number of UAR pages is set to 1024 for hermon.  Note that
172 * BlueFlame (if enabled) will  take 1/2 the space behind BAR1 (the UAR BAR)
173 * and therefore we must limit this even further.  This value is controllable
174 * through the "hermon_log_num_uar" configuration variable. NOTE: This value
175 * should not be set larger than 15 (0xF) because the UAR index number is
176 * used as part of the minor number calculation (see hermon_open() for details)
177 * and the minor numbers should not be larger than eighteen bits (i.e. 15 bits
178 * of UAR index, 3 bits of driver instance number).  This is especially true
179 * for 32-bit kernels.
180 */
181#define	HERMON_NUM_UAR_SHIFT		0xA
182
183/*
184 * A DoorBell record (DBr) will be handled uniquely.  They are not in ICM now,
185 * so they don't need the mapping.  And they just need to be accessible to the
186 * HCA as an address, so we don't need to register the memory.  AND, since
187 * user level (uDAPL, OPEN verbs) won't ever do the unmapping of them we don't
188 * really need to worry about that either.  And the DBrs will have to live in
189 * user mappable memory.  So, we can shortcut a lot of things given these
190 * assumptions.
191 *
192 * Other facts:  the DBrs for Hermon are only two per qp - one for the Receive
193 * side (RQ or SRQ) and one for the CQ.  If a QP is associated with an SRQ, we
194 * only need the ONE for the SRQ.  Also, although the RQ/SRQ DBr is only 4-bytes
195 * while the CQ DBr is 8-bytes, all DBrs will be 8-bytes (see the union below).
196 * Though it may lead to minor wastage, it also means that reuse is easier since
197 * any DBr can be used for either, and we don't have to play allocation games.
198 *
199 * The state structure will hold the pointer to the start of a list of struct
200 * hermon_dbr_info_s, each one containing the necessary information to manage
201 * a page of DBr's.
202 */
203
204typedef uint64_t hermon_dbr_t;
205
206typedef struct hermon_dbr_info_s {
207	struct hermon_dbr_info_s *dbr_link;
208	hermon_dbr_t		*dbr_page;	/* virtual addr of page */
209	uint64_t		dbr_paddr;	/* physical addr of page */
210	ddi_acc_handle_t	dbr_acchdl;
211	ddi_dma_handle_t	dbr_dmahdl;
212	uint32_t		dbr_nfree;	/* #free DBrs in this page */
213	uint32_t		dbr_firstfree;	/* idx of first free DBr */
214} hermon_dbr_info_t;
215
216#define	HERMON_NUM_DBR_PER_PAGE	(PAGESIZE / sizeof (hermon_dbr_t))
217
218
219/*
220 * These defines specify some miscellaneous port-related configuration
221 * information.  Specifically, HERMON_MAX_MTU is used to define the maximum
222 * MTU supported for each Hermon port, HERMON_MAX_PORT_WIDTH is used to define
223 * the maximum supported port width, and the HERMON_MAX_VLCAP define is used
224 * to specify the maximum number of VLs supported, excluding VL15.  Both
225 * of these values are controllable and get be set using the "hermon_max_mtu"
226 * and "hermon_max_vlcap" configuration variables.  Note: as with many of the
227 * configurable variables, caution should be exercised when changing these
228 * values.  These values, specifically, should not be set any larger than
229 * they are defined here as these are set to the current Hermon device
230 * maximums.
231 *
232 * Note that:  with Hermon, these capabilities that were formerly retrieved
233 * 	as part of QUERY_DEV_LIM/CAP must now be retrieved with QUERY_PORT.
234 *	The init sequence will have to be altered vis-a-vis the older HCAs to
235 *	accommodate this change.
236 *
237 *	Also, the maximums will be changed here for now.
238 */
239#define	HERMON_MAX_MTU		0x5 /* was 0x4, 2048 but moved to 4096 */
240#define	HERMON_MAX_PORT_WIDTH	0x7 /* was 0x3 (1x/4x) but now 1/4/8x */
241#define	HERMON_MAX_VLCAP	0x8 /* remain the same for now */
242
243/*
244 * These last defines are used by the statistics counting routines (kstats)
245 * for initialization of the structures associated with the IB statistics
246 * access routines.  The HERMON_CNTR_MASK and HERMON_CNTR_SIZE defines are
247 * used to divide the "pcr" register into two 32-bit counters (one for "pic0"
248 * and the other for "pic1")
249 */
250#define	HERMON_CNTR_MASK		0xFFFFFFFF
251#define	HERMON_CNTR_SIZE		32
252#define	HERMON_CNTR_NUMENTRIES	17
253
254
255
256#define	HERMON_QUEUE_LOCATION_NORMAL	0x1
257#define	HERMON_QUEUE_LOCATION_USERLAND	0x2
258
259/*
260 * Minimum number of ticks to delay between successive polls of the CQ in
261 * VTS ioctl loopback test
262 */
263#define	HERMON_VTS_LOOPBACK_MIN_WAIT_DUR	50
264
265/*
266 * UAR software table, layout and associated structures
267 */
268
269/*
270 * Doorbell record table bitmap macros
271 */
272#define	HERMON_IND_BYTE(ind)		((ind) >> 3)
273#define	HERMON_IND_BIT(ind)		(1 << ((ind) & 0x7))
274
275#define	HERMON_BMAP_BIT_SET(bmap, ind)	\
276	((bmap)[HERMON_IND_BYTE(ind)] |= HERMON_IND_BIT(ind))
277#define	HERMON_BMAP_BIT_CLR(bmap, ind)	\
278	((bmap)[HERMON_IND_BYTE(ind)] &= ~HERMON_IND_BIT(ind))
279#define	HERMON_BMAP_BIT_ISSET(bmap, ind)	\
280	((bmap)[HERMON_IND_BYTE(ind)] & HERMON_IND_BIT(ind))
281
282
283/*
284 * User doorbell record page tracking
285 */
286typedef struct hermon_udbr_page_s hermon_udbr_page_t;
287
288struct hermon_udbr_page_s {
289	hermon_udbr_page_t	*upg_link;
290	uint_t			upg_index;
291	uint_t			upg_nfree;
292	uint64_t		*upg_free;
293	caddr_t			upg_kvaddr;
294	struct buf		*upg_buf;
295	ddi_umem_cookie_t	upg_umemcookie;
296	ddi_dma_handle_t	upg_dmahdl;
297	ddi_dma_cookie_t 	upg_dmacookie;
298};
299
300typedef struct hermon_udbr_mgmt_s hermon_user_dbr_t;
301
302struct hermon_udbr_mgmt_s {
303	hermon_user_dbr_t	*udbr_link;
304	uint_t			udbr_index;	/* same as uarpg */
305	hermon_udbr_page_t	*udbr_pagep;
306};
307
308
309/*
310 * doorbell tracking end
311 */
312
313/*
314 * The hermon_sw_ah_s structure is also referred to using the "hermon_ahhdl_t"
315 * typedef (see hermon_typedef.h).  It encodes all the information necessary
316 * to track the various resources needed to allocate, query, modify, and
317 * free an address handle.
318 *
319 * In specific, it has a lock to ensure single-threaded access. It stores a
320 * pointer to the associated PD handle, and also contains a copy of the
321 * GUID stored into the address handle.  The reason for this extra copy of
322 * the GUID info has to do with Hermon PRM compliance and is fully explained
323 * in hermon_misc.c
324 *
325 * To serve in it's primary function, it also contains a UDAV, which contains
326 * all of the data associated with the UD address vector that is being
327 * utilized by the holder of the address handle. The hardware-specific format
328 * of the UDAV is defined in the hermon_hw.h file.
329 *
330 * It also has the always necessary backpointer to the resource for the AH
331 * handle structure itself.
332 */
333struct hermon_sw_ah_s {
334	kmutex_t	ah_lock;
335	hermon_pdhdl_t	ah_pdhdl;
336	hermon_hw_udav_t *ah_udav;
337	hermon_rsrc_t	*ah_rsrcp;
338	uint64_t	ah_save_guid;
339};
340_NOTE(READ_ONLY_DATA(hermon_sw_ah_s::ah_udav))
341_NOTE(MUTEX_PROTECTS_DATA(hermon_sw_ah_s::ah_lock,
342    hermon_sw_ah_s::ah_pdhdl
343    hermon_sw_ah_s::ah_rsrcp
344    hermon_sw_ah_s::ah_save_guid))
345
346/*
347 * The hermon_sw_mcg_list_s structure is also referred to using the
348 * "hermon_mcghdl_t" typedef (see hermon_typedef.h).  It encodes all the
349 * information necessary to track the various resources needed to for attaching
350 * and detaching QP from multicast groups.
351 *
352 * The Hermon driver keeps an array of these and uses them as a shadow for
353 * the real HW-based MCG table.  They hold all the necessary information
354 * to track the resources and to allow fast access to the MCG table.  First,
355 * it had a 128-bit multicast GID (stored in "mcg_mgid_h" and "mcg_mgid_l".
356 * next if has a field to indicate the index of the next hermon_mcghdl_t in
357 * the current hash chain (zero is the end of the chain).  Note: this very
358 * closely mimics what the hardware MCG entry has. Then it has a field to
359 * indicate how many QP are currently attached to the given MCG.  And, lastly,
360 * it has the obligatory backpointer to the resource for the MCH handle
361 * structure itself.
362 */
363struct hermon_sw_mcg_list_s {
364	uint64_t	mcg_mgid_h;
365	uint64_t	mcg_mgid_l;
366	uint_t		mcg_next_indx;
367	uint_t		mcg_num_qps;
368	hermon_rsrc_t	*mcg_rsrcp;
369};
370
371/*
372 * The hermon_sw_pd_s structure is also referred to using the "hermon_pdhdl_t"
373 * typedef (see hermon_typedef.h).  It encodes all the information necessary
374 * to track the various resources needed to allocate and free protection
375 * domains
376 *
377 * Specifically, it has reference count and a lock to ensure single threaded
378 * access to it.  It has a field for the protection domain number ("pd_pdnum").
379 * And it also has the obligatory backpointer to the resource for the PD
380 * handle structure itself.
381 */
382struct hermon_sw_pd_s {
383	kmutex_t	pd_lock;
384	uint32_t	pd_pdnum;
385	uint32_t	pd_refcnt;
386	hermon_rsrc_t	*pd_rsrcp;
387};
388_NOTE(READ_ONLY_DATA(hermon_sw_pd_s::pd_pdnum
389    hermon_sw_pd_s::pd_rsrcp))
390_NOTE(MUTEX_PROTECTS_DATA(hermon_sw_pd_s::pd_lock,
391    hermon_sw_pd_s::pd_refcnt))
392
393/*
394 * The hermon_qalloc_info_s structure is also referred to using the
395 * "hermon_qalloc_info_t" typedef (see hermon_typedef.h).  It holds all the
396 * information necessary to track the resources for each of the various Hermon
397 * queue types (i.e. Event Queue, Completion Queue, Work Queue).
398 *
399 * Specifically, it has the size, alignment restrictions, and location (in DDR
400 * or in system memory).  And depending on the location, it also has the
401 * ddi_dma_handle_t, ddi_acc_handle_t, and pointers used for reading/writing to
402 * the queue's memory.
403 */
404struct hermon_qalloc_info_s {
405	uint64_t		qa_size;
406	uint64_t		qa_alloc_align;
407	uint64_t		qa_bind_align;
408	uint32_t		*qa_buf_real;
409	uint32_t		*qa_buf_aligned;
410	uint64_t		qa_buf_realsz;
411	uint_t			qa_pgoffs;
412	uint_t			qa_location;
413	ddi_dma_handle_t	qa_dmahdl;
414	ddi_acc_handle_t	qa_acchdl;
415	ddi_umem_cookie_t	qa_umemcookie;
416};
417
418/*
419 * The hermon_ks_mask_t structure encodes all the information necessary for
420 * the individual kstat entries.  The "ks_reg_offset" field contains the
421 * hardware offset for the corresponding counter, and "ks_reg_shift" and
422 * "ks_reg_mask" contain shift and mask registers used by the access routines.
423 * Also the "ks_old_pic0" and "ks_old_pic1" fields contain the most recently
424 * read value for the corresponding port ("pic").  Note:  An array of these
425 * structures is part of the "hermon_ks_info_t" structure below.
426 */
427typedef struct hermon_ks_mask_s {
428	char		*ks_evt_name;
429	uint32_t	ks_old_pic0;
430	uint32_t	ks_old_pic1;
431} hermon_ks_mask_t;
432
433/*
434 * Index into the named data components of 64 bit "perf_counters" kstat.
435 */
436enum {
437	HERMON_PERFCNTR64_ENABLE_IDX = 0,
438	HERMON_PERFCNTR64_XMIT_DATA_IDX,
439	HERMON_PERFCNTR64_RECV_DATA_IDX,
440	HERMON_PERFCNTR64_XMIT_PKTS_IDX,
441	HERMON_PERFCNTR64_RECV_PKTS_IDX,
442	HERMON_PERFCNTR64_NUM_COUNTERS
443};
444
445/*
446 * Data associated with the 64 bit "perf_counters" kstat. One for each port.
447 */
448typedef struct hermon_perfcntr64_ks_info_s {
449	struct kstat	*hki64_ksp;
450	int		hki64_ext_port_counters_supported;
451	int		hki64_enabled;
452	uint64_t	hki64_counters[HERMON_PERFCNTR64_NUM_COUNTERS];
453	uint32_t	hki64_last_read[HERMON_PERFCNTR64_NUM_COUNTERS];
454	uint_t		hki64_port_num;
455	hermon_state_t	*hki64_state;
456} hermon_perfcntr64_ks_info_t;
457
458/*
459 * The hermon_ks_info_t structure stores all the information necessary for
460 * tracking the resources associated with each of the various kstats.  In
461 * addition to containing pointers to each of the counter and pic kstats,
462 * this structure also contains "hki_pcr" which is the control register that
463 * determines which of the countable entries (from the "hki_ib_perfcnt[]"
464 * array) is being currently accessed.
465 */
466typedef struct hermon_ks_info_s {
467	struct kstat	*hki_cntr_ksp;
468	struct kstat	*hki_picN_ksp[HERMON_MAX_PORTS];
469	uint64_t	hki_pcr;
470	uint64_t	hki_pic0;
471	uint64_t	hki_pic1;
472	hermon_ks_mask_t	hki_ib_perfcnt[HERMON_CNTR_NUMENTRIES];
473	kt_did_t	hki_perfcntr64_thread_id;
474	kmutex_t	hki_perfcntr64_lock;
475	kcondvar_t	hki_perfcntr64_cv;
476	uint_t		hki_perfcntr64_flags;	/* see below */
477	hermon_perfcntr64_ks_info_t	hki_perfcntr64[HERMON_MAX_PORTS];
478} hermon_ks_info_t;
479
480/* hki_perfcntr64_flags */
481#define	HERMON_PERFCNTR64_THREAD_CREATED	0x0001
482#define	HERMON_PERFCNTR64_THREAD_EXIT		0x0002
483
484/*
485 * The hermon_ports_ioctl32_t, hermon_loopback_ioctl32_t, and
486 * hermon_flash_ioctl32_s structures are used internally by the Hermon
487 * driver to accomodate 32-bit applications which need to access the
488 * Hermon ioctls.  They are 32-bit versions of externally available
489 * structures defined in hermon_ioctl.h
490 */
491typedef struct hermon_ports_ioctl32_s {
492	uint_t			ap_revision;
493	caddr32_t		ap_ports;
494	uint8_t			ap_num_ports;
495} hermon_ports_ioctl32_t;
496
497typedef struct hermon_loopback_ioctl32_s {
498	uint_t			alb_revision;
499	caddr32_t		alb_send_buf;
500	caddr32_t		alb_fail_buf;
501	uint_t			alb_buf_sz;
502	uint_t			alb_num_iter;
503	uint_t			alb_pass_done;
504	uint_t			alb_timeout;
505	hermon_loopback_error_t	alb_error_type;
506	uint8_t			alb_port_num;
507	uint8_t			alb_num_retry;
508} hermon_loopback_ioctl32_t;
509
510typedef struct hermon_flash_ioctl32_s {
511	uint32_t	af_type;
512	caddr32_t	af_sector;
513	uint32_t	af_sector_num;
514	uint32_t	af_addr;
515	uint32_t	af_quadlet;
516	uint8_t		af_byte;
517} hermon_flash_ioctl32_t;
518
519/*
520 * The hermon_loopback_comm_t and hermon_loopback_state_t structures below
521 * are used to store all of the relevant state information needed to keep
522 * track of a single VTS ioctl loopback test run.
523 */
524typedef struct hermon_loopback_comm_s {
525	uint8_t			*hlc_buf;
526	size_t			hlc_buf_sz;
527	ibt_mr_desc_t		hlc_mrdesc;
528
529	hermon_mrhdl_t		hlc_mrhdl;
530	hermon_cqhdl_t		hlc_cqhdl[2];
531	hermon_qphdl_t		hlc_qp_hdl;
532
533	ibt_mr_attr_t		hlc_memattr;
534	uint_t			hlc_qp_num;
535	ibt_cq_attr_t		hlc_cq_attr;
536	ibt_qp_alloc_attr_t	hlc_qp_attr;
537	ibt_chan_sizes_t	hlc_chan_sizes;
538	ibt_qp_info_t		hlc_qp_info;
539	ibt_queue_sizes_t	hlc_queue_sizes;
540	ibt_send_wr_t		hlc_wr;
541	ibt_wr_ds_t		hlc_sgl;
542	ibt_wc_t		hlc_wc;
543	uint_t			hlc_num_polled;
544	ibt_status_t		hlc_status;
545	int			hlc_complete;
546	int			hlc_wrid;
547} hermon_loopback_comm_t;
548
549typedef struct hermon_loopback_state_s {
550	uint8_t			hls_port;
551	uint_t			hls_lid;
552	uint8_t			hls_retry;
553	hermon_state_t		*hls_state;
554	ibc_hca_hdl_t		hls_hca_hdl;
555	hermon_pdhdl_t		hls_pd_hdl;
556	hermon_loopback_comm_t	hls_tx;
557	hermon_loopback_comm_t	hls_rx;
558	ibt_status_t		hls_status;
559	int			hls_err;
560	int			hls_pkey_ix;
561	int			hls_timeout;
562} hermon_loopback_state_t;
563
564/*
565 * Mellanox FMR
566 */
567typedef struct hermon_fmr_list_s {
568	struct hermon_fmr_list_s		*fmr_next;
569
570	hermon_mrhdl_t			fmr;
571	hermon_fmrhdl_t			fmr_pool;
572	uint_t				fmr_remaps;
573	uint_t				fmr_remap_gen; /* generation */
574} hermon_fmr_list_t;
575
576struct hermon_sw_fmr_s {
577	hermon_state_t			*fmr_state;
578
579	kmutex_t			fmr_lock;
580	hermon_fmr_list_t		*fmr_free_list;
581	hermon_fmr_list_t		**fmr_free_list_tail;
582	int				fmr_free_len;
583	int				fmr_pool_size;
584	int				fmr_max_pages;
585	int				fmr_flags;
586	int				fmr_stat_register;
587
588	ibt_fmr_flush_handler_t		fmr_flush_function;
589	void				*fmr_flush_arg;
590
591	int				fmr_max_remaps;
592	uint_t				fmr_remap_gen; /* generation */
593	int				fmr_page_sz;
594
595	kmutex_t			remap_lock;
596	hermon_fmr_list_t		*fmr_remap_list;
597	hermon_fmr_list_t		**fmr_remap_list_tail;
598	int				fmr_remap_watermark;
599	int				fmr_remap_len;
600
601	kmutex_t			dirty_lock;
602	hermon_fmr_list_t		*fmr_dirty_list;
603	hermon_fmr_list_t		**fmr_dirty_list_tail;
604	int				fmr_dirty_watermark;
605	int				fmr_dirty_len;
606};
607_NOTE(MUTEX_PROTECTS_DATA(hermon_sw_fmr_s::fmr_lock,
608    hermon_sw_fmr_s::fmr_pool_size
609    hermon_sw_fmr_s::fmr_page_sz
610    hermon_sw_fmr_s::fmr_flags
611    hermon_sw_fmr_s::fmr_free_list))
612_NOTE(MUTEX_PROTECTS_DATA(hermon_sw_fmr_s::dirty_lock,
613    hermon_sw_fmr_s::fmr_dirty_watermark
614    hermon_sw_fmr_s::fmr_dirty_len
615    hermon_sw_fmr_s::fmr_dirty_list))
616_NOTE(DATA_READABLE_WITHOUT_LOCK(hermon_sw_fmr_s::fmr_remap_gen
617    hermon_sw_fmr_s::fmr_state
618    hermon_sw_fmr_s::fmr_max_pages
619    hermon_sw_fmr_s::fmr_max_remaps))
620
621/* FRWR guarantees 8 bits of key; avoid corner cases by using "-2" */
622#define	HERMON_FMR_MAX_REMAPS		(256 - 2)
623
624/* Hermon doorbell record routines */
625
626int hermon_dbr_page_alloc(hermon_state_t *state, hermon_dbr_info_t **info);
627int hermon_dbr_alloc(hermon_state_t *state, uint_t index,
628    ddi_acc_handle_t *acchdl, hermon_dbr_t **vdbr, uint64_t *pdbr,
629    uint64_t *mapoffset);
630void hermon_dbr_free(hermon_state_t *state, uint_t indx, hermon_dbr_t *record);
631void hermon_dbr_kern_free(hermon_state_t *state);
632
633/* Hermon Fast Memory Registration Routines */
634int hermon_create_fmr_pool(hermon_state_t *state, hermon_pdhdl_t pdhdl,
635    ibt_fmr_pool_attr_t *params, hermon_fmrhdl_t *fmrhdl);
636int hermon_destroy_fmr_pool(hermon_state_t *state, hermon_fmrhdl_t fmrhdl);
637int hermon_flush_fmr_pool(hermon_state_t *state, hermon_fmrhdl_t fmrhdl);
638int hermon_register_physical_fmr(hermon_state_t *state, hermon_fmrhdl_t fmrhdl,
639    ibt_pmr_attr_t *mem_pattr_p, hermon_mrhdl_t *mrhdl,
640    ibt_pmr_desc_t *mem_desc_p);
641int hermon_deregister_fmr(hermon_state_t *state, hermon_mrhdl_t mr);
642
643
644/* Hermon Address Handle routines */
645int hermon_ah_alloc(hermon_state_t *state, hermon_pdhdl_t pd,
646    ibt_adds_vect_t *attr_p, hermon_ahhdl_t *ahhdl, uint_t sleepflag);
647int hermon_ah_free(hermon_state_t *state, hermon_ahhdl_t *ahhdl,
648    uint_t sleepflag);
649int hermon_ah_query(hermon_state_t *state, hermon_ahhdl_t ahhdl,
650    hermon_pdhdl_t *pdhdl, ibt_adds_vect_t *attr_p);
651int hermon_ah_modify(hermon_state_t *state, hermon_ahhdl_t ahhdl,
652    ibt_adds_vect_t *attr_p);
653
654/* Hermon Multicast Group routines */
655int hermon_mcg_attach(hermon_state_t *state, hermon_qphdl_t qphdl, ib_gid_t gid,
656    ib_lid_t lid);
657int hermon_mcg_detach(hermon_state_t *state, hermon_qphdl_t qphdl, ib_gid_t gid,
658    ib_lid_t lid);
659
660/* Hermon Protection Domain routines */
661int hermon_pd_alloc(hermon_state_t *state, hermon_pdhdl_t *pdhdl,
662    uint_t sleepflag);
663int hermon_pd_free(hermon_state_t *state, hermon_pdhdl_t *pdhdl);
664void hermon_pd_refcnt_inc(hermon_pdhdl_t pd);
665void hermon_pd_refcnt_dec(hermon_pdhdl_t pd);
666
667/* Hermon port-related routines */
668int hermon_port_query(hermon_state_t *state, uint_t port,
669    ibt_hca_portinfo_t *pi);
670int hermon_port_modify(hermon_state_t *state, uint8_t port,
671    ibt_port_modify_flags_t flags, uint8_t init_type);
672
673/* Hermon statistics (kstat) routines */
674int hermon_kstat_init(hermon_state_t *state);
675void hermon_kstat_fini(hermon_state_t *state);
676
677/* Miscellaneous routines */
678int hermon_set_addr_path(hermon_state_t *state, ibt_adds_vect_t *av,
679    hermon_hw_addr_path_t *path, uint_t type);
680void hermon_get_addr_path(hermon_state_t *state, hermon_hw_addr_path_t *path,
681    ibt_adds_vect_t *av, uint_t type);
682int hermon_portnum_is_valid(hermon_state_t *state, uint_t portnum);
683int hermon_pkeyindex_is_valid(hermon_state_t *state, uint_t pkeyindx);
684int hermon_queue_alloc(hermon_state_t *state, hermon_qalloc_info_t *qa_info,
685    uint_t sleepflag);
686void hermon_queue_free(hermon_qalloc_info_t *qa_info);
687
688#ifdef __cplusplus
689}
690#endif
691
692#endif	/* _SYS_IB_ADAPTERS_HERMON_MISC_H */
693