Lines Matching defs:pptr

411 static struct fcp_tgt *fcp_port_create_tgt(struct fcp_port *pptr,
423 static void fcp_handle_devices(struct fcp_port *pptr,
426 static int fcp_handle_mapflags(struct fcp_port *pptr,
430 static int fcp_send_els(struct fcp_port *pptr, struct fcp_tgt *ptgt,
432 static void fcp_update_state(struct fcp_port *pptr, uint32_t state,
440 static int fcp_unsol_prli(struct fcp_port *pptr, fc_unsol_buf_t *buf);
441 static struct fcp_ipkt *fcp_icmd_alloc(struct fcp_port *pptr,
444 static void fcp_icmd_free(struct fcp_port *pptr, struct fcp_ipkt *icmd);
445 static int fcp_alloc_dma(struct fcp_port *pptr, struct fcp_ipkt *icmd,
447 static void fcp_free_dma(struct fcp_port *pptr, struct fcp_ipkt *icmd);
448 static struct fcp_tgt *fcp_lookup_target(struct fcp_port *pptr,
450 static struct fcp_tgt *fcp_get_target_by_did(struct fcp_port *pptr,
462 static int fcp_finish_tgt(struct fcp_port *pptr, struct fcp_tgt *ptgt,
464 static void fcp_finish_init(struct fcp_port *pptr);
469 static int fcp_offline_target(struct fcp_port *pptr, struct fcp_tgt *ptgt,
471 static void fcp_offline_target_now(struct fcp_port *pptr,
481 static void fcp_scan_offline_luns(struct fcp_port *pptr);
482 static void fcp_scan_offline_tgts(struct fcp_port *pptr);
486 fcp_port *pptr);
490 struct fcp_port *pptr);
491 static int fcp_device_changed(struct fcp_port *pptr, struct fcp_tgt *ptgt,
495 static struct fcp_tgt *fcp_alloc_tgt(struct fcp_port *pptr,
498 static void fcp_queue_ipkt(struct fcp_port *pptr, fc_packet_t *fpkt);
504 static int fcp_handle_port_detach(struct fcp_port *pptr, int flag,
506 static void fcp_cleanup_port(struct fcp_port *pptr, int instance);
511 static int fcp_alloc_cmd_resp(struct fcp_port *pptr, fc_packet_t *fpkt,
513 static void fcp_free_cmd_resp(struct fcp_port *pptr, fc_packet_t *fpkt);
519 static int fcp_linkreset(struct fcp_port *pptr, struct scsi_address *ap,
523 static void fcp_cp_pinfo(struct fcp_port *pptr, fc_ulp_port_info_t *pinfo);
539 static void fcp_check_reset_delay(struct fcp_port *pptr);
540 static void fcp_abort_all(struct fcp_port *pptr, struct fcp_tgt *ttgt,
542 struct fcp_port *fcp_soft_state_unlink(struct fcp_port *pptr);
543 static struct fcp_lun *fcp_lookup_lun(struct fcp_port *pptr,
545 static void fcp_prepare_pkt(struct fcp_port *pptr, struct fcp_pkt *cmd,
548 static int fcp_dopoll(struct fcp_port *pptr, struct fcp_pkt *cmd);
550 struct fcp_lun *fcp_get_lun_from_cip(struct fcp_port *pptr,
552 static int fcp_pass_to_hp_and_wait(struct fcp_port *pptr,
555 static struct fcp_hp_elem *fcp_pass_to_hp(struct fcp_port *pptr,
558 static void fcp_retransport_cmd(struct fcp_port *pptr,
562 static void fcp_queue_pkt(struct fcp_port *pptr, struct fcp_pkt *cmd);
563 static void fcp_update_targets(struct fcp_port *pptr,
565 static int fcp_call_finish_init(struct fcp_port *pptr,
567 static int fcp_call_finish_init_held(struct fcp_port *pptr,
570 static void fcp_free_targets(struct fcp_port *pptr);
573 static int fcp_create_on_demand(struct fcp_port *pptr, uchar_t *pwwn);
577 static int fcp_handle_ipkt_errors(struct fcp_port *pptr,
580 static fc_portmap_t *fcp_construct_map(struct fcp_port *pptr,
582 static void fcp_offline_all(struct fcp_port *pptr, int lcount, int cause);
589 static int fcp_do_ns_registry(struct fcp_port *pptr, uint32_t s_id);
590 static void fcp_retry_ns_registry(struct fcp_port *pptr, uint32_t s_id);
594 static void fcp_reconfig_wait(struct fcp_port *pptr);
607 static void fcp_update_mpxio_path_verifybusy(struct fcp_port *pptr);
1437 struct fcp_port *pptr;
1481 pptr = fcp_port_head;
1482 while (pptr) {
1483 if (pptr->port_instance == (uint32_t)fioctl.fp_minor) {
1486 pptr = pptr->port_next;
1490 if (pptr == NULL) {
1493 mutex_enter(&pptr->port_mutex);
1498 mutex_exit(&pptr->port_mutex);
1505 mutex_exit(&pptr->port_mutex);
1508 link_cnt = pptr->port_link_cnt;
1512 if (bcmp(wwn_ptr->raw_wwn, pptr->port_pwwn.raw_wwn,
1515 mutex_exit(&pptr->port_mutex);
1558 if (pptr->port_state & (FCP_STATE_INIT | FCP_STATE_OFFLINE)) {
1560 mutex_exit(&pptr->port_mutex);
1564 for (i = 0; (i < fioctl.listlen) && (link_cnt == pptr->port_link_cnt);
1573 if ((ptgt = fcp_lookup_target(pptr,
1575 mutex_exit(&pptr->port_mutex);
1576 if (fc_ulp_get_remote_port(pptr->port_fp_handle,
1579 mutex_enter(&pptr->port_mutex);
1585 mutex_enter(&pptr->port_mutex);
1633 mutex_exit(&pptr->port_mutex);
1654 fcp_create_on_demand(pptr,
1666 fcp_log(CE_WARN, pptr->port_dip,
1677 mutex_enter(&pptr->port_mutex);
1686 fcp_log(CE_WARN, pptr->port_dip,
1693 mutex_exit(&pptr->port_mutex);
1743 struct fcp_port *pptr;
1789 pptr = fcp_port_head;
1790 while (pptr) {
1791 if (pptr->port_instance == (uint32_t)fioctl.fp_minor) {
1794 pptr = pptr->port_next;
1798 if (pptr == NULL) {
1825 mutex_enter(&pptr->port_mutex);
1828 for (ptgt = pptr->port_tgt_hash_table[i]; ptgt != NULL;
1904 mutex_exit(&pptr->port_mutex);
2290 struct fcp_port *pptr = NULL;
2362 pptr = fcp_port_head;
2363 while (pptr) {
2364 if (pptr->port_instance ==
2368 pptr = pptr->port_next;
2372 if (pptr == NULL) {
2380 ret = fc_ulp_busy_port(pptr->port_fp_handle);
2393 fcp_reconfig_wait(pptr);
2397 mutex_enter(&pptr->port_mutex);
2402 nodma = (pptr->port_fcp_dma == FC_NO_DVMA_SPACE)
2412 if (pptr->port_state & (FCP_STATE_INIT |
2415 } else if (pptr->port_state & FCP_STATE_ONLINING) {
2425 ptgt = fcp_lookup_target(pptr,
2436 mutex_exit(&pptr->port_mutex);
2437 ptgt = fcp_port_create_tgt(pptr,
2441 mutex_enter(&pptr->port_mutex);
2482 lcount = pptr->port_link_cnt;
2491 mutex_exit(&pptr->port_mutex);
2508 mutex_enter(&pptr->port_mutex);
2525 } else if ((plun = fcp_lookup_lun(pptr, (uchar_t *)wwn_ptr,
2537 mutex_exit(&pptr->port_mutex);
2551 icmd = fcp_icmd_alloc(pptr, ptgt,
2618 hp->s_id = pptr->port_id;
2654 fc_ulp_transport(pptr->port_fp_handle,
2682 if (fcp_validate_fcp_response(rsp, pptr) != FC_SUCCESS) {
2683 fcp_log(CE_WARN, pptr->port_dip,
2832 fc_ulp_idle_port(pptr->port_fp_handle);
2874 fcp_port_t *pptr = ptgt->tgt_port;
3024 struct fcp_port *pptr = NULL;
3027 &pptr)) != 0) {
3031 ASSERT(pptr != NULL);
3037 mutex_enter(&pptr->port_mutex);
3038 if (pptr->port_state & FCP_STATE_OFFLINE) {
3039 mutex_exit(&pptr->port_mutex);
3051 if ((pptr->port_state & FCP_STATE_INIT) && pptr->port_tmp_cnt) {
3052 mutex_exit(&pptr->port_mutex);
3056 link_cnt = pptr->port_link_cnt;
3057 mutex_exit(&pptr->port_mutex);
3102 struct fcp_ioctl *fioctl, struct fcp_port **pptr)
3149 *pptr = t_pptr;
3166 * Argument: pptr fcp port structure
3179 fcp_port_create_tgt(struct fcp_port *pptr, la_wwn_t *pwwn, int *ret_val,
3192 if (fc_ulp_get_remote_port(pptr->port_fp_handle, pwwn,
3196 if (fc_ulp_pwwn_to_portmap(pptr->port_fp_handle, pwwn,
3207 lcount = pptr->port_link_cnt;
3208 ptgt = fcp_alloc_tgt(pptr, &devlist, lcount);
3210 fcp_log(CE_WARN, pptr->port_dip,
3276 struct fcp_port *pptr;
3287 pptr = ptgt->tgt_port;
3289 lcount = pptr->port_link_cnt;
3293 icmd = fcp_icmd_alloc(pptr, ptgt, sizeof (la_els_logi_t),
3295 pptr->port_state & FCP_STATE_FCA_IS_NODMA,
3328 hp->s_id = pptr->port_id; /* source ID */
3354 fc_ulp_login(pptr->port_fp_handle, &fpkt, 1);
3554 struct fcp_port *pptr;
3557 pptr = icmd->ipkt_port;
3573 fcp_icmd_free(pptr, icmd);
3660 struct fcp_port *pptr;
3663 pptr = ddi_get_soft_state(fcp_softstate, instance);
3694 return (fcp_handle_port_detach(pptr, flag, instance));
3715 struct fcp_port *pptr = NULL; /* our soft state */
3741 if ((pptr = fcp_get_port(port_handle)) == NULL) {
3747 is_mpxio = pptr->port_mpxio;
3776 FCP_TRACE(fcp_logq, pptr->port_instbuf,
3787 ASSERT(pptr != NULL);
3789 mdi_devi_enter(pptr->port_dip, &circ);
3791 ndi_devi_enter(pptr->port_dip, &circ);
3795 if ((cdip = ndi_devi_find(pptr->port_dip, ndi_nm,
3798 pip = mdi_pi_find(pptr->port_dip, NULL, ndi_addr);
3820 FCP_DTRACE(fcp_logq, pptr->port_instbuf,
3846 ASSERT(pptr != NULL);
3849 mutex_enter(&pptr->port_mutex);
3853 if ((plun = fcp_get_lun_from_cip(pptr, cip)) == NULL) {
3854 mutex_exit(&pptr->port_mutex);
3863 lcount = pptr->port_link_cnt;
3865 mutex_exit(&pptr->port_mutex);
3872 mdi_devi_exit(pptr->port_dip, circ);
3874 ndi_devi_exit(pptr->port_dip, circ);
3878 *rval = fcp_pass_to_hp_and_wait(pptr, plun, cip,
3907 if (FC_TOP_EXTERNAL(pptr->port_topology) &&
3923 ASSERT(pptr != NULL);
3925 mutex_enter(&pptr->port_mutex);
3929 if ((plun = fcp_get_lun_from_cip(pptr, cip)) == NULL) {
3930 mutex_exit(&pptr->port_mutex);
3934 lcount = pptr->port_link_cnt;
3936 mutex_exit(&pptr->port_mutex);
3949 mdi_devi_exit(pptr->port_dip, circ);
3951 ndi_devi_exit(pptr->port_dip, circ);
3955 *rval = fcp_pass_to_hp_and_wait(pptr, plun, cip,
3980 *rval = ndi_dc_devi_create(dcp, pptr->port_dip,
3997 *rval = fcp_create_on_demand(pptr, bytes);
3999 mutex_enter(&pptr->port_mutex);
4000 ptgt = fcp_lookup_target(pptr, (uchar_t *)bytes);
4023 mutex_exit(&pptr->port_mutex);
4113 fcp_log(CE_WARN, pptr->port_dip,
4128 ASSERT(pptr != NULL);
4129 mutex_enter(&pptr->port_mutex);
4133 if ((plun = fcp_get_lun_from_cip(pptr, cip)) == NULL) {
4134 mutex_exit(&pptr->port_mutex);
4138 mutex_exit(&pptr->port_mutex);
4169 ASSERT(pptr != NULL);
4170 ASSERT(pptr->port_dip != NULL);
4171 if (ndi_dc_return_bus_state(pptr->port_dip, dcp) !=
4184 ASSERT(pptr != NULL);
4185 (void) fcp_linkreset(pptr, NULL, KM_SLEEP);
4197 mdi_devi_exit(pptr->port_dip, circ);
4199 ndi_devi_exit(pptr->port_dip, circ);
4218 struct fcp_port *pptr;
4220 if ((pptr = fcp_get_port(port_handle)) == NULL || claimed) {
4224 mutex_enter(&pptr->port_mutex);
4225 if (pptr->port_state & (FCP_STATE_DETACHING |
4227 mutex_exit(&pptr->port_mutex);
4230 mutex_exit(&pptr->port_mutex);
4246 if (fcp_unsol_prli(pptr, buf) == FC_SUCCESS) {
4298 struct fcp_port *pptr;
4301 if ((pptr = fcp_get_port(port_handle)) == NULL) {
4306 FCP_TRACE(fcp_logq, pptr->port_instbuf,
4312 mutex_enter(&pptr->port_mutex);
4317 if (pptr->port_state & (FCP_STATE_DETACHING |
4319 mutex_exit(&pptr->port_mutex);
4330 pptr->port_state |= FCP_STATE_IN_CB_DEVC;
4343 pptr->port_phys_state = port_state;
4346 mutex_exit(&pptr->port_mutex);
4351 fcp_log(CE_WARN, pptr->port_dip,
4354 pptr->port_instance);
4356 mutex_enter(&pptr->port_mutex);
4357 pptr->port_state &= ~FCP_STATE_IN_CB_DEVC;
4358 mutex_exit(&pptr->port_mutex);
4363 mutex_enter(&pptr->port_mutex);
4366 if (pptr->port_id != port_sid) {
4367 FCP_TRACE(fcp_logq, pptr->port_instbuf,
4369 "fcp: Port S_ID=0x%x => 0x%x", pptr->port_id,
4378 pptr->port_id = port_sid;
4388 FCP_TRACE(fcp_logq, pptr->port_instbuf,
4391 if ((pptr->port_state & FCP_STATE_OFFLINE) && dev_cnt) {
4397 pptr->port_tmp_cnt += dev_cnt;
4398 pptr->port_state &= ~FCP_STATE_OFFLINE;
4399 pptr->port_state |= FCP_STATE_INIT;
4400 link_count = pptr->port_link_cnt;
4401 fcp_handle_devices(pptr, devlist, dev_cnt,
4404 pptr->port_link_cnt++;
4405 ASSERT(!(pptr->port_state & FCP_STATE_SUSPENDED));
4406 fcp_update_state(pptr, (FCP_LUN_BUSY |
4408 if (pptr->port_mpxio) {
4409 fcp_update_mpxio_path_verifybusy(pptr);
4411 pptr->port_state |= FCP_STATE_OFFLINE;
4412 pptr->port_state &=
4414 pptr->port_tmp_cnt = 0;
4416 mutex_exit(&pptr->port_mutex);
4425 FCP_TRACE(fcp_logq, pptr->port_instbuf,
4429 pptr->port_link_cnt++;
4431 while (pptr->port_ipkt_cnt) {
4432 mutex_exit(&pptr->port_mutex);
4434 mutex_enter(&pptr->port_mutex);
4437 pptr->port_topology = port_top;
4443 fcp_update_state(pptr, FCP_LUN_BUSY | FCP_LUN_MARK,
4446 pptr->port_state &= ~(FCP_STATE_INIT | FCP_STATE_OFFLINE);
4447 pptr->port_state |= FCP_STATE_ONLINING;
4448 pptr->port_tmp_cnt = dev_cnt;
4449 link_count = pptr->port_link_cnt;
4451 pptr->port_deadline = fcp_watchdog_time +
4459 FCP_TRACE(fcp_logq, pptr->port_instbuf,
4463 pptr->port_state &= ~FCP_STATE_ONLINING;
4464 pptr->port_state |= FCP_STATE_ONLINE;
4473 if (pptr->port_state & FCP_STATE_NS_REG_FAILED) {
4474 fcp_retry_ns_registry(pptr, port_sid);
4477 fcp_handle_devices(pptr, devlist, dev_cnt, link_count,
4486 if (pptr->port_state & FCP_STATE_NS_REG_FAILED) {
4487 pptr->port_state &= ~FCP_STATE_NS_REG_FAILED;
4490 pptr->port_tmp_cnt -= dev_cnt;
4491 fcp_log(CE_WARN, pptr->port_dip,
4495 FCP_TRACE(fcp_logq, pptr->port_instbuf,
4499 scsi_hba_reset_notify_callback(&pptr->port_mutex,
4500 &pptr->port_reset_notify_listf);
4502 mutex_exit(&pptr->port_mutex);
4507 ASSERT(pptr->port_state & FCP_STATE_OFFLINE);
4508 FCP_TRACE(fcp_logq, pptr->port_instbuf,
4511 mutex_exit(&pptr->port_mutex);
4519 if (pptr->port_state & (FCP_STATE_OFFLINE |
4530 pptr->port_state &= ~FCP_STATE_IN_CB_DEVC;
4531 mutex_exit(&pptr->port_mutex);
4535 if (pptr->port_state & FCP_STATE_NS_REG_FAILED) {
4536 fcp_retry_ns_registry(pptr, port_sid);
4543 if (!pptr->port_ipkt_cnt) {
4544 pptr->port_deadline = fcp_watchdog_time +
4559 fcp_update_targets(pptr, devlist, dev_cnt,
4562 link_count = pptr->port_link_cnt;
4564 fcp_handle_devices(pptr, devlist, dev_cnt,
4567 pptr->port_state &= ~FCP_STATE_IN_CB_DEVC;
4569 mutex_exit(&pptr->port_mutex);
4573 if (pptr->port_state & FCP_STATE_NS_REG_FAILED) {
4574 fcp_retry_ns_registry(pptr, port_sid);
4578 mutex_exit(&pptr->port_mutex);
4582 fcp_log(CE_WARN, pptr->port_dip,
4584 mutex_exit(&pptr->port_mutex);
4601 * Argument: *pptr Fcp port structure.
4612 * Notes: The pptr->port_mutex must be held.
4615 fcp_handle_devices(struct fcp_port *pptr, fc_portmap_t devlist[],
4623 FCP_TRACE(fcp_logq, pptr->port_instbuf,
4633 * accessible through this (pptr) local port (The list walked is the
4645 for (i = 0; (i < dev_cnt) && (pptr->port_link_cnt == link_cnt); i++) {
4652 ptgt = fcp_lookup_target(pptr,
4671 * be reached anymore through the local port (pptr). It is offlined.
4675 for (ptgt = pptr->port_tgt_hash_table[i]; ptgt != NULL;
4681 fcp_offline_target_now(pptr, ptgt,
4696 for (i = 0; (i < dev_cnt) && (pptr->port_link_cnt == link_cnt); i++) {
4700 (void) fcp_call_finish_init_held(pptr, ptgt, link_cnt,
4719 ptgt = fcp_lookup_target(pptr,
4729 FCP_TRACE(fcp_logq, pptr->port_instbuf,
4743 FCP_TRACE(fcp_logq, pptr->port_instbuf,
4758 if (fcp_handle_mapflags(pptr, ptgt, map_entry,
4780 mutex_exit(&pptr->port_mutex);
4792 mutex_enter(&pptr->port_mutex);
4795 (void) fcp_offline_target(pptr, ptgt,
4811 (void) fcp_offline_target(pptr, ptgt,
4824 if (fcp_device_changed(pptr, ptgt,
4830 if (fcp_handle_mapflags(pptr, ptgt,
4838 fcp_log(CE_WARN, pptr->port_dip,
4845 if (check_finish_init && pptr->port_link_cnt == link_cnt) {
4847 (void) fcp_call_finish_init_held(pptr, ptgt, link_cnt,
4849 } else if (dev_cnt == 0 && pptr->port_link_cnt == link_cnt) {
4850 fcp_offline_all(pptr, link_cnt, cause);
4858 struct fcp_port *pptr;
4864 pptr = ptgt->tgt_port;
4873 fcp_log(CE_WARN, pptr->port_dip,
4895 rscn_count = fc_ulp_get_rscn_count(pptr->port_fp_handle);
4897 sizeof (struct fcp_reportlun_resp), pptr->port_link_cnt,
4899 FCP_TRACE(fcp_logq, pptr->port_instbuf,
4918 * Argument: *pptr FCP Port structure.
4928 * Notes: pptr->port_mutex must be owned.
4931 fcp_handle_mapflags(struct fcp_port *pptr, struct fcp_tgt *ptgt,
4943 ASSERT(mutex_owned(&pptr->port_mutex));
4953 mutex_exit(&pptr->port_mutex);
4954 ptgt = fcp_alloc_tgt(pptr, map_entry, link_cnt);
4955 mutex_enter(&pptr->port_mutex);
4958 fcp_log(CE_WARN, pptr->port_dip,
5012 mutex_exit(&pptr->port_mutex);
5016 mutex_enter(&pptr->port_mutex);
5028 if (FC_TOP_EXTERNAL(pptr->port_topology) &&
5032 } else if (FC_TOP_EXTERNAL(pptr->port_topology) &&
5056 if (FC_TOP_EXTERNAL(pptr->port_topology) && pptr->port_boot_wwn[0]) {
5057 if (bcmp((caddr_t)pptr->port_boot_wwn,
5065 FCP_TRACE(fcp_logq, pptr->port_instbuf,
5083 mutex_exit(&pptr->port_mutex);
5096 icmd = fcp_icmd_alloc(pptr, ptgt, alloc, alloc, 0,
5097 pptr->port_state & FCP_STATE_FCA_IS_NODMA, lcount, tcount,
5106 mutex_enter(&pptr->port_mutex);
5113 if ((fcp_send_els(pptr, ptgt, icmd, opcode,
5117 fcp_icmd_free(pptr, icmd);
5120 mutex_enter(&pptr->port_mutex);
5131 * Argument: *pptr Fcp port.
5143 fcp_send_els(struct fcp_port *pptr, struct fcp_tgt *ptgt,
5156 ASSERT(ptgt->tgt_port == pptr);
5158 FCP_TRACE(fcp_logq, pptr->port_instbuf,
5175 icmd = fcp_icmd_alloc(pptr, ptgt, alloc, alloc, 0,
5176 pptr->port_state & FCP_STATE_FCA_IS_NODMA,
5203 hp->s_id = pptr->port_id; /* source ID */
5240 mutex_enter(&pptr->port_mutex);
5243 mutex_exit(&pptr->port_mutex);
5245 rval = fc_ulp_login(pptr->port_fp_handle, &fpkt, 1);
5253 res = fcp_handle_ipkt_errors(pptr, ptgt, icmd,
5256 FCP_TRACE(fcp_logq, pptr->port_instbuf,
5260 mutex_exit(&pptr->port_mutex);
5314 mutex_enter(&pptr->port_mutex);
5317 mutex_exit(&pptr->port_mutex);
5319 rval = fc_ulp_issue_els(pptr->port_fp_handle, fpkt);
5327 res = fcp_handle_ipkt_errors(pptr, ptgt, icmd,
5330 mutex_exit(&pptr->port_mutex);
5341 FCP_TRACE(fcp_logq, pptr->port_instbuf,
5347 fcp_icmd_free(pptr, icmd);
5366 fcp_update_state(struct fcp_port *pptr, uint32_t state, int cause)
5371 ASSERT(mutex_owned(&pptr->port_mutex));
5374 for (ptgt = pptr->port_tgt_hash_table[i]; ptgt != NULL;
5389 fcp_offline_all(struct fcp_port *pptr, int lcount, int cause)
5395 ASSERT(mutex_owned(&pptr->port_mutex));
5398 for (ptgt = pptr->port_tgt_hash_table[i]; ptgt != NULL;
5407 pptr->port_tmp_cnt = ndevs;
5410 for (ptgt = pptr->port_tgt_hash_table[i]; ptgt != NULL;
5412 (void) fcp_call_finish_init_held(pptr, ptgt,
5528 struct fcp_port *pptr;
5533 for (pptr = fcp_port_head; pptr != NULL; pptr = pptr->port_next) {
5534 if (pptr->port_fp_handle == port_handle) {
5540 return (pptr);
5548 struct fcp_port *pptr = icmd->ipkt_port;
5556 fcp_log(CE_WARN, pptr->port_dip,
5562 fcp_icmd_free(pptr, icmd);
5593 fcp_unsol_prli(struct fcp_port *pptr, fc_unsol_buf_t *buf)
5607 if ((ptgt = fcp_get_target_by_did(pptr, buf->ub_frame.s_id)) !=
5614 mutex_enter(&pptr->port_mutex);
5615 lcount = pptr->port_link_cnt;
5616 mutex_exit(&pptr->port_mutex);
5618 if ((icmd = fcp_icmd_alloc(pptr, ptgt, sizeof (la_els_prli_t),
5620 pptr->port_state & FCP_STATE_FCA_IS_NODMA,
5675 mutex_enter(&pptr->port_mutex);
5676 if (!FCP_LINK_STATE_CHANGED(pptr, icmd)) {
5678 mutex_exit(&pptr->port_mutex);
5680 if ((rval = fc_ulp_issue_els(pptr->port_fp_handle, fpkt)) !=
5684 fcp_queue_ipkt(pptr, fpkt);
5688 fcp_icmd_free(pptr, icmd);
5692 mutex_exit(&pptr->port_mutex);
5693 fcp_icmd_free(pptr, icmd);
5697 (void) fc_ulp_ubrelease(pptr->port_fp_handle, 1, &buf->ub_token);
5711 * and tcount which came respectively from pptr->link_cnt and
5714 * Argument: *pptr Fcp port.
5729 fcp_icmd_alloc(struct fcp_port *pptr, struct fcp_tgt *ptgt, int cmd_len,
5738 pptr->port_dmacookie_sz + pptr->port_priv_pkt_len,
5741 fcp_log(CE_WARN, pptr->port_dip,
5757 mutex_enter(&pptr->port_mutex);
5758 icmd->ipkt_port = pptr;
5759 mutex_exit(&pptr->port_mutex);
5775 pptr->port_dmacookie_sz);
5811 FCP_TRACE(fcp_logq, pptr->port_instbuf,
5824 if (fcp_alloc_dma(pptr, icmd, nodma, KM_NOSLEEP) != FC_SUCCESS) {
5839 if (fc_ulp_init_packet(pptr->port_fp_handle, fpkt, KM_NOSLEEP)
5841 FCP_TRACE(fcp_logq, pptr->port_instbuf,
5849 if (fc_ulp_init_packet(pptr->port_fp_handle, fpkt, KM_NOSLEEP)
5851 FCP_TRACE(fcp_logq, pptr->port_instbuf,
5858 mutex_enter(&pptr->port_mutex);
5859 if (pptr->port_state & (FCP_STATE_DETACHING |
5863 mutex_exit(&pptr->port_mutex);
5865 rval = fc_ulp_uninit_packet(pptr->port_fp_handle, fpkt);
5877 pptr->port_ipkt_cnt++;
5879 mutex_exit(&pptr->port_mutex);
5891 fcp_free_dma(pptr, icmd);
5893 kmem_free(icmd, sizeof (struct fcp_ipkt) + pptr->port_priv_pkt_len +
5894 (size_t)pptr->port_dmacookie_sz);
5904 * Argument: *pptr Fcp port.
5910 fcp_icmd_free(struct fcp_port *pptr, struct fcp_ipkt *icmd)
5915 (void) fc_ulp_uninit_packet(pptr->port_fp_handle,
5923 fcp_free_dma(pptr, icmd);
5925 kmem_free(icmd, sizeof (struct fcp_ipkt) + pptr->port_priv_pkt_len +
5926 (size_t)pptr->port_dmacookie_sz);
5928 mutex_enter(&pptr->port_mutex);
5936 pptr->port_ipkt_cnt--;
5937 mutex_exit(&pptr->port_mutex);
5946 * Argument: *pptr FCP port.
5955 fcp_alloc_dma(struct fcp_port *pptr, struct fcp_ipkt *icmd,
5988 rval = fcp_alloc_cmd_resp(pptr, fpkt, flags);
5998 !(pptr->port_state & FCP_STATE_FCA_IS_NODMA)) {
6002 if (ddi_dma_alloc_handle(pptr->port_dip,
6003 &pptr->port_data_dma_attr, DDI_DMA_DONTWAIT,
6009 &pptr->port_dma_acc_attr, DDI_DMA_CONSISTENT,
6029 if (ccount > pptr->port_data_dma_attr.dma_attr_sgllen) {
6084 fcp_free_cmd_resp(pptr, fpkt);
6093 fcp_free_dma(struct fcp_port *pptr, struct fcp_ipkt *icmd)
6122 fcp_free_cmd_resp(pptr, fpkt);
6131 * Argument: *pptr FCP port.
6138 * The mutex pptr->port_mutex must be owned.
6142 fcp_lookup_target(struct fcp_port *pptr, uchar_t *wwn)
6147 ASSERT(mutex_owned(&pptr->port_mutex));
6151 for (ptgt = pptr->port_tgt_hash_table[hash]; ptgt != NULL;
6168 fcp_get_target_by_did(struct fcp_port *pptr, uint32_t d_id)
6176 if (fc_ulp_get_pwwn_by_did(pptr->port_fp_handle, port_id,
6178 mutex_enter(&pptr->port_mutex);
6179 ptgt = fcp_lookup_target(pptr, pwwn.raw_wwn);
6180 mutex_exit(&pptr->port_mutex);
6199 struct fcp_port *pptr;
6215 pptr = icmd->ipkt_port;
6226 FCP_TRACE(fcp_logq, pptr->port_instbuf,
6252 FCP_TRACE(fcp_logq, pptr->port_instbuf,
6263 if (fcp_send_els(pptr, ptgt, icmd, LA_ELS_PRLI,
6273 FCP_TRACE(fcp_logq, pptr->port_instbuf,
6301 fc_ulp_disable_relogin(pptr->port_fp_handle,
6306 mutex_enter(&pptr->port_mutex);
6312 FCP_TRACE(fcp_logq, pptr->port_instbuf,
6317 mutex_exit(&pptr->port_mutex);
6321 mutex_exit(&pptr->port_mutex);
6340 fcp_log(CE_WARN, pptr->port_dip,
6378 mutex_enter(&pptr->port_mutex);
6380 fcp_log(CE_WARN, pptr->port_dip,
6385 pptr->port_instbuf, fcp_trace,
6391 mutex_exit(&pptr->port_mutex);
6399 fcp_icmd_free(pptr, icmd);
6404 fcp_log(CE_WARN, pptr->port_dip,
6422 fcp_queue_ipkt(pptr, fpkt);
6426 FCP_TRACE(fcp_logq, pptr->port_instbuf,
6436 mutex_enter(&pptr->port_mutex);
6440 mutex_exit(&pptr->port_mutex);
6449 rval = fc_ulp_issue_els(pptr->port_fp_handle,
6457 fcp_queue_ipkt(pptr, fpkt);
6462 fcp_log(CE_NOTE, pptr->port_dip,
6467 FCP_TRACE(fcp_logq, pptr->port_instbuf,
6471 mutex_exit(&pptr->port_mutex);
6478 fcp_queue_ipkt(pptr, fpkt);
6482 mutex_enter(&pptr->port_mutex);
6485 mutex_exit(&pptr->port_mutex);
6488 FCP_TRACE(fcp_logq, pptr->port_instbuf,
6492 mutex_exit(&pptr->port_mutex);
6498 (void) fcp_call_finish_init(pptr, ptgt, icmd->ipkt_link_cnt,
6500 fcp_icmd_free(pptr, icmd);
6519 struct fcp_port *pptr;
6531 pptr = ptgt->tgt_port;
6532 ASSERT(pptr != NULL);
6534 FCP_TRACE(fcp_logq, pptr->port_instbuf,
6538 nodma = (pptr->port_fcp_dma == FC_NO_DVMA_SPACE) ? 1 : 0;
6539 icmd = fcp_icmd_alloc(pptr, ptgt, sizeof (struct fcp_cmd),
6564 hp->s_id = pptr->port_id;
6633 fca_dev = fc_ulp_get_fca_device(pptr->port_fp_handle, d_id);
6655 fcp_log(CE_WARN, pptr->port_dip,
6665 mutex_enter(&pptr->port_mutex);
6668 mutex_exit(&pptr->port_mutex);
6669 if (fcp_transport(pptr->port_fp_handle, fpkt, 1) !=
6671 fcp_icmd_free(pptr, icmd);
6676 FCP_TRACE(fcp_logq, pptr->port_instbuf,
6680 mutex_exit(&pptr->port_mutex);
6681 fcp_icmd_free(pptr, icmd);
6700 struct fcp_port *pptr = ptgt->tgt_port;
6837 FCP_TRACE(fcp_logq, pptr->port_instbuf,
6859 FCP_TRACE(fcp_logq, pptr->port_instbuf,
6864 FCP_TRACE(fcp_logq, pptr->port_instbuf,
6873 FCP_TRACE(fcp_logq, pptr->port_instbuf,
6900 struct fcp_port *pptr;
6906 pptr = ptgt->tgt_port;
6917 FCP_TRACE(fcp_logq, pptr->port_instbuf,
6955 FCP_TRACE(fcp_logq, pptr->port_instbuf,
6980 mutex_enter(&pptr->port_mutex);
6982 if (!FCP_STATE_CHANGED(pptr, ptgt, icmd)) {
6984 mutex_exit(&pptr->port_mutex);
6987 FCP_TRACE(fcp_logq, pptr->port_instbuf,
6992 mutex_exit(&pptr->port_mutex);
6994 (void) fcp_call_finish_init(pptr, ptgt, icmd->ipkt_link_cnt,
6996 fcp_icmd_free(pptr, icmd);
7002 mutex_enter(&pptr->port_mutex);
7004 if (FCP_STATE_CHANGED(pptr, ptgt, icmd)) {
7005 FCP_TRACE(fcp_logq, pptr->port_instbuf,
7010 mutex_exit(&pptr->port_mutex);
7011 (void) fcp_call_finish_init(pptr, ptgt, icmd->ipkt_link_cnt,
7013 fcp_icmd_free(pptr, icmd);
7019 mutex_exit(&pptr->port_mutex);
7030 if (fcp_validate_fcp_response(rsp, pptr) != FC_SUCCESS) {
7037 FCP_TRACE(fcp_logq, pptr->port_instbuf,
7047 fcp_queue_ipkt(pptr, fpkt);
7061 FCP_TRACE(fcp_logq, pptr->port_instbuf,
7093 (void) fcp_call_finish_init(pptr, ptgt,
7096 fcp_icmd_free(pptr, icmd);
7127 (void) fcp_call_finish_init(pptr, ptgt,
7130 fcp_icmd_free(pptr, icmd);
7146 if (!(pptr->port_state & FCP_STATE_FCA_IS_NODMA)) {
7170 (void) fcp_call_finish_init(pptr, ptgt, icmd->ipkt_link_cnt,
7172 fcp_icmd_free(pptr, icmd);
7184 struct fcp_port *pptr = ptgt->tgt_port;
7188 mutex_enter(&pptr->port_mutex);
7190 mutex_exit(&pptr->port_mutex);
7191 FCP_TRACE(fcp_logq, pptr->port_instbuf,
7198 fcp_queue_ipkt(pptr, fpkt);
7200 FCP_TRACE(fcp_logq, pptr->port_instbuf,
7204 mutex_exit(&pptr->port_mutex);
7205 (void) fcp_call_finish_init(pptr, ptgt,
7208 fcp_icmd_free(pptr, icmd);
7212 (void) fcp_call_finish_init(pptr, ptgt, icmd->ipkt_link_cnt,
7214 fcp_icmd_free(pptr, icmd);
7235 struct fcp_port *pptr;
7246 pptr = icmd->ipkt_port;
7256 FCP_TRACE(fcp_logq, pptr->port_instbuf,
7260 pptr->port_instance, ptgt->tgt_d_id,
7330 FCP_TRACE(fcp_logq, pptr->port_instbuf,
7342 FCP_TRACE(fcp_logq, pptr->port_instbuf,
7350 FCP_TRACE(fcp_logq, pptr->port_instbuf,
7382 FCP_TRACE(fcp_logq, pptr->port_instbuf,
7391 mutex_enter(&pptr->port_mutex);
7404 if (fail || pptr->port_mpxio == 0) {
7411 mutex_exit(&pptr->port_mutex);
7418 (void) fcp_call_finish_init(pptr, ptgt, icmd->ipkt_link_cnt,
7421 fcp_icmd_free(pptr, icmd);
7438 struct fcp_port *pptr;
7447 pptr = icmd->ipkt_port;
7457 FCP_TRACE(fcp_logq, pptr->port_instbuf,
7460 "dtype=0x%x pqual: 0x%x", pptr->port_instance, ptgt->tgt_d_id,
7467 fcp_log(CE_CONT, pptr->port_dip,
7472 FCP_TRACE(fcp_logq, pptr->port_instbuf,
7480 (void) fcp_call_finish_init(pptr, ptgt, icmd->ipkt_link_cnt,
7482 fcp_icmd_free(pptr, icmd);
7501 mutex_enter(&pptr->port_mutex);
7502 if (!pptr->port_notify) {
7508 pptr->port_notify = 1;
7509 mutex_exit(&pptr->port_mutex);
7510 (void) fc_ulp_port_notify(pptr->port_fp_handle, cmd);
7511 mutex_enter(&pptr->port_mutex);
7516 FCP_TRACE(fcp_logq, pptr->port_instbuf,
7520 mutex_exit(&pptr->port_mutex);
7523 (void) fcp_call_finish_init(pptr, ptgt,
7526 fcp_icmd_free(pptr, icmd);
7530 mutex_exit(&pptr->port_mutex);
7546 (void) fcp_call_finish_init(pptr, ptgt,
7555 fcp_icmd_free(pptr, icmd);
7578 struct fcp_port *pptr;
7583 pptr = icmd->ipkt_port;
7589 (void) fcp_call_finish_init(pptr, ptgt, icmd->ipkt_link_cnt,
7591 fcp_icmd_free(pptr, icmd);
7598 FCP_TRACE(fcp_logq, pptr->port_instbuf,
7601 pptr->port_instance, ptgt->tgt_d_id);
7620 fcp_log(CE_NOTE, pptr->port_dip, "!Can not support"
7624 (void) fcp_call_finish_init(pptr, ptgt, icmd->ipkt_link_cnt,
7626 fcp_icmd_free(pptr, icmd);
7649 FCP_TRACE(fcp_logq, pptr->port_instbuf,
7667 (void) fcp_call_finish_init(pptr, ptgt,
7672 fcp_icmd_free(pptr, icmd);
7677 FCP_TRACE(fcp_logq, pptr->port_instbuf,
7729 mutex_enter(&pptr->port_mutex);
7731 if (!FCP_STATE_CHANGED(pptr, ptgt, icmd)) {
7740 mutex_exit(&pptr->port_mutex);
7743 fcp_log(CE_NOTE, pptr->port_dip,
7749 FCP_TRACE(fcp_logq, pptr->port_instbuf,
7754 mutex_exit(&pptr->port_mutex);
7756 (void) fcp_call_finish_init(pptr, ptgt,
7759 fcp_icmd_free(pptr, icmd);
7775 fcp_log(CE_NOTE, pptr->port_dip,
7787 FCP_TRACE(fcp_logq, pptr->port_instbuf,
7790 pptr->port_instance, ptgt->tgt_d_id, nluns_claimed);
7798 FCP_TRACE(fcp_logq, pptr->port_instbuf,
7826 fcp_log(CE_NOTE, pptr->port_dip,
7862 mutex_enter(&pptr->port_mutex);
7864 if (!FCP_STATE_CHANGED(pptr, ptgt, icmd)) {
7865 fcp_log(CE_NOTE, pptr->port_dip,
7871 pptr->port_instbuf, fcp_trace,
7878 mutex_exit(&pptr->port_mutex);
7896 (void) fcp_call_finish_init(pptr, ptgt, icmd->ipkt_link_cnt,
7901 fcp_log(CE_WARN, pptr->port_dip,
7903 (void) fcp_call_finish_init(pptr, ptgt, icmd->ipkt_link_cnt,
7908 fcp_icmd_free(pptr, icmd);
7943 fcp_finish_tgt(struct fcp_port *pptr, struct fcp_tgt *ptgt,
7947 ASSERT(pptr != NULL);
7950 FCP_TRACE(fcp_logq, pptr->port_instbuf,
7955 ASSERT(mutex_owned(&pptr->port_mutex));
7957 if ((pptr->port_link_cnt != link_cnt) ||
7983 rval = fcp_offline_target(pptr, ptgt, link_cnt,
8023 fcp_finish_init(struct fcp_port *pptr)
8026 bzero(pptr->port_finish_stack, sizeof (pptr->port_finish_stack));
8027 pptr->port_finish_depth = getpcstack(pptr->port_finish_stack,
8031 ASSERT(mutex_owned(&pptr->port_mutex));
8033 FCP_TRACE(fcp_logq, pptr->port_instbuf,
8035 " entering; ipkt count=%d", pptr->port_ipkt_cnt);
8037 if ((pptr->port_state & FCP_STATE_ONLINING) &&
8038 !(pptr->port_state & (FCP_STATE_SUSPENDED |
8040 pptr->port_state &= ~FCP_STATE_ONLINING;
8041 pptr->port_state |= FCP_STATE_ONLINE;
8045 cv_broadcast(&pptr->port_config_cv);
8058 struct fcp_port *pptr;
8064 pptr = ptgt->tgt_port;
8066 ASSERT(pptr != NULL);
8075 FCP_TRACE(fcp_logq, pptr->port_instbuf,
8090 (!fcp_pass_to_hp(pptr, plun, plun->lun_cip,
8093 FCP_TRACE(fcp_logq, pptr->port_instbuf,
8108 FCP_TRACE(fcp_logq, pptr->port_instbuf,
8122 if (!fcp_pass_to_hp(pptr, plun, cip, FCP_ONLINE,
8131 if (!fcp_pass_to_hp(pptr, plun, cip, FCP_ONLINE,
8133 fcp_log(CE_CONT, pptr->port_dip,
8152 struct fcp_port *pptr = plun->lun_tgt->tgt_port;
8153 int is_mpxio = pptr->port_mpxio;
8162 FCP_TRACE(fcp_logq, pptr->port_instbuf, fcp_trace,
8168 FCP_TRACE(fcp_logq, pptr->port_instbuf,
8234 if (fc_ulp_busy_port(pptr->port_fp_handle) != 0) {
8239 mdi_devi_enter(pptr->port_dip, &circ);
8241 ndi_devi_enter(pptr->port_dip, &circ);
8244 mutex_enter(&pptr->port_mutex);
8262 fc_ulp_log_device_event(pptr->port_fp_handle,
8267 fc_ulp_log_device_event(pptr->port_fp_handle,
8272 mutex_exit(&pptr->port_mutex);
8275 mdi_devi_exit(pptr->port_dip, circ);
8277 ndi_devi_exit(pptr->port_dip, circ);
8280 fc_ulp_idle_port(pptr->port_fp_handle);
8291 fcp_offline_target(struct fcp_port *pptr, struct fcp_tgt *ptgt,
8296 ASSERT(mutex_owned(&pptr->port_mutex));
8301 if (link_cnt != pptr->port_link_cnt || (tgt_cnt && tgt_cnt !=
8327 elem->next = pptr->port_offline_tgts;
8328 pptr->port_offline_tgts = elem;
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,
8341 ASSERT(mutex_owned(&pptr->port_mutex));
8344 fc_ulp_enable_relogin(pptr->port_fp_handle, &ptgt->tgt_port_wwn);
8379 struct fcp_port *pptr = plun->lun_tgt->tgt_port;
8399 elem->next = pptr->port_offline_luns;
8400 pptr->port_offline_luns = elem;
8475 fcp_scan_offline_luns(struct fcp_port *pptr)
8481 ASSERT(MUTEX_HELD(&pptr->port_mutex));
8484 elem = pptr->port_offline_luns;
8492 if (pptr->port_link_cnt == elem->link_cnt &&
8509 pptr->port_offline_luns = next;
8520 fcp_scan_offline_tgts(struct fcp_port *pptr)
8526 ASSERT(MUTEX_HELD(&pptr->port_mutex));
8529 elem = pptr->port_offline_tgts;
8542 pptr->port_link_cnt == elem->link_cnt + 1 &&
8556 fcp_offline_target_now(pptr,
8568 pptr->port_offline_tgts = next;
8581 struct fcp_port *pptr = LUN_PORT;
8603 pptr->port_ndi_event_hdl, cdip, FCAL_REMOVE_EVENT,
8606 pptr->port_ndi_event_hdl, cdip,
8623 struct fcp_port *pptr = LUN_PORT;
8634 mutex_enter(&pptr->port_pkt_mutex);
8635 for (cmd = pptr->port_pkt_head; cmd != NULL; cmd = ncmd) {
8652 ASSERT(pptr->port_pkt_head != cmd);
8655 ASSERT(cmd == pptr->port_pkt_head);
8656 pptr->port_pkt_head = cmd->cmd_next;
8659 if (cmd == pptr->port_pkt_tail) {
8660 pptr->port_pkt_tail = pcmd;
8676 mutex_exit(&pptr->port_pkt_mutex);
8678 FCP_DTRACE(fcp_logq, pptr->port_instbuf,
8690 fcp_abort_commands(struct fcp_pkt *head, struct fcp_port *pptr)
8695 ASSERT(mutex_owned(&pptr->port_mutex));
8723 mutex_exit(&pptr->port_mutex);
8725 mutex_enter(&pptr->port_mutex);
8738 struct fcp_port *pptr = ADDR2FCP(&pkt->pkt_address);
8751 fcp_log(CE_CONT, pptr->port_dip,
8760 mutex_enter(&pptr->port_pkt_mutex);
8761 pptr->port_npkts--;
8762 mutex_exit(&pptr->port_pkt_mutex);
8776 struct fcp_port *pptr = ADDR2FCP(&pkt->pkt_address);
8789 if (pptr->port_fcp_dma != FC_NO_DVMA_SPACE) {
8845 if (fcp_validate_fcp_response(rsp, pptr) !=
8850 fcp_log(CE_WARN, pptr->port_dip,
8864 if (pptr->port_fcp_dma != FC_NO_DVMA_SPACE) {
8880 FCP_TRACE(fcp_logq, pptr->port_instbuf,
8908 if (fcp_validate_fcp_response(rsp, pptr) !=
8913 fcp_log(CE_WARN, pptr->port_dip,
8930 if (pptr->port_fcp_dma != FC_NO_DVMA_SPACE) {
8952 FCP_TRACE(fcp_logq, pptr->port_instbuf,
8957 FCP_TRACE(fcp_logq, pptr->port_instbuf,
8982 FCP_DTRACE(fcp_logq, pptr->port_instbuf,
9052 FCP_DTRACE(fcp_logq, pptr->port_instbuf,
9069 pptr->port_ndi_event_hdl, cdip,
9073 pptr->port_ndi_event_hdl, cdip,
9133 pptr->port_ndi_event_hdl, cdip,
9138 pptr->port_ndi_event_hdl,
9176 if (pptr->port_fcp_dma != FC_NO_DVMA_SPACE) {
9214 FCP_DTRACE(fcp_logq, pptr->port_instbuf,
9223 FCP_DTRACE(fcp_logq, pptr->port_instbuf,
9235 fcp_validate_fcp_response(struct fcp_rsp *rsp, struct fcp_port *pptr)
9252 FCP_TRACE(fcp_logq, pptr->port_instbuf, fcp_trace,
9284 fcp_device_changed(struct fcp_port *pptr, struct fcp_tgt *ptgt,
9287 ASSERT(mutex_owned(&pptr->port_mutex));
9289 FCP_TRACE(fcp_logq, pptr->port_instbuf,
9298 (FC_TOP_EXTERNAL(pptr->port_topology) &&
9304 (void) fcp_offline_target(pptr, ptgt, link_cnt,
9309 fcp_log(CE_NOTE, pptr->port_dip,
9316 return (fcp_handle_mapflags(pptr, ptgt, map_entry,
9394 * Argument: pptr fcp port structure
9404 fcp_alloc_tgt(struct fcp_port *pptr, fc_portmap_t *map_entry, int link_cnt)
9412 mutex_enter(&pptr->port_mutex);
9413 if (link_cnt != pptr->port_link_cnt) {
9418 mutex_exit(&pptr->port_mutex);
9433 ptgt->tgt_next = pptr->port_tgt_hash_table[hash];
9434 pptr->port_tgt_hash_table[hash] = ptgt;
9437 ptgt->tgt_port = pptr;
9448 mutex_exit(&pptr->port_mutex);
9489 fcp_queue_ipkt(struct fcp_port *pptr, fc_packet_t *fpkt)
9494 mutex_enter(&pptr->port_mutex);
9496 if (FCP_STATE_CHANGED(pptr, ptgt, icmd)) {
9497 FCP_TRACE(fcp_logq, pptr->port_instbuf,
9502 mutex_exit(&pptr->port_mutex);
9503 (void) fcp_call_finish_init(pptr, ptgt, icmd->ipkt_link_cnt,
9505 fcp_icmd_free(pptr, icmd);
9512 if (pptr->port_ipkt_list != NULL) {
9514 pptr->port_ipkt_list->ipkt_prev = icmd;
9515 icmd->ipkt_next = pptr->port_ipkt_list;
9516 pptr->port_ipkt_list = icmd;
9520 pptr->port_ipkt_list = icmd;
9524 mutex_exit(&pptr->port_mutex);
9622 struct fcp_port *pptr;
9626 pptr = ADDR2FCP(&cmd->cmd_pkt->pkt_address);
9629 FCP_DTRACE(fcp_logq, pptr->port_instbuf,
9635 fcp_queue_pkt(pptr, cmd);
9669 fcp_retry_ns_registry(struct fcp_port *pptr, uint32_t s_id)
9673 ASSERT(MUTEX_HELD(&pptr->port_mutex));
9675 if (((pptr->port_state & FCP_STATE_NS_REG_FAILED) == 0) ||
9676 ((pptr->port_topology != FC_TOP_FABRIC) &&
9677 (pptr->port_topology != FC_TOP_PUBLIC_LOOP))) {
9678 if (pptr->port_state & FCP_STATE_NS_REG_FAILED) {
9679 pptr->port_state &= ~FCP_STATE_NS_REG_FAILED;
9683 mutex_exit(&pptr->port_mutex);
9684 rval = fcp_do_ns_registry(pptr, s_id);
9685 mutex_enter(&pptr->port_mutex);
9689 pptr->port_state &= ~(FCP_STATE_NS_REG_FAILED);
9697 fcp_do_ns_registry(struct fcp_port *pptr, uint32_t s_id)
9727 if (fc_ulp_port_ns(pptr->port_fp_handle, NULL, &ns_cmd)) {
9728 fcp_log(CE_WARN, pptr->port_dip,
9771 struct fcp_port *pptr;
9792 if ((pptr = ddi_get_soft_state(fcp_softstate, instance)) == NULL) {
9799 (void) sprintf(pptr->port_instbuf, "fcp(%d)", instance);
9805 (void) fcp_cp_pinfo(pptr, pinfo);
9812 if ((manual_cfg = ddi_prop_get_int(DDI_DEV_T_ANY, pptr->port_dip,
9819 (void) ddi_pathname(pptr->port_dip, pathname);
9823 ddi_driver_name(pptr->port_dip),
9824 ddi_get_instance(pptr->port_dip),
9826 ddi_driver_name(pptr->port_dip));
9831 _NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(pptr->port_link_cnt));
9832 pptr->port_link_cnt = 1;
9833 _NOTE(NOW_VISIBLE_TO_OTHER_THREADS(pptr->port_link_cnt));
9834 pptr->port_id = s_id;
9835 pptr->port_instance = instance;
9836 _NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(pptr->port_state));
9837 pptr->port_state = FCP_STATE_INIT;
9842 pptr->port_state |= FCP_STATE_FCA_IS_NODMA;
9845 _NOTE(NOW_VISIBLE_TO_OTHER_THREADS(pptr->port_state));
9847 if (!(pptr->port_state & FCP_STATE_FCA_IS_NODMA)) {
9852 pptr->port_dmacookie_sz = sizeof (ddi_dma_cookie_t) *
9853 pptr->port_data_dma_attr.dma_attr_sgllen;
9862 mutex_init(&pptr->port_mutex, NULL, MUTEX_DRIVER, NULL);
9863 mutex_init(&pptr->port_pkt_mutex, NULL, MUTEX_DRIVER, NULL);
9869 if ((tran = scsi_hba_tran_alloc(pptr->port_dip, 0)) == NULL) {
9870 fcp_log(CE_WARN, pptr->port_dip,
9876 pptr->port_tran = tran;
9877 tran->tran_hba_private = pptr;
9912 tran->tran_hba_len = pptr->port_priv_pkt_len +
9913 sizeof (struct fcp_pkt) + pptr->port_dmacookie_sz;
9914 if (pptr->port_state & FCP_STATE_FCA_IS_NODMA) {
9928 pptr->port_data_dma_attr = pseudo_fca_dma_attr;
9934 pptr->port_ndi_event_defs = (ndi_event_definition_t *)
9937 bcopy(fcp_ndi_event_defs, pptr->port_ndi_event_defs,
9940 (void) ndi_event_alloc_hdl(pptr->port_dip, NULL,
9941 &pptr->port_ndi_event_hdl, NDI_SLEEP);
9943 pptr->port_ndi_events.ndi_events_version = NDI_EVENTS_REV1;
9944 pptr->port_ndi_events.ndi_n_events = FCP_N_NDI_EVENTS;
9945 pptr->port_ndi_events.ndi_event_defs = pptr->port_ndi_event_defs;
9947 if (DEVI_IS_ATTACHING(pptr->port_dip) &&
9948 (ndi_event_bind_set(pptr->port_ndi_event_hdl,
9949 &pptr->port_ndi_events, NDI_SLEEP) != NDI_SUCCESS)) {
9954 if (scsi_hba_attach_setup(pptr->port_dip, &pptr->port_data_dma_attr,
9957 fcp_log(CE_WARN, pptr->port_dip,
9963 pptr->port_mpxio = 0;
9964 if (mdi_phci_register(MDI_HCI_CLASS_SCSI, pptr->port_dip, 0) ==
9966 pptr->port_mpxio++;
9991 pptr->port_next = fcp_port_head;
9992 fcp_port_head = pptr;
10011 if (fcp_do_ns_registry(pptr, s_id)) {
10012 mutex_enter(&pptr->port_mutex);
10013 pptr->port_state |= FCP_STATE_NS_REG_FAILED;
10014 mutex_exit(&pptr->port_mutex);
10016 mutex_enter(&pptr->port_mutex);
10017 pptr->port_state &= ~(FCP_STATE_NS_REG_FAILED);
10018 mutex_exit(&pptr->port_mutex);
10030 bcopy(boot_wwn, pptr->port_boot_wwn, FC_WWN_SIZE);
10040 switch (FC_PORT_STATE_MASK(pptr->port_phys_state)) {
10052 pptr->port_state |= FCP_STATE_OFFLINE;
10056 if (pptr->port_topology == FC_TOP_UNKNOWN) {
10057 (void) fcp_linkreset(pptr, NULL, KM_NOSLEEP);
10065 ASSERT(pptr->port_topology != FC_TOP_UNKNOWN);
10076 fcp_log(CE_WARN, pptr->port_dip,
10097 if ((res = fc_ulp_getportmap(pptr->port_fp_handle,
10111 fcp_log(CE_WARN, pptr->port_dip,
10130 fcp_statec_callback(ulph, pptr->port_fp_handle,
10131 pptr->port_phys_state, pptr->port_topology, tmp_list,
10132 max_cnt, pptr->port_id);
10140 fcp_log(CE_WARN, pptr->port_dip,
10142 instance, pptr->port_phys_state);
10144 mutex_enter(&pptr->port_mutex);
10145 pptr->port_phys_state = FCP_STATE_OFFLINE;
10146 mutex_exit(&pptr->port_mutex);
10158 pptr->port_attach_time = ddi_get_lbolt64();
10165 fcp_log(CE_WARN, pptr->port_dip, "!failed to attach to port");
10169 (void) fcp_soft_state_unlink(pptr);
10173 if (pptr->port_ndi_event_hdl) {
10175 (void) ndi_event_unbind_set(pptr->port_ndi_event_hdl,
10176 &pptr->port_ndi_events, NDI_SLEEP);
10178 (void) ndi_event_free_hdl(pptr->port_ndi_event_hdl);
10181 if (pptr->port_ndi_event_defs) {
10182 (void) kmem_free(pptr->port_ndi_event_defs,
10189 if (pptr->port_mpxio) {
10190 (void) mdi_phci_unregister(pptr->port_dip, 0);
10191 pptr->port_mpxio--;
10196 (void) scsi_hba_detach(pptr->port_dip);
10198 if (pptr->port_tran != NULL) {
10199 scsi_hba_tran_free(pptr->port_tran);
10225 mutex_destroy(&pptr->port_mutex);
10226 mutex_destroy(&pptr->port_pkt_mutex);
10233 /* this makes pptr invalid */
10241 fcp_handle_port_detach(struct fcp_port *pptr, int flag, int instance)
10245 mutex_enter(&pptr->port_mutex);
10252 if (pptr->port_state & (FCP_STATE_POWER_DOWN |
10254 pptr->port_state |= flag;
10255 mutex_exit(&pptr->port_mutex);
10260 if (pptr->port_state & FCP_STATE_IN_MDI) {
10261 mutex_exit(&pptr->port_mutex);
10265 FCP_TRACE(fcp_logq, pptr->port_instbuf,
10269 pptr->port_state |= flag;
10277 while (pptr->port_tmp_cnt || pptr->port_ipkt_cnt ||
10278 (pptr->port_state & FCP_STATE_IN_WATCHDOG)) {
10286 mutex_exit(&pptr->port_mutex);
10288 mutex_enter(&pptr->port_mutex);
10295 if (pptr->port_tmp_cnt || pptr->port_ipkt_cnt ||
10296 (pptr->port_state & FCP_STATE_IN_WATCHDOG)) {
10297 pptr->port_state &= ~flag;
10298 mutex_exit(&pptr->port_mutex);
10303 pptr = fcp_soft_state_unlink(pptr);
10304 ASSERT(pptr != NULL);
10307 pptr->port_link_cnt++;
10308 pptr->port_state |= FCP_STATE_OFFLINE;
10309 pptr->port_state &= ~(FCP_STATE_ONLINING | FCP_STATE_ONLINE);
10311 fcp_update_state(pptr, (FCP_LUN_BUSY | FCP_LUN_MARK),
10313 mutex_exit(&pptr->port_mutex);
10327 fcp_cleanup_port(pptr, instance);
10335 fcp_cleanup_port(struct fcp_port *pptr, int instance)
10337 ASSERT(pptr != NULL);
10340 if (pptr->port_ndi_event_hdl) {
10341 (void) ndi_event_unbind_set(pptr->port_ndi_event_hdl,
10342 &pptr->port_ndi_events, NDI_SLEEP);
10343 (void) ndi_event_free_hdl(pptr->port_ndi_event_hdl);
10346 if (pptr->port_ndi_event_defs) {
10347 (void) kmem_free(pptr->port_ndi_event_defs,
10352 fcp_free_targets(pptr);
10357 if (pptr->port_mpxio) {
10358 (void) mdi_phci_unregister(pptr->port_dip, 0);
10359 pptr->port_mpxio--;
10363 (void) scsi_hba_detach(pptr->port_dip);
10364 if (pptr->port_tran != NULL) {
10365 scsi_hba_tran_free(pptr->port_tran);
10370 if (pptr->fcp_ksp != NULL) {
10371 kstat_delete(pptr->fcp_ksp);
10376 mutex_destroy(&pptr->port_mutex);
10377 mutex_destroy(&pptr->port_pkt_mutex);
10473 struct fcp_port *pptr;
10476 pptr = (struct fcp_port *)tran->tran_hba_private;
10488 sizeof (struct fcp_pkt) + pptr->port_dmacookie_sz);
10496 if (pptr->port_fcp_dma == FC_NO_DVMA_SPACE) {
10514 if (fcp_alloc_cmd_resp(pptr, fpkt, kmflags) != FC_SUCCESS) {
10541 struct fcp_port *pptr;
10543 pptr = (struct fcp_port *)(tran->tran_hba_private);
10546 if (pptr->port_fcp_dma != FC_NO_DVMA_SPACE) {
10551 fcp_free_cmd_resp(pptr, cmd->cmd_fp_pkt);
10564 * Argument: *pptr FCP port.
10576 fcp_alloc_cmd_resp(struct fcp_port *pptr, fc_packet_t *fpkt, int flags)
10595 if (ddi_dma_alloc_handle(pptr->port_dip, &pptr->port_cmd_dma_attr,
10602 &pptr->port_dma_acc_attr, DDI_DMA_CONSISTENT, cb, NULL,
10628 pptr->port_cmd_dma_attr.dma_attr_sgllen) {
10666 if (ddi_dma_alloc_handle(pptr->port_dip, &pptr->port_resp_dma_attr,
10675 &pptr->port_dma_acc_attr, DDI_DMA_CONSISTENT, cb, NULL,
10716 pptr->port_resp_dma_attr.dma_attr_sgllen) {
10764 * Argument: *pptr FCP port context.
10774 fcp_free_cmd_resp(struct fcp_port *pptr, fc_packet_t *fpkt)
10819 struct fcp_port *pptr = (struct fcp_port *)
10822 ASSERT(pptr != NULL);
10824 FCP_DTRACE(fcp_logq, pptr->port_instbuf, fcp_trace,
10835 FCP_DTRACE(fcp_logq, pptr->port_instbuf, fcp_trace,
10853 FCP_DTRACE(fcp_logq, pptr->port_instbuf, fcp_trace,
10863 mutex_enter(&pptr->port_mutex);
10864 if ((plun = fcp_lookup_lun(pptr, bytes, lun_num)) == NULL) {
10865 mutex_exit(&pptr->port_mutex);
10866 FCP_DTRACE(fcp_logq, pptr->port_instbuf, fcp_trace,
10890 mutex_exit(&pptr->port_mutex);
10905 struct fcp_port *pptr = (struct fcp_port *)
10909 ASSERT(pptr != NULL);
10911 FCP_DTRACE(fcp_logq, pptr->port_instbuf,
10919 FCP_DTRACE(fcp_logq, pptr->port_instbuf,
10944 FCP_DTRACE(fcp_logq, pptr->port_instbuf,
10954 mutex_enter(&pptr->port_mutex);
10955 if ((plun = fcp_lookup_lun(pptr, bytes, lun_num)) == NULL) {
10956 mutex_exit(&pptr->port_mutex);
10957 FCP_DTRACE(fcp_logq, pptr->port_instbuf,
10981 mutex_exit(&pptr->port_mutex);
10997 struct fcp_port *pptr = (struct fcp_port *)
11001 ASSERT(pptr != NULL);
11066 struct fcp_port *pptr = ADDR2FCP(ap);
11075 FCP_DTRACE(fcp_logq, pptr->port_instbuf,
11083 mutex_enter(&pptr->port_mutex);
11094 mutex_exit(&pptr->port_mutex);
11126 if (((plun->lun_state & FCP_LUN_BUSY) && (!(pptr->port_state &
11128 (pptr->port_state & (FCP_STATE_ONLINING | FCP_STATE_IN_CB_DEVC)) ||
11142 mutex_exit(&pptr->port_mutex);
11150 FCP_DTRACE(fcp_logq, pptr->port_instbuf,
11156 mutex_enter(&pptr->port_pkt_mutex);
11157 pptr->port_npkts++;
11158 mutex_exit(&pptr->port_pkt_mutex);
11162 fcp_queue_pkt(pptr, cmd);
11168 mutex_exit(&pptr->port_mutex);
11178 fcp_reconfig_wait(pptr);
11185 fcp_prepare_pkt(pptr, cmd, plun);
11199 return (fcp_dopoll(pptr, cmd));
11203 mutex_enter(&pptr->port_pkt_mutex);
11204 pptr->port_npkts++;
11205 mutex_exit(&pptr->port_pkt_mutex);
11208 rval = fcp_transport(pptr->port_fp_handle, cmd->cmd_fp_pkt, 0);
11210 FCP_DTRACE(fcp_logq, pptr->port_instbuf,
11219 mutex_enter(&pptr->port_pkt_mutex);
11220 pptr->port_npkts--;
11221 mutex_exit(&pptr->port_pkt_mutex);
11241 FCP_TRACE(fcp_logq, pptr->port_instbuf,
11249 FCP_DTRACE(fcp_logq, pptr->port_instbuf,
11256 fcp_queue_pkt(pptr, cmd);
11273 struct fcp_port *pptr = ADDR2FCP(ap);
11282 fcp_abort_all(pptr, ptgt, plun, tgt_cnt);
11297 struct fcp_port *pptr = ADDR2FCP(ap);
11302 if (fcp_linkreset(pptr, ap, KM_NOSLEEP) == FC_SUCCESS) {
11377 struct fcp_port *pptr;
11384 pptr = ADDR2FCP(&pkt->pkt_address);
11421 if (pptr->port_state & FCP_STATE_OFFLINE) {
11428 if (fc_ulp_init_packet(pptr->port_fp_handle, fpkt, kf)
11487 struct fcp_port *pptr = ADDR2FCP(&pkt->pkt_address);
11512 (void) fc_ulp_uninit_packet(pptr->port_fp_handle, cmd->cmd_fp_pkt);
11524 struct fcp_port *pptr = ADDR2FCP(ap);
11527 &pptr->port_mutex, &pptr->port_reset_notify_listf));
11535 struct fcp_port *pptr = fcp_dip2port(dip);
11537 if (pptr == NULL) {
11541 return (ndi_event_retrieve_cookie(pptr->port_ndi_event_hdl, rdip, name,
11551 struct fcp_port *pptr = fcp_dip2port(dip);
11553 if (pptr == NULL) {
11557 return (ndi_event_add_callback(pptr->port_ndi_event_hdl, rdip,
11566 struct fcp_port *pptr = fcp_dip2port(dip);
11568 if (pptr == NULL) {
11571 return (ndi_event_remove_callback(pptr->port_ndi_event_hdl, cb_id));
11582 struct fcp_port *pptr = fcp_dip2port(dip);
11584 if (pptr == NULL) {
11588 return (ndi_event_run_callbacks(pptr->port_ndi_event_hdl, rdip,
11620 struct fcp_port *pptr = ADDR2FCP(ap);
11680 fcp_prepare_pkt(pptr, cmd, plun);
11688 (void) fc_ulp_busy_port(pptr->port_fp_handle);
11689 bval = fcp_dopoll(pptr, cmd);
11690 fc_ulp_idle_port(pptr->port_fp_handle);
11701 if (fcp_validate_fcp_response(rsp, pptr) ==
11703 if (pptr->port_fcp_dma != FC_NO_DVMA_SPACE) {
11722 fcp_log(CE_WARN, pptr->port_dip,
11729 fcp_log(CE_WARN, pptr->port_dip,
11738 fcp_log(CE_WARN, pptr->port_dip,
11752 fcp_log(CE_WARN, pptr->port_dip,
11773 mutex_enter(&pptr->port_mutex);
11784 p->next = pptr->port_reset_list;
11785 pptr->port_reset_list = p;
11787 FCP_TRACE(fcp_logq, pptr->port_instbuf,
11791 scsi_hba_reset_notify_callback(&pptr->port_mutex,
11792 &pptr->port_reset_notify_listf);
11794 mutex_exit(&pptr->port_mutex);
11809 struct fcp_port *pptr = ADDR2FCP(ap);
11816 FCP_TRACE(fcp_logq, pptr->port_instbuf,
11855 FCP_TRACE(fcp_logq, pptr->port_instbuf,
11862 FCP_TRACE(fcp_logq, pptr->port_instbuf,
11874 rval = (int)pptr->port_data_dma_attr.dma_attr_maxxfer;
11891 rval = pptr->port_id;
11905 if (FC_TOP_EXTERNAL(pptr->port_topology) ||
11919 FCP_TRACE(fcp_logq, pptr->port_instbuf,
11926 FCP_TRACE(fcp_logq, pptr->port_instbuf,
11962 struct fcp_port *pptr;
11969 pptr = ddi_get_soft_state(fcp_softstate,
11971 if (pptr == NULL) {
12002 mutex_enter(&pptr->port_mutex);
12003 if ((plun = fcp_lookup_lun(pptr, barray, lun_num)) == NULL) {
12004 mutex_exit(&pptr->port_mutex);
12008 mutex_exit(&pptr->port_mutex);
12013 if (!FC_TOP_EXTERNAL(pptr->port_topology) &&
12045 fcp_log(CE_WARN, pptr->port_dip,
12099 fcp_linkreset(struct fcp_port *pptr, struct scsi_address *ap, int sleep)
12106 mutex_enter(&pptr->port_mutex);
12108 if (pptr->port_state & (FCP_STATE_SUSPENDED |
12110 mutex_exit(&pptr->port_mutex);
12111 FCP_TRACE(fcp_logq, pptr->port_instbuf,
12115 ddi_get_instance(pptr->port_dip));
12119 if (pptr->port_state & (FCP_STATE_OFFLINE | FCP_STATE_ONLINING)) {
12120 mutex_exit(&pptr->port_mutex);
12124 FCP_DTRACE(fcp_logq, pptr->port_instbuf,
12130 if (FC_TOP_EXTERNAL(pptr->port_topology) && (ap != NULL)) {
12137 mutex_exit(&pptr->port_mutex);
12139 return (fc_ulp_linkreset(pptr->port_fp_handle, &wwn, sleep));
12156 struct fcp_port *pptr; /* port state ptr */
12165 if ((pptr = ddi_get_soft_state(fcp_softstate, instance)) == NULL) {
12170 mutex_enter(&pptr->port_mutex);
12173 ASSERT((pptr->port_state & FCP_STATE_POWER_DOWN) == 0);
12174 pptr->port_state &= ~FCP_STATE_SUSPENDED;
12182 if (pptr->port_state & FCP_STATE_SUSPENDED) {
12183 pptr->port_state &= ~FCP_STATE_POWER_DOWN;
12184 mutex_exit(&pptr->port_mutex);
12187 pptr->port_state &= ~FCP_STATE_POWER_DOWN;
12189 pptr->port_id = s_id;
12190 pptr->port_state = FCP_STATE_INIT;
12191 mutex_exit(&pptr->port_mutex);
12197 (void) fcp_cp_pinfo(pptr, pinfo);
12211 switch (FC_PORT_STATE_MASK(pptr->port_phys_state)) {
12222 if (pptr->port_topology == FC_TOP_UNKNOWN) {
12223 (void) fcp_linkreset(pptr, NULL, KM_NOSLEEP);
12228 if (FC_TOP_EXTERNAL(pptr->port_topology) &&
12230 tmp_list = fcp_construct_map(pptr, &alloc_cnt);
12239 ASSERT(pptr->port_topology != FC_TOP_UNKNOWN);
12246 fcp_log(CE_WARN, pptr->port_dip,
12253 if ((res = fc_ulp_getportmap(pptr->port_fp_handle,
12260 FCP_TRACE(fcp_logq, pptr->port_instbuf,
12265 fcp_log(CE_WARN, pptr->port_dip,
12278 fcp_statec_callback(ulph, pptr->port_fp_handle,
12279 pptr->port_phys_state, pptr->port_topology, tmp_list,
12280 max_cnt, pptr->port_id);
12286 fcp_log(CE_WARN, pptr->port_dip,
12288 instance, pptr->port_phys_state);
12290 mutex_enter(&pptr->port_mutex);
12291 pptr->port_phys_state = FCP_STATE_OFFLINE;
12292 mutex_exit(&pptr->port_mutex);
12307 fcp_cp_pinfo(struct fcp_port *pptr, fc_ulp_port_info_t *pinfo)
12309 pptr->port_fp_modlinkage = *pinfo->port_linkage;
12310 pptr->port_dip = pinfo->port_dip;
12311 pptr->port_fp_handle = pinfo->port_handle;
12316 pptr->port_data_dma_attr = *pinfo->port_data_dma_attr;
12317 pptr->port_cmd_dma_attr = *pinfo->port_cmd_dma_attr;
12318 pptr->port_resp_dma_attr = *pinfo->port_resp_dma_attr;
12319 pptr->port_dma_acc_attr = *pinfo->port_acc_attr;
12321 pptr->port_priv_pkt_len = pinfo->port_fca_pkt_size;
12322 pptr->port_max_exch = pinfo->port_fca_max_exch;
12323 pptr->port_phys_state = pinfo->port_state;
12324 pptr->port_topology = pinfo->port_flags;
12325 pptr->port_reset_action = pinfo->port_reset_action;
12326 pptr->port_cmds_dma_flags = pinfo->port_dma_behavior;
12327 pptr->port_fcp_dma = pinfo->port_fcp_dma;
12328 bcopy(&pinfo->port_nwwn, &pptr->port_nwwn, sizeof (la_wwn_t));
12329 bcopy(&pinfo->port_pwwn, &pptr->port_pwwn, sizeof (la_wwn_t));
12332 if (pptr->port_cmd_dma_attr.dma_attr_flags & DDI_DMA_FLAGERR)
12333 pptr->port_cmd_dma_attr.dma_attr_flags &= ~DDI_DMA_FLAGERR;
12334 if (pptr->port_data_dma_attr.dma_attr_flags & DDI_DMA_FLAGERR)
12335 pptr->port_data_dma_attr.dma_attr_flags &= ~DDI_DMA_FLAGERR;
12336 if (pptr->port_resp_dma_attr.dma_attr_flags & DDI_DMA_FLAGERR)
12337 pptr->port_resp_dma_attr.dma_attr_flags &= ~DDI_DMA_FLAGERR;
12374 struct fcp_port *pptr = elem->port;
12382 mutex_enter(&pptr->port_mutex);
12386 pptr->port_state & (FCP_STATE_SUSPENDED |
12389 mutex_exit(&pptr->port_mutex);
12394 mutex_exit(&pptr->port_mutex);
12409 struct fcp_port *pptr = plun->lun_tgt->tgt_port;
12411 ASSERT(MUTEX_HELD(&pptr->port_mutex));
12416 if (pptr->port_mpxio == 0 || plun->lun_mpxio == 0) {
12506 struct fcp_port *pptr = ptgt->tgt_port;
12507 dev_info_t *pdip = pptr->port_dip;
12517 ASSERT(MUTEX_HELD(&pptr->port_mutex));
12567 mutex_exit(&pptr->port_mutex);
12570 (void) fcp_pass_to_hp(pptr, plun, CIP(old_dip), FCP_OFFLINE,
12576 FCP_TRACE(fcp_logq, pptr->port_instbuf,
12581 FCP_TRACE(fcp_logq, pptr->port_instbuf,
12587 mutex_enter(&pptr->port_mutex);
12593 if (ndi_devi_alloc(pptr->port_dip, nname,
12644 if (!FC_TOP_EXTERNAL(pptr->port_topology) && ptgt->tgt_hard_addr != 0) {
12704 struct fcp_port *pptr = ptgt->tgt_port;
12705 dev_info_t *pdip = pptr->port_dip;
12715 ASSERT(MUTEX_HELD(&pptr->port_mutex));
12757 mutex_exit(&pptr->port_mutex);
12760 (void) fcp_pass_to_hp(pptr, plun, CIP(old_pip),
12766 FCP_TRACE(fcp_logq, pptr->port_instbuf,
12771 FCP_TRACE(fcp_logq, pptr->port_instbuf,
12777 mutex_enter(&pptr->port_mutex);
12812 pptr->port_state |= FCP_STATE_IN_MDI;
12814 mutex_exit(&pptr->port_mutex);
12817 fcp_log(CE_WARN, pptr->port_dip,
12819 mutex_enter(&pptr->port_mutex);
12821 pptr->port_state &= ~FCP_STATE_IN_MDI;
12825 mutex_enter(&pptr->port_mutex);
12827 pptr->port_state &= ~FCP_STATE_IN_MDI;
12862 if (!FC_TOP_EXTERNAL(pptr->port_topology) &&
12894 mutex_exit(&pptr->port_mutex);
12896 mutex_enter(&pptr->port_mutex);
12915 struct fcp_port *pptr = ptgt->tgt_port;
12990 if (!FC_TOP_EXTERNAL(pptr->port_topology) &&
13092 struct fcp_port *pptr = ptgt->tgt_port;
13094 ASSERT(MUTEX_HELD(&pptr->port_mutex));
13110 struct fcp_port *pptr = plun->lun_tgt->tgt_port;
13114 ASSERT(MUTEX_HELD(&pptr->port_mutex));
13118 FCP_TRACE(fcp_logq, pptr->port_instbuf,
13130 mutex_exit(&pptr->port_mutex);
13132 FCP_TRACE(fcp_logq, pptr->port_instbuf,
13146 FCP_TRACE(fcp_logq, pptr->port_instbuf,
13164 fcp_log(CE_NOTE, pptr->port_dip,
13170 FCP_TRACE(fcp_logq, pptr->port_instbuf,
13180 mutex_exit(&pptr->port_mutex);
13182 FCP_TRACE(fcp_logq, pptr->port_instbuf,
13192 mdi_devi_exit_phci(pptr->port_dip, *circ);
13196 mdi_devi_enter_phci(pptr->port_dip, circ);
13217 mutex_enter(&pptr->port_mutex);
13224 fcp_log(CE_WARN, pptr->port_dip,
13233 mutex_exit(&pptr->port_mutex);
13240 FCP_TRACE(fcp_logq, pptr->port_instbuf,
13246 mutex_exit(&pptr->port_mutex);
13251 mutex_enter(&pptr->port_mutex);
13257 fcp_log(CE_NOTE, pptr->port_dip,
13270 pptr->port_ndi_event_hdl, cdip, FCAL_INSERT_EVENT,
13272 (void) ndi_event_run_callbacks(pptr->port_ndi_event_hdl,
13276 mutex_enter(&pptr->port_mutex);
13288 struct fcp_port *pptr = plun->lun_tgt->tgt_port;
13293 ASSERT(MUTEX_HELD(&pptr->port_mutex));
13296 FCP_TRACE(fcp_logq, pptr->port_instbuf,
13314 mutex_exit(&pptr->port_mutex);
13317 FCP_TRACE(fcp_logq, pptr->port_instbuf,
13325 mutex_exit(&pptr->port_mutex);
13332 mdi_devi_exit_phci(pptr->port_dip, *circ);
13336 mdi_devi_enter_phci(pptr->port_dip, circ);
13386 FCP_TRACE(fcp_logq, pptr->port_instbuf,
13393 mutex_enter(&pptr->port_mutex);
13397 FCP_TRACE(fcp_logq, pptr->port_instbuf,
13483 struct fcp_port *pptr;
13499 for (pptr = fcp_port_head; pptr != NULL; pptr = pptr->port_next) {
13501 pptr->port_state |= FCP_STATE_IN_WATCHDOG;
13504 mutex_enter(&pptr->port_mutex);
13505 if (pptr->port_ipkt_list == NULL &&
13506 (pptr->port_state & (FCP_STATE_SUSPENDED |
13508 pptr->port_state &= ~FCP_STATE_IN_WATCHDOG;
13509 mutex_exit(&pptr->port_mutex);
13517 if (pptr->port_offline_tgts) {
13518 fcp_scan_offline_tgts(pptr);
13524 if (pptr->port_offline_luns) {
13525 fcp_scan_offline_luns(pptr);
13531 if (pptr->port_reset_list) {
13532 fcp_check_reset_delay(pptr);
13535 mutex_exit(&pptr->port_mutex);
13541 mutex_enter(&pptr->port_pkt_mutex);
13542 tail = pptr->port_pkt_tail;
13544 for (pcmd = NULL, cmd = pptr->port_pkt_head;
13568 if (cmd == pptr->port_pkt_head) {
13570 pptr->port_pkt_head = cmd->cmd_next;
13576 if (cmd == pptr->port_pkt_tail) {
13578 pptr->port_pkt_tail = pcmd;
13594 save_head = pptr->port_pkt_head;
13595 mutex_exit(&pptr->port_pkt_mutex);
13606 FCP_TRACE(fcp_logq, pptr->port_instbuf,
13616 fcp_retransport_cmd(pptr, cmd);
13618 mutex_enter(&pptr->port_pkt_mutex);
13619 if (save_head && save_head != pptr->port_pkt_head) {
13640 mutex_exit(&pptr->port_pkt_mutex);
13642 mutex_enter(&pptr->port_mutex);
13643 for (icmd = pptr->port_ipkt_list; icmd != NULL; icmd = nicmd) {
13654 if (icmd == pptr->port_ipkt_list) {
13655 pptr->port_ipkt_list = icmd->ipkt_next;
13656 if (pptr->port_ipkt_list) {
13657 pptr->port_ipkt_list->ipkt_prev =
13669 mutex_exit(&pptr->port_mutex);
13676 FCP_TRACE(fcp_logq, pptr->port_instbuf,
13689 fc_ulp_get_rscn_count(pptr->
13693 mutex_enter(&pptr->port_mutex);
13695 if (!FCP_STATE_CHANGED(pptr, ptgt, icmd)) {
13697 mutex_exit(&pptr->port_mutex);
13702 pptr->port_fp_handle,
13706 &pptr->port_mutex);
13710 pptr, ptgt, icmd, rval,
13713 &pptr->port_mutex);
13720 pptr->port_fp_handle,
13724 &pptr->port_mutex);
13728 pptr, ptgt, icmd, rval,
13731 &pptr->port_mutex);
13738 pptr->port_fp_handle,
13742 &pptr->port_mutex);
13746 pptr, ptgt, icmd, rval,
13749 &pptr->port_mutex);
13756 mutex_exit(&pptr->port_mutex);
13762 (void) fcp_call_finish_init(pptr, ptgt,
13765 fcp_icmd_free(pptr, icmd);
13766 mutex_enter(&pptr->port_mutex);
13769 pptr->port_state &= ~FCP_STATE_IN_WATCHDOG;
13770 mutex_exit(&pptr->port_mutex);
13792 fcp_check_reset_delay(struct fcp_port *pptr)
13802 ASSERT(mutex_owned(&pptr->port_mutex));
13804 next = pptr->port_reset_list;
13832 if (cur == pptr->port_reset_list) {
13833 pptr->port_reset_list = next;
13837 which = pptr->port_reset_list;
13861 mutex_exit(&pptr->port_mutex);
13862 fcp_abort_all(pptr, ptgt, plun, tgt_cnt);
13863 mutex_enter(&pptr->port_mutex);
13870 fcp_abort_all(struct fcp_port *pptr, struct fcp_tgt *ttgt,
13879 mutex_enter(&pptr->port_pkt_mutex);
13880 for (cmd = pptr->port_pkt_head; cmd != NULL; cmd = ncmd) {
13892 ASSERT(pptr->port_pkt_head != cmd);
13895 ASSERT(cmd == pptr->port_pkt_head);
13896 pptr->port_pkt_head = ncmd;
13898 if (pptr->port_pkt_tail == cmd) {
13900 pptr->port_pkt_tail = pcmd;
13915 mutex_exit(&pptr->port_pkt_mutex);
13923 mutex_enter(&pptr->port_mutex);
13925 mutex_exit(&pptr->port_mutex);
13932 mutex_exit(&pptr->port_mutex);
13941 if (pptr->port_reset_action == FC_RESET_RETURN_ALL) {
13982 rval = fc_ulp_abort(pptr->port_fp_handle,
14007 fcp_log(CE_WARN, pptr->port_dip,
14025 mutex_enter(&pptr->port_pkt_mutex);
14026 if (pptr->port_pkt_head) {
14027 ASSERT(pptr->port_pkt_tail
14029 pptr->port_pkt_tail->cmd_next
14031 pptr->port_pkt_tail = cmd;
14033 ASSERT(pptr->port_pkt_tail
14035 pptr->port_pkt_head =
14036 pptr->port_pkt_tail
14040 mutex_exit(&pptr->port_pkt_mutex);
14054 mutex_enter(&pptr->port_mutex);
14056 mutex_exit(&pptr->port_mutex);
14059 mutex_exit(&pptr->port_mutex);
14071 fcp_soft_state_unlink(struct fcp_port *pptr)
14080 if (hptr == pptr) {
14105 fcp_lookup_lun(struct fcp_port *pptr, uchar_t *wwn, uint16_t lun)
14111 ASSERT(mutex_owned(&pptr->port_mutex));
14114 for (ptgt = pptr->port_tgt_hash_table[hash]; ptgt != NULL;
14142 * Argument: *pptr FCP port.
14149 fcp_prepare_pkt(struct fcp_port *pptr, struct fcp_pkt *cmd,
14174 pptr->port_data_dma_attr.dma_attr_sgllen);
14202 if (pptr->port_fcp_dma != FC_NO_DVMA_SPACE) {
14227 mutex_enter(&pptr->port_mutex);
14228 if (pptr->port_state & FCP_STATE_SUSPENDED) {
14231 mutex_exit(&pptr->port_mutex);
14234 fpkt->pkt_cmd_fhdr.s_id = pptr->port_id;
14257 fcp_dopoll(struct fcp_port *pptr, struct fcp_pkt *cmd)
14262 mutex_enter(&pptr->port_pkt_mutex);
14263 pptr->port_npkts++;
14264 mutex_exit(&pptr->port_pkt_mutex);
14277 rval = fc_ulp_transport(pptr->port_fp_handle, cmd->cmd_fp_pkt);
14280 mutex_enter(&pptr->port_pkt_mutex);
14281 pptr->port_npkts--;
14282 mutex_exit(&pptr->port_pkt_mutex);
14333 fcp_get_lun_from_cip(struct fcp_port *pptr, child_info_t *cip)
14340 ASSERT(mutex_owned(&pptr->port_mutex));
14343 for (ptgt = pptr->port_tgt_hash_table[i];
14374 fcp_pass_to_hp_and_wait(struct fcp_port *pptr, struct fcp_lun *plun,
14381 if ((elem = fcp_pass_to_hp(pptr, plun, cip,
14384 fcp_log(CE_CONT, pptr->port_dip,
14420 fcp_pass_to_hp(struct fcp_port *pptr, struct fcp_lun *plun,
14426 ASSERT(pptr != NULL);
14440 elem->port = pptr;
14453 pdip = pptr->port_dip;
14476 fcp_retransport_cmd(struct fcp_port *pptr, struct fcp_pkt *cmd)
14492 mutex_enter(&pptr->port_mutex);
14495 (!(pptr->port_state & FCP_STATE_ONLINING))) {
14517 mutex_exit(&pptr->port_mutex);
14523 fcp_prepare_pkt(pptr, cmd, plun);
14533 fc_ulp_get_rscn_count(pptr->
14537 rval = fcp_transport(pptr->port_fp_handle,
14546 mutex_exit(&pptr->port_mutex);
14549 fcp_queue_pkt(pptr, cmd);
14574 * Argument: *pptr FCP port.
14582 fcp_queue_pkt(struct fcp_port *pptr, struct fcp_pkt *cmd)
14586 mutex_enter(&pptr->port_pkt_mutex);
14607 if (pptr->port_pkt_head) {
14608 ASSERT(pptr->port_pkt_tail != NULL);
14610 pptr->port_pkt_tail->cmd_next = cmd;
14611 pptr->port_pkt_tail = cmd;
14613 ASSERT(pptr->port_pkt_tail == NULL);
14615 pptr->port_pkt_head = pptr->port_pkt_tail = cmd;
14618 mutex_exit(&pptr->port_pkt_mutex);
14627 * Argument: *pptr FCP port.
14636 * The mutex pptr->port_mutex must be held.
14639 fcp_update_targets(struct fcp_port *pptr, fc_portmap_t *dev_list,
14645 ASSERT(MUTEX_HELD(&pptr->port_mutex));
14649 ptgt = fcp_lookup_target(pptr,
14666 fcp_call_finish_init(struct fcp_port *pptr, struct fcp_tgt *ptgt,
14671 mutex_enter(&pptr->port_mutex);
14672 rval = fcp_call_finish_init_held(pptr, ptgt, lcount, tcount, cause);
14673 mutex_exit(&pptr->port_mutex);
14680 fcp_call_finish_init_held(struct fcp_port *pptr, struct fcp_tgt *ptgt,
14694 FCP_TRACE(fcp_logq, pptr->port_instbuf, fcp_trace,
14698 pptr->port_link_cnt, lcount, ptgt->tgt_change_cnt, tcount,
14699 pptr->port_tmp_cnt, ptgt->tgt_tmp_cnt, cause,
14722 FCP_TRACE(fcp_logq, pptr->port_instbuf, fcp_trace,
14744 (void) fcp_finish_tgt(pptr, ptgt, lcount, tcount, cause);
14747 if (finish_init && lcount == pptr->port_link_cnt) {
14748 ASSERT(pptr->port_tmp_cnt > 0);
14749 if (--pptr->port_tmp_cnt == 0) {
14750 fcp_finish_init(pptr);
14752 } else if (lcount != pptr->port_link_cnt) {
14753 FCP_TRACE(fcp_logq, pptr->port_instbuf,
14768 struct fcp_port *pptr = ptgt->tgt_port;
14781 fcp_log(CE_WARN, pptr->port_dip,
14783 pptr->port_instance);
14799 fcp_statec_callback(NULL, pptr->port_fp_handle, FC_STATE_DEVICE_CHANGE,
14800 pptr->port_topology, devlist, dev_cnt, pptr->port_id);
14815 fcp_free_targets(struct fcp_port *pptr)
14820 mutex_enter(&pptr->port_mutex);
14822 ptgt = pptr->port_tgt_hash_table[i];
14830 mutex_exit(&pptr->port_mutex);
14897 * Argument: *pptr FCP port.
14909 fcp_create_on_demand(struct fcp_port *pptr, uchar_t *pwwn)
14935 mutex_enter(&pptr->port_mutex);
14936 pptr->port_deadline = fcp_watchdog_time + FCP_ICMD_DEADLINE;
14937 mutex_exit(&pptr->port_mutex);
14943 pd = fc_ulp_get_remote_port(pptr->port_fp_handle,
14955 ret = fc_ulp_pwwn_to_portmap(pptr->port_fp_handle,
14968 mutex_enter(&pptr->port_mutex);
14974 ptgt = fcp_lookup_target(pptr, pwwn);
14976 lcount = pptr->port_link_cnt;
14977 mutex_exit(&pptr->port_mutex);
14979 ptgt = fcp_alloc_tgt(pptr, devlist, lcount);
14981 fcp_log(CE_WARN, pptr->port_dip,
14986 mutex_enter(&pptr->port_mutex);
14998 if (FC_TOP_EXTERNAL(pptr->port_topology) &&
15006 fcp_update_targets(pptr, devlist, 1,
15009 lcount = pptr->port_link_cnt;
15012 if (fcp_handle_mapflags(pptr, ptgt, devlist, lcount,
15014 if (FC_TOP_EXTERNAL(pptr->port_topology) &&
15021 if (pptr->port_link_cnt != lcount ||
15025 mutex_exit(&pptr->port_mutex);
15027 FCP_TRACE(fcp_logq, pptr->port_instbuf, fcp_trace,
15032 ptgt, lcount, pptr->port_link_cnt,
15050 FCP_TRACE(fcp_logq, pptr->port_instbuf, fcp_trace,
15056 ntries, ptgt, lcount, pptr->port_link_cnt,
15061 while (ntries-- != 0 && pptr->port_link_cnt == lcount &&
15064 mutex_exit(&pptr->port_mutex);
15068 mutex_enter(&pptr->port_mutex);
15073 if (pptr->port_link_cnt != lcount || ptgt->tgt_change_cnt != tcount) {
15082 FCP_TRACE(fcp_logq, pptr->port_instbuf, fcp_trace,
15088 ntries, ptgt, lcount, pptr->port_link_cnt,
15093 if (FC_TOP_EXTERNAL(pptr->port_topology) &&
15098 mutex_exit(&pptr->port_mutex);
15101 FCP_TRACE(fcp_logq, pptr->port_instbuf, fcp_trace,
15107 ntries, ptgt, lcount, pptr->port_link_cnt,
15118 lcount = pptr->port_link_cnt;
15130 mutex_exit(&pptr->port_mutex);
15143 rval = fcp_pass_to_hp_and_wait(pptr, plun, cip,
15148 pptr->port_instbuf, fcp_trace,
15169 if (FC_TOP_EXTERNAL(pptr->port_topology) &&
15221 struct fcp_port *pptr;
15229 pptr = ptgt->tgt_port;
15287 if (fcp_validate_fcp_response(rsp, pptr) != FC_SUCCESS) {
15293 fcp_log(CE_WARN, pptr->port_dip, buf,
15341 fcp_log(CE_WARN, pptr->port_dip, buf,
15348 fcp_log(CE_WARN, pptr->port_dip, buf,
15362 fcp_log(CE_WARN, pptr->port_dip, buf,
15365 fcp_log(CE_WARN, pptr->port_dip, buf,
15375 fcp_handle_ipkt_errors(struct fcp_port *pptr, struct fcp_tgt *ptgt,
15402 FCP_TRACE(fcp_logq, pptr->port_instbuf, fcp_trace,
15414 FCP_TRACE(fcp_logq, pptr->port_instbuf, fcp_trace,
15420 fcp_queue_ipkt(pptr, icmd->ipkt_fpkt);
15439 FCP_TRACE(fcp_logq, pptr->port_instbuf, fcp_trace,
15445 fcp_queue_ipkt(pptr, icmd->ipkt_fpkt);
15452 mutex_enter(&pptr->port_mutex);
15454 if (!FCP_STATE_CHANGED(pptr, ptgt, icmd)) {
15456 mutex_exit(&pptr->port_mutex);
15459 fcp_log(CE_WARN, pptr->port_dip,
15463 FCP_TRACE(fcp_logq, pptr->port_instbuf,
15468 mutex_exit(&pptr->port_mutex);
15502 fcp_construct_map(struct fcp_port *pptr, uint32_t *dev_cnt)
15509 mutex_enter(&pptr->port_mutex);
15511 for (ptgt = pptr->port_tgt_hash_table[i]; ptgt != NULL;
15522 mutex_exit(&pptr->port_mutex);
15523 fcp_log(CE_WARN, pptr->port_dip,
15525 pptr->port_instance);
15530 for (ptgt = pptr->port_tgt_hash_table[i]; ptgt != NULL;
15536 pptr->port_fp_handle,
15564 mutex_exit(&pptr->port_mutex);
15572 fcp_update_mpxio_path_verifybusy(struct fcp_port *pptr)
15579 for (ptgt = pptr->port_tgt_hash_table[i]; ptgt != NULL;
15586 if (!fcp_pass_to_hp(pptr, plun,
15589 pptr->port_link_cnt,
15592 pptr->port_instbuf,
15712 struct fcp_port *pptr = fcp_dip2port(parent);
15715 (ddi_get_lbolt64() - pptr->port_attach_time);
15753 mutex_enter(&pptr->port_mutex);
15754 while ((reset_delay > 0) && pptr->port_tmp_cnt) {
15755 (void) cv_timedwait(&pptr->port_config_cv,
15756 &pptr->port_mutex,
15760 (ddi_get_lbolt64() - pptr->port_attach_time);
15762 mutex_exit(&pptr->port_mutex);
15859 fcp_reconfig_wait(struct fcp_port *pptr)
15864 * Quick check. If pptr->port_tmp_cnt is 0, there is no
15868 mutex_enter(&pptr->port_mutex);
15869 if (pptr->port_tmp_cnt == 0) {
15870 mutex_exit(&pptr->port_mutex);
15873 mutex_exit(&pptr->port_mutex);
15883 mutex_enter(&pptr->port_mutex);
15886 pptr->port_tmp_cnt) {
15888 (void) cv_timedwait(&pptr->port_config_cv, &pptr->port_mutex,
15892 mutex_exit(&pptr->port_mutex);
16113 * pkt@scsi_pkt, cmd@fcp_pkt, icmd@fcp_ipkt, fpkt@fc_packet, pptr@fcp_port
16120 fcp_port_t *pptr = ADDR2FCP(ap);
16128 pkt = scsi_hba_pkt_alloc(pptr->port_dip, ap, cmdlen, statuslen,
16129 tgtlen, sizeof (fcp_pkt_t) + pptr->port_priv_pkt_len,
16176 FCP_TRACE(fcp_logq, pptr->port_instbuf,
16217 fcp_port_t *pptr = ADDR2FCP(ap);
16222 (void) fc_ulp_uninit_packet(pptr->port_fp_handle,
16242 fcp_port_t *pptr = ADDR2FCP(ap);
16251 (void) fc_ulp_init_packet(pptr->port_fp_handle, cmd->cmd_fp_pkt, 1);
16283 fpkt->pkt_cmd_fhdr.s_id = pptr->port_id;
16314 return (fcp_dopoll(pptr, cmd));
16318 rval = fcp_transport(pptr->port_fp_handle, fpkt, 0);