Print this page
7127 remove -Wno-missing-braces from Makefile.uts
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/xen/io/xnbo.c
+++ new/usr/src/uts/common/xen/io/xnbo.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 2010 Sun Microsystems, Inc. All rights reserved.
24 24 * Use is subject to license terms.
25 25 */
26 26
27 27 /*
28 28 * Xen network backend - mac client edition.
29 29 *
30 30 * A driver that sits above an existing GLDv3/Nemo MAC driver and
31 31 * relays packets to/from that driver from/to a guest domain.
32 32 */
33 33
34 34 #ifdef DEBUG
35 35 #define XNBO_DEBUG 1
36 36 #endif /* DEBUG */
37 37
38 38 #include "xnb.h"
39 39
40 40 #include <sys/sunddi.h>
41 41 #include <sys/ddi.h>
42 42 #include <sys/modctl.h>
43 43 #include <sys/strsubr.h>
44 44 #include <sys/mac_client.h>
45 45 #include <sys/mac_provider.h>
46 46 #include <sys/mac_client_priv.h>
47 47 #include <sys/mac.h>
48 48 #include <net/if.h>
49 49 #include <sys/dlpi.h>
50 50 #include <sys/pattr.h>
51 51 #include <xen/sys/xenbus_impl.h>
52 52 #include <xen/sys/xendev.h>
53 53 #include <sys/sdt.h>
54 54 #include <sys/note.h>
55 55
56 56 #ifdef XNBO_DEBUG
57 57 boolean_t xnbo_cksum_offload_to_peer = B_TRUE;
58 58 boolean_t xnbo_cksum_offload_from_peer = B_TRUE;
59 59 #endif /* XNBO_DEBUG */
60 60
61 61 /* Track multicast addresses. */
62 62 typedef struct xmca {
63 63 struct xmca *next;
64 64 ether_addr_t addr;
65 65 } xmca_t;
66 66
67 67 /* State about this device instance. */
68 68 typedef struct xnbo {
69 69 mac_handle_t o_mh;
70 70 mac_client_handle_t o_mch;
71 71 mac_unicast_handle_t o_mah;
72 72 mac_promisc_handle_t o_mphp;
73 73 boolean_t o_running;
74 74 boolean_t o_promiscuous;
75 75 uint32_t o_hcksum_capab;
76 76 xmca_t *o_mca;
77 77 char o_link_name[LIFNAMSIZ];
78 78 boolean_t o_need_rx_filter;
79 79 boolean_t o_need_setphysaddr;
80 80 boolean_t o_multicast_control;
81 81 } xnbo_t;
82 82
83 83 static void xnbo_close_mac(xnb_t *);
84 84 static void i_xnbo_close_mac(xnb_t *, boolean_t);
85 85
86 86 /*
87 87 * Packets from the peer come here. We pass them to the mac device.
88 88 */
89 89 static void
90 90 xnbo_to_mac(xnb_t *xnbp, mblk_t *mp)
91 91 {
92 92 xnbo_t *xnbop = xnbp->xnb_flavour_data;
93 93
94 94 ASSERT(mp != NULL);
95 95
96 96 if (!xnbop->o_running) {
97 97 xnbp->xnb_stat_tx_too_early++;
98 98 goto fail;
99 99 }
100 100
101 101 if (mac_tx(xnbop->o_mch, mp, 0,
102 102 MAC_DROP_ON_NO_DESC, NULL) != NULL) {
103 103 xnbp->xnb_stat_mac_full++;
104 104 }
105 105
106 106 return;
107 107
108 108 fail:
109 109 freemsgchain(mp);
110 110 }
111 111
112 112 /*
113 113 * Process the checksum flags `flags' provided by the peer for the
114 114 * packet `mp'.
115 115 */
116 116 static mblk_t *
117 117 xnbo_cksum_from_peer(xnb_t *xnbp, mblk_t *mp, uint16_t flags)
118 118 {
119 119 xnbo_t *xnbop = xnbp->xnb_flavour_data;
120 120
121 121 ASSERT(mp->b_next == NULL);
122 122
123 123 if ((flags & NETTXF_csum_blank) != 0) {
124 124 uint32_t capab = xnbop->o_hcksum_capab;
125 125
126 126 #ifdef XNBO_DEBUG
127 127 if (!xnbo_cksum_offload_from_peer)
128 128 capab = 0;
129 129 #endif /* XNBO_DEBUG */
130 130
131 131 /*
132 132 * The checksum in the packet is blank. Determine
133 133 * whether we can do hardware offload and, if so,
134 134 * update the flags on the mblk according. If not,
135 135 * calculate and insert the checksum using software.
136 136 */
137 137 mp = xnb_process_cksum_flags(xnbp, mp, capab);
138 138 }
139 139
140 140 return (mp);
141 141 }
142 142
143 143 /*
144 144 * Calculate the checksum flags to be relayed to the peer for the
145 145 * packet `mp'.
146 146 */
147 147 static uint16_t
148 148 xnbo_cksum_to_peer(xnb_t *xnbp, mblk_t *mp)
149 149 {
150 150 _NOTE(ARGUNUSED(xnbp));
151 151 uint16_t r = 0;
152 152 uint32_t pflags, csum;
153 153
154 154 #ifdef XNBO_DEBUG
155 155 if (!xnbo_cksum_offload_to_peer)
156 156 return (0);
157 157 #endif /* XNBO_DEBUG */
158 158
159 159 /*
160 160 * We might also check for HCK_PARTIALCKSUM here and,
161 161 * providing that the partial checksum covers the TCP/UDP
162 162 * payload, return NETRXF_data_validated.
163 163 *
164 164 * It seems that it's probably not worthwhile, as even MAC
165 165 * devices which advertise HCKSUM_INET_PARTIAL in their
166 166 * capabilities tend to use HCK_FULLCKSUM on the receive side
167 167 * - they are actually saying that in the output path the
168 168 * caller must use HCK_PARTIALCKSUM.
169 169 *
170 170 * Then again, if a NIC supports HCK_PARTIALCKSUM in its'
171 171 * output path, the host IP stack will use it. If such packets
172 172 * are destined for the peer (i.e. looped around) we would
173 173 * gain some advantage.
174 174 */
175 175
176 176 mac_hcksum_get(mp, NULL, NULL, NULL, &csum, &pflags);
177 177
178 178 /*
179 179 * If the MAC driver has asserted that the checksum is
180 180 * good, let the peer know.
181 181 */
182 182 if (((pflags & HCK_FULLCKSUM) != 0) &&
183 183 (((pflags & HCK_FULLCKSUM_OK) != 0) ||
184 184 (csum == 0xffff)))
185 185 r |= NETRXF_data_validated;
186 186
187 187 return (r);
188 188 }
189 189
190 190 /*
191 191 * Packets from the mac device come here. We pass them to the peer.
192 192 */
193 193 /*ARGSUSED*/
194 194 static void
195 195 xnbo_from_mac(void *arg, mac_resource_handle_t mrh, mblk_t *mp,
196 196 boolean_t loopback)
197 197 {
198 198 xnb_t *xnbp = arg;
199 199
200 200 mp = xnb_copy_to_peer(xnbp, mp);
201 201
202 202 if (mp != NULL)
203 203 freemsgchain(mp);
204 204 }
205 205
206 206 /*
207 207 * Packets from the mac device come here. We pass them to the peer if
208 208 * the destination mac address matches or it's a multicast/broadcast
209 209 * address.
210 210 */
211 211 static void
212 212 xnbo_from_mac_filter(void *arg, mac_resource_handle_t mrh, mblk_t *mp,
213 213 boolean_t loopback)
214 214 {
215 215 _NOTE(ARGUNUSED(loopback));
216 216 xnb_t *xnbp = arg;
217 217 xnbo_t *xnbop = xnbp->xnb_flavour_data;
218 218 mblk_t *next, *keep, *keep_head, *free, *free_head;
219 219
220 220 keep = keep_head = free = free_head = NULL;
221 221
222 222 #define ADD(list, bp) \
223 223 if (list != NULL) \
224 224 list->b_next = bp; \
225 225 else \
226 226 list##_head = bp; \
227 227 list = bp;
228 228
229 229 for (; mp != NULL; mp = next) {
230 230 mac_header_info_t hdr_info;
231 231
232 232 next = mp->b_next;
233 233 mp->b_next = NULL;
234 234
235 235 if (mac_header_info(xnbop->o_mh, mp, &hdr_info) != 0) {
236 236 ADD(free, mp);
237 237 continue;
238 238 }
239 239
240 240 if ((hdr_info.mhi_dsttype == MAC_ADDRTYPE_BROADCAST) ||
241 241 (hdr_info.mhi_dsttype == MAC_ADDRTYPE_MULTICAST)) {
242 242 ADD(keep, mp);
243 243 continue;
244 244 }
245 245
246 246 if (bcmp(hdr_info.mhi_daddr, xnbp->xnb_mac_addr,
247 247 sizeof (xnbp->xnb_mac_addr)) == 0) {
248 248 ADD(keep, mp);
249 249 continue;
250 250 }
251 251
252 252 ADD(free, mp);
253 253 }
254 254 #undef ADD
255 255
256 256 if (keep_head != NULL)
257 257 xnbo_from_mac(xnbp, mrh, keep_head, B_FALSE);
258 258
259 259 if (free_head != NULL)
260 260 freemsgchain(free_head);
261 261 }
262 262
263 263 static boolean_t
264 264 xnbo_open_mac(xnb_t *xnbp, char *mac)
265 265 {
266 266 xnbo_t *xnbop = xnbp->xnb_flavour_data;
267 267 int err;
268 268 const mac_info_t *mi;
269 269 void (*rx_fn)(void *, mac_resource_handle_t, mblk_t *, boolean_t);
270 270 struct ether_addr ea;
271 271 uint_t max_sdu;
272 272 mac_diag_t diag;
273 273
274 274 if ((err = mac_open_by_linkname(mac, &xnbop->o_mh)) != 0) {
275 275 cmn_err(CE_WARN, "xnbo_open_mac: "
276 276 "cannot open mac for link %s (%d)", mac, err);
277 277 return (B_FALSE);
278 278 }
279 279 ASSERT(xnbop->o_mh != NULL);
280 280
281 281 mi = mac_info(xnbop->o_mh);
282 282 ASSERT(mi != NULL);
283 283
284 284 if (mi->mi_media != DL_ETHER) {
285 285 cmn_err(CE_WARN, "xnbo_open_mac: "
286 286 "device is not DL_ETHER (%d)", mi->mi_media);
287 287 i_xnbo_close_mac(xnbp, B_TRUE);
288 288 return (B_FALSE);
289 289 }
290 290 if (mi->mi_media != mi->mi_nativemedia) {
291 291 cmn_err(CE_WARN, "xnbo_open_mac: "
292 292 "device media and native media mismatch (%d != %d)",
293 293 mi->mi_media, mi->mi_nativemedia);
294 294 i_xnbo_close_mac(xnbp, B_TRUE);
295 295 return (B_FALSE);
296 296 }
297 297
298 298 mac_sdu_get(xnbop->o_mh, NULL, &max_sdu);
299 299 if (max_sdu > XNBMAXPKT) {
300 300 cmn_err(CE_WARN, "xnbo_open_mac: mac device SDU too big (%d)",
301 301 max_sdu);
302 302 i_xnbo_close_mac(xnbp, B_TRUE);
303 303 return (B_FALSE);
304 304 }
305 305
306 306 /*
307 307 * MAC_OPEN_FLAGS_MULTI_PRIMARY is relevant when we are migrating a
308 308 * guest on the localhost itself. In this case we would have the MAC
309 309 * client open for the guest being migrated *and* also for the
310 310 * migrated guest (i.e. the former will be active till the migration
311 311 * is complete when the latter will be activated). This flag states
312 312 * that it is OK for mac_unicast_add to add the primary MAC unicast
313 313 * address multiple times.
314 314 */
315 315 if (mac_client_open(xnbop->o_mh, &xnbop->o_mch, NULL,
316 316 MAC_OPEN_FLAGS_USE_DATALINK_NAME |
317 317 MAC_OPEN_FLAGS_MULTI_PRIMARY) != 0) {
318 318 cmn_err(CE_WARN, "xnbo_open_mac: "
319 319 "error (%d) opening mac client", err);
320 320 i_xnbo_close_mac(xnbp, B_TRUE);
321 321 return (B_FALSE);
322 322 }
323 323
324 324 if (xnbop->o_need_rx_filter)
325 325 rx_fn = xnbo_from_mac_filter;
326 326 else
327 327 rx_fn = xnbo_from_mac;
328 328
329 329 err = mac_unicast_add_set_rx(xnbop->o_mch, NULL, MAC_UNICAST_PRIMARY,
330 330 &xnbop->o_mah, 0, &diag, xnbop->o_multicast_control ? rx_fn : NULL,
331 331 xnbp);
332 332 if (err != 0) {
333 333 cmn_err(CE_WARN, "xnbo_open_mac: failed to get the primary "
334 334 "MAC address of %s: %d", mac, err);
335 335 i_xnbo_close_mac(xnbp, B_TRUE);
336 336 return (B_FALSE);
337 337 }
338 338 if (!xnbop->o_multicast_control) {
339 339 err = mac_promisc_add(xnbop->o_mch, MAC_CLIENT_PROMISC_ALL,
340 340 rx_fn, xnbp, &xnbop->o_mphp, MAC_PROMISC_FLAGS_NO_TX_LOOP |
341 341 MAC_PROMISC_FLAGS_VLAN_TAG_STRIP);
342 342 if (err != 0) {
343 343 cmn_err(CE_WARN, "xnbo_open_mac: "
344 344 "cannot enable promiscuous mode of %s: %d",
345 345 mac, err);
346 346 i_xnbo_close_mac(xnbp, B_TRUE);
347 347 return (B_FALSE);
348 348 }
349 349 xnbop->o_promiscuous = B_TRUE;
350 350 }
351 351
352 352 if (xnbop->o_need_setphysaddr) {
353 353 err = mac_unicast_primary_set(xnbop->o_mh, xnbp->xnb_mac_addr);
354 354 /* Warn, but continue on. */
355 355 if (err != 0) {
356 356 bcopy(xnbp->xnb_mac_addr, ea.ether_addr_octet,
357 357 ETHERADDRL);
358 358 cmn_err(CE_WARN, "xnbo_open_mac: "
359 359 "cannot set MAC address of %s to "
360 360 "%s: %d", mac, ether_sprintf(&ea), err);
361 361 }
362 362 }
363 363
364 364 if (!mac_capab_get(xnbop->o_mh, MAC_CAPAB_HCKSUM,
365 365 &xnbop->o_hcksum_capab))
366 366 xnbop->o_hcksum_capab = 0;
367 367
368 368 xnbop->o_running = B_TRUE;
369 369
370 370 return (B_TRUE);
371 371 }
372 372
373 373 static void
374 374 xnbo_close_mac(xnb_t *xnbp)
375 375 {
376 376 i_xnbo_close_mac(xnbp, B_FALSE);
377 377 }
378 378
379 379 static void
380 380 i_xnbo_close_mac(xnb_t *xnbp, boolean_t locked)
381 381 {
382 382 xnbo_t *xnbop = xnbp->xnb_flavour_data;
383 383 xmca_t *loop;
384 384
385 385 ASSERT(!locked || MUTEX_HELD(&xnbp->xnb_state_lock));
386 386
387 387 if (xnbop->o_mh == NULL)
388 388 return;
389 389
390 390 if (xnbop->o_running)
391 391 xnbop->o_running = B_FALSE;
392 392
393 393 if (!locked)
394 394 mutex_enter(&xnbp->xnb_state_lock);
395 395 loop = xnbop->o_mca;
396 396 xnbop->o_mca = NULL;
397 397 if (!locked)
398 398 mutex_exit(&xnbp->xnb_state_lock);
399 399
400 400 while (loop != NULL) {
401 401 xmca_t *next = loop->next;
402 402
403 403 DTRACE_PROBE3(mcast_remove,
404 404 (char *), "close",
405 405 (void *), xnbp,
406 406 (etheraddr_t *), loop->addr);
407 407 (void) mac_multicast_remove(xnbop->o_mch, loop->addr);
408 408 kmem_free(loop, sizeof (*loop));
409 409 loop = next;
410 410 }
411 411
412 412 if (xnbop->o_promiscuous) {
413 413 if (xnbop->o_mphp != NULL) {
414 414 mac_promisc_remove(xnbop->o_mphp);
415 415 xnbop->o_mphp = NULL;
416 416 }
417 417 xnbop->o_promiscuous = B_FALSE;
418 418 } else {
419 419 if (xnbop->o_mch != NULL)
420 420 mac_rx_clear(xnbop->o_mch);
421 421 }
422 422
423 423 if (xnbop->o_mah != NULL) {
424 424 (void) mac_unicast_remove(xnbop->o_mch, xnbop->o_mah);
425 425 xnbop->o_mah = NULL;
426 426 }
427 427
428 428 if (xnbop->o_mch != NULL) {
429 429 mac_client_close(xnbop->o_mch, 0);
430 430 xnbop->o_mch = NULL;
431 431 }
432 432
433 433 mac_close(xnbop->o_mh);
434 434 xnbop->o_mh = NULL;
435 435 }
436 436
437 437 /*
438 438 * Hotplug has completed and we are connected to the peer. We have all
439 439 * the information we need to exchange traffic, so open the MAC device
440 440 * and configure it appropriately.
441 441 */
442 442 static boolean_t
443 443 xnbo_start_connect(xnb_t *xnbp)
444 444 {
445 445 xnbo_t *xnbop = xnbp->xnb_flavour_data;
446 446
447 447 return (xnbo_open_mac(xnbp, xnbop->o_link_name));
448 448 }
449 449
450 450 /*
451 451 * The guest has successfully synchronize with this instance. We read
452 452 * the configuration of the guest from xenstore to check whether the
453 453 * guest requests multicast control. If not (the default) we make a
454 454 * note that the MAC device needs to be used in promiscious mode.
455 455 */
456 456 static boolean_t
457 457 xnbo_peer_connected(xnb_t *xnbp)
458 458 {
459 459 char *oename;
460 460 int request;
461 461 xnbo_t *xnbop = xnbp->xnb_flavour_data;
462 462
463 463 oename = xvdi_get_oename(xnbp->xnb_devinfo);
464 464
465 465 if (xenbus_scanf(XBT_NULL, oename,
466 466 "request-multicast-control", "%d", &request) != 0)
467 467 request = 0;
468 468 xnbop->o_multicast_control = (request > 0);
469 469
470 470 return (B_TRUE);
471 471 }
472 472
473 473 /*
474 474 * The guest domain has closed down the inter-domain connection. We
475 475 * close the underlying MAC device.
476 476 */
477 477 static void
478 478 xnbo_peer_disconnected(xnb_t *xnbp)
479 479 {
480 480 xnbo_close_mac(xnbp);
481 481 }
482 482
483 483 /*
484 484 * The hotplug script has completed. We read information from xenstore
485 485 * about our configuration, most notably the name of the MAC device we
486 486 * should use.
487 487 */
488 488 static boolean_t
489 489 xnbo_hotplug_connected(xnb_t *xnbp)
490 490 {
491 491 char *xsname;
492 492 xnbo_t *xnbop = xnbp->xnb_flavour_data;
493 493 int need;
494 494
495 495 xsname = xvdi_get_xsname(xnbp->xnb_devinfo);
496 496
497 497 if (xenbus_scanf(XBT_NULL, xsname,
498 498 "nic", "%s", xnbop->o_link_name) != 0) {
499 499 cmn_err(CE_WARN, "xnbo_connect: "
500 500 "cannot read nic name from %s", xsname);
501 501 return (B_FALSE);
502 502 }
503 503
504 504 if (xenbus_scanf(XBT_NULL, xsname,
505 505 "SUNW-need-rx-filter", "%d", &need) != 0)
506 506 need = 0;
507 507 xnbop->o_need_rx_filter = (need > 0);
508 508
509 509 if (xenbus_scanf(XBT_NULL, xsname,
510 510 "SUNW-need-set-physaddr", "%d", &need) != 0)
511 511 need = 0;
512 512 xnbop->o_need_setphysaddr = (need > 0);
513 513
514 514 return (B_TRUE);
515 515 }
516 516
517 517 /*
518 518 * Find the multicast address `addr', return B_TRUE if it is one that
519 519 * we receive. If `remove', remove it from the set received.
520 520 */
521 521 static boolean_t
522 522 xnbo_mcast_find(xnb_t *xnbp, ether_addr_t *addr, boolean_t remove)
523 523 {
524 524 xnbo_t *xnbop = xnbp->xnb_flavour_data;
525 525 xmca_t *prev, *del, *this;
526 526
527 527 ASSERT(MUTEX_HELD(&xnbp->xnb_state_lock));
528 528 ASSERT(xnbop->o_promiscuous == B_FALSE);
529 529
530 530 prev = del = NULL;
531 531
532 532 this = xnbop->o_mca;
533 533
534 534 while (this != NULL) {
535 535 if (bcmp(&this->addr, addr, sizeof (this->addr)) == 0) {
536 536 del = this;
537 537 if (remove) {
538 538 if (prev == NULL)
539 539 xnbop->o_mca = this->next;
540 540 else
541 541 prev->next = this->next;
542 542 }
543 543 break;
544 544 }
545 545
546 546 prev = this;
547 547 this = this->next;
548 548 }
549 549
550 550 if (del == NULL)
551 551 return (B_FALSE);
552 552
553 553 if (remove) {
554 554 DTRACE_PROBE3(mcast_remove,
555 555 (char *), "remove",
556 556 (void *), xnbp,
557 557 (etheraddr_t *), del->addr);
558 558 mac_multicast_remove(xnbop->o_mch, del->addr);
559 559 kmem_free(del, sizeof (*del));
560 560 }
561 561
562 562 return (B_TRUE);
563 563 }
564 564
565 565 /*
566 566 * Add the multicast address `addr' to the set received.
567 567 */
568 568 static boolean_t
569 569 xnbo_mcast_add(xnb_t *xnbp, ether_addr_t *addr)
570 570 {
571 571 xnbo_t *xnbop = xnbp->xnb_flavour_data;
572 572 boolean_t r = B_FALSE;
573 573
574 574 ASSERT(xnbop->o_promiscuous == B_FALSE);
575 575
576 576 mutex_enter(&xnbp->xnb_state_lock);
577 577
578 578 if (xnbo_mcast_find(xnbp, addr, B_FALSE)) {
579 579 r = B_TRUE;
580 580 } else if (mac_multicast_add(xnbop->o_mch,
581 581 (const uint8_t *)addr) == 0) {
582 582 xmca_t *mca;
583 583
584 584 DTRACE_PROBE3(mcast_add,
585 585 (char *), "add",
586 586 (void *), xnbp,
587 587 (etheraddr_t *), addr);
588 588
589 589 mca = kmem_alloc(sizeof (*mca), KM_SLEEP);
590 590 bcopy(addr, &mca->addr, sizeof (mca->addr));
591 591
592 592 mca->next = xnbop->o_mca;
593 593 xnbop->o_mca = mca;
594 594
595 595 r = B_TRUE;
596 596 }
597 597
598 598 mutex_exit(&xnbp->xnb_state_lock);
599 599
600 600 return (r);
601 601 }
602 602
603 603 /*
604 604 * Remove the multicast address `addr' from the set received.
605 605 */
606 606 static boolean_t
607 607 xnbo_mcast_del(xnb_t *xnbp, ether_addr_t *addr)
608 608 {
609 609 boolean_t r;
610 610
611 611 mutex_enter(&xnbp->xnb_state_lock);
612 612 r = xnbo_mcast_find(xnbp, addr, B_TRUE);
613 613 mutex_exit(&xnbp->xnb_state_lock);
614 614
615 615 return (r);
616 616 }
617 617
618 618 static int
619 619 xnbo_attach(dev_info_t *dip, ddi_attach_cmd_t cmd)
620 620 {
621 621 static xnb_flavour_t flavour = {
622 622 xnbo_to_mac, xnbo_peer_connected, xnbo_peer_disconnected,
623 623 xnbo_hotplug_connected, xnbo_start_connect,
624 624 xnbo_cksum_from_peer, xnbo_cksum_to_peer,
625 625 xnbo_mcast_add, xnbo_mcast_del,
626 626 };
627 627 xnbo_t *xnbop;
628 628
629 629 switch (cmd) {
630 630 case DDI_ATTACH:
631 631 break;
632 632 case DDI_RESUME:
633 633 return (DDI_SUCCESS);
634 634 default:
635 635 return (DDI_FAILURE);
636 636 }
637 637
638 638 xnbop = kmem_zalloc(sizeof (*xnbop), KM_SLEEP);
639 639
640 640 if (xnb_attach(dip, &flavour, xnbop) != DDI_SUCCESS) {
641 641 kmem_free(xnbop, sizeof (*xnbop));
642 642 return (DDI_FAILURE);
643 643 }
644 644
645 645 return (DDI_SUCCESS);
646 646 }
647 647
648 648 static int
649 649 xnbo_detach(dev_info_t *dip, ddi_detach_cmd_t cmd)
650 650 {
651 651 xnb_t *xnbp = ddi_get_driver_private(dip);
652 652 xnbo_t *xnbop = xnbp->xnb_flavour_data;
653 653
654 654 switch (cmd) {
655 655 case DDI_DETACH:
656 656 break;
657 657 case DDI_SUSPEND:
658 658 return (DDI_SUCCESS);
659 659 default:
660 660 return (DDI_FAILURE);
661 661 }
662 662
663 663 mutex_enter(&xnbp->xnb_tx_lock);
664 664 mutex_enter(&xnbp->xnb_rx_lock);
665 665
666 666 if (!xnbp->xnb_detachable || xnbp->xnb_connected ||
667 667 (xnbp->xnb_tx_buf_count > 0)) {
668 668 mutex_exit(&xnbp->xnb_rx_lock);
669 669 mutex_exit(&xnbp->xnb_tx_lock);
670 670
671 671 return (DDI_FAILURE);
672 672 }
673 673
674 674 mutex_exit(&xnbp->xnb_rx_lock);
675 675 mutex_exit(&xnbp->xnb_tx_lock);
676 676
677 677 xnbo_close_mac(xnbp);
678 678 kmem_free(xnbop, sizeof (*xnbop));
679 679
680 680 xnb_detach(dip);
681 681
682 682 return (DDI_SUCCESS);
683 683 }
684 684
685 685 static struct cb_ops cb_ops = {
686 686 nulldev, /* open */
687 687 nulldev, /* close */
688 688 nodev, /* strategy */
689 689 nodev, /* print */
690 690 nodev, /* dump */
691 691 nodev, /* read */
692 692 nodev, /* write */
693 693 nodev, /* ioctl */
694 694 nodev, /* devmap */
695 695 nodev, /* mmap */
696 696 nodev, /* segmap */
697 697 nochpoll, /* poll */
698 698 ddi_prop_op, /* cb_prop_op */
699 699 0, /* streamtab */
700 700 D_NEW | D_MP | D_64BIT /* Driver compatibility flag */
701 701 };
702 702
703 703 static struct dev_ops ops = {
704 704 DEVO_REV, /* devo_rev */
705 705 0, /* devo_refcnt */
706 706 nulldev, /* devo_getinfo */
707 707 nulldev, /* devo_identify */
708 708 nulldev, /* devo_probe */
709 709 xnbo_attach, /* devo_attach */
710 710 xnbo_detach, /* devo_detach */
711 711 nodev, /* devo_reset */
712 712 &cb_ops, /* devo_cb_ops */
↓ open down ↓ |
712 lines elided |
↑ open up ↑ |
713 713 (struct bus_ops *)0, /* devo_bus_ops */
714 714 NULL, /* devo_power */
715 715 ddi_quiesce_not_needed, /* devo_quiesce */
716 716 };
717 717
718 718 static struct modldrv modldrv = {
719 719 &mod_driverops, "xnbo driver", &ops,
720 720 };
721 721
722 722 static struct modlinkage modlinkage = {
723 - MODREV_1, &modldrv, NULL
723 + MODREV_1, { &modldrv, NULL }
724 724 };
725 725
726 726 int
727 727 _init(void)
728 728 {
729 729 return (mod_install(&modlinkage));
730 730 }
731 731
732 732 int
733 733 _info(struct modinfo *modinfop)
734 734 {
735 735 return (mod_info(&modlinkage, modinfop));
736 736 }
737 737
738 738 int
739 739 _fini(void)
740 740 {
741 741 return (mod_remove(&modlinkage));
742 742 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX