1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
*/
#include <sys/types.h>
#include <sys/conf.h>
#include <sys/devops.h>
#include <sys/kmem.h>
#include <sys/ksynch.h>
#include <sys/modctl.h>
#include <sys/stat.h>
#include <sys/ddi.h>
#include <sys/sunddi.h>
#include <sys/mac_provider.h>
#include <sys/mac_ether.h>
#include <sys/ib/clients/eoib/eib_impl.h>
/*
* Declarations private to this file
*/
static void eib_rb_mac_start(eib_t *, eib_vnic_t *);
/*
* This set of routines are used to set/clear the condition that the
* caller is about to do something that affects the state of the nic.
* If there's already someone doing either a start or a stop (possibly
* due to the async handler, a plumb or a dlpi_open happening, or an
* unplumb or dlpi_close coming in), we wait until that's done.
*/
void
eib_mac_set_nic_state(eib_t *ss, uint_t flags)
{
eib_node_state_t *ns = ss->ei_node_state;
mutex_enter(&ns->ns_lock);
while ((ns->ns_nic_state & EIB_NIC_STARTING) ||
(ns->ns_nic_state & EIB_NIC_STOPPING)) {
cv_wait(&ns->ns_cv, &ns->ns_lock);
}
ns->ns_nic_state |= flags;
mutex_exit(&ns->ns_lock);
}
void
eib_mac_clr_nic_state(eib_t *ss, uint_t flags)
{
eib_node_state_t *ns = ss->ei_node_state;
mutex_enter(&ns->ns_lock);
ns->ns_nic_state &= (~flags);
cv_broadcast(&ns->ns_cv);
mutex_exit(&ns->ns_lock);
}
void
eib_mac_upd_nic_state(eib_t *ss, uint_t clr_flags, uint_t set_flags)
{
eib_node_state_t *ns = ss->ei_node_state;
mutex_enter(&ns->ns_lock);
ns->ns_nic_state &= (~clr_flags);
ns->ns_nic_state |= set_flags;
cv_broadcast(&ns->ns_cv);
mutex_exit(&ns->ns_lock);
}
uint_t
eib_mac_get_nic_state(eib_t *ss)
{
eib_node_state_t *ns = ss->ei_node_state;
uint_t nic_state;
mutex_enter(&ns->ns_lock);
nic_state = ns->ns_nic_state;
mutex_exit(&ns->ns_lock);
return (nic_state);
}
void
eib_mac_link_state(eib_t *ss, link_state_t new_link_state,
boolean_t force)
{
eib_node_state_t *ns = ss->ei_node_state;
boolean_t state_changed = B_FALSE;
mutex_enter(&ns->ns_lock);
/*
* We track the link state only if the current link state is
* not unknown. Obviously therefore, the first calls to set
* the link state from eib_mac_start() have to pass an explicit
* 'force' flag to force the state change tracking.
*/
if (ns->ns_link_state != LINK_STATE_UNKNOWN)
force = B_TRUE;
if ((force) && (new_link_state != ns->ns_link_state)) {
ns->ns_link_state = new_link_state;
state_changed = B_TRUE;
}
mutex_exit(&ns->ns_lock);
if (state_changed) {
EIB_DPRINTF_DEBUG(ss->ei_instance,
"eib_mac_link_state: changing link state to %d",
new_link_state);
mac_link_update(ss->ei_mac_hdl, new_link_state);
} else {
EIB_DPRINTF_DEBUG(ss->ei_instance,
"eib_mac_link_state: link state already %d",
new_link_state);
}
}
void
eib_mac_link_up(eib_t *ss, boolean_t force)
{
eib_mac_link_state(ss, LINK_STATE_UP, force);
}
void
eib_mac_link_down(eib_t *ss, boolean_t force)
{
eib_mac_link_state(ss, LINK_STATE_DOWN, force);
}
int
eib_mac_start(eib_t *ss)
{
eib_vnic_t *vnic0 = NULL;
eib_login_data_t *ld;
int err;
/*
* Perform HCA related initializations
*/
if (eib_ibt_hca_init(ss) != EIB_E_SUCCESS)
goto start_fail;
/*
* Make sure port is up. Also record the port base lid if it's up.
*/
if (eib_mac_hca_portstate(ss, &ss->ei_props->ep_blid,
&err) != EIB_E_SUCCESS) {
goto start_fail;
}
/*
* Set up tx and rx buffer pools
*/
if (eib_rsrc_setup_bufs(ss, &err) != EIB_E_SUCCESS)
goto start_fail;
/*
* Set up admin qp for logins and logouts
*/
if (eib_adm_setup_qp(ss, &err) != EIB_E_SUCCESS)
goto start_fail;
/*
* Create the vnic for physlink (instance 0)
*/
if (eib_vnic_create(ss, 0, 0, &vnic0, &err) != EIB_E_SUCCESS)
goto start_fail;
/*
* Update the mac layer about the correct values for MTU and
* unicast MAC address. Note that we've already verified that the
* vhub mtu (plus the eoib encapsulation header) is not greater
* than our port mtu, so we can go ahead and report the vhub mtu
* (of vnic0) directly.
*/
ld = &(vnic0->vn_login_data);
(void) mac_maxsdu_update(ss->ei_mac_hdl, ld->ld_vhub_mtu);
mac_unicst_update(ss->ei_mac_hdl, ld->ld_assigned_mac);
/*
* Report that the link is up and ready
*/
eib_mac_link_up(ss, B_TRUE);
return (0);
start_fail:
eib_rb_mac_start(ss, vnic0);
eib_mac_link_down(ss, B_TRUE);
return (err);
}
void
eib_mac_stop(eib_t *ss)
{
eib_vnic_t *vnic;
link_state_t cur_link_state = ss->ei_node_state->ns_link_state;
int ndx;
/*
* Stopping an EoIB device instance is somewhat different from starting
* it. Between the time the device instance was started and the call to
* eib_m_stop() now, a number of vnics could've been created. All of
* these will need to be destroyed before we can stop the device.
*/
for (ndx = EIB_MAX_VNICS - 1; ndx >= 0; ndx--) {
if ((vnic = ss->ei_vnic[ndx]) != NULL)
eib_vnic_delete(ss, vnic);
}
/*
* And now, to undo the things we did in start (other than creation
* of vnics itself)
*/
eib_rb_mac_start(ss, NULL);
/*
* Now that we're completed stopped, there's no mac address assigned
* to us. Update the mac layer with this information. Note that we
* can let the old max mtu information remain as-is, since we're likely
* to get that same mtu on a later plumb.
*/
mac_unicst_update(ss->ei_mac_hdl, eib_zero_mac);
/*
* If our link state was up when the eib_m_stop() callback was called,
* we'll mark the link state as unknown now. Otherwise, we'll leave
* the link state as-is (down).
*/
if (cur_link_state == LINK_STATE_UP)
eib_mac_link_state(ss, LINK_STATE_UNKNOWN, B_TRUE);
}
int
eib_mac_multicast(eib_t *ss, boolean_t add, uint8_t *mcast_mac)
{
int ret = EIB_E_SUCCESS;
int err = 0;
/*
* If it's a broadcast group join, each vnic needs to and is always
* joined to the broadcast address, so we return success immediately.
* If it's a broadcast group leave, we fail immediately for the same
* reason as above.
*/
if (bcmp(mcast_mac, eib_broadcast_mac, ETHERADDRL) == 0) {
if (add)
return (0);
else
return (EINVAL);
}
if (ss->ei_vnic[0]) {
if (add) {
ret = eib_vnic_join_data_mcg(ss, ss->ei_vnic[0],
mcast_mac, B_FALSE, &err);
} else {
eib_vnic_leave_data_mcg(ss, ss->ei_vnic[0], mcast_mac);
ret = EIB_E_SUCCESS;
}
}
if (ret == EIB_E_SUCCESS)
return (0);
else
return (err);
}
int
eib_mac_promisc(eib_t *ss, boolean_t set)
{
int ret = EIB_E_SUCCESS;
int err = 0;
if (ss->ei_vnic[0]) {
if (set) {
ret = eib_vnic_join_data_mcg(ss, ss->ei_vnic[0],
eib_zero_mac, B_FALSE, &err);
} else {
eib_vnic_leave_data_mcg(ss, ss->ei_vnic[0],
eib_zero_mac);
ret = EIB_E_SUCCESS;
}
}
if (ret == EIB_E_SUCCESS)
return (0);
else
return (err);
}
int
eib_mac_tx(eib_t *ss, mblk_t *mp)
{
eib_ether_hdr_t evh;
eib_vnic_t *vnic = NULL;
eib_wqe_t *swqe = NULL;
boolean_t failed_vnic;
int found;
int ret;
/*
* Grab a send wqe. If we cannot get one, wake up a service
* thread to monitor the swqe status and let the mac layer know
* as soon as we have enough tx wqes to start the traffic again.
*/
if ((swqe = eib_rsrc_grab_swqe(ss, EIB_WPRI_LO)) == NULL) {
EIB_DPRINTF_WARN(ss->ei_instance, "eib_mac_tx: "
"no swqe available, holding tx until resource "
"becomes available");
eib_rsrc_txwqes_needed(ss);
return (EIB_E_FAILURE);
}
/*
* Determine dmac, smac and vlan information
*/
eib_data_parse_ether_hdr(mp, &evh);
/*
* Lookup the {smac, vlan} tuple in our vnic list. If it isn't
* there, this is obviously a new packet on a vnic/vlan that
* we haven't been informed about. So go ahead and file a request
* to create a new vnic. This is obviously not a clean thing to
* do - we should be informed when a vnic/vlan is being created
* and should be given a proper opportunity to login to the gateway
* and do the creation. But we don't have that luxury now, and
* this is the next best thing to do. Note that we return failure
* from here, so tx flow control should prevent further packets
* from coming in until the vnic creation has completed.
*/
found = eib_data_lookup_vnic(ss, evh.eh_smac, evh.eh_vlan, &vnic,
&failed_vnic);
if (found != EIB_E_SUCCESS) {
uint8_t *m = evh.eh_smac;
/*
* Return the swqe back to the pool
*/
eib_rsrc_return_swqe(ss, swqe, NULL);
/*
* If we had previously tried creating this vnic and had
* failed, we'll simply drop the packets on this vnic.
* Otherwise, we'll queue up a request to create this vnic.
*/
if (failed_vnic) {
EIB_DPRINTF_VERBOSE(ss->ei_instance, "eib_mac_tx: "
"vnic creation for mac=%x:%x:%x:%x:%x:%x "
"vlan=0x%x failed previously, dropping pkt",
m[0], m[1], m[2], m[3], m[4], m[5], evh.eh_vlan);
return (EIB_E_SUCCESS);
} else {
eib_vnic_need_new(ss, evh.eh_smac, evh.eh_vlan);
return (EIB_E_FAILURE);
}
}
/*
* We'll try to setup the destination in the swqe for this dmac
* and vlan. If we don't succeed, there's no need to undo any
* vnic-creation we might've made above (if we didn't find the
* vnic corresponding to the {smac, vlan} originally). Note that
* this is not a resource issue, so we'll issue a warning and
* drop the packet, but won't return failure from here.
*/
ret = eib_vnic_setup_dest(vnic, swqe, evh.eh_dmac, evh.eh_vlan);
if (ret != EIB_E_SUCCESS) {
uint8_t *dmac;
dmac = evh.eh_dmac;
EIB_DPRINTF_WARN(ss->ei_instance, "eib_mac_tx: "
"eib_vnic_setup_dest() failed for mac=%x:%x:%x:%x:%x:%x, "
"vlan=0x%x, dropping pkt", dmac[0], dmac[1], dmac[2],
dmac[3], dmac[4], dmac[5]);
eib_rsrc_return_swqe(ss, swqe, NULL);
return (EIB_E_SUCCESS);
}
/*
* The only reason why this would fail is if we needed LSO buffer(s)
* to prepare this frame and couldn't find enough of those.
*/
ret = eib_data_prepare_frame(vnic, swqe, mp, &evh);
if (ret != EIB_E_SUCCESS) {
EIB_DPRINTF_WARN(ss->ei_instance, "eib_mac_tx: "
"eib_data_prepare_frame() failed (no LSO bufs?), "
"holding tx until resource becomes available");
eib_rsrc_return_swqe(ss, swqe, NULL);
eib_rsrc_lsobufs_needed(ss);
return (EIB_E_FAILURE);
}
eib_data_post_tx(vnic, swqe);
return (EIB_E_SUCCESS);
}
int
eib_mac_hca_portstate(eib_t *ss, ib_lid_t *blid, int *err)
{
ibt_hca_portinfo_t *pi;
ibt_status_t ret;
uint_t num_pi;
uint_t sz_pi;
ret = ibt_query_hca_ports(ss->ei_hca_hdl, ss->ei_props->ep_port_num,
&pi, &num_pi, &sz_pi);
if (ret != IBT_SUCCESS) {
EIB_DPRINTF_ERR(ss->ei_instance,
"ibt_query_hca_ports(hca_hdl=0x%llx, "
"port=0x%x) failed, ret=%d", ss->ei_hca_hdl,
ss->ei_props->ep_port_num, ret);
goto mac_hca_portstate_fail;
}
if (num_pi != 1) {
EIB_DPRINTF_ERR(ss->ei_instance,
"ibt_query_hca_ports(hca_hdl=0x%llx, "
"port=0x%x) returned num_pi=%d", ss->ei_hca_hdl,
ss->ei_props->ep_port_num, num_pi);
goto mac_hca_portstate_fail;
}
if (pi->p_linkstate != IBT_PORT_ACTIVE)
goto mac_hca_portstate_fail;
/*
* Return the port's base lid if asked
*/
if (blid) {
*blid = pi->p_base_lid;
}
ibt_free_portinfo(pi, sz_pi);
return (EIB_E_SUCCESS);
mac_hca_portstate_fail:
if (pi) {
ibt_free_portinfo(pi, sz_pi);
}
if (err) {
*err = ENETDOWN;
}
return (EIB_E_FAILURE);
}
static void
eib_rb_mac_start(eib_t *ss, eib_vnic_t *vnic0)
{
int ntries;
/*
* If vnic0 is non-null, delete it
*/
if (vnic0) {
eib_rb_vnic_create(ss, vnic0, ~0);
}
/*
* At this point, we're pretty much done with all communication that
* we need to do for vnic-logout, etc. so we can get rid of any address
* vectors we might've allocated to send control/data packets.
*/
eib_ibt_free_avects(ss);
/*
* Tear down the rest of it
*/
if (ss->ei_admin_chan) {
eib_rb_adm_setup_qp(ss);
}
/*
* If (say) the network layer has been holding onto our rx buffers, we
* wait a reasonable time for it to hand them back to us. If we don't
* get it still, we have nothing to do but avoid rolling back hca init
* since we cannot unregister the memory, release the pd or close the
* hca. We'll try to reuse it if there's a plumb again.
*/
for (ntries = 0; ntries < EIB_MAX_ATTEMPTS; ntries++) {
eib_rb_rsrc_setup_bufs(ss, B_FALSE);
if ((ss->ei_tx == NULL) && (ss->ei_rx == NULL) &&
(ss->ei_lso == NULL)) {
break;
}
delay(drv_usectohz(EIB_DELAY_HALF_SECOND));
}
if (ntries == EIB_MAX_ATTEMPTS) {
EIB_DPRINTF_WARN(ss->ei_instance, "eib_rb_mac_start: "
"bufs outstanding, tx=0x%llx, rx=0x%llx, lso=0x%llx",
ss->ei_tx, ss->ei_rx, ss->ei_lso);
} else if (ss->ei_hca_hdl) {
eib_rb_ibt_hca_init(ss, ~0);
}
ss->ei_props->ep_blid = 0;
/*
* Pending vnic creation requests (and failed-vnic records) will have
* to be cleaned up in any case
*/
eib_flush_vnic_reqs(ss);
}
|