1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2010 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#ifndef _SYS_MAC_IMPL_H
#define _SYS_MAC_IMPL_H
#include <sys/cpupart.h>
#include <sys/modhash.h>
#include <sys/mac_client.h>
#include <sys/mac_provider.h>
#include <sys/note.h>
#include <sys/avl.h>
#include <net/if.h>
#include <sys/mac_flow_impl.h>
#include <netinet/ip6.h>
#ifdef __cplusplus
extern "C" {
#endif
/*
* This is the first minor number available for MAC provider private
* use. This makes it possible to deliver a driver that is both a MAC
* provider and a regular character/block device. See PSARC 2009/380
* for more detail about the construction of such devices. The value
* chosen leaves half of the 32-bit minor numbers (which are really
* only 18 bits wide) available for driver private use. Drivers can
* easily identify their private number by the presence of this value
* in the bits that make up the minor number, since its just the
* highest bit available for such minor numbers.
*/
#define MAC_PRIVATE_MINOR ((MAXMIN32 + 1) / 2)
/*
* The maximum minor number that corresponds to a real instance. This
* limits the number of physical ports that a mac provider can offer.
* Note that this macro must be synchronized with DLS_MAX_MINOR in
* <sys/dls.h>
*/
#define MAC_MAX_MINOR 1000
typedef struct mac_margin_req_s mac_margin_req_t;
struct mac_margin_req_s {
mac_margin_req_t *mmr_nextp;
uint_t mmr_ref;
uint32_t mmr_margin;
};
/* Generic linked chain type */
typedef struct mac_chain_s {
struct mac_chain_s *next;
void *item;
} mac_chain_t;
/*
* Generic mac callback list manipulation structures and macros. The mac_cb_t
* represents a general callback list element embedded in a particular
* data structure such as a mac_notify_cb_t or a mac_promisc_impl_t.
* The mac_cb_info_t represents general information about list walkers.
* Please see the comments above mac_callback_add for more information.
*/
/* mcb_flags */
#define MCB_CONDEMNED 0x1 /* Logically deleted */
#define MCB_NOTIFY_CB_T 0x2
#define MCB_TX_NOTIFY_CB_T 0x4
extern boolean_t mac_tx_serialize;
typedef struct mac_cb_s {
struct mac_cb_s *mcb_nextp; /* Linked list of callbacks */
void *mcb_objp; /* Ptr to enclosing object */
size_t mcb_objsize; /* Sizeof the enclosing obj */
uint_t mcb_flags;
} mac_cb_t;
typedef struct mac_cb_info_s {
kmutex_t *mcbi_lockp;
kcondvar_t mcbi_cv;
uint_t mcbi_del_cnt; /* Deleted callback cnt */
uint_t mcbi_walker_cnt; /* List walker count */
} mac_cb_info_t;
typedef struct mac_notify_cb_s {
mac_cb_t mncb_link; /* Linked list of callbacks */
mac_notify_t mncb_fn; /* callback function */
void *mncb_arg; /* callback argument */
struct mac_impl_s *mncb_mip;
} mac_notify_cb_t;
/*
* mac_callback_add(listinfo, listhead, listelement)
* mac_callback_remove(listinfo, listhead, listelement)
*/
typedef boolean_t (*mcb_func_t)(mac_cb_info_t *, mac_cb_t **, mac_cb_t *);
#define MAC_CALLBACK_WALKER_INC(mcbi) { \
mutex_enter((mcbi)->mcbi_lockp); \
(mcbi)->mcbi_walker_cnt++; \
mutex_exit((mcbi)->mcbi_lockp); \
}
#define MAC_CALLBACK_WALKER_INC_HELD(mcbi) (mcbi)->mcbi_walker_cnt++;
#define MAC_CALLBACK_WALKER_DCR(mcbi, headp) { \
mac_cb_t *rmlist; \
\
mutex_enter((mcbi)->mcbi_lockp); \
if (--(mcbi)->mcbi_walker_cnt == 0 && (mcbi)->mcbi_del_cnt != 0) { \
rmlist = mac_callback_walker_cleanup((mcbi), headp); \
mac_callback_free(rmlist); \
cv_broadcast(&(mcbi)->mcbi_cv); \
} \
mutex_exit((mcbi)->mcbi_lockp); \
}
#define MAC_PROMISC_WALKER_INC(mip) \
MAC_CALLBACK_WALKER_INC(&(mip)->mi_promisc_cb_info)
#define MAC_PROMISC_WALKER_DCR(mip) { \
mac_cb_info_t *mcbi; \
\
mcbi = &(mip)->mi_promisc_cb_info; \
mutex_enter(mcbi->mcbi_lockp); \
if (--mcbi->mcbi_walker_cnt == 0 && mcbi->mcbi_del_cnt != 0) { \
i_mac_promisc_walker_cleanup(mip); \
cv_broadcast(&mcbi->mcbi_cv); \
} \
mutex_exit(mcbi->mcbi_lockp); \
}
typedef struct mactype_s {
const char *mt_ident;
uint32_t mt_ref;
uint_t mt_type;
uint_t mt_nativetype;
size_t mt_addr_length;
uint8_t *mt_brdcst_addr;
mactype_ops_t mt_ops;
mac_stat_info_t *mt_stats; /* array of mac_stat_info_t elements */
size_t mt_statcount; /* number of elements in mt_stats */
mac_ndd_mapping_t *mt_mapping;
size_t mt_mappingcount;
} mactype_t;
/*
* Multiple rings implementation.
*/
typedef enum {
MAC_GROUP_STATE_UNINIT = 0, /* initial state of data structure */
MAC_GROUP_STATE_REGISTERED, /* hooked with h/w group */
MAC_GROUP_STATE_RESERVED, /* group is reserved and opened */
MAC_GROUP_STATE_SHARED /* default group shared among */
/* multiple mac clients */
} mac_group_state_t;
typedef struct mac_ring_s mac_ring_t;
typedef struct mac_group_s mac_group_t;
/*
* Ring data structure for ring control and management.
*/
typedef enum {
MR_FREE, /* Available for assignment to flows */
MR_NEWLY_ADDED, /* Just assigned to another group */
MR_INUSE /* Assigned to an SRS */
} mac_ring_state_t;
/* mr_flag values */
#define MR_INCIPIENT 0x1
#define MR_CONDEMNED 0x2
#define MR_QUIESCE 0x4
typedef struct mac_impl_s mac_impl_t;
struct mac_ring_s {
int mr_index; /* index in the original list */
mac_ring_type_t mr_type; /* ring type */
mac_ring_t *mr_next; /* next ring in the chain */
mac_group_handle_t mr_gh; /* reference to group */
mac_classify_type_t mr_classify_type; /* HW vs SW */
struct mac_soft_ring_set_s *mr_srs; /* associated SRS */
mac_ring_handle_t mr_prh; /* associated pseudo ring hdl */
uint_t mr_refcnt; /* Ring references */
/* ring generation no. to guard against drivers using stale rings */
uint64_t mr_gen_num;
kstat_t *mr_ksp; /* ring kstats */
mac_impl_t *mr_mip; /* pointer to primary's mip */
kmutex_t mr_lock;
kcondvar_t mr_cv; /* mr_lock */
mac_ring_state_t mr_state; /* mr_lock */
uint_t mr_flag; /* mr_lock */
mac_ring_info_t mr_info; /* driver supplied info */
};
#define mr_driver mr_info.mri_driver
#define mr_start mr_info.mri_start
#define mr_stop mr_info.mri_stop
#define mr_stat mr_info.mri_stat
#define MAC_RING_MARK(mr, flag) \
(mr)->mr_flag |= flag;
#define MAC_RING_UNMARK(mr, flag) \
(mr)->mr_flag &= ~flag;
/*
* Reference hold and release on mac_ring_t 'mr'
*/
#define MR_REFHOLD_LOCKED(mr) { \
ASSERT(MUTEX_HELD(&mr->mr_lock)); \
(mr)->mr_refcnt++; \
}
#define MR_REFRELE(mr) { \
mutex_enter(&(mr)->mr_lock); \
ASSERT((mr)->mr_refcnt != 0); \
(mr)->mr_refcnt--; \
if ((mr)->mr_refcnt == 0 && \
((mr)->mr_flag & (MR_CONDEMNED | MR_QUIESCE))) \
cv_signal(&(mr)->mr_cv); \
mutex_exit(&(mr)->mr_lock); \
}
/*
* Per mac client flow information associated with a RX group.
* The entire structure is SL protected.
*/
typedef struct mac_grp_client {
struct mac_grp_client *mgc_next;
struct mac_client_impl_s *mgc_client;
} mac_grp_client_t;
#define MAC_GROUP_NO_CLIENT(g) ((g)->mrg_clients == NULL)
#define MAC_GROUP_ONLY_CLIENT(g) \
((((g)->mrg_clients != NULL) && \
((g)->mrg_clients->mgc_next == NULL)) ? \
(g)->mrg_clients->mgc_client : NULL)
/*
* Common ring group data structure for ring control and management.
* The entire structure is SL protected
*/
struct mac_group_s {
int mrg_index; /* index in the list */
mac_ring_type_t mrg_type; /* ring type */
mac_group_state_t mrg_state; /* state of the group */
mac_group_t *mrg_next; /* next ring in the chain */
mac_handle_t mrg_mh; /* reference to MAC */
mac_ring_t *mrg_rings; /* grouped rings */
uint_t mrg_cur_count; /* actual size of group */
mac_grp_client_t *mrg_clients; /* clients list */
mac_group_info_t mrg_info; /* driver supplied info */
};
#define mrg_driver mrg_info.mgi_driver
#define mrg_start mrg_info.mgi_start
#define mrg_stop mrg_info.mgi_stop
#define GROUP_INTR_HANDLE(g) (g)->mrg_info.mgi_intr.mi_handle
#define GROUP_INTR_ENABLE_FUNC(g) (g)->mrg_info.mgi_intr.mi_enable
#define GROUP_INTR_DISABLE_FUNC(g) (g)->mrg_info.mgi_intr.mi_disable
#define MAC_RING_TX(mhp, rh, mp, rest) { \
mac_ring_handle_t mrh = rh; \
mac_impl_t *mimpl = (mac_impl_t *)mhp; \
/* \
* Send packets through a selected tx ring, or through the \
* default handler if there is no selected ring. \
*/ \
if (mrh == NULL) \
mrh = mimpl->mi_default_tx_ring; \
if (mrh == NULL) { \
rest = mimpl->mi_tx(mimpl->mi_driver, mp); \
} else { \
rest = mac_hwring_tx(mrh, mp); \
} \
}
/*
* This is the final stop before reaching the underlying driver
* or aggregation, so this is where the bridging hook is implemented.
* Packets that are bridged will return through mac_bridge_tx(), with
* rh nulled out if the bridge chooses to send output on a different
* link due to forwarding.
*/
#define MAC_TX(mip, rh, mp, src_mcip) { \
mac_ring_handle_t rhandle = (rh); \
/* \
* If there is a bound Hybrid I/O share, send packets through \
* the default tx ring. (When there's a bound Hybrid I/O share, \
* the tx rings of this client are mapped in the guest domain \
* and not accessible from here.) \
*/ \
_NOTE(CONSTANTCONDITION) \
if ((src_mcip)->mci_state_flags & MCIS_SHARE_BOUND) \
rhandle = (mip)->mi_default_tx_ring; \
if (mip->mi_promisc_list != NULL) \
mac_promisc_dispatch(mip, mp, src_mcip); \
/* \
* Grab the proper transmit pointer and handle. Special \
* optimization: we can test mi_bridge_link itself atomically, \
* and if that indicates no bridge send packets through tx ring.\
*/ \
if (mip->mi_bridge_link == NULL) { \
MAC_RING_TX(mip, rhandle, mp, mp); \
} else { \
mp = mac_bridge_tx(mip, rhandle, mp); \
} \
}
/* mci_tx_flag */
#define MCI_TX_QUIESCE 0x1
typedef struct mac_factory_addr_s {
boolean_t mfa_in_use;
uint8_t mfa_addr[MAXMACADDRLEN];
struct mac_client_impl_s *mfa_client;
} mac_factory_addr_t;
typedef struct mac_mcast_addrs_s {
struct mac_mcast_addrs_s *mma_next;
uint8_t mma_addr[MAXMACADDRLEN];
int mma_ref;
} mac_mcast_addrs_t;
typedef enum {
MAC_ADDRESS_TYPE_UNICAST_CLASSIFIED = 1, /* hardware steering */
MAC_ADDRESS_TYPE_UNICAST_PROMISC /* promiscuous mode */
} mac_address_type_t;
typedef struct mac_address_s {
mac_address_type_t ma_type; /* address type */
int ma_nusers; /* number of users */
/* of that address */
struct mac_address_s *ma_next; /* next address */
uint8_t ma_addr[MAXMACADDRLEN]; /* address value */
size_t ma_len; /* address length */
mac_group_t *ma_group; /* asscociated group */
mac_impl_t *ma_mip; /* MAC handle */
} mac_address_t;
extern krwlock_t i_mac_impl_lock;
extern mod_hash_t *i_mac_impl_hash;
extern kmem_cache_t *i_mac_impl_cachep;
extern uint_t i_mac_impl_count;
/*
* Each registered MAC is associated with a mac_impl_t structure. The
* structure represents the undelying hardware, in terms of definition,
* resources (transmit, receive rings etc.), callback functions etc. It
* also holds the table of MAC clients that are configured on the device.
* The table is used for classifying incoming packets in software.
*
* The protection scheme uses 2 elements, a coarse serialization mechanism
* called perimeter and a finer traditional lock based scheme. More details
* can be found in the big block comment in mac.c.
*
* The protection scheme for each member of the mac_impl_t is described below.
*
* Write Once Only (WO): Typically these don't change for the lifetime of the
* data structure. For example something in mac_impl_t that stays the same
* from mac_register to mac_unregister, or something in a mac_client_impl_t
* that stays the same from mac_client_open to mac_client_close.
*
* Serializer (SL): Protected by the Serializer. All SLOP operations on a
* mac endpoint go through the serializer. MTOPs don't care about reading
* these fields atomically.
*
* Lock: Traditional mutex/rw lock. Modify operations still go through the
* mac serializer, the lock helps synchronize readers with writers.
*/
struct mac_impl_s {
krwlock_t mi_rw_lock;
char mi_name[LIFNAMSIZ]; /* WO */
uint32_t mi_state_flags;
void *mi_driver; /* Driver private, WO */
mac_info_t mi_info; /* WO */
mactype_t *mi_type; /* WO */
void *mi_pdata; /* WO */
size_t mi_pdata_size; /* WO */
mac_callbacks_t *mi_callbacks; /* WO */
dev_info_t *mi_dip; /* WO */
uint32_t mi_ref; /* i_mac_impl_lock */
uint_t mi_active; /* SL */
link_state_t mi_linkstate; /* none */
link_state_t mi_lowlinkstate; /* none */
link_state_t mi_lastlowlinkstate; /* none */
uint_t mi_devpromisc; /* SL */
uint8_t mi_addr[MAXMACADDRLEN]; /* mi_rw_lock */
uint8_t mi_dstaddr[MAXMACADDRLEN]; /* mi_rw_lock */
boolean_t mi_dstaddr_set;
/*
* The mac perimeter. All client initiated create/modify operations
* on a mac end point go through this.
*/
kmutex_t mi_perim_lock;
kthread_t *mi_perim_owner; /* mi_perim_lock */
uint_t mi_perim_ocnt; /* mi_perim_lock */
kcondvar_t mi_perim_cv; /* mi_perim_lock */
/* mac notification callbacks */
kmutex_t mi_notify_lock;
mac_cb_info_t mi_notify_cb_info; /* mi_notify_lock */
mac_cb_t *mi_notify_cb_list; /* mi_notify_lock */
kthread_t *mi_notify_thread; /* mi_notify_lock */
uint_t mi_notify_bits; /* mi_notify_lock */
uint32_t mi_v12n_level; /* Virt'ion readiness */
/*
* RX groups, ring capability
* Fields of this block are SL protected.
*/
mac_group_type_t mi_rx_group_type; /* grouping type */
uint_t mi_rx_group_count;
mac_group_t *mi_rx_groups;
mac_group_t *mi_rx_donor_grp;
uint_t mi_rxrings_rsvd;
uint_t mi_rxrings_avail;
uint_t mi_rxhwclnt_avail;
uint_t mi_rxhwclnt_used;
mac_capab_rings_t mi_rx_rings_cap;
/*
* TX groups and ring capability, SL Protected.
*/
mac_group_type_t mi_tx_group_type; /* grouping type */
uint_t mi_tx_group_count;
uint_t mi_tx_group_free;
mac_group_t *mi_tx_groups;
mac_capab_rings_t mi_tx_rings_cap;
uint_t mi_txrings_rsvd;
uint_t mi_txrings_avail;
uint_t mi_txhwclnt_avail;
uint_t mi_txhwclnt_used;
mac_ring_handle_t mi_default_tx_ring;
/*
* MAC address list. SL protected.
*/
mac_address_t *mi_addresses;
/*
* This MAC's table of sub-flows
*/
flow_tab_t *mi_flow_tab; /* WO */
kstat_t *mi_ksp; /* WO */
uint_t mi_kstat_count; /* WO */
uint_t mi_nactiveclients; /* SL */
/* for broadcast and multicast support */
struct mac_mcast_addrs_s *mi_mcast_addrs; /* mi_rw_lock */
struct mac_bcast_grp_s *mi_bcast_grp; /* mi_rw_lock */
uint_t mi_bcast_ngrps; /* mi_rw_lock */
/* list of MAC clients which opened this MAC */
struct mac_client_impl_s *mi_clients_list; /* mi_rw_lock */
uint_t mi_nclients; /* mi_rw_lock */
struct mac_client_impl_s *mi_single_active_client; /* mi_rw_lock */
uint32_t mi_margin; /* mi_rw_lock */
uint_t mi_sdu_min; /* mi_rw_lock */
uint_t mi_sdu_max; /* mi_rw_lock */
/*
* Cache of factory MAC addresses provided by the driver. If
* the driver doesn't provide multiple factory MAC addresses,
* the mi_factory_addr is set to NULL, and mi_factory_addr_num
* is set to zero.
*/
mac_factory_addr_t *mi_factory_addr; /* mi_rw_lock */
uint_t mi_factory_addr_num; /* mi_rw_lock */
/* for promiscuous mode support */
kmutex_t mi_promisc_lock;
mac_cb_t *mi_promisc_list; /* mi_promisc_lock */
mac_cb_info_t mi_promisc_cb_info; /* mi_promisc_lock */
/* cache of rings over this mac_impl */
kmutex_t mi_ring_lock;
mac_ring_t *mi_ring_freelist; /* mi_ring_lock */
/*
* These are used for caching the properties, if any, for the
* primary MAC client. If the MAC client is not yet in place
* when the properties are set then we cache them here to be
* applied to the MAC client when it is created.
*/
mac_resource_props_t mi_resource_props; /* SL */
uint16_t mi_pvid; /* SL */
minor_t mi_minor; /* WO */
uint32_t mi_oref; /* SL */
mac_capab_legacy_t mi_capab_legacy; /* WO */
dev_t mi_phy_dev; /* WO */
/*
* List of margin value requests added by mac clients. This list is
* sorted: the first one has the greatest value.
*/
mac_margin_req_t *mi_mmrp;
char **mi_priv_prop;
uint_t mi_priv_prop_count;
/*
* Hybrid I/O related definitions.
*/
mac_capab_share_t mi_share_capab;
/*
* Bridging hooks and limit values. Uses mutex and reference counts
* (bridging only) for data path. Limits need no synchronization.
*/
mac_handle_t mi_bridge_link;
kmutex_t mi_bridge_lock;
uint32_t mi_llimit;
uint32_t mi_ldecay;
/* This should be the last block in this structure */
#ifdef DEBUG
#define MAC_PERIM_STACK_DEPTH 15
int mi_perim_stack_depth;
pc_t mi_perim_stack[MAC_PERIM_STACK_DEPTH];
#endif
};
/*
* The default TX group is the last one in the list.
*/
#define MAC_DEFAULT_TX_GROUP(mip) \
(mip)->mi_tx_groups + (mip)->mi_tx_group_count
/*
* The default RX group is the first one in the list
*/
#define MAC_DEFAULT_RX_GROUP(mip) (mip)->mi_rx_groups
/* Reserved RX rings */
#define MAC_RX_RING_RESERVED(m, cnt) { \
ASSERT((m)->mi_rxrings_avail >= (cnt)); \
(m)->mi_rxrings_rsvd += (cnt); \
(m)->mi_rxrings_avail -= (cnt); \
}
/* Released RX rings */
#define MAC_RX_RING_RELEASED(m, cnt) { \
ASSERT((m)->mi_rxrings_rsvd >= (cnt)); \
(m)->mi_rxrings_rsvd -= (cnt); \
(m)->mi_rxrings_avail += (cnt); \
}
/* Reserved a RX group */
#define MAC_RX_GRP_RESERVED(m) { \
ASSERT((m)->mi_rxhwclnt_avail > 0); \
(m)->mi_rxhwclnt_avail--; \
(m)->mi_rxhwclnt_used++; \
}
/* Released a RX group */
#define MAC_RX_GRP_RELEASED(m) { \
ASSERT((m)->mi_rxhwclnt_used > 0); \
(m)->mi_rxhwclnt_avail++; \
(m)->mi_rxhwclnt_used--; \
}
/* Reserved TX rings */
#define MAC_TX_RING_RESERVED(m, cnt) { \
ASSERT((m)->mi_txrings_avail >= (cnt)); \
(m)->mi_txrings_rsvd += (cnt); \
(m)->mi_txrings_avail -= (cnt); \
}
/* Released TX rings */
#define MAC_TX_RING_RELEASED(m, cnt) { \
ASSERT((m)->mi_txrings_rsvd >= (cnt)); \
(m)->mi_txrings_rsvd -= (cnt); \
(m)->mi_txrings_avail += (cnt); \
}
/* Reserved a TX group */
#define MAC_TX_GRP_RESERVED(m) { \
ASSERT((m)->mi_txhwclnt_avail > 0); \
(m)->mi_txhwclnt_avail--; \
(m)->mi_txhwclnt_used++; \
}
/* Released a TX group */
#define MAC_TX_GRP_RELEASED(m) { \
ASSERT((m)->mi_txhwclnt_used > 0); \
(m)->mi_txhwclnt_avail++; \
(m)->mi_txhwclnt_used--; \
}
/* for mi_state_flags */
#define MIS_DISABLED 0x0001
#define MIS_IS_VNIC 0x0002
#define MIS_IS_AGGR 0x0004
#define MIS_NOTIFY_DONE 0x0008
#define MIS_EXCLUSIVE 0x0010
#define MIS_EXCLUSIVE_HELD 0x0020
#define MIS_LEGACY 0x0040
#define MIS_NO_ACTIVE 0x0080
#define MIS_POLL_DISABLE 0x0100
#define mi_getstat mi_callbacks->mc_getstat
#define mi_start mi_callbacks->mc_start
#define mi_stop mi_callbacks->mc_stop
#define mi_open mi_callbacks->mc_open
#define mi_close mi_callbacks->mc_close
#define mi_setpromisc mi_callbacks->mc_setpromisc
#define mi_multicst mi_callbacks->mc_multicst
#define mi_unicst mi_callbacks->mc_unicst
#define mi_tx mi_callbacks->mc_tx
#define mi_ioctl mi_callbacks->mc_ioctl
#define mi_getcapab mi_callbacks->mc_getcapab
typedef struct mac_notify_task_arg {
mac_impl_t *mnt_mip;
mac_notify_type_t mnt_type;
mac_ring_t *mnt_ring;
} mac_notify_task_arg_t;
/*
* XXX All MAC_DBG_PRTs must be replaced with call to dtrace probes. For now
* it may be easier to have these printfs for easier debugging
*/
#ifdef DEBUG
extern int mac_dbg;
#define MAC_DBG_PRT(a) if (mac_dbg > 0) {(void) printf a; }
#else
#define MAC_DBG_PRT(a)
#endif
/*
* The mac_perim_handle_t is an opaque type that encodes the 'mip' pointer
* and whether internally a mac_open was done when acquiring the perimeter.
*/
#define MAC_ENCODE_MPH(mph, mh, need_close) \
(mph) = (mac_perim_handle_t)((uintptr_t)(mh) | need_close)
#define MAC_DECODE_MPH(mph, mip, need_close) { \
mip = (mac_impl_t *)(((uintptr_t)mph) & ~0x1); \
(need_close) = ((uintptr_t)mph & 0x1); \
}
/*
* Type of property information that can be returned by a driver.
* Valid flags of the pr_flags of the mac_prop_info_t data structure.
*/
#define MAC_PROP_INFO_DEFAULT 0x0001
#define MAC_PROP_INFO_RANGE 0x0002
#define MAC_PROP_INFO_PERM 0x0004
/*
* Property information. pr_flags is a combination of one of the
* MAC_PROP_INFO_* flags, it is reset by the framework before invoking
* the driver's prefix_propinfo() entry point.
*
* Drivers should use MAC_PROP_INFO_SET_*() macros to provide
* information about a property.
*/
typedef struct mac_prop_info_state_s {
uint8_t pr_flags;
uint8_t pr_perm;
void *pr_default;
size_t pr_default_size;
uint8_t pr_default_status;
mac_propval_range_t *pr_range;
} mac_prop_info_state_t;
#define MAC_PROTECT_ENABLED(mcip, type) \
(((mcip)->mci_flent-> \
fe_resource_props.mrp_mask & MRP_PROTECT) != 0 && \
((mcip)->mci_flent-> \
fe_resource_props.mrp_protect.mp_types & (type)) != 0)
typedef struct mac_client_impl_s mac_client_impl_t;
extern void mac_init(void);
extern int mac_fini(void);
extern void mac_ndd_ioctl(mac_impl_t *, queue_t *, mblk_t *);
extern boolean_t mac_ip_hdr_length_v6(ip6_t *, uint8_t *, uint16_t *,
uint8_t *, ip6_frag_t **);
extern mblk_t *mac_copymsgchain_cksum(mblk_t *);
extern mblk_t *mac_fix_cksum(mblk_t *);
extern void mac_packet_print(mac_handle_t, mblk_t *);
extern void mac_rx_deliver(void *, mac_resource_handle_t, mblk_t *,
mac_header_info_t *);
extern void mac_tx_notify(mac_impl_t *);
extern boolean_t mac_callback_find(mac_cb_info_t *, mac_cb_t **, mac_cb_t *);
extern void mac_callback_add(mac_cb_info_t *, mac_cb_t **, mac_cb_t *);
extern boolean_t mac_callback_remove(mac_cb_info_t *, mac_cb_t **, mac_cb_t *);
extern void mac_callback_remove_wait(mac_cb_info_t *);
extern void mac_callback_free(mac_cb_t *);
extern mac_cb_t *mac_callback_walker_cleanup(mac_cb_info_t *, mac_cb_t **);
/* in mac_bcast.c */
extern void mac_bcast_init(void);
extern void mac_bcast_fini(void);
extern mac_impl_t *mac_bcast_grp_mip(void *);
extern int mac_bcast_add(mac_client_impl_t *, const uint8_t *, uint16_t,
mac_addrtype_t);
extern void mac_bcast_delete(mac_client_impl_t *, const uint8_t *, uint16_t);
extern void mac_bcast_send(void *, void *, mblk_t *, boolean_t);
extern void mac_bcast_grp_free(void *);
extern void mac_bcast_refresh(mac_impl_t *, mac_multicst_t, void *,
boolean_t);
extern void mac_client_bcast_refresh(mac_client_impl_t *, mac_multicst_t,
void *, boolean_t);
/*
* Grouping functions are used internally by MAC layer.
*/
extern int mac_group_addmac(mac_group_t *, const uint8_t *);
extern int mac_group_remmac(mac_group_t *, const uint8_t *);
extern int mac_rx_group_add_flow(mac_client_impl_t *, flow_entry_t *,
mac_group_t *);
extern mblk_t *mac_hwring_tx(mac_ring_handle_t, mblk_t *);
extern mblk_t *mac_bridge_tx(mac_impl_t *, mac_ring_handle_t, mblk_t *);
extern mac_group_t *mac_reserve_rx_group(mac_client_impl_t *, uint8_t *,
boolean_t);
extern void mac_release_rx_group(mac_client_impl_t *, mac_group_t *);
extern int mac_rx_switch_group(mac_client_impl_t *, mac_group_t *,
mac_group_t *);
extern mac_ring_t *mac_reserve_tx_ring(mac_impl_t *, mac_ring_t *);
extern mac_group_t *mac_reserve_tx_group(mac_client_impl_t *, boolean_t);
extern void mac_release_tx_group(mac_client_impl_t *, mac_group_t *);
extern void mac_tx_switch_group(mac_client_impl_t *, mac_group_t *,
mac_group_t *);
extern void mac_rx_switch_grp_to_sw(mac_group_t *);
/*
* MAC address functions are used internally by MAC layer.
*/
extern mac_address_t *mac_find_macaddr(mac_impl_t *, uint8_t *);
extern boolean_t mac_check_macaddr_shared(mac_address_t *);
extern int mac_update_macaddr(mac_address_t *, uint8_t *);
extern void mac_freshen_macaddr(mac_address_t *, uint8_t *);
extern void mac_retrieve_macaddr(mac_address_t *, uint8_t *);
extern void mac_init_macaddr(mac_impl_t *);
extern void mac_fini_macaddr(mac_impl_t *);
/*
* Flow construction/destruction routines.
* Not meant to be used by mac clients.
*/
extern int mac_link_flow_init(mac_client_handle_t, flow_entry_t *);
extern void mac_link_flow_clean(mac_client_handle_t, flow_entry_t *);
/*
* Fanout update routines called when the link speed of the NIC changes
* or when a MAC client's share is unbound.
*/
extern void mac_fanout_recompute_client(mac_client_impl_t *, cpupart_t *);
extern void mac_fanout_recompute(mac_impl_t *);
/*
* The following functions are used internally by the MAC layer to
* add/remove/update flows associated with a mac_impl_t. They should
* never be used directly by MAC clients.
*/
extern int mac_datapath_setup(mac_client_impl_t *, flow_entry_t *, uint32_t);
extern void mac_datapath_teardown(mac_client_impl_t *, flow_entry_t *,
uint32_t);
extern void mac_rx_srs_group_setup(mac_client_impl_t *, flow_entry_t *,
uint32_t);
extern void mac_tx_srs_group_setup(mac_client_impl_t *, flow_entry_t *,
uint32_t);
extern void mac_rx_srs_group_teardown(flow_entry_t *, boolean_t);
extern void mac_tx_srs_group_teardown(mac_client_impl_t *, flow_entry_t *,
uint32_t);
extern int mac_rx_classify_flow_quiesce(flow_entry_t *, void *);
extern int mac_rx_classify_flow_restart(flow_entry_t *, void *);
extern void mac_client_quiesce(mac_client_impl_t *);
extern void mac_client_restart(mac_client_impl_t *);
extern void mac_flow_update_priority(mac_client_impl_t *, flow_entry_t *);
extern void mac_flow_rem_subflow(flow_entry_t *);
extern void mac_rename_flow(flow_entry_t *, const char *);
extern void mac_flow_set_name(flow_entry_t *, const char *);
extern mblk_t *mac_add_vlan_tag(mblk_t *, uint_t, uint16_t);
extern mblk_t *mac_add_vlan_tag_chain(mblk_t *, uint_t, uint16_t);
extern mblk_t *mac_strip_vlan_tag_chain(mblk_t *);
extern void mac_pkt_drop(void *, mac_resource_handle_t, mblk_t *, boolean_t);
extern mblk_t *mac_rx_flow(mac_handle_t, mac_resource_handle_t, mblk_t *);
extern void i_mac_share_alloc(mac_client_impl_t *);
extern void i_mac_share_free(mac_client_impl_t *);
extern void i_mac_perim_enter(mac_impl_t *);
extern void i_mac_perim_exit(mac_impl_t *);
extern int i_mac_perim_enter_nowait(mac_impl_t *);
extern void i_mac_tx_srs_notify(mac_impl_t *, mac_ring_handle_t);
extern int mac_hold(const char *, mac_impl_t **);
extern void mac_rele(mac_impl_t *);
extern int i_mac_disable(mac_impl_t *);
extern void i_mac_notify(mac_impl_t *, mac_notify_type_t);
extern void i_mac_notify_exit(mac_impl_t *);
extern void mac_rx_group_unmark(mac_group_t *, uint_t);
extern void mac_tx_client_flush(mac_client_impl_t *);
extern void mac_tx_client_block(mac_client_impl_t *);
extern void mac_tx_client_unblock(mac_client_impl_t *);
extern void mac_tx_invoke_callbacks(mac_client_impl_t *, mac_tx_cookie_t);
extern int i_mac_promisc_set(mac_impl_t *, boolean_t);
extern void i_mac_promisc_walker_cleanup(mac_impl_t *);
extern mactype_t *mactype_getplugin(const char *);
extern void mac_addr_factory_init(mac_impl_t *);
extern void mac_addr_factory_fini(mac_impl_t *);
extern void mac_register_priv_prop(mac_impl_t *, char **);
extern void mac_unregister_priv_prop(mac_impl_t *);
extern int mac_init_rings(mac_impl_t *, mac_ring_type_t);
extern void mac_free_rings(mac_impl_t *, mac_ring_type_t);
extern void mac_compare_ddi_handle(mac_group_t *, uint_t, mac_ring_t *);
extern int mac_start_group(mac_group_t *);
extern void mac_stop_group(mac_group_t *);
extern int mac_start_ring(mac_ring_t *);
extern void mac_stop_ring(mac_ring_t *);
extern int mac_add_macaddr(mac_impl_t *, mac_group_t *, uint8_t *, boolean_t);
extern int mac_remove_macaddr(mac_address_t *);
extern void mac_set_group_state(mac_group_t *, mac_group_state_t);
extern void mac_group_add_client(mac_group_t *, mac_client_impl_t *);
extern void mac_group_remove_client(mac_group_t *, mac_client_impl_t *);
extern int i_mac_group_add_ring(mac_group_t *, mac_ring_t *, int);
extern void i_mac_group_rem_ring(mac_group_t *, mac_ring_t *, boolean_t);
extern int mac_group_ring_modify(mac_client_impl_t *, mac_group_t *,
mac_group_t *);
extern void mac_poll_state_change(mac_handle_t, boolean_t);
extern mac_group_state_t mac_group_next_state(mac_group_t *,
mac_client_impl_t **, mac_group_t *, boolean_t);
extern mblk_t *mac_protect_check(mac_client_handle_t, mblk_t *);
extern int mac_protect_set(mac_client_handle_t, mac_resource_props_t *);
extern boolean_t mac_protect_enabled(mac_client_handle_t, uint32_t);
extern int mac_protect_validate(mac_resource_props_t *);
extern void mac_protect_update(mac_resource_props_t *, mac_resource_props_t *);
extern void mac_protect_update_v6_local_addr(mac_client_impl_t *);
extern void mac_protect_intercept_dhcp(mac_client_impl_t *, mblk_t *);
extern void mac_protect_flush_dhcp(mac_client_impl_t *);
extern void mac_protect_cancel_timer(mac_client_impl_t *);
extern void mac_protect_init(mac_client_impl_t *);
extern void mac_protect_fini(mac_client_impl_t *);
extern int mac_set_resources(mac_handle_t, mac_resource_props_t *);
extern void mac_get_resources(mac_handle_t, mac_resource_props_t *);
extern void mac_get_effective_resources(mac_handle_t, mac_resource_props_t *);
extern cpupart_t *mac_pset_find(mac_resource_props_t *, boolean_t *);
extern void mac_set_pool_effective(boolean_t, cpupart_t *,
mac_resource_props_t *, mac_resource_props_t *);
extern void mac_set_rings_effective(mac_client_impl_t *);
extern mac_client_impl_t *mac_check_primary_relocation(mac_client_impl_t *,
boolean_t);
/* Global callbacks into the bridging module (when loaded) */
extern mac_bridge_tx_t mac_bridge_tx_cb;
extern mac_bridge_rx_t mac_bridge_rx_cb;
extern mac_bridge_ref_t mac_bridge_ref_cb;
extern mac_bridge_ls_t mac_bridge_ls_cb;
#ifdef __cplusplus
}
#endif
#endif /* _SYS_MAC_IMPL_H */
|