Lines Matching refs:ptgt
414 static int fcp_tgt_send_plogi(struct fcp_tgt *ptgt, int *fc_status,
416 static int fcp_tgt_send_prli(struct fcp_tgt *ptgt, int *fc_status,
427 struct fcp_tgt *ptgt, fc_portmap_t *map_entry, int link_cnt,
429 static int fcp_handle_reportlun_changed(struct fcp_tgt *ptgt, int cause);
430 static int fcp_send_els(struct fcp_port *pptr, struct fcp_tgt *ptgt,
434 static void fcp_update_tgt_state(struct fcp_tgt *ptgt, int flag,
442 struct fcp_tgt *ptgt, int cmd_len, int resp_len, int data_len,
460 static struct fcp_lun *fcp_get_lun(struct fcp_tgt *ptgt,
462 static int fcp_finish_tgt(struct fcp_port *pptr, struct fcp_tgt *ptgt,
465 static void fcp_create_luns(struct fcp_tgt *ptgt, int link_cnt,
469 static int fcp_offline_target(struct fcp_port *pptr, struct fcp_tgt *ptgt,
472 struct fcp_tgt *ptgt, int link_cnt, int tgt_cnt, int flags);
473 static void fcp_offline_tgt_luns(struct fcp_tgt *ptgt, int link_cnt,
491 static int fcp_device_changed(struct fcp_port *pptr, struct fcp_tgt *ptgt,
493 static struct fcp_lun *fcp_alloc_lun(struct fcp_tgt *ptgt);
497 static void fcp_dealloc_tgt(struct fcp_tgt *ptgt);
566 struct fcp_tgt *ptgt, int lcount, int tcount, int cause);
568 struct fcp_tgt *ptgt, int lcount, int tcount, int cause);
571 static void fcp_free_target(struct fcp_tgt *ptgt);
578 struct fcp_tgt *ptgt, struct fcp_ipkt *icmd, int rval, caddr_t op);
579 static int fcp_outstanding_lun_cmds(struct fcp_tgt *ptgt);
611 static int fcp_is_reconfig_needed(struct fcp_tgt *ptgt,
1441 struct fcp_tgt *ptgt = NULL;
1573 if ((ptgt = fcp_lookup_target(pptr,
1589 mutex_enter(&ptgt->tgt_mutex);
1590 if (ptgt->tgt_state & (FCP_TGT_MARK |
1593 mutex_exit(&ptgt->tgt_mutex);
1597 if (ptgt->tgt_state & FCP_TGT_OFFLINE) {
1598 if (ptgt->tgt_icap && !ptgt->tgt_tcap) {
1603 mutex_exit(&ptgt->tgt_mutex);
1619 dev_data[i].dev_lun_cnt = ptgt->tgt_lun_cnt;
1621 mutex_exit(&ptgt->tgt_mutex);
1623 if ((plun = fcp_get_lun(ptgt, 0)) == NULL) {
1628 mutex_enter(&ptgt->tgt_mutex);
1632 mutex_exit(&ptgt->tgt_mutex);
1678 mutex_enter(&ptgt->tgt_mutex);
1690 mutex_exit(&ptgt->tgt_mutex);
1746 struct fcp_tgt *ptgt = NULL;
1828 for (ptgt = pptr->port_tgt_hash_table[i]; ptgt != NULL;
1829 ptgt = ptgt->tgt_next) {
1831 mutex_enter(&ptgt->tgt_mutex);
1834 for (plun = ptgt->tgt_lun; plun != NULL;
1853 map->d_id = ptgt->tgt_d_id;
1855 map->targetNumber = ptgt->tgt_d_id;
1875 bcopy(ptgt->tgt_node_wwn.raw_wwn,
1877 bcopy(ptgt->tgt_port_wwn.raw_wwn,
1901 mutex_exit(&ptgt->tgt_mutex);
2291 struct fcp_tgt *ptgt = NULL;
2425 ptgt = fcp_lookup_target(pptr,
2431 if (ptgt == NULL) {
2437 ptgt = fcp_port_create_tgt(pptr,
2450 if (ptgt != NULL) {
2461 mutex_enter(&ptgt->tgt_mutex);
2467 if (ptgt->tgt_state &
2475 ptgt->tgt_state |=
2483 tcount = ptgt->tgt_change_cnt;
2484 mutex_exit(&ptgt->tgt_mutex);
2510 if (!ptgt->tgt_tcap && ptgt->tgt_icap) {
2551 icmd = fcp_icmd_alloc(pptr, ptgt,
2592 ptgt = plun->lun_tgt;
2619 hp->d_id = ptgt->tgt_d_id;
2649 mutex_enter(&ptgt->tgt_mutex);
2651 if (!FCP_TGT_STATE_CHANGED(ptgt, icmd)) {
2652 mutex_exit(&ptgt->tgt_mutex);
2660 mutex_exit(&ptgt->tgt_mutex);
2688 ptgt->tgt_d_id, plun->lun_num,
2732 if (fscsi->scsi_bufstatus == STATUS_GOOD && (ptgt != NULL) &&
2736 fcp_is_reconfig_needed(ptgt, fpkt);
2741 mutex_enter(&ptgt->tgt_mutex);
2742 if (ptgt->tgt_tid == NULL) {
2751 (caddr_t)ptgt, drv_usectohz(1));
2753 ptgt->tgt_tid = tid;
2754 ptgt->tgt_state |= FCP_TGT_BUSY;
2758 mutex_exit(&ptgt->tgt_mutex);
2839 if ((ptgt != NULL) && !reconfig_pending) {
2844 mutex_enter(&ptgt->tgt_mutex);
2845 ptgt->tgt_state &= ~FCP_TGT_BUSY;
2846 mutex_exit(&ptgt->tgt_mutex);
2851 mutex_enter(&ptgt->tgt_mutex);
2852 ptgt->tgt_state &= ~FCP_TGT_BUSY;
2853 mutex_exit(&ptgt->tgt_mutex);
2861 fcp_is_reconfig_needed(struct fcp_tgt *ptgt,
2874 fcp_port_t *pptr = ptgt->tgt_port;
2901 mutex_enter(&ptgt->tgt_mutex);
2914 if (fcp_should_mask(&ptgt->tgt_port_wwn,
2930 if (num_luns && num_luns != (ptgt->tgt_lun_cnt + num_masked_luns)) {
2931 mutex_exit(&ptgt->tgt_mutex);
2953 &ptgt->tgt_port_wwn, lun_num) == TRUE)) {
2958 for (plun = ptgt->tgt_lun; plun;
2976 mutex_exit(&ptgt->tgt_mutex);
3182 struct fcp_tgt *ptgt = NULL;
3208 ptgt = fcp_alloc_tgt(pptr, &devlist, lcount);
3209 if (ptgt == NULL) {
3215 mutex_enter(&ptgt->tgt_mutex);
3217 ptgt->tgt_statec_cause = FCP_CAUSE_TGT_CHANGE;
3218 ptgt->tgt_tmp_cnt = 1;
3219 ptgt->tgt_d_id = devlist.map_did.port_id;
3220 ptgt->tgt_hard_addr =
3222 ptgt->tgt_pd_handle = devlist.map_pd;
3223 ptgt->tgt_fca_dev = NULL;
3225 bcopy(&devlist.map_nwwn, &ptgt->tgt_node_wwn.raw_wwn[0],
3227 bcopy(&devlist.map_pwwn, &ptgt->tgt_port_wwn.raw_wwn[0],
3230 mutex_exit(&ptgt->tgt_mutex);
3239 *ret_val = fcp_tgt_send_plogi(ptgt, fc_status,
3245 *ret_val = fcp_tgt_send_prli(ptgt, fc_status,
3251 return (ptgt);
3260 * Argument: ptgt Target to send the plogi to.
3273 fcp_tgt_send_plogi(struct fcp_tgt *ptgt, int *fc_status, int *fc_pkt_state,
3287 pptr = ptgt->tgt_port;
3290 tcount = ptgt->tgt_change_cnt;
3293 icmd = fcp_icmd_alloc(pptr, ptgt, sizeof (la_els_logi_t),
3329 hp->d_id = ptgt->tgt_d_id; /* dest ID */
3388 * Argument: ptgt Target to send the prli to.
3398 fcp_tgt_send_prli(struct fcp_tgt *ptgt, int *fc_status, int *fc_pkt_state,
3553 struct fcp_tgt *ptgt;
3556 ptgt = icmd->ipkt_tgt;
3562 mutex_enter(&ptgt->tgt_mutex);
3572 mutex_exit(&ptgt->tgt_mutex);
3844 struct fcp_tgt *ptgt;
3888 ptgt = plun->lun_tgt;
3889 mutex_enter(&ptgt->tgt_mutex);
3890 for (tplun = ptgt->tgt_lun; tplun != NULL; tplun =
3900 ptgt->tgt_node_state = FCP_TGT_NODE_NONE;
3909 ptgt->tgt_manual_config_only = 1;
3912 mutex_exit(&ptgt->tgt_mutex);
3976 struct fcp_tgt *ptgt = NULL;
4000 ptgt = fcp_lookup_target(pptr, (uchar_t *)bytes);
4001 if (ptgt) {
4007 mutex_enter(&ptgt->tgt_mutex);
4009 plun = ptgt->tgt_lun;
4021 mutex_exit(&ptgt->tgt_mutex);
4026 if (*rval == 0 && ptgt && plun) {
4621 struct fcp_tgt *ptgt = NULL;
4638 * (ptgt->tgt_aux_state = FCP_TGT_TAGGED).
4652 ptgt = fcp_lookup_target(pptr,
4655 if (ptgt) {
4656 map_tag[i] = ptgt->tgt_change_cnt;
4658 ptgt->tgt_aux_state = FCP_TGT_TAGGED;
4675 for (ptgt = pptr->port_tgt_hash_table[i]; ptgt != NULL;
4676 ptgt = ptgt->tgt_next) {
4677 mutex_enter(&ptgt->tgt_mutex);
4678 if ((ptgt->tgt_aux_state != FCP_TGT_TAGGED) &&
4680 !(ptgt->tgt_state & FCP_TGT_OFFLINE)) {
4681 fcp_offline_target_now(pptr, ptgt,
4682 link_cnt, ptgt->tgt_change_cnt, 0);
4684 mutex_exit(&ptgt->tgt_mutex);
4700 (void) fcp_call_finish_init_held(pptr, ptgt, link_cnt,
4719 ptgt = fcp_lookup_target(pptr,
4722 if (ptgt) {
4728 ptgt->tgt_aux_state = 0;
4736 ptgt->tgt_d_id, ptgt->tgt_state);
4756 FCP_TGT_TRACE(ptgt, map_tag[i], FCP_TGT_TRACE_1);
4758 if (fcp_handle_mapflags(pptr, ptgt, map_entry,
4759 link_cnt, (ptgt) ? map_tag[i] : 0,
4762 FCP_TGT_TRACE(ptgt, map_tag[i],
4769 if (ptgt != NULL) {
4770 FCP_TGT_TRACE(ptgt, map_tag[i],
4773 mutex_enter(&ptgt->tgt_mutex);
4774 if (!(ptgt->tgt_state & FCP_TGT_OFFLINE)) {
4779 mutex_exit(&ptgt->tgt_mutex);
4782 mutex_enter(&ptgt->tgt_mutex);
4783 while (ptgt->tgt_ipkt_cnt ||
4784 fcp_outstanding_lun_cmds(ptgt)
4786 mutex_exit(&ptgt->tgt_mutex);
4788 mutex_enter(&ptgt->tgt_mutex);
4790 mutex_exit(&ptgt->tgt_mutex);
4793 mutex_enter(&ptgt->tgt_mutex);
4795 (void) fcp_offline_target(pptr, ptgt,
4798 mutex_exit(&ptgt->tgt_mutex);
4805 if (ptgt != NULL) {
4806 FCP_TGT_TRACE(ptgt, map_tag[i],
4809 mutex_enter(&ptgt->tgt_mutex);
4810 if (!(ptgt->tgt_state & FCP_TGT_OFFLINE)) {
4811 (void) fcp_offline_target(pptr, ptgt,
4814 mutex_exit(&ptgt->tgt_mutex);
4820 if (ptgt != NULL) {
4821 FCP_TGT_TRACE(ptgt, map_tag[i],
4824 if (fcp_device_changed(pptr, ptgt,
4830 if (fcp_handle_mapflags(pptr, ptgt,
4847 (void) fcp_call_finish_init_held(pptr, ptgt, link_cnt,
4855 fcp_handle_reportlun_changed(struct fcp_tgt *ptgt, int cause)
4863 ASSERT(ptgt);
4864 pptr = ptgt->tgt_port;
4866 if ((plun = fcp_get_lun(ptgt, 0)) == NULL) {
4871 plun = fcp_alloc_lun(ptgt);
4875 " D_ID=%x", ptgt->tgt_d_id);
4881 mutex_enter(&ptgt->tgt_mutex);
4891 ptgt->tgt_lun_cnt = 1;
4892 ptgt->tgt_report_lun_cnt = 0;
4893 mutex_exit(&ptgt->tgt_mutex);
4898 ptgt->tgt_change_cnt, cause, rscn_count) != DDI_SUCCESS) {
4901 "to D_ID=%x", ptgt->tgt_d_id);
4912 * Description: This function creates a target structure if the ptgt passed
4919 * *ptgt Target structure.
4931 fcp_handle_mapflags(struct fcp_port *pptr, struct fcp_tgt *ptgt,
4951 if (ptgt == NULL) {
4954 ptgt = fcp_alloc_tgt(pptr, map_entry, link_cnt);
4957 if (ptgt == NULL) {
4962 mutex_enter(&ptgt->tgt_mutex);
4963 ptgt->tgt_statec_cause = cause;
4964 ptgt->tgt_tmp_cnt = 1;
4965 mutex_exit(&ptgt->tgt_mutex);
4973 mutex_enter(&ptgt->tgt_mutex);
4974 ptgt->tgt_d_id = map_entry->map_did.port_id;
4975 ptgt->tgt_hard_addr = map_entry->map_hard_addr.hard_addr;
4976 ptgt->tgt_pd_handle = map_entry->map_pd;
4977 ptgt->tgt_fca_dev = NULL;
4980 bcopy(&map_entry->map_nwwn, &ptgt->tgt_node_wwn.raw_wwn[0],
4982 bcopy(&map_entry->map_pwwn, &ptgt->tgt_port_wwn.raw_wwn[0],
4992 for (pseq_lun = ptgt->tgt_lun;
4997 fcp_update_tgt_state(ptgt, FCP_RESET,
4999 mutex_exit(&ptgt->tgt_mutex);
5010 ptgt->tgt_state &= ~(FCP_TGT_OFFLINE | FCP_TGT_MARK);
5011 mutex_exit(&ptgt->tgt_mutex);
5014 ret = fcp_handle_reportlun_changed(ptgt, cause);
5021 * If ptgt was NULL when this function was entered, then tgt_node_state
5025 switch (ptgt->tgt_node_state) {
5031 ptgt->tgt_node_state = FCP_TGT_NODE_ON_DEMAND;
5034 (ptgt->tgt_manual_config_only == 1) &&
5042 ptgt->tgt_node_state = FCP_TGT_NODE_ON_DEMAND;
5044 ptgt->tgt_node_state = FCP_TGT_NODE_NONE;
5058 (caddr_t)&ptgt->tgt_port_wwn.raw_wwn[0],
5059 sizeof (ptgt->tgt_port_wwn)) == 0) {
5060 ptgt->tgt_node_state = FCP_TGT_NODE_NONE;
5063 mutex_exit(&ptgt->tgt_mutex);
5071 mutex_enter(&ptgt->tgt_mutex);
5076 ptgt->tgt_state &= ~FCP_TGT_OFFLINE;
5077 ptgt->tgt_state |= (FCP_TGT_BUSY | FCP_TGT_MARK);
5079 tcount = tgt_cnt ? tgt_cnt : ptgt->tgt_change_cnt;
5082 mutex_exit(&ptgt->tgt_mutex);
5096 icmd = fcp_icmd_alloc(pptr, ptgt, alloc, alloc, 0,
5101 FCP_TGT_TRACE(ptgt, tgt_cnt, FCP_TGT_TRACE_29);
5113 if ((fcp_send_els(pptr, ptgt, icmd, opcode,
5115 FCP_TGT_TRACE(ptgt, tgt_cnt, FCP_TGT_TRACE_9);
5132 * *ptgt Target to send the ELS to.
5143 fcp_send_els(struct fcp_port *pptr, struct fcp_tgt *ptgt,
5156 ASSERT(ptgt->tgt_port == pptr);
5160 "fcp_send_els: d_id=0x%x ELS 0x%x (%s)", ptgt->tgt_d_id, opcode,
5175 icmd = fcp_icmd_alloc(pptr, ptgt, alloc, alloc, 0,
5179 FCP_TGT_TRACE(ptgt, tcount, FCP_TGT_TRACE_10);
5204 hp->d_id = ptgt->tgt_d_id; /* dest ID */
5241 if (!FCP_TGT_STATE_CHANGED(ptgt, icmd)) {
5251 FCP_TGT_TRACE(ptgt, tcount, FCP_TGT_TRACE_11);
5253 res = fcp_handle_ipkt_errors(pptr, ptgt, icmd,
5259 " for D_ID=0x%x", ptgt->tgt_d_id);
5261 FCP_TGT_TRACE(ptgt, tcount, FCP_TGT_TRACE_12);
5315 if (!FCP_TGT_STATE_CHANGED(ptgt, icmd)) {
5325 FCP_TGT_TRACE(ptgt, tcount, FCP_TGT_TRACE_13);
5327 res = fcp_handle_ipkt_errors(pptr, ptgt, icmd,
5331 FCP_TGT_TRACE(ptgt, tcount, FCP_TGT_TRACE_14);
5369 struct fcp_tgt *ptgt;
5374 for (ptgt = pptr->port_tgt_hash_table[i]; ptgt != NULL;
5375 ptgt = ptgt->tgt_next) {
5376 mutex_enter(&ptgt->tgt_mutex);
5377 fcp_update_tgt_state(ptgt, FCP_SET, state);
5378 ptgt->tgt_change_cnt++;
5379 ptgt->tgt_statec_cause = cause;
5380 ptgt->tgt_tmp_cnt = 1;
5381 ptgt->tgt_done = 0;
5382 mutex_exit(&ptgt->tgt_mutex);
5393 struct fcp_tgt *ptgt;
5398 for (ptgt = pptr->port_tgt_hash_table[i]; ptgt != NULL;
5399 ptgt = ptgt->tgt_next) {
5410 for (ptgt = pptr->port_tgt_hash_table[i]; ptgt != NULL;
5411 ptgt = ptgt->tgt_next) {
5412 (void) fcp_call_finish_init_held(pptr, ptgt,
5413 lcount, ptgt->tgt_change_cnt, cause);
5430 * Argument: *ptgt Target structure.
5437 * The mutex of the target (ptgt->tgt_mutex) must be owned when
5441 fcp_update_tgt_state(struct fcp_tgt *ptgt, int flag, uint32_t state)
5445 ASSERT(mutex_owned(&ptgt->tgt_mutex));
5447 if (!(ptgt->tgt_state & FCP_TGT_OFFLINE)) {
5450 ptgt->tgt_state |= state;
5451 ptgt->tgt_trace = 0;
5453 ptgt->tgt_state &= ~state;
5456 for (plun = ptgt->tgt_lun; plun != NULL;
5485 * The mutex of the target (ptgt->tgt_mutex) must be owned when
5491 struct fcp_tgt *ptgt = plun->lun_tgt;
5493 ASSERT(mutex_owned(&ptgt->tgt_mutex));
5601 struct fcp_tgt *ptgt;
5607 if ((ptgt = fcp_get_target_by_did(pptr, buf->ub_frame.s_id)) !=
5609 mutex_enter(&ptgt->tgt_mutex);
5610 tcount = ptgt->tgt_change_cnt;
5611 mutex_exit(&ptgt->tgt_mutex);
5618 if ((icmd = fcp_icmd_alloc(pptr, ptgt, sizeof (la_els_prli_t),
5683 ptgt != NULL) {
5712 * ptgt->tgt_change_cnt.
5715 * *ptgt Target (destination of the command).
5729 fcp_icmd_alloc(struct fcp_port *pptr, struct fcp_tgt *ptgt, int cmd_len,
5782 if (ptgt != NULL) {
5783 icmd->ipkt_tgt = ptgt;
5784 fpkt->pkt_fca_device = ptgt->tgt_fca_dev;
5834 if (ptgt != NULL) {
5835 mutex_enter(&ptgt->tgt_mutex);
5836 fpkt->pkt_pd = ptgt->tgt_pd_handle;
5844 mutex_exit(&ptgt->tgt_mutex);
5847 mutex_exit(&ptgt->tgt_mutex);
5871 if (ptgt != NULL) {
5872 mutex_enter(&ptgt->tgt_mutex);
5873 ptgt->tgt_ipkt_cnt++;
5874 mutex_exit(&ptgt->tgt_mutex);
5912 struct fcp_tgt *ptgt = icmd->ipkt_tgt;
5930 if (ptgt) {
5931 mutex_enter(&ptgt->tgt_mutex);
5932 ptgt->tgt_ipkt_cnt--;
5933 mutex_exit(&ptgt->tgt_mutex);
6145 struct fcp_tgt *ptgt;
6151 for (ptgt = pptr->port_tgt_hash_table[hash]; ptgt != NULL;
6152 ptgt = ptgt->tgt_next) {
6153 if (!(ptgt->tgt_state & FCP_TGT_ORPHAN) &&
6154 bcmp((caddr_t)wwn, (caddr_t)&ptgt->tgt_port_wwn.raw_wwn[0],
6155 sizeof (ptgt->tgt_port_wwn)) == 0) {
6160 return (ptgt);
6172 struct fcp_tgt *ptgt = NULL;
6179 ptgt = fcp_lookup_target(pptr, pwwn.raw_wwn);
6183 return (ptgt);
6200 struct fcp_tgt *ptgt;
6216 ptgt = icmd->ipkt_tgt;
6230 ptgt->tgt_d_id);
6235 mutex_enter(&ptgt->tgt_mutex);
6236 if (ptgt->tgt_pd_handle == NULL) {
6245 ptgt->tgt_pd_handle = fpkt->pkt_pd;
6247 mutex_exit(&ptgt->tgt_mutex);
6255 ptgt->tgt_d_id,
6256 *((int *)&ptgt->tgt_port_wwn.raw_wwn[0]),
6257 *((int *)&ptgt->tgt_port_wwn.raw_wwn[4]));
6259 FCP_TGT_TRACE(ptgt, icmd->ipkt_change_cnt,
6263 if (fcp_send_els(pptr, ptgt, icmd, LA_ELS_PRLI,
6266 FCP_TGT_TRACE(ptgt, icmd->ipkt_change_cnt,
6275 "PRLI to d_id=0x%x succeeded", ptgt->tgt_d_id);
6277 FCP_TGT_TRACE(ptgt, icmd->ipkt_change_cnt,
6287 mutex_enter(&ptgt->tgt_mutex);
6288 ptgt->tgt_icap = fprli->initiator_fn;
6289 ptgt->tgt_tcap = fprli->target_fn;
6290 mutex_exit(&ptgt->tgt_mutex);
6296 FCP_TGT_TRACE(ptgt, icmd->ipkt_change_cnt,
6302 &ptgt->tgt_port_wwn);
6307 mutex_enter(&ptgt->tgt_mutex);
6308 if (!FCP_TGT_STATE_CHANGED(ptgt, icmd)) {
6309 ptgt->tgt_state &= ~(FCP_TGT_OFFLINE |
6315 " occured for D_ID=0x%x", ptgt->tgt_d_id);
6316 mutex_exit(&ptgt->tgt_mutex);
6320 mutex_exit(&ptgt->tgt_mutex);
6333 if ((plun = fcp_get_lun(ptgt, 0)) == NULL) {
6338 plun = fcp_alloc_lun(ptgt);
6342 " D_ID=%x", ptgt->tgt_d_id);
6349 mutex_enter(&ptgt->tgt_mutex);
6360 ptgt->tgt_lun_cnt = 1;
6361 ptgt->tgt_report_lun_cnt = 0;
6362 mutex_exit(&ptgt->tgt_mutex);
6379 if (!FCP_TGT_STATE_CHANGED(ptgt, icmd)) {
6382 " D_ID=%x", ptgt->tgt_d_id);
6389 ptgt->tgt_d_id);
6393 FCP_TGT_TRACE(ptgt, icmd->ipkt_change_cnt,
6429 " reason= %x", ptgt->tgt_d_id, fpkt->pkt_state,
6437 if (!FCP_TGT_STATE_CHANGED(ptgt, icmd)) {
6465 ptgt->tgt_d_id, msg);
6470 " occured for D_ID=0x%x", ptgt->tgt_d_id);
6483 if (!FCP_TGT_STATE_CHANGED(ptgt, icmd) &&
6491 " for D_ID=0x%x", ptgt->tgt_d_id);
6498 (void) fcp_call_finish_init(pptr, ptgt, icmd->ipkt_link_cnt,
6518 struct fcp_tgt *ptgt;
6528 ptgt = plun->lun_tgt;
6529 ASSERT(ptgt != NULL);
6531 pptr = ptgt->tgt_port;
6536 "fcp_send_scsi: d_id=0x%x opcode=0x%x", ptgt->tgt_d_id, opcode);
6539 icmd = fcp_icmd_alloc(pptr, ptgt, sizeof (struct fcp_cmd),
6565 hp->d_id = ptgt->tgt_d_id;
6631 d_id.port_id = ptgt->tgt_d_id;
6635 mutex_enter(&ptgt->tgt_mutex);
6636 ptgt->tgt_fca_dev = fca_dev;
6637 mutex_exit(&ptgt->tgt_mutex);
6666 if (!FCP_TGT_STATE_CHANGED(ptgt, icmd)) {
6679 " for D_ID=0x%x", ptgt->tgt_d_id);
6699 struct fcp_tgt *ptgt = icmd->ipkt_tgt;
6700 struct fcp_port *pptr = ptgt->tgt_port;
6764 mutex_enter(&ptgt->tgt_mutex);
6766 ptgt->tgt_state &= ~FCP_TGT_ILLREQ;
6767 mutex_exit(&ptgt->tgt_mutex);
6828 mutex_enter(&ptgt->tgt_mutex);
6830 (ptgt->tgt_state & FCP_TGT_ILLREQ)) {
6831 ptgt->tgt_state &= ~FCP_TGT_ILLREQ;
6832 mutex_exit(&ptgt->tgt_mutex);
6840 " target=%x", ptgt->tgt_d_id);
6842 if (ptgt->tgt_tid == NULL) {
6849 (caddr_t)ptgt, (clock_t)drv_usectohz(1));
6851 ptgt->tgt_tid = tid;
6852 ptgt->tgt_state |= FCP_TGT_BUSY;
6855 ptgt->tgt_state |= FCP_TGT_ILLREQ;
6857 mutex_exit(&ptgt->tgt_mutex);
6862 " target=%x", ptgt->tgt_d_id);
6867 " target=%x", ptgt->tgt_d_id);
6901 struct fcp_tgt *ptgt;
6905 ptgt = icmd->ipkt_tgt;
6906 pptr = ptgt->tgt_port;
6921 fpkt->pkt_state, ptgt->tgt_d_id, icmd->ipkt_opcode,
6936 fcp_wwn_to_ascii(&ptgt->tgt_node_wwn.raw_wwn[0], ascii_wwn);
6958 ptgt->tgt_d_id);
6977 FCP_TGT_TRACE(ptgt, icmd->ipkt_change_cnt,
6981 mutex_enter(&ptgt->tgt_mutex);
6982 if (!FCP_STATE_CHANGED(pptr, ptgt, icmd)) {
6983 mutex_exit(&ptgt->tgt_mutex);
6990 " for D_ID=0x%x", ptgt->tgt_d_id);
6991 mutex_exit(&ptgt->tgt_mutex);
6994 (void) fcp_call_finish_init(pptr, ptgt, icmd->ipkt_link_cnt,
7000 FCP_TGT_TRACE(ptgt, icmd->ipkt_change_cnt, FCP_TGT_TRACE_21);
7003 mutex_enter(&ptgt->tgt_mutex);
7004 if (FCP_STATE_CHANGED(pptr, ptgt, icmd)) {
7008 " for D_ID=0x%x", ptgt->tgt_d_id);
7009 mutex_exit(&ptgt->tgt_mutex);
7011 (void) fcp_call_finish_init(pptr, ptgt, icmd->ipkt_link_cnt,
7016 ASSERT((ptgt->tgt_state & FCP_TGT_MARK) == 0);
7018 mutex_exit(&ptgt->tgt_mutex);
7065 ptgt->tgt_d_id, plun->lun_type);
7088 mutex_enter(&ptgt->tgt_mutex);
7091 mutex_exit(&ptgt->tgt_mutex);
7093 (void) fcp_call_finish_init(pptr, ptgt,
7127 (void) fcp_call_finish_init(pptr, ptgt,
7139 mutex_enter(&ptgt->tgt_mutex);
7140 ptgt->tgt_state &= ~FCP_TGT_ILLREQ;
7141 mutex_exit(&ptgt->tgt_mutex);
7158 FCP_TGT_TRACE(ptgt, icmd->ipkt_change_cnt,
7170 (void) fcp_call_finish_init(pptr, ptgt, icmd->ipkt_link_cnt,
7183 struct fcp_tgt *ptgt = icmd->ipkt_tgt;
7184 struct fcp_port *pptr = ptgt->tgt_port;
7189 if (!FCP_TGT_STATE_CHANGED(ptgt, icmd)) {
7195 "Report LUN" : "INQUIRY", ptgt->tgt_d_id,
7203 " for D_ID=0x%x", ptgt->tgt_d_id);
7205 (void) fcp_call_finish_init(pptr, ptgt,
7212 (void) fcp_call_finish_init(pptr, ptgt, icmd->ipkt_link_cnt,
7237 struct fcp_tgt *ptgt;
7247 ptgt = icmd->ipkt_tgt;
7260 pptr->port_instance, ptgt->tgt_d_id,
7413 mutex_enter(&ptgt->tgt_mutex);
7416 mutex_exit(&ptgt->tgt_mutex);
7418 (void) fcp_call_finish_init(pptr, ptgt, icmd->ipkt_link_cnt,
7440 struct fcp_tgt *ptgt;
7448 ptgt = icmd->ipkt_tgt;
7460 "dtype=0x%x pqual: 0x%x", pptr->port_instance, ptgt->tgt_d_id,
7470 ptgt->tgt_d_id, plun->lun_num, dtype, pqual);
7476 ptgt->tgt_d_id, plun->lun_num, dtype, pqual);
7480 (void) fcp_call_finish_init(pptr, ptgt, icmd->ipkt_link_cnt,
7515 if (FCP_TGT_STATE_CHANGED(ptgt, icmd)) {
7519 " for D_ID=0x%x", ptgt->tgt_d_id);
7523 (void) fcp_call_finish_init(pptr, ptgt,
7529 ASSERT((ptgt->tgt_state & FCP_TGT_MARK) == 0);
7546 (void) fcp_call_finish_init(pptr, ptgt,
7579 struct fcp_tgt *ptgt;
7584 ptgt = icmd->ipkt_tgt;
7589 (void) fcp_call_finish_init(pptr, ptgt, icmd->ipkt_link_cnt,
7601 pptr->port_instance, ptgt->tgt_d_id);
7622 ptgt->tgt_d_id);
7624 (void) fcp_call_finish_init(pptr, ptgt, icmd->ipkt_link_cnt,
7635 mutex_enter(&ptgt->tgt_mutex);
7638 (ptgt->tgt_report_lun_cnt < FCP_MAX_REPORTLUNS_ATTEMPTS)) {
7642 ptgt->tgt_report_lun_cnt++;
7643 plun = ptgt->tgt_lun;
7645 mutex_exit(&ptgt->tgt_mutex);
7652 nluns_claimed, ptgt->tgt_d_id);
7667 (void) fcp_call_finish_init(pptr, ptgt,
7681 ptgt->tgt_port_wwn.raw_wwn[0],
7682 ptgt->tgt_port_wwn.raw_wwn[1],
7683 ptgt->tgt_port_wwn.raw_wwn[2],
7684 ptgt->tgt_port_wwn.raw_wwn[3],
7685 ptgt->tgt_port_wwn.raw_wwn[4],
7686 ptgt->tgt_port_wwn.raw_wwn[5],
7687 ptgt->tgt_port_wwn.raw_wwn[6],
7688 ptgt->tgt_port_wwn.raw_wwn[7],
7693 ptgt->tgt_lun_cnt = nluns_claimed;
7698 for (plun = ptgt->tgt_lun; plun; plun = plun->lun_next) {
7727 mutex_exit(&ptgt->tgt_mutex);
7730 mutex_enter(&ptgt->tgt_mutex);
7731 if (!FCP_STATE_CHANGED(pptr, ptgt, icmd)) {
7739 mutex_exit(&ptgt->tgt_mutex);
7745 plun->lun_num, ptgt->tgt_d_id);
7747 mutex_enter(&ptgt->tgt_mutex);
7752 " occured for D_ID=0x%x", ptgt->tgt_d_id);
7753 mutex_exit(&ptgt->tgt_mutex);
7756 (void) fcp_call_finish_init(pptr, ptgt,
7774 mutex_exit(&ptgt->tgt_mutex);
7777 plun->lun_num, ptgt->tgt_d_id);
7778 mutex_enter(&ptgt->tgt_mutex);
7784 ptgt->tgt_tmp_cnt = nluns_claimed ? nluns_claimed : 1;
7785 mutex_exit(&ptgt->tgt_mutex);
7790 pptr->port_instance, ptgt->tgt_d_id, nluns_claimed);
7801 " addr=0x%x", ptgt->tgt_d_id, i, lun_string[1],
7812 mutex_enter(&ptgt->tgt_mutex);
7813 if (fcp_should_mask(&ptgt->tgt_port_wwn,
7815 ptgt->tgt_lun_cnt--;
7816 mutex_exit(&ptgt->tgt_mutex);
7819 mutex_exit(&ptgt->tgt_mutex);
7823 if ((plun = fcp_get_lun(ptgt, lun_num)) == NULL) {
7824 plun = fcp_alloc_lun(ptgt);
7829 ptgt->tgt_d_id, lun_num);
7864 if (!FCP_STATE_CHANGED(pptr, ptgt, icmd)) {
7868 ptgt->tgt_d_id, plun->lun_num);
7875 ptgt->tgt_d_id);
7896 (void) fcp_call_finish_init(pptr, ptgt, icmd->ipkt_link_cnt,
7902 "!FCP: target=%x reported NO Luns", ptgt->tgt_d_id);
7903 (void) fcp_call_finish_init(pptr, ptgt, icmd->ipkt_link_cnt,
7916 fcp_get_lun(struct fcp_tgt *ptgt, uint16_t lun_num)
7920 mutex_enter(&ptgt->tgt_mutex);
7921 for (plun = ptgt->tgt_lun; plun != NULL; plun = plun->lun_next) {
7923 mutex_exit(&ptgt->tgt_mutex);
7927 mutex_exit(&ptgt->tgt_mutex);
7943 fcp_finish_tgt(struct fcp_port *pptr, struct fcp_tgt *ptgt,
7948 ASSERT(ptgt != NULL);
7952 "finish_tgt: D_ID/state = 0x%x/0x%x", ptgt->tgt_d_id,
7953 ptgt->tgt_state);
7958 (tgt_cnt && ptgt->tgt_change_cnt != tgt_cnt)) {
7963 FCP_TGT_TRACE(ptgt, tgt_cnt, FCP_TGT_TRACE_23);
7967 FCP_TGT_TRACE(ptgt, tgt_cnt, FCP_TGT_TRACE_24);
7970 mutex_enter(&ptgt->tgt_mutex);
7972 if (!(ptgt->tgt_state & FCP_TGT_OFFLINE)) {
7977 if (ptgt->tgt_state & FCP_TGT_MARK) {
7982 ptgt->tgt_state &= ~FCP_TGT_MARK;
7983 rval = fcp_offline_target(pptr, ptgt, link_cnt,
7986 ptgt->tgt_state &= ~FCP_TGT_BUSY;
7989 if (ptgt->tgt_node_state != FCP_TGT_NODE_ON_DEMAND) {
7990 ptgt->tgt_node_state = FCP_TGT_NODE_PRESENT;
7991 fcp_create_luns(ptgt, link_cnt, tgt_cnt,
7993 ptgt->tgt_device_created = 1;
7995 fcp_update_tgt_state(ptgt, FCP_RESET,
8001 mutex_exit(&ptgt->tgt_mutex);
8055 fcp_create_luns(struct fcp_tgt *ptgt, int link_cnt, int tgt_cnt, int cause)
8061 ASSERT(ptgt != NULL);
8062 ASSERT(mutex_owned(&ptgt->tgt_mutex));
8064 pptr = ptgt->tgt_port;
8069 for (plun = ptgt->tgt_lun; plun != NULL; plun = plun->lun_next) {
8291 fcp_offline_target(struct fcp_port *pptr, struct fcp_tgt *ptgt,
8297 ASSERT(mutex_owned(&ptgt->tgt_mutex));
8299 ASSERT(!(ptgt->tgt_state & FCP_TGT_OFFLINE));
8302 ptgt->tgt_change_cnt)) {
8303 mutex_exit(&ptgt->tgt_mutex);
8304 FCP_TGT_TRACE(ptgt, tgt_cnt, FCP_TGT_TRACE_25);
8305 mutex_enter(&ptgt->tgt_mutex);
8310 ptgt->tgt_pd_handle = NULL;
8311 mutex_exit(&ptgt->tgt_mutex);
8312 FCP_TGT_TRACE(ptgt, tgt_cnt, FCP_TGT_TRACE_26);
8313 mutex_enter(&ptgt->tgt_mutex);
8315 tgt_cnt = tgt_cnt ? tgt_cnt : ptgt->tgt_change_cnt;
8317 if (ptgt->tgt_tcap &&
8324 elem->ptgt = ptgt;
8330 fcp_offline_target_now(pptr, ptgt, link_cnt, tgt_cnt, flags);
8338 fcp_offline_target_now(struct fcp_port *pptr, struct fcp_tgt *ptgt,
8342 ASSERT(mutex_owned(&ptgt->tgt_mutex));
8344 fc_ulp_enable_relogin(pptr->port_fp_handle, &ptgt->tgt_port_wwn);
8345 ptgt->tgt_state = FCP_TGT_OFFLINE;
8346 ptgt->tgt_pd_handle = NULL;
8347 fcp_offline_tgt_luns(ptgt, link_cnt, tgt_cnt, flags);
8352 fcp_offline_tgt_luns(struct fcp_tgt *ptgt, int link_cnt, int tgt_cnt,
8357 ASSERT(mutex_owned(&ptgt->tgt_port->port_mutex));
8358 ASSERT(mutex_owned(&ptgt->tgt_mutex));
8360 for (plun = ptgt->tgt_lun; plun != NULL; plun = plun->lun_next) {
8489 struct fcp_tgt *ptgt = elem->plun->lun_tgt;
8491 mutex_enter(&ptgt->tgt_mutex);
8493 ptgt->tgt_change_cnt == elem->tgt_cnt) {
8502 mutex_exit(&ptgt->tgt_mutex);
8534 struct fcp_tgt *ptgt = elem->ptgt;
8536 mutex_enter(&ptgt->tgt_mutex);
8538 if (ptgt->tgt_change_cnt == elem->tgt_cnt) {
8541 } else if (ptgt->tgt_change_cnt == elem->tgt_cnt + 1 &&
8543 ptgt->tgt_statec_cause == FCP_CAUSE_LINK_DOWN) {
8554 if (!outdated && !(ptgt->tgt_state &
8557 ptgt, elem->link_cnt, elem->tgt_cnt,
8561 mutex_exit(&ptgt->tgt_mutex);
8778 struct fcp_tgt *ptgt;
8826 ptgt = plun->lun_tgt;
8827 ASSERT(ptgt != NULL);
8855 ptgt->tgt_d_id, plun->lun_num,
8884 ptgt->tgt_d_id, cip);
8918 ptgt->tgt_d_id, plun->lun_num,
8939 mutex_enter(&ptgt->tgt_mutex);
8940 if (ptgt->tgt_tid == NULL) {
8945 (caddr_t)ptgt, drv_usectohz(1));
8947 ptgt->tgt_tid = tid;
8948 ptgt->tgt_state |= FCP_TGT_BUSY;
8950 mutex_exit(&ptgt->tgt_mutex);
8955 " target=%x", ptgt->tgt_d_id);
8960 " target=%x", ptgt->tgt_d_id);
8986 " ASC=%x ASCQ=%x", cmd, ptgt->tgt_d_id, cip,
8994 ptgt = plun->lun_tgt;
8995 ASSERT(ptgt != NULL);
9055 ptgt->tgt_d_id);
9226 " pkt reason=0x%x", cmd, ptgt->tgt_d_id, fpkt->pkt_state,
9284 fcp_device_changed(struct fcp_port *pptr, struct fcp_tgt *ptgt,
9297 if ((ptgt->tgt_d_id != map_entry->map_did.port_id) ||
9299 (ptgt->tgt_hard_addr != map_entry->map_hard_addr.hard_addr))) {
9302 mutex_enter(&ptgt->tgt_mutex);
9303 if (!(ptgt->tgt_state & FCP_TGT_OFFLINE)) {
9304 (void) fcp_offline_target(pptr, ptgt, link_cnt,
9307 mutex_exit(&ptgt->tgt_mutex);
9311 " Old HA=%x New HA=%x", ptgt->tgt_d_id,
9312 map_entry->map_did.port_id, ptgt->tgt_hard_addr,
9316 return (fcp_handle_mapflags(pptr, ptgt, map_entry,
9326 * Argument: ptgt Target the lun will belong to.
9334 fcp_alloc_lun(struct fcp_tgt *ptgt)
9345 plun->lun_tgt = ptgt;
9347 mutex_enter(&ptgt->tgt_mutex);
9348 plun->lun_next = ptgt->tgt_lun;
9349 ptgt->tgt_lun = plun;
9352 mutex_exit(&ptgt->tgt_mutex);
9408 struct fcp_tgt *ptgt;
9410 ptgt = kmem_zalloc(sizeof (*ptgt), KM_NOSLEEP);
9411 if (ptgt != NULL) {
9419 kmem_free(ptgt, sizeof (*ptgt));
9420 ptgt = NULL;
9427 mutex_init(&ptgt->tgt_mutex, NULL, MUTEX_DRIVER, NULL);
9433 ptgt->tgt_next = pptr->port_tgt_hash_table[hash];
9434 pptr->port_tgt_hash_table[hash] = ptgt;
9437 ptgt->tgt_port = pptr;
9439 ptgt->tgt_change_cnt = 1;
9443 ptgt->tgt_manual_config_only = 0;
9445 ptgt->tgt_manual_config_only = 1;
9452 return (ptgt);
9460 * Argument: ptgt Target structure to free.
9467 fcp_dealloc_tgt(struct fcp_tgt *ptgt)
9469 mutex_destroy(&ptgt->tgt_mutex);
9470 kmem_free(ptgt, sizeof (*ptgt));
9492 struct fcp_tgt *ptgt = icmd->ipkt_tgt;
9495 mutex_enter(&ptgt->tgt_mutex);
9496 if (FCP_STATE_CHANGED(pptr, ptgt, icmd)) {
9500 " for D_ID=0x%x", ptgt->tgt_d_id);
9501 mutex_exit(&ptgt->tgt_mutex);
9503 (void) fcp_call_finish_init(pptr, ptgt, icmd->ipkt_link_cnt,
9508 mutex_exit(&ptgt->tgt_mutex);
10817 struct fcp_tgt *ptgt;
10882 ptgt = plun->lun_tgt;
10884 mutex_enter(&ptgt->tgt_mutex);
10889 mutex_exit(&ptgt->tgt_mutex);
10903 struct fcp_tgt *ptgt;
10973 ptgt = plun->lun_tgt;
10975 mutex_enter(&ptgt->tgt_mutex);
10980 mutex_exit(&ptgt->tgt_mutex);
11024 struct fcp_tgt *ptgt;
11035 ptgt = plun->lun_tgt;
11037 ASSERT(ptgt != NULL);
11039 mutex_enter(&ptgt->tgt_mutex);
11046 mutex_exit(&ptgt->tgt_mutex);
11069 struct fcp_tgt *ptgt = plun->lun_tgt;
11084 mutex_enter(&ptgt->tgt_mutex);
11093 mutex_exit(&ptgt->tgt_mutex);
11129 (ptgt->tgt_pd_handle == NULL) ||
11141 mutex_exit(&ptgt->tgt_mutex);
11167 mutex_exit(&ptgt->tgt_mutex);
11233 mutex_enter(&ptgt->tgt_mutex);
11259 mutex_exit(&ptgt->tgt_mutex);
11275 struct fcp_tgt *ptgt = plun->lun_tgt;
11278 if (ptgt) {
11279 mutex_enter(&ptgt->tgt_mutex);
11280 tgt_cnt = ptgt->tgt_change_cnt;
11281 mutex_exit(&ptgt->tgt_mutex);
11282 fcp_abort_all(pptr, ptgt, plun, tgt_cnt);
11299 struct fcp_tgt *ptgt = plun->lun_tgt;
11311 mutex_enter(&ptgt->tgt_mutex);
11312 if (ptgt->tgt_state & (FCP_TGT_OFFLINE | FCP_TGT_BUSY)) {
11313 mutex_exit(&ptgt->tgt_mutex);
11316 mutex_exit(&ptgt->tgt_mutex);
11379 struct fcp_tgt *ptgt;
11386 ptgt = plun->lun_tgt;
11425 mutex_enter(&ptgt->tgt_mutex);
11426 fpkt->pkt_pd = ptgt->tgt_pd_handle;
11430 mutex_exit(&ptgt->tgt_mutex);
11434 mutex_exit(&ptgt->tgt_mutex);
11622 struct fcp_tgt *ptgt = plun->lun_tgt;
11636 mutex_enter(&ptgt->tgt_mutex);
11638 if (ptgt->tgt_state & (FCP_TGT_OFFLINE | FCP_TGT_BUSY)) {
11639 mutex_exit(&ptgt->tgt_mutex);
11643 fcp_update_tgt_state(ptgt, FCP_SET, FCP_LUN_BUSY);
11647 mutex_exit(&ptgt->tgt_mutex);
11655 tgt_cnt = ptgt->tgt_change_cnt;
11657 mutex_exit(&ptgt->tgt_mutex);
11662 mutex_enter(&ptgt->tgt_mutex);
11663 fcp_update_tgt_state(ptgt, FCP_RESET, FCP_LUN_BUSY);
11664 mutex_exit(&ptgt->tgt_mutex);
11724 *((int *)&ptgt->tgt_port_wwn.raw_wwn[0]),
11725 *((int *)&ptgt->tgt_port_wwn.raw_wwn[4]), lun_id);
11732 *((int *)&ptgt->tgt_port_wwn.raw_wwn[0]),
11733 *((int *)&ptgt->tgt_port_wwn.raw_wwn[4]), lun_id,
11743 *((int *)&ptgt->tgt_port_wwn.raw_wwn[0]),
11744 *((int *)&ptgt->tgt_port_wwn.raw_wwn[4]), lun_id,
11754 *((int *)&ptgt->tgt_port_wwn.raw_wwn[0]),
11755 *((int *)&ptgt->tgt_port_wwn.raw_wwn[4]), lun_id);
11762 mutex_enter(&ptgt->tgt_mutex);
11764 fcp_update_tgt_state(ptgt, FCP_RESET, FCP_LUN_BUSY);
11768 mutex_exit(&ptgt->tgt_mutex);
11775 p->tgt = ptgt;
11781 p->tgt = ptgt;
11811 struct fcp_tgt *ptgt = plun->lun_tgt;
11906 (ptgt->tgt_hard_addr == 0)) {
11961 struct fcp_tgt *ptgt;
12007 ptgt = plun->lun_tgt;
12014 ptgt->tgt_hard_addr != 0) {
12016 ptgt->tgt_hard_addr];
12018 tgt_id = ptgt->tgt_d_id;
12070 struct fcp_tgt *ptgt;
12077 if ((ptgt = plun->lun_tgt) == NULL) {
12081 numChars = snprintf(name, len, "%x", ptgt->tgt_d_id);
12103 struct fcp_tgt *ptgt;
12132 ptgt = plun->lun_tgt;
12133 bcopy(&ptgt->tgt_port_wwn.raw_wwn[0], &wwn, sizeof (wwn));
12505 struct fcp_tgt *ptgt = plun->lun_tgt;
12506 struct fcp_port *pptr = ptgt->tgt_port;
12539 ptgt->tgt_port_wwn.raw_wwn[0],
12540 ptgt->tgt_port_wwn.raw_wwn[1],
12541 ptgt->tgt_port_wwn.raw_wwn[2],
12542 ptgt->tgt_port_wwn.raw_wwn[3],
12543 ptgt->tgt_port_wwn.raw_wwn[4],
12544 ptgt->tgt_port_wwn.raw_wwn[5],
12545 ptgt->tgt_port_wwn.raw_wwn[6],
12546 ptgt->tgt_port_wwn.raw_wwn[7], plun->lun_num,
12569 mutex_enter(&ptgt->tgt_mutex);
12572 mutex_exit(&ptgt->tgt_mutex);
12619 ptgt->tgt_node_wwn.raw_wwn, FC_WWN_SIZE) != DDI_PROP_SUCCESS) {
12625 ptgt->tgt_port_wwn.raw_wwn, FC_WWN_SIZE) != DDI_PROP_SUCCESS) {
12630 fcp_wwn_to_ascii(ptgt->tgt_port_wwn.raw_wwn, t_pwwn);
12644 if (!FC_TOP_EXTERNAL(pptr->port_topology) && ptgt->tgt_hard_addr != 0) {
12645 tgt_id = (uint32_t)fcp_alpa_to_switch[ptgt->tgt_hard_addr];
12647 tgt_id = ptgt->tgt_d_id;
12703 struct fcp_tgt *ptgt = plun->lun_tgt;
12704 struct fcp_port *pptr = ptgt->tgt_port;
12729 ptgt->tgt_port_wwn.raw_wwn[0],
12730 ptgt->tgt_port_wwn.raw_wwn[1],
12731 ptgt->tgt_port_wwn.raw_wwn[2],
12732 ptgt->tgt_port_wwn.raw_wwn[3],
12733 ptgt->tgt_port_wwn.raw_wwn[4],
12734 ptgt->tgt_port_wwn.raw_wwn[5],
12735 ptgt->tgt_port_wwn.raw_wwn[6],
12736 ptgt->tgt_port_wwn.raw_wwn[7], plun->lun_num,
12759 mutex_enter(&ptgt->tgt_mutex);
12763 mutex_exit(&ptgt->tgt_mutex);
12791 ptgt->tgt_port_wwn.raw_wwn[i]);
12835 ptgt->tgt_node_wwn.raw_wwn, FC_WWN_SIZE)
12842 ptgt->tgt_port_wwn.raw_wwn, FC_WWN_SIZE)
12848 fcp_wwn_to_ascii(ptgt->tgt_port_wwn.raw_wwn, t_pwwn);
12863 ptgt->tgt_hard_addr != 0) {
12865 fcp_alpa_to_switch[ptgt->tgt_hard_addr];
12867 tgt_id = ptgt->tgt_d_id;
12914 struct fcp_tgt *ptgt = plun->lun_tgt;
12915 struct fcp_port *pptr = ptgt->tgt_port;
12942 if (bcmp(bytes, ptgt->tgt_node_wwn.raw_wwn, nbytes) != 0) {
12963 if (bcmp(bytes, ptgt->tgt_port_wwn.raw_wwn, nbytes) != 0) {
12991 ptgt->tgt_hard_addr != 0) {
12993 (uint32_t)fcp_alpa_to_switch[ptgt->tgt_hard_addr];
12995 tgt_id = ptgt->tgt_d_id;
13091 struct fcp_tgt *ptgt = plun->lun_tgt;
13092 struct fcp_port *pptr = ptgt->tgt_port;
13096 fcp_wwn_to_ascii(ptgt->tgt_port_wwn.raw_wwn, buf);
13111 struct fcp_tgt *ptgt = plun->lun_tgt;
13135 ddi_get_name(cdip), ptgt->tgt_d_id, plun->lun_num);
13160 mutex_enter(&ptgt->tgt_mutex);
13162 mutex_exit(&ptgt->tgt_mutex);
13167 ddi_get_name(cdip), ptgt->tgt_d_id,
13174 ddi_get_name(cdip), ptgt->tgt_d_id,
13185 ddi_get_name(cdip), ptgt->tgt_d_id, plun->lun_num);
13200 mutex_enter(&ptgt->tgt_mutex);
13202 mutex_exit(&ptgt->tgt_mutex);
13229 mutex_enter(&ptgt->tgt_mutex);
13231 mutex_exit(&ptgt->tgt_mutex);
13260 ddi_get_name(cdip), ptgt->tgt_d_id,
13289 struct fcp_tgt *ptgt = plun->lun_tgt;
13342 mutex_enter(&ptgt->tgt_mutex);
13344 mutex_exit(&ptgt->tgt_mutex);
13400 ddi_get_name(cdip), ptgt->tgt_d_id, plun->lun_num);
13601 struct fcp_tgt *ptgt;
13604 ptgt = plun->lun_tgt;
13609 pkt->pkt_cdbp[0], ptgt->tgt_d_id);
13644 struct fcp_tgt *ptgt = icmd->ipkt_tgt;
13694 mutex_enter(&ptgt->tgt_mutex);
13695 if (!FCP_STATE_CHANGED(pptr, ptgt, icmd)) {
13696 mutex_exit(&ptgt->tgt_mutex);
13710 pptr, ptgt, icmd, rval,
13728 pptr, ptgt, icmd, rval,
13746 pptr, ptgt, icmd, rval,
13755 mutex_exit(&ptgt->tgt_mutex);
13762 (void) fcp_call_finish_init(pptr, ptgt,
13796 struct fcp_tgt *ptgt;
13813 ptgt = cur->tgt;
13817 if (ptgt) {
13822 ptgt = plun->lun_tgt;
13850 if (tgt_cnt == ptgt->tgt_change_cnt) {
13851 mutex_enter(&ptgt->tgt_mutex);
13853 fcp_update_tgt_state(ptgt,
13859 mutex_exit(&ptgt->tgt_mutex);
13862 fcp_abort_all(pptr, ptgt, plun, tgt_cnt);
13882 struct fcp_tgt *ptgt = plun->lun_tgt;
13886 if (ptgt != ttgt && plun != rlun) {
14108 struct fcp_tgt *ptgt;
14114 for (ptgt = pptr->port_tgt_hash_table[hash]; ptgt != NULL;
14115 ptgt = ptgt->tgt_next) {
14116 if (bcmp((caddr_t)wwn, (caddr_t)&ptgt->tgt_port_wwn.raw_wwn[0],
14117 sizeof (ptgt->tgt_port_wwn)) == 0) {
14118 mutex_enter(&ptgt->tgt_mutex);
14119 for (plun = ptgt->tgt_lun;
14123 mutex_exit(&ptgt->tgt_mutex);
14127 mutex_exit(&ptgt->tgt_mutex);
14153 struct fcp_tgt *ptgt = plun->lun_tgt;
14233 fpkt->pkt_cmd_fhdr.d_id = ptgt->tgt_d_id;
14240 fpkt->pkt_fca_device = ptgt->tgt_fca_dev;
14335 struct fcp_tgt *ptgt;
14343 for (ptgt = pptr->port_tgt_hash_table[i];
14344 ptgt != NULL;
14345 ptgt = ptgt->tgt_next) {
14346 mutex_enter(&ptgt->tgt_mutex);
14347 for (plun = ptgt->tgt_lun; plun != NULL;
14352 mutex_exit(&ptgt->tgt_mutex);
14357 mutex_exit(&ptgt->tgt_mutex);
14481 struct fcp_tgt *ptgt;
14486 ptgt = plun->lun_tgt;
14493 mutex_enter(&ptgt->tgt_mutex);
14507 if ((fpkt->pkt_pd == NULL) && (ptgt->tgt_pd_handle != NULL)) {
14508 fpkt->pkt_pd = ptgt->tgt_pd_handle;
14513 fc_ulp_hold_remote_port(ptgt->tgt_pd_handle);
14516 mutex_exit(&ptgt->tgt_mutex);
14545 mutex_exit(&ptgt->tgt_mutex);
14643 struct fcp_tgt *ptgt;
14649 ptgt = fcp_lookup_target(pptr,
14651 if (ptgt == NULL) {
14655 mutex_enter(&ptgt->tgt_mutex);
14656 ptgt->tgt_trace = 0;
14657 ptgt->tgt_change_cnt++;
14658 ptgt->tgt_statec_cause = cause;
14659 ptgt->tgt_tmp_cnt = 1;
14660 fcp_update_tgt_state(ptgt, FCP_SET, state);
14661 mutex_exit(&ptgt->tgt_mutex);
14666 fcp_call_finish_init(struct fcp_port *pptr, struct fcp_tgt *ptgt,
14672 rval = fcp_call_finish_init_held(pptr, ptgt, lcount, tcount, cause);
14680 fcp_call_finish_init_held(struct fcp_port *pptr, struct fcp_tgt *ptgt,
14693 if (ptgt != NULL) {
14698 pptr->port_link_cnt, lcount, ptgt->tgt_change_cnt, tcount,
14699 pptr->port_tmp_cnt, ptgt->tgt_tmp_cnt, cause,
14700 ptgt->tgt_d_id, ptgt->tgt_done);
14702 mutex_enter(&ptgt->tgt_mutex);
14704 if (tcount && (ptgt->tgt_change_cnt != tcount)) {
14706 if (do_finish_init && ptgt->tgt_done == 0) {
14707 ptgt->tgt_done++;
14711 if (--ptgt->tgt_tmp_cnt <= 0) {
14712 ptgt->tgt_tmp_cnt = 0;
14720 mutex_exit(&ptgt->tgt_mutex);
14732 ASSERT(ptgt != NULL);
14734 mutex_enter(&ptgt->tgt_mutex);
14736 bzero(ptgt->tgt_tmp_cnt_stack,
14737 sizeof (ptgt->tgt_tmp_cnt_stack));
14739 ptgt->tgt_tmp_cnt_depth = getpcstack(ptgt->tgt_tmp_cnt_stack,
14742 mutex_exit(&ptgt->tgt_mutex);
14744 (void) fcp_finish_tgt(pptr, ptgt, lcount, tcount, cause);
14756 " for D_ID=0x%x", (ptgt) ? ptgt->tgt_d_id : 0);
14767 struct fcp_tgt *ptgt = (struct fcp_tgt *)tgt_handle;
14768 struct fcp_port *pptr = ptgt->tgt_port;
14775 if (ptgt->tgt_tid == NULL) {
14788 devlist->map_pd = ptgt->tgt_pd_handle;
14789 devlist->map_hard_addr.hard_addr = ptgt->tgt_hard_addr;
14790 devlist->map_did.port_id = ptgt->tgt_d_id;
14792 bcopy(&ptgt->tgt_node_wwn.raw_wwn[0], &devlist->map_nwwn, FC_WWN_SIZE);
14793 bcopy(&ptgt->tgt_port_wwn.raw_wwn[0], &devlist->map_pwwn, FC_WWN_SIZE);
14806 mutex_enter(&ptgt->tgt_mutex);
14807 ptgt->tgt_tid = NULL;
14808 mutex_exit(&ptgt->tgt_mutex);
14818 struct fcp_tgt *ptgt;
14822 ptgt = pptr->port_tgt_hash_table[i];
14823 while (ptgt != NULL) {
14824 struct fcp_tgt *next_tgt = ptgt->tgt_next;
14826 fcp_free_target(ptgt);
14827 ptgt = next_tgt;
14835 fcp_free_target(struct fcp_tgt *ptgt)
14840 mutex_enter(&ptgt->tgt_mutex);
14841 tid = ptgt->tgt_tid;
14852 ptgt->tgt_tid = NULL;
14853 mutex_exit(&ptgt->tgt_mutex);
14855 mutex_enter(&ptgt->tgt_mutex);
14858 plun = ptgt->tgt_lun;
14866 mutex_exit(&ptgt->tgt_mutex);
14867 fcp_dealloc_tgt(ptgt);
14921 struct fcp_tgt *ptgt;
14974 ptgt = fcp_lookup_target(pptr, pwwn);
14975 if (ptgt == NULL) {
14979 ptgt = fcp_alloc_tgt(pptr, devlist, lcount);
14980 if (ptgt == NULL) {
14989 mutex_enter(&ptgt->tgt_mutex);
14990 ptgt->tgt_statec_cause = FCP_CAUSE_USER_CREATE;
14991 ptgt->tgt_tmp_cnt = 1;
14992 ptgt->tgt_device_created = 0;
15000 ptgt->tgt_manual_config_only == 1) {
15002 ptgt->tgt_manual_config_only = 0;
15004 mutex_exit(&ptgt->tgt_mutex);
15010 tcount = ptgt->tgt_change_cnt;
15012 if (fcp_handle_mapflags(pptr, ptgt, devlist, lcount,
15016 mutex_enter(&ptgt->tgt_mutex);
15017 ptgt->tgt_manual_config_only = 1;
15018 mutex_exit(&ptgt->tgt_mutex);
15022 ptgt->tgt_change_cnt != tcount) {
15029 "fcp_create_on_demand: mapflags ptgt=%x, "
15032 ptgt, lcount, pptr->port_link_cnt,
15033 tcount, ptgt->tgt_change_cnt, rval);
15052 "fcp_create_on_demand(1): ntries=%x, ptgt=%x, "
15056 ntries, ptgt, lcount, pptr->port_link_cnt,
15057 tcount, ptgt->tgt_change_cnt, rval, ptgt->tgt_device_created,
15058 ptgt->tgt_tmp_cnt);
15060 mutex_enter(&ptgt->tgt_mutex);
15062 ptgt->tgt_change_cnt == tcount && ptgt->tgt_device_created == 0) {
15063 mutex_exit(&ptgt->tgt_mutex);
15069 mutex_enter(&ptgt->tgt_mutex);
15073 if (pptr->port_link_cnt != lcount || ptgt->tgt_change_cnt != tcount) {
15076 if (ptgt->tgt_tmp_cnt == 0 && ptgt->tgt_node_state ==
15084 "fcp_create_on_demand(2): ntries=%x, ptgt=%x, "
15088 ntries, ptgt, lcount, pptr->port_link_cnt,
15089 tcount, ptgt->tgt_change_cnt, rval, ptgt->tgt_device_created,
15090 ptgt->tgt_tmp_cnt);
15095 ptgt->tgt_manual_config_only = 1;
15097 mutex_exit(&ptgt->tgt_mutex);
15103 "fcp_create_on_demand(3): ntries=%x, ptgt=%x, "
15107 ntries, ptgt, lcount, pptr->port_link_cnt,
15108 tcount, ptgt->tgt_change_cnt, rval,
15109 ptgt->tgt_device_created, ptgt->tgt_d_id);
15113 if ((plun = ptgt->tgt_lun) != NULL) {
15126 if (ptgt->tgt_lun_cnt == 0) {
15127 ptgt->tgt_node_state = FCP_TGT_NODE_NONE;
15129 mutex_exit(&ptgt->tgt_mutex);
15139 mutex_enter(&ptgt->tgt_mutex);
15141 mutex_exit(&ptgt->tgt_mutex);
15160 mutex_enter(&ptgt->tgt_mutex);
15164 mutex_exit(&ptgt->tgt_mutex);
15171 mutex_enter(&ptgt->tgt_mutex);
15174 ptgt->tgt_manual_config_only = 0;
15177 ptgt->tgt_manual_config_only = 1;
15179 mutex_exit(&ptgt->tgt_mutex);
15222 struct fcp_tgt *ptgt;
15227 ptgt = icmd->ipkt_tgt;
15229 pptr = ptgt->tgt_port;
15294 ptgt->tgt_d_id, plun->lun_num, rsp->reserved_0,
15342 ptgt->tgt_d_id, plun->lun_num, sense_key,
15349 ptgt->tgt_d_id, plun->lun_num,
15363 ptgt->tgt_d_id, plun->lun_num, state, reason);
15366 ptgt->tgt_d_id, state, reason);
15375 fcp_handle_ipkt_errors(struct fcp_port *pptr, struct fcp_tgt *ptgt,
15405 rval, ptgt->tgt_d_id);
15417 rval, ptgt->tgt_d_id);
15442 rval, ptgt->tgt_d_id);
15453 mutex_enter(&ptgt->tgt_mutex);
15454 if (!FCP_STATE_CHANGED(pptr, ptgt, icmd)) {
15455 mutex_exit(&ptgt->tgt_mutex);
15461 op, ptgt->tgt_d_id, error);
15466 " for D_ID=0x%x", ptgt->tgt_d_id);
15467 mutex_exit(&ptgt->tgt_mutex);
15481 fcp_outstanding_lun_cmds(struct fcp_tgt *ptgt)
15486 for (plun = ptgt->tgt_lun; plun != NULL; plun = plun->lun_next) {
15507 struct fcp_tgt *ptgt;
15511 for (ptgt = pptr->port_tgt_hash_table[i]; ptgt != NULL;
15512 ptgt = ptgt->tgt_next) {
15513 if (!(ptgt->tgt_state & FCP_TGT_ORPHAN)) {
15530 for (ptgt = pptr->port_tgt_hash_table[i]; ptgt != NULL;
15531 ptgt = ptgt->tgt_next) {
15532 if (!(ptgt->tgt_state & FCP_TGT_ORPHAN)) {
15537 (la_wwn_t *)&ptgt->tgt_port_wwn.raw_wwn[0],
15546 devlist->map_did.port_id = ptgt->tgt_d_id;
15548 ptgt->tgt_hard_addr;
15553 bcopy(&ptgt->tgt_node_wwn.raw_wwn[0],
15556 bcopy(&ptgt->tgt_port_wwn.raw_wwn[0],
15575 struct fcp_tgt *ptgt;
15579 for (ptgt = pptr->port_tgt_hash_table[i]; ptgt != NULL;
15580 ptgt = ptgt->tgt_next) {
15581 mutex_enter(&ptgt->tgt_mutex);
15582 for (plun = ptgt->tgt_lun; plun != NULL;
15590 ptgt->tgt_change_cnt, 0, 0)) {
15601 mutex_exit(&ptgt->tgt_mutex);
16244 fcp_tgt_t *ptgt = plun->lun_tgt;
16250 fpkt->pkt_pd = ptgt->tgt_pd_handle;
16282 fpkt->pkt_cmd_fhdr.d_id = ptgt->tgt_d_id;