* requests.
                 */
                rval = qla2x00_get_port_database(vha, fcport, 0);
+               if (rval == QLA_NOT_LOGGED_IN) {
+                       fcport->flags &= ~FCF_ASYNC_SENT;
+                       fcport->flags |= FCF_LOGIN_NEEDED;
+                       set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
+                       break;
+               }
+
                if (rval != QLA_SUCCESS) {
                        qla2x00_post_async_logout_work(vha, fcport, NULL);
                        qla2x00_post_async_login_work(vha, fcport, NULL);
                        fcport->flags |= FCF_LOGIN_NEEDED;
                        if (fcport->loop_id != FC_NO_LOOP_ID &&
                            (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
+                           (fcport->flags & FCF_ASYNC_SENT) == 0 &&
                            fcport->port_type != FCT_INITIATOR &&
                            fcport->port_type != FCT_BROADCAST) {
                                ha->isp_ops->fabric_logout(vha, fcport->loop_id,
 
                goto gpd_error_out;
 
        if (IS_FWI2_CAPABLE(ha)) {
+               uint64_t zero = 0;
                pd24 = (struct port_database_24xx *) pd;
 
                /* Check for logged in state. */
                        goto gpd_error_out;
                }
 
+               if (fcport->loop_id == FC_NO_LOOP_ID ||
+                   (memcmp(fcport->port_name, (uint8_t *)&zero, 8) &&
+                    memcmp(fcport->port_name, pd24->port_name, 8))) {
+                       /* We lost the device mid way. */
+                       rval = QLA_NOT_LOGGED_IN;
+                       goto gpd_error_out;
+               }
+
                /* Names are little-endian. */
                memcpy(fcport->node_name, pd24->node_name, WWN_SIZE);
                memcpy(fcport->port_name, pd24->port_name, WWN_SIZE);
                else
                        fcport->port_type = FCT_TARGET;
        } else {
+               uint64_t zero = 0;
+
                /* Check for logged in state. */
                if (pd->master_state != PD_STATE_PORT_LOGGED_IN &&
                    pd->slave_state != PD_STATE_PORT_LOGGED_IN) {
                        goto gpd_error_out;
                }
 
+               if (fcport->loop_id == FC_NO_LOOP_ID ||
+                   (memcmp(fcport->port_name, (uint8_t *)&zero, 8) &&
+                    memcmp(fcport->port_name, pd->port_name, 8))) {
+                       /* We lost the device mid way. */
+                       rval = QLA_NOT_LOGGED_IN;
+                       goto gpd_error_out;
+               }
+
                /* Names are little-endian. */
                memcpy(fcport->node_name, pd->node_name, WWN_SIZE);
                memcpy(fcport->port_name, pd->port_name, WWN_SIZE);