xnbu.c (568a765b) xnbu.c (551bc2a6)
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE

--- 67 unchanged lines hidden (view full) ---

76 xnbu_m_resources,
77 NULL,
78 xnbu_m_getcapab
79};
80
81static void
82xnbu_to_host(xnb_t *xnbp, mblk_t *mp)
83{
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE

--- 67 unchanged lines hidden (view full) ---

76 xnbu_m_resources,
77 NULL,
78 xnbu_m_getcapab
79};
80
81static void
82xnbu_to_host(xnb_t *xnbp, mblk_t *mp)
83{
84 xnbu_t *xnbup = xnbp->x_flavour_data;
84 xnbu_t *xnbup = xnbp->xnb_flavour_data;
85 boolean_t sched = B_FALSE;
86
87 ASSERT(mp != NULL);
88
89 mac_rx(xnbup->u_mh, xnbup->u_rx_handle, mp);
90
85 boolean_t sched = B_FALSE;
86
87 ASSERT(mp != NULL);
88
89 mac_rx(xnbup->u_mh, xnbup->u_rx_handle, mp);
90
91 mutex_enter(&xnbp->x_tx_lock);
91 mutex_enter(&xnbp->xnb_tx_lock);
92
93 /*
94 * If a transmit attempt failed because we ran out of ring
95 * space and there is now some space, re-enable the transmit
96 * path.
97 */
98 if (xnbup->u_need_sched &&
92
93 /*
94 * If a transmit attempt failed because we ran out of ring
95 * space and there is now some space, re-enable the transmit
96 * path.
97 */
98 if (xnbup->u_need_sched &&
99 RING_HAS_UNCONSUMED_REQUESTS(&xnbp->x_rx_ring)) {
99 RING_HAS_UNCONSUMED_REQUESTS(&xnbp->xnb_rx_ring)) {
100 sched = B_TRUE;
101 xnbup->u_need_sched = B_FALSE;
102 }
103
100 sched = B_TRUE;
101 xnbup->u_need_sched = B_FALSE;
102 }
103
104 mutex_exit(&xnbp->x_tx_lock);
104 mutex_exit(&xnbp->xnb_tx_lock);
105
106 if (sched)
107 mac_tx_update(xnbup->u_mh);
108}
109
110static mblk_t *
111xnbu_cksum_from_peer(xnb_t *xnbp, mblk_t *mp, uint16_t flags)
112{

--- 37 unchanged lines hidden (view full) ---

150 return (mp);
151}
152
153static uint16_t
154xnbu_cksum_to_peer(xnb_t *xnbp, mblk_t *mp)
155{
156 uint16_t r = 0;
157
105
106 if (sched)
107 mac_tx_update(xnbup->u_mh);
108}
109
110static mblk_t *
111xnbu_cksum_from_peer(xnb_t *xnbp, mblk_t *mp, uint16_t flags)
112{

--- 37 unchanged lines hidden (view full) ---

150 return (mp);
151}
152
153static uint16_t
154xnbu_cksum_to_peer(xnb_t *xnbp, mblk_t *mp)
155{
156 uint16_t r = 0;
157
158 if (xnbp->x_cksum_offload) {
158 if (xnbp->xnb_cksum_offload) {
159 uint32_t pflags;
160
161 hcksum_retrieve(mp, NULL, NULL, NULL, NULL,
162 NULL, NULL, &pflags);
163
164 /*
165 * If the protocol stack has requested checksum
166 * offload, inform the peer that we have not

--- 4 unchanged lines hidden (view full) ---

171 }
172
173 return (r);
174}
175
176static void
177xnbu_connected(xnb_t *xnbp)
178{
159 uint32_t pflags;
160
161 hcksum_retrieve(mp, NULL, NULL, NULL, NULL,
162 NULL, NULL, &pflags);
163
164 /*
165 * If the protocol stack has requested checksum
166 * offload, inform the peer that we have not

--- 4 unchanged lines hidden (view full) ---

171 }
172
173 return (r);
174}
175
176static void
177xnbu_connected(xnb_t *xnbp)
178{
179 xnbu_t *xnbup = xnbp->x_flavour_data;
179 xnbu_t *xnbup = xnbp->xnb_flavour_data;
180
181 mac_link_update(xnbup->u_mh, LINK_STATE_UP);
182 /*
183 * We are able to send packets now - bring them on.
184 */
185 mac_tx_update(xnbup->u_mh);
186}
187
188static void
189xnbu_disconnected(xnb_t *xnbp)
190{
180
181 mac_link_update(xnbup->u_mh, LINK_STATE_UP);
182 /*
183 * We are able to send packets now - bring them on.
184 */
185 mac_tx_update(xnbup->u_mh);
186}
187
188static void
189xnbu_disconnected(xnb_t *xnbp)
190{
191 xnbu_t *xnbup = xnbp->x_flavour_data;
191 xnbu_t *xnbup = xnbp->xnb_flavour_data;
192
193 mac_link_update(xnbup->u_mh, LINK_STATE_DOWN);
194}
195
196/*ARGSUSED*/
197static boolean_t
198xnbu_hotplug(xnb_t *xnbp)
199{
200 return (B_TRUE);
201}
202
203static mblk_t *
204xnbu_m_send(void *arg, mblk_t *mp)
205{
206 xnb_t *xnbp = arg;
192
193 mac_link_update(xnbup->u_mh, LINK_STATE_DOWN);
194}
195
196/*ARGSUSED*/
197static boolean_t
198xnbu_hotplug(xnb_t *xnbp)
199{
200 return (B_TRUE);
201}
202
203static mblk_t *
204xnbu_m_send(void *arg, mblk_t *mp)
205{
206 xnb_t *xnbp = arg;
207 xnbu_t *xnbup = xnbp->x_flavour_data;
207 xnbu_t *xnbup = xnbp->xnb_flavour_data;
208
208
209 mp = xnb_to_peer(arg, mp);
209 mp = xnb_copy_to_peer(arg, mp);
210
211 /* XXPV dme: playing with need_sched without txlock? */
212
213 /*
214 * If we consumed all of the mblk_t's offered, perhaps we need
215 * to indicate that we can accept more. Otherwise we are full
216 * and need to wait for space.
217 */

--- 16 unchanged lines hidden (view full) ---

234/*
235 * xnbu_m_set_mac_addr() -- set the physical network address on the board
236 */
237/* ARGSUSED */
238static int
239xnbu_m_set_mac_addr(void *arg, const uint8_t *macaddr)
240{
241 xnb_t *xnbp = arg;
210
211 /* XXPV dme: playing with need_sched without txlock? */
212
213 /*
214 * If we consumed all of the mblk_t's offered, perhaps we need
215 * to indicate that we can accept more. Otherwise we are full
216 * and need to wait for space.
217 */

--- 16 unchanged lines hidden (view full) ---

234/*
235 * xnbu_m_set_mac_addr() -- set the physical network address on the board
236 */
237/* ARGSUSED */
238static int
239xnbu_m_set_mac_addr(void *arg, const uint8_t *macaddr)
240{
241 xnb_t *xnbp = arg;
242 xnbu_t *xnbup = xnbp->x_flavour_data;
242 xnbu_t *xnbup = xnbp->xnb_flavour_data;
243
243
244 bcopy(macaddr, xnbp->x_mac_addr, ETHERADDRL);
245 mac_unicst_update(xnbup->u_mh, xnbp->x_mac_addr);
244 bcopy(macaddr, xnbp->xnb_mac_addr, ETHERADDRL);
245 mac_unicst_update(xnbup->u_mh, xnbp->xnb_mac_addr);
246
247 return (0);
248}
249
250/*
251 * xnbu_m_set_multicast() -- set (enable) or disable a multicast address
252 */
253/*ARGSUSED*/

--- 41 unchanged lines hidden (view full) ---

295{
296}
297
298static int
299xnbu_m_stat(void *arg, uint_t stat, uint64_t *val)
300{
301 xnb_t *xnbp = arg;
302
246
247 return (0);
248}
249
250/*
251 * xnbu_m_set_multicast() -- set (enable) or disable a multicast address
252 */
253/*ARGSUSED*/

--- 41 unchanged lines hidden (view full) ---

295{
296}
297
298static int
299xnbu_m_stat(void *arg, uint_t stat, uint64_t *val)
300{
301 xnb_t *xnbp = arg;
302
303 mutex_enter(&xnbp->x_tx_lock);
304 mutex_enter(&xnbp->x_rx_lock);
303 mutex_enter(&xnbp->xnb_tx_lock);
304 mutex_enter(&xnbp->xnb_rx_lock);
305
306#define map_stat(q, r) \
307 case (MAC_STAT_##q): \
305
306#define map_stat(q, r) \
307 case (MAC_STAT_##q): \
308 *val = xnbp->x_stat_##r; \
308 *val = xnbp->xnb_stat_##r; \
309 break
310
311 switch (stat) {
312
313 map_stat(IPACKETS, ipackets);
314 map_stat(OPACKETS, opackets);
315 map_stat(RBYTES, rbytes);
316 map_stat(OBYTES, obytes);
317
318 default:
309 break
310
311 switch (stat) {
312
313 map_stat(IPACKETS, ipackets);
314 map_stat(OPACKETS, opackets);
315 map_stat(RBYTES, rbytes);
316 map_stat(OBYTES, obytes);
317
318 default:
319 mutex_exit(&xnbp->x_rx_lock);
320 mutex_exit(&xnbp->x_tx_lock);
319 mutex_exit(&xnbp->xnb_rx_lock);
320 mutex_exit(&xnbp->xnb_tx_lock);
321
322 return (ENOTSUP);
323 }
324
325#undef map_stat
326
321
322 return (ENOTSUP);
323 }
324
325#undef map_stat
326
327 mutex_exit(&xnbp->x_rx_lock);
328 mutex_exit(&xnbp->x_tx_lock);
327 mutex_exit(&xnbp->xnb_rx_lock);
328 mutex_exit(&xnbp->xnb_tx_lock);
329
330 return (0);
331}
332
333/*ARGSUSED*/
334static void
335xnbu_m_blank(void *arg, time_t ticks, uint_t count)
336{
337 /*
338 * XXPV dme: blanking is not currently implemented.
339 */
340}
341
342static void
343xnbu_m_resources(void *arg)
344{
345 xnb_t *xnbp = arg;
329
330 return (0);
331}
332
333/*ARGSUSED*/
334static void
335xnbu_m_blank(void *arg, time_t ticks, uint_t count)
336{
337 /*
338 * XXPV dme: blanking is not currently implemented.
339 */
340}
341
342static void
343xnbu_m_resources(void *arg)
344{
345 xnb_t *xnbp = arg;
346 xnbu_t *xnbup = xnbp->x_flavour_data;
346 xnbu_t *xnbup = xnbp->xnb_flavour_data;
347 mac_rx_fifo_t mrf;
348
349 mrf.mrf_type = MAC_RX_FIFO;
350 mrf.mrf_blank = xnbu_m_blank;
351 mrf.mrf_arg = (void *)xnbp;
352 mrf.mrf_normal_blank_time = 128; /* XXPV dme: see xnbu_m_blank() */
353 mrf.mrf_normal_pkt_count = 8; /* XXPV dme: see xnbu_m_blank() */
354

--- 5 unchanged lines hidden (view full) ---

360xnbu_m_getcapab(void *arg, mac_capab_t cap, void *cap_data)
361{
362 xnb_t *xnbp = arg;
363
364 switch (cap) {
365 case MAC_CAPAB_HCKSUM: {
366 uint32_t *capab = cap_data;
367
347 mac_rx_fifo_t mrf;
348
349 mrf.mrf_type = MAC_RX_FIFO;
350 mrf.mrf_blank = xnbu_m_blank;
351 mrf.mrf_arg = (void *)xnbp;
352 mrf.mrf_normal_blank_time = 128; /* XXPV dme: see xnbu_m_blank() */
353 mrf.mrf_normal_pkt_count = 8; /* XXPV dme: see xnbu_m_blank() */
354

--- 5 unchanged lines hidden (view full) ---

360xnbu_m_getcapab(void *arg, mac_capab_t cap, void *cap_data)
361{
362 xnb_t *xnbp = arg;
363
364 switch (cap) {
365 case MAC_CAPAB_HCKSUM: {
366 uint32_t *capab = cap_data;
367
368 if (xnbp->x_cksum_offload)
368 if (xnbp->xnb_cksum_offload)
369 *capab = HCKSUM_INET_PARTIAL;
370 else
371 *capab = 0;
372 break;
373 }
374
375 case MAC_CAPAB_POLL:
376 /* Just return B_TRUE. */

--- 46 unchanged lines hidden (view full) ---

423 mr->m_dip = dip;
424 mr->m_driver = xnbp;
425
426 /*
427 * Initialize pointers to device specific functions which will be
428 * used by the generic layer.
429 */
430 mr->m_type_ident = MAC_PLUGIN_IDENT_ETHER;
369 *capab = HCKSUM_INET_PARTIAL;
370 else
371 *capab = 0;
372 break;
373 }
374
375 case MAC_CAPAB_POLL:
376 /* Just return B_TRUE. */

--- 46 unchanged lines hidden (view full) ---

423 mr->m_dip = dip;
424 mr->m_driver = xnbp;
425
426 /*
427 * Initialize pointers to device specific functions which will be
428 * used by the generic layer.
429 */
430 mr->m_type_ident = MAC_PLUGIN_IDENT_ETHER;
431 mr->m_src_addr = xnbp->x_mac_addr;
431 mr->m_src_addr = xnbp->xnb_mac_addr;
432 mr->m_callbacks = &xnb_callbacks;
433 mr->m_min_sdu = 0;
434 mr->m_max_sdu = XNBMAXPKT;
435
432 mr->m_callbacks = &xnb_callbacks;
433 mr->m_min_sdu = 0;
434 mr->m_max_sdu = XNBMAXPKT;
435
436 (void) memset(xnbp->x_mac_addr, 0xff, ETHERADDRL);
437 xnbp->x_mac_addr[0] &= 0xfe;
436 (void) memset(xnbp->xnb_mac_addr, 0xff, ETHERADDRL);
437 xnbp->xnb_mac_addr[0] &= 0xfe;
438 xnbup->u_need_sched = B_FALSE;
439
440 /*
441 * Register ourselves with the GLDv3 interface.
442 */
443 err = mac_register(mr, &xnbup->u_mh);
444 mac_free(mr);
445 if (err != 0) {

--- 7 unchanged lines hidden (view full) ---

453 return (DDI_SUCCESS);
454}
455
456/*ARGSUSED*/
457int
458xnbu_detach(dev_info_t *dip, ddi_detach_cmd_t cmd)
459{
460 xnb_t *xnbp = ddi_get_driver_private(dip);
438 xnbup->u_need_sched = B_FALSE;
439
440 /*
441 * Register ourselves with the GLDv3 interface.
442 */
443 err = mac_register(mr, &xnbup->u_mh);
444 mac_free(mr);
445 if (err != 0) {

--- 7 unchanged lines hidden (view full) ---

453 return (DDI_SUCCESS);
454}
455
456/*ARGSUSED*/
457int
458xnbu_detach(dev_info_t *dip, ddi_detach_cmd_t cmd)
459{
460 xnb_t *xnbp = ddi_get_driver_private(dip);
461 xnbu_t *xnbup = xnbp->x_flavour_data;
461 xnbu_t *xnbup = xnbp->xnb_flavour_data;
462
463 switch (cmd) {
464 case DDI_DETACH:
465 break;
466 case DDI_SUSPEND:
467 return (DDI_SUCCESS);
468 default:
469 return (DDI_FAILURE);
470 }
471
472 ASSERT(xnbp != NULL);
473 ASSERT(xnbup != NULL);
474
462
463 switch (cmd) {
464 case DDI_DETACH:
465 break;
466 case DDI_SUSPEND:
467 return (DDI_SUCCESS);
468 default:
469 return (DDI_FAILURE);
470 }
471
472 ASSERT(xnbp != NULL);
473 ASSERT(xnbup != NULL);
474
475 mutex_enter(&xnbp->x_tx_lock);
476 mutex_enter(&xnbp->x_rx_lock);
475 mutex_enter(&xnbp->xnb_tx_lock);
476 mutex_enter(&xnbp->xnb_rx_lock);
477
477
478 if (!xnbp->x_detachable || xnbp->x_connected ||
479 (xnbp->x_rx_buf_count > 0)) {
480 mutex_exit(&xnbp->x_rx_lock);
481 mutex_exit(&xnbp->x_tx_lock);
478 if (!xnbp->xnb_detachable || xnbp->xnb_connected ||
479 (xnbp->xnb_rx_buf_count > 0)) {
480 mutex_exit(&xnbp->xnb_rx_lock);
481 mutex_exit(&xnbp->xnb_tx_lock);
482
483 return (DDI_FAILURE);
484 }
485
482
483 return (DDI_FAILURE);
484 }
485
486 mutex_exit(&xnbp->x_rx_lock);
487 mutex_exit(&xnbp->x_tx_lock);
486 mutex_exit(&xnbp->xnb_rx_lock);
487 mutex_exit(&xnbp->xnb_tx_lock);
488
489 /*
490 * Attempt to unregister the mac.
491 */
492 if ((xnbup->u_mh != NULL) && (mac_unregister(xnbup->u_mh) != 0))
493 return (DDI_FAILURE);
494 kmem_free(xnbup, sizeof (*xnbup));
495

--- 47 unchanged lines hidden ---
488
489 /*
490 * Attempt to unregister the mac.
491 */
492 if ((xnbup->u_mh != NULL) && (mac_unregister(xnbup->u_mh) != 0))
493 return (DDI_FAILURE);
494 kmem_free(xnbup, sizeof (*xnbup));
495

--- 47 unchanged lines hidden ---