79 #include <sys/mac_provider.h>
80 #include <sys/mac_ether.h>
81
82 /*
83 * The call to mac_register(9F) generally comes from the context of
84 * attach(9E). This function encapsulates setting up and initializing
85 * the mac_register_t structure and should be assumed to be called from
86 * attach.
87 *
88 * The exact set of callbacks and private properties will vary based
89 * upon the driver.
90 */
91
92 static char *example_priv_props[] = {
93 "_rx_intr_throttle",
94 "_tx_intr_throttle",
95 NULL
96 };
97
98 static mac_callbacks_t example_m_callbacks = {
99 .mc_callbacsk = MC_GETCAPAB | MC_SETPROP | MC_GETPROP | MC_PROPINFO |
100 MC_IOCTL,
101 .mc_start = example_m_start,
102 .mc_stop = example_m_stop,
103 .mc_setpromisc = example_m_setpromisc,
104 .mc_multicst = example_m_multicst,
105 .mc_unicst = example_m_unicst,
106 .mc_tx = example_m_tx,
107 .mc_ioctl = example_m_ioctl,
108 .mc_getcapab = example_m_getcapab,
109 .mc_getprop = example_m_getprop,
110 .mc_setprop = example_m_setprop,
111 .mc_propinfo = example_m_propinfo
112 };
113
114 static boolean_t
115 example_register_mac(example_t *ep)
116 {
117 int status;
118 mac_register_t *mac;
119
120 mac = mac_alloc(MAC_VERSION);
121 if (mac == NULL)
122 return (B_FALSE);
123
124 mac->m_type_ident = MAC_PLUGIN_IDENT_ETHER;
125 mac->m_driver = ep;
126 mac->m_dip = ep->ep_dev_info;
127 mac->m_src_addr = ep->ep_mac_addr;
128 mac->m_callbacks = &example_m_callbacks;
129 mac->m_min_sdu = 0;
130 mac->m_max_sdu = ep->ep_sdu;
131 mac->m_margin = VLAN_TAGSZ;
132 mac->m_priv_props = exmple_priv_props;
133
134 status = mac_register(mac, &ep->ep_mac_hdl);
135 mac_free(mac);
136
137 return (status == 0);
138 }
139
140 ERRORS
141 The mac_register() function may fail if:
142
143 EEXIST A driver with the same name and instance already
144 exists.
145
146 EINVAL There was something invalid with the device's
147 registration information. Some of the following
148 reasons may apply, this list is not exhaustive:
149
150 o The mac_init_ops(9F) function was not called.
151
152 o The specified mac plugin does not exist.
167 nodes.
168
169 ENOSPC The mac(9E) framework was unable to allocate a minor
170 number for the device as they have all been exhausted.
171
172 The mac_unregister() function will fail if:
173
174 EBUSY The device is still in use.
175
176 ENOTEMPTY The flow table is not empty.
177
178 Note the set of errors for both the mac_regster() and mac_unregister()
179 functions are not set in stone and may be expanded in future revisions.
180 In general, all errors should be handled by the device driver in similar
181 ways for these functions.
182
183 SEE ALSO
184 attach(9E), detach(9E), mac(9E), mac_alloc(9F), mac_init_ops(9F),
185 mac_callbacks(9S), mac_register(9S)
186
187 illumos September 22, 2017 illumos
|
79 #include <sys/mac_provider.h>
80 #include <sys/mac_ether.h>
81
82 /*
83 * The call to mac_register(9F) generally comes from the context of
84 * attach(9E). This function encapsulates setting up and initializing
85 * the mac_register_t structure and should be assumed to be called from
86 * attach.
87 *
88 * The exact set of callbacks and private properties will vary based
89 * upon the driver.
90 */
91
92 static char *example_priv_props[] = {
93 "_rx_intr_throttle",
94 "_tx_intr_throttle",
95 NULL
96 };
97
98 static mac_callbacks_t example_m_callbacks = {
99 .mc_callbacks = MC_GETCAPAB | MC_SETPROP | MC_GETPROP | MC_PROPINFO |
100 MC_IOCTL,
101 .mc_start = example_m_start,
102 .mc_stop = example_m_stop,
103 .mc_setpromisc = example_m_setpromisc,
104 .mc_multicst = example_m_multicst,
105 .mc_unicst = example_m_unicst,
106 .mc_tx = example_m_tx,
107 .mc_ioctl = example_m_ioctl,
108 .mc_getcapab = example_m_getcapab,
109 .mc_getprop = example_m_getprop,
110 .mc_setprop = example_m_setprop,
111 .mc_propinfo = example_m_propinfo
112 };
113
114 static boolean_t
115 example_register_mac(example_t *ep)
116 {
117 int status;
118 mac_register_t *mac;
119
120 mac = mac_alloc(MAC_VERSION);
121 if (mac == NULL)
122 return (B_FALSE);
123
124 mac->m_type_ident = MAC_PLUGIN_IDENT_ETHER;
125 mac->m_driver = ep;
126 mac->m_dip = ep->ep_dev_info;
127 mac->m_src_addr = ep->ep_mac_addr;
128 mac->m_callbacks = &example_m_callbacks;
129 mac->m_min_sdu = 0;
130 mac->m_max_sdu = ep->ep_sdu;
131 mac->m_margin = VLAN_TAGSZ;
132 mac->m_priv_props = example_priv_props;
133
134 status = mac_register(mac, &ep->ep_mac_hdl);
135 mac_free(mac);
136
137 return (status == 0);
138 }
139
140 ERRORS
141 The mac_register() function may fail if:
142
143 EEXIST A driver with the same name and instance already
144 exists.
145
146 EINVAL There was something invalid with the device's
147 registration information. Some of the following
148 reasons may apply, this list is not exhaustive:
149
150 o The mac_init_ops(9F) function was not called.
151
152 o The specified mac plugin does not exist.
167 nodes.
168
169 ENOSPC The mac(9E) framework was unable to allocate a minor
170 number for the device as they have all been exhausted.
171
172 The mac_unregister() function will fail if:
173
174 EBUSY The device is still in use.
175
176 ENOTEMPTY The flow table is not empty.
177
178 Note the set of errors for both the mac_regster() and mac_unregister()
179 functions are not set in stone and may be expanded in future revisions.
180 In general, all errors should be handled by the device driver in similar
181 ways for these functions.
182
183 SEE ALSO
184 attach(9E), detach(9E), mac(9E), mac_alloc(9F), mac_init_ops(9F),
185 mac_callbacks(9S), mac_register(9S)
186
187 illumos February 15, 2020 illumos
|