1143 for (i = 0; i < port->port_max_logins; i++) {
1144 if (iport->iport_rp_slots[i] == NULL) {
1145 break;
1146 }
1147 }
1148 if (i == port->port_max_logins) {
1149 /* This is really pushing it. */
1150 (void) snprintf(info, sizeof (info),
1151 "fct_register_remote_port "
1152 "Cannot register portid %x because all the "
1153 "handles are used up", rp->rp_id);
1154 goto hba_fatal_err;
1155 }
1156 rp->rp_handle = i;
1157 }
1158 /* By this time rport_handle is valid */
1159 if ((irp->irp_flags & IRP_HANDLE_OPENED) == 0) {
1160 iport->iport_rp_slots[rp->rp_handle] = irp;
1161 atomic_or_32(&irp->irp_flags, IRP_HANDLE_OPENED);
1162 }
1163 (void) atomic_inc_64_nv(&iport->iport_last_change);
1164 fct_log_remote_port_event(port, ESC_SUNFC_TARGET_ADD,
1165 rp->rp_pwwn, rp->rp_id);
1166
1167 register_rp_done:;
1168 rw_exit(&irp->irp_lock);
1169 rw_exit(&iport->iport_lock);
1170 return (FCT_SUCCESS);
1171
1172 hba_fatal_err:;
1173 rw_exit(&irp->irp_lock);
1174 rw_exit(&iport->iport_lock);
1175 /*
1176 * XXX Throw HBA fatal error event
1177 */
1178 (void) fct_port_shutdown(iport->iport_port,
1179 STMF_RFLAG_FATAL_ERROR | STMF_RFLAG_RESET, info);
1180 return (FCT_FAILURE);
1181 }
1182
1183 fct_status_t
1188 fct_i_remote_port_t *irp = RP_TO_IRP(rp);
1189
1190 if (irp->irp_snn) {
1191 kmem_free(irp->irp_snn, strlen(irp->irp_snn) + 1);
1192 irp->irp_snn = NULL;
1193 }
1194 if (irp->irp_spn) {
1195 kmem_free(irp->irp_spn, strlen(irp->irp_spn) + 1);
1196 irp->irp_spn = NULL;
1197 }
1198
1199 if ((ret = port->port_deregister_remote_port(port, rp)) !=
1200 FCT_SUCCESS) {
1201 return (ret);
1202 }
1203
1204 if (irp->irp_flags & IRP_HANDLE_OPENED) {
1205 atomic_and_32(&irp->irp_flags, ~IRP_HANDLE_OPENED);
1206 iport->iport_rp_slots[rp->rp_handle] = NULL;
1207 }
1208 (void) atomic_inc_64_nv(&iport->iport_last_change);
1209 fct_log_remote_port_event(port, ESC_SUNFC_TARGET_REMOVE,
1210 rp->rp_pwwn, rp->rp_id);
1211
1212 return (FCT_SUCCESS);
1213 }
1214
1215 fct_status_t
1216 fct_send_accrjt(fct_cmd_t *cmd, uint8_t accrjt, uint8_t reason, uint8_t expl)
1217 {
1218 fct_local_port_t *port = (fct_local_port_t *)cmd->cmd_port;
1219 fct_els_t *els = (fct_els_t *)cmd->cmd_specific;
1220
1221 els->els_resp_size = els->els_resp_alloc_size = 8;
1222 els->els_resp_payload = (uint8_t *)kmem_zalloc(8, KM_SLEEP);
1223 els->els_resp_payload[0] = accrjt;
1224 if (accrjt == 1) {
1225 els->els_resp_payload[5] = reason;
1226 els->els_resp_payload[6] = expl;
1227 } else {
1228 els->els_resp_size = 4;
|
1143 for (i = 0; i < port->port_max_logins; i++) {
1144 if (iport->iport_rp_slots[i] == NULL) {
1145 break;
1146 }
1147 }
1148 if (i == port->port_max_logins) {
1149 /* This is really pushing it. */
1150 (void) snprintf(info, sizeof (info),
1151 "fct_register_remote_port "
1152 "Cannot register portid %x because all the "
1153 "handles are used up", rp->rp_id);
1154 goto hba_fatal_err;
1155 }
1156 rp->rp_handle = i;
1157 }
1158 /* By this time rport_handle is valid */
1159 if ((irp->irp_flags & IRP_HANDLE_OPENED) == 0) {
1160 iport->iport_rp_slots[rp->rp_handle] = irp;
1161 atomic_or_32(&irp->irp_flags, IRP_HANDLE_OPENED);
1162 }
1163 atomic_inc_64(&iport->iport_last_change);
1164 fct_log_remote_port_event(port, ESC_SUNFC_TARGET_ADD,
1165 rp->rp_pwwn, rp->rp_id);
1166
1167 register_rp_done:;
1168 rw_exit(&irp->irp_lock);
1169 rw_exit(&iport->iport_lock);
1170 return (FCT_SUCCESS);
1171
1172 hba_fatal_err:;
1173 rw_exit(&irp->irp_lock);
1174 rw_exit(&iport->iport_lock);
1175 /*
1176 * XXX Throw HBA fatal error event
1177 */
1178 (void) fct_port_shutdown(iport->iport_port,
1179 STMF_RFLAG_FATAL_ERROR | STMF_RFLAG_RESET, info);
1180 return (FCT_FAILURE);
1181 }
1182
1183 fct_status_t
1188 fct_i_remote_port_t *irp = RP_TO_IRP(rp);
1189
1190 if (irp->irp_snn) {
1191 kmem_free(irp->irp_snn, strlen(irp->irp_snn) + 1);
1192 irp->irp_snn = NULL;
1193 }
1194 if (irp->irp_spn) {
1195 kmem_free(irp->irp_spn, strlen(irp->irp_spn) + 1);
1196 irp->irp_spn = NULL;
1197 }
1198
1199 if ((ret = port->port_deregister_remote_port(port, rp)) !=
1200 FCT_SUCCESS) {
1201 return (ret);
1202 }
1203
1204 if (irp->irp_flags & IRP_HANDLE_OPENED) {
1205 atomic_and_32(&irp->irp_flags, ~IRP_HANDLE_OPENED);
1206 iport->iport_rp_slots[rp->rp_handle] = NULL;
1207 }
1208 atomic_inc_64(&iport->iport_last_change);
1209 fct_log_remote_port_event(port, ESC_SUNFC_TARGET_REMOVE,
1210 rp->rp_pwwn, rp->rp_id);
1211
1212 return (FCT_SUCCESS);
1213 }
1214
1215 fct_status_t
1216 fct_send_accrjt(fct_cmd_t *cmd, uint8_t accrjt, uint8_t reason, uint8_t expl)
1217 {
1218 fct_local_port_t *port = (fct_local_port_t *)cmd->cmd_port;
1219 fct_els_t *els = (fct_els_t *)cmd->cmd_specific;
1220
1221 els->els_resp_size = els->els_resp_alloc_size = 8;
1222 els->els_resp_payload = (uint8_t *)kmem_zalloc(8, KM_SLEEP);
1223 els->els_resp_payload[0] = accrjt;
1224 if (accrjt == 1) {
1225 els->els_resp_payload[5] = reason;
1226 els->els_resp_payload[6] = expl;
1227 } else {
1228 els->els_resp_size = 4;
|