10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*7875SChris.Horne@Sun.COM * Common Development and Distribution License (the "License").
6*7875SChris.Horne@Sun.COM * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
210Sstevel@tonic-gate /*
22*7875SChris.Horne@Sun.COM * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
230Sstevel@tonic-gate * Use is subject to license terms.
240Sstevel@tonic-gate */
250Sstevel@tonic-gate
260Sstevel@tonic-gate #include <sys/note.h>
270Sstevel@tonic-gate
280Sstevel@tonic-gate /*
290Sstevel@tonic-gate * Generic SCSI Host Bus Adapter interface implementation
300Sstevel@tonic-gate */
310Sstevel@tonic-gate
320Sstevel@tonic-gate #include <sys/dada/dada.h>
330Sstevel@tonic-gate
340Sstevel@tonic-gate extern int dcd_options;
350Sstevel@tonic-gate
360Sstevel@tonic-gate static kmutex_t dcd_hba_mutex;
370Sstevel@tonic-gate
380Sstevel@tonic-gate kmutex_t dcd_log_mutex;
390Sstevel@tonic-gate
400Sstevel@tonic-gate struct dcd_hba_inst {
410Sstevel@tonic-gate dev_info_t *inst_dip;
420Sstevel@tonic-gate dcd_hba_tran_t *inst_hba_tran;
430Sstevel@tonic-gate struct dcd_hba_inst *inst_next;
440Sstevel@tonic-gate struct dcd_hba_inst *inst_prev;
450Sstevel@tonic-gate };
460Sstevel@tonic-gate
470Sstevel@tonic-gate static struct dcd_hba_inst *dcd_hba_list = NULL;
480Sstevel@tonic-gate static struct dcd_hba_inst *dcd_hba_list_tail = NULL;
490Sstevel@tonic-gate
500Sstevel@tonic-gate
510Sstevel@tonic-gate _NOTE(READ_ONLY_DATA(dev_ops))
520Sstevel@tonic-gate
530Sstevel@tonic-gate kmutex_t dcd_flag_nointr_mutex;
540Sstevel@tonic-gate kcondvar_t dcd_flag_nointr_cv;
550Sstevel@tonic-gate
560Sstevel@tonic-gate
570Sstevel@tonic-gate /*
580Sstevel@tonic-gate * Called from _init when loading the dcd module.
590Sstevel@tonic-gate */
600Sstevel@tonic-gate void
dcd_initialize_hba_interface()610Sstevel@tonic-gate dcd_initialize_hba_interface()
620Sstevel@tonic-gate {
630Sstevel@tonic-gate mutex_init(&dcd_hba_mutex, NULL, MUTEX_DRIVER, NULL);
640Sstevel@tonic-gate mutex_init(&dcd_flag_nointr_mutex, NULL, MUTEX_DRIVER, NULL);
650Sstevel@tonic-gate cv_init(&dcd_flag_nointr_cv, NULL, CV_DRIVER, NULL);
660Sstevel@tonic-gate mutex_init(&dcd_log_mutex, NULL, MUTEX_DRIVER, NULL);
670Sstevel@tonic-gate }
680Sstevel@tonic-gate
690Sstevel@tonic-gate /*
700Sstevel@tonic-gate * Called from fini() when unloading the dcd module.
710Sstevel@tonic-gate */
720Sstevel@tonic-gate
730Sstevel@tonic-gate void
dcd_uninitialize_hba_interface()740Sstevel@tonic-gate dcd_uninitialize_hba_interface()
750Sstevel@tonic-gate {
760Sstevel@tonic-gate mutex_destroy(&dcd_hba_mutex);
770Sstevel@tonic-gate cv_destroy(&dcd_flag_nointr_cv);
780Sstevel@tonic-gate mutex_destroy(&dcd_flag_nointr_mutex);
790Sstevel@tonic-gate mutex_destroy(&dcd_log_mutex);
800Sstevel@tonic-gate }
810Sstevel@tonic-gate
820Sstevel@tonic-gate
830Sstevel@tonic-gate /*
840Sstevel@tonic-gate * Called by an HBA from _init()
850Sstevel@tonic-gate */
860Sstevel@tonic-gate /* ARGSUSED */
870Sstevel@tonic-gate int
dcd_hba_init(struct modlinkage * modlp)880Sstevel@tonic-gate dcd_hba_init(struct modlinkage *modlp)
890Sstevel@tonic-gate {
900Sstevel@tonic-gate
910Sstevel@tonic-gate return (0);
920Sstevel@tonic-gate }
930Sstevel@tonic-gate
940Sstevel@tonic-gate
950Sstevel@tonic-gate
960Sstevel@tonic-gate #ifdef NOTNEEDED
970Sstevel@tonic-gate /* ARGSUSED */
980Sstevel@tonic-gate int
dcd_hba_attach(dev_info_t * dip,ddi_dma_lim_t * hba_lim,dcd_hba_tran_t * hba_tran,int flags,void * hba_options)990Sstevel@tonic-gate dcd_hba_attach(dev_info_t *dip,
1000Sstevel@tonic-gate ddi_dma_lim_t *hba_lim,
1010Sstevel@tonic-gate dcd_hba_tran_t *hba_tran,
1020Sstevel@tonic-gate int flags,
1030Sstevel@tonic-gate void *hba_options)
1040Sstevel@tonic-gate {
1050Sstevel@tonic-gate
1060Sstevel@tonic-gate ddi_dma_attr_t hba_dma_attr;
1070Sstevel@tonic-gate
1080Sstevel@tonic-gate bzero(&hba_dma_attr, sizeof (ddi_dma_attr_t));
1090Sstevel@tonic-gate
1100Sstevel@tonic-gate hba_dma_attr.dma_attr_burstsizes = hba_lim->dlim_burstsizes;
1110Sstevel@tonic-gate hba_dma_attr.dma_attr_minxfer = hba_lim->dlim_minxfer;
1120Sstevel@tonic-gate
1130Sstevel@tonic-gate return (dcd_hba_attach_setup(dip, &hba_dma_attr, hba_tran, flags));
1140Sstevel@tonic-gate }
1150Sstevel@tonic-gate #endif
1160Sstevel@tonic-gate
1170Sstevel@tonic-gate
1180Sstevel@tonic-gate int
dcd_hba_attach(dev_info_t * dip,ddi_dma_attr_t * hba_dma_attr,dcd_hba_tran_t * hba_tran,int flags)1190Sstevel@tonic-gate dcd_hba_attach(
1200Sstevel@tonic-gate dev_info_t *dip,
1210Sstevel@tonic-gate ddi_dma_attr_t *hba_dma_attr,
1220Sstevel@tonic-gate dcd_hba_tran_t *hba_tran,
1230Sstevel@tonic-gate int flags)
1240Sstevel@tonic-gate {
1250Sstevel@tonic-gate
1260Sstevel@tonic-gate struct dcd_hba_inst *elem;
1270Sstevel@tonic-gate int value;
1280Sstevel@tonic-gate int len;
1290Sstevel@tonic-gate char *prop_name;
1300Sstevel@tonic-gate char *errmsg =
131*7875SChris.Horne@Sun.COM "dcd_hba_attach: cannott create property '%s' for %s%d\n";
1320Sstevel@tonic-gate
1330Sstevel@tonic-gate /*
1340Sstevel@tonic-gate * Link this instance into the list
1350Sstevel@tonic-gate */
1360Sstevel@tonic-gate elem = kmem_alloc(sizeof (struct dcd_hba_inst), KM_SLEEP);
1370Sstevel@tonic-gate
1380Sstevel@tonic-gate elem->inst_dip = dip;
1390Sstevel@tonic-gate elem->inst_hba_tran = hba_tran;
1400Sstevel@tonic-gate
1410Sstevel@tonic-gate mutex_enter(&dcd_hba_mutex);
1420Sstevel@tonic-gate elem->inst_next = NULL;
1430Sstevel@tonic-gate elem->inst_prev = dcd_hba_list_tail;
1440Sstevel@tonic-gate
1450Sstevel@tonic-gate if (dcd_hba_list == NULL) {
1460Sstevel@tonic-gate dcd_hba_list = elem;
1470Sstevel@tonic-gate }
1480Sstevel@tonic-gate if (dcd_hba_list_tail) {
1490Sstevel@tonic-gate dcd_hba_list_tail->inst_next = elem;
1500Sstevel@tonic-gate }
1510Sstevel@tonic-gate dcd_hba_list_tail = elem;
1520Sstevel@tonic-gate mutex_exit(&dcd_hba_mutex);
1530Sstevel@tonic-gate
1540Sstevel@tonic-gate
1550Sstevel@tonic-gate /*
1560Sstevel@tonic-gate * Save all the improtant HBA information that must be accessed
1570Sstevel@tonic-gate * later.
1580Sstevel@tonic-gate */
1590Sstevel@tonic-gate
1600Sstevel@tonic-gate hba_tran->tran_hba_dip = dip;
1610Sstevel@tonic-gate hba_tran->tran_hba_flags = flags;
1620Sstevel@tonic-gate
1630Sstevel@tonic-gate /*
1640Sstevel@tonic-gate * Note: We only need dma_attr_minxfer and dma_attr_burstsize
1650Sstevel@tonic-gate * from the DMA atrributes
1660Sstevel@tonic-gate */
1670Sstevel@tonic-gate
1680Sstevel@tonic-gate hba_tran->tran_min_xfer = hba_dma_attr->dma_attr_minxfer;
1690Sstevel@tonic-gate hba_tran->tran_min_burst_size =
170*7875SChris.Horne@Sun.COM (1<<(ddi_ffs(hba_dma_attr->dma_attr_burstsizes)-1));
1710Sstevel@tonic-gate hba_tran->tran_max_burst_size =
172*7875SChris.Horne@Sun.COM (1<<(ddi_fls(hba_dma_attr->dma_attr_burstsizes)-1));
1730Sstevel@tonic-gate
1740Sstevel@tonic-gate
1750Sstevel@tonic-gate
1760Sstevel@tonic-gate prop_name = "dcd_options";
1770Sstevel@tonic-gate len = 0;
1780Sstevel@tonic-gate if (ddi_prop_op(DDI_DEV_T_ANY, dip, PROP_LEN, 0, prop_name,
1790Sstevel@tonic-gate NULL, &len) == DDI_PROP_NOT_FOUND) {
1800Sstevel@tonic-gate value = dcd_options;
1810Sstevel@tonic-gate if (ddi_prop_update_int(DDI_MAJOR_T_UNKNOWN, dip,
1820Sstevel@tonic-gate prop_name, value) != DDI_PROP_SUCCESS) {
1830Sstevel@tonic-gate cmn_err(CE_CONT, errmsg, prop_name,
184*7875SChris.Horne@Sun.COM ddi_get_name(dip), ddi_get_instance(dip));
1850Sstevel@tonic-gate }
1860Sstevel@tonic-gate }
1870Sstevel@tonic-gate
1880Sstevel@tonic-gate
1890Sstevel@tonic-gate /*
1900Sstevel@tonic-gate * XXX : This needs to be removed when code cleanup
1910Sstevel@tonic-gate * ddi_set_driver_private(dip, (caddr_t)hba_tran);
1920Sstevel@tonic-gate */
1930Sstevel@tonic-gate #ifdef DEBUG1
1940Sstevel@tonic-gate printf("Called Set driver private with dip %x, tran %x\n",
195*7875SChris.Horne@Sun.COM dip, hba_tran);
1960Sstevel@tonic-gate #endif
1970Sstevel@tonic-gate
1980Sstevel@tonic-gate return (DDI_SUCCESS);
1990Sstevel@tonic-gate }
2000Sstevel@tonic-gate
2010Sstevel@tonic-gate
2020Sstevel@tonic-gate /*
2030Sstevel@tonic-gate * called by an HBA to detach an instance of the driver
2040Sstevel@tonic-gate */
2050Sstevel@tonic-gate
2060Sstevel@tonic-gate int
dcd_hba_detach(dev_info_t * dip)2070Sstevel@tonic-gate dcd_hba_detach(dev_info_t *dip)
2080Sstevel@tonic-gate {
2090Sstevel@tonic-gate
2100Sstevel@tonic-gate dcd_hba_tran_t *hba;
2110Sstevel@tonic-gate struct dcd_hba_inst *elem;
2120Sstevel@tonic-gate
2130Sstevel@tonic-gate hba = ddi_get_driver_private(dip);
2140Sstevel@tonic-gate ddi_set_driver_private(dip, NULL);
2150Sstevel@tonic-gate ASSERT(hba != NULL);
2160Sstevel@tonic-gate
2170Sstevel@tonic-gate hba->tran_hba_dip = (dev_info_t *)NULL;
2180Sstevel@tonic-gate hba->tran_hba_flags = 0;
2190Sstevel@tonic-gate hba->tran_min_burst_size = (uchar_t)0;
2200Sstevel@tonic-gate hba->tran_max_burst_size = (uchar_t)0;
2210Sstevel@tonic-gate
2220Sstevel@tonic-gate
2230Sstevel@tonic-gate /*
2240Sstevel@tonic-gate * Remove HBA instance from dcd_hba_list
2250Sstevel@tonic-gate */
2260Sstevel@tonic-gate
2270Sstevel@tonic-gate mutex_enter(&dcd_hba_mutex);
2280Sstevel@tonic-gate
2290Sstevel@tonic-gate for (elem = dcd_hba_list; elem != (struct dcd_hba_inst *)NULL;
230*7875SChris.Horne@Sun.COM elem = elem->inst_next) {
2310Sstevel@tonic-gate if (elem->inst_dip == dip)
2320Sstevel@tonic-gate break;
2330Sstevel@tonic-gate }
2340Sstevel@tonic-gate
2350Sstevel@tonic-gate if (elem == (struct dcd_hba_inst *)NULL) {
2360Sstevel@tonic-gate cmn_err(CE_NOTE, "dcd_hba_attach: Unknown HBA instance\n");
2370Sstevel@tonic-gate mutex_exit(&dcd_hba_mutex);
2380Sstevel@tonic-gate }
2390Sstevel@tonic-gate
2400Sstevel@tonic-gate if (elem == dcd_hba_list) {
2410Sstevel@tonic-gate dcd_hba_list = elem->inst_next;
2420Sstevel@tonic-gate dcd_hba_list->inst_prev = (struct dcd_hba_inst *)NULL;
2430Sstevel@tonic-gate } else if (elem == dcd_hba_list_tail) {
2440Sstevel@tonic-gate dcd_hba_list_tail = elem->inst_prev;
2450Sstevel@tonic-gate dcd_hba_list_tail->inst_next = (struct dcd_hba_inst *)NULL;
2460Sstevel@tonic-gate } else {
2470Sstevel@tonic-gate elem->inst_prev->inst_next = elem->inst_next;
2480Sstevel@tonic-gate elem->inst_next->inst_prev = elem->inst_prev;
2490Sstevel@tonic-gate }
2500Sstevel@tonic-gate mutex_exit(&dcd_hba_mutex);
2510Sstevel@tonic-gate
2520Sstevel@tonic-gate kmem_free(elem, sizeof (struct dcd_hba_inst));
2530Sstevel@tonic-gate
2540Sstevel@tonic-gate return (DDI_SUCCESS);
2550Sstevel@tonic-gate }
2560Sstevel@tonic-gate
2570Sstevel@tonic-gate void
dcd_hba_fini()2580Sstevel@tonic-gate dcd_hba_fini()
2590Sstevel@tonic-gate {
2600Sstevel@tonic-gate
2610Sstevel@tonic-gate }
2620Sstevel@tonic-gate
2630Sstevel@tonic-gate /* ARGSUSED */
2640Sstevel@tonic-gate dcd_hba_tran_t *
dcd_hba_tran_alloc(dev_info_t * dip,int flags)2650Sstevel@tonic-gate dcd_hba_tran_alloc(
2660Sstevel@tonic-gate dev_info_t *dip,
2670Sstevel@tonic-gate int flags)
2680Sstevel@tonic-gate {
2690Sstevel@tonic-gate
2700Sstevel@tonic-gate return (kmem_zalloc(sizeof (dcd_hba_tran_t),
271*7875SChris.Horne@Sun.COM (flags & DCD_HBA_CANSLEEP) ? KM_SLEEP: KM_NOSLEEP));
2720Sstevel@tonic-gate }
2730Sstevel@tonic-gate
2740Sstevel@tonic-gate
2750Sstevel@tonic-gate void
dcd_hba_tran_free(dcd_hba_tran_t * hba_tran)2760Sstevel@tonic-gate dcd_hba_tran_free(dcd_hba_tran_t *hba_tran)
2770Sstevel@tonic-gate {
2780Sstevel@tonic-gate
2790Sstevel@tonic-gate kmem_free(hba_tran, sizeof (dcd_hba_tran_t));
2800Sstevel@tonic-gate }
2810Sstevel@tonic-gate
2820Sstevel@tonic-gate
2830Sstevel@tonic-gate /*
2840Sstevel@tonic-gate * XXX: Do we really need the following routines.
2850Sstevel@tonic-gate */
2860Sstevel@tonic-gate
2870Sstevel@tonic-gate /*
2880Sstevel@tonic-gate * private wrapper for dcd_pkt's allocated via scsi_hba_pkt_alloc
2890Sstevel@tonic-gate */
2900Sstevel@tonic-gate
2910Sstevel@tonic-gate struct dcd_pkt_wrapper {
2920Sstevel@tonic-gate struct dcd_pkt dcd_pkt;
2930Sstevel@tonic-gate int pkt_wrapper_len;
2940Sstevel@tonic-gate };
2950Sstevel@tonic-gate
2960Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("unique per thread", dcd_pkt_wrapper))
2970Sstevel@tonic-gate
2980Sstevel@tonic-gate /*
2990Sstevel@tonic-gate * Round up all allocations so that we can gurentee
3000Sstevel@tonic-gate * long-long alignment. This is the same alignment
3010Sstevel@tonic-gate * provided by kmem_alloc().
3020Sstevel@tonic-gate */
3030Sstevel@tonic-gate
3040Sstevel@tonic-gate #define ROUNDUP(x) (((x) + 0x07) & ~0x07)
3050Sstevel@tonic-gate
3060Sstevel@tonic-gate /*
3070Sstevel@tonic-gate * Called by an HBA to allocate a dcd_pkt
3080Sstevel@tonic-gate */
3090Sstevel@tonic-gate
3100Sstevel@tonic-gate /* ARGSUSED */
3110Sstevel@tonic-gate struct dcd_pkt *
dcd_hba_pkt_alloc(struct dcd_address * ap,int cmdlen,int statuslen,int tgtlen,int hbalen,int (* callback)(caddr_t arg),caddr_t arg)3120Sstevel@tonic-gate dcd_hba_pkt_alloc(
3130Sstevel@tonic-gate struct dcd_address *ap,
3140Sstevel@tonic-gate int cmdlen,
3150Sstevel@tonic-gate int statuslen,
3160Sstevel@tonic-gate int tgtlen,
3170Sstevel@tonic-gate int hbalen,
3180Sstevel@tonic-gate int (*callback)(caddr_t arg),
3190Sstevel@tonic-gate caddr_t arg)
3200Sstevel@tonic-gate {
3210Sstevel@tonic-gate
3220Sstevel@tonic-gate struct dcd_pkt *pkt;
3230Sstevel@tonic-gate struct dcd_pkt_wrapper *hba_pkt;
3240Sstevel@tonic-gate caddr_t p;
3250Sstevel@tonic-gate int pktlen;
3260Sstevel@tonic-gate
3270Sstevel@tonic-gate
3280Sstevel@tonic-gate /*
3290Sstevel@tonic-gate * Sanity check
3300Sstevel@tonic-gate */
3310Sstevel@tonic-gate if (callback != SLEEP_FUNC && callback != NULL_FUNC) {
3320Sstevel@tonic-gate cmn_err(CE_PANIC, " dcd_hba_pkt_alloc: callback must be"
333*7875SChris.Horne@Sun.COM " either SLEEP or NULL\n");
3340Sstevel@tonic-gate }
3350Sstevel@tonic-gate
3360Sstevel@tonic-gate
3370Sstevel@tonic-gate /*
3380Sstevel@tonic-gate * Round up so everything gets allocated on long-word boundaries.
3390Sstevel@tonic-gate */
3400Sstevel@tonic-gate
3410Sstevel@tonic-gate cmdlen = ROUNDUP(cmdlen);
3420Sstevel@tonic-gate tgtlen = ROUNDUP(tgtlen);
3430Sstevel@tonic-gate hbalen = ROUNDUP(hbalen);
3440Sstevel@tonic-gate statuslen = ROUNDUP(statuslen);
345*7875SChris.Horne@Sun.COM pktlen = sizeof (struct dcd_pkt_wrapper) +
346*7875SChris.Horne@Sun.COM cmdlen + tgtlen +hbalen + statuslen;
3470Sstevel@tonic-gate
3480Sstevel@tonic-gate hba_pkt = kmem_zalloc(pktlen,
349*7875SChris.Horne@Sun.COM (callback = SLEEP_FUNC) ? KM_SLEEP: KM_NOSLEEP);
3500Sstevel@tonic-gate
3510Sstevel@tonic-gate if (hba_pkt == NULL) {
3520Sstevel@tonic-gate ASSERT(callback == NULL_FUNC);
3530Sstevel@tonic-gate return (NULL);
3540Sstevel@tonic-gate }
3550Sstevel@tonic-gate
3560Sstevel@tonic-gate /*
3570Sstevel@tonic-gate * Set up or private info on this pkt
3580Sstevel@tonic-gate */
3590Sstevel@tonic-gate hba_pkt->pkt_wrapper_len = pktlen;
3600Sstevel@tonic-gate pkt = &hba_pkt->dcd_pkt;
3610Sstevel@tonic-gate p = (caddr_t)(hba_pkt + 1);
3620Sstevel@tonic-gate
3630Sstevel@tonic-gate /*
3640Sstevel@tonic-gate * set up pointers to private data areas, cdb and status.
3650Sstevel@tonic-gate */
3660Sstevel@tonic-gate if (hbalen > 0) {
3670Sstevel@tonic-gate pkt->pkt_ha_private = (ataopaque_t)p;
3680Sstevel@tonic-gate p += hbalen;
3690Sstevel@tonic-gate }
3700Sstevel@tonic-gate
3710Sstevel@tonic-gate if (tgtlen > 0) {
3720Sstevel@tonic-gate pkt->pkt_private = (ataopaque_t)p;
3730Sstevel@tonic-gate p += tgtlen;
3740Sstevel@tonic-gate }
3750Sstevel@tonic-gate
3760Sstevel@tonic-gate if (statuslen > 0) {
3770Sstevel@tonic-gate pkt->pkt_scbp = (uchar_t *)p;
3780Sstevel@tonic-gate p += statuslen;
3790Sstevel@tonic-gate }
3800Sstevel@tonic-gate
3810Sstevel@tonic-gate if (cmdlen > 0) {
3820Sstevel@tonic-gate pkt->pkt_cdbp = (void *)p;
3830Sstevel@tonic-gate }
3840Sstevel@tonic-gate
3850Sstevel@tonic-gate /*
3860Sstevel@tonic-gate * Initialize the pkt's dcd_address
3870Sstevel@tonic-gate */
3880Sstevel@tonic-gate pkt->pkt_address = *ap;
3890Sstevel@tonic-gate #ifdef DEBUG1
390*7875SChris.Horne@Sun.COM printf("da_target %x, da_lun %x, a_hba_tran %x\n",
391*7875SChris.Horne@Sun.COM pkt->pkt_address.da_target, pkt->pkt_address.da_lun,
392*7875SChris.Horne@Sun.COM pkt->pkt_address.a_hba_tran);
393*7875SChris.Horne@Sun.COM printf("From address : da_target %x, da_lun %x, a_hba_tran %x\n",
394*7875SChris.Horne@Sun.COM ap->da_target, ap->da_lun, ap->a_hba_tran);
3950Sstevel@tonic-gate printf("Pkt %x\n", pkt);
3960Sstevel@tonic-gate
3970Sstevel@tonic-gate #endif
3980Sstevel@tonic-gate return (pkt);
3990Sstevel@tonic-gate }
4000Sstevel@tonic-gate
4010Sstevel@tonic-gate
4020Sstevel@tonic-gate /* ARGSUSED */
4030Sstevel@tonic-gate void
dcd_hba_pkt_free(struct dcd_address * ap,struct dcd_pkt * pkt)4040Sstevel@tonic-gate dcd_hba_pkt_free(
4050Sstevel@tonic-gate struct dcd_address *ap,
4060Sstevel@tonic-gate struct dcd_pkt *pkt)
4070Sstevel@tonic-gate {
4080Sstevel@tonic-gate
4090Sstevel@tonic-gate kmem_free((struct dcd_pkt_wrapper *)pkt,
410*7875SChris.Horne@Sun.COM ((struct dcd_pkt_wrapper *)pkt)->pkt_wrapper_len);
4110Sstevel@tonic-gate }
4120Sstevel@tonic-gate
4130Sstevel@tonic-gate
4140Sstevel@tonic-gate /*
4150Sstevel@tonic-gate * Called by an HBA to map strings to capability indices
4160Sstevel@tonic-gate */
4170Sstevel@tonic-gate
4180Sstevel@tonic-gate int
dcd_hba_lookup_capstr(char * capstr)4190Sstevel@tonic-gate dcd_hba_lookup_capstr(char *capstr)
4200Sstevel@tonic-gate {
4210Sstevel@tonic-gate
4220Sstevel@tonic-gate /*
4230Sstevel@tonic-gate * Capability strings, masking the '-' vs '_'.
4240Sstevel@tonic-gate */
4250Sstevel@tonic-gate static struct cap_strings {
4260Sstevel@tonic-gate char *cap_string;
4270Sstevel@tonic-gate int cap_index;
4280Sstevel@tonic-gate } cap_string[] = {
4290Sstevel@tonic-gate { "dma-max", DCD_CAP_DMA_MAX },
4300Sstevel@tonic-gate { "dma_max", DCD_CAP_DMA_MAX },
4310Sstevel@tonic-gate { "ultraata", DCD_CAP_ULTRA_ATA },
4320Sstevel@tonic-gate { "busmaster", DCD_CAP_BUS_MASTER },
4330Sstevel@tonic-gate { "overlap", DCD_CAP_OVERLAP },
4340Sstevel@tonic-gate { "parity", DCD_CAP_PARITY },
4350Sstevel@tonic-gate { "sector-size", DCD_CAP_SECTOR_SIZE },
4360Sstevel@tonic-gate { "total-sectors", DCD_CAP_TOTAL_SECTORS },
4370Sstevel@tonic-gate { "geometry", DCD_CAP_GEOMETRY },
4380Sstevel@tonic-gate { "block-mode", DCD_CAP_BLOCKMODE },
4390Sstevel@tonic-gate { "block-factor", DCD_CAP_BLOCKFACTOR },
4400Sstevel@tonic-gate { "dma-support", DCD_CAP_DMA_SUPPORT },
4410Sstevel@tonic-gate { "pio-support", DCD_CAP_PIO_SUPPORT },
4420Sstevel@tonic-gate { "lba-addressing", DCD_CAP_LBA_ADDRESSING },
4430Sstevel@tonic-gate { NULL, 0 }
4440Sstevel@tonic-gate };
4450Sstevel@tonic-gate struct cap_strings *cp;
4460Sstevel@tonic-gate
4470Sstevel@tonic-gate for (cp = cap_string; cp->cap_string != NULL; cp++) {
4480Sstevel@tonic-gate if (strcmp(cp->cap_string, capstr) == 0) {
4490Sstevel@tonic-gate return (cp->cap_index);
4500Sstevel@tonic-gate }
4510Sstevel@tonic-gate }
4520Sstevel@tonic-gate
4530Sstevel@tonic-gate return (-1);
4540Sstevel@tonic-gate }
455