Print this page
11493 aggr needs support for multiple pseudo rx groups
Portions contributed by: Dan McDonald <danmcd@joyent.com>
Reviewed by: Patrick Mooney <patrick.mooney@joyent.com>
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>
Reviewed by: Robert Mustacchi <rm@joyent.com>
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/io/mac/mac_provider.c
+++ new/usr/src/uts/common/io/mac/mac_provider.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /*
23 23 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
24 24 * Copyright 2018 Joyent, Inc.
25 25 * Copyright 2017 OmniTI Computer Consulting, Inc. All rights reserved.
26 26 */
27 27
28 28 #include <sys/types.h>
29 29 #include <sys/conf.h>
30 30 #include <sys/id_space.h>
31 31 #include <sys/esunddi.h>
32 32 #include <sys/stat.h>
33 33 #include <sys/mkdev.h>
34 34 #include <sys/stream.h>
35 35 #include <sys/strsubr.h>
36 36 #include <sys/dlpi.h>
37 37 #include <sys/modhash.h>
38 38 #include <sys/mac.h>
39 39 #include <sys/mac_provider.h>
40 40 #include <sys/mac_impl.h>
41 41 #include <sys/mac_client_impl.h>
42 42 #include <sys/mac_client_priv.h>
43 43 #include <sys/mac_soft_ring.h>
44 44 #include <sys/mac_stat.h>
45 45 #include <sys/dld.h>
46 46 #include <sys/modctl.h>
47 47 #include <sys/fs/dv_node.h>
48 48 #include <sys/thread.h>
49 49 #include <sys/proc.h>
50 50 #include <sys/callb.h>
51 51 #include <sys/cpuvar.h>
52 52 #include <sys/atomic.h>
53 53 #include <sys/sdt.h>
54 54 #include <sys/mac_flow.h>
55 55 #include <sys/ddi_intr_impl.h>
56 56 #include <sys/disp.h>
57 57 #include <sys/sdt.h>
58 58 #include <sys/pattr.h>
59 59 #include <sys/strsun.h>
60 60 #include <sys/vlan.h>
61 61
62 62 /*
63 63 * MAC Provider Interface.
64 64 *
65 65 * Interface for GLDv3 compatible NIC drivers.
66 66 */
67 67
68 68 static void i_mac_notify_thread(void *);
69 69
70 70 typedef void (*mac_notify_default_cb_fn_t)(mac_impl_t *);
71 71
72 72 static const mac_notify_default_cb_fn_t mac_notify_cb_list[MAC_NNOTE] = {
73 73 mac_fanout_recompute, /* MAC_NOTE_LINK */
74 74 NULL, /* MAC_NOTE_UNICST */
75 75 NULL, /* MAC_NOTE_TX */
76 76 NULL, /* MAC_NOTE_DEVPROMISC */
77 77 NULL, /* MAC_NOTE_FASTPATH_FLUSH */
78 78 NULL, /* MAC_NOTE_SDU_SIZE */
79 79 NULL, /* MAC_NOTE_MARGIN */
80 80 NULL, /* MAC_NOTE_CAPAB_CHG */
81 81 NULL /* MAC_NOTE_LOWLINK */
82 82 };
83 83
84 84 /*
85 85 * Driver support functions.
86 86 */
87 87
88 88 /* REGISTRATION */
89 89
90 90 mac_register_t *
91 91 mac_alloc(uint_t mac_version)
92 92 {
93 93 mac_register_t *mregp;
94 94
95 95 /*
96 96 * Make sure there isn't a version mismatch between the driver and
97 97 * the framework. In the future, if multiple versions are
98 98 * supported, this check could become more sophisticated.
99 99 */
100 100 if (mac_version != MAC_VERSION)
101 101 return (NULL);
102 102
103 103 mregp = kmem_zalloc(sizeof (mac_register_t), KM_SLEEP);
104 104 mregp->m_version = mac_version;
105 105 return (mregp);
106 106 }
107 107
108 108 void
109 109 mac_free(mac_register_t *mregp)
110 110 {
111 111 kmem_free(mregp, sizeof (mac_register_t));
112 112 }
113 113
114 114 /*
115 115 * mac_register() is how drivers register new MACs with the GLDv3
116 116 * framework. The mregp argument is allocated by drivers using the
117 117 * mac_alloc() function, and can be freed using mac_free() immediately upon
118 118 * return from mac_register(). Upon success (0 return value), the mhp
119 119 * opaque pointer becomes the driver's handle to its MAC interface, and is
120 120 * the argument to all other mac module entry points.
121 121 */
122 122 /* ARGSUSED */
123 123 int
124 124 mac_register(mac_register_t *mregp, mac_handle_t *mhp)
125 125 {
126 126 mac_impl_t *mip;
127 127 mactype_t *mtype;
128 128 int err = EINVAL;
129 129 struct devnames *dnp = NULL;
130 130 uint_t instance;
131 131 boolean_t style1_created = B_FALSE;
132 132 boolean_t style2_created = B_FALSE;
133 133 char *driver;
134 134 minor_t minor = 0;
135 135
136 136 /* A successful call to mac_init_ops() sets the DN_GLDV3_DRIVER flag. */
137 137 if (!GLDV3_DRV(ddi_driver_major(mregp->m_dip)))
138 138 return (EINVAL);
139 139
140 140 /* Find the required MAC-Type plugin. */
141 141 if ((mtype = mactype_getplugin(mregp->m_type_ident)) == NULL)
142 142 return (EINVAL);
143 143
144 144 /* Create a mac_impl_t to represent this MAC. */
145 145 mip = kmem_cache_alloc(i_mac_impl_cachep, KM_SLEEP);
146 146
147 147 /*
148 148 * The mac is not ready for open yet.
149 149 */
150 150 mip->mi_state_flags |= MIS_DISABLED;
151 151
152 152 /*
153 153 * When a mac is registered, the m_instance field can be set to:
154 154 *
155 155 * 0: Get the mac's instance number from m_dip.
156 156 * This is usually used for physical device dips.
157 157 *
158 158 * [1 .. MAC_MAX_MINOR-1]: Use the value as the mac's instance number.
159 159 * For example, when an aggregation is created with the key option,
160 160 * "key" will be used as the instance number.
161 161 *
162 162 * -1: Assign an instance number from [MAC_MAX_MINOR .. MAXMIN-1].
163 163 * This is often used when a MAC of a virtual link is registered
164 164 * (e.g., aggregation when "key" is not specified, or vnic).
165 165 *
166 166 * Note that the instance number is used to derive the mi_minor field
167 167 * of mac_impl_t, which will then be used to derive the name of kstats
168 168 * and the devfs nodes. The first 2 cases are needed to preserve
169 169 * backward compatibility.
170 170 */
171 171 switch (mregp->m_instance) {
172 172 case 0:
173 173 instance = ddi_get_instance(mregp->m_dip);
174 174 break;
175 175 case ((uint_t)-1):
176 176 minor = mac_minor_hold(B_TRUE);
177 177 if (minor == 0) {
178 178 err = ENOSPC;
179 179 goto fail;
180 180 }
181 181 instance = minor - 1;
182 182 break;
183 183 default:
184 184 instance = mregp->m_instance;
185 185 if (instance >= MAC_MAX_MINOR) {
186 186 err = EINVAL;
187 187 goto fail;
188 188 }
189 189 break;
190 190 }
191 191
192 192 mip->mi_minor = (minor_t)(instance + 1);
193 193 mip->mi_dip = mregp->m_dip;
194 194 mip->mi_clients_list = NULL;
195 195 mip->mi_nclients = 0;
196 196
197 197 /* Set the default IEEE Port VLAN Identifier */
198 198 mip->mi_pvid = 1;
199 199
200 200 /* Default bridge link learning protection values */
201 201 mip->mi_llimit = 1000;
202 202 mip->mi_ldecay = 200;
203 203
204 204 driver = (char *)ddi_driver_name(mip->mi_dip);
205 205
206 206 /* Construct the MAC name as <drvname><instance> */
207 207 (void) snprintf(mip->mi_name, sizeof (mip->mi_name), "%s%d",
208 208 driver, instance);
209 209
210 210 mip->mi_driver = mregp->m_driver;
211 211
212 212 mip->mi_type = mtype;
213 213 mip->mi_margin = mregp->m_margin;
214 214 mip->mi_info.mi_media = mtype->mt_type;
215 215 mip->mi_info.mi_nativemedia = mtype->mt_nativetype;
216 216 if (mregp->m_max_sdu <= mregp->m_min_sdu)
217 217 goto fail;
218 218 if (mregp->m_multicast_sdu == 0)
219 219 mregp->m_multicast_sdu = mregp->m_max_sdu;
220 220 if (mregp->m_multicast_sdu < mregp->m_min_sdu ||
221 221 mregp->m_multicast_sdu > mregp->m_max_sdu)
222 222 goto fail;
223 223 mip->mi_sdu_min = mregp->m_min_sdu;
224 224 mip->mi_sdu_max = mregp->m_max_sdu;
225 225 mip->mi_sdu_multicast = mregp->m_multicast_sdu;
226 226 mip->mi_info.mi_addr_length = mip->mi_type->mt_addr_length;
227 227 /*
228 228 * If the media supports a broadcast address, cache a pointer to it
229 229 * in the mac_info_t so that upper layers can use it.
230 230 */
231 231 mip->mi_info.mi_brdcst_addr = mip->mi_type->mt_brdcst_addr;
232 232
233 233 mip->mi_v12n_level = mregp->m_v12n;
234 234
235 235 /*
236 236 * Copy the unicast source address into the mac_info_t, but only if
237 237 * the MAC-Type defines a non-zero address length. We need to
238 238 * handle MAC-Types that have an address length of 0
239 239 * (point-to-point protocol MACs for example).
240 240 */
241 241 if (mip->mi_type->mt_addr_length > 0) {
242 242 if (mregp->m_src_addr == NULL)
243 243 goto fail;
244 244 mip->mi_info.mi_unicst_addr =
245 245 kmem_alloc(mip->mi_type->mt_addr_length, KM_SLEEP);
246 246 bcopy(mregp->m_src_addr, mip->mi_info.mi_unicst_addr,
247 247 mip->mi_type->mt_addr_length);
248 248
249 249 /*
250 250 * Copy the fixed 'factory' MAC address from the immutable
251 251 * info. This is taken to be the MAC address currently in
252 252 * use.
253 253 */
254 254 bcopy(mip->mi_info.mi_unicst_addr, mip->mi_addr,
255 255 mip->mi_type->mt_addr_length);
256 256
257 257 /*
258 258 * At this point, we should set up the classification
259 259 * rules etc but we delay it till mac_open() so that
260 260 * the resource discovery has taken place and we
261 261 * know someone wants to use the device. Otherwise
262 262 * memory gets allocated for Rx ring structures even
263 263 * during probe.
264 264 */
265 265
266 266 /* Copy the destination address if one is provided. */
267 267 if (mregp->m_dst_addr != NULL) {
268 268 bcopy(mregp->m_dst_addr, mip->mi_dstaddr,
269 269 mip->mi_type->mt_addr_length);
270 270 mip->mi_dstaddr_set = B_TRUE;
271 271 }
272 272 } else if (mregp->m_src_addr != NULL) {
273 273 goto fail;
274 274 }
275 275
276 276 /*
277 277 * The format of the m_pdata is specific to the plugin. It is
278 278 * passed in as an argument to all of the plugin callbacks. The
279 279 * driver can update this information by calling
280 280 * mac_pdata_update().
281 281 */
282 282 if (mip->mi_type->mt_ops.mtops_ops & MTOPS_PDATA_VERIFY) {
283 283 /*
284 284 * Verify if the supplied plugin data is valid. Note that
285 285 * even if the caller passed in a NULL pointer as plugin data,
286 286 * we still need to verify if that's valid as the plugin may
287 287 * require plugin data to function.
288 288 */
289 289 if (!mip->mi_type->mt_ops.mtops_pdata_verify(mregp->m_pdata,
290 290 mregp->m_pdata_size)) {
291 291 goto fail;
292 292 }
293 293 if (mregp->m_pdata != NULL) {
294 294 mip->mi_pdata =
295 295 kmem_alloc(mregp->m_pdata_size, KM_SLEEP);
296 296 bcopy(mregp->m_pdata, mip->mi_pdata,
297 297 mregp->m_pdata_size);
298 298 mip->mi_pdata_size = mregp->m_pdata_size;
299 299 }
300 300 } else if (mregp->m_pdata != NULL) {
301 301 /*
302 302 * The caller supplied non-NULL plugin data, but the plugin
303 303 * does not recognize plugin data.
304 304 */
305 305 err = EINVAL;
306 306 goto fail;
307 307 }
308 308
309 309 /*
310 310 * Register the private properties.
311 311 */
312 312 mac_register_priv_prop(mip, mregp->m_priv_props);
313 313
314 314 /*
315 315 * Stash the driver callbacks into the mac_impl_t, but first sanity
316 316 * check to make sure all mandatory callbacks are set.
317 317 */
318 318 if (mregp->m_callbacks->mc_getstat == NULL ||
319 319 mregp->m_callbacks->mc_start == NULL ||
320 320 mregp->m_callbacks->mc_stop == NULL ||
321 321 mregp->m_callbacks->mc_setpromisc == NULL ||
322 322 mregp->m_callbacks->mc_multicst == NULL) {
323 323 goto fail;
324 324 }
325 325 mip->mi_callbacks = mregp->m_callbacks;
326 326
327 327 if (mac_capab_get((mac_handle_t)mip, MAC_CAPAB_LEGACY,
328 328 &mip->mi_capab_legacy)) {
329 329 mip->mi_state_flags |= MIS_LEGACY;
330 330 mip->mi_phy_dev = mip->mi_capab_legacy.ml_dev;
331 331 } else {
332 332 mip->mi_phy_dev = makedevice(ddi_driver_major(mip->mi_dip),
333 333 mip->mi_minor);
334 334 }
335 335
336 336 /*
337 337 * Allocate a notification thread. thread_create blocks for memory
338 338 * if needed, it never fails.
339 339 */
340 340 mip->mi_notify_thread = thread_create(NULL, 0, i_mac_notify_thread,
341 341 mip, 0, &p0, TS_RUN, minclsyspri);
342 342
343 343 /*
344 344 * Initialize the capabilities
345 345 */
346 346
347 347 bzero(&mip->mi_rx_rings_cap, sizeof (mac_capab_rings_t));
348 348 bzero(&mip->mi_tx_rings_cap, sizeof (mac_capab_rings_t));
349 349
350 350 if (i_mac_capab_get((mac_handle_t)mip, MAC_CAPAB_VNIC, NULL))
351 351 mip->mi_state_flags |= MIS_IS_VNIC;
352 352
353 353 if (i_mac_capab_get((mac_handle_t)mip, MAC_CAPAB_AGGR, NULL))
354 354 mip->mi_state_flags |= MIS_IS_AGGR;
355 355
356 356 mac_addr_factory_init(mip);
357 357
358 358 mac_transceiver_init(mip);
359 359
360 360 mac_led_init(mip);
361 361
362 362 /*
363 363 * Enforce the virtrualization level registered.
364 364 */
365 365 if (mip->mi_v12n_level & MAC_VIRT_LEVEL1) {
366 366 if (mac_init_rings(mip, MAC_RING_TYPE_RX) != 0 ||
367 367 mac_init_rings(mip, MAC_RING_TYPE_TX) != 0)
368 368 goto fail;
369 369
370 370 /*
371 371 * The driver needs to register at least rx rings for this
372 372 * virtualization level.
373 373 */
374 374 if (mip->mi_rx_groups == NULL)
375 375 goto fail;
376 376 }
377 377
378 378 /*
379 379 * The driver must set mc_unicst entry point to NULL when it advertises
380 380 * CAP_RINGS for rx groups.
381 381 */
382 382 if (mip->mi_rx_groups != NULL) {
383 383 if (mregp->m_callbacks->mc_unicst != NULL)
384 384 goto fail;
385 385 } else {
386 386 if (mregp->m_callbacks->mc_unicst == NULL)
387 387 goto fail;
388 388 }
389 389
390 390 /*
391 391 * Initialize MAC addresses. Must be called after mac_init_rings().
392 392 */
393 393 mac_init_macaddr(mip);
394 394
395 395 mip->mi_share_capab.ms_snum = 0;
396 396 if (mip->mi_v12n_level & MAC_VIRT_HIO) {
397 397 (void) mac_capab_get((mac_handle_t)mip, MAC_CAPAB_SHARES,
398 398 &mip->mi_share_capab);
399 399 }
400 400
401 401 /*
402 402 * Initialize the kstats for this device.
403 403 */
404 404 mac_driver_stat_create(mip);
405 405
406 406 /* Zero out any properties. */
407 407 bzero(&mip->mi_resource_props, sizeof (mac_resource_props_t));
408 408
409 409 if (mip->mi_minor <= MAC_MAX_MINOR) {
410 410 /* Create a style-2 DLPI device */
411 411 if (ddi_create_minor_node(mip->mi_dip, driver, S_IFCHR, 0,
412 412 DDI_NT_NET, CLONE_DEV) != DDI_SUCCESS)
413 413 goto fail;
414 414 style2_created = B_TRUE;
415 415
416 416 /* Create a style-1 DLPI device */
417 417 if (ddi_create_minor_node(mip->mi_dip, mip->mi_name, S_IFCHR,
418 418 mip->mi_minor, DDI_NT_NET, 0) != DDI_SUCCESS)
419 419 goto fail;
420 420 style1_created = B_TRUE;
421 421 }
422 422
423 423 mac_flow_l2tab_create(mip, &mip->mi_flow_tab);
424 424
425 425 rw_enter(&i_mac_impl_lock, RW_WRITER);
426 426 if (mod_hash_insert(i_mac_impl_hash,
427 427 (mod_hash_key_t)mip->mi_name, (mod_hash_val_t)mip) != 0) {
428 428 rw_exit(&i_mac_impl_lock);
429 429 err = EEXIST;
430 430 goto fail;
431 431 }
432 432
433 433 DTRACE_PROBE2(mac__register, struct devnames *, dnp,
434 434 (mac_impl_t *), mip);
435 435
436 436 /*
437 437 * Mark the MAC to be ready for open.
438 438 */
439 439 mip->mi_state_flags &= ~MIS_DISABLED;
440 440 rw_exit(&i_mac_impl_lock);
441 441
442 442 atomic_inc_32(&i_mac_impl_count);
443 443
444 444 cmn_err(CE_NOTE, "!%s registered", mip->mi_name);
445 445 *mhp = (mac_handle_t)mip;
446 446 return (0);
447 447
448 448 fail:
449 449 if (style1_created)
450 450 ddi_remove_minor_node(mip->mi_dip, mip->mi_name);
451 451
452 452 if (style2_created)
453 453 ddi_remove_minor_node(mip->mi_dip, driver);
454 454
455 455 mac_addr_factory_fini(mip);
456 456
457 457 /* Clean up registered MAC addresses */
458 458 mac_fini_macaddr(mip);
459 459
460 460 /* Clean up registered rings */
461 461 mac_free_rings(mip, MAC_RING_TYPE_RX);
462 462 mac_free_rings(mip, MAC_RING_TYPE_TX);
463 463
464 464 /* Clean up notification thread */
465 465 if (mip->mi_notify_thread != NULL)
466 466 i_mac_notify_exit(mip);
467 467
468 468 if (mip->mi_info.mi_unicst_addr != NULL) {
469 469 kmem_free(mip->mi_info.mi_unicst_addr,
470 470 mip->mi_type->mt_addr_length);
471 471 mip->mi_info.mi_unicst_addr = NULL;
472 472 }
473 473
474 474 mac_driver_stat_delete(mip);
475 475
476 476 if (mip->mi_type != NULL) {
477 477 atomic_dec_32(&mip->mi_type->mt_ref);
478 478 mip->mi_type = NULL;
479 479 }
480 480
481 481 if (mip->mi_pdata != NULL) {
482 482 kmem_free(mip->mi_pdata, mip->mi_pdata_size);
483 483 mip->mi_pdata = NULL;
484 484 mip->mi_pdata_size = 0;
485 485 }
486 486
487 487 if (minor != 0) {
488 488 ASSERT(minor > MAC_MAX_MINOR);
489 489 mac_minor_rele(minor);
490 490 }
491 491
492 492 mip->mi_state_flags = 0;
493 493 mac_unregister_priv_prop(mip);
494 494
495 495 /*
496 496 * Clear the state before destroying the mac_impl_t
497 497 */
498 498 mip->mi_state_flags = 0;
499 499
500 500 kmem_cache_free(i_mac_impl_cachep, mip);
501 501 return (err);
502 502 }
503 503
504 504 /*
505 505 * Unregister from the GLDv3 framework
506 506 */
507 507 int
508 508 mac_unregister(mac_handle_t mh)
509 509 {
510 510 int err;
511 511 mac_impl_t *mip = (mac_impl_t *)mh;
512 512 mod_hash_val_t val;
513 513 mac_margin_req_t *mmr, *nextmmr;
514 514
515 515 /* Fail the unregister if there are any open references to this mac. */
516 516 if ((err = mac_disable_nowait(mh)) != 0)
517 517 return (err);
518 518
519 519 /*
520 520 * Clean up notification thread and wait for it to exit.
521 521 */
522 522 i_mac_notify_exit(mip);
523 523
524 524 /*
525 525 * Prior to acquiring the MAC perimeter, remove the MAC instance from
526 526 * the internal hash table. Such removal means table-walkers that
527 527 * acquire the perimeter will not do so on behalf of what we are
528 528 * unregistering, which prevents a deadlock.
529 529 */
530 530 rw_enter(&i_mac_impl_lock, RW_WRITER);
531 531 (void) mod_hash_remove(i_mac_impl_hash,
532 532 (mod_hash_key_t)mip->mi_name, &val);
533 533 rw_exit(&i_mac_impl_lock);
534 534 ASSERT(mip == (mac_impl_t *)val);
535 535
536 536 i_mac_perim_enter(mip);
537 537
538 538 /*
539 539 * There is still resource properties configured over this mac.
540 540 */
541 541 if (mip->mi_resource_props.mrp_mask != 0)
542 542 mac_fastpath_enable((mac_handle_t)mip);
543 543
544 544 if (mip->mi_minor < MAC_MAX_MINOR + 1) {
545 545 ddi_remove_minor_node(mip->mi_dip, mip->mi_name);
546 546 ddi_remove_minor_node(mip->mi_dip,
547 547 (char *)ddi_driver_name(mip->mi_dip));
548 548 }
549 549
550 550 ASSERT(mip->mi_nactiveclients == 0 && !(mip->mi_state_flags &
551 551 MIS_EXCLUSIVE));
552 552
553 553 mac_driver_stat_delete(mip);
554 554
555 555 ASSERT(i_mac_impl_count > 0);
556 556 atomic_dec_32(&i_mac_impl_count);
557 557
558 558 if (mip->mi_pdata != NULL)
559 559 kmem_free(mip->mi_pdata, mip->mi_pdata_size);
560 560 mip->mi_pdata = NULL;
561 561 mip->mi_pdata_size = 0;
562 562
563 563 /*
564 564 * Free the list of margin request.
565 565 */
566 566 for (mmr = mip->mi_mmrp; mmr != NULL; mmr = nextmmr) {
567 567 nextmmr = mmr->mmr_nextp;
568 568 kmem_free(mmr, sizeof (mac_margin_req_t));
569 569 }
570 570 mip->mi_mmrp = NULL;
571 571
572 572 mip->mi_linkstate = mip->mi_lowlinkstate = LINK_STATE_UNKNOWN;
573 573 kmem_free(mip->mi_info.mi_unicst_addr, mip->mi_type->mt_addr_length);
574 574 mip->mi_info.mi_unicst_addr = NULL;
575 575
576 576 atomic_dec_32(&mip->mi_type->mt_ref);
577 577 mip->mi_type = NULL;
578 578
579 579 /*
580 580 * Free the primary MAC address.
581 581 */
582 582 mac_fini_macaddr(mip);
583 583
584 584 /*
585 585 * free all rings
586 586 */
587 587 mac_free_rings(mip, MAC_RING_TYPE_RX);
588 588 mac_free_rings(mip, MAC_RING_TYPE_TX);
589 589
590 590 mac_addr_factory_fini(mip);
591 591
592 592 bzero(mip->mi_addr, MAXMACADDRLEN);
593 593 bzero(mip->mi_dstaddr, MAXMACADDRLEN);
594 594 mip->mi_dstaddr_set = B_FALSE;
595 595
596 596 /* and the flows */
597 597 mac_flow_tab_destroy(mip->mi_flow_tab);
598 598 mip->mi_flow_tab = NULL;
599 599
600 600 if (mip->mi_minor > MAC_MAX_MINOR)
601 601 mac_minor_rele(mip->mi_minor);
602 602
603 603 cmn_err(CE_NOTE, "!%s unregistered", mip->mi_name);
604 604
605 605 /*
606 606 * Reset the perim related fields to default values before
607 607 * kmem_cache_free
608 608 */
609 609 i_mac_perim_exit(mip);
610 610 mip->mi_state_flags = 0;
611 611
612 612 mac_unregister_priv_prop(mip);
613 613
614 614 ASSERT(mip->mi_bridge_link == NULL);
615 615 kmem_cache_free(i_mac_impl_cachep, mip);
616 616
617 617 return (0);
618 618 }
619 619
620 620 /* DATA RECEPTION */
621 621
622 622 /*
623 623 * This function is invoked for packets received by the MAC driver in
624 624 * interrupt context. The ring generation number provided by the driver
625 625 * is matched with the ring generation number held in MAC. If they do not
626 626 * match, received packets are considered stale packets coming from an older
627 627 * assignment of the ring. Drop them.
628 628 */
629 629 void
630 630 mac_rx_ring(mac_handle_t mh, mac_ring_handle_t mrh, mblk_t *mp_chain,
631 631 uint64_t mr_gen_num)
632 632 {
633 633 mac_ring_t *mr = (mac_ring_t *)mrh;
634 634
635 635 if ((mr != NULL) && (mr->mr_gen_num != mr_gen_num)) {
636 636 DTRACE_PROBE2(mac__rx__rings__stale__packet, uint64_t,
637 637 mr->mr_gen_num, uint64_t, mr_gen_num);
638 638 freemsgchain(mp_chain);
639 639 return;
640 640 }
641 641 mac_rx(mh, (mac_resource_handle_t)mrh, mp_chain);
642 642 }
643 643
644 644 /*
645 645 * This function is invoked for each packet received by the underlying driver.
646 646 */
647 647 void
648 648 mac_rx(mac_handle_t mh, mac_resource_handle_t mrh, mblk_t *mp_chain)
649 649 {
650 650 mac_impl_t *mip = (mac_impl_t *)mh;
651 651
652 652 /*
653 653 * Check if the link is part of a bridge. If not, then we don't need
654 654 * to take the lock to remain consistent. Make this common case
655 655 * lock-free and tail-call optimized.
656 656 */
657 657 if (mip->mi_bridge_link == NULL) {
658 658 mac_rx_common(mh, mrh, mp_chain);
659 659 } else {
660 660 /*
661 661 * Once we take a reference on the bridge link, the bridge
662 662 * module itself can't unload, so the callback pointers are
663 663 * stable.
664 664 */
665 665 mutex_enter(&mip->mi_bridge_lock);
666 666 if ((mh = mip->mi_bridge_link) != NULL)
667 667 mac_bridge_ref_cb(mh, B_TRUE);
668 668 mutex_exit(&mip->mi_bridge_lock);
669 669 if (mh == NULL) {
670 670 mac_rx_common((mac_handle_t)mip, mrh, mp_chain);
671 671 } else {
672 672 mac_bridge_rx_cb(mh, mrh, mp_chain);
673 673 mac_bridge_ref_cb(mh, B_FALSE);
674 674 }
675 675 }
676 676 }
677 677
678 678 /*
679 679 * Special case function: this allows snooping of packets transmitted and
680 680 * received by TRILL. By design, they go directly into the TRILL module.
681 681 */
682 682 void
683 683 mac_trill_snoop(mac_handle_t mh, mblk_t *mp)
684 684 {
685 685 mac_impl_t *mip = (mac_impl_t *)mh;
686 686
687 687 if (mip->mi_promisc_list != NULL)
688 688 mac_promisc_dispatch(mip, mp, NULL);
689 689 }
690 690
691 691 /*
↓ open down ↓ |
691 lines elided |
↑ open up ↑ |
692 692 * This is the upward reentry point for packets arriving from the bridging
693 693 * module and from mac_rx for links not part of a bridge.
694 694 */
695 695 void
696 696 mac_rx_common(mac_handle_t mh, mac_resource_handle_t mrh, mblk_t *mp_chain)
697 697 {
698 698 mac_impl_t *mip = (mac_impl_t *)mh;
699 699 mac_ring_t *mr = (mac_ring_t *)mrh;
700 700 mac_soft_ring_set_t *mac_srs;
701 701 mblk_t *bp = mp_chain;
702 - boolean_t hw_classified = B_FALSE;
703 702
704 703 /*
705 704 * If there are any promiscuous mode callbacks defined for
706 705 * this MAC, pass them a copy if appropriate.
707 706 */
708 707 if (mip->mi_promisc_list != NULL)
709 708 mac_promisc_dispatch(mip, mp_chain, NULL);
710 709
711 710 if (mr != NULL) {
712 711 /*
713 712 * If the SRS teardown has started, just return. The 'mr'
714 - * continues to be valid until the driver unregisters the mac.
713 + * continues to be valid until the driver unregisters the MAC.
715 714 * Hardware classified packets will not make their way up
716 715 * beyond this point once the teardown has started. The driver
717 716 * is never passed a pointer to a flow entry or SRS or any
718 717 * structure that can be freed much before mac_unregister.
719 718 */
720 719 mutex_enter(&mr->mr_lock);
721 720 if ((mr->mr_state != MR_INUSE) || (mr->mr_flag &
722 721 (MR_INCIPIENT | MR_CONDEMNED | MR_QUIESCE))) {
723 722 mutex_exit(&mr->mr_lock);
724 723 freemsgchain(mp_chain);
725 724 return;
726 725 }
727 - if (mr->mr_classify_type == MAC_HW_CLASSIFIER) {
728 - hw_classified = B_TRUE;
726 +
727 + /*
728 + * The ring is in passthru mode; pass the chain up to
729 + * the pseudo ring.
730 + */
731 + if (mr->mr_classify_type == MAC_PASSTHRU_CLASSIFIER) {
729 732 MR_REFHOLD_LOCKED(mr);
733 + mutex_exit(&mr->mr_lock);
734 + mr->mr_pt_fn(mr->mr_pt_arg1, mr->mr_pt_arg2, mp_chain,
735 + B_FALSE);
736 + MR_REFRELE(mr);
737 + return;
730 738 }
731 - mutex_exit(&mr->mr_lock);
732 739
733 740 /*
741 + * The passthru callback should only be set when in
742 + * MAC_PASSTHRU_CLASSIFIER mode.
743 + */
744 + ASSERT3P(mr->mr_pt_fn, ==, NULL);
745 +
746 + /*
734 747 * We check if an SRS is controlling this ring.
735 748 * If so, we can directly call the srs_lower_proc
736 749 * routine otherwise we need to go through mac_rx_classify
737 750 * to reach the right place.
738 751 */
739 - if (hw_classified) {
752 + if (mr->mr_classify_type == MAC_HW_CLASSIFIER) {
753 + MR_REFHOLD_LOCKED(mr);
754 + mutex_exit(&mr->mr_lock);
755 + ASSERT3P(mr->mr_srs, !=, NULL);
740 756 mac_srs = mr->mr_srs;
757 +
741 758 /*
742 - * This is supposed to be the fast path.
743 - * All packets received though here were steered by
744 - * the hardware classifier, and share the same
745 - * MAC header info.
759 + * This is the fast path. All packets received
760 + * on this ring are hardware classified and
761 + * share the same MAC header info.
746 762 */
747 763 mac_srs->srs_rx.sr_lower_proc(mh,
748 764 (mac_resource_handle_t)mac_srs, mp_chain, B_FALSE);
749 765 MR_REFRELE(mr);
750 766 return;
751 767 }
768 +
769 + mutex_exit(&mr->mr_lock);
752 770 /* We'll fall through to software classification */
753 771 } else {
754 772 flow_entry_t *flent;
755 773 int err;
756 774
757 775 rw_enter(&mip->mi_rw_lock, RW_READER);
758 776 if (mip->mi_single_active_client != NULL) {
759 777 flent = mip->mi_single_active_client->mci_flent_list;
760 778 FLOW_TRY_REFHOLD(flent, err);
761 779 rw_exit(&mip->mi_rw_lock);
762 780 if (err == 0) {
763 781 (flent->fe_cb_fn)(flent->fe_cb_arg1,
764 782 flent->fe_cb_arg2, mp_chain, B_FALSE);
765 783 FLOW_REFRELE(flent);
766 784 return;
767 785 }
768 786 } else {
769 787 rw_exit(&mip->mi_rw_lock);
770 788 }
771 789 }
772 790
773 791 if (!FLOW_TAB_EMPTY(mip->mi_flow_tab)) {
774 792 if ((bp = mac_rx_flow(mh, mrh, bp)) == NULL)
775 793 return;
776 794 }
777 795
778 796 freemsgchain(bp);
779 797 }
780 798
781 799 /* DATA TRANSMISSION */
782 800
783 801 /*
784 802 * A driver's notification to resume transmission, in case of a provider
785 803 * without TX rings.
786 804 */
787 805 void
788 806 mac_tx_update(mac_handle_t mh)
789 807 {
790 808 mac_tx_ring_update(mh, NULL);
791 809 }
792 810
793 811 /*
794 812 * A driver's notification to resume transmission on the specified TX ring.
795 813 */
796 814 void
797 815 mac_tx_ring_update(mac_handle_t mh, mac_ring_handle_t rh)
798 816 {
799 817 i_mac_tx_srs_notify((mac_impl_t *)mh, rh);
800 818 }
801 819
802 820 /* LINK STATE */
803 821 /*
804 822 * Notify the MAC layer about a link state change
805 823 */
806 824 void
807 825 mac_link_update(mac_handle_t mh, link_state_t link)
808 826 {
809 827 mac_impl_t *mip = (mac_impl_t *)mh;
810 828
811 829 /*
812 830 * Save the link state.
813 831 */
814 832 mip->mi_lowlinkstate = link;
815 833
816 834 /*
817 835 * Send a MAC_NOTE_LOWLINK notification. This tells the notification
818 836 * thread to deliver both lower and upper notifications.
819 837 */
820 838 i_mac_notify(mip, MAC_NOTE_LOWLINK);
821 839 }
822 840
823 841 /*
824 842 * Notify the MAC layer about a link state change due to bridging.
825 843 */
826 844 void
827 845 mac_link_redo(mac_handle_t mh, link_state_t link)
828 846 {
829 847 mac_impl_t *mip = (mac_impl_t *)mh;
830 848
831 849 /*
832 850 * Save the link state.
833 851 */
834 852 mip->mi_linkstate = link;
835 853
836 854 /*
837 855 * Send a MAC_NOTE_LINK notification. Only upper notifications are
838 856 * made.
839 857 */
840 858 i_mac_notify(mip, MAC_NOTE_LINK);
841 859 }
842 860
843 861 /* MINOR NODE HANDLING */
844 862
845 863 /*
846 864 * Given a dev_t, return the instance number (PPA) associated with it.
847 865 * Drivers can use this in their getinfo(9e) implementation to lookup
848 866 * the instance number (i.e. PPA) of the device, to use as an index to
849 867 * their own array of soft state structures.
850 868 *
851 869 * Returns -1 on error.
852 870 */
853 871 int
854 872 mac_devt_to_instance(dev_t devt)
855 873 {
856 874 return (dld_devt_to_instance(devt));
857 875 }
858 876
859 877 /*
860 878 * This function returns the first minor number that is available for
861 879 * driver private use. All minor numbers smaller than this are
862 880 * reserved for GLDv3 use.
863 881 */
864 882 minor_t
865 883 mac_private_minor(void)
866 884 {
867 885 return (MAC_PRIVATE_MINOR);
868 886 }
869 887
870 888 /* OTHER CONTROL INFORMATION */
871 889
872 890 /*
873 891 * A driver notified us that its primary MAC address has changed.
874 892 */
875 893 void
876 894 mac_unicst_update(mac_handle_t mh, const uint8_t *addr)
877 895 {
878 896 mac_impl_t *mip = (mac_impl_t *)mh;
879 897
880 898 if (mip->mi_type->mt_addr_length == 0)
881 899 return;
882 900
883 901 i_mac_perim_enter(mip);
884 902
885 903 /*
886 904 * If address changes, freshen the MAC address value and update
887 905 * all MAC clients that share this MAC address.
888 906 */
889 907 if (bcmp(addr, mip->mi_addr, mip->mi_type->mt_addr_length) != 0) {
890 908 mac_freshen_macaddr(mac_find_macaddr(mip, mip->mi_addr),
891 909 (uint8_t *)addr);
892 910 }
893 911
894 912 i_mac_perim_exit(mip);
895 913
896 914 /*
897 915 * Send a MAC_NOTE_UNICST notification.
898 916 */
899 917 i_mac_notify(mip, MAC_NOTE_UNICST);
900 918 }
901 919
902 920 void
903 921 mac_dst_update(mac_handle_t mh, const uint8_t *addr)
904 922 {
905 923 mac_impl_t *mip = (mac_impl_t *)mh;
906 924
907 925 if (mip->mi_type->mt_addr_length == 0)
908 926 return;
909 927
910 928 i_mac_perim_enter(mip);
911 929 bcopy(addr, mip->mi_dstaddr, mip->mi_type->mt_addr_length);
912 930 i_mac_perim_exit(mip);
913 931 i_mac_notify(mip, MAC_NOTE_DEST);
914 932 }
915 933
916 934 /*
917 935 * MAC plugin information changed.
918 936 */
919 937 int
920 938 mac_pdata_update(mac_handle_t mh, void *mac_pdata, size_t dsize)
921 939 {
922 940 mac_impl_t *mip = (mac_impl_t *)mh;
923 941
924 942 /*
925 943 * Verify that the plugin supports MAC plugin data and that the
926 944 * supplied data is valid.
927 945 */
928 946 if (!(mip->mi_type->mt_ops.mtops_ops & MTOPS_PDATA_VERIFY))
929 947 return (EINVAL);
930 948 if (!mip->mi_type->mt_ops.mtops_pdata_verify(mac_pdata, dsize))
931 949 return (EINVAL);
932 950
933 951 if (mip->mi_pdata != NULL)
934 952 kmem_free(mip->mi_pdata, mip->mi_pdata_size);
935 953
936 954 mip->mi_pdata = kmem_alloc(dsize, KM_SLEEP);
937 955 bcopy(mac_pdata, mip->mi_pdata, dsize);
938 956 mip->mi_pdata_size = dsize;
939 957
940 958 /*
941 959 * Since the MAC plugin data is used to construct MAC headers that
942 960 * were cached in fast-path headers, we need to flush fast-path
943 961 * information for links associated with this mac.
944 962 */
945 963 i_mac_notify(mip, MAC_NOTE_FASTPATH_FLUSH);
946 964 return (0);
947 965 }
948 966
949 967 /*
950 968 * Invoked by driver as well as the framework to notify its capability change.
951 969 */
952 970 void
953 971 mac_capab_update(mac_handle_t mh)
954 972 {
955 973 /* Send MAC_NOTE_CAPAB_CHG notification */
956 974 i_mac_notify((mac_impl_t *)mh, MAC_NOTE_CAPAB_CHG);
957 975 }
958 976
959 977 /*
960 978 * Used by normal drivers to update the max sdu size.
961 979 * We need to handle the case of a smaller mi_sdu_multicast
962 980 * since this is called by mac_set_mtu() even for drivers that
963 981 * have differing unicast and multicast mtu and we don't want to
964 982 * increase the multicast mtu by accident in that case.
965 983 */
966 984 int
967 985 mac_maxsdu_update(mac_handle_t mh, uint_t sdu_max)
968 986 {
969 987 mac_impl_t *mip = (mac_impl_t *)mh;
970 988
971 989 if (sdu_max == 0 || sdu_max < mip->mi_sdu_min)
972 990 return (EINVAL);
973 991 mip->mi_sdu_max = sdu_max;
974 992 if (mip->mi_sdu_multicast > mip->mi_sdu_max)
975 993 mip->mi_sdu_multicast = mip->mi_sdu_max;
976 994
977 995 /* Send a MAC_NOTE_SDU_SIZE notification. */
978 996 i_mac_notify(mip, MAC_NOTE_SDU_SIZE);
979 997 return (0);
980 998 }
981 999
982 1000 /*
983 1001 * Version of the above function that is used by drivers that have a different
984 1002 * max sdu size for multicast/broadcast vs. unicast.
985 1003 */
986 1004 int
987 1005 mac_maxsdu_update2(mac_handle_t mh, uint_t sdu_max, uint_t sdu_multicast)
988 1006 {
989 1007 mac_impl_t *mip = (mac_impl_t *)mh;
990 1008
991 1009 if (sdu_max == 0 || sdu_max < mip->mi_sdu_min)
992 1010 return (EINVAL);
993 1011 if (sdu_multicast == 0)
994 1012 sdu_multicast = sdu_max;
995 1013 if (sdu_multicast > sdu_max || sdu_multicast < mip->mi_sdu_min)
996 1014 return (EINVAL);
997 1015 mip->mi_sdu_max = sdu_max;
998 1016 mip->mi_sdu_multicast = sdu_multicast;
999 1017
1000 1018 /* Send a MAC_NOTE_SDU_SIZE notification. */
1001 1019 i_mac_notify(mip, MAC_NOTE_SDU_SIZE);
1002 1020 return (0);
1003 1021 }
1004 1022
1005 1023 static void
1006 1024 mac_ring_intr_retarget(mac_group_t *group, mac_ring_t *ring)
1007 1025 {
1008 1026 mac_client_impl_t *mcip;
1009 1027 flow_entry_t *flent;
1010 1028 mac_soft_ring_set_t *mac_rx_srs;
1011 1029 mac_cpus_t *srs_cpu;
1012 1030 int i;
1013 1031
1014 1032 if (((mcip = MAC_GROUP_ONLY_CLIENT(group)) != NULL) &&
1015 1033 (!ring->mr_info.mri_intr.mi_ddi_shared)) {
1016 1034 /* interrupt can be re-targeted */
1017 1035 ASSERT(group->mrg_state == MAC_GROUP_STATE_RESERVED);
1018 1036 flent = mcip->mci_flent;
1019 1037 if (ring->mr_type == MAC_RING_TYPE_RX) {
1020 1038 for (i = 0; i < flent->fe_rx_srs_cnt; i++) {
1021 1039 mac_rx_srs = flent->fe_rx_srs[i];
1022 1040 if (mac_rx_srs->srs_ring != ring)
1023 1041 continue;
1024 1042 srs_cpu = &mac_rx_srs->srs_cpu;
1025 1043 mutex_enter(&cpu_lock);
1026 1044 mac_rx_srs_retarget_intr(mac_rx_srs,
1027 1045 srs_cpu->mc_rx_intr_cpu);
1028 1046 mutex_exit(&cpu_lock);
1029 1047 break;
1030 1048 }
1031 1049 } else {
1032 1050 if (flent->fe_tx_srs != NULL) {
1033 1051 mutex_enter(&cpu_lock);
1034 1052 mac_tx_srs_retarget_intr(
1035 1053 flent->fe_tx_srs);
1036 1054 mutex_exit(&cpu_lock);
1037 1055 }
1038 1056 }
1039 1057 }
1040 1058 }
1041 1059
1042 1060 /*
1043 1061 * Clients like aggr create pseudo rings (mac_ring_t) and expose them to
1044 1062 * their clients. There is a 1-1 mapping pseudo ring and the hardware
1045 1063 * ring. ddi interrupt handles are exported from the hardware ring to
1046 1064 * the pseudo ring. Thus when the interrupt handle changes, clients of
1047 1065 * aggr that are using the handle need to use the new handle and
1048 1066 * re-target their interrupts.
1049 1067 */
1050 1068 static void
1051 1069 mac_pseudo_ring_intr_retarget(mac_impl_t *mip, mac_ring_t *ring,
1052 1070 ddi_intr_handle_t ddh)
1053 1071 {
1054 1072 mac_ring_t *pring;
1055 1073 mac_group_t *pgroup;
1056 1074 mac_impl_t *pmip;
1057 1075 char macname[MAXNAMELEN];
1058 1076 mac_perim_handle_t p_mph;
1059 1077 uint64_t saved_gen_num;
1060 1078
1061 1079 again:
1062 1080 pring = (mac_ring_t *)ring->mr_prh;
1063 1081 pgroup = (mac_group_t *)pring->mr_gh;
1064 1082 pmip = (mac_impl_t *)pgroup->mrg_mh;
1065 1083 saved_gen_num = ring->mr_gen_num;
1066 1084 (void) strlcpy(macname, pmip->mi_name, MAXNAMELEN);
1067 1085 /*
1068 1086 * We need to enter aggr's perimeter. The locking hierarchy
1069 1087 * dictates that aggr's perimeter should be entered first
1070 1088 * and then the port's perimeter. So drop the port's
1071 1089 * perimeter, enter aggr's and then re-enter port's
1072 1090 * perimeter.
1073 1091 */
1074 1092 i_mac_perim_exit(mip);
1075 1093 /*
1076 1094 * While we know pmip is the aggr's mip, there is a
1077 1095 * possibility that aggr could have unregistered by
1078 1096 * the time we exit port's perimeter (mip) and
1079 1097 * enter aggr's perimeter (pmip). To avoid that
1080 1098 * scenario, enter aggr's perimeter using its name.
1081 1099 */
1082 1100 if (mac_perim_enter_by_macname(macname, &p_mph) != 0)
1083 1101 return;
1084 1102 i_mac_perim_enter(mip);
1085 1103 /*
1086 1104 * Check if the ring got assigned to another aggregation before
1087 1105 * be could enter aggr's and the port's perimeter. When a ring
1088 1106 * gets deleted from an aggregation, it calls mac_stop_ring()
1089 1107 * which increments the generation number. So checking
1090 1108 * generation number will be enough.
1091 1109 */
1092 1110 if (ring->mr_gen_num != saved_gen_num && ring->mr_prh != NULL) {
1093 1111 i_mac_perim_exit(mip);
1094 1112 mac_perim_exit(p_mph);
1095 1113 i_mac_perim_enter(mip);
1096 1114 goto again;
1097 1115 }
1098 1116
1099 1117 /* Check if pseudo ring is still present */
1100 1118 if (ring->mr_prh != NULL) {
1101 1119 pring->mr_info.mri_intr.mi_ddi_handle = ddh;
1102 1120 pring->mr_info.mri_intr.mi_ddi_shared =
1103 1121 ring->mr_info.mri_intr.mi_ddi_shared;
1104 1122 if (ddh != NULL)
1105 1123 mac_ring_intr_retarget(pgroup, pring);
1106 1124 }
1107 1125 i_mac_perim_exit(mip);
1108 1126 mac_perim_exit(p_mph);
1109 1127 }
1110 1128 /*
1111 1129 * API called by driver to provide new interrupt handle for TX/RX rings.
1112 1130 * This usually happens when IRM (Interrupt Resource Manangement)
1113 1131 * framework either gives the driver more MSI-x interrupts or takes
1114 1132 * away MSI-x interrupts from the driver.
1115 1133 */
1116 1134 void
1117 1135 mac_ring_intr_set(mac_ring_handle_t mrh, ddi_intr_handle_t ddh)
1118 1136 {
1119 1137 mac_ring_t *ring = (mac_ring_t *)mrh;
1120 1138 mac_group_t *group = (mac_group_t *)ring->mr_gh;
1121 1139 mac_impl_t *mip = (mac_impl_t *)group->mrg_mh;
1122 1140
1123 1141 i_mac_perim_enter(mip);
1124 1142 ring->mr_info.mri_intr.mi_ddi_handle = ddh;
1125 1143 if (ddh == NULL) {
1126 1144 /* Interrupts being reset */
1127 1145 ring->mr_info.mri_intr.mi_ddi_shared = B_FALSE;
1128 1146 if (ring->mr_prh != NULL) {
1129 1147 mac_pseudo_ring_intr_retarget(mip, ring, ddh);
1130 1148 return;
1131 1149 }
1132 1150 } else {
1133 1151 /* New interrupt handle */
1134 1152 mac_compare_ddi_handle(mip->mi_rx_groups,
1135 1153 mip->mi_rx_group_count, ring);
1136 1154 if (!ring->mr_info.mri_intr.mi_ddi_shared) {
1137 1155 mac_compare_ddi_handle(mip->mi_tx_groups,
1138 1156 mip->mi_tx_group_count, ring);
1139 1157 }
1140 1158 if (ring->mr_prh != NULL) {
1141 1159 mac_pseudo_ring_intr_retarget(mip, ring, ddh);
1142 1160 return;
1143 1161 } else {
1144 1162 mac_ring_intr_retarget(group, ring);
1145 1163 }
1146 1164 }
1147 1165 i_mac_perim_exit(mip);
1148 1166 }
1149 1167
1150 1168 /* PRIVATE FUNCTIONS, FOR INTERNAL USE ONLY */
1151 1169
1152 1170 /*
1153 1171 * Updates the mac_impl structure with the current state of the link
1154 1172 */
1155 1173 static void
1156 1174 i_mac_log_link_state(mac_impl_t *mip)
1157 1175 {
1158 1176 /*
1159 1177 * If no change, then it is not interesting.
1160 1178 */
1161 1179 if (mip->mi_lastlowlinkstate == mip->mi_lowlinkstate)
1162 1180 return;
1163 1181
1164 1182 switch (mip->mi_lowlinkstate) {
1165 1183 case LINK_STATE_UP:
1166 1184 if (mip->mi_type->mt_ops.mtops_ops & MTOPS_LINK_DETAILS) {
1167 1185 char det[200];
1168 1186
1169 1187 mip->mi_type->mt_ops.mtops_link_details(det,
1170 1188 sizeof (det), (mac_handle_t)mip, mip->mi_pdata);
1171 1189
1172 1190 cmn_err(CE_NOTE, "!%s link up, %s", mip->mi_name, det);
1173 1191 } else {
1174 1192 cmn_err(CE_NOTE, "!%s link up", mip->mi_name);
1175 1193 }
1176 1194 break;
1177 1195
1178 1196 case LINK_STATE_DOWN:
1179 1197 /*
1180 1198 * Only transitions from UP to DOWN are interesting
1181 1199 */
1182 1200 if (mip->mi_lastlowlinkstate != LINK_STATE_UNKNOWN)
1183 1201 cmn_err(CE_NOTE, "!%s link down", mip->mi_name);
1184 1202 break;
1185 1203
1186 1204 case LINK_STATE_UNKNOWN:
1187 1205 /*
1188 1206 * This case is normally not interesting.
1189 1207 */
1190 1208 break;
1191 1209 }
1192 1210 mip->mi_lastlowlinkstate = mip->mi_lowlinkstate;
1193 1211 }
1194 1212
1195 1213 /*
1196 1214 * Main routine for the callbacks notifications thread
1197 1215 */
1198 1216 static void
1199 1217 i_mac_notify_thread(void *arg)
1200 1218 {
1201 1219 mac_impl_t *mip = arg;
1202 1220 callb_cpr_t cprinfo;
1203 1221 mac_cb_t *mcb;
1204 1222 mac_cb_info_t *mcbi;
1205 1223 mac_notify_cb_t *mncb;
1206 1224
1207 1225 mcbi = &mip->mi_notify_cb_info;
1208 1226 CALLB_CPR_INIT(&cprinfo, mcbi->mcbi_lockp, callb_generic_cpr,
1209 1227 "i_mac_notify_thread");
1210 1228
1211 1229 mutex_enter(mcbi->mcbi_lockp);
1212 1230
1213 1231 for (;;) {
1214 1232 uint32_t bits;
1215 1233 uint32_t type;
1216 1234
1217 1235 bits = mip->mi_notify_bits;
1218 1236 if (bits == 0) {
1219 1237 CALLB_CPR_SAFE_BEGIN(&cprinfo);
1220 1238 cv_wait(&mcbi->mcbi_cv, mcbi->mcbi_lockp);
1221 1239 CALLB_CPR_SAFE_END(&cprinfo, mcbi->mcbi_lockp);
1222 1240 continue;
1223 1241 }
1224 1242 mip->mi_notify_bits = 0;
1225 1243 if ((bits & (1 << MAC_NNOTE)) != 0) {
1226 1244 /* request to quit */
1227 1245 ASSERT(mip->mi_state_flags & MIS_DISABLED);
1228 1246 break;
1229 1247 }
1230 1248
1231 1249 mutex_exit(mcbi->mcbi_lockp);
1232 1250
1233 1251 /*
1234 1252 * Log link changes on the actual link, but then do reports on
1235 1253 * synthetic state (if part of a bridge).
1236 1254 */
1237 1255 if ((bits & (1 << MAC_NOTE_LOWLINK)) != 0) {
1238 1256 link_state_t newstate;
1239 1257 mac_handle_t mh;
1240 1258
1241 1259 i_mac_log_link_state(mip);
1242 1260 newstate = mip->mi_lowlinkstate;
1243 1261 if (mip->mi_bridge_link != NULL) {
1244 1262 mutex_enter(&mip->mi_bridge_lock);
1245 1263 if ((mh = mip->mi_bridge_link) != NULL) {
1246 1264 newstate = mac_bridge_ls_cb(mh,
1247 1265 newstate);
1248 1266 }
1249 1267 mutex_exit(&mip->mi_bridge_lock);
1250 1268 }
1251 1269 if (newstate != mip->mi_linkstate) {
1252 1270 mip->mi_linkstate = newstate;
1253 1271 bits |= 1 << MAC_NOTE_LINK;
1254 1272 }
1255 1273 }
1256 1274
1257 1275 /*
1258 1276 * Do notification callbacks for each notification type.
1259 1277 */
1260 1278 for (type = 0; type < MAC_NNOTE; type++) {
1261 1279 if ((bits & (1 << type)) == 0) {
1262 1280 continue;
1263 1281 }
1264 1282
1265 1283 if (mac_notify_cb_list[type] != NULL)
1266 1284 (*mac_notify_cb_list[type])(mip);
1267 1285
1268 1286 /*
1269 1287 * Walk the list of notifications.
1270 1288 */
1271 1289 MAC_CALLBACK_WALKER_INC(&mip->mi_notify_cb_info);
1272 1290 for (mcb = mip->mi_notify_cb_list; mcb != NULL;
1273 1291 mcb = mcb->mcb_nextp) {
1274 1292 mncb = (mac_notify_cb_t *)mcb->mcb_objp;
1275 1293 mncb->mncb_fn(mncb->mncb_arg, type);
1276 1294 }
1277 1295 MAC_CALLBACK_WALKER_DCR(&mip->mi_notify_cb_info,
1278 1296 &mip->mi_notify_cb_list);
1279 1297 }
1280 1298
1281 1299 mutex_enter(mcbi->mcbi_lockp);
1282 1300 }
1283 1301
1284 1302 mip->mi_state_flags |= MIS_NOTIFY_DONE;
1285 1303 cv_broadcast(&mcbi->mcbi_cv);
1286 1304
1287 1305 /* CALLB_CPR_EXIT drops the lock */
1288 1306 CALLB_CPR_EXIT(&cprinfo);
1289 1307 thread_exit();
1290 1308 }
1291 1309
1292 1310 /*
1293 1311 * Signal the i_mac_notify_thread asking it to quit.
1294 1312 * Then wait till it is done.
1295 1313 */
1296 1314 void
1297 1315 i_mac_notify_exit(mac_impl_t *mip)
1298 1316 {
1299 1317 mac_cb_info_t *mcbi;
1300 1318
1301 1319 mcbi = &mip->mi_notify_cb_info;
1302 1320
1303 1321 mutex_enter(mcbi->mcbi_lockp);
1304 1322 mip->mi_notify_bits = (1 << MAC_NNOTE);
1305 1323 cv_broadcast(&mcbi->mcbi_cv);
1306 1324
1307 1325
1308 1326 while ((mip->mi_notify_thread != NULL) &&
1309 1327 !(mip->mi_state_flags & MIS_NOTIFY_DONE)) {
1310 1328 cv_wait(&mcbi->mcbi_cv, mcbi->mcbi_lockp);
1311 1329 }
1312 1330
1313 1331 /* Necessary clean up before doing kmem_cache_free */
1314 1332 mip->mi_state_flags &= ~MIS_NOTIFY_DONE;
1315 1333 mip->mi_notify_bits = 0;
1316 1334 mip->mi_notify_thread = NULL;
1317 1335 mutex_exit(mcbi->mcbi_lockp);
1318 1336 }
1319 1337
1320 1338 /*
1321 1339 * Entry point invoked by drivers to dynamically add a ring to an
1322 1340 * existing group.
1323 1341 */
1324 1342 int
1325 1343 mac_group_add_ring(mac_group_handle_t gh, int index)
1326 1344 {
1327 1345 mac_group_t *group = (mac_group_t *)gh;
1328 1346 mac_impl_t *mip = (mac_impl_t *)group->mrg_mh;
1329 1347 int ret;
1330 1348
1331 1349 i_mac_perim_enter(mip);
1332 1350 ret = i_mac_group_add_ring(group, NULL, index);
1333 1351 i_mac_perim_exit(mip);
1334 1352 return (ret);
1335 1353 }
1336 1354
1337 1355 /*
1338 1356 * Entry point invoked by drivers to dynamically remove a ring
1339 1357 * from an existing group. The specified ring handle must no longer
1340 1358 * be used by the driver after a call to this function.
1341 1359 */
1342 1360 void
1343 1361 mac_group_rem_ring(mac_group_handle_t gh, mac_ring_handle_t rh)
1344 1362 {
1345 1363 mac_group_t *group = (mac_group_t *)gh;
1346 1364 mac_impl_t *mip = (mac_impl_t *)group->mrg_mh;
1347 1365
1348 1366 i_mac_perim_enter(mip);
1349 1367 i_mac_group_rem_ring(group, (mac_ring_t *)rh, B_TRUE);
1350 1368 i_mac_perim_exit(mip);
1351 1369 }
1352 1370
1353 1371 /*
1354 1372 * mac_prop_info_*() callbacks called from the driver's prefix_propinfo()
1355 1373 * entry points.
1356 1374 */
1357 1375
1358 1376 void
1359 1377 mac_prop_info_set_default_uint8(mac_prop_info_handle_t ph, uint8_t val)
1360 1378 {
1361 1379 mac_prop_info_state_t *pr = (mac_prop_info_state_t *)ph;
1362 1380
1363 1381 /* nothing to do if the caller doesn't want the default value */
1364 1382 if (pr->pr_default == NULL)
1365 1383 return;
1366 1384
1367 1385 ASSERT(pr->pr_default_size >= sizeof (uint8_t));
1368 1386
1369 1387 *(uint8_t *)(pr->pr_default) = val;
1370 1388 pr->pr_flags |= MAC_PROP_INFO_DEFAULT;
1371 1389 }
1372 1390
1373 1391 void
1374 1392 mac_prop_info_set_default_uint64(mac_prop_info_handle_t ph, uint64_t val)
1375 1393 {
1376 1394 mac_prop_info_state_t *pr = (mac_prop_info_state_t *)ph;
1377 1395
1378 1396 /* nothing to do if the caller doesn't want the default value */
1379 1397 if (pr->pr_default == NULL)
1380 1398 return;
1381 1399
1382 1400 ASSERT(pr->pr_default_size >= sizeof (uint64_t));
1383 1401
1384 1402 bcopy(&val, pr->pr_default, sizeof (val));
1385 1403
1386 1404 pr->pr_flags |= MAC_PROP_INFO_DEFAULT;
1387 1405 }
1388 1406
1389 1407 void
1390 1408 mac_prop_info_set_default_uint32(mac_prop_info_handle_t ph, uint32_t val)
1391 1409 {
1392 1410 mac_prop_info_state_t *pr = (mac_prop_info_state_t *)ph;
1393 1411
1394 1412 /* nothing to do if the caller doesn't want the default value */
1395 1413 if (pr->pr_default == NULL)
1396 1414 return;
1397 1415
1398 1416 ASSERT(pr->pr_default_size >= sizeof (uint32_t));
1399 1417
1400 1418 bcopy(&val, pr->pr_default, sizeof (val));
1401 1419
1402 1420 pr->pr_flags |= MAC_PROP_INFO_DEFAULT;
1403 1421 }
1404 1422
1405 1423 void
1406 1424 mac_prop_info_set_default_str(mac_prop_info_handle_t ph, const char *str)
1407 1425 {
1408 1426 mac_prop_info_state_t *pr = (mac_prop_info_state_t *)ph;
1409 1427
1410 1428 /* nothing to do if the caller doesn't want the default value */
1411 1429 if (pr->pr_default == NULL)
1412 1430 return;
1413 1431
1414 1432 if (strlen(str) >= pr->pr_default_size)
1415 1433 pr->pr_errno = ENOBUFS;
1416 1434 else
1417 1435 (void) strlcpy(pr->pr_default, str, pr->pr_default_size);
1418 1436 pr->pr_flags |= MAC_PROP_INFO_DEFAULT;
1419 1437 }
1420 1438
1421 1439 void
1422 1440 mac_prop_info_set_default_link_flowctrl(mac_prop_info_handle_t ph,
1423 1441 link_flowctrl_t val)
1424 1442 {
1425 1443 mac_prop_info_state_t *pr = (mac_prop_info_state_t *)ph;
1426 1444
1427 1445 /* nothing to do if the caller doesn't want the default value */
1428 1446 if (pr->pr_default == NULL)
1429 1447 return;
1430 1448
1431 1449 ASSERT(pr->pr_default_size >= sizeof (link_flowctrl_t));
1432 1450
1433 1451 bcopy(&val, pr->pr_default, sizeof (val));
1434 1452
1435 1453 pr->pr_flags |= MAC_PROP_INFO_DEFAULT;
1436 1454 }
1437 1455
1438 1456 void
1439 1457 mac_prop_info_set_range_uint32(mac_prop_info_handle_t ph, uint32_t min,
1440 1458 uint32_t max)
1441 1459 {
1442 1460 mac_prop_info_state_t *pr = (mac_prop_info_state_t *)ph;
1443 1461 mac_propval_range_t *range = pr->pr_range;
1444 1462 mac_propval_uint32_range_t *range32;
1445 1463
1446 1464 /* nothing to do if the caller doesn't want the range info */
1447 1465 if (range == NULL)
1448 1466 return;
1449 1467
1450 1468 if (pr->pr_range_cur_count++ == 0) {
1451 1469 /* first range */
1452 1470 pr->pr_flags |= MAC_PROP_INFO_RANGE;
1453 1471 range->mpr_type = MAC_PROPVAL_UINT32;
1454 1472 } else {
1455 1473 /* all ranges of a property should be of the same type */
1456 1474 ASSERT(range->mpr_type == MAC_PROPVAL_UINT32);
1457 1475 if (pr->pr_range_cur_count > range->mpr_count) {
1458 1476 pr->pr_errno = ENOSPC;
1459 1477 return;
1460 1478 }
1461 1479 }
1462 1480
1463 1481 range32 = range->mpr_range_uint32;
1464 1482 range32[pr->pr_range_cur_count - 1].mpur_min = min;
1465 1483 range32[pr->pr_range_cur_count - 1].mpur_max = max;
1466 1484 }
1467 1485
1468 1486 void
1469 1487 mac_prop_info_set_perm(mac_prop_info_handle_t ph, uint8_t perm)
1470 1488 {
1471 1489 mac_prop_info_state_t *pr = (mac_prop_info_state_t *)ph;
1472 1490
1473 1491 pr->pr_perm = perm;
1474 1492 pr->pr_flags |= MAC_PROP_INFO_PERM;
1475 1493 }
1476 1494
1477 1495 void mac_hcksum_get(mblk_t *mp, uint32_t *start, uint32_t *stuff,
1478 1496 uint32_t *end, uint32_t *value, uint32_t *flags_ptr)
1479 1497 {
1480 1498 uint32_t flags;
1481 1499
1482 1500 ASSERT(DB_TYPE(mp) == M_DATA);
1483 1501
1484 1502 flags = DB_CKSUMFLAGS(mp) & HCK_FLAGS;
1485 1503 if ((flags & (HCK_PARTIALCKSUM | HCK_FULLCKSUM)) != 0) {
1486 1504 if (value != NULL)
1487 1505 *value = (uint32_t)DB_CKSUM16(mp);
1488 1506 if ((flags & HCK_PARTIALCKSUM) != 0) {
1489 1507 if (start != NULL)
1490 1508 *start = (uint32_t)DB_CKSUMSTART(mp);
1491 1509 if (stuff != NULL)
1492 1510 *stuff = (uint32_t)DB_CKSUMSTUFF(mp);
1493 1511 if (end != NULL)
1494 1512 *end = (uint32_t)DB_CKSUMEND(mp);
1495 1513 }
1496 1514 }
1497 1515
1498 1516 if (flags_ptr != NULL)
1499 1517 *flags_ptr = flags;
1500 1518 }
1501 1519
1502 1520 void mac_hcksum_set(mblk_t *mp, uint32_t start, uint32_t stuff,
1503 1521 uint32_t end, uint32_t value, uint32_t flags)
1504 1522 {
1505 1523 ASSERT(DB_TYPE(mp) == M_DATA);
1506 1524
1507 1525 DB_CKSUMSTART(mp) = (intptr_t)start;
1508 1526 DB_CKSUMSTUFF(mp) = (intptr_t)stuff;
1509 1527 DB_CKSUMEND(mp) = (intptr_t)end;
1510 1528 DB_CKSUMFLAGS(mp) = (uint16_t)flags;
1511 1529 DB_CKSUM16(mp) = (uint16_t)value;
1512 1530 }
1513 1531
1514 1532 void
1515 1533 mac_lso_get(mblk_t *mp, uint32_t *mss, uint32_t *flags)
1516 1534 {
1517 1535 ASSERT(DB_TYPE(mp) == M_DATA);
1518 1536
1519 1537 if (flags != NULL) {
1520 1538 *flags = DB_CKSUMFLAGS(mp) & HW_LSO;
1521 1539 if ((*flags != 0) && (mss != NULL))
1522 1540 *mss = (uint32_t)DB_LSOMSS(mp);
1523 1541 }
1524 1542 }
1525 1543
1526 1544 void
1527 1545 mac_transceiver_info_set_present(mac_transceiver_info_t *infop,
1528 1546 boolean_t present)
1529 1547 {
1530 1548 infop->mti_present = present;
1531 1549 }
1532 1550
1533 1551 void
1534 1552 mac_transceiver_info_set_usable(mac_transceiver_info_t *infop,
1535 1553 boolean_t usable)
1536 1554 {
1537 1555 infop->mti_usable = usable;
1538 1556 }
↓ open down ↓ |
777 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX