13976
|
1 |
/*********************************************************
|
|
2 |
* Copyright (C) 2007 VMware, Inc. All rights reserved.
|
|
3 |
*
|
|
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.
|
|
8 |
*
|
|
9 |
* You can obtain a copy of the License at
|
|
10 |
* http://www.opensource.org/licenses/cddl1.php
|
|
11 |
*
|
|
12 |
* See the License for the specific language governing permissions
|
|
13 |
* and limitations under the License.
|
|
14 |
*
|
|
15 |
*********************************************************/
|
|
16 |
/*
|
14277
|
17 |
* Copyright (c) 2012, 2014 by Delphix. All rights reserved.
|
13976
|
18 |
*/
|
|
19 |
|
|
20 |
#include <vmxnet3_solaris.h>
|
|
21 |
|
|
22 |
/*
|
|
23 |
* This driver is based on VMware's version 261024, and contains additional
|
|
24 |
* enhancements (see README.txt).
|
|
25 |
*/
|
|
26 |
#define BUILD_NUMBER_NUMERIC 261024
|
|
27 |
#define BUILD_NUMBER_NUMERIC_STRING "261024-il1"
|
|
28 |
|
|
29 |
/*
|
|
30 |
* TODO:
|
|
31 |
* - Tx data ring
|
|
32 |
* - MAC_CAPAB_POLL support
|
|
33 |
* - JF support
|
|
34 |
* - Dynamic RX pool
|
|
35 |
*/
|
|
36 |
|
|
37 |
/*
|
|
38 |
* Forward declarations
|
|
39 |
*/
|
|
40 |
static int vmxnet3_getstat(void *, uint_t, uint64_t *);
|
|
41 |
static int vmxnet3_start(void *);
|
|
42 |
static void vmxnet3_stop(void *);
|
|
43 |
static int vmxnet3_setpromisc(void *, boolean_t);
|
|
44 |
static void vmxnet3_ioctl(void *arg, queue_t *wq, mblk_t *mp);
|
|
45 |
static int vmxnet3_multicst(void *, boolean_t, const uint8_t *);
|
|
46 |
static int vmxnet3_unicst(void *, const uint8_t *);
|
|
47 |
static boolean_t vmxnet3_getcapab(void *, mac_capab_t, void *);
|
|
48 |
static int vmxnet3_setmacprop(void *, const char *, mac_prop_id_t, uint_t,
|
|
49 |
const void *);
|
|
50 |
static void vmxnet3_macpropinfo(void *, const char *, mac_prop_id_t,
|
|
51 |
mac_prop_info_handle_t);
|
|
52 |
|
|
53 |
int vmxnet3_debug_level;
|
|
54 |
|
|
55 |
/* MAC callbacks */
|
|
56 |
static mac_callbacks_t vmxnet3_mac_callbacks = {
|
|
57 |
.mc_callbacks = MC_GETCAPAB | MC_IOCTL | MC_SETPROP | MC_PROPINFO,
|
|
58 |
.mc_getstat = vmxnet3_getstat,
|
|
59 |
.mc_start = vmxnet3_start,
|
|
60 |
.mc_stop = vmxnet3_stop,
|
|
61 |
.mc_setpromisc = vmxnet3_setpromisc,
|
|
62 |
.mc_multicst = vmxnet3_multicst,
|
|
63 |
.mc_unicst = vmxnet3_unicst,
|
|
64 |
.mc_tx = vmxnet3_tx,
|
|
65 |
.mc_ioctl = vmxnet3_ioctl,
|
|
66 |
.mc_getcapab = vmxnet3_getcapab,
|
|
67 |
.mc_setprop = vmxnet3_setmacprop,
|
|
68 |
.mc_propinfo = vmxnet3_macpropinfo
|
|
69 |
};
|
|
70 |
|
|
71 |
/* Tx DMA engine description */
|
|
72 |
static ddi_dma_attr_t vmxnet3_dma_attrs_tx = {
|
|
73 |
DMA_ATTR_V0, /* dma_attr_version */
|
|
74 |
0x0000000000000000ull, /* dma_attr_addr_lo */
|
|
75 |
0xFFFFFFFFFFFFFFFFull, /* dma_attr_addr_hi */
|
|
76 |
0xFFFFFFFFFFFFFFFFull, /* dma_attr_count_max */
|
|
77 |
0x0000000000000001ull, /* dma_attr_align */
|
|
78 |
0x0000000000000001ull, /* dma_attr_burstsizes */
|
|
79 |
0x00000001, /* dma_attr_minxfer */
|
|
80 |
0x000000000000FFFFull, /* dma_attr_maxxfer */
|
|
81 |
0xFFFFFFFFFFFFFFFFull, /* dma_attr_seg */
|
|
82 |
-1, /* dma_attr_sgllen */
|
|
83 |
0x00000001, /* dma_attr_granular */
|
|
84 |
0 /* dma_attr_flags */
|
|
85 |
};
|
|
86 |
|
|
87 |
/* --- */
|
|
88 |
|
|
89 |
/*
|
|
90 |
*---------------------------------------------------------------------------
|
|
91 |
*
|
|
92 |
* vmxnet3_getstat --
|
|
93 |
*
|
|
94 |
* Fetch the statistics of a vmxnet3 device.
|
|
95 |
*
|
|
96 |
* Results:
|
|
97 |
* DDI_FAILURE.
|
|
98 |
*
|
|
99 |
* Side effects:
|
|
100 |
* None.
|
|
101 |
*
|
|
102 |
*---------------------------------------------------------------------------
|
|
103 |
*/
|
|
104 |
static int
|
|
105 |
vmxnet3_getstat(void *data, uint_t stat, uint64_t *val)
|
|
106 |
{
|
|
107 |
vmxnet3_softc_t *dp = data;
|
|
108 |
UPT1_TxStats *txStats;
|
|
109 |
UPT1_RxStats *rxStats;
|
|
110 |
|
|
111 |
VMXNET3_DEBUG(dp, 3, "getstat(%u)\n", stat);
|
|
112 |
|
|
113 |
if (!dp->devEnabled) {
|
|
114 |
return DDI_FAILURE;
|
|
115 |
}
|
|
116 |
|
|
117 |
txStats = &VMXNET3_TQDESC(dp)->stats;
|
|
118 |
rxStats = &VMXNET3_RQDESC(dp)->stats;
|
|
119 |
|
|
120 |
/*
|
|
121 |
* First touch the related register
|
|
122 |
*/
|
|
123 |
switch (stat) {
|
|
124 |
case MAC_STAT_MULTIRCV:
|
|
125 |
case MAC_STAT_BRDCSTRCV:
|
|
126 |
case MAC_STAT_MULTIXMT:
|
|
127 |
case MAC_STAT_BRDCSTXMT:
|
|
128 |
case MAC_STAT_NORCVBUF:
|
|
129 |
case MAC_STAT_IERRORS:
|
|
130 |
case MAC_STAT_NOXMTBUF:
|
|
131 |
case MAC_STAT_OERRORS:
|
|
132 |
case MAC_STAT_RBYTES:
|
|
133 |
case MAC_STAT_IPACKETS:
|
|
134 |
case MAC_STAT_OBYTES:
|
|
135 |
case MAC_STAT_OPACKETS:
|
|
136 |
VMXNET3_BAR1_PUT32(dp, VMXNET3_REG_CMD, VMXNET3_CMD_GET_STATS);
|
|
137 |
break;
|
|
138 |
case MAC_STAT_IFSPEED:
|
|
139 |
case MAC_STAT_COLLISIONS:
|
|
140 |
case ETHER_STAT_LINK_DUPLEX:
|
|
141 |
/* nothing */
|
|
142 |
break;
|
|
143 |
default:
|
|
144 |
return DDI_FAILURE;
|
|
145 |
}
|
|
146 |
|
|
147 |
/*
|
|
148 |
* Then fetch the corresponding stat
|
|
149 |
*/
|
|
150 |
switch (stat) {
|
|
151 |
case MAC_STAT_IFSPEED:
|
|
152 |
*val = dp->linkSpeed;
|
|
153 |
break;
|
|
154 |
case MAC_STAT_MULTIRCV:
|
|
155 |
*val = rxStats->mcastPktsRxOK;
|
|
156 |
break;
|
|
157 |
case MAC_STAT_BRDCSTRCV:
|
|
158 |
*val = rxStats->bcastPktsRxOK;
|
|
159 |
break;
|
|
160 |
case MAC_STAT_MULTIXMT:
|
|
161 |
*val = txStats->mcastPktsTxOK;
|
|
162 |
break;
|
|
163 |
case MAC_STAT_BRDCSTXMT:
|
|
164 |
*val = txStats->bcastPktsTxOK;
|
|
165 |
break;
|
|
166 |
case MAC_STAT_NORCVBUF:
|
|
167 |
*val = rxStats->pktsRxOutOfBuf + dp->rx_alloc_failed;
|
|
168 |
break;
|
|
169 |
case MAC_STAT_IERRORS:
|
|
170 |
*val = rxStats->pktsRxError;
|
|
171 |
break;
|
|
172 |
case MAC_STAT_NOXMTBUF:
|
|
173 |
*val = txStats->pktsTxDiscard + dp->tx_pullup_failed;
|
|
174 |
break;
|
|
175 |
case MAC_STAT_OERRORS:
|
|
176 |
*val = txStats->pktsTxError + dp->tx_error;
|
|
177 |
break;
|
|
178 |
case MAC_STAT_COLLISIONS:
|
|
179 |
*val = 0;
|
|
180 |
break;
|
|
181 |
case MAC_STAT_RBYTES:
|
14277
|
182 |
*val = rxStats->ucastBytesRxOK +
|
13976
|
183 |
rxStats->mcastBytesRxOK +
|
|
184 |
rxStats->bcastBytesRxOK;
|
|
185 |
break;
|
|
186 |
case MAC_STAT_IPACKETS:
|
14277
|
187 |
*val = rxStats->ucastPktsRxOK +
|
13976
|
188 |
rxStats->mcastPktsRxOK +
|
|
189 |
rxStats->bcastPktsRxOK;
|
|
190 |
break;
|
|
191 |
case MAC_STAT_OBYTES:
|
14277
|
192 |
*val = txStats->ucastBytesTxOK +
|
13976
|
193 |
txStats->mcastBytesTxOK +
|
|
194 |
txStats->bcastBytesTxOK;
|
|
195 |
break;
|
|
196 |
case MAC_STAT_OPACKETS:
|
14277
|
197 |
*val = txStats->ucastPktsTxOK +
|
13976
|
198 |
txStats->mcastPktsTxOK +
|
|
199 |
txStats->bcastPktsTxOK;
|
|
200 |
break;
|
|
201 |
case ETHER_STAT_LINK_DUPLEX:
|
|
202 |
*val = LINK_DUPLEX_FULL;
|
|
203 |
break;
|
|
204 |
default:
|
|
205 |
ASSERT(B_FALSE);
|
|
206 |
}
|
|
207 |
|
|
208 |
return DDI_SUCCESS;
|
|
209 |
}
|
|
210 |
|
|
211 |
/*
|
|
212 |
*---------------------------------------------------------------------------
|
|
213 |
*
|
|
214 |
* vmxnet3_prepare_drivershared --
|
|
215 |
*
|
|
216 |
* Allocate and initialize the shared data structures
|
|
217 |
* of a vmxnet3 device.
|
|
218 |
*
|
|
219 |
* Results:
|
|
220 |
* DDI_SUCCESS or DDI_FAILURE.
|
|
221 |
*
|
|
222 |
* Side effects:
|
|
223 |
* None.
|
|
224 |
*
|
|
225 |
*---------------------------------------------------------------------------
|
|
226 |
*/
|
|
227 |
static int
|
|
228 |
vmxnet3_prepare_drivershared(vmxnet3_softc_t *dp)
|
|
229 |
{
|
|
230 |
Vmxnet3_DriverShared *ds;
|
|
231 |
size_t allocSize = sizeof(Vmxnet3_DriverShared);
|
|
232 |
|
|
233 |
if (vmxnet3_alloc_dma_mem_1(dp, &dp->sharedData, allocSize,
|
|
234 |
B_TRUE) != DDI_SUCCESS) {
|
|
235 |
return DDI_FAILURE;
|
|
236 |
}
|
|
237 |
ds = VMXNET3_DS(dp);
|
|
238 |
(void) memset(ds, 0, allocSize);
|
|
239 |
|
|
240 |
allocSize = sizeof(Vmxnet3_TxQueueDesc) + sizeof(Vmxnet3_RxQueueDesc);
|
|
241 |
if (vmxnet3_alloc_dma_mem_128(dp, &dp->queueDescs, allocSize,
|
|
242 |
B_TRUE) != DDI_SUCCESS) {
|
|
243 |
vmxnet3_free_dma_mem(&dp->sharedData);
|
|
244 |
return DDI_FAILURE;
|
|
245 |
}
|
|
246 |
(void) memset(dp->queueDescs.buf, 0, allocSize);
|
|
247 |
|
|
248 |
ds->magic = VMXNET3_REV1_MAGIC;
|
|
249 |
|
|
250 |
/* Take care of most of devRead */
|
|
251 |
ds->devRead.misc.driverInfo.version = BUILD_NUMBER_NUMERIC;
|
|
252 |
#ifdef _LP64
|
|
253 |
ds->devRead.misc.driverInfo.gos.gosBits = VMXNET3_GOS_BITS_64;
|
|
254 |
#else
|
|
255 |
ds->devRead.misc.driverInfo.gos.gosBits = VMXNET3_GOS_BITS_32;
|
|
256 |
#endif
|
|
257 |
ds->devRead.misc.driverInfo.gos.gosType = VMXNET3_GOS_TYPE_SOLARIS;
|
|
258 |
ds->devRead.misc.driverInfo.gos.gosVer = 10;
|
|
259 |
ds->devRead.misc.driverInfo.vmxnet3RevSpt = 1;
|
|
260 |
ds->devRead.misc.driverInfo.uptVerSpt = 1;
|
|
261 |
|
|
262 |
ds->devRead.misc.uptFeatures = UPT1_F_RXCSUM;
|
|
263 |
ds->devRead.misc.mtu = dp->cur_mtu;
|
|
264 |
|
|
265 |
// XXX: ds->devRead.misc.maxNumRxSG
|
|
266 |
ds->devRead.misc.numTxQueues = 1;
|
|
267 |
ds->devRead.misc.numRxQueues = 1;
|
|
268 |
ds->devRead.misc.queueDescPA = dp->queueDescs.bufPA;
|
|
269 |
ds->devRead.misc.queueDescLen = allocSize;
|
|
270 |
|
|
271 |
/* TxQueue and RxQueue information is filled in other functions */
|
|
272 |
|
|
273 |
ds->devRead.intrConf.autoMask = (dp->intrMaskMode == VMXNET3_IMM_AUTO);
|
|
274 |
ds->devRead.intrConf.numIntrs = 1;
|
|
275 |
// XXX: ds->intr.modLevels
|
|
276 |
ds->devRead.intrConf.eventIntrIdx = 0;
|
|
277 |
|
|
278 |
VMXNET3_BAR1_PUT32(dp, VMXNET3_REG_DSAL, VMXNET3_ADDR_LO(dp->sharedData.bufPA));
|
|
279 |
VMXNET3_BAR1_PUT32(dp, VMXNET3_REG_DSAH, VMXNET3_ADDR_HI(dp->sharedData.bufPA));
|
|
280 |
|
|
281 |
return DDI_SUCCESS;
|
|
282 |
}
|
|
283 |
|
|
284 |
/*
|
|
285 |
*---------------------------------------------------------------------------
|
|
286 |
*
|
|
287 |
* vmxnet3_destroy_drivershared --
|
|
288 |
*
|
|
289 |
* Destroy the shared data structures of a vmxnet3 device.
|
|
290 |
*
|
|
291 |
* Results:
|
|
292 |
* None.
|
|
293 |
*
|
|
294 |
* Side effects:
|
|
295 |
* None.
|
|
296 |
*
|
|
297 |
*---------------------------------------------------------------------------
|
|
298 |
*/
|
|
299 |
static void
|
|
300 |
vmxnet3_destroy_drivershared(vmxnet3_softc_t *dp)
|
|
301 |
{
|
|
302 |
VMXNET3_BAR1_PUT32(dp, VMXNET3_REG_DSAL, 0);
|
|
303 |
VMXNET3_BAR1_PUT32(dp, VMXNET3_REG_DSAH, 0);
|
|
304 |
|
|
305 |
vmxnet3_free_dma_mem(&dp->queueDescs);
|
|
306 |
vmxnet3_free_dma_mem(&dp->sharedData);
|
|
307 |
}
|
|
308 |
|
|
309 |
/*
|
|
310 |
*---------------------------------------------------------------------------
|
|
311 |
*
|
|
312 |
* vmxnet3_alloc_cmdring --
|
|
313 |
*
|
|
314 |
* Allocate and initialize the command ring of a queue.
|
|
315 |
*
|
|
316 |
* Results:
|
|
317 |
* DDI_SUCCESS or DDI_FAILURE.
|
|
318 |
*
|
|
319 |
* Side effects:
|
|
320 |
* None.
|
|
321 |
*
|
|
322 |
*---------------------------------------------------------------------------
|
|
323 |
*/
|
|
324 |
static int
|
|
325 |
vmxnet3_alloc_cmdring(vmxnet3_softc_t *dp, vmxnet3_cmdring_t *cmdRing)
|
|
326 |
{
|
|
327 |
size_t ringSize = cmdRing->size * sizeof(Vmxnet3_TxDesc);
|
|
328 |
|
|
329 |
if (vmxnet3_alloc_dma_mem_512(dp, &cmdRing->dma, ringSize,
|
|
330 |
B_TRUE) != DDI_SUCCESS) {
|
|
331 |
return DDI_FAILURE;
|
|
332 |
}
|
|
333 |
(void) memset(cmdRing->dma.buf, 0, ringSize);
|
|
334 |
cmdRing->avail = cmdRing->size;
|
|
335 |
cmdRing->next2fill = 0;
|
|
336 |
cmdRing->gen = VMXNET3_INIT_GEN;
|
|
337 |
|
|
338 |
return DDI_SUCCESS;
|
|
339 |
}
|
|
340 |
|
|
341 |
/*
|
|
342 |
*---------------------------------------------------------------------------
|
|
343 |
*
|
|
344 |
* vmxnet3_alloc_compring --
|
|
345 |
*
|
|
346 |
* Allocate and initialize the completion ring of a queue.
|
|
347 |
*
|
|
348 |
* Results:
|
|
349 |
* DDI_SUCCESS or DDI_FAILURE.
|
|
350 |
*
|
|
351 |
* Side effects:
|
|
352 |
* None.
|
|
353 |
*
|
|
354 |
*---------------------------------------------------------------------------
|
|
355 |
*/
|
|
356 |
static int
|
|
357 |
vmxnet3_alloc_compring(vmxnet3_softc_t *dp, vmxnet3_compring_t *compRing)
|
|
358 |
{
|
|
359 |
size_t ringSize = compRing->size * sizeof(Vmxnet3_TxCompDesc);
|
|
360 |
|
|
361 |
if (vmxnet3_alloc_dma_mem_512(dp, &compRing->dma, ringSize,
|
|
362 |
B_TRUE) != DDI_SUCCESS) {
|
|
363 |
return DDI_FAILURE;
|
|
364 |
}
|
|
365 |
(void) memset(compRing->dma.buf, 0, ringSize);
|
|
366 |
compRing->next2comp = 0;
|
|
367 |
compRing->gen = VMXNET3_INIT_GEN;
|
|
368 |
|
|
369 |
return DDI_SUCCESS;
|
|
370 |
}
|
|
371 |
|
|
372 |
/*
|
|
373 |
*---------------------------------------------------------------------------
|
|
374 |
*
|
|
375 |
* vmxnet3_prepare_txqueue --
|
|
376 |
*
|
|
377 |
* Initialize the tx queue of a vmxnet3 device.
|
|
378 |
*
|
|
379 |
* Results:
|
|
380 |
* DDI_SUCCESS or DDI_FAILURE.
|
|
381 |
*
|
|
382 |
* Side effects:
|
|
383 |
* None.
|
|
384 |
*
|
|
385 |
*---------------------------------------------------------------------------
|
|
386 |
*/
|
|
387 |
static int
|
|
388 |
vmxnet3_prepare_txqueue(vmxnet3_softc_t *dp)
|
|
389 |
{
|
|
390 |
Vmxnet3_TxQueueDesc *tqdesc = VMXNET3_TQDESC(dp);
|
|
391 |
vmxnet3_txqueue_t *txq = &dp->txQueue;
|
|
392 |
|
|
393 |
ASSERT(!(txq->cmdRing.size & VMXNET3_RING_SIZE_MASK));
|
|
394 |
ASSERT(!(txq->compRing.size & VMXNET3_RING_SIZE_MASK));
|
|
395 |
ASSERT(!txq->cmdRing.dma.buf && !txq->compRing.dma.buf);
|
|
396 |
|
|
397 |
if (vmxnet3_alloc_cmdring(dp, &txq->cmdRing) != DDI_SUCCESS) {
|
|
398 |
goto error;
|
|
399 |
}
|
|
400 |
tqdesc->conf.txRingBasePA = txq->cmdRing.dma.bufPA;
|
|
401 |
tqdesc->conf.txRingSize = txq->cmdRing.size;
|
|
402 |
tqdesc->conf.dataRingBasePA = 0;
|
|
403 |
tqdesc->conf.dataRingSize = 0;
|
|
404 |
|
|
405 |
if (vmxnet3_alloc_compring(dp, &txq->compRing) != DDI_SUCCESS) {
|
|
406 |
goto error_cmdring;
|
|
407 |
}
|
|
408 |
tqdesc->conf.compRingBasePA = txq->compRing.dma.bufPA;
|
|
409 |
tqdesc->conf.compRingSize = txq->compRing.size;
|
|
410 |
|
|
411 |
txq->metaRing = kmem_zalloc(txq->cmdRing.size*sizeof(vmxnet3_metatx_t),
|
|
412 |
KM_SLEEP);
|
|
413 |
ASSERT(txq->metaRing);
|
|
414 |
|
|
415 |
if (vmxnet3_txqueue_init(dp, txq) != DDI_SUCCESS) {
|
|
416 |
goto error_mpring;
|
|
417 |
}
|
|
418 |
|
|
419 |
return DDI_SUCCESS;
|
|
420 |
|
|
421 |
error_mpring:
|
|
422 |
kmem_free(txq->metaRing, txq->cmdRing.size*sizeof(vmxnet3_metatx_t));
|
|
423 |
vmxnet3_free_dma_mem(&txq->compRing.dma);
|
|
424 |
error_cmdring:
|
|
425 |
vmxnet3_free_dma_mem(&txq->cmdRing.dma);
|
|
426 |
error:
|
|
427 |
return DDI_FAILURE;
|
|
428 |
}
|
|
429 |
|
|
430 |
/*
|
|
431 |
*---------------------------------------------------------------------------
|
|
432 |
*
|
|
433 |
* vmxnet3_prepare_rxqueue --
|
|
434 |
*
|
|
435 |
* Initialize the rx queue of a vmxnet3 device.
|
|
436 |
*
|
|
437 |
* Results:
|
|
438 |
* DDI_SUCCESS or DDI_FAILURE.
|
|
439 |
*
|
|
440 |
* Side effects:
|
|
441 |
* None.
|
|
442 |
*
|
|
443 |
*---------------------------------------------------------------------------
|
|
444 |
*/
|
|
445 |
static int
|
|
446 |
vmxnet3_prepare_rxqueue(vmxnet3_softc_t *dp)
|
|
447 |
{
|
|
448 |
Vmxnet3_RxQueueDesc *rqdesc = VMXNET3_RQDESC(dp);
|
|
449 |
vmxnet3_rxqueue_t *rxq = &dp->rxQueue;
|
|
450 |
|
|
451 |
ASSERT(!(rxq->cmdRing.size & VMXNET3_RING_SIZE_MASK));
|
|
452 |
ASSERT(!(rxq->compRing.size & VMXNET3_RING_SIZE_MASK));
|
|
453 |
ASSERT(!rxq->cmdRing.dma.buf && !rxq->compRing.dma.buf);
|
|
454 |
|
|
455 |
if (vmxnet3_alloc_cmdring(dp, &rxq->cmdRing) != DDI_SUCCESS) {
|
|
456 |
goto error;
|
|
457 |
}
|
|
458 |
rqdesc->conf.rxRingBasePA[0] = rxq->cmdRing.dma.bufPA;
|
|
459 |
rqdesc->conf.rxRingSize[0] = rxq->cmdRing.size;
|
|
460 |
rqdesc->conf.rxRingBasePA[1] = 0;
|
|
461 |
rqdesc->conf.rxRingSize[1] = 0;
|
|
462 |
|
|
463 |
if (vmxnet3_alloc_compring(dp, &rxq->compRing) != DDI_SUCCESS) {
|
|
464 |
goto error_cmdring;
|
|
465 |
}
|
|
466 |
rqdesc->conf.compRingBasePA = rxq->compRing.dma.bufPA;
|
|
467 |
rqdesc->conf.compRingSize = rxq->compRing.size;
|
|
468 |
|
|
469 |
rxq->bufRing = kmem_zalloc(rxq->cmdRing.size*sizeof(vmxnet3_bufdesc_t),
|
|
470 |
KM_SLEEP);
|
|
471 |
ASSERT(rxq->bufRing);
|
|
472 |
|
|
473 |
if (vmxnet3_rxqueue_init(dp, rxq) != DDI_SUCCESS) {
|
|
474 |
goto error_bufring;
|
|
475 |
}
|
|
476 |
|
|
477 |
return DDI_SUCCESS;
|
|
478 |
|
|
479 |
error_bufring:
|
|
480 |
kmem_free(rxq->bufRing, rxq->cmdRing.size*sizeof(vmxnet3_bufdesc_t));
|
|
481 |
vmxnet3_free_dma_mem(&rxq->compRing.dma);
|
|
482 |
error_cmdring:
|
|
483 |
vmxnet3_free_dma_mem(&rxq->cmdRing.dma);
|
|
484 |
error:
|
|
485 |
return DDI_FAILURE;
|
|
486 |
}
|
|
487 |
|
|
488 |
/*
|
|
489 |
*---------------------------------------------------------------------------
|
|
490 |
*
|
|
491 |
* vmxnet3_destroy_txqueue --
|
|
492 |
*
|
|
493 |
* Destroy the tx queue of a vmxnet3 device.
|
|
494 |
*
|
|
495 |
* Results:
|
|
496 |
* None.
|
|
497 |
*
|
|
498 |
* Side effects:
|
|
499 |
* None.
|
|
500 |
*
|
|
501 |
*---------------------------------------------------------------------------
|
|
502 |
*/
|
|
503 |
static void
|
|
504 |
vmxnet3_destroy_txqueue(vmxnet3_softc_t *dp)
|
|
505 |
{
|
|
506 |
vmxnet3_txqueue_t *txq = &dp->txQueue;
|
|
507 |
|
|
508 |
ASSERT(txq->metaRing);
|
|
509 |
ASSERT(txq->cmdRing.dma.buf && txq->compRing.dma.buf);
|
|
510 |
|
|
511 |
vmxnet3_txqueue_fini(dp, txq);
|
|
512 |
|
|
513 |
kmem_free(txq->metaRing, txq->cmdRing.size*sizeof(vmxnet3_metatx_t));
|
|
514 |
|
|
515 |
vmxnet3_free_dma_mem(&txq->cmdRing.dma);
|
|
516 |
vmxnet3_free_dma_mem(&txq->compRing.dma);
|
|
517 |
}
|
|
518 |
|
|
519 |
/*
|
|
520 |
*---------------------------------------------------------------------------
|
|
521 |
*
|
|
522 |
* vmxnet3_destroy_rxqueue --
|
|
523 |
*
|
|
524 |
* Destroy the rx queue of a vmxnet3 device.
|
|
525 |
*
|
|
526 |
* Results:
|
|
527 |
* None.
|
|
528 |
*
|
|
529 |
* Side effects:
|
|
530 |
* None.
|
|
531 |
*
|
|
532 |
*---------------------------------------------------------------------------
|
|
533 |
*/
|
|
534 |
static void
|
|
535 |
vmxnet3_destroy_rxqueue(vmxnet3_softc_t *dp)
|
|
536 |
{
|
|
537 |
vmxnet3_rxqueue_t *rxq = &dp->rxQueue;
|
|
538 |
|
|
539 |
ASSERT(rxq->bufRing);
|
|
540 |
ASSERT(rxq->cmdRing.dma.buf && rxq->compRing.dma.buf);
|
|
541 |
|
|
542 |
vmxnet3_rxqueue_fini(dp, rxq);
|
|
543 |
|
|
544 |
kmem_free(rxq->bufRing, rxq->cmdRing.size*sizeof(vmxnet3_bufdesc_t));
|
|
545 |
|
|
546 |
vmxnet3_free_dma_mem(&rxq->cmdRing.dma);
|
|
547 |
vmxnet3_free_dma_mem(&rxq->compRing.dma);
|
|
548 |
}
|
|
549 |
|
|
550 |
/*
|
|
551 |
*---------------------------------------------------------------------------
|
|
552 |
*
|
|
553 |
* vmxnet3_refresh_rxfilter --
|
|
554 |
*
|
|
555 |
* Apply new RX filters settings to a vmxnet3 device.
|
|
556 |
*
|
|
557 |
* Results:
|
|
558 |
* None.
|
|
559 |
*
|
|
560 |
* Side effects:
|
|
561 |
* None.
|
|
562 |
*
|
|
563 |
*---------------------------------------------------------------------------
|
|
564 |
*/
|
|
565 |
static void
|
|
566 |
vmxnet3_refresh_rxfilter(vmxnet3_softc_t *dp)
|
|
567 |
{
|
|
568 |
Vmxnet3_DriverShared *ds = VMXNET3_DS(dp);
|
|
569 |
|
|
570 |
ds->devRead.rxFilterConf.rxMode = dp->rxMode;
|
|
571 |
VMXNET3_BAR1_PUT32(dp, VMXNET3_REG_CMD, VMXNET3_CMD_UPDATE_RX_MODE);
|
|
572 |
}
|
|
573 |
|
|
574 |
/*
|
|
575 |
*---------------------------------------------------------------------------
|
|
576 |
*
|
|
577 |
* vmxnet3_refresh_linkstate --
|
|
578 |
*
|
|
579 |
* Fetch the link state of a vmxnet3 device.
|
|
580 |
*
|
|
581 |
* Results:
|
|
582 |
* None.
|
|
583 |
*
|
|
584 |
* Side effects:
|
|
585 |
* None.
|
|
586 |
*
|
|
587 |
*---------------------------------------------------------------------------
|
|
588 |
*/
|
|
589 |
static void
|
|
590 |
vmxnet3_refresh_linkstate(vmxnet3_softc_t *dp)
|
|
591 |
{
|
|
592 |
uint32_t ret32;
|
|
593 |
|
|
594 |
VMXNET3_BAR1_PUT32(dp, VMXNET3_REG_CMD, VMXNET3_CMD_GET_LINK);
|
|
595 |
ret32 = VMXNET3_BAR1_GET32(dp, VMXNET3_REG_CMD);
|
|
596 |
if (ret32 & 1) {
|
|
597 |
dp->linkState = LINK_STATE_UP;
|
|
598 |
dp->linkSpeed = (ret32 >> 16) * 1000000ULL;
|
|
599 |
} else {
|
|
600 |
dp->linkState = LINK_STATE_DOWN;
|
|
601 |
dp->linkSpeed = 0;
|
|
602 |
}
|
|
603 |
}
|
|
604 |
|
|
605 |
/*
|
|
606 |
*---------------------------------------------------------------------------
|
|
607 |
*
|
|
608 |
* vmxnet3_start --
|
|
609 |
*
|
|
610 |
* Start a vmxnet3 device: allocate and initialize the shared data
|
|
611 |
* structures and send a start command to the device.
|
|
612 |
*
|
|
613 |
* Results:
|
|
614 |
* DDI_SUCCESS or DDI_FAILURE.
|
|
615 |
*
|
|
616 |
* Side effects:
|
|
617 |
* None.
|
|
618 |
*
|
|
619 |
*---------------------------------------------------------------------------
|
|
620 |
*/
|
|
621 |
static int
|
|
622 |
vmxnet3_start(void *data)
|
|
623 |
{
|
|
624 |
vmxnet3_softc_t *dp = data;
|
|
625 |
Vmxnet3_TxQueueDesc *tqdesc;
|
|
626 |
Vmxnet3_RxQueueDesc *rqdesc;
|
|
627 |
int txQueueSize, rxQueueSize;
|
|
628 |
uint32_t ret32;
|
|
629 |
|
|
630 |
VMXNET3_DEBUG(dp, 1, "start()\n");
|
|
631 |
|
|
632 |
/*
|
|
633 |
* Allocate vmxnet3's shared data and advertise its PA
|
|
634 |
*/
|
|
635 |
if (vmxnet3_prepare_drivershared(dp) != DDI_SUCCESS) {
|
|
636 |
VMXNET3_WARN(dp, "vmxnet3_prepare_drivershared() failed\n");
|
|
637 |
goto error;
|
|
638 |
}
|
|
639 |
tqdesc = VMXNET3_TQDESC(dp);
|
|
640 |
rqdesc = VMXNET3_RQDESC(dp);
|
|
641 |
|
|
642 |
/*
|
|
643 |
* Create and initialize the tx queue
|
|
644 |
*/
|
|
645 |
txQueueSize = vmxnet3_getprop(dp, "TxRingSize", 32, 4096,
|
|
646 |
VMXNET3_DEF_TX_RING_SIZE);
|
|
647 |
if (!(txQueueSize & VMXNET3_RING_SIZE_MASK)) {
|
|
648 |
dp->txQueue.cmdRing.size = txQueueSize;
|
|
649 |
dp->txQueue.compRing.size = txQueueSize;
|
|
650 |
dp->txQueue.sharedCtrl = &tqdesc->ctrl;
|
|
651 |
if (vmxnet3_prepare_txqueue(dp) != DDI_SUCCESS) {
|
|
652 |
VMXNET3_WARN(dp, "vmxnet3_prepare_txqueue() failed\n");
|
|
653 |
goto error_shared_data;
|
|
654 |
}
|
|
655 |
} else {
|
|
656 |
VMXNET3_WARN(dp, "invalid tx ring size (%d)\n", txQueueSize);
|
|
657 |
goto error_shared_data;
|
|
658 |
}
|
|
659 |
|
|
660 |
/*
|
|
661 |
* Create and initialize the rx queue
|
|
662 |
*/
|
|
663 |
rxQueueSize = vmxnet3_getprop(dp, "RxRingSize", 32, 4096,
|
|
664 |
VMXNET3_DEF_RX_RING_SIZE);
|
|
665 |
if (!(rxQueueSize & VMXNET3_RING_SIZE_MASK)) {
|
|
666 |
dp->rxQueue.cmdRing.size = rxQueueSize;
|
|
667 |
dp->rxQueue.compRing.size = rxQueueSize;
|
|
668 |
dp->rxQueue.sharedCtrl = &rqdesc->ctrl;
|
|
669 |
if (vmxnet3_prepare_rxqueue(dp) != DDI_SUCCESS) {
|
|
670 |
VMXNET3_WARN(dp, "vmxnet3_prepare_rxqueue() failed\n");
|
|
671 |
goto error_tx_queue;
|
|
672 |
}
|
|
673 |
} else {
|
|
674 |
VMXNET3_WARN(dp, "invalid rx ring size (%d)\n", rxQueueSize);
|
|
675 |
goto error_tx_queue;
|
|
676 |
}
|
|
677 |
|
|
678 |
/*
|
|
679 |
* Allocate the Tx DMA handle
|
|
680 |
*/
|
|
681 |
if (ddi_dma_alloc_handle(dp->dip, &vmxnet3_dma_attrs_tx, DDI_DMA_SLEEP,
|
|
682 |
NULL, &dp->txDmaHandle) != DDI_SUCCESS) {
|
|
683 |
VMXNET3_WARN(dp, "ddi_dma_alloc_handle() failed\n");
|
|
684 |
goto error_rx_queue;
|
|
685 |
}
|
|
686 |
|
|
687 |
/*
|
|
688 |
* Activate the device
|
|
689 |
*/
|
|
690 |
VMXNET3_BAR1_PUT32(dp, VMXNET3_REG_CMD, VMXNET3_CMD_ACTIVATE_DEV);
|
|
691 |
ret32 = VMXNET3_BAR1_GET32(dp, VMXNET3_REG_CMD);
|
|
692 |
if (ret32) {
|
|
693 |
VMXNET3_WARN(dp, "ACTIVATE_DEV failed: 0x%x\n", ret32);
|
|
694 |
goto error_txhandle;
|
|
695 |
}
|
|
696 |
dp->devEnabled = B_TRUE;
|
|
697 |
|
|
698 |
VMXNET3_BAR0_PUT32(dp, VMXNET3_REG_RXPROD, dp->txQueue.cmdRing.size - 1);
|
|
699 |
|
|
700 |
/*
|
|
701 |
* Update the RX filters, must be done after ACTIVATE_DEV
|
|
702 |
*/
|
|
703 |
dp->rxMode = VMXNET3_RXM_UCAST | VMXNET3_RXM_BCAST;
|
|
704 |
vmxnet3_refresh_rxfilter(dp);
|
|
705 |
|
|
706 |
/*
|
|
707 |
* Get the link state now because no events will be generated
|
|
708 |
*/
|
|
709 |
vmxnet3_refresh_linkstate(dp);
|
|
710 |
mac_link_update(dp->mac, dp->linkState);
|
|
711 |
|
|
712 |
/*
|
|
713 |
* Finally, unmask the interrupt
|
|
714 |
*/
|
|
715 |
VMXNET3_BAR0_PUT32(dp, VMXNET3_REG_IMR, 0);
|
|
716 |
|
|
717 |
return DDI_SUCCESS;
|
|
718 |
|
|
719 |
error_txhandle:
|
|
720 |
ddi_dma_free_handle(&dp->txDmaHandle);
|
|
721 |
error_rx_queue:
|
|
722 |
vmxnet3_destroy_rxqueue(dp);
|
|
723 |
error_tx_queue:
|
|
724 |
vmxnet3_destroy_txqueue(dp);
|
|
725 |
error_shared_data:
|
|
726 |
vmxnet3_destroy_drivershared(dp);
|
|
727 |
error:
|
|
728 |
return DDI_FAILURE;
|
|
729 |
}
|
|
730 |
|
|
731 |
/*
|
|
732 |
*---------------------------------------------------------------------------
|
|
733 |
*
|
|
734 |
* vmxnet3_stop --
|
|
735 |
*
|
|
736 |
* Stop a vmxnet3 device: send a stop command to the device and
|
|
737 |
* de-allocate the shared data structures.
|
|
738 |
*
|
|
739 |
* Results:
|
|
740 |
* None.
|
|
741 |
*
|
|
742 |
* Side effects:
|
|
743 |
* None.
|
|
744 |
*
|
|
745 |
*---------------------------------------------------------------------------
|
|
746 |
*/
|
|
747 |
static void
|
|
748 |
vmxnet3_stop(void *data)
|
|
749 |
{
|
|
750 |
vmxnet3_softc_t *dp = data;
|
|
751 |
|
|
752 |
VMXNET3_DEBUG(dp, 1, "stop()\n");
|
|
753 |
|
|
754 |
/*
|
|
755 |
* Take the 2 locks related to asynchronous events.
|
|
756 |
* These events should always check dp->devEnabled before poking dp.
|
|
757 |
*/
|
|
758 |
mutex_enter(&dp->intrLock);
|
|
759 |
mutex_enter(&dp->rxPoolLock);
|
|
760 |
VMXNET3_BAR0_PUT32(dp, VMXNET3_REG_IMR, 1);
|
|
761 |
dp->devEnabled = B_FALSE;
|
|
762 |
VMXNET3_BAR1_PUT32(dp, VMXNET3_REG_CMD, VMXNET3_CMD_QUIESCE_DEV);
|
|
763 |
mutex_exit(&dp->rxPoolLock);
|
|
764 |
mutex_exit(&dp->intrLock);
|
|
765 |
|
|
766 |
ddi_dma_free_handle(&dp->txDmaHandle);
|
|
767 |
|
|
768 |
vmxnet3_destroy_rxqueue(dp);
|
|
769 |
vmxnet3_destroy_txqueue(dp);
|
|
770 |
|
|
771 |
vmxnet3_destroy_drivershared(dp);
|
|
772 |
}
|
|
773 |
|
|
774 |
/*
|
|
775 |
*---------------------------------------------------------------------------
|
|
776 |
*
|
|
777 |
* vmxnet3_setpromisc --
|
|
778 |
*
|
|
779 |
* Set or unset promiscuous mode on a vmxnet3 device.
|
|
780 |
*
|
|
781 |
* Results:
|
|
782 |
* DDI_SUCCESS.
|
|
783 |
*
|
|
784 |
* Side effects:
|
|
785 |
* None.
|
|
786 |
*
|
|
787 |
*---------------------------------------------------------------------------
|
|
788 |
*/
|
|
789 |
static int
|
|
790 |
vmxnet3_setpromisc(void *data, boolean_t promisc)
|
|
791 |
{
|
|
792 |
vmxnet3_softc_t *dp = data;
|
|
793 |
|
|
794 |
VMXNET3_DEBUG(dp, 2, "setpromisc(%s)\n", promisc ? "TRUE" : "FALSE");
|
|
795 |
|
|
796 |
if (promisc) {
|
|
797 |
dp->rxMode |= VMXNET3_RXM_PROMISC;
|
|
798 |
} else {
|
|
799 |
dp->rxMode &= ~VMXNET3_RXM_PROMISC;
|
|
800 |
}
|
|
801 |
|
|
802 |
vmxnet3_refresh_rxfilter(dp);
|
|
803 |
|
|
804 |
return DDI_SUCCESS;
|
|
805 |
}
|
|
806 |
|
|
807 |
/*
|
|
808 |
*---------------------------------------------------------------------------
|
|
809 |
*
|
|
810 |
* vmxnet3_multicst --
|
|
811 |
*
|
|
812 |
* Add or remove a multicast address from/to a vmxnet3 device.
|
|
813 |
*
|
|
814 |
* Results:
|
|
815 |
* DDI_FAILURE.
|
|
816 |
*
|
|
817 |
* Side effects:
|
|
818 |
* None.
|
|
819 |
*
|
|
820 |
*---------------------------------------------------------------------------
|
|
821 |
*/
|
|
822 |
static int
|
|
823 |
vmxnet3_multicst(void *data, boolean_t add, const uint8_t *macaddr)
|
|
824 |
{
|
|
825 |
vmxnet3_softc_t *dp = data;
|
|
826 |
vmxnet3_dmabuf_t newMfTable;
|
|
827 |
int ret = DDI_SUCCESS;
|
|
828 |
uint16_t macIdx;
|
|
829 |
|
|
830 |
VMXNET3_DEBUG(dp, 2, "multicst(%s, "MACADDR_FMT")\n",
|
|
831 |
add ? "add" : "remove",
|
|
832 |
MACADDR_FMT_ARGS(macaddr));
|
|
833 |
|
|
834 |
/*
|
|
835 |
* First lookup the position of the given MAC to check if it is
|
|
836 |
* present in the existing MF table.
|
|
837 |
*/
|
|
838 |
for (macIdx = 0; macIdx < dp->mfTable.bufLen; macIdx += 6) {
|
|
839 |
if (memcmp(&dp->mfTable.buf[macIdx], macaddr, 6) == 0) {
|
|
840 |
break;
|
|
841 |
}
|
|
842 |
}
|
|
843 |
|
|
844 |
/*
|
|
845 |
* Check for 2 situations we can handle gracefully by bailing out:
|
|
846 |
* Adding an already existing filter or removing a non-existing one.
|
|
847 |
*/
|
|
848 |
if (add && macIdx < dp->mfTable.bufLen) {
|
|
849 |
VMXNET3_WARN(dp, MACADDR_FMT " already in MC filter list @ %u\n",
|
|
850 |
MACADDR_FMT_ARGS(macaddr), macIdx / 6);
|
|
851 |
ASSERT(B_FALSE);
|
|
852 |
goto done;
|
|
853 |
}
|
|
854 |
if (!add && macIdx == dp->mfTable.bufLen) {
|
|
855 |
VMXNET3_WARN(dp, MACADDR_FMT " not in MC filter list @ %u\n",
|
|
856 |
MACADDR_FMT_ARGS(macaddr), macIdx / 6);
|
|
857 |
ASSERT(B_FALSE);
|
|
858 |
goto done;
|
|
859 |
}
|
|
860 |
|
|
861 |
/*
|
|
862 |
* Create the new MF table
|
|
863 |
*/
|
|
864 |
{
|
|
865 |
size_t allocSize = dp->mfTable.bufLen + (add ? 6 : -6);
|
|
866 |
if (allocSize) {
|
|
867 |
ret = vmxnet3_alloc_dma_mem_1(dp, &newMfTable, allocSize, B_TRUE);
|
|
868 |
ASSERT(ret == DDI_SUCCESS);
|
|
869 |
if (add) {
|
|
870 |
(void) memcpy(newMfTable.buf, dp->mfTable.buf, dp->mfTable.bufLen);
|
|
871 |
(void) memcpy(newMfTable.buf + dp->mfTable.bufLen, macaddr, 6);
|
|
872 |
} else {
|
|
873 |
(void) memcpy(newMfTable.buf, dp->mfTable.buf, macIdx);
|
|
874 |
(void) memcpy(newMfTable.buf + macIdx,
|
|
875 |
dp->mfTable.buf + macIdx + 6,
|
|
876 |
dp->mfTable.bufLen - macIdx - 6);
|
|
877 |
}
|
|
878 |
} else {
|
|
879 |
newMfTable.buf = NULL;
|
|
880 |
newMfTable.bufPA = 0;
|
|
881 |
newMfTable.bufLen = 0;
|
|
882 |
}
|
|
883 |
}
|
|
884 |
|
|
885 |
/*
|
|
886 |
* Now handle 2 corner cases: if we're creating the first filter or
|
|
887 |
* removing the last one, we have to update rxMode accordingly.
|
|
888 |
*/
|
|
889 |
if (add && newMfTable.bufLen == 6) {
|
|
890 |
ASSERT(!(dp->rxMode & VMXNET3_RXM_MCAST));
|
|
891 |
dp->rxMode |= VMXNET3_RXM_MCAST;
|
|
892 |
vmxnet3_refresh_rxfilter(dp);
|
|
893 |
}
|
|
894 |
if (!add && dp->mfTable.bufLen == 6) {
|
|
895 |
ASSERT(newMfTable.buf == NULL);
|
|
896 |
ASSERT(dp->rxMode & VMXNET3_RXM_MCAST);
|
|
897 |
dp->rxMode &= ~VMXNET3_RXM_MCAST;
|
|
898 |
vmxnet3_refresh_rxfilter(dp);
|
|
899 |
}
|
|
900 |
|
|
901 |
/*
|
|
902 |
* Now replace the old MF table with the new one
|
|
903 |
*/
|
|
904 |
if (dp->mfTable.buf) {
|
|
905 |
vmxnet3_free_dma_mem(&dp->mfTable);
|
|
906 |
}
|
|
907 |
dp->mfTable = newMfTable;
|
|
908 |
VMXNET3_DS(dp)->devRead.rxFilterConf.mfTablePA = newMfTable.bufPA;
|
|
909 |
VMXNET3_DS(dp)->devRead.rxFilterConf.mfTableLen = newMfTable.bufLen;
|
|
910 |
|
|
911 |
done:
|
|
912 |
/* Always update the filters */
|
|
913 |
VMXNET3_BAR1_PUT32(dp, VMXNET3_REG_CMD, VMXNET3_CMD_UPDATE_MAC_FILTERS);
|
|
914 |
|
|
915 |
return ret;
|
|
916 |
}
|
|
917 |
|
|
918 |
/*
|
|
919 |
*---------------------------------------------------------------------------
|
|
920 |
*
|
|
921 |
* vmxnet3_unicst --
|
|
922 |
*
|
|
923 |
* Set the mac address of a vmxnet3 device.
|
|
924 |
*
|
|
925 |
* Results:
|
|
926 |
* DDI_FAILURE.
|
|
927 |
*
|
|
928 |
* Side effects:
|
|
929 |
* None.
|
|
930 |
*
|
|
931 |
*---------------------------------------------------------------------------
|
|
932 |
*/
|
|
933 |
static int
|
|
934 |
vmxnet3_unicst(void *data, const uint8_t *macaddr)
|
|
935 |
{
|
|
936 |
vmxnet3_softc_t *dp = data;
|
|
937 |
uint32_t val32;
|
|
938 |
|
|
939 |
VMXNET3_DEBUG(dp, 2, "unicst("MACADDR_FMT")\n",
|
|
940 |
MACADDR_FMT_ARGS(macaddr));
|
|
941 |
|
|
942 |
val32 = *((uint32_t *) (macaddr + 0));
|
|
943 |
VMXNET3_BAR1_PUT32(dp, VMXNET3_REG_MACL, val32);
|
|
944 |
val32 = *((uint16_t *) (macaddr + 4));
|
|
945 |
VMXNET3_BAR1_PUT32(dp, VMXNET3_REG_MACH, val32);
|
|
946 |
|
|
947 |
(void) memcpy(dp->macaddr, macaddr, 6);
|
|
948 |
|
|
949 |
return DDI_SUCCESS;
|
|
950 |
}
|
|
951 |
|
|
952 |
|
|
953 |
/*
|
|
954 |
*---------------------------------------------------------------------------
|
|
955 |
*
|
|
956 |
* vmxnet3_change_mtu --
|
|
957 |
*
|
14277
|
958 |
* Change the MTU as seen by the driver. This is only supported when
|
|
959 |
* the mac is stopped.
|
13976
|
960 |
*
|
|
961 |
* Results:
|
14277
|
962 |
* EBUSY if the device is enabled.
|
|
963 |
* EINVAL for invalid MTU values.
|
|
964 |
* 0 on success.
|
13976
|
965 |
*
|
|
966 |
* Side effects:
|
|
967 |
* None.
|
|
968 |
*
|
|
969 |
*---------------------------------------------------------------------------
|
|
970 |
*/
|
|
971 |
|
|
972 |
static int
|
|
973 |
vmxnet3_change_mtu(vmxnet3_softc_t *dp, uint32_t new_mtu)
|
|
974 |
{
|
14277
|
975 |
int ret;
|
|
976 |
|
|
977 |
if (dp->devEnabled)
|
|
978 |
return EBUSY;
|
|
979 |
|
13976
|
980 |
if (new_mtu == dp->cur_mtu) {
|
|
981 |
VMXNET3_WARN(dp, "New MTU is same as old mtu : %d.\n", new_mtu);
|
|
982 |
return 0;
|
|
983 |
}
|
|
984 |
|
|
985 |
if (new_mtu < VMXNET3_MIN_MTU || new_mtu > VMXNET3_MAX_MTU) {
|
|
986 |
VMXNET3_WARN(dp, "New MTU not in valid range [%d, %d].\n",
|
|
987 |
VMXNET3_MIN_MTU, VMXNET3_MAX_MTU);
|
|
988 |
return EINVAL;
|
|
989 |
}
|
|
990 |
|
|
991 |
dp->cur_mtu = new_mtu;
|
|
992 |
|
14277
|
993 |
if ((ret = mac_maxsdu_update(dp->mac, new_mtu)) != 0)
|
|
994 |
VMXNET3_WARN(dp, "Unable to update mac with %d mtu: %d", new_mtu, ret);
|
13976
|
995 |
|
|
996 |
return ret;
|
|
997 |
}
|
|
998 |
|
|
999 |
|
|
1000 |
/*
|
|
1001 |
*---------------------------------------------------------------------------
|
|
1002 |
*
|
|
1003 |
* vmxnet3_ioctl --
|
|
1004 |
*
|
|
1005 |
* DDI/DDK callback to handle IOCTL in driver. Currently it only handles
|
|
1006 |
* ND_SET ioctl. Rest all are ignored. The ND_SET is used to set/reset
|
|
1007 |
* accept-jumbo ndd parameted for the interface.
|
|
1008 |
*
|
|
1009 |
* Results:
|
|
1010 |
* Nothing is returned directly. An ACK or NACK is conveyed to the calling
|
|
1011 |
* function from the mblk which was used to call this function.
|
|
1012 |
*
|
|
1013 |
* Side effects:
|
|
1014 |
* MTU can be changed and device can be reset.
|
|
1015 |
*
|
|
1016 |
*---------------------------------------------------------------------------
|
|
1017 |
*/
|
|
1018 |
|
|
1019 |
static void
|
|
1020 |
vmxnet3_ioctl(void *arg, queue_t *wq, mblk_t *mp)
|
|
1021 |
{
|
|
1022 |
vmxnet3_softc_t *dp = arg;
|
|
1023 |
int ret = EINVAL;
|
|
1024 |
IOCP iocp;
|
|
1025 |
mblk_t *mp1;
|
|
1026 |
char *valp, *param;
|
|
1027 |
int data;
|
|
1028 |
|
|
1029 |
iocp = (void *)mp->b_rptr;
|
|
1030 |
iocp->ioc_error = 0;
|
|
1031 |
|
|
1032 |
switch (iocp->ioc_cmd) {
|
|
1033 |
case ND_SET:
|
|
1034 |
|
|
1035 |
/* the mblk in continuation would contain the ndd parameter name
|
|
1036 |
* and data value to be set
|
|
1037 |
*/
|
|
1038 |
mp1 = mp->b_cont;
|
|
1039 |
if (!mp1) {
|
|
1040 |
VMXNET3_WARN(dp, "Error locating parameter name.\n");
|
|
1041 |
ret = EINVAL;
|
|
1042 |
break;
|
|
1043 |
}
|
|
1044 |
|
|
1045 |
mp1->b_datap->db_lim[-1] = '\0'; /* Force null termination */
|
|
1046 |
|
|
1047 |
/*
|
|
1048 |
* From /usr/src/uts/common/inet/nd.c : nd_getset()
|
|
1049 |
* "logic throughout nd_xxx assumes single data block for ioctl.
|
|
1050 |
* However, existing code sends in some big buffers."
|
|
1051 |
*/
|
|
1052 |
if (mp1->b_cont) {
|
|
1053 |
freemsg(mp1->b_cont);
|
|
1054 |
mp1->b_cont = NULL;
|
|
1055 |
}
|
|
1056 |
|
|
1057 |
valp = (char *)mp1->b_rptr; /* Points to param name*/
|
|
1058 |
ASSERT(valp);
|
|
1059 |
param = valp;
|
|
1060 |
VMXNET3_DEBUG(dp, 3, "ND Set ioctl for %s\n", param);
|
|
1061 |
|
|
1062 |
/* Go past the end of this null terminated string to get the data value.*/
|
|
1063 |
while (*valp && valp <= (char *)mp1->b_wptr)
|
|
1064 |
valp++;
|
|
1065 |
|
|
1066 |
if (valp > (char *)mp1->b_wptr) {
|
|
1067 |
/* We are already beyond the readable area of mblk and still havent
|
|
1068 |
* found the end of param string.
|
|
1069 |
*/
|
|
1070 |
VMXNET3_WARN(dp, "No data value found to be set to param.\n");
|
|
1071 |
data = -1;
|
|
1072 |
} else {
|
|
1073 |
valp++; /* Now this points to data string */
|
|
1074 |
data = (int)*valp - (int)'0'; /* Get numeric value of first letter */
|
|
1075 |
}
|
|
1076 |
|
|
1077 |
if (strcmp("accept-jumbo", param) == 0) {
|
|
1078 |
if (data == 1) {
|
|
1079 |
VMXNET3_DEBUG(dp, 2, "Accepting jumbo frames\n");
|
|
1080 |
ret = vmxnet3_change_mtu(dp, VMXNET3_MAX_MTU);
|
|
1081 |
} else if (data == 0) {
|
|
1082 |
VMXNET3_DEBUG(dp, 2, "Rejecting jumbo frames\n");
|
|
1083 |
ret = vmxnet3_change_mtu(dp, ETHERMTU);
|
|
1084 |
} else {
|
|
1085 |
VMXNET3_WARN(dp, "Invalid data value to be set, use 1 or 0.\n");
|
|
1086 |
ret = -1;
|
|
1087 |
}
|
|
1088 |
}
|
|
1089 |
freemsg(mp1);
|
|
1090 |
mp->b_cont = NULL;
|
|
1091 |
break;
|
|
1092 |
|
|
1093 |
default:
|
|
1094 |
if (mp->b_cont) {
|
|
1095 |
freemsg(mp->b_cont);
|
|
1096 |
mp->b_cont = NULL;
|
|
1097 |
}
|
|
1098 |
ret = -1;
|
|
1099 |
break;
|
|
1100 |
}
|
|
1101 |
|
|
1102 |
if (ret == 0)
|
|
1103 |
miocack(wq, mp, 0, 0);
|
|
1104 |
else
|
|
1105 |
miocnak(wq, mp, 0, EINVAL);
|
|
1106 |
}
|
|
1107 |
|
|
1108 |
|
|
1109 |
/*
|
|
1110 |
*---------------------------------------------------------------------------
|
|
1111 |
*
|
|
1112 |
* vmxnet3_getcapab --
|
|
1113 |
*
|
|
1114 |
* Get the capabilities of a vmxnet3 device.
|
|
1115 |
*
|
|
1116 |
* Results:
|
|
1117 |
* B_TRUE or B_FALSE.
|
|
1118 |
*
|
|
1119 |
* Side effects:
|
|
1120 |
* None.
|
|
1121 |
*
|
|
1122 |
*---------------------------------------------------------------------------
|
|
1123 |
*/
|
|
1124 |
static boolean_t
|
|
1125 |
vmxnet3_getcapab(void *data, mac_capab_t capab, void *arg)
|
|
1126 |
{
|
|
1127 |
vmxnet3_softc_t *dp = data;
|
|
1128 |
boolean_t ret;
|
|
1129 |
|
|
1130 |
switch (capab) {
|
|
1131 |
case MAC_CAPAB_HCKSUM: {
|
|
1132 |
uint32_t *txflags = arg;
|
|
1133 |
*txflags = HCKSUM_INET_PARTIAL;
|
|
1134 |
ret = B_TRUE;
|
|
1135 |
break;
|
|
1136 |
}
|
|
1137 |
case MAC_CAPAB_LSO: {
|
|
1138 |
mac_capab_lso_t *lso = arg;
|
|
1139 |
lso->lso_flags = LSO_TX_BASIC_TCP_IPV4;
|
|
1140 |
lso->lso_basic_tcp_ipv4.lso_max = IP_MAXPACKET;
|
|
1141 |
ret = vmxnet3_getprop(dp, "EnableLSO", 0, 1, 1);
|
|
1142 |
break;
|
|
1143 |
}
|
|
1144 |
default:
|
|
1145 |
ret = B_FALSE;
|
|
1146 |
}
|
|
1147 |
|
|
1148 |
VMXNET3_DEBUG(dp, 2, "getcapab(0x%x) -> %s\n", capab, ret ? "yes" : "no");
|
|
1149 |
|
|
1150 |
return ret;
|
|
1151 |
}
|
|
1152 |
|
|
1153 |
/*
|
|
1154 |
*---------------------------------------------------------------------------
|
|
1155 |
*
|
|
1156 |
* vmxnet3_setmacprop --
|
|
1157 |
*
|
|
1158 |
* Set a MAC property.
|
|
1159 |
*
|
|
1160 |
* Results:
|
|
1161 |
* 0 on success, errno otherwise.
|
|
1162 |
*
|
|
1163 |
* Side effects:
|
|
1164 |
* None.
|
|
1165 |
*
|
|
1166 |
*---------------------------------------------------------------------------
|
|
1167 |
*/
|
|
1168 |
/* ARGSUSED */
|
|
1169 |
static int
|
|
1170 |
vmxnet3_setmacprop(void *data, const char *pr_name, mac_prop_id_t pr_num,
|
|
1171 |
uint_t pr_valsize, const void *pr_val)
|
|
1172 |
{
|
|
1173 |
vmxnet3_softc_t *dp = data;
|
|
1174 |
int ret = 0;
|
|
1175 |
uint32_t newmtu;
|
|
1176 |
|
|
1177 |
switch (pr_num) {
|
|
1178 |
case MAC_PROP_MTU:
|
|
1179 |
(void) memcpy(&newmtu, pr_val, sizeof (newmtu));
|
|
1180 |
ret = vmxnet3_change_mtu(dp, newmtu);
|
|
1181 |
break;
|
|
1182 |
default:
|
|
1183 |
ret = ENOTSUP;
|
|
1184 |
}
|
|
1185 |
|
|
1186 |
return ret;
|
|
1187 |
}
|
|
1188 |
|
|
1189 |
/*
|
|
1190 |
*---------------------------------------------------------------------------
|
|
1191 |
*
|
|
1192 |
* vmxnet3_macpropinfo --
|
|
1193 |
*
|
|
1194 |
* Get MAC property information.
|
|
1195 |
*
|
|
1196 |
* Results:
|
|
1197 |
* None.
|
|
1198 |
*
|
|
1199 |
* Side effects:
|
|
1200 |
* None.
|
|
1201 |
*
|
|
1202 |
*---------------------------------------------------------------------------
|
|
1203 |
*/
|
|
1204 |
/* ARGSUSED */
|
|
1205 |
static void
|
|
1206 |
vmxnet3_macpropinfo(void *data, const char *pr_name, mac_prop_id_t pr_num,
|
|
1207 |
mac_prop_info_handle_t prh)
|
|
1208 |
{
|
|
1209 |
switch (pr_num) {
|
|
1210 |
case MAC_PROP_MTU:
|
|
1211 |
mac_prop_info_set_range_uint32(prh, VMXNET3_MIN_MTU, VMXNET3_MAX_MTU);
|
|
1212 |
break;
|
|
1213 |
default:
|
|
1214 |
break;
|
|
1215 |
}
|
|
1216 |
}
|
|
1217 |
|
|
1218 |
/*
|
|
1219 |
*---------------------------------------------------------------------------
|
|
1220 |
*
|
|
1221 |
* vmxnet3_reset --
|
|
1222 |
*
|
|
1223 |
* Reset a vmxnet3 device. Only to be used when the device is wedged.
|
|
1224 |
*
|
|
1225 |
* Results:
|
|
1226 |
* None.
|
|
1227 |
*
|
|
1228 |
* Side effects:
|
|
1229 |
* The device is reset.
|
|
1230 |
*
|
|
1231 |
*---------------------------------------------------------------------------
|
|
1232 |
*/
|
|
1233 |
static void
|
|
1234 |
vmxnet3_reset(void *data)
|
|
1235 |
{
|
|
1236 |
int ret;
|
|
1237 |
|
|
1238 |
vmxnet3_softc_t *dp = data;
|
|
1239 |
|
|
1240 |
VMXNET3_DEBUG(dp, 1, "vmxnet3_reset()\n");
|
|
1241 |
|
|
1242 |
atomic_inc_32(&dp->reset_count);
|
|
1243 |
vmxnet3_stop(dp);
|
|
1244 |
VMXNET3_BAR1_PUT32(dp, VMXNET3_REG_CMD, VMXNET3_CMD_RESET_DEV);
|
|
1245 |
if ((ret = vmxnet3_start(dp)) != DDI_SUCCESS)
|
14277
|
1246 |
VMXNET3_WARN(dp, "failed to reset the device: %d", ret);
|
13976
|
1247 |
}
|
|
1248 |
|
|
1249 |
/*
|
|
1250 |
*---------------------------------------------------------------------------
|
|
1251 |
*
|
|
1252 |
* vmxnet3_intr_events --
|
|
1253 |
*
|
|
1254 |
* Process pending events on a vmxnet3 device.
|
|
1255 |
*
|
|
1256 |
* Results:
|
|
1257 |
* B_TRUE if the link state changed, B_FALSE otherwise.
|
|
1258 |
*
|
|
1259 |
* Side effects:
|
|
1260 |
* None.
|
|
1261 |
*
|
|
1262 |
*---------------------------------------------------------------------------
|
|
1263 |
*/
|
|
1264 |
static boolean_t
|
|
1265 |
vmxnet3_intr_events(vmxnet3_softc_t *dp)
|
|
1266 |
{
|
|
1267 |
Vmxnet3_DriverShared *ds = VMXNET3_DS(dp);
|
|
1268 |
boolean_t linkStateChanged = B_FALSE;
|
|
1269 |
uint32_t events = ds->ecr;
|
|
1270 |
|
|
1271 |
if (events) {
|
|
1272 |
VMXNET3_DEBUG(dp, 2, "events(0x%x)\n", events);
|
|
1273 |
if (events & (VMXNET3_ECR_RQERR | VMXNET3_ECR_TQERR)) {
|
|
1274 |
Vmxnet3_TxQueueDesc *tqdesc = VMXNET3_TQDESC(dp);
|
|
1275 |
Vmxnet3_RxQueueDesc *rqdesc = VMXNET3_RQDESC(dp);
|
|
1276 |
|
|
1277 |
VMXNET3_BAR1_PUT32(dp, VMXNET3_REG_CMD, VMXNET3_CMD_GET_QUEUE_STATUS);
|
|
1278 |
if (tqdesc->status.stopped) {
|
|
1279 |
VMXNET3_WARN(dp, "tq error 0x%x\n", tqdesc->status.error);
|
|
1280 |
}
|
|
1281 |
if (rqdesc->status.stopped) {
|
|
1282 |
VMXNET3_WARN(dp, "rq error 0x%x\n", rqdesc->status.error);
|
|
1283 |
}
|
|
1284 |
|
|
1285 |
if (ddi_taskq_dispatch(dp->resetTask, vmxnet3_reset,
|
|
1286 |
dp, DDI_NOSLEEP) == DDI_SUCCESS) {
|
|
1287 |
VMXNET3_WARN(dp, "reset scheduled\n");
|
|
1288 |
} else {
|
|
1289 |
VMXNET3_WARN(dp, "ddi_taskq_dispatch() failed()\n");
|
|
1290 |
}
|
|
1291 |
}
|
|
1292 |
if (events & VMXNET3_ECR_LINK) {
|
|
1293 |
vmxnet3_refresh_linkstate(dp);
|
|
1294 |
linkStateChanged = B_TRUE;
|
|
1295 |
}
|
14277
|
1296 |
if (events & VMXNET3_ECR_DIC) {
|
|
1297 |
VMXNET3_DEBUG(dp, 1, "device implementation change\n");
|
|
1298 |
}
|
13976
|
1299 |
VMXNET3_BAR1_PUT32(dp, VMXNET3_REG_ECR, events);
|
|
1300 |
}
|
|
1301 |
|
|
1302 |
return linkStateChanged;
|
|
1303 |
}
|
|
1304 |
|
|
1305 |
/*
|
|
1306 |
*---------------------------------------------------------------------------
|
|
1307 |
*
|
|
1308 |
* vmxnet3_intr --
|
|
1309 |
*
|
|
1310 |
* Interrupt handler of a vmxnet3 device.
|
|
1311 |
*
|
|
1312 |
* Results:
|
|
1313 |
* DDI_INTR_CLAIMED or DDI_INTR_UNCLAIMED.
|
|
1314 |
*
|
|
1315 |
* Side effects:
|
|
1316 |
* None.
|
|
1317 |
*
|
|
1318 |
*---------------------------------------------------------------------------
|
|
1319 |
*/
|
|
1320 |
/* ARGSUSED1 */
|
|
1321 |
static u_int
|
|
1322 |
vmxnet3_intr(caddr_t data1, caddr_t data2)
|
|
1323 |
{
|
|
1324 |
vmxnet3_softc_t *dp = (void *) data1;
|
|
1325 |
|
|
1326 |
VMXNET3_DEBUG(dp, 3, "intr()\n");
|
|
1327 |
|
|
1328 |
mutex_enter(&dp->intrLock);
|
|
1329 |
|
|
1330 |
if (dp->devEnabled) {
|
|
1331 |
boolean_t linkStateChanged;
|
|
1332 |
boolean_t mustUpdateTx;
|
|
1333 |
mblk_t *mps;
|
|
1334 |
|
|
1335 |
if (dp->intrType == DDI_INTR_TYPE_FIXED &&
|
|
1336 |
!VMXNET3_BAR1_GET32(dp, VMXNET3_REG_ICR)) {
|
|
1337 |
goto intr_unclaimed;
|
|
1338 |
}
|
|
1339 |
|
|
1340 |
if (dp->intrMaskMode == VMXNET3_IMM_ACTIVE) {
|
|
1341 |
VMXNET3_BAR0_PUT32(dp, VMXNET3_REG_IMR, 1);
|
|
1342 |
}
|
|
1343 |
|
|
1344 |
linkStateChanged = vmxnet3_intr_events(dp);
|
|
1345 |
mustUpdateTx = vmxnet3_tx_complete(dp, &dp->txQueue);
|
|
1346 |
mps = vmxnet3_rx_intr(dp, &dp->rxQueue);
|
|
1347 |
|
|
1348 |
mutex_exit(&dp->intrLock);
|
|
1349 |
VMXNET3_BAR0_PUT32(dp, VMXNET3_REG_IMR, 0);
|
|
1350 |
|
|
1351 |
if (linkStateChanged) {
|
|
1352 |
mac_link_update(dp->mac, dp->linkState);
|
|
1353 |
}
|
|
1354 |
if (mustUpdateTx) {
|
|
1355 |
mac_tx_update(dp->mac);
|
|
1356 |
}
|
|
1357 |
if (mps) {
|
|
1358 |
mac_rx(dp->mac, NULL, mps);
|
|
1359 |
}
|
|
1360 |
|
|
1361 |
return DDI_INTR_CLAIMED;
|
|
1362 |
}
|
|
1363 |
|
|
1364 |
intr_unclaimed:
|
|
1365 |
mutex_exit(&dp->intrLock);
|
|
1366 |
return DDI_INTR_UNCLAIMED;
|
|
1367 |
}
|
|
1368 |
|
|
1369 |
static int
|
|
1370 |
vmxnet3_kstat_update(kstat_t *ksp, int rw)
|
|
1371 |
{
|
|
1372 |
vmxnet3_softc_t *dp = ksp->ks_private;
|
|
1373 |
vmxnet3_kstats_t *statp = ksp->ks_data;
|
|
1374 |
|
|
1375 |
if (rw == KSTAT_WRITE)
|
|
1376 |
return EACCES;
|
|
1377 |
|
|
1378 |
statp->reset_count.value.ul = dp->reset_count;
|
|
1379 |
statp->tx_pullup_needed.value.ul = dp->tx_pullup_needed;
|
|
1380 |
statp->tx_ring_full.value.ul = dp->tx_ring_full;
|
|
1381 |
statp->rx_alloc_buf.value.ul = dp->rx_alloc_buf;
|
|
1382 |
|
|
1383 |
return 0;
|
|
1384 |
}
|
|
1385 |
|
|
1386 |
static int
|
|
1387 |
vmxnet3_kstat_init(vmxnet3_softc_t *dp)
|
|
1388 |
{
|
|
1389 |
vmxnet3_kstats_t *statp;
|
|
1390 |
|
|
1391 |
dp->devKstats = kstat_create(VMXNET3_MODNAME, dp->instance, "statistics",
|
|
1392 |
"dev", KSTAT_TYPE_NAMED,
|
|
1393 |
sizeof (vmxnet3_kstats_t) /
|
|
1394 |
sizeof (kstat_named_t), 0);
|
|
1395 |
if (dp->devKstats == NULL)
|
|
1396 |
return DDI_FAILURE;
|
|
1397 |
|
|
1398 |
dp->devKstats->ks_update = vmxnet3_kstat_update;
|
|
1399 |
dp->devKstats->ks_private = dp;
|
|
1400 |
|
|
1401 |
statp = dp->devKstats->ks_data;
|
|
1402 |
|
|
1403 |
kstat_named_init(&statp->reset_count, "reset_count", KSTAT_DATA_ULONG);
|
|
1404 |
kstat_named_init(&statp->tx_pullup_needed, "tx_pullup_needed",
|
|
1405 |
KSTAT_DATA_ULONG);
|
|
1406 |
kstat_named_init(&statp->tx_ring_full, "tx_ring_full", KSTAT_DATA_ULONG);
|
|
1407 |
kstat_named_init(&statp->rx_alloc_buf, "rx_alloc_buf", KSTAT_DATA_ULONG);
|
|
1408 |
|
|
1409 |
kstat_install(dp->devKstats);
|
|
1410 |
|
|
1411 |
return DDI_SUCCESS;
|
|
1412 |
}
|
|
1413 |
|
|
1414 |
/*
|
|
1415 |
*---------------------------------------------------------------------------
|
|
1416 |
*
|
|
1417 |
* vmxnet3_attach --
|
|
1418 |
*
|
|
1419 |
* Probe and attach a vmxnet3 instance to the stack.
|
|
1420 |
*
|
|
1421 |
* Results:
|
|
1422 |
* DDI_SUCCESS or DDI_FAILURE.
|
|
1423 |
*
|
|
1424 |
* Side effects:
|
|
1425 |
* None.
|
|
1426 |
*
|
|
1427 |
*---------------------------------------------------------------------------
|
|
1428 |
*/
|
|
1429 |
static int
|
|
1430 |
vmxnet3_attach(dev_info_t *dip, ddi_attach_cmd_t cmd)
|
|
1431 |
{
|
|
1432 |
vmxnet3_softc_t *dp;
|
|
1433 |
mac_register_t *macr;
|
|
1434 |
uint16_t vendorId, devId, ret16;
|
|
1435 |
uint32_t ret32;
|
|
1436 |
int ret, err;
|
|
1437 |
uint_t uret;
|
|
1438 |
|
|
1439 |
if (cmd != DDI_ATTACH) {
|
|
1440 |
goto error;
|
|
1441 |
}
|
|
1442 |
|
|
1443 |
/*
|
|
1444 |
* Allocate the soft state
|
|
1445 |
*/
|
|
1446 |
dp = kmem_zalloc(sizeof(vmxnet3_softc_t), KM_SLEEP);
|
|
1447 |
ASSERT(dp);
|
|
1448 |
|
|
1449 |
dp->dip = dip;
|
|
1450 |
dp->instance = ddi_get_instance(dip);
|
|
1451 |
dp->cur_mtu = ETHERMTU;
|
|
1452 |
|
|
1453 |
VMXNET3_DEBUG(dp, 1, "attach()\n");
|
|
1454 |
|
|
1455 |
ddi_set_driver_private(dip, dp);
|
|
1456 |
|
|
1457 |
/*
|
|
1458 |
* Get access to the PCI bus configuration space
|
|
1459 |
*/
|
|
1460 |
if (pci_config_setup(dip, &dp->pciHandle) != DDI_SUCCESS) {
|
|
1461 |
VMXNET3_WARN(dp, "pci_config_setup() failed\n");
|
|
1462 |
goto error_soft_state;
|
|
1463 |
}
|
|
1464 |
|
|
1465 |
/*
|
|
1466 |
* Make sure the chip is a vmxnet3 device
|
|
1467 |
*/
|
|
1468 |
vendorId = pci_config_get16(dp->pciHandle, PCI_CONF_VENID);
|
|
1469 |
devId = pci_config_get16(dp->pciHandle, PCI_CONF_DEVID);
|
|
1470 |
if (vendorId != PCI_VENDOR_ID_VMWARE ||
|
|
1471 |
devId != PCI_DEVICE_ID_VMWARE_VMXNET3) {
|
|
1472 |
VMXNET3_WARN(dp, "wrong PCI venid/devid (0x%x, 0x%x)\n",
|
|
1473 |
vendorId, devId);
|
|
1474 |
goto error_pci_config;
|
|
1475 |
}
|
|
1476 |
|
|
1477 |
/*
|
|
1478 |
* Make sure we can access the registers through the I/O space
|
|
1479 |
*/
|
|
1480 |
ret16 = pci_config_get16(dp->pciHandle, PCI_CONF_COMM);
|
|
1481 |
ret16 |= PCI_COMM_IO | PCI_COMM_ME;
|
|
1482 |
pci_config_put16(dp->pciHandle, PCI_CONF_COMM, ret16);
|
|
1483 |
|
|
1484 |
/*
|
|
1485 |
* Map the I/O space in memory
|
|
1486 |
*/
|
|
1487 |
if (ddi_regs_map_setup(dip, 1, &dp->bar0, 0, 0, &vmxnet3_dev_attr,
|
|
1488 |
&dp->bar0Handle) != DDI_SUCCESS) {
|
|
1489 |
VMXNET3_WARN(dp, "ddi_regs_map_setup() for BAR0 failed\n");
|
|
1490 |
goto error_pci_config;
|
|
1491 |
}
|
|
1492 |
|
|
1493 |
if (ddi_regs_map_setup(dip, 2, &dp->bar1, 0, 0, &vmxnet3_dev_attr,
|
|
1494 |
&dp->bar1Handle) != DDI_SUCCESS) {
|
|
1495 |
VMXNET3_WARN(dp, "ddi_regs_map_setup() for BAR1 failed\n");
|
|
1496 |
goto error_regs_map_0;
|
|
1497 |
}
|
|
1498 |
|
|
1499 |
/*
|
|
1500 |
* Check the version number of the virtual device
|
|
1501 |
*/
|
|
1502 |
if (VMXNET3_BAR1_GET32(dp, VMXNET3_REG_VRRS) & 1) {
|
|
1503 |
VMXNET3_BAR1_PUT32(dp, VMXNET3_REG_VRRS, 1);
|
|
1504 |
} else {
|
|
1505 |
VMXNET3_WARN(dp, "incompatible h/w version\n");
|
|
1506 |
goto error_regs_map_1;
|
|
1507 |
}
|
|
1508 |
|
|
1509 |
if (VMXNET3_BAR1_GET32(dp, VMXNET3_REG_UVRS) & 1) {
|
|
1510 |
VMXNET3_BAR1_PUT32(dp, VMXNET3_REG_UVRS, 1);
|
|
1511 |
} else {
|
|
1512 |
VMXNET3_WARN(dp, "incompatible upt version\n");
|
|
1513 |
goto error_regs_map_1;
|
|
1514 |
}
|
|
1515 |
|
|
1516 |
if (vmxnet3_kstat_init(dp) != DDI_SUCCESS) {
|
|
1517 |
VMXNET3_WARN(dp, "unable to initialize kstats");
|
|
1518 |
goto error_regs_map_1;
|
|
1519 |
}
|
|
1520 |
|
|
1521 |
/*
|
|
1522 |
* Read the MAC address from the device
|
|
1523 |
*/
|
|
1524 |
ret32 = VMXNET3_BAR1_GET32(dp, VMXNET3_REG_MACL);
|
|
1525 |
*((uint32_t *) (dp->macaddr + 0)) = ret32;
|
|
1526 |
ret32 = VMXNET3_BAR1_GET32(dp, VMXNET3_REG_MACH);
|
|
1527 |
*((uint16_t *) (dp->macaddr + 4)) = ret32;
|
|
1528 |
|
|
1529 |
/*
|
|
1530 |
* Register with the MAC framework
|
|
1531 |
*/
|
|
1532 |
if (!(macr = mac_alloc(MAC_VERSION))) {
|
|
1533 |
VMXNET3_WARN(dp, "mac_alloc() failed.\n");
|
|
1534 |
goto error_kstat;
|
|
1535 |
}
|
|
1536 |
|
|
1537 |
macr->m_type_ident = MAC_PLUGIN_IDENT_ETHER;
|
|
1538 |
macr->m_driver = dp;
|
|
1539 |
macr->m_dip = dip;
|
|
1540 |
macr->m_instance = 0;
|
|
1541 |
macr->m_src_addr = dp->macaddr;
|
|
1542 |
macr->m_dst_addr = NULL;
|
|
1543 |
macr->m_callbacks = &vmxnet3_mac_callbacks;
|
|
1544 |
macr->m_min_sdu = VMXNET3_MIN_MTU;
|
|
1545 |
macr->m_max_sdu = ETHERMTU;
|
|
1546 |
macr->m_margin = VLAN_TAGSZ;
|
|
1547 |
macr->m_pdata = NULL;
|
|
1548 |
macr->m_pdata_size = 0;
|
|
1549 |
|
|
1550 |
ret = mac_register(macr, &dp->mac);
|
|
1551 |
mac_free(macr);
|
|
1552 |
if (ret != DDI_SUCCESS) {
|
|
1553 |
VMXNET3_WARN(dp, "mac_register() failed\n");
|
|
1554 |
goto error_kstat;
|
|
1555 |
}
|
|
1556 |
|
|
1557 |
/*
|
|
1558 |
* Register the interrupt(s) in this order of preference:
|
|
1559 |
* MSI-X, MSI, INTx
|
|
1560 |
*/
|
|
1561 |
VMXNET3_BAR1_PUT32(dp, VMXNET3_REG_CMD, VMXNET3_CMD_GET_CONF_INTR);
|
|
1562 |
ret32 = VMXNET3_BAR1_GET32(dp, VMXNET3_REG_CMD);
|
|
1563 |
switch (ret32 & 0x3) {
|
|
1564 |
case VMXNET3_IT_AUTO:
|
|
1565 |
case VMXNET3_IT_MSIX:
|
|
1566 |
dp->intrType = DDI_INTR_TYPE_MSIX;
|
|
1567 |
err = ddi_intr_alloc(dip, &dp->intrHandle, dp->intrType, 0, 1,
|
|
1568 |
&ret, DDI_INTR_ALLOC_STRICT);
|
|
1569 |
if (err == DDI_SUCCESS)
|
|
1570 |
break;
|
|
1571 |
VMXNET3_DEBUG(dp, 2, "DDI_INTR_TYPE_MSIX failed, err:%d\n", err);
|
|
1572 |
/* FALLTHROUGH */
|
|
1573 |
case VMXNET3_IT_MSI:
|
|
1574 |
dp->intrType = DDI_INTR_TYPE_MSI;
|
|
1575 |
if (ddi_intr_alloc(dip, &dp->intrHandle, dp->intrType, 0, 1,
|
|
1576 |
&ret, DDI_INTR_ALLOC_STRICT) == DDI_SUCCESS)
|
|
1577 |
break;
|
|
1578 |
VMXNET3_DEBUG(dp, 2, "DDI_INTR_TYPE_MSI failed\n");
|
|
1579 |
/* FALLTHROUGH */
|
|
1580 |
case VMXNET3_IT_INTX:
|
|
1581 |
dp->intrType = DDI_INTR_TYPE_FIXED;
|
|
1582 |
if (ddi_intr_alloc(dip, &dp->intrHandle, dp->intrType, 0, 1,
|
|
1583 |
&ret, DDI_INTR_ALLOC_STRICT) == DDI_SUCCESS) {
|
|
1584 |
break;
|
|
1585 |
}
|
|
1586 |
VMXNET3_DEBUG(dp, 2, "DDI_INTR_TYPE_INTX failed\n");
|
|
1587 |
/* FALLTHROUGH */
|
|
1588 |
default:
|
|
1589 |
VMXNET3_WARN(dp, "ddi_intr_alloc() failed\n");
|
|
1590 |
goto error_mac;
|
|
1591 |
}
|
|
1592 |
dp->intrMaskMode = (ret32 >> 2) & 0x3;
|
|
1593 |
if (dp->intrMaskMode == VMXNET3_IMM_LAZY) {
|
|
1594 |
VMXNET3_WARN(dp, "Lazy masking is not supported\n");
|
|
1595 |
goto error_intr;
|
|
1596 |
}
|
|
1597 |
|
|
1598 |
if (ddi_intr_get_pri(dp->intrHandle, &uret) != DDI_SUCCESS) {
|
|
1599 |
VMXNET3_WARN(dp, "ddi_intr_get_pri() failed\n");
|
|
1600 |
goto error_intr;
|
|
1601 |
}
|
|
1602 |
|
|
1603 |
VMXNET3_DEBUG(dp, 2, "intrType=0x%x, intrMaskMode=0x%x, intrPrio=%u\n",
|
|
1604 |
dp->intrType, dp->intrMaskMode, uret);
|
|
1605 |
|
|
1606 |
/*
|
|
1607 |
* Create a task queue to reset the device if it wedges.
|
|
1608 |
*/
|
|
1609 |
dp->resetTask = ddi_taskq_create(dip, "vmxnet3_reset_task", 1,
|
|
1610 |
TASKQ_DEFAULTPRI, 0);
|
|
1611 |
if (!dp->resetTask) {
|
|
1612 |
VMXNET3_WARN(dp, "ddi_taskq_create() failed()\n");
|
|
1613 |
goto error_intr;
|
|
1614 |
}
|
|
1615 |
|
|
1616 |
/*
|
|
1617 |
* Initialize our mutexes now that we know the interrupt priority
|
|
1618 |
* This _must_ be done before ddi_intr_enable()
|
|
1619 |
*/
|
|
1620 |
mutex_init(&dp->intrLock, NULL, MUTEX_DRIVER, DDI_INTR_PRI(uret));
|
|
1621 |
mutex_init(&dp->txLock, NULL, MUTEX_DRIVER, DDI_INTR_PRI(uret));
|
|
1622 |
mutex_init(&dp->rxPoolLock, NULL, MUTEX_DRIVER, DDI_INTR_PRI(uret));
|
|
1623 |
|
|
1624 |
if (ddi_intr_add_handler(dp->intrHandle, vmxnet3_intr,
|
|
1625 |
dp, NULL) != DDI_SUCCESS) {
|
|
1626 |
VMXNET3_WARN(dp, "ddi_intr_add_handler() failed\n");
|
|
1627 |
goto error_mutexes;
|
|
1628 |
}
|
|
1629 |
|
|
1630 |
err = ddi_intr_get_cap(dp->intrHandle, &dp->intrCap);
|
|
1631 |
if (err != DDI_SUCCESS) {
|
|
1632 |
VMXNET3_WARN(dp, "ddi_intr_get_cap() failed %d", err);
|
|
1633 |
goto error_intr_handler;
|
|
1634 |
}
|
|
1635 |
|
|
1636 |
if (dp->intrCap & DDI_INTR_FLAG_BLOCK) {
|
|
1637 |
err = ddi_intr_block_enable(&dp->intrHandle, 1);
|
|
1638 |
if (err != DDI_SUCCESS) {
|
|
1639 |
VMXNET3_WARN(dp, "ddi_intr_block_enable() failed, err:%d\n", err);
|
|
1640 |
goto error_intr_handler;
|
|
1641 |
}
|
|
1642 |
} else {
|
|
1643 |
err = ddi_intr_enable(dp->intrHandle);
|
|
1644 |
if ((err != DDI_SUCCESS)) {
|
|
1645 |
VMXNET3_WARN(dp, "ddi_intr_enable() failed, err:%d\n", err);
|
|
1646 |
goto error_intr_handler;
|
|
1647 |
}
|
|
1648 |
}
|
|
1649 |
|
|
1650 |
return DDI_SUCCESS;
|
|
1651 |
|
|
1652 |
error_intr_handler:
|
|
1653 |
(void) ddi_intr_remove_handler(dp->intrHandle);
|
|
1654 |
error_mutexes:
|
|
1655 |
mutex_destroy(&dp->rxPoolLock);
|
|
1656 |
mutex_destroy(&dp->txLock);
|
|
1657 |
mutex_destroy(&dp->intrLock);
|
|
1658 |
ddi_taskq_destroy(dp->resetTask);
|
|
1659 |
error_intr:
|
|
1660 |
(void) ddi_intr_free(dp->intrHandle);
|
|
1661 |
error_mac:
|
|
1662 |
(void) mac_unregister(dp->mac);
|
|
1663 |
error_kstat:
|
|
1664 |
kstat_delete(dp->devKstats);
|
|
1665 |
error_regs_map_1:
|
|
1666 |
ddi_regs_map_free(&dp->bar1Handle);
|
|
1667 |
error_regs_map_0:
|
|
1668 |
ddi_regs_map_free(&dp->bar0Handle);
|
|
1669 |
error_pci_config:
|
|
1670 |
pci_config_teardown(&dp->pciHandle);
|
|
1671 |
error_soft_state:
|
|
1672 |
kmem_free(dp, sizeof(vmxnet3_softc_t));
|
|
1673 |
error:
|
|
1674 |
return DDI_FAILURE;
|
|
1675 |
}
|
|
1676 |
|
|
1677 |
/*
|
|
1678 |
*---------------------------------------------------------------------------
|
|
1679 |
*
|
|
1680 |
* vmxnet3_detach --
|
|
1681 |
*
|
|
1682 |
* Detach a vmxnet3 instance from the stack.
|
|
1683 |
*
|
|
1684 |
* Results:
|
|
1685 |
* DDI_SUCCESS or DDI_FAILURE.
|
|
1686 |
*
|
|
1687 |
* Side effects:
|
|
1688 |
* None.
|
|
1689 |
*
|
|
1690 |
*---------------------------------------------------------------------------
|
|
1691 |
*/
|
|
1692 |
static int
|
|
1693 |
vmxnet3_detach(dev_info_t *dip, ddi_detach_cmd_t cmd)
|
|
1694 |
{
|
|
1695 |
vmxnet3_softc_t *dp = ddi_get_driver_private(dip);
|
|
1696 |
unsigned int retries = 0;
|
|
1697 |
int ret;
|
|
1698 |
|
|
1699 |
VMXNET3_DEBUG(dp, 1, "detach()\n");
|
|
1700 |
|
|
1701 |
if (cmd != DDI_DETACH) {
|
|
1702 |
return DDI_FAILURE;
|
|
1703 |
}
|
|
1704 |
|
|
1705 |
while (dp->rxNumBufs) {
|
|
1706 |
if (retries++ < 10) {
|
|
1707 |
VMXNET3_WARN(dp, "rx pending (%u), waiting 1 second...\n",
|
|
1708 |
dp->rxNumBufs);
|
|
1709 |
delay(drv_usectohz(1000000));
|
|
1710 |
} else {
|
|
1711 |
VMXNET3_WARN(dp, "giving up...\n");
|
|
1712 |
return DDI_FAILURE;
|
|
1713 |
}
|
|
1714 |
}
|
|
1715 |
|
|
1716 |
if (dp->intrCap & DDI_INTR_FLAG_BLOCK) {
|
|
1717 |
ret = ddi_intr_block_disable(&dp->intrHandle, 1);
|
|
1718 |
} else {
|
|
1719 |
ret = ddi_intr_disable(dp->intrHandle);
|
|
1720 |
}
|
|
1721 |
if (ret != DDI_SUCCESS) {
|
|
1722 |
VMXNET3_WARN(dp, "unable to disable interrupts");
|
|
1723 |
return DDI_FAILURE;
|
|
1724 |
}
|
|
1725 |
if (ddi_intr_remove_handler(dp->intrHandle) != DDI_SUCCESS) {
|
|
1726 |
VMXNET3_WARN(dp, "unable to remove interrupt handler");
|
|
1727 |
return DDI_FAILURE;
|
|
1728 |
}
|
|
1729 |
(void) ddi_intr_free(dp->intrHandle);
|
|
1730 |
|
|
1731 |
VERIFY(mac_unregister(dp->mac) == 0);
|
|
1732 |
|
|
1733 |
kstat_delete(dp->devKstats);
|
|
1734 |
|
|
1735 |
if (dp->mfTable.buf) {
|
|
1736 |
vmxnet3_free_dma_mem(&dp->mfTable);
|
|
1737 |
}
|
|
1738 |
|
|
1739 |
mutex_destroy(&dp->rxPoolLock);
|
|
1740 |
mutex_destroy(&dp->txLock);
|
|
1741 |
mutex_destroy(&dp->intrLock);
|
|
1742 |
ddi_taskq_destroy(dp->resetTask);
|
|
1743 |
|
|
1744 |
ddi_regs_map_free(&dp->bar1Handle);
|
|
1745 |
ddi_regs_map_free(&dp->bar0Handle);
|
|
1746 |
pci_config_teardown(&dp->pciHandle);
|
|
1747 |
|
|
1748 |
kmem_free(dp, sizeof(vmxnet3_softc_t));
|
|
1749 |
|
|
1750 |
return DDI_SUCCESS;
|
|
1751 |
}
|
|
1752 |
|
|
1753 |
/* --- */
|
|
1754 |
|
|
1755 |
/*
|
|
1756 |
* Structures used by the Solaris module loader
|
|
1757 |
*/
|
|
1758 |
|
|
1759 |
#define VMXNET3_IDENT "VMware Ethernet v3 b" BUILD_NUMBER_NUMERIC_STRING
|
|
1760 |
|
|
1761 |
DDI_DEFINE_STREAM_OPS(vmxnet3_dev_ops,
|
|
1762 |
nulldev,
|
|
1763 |
nulldev,
|
|
1764 |
vmxnet3_attach,
|
|
1765 |
vmxnet3_detach,
|
|
1766 |
nodev,
|
|
1767 |
NULL,
|
|
1768 |
D_NEW | D_MP,
|
|
1769 |
NULL,
|
|
1770 |
ddi_quiesce_not_supported);
|
|
1771 |
|
|
1772 |
static struct modldrv vmxnet3_modldrv = {
|
|
1773 |
&mod_driverops, /* drv_modops */
|
|
1774 |
VMXNET3_IDENT, /* drv_linkinfo */
|
|
1775 |
&vmxnet3_dev_ops /* drv_dev_ops */
|
|
1776 |
};
|
|
1777 |
|
|
1778 |
static struct modlinkage vmxnet3_modlinkage = {
|
|
1779 |
MODREV_1, /* ml_rev */
|
|
1780 |
{ &vmxnet3_modldrv, NULL } /* ml_linkage */
|
|
1781 |
};
|
|
1782 |
|
|
1783 |
/* Module load entry point */
|
|
1784 |
int _init(void)
|
|
1785 |
{
|
|
1786 |
int ret;
|
|
1787 |
|
|
1788 |
mac_init_ops(&vmxnet3_dev_ops, VMXNET3_MODNAME);
|
|
1789 |
ret = mod_install(&vmxnet3_modlinkage);
|
|
1790 |
if (ret != DDI_SUCCESS) {
|
|
1791 |
mac_fini_ops(&vmxnet3_dev_ops);
|
|
1792 |
}
|
|
1793 |
|
|
1794 |
return ret;
|
|
1795 |
}
|
|
1796 |
|
|
1797 |
/* Module unload entry point */
|
|
1798 |
int _fini(void)
|
|
1799 |
{
|
|
1800 |
int ret;
|
|
1801 |
|
|
1802 |
ret = mod_remove(&vmxnet3_modlinkage);
|
|
1803 |
if (ret == DDI_SUCCESS) {
|
|
1804 |
mac_fini_ops(&vmxnet3_dev_ops);
|
|
1805 |
}
|
|
1806 |
|
|
1807 |
return ret;
|
|
1808 |
}
|
|
1809 |
|
|
1810 |
/* Module info entry point */
|
|
1811 |
int _info(struct modinfo *modinfop)
|
|
1812 |
{
|
|
1813 |
return mod_info(&vmxnet3_modlinkage, modinfop);
|
|
1814 |
}
|
|
1815 |
|
|
1816 |
void
|
|
1817 |
vmxnet3_log(int level, vmxnet3_softc_t *dp, char *fmt, ...)
|
|
1818 |
{
|
14277
|
1819 |
dev_err(dp->dip, level, fmt);
|
13976
|
1820 |
}
|