Lines Matching refs:dkp
72 #define DKTP_DATA (dkp->dk_tgobjp)->tg_data
73 #define DKTP_EXT (dkp->dk_tgobjp)->tg_ext
95 static int cmdk_create_obj(dev_info_t *dip, struct cmdk *dkp);
96 static void cmdk_destroy_obj(dev_info_t *dip, struct cmdk *dkp);
104 static void cmdk_bbh_reopen(struct cmdk *dkp);
108 static void cmdk_bbh_close(struct cmdk *dkp);
109 static void cmdk_bbh_setalts_idx(struct cmdk *dkp);
164 static void cmdk_setup_pm(dev_info_t *dip, struct cmdk *dkp);
221 static void cmdk_devid_setup(struct cmdk *dkp);
222 static int cmdk_devid_modser(struct cmdk *dkp);
223 static int cmdk_get_modser(struct cmdk *dkp, int ioccmd, char *buf, int len);
224 static int cmdk_devid_fabricate(struct cmdk *dkp);
225 static int cmdk_devid_read(struct cmdk *dkp);
234 cmdk_isopen(struct cmdk *dkp, dev_t dev)
239 ASSERT(MUTEX_HELD((&dkp->dk_mutex)));
245 if (dkp->dk_open_lyr[part] != 0)
248 if (dkp->dk_open_reg[otyp] & partbit)
293 struct cmdk *dkp;
305 if ((dkp = ddi_get_soft_state(cmdk_state, instance)) == NULL)
308 mutex_init(&dkp->dk_mutex, NULL, MUTEX_DRIVER, NULL);
309 rw_init(&dkp->dk_bbh_mutex, NULL, RW_DRIVER, NULL);
310 dkp->dk_dip = dip;
311 mutex_enter(&dkp->dk_mutex);
313 dkp->dk_dev = makedevice(ddi_driver_major(dip),
317 if (cmdk_create_obj(dip, dkp) != DDI_SUCCESS) {
318 mutex_exit(&dkp->dk_mutex);
319 mutex_destroy(&dkp->dk_mutex);
320 rw_destroy(&dkp->dk_bbh_mutex);
329 cmdk_destroy_obj(dip, dkp); /* dadk/strategy linkage */
330 mutex_exit(&dkp->dk_mutex);
331 mutex_destroy(&dkp->dk_mutex);
332 rw_destroy(&dkp->dk_bbh_mutex);
339 mutex_exit(&dkp->dk_mutex);
352 struct cmdk *dkp;
365 if (!(dkp = ddi_get_soft_state(cmdk_state, instance)))
368 dkp->dk_pm_level = CMDK_SPINDLE_UNINIT;
369 mutex_init(&dkp->dk_mutex, NULL, MUTEX_DRIVER, NULL);
371 mutex_enter(&dkp->dk_mutex);
401 dkp->dk_flag |= CMDK_TGDK_OPEN;
403 cmlb_alloc_handle((cmlb_handle_t *)&dkp->dk_cmlbhandle);
412 dkp->dk_cmlbhandle,
417 (void) cmlb_validate(dkp->dk_cmlbhandle, 0, 0);
420 cmdk_bbh_reopen(dkp);
423 cmdk_devid_setup(dkp);
430 mutex_exit(&dkp->dk_mutex);
443 mutex_init(&dkp->dk_pm_mutex, NULL, MUTEX_DRIVER, NULL);
444 cv_init(&dkp->dk_suspend_cv, NULL, CV_DRIVER, NULL);
445 cmdk_setup_pm(dip, dkp);
450 cmlb_free_handle(&dkp->dk_cmlbhandle);
453 cmdk_destroy_obj(dip, dkp);
454 rw_destroy(&dkp->dk_bbh_mutex);
455 mutex_exit(&dkp->dk_mutex);
456 mutex_destroy(&dkp->dk_mutex);
467 struct cmdk *dkp;
492 dkp = ddi_get_soft_state(cmdk_state, instance);
493 if (!dkp)
495 if (dkp->dk_flag & CMDK_OPEN)
500 if (!(dkp = ddi_get_soft_state(cmdk_state, instance)))
503 mutex_enter(&dkp->dk_mutex);
510 if (dkp->dk_flag & CMDK_TGDK_OPEN) {
511 dkp->dk_flag &= ~CMDK_TGDK_OPEN;
515 cmlb_detach(dkp->dk_cmlbhandle, 0);
516 cmlb_free_handle(&dkp->dk_cmlbhandle);
519 cmdk_destroy_obj(dip, dkp); /* dadk/strategy linkage */
524 if (dkp->dk_devid) {
525 ddi_devid_free(dkp->dk_devid);
526 dkp->dk_devid = NULL;
529 mutex_exit(&dkp->dk_mutex);
530 mutex_destroy(&dkp->dk_mutex);
531 rw_destroy(&dkp->dk_bbh_mutex);
532 mutex_destroy(&dkp->dk_pm_mutex);
533 cv_destroy(&dkp->dk_suspend_cv);
546 struct cmdk *dkp;
559 if (!(dkp = ddi_get_soft_state(cmdk_state, instance)))
561 *result = (void *) dkp->dk_dip;
576 cmdk_setup_pm(dev_info_t *dip, struct cmdk *dkp)
592 mutex_enter(&dkp->dk_pm_mutex);
593 dkp->dk_pm_level = CMDK_SPINDLE_ON;
594 dkp->dk_pm_is_enabled = 1;
595 mutex_exit(&dkp->dk_pm_mutex);
597 mutex_enter(&dkp->dk_pm_mutex);
598 dkp->dk_pm_level = CMDK_SPINDLE_OFF;
599 dkp->dk_pm_is_enabled = 0;
600 mutex_exit(&dkp->dk_pm_mutex);
603 mutex_enter(&dkp->dk_pm_mutex);
604 dkp->dk_pm_level = CMDK_SPINDLE_UNINIT;
605 dkp->dk_pm_is_enabled = 0;
606 mutex_exit(&dkp->dk_pm_mutex);
617 struct cmdk *dkp;
622 if (!(dkp = ddi_get_soft_state(cmdk_state, instance)))
624 mutex_enter(&dkp->dk_mutex);
625 if (dkp->dk_flag & CMDK_SUSPEND) {
626 mutex_exit(&dkp->dk_mutex);
629 dkp->dk_flag |= CMDK_SUSPEND;
635 dkp->dk_flag &= ~CMDK_SUSPEND;
636 cv_broadcast(&dkp->dk_suspend_cv);
637 mutex_exit(&dkp->dk_mutex);
642 mutex_exit(&dkp->dk_mutex);
653 struct cmdk *dkp;
657 if (!(dkp = ddi_get_soft_state(cmdk_state, instance)))
659 mutex_enter(&dkp->dk_mutex);
660 if (!(dkp->dk_flag & CMDK_SUSPEND)) {
661 mutex_exit(&dkp->dk_mutex);
664 dkp->dk_pm_level = CMDK_SPINDLE_ON;
665 dkp->dk_flag &= ~CMDK_SUSPEND;
666 cv_broadcast(&dkp->dk_suspend_cv);
667 mutex_exit(&dkp->dk_mutex);
683 struct cmdk *dkp;
687 if (!(dkp = ddi_get_soft_state(cmdk_state, instance)) ||
693 mutex_enter(&dkp->dk_pm_mutex);
694 if (dkp->dk_pm_is_enabled && dkp->dk_pm_level == level) {
695 mutex_exit(&dkp->dk_pm_mutex);
698 mutex_exit(&dkp->dk_pm_mutex);
705 mutex_enter(&dkp->dk_pm_mutex);
706 dkp->dk_pm_level = level;
707 mutex_exit(&dkp->dk_pm_mutex);
715 struct cmdk *dkp;
722 dkp = ddi_get_soft_state(cmdk_state, ddi_get_instance(dip));
723 if (dkp == NULL)
727 return (cmlb_prop_op(dkp->dk_cmlbhandle,
739 struct cmdk *dkp;
750 if (!(dkp = ddi_get_soft_state(cmdk_state, instance)) || (blkno < 0))
754 dkp->dk_cmlbhandle,
871 struct cmdk *dkp;
875 if (!(dkp = ddi_get_soft_state(cmdk_state, instance)))
878 mutex_enter(&dkp->dk_mutex);
879 while (dkp->dk_flag & CMDK_SUSPEND) {
880 cv_wait(&dkp->dk_suspend_cv, &dkp->dk_mutex);
882 mutex_exit(&dkp->dk_mutex);
912 info->dki_cnum = ddi_get_instance(ddi_get_parent(dkp->dk_dip));
914 ddi_get_name(ddi_get_parent(dkp->dk_dip)));
917 info->dki_unit = ddi_get_instance(dkp->dk_dip);
918 devp = ddi_get_driver_private(dkp->dk_dip);
920 (void) strcpy(info->dki_dname, ddi_driver_name(dkp->dk_dip));
951 if (cmlb_validate(dkp->dk_cmlbhandle, 0, 0) != 0)
954 if (cmlb_partinfo(dkp->dk_cmlbhandle, CMDKPART(dev),
993 cmdk_bbh_reopen(dkp);
1017 rc = cmlb_ioctl(dkp->dk_cmlbhandle, dev, cmd, arg, flag,
1020 cmdk_devid_setup(dkp);
1067 struct cmdk *dkp;
1072 if (!(dkp = ddi_get_soft_state(cmdk_state, instance)) ||
1076 mutex_enter(&dkp->dk_mutex);
1079 ASSERT(cmdk_isopen(dkp, dev));
1080 if (!(dkp->dk_flag & CMDK_OPEN)) {
1081 mutex_exit(&dkp->dk_mutex);
1085 while (dkp->dk_flag & CMDK_SUSPEND) {
1086 cv_wait(&dkp->dk_suspend_cv, &dkp->dk_mutex);
1094 ASSERT(dkp->dk_open_lyr[part] > 0);
1095 if (dkp->dk_open_lyr[part])
1096 dkp->dk_open_lyr[part]--;
1098 ASSERT((dkp->dk_open_reg[otyp] & partbit) != 0);
1099 dkp->dk_open_reg[otyp] &= ~partbit;
1101 dkp->dk_open_exl &= ~partbit;
1104 if (dkp->dk_open_lyr[i] != 0) {
1111 if (dkp->dk_open_reg[i] != 0) {
1116 mutex_exit(&dkp->dk_mutex);
1119 cmlb_invalidate(dkp->dk_cmlbhandle, 0);
1132 struct cmdk *dkp;
1139 if (!(dkp = ddi_get_soft_state(cmdk_state, instance)))
1145 mutex_enter(&dkp->dk_mutex);
1146 while (dkp->dk_flag & CMDK_SUSPEND) {
1147 cv_wait(&dkp->dk_suspend_cv, &dkp->dk_mutex);
1149 mutex_exit(&dkp->dk_mutex);
1155 mutex_enter(&dkp->dk_mutex);
1157 if (cmlb_validate(dkp->dk_cmlbhandle, 0, 0) != 0) {
1161 mutex_exit(&dkp->dk_mutex);
1164 } else if (cmlb_partinfo(dkp->dk_cmlbhandle, part, &p_lblkcnt,
1168 mutex_exit(&dkp->dk_mutex);
1174 mutex_exit(&dkp->dk_mutex);
1180 mutex_exit(&dkp->dk_mutex);
1185 if (dkp->dk_open_exl & partbit)
1190 if (dkp->dk_open_lyr[part])
1193 if (dkp->dk_open_reg[i] & partbit)
1199 dkp->dk_flag |= CMDK_OPEN;
1201 dkp->dk_open_lyr[part]++;
1203 dkp->dk_open_reg[otyp] |= partbit;
1205 dkp->dk_open_exl |= partbit;
1207 mutex_exit(&dkp->dk_mutex);
1211 mutex_exit(&dkp->dk_mutex);
1266 struct cmdk *dkp;
1269 if (!(dkp = ddi_get_soft_state(cmdk_state, instance)))
1272 mutex_enter(&dkp->dk_mutex);
1273 while (dkp->dk_flag & CMDK_SUSPEND) {
1274 cv_wait(&dkp->dk_suspend_cv, &dkp->dk_mutex);
1276 mutex_exit(&dkp->dk_mutex);
1285 struct cmdk *dkp;
1288 if (!(dkp = ddi_get_soft_state(cmdk_state, instance)))
1291 mutex_enter(&dkp->dk_mutex);
1292 while (dkp->dk_flag & CMDK_SUSPEND) {
1293 cv_wait(&dkp->dk_suspend_cv, &dkp->dk_mutex);
1295 mutex_exit(&dkp->dk_mutex);
1307 struct cmdk *dkp;
1313 if (cmdk_indump || !(dkp = ddi_get_soft_state(cmdk_state, instance)) ||
1321 mutex_enter(&dkp->dk_mutex);
1322 ASSERT(cmdk_isopen(dkp, bp->b_edev));
1323 while (dkp->dk_flag & CMDK_SUSPEND) {
1324 cv_wait(&dkp->dk_suspend_cv, &dkp->dk_mutex);
1326 mutex_exit(&dkp->dk_mutex);
1335 if (cmlb_partinfo(dkp->dk_cmlbhandle, CMDKPART(bp->b_edev),
1364 cmdk_create_obj(dev_info_t *dip, struct cmdk *dkp)
1374 ASSERT(mutex_owned(&dkp->dk_mutex));
1414 /* populate bbh_obj object stored in dkp */
1415 dkp->dk_bbh_obj.bbh_data = dkp;
1416 dkp->dk_bbh_obj.bbh_ops = &cmdk_bbh_ops;
1419 dkp->dk_tgobjp = (opaque_t)dadk_create();
1422 (void) dadk_init(DKTP_DATA, devp, flcobjp, queobjp, &dkp->dk_bbh_obj,
1429 cmdk_destroy_obj(dev_info_t *dip, struct cmdk *dkp)
1436 ASSERT(mutex_owned(&dkp->dk_mutex));
1438 (void) dadk_free((dkp->dk_tgobjp));
1439 dkp->dk_tgobjp = NULL;
1465 struct cmdk *dkp;
1471 dkp = ddi_get_soft_state(cmdk_state, ddi_get_instance(dip));
1472 if (dkp == NULL)
1507 struct cmdk *dkp;
1511 dkp = ddi_get_soft_state(cmdk_state, ddi_get_instance(dip));
1512 if (dkp == NULL)
1604 cmdk_devid_setup(struct cmdk *dkp)
1611 if (dkp->dk_devid != NULL)
1615 rc = cmdk_devid_modser(dkp);
1618 rc = cmdk_devid_read(dkp);
1622 rc = cmdk_devid_fabricate(dkp);
1627 (void) ddi_devid_register(dkp->dk_dip, dkp->dk_devid);
1636 cmdk_devid_modser(struct cmdk *dkp)
1647 modlen = cmdk_get_modser(dkp, DIOCTL_GETMODEL, hwid, CMDK_HWIDLEN);
1653 serlen = cmdk_get_modser(dkp, DIOCTL_GETSERIAL,
1662 rc = ddi_devid_init(dkp->dk_dip, DEVID_ATA_SERIAL, modlen + serlen,
1663 hwid, &dkp->dk_devid);
1677 cmdk_get_modser(struct cmdk *dkp, int ioccmd, char *buf, int len)
1690 dkp->dk_dev,
1724 cmdk_devid_read(struct cmdk *dkp)
1734 if (cmlb_get_devid_block(dkp->dk_cmlbhandle, &blk, 0))
1765 dkp->dk_devid = kmem_alloc(sz, KM_SLEEP);
1766 bcopy(dkdevidp->dkd_devid, dkp->dk_devid, sz);
1782 cmdk_devid_fabricate(struct cmdk *dkp)
1792 if (ddi_devid_init(dkp->dk_dip, DEVID_FAB, 0, NULL, &devid) !=
1796 if (cmlb_get_devid_block(dkp->dk_cmlbhandle, &blk, 0)) {
1831 dkp->dk_devid = devid;
1846 cmdk_bbh_free_alts(struct cmdk *dkp)
1848 if (dkp->dk_alts_hdl) {
1849 (void) dadk_iob_free(DKTP_DATA, dkp->dk_alts_hdl);
1850 kmem_free(dkp->dk_slc_cnt,
1852 dkp->dk_alts_hdl = NULL;
1857 cmdk_bbh_reopen(struct cmdk *dkp)
1873 dkp->dk_cmlbhandle,
1927 rw_enter(&dkp->dk_bbh_mutex, RW_WRITER);
1930 if (dkp->dk_slc_cnt == NULL) {
1931 dkp->dk_slc_cnt = kmem_alloc(NDKMAP *
1934 dkp->dk_slc_ent = (struct alts_ent **)(dkp->dk_slc_cnt + NDKMAP);
1937 if (dkp->dk_alts_hdl) {
1938 (void) dadk_iob_free(DKTP_DATA, dkp->dk_alts_hdl);
1939 dkp->dk_alts_hdl = NULL;
1940 dkp->dk_altused = 0;
1944 dkp->dk_alts_hdl = handle;
1945 dkp->dk_altused = altused;
1957 dkp->dk_cmlbhandle,
1967 dkp->dk_slc_cnt[i] = 0;
1979 dkp->dk_slc_ent[i] = enttblp + j;
1983 dkp->dk_slc_cnt[i] += 1;
1987 rw_exit(&dkp->dk_bbh_mutex);
1991 rw_enter(&dkp->dk_bbh_mutex, RW_WRITER);
1993 if (handle && handle != dkp->dk_alts_hdl)
1996 if (dkp->dk_alts_hdl) {
1997 (void) dadk_iob_free(DKTP_DATA, dkp->dk_alts_hdl);
1998 dkp->dk_alts_hdl = NULL;
2001 rw_exit(&dkp->dk_bbh_mutex);
2051 struct cmdk *dkp = (struct cmdk *)bbh_data;
2073 if (!dkp->dk_alts_hdl) {
2077 rw_enter(&dkp->dk_bbh_mutex, RW_READER);
2079 if (dkp->dk_alts_hdl == NULL) {
2080 rw_exit(&dkp->dk_bbh_mutex);
2084 alts_used = dkp->dk_slc_cnt[part];
2086 rw_exit(&dkp->dk_bbh_mutex);
2089 altp = dkp->dk_slc_ent[part];
2098 rw_exit(&dkp->dk_bbh_mutex);
2114 rw_exit(&dkp->dk_bbh_mutex);
2132 altp = dkp->dk_slc_ent[part];
2183 rw_exit(&dkp->dk_bbh_mutex);