diff options
author | mav <mav@FreeBSD.org> | 2015-10-05 08:31:48 +0000 |
---|---|---|
committer | mav <mav@FreeBSD.org> | 2015-10-05 08:31:48 +0000 |
commit | ec7deb53d18cdb5720ef959156dcf8fcff0247f9 (patch) | |
tree | cef4ce32df3befdd43da3ea6ae0fded0a69f468d /sys/dev/isp/isp.c | |
parent | 9b07ecd0998dda43886587a22afa4d7bb60c8ffd (diff) | |
download | FreeBSD-src-ec7deb53d18cdb5720ef959156dcf8fcff0247f9.zip FreeBSD-src-ec7deb53d18cdb5720ef959156dcf8fcff0247f9.tar.gz |
MFC r285459: Unify port database use for target and initiator roles.
Aside from cleaner and more consistent code, this allows ports to be both
target and initiator same time, and easily switch from any role to any.
Diffstat (limited to 'sys/dev/isp/isp.c')
-rw-r--r-- | sys/dev/isp/isp.c | 216 |
1 files changed, 73 insertions, 143 deletions
diff --git a/sys/dev/isp/isp.c b/sys/dev/isp/isp.c index 0e600d1..aaab1c3 100644 --- a/sys/dev/isp/isp.c +++ b/sys/dev/isp/isp.c @@ -65,16 +65,18 @@ __FBSDID("$FreeBSD$"); */ #define MBOX_DELAY_COUNT 1000000 / 100 #define ISP_MARK_PORTDB(a, b, c) \ - isp_prt(isp, ISP_LOG_SANCFG, \ - "Chan %d ISP_MARK_PORTDB@LINE %d", b, __LINE__); \ - isp_mark_portdb(a, b, c) + do { \ + isp_prt(isp, ISP_LOG_SANCFG, \ + "Chan %d ISP_MARK_PORTDB@LINE %d", (b), __LINE__); \ + isp_mark_portdb((a), (b), (c)); \ + } while (0) /* * Local static data */ static const char fconf[] = "Chan %d PortDB[%d] changed:\n current =(0x%x@0x%06x 0x%08x%08x 0x%08x%08x)\n database=(0x%x@0x%06x 0x%08x%08x 0x%08x%08x)"; static const char notresp[] = "Not RESPONSE in RESPONSE Queue (type 0x%x) @ idx %d (next %d) nlooked %d"; -static const char topology[] = "Chan %d WWPN 0x%08x%08x PortID 0x%06x N-Port Handle %d, Connection '%s'"; +static const char topology[] = "Chan %d WWPN 0x%08x%08x PortID 0x%06x handle 0x%x, Connection '%s'"; static const char bun[] = "bad underrun (count %d, resid %d, status %s)"; static const char lipd[] = "Chan %d LIP destroyed %d active commands"; static const char sacq[] = "unable to acquire scratch area"; @@ -2223,36 +2225,10 @@ isp_fibre_init_2400(ispsoftc_t *isp) } static void -isp_del_all_init_entries(ispsoftc_t *isp, int chan) -{ - fcparam *fcp = FCPARAM(isp, chan); - fcportdb_t *lp; - int i; - - for (i = 0; i < MAX_FC_TARG; i++) { - lp = &fcp->portdb[i]; - if (lp->state == FC_PORTDB_STATE_NIL || lp->target_mode) - continue; - lp->state = FC_PORTDB_STATE_NIL; - isp_async(isp, ISPASYNC_DEV_GONE, chan, lp, 1); - if (lp->autologin == 0) { - (void) isp_plogx(isp, chan, lp->handle, - lp->portid, - PLOGX_FLG_CMD_LOGO | - PLOGX_FLG_IMPLICIT | - PLOGX_FLG_FREE_NPHDL, 0); - } else { - lp->autologin = 0; - } - lp->new_prli_word3 = 0; - lp->new_portid = 0; - } -} - -static void isp_mark_portdb(ispsoftc_t *isp, int chan, int disposition) { fcparam *fcp = FCPARAM(isp, chan); + fcportdb_t *lp; int i; if (chan < 0 || chan >= isp->isp_nchan) { @@ -2260,32 +2236,28 @@ isp_mark_portdb(ispsoftc_t *isp, int chan, int disposition) return; } for (i = 0; i < MAX_FC_TARG; i++) { - if (fcp->portdb[i].target_mode) { - if (disposition < 0) { - isp_prt(isp, ISP_LOGTINFO, "isp_mark_portdb: Chan %d zeroing handle 0x" "%04x port 0x%06x", chan, - fcp->portdb[i].handle, fcp->portdb[i].portid); - ISP_MEMZERO(&fcp->portdb[i], sizeof (fcportdb_t)); - } - continue; - } - if (disposition == 0) { - ISP_MEMZERO(&fcp->portdb[i], sizeof (fcportdb_t)); - } else { - switch (fcp->portdb[i].state) { - case FC_PORTDB_STATE_CHANGED: - case FC_PORTDB_STATE_PENDING_VALID: - case FC_PORTDB_STATE_VALID: - case FC_PORTDB_STATE_PROBATIONAL: - fcp->portdb[i].state = FC_PORTDB_STATE_PROBATIONAL; - break; - case FC_PORTDB_STATE_ZOMBIE: - break; - case FC_PORTDB_STATE_NIL: - default: - ISP_MEMZERO(&fcp->portdb[i], sizeof (fcportdb_t)); - fcp->portdb[i].state = FC_PORTDB_STATE_NIL; - break; + lp = &fcp->portdb[i]; + switch (lp->state) { + case FC_PORTDB_STATE_PROBATIONAL: + case FC_PORTDB_STATE_DEAD: + case FC_PORTDB_STATE_CHANGED: + case FC_PORTDB_STATE_PENDING_VALID: + case FC_PORTDB_STATE_VALID: + if (disposition > 0) + lp->state = FC_PORTDB_STATE_PROBATIONAL; + else { + lp->state = FC_PORTDB_STATE_NIL; + isp_async(isp, ISPASYNC_DEV_GONE, chan, lp); } + break; + case FC_PORTDB_STATE_ZOMBIE: + break; + case FC_PORTDB_STATE_NIL: + case FC_PORTDB_STATE_NEW: + default: + ISP_MEMZERO(lp, sizeof(*lp)); + lp->state = FC_PORTDB_STATE_NIL; + break; } } } @@ -2473,7 +2445,7 @@ isp_port_login(ispsoftc_t *isp, uint16_t handle, uint32_t portid) return (MBOX_PORT_ID_USED | (mbs.param[1] << 16)); case MBOX_LOOP_ID_USED: - isp_prt(isp, ISP_LOG_SANCFG|ISP_LOG_WARN1, "isp_port_login: handle 0x%04x in use for port id 0x%02xXXXX", handle, mbs.param[1] & 0xff); + isp_prt(isp, ISP_LOG_SANCFG|ISP_LOG_WARN1, "isp_port_login: handle 0x%x in use for port id 0x%02xXXXX", handle, mbs.param[1] & 0xff); return (MBOX_LOOP_ID_USED); case MBOX_COMMAND_COMPLETE: @@ -2559,7 +2531,7 @@ isp_getpdb(ispsoftc_t *isp, int chan, uint16_t id, isp_pdb_t *pdb, int dolock) pdb->portid = BITS2WORD_24XX(un.bill.pdb_portid_bits); ISP_MEMCPY(pdb->portname, un.bill.pdb_portname, 8); ISP_MEMCPY(pdb->nodename, un.bill.pdb_nodename, 8); - isp_prt(isp, ISP_LOG_SANCFG, "Chan %d Port 0x%06x flags 0x%x curstate %x", chan, pdb->portid, un.bill.pdb_flags, un.bill.pdb_curstate); + isp_prt(isp, ISP_LOG_SANCFG, "Chan %d handle 0x%x Port 0x%06x flags 0x%x curstate %x", chan, id, pdb->portid, un.bill.pdb_flags, un.bill.pdb_curstate); if (un.bill.pdb_curstate < PDB2400_STATE_PLOGI_DONE || un.bill.pdb_curstate > PDB2400_STATE_LOGGED_IN) { mbs.param[0] = MBOX_NOT_LOGGED_IN; if (dolock) { @@ -2587,6 +2559,7 @@ isp_dump_chip_portdb(ispsoftc_t *isp, int chan, int dolock) isp_pdb_t pdb; int lim, loopid; + isp_prt(isp, ISP_LOG_SANCFG|ISP_LOGINFO, "Chan %d chip port dump", chan); if (ISP_CAP_2KLOGIN(isp)) { lim = NPH_MAX_2K; } else { @@ -2988,16 +2961,8 @@ isp_pdb_sync(ispsoftc_t *isp, int chan) for (dbidx = 0; dbidx < MAX_FC_TARG; dbidx++) { lp = &fcp->portdb[dbidx]; - if (lp->state == FC_PORTDB_STATE_NIL || lp->target_mode) { - continue; - } - - if (lp->state == FC_PORTDB_STATE_VALID) { - if (dbidx != FL_ID) { - isp_prt(isp, - ISP_LOGERR, "portdb idx %d already valid", - dbidx); - } + if (lp->state == FC_PORTDB_STATE_NIL || + lp->state == FC_PORTDB_STATE_VALID) { continue; } @@ -3005,7 +2970,7 @@ isp_pdb_sync(ispsoftc_t *isp, int chan) case FC_PORTDB_STATE_PROBATIONAL: case FC_PORTDB_STATE_DEAD: lp->state = FC_PORTDB_STATE_NIL; - isp_async(isp, ISPASYNC_DEV_GONE, chan, lp, 0); + isp_async(isp, ISPASYNC_DEV_GONE, chan, lp); if (lp->autologin == 0) { (void) isp_plogx(isp, chan, lp->handle, lp->portid, @@ -3029,17 +2994,14 @@ isp_pdb_sync(ispsoftc_t *isp, int chan) isp_async(isp, ISPASYNC_DEV_ARRIVED, chan, lp); lp->new_prli_word3 = 0; lp->new_portid = 0; - lp->announced = 0; break; case FC_PORTDB_STATE_CHANGED: -/* - * XXXX FIX THIS - */ lp->state = FC_PORTDB_STATE_VALID; isp_async(isp, ISPASYNC_DEV_CHANGED, chan, lp); + lp->portid = lp->new_portid; + lp->prli_word3 = lp->new_prli_word3; lp->new_prli_word3 = 0; lp->new_portid = 0; - lp->announced = 0; break; case FC_PORTDB_STATE_PENDING_VALID: lp->portid = lp->new_portid; @@ -3050,13 +3012,12 @@ isp_pdb_sync(ispsoftc_t *isp, int chan) lp->new_prli_word3 = 0; lp->new_portid = 0; } - lp->announced = 0; break; case FC_PORTDB_STATE_ZOMBIE: break; default: isp_prt(isp, ISP_LOGWARN, - "isp_scan_loop: state %d for idx %d", + "isp_pdb_sync: state %d for idx %d", lp->state, dbidx); isp_dump_portdb(isp, chan); } @@ -3127,7 +3088,6 @@ isp_scan_loop(ispsoftc_t *isp, int chan) isp_prt(isp, ISP_LOG_SANCFG, "Chan %d FC scan loop 0..%d", chan, lim-1); - /* * Run through the list and get the port database info for each one. */ @@ -3211,6 +3171,9 @@ isp_scan_loop(ispsoftc_t *isp, int chan) */ if (tmp.node_wwn == 0 || tmp.port_wwn == 0 || tmp.portid == 0) { int a, b, c; + isp_prt(isp, ISP_LOGWARN, + "Chan %d bad pdb (WWNN %016jx, WWPN %016jx, PortID %06x, W3 0x%x, H 0x%x) @ handle 0x%x", + chan, tmp.node_wwn, tmp.port_wwn, tmp.portid, tmp.prli_word3, tmp.handle, handle); a = (tmp.node_wwn == 0); b = (tmp.port_wwn == 0); c = (tmp.portid == 0); @@ -3220,13 +3183,10 @@ isp_scan_loop(ispsoftc_t *isp, int chan) tmp.port_wwn = isp_get_wwn(isp, chan, handle, 0); if (tmp.node_wwn && tmp.port_wwn) { - isp_prt(isp, ISP_LOGINFO, "DODGED!"); + isp_prt(isp, ISP_LOGWARN, "DODGED!"); goto cont; } } - isp_prt(isp, ISP_LOGWARN, - "Chan %d bad pdb (%1d%1d%1d) @ handle 0x%x", chan, - a, b, c, handle); isp_dump_portdb(isp, chan); continue; } @@ -3234,30 +3194,19 @@ isp_scan_loop(ispsoftc_t *isp, int chan) /* * Now search the entire port database - * for the same Port and Node WWN. + * for the same Port WWN. */ - for (i = 0; i < MAX_FC_TARG; i++) { - lp = &fcp->portdb[i]; - - if (lp->state == FC_PORTDB_STATE_NIL || lp->target_mode) { - continue; - } - if (lp->node_wwn != tmp.node_wwn) { - continue; - } - if (lp->port_wwn != tmp.port_wwn) { - continue; - } - + if (isp_find_pdb_by_wwn(isp, chan, tmp.port_wwn, &lp)) { /* * Okay- we've found a non-nil entry that matches. * Check to make sure it's probational or a zombie. */ if (lp->state != FC_PORTDB_STATE_PROBATIONAL && - lp->state != FC_PORTDB_STATE_ZOMBIE) { + lp->state != FC_PORTDB_STATE_ZOMBIE && + lp->state != FC_PORTDB_STATE_VALID) { isp_prt(isp, ISP_LOGERR, "Chan %d [%d] not probational/zombie (0x%x)", - chan, i, lp->state); + chan, FC_PORTDB_TGT(isp, chan, lp), lp->state); isp_dump_portdb(isp, chan); ISP_MARK_PORTDB(isp, chan, 1); isp_prt(isp, ISP_LOG_SANCFG, "Chan %d FC scan loop DONE (bad)", chan); @@ -3269,6 +3218,7 @@ isp_scan_loop(ispsoftc_t *isp, int chan) * automatically. */ lp->autologin = 1; + lp->node_wwn = tmp.node_wwn; /* * Check to make see if really still the same @@ -3279,7 +3229,7 @@ isp_scan_loop(ispsoftc_t *isp, int chan) lp->new_prli_word3 = tmp.prli_word3; lp->state = FC_PORTDB_STATE_PENDING_VALID; isp_prt(isp, ISP_LOG_SANCFG, "Chan %d Loop Port 0x%06x@0x%04x Pending Valid", chan, tmp.portid, tmp.handle); - break; + continue; } /* @@ -3296,13 +3246,6 @@ isp_scan_loop(ispsoftc_t *isp, int chan) lp->state = FC_PORTDB_STATE_CHANGED; lp->new_portid = tmp.portid; lp->new_prli_word3 = tmp.prli_word3; - break; - } - - /* - * Did we find and update an old entry? - */ - if (i < MAX_FC_TARG) { continue; } @@ -3311,9 +3254,6 @@ isp_scan_loop(ispsoftc_t *isp, int chan) * for it and save info for later disposition. */ for (i = 0; i < MAX_FC_TARG; i++) { - if (fcp->portdb[i].target_mode) { - continue; - } if (fcp->portdb[i].state == FC_PORTDB_STATE_NIL) { break; } @@ -3739,7 +3679,7 @@ isp_scan_fabric(ispsoftc_t *isp, int chan) for (dbidx = 0; dbidx < MAX_FC_TARG; dbidx++) { lp = &fcp->portdb[dbidx]; - if (lp->state != FC_PORTDB_STATE_PROBATIONAL || lp->target_mode) { + if (lp->state != FC_PORTDB_STATE_PROBATIONAL) { continue; } if (lp->portid == portid) { @@ -3781,7 +3721,7 @@ isp_scan_fabric(ispsoftc_t *isp, int chan) if (r != 0) { lp->new_portid = portid; lp->state = FC_PORTDB_STATE_DEAD; - isp_prt(isp, ISP_LOG_SANCFG, "Chan %d Fabric Port 0x%06x is dead", chan, portid); + isp_prt(isp, ISP_LOG_SANCFG, "Chan %d Fabric PortID 0x%06x handle 0x%x is dead (%d)", chan, portid, lp->handle, r); continue; } @@ -3797,7 +3737,7 @@ isp_scan_fabric(ispsoftc_t *isp, int chan) if (pdb.handle != lp->handle || pdb.portid != portid || wwpn != lp->port_wwn || - wwnn != lp->node_wwn) { + (lp->node_wwn != 0 && wwnn != lp->node_wwn)) { isp_prt(isp, ISP_LOG_SANCFG, fconf, chan, dbidx, pdb.handle, pdb.portid, (uint32_t) (wwnn >> 32), (uint32_t) wwnn, @@ -3815,8 +3755,9 @@ isp_scan_fabric(ispsoftc_t *isp, int chan) * portid consistency after re-login. * */ - if (isp_login_device(isp, chan, portid, &pdb, - &oldhandle)) { + if ((fcp->role & ISP_ROLE_INITIATOR) == 0 || + isp_login_device(isp, chan, portid, &pdb, + &oldhandle)) { lp->new_portid = portid; lp->state = FC_PORTDB_STATE_DEAD; if (fcp->isp_loopstate != @@ -3837,7 +3778,7 @@ isp_scan_fabric(ispsoftc_t *isp, int chan) MAKE_WWN_FROM_NODE_NAME(wwnn, pdb.nodename); MAKE_WWN_FROM_NODE_NAME(wwpn, pdb.portname); if (wwpn != lp->port_wwn || - wwnn != lp->node_wwn) { + (lp->node_wwn != 0 && wwnn != lp->node_wwn)) { isp_prt(isp, ISP_LOGWARN, "changed WWN" " after relogin"); lp->new_portid = portid; @@ -3875,6 +3816,9 @@ isp_scan_fabric(ispsoftc_t *isp, int chan) continue; } + if ((fcp->role & ISP_ROLE_INITIATOR) == 0) + continue; + /* * Ah- a new entry. Search the database again for all non-NIL * entries to make sure we never ever make a new database entry @@ -3888,12 +3832,6 @@ isp_scan_fabric(ispsoftc_t *isp, int chan) lp <= &fcp->portdb[SNS_ID]) { continue; } - /* - * Skip any target mode entries. - */ - if (lp->target_mode) { - continue; - } if (lp->state == FC_PORTDB_STATE_NIL) { if (dbidx == MAX_FC_TARG) { dbidx = lp - fcp->portdb; @@ -3966,10 +3904,9 @@ isp_scan_fabric(ispsoftc_t *isp, int chan) if (dbidx >= FL_ID && dbidx <= SNS_ID) { continue; } - if (fcp->portdb[dbidx].target_mode) { - continue; - } - if (fcp->portdb[dbidx].node_wwn == wwnn && fcp->portdb[dbidx].port_wwn == wwpn) { + if ((fcp->portdb[dbidx].node_wwn == wwnn || + fcp->portdb[dbidx].node_wwn == 0) && + fcp->portdb[dbidx].port_wwn == wwpn) { break; } } @@ -4007,6 +3944,7 @@ isp_scan_fabric(ispsoftc_t *isp, int chan) */ lp = &fcp->portdb[dbidx]; lp->handle = handle; + lp->node_wwn = wwnn; lp->new_portid = portid; lp->new_prli_word3 = nr; if (lp->portid != portid || lp->prli_word3 != nr) { @@ -4393,7 +4331,7 @@ isp_start(XS_T *xs) isp_prt(isp, ISP_LOGDEBUG2, "XS_TGT(xs)=%d", target); lp = &fcp->portdb[target]; if (target < 0 || target >= MAX_FC_TARG || - lp->dev_map_idx == 0) { + lp->is_target == 0) { XS_SETERR(xs, HBA_SELTIMEOUT); return (CMD_COMPLETE); } @@ -4406,7 +4344,6 @@ isp_start(XS_T *xs) XS_SETERR(xs, HBA_SELTIMEOUT); return (CMD_COMPLETE); } - lp->dirty = 1; } else { sdparam *sdp = SDPARAM(isp, XS_CHANNEL(xs)); if ((sdp->role & ISP_ROLE_INITIATOR) == 0) { @@ -4417,6 +4354,7 @@ isp_start(XS_T *xs) if (sdp->update) { isp_spi_update(isp, XS_CHANNEL(xs)); } + lp = NULL; } start_again: @@ -4703,7 +4641,7 @@ isp_control(ispsoftc_t *isp, ispctl_t ctl, ...) break; } lp = &fcp->portdb[tgt]; - if (lp->dev_map_idx == 0 || + if (lp->is_target == 0 || lp->state != FC_PORTDB_STATE_VALID) { isp_prt(isp, ISP_LOGWARN, "Chan %d abort of no longer valid target %d", chan, tgt); break; @@ -4793,7 +4731,7 @@ isp_control(ispsoftc_t *isp, ispctl_t ctl, ...) break; } lp = &fcp->portdb[tgt]; - if (lp->dev_map_idx == 0 || + if (lp->is_target == 0 || lp->state != FC_PORTDB_STATE_VALID) { isp_prt(isp, ISP_LOGWARN, "Chan %d abort of no longer valid target %d", chan, tgt); break; @@ -5004,12 +4942,6 @@ isp_control(ispsoftc_t *isp, ispctl_t ctl, ...) role = va_arg(ap, int); va_end(ap); if (IS_FC(isp)) { -#ifdef ISP_TARGET_MODE - if ((role & ISP_ROLE_TARGET) == 0) - isp_del_all_wwn_entries(isp, chan); -#endif - if ((role & ISP_ROLE_INITIATOR) == 0) - isp_del_all_init_entries(isp, chan); r = isp_fc_change_role(isp, chan, role); } else { SDPARAM(isp, chan)->role = role; @@ -7887,26 +7819,26 @@ isp_setdfltfcparm(ispsoftc_t *isp, int chan) * not disturb an already active list of commands. */ -void +int isp_reinit(ispsoftc_t *isp, int do_load_defaults) { - int i; + int i, res = 0; isp_reset(isp, do_load_defaults); - if (isp->isp_state != ISP_RESETSTATE) { + res = EIO; isp_prt(isp, ISP_LOGERR, "%s: cannot reset card", __func__); ISP_DISABLE_INTS(isp); goto cleanup; } isp_init(isp); - if (isp->isp_state == ISP_INITSTATE) { isp->isp_state = ISP_RUNSTATE; } if (isp->isp_state != ISP_RUNSTATE) { + res = EIO; #ifndef ISP_TARGET_MODE isp_prt(isp, ISP_LOGWARN, "%s: not at runstate", __func__); #endif @@ -7923,18 +7855,16 @@ isp_reinit(ispsoftc_t *isp, int do_load_defaults) ISP_WRITE(isp, BIU2100_CSR, BIU2100_RISC_REGS); } } - } + } cleanup: - isp->isp_nactive = 0; - isp_clear_commands(isp); if (IS_FC(isp)) { - for (i = 0; i < isp->isp_nchan; i++) { + for (i = 0; i < isp->isp_nchan; i++) ISP_MARK_PORTDB(isp, i, -1); - } } + return (res); } /* |