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.c
+++ new/usr/src/uts/common/io/mac/mac.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) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
24 24 * Copyright 2019 Joyent, Inc.
25 25 * Copyright 2015 Garrett D'Amore <garrett@damore.org>
26 26 */
27 27
28 28 /*
29 29 * MAC Services Module
30 30 *
31 31 * The GLDv3 framework locking - The MAC layer
32 32 * --------------------------------------------
33 33 *
34 34 * The MAC layer is central to the GLD framework and can provide the locking
35 35 * framework needed for itself and for the use of MAC clients. MAC end points
36 36 * are fairly disjoint and don't share a lot of state. So a coarse grained
37 37 * multi-threading scheme is to single thread all create/modify/delete or set
38 38 * type of control operations on a per mac end point while allowing data threads
39 39 * concurrently.
40 40 *
41 41 * Control operations (set) that modify a mac end point are always serialized on
42 42 * a per mac end point basis, We have at most 1 such thread per mac end point
43 43 * at a time.
44 44 *
45 45 * All other operations that are not serialized are essentially multi-threaded.
46 46 * For example a control operation (get) like getting statistics which may not
47 47 * care about reading values atomically or data threads sending or receiving
48 48 * data. Mostly these type of operations don't modify the control state. Any
49 49 * state these operations care about are protected using traditional locks.
50 50 *
51 51 * The perimeter only serializes serial operations. It does not imply there
52 52 * aren't any other concurrent operations. However a serialized operation may
53 53 * sometimes need to make sure it is the only thread. In this case it needs
54 54 * to use reference counting mechanisms to cv_wait until any current data
55 55 * threads are done.
56 56 *
57 57 * The mac layer itself does not hold any locks across a call to another layer.
58 58 * The perimeter is however held across a down call to the driver to make the
59 59 * whole control operation atomic with respect to other control operations.
60 60 * Also the data path and get type control operations may proceed concurrently.
61 61 * These operations synchronize with the single serial operation on a given mac
62 62 * end point using regular locks. The perimeter ensures that conflicting
63 63 * operations like say a mac_multicast_add and a mac_multicast_remove on the
64 64 * same mac end point don't interfere with each other and also ensures that the
65 65 * changes in the mac layer and the call to the underlying driver to say add a
66 66 * multicast address are done atomically without interference from a thread
67 67 * trying to delete the same address.
68 68 *
69 69 * For example, consider
70 70 * mac_multicst_add()
71 71 * {
72 72 * mac_perimeter_enter(); serialize all control operations
73 73 *
74 74 * grab list lock protect against access by data threads
75 75 * add to list
76 76 * drop list lock
77 77 *
78 78 * call driver's mi_multicst
79 79 *
80 80 * mac_perimeter_exit();
81 81 * }
82 82 *
83 83 * To lessen the number of serialization locks and simplify the lock hierarchy,
84 84 * we serialize all the control operations on a per mac end point by using a
85 85 * single serialization lock called the perimeter. We allow recursive entry into
86 86 * the perimeter to facilitate use of this mechanism by both the mac client and
87 87 * the MAC layer itself.
88 88 *
89 89 * MAC client means an entity that does an operation on a mac handle
90 90 * obtained from a mac_open/mac_client_open. Similarly MAC driver means
91 91 * an entity that does an operation on a mac handle obtained from a
92 92 * mac_register. An entity could be both client and driver but on different
93 93 * handles eg. aggr. and should only make the corresponding mac interface calls
94 94 * i.e. mac driver interface or mac client interface as appropriate for that
95 95 * mac handle.
96 96 *
97 97 * General rules.
98 98 * -------------
99 99 *
100 100 * R1. The lock order of upcall threads is natually opposite to downcall
101 101 * threads. Hence upcalls must not hold any locks across layers for fear of
102 102 * recursive lock enter and lock order violation. This applies to all layers.
103 103 *
104 104 * R2. The perimeter is just another lock. Since it is held in the down
105 105 * direction, acquiring the perimeter in an upcall is prohibited as it would
106 106 * cause a deadlock. This applies to all layers.
107 107 *
108 108 * Note that upcalls that need to grab the mac perimeter (for example
109 109 * mac_notify upcalls) can still achieve that by posting the request to a
110 110 * thread, which can then grab all the required perimeters and locks in the
111 111 * right global order. Note that in the above example the mac layer iself
112 112 * won't grab the mac perimeter in the mac_notify upcall, instead the upcall
113 113 * to the client must do that. Please see the aggr code for an example.
114 114 *
115 115 * MAC client rules
116 116 * ----------------
117 117 *
118 118 * R3. A MAC client may use the MAC provided perimeter facility to serialize
119 119 * control operations on a per mac end point. It does this by by acquring
120 120 * and holding the perimeter across a sequence of calls to the mac layer.
121 121 * This ensures atomicity across the entire block of mac calls. In this
122 122 * model the MAC client must not hold any client locks across the calls to
123 123 * the mac layer. This model is the preferred solution.
124 124 *
125 125 * R4. However if a MAC client has a lot of global state across all mac end
126 126 * points the per mac end point serialization may not be sufficient. In this
127 127 * case the client may choose to use global locks or use its own serialization.
128 128 * To avoid deadlocks, these client layer locks held across the mac calls
129 129 * in the control path must never be acquired by the data path for the reason
130 130 * mentioned below.
131 131 *
132 132 * (Assume that a control operation that holds a client lock blocks in the
133 133 * mac layer waiting for upcall reference counts to drop to zero. If an upcall
134 134 * data thread that holds this reference count, tries to acquire the same
135 135 * client lock subsequently it will deadlock).
136 136 *
137 137 * A MAC client may follow either the R3 model or the R4 model, but can't
138 138 * mix both. In the former, the hierarchy is Perim -> client locks, but in
139 139 * the latter it is client locks -> Perim.
140 140 *
141 141 * R5. MAC clients must make MAC calls (excluding data calls) in a cv_wait'able
142 142 * context since they may block while trying to acquire the perimeter.
143 143 * In addition some calls may block waiting for upcall refcnts to come down to
144 144 * zero.
145 145 *
146 146 * R6. MAC clients must make sure that they are single threaded and all threads
147 147 * from the top (in particular data threads) have finished before calling
148 148 * mac_client_close. The MAC framework does not track the number of client
149 149 * threads using the mac client handle. Also mac clients must make sure
150 150 * they have undone all the control operations before calling mac_client_close.
151 151 * For example mac_unicast_remove/mac_multicast_remove to undo the corresponding
152 152 * mac_unicast_add/mac_multicast_add.
153 153 *
154 154 * MAC framework rules
155 155 * -------------------
156 156 *
157 157 * R7. The mac layer itself must not hold any mac layer locks (except the mac
158 158 * perimeter) across a call to any other layer from the mac layer. The call to
159 159 * any other layer could be via mi_* entry points, classifier entry points into
160 160 * the driver or via upcall pointers into layers above. The mac perimeter may
161 161 * be acquired or held only in the down direction, for e.g. when calling into
162 162 * a mi_* driver enty point to provide atomicity of the operation.
163 163 *
164 164 * R8. Since it is not guaranteed (see R14) that drivers won't hold locks across
165 165 * mac driver interfaces, the MAC layer must provide a cut out for control
166 166 * interfaces like upcall notifications and start them in a separate thread.
167 167 *
168 168 * R9. Note that locking order also implies a plumbing order. For example
169 169 * VNICs are allowed to be created over aggrs, but not vice-versa. An attempt
170 170 * to plumb in any other order must be failed at mac_open time, otherwise it
171 171 * could lead to deadlocks due to inverse locking order.
172 172 *
173 173 * R10. MAC driver interfaces must not block since the driver could call them
174 174 * in interrupt context.
175 175 *
176 176 * R11. Walkers must preferably not hold any locks while calling walker
177 177 * callbacks. Instead these can operate on reference counts. In simple
178 178 * callbacks it may be ok to hold a lock and call the callbacks, but this is
179 179 * harder to maintain in the general case of arbitrary callbacks.
180 180 *
181 181 * R12. The MAC layer must protect upcall notification callbacks using reference
182 182 * counts rather than holding locks across the callbacks.
183 183 *
184 184 * R13. Given the variety of drivers, it is preferable if the MAC layer can make
185 185 * sure that any pointers (such as mac ring pointers) it passes to the driver
186 186 * remain valid until mac unregister time. Currently the mac layer achieves
187 187 * this by using generation numbers for rings and freeing the mac rings only
188 188 * at unregister time. The MAC layer must provide a layer of indirection and
189 189 * must not expose underlying driver rings or driver data structures/pointers
190 190 * directly to MAC clients.
191 191 *
192 192 * MAC driver rules
193 193 * ----------------
194 194 *
195 195 * R14. It would be preferable if MAC drivers don't hold any locks across any
196 196 * mac call. However at a minimum they must not hold any locks across data
197 197 * upcalls. They must also make sure that all references to mac data structures
198 198 * are cleaned up and that it is single threaded at mac_unregister time.
199 199 *
200 200 * R15. MAC driver interfaces don't block and so the action may be done
201 201 * asynchronously in a separate thread as for example handling notifications.
202 202 * The driver must not assume that the action is complete when the call
203 203 * returns.
204 204 *
205 205 * R16. Drivers must maintain a generation number per Rx ring, and pass it
206 206 * back to mac_rx_ring(); They are expected to increment the generation
207 207 * number whenever the ring's stop routine is invoked.
208 208 * See comments in mac_rx_ring();
209 209 *
210 210 * R17 Similarly mi_stop is another synchronization point and the driver must
211 211 * ensure that all upcalls are done and there won't be any future upcall
212 212 * before returning from mi_stop.
213 213 *
214 214 * R18. The driver may assume that all set/modify control operations via
215 215 * the mi_* entry points are single threaded on a per mac end point.
216 216 *
217 217 * Lock and Perimeter hierarchy scenarios
218 218 * ---------------------------------------
219 219 *
220 220 * i_mac_impl_lock -> mi_rw_lock -> srs_lock -> s_ring_lock[i_mac_tx_srs_notify]
221 221 *
222 222 * ft_lock -> fe_lock [mac_flow_lookup]
223 223 *
224 224 * mi_rw_lock -> fe_lock [mac_bcast_send]
225 225 *
226 226 * srs_lock -> mac_bw_lock [mac_rx_srs_drain_bw]
227 227 *
228 228 * cpu_lock -> mac_srs_g_lock -> srs_lock -> s_ring_lock [mac_walk_srs_and_bind]
229 229 *
230 230 * i_dls_devnet_lock -> mac layer locks [dls_devnet_rename]
231 231 *
232 232 * Perimeters are ordered P1 -> P2 -> P3 from top to bottom in order of mac
233 233 * client to driver. In the case of clients that explictly use the mac provided
234 234 * perimeter mechanism for its serialization, the hierarchy is
235 235 * Perimeter -> mac layer locks, since the client never holds any locks across
236 236 * the mac calls. In the case of clients that use its own locks the hierarchy
237 237 * is Client locks -> Mac Perim -> Mac layer locks. The client never explicitly
238 238 * calls mac_perim_enter/exit in this case.
239 239 *
240 240 * Subflow creation rules
241 241 * ---------------------------
242 242 * o In case of a user specified cpulist present on underlying link and flows,
243 243 * the flows cpulist must be a subset of the underlying link.
244 244 * o In case of a user specified fanout mode present on link and flow, the
245 245 * subflow fanout count has to be less than or equal to that of the
246 246 * underlying link. The cpu-bindings for the subflows will be a subset of
247 247 * the underlying link.
248 248 * o In case if no cpulist specified on both underlying link and flow, the
249 249 * underlying link relies on a MAC tunable to provide out of box fanout.
250 250 * The subflow will have no cpulist (the subflow will be unbound)
251 251 * o In case if no cpulist is specified on the underlying link, a subflow can
252 252 * carry either a user-specified cpulist or fanout count. The cpu-bindings
253 253 * for the subflow will not adhere to restriction that they need to be subset
254 254 * of the underlying link.
255 255 * o In case where the underlying link is carrying either a user specified
256 256 * cpulist or fanout mode and for a unspecified subflow, the subflow will be
257 257 * created unbound.
258 258 * o While creating unbound subflows, bandwidth mode changes attempt to
259 259 * figure a right fanout count. In such cases the fanout count will override
260 260 * the unbound cpu-binding behavior.
261 261 * o In addition to this, while cycling between flow and link properties, we
262 262 * impose a restriction that if a link property has a subflow with
263 263 * user-specified attributes, we will not allow changing the link property.
264 264 * The administrator needs to reset all the user specified properties for the
265 265 * subflows before attempting a link property change.
266 266 * Some of the above rules can be overridden by specifying additional command
267 267 * line options while creating or modifying link or subflow properties.
268 268 *
269 269 * Datapath
270 270 * --------
271 271 *
272 272 * For information on the datapath, the world of soft rings, hardware rings, how
273 273 * it is structured, and the path of an mblk_t between a driver and a mac
274 274 * client, see mac_sched.c.
275 275 */
276 276
277 277 #include <sys/types.h>
278 278 #include <sys/conf.h>
279 279 #include <sys/id_space.h>
280 280 #include <sys/esunddi.h>
281 281 #include <sys/stat.h>
282 282 #include <sys/mkdev.h>
283 283 #include <sys/stream.h>
284 284 #include <sys/strsun.h>
285 285 #include <sys/strsubr.h>
286 286 #include <sys/dlpi.h>
287 287 #include <sys/list.h>
288 288 #include <sys/modhash.h>
289 289 #include <sys/mac_provider.h>
290 290 #include <sys/mac_client_impl.h>
291 291 #include <sys/mac_soft_ring.h>
292 292 #include <sys/mac_stat.h>
293 293 #include <sys/mac_impl.h>
294 294 #include <sys/mac.h>
295 295 #include <sys/dls.h>
296 296 #include <sys/dld.h>
297 297 #include <sys/modctl.h>
298 298 #include <sys/fs/dv_node.h>
299 299 #include <sys/thread.h>
300 300 #include <sys/proc.h>
301 301 #include <sys/callb.h>
302 302 #include <sys/cpuvar.h>
303 303 #include <sys/atomic.h>
304 304 #include <sys/bitmap.h>
305 305 #include <sys/sdt.h>
306 306 #include <sys/mac_flow.h>
307 307 #include <sys/ddi_intr_impl.h>
308 308 #include <sys/disp.h>
309 309 #include <sys/sdt.h>
310 310 #include <sys/vnic.h>
311 311 #include <sys/vnic_impl.h>
312 312 #include <sys/vlan.h>
313 313 #include <inet/ip.h>
314 314 #include <inet/ip6.h>
315 315 #include <sys/exacct.h>
316 316 #include <sys/exacct_impl.h>
317 317 #include <inet/nd.h>
318 318 #include <sys/ethernet.h>
319 319 #include <sys/pool.h>
320 320 #include <sys/pool_pset.h>
321 321 #include <sys/cpupart.h>
322 322 #include <inet/wifi_ioctl.h>
323 323 #include <net/wpa.h>
324 324
325 325 #define IMPL_HASHSZ 67 /* prime */
326 326
327 327 kmem_cache_t *i_mac_impl_cachep;
328 328 mod_hash_t *i_mac_impl_hash;
329 329 krwlock_t i_mac_impl_lock;
330 330 uint_t i_mac_impl_count;
331 331 static kmem_cache_t *mac_ring_cache;
332 332 static id_space_t *minor_ids;
333 333 static uint32_t minor_count;
334 334 static pool_event_cb_t mac_pool_event_reg;
335 335
336 336 /*
337 337 * Logging stuff. Perhaps mac_logging_interval could be broken into
338 338 * mac_flow_log_interval and mac_link_log_interval if we want to be
339 339 * able to schedule them differently.
340 340 */
341 341 uint_t mac_logging_interval;
342 342 boolean_t mac_flow_log_enable;
343 343 boolean_t mac_link_log_enable;
344 344 timeout_id_t mac_logging_timer;
345 345
346 346 #define MACTYPE_KMODDIR "mac"
347 347 #define MACTYPE_HASHSZ 67
348 348 static mod_hash_t *i_mactype_hash;
349 349 /*
350 350 * i_mactype_lock synchronizes threads that obtain references to mactype_t
351 351 * structures through i_mactype_getplugin().
352 352 */
353 353 static kmutex_t i_mactype_lock;
354 354
355 355 /*
356 356 * mac_tx_percpu_cnt
357 357 *
358 358 * Number of per cpu locks per mac_client_impl_t. Used by the transmit side
359 359 * in mac_tx to reduce lock contention. This is sized at boot time in mac_init.
360 360 * mac_tx_percpu_cnt_max is settable in /etc/system and must be a power of 2.
361 361 * Per cpu locks may be disabled by setting mac_tx_percpu_cnt_max to 1.
362 362 */
363 363 int mac_tx_percpu_cnt;
364 364 int mac_tx_percpu_cnt_max = 128;
365 365
366 366 /*
367 367 * Call back functions for the bridge module. These are guaranteed to be valid
368 368 * when holding a reference on a link or when holding mip->mi_bridge_lock and
369 369 * mi_bridge_link is non-NULL.
370 370 */
371 371 mac_bridge_tx_t mac_bridge_tx_cb;
372 372 mac_bridge_rx_t mac_bridge_rx_cb;
373 373 mac_bridge_ref_t mac_bridge_ref_cb;
374 374 mac_bridge_ls_t mac_bridge_ls_cb;
375 375
376 376 static int i_mac_constructor(void *, void *, int);
377 377 static void i_mac_destructor(void *, void *);
378 378 static int i_mac_ring_ctor(void *, void *, int);
379 379 static void i_mac_ring_dtor(void *, void *);
380 380 static mblk_t *mac_rx_classify(mac_impl_t *, mac_resource_handle_t, mblk_t *);
381 381 void mac_tx_client_flush(mac_client_impl_t *);
382 382 void mac_tx_client_block(mac_client_impl_t *);
383 383 static void mac_rx_ring_quiesce(mac_ring_t *, uint_t);
384 384 static int mac_start_group_and_rings(mac_group_t *);
385 385 static void mac_stop_group_and_rings(mac_group_t *);
386 386 static void mac_pool_event_cb(pool_event_t, int, void *);
387 387
388 388 typedef struct netinfo_s {
389 389 list_node_t ni_link;
390 390 void *ni_record;
391 391 int ni_size;
392 392 int ni_type;
393 393 } netinfo_t;
394 394
395 395 /*
396 396 * Module initialization functions.
397 397 */
398 398
399 399 void
400 400 mac_init(void)
401 401 {
402 402 mac_tx_percpu_cnt = ((boot_max_ncpus == -1) ? max_ncpus :
403 403 boot_max_ncpus);
404 404
405 405 /* Upper bound is mac_tx_percpu_cnt_max */
406 406 if (mac_tx_percpu_cnt > mac_tx_percpu_cnt_max)
407 407 mac_tx_percpu_cnt = mac_tx_percpu_cnt_max;
408 408
409 409 if (mac_tx_percpu_cnt < 1) {
410 410 /* Someone set max_tx_percpu_cnt_max to 0 or less */
411 411 mac_tx_percpu_cnt = 1;
412 412 }
413 413
414 414 ASSERT(mac_tx_percpu_cnt >= 1);
415 415 mac_tx_percpu_cnt = (1 << highbit(mac_tx_percpu_cnt - 1));
416 416 /*
417 417 * Make it of the form 2**N - 1 in the range
418 418 * [0 .. mac_tx_percpu_cnt_max - 1]
419 419 */
420 420 mac_tx_percpu_cnt--;
421 421
422 422 i_mac_impl_cachep = kmem_cache_create("mac_impl_cache",
423 423 sizeof (mac_impl_t), 0, i_mac_constructor, i_mac_destructor,
424 424 NULL, NULL, NULL, 0);
425 425 ASSERT(i_mac_impl_cachep != NULL);
426 426
427 427 mac_ring_cache = kmem_cache_create("mac_ring_cache",
428 428 sizeof (mac_ring_t), 0, i_mac_ring_ctor, i_mac_ring_dtor, NULL,
429 429 NULL, NULL, 0);
430 430 ASSERT(mac_ring_cache != NULL);
431 431
432 432 i_mac_impl_hash = mod_hash_create_extended("mac_impl_hash",
433 433 IMPL_HASHSZ, mod_hash_null_keydtor, mod_hash_null_valdtor,
434 434 mod_hash_bystr, NULL, mod_hash_strkey_cmp, KM_SLEEP);
435 435 rw_init(&i_mac_impl_lock, NULL, RW_DEFAULT, NULL);
436 436
437 437 mac_flow_init();
438 438 mac_soft_ring_init();
439 439 mac_bcast_init();
440 440 mac_client_init();
441 441
442 442 i_mac_impl_count = 0;
443 443
444 444 i_mactype_hash = mod_hash_create_extended("mactype_hash",
445 445 MACTYPE_HASHSZ,
446 446 mod_hash_null_keydtor, mod_hash_null_valdtor,
447 447 mod_hash_bystr, NULL, mod_hash_strkey_cmp, KM_SLEEP);
448 448
449 449 /*
450 450 * Allocate an id space to manage minor numbers. The range of the
451 451 * space will be from MAC_MAX_MINOR+1 to MAC_PRIVATE_MINOR-1. This
452 452 * leaves half of the 32-bit minors available for driver private use.
453 453 */
454 454 minor_ids = id_space_create("mac_minor_ids", MAC_MAX_MINOR+1,
455 455 MAC_PRIVATE_MINOR-1);
456 456 ASSERT(minor_ids != NULL);
457 457 minor_count = 0;
458 458
459 459 /* Let's default to 20 seconds */
460 460 mac_logging_interval = 20;
461 461 mac_flow_log_enable = B_FALSE;
462 462 mac_link_log_enable = B_FALSE;
463 463 mac_logging_timer = NULL;
464 464
465 465 /* Register to be notified of noteworthy pools events */
466 466 mac_pool_event_reg.pec_func = mac_pool_event_cb;
467 467 mac_pool_event_reg.pec_arg = NULL;
468 468 pool_event_cb_register(&mac_pool_event_reg);
469 469 }
470 470
471 471 int
472 472 mac_fini(void)
473 473 {
474 474
475 475 if (i_mac_impl_count > 0 || minor_count > 0)
476 476 return (EBUSY);
477 477
478 478 pool_event_cb_unregister(&mac_pool_event_reg);
479 479
480 480 id_space_destroy(minor_ids);
481 481 mac_flow_fini();
482 482
483 483 mod_hash_destroy_hash(i_mac_impl_hash);
484 484 rw_destroy(&i_mac_impl_lock);
485 485
486 486 mac_client_fini();
487 487 kmem_cache_destroy(mac_ring_cache);
488 488
489 489 mod_hash_destroy_hash(i_mactype_hash);
490 490 mac_soft_ring_finish();
491 491
492 492
493 493 return (0);
494 494 }
495 495
496 496 /*
497 497 * Initialize a GLDv3 driver's device ops. A driver that manages its own ops
498 498 * (e.g. softmac) may pass in a NULL ops argument.
499 499 */
500 500 void
501 501 mac_init_ops(struct dev_ops *ops, const char *name)
502 502 {
503 503 major_t major = ddi_name_to_major((char *)name);
504 504
505 505 /*
506 506 * By returning on error below, we are not letting the driver continue
507 507 * in an undefined context. The mac_register() function will faill if
508 508 * DN_GLDV3_DRIVER isn't set.
509 509 */
510 510 if (major == DDI_MAJOR_T_NONE)
511 511 return;
512 512 LOCK_DEV_OPS(&devnamesp[major].dn_lock);
513 513 devnamesp[major].dn_flags |= (DN_GLDV3_DRIVER | DN_NETWORK_DRIVER);
514 514 UNLOCK_DEV_OPS(&devnamesp[major].dn_lock);
515 515 if (ops != NULL)
516 516 dld_init_ops(ops, name);
517 517 }
518 518
519 519 void
520 520 mac_fini_ops(struct dev_ops *ops)
521 521 {
522 522 dld_fini_ops(ops);
523 523 }
524 524
525 525 /*ARGSUSED*/
526 526 static int
527 527 i_mac_constructor(void *buf, void *arg, int kmflag)
528 528 {
529 529 mac_impl_t *mip = buf;
530 530
531 531 bzero(buf, sizeof (mac_impl_t));
532 532
533 533 mip->mi_linkstate = LINK_STATE_UNKNOWN;
534 534
535 535 rw_init(&mip->mi_rw_lock, NULL, RW_DRIVER, NULL);
536 536 mutex_init(&mip->mi_notify_lock, NULL, MUTEX_DRIVER, NULL);
537 537 mutex_init(&mip->mi_promisc_lock, NULL, MUTEX_DRIVER, NULL);
538 538 mutex_init(&mip->mi_ring_lock, NULL, MUTEX_DEFAULT, NULL);
539 539
540 540 mip->mi_notify_cb_info.mcbi_lockp = &mip->mi_notify_lock;
541 541 cv_init(&mip->mi_notify_cb_info.mcbi_cv, NULL, CV_DRIVER, NULL);
542 542 mip->mi_promisc_cb_info.mcbi_lockp = &mip->mi_promisc_lock;
543 543 cv_init(&mip->mi_promisc_cb_info.mcbi_cv, NULL, CV_DRIVER, NULL);
544 544
545 545 mutex_init(&mip->mi_bridge_lock, NULL, MUTEX_DEFAULT, NULL);
546 546
547 547 return (0);
548 548 }
549 549
550 550 /*ARGSUSED*/
551 551 static void
552 552 i_mac_destructor(void *buf, void *arg)
553 553 {
554 554 mac_impl_t *mip = buf;
555 555 mac_cb_info_t *mcbi;
556 556
557 557 ASSERT(mip->mi_ref == 0);
558 558 ASSERT(mip->mi_active == 0);
559 559 ASSERT(mip->mi_linkstate == LINK_STATE_UNKNOWN);
560 560 ASSERT(mip->mi_devpromisc == 0);
561 561 ASSERT(mip->mi_ksp == NULL);
562 562 ASSERT(mip->mi_kstat_count == 0);
563 563 ASSERT(mip->mi_nclients == 0);
564 564 ASSERT(mip->mi_nactiveclients == 0);
565 565 ASSERT(mip->mi_single_active_client == NULL);
566 566 ASSERT(mip->mi_state_flags == 0);
567 567 ASSERT(mip->mi_factory_addr == NULL);
568 568 ASSERT(mip->mi_factory_addr_num == 0);
569 569 ASSERT(mip->mi_default_tx_ring == NULL);
570 570
571 571 mcbi = &mip->mi_notify_cb_info;
572 572 ASSERT(mcbi->mcbi_del_cnt == 0 && mcbi->mcbi_walker_cnt == 0);
573 573 ASSERT(mip->mi_notify_bits == 0);
574 574 ASSERT(mip->mi_notify_thread == NULL);
575 575 ASSERT(mcbi->mcbi_lockp == &mip->mi_notify_lock);
576 576 mcbi->mcbi_lockp = NULL;
577 577
578 578 mcbi = &mip->mi_promisc_cb_info;
579 579 ASSERT(mcbi->mcbi_del_cnt == 0 && mip->mi_promisc_list == NULL);
580 580 ASSERT(mip->mi_promisc_list == NULL);
581 581 ASSERT(mcbi->mcbi_lockp == &mip->mi_promisc_lock);
582 582 mcbi->mcbi_lockp = NULL;
583 583
584 584 ASSERT(mip->mi_bcast_ngrps == 0 && mip->mi_bcast_grp == NULL);
585 585 ASSERT(mip->mi_perim_owner == NULL && mip->mi_perim_ocnt == 0);
586 586
587 587 rw_destroy(&mip->mi_rw_lock);
588 588
589 589 mutex_destroy(&mip->mi_promisc_lock);
590 590 cv_destroy(&mip->mi_promisc_cb_info.mcbi_cv);
591 591 mutex_destroy(&mip->mi_notify_lock);
592 592 cv_destroy(&mip->mi_notify_cb_info.mcbi_cv);
593 593 mutex_destroy(&mip->mi_ring_lock);
594 594
595 595 ASSERT(mip->mi_bridge_link == NULL);
596 596 }
597 597
598 598 /* ARGSUSED */
599 599 static int
600 600 i_mac_ring_ctor(void *buf, void *arg, int kmflag)
601 601 {
602 602 mac_ring_t *ring = (mac_ring_t *)buf;
603 603
604 604 bzero(ring, sizeof (mac_ring_t));
605 605 cv_init(&ring->mr_cv, NULL, CV_DEFAULT, NULL);
606 606 mutex_init(&ring->mr_lock, NULL, MUTEX_DEFAULT, NULL);
607 607 ring->mr_state = MR_FREE;
608 608 return (0);
609 609 }
610 610
611 611 /* ARGSUSED */
612 612 static void
613 613 i_mac_ring_dtor(void *buf, void *arg)
614 614 {
615 615 mac_ring_t *ring = (mac_ring_t *)buf;
616 616
617 617 cv_destroy(&ring->mr_cv);
618 618 mutex_destroy(&ring->mr_lock);
619 619 }
620 620
621 621 /*
622 622 * Common functions to do mac callback addition and deletion. Currently this is
623 623 * used by promisc callbacks and notify callbacks. List addition and deletion
624 624 * need to take care of list walkers. List walkers in general, can't hold list
625 625 * locks and make upcall callbacks due to potential lock order and recursive
626 626 * reentry issues. Instead list walkers increment the list walker count to mark
627 627 * the presence of a walker thread. Addition can be carefully done to ensure
628 628 * that the list walker always sees either the old list or the new list.
629 629 * However the deletion can't be done while the walker is active, instead the
630 630 * deleting thread simply marks the entry as logically deleted. The last walker
631 631 * physically deletes and frees up the logically deleted entries when the walk
632 632 * is complete.
633 633 */
634 634 void
635 635 mac_callback_add(mac_cb_info_t *mcbi, mac_cb_t **mcb_head,
636 636 mac_cb_t *mcb_elem)
637 637 {
638 638 mac_cb_t *p;
639 639 mac_cb_t **pp;
640 640
641 641 /* Verify it is not already in the list */
642 642 for (pp = mcb_head; (p = *pp) != NULL; pp = &p->mcb_nextp) {
643 643 if (p == mcb_elem)
644 644 break;
645 645 }
646 646 VERIFY(p == NULL);
647 647
648 648 /*
649 649 * Add it to the head of the callback list. The membar ensures that
650 650 * the following list pointer manipulations reach global visibility
651 651 * in exactly the program order below.
652 652 */
653 653 ASSERT(MUTEX_HELD(mcbi->mcbi_lockp));
654 654
655 655 mcb_elem->mcb_nextp = *mcb_head;
656 656 membar_producer();
657 657 *mcb_head = mcb_elem;
658 658 }
659 659
660 660 /*
661 661 * Mark the entry as logically deleted. If there aren't any walkers unlink
662 662 * from the list. In either case return the corresponding status.
663 663 */
664 664 boolean_t
665 665 mac_callback_remove(mac_cb_info_t *mcbi, mac_cb_t **mcb_head,
666 666 mac_cb_t *mcb_elem)
667 667 {
668 668 mac_cb_t *p;
669 669 mac_cb_t **pp;
670 670
671 671 ASSERT(MUTEX_HELD(mcbi->mcbi_lockp));
672 672 /*
673 673 * Search the callback list for the entry to be removed
674 674 */
675 675 for (pp = mcb_head; (p = *pp) != NULL; pp = &p->mcb_nextp) {
676 676 if (p == mcb_elem)
677 677 break;
678 678 }
679 679 VERIFY(p != NULL);
680 680
681 681 /*
682 682 * If there are walkers just mark it as deleted and the last walker
683 683 * will remove from the list and free it.
684 684 */
685 685 if (mcbi->mcbi_walker_cnt != 0) {
686 686 p->mcb_flags |= MCB_CONDEMNED;
687 687 mcbi->mcbi_del_cnt++;
688 688 return (B_FALSE);
689 689 }
690 690
691 691 ASSERT(mcbi->mcbi_del_cnt == 0);
692 692 *pp = p->mcb_nextp;
693 693 p->mcb_nextp = NULL;
694 694 return (B_TRUE);
695 695 }
696 696
697 697 /*
698 698 * Wait for all pending callback removals to be completed
699 699 */
700 700 void
701 701 mac_callback_remove_wait(mac_cb_info_t *mcbi)
702 702 {
703 703 ASSERT(MUTEX_HELD(mcbi->mcbi_lockp));
704 704 while (mcbi->mcbi_del_cnt != 0) {
705 705 DTRACE_PROBE1(need_wait, mac_cb_info_t *, mcbi);
706 706 cv_wait(&mcbi->mcbi_cv, mcbi->mcbi_lockp);
707 707 }
708 708 }
709 709
710 710 /*
711 711 * The last mac callback walker does the cleanup. Walk the list and unlik
712 712 * all the logically deleted entries and construct a temporary list of
713 713 * removed entries. Return the list of removed entries to the caller.
714 714 */
715 715 mac_cb_t *
716 716 mac_callback_walker_cleanup(mac_cb_info_t *mcbi, mac_cb_t **mcb_head)
717 717 {
718 718 mac_cb_t *p;
719 719 mac_cb_t **pp;
720 720 mac_cb_t *rmlist = NULL; /* List of removed elements */
721 721 int cnt = 0;
722 722
723 723 ASSERT(MUTEX_HELD(mcbi->mcbi_lockp));
724 724 ASSERT(mcbi->mcbi_del_cnt != 0 && mcbi->mcbi_walker_cnt == 0);
725 725
726 726 pp = mcb_head;
727 727 while (*pp != NULL) {
728 728 if ((*pp)->mcb_flags & MCB_CONDEMNED) {
729 729 p = *pp;
730 730 *pp = p->mcb_nextp;
731 731 p->mcb_nextp = rmlist;
732 732 rmlist = p;
733 733 cnt++;
734 734 continue;
735 735 }
736 736 pp = &(*pp)->mcb_nextp;
737 737 }
738 738
739 739 ASSERT(mcbi->mcbi_del_cnt == cnt);
740 740 mcbi->mcbi_del_cnt = 0;
741 741 return (rmlist);
742 742 }
743 743
744 744 boolean_t
745 745 mac_callback_lookup(mac_cb_t **mcb_headp, mac_cb_t *mcb_elem)
746 746 {
747 747 mac_cb_t *mcb;
748 748
749 749 /* Verify it is not already in the list */
750 750 for (mcb = *mcb_headp; mcb != NULL; mcb = mcb->mcb_nextp) {
751 751 if (mcb == mcb_elem)
752 752 return (B_TRUE);
753 753 }
754 754
755 755 return (B_FALSE);
756 756 }
757 757
758 758 boolean_t
759 759 mac_callback_find(mac_cb_info_t *mcbi, mac_cb_t **mcb_headp, mac_cb_t *mcb_elem)
760 760 {
761 761 boolean_t found;
762 762
763 763 mutex_enter(mcbi->mcbi_lockp);
764 764 found = mac_callback_lookup(mcb_headp, mcb_elem);
765 765 mutex_exit(mcbi->mcbi_lockp);
766 766
767 767 return (found);
768 768 }
769 769
770 770 /* Free the list of removed callbacks */
771 771 void
772 772 mac_callback_free(mac_cb_t *rmlist)
773 773 {
774 774 mac_cb_t *mcb;
775 775 mac_cb_t *mcb_next;
776 776
777 777 for (mcb = rmlist; mcb != NULL; mcb = mcb_next) {
778 778 mcb_next = mcb->mcb_nextp;
779 779 kmem_free(mcb->mcb_objp, mcb->mcb_objsize);
780 780 }
781 781 }
782 782
783 783 /*
784 784 * The promisc callbacks are in 2 lists, one off the 'mip' and another off the
785 785 * 'mcip' threaded by mpi_mi_link and mpi_mci_link respectively. However there
786 786 * is only a single shared total walker count, and an entry can't be physically
787 787 * unlinked if a walker is active on either list. The last walker does this
788 788 * cleanup of logically deleted entries.
789 789 */
790 790 void
791 791 i_mac_promisc_walker_cleanup(mac_impl_t *mip)
792 792 {
793 793 mac_cb_t *rmlist;
794 794 mac_cb_t *mcb;
795 795 mac_cb_t *mcb_next;
796 796 mac_promisc_impl_t *mpip;
797 797
798 798 /*
799 799 * Construct a temporary list of deleted callbacks by walking the
800 800 * the mi_promisc_list. Then for each entry in the temporary list,
801 801 * remove it from the mci_promisc_list and free the entry.
802 802 */
803 803 rmlist = mac_callback_walker_cleanup(&mip->mi_promisc_cb_info,
804 804 &mip->mi_promisc_list);
805 805
806 806 for (mcb = rmlist; mcb != NULL; mcb = mcb_next) {
807 807 mcb_next = mcb->mcb_nextp;
808 808 mpip = (mac_promisc_impl_t *)mcb->mcb_objp;
809 809 VERIFY(mac_callback_remove(&mip->mi_promisc_cb_info,
810 810 &mpip->mpi_mcip->mci_promisc_list, &mpip->mpi_mci_link));
811 811 mcb->mcb_flags = 0;
812 812 mcb->mcb_nextp = NULL;
813 813 kmem_cache_free(mac_promisc_impl_cache, mpip);
814 814 }
815 815 }
816 816
817 817 void
818 818 i_mac_notify(mac_impl_t *mip, mac_notify_type_t type)
819 819 {
820 820 mac_cb_info_t *mcbi;
821 821
822 822 /*
823 823 * Signal the notify thread even after mi_ref has become zero and
824 824 * mi_disabled is set. The synchronization with the notify thread
825 825 * happens in mac_unregister and that implies the driver must make
826 826 * sure it is single-threaded (with respect to mac calls) and that
827 827 * all pending mac calls have returned before it calls mac_unregister
828 828 */
829 829 rw_enter(&i_mac_impl_lock, RW_READER);
830 830 if (mip->mi_state_flags & MIS_DISABLED)
831 831 goto exit;
832 832
833 833 /*
834 834 * Guard against incorrect notifications. (Running a newer
835 835 * mac client against an older implementation?)
836 836 */
837 837 if (type >= MAC_NNOTE)
838 838 goto exit;
839 839
840 840 mcbi = &mip->mi_notify_cb_info;
841 841 mutex_enter(mcbi->mcbi_lockp);
842 842 mip->mi_notify_bits |= (1 << type);
843 843 cv_broadcast(&mcbi->mcbi_cv);
844 844 mutex_exit(mcbi->mcbi_lockp);
845 845
846 846 exit:
847 847 rw_exit(&i_mac_impl_lock);
848 848 }
849 849
850 850 /*
851 851 * Mac serialization primitives. Please see the block comment at the
852 852 * top of the file.
853 853 */
854 854 void
855 855 i_mac_perim_enter(mac_impl_t *mip)
856 856 {
857 857 mac_client_impl_t *mcip;
858 858
859 859 if (mip->mi_state_flags & MIS_IS_VNIC) {
860 860 /*
861 861 * This is a VNIC. Return the lower mac since that is what
862 862 * we want to serialize on.
863 863 */
864 864 mcip = mac_vnic_lower(mip);
865 865 mip = mcip->mci_mip;
866 866 }
867 867
868 868 mutex_enter(&mip->mi_perim_lock);
869 869 if (mip->mi_perim_owner == curthread) {
870 870 mip->mi_perim_ocnt++;
871 871 mutex_exit(&mip->mi_perim_lock);
872 872 return;
873 873 }
874 874
875 875 while (mip->mi_perim_owner != NULL)
876 876 cv_wait(&mip->mi_perim_cv, &mip->mi_perim_lock);
877 877
878 878 mip->mi_perim_owner = curthread;
879 879 ASSERT(mip->mi_perim_ocnt == 0);
880 880 mip->mi_perim_ocnt++;
881 881 #ifdef DEBUG
882 882 mip->mi_perim_stack_depth = getpcstack(mip->mi_perim_stack,
883 883 MAC_PERIM_STACK_DEPTH);
884 884 #endif
885 885 mutex_exit(&mip->mi_perim_lock);
886 886 }
887 887
888 888 int
889 889 i_mac_perim_enter_nowait(mac_impl_t *mip)
890 890 {
891 891 /*
892 892 * The vnic is a special case, since the serialization is done based
893 893 * on the lower mac. If the lower mac is busy, it does not imply the
894 894 * vnic can't be unregistered. But in the case of other drivers,
895 895 * a busy perimeter or open mac handles implies that the mac is busy
896 896 * and can't be unregistered.
897 897 */
898 898 if (mip->mi_state_flags & MIS_IS_VNIC) {
899 899 i_mac_perim_enter(mip);
900 900 return (0);
901 901 }
902 902
903 903 mutex_enter(&mip->mi_perim_lock);
904 904 if (mip->mi_perim_owner != NULL) {
905 905 mutex_exit(&mip->mi_perim_lock);
906 906 return (EBUSY);
907 907 }
908 908 ASSERT(mip->mi_perim_ocnt == 0);
909 909 mip->mi_perim_owner = curthread;
910 910 mip->mi_perim_ocnt++;
911 911 mutex_exit(&mip->mi_perim_lock);
912 912
913 913 return (0);
914 914 }
915 915
916 916 void
917 917 i_mac_perim_exit(mac_impl_t *mip)
918 918 {
919 919 mac_client_impl_t *mcip;
920 920
921 921 if (mip->mi_state_flags & MIS_IS_VNIC) {
922 922 /*
923 923 * This is a VNIC. Return the lower mac since that is what
924 924 * we want to serialize on.
925 925 */
926 926 mcip = mac_vnic_lower(mip);
927 927 mip = mcip->mci_mip;
928 928 }
929 929
930 930 ASSERT(mip->mi_perim_owner == curthread && mip->mi_perim_ocnt != 0);
931 931
932 932 mutex_enter(&mip->mi_perim_lock);
933 933 if (--mip->mi_perim_ocnt == 0) {
934 934 mip->mi_perim_owner = NULL;
935 935 cv_signal(&mip->mi_perim_cv);
936 936 }
937 937 mutex_exit(&mip->mi_perim_lock);
938 938 }
939 939
940 940 /*
941 941 * Returns whether the current thread holds the mac perimeter. Used in making
942 942 * assertions.
943 943 */
944 944 boolean_t
945 945 mac_perim_held(mac_handle_t mh)
946 946 {
947 947 mac_impl_t *mip = (mac_impl_t *)mh;
948 948 mac_client_impl_t *mcip;
949 949
950 950 if (mip->mi_state_flags & MIS_IS_VNIC) {
951 951 /*
952 952 * This is a VNIC. Return the lower mac since that is what
953 953 * we want to serialize on.
954 954 */
955 955 mcip = mac_vnic_lower(mip);
956 956 mip = mcip->mci_mip;
957 957 }
958 958 return (mip->mi_perim_owner == curthread);
959 959 }
960 960
961 961 /*
962 962 * mac client interfaces to enter the mac perimeter of a mac end point, given
963 963 * its mac handle, or macname or linkid.
964 964 */
965 965 void
966 966 mac_perim_enter_by_mh(mac_handle_t mh, mac_perim_handle_t *mphp)
967 967 {
968 968 mac_impl_t *mip = (mac_impl_t *)mh;
969 969
970 970 i_mac_perim_enter(mip);
971 971 /*
972 972 * The mac_perim_handle_t returned encodes the 'mip' and whether a
973 973 * mac_open has been done internally while entering the perimeter.
974 974 * This information is used in mac_perim_exit
975 975 */
976 976 MAC_ENCODE_MPH(*mphp, mip, 0);
977 977 }
978 978
979 979 int
980 980 mac_perim_enter_by_macname(const char *name, mac_perim_handle_t *mphp)
981 981 {
982 982 int err;
983 983 mac_handle_t mh;
984 984
985 985 if ((err = mac_open(name, &mh)) != 0)
986 986 return (err);
987 987
988 988 mac_perim_enter_by_mh(mh, mphp);
989 989 MAC_ENCODE_MPH(*mphp, mh, 1);
990 990 return (0);
991 991 }
992 992
993 993 int
994 994 mac_perim_enter_by_linkid(datalink_id_t linkid, mac_perim_handle_t *mphp)
995 995 {
996 996 int err;
997 997 mac_handle_t mh;
998 998
999 999 if ((err = mac_open_by_linkid(linkid, &mh)) != 0)
1000 1000 return (err);
1001 1001
1002 1002 mac_perim_enter_by_mh(mh, mphp);
1003 1003 MAC_ENCODE_MPH(*mphp, mh, 1);
1004 1004 return (0);
1005 1005 }
1006 1006
1007 1007 void
1008 1008 mac_perim_exit(mac_perim_handle_t mph)
1009 1009 {
1010 1010 mac_impl_t *mip;
1011 1011 boolean_t need_close;
1012 1012
1013 1013 MAC_DECODE_MPH(mph, mip, need_close);
1014 1014 i_mac_perim_exit(mip);
1015 1015 if (need_close)
1016 1016 mac_close((mac_handle_t)mip);
1017 1017 }
1018 1018
1019 1019 int
1020 1020 mac_hold(const char *macname, mac_impl_t **pmip)
1021 1021 {
1022 1022 mac_impl_t *mip;
1023 1023 int err;
1024 1024
1025 1025 /*
1026 1026 * Check the device name length to make sure it won't overflow our
1027 1027 * buffer.
1028 1028 */
1029 1029 if (strlen(macname) >= MAXNAMELEN)
1030 1030 return (EINVAL);
1031 1031
1032 1032 /*
1033 1033 * Look up its entry in the global hash table.
1034 1034 */
1035 1035 rw_enter(&i_mac_impl_lock, RW_WRITER);
1036 1036 err = mod_hash_find(i_mac_impl_hash, (mod_hash_key_t)macname,
1037 1037 (mod_hash_val_t *)&mip);
1038 1038
1039 1039 if (err != 0) {
1040 1040 rw_exit(&i_mac_impl_lock);
1041 1041 return (ENOENT);
1042 1042 }
1043 1043
1044 1044 if (mip->mi_state_flags & MIS_DISABLED) {
1045 1045 rw_exit(&i_mac_impl_lock);
1046 1046 return (ENOENT);
1047 1047 }
1048 1048
1049 1049 if (mip->mi_state_flags & MIS_EXCLUSIVE_HELD) {
1050 1050 rw_exit(&i_mac_impl_lock);
1051 1051 return (EBUSY);
1052 1052 }
1053 1053
1054 1054 mip->mi_ref++;
1055 1055 rw_exit(&i_mac_impl_lock);
1056 1056
1057 1057 *pmip = mip;
1058 1058 return (0);
1059 1059 }
1060 1060
1061 1061 void
1062 1062 mac_rele(mac_impl_t *mip)
1063 1063 {
1064 1064 rw_enter(&i_mac_impl_lock, RW_WRITER);
1065 1065 ASSERT(mip->mi_ref != 0);
1066 1066 if (--mip->mi_ref == 0) {
1067 1067 ASSERT(mip->mi_nactiveclients == 0 &&
1068 1068 !(mip->mi_state_flags & MIS_EXCLUSIVE));
1069 1069 }
1070 1070 rw_exit(&i_mac_impl_lock);
1071 1071 }
1072 1072
1073 1073 /*
1074 1074 * Private GLDv3 function to start a MAC instance.
1075 1075 */
1076 1076 int
1077 1077 mac_start(mac_handle_t mh)
1078 1078 {
1079 1079 mac_impl_t *mip = (mac_impl_t *)mh;
1080 1080 int err = 0;
1081 1081 mac_group_t *defgrp;
1082 1082
1083 1083 ASSERT(MAC_PERIM_HELD((mac_handle_t)mip));
1084 1084 ASSERT(mip->mi_start != NULL);
1085 1085
1086 1086 /*
1087 1087 * Check whether the device is already started.
1088 1088 */
1089 1089 if (mip->mi_active++ == 0) {
1090 1090 mac_ring_t *ring = NULL;
1091 1091
1092 1092 /*
1093 1093 * Start the device.
1094 1094 */
1095 1095 err = mip->mi_start(mip->mi_driver);
1096 1096 if (err != 0) {
1097 1097 mip->mi_active--;
1098 1098 return (err);
1099 1099 }
1100 1100
1101 1101 /*
1102 1102 * Start the default tx ring.
1103 1103 */
1104 1104 if (mip->mi_default_tx_ring != NULL) {
1105 1105
1106 1106 ring = (mac_ring_t *)mip->mi_default_tx_ring;
1107 1107 if (ring->mr_state != MR_INUSE) {
1108 1108 err = mac_start_ring(ring);
1109 1109 if (err != 0) {
1110 1110 mip->mi_active--;
1111 1111 return (err);
1112 1112 }
1113 1113 }
1114 1114 }
1115 1115
1116 1116 if ((defgrp = MAC_DEFAULT_RX_GROUP(mip)) != NULL) {
1117 1117 /*
1118 1118 * Start the default group which is responsible
1119 1119 * for receiving broadcast and multicast
1120 1120 * traffic for both primary and non-primary
1121 1121 * MAC clients.
1122 1122 */
1123 1123 ASSERT(defgrp->mrg_state == MAC_GROUP_STATE_REGISTERED);
1124 1124 err = mac_start_group_and_rings(defgrp);
1125 1125 if (err != 0) {
1126 1126 mip->mi_active--;
1127 1127 if ((ring != NULL) &&
1128 1128 (ring->mr_state == MR_INUSE))
1129 1129 mac_stop_ring(ring);
1130 1130 return (err);
1131 1131 }
1132 1132 mac_set_group_state(defgrp, MAC_GROUP_STATE_SHARED);
1133 1133 }
1134 1134 }
1135 1135
1136 1136 return (err);
1137 1137 }
1138 1138
1139 1139 /*
1140 1140 * Private GLDv3 function to stop a MAC instance.
1141 1141 */
1142 1142 void
1143 1143 mac_stop(mac_handle_t mh)
1144 1144 {
1145 1145 mac_impl_t *mip = (mac_impl_t *)mh;
1146 1146 mac_group_t *grp;
1147 1147
1148 1148 ASSERT(mip->mi_stop != NULL);
1149 1149 ASSERT(MAC_PERIM_HELD((mac_handle_t)mip));
1150 1150
1151 1151 /*
1152 1152 * Check whether the device is still needed.
1153 1153 */
1154 1154 ASSERT(mip->mi_active != 0);
1155 1155 if (--mip->mi_active == 0) {
1156 1156 if ((grp = MAC_DEFAULT_RX_GROUP(mip)) != NULL) {
1157 1157 /*
1158 1158 * There should be no more active clients since the
1159 1159 * MAC is being stopped. Stop the default RX group
1160 1160 * and transition it back to registered state.
1161 1161 *
1162 1162 * When clients are torn down, the groups
1163 1163 * are release via mac_release_rx_group which
1164 1164 * knows the the default group is always in
1165 1165 * started mode since broadcast uses it. So
1166 1166 * we can assert that their are no clients
1167 1167 * (since mac_bcast_add doesn't register itself
1168 1168 * as a client) and group is in SHARED state.
1169 1169 */
1170 1170 ASSERT(grp->mrg_state == MAC_GROUP_STATE_SHARED);
1171 1171 ASSERT(MAC_GROUP_NO_CLIENT(grp) &&
1172 1172 mip->mi_nactiveclients == 0);
1173 1173 mac_stop_group_and_rings(grp);
1174 1174 mac_set_group_state(grp, MAC_GROUP_STATE_REGISTERED);
1175 1175 }
1176 1176
1177 1177 if (mip->mi_default_tx_ring != NULL) {
1178 1178 mac_ring_t *ring;
1179 1179
1180 1180 ring = (mac_ring_t *)mip->mi_default_tx_ring;
1181 1181 if (ring->mr_state == MR_INUSE) {
1182 1182 mac_stop_ring(ring);
1183 1183 ring->mr_flag = 0;
1184 1184 }
1185 1185 }
1186 1186
1187 1187 /*
1188 1188 * Stop the device.
1189 1189 */
1190 1190 mip->mi_stop(mip->mi_driver);
1191 1191 }
1192 1192 }
1193 1193
1194 1194 int
1195 1195 i_mac_promisc_set(mac_impl_t *mip, boolean_t on)
1196 1196 {
1197 1197 int err = 0;
1198 1198
1199 1199 ASSERT(MAC_PERIM_HELD((mac_handle_t)mip));
1200 1200 ASSERT(mip->mi_setpromisc != NULL);
1201 1201
1202 1202 if (on) {
1203 1203 /*
1204 1204 * Enable promiscuous mode on the device if not yet enabled.
1205 1205 */
1206 1206 if (mip->mi_devpromisc++ == 0) {
1207 1207 err = mip->mi_setpromisc(mip->mi_driver, B_TRUE);
1208 1208 if (err != 0) {
1209 1209 mip->mi_devpromisc--;
1210 1210 return (err);
1211 1211 }
1212 1212 i_mac_notify(mip, MAC_NOTE_DEVPROMISC);
1213 1213 }
1214 1214 } else {
1215 1215 if (mip->mi_devpromisc == 0)
1216 1216 return (EPROTO);
1217 1217
1218 1218 /*
1219 1219 * Disable promiscuous mode on the device if this is the last
1220 1220 * enabling.
1221 1221 */
1222 1222 if (--mip->mi_devpromisc == 0) {
1223 1223 err = mip->mi_setpromisc(mip->mi_driver, B_FALSE);
1224 1224 if (err != 0) {
1225 1225 mip->mi_devpromisc++;
1226 1226 return (err);
1227 1227 }
1228 1228 i_mac_notify(mip, MAC_NOTE_DEVPROMISC);
1229 1229 }
1230 1230 }
1231 1231
1232 1232 return (0);
1233 1233 }
1234 1234
1235 1235 /*
1236 1236 * The promiscuity state can change any time. If the caller needs to take
1237 1237 * actions that are atomic with the promiscuity state, then the caller needs
1238 1238 * to bracket the entire sequence with mac_perim_enter/exit
1239 1239 */
1240 1240 boolean_t
1241 1241 mac_promisc_get(mac_handle_t mh)
1242 1242 {
1243 1243 mac_impl_t *mip = (mac_impl_t *)mh;
1244 1244
1245 1245 /*
1246 1246 * Return the current promiscuity.
1247 1247 */
1248 1248 return (mip->mi_devpromisc != 0);
1249 1249 }
1250 1250
1251 1251 /*
1252 1252 * Invoked at MAC instance attach time to initialize the list
1253 1253 * of factory MAC addresses supported by a MAC instance. This function
1254 1254 * builds a local cache in the mac_impl_t for the MAC addresses
1255 1255 * supported by the underlying hardware. The MAC clients themselves
1256 1256 * use the mac_addr_factory*() functions to query and reserve
1257 1257 * factory MAC addresses.
1258 1258 */
1259 1259 void
1260 1260 mac_addr_factory_init(mac_impl_t *mip)
1261 1261 {
1262 1262 mac_capab_multifactaddr_t capab;
1263 1263 uint8_t *addr;
1264 1264 int i;
1265 1265
1266 1266 /*
1267 1267 * First round to see how many factory MAC addresses are available.
1268 1268 */
1269 1269 bzero(&capab, sizeof (capab));
1270 1270 if (!i_mac_capab_get((mac_handle_t)mip, MAC_CAPAB_MULTIFACTADDR,
1271 1271 &capab) || (capab.mcm_naddr == 0)) {
1272 1272 /*
1273 1273 * The MAC instance doesn't support multiple factory
1274 1274 * MAC addresses, we're done here.
1275 1275 */
1276 1276 return;
1277 1277 }
1278 1278
1279 1279 /*
1280 1280 * Allocate the space and get all the factory addresses.
1281 1281 */
1282 1282 addr = kmem_alloc(capab.mcm_naddr * MAXMACADDRLEN, KM_SLEEP);
1283 1283 capab.mcm_getaddr(mip->mi_driver, capab.mcm_naddr, addr);
1284 1284
1285 1285 mip->mi_factory_addr_num = capab.mcm_naddr;
1286 1286 mip->mi_factory_addr = kmem_zalloc(mip->mi_factory_addr_num *
1287 1287 sizeof (mac_factory_addr_t), KM_SLEEP);
1288 1288
1289 1289 for (i = 0; i < capab.mcm_naddr; i++) {
1290 1290 bcopy(addr + i * MAXMACADDRLEN,
1291 1291 mip->mi_factory_addr[i].mfa_addr,
1292 1292 mip->mi_type->mt_addr_length);
1293 1293 mip->mi_factory_addr[i].mfa_in_use = B_FALSE;
1294 1294 }
1295 1295
1296 1296 kmem_free(addr, capab.mcm_naddr * MAXMACADDRLEN);
1297 1297 }
1298 1298
1299 1299 void
1300 1300 mac_addr_factory_fini(mac_impl_t *mip)
1301 1301 {
1302 1302 if (mip->mi_factory_addr == NULL) {
1303 1303 ASSERT(mip->mi_factory_addr_num == 0);
1304 1304 return;
1305 1305 }
1306 1306
1307 1307 kmem_free(mip->mi_factory_addr, mip->mi_factory_addr_num *
1308 1308 sizeof (mac_factory_addr_t));
1309 1309
1310 1310 mip->mi_factory_addr = NULL;
1311 1311 mip->mi_factory_addr_num = 0;
1312 1312 }
1313 1313
1314 1314 /*
1315 1315 * Reserve a factory MAC address. If *slot is set to -1, the function
1316 1316 * attempts to reserve any of the available factory MAC addresses and
1317 1317 * returns the reserved slot id. If no slots are available, the function
1318 1318 * returns ENOSPC. If *slot is not set to -1, the function reserves
1319 1319 * the specified slot if it is available, or returns EBUSY is the slot
1320 1320 * is already used. Returns ENOTSUP if the underlying MAC does not
1321 1321 * support multiple factory addresses. If the slot number is not -1 but
1322 1322 * is invalid, returns EINVAL.
1323 1323 */
1324 1324 int
1325 1325 mac_addr_factory_reserve(mac_client_handle_t mch, int *slot)
1326 1326 {
1327 1327 mac_client_impl_t *mcip = (mac_client_impl_t *)mch;
1328 1328 mac_impl_t *mip = mcip->mci_mip;
1329 1329 int i, ret = 0;
1330 1330
1331 1331 i_mac_perim_enter(mip);
1332 1332 /*
1333 1333 * Protect against concurrent readers that may need a self-consistent
1334 1334 * view of the factory addresses
1335 1335 */
1336 1336 rw_enter(&mip->mi_rw_lock, RW_WRITER);
1337 1337
1338 1338 if (mip->mi_factory_addr_num == 0) {
1339 1339 ret = ENOTSUP;
1340 1340 goto bail;
1341 1341 }
1342 1342
1343 1343 if (*slot != -1) {
1344 1344 /* check the specified slot */
1345 1345 if (*slot < 1 || *slot > mip->mi_factory_addr_num) {
1346 1346 ret = EINVAL;
1347 1347 goto bail;
1348 1348 }
1349 1349 if (mip->mi_factory_addr[*slot-1].mfa_in_use) {
1350 1350 ret = EBUSY;
1351 1351 goto bail;
1352 1352 }
1353 1353 } else {
1354 1354 /* pick the next available slot */
1355 1355 for (i = 0; i < mip->mi_factory_addr_num; i++) {
1356 1356 if (!mip->mi_factory_addr[i].mfa_in_use)
1357 1357 break;
1358 1358 }
1359 1359
1360 1360 if (i == mip->mi_factory_addr_num) {
1361 1361 ret = ENOSPC;
1362 1362 goto bail;
1363 1363 }
1364 1364 *slot = i+1;
1365 1365 }
1366 1366
1367 1367 mip->mi_factory_addr[*slot-1].mfa_in_use = B_TRUE;
1368 1368 mip->mi_factory_addr[*slot-1].mfa_client = mcip;
1369 1369
1370 1370 bail:
1371 1371 rw_exit(&mip->mi_rw_lock);
1372 1372 i_mac_perim_exit(mip);
1373 1373 return (ret);
1374 1374 }
1375 1375
1376 1376 /*
1377 1377 * Release the specified factory MAC address slot.
1378 1378 */
1379 1379 void
1380 1380 mac_addr_factory_release(mac_client_handle_t mch, uint_t slot)
1381 1381 {
1382 1382 mac_client_impl_t *mcip = (mac_client_impl_t *)mch;
1383 1383 mac_impl_t *mip = mcip->mci_mip;
1384 1384
1385 1385 i_mac_perim_enter(mip);
1386 1386 /*
1387 1387 * Protect against concurrent readers that may need a self-consistent
1388 1388 * view of the factory addresses
1389 1389 */
1390 1390 rw_enter(&mip->mi_rw_lock, RW_WRITER);
1391 1391
1392 1392 ASSERT(slot > 0 && slot <= mip->mi_factory_addr_num);
1393 1393 ASSERT(mip->mi_factory_addr[slot-1].mfa_in_use);
1394 1394
1395 1395 mip->mi_factory_addr[slot-1].mfa_in_use = B_FALSE;
1396 1396
1397 1397 rw_exit(&mip->mi_rw_lock);
1398 1398 i_mac_perim_exit(mip);
1399 1399 }
1400 1400
1401 1401 /*
1402 1402 * Stores in mac_addr the value of the specified MAC address. Returns
1403 1403 * 0 on success, or EINVAL if the slot number is not valid for the MAC.
1404 1404 * The caller must provide a string of at least MAXNAMELEN bytes.
1405 1405 */
1406 1406 void
1407 1407 mac_addr_factory_value(mac_handle_t mh, int slot, uchar_t *mac_addr,
1408 1408 uint_t *addr_len, char *client_name, boolean_t *in_use_arg)
1409 1409 {
1410 1410 mac_impl_t *mip = (mac_impl_t *)mh;
1411 1411 boolean_t in_use;
1412 1412
1413 1413 ASSERT(slot > 0 && slot <= mip->mi_factory_addr_num);
1414 1414
1415 1415 /*
1416 1416 * Readers need to hold mi_rw_lock. Writers need to hold mac perimeter
1417 1417 * and mi_rw_lock
1418 1418 */
1419 1419 rw_enter(&mip->mi_rw_lock, RW_READER);
1420 1420 bcopy(mip->mi_factory_addr[slot-1].mfa_addr, mac_addr, MAXMACADDRLEN);
1421 1421 *addr_len = mip->mi_type->mt_addr_length;
1422 1422 in_use = mip->mi_factory_addr[slot-1].mfa_in_use;
1423 1423 if (in_use && client_name != NULL) {
1424 1424 bcopy(mip->mi_factory_addr[slot-1].mfa_client->mci_name,
1425 1425 client_name, MAXNAMELEN);
1426 1426 }
1427 1427 if (in_use_arg != NULL)
1428 1428 *in_use_arg = in_use;
1429 1429 rw_exit(&mip->mi_rw_lock);
1430 1430 }
1431 1431
1432 1432 /*
1433 1433 * Returns the number of factory MAC addresses (in addition to the
1434 1434 * primary MAC address), 0 if the underlying MAC doesn't support
1435 1435 * that feature.
1436 1436 */
1437 1437 uint_t
1438 1438 mac_addr_factory_num(mac_handle_t mh)
1439 1439 {
1440 1440 mac_impl_t *mip = (mac_impl_t *)mh;
1441 1441
1442 1442 return (mip->mi_factory_addr_num);
1443 1443 }
1444 1444
1445 1445
1446 1446 void
1447 1447 mac_rx_group_unmark(mac_group_t *grp, uint_t flag)
1448 1448 {
1449 1449 mac_ring_t *ring;
↓ open down ↓ |
1449 lines elided |
↑ open up ↑ |
1450 1450
1451 1451 for (ring = grp->mrg_rings; ring != NULL; ring = ring->mr_next)
1452 1452 ring->mr_flag &= ~flag;
1453 1453 }
1454 1454
1455 1455 /*
1456 1456 * The following mac_hwrings_xxx() functions are private mac client functions
1457 1457 * used by the aggr driver to access and control the underlying HW Rx group
1458 1458 * and rings. In this case, the aggr driver has exclusive control of the
1459 1459 * underlying HW Rx group/rings, it calls the following functions to
1460 - * start/stop the HW Rx rings, disable/enable polling, add/remove mac'
1460 + * start/stop the HW Rx rings, disable/enable polling, add/remove MAC
1461 1461 * addresses, or set up the Rx callback.
1462 1462 */
1463 1463 /* ARGSUSED */
1464 1464 static void
1465 1465 mac_hwrings_rx_process(void *arg, mac_resource_handle_t srs,
1466 1466 mblk_t *mp_chain, boolean_t loopback)
1467 1467 {
1468 1468 mac_soft_ring_set_t *mac_srs = (mac_soft_ring_set_t *)srs;
1469 1469 mac_srs_rx_t *srs_rx = &mac_srs->srs_rx;
1470 1470 mac_direct_rx_t proc;
1471 1471 void *arg1;
1472 1472 mac_resource_handle_t arg2;
1473 1473
1474 1474 proc = srs_rx->sr_func;
1475 1475 arg1 = srs_rx->sr_arg1;
1476 1476 arg2 = mac_srs->srs_mrh;
1477 1477
1478 1478 proc(arg1, arg2, mp_chain, NULL);
1479 1479 }
1480 1480
1481 1481 /*
1482 1482 * This function is called to get the list of HW rings that are reserved by
1483 1483 * an exclusive mac client.
1484 1484 *
1485 1485 * Return value: the number of HW rings.
1486 1486 */
1487 1487 int
1488 1488 mac_hwrings_get(mac_client_handle_t mch, mac_group_handle_t *hwgh,
1489 1489 mac_ring_handle_t *hwrh, mac_ring_type_t rtype)
1490 1490 {
1491 1491 mac_client_impl_t *mcip = (mac_client_impl_t *)mch;
1492 1492 flow_entry_t *flent = mcip->mci_flent;
1493 1493 mac_group_t *grp;
1494 1494 mac_ring_t *ring;
↓ open down ↓ |
24 lines elided |
↑ open up ↑ |
1495 1495 int cnt = 0;
1496 1496
1497 1497 if (rtype == MAC_RING_TYPE_RX) {
1498 1498 grp = flent->fe_rx_ring_group;
1499 1499 } else if (rtype == MAC_RING_TYPE_TX) {
1500 1500 grp = flent->fe_tx_ring_group;
1501 1501 } else {
1502 1502 ASSERT(B_FALSE);
1503 1503 return (-1);
1504 1504 }
1505 +
1505 1506 /*
1506 - * The mac client did not reserve any RX group, return directly.
1507 + * The MAC client did not reserve an Rx group, return directly.
1507 1508 * This is probably because the underlying MAC does not support
1508 1509 * any groups.
1509 1510 */
1510 1511 if (hwgh != NULL)
1511 1512 *hwgh = NULL;
1512 1513 if (grp == NULL)
1513 1514 return (0);
1514 1515 /*
1515 - * This group must be reserved by this mac client.
1516 + * This group must be reserved by this MAC client.
1516 1517 */
1517 1518 ASSERT((grp->mrg_state == MAC_GROUP_STATE_RESERVED) &&
1518 1519 (mcip == MAC_GROUP_ONLY_CLIENT(grp)));
1519 1520
1520 1521 for (ring = grp->mrg_rings; ring != NULL; ring = ring->mr_next, cnt++) {
1521 1522 ASSERT(cnt < MAX_RINGS_PER_GROUP);
1522 1523 hwrh[cnt] = (mac_ring_handle_t)ring;
1523 1524 }
1524 1525 if (hwgh != NULL)
1525 1526 *hwgh = (mac_group_handle_t)grp;
1526 1527
1527 1528 return (cnt);
1528 1529 }
1529 1530
1530 1531 /*
1532 + * Get the HW ring handles of the given group index. If the MAC
1533 + * doesn't have a group at this index, or any groups at all, then 0 is
1534 + * returned and hwgh is set to NULL. This is a private client API. The
1535 + * MAC perimeter must be held when calling this function.
1536 + *
1537 + * mh: A handle to the MAC that owns the group.
1538 + *
1539 + * idx: The index of the HW group to be read.
1540 + *
1541 + * hwgh: If non-NULL, contains a handle to the HW group on return.
1542 + *
1543 + * hwrh: An array of ring handles pointing to the HW rings in the
1544 + * group. The array must be large enough to hold a handle to each ring
1545 + * in the group. To be safe, this array should be of size MAX_RINGS_PER_GROUP.
1546 + *
1547 + * rtype: Used to determine if we are fetching Rx or Tx rings.
1548 + *
1549 + * Returns the number of rings in the group.
1550 + */
1551 +uint_t
1552 +mac_hwrings_idx_get(mac_handle_t mh, uint_t idx, mac_group_handle_t *hwgh,
1553 + mac_ring_handle_t *hwrh, mac_ring_type_t rtype)
1554 +{
1555 + mac_impl_t *mip = (mac_impl_t *)mh;
1556 + mac_group_t *grp;
1557 + mac_ring_t *ring;
1558 + uint_t cnt = 0;
1559 +
1560 + /*
1561 + * The MAC perimeter must be held when accessing the
1562 + * mi_{rx,tx}_groups fields.
1563 + */
1564 + ASSERT(MAC_PERIM_HELD(mh));
1565 + ASSERT(rtype == MAC_RING_TYPE_RX || rtype == MAC_RING_TYPE_TX);
1566 +
1567 + if (rtype == MAC_RING_TYPE_RX) {
1568 + grp = mip->mi_rx_groups;
1569 + } else if (rtype == MAC_RING_TYPE_TX) {
1570 + grp = mip->mi_tx_groups;
1571 + }
1572 +
1573 + while (grp != NULL && grp->mrg_index != idx)
1574 + grp = grp->mrg_next;
1575 +
1576 + /*
1577 + * If the MAC doesn't have a group at this index or doesn't
1578 + * impelement RINGS capab, then set hwgh to NULL and return 0.
1579 + */
1580 + if (hwgh != NULL)
1581 + *hwgh = NULL;
1582 +
1583 + if (grp == NULL)
1584 + return (0);
1585 +
1586 + ASSERT3U(idx, ==, grp->mrg_index);
1587 +
1588 + for (ring = grp->mrg_rings; ring != NULL; ring = ring->mr_next, cnt++) {
1589 + ASSERT3U(cnt, <, MAX_RINGS_PER_GROUP);
1590 + hwrh[cnt] = (mac_ring_handle_t)ring;
1591 + }
1592 +
1593 + /* A group should always have at least one ring. */
1594 + ASSERT3U(cnt, >, 0);
1595 +
1596 + if (hwgh != NULL)
1597 + *hwgh = (mac_group_handle_t)grp;
1598 +
1599 + return (cnt);
1600 +}
1601 +
1602 +/*
1531 1603 * This function is called to get info about Tx/Rx rings.
1532 1604 *
1533 1605 * Return value: returns uint_t which will have various bits set
1534 1606 * that indicates different properties of the ring.
1535 1607 */
1536 1608 uint_t
1537 1609 mac_hwring_getinfo(mac_ring_handle_t rh)
1538 1610 {
1539 1611 mac_ring_t *ring = (mac_ring_t *)rh;
1540 1612 mac_ring_info_t *info = &ring->mr_info;
1541 1613
1542 1614 return (info->mri_flags);
1543 1615 }
1544 1616
1545 1617 /*
1618 + * Set the passthru callback on the hardware ring.
1619 + */
1620 +void
1621 +mac_hwring_set_passthru(mac_ring_handle_t hwrh, mac_rx_t fn, void *arg1,
1622 + mac_resource_handle_t arg2)
1623 +{
1624 + mac_ring_t *hwring = (mac_ring_t *)hwrh;
1625 +
1626 + ASSERT3S(hwring->mr_type, ==, MAC_RING_TYPE_RX);
1627 +
1628 + hwring->mr_classify_type = MAC_PASSTHRU_CLASSIFIER;
1629 +
1630 + hwring->mr_pt_fn = fn;
1631 + hwring->mr_pt_arg1 = arg1;
1632 + hwring->mr_pt_arg2 = arg2;
1633 +}
1634 +
1635 +/*
1636 + * Clear the passthru callback on the hardware ring.
1637 + */
1638 +void
1639 +mac_hwring_clear_passthru(mac_ring_handle_t hwrh)
1640 +{
1641 + mac_ring_t *hwring = (mac_ring_t *)hwrh;
1642 +
1643 + ASSERT3S(hwring->mr_type, ==, MAC_RING_TYPE_RX);
1644 +
1645 + hwring->mr_classify_type = MAC_NO_CLASSIFIER;
1646 +
1647 + hwring->mr_pt_fn = NULL;
1648 + hwring->mr_pt_arg1 = NULL;
1649 + hwring->mr_pt_arg2 = NULL;
1650 +}
1651 +
1652 +void
1653 +mac_client_set_flow_cb(mac_client_handle_t mch, mac_rx_t func, void *arg1)
1654 +{
1655 + mac_client_impl_t *mcip = (mac_client_impl_t *)mch;
1656 + flow_entry_t *flent = mcip->mci_flent;
1657 +
1658 + mutex_enter(&flent->fe_lock);
1659 + flent->fe_cb_fn = (flow_fn_t)func;
1660 + flent->fe_cb_arg1 = arg1;
1661 + flent->fe_cb_arg2 = NULL;
1662 + flent->fe_flags &= ~FE_MC_NO_DATAPATH;
1663 + mutex_exit(&flent->fe_lock);
1664 +}
1665 +
1666 +void
1667 +mac_client_clear_flow_cb(mac_client_handle_t mch)
1668 +{
1669 + mac_client_impl_t *mcip = (mac_client_impl_t *)mch;
1670 + flow_entry_t *flent = mcip->mci_flent;
1671 +
1672 + mutex_enter(&flent->fe_lock);
1673 + flent->fe_cb_fn = (flow_fn_t)mac_pkt_drop;
1674 + flent->fe_cb_arg1 = NULL;
1675 + flent->fe_cb_arg2 = NULL;
1676 + flent->fe_flags |= FE_MC_NO_DATAPATH;
1677 + mutex_exit(&flent->fe_lock);
1678 +}
1679 +
1680 +/*
1546 1681 * Export ddi interrupt handles from the HW ring to the pseudo ring and
1547 1682 * setup the RX callback of the mac client which exclusively controls
1548 1683 * HW ring.
1549 1684 */
1550 1685 void
1551 1686 mac_hwring_setup(mac_ring_handle_t hwrh, mac_resource_handle_t prh,
1552 1687 mac_ring_handle_t pseudo_rh)
1553 1688 {
1554 1689 mac_ring_t *hw_ring = (mac_ring_t *)hwrh;
1555 1690 mac_ring_t *pseudo_ring;
1556 1691 mac_soft_ring_set_t *mac_srs = hw_ring->mr_srs;
1557 1692
1558 1693 if (pseudo_rh != NULL) {
1559 1694 pseudo_ring = (mac_ring_t *)pseudo_rh;
1560 1695 /* Export the ddi handles to pseudo ring */
1561 1696 pseudo_ring->mr_info.mri_intr.mi_ddi_handle =
1562 1697 hw_ring->mr_info.mri_intr.mi_ddi_handle;
1563 1698 pseudo_ring->mr_info.mri_intr.mi_ddi_shared =
1564 1699 hw_ring->mr_info.mri_intr.mi_ddi_shared;
1565 1700 /*
1566 1701 * Save a pointer to pseudo ring in the hw ring. If
1567 1702 * interrupt handle changes, the hw ring will be
1568 1703 * notified of the change (see mac_ring_intr_set())
1569 1704 * and the appropriate change has to be made to
1570 1705 * the pseudo ring that has exported the ddi handle.
1571 1706 */
1572 1707 hw_ring->mr_prh = pseudo_rh;
1573 1708 }
1574 1709
1575 1710 if (hw_ring->mr_type == MAC_RING_TYPE_RX) {
1576 1711 ASSERT(!(mac_srs->srs_type & SRST_TX));
1577 1712 mac_srs->srs_mrh = prh;
1578 1713 mac_srs->srs_rx.sr_lower_proc = mac_hwrings_rx_process;
1579 1714 }
1580 1715 }
1581 1716
1582 1717 void
1583 1718 mac_hwring_teardown(mac_ring_handle_t hwrh)
1584 1719 {
1585 1720 mac_ring_t *hw_ring = (mac_ring_t *)hwrh;
1586 1721 mac_soft_ring_set_t *mac_srs;
1587 1722
1588 1723 if (hw_ring == NULL)
1589 1724 return;
1590 1725 hw_ring->mr_prh = NULL;
1591 1726 if (hw_ring->mr_type == MAC_RING_TYPE_RX) {
1592 1727 mac_srs = hw_ring->mr_srs;
1593 1728 ASSERT(!(mac_srs->srs_type & SRST_TX));
1594 1729 mac_srs->srs_rx.sr_lower_proc = mac_rx_srs_process;
1595 1730 mac_srs->srs_mrh = NULL;
1596 1731 }
1597 1732 }
1598 1733
1599 1734 int
1600 1735 mac_hwring_disable_intr(mac_ring_handle_t rh)
1601 1736 {
1602 1737 mac_ring_t *rr_ring = (mac_ring_t *)rh;
1603 1738 mac_intr_t *intr = &rr_ring->mr_info.mri_intr;
1604 1739
1605 1740 return (intr->mi_disable(intr->mi_handle));
1606 1741 }
↓ open down ↓ |
51 lines elided |
↑ open up ↑ |
1607 1742
1608 1743 int
1609 1744 mac_hwring_enable_intr(mac_ring_handle_t rh)
1610 1745 {
1611 1746 mac_ring_t *rr_ring = (mac_ring_t *)rh;
1612 1747 mac_intr_t *intr = &rr_ring->mr_info.mri_intr;
1613 1748
1614 1749 return (intr->mi_enable(intr->mi_handle));
1615 1750 }
1616 1751
1752 +/*
1753 + * Start the HW ring pointed to by rh.
1754 + *
1755 + * This is used by special MAC clients that are MAC themselves and
1756 + * need to exert control over the underlying HW rings of the NIC.
1757 + */
1617 1758 int
1618 1759 mac_hwring_start(mac_ring_handle_t rh)
1619 1760 {
1620 1761 mac_ring_t *rr_ring = (mac_ring_t *)rh;
1762 + int rv = 0;
1621 1763
1764 + if (rr_ring->mr_state != MR_INUSE)
1765 + rv = mac_start_ring(rr_ring);
1766 +
1767 + return (rv);
1768 +}
1769 +
1770 +/*
1771 + * Stop the HW ring pointed to by rh. Also see mac_hwring_start().
1772 + */
1773 +void
1774 +mac_hwring_stop(mac_ring_handle_t rh)
1775 +{
1776 + mac_ring_t *rr_ring = (mac_ring_t *)rh;
1777 +
1778 + if (rr_ring->mr_state != MR_FREE)
1779 + mac_stop_ring(rr_ring);
1780 +}
1781 +
1782 +/*
1783 + * Remove the quiesced flag from the HW ring pointed to by rh.
1784 + *
1785 + * This is used by special MAC clients that are MAC themselves and
1786 + * need to exert control over the underlying HW rings of the NIC.
1787 + */
1788 +int
1789 +mac_hwring_activate(mac_ring_handle_t rh)
1790 +{
1791 + mac_ring_t *rr_ring = (mac_ring_t *)rh;
1792 +
1622 1793 MAC_RING_UNMARK(rr_ring, MR_QUIESCE);
1623 1794 return (0);
1624 1795 }
1625 1796
1797 +/*
1798 + * Quiesce the HW ring pointed to by rh. Also see mac_hwring_activate().
1799 + */
1626 1800 void
1627 -mac_hwring_stop(mac_ring_handle_t rh)
1801 +mac_hwring_quiesce(mac_ring_handle_t rh)
1628 1802 {
1629 1803 mac_ring_t *rr_ring = (mac_ring_t *)rh;
1630 1804
1631 1805 mac_rx_ring_quiesce(rr_ring, MR_QUIESCE);
1632 1806 }
1633 1807
1634 1808 mblk_t *
1635 1809 mac_hwring_poll(mac_ring_handle_t rh, int bytes_to_pickup)
1636 1810 {
1637 1811 mac_ring_t *rr_ring = (mac_ring_t *)rh;
1638 1812 mac_ring_info_t *info = &rr_ring->mr_info;
1639 1813
1640 1814 return (info->mri_poll(info->mri_driver, bytes_to_pickup));
1641 1815 }
1642 1816
1643 1817 /*
1644 1818 * Send packets through a selected tx ring.
1645 1819 */
1646 1820 mblk_t *
1647 1821 mac_hwring_tx(mac_ring_handle_t rh, mblk_t *mp)
1648 1822 {
1649 1823 mac_ring_t *ring = (mac_ring_t *)rh;
1650 1824 mac_ring_info_t *info = &ring->mr_info;
1651 1825
1652 1826 ASSERT(ring->mr_type == MAC_RING_TYPE_TX &&
1653 1827 ring->mr_state >= MR_INUSE);
1654 1828 return (info->mri_tx(info->mri_driver, mp));
1655 1829 }
1656 1830
1657 1831 /*
1658 1832 * Query stats for a particular rx/tx ring
1659 1833 */
1660 1834 int
1661 1835 mac_hwring_getstat(mac_ring_handle_t rh, uint_t stat, uint64_t *val)
1662 1836 {
1663 1837 mac_ring_t *ring = (mac_ring_t *)rh;
1664 1838 mac_ring_info_t *info = &ring->mr_info;
1665 1839
1666 1840 return (info->mri_stat(info->mri_driver, stat, val));
1667 1841 }
1668 1842
1669 1843 /*
1670 1844 * Private function that is only used by aggr to send packets through
1671 1845 * a port/Tx ring. Since aggr exposes a pseudo Tx ring even for ports
1672 1846 * that does not expose Tx rings, aggr_ring_tx() entry point needs
1673 1847 * access to mac_impl_t to send packets through m_tx() entry point.
1674 1848 * It accomplishes this by calling mac_hwring_send_priv() function.
1675 1849 */
1676 1850 mblk_t *
1677 1851 mac_hwring_send_priv(mac_client_handle_t mch, mac_ring_handle_t rh, mblk_t *mp)
1678 1852 {
1679 1853 mac_client_impl_t *mcip = (mac_client_impl_t *)mch;
1680 1854 mac_impl_t *mip = mcip->mci_mip;
1681 1855
1682 1856 MAC_TX(mip, rh, mp, mcip);
1683 1857 return (mp);
1684 1858 }
1685 1859
1686 1860 /*
1687 1861 * Private function that is only used by aggr to update the default transmission
1688 1862 * ring. Because aggr exposes a pseudo Tx ring even for ports that may
1689 1863 * temporarily be down, it may need to update the default ring that is used by
1690 1864 * MAC such that it refers to a link that can actively be used to send traffic.
1691 1865 * Note that this is different from the case where the port has been removed
1692 1866 * from the group. In those cases, all of the rings will be torn down because
1693 1867 * the ring will no longer exist. It's important to give aggr a case where the
1694 1868 * rings can still exist such that it may be able to continue to send LACP PDUs
1695 1869 * to potentially restore the link.
1696 1870 *
1697 1871 * Finally, we explicitly don't do anything if the ring hasn't been enabled yet.
1698 1872 * This is to help out aggr which doesn't really know the internal state that
1699 1873 * MAC does about the rings and can't know that it's not quite ready for use
1700 1874 * yet.
1701 1875 */
1702 1876 void
1703 1877 mac_hwring_set_default(mac_handle_t mh, mac_ring_handle_t rh)
1704 1878 {
1705 1879 mac_impl_t *mip = (mac_impl_t *)mh;
1706 1880 mac_ring_t *ring = (mac_ring_t *)rh;
1707 1881
1708 1882 ASSERT(MAC_PERIM_HELD(mh));
1709 1883 VERIFY(mip->mi_state_flags & MIS_IS_AGGR);
1710 1884
1711 1885 if (ring->mr_state != MR_INUSE)
1712 1886 return;
1713 1887
1714 1888 mip->mi_default_tx_ring = rh;
1715 1889 }
1716 1890
1717 1891 int
1718 1892 mac_hwgroup_addmac(mac_group_handle_t gh, const uint8_t *addr)
1719 1893 {
1720 1894 mac_group_t *group = (mac_group_t *)gh;
1721 1895
1722 1896 return (mac_group_addmac(group, addr));
1723 1897 }
1724 1898
1725 1899 int
1726 1900 mac_hwgroup_remmac(mac_group_handle_t gh, const uint8_t *addr)
1727 1901 {
1728 1902 mac_group_t *group = (mac_group_t *)gh;
1729 1903
1730 1904 return (mac_group_remmac(group, addr));
1731 1905 }
1732 1906
1733 1907 /*
1734 1908 * Program the group's HW VLAN filter if it has such support.
1735 1909 * Otherwise, the group will implicitly accept tagged traffic and
1736 1910 * there is nothing to do.
1737 1911 */
1738 1912 int
1739 1913 mac_hwgroup_addvlan(mac_group_handle_t gh, uint16_t vid)
1740 1914 {
1741 1915 mac_group_t *group = (mac_group_t *)gh;
1742 1916
1743 1917 if (!MAC_GROUP_HW_VLAN(group))
1744 1918 return (0);
1745 1919
1746 1920 return (mac_group_addvlan(group, vid));
1747 1921 }
1748 1922
1749 1923 int
1750 1924 mac_hwgroup_remvlan(mac_group_handle_t gh, uint16_t vid)
1751 1925 {
1752 1926 mac_group_t *group = (mac_group_t *)gh;
1753 1927
1754 1928 if (!MAC_GROUP_HW_VLAN(group))
1755 1929 return (0);
1756 1930
1757 1931 return (mac_group_remvlan(group, vid));
1758 1932 }
1759 1933
1760 1934 /*
1761 1935 * Determine if a MAC has HW VLAN support. This is a private API
1762 1936 * consumed by aggr. In the future it might be nice to have a bitfield
1763 1937 * in mac_capab_rings_t to track which forms of HW filtering are
1764 1938 * supported by the MAC.
↓ open down ↓ |
127 lines elided |
↑ open up ↑ |
1765 1939 */
1766 1940 boolean_t
1767 1941 mac_has_hw_vlan(mac_handle_t mh)
1768 1942 {
1769 1943 mac_impl_t *mip = (mac_impl_t *)mh;
1770 1944
1771 1945 return (MAC_GROUP_HW_VLAN(mip->mi_rx_groups));
1772 1946 }
1773 1947
1774 1948 /*
1949 + * Get the number of Rx HW groups on this MAC.
1950 + */
1951 +uint_t
1952 +mac_get_num_rx_groups(mac_handle_t mh)
1953 +{
1954 + mac_impl_t *mip = (mac_impl_t *)mh;
1955 +
1956 + ASSERT(MAC_PERIM_HELD(mh));
1957 + return (mip->mi_rx_group_count);
1958 +}
1959 +
1960 +int
1961 +mac_set_promisc(mac_handle_t mh, boolean_t value)
1962 +{
1963 + mac_impl_t *mip = (mac_impl_t *)mh;
1964 +
1965 + ASSERT(MAC_PERIM_HELD(mh));
1966 + return (i_mac_promisc_set(mip, value));
1967 +}
1968 +
1969 +/*
1775 1970 * Set the RX group to be shared/reserved. Note that the group must be
1776 1971 * started/stopped outside of this function.
1777 1972 */
1778 1973 void
1779 1974 mac_set_group_state(mac_group_t *grp, mac_group_state_t state)
1780 1975 {
1781 1976 /*
1782 1977 * If there is no change in the group state, just return.
1783 1978 */
1784 1979 if (grp->mrg_state == state)
1785 1980 return;
1786 1981
1787 1982 switch (state) {
1788 1983 case MAC_GROUP_STATE_RESERVED:
1789 1984 /*
1790 1985 * Successfully reserved the group.
1791 1986 *
1792 1987 * Given that there is an exclusive client controlling this
1793 1988 * group, we enable the group level polling when available,
1794 1989 * so that SRSs get to turn on/off individual rings they's
1795 1990 * assigned to.
1796 1991 */
1797 1992 ASSERT(MAC_PERIM_HELD(grp->mrg_mh));
1798 1993
1799 1994 if (grp->mrg_type == MAC_RING_TYPE_RX &&
1800 1995 GROUP_INTR_DISABLE_FUNC(grp) != NULL) {
1801 1996 GROUP_INTR_DISABLE_FUNC(grp)(GROUP_INTR_HANDLE(grp));
1802 1997 }
1803 1998 break;
1804 1999
1805 2000 case MAC_GROUP_STATE_SHARED:
1806 2001 /*
1807 2002 * Set all rings of this group to software classified.
1808 2003 * If the group has an overriding interrupt, then re-enable it.
1809 2004 */
1810 2005 ASSERT(MAC_PERIM_HELD(grp->mrg_mh));
1811 2006
1812 2007 if (grp->mrg_type == MAC_RING_TYPE_RX &&
1813 2008 GROUP_INTR_ENABLE_FUNC(grp) != NULL) {
1814 2009 GROUP_INTR_ENABLE_FUNC(grp)(GROUP_INTR_HANDLE(grp));
1815 2010 }
1816 2011 /* The ring is not available for reservations any more */
1817 2012 break;
1818 2013
1819 2014 case MAC_GROUP_STATE_REGISTERED:
1820 2015 /* Also callable from mac_register, perim is not held */
1821 2016 break;
1822 2017
1823 2018 default:
1824 2019 ASSERT(B_FALSE);
1825 2020 break;
1826 2021 }
1827 2022
1828 2023 grp->mrg_state = state;
1829 2024 }
1830 2025
1831 2026 /*
1832 2027 * Quiesce future hardware classified packets for the specified Rx ring
1833 2028 */
1834 2029 static void
1835 2030 mac_rx_ring_quiesce(mac_ring_t *rx_ring, uint_t ring_flag)
1836 2031 {
1837 2032 ASSERT(rx_ring->mr_classify_type == MAC_HW_CLASSIFIER);
1838 2033 ASSERT(ring_flag == MR_CONDEMNED || ring_flag == MR_QUIESCE);
1839 2034
1840 2035 mutex_enter(&rx_ring->mr_lock);
1841 2036 rx_ring->mr_flag |= ring_flag;
1842 2037 while (rx_ring->mr_refcnt != 0)
1843 2038 cv_wait(&rx_ring->mr_cv, &rx_ring->mr_lock);
1844 2039 mutex_exit(&rx_ring->mr_lock);
1845 2040 }
1846 2041
1847 2042 /*
1848 2043 * Please see mac_tx for details about the per cpu locking scheme
1849 2044 */
1850 2045 static void
1851 2046 mac_tx_lock_all(mac_client_impl_t *mcip)
1852 2047 {
1853 2048 int i;
1854 2049
1855 2050 for (i = 0; i <= mac_tx_percpu_cnt; i++)
1856 2051 mutex_enter(&mcip->mci_tx_pcpu[i].pcpu_tx_lock);
1857 2052 }
1858 2053
1859 2054 static void
1860 2055 mac_tx_unlock_all(mac_client_impl_t *mcip)
1861 2056 {
1862 2057 int i;
1863 2058
1864 2059 for (i = mac_tx_percpu_cnt; i >= 0; i--)
1865 2060 mutex_exit(&mcip->mci_tx_pcpu[i].pcpu_tx_lock);
1866 2061 }
1867 2062
1868 2063 static void
1869 2064 mac_tx_unlock_allbutzero(mac_client_impl_t *mcip)
1870 2065 {
1871 2066 int i;
1872 2067
1873 2068 for (i = mac_tx_percpu_cnt; i > 0; i--)
1874 2069 mutex_exit(&mcip->mci_tx_pcpu[i].pcpu_tx_lock);
1875 2070 }
1876 2071
1877 2072 static int
1878 2073 mac_tx_sum_refcnt(mac_client_impl_t *mcip)
1879 2074 {
1880 2075 int i;
1881 2076 int refcnt = 0;
1882 2077
1883 2078 for (i = 0; i <= mac_tx_percpu_cnt; i++)
1884 2079 refcnt += mcip->mci_tx_pcpu[i].pcpu_tx_refcnt;
1885 2080
1886 2081 return (refcnt);
1887 2082 }
1888 2083
1889 2084 /*
1890 2085 * Stop future Tx packets coming down from the client in preparation for
1891 2086 * quiescing the Tx side. This is needed for dynamic reclaim and reassignment
1892 2087 * of rings between clients
1893 2088 */
1894 2089 void
1895 2090 mac_tx_client_block(mac_client_impl_t *mcip)
1896 2091 {
1897 2092 mac_tx_lock_all(mcip);
1898 2093 mcip->mci_tx_flag |= MCI_TX_QUIESCE;
1899 2094 while (mac_tx_sum_refcnt(mcip) != 0) {
1900 2095 mac_tx_unlock_allbutzero(mcip);
1901 2096 cv_wait(&mcip->mci_tx_cv, &mcip->mci_tx_pcpu[0].pcpu_tx_lock);
1902 2097 mutex_exit(&mcip->mci_tx_pcpu[0].pcpu_tx_lock);
1903 2098 mac_tx_lock_all(mcip);
1904 2099 }
1905 2100 mac_tx_unlock_all(mcip);
1906 2101 }
1907 2102
1908 2103 void
1909 2104 mac_tx_client_unblock(mac_client_impl_t *mcip)
1910 2105 {
1911 2106 mac_tx_lock_all(mcip);
1912 2107 mcip->mci_tx_flag &= ~MCI_TX_QUIESCE;
1913 2108 mac_tx_unlock_all(mcip);
1914 2109 /*
1915 2110 * We may fail to disable flow control for the last MAC_NOTE_TX
1916 2111 * notification because the MAC client is quiesced. Send the
1917 2112 * notification again.
1918 2113 */
1919 2114 i_mac_notify(mcip->mci_mip, MAC_NOTE_TX);
1920 2115 }
1921 2116
1922 2117 /*
1923 2118 * Wait for an SRS to quiesce. The SRS worker will signal us when the
1924 2119 * quiesce is done.
1925 2120 */
1926 2121 static void
1927 2122 mac_srs_quiesce_wait(mac_soft_ring_set_t *srs, uint_t srs_flag)
1928 2123 {
1929 2124 mutex_enter(&srs->srs_lock);
1930 2125 while (!(srs->srs_state & srs_flag))
1931 2126 cv_wait(&srs->srs_quiesce_done_cv, &srs->srs_lock);
1932 2127 mutex_exit(&srs->srs_lock);
1933 2128 }
1934 2129
1935 2130 /*
1936 2131 * Quiescing an Rx SRS is achieved by the following sequence. The protocol
1937 2132 * works bottom up by cutting off packet flow from the bottommost point in the
1938 2133 * mac, then the SRS, and then the soft rings. There are 2 use cases of this
1939 2134 * mechanism. One is a temporary quiesce of the SRS, such as say while changing
1940 2135 * the Rx callbacks. Another use case is Rx SRS teardown. In the former case
1941 2136 * the QUIESCE prefix/suffix is used and in the latter the CONDEMNED is used
1942 2137 * for the SRS and MR flags. In the former case the threads pause waiting for
1943 2138 * a restart, while in the latter case the threads exit. The Tx SRS teardown
1944 2139 * is also mostly similar to the above.
1945 2140 *
1946 2141 * 1. Stop future hardware classified packets at the lowest level in the mac.
1947 2142 * Remove any hardware classification rule (CONDEMNED case) and mark the
1948 2143 * rings as CONDEMNED or QUIESCE as appropriate. This prevents the mr_refcnt
1949 2144 * from increasing. Upcalls from the driver that come through hardware
1950 2145 * classification will be dropped in mac_rx from now on. Then we wait for
1951 2146 * the mr_refcnt to drop to zero. When the mr_refcnt reaches zero we are
1952 2147 * sure there aren't any upcall threads from the driver through hardware
1953 2148 * classification. In the case of SRS teardown we also remove the
1954 2149 * classification rule in the driver.
1955 2150 *
1956 2151 * 2. Stop future software classified packets by marking the flow entry with
1957 2152 * FE_QUIESCE or FE_CONDEMNED as appropriate which prevents the refcnt from
1958 2153 * increasing. We also remove the flow entry from the table in the latter
1959 2154 * case. Then wait for the fe_refcnt to reach an appropriate quiescent value
1960 2155 * that indicates there aren't any active threads using that flow entry.
1961 2156 *
1962 2157 * 3. Quiesce the SRS and softrings by signaling the SRS. The SRS poll thread,
1963 2158 * SRS worker thread, and the soft ring threads are quiesced in sequence
1964 2159 * with the SRS worker thread serving as a master controller. This
1965 2160 * mechansim is explained in mac_srs_worker_quiesce().
1966 2161 *
1967 2162 * The restart mechanism to reactivate the SRS and softrings is explained
1968 2163 * in mac_srs_worker_restart(). Here we just signal the SRS worker to start the
1969 2164 * restart sequence.
1970 2165 */
1971 2166 void
1972 2167 mac_rx_srs_quiesce(mac_soft_ring_set_t *srs, uint_t srs_quiesce_flag)
1973 2168 {
1974 2169 flow_entry_t *flent = srs->srs_flent;
1975 2170 uint_t mr_flag, srs_done_flag;
1976 2171
1977 2172 ASSERT(MAC_PERIM_HELD((mac_handle_t)FLENT_TO_MIP(flent)));
1978 2173 ASSERT(!(srs->srs_type & SRST_TX));
1979 2174
1980 2175 if (srs_quiesce_flag == SRS_CONDEMNED) {
1981 2176 mr_flag = MR_CONDEMNED;
1982 2177 srs_done_flag = SRS_CONDEMNED_DONE;
1983 2178 if (srs->srs_type & SRST_CLIENT_POLL_ENABLED)
1984 2179 mac_srs_client_poll_disable(srs->srs_mcip, srs);
1985 2180 } else {
1986 2181 ASSERT(srs_quiesce_flag == SRS_QUIESCE);
1987 2182 mr_flag = MR_QUIESCE;
1988 2183 srs_done_flag = SRS_QUIESCE_DONE;
1989 2184 if (srs->srs_type & SRST_CLIENT_POLL_ENABLED)
1990 2185 mac_srs_client_poll_quiesce(srs->srs_mcip, srs);
1991 2186 }
1992 2187
1993 2188 if (srs->srs_ring != NULL) {
1994 2189 mac_rx_ring_quiesce(srs->srs_ring, mr_flag);
1995 2190 } else {
1996 2191 /*
1997 2192 * SRS is driven by software classification. In case
1998 2193 * of CONDEMNED, the top level teardown functions will
1999 2194 * deal with flow removal.
2000 2195 */
2001 2196 if (srs_quiesce_flag != SRS_CONDEMNED) {
2002 2197 FLOW_MARK(flent, FE_QUIESCE);
2003 2198 mac_flow_wait(flent, FLOW_DRIVER_UPCALL);
2004 2199 }
2005 2200 }
2006 2201
2007 2202 /*
2008 2203 * Signal the SRS to quiesce itself, and then cv_wait for the
2009 2204 * SRS quiesce to complete. The SRS worker thread will wake us
2010 2205 * up when the quiesce is complete
2011 2206 */
2012 2207 mac_srs_signal(srs, srs_quiesce_flag);
2013 2208 mac_srs_quiesce_wait(srs, srs_done_flag);
2014 2209 }
2015 2210
2016 2211 /*
2017 2212 * Remove an SRS.
2018 2213 */
2019 2214 void
2020 2215 mac_rx_srs_remove(mac_soft_ring_set_t *srs)
2021 2216 {
2022 2217 flow_entry_t *flent = srs->srs_flent;
2023 2218 int i;
2024 2219
2025 2220 mac_rx_srs_quiesce(srs, SRS_CONDEMNED);
2026 2221 /*
2027 2222 * Locate and remove our entry in the fe_rx_srs[] array, and
2028 2223 * adjust the fe_rx_srs array entries and array count by
2029 2224 * moving the last entry into the vacated spot.
2030 2225 */
2031 2226 mutex_enter(&flent->fe_lock);
2032 2227 for (i = 0; i < flent->fe_rx_srs_cnt; i++) {
2033 2228 if (flent->fe_rx_srs[i] == srs)
2034 2229 break;
2035 2230 }
2036 2231
2037 2232 ASSERT(i != 0 && i < flent->fe_rx_srs_cnt);
2038 2233 if (i != flent->fe_rx_srs_cnt - 1) {
2039 2234 flent->fe_rx_srs[i] =
2040 2235 flent->fe_rx_srs[flent->fe_rx_srs_cnt - 1];
2041 2236 i = flent->fe_rx_srs_cnt - 1;
2042 2237 }
2043 2238
2044 2239 flent->fe_rx_srs[i] = NULL;
2045 2240 flent->fe_rx_srs_cnt--;
2046 2241 mutex_exit(&flent->fe_lock);
2047 2242
2048 2243 mac_srs_free(srs);
2049 2244 }
2050 2245
2051 2246 static void
2052 2247 mac_srs_clear_flag(mac_soft_ring_set_t *srs, uint_t flag)
2053 2248 {
2054 2249 mutex_enter(&srs->srs_lock);
2055 2250 srs->srs_state &= ~flag;
2056 2251 mutex_exit(&srs->srs_lock);
2057 2252 }
2058 2253
2059 2254 void
2060 2255 mac_rx_srs_restart(mac_soft_ring_set_t *srs)
2061 2256 {
2062 2257 flow_entry_t *flent = srs->srs_flent;
2063 2258 mac_ring_t *mr;
2064 2259
2065 2260 ASSERT(MAC_PERIM_HELD((mac_handle_t)FLENT_TO_MIP(flent)));
2066 2261 ASSERT((srs->srs_type & SRST_TX) == 0);
2067 2262
2068 2263 /*
2069 2264 * This handles a change in the number of SRSs between the quiesce and
2070 2265 * and restart operation of a flow.
2071 2266 */
2072 2267 if (!SRS_QUIESCED(srs))
2073 2268 return;
2074 2269
2075 2270 /*
2076 2271 * Signal the SRS to restart itself. Wait for the restart to complete
2077 2272 * Note that we only restart the SRS if it is not marked as
2078 2273 * permanently quiesced.
2079 2274 */
2080 2275 if (!SRS_QUIESCED_PERMANENT(srs)) {
2081 2276 mac_srs_signal(srs, SRS_RESTART);
2082 2277 mac_srs_quiesce_wait(srs, SRS_RESTART_DONE);
2083 2278 mac_srs_clear_flag(srs, SRS_RESTART_DONE);
2084 2279
2085 2280 mac_srs_client_poll_restart(srs->srs_mcip, srs);
2086 2281 }
2087 2282
2088 2283 /* Finally clear the flags to let the packets in */
2089 2284 mr = srs->srs_ring;
2090 2285 if (mr != NULL) {
2091 2286 MAC_RING_UNMARK(mr, MR_QUIESCE);
2092 2287 /* In case the ring was stopped, safely restart it */
2093 2288 if (mr->mr_state != MR_INUSE)
2094 2289 (void) mac_start_ring(mr);
2095 2290 } else {
2096 2291 FLOW_UNMARK(flent, FE_QUIESCE);
2097 2292 }
2098 2293 }
2099 2294
2100 2295 /*
2101 2296 * Temporary quiesce of a flow and associated Rx SRS.
2102 2297 * Please see block comment above mac_rx_classify_flow_rem.
2103 2298 */
2104 2299 /* ARGSUSED */
2105 2300 int
2106 2301 mac_rx_classify_flow_quiesce(flow_entry_t *flent, void *arg)
2107 2302 {
2108 2303 int i;
2109 2304
2110 2305 for (i = 0; i < flent->fe_rx_srs_cnt; i++) {
2111 2306 mac_rx_srs_quiesce((mac_soft_ring_set_t *)flent->fe_rx_srs[i],
2112 2307 SRS_QUIESCE);
2113 2308 }
2114 2309 return (0);
2115 2310 }
2116 2311
2117 2312 /*
2118 2313 * Restart a flow and associated Rx SRS that has been quiesced temporarily
2119 2314 * Please see block comment above mac_rx_classify_flow_rem
2120 2315 */
2121 2316 /* ARGSUSED */
2122 2317 int
2123 2318 mac_rx_classify_flow_restart(flow_entry_t *flent, void *arg)
2124 2319 {
2125 2320 int i;
2126 2321
2127 2322 for (i = 0; i < flent->fe_rx_srs_cnt; i++)
2128 2323 mac_rx_srs_restart((mac_soft_ring_set_t *)flent->fe_rx_srs[i]);
2129 2324
2130 2325 return (0);
2131 2326 }
2132 2327
2133 2328 void
2134 2329 mac_srs_perm_quiesce(mac_client_handle_t mch, boolean_t on)
2135 2330 {
2136 2331 mac_client_impl_t *mcip = (mac_client_impl_t *)mch;
2137 2332 flow_entry_t *flent = mcip->mci_flent;
2138 2333 mac_impl_t *mip = mcip->mci_mip;
2139 2334 mac_soft_ring_set_t *mac_srs;
2140 2335 int i;
2141 2336
2142 2337 ASSERT(MAC_PERIM_HELD((mac_handle_t)mip));
2143 2338
2144 2339 if (flent == NULL)
2145 2340 return;
2146 2341
2147 2342 for (i = 0; i < flent->fe_rx_srs_cnt; i++) {
2148 2343 mac_srs = flent->fe_rx_srs[i];
2149 2344 mutex_enter(&mac_srs->srs_lock);
2150 2345 if (on)
2151 2346 mac_srs->srs_state |= SRS_QUIESCE_PERM;
2152 2347 else
2153 2348 mac_srs->srs_state &= ~SRS_QUIESCE_PERM;
2154 2349 mutex_exit(&mac_srs->srs_lock);
2155 2350 }
2156 2351 }
2157 2352
2158 2353 void
2159 2354 mac_rx_client_quiesce(mac_client_handle_t mch)
2160 2355 {
2161 2356 mac_client_impl_t *mcip = (mac_client_impl_t *)mch;
2162 2357 mac_impl_t *mip = mcip->mci_mip;
2163 2358
2164 2359 ASSERT(MAC_PERIM_HELD((mac_handle_t)mip));
2165 2360
2166 2361 if (MCIP_DATAPATH_SETUP(mcip)) {
2167 2362 (void) mac_rx_classify_flow_quiesce(mcip->mci_flent,
2168 2363 NULL);
2169 2364 (void) mac_flow_walk_nolock(mcip->mci_subflow_tab,
2170 2365 mac_rx_classify_flow_quiesce, NULL);
2171 2366 }
2172 2367 }
2173 2368
2174 2369 void
2175 2370 mac_rx_client_restart(mac_client_handle_t mch)
2176 2371 {
2177 2372 mac_client_impl_t *mcip = (mac_client_impl_t *)mch;
2178 2373 mac_impl_t *mip = mcip->mci_mip;
2179 2374
2180 2375 ASSERT(MAC_PERIM_HELD((mac_handle_t)mip));
2181 2376
2182 2377 if (MCIP_DATAPATH_SETUP(mcip)) {
2183 2378 (void) mac_rx_classify_flow_restart(mcip->mci_flent, NULL);
2184 2379 (void) mac_flow_walk_nolock(mcip->mci_subflow_tab,
2185 2380 mac_rx_classify_flow_restart, NULL);
2186 2381 }
2187 2382 }
2188 2383
2189 2384 /*
2190 2385 * This function only quiesces the Tx SRS and softring worker threads. Callers
2191 2386 * need to make sure that there aren't any mac client threads doing current or
2192 2387 * future transmits in the mac before calling this function.
2193 2388 */
2194 2389 void
2195 2390 mac_tx_srs_quiesce(mac_soft_ring_set_t *srs, uint_t srs_quiesce_flag)
2196 2391 {
2197 2392 mac_client_impl_t *mcip = srs->srs_mcip;
2198 2393
2199 2394 ASSERT(MAC_PERIM_HELD((mac_handle_t)mcip->mci_mip));
2200 2395
2201 2396 ASSERT(srs->srs_type & SRST_TX);
2202 2397 ASSERT(srs_quiesce_flag == SRS_CONDEMNED ||
2203 2398 srs_quiesce_flag == SRS_QUIESCE);
2204 2399
2205 2400 /*
2206 2401 * Signal the SRS to quiesce itself, and then cv_wait for the
2207 2402 * SRS quiesce to complete. The SRS worker thread will wake us
2208 2403 * up when the quiesce is complete
2209 2404 */
2210 2405 mac_srs_signal(srs, srs_quiesce_flag);
2211 2406 mac_srs_quiesce_wait(srs, srs_quiesce_flag == SRS_QUIESCE ?
2212 2407 SRS_QUIESCE_DONE : SRS_CONDEMNED_DONE);
2213 2408 }
2214 2409
2215 2410 void
2216 2411 mac_tx_srs_restart(mac_soft_ring_set_t *srs)
2217 2412 {
2218 2413 /*
2219 2414 * Resizing the fanout could result in creation of new SRSs.
2220 2415 * They may not necessarily be in the quiesced state in which
2221 2416 * case it need be restarted
2222 2417 */
2223 2418 if (!SRS_QUIESCED(srs))
2224 2419 return;
2225 2420
2226 2421 mac_srs_signal(srs, SRS_RESTART);
2227 2422 mac_srs_quiesce_wait(srs, SRS_RESTART_DONE);
2228 2423 mac_srs_clear_flag(srs, SRS_RESTART_DONE);
2229 2424 }
2230 2425
2231 2426 /*
2232 2427 * Temporary quiesce of a flow and associated Rx SRS.
2233 2428 * Please see block comment above mac_rx_srs_quiesce
2234 2429 */
2235 2430 /* ARGSUSED */
2236 2431 int
2237 2432 mac_tx_flow_quiesce(flow_entry_t *flent, void *arg)
2238 2433 {
2239 2434 /*
2240 2435 * The fe_tx_srs is null for a subflow on an interface that is
2241 2436 * not plumbed
2242 2437 */
2243 2438 if (flent->fe_tx_srs != NULL)
2244 2439 mac_tx_srs_quiesce(flent->fe_tx_srs, SRS_QUIESCE);
2245 2440 return (0);
2246 2441 }
2247 2442
2248 2443 /* ARGSUSED */
2249 2444 int
2250 2445 mac_tx_flow_restart(flow_entry_t *flent, void *arg)
2251 2446 {
2252 2447 /*
2253 2448 * The fe_tx_srs is null for a subflow on an interface that is
2254 2449 * not plumbed
2255 2450 */
2256 2451 if (flent->fe_tx_srs != NULL)
2257 2452 mac_tx_srs_restart(flent->fe_tx_srs);
2258 2453 return (0);
2259 2454 }
2260 2455
2261 2456 static void
2262 2457 i_mac_tx_client_quiesce(mac_client_handle_t mch, uint_t srs_quiesce_flag)
2263 2458 {
2264 2459 mac_client_impl_t *mcip = (mac_client_impl_t *)mch;
2265 2460
2266 2461 ASSERT(MAC_PERIM_HELD((mac_handle_t)mcip->mci_mip));
2267 2462
2268 2463 mac_tx_client_block(mcip);
2269 2464 if (MCIP_TX_SRS(mcip) != NULL) {
2270 2465 mac_tx_srs_quiesce(MCIP_TX_SRS(mcip), srs_quiesce_flag);
2271 2466 (void) mac_flow_walk_nolock(mcip->mci_subflow_tab,
2272 2467 mac_tx_flow_quiesce, NULL);
2273 2468 }
2274 2469 }
2275 2470
2276 2471 void
2277 2472 mac_tx_client_quiesce(mac_client_handle_t mch)
2278 2473 {
2279 2474 i_mac_tx_client_quiesce(mch, SRS_QUIESCE);
2280 2475 }
2281 2476
2282 2477 void
2283 2478 mac_tx_client_condemn(mac_client_handle_t mch)
2284 2479 {
2285 2480 i_mac_tx_client_quiesce(mch, SRS_CONDEMNED);
2286 2481 }
2287 2482
2288 2483 void
2289 2484 mac_tx_client_restart(mac_client_handle_t mch)
2290 2485 {
2291 2486 mac_client_impl_t *mcip = (mac_client_impl_t *)mch;
2292 2487
2293 2488 ASSERT(MAC_PERIM_HELD((mac_handle_t)mcip->mci_mip));
2294 2489
2295 2490 mac_tx_client_unblock(mcip);
2296 2491 if (MCIP_TX_SRS(mcip) != NULL) {
2297 2492 mac_tx_srs_restart(MCIP_TX_SRS(mcip));
2298 2493 (void) mac_flow_walk_nolock(mcip->mci_subflow_tab,
2299 2494 mac_tx_flow_restart, NULL);
2300 2495 }
2301 2496 }
2302 2497
2303 2498 void
2304 2499 mac_tx_client_flush(mac_client_impl_t *mcip)
2305 2500 {
2306 2501 ASSERT(MAC_PERIM_HELD((mac_handle_t)mcip->mci_mip));
2307 2502
2308 2503 mac_tx_client_quiesce((mac_client_handle_t)mcip);
2309 2504 mac_tx_client_restart((mac_client_handle_t)mcip);
2310 2505 }
2311 2506
2312 2507 void
2313 2508 mac_client_quiesce(mac_client_impl_t *mcip)
2314 2509 {
2315 2510 mac_rx_client_quiesce((mac_client_handle_t)mcip);
2316 2511 mac_tx_client_quiesce((mac_client_handle_t)mcip);
2317 2512 }
2318 2513
2319 2514 void
2320 2515 mac_client_restart(mac_client_impl_t *mcip)
2321 2516 {
2322 2517 mac_rx_client_restart((mac_client_handle_t)mcip);
2323 2518 mac_tx_client_restart((mac_client_handle_t)mcip);
2324 2519 }
2325 2520
2326 2521 /*
2327 2522 * Allocate a minor number.
2328 2523 */
2329 2524 minor_t
2330 2525 mac_minor_hold(boolean_t sleep)
2331 2526 {
2332 2527 id_t id;
2333 2528
2334 2529 /*
2335 2530 * Grab a value from the arena.
2336 2531 */
2337 2532 atomic_inc_32(&minor_count);
2338 2533
2339 2534 if (sleep)
2340 2535 return ((uint_t)id_alloc(minor_ids));
2341 2536
2342 2537 if ((id = id_alloc_nosleep(minor_ids)) == -1) {
2343 2538 atomic_dec_32(&minor_count);
2344 2539 return (0);
2345 2540 }
2346 2541
2347 2542 return ((uint_t)id);
2348 2543 }
2349 2544
2350 2545 /*
2351 2546 * Release a previously allocated minor number.
2352 2547 */
2353 2548 void
2354 2549 mac_minor_rele(minor_t minor)
2355 2550 {
2356 2551 /*
2357 2552 * Return the value to the arena.
2358 2553 */
2359 2554 id_free(minor_ids, minor);
2360 2555 atomic_dec_32(&minor_count);
2361 2556 }
2362 2557
2363 2558 uint32_t
2364 2559 mac_no_notification(mac_handle_t mh)
2365 2560 {
2366 2561 mac_impl_t *mip = (mac_impl_t *)mh;
2367 2562
2368 2563 return (((mip->mi_state_flags & MIS_LEGACY) != 0) ?
2369 2564 mip->mi_capab_legacy.ml_unsup_note : 0);
2370 2565 }
2371 2566
2372 2567 /*
2373 2568 * Prevent any new opens of this mac in preparation for unregister
2374 2569 */
2375 2570 int
2376 2571 i_mac_disable(mac_impl_t *mip)
2377 2572 {
2378 2573 mac_client_impl_t *mcip;
2379 2574
2380 2575 rw_enter(&i_mac_impl_lock, RW_WRITER);
2381 2576 if (mip->mi_state_flags & MIS_DISABLED) {
2382 2577 /* Already disabled, return success */
2383 2578 rw_exit(&i_mac_impl_lock);
2384 2579 return (0);
2385 2580 }
2386 2581 /*
2387 2582 * See if there are any other references to this mac_t (e.g., VLAN's).
2388 2583 * If so return failure. If all the other checks below pass, then
2389 2584 * set mi_disabled atomically under the i_mac_impl_lock to prevent
2390 2585 * any new VLAN's from being created or new mac client opens of this
2391 2586 * mac end point.
2392 2587 */
2393 2588 if (mip->mi_ref > 0) {
2394 2589 rw_exit(&i_mac_impl_lock);
2395 2590 return (EBUSY);
2396 2591 }
2397 2592
2398 2593 /*
2399 2594 * mac clients must delete all multicast groups they join before
2400 2595 * closing. bcast groups are reference counted, the last client
2401 2596 * to delete the group will wait till the group is physically
2402 2597 * deleted. Since all clients have closed this mac end point
2403 2598 * mi_bcast_ngrps must be zero at this point
2404 2599 */
2405 2600 ASSERT(mip->mi_bcast_ngrps == 0);
2406 2601
2407 2602 /*
2408 2603 * Don't let go of this if it has some flows.
2409 2604 * All other code guarantees no flows are added to a disabled
2410 2605 * mac, therefore it is sufficient to check for the flow table
2411 2606 * only here.
2412 2607 */
2413 2608 mcip = mac_primary_client_handle(mip);
2414 2609 if ((mcip != NULL) && mac_link_has_flows((mac_client_handle_t)mcip)) {
2415 2610 rw_exit(&i_mac_impl_lock);
2416 2611 return (ENOTEMPTY);
2417 2612 }
2418 2613
2419 2614 mip->mi_state_flags |= MIS_DISABLED;
2420 2615 rw_exit(&i_mac_impl_lock);
2421 2616 return (0);
2422 2617 }
2423 2618
2424 2619 int
2425 2620 mac_disable_nowait(mac_handle_t mh)
2426 2621 {
2427 2622 mac_impl_t *mip = (mac_impl_t *)mh;
2428 2623 int err;
2429 2624
2430 2625 if ((err = i_mac_perim_enter_nowait(mip)) != 0)
2431 2626 return (err);
2432 2627 err = i_mac_disable(mip);
2433 2628 i_mac_perim_exit(mip);
2434 2629 return (err);
2435 2630 }
2436 2631
2437 2632 int
2438 2633 mac_disable(mac_handle_t mh)
2439 2634 {
2440 2635 mac_impl_t *mip = (mac_impl_t *)mh;
2441 2636 int err;
2442 2637
2443 2638 i_mac_perim_enter(mip);
2444 2639 err = i_mac_disable(mip);
2445 2640 i_mac_perim_exit(mip);
2446 2641
2447 2642 /*
2448 2643 * Clean up notification thread and wait for it to exit.
2449 2644 */
2450 2645 if (err == 0)
2451 2646 i_mac_notify_exit(mip);
2452 2647
2453 2648 return (err);
2454 2649 }
2455 2650
2456 2651 /*
2457 2652 * Called when the MAC instance has a non empty flow table, to de-multiplex
↓ open down ↓ |
673 lines elided |
↑ open up ↑ |
2458 2653 * incoming packets to the right flow.
2459 2654 */
2460 2655 /* ARGSUSED */
2461 2656 static mblk_t *
2462 2657 mac_rx_classify(mac_impl_t *mip, mac_resource_handle_t mrh, mblk_t *mp)
2463 2658 {
2464 2659 flow_entry_t *flent = NULL;
2465 2660 uint_t flags = FLOW_INBOUND;
2466 2661 int err;
2467 2662
2468 - /*
2469 - * If the MAC is a port of an aggregation, pass FLOW_IGNORE_VLAN
2470 - * to mac_flow_lookup() so that the VLAN packets can be successfully
2471 - * passed to the non-VLAN aggregation flows.
2472 - *
2473 - * Note that there is possibly a race between this and
2474 - * mac_unicast_remove/add() and VLAN packets could be incorrectly
2475 - * classified to non-VLAN flows of non-aggregation MAC clients. These
2476 - * VLAN packets will be then filtered out by the MAC module.
2477 - */
2478 - if ((mip->mi_state_flags & MIS_EXCLUSIVE) != 0)
2479 - flags |= FLOW_IGNORE_VLAN;
2480 -
2481 2663 err = mac_flow_lookup(mip->mi_flow_tab, mp, flags, &flent);
2482 2664 if (err != 0) {
2483 2665 /* no registered receive function */
2484 2666 return (mp);
2485 2667 } else {
2486 2668 mac_client_impl_t *mcip;
2487 2669
2488 2670 /*
2489 2671 * This flent might just be an additional one on the MAC client,
2490 2672 * i.e. for classification purposes (different fdesc), however
2491 2673 * the resources, SRS et. al., are in the mci_flent, so if
2492 2674 * this isn't the mci_flent, we need to get it.
2493 2675 */
2494 2676 if ((mcip = flent->fe_mcip) != NULL &&
2495 2677 mcip->mci_flent != flent) {
2496 2678 FLOW_REFRELE(flent);
2497 2679 flent = mcip->mci_flent;
2498 2680 FLOW_TRY_REFHOLD(flent, err);
2499 2681 if (err != 0)
2500 2682 return (mp);
2501 2683 }
2502 2684 (flent->fe_cb_fn)(flent->fe_cb_arg1, flent->fe_cb_arg2, mp,
2503 2685 B_FALSE);
2504 2686 FLOW_REFRELE(flent);
2505 2687 }
2506 2688 return (NULL);
2507 2689 }
2508 2690
2509 2691 mblk_t *
2510 2692 mac_rx_flow(mac_handle_t mh, mac_resource_handle_t mrh, mblk_t *mp_chain)
2511 2693 {
2512 2694 mac_impl_t *mip = (mac_impl_t *)mh;
2513 2695 mblk_t *bp, *bp1, **bpp, *list = NULL;
2514 2696
2515 2697 /*
2516 2698 * We walk the chain and attempt to classify each packet.
2517 2699 * The packets that couldn't be classified will be returned
2518 2700 * back to the caller.
2519 2701 */
2520 2702 bp = mp_chain;
2521 2703 bpp = &list;
2522 2704 while (bp != NULL) {
2523 2705 bp1 = bp;
2524 2706 bp = bp->b_next;
2525 2707 bp1->b_next = NULL;
2526 2708
2527 2709 if (mac_rx_classify(mip, mrh, bp1) != NULL) {
2528 2710 *bpp = bp1;
2529 2711 bpp = &bp1->b_next;
2530 2712 }
2531 2713 }
2532 2714 return (list);
2533 2715 }
2534 2716
2535 2717 static int
2536 2718 mac_tx_flow_srs_wakeup(flow_entry_t *flent, void *arg)
2537 2719 {
2538 2720 mac_ring_handle_t ring = arg;
2539 2721
2540 2722 if (flent->fe_tx_srs)
2541 2723 mac_tx_srs_wakeup(flent->fe_tx_srs, ring);
2542 2724 return (0);
2543 2725 }
2544 2726
2545 2727 void
2546 2728 i_mac_tx_srs_notify(mac_impl_t *mip, mac_ring_handle_t ring)
2547 2729 {
2548 2730 mac_client_impl_t *cclient;
2549 2731 mac_soft_ring_set_t *mac_srs;
2550 2732
2551 2733 /*
2552 2734 * After grabbing the mi_rw_lock, the list of clients can't change.
2553 2735 * If there are any clients mi_disabled must be B_FALSE and can't
2554 2736 * get set since there are clients. If there aren't any clients we
2555 2737 * don't do anything. In any case the mip has to be valid. The driver
2556 2738 * must make sure that it goes single threaded (with respect to mac
2557 2739 * calls) and wait for all pending mac calls to finish before calling
2558 2740 * mac_unregister.
2559 2741 */
2560 2742 rw_enter(&i_mac_impl_lock, RW_READER);
2561 2743 if (mip->mi_state_flags & MIS_DISABLED) {
2562 2744 rw_exit(&i_mac_impl_lock);
2563 2745 return;
2564 2746 }
2565 2747
2566 2748 /*
2567 2749 * Get MAC tx srs from walking mac_client_handle list.
2568 2750 */
2569 2751 rw_enter(&mip->mi_rw_lock, RW_READER);
2570 2752 for (cclient = mip->mi_clients_list; cclient != NULL;
2571 2753 cclient = cclient->mci_client_next) {
2572 2754 if ((mac_srs = MCIP_TX_SRS(cclient)) != NULL) {
2573 2755 mac_tx_srs_wakeup(mac_srs, ring);
2574 2756 } else {
2575 2757 /*
2576 2758 * Aggr opens underlying ports in exclusive mode
2577 2759 * and registers flow control callbacks using
2578 2760 * mac_tx_client_notify(). When opened in
2579 2761 * exclusive mode, Tx SRS won't be created
2580 2762 * during mac_unicast_add().
2581 2763 */
2582 2764 if (cclient->mci_state_flags & MCIS_EXCLUSIVE) {
2583 2765 mac_tx_invoke_callbacks(cclient,
2584 2766 (mac_tx_cookie_t)ring);
2585 2767 }
2586 2768 }
2587 2769 (void) mac_flow_walk(cclient->mci_subflow_tab,
2588 2770 mac_tx_flow_srs_wakeup, ring);
2589 2771 }
2590 2772 rw_exit(&mip->mi_rw_lock);
2591 2773 rw_exit(&i_mac_impl_lock);
2592 2774 }
2593 2775
2594 2776 /* ARGSUSED */
2595 2777 void
2596 2778 mac_multicast_refresh(mac_handle_t mh, mac_multicst_t refresh, void *arg,
2597 2779 boolean_t add)
2598 2780 {
2599 2781 mac_impl_t *mip = (mac_impl_t *)mh;
2600 2782
2601 2783 i_mac_perim_enter((mac_impl_t *)mh);
2602 2784 /*
2603 2785 * If no specific refresh function was given then default to the
2604 2786 * driver's m_multicst entry point.
2605 2787 */
2606 2788 if (refresh == NULL) {
2607 2789 refresh = mip->mi_multicst;
2608 2790 arg = mip->mi_driver;
2609 2791 }
2610 2792
2611 2793 mac_bcast_refresh(mip, refresh, arg, add);
2612 2794 i_mac_perim_exit((mac_impl_t *)mh);
2613 2795 }
2614 2796
2615 2797 void
2616 2798 mac_promisc_refresh(mac_handle_t mh, mac_setpromisc_t refresh, void *arg)
2617 2799 {
2618 2800 mac_impl_t *mip = (mac_impl_t *)mh;
2619 2801
2620 2802 /*
2621 2803 * If no specific refresh function was given then default to the
2622 2804 * driver's m_promisc entry point.
2623 2805 */
2624 2806 if (refresh == NULL) {
2625 2807 refresh = mip->mi_setpromisc;
2626 2808 arg = mip->mi_driver;
2627 2809 }
2628 2810 ASSERT(refresh != NULL);
2629 2811
2630 2812 /*
2631 2813 * Call the refresh function with the current promiscuity.
2632 2814 */
2633 2815 refresh(arg, (mip->mi_devpromisc != 0));
2634 2816 }
2635 2817
2636 2818 /*
2637 2819 * The mac client requests that the mac not to change its margin size to
2638 2820 * be less than the specified value. If "current" is B_TRUE, then the client
2639 2821 * requests the mac not to change its margin size to be smaller than the
2640 2822 * current size. Further, return the current margin size value in this case.
2641 2823 *
2642 2824 * We keep every requested size in an ordered list from largest to smallest.
2643 2825 */
2644 2826 int
2645 2827 mac_margin_add(mac_handle_t mh, uint32_t *marginp, boolean_t current)
2646 2828 {
2647 2829 mac_impl_t *mip = (mac_impl_t *)mh;
2648 2830 mac_margin_req_t **pp, *p;
2649 2831 int err = 0;
2650 2832
2651 2833 rw_enter(&(mip->mi_rw_lock), RW_WRITER);
2652 2834 if (current)
2653 2835 *marginp = mip->mi_margin;
2654 2836
2655 2837 /*
2656 2838 * If the current margin value cannot satisfy the margin requested,
2657 2839 * return ENOTSUP directly.
2658 2840 */
2659 2841 if (*marginp > mip->mi_margin) {
2660 2842 err = ENOTSUP;
2661 2843 goto done;
2662 2844 }
2663 2845
2664 2846 /*
2665 2847 * Check whether the given margin is already in the list. If so,
2666 2848 * bump the reference count.
2667 2849 */
2668 2850 for (pp = &mip->mi_mmrp; (p = *pp) != NULL; pp = &p->mmr_nextp) {
2669 2851 if (p->mmr_margin == *marginp) {
2670 2852 /*
2671 2853 * The margin requested is already in the list,
2672 2854 * so just bump the reference count.
2673 2855 */
2674 2856 p->mmr_ref++;
2675 2857 goto done;
2676 2858 }
2677 2859 if (p->mmr_margin < *marginp)
2678 2860 break;
2679 2861 }
2680 2862
2681 2863
2682 2864 p = kmem_zalloc(sizeof (mac_margin_req_t), KM_SLEEP);
2683 2865 p->mmr_margin = *marginp;
2684 2866 p->mmr_ref++;
2685 2867 p->mmr_nextp = *pp;
2686 2868 *pp = p;
2687 2869
2688 2870 done:
2689 2871 rw_exit(&(mip->mi_rw_lock));
2690 2872 return (err);
2691 2873 }
2692 2874
2693 2875 /*
2694 2876 * The mac client requests to cancel its previous mac_margin_add() request.
2695 2877 * We remove the requested margin size from the list.
2696 2878 */
2697 2879 int
2698 2880 mac_margin_remove(mac_handle_t mh, uint32_t margin)
2699 2881 {
2700 2882 mac_impl_t *mip = (mac_impl_t *)mh;
2701 2883 mac_margin_req_t **pp, *p;
2702 2884 int err = 0;
2703 2885
2704 2886 rw_enter(&(mip->mi_rw_lock), RW_WRITER);
2705 2887 /*
2706 2888 * Find the entry in the list for the given margin.
2707 2889 */
2708 2890 for (pp = &(mip->mi_mmrp); (p = *pp) != NULL; pp = &(p->mmr_nextp)) {
2709 2891 if (p->mmr_margin == margin) {
2710 2892 if (--p->mmr_ref == 0)
2711 2893 break;
2712 2894
2713 2895 /*
2714 2896 * There is still a reference to this address so
2715 2897 * there's nothing more to do.
2716 2898 */
2717 2899 goto done;
2718 2900 }
2719 2901 }
2720 2902
2721 2903 /*
2722 2904 * We did not find an entry for the given margin.
2723 2905 */
2724 2906 if (p == NULL) {
2725 2907 err = ENOENT;
2726 2908 goto done;
2727 2909 }
2728 2910
2729 2911 ASSERT(p->mmr_ref == 0);
2730 2912
2731 2913 /*
2732 2914 * Remove it from the list.
2733 2915 */
2734 2916 *pp = p->mmr_nextp;
2735 2917 kmem_free(p, sizeof (mac_margin_req_t));
2736 2918 done:
2737 2919 rw_exit(&(mip->mi_rw_lock));
2738 2920 return (err);
2739 2921 }
2740 2922
2741 2923 boolean_t
2742 2924 mac_margin_update(mac_handle_t mh, uint32_t margin)
2743 2925 {
2744 2926 mac_impl_t *mip = (mac_impl_t *)mh;
2745 2927 uint32_t margin_needed = 0;
2746 2928
2747 2929 rw_enter(&(mip->mi_rw_lock), RW_WRITER);
2748 2930
2749 2931 if (mip->mi_mmrp != NULL)
2750 2932 margin_needed = mip->mi_mmrp->mmr_margin;
2751 2933
2752 2934 if (margin_needed <= margin)
2753 2935 mip->mi_margin = margin;
2754 2936
2755 2937 rw_exit(&(mip->mi_rw_lock));
2756 2938
2757 2939 if (margin_needed <= margin)
2758 2940 i_mac_notify(mip, MAC_NOTE_MARGIN);
2759 2941
2760 2942 return (margin_needed <= margin);
2761 2943 }
2762 2944
2763 2945 /*
2764 2946 * MAC clients use this interface to request that a MAC device not change its
2765 2947 * MTU below the specified amount. At this time, that amount must be within the
2766 2948 * range of the device's current minimum and the device's current maximum. eg. a
2767 2949 * client cannot request a 3000 byte MTU when the device's MTU is currently
2768 2950 * 2000.
2769 2951 *
2770 2952 * If "current" is set to B_TRUE, then the request is to simply to reserve the
2771 2953 * current underlying mac's maximum for this mac client and return it in mtup.
2772 2954 */
2773 2955 int
2774 2956 mac_mtu_add(mac_handle_t mh, uint32_t *mtup, boolean_t current)
2775 2957 {
2776 2958 mac_impl_t *mip = (mac_impl_t *)mh;
2777 2959 mac_mtu_req_t *prev, *cur;
2778 2960 mac_propval_range_t mpr;
2779 2961 int err;
2780 2962
2781 2963 i_mac_perim_enter(mip);
2782 2964 rw_enter(&mip->mi_rw_lock, RW_WRITER);
2783 2965
2784 2966 if (current == B_TRUE)
2785 2967 *mtup = mip->mi_sdu_max;
2786 2968 mpr.mpr_count = 1;
2787 2969 err = mac_prop_info(mh, MAC_PROP_MTU, "mtu", NULL, 0, &mpr, NULL);
2788 2970 if (err != 0) {
2789 2971 rw_exit(&mip->mi_rw_lock);
2790 2972 i_mac_perim_exit(mip);
2791 2973 return (err);
2792 2974 }
2793 2975
2794 2976 if (*mtup > mip->mi_sdu_max ||
2795 2977 *mtup < mpr.mpr_range_uint32[0].mpur_min) {
2796 2978 rw_exit(&mip->mi_rw_lock);
2797 2979 i_mac_perim_exit(mip);
2798 2980 return (ENOTSUP);
2799 2981 }
2800 2982
2801 2983 prev = NULL;
2802 2984 for (cur = mip->mi_mtrp; cur != NULL; cur = cur->mtr_nextp) {
2803 2985 if (*mtup == cur->mtr_mtu) {
2804 2986 cur->mtr_ref++;
2805 2987 rw_exit(&mip->mi_rw_lock);
2806 2988 i_mac_perim_exit(mip);
2807 2989 return (0);
2808 2990 }
2809 2991
2810 2992 if (*mtup > cur->mtr_mtu)
2811 2993 break;
2812 2994
2813 2995 prev = cur;
2814 2996 }
2815 2997
2816 2998 cur = kmem_alloc(sizeof (mac_mtu_req_t), KM_SLEEP);
2817 2999 cur->mtr_mtu = *mtup;
2818 3000 cur->mtr_ref = 1;
2819 3001 if (prev != NULL) {
2820 3002 cur->mtr_nextp = prev->mtr_nextp;
2821 3003 prev->mtr_nextp = cur;
2822 3004 } else {
2823 3005 cur->mtr_nextp = mip->mi_mtrp;
2824 3006 mip->mi_mtrp = cur;
2825 3007 }
2826 3008
2827 3009 rw_exit(&mip->mi_rw_lock);
2828 3010 i_mac_perim_exit(mip);
2829 3011 return (0);
2830 3012 }
2831 3013
2832 3014 int
2833 3015 mac_mtu_remove(mac_handle_t mh, uint32_t mtu)
2834 3016 {
2835 3017 mac_impl_t *mip = (mac_impl_t *)mh;
2836 3018 mac_mtu_req_t *cur, *prev;
2837 3019
2838 3020 i_mac_perim_enter(mip);
2839 3021 rw_enter(&mip->mi_rw_lock, RW_WRITER);
2840 3022
2841 3023 prev = NULL;
2842 3024 for (cur = mip->mi_mtrp; cur != NULL; cur = cur->mtr_nextp) {
2843 3025 if (cur->mtr_mtu == mtu) {
2844 3026 ASSERT(cur->mtr_ref > 0);
2845 3027 cur->mtr_ref--;
2846 3028 if (cur->mtr_ref == 0) {
2847 3029 if (prev == NULL) {
2848 3030 mip->mi_mtrp = cur->mtr_nextp;
2849 3031 } else {
2850 3032 prev->mtr_nextp = cur->mtr_nextp;
2851 3033 }
2852 3034 kmem_free(cur, sizeof (mac_mtu_req_t));
2853 3035 }
2854 3036 rw_exit(&mip->mi_rw_lock);
2855 3037 i_mac_perim_exit(mip);
2856 3038 return (0);
2857 3039 }
2858 3040
2859 3041 prev = cur;
2860 3042 }
2861 3043
2862 3044 rw_exit(&mip->mi_rw_lock);
2863 3045 i_mac_perim_exit(mip);
2864 3046 return (ENOENT);
2865 3047 }
2866 3048
2867 3049 /*
2868 3050 * MAC Type Plugin functions.
2869 3051 */
2870 3052
2871 3053 mactype_t *
2872 3054 mactype_getplugin(const char *pname)
2873 3055 {
2874 3056 mactype_t *mtype = NULL;
2875 3057 boolean_t tried_modload = B_FALSE;
2876 3058
2877 3059 mutex_enter(&i_mactype_lock);
2878 3060
2879 3061 find_registered_mactype:
2880 3062 if (mod_hash_find(i_mactype_hash, (mod_hash_key_t)pname,
2881 3063 (mod_hash_val_t *)&mtype) != 0) {
2882 3064 if (!tried_modload) {
2883 3065 /*
2884 3066 * If the plugin has not yet been loaded, then
2885 3067 * attempt to load it now. If modload() succeeds,
2886 3068 * the plugin should have registered using
2887 3069 * mactype_register(), in which case we can go back
2888 3070 * and attempt to find it again.
2889 3071 */
2890 3072 if (modload(MACTYPE_KMODDIR, (char *)pname) != -1) {
2891 3073 tried_modload = B_TRUE;
2892 3074 goto find_registered_mactype;
2893 3075 }
2894 3076 }
2895 3077 } else {
2896 3078 /*
2897 3079 * Note that there's no danger that the plugin we've loaded
2898 3080 * could be unloaded between the modload() step and the
2899 3081 * reference count bump here, as we're holding
2900 3082 * i_mactype_lock, which mactype_unregister() also holds.
2901 3083 */
2902 3084 atomic_inc_32(&mtype->mt_ref);
2903 3085 }
2904 3086
2905 3087 mutex_exit(&i_mactype_lock);
2906 3088 return (mtype);
2907 3089 }
2908 3090
2909 3091 mactype_register_t *
2910 3092 mactype_alloc(uint_t mactype_version)
2911 3093 {
2912 3094 mactype_register_t *mtrp;
2913 3095
2914 3096 /*
2915 3097 * Make sure there isn't a version mismatch between the plugin and
2916 3098 * the framework. In the future, if multiple versions are
2917 3099 * supported, this check could become more sophisticated.
2918 3100 */
2919 3101 if (mactype_version != MACTYPE_VERSION)
2920 3102 return (NULL);
2921 3103
2922 3104 mtrp = kmem_zalloc(sizeof (mactype_register_t), KM_SLEEP);
2923 3105 mtrp->mtr_version = mactype_version;
2924 3106 return (mtrp);
2925 3107 }
2926 3108
2927 3109 void
2928 3110 mactype_free(mactype_register_t *mtrp)
2929 3111 {
2930 3112 kmem_free(mtrp, sizeof (mactype_register_t));
2931 3113 }
2932 3114
2933 3115 int
2934 3116 mactype_register(mactype_register_t *mtrp)
2935 3117 {
2936 3118 mactype_t *mtp;
2937 3119 mactype_ops_t *ops = mtrp->mtr_ops;
2938 3120
2939 3121 /* Do some sanity checking before we register this MAC type. */
2940 3122 if (mtrp->mtr_ident == NULL || ops == NULL)
2941 3123 return (EINVAL);
2942 3124
2943 3125 /*
2944 3126 * Verify that all mandatory callbacks are set in the ops
2945 3127 * vector.
2946 3128 */
2947 3129 if (ops->mtops_unicst_verify == NULL ||
2948 3130 ops->mtops_multicst_verify == NULL ||
2949 3131 ops->mtops_sap_verify == NULL ||
2950 3132 ops->mtops_header == NULL ||
2951 3133 ops->mtops_header_info == NULL) {
2952 3134 return (EINVAL);
2953 3135 }
2954 3136
2955 3137 mtp = kmem_zalloc(sizeof (*mtp), KM_SLEEP);
2956 3138 mtp->mt_ident = mtrp->mtr_ident;
2957 3139 mtp->mt_ops = *ops;
2958 3140 mtp->mt_type = mtrp->mtr_mactype;
2959 3141 mtp->mt_nativetype = mtrp->mtr_nativetype;
2960 3142 mtp->mt_addr_length = mtrp->mtr_addrlen;
2961 3143 if (mtrp->mtr_brdcst_addr != NULL) {
2962 3144 mtp->mt_brdcst_addr = kmem_alloc(mtrp->mtr_addrlen, KM_SLEEP);
2963 3145 bcopy(mtrp->mtr_brdcst_addr, mtp->mt_brdcst_addr,
2964 3146 mtrp->mtr_addrlen);
2965 3147 }
2966 3148
2967 3149 mtp->mt_stats = mtrp->mtr_stats;
2968 3150 mtp->mt_statcount = mtrp->mtr_statcount;
2969 3151
2970 3152 mtp->mt_mapping = mtrp->mtr_mapping;
2971 3153 mtp->mt_mappingcount = mtrp->mtr_mappingcount;
2972 3154
2973 3155 if (mod_hash_insert(i_mactype_hash,
2974 3156 (mod_hash_key_t)mtp->mt_ident, (mod_hash_val_t)mtp) != 0) {
2975 3157 kmem_free(mtp->mt_brdcst_addr, mtp->mt_addr_length);
2976 3158 kmem_free(mtp, sizeof (*mtp));
2977 3159 return (EEXIST);
2978 3160 }
2979 3161 return (0);
2980 3162 }
2981 3163
2982 3164 int
2983 3165 mactype_unregister(const char *ident)
2984 3166 {
2985 3167 mactype_t *mtp;
2986 3168 mod_hash_val_t val;
2987 3169 int err;
2988 3170
2989 3171 /*
2990 3172 * Let's not allow MAC drivers to use this plugin while we're
2991 3173 * trying to unregister it. Holding i_mactype_lock also prevents a
2992 3174 * plugin from unregistering while a MAC driver is attempting to
2993 3175 * hold a reference to it in i_mactype_getplugin().
2994 3176 */
2995 3177 mutex_enter(&i_mactype_lock);
2996 3178
2997 3179 if ((err = mod_hash_find(i_mactype_hash, (mod_hash_key_t)ident,
2998 3180 (mod_hash_val_t *)&mtp)) != 0) {
2999 3181 /* A plugin is trying to unregister, but it never registered. */
3000 3182 err = ENXIO;
3001 3183 goto done;
3002 3184 }
3003 3185
3004 3186 if (mtp->mt_ref != 0) {
3005 3187 err = EBUSY;
3006 3188 goto done;
3007 3189 }
3008 3190
3009 3191 err = mod_hash_remove(i_mactype_hash, (mod_hash_key_t)ident, &val);
3010 3192 ASSERT(err == 0);
3011 3193 if (err != 0) {
3012 3194 /* This should never happen, thus the ASSERT() above. */
3013 3195 err = EINVAL;
3014 3196 goto done;
3015 3197 }
3016 3198 ASSERT(mtp == (mactype_t *)val);
3017 3199
3018 3200 if (mtp->mt_brdcst_addr != NULL)
3019 3201 kmem_free(mtp->mt_brdcst_addr, mtp->mt_addr_length);
3020 3202 kmem_free(mtp, sizeof (mactype_t));
3021 3203 done:
3022 3204 mutex_exit(&i_mactype_lock);
3023 3205 return (err);
3024 3206 }
3025 3207
3026 3208 /*
3027 3209 * Checks the size of the value size specified for a property as
3028 3210 * part of a property operation. Returns B_TRUE if the size is
3029 3211 * correct, B_FALSE otherwise.
3030 3212 */
3031 3213 boolean_t
3032 3214 mac_prop_check_size(mac_prop_id_t id, uint_t valsize, boolean_t is_range)
3033 3215 {
3034 3216 uint_t minsize = 0;
3035 3217
3036 3218 if (is_range)
3037 3219 return (valsize >= sizeof (mac_propval_range_t));
3038 3220
3039 3221 switch (id) {
3040 3222 case MAC_PROP_ZONE:
3041 3223 minsize = sizeof (dld_ioc_zid_t);
3042 3224 break;
3043 3225 case MAC_PROP_AUTOPUSH:
3044 3226 if (valsize != 0)
3045 3227 minsize = sizeof (struct dlautopush);
3046 3228 break;
3047 3229 case MAC_PROP_TAGMODE:
3048 3230 minsize = sizeof (link_tagmode_t);
3049 3231 break;
3050 3232 case MAC_PROP_RESOURCE:
3051 3233 case MAC_PROP_RESOURCE_EFF:
3052 3234 minsize = sizeof (mac_resource_props_t);
3053 3235 break;
3054 3236 case MAC_PROP_DUPLEX:
3055 3237 minsize = sizeof (link_duplex_t);
3056 3238 break;
3057 3239 case MAC_PROP_SPEED:
3058 3240 minsize = sizeof (uint64_t);
3059 3241 break;
3060 3242 case MAC_PROP_STATUS:
3061 3243 minsize = sizeof (link_state_t);
3062 3244 break;
3063 3245 case MAC_PROP_AUTONEG:
3064 3246 case MAC_PROP_EN_AUTONEG:
3065 3247 minsize = sizeof (uint8_t);
3066 3248 break;
3067 3249 case MAC_PROP_MTU:
3068 3250 case MAC_PROP_LLIMIT:
3069 3251 case MAC_PROP_LDECAY:
3070 3252 minsize = sizeof (uint32_t);
3071 3253 break;
3072 3254 case MAC_PROP_FLOWCTRL:
3073 3255 minsize = sizeof (link_flowctrl_t);
3074 3256 break;
3075 3257 case MAC_PROP_ADV_5000FDX_CAP:
3076 3258 case MAC_PROP_EN_5000FDX_CAP:
3077 3259 case MAC_PROP_ADV_2500FDX_CAP:
3078 3260 case MAC_PROP_EN_2500FDX_CAP:
3079 3261 case MAC_PROP_ADV_100GFDX_CAP:
3080 3262 case MAC_PROP_EN_100GFDX_CAP:
3081 3263 case MAC_PROP_ADV_50GFDX_CAP:
3082 3264 case MAC_PROP_EN_50GFDX_CAP:
3083 3265 case MAC_PROP_ADV_40GFDX_CAP:
3084 3266 case MAC_PROP_EN_40GFDX_CAP:
3085 3267 case MAC_PROP_ADV_25GFDX_CAP:
3086 3268 case MAC_PROP_EN_25GFDX_CAP:
3087 3269 case MAC_PROP_ADV_10GFDX_CAP:
3088 3270 case MAC_PROP_EN_10GFDX_CAP:
3089 3271 case MAC_PROP_ADV_1000HDX_CAP:
3090 3272 case MAC_PROP_EN_1000HDX_CAP:
3091 3273 case MAC_PROP_ADV_100FDX_CAP:
3092 3274 case MAC_PROP_EN_100FDX_CAP:
3093 3275 case MAC_PROP_ADV_100HDX_CAP:
3094 3276 case MAC_PROP_EN_100HDX_CAP:
3095 3277 case MAC_PROP_ADV_10FDX_CAP:
3096 3278 case MAC_PROP_EN_10FDX_CAP:
3097 3279 case MAC_PROP_ADV_10HDX_CAP:
3098 3280 case MAC_PROP_EN_10HDX_CAP:
3099 3281 case MAC_PROP_ADV_100T4_CAP:
3100 3282 case MAC_PROP_EN_100T4_CAP:
3101 3283 minsize = sizeof (uint8_t);
3102 3284 break;
3103 3285 case MAC_PROP_PVID:
3104 3286 minsize = sizeof (uint16_t);
3105 3287 break;
3106 3288 case MAC_PROP_IPTUN_HOPLIMIT:
3107 3289 minsize = sizeof (uint32_t);
3108 3290 break;
3109 3291 case MAC_PROP_IPTUN_ENCAPLIMIT:
3110 3292 minsize = sizeof (uint32_t);
3111 3293 break;
3112 3294 case MAC_PROP_MAX_TX_RINGS_AVAIL:
3113 3295 case MAC_PROP_MAX_RX_RINGS_AVAIL:
3114 3296 case MAC_PROP_MAX_RXHWCLNT_AVAIL:
3115 3297 case MAC_PROP_MAX_TXHWCLNT_AVAIL:
3116 3298 minsize = sizeof (uint_t);
3117 3299 break;
3118 3300 case MAC_PROP_WL_ESSID:
3119 3301 minsize = sizeof (wl_linkstatus_t);
3120 3302 break;
3121 3303 case MAC_PROP_WL_BSSID:
3122 3304 minsize = sizeof (wl_bssid_t);
3123 3305 break;
3124 3306 case MAC_PROP_WL_BSSTYPE:
3125 3307 minsize = sizeof (wl_bss_type_t);
3126 3308 break;
3127 3309 case MAC_PROP_WL_LINKSTATUS:
3128 3310 minsize = sizeof (wl_linkstatus_t);
3129 3311 break;
3130 3312 case MAC_PROP_WL_DESIRED_RATES:
3131 3313 minsize = sizeof (wl_rates_t);
3132 3314 break;
3133 3315 case MAC_PROP_WL_SUPPORTED_RATES:
3134 3316 minsize = sizeof (wl_rates_t);
3135 3317 break;
3136 3318 case MAC_PROP_WL_AUTH_MODE:
3137 3319 minsize = sizeof (wl_authmode_t);
3138 3320 break;
3139 3321 case MAC_PROP_WL_ENCRYPTION:
3140 3322 minsize = sizeof (wl_encryption_t);
3141 3323 break;
3142 3324 case MAC_PROP_WL_RSSI:
3143 3325 minsize = sizeof (wl_rssi_t);
3144 3326 break;
3145 3327 case MAC_PROP_WL_PHY_CONFIG:
3146 3328 minsize = sizeof (wl_phy_conf_t);
3147 3329 break;
3148 3330 case MAC_PROP_WL_CAPABILITY:
3149 3331 minsize = sizeof (wl_capability_t);
3150 3332 break;
3151 3333 case MAC_PROP_WL_WPA:
3152 3334 minsize = sizeof (wl_wpa_t);
3153 3335 break;
3154 3336 case MAC_PROP_WL_SCANRESULTS:
3155 3337 minsize = sizeof (wl_wpa_ess_t);
3156 3338 break;
3157 3339 case MAC_PROP_WL_POWER_MODE:
3158 3340 minsize = sizeof (wl_ps_mode_t);
3159 3341 break;
3160 3342 case MAC_PROP_WL_RADIO:
3161 3343 minsize = sizeof (wl_radio_t);
3162 3344 break;
3163 3345 case MAC_PROP_WL_ESS_LIST:
3164 3346 minsize = sizeof (wl_ess_list_t);
3165 3347 break;
3166 3348 case MAC_PROP_WL_KEY_TAB:
3167 3349 minsize = sizeof (wl_wep_key_tab_t);
3168 3350 break;
3169 3351 case MAC_PROP_WL_CREATE_IBSS:
3170 3352 minsize = sizeof (wl_create_ibss_t);
3171 3353 break;
3172 3354 case MAC_PROP_WL_SETOPTIE:
3173 3355 minsize = sizeof (wl_wpa_ie_t);
3174 3356 break;
3175 3357 case MAC_PROP_WL_DELKEY:
3176 3358 minsize = sizeof (wl_del_key_t);
3177 3359 break;
3178 3360 case MAC_PROP_WL_KEY:
3179 3361 minsize = sizeof (wl_key_t);
3180 3362 break;
3181 3363 case MAC_PROP_WL_MLME:
3182 3364 minsize = sizeof (wl_mlme_t);
3183 3365 break;
3184 3366 case MAC_PROP_VN_PROMISC_FILTERED:
3185 3367 minsize = sizeof (boolean_t);
3186 3368 break;
3187 3369 }
3188 3370
3189 3371 return (valsize >= minsize);
3190 3372 }
3191 3373
3192 3374 /*
3193 3375 * mac_set_prop() sets MAC or hardware driver properties:
3194 3376 *
3195 3377 * - MAC-managed properties such as resource properties include maxbw,
3196 3378 * priority, and cpu binding list, as well as the default port VID
3197 3379 * used by bridging. These properties are consumed by the MAC layer
3198 3380 * itself and not passed down to the driver. For resource control
3199 3381 * properties, this function invokes mac_set_resources() which will
3200 3382 * cache the property value in mac_impl_t and may call
3201 3383 * mac_client_set_resource() to update property value of the primary
3202 3384 * mac client, if it exists.
3203 3385 *
3204 3386 * - Properties which act on the hardware and must be passed to the
3205 3387 * driver, such as MTU, through the driver's mc_setprop() entry point.
3206 3388 */
3207 3389 int
3208 3390 mac_set_prop(mac_handle_t mh, mac_prop_id_t id, char *name, void *val,
3209 3391 uint_t valsize)
3210 3392 {
3211 3393 int err = ENOTSUP;
3212 3394 mac_impl_t *mip = (mac_impl_t *)mh;
3213 3395
3214 3396 ASSERT(MAC_PERIM_HELD(mh));
3215 3397
3216 3398 switch (id) {
3217 3399 case MAC_PROP_RESOURCE: {
3218 3400 mac_resource_props_t *mrp;
3219 3401
3220 3402 /* call mac_set_resources() for MAC properties */
3221 3403 ASSERT(valsize >= sizeof (mac_resource_props_t));
3222 3404 mrp = kmem_zalloc(sizeof (*mrp), KM_SLEEP);
3223 3405 bcopy(val, mrp, sizeof (*mrp));
3224 3406 err = mac_set_resources(mh, mrp);
3225 3407 kmem_free(mrp, sizeof (*mrp));
3226 3408 break;
3227 3409 }
3228 3410
3229 3411 case MAC_PROP_PVID:
3230 3412 ASSERT(valsize >= sizeof (uint16_t));
3231 3413 if (mip->mi_state_flags & MIS_IS_VNIC)
3232 3414 return (EINVAL);
3233 3415 err = mac_set_pvid(mh, *(uint16_t *)val);
3234 3416 break;
3235 3417
3236 3418 case MAC_PROP_MTU: {
3237 3419 uint32_t mtu;
3238 3420
3239 3421 ASSERT(valsize >= sizeof (uint32_t));
3240 3422 bcopy(val, &mtu, sizeof (mtu));
3241 3423 err = mac_set_mtu(mh, mtu, NULL);
3242 3424 break;
3243 3425 }
3244 3426
3245 3427 case MAC_PROP_LLIMIT:
3246 3428 case MAC_PROP_LDECAY: {
3247 3429 uint32_t learnval;
3248 3430
3249 3431 if (valsize < sizeof (learnval) ||
3250 3432 (mip->mi_state_flags & MIS_IS_VNIC))
3251 3433 return (EINVAL);
3252 3434 bcopy(val, &learnval, sizeof (learnval));
3253 3435 if (learnval == 0 && id == MAC_PROP_LDECAY)
3254 3436 return (EINVAL);
3255 3437 if (id == MAC_PROP_LLIMIT)
3256 3438 mip->mi_llimit = learnval;
3257 3439 else
3258 3440 mip->mi_ldecay = learnval;
3259 3441 err = 0;
3260 3442 break;
3261 3443 }
3262 3444
3263 3445 default:
3264 3446 /* For other driver properties, call driver's callback */
3265 3447 if (mip->mi_callbacks->mc_callbacks & MC_SETPROP) {
3266 3448 err = mip->mi_callbacks->mc_setprop(mip->mi_driver,
3267 3449 name, id, valsize, val);
3268 3450 }
3269 3451 }
3270 3452 return (err);
3271 3453 }
3272 3454
3273 3455 /*
3274 3456 * mac_get_prop() gets MAC or device driver properties.
3275 3457 *
3276 3458 * If the property is a driver property, mac_get_prop() calls driver's callback
3277 3459 * entry point to get it.
3278 3460 * If the property is a MAC property, mac_get_prop() invokes mac_get_resources()
3279 3461 * which returns the cached value in mac_impl_t.
3280 3462 */
3281 3463 int
3282 3464 mac_get_prop(mac_handle_t mh, mac_prop_id_t id, char *name, void *val,
3283 3465 uint_t valsize)
3284 3466 {
3285 3467 int err = ENOTSUP;
3286 3468 mac_impl_t *mip = (mac_impl_t *)mh;
3287 3469 uint_t rings;
3288 3470 uint_t vlinks;
3289 3471
3290 3472 bzero(val, valsize);
3291 3473
3292 3474 switch (id) {
3293 3475 case MAC_PROP_RESOURCE: {
3294 3476 mac_resource_props_t *mrp;
3295 3477
3296 3478 /* If mac property, read from cache */
3297 3479 ASSERT(valsize >= sizeof (mac_resource_props_t));
3298 3480 mrp = kmem_zalloc(sizeof (*mrp), KM_SLEEP);
3299 3481 mac_get_resources(mh, mrp);
3300 3482 bcopy(mrp, val, sizeof (*mrp));
3301 3483 kmem_free(mrp, sizeof (*mrp));
3302 3484 return (0);
3303 3485 }
3304 3486 case MAC_PROP_RESOURCE_EFF: {
3305 3487 mac_resource_props_t *mrp;
3306 3488
3307 3489 /* If mac effective property, read from client */
3308 3490 ASSERT(valsize >= sizeof (mac_resource_props_t));
3309 3491 mrp = kmem_zalloc(sizeof (*mrp), KM_SLEEP);
3310 3492 mac_get_effective_resources(mh, mrp);
3311 3493 bcopy(mrp, val, sizeof (*mrp));
3312 3494 kmem_free(mrp, sizeof (*mrp));
3313 3495 return (0);
3314 3496 }
3315 3497
3316 3498 case MAC_PROP_PVID:
3317 3499 ASSERT(valsize >= sizeof (uint16_t));
3318 3500 if (mip->mi_state_flags & MIS_IS_VNIC)
3319 3501 return (EINVAL);
3320 3502 *(uint16_t *)val = mac_get_pvid(mh);
3321 3503 return (0);
3322 3504
3323 3505 case MAC_PROP_LLIMIT:
3324 3506 case MAC_PROP_LDECAY:
3325 3507 ASSERT(valsize >= sizeof (uint32_t));
3326 3508 if (mip->mi_state_flags & MIS_IS_VNIC)
3327 3509 return (EINVAL);
3328 3510 if (id == MAC_PROP_LLIMIT)
3329 3511 bcopy(&mip->mi_llimit, val, sizeof (mip->mi_llimit));
3330 3512 else
3331 3513 bcopy(&mip->mi_ldecay, val, sizeof (mip->mi_ldecay));
3332 3514 return (0);
3333 3515
3334 3516 case MAC_PROP_MTU: {
3335 3517 uint32_t sdu;
3336 3518
3337 3519 ASSERT(valsize >= sizeof (uint32_t));
3338 3520 mac_sdu_get2(mh, NULL, &sdu, NULL);
3339 3521 bcopy(&sdu, val, sizeof (sdu));
3340 3522
3341 3523 return (0);
3342 3524 }
3343 3525 case MAC_PROP_STATUS: {
3344 3526 link_state_t link_state;
3345 3527
3346 3528 if (valsize < sizeof (link_state))
3347 3529 return (EINVAL);
3348 3530 link_state = mac_link_get(mh);
3349 3531 bcopy(&link_state, val, sizeof (link_state));
3350 3532
3351 3533 return (0);
3352 3534 }
3353 3535
3354 3536 case MAC_PROP_MAX_RX_RINGS_AVAIL:
3355 3537 case MAC_PROP_MAX_TX_RINGS_AVAIL:
3356 3538 ASSERT(valsize >= sizeof (uint_t));
3357 3539 rings = id == MAC_PROP_MAX_RX_RINGS_AVAIL ?
3358 3540 mac_rxavail_get(mh) : mac_txavail_get(mh);
3359 3541 bcopy(&rings, val, sizeof (uint_t));
3360 3542 return (0);
3361 3543
3362 3544 case MAC_PROP_MAX_RXHWCLNT_AVAIL:
3363 3545 case MAC_PROP_MAX_TXHWCLNT_AVAIL:
3364 3546 ASSERT(valsize >= sizeof (uint_t));
3365 3547 vlinks = id == MAC_PROP_MAX_RXHWCLNT_AVAIL ?
3366 3548 mac_rxhwlnksavail_get(mh) : mac_txhwlnksavail_get(mh);
3367 3549 bcopy(&vlinks, val, sizeof (uint_t));
3368 3550 return (0);
3369 3551
3370 3552 case MAC_PROP_RXRINGSRANGE:
3371 3553 case MAC_PROP_TXRINGSRANGE:
3372 3554 /*
3373 3555 * The value for these properties are returned through
3374 3556 * the MAC_PROP_RESOURCE property.
3375 3557 */
3376 3558 return (0);
3377 3559
3378 3560 default:
3379 3561 break;
3380 3562
3381 3563 }
3382 3564
3383 3565 /* If driver property, request from driver */
3384 3566 if (mip->mi_callbacks->mc_callbacks & MC_GETPROP) {
3385 3567 err = mip->mi_callbacks->mc_getprop(mip->mi_driver, name, id,
3386 3568 valsize, val);
3387 3569 }
3388 3570
3389 3571 return (err);
3390 3572 }
3391 3573
3392 3574 /*
3393 3575 * Helper function to initialize the range structure for use in
3394 3576 * mac_get_prop. If the type can be other than uint32, we can
3395 3577 * pass that as an arg.
3396 3578 */
3397 3579 static void
3398 3580 _mac_set_range(mac_propval_range_t *range, uint32_t min, uint32_t max)
3399 3581 {
3400 3582 range->mpr_count = 1;
3401 3583 range->mpr_type = MAC_PROPVAL_UINT32;
3402 3584 range->mpr_range_uint32[0].mpur_min = min;
3403 3585 range->mpr_range_uint32[0].mpur_max = max;
3404 3586 }
3405 3587
3406 3588 /*
3407 3589 * Returns information about the specified property, such as default
3408 3590 * values or permissions.
3409 3591 */
3410 3592 int
3411 3593 mac_prop_info(mac_handle_t mh, mac_prop_id_t id, char *name,
3412 3594 void *default_val, uint_t default_size, mac_propval_range_t *range,
3413 3595 uint_t *perm)
3414 3596 {
3415 3597 mac_prop_info_state_t state;
3416 3598 mac_impl_t *mip = (mac_impl_t *)mh;
3417 3599 uint_t max;
3418 3600
3419 3601 /*
3420 3602 * A property is read/write by default unless the driver says
3421 3603 * otherwise.
3422 3604 */
3423 3605 if (perm != NULL)
3424 3606 *perm = MAC_PROP_PERM_RW;
3425 3607
3426 3608 if (default_val != NULL)
3427 3609 bzero(default_val, default_size);
3428 3610
3429 3611 /*
3430 3612 * First, handle framework properties for which we don't need to
3431 3613 * involve the driver.
3432 3614 */
3433 3615 switch (id) {
3434 3616 case MAC_PROP_RESOURCE:
3435 3617 case MAC_PROP_PVID:
3436 3618 case MAC_PROP_LLIMIT:
3437 3619 case MAC_PROP_LDECAY:
3438 3620 return (0);
3439 3621
3440 3622 case MAC_PROP_MAX_RX_RINGS_AVAIL:
3441 3623 case MAC_PROP_MAX_TX_RINGS_AVAIL:
3442 3624 case MAC_PROP_MAX_RXHWCLNT_AVAIL:
3443 3625 case MAC_PROP_MAX_TXHWCLNT_AVAIL:
3444 3626 if (perm != NULL)
3445 3627 *perm = MAC_PROP_PERM_READ;
3446 3628 return (0);
3447 3629
3448 3630 case MAC_PROP_RXRINGSRANGE:
3449 3631 case MAC_PROP_TXRINGSRANGE:
3450 3632 /*
3451 3633 * Currently, we support range for RX and TX rings properties.
3452 3634 * When we extend this support to maxbw, cpus and priority,
3453 3635 * we should move this to mac_get_resources.
3454 3636 * There is no default value for RX or TX rings.
3455 3637 */
3456 3638 if ((mip->mi_state_flags & MIS_IS_VNIC) &&
3457 3639 mac_is_vnic_primary(mh)) {
3458 3640 /*
3459 3641 * We don't support setting rings for a VLAN
3460 3642 * data link because it shares its ring with the
3461 3643 * primary MAC client.
3462 3644 */
3463 3645 if (perm != NULL)
3464 3646 *perm = MAC_PROP_PERM_READ;
3465 3647 if (range != NULL)
3466 3648 range->mpr_count = 0;
3467 3649 } else if (range != NULL) {
3468 3650 if (mip->mi_state_flags & MIS_IS_VNIC)
3469 3651 mh = mac_get_lower_mac_handle(mh);
3470 3652 mip = (mac_impl_t *)mh;
3471 3653 if ((id == MAC_PROP_RXRINGSRANGE &&
3472 3654 mip->mi_rx_group_type == MAC_GROUP_TYPE_STATIC) ||
3473 3655 (id == MAC_PROP_TXRINGSRANGE &&
3474 3656 mip->mi_tx_group_type == MAC_GROUP_TYPE_STATIC)) {
3475 3657 if (id == MAC_PROP_RXRINGSRANGE) {
3476 3658 if ((mac_rxhwlnksavail_get(mh) +
3477 3659 mac_rxhwlnksrsvd_get(mh)) <= 1) {
3478 3660 /*
3479 3661 * doesn't support groups or
3480 3662 * rings
3481 3663 */
3482 3664 range->mpr_count = 0;
3483 3665 } else {
3484 3666 /*
3485 3667 * supports specifying groups,
3486 3668 * but not rings
3487 3669 */
3488 3670 _mac_set_range(range, 0, 0);
3489 3671 }
3490 3672 } else {
3491 3673 if ((mac_txhwlnksavail_get(mh) +
3492 3674 mac_txhwlnksrsvd_get(mh)) <= 1) {
3493 3675 /*
3494 3676 * doesn't support groups or
3495 3677 * rings
3496 3678 */
3497 3679 range->mpr_count = 0;
3498 3680 } else {
3499 3681 /*
3500 3682 * supports specifying groups,
3501 3683 * but not rings
3502 3684 */
3503 3685 _mac_set_range(range, 0, 0);
3504 3686 }
3505 3687 }
3506 3688 } else {
3507 3689 max = id == MAC_PROP_RXRINGSRANGE ?
3508 3690 mac_rxavail_get(mh) + mac_rxrsvd_get(mh) :
3509 3691 mac_txavail_get(mh) + mac_txrsvd_get(mh);
3510 3692 if (max <= 1) {
3511 3693 /*
3512 3694 * doesn't support groups or
3513 3695 * rings
3514 3696 */
3515 3697 range->mpr_count = 0;
3516 3698 } else {
3517 3699 /*
3518 3700 * -1 because we have to leave out the
3519 3701 * default ring.
3520 3702 */
3521 3703 _mac_set_range(range, 1, max - 1);
3522 3704 }
3523 3705 }
3524 3706 }
3525 3707 return (0);
3526 3708
3527 3709 case MAC_PROP_STATUS:
3528 3710 if (perm != NULL)
3529 3711 *perm = MAC_PROP_PERM_READ;
3530 3712 return (0);
3531 3713 }
3532 3714
3533 3715 /*
3534 3716 * Get the property info from the driver if it implements the
3535 3717 * property info entry point.
3536 3718 */
3537 3719 bzero(&state, sizeof (state));
3538 3720
3539 3721 if (mip->mi_callbacks->mc_callbacks & MC_PROPINFO) {
3540 3722 state.pr_default = default_val;
3541 3723 state.pr_default_size = default_size;
3542 3724
3543 3725 /*
3544 3726 * The caller specifies the maximum number of ranges
3545 3727 * it can accomodate using mpr_count. We don't touch
3546 3728 * this value until the driver returns from its
3547 3729 * mc_propinfo() callback, and ensure we don't exceed
3548 3730 * this number of range as the driver defines
3549 3731 * supported range from its mc_propinfo().
3550 3732 *
3551 3733 * pr_range_cur_count keeps track of how many ranges
3552 3734 * were defined by the driver from its mc_propinfo()
3553 3735 * entry point.
3554 3736 *
3555 3737 * On exit, the user-specified range mpr_count returns
3556 3738 * the number of ranges specified by the driver on
3557 3739 * success, or the number of ranges it wanted to
3558 3740 * define if that number of ranges could not be
3559 3741 * accomodated by the specified range structure. In
3560 3742 * the latter case, the caller will be able to
3561 3743 * allocate a larger range structure, and query the
3562 3744 * property again.
3563 3745 */
3564 3746 state.pr_range_cur_count = 0;
3565 3747 state.pr_range = range;
3566 3748
3567 3749 mip->mi_callbacks->mc_propinfo(mip->mi_driver, name, id,
3568 3750 (mac_prop_info_handle_t)&state);
3569 3751
3570 3752 if (state.pr_flags & MAC_PROP_INFO_RANGE)
3571 3753 range->mpr_count = state.pr_range_cur_count;
3572 3754
3573 3755 /*
3574 3756 * The operation could fail if the buffer supplied by
3575 3757 * the user was too small for the range or default
3576 3758 * value of the property.
3577 3759 */
3578 3760 if (state.pr_errno != 0)
3579 3761 return (state.pr_errno);
3580 3762
3581 3763 if (perm != NULL && state.pr_flags & MAC_PROP_INFO_PERM)
3582 3764 *perm = state.pr_perm;
3583 3765 }
3584 3766
3585 3767 /*
3586 3768 * The MAC layer may want to provide default values or allowed
3587 3769 * ranges for properties if the driver does not provide a
3588 3770 * property info entry point, or that entry point exists, but
3589 3771 * it did not provide a default value or allowed ranges for
3590 3772 * that property.
3591 3773 */
3592 3774 switch (id) {
3593 3775 case MAC_PROP_MTU: {
3594 3776 uint32_t sdu;
3595 3777
3596 3778 mac_sdu_get2(mh, NULL, &sdu, NULL);
3597 3779
3598 3780 if (range != NULL && !(state.pr_flags &
3599 3781 MAC_PROP_INFO_RANGE)) {
3600 3782 /* MTU range */
3601 3783 _mac_set_range(range, sdu, sdu);
3602 3784 }
3603 3785
3604 3786 if (default_val != NULL && !(state.pr_flags &
3605 3787 MAC_PROP_INFO_DEFAULT)) {
3606 3788 if (mip->mi_info.mi_media == DL_ETHER)
3607 3789 sdu = ETHERMTU;
3608 3790 /* default MTU value */
3609 3791 bcopy(&sdu, default_val, sizeof (sdu));
3610 3792 }
3611 3793 }
3612 3794 }
3613 3795
3614 3796 return (0);
3615 3797 }
3616 3798
3617 3799 int
3618 3800 mac_fastpath_disable(mac_handle_t mh)
3619 3801 {
3620 3802 mac_impl_t *mip = (mac_impl_t *)mh;
3621 3803
3622 3804 if ((mip->mi_state_flags & MIS_LEGACY) == 0)
3623 3805 return (0);
3624 3806
3625 3807 return (mip->mi_capab_legacy.ml_fastpath_disable(mip->mi_driver));
3626 3808 }
3627 3809
3628 3810 void
3629 3811 mac_fastpath_enable(mac_handle_t mh)
3630 3812 {
3631 3813 mac_impl_t *mip = (mac_impl_t *)mh;
3632 3814
3633 3815 if ((mip->mi_state_flags & MIS_LEGACY) == 0)
3634 3816 return;
3635 3817
3636 3818 mip->mi_capab_legacy.ml_fastpath_enable(mip->mi_driver);
3637 3819 }
3638 3820
3639 3821 void
3640 3822 mac_register_priv_prop(mac_impl_t *mip, char **priv_props)
3641 3823 {
3642 3824 uint_t nprops, i;
3643 3825
3644 3826 if (priv_props == NULL)
3645 3827 return;
3646 3828
3647 3829 nprops = 0;
3648 3830 while (priv_props[nprops] != NULL)
3649 3831 nprops++;
3650 3832 if (nprops == 0)
3651 3833 return;
3652 3834
3653 3835
3654 3836 mip->mi_priv_prop = kmem_zalloc(nprops * sizeof (char *), KM_SLEEP);
3655 3837
3656 3838 for (i = 0; i < nprops; i++) {
3657 3839 mip->mi_priv_prop[i] = kmem_zalloc(MAXLINKPROPNAME, KM_SLEEP);
3658 3840 (void) strlcpy(mip->mi_priv_prop[i], priv_props[i],
3659 3841 MAXLINKPROPNAME);
3660 3842 }
3661 3843
3662 3844 mip->mi_priv_prop_count = nprops;
3663 3845 }
3664 3846
3665 3847 void
3666 3848 mac_unregister_priv_prop(mac_impl_t *mip)
3667 3849 {
3668 3850 uint_t i;
3669 3851
3670 3852 if (mip->mi_priv_prop_count == 0) {
3671 3853 ASSERT(mip->mi_priv_prop == NULL);
3672 3854 return;
3673 3855 }
3674 3856
3675 3857 for (i = 0; i < mip->mi_priv_prop_count; i++)
3676 3858 kmem_free(mip->mi_priv_prop[i], MAXLINKPROPNAME);
3677 3859 kmem_free(mip->mi_priv_prop, mip->mi_priv_prop_count *
3678 3860 sizeof (char *));
3679 3861
3680 3862 mip->mi_priv_prop = NULL;
3681 3863 mip->mi_priv_prop_count = 0;
3682 3864 }
3683 3865
3684 3866 /*
3685 3867 * mac_ring_t 'mr' macros. Some rogue drivers may access ring structure
3686 3868 * (by invoking mac_rx()) even after processing mac_stop_ring(). In such
3687 3869 * cases if MAC free's the ring structure after mac_stop_ring(), any
3688 3870 * illegal access to the ring structure coming from the driver will panic
3689 3871 * the system. In order to protect the system from such inadverent access,
3690 3872 * we maintain a cache of rings in the mac_impl_t after they get free'd up.
3691 3873 * When packets are received on free'd up rings, MAC (through the generation
3692 3874 * count mechanism) will drop such packets.
3693 3875 */
3694 3876 static mac_ring_t *
3695 3877 mac_ring_alloc(mac_impl_t *mip)
3696 3878 {
3697 3879 mac_ring_t *ring;
3698 3880
3699 3881 mutex_enter(&mip->mi_ring_lock);
3700 3882 if (mip->mi_ring_freelist != NULL) {
3701 3883 ring = mip->mi_ring_freelist;
3702 3884 mip->mi_ring_freelist = ring->mr_next;
3703 3885 bzero(ring, sizeof (mac_ring_t));
3704 3886 mutex_exit(&mip->mi_ring_lock);
3705 3887 } else {
3706 3888 mutex_exit(&mip->mi_ring_lock);
3707 3889 ring = kmem_cache_alloc(mac_ring_cache, KM_SLEEP);
3708 3890 }
3709 3891 ASSERT((ring != NULL) && (ring->mr_state == MR_FREE));
3710 3892 return (ring);
3711 3893 }
3712 3894
3713 3895 static void
3714 3896 mac_ring_free(mac_impl_t *mip, mac_ring_t *ring)
3715 3897 {
3716 3898 ASSERT(ring->mr_state == MR_FREE);
3717 3899
3718 3900 mutex_enter(&mip->mi_ring_lock);
3719 3901 ring->mr_state = MR_FREE;
3720 3902 ring->mr_flag = 0;
3721 3903 ring->mr_next = mip->mi_ring_freelist;
3722 3904 ring->mr_mip = NULL;
3723 3905 mip->mi_ring_freelist = ring;
3724 3906 mac_ring_stat_delete(ring);
3725 3907 mutex_exit(&mip->mi_ring_lock);
3726 3908 }
3727 3909
3728 3910 static void
3729 3911 mac_ring_freeall(mac_impl_t *mip)
3730 3912 {
3731 3913 mac_ring_t *ring_next;
3732 3914 mutex_enter(&mip->mi_ring_lock);
3733 3915 mac_ring_t *ring = mip->mi_ring_freelist;
3734 3916 while (ring != NULL) {
3735 3917 ring_next = ring->mr_next;
3736 3918 kmem_cache_free(mac_ring_cache, ring);
3737 3919 ring = ring_next;
3738 3920 }
3739 3921 mip->mi_ring_freelist = NULL;
3740 3922 mutex_exit(&mip->mi_ring_lock);
3741 3923 }
3742 3924
3743 3925 int
3744 3926 mac_start_ring(mac_ring_t *ring)
3745 3927 {
3746 3928 int rv = 0;
3747 3929
3748 3930 ASSERT(ring->mr_state == MR_FREE);
3749 3931
3750 3932 if (ring->mr_start != NULL) {
3751 3933 rv = ring->mr_start(ring->mr_driver, ring->mr_gen_num);
3752 3934 if (rv != 0)
3753 3935 return (rv);
3754 3936 }
3755 3937
3756 3938 ring->mr_state = MR_INUSE;
3757 3939 return (rv);
3758 3940 }
3759 3941
3760 3942 void
3761 3943 mac_stop_ring(mac_ring_t *ring)
3762 3944 {
3763 3945 ASSERT(ring->mr_state == MR_INUSE);
3764 3946
3765 3947 if (ring->mr_stop != NULL)
3766 3948 ring->mr_stop(ring->mr_driver);
3767 3949
3768 3950 ring->mr_state = MR_FREE;
3769 3951
3770 3952 /*
3771 3953 * Increment the ring generation number for this ring.
3772 3954 */
3773 3955 ring->mr_gen_num++;
3774 3956 }
3775 3957
3776 3958 int
3777 3959 mac_start_group(mac_group_t *group)
3778 3960 {
3779 3961 int rv = 0;
3780 3962
3781 3963 if (group->mrg_start != NULL)
3782 3964 rv = group->mrg_start(group->mrg_driver);
3783 3965
3784 3966 return (rv);
3785 3967 }
3786 3968
3787 3969 void
3788 3970 mac_stop_group(mac_group_t *group)
3789 3971 {
3790 3972 if (group->mrg_stop != NULL)
3791 3973 group->mrg_stop(group->mrg_driver);
3792 3974 }
3793 3975
3794 3976 /*
3795 3977 * Called from mac_start() on the default Rx group. Broadcast and multicast
3796 3978 * packets are received only on the default group. Hence the default group
3797 3979 * needs to be up even if the primary client is not up, for the other groups
3798 3980 * to be functional. We do this by calling this function at mac_start time
3799 3981 * itself. However the broadcast packets that are received can't make their
3800 3982 * way beyond mac_rx until a mac client creates a broadcast flow.
3801 3983 */
3802 3984 static int
3803 3985 mac_start_group_and_rings(mac_group_t *group)
↓ open down ↓ |
1313 lines elided |
↑ open up ↑ |
3804 3986 {
3805 3987 mac_ring_t *ring;
3806 3988 int rv = 0;
3807 3989
3808 3990 ASSERT(group->mrg_state == MAC_GROUP_STATE_REGISTERED);
3809 3991 if ((rv = mac_start_group(group)) != 0)
3810 3992 return (rv);
3811 3993
3812 3994 for (ring = group->mrg_rings; ring != NULL; ring = ring->mr_next) {
3813 3995 ASSERT(ring->mr_state == MR_FREE);
3996 +
3814 3997 if ((rv = mac_start_ring(ring)) != 0)
3815 3998 goto error;
3816 - ring->mr_classify_type = MAC_SW_CLASSIFIER;
3999 +
4000 + /*
4001 + * When aggr_set_port_sdu() is called, it will remove
4002 + * the port client's unicast address. This will cause
4003 + * MAC to stop the default group's rings on the port
4004 + * MAC. After it modifies the SDU, it will then re-add
4005 + * the unicast address. At which time, this function is
4006 + * called to start the default group's rings. Normally
4007 + * this function would set the classify type to
4008 + * MAC_SW_CLASSIFIER; but that will break aggr which
4009 + * relies on the passthru classify mode being set for
4010 + * correct delivery (see mac_rx_common()). To avoid
4011 + * that, we check for a passthru callback and set the
4012 + * classify type to MAC_PASSTHRU_CLASSIFIER; as it was
4013 + * before the rings were stopped.
4014 + */
4015 + ring->mr_classify_type = (ring->mr_pt_fn != NULL) ?
4016 + MAC_PASSTHRU_CLASSIFIER : MAC_SW_CLASSIFIER;
3817 4017 }
3818 4018 return (0);
3819 4019
3820 4020 error:
3821 4021 mac_stop_group_and_rings(group);
3822 4022 return (rv);
3823 4023 }
3824 4024
3825 4025 /* Called from mac_stop on the default Rx group */
3826 4026 static void
3827 4027 mac_stop_group_and_rings(mac_group_t *group)
3828 4028 {
3829 4029 mac_ring_t *ring;
3830 4030
3831 4031 for (ring = group->mrg_rings; ring != NULL; ring = ring->mr_next) {
3832 4032 if (ring->mr_state != MR_FREE) {
3833 4033 mac_stop_ring(ring);
3834 4034 ring->mr_flag = 0;
3835 4035 ring->mr_classify_type = MAC_NO_CLASSIFIER;
3836 4036 }
3837 4037 }
3838 4038 mac_stop_group(group);
3839 4039 }
3840 4040
3841 4041
3842 4042 static mac_ring_t *
3843 4043 mac_init_ring(mac_impl_t *mip, mac_group_t *group, int index,
3844 4044 mac_capab_rings_t *cap_rings)
3845 4045 {
3846 4046 mac_ring_t *ring, *rnext;
3847 4047 mac_ring_info_t ring_info;
3848 4048 ddi_intr_handle_t ddi_handle;
3849 4049
3850 4050 ring = mac_ring_alloc(mip);
3851 4051
3852 4052 /* Prepare basic information of ring */
3853 4053
3854 4054 /*
3855 4055 * Ring index is numbered to be unique across a particular device.
3856 4056 * Ring index computation makes following assumptions:
3857 4057 * - For drivers with static grouping (e.g. ixgbe, bge),
3858 4058 * ring index exchanged with the driver (e.g. during mr_rget)
3859 4059 * is unique only across the group the ring belongs to.
3860 4060 * - Drivers with dynamic grouping (e.g. nxge), start
3861 4061 * with single group (mrg_index = 0).
3862 4062 */
3863 4063 ring->mr_index = group->mrg_index * group->mrg_info.mgi_count + index;
3864 4064 ring->mr_type = group->mrg_type;
3865 4065 ring->mr_gh = (mac_group_handle_t)group;
3866 4066
3867 4067 /* Insert the new ring to the list. */
3868 4068 ring->mr_next = group->mrg_rings;
3869 4069 group->mrg_rings = ring;
3870 4070
3871 4071 /* Zero to reuse the info data structure */
3872 4072 bzero(&ring_info, sizeof (ring_info));
3873 4073
3874 4074 /* Query ring information from driver */
3875 4075 cap_rings->mr_rget(mip->mi_driver, group->mrg_type, group->mrg_index,
3876 4076 index, &ring_info, (mac_ring_handle_t)ring);
3877 4077
3878 4078 ring->mr_info = ring_info;
3879 4079
3880 4080 /*
3881 4081 * The interrupt handle could be shared among multiple rings.
3882 4082 * Thus if there is a bunch of rings that are sharing an
3883 4083 * interrupt, then only one ring among the bunch will be made
3884 4084 * available for interrupt re-targeting; the rest will have
3885 4085 * ddi_shared flag set to TRUE and would not be available for
3886 4086 * be interrupt re-targeting.
3887 4087 */
3888 4088 if ((ddi_handle = ring_info.mri_intr.mi_ddi_handle) != NULL) {
3889 4089 rnext = ring->mr_next;
3890 4090 while (rnext != NULL) {
3891 4091 if (rnext->mr_info.mri_intr.mi_ddi_handle ==
3892 4092 ddi_handle) {
3893 4093 /*
3894 4094 * If default ring (mr_index == 0) is part
3895 4095 * of a group of rings sharing an
3896 4096 * interrupt, then set ddi_shared flag for
3897 4097 * the default ring and give another ring
3898 4098 * the chance to be re-targeted.
3899 4099 */
3900 4100 if (rnext->mr_index == 0 &&
3901 4101 !rnext->mr_info.mri_intr.mi_ddi_shared) {
3902 4102 rnext->mr_info.mri_intr.mi_ddi_shared =
3903 4103 B_TRUE;
3904 4104 } else {
3905 4105 ring->mr_info.mri_intr.mi_ddi_shared =
3906 4106 B_TRUE;
3907 4107 }
3908 4108 break;
3909 4109 }
3910 4110 rnext = rnext->mr_next;
3911 4111 }
3912 4112 /*
3913 4113 * If rnext is NULL, then no matching ddi_handle was found.
3914 4114 * Rx rings get registered first. So if this is a Tx ring,
3915 4115 * then go through all the Rx rings and see if there is a
3916 4116 * matching ddi handle.
3917 4117 */
3918 4118 if (rnext == NULL && ring->mr_type == MAC_RING_TYPE_TX) {
3919 4119 mac_compare_ddi_handle(mip->mi_rx_groups,
3920 4120 mip->mi_rx_group_count, ring);
3921 4121 }
3922 4122 }
3923 4123
3924 4124 /* Update ring's status */
3925 4125 ring->mr_state = MR_FREE;
3926 4126 ring->mr_flag = 0;
3927 4127
3928 4128 /* Update the ring count of the group */
3929 4129 group->mrg_cur_count++;
3930 4130
3931 4131 /* Create per ring kstats */
3932 4132 if (ring->mr_stat != NULL) {
3933 4133 ring->mr_mip = mip;
3934 4134 mac_ring_stat_create(ring);
3935 4135 }
3936 4136
3937 4137 return (ring);
3938 4138 }
3939 4139
3940 4140 /*
3941 4141 * Rings are chained together for easy regrouping.
3942 4142 */
3943 4143 static void
3944 4144 mac_init_group(mac_impl_t *mip, mac_group_t *group, int size,
3945 4145 mac_capab_rings_t *cap_rings)
3946 4146 {
3947 4147 int index;
3948 4148
3949 4149 /*
3950 4150 * Initialize all ring members of this group. Size of zero will not
3951 4151 * enter the loop, so it's safe for initializing an empty group.
3952 4152 */
3953 4153 for (index = size - 1; index >= 0; index--)
3954 4154 (void) mac_init_ring(mip, group, index, cap_rings);
3955 4155 }
3956 4156
3957 4157 int
3958 4158 mac_init_rings(mac_impl_t *mip, mac_ring_type_t rtype)
3959 4159 {
3960 4160 mac_capab_rings_t *cap_rings;
3961 4161 mac_group_t *group;
3962 4162 mac_group_t *groups;
3963 4163 mac_group_info_t group_info;
3964 4164 uint_t group_free = 0;
3965 4165 uint_t ring_left;
3966 4166 mac_ring_t *ring;
3967 4167 int g;
3968 4168 int err = 0;
3969 4169 uint_t grpcnt;
3970 4170 boolean_t pseudo_txgrp = B_FALSE;
3971 4171
3972 4172 switch (rtype) {
3973 4173 case MAC_RING_TYPE_RX:
3974 4174 ASSERT(mip->mi_rx_groups == NULL);
3975 4175
3976 4176 cap_rings = &mip->mi_rx_rings_cap;
3977 4177 cap_rings->mr_type = MAC_RING_TYPE_RX;
3978 4178 break;
3979 4179 case MAC_RING_TYPE_TX:
3980 4180 ASSERT(mip->mi_tx_groups == NULL);
3981 4181
3982 4182 cap_rings = &mip->mi_tx_rings_cap;
3983 4183 cap_rings->mr_type = MAC_RING_TYPE_TX;
3984 4184 break;
3985 4185 default:
3986 4186 ASSERT(B_FALSE);
3987 4187 }
3988 4188
3989 4189 if (!i_mac_capab_get((mac_handle_t)mip, MAC_CAPAB_RINGS, cap_rings))
3990 4190 return (0);
3991 4191 grpcnt = cap_rings->mr_gnum;
3992 4192
3993 4193 /*
3994 4194 * If we have multiple TX rings, but only one TX group, we can
3995 4195 * create pseudo TX groups (one per TX ring) in the MAC layer,
3996 4196 * except for an aggr. For an aggr currently we maintain only
3997 4197 * one group with all the rings (for all its ports), going
3998 4198 * forwards we might change this.
3999 4199 */
4000 4200 if (rtype == MAC_RING_TYPE_TX &&
4001 4201 cap_rings->mr_gnum == 0 && cap_rings->mr_rnum > 0 &&
4002 4202 (mip->mi_state_flags & MIS_IS_AGGR) == 0) {
4003 4203 /*
4004 4204 * The -1 here is because we create a default TX group
4005 4205 * with all the rings in it.
4006 4206 */
4007 4207 grpcnt = cap_rings->mr_rnum - 1;
4008 4208 pseudo_txgrp = B_TRUE;
4009 4209 }
4010 4210
4011 4211 /*
4012 4212 * Allocate a contiguous buffer for all groups.
4013 4213 */
4014 4214 groups = kmem_zalloc(sizeof (mac_group_t) * (grpcnt+ 1), KM_SLEEP);
4015 4215
4016 4216 ring_left = cap_rings->mr_rnum;
4017 4217
4018 4218 /*
4019 4219 * Get all ring groups if any, and get their ring members
4020 4220 * if any.
4021 4221 */
4022 4222 for (g = 0; g < grpcnt; g++) {
4023 4223 group = groups + g;
4024 4224
4025 4225 /* Prepare basic information of the group */
4026 4226 group->mrg_index = g;
4027 4227 group->mrg_type = rtype;
4028 4228 group->mrg_state = MAC_GROUP_STATE_UNINIT;
4029 4229 group->mrg_mh = (mac_handle_t)mip;
4030 4230 group->mrg_next = group + 1;
4031 4231
4032 4232 /* Zero to reuse the info data structure */
4033 4233 bzero(&group_info, sizeof (group_info));
4034 4234
4035 4235 if (pseudo_txgrp) {
4036 4236 /*
4037 4237 * This is a pseudo group that we created, apart
4038 4238 * from setting the state there is nothing to be
4039 4239 * done.
4040 4240 */
4041 4241 group->mrg_state = MAC_GROUP_STATE_REGISTERED;
4042 4242 group_free++;
4043 4243 continue;
4044 4244 }
4045 4245 /* Query group information from driver */
4046 4246 cap_rings->mr_gget(mip->mi_driver, rtype, g, &group_info,
4047 4247 (mac_group_handle_t)group);
4048 4248
4049 4249 switch (cap_rings->mr_group_type) {
4050 4250 case MAC_GROUP_TYPE_DYNAMIC:
4051 4251 if (cap_rings->mr_gaddring == NULL ||
4052 4252 cap_rings->mr_gremring == NULL) {
4053 4253 DTRACE_PROBE3(
4054 4254 mac__init__rings_no_addremring,
4055 4255 char *, mip->mi_name,
4056 4256 mac_group_add_ring_t,
4057 4257 cap_rings->mr_gaddring,
4058 4258 mac_group_add_ring_t,
4059 4259 cap_rings->mr_gremring);
4060 4260 err = EINVAL;
4061 4261 goto bail;
4062 4262 }
4063 4263
4064 4264 switch (rtype) {
4065 4265 case MAC_RING_TYPE_RX:
4066 4266 /*
4067 4267 * The first RX group must have non-zero
4068 4268 * rings, and the following groups must
4069 4269 * have zero rings.
4070 4270 */
4071 4271 if (g == 0 && group_info.mgi_count == 0) {
4072 4272 DTRACE_PROBE1(
4073 4273 mac__init__rings__rx__def__zero,
4074 4274 char *, mip->mi_name);
4075 4275 err = EINVAL;
4076 4276 goto bail;
4077 4277 }
4078 4278 if (g > 0 && group_info.mgi_count != 0) {
4079 4279 DTRACE_PROBE3(
4080 4280 mac__init__rings__rx__nonzero,
4081 4281 char *, mip->mi_name,
4082 4282 int, g, int, group_info.mgi_count);
4083 4283 err = EINVAL;
4084 4284 goto bail;
4085 4285 }
4086 4286 break;
4087 4287 case MAC_RING_TYPE_TX:
4088 4288 /*
4089 4289 * All TX ring groups must have zero rings.
4090 4290 */
4091 4291 if (group_info.mgi_count != 0) {
4092 4292 DTRACE_PROBE3(
4093 4293 mac__init__rings__tx__nonzero,
4094 4294 char *, mip->mi_name,
4095 4295 int, g, int, group_info.mgi_count);
4096 4296 err = EINVAL;
4097 4297 goto bail;
4098 4298 }
4099 4299 break;
4100 4300 }
4101 4301 break;
4102 4302 case MAC_GROUP_TYPE_STATIC:
4103 4303 /*
4104 4304 * Note that an empty group is allowed, e.g., an aggr
4105 4305 * would start with an empty group.
4106 4306 */
4107 4307 break;
4108 4308 default:
4109 4309 /* unknown group type */
4110 4310 DTRACE_PROBE2(mac__init__rings__unknown__type,
4111 4311 char *, mip->mi_name,
4112 4312 int, cap_rings->mr_group_type);
4113 4313 err = EINVAL;
4114 4314 goto bail;
4115 4315 }
4116 4316
4117 4317
4118 4318 /*
4119 4319 * The driver must register some form of hardware MAC
4120 4320 * filter in order for Rx groups to support multiple
4121 4321 * MAC addresses.
4122 4322 */
4123 4323 if (rtype == MAC_RING_TYPE_RX &&
4124 4324 (group_info.mgi_addmac == NULL ||
4125 4325 group_info.mgi_remmac == NULL)) {
4126 4326 DTRACE_PROBE1(mac__init__rings__no__mac__filter,
4127 4327 char *, mip->mi_name);
4128 4328 err = EINVAL;
4129 4329 goto bail;
4130 4330 }
4131 4331
4132 4332 /* Cache driver-supplied information */
4133 4333 group->mrg_info = group_info;
4134 4334
4135 4335 /* Update the group's status and group count. */
4136 4336 mac_set_group_state(group, MAC_GROUP_STATE_REGISTERED);
4137 4337 group_free++;
4138 4338
4139 4339 group->mrg_rings = NULL;
4140 4340 group->mrg_cur_count = 0;
4141 4341 mac_init_group(mip, group, group_info.mgi_count, cap_rings);
4142 4342 ring_left -= group_info.mgi_count;
4143 4343
4144 4344 /* The current group size should be equal to default value */
4145 4345 ASSERT(group->mrg_cur_count == group_info.mgi_count);
4146 4346 }
4147 4347
4148 4348 /* Build up a dummy group for free resources as a pool */
4149 4349 group = groups + grpcnt;
4150 4350
4151 4351 /* Prepare basic information of the group */
4152 4352 group->mrg_index = -1;
4153 4353 group->mrg_type = rtype;
4154 4354 group->mrg_state = MAC_GROUP_STATE_UNINIT;
4155 4355 group->mrg_mh = (mac_handle_t)mip;
4156 4356 group->mrg_next = NULL;
4157 4357
4158 4358 /*
4159 4359 * If there are ungrouped rings, allocate a continuous buffer for
4160 4360 * remaining resources.
4161 4361 */
4162 4362 if (ring_left != 0) {
4163 4363 group->mrg_rings = NULL;
4164 4364 group->mrg_cur_count = 0;
4165 4365 mac_init_group(mip, group, ring_left, cap_rings);
4166 4366
4167 4367 /* The current group size should be equal to ring_left */
4168 4368 ASSERT(group->mrg_cur_count == ring_left);
4169 4369
4170 4370 ring_left = 0;
4171 4371
4172 4372 /* Update this group's status */
4173 4373 mac_set_group_state(group, MAC_GROUP_STATE_REGISTERED);
4174 4374 } else {
4175 4375 group->mrg_rings = NULL;
4176 4376 }
4177 4377
4178 4378 ASSERT(ring_left == 0);
4179 4379
4180 4380 bail:
4181 4381
4182 4382 /* Cache other important information to finalize the initialization */
4183 4383 switch (rtype) {
4184 4384 case MAC_RING_TYPE_RX:
4185 4385 mip->mi_rx_group_type = cap_rings->mr_group_type;
4186 4386 mip->mi_rx_group_count = cap_rings->mr_gnum;
4187 4387 mip->mi_rx_groups = groups;
4188 4388 mip->mi_rx_donor_grp = groups;
4189 4389 if (mip->mi_rx_group_type == MAC_GROUP_TYPE_DYNAMIC) {
4190 4390 /*
4191 4391 * The default ring is reserved since it is
4192 4392 * used for sending the broadcast etc. packets.
4193 4393 */
4194 4394 mip->mi_rxrings_avail =
4195 4395 mip->mi_rx_groups->mrg_cur_count - 1;
4196 4396 mip->mi_rxrings_rsvd = 1;
4197 4397 }
4198 4398 /*
4199 4399 * The default group cannot be reserved. It is used by
4200 4400 * all the clients that do not have an exclusive group.
4201 4401 */
4202 4402 mip->mi_rxhwclnt_avail = mip->mi_rx_group_count - 1;
4203 4403 mip->mi_rxhwclnt_used = 1;
4204 4404 break;
4205 4405 case MAC_RING_TYPE_TX:
4206 4406 mip->mi_tx_group_type = pseudo_txgrp ? MAC_GROUP_TYPE_DYNAMIC :
4207 4407 cap_rings->mr_group_type;
4208 4408 mip->mi_tx_group_count = grpcnt;
4209 4409 mip->mi_tx_group_free = group_free;
4210 4410 mip->mi_tx_groups = groups;
4211 4411
4212 4412 group = groups + grpcnt;
4213 4413 ring = group->mrg_rings;
4214 4414 /*
4215 4415 * The ring can be NULL in the case of aggr. Aggr will
4216 4416 * have an empty Tx group which will get populated
4217 4417 * later when pseudo Tx rings are added after
4218 4418 * mac_register() is done.
4219 4419 */
4220 4420 if (ring == NULL) {
4221 4421 ASSERT(mip->mi_state_flags & MIS_IS_AGGR);
4222 4422 /*
4223 4423 * pass the group to aggr so it can add Tx
4224 4424 * rings to the group later.
4225 4425 */
4226 4426 cap_rings->mr_gget(mip->mi_driver, rtype, 0, NULL,
4227 4427 (mac_group_handle_t)group);
4228 4428 /*
4229 4429 * Even though there are no rings at this time
4230 4430 * (rings will come later), set the group
4231 4431 * state to registered.
4232 4432 */
4233 4433 group->mrg_state = MAC_GROUP_STATE_REGISTERED;
4234 4434 } else {
4235 4435 /*
4236 4436 * Ring 0 is used as the default one and it could be
4237 4437 * assigned to a client as well.
4238 4438 */
4239 4439 while ((ring->mr_index != 0) && (ring->mr_next != NULL))
4240 4440 ring = ring->mr_next;
4241 4441 ASSERT(ring->mr_index == 0);
4242 4442 mip->mi_default_tx_ring = (mac_ring_handle_t)ring;
4243 4443 }
4244 4444 if (mip->mi_tx_group_type == MAC_GROUP_TYPE_DYNAMIC) {
4245 4445 mip->mi_txrings_avail = group->mrg_cur_count - 1;
4246 4446 /*
4247 4447 * The default ring cannot be reserved.
4248 4448 */
4249 4449 mip->mi_txrings_rsvd = 1;
4250 4450 }
4251 4451 /*
4252 4452 * The default group cannot be reserved. It will be shared
4253 4453 * by clients that do not have an exclusive group.
4254 4454 */
4255 4455 mip->mi_txhwclnt_avail = mip->mi_tx_group_count;
4256 4456 mip->mi_txhwclnt_used = 1;
4257 4457 break;
4258 4458 default:
4259 4459 ASSERT(B_FALSE);
4260 4460 }
4261 4461
4262 4462 if (err != 0)
4263 4463 mac_free_rings(mip, rtype);
4264 4464
4265 4465 return (err);
4266 4466 }
4267 4467
4268 4468 /*
4269 4469 * The ddi interrupt handle could be shared amoung rings. If so, compare
4270 4470 * the new ring's ddi handle with the existing ones and set ddi_shared
4271 4471 * flag.
4272 4472 */
4273 4473 void
4274 4474 mac_compare_ddi_handle(mac_group_t *groups, uint_t grpcnt, mac_ring_t *cring)
4275 4475 {
4276 4476 mac_group_t *group;
4277 4477 mac_ring_t *ring;
4278 4478 ddi_intr_handle_t ddi_handle;
4279 4479 int g;
4280 4480
4281 4481 ddi_handle = cring->mr_info.mri_intr.mi_ddi_handle;
4282 4482 for (g = 0; g < grpcnt; g++) {
4283 4483 group = groups + g;
4284 4484 for (ring = group->mrg_rings; ring != NULL;
4285 4485 ring = ring->mr_next) {
4286 4486 if (ring == cring)
4287 4487 continue;
4288 4488 if (ring->mr_info.mri_intr.mi_ddi_handle ==
4289 4489 ddi_handle) {
4290 4490 if (cring->mr_type == MAC_RING_TYPE_RX &&
4291 4491 ring->mr_index == 0 &&
4292 4492 !ring->mr_info.mri_intr.mi_ddi_shared) {
4293 4493 ring->mr_info.mri_intr.mi_ddi_shared =
4294 4494 B_TRUE;
4295 4495 } else {
4296 4496 cring->mr_info.mri_intr.mi_ddi_shared =
4297 4497 B_TRUE;
4298 4498 }
4299 4499 return;
4300 4500 }
4301 4501 }
4302 4502 }
4303 4503 }
4304 4504
4305 4505 /*
4306 4506 * Called to free all groups of particular type (RX or TX). It's assumed that
4307 4507 * no clients are using these groups.
4308 4508 */
4309 4509 void
4310 4510 mac_free_rings(mac_impl_t *mip, mac_ring_type_t rtype)
4311 4511 {
4312 4512 mac_group_t *group, *groups;
4313 4513 uint_t group_count;
4314 4514
4315 4515 switch (rtype) {
4316 4516 case MAC_RING_TYPE_RX:
4317 4517 if (mip->mi_rx_groups == NULL)
4318 4518 return;
4319 4519
4320 4520 groups = mip->mi_rx_groups;
4321 4521 group_count = mip->mi_rx_group_count;
4322 4522
4323 4523 mip->mi_rx_groups = NULL;
4324 4524 mip->mi_rx_donor_grp = NULL;
4325 4525 mip->mi_rx_group_count = 0;
4326 4526 break;
4327 4527 case MAC_RING_TYPE_TX:
4328 4528 ASSERT(mip->mi_tx_group_count == mip->mi_tx_group_free);
4329 4529
4330 4530 if (mip->mi_tx_groups == NULL)
4331 4531 return;
4332 4532
4333 4533 groups = mip->mi_tx_groups;
4334 4534 group_count = mip->mi_tx_group_count;
4335 4535
4336 4536 mip->mi_tx_groups = NULL;
4337 4537 mip->mi_tx_group_count = 0;
4338 4538 mip->mi_tx_group_free = 0;
4339 4539 mip->mi_default_tx_ring = NULL;
4340 4540 break;
4341 4541 default:
4342 4542 ASSERT(B_FALSE);
4343 4543 }
4344 4544
4345 4545 for (group = groups; group != NULL; group = group->mrg_next) {
4346 4546 mac_ring_t *ring;
4347 4547
4348 4548 if (group->mrg_cur_count == 0)
4349 4549 continue;
4350 4550
4351 4551 ASSERT(group->mrg_rings != NULL);
4352 4552
4353 4553 while ((ring = group->mrg_rings) != NULL) {
4354 4554 group->mrg_rings = ring->mr_next;
4355 4555 mac_ring_free(mip, ring);
4356 4556 }
4357 4557 }
4358 4558
4359 4559 /* Free all the cached rings */
4360 4560 mac_ring_freeall(mip);
4361 4561 /* Free the block of group data strutures */
4362 4562 kmem_free(groups, sizeof (mac_group_t) * (group_count + 1));
4363 4563 }
4364 4564
4365 4565 /*
4366 4566 * Associate the VLAN filter to the receive group.
4367 4567 */
4368 4568 int
4369 4569 mac_group_addvlan(mac_group_t *group, uint16_t vlan)
4370 4570 {
4371 4571 VERIFY3S(group->mrg_type, ==, MAC_RING_TYPE_RX);
4372 4572 VERIFY3P(group->mrg_info.mgi_addvlan, !=, NULL);
4373 4573
4374 4574 if (vlan > VLAN_ID_MAX)
4375 4575 return (EINVAL);
4376 4576
4377 4577 vlan = MAC_VLAN_UNTAGGED_VID(vlan);
4378 4578 return (group->mrg_info.mgi_addvlan(group->mrg_info.mgi_driver, vlan));
4379 4579 }
4380 4580
4381 4581 /*
4382 4582 * Dissociate the VLAN from the receive group.
4383 4583 */
4384 4584 int
4385 4585 mac_group_remvlan(mac_group_t *group, uint16_t vlan)
4386 4586 {
4387 4587 VERIFY3S(group->mrg_type, ==, MAC_RING_TYPE_RX);
4388 4588 VERIFY3P(group->mrg_info.mgi_remvlan, !=, NULL);
4389 4589
4390 4590 if (vlan > VLAN_ID_MAX)
4391 4591 return (EINVAL);
4392 4592
4393 4593 vlan = MAC_VLAN_UNTAGGED_VID(vlan);
4394 4594 return (group->mrg_info.mgi_remvlan(group->mrg_info.mgi_driver, vlan));
4395 4595 }
4396 4596
4397 4597 /*
4398 4598 * Associate a MAC address with a receive group.
4399 4599 *
4400 4600 * The return value of this function should always be checked properly, because
4401 4601 * any type of failure could cause unexpected results. A group can be added
4402 4602 * or removed with a MAC address only after it has been reserved. Ideally,
4403 4603 * a successful reservation always leads to calling mac_group_addmac() to
4404 4604 * steer desired traffic. Failure of adding an unicast MAC address doesn't
4405 4605 * always imply that the group is functioning abnormally.
4406 4606 *
4407 4607 * Currently this function is called everywhere, and it reflects assumptions
4408 4608 * about MAC addresses in the implementation. CR 6735196.
4409 4609 */
4410 4610 int
4411 4611 mac_group_addmac(mac_group_t *group, const uint8_t *addr)
4412 4612 {
4413 4613 VERIFY3S(group->mrg_type, ==, MAC_RING_TYPE_RX);
4414 4614 VERIFY3P(group->mrg_info.mgi_addmac, !=, NULL);
4415 4615
4416 4616 return (group->mrg_info.mgi_addmac(group->mrg_info.mgi_driver, addr));
4417 4617 }
4418 4618
4419 4619 /*
4420 4620 * Remove the association between MAC address and receive group.
4421 4621 */
4422 4622 int
4423 4623 mac_group_remmac(mac_group_t *group, const uint8_t *addr)
4424 4624 {
4425 4625 VERIFY3S(group->mrg_type, ==, MAC_RING_TYPE_RX);
4426 4626 VERIFY3P(group->mrg_info.mgi_remmac, !=, NULL);
4427 4627
4428 4628 return (group->mrg_info.mgi_remmac(group->mrg_info.mgi_driver, addr));
4429 4629 }
4430 4630
4431 4631 /*
4432 4632 * This is the entry point for packets transmitted through the bridging code.
4433 4633 * If no bridge is in place, MAC_RING_TX transmits using tx ring. The 'rh'
4434 4634 * pointer may be NULL to select the default ring.
4435 4635 */
4436 4636 mblk_t *
4437 4637 mac_bridge_tx(mac_impl_t *mip, mac_ring_handle_t rh, mblk_t *mp)
4438 4638 {
4439 4639 mac_handle_t mh;
4440 4640
4441 4641 /*
4442 4642 * Once we take a reference on the bridge link, the bridge
4443 4643 * module itself can't unload, so the callback pointers are
4444 4644 * stable.
4445 4645 */
4446 4646 mutex_enter(&mip->mi_bridge_lock);
4447 4647 if ((mh = mip->mi_bridge_link) != NULL)
4448 4648 mac_bridge_ref_cb(mh, B_TRUE);
4449 4649 mutex_exit(&mip->mi_bridge_lock);
4450 4650 if (mh == NULL) {
4451 4651 MAC_RING_TX(mip, rh, mp, mp);
4452 4652 } else {
4453 4653 mp = mac_bridge_tx_cb(mh, rh, mp);
4454 4654 mac_bridge_ref_cb(mh, B_FALSE);
4455 4655 }
4456 4656
4457 4657 return (mp);
4458 4658 }
4459 4659
4460 4660 /*
4461 4661 * Find a ring from its index.
4462 4662 */
4463 4663 mac_ring_handle_t
4464 4664 mac_find_ring(mac_group_handle_t gh, int index)
4465 4665 {
4466 4666 mac_group_t *group = (mac_group_t *)gh;
4467 4667 mac_ring_t *ring = group->mrg_rings;
4468 4668
4469 4669 for (ring = group->mrg_rings; ring != NULL; ring = ring->mr_next)
4470 4670 if (ring->mr_index == index)
4471 4671 break;
4472 4672
4473 4673 return ((mac_ring_handle_t)ring);
4474 4674 }
4475 4675 /*
4476 4676 * Add a ring to an existing group.
4477 4677 *
4478 4678 * The ring must be either passed directly (for example if the ring
4479 4679 * movement is initiated by the framework), or specified through a driver
4480 4680 * index (for example when the ring is added by the driver.
4481 4681 *
4482 4682 * The caller needs to call mac_perim_enter() before calling this function.
4483 4683 */
4484 4684 int
4485 4685 i_mac_group_add_ring(mac_group_t *group, mac_ring_t *ring, int index)
4486 4686 {
4487 4687 mac_impl_t *mip = (mac_impl_t *)group->mrg_mh;
4488 4688 mac_capab_rings_t *cap_rings;
4489 4689 boolean_t driver_call = (ring == NULL);
4490 4690 mac_group_type_t group_type;
4491 4691 int ret = 0;
4492 4692 flow_entry_t *flent;
4493 4693
4494 4694 ASSERT(MAC_PERIM_HELD((mac_handle_t)mip));
4495 4695
4496 4696 switch (group->mrg_type) {
4497 4697 case MAC_RING_TYPE_RX:
4498 4698 cap_rings = &mip->mi_rx_rings_cap;
4499 4699 group_type = mip->mi_rx_group_type;
4500 4700 break;
4501 4701 case MAC_RING_TYPE_TX:
4502 4702 cap_rings = &mip->mi_tx_rings_cap;
4503 4703 group_type = mip->mi_tx_group_type;
4504 4704 break;
4505 4705 default:
4506 4706 ASSERT(B_FALSE);
4507 4707 }
4508 4708
4509 4709 /*
4510 4710 * There should be no ring with the same ring index in the target
4511 4711 * group.
4512 4712 */
4513 4713 ASSERT(mac_find_ring((mac_group_handle_t)group,
4514 4714 driver_call ? index : ring->mr_index) == NULL);
4515 4715
4516 4716 if (driver_call) {
4517 4717 /*
4518 4718 * The function is called as a result of a request from
4519 4719 * a driver to add a ring to an existing group, for example
4520 4720 * from the aggregation driver. Allocate a new mac_ring_t
4521 4721 * for that ring.
4522 4722 */
4523 4723 ring = mac_init_ring(mip, group, index, cap_rings);
4524 4724 ASSERT(group->mrg_state > MAC_GROUP_STATE_UNINIT);
4525 4725 } else {
4526 4726 /*
4527 4727 * The function is called as a result of a MAC layer request
4528 4728 * to add a ring to an existing group. In this case the
4529 4729 * ring is being moved between groups, which requires
4530 4730 * the underlying driver to support dynamic grouping,
4531 4731 * and the mac_ring_t already exists.
4532 4732 */
4533 4733 ASSERT(group_type == MAC_GROUP_TYPE_DYNAMIC);
4534 4734 ASSERT(group->mrg_driver == NULL ||
4535 4735 cap_rings->mr_gaddring != NULL);
4536 4736 ASSERT(ring->mr_gh == NULL);
4537 4737 }
4538 4738
4539 4739 /*
4540 4740 * At this point the ring should not be in use, and it should be
4541 4741 * of the right for the target group.
4542 4742 */
4543 4743 ASSERT(ring->mr_state < MR_INUSE);
4544 4744 ASSERT(ring->mr_srs == NULL);
4545 4745 ASSERT(ring->mr_type == group->mrg_type);
4546 4746
4547 4747 if (!driver_call) {
4548 4748 /*
4549 4749 * Add the driver level hardware ring if the process was not
4550 4750 * initiated by the driver, and the target group is not the
4551 4751 * group.
4552 4752 */
4553 4753 if (group->mrg_driver != NULL) {
4554 4754 cap_rings->mr_gaddring(group->mrg_driver,
4555 4755 ring->mr_driver, ring->mr_type);
4556 4756 }
4557 4757
4558 4758 /*
4559 4759 * Insert the ring ahead existing rings.
4560 4760 */
4561 4761 ring->mr_next = group->mrg_rings;
4562 4762 group->mrg_rings = ring;
4563 4763 ring->mr_gh = (mac_group_handle_t)group;
4564 4764 group->mrg_cur_count++;
4565 4765 }
4566 4766
4567 4767 /*
4568 4768 * If the group has not been actively used, we're done.
4569 4769 */
4570 4770 if (group->mrg_index != -1 &&
4571 4771 group->mrg_state < MAC_GROUP_STATE_RESERVED)
4572 4772 return (0);
4573 4773
4574 4774 /*
4575 4775 * Start the ring if needed. Failure causes to undo the grouping action.
4576 4776 */
4577 4777 if (ring->mr_state != MR_INUSE) {
4578 4778 if ((ret = mac_start_ring(ring)) != 0) {
4579 4779 if (!driver_call) {
4580 4780 cap_rings->mr_gremring(group->mrg_driver,
4581 4781 ring->mr_driver, ring->mr_type);
4582 4782 }
4583 4783 group->mrg_cur_count--;
4584 4784 group->mrg_rings = ring->mr_next;
4585 4785
4586 4786 ring->mr_gh = NULL;
4587 4787
4588 4788 if (driver_call)
4589 4789 mac_ring_free(mip, ring);
4590 4790
4591 4791 return (ret);
4592 4792 }
4593 4793 }
4594 4794
4595 4795 /*
4596 4796 * Set up SRS/SR according to the ring type.
4597 4797 */
4598 4798 switch (ring->mr_type) {
4599 4799 case MAC_RING_TYPE_RX:
4600 4800 /*
4601 4801 * Setup an SRS on top of the new ring if the group is
4602 4802 * reserved for someone's exclusive use.
4603 4803 */
4604 4804 if (group->mrg_state == MAC_GROUP_STATE_RESERVED) {
4605 4805 mac_client_impl_t *mcip = MAC_GROUP_ONLY_CLIENT(group);
4606 4806
4607 4807 VERIFY3P(mcip, !=, NULL);
4608 4808 flent = mcip->mci_flent;
4609 4809 VERIFY3S(flent->fe_rx_srs_cnt, >, 0);
4610 4810 mac_rx_srs_group_setup(mcip, flent, SRST_LINK);
4611 4811 mac_fanout_setup(mcip, flent, MCIP_RESOURCE_PROPS(mcip),
4612 4812 mac_rx_deliver, mcip, NULL, NULL);
4613 4813 } else {
4614 4814 ring->mr_classify_type = MAC_SW_CLASSIFIER;
4615 4815 }
4616 4816 break;
4617 4817 case MAC_RING_TYPE_TX:
4618 4818 {
4619 4819 mac_grp_client_t *mgcp = group->mrg_clients;
4620 4820 mac_client_impl_t *mcip;
4621 4821 mac_soft_ring_set_t *mac_srs;
4622 4822 mac_srs_tx_t *tx;
4623 4823
4624 4824 if (MAC_GROUP_NO_CLIENT(group)) {
4625 4825 if (ring->mr_state == MR_INUSE)
4626 4826 mac_stop_ring(ring);
4627 4827 ring->mr_flag = 0;
4628 4828 break;
4629 4829 }
4630 4830 /*
4631 4831 * If the rings are being moved to a group that has
4632 4832 * clients using it, then add the new rings to the
4633 4833 * clients SRS.
4634 4834 */
4635 4835 while (mgcp != NULL) {
4636 4836 boolean_t is_aggr;
4637 4837
4638 4838 mcip = mgcp->mgc_client;
4639 4839 flent = mcip->mci_flent;
4640 4840 is_aggr = (mcip->mci_state_flags & MCIS_IS_AGGR_CLIENT);
4641 4841 mac_srs = MCIP_TX_SRS(mcip);
4642 4842 tx = &mac_srs->srs_tx;
4643 4843 mac_tx_client_quiesce((mac_client_handle_t)mcip);
4644 4844 /*
4645 4845 * If we are growing from 1 to multiple rings.
4646 4846 */
4647 4847 if (tx->st_mode == SRS_TX_BW ||
4648 4848 tx->st_mode == SRS_TX_SERIALIZE ||
4649 4849 tx->st_mode == SRS_TX_DEFAULT) {
4650 4850 mac_ring_t *tx_ring = tx->st_arg2;
4651 4851
4652 4852 tx->st_arg2 = NULL;
4653 4853 mac_tx_srs_stat_recreate(mac_srs, B_TRUE);
4654 4854 mac_tx_srs_add_ring(mac_srs, tx_ring);
4655 4855 if (mac_srs->srs_type & SRST_BW_CONTROL) {
4656 4856 tx->st_mode = is_aggr ? SRS_TX_BW_AGGR :
4657 4857 SRS_TX_BW_FANOUT;
4658 4858 } else {
4659 4859 tx->st_mode = is_aggr ? SRS_TX_AGGR :
4660 4860 SRS_TX_FANOUT;
4661 4861 }
4662 4862 tx->st_func = mac_tx_get_func(tx->st_mode);
4663 4863 }
4664 4864 mac_tx_srs_add_ring(mac_srs, ring);
4665 4865 mac_fanout_setup(mcip, flent, MCIP_RESOURCE_PROPS(mcip),
4666 4866 mac_rx_deliver, mcip, NULL, NULL);
4667 4867 mac_tx_client_restart((mac_client_handle_t)mcip);
4668 4868 mgcp = mgcp->mgc_next;
4669 4869 }
4670 4870 break;
4671 4871 }
4672 4872 default:
4673 4873 ASSERT(B_FALSE);
4674 4874 }
4675 4875 /*
4676 4876 * For aggr, the default ring will be NULL to begin with. If it
4677 4877 * is NULL, then pick the first ring that gets added as the
4678 4878 * default ring. Any ring in an aggregation can be removed at
4679 4879 * any time (by the user action of removing a link) and if the
4680 4880 * current default ring gets removed, then a new one gets
4681 4881 * picked (see i_mac_group_rem_ring()).
4682 4882 */
4683 4883 if (mip->mi_state_flags & MIS_IS_AGGR &&
4684 4884 mip->mi_default_tx_ring == NULL &&
4685 4885 ring->mr_type == MAC_RING_TYPE_TX) {
4686 4886 mip->mi_default_tx_ring = (mac_ring_handle_t)ring;
4687 4887 }
4688 4888
4689 4889 MAC_RING_UNMARK(ring, MR_INCIPIENT);
4690 4890 return (0);
4691 4891 }
4692 4892
4693 4893 /*
4694 4894 * Remove a ring from it's current group. MAC internal function for dynamic
4695 4895 * grouping.
4696 4896 *
4697 4897 * The caller needs to call mac_perim_enter() before calling this function.
4698 4898 */
4699 4899 void
4700 4900 i_mac_group_rem_ring(mac_group_t *group, mac_ring_t *ring,
4701 4901 boolean_t driver_call)
4702 4902 {
4703 4903 mac_impl_t *mip = (mac_impl_t *)group->mrg_mh;
4704 4904 mac_capab_rings_t *cap_rings = NULL;
4705 4905 mac_group_type_t group_type;
4706 4906
4707 4907 ASSERT(MAC_PERIM_HELD((mac_handle_t)mip));
4708 4908
4709 4909 ASSERT(mac_find_ring((mac_group_handle_t)group,
4710 4910 ring->mr_index) == (mac_ring_handle_t)ring);
4711 4911 ASSERT((mac_group_t *)ring->mr_gh == group);
4712 4912 ASSERT(ring->mr_type == group->mrg_type);
4713 4913
4714 4914 if (ring->mr_state == MR_INUSE)
4715 4915 mac_stop_ring(ring);
4716 4916 switch (ring->mr_type) {
4717 4917 case MAC_RING_TYPE_RX:
4718 4918 group_type = mip->mi_rx_group_type;
4719 4919 cap_rings = &mip->mi_rx_rings_cap;
4720 4920
4721 4921 /*
4722 4922 * Only hardware classified packets hold a reference to the
4723 4923 * ring all the way up the Rx path. mac_rx_srs_remove()
4724 4924 * will take care of quiescing the Rx path and removing the
4725 4925 * SRS. The software classified path neither holds a reference
4726 4926 * nor any association with the ring in mac_rx.
4727 4927 */
4728 4928 if (ring->mr_srs != NULL) {
4729 4929 mac_rx_srs_remove(ring->mr_srs);
4730 4930 ring->mr_srs = NULL;
4731 4931 }
4732 4932
4733 4933 break;
4734 4934 case MAC_RING_TYPE_TX:
4735 4935 {
4736 4936 mac_grp_client_t *mgcp;
4737 4937 mac_client_impl_t *mcip;
4738 4938 mac_soft_ring_set_t *mac_srs;
4739 4939 mac_srs_tx_t *tx;
4740 4940 mac_ring_t *rem_ring;
4741 4941 mac_group_t *defgrp;
4742 4942 uint_t ring_info = 0;
4743 4943
4744 4944 /*
4745 4945 * For TX this function is invoked in three
4746 4946 * cases:
4747 4947 *
4748 4948 * 1) In the case of a failure during the
4749 4949 * initial creation of a group when a share is
4750 4950 * associated with a MAC client. So the SRS is not
4751 4951 * yet setup, and will be setup later after the
4752 4952 * group has been reserved and populated.
4753 4953 *
4754 4954 * 2) From mac_release_tx_group() when freeing
4755 4955 * a TX SRS.
4756 4956 *
4757 4957 * 3) In the case of aggr, when a port gets removed,
4758 4958 * the pseudo Tx rings that it exposed gets removed.
4759 4959 *
4760 4960 * In the first two cases the SRS and its soft
4761 4961 * rings are already quiesced.
4762 4962 */
4763 4963 if (driver_call) {
4764 4964 mac_client_impl_t *mcip;
4765 4965 mac_soft_ring_set_t *mac_srs;
4766 4966 mac_soft_ring_t *sringp;
4767 4967 mac_srs_tx_t *srs_tx;
4768 4968
4769 4969 if (mip->mi_state_flags & MIS_IS_AGGR &&
4770 4970 mip->mi_default_tx_ring ==
4771 4971 (mac_ring_handle_t)ring) {
4772 4972 /* pick a new default Tx ring */
4773 4973 mip->mi_default_tx_ring =
4774 4974 (group->mrg_rings != ring) ?
4775 4975 (mac_ring_handle_t)group->mrg_rings :
4776 4976 (mac_ring_handle_t)(ring->mr_next);
4777 4977 }
4778 4978 /* Presently only aggr case comes here */
4779 4979 if (group->mrg_state != MAC_GROUP_STATE_RESERVED)
4780 4980 break;
4781 4981
4782 4982 mcip = MAC_GROUP_ONLY_CLIENT(group);
4783 4983 ASSERT(mcip != NULL);
4784 4984 ASSERT(mcip->mci_state_flags & MCIS_IS_AGGR_CLIENT);
4785 4985 mac_srs = MCIP_TX_SRS(mcip);
4786 4986 ASSERT(mac_srs->srs_tx.st_mode == SRS_TX_AGGR ||
4787 4987 mac_srs->srs_tx.st_mode == SRS_TX_BW_AGGR);
4788 4988 srs_tx = &mac_srs->srs_tx;
4789 4989 /*
4790 4990 * Wakeup any callers blocked on this
4791 4991 * Tx ring due to flow control.
4792 4992 */
4793 4993 sringp = srs_tx->st_soft_rings[ring->mr_index];
4794 4994 ASSERT(sringp != NULL);
4795 4995 mac_tx_invoke_callbacks(mcip, (mac_tx_cookie_t)sringp);
4796 4996 mac_tx_client_quiesce((mac_client_handle_t)mcip);
4797 4997 mac_tx_srs_del_ring(mac_srs, ring);
4798 4998 mac_tx_client_restart((mac_client_handle_t)mcip);
4799 4999 break;
4800 5000 }
4801 5001 ASSERT(ring != (mac_ring_t *)mip->mi_default_tx_ring);
4802 5002 group_type = mip->mi_tx_group_type;
4803 5003 cap_rings = &mip->mi_tx_rings_cap;
4804 5004 /*
4805 5005 * See if we need to take it out of the MAC clients using
4806 5006 * this group
4807 5007 */
4808 5008 if (MAC_GROUP_NO_CLIENT(group))
4809 5009 break;
4810 5010 mgcp = group->mrg_clients;
4811 5011 defgrp = MAC_DEFAULT_TX_GROUP(mip);
4812 5012 while (mgcp != NULL) {
4813 5013 mcip = mgcp->mgc_client;
4814 5014 mac_srs = MCIP_TX_SRS(mcip);
4815 5015 tx = &mac_srs->srs_tx;
4816 5016 mac_tx_client_quiesce((mac_client_handle_t)mcip);
4817 5017 /*
4818 5018 * If we are here when removing rings from the
4819 5019 * defgroup, mac_reserve_tx_ring would have
4820 5020 * already deleted the ring from the MAC
4821 5021 * clients in the group.
4822 5022 */
4823 5023 if (group != defgrp) {
4824 5024 mac_tx_invoke_callbacks(mcip,
4825 5025 (mac_tx_cookie_t)
4826 5026 mac_tx_srs_get_soft_ring(mac_srs, ring));
4827 5027 mac_tx_srs_del_ring(mac_srs, ring);
4828 5028 }
4829 5029 /*
4830 5030 * Additionally, if we are left with only
4831 5031 * one ring in the group after this, we need
4832 5032 * to modify the mode etc. to. (We haven't
4833 5033 * yet taken the ring out, so we check with 2).
4834 5034 */
4835 5035 if (group->mrg_cur_count == 2) {
4836 5036 if (ring->mr_next == NULL)
4837 5037 rem_ring = group->mrg_rings;
4838 5038 else
4839 5039 rem_ring = ring->mr_next;
4840 5040 mac_tx_invoke_callbacks(mcip,
4841 5041 (mac_tx_cookie_t)
4842 5042 mac_tx_srs_get_soft_ring(mac_srs,
4843 5043 rem_ring));
4844 5044 mac_tx_srs_del_ring(mac_srs, rem_ring);
4845 5045 if (rem_ring->mr_state != MR_INUSE) {
4846 5046 (void) mac_start_ring(rem_ring);
4847 5047 }
4848 5048 tx->st_arg2 = (void *)rem_ring;
4849 5049 mac_tx_srs_stat_recreate(mac_srs, B_FALSE);
4850 5050 ring_info = mac_hwring_getinfo(
4851 5051 (mac_ring_handle_t)rem_ring);
4852 5052 /*
4853 5053 * We are shrinking from multiple
4854 5054 * to 1 ring.
4855 5055 */
4856 5056 if (mac_srs->srs_type & SRST_BW_CONTROL) {
4857 5057 tx->st_mode = SRS_TX_BW;
4858 5058 } else if (mac_tx_serialize ||
4859 5059 (ring_info & MAC_RING_TX_SERIALIZE)) {
4860 5060 tx->st_mode = SRS_TX_SERIALIZE;
4861 5061 } else {
4862 5062 tx->st_mode = SRS_TX_DEFAULT;
4863 5063 }
4864 5064 tx->st_func = mac_tx_get_func(tx->st_mode);
4865 5065 }
4866 5066 mac_tx_client_restart((mac_client_handle_t)mcip);
4867 5067 mgcp = mgcp->mgc_next;
4868 5068 }
4869 5069 break;
4870 5070 }
4871 5071 default:
4872 5072 ASSERT(B_FALSE);
4873 5073 }
4874 5074
4875 5075 /*
4876 5076 * Remove the ring from the group.
4877 5077 */
4878 5078 if (ring == group->mrg_rings)
4879 5079 group->mrg_rings = ring->mr_next;
4880 5080 else {
4881 5081 mac_ring_t *pre;
4882 5082
4883 5083 pre = group->mrg_rings;
4884 5084 while (pre->mr_next != ring)
4885 5085 pre = pre->mr_next;
4886 5086 pre->mr_next = ring->mr_next;
4887 5087 }
4888 5088 group->mrg_cur_count--;
4889 5089
4890 5090 if (!driver_call) {
4891 5091 ASSERT(group_type == MAC_GROUP_TYPE_DYNAMIC);
4892 5092 ASSERT(group->mrg_driver == NULL ||
4893 5093 cap_rings->mr_gremring != NULL);
4894 5094
4895 5095 /*
4896 5096 * Remove the driver level hardware ring.
4897 5097 */
4898 5098 if (group->mrg_driver != NULL) {
4899 5099 cap_rings->mr_gremring(group->mrg_driver,
4900 5100 ring->mr_driver, ring->mr_type);
4901 5101 }
4902 5102 }
4903 5103
4904 5104 ring->mr_gh = NULL;
4905 5105 if (driver_call)
4906 5106 mac_ring_free(mip, ring);
4907 5107 else
4908 5108 ring->mr_flag = 0;
4909 5109 }
4910 5110
4911 5111 /*
4912 5112 * Move a ring to the target group. If needed, remove the ring from the group
4913 5113 * that it currently belongs to.
4914 5114 *
4915 5115 * The caller need to enter MAC's perimeter by calling mac_perim_enter().
4916 5116 */
4917 5117 static int
4918 5118 mac_group_mov_ring(mac_impl_t *mip, mac_group_t *d_group, mac_ring_t *ring)
4919 5119 {
4920 5120 mac_group_t *s_group = (mac_group_t *)ring->mr_gh;
4921 5121 int rv;
4922 5122
4923 5123 ASSERT(MAC_PERIM_HELD((mac_handle_t)mip));
4924 5124 ASSERT(d_group != NULL);
4925 5125 ASSERT(s_group == NULL || s_group->mrg_mh == d_group->mrg_mh);
4926 5126
4927 5127 if (s_group == d_group)
4928 5128 return (0);
4929 5129
4930 5130 /*
4931 5131 * Remove it from current group first.
4932 5132 */
4933 5133 if (s_group != NULL)
4934 5134 i_mac_group_rem_ring(s_group, ring, B_FALSE);
4935 5135
4936 5136 /*
4937 5137 * Add it to the new group.
4938 5138 */
4939 5139 rv = i_mac_group_add_ring(d_group, ring, 0);
4940 5140 if (rv != 0) {
4941 5141 /*
4942 5142 * Failed to add ring back to source group. If
4943 5143 * that fails, the ring is stuck in limbo, log message.
4944 5144 */
4945 5145 if (i_mac_group_add_ring(s_group, ring, 0)) {
4946 5146 cmn_err(CE_WARN, "%s: failed to move ring %p\n",
4947 5147 mip->mi_name, (void *)ring);
4948 5148 }
4949 5149 }
4950 5150
4951 5151 return (rv);
4952 5152 }
4953 5153
4954 5154 /*
4955 5155 * Find a MAC address according to its value.
4956 5156 */
4957 5157 mac_address_t *
4958 5158 mac_find_macaddr(mac_impl_t *mip, uint8_t *mac_addr)
4959 5159 {
4960 5160 mac_address_t *map;
4961 5161
4962 5162 ASSERT(MAC_PERIM_HELD((mac_handle_t)mip));
4963 5163
4964 5164 for (map = mip->mi_addresses; map != NULL; map = map->ma_next) {
4965 5165 if (bcmp(mac_addr, map->ma_addr, map->ma_len) == 0)
4966 5166 break;
4967 5167 }
4968 5168
4969 5169 return (map);
4970 5170 }
4971 5171
4972 5172 /*
4973 5173 * Check whether the MAC address is shared by multiple clients.
4974 5174 */
4975 5175 boolean_t
4976 5176 mac_check_macaddr_shared(mac_address_t *map)
4977 5177 {
4978 5178 ASSERT(MAC_PERIM_HELD((mac_handle_t)map->ma_mip));
4979 5179
4980 5180 return (map->ma_nusers > 1);
4981 5181 }
4982 5182
4983 5183 /*
4984 5184 * Remove the specified MAC address from the MAC address list and free it.
4985 5185 */
4986 5186 static void
4987 5187 mac_free_macaddr(mac_address_t *map)
4988 5188 {
4989 5189 mac_impl_t *mip = map->ma_mip;
4990 5190
4991 5191 ASSERT(MAC_PERIM_HELD((mac_handle_t)mip));
4992 5192 VERIFY3P(mip->mi_addresses, !=, NULL);
4993 5193
4994 5194 VERIFY3P(map, ==, mac_find_macaddr(mip, map->ma_addr));
4995 5195 VERIFY3P(map, !=, NULL);
4996 5196 VERIFY3S(map->ma_nusers, ==, 0);
4997 5197 VERIFY3P(map->ma_vlans, ==, NULL);
4998 5198
4999 5199 if (map == mip->mi_addresses) {
5000 5200 mip->mi_addresses = map->ma_next;
5001 5201 } else {
5002 5202 mac_address_t *pre;
5003 5203
5004 5204 pre = mip->mi_addresses;
5005 5205 while (pre->ma_next != map)
5006 5206 pre = pre->ma_next;
5007 5207 pre->ma_next = map->ma_next;
5008 5208 }
5009 5209
5010 5210 kmem_free(map, sizeof (mac_address_t));
5011 5211 }
5012 5212
5013 5213 static mac_vlan_t *
5014 5214 mac_find_vlan(mac_address_t *map, uint16_t vid)
5015 5215 {
5016 5216 mac_vlan_t *mvp;
5017 5217
5018 5218 for (mvp = map->ma_vlans; mvp != NULL; mvp = mvp->mv_next) {
5019 5219 if (mvp->mv_vid == vid)
5020 5220 return (mvp);
5021 5221 }
5022 5222
5023 5223 return (NULL);
5024 5224 }
5025 5225
5026 5226 static mac_vlan_t *
5027 5227 mac_add_vlan(mac_address_t *map, uint16_t vid)
5028 5228 {
5029 5229 mac_vlan_t *mvp;
5030 5230
5031 5231 /*
5032 5232 * We should never add the same {addr, VID} tuple more
5033 5233 * than once, but let's be sure.
5034 5234 */
5035 5235 for (mvp = map->ma_vlans; mvp != NULL; mvp = mvp->mv_next)
5036 5236 VERIFY3U(mvp->mv_vid, !=, vid);
5037 5237
5038 5238 /* Add the VLAN to the head of the VLAN list. */
5039 5239 mvp = kmem_zalloc(sizeof (mac_vlan_t), KM_SLEEP);
5040 5240 mvp->mv_vid = vid;
5041 5241 mvp->mv_next = map->ma_vlans;
5042 5242 map->ma_vlans = mvp;
5043 5243
5044 5244 return (mvp);
5045 5245 }
5046 5246
5047 5247 static void
5048 5248 mac_rem_vlan(mac_address_t *map, mac_vlan_t *mvp)
5049 5249 {
5050 5250 mac_vlan_t *pre;
5051 5251
5052 5252 if (map->ma_vlans == mvp) {
5053 5253 map->ma_vlans = mvp->mv_next;
5054 5254 } else {
5055 5255 pre = map->ma_vlans;
5056 5256 while (pre->mv_next != mvp) {
5057 5257 pre = pre->mv_next;
5058 5258
5059 5259 /*
5060 5260 * We've reached the end of the list without
5061 5261 * finding mvp.
5062 5262 */
5063 5263 VERIFY3P(pre, !=, NULL);
5064 5264 }
5065 5265 pre->mv_next = mvp->mv_next;
5066 5266 }
5067 5267
5068 5268 kmem_free(mvp, sizeof (mac_vlan_t));
5069 5269 }
5070 5270
5071 5271 /*
5072 5272 * Create a new mac_address_t if this is the first use of the address
5073 5273 * or add a VID to an existing address. In either case, the
5074 5274 * mac_address_t acts as a list of {addr, VID} tuples where each tuple
5075 5275 * shares the same addr. If group is non-NULL then attempt to program
5076 5276 * the MAC's HW filters for this group. Otherwise, if group is NULL,
5077 5277 * then the MAC has no rings and there is nothing to program.
5078 5278 */
5079 5279 int
5080 5280 mac_add_macaddr_vlan(mac_impl_t *mip, mac_group_t *group, uint8_t *addr,
5081 5281 uint16_t vid, boolean_t use_hw)
5082 5282 {
5083 5283 mac_address_t *map;
5084 5284 mac_vlan_t *mvp;
5085 5285 int err = 0;
5086 5286 boolean_t allocated_map = B_FALSE;
5087 5287 boolean_t hw_mac = B_FALSE;
5088 5288 boolean_t hw_vlan = B_FALSE;
5089 5289
5090 5290 ASSERT(MAC_PERIM_HELD((mac_handle_t)mip));
5091 5291
5092 5292 map = mac_find_macaddr(mip, addr);
5093 5293
5094 5294 /*
5095 5295 * If this is the first use of this MAC address then allocate
5096 5296 * and initialize a new structure.
5097 5297 */
5098 5298 if (map == NULL) {
5099 5299 map = kmem_zalloc(sizeof (mac_address_t), KM_SLEEP);
5100 5300 map->ma_len = mip->mi_type->mt_addr_length;
5101 5301 bcopy(addr, map->ma_addr, map->ma_len);
5102 5302 map->ma_nusers = 0;
5103 5303 map->ma_group = group;
5104 5304 map->ma_mip = mip;
5105 5305 map->ma_untagged = B_FALSE;
5106 5306
5107 5307 /* Add the new MAC address to the head of the address list. */
5108 5308 map->ma_next = mip->mi_addresses;
5109 5309 mip->mi_addresses = map;
5110 5310
5111 5311 allocated_map = B_TRUE;
5112 5312 }
5113 5313
5114 5314 VERIFY(map->ma_group == NULL || map->ma_group == group);
5115 5315 if (map->ma_group == NULL)
5116 5316 map->ma_group = group;
5117 5317
5118 5318 if (vid == VLAN_ID_NONE) {
5119 5319 map->ma_untagged = B_TRUE;
5120 5320 mvp = NULL;
5121 5321 } else {
5122 5322 mvp = mac_add_vlan(map, vid);
5123 5323 }
5124 5324
5125 5325 /*
5126 5326 * Set the VLAN HW filter if:
5127 5327 *
5128 5328 * o the MAC's VLAN HW filtering is enabled, and
5129 5329 * o the address does not currently rely on promisc mode.
5130 5330 *
5131 5331 * This is called even when the client specifies an untagged
5132 5332 * address (VLAN_ID_NONE) because some MAC providers require
5133 5333 * setting additional bits to accept untagged traffic when
5134 5334 * VLAN HW filtering is enabled.
5135 5335 */
5136 5336 if (MAC_GROUP_HW_VLAN(group) &&
5137 5337 map->ma_type != MAC_ADDRESS_TYPE_UNICAST_PROMISC) {
5138 5338 if ((err = mac_group_addvlan(group, vid)) != 0)
5139 5339 goto bail;
5140 5340
5141 5341 hw_vlan = B_TRUE;
5142 5342 }
5143 5343
5144 5344 VERIFY3S(map->ma_nusers, >=, 0);
5145 5345 map->ma_nusers++;
5146 5346
5147 5347 /*
5148 5348 * If this MAC address already has a HW filter then simply
5149 5349 * increment the counter.
5150 5350 */
5151 5351 if (map->ma_nusers > 1)
5152 5352 return (0);
5153 5353
5154 5354 /*
5155 5355 * All logic from here on out is executed during initial
5156 5356 * creation only.
5157 5357 */
5158 5358 VERIFY3S(map->ma_nusers, ==, 1);
5159 5359
5160 5360 /*
5161 5361 * Activate this MAC address by adding it to the reserved group.
5162 5362 */
5163 5363 if (group != NULL) {
5164 5364 err = mac_group_addmac(group, (const uint8_t *)addr);
5165 5365
5166 5366 /*
5167 5367 * If the driver is out of filters then we can
5168 5368 * continue and use promisc mode. For any other error,
5169 5369 * assume the driver is in a state where we can't
5170 5370 * program the filters or use promisc mode; so we must
5171 5371 * bail.
5172 5372 */
5173 5373 if (err != 0 && err != ENOSPC) {
5174 5374 map->ma_nusers--;
5175 5375 goto bail;
5176 5376 }
5177 5377
5178 5378 hw_mac = (err == 0);
5179 5379 }
5180 5380
5181 5381 if (hw_mac) {
5182 5382 map->ma_type = MAC_ADDRESS_TYPE_UNICAST_CLASSIFIED;
5183 5383 return (0);
5184 5384 }
5185 5385
5186 5386 /*
5187 5387 * The MAC address addition failed. If the client requires a
5188 5388 * hardware classified MAC address, fail the operation. This
5189 5389 * feature is only used by sun4v vsw.
5190 5390 */
5191 5391 if (use_hw && !hw_mac) {
5192 5392 err = ENOSPC;
5193 5393 map->ma_nusers--;
5194 5394 goto bail;
5195 5395 }
5196 5396
5197 5397 /*
5198 5398 * If we reach this point then either the MAC doesn't have
5199 5399 * RINGS capability or we are out of MAC address HW filters.
5200 5400 * In any case we must put the MAC into promiscuous mode.
5201 5401 */
5202 5402 VERIFY(group == NULL || !hw_mac);
5203 5403
5204 5404 /*
5205 5405 * The one exception is the primary address. A non-RINGS
5206 5406 * driver filters the primary address by default; promisc mode
5207 5407 * is not needed.
5208 5408 */
5209 5409 if ((group == NULL) &&
5210 5410 (bcmp(map->ma_addr, mip->mi_addr, map->ma_len) == 0)) {
5211 5411 map->ma_type = MAC_ADDRESS_TYPE_UNICAST_CLASSIFIED;
5212 5412 return (0);
5213 5413 }
5214 5414
5215 5415 /*
5216 5416 * Enable promiscuous mode in order to receive traffic to the
5217 5417 * new MAC address. All existing HW filters still send their
5218 5418 * traffic to their respective group/SRSes. But with promisc
5219 5419 * enabled all unknown traffic is delivered to the default
5220 5420 * group where it is SW classified via mac_rx_classify().
5221 5421 */
5222 5422 if ((err = i_mac_promisc_set(mip, B_TRUE)) == 0) {
5223 5423 map->ma_type = MAC_ADDRESS_TYPE_UNICAST_PROMISC;
5224 5424 return (0);
5225 5425 }
5226 5426
5227 5427 bail:
5228 5428 if (hw_vlan) {
5229 5429 int err2 = mac_group_remvlan(group, vid);
5230 5430
5231 5431 if (err2 != 0) {
5232 5432 cmn_err(CE_WARN, "Failed to remove VLAN %u from group"
5233 5433 " %d on MAC %s: %d.", vid, group->mrg_index,
5234 5434 mip->mi_name, err2);
5235 5435 }
5236 5436 }
5237 5437
5238 5438 if (mvp != NULL)
5239 5439 mac_rem_vlan(map, mvp);
5240 5440
5241 5441 if (allocated_map)
5242 5442 mac_free_macaddr(map);
5243 5443
5244 5444 return (err);
5245 5445 }
5246 5446
5247 5447 int
5248 5448 mac_remove_macaddr_vlan(mac_address_t *map, uint16_t vid)
5249 5449 {
5250 5450 mac_vlan_t *mvp;
5251 5451 mac_impl_t *mip = map->ma_mip;
5252 5452 mac_group_t *group = map->ma_group;
5253 5453 int err = 0;
5254 5454
5255 5455 ASSERT(MAC_PERIM_HELD((mac_handle_t)mip));
5256 5456 VERIFY3P(map, ==, mac_find_macaddr(mip, map->ma_addr));
5257 5457
5258 5458 if (vid == VLAN_ID_NONE) {
5259 5459 map->ma_untagged = B_FALSE;
5260 5460 mvp = NULL;
5261 5461 } else {
5262 5462 mvp = mac_find_vlan(map, vid);
5263 5463 VERIFY3P(mvp, !=, NULL);
5264 5464 }
5265 5465
5266 5466 if (MAC_GROUP_HW_VLAN(group) &&
5267 5467 map->ma_type == MAC_ADDRESS_TYPE_UNICAST_CLASSIFIED &&
5268 5468 ((err = mac_group_remvlan(group, vid)) != 0))
5269 5469 return (err);
5270 5470
5271 5471 if (mvp != NULL)
5272 5472 mac_rem_vlan(map, mvp);
5273 5473
5274 5474 /*
5275 5475 * If it's not the last client using this MAC address, only update
5276 5476 * the MAC clients count.
5277 5477 */
5278 5478 map->ma_nusers--;
5279 5479 if (map->ma_nusers > 0)
5280 5480 return (0);
5281 5481
5282 5482 /*
5283 5483 * The MAC address is no longer used by any MAC client, so
5284 5484 * remove it from its associated group. Turn off promiscuous
5285 5485 * mode if this is the last address relying on it.
5286 5486 */
5287 5487 switch (map->ma_type) {
5288 5488 case MAC_ADDRESS_TYPE_UNICAST_CLASSIFIED:
5289 5489 /*
5290 5490 * Don't free the preset primary address for drivers that
5291 5491 * don't advertise RINGS capability.
5292 5492 */
5293 5493 if (group == NULL)
5294 5494 return (0);
5295 5495
5296 5496 if ((err = mac_group_remmac(group, map->ma_addr)) != 0) {
5297 5497 if (vid == VLAN_ID_NONE)
5298 5498 map->ma_untagged = B_TRUE;
5299 5499 else
5300 5500 (void) mac_add_vlan(map, vid);
5301 5501
5302 5502 /*
5303 5503 * If we fail to remove the MAC address HW
5304 5504 * filter but then also fail to re-add the
5305 5505 * VLAN HW filter then we are in a busted
5306 5506 * state and should just crash.
5307 5507 */
5308 5508 if (MAC_GROUP_HW_VLAN(group)) {
5309 5509 int err2;
5310 5510
5311 5511 err2 = mac_group_addvlan(group, vid);
5312 5512 if (err2 != 0) {
5313 5513 cmn_err(CE_WARN, "Failed to readd VLAN"
5314 5514 " %u to group %d on MAC %s: %d.",
5315 5515 vid, group->mrg_index, mip->mi_name,
5316 5516 err2);
5317 5517 }
5318 5518 }
5319 5519
5320 5520 return (err);
5321 5521 }
5322 5522
5323 5523 map->ma_group = NULL;
5324 5524 break;
5325 5525 case MAC_ADDRESS_TYPE_UNICAST_PROMISC:
5326 5526 err = i_mac_promisc_set(mip, B_FALSE);
5327 5527 break;
5328 5528 default:
5329 5529 panic("Unexpected ma_type 0x%x, file: %s, line %d",
5330 5530 map->ma_type, __FILE__, __LINE__);
5331 5531 }
5332 5532
5333 5533 if (err != 0)
5334 5534 return (err);
5335 5535
5336 5536 /*
5337 5537 * We created MAC address for the primary one at registration, so we
5338 5538 * won't free it here. mac_fini_macaddr() will take care of it.
5339 5539 */
5340 5540 if (bcmp(map->ma_addr, mip->mi_addr, map->ma_len) != 0)
5341 5541 mac_free_macaddr(map);
5342 5542
5343 5543 return (0);
5344 5544 }
5345 5545
5346 5546 /*
5347 5547 * Update an existing MAC address. The caller need to make sure that the new
5348 5548 * value has not been used.
5349 5549 */
5350 5550 int
5351 5551 mac_update_macaddr(mac_address_t *map, uint8_t *mac_addr)
5352 5552 {
5353 5553 mac_impl_t *mip = map->ma_mip;
5354 5554 int err = 0;
5355 5555
5356 5556 ASSERT(MAC_PERIM_HELD((mac_handle_t)mip));
5357 5557 ASSERT(mac_find_macaddr(mip, mac_addr) == NULL);
5358 5558
5359 5559 switch (map->ma_type) {
5360 5560 case MAC_ADDRESS_TYPE_UNICAST_CLASSIFIED:
5361 5561 /*
5362 5562 * Update the primary address for drivers that are not
5363 5563 * RINGS capable.
5364 5564 */
5365 5565 if (mip->mi_rx_groups == NULL) {
5366 5566 err = mip->mi_unicst(mip->mi_driver, (const uint8_t *)
5367 5567 mac_addr);
5368 5568 if (err != 0)
5369 5569 return (err);
5370 5570 break;
5371 5571 }
5372 5572
5373 5573 /*
5374 5574 * If this MAC address is not currently in use,
5375 5575 * simply break out and update the value.
5376 5576 */
5377 5577 if (map->ma_nusers == 0)
5378 5578 break;
5379 5579
5380 5580 /*
5381 5581 * Need to replace the MAC address associated with a group.
5382 5582 */
5383 5583 err = mac_group_remmac(map->ma_group, map->ma_addr);
5384 5584 if (err != 0)
5385 5585 return (err);
5386 5586
5387 5587 err = mac_group_addmac(map->ma_group, mac_addr);
5388 5588
5389 5589 /*
5390 5590 * Failure hints hardware error. The MAC layer needs to
5391 5591 * have error notification facility to handle this.
5392 5592 * Now, simply try to restore the value.
5393 5593 */
5394 5594 if (err != 0)
5395 5595 (void) mac_group_addmac(map->ma_group, map->ma_addr);
5396 5596
5397 5597 break;
5398 5598 case MAC_ADDRESS_TYPE_UNICAST_PROMISC:
5399 5599 /*
5400 5600 * Need to do nothing more if in promiscuous mode.
5401 5601 */
5402 5602 break;
5403 5603 default:
5404 5604 ASSERT(B_FALSE);
5405 5605 }
5406 5606
5407 5607 /*
5408 5608 * Successfully replaced the MAC address.
5409 5609 */
5410 5610 if (err == 0)
5411 5611 bcopy(mac_addr, map->ma_addr, map->ma_len);
5412 5612
5413 5613 return (err);
5414 5614 }
5415 5615
5416 5616 /*
5417 5617 * Freshen the MAC address with new value. Its caller must have updated the
5418 5618 * hardware MAC address before calling this function.
5419 5619 * This funcitons is supposed to be used to handle the MAC address change
5420 5620 * notification from underlying drivers.
5421 5621 */
5422 5622 void
5423 5623 mac_freshen_macaddr(mac_address_t *map, uint8_t *mac_addr)
5424 5624 {
5425 5625 mac_impl_t *mip = map->ma_mip;
5426 5626
5427 5627 ASSERT(MAC_PERIM_HELD((mac_handle_t)mip));
5428 5628 ASSERT(mac_find_macaddr(mip, mac_addr) == NULL);
5429 5629
5430 5630 /*
5431 5631 * Freshen the MAC address with new value.
5432 5632 */
5433 5633 bcopy(mac_addr, map->ma_addr, map->ma_len);
5434 5634 bcopy(mac_addr, mip->mi_addr, map->ma_len);
5435 5635
5436 5636 /*
5437 5637 * Update all MAC clients that share this MAC address.
5438 5638 */
5439 5639 mac_unicast_update_clients(mip, map);
5440 5640 }
5441 5641
5442 5642 /*
5443 5643 * Set up the primary MAC address.
5444 5644 */
5445 5645 void
5446 5646 mac_init_macaddr(mac_impl_t *mip)
5447 5647 {
5448 5648 mac_address_t *map;
5449 5649
5450 5650 /*
5451 5651 * The reference count is initialized to zero, until it's really
5452 5652 * activated.
5453 5653 */
5454 5654 map = kmem_zalloc(sizeof (mac_address_t), KM_SLEEP);
5455 5655 map->ma_len = mip->mi_type->mt_addr_length;
5456 5656 bcopy(mip->mi_addr, map->ma_addr, map->ma_len);
5457 5657
5458 5658 /*
5459 5659 * If driver advertises RINGS capability, it shouldn't have initialized
5460 5660 * its primary MAC address. For other drivers, including VNIC, the
5461 5661 * primary address must work after registration.
5462 5662 */
5463 5663 if (mip->mi_rx_groups == NULL)
5464 5664 map->ma_type = MAC_ADDRESS_TYPE_UNICAST_CLASSIFIED;
5465 5665
5466 5666 map->ma_mip = mip;
5467 5667
5468 5668 mip->mi_addresses = map;
5469 5669 }
5470 5670
5471 5671 /*
5472 5672 * Clean up the primary MAC address. Note, only one primary MAC address
5473 5673 * is allowed. All other MAC addresses must have been freed appropriately.
5474 5674 */
5475 5675 void
5476 5676 mac_fini_macaddr(mac_impl_t *mip)
5477 5677 {
5478 5678 mac_address_t *map = mip->mi_addresses;
5479 5679
5480 5680 if (map == NULL)
5481 5681 return;
5482 5682
5483 5683 /*
5484 5684 * If mi_addresses is initialized, there should be exactly one
5485 5685 * entry left on the list with no users.
5486 5686 */
5487 5687 VERIFY3S(map->ma_nusers, ==, 0);
5488 5688 VERIFY3P(map->ma_next, ==, NULL);
5489 5689 VERIFY3P(map->ma_vlans, ==, NULL);
5490 5690
5491 5691 kmem_free(map, sizeof (mac_address_t));
5492 5692 mip->mi_addresses = NULL;
5493 5693 }
5494 5694
5495 5695 /*
5496 5696 * Logging related functions.
5497 5697 *
5498 5698 * Note that Kernel statistics have been extended to maintain fine
5499 5699 * granularity of statistics viz. hardware lane, software lane, fanout
5500 5700 * stats etc. However, extended accounting continues to support only
5501 5701 * aggregate statistics like before.
5502 5702 */
5503 5703
5504 5704 /* Write the flow description to a netinfo_t record */
5505 5705 static netinfo_t *
5506 5706 mac_write_flow_desc(flow_entry_t *flent, mac_client_impl_t *mcip)
5507 5707 {
5508 5708 netinfo_t *ninfo;
5509 5709 net_desc_t *ndesc;
5510 5710 flow_desc_t *fdesc;
5511 5711 mac_resource_props_t *mrp;
5512 5712
5513 5713 ninfo = kmem_zalloc(sizeof (netinfo_t), KM_NOSLEEP);
5514 5714 if (ninfo == NULL)
5515 5715 return (NULL);
5516 5716 ndesc = kmem_zalloc(sizeof (net_desc_t), KM_NOSLEEP);
5517 5717 if (ndesc == NULL) {
5518 5718 kmem_free(ninfo, sizeof (netinfo_t));
5519 5719 return (NULL);
5520 5720 }
5521 5721
5522 5722 /*
5523 5723 * Grab the fe_lock to see a self-consistent fe_flow_desc.
5524 5724 * Updates to the fe_flow_desc are done under the fe_lock
5525 5725 */
5526 5726 mutex_enter(&flent->fe_lock);
5527 5727 fdesc = &flent->fe_flow_desc;
5528 5728 mrp = &flent->fe_resource_props;
5529 5729
5530 5730 ndesc->nd_name = flent->fe_flow_name;
5531 5731 ndesc->nd_devname = mcip->mci_name;
5532 5732 bcopy(fdesc->fd_src_mac, ndesc->nd_ehost, ETHERADDRL);
5533 5733 bcopy(fdesc->fd_dst_mac, ndesc->nd_edest, ETHERADDRL);
5534 5734 ndesc->nd_sap = htonl(fdesc->fd_sap);
5535 5735 ndesc->nd_isv4 = (uint8_t)fdesc->fd_ipversion == IPV4_VERSION;
5536 5736 ndesc->nd_bw_limit = mrp->mrp_maxbw;
5537 5737 if (ndesc->nd_isv4) {
5538 5738 ndesc->nd_saddr[3] = htonl(fdesc->fd_local_addr.s6_addr32[3]);
5539 5739 ndesc->nd_daddr[3] = htonl(fdesc->fd_remote_addr.s6_addr32[3]);
5540 5740 } else {
5541 5741 bcopy(&fdesc->fd_local_addr, ndesc->nd_saddr, IPV6_ADDR_LEN);
5542 5742 bcopy(&fdesc->fd_remote_addr, ndesc->nd_daddr, IPV6_ADDR_LEN);
5543 5743 }
5544 5744 ndesc->nd_sport = htons(fdesc->fd_local_port);
5545 5745 ndesc->nd_dport = htons(fdesc->fd_remote_port);
5546 5746 ndesc->nd_protocol = (uint8_t)fdesc->fd_protocol;
5547 5747 mutex_exit(&flent->fe_lock);
5548 5748
5549 5749 ninfo->ni_record = ndesc;
5550 5750 ninfo->ni_size = sizeof (net_desc_t);
5551 5751 ninfo->ni_type = EX_NET_FLDESC_REC;
5552 5752
5553 5753 return (ninfo);
5554 5754 }
5555 5755
5556 5756 /* Write the flow statistics to a netinfo_t record */
5557 5757 static netinfo_t *
5558 5758 mac_write_flow_stats(flow_entry_t *flent)
5559 5759 {
5560 5760 netinfo_t *ninfo;
5561 5761 net_stat_t *nstat;
5562 5762 mac_soft_ring_set_t *mac_srs;
5563 5763 mac_rx_stats_t *mac_rx_stat;
5564 5764 mac_tx_stats_t *mac_tx_stat;
5565 5765 int i;
5566 5766
5567 5767 ninfo = kmem_zalloc(sizeof (netinfo_t), KM_NOSLEEP);
5568 5768 if (ninfo == NULL)
5569 5769 return (NULL);
5570 5770 nstat = kmem_zalloc(sizeof (net_stat_t), KM_NOSLEEP);
5571 5771 if (nstat == NULL) {
5572 5772 kmem_free(ninfo, sizeof (netinfo_t));
5573 5773 return (NULL);
5574 5774 }
5575 5775
5576 5776 nstat->ns_name = flent->fe_flow_name;
5577 5777 for (i = 0; i < flent->fe_rx_srs_cnt; i++) {
5578 5778 mac_srs = (mac_soft_ring_set_t *)flent->fe_rx_srs[i];
5579 5779 mac_rx_stat = &mac_srs->srs_rx.sr_stat;
5580 5780
5581 5781 nstat->ns_ibytes += mac_rx_stat->mrs_intrbytes +
5582 5782 mac_rx_stat->mrs_pollbytes + mac_rx_stat->mrs_lclbytes;
5583 5783 nstat->ns_ipackets += mac_rx_stat->mrs_intrcnt +
5584 5784 mac_rx_stat->mrs_pollcnt + mac_rx_stat->mrs_lclcnt;
5585 5785 nstat->ns_oerrors += mac_rx_stat->mrs_ierrors;
5586 5786 }
5587 5787
5588 5788 mac_srs = (mac_soft_ring_set_t *)(flent->fe_tx_srs);
5589 5789 if (mac_srs != NULL) {
5590 5790 mac_tx_stat = &mac_srs->srs_tx.st_stat;
5591 5791
5592 5792 nstat->ns_obytes = mac_tx_stat->mts_obytes;
5593 5793 nstat->ns_opackets = mac_tx_stat->mts_opackets;
5594 5794 nstat->ns_oerrors = mac_tx_stat->mts_oerrors;
5595 5795 }
5596 5796
5597 5797 ninfo->ni_record = nstat;
5598 5798 ninfo->ni_size = sizeof (net_stat_t);
5599 5799 ninfo->ni_type = EX_NET_FLSTAT_REC;
5600 5800
5601 5801 return (ninfo);
5602 5802 }
5603 5803
5604 5804 /* Write the link description to a netinfo_t record */
5605 5805 static netinfo_t *
5606 5806 mac_write_link_desc(mac_client_impl_t *mcip)
5607 5807 {
5608 5808 netinfo_t *ninfo;
5609 5809 net_desc_t *ndesc;
5610 5810 flow_entry_t *flent = mcip->mci_flent;
5611 5811
5612 5812 ninfo = kmem_zalloc(sizeof (netinfo_t), KM_NOSLEEP);
5613 5813 if (ninfo == NULL)
5614 5814 return (NULL);
5615 5815 ndesc = kmem_zalloc(sizeof (net_desc_t), KM_NOSLEEP);
5616 5816 if (ndesc == NULL) {
5617 5817 kmem_free(ninfo, sizeof (netinfo_t));
5618 5818 return (NULL);
5619 5819 }
5620 5820
5621 5821 ndesc->nd_name = mcip->mci_name;
5622 5822 ndesc->nd_devname = mcip->mci_name;
5623 5823 ndesc->nd_isv4 = B_TRUE;
5624 5824 /*
5625 5825 * Grab the fe_lock to see a self-consistent fe_flow_desc.
5626 5826 * Updates to the fe_flow_desc are done under the fe_lock
5627 5827 * after removing the flent from the flow table.
5628 5828 */
5629 5829 mutex_enter(&flent->fe_lock);
5630 5830 bcopy(flent->fe_flow_desc.fd_src_mac, ndesc->nd_ehost, ETHERADDRL);
5631 5831 mutex_exit(&flent->fe_lock);
5632 5832
5633 5833 ninfo->ni_record = ndesc;
5634 5834 ninfo->ni_size = sizeof (net_desc_t);
5635 5835 ninfo->ni_type = EX_NET_LNDESC_REC;
5636 5836
5637 5837 return (ninfo);
5638 5838 }
5639 5839
5640 5840 /* Write the link statistics to a netinfo_t record */
5641 5841 static netinfo_t *
5642 5842 mac_write_link_stats(mac_client_impl_t *mcip)
5643 5843 {
5644 5844 netinfo_t *ninfo;
5645 5845 net_stat_t *nstat;
5646 5846 flow_entry_t *flent;
5647 5847 mac_soft_ring_set_t *mac_srs;
5648 5848 mac_rx_stats_t *mac_rx_stat;
5649 5849 mac_tx_stats_t *mac_tx_stat;
5650 5850 int i;
5651 5851
5652 5852 ninfo = kmem_zalloc(sizeof (netinfo_t), KM_NOSLEEP);
5653 5853 if (ninfo == NULL)
5654 5854 return (NULL);
5655 5855 nstat = kmem_zalloc(sizeof (net_stat_t), KM_NOSLEEP);
5656 5856 if (nstat == NULL) {
5657 5857 kmem_free(ninfo, sizeof (netinfo_t));
5658 5858 return (NULL);
5659 5859 }
5660 5860
5661 5861 nstat->ns_name = mcip->mci_name;
5662 5862 flent = mcip->mci_flent;
5663 5863 if (flent != NULL) {
5664 5864 for (i = 0; i < flent->fe_rx_srs_cnt; i++) {
5665 5865 mac_srs = (mac_soft_ring_set_t *)flent->fe_rx_srs[i];
5666 5866 mac_rx_stat = &mac_srs->srs_rx.sr_stat;
5667 5867
5668 5868 nstat->ns_ibytes += mac_rx_stat->mrs_intrbytes +
5669 5869 mac_rx_stat->mrs_pollbytes +
5670 5870 mac_rx_stat->mrs_lclbytes;
5671 5871 nstat->ns_ipackets += mac_rx_stat->mrs_intrcnt +
5672 5872 mac_rx_stat->mrs_pollcnt + mac_rx_stat->mrs_lclcnt;
5673 5873 nstat->ns_oerrors += mac_rx_stat->mrs_ierrors;
5674 5874 }
5675 5875 }
5676 5876
5677 5877 mac_srs = (mac_soft_ring_set_t *)(mcip->mci_flent->fe_tx_srs);
5678 5878 if (mac_srs != NULL) {
5679 5879 mac_tx_stat = &mac_srs->srs_tx.st_stat;
5680 5880
5681 5881 nstat->ns_obytes = mac_tx_stat->mts_obytes;
5682 5882 nstat->ns_opackets = mac_tx_stat->mts_opackets;
5683 5883 nstat->ns_oerrors = mac_tx_stat->mts_oerrors;
5684 5884 }
5685 5885
5686 5886 ninfo->ni_record = nstat;
5687 5887 ninfo->ni_size = sizeof (net_stat_t);
5688 5888 ninfo->ni_type = EX_NET_LNSTAT_REC;
5689 5889
5690 5890 return (ninfo);
5691 5891 }
5692 5892
5693 5893 typedef struct i_mac_log_state_s {
5694 5894 boolean_t mi_last;
5695 5895 int mi_fenable;
5696 5896 int mi_lenable;
5697 5897 list_t *mi_list;
5698 5898 } i_mac_log_state_t;
5699 5899
5700 5900 /*
5701 5901 * For a given flow, if the description has not been logged before, do it now.
5702 5902 * If it is a VNIC, then we have collected information about it from the MAC
5703 5903 * table, so skip it.
5704 5904 *
5705 5905 * Called through mac_flow_walk_nolock()
5706 5906 *
5707 5907 * Return 0 if successful.
5708 5908 */
5709 5909 static int
5710 5910 mac_log_flowinfo(flow_entry_t *flent, void *arg)
5711 5911 {
5712 5912 mac_client_impl_t *mcip = flent->fe_mcip;
5713 5913 i_mac_log_state_t *lstate = arg;
5714 5914 netinfo_t *ninfo;
5715 5915
5716 5916 if (mcip == NULL)
5717 5917 return (0);
5718 5918
5719 5919 /*
5720 5920 * If the name starts with "vnic", and fe_user_generated is true (to
5721 5921 * exclude the mcast and active flow entries created implicitly for
5722 5922 * a vnic, it is a VNIC flow. i.e. vnic1 is a vnic flow,
5723 5923 * vnic/bge1/mcast1 is not and neither is vnic/bge1/active.
5724 5924 */
5725 5925 if (strncasecmp(flent->fe_flow_name, "vnic", 4) == 0 &&
5726 5926 (flent->fe_type & FLOW_USER) != 0) {
5727 5927 return (0);
5728 5928 }
5729 5929
5730 5930 if (!flent->fe_desc_logged) {
5731 5931 /*
5732 5932 * We don't return error because we want to continue the
5733 5933 * walk in case this is the last walk which means we
5734 5934 * need to reset fe_desc_logged in all the flows.
5735 5935 */
5736 5936 if ((ninfo = mac_write_flow_desc(flent, mcip)) == NULL)
5737 5937 return (0);
5738 5938 list_insert_tail(lstate->mi_list, ninfo);
5739 5939 flent->fe_desc_logged = B_TRUE;
5740 5940 }
5741 5941
5742 5942 /*
5743 5943 * Regardless of the error, we want to proceed in case we have to
5744 5944 * reset fe_desc_logged.
5745 5945 */
5746 5946 ninfo = mac_write_flow_stats(flent);
5747 5947 if (ninfo == NULL)
5748 5948 return (-1);
5749 5949
5750 5950 list_insert_tail(lstate->mi_list, ninfo);
5751 5951
5752 5952 if (mcip != NULL && !(mcip->mci_state_flags & MCIS_DESC_LOGGED))
5753 5953 flent->fe_desc_logged = B_FALSE;
5754 5954
5755 5955 return (0);
5756 5956 }
5757 5957
5758 5958 /*
5759 5959 * Log the description for each mac client of this mac_impl_t, if it
5760 5960 * hasn't already been done. Additionally, log statistics for the link as
5761 5961 * well. Walk the flow table and log information for each flow as well.
5762 5962 * If it is the last walk (mci_last), then we turn off mci_desc_logged (and
5763 5963 * also fe_desc_logged, if flow logging is on) since we want to log the
5764 5964 * description if and when logging is restarted.
5765 5965 *
5766 5966 * Return 0 upon success or -1 upon failure
5767 5967 */
5768 5968 static int
5769 5969 i_mac_impl_log(mac_impl_t *mip, i_mac_log_state_t *lstate)
5770 5970 {
5771 5971 mac_client_impl_t *mcip;
5772 5972 netinfo_t *ninfo;
5773 5973
5774 5974 i_mac_perim_enter(mip);
5775 5975 /*
5776 5976 * Only walk the client list for NIC and etherstub
5777 5977 */
5778 5978 if ((mip->mi_state_flags & MIS_DISABLED) ||
5779 5979 ((mip->mi_state_flags & MIS_IS_VNIC) &&
5780 5980 (mac_get_lower_mac_handle((mac_handle_t)mip) != NULL))) {
5781 5981 i_mac_perim_exit(mip);
5782 5982 return (0);
5783 5983 }
5784 5984
5785 5985 for (mcip = mip->mi_clients_list; mcip != NULL;
5786 5986 mcip = mcip->mci_client_next) {
5787 5987 if (!MCIP_DATAPATH_SETUP(mcip))
5788 5988 continue;
5789 5989 if (lstate->mi_lenable) {
5790 5990 if (!(mcip->mci_state_flags & MCIS_DESC_LOGGED)) {
5791 5991 ninfo = mac_write_link_desc(mcip);
5792 5992 if (ninfo == NULL) {
5793 5993 /*
5794 5994 * We can't terminate it if this is the last
5795 5995 * walk, else there might be some links with
5796 5996 * mi_desc_logged set to true, which means
5797 5997 * their description won't be logged the next
5798 5998 * time logging is started (similarly for the
5799 5999 * flows within such links). We can continue
5800 6000 * without walking the flow table (i.e. to
5801 6001 * set fe_desc_logged to false) because we
5802 6002 * won't have written any flow stuff for this
5803 6003 * link as we haven't logged the link itself.
5804 6004 */
5805 6005 i_mac_perim_exit(mip);
5806 6006 if (lstate->mi_last)
5807 6007 return (0);
5808 6008 else
5809 6009 return (-1);
5810 6010 }
5811 6011 mcip->mci_state_flags |= MCIS_DESC_LOGGED;
5812 6012 list_insert_tail(lstate->mi_list, ninfo);
5813 6013 }
5814 6014 }
5815 6015
5816 6016 ninfo = mac_write_link_stats(mcip);
5817 6017 if (ninfo == NULL && !lstate->mi_last) {
5818 6018 i_mac_perim_exit(mip);
5819 6019 return (-1);
5820 6020 }
5821 6021 list_insert_tail(lstate->mi_list, ninfo);
5822 6022
5823 6023 if (lstate->mi_last)
5824 6024 mcip->mci_state_flags &= ~MCIS_DESC_LOGGED;
5825 6025
5826 6026 if (lstate->mi_fenable) {
5827 6027 if (mcip->mci_subflow_tab != NULL) {
5828 6028 (void) mac_flow_walk_nolock(
5829 6029 mcip->mci_subflow_tab, mac_log_flowinfo,
5830 6030 lstate);
5831 6031 }
5832 6032 }
5833 6033 }
5834 6034 i_mac_perim_exit(mip);
5835 6035 return (0);
5836 6036 }
5837 6037
5838 6038 /*
5839 6039 * modhash walker function to add a mac_impl_t to a list
5840 6040 */
5841 6041 /*ARGSUSED*/
5842 6042 static uint_t
5843 6043 i_mac_impl_list_walker(mod_hash_key_t key, mod_hash_val_t *val, void *arg)
5844 6044 {
5845 6045 list_t *list = (list_t *)arg;
5846 6046 mac_impl_t *mip = (mac_impl_t *)val;
5847 6047
5848 6048 if ((mip->mi_state_flags & MIS_DISABLED) == 0) {
5849 6049 list_insert_tail(list, mip);
5850 6050 mip->mi_ref++;
5851 6051 }
5852 6052
5853 6053 return (MH_WALK_CONTINUE);
5854 6054 }
5855 6055
5856 6056 void
5857 6057 i_mac_log_info(list_t *net_log_list, i_mac_log_state_t *lstate)
5858 6058 {
5859 6059 list_t mac_impl_list;
5860 6060 mac_impl_t *mip;
5861 6061 netinfo_t *ninfo;
5862 6062
5863 6063 /* Create list of mac_impls */
5864 6064 ASSERT(RW_LOCK_HELD(&i_mac_impl_lock));
5865 6065 list_create(&mac_impl_list, sizeof (mac_impl_t), offsetof(mac_impl_t,
5866 6066 mi_node));
5867 6067 mod_hash_walk(i_mac_impl_hash, i_mac_impl_list_walker, &mac_impl_list);
5868 6068 rw_exit(&i_mac_impl_lock);
5869 6069
5870 6070 /* Create log entries for each mac_impl */
5871 6071 for (mip = list_head(&mac_impl_list); mip != NULL;
5872 6072 mip = list_next(&mac_impl_list, mip)) {
5873 6073 if (i_mac_impl_log(mip, lstate) != 0)
5874 6074 continue;
5875 6075 }
5876 6076
5877 6077 /* Remove elements and destroy list of mac_impls */
5878 6078 rw_enter(&i_mac_impl_lock, RW_WRITER);
5879 6079 while ((mip = list_remove_tail(&mac_impl_list)) != NULL) {
5880 6080 mip->mi_ref--;
5881 6081 }
5882 6082 rw_exit(&i_mac_impl_lock);
5883 6083 list_destroy(&mac_impl_list);
5884 6084
5885 6085 /*
5886 6086 * Write log entries to files outside of locks, free associated
5887 6087 * structures, and remove entries from the list.
5888 6088 */
5889 6089 while ((ninfo = list_head(net_log_list)) != NULL) {
5890 6090 (void) exacct_commit_netinfo(ninfo->ni_record, ninfo->ni_type);
5891 6091 list_remove(net_log_list, ninfo);
5892 6092 kmem_free(ninfo->ni_record, ninfo->ni_size);
5893 6093 kmem_free(ninfo, sizeof (*ninfo));
5894 6094 }
5895 6095 list_destroy(net_log_list);
5896 6096 }
5897 6097
5898 6098 /*
5899 6099 * The timer thread that runs every mac_logging_interval seconds and logs
5900 6100 * link and/or flow information.
5901 6101 */
5902 6102 /* ARGSUSED */
5903 6103 void
5904 6104 mac_log_linkinfo(void *arg)
5905 6105 {
5906 6106 i_mac_log_state_t lstate;
5907 6107 list_t net_log_list;
5908 6108
5909 6109 list_create(&net_log_list, sizeof (netinfo_t),
5910 6110 offsetof(netinfo_t, ni_link));
5911 6111
5912 6112 rw_enter(&i_mac_impl_lock, RW_READER);
5913 6113 if (!mac_flow_log_enable && !mac_link_log_enable) {
5914 6114 rw_exit(&i_mac_impl_lock);
5915 6115 return;
5916 6116 }
5917 6117 lstate.mi_fenable = mac_flow_log_enable;
5918 6118 lstate.mi_lenable = mac_link_log_enable;
5919 6119 lstate.mi_last = B_FALSE;
5920 6120 lstate.mi_list = &net_log_list;
5921 6121
5922 6122 /* Write log entries for each mac_impl in the list */
5923 6123 i_mac_log_info(&net_log_list, &lstate);
5924 6124
5925 6125 if (mac_flow_log_enable || mac_link_log_enable) {
5926 6126 mac_logging_timer = timeout(mac_log_linkinfo, NULL,
5927 6127 SEC_TO_TICK(mac_logging_interval));
5928 6128 }
5929 6129 }
5930 6130
5931 6131 typedef struct i_mac_fastpath_state_s {
5932 6132 boolean_t mf_disable;
5933 6133 int mf_err;
5934 6134 } i_mac_fastpath_state_t;
5935 6135
5936 6136 /* modhash walker function to enable or disable fastpath */
5937 6137 /*ARGSUSED*/
5938 6138 static uint_t
5939 6139 i_mac_fastpath_walker(mod_hash_key_t key, mod_hash_val_t *val,
5940 6140 void *arg)
5941 6141 {
5942 6142 i_mac_fastpath_state_t *state = arg;
5943 6143 mac_handle_t mh = (mac_handle_t)val;
5944 6144
5945 6145 if (state->mf_disable)
5946 6146 state->mf_err = mac_fastpath_disable(mh);
5947 6147 else
5948 6148 mac_fastpath_enable(mh);
5949 6149
5950 6150 return (state->mf_err == 0 ? MH_WALK_CONTINUE : MH_WALK_TERMINATE);
5951 6151 }
5952 6152
5953 6153 /*
5954 6154 * Start the logging timer.
5955 6155 */
5956 6156 int
5957 6157 mac_start_logusage(mac_logtype_t type, uint_t interval)
5958 6158 {
5959 6159 i_mac_fastpath_state_t dstate = {B_TRUE, 0};
5960 6160 i_mac_fastpath_state_t estate = {B_FALSE, 0};
5961 6161 int err;
5962 6162
5963 6163 rw_enter(&i_mac_impl_lock, RW_WRITER);
5964 6164 switch (type) {
5965 6165 case MAC_LOGTYPE_FLOW:
5966 6166 if (mac_flow_log_enable) {
5967 6167 rw_exit(&i_mac_impl_lock);
5968 6168 return (0);
5969 6169 }
5970 6170 /* FALLTHRU */
5971 6171 case MAC_LOGTYPE_LINK:
5972 6172 if (mac_link_log_enable) {
5973 6173 rw_exit(&i_mac_impl_lock);
5974 6174 return (0);
5975 6175 }
5976 6176 break;
5977 6177 default:
5978 6178 ASSERT(0);
5979 6179 }
5980 6180
5981 6181 /* Disable fastpath */
5982 6182 mod_hash_walk(i_mac_impl_hash, i_mac_fastpath_walker, &dstate);
5983 6183 if ((err = dstate.mf_err) != 0) {
5984 6184 /* Reenable fastpath */
5985 6185 mod_hash_walk(i_mac_impl_hash, i_mac_fastpath_walker, &estate);
5986 6186 rw_exit(&i_mac_impl_lock);
5987 6187 return (err);
5988 6188 }
5989 6189
5990 6190 switch (type) {
5991 6191 case MAC_LOGTYPE_FLOW:
5992 6192 mac_flow_log_enable = B_TRUE;
5993 6193 /* FALLTHRU */
5994 6194 case MAC_LOGTYPE_LINK:
5995 6195 mac_link_log_enable = B_TRUE;
5996 6196 break;
5997 6197 }
5998 6198
5999 6199 mac_logging_interval = interval;
6000 6200 rw_exit(&i_mac_impl_lock);
6001 6201 mac_log_linkinfo(NULL);
6002 6202 return (0);
6003 6203 }
6004 6204
6005 6205 /*
6006 6206 * Stop the logging timer if both link and flow logging are turned off.
6007 6207 */
6008 6208 void
6009 6209 mac_stop_logusage(mac_logtype_t type)
6010 6210 {
6011 6211 i_mac_log_state_t lstate;
6012 6212 i_mac_fastpath_state_t estate = {B_FALSE, 0};
6013 6213 list_t net_log_list;
6014 6214
6015 6215 list_create(&net_log_list, sizeof (netinfo_t),
6016 6216 offsetof(netinfo_t, ni_link));
6017 6217
6018 6218 rw_enter(&i_mac_impl_lock, RW_WRITER);
6019 6219
6020 6220 lstate.mi_fenable = mac_flow_log_enable;
6021 6221 lstate.mi_lenable = mac_link_log_enable;
6022 6222 lstate.mi_list = &net_log_list;
6023 6223
6024 6224 /* Last walk */
6025 6225 lstate.mi_last = B_TRUE;
6026 6226
6027 6227 switch (type) {
6028 6228 case MAC_LOGTYPE_FLOW:
6029 6229 if (lstate.mi_fenable) {
6030 6230 ASSERT(mac_link_log_enable);
6031 6231 mac_flow_log_enable = B_FALSE;
6032 6232 mac_link_log_enable = B_FALSE;
6033 6233 break;
6034 6234 }
6035 6235 /* FALLTHRU */
6036 6236 case MAC_LOGTYPE_LINK:
6037 6237 if (!lstate.mi_lenable || mac_flow_log_enable) {
6038 6238 rw_exit(&i_mac_impl_lock);
6039 6239 return;
6040 6240 }
6041 6241 mac_link_log_enable = B_FALSE;
6042 6242 break;
6043 6243 default:
6044 6244 ASSERT(0);
6045 6245 }
6046 6246
6047 6247 /* Reenable fastpath */
6048 6248 mod_hash_walk(i_mac_impl_hash, i_mac_fastpath_walker, &estate);
6049 6249
6050 6250 (void) untimeout(mac_logging_timer);
6051 6251 mac_logging_timer = NULL;
6052 6252
6053 6253 /* Write log entries for each mac_impl in the list */
6054 6254 i_mac_log_info(&net_log_list, &lstate);
6055 6255 }
6056 6256
6057 6257 /*
6058 6258 * Walk the rx and tx SRS/SRs for a flow and update the priority value.
6059 6259 */
6060 6260 void
6061 6261 mac_flow_update_priority(mac_client_impl_t *mcip, flow_entry_t *flent)
6062 6262 {
6063 6263 pri_t pri;
6064 6264 int count;
6065 6265 mac_soft_ring_set_t *mac_srs;
6066 6266
6067 6267 if (flent->fe_rx_srs_cnt <= 0)
6068 6268 return;
6069 6269
6070 6270 if (((mac_soft_ring_set_t *)flent->fe_rx_srs[0])->srs_type ==
6071 6271 SRST_FLOW) {
6072 6272 pri = FLOW_PRIORITY(mcip->mci_min_pri,
6073 6273 mcip->mci_max_pri,
6074 6274 flent->fe_resource_props.mrp_priority);
6075 6275 } else {
6076 6276 pri = mcip->mci_max_pri;
6077 6277 }
6078 6278
6079 6279 for (count = 0; count < flent->fe_rx_srs_cnt; count++) {
6080 6280 mac_srs = flent->fe_rx_srs[count];
6081 6281 mac_update_srs_priority(mac_srs, pri);
6082 6282 }
6083 6283 /*
6084 6284 * If we have a Tx SRS, we need to modify all the threads associated
6085 6285 * with it.
6086 6286 */
6087 6287 if (flent->fe_tx_srs != NULL)
6088 6288 mac_update_srs_priority(flent->fe_tx_srs, pri);
6089 6289 }
6090 6290
6091 6291 /*
6092 6292 * RX and TX rings are reserved according to different semantics depending
6093 6293 * on the requests from the MAC clients and type of rings:
6094 6294 *
6095 6295 * On the Tx side, by default we reserve individual rings, independently from
6096 6296 * the groups.
6097 6297 *
6098 6298 * On the Rx side, the reservation is at the granularity of the group
6099 6299 * of rings, and used for v12n level 1 only. It has a special case for the
6100 6300 * primary client.
6101 6301 *
6102 6302 * If a share is allocated to a MAC client, we allocate a TX group and an
6103 6303 * RX group to the client, and assign TX rings and RX rings to these
6104 6304 * groups according to information gathered from the driver through
6105 6305 * the share capability.
6106 6306 *
6107 6307 * The foreseable evolution of Rx rings will handle v12n level 2 and higher
6108 6308 * to allocate individual rings out of a group and program the hw classifier
6109 6309 * based on IP address or higher level criteria.
6110 6310 */
6111 6311
6112 6312 /*
6113 6313 * mac_reserve_tx_ring()
6114 6314 * Reserve a unused ring by marking it with MR_INUSE state.
6115 6315 * As reserved, the ring is ready to function.
6116 6316 *
6117 6317 * Notes for Hybrid I/O:
6118 6318 *
6119 6319 * If a specific ring is needed, it is specified through the desired_ring
6120 6320 * argument. Otherwise that argument is set to NULL.
6121 6321 * If the desired ring was previous allocated to another client, this
6122 6322 * function swaps it with a new ring from the group of unassigned rings.
6123 6323 */
6124 6324 mac_ring_t *
6125 6325 mac_reserve_tx_ring(mac_impl_t *mip, mac_ring_t *desired_ring)
6126 6326 {
6127 6327 mac_group_t *group;
6128 6328 mac_grp_client_t *mgcp;
6129 6329 mac_client_impl_t *mcip;
6130 6330 mac_soft_ring_set_t *srs;
6131 6331
6132 6332 ASSERT(MAC_PERIM_HELD((mac_handle_t)mip));
6133 6333
6134 6334 /*
6135 6335 * Find an available ring and start it before changing its status.
6136 6336 * The unassigned rings are at the end of the mi_tx_groups
6137 6337 * array.
6138 6338 */
6139 6339 group = MAC_DEFAULT_TX_GROUP(mip);
6140 6340
6141 6341 /* Can't take the default ring out of the default group */
6142 6342 ASSERT(desired_ring != (mac_ring_t *)mip->mi_default_tx_ring);
6143 6343
6144 6344 if (desired_ring->mr_state == MR_FREE) {
6145 6345 ASSERT(MAC_GROUP_NO_CLIENT(group));
6146 6346 if (mac_start_ring(desired_ring) != 0)
6147 6347 return (NULL);
6148 6348 return (desired_ring);
6149 6349 }
6150 6350 /*
6151 6351 * There are clients using this ring, so let's move the clients
6152 6352 * away from using this ring.
6153 6353 */
6154 6354 for (mgcp = group->mrg_clients; mgcp != NULL; mgcp = mgcp->mgc_next) {
6155 6355 mcip = mgcp->mgc_client;
6156 6356 mac_tx_client_quiesce((mac_client_handle_t)mcip);
6157 6357 srs = MCIP_TX_SRS(mcip);
6158 6358 ASSERT(mac_tx_srs_ring_present(srs, desired_ring));
6159 6359 mac_tx_invoke_callbacks(mcip,
6160 6360 (mac_tx_cookie_t)mac_tx_srs_get_soft_ring(srs,
6161 6361 desired_ring));
6162 6362 mac_tx_srs_del_ring(srs, desired_ring);
6163 6363 mac_tx_client_restart((mac_client_handle_t)mcip);
6164 6364 }
6165 6365 return (desired_ring);
6166 6366 }
6167 6367
6168 6368 /*
6169 6369 * For a non-default group with multiple clients, return the primary client.
6170 6370 */
6171 6371 static mac_client_impl_t *
6172 6372 mac_get_grp_primary(mac_group_t *grp)
6173 6373 {
6174 6374 mac_grp_client_t *mgcp = grp->mrg_clients;
6175 6375 mac_client_impl_t *mcip;
6176 6376
6177 6377 while (mgcp != NULL) {
6178 6378 mcip = mgcp->mgc_client;
6179 6379 if (mcip->mci_flent->fe_type & FLOW_PRIMARY_MAC)
6180 6380 return (mcip);
6181 6381 mgcp = mgcp->mgc_next;
6182 6382 }
6183 6383 return (NULL);
6184 6384 }
6185 6385
6186 6386 /*
6187 6387 * Hybrid I/O specifies the ring that should be given to a share.
6188 6388 * If the ring is already used by clients, then we need to release
6189 6389 * the ring back to the default group so that we can give it to
6190 6390 * the share. This means the clients using this ring now get a
6191 6391 * replacement ring. If there aren't any replacement rings, this
6192 6392 * function returns a failure.
6193 6393 */
6194 6394 static int
6195 6395 mac_reclaim_ring_from_grp(mac_impl_t *mip, mac_ring_type_t ring_type,
6196 6396 mac_ring_t *ring, mac_ring_t **rings, int nrings)
6197 6397 {
6198 6398 mac_group_t *group = (mac_group_t *)ring->mr_gh;
6199 6399 mac_resource_props_t *mrp;
6200 6400 mac_client_impl_t *mcip;
6201 6401 mac_group_t *defgrp;
6202 6402 mac_ring_t *tring;
6203 6403 mac_group_t *tgrp;
6204 6404 int i;
6205 6405 int j;
6206 6406
6207 6407 mcip = MAC_GROUP_ONLY_CLIENT(group);
6208 6408 if (mcip == NULL)
6209 6409 mcip = mac_get_grp_primary(group);
6210 6410 ASSERT(mcip != NULL);
6211 6411 ASSERT(mcip->mci_share == 0);
6212 6412
6213 6413 mrp = MCIP_RESOURCE_PROPS(mcip);
6214 6414 if (ring_type == MAC_RING_TYPE_RX) {
6215 6415 defgrp = mip->mi_rx_donor_grp;
6216 6416 if ((mrp->mrp_mask & MRP_RX_RINGS) == 0) {
6217 6417 /* Need to put this mac client in the default group */
6218 6418 if (mac_rx_switch_group(mcip, group, defgrp) != 0)
6219 6419 return (ENOSPC);
6220 6420 } else {
6221 6421 /*
6222 6422 * Switch this ring with some other ring from
6223 6423 * the default group.
6224 6424 */
6225 6425 for (tring = defgrp->mrg_rings; tring != NULL;
6226 6426 tring = tring->mr_next) {
6227 6427 if (tring->mr_index == 0)
6228 6428 continue;
6229 6429 for (j = 0; j < nrings; j++) {
6230 6430 if (rings[j] == tring)
6231 6431 break;
6232 6432 }
6233 6433 if (j >= nrings)
6234 6434 break;
6235 6435 }
6236 6436 if (tring == NULL)
6237 6437 return (ENOSPC);
6238 6438 if (mac_group_mov_ring(mip, group, tring) != 0)
6239 6439 return (ENOSPC);
6240 6440 if (mac_group_mov_ring(mip, defgrp, ring) != 0) {
6241 6441 (void) mac_group_mov_ring(mip, defgrp, tring);
6242 6442 return (ENOSPC);
6243 6443 }
6244 6444 }
6245 6445 ASSERT(ring->mr_gh == (mac_group_handle_t)defgrp);
6246 6446 return (0);
6247 6447 }
6248 6448
6249 6449 defgrp = MAC_DEFAULT_TX_GROUP(mip);
6250 6450 if (ring == (mac_ring_t *)mip->mi_default_tx_ring) {
6251 6451 /*
6252 6452 * See if we can get a spare ring to replace the default
6253 6453 * ring.
6254 6454 */
6255 6455 if (defgrp->mrg_cur_count == 1) {
6256 6456 /*
6257 6457 * Need to get a ring from another client, see if
6258 6458 * there are any clients that can be moved to
6259 6459 * the default group, thereby freeing some rings.
6260 6460 */
6261 6461 for (i = 0; i < mip->mi_tx_group_count; i++) {
6262 6462 tgrp = &mip->mi_tx_groups[i];
6263 6463 if (tgrp->mrg_state ==
6264 6464 MAC_GROUP_STATE_REGISTERED) {
6265 6465 continue;
6266 6466 }
6267 6467 mcip = MAC_GROUP_ONLY_CLIENT(tgrp);
6268 6468 if (mcip == NULL)
6269 6469 mcip = mac_get_grp_primary(tgrp);
6270 6470 ASSERT(mcip != NULL);
6271 6471 mrp = MCIP_RESOURCE_PROPS(mcip);
6272 6472 if ((mrp->mrp_mask & MRP_TX_RINGS) == 0) {
6273 6473 ASSERT(tgrp->mrg_cur_count == 1);
6274 6474 /*
6275 6475 * If this ring is part of the
6276 6476 * rings asked by the share we cannot
6277 6477 * use it as the default ring.
6278 6478 */
6279 6479 for (j = 0; j < nrings; j++) {
6280 6480 if (rings[j] == tgrp->mrg_rings)
6281 6481 break;
6282 6482 }
6283 6483 if (j < nrings)
6284 6484 continue;
6285 6485 mac_tx_client_quiesce(
6286 6486 (mac_client_handle_t)mcip);
6287 6487 mac_tx_switch_group(mcip, tgrp,
6288 6488 defgrp);
6289 6489 mac_tx_client_restart(
6290 6490 (mac_client_handle_t)mcip);
6291 6491 break;
6292 6492 }
6293 6493 }
6294 6494 /*
6295 6495 * All the rings are reserved, can't give up the
6296 6496 * default ring.
6297 6497 */
6298 6498 if (defgrp->mrg_cur_count <= 1)
6299 6499 return (ENOSPC);
6300 6500 }
6301 6501 /*
6302 6502 * Swap the default ring with another.
6303 6503 */
6304 6504 for (tring = defgrp->mrg_rings; tring != NULL;
6305 6505 tring = tring->mr_next) {
6306 6506 /*
6307 6507 * If this ring is part of the rings asked by the
6308 6508 * share we cannot use it as the default ring.
6309 6509 */
6310 6510 for (j = 0; j < nrings; j++) {
6311 6511 if (rings[j] == tring)
6312 6512 break;
6313 6513 }
6314 6514 if (j >= nrings)
6315 6515 break;
6316 6516 }
6317 6517 ASSERT(tring != NULL);
6318 6518 mip->mi_default_tx_ring = (mac_ring_handle_t)tring;
6319 6519 return (0);
6320 6520 }
6321 6521 /*
6322 6522 * The Tx ring is with a group reserved by a MAC client. See if
6323 6523 * we can swap it.
6324 6524 */
6325 6525 ASSERT(group->mrg_state == MAC_GROUP_STATE_RESERVED);
6326 6526 mcip = MAC_GROUP_ONLY_CLIENT(group);
6327 6527 if (mcip == NULL)
6328 6528 mcip = mac_get_grp_primary(group);
6329 6529 ASSERT(mcip != NULL);
6330 6530 mrp = MCIP_RESOURCE_PROPS(mcip);
6331 6531 mac_tx_client_quiesce((mac_client_handle_t)mcip);
6332 6532 if ((mrp->mrp_mask & MRP_TX_RINGS) == 0) {
6333 6533 ASSERT(group->mrg_cur_count == 1);
6334 6534 /* Put this mac client in the default group */
6335 6535 mac_tx_switch_group(mcip, group, defgrp);
6336 6536 } else {
6337 6537 /*
6338 6538 * Switch this ring with some other ring from
6339 6539 * the default group.
6340 6540 */
6341 6541 for (tring = defgrp->mrg_rings; tring != NULL;
6342 6542 tring = tring->mr_next) {
6343 6543 if (tring == (mac_ring_t *)mip->mi_default_tx_ring)
6344 6544 continue;
6345 6545 /*
6346 6546 * If this ring is part of the rings asked by the
6347 6547 * share we cannot use it for swapping.
6348 6548 */
6349 6549 for (j = 0; j < nrings; j++) {
6350 6550 if (rings[j] == tring)
6351 6551 break;
6352 6552 }
6353 6553 if (j >= nrings)
6354 6554 break;
6355 6555 }
6356 6556 if (tring == NULL) {
6357 6557 mac_tx_client_restart((mac_client_handle_t)mcip);
6358 6558 return (ENOSPC);
6359 6559 }
6360 6560 if (mac_group_mov_ring(mip, group, tring) != 0) {
6361 6561 mac_tx_client_restart((mac_client_handle_t)mcip);
6362 6562 return (ENOSPC);
6363 6563 }
6364 6564 if (mac_group_mov_ring(mip, defgrp, ring) != 0) {
6365 6565 (void) mac_group_mov_ring(mip, defgrp, tring);
6366 6566 mac_tx_client_restart((mac_client_handle_t)mcip);
6367 6567 return (ENOSPC);
6368 6568 }
6369 6569 }
6370 6570 mac_tx_client_restart((mac_client_handle_t)mcip);
6371 6571 ASSERT(ring->mr_gh == (mac_group_handle_t)defgrp);
6372 6572 return (0);
6373 6573 }
6374 6574
6375 6575 /*
6376 6576 * Populate a zero-ring group with rings. If the share is non-NULL,
6377 6577 * the rings are chosen according to that share.
6378 6578 * Invoked after allocating a new RX or TX group through
6379 6579 * mac_reserve_rx_group() or mac_reserve_tx_group(), respectively.
6380 6580 * Returns zero on success, an errno otherwise.
6381 6581 */
6382 6582 int
6383 6583 i_mac_group_allocate_rings(mac_impl_t *mip, mac_ring_type_t ring_type,
6384 6584 mac_group_t *src_group, mac_group_t *new_group, mac_share_handle_t share,
6385 6585 uint32_t ringcnt)
6386 6586 {
6387 6587 mac_ring_t **rings, *ring;
6388 6588 uint_t nrings;
6389 6589 int rv = 0, i = 0, j;
6390 6590
6391 6591 ASSERT((ring_type == MAC_RING_TYPE_RX &&
6392 6592 mip->mi_rx_group_type == MAC_GROUP_TYPE_DYNAMIC) ||
6393 6593 (ring_type == MAC_RING_TYPE_TX &&
6394 6594 mip->mi_tx_group_type == MAC_GROUP_TYPE_DYNAMIC));
6395 6595
6396 6596 /*
6397 6597 * First find the rings to allocate to the group.
6398 6598 */
6399 6599 if (share != 0) {
6400 6600 /* get rings through ms_squery() */
6401 6601 mip->mi_share_capab.ms_squery(share, ring_type, NULL, &nrings);
6402 6602 ASSERT(nrings != 0);
6403 6603 rings = kmem_alloc(nrings * sizeof (mac_ring_handle_t),
6404 6604 KM_SLEEP);
6405 6605 mip->mi_share_capab.ms_squery(share, ring_type,
6406 6606 (mac_ring_handle_t *)rings, &nrings);
6407 6607 for (i = 0; i < nrings; i++) {
6408 6608 /*
6409 6609 * If we have given this ring to a non-default
6410 6610 * group, we need to check if we can get this
6411 6611 * ring.
6412 6612 */
6413 6613 ring = rings[i];
6414 6614 if (ring->mr_gh != (mac_group_handle_t)src_group ||
6415 6615 ring == (mac_ring_t *)mip->mi_default_tx_ring) {
6416 6616 if (mac_reclaim_ring_from_grp(mip, ring_type,
6417 6617 ring, rings, nrings) != 0) {
6418 6618 rv = ENOSPC;
6419 6619 goto bail;
6420 6620 }
6421 6621 }
6422 6622 }
6423 6623 } else {
6424 6624 /*
6425 6625 * Pick one ring from default group.
6426 6626 *
6427 6627 * for now pick the second ring which requires the first ring
6428 6628 * at index 0 to stay in the default group, since it is the
6429 6629 * ring which carries the multicast traffic.
6430 6630 * We need a better way for a driver to indicate this,
6431 6631 * for example a per-ring flag.
6432 6632 */
6433 6633 rings = kmem_alloc(ringcnt * sizeof (mac_ring_handle_t),
6434 6634 KM_SLEEP);
6435 6635 for (ring = src_group->mrg_rings; ring != NULL;
6436 6636 ring = ring->mr_next) {
6437 6637 if (ring_type == MAC_RING_TYPE_RX &&
6438 6638 ring->mr_index == 0) {
6439 6639 continue;
6440 6640 }
6441 6641 if (ring_type == MAC_RING_TYPE_TX &&
6442 6642 ring == (mac_ring_t *)mip->mi_default_tx_ring) {
6443 6643 continue;
6444 6644 }
6445 6645 rings[i++] = ring;
6446 6646 if (i == ringcnt)
6447 6647 break;
6448 6648 }
6449 6649 ASSERT(ring != NULL);
6450 6650 nrings = i;
6451 6651 /* Not enough rings as required */
6452 6652 if (nrings != ringcnt) {
6453 6653 rv = ENOSPC;
6454 6654 goto bail;
6455 6655 }
6456 6656 }
6457 6657
6458 6658 switch (ring_type) {
6459 6659 case MAC_RING_TYPE_RX:
6460 6660 if (src_group->mrg_cur_count - nrings < 1) {
6461 6661 /* we ran out of rings */
6462 6662 rv = ENOSPC;
6463 6663 goto bail;
6464 6664 }
6465 6665
6466 6666 /* move receive rings to new group */
6467 6667 for (i = 0; i < nrings; i++) {
6468 6668 rv = mac_group_mov_ring(mip, new_group, rings[i]);
6469 6669 if (rv != 0) {
6470 6670 /* move rings back on failure */
6471 6671 for (j = 0; j < i; j++) {
6472 6672 (void) mac_group_mov_ring(mip,
6473 6673 src_group, rings[j]);
6474 6674 }
6475 6675 goto bail;
6476 6676 }
6477 6677 }
6478 6678 break;
6479 6679
6480 6680 case MAC_RING_TYPE_TX: {
6481 6681 mac_ring_t *tmp_ring;
6482 6682
6483 6683 /* move the TX rings to the new group */
6484 6684 for (i = 0; i < nrings; i++) {
6485 6685 /* get the desired ring */
6486 6686 tmp_ring = mac_reserve_tx_ring(mip, rings[i]);
6487 6687 if (tmp_ring == NULL) {
6488 6688 rv = ENOSPC;
6489 6689 goto bail;
6490 6690 }
6491 6691 ASSERT(tmp_ring == rings[i]);
6492 6692 rv = mac_group_mov_ring(mip, new_group, rings[i]);
6493 6693 if (rv != 0) {
6494 6694 /* cleanup on failure */
6495 6695 for (j = 0; j < i; j++) {
6496 6696 (void) mac_group_mov_ring(mip,
6497 6697 MAC_DEFAULT_TX_GROUP(mip),
6498 6698 rings[j]);
6499 6699 }
6500 6700 goto bail;
6501 6701 }
6502 6702 }
6503 6703 break;
6504 6704 }
6505 6705 }
6506 6706
6507 6707 /* add group to share */
6508 6708 if (share != 0)
6509 6709 mip->mi_share_capab.ms_sadd(share, new_group->mrg_driver);
6510 6710
6511 6711 bail:
6512 6712 /* free temporary array of rings */
6513 6713 kmem_free(rings, nrings * sizeof (mac_ring_handle_t));
6514 6714
6515 6715 return (rv);
6516 6716 }
6517 6717
6518 6718 void
6519 6719 mac_group_add_client(mac_group_t *grp, mac_client_impl_t *mcip)
6520 6720 {
6521 6721 mac_grp_client_t *mgcp;
6522 6722
6523 6723 for (mgcp = grp->mrg_clients; mgcp != NULL; mgcp = mgcp->mgc_next) {
6524 6724 if (mgcp->mgc_client == mcip)
6525 6725 break;
6526 6726 }
6527 6727
6528 6728 ASSERT(mgcp == NULL);
6529 6729
6530 6730 mgcp = kmem_zalloc(sizeof (mac_grp_client_t), KM_SLEEP);
6531 6731 mgcp->mgc_client = mcip;
6532 6732 mgcp->mgc_next = grp->mrg_clients;
6533 6733 grp->mrg_clients = mgcp;
6534 6734 }
6535 6735
6536 6736 void
6537 6737 mac_group_remove_client(mac_group_t *grp, mac_client_impl_t *mcip)
6538 6738 {
6539 6739 mac_grp_client_t *mgcp, **pprev;
6540 6740
6541 6741 for (pprev = &grp->mrg_clients, mgcp = *pprev; mgcp != NULL;
6542 6742 pprev = &mgcp->mgc_next, mgcp = *pprev) {
6543 6743 if (mgcp->mgc_client == mcip)
6544 6744 break;
6545 6745 }
6546 6746
6547 6747 ASSERT(mgcp != NULL);
6548 6748
6549 6749 *pprev = mgcp->mgc_next;
6550 6750 kmem_free(mgcp, sizeof (mac_grp_client_t));
6551 6751 }
6552 6752
6553 6753 /*
6554 6754 * Return true if any client on this group explicitly asked for HW
6555 6755 * rings (of type mask) or have a bound share.
6556 6756 */
6557 6757 static boolean_t
6558 6758 i_mac_clients_hw(mac_group_t *grp, uint32_t mask)
6559 6759 {
6560 6760 mac_grp_client_t *mgcip;
6561 6761 mac_client_impl_t *mcip;
6562 6762 mac_resource_props_t *mrp;
6563 6763
6564 6764 for (mgcip = grp->mrg_clients; mgcip != NULL; mgcip = mgcip->mgc_next) {
6565 6765 mcip = mgcip->mgc_client;
6566 6766 mrp = MCIP_RESOURCE_PROPS(mcip);
6567 6767 if (mcip->mci_share != 0 || (mrp->mrp_mask & mask) != 0)
6568 6768 return (B_TRUE);
6569 6769 }
6570 6770
6571 6771 return (B_FALSE);
6572 6772 }
6573 6773
6574 6774 /*
6575 6775 * Finds an available group and exclusively reserves it for a client.
6576 6776 * The group is chosen to suit the flow's resource controls (bandwidth and
6577 6777 * fanout requirements) and the address type.
6578 6778 * If the requestor is the pimary MAC then return the group with the
6579 6779 * largest number of rings, otherwise the default ring when available.
6580 6780 */
6581 6781 mac_group_t *
6582 6782 mac_reserve_rx_group(mac_client_impl_t *mcip, uint8_t *mac_addr, boolean_t move)
6583 6783 {
6584 6784 mac_share_handle_t share = mcip->mci_share;
6585 6785 mac_impl_t *mip = mcip->mci_mip;
6586 6786 mac_group_t *grp = NULL;
6587 6787 int i;
6588 6788 int err = 0;
6589 6789 mac_address_t *map;
6590 6790 mac_resource_props_t *mrp = MCIP_RESOURCE_PROPS(mcip);
6591 6791 int nrings;
6592 6792 int donor_grp_rcnt;
6593 6793 boolean_t need_exclgrp = B_FALSE;
6594 6794 int need_rings = 0;
6595 6795 mac_group_t *candidate_grp = NULL;
6596 6796 mac_client_impl_t *gclient;
6597 6797 mac_group_t *donorgrp = NULL;
6598 6798 boolean_t rxhw = mrp->mrp_mask & MRP_RX_RINGS;
6599 6799 boolean_t unspec = mrp->mrp_mask & MRP_RXRINGS_UNSPEC;
6600 6800 boolean_t isprimary;
6601 6801
6602 6802 ASSERT(MAC_PERIM_HELD((mac_handle_t)mip));
6603 6803
6604 6804 isprimary = mcip->mci_flent->fe_type & FLOW_PRIMARY_MAC;
6605 6805
6606 6806 /*
6607 6807 * Check if a group already has this MAC address (case of VLANs)
6608 6808 * unless we are moving this MAC client from one group to another.
6609 6809 */
6610 6810 if (!move && (map = mac_find_macaddr(mip, mac_addr)) != NULL) {
6611 6811 if (map->ma_group != NULL)
6612 6812 return (map->ma_group);
6613 6813 }
6614 6814
6615 6815 if (mip->mi_rx_groups == NULL || mip->mi_rx_group_count == 0)
6616 6816 return (NULL);
6617 6817
6618 6818 /*
6619 6819 * If this client is requesting exclusive MAC access then
6620 6820 * return NULL to ensure the client uses the default group.
6621 6821 */
6622 6822 if (mcip->mci_state_flags & MCIS_EXCLUSIVE)
6623 6823 return (NULL);
6624 6824
6625 6825 /* For dynamic groups default unspecified to 1 */
6626 6826 if (rxhw && unspec &&
6627 6827 mip->mi_rx_group_type == MAC_GROUP_TYPE_DYNAMIC) {
6628 6828 mrp->mrp_nrxrings = 1;
6629 6829 }
6630 6830
6631 6831 /*
6632 6832 * For static grouping we allow only specifying rings=0 and
6633 6833 * unspecified
6634 6834 */
6635 6835 if (rxhw && mrp->mrp_nrxrings > 0 &&
6636 6836 mip->mi_rx_group_type == MAC_GROUP_TYPE_STATIC) {
6637 6837 return (NULL);
6638 6838 }
6639 6839
6640 6840 if (rxhw) {
6641 6841 /*
6642 6842 * We have explicitly asked for a group (with nrxrings,
6643 6843 * if unspec).
6644 6844 */
6645 6845 if (unspec || mrp->mrp_nrxrings > 0) {
6646 6846 need_exclgrp = B_TRUE;
6647 6847 need_rings = mrp->mrp_nrxrings;
6648 6848 } else if (mrp->mrp_nrxrings == 0) {
6649 6849 /*
6650 6850 * We have asked for a software group.
6651 6851 */
6652 6852 return (NULL);
6653 6853 }
6654 6854 } else if (isprimary && mip->mi_nactiveclients == 1 &&
6655 6855 mip->mi_rx_group_type == MAC_GROUP_TYPE_DYNAMIC) {
6656 6856 /*
6657 6857 * If the primary is the only active client on this
6658 6858 * mip and we have not asked for any rings, we give
6659 6859 * it the default group so that the primary gets to
6660 6860 * use all the rings.
6661 6861 */
6662 6862 return (NULL);
6663 6863 }
6664 6864
6665 6865 /* The group that can donate rings */
6666 6866 donorgrp = mip->mi_rx_donor_grp;
6667 6867
6668 6868 /*
6669 6869 * The number of rings that the default group can donate.
6670 6870 * We need to leave at least one ring.
6671 6871 */
6672 6872 donor_grp_rcnt = donorgrp->mrg_cur_count - 1;
6673 6873
6674 6874 /*
6675 6875 * Try to exclusively reserve a RX group.
6676 6876 *
6677 6877 * For flows requiring HW_DEFAULT_RING (unicast flow of the primary
6678 6878 * client), try to reserve the a non-default RX group and give
6679 6879 * it all the rings from the donor group, except the default ring
6680 6880 *
6681 6881 * For flows requiring HW_RING (unicast flow of other clients), try
6682 6882 * to reserve non-default RX group with the specified number of
6683 6883 * rings, if available.
6684 6884 *
6685 6885 * For flows that have not asked for software or hardware ring,
6686 6886 * try to reserve a non-default group with 1 ring, if available.
6687 6887 */
6688 6888 for (i = 1; i < mip->mi_rx_group_count; i++) {
6689 6889 grp = &mip->mi_rx_groups[i];
6690 6890
6691 6891 DTRACE_PROBE3(rx__group__trying, char *, mip->mi_name,
6692 6892 int, grp->mrg_index, mac_group_state_t, grp->mrg_state);
6693 6893
6694 6894 /*
6695 6895 * Check if this group could be a candidate group for
6696 6896 * eviction if we need a group for this MAC client,
6697 6897 * but there aren't any. A candidate group is one
6698 6898 * that didn't ask for an exclusive group, but got
6699 6899 * one and it has enough rings (combined with what
6700 6900 * the donor group can donate) for the new MAC
6701 6901 * client.
6702 6902 */
6703 6903 if (grp->mrg_state >= MAC_GROUP_STATE_RESERVED) {
6704 6904 /*
6705 6905 * If the donor group is not the default
6706 6906 * group, don't bother looking for a candidate
6707 6907 * group. If we don't have enough rings we
6708 6908 * will check if the primary group can be
6709 6909 * vacated.
6710 6910 */
6711 6911 if (candidate_grp == NULL &&
6712 6912 donorgrp == MAC_DEFAULT_RX_GROUP(mip)) {
6713 6913 if (!i_mac_clients_hw(grp, MRP_RX_RINGS) &&
6714 6914 (unspec ||
6715 6915 (grp->mrg_cur_count + donor_grp_rcnt >=
6716 6916 need_rings))) {
6717 6917 candidate_grp = grp;
6718 6918 }
6719 6919 }
6720 6920 continue;
6721 6921 }
6722 6922 /*
6723 6923 * This group could already be SHARED by other multicast
6724 6924 * flows on this client. In that case, the group would
6725 6925 * be shared and has already been started.
6726 6926 */
6727 6927 ASSERT(grp->mrg_state != MAC_GROUP_STATE_UNINIT);
6728 6928
6729 6929 if ((grp->mrg_state == MAC_GROUP_STATE_REGISTERED) &&
6730 6930 (mac_start_group(grp) != 0)) {
6731 6931 continue;
6732 6932 }
6733 6933
6734 6934 if (mip->mi_rx_group_type != MAC_GROUP_TYPE_DYNAMIC)
6735 6935 break;
6736 6936 ASSERT(grp->mrg_cur_count == 0);
6737 6937
6738 6938 /*
6739 6939 * Populate the group. Rings should be taken
6740 6940 * from the donor group.
6741 6941 */
6742 6942 nrings = rxhw ? need_rings : isprimary ? donor_grp_rcnt: 1;
6743 6943
6744 6944 /*
6745 6945 * If the donor group can't donate, let's just walk and
6746 6946 * see if someone can vacate a group, so that we have
6747 6947 * enough rings for this, unless we already have
6748 6948 * identified a candiate group..
6749 6949 */
6750 6950 if (nrings <= donor_grp_rcnt) {
6751 6951 err = i_mac_group_allocate_rings(mip, MAC_RING_TYPE_RX,
6752 6952 donorgrp, grp, share, nrings);
6753 6953 if (err == 0) {
6754 6954 /*
6755 6955 * For a share i_mac_group_allocate_rings gets
6756 6956 * the rings from the driver, let's populate
6757 6957 * the property for the client now.
6758 6958 */
6759 6959 if (share != 0) {
6760 6960 mac_client_set_rings(
6761 6961 (mac_client_handle_t)mcip,
6762 6962 grp->mrg_cur_count, -1);
6763 6963 }
6764 6964 if (mac_is_primary_client(mcip) && !rxhw)
6765 6965 mip->mi_rx_donor_grp = grp;
6766 6966 break;
6767 6967 }
6768 6968 }
6769 6969
6770 6970 DTRACE_PROBE3(rx__group__reserve__alloc__rings, char *,
6771 6971 mip->mi_name, int, grp->mrg_index, int, err);
6772 6972
6773 6973 /*
6774 6974 * It's a dynamic group but the grouping operation
6775 6975 * failed.
6776 6976 */
6777 6977 mac_stop_group(grp);
6778 6978 }
6779 6979
6780 6980 /* We didn't find an exclusive group for this MAC client */
6781 6981 if (i >= mip->mi_rx_group_count) {
6782 6982
6783 6983 if (!need_exclgrp)
6784 6984 return (NULL);
6785 6985
6786 6986 /*
6787 6987 * If we found a candidate group then move the
6788 6988 * existing MAC client from the candidate_group to the
6789 6989 * default group and give the candidate_group to the
6790 6990 * new MAC client. If we didn't find a candidate
6791 6991 * group, then check if the primary is in its own
6792 6992 * group and if it can make way for this MAC client.
6793 6993 */
6794 6994 if (candidate_grp == NULL &&
6795 6995 donorgrp != MAC_DEFAULT_RX_GROUP(mip) &&
6796 6996 donorgrp->mrg_cur_count >= need_rings) {
6797 6997 candidate_grp = donorgrp;
6798 6998 }
6799 6999 if (candidate_grp != NULL) {
6800 7000 boolean_t prim_grp = B_FALSE;
6801 7001
6802 7002 /*
6803 7003 * Switch the existing MAC client from the
6804 7004 * candidate group to the default group. If
6805 7005 * the candidate group is the donor group,
6806 7006 * then after the switch we need to update the
6807 7007 * donor group too.
6808 7008 */
6809 7009 grp = candidate_grp;
6810 7010 gclient = grp->mrg_clients->mgc_client;
6811 7011 VERIFY3P(gclient, !=, NULL);
6812 7012 if (grp == mip->mi_rx_donor_grp)
6813 7013 prim_grp = B_TRUE;
6814 7014 if (mac_rx_switch_group(gclient, grp,
6815 7015 MAC_DEFAULT_RX_GROUP(mip)) != 0) {
6816 7016 return (NULL);
6817 7017 }
6818 7018 if (prim_grp) {
6819 7019 mip->mi_rx_donor_grp =
6820 7020 MAC_DEFAULT_RX_GROUP(mip);
6821 7021 donorgrp = MAC_DEFAULT_RX_GROUP(mip);
6822 7022 }
6823 7023
6824 7024 /*
6825 7025 * Now give this group with the required rings
6826 7026 * to this MAC client.
6827 7027 */
6828 7028 ASSERT(grp->mrg_state == MAC_GROUP_STATE_REGISTERED);
6829 7029 if (mac_start_group(grp) != 0)
6830 7030 return (NULL);
6831 7031
6832 7032 if (mip->mi_rx_group_type != MAC_GROUP_TYPE_DYNAMIC)
6833 7033 return (grp);
6834 7034
6835 7035 donor_grp_rcnt = donorgrp->mrg_cur_count - 1;
6836 7036 ASSERT(grp->mrg_cur_count == 0);
6837 7037 ASSERT(donor_grp_rcnt >= need_rings);
6838 7038 err = i_mac_group_allocate_rings(mip, MAC_RING_TYPE_RX,
6839 7039 donorgrp, grp, share, need_rings);
6840 7040 if (err == 0) {
6841 7041 /*
6842 7042 * For a share i_mac_group_allocate_rings gets
6843 7043 * the rings from the driver, let's populate
6844 7044 * the property for the client now.
6845 7045 */
6846 7046 if (share != 0) {
6847 7047 mac_client_set_rings(
6848 7048 (mac_client_handle_t)mcip,
6849 7049 grp->mrg_cur_count, -1);
6850 7050 }
6851 7051 DTRACE_PROBE2(rx__group__reserved,
6852 7052 char *, mip->mi_name, int, grp->mrg_index);
6853 7053 return (grp);
6854 7054 }
6855 7055 DTRACE_PROBE3(rx__group__reserve__alloc__rings, char *,
6856 7056 mip->mi_name, int, grp->mrg_index, int, err);
6857 7057 mac_stop_group(grp);
6858 7058 }
6859 7059 return (NULL);
6860 7060 }
6861 7061 ASSERT(grp != NULL);
6862 7062
6863 7063 DTRACE_PROBE2(rx__group__reserved,
6864 7064 char *, mip->mi_name, int, grp->mrg_index);
6865 7065 return (grp);
6866 7066 }
6867 7067
6868 7068 /*
6869 7069 * mac_rx_release_group()
6870 7070 *
6871 7071 * Release the group when it has no remaining clients. The group is
6872 7072 * stopped and its shares are removed and all rings are assigned back
6873 7073 * to default group. This should never be called against the default
6874 7074 * group.
6875 7075 */
6876 7076 void
6877 7077 mac_release_rx_group(mac_client_impl_t *mcip, mac_group_t *group)
6878 7078 {
6879 7079 mac_impl_t *mip = mcip->mci_mip;
6880 7080 mac_ring_t *ring;
6881 7081
6882 7082 ASSERT(group != MAC_DEFAULT_RX_GROUP(mip));
6883 7083 ASSERT(MAC_GROUP_NO_CLIENT(group) == B_TRUE);
6884 7084
6885 7085 if (mip->mi_rx_donor_grp == group)
6886 7086 mip->mi_rx_donor_grp = MAC_DEFAULT_RX_GROUP(mip);
6887 7087
6888 7088 /*
6889 7089 * This is the case where there are no clients left. Any
6890 7090 * SRS etc on this group have also be quiesced.
6891 7091 */
6892 7092 for (ring = group->mrg_rings; ring != NULL; ring = ring->mr_next) {
6893 7093 if (ring->mr_classify_type == MAC_HW_CLASSIFIER) {
6894 7094 ASSERT(group->mrg_state == MAC_GROUP_STATE_RESERVED);
6895 7095 /*
6896 7096 * Remove the SRS associated with the HW ring.
6897 7097 * As a result, polling will be disabled.
6898 7098 */
6899 7099 ring->mr_srs = NULL;
6900 7100 }
6901 7101 ASSERT(group->mrg_state < MAC_GROUP_STATE_RESERVED ||
6902 7102 ring->mr_state == MR_INUSE);
6903 7103 if (ring->mr_state == MR_INUSE) {
6904 7104 mac_stop_ring(ring);
6905 7105 ring->mr_flag = 0;
6906 7106 }
6907 7107 }
6908 7108
6909 7109 /* remove group from share */
6910 7110 if (mcip->mci_share != 0) {
6911 7111 mip->mi_share_capab.ms_sremove(mcip->mci_share,
6912 7112 group->mrg_driver);
6913 7113 }
6914 7114
6915 7115 if (mip->mi_rx_group_type == MAC_GROUP_TYPE_DYNAMIC) {
6916 7116 mac_ring_t *ring;
6917 7117
6918 7118 /*
6919 7119 * Rings were dynamically allocated to group.
6920 7120 * Move rings back to default group.
6921 7121 */
6922 7122 while ((ring = group->mrg_rings) != NULL) {
6923 7123 (void) mac_group_mov_ring(mip, mip->mi_rx_donor_grp,
6924 7124 ring);
6925 7125 }
6926 7126 }
6927 7127 mac_stop_group(group);
6928 7128 /*
6929 7129 * Possible improvement: See if we can assign the group just released
6930 7130 * to a another client of the mip
6931 7131 */
6932 7132 }
6933 7133
6934 7134 /*
6935 7135 * Move the MAC address from fgrp to tgrp.
6936 7136 */
6937 7137 static int
6938 7138 mac_rx_move_macaddr(mac_client_impl_t *mcip, mac_group_t *fgrp,
6939 7139 mac_group_t *tgrp)
6940 7140 {
6941 7141 mac_impl_t *mip = mcip->mci_mip;
6942 7142 uint8_t maddr[MAXMACADDRLEN];
6943 7143 int err = 0;
6944 7144 uint16_t vid;
6945 7145 mac_unicast_impl_t *muip;
6946 7146 boolean_t use_hw;
6947 7147
6948 7148 mac_rx_client_quiesce((mac_client_handle_t)mcip);
6949 7149 VERIFY3P(mcip->mci_unicast, !=, NULL);
6950 7150 bcopy(mcip->mci_unicast->ma_addr, maddr, mcip->mci_unicast->ma_len);
6951 7151
6952 7152 /*
6953 7153 * Does the client require MAC address hardware classifiction?
6954 7154 */
6955 7155 use_hw = (mcip->mci_state_flags & MCIS_UNICAST_HW) != 0;
6956 7156 vid = i_mac_flow_vid(mcip->mci_flent);
6957 7157
6958 7158 /*
6959 7159 * You can never move an address that is shared by multiple
6960 7160 * clients. mac_datapath_setup() ensures that clients sharing
6961 7161 * an address are placed on the default group. This guarantees
6962 7162 * that a non-default group will only ever have one client and
6963 7163 * thus make full use of HW filters.
6964 7164 */
6965 7165 if (mac_check_macaddr_shared(mcip->mci_unicast))
6966 7166 return (EINVAL);
6967 7167
6968 7168 err = mac_remove_macaddr_vlan(mcip->mci_unicast, vid);
6969 7169
6970 7170 if (err != 0) {
6971 7171 mac_rx_client_restart((mac_client_handle_t)mcip);
6972 7172 return (err);
6973 7173 }
6974 7174
6975 7175 /*
6976 7176 * If this isn't the primary MAC address then the
6977 7177 * mac_address_t has been freed by the last call to
6978 7178 * mac_remove_macaddr_vlan(). In any case, NULL the reference
6979 7179 * to avoid a dangling pointer.
6980 7180 */
6981 7181 mcip->mci_unicast = NULL;
6982 7182
6983 7183 /*
6984 7184 * We also have to NULL all the mui_map references -- sun4v
6985 7185 * strikes again!
6986 7186 */
6987 7187 rw_enter(&mcip->mci_rw_lock, RW_WRITER);
6988 7188 for (muip = mcip->mci_unicast_list; muip != NULL; muip = muip->mui_next)
6989 7189 muip->mui_map = NULL;
6990 7190 rw_exit(&mcip->mci_rw_lock);
6991 7191
6992 7192 /*
6993 7193 * Program the H/W Classifier first, if this fails we need not
6994 7194 * proceed with the other stuff.
6995 7195 */
6996 7196 if ((err = mac_add_macaddr_vlan(mip, tgrp, maddr, vid, use_hw)) != 0) {
6997 7197 int err2;
6998 7198
6999 7199 /* Revert back the H/W Classifier */
7000 7200 err2 = mac_add_macaddr_vlan(mip, fgrp, maddr, vid, use_hw);
7001 7201
7002 7202 if (err2 != 0) {
7003 7203 cmn_err(CE_WARN, "Failed to revert HW classification"
7004 7204 " on MAC %s, for client %s: %d.", mip->mi_name,
7005 7205 mcip->mci_name, err2);
7006 7206 }
7007 7207
7008 7208 mac_rx_client_restart((mac_client_handle_t)mcip);
7009 7209 return (err);
7010 7210 }
7011 7211
7012 7212 /*
7013 7213 * Get a reference to the new mac_address_t and update the
7014 7214 * client's reference. Then restart the client and add the
7015 7215 * other clients of this MAC addr (if they exsit).
7016 7216 */
7017 7217 mcip->mci_unicast = mac_find_macaddr(mip, maddr);
7018 7218 rw_enter(&mcip->mci_rw_lock, RW_WRITER);
7019 7219 for (muip = mcip->mci_unicast_list; muip != NULL; muip = muip->mui_next)
7020 7220 muip->mui_map = mcip->mci_unicast;
7021 7221 rw_exit(&mcip->mci_rw_lock);
7022 7222 mac_rx_client_restart((mac_client_handle_t)mcip);
7023 7223 return (0);
7024 7224 }
7025 7225
7026 7226 /*
7027 7227 * Switch the MAC client from one group to another. This means we need
7028 7228 * to remove the MAC address from the group, remove the MAC client,
7029 7229 * teardown the SRSs and revert the group state. Then, we add the client
7030 7230 * to the destination group, set the SRSs, and add the MAC address to the
7031 7231 * group.
7032 7232 */
7033 7233 int
7034 7234 mac_rx_switch_group(mac_client_impl_t *mcip, mac_group_t *fgrp,
7035 7235 mac_group_t *tgrp)
7036 7236 {
7037 7237 int err;
7038 7238 mac_group_state_t next_state;
7039 7239 mac_client_impl_t *group_only_mcip;
7040 7240 mac_client_impl_t *gmcip;
7041 7241 mac_impl_t *mip = mcip->mci_mip;
7042 7242 mac_grp_client_t *mgcp;
7043 7243
7044 7244 VERIFY3P(fgrp, ==, mcip->mci_flent->fe_rx_ring_group);
7045 7245
7046 7246 if ((err = mac_rx_move_macaddr(mcip, fgrp, tgrp)) != 0)
7047 7247 return (err);
7048 7248
7049 7249 /*
7050 7250 * If the group is marked as reserved and in use by a single
7051 7251 * client, then there is an SRS to teardown.
7052 7252 */
7053 7253 if (fgrp->mrg_state == MAC_GROUP_STATE_RESERVED &&
7054 7254 MAC_GROUP_ONLY_CLIENT(fgrp) != NULL) {
7055 7255 mac_rx_srs_group_teardown(mcip->mci_flent, B_TRUE);
7056 7256 }
7057 7257
7058 7258 /*
7059 7259 * If we are moving the client from a non-default group, then
7060 7260 * we know that any additional clients on this group share the
7061 7261 * same MAC address. Since we moved the MAC address filter, we
7062 7262 * need to move these clients too.
7063 7263 *
7064 7264 * If we are moving the client from the default group and its
7065 7265 * MAC address has VLAN clients, then we must move those
7066 7266 * clients as well.
7067 7267 *
7068 7268 * In both cases the idea is the same: we moved the MAC
7069 7269 * address filter to the tgrp, so we must move all clients
7070 7270 * using that MAC address to tgrp as well.
7071 7271 */
7072 7272 if (fgrp != MAC_DEFAULT_RX_GROUP(mip)) {
7073 7273 mgcp = fgrp->mrg_clients;
7074 7274 while (mgcp != NULL) {
7075 7275 gmcip = mgcp->mgc_client;
7076 7276 mgcp = mgcp->mgc_next;
7077 7277 mac_group_remove_client(fgrp, gmcip);
7078 7278 mac_group_add_client(tgrp, gmcip);
7079 7279 gmcip->mci_flent->fe_rx_ring_group = tgrp;
7080 7280 }
7081 7281 mac_release_rx_group(mcip, fgrp);
7082 7282 VERIFY3B(MAC_GROUP_NO_CLIENT(fgrp), ==, B_TRUE);
7083 7283 mac_set_group_state(fgrp, MAC_GROUP_STATE_REGISTERED);
7084 7284 } else {
7085 7285 mac_group_remove_client(fgrp, mcip);
7086 7286 mac_group_add_client(tgrp, mcip);
7087 7287 mcip->mci_flent->fe_rx_ring_group = tgrp;
7088 7288
7089 7289 /*
7090 7290 * If there are other clients (VLANs) sharing this address
7091 7291 * then move them too.
7092 7292 */
7093 7293 if (mac_check_macaddr_shared(mcip->mci_unicast)) {
7094 7294 /*
7095 7295 * We need to move all the clients that are using
7096 7296 * this MAC address.
7097 7297 */
7098 7298 mgcp = fgrp->mrg_clients;
7099 7299 while (mgcp != NULL) {
7100 7300 gmcip = mgcp->mgc_client;
7101 7301 mgcp = mgcp->mgc_next;
7102 7302 if (mcip->mci_unicast == gmcip->mci_unicast) {
7103 7303 mac_group_remove_client(fgrp, gmcip);
7104 7304 mac_group_add_client(tgrp, gmcip);
7105 7305 gmcip->mci_flent->fe_rx_ring_group =
7106 7306 tgrp;
7107 7307 }
7108 7308 }
7109 7309 }
7110 7310
7111 7311 /*
7112 7312 * The default group still handles multicast and
7113 7313 * broadcast traffic; it won't transition to
7114 7314 * MAC_GROUP_STATE_REGISTERED.
7115 7315 */
7116 7316 if (fgrp->mrg_state == MAC_GROUP_STATE_RESERVED)
7117 7317 mac_rx_group_unmark(fgrp, MR_CONDEMNED);
7118 7318 mac_set_group_state(fgrp, MAC_GROUP_STATE_SHARED);
7119 7319 }
7120 7320
7121 7321 next_state = mac_group_next_state(tgrp, &group_only_mcip,
7122 7322 MAC_DEFAULT_RX_GROUP(mip), B_TRUE);
7123 7323 mac_set_group_state(tgrp, next_state);
7124 7324
7125 7325 /*
7126 7326 * If the destination group is reserved, then setup the SRSes.
7127 7327 * Otherwise make sure to use SW classification.
7128 7328 */
7129 7329 if (tgrp->mrg_state == MAC_GROUP_STATE_RESERVED) {
7130 7330 mac_rx_srs_group_setup(mcip, mcip->mci_flent, SRST_LINK);
7131 7331 mac_fanout_setup(mcip, mcip->mci_flent,
7132 7332 MCIP_RESOURCE_PROPS(mcip), mac_rx_deliver, mcip, NULL,
7133 7333 NULL);
7134 7334 mac_rx_group_unmark(tgrp, MR_INCIPIENT);
7135 7335 } else {
7136 7336 mac_rx_switch_grp_to_sw(tgrp);
7137 7337 }
7138 7338
7139 7339 return (0);
7140 7340 }
7141 7341
7142 7342 /*
7143 7343 * Reserves a TX group for the specified share. Invoked by mac_tx_srs_setup()
7144 7344 * when a share was allocated to the client.
7145 7345 */
7146 7346 mac_group_t *
7147 7347 mac_reserve_tx_group(mac_client_impl_t *mcip, boolean_t move)
7148 7348 {
7149 7349 mac_impl_t *mip = mcip->mci_mip;
7150 7350 mac_group_t *grp = NULL;
7151 7351 int rv;
7152 7352 int i;
7153 7353 int err;
7154 7354 mac_group_t *defgrp;
7155 7355 mac_share_handle_t share = mcip->mci_share;
7156 7356 mac_resource_props_t *mrp = MCIP_RESOURCE_PROPS(mcip);
7157 7357 int nrings;
7158 7358 int defnrings;
7159 7359 boolean_t need_exclgrp = B_FALSE;
7160 7360 int need_rings = 0;
7161 7361 mac_group_t *candidate_grp = NULL;
7162 7362 mac_client_impl_t *gclient;
7163 7363 mac_resource_props_t *gmrp;
7164 7364 boolean_t txhw = mrp->mrp_mask & MRP_TX_RINGS;
7165 7365 boolean_t unspec = mrp->mrp_mask & MRP_TXRINGS_UNSPEC;
7166 7366 boolean_t isprimary;
7167 7367
7168 7368 isprimary = mcip->mci_flent->fe_type & FLOW_PRIMARY_MAC;
7169 7369
7170 7370 /*
7171 7371 * When we come here for a VLAN on the primary (dladm create-vlan),
7172 7372 * we need to pair it along with the primary (to keep it consistent
7173 7373 * with the RX side). So, we check if the primary is already assigned
7174 7374 * to a group and return the group if so. The other way is also
7175 7375 * true, i.e. the VLAN is already created and now we are plumbing
7176 7376 * the primary.
7177 7377 */
7178 7378 if (!move && isprimary) {
7179 7379 for (gclient = mip->mi_clients_list; gclient != NULL;
7180 7380 gclient = gclient->mci_client_next) {
7181 7381 if (gclient->mci_flent->fe_type & FLOW_PRIMARY_MAC &&
7182 7382 gclient->mci_flent->fe_tx_ring_group != NULL) {
7183 7383 return (gclient->mci_flent->fe_tx_ring_group);
7184 7384 }
7185 7385 }
7186 7386 }
7187 7387
7188 7388 if (mip->mi_tx_groups == NULL || mip->mi_tx_group_count == 0)
7189 7389 return (NULL);
7190 7390
7191 7391 /* For dynamic groups, default unspec to 1 */
7192 7392 if (txhw && unspec &&
7193 7393 mip->mi_tx_group_type == MAC_GROUP_TYPE_DYNAMIC) {
7194 7394 mrp->mrp_ntxrings = 1;
7195 7395 }
7196 7396 /*
7197 7397 * For static grouping we allow only specifying rings=0 and
7198 7398 * unspecified
7199 7399 */
7200 7400 if (txhw && mrp->mrp_ntxrings > 0 &&
7201 7401 mip->mi_tx_group_type == MAC_GROUP_TYPE_STATIC) {
7202 7402 return (NULL);
7203 7403 }
7204 7404
7205 7405 if (txhw) {
7206 7406 /*
7207 7407 * We have explicitly asked for a group (with ntxrings,
7208 7408 * if unspec).
7209 7409 */
7210 7410 if (unspec || mrp->mrp_ntxrings > 0) {
7211 7411 need_exclgrp = B_TRUE;
7212 7412 need_rings = mrp->mrp_ntxrings;
7213 7413 } else if (mrp->mrp_ntxrings == 0) {
7214 7414 /*
7215 7415 * We have asked for a software group.
7216 7416 */
7217 7417 return (NULL);
7218 7418 }
7219 7419 }
7220 7420 defgrp = MAC_DEFAULT_TX_GROUP(mip);
7221 7421 /*
7222 7422 * The number of rings that the default group can donate.
7223 7423 * We need to leave at least one ring - the default ring - in
7224 7424 * this group.
7225 7425 */
7226 7426 defnrings = defgrp->mrg_cur_count - 1;
7227 7427
7228 7428 /*
7229 7429 * Primary gets default group unless explicitly told not
7230 7430 * to (i.e. rings > 0).
7231 7431 */
7232 7432 if (isprimary && !need_exclgrp)
7233 7433 return (NULL);
7234 7434
7235 7435 nrings = (mrp->mrp_mask & MRP_TX_RINGS) != 0 ? mrp->mrp_ntxrings : 1;
7236 7436 for (i = 0; i < mip->mi_tx_group_count; i++) {
7237 7437 grp = &mip->mi_tx_groups[i];
7238 7438 if ((grp->mrg_state == MAC_GROUP_STATE_RESERVED) ||
7239 7439 (grp->mrg_state == MAC_GROUP_STATE_UNINIT)) {
7240 7440 /*
7241 7441 * Select a candidate for replacement if we don't
7242 7442 * get an exclusive group. A candidate group is one
7243 7443 * that didn't ask for an exclusive group, but got
7244 7444 * one and it has enough rings (combined with what
7245 7445 * the default group can donate) for the new MAC
7246 7446 * client.
7247 7447 */
7248 7448 if (grp->mrg_state == MAC_GROUP_STATE_RESERVED &&
7249 7449 candidate_grp == NULL) {
7250 7450 gclient = MAC_GROUP_ONLY_CLIENT(grp);
7251 7451 VERIFY3P(gclient, !=, NULL);
7252 7452 gmrp = MCIP_RESOURCE_PROPS(gclient);
7253 7453 if (gclient->mci_share == 0 &&
7254 7454 (gmrp->mrp_mask & MRP_TX_RINGS) == 0 &&
7255 7455 (unspec ||
7256 7456 (grp->mrg_cur_count + defnrings) >=
7257 7457 need_rings)) {
7258 7458 candidate_grp = grp;
7259 7459 }
7260 7460 }
7261 7461 continue;
7262 7462 }
7263 7463 /*
7264 7464 * If the default can't donate let's just walk and
7265 7465 * see if someone can vacate a group, so that we have
7266 7466 * enough rings for this.
7267 7467 */
7268 7468 if (mip->mi_tx_group_type != MAC_GROUP_TYPE_DYNAMIC ||
7269 7469 nrings <= defnrings) {
7270 7470 if (grp->mrg_state == MAC_GROUP_STATE_REGISTERED) {
7271 7471 rv = mac_start_group(grp);
7272 7472 ASSERT(rv == 0);
7273 7473 }
7274 7474 break;
7275 7475 }
7276 7476 }
7277 7477
7278 7478 /* The default group */
7279 7479 if (i >= mip->mi_tx_group_count) {
7280 7480 /*
7281 7481 * If we need an exclusive group and have identified a
7282 7482 * candidate group we switch the MAC client from the
7283 7483 * candidate group to the default group and give the
7284 7484 * candidate group to this client.
7285 7485 */
7286 7486 if (need_exclgrp && candidate_grp != NULL) {
7287 7487 /*
7288 7488 * Switch the MAC client from the candidate
7289 7489 * group to the default group. We know the
7290 7490 * candidate_grp came from a reserved group
7291 7491 * and thus only has one client.
7292 7492 */
7293 7493 grp = candidate_grp;
7294 7494 gclient = MAC_GROUP_ONLY_CLIENT(grp);
7295 7495 VERIFY3P(gclient, !=, NULL);
7296 7496 mac_tx_client_quiesce((mac_client_handle_t)gclient);
7297 7497 mac_tx_switch_group(gclient, grp, defgrp);
7298 7498 mac_tx_client_restart((mac_client_handle_t)gclient);
7299 7499
7300 7500 /*
7301 7501 * Give the candidate group with the specified number
7302 7502 * of rings to this MAC client.
7303 7503 */
7304 7504 ASSERT(grp->mrg_state == MAC_GROUP_STATE_REGISTERED);
7305 7505 rv = mac_start_group(grp);
7306 7506 ASSERT(rv == 0);
7307 7507
7308 7508 if (mip->mi_tx_group_type != MAC_GROUP_TYPE_DYNAMIC)
7309 7509 return (grp);
7310 7510
7311 7511 ASSERT(grp->mrg_cur_count == 0);
7312 7512 ASSERT(defgrp->mrg_cur_count > need_rings);
7313 7513
7314 7514 err = i_mac_group_allocate_rings(mip, MAC_RING_TYPE_TX,
7315 7515 defgrp, grp, share, need_rings);
7316 7516 if (err == 0) {
7317 7517 /*
7318 7518 * For a share i_mac_group_allocate_rings gets
7319 7519 * the rings from the driver, let's populate
7320 7520 * the property for the client now.
7321 7521 */
7322 7522 if (share != 0) {
7323 7523 mac_client_set_rings(
7324 7524 (mac_client_handle_t)mcip, -1,
7325 7525 grp->mrg_cur_count);
7326 7526 }
7327 7527 mip->mi_tx_group_free--;
7328 7528 return (grp);
7329 7529 }
7330 7530 DTRACE_PROBE3(tx__group__reserve__alloc__rings, char *,
7331 7531 mip->mi_name, int, grp->mrg_index, int, err);
7332 7532 mac_stop_group(grp);
7333 7533 }
7334 7534 return (NULL);
7335 7535 }
7336 7536 /*
7337 7537 * We got an exclusive group, but it is not dynamic.
7338 7538 */
7339 7539 if (mip->mi_tx_group_type != MAC_GROUP_TYPE_DYNAMIC) {
7340 7540 mip->mi_tx_group_free--;
7341 7541 return (grp);
7342 7542 }
7343 7543
7344 7544 rv = i_mac_group_allocate_rings(mip, MAC_RING_TYPE_TX, defgrp, grp,
7345 7545 share, nrings);
7346 7546 if (rv != 0) {
7347 7547 DTRACE_PROBE3(tx__group__reserve__alloc__rings,
7348 7548 char *, mip->mi_name, int, grp->mrg_index, int, rv);
7349 7549 mac_stop_group(grp);
7350 7550 return (NULL);
7351 7551 }
7352 7552 /*
7353 7553 * For a share i_mac_group_allocate_rings gets the rings from the
7354 7554 * driver, let's populate the property for the client now.
7355 7555 */
7356 7556 if (share != 0) {
7357 7557 mac_client_set_rings((mac_client_handle_t)mcip, -1,
7358 7558 grp->mrg_cur_count);
7359 7559 }
7360 7560 mip->mi_tx_group_free--;
7361 7561 return (grp);
7362 7562 }
7363 7563
7364 7564 void
7365 7565 mac_release_tx_group(mac_client_impl_t *mcip, mac_group_t *grp)
7366 7566 {
7367 7567 mac_impl_t *mip = mcip->mci_mip;
7368 7568 mac_share_handle_t share = mcip->mci_share;
7369 7569 mac_ring_t *ring;
7370 7570 mac_soft_ring_set_t *srs = MCIP_TX_SRS(mcip);
7371 7571 mac_group_t *defgrp;
7372 7572
7373 7573 defgrp = MAC_DEFAULT_TX_GROUP(mip);
7374 7574 if (srs != NULL) {
7375 7575 if (srs->srs_soft_ring_count > 0) {
7376 7576 for (ring = grp->mrg_rings; ring != NULL;
7377 7577 ring = ring->mr_next) {
7378 7578 ASSERT(mac_tx_srs_ring_present(srs, ring));
7379 7579 mac_tx_invoke_callbacks(mcip,
7380 7580 (mac_tx_cookie_t)
7381 7581 mac_tx_srs_get_soft_ring(srs, ring));
7382 7582 mac_tx_srs_del_ring(srs, ring);
7383 7583 }
7384 7584 } else {
7385 7585 ASSERT(srs->srs_tx.st_arg2 != NULL);
7386 7586 srs->srs_tx.st_arg2 = NULL;
7387 7587 mac_srs_stat_delete(srs);
7388 7588 }
7389 7589 }
7390 7590 if (share != 0)
7391 7591 mip->mi_share_capab.ms_sremove(share, grp->mrg_driver);
7392 7592
7393 7593 /* move the ring back to the pool */
7394 7594 if (mip->mi_tx_group_type == MAC_GROUP_TYPE_DYNAMIC) {
7395 7595 while ((ring = grp->mrg_rings) != NULL)
7396 7596 (void) mac_group_mov_ring(mip, defgrp, ring);
7397 7597 }
7398 7598 mac_stop_group(grp);
7399 7599 mip->mi_tx_group_free++;
7400 7600 }
7401 7601
7402 7602 /*
7403 7603 * Disassociate a MAC client from a group, i.e go through the rings in the
7404 7604 * group and delete all the soft rings tied to them.
7405 7605 */
7406 7606 static void
7407 7607 mac_tx_dismantle_soft_rings(mac_group_t *fgrp, flow_entry_t *flent)
7408 7608 {
7409 7609 mac_client_impl_t *mcip = flent->fe_mcip;
7410 7610 mac_soft_ring_set_t *tx_srs;
7411 7611 mac_srs_tx_t *tx;
7412 7612 mac_ring_t *ring;
7413 7613
7414 7614 tx_srs = flent->fe_tx_srs;
7415 7615 tx = &tx_srs->srs_tx;
7416 7616
7417 7617 /* Single ring case we haven't created any soft rings */
7418 7618 if (tx->st_mode == SRS_TX_BW || tx->st_mode == SRS_TX_SERIALIZE ||
7419 7619 tx->st_mode == SRS_TX_DEFAULT) {
7420 7620 tx->st_arg2 = NULL;
7421 7621 mac_srs_stat_delete(tx_srs);
7422 7622 /* Fanout case, where we have to dismantle the soft rings */
7423 7623 } else {
7424 7624 for (ring = fgrp->mrg_rings; ring != NULL;
7425 7625 ring = ring->mr_next) {
7426 7626 ASSERT(mac_tx_srs_ring_present(tx_srs, ring));
7427 7627 mac_tx_invoke_callbacks(mcip,
7428 7628 (mac_tx_cookie_t)mac_tx_srs_get_soft_ring(tx_srs,
7429 7629 ring));
7430 7630 mac_tx_srs_del_ring(tx_srs, ring);
7431 7631 }
7432 7632 ASSERT(tx->st_arg2 == NULL);
7433 7633 }
7434 7634 }
7435 7635
7436 7636 /*
7437 7637 * Switch the MAC client from one group to another. This means we need
7438 7638 * to remove the MAC client, teardown the SRSs and revert the group state.
7439 7639 * Then, we add the client to the destination roup, set the SRSs etc.
7440 7640 */
7441 7641 void
7442 7642 mac_tx_switch_group(mac_client_impl_t *mcip, mac_group_t *fgrp,
7443 7643 mac_group_t *tgrp)
7444 7644 {
7445 7645 mac_client_impl_t *group_only_mcip;
7446 7646 mac_impl_t *mip = mcip->mci_mip;
7447 7647 flow_entry_t *flent = mcip->mci_flent;
7448 7648 mac_group_t *defgrp;
7449 7649 mac_grp_client_t *mgcp;
7450 7650 mac_client_impl_t *gmcip;
7451 7651 flow_entry_t *gflent;
7452 7652
7453 7653 defgrp = MAC_DEFAULT_TX_GROUP(mip);
7454 7654 ASSERT(fgrp == flent->fe_tx_ring_group);
7455 7655
7456 7656 if (fgrp == defgrp) {
7457 7657 /*
7458 7658 * If this is the primary we need to find any VLANs on
7459 7659 * the primary and move them too.
7460 7660 */
7461 7661 mac_group_remove_client(fgrp, mcip);
7462 7662 mac_tx_dismantle_soft_rings(fgrp, flent);
7463 7663 if (mac_check_macaddr_shared(mcip->mci_unicast)) {
7464 7664 mgcp = fgrp->mrg_clients;
7465 7665 while (mgcp != NULL) {
7466 7666 gmcip = mgcp->mgc_client;
7467 7667 mgcp = mgcp->mgc_next;
7468 7668 if (mcip->mci_unicast != gmcip->mci_unicast)
7469 7669 continue;
7470 7670 mac_tx_client_quiesce(
7471 7671 (mac_client_handle_t)gmcip);
7472 7672
7473 7673 gflent = gmcip->mci_flent;
7474 7674 mac_group_remove_client(fgrp, gmcip);
7475 7675 mac_tx_dismantle_soft_rings(fgrp, gflent);
7476 7676
7477 7677 mac_group_add_client(tgrp, gmcip);
7478 7678 gflent->fe_tx_ring_group = tgrp;
7479 7679 /* We could directly set this to SHARED */
7480 7680 tgrp->mrg_state = mac_group_next_state(tgrp,
7481 7681 &group_only_mcip, defgrp, B_FALSE);
7482 7682
7483 7683 mac_tx_srs_group_setup(gmcip, gflent,
7484 7684 SRST_LINK);
7485 7685 mac_fanout_setup(gmcip, gflent,
7486 7686 MCIP_RESOURCE_PROPS(gmcip), mac_rx_deliver,
7487 7687 gmcip, NULL, NULL);
7488 7688
7489 7689 mac_tx_client_restart(
7490 7690 (mac_client_handle_t)gmcip);
7491 7691 }
7492 7692 }
7493 7693 if (MAC_GROUP_NO_CLIENT(fgrp)) {
7494 7694 mac_ring_t *ring;
7495 7695 int cnt;
7496 7696 int ringcnt;
7497 7697
7498 7698 fgrp->mrg_state = MAC_GROUP_STATE_REGISTERED;
7499 7699 /*
7500 7700 * Additionally, we also need to stop all
7501 7701 * the rings in the default group, except
7502 7702 * the default ring. The reason being
7503 7703 * this group won't be released since it is
7504 7704 * the default group, so the rings won't
7505 7705 * be stopped otherwise.
7506 7706 */
7507 7707 ringcnt = fgrp->mrg_cur_count;
7508 7708 ring = fgrp->mrg_rings;
7509 7709 for (cnt = 0; cnt < ringcnt; cnt++) {
7510 7710 if (ring->mr_state == MR_INUSE &&
7511 7711 ring !=
7512 7712 (mac_ring_t *)mip->mi_default_tx_ring) {
7513 7713 mac_stop_ring(ring);
7514 7714 ring->mr_flag = 0;
7515 7715 }
7516 7716 ring = ring->mr_next;
7517 7717 }
7518 7718 } else if (MAC_GROUP_ONLY_CLIENT(fgrp) != NULL) {
7519 7719 fgrp->mrg_state = MAC_GROUP_STATE_RESERVED;
7520 7720 } else {
7521 7721 ASSERT(fgrp->mrg_state == MAC_GROUP_STATE_SHARED);
7522 7722 }
7523 7723 } else {
7524 7724 /*
7525 7725 * We could have VLANs sharing the non-default group with
7526 7726 * the primary.
7527 7727 */
7528 7728 mgcp = fgrp->mrg_clients;
7529 7729 while (mgcp != NULL) {
7530 7730 gmcip = mgcp->mgc_client;
7531 7731 mgcp = mgcp->mgc_next;
7532 7732 if (gmcip == mcip)
7533 7733 continue;
7534 7734 mac_tx_client_quiesce((mac_client_handle_t)gmcip);
7535 7735 gflent = gmcip->mci_flent;
7536 7736
7537 7737 mac_group_remove_client(fgrp, gmcip);
7538 7738 mac_tx_dismantle_soft_rings(fgrp, gflent);
7539 7739
7540 7740 mac_group_add_client(tgrp, gmcip);
7541 7741 gflent->fe_tx_ring_group = tgrp;
7542 7742 /* We could directly set this to SHARED */
7543 7743 tgrp->mrg_state = mac_group_next_state(tgrp,
7544 7744 &group_only_mcip, defgrp, B_FALSE);
7545 7745 mac_tx_srs_group_setup(gmcip, gflent, SRST_LINK);
7546 7746 mac_fanout_setup(gmcip, gflent,
7547 7747 MCIP_RESOURCE_PROPS(gmcip), mac_rx_deliver,
7548 7748 gmcip, NULL, NULL);
7549 7749
7550 7750 mac_tx_client_restart((mac_client_handle_t)gmcip);
7551 7751 }
7552 7752 mac_group_remove_client(fgrp, mcip);
7553 7753 mac_release_tx_group(mcip, fgrp);
7554 7754 fgrp->mrg_state = MAC_GROUP_STATE_REGISTERED;
7555 7755 }
7556 7756
7557 7757 /* Add it to the tgroup */
7558 7758 mac_group_add_client(tgrp, mcip);
7559 7759 flent->fe_tx_ring_group = tgrp;
7560 7760 tgrp->mrg_state = mac_group_next_state(tgrp, &group_only_mcip,
7561 7761 defgrp, B_FALSE);
7562 7762
7563 7763 mac_tx_srs_group_setup(mcip, flent, SRST_LINK);
7564 7764 mac_fanout_setup(mcip, flent, MCIP_RESOURCE_PROPS(mcip),
7565 7765 mac_rx_deliver, mcip, NULL, NULL);
7566 7766 }
7567 7767
7568 7768 /*
7569 7769 * This is a 1-time control path activity initiated by the client (IP).
7570 7770 * The mac perimeter protects against other simultaneous control activities,
7571 7771 * for example an ioctl that attempts to change the degree of fanout and
7572 7772 * increase or decrease the number of softrings associated with this Tx SRS.
7573 7773 */
7574 7774 static mac_tx_notify_cb_t *
7575 7775 mac_client_tx_notify_add(mac_client_impl_t *mcip,
7576 7776 mac_tx_notify_t notify, void *arg)
7577 7777 {
7578 7778 mac_cb_info_t *mcbi;
7579 7779 mac_tx_notify_cb_t *mtnfp;
7580 7780
7581 7781 ASSERT(MAC_PERIM_HELD((mac_handle_t)mcip->mci_mip));
7582 7782
7583 7783 mtnfp = kmem_zalloc(sizeof (mac_tx_notify_cb_t), KM_SLEEP);
7584 7784 mtnfp->mtnf_fn = notify;
7585 7785 mtnfp->mtnf_arg = arg;
7586 7786 mtnfp->mtnf_link.mcb_objp = mtnfp;
7587 7787 mtnfp->mtnf_link.mcb_objsize = sizeof (mac_tx_notify_cb_t);
7588 7788 mtnfp->mtnf_link.mcb_flags = MCB_TX_NOTIFY_CB_T;
7589 7789
7590 7790 mcbi = &mcip->mci_tx_notify_cb_info;
7591 7791 mutex_enter(mcbi->mcbi_lockp);
7592 7792 mac_callback_add(mcbi, &mcip->mci_tx_notify_cb_list, &mtnfp->mtnf_link);
7593 7793 mutex_exit(mcbi->mcbi_lockp);
7594 7794 return (mtnfp);
7595 7795 }
7596 7796
7597 7797 static void
7598 7798 mac_client_tx_notify_remove(mac_client_impl_t *mcip, mac_tx_notify_cb_t *mtnfp)
7599 7799 {
7600 7800 mac_cb_info_t *mcbi;
7601 7801 mac_cb_t **cblist;
7602 7802
7603 7803 ASSERT(MAC_PERIM_HELD((mac_handle_t)mcip->mci_mip));
7604 7804
7605 7805 if (!mac_callback_find(&mcip->mci_tx_notify_cb_info,
7606 7806 &mcip->mci_tx_notify_cb_list, &mtnfp->mtnf_link)) {
7607 7807 cmn_err(CE_WARN,
7608 7808 "mac_client_tx_notify_remove: callback not "
7609 7809 "found, mcip 0x%p mtnfp 0x%p", (void *)mcip, (void *)mtnfp);
7610 7810 return;
7611 7811 }
7612 7812
7613 7813 mcbi = &mcip->mci_tx_notify_cb_info;
7614 7814 cblist = &mcip->mci_tx_notify_cb_list;
7615 7815 mutex_enter(mcbi->mcbi_lockp);
7616 7816 if (mac_callback_remove(mcbi, cblist, &mtnfp->mtnf_link))
7617 7817 kmem_free(mtnfp, sizeof (mac_tx_notify_cb_t));
7618 7818 else
7619 7819 mac_callback_remove_wait(&mcip->mci_tx_notify_cb_info);
7620 7820 mutex_exit(mcbi->mcbi_lockp);
7621 7821 }
7622 7822
7623 7823 /*
7624 7824 * mac_client_tx_notify():
7625 7825 * call to add and remove flow control callback routine.
7626 7826 */
7627 7827 mac_tx_notify_handle_t
7628 7828 mac_client_tx_notify(mac_client_handle_t mch, mac_tx_notify_t callb_func,
7629 7829 void *ptr)
7630 7830 {
7631 7831 mac_client_impl_t *mcip = (mac_client_impl_t *)mch;
7632 7832 mac_tx_notify_cb_t *mtnfp = NULL;
7633 7833
7634 7834 i_mac_perim_enter(mcip->mci_mip);
7635 7835
7636 7836 if (callb_func != NULL) {
7637 7837 /* Add a notify callback */
7638 7838 mtnfp = mac_client_tx_notify_add(mcip, callb_func, ptr);
7639 7839 } else {
7640 7840 mac_client_tx_notify_remove(mcip, (mac_tx_notify_cb_t *)ptr);
7641 7841 }
7642 7842 i_mac_perim_exit(mcip->mci_mip);
7643 7843
7644 7844 return ((mac_tx_notify_handle_t)mtnfp);
7645 7845 }
7646 7846
7647 7847 void
7648 7848 mac_bridge_vectors(mac_bridge_tx_t txf, mac_bridge_rx_t rxf,
7649 7849 mac_bridge_ref_t reff, mac_bridge_ls_t lsf)
7650 7850 {
7651 7851 mac_bridge_tx_cb = txf;
7652 7852 mac_bridge_rx_cb = rxf;
7653 7853 mac_bridge_ref_cb = reff;
7654 7854 mac_bridge_ls_cb = lsf;
7655 7855 }
7656 7856
7657 7857 int
7658 7858 mac_bridge_set(mac_handle_t mh, mac_handle_t link)
7659 7859 {
7660 7860 mac_impl_t *mip = (mac_impl_t *)mh;
7661 7861 int retv;
7662 7862
7663 7863 mutex_enter(&mip->mi_bridge_lock);
7664 7864 if (mip->mi_bridge_link == NULL) {
7665 7865 mip->mi_bridge_link = link;
7666 7866 retv = 0;
7667 7867 } else {
7668 7868 retv = EBUSY;
7669 7869 }
7670 7870 mutex_exit(&mip->mi_bridge_lock);
7671 7871 if (retv == 0) {
7672 7872 mac_poll_state_change(mh, B_FALSE);
7673 7873 mac_capab_update(mh);
7674 7874 }
7675 7875 return (retv);
7676 7876 }
7677 7877
7678 7878 /*
7679 7879 * Disable bridging on the indicated link.
7680 7880 */
7681 7881 void
7682 7882 mac_bridge_clear(mac_handle_t mh, mac_handle_t link)
7683 7883 {
7684 7884 mac_impl_t *mip = (mac_impl_t *)mh;
7685 7885
7686 7886 mutex_enter(&mip->mi_bridge_lock);
7687 7887 ASSERT(mip->mi_bridge_link == link);
7688 7888 mip->mi_bridge_link = NULL;
7689 7889 mutex_exit(&mip->mi_bridge_lock);
7690 7890 mac_poll_state_change(mh, B_TRUE);
7691 7891 mac_capab_update(mh);
7692 7892 }
7693 7893
7694 7894 void
7695 7895 mac_no_active(mac_handle_t mh)
7696 7896 {
7697 7897 mac_impl_t *mip = (mac_impl_t *)mh;
7698 7898
7699 7899 i_mac_perim_enter(mip);
7700 7900 mip->mi_state_flags |= MIS_NO_ACTIVE;
7701 7901 i_mac_perim_exit(mip);
7702 7902 }
7703 7903
7704 7904 /*
7705 7905 * Walk the primary VLAN clients whenever the primary's rings property
7706 7906 * changes and update the mac_resource_props_t for the VLAN's client.
7707 7907 * We need to do this since we don't support setting these properties
7708 7908 * on the primary's VLAN clients, but the VLAN clients have to
7709 7909 * follow the primary w.r.t the rings property.
7710 7910 */
7711 7911 void
7712 7912 mac_set_prim_vlan_rings(mac_impl_t *mip, mac_resource_props_t *mrp)
7713 7913 {
7714 7914 mac_client_impl_t *vmcip;
7715 7915 mac_resource_props_t *vmrp;
7716 7916
7717 7917 for (vmcip = mip->mi_clients_list; vmcip != NULL;
7718 7918 vmcip = vmcip->mci_client_next) {
7719 7919 if (!(vmcip->mci_flent->fe_type & FLOW_PRIMARY_MAC) ||
7720 7920 mac_client_vid((mac_client_handle_t)vmcip) ==
7721 7921 VLAN_ID_NONE) {
7722 7922 continue;
7723 7923 }
7724 7924 vmrp = MCIP_RESOURCE_PROPS(vmcip);
7725 7925
7726 7926 vmrp->mrp_nrxrings = mrp->mrp_nrxrings;
7727 7927 if (mrp->mrp_mask & MRP_RX_RINGS)
7728 7928 vmrp->mrp_mask |= MRP_RX_RINGS;
7729 7929 else if (vmrp->mrp_mask & MRP_RX_RINGS)
7730 7930 vmrp->mrp_mask &= ~MRP_RX_RINGS;
7731 7931
7732 7932 vmrp->mrp_ntxrings = mrp->mrp_ntxrings;
7733 7933 if (mrp->mrp_mask & MRP_TX_RINGS)
7734 7934 vmrp->mrp_mask |= MRP_TX_RINGS;
7735 7935 else if (vmrp->mrp_mask & MRP_TX_RINGS)
7736 7936 vmrp->mrp_mask &= ~MRP_TX_RINGS;
7737 7937
7738 7938 if (mrp->mrp_mask & MRP_RXRINGS_UNSPEC)
7739 7939 vmrp->mrp_mask |= MRP_RXRINGS_UNSPEC;
7740 7940 else
7741 7941 vmrp->mrp_mask &= ~MRP_RXRINGS_UNSPEC;
7742 7942
7743 7943 if (mrp->mrp_mask & MRP_TXRINGS_UNSPEC)
7744 7944 vmrp->mrp_mask |= MRP_TXRINGS_UNSPEC;
7745 7945 else
7746 7946 vmrp->mrp_mask &= ~MRP_TXRINGS_UNSPEC;
7747 7947 }
7748 7948 }
7749 7949
7750 7950 /*
7751 7951 * We are adding or removing ring(s) from a group. The source for taking
7752 7952 * rings is the default group. The destination for giving rings back is
7753 7953 * the default group.
7754 7954 */
7755 7955 int
7756 7956 mac_group_ring_modify(mac_client_impl_t *mcip, mac_group_t *group,
7757 7957 mac_group_t *defgrp)
7758 7958 {
7759 7959 mac_resource_props_t *mrp = MCIP_RESOURCE_PROPS(mcip);
7760 7960 uint_t modify;
7761 7961 int count;
7762 7962 mac_ring_t *ring;
7763 7963 mac_ring_t *next;
7764 7964 mac_impl_t *mip = mcip->mci_mip;
7765 7965 mac_ring_t **rings;
7766 7966 uint_t ringcnt;
7767 7967 int i = 0;
7768 7968 boolean_t rx_group = group->mrg_type == MAC_RING_TYPE_RX;
7769 7969 int start;
7770 7970 int end;
7771 7971 mac_group_t *tgrp;
7772 7972 int j;
7773 7973 int rv = 0;
7774 7974
7775 7975 /*
7776 7976 * If we are asked for just a group, we give 1 ring, else
7777 7977 * the specified number of rings.
7778 7978 */
7779 7979 if (rx_group) {
7780 7980 ringcnt = (mrp->mrp_mask & MRP_RXRINGS_UNSPEC) ? 1:
7781 7981 mrp->mrp_nrxrings;
7782 7982 } else {
7783 7983 ringcnt = (mrp->mrp_mask & MRP_TXRINGS_UNSPEC) ? 1:
7784 7984 mrp->mrp_ntxrings;
7785 7985 }
7786 7986
7787 7987 /* don't allow modifying rings for a share for now. */
7788 7988 ASSERT(mcip->mci_share == 0);
7789 7989
7790 7990 if (ringcnt == group->mrg_cur_count)
7791 7991 return (0);
7792 7992
7793 7993 if (group->mrg_cur_count > ringcnt) {
7794 7994 modify = group->mrg_cur_count - ringcnt;
7795 7995 if (rx_group) {
7796 7996 if (mip->mi_rx_donor_grp == group) {
7797 7997 ASSERT(mac_is_primary_client(mcip));
7798 7998 mip->mi_rx_donor_grp = defgrp;
7799 7999 } else {
7800 8000 defgrp = mip->mi_rx_donor_grp;
7801 8001 }
7802 8002 }
7803 8003 ring = group->mrg_rings;
7804 8004 rings = kmem_alloc(modify * sizeof (mac_ring_handle_t),
7805 8005 KM_SLEEP);
7806 8006 j = 0;
7807 8007 for (count = 0; count < modify; count++) {
7808 8008 next = ring->mr_next;
7809 8009 rv = mac_group_mov_ring(mip, defgrp, ring);
7810 8010 if (rv != 0) {
7811 8011 /* cleanup on failure */
7812 8012 for (j = 0; j < count; j++) {
7813 8013 (void) mac_group_mov_ring(mip, group,
7814 8014 rings[j]);
7815 8015 }
7816 8016 break;
7817 8017 }
7818 8018 rings[j++] = ring;
7819 8019 ring = next;
7820 8020 }
7821 8021 kmem_free(rings, modify * sizeof (mac_ring_handle_t));
7822 8022 return (rv);
7823 8023 }
7824 8024 if (ringcnt >= MAX_RINGS_PER_GROUP)
7825 8025 return (EINVAL);
7826 8026
7827 8027 modify = ringcnt - group->mrg_cur_count;
7828 8028
7829 8029 if (rx_group) {
7830 8030 if (group != mip->mi_rx_donor_grp)
7831 8031 defgrp = mip->mi_rx_donor_grp;
7832 8032 else
7833 8033 /*
7834 8034 * This is the donor group with all the remaining
7835 8035 * rings. Default group now gets to be the donor
7836 8036 */
7837 8037 mip->mi_rx_donor_grp = defgrp;
7838 8038 start = 1;
7839 8039 end = mip->mi_rx_group_count;
7840 8040 } else {
7841 8041 start = 0;
7842 8042 end = mip->mi_tx_group_count - 1;
7843 8043 }
7844 8044 /*
7845 8045 * If the default doesn't have any rings, lets see if we can
7846 8046 * take rings given to an h/w client that doesn't need it.
7847 8047 * For now, we just see if there is any one client that can donate
7848 8048 * all the required rings.
7849 8049 */
7850 8050 if (defgrp->mrg_cur_count < (modify + 1)) {
7851 8051 for (i = start; i < end; i++) {
7852 8052 if (rx_group) {
7853 8053 tgrp = &mip->mi_rx_groups[i];
7854 8054 if (tgrp == group || tgrp->mrg_state <
7855 8055 MAC_GROUP_STATE_RESERVED) {
7856 8056 continue;
7857 8057 }
7858 8058 if (i_mac_clients_hw(tgrp, MRP_RX_RINGS))
7859 8059 continue;
7860 8060 mcip = tgrp->mrg_clients->mgc_client;
7861 8061 VERIFY3P(mcip, !=, NULL);
7862 8062 if ((tgrp->mrg_cur_count +
7863 8063 defgrp->mrg_cur_count) < (modify + 1)) {
7864 8064 continue;
7865 8065 }
7866 8066 if (mac_rx_switch_group(mcip, tgrp,
7867 8067 defgrp) != 0) {
7868 8068 return (ENOSPC);
7869 8069 }
7870 8070 } else {
7871 8071 tgrp = &mip->mi_tx_groups[i];
7872 8072 if (tgrp == group || tgrp->mrg_state <
7873 8073 MAC_GROUP_STATE_RESERVED) {
7874 8074 continue;
7875 8075 }
7876 8076 if (i_mac_clients_hw(tgrp, MRP_TX_RINGS))
7877 8077 continue;
7878 8078 mcip = tgrp->mrg_clients->mgc_client;
7879 8079 VERIFY3P(mcip, !=, NULL);
7880 8080 if ((tgrp->mrg_cur_count +
7881 8081 defgrp->mrg_cur_count) < (modify + 1)) {
7882 8082 continue;
7883 8083 }
7884 8084 /* OK, we can switch this to s/w */
7885 8085 mac_tx_client_quiesce(
7886 8086 (mac_client_handle_t)mcip);
7887 8087 mac_tx_switch_group(mcip, tgrp, defgrp);
7888 8088 mac_tx_client_restart(
7889 8089 (mac_client_handle_t)mcip);
7890 8090 }
7891 8091 }
7892 8092 if (defgrp->mrg_cur_count < (modify + 1))
7893 8093 return (ENOSPC);
7894 8094 }
7895 8095 if ((rv = i_mac_group_allocate_rings(mip, group->mrg_type, defgrp,
7896 8096 group, mcip->mci_share, modify)) != 0) {
7897 8097 return (rv);
7898 8098 }
7899 8099 return (0);
7900 8100 }
7901 8101
7902 8102 /*
7903 8103 * Given the poolname in mac_resource_props, find the cpupart
7904 8104 * that is associated with this pool. The cpupart will be used
7905 8105 * later for finding the cpus to be bound to the networking threads.
7906 8106 *
7907 8107 * use_default is set B_TRUE if pools are enabled and pool_default
7908 8108 * is returned. This avoids a 2nd lookup to set the poolname
7909 8109 * for pool-effective.
7910 8110 *
7911 8111 * returns:
7912 8112 *
7913 8113 * NULL - pools are disabled or if the 'cpus' property is set.
7914 8114 * cpupart of pool_default - pools are enabled and the pool
7915 8115 * is not available or poolname is blank
7916 8116 * cpupart of named pool - pools are enabled and the pool
7917 8117 * is available.
7918 8118 */
7919 8119 cpupart_t *
7920 8120 mac_pset_find(mac_resource_props_t *mrp, boolean_t *use_default)
7921 8121 {
7922 8122 pool_t *pool;
7923 8123 cpupart_t *cpupart;
7924 8124
7925 8125 *use_default = B_FALSE;
7926 8126
7927 8127 /* CPUs property is set */
7928 8128 if (mrp->mrp_mask & MRP_CPUS)
7929 8129 return (NULL);
7930 8130
7931 8131 ASSERT(pool_lock_held());
7932 8132
7933 8133 /* Pools are disabled, no pset */
7934 8134 if (pool_state == POOL_DISABLED)
7935 8135 return (NULL);
7936 8136
7937 8137 /* Pools property is set */
7938 8138 if (mrp->mrp_mask & MRP_POOL) {
7939 8139 if ((pool = pool_lookup_pool_by_name(mrp->mrp_pool)) == NULL) {
7940 8140 /* Pool not found */
7941 8141 DTRACE_PROBE1(mac_pset_find_no_pool, char *,
7942 8142 mrp->mrp_pool);
7943 8143 *use_default = B_TRUE;
7944 8144 pool = pool_default;
7945 8145 }
7946 8146 /* Pools property is not set */
7947 8147 } else {
7948 8148 *use_default = B_TRUE;
7949 8149 pool = pool_default;
7950 8150 }
7951 8151
7952 8152 /* Find the CPU pset that corresponds to the pool */
7953 8153 mutex_enter(&cpu_lock);
7954 8154 if ((cpupart = cpupart_find(pool->pool_pset->pset_id)) == NULL) {
7955 8155 DTRACE_PROBE1(mac_find_pset_no_pset, psetid_t,
7956 8156 pool->pool_pset->pset_id);
7957 8157 }
7958 8158 mutex_exit(&cpu_lock);
7959 8159
7960 8160 return (cpupart);
7961 8161 }
7962 8162
7963 8163 void
7964 8164 mac_set_pool_effective(boolean_t use_default, cpupart_t *cpupart,
7965 8165 mac_resource_props_t *mrp, mac_resource_props_t *emrp)
7966 8166 {
7967 8167 ASSERT(pool_lock_held());
7968 8168
7969 8169 if (cpupart != NULL) {
7970 8170 emrp->mrp_mask |= MRP_POOL;
7971 8171 if (use_default) {
7972 8172 (void) strcpy(emrp->mrp_pool,
7973 8173 "pool_default");
7974 8174 } else {
7975 8175 ASSERT(strlen(mrp->mrp_pool) != 0);
7976 8176 (void) strcpy(emrp->mrp_pool,
7977 8177 mrp->mrp_pool);
7978 8178 }
7979 8179 } else {
7980 8180 emrp->mrp_mask &= ~MRP_POOL;
7981 8181 bzero(emrp->mrp_pool, MAXPATHLEN);
7982 8182 }
7983 8183 }
7984 8184
7985 8185 struct mac_pool_arg {
7986 8186 char mpa_poolname[MAXPATHLEN];
7987 8187 pool_event_t mpa_what;
7988 8188 };
7989 8189
7990 8190 /*ARGSUSED*/
7991 8191 static uint_t
7992 8192 mac_pool_link_update(mod_hash_key_t key, mod_hash_val_t *val, void *arg)
7993 8193 {
7994 8194 struct mac_pool_arg *mpa = arg;
7995 8195 mac_impl_t *mip = (mac_impl_t *)val;
7996 8196 mac_client_impl_t *mcip;
7997 8197 mac_resource_props_t *mrp, *emrp;
7998 8198 boolean_t pool_update = B_FALSE;
7999 8199 boolean_t pool_clear = B_FALSE;
8000 8200 boolean_t use_default = B_FALSE;
8001 8201 cpupart_t *cpupart = NULL;
8002 8202
8003 8203 mrp = kmem_zalloc(sizeof (*mrp), KM_SLEEP);
8004 8204 i_mac_perim_enter(mip);
8005 8205 for (mcip = mip->mi_clients_list; mcip != NULL;
8006 8206 mcip = mcip->mci_client_next) {
8007 8207 pool_update = B_FALSE;
8008 8208 pool_clear = B_FALSE;
8009 8209 use_default = B_FALSE;
8010 8210 mac_client_get_resources((mac_client_handle_t)mcip, mrp);
8011 8211 emrp = MCIP_EFFECTIVE_PROPS(mcip);
8012 8212
8013 8213 /*
8014 8214 * When pools are enabled
8015 8215 */
8016 8216 if ((mpa->mpa_what == POOL_E_ENABLE) &&
8017 8217 ((mrp->mrp_mask & MRP_CPUS) == 0)) {
8018 8218 mrp->mrp_mask |= MRP_POOL;
8019 8219 pool_update = B_TRUE;
8020 8220 }
8021 8221
8022 8222 /*
8023 8223 * When pools are disabled
8024 8224 */
8025 8225 if ((mpa->mpa_what == POOL_E_DISABLE) &&
8026 8226 ((mrp->mrp_mask & MRP_CPUS) == 0)) {
8027 8227 mrp->mrp_mask |= MRP_POOL;
8028 8228 pool_clear = B_TRUE;
8029 8229 }
8030 8230
8031 8231 /*
8032 8232 * Look for links with the pool property set and the poolname
8033 8233 * matching the one which is changing.
8034 8234 */
8035 8235 if (strcmp(mrp->mrp_pool, mpa->mpa_poolname) == 0) {
8036 8236 /*
8037 8237 * The pool associated with the link has changed.
8038 8238 */
8039 8239 if (mpa->mpa_what == POOL_E_CHANGE) {
8040 8240 mrp->mrp_mask |= MRP_POOL;
8041 8241 pool_update = B_TRUE;
8042 8242 }
8043 8243 }
8044 8244
8045 8245 /*
8046 8246 * This link is associated with pool_default and
8047 8247 * pool_default has changed.
8048 8248 */
8049 8249 if ((mpa->mpa_what == POOL_E_CHANGE) &&
8050 8250 (strcmp(emrp->mrp_pool, "pool_default") == 0) &&
8051 8251 (strcmp(mpa->mpa_poolname, "pool_default") == 0)) {
8052 8252 mrp->mrp_mask |= MRP_POOL;
8053 8253 pool_update = B_TRUE;
8054 8254 }
8055 8255
8056 8256 /*
8057 8257 * Get new list of cpus for the pool, bind network
8058 8258 * threads to new list of cpus and update resources.
8059 8259 */
8060 8260 if (pool_update) {
8061 8261 if (MCIP_DATAPATH_SETUP(mcip)) {
8062 8262 pool_lock();
8063 8263 cpupart = mac_pset_find(mrp, &use_default);
8064 8264 mac_fanout_setup(mcip, mcip->mci_flent, mrp,
8065 8265 mac_rx_deliver, mcip, NULL, cpupart);
8066 8266 mac_set_pool_effective(use_default, cpupart,
8067 8267 mrp, emrp);
8068 8268 pool_unlock();
8069 8269 }
8070 8270 mac_update_resources(mrp, MCIP_RESOURCE_PROPS(mcip),
8071 8271 B_FALSE);
8072 8272 }
8073 8273
8074 8274 /*
8075 8275 * Clear the effective pool and bind network threads
8076 8276 * to any available CPU.
8077 8277 */
8078 8278 if (pool_clear) {
8079 8279 if (MCIP_DATAPATH_SETUP(mcip)) {
8080 8280 emrp->mrp_mask &= ~MRP_POOL;
8081 8281 bzero(emrp->mrp_pool, MAXPATHLEN);
8082 8282 mac_fanout_setup(mcip, mcip->mci_flent, mrp,
8083 8283 mac_rx_deliver, mcip, NULL, NULL);
8084 8284 }
8085 8285 mac_update_resources(mrp, MCIP_RESOURCE_PROPS(mcip),
8086 8286 B_FALSE);
8087 8287 }
8088 8288 }
8089 8289 i_mac_perim_exit(mip);
8090 8290 kmem_free(mrp, sizeof (*mrp));
8091 8291 return (MH_WALK_CONTINUE);
8092 8292 }
8093 8293
8094 8294 static void
8095 8295 mac_pool_update(void *arg)
8096 8296 {
8097 8297 mod_hash_walk(i_mac_impl_hash, mac_pool_link_update, arg);
8098 8298 kmem_free(arg, sizeof (struct mac_pool_arg));
8099 8299 }
8100 8300
8101 8301 /*
8102 8302 * Callback function to be executed when a noteworthy pool event
8103 8303 * takes place.
8104 8304 */
8105 8305 /* ARGSUSED */
8106 8306 static void
8107 8307 mac_pool_event_cb(pool_event_t what, poolid_t id, void *arg)
8108 8308 {
8109 8309 pool_t *pool;
8110 8310 char *poolname = NULL;
8111 8311 struct mac_pool_arg *mpa;
8112 8312
8113 8313 pool_lock();
8114 8314 mpa = kmem_zalloc(sizeof (struct mac_pool_arg), KM_SLEEP);
8115 8315
8116 8316 switch (what) {
8117 8317 case POOL_E_ENABLE:
8118 8318 case POOL_E_DISABLE:
8119 8319 break;
8120 8320
8121 8321 case POOL_E_CHANGE:
8122 8322 pool = pool_lookup_pool_by_id(id);
8123 8323 if (pool == NULL) {
8124 8324 kmem_free(mpa, sizeof (struct mac_pool_arg));
8125 8325 pool_unlock();
8126 8326 return;
8127 8327 }
8128 8328 pool_get_name(pool, &poolname);
8129 8329 (void) strlcpy(mpa->mpa_poolname, poolname,
8130 8330 sizeof (mpa->mpa_poolname));
8131 8331 break;
8132 8332
8133 8333 default:
8134 8334 kmem_free(mpa, sizeof (struct mac_pool_arg));
8135 8335 pool_unlock();
8136 8336 return;
8137 8337 }
8138 8338 pool_unlock();
8139 8339
8140 8340 mpa->mpa_what = what;
8141 8341
8142 8342 mac_pool_update(mpa);
8143 8343 }
8144 8344
8145 8345 /*
8146 8346 * Set effective rings property. This could be called from datapath_setup/
8147 8347 * datapath_teardown or set-linkprop.
8148 8348 * If the group is reserved we just go ahead and set the effective rings.
8149 8349 * Additionally, for TX this could mean the default group has lost/gained
8150 8350 * some rings, so if the default group is reserved, we need to adjust the
8151 8351 * effective rings for the default group clients. For RX, if we are working
8152 8352 * with the non-default group, we just need to reset the effective props
8153 8353 * for the default group clients.
8154 8354 */
8155 8355 void
8156 8356 mac_set_rings_effective(mac_client_impl_t *mcip)
8157 8357 {
8158 8358 mac_impl_t *mip = mcip->mci_mip;
8159 8359 mac_group_t *grp;
8160 8360 mac_group_t *defgrp;
8161 8361 flow_entry_t *flent = mcip->mci_flent;
8162 8362 mac_resource_props_t *emrp = MCIP_EFFECTIVE_PROPS(mcip);
8163 8363 mac_grp_client_t *mgcp;
8164 8364 mac_client_impl_t *gmcip;
8165 8365
8166 8366 grp = flent->fe_rx_ring_group;
8167 8367 if (grp != NULL) {
8168 8368 defgrp = MAC_DEFAULT_RX_GROUP(mip);
8169 8369 /*
8170 8370 * If we have reserved a group, set the effective rings
8171 8371 * to the ring count in the group.
8172 8372 */
8173 8373 if (grp->mrg_state == MAC_GROUP_STATE_RESERVED) {
8174 8374 emrp->mrp_mask |= MRP_RX_RINGS;
8175 8375 emrp->mrp_nrxrings = grp->mrg_cur_count;
8176 8376 }
8177 8377
8178 8378 /*
8179 8379 * We go through the clients in the shared group and
8180 8380 * reset the effective properties. It is possible this
8181 8381 * might have already been done for some client (i.e.
8182 8382 * if some client is being moved to a group that is
8183 8383 * already shared). The case where the default group is
8184 8384 * RESERVED is taken care of above (note in the RX side if
8185 8385 * there is a non-default group, the default group is always
8186 8386 * SHARED).
8187 8387 */
8188 8388 if (grp != defgrp || grp->mrg_state == MAC_GROUP_STATE_SHARED) {
8189 8389 if (grp->mrg_state == MAC_GROUP_STATE_SHARED)
8190 8390 mgcp = grp->mrg_clients;
8191 8391 else
8192 8392 mgcp = defgrp->mrg_clients;
8193 8393 while (mgcp != NULL) {
8194 8394 gmcip = mgcp->mgc_client;
8195 8395 emrp = MCIP_EFFECTIVE_PROPS(gmcip);
8196 8396 if (emrp->mrp_mask & MRP_RX_RINGS) {
8197 8397 emrp->mrp_mask &= ~MRP_RX_RINGS;
8198 8398 emrp->mrp_nrxrings = 0;
8199 8399 }
8200 8400 mgcp = mgcp->mgc_next;
8201 8401 }
8202 8402 }
8203 8403 }
8204 8404
8205 8405 /* Now the TX side */
8206 8406 grp = flent->fe_tx_ring_group;
8207 8407 if (grp != NULL) {
8208 8408 defgrp = MAC_DEFAULT_TX_GROUP(mip);
8209 8409
8210 8410 if (grp->mrg_state == MAC_GROUP_STATE_RESERVED) {
8211 8411 emrp->mrp_mask |= MRP_TX_RINGS;
8212 8412 emrp->mrp_ntxrings = grp->mrg_cur_count;
8213 8413 } else if (grp->mrg_state == MAC_GROUP_STATE_SHARED) {
8214 8414 mgcp = grp->mrg_clients;
8215 8415 while (mgcp != NULL) {
8216 8416 gmcip = mgcp->mgc_client;
8217 8417 emrp = MCIP_EFFECTIVE_PROPS(gmcip);
8218 8418 if (emrp->mrp_mask & MRP_TX_RINGS) {
8219 8419 emrp->mrp_mask &= ~MRP_TX_RINGS;
8220 8420 emrp->mrp_ntxrings = 0;
8221 8421 }
8222 8422 mgcp = mgcp->mgc_next;
8223 8423 }
8224 8424 }
8225 8425
8226 8426 /*
8227 8427 * If the group is not the default group and the default
8228 8428 * group is reserved, the ring count in the default group
8229 8429 * might have changed, update it.
8230 8430 */
8231 8431 if (grp != defgrp &&
8232 8432 defgrp->mrg_state == MAC_GROUP_STATE_RESERVED) {
8233 8433 gmcip = MAC_GROUP_ONLY_CLIENT(defgrp);
8234 8434 emrp = MCIP_EFFECTIVE_PROPS(gmcip);
8235 8435 emrp->mrp_ntxrings = defgrp->mrg_cur_count;
8236 8436 }
8237 8437 }
8238 8438 emrp = MCIP_EFFECTIVE_PROPS(mcip);
8239 8439 }
8240 8440
8241 8441 /*
8242 8442 * Check if the primary is in the default group. If so, see if we
8243 8443 * can give it a an exclusive group now that another client is
8244 8444 * being configured. We take the primary out of the default group
8245 8445 * because the multicast/broadcast packets for the all the clients
8246 8446 * will land in the default ring in the default group which means
8247 8447 * any client in the default group, even if it is the only on in
8248 8448 * the group, will lose exclusive access to the rings, hence
8249 8449 * polling.
8250 8450 */
8251 8451 mac_client_impl_t *
8252 8452 mac_check_primary_relocation(mac_client_impl_t *mcip, boolean_t rxhw)
8253 8453 {
8254 8454 mac_impl_t *mip = mcip->mci_mip;
8255 8455 mac_group_t *defgrp = MAC_DEFAULT_RX_GROUP(mip);
8256 8456 flow_entry_t *flent = mcip->mci_flent;
8257 8457 mac_resource_props_t *mrp = MCIP_RESOURCE_PROPS(mcip);
8258 8458 uint8_t *mac_addr;
8259 8459 mac_group_t *ngrp;
8260 8460
8261 8461 /*
8262 8462 * Check if the primary is in the default group, if not
8263 8463 * or if it is explicitly configured to be in the default
8264 8464 * group OR set the RX rings property, return.
8265 8465 */
8266 8466 if (flent->fe_rx_ring_group != defgrp || mrp->mrp_mask & MRP_RX_RINGS)
8267 8467 return (NULL);
8268 8468
8269 8469 /*
8270 8470 * If the new client needs an exclusive group and we
8271 8471 * don't have another for the primary, return.
8272 8472 */
8273 8473 if (rxhw && mip->mi_rxhwclnt_avail < 2)
8274 8474 return (NULL);
8275 8475
8276 8476 mac_addr = flent->fe_flow_desc.fd_dst_mac;
8277 8477 /*
8278 8478 * We call this when we are setting up the datapath for
8279 8479 * the first non-primary.
8280 8480 */
8281 8481 ASSERT(mip->mi_nactiveclients == 2);
8282 8482
8283 8483 /*
8284 8484 * OK, now we have the primary that needs to be relocated.
8285 8485 */
8286 8486 ngrp = mac_reserve_rx_group(mcip, mac_addr, B_TRUE);
8287 8487 if (ngrp == NULL)
8288 8488 return (NULL);
8289 8489 if (mac_rx_switch_group(mcip, defgrp, ngrp) != 0) {
8290 8490 mac_stop_group(ngrp);
8291 8491 return (NULL);
8292 8492 }
8293 8493 return (mcip);
8294 8494 }
8295 8495
8296 8496 void
8297 8497 mac_transceiver_init(mac_impl_t *mip)
8298 8498 {
8299 8499 if (mac_capab_get((mac_handle_t)mip, MAC_CAPAB_TRANSCEIVER,
8300 8500 &mip->mi_transceiver)) {
8301 8501 /*
8302 8502 * The driver set a flag that we don't know about. In this case,
8303 8503 * we need to warn about that case and ignore this capability.
8304 8504 */
8305 8505 if (mip->mi_transceiver.mct_flags != 0) {
8306 8506 dev_err(mip->mi_dip, CE_WARN, "driver set transceiver "
8307 8507 "flags to invalid value: 0x%x, ignoring "
8308 8508 "capability", mip->mi_transceiver.mct_flags);
8309 8509 bzero(&mip->mi_transceiver,
8310 8510 sizeof (mac_capab_transceiver_t));
8311 8511 }
8312 8512 } else {
8313 8513 bzero(&mip->mi_transceiver,
8314 8514 sizeof (mac_capab_transceiver_t));
8315 8515 }
8316 8516 }
8317 8517
8318 8518 int
8319 8519 mac_transceiver_count(mac_handle_t mh, uint_t *countp)
8320 8520 {
8321 8521 mac_impl_t *mip = (mac_impl_t *)mh;
8322 8522
8323 8523 ASSERT(MAC_PERIM_HELD(mh));
8324 8524
8325 8525 if (mip->mi_transceiver.mct_ntransceivers == 0)
8326 8526 return (ENOTSUP);
8327 8527
8328 8528 *countp = mip->mi_transceiver.mct_ntransceivers;
8329 8529 return (0);
8330 8530 }
8331 8531
8332 8532 int
8333 8533 mac_transceiver_info(mac_handle_t mh, uint_t tranid, boolean_t *present,
8334 8534 boolean_t *usable)
8335 8535 {
8336 8536 int ret;
8337 8537 mac_transceiver_info_t info;
8338 8538
8339 8539 mac_impl_t *mip = (mac_impl_t *)mh;
8340 8540
8341 8541 ASSERT(MAC_PERIM_HELD(mh));
8342 8542
8343 8543 if (mip->mi_transceiver.mct_info == NULL ||
8344 8544 mip->mi_transceiver.mct_ntransceivers == 0)
8345 8545 return (ENOTSUP);
8346 8546
8347 8547 if (tranid >= mip->mi_transceiver.mct_ntransceivers)
8348 8548 return (EINVAL);
8349 8549
8350 8550 bzero(&info, sizeof (mac_transceiver_info_t));
8351 8551 if ((ret = mip->mi_transceiver.mct_info(mip->mi_driver, tranid,
8352 8552 &info)) != 0) {
8353 8553 return (ret);
8354 8554 }
8355 8555
8356 8556 *present = info.mti_present;
8357 8557 *usable = info.mti_usable;
8358 8558 return (0);
8359 8559 }
8360 8560
8361 8561 int
8362 8562 mac_transceiver_read(mac_handle_t mh, uint_t tranid, uint_t page, void *buf,
8363 8563 size_t nbytes, off_t offset, size_t *nread)
8364 8564 {
8365 8565 int ret;
8366 8566 size_t nr;
8367 8567 mac_impl_t *mip = (mac_impl_t *)mh;
8368 8568
8369 8569 ASSERT(MAC_PERIM_HELD(mh));
8370 8570
8371 8571 if (mip->mi_transceiver.mct_read == NULL)
8372 8572 return (ENOTSUP);
8373 8573
8374 8574 if (tranid >= mip->mi_transceiver.mct_ntransceivers)
8375 8575 return (EINVAL);
8376 8576
8377 8577 /*
8378 8578 * All supported pages today are 256 bytes wide. Make sure offset +
8379 8579 * nbytes never exceeds that.
8380 8580 */
8381 8581 if (offset < 0 || offset >= 256 || nbytes > 256 ||
8382 8582 offset + nbytes > 256)
8383 8583 return (EINVAL);
8384 8584
8385 8585 if (nread == NULL)
8386 8586 nread = &nr;
8387 8587 ret = mip->mi_transceiver.mct_read(mip->mi_driver, tranid, page, buf,
8388 8588 nbytes, offset, nread);
8389 8589 if (ret == 0 && *nread > nbytes) {
8390 8590 dev_err(mip->mi_dip, CE_PANIC, "driver wrote %lu bytes into "
8391 8591 "%lu byte sized buffer, possible memory corruption",
8392 8592 *nread, nbytes);
8393 8593 }
8394 8594
8395 8595 return (ret);
8396 8596 }
8397 8597
8398 8598 void
8399 8599 mac_led_init(mac_impl_t *mip)
8400 8600 {
8401 8601 mip->mi_led_modes = MAC_LED_DEFAULT;
8402 8602
8403 8603 if (!mac_capab_get((mac_handle_t)mip, MAC_CAPAB_LED, &mip->mi_led)) {
8404 8604 bzero(&mip->mi_led, sizeof (mac_capab_led_t));
8405 8605 return;
8406 8606 }
8407 8607
8408 8608 if (mip->mi_led.mcl_flags != 0) {
8409 8609 dev_err(mip->mi_dip, CE_WARN, "driver set led capability "
8410 8610 "flags to invalid value: 0x%x, ignoring "
8411 8611 "capability", mip->mi_transceiver.mct_flags);
8412 8612 bzero(&mip->mi_led, sizeof (mac_capab_led_t));
8413 8613 return;
8414 8614 }
8415 8615
8416 8616 if ((mip->mi_led.mcl_modes & ~MAC_LED_ALL) != 0) {
8417 8617 dev_err(mip->mi_dip, CE_WARN, "driver set led capability "
8418 8618 "supported modes to invalid value: 0x%x, ignoring "
8419 8619 "capability", mip->mi_transceiver.mct_flags);
8420 8620 bzero(&mip->mi_led, sizeof (mac_capab_led_t));
8421 8621 return;
8422 8622 }
8423 8623 }
8424 8624
8425 8625 int
8426 8626 mac_led_get(mac_handle_t mh, mac_led_mode_t *supported, mac_led_mode_t *active)
8427 8627 {
8428 8628 mac_impl_t *mip = (mac_impl_t *)mh;
8429 8629
8430 8630 ASSERT(MAC_PERIM_HELD(mh));
8431 8631
8432 8632 if (mip->mi_led.mcl_set == NULL)
8433 8633 return (ENOTSUP);
8434 8634
8435 8635 *supported = mip->mi_led.mcl_modes;
8436 8636 *active = mip->mi_led_modes;
8437 8637
8438 8638 return (0);
8439 8639 }
8440 8640
8441 8641 /*
8442 8642 * Update and multiplex the various LED requests. We only ever send one LED to
8443 8643 * the underlying driver at a time. As such, we end up multiplexing all
8444 8644 * requested states and picking one to send down to the driver.
8445 8645 */
8446 8646 int
8447 8647 mac_led_set(mac_handle_t mh, mac_led_mode_t desired)
8448 8648 {
8449 8649 int ret;
8450 8650 mac_led_mode_t driver;
8451 8651
8452 8652 mac_impl_t *mip = (mac_impl_t *)mh;
8453 8653
8454 8654 ASSERT(MAC_PERIM_HELD(mh));
8455 8655
8456 8656 /*
8457 8657 * If we've been passed a desired value of zero, that indicates that
8458 8658 * we're basically resetting to the value of zero, which is our default
8459 8659 * value.
8460 8660 */
8461 8661 if (desired == 0)
8462 8662 desired = MAC_LED_DEFAULT;
8463 8663
8464 8664 if (mip->mi_led.mcl_set == NULL)
8465 8665 return (ENOTSUP);
8466 8666
8467 8667 /*
8468 8668 * Catch both values that we don't know about and those that the driver
8469 8669 * doesn't support.
8470 8670 */
8471 8671 if ((desired & ~MAC_LED_ALL) != 0)
8472 8672 return (EINVAL);
8473 8673
8474 8674 if ((desired & ~mip->mi_led.mcl_modes) != 0)
8475 8675 return (ENOTSUP);
8476 8676
8477 8677 /*
8478 8678 * If we have the same value, then there is nothing to do.
8479 8679 */
8480 8680 if (desired == mip->mi_led_modes)
8481 8681 return (0);
8482 8682
8483 8683 /*
8484 8684 * Based on the desired value, determine what to send to the driver. We
8485 8685 * only will send a single bit to the driver at any given time. IDENT
8486 8686 * takes priority over OFF or ON. We also let OFF take priority over the
8487 8687 * rest.
8488 8688 */
8489 8689 if (desired & MAC_LED_IDENT) {
8490 8690 driver = MAC_LED_IDENT;
8491 8691 } else if (desired & MAC_LED_OFF) {
8492 8692 driver = MAC_LED_OFF;
8493 8693 } else if (desired & MAC_LED_ON) {
8494 8694 driver = MAC_LED_ON;
8495 8695 } else {
8496 8696 driver = MAC_LED_DEFAULT;
8497 8697 }
8498 8698
8499 8699 if ((ret = mip->mi_led.mcl_set(mip->mi_driver, driver, 0)) == 0) {
8500 8700 mip->mi_led_modes = desired;
8501 8701 }
8502 8702
8503 8703 return (ret);
8504 8704 }
↓ open down ↓ |
4678 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX