1 // SPDX-License-Identifier: GPL-2.0-only 2 /* 3 * QLogic Fibre Channel HBA Driver 4 * Copyright (c) 2003-2014 QLogic Corporation 5 */ 6 #include "qla_def.h" 7 #include "qla_gbl.h" 8 9 #include <linux/delay.h> 10 #include <linux/slab.h> 11 #include <linux/vmalloc.h> 12 13 #include "qla_devtbl.h" 14 15 #ifdef CONFIG_SPARC 16 #include <asm/prom.h> 17 #endif 18 19 #include "qla_target.h" 20 21 /* 22 * QLogic ISP2x00 Hardware Support Function Prototypes. 23 */ 24 static int qla2x00_isp_firmware(scsi_qla_host_t *); 25 static int qla2x00_setup_chip(scsi_qla_host_t *); 26 static int qla2x00_fw_ready(scsi_qla_host_t *); 27 static int qla2x00_configure_hba(scsi_qla_host_t *); 28 static int qla2x00_configure_loop(scsi_qla_host_t *); 29 static int qla2x00_configure_local_loop(scsi_qla_host_t *); 30 static int qla2x00_configure_fabric(scsi_qla_host_t *); 31 static int qla2x00_find_all_fabric_devs(scsi_qla_host_t *); 32 static int qla2x00_restart_isp(scsi_qla_host_t *); 33 34 static struct qla_chip_state_84xx *qla84xx_get_chip(struct scsi_qla_host *); 35 static int qla84xx_init_chip(scsi_qla_host_t *); 36 static int qla25xx_init_queues(struct qla_hw_data *); 37 static void qla24xx_handle_gpdb_event(scsi_qla_host_t *vha, 38 struct event_arg *ea); 39 static void qla24xx_handle_prli_done_event(struct scsi_qla_host *, 40 struct event_arg *); 41 static void __qla24xx_handle_gpdb_event(scsi_qla_host_t *, struct event_arg *); 42 43 /* SRB Extensions ---------------------------------------------------------- */ 44 45 void 46 qla2x00_sp_timeout(struct timer_list *t) 47 { 48 srb_t *sp = from_timer(sp, t, u.iocb_cmd.timer); 49 struct srb_iocb *iocb; 50 51 WARN_ON(irqs_disabled()); 52 iocb = &sp->u.iocb_cmd; 53 iocb->timeout(sp); 54 } 55 56 void qla2x00_sp_free(srb_t *sp) 57 { 58 struct srb_iocb *iocb = &sp->u.iocb_cmd; 59 60 del_timer(&iocb->timer); 61 qla2x00_rel_sp(sp); 62 } 63 64 void qla2xxx_rel_done_warning(srb_t *sp, int res) 65 { 66 WARN_ONCE(1, "Calling done() of an already freed srb %p object\n", sp); 67 } 68 69 void qla2xxx_rel_free_warning(srb_t *sp) 70 { 71 WARN_ONCE(1, "Calling free() of an already freed srb %p object\n", sp); 72 } 73 74 /* Asynchronous Login/Logout Routines -------------------------------------- */ 75 76 unsigned long 77 qla2x00_get_async_timeout(struct scsi_qla_host *vha) 78 { 79 unsigned long tmo; 80 struct qla_hw_data *ha = vha->hw; 81 82 /* Firmware should use switch negotiated r_a_tov for timeout. */ 83 tmo = ha->r_a_tov / 10 * 2; 84 if (IS_QLAFX00(ha)) { 85 tmo = FX00_DEF_RATOV * 2; 86 } else if (!IS_FWI2_CAPABLE(ha)) { 87 /* 88 * Except for earlier ISPs where the timeout is seeded from the 89 * initialization control block. 90 */ 91 tmo = ha->login_timeout; 92 } 93 return tmo; 94 } 95 96 static void qla24xx_abort_iocb_timeout(void *data) 97 { 98 srb_t *sp = data; 99 struct srb_iocb *abt = &sp->u.iocb_cmd; 100 struct qla_qpair *qpair = sp->qpair; 101 u32 handle; 102 unsigned long flags; 103 104 if (sp->cmd_sp) 105 ql_dbg(ql_dbg_async, sp->vha, 0x507c, 106 "Abort timeout - cmd hdl=%x, cmd type=%x hdl=%x, type=%x\n", 107 sp->cmd_sp->handle, sp->cmd_sp->type, 108 sp->handle, sp->type); 109 else 110 ql_dbg(ql_dbg_async, sp->vha, 0x507c, 111 "Abort timeout 2 - hdl=%x, type=%x\n", 112 sp->handle, sp->type); 113 114 spin_lock_irqsave(qpair->qp_lock_ptr, flags); 115 for (handle = 1; handle < qpair->req->num_outstanding_cmds; handle++) { 116 if (sp->cmd_sp && (qpair->req->outstanding_cmds[handle] == 117 sp->cmd_sp)) 118 qpair->req->outstanding_cmds[handle] = NULL; 119 120 /* removing the abort */ 121 if (qpair->req->outstanding_cmds[handle] == sp) { 122 qpair->req->outstanding_cmds[handle] = NULL; 123 break; 124 } 125 } 126 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); 127 128 if (sp->cmd_sp) 129 sp->cmd_sp->done(sp->cmd_sp, QLA_OS_TIMER_EXPIRED); 130 131 abt->u.abt.comp_status = cpu_to_le16(CS_TIMEOUT); 132 sp->done(sp, QLA_OS_TIMER_EXPIRED); 133 } 134 135 static void qla24xx_abort_sp_done(srb_t *sp, int res) 136 { 137 struct srb_iocb *abt = &sp->u.iocb_cmd; 138 srb_t *orig_sp = sp->cmd_sp; 139 140 if (orig_sp) 141 qla_wait_nvme_release_cmd_kref(orig_sp); 142 143 del_timer(&sp->u.iocb_cmd.timer); 144 if (sp->flags & SRB_WAKEUP_ON_COMP) 145 complete(&abt->u.abt.comp); 146 else 147 sp->free(sp); 148 } 149 150 int qla24xx_async_abort_cmd(srb_t *cmd_sp, bool wait) 151 { 152 scsi_qla_host_t *vha = cmd_sp->vha; 153 struct srb_iocb *abt_iocb; 154 srb_t *sp; 155 int rval = QLA_FUNCTION_FAILED; 156 157 sp = qla2xxx_get_qpair_sp(cmd_sp->vha, cmd_sp->qpair, cmd_sp->fcport, 158 GFP_ATOMIC); 159 if (!sp) 160 return QLA_MEMORY_ALLOC_FAILED; 161 162 abt_iocb = &sp->u.iocb_cmd; 163 sp->type = SRB_ABT_CMD; 164 sp->name = "abort"; 165 sp->qpair = cmd_sp->qpair; 166 sp->cmd_sp = cmd_sp; 167 if (wait) 168 sp->flags = SRB_WAKEUP_ON_COMP; 169 170 abt_iocb->timeout = qla24xx_abort_iocb_timeout; 171 init_completion(&abt_iocb->u.abt.comp); 172 /* FW can send 2 x ABTS's timeout/20s */ 173 qla2x00_init_timer(sp, 42); 174 175 abt_iocb->u.abt.cmd_hndl = cmd_sp->handle; 176 abt_iocb->u.abt.req_que_no = cpu_to_le16(cmd_sp->qpair->req->id); 177 178 sp->done = qla24xx_abort_sp_done; 179 180 ql_dbg(ql_dbg_async, vha, 0x507c, 181 "Abort command issued - hdl=%x, type=%x\n", cmd_sp->handle, 182 cmd_sp->type); 183 184 rval = qla2x00_start_sp(sp); 185 if (rval != QLA_SUCCESS) { 186 sp->free(sp); 187 return rval; 188 } 189 190 if (wait) { 191 wait_for_completion(&abt_iocb->u.abt.comp); 192 rval = abt_iocb->u.abt.comp_status == CS_COMPLETE ? 193 QLA_SUCCESS : QLA_ERR_FROM_FW; 194 sp->free(sp); 195 } 196 197 return rval; 198 } 199 200 void 201 qla2x00_async_iocb_timeout(void *data) 202 { 203 srb_t *sp = data; 204 fc_port_t *fcport = sp->fcport; 205 struct srb_iocb *lio = &sp->u.iocb_cmd; 206 int rc, h; 207 unsigned long flags; 208 209 if (fcport) { 210 ql_dbg(ql_dbg_disc, fcport->vha, 0x2071, 211 "Async-%s timeout - hdl=%x portid=%06x %8phC.\n", 212 sp->name, sp->handle, fcport->d_id.b24, fcport->port_name); 213 214 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE); 215 } else { 216 pr_info("Async-%s timeout - hdl=%x.\n", 217 sp->name, sp->handle); 218 } 219 220 switch (sp->type) { 221 case SRB_LOGIN_CMD: 222 rc = qla24xx_async_abort_cmd(sp, false); 223 if (rc) { 224 /* Retry as needed. */ 225 lio->u.logio.data[0] = MBS_COMMAND_ERROR; 226 lio->u.logio.data[1] = 227 lio->u.logio.flags & SRB_LOGIN_RETRIED ? 228 QLA_LOGIO_LOGIN_RETRIED : 0; 229 spin_lock_irqsave(sp->qpair->qp_lock_ptr, flags); 230 for (h = 1; h < sp->qpair->req->num_outstanding_cmds; 231 h++) { 232 if (sp->qpair->req->outstanding_cmds[h] == 233 sp) { 234 sp->qpair->req->outstanding_cmds[h] = 235 NULL; 236 break; 237 } 238 } 239 spin_unlock_irqrestore(sp->qpair->qp_lock_ptr, flags); 240 sp->done(sp, QLA_FUNCTION_TIMEOUT); 241 } 242 break; 243 case SRB_LOGOUT_CMD: 244 case SRB_CT_PTHRU_CMD: 245 case SRB_MB_IOCB: 246 case SRB_NACK_PLOGI: 247 case SRB_NACK_PRLI: 248 case SRB_NACK_LOGO: 249 case SRB_CTRL_VP: 250 default: 251 rc = qla24xx_async_abort_cmd(sp, false); 252 if (rc) { 253 spin_lock_irqsave(sp->qpair->qp_lock_ptr, flags); 254 for (h = 1; h < sp->qpair->req->num_outstanding_cmds; 255 h++) { 256 if (sp->qpair->req->outstanding_cmds[h] == 257 sp) { 258 sp->qpair->req->outstanding_cmds[h] = 259 NULL; 260 break; 261 } 262 } 263 spin_unlock_irqrestore(sp->qpair->qp_lock_ptr, flags); 264 sp->done(sp, QLA_FUNCTION_TIMEOUT); 265 } 266 break; 267 } 268 } 269 270 static void qla2x00_async_login_sp_done(srb_t *sp, int res) 271 { 272 struct scsi_qla_host *vha = sp->vha; 273 struct srb_iocb *lio = &sp->u.iocb_cmd; 274 struct event_arg ea; 275 276 ql_dbg(ql_dbg_disc, vha, 0x20dd, 277 "%s %8phC res %d \n", __func__, sp->fcport->port_name, res); 278 279 sp->fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE); 280 281 if (!test_bit(UNLOADING, &vha->dpc_flags)) { 282 memset(&ea, 0, sizeof(ea)); 283 ea.fcport = sp->fcport; 284 ea.data[0] = lio->u.logio.data[0]; 285 ea.data[1] = lio->u.logio.data[1]; 286 ea.iop[0] = lio->u.logio.iop[0]; 287 ea.iop[1] = lio->u.logio.iop[1]; 288 ea.sp = sp; 289 qla24xx_handle_plogi_done_event(vha, &ea); 290 } 291 292 sp->free(sp); 293 } 294 295 int 296 qla2x00_async_login(struct scsi_qla_host *vha, fc_port_t *fcport, 297 uint16_t *data) 298 { 299 srb_t *sp; 300 struct srb_iocb *lio; 301 int rval = QLA_FUNCTION_FAILED; 302 303 if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT) || 304 fcport->loop_id == FC_NO_LOOP_ID) { 305 ql_log(ql_log_warn, vha, 0xffff, 306 "%s: %8phC - not sending command.\n", 307 __func__, fcport->port_name); 308 return rval; 309 } 310 311 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); 312 if (!sp) 313 goto done; 314 315 qla2x00_set_fcport_disc_state(fcport, DSC_LOGIN_PEND); 316 fcport->flags |= FCF_ASYNC_SENT; 317 fcport->logout_completed = 0; 318 319 sp->type = SRB_LOGIN_CMD; 320 sp->name = "login"; 321 sp->gen1 = fcport->rscn_gen; 322 sp->gen2 = fcport->login_gen; 323 324 lio = &sp->u.iocb_cmd; 325 lio->timeout = qla2x00_async_iocb_timeout; 326 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2); 327 328 sp->done = qla2x00_async_login_sp_done; 329 if (N2N_TOPO(fcport->vha->hw) && fcport_is_bigger(fcport)) { 330 lio->u.logio.flags |= SRB_LOGIN_PRLI_ONLY; 331 } else { 332 if (vha->hw->flags.edif_enabled && 333 vha->e_dbell.db_flags & EDB_ACTIVE) { 334 lio->u.logio.flags |= 335 (SRB_LOGIN_FCSP | SRB_LOGIN_SKIP_PRLI); 336 ql_dbg(ql_dbg_disc, vha, 0x2072, 337 "Async-login: w/ FCSP %8phC hdl=%x, loopid=%x portid=%06x\n", 338 fcport->port_name, sp->handle, fcport->loop_id, fcport->d_id.b24); 339 } else { 340 lio->u.logio.flags |= SRB_LOGIN_COND_PLOGI; 341 } 342 } 343 344 if (NVME_TARGET(vha->hw, fcport)) 345 lio->u.logio.flags |= SRB_LOGIN_SKIP_PRLI; 346 347 ql_dbg(ql_dbg_disc, vha, 0x2072, 348 "Async-login - %8phC hdl=%x, loopid=%x portid=%06x retries=%d.\n", 349 fcport->port_name, sp->handle, fcport->loop_id, 350 fcport->d_id.b24, fcport->login_retry); 351 352 rval = qla2x00_start_sp(sp); 353 if (rval != QLA_SUCCESS) { 354 fcport->flags |= FCF_LOGIN_NEEDED; 355 set_bit(RELOGIN_NEEDED, &vha->dpc_flags); 356 goto done_free_sp; 357 } 358 359 return rval; 360 361 done_free_sp: 362 sp->free(sp); 363 fcport->flags &= ~FCF_ASYNC_SENT; 364 done: 365 fcport->flags &= ~FCF_ASYNC_ACTIVE; 366 return rval; 367 } 368 369 static void qla2x00_async_logout_sp_done(srb_t *sp, int res) 370 { 371 sp->fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE); 372 sp->fcport->login_gen++; 373 qlt_logo_completion_handler(sp->fcport, sp->u.iocb_cmd.u.logio.data[0]); 374 sp->free(sp); 375 } 376 377 int 378 qla2x00_async_logout(struct scsi_qla_host *vha, fc_port_t *fcport) 379 { 380 srb_t *sp; 381 struct srb_iocb *lio; 382 int rval = QLA_FUNCTION_FAILED; 383 384 fcport->flags |= FCF_ASYNC_SENT; 385 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); 386 if (!sp) 387 goto done; 388 389 sp->type = SRB_LOGOUT_CMD; 390 sp->name = "logout"; 391 392 lio = &sp->u.iocb_cmd; 393 lio->timeout = qla2x00_async_iocb_timeout; 394 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2); 395 396 sp->done = qla2x00_async_logout_sp_done; 397 398 ql_dbg(ql_dbg_disc, vha, 0x2070, 399 "Async-logout - hdl=%x loop-id=%x portid=%02x%02x%02x %8phC explicit %d.\n", 400 sp->handle, fcport->loop_id, fcport->d_id.b.domain, 401 fcport->d_id.b.area, fcport->d_id.b.al_pa, 402 fcport->port_name, fcport->explicit_logout); 403 404 rval = qla2x00_start_sp(sp); 405 if (rval != QLA_SUCCESS) 406 goto done_free_sp; 407 return rval; 408 409 done_free_sp: 410 sp->free(sp); 411 done: 412 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE); 413 return rval; 414 } 415 416 void 417 qla2x00_async_prlo_done(struct scsi_qla_host *vha, fc_port_t *fcport, 418 uint16_t *data) 419 { 420 fcport->flags &= ~FCF_ASYNC_ACTIVE; 421 /* Don't re-login in target mode */ 422 if (!fcport->tgt_session) 423 qla2x00_mark_device_lost(vha, fcport, 1); 424 qlt_logo_completion_handler(fcport, data[0]); 425 } 426 427 static void qla2x00_async_prlo_sp_done(srb_t *sp, int res) 428 { 429 struct srb_iocb *lio = &sp->u.iocb_cmd; 430 struct scsi_qla_host *vha = sp->vha; 431 432 sp->fcport->flags &= ~FCF_ASYNC_ACTIVE; 433 if (!test_bit(UNLOADING, &vha->dpc_flags)) 434 qla2x00_post_async_prlo_done_work(sp->fcport->vha, sp->fcport, 435 lio->u.logio.data); 436 sp->free(sp); 437 } 438 439 int 440 qla2x00_async_prlo(struct scsi_qla_host *vha, fc_port_t *fcport) 441 { 442 srb_t *sp; 443 struct srb_iocb *lio; 444 int rval; 445 446 rval = QLA_FUNCTION_FAILED; 447 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); 448 if (!sp) 449 goto done; 450 451 sp->type = SRB_PRLO_CMD; 452 sp->name = "prlo"; 453 454 lio = &sp->u.iocb_cmd; 455 lio->timeout = qla2x00_async_iocb_timeout; 456 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2); 457 458 sp->done = qla2x00_async_prlo_sp_done; 459 460 ql_dbg(ql_dbg_disc, vha, 0x2070, 461 "Async-prlo - hdl=%x loop-id=%x portid=%02x%02x%02x.\n", 462 sp->handle, fcport->loop_id, fcport->d_id.b.domain, 463 fcport->d_id.b.area, fcport->d_id.b.al_pa); 464 465 rval = qla2x00_start_sp(sp); 466 if (rval != QLA_SUCCESS) 467 goto done_free_sp; 468 469 return rval; 470 471 done_free_sp: 472 sp->free(sp); 473 done: 474 fcport->flags &= ~FCF_ASYNC_ACTIVE; 475 return rval; 476 } 477 478 static 479 void qla24xx_handle_adisc_event(scsi_qla_host_t *vha, struct event_arg *ea) 480 { 481 struct fc_port *fcport = ea->fcport; 482 483 ql_dbg(ql_dbg_disc, vha, 0x20d2, 484 "%s %8phC DS %d LS %d rc %d login %d|%d rscn %d|%d lid %d\n", 485 __func__, fcport->port_name, fcport->disc_state, 486 fcport->fw_login_state, ea->rc, fcport->login_gen, ea->sp->gen2, 487 fcport->rscn_gen, ea->sp->gen1, fcport->loop_id); 488 489 WARN_ONCE(!qla2xxx_is_valid_mbs(ea->data[0]), "mbs: %#x\n", 490 ea->data[0]); 491 492 if (ea->data[0] != MBS_COMMAND_COMPLETE) { 493 ql_dbg(ql_dbg_disc, vha, 0x2066, 494 "%s %8phC: adisc fail: post delete\n", 495 __func__, ea->fcport->port_name); 496 /* deleted = 0 & logout_on_delete = force fw cleanup */ 497 fcport->deleted = 0; 498 fcport->logout_on_delete = 1; 499 qlt_schedule_sess_for_deletion(ea->fcport); 500 return; 501 } 502 503 if (ea->fcport->disc_state == DSC_DELETE_PEND) 504 return; 505 506 if (ea->sp->gen2 != ea->fcport->login_gen) { 507 /* target side must have changed it. */ 508 ql_dbg(ql_dbg_disc, vha, 0x20d3, 509 "%s %8phC generation changed\n", 510 __func__, ea->fcport->port_name); 511 return; 512 } else if (ea->sp->gen1 != ea->fcport->rscn_gen) { 513 qla_rscn_replay(fcport); 514 qlt_schedule_sess_for_deletion(fcport); 515 return; 516 } 517 518 __qla24xx_handle_gpdb_event(vha, ea); 519 } 520 521 static int qla_post_els_plogi_work(struct scsi_qla_host *vha, fc_port_t *fcport) 522 { 523 struct qla_work_evt *e; 524 525 e = qla2x00_alloc_work(vha, QLA_EVT_ELS_PLOGI); 526 if (!e) 527 return QLA_FUNCTION_FAILED; 528 529 e->u.fcport.fcport = fcport; 530 fcport->flags |= FCF_ASYNC_ACTIVE; 531 qla2x00_set_fcport_disc_state(fcport, DSC_LOGIN_PEND); 532 return qla2x00_post_work(vha, e); 533 } 534 535 static void qla2x00_async_adisc_sp_done(srb_t *sp, int res) 536 { 537 struct scsi_qla_host *vha = sp->vha; 538 struct event_arg ea; 539 struct srb_iocb *lio = &sp->u.iocb_cmd; 540 541 ql_dbg(ql_dbg_disc, vha, 0x2066, 542 "Async done-%s res %x %8phC\n", 543 sp->name, res, sp->fcport->port_name); 544 545 sp->fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE); 546 547 memset(&ea, 0, sizeof(ea)); 548 ea.rc = res; 549 ea.data[0] = lio->u.logio.data[0]; 550 ea.data[1] = lio->u.logio.data[1]; 551 ea.iop[0] = lio->u.logio.iop[0]; 552 ea.iop[1] = lio->u.logio.iop[1]; 553 ea.fcport = sp->fcport; 554 ea.sp = sp; 555 556 qla24xx_handle_adisc_event(vha, &ea); 557 558 sp->free(sp); 559 } 560 561 int 562 qla2x00_async_adisc(struct scsi_qla_host *vha, fc_port_t *fcport, 563 uint16_t *data) 564 { 565 srb_t *sp; 566 struct srb_iocb *lio; 567 int rval = QLA_FUNCTION_FAILED; 568 569 if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT)) 570 return rval; 571 572 fcport->flags |= FCF_ASYNC_SENT; 573 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); 574 if (!sp) 575 goto done; 576 577 sp->type = SRB_ADISC_CMD; 578 sp->name = "adisc"; 579 580 lio = &sp->u.iocb_cmd; 581 lio->timeout = qla2x00_async_iocb_timeout; 582 sp->gen1 = fcport->rscn_gen; 583 sp->gen2 = fcport->login_gen; 584 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2); 585 586 sp->done = qla2x00_async_adisc_sp_done; 587 if (data[1] & QLA_LOGIO_LOGIN_RETRIED) 588 lio->u.logio.flags |= SRB_LOGIN_RETRIED; 589 590 ql_dbg(ql_dbg_disc, vha, 0x206f, 591 "Async-adisc - hdl=%x loopid=%x portid=%06x %8phC.\n", 592 sp->handle, fcport->loop_id, fcport->d_id.b24, fcport->port_name); 593 594 rval = qla2x00_start_sp(sp); 595 if (rval != QLA_SUCCESS) 596 goto done_free_sp; 597 598 return rval; 599 600 done_free_sp: 601 sp->free(sp); 602 done: 603 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE); 604 qla2x00_post_async_adisc_work(vha, fcport, data); 605 return rval; 606 } 607 608 static bool qla2x00_is_reserved_id(scsi_qla_host_t *vha, uint16_t loop_id) 609 { 610 struct qla_hw_data *ha = vha->hw; 611 612 if (IS_FWI2_CAPABLE(ha)) 613 return loop_id > NPH_LAST_HANDLE; 614 615 return (loop_id > ha->max_loop_id && loop_id < SNS_FIRST_LOOP_ID) || 616 loop_id == MANAGEMENT_SERVER || loop_id == BROADCAST; 617 } 618 619 /** 620 * qla2x00_find_new_loop_id - scan through our port list and find a new usable loop ID 621 * @vha: adapter state pointer. 622 * @dev: port structure pointer. 623 * 624 * Returns: 625 * qla2x00 local function return status code. 626 * 627 * Context: 628 * Kernel context. 629 */ 630 static int qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev) 631 { 632 int rval; 633 struct qla_hw_data *ha = vha->hw; 634 unsigned long flags = 0; 635 636 rval = QLA_SUCCESS; 637 638 spin_lock_irqsave(&ha->vport_slock, flags); 639 640 dev->loop_id = find_first_zero_bit(ha->loop_id_map, LOOPID_MAP_SIZE); 641 if (dev->loop_id >= LOOPID_MAP_SIZE || 642 qla2x00_is_reserved_id(vha, dev->loop_id)) { 643 dev->loop_id = FC_NO_LOOP_ID; 644 rval = QLA_FUNCTION_FAILED; 645 } else { 646 set_bit(dev->loop_id, ha->loop_id_map); 647 } 648 spin_unlock_irqrestore(&ha->vport_slock, flags); 649 650 if (rval == QLA_SUCCESS) 651 ql_dbg(ql_dbg_disc, dev->vha, 0x2086, 652 "Assigning new loopid=%x, portid=%x.\n", 653 dev->loop_id, dev->d_id.b24); 654 else 655 ql_log(ql_log_warn, dev->vha, 0x2087, 656 "No loop_id's available, portid=%x.\n", 657 dev->d_id.b24); 658 659 return rval; 660 } 661 662 void qla2x00_clear_loop_id(fc_port_t *fcport) 663 { 664 struct qla_hw_data *ha = fcport->vha->hw; 665 666 if (fcport->loop_id == FC_NO_LOOP_ID || 667 qla2x00_is_reserved_id(fcport->vha, fcport->loop_id)) 668 return; 669 670 clear_bit(fcport->loop_id, ha->loop_id_map); 671 fcport->loop_id = FC_NO_LOOP_ID; 672 } 673 674 static void qla24xx_handle_gnl_done_event(scsi_qla_host_t *vha, 675 struct event_arg *ea) 676 { 677 fc_port_t *fcport, *conflict_fcport; 678 struct get_name_list_extended *e; 679 u16 i, n, found = 0, loop_id; 680 port_id_t id; 681 u64 wwn; 682 u16 data[2]; 683 u8 current_login_state, nvme_cls; 684 685 fcport = ea->fcport; 686 ql_dbg(ql_dbg_disc, vha, 0xffff, 687 "%s %8phC DS %d LS rc %d %d login %d|%d rscn %d|%d lid %d edif %d\n", 688 __func__, fcport->port_name, fcport->disc_state, 689 fcport->fw_login_state, ea->rc, 690 fcport->login_gen, fcport->last_login_gen, 691 fcport->rscn_gen, fcport->last_rscn_gen, vha->loop_id, fcport->edif.enable); 692 693 if (fcport->disc_state == DSC_DELETE_PEND) 694 return; 695 696 if (ea->rc) { /* rval */ 697 if (fcport->login_retry == 0) { 698 ql_dbg(ql_dbg_disc, vha, 0x20de, 699 "GNL failed Port login retry %8phN, retry cnt=%d.\n", 700 fcport->port_name, fcport->login_retry); 701 } 702 return; 703 } 704 705 if (fcport->last_rscn_gen != fcport->rscn_gen) { 706 qla_rscn_replay(fcport); 707 qlt_schedule_sess_for_deletion(fcport); 708 return; 709 } else if (fcport->last_login_gen != fcport->login_gen) { 710 ql_dbg(ql_dbg_disc, vha, 0x20e0, 711 "%s %8phC login gen changed\n", 712 __func__, fcport->port_name); 713 set_bit(RELOGIN_NEEDED, &vha->dpc_flags); 714 return; 715 } 716 717 n = ea->data[0] / sizeof(struct get_name_list_extended); 718 719 ql_dbg(ql_dbg_disc, vha, 0x20e1, 720 "%s %d %8phC n %d %02x%02x%02x lid %d \n", 721 __func__, __LINE__, fcport->port_name, n, 722 fcport->d_id.b.domain, fcport->d_id.b.area, 723 fcport->d_id.b.al_pa, fcport->loop_id); 724 725 for (i = 0; i < n; i++) { 726 e = &vha->gnl.l[i]; 727 wwn = wwn_to_u64(e->port_name); 728 id.b.domain = e->port_id[2]; 729 id.b.area = e->port_id[1]; 730 id.b.al_pa = e->port_id[0]; 731 id.b.rsvd_1 = 0; 732 733 if (memcmp((u8 *)&wwn, fcport->port_name, WWN_SIZE)) 734 continue; 735 736 if (IS_SW_RESV_ADDR(id)) 737 continue; 738 739 found = 1; 740 741 loop_id = le16_to_cpu(e->nport_handle); 742 loop_id = (loop_id & 0x7fff); 743 nvme_cls = e->current_login_state >> 4; 744 current_login_state = e->current_login_state & 0xf; 745 746 if (PRLI_PHASE(nvme_cls)) { 747 current_login_state = nvme_cls; 748 fcport->fc4_type &= ~FS_FC4TYPE_FCP; 749 fcport->fc4_type |= FS_FC4TYPE_NVME; 750 } else if (PRLI_PHASE(current_login_state)) { 751 fcport->fc4_type |= FS_FC4TYPE_FCP; 752 fcport->fc4_type &= ~FS_FC4TYPE_NVME; 753 } 754 755 ql_dbg(ql_dbg_disc, vha, 0x20e2, 756 "%s found %8phC CLS [%x|%x] fc4_type %d ID[%06x|%06x] lid[%d|%d]\n", 757 __func__, fcport->port_name, 758 e->current_login_state, fcport->fw_login_state, 759 fcport->fc4_type, id.b24, fcport->d_id.b24, 760 loop_id, fcport->loop_id); 761 762 switch (fcport->disc_state) { 763 case DSC_DELETE_PEND: 764 case DSC_DELETED: 765 break; 766 default: 767 if ((id.b24 != fcport->d_id.b24 && 768 fcport->d_id.b24 && 769 fcport->loop_id != FC_NO_LOOP_ID) || 770 (fcport->loop_id != FC_NO_LOOP_ID && 771 fcport->loop_id != loop_id)) { 772 ql_dbg(ql_dbg_disc, vha, 0x20e3, 773 "%s %d %8phC post del sess\n", 774 __func__, __LINE__, fcport->port_name); 775 if (fcport->n2n_flag) 776 fcport->d_id.b24 = 0; 777 qlt_schedule_sess_for_deletion(fcport); 778 return; 779 } 780 break; 781 } 782 783 fcport->loop_id = loop_id; 784 if (fcport->n2n_flag) 785 fcport->d_id.b24 = id.b24; 786 787 wwn = wwn_to_u64(fcport->port_name); 788 qlt_find_sess_invalidate_other(vha, wwn, 789 id, loop_id, &conflict_fcport); 790 791 if (conflict_fcport) { 792 /* 793 * Another share fcport share the same loop_id & 794 * nport id. Conflict fcport needs to finish 795 * cleanup before this fcport can proceed to login. 796 */ 797 conflict_fcport->conflict = fcport; 798 fcport->login_pause = 1; 799 } 800 801 switch (vha->hw->current_topology) { 802 default: 803 switch (current_login_state) { 804 case DSC_LS_PRLI_COMP: 805 ql_dbg(ql_dbg_disc, 806 vha, 0x20e4, "%s %d %8phC post gpdb\n", 807 __func__, __LINE__, fcport->port_name); 808 809 if ((e->prli_svc_param_word_3[0] & BIT_4) == 0) 810 fcport->port_type = FCT_INITIATOR; 811 else 812 fcport->port_type = FCT_TARGET; 813 data[0] = data[1] = 0; 814 qla2x00_post_async_adisc_work(vha, fcport, 815 data); 816 break; 817 case DSC_LS_PLOGI_COMP: 818 if (vha->hw->flags.edif_enabled) { 819 /* check to see if App support Secure */ 820 qla24xx_post_gpdb_work(vha, fcport, 0); 821 break; 822 } 823 fallthrough; 824 case DSC_LS_PORT_UNAVAIL: 825 default: 826 if (fcport->loop_id == FC_NO_LOOP_ID) { 827 qla2x00_find_new_loop_id(vha, fcport); 828 fcport->fw_login_state = 829 DSC_LS_PORT_UNAVAIL; 830 } 831 ql_dbg(ql_dbg_disc, vha, 0x20e5, 832 "%s %d %8phC\n", __func__, __LINE__, 833 fcport->port_name); 834 qla24xx_fcport_handle_login(vha, fcport); 835 break; 836 } 837 break; 838 case ISP_CFG_N: 839 fcport->fw_login_state = current_login_state; 840 fcport->d_id = id; 841 switch (current_login_state) { 842 case DSC_LS_PRLI_PEND: 843 /* 844 * In the middle of PRLI. Let it finish. 845 * Allow relogin code to recheck state again 846 * with GNL. Push disc_state back to DELETED 847 * so GNL can go out again 848 */ 849 qla2x00_set_fcport_disc_state(fcport, 850 DSC_DELETED); 851 set_bit(RELOGIN_NEEDED, &vha->dpc_flags); 852 break; 853 case DSC_LS_PRLI_COMP: 854 if ((e->prli_svc_param_word_3[0] & BIT_4) == 0) 855 fcport->port_type = FCT_INITIATOR; 856 else 857 fcport->port_type = FCT_TARGET; 858 859 data[0] = data[1] = 0; 860 qla2x00_post_async_adisc_work(vha, fcport, 861 data); 862 break; 863 case DSC_LS_PLOGI_COMP: 864 if (vha->hw->flags.edif_enabled && 865 vha->e_dbell.db_flags & EDB_ACTIVE) { 866 /* check to see if App support secure or not */ 867 qla24xx_post_gpdb_work(vha, fcport, 0); 868 break; 869 } 870 if (fcport_is_bigger(fcport)) { 871 /* local adapter is smaller */ 872 if (fcport->loop_id != FC_NO_LOOP_ID) 873 qla2x00_clear_loop_id(fcport); 874 875 fcport->loop_id = loop_id; 876 qla24xx_fcport_handle_login(vha, 877 fcport); 878 break; 879 } 880 fallthrough; 881 default: 882 if (fcport_is_smaller(fcport)) { 883 /* local adapter is bigger */ 884 if (fcport->loop_id != FC_NO_LOOP_ID) 885 qla2x00_clear_loop_id(fcport); 886 887 fcport->loop_id = loop_id; 888 qla24xx_fcport_handle_login(vha, 889 fcport); 890 } 891 break; 892 } 893 break; 894 } /* switch (ha->current_topology) */ 895 } 896 897 if (!found) { 898 switch (vha->hw->current_topology) { 899 case ISP_CFG_F: 900 case ISP_CFG_FL: 901 for (i = 0; i < n; i++) { 902 e = &vha->gnl.l[i]; 903 id.b.domain = e->port_id[0]; 904 id.b.area = e->port_id[1]; 905 id.b.al_pa = e->port_id[2]; 906 id.b.rsvd_1 = 0; 907 loop_id = le16_to_cpu(e->nport_handle); 908 909 if (fcport->d_id.b24 == id.b24) { 910 conflict_fcport = 911 qla2x00_find_fcport_by_wwpn(vha, 912 e->port_name, 0); 913 if (conflict_fcport) { 914 ql_dbg(ql_dbg_disc + ql_dbg_verbose, 915 vha, 0x20e5, 916 "%s %d %8phC post del sess\n", 917 __func__, __LINE__, 918 conflict_fcport->port_name); 919 qlt_schedule_sess_for_deletion 920 (conflict_fcport); 921 } 922 } 923 /* 924 * FW already picked this loop id for 925 * another fcport 926 */ 927 if (fcport->loop_id == loop_id) 928 fcport->loop_id = FC_NO_LOOP_ID; 929 } 930 qla24xx_fcport_handle_login(vha, fcport); 931 break; 932 case ISP_CFG_N: 933 qla2x00_set_fcport_disc_state(fcport, DSC_DELETED); 934 if (time_after_eq(jiffies, fcport->dm_login_expire)) { 935 if (fcport->n2n_link_reset_cnt < 2) { 936 fcport->n2n_link_reset_cnt++; 937 /* 938 * remote port is not sending PLOGI. 939 * Reset link to kick start his state 940 * machine 941 */ 942 set_bit(N2N_LINK_RESET, 943 &vha->dpc_flags); 944 } else { 945 if (fcport->n2n_chip_reset < 1) { 946 ql_log(ql_log_info, vha, 0x705d, 947 "Chip reset to bring laser down"); 948 set_bit(ISP_ABORT_NEEDED, 949 &vha->dpc_flags); 950 fcport->n2n_chip_reset++; 951 } else { 952 ql_log(ql_log_info, vha, 0x705d, 953 "Remote port %8ph is not coming back\n", 954 fcport->port_name); 955 fcport->scan_state = 0; 956 } 957 } 958 qla2xxx_wake_dpc(vha); 959 } else { 960 /* 961 * report port suppose to do PLOGI. Give him 962 * more time. FW will catch it. 963 */ 964 set_bit(RELOGIN_NEEDED, &vha->dpc_flags); 965 } 966 break; 967 default: 968 break; 969 } 970 } 971 } /* gnl_event */ 972 973 static void qla24xx_async_gnl_sp_done(srb_t *sp, int res) 974 { 975 struct scsi_qla_host *vha = sp->vha; 976 unsigned long flags; 977 struct fc_port *fcport = NULL, *tf; 978 u16 i, n = 0, loop_id; 979 struct event_arg ea; 980 struct get_name_list_extended *e; 981 u64 wwn; 982 struct list_head h; 983 bool found = false; 984 985 ql_dbg(ql_dbg_disc, vha, 0x20e7, 986 "Async done-%s res %x mb[1]=%x mb[2]=%x \n", 987 sp->name, res, sp->u.iocb_cmd.u.mbx.in_mb[1], 988 sp->u.iocb_cmd.u.mbx.in_mb[2]); 989 990 if (res == QLA_FUNCTION_TIMEOUT) 991 return; 992 993 sp->fcport->flags &= ~(FCF_ASYNC_SENT|FCF_ASYNC_ACTIVE); 994 memset(&ea, 0, sizeof(ea)); 995 ea.sp = sp; 996 ea.rc = res; 997 998 if (sp->u.iocb_cmd.u.mbx.in_mb[1] >= 999 sizeof(struct get_name_list_extended)) { 1000 n = sp->u.iocb_cmd.u.mbx.in_mb[1] / 1001 sizeof(struct get_name_list_extended); 1002 ea.data[0] = sp->u.iocb_cmd.u.mbx.in_mb[1]; /* amnt xfered */ 1003 } 1004 1005 for (i = 0; i < n; i++) { 1006 e = &vha->gnl.l[i]; 1007 loop_id = le16_to_cpu(e->nport_handle); 1008 /* mask out reserve bit */ 1009 loop_id = (loop_id & 0x7fff); 1010 set_bit(loop_id, vha->hw->loop_id_map); 1011 wwn = wwn_to_u64(e->port_name); 1012 1013 ql_dbg(ql_dbg_disc, vha, 0x20e8, 1014 "%s %8phC %02x:%02x:%02x CLS %x/%x lid %x \n", 1015 __func__, &wwn, e->port_id[2], e->port_id[1], 1016 e->port_id[0], e->current_login_state, e->last_login_state, 1017 (loop_id & 0x7fff)); 1018 } 1019 1020 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); 1021 1022 INIT_LIST_HEAD(&h); 1023 fcport = tf = NULL; 1024 if (!list_empty(&vha->gnl.fcports)) 1025 list_splice_init(&vha->gnl.fcports, &h); 1026 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); 1027 1028 list_for_each_entry_safe(fcport, tf, &h, gnl_entry) { 1029 list_del_init(&fcport->gnl_entry); 1030 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); 1031 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE); 1032 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); 1033 ea.fcport = fcport; 1034 1035 qla24xx_handle_gnl_done_event(vha, &ea); 1036 } 1037 1038 /* create new fcport if fw has knowledge of new sessions */ 1039 for (i = 0; i < n; i++) { 1040 port_id_t id; 1041 u64 wwnn; 1042 1043 e = &vha->gnl.l[i]; 1044 wwn = wwn_to_u64(e->port_name); 1045 1046 found = false; 1047 list_for_each_entry_safe(fcport, tf, &vha->vp_fcports, list) { 1048 if (!memcmp((u8 *)&wwn, fcport->port_name, 1049 WWN_SIZE)) { 1050 found = true; 1051 break; 1052 } 1053 } 1054 1055 id.b.domain = e->port_id[2]; 1056 id.b.area = e->port_id[1]; 1057 id.b.al_pa = e->port_id[0]; 1058 id.b.rsvd_1 = 0; 1059 1060 if (!found && wwn && !IS_SW_RESV_ADDR(id)) { 1061 ql_dbg(ql_dbg_disc, vha, 0x2065, 1062 "%s %d %8phC %06x post new sess\n", 1063 __func__, __LINE__, (u8 *)&wwn, id.b24); 1064 wwnn = wwn_to_u64(e->node_name); 1065 qla24xx_post_newsess_work(vha, &id, (u8 *)&wwn, 1066 (u8 *)&wwnn, NULL, 0); 1067 } 1068 } 1069 1070 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); 1071 vha->gnl.sent = 0; 1072 if (!list_empty(&vha->gnl.fcports)) { 1073 /* retrigger gnl */ 1074 list_for_each_entry_safe(fcport, tf, &vha->gnl.fcports, 1075 gnl_entry) { 1076 list_del_init(&fcport->gnl_entry); 1077 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE); 1078 if (qla24xx_post_gnl_work(vha, fcport) == QLA_SUCCESS) 1079 break; 1080 } 1081 } 1082 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); 1083 1084 sp->free(sp); 1085 } 1086 1087 int qla24xx_async_gnl(struct scsi_qla_host *vha, fc_port_t *fcport) 1088 { 1089 srb_t *sp; 1090 struct srb_iocb *mbx; 1091 int rval = QLA_FUNCTION_FAILED; 1092 unsigned long flags; 1093 u16 *mb; 1094 1095 if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT)) 1096 return rval; 1097 1098 ql_dbg(ql_dbg_disc, vha, 0x20d9, 1099 "Async-gnlist WWPN %8phC \n", fcport->port_name); 1100 1101 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); 1102 fcport->flags |= FCF_ASYNC_SENT; 1103 qla2x00_set_fcport_disc_state(fcport, DSC_GNL); 1104 fcport->last_rscn_gen = fcport->rscn_gen; 1105 fcport->last_login_gen = fcport->login_gen; 1106 1107 list_add_tail(&fcport->gnl_entry, &vha->gnl.fcports); 1108 if (vha->gnl.sent) { 1109 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); 1110 return QLA_SUCCESS; 1111 } 1112 vha->gnl.sent = 1; 1113 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); 1114 1115 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); 1116 if (!sp) 1117 goto done; 1118 1119 sp->type = SRB_MB_IOCB; 1120 sp->name = "gnlist"; 1121 sp->gen1 = fcport->rscn_gen; 1122 sp->gen2 = fcport->login_gen; 1123 1124 mbx = &sp->u.iocb_cmd; 1125 mbx->timeout = qla2x00_async_iocb_timeout; 1126 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha)+2); 1127 1128 mb = sp->u.iocb_cmd.u.mbx.out_mb; 1129 mb[0] = MBC_PORT_NODE_NAME_LIST; 1130 mb[1] = BIT_2 | BIT_3; 1131 mb[2] = MSW(vha->gnl.ldma); 1132 mb[3] = LSW(vha->gnl.ldma); 1133 mb[6] = MSW(MSD(vha->gnl.ldma)); 1134 mb[7] = LSW(MSD(vha->gnl.ldma)); 1135 mb[8] = vha->gnl.size; 1136 mb[9] = vha->vp_idx; 1137 1138 sp->done = qla24xx_async_gnl_sp_done; 1139 1140 ql_dbg(ql_dbg_disc, vha, 0x20da, 1141 "Async-%s - OUT WWPN %8phC hndl %x\n", 1142 sp->name, fcport->port_name, sp->handle); 1143 1144 rval = qla2x00_start_sp(sp); 1145 if (rval != QLA_SUCCESS) 1146 goto done_free_sp; 1147 1148 return rval; 1149 1150 done_free_sp: 1151 sp->free(sp); 1152 done: 1153 fcport->flags &= ~(FCF_ASYNC_ACTIVE | FCF_ASYNC_SENT); 1154 return rval; 1155 } 1156 1157 int qla24xx_post_gnl_work(struct scsi_qla_host *vha, fc_port_t *fcport) 1158 { 1159 struct qla_work_evt *e; 1160 1161 e = qla2x00_alloc_work(vha, QLA_EVT_GNL); 1162 if (!e) 1163 return QLA_FUNCTION_FAILED; 1164 1165 e->u.fcport.fcport = fcport; 1166 fcport->flags |= FCF_ASYNC_ACTIVE; 1167 return qla2x00_post_work(vha, e); 1168 } 1169 1170 static void qla24xx_async_gpdb_sp_done(srb_t *sp, int res) 1171 { 1172 struct scsi_qla_host *vha = sp->vha; 1173 struct qla_hw_data *ha = vha->hw; 1174 fc_port_t *fcport = sp->fcport; 1175 u16 *mb = sp->u.iocb_cmd.u.mbx.in_mb; 1176 struct event_arg ea; 1177 1178 ql_dbg(ql_dbg_disc, vha, 0x20db, 1179 "Async done-%s res %x, WWPN %8phC mb[1]=%x mb[2]=%x \n", 1180 sp->name, res, fcport->port_name, mb[1], mb[2]); 1181 1182 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE); 1183 1184 if (res == QLA_FUNCTION_TIMEOUT) 1185 goto done; 1186 1187 memset(&ea, 0, sizeof(ea)); 1188 ea.fcport = fcport; 1189 ea.sp = sp; 1190 1191 qla24xx_handle_gpdb_event(vha, &ea); 1192 1193 done: 1194 dma_pool_free(ha->s_dma_pool, sp->u.iocb_cmd.u.mbx.in, 1195 sp->u.iocb_cmd.u.mbx.in_dma); 1196 1197 sp->free(sp); 1198 } 1199 1200 int qla24xx_post_prli_work(struct scsi_qla_host *vha, fc_port_t *fcport) 1201 { 1202 struct qla_work_evt *e; 1203 1204 if (vha->host->active_mode == MODE_TARGET) 1205 return QLA_FUNCTION_FAILED; 1206 1207 e = qla2x00_alloc_work(vha, QLA_EVT_PRLI); 1208 if (!e) 1209 return QLA_FUNCTION_FAILED; 1210 1211 e->u.fcport.fcport = fcport; 1212 1213 return qla2x00_post_work(vha, e); 1214 } 1215 1216 static void qla2x00_async_prli_sp_done(srb_t *sp, int res) 1217 { 1218 struct scsi_qla_host *vha = sp->vha; 1219 struct srb_iocb *lio = &sp->u.iocb_cmd; 1220 struct event_arg ea; 1221 1222 ql_dbg(ql_dbg_disc, vha, 0x2129, 1223 "%s %8phC res %x\n", __func__, 1224 sp->fcport->port_name, res); 1225 1226 sp->fcport->flags &= ~FCF_ASYNC_SENT; 1227 1228 if (!test_bit(UNLOADING, &vha->dpc_flags)) { 1229 memset(&ea, 0, sizeof(ea)); 1230 ea.fcport = sp->fcport; 1231 ea.data[0] = lio->u.logio.data[0]; 1232 ea.data[1] = lio->u.logio.data[1]; 1233 ea.iop[0] = lio->u.logio.iop[0]; 1234 ea.iop[1] = lio->u.logio.iop[1]; 1235 ea.sp = sp; 1236 if (res == QLA_OS_TIMER_EXPIRED) 1237 ea.data[0] = QLA_OS_TIMER_EXPIRED; 1238 1239 qla24xx_handle_prli_done_event(vha, &ea); 1240 } 1241 1242 sp->free(sp); 1243 } 1244 1245 int 1246 qla24xx_async_prli(struct scsi_qla_host *vha, fc_port_t *fcport) 1247 { 1248 srb_t *sp; 1249 struct srb_iocb *lio; 1250 int rval = QLA_FUNCTION_FAILED; 1251 1252 if (!vha->flags.online) { 1253 ql_dbg(ql_dbg_disc, vha, 0xffff, "%s %d %8phC exit\n", 1254 __func__, __LINE__, fcport->port_name); 1255 return rval; 1256 } 1257 1258 if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND || 1259 fcport->fw_login_state == DSC_LS_PRLI_PEND) && 1260 qla_dual_mode_enabled(vha)) { 1261 ql_dbg(ql_dbg_disc, vha, 0xffff, "%s %d %8phC exit\n", 1262 __func__, __LINE__, fcport->port_name); 1263 return rval; 1264 } 1265 1266 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); 1267 if (!sp) 1268 return rval; 1269 1270 fcport->flags |= FCF_ASYNC_SENT; 1271 fcport->logout_completed = 0; 1272 1273 sp->type = SRB_PRLI_CMD; 1274 sp->name = "prli"; 1275 1276 lio = &sp->u.iocb_cmd; 1277 lio->timeout = qla2x00_async_iocb_timeout; 1278 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2); 1279 1280 sp->done = qla2x00_async_prli_sp_done; 1281 lio->u.logio.flags = 0; 1282 1283 if (NVME_TARGET(vha->hw, fcport)) 1284 lio->u.logio.flags |= SRB_LOGIN_NVME_PRLI; 1285 1286 ql_dbg(ql_dbg_disc, vha, 0x211b, 1287 "Async-prli - %8phC hdl=%x, loopid=%x portid=%06x retries=%d fc4type %x priority %x %s.\n", 1288 fcport->port_name, sp->handle, fcport->loop_id, fcport->d_id.b24, 1289 fcport->login_retry, fcport->fc4_type, vha->hw->fc4_type_priority, 1290 NVME_TARGET(vha->hw, fcport) ? "nvme" : "fcp"); 1291 1292 rval = qla2x00_start_sp(sp); 1293 if (rval != QLA_SUCCESS) { 1294 fcport->flags |= FCF_LOGIN_NEEDED; 1295 set_bit(RELOGIN_NEEDED, &vha->dpc_flags); 1296 goto done_free_sp; 1297 } 1298 1299 return rval; 1300 1301 done_free_sp: 1302 sp->free(sp); 1303 fcport->flags &= ~FCF_ASYNC_SENT; 1304 return rval; 1305 } 1306 1307 int qla24xx_post_gpdb_work(struct scsi_qla_host *vha, fc_port_t *fcport, u8 opt) 1308 { 1309 struct qla_work_evt *e; 1310 1311 e = qla2x00_alloc_work(vha, QLA_EVT_GPDB); 1312 if (!e) 1313 return QLA_FUNCTION_FAILED; 1314 1315 e->u.fcport.fcport = fcport; 1316 e->u.fcport.opt = opt; 1317 fcport->flags |= FCF_ASYNC_ACTIVE; 1318 return qla2x00_post_work(vha, e); 1319 } 1320 1321 int qla24xx_async_gpdb(struct scsi_qla_host *vha, fc_port_t *fcport, u8 opt) 1322 { 1323 srb_t *sp; 1324 struct srb_iocb *mbx; 1325 int rval = QLA_FUNCTION_FAILED; 1326 u16 *mb; 1327 dma_addr_t pd_dma; 1328 struct port_database_24xx *pd; 1329 struct qla_hw_data *ha = vha->hw; 1330 1331 if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT) || 1332 fcport->loop_id == FC_NO_LOOP_ID) { 1333 ql_log(ql_log_warn, vha, 0xffff, 1334 "%s: %8phC - not sending command.\n", 1335 __func__, fcport->port_name); 1336 return rval; 1337 } 1338 1339 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); 1340 if (!sp) 1341 goto done; 1342 1343 qla2x00_set_fcport_disc_state(fcport, DSC_GPDB); 1344 1345 fcport->flags |= FCF_ASYNC_SENT; 1346 sp->type = SRB_MB_IOCB; 1347 sp->name = "gpdb"; 1348 sp->gen1 = fcport->rscn_gen; 1349 sp->gen2 = fcport->login_gen; 1350 1351 mbx = &sp->u.iocb_cmd; 1352 mbx->timeout = qla2x00_async_iocb_timeout; 1353 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2); 1354 1355 pd = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma); 1356 if (pd == NULL) { 1357 ql_log(ql_log_warn, vha, 0xd043, 1358 "Failed to allocate port database structure.\n"); 1359 goto done_free_sp; 1360 } 1361 1362 mb = sp->u.iocb_cmd.u.mbx.out_mb; 1363 mb[0] = MBC_GET_PORT_DATABASE; 1364 mb[1] = fcport->loop_id; 1365 mb[2] = MSW(pd_dma); 1366 mb[3] = LSW(pd_dma); 1367 mb[6] = MSW(MSD(pd_dma)); 1368 mb[7] = LSW(MSD(pd_dma)); 1369 mb[9] = vha->vp_idx; 1370 mb[10] = opt; 1371 1372 mbx->u.mbx.in = pd; 1373 mbx->u.mbx.in_dma = pd_dma; 1374 1375 sp->done = qla24xx_async_gpdb_sp_done; 1376 1377 ql_dbg(ql_dbg_disc, vha, 0x20dc, 1378 "Async-%s %8phC hndl %x opt %x\n", 1379 sp->name, fcport->port_name, sp->handle, opt); 1380 1381 rval = qla2x00_start_sp(sp); 1382 if (rval != QLA_SUCCESS) 1383 goto done_free_sp; 1384 return rval; 1385 1386 done_free_sp: 1387 if (pd) 1388 dma_pool_free(ha->s_dma_pool, pd, pd_dma); 1389 1390 sp->free(sp); 1391 fcport->flags &= ~FCF_ASYNC_SENT; 1392 done: 1393 fcport->flags &= ~FCF_ASYNC_ACTIVE; 1394 qla24xx_post_gpdb_work(vha, fcport, opt); 1395 return rval; 1396 } 1397 1398 static 1399 void __qla24xx_handle_gpdb_event(scsi_qla_host_t *vha, struct event_arg *ea) 1400 { 1401 unsigned long flags; 1402 1403 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); 1404 ea->fcport->login_gen++; 1405 ea->fcport->deleted = 0; 1406 ea->fcport->logout_on_delete = 1; 1407 1408 if (!ea->fcport->login_succ && !IS_SW_RESV_ADDR(ea->fcport->d_id)) { 1409 vha->fcport_count++; 1410 ea->fcport->login_succ = 1; 1411 1412 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); 1413 qla24xx_sched_upd_fcport(ea->fcport); 1414 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); 1415 } else if (ea->fcport->login_succ) { 1416 /* 1417 * We have an existing session. A late RSCN delivery 1418 * must have triggered the session to be re-validate. 1419 * Session is still valid. 1420 */ 1421 ql_dbg(ql_dbg_disc, vha, 0x20d6, 1422 "%s %d %8phC session revalidate success\n", 1423 __func__, __LINE__, ea->fcport->port_name); 1424 qla2x00_set_fcport_disc_state(ea->fcport, DSC_LOGIN_COMPLETE); 1425 } 1426 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); 1427 } 1428 1429 static int qla_chk_secure_login(scsi_qla_host_t *vha, fc_port_t *fcport, 1430 struct port_database_24xx *pd) 1431 { 1432 int rc = 0; 1433 1434 if (pd->secure_login) { 1435 ql_dbg(ql_dbg_disc, vha, 0x104d, 1436 "Secure Login established on %8phC\n", 1437 fcport->port_name); 1438 fcport->flags |= FCF_FCSP_DEVICE; 1439 } else { 1440 ql_dbg(ql_dbg_disc, vha, 0x104d, 1441 "non-Secure Login %8phC", 1442 fcport->port_name); 1443 fcport->flags &= ~FCF_FCSP_DEVICE; 1444 } 1445 if (vha->hw->flags.edif_enabled) { 1446 if (fcport->flags & FCF_FCSP_DEVICE) { 1447 qla2x00_set_fcport_disc_state(fcport, DSC_LOGIN_AUTH_PEND); 1448 /* Start edif prli timer & ring doorbell for app */ 1449 fcport->edif.rx_sa_set = 0; 1450 fcport->edif.tx_sa_set = 0; 1451 fcport->edif.rx_sa_pending = 0; 1452 fcport->edif.tx_sa_pending = 0; 1453 1454 qla2x00_post_aen_work(vha, FCH_EVT_PORT_ONLINE, 1455 fcport->d_id.b24); 1456 1457 if (vha->e_dbell.db_flags == EDB_ACTIVE) { 1458 ql_dbg(ql_dbg_disc, vha, 0x20ef, 1459 "%s %d %8phC EDIF: post DB_AUTH: AUTH needed\n", 1460 __func__, __LINE__, fcport->port_name); 1461 fcport->edif.app_started = 1; 1462 fcport->edif.app_sess_online = 1; 1463 1464 qla_edb_eventcreate(vha, VND_CMD_AUTH_STATE_NEEDED, 1465 fcport->d_id.b24, 0, fcport); 1466 } 1467 1468 rc = 1; 1469 } else if (qla_ini_mode_enabled(vha) || qla_dual_mode_enabled(vha)) { 1470 ql_dbg(ql_dbg_disc, vha, 0x2117, 1471 "%s %d %8phC post prli\n", 1472 __func__, __LINE__, fcport->port_name); 1473 qla24xx_post_prli_work(vha, fcport); 1474 rc = 1; 1475 } 1476 } 1477 return rc; 1478 } 1479 1480 static 1481 void qla24xx_handle_gpdb_event(scsi_qla_host_t *vha, struct event_arg *ea) 1482 { 1483 fc_port_t *fcport = ea->fcport; 1484 struct port_database_24xx *pd; 1485 struct srb *sp = ea->sp; 1486 uint8_t ls; 1487 1488 pd = (struct port_database_24xx *)sp->u.iocb_cmd.u.mbx.in; 1489 1490 fcport->flags &= ~FCF_ASYNC_SENT; 1491 1492 ql_dbg(ql_dbg_disc, vha, 0x20d2, 1493 "%s %8phC DS %d LS %x fc4_type %x rc %x\n", __func__, 1494 fcport->port_name, fcport->disc_state, pd->current_login_state, 1495 fcport->fc4_type, ea->rc); 1496 1497 if (fcport->disc_state == DSC_DELETE_PEND) { 1498 ql_dbg(ql_dbg_disc, vha, 0x20d5, "%s %d %8phC\n", 1499 __func__, __LINE__, fcport->port_name); 1500 return; 1501 } 1502 1503 if (NVME_TARGET(vha->hw, fcport)) 1504 ls = pd->current_login_state >> 4; 1505 else 1506 ls = pd->current_login_state & 0xf; 1507 1508 if (ea->sp->gen2 != fcport->login_gen) { 1509 /* target side must have changed it. */ 1510 1511 ql_dbg(ql_dbg_disc, vha, 0x20d3, 1512 "%s %8phC generation changed\n", 1513 __func__, fcport->port_name); 1514 return; 1515 } else if (ea->sp->gen1 != fcport->rscn_gen) { 1516 qla_rscn_replay(fcport); 1517 qlt_schedule_sess_for_deletion(fcport); 1518 ql_dbg(ql_dbg_disc, vha, 0x20d5, "%s %d %8phC, ls %x\n", 1519 __func__, __LINE__, fcport->port_name, ls); 1520 return; 1521 } 1522 1523 switch (ls) { 1524 case PDS_PRLI_COMPLETE: 1525 __qla24xx_parse_gpdb(vha, fcport, pd); 1526 break; 1527 case PDS_PLOGI_COMPLETE: 1528 if (qla_chk_secure_login(vha, fcport, pd)) { 1529 ql_dbg(ql_dbg_disc, vha, 0x20d5, "%s %d %8phC, ls %x\n", 1530 __func__, __LINE__, fcport->port_name, ls); 1531 return; 1532 } 1533 fallthrough; 1534 case PDS_PLOGI_PENDING: 1535 case PDS_PRLI_PENDING: 1536 case PDS_PRLI2_PENDING: 1537 /* Set discovery state back to GNL to Relogin attempt */ 1538 if (qla_dual_mode_enabled(vha) || 1539 qla_ini_mode_enabled(vha)) { 1540 qla2x00_set_fcport_disc_state(fcport, DSC_GNL); 1541 set_bit(RELOGIN_NEEDED, &vha->dpc_flags); 1542 } 1543 ql_dbg(ql_dbg_disc, vha, 0x20d5, "%s %d %8phC, ls %x\n", 1544 __func__, __LINE__, fcport->port_name, ls); 1545 return; 1546 case PDS_LOGO_PENDING: 1547 case PDS_PORT_UNAVAILABLE: 1548 default: 1549 ql_dbg(ql_dbg_disc, vha, 0x20d5, "%s %d %8phC post del sess\n", 1550 __func__, __LINE__, fcport->port_name); 1551 qlt_schedule_sess_for_deletion(fcport); 1552 return; 1553 } 1554 __qla24xx_handle_gpdb_event(vha, ea); 1555 } /* gpdb event */ 1556 1557 static void qla_chk_n2n_b4_login(struct scsi_qla_host *vha, fc_port_t *fcport) 1558 { 1559 u8 login = 0; 1560 int rc; 1561 1562 if (qla_tgt_mode_enabled(vha)) 1563 return; 1564 1565 if (qla_dual_mode_enabled(vha)) { 1566 if (N2N_TOPO(vha->hw)) { 1567 u64 mywwn, wwn; 1568 1569 mywwn = wwn_to_u64(vha->port_name); 1570 wwn = wwn_to_u64(fcport->port_name); 1571 if (mywwn > wwn) 1572 login = 1; 1573 else if ((fcport->fw_login_state == DSC_LS_PLOGI_COMP) 1574 && time_after_eq(jiffies, 1575 fcport->plogi_nack_done_deadline)) 1576 login = 1; 1577 } else { 1578 login = 1; 1579 } 1580 } else { 1581 /* initiator mode */ 1582 login = 1; 1583 } 1584 1585 if (login && fcport->login_retry) { 1586 fcport->login_retry--; 1587 if (fcport->loop_id == FC_NO_LOOP_ID) { 1588 fcport->fw_login_state = DSC_LS_PORT_UNAVAIL; 1589 rc = qla2x00_find_new_loop_id(vha, fcport); 1590 if (rc) { 1591 ql_dbg(ql_dbg_disc, vha, 0x20e6, 1592 "%s %d %8phC post del sess - out of loopid\n", 1593 __func__, __LINE__, fcport->port_name); 1594 fcport->scan_state = 0; 1595 qlt_schedule_sess_for_deletion(fcport); 1596 return; 1597 } 1598 } 1599 ql_dbg(ql_dbg_disc, vha, 0x20bf, 1600 "%s %d %8phC post login\n", 1601 __func__, __LINE__, fcport->port_name); 1602 qla2x00_post_async_login_work(vha, fcport, NULL); 1603 } 1604 } 1605 1606 int qla24xx_fcport_handle_login(struct scsi_qla_host *vha, fc_port_t *fcport) 1607 { 1608 u16 data[2]; 1609 u64 wwn; 1610 u16 sec; 1611 1612 ql_dbg(ql_dbg_disc, vha, 0x20d8, 1613 "%s %8phC DS %d LS %d P %d fl %x confl %p rscn %d|%d login %d lid %d scan %d fc4type %x\n", 1614 __func__, fcport->port_name, fcport->disc_state, 1615 fcport->fw_login_state, fcport->login_pause, fcport->flags, 1616 fcport->conflict, fcport->last_rscn_gen, fcport->rscn_gen, 1617 fcport->login_gen, fcport->loop_id, fcport->scan_state, 1618 fcport->fc4_type); 1619 1620 if (fcport->scan_state != QLA_FCPORT_FOUND) 1621 return 0; 1622 1623 if ((fcport->loop_id != FC_NO_LOOP_ID) && 1624 qla_dual_mode_enabled(vha) && 1625 ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) || 1626 (fcport->fw_login_state == DSC_LS_PRLI_PEND))) 1627 return 0; 1628 1629 if (fcport->fw_login_state == DSC_LS_PLOGI_COMP && 1630 !N2N_TOPO(vha->hw)) { 1631 if (time_before_eq(jiffies, fcport->plogi_nack_done_deadline)) { 1632 set_bit(RELOGIN_NEEDED, &vha->dpc_flags); 1633 return 0; 1634 } 1635 } 1636 1637 /* Target won't initiate port login if fabric is present */ 1638 if (vha->host->active_mode == MODE_TARGET && !N2N_TOPO(vha->hw)) 1639 return 0; 1640 1641 if (fcport->flags & FCF_ASYNC_SENT) { 1642 set_bit(RELOGIN_NEEDED, &vha->dpc_flags); 1643 return 0; 1644 } 1645 1646 switch (fcport->disc_state) { 1647 case DSC_DELETED: 1648 wwn = wwn_to_u64(fcport->node_name); 1649 switch (vha->hw->current_topology) { 1650 case ISP_CFG_N: 1651 if (fcport_is_smaller(fcport)) { 1652 /* this adapter is bigger */ 1653 if (fcport->login_retry) { 1654 if (fcport->loop_id == FC_NO_LOOP_ID) { 1655 qla2x00_find_new_loop_id(vha, 1656 fcport); 1657 fcport->fw_login_state = 1658 DSC_LS_PORT_UNAVAIL; 1659 } 1660 fcport->login_retry--; 1661 qla_post_els_plogi_work(vha, fcport); 1662 } else { 1663 ql_log(ql_log_info, vha, 0x705d, 1664 "Unable to reach remote port %8phC", 1665 fcport->port_name); 1666 } 1667 } else { 1668 qla24xx_post_gnl_work(vha, fcport); 1669 } 1670 break; 1671 default: 1672 if (wwn == 0) { 1673 ql_dbg(ql_dbg_disc, vha, 0xffff, 1674 "%s %d %8phC post GNNID\n", 1675 __func__, __LINE__, fcport->port_name); 1676 qla24xx_post_gnnid_work(vha, fcport); 1677 } else if (fcport->loop_id == FC_NO_LOOP_ID) { 1678 ql_dbg(ql_dbg_disc, vha, 0x20bd, 1679 "%s %d %8phC post gnl\n", 1680 __func__, __LINE__, fcport->port_name); 1681 qla24xx_post_gnl_work(vha, fcport); 1682 } else { 1683 qla_chk_n2n_b4_login(vha, fcport); 1684 } 1685 break; 1686 } 1687 break; 1688 1689 case DSC_GNL: 1690 switch (vha->hw->current_topology) { 1691 case ISP_CFG_N: 1692 if ((fcport->current_login_state & 0xf) == 0x6) { 1693 ql_dbg(ql_dbg_disc, vha, 0x2118, 1694 "%s %d %8phC post GPDB work\n", 1695 __func__, __LINE__, fcport->port_name); 1696 fcport->chip_reset = 1697 vha->hw->base_qpair->chip_reset; 1698 qla24xx_post_gpdb_work(vha, fcport, 0); 1699 } else { 1700 ql_dbg(ql_dbg_disc, vha, 0x2118, 1701 "%s %d %8phC post %s PRLI\n", 1702 __func__, __LINE__, fcport->port_name, 1703 NVME_TARGET(vha->hw, fcport) ? "NVME" : 1704 "FC"); 1705 qla24xx_post_prli_work(vha, fcport); 1706 } 1707 break; 1708 default: 1709 if (fcport->login_pause) { 1710 ql_dbg(ql_dbg_disc, vha, 0x20d8, 1711 "%s %d %8phC exit\n", 1712 __func__, __LINE__, 1713 fcport->port_name); 1714 fcport->last_rscn_gen = fcport->rscn_gen; 1715 fcport->last_login_gen = fcport->login_gen; 1716 set_bit(RELOGIN_NEEDED, &vha->dpc_flags); 1717 break; 1718 } 1719 qla_chk_n2n_b4_login(vha, fcport); 1720 break; 1721 } 1722 break; 1723 1724 case DSC_LOGIN_FAILED: 1725 if (N2N_TOPO(vha->hw)) 1726 qla_chk_n2n_b4_login(vha, fcport); 1727 else 1728 qlt_schedule_sess_for_deletion(fcport); 1729 break; 1730 1731 case DSC_LOGIN_COMPLETE: 1732 /* recheck login state */ 1733 data[0] = data[1] = 0; 1734 qla2x00_post_async_adisc_work(vha, fcport, data); 1735 break; 1736 1737 case DSC_LOGIN_PEND: 1738 if (fcport->fw_login_state == DSC_LS_PLOGI_COMP) 1739 qla24xx_post_prli_work(vha, fcport); 1740 break; 1741 1742 case DSC_UPD_FCPORT: 1743 sec = jiffies_to_msecs(jiffies - 1744 fcport->jiffies_at_registration)/1000; 1745 if (fcport->sec_since_registration < sec && sec && 1746 !(sec % 60)) { 1747 fcport->sec_since_registration = sec; 1748 ql_dbg(ql_dbg_disc, fcport->vha, 0xffff, 1749 "%s %8phC - Slow Rport registration(%d Sec)\n", 1750 __func__, fcport->port_name, sec); 1751 } 1752 1753 if (fcport->next_disc_state != DSC_DELETE_PEND) 1754 fcport->next_disc_state = DSC_ADISC; 1755 set_bit(RELOGIN_NEEDED, &vha->dpc_flags); 1756 break; 1757 1758 default: 1759 break; 1760 } 1761 1762 return 0; 1763 } 1764 1765 int qla24xx_post_newsess_work(struct scsi_qla_host *vha, port_id_t *id, 1766 u8 *port_name, u8 *node_name, void *pla, u8 fc4_type) 1767 { 1768 struct qla_work_evt *e; 1769 1770 e = qla2x00_alloc_work(vha, QLA_EVT_NEW_SESS); 1771 if (!e) 1772 return QLA_FUNCTION_FAILED; 1773 1774 e->u.new_sess.id = *id; 1775 e->u.new_sess.pla = pla; 1776 e->u.new_sess.fc4_type = fc4_type; 1777 memcpy(e->u.new_sess.port_name, port_name, WWN_SIZE); 1778 if (node_name) 1779 memcpy(e->u.new_sess.node_name, node_name, WWN_SIZE); 1780 1781 return qla2x00_post_work(vha, e); 1782 } 1783 1784 void qla2x00_handle_rscn(scsi_qla_host_t *vha, struct event_arg *ea) 1785 { 1786 fc_port_t *fcport; 1787 unsigned long flags; 1788 1789 fcport = qla2x00_find_fcport_by_nportid(vha, &ea->id, 1); 1790 if (fcport) { 1791 if (fcport->flags & FCF_FCP2_DEVICE) { 1792 ql_dbg(ql_dbg_disc, vha, 0x2115, 1793 "Delaying session delete for FCP2 portid=%06x %8phC ", 1794 fcport->d_id.b24, fcport->port_name); 1795 return; 1796 } 1797 fcport->scan_needed = 1; 1798 fcport->rscn_gen++; 1799 } 1800 1801 spin_lock_irqsave(&vha->work_lock, flags); 1802 if (vha->scan.scan_flags == 0) { 1803 ql_dbg(ql_dbg_disc, vha, 0xffff, "%s: schedule\n", __func__); 1804 vha->scan.scan_flags |= SF_QUEUED; 1805 schedule_delayed_work(&vha->scan.scan_work, 5); 1806 } 1807 spin_unlock_irqrestore(&vha->work_lock, flags); 1808 } 1809 1810 void qla24xx_handle_relogin_event(scsi_qla_host_t *vha, 1811 struct event_arg *ea) 1812 { 1813 fc_port_t *fcport = ea->fcport; 1814 1815 if (test_bit(UNLOADING, &vha->dpc_flags)) 1816 return; 1817 1818 ql_dbg(ql_dbg_disc, vha, 0x2102, 1819 "%s %8phC DS %d LS %d P %d del %d cnfl %p rscn %d|%d login %d|%d fl %x\n", 1820 __func__, fcport->port_name, fcport->disc_state, 1821 fcport->fw_login_state, fcport->login_pause, 1822 fcport->deleted, fcport->conflict, 1823 fcport->last_rscn_gen, fcport->rscn_gen, 1824 fcport->last_login_gen, fcport->login_gen, 1825 fcport->flags); 1826 1827 if (fcport->last_rscn_gen != fcport->rscn_gen) { 1828 ql_dbg(ql_dbg_disc, vha, 0x20e9, "%s %d %8phC post gnl\n", 1829 __func__, __LINE__, fcport->port_name); 1830 qla24xx_post_gnl_work(vha, fcport); 1831 return; 1832 } 1833 1834 qla24xx_fcport_handle_login(vha, fcport); 1835 } 1836 1837 void qla_handle_els_plogi_done(scsi_qla_host_t *vha, 1838 struct event_arg *ea) 1839 { 1840 if (N2N_TOPO(vha->hw) && fcport_is_smaller(ea->fcport) && 1841 vha->hw->flags.edif_enabled) { 1842 /* check to see if App support Secure */ 1843 qla24xx_post_gpdb_work(vha, ea->fcport, 0); 1844 return; 1845 } 1846 1847 /* for pure Target Mode, PRLI will not be initiated */ 1848 if (vha->host->active_mode == MODE_TARGET) 1849 return; 1850 1851 ql_dbg(ql_dbg_disc, vha, 0x2118, 1852 "%s %d %8phC post PRLI\n", 1853 __func__, __LINE__, ea->fcport->port_name); 1854 qla24xx_post_prli_work(vha, ea->fcport); 1855 } 1856 1857 /* 1858 * RSCN(s) came in for this fcport, but the RSCN(s) was not able 1859 * to be consumed by the fcport 1860 */ 1861 void qla_rscn_replay(fc_port_t *fcport) 1862 { 1863 struct event_arg ea; 1864 1865 switch (fcport->disc_state) { 1866 case DSC_DELETE_PEND: 1867 return; 1868 default: 1869 break; 1870 } 1871 1872 if (fcport->scan_needed) { 1873 memset(&ea, 0, sizeof(ea)); 1874 ea.id = fcport->d_id; 1875 ea.id.b.rsvd_1 = RSCN_PORT_ADDR; 1876 qla2x00_handle_rscn(fcport->vha, &ea); 1877 } 1878 } 1879 1880 static void 1881 qla2x00_tmf_iocb_timeout(void *data) 1882 { 1883 srb_t *sp = data; 1884 struct srb_iocb *tmf = &sp->u.iocb_cmd; 1885 int rc, h; 1886 unsigned long flags; 1887 1888 rc = qla24xx_async_abort_cmd(sp, false); 1889 if (rc) { 1890 spin_lock_irqsave(sp->qpair->qp_lock_ptr, flags); 1891 for (h = 1; h < sp->qpair->req->num_outstanding_cmds; h++) { 1892 if (sp->qpair->req->outstanding_cmds[h] == sp) { 1893 sp->qpair->req->outstanding_cmds[h] = NULL; 1894 break; 1895 } 1896 } 1897 spin_unlock_irqrestore(sp->qpair->qp_lock_ptr, flags); 1898 tmf->u.tmf.comp_status = cpu_to_le16(CS_TIMEOUT); 1899 tmf->u.tmf.data = QLA_FUNCTION_FAILED; 1900 complete(&tmf->u.tmf.comp); 1901 } 1902 } 1903 1904 static void qla2x00_tmf_sp_done(srb_t *sp, int res) 1905 { 1906 struct srb_iocb *tmf = &sp->u.iocb_cmd; 1907 1908 complete(&tmf->u.tmf.comp); 1909 } 1910 1911 int 1912 qla2x00_async_tm_cmd(fc_port_t *fcport, uint32_t flags, uint32_t lun, 1913 uint32_t tag) 1914 { 1915 struct scsi_qla_host *vha = fcport->vha; 1916 struct srb_iocb *tm_iocb; 1917 srb_t *sp; 1918 int rval = QLA_FUNCTION_FAILED; 1919 1920 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); 1921 if (!sp) 1922 goto done; 1923 1924 tm_iocb = &sp->u.iocb_cmd; 1925 sp->type = SRB_TM_CMD; 1926 sp->name = "tmf"; 1927 1928 tm_iocb->timeout = qla2x00_tmf_iocb_timeout; 1929 init_completion(&tm_iocb->u.tmf.comp); 1930 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha)); 1931 1932 tm_iocb->u.tmf.flags = flags; 1933 tm_iocb->u.tmf.lun = lun; 1934 tm_iocb->u.tmf.data = tag; 1935 sp->done = qla2x00_tmf_sp_done; 1936 1937 ql_dbg(ql_dbg_taskm, vha, 0x802f, 1938 "Async-tmf hdl=%x loop-id=%x portid=%02x%02x%02x.\n", 1939 sp->handle, fcport->loop_id, fcport->d_id.b.domain, 1940 fcport->d_id.b.area, fcport->d_id.b.al_pa); 1941 1942 rval = qla2x00_start_sp(sp); 1943 if (rval != QLA_SUCCESS) 1944 goto done_free_sp; 1945 wait_for_completion(&tm_iocb->u.tmf.comp); 1946 1947 rval = tm_iocb->u.tmf.data; 1948 1949 if (rval != QLA_SUCCESS) { 1950 ql_log(ql_log_warn, vha, 0x8030, 1951 "TM IOCB failed (%x).\n", rval); 1952 } 1953 1954 if (!test_bit(UNLOADING, &vha->dpc_flags) && !IS_QLAFX00(vha->hw)) { 1955 flags = tm_iocb->u.tmf.flags; 1956 lun = (uint16_t)tm_iocb->u.tmf.lun; 1957 1958 /* Issue Marker IOCB */ 1959 qla2x00_marker(vha, vha->hw->base_qpair, 1960 fcport->loop_id, lun, 1961 flags == TCF_LUN_RESET ? MK_SYNC_ID_LUN : MK_SYNC_ID); 1962 } 1963 1964 done_free_sp: 1965 sp->free(sp); 1966 fcport->flags &= ~FCF_ASYNC_SENT; 1967 done: 1968 return rval; 1969 } 1970 1971 int 1972 qla24xx_async_abort_command(srb_t *sp) 1973 { 1974 unsigned long flags = 0; 1975 1976 uint32_t handle; 1977 fc_port_t *fcport = sp->fcport; 1978 struct qla_qpair *qpair = sp->qpair; 1979 struct scsi_qla_host *vha = fcport->vha; 1980 struct req_que *req = qpair->req; 1981 1982 spin_lock_irqsave(qpair->qp_lock_ptr, flags); 1983 for (handle = 1; handle < req->num_outstanding_cmds; handle++) { 1984 if (req->outstanding_cmds[handle] == sp) 1985 break; 1986 } 1987 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); 1988 1989 if (handle == req->num_outstanding_cmds) { 1990 /* Command not found. */ 1991 return QLA_ERR_NOT_FOUND; 1992 } 1993 if (sp->type == SRB_FXIOCB_DCMD) 1994 return qlafx00_fx_disc(vha, &vha->hw->mr.fcport, 1995 FXDISC_ABORT_IOCTL); 1996 1997 return qla24xx_async_abort_cmd(sp, true); 1998 } 1999 2000 static void 2001 qla24xx_handle_prli_done_event(struct scsi_qla_host *vha, struct event_arg *ea) 2002 { 2003 struct srb *sp; 2004 WARN_ONCE(!qla2xxx_is_valid_mbs(ea->data[0]), "mbs: %#x\n", 2005 ea->data[0]); 2006 2007 switch (ea->data[0]) { 2008 case MBS_COMMAND_COMPLETE: 2009 ql_dbg(ql_dbg_disc, vha, 0x2118, 2010 "%s %d %8phC post gpdb\n", 2011 __func__, __LINE__, ea->fcport->port_name); 2012 2013 ea->fcport->chip_reset = vha->hw->base_qpair->chip_reset; 2014 ea->fcport->logout_on_delete = 1; 2015 ea->fcport->nvme_prli_service_param = ea->iop[0]; 2016 if (ea->iop[0] & NVME_PRLI_SP_FIRST_BURST) 2017 ea->fcport->nvme_first_burst_size = 2018 (ea->iop[1] & 0xffff) * 512; 2019 else 2020 ea->fcport->nvme_first_burst_size = 0; 2021 qla24xx_post_gpdb_work(vha, ea->fcport, 0); 2022 break; 2023 default: 2024 if ((ea->iop[0] == LSC_SCODE_ELS_REJECT) && 2025 (ea->iop[1] == 0x50000)) { /* reson 5=busy expl:0x0 */ 2026 set_bit(RELOGIN_NEEDED, &vha->dpc_flags); 2027 ea->fcport->fw_login_state = DSC_LS_PLOGI_COMP; 2028 break; 2029 } 2030 2031 sp = ea->sp; 2032 ql_dbg(ql_dbg_disc, vha, 0x2118, 2033 "%s %d %8phC priority %s, fc4type %x prev try %s\n", 2034 __func__, __LINE__, ea->fcport->port_name, 2035 vha->hw->fc4_type_priority == FC4_PRIORITY_FCP ? 2036 "FCP" : "NVMe", ea->fcport->fc4_type, 2037 (sp->u.iocb_cmd.u.logio.flags & SRB_LOGIN_NVME_PRLI) ? 2038 "NVME" : "FCP"); 2039 2040 if (NVME_FCP_TARGET(ea->fcport)) { 2041 if (sp->u.iocb_cmd.u.logio.flags & SRB_LOGIN_NVME_PRLI) 2042 ea->fcport->do_prli_nvme = 0; 2043 else 2044 ea->fcport->do_prli_nvme = 1; 2045 } else { 2046 ea->fcport->do_prli_nvme = 0; 2047 } 2048 2049 if (N2N_TOPO(vha->hw)) { 2050 if (ea->fcport->n2n_link_reset_cnt < 2051 vha->hw->login_retry_count) { 2052 ea->fcport->n2n_link_reset_cnt++; 2053 vha->relogin_jif = jiffies + 2 * HZ; 2054 /* 2055 * PRLI failed. Reset link to kick start 2056 * state machine 2057 */ 2058 set_bit(N2N_LINK_RESET, &vha->dpc_flags); 2059 qla2xxx_wake_dpc(vha); 2060 } else { 2061 ql_log(ql_log_warn, vha, 0x2119, 2062 "%s %d %8phC Unable to reconnect\n", 2063 __func__, __LINE__, 2064 ea->fcport->port_name); 2065 } 2066 } else { 2067 /* 2068 * switch connect. login failed. Take connection down 2069 * and allow relogin to retrigger 2070 */ 2071 ea->fcport->flags &= ~FCF_ASYNC_SENT; 2072 ea->fcport->keep_nport_handle = 0; 2073 ea->fcport->logout_on_delete = 1; 2074 qlt_schedule_sess_for_deletion(ea->fcport); 2075 } 2076 break; 2077 } 2078 } 2079 2080 void 2081 qla24xx_handle_plogi_done_event(struct scsi_qla_host *vha, struct event_arg *ea) 2082 { 2083 port_id_t cid; /* conflict Nport id */ 2084 u16 lid; 2085 struct fc_port *conflict_fcport; 2086 unsigned long flags; 2087 struct fc_port *fcport = ea->fcport; 2088 2089 ql_dbg(ql_dbg_disc, vha, 0xffff, 2090 "%s %8phC DS %d LS %d rc %d login %d|%d rscn %d|%d data %x|%x iop %x|%x\n", 2091 __func__, fcport->port_name, fcport->disc_state, 2092 fcport->fw_login_state, ea->rc, ea->sp->gen2, fcport->login_gen, 2093 ea->sp->gen1, fcport->rscn_gen, 2094 ea->data[0], ea->data[1], ea->iop[0], ea->iop[1]); 2095 2096 if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) || 2097 (fcport->fw_login_state == DSC_LS_PRLI_PEND)) { 2098 ql_dbg(ql_dbg_disc, vha, 0x20ea, 2099 "%s %d %8phC Remote is trying to login\n", 2100 __func__, __LINE__, fcport->port_name); 2101 return; 2102 } 2103 2104 if ((fcport->disc_state == DSC_DELETE_PEND) || 2105 (fcport->disc_state == DSC_DELETED)) { 2106 set_bit(RELOGIN_NEEDED, &vha->dpc_flags); 2107 return; 2108 } 2109 2110 if (ea->sp->gen2 != fcport->login_gen) { 2111 /* target side must have changed it. */ 2112 ql_dbg(ql_dbg_disc, vha, 0x20d3, 2113 "%s %8phC generation changed\n", 2114 __func__, fcport->port_name); 2115 set_bit(RELOGIN_NEEDED, &vha->dpc_flags); 2116 return; 2117 } else if (ea->sp->gen1 != fcport->rscn_gen) { 2118 ql_dbg(ql_dbg_disc, vha, 0x20d3, 2119 "%s %8phC RSCN generation changed\n", 2120 __func__, fcport->port_name); 2121 qla_rscn_replay(fcport); 2122 qlt_schedule_sess_for_deletion(fcport); 2123 return; 2124 } 2125 2126 WARN_ONCE(!qla2xxx_is_valid_mbs(ea->data[0]), "mbs: %#x\n", 2127 ea->data[0]); 2128 2129 switch (ea->data[0]) { 2130 case MBS_COMMAND_COMPLETE: 2131 /* 2132 * Driver must validate login state - If PRLI not complete, 2133 * force a relogin attempt via implicit LOGO, PLOGI, and PRLI 2134 * requests. 2135 */ 2136 if (vha->hw->flags.edif_enabled) { 2137 set_bit(ea->fcport->loop_id, vha->hw->loop_id_map); 2138 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); 2139 ea->fcport->chip_reset = vha->hw->base_qpair->chip_reset; 2140 ea->fcport->logout_on_delete = 1; 2141 ea->fcport->send_els_logo = 0; 2142 ea->fcport->fw_login_state = DSC_LS_PLOGI_COMP; 2143 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); 2144 2145 qla24xx_post_gpdb_work(vha, ea->fcport, 0); 2146 } else { 2147 if (NVME_TARGET(vha->hw, fcport)) { 2148 ql_dbg(ql_dbg_disc, vha, 0x2117, 2149 "%s %d %8phC post prli\n", 2150 __func__, __LINE__, fcport->port_name); 2151 qla24xx_post_prli_work(vha, fcport); 2152 } else { 2153 ql_dbg(ql_dbg_disc, vha, 0x20ea, 2154 "%s %d %8phC LoopID 0x%x in use with %06x. post gpdb\n", 2155 __func__, __LINE__, fcport->port_name, 2156 fcport->loop_id, fcport->d_id.b24); 2157 2158 set_bit(fcport->loop_id, vha->hw->loop_id_map); 2159 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); 2160 fcport->chip_reset = vha->hw->base_qpair->chip_reset; 2161 fcport->logout_on_delete = 1; 2162 fcport->send_els_logo = 0; 2163 fcport->fw_login_state = DSC_LS_PRLI_COMP; 2164 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); 2165 2166 qla24xx_post_gpdb_work(vha, fcport, 0); 2167 } 2168 } 2169 break; 2170 case MBS_COMMAND_ERROR: 2171 ql_dbg(ql_dbg_disc, vha, 0x20eb, "%s %d %8phC cmd error %x\n", 2172 __func__, __LINE__, ea->fcport->port_name, ea->data[1]); 2173 2174 ea->fcport->flags &= ~FCF_ASYNC_SENT; 2175 qla2x00_set_fcport_disc_state(ea->fcport, DSC_LOGIN_FAILED); 2176 if (ea->data[1] & QLA_LOGIO_LOGIN_RETRIED) 2177 set_bit(RELOGIN_NEEDED, &vha->dpc_flags); 2178 else 2179 qla2x00_mark_device_lost(vha, ea->fcport, 1); 2180 break; 2181 case MBS_LOOP_ID_USED: 2182 /* data[1] = IO PARAM 1 = nport ID */ 2183 cid.b.domain = (ea->iop[1] >> 16) & 0xff; 2184 cid.b.area = (ea->iop[1] >> 8) & 0xff; 2185 cid.b.al_pa = ea->iop[1] & 0xff; 2186 cid.b.rsvd_1 = 0; 2187 2188 ql_dbg(ql_dbg_disc, vha, 0x20ec, 2189 "%s %d %8phC lid %#x in use with pid %06x post gnl\n", 2190 __func__, __LINE__, ea->fcport->port_name, 2191 ea->fcport->loop_id, cid.b24); 2192 2193 set_bit(ea->fcport->loop_id, vha->hw->loop_id_map); 2194 ea->fcport->loop_id = FC_NO_LOOP_ID; 2195 qla24xx_post_gnl_work(vha, ea->fcport); 2196 break; 2197 case MBS_PORT_ID_USED: 2198 lid = ea->iop[1] & 0xffff; 2199 qlt_find_sess_invalidate_other(vha, 2200 wwn_to_u64(ea->fcport->port_name), 2201 ea->fcport->d_id, lid, &conflict_fcport); 2202 2203 if (conflict_fcport) { 2204 /* 2205 * Another fcport share the same loop_id/nport id. 2206 * Conflict fcport needs to finish cleanup before this 2207 * fcport can proceed to login. 2208 */ 2209 conflict_fcport->conflict = ea->fcport; 2210 ea->fcport->login_pause = 1; 2211 2212 ql_dbg(ql_dbg_disc, vha, 0x20ed, 2213 "%s %d %8phC NPortId %06x inuse with loopid 0x%x. post gidpn\n", 2214 __func__, __LINE__, ea->fcport->port_name, 2215 ea->fcport->d_id.b24, lid); 2216 } else { 2217 ql_dbg(ql_dbg_disc, vha, 0x20ed, 2218 "%s %d %8phC NPortId %06x inuse with loopid 0x%x. sched delete\n", 2219 __func__, __LINE__, ea->fcport->port_name, 2220 ea->fcport->d_id.b24, lid); 2221 2222 qla2x00_clear_loop_id(ea->fcport); 2223 set_bit(lid, vha->hw->loop_id_map); 2224 ea->fcport->loop_id = lid; 2225 ea->fcport->keep_nport_handle = 0; 2226 ea->fcport->logout_on_delete = 1; 2227 qlt_schedule_sess_for_deletion(ea->fcport); 2228 } 2229 break; 2230 } 2231 return; 2232 } 2233 2234 /****************************************************************************/ 2235 /* QLogic ISP2x00 Hardware Support Functions. */ 2236 /****************************************************************************/ 2237 2238 static int 2239 qla83xx_nic_core_fw_load(scsi_qla_host_t *vha) 2240 { 2241 int rval = QLA_SUCCESS; 2242 struct qla_hw_data *ha = vha->hw; 2243 uint32_t idc_major_ver, idc_minor_ver; 2244 uint16_t config[4]; 2245 2246 qla83xx_idc_lock(vha, 0); 2247 2248 /* SV: TODO: Assign initialization timeout from 2249 * flash-info / other param 2250 */ 2251 ha->fcoe_dev_init_timeout = QLA83XX_IDC_INITIALIZATION_TIMEOUT; 2252 ha->fcoe_reset_timeout = QLA83XX_IDC_RESET_ACK_TIMEOUT; 2253 2254 /* Set our fcoe function presence */ 2255 if (__qla83xx_set_drv_presence(vha) != QLA_SUCCESS) { 2256 ql_dbg(ql_dbg_p3p, vha, 0xb077, 2257 "Error while setting DRV-Presence.\n"); 2258 rval = QLA_FUNCTION_FAILED; 2259 goto exit; 2260 } 2261 2262 /* Decide the reset ownership */ 2263 qla83xx_reset_ownership(vha); 2264 2265 /* 2266 * On first protocol driver load: 2267 * Init-Owner: Set IDC-Major-Version and Clear IDC-Lock-Recovery 2268 * register. 2269 * Others: Check compatibility with current IDC Major version. 2270 */ 2271 qla83xx_rd_reg(vha, QLA83XX_IDC_MAJOR_VERSION, &idc_major_ver); 2272 if (ha->flags.nic_core_reset_owner) { 2273 /* Set IDC Major version */ 2274 idc_major_ver = QLA83XX_SUPP_IDC_MAJOR_VERSION; 2275 qla83xx_wr_reg(vha, QLA83XX_IDC_MAJOR_VERSION, idc_major_ver); 2276 2277 /* Clearing IDC-Lock-Recovery register */ 2278 qla83xx_wr_reg(vha, QLA83XX_IDC_LOCK_RECOVERY, 0); 2279 } else if (idc_major_ver != QLA83XX_SUPP_IDC_MAJOR_VERSION) { 2280 /* 2281 * Clear further IDC participation if we are not compatible with 2282 * the current IDC Major Version. 2283 */ 2284 ql_log(ql_log_warn, vha, 0xb07d, 2285 "Failing load, idc_major_ver=%d, expected_major_ver=%d.\n", 2286 idc_major_ver, QLA83XX_SUPP_IDC_MAJOR_VERSION); 2287 __qla83xx_clear_drv_presence(vha); 2288 rval = QLA_FUNCTION_FAILED; 2289 goto exit; 2290 } 2291 /* Each function sets its supported Minor version. */ 2292 qla83xx_rd_reg(vha, QLA83XX_IDC_MINOR_VERSION, &idc_minor_ver); 2293 idc_minor_ver |= (QLA83XX_SUPP_IDC_MINOR_VERSION << (ha->portnum * 2)); 2294 qla83xx_wr_reg(vha, QLA83XX_IDC_MINOR_VERSION, idc_minor_ver); 2295 2296 if (ha->flags.nic_core_reset_owner) { 2297 memset(config, 0, sizeof(config)); 2298 if (!qla81xx_get_port_config(vha, config)) 2299 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, 2300 QLA8XXX_DEV_READY); 2301 } 2302 2303 rval = qla83xx_idc_state_handler(vha); 2304 2305 exit: 2306 qla83xx_idc_unlock(vha, 0); 2307 2308 return rval; 2309 } 2310 2311 /* 2312 * qla2x00_initialize_adapter 2313 * Initialize board. 2314 * 2315 * Input: 2316 * ha = adapter block pointer. 2317 * 2318 * Returns: 2319 * 0 = success 2320 */ 2321 int 2322 qla2x00_initialize_adapter(scsi_qla_host_t *vha) 2323 { 2324 int rval; 2325 struct qla_hw_data *ha = vha->hw; 2326 struct req_que *req = ha->req_q_map[0]; 2327 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; 2328 2329 memset(&vha->qla_stats, 0, sizeof(vha->qla_stats)); 2330 memset(&vha->fc_host_stat, 0, sizeof(vha->fc_host_stat)); 2331 2332 /* Clear adapter flags. */ 2333 vha->flags.online = 0; 2334 ha->flags.chip_reset_done = 0; 2335 vha->flags.reset_active = 0; 2336 ha->flags.pci_channel_io_perm_failure = 0; 2337 ha->flags.eeh_busy = 0; 2338 vha->qla_stats.jiffies_at_last_reset = get_jiffies_64(); 2339 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME); 2340 atomic_set(&vha->loop_state, LOOP_DOWN); 2341 vha->device_flags = DFLG_NO_CABLE; 2342 vha->dpc_flags = 0; 2343 vha->flags.management_server_logged_in = 0; 2344 vha->marker_needed = 0; 2345 ha->isp_abort_cnt = 0; 2346 ha->beacon_blink_led = 0; 2347 2348 set_bit(0, ha->req_qid_map); 2349 set_bit(0, ha->rsp_qid_map); 2350 2351 ql_dbg(ql_dbg_init, vha, 0x0040, 2352 "Configuring PCI space...\n"); 2353 rval = ha->isp_ops->pci_config(vha); 2354 if (rval) { 2355 ql_log(ql_log_warn, vha, 0x0044, 2356 "Unable to configure PCI space.\n"); 2357 return (rval); 2358 } 2359 2360 ha->isp_ops->reset_chip(vha); 2361 2362 /* Check for secure flash support */ 2363 if (IS_QLA28XX(ha)) { 2364 if (rd_reg_word(®->mailbox12) & BIT_0) 2365 ha->flags.secure_adapter = 1; 2366 ql_log(ql_log_info, vha, 0xffff, "Secure Adapter: %s\n", 2367 (ha->flags.secure_adapter) ? "Yes" : "No"); 2368 } 2369 2370 2371 rval = qla2xxx_get_flash_info(vha); 2372 if (rval) { 2373 ql_log(ql_log_fatal, vha, 0x004f, 2374 "Unable to validate FLASH data.\n"); 2375 return rval; 2376 } 2377 2378 if (IS_QLA8044(ha)) { 2379 qla8044_read_reset_template(vha); 2380 2381 /* NOTE: If ql2xdontresethba==1, set IDC_CTRL DONTRESET_BIT0. 2382 * If DONRESET_BIT0 is set, drivers should not set dev_state 2383 * to NEED_RESET. But if NEED_RESET is set, drivers should 2384 * should honor the reset. */ 2385 if (ql2xdontresethba == 1) 2386 qla8044_set_idc_dontreset(vha); 2387 } 2388 2389 ha->isp_ops->get_flash_version(vha, req->ring); 2390 ql_dbg(ql_dbg_init, vha, 0x0061, 2391 "Configure NVRAM parameters...\n"); 2392 2393 /* Let priority default to FCP, can be overridden by nvram_config */ 2394 ha->fc4_type_priority = FC4_PRIORITY_FCP; 2395 2396 ha->isp_ops->nvram_config(vha); 2397 2398 if (ha->fc4_type_priority != FC4_PRIORITY_FCP && 2399 ha->fc4_type_priority != FC4_PRIORITY_NVME) 2400 ha->fc4_type_priority = FC4_PRIORITY_FCP; 2401 2402 ql_log(ql_log_info, vha, 0xffff, "FC4 priority set to %s\n", 2403 ha->fc4_type_priority == FC4_PRIORITY_FCP ? "FCP" : "NVMe"); 2404 2405 if (ha->flags.disable_serdes) { 2406 /* Mask HBA via NVRAM settings? */ 2407 ql_log(ql_log_info, vha, 0x0077, 2408 "Masking HBA WWPN %8phN (via NVRAM).\n", vha->port_name); 2409 return QLA_FUNCTION_FAILED; 2410 } 2411 2412 ql_dbg(ql_dbg_init, vha, 0x0078, 2413 "Verifying loaded RISC code...\n"); 2414 2415 /* If smartsan enabled then require fdmi and rdp enabled */ 2416 if (ql2xsmartsan) { 2417 ql2xfdmienable = 1; 2418 ql2xrdpenable = 1; 2419 } 2420 2421 if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) { 2422 rval = ha->isp_ops->chip_diag(vha); 2423 if (rval) 2424 return (rval); 2425 rval = qla2x00_setup_chip(vha); 2426 if (rval) 2427 return (rval); 2428 } 2429 2430 if (IS_QLA84XX(ha)) { 2431 ha->cs84xx = qla84xx_get_chip(vha); 2432 if (!ha->cs84xx) { 2433 ql_log(ql_log_warn, vha, 0x00d0, 2434 "Unable to configure ISP84XX.\n"); 2435 return QLA_FUNCTION_FAILED; 2436 } 2437 } 2438 2439 if (qla_ini_mode_enabled(vha) || qla_dual_mode_enabled(vha)) 2440 rval = qla2x00_init_rings(vha); 2441 2442 /* No point in continuing if firmware initialization failed. */ 2443 if (rval != QLA_SUCCESS) 2444 return rval; 2445 2446 ha->flags.chip_reset_done = 1; 2447 2448 if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) { 2449 /* Issue verify 84xx FW IOCB to complete 84xx initialization */ 2450 rval = qla84xx_init_chip(vha); 2451 if (rval != QLA_SUCCESS) { 2452 ql_log(ql_log_warn, vha, 0x00d4, 2453 "Unable to initialize ISP84XX.\n"); 2454 qla84xx_put_chip(vha); 2455 } 2456 } 2457 2458 /* Load the NIC Core f/w if we are the first protocol driver. */ 2459 if (IS_QLA8031(ha)) { 2460 rval = qla83xx_nic_core_fw_load(vha); 2461 if (rval) 2462 ql_log(ql_log_warn, vha, 0x0124, 2463 "Error in initializing NIC Core f/w.\n"); 2464 } 2465 2466 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha)) 2467 qla24xx_read_fcp_prio_cfg(vha); 2468 2469 if (IS_P3P_TYPE(ha)) 2470 qla82xx_set_driver_version(vha, QLA2XXX_VERSION); 2471 else 2472 qla25xx_set_driver_version(vha, QLA2XXX_VERSION); 2473 2474 return (rval); 2475 } 2476 2477 /** 2478 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers. 2479 * @vha: HA context 2480 * 2481 * Returns 0 on success. 2482 */ 2483 int 2484 qla2100_pci_config(scsi_qla_host_t *vha) 2485 { 2486 uint16_t w; 2487 unsigned long flags; 2488 struct qla_hw_data *ha = vha->hw; 2489 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; 2490 2491 pci_set_master(ha->pdev); 2492 pci_try_set_mwi(ha->pdev); 2493 2494 pci_read_config_word(ha->pdev, PCI_COMMAND, &w); 2495 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR); 2496 pci_write_config_word(ha->pdev, PCI_COMMAND, w); 2497 2498 pci_disable_rom(ha->pdev); 2499 2500 /* Get PCI bus information. */ 2501 spin_lock_irqsave(&ha->hardware_lock, flags); 2502 ha->pci_attr = rd_reg_word(®->ctrl_status); 2503 spin_unlock_irqrestore(&ha->hardware_lock, flags); 2504 2505 return QLA_SUCCESS; 2506 } 2507 2508 /** 2509 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers. 2510 * @vha: HA context 2511 * 2512 * Returns 0 on success. 2513 */ 2514 int 2515 qla2300_pci_config(scsi_qla_host_t *vha) 2516 { 2517 uint16_t w; 2518 unsigned long flags = 0; 2519 uint32_t cnt; 2520 struct qla_hw_data *ha = vha->hw; 2521 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; 2522 2523 pci_set_master(ha->pdev); 2524 pci_try_set_mwi(ha->pdev); 2525 2526 pci_read_config_word(ha->pdev, PCI_COMMAND, &w); 2527 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR); 2528 2529 if (IS_QLA2322(ha) || IS_QLA6322(ha)) 2530 w &= ~PCI_COMMAND_INTX_DISABLE; 2531 pci_write_config_word(ha->pdev, PCI_COMMAND, w); 2532 2533 /* 2534 * If this is a 2300 card and not 2312, reset the 2535 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately, 2536 * the 2310 also reports itself as a 2300 so we need to get the 2537 * fb revision level -- a 6 indicates it really is a 2300 and 2538 * not a 2310. 2539 */ 2540 if (IS_QLA2300(ha)) { 2541 spin_lock_irqsave(&ha->hardware_lock, flags); 2542 2543 /* Pause RISC. */ 2544 wrt_reg_word(®->hccr, HCCR_PAUSE_RISC); 2545 for (cnt = 0; cnt < 30000; cnt++) { 2546 if ((rd_reg_word(®->hccr) & HCCR_RISC_PAUSE) != 0) 2547 break; 2548 2549 udelay(10); 2550 } 2551 2552 /* Select FPM registers. */ 2553 wrt_reg_word(®->ctrl_status, 0x20); 2554 rd_reg_word(®->ctrl_status); 2555 2556 /* Get the fb rev level */ 2557 ha->fb_rev = RD_FB_CMD_REG(ha, reg); 2558 2559 if (ha->fb_rev == FPM_2300) 2560 pci_clear_mwi(ha->pdev); 2561 2562 /* Deselect FPM registers. */ 2563 wrt_reg_word(®->ctrl_status, 0x0); 2564 rd_reg_word(®->ctrl_status); 2565 2566 /* Release RISC module. */ 2567 wrt_reg_word(®->hccr, HCCR_RELEASE_RISC); 2568 for (cnt = 0; cnt < 30000; cnt++) { 2569 if ((rd_reg_word(®->hccr) & HCCR_RISC_PAUSE) == 0) 2570 break; 2571 2572 udelay(10); 2573 } 2574 2575 spin_unlock_irqrestore(&ha->hardware_lock, flags); 2576 } 2577 2578 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80); 2579 2580 pci_disable_rom(ha->pdev); 2581 2582 /* Get PCI bus information. */ 2583 spin_lock_irqsave(&ha->hardware_lock, flags); 2584 ha->pci_attr = rd_reg_word(®->ctrl_status); 2585 spin_unlock_irqrestore(&ha->hardware_lock, flags); 2586 2587 return QLA_SUCCESS; 2588 } 2589 2590 /** 2591 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers. 2592 * @vha: HA context 2593 * 2594 * Returns 0 on success. 2595 */ 2596 int 2597 qla24xx_pci_config(scsi_qla_host_t *vha) 2598 { 2599 uint16_t w; 2600 unsigned long flags = 0; 2601 struct qla_hw_data *ha = vha->hw; 2602 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; 2603 2604 pci_set_master(ha->pdev); 2605 pci_try_set_mwi(ha->pdev); 2606 2607 pci_read_config_word(ha->pdev, PCI_COMMAND, &w); 2608 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR); 2609 w &= ~PCI_COMMAND_INTX_DISABLE; 2610 pci_write_config_word(ha->pdev, PCI_COMMAND, w); 2611 2612 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80); 2613 2614 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */ 2615 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX)) 2616 pcix_set_mmrbc(ha->pdev, 2048); 2617 2618 /* PCIe -- adjust Maximum Read Request Size (2048). */ 2619 if (pci_is_pcie(ha->pdev)) 2620 pcie_set_readrq(ha->pdev, 4096); 2621 2622 pci_disable_rom(ha->pdev); 2623 2624 ha->chip_revision = ha->pdev->revision; 2625 2626 /* Get PCI bus information. */ 2627 spin_lock_irqsave(&ha->hardware_lock, flags); 2628 ha->pci_attr = rd_reg_dword(®->ctrl_status); 2629 spin_unlock_irqrestore(&ha->hardware_lock, flags); 2630 2631 return QLA_SUCCESS; 2632 } 2633 2634 /** 2635 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers. 2636 * @vha: HA context 2637 * 2638 * Returns 0 on success. 2639 */ 2640 int 2641 qla25xx_pci_config(scsi_qla_host_t *vha) 2642 { 2643 uint16_t w; 2644 struct qla_hw_data *ha = vha->hw; 2645 2646 pci_set_master(ha->pdev); 2647 pci_try_set_mwi(ha->pdev); 2648 2649 pci_read_config_word(ha->pdev, PCI_COMMAND, &w); 2650 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR); 2651 w &= ~PCI_COMMAND_INTX_DISABLE; 2652 pci_write_config_word(ha->pdev, PCI_COMMAND, w); 2653 2654 /* PCIe -- adjust Maximum Read Request Size (2048). */ 2655 if (pci_is_pcie(ha->pdev)) 2656 pcie_set_readrq(ha->pdev, 4096); 2657 2658 pci_disable_rom(ha->pdev); 2659 2660 ha->chip_revision = ha->pdev->revision; 2661 2662 return QLA_SUCCESS; 2663 } 2664 2665 /** 2666 * qla2x00_isp_firmware() - Choose firmware image. 2667 * @vha: HA context 2668 * 2669 * Returns 0 on success. 2670 */ 2671 static int 2672 qla2x00_isp_firmware(scsi_qla_host_t *vha) 2673 { 2674 int rval; 2675 uint16_t loop_id, topo, sw_cap; 2676 uint8_t domain, area, al_pa; 2677 struct qla_hw_data *ha = vha->hw; 2678 2679 /* Assume loading risc code */ 2680 rval = QLA_FUNCTION_FAILED; 2681 2682 if (ha->flags.disable_risc_code_load) { 2683 ql_log(ql_log_info, vha, 0x0079, "RISC CODE NOT loaded.\n"); 2684 2685 /* Verify checksum of loaded RISC code. */ 2686 rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address); 2687 if (rval == QLA_SUCCESS) { 2688 /* And, verify we are not in ROM code. */ 2689 rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa, 2690 &area, &domain, &topo, &sw_cap); 2691 } 2692 } 2693 2694 if (rval) 2695 ql_dbg(ql_dbg_init, vha, 0x007a, 2696 "**** Load RISC code ****.\n"); 2697 2698 return (rval); 2699 } 2700 2701 /** 2702 * qla2x00_reset_chip() - Reset ISP chip. 2703 * @vha: HA context 2704 * 2705 * Returns 0 on success. 2706 */ 2707 int 2708 qla2x00_reset_chip(scsi_qla_host_t *vha) 2709 { 2710 unsigned long flags = 0; 2711 struct qla_hw_data *ha = vha->hw; 2712 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; 2713 uint32_t cnt; 2714 uint16_t cmd; 2715 int rval = QLA_FUNCTION_FAILED; 2716 2717 if (unlikely(pci_channel_offline(ha->pdev))) 2718 return rval; 2719 2720 ha->isp_ops->disable_intrs(ha); 2721 2722 spin_lock_irqsave(&ha->hardware_lock, flags); 2723 2724 /* Turn off master enable */ 2725 cmd = 0; 2726 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd); 2727 cmd &= ~PCI_COMMAND_MASTER; 2728 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd); 2729 2730 if (!IS_QLA2100(ha)) { 2731 /* Pause RISC. */ 2732 wrt_reg_word(®->hccr, HCCR_PAUSE_RISC); 2733 if (IS_QLA2200(ha) || IS_QLA2300(ha)) { 2734 for (cnt = 0; cnt < 30000; cnt++) { 2735 if ((rd_reg_word(®->hccr) & 2736 HCCR_RISC_PAUSE) != 0) 2737 break; 2738 udelay(100); 2739 } 2740 } else { 2741 rd_reg_word(®->hccr); /* PCI Posting. */ 2742 udelay(10); 2743 } 2744 2745 /* Select FPM registers. */ 2746 wrt_reg_word(®->ctrl_status, 0x20); 2747 rd_reg_word(®->ctrl_status); /* PCI Posting. */ 2748 2749 /* FPM Soft Reset. */ 2750 wrt_reg_word(®->fpm_diag_config, 0x100); 2751 rd_reg_word(®->fpm_diag_config); /* PCI Posting. */ 2752 2753 /* Toggle Fpm Reset. */ 2754 if (!IS_QLA2200(ha)) { 2755 wrt_reg_word(®->fpm_diag_config, 0x0); 2756 rd_reg_word(®->fpm_diag_config); /* PCI Posting. */ 2757 } 2758 2759 /* Select frame buffer registers. */ 2760 wrt_reg_word(®->ctrl_status, 0x10); 2761 rd_reg_word(®->ctrl_status); /* PCI Posting. */ 2762 2763 /* Reset frame buffer FIFOs. */ 2764 if (IS_QLA2200(ha)) { 2765 WRT_FB_CMD_REG(ha, reg, 0xa000); 2766 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */ 2767 } else { 2768 WRT_FB_CMD_REG(ha, reg, 0x00fc); 2769 2770 /* Read back fb_cmd until zero or 3 seconds max */ 2771 for (cnt = 0; cnt < 3000; cnt++) { 2772 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0) 2773 break; 2774 udelay(100); 2775 } 2776 } 2777 2778 /* Select RISC module registers. */ 2779 wrt_reg_word(®->ctrl_status, 0); 2780 rd_reg_word(®->ctrl_status); /* PCI Posting. */ 2781 2782 /* Reset RISC processor. */ 2783 wrt_reg_word(®->hccr, HCCR_RESET_RISC); 2784 rd_reg_word(®->hccr); /* PCI Posting. */ 2785 2786 /* Release RISC processor. */ 2787 wrt_reg_word(®->hccr, HCCR_RELEASE_RISC); 2788 rd_reg_word(®->hccr); /* PCI Posting. */ 2789 } 2790 2791 wrt_reg_word(®->hccr, HCCR_CLR_RISC_INT); 2792 wrt_reg_word(®->hccr, HCCR_CLR_HOST_INT); 2793 2794 /* Reset ISP chip. */ 2795 wrt_reg_word(®->ctrl_status, CSR_ISP_SOFT_RESET); 2796 2797 /* Wait for RISC to recover from reset. */ 2798 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) { 2799 /* 2800 * It is necessary to for a delay here since the card doesn't 2801 * respond to PCI reads during a reset. On some architectures 2802 * this will result in an MCA. 2803 */ 2804 udelay(20); 2805 for (cnt = 30000; cnt; cnt--) { 2806 if ((rd_reg_word(®->ctrl_status) & 2807 CSR_ISP_SOFT_RESET) == 0) 2808 break; 2809 udelay(100); 2810 } 2811 } else 2812 udelay(10); 2813 2814 /* Reset RISC processor. */ 2815 wrt_reg_word(®->hccr, HCCR_RESET_RISC); 2816 2817 wrt_reg_word(®->semaphore, 0); 2818 2819 /* Release RISC processor. */ 2820 wrt_reg_word(®->hccr, HCCR_RELEASE_RISC); 2821 rd_reg_word(®->hccr); /* PCI Posting. */ 2822 2823 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) { 2824 for (cnt = 0; cnt < 30000; cnt++) { 2825 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY) 2826 break; 2827 2828 udelay(100); 2829 } 2830 } else 2831 udelay(100); 2832 2833 /* Turn on master enable */ 2834 cmd |= PCI_COMMAND_MASTER; 2835 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd); 2836 2837 /* Disable RISC pause on FPM parity error. */ 2838 if (!IS_QLA2100(ha)) { 2839 wrt_reg_word(®->hccr, HCCR_DISABLE_PARITY_PAUSE); 2840 rd_reg_word(®->hccr); /* PCI Posting. */ 2841 } 2842 2843 spin_unlock_irqrestore(&ha->hardware_lock, flags); 2844 2845 return QLA_SUCCESS; 2846 } 2847 2848 /** 2849 * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC. 2850 * @vha: HA context 2851 * 2852 * Returns 0 on success. 2853 */ 2854 static int 2855 qla81xx_reset_mpi(scsi_qla_host_t *vha) 2856 { 2857 uint16_t mb[4] = {0x1010, 0, 1, 0}; 2858 2859 if (!IS_QLA81XX(vha->hw)) 2860 return QLA_SUCCESS; 2861 2862 return qla81xx_write_mpi_register(vha, mb); 2863 } 2864 2865 static int 2866 qla_chk_risc_recovery(scsi_qla_host_t *vha) 2867 { 2868 struct qla_hw_data *ha = vha->hw; 2869 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; 2870 __le16 __iomem *mbptr = ®->mailbox0; 2871 int i; 2872 u16 mb[32]; 2873 int rc = QLA_SUCCESS; 2874 2875 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha)) 2876 return rc; 2877 2878 /* this check is only valid after RISC reset */ 2879 mb[0] = rd_reg_word(mbptr); 2880 mbptr++; 2881 if (mb[0] == 0xf) { 2882 rc = QLA_FUNCTION_FAILED; 2883 2884 for (i = 1; i < 32; i++) { 2885 mb[i] = rd_reg_word(mbptr); 2886 mbptr++; 2887 } 2888 2889 ql_log(ql_log_warn, vha, 0x1015, 2890 "RISC reset failed. mb[0-7] %04xh %04xh %04xh %04xh %04xh %04xh %04xh %04xh\n", 2891 mb[0], mb[1], mb[2], mb[3], mb[4], mb[5], mb[6], mb[7]); 2892 ql_log(ql_log_warn, vha, 0x1015, 2893 "RISC reset failed. mb[8-15] %04xh %04xh %04xh %04xh %04xh %04xh %04xh %04xh\n", 2894 mb[8], mb[9], mb[10], mb[11], mb[12], mb[13], mb[14], 2895 mb[15]); 2896 ql_log(ql_log_warn, vha, 0x1015, 2897 "RISC reset failed. mb[16-23] %04xh %04xh %04xh %04xh %04xh %04xh %04xh %04xh\n", 2898 mb[16], mb[17], mb[18], mb[19], mb[20], mb[21], mb[22], 2899 mb[23]); 2900 ql_log(ql_log_warn, vha, 0x1015, 2901 "RISC reset failed. mb[24-31] %04xh %04xh %04xh %04xh %04xh %04xh %04xh %04xh\n", 2902 mb[24], mb[25], mb[26], mb[27], mb[28], mb[29], mb[30], 2903 mb[31]); 2904 } 2905 return rc; 2906 } 2907 2908 /** 2909 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC. 2910 * @vha: HA context 2911 * 2912 * Returns 0 on success. 2913 */ 2914 static inline int 2915 qla24xx_reset_risc(scsi_qla_host_t *vha) 2916 { 2917 unsigned long flags = 0; 2918 struct qla_hw_data *ha = vha->hw; 2919 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; 2920 uint32_t cnt; 2921 uint16_t wd; 2922 static int abts_cnt; /* ISP abort retry counts */ 2923 int rval = QLA_SUCCESS; 2924 int print = 1; 2925 2926 spin_lock_irqsave(&ha->hardware_lock, flags); 2927 2928 /* Reset RISC. */ 2929 wrt_reg_dword(®->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES); 2930 for (cnt = 0; cnt < 30000; cnt++) { 2931 if ((rd_reg_dword(®->ctrl_status) & CSRX_DMA_ACTIVE) == 0) 2932 break; 2933 2934 udelay(10); 2935 } 2936 2937 if (!(rd_reg_dword(®->ctrl_status) & CSRX_DMA_ACTIVE)) 2938 set_bit(DMA_SHUTDOWN_CMPL, &ha->fw_dump_cap_flags); 2939 2940 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017e, 2941 "HCCR: 0x%x, Control Status %x, DMA active status:0x%x\n", 2942 rd_reg_dword(®->hccr), 2943 rd_reg_dword(®->ctrl_status), 2944 (rd_reg_dword(®->ctrl_status) & CSRX_DMA_ACTIVE)); 2945 2946 wrt_reg_dword(®->ctrl_status, 2947 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES); 2948 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd); 2949 2950 udelay(100); 2951 2952 /* Wait for firmware to complete NVRAM accesses. */ 2953 rd_reg_word(®->mailbox0); 2954 for (cnt = 10000; rd_reg_word(®->mailbox0) != 0 && 2955 rval == QLA_SUCCESS; cnt--) { 2956 barrier(); 2957 if (cnt) 2958 udelay(5); 2959 else 2960 rval = QLA_FUNCTION_TIMEOUT; 2961 } 2962 2963 if (rval == QLA_SUCCESS) 2964 set_bit(ISP_MBX_RDY, &ha->fw_dump_cap_flags); 2965 2966 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017f, 2967 "HCCR: 0x%x, MailBox0 Status 0x%x\n", 2968 rd_reg_dword(®->hccr), 2969 rd_reg_word(®->mailbox0)); 2970 2971 /* Wait for soft-reset to complete. */ 2972 rd_reg_dword(®->ctrl_status); 2973 for (cnt = 0; cnt < 60; cnt++) { 2974 barrier(); 2975 if ((rd_reg_dword(®->ctrl_status) & 2976 CSRX_ISP_SOFT_RESET) == 0) 2977 break; 2978 2979 udelay(5); 2980 } 2981 if (!(rd_reg_dword(®->ctrl_status) & CSRX_ISP_SOFT_RESET)) 2982 set_bit(ISP_SOFT_RESET_CMPL, &ha->fw_dump_cap_flags); 2983 2984 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015d, 2985 "HCCR: 0x%x, Soft Reset status: 0x%x\n", 2986 rd_reg_dword(®->hccr), 2987 rd_reg_dword(®->ctrl_status)); 2988 2989 /* If required, do an MPI FW reset now */ 2990 if (test_and_clear_bit(MPI_RESET_NEEDED, &vha->dpc_flags)) { 2991 if (qla81xx_reset_mpi(vha) != QLA_SUCCESS) { 2992 if (++abts_cnt < 5) { 2993 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); 2994 set_bit(MPI_RESET_NEEDED, &vha->dpc_flags); 2995 } else { 2996 /* 2997 * We exhausted the ISP abort retries. We have to 2998 * set the board offline. 2999 */ 3000 abts_cnt = 0; 3001 vha->flags.online = 0; 3002 } 3003 } 3004 } 3005 3006 wrt_reg_dword(®->hccr, HCCRX_SET_RISC_RESET); 3007 rd_reg_dword(®->hccr); 3008 3009 wrt_reg_dword(®->hccr, HCCRX_REL_RISC_PAUSE); 3010 rd_reg_dword(®->hccr); 3011 3012 wrt_reg_dword(®->hccr, HCCRX_CLR_RISC_RESET); 3013 mdelay(10); 3014 rd_reg_dword(®->hccr); 3015 3016 wd = rd_reg_word(®->mailbox0); 3017 for (cnt = 300; wd != 0 && rval == QLA_SUCCESS; cnt--) { 3018 barrier(); 3019 if (cnt) { 3020 mdelay(1); 3021 if (print && qla_chk_risc_recovery(vha)) 3022 print = 0; 3023 3024 wd = rd_reg_word(®->mailbox0); 3025 } else { 3026 rval = QLA_FUNCTION_TIMEOUT; 3027 3028 ql_log(ql_log_warn, vha, 0x015e, 3029 "RISC reset timeout\n"); 3030 } 3031 } 3032 3033 if (rval == QLA_SUCCESS) 3034 set_bit(RISC_RDY_AFT_RESET, &ha->fw_dump_cap_flags); 3035 3036 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015e, 3037 "Host Risc 0x%x, mailbox0 0x%x\n", 3038 rd_reg_dword(®->hccr), 3039 rd_reg_word(®->mailbox0)); 3040 3041 spin_unlock_irqrestore(&ha->hardware_lock, flags); 3042 3043 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015f, 3044 "Driver in %s mode\n", 3045 IS_NOPOLLING_TYPE(ha) ? "Interrupt" : "Polling"); 3046 3047 if (IS_NOPOLLING_TYPE(ha)) 3048 ha->isp_ops->enable_intrs(ha); 3049 3050 return rval; 3051 } 3052 3053 static void 3054 qla25xx_read_risc_sema_reg(scsi_qla_host_t *vha, uint32_t *data) 3055 { 3056 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24; 3057 3058 wrt_reg_dword(®->iobase_addr, RISC_REGISTER_BASE_OFFSET); 3059 *data = rd_reg_dword(®->iobase_window + RISC_REGISTER_WINDOW_OFFSET); 3060 } 3061 3062 static void 3063 qla25xx_write_risc_sema_reg(scsi_qla_host_t *vha, uint32_t data) 3064 { 3065 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24; 3066 3067 wrt_reg_dword(®->iobase_addr, RISC_REGISTER_BASE_OFFSET); 3068 wrt_reg_dword(®->iobase_window + RISC_REGISTER_WINDOW_OFFSET, data); 3069 } 3070 3071 static void 3072 qla25xx_manipulate_risc_semaphore(scsi_qla_host_t *vha) 3073 { 3074 uint32_t wd32 = 0; 3075 uint delta_msec = 100; 3076 uint elapsed_msec = 0; 3077 uint timeout_msec; 3078 ulong n; 3079 3080 if (vha->hw->pdev->subsystem_device != 0x0175 && 3081 vha->hw->pdev->subsystem_device != 0x0240) 3082 return; 3083 3084 wrt_reg_dword(&vha->hw->iobase->isp24.hccr, HCCRX_SET_RISC_PAUSE); 3085 udelay(100); 3086 3087 attempt: 3088 timeout_msec = TIMEOUT_SEMAPHORE; 3089 n = timeout_msec / delta_msec; 3090 while (n--) { 3091 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_SET); 3092 qla25xx_read_risc_sema_reg(vha, &wd32); 3093 if (wd32 & RISC_SEMAPHORE) 3094 break; 3095 msleep(delta_msec); 3096 elapsed_msec += delta_msec; 3097 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED) 3098 goto force; 3099 } 3100 3101 if (!(wd32 & RISC_SEMAPHORE)) 3102 goto force; 3103 3104 if (!(wd32 & RISC_SEMAPHORE_FORCE)) 3105 goto acquired; 3106 3107 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_CLR); 3108 timeout_msec = TIMEOUT_SEMAPHORE_FORCE; 3109 n = timeout_msec / delta_msec; 3110 while (n--) { 3111 qla25xx_read_risc_sema_reg(vha, &wd32); 3112 if (!(wd32 & RISC_SEMAPHORE_FORCE)) 3113 break; 3114 msleep(delta_msec); 3115 elapsed_msec += delta_msec; 3116 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED) 3117 goto force; 3118 } 3119 3120 if (wd32 & RISC_SEMAPHORE_FORCE) 3121 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_CLR); 3122 3123 goto attempt; 3124 3125 force: 3126 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_SET); 3127 3128 acquired: 3129 return; 3130 } 3131 3132 /** 3133 * qla24xx_reset_chip() - Reset ISP24xx chip. 3134 * @vha: HA context 3135 * 3136 * Returns 0 on success. 3137 */ 3138 int 3139 qla24xx_reset_chip(scsi_qla_host_t *vha) 3140 { 3141 struct qla_hw_data *ha = vha->hw; 3142 int rval = QLA_FUNCTION_FAILED; 3143 3144 if (pci_channel_offline(ha->pdev) && 3145 ha->flags.pci_channel_io_perm_failure) { 3146 return rval; 3147 } 3148 3149 ha->isp_ops->disable_intrs(ha); 3150 3151 qla25xx_manipulate_risc_semaphore(vha); 3152 3153 /* Perform RISC reset. */ 3154 rval = qla24xx_reset_risc(vha); 3155 3156 return rval; 3157 } 3158 3159 /** 3160 * qla2x00_chip_diag() - Test chip for proper operation. 3161 * @vha: HA context 3162 * 3163 * Returns 0 on success. 3164 */ 3165 int 3166 qla2x00_chip_diag(scsi_qla_host_t *vha) 3167 { 3168 int rval; 3169 struct qla_hw_data *ha = vha->hw; 3170 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; 3171 unsigned long flags = 0; 3172 uint16_t data; 3173 uint32_t cnt; 3174 uint16_t mb[5]; 3175 struct req_que *req = ha->req_q_map[0]; 3176 3177 /* Assume a failed state */ 3178 rval = QLA_FUNCTION_FAILED; 3179 3180 ql_dbg(ql_dbg_init, vha, 0x007b, "Testing device at %p.\n", 3181 ®->flash_address); 3182 3183 spin_lock_irqsave(&ha->hardware_lock, flags); 3184 3185 /* Reset ISP chip. */ 3186 wrt_reg_word(®->ctrl_status, CSR_ISP_SOFT_RESET); 3187 3188 /* 3189 * We need to have a delay here since the card will not respond while 3190 * in reset causing an MCA on some architectures. 3191 */ 3192 udelay(20); 3193 data = qla2x00_debounce_register(®->ctrl_status); 3194 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) { 3195 udelay(5); 3196 data = rd_reg_word(®->ctrl_status); 3197 barrier(); 3198 } 3199 3200 if (!cnt) 3201 goto chip_diag_failed; 3202 3203 ql_dbg(ql_dbg_init, vha, 0x007c, 3204 "Reset register cleared by chip reset.\n"); 3205 3206 /* Reset RISC processor. */ 3207 wrt_reg_word(®->hccr, HCCR_RESET_RISC); 3208 wrt_reg_word(®->hccr, HCCR_RELEASE_RISC); 3209 3210 /* Workaround for QLA2312 PCI parity error */ 3211 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) { 3212 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0)); 3213 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) { 3214 udelay(5); 3215 data = RD_MAILBOX_REG(ha, reg, 0); 3216 barrier(); 3217 } 3218 } else 3219 udelay(10); 3220 3221 if (!cnt) 3222 goto chip_diag_failed; 3223 3224 /* Check product ID of chip */ 3225 ql_dbg(ql_dbg_init, vha, 0x007d, "Checking product ID of chip.\n"); 3226 3227 mb[1] = RD_MAILBOX_REG(ha, reg, 1); 3228 mb[2] = RD_MAILBOX_REG(ha, reg, 2); 3229 mb[3] = RD_MAILBOX_REG(ha, reg, 3); 3230 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4)); 3231 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) || 3232 mb[3] != PROD_ID_3) { 3233 ql_log(ql_log_warn, vha, 0x0062, 3234 "Wrong product ID = 0x%x,0x%x,0x%x.\n", 3235 mb[1], mb[2], mb[3]); 3236 3237 goto chip_diag_failed; 3238 } 3239 ha->product_id[0] = mb[1]; 3240 ha->product_id[1] = mb[2]; 3241 ha->product_id[2] = mb[3]; 3242 ha->product_id[3] = mb[4]; 3243 3244 /* Adjust fw RISC transfer size */ 3245 if (req->length > 1024) 3246 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024; 3247 else 3248 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 3249 req->length; 3250 3251 if (IS_QLA2200(ha) && 3252 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) { 3253 /* Limit firmware transfer size with a 2200A */ 3254 ql_dbg(ql_dbg_init, vha, 0x007e, "Found QLA2200A Chip.\n"); 3255 3256 ha->device_type |= DT_ISP2200A; 3257 ha->fw_transfer_size = 128; 3258 } 3259 3260 /* Wrap Incoming Mailboxes Test. */ 3261 spin_unlock_irqrestore(&ha->hardware_lock, flags); 3262 3263 ql_dbg(ql_dbg_init, vha, 0x007f, "Checking mailboxes.\n"); 3264 rval = qla2x00_mbx_reg_test(vha); 3265 if (rval) 3266 ql_log(ql_log_warn, vha, 0x0080, 3267 "Failed mailbox send register test.\n"); 3268 else 3269 /* Flag a successful rval */ 3270 rval = QLA_SUCCESS; 3271 spin_lock_irqsave(&ha->hardware_lock, flags); 3272 3273 chip_diag_failed: 3274 if (rval) 3275 ql_log(ql_log_info, vha, 0x0081, 3276 "Chip diagnostics **** FAILED ****.\n"); 3277 3278 spin_unlock_irqrestore(&ha->hardware_lock, flags); 3279 3280 return (rval); 3281 } 3282 3283 /** 3284 * qla24xx_chip_diag() - Test ISP24xx for proper operation. 3285 * @vha: HA context 3286 * 3287 * Returns 0 on success. 3288 */ 3289 int 3290 qla24xx_chip_diag(scsi_qla_host_t *vha) 3291 { 3292 int rval; 3293 struct qla_hw_data *ha = vha->hw; 3294 struct req_que *req = ha->req_q_map[0]; 3295 3296 if (IS_P3P_TYPE(ha)) 3297 return QLA_SUCCESS; 3298 3299 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length; 3300 3301 rval = qla2x00_mbx_reg_test(vha); 3302 if (rval) { 3303 ql_log(ql_log_warn, vha, 0x0082, 3304 "Failed mailbox send register test.\n"); 3305 } else { 3306 /* Flag a successful rval */ 3307 rval = QLA_SUCCESS; 3308 } 3309 3310 return rval; 3311 } 3312 3313 static void 3314 qla2x00_init_fce_trace(scsi_qla_host_t *vha) 3315 { 3316 int rval; 3317 dma_addr_t tc_dma; 3318 void *tc; 3319 struct qla_hw_data *ha = vha->hw; 3320 3321 if (!IS_FWI2_CAPABLE(ha)) 3322 return; 3323 3324 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) && 3325 !IS_QLA27XX(ha) && !IS_QLA28XX(ha)) 3326 return; 3327 3328 if (ha->fce) { 3329 ql_dbg(ql_dbg_init, vha, 0x00bd, 3330 "%s: FCE Mem is already allocated.\n", 3331 __func__); 3332 return; 3333 } 3334 3335 /* Allocate memory for Fibre Channel Event Buffer. */ 3336 tc = dma_alloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma, 3337 GFP_KERNEL); 3338 if (!tc) { 3339 ql_log(ql_log_warn, vha, 0x00be, 3340 "Unable to allocate (%d KB) for FCE.\n", 3341 FCE_SIZE / 1024); 3342 return; 3343 } 3344 3345 rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS, 3346 ha->fce_mb, &ha->fce_bufs); 3347 if (rval) { 3348 ql_log(ql_log_warn, vha, 0x00bf, 3349 "Unable to initialize FCE (%d).\n", rval); 3350 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc, tc_dma); 3351 return; 3352 } 3353 3354 ql_dbg(ql_dbg_init, vha, 0x00c0, 3355 "Allocated (%d KB) for FCE...\n", FCE_SIZE / 1024); 3356 3357 ha->flags.fce_enabled = 1; 3358 ha->fce_dma = tc_dma; 3359 ha->fce = tc; 3360 } 3361 3362 static void 3363 qla2x00_init_eft_trace(scsi_qla_host_t *vha) 3364 { 3365 int rval; 3366 dma_addr_t tc_dma; 3367 void *tc; 3368 struct qla_hw_data *ha = vha->hw; 3369 3370 if (!IS_FWI2_CAPABLE(ha)) 3371 return; 3372 3373 if (ha->eft) { 3374 ql_dbg(ql_dbg_init, vha, 0x00bd, 3375 "%s: EFT Mem is already allocated.\n", 3376 __func__); 3377 return; 3378 } 3379 3380 /* Allocate memory for Extended Trace Buffer. */ 3381 tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma, 3382 GFP_KERNEL); 3383 if (!tc) { 3384 ql_log(ql_log_warn, vha, 0x00c1, 3385 "Unable to allocate (%d KB) for EFT.\n", 3386 EFT_SIZE / 1024); 3387 return; 3388 } 3389 3390 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS); 3391 if (rval) { 3392 ql_log(ql_log_warn, vha, 0x00c2, 3393 "Unable to initialize EFT (%d).\n", rval); 3394 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc, tc_dma); 3395 return; 3396 } 3397 3398 ql_dbg(ql_dbg_init, vha, 0x00c3, 3399 "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024); 3400 3401 ha->eft_dma = tc_dma; 3402 ha->eft = tc; 3403 } 3404 3405 static void 3406 qla2x00_alloc_offload_mem(scsi_qla_host_t *vha) 3407 { 3408 qla2x00_init_fce_trace(vha); 3409 qla2x00_init_eft_trace(vha); 3410 } 3411 3412 void 3413 qla2x00_alloc_fw_dump(scsi_qla_host_t *vha) 3414 { 3415 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size, 3416 eft_size, fce_size, mq_size; 3417 struct qla_hw_data *ha = vha->hw; 3418 struct req_que *req = ha->req_q_map[0]; 3419 struct rsp_que *rsp = ha->rsp_q_map[0]; 3420 struct qla2xxx_fw_dump *fw_dump; 3421 3422 dump_size = fixed_size = mem_size = eft_size = fce_size = mq_size = 0; 3423 req_q_size = rsp_q_size = 0; 3424 3425 if (IS_QLA2100(ha) || IS_QLA2200(ha)) { 3426 fixed_size = sizeof(struct qla2100_fw_dump); 3427 } else if (IS_QLA23XX(ha)) { 3428 fixed_size = offsetof(struct qla2300_fw_dump, data_ram); 3429 mem_size = (ha->fw_memory_size - 0x11000 + 1) * 3430 sizeof(uint16_t); 3431 } else if (IS_FWI2_CAPABLE(ha)) { 3432 if (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha)) 3433 fixed_size = offsetof(struct qla83xx_fw_dump, ext_mem); 3434 else if (IS_QLA81XX(ha)) 3435 fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem); 3436 else if (IS_QLA25XX(ha)) 3437 fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem); 3438 else 3439 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem); 3440 3441 mem_size = (ha->fw_memory_size - 0x100000 + 1) * 3442 sizeof(uint32_t); 3443 if (ha->mqenable) { 3444 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha) && 3445 !IS_QLA28XX(ha)) 3446 mq_size = sizeof(struct qla2xxx_mq_chain); 3447 /* 3448 * Allocate maximum buffer size for all queues - Q0. 3449 * Resizing must be done at end-of-dump processing. 3450 */ 3451 mq_size += (ha->max_req_queues - 1) * 3452 (req->length * sizeof(request_t)); 3453 mq_size += (ha->max_rsp_queues - 1) * 3454 (rsp->length * sizeof(response_t)); 3455 } 3456 if (ha->tgt.atio_ring) 3457 mq_size += ha->tgt.atio_q_length * sizeof(request_t); 3458 3459 qla2x00_init_fce_trace(vha); 3460 if (ha->fce) 3461 fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE; 3462 qla2x00_init_eft_trace(vha); 3463 if (ha->eft) 3464 eft_size = EFT_SIZE; 3465 } 3466 3467 if (IS_QLA27XX(ha) || IS_QLA28XX(ha)) { 3468 struct fwdt *fwdt = ha->fwdt; 3469 uint j; 3470 3471 for (j = 0; j < 2; j++, fwdt++) { 3472 if (!fwdt->template) { 3473 ql_dbg(ql_dbg_init, vha, 0x00ba, 3474 "-> fwdt%u no template\n", j); 3475 continue; 3476 } 3477 ql_dbg(ql_dbg_init, vha, 0x00fa, 3478 "-> fwdt%u calculating fwdump size...\n", j); 3479 fwdt->dump_size = qla27xx_fwdt_calculate_dump_size( 3480 vha, fwdt->template); 3481 ql_dbg(ql_dbg_init, vha, 0x00fa, 3482 "-> fwdt%u calculated fwdump size = %#lx bytes\n", 3483 j, fwdt->dump_size); 3484 dump_size += fwdt->dump_size; 3485 } 3486 /* Add space for spare MPI fw dump. */ 3487 dump_size += ha->fwdt[1].dump_size; 3488 } else { 3489 req_q_size = req->length * sizeof(request_t); 3490 rsp_q_size = rsp->length * sizeof(response_t); 3491 dump_size = offsetof(struct qla2xxx_fw_dump, isp); 3492 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size 3493 + eft_size; 3494 ha->chain_offset = dump_size; 3495 dump_size += mq_size + fce_size; 3496 if (ha->exchoffld_buf) 3497 dump_size += sizeof(struct qla2xxx_offld_chain) + 3498 ha->exchoffld_size; 3499 if (ha->exlogin_buf) 3500 dump_size += sizeof(struct qla2xxx_offld_chain) + 3501 ha->exlogin_size; 3502 } 3503 3504 if (!ha->fw_dump_len || dump_size > ha->fw_dump_alloc_len) { 3505 3506 ql_dbg(ql_dbg_init, vha, 0x00c5, 3507 "%s dump_size %d fw_dump_len %d fw_dump_alloc_len %d\n", 3508 __func__, dump_size, ha->fw_dump_len, 3509 ha->fw_dump_alloc_len); 3510 3511 fw_dump = vmalloc(dump_size); 3512 if (!fw_dump) { 3513 ql_log(ql_log_warn, vha, 0x00c4, 3514 "Unable to allocate (%d KB) for firmware dump.\n", 3515 dump_size / 1024); 3516 } else { 3517 mutex_lock(&ha->optrom_mutex); 3518 if (ha->fw_dumped) { 3519 memcpy(fw_dump, ha->fw_dump, ha->fw_dump_len); 3520 vfree(ha->fw_dump); 3521 ha->fw_dump = fw_dump; 3522 ha->fw_dump_alloc_len = dump_size; 3523 ql_dbg(ql_dbg_init, vha, 0x00c5, 3524 "Re-Allocated (%d KB) and save firmware dump.\n", 3525 dump_size / 1024); 3526 } else { 3527 vfree(ha->fw_dump); 3528 ha->fw_dump = fw_dump; 3529 3530 ha->fw_dump_len = ha->fw_dump_alloc_len = 3531 dump_size; 3532 ql_dbg(ql_dbg_init, vha, 0x00c5, 3533 "Allocated (%d KB) for firmware dump.\n", 3534 dump_size / 1024); 3535 3536 if (IS_QLA27XX(ha) || IS_QLA28XX(ha)) { 3537 ha->mpi_fw_dump = (char *)fw_dump + 3538 ha->fwdt[1].dump_size; 3539 mutex_unlock(&ha->optrom_mutex); 3540 return; 3541 } 3542 3543 ha->fw_dump->signature[0] = 'Q'; 3544 ha->fw_dump->signature[1] = 'L'; 3545 ha->fw_dump->signature[2] = 'G'; 3546 ha->fw_dump->signature[3] = 'C'; 3547 ha->fw_dump->version = htonl(1); 3548 3549 ha->fw_dump->fixed_size = htonl(fixed_size); 3550 ha->fw_dump->mem_size = htonl(mem_size); 3551 ha->fw_dump->req_q_size = htonl(req_q_size); 3552 ha->fw_dump->rsp_q_size = htonl(rsp_q_size); 3553 3554 ha->fw_dump->eft_size = htonl(eft_size); 3555 ha->fw_dump->eft_addr_l = 3556 htonl(LSD(ha->eft_dma)); 3557 ha->fw_dump->eft_addr_h = 3558 htonl(MSD(ha->eft_dma)); 3559 3560 ha->fw_dump->header_size = 3561 htonl(offsetof 3562 (struct qla2xxx_fw_dump, isp)); 3563 } 3564 mutex_unlock(&ha->optrom_mutex); 3565 } 3566 } 3567 } 3568 3569 static int 3570 qla81xx_mpi_sync(scsi_qla_host_t *vha) 3571 { 3572 #define MPS_MASK 0xe0 3573 int rval; 3574 uint16_t dc; 3575 uint32_t dw; 3576 3577 if (!IS_QLA81XX(vha->hw)) 3578 return QLA_SUCCESS; 3579 3580 rval = qla2x00_write_ram_word(vha, 0x7c00, 1); 3581 if (rval != QLA_SUCCESS) { 3582 ql_log(ql_log_warn, vha, 0x0105, 3583 "Unable to acquire semaphore.\n"); 3584 goto done; 3585 } 3586 3587 pci_read_config_word(vha->hw->pdev, 0x54, &dc); 3588 rval = qla2x00_read_ram_word(vha, 0x7a15, &dw); 3589 if (rval != QLA_SUCCESS) { 3590 ql_log(ql_log_warn, vha, 0x0067, "Unable to read sync.\n"); 3591 goto done_release; 3592 } 3593 3594 dc &= MPS_MASK; 3595 if (dc == (dw & MPS_MASK)) 3596 goto done_release; 3597 3598 dw &= ~MPS_MASK; 3599 dw |= dc; 3600 rval = qla2x00_write_ram_word(vha, 0x7a15, dw); 3601 if (rval != QLA_SUCCESS) { 3602 ql_log(ql_log_warn, vha, 0x0114, "Unable to gain sync.\n"); 3603 } 3604 3605 done_release: 3606 rval = qla2x00_write_ram_word(vha, 0x7c00, 0); 3607 if (rval != QLA_SUCCESS) { 3608 ql_log(ql_log_warn, vha, 0x006d, 3609 "Unable to release semaphore.\n"); 3610 } 3611 3612 done: 3613 return rval; 3614 } 3615 3616 int 3617 qla2x00_alloc_outstanding_cmds(struct qla_hw_data *ha, struct req_que *req) 3618 { 3619 /* Don't try to reallocate the array */ 3620 if (req->outstanding_cmds) 3621 return QLA_SUCCESS; 3622 3623 if (!IS_FWI2_CAPABLE(ha)) 3624 req->num_outstanding_cmds = DEFAULT_OUTSTANDING_COMMANDS; 3625 else { 3626 if (ha->cur_fw_xcb_count <= ha->cur_fw_iocb_count) 3627 req->num_outstanding_cmds = ha->cur_fw_xcb_count; 3628 else 3629 req->num_outstanding_cmds = ha->cur_fw_iocb_count; 3630 } 3631 3632 req->outstanding_cmds = kcalloc(req->num_outstanding_cmds, 3633 sizeof(srb_t *), 3634 GFP_KERNEL); 3635 3636 if (!req->outstanding_cmds) { 3637 /* 3638 * Try to allocate a minimal size just so we can get through 3639 * initialization. 3640 */ 3641 req->num_outstanding_cmds = MIN_OUTSTANDING_COMMANDS; 3642 req->outstanding_cmds = kcalloc(req->num_outstanding_cmds, 3643 sizeof(srb_t *), 3644 GFP_KERNEL); 3645 3646 if (!req->outstanding_cmds) { 3647 ql_log(ql_log_fatal, NULL, 0x0126, 3648 "Failed to allocate memory for " 3649 "outstanding_cmds for req_que %p.\n", req); 3650 req->num_outstanding_cmds = 0; 3651 return QLA_FUNCTION_FAILED; 3652 } 3653 } 3654 3655 return QLA_SUCCESS; 3656 } 3657 3658 #define PRINT_FIELD(_field, _flag, _str) { \ 3659 if (a0->_field & _flag) {\ 3660 if (p) {\ 3661 strcat(ptr, "|");\ 3662 ptr++;\ 3663 leftover--;\ 3664 } \ 3665 len = snprintf(ptr, leftover, "%s", _str); \ 3666 p = 1;\ 3667 leftover -= len;\ 3668 ptr += len; \ 3669 } \ 3670 } 3671 3672 static void qla2xxx_print_sfp_info(struct scsi_qla_host *vha) 3673 { 3674 #define STR_LEN 64 3675 struct sff_8247_a0 *a0 = (struct sff_8247_a0 *)vha->hw->sfp_data; 3676 u8 str[STR_LEN], *ptr, p; 3677 int leftover, len; 3678 3679 memset(str, 0, STR_LEN); 3680 snprintf(str, SFF_VEN_NAME_LEN+1, a0->vendor_name); 3681 ql_dbg(ql_dbg_init, vha, 0x015a, 3682 "SFP MFG Name: %s\n", str); 3683 3684 memset(str, 0, STR_LEN); 3685 snprintf(str, SFF_PART_NAME_LEN+1, a0->vendor_pn); 3686 ql_dbg(ql_dbg_init, vha, 0x015c, 3687 "SFP Part Name: %s\n", str); 3688 3689 /* media */ 3690 memset(str, 0, STR_LEN); 3691 ptr = str; 3692 leftover = STR_LEN; 3693 p = len = 0; 3694 PRINT_FIELD(fc_med_cc9, FC_MED_TW, "Twin AX"); 3695 PRINT_FIELD(fc_med_cc9, FC_MED_TP, "Twisted Pair"); 3696 PRINT_FIELD(fc_med_cc9, FC_MED_MI, "Min Coax"); 3697 PRINT_FIELD(fc_med_cc9, FC_MED_TV, "Video Coax"); 3698 PRINT_FIELD(fc_med_cc9, FC_MED_M6, "MultiMode 62.5um"); 3699 PRINT_FIELD(fc_med_cc9, FC_MED_M5, "MultiMode 50um"); 3700 PRINT_FIELD(fc_med_cc9, FC_MED_SM, "SingleMode"); 3701 ql_dbg(ql_dbg_init, vha, 0x0160, 3702 "SFP Media: %s\n", str); 3703 3704 /* link length */ 3705 memset(str, 0, STR_LEN); 3706 ptr = str; 3707 leftover = STR_LEN; 3708 p = len = 0; 3709 PRINT_FIELD(fc_ll_cc7, FC_LL_VL, "Very Long"); 3710 PRINT_FIELD(fc_ll_cc7, FC_LL_S, "Short"); 3711 PRINT_FIELD(fc_ll_cc7, FC_LL_I, "Intermediate"); 3712 PRINT_FIELD(fc_ll_cc7, FC_LL_L, "Long"); 3713 PRINT_FIELD(fc_ll_cc7, FC_LL_M, "Medium"); 3714 ql_dbg(ql_dbg_init, vha, 0x0196, 3715 "SFP Link Length: %s\n", str); 3716 3717 memset(str, 0, STR_LEN); 3718 ptr = str; 3719 leftover = STR_LEN; 3720 p = len = 0; 3721 PRINT_FIELD(fc_ll_cc7, FC_LL_SA, "Short Wave (SA)"); 3722 PRINT_FIELD(fc_ll_cc7, FC_LL_LC, "Long Wave(LC)"); 3723 PRINT_FIELD(fc_tec_cc8, FC_TEC_SN, "Short Wave (SN)"); 3724 PRINT_FIELD(fc_tec_cc8, FC_TEC_SL, "Short Wave (SL)"); 3725 PRINT_FIELD(fc_tec_cc8, FC_TEC_LL, "Long Wave (LL)"); 3726 ql_dbg(ql_dbg_init, vha, 0x016e, 3727 "SFP FC Link Tech: %s\n", str); 3728 3729 if (a0->length_km) 3730 ql_dbg(ql_dbg_init, vha, 0x016f, 3731 "SFP Distant: %d km\n", a0->length_km); 3732 if (a0->length_100m) 3733 ql_dbg(ql_dbg_init, vha, 0x0170, 3734 "SFP Distant: %d m\n", a0->length_100m*100); 3735 if (a0->length_50um_10m) 3736 ql_dbg(ql_dbg_init, vha, 0x0189, 3737 "SFP Distant (WL=50um): %d m\n", a0->length_50um_10m * 10); 3738 if (a0->length_62um_10m) 3739 ql_dbg(ql_dbg_init, vha, 0x018a, 3740 "SFP Distant (WL=62.5um): %d m\n", a0->length_62um_10m * 10); 3741 if (a0->length_om4_10m) 3742 ql_dbg(ql_dbg_init, vha, 0x0194, 3743 "SFP Distant (OM4): %d m\n", a0->length_om4_10m * 10); 3744 if (a0->length_om3_10m) 3745 ql_dbg(ql_dbg_init, vha, 0x0195, 3746 "SFP Distant (OM3): %d m\n", a0->length_om3_10m * 10); 3747 } 3748 3749 3750 /** 3751 * qla24xx_detect_sfp() 3752 * 3753 * @vha: adapter state pointer. 3754 * 3755 * @return 3756 * 0 -- Configure firmware to use short-range settings -- normal 3757 * buffer-to-buffer credits. 3758 * 3759 * 1 -- Configure firmware to use long-range settings -- extra 3760 * buffer-to-buffer credits should be allocated with 3761 * ha->lr_distance containing distance settings from NVRAM or SFP 3762 * (if supported). 3763 */ 3764 int 3765 qla24xx_detect_sfp(scsi_qla_host_t *vha) 3766 { 3767 int rc, used_nvram; 3768 struct sff_8247_a0 *a; 3769 struct qla_hw_data *ha = vha->hw; 3770 struct nvram_81xx *nv = ha->nvram; 3771 #define LR_DISTANCE_UNKNOWN 2 3772 static const char * const types[] = { "Short", "Long" }; 3773 static const char * const lengths[] = { "(10km)", "(5km)", "" }; 3774 u8 ll = 0; 3775 3776 /* Seed with NVRAM settings. */ 3777 used_nvram = 0; 3778 ha->flags.lr_detected = 0; 3779 if (IS_BPM_RANGE_CAPABLE(ha) && 3780 (nv->enhanced_features & NEF_LR_DIST_ENABLE)) { 3781 used_nvram = 1; 3782 ha->flags.lr_detected = 1; 3783 ha->lr_distance = 3784 (nv->enhanced_features >> LR_DIST_NV_POS) 3785 & LR_DIST_NV_MASK; 3786 } 3787 3788 if (!IS_BPM_ENABLED(vha)) 3789 goto out; 3790 /* Determine SR/LR capabilities of SFP/Transceiver. */ 3791 rc = qla2x00_read_sfp_dev(vha, NULL, 0); 3792 if (rc) 3793 goto out; 3794 3795 used_nvram = 0; 3796 a = (struct sff_8247_a0 *)vha->hw->sfp_data; 3797 qla2xxx_print_sfp_info(vha); 3798 3799 ha->flags.lr_detected = 0; 3800 ll = a->fc_ll_cc7; 3801 if (ll & FC_LL_VL || ll & FC_LL_L) { 3802 /* Long range, track length. */ 3803 ha->flags.lr_detected = 1; 3804 3805 if (a->length_km > 5 || a->length_100m > 50) 3806 ha->lr_distance = LR_DISTANCE_10K; 3807 else 3808 ha->lr_distance = LR_DISTANCE_5K; 3809 } 3810 3811 out: 3812 ql_dbg(ql_dbg_async, vha, 0x507b, 3813 "SFP detect: %s-Range SFP %s (nvr=%x ll=%x lr=%x lrd=%x).\n", 3814 types[ha->flags.lr_detected], 3815 ha->flags.lr_detected ? lengths[ha->lr_distance] : 3816 lengths[LR_DISTANCE_UNKNOWN], 3817 used_nvram, ll, ha->flags.lr_detected, ha->lr_distance); 3818 return ha->flags.lr_detected; 3819 } 3820 3821 void qla_init_iocb_limit(scsi_qla_host_t *vha) 3822 { 3823 u16 i, num_qps; 3824 u32 limit; 3825 struct qla_hw_data *ha = vha->hw; 3826 3827 num_qps = ha->num_qpairs + 1; 3828 limit = (ha->orig_fw_iocb_count * QLA_IOCB_PCT_LIMIT) / 100; 3829 3830 ha->base_qpair->fwres.iocbs_total = ha->orig_fw_iocb_count; 3831 ha->base_qpair->fwres.iocbs_limit = limit; 3832 ha->base_qpair->fwres.iocbs_qp_limit = limit / num_qps; 3833 ha->base_qpair->fwres.iocbs_used = 0; 3834 for (i = 0; i < ha->max_qpairs; i++) { 3835 if (ha->queue_pair_map[i]) { 3836 ha->queue_pair_map[i]->fwres.iocbs_total = 3837 ha->orig_fw_iocb_count; 3838 ha->queue_pair_map[i]->fwres.iocbs_limit = limit; 3839 ha->queue_pair_map[i]->fwres.iocbs_qp_limit = 3840 limit / num_qps; 3841 ha->queue_pair_map[i]->fwres.iocbs_used = 0; 3842 } 3843 } 3844 } 3845 3846 /** 3847 * qla2x00_setup_chip() - Load and start RISC firmware. 3848 * @vha: HA context 3849 * 3850 * Returns 0 on success. 3851 */ 3852 static int 3853 qla2x00_setup_chip(scsi_qla_host_t *vha) 3854 { 3855 int rval; 3856 uint32_t srisc_address = 0; 3857 struct qla_hw_data *ha = vha->hw; 3858 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; 3859 unsigned long flags; 3860 uint16_t fw_major_version; 3861 int done_once = 0; 3862 3863 if (IS_P3P_TYPE(ha)) { 3864 rval = ha->isp_ops->load_risc(vha, &srisc_address); 3865 if (rval == QLA_SUCCESS) { 3866 qla2x00_stop_firmware(vha); 3867 goto enable_82xx_npiv; 3868 } else 3869 goto failed; 3870 } 3871 3872 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) { 3873 /* Disable SRAM, Instruction RAM and GP RAM parity. */ 3874 spin_lock_irqsave(&ha->hardware_lock, flags); 3875 wrt_reg_word(®->hccr, (HCCR_ENABLE_PARITY + 0x0)); 3876 rd_reg_word(®->hccr); 3877 spin_unlock_irqrestore(&ha->hardware_lock, flags); 3878 } 3879 3880 qla81xx_mpi_sync(vha); 3881 3882 execute_fw_with_lr: 3883 /* Load firmware sequences */ 3884 rval = ha->isp_ops->load_risc(vha, &srisc_address); 3885 if (rval == QLA_SUCCESS) { 3886 ql_dbg(ql_dbg_init, vha, 0x00c9, 3887 "Verifying Checksum of loaded RISC code.\n"); 3888 3889 rval = qla2x00_verify_checksum(vha, srisc_address); 3890 if (rval == QLA_SUCCESS) { 3891 /* Start firmware execution. */ 3892 ql_dbg(ql_dbg_init, vha, 0x00ca, 3893 "Starting firmware.\n"); 3894 3895 if (ql2xexlogins) 3896 ha->flags.exlogins_enabled = 1; 3897 3898 if (qla_is_exch_offld_enabled(vha)) 3899 ha->flags.exchoffld_enabled = 1; 3900 3901 rval = qla2x00_execute_fw(vha, srisc_address); 3902 /* Retrieve firmware information. */ 3903 if (rval == QLA_SUCCESS) { 3904 /* Enable BPM support? */ 3905 if (!done_once++ && qla24xx_detect_sfp(vha)) { 3906 ql_dbg(ql_dbg_init, vha, 0x00ca, 3907 "Re-starting firmware -- BPM.\n"); 3908 /* Best-effort - re-init. */ 3909 ha->isp_ops->reset_chip(vha); 3910 ha->isp_ops->chip_diag(vha); 3911 goto execute_fw_with_lr; 3912 } 3913 3914 if (IS_ZIO_THRESHOLD_CAPABLE(ha)) 3915 qla27xx_set_zio_threshold(vha, 3916 ha->last_zio_threshold); 3917 3918 rval = qla2x00_set_exlogins_buffer(vha); 3919 if (rval != QLA_SUCCESS) 3920 goto failed; 3921 3922 rval = qla2x00_set_exchoffld_buffer(vha); 3923 if (rval != QLA_SUCCESS) 3924 goto failed; 3925 3926 enable_82xx_npiv: 3927 fw_major_version = ha->fw_major_version; 3928 if (IS_P3P_TYPE(ha)) 3929 qla82xx_check_md_needed(vha); 3930 else 3931 rval = qla2x00_get_fw_version(vha); 3932 if (rval != QLA_SUCCESS) 3933 goto failed; 3934 ha->flags.npiv_supported = 0; 3935 if (IS_QLA2XXX_MIDTYPE(ha) && 3936 (ha->fw_attributes & BIT_2)) { 3937 ha->flags.npiv_supported = 1; 3938 if ((!ha->max_npiv_vports) || 3939 ((ha->max_npiv_vports + 1) % 3940 MIN_MULTI_ID_FABRIC)) 3941 ha->max_npiv_vports = 3942 MIN_MULTI_ID_FABRIC - 1; 3943 } 3944 qla2x00_get_resource_cnts(vha); 3945 qla_init_iocb_limit(vha); 3946 3947 /* 3948 * Allocate the array of outstanding commands 3949 * now that we know the firmware resources. 3950 */ 3951 rval = qla2x00_alloc_outstanding_cmds(ha, 3952 vha->req); 3953 if (rval != QLA_SUCCESS) 3954 goto failed; 3955 3956 if (!fw_major_version && !(IS_P3P_TYPE(ha))) 3957 qla2x00_alloc_offload_mem(vha); 3958 3959 if (ql2xallocfwdump && !(IS_P3P_TYPE(ha))) 3960 qla2x00_alloc_fw_dump(vha); 3961 3962 } else { 3963 goto failed; 3964 } 3965 } else { 3966 ql_log(ql_log_fatal, vha, 0x00cd, 3967 "ISP Firmware failed checksum.\n"); 3968 goto failed; 3969 } 3970 3971 /* Enable PUREX PASSTHRU */ 3972 if (ql2xrdpenable || ha->flags.scm_supported_f || 3973 ha->flags.edif_enabled) 3974 qla25xx_set_els_cmds_supported(vha); 3975 } else 3976 goto failed; 3977 3978 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) { 3979 /* Enable proper parity. */ 3980 spin_lock_irqsave(&ha->hardware_lock, flags); 3981 if (IS_QLA2300(ha)) 3982 /* SRAM parity */ 3983 wrt_reg_word(®->hccr, HCCR_ENABLE_PARITY + 0x1); 3984 else 3985 /* SRAM, Instruction RAM and GP RAM parity */ 3986 wrt_reg_word(®->hccr, HCCR_ENABLE_PARITY + 0x7); 3987 rd_reg_word(®->hccr); 3988 spin_unlock_irqrestore(&ha->hardware_lock, flags); 3989 } 3990 3991 if (IS_QLA27XX(ha) || IS_QLA28XX(ha)) 3992 ha->flags.fac_supported = 1; 3993 else if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) { 3994 uint32_t size; 3995 3996 rval = qla81xx_fac_get_sector_size(vha, &size); 3997 if (rval == QLA_SUCCESS) { 3998 ha->flags.fac_supported = 1; 3999 ha->fdt_block_size = size << 2; 4000 } else { 4001 ql_log(ql_log_warn, vha, 0x00ce, 4002 "Unsupported FAC firmware (%d.%02d.%02d).\n", 4003 ha->fw_major_version, ha->fw_minor_version, 4004 ha->fw_subminor_version); 4005 4006 if (IS_QLA83XX(ha) || IS_QLA27XX(ha) || 4007 IS_QLA28XX(ha)) { 4008 ha->flags.fac_supported = 0; 4009 rval = QLA_SUCCESS; 4010 } 4011 } 4012 } 4013 failed: 4014 if (rval) { 4015 ql_log(ql_log_fatal, vha, 0x00cf, 4016 "Setup chip ****FAILED****.\n"); 4017 } 4018 4019 return (rval); 4020 } 4021 4022 /** 4023 * qla2x00_init_response_q_entries() - Initializes response queue entries. 4024 * @rsp: response queue 4025 * 4026 * Beginning of request ring has initialization control block already built 4027 * by nvram config routine. 4028 * 4029 * Returns 0 on success. 4030 */ 4031 void 4032 qla2x00_init_response_q_entries(struct rsp_que *rsp) 4033 { 4034 uint16_t cnt; 4035 response_t *pkt; 4036 4037 rsp->ring_ptr = rsp->ring; 4038 rsp->ring_index = 0; 4039 rsp->status_srb = NULL; 4040 pkt = rsp->ring_ptr; 4041 for (cnt = 0; cnt < rsp->length; cnt++) { 4042 pkt->signature = RESPONSE_PROCESSED; 4043 pkt++; 4044 } 4045 } 4046 4047 /** 4048 * qla2x00_update_fw_options() - Read and process firmware options. 4049 * @vha: HA context 4050 * 4051 * Returns 0 on success. 4052 */ 4053 void 4054 qla2x00_update_fw_options(scsi_qla_host_t *vha) 4055 { 4056 uint16_t swing, emphasis, tx_sens, rx_sens; 4057 struct qla_hw_data *ha = vha->hw; 4058 4059 memset(ha->fw_options, 0, sizeof(ha->fw_options)); 4060 qla2x00_get_fw_options(vha, ha->fw_options); 4061 4062 if (IS_QLA2100(ha) || IS_QLA2200(ha)) 4063 return; 4064 4065 /* Serial Link options. */ 4066 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0115, 4067 "Serial link options.\n"); 4068 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0109, 4069 ha->fw_seriallink_options, sizeof(ha->fw_seriallink_options)); 4070 4071 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING; 4072 if (ha->fw_seriallink_options[3] & BIT_2) { 4073 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING; 4074 4075 /* 1G settings */ 4076 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0); 4077 emphasis = (ha->fw_seriallink_options[2] & 4078 (BIT_4 | BIT_3)) >> 3; 4079 tx_sens = ha->fw_seriallink_options[0] & 4080 (BIT_3 | BIT_2 | BIT_1 | BIT_0); 4081 rx_sens = (ha->fw_seriallink_options[0] & 4082 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4; 4083 ha->fw_options[10] = (emphasis << 14) | (swing << 8); 4084 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) { 4085 if (rx_sens == 0x0) 4086 rx_sens = 0x3; 4087 ha->fw_options[10] |= (tx_sens << 4) | rx_sens; 4088 } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) 4089 ha->fw_options[10] |= BIT_5 | 4090 ((rx_sens & (BIT_1 | BIT_0)) << 2) | 4091 (tx_sens & (BIT_1 | BIT_0)); 4092 4093 /* 2G settings */ 4094 swing = (ha->fw_seriallink_options[2] & 4095 (BIT_7 | BIT_6 | BIT_5)) >> 5; 4096 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0); 4097 tx_sens = ha->fw_seriallink_options[1] & 4098 (BIT_3 | BIT_2 | BIT_1 | BIT_0); 4099 rx_sens = (ha->fw_seriallink_options[1] & 4100 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4; 4101 ha->fw_options[11] = (emphasis << 14) | (swing << 8); 4102 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) { 4103 if (rx_sens == 0x0) 4104 rx_sens = 0x3; 4105 ha->fw_options[11] |= (tx_sens << 4) | rx_sens; 4106 } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) 4107 ha->fw_options[11] |= BIT_5 | 4108 ((rx_sens & (BIT_1 | BIT_0)) << 2) | 4109 (tx_sens & (BIT_1 | BIT_0)); 4110 } 4111 4112 /* FCP2 options. */ 4113 /* Return command IOCBs without waiting for an ABTS to complete. */ 4114 ha->fw_options[3] |= BIT_13; 4115 4116 /* LED scheme. */ 4117 if (ha->flags.enable_led_scheme) 4118 ha->fw_options[2] |= BIT_12; 4119 4120 /* Detect ISP6312. */ 4121 if (IS_QLA6312(ha)) 4122 ha->fw_options[2] |= BIT_13; 4123 4124 /* Set Retry FLOGI in case of P2P connection */ 4125 if (ha->operating_mode == P2P) { 4126 ha->fw_options[2] |= BIT_3; 4127 ql_dbg(ql_dbg_disc, vha, 0x2100, 4128 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n", 4129 __func__, ha->fw_options[2]); 4130 } 4131 4132 /* Update firmware options. */ 4133 qla2x00_set_fw_options(vha, ha->fw_options); 4134 } 4135 4136 void 4137 qla24xx_update_fw_options(scsi_qla_host_t *vha) 4138 { 4139 int rval; 4140 struct qla_hw_data *ha = vha->hw; 4141 4142 if (IS_P3P_TYPE(ha)) 4143 return; 4144 4145 /* Hold status IOCBs until ABTS response received. */ 4146 if (ql2xfwholdabts) 4147 ha->fw_options[3] |= BIT_12; 4148 4149 /* Set Retry FLOGI in case of P2P connection */ 4150 if (ha->operating_mode == P2P) { 4151 ha->fw_options[2] |= BIT_3; 4152 ql_dbg(ql_dbg_disc, vha, 0x2101, 4153 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n", 4154 __func__, ha->fw_options[2]); 4155 } 4156 4157 /* Move PUREX, ABTS RX & RIDA to ATIOQ */ 4158 if (ql2xmvasynctoatio && !ha->flags.edif_enabled && 4159 (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha))) { 4160 if (qla_tgt_mode_enabled(vha) || 4161 qla_dual_mode_enabled(vha)) 4162 ha->fw_options[2] |= BIT_11; 4163 else 4164 ha->fw_options[2] &= ~BIT_11; 4165 } 4166 4167 if (IS_QLA25XX(ha) || IS_QLA83XX(ha) || IS_QLA27XX(ha) || 4168 IS_QLA28XX(ha)) { 4169 /* 4170 * Tell FW to track each exchange to prevent 4171 * driver from using stale exchange. 4172 */ 4173 if (qla_tgt_mode_enabled(vha) || 4174 qla_dual_mode_enabled(vha)) 4175 ha->fw_options[2] |= BIT_4; 4176 else 4177 ha->fw_options[2] &= ~(BIT_4); 4178 4179 /* Reserve 1/2 of emergency exchanges for ELS.*/ 4180 if (qla2xuseresexchforels) 4181 ha->fw_options[2] |= BIT_8; 4182 else 4183 ha->fw_options[2] &= ~BIT_8; 4184 4185 /* 4186 * N2N: set Secure=1 for PLOGI ACC and 4187 * fw shal not send PRLI after PLOGI Acc 4188 */ 4189 if (ha->flags.edif_enabled && 4190 vha->e_dbell.db_flags & EDB_ACTIVE) { 4191 ha->fw_options[3] |= BIT_15; 4192 ha->flags.n2n_fw_acc_sec = 1; 4193 } else { 4194 ha->fw_options[3] &= ~BIT_15; 4195 ha->flags.n2n_fw_acc_sec = 0; 4196 } 4197 } 4198 4199 if (ql2xrdpenable || ha->flags.scm_supported_f || 4200 ha->flags.edif_enabled) 4201 ha->fw_options[1] |= ADD_FO1_ENABLE_PUREX_IOCB; 4202 4203 /* Enable Async 8130/8131 events -- transceiver insertion/removal */ 4204 if (IS_BPM_RANGE_CAPABLE(ha)) 4205 ha->fw_options[3] |= BIT_10; 4206 4207 ql_dbg(ql_dbg_init, vha, 0x00e8, 4208 "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n", 4209 __func__, ha->fw_options[1], ha->fw_options[2], 4210 ha->fw_options[3], vha->host->active_mode); 4211 4212 if (ha->fw_options[1] || ha->fw_options[2] || ha->fw_options[3]) 4213 qla2x00_set_fw_options(vha, ha->fw_options); 4214 4215 /* Update Serial Link options. */ 4216 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0) 4217 return; 4218 4219 rval = qla2x00_set_serdes_params(vha, 4220 le16_to_cpu(ha->fw_seriallink_options24[1]), 4221 le16_to_cpu(ha->fw_seriallink_options24[2]), 4222 le16_to_cpu(ha->fw_seriallink_options24[3])); 4223 if (rval != QLA_SUCCESS) { 4224 ql_log(ql_log_warn, vha, 0x0104, 4225 "Unable to update Serial Link options (%x).\n", rval); 4226 } 4227 } 4228 4229 void 4230 qla2x00_config_rings(struct scsi_qla_host *vha) 4231 { 4232 struct qla_hw_data *ha = vha->hw; 4233 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; 4234 struct req_que *req = ha->req_q_map[0]; 4235 struct rsp_que *rsp = ha->rsp_q_map[0]; 4236 4237 /* Setup ring parameters in initialization control block. */ 4238 ha->init_cb->request_q_outpointer = cpu_to_le16(0); 4239 ha->init_cb->response_q_inpointer = cpu_to_le16(0); 4240 ha->init_cb->request_q_length = cpu_to_le16(req->length); 4241 ha->init_cb->response_q_length = cpu_to_le16(rsp->length); 4242 put_unaligned_le64(req->dma, &ha->init_cb->request_q_address); 4243 put_unaligned_le64(rsp->dma, &ha->init_cb->response_q_address); 4244 4245 wrt_reg_word(ISP_REQ_Q_IN(ha, reg), 0); 4246 wrt_reg_word(ISP_REQ_Q_OUT(ha, reg), 0); 4247 wrt_reg_word(ISP_RSP_Q_IN(ha, reg), 0); 4248 wrt_reg_word(ISP_RSP_Q_OUT(ha, reg), 0); 4249 rd_reg_word(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */ 4250 } 4251 4252 void 4253 qla24xx_config_rings(struct scsi_qla_host *vha) 4254 { 4255 struct qla_hw_data *ha = vha->hw; 4256 device_reg_t *reg = ISP_QUE_REG(ha, 0); 4257 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp; 4258 struct qla_msix_entry *msix; 4259 struct init_cb_24xx *icb; 4260 uint16_t rid = 0; 4261 struct req_que *req = ha->req_q_map[0]; 4262 struct rsp_que *rsp = ha->rsp_q_map[0]; 4263 4264 /* Setup ring parameters in initialization control block. */ 4265 icb = (struct init_cb_24xx *)ha->init_cb; 4266 icb->request_q_outpointer = cpu_to_le16(0); 4267 icb->response_q_inpointer = cpu_to_le16(0); 4268 icb->request_q_length = cpu_to_le16(req->length); 4269 icb->response_q_length = cpu_to_le16(rsp->length); 4270 put_unaligned_le64(req->dma, &icb->request_q_address); 4271 put_unaligned_le64(rsp->dma, &icb->response_q_address); 4272 4273 /* Setup ATIO queue dma pointers for target mode */ 4274 icb->atio_q_inpointer = cpu_to_le16(0); 4275 icb->atio_q_length = cpu_to_le16(ha->tgt.atio_q_length); 4276 put_unaligned_le64(ha->tgt.atio_dma, &icb->atio_q_address); 4277 4278 if (IS_SHADOW_REG_CAPABLE(ha)) 4279 icb->firmware_options_2 |= cpu_to_le32(BIT_30|BIT_29); 4280 4281 if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha) || 4282 IS_QLA28XX(ha)) { 4283 icb->qos = cpu_to_le16(QLA_DEFAULT_QUE_QOS); 4284 icb->rid = cpu_to_le16(rid); 4285 if (ha->flags.msix_enabled) { 4286 msix = &ha->msix_entries[1]; 4287 ql_dbg(ql_dbg_init, vha, 0x0019, 4288 "Registering vector 0x%x for base que.\n", 4289 msix->entry); 4290 icb->msix = cpu_to_le16(msix->entry); 4291 } 4292 /* Use alternate PCI bus number */ 4293 if (MSB(rid)) 4294 icb->firmware_options_2 |= cpu_to_le32(BIT_19); 4295 /* Use alternate PCI devfn */ 4296 if (LSB(rid)) 4297 icb->firmware_options_2 |= cpu_to_le32(BIT_18); 4298 4299 /* Use Disable MSIX Handshake mode for capable adapters */ 4300 if ((ha->fw_attributes & BIT_6) && (IS_MSIX_NACK_CAPABLE(ha)) && 4301 (ha->flags.msix_enabled)) { 4302 icb->firmware_options_2 &= cpu_to_le32(~BIT_22); 4303 ha->flags.disable_msix_handshake = 1; 4304 ql_dbg(ql_dbg_init, vha, 0x00fe, 4305 "MSIX Handshake Disable Mode turned on.\n"); 4306 } else { 4307 icb->firmware_options_2 |= cpu_to_le32(BIT_22); 4308 } 4309 icb->firmware_options_2 |= cpu_to_le32(BIT_23); 4310 4311 wrt_reg_dword(®->isp25mq.req_q_in, 0); 4312 wrt_reg_dword(®->isp25mq.req_q_out, 0); 4313 wrt_reg_dword(®->isp25mq.rsp_q_in, 0); 4314 wrt_reg_dword(®->isp25mq.rsp_q_out, 0); 4315 } else { 4316 wrt_reg_dword(®->isp24.req_q_in, 0); 4317 wrt_reg_dword(®->isp24.req_q_out, 0); 4318 wrt_reg_dword(®->isp24.rsp_q_in, 0); 4319 wrt_reg_dword(®->isp24.rsp_q_out, 0); 4320 } 4321 4322 qlt_24xx_config_rings(vha); 4323 4324 /* If the user has configured the speed, set it here */ 4325 if (ha->set_data_rate) { 4326 ql_dbg(ql_dbg_init, vha, 0x00fd, 4327 "Speed set by user : %s Gbps \n", 4328 qla2x00_get_link_speed_str(ha, ha->set_data_rate)); 4329 icb->firmware_options_3 = cpu_to_le32(ha->set_data_rate << 13); 4330 } 4331 4332 /* PCI posting */ 4333 rd_reg_word(&ioreg->hccr); 4334 } 4335 4336 /** 4337 * qla2x00_init_rings() - Initializes firmware. 4338 * @vha: HA context 4339 * 4340 * Beginning of request ring has initialization control block already built 4341 * by nvram config routine. 4342 * 4343 * Returns 0 on success. 4344 */ 4345 int 4346 qla2x00_init_rings(scsi_qla_host_t *vha) 4347 { 4348 int rval; 4349 unsigned long flags = 0; 4350 int cnt, que; 4351 struct qla_hw_data *ha = vha->hw; 4352 struct req_que *req; 4353 struct rsp_que *rsp; 4354 struct mid_init_cb_24xx *mid_init_cb = 4355 (struct mid_init_cb_24xx *) ha->init_cb; 4356 4357 spin_lock_irqsave(&ha->hardware_lock, flags); 4358 4359 /* Clear outstanding commands array. */ 4360 for (que = 0; que < ha->max_req_queues; que++) { 4361 req = ha->req_q_map[que]; 4362 if (!req || !test_bit(que, ha->req_qid_map)) 4363 continue; 4364 req->out_ptr = (uint16_t *)(req->ring + req->length); 4365 *req->out_ptr = 0; 4366 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) 4367 req->outstanding_cmds[cnt] = NULL; 4368 4369 req->current_outstanding_cmd = 1; 4370 4371 /* Initialize firmware. */ 4372 req->ring_ptr = req->ring; 4373 req->ring_index = 0; 4374 req->cnt = req->length; 4375 } 4376 4377 for (que = 0; que < ha->max_rsp_queues; que++) { 4378 rsp = ha->rsp_q_map[que]; 4379 if (!rsp || !test_bit(que, ha->rsp_qid_map)) 4380 continue; 4381 rsp->in_ptr = (uint16_t *)(rsp->ring + rsp->length); 4382 *rsp->in_ptr = 0; 4383 /* Initialize response queue entries */ 4384 if (IS_QLAFX00(ha)) 4385 qlafx00_init_response_q_entries(rsp); 4386 else 4387 qla2x00_init_response_q_entries(rsp); 4388 } 4389 4390 ha->tgt.atio_ring_ptr = ha->tgt.atio_ring; 4391 ha->tgt.atio_ring_index = 0; 4392 /* Initialize ATIO queue entries */ 4393 qlt_init_atio_q_entries(vha); 4394 4395 ha->isp_ops->config_rings(vha); 4396 4397 spin_unlock_irqrestore(&ha->hardware_lock, flags); 4398 4399 if (IS_QLAFX00(ha)) { 4400 rval = qlafx00_init_firmware(vha, ha->init_cb_size); 4401 goto next_check; 4402 } 4403 4404 /* Update any ISP specific firmware options before initialization. */ 4405 ha->isp_ops->update_fw_options(vha); 4406 4407 ql_dbg(ql_dbg_init, vha, 0x00d1, 4408 "Issue init firmware FW opt 1-3= %08x %08x %08x.\n", 4409 le32_to_cpu(mid_init_cb->init_cb.firmware_options_1), 4410 le32_to_cpu(mid_init_cb->init_cb.firmware_options_2), 4411 le32_to_cpu(mid_init_cb->init_cb.firmware_options_3)); 4412 4413 if (ha->flags.npiv_supported) { 4414 if (ha->operating_mode == LOOP && !IS_CNA_CAPABLE(ha)) 4415 ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1; 4416 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports); 4417 } 4418 4419 if (IS_FWI2_CAPABLE(ha)) { 4420 mid_init_cb->options = cpu_to_le16(BIT_1); 4421 mid_init_cb->init_cb.execution_throttle = 4422 cpu_to_le16(ha->cur_fw_xcb_count); 4423 ha->flags.dport_enabled = 4424 (le32_to_cpu(mid_init_cb->init_cb.firmware_options_1) & 4425 BIT_7) != 0; 4426 ql_dbg(ql_dbg_init, vha, 0x0191, "DPORT Support: %s.\n", 4427 (ha->flags.dport_enabled) ? "enabled" : "disabled"); 4428 /* FA-WWPN Status */ 4429 ha->flags.fawwpn_enabled = 4430 (le32_to_cpu(mid_init_cb->init_cb.firmware_options_1) & 4431 BIT_6) != 0; 4432 ql_dbg(ql_dbg_init, vha, 0x00bc, "FA-WWPN Support: %s.\n", 4433 (ha->flags.fawwpn_enabled) ? "enabled" : "disabled"); 4434 } 4435 4436 rval = qla2x00_init_firmware(vha, ha->init_cb_size); 4437 next_check: 4438 if (rval) { 4439 ql_log(ql_log_fatal, vha, 0x00d2, 4440 "Init Firmware **** FAILED ****.\n"); 4441 } else { 4442 ql_dbg(ql_dbg_init, vha, 0x00d3, 4443 "Init Firmware -- success.\n"); 4444 QLA_FW_STARTED(ha); 4445 vha->u_ql2xexchoffld = vha->u_ql2xiniexchg = 0; 4446 } 4447 4448 return (rval); 4449 } 4450 4451 /** 4452 * qla2x00_fw_ready() - Waits for firmware ready. 4453 * @vha: HA context 4454 * 4455 * Returns 0 on success. 4456 */ 4457 static int 4458 qla2x00_fw_ready(scsi_qla_host_t *vha) 4459 { 4460 int rval; 4461 unsigned long wtime, mtime, cs84xx_time; 4462 uint16_t min_wait; /* Minimum wait time if loop is down */ 4463 uint16_t wait_time; /* Wait time if loop is coming ready */ 4464 uint16_t state[6]; 4465 struct qla_hw_data *ha = vha->hw; 4466 4467 if (IS_QLAFX00(vha->hw)) 4468 return qlafx00_fw_ready(vha); 4469 4470 /* Time to wait for loop down */ 4471 if (IS_P3P_TYPE(ha)) 4472 min_wait = 30; 4473 else 4474 min_wait = 20; 4475 4476 /* 4477 * Firmware should take at most one RATOV to login, plus 5 seconds for 4478 * our own processing. 4479 */ 4480 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) { 4481 wait_time = min_wait; 4482 } 4483 4484 /* Min wait time if loop down */ 4485 mtime = jiffies + (min_wait * HZ); 4486 4487 /* wait time before firmware ready */ 4488 wtime = jiffies + (wait_time * HZ); 4489 4490 /* Wait for ISP to finish LIP */ 4491 if (!vha->flags.init_done) 4492 ql_log(ql_log_info, vha, 0x801e, 4493 "Waiting for LIP to complete.\n"); 4494 4495 do { 4496 memset(state, -1, sizeof(state)); 4497 rval = qla2x00_get_firmware_state(vha, state); 4498 if (rval == QLA_SUCCESS) { 4499 if (state[0] < FSTATE_LOSS_OF_SYNC) { 4500 vha->device_flags &= ~DFLG_NO_CABLE; 4501 } 4502 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) { 4503 ql_dbg(ql_dbg_taskm, vha, 0x801f, 4504 "fw_state=%x 84xx=%x.\n", state[0], 4505 state[2]); 4506 if ((state[2] & FSTATE_LOGGED_IN) && 4507 (state[2] & FSTATE_WAITING_FOR_VERIFY)) { 4508 ql_dbg(ql_dbg_taskm, vha, 0x8028, 4509 "Sending verify iocb.\n"); 4510 4511 cs84xx_time = jiffies; 4512 rval = qla84xx_init_chip(vha); 4513 if (rval != QLA_SUCCESS) { 4514 ql_log(ql_log_warn, 4515 vha, 0x8007, 4516 "Init chip failed.\n"); 4517 break; 4518 } 4519 4520 /* Add time taken to initialize. */ 4521 cs84xx_time = jiffies - cs84xx_time; 4522 wtime += cs84xx_time; 4523 mtime += cs84xx_time; 4524 ql_dbg(ql_dbg_taskm, vha, 0x8008, 4525 "Increasing wait time by %ld. " 4526 "New time %ld.\n", cs84xx_time, 4527 wtime); 4528 } 4529 } else if (state[0] == FSTATE_READY) { 4530 ql_dbg(ql_dbg_taskm, vha, 0x8037, 4531 "F/W Ready - OK.\n"); 4532 4533 qla2x00_get_retry_cnt(vha, &ha->retry_count, 4534 &ha->login_timeout, &ha->r_a_tov); 4535 4536 rval = QLA_SUCCESS; 4537 break; 4538 } 4539 4540 rval = QLA_FUNCTION_FAILED; 4541 4542 if (atomic_read(&vha->loop_down_timer) && 4543 state[0] != FSTATE_READY) { 4544 /* Loop down. Timeout on min_wait for states 4545 * other than Wait for Login. 4546 */ 4547 if (time_after_eq(jiffies, mtime)) { 4548 ql_log(ql_log_info, vha, 0x8038, 4549 "Cable is unplugged...\n"); 4550 4551 vha->device_flags |= DFLG_NO_CABLE; 4552 break; 4553 } 4554 } 4555 } else { 4556 /* Mailbox cmd failed. Timeout on min_wait. */ 4557 if (time_after_eq(jiffies, mtime) || 4558 ha->flags.isp82xx_fw_hung) 4559 break; 4560 } 4561 4562 if (time_after_eq(jiffies, wtime)) 4563 break; 4564 4565 /* Delay for a while */ 4566 msleep(500); 4567 } while (1); 4568 4569 ql_dbg(ql_dbg_taskm, vha, 0x803a, 4570 "fw_state=%x (%x, %x, %x, %x %x) curr time=%lx.\n", state[0], 4571 state[1], state[2], state[3], state[4], state[5], jiffies); 4572 4573 if (rval && !(vha->device_flags & DFLG_NO_CABLE)) { 4574 ql_log(ql_log_warn, vha, 0x803b, 4575 "Firmware ready **** FAILED ****.\n"); 4576 } 4577 4578 return (rval); 4579 } 4580 4581 /* 4582 * qla2x00_configure_hba 4583 * Setup adapter context. 4584 * 4585 * Input: 4586 * ha = adapter state pointer. 4587 * 4588 * Returns: 4589 * 0 = success 4590 * 4591 * Context: 4592 * Kernel context. 4593 */ 4594 static int 4595 qla2x00_configure_hba(scsi_qla_host_t *vha) 4596 { 4597 int rval; 4598 uint16_t loop_id; 4599 uint16_t topo; 4600 uint16_t sw_cap; 4601 uint8_t al_pa; 4602 uint8_t area; 4603 uint8_t domain; 4604 char connect_type[22]; 4605 struct qla_hw_data *ha = vha->hw; 4606 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev); 4607 port_id_t id; 4608 unsigned long flags; 4609 4610 /* Get host addresses. */ 4611 rval = qla2x00_get_adapter_id(vha, 4612 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap); 4613 if (rval != QLA_SUCCESS) { 4614 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) || 4615 IS_CNA_CAPABLE(ha) || 4616 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) { 4617 ql_dbg(ql_dbg_disc, vha, 0x2008, 4618 "Loop is in a transition state.\n"); 4619 } else { 4620 ql_log(ql_log_warn, vha, 0x2009, 4621 "Unable to get host loop ID.\n"); 4622 if (IS_FWI2_CAPABLE(ha) && (vha == base_vha) && 4623 (rval == QLA_COMMAND_ERROR && loop_id == 0x1b)) { 4624 ql_log(ql_log_warn, vha, 0x1151, 4625 "Doing link init.\n"); 4626 if (qla24xx_link_initialize(vha) == QLA_SUCCESS) 4627 return rval; 4628 } 4629 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); 4630 } 4631 return (rval); 4632 } 4633 4634 if (topo == 4) { 4635 ql_log(ql_log_info, vha, 0x200a, 4636 "Cannot get topology - retrying.\n"); 4637 return (QLA_FUNCTION_FAILED); 4638 } 4639 4640 vha->loop_id = loop_id; 4641 4642 /* initialize */ 4643 ha->min_external_loopid = SNS_FIRST_LOOP_ID; 4644 ha->operating_mode = LOOP; 4645 4646 switch (topo) { 4647 case 0: 4648 ql_dbg(ql_dbg_disc, vha, 0x200b, "HBA in NL topology.\n"); 4649 ha->switch_cap = 0; 4650 ha->current_topology = ISP_CFG_NL; 4651 strcpy(connect_type, "(Loop)"); 4652 break; 4653 4654 case 1: 4655 ql_dbg(ql_dbg_disc, vha, 0x200c, "HBA in FL topology.\n"); 4656 ha->switch_cap = sw_cap; 4657 ha->current_topology = ISP_CFG_FL; 4658 strcpy(connect_type, "(FL_Port)"); 4659 break; 4660 4661 case 2: 4662 ql_dbg(ql_dbg_disc, vha, 0x200d, "HBA in N P2P topology.\n"); 4663 ha->switch_cap = 0; 4664 ha->operating_mode = P2P; 4665 ha->current_topology = ISP_CFG_N; 4666 strcpy(connect_type, "(N_Port-to-N_Port)"); 4667 break; 4668 4669 case 3: 4670 ql_dbg(ql_dbg_disc, vha, 0x200e, "HBA in F P2P topology.\n"); 4671 ha->switch_cap = sw_cap; 4672 ha->operating_mode = P2P; 4673 ha->current_topology = ISP_CFG_F; 4674 strcpy(connect_type, "(F_Port)"); 4675 break; 4676 4677 default: 4678 ql_dbg(ql_dbg_disc, vha, 0x200f, 4679 "HBA in unknown topology %x, using NL.\n", topo); 4680 ha->switch_cap = 0; 4681 ha->current_topology = ISP_CFG_NL; 4682 strcpy(connect_type, "(Loop)"); 4683 break; 4684 } 4685 4686 /* Save Host port and loop ID. */ 4687 /* byte order - Big Endian */ 4688 id.b.domain = domain; 4689 id.b.area = area; 4690 id.b.al_pa = al_pa; 4691 id.b.rsvd_1 = 0; 4692 spin_lock_irqsave(&ha->hardware_lock, flags); 4693 if (vha->hw->flags.edif_enabled) { 4694 if (topo != 2) 4695 qlt_update_host_map(vha, id); 4696 } else if (!(topo == 2 && ha->flags.n2n_bigger)) 4697 qlt_update_host_map(vha, id); 4698 spin_unlock_irqrestore(&ha->hardware_lock, flags); 4699 4700 if (!vha->flags.init_done) 4701 ql_log(ql_log_info, vha, 0x2010, 4702 "Topology - %s, Host Loop address 0x%x.\n", 4703 connect_type, vha->loop_id); 4704 4705 return(rval); 4706 } 4707 4708 inline void 4709 qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len, 4710 const char *def) 4711 { 4712 char *st, *en; 4713 uint16_t index; 4714 uint64_t zero[2] = { 0 }; 4715 struct qla_hw_data *ha = vha->hw; 4716 int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) && 4717 !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha); 4718 4719 if (len > sizeof(zero)) 4720 len = sizeof(zero); 4721 if (memcmp(model, &zero, len) != 0) { 4722 memcpy(ha->model_number, model, len); 4723 st = en = ha->model_number; 4724 en += len - 1; 4725 while (en > st) { 4726 if (*en != 0x20 && *en != 0x00) 4727 break; 4728 *en-- = '\0'; 4729 } 4730 4731 index = (ha->pdev->subsystem_device & 0xff); 4732 if (use_tbl && 4733 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC && 4734 index < QLA_MODEL_NAMES) 4735 strlcpy(ha->model_desc, 4736 qla2x00_model_name[index * 2 + 1], 4737 sizeof(ha->model_desc)); 4738 } else { 4739 index = (ha->pdev->subsystem_device & 0xff); 4740 if (use_tbl && 4741 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC && 4742 index < QLA_MODEL_NAMES) { 4743 strlcpy(ha->model_number, 4744 qla2x00_model_name[index * 2], 4745 sizeof(ha->model_number)); 4746 strlcpy(ha->model_desc, 4747 qla2x00_model_name[index * 2 + 1], 4748 sizeof(ha->model_desc)); 4749 } else { 4750 strlcpy(ha->model_number, def, 4751 sizeof(ha->model_number)); 4752 } 4753 } 4754 if (IS_FWI2_CAPABLE(ha)) 4755 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc, 4756 sizeof(ha->model_desc)); 4757 } 4758 4759 /* On sparc systems, obtain port and node WWN from firmware 4760 * properties. 4761 */ 4762 static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv) 4763 { 4764 #ifdef CONFIG_SPARC 4765 struct qla_hw_data *ha = vha->hw; 4766 struct pci_dev *pdev = ha->pdev; 4767 struct device_node *dp = pci_device_to_OF_node(pdev); 4768 const u8 *val; 4769 int len; 4770 4771 val = of_get_property(dp, "port-wwn", &len); 4772 if (val && len >= WWN_SIZE) 4773 memcpy(nv->port_name, val, WWN_SIZE); 4774 4775 val = of_get_property(dp, "node-wwn", &len); 4776 if (val && len >= WWN_SIZE) 4777 memcpy(nv->node_name, val, WWN_SIZE); 4778 #endif 4779 } 4780 4781 /* 4782 * NVRAM configuration for ISP 2xxx 4783 * 4784 * Input: 4785 * ha = adapter block pointer. 4786 * 4787 * Output: 4788 * initialization control block in response_ring 4789 * host adapters parameters in host adapter block 4790 * 4791 * Returns: 4792 * 0 = success. 4793 */ 4794 int 4795 qla2x00_nvram_config(scsi_qla_host_t *vha) 4796 { 4797 int rval; 4798 uint8_t chksum = 0; 4799 uint16_t cnt; 4800 uint8_t *dptr1, *dptr2; 4801 struct qla_hw_data *ha = vha->hw; 4802 init_cb_t *icb = ha->init_cb; 4803 nvram_t *nv = ha->nvram; 4804 uint8_t *ptr = ha->nvram; 4805 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; 4806 4807 rval = QLA_SUCCESS; 4808 4809 /* Determine NVRAM starting address. */ 4810 ha->nvram_size = sizeof(*nv); 4811 ha->nvram_base = 0; 4812 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha)) 4813 if ((rd_reg_word(®->ctrl_status) >> 14) == 1) 4814 ha->nvram_base = 0x80; 4815 4816 /* Get NVRAM data and calculate checksum. */ 4817 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size); 4818 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++) 4819 chksum += *ptr++; 4820 4821 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x010f, 4822 "Contents of NVRAM.\n"); 4823 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0110, 4824 nv, ha->nvram_size); 4825 4826 /* Bad NVRAM data, set defaults parameters. */ 4827 if (chksum || memcmp("ISP ", nv->id, sizeof(nv->id)) || 4828 nv->nvram_version < 1) { 4829 /* Reset NVRAM data. */ 4830 ql_log(ql_log_warn, vha, 0x0064, 4831 "Inconsistent NVRAM detected: checksum=%#x id=%.4s version=%#x.\n", 4832 chksum, nv->id, nv->nvram_version); 4833 ql_log(ql_log_warn, vha, 0x0065, 4834 "Falling back to " 4835 "functioning (yet invalid -- WWPN) defaults.\n"); 4836 4837 /* 4838 * Set default initialization control block. 4839 */ 4840 memset(nv, 0, ha->nvram_size); 4841 nv->parameter_block_version = ICB_VERSION; 4842 4843 if (IS_QLA23XX(ha)) { 4844 nv->firmware_options[0] = BIT_2 | BIT_1; 4845 nv->firmware_options[1] = BIT_7 | BIT_5; 4846 nv->add_firmware_options[0] = BIT_5; 4847 nv->add_firmware_options[1] = BIT_5 | BIT_4; 4848 nv->frame_payload_size = cpu_to_le16(2048); 4849 nv->special_options[1] = BIT_7; 4850 } else if (IS_QLA2200(ha)) { 4851 nv->firmware_options[0] = BIT_2 | BIT_1; 4852 nv->firmware_options[1] = BIT_7 | BIT_5; 4853 nv->add_firmware_options[0] = BIT_5; 4854 nv->add_firmware_options[1] = BIT_5 | BIT_4; 4855 nv->frame_payload_size = cpu_to_le16(1024); 4856 } else if (IS_QLA2100(ha)) { 4857 nv->firmware_options[0] = BIT_3 | BIT_1; 4858 nv->firmware_options[1] = BIT_5; 4859 nv->frame_payload_size = cpu_to_le16(1024); 4860 } 4861 4862 nv->max_iocb_allocation = cpu_to_le16(256); 4863 nv->execution_throttle = cpu_to_le16(16); 4864 nv->retry_count = 8; 4865 nv->retry_delay = 1; 4866 4867 nv->port_name[0] = 33; 4868 nv->port_name[3] = 224; 4869 nv->port_name[4] = 139; 4870 4871 qla2xxx_nvram_wwn_from_ofw(vha, nv); 4872 4873 nv->login_timeout = 4; 4874 4875 /* 4876 * Set default host adapter parameters 4877 */ 4878 nv->host_p[1] = BIT_2; 4879 nv->reset_delay = 5; 4880 nv->port_down_retry_count = 8; 4881 nv->max_luns_per_target = cpu_to_le16(8); 4882 nv->link_down_timeout = 60; 4883 4884 rval = 1; 4885 } 4886 4887 /* Reset Initialization control block */ 4888 memset(icb, 0, ha->init_cb_size); 4889 4890 /* 4891 * Setup driver NVRAM options. 4892 */ 4893 nv->firmware_options[0] |= (BIT_6 | BIT_1); 4894 nv->firmware_options[0] &= ~(BIT_5 | BIT_4); 4895 nv->firmware_options[1] |= (BIT_5 | BIT_0); 4896 nv->firmware_options[1] &= ~BIT_4; 4897 4898 if (IS_QLA23XX(ha)) { 4899 nv->firmware_options[0] |= BIT_2; 4900 nv->firmware_options[0] &= ~BIT_3; 4901 nv->special_options[0] &= ~BIT_6; 4902 nv->add_firmware_options[1] |= BIT_5 | BIT_4; 4903 4904 if (IS_QLA2300(ha)) { 4905 if (ha->fb_rev == FPM_2310) { 4906 strcpy(ha->model_number, "QLA2310"); 4907 } else { 4908 strcpy(ha->model_number, "QLA2300"); 4909 } 4910 } else { 4911 qla2x00_set_model_info(vha, nv->model_number, 4912 sizeof(nv->model_number), "QLA23xx"); 4913 } 4914 } else if (IS_QLA2200(ha)) { 4915 nv->firmware_options[0] |= BIT_2; 4916 /* 4917 * 'Point-to-point preferred, else loop' is not a safe 4918 * connection mode setting. 4919 */ 4920 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) == 4921 (BIT_5 | BIT_4)) { 4922 /* Force 'loop preferred, else point-to-point'. */ 4923 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4); 4924 nv->add_firmware_options[0] |= BIT_5; 4925 } 4926 strcpy(ha->model_number, "QLA22xx"); 4927 } else /*if (IS_QLA2100(ha))*/ { 4928 strcpy(ha->model_number, "QLA2100"); 4929 } 4930 4931 /* 4932 * Copy over NVRAM RISC parameter block to initialization control block. 4933 */ 4934 dptr1 = (uint8_t *)icb; 4935 dptr2 = (uint8_t *)&nv->parameter_block_version; 4936 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version; 4937 while (cnt--) 4938 *dptr1++ = *dptr2++; 4939 4940 /* Copy 2nd half. */ 4941 dptr1 = (uint8_t *)icb->add_firmware_options; 4942 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options; 4943 while (cnt--) 4944 *dptr1++ = *dptr2++; 4945 ha->frame_payload_size = le16_to_cpu(icb->frame_payload_size); 4946 /* Use alternate WWN? */ 4947 if (nv->host_p[1] & BIT_7) { 4948 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE); 4949 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE); 4950 } 4951 4952 /* Prepare nodename */ 4953 if ((icb->firmware_options[1] & BIT_6) == 0) { 4954 /* 4955 * Firmware will apply the following mask if the nodename was 4956 * not provided. 4957 */ 4958 memcpy(icb->node_name, icb->port_name, WWN_SIZE); 4959 icb->node_name[0] &= 0xF0; 4960 } 4961 4962 /* 4963 * Set host adapter parameters. 4964 */ 4965 4966 /* 4967 * BIT_7 in the host-parameters section allows for modification to 4968 * internal driver logging. 4969 */ 4970 if (nv->host_p[0] & BIT_7) 4971 ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK; 4972 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0); 4973 /* Always load RISC code on non ISP2[12]00 chips. */ 4974 if (!IS_QLA2100(ha) && !IS_QLA2200(ha)) 4975 ha->flags.disable_risc_code_load = 0; 4976 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0); 4977 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0); 4978 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0); 4979 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0; 4980 ha->flags.disable_serdes = 0; 4981 4982 ha->operating_mode = 4983 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4; 4984 4985 memcpy(ha->fw_seriallink_options, nv->seriallink_options, 4986 sizeof(ha->fw_seriallink_options)); 4987 4988 /* save HBA serial number */ 4989 ha->serial0 = icb->port_name[5]; 4990 ha->serial1 = icb->port_name[6]; 4991 ha->serial2 = icb->port_name[7]; 4992 memcpy(vha->node_name, icb->node_name, WWN_SIZE); 4993 memcpy(vha->port_name, icb->port_name, WWN_SIZE); 4994 4995 icb->execution_throttle = cpu_to_le16(0xFFFF); 4996 4997 ha->retry_count = nv->retry_count; 4998 4999 /* Set minimum login_timeout to 4 seconds. */ 5000 if (nv->login_timeout != ql2xlogintimeout) 5001 nv->login_timeout = ql2xlogintimeout; 5002 if (nv->login_timeout < 4) 5003 nv->login_timeout = 4; 5004 ha->login_timeout = nv->login_timeout; 5005 5006 /* Set minimum RATOV to 100 tenths of a second. */ 5007 ha->r_a_tov = 100; 5008 5009 ha->loop_reset_delay = nv->reset_delay; 5010 5011 /* Link Down Timeout = 0: 5012 * 5013 * When Port Down timer expires we will start returning 5014 * I/O's to OS with "DID_NO_CONNECT". 5015 * 5016 * Link Down Timeout != 0: 5017 * 5018 * The driver waits for the link to come up after link down 5019 * before returning I/Os to OS with "DID_NO_CONNECT". 5020 */ 5021 if (nv->link_down_timeout == 0) { 5022 ha->loop_down_abort_time = 5023 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT); 5024 } else { 5025 ha->link_down_timeout = nv->link_down_timeout; 5026 ha->loop_down_abort_time = 5027 (LOOP_DOWN_TIME - ha->link_down_timeout); 5028 } 5029 5030 /* 5031 * Need enough time to try and get the port back. 5032 */ 5033 ha->port_down_retry_count = nv->port_down_retry_count; 5034 if (qlport_down_retry) 5035 ha->port_down_retry_count = qlport_down_retry; 5036 /* Set login_retry_count */ 5037 ha->login_retry_count = nv->retry_count; 5038 if (ha->port_down_retry_count == nv->port_down_retry_count && 5039 ha->port_down_retry_count > 3) 5040 ha->login_retry_count = ha->port_down_retry_count; 5041 else if (ha->port_down_retry_count > (int)ha->login_retry_count) 5042 ha->login_retry_count = ha->port_down_retry_count; 5043 if (ql2xloginretrycount) 5044 ha->login_retry_count = ql2xloginretrycount; 5045 5046 icb->lun_enables = cpu_to_le16(0); 5047 icb->command_resource_count = 0; 5048 icb->immediate_notify_resource_count = 0; 5049 icb->timeout = cpu_to_le16(0); 5050 5051 if (IS_QLA2100(ha) || IS_QLA2200(ha)) { 5052 /* Enable RIO */ 5053 icb->firmware_options[0] &= ~BIT_3; 5054 icb->add_firmware_options[0] &= 5055 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0); 5056 icb->add_firmware_options[0] |= BIT_2; 5057 icb->response_accumulation_timer = 3; 5058 icb->interrupt_delay_timer = 5; 5059 5060 vha->flags.process_response_queue = 1; 5061 } else { 5062 /* Enable ZIO. */ 5063 if (!vha->flags.init_done) { 5064 ha->zio_mode = icb->add_firmware_options[0] & 5065 (BIT_3 | BIT_2 | BIT_1 | BIT_0); 5066 ha->zio_timer = icb->interrupt_delay_timer ? 5067 icb->interrupt_delay_timer : 2; 5068 } 5069 icb->add_firmware_options[0] &= 5070 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0); 5071 vha->flags.process_response_queue = 0; 5072 if (ha->zio_mode != QLA_ZIO_DISABLED) { 5073 ha->zio_mode = QLA_ZIO_MODE_6; 5074 5075 ql_log(ql_log_info, vha, 0x0068, 5076 "ZIO mode %d enabled; timer delay (%d us).\n", 5077 ha->zio_mode, ha->zio_timer * 100); 5078 5079 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode; 5080 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer; 5081 vha->flags.process_response_queue = 1; 5082 } 5083 } 5084 5085 if (rval) { 5086 ql_log(ql_log_warn, vha, 0x0069, 5087 "NVRAM configuration failed.\n"); 5088 } 5089 return (rval); 5090 } 5091 5092 static void 5093 qla2x00_rport_del(void *data) 5094 { 5095 fc_port_t *fcport = data; 5096 struct fc_rport *rport; 5097 unsigned long flags; 5098 5099 spin_lock_irqsave(fcport->vha->host->host_lock, flags); 5100 rport = fcport->drport ? fcport->drport : fcport->rport; 5101 fcport->drport = NULL; 5102 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags); 5103 if (rport) { 5104 ql_dbg(ql_dbg_disc, fcport->vha, 0x210b, 5105 "%s %8phN. rport %p roles %x\n", 5106 __func__, fcport->port_name, rport, 5107 rport->roles); 5108 5109 fc_remote_port_delete(rport); 5110 } 5111 } 5112 5113 void qla2x00_set_fcport_state(fc_port_t *fcport, int state) 5114 { 5115 int old_state; 5116 5117 old_state = atomic_read(&fcport->state); 5118 atomic_set(&fcport->state, state); 5119 5120 /* Don't print state transitions during initial allocation of fcport */ 5121 if (old_state && old_state != state) { 5122 ql_dbg(ql_dbg_disc, fcport->vha, 0x207d, 5123 "FCPort %8phC state transitioned from %s to %s - portid=%02x%02x%02x.\n", 5124 fcport->port_name, port_state_str[old_state], 5125 port_state_str[state], fcport->d_id.b.domain, 5126 fcport->d_id.b.area, fcport->d_id.b.al_pa); 5127 } 5128 } 5129 5130 /** 5131 * qla2x00_alloc_fcport() - Allocate a generic fcport. 5132 * @vha: HA context 5133 * @flags: allocation flags 5134 * 5135 * Returns a pointer to the allocated fcport, or NULL, if none available. 5136 */ 5137 fc_port_t * 5138 qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags) 5139 { 5140 fc_port_t *fcport; 5141 5142 fcport = kzalloc(sizeof(fc_port_t), flags); 5143 if (!fcport) 5144 return NULL; 5145 5146 fcport->ct_desc.ct_sns = dma_alloc_coherent(&vha->hw->pdev->dev, 5147 sizeof(struct ct_sns_pkt), &fcport->ct_desc.ct_sns_dma, 5148 flags); 5149 if (!fcport->ct_desc.ct_sns) { 5150 ql_log(ql_log_warn, vha, 0xd049, 5151 "Failed to allocate ct_sns request.\n"); 5152 kfree(fcport); 5153 return NULL; 5154 } 5155 5156 /* Setup fcport template structure. */ 5157 fcport->vha = vha; 5158 fcport->port_type = FCT_UNKNOWN; 5159 fcport->loop_id = FC_NO_LOOP_ID; 5160 qla2x00_set_fcport_state(fcport, FCS_UNCONFIGURED); 5161 fcport->supported_classes = FC_COS_UNSPECIFIED; 5162 fcport->fp_speed = PORT_SPEED_UNKNOWN; 5163 5164 fcport->disc_state = DSC_DELETED; 5165 fcport->fw_login_state = DSC_LS_PORT_UNAVAIL; 5166 fcport->deleted = QLA_SESS_DELETED; 5167 fcport->login_retry = vha->hw->login_retry_count; 5168 fcport->chip_reset = vha->hw->base_qpair->chip_reset; 5169 fcport->logout_on_delete = 1; 5170 fcport->tgt_link_down_time = QLA2XX_MAX_LINK_DOWN_TIME; 5171 fcport->tgt_short_link_down_cnt = 0; 5172 fcport->dev_loss_tmo = 0; 5173 5174 if (!fcport->ct_desc.ct_sns) { 5175 ql_log(ql_log_warn, vha, 0xd049, 5176 "Failed to allocate ct_sns request.\n"); 5177 kfree(fcport); 5178 return NULL; 5179 } 5180 5181 INIT_WORK(&fcport->del_work, qla24xx_delete_sess_fn); 5182 INIT_WORK(&fcport->free_work, qlt_free_session_done); 5183 INIT_WORK(&fcport->reg_work, qla_register_fcport_fn); 5184 INIT_LIST_HEAD(&fcport->gnl_entry); 5185 INIT_LIST_HEAD(&fcport->list); 5186 5187 INIT_LIST_HEAD(&fcport->sess_cmd_list); 5188 spin_lock_init(&fcport->sess_cmd_lock); 5189 5190 spin_lock_init(&fcport->edif.sa_list_lock); 5191 INIT_LIST_HEAD(&fcport->edif.tx_sa_list); 5192 INIT_LIST_HEAD(&fcport->edif.rx_sa_list); 5193 5194 if (vha->e_dbell.db_flags == EDB_ACTIVE) 5195 fcport->edif.app_started = 1; 5196 5197 spin_lock_init(&fcport->edif.indx_list_lock); 5198 INIT_LIST_HEAD(&fcport->edif.edif_indx_list); 5199 5200 return fcport; 5201 } 5202 5203 void 5204 qla2x00_free_fcport(fc_port_t *fcport) 5205 { 5206 if (fcport->ct_desc.ct_sns) { 5207 dma_free_coherent(&fcport->vha->hw->pdev->dev, 5208 sizeof(struct ct_sns_pkt), fcport->ct_desc.ct_sns, 5209 fcport->ct_desc.ct_sns_dma); 5210 5211 fcport->ct_desc.ct_sns = NULL; 5212 } 5213 5214 qla_edif_flush_sa_ctl_lists(fcport); 5215 list_del(&fcport->list); 5216 qla2x00_clear_loop_id(fcport); 5217 5218 qla_edif_list_del(fcport); 5219 5220 kfree(fcport); 5221 } 5222 5223 static void qla_get_login_template(scsi_qla_host_t *vha) 5224 { 5225 struct qla_hw_data *ha = vha->hw; 5226 int rval; 5227 u32 *bp, sz; 5228 __be32 *q; 5229 5230 memset(ha->init_cb, 0, ha->init_cb_size); 5231 sz = min_t(int, sizeof(struct fc_els_flogi), ha->init_cb_size); 5232 rval = qla24xx_get_port_login_templ(vha, ha->init_cb_dma, 5233 ha->init_cb, sz); 5234 if (rval != QLA_SUCCESS) { 5235 ql_dbg(ql_dbg_init, vha, 0x00d1, 5236 "PLOGI ELS param read fail.\n"); 5237 return; 5238 } 5239 q = (__be32 *)&ha->plogi_els_payld.fl_csp; 5240 5241 bp = (uint32_t *)ha->init_cb; 5242 cpu_to_be32_array(q, bp, sz / 4); 5243 ha->flags.plogi_template_valid = 1; 5244 } 5245 5246 /* 5247 * qla2x00_configure_loop 5248 * Updates Fibre Channel Device Database with what is actually on loop. 5249 * 5250 * Input: 5251 * ha = adapter block pointer. 5252 * 5253 * Returns: 5254 * 0 = success. 5255 * 1 = error. 5256 * 2 = database was full and device was not configured. 5257 */ 5258 static int 5259 qla2x00_configure_loop(scsi_qla_host_t *vha) 5260 { 5261 int rval; 5262 unsigned long flags, save_flags; 5263 struct qla_hw_data *ha = vha->hw; 5264 5265 rval = QLA_SUCCESS; 5266 5267 /* Get Initiator ID */ 5268 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) { 5269 rval = qla2x00_configure_hba(vha); 5270 if (rval != QLA_SUCCESS) { 5271 ql_dbg(ql_dbg_disc, vha, 0x2013, 5272 "Unable to configure HBA.\n"); 5273 return (rval); 5274 } 5275 } 5276 5277 save_flags = flags = vha->dpc_flags; 5278 ql_dbg(ql_dbg_disc, vha, 0x2014, 5279 "Configure loop -- dpc flags = 0x%lx.\n", flags); 5280 5281 /* 5282 * If we have both an RSCN and PORT UPDATE pending then handle them 5283 * both at the same time. 5284 */ 5285 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); 5286 clear_bit(RSCN_UPDATE, &vha->dpc_flags); 5287 5288 qla2x00_get_data_rate(vha); 5289 qla_get_login_template(vha); 5290 5291 /* Determine what we need to do */ 5292 if ((ha->current_topology == ISP_CFG_FL || 5293 ha->current_topology == ISP_CFG_F) && 5294 (test_bit(LOCAL_LOOP_UPDATE, &flags))) { 5295 5296 set_bit(RSCN_UPDATE, &flags); 5297 clear_bit(LOCAL_LOOP_UPDATE, &flags); 5298 5299 } else if (ha->current_topology == ISP_CFG_NL || 5300 ha->current_topology == ISP_CFG_N) { 5301 clear_bit(RSCN_UPDATE, &flags); 5302 set_bit(LOCAL_LOOP_UPDATE, &flags); 5303 } else if (!vha->flags.online || 5304 (test_bit(ABORT_ISP_ACTIVE, &flags))) { 5305 set_bit(RSCN_UPDATE, &flags); 5306 set_bit(LOCAL_LOOP_UPDATE, &flags); 5307 } 5308 5309 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) { 5310 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) { 5311 ql_dbg(ql_dbg_disc, vha, 0x2015, 5312 "Loop resync needed, failing.\n"); 5313 rval = QLA_FUNCTION_FAILED; 5314 } else 5315 rval = qla2x00_configure_local_loop(vha); 5316 } 5317 5318 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) { 5319 if (LOOP_TRANSITION(vha)) { 5320 ql_dbg(ql_dbg_disc, vha, 0x2099, 5321 "Needs RSCN update and loop transition.\n"); 5322 rval = QLA_FUNCTION_FAILED; 5323 } 5324 else 5325 rval = qla2x00_configure_fabric(vha); 5326 } 5327 5328 if (rval == QLA_SUCCESS) { 5329 if (atomic_read(&vha->loop_down_timer) || 5330 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) { 5331 rval = QLA_FUNCTION_FAILED; 5332 } else { 5333 atomic_set(&vha->loop_state, LOOP_READY); 5334 ql_dbg(ql_dbg_disc, vha, 0x2069, 5335 "LOOP READY.\n"); 5336 ha->flags.fw_init_done = 1; 5337 5338 /* 5339 * use link up to wake up app to get ready for 5340 * authentication. 5341 */ 5342 if (ha->flags.edif_enabled && 5343 !(vha->e_dbell.db_flags & EDB_ACTIVE)) 5344 qla2x00_post_aen_work(vha, FCH_EVT_LINKUP, 5345 ha->link_data_rate); 5346 5347 /* 5348 * Process any ATIO queue entries that came in 5349 * while we weren't online. 5350 */ 5351 if (qla_tgt_mode_enabled(vha) || 5352 qla_dual_mode_enabled(vha)) { 5353 spin_lock_irqsave(&ha->tgt.atio_lock, flags); 5354 qlt_24xx_process_atio_queue(vha, 0); 5355 spin_unlock_irqrestore(&ha->tgt.atio_lock, 5356 flags); 5357 } 5358 } 5359 } 5360 5361 if (rval) { 5362 ql_dbg(ql_dbg_disc, vha, 0x206a, 5363 "%s *** FAILED ***.\n", __func__); 5364 } else { 5365 ql_dbg(ql_dbg_disc, vha, 0x206b, 5366 "%s: exiting normally. local port wwpn %8phN id %06x)\n", 5367 __func__, vha->port_name, vha->d_id.b24); 5368 } 5369 5370 /* Restore state if a resync event occurred during processing */ 5371 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) { 5372 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags)) 5373 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); 5374 if (test_bit(RSCN_UPDATE, &save_flags)) { 5375 set_bit(RSCN_UPDATE, &vha->dpc_flags); 5376 } 5377 } 5378 5379 return (rval); 5380 } 5381 5382 static int qla2x00_configure_n2n_loop(scsi_qla_host_t *vha) 5383 { 5384 unsigned long flags; 5385 fc_port_t *fcport; 5386 5387 ql_dbg(ql_dbg_disc, vha, 0x206a, "%s %d.\n", __func__, __LINE__); 5388 5389 if (test_and_clear_bit(N2N_LOGIN_NEEDED, &vha->dpc_flags)) 5390 set_bit(RELOGIN_NEEDED, &vha->dpc_flags); 5391 5392 list_for_each_entry(fcport, &vha->vp_fcports, list) { 5393 if (fcport->n2n_flag) { 5394 qla24xx_fcport_handle_login(vha, fcport); 5395 return QLA_SUCCESS; 5396 } 5397 } 5398 5399 spin_lock_irqsave(&vha->work_lock, flags); 5400 vha->scan.scan_retry++; 5401 spin_unlock_irqrestore(&vha->work_lock, flags); 5402 5403 if (vha->scan.scan_retry < MAX_SCAN_RETRIES) { 5404 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); 5405 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); 5406 } 5407 return QLA_FUNCTION_FAILED; 5408 } 5409 5410 /* 5411 * qla2x00_configure_local_loop 5412 * Updates Fibre Channel Device Database with local loop devices. 5413 * 5414 * Input: 5415 * ha = adapter block pointer. 5416 * 5417 * Returns: 5418 * 0 = success. 5419 */ 5420 static int 5421 qla2x00_configure_local_loop(scsi_qla_host_t *vha) 5422 { 5423 int rval, rval2; 5424 int found_devs; 5425 int found; 5426 fc_port_t *fcport, *new_fcport; 5427 uint16_t index; 5428 uint16_t entries; 5429 struct gid_list_info *gid; 5430 uint16_t loop_id; 5431 uint8_t domain, area, al_pa; 5432 struct qla_hw_data *ha = vha->hw; 5433 unsigned long flags; 5434 5435 /* Inititae N2N login. */ 5436 if (N2N_TOPO(ha)) 5437 return qla2x00_configure_n2n_loop(vha); 5438 5439 found_devs = 0; 5440 new_fcport = NULL; 5441 entries = MAX_FIBRE_DEVICES_LOOP; 5442 5443 /* Get list of logged in devices. */ 5444 memset(ha->gid_list, 0, qla2x00_gid_list_size(ha)); 5445 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma, 5446 &entries); 5447 if (rval != QLA_SUCCESS) 5448 goto err; 5449 5450 ql_dbg(ql_dbg_disc, vha, 0x2011, 5451 "Entries in ID list (%d).\n", entries); 5452 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2075, 5453 ha->gid_list, entries * sizeof(*ha->gid_list)); 5454 5455 if (entries == 0) { 5456 spin_lock_irqsave(&vha->work_lock, flags); 5457 vha->scan.scan_retry++; 5458 spin_unlock_irqrestore(&vha->work_lock, flags); 5459 5460 if (vha->scan.scan_retry < MAX_SCAN_RETRIES) { 5461 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); 5462 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); 5463 } 5464 } else { 5465 vha->scan.scan_retry = 0; 5466 } 5467 5468 list_for_each_entry(fcport, &vha->vp_fcports, list) { 5469 fcport->scan_state = QLA_FCPORT_SCAN; 5470 } 5471 5472 /* Allocate temporary fcport for any new fcports discovered. */ 5473 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); 5474 if (new_fcport == NULL) { 5475 ql_log(ql_log_warn, vha, 0x2012, 5476 "Memory allocation failed for fcport.\n"); 5477 rval = QLA_MEMORY_ALLOC_FAILED; 5478 goto err; 5479 } 5480 new_fcport->flags &= ~FCF_FABRIC_DEVICE; 5481 5482 /* Add devices to port list. */ 5483 gid = ha->gid_list; 5484 for (index = 0; index < entries; index++) { 5485 domain = gid->domain; 5486 area = gid->area; 5487 al_pa = gid->al_pa; 5488 if (IS_QLA2100(ha) || IS_QLA2200(ha)) 5489 loop_id = gid->loop_id_2100; 5490 else 5491 loop_id = le16_to_cpu(gid->loop_id); 5492 gid = (void *)gid + ha->gid_list_info_size; 5493 5494 /* Bypass reserved domain fields. */ 5495 if ((domain & 0xf0) == 0xf0) 5496 continue; 5497 5498 /* Bypass if not same domain and area of adapter. */ 5499 if (area && domain && ((area != vha->d_id.b.area) || 5500 (domain != vha->d_id.b.domain)) && 5501 (ha->current_topology == ISP_CFG_NL)) 5502 continue; 5503 5504 5505 /* Bypass invalid local loop ID. */ 5506 if (loop_id > LAST_LOCAL_LOOP_ID) 5507 continue; 5508 5509 memset(new_fcport->port_name, 0, WWN_SIZE); 5510 5511 /* Fill in member data. */ 5512 new_fcport->d_id.b.domain = domain; 5513 new_fcport->d_id.b.area = area; 5514 new_fcport->d_id.b.al_pa = al_pa; 5515 new_fcport->loop_id = loop_id; 5516 new_fcport->scan_state = QLA_FCPORT_FOUND; 5517 5518 rval2 = qla2x00_get_port_database(vha, new_fcport, 0); 5519 if (rval2 != QLA_SUCCESS) { 5520 ql_dbg(ql_dbg_disc, vha, 0x2097, 5521 "Failed to retrieve fcport information " 5522 "-- get_port_database=%x, loop_id=0x%04x.\n", 5523 rval2, new_fcport->loop_id); 5524 /* Skip retry if N2N */ 5525 if (ha->current_topology != ISP_CFG_N) { 5526 ql_dbg(ql_dbg_disc, vha, 0x2105, 5527 "Scheduling resync.\n"); 5528 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); 5529 continue; 5530 } 5531 } 5532 5533 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); 5534 /* Check for matching device in port list. */ 5535 found = 0; 5536 fcport = NULL; 5537 list_for_each_entry(fcport, &vha->vp_fcports, list) { 5538 if (memcmp(new_fcport->port_name, fcport->port_name, 5539 WWN_SIZE)) 5540 continue; 5541 5542 fcport->flags &= ~FCF_FABRIC_DEVICE; 5543 fcport->loop_id = new_fcport->loop_id; 5544 fcport->port_type = new_fcport->port_type; 5545 fcport->d_id.b24 = new_fcport->d_id.b24; 5546 memcpy(fcport->node_name, new_fcport->node_name, 5547 WWN_SIZE); 5548 fcport->scan_state = QLA_FCPORT_FOUND; 5549 found++; 5550 break; 5551 } 5552 5553 if (!found) { 5554 /* New device, add to fcports list. */ 5555 list_add_tail(&new_fcport->list, &vha->vp_fcports); 5556 5557 /* Allocate a new replacement fcport. */ 5558 fcport = new_fcport; 5559 5560 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); 5561 5562 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); 5563 5564 if (new_fcport == NULL) { 5565 ql_log(ql_log_warn, vha, 0xd031, 5566 "Failed to allocate memory for fcport.\n"); 5567 rval = QLA_MEMORY_ALLOC_FAILED; 5568 goto err; 5569 } 5570 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); 5571 new_fcport->flags &= ~FCF_FABRIC_DEVICE; 5572 } 5573 5574 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); 5575 5576 /* Base iIDMA settings on HBA port speed. */ 5577 fcport->fp_speed = ha->link_data_rate; 5578 5579 found_devs++; 5580 } 5581 5582 list_for_each_entry(fcport, &vha->vp_fcports, list) { 5583 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) 5584 break; 5585 5586 if (fcport->scan_state == QLA_FCPORT_SCAN) { 5587 if ((qla_dual_mode_enabled(vha) || 5588 qla_ini_mode_enabled(vha)) && 5589 atomic_read(&fcport->state) == FCS_ONLINE) { 5590 qla2x00_mark_device_lost(vha, fcport, 5591 ql2xplogiabsentdevice); 5592 if (fcport->loop_id != FC_NO_LOOP_ID && 5593 (fcport->flags & FCF_FCP2_DEVICE) == 0 && 5594 fcport->port_type != FCT_INITIATOR && 5595 fcport->port_type != FCT_BROADCAST) { 5596 ql_dbg(ql_dbg_disc, vha, 0x20f0, 5597 "%s %d %8phC post del sess\n", 5598 __func__, __LINE__, 5599 fcport->port_name); 5600 5601 qlt_schedule_sess_for_deletion(fcport); 5602 continue; 5603 } 5604 } 5605 } 5606 5607 if (fcport->scan_state == QLA_FCPORT_FOUND) 5608 qla24xx_fcport_handle_login(vha, fcport); 5609 } 5610 5611 qla2x00_free_fcport(new_fcport); 5612 5613 return rval; 5614 5615 err: 5616 ql_dbg(ql_dbg_disc, vha, 0x2098, 5617 "Configure local loop error exit: rval=%x.\n", rval); 5618 return rval; 5619 } 5620 5621 static void 5622 qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport) 5623 { 5624 int rval; 5625 uint16_t mb[MAILBOX_REGISTER_COUNT]; 5626 struct qla_hw_data *ha = vha->hw; 5627 5628 if (!IS_IIDMA_CAPABLE(ha)) 5629 return; 5630 5631 if (atomic_read(&fcport->state) != FCS_ONLINE) 5632 return; 5633 5634 if (fcport->fp_speed == PORT_SPEED_UNKNOWN || 5635 fcport->fp_speed > ha->link_data_rate || 5636 !ha->flags.gpsc_supported) 5637 return; 5638 5639 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed, 5640 mb); 5641 if (rval != QLA_SUCCESS) { 5642 ql_dbg(ql_dbg_disc, vha, 0x2004, 5643 "Unable to adjust iIDMA %8phN -- %04x %x %04x %04x.\n", 5644 fcport->port_name, rval, fcport->fp_speed, mb[0], mb[1]); 5645 } else { 5646 ql_dbg(ql_dbg_disc, vha, 0x2005, 5647 "iIDMA adjusted to %s GB/s (%X) on %8phN.\n", 5648 qla2x00_get_link_speed_str(ha, fcport->fp_speed), 5649 fcport->fp_speed, fcport->port_name); 5650 } 5651 } 5652 5653 void qla_do_iidma_work(struct scsi_qla_host *vha, fc_port_t *fcport) 5654 { 5655 qla2x00_iidma_fcport(vha, fcport); 5656 qla24xx_update_fcport_fcp_prio(vha, fcport); 5657 } 5658 5659 int qla_post_iidma_work(struct scsi_qla_host *vha, fc_port_t *fcport) 5660 { 5661 struct qla_work_evt *e; 5662 5663 e = qla2x00_alloc_work(vha, QLA_EVT_IIDMA); 5664 if (!e) 5665 return QLA_FUNCTION_FAILED; 5666 5667 e->u.fcport.fcport = fcport; 5668 return qla2x00_post_work(vha, e); 5669 } 5670 5671 /* qla2x00_reg_remote_port is reserved for Initiator Mode only.*/ 5672 static void 5673 qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport) 5674 { 5675 struct fc_rport_identifiers rport_ids; 5676 struct fc_rport *rport; 5677 unsigned long flags; 5678 5679 if (atomic_read(&fcport->state) == FCS_ONLINE) 5680 return; 5681 5682 rport_ids.node_name = wwn_to_u64(fcport->node_name); 5683 rport_ids.port_name = wwn_to_u64(fcport->port_name); 5684 rport_ids.port_id = fcport->d_id.b.domain << 16 | 5685 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa; 5686 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN; 5687 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids); 5688 if (!rport) { 5689 ql_log(ql_log_warn, vha, 0x2006, 5690 "Unable to allocate fc remote port.\n"); 5691 return; 5692 } 5693 5694 spin_lock_irqsave(fcport->vha->host->host_lock, flags); 5695 *((fc_port_t **)rport->dd_data) = fcport; 5696 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags); 5697 fcport->dev_loss_tmo = rport->dev_loss_tmo; 5698 5699 rport->supported_classes = fcport->supported_classes; 5700 5701 rport_ids.roles = FC_PORT_ROLE_UNKNOWN; 5702 if (fcport->port_type == FCT_INITIATOR) 5703 rport_ids.roles |= FC_PORT_ROLE_FCP_INITIATOR; 5704 if (fcport->port_type == FCT_TARGET) 5705 rport_ids.roles |= FC_PORT_ROLE_FCP_TARGET; 5706 if (fcport->port_type & FCT_NVME_INITIATOR) 5707 rport_ids.roles |= FC_PORT_ROLE_NVME_INITIATOR; 5708 if (fcport->port_type & FCT_NVME_TARGET) 5709 rport_ids.roles |= FC_PORT_ROLE_NVME_TARGET; 5710 if (fcport->port_type & FCT_NVME_DISCOVERY) 5711 rport_ids.roles |= FC_PORT_ROLE_NVME_DISCOVERY; 5712 5713 fc_remote_port_rolechg(rport, rport_ids.roles); 5714 5715 ql_dbg(ql_dbg_disc, vha, 0x20ee, 5716 "%s: %8phN. rport %ld:0:%d (%p) is %s mode\n", 5717 __func__, fcport->port_name, vha->host_no, 5718 rport->scsi_target_id, rport, 5719 (fcport->port_type == FCT_TARGET) ? "tgt" : 5720 ((fcport->port_type & FCT_NVME) ? "nvme" : "ini")); 5721 } 5722 5723 /* 5724 * qla2x00_update_fcport 5725 * Updates device on list. 5726 * 5727 * Input: 5728 * ha = adapter block pointer. 5729 * fcport = port structure pointer. 5730 * 5731 * Return: 5732 * 0 - Success 5733 * BIT_0 - error 5734 * 5735 * Context: 5736 * Kernel context. 5737 */ 5738 void 5739 qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport) 5740 { 5741 if (IS_SW_RESV_ADDR(fcport->d_id)) 5742 return; 5743 5744 ql_dbg(ql_dbg_disc, vha, 0x20ef, "%s %8phC\n", 5745 __func__, fcport->port_name); 5746 5747 qla2x00_set_fcport_disc_state(fcport, DSC_UPD_FCPORT); 5748 fcport->login_retry = vha->hw->login_retry_count; 5749 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT); 5750 fcport->deleted = 0; 5751 if (vha->hw->current_topology == ISP_CFG_NL) 5752 fcport->logout_on_delete = 0; 5753 else 5754 fcport->logout_on_delete = 1; 5755 fcport->n2n_chip_reset = fcport->n2n_link_reset_cnt = 0; 5756 5757 if (fcport->tgt_link_down_time < fcport->dev_loss_tmo) { 5758 fcport->tgt_short_link_down_cnt++; 5759 fcport->tgt_link_down_time = QLA2XX_MAX_LINK_DOWN_TIME; 5760 } 5761 5762 switch (vha->hw->current_topology) { 5763 case ISP_CFG_N: 5764 case ISP_CFG_NL: 5765 fcport->keep_nport_handle = 1; 5766 break; 5767 default: 5768 break; 5769 } 5770 5771 qla2x00_iidma_fcport(vha, fcport); 5772 5773 qla2x00_dfs_create_rport(vha, fcport); 5774 5775 if (NVME_TARGET(vha->hw, fcport)) { 5776 qla_nvme_register_remote(vha, fcport); 5777 qla2x00_set_fcport_disc_state(fcport, DSC_LOGIN_COMPLETE); 5778 qla2x00_set_fcport_state(fcport, FCS_ONLINE); 5779 return; 5780 } 5781 5782 qla24xx_update_fcport_fcp_prio(vha, fcport); 5783 5784 switch (vha->host->active_mode) { 5785 case MODE_INITIATOR: 5786 qla2x00_reg_remote_port(vha, fcport); 5787 break; 5788 case MODE_TARGET: 5789 if (!vha->vha_tgt.qla_tgt->tgt_stop && 5790 !vha->vha_tgt.qla_tgt->tgt_stopped) 5791 qlt_fc_port_added(vha, fcport); 5792 break; 5793 case MODE_DUAL: 5794 qla2x00_reg_remote_port(vha, fcport); 5795 if (!vha->vha_tgt.qla_tgt->tgt_stop && 5796 !vha->vha_tgt.qla_tgt->tgt_stopped) 5797 qlt_fc_port_added(vha, fcport); 5798 break; 5799 default: 5800 break; 5801 } 5802 5803 qla2x00_set_fcport_state(fcport, FCS_ONLINE); 5804 5805 if (IS_IIDMA_CAPABLE(vha->hw) && vha->hw->flags.gpsc_supported) { 5806 if (fcport->id_changed) { 5807 fcport->id_changed = 0; 5808 ql_dbg(ql_dbg_disc, vha, 0x20d7, 5809 "%s %d %8phC post gfpnid fcp_cnt %d\n", 5810 __func__, __LINE__, fcport->port_name, 5811 vha->fcport_count); 5812 qla24xx_post_gfpnid_work(vha, fcport); 5813 } else { 5814 ql_dbg(ql_dbg_disc, vha, 0x20d7, 5815 "%s %d %8phC post gpsc fcp_cnt %d\n", 5816 __func__, __LINE__, fcport->port_name, 5817 vha->fcport_count); 5818 qla24xx_post_gpsc_work(vha, fcport); 5819 } 5820 } 5821 5822 qla2x00_set_fcport_disc_state(fcport, DSC_LOGIN_COMPLETE); 5823 } 5824 5825 void qla_register_fcport_fn(struct work_struct *work) 5826 { 5827 fc_port_t *fcport = container_of(work, struct fc_port, reg_work); 5828 u32 rscn_gen = fcport->rscn_gen; 5829 u16 data[2]; 5830 5831 if (IS_SW_RESV_ADDR(fcport->d_id)) 5832 return; 5833 5834 qla2x00_update_fcport(fcport->vha, fcport); 5835 5836 if (rscn_gen != fcport->rscn_gen) { 5837 /* RSCN(s) came in while registration */ 5838 switch (fcport->next_disc_state) { 5839 case DSC_DELETE_PEND: 5840 qlt_schedule_sess_for_deletion(fcport); 5841 break; 5842 case DSC_ADISC: 5843 data[0] = data[1] = 0; 5844 qla2x00_post_async_adisc_work(fcport->vha, fcport, 5845 data); 5846 break; 5847 default: 5848 break; 5849 } 5850 } 5851 } 5852 5853 /* 5854 * qla2x00_configure_fabric 5855 * Setup SNS devices with loop ID's. 5856 * 5857 * Input: 5858 * ha = adapter block pointer. 5859 * 5860 * Returns: 5861 * 0 = success. 5862 * BIT_0 = error 5863 */ 5864 static int 5865 qla2x00_configure_fabric(scsi_qla_host_t *vha) 5866 { 5867 int rval; 5868 fc_port_t *fcport; 5869 uint16_t mb[MAILBOX_REGISTER_COUNT]; 5870 uint16_t loop_id; 5871 LIST_HEAD(new_fcports); 5872 struct qla_hw_data *ha = vha->hw; 5873 int discovery_gen; 5874 5875 /* If FL port exists, then SNS is present */ 5876 if (IS_FWI2_CAPABLE(ha)) 5877 loop_id = NPH_F_PORT; 5878 else 5879 loop_id = SNS_FL_PORT; 5880 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1); 5881 if (rval != QLA_SUCCESS) { 5882 ql_dbg(ql_dbg_disc, vha, 0x20a0, 5883 "MBX_GET_PORT_NAME failed, No FL Port.\n"); 5884 5885 vha->device_flags &= ~SWITCH_FOUND; 5886 return (QLA_SUCCESS); 5887 } 5888 vha->device_flags |= SWITCH_FOUND; 5889 5890 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_port_name, 0); 5891 if (rval != QLA_SUCCESS) 5892 ql_dbg(ql_dbg_disc, vha, 0x20ff, 5893 "Failed to get Fabric Port Name\n"); 5894 5895 if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) { 5896 rval = qla2x00_send_change_request(vha, 0x3, 0); 5897 if (rval != QLA_SUCCESS) 5898 ql_log(ql_log_warn, vha, 0x121, 5899 "Failed to enable receiving of RSCN requests: 0x%x.\n", 5900 rval); 5901 } 5902 5903 do { 5904 qla2x00_mgmt_svr_login(vha); 5905 5906 /* Ensure we are logged into the SNS. */ 5907 loop_id = NPH_SNS_LID(ha); 5908 rval = ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff, 5909 0xfc, mb, BIT_1|BIT_0); 5910 if (rval != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) { 5911 ql_dbg(ql_dbg_disc, vha, 0x20a1, 5912 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x mb[6]=%x mb[7]=%x (%x).\n", 5913 loop_id, mb[0], mb[1], mb[2], mb[6], mb[7], rval); 5914 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); 5915 return rval; 5916 } 5917 5918 /* FDMI support. */ 5919 if (ql2xfdmienable && 5920 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags)) 5921 qla2x00_fdmi_register(vha); 5922 5923 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) { 5924 if (qla2x00_rft_id(vha)) { 5925 /* EMPTY */ 5926 ql_dbg(ql_dbg_disc, vha, 0x20a2, 5927 "Register FC-4 TYPE failed.\n"); 5928 if (test_bit(LOOP_RESYNC_NEEDED, 5929 &vha->dpc_flags)) 5930 break; 5931 } 5932 if (qla2x00_rff_id(vha, FC4_TYPE_FCP_SCSI)) { 5933 /* EMPTY */ 5934 ql_dbg(ql_dbg_disc, vha, 0x209a, 5935 "Register FC-4 Features failed.\n"); 5936 if (test_bit(LOOP_RESYNC_NEEDED, 5937 &vha->dpc_flags)) 5938 break; 5939 } 5940 if (vha->flags.nvme_enabled) { 5941 if (qla2x00_rff_id(vha, FC_TYPE_NVME)) { 5942 ql_dbg(ql_dbg_disc, vha, 0x2049, 5943 "Register NVME FC Type Features failed.\n"); 5944 } 5945 } 5946 if (qla2x00_rnn_id(vha)) { 5947 /* EMPTY */ 5948 ql_dbg(ql_dbg_disc, vha, 0x2104, 5949 "Register Node Name failed.\n"); 5950 if (test_bit(LOOP_RESYNC_NEEDED, 5951 &vha->dpc_flags)) 5952 break; 5953 } else if (qla2x00_rsnn_nn(vha)) { 5954 /* EMPTY */ 5955 ql_dbg(ql_dbg_disc, vha, 0x209b, 5956 "Register Symbolic Node Name failed.\n"); 5957 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) 5958 break; 5959 } 5960 } 5961 5962 5963 /* Mark the time right before querying FW for connected ports. 5964 * This process is long, asynchronous and by the time it's done, 5965 * collected information might not be accurate anymore. E.g. 5966 * disconnected port might have re-connected and a brand new 5967 * session has been created. In this case session's generation 5968 * will be newer than discovery_gen. */ 5969 qlt_do_generation_tick(vha, &discovery_gen); 5970 5971 if (USE_ASYNC_SCAN(ha)) { 5972 rval = qla24xx_async_gpnft(vha, FC4_TYPE_FCP_SCSI, 5973 NULL); 5974 if (rval) 5975 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); 5976 } else { 5977 list_for_each_entry(fcport, &vha->vp_fcports, list) 5978 fcport->scan_state = QLA_FCPORT_SCAN; 5979 5980 rval = qla2x00_find_all_fabric_devs(vha); 5981 } 5982 if (rval != QLA_SUCCESS) 5983 break; 5984 } while (0); 5985 5986 if (!vha->nvme_local_port && vha->flags.nvme_enabled) 5987 qla_nvme_register_hba(vha); 5988 5989 if (rval) 5990 ql_dbg(ql_dbg_disc, vha, 0x2068, 5991 "Configure fabric error exit rval=%d.\n", rval); 5992 5993 return (rval); 5994 } 5995 5996 /* 5997 * qla2x00_find_all_fabric_devs 5998 * 5999 * Input: 6000 * ha = adapter block pointer. 6001 * dev = database device entry pointer. 6002 * 6003 * Returns: 6004 * 0 = success. 6005 * 6006 * Context: 6007 * Kernel context. 6008 */ 6009 static int 6010 qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha) 6011 { 6012 int rval; 6013 uint16_t loop_id; 6014 fc_port_t *fcport, *new_fcport; 6015 int found; 6016 6017 sw_info_t *swl; 6018 int swl_idx; 6019 int first_dev, last_dev; 6020 port_id_t wrap = {}, nxt_d_id; 6021 struct qla_hw_data *ha = vha->hw; 6022 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev); 6023 unsigned long flags; 6024 6025 rval = QLA_SUCCESS; 6026 6027 /* Try GID_PT to get device list, else GAN. */ 6028 if (!ha->swl) 6029 ha->swl = kcalloc(ha->max_fibre_devices, sizeof(sw_info_t), 6030 GFP_KERNEL); 6031 swl = ha->swl; 6032 if (!swl) { 6033 /*EMPTY*/ 6034 ql_dbg(ql_dbg_disc, vha, 0x209c, 6035 "GID_PT allocations failed, fallback on GA_NXT.\n"); 6036 } else { 6037 memset(swl, 0, ha->max_fibre_devices * sizeof(sw_info_t)); 6038 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) { 6039 swl = NULL; 6040 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) 6041 return rval; 6042 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) { 6043 swl = NULL; 6044 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) 6045 return rval; 6046 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) { 6047 swl = NULL; 6048 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) 6049 return rval; 6050 } else if (qla2x00_gfpn_id(vha, swl) != QLA_SUCCESS) { 6051 swl = NULL; 6052 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) 6053 return rval; 6054 } 6055 6056 /* If other queries succeeded probe for FC-4 type */ 6057 if (swl) { 6058 qla2x00_gff_id(vha, swl); 6059 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) 6060 return rval; 6061 } 6062 } 6063 swl_idx = 0; 6064 6065 /* Allocate temporary fcport for any new fcports discovered. */ 6066 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); 6067 if (new_fcport == NULL) { 6068 ql_log(ql_log_warn, vha, 0x209d, 6069 "Failed to allocate memory for fcport.\n"); 6070 return (QLA_MEMORY_ALLOC_FAILED); 6071 } 6072 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED); 6073 /* Set start port ID scan at adapter ID. */ 6074 first_dev = 1; 6075 last_dev = 0; 6076 6077 /* Starting free loop ID. */ 6078 loop_id = ha->min_external_loopid; 6079 for (; loop_id <= ha->max_loop_id; loop_id++) { 6080 if (qla2x00_is_reserved_id(vha, loop_id)) 6081 continue; 6082 6083 if (ha->current_topology == ISP_CFG_FL && 6084 (atomic_read(&vha->loop_down_timer) || 6085 LOOP_TRANSITION(vha))) { 6086 atomic_set(&vha->loop_down_timer, 0); 6087 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); 6088 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); 6089 break; 6090 } 6091 6092 if (swl != NULL) { 6093 if (last_dev) { 6094 wrap.b24 = new_fcport->d_id.b24; 6095 } else { 6096 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24; 6097 memcpy(new_fcport->node_name, 6098 swl[swl_idx].node_name, WWN_SIZE); 6099 memcpy(new_fcport->port_name, 6100 swl[swl_idx].port_name, WWN_SIZE); 6101 memcpy(new_fcport->fabric_port_name, 6102 swl[swl_idx].fabric_port_name, WWN_SIZE); 6103 new_fcport->fp_speed = swl[swl_idx].fp_speed; 6104 new_fcport->fc4_type = swl[swl_idx].fc4_type; 6105 6106 new_fcport->nvme_flag = 0; 6107 if (vha->flags.nvme_enabled && 6108 swl[swl_idx].fc4_type & FS_FC4TYPE_NVME) { 6109 ql_log(ql_log_info, vha, 0x2131, 6110 "FOUND: NVME port %8phC as FC Type 28h\n", 6111 new_fcport->port_name); 6112 } 6113 6114 if (swl[swl_idx].d_id.b.rsvd_1 != 0) { 6115 last_dev = 1; 6116 } 6117 swl_idx++; 6118 } 6119 } else { 6120 /* Send GA_NXT to the switch */ 6121 rval = qla2x00_ga_nxt(vha, new_fcport); 6122 if (rval != QLA_SUCCESS) { 6123 ql_log(ql_log_warn, vha, 0x209e, 6124 "SNS scan failed -- assuming " 6125 "zero-entry result.\n"); 6126 rval = QLA_SUCCESS; 6127 break; 6128 } 6129 } 6130 6131 /* If wrap on switch device list, exit. */ 6132 if (first_dev) { 6133 wrap.b24 = new_fcport->d_id.b24; 6134 first_dev = 0; 6135 } else if (new_fcport->d_id.b24 == wrap.b24) { 6136 ql_dbg(ql_dbg_disc, vha, 0x209f, 6137 "Device wrap (%02x%02x%02x).\n", 6138 new_fcport->d_id.b.domain, 6139 new_fcport->d_id.b.area, 6140 new_fcport->d_id.b.al_pa); 6141 break; 6142 } 6143 6144 /* Bypass if same physical adapter. */ 6145 if (new_fcport->d_id.b24 == base_vha->d_id.b24) 6146 continue; 6147 6148 /* Bypass virtual ports of the same host. */ 6149 if (qla2x00_is_a_vp_did(vha, new_fcport->d_id.b24)) 6150 continue; 6151 6152 /* Bypass if same domain and area of adapter. */ 6153 if (((new_fcport->d_id.b24 & 0xffff00) == 6154 (vha->d_id.b24 & 0xffff00)) && ha->current_topology == 6155 ISP_CFG_FL) 6156 continue; 6157 6158 /* Bypass reserved domain fields. */ 6159 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0) 6160 continue; 6161 6162 /* Bypass ports whose FCP-4 type is not FCP_SCSI */ 6163 if (ql2xgffidenable && 6164 (!(new_fcport->fc4_type & FS_FC4TYPE_FCP) && 6165 new_fcport->fc4_type != 0)) 6166 continue; 6167 6168 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); 6169 6170 /* Locate matching device in database. */ 6171 found = 0; 6172 list_for_each_entry(fcport, &vha->vp_fcports, list) { 6173 if (memcmp(new_fcport->port_name, fcport->port_name, 6174 WWN_SIZE)) 6175 continue; 6176 6177 fcport->scan_state = QLA_FCPORT_FOUND; 6178 6179 found++; 6180 6181 /* Update port state. */ 6182 memcpy(fcport->fabric_port_name, 6183 new_fcport->fabric_port_name, WWN_SIZE); 6184 fcport->fp_speed = new_fcport->fp_speed; 6185 6186 /* 6187 * If address the same and state FCS_ONLINE 6188 * (or in target mode), nothing changed. 6189 */ 6190 if (fcport->d_id.b24 == new_fcport->d_id.b24 && 6191 (atomic_read(&fcport->state) == FCS_ONLINE || 6192 (vha->host->active_mode == MODE_TARGET))) { 6193 break; 6194 } 6195 6196 if (fcport->login_retry == 0) 6197 fcport->login_retry = 6198 vha->hw->login_retry_count; 6199 /* 6200 * If device was not a fabric device before. 6201 */ 6202 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) { 6203 fcport->d_id.b24 = new_fcport->d_id.b24; 6204 qla2x00_clear_loop_id(fcport); 6205 fcport->flags |= (FCF_FABRIC_DEVICE | 6206 FCF_LOGIN_NEEDED); 6207 break; 6208 } 6209 6210 /* 6211 * Port ID changed or device was marked to be updated; 6212 * Log it out if still logged in and mark it for 6213 * relogin later. 6214 */ 6215 if (qla_tgt_mode_enabled(base_vha)) { 6216 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf080, 6217 "port changed FC ID, %8phC" 6218 " old %x:%x:%x (loop_id 0x%04x)-> new %x:%x:%x\n", 6219 fcport->port_name, 6220 fcport->d_id.b.domain, 6221 fcport->d_id.b.area, 6222 fcport->d_id.b.al_pa, 6223 fcport->loop_id, 6224 new_fcport->d_id.b.domain, 6225 new_fcport->d_id.b.area, 6226 new_fcport->d_id.b.al_pa); 6227 fcport->d_id.b24 = new_fcport->d_id.b24; 6228 break; 6229 } 6230 6231 fcport->d_id.b24 = new_fcport->d_id.b24; 6232 fcport->flags |= FCF_LOGIN_NEEDED; 6233 break; 6234 } 6235 6236 if (found && NVME_TARGET(vha->hw, fcport)) { 6237 if (fcport->disc_state == DSC_DELETE_PEND) { 6238 qla2x00_set_fcport_disc_state(fcport, DSC_GNL); 6239 vha->fcport_count--; 6240 fcport->login_succ = 0; 6241 } 6242 } 6243 6244 if (found) { 6245 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); 6246 continue; 6247 } 6248 /* If device was not in our fcports list, then add it. */ 6249 new_fcport->scan_state = QLA_FCPORT_FOUND; 6250 list_add_tail(&new_fcport->list, &vha->vp_fcports); 6251 6252 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); 6253 6254 6255 /* Allocate a new replacement fcport. */ 6256 nxt_d_id.b24 = new_fcport->d_id.b24; 6257 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); 6258 if (new_fcport == NULL) { 6259 ql_log(ql_log_warn, vha, 0xd032, 6260 "Memory allocation failed for fcport.\n"); 6261 return (QLA_MEMORY_ALLOC_FAILED); 6262 } 6263 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED); 6264 new_fcport->d_id.b24 = nxt_d_id.b24; 6265 } 6266 6267 qla2x00_free_fcport(new_fcport); 6268 6269 /* 6270 * Logout all previous fabric dev marked lost, except FCP2 devices. 6271 */ 6272 list_for_each_entry(fcport, &vha->vp_fcports, list) { 6273 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) 6274 break; 6275 6276 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) 6277 continue; 6278 6279 if (fcport->scan_state == QLA_FCPORT_SCAN) { 6280 if ((qla_dual_mode_enabled(vha) || 6281 qla_ini_mode_enabled(vha)) && 6282 atomic_read(&fcport->state) == FCS_ONLINE) { 6283 qla2x00_mark_device_lost(vha, fcport, 6284 ql2xplogiabsentdevice); 6285 if (fcport->loop_id != FC_NO_LOOP_ID && 6286 (fcport->flags & FCF_FCP2_DEVICE) == 0 && 6287 fcport->port_type != FCT_INITIATOR && 6288 fcport->port_type != FCT_BROADCAST) { 6289 ql_dbg(ql_dbg_disc, vha, 0x20f0, 6290 "%s %d %8phC post del sess\n", 6291 __func__, __LINE__, 6292 fcport->port_name); 6293 qlt_schedule_sess_for_deletion(fcport); 6294 continue; 6295 } 6296 } 6297 } 6298 6299 if (fcport->scan_state == QLA_FCPORT_FOUND && 6300 (fcport->flags & FCF_LOGIN_NEEDED) != 0) 6301 qla24xx_fcport_handle_login(vha, fcport); 6302 } 6303 return (rval); 6304 } 6305 6306 /* FW does not set aside Loop id for MGMT Server/FFFFFAh */ 6307 int 6308 qla2x00_reserve_mgmt_server_loop_id(scsi_qla_host_t *vha) 6309 { 6310 int loop_id = FC_NO_LOOP_ID; 6311 int lid = NPH_MGMT_SERVER - vha->vp_idx; 6312 unsigned long flags; 6313 struct qla_hw_data *ha = vha->hw; 6314 6315 if (vha->vp_idx == 0) { 6316 set_bit(NPH_MGMT_SERVER, ha->loop_id_map); 6317 return NPH_MGMT_SERVER; 6318 } 6319 6320 /* pick id from high and work down to low */ 6321 spin_lock_irqsave(&ha->vport_slock, flags); 6322 for (; lid > 0; lid--) { 6323 if (!test_bit(lid, vha->hw->loop_id_map)) { 6324 set_bit(lid, vha->hw->loop_id_map); 6325 loop_id = lid; 6326 break; 6327 } 6328 } 6329 spin_unlock_irqrestore(&ha->vport_slock, flags); 6330 6331 return loop_id; 6332 } 6333 6334 /* 6335 * qla2x00_fabric_login 6336 * Issue fabric login command. 6337 * 6338 * Input: 6339 * ha = adapter block pointer. 6340 * device = pointer to FC device type structure. 6341 * 6342 * Returns: 6343 * 0 - Login successfully 6344 * 1 - Login failed 6345 * 2 - Initiator device 6346 * 3 - Fatal error 6347 */ 6348 int 6349 qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport, 6350 uint16_t *next_loopid) 6351 { 6352 int rval; 6353 int retry; 6354 uint16_t tmp_loopid; 6355 uint16_t mb[MAILBOX_REGISTER_COUNT]; 6356 struct qla_hw_data *ha = vha->hw; 6357 6358 retry = 0; 6359 tmp_loopid = 0; 6360 6361 for (;;) { 6362 ql_dbg(ql_dbg_disc, vha, 0x2000, 6363 "Trying Fabric Login w/loop id 0x%04x for port " 6364 "%02x%02x%02x.\n", 6365 fcport->loop_id, fcport->d_id.b.domain, 6366 fcport->d_id.b.area, fcport->d_id.b.al_pa); 6367 6368 /* Login fcport on switch. */ 6369 rval = ha->isp_ops->fabric_login(vha, fcport->loop_id, 6370 fcport->d_id.b.domain, fcport->d_id.b.area, 6371 fcport->d_id.b.al_pa, mb, BIT_0); 6372 if (rval != QLA_SUCCESS) { 6373 return rval; 6374 } 6375 if (mb[0] == MBS_PORT_ID_USED) { 6376 /* 6377 * Device has another loop ID. The firmware team 6378 * recommends the driver perform an implicit login with 6379 * the specified ID again. The ID we just used is save 6380 * here so we return with an ID that can be tried by 6381 * the next login. 6382 */ 6383 retry++; 6384 tmp_loopid = fcport->loop_id; 6385 fcport->loop_id = mb[1]; 6386 6387 ql_dbg(ql_dbg_disc, vha, 0x2001, 6388 "Fabric Login: port in use - next loop " 6389 "id=0x%04x, port id= %02x%02x%02x.\n", 6390 fcport->loop_id, fcport->d_id.b.domain, 6391 fcport->d_id.b.area, fcport->d_id.b.al_pa); 6392 6393 } else if (mb[0] == MBS_COMMAND_COMPLETE) { 6394 /* 6395 * Login succeeded. 6396 */ 6397 if (retry) { 6398 /* A retry occurred before. */ 6399 *next_loopid = tmp_loopid; 6400 } else { 6401 /* 6402 * No retry occurred before. Just increment the 6403 * ID value for next login. 6404 */ 6405 *next_loopid = (fcport->loop_id + 1); 6406 } 6407 6408 if (mb[1] & BIT_0) { 6409 fcport->port_type = FCT_INITIATOR; 6410 } else { 6411 fcport->port_type = FCT_TARGET; 6412 if (mb[1] & BIT_1) { 6413 fcport->flags |= FCF_FCP2_DEVICE; 6414 } 6415 } 6416 6417 if (mb[10] & BIT_0) 6418 fcport->supported_classes |= FC_COS_CLASS2; 6419 if (mb[10] & BIT_1) 6420 fcport->supported_classes |= FC_COS_CLASS3; 6421 6422 if (IS_FWI2_CAPABLE(ha)) { 6423 if (mb[10] & BIT_7) 6424 fcport->flags |= 6425 FCF_CONF_COMP_SUPPORTED; 6426 } 6427 6428 rval = QLA_SUCCESS; 6429 break; 6430 } else if (mb[0] == MBS_LOOP_ID_USED) { 6431 /* 6432 * Loop ID already used, try next loop ID. 6433 */ 6434 fcport->loop_id++; 6435 rval = qla2x00_find_new_loop_id(vha, fcport); 6436 if (rval != QLA_SUCCESS) { 6437 /* Ran out of loop IDs to use */ 6438 break; 6439 } 6440 } else if (mb[0] == MBS_COMMAND_ERROR) { 6441 /* 6442 * Firmware possibly timed out during login. If NO 6443 * retries are left to do then the device is declared 6444 * dead. 6445 */ 6446 *next_loopid = fcport->loop_id; 6447 ha->isp_ops->fabric_logout(vha, fcport->loop_id, 6448 fcport->d_id.b.domain, fcport->d_id.b.area, 6449 fcport->d_id.b.al_pa); 6450 qla2x00_mark_device_lost(vha, fcport, 1); 6451 6452 rval = 1; 6453 break; 6454 } else { 6455 /* 6456 * unrecoverable / not handled error 6457 */ 6458 ql_dbg(ql_dbg_disc, vha, 0x2002, 6459 "Failed=%x port_id=%02x%02x%02x loop_id=%x " 6460 "jiffies=%lx.\n", mb[0], fcport->d_id.b.domain, 6461 fcport->d_id.b.area, fcport->d_id.b.al_pa, 6462 fcport->loop_id, jiffies); 6463 6464 *next_loopid = fcport->loop_id; 6465 ha->isp_ops->fabric_logout(vha, fcport->loop_id, 6466 fcport->d_id.b.domain, fcport->d_id.b.area, 6467 fcport->d_id.b.al_pa); 6468 qla2x00_clear_loop_id(fcport); 6469 fcport->login_retry = 0; 6470 6471 rval = 3; 6472 break; 6473 } 6474 } 6475 6476 return (rval); 6477 } 6478 6479 /* 6480 * qla2x00_local_device_login 6481 * Issue local device login command. 6482 * 6483 * Input: 6484 * ha = adapter block pointer. 6485 * loop_id = loop id of device to login to. 6486 * 6487 * Returns (Where's the #define!!!!): 6488 * 0 - Login successfully 6489 * 1 - Login failed 6490 * 3 - Fatal error 6491 */ 6492 int 6493 qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport) 6494 { 6495 int rval; 6496 uint16_t mb[MAILBOX_REGISTER_COUNT]; 6497 6498 memset(mb, 0, sizeof(mb)); 6499 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0); 6500 if (rval == QLA_SUCCESS) { 6501 /* Interrogate mailbox registers for any errors */ 6502 if (mb[0] == MBS_COMMAND_ERROR) 6503 rval = 1; 6504 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR) 6505 /* device not in PCB table */ 6506 rval = 3; 6507 } 6508 6509 return (rval); 6510 } 6511 6512 /* 6513 * qla2x00_loop_resync 6514 * Resync with fibre channel devices. 6515 * 6516 * Input: 6517 * ha = adapter block pointer. 6518 * 6519 * Returns: 6520 * 0 = success 6521 */ 6522 int 6523 qla2x00_loop_resync(scsi_qla_host_t *vha) 6524 { 6525 int rval = QLA_SUCCESS; 6526 uint32_t wait_time; 6527 6528 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags); 6529 if (vha->flags.online) { 6530 if (!(rval = qla2x00_fw_ready(vha))) { 6531 /* Wait at most MAX_TARGET RSCNs for a stable link. */ 6532 wait_time = 256; 6533 do { 6534 if (!IS_QLAFX00(vha->hw)) { 6535 /* 6536 * Issue a marker after FW becomes 6537 * ready. 6538 */ 6539 qla2x00_marker(vha, vha->hw->base_qpair, 6540 0, 0, MK_SYNC_ALL); 6541 vha->marker_needed = 0; 6542 } 6543 6544 /* Remap devices on Loop. */ 6545 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); 6546 6547 if (IS_QLAFX00(vha->hw)) 6548 qlafx00_configure_devices(vha); 6549 else 6550 qla2x00_configure_loop(vha); 6551 6552 wait_time--; 6553 } while (!atomic_read(&vha->loop_down_timer) && 6554 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) 6555 && wait_time && (test_bit(LOOP_RESYNC_NEEDED, 6556 &vha->dpc_flags))); 6557 } 6558 } 6559 6560 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) 6561 return (QLA_FUNCTION_FAILED); 6562 6563 if (rval) 6564 ql_dbg(ql_dbg_disc, vha, 0x206c, 6565 "%s *** FAILED ***.\n", __func__); 6566 6567 return (rval); 6568 } 6569 6570 /* 6571 * qla2x00_perform_loop_resync 6572 * Description: This function will set the appropriate flags and call 6573 * qla2x00_loop_resync. If successful loop will be resynced 6574 * Arguments : scsi_qla_host_t pointer 6575 * returm : Success or Failure 6576 */ 6577 6578 int qla2x00_perform_loop_resync(scsi_qla_host_t *ha) 6579 { 6580 int32_t rval = 0; 6581 6582 if (!test_and_set_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags)) { 6583 /*Configure the flags so that resync happens properly*/ 6584 atomic_set(&ha->loop_down_timer, 0); 6585 if (!(ha->device_flags & DFLG_NO_CABLE)) { 6586 atomic_set(&ha->loop_state, LOOP_UP); 6587 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags); 6588 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags); 6589 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags); 6590 6591 rval = qla2x00_loop_resync(ha); 6592 } else 6593 atomic_set(&ha->loop_state, LOOP_DEAD); 6594 6595 clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags); 6596 } 6597 6598 return rval; 6599 } 6600 6601 void 6602 qla2x00_update_fcports(scsi_qla_host_t *base_vha) 6603 { 6604 fc_port_t *fcport; 6605 struct scsi_qla_host *vha, *tvp; 6606 struct qla_hw_data *ha = base_vha->hw; 6607 unsigned long flags; 6608 6609 spin_lock_irqsave(&ha->vport_slock, flags); 6610 /* Go with deferred removal of rport references. */ 6611 list_for_each_entry_safe(vha, tvp, &base_vha->hw->vp_list, list) { 6612 atomic_inc(&vha->vref_count); 6613 list_for_each_entry(fcport, &vha->vp_fcports, list) { 6614 if (fcport->drport && 6615 atomic_read(&fcport->state) != FCS_UNCONFIGURED) { 6616 spin_unlock_irqrestore(&ha->vport_slock, flags); 6617 qla2x00_rport_del(fcport); 6618 6619 spin_lock_irqsave(&ha->vport_slock, flags); 6620 } 6621 } 6622 atomic_dec(&vha->vref_count); 6623 wake_up(&vha->vref_waitq); 6624 } 6625 spin_unlock_irqrestore(&ha->vport_slock, flags); 6626 } 6627 6628 /* Assumes idc_lock always held on entry */ 6629 void 6630 qla83xx_reset_ownership(scsi_qla_host_t *vha) 6631 { 6632 struct qla_hw_data *ha = vha->hw; 6633 uint32_t drv_presence, drv_presence_mask; 6634 uint32_t dev_part_info1, dev_part_info2, class_type; 6635 uint32_t class_type_mask = 0x3; 6636 uint16_t fcoe_other_function = 0xffff, i; 6637 6638 if (IS_QLA8044(ha)) { 6639 drv_presence = qla8044_rd_direct(vha, 6640 QLA8044_CRB_DRV_ACTIVE_INDEX); 6641 dev_part_info1 = qla8044_rd_direct(vha, 6642 QLA8044_CRB_DEV_PART_INFO_INDEX); 6643 dev_part_info2 = qla8044_rd_direct(vha, 6644 QLA8044_CRB_DEV_PART_INFO2); 6645 } else { 6646 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence); 6647 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO1, &dev_part_info1); 6648 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO2, &dev_part_info2); 6649 } 6650 for (i = 0; i < 8; i++) { 6651 class_type = ((dev_part_info1 >> (i * 4)) & class_type_mask); 6652 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) && 6653 (i != ha->portnum)) { 6654 fcoe_other_function = i; 6655 break; 6656 } 6657 } 6658 if (fcoe_other_function == 0xffff) { 6659 for (i = 0; i < 8; i++) { 6660 class_type = ((dev_part_info2 >> (i * 4)) & 6661 class_type_mask); 6662 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) && 6663 ((i + 8) != ha->portnum)) { 6664 fcoe_other_function = i + 8; 6665 break; 6666 } 6667 } 6668 } 6669 /* 6670 * Prepare drv-presence mask based on fcoe functions present. 6671 * However consider only valid physical fcoe function numbers (0-15). 6672 */ 6673 drv_presence_mask = ~((1 << (ha->portnum)) | 6674 ((fcoe_other_function == 0xffff) ? 6675 0 : (1 << (fcoe_other_function)))); 6676 6677 /* We are the reset owner iff: 6678 * - No other protocol drivers present. 6679 * - This is the lowest among fcoe functions. */ 6680 if (!(drv_presence & drv_presence_mask) && 6681 (ha->portnum < fcoe_other_function)) { 6682 ql_dbg(ql_dbg_p3p, vha, 0xb07f, 6683 "This host is Reset owner.\n"); 6684 ha->flags.nic_core_reset_owner = 1; 6685 } 6686 } 6687 6688 static int 6689 __qla83xx_set_drv_ack(scsi_qla_host_t *vha) 6690 { 6691 int rval = QLA_SUCCESS; 6692 struct qla_hw_data *ha = vha->hw; 6693 uint32_t drv_ack; 6694 6695 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack); 6696 if (rval == QLA_SUCCESS) { 6697 drv_ack |= (1 << ha->portnum); 6698 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack); 6699 } 6700 6701 return rval; 6702 } 6703 6704 static int 6705 __qla83xx_clear_drv_ack(scsi_qla_host_t *vha) 6706 { 6707 int rval = QLA_SUCCESS; 6708 struct qla_hw_data *ha = vha->hw; 6709 uint32_t drv_ack; 6710 6711 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack); 6712 if (rval == QLA_SUCCESS) { 6713 drv_ack &= ~(1 << ha->portnum); 6714 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack); 6715 } 6716 6717 return rval; 6718 } 6719 6720 static const char * 6721 qla83xx_dev_state_to_string(uint32_t dev_state) 6722 { 6723 switch (dev_state) { 6724 case QLA8XXX_DEV_COLD: 6725 return "COLD/RE-INIT"; 6726 case QLA8XXX_DEV_INITIALIZING: 6727 return "INITIALIZING"; 6728 case QLA8XXX_DEV_READY: 6729 return "READY"; 6730 case QLA8XXX_DEV_NEED_RESET: 6731 return "NEED RESET"; 6732 case QLA8XXX_DEV_NEED_QUIESCENT: 6733 return "NEED QUIESCENT"; 6734 case QLA8XXX_DEV_FAILED: 6735 return "FAILED"; 6736 case QLA8XXX_DEV_QUIESCENT: 6737 return "QUIESCENT"; 6738 default: 6739 return "Unknown"; 6740 } 6741 } 6742 6743 /* Assumes idc-lock always held on entry */ 6744 void 6745 qla83xx_idc_audit(scsi_qla_host_t *vha, int audit_type) 6746 { 6747 struct qla_hw_data *ha = vha->hw; 6748 uint32_t idc_audit_reg = 0, duration_secs = 0; 6749 6750 switch (audit_type) { 6751 case IDC_AUDIT_TIMESTAMP: 6752 ha->idc_audit_ts = (jiffies_to_msecs(jiffies) / 1000); 6753 idc_audit_reg = (ha->portnum) | 6754 (IDC_AUDIT_TIMESTAMP << 7) | (ha->idc_audit_ts << 8); 6755 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg); 6756 break; 6757 6758 case IDC_AUDIT_COMPLETION: 6759 duration_secs = ((jiffies_to_msecs(jiffies) - 6760 jiffies_to_msecs(ha->idc_audit_ts)) / 1000); 6761 idc_audit_reg = (ha->portnum) | 6762 (IDC_AUDIT_COMPLETION << 7) | (duration_secs << 8); 6763 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg); 6764 break; 6765 6766 default: 6767 ql_log(ql_log_warn, vha, 0xb078, 6768 "Invalid audit type specified.\n"); 6769 break; 6770 } 6771 } 6772 6773 /* Assumes idc_lock always held on entry */ 6774 static int 6775 qla83xx_initiating_reset(scsi_qla_host_t *vha) 6776 { 6777 struct qla_hw_data *ha = vha->hw; 6778 uint32_t idc_control, dev_state; 6779 6780 __qla83xx_get_idc_control(vha, &idc_control); 6781 if ((idc_control & QLA83XX_IDC_RESET_DISABLED)) { 6782 ql_log(ql_log_info, vha, 0xb080, 6783 "NIC Core reset has been disabled. idc-control=0x%x\n", 6784 idc_control); 6785 return QLA_FUNCTION_FAILED; 6786 } 6787 6788 /* Set NEED-RESET iff in READY state and we are the reset-owner */ 6789 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state); 6790 if (ha->flags.nic_core_reset_owner && dev_state == QLA8XXX_DEV_READY) { 6791 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, 6792 QLA8XXX_DEV_NEED_RESET); 6793 ql_log(ql_log_info, vha, 0xb056, "HW State: NEED RESET.\n"); 6794 qla83xx_idc_audit(vha, IDC_AUDIT_TIMESTAMP); 6795 } else { 6796 const char *state = qla83xx_dev_state_to_string(dev_state); 6797 6798 ql_log(ql_log_info, vha, 0xb057, "HW State: %s.\n", state); 6799 6800 /* SV: XXX: Is timeout required here? */ 6801 /* Wait for IDC state change READY -> NEED_RESET */ 6802 while (dev_state == QLA8XXX_DEV_READY) { 6803 qla83xx_idc_unlock(vha, 0); 6804 msleep(200); 6805 qla83xx_idc_lock(vha, 0); 6806 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state); 6807 } 6808 } 6809 6810 /* Send IDC ack by writing to drv-ack register */ 6811 __qla83xx_set_drv_ack(vha); 6812 6813 return QLA_SUCCESS; 6814 } 6815 6816 int 6817 __qla83xx_set_idc_control(scsi_qla_host_t *vha, uint32_t idc_control) 6818 { 6819 return qla83xx_wr_reg(vha, QLA83XX_IDC_CONTROL, idc_control); 6820 } 6821 6822 int 6823 __qla83xx_get_idc_control(scsi_qla_host_t *vha, uint32_t *idc_control) 6824 { 6825 return qla83xx_rd_reg(vha, QLA83XX_IDC_CONTROL, idc_control); 6826 } 6827 6828 static int 6829 qla83xx_check_driver_presence(scsi_qla_host_t *vha) 6830 { 6831 uint32_t drv_presence = 0; 6832 struct qla_hw_data *ha = vha->hw; 6833 6834 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence); 6835 if (drv_presence & (1 << ha->portnum)) 6836 return QLA_SUCCESS; 6837 else 6838 return QLA_TEST_FAILED; 6839 } 6840 6841 int 6842 qla83xx_nic_core_reset(scsi_qla_host_t *vha) 6843 { 6844 int rval = QLA_SUCCESS; 6845 struct qla_hw_data *ha = vha->hw; 6846 6847 ql_dbg(ql_dbg_p3p, vha, 0xb058, 6848 "Entered %s().\n", __func__); 6849 6850 if (vha->device_flags & DFLG_DEV_FAILED) { 6851 ql_log(ql_log_warn, vha, 0xb059, 6852 "Device in unrecoverable FAILED state.\n"); 6853 return QLA_FUNCTION_FAILED; 6854 } 6855 6856 qla83xx_idc_lock(vha, 0); 6857 6858 if (qla83xx_check_driver_presence(vha) != QLA_SUCCESS) { 6859 ql_log(ql_log_warn, vha, 0xb05a, 6860 "Function=0x%x has been removed from IDC participation.\n", 6861 ha->portnum); 6862 rval = QLA_FUNCTION_FAILED; 6863 goto exit; 6864 } 6865 6866 qla83xx_reset_ownership(vha); 6867 6868 rval = qla83xx_initiating_reset(vha); 6869 6870 /* 6871 * Perform reset if we are the reset-owner, 6872 * else wait till IDC state changes to READY/FAILED. 6873 */ 6874 if (rval == QLA_SUCCESS) { 6875 rval = qla83xx_idc_state_handler(vha); 6876 6877 if (rval == QLA_SUCCESS) 6878 ha->flags.nic_core_hung = 0; 6879 __qla83xx_clear_drv_ack(vha); 6880 } 6881 6882 exit: 6883 qla83xx_idc_unlock(vha, 0); 6884 6885 ql_dbg(ql_dbg_p3p, vha, 0xb05b, "Exiting %s.\n", __func__); 6886 6887 return rval; 6888 } 6889 6890 int 6891 qla2xxx_mctp_dump(scsi_qla_host_t *vha) 6892 { 6893 struct qla_hw_data *ha = vha->hw; 6894 int rval = QLA_FUNCTION_FAILED; 6895 6896 if (!IS_MCTP_CAPABLE(ha)) { 6897 /* This message can be removed from the final version */ 6898 ql_log(ql_log_info, vha, 0x506d, 6899 "This board is not MCTP capable\n"); 6900 return rval; 6901 } 6902 6903 if (!ha->mctp_dump) { 6904 ha->mctp_dump = dma_alloc_coherent(&ha->pdev->dev, 6905 MCTP_DUMP_SIZE, &ha->mctp_dump_dma, GFP_KERNEL); 6906 6907 if (!ha->mctp_dump) { 6908 ql_log(ql_log_warn, vha, 0x506e, 6909 "Failed to allocate memory for mctp dump\n"); 6910 return rval; 6911 } 6912 } 6913 6914 #define MCTP_DUMP_STR_ADDR 0x00000000 6915 rval = qla2x00_dump_mctp_data(vha, ha->mctp_dump_dma, 6916 MCTP_DUMP_STR_ADDR, MCTP_DUMP_SIZE/4); 6917 if (rval != QLA_SUCCESS) { 6918 ql_log(ql_log_warn, vha, 0x506f, 6919 "Failed to capture mctp dump\n"); 6920 } else { 6921 ql_log(ql_log_info, vha, 0x5070, 6922 "Mctp dump capture for host (%ld/%p).\n", 6923 vha->host_no, ha->mctp_dump); 6924 ha->mctp_dumped = 1; 6925 } 6926 6927 if (!ha->flags.nic_core_reset_hdlr_active && !ha->portnum) { 6928 ha->flags.nic_core_reset_hdlr_active = 1; 6929 rval = qla83xx_restart_nic_firmware(vha); 6930 if (rval) 6931 /* NIC Core reset failed. */ 6932 ql_log(ql_log_warn, vha, 0x5071, 6933 "Failed to restart nic firmware\n"); 6934 else 6935 ql_dbg(ql_dbg_p3p, vha, 0xb084, 6936 "Restarted NIC firmware successfully.\n"); 6937 ha->flags.nic_core_reset_hdlr_active = 0; 6938 } 6939 6940 return rval; 6941 6942 } 6943 6944 /* 6945 * qla2x00_quiesce_io 6946 * Description: This function will block the new I/Os 6947 * Its not aborting any I/Os as context 6948 * is not destroyed during quiescence 6949 * Arguments: scsi_qla_host_t 6950 * return : void 6951 */ 6952 void 6953 qla2x00_quiesce_io(scsi_qla_host_t *vha) 6954 { 6955 struct qla_hw_data *ha = vha->hw; 6956 struct scsi_qla_host *vp, *tvp; 6957 unsigned long flags; 6958 6959 ql_dbg(ql_dbg_dpc, vha, 0x401d, 6960 "Quiescing I/O - ha=%p.\n", ha); 6961 6962 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME); 6963 if (atomic_read(&vha->loop_state) != LOOP_DOWN) { 6964 atomic_set(&vha->loop_state, LOOP_DOWN); 6965 qla2x00_mark_all_devices_lost(vha); 6966 6967 spin_lock_irqsave(&ha->vport_slock, flags); 6968 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) { 6969 atomic_inc(&vp->vref_count); 6970 spin_unlock_irqrestore(&ha->vport_slock, flags); 6971 6972 qla2x00_mark_all_devices_lost(vp); 6973 6974 spin_lock_irqsave(&ha->vport_slock, flags); 6975 atomic_dec(&vp->vref_count); 6976 } 6977 spin_unlock_irqrestore(&ha->vport_slock, flags); 6978 } else { 6979 if (!atomic_read(&vha->loop_down_timer)) 6980 atomic_set(&vha->loop_down_timer, 6981 LOOP_DOWN_TIME); 6982 } 6983 /* Wait for pending cmds to complete */ 6984 WARN_ON_ONCE(qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) 6985 != QLA_SUCCESS); 6986 } 6987 6988 void 6989 qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha) 6990 { 6991 struct qla_hw_data *ha = vha->hw; 6992 struct scsi_qla_host *vp, *tvp; 6993 unsigned long flags; 6994 fc_port_t *fcport; 6995 u16 i; 6996 6997 /* For ISP82XX, driver waits for completion of the commands. 6998 * online flag should be set. 6999 */ 7000 if (!(IS_P3P_TYPE(ha))) 7001 vha->flags.online = 0; 7002 ha->flags.chip_reset_done = 0; 7003 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); 7004 vha->qla_stats.total_isp_aborts++; 7005 7006 ql_log(ql_log_info, vha, 0x00af, 7007 "Performing ISP error recovery - ha=%p.\n", ha); 7008 7009 ha->flags.purge_mbox = 1; 7010 /* For ISP82XX, reset_chip is just disabling interrupts. 7011 * Driver waits for the completion of the commands. 7012 * the interrupts need to be enabled. 7013 */ 7014 if (!(IS_P3P_TYPE(ha))) 7015 ha->isp_ops->reset_chip(vha); 7016 7017 ha->link_data_rate = PORT_SPEED_UNKNOWN; 7018 SAVE_TOPO(ha); 7019 ha->flags.rida_fmt2 = 0; 7020 ha->flags.n2n_ae = 0; 7021 ha->flags.lip_ae = 0; 7022 ha->current_topology = 0; 7023 QLA_FW_STOPPED(ha); 7024 ha->flags.fw_init_done = 0; 7025 ha->chip_reset++; 7026 ha->base_qpair->chip_reset = ha->chip_reset; 7027 ha->base_qpair->cmd_cnt = ha->base_qpair->cmd_completion_cnt = 0; 7028 ha->base_qpair->prev_completion_cnt = 0; 7029 for (i = 0; i < ha->max_qpairs; i++) { 7030 if (ha->queue_pair_map[i]) { 7031 ha->queue_pair_map[i]->chip_reset = 7032 ha->base_qpair->chip_reset; 7033 ha->queue_pair_map[i]->cmd_cnt = 7034 ha->queue_pair_map[i]->cmd_completion_cnt = 0; 7035 ha->base_qpair->prev_completion_cnt = 0; 7036 } 7037 } 7038 7039 /* purge MBox commands */ 7040 if (atomic_read(&ha->num_pend_mbx_stage3)) { 7041 clear_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags); 7042 complete(&ha->mbx_intr_comp); 7043 } 7044 7045 i = 0; 7046 while (atomic_read(&ha->num_pend_mbx_stage3) || 7047 atomic_read(&ha->num_pend_mbx_stage2) || 7048 atomic_read(&ha->num_pend_mbx_stage1)) { 7049 msleep(20); 7050 i++; 7051 if (i > 50) 7052 break; 7053 } 7054 ha->flags.purge_mbox = 0; 7055 7056 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME); 7057 if (atomic_read(&vha->loop_state) != LOOP_DOWN) { 7058 atomic_set(&vha->loop_state, LOOP_DOWN); 7059 qla2x00_mark_all_devices_lost(vha); 7060 7061 spin_lock_irqsave(&ha->vport_slock, flags); 7062 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) { 7063 atomic_inc(&vp->vref_count); 7064 spin_unlock_irqrestore(&ha->vport_slock, flags); 7065 7066 qla2x00_mark_all_devices_lost(vp); 7067 7068 spin_lock_irqsave(&ha->vport_slock, flags); 7069 atomic_dec(&vp->vref_count); 7070 } 7071 spin_unlock_irqrestore(&ha->vport_slock, flags); 7072 } else { 7073 if (!atomic_read(&vha->loop_down_timer)) 7074 atomic_set(&vha->loop_down_timer, 7075 LOOP_DOWN_TIME); 7076 } 7077 7078 /* Clear all async request states across all VPs. */ 7079 list_for_each_entry(fcport, &vha->vp_fcports, list) { 7080 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT); 7081 fcport->scan_state = 0; 7082 } 7083 spin_lock_irqsave(&ha->vport_slock, flags); 7084 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) { 7085 atomic_inc(&vp->vref_count); 7086 spin_unlock_irqrestore(&ha->vport_slock, flags); 7087 7088 list_for_each_entry(fcport, &vp->vp_fcports, list) 7089 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT); 7090 7091 spin_lock_irqsave(&ha->vport_slock, flags); 7092 atomic_dec(&vp->vref_count); 7093 } 7094 spin_unlock_irqrestore(&ha->vport_slock, flags); 7095 7096 /* Make sure for ISP 82XX IO DMA is complete */ 7097 if (IS_P3P_TYPE(ha)) { 7098 qla82xx_chip_reset_cleanup(vha); 7099 ql_log(ql_log_info, vha, 0x00b4, 7100 "Done chip reset cleanup.\n"); 7101 7102 /* Done waiting for pending commands. Reset online flag */ 7103 vha->flags.online = 0; 7104 } 7105 7106 /* Requeue all commands in outstanding command list. */ 7107 qla2x00_abort_all_cmds(vha, DID_RESET << 16); 7108 /* memory barrier */ 7109 wmb(); 7110 } 7111 7112 /* 7113 * qla2x00_abort_isp 7114 * Resets ISP and aborts all outstanding commands. 7115 * 7116 * Input: 7117 * ha = adapter block pointer. 7118 * 7119 * Returns: 7120 * 0 = success 7121 */ 7122 int 7123 qla2x00_abort_isp(scsi_qla_host_t *vha) 7124 { 7125 int rval; 7126 uint8_t status = 0; 7127 struct qla_hw_data *ha = vha->hw; 7128 struct scsi_qla_host *vp, *tvp; 7129 struct req_que *req = ha->req_q_map[0]; 7130 unsigned long flags; 7131 7132 if (vha->flags.online) { 7133 qla2x00_abort_isp_cleanup(vha); 7134 7135 if (vha->hw->flags.port_isolated) 7136 return status; 7137 7138 if (qla2x00_isp_reg_stat(ha)) { 7139 ql_log(ql_log_info, vha, 0x803f, 7140 "ISP Abort - ISP reg disconnect, exiting.\n"); 7141 return status; 7142 } 7143 7144 if (test_and_clear_bit(ISP_ABORT_TO_ROM, &vha->dpc_flags)) { 7145 ha->flags.chip_reset_done = 1; 7146 vha->flags.online = 1; 7147 status = 0; 7148 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags); 7149 return status; 7150 } 7151 7152 if (IS_QLA8031(ha)) { 7153 ql_dbg(ql_dbg_p3p, vha, 0xb05c, 7154 "Clearing fcoe driver presence.\n"); 7155 if (qla83xx_clear_drv_presence(vha) != QLA_SUCCESS) 7156 ql_dbg(ql_dbg_p3p, vha, 0xb073, 7157 "Error while clearing DRV-Presence.\n"); 7158 } 7159 7160 if (unlikely(pci_channel_offline(ha->pdev) && 7161 ha->flags.pci_channel_io_perm_failure)) { 7162 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags); 7163 status = 0; 7164 return status; 7165 } 7166 7167 switch (vha->qlini_mode) { 7168 case QLA2XXX_INI_MODE_DISABLED: 7169 if (!qla_tgt_mode_enabled(vha)) 7170 return 0; 7171 break; 7172 case QLA2XXX_INI_MODE_DUAL: 7173 if (!qla_dual_mode_enabled(vha) && 7174 !qla_ini_mode_enabled(vha)) 7175 return 0; 7176 break; 7177 case QLA2XXX_INI_MODE_ENABLED: 7178 default: 7179 break; 7180 } 7181 7182 ha->isp_ops->get_flash_version(vha, req->ring); 7183 7184 if (qla2x00_isp_reg_stat(ha)) { 7185 ql_log(ql_log_info, vha, 0x803f, 7186 "ISP Abort - ISP reg disconnect pre nvram config, exiting.\n"); 7187 return status; 7188 } 7189 ha->isp_ops->nvram_config(vha); 7190 7191 if (qla2x00_isp_reg_stat(ha)) { 7192 ql_log(ql_log_info, vha, 0x803f, 7193 "ISP Abort - ISP reg disconnect post nvmram config, exiting.\n"); 7194 return status; 7195 } 7196 if (!qla2x00_restart_isp(vha)) { 7197 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); 7198 7199 if (!atomic_read(&vha->loop_down_timer)) { 7200 /* 7201 * Issue marker command only when we are going 7202 * to start the I/O . 7203 */ 7204 vha->marker_needed = 1; 7205 } 7206 7207 vha->flags.online = 1; 7208 7209 ha->isp_ops->enable_intrs(ha); 7210 7211 ha->isp_abort_cnt = 0; 7212 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags); 7213 7214 if (IS_QLA81XX(ha) || IS_QLA8031(ha)) 7215 qla2x00_get_fw_version(vha); 7216 if (ha->fce) { 7217 ha->flags.fce_enabled = 1; 7218 memset(ha->fce, 0, 7219 fce_calc_size(ha->fce_bufs)); 7220 rval = qla2x00_enable_fce_trace(vha, 7221 ha->fce_dma, ha->fce_bufs, ha->fce_mb, 7222 &ha->fce_bufs); 7223 if (rval) { 7224 ql_log(ql_log_warn, vha, 0x8033, 7225 "Unable to reinitialize FCE " 7226 "(%d).\n", rval); 7227 ha->flags.fce_enabled = 0; 7228 } 7229 } 7230 7231 if (ha->eft) { 7232 memset(ha->eft, 0, EFT_SIZE); 7233 rval = qla2x00_enable_eft_trace(vha, 7234 ha->eft_dma, EFT_NUM_BUFFERS); 7235 if (rval) { 7236 ql_log(ql_log_warn, vha, 0x8034, 7237 "Unable to reinitialize EFT " 7238 "(%d).\n", rval); 7239 } 7240 } 7241 } else { /* failed the ISP abort */ 7242 vha->flags.online = 1; 7243 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) { 7244 if (ha->isp_abort_cnt == 0) { 7245 ql_log(ql_log_fatal, vha, 0x8035, 7246 "ISP error recover failed - " 7247 "board disabled.\n"); 7248 /* 7249 * The next call disables the board 7250 * completely. 7251 */ 7252 qla2x00_abort_isp_cleanup(vha); 7253 vha->flags.online = 0; 7254 clear_bit(ISP_ABORT_RETRY, 7255 &vha->dpc_flags); 7256 status = 0; 7257 } else { /* schedule another ISP abort */ 7258 ha->isp_abort_cnt--; 7259 ql_dbg(ql_dbg_taskm, vha, 0x8020, 7260 "ISP abort - retry remaining %d.\n", 7261 ha->isp_abort_cnt); 7262 status = 1; 7263 } 7264 } else { 7265 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT; 7266 ql_dbg(ql_dbg_taskm, vha, 0x8021, 7267 "ISP error recovery - retrying (%d) " 7268 "more times.\n", ha->isp_abort_cnt); 7269 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags); 7270 status = 1; 7271 } 7272 } 7273 7274 } 7275 7276 if (vha->hw->flags.port_isolated) { 7277 qla2x00_abort_isp_cleanup(vha); 7278 return status; 7279 } 7280 7281 if (!status) { 7282 ql_dbg(ql_dbg_taskm, vha, 0x8022, "%s succeeded.\n", __func__); 7283 qla2x00_configure_hba(vha); 7284 spin_lock_irqsave(&ha->vport_slock, flags); 7285 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) { 7286 if (vp->vp_idx) { 7287 atomic_inc(&vp->vref_count); 7288 spin_unlock_irqrestore(&ha->vport_slock, flags); 7289 7290 qla2x00_vp_abort_isp(vp); 7291 7292 spin_lock_irqsave(&ha->vport_slock, flags); 7293 atomic_dec(&vp->vref_count); 7294 } 7295 } 7296 spin_unlock_irqrestore(&ha->vport_slock, flags); 7297 7298 if (IS_QLA8031(ha)) { 7299 ql_dbg(ql_dbg_p3p, vha, 0xb05d, 7300 "Setting back fcoe driver presence.\n"); 7301 if (qla83xx_set_drv_presence(vha) != QLA_SUCCESS) 7302 ql_dbg(ql_dbg_p3p, vha, 0xb074, 7303 "Error while setting DRV-Presence.\n"); 7304 } 7305 } else { 7306 ql_log(ql_log_warn, vha, 0x8023, "%s **** FAILED ****.\n", 7307 __func__); 7308 } 7309 7310 return(status); 7311 } 7312 7313 /* 7314 * qla2x00_restart_isp 7315 * restarts the ISP after a reset 7316 * 7317 * Input: 7318 * ha = adapter block pointer. 7319 * 7320 * Returns: 7321 * 0 = success 7322 */ 7323 static int 7324 qla2x00_restart_isp(scsi_qla_host_t *vha) 7325 { 7326 int status; 7327 struct qla_hw_data *ha = vha->hw; 7328 7329 /* If firmware needs to be loaded */ 7330 if (qla2x00_isp_firmware(vha)) { 7331 vha->flags.online = 0; 7332 status = ha->isp_ops->chip_diag(vha); 7333 if (status) 7334 return status; 7335 status = qla2x00_setup_chip(vha); 7336 if (status) 7337 return status; 7338 } 7339 7340 status = qla2x00_init_rings(vha); 7341 if (status) 7342 return status; 7343 7344 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); 7345 ha->flags.chip_reset_done = 1; 7346 7347 /* Initialize the queues in use */ 7348 qla25xx_init_queues(ha); 7349 7350 status = qla2x00_fw_ready(vha); 7351 if (status) { 7352 /* if no cable then assume it's good */ 7353 return vha->device_flags & DFLG_NO_CABLE ? 0 : status; 7354 } 7355 7356 /* Issue a marker after FW becomes ready. */ 7357 qla2x00_marker(vha, ha->base_qpair, 0, 0, MK_SYNC_ALL); 7358 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); 7359 7360 return 0; 7361 } 7362 7363 static int 7364 qla25xx_init_queues(struct qla_hw_data *ha) 7365 { 7366 struct rsp_que *rsp = NULL; 7367 struct req_que *req = NULL; 7368 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev); 7369 int ret = -1; 7370 int i; 7371 7372 for (i = 1; i < ha->max_rsp_queues; i++) { 7373 rsp = ha->rsp_q_map[i]; 7374 if (rsp && test_bit(i, ha->rsp_qid_map)) { 7375 rsp->options &= ~BIT_0; 7376 ret = qla25xx_init_rsp_que(base_vha, rsp); 7377 if (ret != QLA_SUCCESS) 7378 ql_dbg(ql_dbg_init, base_vha, 0x00ff, 7379 "%s Rsp que: %d init failed.\n", 7380 __func__, rsp->id); 7381 else 7382 ql_dbg(ql_dbg_init, base_vha, 0x0100, 7383 "%s Rsp que: %d inited.\n", 7384 __func__, rsp->id); 7385 } 7386 } 7387 for (i = 1; i < ha->max_req_queues; i++) { 7388 req = ha->req_q_map[i]; 7389 if (req && test_bit(i, ha->req_qid_map)) { 7390 /* Clear outstanding commands array. */ 7391 req->options &= ~BIT_0; 7392 ret = qla25xx_init_req_que(base_vha, req); 7393 if (ret != QLA_SUCCESS) 7394 ql_dbg(ql_dbg_init, base_vha, 0x0101, 7395 "%s Req que: %d init failed.\n", 7396 __func__, req->id); 7397 else 7398 ql_dbg(ql_dbg_init, base_vha, 0x0102, 7399 "%s Req que: %d inited.\n", 7400 __func__, req->id); 7401 } 7402 } 7403 return ret; 7404 } 7405 7406 /* 7407 * qla2x00_reset_adapter 7408 * Reset adapter. 7409 * 7410 * Input: 7411 * ha = adapter block pointer. 7412 */ 7413 int 7414 qla2x00_reset_adapter(scsi_qla_host_t *vha) 7415 { 7416 unsigned long flags = 0; 7417 struct qla_hw_data *ha = vha->hw; 7418 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; 7419 7420 vha->flags.online = 0; 7421 ha->isp_ops->disable_intrs(ha); 7422 7423 spin_lock_irqsave(&ha->hardware_lock, flags); 7424 wrt_reg_word(®->hccr, HCCR_RESET_RISC); 7425 rd_reg_word(®->hccr); /* PCI Posting. */ 7426 wrt_reg_word(®->hccr, HCCR_RELEASE_RISC); 7427 rd_reg_word(®->hccr); /* PCI Posting. */ 7428 spin_unlock_irqrestore(&ha->hardware_lock, flags); 7429 7430 return QLA_SUCCESS; 7431 } 7432 7433 int 7434 qla24xx_reset_adapter(scsi_qla_host_t *vha) 7435 { 7436 unsigned long flags = 0; 7437 struct qla_hw_data *ha = vha->hw; 7438 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; 7439 7440 if (IS_P3P_TYPE(ha)) 7441 return QLA_SUCCESS; 7442 7443 vha->flags.online = 0; 7444 ha->isp_ops->disable_intrs(ha); 7445 7446 spin_lock_irqsave(&ha->hardware_lock, flags); 7447 wrt_reg_dword(®->hccr, HCCRX_SET_RISC_RESET); 7448 rd_reg_dword(®->hccr); 7449 wrt_reg_dword(®->hccr, HCCRX_REL_RISC_PAUSE); 7450 rd_reg_dword(®->hccr); 7451 spin_unlock_irqrestore(&ha->hardware_lock, flags); 7452 7453 if (IS_NOPOLLING_TYPE(ha)) 7454 ha->isp_ops->enable_intrs(ha); 7455 7456 return QLA_SUCCESS; 7457 } 7458 7459 /* On sparc systems, obtain port and node WWN from firmware 7460 * properties. 7461 */ 7462 static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, 7463 struct nvram_24xx *nv) 7464 { 7465 #ifdef CONFIG_SPARC 7466 struct qla_hw_data *ha = vha->hw; 7467 struct pci_dev *pdev = ha->pdev; 7468 struct device_node *dp = pci_device_to_OF_node(pdev); 7469 const u8 *val; 7470 int len; 7471 7472 val = of_get_property(dp, "port-wwn", &len); 7473 if (val && len >= WWN_SIZE) 7474 memcpy(nv->port_name, val, WWN_SIZE); 7475 7476 val = of_get_property(dp, "node-wwn", &len); 7477 if (val && len >= WWN_SIZE) 7478 memcpy(nv->node_name, val, WWN_SIZE); 7479 #endif 7480 } 7481 7482 int 7483 qla24xx_nvram_config(scsi_qla_host_t *vha) 7484 { 7485 int rval; 7486 struct init_cb_24xx *icb; 7487 struct nvram_24xx *nv; 7488 __le32 *dptr; 7489 uint8_t *dptr1, *dptr2; 7490 uint32_t chksum; 7491 uint16_t cnt; 7492 struct qla_hw_data *ha = vha->hw; 7493 7494 rval = QLA_SUCCESS; 7495 icb = (struct init_cb_24xx *)ha->init_cb; 7496 nv = ha->nvram; 7497 7498 /* Determine NVRAM starting address. */ 7499 if (ha->port_no == 0) { 7500 ha->nvram_base = FA_NVRAM_FUNC0_ADDR; 7501 ha->vpd_base = FA_NVRAM_VPD0_ADDR; 7502 } else { 7503 ha->nvram_base = FA_NVRAM_FUNC1_ADDR; 7504 ha->vpd_base = FA_NVRAM_VPD1_ADDR; 7505 } 7506 7507 ha->nvram_size = sizeof(*nv); 7508 ha->vpd_size = FA_NVRAM_VPD_SIZE; 7509 7510 /* Get VPD data into cache */ 7511 ha->vpd = ha->nvram + VPD_OFFSET; 7512 ha->isp_ops->read_nvram(vha, ha->vpd, 7513 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4); 7514 7515 /* Get NVRAM data into cache and calculate checksum. */ 7516 dptr = (__force __le32 *)nv; 7517 ha->isp_ops->read_nvram(vha, dptr, ha->nvram_base, ha->nvram_size); 7518 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++) 7519 chksum += le32_to_cpu(*dptr); 7520 7521 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x006a, 7522 "Contents of NVRAM\n"); 7523 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x010d, 7524 nv, ha->nvram_size); 7525 7526 /* Bad NVRAM data, set defaults parameters. */ 7527 if (chksum || memcmp("ISP ", nv->id, sizeof(nv->id)) || 7528 le16_to_cpu(nv->nvram_version) < ICB_VERSION) { 7529 /* Reset NVRAM data. */ 7530 ql_log(ql_log_warn, vha, 0x006b, 7531 "Inconsistent NVRAM checksum=%#x id=%.4s version=%#x.\n", 7532 chksum, nv->id, nv->nvram_version); 7533 ql_dump_buffer(ql_dbg_init, vha, 0x006b, nv, sizeof(*nv)); 7534 ql_log(ql_log_warn, vha, 0x006c, 7535 "Falling back to functioning (yet invalid -- WWPN) " 7536 "defaults.\n"); 7537 7538 /* 7539 * Set default initialization control block. 7540 */ 7541 memset(nv, 0, ha->nvram_size); 7542 nv->nvram_version = cpu_to_le16(ICB_VERSION); 7543 nv->version = cpu_to_le16(ICB_VERSION); 7544 nv->frame_payload_size = cpu_to_le16(2048); 7545 nv->execution_throttle = cpu_to_le16(0xFFFF); 7546 nv->exchange_count = cpu_to_le16(0); 7547 nv->hard_address = cpu_to_le16(124); 7548 nv->port_name[0] = 0x21; 7549 nv->port_name[1] = 0x00 + ha->port_no + 1; 7550 nv->port_name[2] = 0x00; 7551 nv->port_name[3] = 0xe0; 7552 nv->port_name[4] = 0x8b; 7553 nv->port_name[5] = 0x1c; 7554 nv->port_name[6] = 0x55; 7555 nv->port_name[7] = 0x86; 7556 nv->node_name[0] = 0x20; 7557 nv->node_name[1] = 0x00; 7558 nv->node_name[2] = 0x00; 7559 nv->node_name[3] = 0xe0; 7560 nv->node_name[4] = 0x8b; 7561 nv->node_name[5] = 0x1c; 7562 nv->node_name[6] = 0x55; 7563 nv->node_name[7] = 0x86; 7564 qla24xx_nvram_wwn_from_ofw(vha, nv); 7565 nv->login_retry_count = cpu_to_le16(8); 7566 nv->interrupt_delay_timer = cpu_to_le16(0); 7567 nv->login_timeout = cpu_to_le16(0); 7568 nv->firmware_options_1 = 7569 cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1); 7570 nv->firmware_options_2 = cpu_to_le32(2 << 4); 7571 nv->firmware_options_2 |= cpu_to_le32(BIT_12); 7572 nv->firmware_options_3 = cpu_to_le32(2 << 13); 7573 nv->host_p = cpu_to_le32(BIT_11|BIT_10); 7574 nv->efi_parameters = cpu_to_le32(0); 7575 nv->reset_delay = 5; 7576 nv->max_luns_per_target = cpu_to_le16(128); 7577 nv->port_down_retry_count = cpu_to_le16(30); 7578 nv->link_down_timeout = cpu_to_le16(30); 7579 7580 rval = 1; 7581 } 7582 7583 if (qla_tgt_mode_enabled(vha)) { 7584 /* Don't enable full login after initial LIP */ 7585 nv->firmware_options_1 &= cpu_to_le32(~BIT_13); 7586 /* Don't enable LIP full login for initiator */ 7587 nv->host_p &= cpu_to_le32(~BIT_10); 7588 } 7589 7590 qlt_24xx_config_nvram_stage1(vha, nv); 7591 7592 /* Reset Initialization control block */ 7593 memset(icb, 0, ha->init_cb_size); 7594 7595 /* Copy 1st segment. */ 7596 dptr1 = (uint8_t *)icb; 7597 dptr2 = (uint8_t *)&nv->version; 7598 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version; 7599 while (cnt--) 7600 *dptr1++ = *dptr2++; 7601 7602 icb->login_retry_count = nv->login_retry_count; 7603 icb->link_down_on_nos = nv->link_down_on_nos; 7604 7605 /* Copy 2nd segment. */ 7606 dptr1 = (uint8_t *)&icb->interrupt_delay_timer; 7607 dptr2 = (uint8_t *)&nv->interrupt_delay_timer; 7608 cnt = (uint8_t *)&icb->reserved_3 - 7609 (uint8_t *)&icb->interrupt_delay_timer; 7610 while (cnt--) 7611 *dptr1++ = *dptr2++; 7612 ha->frame_payload_size = le16_to_cpu(icb->frame_payload_size); 7613 /* 7614 * Setup driver NVRAM options. 7615 */ 7616 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name), 7617 "QLA2462"); 7618 7619 qlt_24xx_config_nvram_stage2(vha, icb); 7620 7621 if (nv->host_p & cpu_to_le32(BIT_15)) { 7622 /* Use alternate WWN? */ 7623 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE); 7624 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE); 7625 } 7626 7627 /* Prepare nodename */ 7628 if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) { 7629 /* 7630 * Firmware will apply the following mask if the nodename was 7631 * not provided. 7632 */ 7633 memcpy(icb->node_name, icb->port_name, WWN_SIZE); 7634 icb->node_name[0] &= 0xF0; 7635 } 7636 7637 /* Set host adapter parameters. */ 7638 ha->flags.disable_risc_code_load = 0; 7639 ha->flags.enable_lip_reset = 0; 7640 ha->flags.enable_lip_full_login = 7641 le32_to_cpu(nv->host_p) & BIT_10 ? 1 : 0; 7642 ha->flags.enable_target_reset = 7643 le32_to_cpu(nv->host_p) & BIT_11 ? 1 : 0; 7644 ha->flags.enable_led_scheme = 0; 7645 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1 : 0; 7646 7647 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) & 7648 (BIT_6 | BIT_5 | BIT_4)) >> 4; 7649 7650 memcpy(ha->fw_seriallink_options24, nv->seriallink_options, 7651 sizeof(ha->fw_seriallink_options24)); 7652 7653 /* save HBA serial number */ 7654 ha->serial0 = icb->port_name[5]; 7655 ha->serial1 = icb->port_name[6]; 7656 ha->serial2 = icb->port_name[7]; 7657 memcpy(vha->node_name, icb->node_name, WWN_SIZE); 7658 memcpy(vha->port_name, icb->port_name, WWN_SIZE); 7659 7660 icb->execution_throttle = cpu_to_le16(0xFFFF); 7661 7662 ha->retry_count = le16_to_cpu(nv->login_retry_count); 7663 7664 /* Set minimum login_timeout to 4 seconds. */ 7665 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout) 7666 nv->login_timeout = cpu_to_le16(ql2xlogintimeout); 7667 if (le16_to_cpu(nv->login_timeout) < 4) 7668 nv->login_timeout = cpu_to_le16(4); 7669 ha->login_timeout = le16_to_cpu(nv->login_timeout); 7670 7671 /* Set minimum RATOV to 100 tenths of a second. */ 7672 ha->r_a_tov = 100; 7673 7674 ha->loop_reset_delay = nv->reset_delay; 7675 7676 /* Link Down Timeout = 0: 7677 * 7678 * When Port Down timer expires we will start returning 7679 * I/O's to OS with "DID_NO_CONNECT". 7680 * 7681 * Link Down Timeout != 0: 7682 * 7683 * The driver waits for the link to come up after link down 7684 * before returning I/Os to OS with "DID_NO_CONNECT". 7685 */ 7686 if (le16_to_cpu(nv->link_down_timeout) == 0) { 7687 ha->loop_down_abort_time = 7688 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT); 7689 } else { 7690 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout); 7691 ha->loop_down_abort_time = 7692 (LOOP_DOWN_TIME - ha->link_down_timeout); 7693 } 7694 7695 /* Need enough time to try and get the port back. */ 7696 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count); 7697 if (qlport_down_retry) 7698 ha->port_down_retry_count = qlport_down_retry; 7699 7700 /* Set login_retry_count */ 7701 ha->login_retry_count = le16_to_cpu(nv->login_retry_count); 7702 if (ha->port_down_retry_count == 7703 le16_to_cpu(nv->port_down_retry_count) && 7704 ha->port_down_retry_count > 3) 7705 ha->login_retry_count = ha->port_down_retry_count; 7706 else if (ha->port_down_retry_count > (int)ha->login_retry_count) 7707 ha->login_retry_count = ha->port_down_retry_count; 7708 if (ql2xloginretrycount) 7709 ha->login_retry_count = ql2xloginretrycount; 7710 7711 /* N2N: driver will initiate Login instead of FW */ 7712 icb->firmware_options_3 |= cpu_to_le32(BIT_8); 7713 7714 /* Enable ZIO. */ 7715 if (!vha->flags.init_done) { 7716 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) & 7717 (BIT_3 | BIT_2 | BIT_1 | BIT_0); 7718 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ? 7719 le16_to_cpu(icb->interrupt_delay_timer) : 2; 7720 } 7721 icb->firmware_options_2 &= cpu_to_le32( 7722 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0)); 7723 if (ha->zio_mode != QLA_ZIO_DISABLED) { 7724 ha->zio_mode = QLA_ZIO_MODE_6; 7725 7726 ql_log(ql_log_info, vha, 0x006f, 7727 "ZIO mode %d enabled; timer delay (%d us).\n", 7728 ha->zio_mode, ha->zio_timer * 100); 7729 7730 icb->firmware_options_2 |= cpu_to_le32( 7731 (uint32_t)ha->zio_mode); 7732 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer); 7733 } 7734 7735 if (rval) { 7736 ql_log(ql_log_warn, vha, 0x0070, 7737 "NVRAM configuration failed.\n"); 7738 } 7739 return (rval); 7740 } 7741 7742 static void 7743 qla27xx_print_image(struct scsi_qla_host *vha, char *name, 7744 struct qla27xx_image_status *image_status) 7745 { 7746 ql_dbg(ql_dbg_init, vha, 0x018b, 7747 "%s %s: mask=%#02x gen=%#04x ver=%u.%u map=%#01x sum=%#08x sig=%#08x\n", 7748 name, "status", 7749 image_status->image_status_mask, 7750 le16_to_cpu(image_status->generation), 7751 image_status->ver_major, 7752 image_status->ver_minor, 7753 image_status->bitmap, 7754 le32_to_cpu(image_status->checksum), 7755 le32_to_cpu(image_status->signature)); 7756 } 7757 7758 static bool 7759 qla28xx_check_aux_image_status_signature( 7760 struct qla27xx_image_status *image_status) 7761 { 7762 ulong signature = le32_to_cpu(image_status->signature); 7763 7764 return signature != QLA28XX_AUX_IMG_STATUS_SIGN; 7765 } 7766 7767 static bool 7768 qla27xx_check_image_status_signature(struct qla27xx_image_status *image_status) 7769 { 7770 ulong signature = le32_to_cpu(image_status->signature); 7771 7772 return 7773 signature != QLA27XX_IMG_STATUS_SIGN && 7774 signature != QLA28XX_IMG_STATUS_SIGN; 7775 } 7776 7777 static ulong 7778 qla27xx_image_status_checksum(struct qla27xx_image_status *image_status) 7779 { 7780 __le32 *p = (__force __le32 *)image_status; 7781 uint n = sizeof(*image_status) / sizeof(*p); 7782 uint32_t sum = 0; 7783 7784 for ( ; n--; p++) 7785 sum += le32_to_cpup(p); 7786 7787 return sum; 7788 } 7789 7790 static inline uint 7791 qla28xx_component_bitmask(struct qla27xx_image_status *aux, uint bitmask) 7792 { 7793 return aux->bitmap & bitmask ? 7794 QLA27XX_SECONDARY_IMAGE : QLA27XX_PRIMARY_IMAGE; 7795 } 7796 7797 static void 7798 qla28xx_component_status( 7799 struct active_regions *active_regions, struct qla27xx_image_status *aux) 7800 { 7801 active_regions->aux.board_config = 7802 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_BOARD_CONFIG); 7803 7804 active_regions->aux.vpd_nvram = 7805 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_VPD_NVRAM); 7806 7807 active_regions->aux.npiv_config_0_1 = 7808 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_NPIV_CONFIG_0_1); 7809 7810 active_regions->aux.npiv_config_2_3 = 7811 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_NPIV_CONFIG_2_3); 7812 } 7813 7814 static int 7815 qla27xx_compare_image_generation( 7816 struct qla27xx_image_status *pri_image_status, 7817 struct qla27xx_image_status *sec_image_status) 7818 { 7819 /* calculate generation delta as uint16 (this accounts for wrap) */ 7820 int16_t delta = 7821 le16_to_cpu(pri_image_status->generation) - 7822 le16_to_cpu(sec_image_status->generation); 7823 7824 ql_dbg(ql_dbg_init, NULL, 0x0180, "generation delta = %d\n", delta); 7825 7826 return delta; 7827 } 7828 7829 void 7830 qla28xx_get_aux_images( 7831 struct scsi_qla_host *vha, struct active_regions *active_regions) 7832 { 7833 struct qla_hw_data *ha = vha->hw; 7834 struct qla27xx_image_status pri_aux_image_status, sec_aux_image_status; 7835 bool valid_pri_image = false, valid_sec_image = false; 7836 bool active_pri_image = false, active_sec_image = false; 7837 7838 if (!ha->flt_region_aux_img_status_pri) { 7839 ql_dbg(ql_dbg_init, vha, 0x018a, "Primary aux image not addressed\n"); 7840 goto check_sec_image; 7841 } 7842 7843 qla24xx_read_flash_data(vha, (uint32_t *)&pri_aux_image_status, 7844 ha->flt_region_aux_img_status_pri, 7845 sizeof(pri_aux_image_status) >> 2); 7846 qla27xx_print_image(vha, "Primary aux image", &pri_aux_image_status); 7847 7848 if (qla28xx_check_aux_image_status_signature(&pri_aux_image_status)) { 7849 ql_dbg(ql_dbg_init, vha, 0x018b, 7850 "Primary aux image signature (%#x) not valid\n", 7851 le32_to_cpu(pri_aux_image_status.signature)); 7852 goto check_sec_image; 7853 } 7854 7855 if (qla27xx_image_status_checksum(&pri_aux_image_status)) { 7856 ql_dbg(ql_dbg_init, vha, 0x018c, 7857 "Primary aux image checksum failed\n"); 7858 goto check_sec_image; 7859 } 7860 7861 valid_pri_image = true; 7862 7863 if (pri_aux_image_status.image_status_mask & 1) { 7864 ql_dbg(ql_dbg_init, vha, 0x018d, 7865 "Primary aux image is active\n"); 7866 active_pri_image = true; 7867 } 7868 7869 check_sec_image: 7870 if (!ha->flt_region_aux_img_status_sec) { 7871 ql_dbg(ql_dbg_init, vha, 0x018a, 7872 "Secondary aux image not addressed\n"); 7873 goto check_valid_image; 7874 } 7875 7876 qla24xx_read_flash_data(vha, (uint32_t *)&sec_aux_image_status, 7877 ha->flt_region_aux_img_status_sec, 7878 sizeof(sec_aux_image_status) >> 2); 7879 qla27xx_print_image(vha, "Secondary aux image", &sec_aux_image_status); 7880 7881 if (qla28xx_check_aux_image_status_signature(&sec_aux_image_status)) { 7882 ql_dbg(ql_dbg_init, vha, 0x018b, 7883 "Secondary aux image signature (%#x) not valid\n", 7884 le32_to_cpu(sec_aux_image_status.signature)); 7885 goto check_valid_image; 7886 } 7887 7888 if (qla27xx_image_status_checksum(&sec_aux_image_status)) { 7889 ql_dbg(ql_dbg_init, vha, 0x018c, 7890 "Secondary aux image checksum failed\n"); 7891 goto check_valid_image; 7892 } 7893 7894 valid_sec_image = true; 7895 7896 if (sec_aux_image_status.image_status_mask & 1) { 7897 ql_dbg(ql_dbg_init, vha, 0x018d, 7898 "Secondary aux image is active\n"); 7899 active_sec_image = true; 7900 } 7901 7902 check_valid_image: 7903 if (valid_pri_image && active_pri_image && 7904 valid_sec_image && active_sec_image) { 7905 if (qla27xx_compare_image_generation(&pri_aux_image_status, 7906 &sec_aux_image_status) >= 0) { 7907 qla28xx_component_status(active_regions, 7908 &pri_aux_image_status); 7909 } else { 7910 qla28xx_component_status(active_regions, 7911 &sec_aux_image_status); 7912 } 7913 } else if (valid_pri_image && active_pri_image) { 7914 qla28xx_component_status(active_regions, &pri_aux_image_status); 7915 } else if (valid_sec_image && active_sec_image) { 7916 qla28xx_component_status(active_regions, &sec_aux_image_status); 7917 } 7918 7919 ql_dbg(ql_dbg_init, vha, 0x018f, 7920 "aux images active: BCFG=%u VPD/NVR=%u NPIV0/1=%u NPIV2/3=%u\n", 7921 active_regions->aux.board_config, 7922 active_regions->aux.vpd_nvram, 7923 active_regions->aux.npiv_config_0_1, 7924 active_regions->aux.npiv_config_2_3); 7925 } 7926 7927 void 7928 qla27xx_get_active_image(struct scsi_qla_host *vha, 7929 struct active_regions *active_regions) 7930 { 7931 struct qla_hw_data *ha = vha->hw; 7932 struct qla27xx_image_status pri_image_status, sec_image_status; 7933 bool valid_pri_image = false, valid_sec_image = false; 7934 bool active_pri_image = false, active_sec_image = false; 7935 7936 if (!ha->flt_region_img_status_pri) { 7937 ql_dbg(ql_dbg_init, vha, 0x018a, "Primary image not addressed\n"); 7938 goto check_sec_image; 7939 } 7940 7941 if (qla24xx_read_flash_data(vha, (uint32_t *)&pri_image_status, 7942 ha->flt_region_img_status_pri, sizeof(pri_image_status) >> 2) != 7943 QLA_SUCCESS) { 7944 WARN_ON_ONCE(true); 7945 goto check_sec_image; 7946 } 7947 qla27xx_print_image(vha, "Primary image", &pri_image_status); 7948 7949 if (qla27xx_check_image_status_signature(&pri_image_status)) { 7950 ql_dbg(ql_dbg_init, vha, 0x018b, 7951 "Primary image signature (%#x) not valid\n", 7952 le32_to_cpu(pri_image_status.signature)); 7953 goto check_sec_image; 7954 } 7955 7956 if (qla27xx_image_status_checksum(&pri_image_status)) { 7957 ql_dbg(ql_dbg_init, vha, 0x018c, 7958 "Primary image checksum failed\n"); 7959 goto check_sec_image; 7960 } 7961 7962 valid_pri_image = true; 7963 7964 if (pri_image_status.image_status_mask & 1) { 7965 ql_dbg(ql_dbg_init, vha, 0x018d, 7966 "Primary image is active\n"); 7967 active_pri_image = true; 7968 } 7969 7970 check_sec_image: 7971 if (!ha->flt_region_img_status_sec) { 7972 ql_dbg(ql_dbg_init, vha, 0x018a, "Secondary image not addressed\n"); 7973 goto check_valid_image; 7974 } 7975 7976 qla24xx_read_flash_data(vha, (uint32_t *)(&sec_image_status), 7977 ha->flt_region_img_status_sec, sizeof(sec_image_status) >> 2); 7978 qla27xx_print_image(vha, "Secondary image", &sec_image_status); 7979 7980 if (qla27xx_check_image_status_signature(&sec_image_status)) { 7981 ql_dbg(ql_dbg_init, vha, 0x018b, 7982 "Secondary image signature (%#x) not valid\n", 7983 le32_to_cpu(sec_image_status.signature)); 7984 goto check_valid_image; 7985 } 7986 7987 if (qla27xx_image_status_checksum(&sec_image_status)) { 7988 ql_dbg(ql_dbg_init, vha, 0x018c, 7989 "Secondary image checksum failed\n"); 7990 goto check_valid_image; 7991 } 7992 7993 valid_sec_image = true; 7994 7995 if (sec_image_status.image_status_mask & 1) { 7996 ql_dbg(ql_dbg_init, vha, 0x018d, 7997 "Secondary image is active\n"); 7998 active_sec_image = true; 7999 } 8000 8001 check_valid_image: 8002 if (valid_pri_image && active_pri_image) 8003 active_regions->global = QLA27XX_PRIMARY_IMAGE; 8004 8005 if (valid_sec_image && active_sec_image) { 8006 if (!active_regions->global || 8007 qla27xx_compare_image_generation( 8008 &pri_image_status, &sec_image_status) < 0) { 8009 active_regions->global = QLA27XX_SECONDARY_IMAGE; 8010 } 8011 } 8012 8013 ql_dbg(ql_dbg_init, vha, 0x018f, "active image %s (%u)\n", 8014 active_regions->global == QLA27XX_DEFAULT_IMAGE ? 8015 "default (boot/fw)" : 8016 active_regions->global == QLA27XX_PRIMARY_IMAGE ? 8017 "primary" : 8018 active_regions->global == QLA27XX_SECONDARY_IMAGE ? 8019 "secondary" : "invalid", 8020 active_regions->global); 8021 } 8022 8023 bool qla24xx_risc_firmware_invalid(uint32_t *dword) 8024 { 8025 return 8026 !(dword[4] | dword[5] | dword[6] | dword[7]) || 8027 !(~dword[4] | ~dword[5] | ~dword[6] | ~dword[7]); 8028 } 8029 8030 static int 8031 qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr, 8032 uint32_t faddr) 8033 { 8034 int rval; 8035 uint templates, segments, fragment; 8036 ulong i; 8037 uint j; 8038 ulong dlen; 8039 uint32_t *dcode; 8040 uint32_t risc_addr, risc_size, risc_attr = 0; 8041 struct qla_hw_data *ha = vha->hw; 8042 struct req_que *req = ha->req_q_map[0]; 8043 struct fwdt *fwdt = ha->fwdt; 8044 8045 ql_dbg(ql_dbg_init, vha, 0x008b, 8046 "FW: Loading firmware from flash (%x).\n", faddr); 8047 8048 dcode = (uint32_t *)req->ring; 8049 qla24xx_read_flash_data(vha, dcode, faddr, 8); 8050 if (qla24xx_risc_firmware_invalid(dcode)) { 8051 ql_log(ql_log_fatal, vha, 0x008c, 8052 "Unable to verify the integrity of flash firmware " 8053 "image.\n"); 8054 ql_log(ql_log_fatal, vha, 0x008d, 8055 "Firmware data: %08x %08x %08x %08x.\n", 8056 dcode[0], dcode[1], dcode[2], dcode[3]); 8057 8058 return QLA_FUNCTION_FAILED; 8059 } 8060 8061 dcode = (uint32_t *)req->ring; 8062 *srisc_addr = 0; 8063 segments = FA_RISC_CODE_SEGMENTS; 8064 for (j = 0; j < segments; j++) { 8065 ql_dbg(ql_dbg_init, vha, 0x008d, 8066 "-> Loading segment %u...\n", j); 8067 qla24xx_read_flash_data(vha, dcode, faddr, 10); 8068 risc_addr = be32_to_cpu((__force __be32)dcode[2]); 8069 risc_size = be32_to_cpu((__force __be32)dcode[3]); 8070 if (!*srisc_addr) { 8071 *srisc_addr = risc_addr; 8072 risc_attr = be32_to_cpu((__force __be32)dcode[9]); 8073 } 8074 8075 dlen = ha->fw_transfer_size >> 2; 8076 for (fragment = 0; risc_size; fragment++) { 8077 if (dlen > risc_size) 8078 dlen = risc_size; 8079 8080 ql_dbg(ql_dbg_init, vha, 0x008e, 8081 "-> Loading fragment %u: %#x <- %#x (%#lx dwords)...\n", 8082 fragment, risc_addr, faddr, dlen); 8083 qla24xx_read_flash_data(vha, dcode, faddr, dlen); 8084 for (i = 0; i < dlen; i++) 8085 dcode[i] = swab32(dcode[i]); 8086 8087 rval = qla2x00_load_ram(vha, req->dma, risc_addr, dlen); 8088 if (rval) { 8089 ql_log(ql_log_fatal, vha, 0x008f, 8090 "-> Failed load firmware fragment %u.\n", 8091 fragment); 8092 return QLA_FUNCTION_FAILED; 8093 } 8094 8095 faddr += dlen; 8096 risc_addr += dlen; 8097 risc_size -= dlen; 8098 } 8099 } 8100 8101 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha)) 8102 return QLA_SUCCESS; 8103 8104 templates = (risc_attr & BIT_9) ? 2 : 1; 8105 ql_dbg(ql_dbg_init, vha, 0x0160, "-> templates = %u\n", templates); 8106 for (j = 0; j < templates; j++, fwdt++) { 8107 vfree(fwdt->template); 8108 fwdt->template = NULL; 8109 fwdt->length = 0; 8110 8111 dcode = (uint32_t *)req->ring; 8112 qla24xx_read_flash_data(vha, dcode, faddr, 7); 8113 risc_size = be32_to_cpu((__force __be32)dcode[2]); 8114 ql_dbg(ql_dbg_init, vha, 0x0161, 8115 "-> fwdt%u template array at %#x (%#x dwords)\n", 8116 j, faddr, risc_size); 8117 if (!risc_size || !~risc_size) { 8118 ql_dbg(ql_dbg_init, vha, 0x0162, 8119 "-> fwdt%u failed to read array\n", j); 8120 goto failed; 8121 } 8122 8123 /* skip header and ignore checksum */ 8124 faddr += 7; 8125 risc_size -= 8; 8126 8127 ql_dbg(ql_dbg_init, vha, 0x0163, 8128 "-> fwdt%u template allocate template %#x words...\n", 8129 j, risc_size); 8130 fwdt->template = vmalloc(risc_size * sizeof(*dcode)); 8131 if (!fwdt->template) { 8132 ql_log(ql_log_warn, vha, 0x0164, 8133 "-> fwdt%u failed allocate template.\n", j); 8134 goto failed; 8135 } 8136 8137 dcode = fwdt->template; 8138 qla24xx_read_flash_data(vha, dcode, faddr, risc_size); 8139 8140 if (!qla27xx_fwdt_template_valid(dcode)) { 8141 ql_log(ql_log_warn, vha, 0x0165, 8142 "-> fwdt%u failed template validate\n", j); 8143 goto failed; 8144 } 8145 8146 dlen = qla27xx_fwdt_template_size(dcode); 8147 ql_dbg(ql_dbg_init, vha, 0x0166, 8148 "-> fwdt%u template size %#lx bytes (%#lx words)\n", 8149 j, dlen, dlen / sizeof(*dcode)); 8150 if (dlen > risc_size * sizeof(*dcode)) { 8151 ql_log(ql_log_warn, vha, 0x0167, 8152 "-> fwdt%u template exceeds array (%-lu bytes)\n", 8153 j, dlen - risc_size * sizeof(*dcode)); 8154 goto failed; 8155 } 8156 8157 fwdt->length = dlen; 8158 ql_dbg(ql_dbg_init, vha, 0x0168, 8159 "-> fwdt%u loaded template ok\n", j); 8160 8161 faddr += risc_size + 1; 8162 } 8163 8164 return QLA_SUCCESS; 8165 8166 failed: 8167 vfree(fwdt->template); 8168 fwdt->template = NULL; 8169 fwdt->length = 0; 8170 8171 return QLA_SUCCESS; 8172 } 8173 8174 #define QLA_FW_URL "http://ldriver.qlogic.com/firmware/" 8175 8176 int 8177 qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr) 8178 { 8179 int rval; 8180 int i, fragment; 8181 uint16_t *wcode; 8182 __be16 *fwcode; 8183 uint32_t risc_addr, risc_size, fwclen, wlen, *seg; 8184 struct fw_blob *blob; 8185 struct qla_hw_data *ha = vha->hw; 8186 struct req_que *req = ha->req_q_map[0]; 8187 8188 /* Load firmware blob. */ 8189 blob = qla2x00_request_firmware(vha); 8190 if (!blob) { 8191 ql_log(ql_log_info, vha, 0x0083, 8192 "Firmware image unavailable.\n"); 8193 ql_log(ql_log_info, vha, 0x0084, 8194 "Firmware images can be retrieved from: "QLA_FW_URL ".\n"); 8195 return QLA_FUNCTION_FAILED; 8196 } 8197 8198 rval = QLA_SUCCESS; 8199 8200 wcode = (uint16_t *)req->ring; 8201 *srisc_addr = 0; 8202 fwcode = (__force __be16 *)blob->fw->data; 8203 fwclen = 0; 8204 8205 /* Validate firmware image by checking version. */ 8206 if (blob->fw->size < 8 * sizeof(uint16_t)) { 8207 ql_log(ql_log_fatal, vha, 0x0085, 8208 "Unable to verify integrity of firmware image (%zd).\n", 8209 blob->fw->size); 8210 goto fail_fw_integrity; 8211 } 8212 for (i = 0; i < 4; i++) 8213 wcode[i] = be16_to_cpu(fwcode[i + 4]); 8214 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff && 8215 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 && 8216 wcode[2] == 0 && wcode[3] == 0)) { 8217 ql_log(ql_log_fatal, vha, 0x0086, 8218 "Unable to verify integrity of firmware image.\n"); 8219 ql_log(ql_log_fatal, vha, 0x0087, 8220 "Firmware data: %04x %04x %04x %04x.\n", 8221 wcode[0], wcode[1], wcode[2], wcode[3]); 8222 goto fail_fw_integrity; 8223 } 8224 8225 seg = blob->segs; 8226 while (*seg && rval == QLA_SUCCESS) { 8227 risc_addr = *seg; 8228 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr; 8229 risc_size = be16_to_cpu(fwcode[3]); 8230 8231 /* Validate firmware image size. */ 8232 fwclen += risc_size * sizeof(uint16_t); 8233 if (blob->fw->size < fwclen) { 8234 ql_log(ql_log_fatal, vha, 0x0088, 8235 "Unable to verify integrity of firmware image " 8236 "(%zd).\n", blob->fw->size); 8237 goto fail_fw_integrity; 8238 } 8239 8240 fragment = 0; 8241 while (risc_size > 0 && rval == QLA_SUCCESS) { 8242 wlen = (uint16_t)(ha->fw_transfer_size >> 1); 8243 if (wlen > risc_size) 8244 wlen = risc_size; 8245 ql_dbg(ql_dbg_init, vha, 0x0089, 8246 "Loading risc segment@ risc addr %x number of " 8247 "words 0x%x.\n", risc_addr, wlen); 8248 8249 for (i = 0; i < wlen; i++) 8250 wcode[i] = swab16((__force u32)fwcode[i]); 8251 8252 rval = qla2x00_load_ram(vha, req->dma, risc_addr, 8253 wlen); 8254 if (rval) { 8255 ql_log(ql_log_fatal, vha, 0x008a, 8256 "Failed to load segment %d of firmware.\n", 8257 fragment); 8258 break; 8259 } 8260 8261 fwcode += wlen; 8262 risc_addr += wlen; 8263 risc_size -= wlen; 8264 fragment++; 8265 } 8266 8267 /* Next segment. */ 8268 seg++; 8269 } 8270 return rval; 8271 8272 fail_fw_integrity: 8273 return QLA_FUNCTION_FAILED; 8274 } 8275 8276 static int 8277 qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr) 8278 { 8279 int rval; 8280 uint templates, segments, fragment; 8281 uint32_t *dcode; 8282 ulong dlen; 8283 uint32_t risc_addr, risc_size, risc_attr = 0; 8284 ulong i; 8285 uint j; 8286 struct fw_blob *blob; 8287 __be32 *fwcode; 8288 struct qla_hw_data *ha = vha->hw; 8289 struct req_que *req = ha->req_q_map[0]; 8290 struct fwdt *fwdt = ha->fwdt; 8291 8292 ql_dbg(ql_dbg_init, vha, 0x0090, 8293 "-> FW: Loading via request-firmware.\n"); 8294 8295 blob = qla2x00_request_firmware(vha); 8296 if (!blob) { 8297 ql_log(ql_log_warn, vha, 0x0092, 8298 "-> Firmware file not found.\n"); 8299 8300 return QLA_FUNCTION_FAILED; 8301 } 8302 8303 fwcode = (__force __be32 *)blob->fw->data; 8304 dcode = (__force uint32_t *)fwcode; 8305 if (qla24xx_risc_firmware_invalid(dcode)) { 8306 ql_log(ql_log_fatal, vha, 0x0093, 8307 "Unable to verify integrity of firmware image (%zd).\n", 8308 blob->fw->size); 8309 ql_log(ql_log_fatal, vha, 0x0095, 8310 "Firmware data: %08x %08x %08x %08x.\n", 8311 dcode[0], dcode[1], dcode[2], dcode[3]); 8312 return QLA_FUNCTION_FAILED; 8313 } 8314 8315 dcode = (uint32_t *)req->ring; 8316 *srisc_addr = 0; 8317 segments = FA_RISC_CODE_SEGMENTS; 8318 for (j = 0; j < segments; j++) { 8319 ql_dbg(ql_dbg_init, vha, 0x0096, 8320 "-> Loading segment %u...\n", j); 8321 risc_addr = be32_to_cpu(fwcode[2]); 8322 risc_size = be32_to_cpu(fwcode[3]); 8323 8324 if (!*srisc_addr) { 8325 *srisc_addr = risc_addr; 8326 risc_attr = be32_to_cpu(fwcode[9]); 8327 } 8328 8329 dlen = ha->fw_transfer_size >> 2; 8330 for (fragment = 0; risc_size; fragment++) { 8331 if (dlen > risc_size) 8332 dlen = risc_size; 8333 8334 ql_dbg(ql_dbg_init, vha, 0x0097, 8335 "-> Loading fragment %u: %#x <- %#x (%#lx words)...\n", 8336 fragment, risc_addr, 8337 (uint32_t)(fwcode - (typeof(fwcode))blob->fw->data), 8338 dlen); 8339 8340 for (i = 0; i < dlen; i++) 8341 dcode[i] = swab32((__force u32)fwcode[i]); 8342 8343 rval = qla2x00_load_ram(vha, req->dma, risc_addr, dlen); 8344 if (rval) { 8345 ql_log(ql_log_fatal, vha, 0x0098, 8346 "-> Failed load firmware fragment %u.\n", 8347 fragment); 8348 return QLA_FUNCTION_FAILED; 8349 } 8350 8351 fwcode += dlen; 8352 risc_addr += dlen; 8353 risc_size -= dlen; 8354 } 8355 } 8356 8357 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha)) 8358 return QLA_SUCCESS; 8359 8360 templates = (risc_attr & BIT_9) ? 2 : 1; 8361 ql_dbg(ql_dbg_init, vha, 0x0170, "-> templates = %u\n", templates); 8362 for (j = 0; j < templates; j++, fwdt++) { 8363 vfree(fwdt->template); 8364 fwdt->template = NULL; 8365 fwdt->length = 0; 8366 8367 risc_size = be32_to_cpu(fwcode[2]); 8368 ql_dbg(ql_dbg_init, vha, 0x0171, 8369 "-> fwdt%u template array at %#x (%#x dwords)\n", 8370 j, (uint32_t)((void *)fwcode - (void *)blob->fw->data), 8371 risc_size); 8372 if (!risc_size || !~risc_size) { 8373 ql_dbg(ql_dbg_init, vha, 0x0172, 8374 "-> fwdt%u failed to read array\n", j); 8375 goto failed; 8376 } 8377 8378 /* skip header and ignore checksum */ 8379 fwcode += 7; 8380 risc_size -= 8; 8381 8382 ql_dbg(ql_dbg_init, vha, 0x0173, 8383 "-> fwdt%u template allocate template %#x words...\n", 8384 j, risc_size); 8385 fwdt->template = vmalloc(risc_size * sizeof(*dcode)); 8386 if (!fwdt->template) { 8387 ql_log(ql_log_warn, vha, 0x0174, 8388 "-> fwdt%u failed allocate template.\n", j); 8389 goto failed; 8390 } 8391 8392 dcode = fwdt->template; 8393 for (i = 0; i < risc_size; i++) 8394 dcode[i] = (__force u32)fwcode[i]; 8395 8396 if (!qla27xx_fwdt_template_valid(dcode)) { 8397 ql_log(ql_log_warn, vha, 0x0175, 8398 "-> fwdt%u failed template validate\n", j); 8399 goto failed; 8400 } 8401 8402 dlen = qla27xx_fwdt_template_size(dcode); 8403 ql_dbg(ql_dbg_init, vha, 0x0176, 8404 "-> fwdt%u template size %#lx bytes (%#lx words)\n", 8405 j, dlen, dlen / sizeof(*dcode)); 8406 if (dlen > risc_size * sizeof(*dcode)) { 8407 ql_log(ql_log_warn, vha, 0x0177, 8408 "-> fwdt%u template exceeds array (%-lu bytes)\n", 8409 j, dlen - risc_size * sizeof(*dcode)); 8410 goto failed; 8411 } 8412 8413 fwdt->length = dlen; 8414 ql_dbg(ql_dbg_init, vha, 0x0178, 8415 "-> fwdt%u loaded template ok\n", j); 8416 8417 fwcode += risc_size + 1; 8418 } 8419 8420 return QLA_SUCCESS; 8421 8422 failed: 8423 vfree(fwdt->template); 8424 fwdt->template = NULL; 8425 fwdt->length = 0; 8426 8427 return QLA_SUCCESS; 8428 } 8429 8430 int 8431 qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr) 8432 { 8433 int rval; 8434 8435 if (ql2xfwloadbin == 1) 8436 return qla81xx_load_risc(vha, srisc_addr); 8437 8438 /* 8439 * FW Load priority: 8440 * 1) Firmware via request-firmware interface (.bin file). 8441 * 2) Firmware residing in flash. 8442 */ 8443 rval = qla24xx_load_risc_blob(vha, srisc_addr); 8444 if (rval == QLA_SUCCESS) 8445 return rval; 8446 8447 return qla24xx_load_risc_flash(vha, srisc_addr, 8448 vha->hw->flt_region_fw); 8449 } 8450 8451 int 8452 qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr) 8453 { 8454 int rval; 8455 struct qla_hw_data *ha = vha->hw; 8456 struct active_regions active_regions = { }; 8457 8458 if (ql2xfwloadbin == 2) 8459 goto try_blob_fw; 8460 8461 /* FW Load priority: 8462 * 1) Firmware residing in flash. 8463 * 2) Firmware via request-firmware interface (.bin file). 8464 * 3) Golden-Firmware residing in flash -- (limited operation). 8465 */ 8466 8467 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha)) 8468 goto try_primary_fw; 8469 8470 qla27xx_get_active_image(vha, &active_regions); 8471 8472 if (active_regions.global != QLA27XX_SECONDARY_IMAGE) 8473 goto try_primary_fw; 8474 8475 ql_dbg(ql_dbg_init, vha, 0x008b, 8476 "Loading secondary firmware image.\n"); 8477 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw_sec); 8478 if (!rval) 8479 return rval; 8480 8481 try_primary_fw: 8482 ql_dbg(ql_dbg_init, vha, 0x008b, 8483 "Loading primary firmware image.\n"); 8484 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw); 8485 if (!rval) 8486 return rval; 8487 8488 try_blob_fw: 8489 rval = qla24xx_load_risc_blob(vha, srisc_addr); 8490 if (!rval || !ha->flt_region_gold_fw) 8491 return rval; 8492 8493 ql_log(ql_log_info, vha, 0x0099, 8494 "Attempting to fallback to golden firmware.\n"); 8495 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw); 8496 if (rval) 8497 return rval; 8498 8499 ql_log(ql_log_info, vha, 0x009a, "Need firmware flash update.\n"); 8500 ha->flags.running_gold_fw = 1; 8501 return rval; 8502 } 8503 8504 void 8505 qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha) 8506 { 8507 int ret, retries; 8508 struct qla_hw_data *ha = vha->hw; 8509 8510 if (ha->flags.pci_channel_io_perm_failure) 8511 return; 8512 if (!IS_FWI2_CAPABLE(ha)) 8513 return; 8514 if (!ha->fw_major_version) 8515 return; 8516 if (!ha->flags.fw_started) 8517 return; 8518 8519 ret = qla2x00_stop_firmware(vha); 8520 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT && 8521 ret != QLA_INVALID_COMMAND && retries ; retries--) { 8522 ha->isp_ops->reset_chip(vha); 8523 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS) 8524 continue; 8525 if (qla2x00_setup_chip(vha) != QLA_SUCCESS) 8526 continue; 8527 ql_log(ql_log_info, vha, 0x8015, 8528 "Attempting retry of stop-firmware command.\n"); 8529 ret = qla2x00_stop_firmware(vha); 8530 } 8531 8532 QLA_FW_STOPPED(ha); 8533 ha->flags.fw_init_done = 0; 8534 } 8535 8536 int 8537 qla24xx_configure_vhba(scsi_qla_host_t *vha) 8538 { 8539 int rval = QLA_SUCCESS; 8540 int rval2; 8541 uint16_t mb[MAILBOX_REGISTER_COUNT]; 8542 struct qla_hw_data *ha = vha->hw; 8543 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev); 8544 8545 if (!vha->vp_idx) 8546 return -EINVAL; 8547 8548 rval = qla2x00_fw_ready(base_vha); 8549 8550 if (rval == QLA_SUCCESS) { 8551 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); 8552 qla2x00_marker(vha, ha->base_qpair, 0, 0, MK_SYNC_ALL); 8553 } 8554 8555 vha->flags.management_server_logged_in = 0; 8556 8557 /* Login to SNS first */ 8558 rval2 = ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb, 8559 BIT_1); 8560 if (rval2 != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) { 8561 if (rval2 == QLA_MEMORY_ALLOC_FAILED) 8562 ql_dbg(ql_dbg_init, vha, 0x0120, 8563 "Failed SNS login: loop_id=%x, rval2=%d\n", 8564 NPH_SNS, rval2); 8565 else 8566 ql_dbg(ql_dbg_init, vha, 0x0103, 8567 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x " 8568 "mb[2]=%x mb[6]=%x mb[7]=%x.\n", 8569 NPH_SNS, mb[0], mb[1], mb[2], mb[6], mb[7]); 8570 return (QLA_FUNCTION_FAILED); 8571 } 8572 8573 atomic_set(&vha->loop_down_timer, 0); 8574 atomic_set(&vha->loop_state, LOOP_UP); 8575 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); 8576 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); 8577 rval = qla2x00_loop_resync(base_vha); 8578 8579 return rval; 8580 } 8581 8582 /* 84XX Support **************************************************************/ 8583 8584 static LIST_HEAD(qla_cs84xx_list); 8585 static DEFINE_MUTEX(qla_cs84xx_mutex); 8586 8587 static struct qla_chip_state_84xx * 8588 qla84xx_get_chip(struct scsi_qla_host *vha) 8589 { 8590 struct qla_chip_state_84xx *cs84xx; 8591 struct qla_hw_data *ha = vha->hw; 8592 8593 mutex_lock(&qla_cs84xx_mutex); 8594 8595 /* Find any shared 84xx chip. */ 8596 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) { 8597 if (cs84xx->bus == ha->pdev->bus) { 8598 kref_get(&cs84xx->kref); 8599 goto done; 8600 } 8601 } 8602 8603 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL); 8604 if (!cs84xx) 8605 goto done; 8606 8607 kref_init(&cs84xx->kref); 8608 spin_lock_init(&cs84xx->access_lock); 8609 mutex_init(&cs84xx->fw_update_mutex); 8610 cs84xx->bus = ha->pdev->bus; 8611 8612 list_add_tail(&cs84xx->list, &qla_cs84xx_list); 8613 done: 8614 mutex_unlock(&qla_cs84xx_mutex); 8615 return cs84xx; 8616 } 8617 8618 static void 8619 __qla84xx_chip_release(struct kref *kref) 8620 { 8621 struct qla_chip_state_84xx *cs84xx = 8622 container_of(kref, struct qla_chip_state_84xx, kref); 8623 8624 mutex_lock(&qla_cs84xx_mutex); 8625 list_del(&cs84xx->list); 8626 mutex_unlock(&qla_cs84xx_mutex); 8627 kfree(cs84xx); 8628 } 8629 8630 void 8631 qla84xx_put_chip(struct scsi_qla_host *vha) 8632 { 8633 struct qla_hw_data *ha = vha->hw; 8634 8635 if (ha->cs84xx) 8636 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release); 8637 } 8638 8639 static int 8640 qla84xx_init_chip(scsi_qla_host_t *vha) 8641 { 8642 int rval; 8643 uint16_t status[2]; 8644 struct qla_hw_data *ha = vha->hw; 8645 8646 mutex_lock(&ha->cs84xx->fw_update_mutex); 8647 8648 rval = qla84xx_verify_chip(vha, status); 8649 8650 mutex_unlock(&ha->cs84xx->fw_update_mutex); 8651 8652 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED : 8653 QLA_SUCCESS; 8654 } 8655 8656 /* 81XX Support **************************************************************/ 8657 8658 int 8659 qla81xx_nvram_config(scsi_qla_host_t *vha) 8660 { 8661 int rval; 8662 struct init_cb_81xx *icb; 8663 struct nvram_81xx *nv; 8664 __le32 *dptr; 8665 uint8_t *dptr1, *dptr2; 8666 uint32_t chksum; 8667 uint16_t cnt; 8668 struct qla_hw_data *ha = vha->hw; 8669 uint32_t faddr; 8670 struct active_regions active_regions = { }; 8671 8672 rval = QLA_SUCCESS; 8673 icb = (struct init_cb_81xx *)ha->init_cb; 8674 nv = ha->nvram; 8675 8676 /* Determine NVRAM starting address. */ 8677 ha->nvram_size = sizeof(*nv); 8678 ha->vpd_size = FA_NVRAM_VPD_SIZE; 8679 if (IS_P3P_TYPE(ha) || IS_QLA8031(ha)) 8680 ha->vpd_size = FA_VPD_SIZE_82XX; 8681 8682 if (IS_QLA28XX(ha) || IS_QLA27XX(ha)) 8683 qla28xx_get_aux_images(vha, &active_regions); 8684 8685 /* Get VPD data into cache */ 8686 ha->vpd = ha->nvram + VPD_OFFSET; 8687 8688 faddr = ha->flt_region_vpd; 8689 if (IS_QLA28XX(ha)) { 8690 if (active_regions.aux.vpd_nvram == QLA27XX_SECONDARY_IMAGE) 8691 faddr = ha->flt_region_vpd_sec; 8692 ql_dbg(ql_dbg_init, vha, 0x0110, 8693 "Loading %s nvram image.\n", 8694 active_regions.aux.vpd_nvram == QLA27XX_PRIMARY_IMAGE ? 8695 "primary" : "secondary"); 8696 } 8697 ha->isp_ops->read_optrom(vha, ha->vpd, faddr << 2, ha->vpd_size); 8698 8699 /* Get NVRAM data into cache and calculate checksum. */ 8700 faddr = ha->flt_region_nvram; 8701 if (IS_QLA28XX(ha)) { 8702 if (active_regions.aux.vpd_nvram == QLA27XX_SECONDARY_IMAGE) 8703 faddr = ha->flt_region_nvram_sec; 8704 } 8705 ql_dbg(ql_dbg_init, vha, 0x0110, 8706 "Loading %s nvram image.\n", 8707 active_regions.aux.vpd_nvram == QLA27XX_PRIMARY_IMAGE ? 8708 "primary" : "secondary"); 8709 ha->isp_ops->read_optrom(vha, ha->nvram, faddr << 2, ha->nvram_size); 8710 8711 dptr = (__force __le32 *)nv; 8712 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++) 8713 chksum += le32_to_cpu(*dptr); 8714 8715 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0111, 8716 "Contents of NVRAM:\n"); 8717 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0112, 8718 nv, ha->nvram_size); 8719 8720 /* Bad NVRAM data, set defaults parameters. */ 8721 if (chksum || memcmp("ISP ", nv->id, sizeof(nv->id)) || 8722 le16_to_cpu(nv->nvram_version) < ICB_VERSION) { 8723 /* Reset NVRAM data. */ 8724 ql_log(ql_log_info, vha, 0x0073, 8725 "Inconsistent NVRAM checksum=%#x id=%.4s version=%#x.\n", 8726 chksum, nv->id, le16_to_cpu(nv->nvram_version)); 8727 ql_dump_buffer(ql_dbg_init, vha, 0x0073, nv, sizeof(*nv)); 8728 ql_log(ql_log_info, vha, 0x0074, 8729 "Falling back to functioning (yet invalid -- WWPN) " 8730 "defaults.\n"); 8731 8732 /* 8733 * Set default initialization control block. 8734 */ 8735 memset(nv, 0, ha->nvram_size); 8736 nv->nvram_version = cpu_to_le16(ICB_VERSION); 8737 nv->version = cpu_to_le16(ICB_VERSION); 8738 nv->frame_payload_size = cpu_to_le16(2048); 8739 nv->execution_throttle = cpu_to_le16(0xFFFF); 8740 nv->exchange_count = cpu_to_le16(0); 8741 nv->port_name[0] = 0x21; 8742 nv->port_name[1] = 0x00 + ha->port_no + 1; 8743 nv->port_name[2] = 0x00; 8744 nv->port_name[3] = 0xe0; 8745 nv->port_name[4] = 0x8b; 8746 nv->port_name[5] = 0x1c; 8747 nv->port_name[6] = 0x55; 8748 nv->port_name[7] = 0x86; 8749 nv->node_name[0] = 0x20; 8750 nv->node_name[1] = 0x00; 8751 nv->node_name[2] = 0x00; 8752 nv->node_name[3] = 0xe0; 8753 nv->node_name[4] = 0x8b; 8754 nv->node_name[5] = 0x1c; 8755 nv->node_name[6] = 0x55; 8756 nv->node_name[7] = 0x86; 8757 nv->login_retry_count = cpu_to_le16(8); 8758 nv->interrupt_delay_timer = cpu_to_le16(0); 8759 nv->login_timeout = cpu_to_le16(0); 8760 nv->firmware_options_1 = 8761 cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1); 8762 nv->firmware_options_2 = cpu_to_le32(2 << 4); 8763 nv->firmware_options_2 |= cpu_to_le32(BIT_12); 8764 nv->firmware_options_3 = cpu_to_le32(2 << 13); 8765 nv->host_p = cpu_to_le32(BIT_11|BIT_10); 8766 nv->efi_parameters = cpu_to_le32(0); 8767 nv->reset_delay = 5; 8768 nv->max_luns_per_target = cpu_to_le16(128); 8769 nv->port_down_retry_count = cpu_to_le16(30); 8770 nv->link_down_timeout = cpu_to_le16(180); 8771 nv->enode_mac[0] = 0x00; 8772 nv->enode_mac[1] = 0xC0; 8773 nv->enode_mac[2] = 0xDD; 8774 nv->enode_mac[3] = 0x04; 8775 nv->enode_mac[4] = 0x05; 8776 nv->enode_mac[5] = 0x06 + ha->port_no + 1; 8777 8778 rval = 1; 8779 } 8780 8781 if (IS_T10_PI_CAPABLE(ha)) 8782 nv->frame_payload_size &= cpu_to_le16(~7); 8783 8784 qlt_81xx_config_nvram_stage1(vha, nv); 8785 8786 /* Reset Initialization control block */ 8787 memset(icb, 0, ha->init_cb_size); 8788 8789 /* Copy 1st segment. */ 8790 dptr1 = (uint8_t *)icb; 8791 dptr2 = (uint8_t *)&nv->version; 8792 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version; 8793 while (cnt--) 8794 *dptr1++ = *dptr2++; 8795 8796 icb->login_retry_count = nv->login_retry_count; 8797 8798 /* Copy 2nd segment. */ 8799 dptr1 = (uint8_t *)&icb->interrupt_delay_timer; 8800 dptr2 = (uint8_t *)&nv->interrupt_delay_timer; 8801 cnt = (uint8_t *)&icb->reserved_5 - 8802 (uint8_t *)&icb->interrupt_delay_timer; 8803 while (cnt--) 8804 *dptr1++ = *dptr2++; 8805 8806 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac)); 8807 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */ 8808 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) { 8809 icb->enode_mac[0] = 0x00; 8810 icb->enode_mac[1] = 0xC0; 8811 icb->enode_mac[2] = 0xDD; 8812 icb->enode_mac[3] = 0x04; 8813 icb->enode_mac[4] = 0x05; 8814 icb->enode_mac[5] = 0x06 + ha->port_no + 1; 8815 } 8816 8817 /* Use extended-initialization control block. */ 8818 memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb)); 8819 ha->frame_payload_size = le16_to_cpu(icb->frame_payload_size); 8820 /* 8821 * Setup driver NVRAM options. 8822 */ 8823 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name), 8824 "QLE8XXX"); 8825 8826 qlt_81xx_config_nvram_stage2(vha, icb); 8827 8828 /* Use alternate WWN? */ 8829 if (nv->host_p & cpu_to_le32(BIT_15)) { 8830 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE); 8831 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE); 8832 } 8833 8834 /* Prepare nodename */ 8835 if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) { 8836 /* 8837 * Firmware will apply the following mask if the nodename was 8838 * not provided. 8839 */ 8840 memcpy(icb->node_name, icb->port_name, WWN_SIZE); 8841 icb->node_name[0] &= 0xF0; 8842 } 8843 8844 if (IS_QLA28XX(ha) || IS_QLA27XX(ha)) { 8845 if ((nv->enhanced_features & BIT_7) == 0) 8846 ha->flags.scm_supported_a = 1; 8847 } 8848 8849 /* Set host adapter parameters. */ 8850 ha->flags.disable_risc_code_load = 0; 8851 ha->flags.enable_lip_reset = 0; 8852 ha->flags.enable_lip_full_login = 8853 le32_to_cpu(nv->host_p) & BIT_10 ? 1 : 0; 8854 ha->flags.enable_target_reset = 8855 le32_to_cpu(nv->host_p) & BIT_11 ? 1 : 0; 8856 ha->flags.enable_led_scheme = 0; 8857 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1 : 0; 8858 8859 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) & 8860 (BIT_6 | BIT_5 | BIT_4)) >> 4; 8861 8862 /* save HBA serial number */ 8863 ha->serial0 = icb->port_name[5]; 8864 ha->serial1 = icb->port_name[6]; 8865 ha->serial2 = icb->port_name[7]; 8866 memcpy(vha->node_name, icb->node_name, WWN_SIZE); 8867 memcpy(vha->port_name, icb->port_name, WWN_SIZE); 8868 8869 icb->execution_throttle = cpu_to_le16(0xFFFF); 8870 8871 ha->retry_count = le16_to_cpu(nv->login_retry_count); 8872 8873 /* Set minimum login_timeout to 4 seconds. */ 8874 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout) 8875 nv->login_timeout = cpu_to_le16(ql2xlogintimeout); 8876 if (le16_to_cpu(nv->login_timeout) < 4) 8877 nv->login_timeout = cpu_to_le16(4); 8878 ha->login_timeout = le16_to_cpu(nv->login_timeout); 8879 8880 /* Set minimum RATOV to 100 tenths of a second. */ 8881 ha->r_a_tov = 100; 8882 8883 ha->loop_reset_delay = nv->reset_delay; 8884 8885 /* Link Down Timeout = 0: 8886 * 8887 * When Port Down timer expires we will start returning 8888 * I/O's to OS with "DID_NO_CONNECT". 8889 * 8890 * Link Down Timeout != 0: 8891 * 8892 * The driver waits for the link to come up after link down 8893 * before returning I/Os to OS with "DID_NO_CONNECT". 8894 */ 8895 if (le16_to_cpu(nv->link_down_timeout) == 0) { 8896 ha->loop_down_abort_time = 8897 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT); 8898 } else { 8899 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout); 8900 ha->loop_down_abort_time = 8901 (LOOP_DOWN_TIME - ha->link_down_timeout); 8902 } 8903 8904 /* Need enough time to try and get the port back. */ 8905 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count); 8906 if (qlport_down_retry) 8907 ha->port_down_retry_count = qlport_down_retry; 8908 8909 /* Set login_retry_count */ 8910 ha->login_retry_count = le16_to_cpu(nv->login_retry_count); 8911 if (ha->port_down_retry_count == 8912 le16_to_cpu(nv->port_down_retry_count) && 8913 ha->port_down_retry_count > 3) 8914 ha->login_retry_count = ha->port_down_retry_count; 8915 else if (ha->port_down_retry_count > (int)ha->login_retry_count) 8916 ha->login_retry_count = ha->port_down_retry_count; 8917 if (ql2xloginretrycount) 8918 ha->login_retry_count = ql2xloginretrycount; 8919 8920 /* if not running MSI-X we need handshaking on interrupts */ 8921 if (!vha->hw->flags.msix_enabled && 8922 (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha))) 8923 icb->firmware_options_2 |= cpu_to_le32(BIT_22); 8924 8925 /* Enable ZIO. */ 8926 if (!vha->flags.init_done) { 8927 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) & 8928 (BIT_3 | BIT_2 | BIT_1 | BIT_0); 8929 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ? 8930 le16_to_cpu(icb->interrupt_delay_timer) : 2; 8931 } 8932 icb->firmware_options_2 &= cpu_to_le32( 8933 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0)); 8934 vha->flags.process_response_queue = 0; 8935 if (ha->zio_mode != QLA_ZIO_DISABLED) { 8936 ha->zio_mode = QLA_ZIO_MODE_6; 8937 8938 ql_log(ql_log_info, vha, 0x0075, 8939 "ZIO mode %d enabled; timer delay (%d us).\n", 8940 ha->zio_mode, 8941 ha->zio_timer * 100); 8942 8943 icb->firmware_options_2 |= cpu_to_le32( 8944 (uint32_t)ha->zio_mode); 8945 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer); 8946 vha->flags.process_response_queue = 1; 8947 } 8948 8949 /* enable RIDA Format2 */ 8950 icb->firmware_options_3 |= cpu_to_le32(BIT_0); 8951 8952 /* N2N: driver will initiate Login instead of FW */ 8953 icb->firmware_options_3 |= cpu_to_le32(BIT_8); 8954 8955 /* Determine NVMe/FCP priority for target ports */ 8956 ha->fc4_type_priority = qla2xxx_get_fc4_priority(vha); 8957 8958 if (rval) { 8959 ql_log(ql_log_warn, vha, 0x0076, 8960 "NVRAM configuration failed.\n"); 8961 } 8962 return (rval); 8963 } 8964 8965 int 8966 qla82xx_restart_isp(scsi_qla_host_t *vha) 8967 { 8968 int status, rval; 8969 struct qla_hw_data *ha = vha->hw; 8970 struct scsi_qla_host *vp, *tvp; 8971 unsigned long flags; 8972 8973 status = qla2x00_init_rings(vha); 8974 if (!status) { 8975 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); 8976 ha->flags.chip_reset_done = 1; 8977 8978 status = qla2x00_fw_ready(vha); 8979 if (!status) { 8980 /* Issue a marker after FW becomes ready. */ 8981 qla2x00_marker(vha, ha->base_qpair, 0, 0, MK_SYNC_ALL); 8982 vha->flags.online = 1; 8983 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); 8984 } 8985 8986 /* if no cable then assume it's good */ 8987 if ((vha->device_flags & DFLG_NO_CABLE)) 8988 status = 0; 8989 } 8990 8991 if (!status) { 8992 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); 8993 8994 if (!atomic_read(&vha->loop_down_timer)) { 8995 /* 8996 * Issue marker command only when we are going 8997 * to start the I/O . 8998 */ 8999 vha->marker_needed = 1; 9000 } 9001 9002 ha->isp_ops->enable_intrs(ha); 9003 9004 ha->isp_abort_cnt = 0; 9005 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags); 9006 9007 /* Update the firmware version */ 9008 status = qla82xx_check_md_needed(vha); 9009 9010 if (ha->fce) { 9011 ha->flags.fce_enabled = 1; 9012 memset(ha->fce, 0, 9013 fce_calc_size(ha->fce_bufs)); 9014 rval = qla2x00_enable_fce_trace(vha, 9015 ha->fce_dma, ha->fce_bufs, ha->fce_mb, 9016 &ha->fce_bufs); 9017 if (rval) { 9018 ql_log(ql_log_warn, vha, 0x8001, 9019 "Unable to reinitialize FCE (%d).\n", 9020 rval); 9021 ha->flags.fce_enabled = 0; 9022 } 9023 } 9024 9025 if (ha->eft) { 9026 memset(ha->eft, 0, EFT_SIZE); 9027 rval = qla2x00_enable_eft_trace(vha, 9028 ha->eft_dma, EFT_NUM_BUFFERS); 9029 if (rval) { 9030 ql_log(ql_log_warn, vha, 0x8010, 9031 "Unable to reinitialize EFT (%d).\n", 9032 rval); 9033 } 9034 } 9035 } 9036 9037 if (!status) { 9038 ql_dbg(ql_dbg_taskm, vha, 0x8011, 9039 "qla82xx_restart_isp succeeded.\n"); 9040 9041 spin_lock_irqsave(&ha->vport_slock, flags); 9042 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) { 9043 if (vp->vp_idx) { 9044 atomic_inc(&vp->vref_count); 9045 spin_unlock_irqrestore(&ha->vport_slock, flags); 9046 9047 qla2x00_vp_abort_isp(vp); 9048 9049 spin_lock_irqsave(&ha->vport_slock, flags); 9050 atomic_dec(&vp->vref_count); 9051 } 9052 } 9053 spin_unlock_irqrestore(&ha->vport_slock, flags); 9054 9055 } else { 9056 ql_log(ql_log_warn, vha, 0x8016, 9057 "qla82xx_restart_isp **** FAILED ****.\n"); 9058 } 9059 9060 return status; 9061 } 9062 9063 /* 9064 * qla24xx_get_fcp_prio 9065 * Gets the fcp cmd priority value for the logged in port. 9066 * Looks for a match of the port descriptors within 9067 * each of the fcp prio config entries. If a match is found, 9068 * the tag (priority) value is returned. 9069 * 9070 * Input: 9071 * vha = scsi host structure pointer. 9072 * fcport = port structure pointer. 9073 * 9074 * Return: 9075 * non-zero (if found) 9076 * -1 (if not found) 9077 * 9078 * Context: 9079 * Kernel context 9080 */ 9081 static int 9082 qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport) 9083 { 9084 int i, entries; 9085 uint8_t pid_match, wwn_match; 9086 int priority; 9087 uint32_t pid1, pid2; 9088 uint64_t wwn1, wwn2; 9089 struct qla_fcp_prio_entry *pri_entry; 9090 struct qla_hw_data *ha = vha->hw; 9091 9092 if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled) 9093 return -1; 9094 9095 priority = -1; 9096 entries = ha->fcp_prio_cfg->num_entries; 9097 pri_entry = &ha->fcp_prio_cfg->entry[0]; 9098 9099 for (i = 0; i < entries; i++) { 9100 pid_match = wwn_match = 0; 9101 9102 if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) { 9103 pri_entry++; 9104 continue; 9105 } 9106 9107 /* check source pid for a match */ 9108 if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) { 9109 pid1 = pri_entry->src_pid & INVALID_PORT_ID; 9110 pid2 = vha->d_id.b24 & INVALID_PORT_ID; 9111 if (pid1 == INVALID_PORT_ID) 9112 pid_match++; 9113 else if (pid1 == pid2) 9114 pid_match++; 9115 } 9116 9117 /* check destination pid for a match */ 9118 if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) { 9119 pid1 = pri_entry->dst_pid & INVALID_PORT_ID; 9120 pid2 = fcport->d_id.b24 & INVALID_PORT_ID; 9121 if (pid1 == INVALID_PORT_ID) 9122 pid_match++; 9123 else if (pid1 == pid2) 9124 pid_match++; 9125 } 9126 9127 /* check source WWN for a match */ 9128 if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) { 9129 wwn1 = wwn_to_u64(vha->port_name); 9130 wwn2 = wwn_to_u64(pri_entry->src_wwpn); 9131 if (wwn2 == (uint64_t)-1) 9132 wwn_match++; 9133 else if (wwn1 == wwn2) 9134 wwn_match++; 9135 } 9136 9137 /* check destination WWN for a match */ 9138 if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) { 9139 wwn1 = wwn_to_u64(fcport->port_name); 9140 wwn2 = wwn_to_u64(pri_entry->dst_wwpn); 9141 if (wwn2 == (uint64_t)-1) 9142 wwn_match++; 9143 else if (wwn1 == wwn2) 9144 wwn_match++; 9145 } 9146 9147 if (pid_match == 2 || wwn_match == 2) { 9148 /* Found a matching entry */ 9149 if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID) 9150 priority = pri_entry->tag; 9151 break; 9152 } 9153 9154 pri_entry++; 9155 } 9156 9157 return priority; 9158 } 9159 9160 /* 9161 * qla24xx_update_fcport_fcp_prio 9162 * Activates fcp priority for the logged in fc port 9163 * 9164 * Input: 9165 * vha = scsi host structure pointer. 9166 * fcp = port structure pointer. 9167 * 9168 * Return: 9169 * QLA_SUCCESS or QLA_FUNCTION_FAILED 9170 * 9171 * Context: 9172 * Kernel context. 9173 */ 9174 int 9175 qla24xx_update_fcport_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport) 9176 { 9177 int ret; 9178 int priority; 9179 uint16_t mb[5]; 9180 9181 if (fcport->port_type != FCT_TARGET || 9182 fcport->loop_id == FC_NO_LOOP_ID) 9183 return QLA_FUNCTION_FAILED; 9184 9185 priority = qla24xx_get_fcp_prio(vha, fcport); 9186 if (priority < 0) 9187 return QLA_FUNCTION_FAILED; 9188 9189 if (IS_P3P_TYPE(vha->hw)) { 9190 fcport->fcp_prio = priority & 0xf; 9191 return QLA_SUCCESS; 9192 } 9193 9194 ret = qla24xx_set_fcp_prio(vha, fcport->loop_id, priority, mb); 9195 if (ret == QLA_SUCCESS) { 9196 if (fcport->fcp_prio != priority) 9197 ql_dbg(ql_dbg_user, vha, 0x709e, 9198 "Updated FCP_CMND priority - value=%d loop_id=%d " 9199 "port_id=%02x%02x%02x.\n", priority, 9200 fcport->loop_id, fcport->d_id.b.domain, 9201 fcport->d_id.b.area, fcport->d_id.b.al_pa); 9202 fcport->fcp_prio = priority & 0xf; 9203 } else 9204 ql_dbg(ql_dbg_user, vha, 0x704f, 9205 "Unable to update FCP_CMND priority - ret=0x%x for " 9206 "loop_id=%d port_id=%02x%02x%02x.\n", ret, fcport->loop_id, 9207 fcport->d_id.b.domain, fcport->d_id.b.area, 9208 fcport->d_id.b.al_pa); 9209 return ret; 9210 } 9211 9212 /* 9213 * qla24xx_update_all_fcp_prio 9214 * Activates fcp priority for all the logged in ports 9215 * 9216 * Input: 9217 * ha = adapter block pointer. 9218 * 9219 * Return: 9220 * QLA_SUCCESS or QLA_FUNCTION_FAILED 9221 * 9222 * Context: 9223 * Kernel context. 9224 */ 9225 int 9226 qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha) 9227 { 9228 int ret; 9229 fc_port_t *fcport; 9230 9231 ret = QLA_FUNCTION_FAILED; 9232 /* We need to set priority for all logged in ports */ 9233 list_for_each_entry(fcport, &vha->vp_fcports, list) 9234 ret = qla24xx_update_fcport_fcp_prio(vha, fcport); 9235 9236 return ret; 9237 } 9238 9239 struct qla_qpair *qla2xxx_create_qpair(struct scsi_qla_host *vha, int qos, 9240 int vp_idx, bool startqp) 9241 { 9242 int rsp_id = 0; 9243 int req_id = 0; 9244 int i; 9245 struct qla_hw_data *ha = vha->hw; 9246 uint16_t qpair_id = 0; 9247 struct qla_qpair *qpair = NULL; 9248 struct qla_msix_entry *msix; 9249 9250 if (!(ha->fw_attributes & BIT_6) || !ha->flags.msix_enabled) { 9251 ql_log(ql_log_warn, vha, 0x00181, 9252 "FW/Driver is not multi-queue capable.\n"); 9253 return NULL; 9254 } 9255 9256 if (ql2xmqsupport || ql2xnvmeenable) { 9257 qpair = kzalloc(sizeof(struct qla_qpair), GFP_KERNEL); 9258 if (qpair == NULL) { 9259 ql_log(ql_log_warn, vha, 0x0182, 9260 "Failed to allocate memory for queue pair.\n"); 9261 return NULL; 9262 } 9263 9264 qpair->hw = vha->hw; 9265 qpair->vha = vha; 9266 qpair->qp_lock_ptr = &qpair->qp_lock; 9267 spin_lock_init(&qpair->qp_lock); 9268 qpair->use_shadow_reg = IS_SHADOW_REG_CAPABLE(ha) ? 1 : 0; 9269 9270 /* Assign available que pair id */ 9271 mutex_lock(&ha->mq_lock); 9272 qpair_id = find_first_zero_bit(ha->qpair_qid_map, ha->max_qpairs); 9273 if (ha->num_qpairs >= ha->max_qpairs) { 9274 mutex_unlock(&ha->mq_lock); 9275 ql_log(ql_log_warn, vha, 0x0183, 9276 "No resources to create additional q pair.\n"); 9277 goto fail_qid_map; 9278 } 9279 ha->num_qpairs++; 9280 set_bit(qpair_id, ha->qpair_qid_map); 9281 ha->queue_pair_map[qpair_id] = qpair; 9282 qpair->id = qpair_id; 9283 qpair->vp_idx = vp_idx; 9284 qpair->fw_started = ha->flags.fw_started; 9285 INIT_LIST_HEAD(&qpair->hints_list); 9286 qpair->chip_reset = ha->base_qpair->chip_reset; 9287 qpair->enable_class_2 = ha->base_qpair->enable_class_2; 9288 qpair->enable_explicit_conf = 9289 ha->base_qpair->enable_explicit_conf; 9290 9291 for (i = 0; i < ha->msix_count; i++) { 9292 msix = &ha->msix_entries[i]; 9293 if (msix->in_use) 9294 continue; 9295 qpair->msix = msix; 9296 ql_dbg(ql_dbg_multiq, vha, 0xc00f, 9297 "Vector %x selected for qpair\n", msix->vector); 9298 break; 9299 } 9300 if (!qpair->msix) { 9301 ql_log(ql_log_warn, vha, 0x0184, 9302 "Out of MSI-X vectors!.\n"); 9303 goto fail_msix; 9304 } 9305 9306 qpair->msix->in_use = 1; 9307 list_add_tail(&qpair->qp_list_elem, &vha->qp_list); 9308 qpair->pdev = ha->pdev; 9309 if (IS_QLA27XX(ha) || IS_QLA83XX(ha) || IS_QLA28XX(ha)) 9310 qpair->reqq_start_iocbs = qla_83xx_start_iocbs; 9311 9312 mutex_unlock(&ha->mq_lock); 9313 9314 /* Create response queue first */ 9315 rsp_id = qla25xx_create_rsp_que(ha, 0, 0, 0, qpair, startqp); 9316 if (!rsp_id) { 9317 ql_log(ql_log_warn, vha, 0x0185, 9318 "Failed to create response queue.\n"); 9319 goto fail_rsp; 9320 } 9321 9322 qpair->rsp = ha->rsp_q_map[rsp_id]; 9323 9324 /* Create request queue */ 9325 req_id = qla25xx_create_req_que(ha, 0, vp_idx, 0, rsp_id, qos, 9326 startqp); 9327 if (!req_id) { 9328 ql_log(ql_log_warn, vha, 0x0186, 9329 "Failed to create request queue.\n"); 9330 goto fail_req; 9331 } 9332 9333 qpair->req = ha->req_q_map[req_id]; 9334 qpair->rsp->req = qpair->req; 9335 qpair->rsp->qpair = qpair; 9336 /* init qpair to this cpu. Will adjust at run time. */ 9337 qla_cpu_update(qpair, smp_processor_id()); 9338 9339 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) { 9340 if (ha->fw_attributes & BIT_4) 9341 qpair->difdix_supported = 1; 9342 } 9343 9344 qpair->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep); 9345 if (!qpair->srb_mempool) { 9346 ql_log(ql_log_warn, vha, 0xd036, 9347 "Failed to create srb mempool for qpair %d\n", 9348 qpair->id); 9349 goto fail_mempool; 9350 } 9351 9352 /* Mark as online */ 9353 qpair->online = 1; 9354 9355 if (!vha->flags.qpairs_available) 9356 vha->flags.qpairs_available = 1; 9357 9358 ql_dbg(ql_dbg_multiq, vha, 0xc00d, 9359 "Request/Response queue pair created, id %d\n", 9360 qpair->id); 9361 ql_dbg(ql_dbg_init, vha, 0x0187, 9362 "Request/Response queue pair created, id %d\n", 9363 qpair->id); 9364 } 9365 return qpair; 9366 9367 fail_mempool: 9368 fail_req: 9369 qla25xx_delete_rsp_que(vha, qpair->rsp); 9370 fail_rsp: 9371 mutex_lock(&ha->mq_lock); 9372 qpair->msix->in_use = 0; 9373 list_del(&qpair->qp_list_elem); 9374 if (list_empty(&vha->qp_list)) 9375 vha->flags.qpairs_available = 0; 9376 fail_msix: 9377 ha->queue_pair_map[qpair_id] = NULL; 9378 clear_bit(qpair_id, ha->qpair_qid_map); 9379 ha->num_qpairs--; 9380 mutex_unlock(&ha->mq_lock); 9381 fail_qid_map: 9382 kfree(qpair); 9383 return NULL; 9384 } 9385 9386 int qla2xxx_delete_qpair(struct scsi_qla_host *vha, struct qla_qpair *qpair) 9387 { 9388 int ret = QLA_FUNCTION_FAILED; 9389 struct qla_hw_data *ha = qpair->hw; 9390 9391 qpair->delete_in_progress = 1; 9392 9393 ret = qla25xx_delete_req_que(vha, qpair->req); 9394 if (ret != QLA_SUCCESS) 9395 goto fail; 9396 9397 ret = qla25xx_delete_rsp_que(vha, qpair->rsp); 9398 if (ret != QLA_SUCCESS) 9399 goto fail; 9400 9401 mutex_lock(&ha->mq_lock); 9402 ha->queue_pair_map[qpair->id] = NULL; 9403 clear_bit(qpair->id, ha->qpair_qid_map); 9404 ha->num_qpairs--; 9405 list_del(&qpair->qp_list_elem); 9406 if (list_empty(&vha->qp_list)) { 9407 vha->flags.qpairs_available = 0; 9408 vha->flags.qpairs_req_created = 0; 9409 vha->flags.qpairs_rsp_created = 0; 9410 } 9411 mempool_destroy(qpair->srb_mempool); 9412 kfree(qpair); 9413 mutex_unlock(&ha->mq_lock); 9414 9415 return QLA_SUCCESS; 9416 fail: 9417 return ret; 9418 } 9419 9420 uint64_t 9421 qla2x00_count_set_bits(uint32_t num) 9422 { 9423 /* Brian Kernighan's Algorithm */ 9424 u64 count = 0; 9425 9426 while (num) { 9427 num &= (num - 1); 9428 count++; 9429 } 9430 return count; 9431 } 9432 9433 uint64_t 9434 qla2x00_get_num_tgts(scsi_qla_host_t *vha) 9435 { 9436 fc_port_t *f, *tf; 9437 u64 count = 0; 9438 9439 f = NULL; 9440 tf = NULL; 9441 9442 list_for_each_entry_safe(f, tf, &vha->vp_fcports, list) { 9443 if (f->port_type != FCT_TARGET) 9444 continue; 9445 count++; 9446 } 9447 return count; 9448 } 9449 9450 int qla2xxx_reset_stats(struct Scsi_Host *host, u32 flags) 9451 { 9452 scsi_qla_host_t *vha = shost_priv(host); 9453 fc_port_t *fcport = NULL; 9454 unsigned long int_flags; 9455 9456 if (flags & QLA2XX_HW_ERROR) 9457 vha->hw_err_cnt = 0; 9458 if (flags & QLA2XX_SHT_LNK_DWN) 9459 vha->short_link_down_cnt = 0; 9460 if (flags & QLA2XX_INT_ERR) 9461 vha->interface_err_cnt = 0; 9462 if (flags & QLA2XX_CMD_TIMEOUT) 9463 vha->cmd_timeout_cnt = 0; 9464 if (flags & QLA2XX_RESET_CMD_ERR) 9465 vha->reset_cmd_err_cnt = 0; 9466 if (flags & QLA2XX_TGT_SHT_LNK_DOWN) { 9467 spin_lock_irqsave(&vha->hw->tgt.sess_lock, int_flags); 9468 list_for_each_entry(fcport, &vha->vp_fcports, list) { 9469 fcport->tgt_short_link_down_cnt = 0; 9470 fcport->tgt_link_down_time = QLA2XX_MAX_LINK_DOWN_TIME; 9471 } 9472 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, int_flags); 9473 } 9474 vha->link_down_time = QLA2XX_MAX_LINK_DOWN_TIME; 9475 return 0; 9476 } 9477 9478 int qla2xxx_start_stats(struct Scsi_Host *host, u32 flags) 9479 { 9480 return qla2xxx_reset_stats(host, flags); 9481 } 9482 9483 int qla2xxx_stop_stats(struct Scsi_Host *host, u32 flags) 9484 { 9485 return qla2xxx_reset_stats(host, flags); 9486 } 9487 9488 int qla2xxx_get_ini_stats(struct Scsi_Host *host, u32 flags, 9489 void *data, u64 size) 9490 { 9491 scsi_qla_host_t *vha = shost_priv(host); 9492 struct ql_vnd_host_stats_resp *resp = (struct ql_vnd_host_stats_resp *)data; 9493 struct ql_vnd_stats *rsp_data = &resp->stats; 9494 u64 ini_entry_count = 0; 9495 u64 i = 0; 9496 u64 entry_count = 0; 9497 u64 num_tgt = 0; 9498 u32 tmp_stat_type = 0; 9499 fc_port_t *fcport = NULL; 9500 unsigned long int_flags; 9501 9502 /* Copy stat type to work on it */ 9503 tmp_stat_type = flags; 9504 9505 if (tmp_stat_type & BIT_17) { 9506 num_tgt = qla2x00_get_num_tgts(vha); 9507 /* unset BIT_17 */ 9508 tmp_stat_type &= ~(1 << 17); 9509 } 9510 ini_entry_count = qla2x00_count_set_bits(tmp_stat_type); 9511 9512 entry_count = ini_entry_count + num_tgt; 9513 9514 rsp_data->entry_count = entry_count; 9515 9516 i = 0; 9517 if (flags & QLA2XX_HW_ERROR) { 9518 rsp_data->entry[i].stat_type = QLA2XX_HW_ERROR; 9519 rsp_data->entry[i].tgt_num = 0x0; 9520 rsp_data->entry[i].cnt = vha->hw_err_cnt; 9521 i++; 9522 } 9523 9524 if (flags & QLA2XX_SHT_LNK_DWN) { 9525 rsp_data->entry[i].stat_type = QLA2XX_SHT_LNK_DWN; 9526 rsp_data->entry[i].tgt_num = 0x0; 9527 rsp_data->entry[i].cnt = vha->short_link_down_cnt; 9528 i++; 9529 } 9530 9531 if (flags & QLA2XX_INT_ERR) { 9532 rsp_data->entry[i].stat_type = QLA2XX_INT_ERR; 9533 rsp_data->entry[i].tgt_num = 0x0; 9534 rsp_data->entry[i].cnt = vha->interface_err_cnt; 9535 i++; 9536 } 9537 9538 if (flags & QLA2XX_CMD_TIMEOUT) { 9539 rsp_data->entry[i].stat_type = QLA2XX_CMD_TIMEOUT; 9540 rsp_data->entry[i].tgt_num = 0x0; 9541 rsp_data->entry[i].cnt = vha->cmd_timeout_cnt; 9542 i++; 9543 } 9544 9545 if (flags & QLA2XX_RESET_CMD_ERR) { 9546 rsp_data->entry[i].stat_type = QLA2XX_RESET_CMD_ERR; 9547 rsp_data->entry[i].tgt_num = 0x0; 9548 rsp_data->entry[i].cnt = vha->reset_cmd_err_cnt; 9549 i++; 9550 } 9551 9552 /* i will continue from previous loop, as target 9553 * entries are after initiator 9554 */ 9555 if (flags & QLA2XX_TGT_SHT_LNK_DOWN) { 9556 spin_lock_irqsave(&vha->hw->tgt.sess_lock, int_flags); 9557 list_for_each_entry(fcport, &vha->vp_fcports, list) { 9558 if (fcport->port_type != FCT_TARGET) 9559 continue; 9560 if (!fcport->rport) 9561 continue; 9562 rsp_data->entry[i].stat_type = QLA2XX_TGT_SHT_LNK_DOWN; 9563 rsp_data->entry[i].tgt_num = fcport->rport->number; 9564 rsp_data->entry[i].cnt = fcport->tgt_short_link_down_cnt; 9565 i++; 9566 } 9567 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, int_flags); 9568 } 9569 resp->status = EXT_STATUS_OK; 9570 9571 return 0; 9572 } 9573 9574 int qla2xxx_get_tgt_stats(struct Scsi_Host *host, u32 flags, 9575 struct fc_rport *rport, void *data, u64 size) 9576 { 9577 struct ql_vnd_tgt_stats_resp *tgt_data = data; 9578 fc_port_t *fcport = *(fc_port_t **)rport->dd_data; 9579 9580 tgt_data->status = 0; 9581 tgt_data->stats.entry_count = 1; 9582 tgt_data->stats.entry[0].stat_type = flags; 9583 tgt_data->stats.entry[0].tgt_num = rport->number; 9584 tgt_data->stats.entry[0].cnt = fcport->tgt_short_link_down_cnt; 9585 9586 return 0; 9587 } 9588 9589 int qla2xxx_disable_port(struct Scsi_Host *host) 9590 { 9591 scsi_qla_host_t *vha = shost_priv(host); 9592 9593 vha->hw->flags.port_isolated = 1; 9594 9595 if (qla2x00_chip_is_down(vha)) 9596 return 0; 9597 9598 if (vha->flags.online) { 9599 qla2x00_abort_isp_cleanup(vha); 9600 qla2x00_wait_for_sess_deletion(vha); 9601 } 9602 9603 return 0; 9604 } 9605 9606 int qla2xxx_enable_port(struct Scsi_Host *host) 9607 { 9608 scsi_qla_host_t *vha = shost_priv(host); 9609 9610 vha->hw->flags.port_isolated = 0; 9611 /* Set the flag to 1, so that isp_abort can proceed */ 9612 vha->flags.online = 1; 9613 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); 9614 qla2xxx_wake_dpc(vha); 9615 9616 return 0; 9617 } 9618