587 /*
588 * Destroy object cache.
589 */
590 kmem_cache_destroy(str_cachep);
591 mod_hash_destroy_idhash(str_hashp);
592 return (0);
593 }
594
595 /*
596 * Create a new dld_str_t object.
597 */
598 dld_str_t *
599 dld_str_create(queue_t *rq, uint_t type, major_t major, t_uscalar_t style)
600 {
601 dld_str_t *dsp;
602 int err;
603
604 /*
605 * Allocate an object from the cache.
606 */
607 atomic_add_32(&str_count, 1);
608 dsp = kmem_cache_alloc(str_cachep, KM_SLEEP);
609
610 /*
611 * Allocate the dummy mblk for flow-control.
612 */
613 dsp->ds_tx_flow_mp = allocb(1, BPRI_HI);
614 if (dsp->ds_tx_flow_mp == NULL) {
615 kmem_cache_free(str_cachep, dsp);
616 atomic_add_32(&str_count, -1);
617 return (NULL);
618 }
619 dsp->ds_type = type;
620 dsp->ds_major = major;
621 dsp->ds_style = style;
622
623 /*
624 * Initialize the queue pointers.
625 */
626 ASSERT(RD(rq) == rq);
627 dsp->ds_rq = rq;
628 dsp->ds_wq = WR(rq);
629 rq->q_ptr = WR(rq)->q_ptr = (void *)dsp;
630
631 /*
632 * We want explicit control over our write-side STREAMS queue
633 * where the dummy mblk gets added/removed for flow-control.
634 */
635 noenable(WR(rq));
636
693 ASSERT(dsp->ds_rx == NULL);
694 ASSERT(dsp->ds_rx_arg == NULL);
695 ASSERT(dsp->ds_next == NULL);
696 ASSERT(dsp->ds_head == NULL);
697
698 /*
699 * Free the dummy mblk if exists.
700 */
701 if (dsp->ds_tx_flow_mp != NULL) {
702 freeb(dsp->ds_tx_flow_mp);
703 dsp->ds_tx_flow_mp = NULL;
704 }
705
706 (void) mod_hash_remove(str_hashp, STR_HASH_KEY(dsp->ds_minor), &val);
707 ASSERT(dsp == (dld_str_t *)val);
708
709 /*
710 * Free the object back to the cache.
711 */
712 kmem_cache_free(str_cachep, dsp);
713 atomic_add_32(&str_count, -1);
714 }
715
716 /*
717 * kmem_cache contructor function: see kmem_cache_create(9f).
718 */
719 /*ARGSUSED*/
720 static int
721 str_constructor(void *buf, void *cdrarg, int kmflags)
722 {
723 dld_str_t *dsp = buf;
724
725 bzero(buf, sizeof (dld_str_t));
726
727 /*
728 * Allocate a new minor number.
729 */
730 if ((dsp->ds_minor = mac_minor_hold(kmflags == KM_SLEEP)) == 0)
731 return (-1);
732
733 /*
|
587 /*
588 * Destroy object cache.
589 */
590 kmem_cache_destroy(str_cachep);
591 mod_hash_destroy_idhash(str_hashp);
592 return (0);
593 }
594
595 /*
596 * Create a new dld_str_t object.
597 */
598 dld_str_t *
599 dld_str_create(queue_t *rq, uint_t type, major_t major, t_uscalar_t style)
600 {
601 dld_str_t *dsp;
602 int err;
603
604 /*
605 * Allocate an object from the cache.
606 */
607 atomic_inc_32(&str_count);
608 dsp = kmem_cache_alloc(str_cachep, KM_SLEEP);
609
610 /*
611 * Allocate the dummy mblk for flow-control.
612 */
613 dsp->ds_tx_flow_mp = allocb(1, BPRI_HI);
614 if (dsp->ds_tx_flow_mp == NULL) {
615 kmem_cache_free(str_cachep, dsp);
616 atomic_dec_32(&str_count);
617 return (NULL);
618 }
619 dsp->ds_type = type;
620 dsp->ds_major = major;
621 dsp->ds_style = style;
622
623 /*
624 * Initialize the queue pointers.
625 */
626 ASSERT(RD(rq) == rq);
627 dsp->ds_rq = rq;
628 dsp->ds_wq = WR(rq);
629 rq->q_ptr = WR(rq)->q_ptr = (void *)dsp;
630
631 /*
632 * We want explicit control over our write-side STREAMS queue
633 * where the dummy mblk gets added/removed for flow-control.
634 */
635 noenable(WR(rq));
636
693 ASSERT(dsp->ds_rx == NULL);
694 ASSERT(dsp->ds_rx_arg == NULL);
695 ASSERT(dsp->ds_next == NULL);
696 ASSERT(dsp->ds_head == NULL);
697
698 /*
699 * Free the dummy mblk if exists.
700 */
701 if (dsp->ds_tx_flow_mp != NULL) {
702 freeb(dsp->ds_tx_flow_mp);
703 dsp->ds_tx_flow_mp = NULL;
704 }
705
706 (void) mod_hash_remove(str_hashp, STR_HASH_KEY(dsp->ds_minor), &val);
707 ASSERT(dsp == (dld_str_t *)val);
708
709 /*
710 * Free the object back to the cache.
711 */
712 kmem_cache_free(str_cachep, dsp);
713 atomic_dec_32(&str_count);
714 }
715
716 /*
717 * kmem_cache contructor function: see kmem_cache_create(9f).
718 */
719 /*ARGSUSED*/
720 static int
721 str_constructor(void *buf, void *cdrarg, int kmflags)
722 {
723 dld_str_t *dsp = buf;
724
725 bzero(buf, sizeof (dld_str_t));
726
727 /*
728 * Allocate a new minor number.
729 */
730 if ((dsp->ds_minor = mac_minor_hold(kmflags == KM_SLEEP)) == 0)
731 return (-1);
732
733 /*
|