4042
4043 /*
4044 * The new ndi interfaces for on-demand creation
4045 * are inflexible, Do some more work to pass on
4046 * a path name of some LUN (design is broken !)
4047 */
4048 if (plun->lun_cip) {
4049 if (plun->lun_mpxio == 0) {
4050 cdip = DIP(plun->lun_cip);
4051 } else {
4052 cdip = mdi_pi_get_client(
4053 PIP(plun->lun_cip));
4054 }
4055 if (cdip == NULL) {
4056 *rval = ENXIO;
4057 break;
4058 }
4059
4060 if (!i_ddi_devi_attached(cdip)) {
4061 mutex_exit(&plun->lun_mutex);
4062 delay(drv_usectohz(1000000));
4063 mutex_enter(&plun->lun_mutex);
4064 } else {
4065 /*
4066 * This Lun is ready, lets
4067 * check the next one.
4068 */
4069 mutex_exit(&plun->lun_mutex);
4070 plun = plun->lun_next;
4071 while (plun && (plun->lun_state
4072 & FCP_LUN_OFFLINE)) {
4073 plun = plun->lun_next;
4074 }
4075 if (!plun) {
4076 break;
4077 }
4078 mutex_enter(&plun->lun_mutex);
4079 }
4080 } else {
4081 /*
4082 * lun_cip field for a valid lun
4413 ~(FCP_STATE_ONLINING | FCP_STATE_ONLINE);
4414 pptr->port_tmp_cnt = 0;
4415 }
4416 mutex_exit(&pptr->port_mutex);
4417 break;
4418
4419 case FC_STATE_ONLINE:
4420 case FC_STATE_LIP:
4421 case FC_STATE_LIP_LBIT_SET:
4422 /*
4423 * link has gone from offline to online
4424 */
4425 FCP_TRACE(fcp_logq, pptr->port_instbuf,
4426 fcp_trace, FCP_BUF_LEVEL_3, 0,
4427 "link went online");
4428
4429 pptr->port_link_cnt++;
4430
4431 while (pptr->port_ipkt_cnt) {
4432 mutex_exit(&pptr->port_mutex);
4433 delay(drv_usectohz(1000000));
4434 mutex_enter(&pptr->port_mutex);
4435 }
4436
4437 pptr->port_topology = port_top;
4438
4439 /*
4440 * The state of the targets and luns accessible through this
4441 * port is updated.
4442 */
4443 fcp_update_state(pptr, FCP_LUN_BUSY | FCP_LUN_MARK,
4444 FCP_CAUSE_LINK_CHANGE);
4445
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;
4450
4451 pptr->port_deadline = fcp_watchdog_time +
4452 FCP_ICMD_DEADLINE;
4453
4767
4768 case PORT_DEVICE_OLD:
4769 if (ptgt != NULL) {
4770 FCP_TGT_TRACE(ptgt, map_tag[i],
4771 FCP_TGT_TRACE_3);
4772
4773 mutex_enter(&ptgt->tgt_mutex);
4774 if (!(ptgt->tgt_state & FCP_TGT_OFFLINE)) {
4775 /*
4776 * Must do an in-line wait for I/Os
4777 * to get drained
4778 */
4779 mutex_exit(&ptgt->tgt_mutex);
4780 mutex_exit(&pptr->port_mutex);
4781
4782 mutex_enter(&ptgt->tgt_mutex);
4783 while (ptgt->tgt_ipkt_cnt ||
4784 fcp_outstanding_lun_cmds(ptgt)
4785 == FC_SUCCESS) {
4786 mutex_exit(&ptgt->tgt_mutex);
4787 delay(drv_usectohz(1000000));
4788 mutex_enter(&ptgt->tgt_mutex);
4789 }
4790 mutex_exit(&ptgt->tgt_mutex);
4791
4792 mutex_enter(&pptr->port_mutex);
4793 mutex_enter(&ptgt->tgt_mutex);
4794
4795 (void) fcp_offline_target(pptr, ptgt,
4796 link_cnt, map_tag[i], 0, 0);
4797 }
4798 mutex_exit(&ptgt->tgt_mutex);
4799 }
4800 check_finish_init++;
4801 break;
4802
4803 case PORT_DEVICE_USER_DELETE:
4804 case PORT_DEVICE_USER_LOGOUT:
4805 if (ptgt != NULL) {
4806 FCP_TGT_TRACE(ptgt, map_tag[i],
4807 FCP_TGT_TRACE_4);
9990 * done attaching it. The reason for that is: because of the code that
9991 * follows. At this point the resources to handle the port are
9992 * allocated. This function is now going to do the following:
9993 *
9994 * 1) It is going to try to register with the name server advertizing
9995 * the new FCP capability of the port.
9996 * 2) It is going to play the role of the fp/fctl layer by building
9997 * a list of worlwide names reachable through this port and call
9998 * itself on fcp_statec_callback(). That requires the port to
9999 * be part of the global list.
10000 */
10001 mutex_enter(&fcp_global_mutex);
10002 if (fcp_port_head == NULL) {
10003 fcp_read_blacklist(pinfo->port_dip, &fcp_lun_blacklist);
10004 }
10005 pptr->port_next = fcp_port_head;
10006 fcp_port_head = pptr;
10007 soft_state_linked++;
10008
10009 if (fcp_watchdog_init++ == 0) {
10010 fcp_watchdog_tick = fcp_watchdog_timeout *
10011 drv_usectohz(1000000);
10012 fcp_watchdog_id = timeout(fcp_watch, NULL,
10013 fcp_watchdog_tick);
10014 }
10015 mutex_exit(&fcp_global_mutex);
10016
10017 /*
10018 * Here an attempt is made to register with the name server, the new
10019 * FCP capability. That is done using an RTF_ID to the name server.
10020 * It is done synchronously. The function fcp_do_ns_registry()
10021 * doesn't return till the name server responded.
10022 * On failures, just ignore it for now and it will get retried during
10023 * state change callbacks. We'll set a flag to show this failure
10024 */
10025 if (fcp_do_ns_registry(pptr, s_id)) {
10026 mutex_enter(&pptr->port_mutex);
10027 pptr->port_state |= FCP_STATE_NS_REG_FAILED;
10028 mutex_exit(&pptr->port_mutex);
10029 } else {
10030 mutex_enter(&pptr->port_mutex);
10031 pptr->port_state &= ~(FCP_STATE_NS_REG_FAILED);
10281 "fcp_handle_port_detach: port is detaching");
10282
10283 pptr->port_state |= flag;
10284
10285 /*
10286 * Wait for any ongoing reconfig/ipkt to complete, that
10287 * ensures the freeing to targets/luns is safe.
10288 * No more ref to this port should happen from statec/ioctl
10289 * after that as it was removed from the global port list.
10290 */
10291 while (pptr->port_tmp_cnt || pptr->port_ipkt_cnt ||
10292 (pptr->port_state & FCP_STATE_IN_WATCHDOG)) {
10293 /*
10294 * Let's give sufficient time for reconfig/ipkt
10295 * to complete.
10296 */
10297 if (count++ >= FCP_ICMD_DEADLINE) {
10298 break;
10299 }
10300 mutex_exit(&pptr->port_mutex);
10301 delay(drv_usectohz(1000000));
10302 mutex_enter(&pptr->port_mutex);
10303 }
10304
10305 /*
10306 * if the driver is still busy then fail to
10307 * suspend/power down.
10308 */
10309 if (pptr->port_tmp_cnt || pptr->port_ipkt_cnt ||
10310 (pptr->port_state & FCP_STATE_IN_WATCHDOG)) {
10311 pptr->port_state &= ~flag;
10312 mutex_exit(&pptr->port_mutex);
10313 return (FC_FAILURE);
10314 }
10315
10316 if (flag == FCP_STATE_DETACHING) {
10317 pptr = fcp_soft_state_unlink(pptr);
10318 ASSERT(pptr != NULL);
10319 }
10320
10321 pptr->port_link_cnt++;
12195 */
12196 if (pptr->port_state & FCP_STATE_SUSPENDED) {
12197 pptr->port_state &= ~FCP_STATE_POWER_DOWN;
12198 mutex_exit(&pptr->port_mutex);
12199 return (DDI_SUCCESS);
12200 }
12201 pptr->port_state &= ~FCP_STATE_POWER_DOWN;
12202 }
12203 pptr->port_id = s_id;
12204 pptr->port_state = FCP_STATE_INIT;
12205 mutex_exit(&pptr->port_mutex);
12206
12207 /*
12208 * Make a copy of ulp_port_info as fctl allocates
12209 * a temp struct.
12210 */
12211 (void) fcp_cp_pinfo(pptr, pinfo);
12212
12213 mutex_enter(&fcp_global_mutex);
12214 if (fcp_watchdog_init++ == 0) {
12215 fcp_watchdog_tick = fcp_watchdog_timeout *
12216 drv_usectohz(1000000);
12217 fcp_watchdog_id = timeout(fcp_watch,
12218 NULL, fcp_watchdog_tick);
12219 }
12220 mutex_exit(&fcp_global_mutex);
12221
12222 /*
12223 * Handle various topologies and link states.
12224 */
12225 switch (FC_PORT_STATE_MASK(pptr->port_phys_state)) {
12226 case FC_STATE_OFFLINE:
12227 /*
12228 * Wait for ONLINE, at which time a state
12229 * change will cause a statec_callback
12230 */
12231 res = DDI_SUCCESS;
12232 break;
12233
12234 case FC_STATE_ONLINE:
12235
12236 if (pptr->port_topology == FC_TOP_UNKNOWN) {
|
4042
4043 /*
4044 * The new ndi interfaces for on-demand creation
4045 * are inflexible, Do some more work to pass on
4046 * a path name of some LUN (design is broken !)
4047 */
4048 if (plun->lun_cip) {
4049 if (plun->lun_mpxio == 0) {
4050 cdip = DIP(plun->lun_cip);
4051 } else {
4052 cdip = mdi_pi_get_client(
4053 PIP(plun->lun_cip));
4054 }
4055 if (cdip == NULL) {
4056 *rval = ENXIO;
4057 break;
4058 }
4059
4060 if (!i_ddi_devi_attached(cdip)) {
4061 mutex_exit(&plun->lun_mutex);
4062 delay(drv_sectohz(1));
4063 mutex_enter(&plun->lun_mutex);
4064 } else {
4065 /*
4066 * This Lun is ready, lets
4067 * check the next one.
4068 */
4069 mutex_exit(&plun->lun_mutex);
4070 plun = plun->lun_next;
4071 while (plun && (plun->lun_state
4072 & FCP_LUN_OFFLINE)) {
4073 plun = plun->lun_next;
4074 }
4075 if (!plun) {
4076 break;
4077 }
4078 mutex_enter(&plun->lun_mutex);
4079 }
4080 } else {
4081 /*
4082 * lun_cip field for a valid lun
4413 ~(FCP_STATE_ONLINING | FCP_STATE_ONLINE);
4414 pptr->port_tmp_cnt = 0;
4415 }
4416 mutex_exit(&pptr->port_mutex);
4417 break;
4418
4419 case FC_STATE_ONLINE:
4420 case FC_STATE_LIP:
4421 case FC_STATE_LIP_LBIT_SET:
4422 /*
4423 * link has gone from offline to online
4424 */
4425 FCP_TRACE(fcp_logq, pptr->port_instbuf,
4426 fcp_trace, FCP_BUF_LEVEL_3, 0,
4427 "link went online");
4428
4429 pptr->port_link_cnt++;
4430
4431 while (pptr->port_ipkt_cnt) {
4432 mutex_exit(&pptr->port_mutex);
4433 delay(drv_sectohz(1));
4434 mutex_enter(&pptr->port_mutex);
4435 }
4436
4437 pptr->port_topology = port_top;
4438
4439 /*
4440 * The state of the targets and luns accessible through this
4441 * port is updated.
4442 */
4443 fcp_update_state(pptr, FCP_LUN_BUSY | FCP_LUN_MARK,
4444 FCP_CAUSE_LINK_CHANGE);
4445
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;
4450
4451 pptr->port_deadline = fcp_watchdog_time +
4452 FCP_ICMD_DEADLINE;
4453
4767
4768 case PORT_DEVICE_OLD:
4769 if (ptgt != NULL) {
4770 FCP_TGT_TRACE(ptgt, map_tag[i],
4771 FCP_TGT_TRACE_3);
4772
4773 mutex_enter(&ptgt->tgt_mutex);
4774 if (!(ptgt->tgt_state & FCP_TGT_OFFLINE)) {
4775 /*
4776 * Must do an in-line wait for I/Os
4777 * to get drained
4778 */
4779 mutex_exit(&ptgt->tgt_mutex);
4780 mutex_exit(&pptr->port_mutex);
4781
4782 mutex_enter(&ptgt->tgt_mutex);
4783 while (ptgt->tgt_ipkt_cnt ||
4784 fcp_outstanding_lun_cmds(ptgt)
4785 == FC_SUCCESS) {
4786 mutex_exit(&ptgt->tgt_mutex);
4787 delay(drv_sectohz(1));
4788 mutex_enter(&ptgt->tgt_mutex);
4789 }
4790 mutex_exit(&ptgt->tgt_mutex);
4791
4792 mutex_enter(&pptr->port_mutex);
4793 mutex_enter(&ptgt->tgt_mutex);
4794
4795 (void) fcp_offline_target(pptr, ptgt,
4796 link_cnt, map_tag[i], 0, 0);
4797 }
4798 mutex_exit(&ptgt->tgt_mutex);
4799 }
4800 check_finish_init++;
4801 break;
4802
4803 case PORT_DEVICE_USER_DELETE:
4804 case PORT_DEVICE_USER_LOGOUT:
4805 if (ptgt != NULL) {
4806 FCP_TGT_TRACE(ptgt, map_tag[i],
4807 FCP_TGT_TRACE_4);
9990 * done attaching it. The reason for that is: because of the code that
9991 * follows. At this point the resources to handle the port are
9992 * allocated. This function is now going to do the following:
9993 *
9994 * 1) It is going to try to register with the name server advertizing
9995 * the new FCP capability of the port.
9996 * 2) It is going to play the role of the fp/fctl layer by building
9997 * a list of worlwide names reachable through this port and call
9998 * itself on fcp_statec_callback(). That requires the port to
9999 * be part of the global list.
10000 */
10001 mutex_enter(&fcp_global_mutex);
10002 if (fcp_port_head == NULL) {
10003 fcp_read_blacklist(pinfo->port_dip, &fcp_lun_blacklist);
10004 }
10005 pptr->port_next = fcp_port_head;
10006 fcp_port_head = pptr;
10007 soft_state_linked++;
10008
10009 if (fcp_watchdog_init++ == 0) {
10010 fcp_watchdog_tick = drv_sectohz(fcp_watchdog_timeout);
10011 fcp_watchdog_id = timeout(fcp_watch, NULL,
10012 fcp_watchdog_tick);
10013 }
10014 mutex_exit(&fcp_global_mutex);
10015
10016 /*
10017 * Here an attempt is made to register with the name server, the new
10018 * FCP capability. That is done using an RTF_ID to the name server.
10019 * It is done synchronously. The function fcp_do_ns_registry()
10020 * doesn't return till the name server responded.
10021 * On failures, just ignore it for now and it will get retried during
10022 * state change callbacks. We'll set a flag to show this failure
10023 */
10024 if (fcp_do_ns_registry(pptr, s_id)) {
10025 mutex_enter(&pptr->port_mutex);
10026 pptr->port_state |= FCP_STATE_NS_REG_FAILED;
10027 mutex_exit(&pptr->port_mutex);
10028 } else {
10029 mutex_enter(&pptr->port_mutex);
10030 pptr->port_state &= ~(FCP_STATE_NS_REG_FAILED);
10280 "fcp_handle_port_detach: port is detaching");
10281
10282 pptr->port_state |= flag;
10283
10284 /*
10285 * Wait for any ongoing reconfig/ipkt to complete, that
10286 * ensures the freeing to targets/luns is safe.
10287 * No more ref to this port should happen from statec/ioctl
10288 * after that as it was removed from the global port list.
10289 */
10290 while (pptr->port_tmp_cnt || pptr->port_ipkt_cnt ||
10291 (pptr->port_state & FCP_STATE_IN_WATCHDOG)) {
10292 /*
10293 * Let's give sufficient time for reconfig/ipkt
10294 * to complete.
10295 */
10296 if (count++ >= FCP_ICMD_DEADLINE) {
10297 break;
10298 }
10299 mutex_exit(&pptr->port_mutex);
10300 delay(drv_sectohz(1));
10301 mutex_enter(&pptr->port_mutex);
10302 }
10303
10304 /*
10305 * if the driver is still busy then fail to
10306 * suspend/power down.
10307 */
10308 if (pptr->port_tmp_cnt || pptr->port_ipkt_cnt ||
10309 (pptr->port_state & FCP_STATE_IN_WATCHDOG)) {
10310 pptr->port_state &= ~flag;
10311 mutex_exit(&pptr->port_mutex);
10312 return (FC_FAILURE);
10313 }
10314
10315 if (flag == FCP_STATE_DETACHING) {
10316 pptr = fcp_soft_state_unlink(pptr);
10317 ASSERT(pptr != NULL);
10318 }
10319
10320 pptr->port_link_cnt++;
12194 */
12195 if (pptr->port_state & FCP_STATE_SUSPENDED) {
12196 pptr->port_state &= ~FCP_STATE_POWER_DOWN;
12197 mutex_exit(&pptr->port_mutex);
12198 return (DDI_SUCCESS);
12199 }
12200 pptr->port_state &= ~FCP_STATE_POWER_DOWN;
12201 }
12202 pptr->port_id = s_id;
12203 pptr->port_state = FCP_STATE_INIT;
12204 mutex_exit(&pptr->port_mutex);
12205
12206 /*
12207 * Make a copy of ulp_port_info as fctl allocates
12208 * a temp struct.
12209 */
12210 (void) fcp_cp_pinfo(pptr, pinfo);
12211
12212 mutex_enter(&fcp_global_mutex);
12213 if (fcp_watchdog_init++ == 0) {
12214 fcp_watchdog_tick = drv_sectohz(fcp_watchdog_timeout);
12215 fcp_watchdog_id = timeout(fcp_watch,
12216 NULL, fcp_watchdog_tick);
12217 }
12218 mutex_exit(&fcp_global_mutex);
12219
12220 /*
12221 * Handle various topologies and link states.
12222 */
12223 switch (FC_PORT_STATE_MASK(pptr->port_phys_state)) {
12224 case FC_STATE_OFFLINE:
12225 /*
12226 * Wait for ONLINE, at which time a state
12227 * change will cause a statec_callback
12228 */
12229 res = DDI_SUCCESS;
12230 break;
12231
12232 case FC_STATE_ONLINE:
12233
12234 if (pptr->port_topology == FC_TOP_UNKNOWN) {
|