2 * Copyright (C) 2007-2014 VMware, Inc. All rights reserved.
4 * The contents of this file are subject to the terms of the Common
5 * Development and Distribution License (the "License") version 1.0
6 * and no later version. You may not use this file except in
7 * compliance with the License.
9 * You can obtain a copy of the License at
10 * http://www.opensource.org/licenses/cddl1.php
12 * See the License for the specific language governing permissions
13 * and limitations under the License.
17 * Copyright (c) 2012, 2016 by Delphix. All rights reserved.
23 #include <sys/atomic.h>
24 #include <sys/types.h>
26 #include <sys/debug.h>
27 #include <sys/cmn_err.h>
28 #include <sys/stropts.h>
29 #include <sys/stream.h>
30 #include <sys/strlog.h>
33 #include <sys/kstat.h>
34 #include <sys/vtrace.h>
36 #include <sys/strsun.h>
37 #include <sys/ethernet.h>
39 #include <sys/modctl.h>
40 #include <sys/errno.h>
42 #include <sys/sunddi.h>
43 #include <sys/ddi_impldefs.h>
45 #include <sys/strsubr.h>
46 #include <sys/pattr.h>
48 #include <sys/sockio.h>
49 #include <sys/mac_provider.h>
50 #include <sys/mac_ether.h>
51 #include <inet/common.h>
55 #include <vmxnet3_defs.h>
57 typedef struct vmxnet3_dmabuf_t
{
61 ddi_dma_handle_t dmaHandle
;
62 ddi_acc_handle_t dataHandle
;
65 typedef struct vmxnet3_cmdring_t
{
73 typedef struct vmxnet3_compring_t
{
80 typedef struct vmxnet3_metatx_t
{
86 typedef struct vmxnet3_txqueue_t
{
87 vmxnet3_cmdring_t cmdRing
;
88 vmxnet3_compring_t compRing
;
89 vmxnet3_metatx_t
*metaRing
;
90 Vmxnet3_TxQueueCtrl
*sharedCtrl
;
93 typedef struct vmxnet3_rxbuf_t
{
97 struct vmxnet3_softc_t
*dp
;
98 struct vmxnet3_rxbuf_t
*next
;
101 typedef struct vmxnet3_bufdesc_t
{
102 vmxnet3_rxbuf_t
*rxBuf
;
105 typedef struct vmxnet3_rxpool_t
{
106 vmxnet3_rxbuf_t
*listHead
;
108 unsigned int nBufsLimit
;
111 typedef struct vmxnet3_rxqueue_t
{
112 vmxnet3_cmdring_t cmdRing
;
113 vmxnet3_compring_t compRing
;
114 vmxnet3_bufdesc_t
*bufRing
;
115 Vmxnet3_RxQueueCtrl
*sharedCtrl
;
118 typedef struct vmxnet3_softc_t
{
123 ddi_acc_handle_t pciHandle
;
124 ddi_acc_handle_t bar0Handle
, bar1Handle
;
127 boolean_t devEnabled
;
130 boolean_t allow_jumbo
;
131 link_state_t linkState
;
133 vmxnet3_dmabuf_t sharedData
;
134 vmxnet3_dmabuf_t queueDescs
;
140 ddi_intr_handle_t intrHandle
;
141 ddi_taskq_t
*resetTask
;
144 vmxnet3_txqueue_t txQueue
;
145 ddi_dma_handle_t txDmaHandle
;
146 boolean_t txMustResched
;
148 vmxnet3_rxqueue_t rxQueue
;
150 vmxnet3_rxpool_t rxPool
;
154 vmxnet3_dmabuf_t mfTable
;
156 uint32_t reset_count
;
157 uint32_t tx_pullup_needed
;
158 uint32_t tx_pullup_failed
;
159 uint32_t tx_ring_full
;
161 uint32_t rx_num_bufs
;
162 uint32_t rx_alloc_buf
;
163 uint32_t rx_alloc_failed
;
164 uint32_t rx_pool_empty
;
167 typedef struct vmxnet3_kstats_t
{
168 kstat_named_t reset_count
;
169 kstat_named_t tx_pullup_needed
;
170 kstat_named_t tx_ring_full
;
171 kstat_named_t rx_alloc_buf
;
172 kstat_named_t rx_pool_empty
;
173 kstat_named_t rx_num_bufs
;
176 int vmxnet3_dmaerr2errno(int);
177 int vmxnet3_alloc_dma_mem_1(vmxnet3_softc_t
*dp
, vmxnet3_dmabuf_t
*dma
,
178 size_t size
, boolean_t canSleep
);
179 int vmxnet3_alloc_dma_mem_128(vmxnet3_softc_t
*dp
, vmxnet3_dmabuf_t
*dma
,
180 size_t size
, boolean_t canSleep
);
181 int vmxnet3_alloc_dma_mem_512(vmxnet3_softc_t
*dp
, vmxnet3_dmabuf_t
*dma
,
182 size_t size
, boolean_t canSleep
);
183 void vmxnet3_free_dma_mem(vmxnet3_dmabuf_t
*dma
);
184 int vmxnet3_getprop(vmxnet3_softc_t
*dp
, char *name
, int min
, int max
,
187 int vmxnet3_txqueue_init(vmxnet3_softc_t
*dp
, vmxnet3_txqueue_t
*txq
);
188 mblk_t
*vmxnet3_tx(void *data
, mblk_t
*mps
);
189 boolean_t
vmxnet3_tx_complete(vmxnet3_softc_t
*dp
, vmxnet3_txqueue_t
*txq
);
190 void vmxnet3_txqueue_fini(vmxnet3_softc_t
*dp
, vmxnet3_txqueue_t
*txq
);
192 int vmxnet3_rxqueue_init(vmxnet3_softc_t
*dp
, vmxnet3_rxqueue_t
*rxq
);
193 mblk_t
*vmxnet3_rx_intr(vmxnet3_softc_t
*dp
, vmxnet3_rxqueue_t
*rxq
);
194 void vmxnet3_rxqueue_fini(vmxnet3_softc_t
*dp
, vmxnet3_rxqueue_t
*rxq
);
195 void vmxnet3_log(int level
, vmxnet3_softc_t
*dp
, char *fmt
, ...);
197 extern ddi_device_acc_attr_t vmxnet3_dev_attr
;
199 extern int vmxnet3s_debug
;
201 #define VMXNET3_MODNAME "vmxnet3s"
202 #define VMXNET3_DRIVER_VERSION_STRING "1.1.0.0"
205 #define VMXNET3_WARN(Device, ...) \
206 dev_err((Device)->dip, CE_WARN, "!" __VA_ARGS__)
209 #define VMXNET3_DEBUG(Device, Level, ...) { \
210 if (Level <= vmxnet3s_debug) { \
211 dev_err((Device)->dip, CE_CONT, "?" __VA_ARGS__); \
215 #define VMXNET3_DEBUG(Device, Level, ...)
218 #define MACADDR_FMT "%02x:%02x:%02x:%02x:%02x:%02x"
219 #define MACADDR_FMT_ARGS(mac) mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]
221 /* Default ring size */
222 #define VMXNET3_DEF_TX_RING_SIZE 256
223 #define VMXNET3_DEF_RX_RING_SIZE 256
225 /* Register access helpers */
226 #define VMXNET3_BAR0_GET32(Device, Reg) \
227 ddi_get32((Device)->bar0Handle, (uint32_t *)((Device)->bar0 + (Reg)))
228 #define VMXNET3_BAR0_PUT32(Device, Reg, Value) \
229 ddi_put32((Device)->bar0Handle, (uint32_t *)((Device)->bar0 + (Reg)), \
231 #define VMXNET3_BAR1_GET32(Device, Reg) \
232 ddi_get32((Device)->bar1Handle, (uint32_t *)((Device)->bar1 + (Reg)))
233 #define VMXNET3_BAR1_PUT32(Device, Reg, Value) \
234 ddi_put32((Device)->bar1Handle, (uint32_t *)((Device)->bar1 + (Reg)), \
238 #define VMXNET3_DS(Device) ((Vmxnet3_DriverShared *) (Device)->sharedData.buf)
239 #define VMXNET3_TQDESC(Device) \
240 ((Vmxnet3_TxQueueDesc *) (Device)->queueDescs.buf)
241 #define VMXNET3_RQDESC(Device) \
242 ((Vmxnet3_RxQueueDesc *) ((Device)->queueDescs.buf + \
243 sizeof (Vmxnet3_TxQueueDesc)))
245 #define VMXNET3_ADDR_LO(addr) ((uint32_t)(addr))
246 #define VMXNET3_ADDR_HI(addr) ((uint32_t)(((uint64_t)(addr)) >> 32))
248 #define VMXNET3_GET_DESC(Ring, Idx) \
249 (((Vmxnet3_GenericDesc *) (Ring)->dma.buf) + Idx)
252 #define VMXNET3_INC_RING_IDX(Ring, Idx) { \
254 if ((Idx) == (Ring)->size) { \
260 #define VMXNET3_DEC_RING_IDX(Ring, Idx) { \
262 (Idx) = (Ring)->size; \
268 #define PCI_VENDOR_ID_VMWARE 0x15AD
269 #define PCI_DEVICE_ID_VMWARE_VMXNET3 0x07B0
271 #endif /* _VMXNET3_H_ */