xref: /illumos-gate/usr/src/uts/common/io/cxgbe/shared/shared.h (revision 20a7641f9918de8574b8b3b47dbe35c4bfc78df1)
1 /*
2  * This file and its contents are supplied under the terms of the
3  * Common Development and Distribution License ("CDDL"), version 1.0.
4  * You may only use this file in accordance with the terms of version
5  * 1.0 of the CDDL.
6  *
7  * A full copy of the text of the CDDL should have accompanied this
8  * source. A copy of the CDDL is also available via the Internet at
9  * http://www.illumos.org/license/CDDL.
10  */
11 
12 /*
13  * This file is part of the Chelsio T4 support code.
14  *
15  * Copyright (C) 2011-2013 Chelsio Communications.  All rights reserved.
16  *
17  * This program is distributed in the hope that it will be useful, but WITHOUT
18  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19  * FITNESS FOR A PARTICULAR PURPOSE.  See the LICENSE file included in this
20  * release for licensing terms and conditions.
21  */
22 
23 #ifndef __CXGBE_SHARED_H
24 #define	__CXGBE_SHARED_H
25 
26 #include <sys/ddi.h>
27 #include <sys/sunddi.h>
28 
29 #define	UNIMPLEMENTED() cmn_err(CE_WARN, "%s (%s:%d) unimplemented.", \
30     __func__, __FILE__, __LINE__)
31 
32 #define	bitloc(a, i)	((a)[(i)/NBBY])
33 #define	setbit(a, i)	((a)[(i)/NBBY] |= 1<<((i)%NBBY))
34 #define	clrbit(a, i)	((a)[(i)/NBBY] &= ~(1<<((i)%NBBY)))
35 #define	isset(a, i)	((a)[(i)/NBBY] & (1<<((i)%NBBY)))
36 #define	isclr(a, i)	(((a)[(i)/NBBY] & (1<<((i)%NBBY))) == 0)
37 
38 /* TODO: really icky, but we don't want to include adapter.h in cxgb/cxgbe */
39 #define	PORT_INFO_HDR \
40 	dev_info_t *dip; \
41 	void *mh; \
42 	void *mc; \
43 	void *props; \
44 	int mtu; \
45 	uint8_t hw_addr[ETHERADDRL]
46 
47 struct mblk_pair {
48 	mblk_t *head, *tail;
49 };
50 
51 struct rxbuf {
52 	kmem_cache_t *cache;		/* the kmem_cache this rxb came from */
53 	ddi_dma_handle_t dhdl;
54 	ddi_acc_handle_t ahdl;
55 	caddr_t va;			/* KVA of buffer */
56 	uint64_t ba;			/* bus address of buffer */
57 	frtn_t freefunc;
58 	uint_t buf_size;
59 	volatile uint_t ref_cnt;
60 };
61 
62 struct rxbuf_cache_params {
63 	dev_info_t		*dip;
64 	ddi_dma_attr_t		dma_attr_rx;
65 	ddi_device_acc_attr_t	acc_attr_rx;
66 	size_t			buf_size;
67 };
68 
69 int cxgb_printf(dev_info_t *dip, int level, char *f, ...);
70 kmem_cache_t *rxbuf_cache_create(struct rxbuf_cache_params *p);
71 void rxbuf_cache_destroy(kmem_cache_t *cache);
72 struct rxbuf *rxbuf_alloc(kmem_cache_t *cache, int kmflags, uint_t ref_cnt);
73 void rxbuf_free(struct rxbuf *rxb);
74 
75 #endif /* __CXGBE_SHARED_H */
76