2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2014 QLogic Corporation
5 * See LICENSE.qla2xxx for copyright and licensing details.
10 #include <linux/delay.h>
11 #include <linux/slab.h>
12 #include <linux/vmalloc.h>
14 #include "qla_devtbl.h"
20 #include <target/target_core_base.h>
21 #include "qla_target.h"
24 * QLogic ISP2x00 Hardware Support Function Prototypes.
26 static int qla2x00_isp_firmware(scsi_qla_host_t *);
27 static int qla2x00_setup_chip(scsi_qla_host_t *);
28 static int qla2x00_fw_ready(scsi_qla_host_t *);
29 static int qla2x00_configure_hba(scsi_qla_host_t *);
30 static int qla2x00_configure_loop(scsi_qla_host_t *);
31 static int qla2x00_configure_local_loop(scsi_qla_host_t *);
32 static int qla2x00_configure_fabric(scsi_qla_host_t *);
33 static int qla2x00_find_all_fabric_devs(scsi_qla_host_t *);
34 static int qla2x00_restart_isp(scsi_qla_host_t *);
36 static struct qla_chip_state_84xx *qla84xx_get_chip(struct scsi_qla_host *);
37 static int qla84xx_init_chip(scsi_qla_host_t *);
38 static int qla25xx_init_queues(struct qla_hw_data *);
39 static int qla24xx_post_prli_work(struct scsi_qla_host*, fc_port_t *);
40 static void qla24xx_handle_plogi_done_event(struct scsi_qla_host *,
42 static void qla24xx_handle_prli_done_event(struct scsi_qla_host *,
45 /* SRB Extensions ---------------------------------------------------------- */
48 qla2x00_sp_timeout(unsigned long __data)
50 srb_t *sp = (srb_t *)__data;
51 struct srb_iocb *iocb;
52 scsi_qla_host_t *vha = sp->vha;
56 spin_lock_irqsave(&vha->hw->hardware_lock, flags);
57 req = vha->hw->req_q_map[0];
58 req->outstanding_cmds[sp->handle] = NULL;
59 iocb = &sp->u.iocb_cmd;
62 spin_unlock_irqrestore(&vha->hw->hardware_lock, flags);
66 qla2x00_sp_free(void *ptr)
69 struct srb_iocb *iocb = &sp->u.iocb_cmd;
71 del_timer(&iocb->timer);
75 /* Asynchronous Login/Logout Routines -------------------------------------- */
78 qla2x00_get_async_timeout(struct scsi_qla_host *vha)
81 struct qla_hw_data *ha = vha->hw;
83 /* Firmware should use switch negotiated r_a_tov for timeout. */
84 tmo = ha->r_a_tov / 10 * 2;
86 tmo = FX00_DEF_RATOV * 2;
87 } else if (!IS_FWI2_CAPABLE(ha)) {
89 * Except for earlier ISPs where the timeout is seeded from the
90 * initialization control block.
92 tmo = ha->login_timeout;
98 qla2x00_async_iocb_timeout(void *data)
101 fc_port_t *fcport = sp->fcport;
102 struct srb_iocb *lio = &sp->u.iocb_cmd;
106 ql_dbg(ql_dbg_disc, fcport->vha, 0x2071,
107 "Async-%s timeout - hdl=%x portid=%06x %8phC.\n",
108 sp->name, sp->handle, fcport->d_id.b24, fcport->port_name);
110 fcport->flags &= ~FCF_ASYNC_SENT;
112 pr_info("Async-%s timeout - hdl=%x.\n",
113 sp->name, sp->handle);
120 /* Retry as needed. */
121 lio->u.logio.data[0] = MBS_COMMAND_ERROR;
122 lio->u.logio.data[1] = lio->u.logio.flags & SRB_LOGIN_RETRIED ?
123 QLA_LOGIO_LOGIN_RETRIED : 0;
124 memset(&ea, 0, sizeof(ea));
125 ea.event = FCME_PLOGI_DONE;
126 ea.fcport = sp->fcport;
127 ea.data[0] = lio->u.logio.data[0];
128 ea.data[1] = lio->u.logio.data[1];
130 qla24xx_handle_plogi_done_event(fcport->vha, &ea);
135 qlt_logo_completion_handler(fcport, QLA_FUNCTION_TIMEOUT);
137 case SRB_CT_PTHRU_CMD:
142 sp->done(sp, QLA_FUNCTION_TIMEOUT);
148 qla2x00_async_login_sp_done(void *ptr, int res)
151 struct scsi_qla_host *vha = sp->vha;
152 struct srb_iocb *lio = &sp->u.iocb_cmd;
155 ql_dbg(ql_dbg_disc, vha, 0x20dd,
156 "%s %8phC res %d \n", __func__, sp->fcport->port_name, res);
158 sp->fcport->flags &= ~FCF_ASYNC_SENT;
159 if (!test_bit(UNLOADING, &vha->dpc_flags)) {
160 memset(&ea, 0, sizeof(ea));
161 ea.event = FCME_PLOGI_DONE;
162 ea.fcport = sp->fcport;
163 ea.data[0] = lio->u.logio.data[0];
164 ea.data[1] = lio->u.logio.data[1];
165 ea.iop[0] = lio->u.logio.iop[0];
166 ea.iop[1] = lio->u.logio.iop[1];
168 qla2x00_fcport_event_handler(vha, &ea);
175 qla2x00_async_login(struct scsi_qla_host *vha, fc_port_t *fcport,
179 struct srb_iocb *lio;
180 int rval = QLA_FUNCTION_FAILED;
182 if (!vha->flags.online)
185 if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
186 (fcport->fw_login_state == DSC_LS_PLOGI_COMP) ||
187 (fcport->fw_login_state == DSC_LS_PRLI_PEND))
190 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
194 fcport->flags |= FCF_ASYNC_SENT;
195 fcport->logout_completed = 0;
197 sp->type = SRB_LOGIN_CMD;
199 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
201 lio = &sp->u.iocb_cmd;
202 lio->timeout = qla2x00_async_iocb_timeout;
203 sp->done = qla2x00_async_login_sp_done;
204 lio->u.logio.flags |= SRB_LOGIN_COND_PLOGI;
206 if (fcport->fc4f_nvme)
207 lio->u.logio.flags |= SRB_LOGIN_SKIP_PRLI;
209 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
210 lio->u.logio.flags |= SRB_LOGIN_RETRIED;
211 rval = qla2x00_start_sp(sp);
212 if (rval != QLA_SUCCESS) {
213 fcport->flags &= ~FCF_ASYNC_SENT;
214 fcport->flags |= FCF_LOGIN_NEEDED;
215 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
219 ql_dbg(ql_dbg_disc, vha, 0x2072,
220 "Async-login - %8phC hdl=%x, loopid=%x portid=%02x%02x%02x "
221 "retries=%d.\n", fcport->port_name, sp->handle, fcport->loop_id,
222 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa,
223 fcport->login_retry);
229 fcport->flags &= ~FCF_ASYNC_SENT;
234 qla2x00_async_logout_sp_done(void *ptr, int res)
237 struct srb_iocb *lio = &sp->u.iocb_cmd;
239 sp->fcport->flags &= ~FCF_ASYNC_SENT;
240 if (!test_bit(UNLOADING, &sp->vha->dpc_flags))
241 qla2x00_post_async_logout_done_work(sp->vha, sp->fcport,
247 qla2x00_async_logout(struct scsi_qla_host *vha, fc_port_t *fcport)
250 struct srb_iocb *lio;
253 rval = QLA_FUNCTION_FAILED;
254 fcport->flags |= FCF_ASYNC_SENT;
255 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
259 sp->type = SRB_LOGOUT_CMD;
261 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
263 lio = &sp->u.iocb_cmd;
264 lio->timeout = qla2x00_async_iocb_timeout;
265 sp->done = qla2x00_async_logout_sp_done;
266 rval = qla2x00_start_sp(sp);
267 if (rval != QLA_SUCCESS)
270 ql_dbg(ql_dbg_disc, vha, 0x2070,
271 "Async-logout - hdl=%x loop-id=%x portid=%02x%02x%02x %8phC.\n",
272 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
273 fcport->d_id.b.area, fcport->d_id.b.al_pa,
280 fcport->flags &= ~FCF_ASYNC_SENT;
285 qla2x00_async_adisc_sp_done(void *ptr, int res)
288 struct scsi_qla_host *vha = sp->vha;
289 struct srb_iocb *lio = &sp->u.iocb_cmd;
291 if (!test_bit(UNLOADING, &vha->dpc_flags))
292 qla2x00_post_async_adisc_done_work(sp->vha, sp->fcport,
298 qla2x00_async_adisc(struct scsi_qla_host *vha, fc_port_t *fcport,
302 struct srb_iocb *lio;
305 rval = QLA_FUNCTION_FAILED;
306 fcport->flags |= FCF_ASYNC_SENT;
307 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
311 sp->type = SRB_ADISC_CMD;
313 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
315 lio = &sp->u.iocb_cmd;
316 lio->timeout = qla2x00_async_iocb_timeout;
317 sp->done = qla2x00_async_adisc_sp_done;
318 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
319 lio->u.logio.flags |= SRB_LOGIN_RETRIED;
320 rval = qla2x00_start_sp(sp);
321 if (rval != QLA_SUCCESS)
324 ql_dbg(ql_dbg_disc, vha, 0x206f,
325 "Async-adisc - hdl=%x loopid=%x portid=%02x%02x%02x.\n",
326 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
327 fcport->d_id.b.area, fcport->d_id.b.al_pa);
333 fcport->flags &= ~FCF_ASYNC_SENT;
337 static void qla24xx_handle_gnl_done_event(scsi_qla_host_t *vha,
338 struct event_arg *ea)
340 fc_port_t *fcport, *conflict_fcport;
341 struct get_name_list_extended *e;
342 u16 i, n, found = 0, loop_id;
345 u8 opt = 0, current_login_state;
349 if (ea->rc) { /* rval */
350 if (fcport->login_retry == 0) {
351 fcport->login_retry = vha->hw->login_retry_count;
352 ql_dbg(ql_dbg_disc, vha, 0x20de,
353 "GNL failed Port login retry %8phN, retry cnt=%d.\n",
354 fcport->port_name, fcport->login_retry);
359 if (fcport->last_rscn_gen != fcport->rscn_gen) {
360 ql_dbg(ql_dbg_disc, vha, 0x20df,
361 "%s %8phC rscn gen changed rscn %d|%d \n",
362 __func__, fcport->port_name,
363 fcport->last_rscn_gen, fcport->rscn_gen);
364 qla24xx_post_gidpn_work(vha, fcport);
366 } else if (fcport->last_login_gen != fcport->login_gen) {
367 ql_dbg(ql_dbg_disc, vha, 0x20e0,
368 "%s %8phC login gen changed login %d|%d\n",
369 __func__, fcport->port_name,
370 fcport->last_login_gen, fcport->login_gen);
374 n = ea->data[0] / sizeof(struct get_name_list_extended);
376 ql_dbg(ql_dbg_disc, vha, 0x20e1,
377 "%s %d %8phC n %d %02x%02x%02x lid %d \n",
378 __func__, __LINE__, fcport->port_name, n,
379 fcport->d_id.b.domain, fcport->d_id.b.area,
380 fcport->d_id.b.al_pa, fcport->loop_id);
382 for (i = 0; i < n; i++) {
384 wwn = wwn_to_u64(e->port_name);
386 if (memcmp((u8 *)&wwn, fcport->port_name, WWN_SIZE))
390 id.b.domain = e->port_id[2];
391 id.b.area = e->port_id[1];
392 id.b.al_pa = e->port_id[0];
395 loop_id = le16_to_cpu(e->nport_handle);
396 loop_id = (loop_id & 0x7fff);
398 ql_dbg(ql_dbg_disc, vha, 0x20e2,
399 "%s found %8phC CLS [%d|%d] ID[%02x%02x%02x|%02x%02x%02x] lid[%d|%d]\n",
400 __func__, fcport->port_name,
401 e->current_login_state, fcport->fw_login_state,
402 id.b.domain, id.b.area, id.b.al_pa,
403 fcport->d_id.b.domain, fcport->d_id.b.area,
404 fcport->d_id.b.al_pa, loop_id, fcport->loop_id);
406 if ((id.b24 != fcport->d_id.b24) ||
407 ((fcport->loop_id != FC_NO_LOOP_ID) &&
408 (fcport->loop_id != loop_id))) {
409 ql_dbg(ql_dbg_disc, vha, 0x20e3,
410 "%s %d %8phC post del sess\n",
411 __func__, __LINE__, fcport->port_name);
412 qlt_schedule_sess_for_deletion(fcport, 1);
416 fcport->loop_id = loop_id;
418 wwn = wwn_to_u64(fcport->port_name);
419 qlt_find_sess_invalidate_other(vha, wwn,
420 id, loop_id, &conflict_fcport);
422 if (conflict_fcport) {
424 * Another share fcport share the same loop_id &
425 * nport id. Conflict fcport needs to finish
426 * cleanup before this fcport can proceed to login.
428 conflict_fcport->conflict = fcport;
429 fcport->login_pause = 1;
432 if (fcport->fc4f_nvme)
433 current_login_state = e->current_login_state >> 4;
435 current_login_state = e->current_login_state & 0xf;
437 switch (current_login_state) {
438 case DSC_LS_PRLI_COMP:
439 ql_dbg(ql_dbg_disc, vha, 0x20e4,
440 "%s %d %8phC post gpdb\n",
441 __func__, __LINE__, fcport->port_name);
442 opt = PDO_FORCE_ADISC;
443 qla24xx_post_gpdb_work(vha, fcport, opt);
445 case DSC_LS_PORT_UNAVAIL:
447 if (fcport->loop_id == FC_NO_LOOP_ID) {
448 qla2x00_find_new_loop_id(vha, fcport);
449 fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
451 ql_dbg(ql_dbg_disc, vha, 0x20e5,
453 __func__, __LINE__, fcport->port_name);
454 qla24xx_fcport_handle_login(vha, fcport);
460 /* fw has no record of this port */
461 if (fcport->loop_id == FC_NO_LOOP_ID) {
462 qla2x00_find_new_loop_id(vha, fcport);
463 fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
465 for (i = 0; i < n; i++) {
467 id.b.domain = e->port_id[0];
468 id.b.area = e->port_id[1];
469 id.b.al_pa = e->port_id[2];
471 loop_id = le16_to_cpu(e->nport_handle);
473 if (fcport->d_id.b24 == id.b24) {
475 qla2x00_find_fcport_by_wwpn(vha,
478 ql_dbg(ql_dbg_disc, vha, 0x20e6,
479 "%s %d %8phC post del sess\n",
481 conflict_fcport->port_name);
482 qlt_schedule_sess_for_deletion
483 (conflict_fcport, 1);
486 if (fcport->loop_id == loop_id) {
487 /* FW already picked this loop id for another fcport */
488 qla2x00_find_new_loop_id(vha, fcport);
492 qla24xx_fcport_handle_login(vha, fcport);
497 qla24xx_async_gnl_sp_done(void *s, int res)
500 struct scsi_qla_host *vha = sp->vha;
502 struct fc_port *fcport = NULL, *tf;
503 u16 i, n = 0, loop_id;
505 struct get_name_list_extended *e;
509 ql_dbg(ql_dbg_disc, vha, 0x20e7,
510 "Async done-%s res %x mb[1]=%x mb[2]=%x \n",
511 sp->name, res, sp->u.iocb_cmd.u.mbx.in_mb[1],
512 sp->u.iocb_cmd.u.mbx.in_mb[2]);
514 memset(&ea, 0, sizeof(ea));
517 ea.event = FCME_GNL_DONE;
519 if (sp->u.iocb_cmd.u.mbx.in_mb[1] >=
520 sizeof(struct get_name_list_extended)) {
521 n = sp->u.iocb_cmd.u.mbx.in_mb[1] /
522 sizeof(struct get_name_list_extended);
523 ea.data[0] = sp->u.iocb_cmd.u.mbx.in_mb[1]; /* amnt xfered */
526 for (i = 0; i < n; i++) {
528 loop_id = le16_to_cpu(e->nport_handle);
529 /* mask out reserve bit */
530 loop_id = (loop_id & 0x7fff);
531 set_bit(loop_id, vha->hw->loop_id_map);
532 wwn = wwn_to_u64(e->port_name);
534 ql_dbg(ql_dbg_disc + ql_dbg_verbose, vha, 0x20e8,
535 "%s %8phC %02x:%02x:%02x state %d/%d lid %x \n",
536 __func__, (void *)&wwn, e->port_id[2], e->port_id[1],
537 e->port_id[0], e->current_login_state, e->last_login_state,
541 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
546 if (!list_empty(&vha->gnl.fcports))
547 list_splice_init(&vha->gnl.fcports, &h);
549 list_for_each_entry_safe(fcport, tf, &h, gnl_entry) {
550 list_del_init(&fcport->gnl_entry);
551 fcport->flags &= ~FCF_ASYNC_SENT;
554 qla2x00_fcport_event_handler(vha, &ea);
557 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
562 int qla24xx_async_gnl(struct scsi_qla_host *vha, fc_port_t *fcport)
565 struct srb_iocb *mbx;
566 int rval = QLA_FUNCTION_FAILED;
570 if (!vha->flags.online)
573 ql_dbg(ql_dbg_disc, vha, 0x20d9,
574 "Async-gnlist WWPN %8phC \n", fcport->port_name);
576 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
577 fcport->flags |= FCF_ASYNC_SENT;
578 fcport->disc_state = DSC_GNL;
579 fcport->last_rscn_gen = fcport->rscn_gen;
580 fcport->last_login_gen = fcport->login_gen;
582 list_add_tail(&fcport->gnl_entry, &vha->gnl.fcports);
584 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
589 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
591 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
594 sp->type = SRB_MB_IOCB;
596 sp->gen1 = fcport->rscn_gen;
597 sp->gen2 = fcport->login_gen;
599 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha)+2);
601 mb = sp->u.iocb_cmd.u.mbx.out_mb;
602 mb[0] = MBC_PORT_NODE_NAME_LIST;
603 mb[1] = BIT_2 | BIT_3;
604 mb[2] = MSW(vha->gnl.ldma);
605 mb[3] = LSW(vha->gnl.ldma);
606 mb[6] = MSW(MSD(vha->gnl.ldma));
607 mb[7] = LSW(MSD(vha->gnl.ldma));
608 mb[8] = vha->gnl.size;
611 mbx = &sp->u.iocb_cmd;
612 mbx->timeout = qla2x00_async_iocb_timeout;
614 sp->done = qla24xx_async_gnl_sp_done;
616 rval = qla2x00_start_sp(sp);
617 if (rval != QLA_SUCCESS)
620 ql_dbg(ql_dbg_disc, vha, 0x20da,
621 "Async-%s - OUT WWPN %8phC hndl %x\n",
622 sp->name, fcport->port_name, sp->handle);
629 fcport->flags &= ~FCF_ASYNC_SENT;
633 int qla24xx_post_gnl_work(struct scsi_qla_host *vha, fc_port_t *fcport)
635 struct qla_work_evt *e;
637 e = qla2x00_alloc_work(vha, QLA_EVT_GNL);
639 return QLA_FUNCTION_FAILED;
641 e->u.fcport.fcport = fcport;
642 return qla2x00_post_work(vha, e);
646 void qla24xx_async_gpdb_sp_done(void *s, int res)
649 struct scsi_qla_host *vha = sp->vha;
650 struct qla_hw_data *ha = vha->hw;
651 struct port_database_24xx *pd;
652 fc_port_t *fcport = sp->fcport;
653 u16 *mb = sp->u.iocb_cmd.u.mbx.in_mb;
654 int rval = QLA_SUCCESS;
657 ql_dbg(ql_dbg_disc, vha, 0x20db,
658 "Async done-%s res %x, WWPN %8phC mb[1]=%x mb[2]=%x \n",
659 sp->name, res, fcport->port_name, mb[1], mb[2]);
661 fcport->flags &= ~FCF_ASYNC_SENT;
668 pd = (struct port_database_24xx *)sp->u.iocb_cmd.u.mbx.in;
670 rval = __qla24xx_parse_gpdb(vha, fcport, pd);
673 memset(&ea, 0, sizeof(ea));
674 ea.event = FCME_GPDB_DONE;
679 qla2x00_fcport_event_handler(vha, &ea);
681 dma_pool_free(ha->s_dma_pool, sp->u.iocb_cmd.u.mbx.in,
682 sp->u.iocb_cmd.u.mbx.in_dma);
687 static int qla24xx_post_prli_work(struct scsi_qla_host *vha, fc_port_t *fcport)
689 struct qla_work_evt *e;
691 e = qla2x00_alloc_work(vha, QLA_EVT_PRLI);
693 return QLA_FUNCTION_FAILED;
695 e->u.fcport.fcport = fcport;
697 return qla2x00_post_work(vha, e);
701 qla2x00_async_prli_sp_done(void *ptr, int res)
704 struct scsi_qla_host *vha = sp->vha;
705 struct srb_iocb *lio = &sp->u.iocb_cmd;
708 ql_dbg(ql_dbg_disc, vha, 0x2129,
709 "%s %8phC res %d \n", __func__,
710 sp->fcport->port_name, res);
712 sp->fcport->flags &= ~FCF_ASYNC_SENT;
714 if (!test_bit(UNLOADING, &vha->dpc_flags)) {
715 memset(&ea, 0, sizeof(ea));
716 ea.event = FCME_PRLI_DONE;
717 ea.fcport = sp->fcport;
718 ea.data[0] = lio->u.logio.data[0];
719 ea.data[1] = lio->u.logio.data[1];
720 ea.iop[0] = lio->u.logio.iop[0];
721 ea.iop[1] = lio->u.logio.iop[1];
724 qla2x00_fcport_event_handler(vha, &ea);
731 qla24xx_async_prli(struct scsi_qla_host *vha, fc_port_t *fcport)
734 struct srb_iocb *lio;
735 int rval = QLA_FUNCTION_FAILED;
737 if (!vha->flags.online)
740 if (fcport->fw_login_state == DSC_LS_PLOGI_PEND ||
741 fcport->fw_login_state == DSC_LS_PLOGI_COMP ||
742 fcport->fw_login_state == DSC_LS_PRLI_PEND)
745 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
749 fcport->flags |= FCF_ASYNC_SENT;
750 fcport->logout_completed = 0;
752 sp->type = SRB_PRLI_CMD;
754 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
756 lio = &sp->u.iocb_cmd;
757 lio->timeout = qla2x00_async_iocb_timeout;
758 sp->done = qla2x00_async_prli_sp_done;
759 lio->u.logio.flags = 0;
761 if (fcport->fc4f_nvme)
762 lio->u.logio.flags |= SRB_LOGIN_NVME_PRLI;
764 rval = qla2x00_start_sp(sp);
765 if (rval != QLA_SUCCESS) {
766 fcport->flags &= ~FCF_ASYNC_SENT;
767 fcport->flags |= FCF_LOGIN_NEEDED;
768 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
772 ql_dbg(ql_dbg_disc, vha, 0x211b,
773 "Async-prli - %8phC hdl=%x, loopid=%x portid=%06x retries=%d.\n",
774 fcport->port_name, sp->handle, fcport->loop_id,
775 fcport->d_id.b24, fcport->login_retry);
781 fcport->flags &= ~FCF_ASYNC_SENT;
785 int qla24xx_post_gpdb_work(struct scsi_qla_host *vha, fc_port_t *fcport, u8 opt)
787 struct qla_work_evt *e;
789 e = qla2x00_alloc_work(vha, QLA_EVT_GPDB);
791 return QLA_FUNCTION_FAILED;
793 e->u.fcport.fcport = fcport;
794 e->u.fcport.opt = opt;
795 return qla2x00_post_work(vha, e);
798 int qla24xx_async_gpdb(struct scsi_qla_host *vha, fc_port_t *fcport, u8 opt)
801 struct srb_iocb *mbx;
802 int rval = QLA_FUNCTION_FAILED;
805 struct port_database_24xx *pd;
806 struct qla_hw_data *ha = vha->hw;
808 if (!vha->flags.online)
811 fcport->flags |= FCF_ASYNC_SENT;
812 fcport->disc_state = DSC_GPDB;
814 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
818 sp->type = SRB_MB_IOCB;
820 sp->gen1 = fcport->rscn_gen;
821 sp->gen2 = fcport->login_gen;
822 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
824 pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
826 ql_log(ql_log_warn, vha, 0xd043,
827 "Failed to allocate port database structure.\n");
830 memset(pd, 0, max(PORT_DATABASE_SIZE, PORT_DATABASE_24XX_SIZE));
832 mb = sp->u.iocb_cmd.u.mbx.out_mb;
833 mb[0] = MBC_GET_PORT_DATABASE;
834 mb[1] = fcport->loop_id;
837 mb[6] = MSW(MSD(pd_dma));
838 mb[7] = LSW(MSD(pd_dma));
842 mbx = &sp->u.iocb_cmd;
843 mbx->timeout = qla2x00_async_iocb_timeout;
844 mbx->u.mbx.in = (void *)pd;
845 mbx->u.mbx.in_dma = pd_dma;
847 sp->done = qla24xx_async_gpdb_sp_done;
849 rval = qla2x00_start_sp(sp);
850 if (rval != QLA_SUCCESS)
853 ql_dbg(ql_dbg_disc, vha, 0x20dc,
854 "Async-%s %8phC hndl %x opt %x\n",
855 sp->name, fcport->port_name, sp->handle, opt);
861 dma_pool_free(ha->s_dma_pool, pd, pd_dma);
865 fcport->flags &= ~FCF_ASYNC_SENT;
866 qla24xx_post_gpdb_work(vha, fcport, opt);
871 void qla24xx_handle_gpdb_event(scsi_qla_host_t *vha, struct event_arg *ea)
874 fc_port_t *fcport = ea->fcport;
876 u16 opt = ea->sp->u.iocb_cmd.u.mbx.out_mb[10];
878 fcport->flags &= ~FCF_ASYNC_SENT;
880 ql_dbg(ql_dbg_disc, vha, 0x20d2,
881 "%s %8phC DS %d LS %d rval %d\n", __func__, fcport->port_name,
882 fcport->disc_state, fcport->fw_login_state, rval);
884 if (ea->sp->gen2 != fcport->login_gen) {
885 /* target side must have changed it. */
886 ql_dbg(ql_dbg_disc, vha, 0x20d3,
887 "%s %8phC generation changed rscn %d|%d login %d|%d \n",
888 __func__, fcport->port_name, fcport->last_rscn_gen,
889 fcport->rscn_gen, fcport->last_login_gen,
892 } else if (ea->sp->gen1 != fcport->rscn_gen) {
893 ql_dbg(ql_dbg_disc, vha, 0x20d4, "%s %d %8phC post gidpn\n",
894 __func__, __LINE__, fcport->port_name);
895 qla24xx_post_gidpn_work(vha, fcport);
899 if (rval != QLA_SUCCESS) {
900 ql_dbg(ql_dbg_disc, vha, 0x20d5, "%s %d %8phC post del sess\n",
901 __func__, __LINE__, fcport->port_name);
902 qlt_schedule_sess_for_deletion_lock(fcport);
906 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
907 if (opt != PDO_FORCE_ADISC)
908 ea->fcport->login_gen++;
909 ea->fcport->deleted = 0;
910 ea->fcport->logout_on_delete = 1;
912 if (!ea->fcport->login_succ && !IS_SW_RESV_ADDR(ea->fcport->d_id)) {
914 ea->fcport->login_succ = 1;
916 if (!IS_IIDMA_CAPABLE(vha->hw) ||
917 !vha->hw->flags.gpsc_supported) {
918 ql_dbg(ql_dbg_disc, vha, 0x20d6,
919 "%s %d %8phC post upd_fcport fcp_cnt %d\n",
920 __func__, __LINE__, fcport->port_name,
923 qla24xx_post_upd_fcport_work(vha, fcport);
925 ql_dbg(ql_dbg_disc, vha, 0x20d7,
926 "%s %d %8phC post gpsc fcp_cnt %d\n",
927 __func__, __LINE__, fcport->port_name,
930 qla24xx_post_gpsc_work(vha, fcport);
932 } else if (ea->fcport->login_succ) {
934 * We have an existing session. A late RSCN delivery
935 * must have triggered the session to be re-validate.
936 * session is still valid.
938 fcport->disc_state = DSC_LOGIN_COMPLETE;
940 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
943 int qla24xx_fcport_handle_login(struct scsi_qla_host *vha, fc_port_t *fcport)
945 if (fcport->login_retry == 0)
948 if (fcport->scan_state != QLA_FCPORT_FOUND)
951 ql_dbg(ql_dbg_disc, vha, 0x20d8,
952 "%s %8phC DS %d LS %d P %d fl %x confl %p rscn %d|%d login %d|%d retry %d lid %d\n",
953 __func__, fcport->port_name, fcport->disc_state,
954 fcport->fw_login_state, fcport->login_pause, fcport->flags,
955 fcport->conflict, fcport->last_rscn_gen, fcport->rscn_gen,
956 fcport->last_login_gen, fcport->login_gen, fcport->login_retry,
959 fcport->login_retry--;
961 if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
962 (fcport->fw_login_state == DSC_LS_PRLI_PEND))
965 if (fcport->fw_login_state == DSC_LS_PLOGI_COMP) {
966 if (time_before_eq(jiffies, fcport->plogi_nack_done_deadline))
970 /* for pure Target Mode. Login will not be initiated */
971 if (vha->host->active_mode == MODE_TARGET)
974 if (fcport->flags & FCF_ASYNC_SENT) {
975 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
979 switch (fcport->disc_state) {
981 if (fcport->loop_id == FC_NO_LOOP_ID) {
982 ql_dbg(ql_dbg_disc, vha, 0x20bd,
983 "%s %d %8phC post gnl\n",
984 __func__, __LINE__, fcport->port_name);
985 qla24xx_post_gnl_work(vha, fcport);
987 ql_dbg(ql_dbg_disc, vha, 0x20bf,
988 "%s %d %8phC post login\n",
989 __func__, __LINE__, fcport->port_name);
990 fcport->disc_state = DSC_LOGIN_PEND;
991 qla2x00_post_async_login_work(vha, fcport, NULL);
996 if (fcport->login_pause) {
997 fcport->last_rscn_gen = fcport->rscn_gen;
998 fcport->last_login_gen = fcport->login_gen;
999 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1003 if (fcport->flags & FCF_FCP2_DEVICE) {
1004 u8 opt = PDO_FORCE_ADISC;
1006 ql_dbg(ql_dbg_disc, vha, 0x20c9,
1007 "%s %d %8phC post gpdb\n",
1008 __func__, __LINE__, fcport->port_name);
1010 fcport->disc_state = DSC_GPDB;
1011 qla24xx_post_gpdb_work(vha, fcport, opt);
1013 ql_dbg(ql_dbg_disc, vha, 0x20cf,
1014 "%s %d %8phC post login\n",
1015 __func__, __LINE__, fcport->port_name);
1016 fcport->disc_state = DSC_LOGIN_PEND;
1017 qla2x00_post_async_login_work(vha, fcport, NULL);
1022 case DSC_LOGIN_FAILED:
1023 ql_dbg(ql_dbg_disc, vha, 0x20d0,
1024 "%s %d %8phC post gidpn\n",
1025 __func__, __LINE__, fcport->port_name);
1027 qla24xx_post_gidpn_work(vha, fcport);
1030 case DSC_LOGIN_COMPLETE:
1031 /* recheck login state */
1032 ql_dbg(ql_dbg_disc, vha, 0x20d1,
1033 "%s %d %8phC post gpdb\n",
1034 __func__, __LINE__, fcport->port_name);
1036 qla24xx_post_gpdb_work(vha, fcport, PDO_FORCE_ADISC);
1047 void qla24xx_handle_rscn_event(fc_port_t *fcport, struct event_arg *ea)
1051 ql_dbg(ql_dbg_disc, fcport->vha, 0x210c,
1052 "%s %8phC DS %d LS %d\n",
1053 __func__, fcport->port_name, fcport->disc_state,
1054 fcport->fw_login_state);
1056 if (fcport->flags & FCF_ASYNC_SENT)
1059 switch (fcport->disc_state) {
1061 case DSC_LOGIN_COMPLETE:
1062 qla24xx_post_gidpn_work(fcport->vha, fcport);
1070 int qla24xx_post_newsess_work(struct scsi_qla_host *vha, port_id_t *id,
1071 u8 *port_name, void *pla)
1073 struct qla_work_evt *e;
1074 e = qla2x00_alloc_work(vha, QLA_EVT_NEW_SESS);
1076 return QLA_FUNCTION_FAILED;
1078 e->u.new_sess.id = *id;
1079 e->u.new_sess.pla = pla;
1080 memcpy(e->u.new_sess.port_name, port_name, WWN_SIZE);
1082 return qla2x00_post_work(vha, e);
1086 int qla24xx_handle_delete_done_event(scsi_qla_host_t *vha,
1087 struct event_arg *ea)
1089 fc_port_t *fcport = ea->fcport;
1091 if (test_bit(UNLOADING, &vha->dpc_flags))
1094 switch (vha->host->active_mode) {
1095 case MODE_INITIATOR:
1097 if (fcport->scan_state == QLA_FCPORT_FOUND)
1098 qla24xx_fcport_handle_login(vha, fcport);
1111 void qla24xx_handle_relogin_event(scsi_qla_host_t *vha,
1112 struct event_arg *ea)
1114 fc_port_t *fcport = ea->fcport;
1116 if (fcport->scan_state != QLA_FCPORT_FOUND) {
1117 fcport->login_retry++;
1121 ql_dbg(ql_dbg_disc, vha, 0x2102,
1122 "%s %8phC DS %d LS %d P %d del %d cnfl %p rscn %d|%d login %d|%d fl %x\n",
1123 __func__, fcport->port_name, fcport->disc_state,
1124 fcport->fw_login_state, fcport->login_pause,
1125 fcport->deleted, fcport->conflict,
1126 fcport->last_rscn_gen, fcport->rscn_gen,
1127 fcport->last_login_gen, fcport->login_gen,
1130 if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
1131 (fcport->fw_login_state == DSC_LS_PRLI_PEND))
1134 if (fcport->fw_login_state == DSC_LS_PLOGI_COMP) {
1135 if (time_before_eq(jiffies, fcport->plogi_nack_done_deadline))
1139 if (fcport->flags & FCF_ASYNC_SENT) {
1140 fcport->login_retry++;
1141 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1145 if (fcport->disc_state == DSC_DELETE_PEND) {
1146 fcport->login_retry++;
1150 if (fcport->last_rscn_gen != fcport->rscn_gen) {
1151 ql_dbg(ql_dbg_disc, vha, 0x20e9, "%s %d %8phC post gidpn\n",
1152 __func__, __LINE__, fcport->port_name);
1154 qla24xx_post_gidpn_work(vha, fcport);
1158 qla24xx_fcport_handle_login(vha, fcport);
1161 void qla2x00_fcport_event_handler(scsi_qla_host_t *vha, struct event_arg *ea)
1163 fc_port_t *fcport, *f, *tf;
1164 uint32_t id = 0, mask, rid;
1167 switch (ea->event) {
1170 case FCME_GIDPN_DONE:
1171 case FCME_GPSC_DONE:
1172 case FCME_GPNID_DONE:
1173 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) ||
1174 test_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags))
1181 switch (ea->event) {
1183 if (test_bit(UNLOADING, &vha->dpc_flags))
1186 qla24xx_handle_relogin_event(vha, ea);
1189 if (test_bit(UNLOADING, &vha->dpc_flags))
1191 switch (ea->id.b.rsvd_1) {
1192 case RSCN_PORT_ADDR:
1193 fcport = qla2x00_find_fcport_by_nportid(vha, &ea->id, 1);
1196 rc = qla24xx_post_gpnid_work(vha, &ea->id);
1198 ql_log(ql_log_warn, vha, 0xd044,
1199 "RSCN GPNID work failed %02x%02x%02x\n",
1200 ea->id.b.domain, ea->id.b.area,
1204 ea->fcport = fcport;
1205 qla24xx_handle_rscn_event(fcport, ea);
1208 case RSCN_AREA_ADDR:
1210 if (ea->id.b.rsvd_1 == RSCN_AREA_ADDR) {
1212 ql_dbg(ql_dbg_async, vha, 0x5044,
1213 "RSCN: Area 0x%06x was affected\n",
1217 ql_dbg(ql_dbg_async, vha, 0x507a,
1218 "RSCN: Domain 0x%06x was affected\n",
1222 rid = ea->id.b24 & mask;
1223 list_for_each_entry_safe(f, tf, &vha->vp_fcports,
1225 id = f->d_id.b24 & mask;
1228 qla24xx_handle_rscn_event(f, ea);
1234 ql_log(ql_log_warn, vha, 0xd045,
1235 "RSCN: Fabric was affected. Addr format %d\n",
1237 qla2x00_mark_all_devices_lost(vha, 1);
1238 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
1239 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
1242 case FCME_GIDPN_DONE:
1243 qla24xx_handle_gidpn_event(vha, ea);
1246 qla24xx_handle_gnl_done_event(vha, ea);
1248 case FCME_GPSC_DONE:
1249 qla24xx_post_upd_fcport_work(vha, ea->fcport);
1251 case FCME_PLOGI_DONE: /* Initiator side sent LLIOCB */
1252 qla24xx_handle_plogi_done_event(vha, ea);
1254 case FCME_PRLI_DONE:
1255 qla24xx_handle_prli_done_event(vha, ea);
1257 case FCME_GPDB_DONE:
1258 qla24xx_handle_gpdb_event(vha, ea);
1260 case FCME_GPNID_DONE:
1261 qla24xx_handle_gpnid_event(vha, ea);
1263 case FCME_GFFID_DONE:
1264 qla24xx_handle_gffid_event(vha, ea);
1266 case FCME_DELETE_DONE:
1267 qla24xx_handle_delete_done_event(vha, ea);
1276 qla2x00_tmf_iocb_timeout(void *data)
1279 struct srb_iocb *tmf = &sp->u.iocb_cmd;
1281 tmf->u.tmf.comp_status = CS_TIMEOUT;
1282 complete(&tmf->u.tmf.comp);
1286 qla2x00_tmf_sp_done(void *ptr, int res)
1289 struct srb_iocb *tmf = &sp->u.iocb_cmd;
1291 complete(&tmf->u.tmf.comp);
1295 qla2x00_async_tm_cmd(fc_port_t *fcport, uint32_t flags, uint32_t lun,
1298 struct scsi_qla_host *vha = fcport->vha;
1299 struct srb_iocb *tm_iocb;
1301 int rval = QLA_FUNCTION_FAILED;
1303 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1307 tm_iocb = &sp->u.iocb_cmd;
1308 sp->type = SRB_TM_CMD;
1310 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha));
1311 tm_iocb->u.tmf.flags = flags;
1312 tm_iocb->u.tmf.lun = lun;
1313 tm_iocb->u.tmf.data = tag;
1314 sp->done = qla2x00_tmf_sp_done;
1315 tm_iocb->timeout = qla2x00_tmf_iocb_timeout;
1316 init_completion(&tm_iocb->u.tmf.comp);
1318 rval = qla2x00_start_sp(sp);
1319 if (rval != QLA_SUCCESS)
1322 ql_dbg(ql_dbg_taskm, vha, 0x802f,
1323 "Async-tmf hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
1324 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
1325 fcport->d_id.b.area, fcport->d_id.b.al_pa);
1327 wait_for_completion(&tm_iocb->u.tmf.comp);
1329 rval = tm_iocb->u.tmf.data;
1331 if (rval != QLA_SUCCESS) {
1332 ql_log(ql_log_warn, vha, 0x8030,
1333 "TM IOCB failed (%x).\n", rval);
1336 if (!test_bit(UNLOADING, &vha->dpc_flags) && !IS_QLAFX00(vha->hw)) {
1337 flags = tm_iocb->u.tmf.flags;
1338 lun = (uint16_t)tm_iocb->u.tmf.lun;
1340 /* Issue Marker IOCB */
1341 qla2x00_marker(vha, vha->hw->req_q_map[0],
1342 vha->hw->rsp_q_map[0], sp->fcport->loop_id, lun,
1343 flags == TCF_LUN_RESET ? MK_SYNC_ID_LUN : MK_SYNC_ID);
1353 qla24xx_abort_iocb_timeout(void *data)
1356 struct srb_iocb *abt = &sp->u.iocb_cmd;
1358 abt->u.abt.comp_status = CS_TIMEOUT;
1359 complete(&abt->u.abt.comp);
1363 qla24xx_abort_sp_done(void *ptr, int res)
1366 struct srb_iocb *abt = &sp->u.iocb_cmd;
1368 if (del_timer(&sp->u.iocb_cmd.timer))
1369 complete(&abt->u.abt.comp);
1373 qla24xx_async_abort_cmd(srb_t *cmd_sp)
1375 scsi_qla_host_t *vha = cmd_sp->vha;
1376 fc_port_t *fcport = cmd_sp->fcport;
1377 struct srb_iocb *abt_iocb;
1379 int rval = QLA_FUNCTION_FAILED;
1381 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1385 abt_iocb = &sp->u.iocb_cmd;
1386 sp->type = SRB_ABT_CMD;
1388 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha));
1389 abt_iocb->u.abt.cmd_hndl = cmd_sp->handle;
1390 sp->done = qla24xx_abort_sp_done;
1391 abt_iocb->timeout = qla24xx_abort_iocb_timeout;
1392 init_completion(&abt_iocb->u.abt.comp);
1394 rval = qla2x00_start_sp(sp);
1395 if (rval != QLA_SUCCESS)
1398 ql_dbg(ql_dbg_async, vha, 0x507c,
1399 "Abort command issued - hdl=%x, target_id=%x\n",
1400 cmd_sp->handle, fcport->tgt_id);
1402 wait_for_completion(&abt_iocb->u.abt.comp);
1404 rval = abt_iocb->u.abt.comp_status == CS_COMPLETE ?
1405 QLA_SUCCESS : QLA_FUNCTION_FAILED;
1414 qla24xx_async_abort_command(srb_t *sp)
1416 unsigned long flags = 0;
1419 fc_port_t *fcport = sp->fcport;
1420 struct scsi_qla_host *vha = fcport->vha;
1421 struct qla_hw_data *ha = vha->hw;
1422 struct req_que *req = vha->req;
1424 spin_lock_irqsave(&ha->hardware_lock, flags);
1425 for (handle = 1; handle < req->num_outstanding_cmds; handle++) {
1426 if (req->outstanding_cmds[handle] == sp)
1429 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1430 if (handle == req->num_outstanding_cmds) {
1431 /* Command not found. */
1432 return QLA_FUNCTION_FAILED;
1434 if (sp->type == SRB_FXIOCB_DCMD)
1435 return qlafx00_fx_disc(vha, &vha->hw->mr.fcport,
1436 FXDISC_ABORT_IOCTL);
1438 return qla24xx_async_abort_cmd(sp);
1442 qla24xx_handle_prli_done_event(struct scsi_qla_host *vha, struct event_arg *ea)
1444 switch (ea->data[0]) {
1445 case MBS_COMMAND_COMPLETE:
1446 ql_dbg(ql_dbg_disc, vha, 0x2118,
1447 "%s %d %8phC post gpdb\n",
1448 __func__, __LINE__, ea->fcport->port_name);
1450 ea->fcport->chip_reset = vha->hw->base_qpair->chip_reset;
1451 ea->fcport->logout_on_delete = 1;
1452 qla24xx_post_gpdb_work(vha, ea->fcport, 0);
1455 ql_dbg(ql_dbg_disc, vha, 0x2119,
1456 "%s %d %8phC unhandle event of %x\n",
1457 __func__, __LINE__, ea->fcport->port_name, ea->data[0]);
1463 qla24xx_handle_plogi_done_event(struct scsi_qla_host *vha, struct event_arg *ea)
1465 port_id_t cid; /* conflict Nport id */
1467 struct fc_port *conflict_fcport;
1469 switch (ea->data[0]) {
1470 case MBS_COMMAND_COMPLETE:
1472 * Driver must validate login state - If PRLI not complete,
1473 * force a relogin attempt via implicit LOGO, PLOGI, and PRLI
1476 if (ea->fcport->fc4f_nvme) {
1477 ql_dbg(ql_dbg_disc, vha, 0x2117,
1478 "%s %d %8phC post prli\n",
1479 __func__, __LINE__, ea->fcport->port_name);
1480 qla24xx_post_prli_work(vha, ea->fcport);
1482 ql_dbg(ql_dbg_disc, vha, 0x20ea,
1483 "%s %d %8phC LoopID 0x%x in use with %06x. post gnl\n",
1484 __func__, __LINE__, ea->fcport->port_name,
1485 ea->fcport->loop_id, ea->fcport->d_id.b24);
1487 set_bit(ea->fcport->loop_id, vha->hw->loop_id_map);
1488 ea->fcport->loop_id = FC_NO_LOOP_ID;
1489 ea->fcport->chip_reset = vha->hw->base_qpair->chip_reset;
1490 ea->fcport->logout_on_delete = 1;
1491 ea->fcport->send_els_logo = 0;
1492 qla24xx_post_gpdb_work(vha, ea->fcport, 0);
1495 case MBS_COMMAND_ERROR:
1496 ql_dbg(ql_dbg_disc, vha, 0x20eb, "%s %d %8phC cmd error %x\n",
1497 __func__, __LINE__, ea->fcport->port_name, ea->data[1]);
1499 ea->fcport->flags &= ~FCF_ASYNC_SENT;
1500 ea->fcport->disc_state = DSC_LOGIN_FAILED;
1501 if (ea->data[1] & QLA_LOGIO_LOGIN_RETRIED)
1502 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1504 qla2x00_mark_device_lost(vha, ea->fcport, 1, 0);
1506 case MBS_LOOP_ID_USED:
1507 /* data[1] = IO PARAM 1 = nport ID */
1508 cid.b.domain = (ea->iop[1] >> 16) & 0xff;
1509 cid.b.area = (ea->iop[1] >> 8) & 0xff;
1510 cid.b.al_pa = ea->iop[1] & 0xff;
1513 ql_dbg(ql_dbg_disc, vha, 0x20ec,
1514 "%s %d %8phC lid %#x in use with pid %06x post gnl\n",
1515 __func__, __LINE__, ea->fcport->port_name,
1516 ea->fcport->loop_id, cid.b24);
1518 set_bit(ea->fcport->loop_id, vha->hw->loop_id_map);
1519 ea->fcport->loop_id = FC_NO_LOOP_ID;
1520 qla24xx_post_gnl_work(vha, ea->fcport);
1522 case MBS_PORT_ID_USED:
1523 lid = ea->iop[1] & 0xffff;
1524 qlt_find_sess_invalidate_other(vha,
1525 wwn_to_u64(ea->fcport->port_name),
1526 ea->fcport->d_id, lid, &conflict_fcport);
1528 if (conflict_fcport) {
1530 * Another fcport share the same loop_id/nport id.
1531 * Conflict fcport needs to finish cleanup before this
1532 * fcport can proceed to login.
1534 conflict_fcport->conflict = ea->fcport;
1535 ea->fcport->login_pause = 1;
1537 ql_dbg(ql_dbg_disc, vha, 0x20ed,
1538 "%s %d %8phC NPortId %06x inuse with loopid 0x%x. post gidpn\n",
1539 __func__, __LINE__, ea->fcport->port_name,
1540 ea->fcport->d_id.b24, lid);
1541 qla2x00_clear_loop_id(ea->fcport);
1542 qla24xx_post_gidpn_work(vha, ea->fcport);
1544 ql_dbg(ql_dbg_disc, vha, 0x20ed,
1545 "%s %d %8phC NPortId %06x inuse with loopid 0x%x. sched delete\n",
1546 __func__, __LINE__, ea->fcport->port_name,
1547 ea->fcport->d_id.b24, lid);
1549 qla2x00_clear_loop_id(ea->fcport);
1550 set_bit(lid, vha->hw->loop_id_map);
1551 ea->fcport->loop_id = lid;
1552 ea->fcport->keep_nport_handle = 0;
1553 qlt_schedule_sess_for_deletion(ea->fcport, false);
1561 qla2x00_async_logout_done(struct scsi_qla_host *vha, fc_port_t *fcport,
1564 qla2x00_mark_device_lost(vha, fcport, 1, 0);
1565 qlt_logo_completion_handler(fcport, data[0]);
1566 fcport->login_gen++;
1571 qla2x00_async_adisc_done(struct scsi_qla_host *vha, fc_port_t *fcport,
1574 if (data[0] == MBS_COMMAND_COMPLETE) {
1575 qla2x00_update_fcport(vha, fcport);
1581 fcport->flags &= ~FCF_ASYNC_SENT;
1582 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
1583 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1585 qla2x00_mark_device_lost(vha, fcport, 1, 0);
1590 /****************************************************************************/
1591 /* QLogic ISP2x00 Hardware Support Functions. */
1592 /****************************************************************************/
1595 qla83xx_nic_core_fw_load(scsi_qla_host_t *vha)
1597 int rval = QLA_SUCCESS;
1598 struct qla_hw_data *ha = vha->hw;
1599 uint32_t idc_major_ver, idc_minor_ver;
1602 qla83xx_idc_lock(vha, 0);
1604 /* SV: TODO: Assign initialization timeout from
1605 * flash-info / other param
1607 ha->fcoe_dev_init_timeout = QLA83XX_IDC_INITIALIZATION_TIMEOUT;
1608 ha->fcoe_reset_timeout = QLA83XX_IDC_RESET_ACK_TIMEOUT;
1610 /* Set our fcoe function presence */
1611 if (__qla83xx_set_drv_presence(vha) != QLA_SUCCESS) {
1612 ql_dbg(ql_dbg_p3p, vha, 0xb077,
1613 "Error while setting DRV-Presence.\n");
1614 rval = QLA_FUNCTION_FAILED;
1618 /* Decide the reset ownership */
1619 qla83xx_reset_ownership(vha);
1622 * On first protocol driver load:
1623 * Init-Owner: Set IDC-Major-Version and Clear IDC-Lock-Recovery
1625 * Others: Check compatibility with current IDC Major version.
1627 qla83xx_rd_reg(vha, QLA83XX_IDC_MAJOR_VERSION, &idc_major_ver);
1628 if (ha->flags.nic_core_reset_owner) {
1629 /* Set IDC Major version */
1630 idc_major_ver = QLA83XX_SUPP_IDC_MAJOR_VERSION;
1631 qla83xx_wr_reg(vha, QLA83XX_IDC_MAJOR_VERSION, idc_major_ver);
1633 /* Clearing IDC-Lock-Recovery register */
1634 qla83xx_wr_reg(vha, QLA83XX_IDC_LOCK_RECOVERY, 0);
1635 } else if (idc_major_ver != QLA83XX_SUPP_IDC_MAJOR_VERSION) {
1637 * Clear further IDC participation if we are not compatible with
1638 * the current IDC Major Version.
1640 ql_log(ql_log_warn, vha, 0xb07d,
1641 "Failing load, idc_major_ver=%d, expected_major_ver=%d.\n",
1642 idc_major_ver, QLA83XX_SUPP_IDC_MAJOR_VERSION);
1643 __qla83xx_clear_drv_presence(vha);
1644 rval = QLA_FUNCTION_FAILED;
1647 /* Each function sets its supported Minor version. */
1648 qla83xx_rd_reg(vha, QLA83XX_IDC_MINOR_VERSION, &idc_minor_ver);
1649 idc_minor_ver |= (QLA83XX_SUPP_IDC_MINOR_VERSION << (ha->portnum * 2));
1650 qla83xx_wr_reg(vha, QLA83XX_IDC_MINOR_VERSION, idc_minor_ver);
1652 if (ha->flags.nic_core_reset_owner) {
1653 memset(config, 0, sizeof(config));
1654 if (!qla81xx_get_port_config(vha, config))
1655 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
1659 rval = qla83xx_idc_state_handler(vha);
1662 qla83xx_idc_unlock(vha, 0);
1668 * qla2x00_initialize_adapter
1672 * ha = adapter block pointer.
1678 qla2x00_initialize_adapter(scsi_qla_host_t *vha)
1681 struct qla_hw_data *ha = vha->hw;
1682 struct req_que *req = ha->req_q_map[0];
1684 memset(&vha->qla_stats, 0, sizeof(vha->qla_stats));
1685 memset(&vha->fc_host_stat, 0, sizeof(vha->fc_host_stat));
1687 /* Clear adapter flags. */
1688 vha->flags.online = 0;
1689 ha->flags.chip_reset_done = 0;
1690 vha->flags.reset_active = 0;
1691 ha->flags.pci_channel_io_perm_failure = 0;
1692 ha->flags.eeh_busy = 0;
1693 vha->qla_stats.jiffies_at_last_reset = get_jiffies_64();
1694 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
1695 atomic_set(&vha->loop_state, LOOP_DOWN);
1696 vha->device_flags = DFLG_NO_CABLE;
1698 vha->flags.management_server_logged_in = 0;
1699 vha->marker_needed = 0;
1700 ha->isp_abort_cnt = 0;
1701 ha->beacon_blink_led = 0;
1703 set_bit(0, ha->req_qid_map);
1704 set_bit(0, ha->rsp_qid_map);
1706 ql_dbg(ql_dbg_init, vha, 0x0040,
1707 "Configuring PCI space...\n");
1708 rval = ha->isp_ops->pci_config(vha);
1710 ql_log(ql_log_warn, vha, 0x0044,
1711 "Unable to configure PCI space.\n");
1715 ha->isp_ops->reset_chip(vha);
1717 rval = qla2xxx_get_flash_info(vha);
1719 ql_log(ql_log_fatal, vha, 0x004f,
1720 "Unable to validate FLASH data.\n");
1724 if (IS_QLA8044(ha)) {
1725 qla8044_read_reset_template(vha);
1727 /* NOTE: If ql2xdontresethba==1, set IDC_CTRL DONTRESET_BIT0.
1728 * If DONRESET_BIT0 is set, drivers should not set dev_state
1729 * to NEED_RESET. But if NEED_RESET is set, drivers should
1730 * should honor the reset. */
1731 if (ql2xdontresethba == 1)
1732 qla8044_set_idc_dontreset(vha);
1735 ha->isp_ops->get_flash_version(vha, req->ring);
1736 ql_dbg(ql_dbg_init, vha, 0x0061,
1737 "Configure NVRAM parameters...\n");
1739 ha->isp_ops->nvram_config(vha);
1741 if (ha->flags.disable_serdes) {
1742 /* Mask HBA via NVRAM settings? */
1743 ql_log(ql_log_info, vha, 0x0077,
1744 "Masking HBA WWPN %8phN (via NVRAM).\n", vha->port_name);
1745 return QLA_FUNCTION_FAILED;
1748 ql_dbg(ql_dbg_init, vha, 0x0078,
1749 "Verifying loaded RISC code...\n");
1751 if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) {
1752 rval = ha->isp_ops->chip_diag(vha);
1755 rval = qla2x00_setup_chip(vha);
1760 if (IS_QLA84XX(ha)) {
1761 ha->cs84xx = qla84xx_get_chip(vha);
1763 ql_log(ql_log_warn, vha, 0x00d0,
1764 "Unable to configure ISP84XX.\n");
1765 return QLA_FUNCTION_FAILED;
1769 if (qla_ini_mode_enabled(vha) || qla_dual_mode_enabled(vha))
1770 rval = qla2x00_init_rings(vha);
1772 ha->flags.chip_reset_done = 1;
1774 if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) {
1775 /* Issue verify 84xx FW IOCB to complete 84xx initialization */
1776 rval = qla84xx_init_chip(vha);
1777 if (rval != QLA_SUCCESS) {
1778 ql_log(ql_log_warn, vha, 0x00d4,
1779 "Unable to initialize ISP84XX.\n");
1780 qla84xx_put_chip(vha);
1784 /* Load the NIC Core f/w if we are the first protocol driver. */
1785 if (IS_QLA8031(ha)) {
1786 rval = qla83xx_nic_core_fw_load(vha);
1788 ql_log(ql_log_warn, vha, 0x0124,
1789 "Error in initializing NIC Core f/w.\n");
1792 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha))
1793 qla24xx_read_fcp_prio_cfg(vha);
1795 if (IS_P3P_TYPE(ha))
1796 qla82xx_set_driver_version(vha, QLA2XXX_VERSION);
1798 qla25xx_set_driver_version(vha, QLA2XXX_VERSION);
1804 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
1807 * Returns 0 on success.
1810 qla2100_pci_config(scsi_qla_host_t *vha)
1813 unsigned long flags;
1814 struct qla_hw_data *ha = vha->hw;
1815 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1817 pci_set_master(ha->pdev);
1818 pci_try_set_mwi(ha->pdev);
1820 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
1821 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
1822 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
1824 pci_disable_rom(ha->pdev);
1826 /* Get PCI bus information. */
1827 spin_lock_irqsave(&ha->hardware_lock, flags);
1828 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
1829 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1835 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
1838 * Returns 0 on success.
1841 qla2300_pci_config(scsi_qla_host_t *vha)
1844 unsigned long flags = 0;
1846 struct qla_hw_data *ha = vha->hw;
1847 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1849 pci_set_master(ha->pdev);
1850 pci_try_set_mwi(ha->pdev);
1852 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
1853 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
1855 if (IS_QLA2322(ha) || IS_QLA6322(ha))
1856 w &= ~PCI_COMMAND_INTX_DISABLE;
1857 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
1860 * If this is a 2300 card and not 2312, reset the
1861 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
1862 * the 2310 also reports itself as a 2300 so we need to get the
1863 * fb revision level -- a 6 indicates it really is a 2300 and
1866 if (IS_QLA2300(ha)) {
1867 spin_lock_irqsave(&ha->hardware_lock, flags);
1870 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
1871 for (cnt = 0; cnt < 30000; cnt++) {
1872 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) != 0)
1878 /* Select FPM registers. */
1879 WRT_REG_WORD(®->ctrl_status, 0x20);
1880 RD_REG_WORD(®->ctrl_status);
1882 /* Get the fb rev level */
1883 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
1885 if (ha->fb_rev == FPM_2300)
1886 pci_clear_mwi(ha->pdev);
1888 /* Deselect FPM registers. */
1889 WRT_REG_WORD(®->ctrl_status, 0x0);
1890 RD_REG_WORD(®->ctrl_status);
1892 /* Release RISC module. */
1893 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
1894 for (cnt = 0; cnt < 30000; cnt++) {
1895 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) == 0)
1901 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1904 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
1906 pci_disable_rom(ha->pdev);
1908 /* Get PCI bus information. */
1909 spin_lock_irqsave(&ha->hardware_lock, flags);
1910 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
1911 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1917 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
1920 * Returns 0 on success.
1923 qla24xx_pci_config(scsi_qla_host_t *vha)
1926 unsigned long flags = 0;
1927 struct qla_hw_data *ha = vha->hw;
1928 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1930 pci_set_master(ha->pdev);
1931 pci_try_set_mwi(ha->pdev);
1933 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
1934 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
1935 w &= ~PCI_COMMAND_INTX_DISABLE;
1936 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
1938 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
1940 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
1941 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
1942 pcix_set_mmrbc(ha->pdev, 2048);
1944 /* PCIe -- adjust Maximum Read Request Size (2048). */
1945 if (pci_is_pcie(ha->pdev))
1946 pcie_set_readrq(ha->pdev, 4096);
1948 pci_disable_rom(ha->pdev);
1950 ha->chip_revision = ha->pdev->revision;
1952 /* Get PCI bus information. */
1953 spin_lock_irqsave(&ha->hardware_lock, flags);
1954 ha->pci_attr = RD_REG_DWORD(®->ctrl_status);
1955 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1961 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
1964 * Returns 0 on success.
1967 qla25xx_pci_config(scsi_qla_host_t *vha)
1970 struct qla_hw_data *ha = vha->hw;
1972 pci_set_master(ha->pdev);
1973 pci_try_set_mwi(ha->pdev);
1975 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
1976 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
1977 w &= ~PCI_COMMAND_INTX_DISABLE;
1978 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
1980 /* PCIe -- adjust Maximum Read Request Size (2048). */
1981 if (pci_is_pcie(ha->pdev))
1982 pcie_set_readrq(ha->pdev, 4096);
1984 pci_disable_rom(ha->pdev);
1986 ha->chip_revision = ha->pdev->revision;
1992 * qla2x00_isp_firmware() - Choose firmware image.
1995 * Returns 0 on success.
1998 qla2x00_isp_firmware(scsi_qla_host_t *vha)
2001 uint16_t loop_id, topo, sw_cap;
2002 uint8_t domain, area, al_pa;
2003 struct qla_hw_data *ha = vha->hw;
2005 /* Assume loading risc code */
2006 rval = QLA_FUNCTION_FAILED;
2008 if (ha->flags.disable_risc_code_load) {
2009 ql_log(ql_log_info, vha, 0x0079, "RISC CODE NOT loaded.\n");
2011 /* Verify checksum of loaded RISC code. */
2012 rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address);
2013 if (rval == QLA_SUCCESS) {
2014 /* And, verify we are not in ROM code. */
2015 rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
2016 &area, &domain, &topo, &sw_cap);
2021 ql_dbg(ql_dbg_init, vha, 0x007a,
2022 "**** Load RISC code ****.\n");
2028 * qla2x00_reset_chip() - Reset ISP chip.
2031 * Returns 0 on success.
2034 qla2x00_reset_chip(scsi_qla_host_t *vha)
2036 unsigned long flags = 0;
2037 struct qla_hw_data *ha = vha->hw;
2038 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2042 if (unlikely(pci_channel_offline(ha->pdev)))
2045 ha->isp_ops->disable_intrs(ha);
2047 spin_lock_irqsave(&ha->hardware_lock, flags);
2049 /* Turn off master enable */
2051 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
2052 cmd &= ~PCI_COMMAND_MASTER;
2053 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
2055 if (!IS_QLA2100(ha)) {
2057 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
2058 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
2059 for (cnt = 0; cnt < 30000; cnt++) {
2060 if ((RD_REG_WORD(®->hccr) &
2061 HCCR_RISC_PAUSE) != 0)
2066 RD_REG_WORD(®->hccr); /* PCI Posting. */
2070 /* Select FPM registers. */
2071 WRT_REG_WORD(®->ctrl_status, 0x20);
2072 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
2074 /* FPM Soft Reset. */
2075 WRT_REG_WORD(®->fpm_diag_config, 0x100);
2076 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
2078 /* Toggle Fpm Reset. */
2079 if (!IS_QLA2200(ha)) {
2080 WRT_REG_WORD(®->fpm_diag_config, 0x0);
2081 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
2084 /* Select frame buffer registers. */
2085 WRT_REG_WORD(®->ctrl_status, 0x10);
2086 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
2088 /* Reset frame buffer FIFOs. */
2089 if (IS_QLA2200(ha)) {
2090 WRT_FB_CMD_REG(ha, reg, 0xa000);
2091 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
2093 WRT_FB_CMD_REG(ha, reg, 0x00fc);
2095 /* Read back fb_cmd until zero or 3 seconds max */
2096 for (cnt = 0; cnt < 3000; cnt++) {
2097 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
2103 /* Select RISC module registers. */
2104 WRT_REG_WORD(®->ctrl_status, 0);
2105 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
2107 /* Reset RISC processor. */
2108 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
2109 RD_REG_WORD(®->hccr); /* PCI Posting. */
2111 /* Release RISC processor. */
2112 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
2113 RD_REG_WORD(®->hccr); /* PCI Posting. */
2116 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
2117 WRT_REG_WORD(®->hccr, HCCR_CLR_HOST_INT);
2119 /* Reset ISP chip. */
2120 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
2122 /* Wait for RISC to recover from reset. */
2123 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
2125 * It is necessary to for a delay here since the card doesn't
2126 * respond to PCI reads during a reset. On some architectures
2127 * this will result in an MCA.
2130 for (cnt = 30000; cnt; cnt--) {
2131 if ((RD_REG_WORD(®->ctrl_status) &
2132 CSR_ISP_SOFT_RESET) == 0)
2139 /* Reset RISC processor. */
2140 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
2142 WRT_REG_WORD(®->semaphore, 0);
2144 /* Release RISC processor. */
2145 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
2146 RD_REG_WORD(®->hccr); /* PCI Posting. */
2148 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
2149 for (cnt = 0; cnt < 30000; cnt++) {
2150 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
2158 /* Turn on master enable */
2159 cmd |= PCI_COMMAND_MASTER;
2160 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
2162 /* Disable RISC pause on FPM parity error. */
2163 if (!IS_QLA2100(ha)) {
2164 WRT_REG_WORD(®->hccr, HCCR_DISABLE_PARITY_PAUSE);
2165 RD_REG_WORD(®->hccr); /* PCI Posting. */
2168 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2172 * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC.
2174 * Returns 0 on success.
2177 qla81xx_reset_mpi(scsi_qla_host_t *vha)
2179 uint16_t mb[4] = {0x1010, 0, 1, 0};
2181 if (!IS_QLA81XX(vha->hw))
2184 return qla81xx_write_mpi_register(vha, mb);
2188 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
2191 * Returns 0 on success.
2194 qla24xx_reset_risc(scsi_qla_host_t *vha)
2196 unsigned long flags = 0;
2197 struct qla_hw_data *ha = vha->hw;
2198 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2201 static int abts_cnt; /* ISP abort retry counts */
2202 int rval = QLA_SUCCESS;
2204 spin_lock_irqsave(&ha->hardware_lock, flags);
2207 WRT_REG_DWORD(®->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
2208 for (cnt = 0; cnt < 30000; cnt++) {
2209 if ((RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
2215 if (!(RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE))
2216 set_bit(DMA_SHUTDOWN_CMPL, &ha->fw_dump_cap_flags);
2218 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017e,
2219 "HCCR: 0x%x, Control Status %x, DMA active status:0x%x\n",
2220 RD_REG_DWORD(®->hccr),
2221 RD_REG_DWORD(®->ctrl_status),
2222 (RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE));
2224 WRT_REG_DWORD(®->ctrl_status,
2225 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
2226 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
2230 /* Wait for firmware to complete NVRAM accesses. */
2231 RD_REG_WORD(®->mailbox0);
2232 for (cnt = 10000; RD_REG_WORD(®->mailbox0) != 0 &&
2233 rval == QLA_SUCCESS; cnt--) {
2238 rval = QLA_FUNCTION_TIMEOUT;
2241 if (rval == QLA_SUCCESS)
2242 set_bit(ISP_MBX_RDY, &ha->fw_dump_cap_flags);
2244 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017f,
2245 "HCCR: 0x%x, MailBox0 Status 0x%x\n",
2246 RD_REG_DWORD(®->hccr),
2247 RD_REG_DWORD(®->mailbox0));
2249 /* Wait for soft-reset to complete. */
2250 RD_REG_DWORD(®->ctrl_status);
2251 for (cnt = 0; cnt < 60; cnt++) {
2253 if ((RD_REG_DWORD(®->ctrl_status) &
2254 CSRX_ISP_SOFT_RESET) == 0)
2259 if (!(RD_REG_DWORD(®->ctrl_status) & CSRX_ISP_SOFT_RESET))
2260 set_bit(ISP_SOFT_RESET_CMPL, &ha->fw_dump_cap_flags);
2262 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015d,
2263 "HCCR: 0x%x, Soft Reset status: 0x%x\n",
2264 RD_REG_DWORD(®->hccr),
2265 RD_REG_DWORD(®->ctrl_status));
2267 /* If required, do an MPI FW reset now */
2268 if (test_and_clear_bit(MPI_RESET_NEEDED, &vha->dpc_flags)) {
2269 if (qla81xx_reset_mpi(vha) != QLA_SUCCESS) {
2270 if (++abts_cnt < 5) {
2271 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
2272 set_bit(MPI_RESET_NEEDED, &vha->dpc_flags);
2275 * We exhausted the ISP abort retries. We have to
2276 * set the board offline.
2279 vha->flags.online = 0;
2284 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
2285 RD_REG_DWORD(®->hccr);
2287 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
2288 RD_REG_DWORD(®->hccr);
2290 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_RESET);
2291 RD_REG_DWORD(®->hccr);
2293 RD_REG_WORD(®->mailbox0);
2294 for (cnt = 60; RD_REG_WORD(®->mailbox0) != 0 &&
2295 rval == QLA_SUCCESS; cnt--) {
2300 rval = QLA_FUNCTION_TIMEOUT;
2302 if (rval == QLA_SUCCESS)
2303 set_bit(RISC_RDY_AFT_RESET, &ha->fw_dump_cap_flags);
2305 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015e,
2306 "Host Risc 0x%x, mailbox0 0x%x\n",
2307 RD_REG_DWORD(®->hccr),
2308 RD_REG_WORD(®->mailbox0));
2310 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2312 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015f,
2313 "Driver in %s mode\n",
2314 IS_NOPOLLING_TYPE(ha) ? "Interrupt" : "Polling");
2316 if (IS_NOPOLLING_TYPE(ha))
2317 ha->isp_ops->enable_intrs(ha);
2323 qla25xx_read_risc_sema_reg(scsi_qla_host_t *vha, uint32_t *data)
2325 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
2327 WRT_REG_DWORD(®->iobase_addr, RISC_REGISTER_BASE_OFFSET);
2328 *data = RD_REG_DWORD(®->iobase_window + RISC_REGISTER_WINDOW_OFFET);
2333 qla25xx_write_risc_sema_reg(scsi_qla_host_t *vha, uint32_t data)
2335 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
2337 WRT_REG_DWORD(®->iobase_addr, RISC_REGISTER_BASE_OFFSET);
2338 WRT_REG_DWORD(®->iobase_window + RISC_REGISTER_WINDOW_OFFET, data);
2342 qla25xx_manipulate_risc_semaphore(scsi_qla_host_t *vha)
2345 uint delta_msec = 100;
2346 uint elapsed_msec = 0;
2350 if (vha->hw->pdev->subsystem_device != 0x0175 &&
2351 vha->hw->pdev->subsystem_device != 0x0240)
2354 WRT_REG_DWORD(&vha->hw->iobase->isp24.hccr, HCCRX_SET_RISC_PAUSE);
2358 timeout_msec = TIMEOUT_SEMAPHORE;
2359 n = timeout_msec / delta_msec;
2361 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_SET);
2362 qla25xx_read_risc_sema_reg(vha, &wd32);
2363 if (wd32 & RISC_SEMAPHORE)
2366 elapsed_msec += delta_msec;
2367 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
2371 if (!(wd32 & RISC_SEMAPHORE))
2374 if (!(wd32 & RISC_SEMAPHORE_FORCE))
2377 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_CLR);
2378 timeout_msec = TIMEOUT_SEMAPHORE_FORCE;
2379 n = timeout_msec / delta_msec;
2381 qla25xx_read_risc_sema_reg(vha, &wd32);
2382 if (!(wd32 & RISC_SEMAPHORE_FORCE))
2385 elapsed_msec += delta_msec;
2386 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
2390 if (wd32 & RISC_SEMAPHORE_FORCE)
2391 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_CLR);
2396 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_SET);
2403 * qla24xx_reset_chip() - Reset ISP24xx chip.
2406 * Returns 0 on success.
2409 qla24xx_reset_chip(scsi_qla_host_t *vha)
2411 struct qla_hw_data *ha = vha->hw;
2413 if (pci_channel_offline(ha->pdev) &&
2414 ha->flags.pci_channel_io_perm_failure) {
2418 ha->isp_ops->disable_intrs(ha);
2420 qla25xx_manipulate_risc_semaphore(vha);
2422 /* Perform RISC reset. */
2423 qla24xx_reset_risc(vha);
2427 * qla2x00_chip_diag() - Test chip for proper operation.
2430 * Returns 0 on success.
2433 qla2x00_chip_diag(scsi_qla_host_t *vha)
2436 struct qla_hw_data *ha = vha->hw;
2437 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2438 unsigned long flags = 0;
2442 struct req_que *req = ha->req_q_map[0];
2444 /* Assume a failed state */
2445 rval = QLA_FUNCTION_FAILED;
2447 ql_dbg(ql_dbg_init, vha, 0x007b,
2448 "Testing device at %lx.\n", (u_long)®->flash_address);
2450 spin_lock_irqsave(&ha->hardware_lock, flags);
2452 /* Reset ISP chip. */
2453 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
2456 * We need to have a delay here since the card will not respond while
2457 * in reset causing an MCA on some architectures.
2460 data = qla2x00_debounce_register(®->ctrl_status);
2461 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
2463 data = RD_REG_WORD(®->ctrl_status);
2468 goto chip_diag_failed;
2470 ql_dbg(ql_dbg_init, vha, 0x007c,
2471 "Reset register cleared by chip reset.\n");
2473 /* Reset RISC processor. */
2474 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
2475 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
2477 /* Workaround for QLA2312 PCI parity error */
2478 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
2479 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
2480 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
2482 data = RD_MAILBOX_REG(ha, reg, 0);
2489 goto chip_diag_failed;
2491 /* Check product ID of chip */
2492 ql_dbg(ql_dbg_init, vha, 0x007d, "Checking product ID of chip.\n");
2494 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
2495 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
2496 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
2497 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
2498 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
2499 mb[3] != PROD_ID_3) {
2500 ql_log(ql_log_warn, vha, 0x0062,
2501 "Wrong product ID = 0x%x,0x%x,0x%x.\n",
2502 mb[1], mb[2], mb[3]);
2504 goto chip_diag_failed;
2506 ha->product_id[0] = mb[1];
2507 ha->product_id[1] = mb[2];
2508 ha->product_id[2] = mb[3];
2509 ha->product_id[3] = mb[4];
2511 /* Adjust fw RISC transfer size */
2512 if (req->length > 1024)
2513 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
2515 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
2518 if (IS_QLA2200(ha) &&
2519 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
2520 /* Limit firmware transfer size with a 2200A */
2521 ql_dbg(ql_dbg_init, vha, 0x007e, "Found QLA2200A Chip.\n");
2523 ha->device_type |= DT_ISP2200A;
2524 ha->fw_transfer_size = 128;
2527 /* Wrap Incoming Mailboxes Test. */
2528 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2530 ql_dbg(ql_dbg_init, vha, 0x007f, "Checking mailboxes.\n");
2531 rval = qla2x00_mbx_reg_test(vha);
2533 ql_log(ql_log_warn, vha, 0x0080,
2534 "Failed mailbox send register test.\n");
2536 /* Flag a successful rval */
2538 spin_lock_irqsave(&ha->hardware_lock, flags);
2542 ql_log(ql_log_info, vha, 0x0081,
2543 "Chip diagnostics **** FAILED ****.\n");
2545 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2551 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
2554 * Returns 0 on success.
2557 qla24xx_chip_diag(scsi_qla_host_t *vha)
2560 struct qla_hw_data *ha = vha->hw;
2561 struct req_que *req = ha->req_q_map[0];
2563 if (IS_P3P_TYPE(ha))
2566 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
2568 rval = qla2x00_mbx_reg_test(vha);
2570 ql_log(ql_log_warn, vha, 0x0082,
2571 "Failed mailbox send register test.\n");
2573 /* Flag a successful rval */
2581 qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
2584 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
2585 eft_size, fce_size, mq_size;
2588 struct qla_hw_data *ha = vha->hw;
2589 struct req_que *req = ha->req_q_map[0];
2590 struct rsp_que *rsp = ha->rsp_q_map[0];
2593 ql_dbg(ql_dbg_init, vha, 0x00bd,
2594 "Firmware dump already allocated.\n");
2599 ha->fw_dump_cap_flags = 0;
2600 dump_size = fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
2601 req_q_size = rsp_q_size = 0;
2606 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
2607 fixed_size = sizeof(struct qla2100_fw_dump);
2608 } else if (IS_QLA23XX(ha)) {
2609 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
2610 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
2612 } else if (IS_FWI2_CAPABLE(ha)) {
2613 if (IS_QLA83XX(ha) || IS_QLA27XX(ha))
2614 fixed_size = offsetof(struct qla83xx_fw_dump, ext_mem);
2615 else if (IS_QLA81XX(ha))
2616 fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem);
2617 else if (IS_QLA25XX(ha))
2618 fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem);
2620 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
2622 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
2625 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha))
2626 mq_size = sizeof(struct qla2xxx_mq_chain);
2628 * Allocate maximum buffer size for all queues.
2629 * Resizing must be done at end-of-dump processing.
2631 mq_size += ha->max_req_queues *
2632 (req->length * sizeof(request_t));
2633 mq_size += ha->max_rsp_queues *
2634 (rsp->length * sizeof(response_t));
2636 if (ha->tgt.atio_ring)
2637 mq_size += ha->tgt.atio_q_length * sizeof(request_t);
2638 /* Allocate memory for Fibre Channel Event Buffer. */
2639 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
2645 dma_free_coherent(&ha->pdev->dev,
2646 FCE_SIZE, ha->fce, ha->fce_dma);
2648 /* Allocate memory for Fibre Channel Event Buffer. */
2649 tc = dma_zalloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
2652 ql_log(ql_log_warn, vha, 0x00be,
2653 "Unable to allocate (%d KB) for FCE.\n",
2658 rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
2659 ha->fce_mb, &ha->fce_bufs);
2661 ql_log(ql_log_warn, vha, 0x00bf,
2662 "Unable to initialize FCE (%d).\n", rval);
2663 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc,
2665 ha->flags.fce_enabled = 0;
2668 ql_dbg(ql_dbg_init, vha, 0x00c0,
2669 "Allocate (%d KB) for FCE...\n", FCE_SIZE / 1024);
2671 fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
2672 ha->flags.fce_enabled = 1;
2673 ha->fce_dma = tc_dma;
2678 dma_free_coherent(&ha->pdev->dev,
2679 EFT_SIZE, ha->eft, ha->eft_dma);
2681 /* Allocate memory for Extended Trace Buffer. */
2682 tc = dma_zalloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
2685 ql_log(ql_log_warn, vha, 0x00c1,
2686 "Unable to allocate (%d KB) for EFT.\n",
2691 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
2693 ql_log(ql_log_warn, vha, 0x00c2,
2694 "Unable to initialize EFT (%d).\n", rval);
2695 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
2699 ql_dbg(ql_dbg_init, vha, 0x00c3,
2700 "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024);
2702 eft_size = EFT_SIZE;
2703 ha->eft_dma = tc_dma;
2708 if (IS_QLA27XX(ha)) {
2709 if (!ha->fw_dump_template) {
2710 ql_log(ql_log_warn, vha, 0x00ba,
2711 "Failed missing fwdump template\n");
2714 dump_size = qla27xx_fwdt_calculate_dump_size(vha);
2715 ql_dbg(ql_dbg_init, vha, 0x00fa,
2716 "-> allocating fwdump (%x bytes)...\n", dump_size);
2720 req_q_size = req->length * sizeof(request_t);
2721 rsp_q_size = rsp->length * sizeof(response_t);
2722 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
2723 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size + eft_size;
2724 ha->chain_offset = dump_size;
2725 dump_size += mq_size + fce_size;
2727 if (ha->exchoffld_buf)
2728 dump_size += sizeof(struct qla2xxx_offld_chain) +
2730 if (ha->exlogin_buf)
2731 dump_size += sizeof(struct qla2xxx_offld_chain) +
2735 ha->fw_dump = vmalloc(dump_size);
2737 ql_log(ql_log_warn, vha, 0x00c4,
2738 "Unable to allocate (%d KB) for firmware dump.\n",
2742 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce,
2749 dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft,
2756 ha->fw_dump_len = dump_size;
2757 ql_dbg(ql_dbg_init, vha, 0x00c5,
2758 "Allocated (%d KB) for firmware dump.\n", dump_size / 1024);
2763 ha->fw_dump->signature[0] = 'Q';
2764 ha->fw_dump->signature[1] = 'L';
2765 ha->fw_dump->signature[2] = 'G';
2766 ha->fw_dump->signature[3] = 'C';
2767 ha->fw_dump->version = htonl(1);
2769 ha->fw_dump->fixed_size = htonl(fixed_size);
2770 ha->fw_dump->mem_size = htonl(mem_size);
2771 ha->fw_dump->req_q_size = htonl(req_q_size);
2772 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
2774 ha->fw_dump->eft_size = htonl(eft_size);
2775 ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
2776 ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
2778 ha->fw_dump->header_size =
2779 htonl(offsetof(struct qla2xxx_fw_dump, isp));
2783 qla81xx_mpi_sync(scsi_qla_host_t *vha)
2785 #define MPS_MASK 0xe0
2790 if (!IS_QLA81XX(vha->hw))
2793 rval = qla2x00_write_ram_word(vha, 0x7c00, 1);
2794 if (rval != QLA_SUCCESS) {
2795 ql_log(ql_log_warn, vha, 0x0105,
2796 "Unable to acquire semaphore.\n");
2800 pci_read_config_word(vha->hw->pdev, 0x54, &dc);
2801 rval = qla2x00_read_ram_word(vha, 0x7a15, &dw);
2802 if (rval != QLA_SUCCESS) {
2803 ql_log(ql_log_warn, vha, 0x0067, "Unable to read sync.\n");
2808 if (dc == (dw & MPS_MASK))
2813 rval = qla2x00_write_ram_word(vha, 0x7a15, dw);
2814 if (rval != QLA_SUCCESS) {
2815 ql_log(ql_log_warn, vha, 0x0114, "Unable to gain sync.\n");
2819 rval = qla2x00_write_ram_word(vha, 0x7c00, 0);
2820 if (rval != QLA_SUCCESS) {
2821 ql_log(ql_log_warn, vha, 0x006d,
2822 "Unable to release semaphore.\n");
2830 qla2x00_alloc_outstanding_cmds(struct qla_hw_data *ha, struct req_que *req)
2832 /* Don't try to reallocate the array */
2833 if (req->outstanding_cmds)
2836 if (!IS_FWI2_CAPABLE(ha))
2837 req->num_outstanding_cmds = DEFAULT_OUTSTANDING_COMMANDS;
2839 if (ha->cur_fw_xcb_count <= ha->cur_fw_iocb_count)
2840 req->num_outstanding_cmds = ha->cur_fw_xcb_count;
2842 req->num_outstanding_cmds = ha->cur_fw_iocb_count;
2845 req->outstanding_cmds = kzalloc(sizeof(srb_t *) *
2846 req->num_outstanding_cmds, GFP_KERNEL);
2848 if (!req->outstanding_cmds) {
2850 * Try to allocate a minimal size just so we can get through
2853 req->num_outstanding_cmds = MIN_OUTSTANDING_COMMANDS;
2854 req->outstanding_cmds = kzalloc(sizeof(srb_t *) *
2855 req->num_outstanding_cmds, GFP_KERNEL);
2857 if (!req->outstanding_cmds) {
2858 ql_log(ql_log_fatal, NULL, 0x0126,
2859 "Failed to allocate memory for "
2860 "outstanding_cmds for req_que %p.\n", req);
2861 req->num_outstanding_cmds = 0;
2862 return QLA_FUNCTION_FAILED;
2869 #define PRINT_FIELD(_field, _flag, _str) { \
2870 if (a0->_field & _flag) {\
2876 len = snprintf(ptr, leftover, "%s", _str); \
2883 static void qla2xxx_print_sfp_info(struct scsi_qla_host *vha)
2886 struct sff_8247_a0 *a0 = (struct sff_8247_a0 *)vha->hw->sfp_data;
2887 u8 str[STR_LEN], *ptr, p;
2890 memset(str, 0, STR_LEN);
2891 snprintf(str, SFF_VEN_NAME_LEN+1, a0->vendor_name);
2892 ql_dbg(ql_dbg_init, vha, 0x015a,
2893 "SFP MFG Name: %s\n", str);
2895 memset(str, 0, STR_LEN);
2896 snprintf(str, SFF_PART_NAME_LEN+1, a0->vendor_pn);
2897 ql_dbg(ql_dbg_init, vha, 0x015c,
2898 "SFP Part Name: %s\n", str);
2901 memset(str, 0, STR_LEN);
2905 PRINT_FIELD(fc_med_cc9, FC_MED_TW, "Twin AX");
2906 PRINT_FIELD(fc_med_cc9, FC_MED_TP, "Twisted Pair");
2907 PRINT_FIELD(fc_med_cc9, FC_MED_MI, "Min Coax");
2908 PRINT_FIELD(fc_med_cc9, FC_MED_TV, "Video Coax");
2909 PRINT_FIELD(fc_med_cc9, FC_MED_M6, "MultiMode 62.5um");
2910 PRINT_FIELD(fc_med_cc9, FC_MED_M5, "MultiMode 50um");
2911 PRINT_FIELD(fc_med_cc9, FC_MED_SM, "SingleMode");
2912 ql_dbg(ql_dbg_init, vha, 0x0160,
2913 "SFP Media: %s\n", str);
2916 memset(str, 0, STR_LEN);
2920 PRINT_FIELD(fc_ll_cc7, FC_LL_VL, "Very Long");
2921 PRINT_FIELD(fc_ll_cc7, FC_LL_S, "Short");
2922 PRINT_FIELD(fc_ll_cc7, FC_LL_I, "Intermediate");
2923 PRINT_FIELD(fc_ll_cc7, FC_LL_L, "Long");
2924 PRINT_FIELD(fc_ll_cc7, FC_LL_M, "Medium");
2925 ql_dbg(ql_dbg_init, vha, 0x0196,
2926 "SFP Link Length: %s\n", str);
2928 memset(str, 0, STR_LEN);
2932 PRINT_FIELD(fc_ll_cc7, FC_LL_SA, "Short Wave (SA)");
2933 PRINT_FIELD(fc_ll_cc7, FC_LL_LC, "Long Wave(LC)");
2934 PRINT_FIELD(fc_tec_cc8, FC_TEC_SN, "Short Wave (SN)");
2935 PRINT_FIELD(fc_tec_cc8, FC_TEC_SL, "Short Wave (SL)");
2936 PRINT_FIELD(fc_tec_cc8, FC_TEC_LL, "Long Wave (LL)");
2937 ql_dbg(ql_dbg_init, vha, 0x016e,
2938 "SFP FC Link Tech: %s\n", str);
2941 ql_dbg(ql_dbg_init, vha, 0x016f,
2942 "SFP Distant: %d km\n", a0->length_km);
2943 if (a0->length_100m)
2944 ql_dbg(ql_dbg_init, vha, 0x0170,
2945 "SFP Distant: %d m\n", a0->length_100m*100);
2946 if (a0->length_50um_10m)
2947 ql_dbg(ql_dbg_init, vha, 0x0189,
2948 "SFP Distant (WL=50um): %d m\n", a0->length_50um_10m * 10);
2949 if (a0->length_62um_10m)
2950 ql_dbg(ql_dbg_init, vha, 0x018a,
2951 "SFP Distant (WL=62.5um): %d m\n", a0->length_62um_10m * 10);
2952 if (a0->length_om4_10m)
2953 ql_dbg(ql_dbg_init, vha, 0x0194,
2954 "SFP Distant (OM4): %d m\n", a0->length_om4_10m * 10);
2955 if (a0->length_om3_10m)
2956 ql_dbg(ql_dbg_init, vha, 0x0195,
2957 "SFP Distant (OM3): %d m\n", a0->length_om3_10m * 10);
2963 * QLA_SUCCESS: no action
2964 * QLA_INTERFACE_ERROR: SFP is not there.
2965 * QLA_FUNCTION_FAILED: detected New SFP
2968 qla24xx_detect_sfp(scsi_qla_host_t *vha)
2970 int rc = QLA_SUCCESS;
2971 struct sff_8247_a0 *a;
2972 struct qla_hw_data *ha = vha->hw;
2974 if (!AUTO_DETECT_SFP_SUPPORT(vha))
2977 rc = qla2x00_read_sfp_dev(vha, NULL, 0);
2981 a = (struct sff_8247_a0 *)vha->hw->sfp_data;
2982 qla2xxx_print_sfp_info(vha);
2984 if (a->fc_ll_cc7 & FC_LL_VL || a->fc_ll_cc7 & FC_LL_L) {
2986 ha->flags.detected_lr_sfp = 1;
2988 if (a->length_km > 5 || a->length_100m > 50)
2989 ha->long_range_distance = LR_DISTANCE_10K;
2991 ha->long_range_distance = LR_DISTANCE_5K;
2993 if (ha->flags.detected_lr_sfp != ha->flags.using_lr_setting)
2994 ql_dbg(ql_dbg_async, vha, 0x507b,
2995 "Detected Long Range SFP.\n");
2998 ha->flags.detected_lr_sfp = 0;
2999 if (ha->flags.using_lr_setting)
3000 ql_dbg(ql_dbg_async, vha, 0x5084,
3001 "Detected Short Range SFP.\n");
3004 if (!vha->flags.init_done)
3011 * qla2x00_setup_chip() - Load and start RISC firmware.
3014 * Returns 0 on success.
3017 qla2x00_setup_chip(scsi_qla_host_t *vha)
3020 uint32_t srisc_address = 0;
3021 struct qla_hw_data *ha = vha->hw;
3022 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3023 unsigned long flags;
3024 uint16_t fw_major_version;
3026 if (IS_P3P_TYPE(ha)) {
3027 rval = ha->isp_ops->load_risc(vha, &srisc_address);
3028 if (rval == QLA_SUCCESS) {
3029 qla2x00_stop_firmware(vha);
3030 goto enable_82xx_npiv;
3035 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
3036 /* Disable SRAM, Instruction RAM and GP RAM parity. */
3037 spin_lock_irqsave(&ha->hardware_lock, flags);
3038 WRT_REG_WORD(®->hccr, (HCCR_ENABLE_PARITY + 0x0));
3039 RD_REG_WORD(®->hccr);
3040 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3043 qla81xx_mpi_sync(vha);
3045 /* Load firmware sequences */
3046 rval = ha->isp_ops->load_risc(vha, &srisc_address);
3047 if (rval == QLA_SUCCESS) {
3048 ql_dbg(ql_dbg_init, vha, 0x00c9,
3049 "Verifying Checksum of loaded RISC code.\n");
3051 rval = qla2x00_verify_checksum(vha, srisc_address);
3052 if (rval == QLA_SUCCESS) {
3053 /* Start firmware execution. */
3054 ql_dbg(ql_dbg_init, vha, 0x00ca,
3055 "Starting firmware.\n");
3058 ha->flags.exlogins_enabled = 1;
3060 if (qla_is_exch_offld_enabled(vha))
3061 ha->flags.exchoffld_enabled = 1;
3063 rval = qla2x00_execute_fw(vha, srisc_address);
3064 /* Retrieve firmware information. */
3065 if (rval == QLA_SUCCESS) {
3066 qla24xx_detect_sfp(vha);
3068 rval = qla2x00_set_exlogins_buffer(vha);
3069 if (rval != QLA_SUCCESS)
3072 rval = qla2x00_set_exchoffld_buffer(vha);
3073 if (rval != QLA_SUCCESS)
3077 fw_major_version = ha->fw_major_version;
3078 if (IS_P3P_TYPE(ha))
3079 qla82xx_check_md_needed(vha);
3081 rval = qla2x00_get_fw_version(vha);
3082 if (rval != QLA_SUCCESS)
3084 ha->flags.npiv_supported = 0;
3085 if (IS_QLA2XXX_MIDTYPE(ha) &&
3086 (ha->fw_attributes & BIT_2)) {
3087 ha->flags.npiv_supported = 1;
3088 if ((!ha->max_npiv_vports) ||
3089 ((ha->max_npiv_vports + 1) %
3090 MIN_MULTI_ID_FABRIC))
3091 ha->max_npiv_vports =
3092 MIN_MULTI_ID_FABRIC - 1;
3094 qla2x00_get_resource_cnts(vha);
3097 * Allocate the array of outstanding commands
3098 * now that we know the firmware resources.
3100 rval = qla2x00_alloc_outstanding_cmds(ha,
3102 if (rval != QLA_SUCCESS)
3105 if (!fw_major_version && ql2xallocfwdump
3106 && !(IS_P3P_TYPE(ha)))
3107 qla2x00_alloc_fw_dump(vha);
3112 ql_log(ql_log_fatal, vha, 0x00cd,
3113 "ISP Firmware failed checksum.\n");
3119 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
3120 /* Enable proper parity. */
3121 spin_lock_irqsave(&ha->hardware_lock, flags);
3124 WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x1);
3126 /* SRAM, Instruction RAM and GP RAM parity */
3127 WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x7);
3128 RD_REG_WORD(®->hccr);
3129 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3133 ha->flags.fac_supported = 1;
3134 else if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) {
3137 rval = qla81xx_fac_get_sector_size(vha, &size);
3138 if (rval == QLA_SUCCESS) {
3139 ha->flags.fac_supported = 1;
3140 ha->fdt_block_size = size << 2;
3142 ql_log(ql_log_warn, vha, 0x00ce,
3143 "Unsupported FAC firmware (%d.%02d.%02d).\n",
3144 ha->fw_major_version, ha->fw_minor_version,
3145 ha->fw_subminor_version);
3147 if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
3148 ha->flags.fac_supported = 0;
3155 ql_log(ql_log_fatal, vha, 0x00cf,
3156 "Setup chip ****FAILED****.\n");
3163 * qla2x00_init_response_q_entries() - Initializes response queue entries.
3166 * Beginning of request ring has initialization control block already built
3167 * by nvram config routine.
3169 * Returns 0 on success.
3172 qla2x00_init_response_q_entries(struct rsp_que *rsp)
3177 rsp->ring_ptr = rsp->ring;
3178 rsp->ring_index = 0;
3179 rsp->status_srb = NULL;
3180 pkt = rsp->ring_ptr;
3181 for (cnt = 0; cnt < rsp->length; cnt++) {
3182 pkt->signature = RESPONSE_PROCESSED;
3188 * qla2x00_update_fw_options() - Read and process firmware options.
3191 * Returns 0 on success.
3194 qla2x00_update_fw_options(scsi_qla_host_t *vha)
3196 uint16_t swing, emphasis, tx_sens, rx_sens;
3197 struct qla_hw_data *ha = vha->hw;
3199 memset(ha->fw_options, 0, sizeof(ha->fw_options));
3200 qla2x00_get_fw_options(vha, ha->fw_options);
3202 if (IS_QLA2100(ha) || IS_QLA2200(ha))
3205 /* Serial Link options. */
3206 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0115,
3207 "Serial link options.\n");
3208 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0109,
3209 (uint8_t *)&ha->fw_seriallink_options,
3210 sizeof(ha->fw_seriallink_options));
3212 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
3213 if (ha->fw_seriallink_options[3] & BIT_2) {
3214 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
3217 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
3218 emphasis = (ha->fw_seriallink_options[2] &
3219 (BIT_4 | BIT_3)) >> 3;
3220 tx_sens = ha->fw_seriallink_options[0] &
3221 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
3222 rx_sens = (ha->fw_seriallink_options[0] &
3223 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
3224 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
3225 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
3228 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
3229 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
3230 ha->fw_options[10] |= BIT_5 |
3231 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
3232 (tx_sens & (BIT_1 | BIT_0));
3235 swing = (ha->fw_seriallink_options[2] &
3236 (BIT_7 | BIT_6 | BIT_5)) >> 5;
3237 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
3238 tx_sens = ha->fw_seriallink_options[1] &
3239 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
3240 rx_sens = (ha->fw_seriallink_options[1] &
3241 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
3242 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
3243 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
3246 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
3247 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
3248 ha->fw_options[11] |= BIT_5 |
3249 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
3250 (tx_sens & (BIT_1 | BIT_0));
3254 /* Return command IOCBs without waiting for an ABTS to complete. */
3255 ha->fw_options[3] |= BIT_13;
3258 if (ha->flags.enable_led_scheme)
3259 ha->fw_options[2] |= BIT_12;
3261 /* Detect ISP6312. */
3263 ha->fw_options[2] |= BIT_13;
3265 /* Set Retry FLOGI in case of P2P connection */
3266 if (ha->operating_mode == P2P) {
3267 ha->fw_options[2] |= BIT_3;
3268 ql_dbg(ql_dbg_disc, vha, 0x2100,
3269 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
3270 __func__, ha->fw_options[2]);
3273 /* Update firmware options. */
3274 qla2x00_set_fw_options(vha, ha->fw_options);
3278 qla24xx_update_fw_options(scsi_qla_host_t *vha)
3281 struct qla_hw_data *ha = vha->hw;
3283 if (IS_P3P_TYPE(ha))
3286 /* Hold status IOCBs until ABTS response received. */
3288 ha->fw_options[3] |= BIT_12;
3290 /* Set Retry FLOGI in case of P2P connection */
3291 if (ha->operating_mode == P2P) {
3292 ha->fw_options[2] |= BIT_3;
3293 ql_dbg(ql_dbg_disc, vha, 0x2101,
3294 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
3295 __func__, ha->fw_options[2]);
3298 /* Move PUREX, ABTS RX & RIDA to ATIOQ */
3299 if (ql2xmvasynctoatio &&
3300 (IS_QLA83XX(ha) || IS_QLA27XX(ha))) {
3301 if (qla_tgt_mode_enabled(vha) ||
3302 qla_dual_mode_enabled(vha))
3303 ha->fw_options[2] |= BIT_11;
3305 ha->fw_options[2] &= ~BIT_11;
3308 if (IS_QLA25XX(ha) || IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
3310 * Tell FW to track each exchange to prevent
3311 * driver from using stale exchange.
3313 if (qla_tgt_mode_enabled(vha) ||
3314 qla_dual_mode_enabled(vha))
3315 ha->fw_options[2] |= BIT_4;
3317 ha->fw_options[2] &= ~BIT_4;
3320 ql_dbg(ql_dbg_init, vha, 0x00e8,
3321 "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n",
3322 __func__, ha->fw_options[1], ha->fw_options[2],
3323 ha->fw_options[3], vha->host->active_mode);
3325 if (ha->fw_options[1] || ha->fw_options[2] || ha->fw_options[3])
3326 qla2x00_set_fw_options(vha, ha->fw_options);
3328 /* Update Serial Link options. */
3329 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
3332 rval = qla2x00_set_serdes_params(vha,
3333 le16_to_cpu(ha->fw_seriallink_options24[1]),
3334 le16_to_cpu(ha->fw_seriallink_options24[2]),
3335 le16_to_cpu(ha->fw_seriallink_options24[3]));
3336 if (rval != QLA_SUCCESS) {
3337 ql_log(ql_log_warn, vha, 0x0104,
3338 "Unable to update Serial Link options (%x).\n", rval);
3343 qla2x00_config_rings(struct scsi_qla_host *vha)
3345 struct qla_hw_data *ha = vha->hw;
3346 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3347 struct req_que *req = ha->req_q_map[0];
3348 struct rsp_que *rsp = ha->rsp_q_map[0];
3350 /* Setup ring parameters in initialization control block. */
3351 ha->init_cb->request_q_outpointer = cpu_to_le16(0);
3352 ha->init_cb->response_q_inpointer = cpu_to_le16(0);
3353 ha->init_cb->request_q_length = cpu_to_le16(req->length);
3354 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
3355 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
3356 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
3357 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
3358 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
3360 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
3361 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
3362 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
3363 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
3364 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
3368 qla24xx_config_rings(struct scsi_qla_host *vha)
3370 struct qla_hw_data *ha = vha->hw;
3371 device_reg_t *reg = ISP_QUE_REG(ha, 0);
3372 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
3373 struct qla_msix_entry *msix;
3374 struct init_cb_24xx *icb;
3376 struct req_que *req = ha->req_q_map[0];
3377 struct rsp_que *rsp = ha->rsp_q_map[0];
3379 /* Setup ring parameters in initialization control block. */
3380 icb = (struct init_cb_24xx *)ha->init_cb;
3381 icb->request_q_outpointer = cpu_to_le16(0);
3382 icb->response_q_inpointer = cpu_to_le16(0);
3383 icb->request_q_length = cpu_to_le16(req->length);
3384 icb->response_q_length = cpu_to_le16(rsp->length);
3385 icb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
3386 icb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
3387 icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
3388 icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
3390 /* Setup ATIO queue dma pointers for target mode */
3391 icb->atio_q_inpointer = cpu_to_le16(0);
3392 icb->atio_q_length = cpu_to_le16(ha->tgt.atio_q_length);
3393 icb->atio_q_address[0] = cpu_to_le32(LSD(ha->tgt.atio_dma));
3394 icb->atio_q_address[1] = cpu_to_le32(MSD(ha->tgt.atio_dma));
3396 if (IS_SHADOW_REG_CAPABLE(ha))
3397 icb->firmware_options_2 |= cpu_to_le32(BIT_30|BIT_29);
3399 if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
3400 icb->qos = cpu_to_le16(QLA_DEFAULT_QUE_QOS);
3401 icb->rid = cpu_to_le16(rid);
3402 if (ha->flags.msix_enabled) {
3403 msix = &ha->msix_entries[1];
3404 ql_dbg(ql_dbg_init, vha, 0x0019,
3405 "Registering vector 0x%x for base que.\n",
3407 icb->msix = cpu_to_le16(msix->entry);
3409 /* Use alternate PCI bus number */
3411 icb->firmware_options_2 |= cpu_to_le32(BIT_19);
3412 /* Use alternate PCI devfn */
3414 icb->firmware_options_2 |= cpu_to_le32(BIT_18);
3416 /* Use Disable MSIX Handshake mode for capable adapters */
3417 if ((ha->fw_attributes & BIT_6) && (IS_MSIX_NACK_CAPABLE(ha)) &&
3418 (ha->flags.msix_enabled)) {
3419 icb->firmware_options_2 &= cpu_to_le32(~BIT_22);
3420 ha->flags.disable_msix_handshake = 1;
3421 ql_dbg(ql_dbg_init, vha, 0x00fe,
3422 "MSIX Handshake Disable Mode turned on.\n");
3424 icb->firmware_options_2 |= cpu_to_le32(BIT_22);
3426 icb->firmware_options_2 |= cpu_to_le32(BIT_23);
3428 WRT_REG_DWORD(®->isp25mq.req_q_in, 0);
3429 WRT_REG_DWORD(®->isp25mq.req_q_out, 0);
3430 WRT_REG_DWORD(®->isp25mq.rsp_q_in, 0);
3431 WRT_REG_DWORD(®->isp25mq.rsp_q_out, 0);
3433 WRT_REG_DWORD(®->isp24.req_q_in, 0);
3434 WRT_REG_DWORD(®->isp24.req_q_out, 0);
3435 WRT_REG_DWORD(®->isp24.rsp_q_in, 0);
3436 WRT_REG_DWORD(®->isp24.rsp_q_out, 0);
3438 qlt_24xx_config_rings(vha);
3441 RD_REG_DWORD(&ioreg->hccr);
3445 * qla2x00_init_rings() - Initializes firmware.
3448 * Beginning of request ring has initialization control block already built
3449 * by nvram config routine.
3451 * Returns 0 on success.
3454 qla2x00_init_rings(scsi_qla_host_t *vha)
3457 unsigned long flags = 0;
3459 struct qla_hw_data *ha = vha->hw;
3460 struct req_que *req;
3461 struct rsp_que *rsp;
3462 struct mid_init_cb_24xx *mid_init_cb =
3463 (struct mid_init_cb_24xx *) ha->init_cb;
3465 spin_lock_irqsave(&ha->hardware_lock, flags);
3467 /* Clear outstanding commands array. */
3468 for (que = 0; que < ha->max_req_queues; que++) {
3469 req = ha->req_q_map[que];
3470 if (!req || !test_bit(que, ha->req_qid_map))
3472 req->out_ptr = (void *)(req->ring + req->length);
3474 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++)
3475 req->outstanding_cmds[cnt] = NULL;
3477 req->current_outstanding_cmd = 1;
3479 /* Initialize firmware. */
3480 req->ring_ptr = req->ring;
3481 req->ring_index = 0;
3482 req->cnt = req->length;
3485 for (que = 0; que < ha->max_rsp_queues; que++) {
3486 rsp = ha->rsp_q_map[que];
3487 if (!rsp || !test_bit(que, ha->rsp_qid_map))
3489 rsp->in_ptr = (void *)(rsp->ring + rsp->length);
3491 /* Initialize response queue entries */
3493 qlafx00_init_response_q_entries(rsp);
3495 qla2x00_init_response_q_entries(rsp);
3498 ha->tgt.atio_ring_ptr = ha->tgt.atio_ring;
3499 ha->tgt.atio_ring_index = 0;
3500 /* Initialize ATIO queue entries */
3501 qlt_init_atio_q_entries(vha);
3503 ha->isp_ops->config_rings(vha);
3505 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3507 ql_dbg(ql_dbg_init, vha, 0x00d1, "Issue init firmware.\n");
3509 if (IS_QLAFX00(ha)) {
3510 rval = qlafx00_init_firmware(vha, ha->init_cb_size);
3514 /* Update any ISP specific firmware options before initialization. */
3515 ha->isp_ops->update_fw_options(vha);
3517 if (ha->flags.npiv_supported) {
3518 if (ha->operating_mode == LOOP && !IS_CNA_CAPABLE(ha))
3519 ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
3520 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
3523 if (IS_FWI2_CAPABLE(ha)) {
3524 mid_init_cb->options = cpu_to_le16(BIT_1);
3525 mid_init_cb->init_cb.execution_throttle =
3526 cpu_to_le16(ha->cur_fw_xcb_count);
3527 ha->flags.dport_enabled =
3528 (mid_init_cb->init_cb.firmware_options_1 & BIT_7) != 0;
3529 ql_dbg(ql_dbg_init, vha, 0x0191, "DPORT Support: %s.\n",
3530 (ha->flags.dport_enabled) ? "enabled" : "disabled");
3531 /* FA-WWPN Status */
3532 ha->flags.fawwpn_enabled =
3533 (mid_init_cb->init_cb.firmware_options_1 & BIT_6) != 0;
3534 ql_dbg(ql_dbg_init, vha, 0x00bc, "FA-WWPN Support: %s.\n",
3535 (ha->flags.fawwpn_enabled) ? "enabled" : "disabled");
3538 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
3541 ql_log(ql_log_fatal, vha, 0x00d2,
3542 "Init Firmware **** FAILED ****.\n");
3544 ql_dbg(ql_dbg_init, vha, 0x00d3,
3545 "Init Firmware -- success.\n");
3553 * qla2x00_fw_ready() - Waits for firmware ready.
3556 * Returns 0 on success.
3559 qla2x00_fw_ready(scsi_qla_host_t *vha)
3562 unsigned long wtime, mtime, cs84xx_time;
3563 uint16_t min_wait; /* Minimum wait time if loop is down */
3564 uint16_t wait_time; /* Wait time if loop is coming ready */
3566 struct qla_hw_data *ha = vha->hw;
3568 if (IS_QLAFX00(vha->hw))
3569 return qlafx00_fw_ready(vha);
3573 /* Time to wait for loop down */
3574 if (IS_P3P_TYPE(ha))
3580 * Firmware should take at most one RATOV to login, plus 5 seconds for
3581 * our own processing.
3583 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
3584 wait_time = min_wait;
3587 /* Min wait time if loop down */
3588 mtime = jiffies + (min_wait * HZ);
3590 /* wait time before firmware ready */
3591 wtime = jiffies + (wait_time * HZ);
3593 /* Wait for ISP to finish LIP */
3594 if (!vha->flags.init_done)
3595 ql_log(ql_log_info, vha, 0x801e,
3596 "Waiting for LIP to complete.\n");
3599 memset(state, -1, sizeof(state));
3600 rval = qla2x00_get_firmware_state(vha, state);
3601 if (rval == QLA_SUCCESS) {
3602 if (state[0] < FSTATE_LOSS_OF_SYNC) {
3603 vha->device_flags &= ~DFLG_NO_CABLE;
3605 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
3606 ql_dbg(ql_dbg_taskm, vha, 0x801f,
3607 "fw_state=%x 84xx=%x.\n", state[0],
3609 if ((state[2] & FSTATE_LOGGED_IN) &&
3610 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
3611 ql_dbg(ql_dbg_taskm, vha, 0x8028,
3612 "Sending verify iocb.\n");
3614 cs84xx_time = jiffies;
3615 rval = qla84xx_init_chip(vha);
3616 if (rval != QLA_SUCCESS) {
3619 "Init chip failed.\n");
3623 /* Add time taken to initialize. */
3624 cs84xx_time = jiffies - cs84xx_time;
3625 wtime += cs84xx_time;
3626 mtime += cs84xx_time;
3627 ql_dbg(ql_dbg_taskm, vha, 0x8008,
3628 "Increasing wait time by %ld. "
3629 "New time %ld.\n", cs84xx_time,
3632 } else if (state[0] == FSTATE_READY) {
3633 ql_dbg(ql_dbg_taskm, vha, 0x8037,
3634 "F/W Ready - OK.\n");
3636 qla2x00_get_retry_cnt(vha, &ha->retry_count,
3637 &ha->login_timeout, &ha->r_a_tov);
3643 rval = QLA_FUNCTION_FAILED;
3645 if (atomic_read(&vha->loop_down_timer) &&
3646 state[0] != FSTATE_READY) {
3647 /* Loop down. Timeout on min_wait for states
3648 * other than Wait for Login.
3650 if (time_after_eq(jiffies, mtime)) {
3651 ql_log(ql_log_info, vha, 0x8038,
3652 "Cable is unplugged...\n");
3654 vha->device_flags |= DFLG_NO_CABLE;
3659 /* Mailbox cmd failed. Timeout on min_wait. */
3660 if (time_after_eq(jiffies, mtime) ||
3661 ha->flags.isp82xx_fw_hung)
3665 if (time_after_eq(jiffies, wtime))
3668 /* Delay for a while */
3672 ql_dbg(ql_dbg_taskm, vha, 0x803a,
3673 "fw_state=%x (%x, %x, %x, %x %x) curr time=%lx.\n", state[0],
3674 state[1], state[2], state[3], state[4], state[5], jiffies);
3676 if (rval && !(vha->device_flags & DFLG_NO_CABLE)) {
3677 ql_log(ql_log_warn, vha, 0x803b,
3678 "Firmware ready **** FAILED ****.\n");
3685 * qla2x00_configure_hba
3686 * Setup adapter context.
3689 * ha = adapter state pointer.
3698 qla2x00_configure_hba(scsi_qla_host_t *vha)
3707 char connect_type[22];
3708 struct qla_hw_data *ha = vha->hw;
3709 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
3712 /* Get host addresses. */
3713 rval = qla2x00_get_adapter_id(vha,
3714 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
3715 if (rval != QLA_SUCCESS) {
3716 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
3717 IS_CNA_CAPABLE(ha) ||
3718 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
3719 ql_dbg(ql_dbg_disc, vha, 0x2008,
3720 "Loop is in a transition state.\n");
3722 ql_log(ql_log_warn, vha, 0x2009,
3723 "Unable to get host loop ID.\n");
3724 if (IS_FWI2_CAPABLE(ha) && (vha == base_vha) &&
3725 (rval == QLA_COMMAND_ERROR && loop_id == 0x1b)) {
3726 ql_log(ql_log_warn, vha, 0x1151,
3727 "Doing link init.\n");
3728 if (qla24xx_link_initialize(vha) == QLA_SUCCESS)
3731 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
3737 ql_log(ql_log_info, vha, 0x200a,
3738 "Cannot get topology - retrying.\n");
3739 return (QLA_FUNCTION_FAILED);
3742 vha->loop_id = loop_id;
3745 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
3746 ha->operating_mode = LOOP;
3751 ql_dbg(ql_dbg_disc, vha, 0x200b, "HBA in NL topology.\n");
3752 ha->current_topology = ISP_CFG_NL;
3753 strcpy(connect_type, "(Loop)");
3757 ql_dbg(ql_dbg_disc, vha, 0x200c, "HBA in FL topology.\n");
3758 ha->switch_cap = sw_cap;
3759 ha->current_topology = ISP_CFG_FL;
3760 strcpy(connect_type, "(FL_Port)");
3764 ql_dbg(ql_dbg_disc, vha, 0x200d, "HBA in N P2P topology.\n");
3765 ha->operating_mode = P2P;
3766 ha->current_topology = ISP_CFG_N;
3767 strcpy(connect_type, "(N_Port-to-N_Port)");
3771 ql_dbg(ql_dbg_disc, vha, 0x200e, "HBA in F P2P topology.\n");
3772 ha->switch_cap = sw_cap;
3773 ha->operating_mode = P2P;
3774 ha->current_topology = ISP_CFG_F;
3775 strcpy(connect_type, "(F_Port)");
3779 ql_dbg(ql_dbg_disc, vha, 0x200f,
3780 "HBA in unknown topology %x, using NL.\n", topo);
3781 ha->current_topology = ISP_CFG_NL;
3782 strcpy(connect_type, "(Loop)");
3786 /* Save Host port and loop ID. */
3787 /* byte order - Big Endian */
3788 id.b.domain = domain;
3792 qlt_update_host_map(vha, id);
3794 if (!vha->flags.init_done)
3795 ql_log(ql_log_info, vha, 0x2010,
3796 "Topology - %s, Host Loop address 0x%x.\n",
3797 connect_type, vha->loop_id);
3803 qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
3808 struct qla_hw_data *ha = vha->hw;
3809 int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) &&
3810 !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha);
3812 if (memcmp(model, BINZERO, len) != 0) {
3813 strncpy(ha->model_number, model, len);
3814 st = en = ha->model_number;
3817 if (*en != 0x20 && *en != 0x00)
3822 index = (ha->pdev->subsystem_device & 0xff);
3824 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
3825 index < QLA_MODEL_NAMES)
3826 strncpy(ha->model_desc,
3827 qla2x00_model_name[index * 2 + 1],
3828 sizeof(ha->model_desc) - 1);
3830 index = (ha->pdev->subsystem_device & 0xff);
3832 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
3833 index < QLA_MODEL_NAMES) {
3834 strcpy(ha->model_number,
3835 qla2x00_model_name[index * 2]);
3836 strncpy(ha->model_desc,
3837 qla2x00_model_name[index * 2 + 1],
3838 sizeof(ha->model_desc) - 1);
3840 strcpy(ha->model_number, def);
3843 if (IS_FWI2_CAPABLE(ha))
3844 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
3845 sizeof(ha->model_desc));
3848 /* On sparc systems, obtain port and node WWN from firmware
3851 static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
3854 struct qla_hw_data *ha = vha->hw;
3855 struct pci_dev *pdev = ha->pdev;
3856 struct device_node *dp = pci_device_to_OF_node(pdev);
3860 val = of_get_property(dp, "port-wwn", &len);
3861 if (val && len >= WWN_SIZE)
3862 memcpy(nv->port_name, val, WWN_SIZE);
3864 val = of_get_property(dp, "node-wwn", &len);
3865 if (val && len >= WWN_SIZE)
3866 memcpy(nv->node_name, val, WWN_SIZE);
3871 * NVRAM configuration for ISP 2xxx
3874 * ha = adapter block pointer.
3877 * initialization control block in response_ring
3878 * host adapters parameters in host adapter block
3884 qla2x00_nvram_config(scsi_qla_host_t *vha)
3889 uint8_t *dptr1, *dptr2;
3890 struct qla_hw_data *ha = vha->hw;
3891 init_cb_t *icb = ha->init_cb;
3892 nvram_t *nv = ha->nvram;
3893 uint8_t *ptr = ha->nvram;
3894 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3898 /* Determine NVRAM starting address. */
3899 ha->nvram_size = sizeof(nvram_t);
3901 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
3902 if ((RD_REG_WORD(®->ctrl_status) >> 14) == 1)
3903 ha->nvram_base = 0x80;
3905 /* Get NVRAM data and calculate checksum. */
3906 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
3907 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
3910 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x010f,
3911 "Contents of NVRAM.\n");
3912 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0110,
3913 (uint8_t *)nv, ha->nvram_size);
3915 /* Bad NVRAM data, set defaults parameters. */
3916 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
3917 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
3918 /* Reset NVRAM data. */
3919 ql_log(ql_log_warn, vha, 0x0064,
3920 "Inconsistent NVRAM "
3921 "detected: checksum=0x%x id=%c version=0x%x.\n",
3922 chksum, nv->id[0], nv->nvram_version);
3923 ql_log(ql_log_warn, vha, 0x0065,
3925 "functioning (yet invalid -- WWPN) defaults.\n");
3928 * Set default initialization control block.
3930 memset(nv, 0, ha->nvram_size);
3931 nv->parameter_block_version = ICB_VERSION;
3933 if (IS_QLA23XX(ha)) {
3934 nv->firmware_options[0] = BIT_2 | BIT_1;
3935 nv->firmware_options[1] = BIT_7 | BIT_5;
3936 nv->add_firmware_options[0] = BIT_5;
3937 nv->add_firmware_options[1] = BIT_5 | BIT_4;
3938 nv->frame_payload_size = 2048;
3939 nv->special_options[1] = BIT_7;
3940 } else if (IS_QLA2200(ha)) {
3941 nv->firmware_options[0] = BIT_2 | BIT_1;
3942 nv->firmware_options[1] = BIT_7 | BIT_5;
3943 nv->add_firmware_options[0] = BIT_5;
3944 nv->add_firmware_options[1] = BIT_5 | BIT_4;
3945 nv->frame_payload_size = 1024;
3946 } else if (IS_QLA2100(ha)) {
3947 nv->firmware_options[0] = BIT_3 | BIT_1;
3948 nv->firmware_options[1] = BIT_5;
3949 nv->frame_payload_size = 1024;
3952 nv->max_iocb_allocation = cpu_to_le16(256);
3953 nv->execution_throttle = cpu_to_le16(16);
3954 nv->retry_count = 8;
3955 nv->retry_delay = 1;
3957 nv->port_name[0] = 33;
3958 nv->port_name[3] = 224;
3959 nv->port_name[4] = 139;
3961 qla2xxx_nvram_wwn_from_ofw(vha, nv);
3963 nv->login_timeout = 4;
3966 * Set default host adapter parameters
3968 nv->host_p[1] = BIT_2;
3969 nv->reset_delay = 5;
3970 nv->port_down_retry_count = 8;
3971 nv->max_luns_per_target = cpu_to_le16(8);
3972 nv->link_down_timeout = 60;
3977 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
3979 * The SN2 does not provide BIOS emulation which means you can't change
3980 * potentially bogus BIOS settings. Force the use of default settings
3981 * for link rate and frame size. Hope that the rest of the settings
3984 if (ia64_platform_is("sn2")) {
3985 nv->frame_payload_size = 2048;
3987 nv->special_options[1] = BIT_7;
3991 /* Reset Initialization control block */
3992 memset(icb, 0, ha->init_cb_size);
3995 * Setup driver NVRAM options.
3997 nv->firmware_options[0] |= (BIT_6 | BIT_1);
3998 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
3999 nv->firmware_options[1] |= (BIT_5 | BIT_0);
4000 nv->firmware_options[1] &= ~BIT_4;
4002 if (IS_QLA23XX(ha)) {
4003 nv->firmware_options[0] |= BIT_2;
4004 nv->firmware_options[0] &= ~BIT_3;
4005 nv->special_options[0] &= ~BIT_6;
4006 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
4008 if (IS_QLA2300(ha)) {
4009 if (ha->fb_rev == FPM_2310) {
4010 strcpy(ha->model_number, "QLA2310");
4012 strcpy(ha->model_number, "QLA2300");
4015 qla2x00_set_model_info(vha, nv->model_number,
4016 sizeof(nv->model_number), "QLA23xx");
4018 } else if (IS_QLA2200(ha)) {
4019 nv->firmware_options[0] |= BIT_2;
4021 * 'Point-to-point preferred, else loop' is not a safe
4022 * connection mode setting.
4024 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
4026 /* Force 'loop preferred, else point-to-point'. */
4027 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
4028 nv->add_firmware_options[0] |= BIT_5;
4030 strcpy(ha->model_number, "QLA22xx");
4031 } else /*if (IS_QLA2100(ha))*/ {
4032 strcpy(ha->model_number, "QLA2100");
4036 * Copy over NVRAM RISC parameter block to initialization control block.
4038 dptr1 = (uint8_t *)icb;
4039 dptr2 = (uint8_t *)&nv->parameter_block_version;
4040 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
4042 *dptr1++ = *dptr2++;
4044 /* Copy 2nd half. */
4045 dptr1 = (uint8_t *)icb->add_firmware_options;
4046 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
4048 *dptr1++ = *dptr2++;
4050 /* Use alternate WWN? */
4051 if (nv->host_p[1] & BIT_7) {
4052 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
4053 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
4056 /* Prepare nodename */
4057 if ((icb->firmware_options[1] & BIT_6) == 0) {
4059 * Firmware will apply the following mask if the nodename was
4062 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
4063 icb->node_name[0] &= 0xF0;
4067 * Set host adapter parameters.
4071 * BIT_7 in the host-parameters section allows for modification to
4072 * internal driver logging.
4074 if (nv->host_p[0] & BIT_7)
4075 ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK;
4076 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
4077 /* Always load RISC code on non ISP2[12]00 chips. */
4078 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
4079 ha->flags.disable_risc_code_load = 0;
4080 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
4081 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
4082 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
4083 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
4084 ha->flags.disable_serdes = 0;
4086 ha->operating_mode =
4087 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
4089 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
4090 sizeof(ha->fw_seriallink_options));
4092 /* save HBA serial number */
4093 ha->serial0 = icb->port_name[5];
4094 ha->serial1 = icb->port_name[6];
4095 ha->serial2 = icb->port_name[7];
4096 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
4097 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
4099 icb->execution_throttle = cpu_to_le16(0xFFFF);
4101 ha->retry_count = nv->retry_count;
4103 /* Set minimum login_timeout to 4 seconds. */
4104 if (nv->login_timeout != ql2xlogintimeout)
4105 nv->login_timeout = ql2xlogintimeout;
4106 if (nv->login_timeout < 4)
4107 nv->login_timeout = 4;
4108 ha->login_timeout = nv->login_timeout;
4110 /* Set minimum RATOV to 100 tenths of a second. */
4113 ha->loop_reset_delay = nv->reset_delay;
4115 /* Link Down Timeout = 0:
4117 * When Port Down timer expires we will start returning
4118 * I/O's to OS with "DID_NO_CONNECT".
4120 * Link Down Timeout != 0:
4122 * The driver waits for the link to come up after link down
4123 * before returning I/Os to OS with "DID_NO_CONNECT".
4125 if (nv->link_down_timeout == 0) {
4126 ha->loop_down_abort_time =
4127 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
4129 ha->link_down_timeout = nv->link_down_timeout;
4130 ha->loop_down_abort_time =
4131 (LOOP_DOWN_TIME - ha->link_down_timeout);
4135 * Need enough time to try and get the port back.
4137 ha->port_down_retry_count = nv->port_down_retry_count;
4138 if (qlport_down_retry)
4139 ha->port_down_retry_count = qlport_down_retry;
4140 /* Set login_retry_count */
4141 ha->login_retry_count = nv->retry_count;
4142 if (ha->port_down_retry_count == nv->port_down_retry_count &&
4143 ha->port_down_retry_count > 3)
4144 ha->login_retry_count = ha->port_down_retry_count;
4145 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
4146 ha->login_retry_count = ha->port_down_retry_count;
4147 if (ql2xloginretrycount)
4148 ha->login_retry_count = ql2xloginretrycount;
4150 icb->lun_enables = cpu_to_le16(0);
4151 icb->command_resource_count = 0;
4152 icb->immediate_notify_resource_count = 0;
4153 icb->timeout = cpu_to_le16(0);
4155 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
4157 icb->firmware_options[0] &= ~BIT_3;
4158 icb->add_firmware_options[0] &=
4159 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
4160 icb->add_firmware_options[0] |= BIT_2;
4161 icb->response_accumulation_timer = 3;
4162 icb->interrupt_delay_timer = 5;
4164 vha->flags.process_response_queue = 1;
4167 if (!vha->flags.init_done) {
4168 ha->zio_mode = icb->add_firmware_options[0] &
4169 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4170 ha->zio_timer = icb->interrupt_delay_timer ?
4171 icb->interrupt_delay_timer: 2;
4173 icb->add_firmware_options[0] &=
4174 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
4175 vha->flags.process_response_queue = 0;
4176 if (ha->zio_mode != QLA_ZIO_DISABLED) {
4177 ha->zio_mode = QLA_ZIO_MODE_6;
4179 ql_log(ql_log_info, vha, 0x0068,
4180 "ZIO mode %d enabled; timer delay (%d us).\n",
4181 ha->zio_mode, ha->zio_timer * 100);
4183 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
4184 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
4185 vha->flags.process_response_queue = 1;
4190 ql_log(ql_log_warn, vha, 0x0069,
4191 "NVRAM configuration failed.\n");
4197 qla2x00_rport_del(void *data)
4199 fc_port_t *fcport = data;
4200 struct fc_rport *rport;
4201 unsigned long flags;
4203 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
4204 rport = fcport->drport ? fcport->drport: fcport->rport;
4205 fcport->drport = NULL;
4206 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
4208 ql_dbg(ql_dbg_disc, fcport->vha, 0x210b,
4209 "%s %8phN. rport %p roles %x\n",
4210 __func__, fcport->port_name, rport,
4213 fc_remote_port_delete(rport);
4218 * qla2x00_alloc_fcport() - Allocate a generic fcport.
4220 * @flags: allocation flags
4222 * Returns a pointer to the allocated fcport, or NULL, if none available.
4225 qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
4229 fcport = kzalloc(sizeof(fc_port_t), flags);
4233 /* Setup fcport template structure. */
4235 fcport->port_type = FCT_UNKNOWN;
4236 fcport->loop_id = FC_NO_LOOP_ID;
4237 qla2x00_set_fcport_state(fcport, FCS_UNCONFIGURED);
4238 fcport->supported_classes = FC_COS_UNSPECIFIED;
4239 fcport->fp_speed = PORT_SPEED_UNKNOWN;
4241 fcport->ct_desc.ct_sns = dma_alloc_coherent(&vha->hw->pdev->dev,
4242 sizeof(struct ct_sns_pkt), &fcport->ct_desc.ct_sns_dma,
4244 fcport->disc_state = DSC_DELETED;
4245 fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
4246 fcport->deleted = QLA_SESS_DELETED;
4247 fcport->login_retry = vha->hw->login_retry_count;
4248 fcport->login_retry = 5;
4249 fcport->logout_on_delete = 1;
4251 if (!fcport->ct_desc.ct_sns) {
4252 ql_log(ql_log_warn, vha, 0xd049,
4253 "Failed to allocate ct_sns request.\n");
4257 INIT_WORK(&fcport->del_work, qla24xx_delete_sess_fn);
4258 INIT_LIST_HEAD(&fcport->gnl_entry);
4259 INIT_LIST_HEAD(&fcport->list);
4265 qla2x00_free_fcport(fc_port_t *fcport)
4267 if (fcport->ct_desc.ct_sns) {
4268 dma_free_coherent(&fcport->vha->hw->pdev->dev,
4269 sizeof(struct ct_sns_pkt), fcport->ct_desc.ct_sns,
4270 fcport->ct_desc.ct_sns_dma);
4272 fcport->ct_desc.ct_sns = NULL;
4278 * qla2x00_configure_loop
4279 * Updates Fibre Channel Device Database with what is actually on loop.
4282 * ha = adapter block pointer.
4287 * 2 = database was full and device was not configured.
4290 qla2x00_configure_loop(scsi_qla_host_t *vha)
4293 unsigned long flags, save_flags;
4294 struct qla_hw_data *ha = vha->hw;
4297 /* Get Initiator ID */
4298 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
4299 rval = qla2x00_configure_hba(vha);
4300 if (rval != QLA_SUCCESS) {
4301 ql_dbg(ql_dbg_disc, vha, 0x2013,
4302 "Unable to configure HBA.\n");
4307 save_flags = flags = vha->dpc_flags;
4308 ql_dbg(ql_dbg_disc, vha, 0x2014,
4309 "Configure loop -- dpc flags = 0x%lx.\n", flags);
4312 * If we have both an RSCN and PORT UPDATE pending then handle them
4313 * both at the same time.
4315 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
4316 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
4318 qla2x00_get_data_rate(vha);
4320 /* Determine what we need to do */
4321 if (ha->current_topology == ISP_CFG_FL &&
4322 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
4324 set_bit(RSCN_UPDATE, &flags);
4326 } else if (ha->current_topology == ISP_CFG_F &&
4327 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
4329 set_bit(RSCN_UPDATE, &flags);
4330 clear_bit(LOCAL_LOOP_UPDATE, &flags);
4332 } else if (ha->current_topology == ISP_CFG_N) {
4333 clear_bit(RSCN_UPDATE, &flags);
4334 } else if (ha->current_topology == ISP_CFG_NL) {
4335 clear_bit(RSCN_UPDATE, &flags);
4336 set_bit(LOCAL_LOOP_UPDATE, &flags);
4337 } else if (!vha->flags.online ||
4338 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
4339 set_bit(RSCN_UPDATE, &flags);
4340 set_bit(LOCAL_LOOP_UPDATE, &flags);
4343 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
4344 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
4345 ql_dbg(ql_dbg_disc, vha, 0x2015,
4346 "Loop resync needed, failing.\n");
4347 rval = QLA_FUNCTION_FAILED;
4349 rval = qla2x00_configure_local_loop(vha);
4352 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
4353 if (LOOP_TRANSITION(vha)) {
4354 ql_dbg(ql_dbg_disc, vha, 0x2099,
4355 "Needs RSCN update and loop transition.\n");
4356 rval = QLA_FUNCTION_FAILED;
4359 rval = qla2x00_configure_fabric(vha);
4362 if (rval == QLA_SUCCESS) {
4363 if (atomic_read(&vha->loop_down_timer) ||
4364 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
4365 rval = QLA_FUNCTION_FAILED;
4367 atomic_set(&vha->loop_state, LOOP_READY);
4368 ql_dbg(ql_dbg_disc, vha, 0x2069,
4370 ha->flags.fw_init_done = 1;
4373 * Process any ATIO queue entries that came in
4374 * while we weren't online.
4376 if (qla_tgt_mode_enabled(vha) ||
4377 qla_dual_mode_enabled(vha)) {
4378 if (IS_QLA27XX(ha) || IS_QLA83XX(ha)) {
4379 spin_lock_irqsave(&ha->tgt.atio_lock,
4381 qlt_24xx_process_atio_queue(vha, 0);
4382 spin_unlock_irqrestore(
4383 &ha->tgt.atio_lock, flags);
4385 spin_lock_irqsave(&ha->hardware_lock,
4387 qlt_24xx_process_atio_queue(vha, 1);
4388 spin_unlock_irqrestore(
4389 &ha->hardware_lock, flags);
4396 ql_dbg(ql_dbg_disc, vha, 0x206a,
4397 "%s *** FAILED ***.\n", __func__);
4399 ql_dbg(ql_dbg_disc, vha, 0x206b,
4400 "%s: exiting normally.\n", __func__);
4403 /* Restore state if a resync event occurred during processing */
4404 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
4405 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
4406 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
4407 if (test_bit(RSCN_UPDATE, &save_flags)) {
4408 set_bit(RSCN_UPDATE, &vha->dpc_flags);
4418 * qla2x00_configure_local_loop
4419 * Updates Fibre Channel Device Database with local loop devices.
4422 * ha = adapter block pointer.
4428 qla2x00_configure_local_loop(scsi_qla_host_t *vha)
4433 fc_port_t *fcport, *new_fcport;
4439 uint8_t domain, area, al_pa;
4440 struct qla_hw_data *ha = vha->hw;
4441 unsigned long flags;
4445 entries = MAX_FIBRE_DEVICES_LOOP;
4447 /* Get list of logged in devices. */
4448 memset(ha->gid_list, 0, qla2x00_gid_list_size(ha));
4449 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
4451 if (rval != QLA_SUCCESS)
4452 goto cleanup_allocation;
4454 ql_dbg(ql_dbg_disc, vha, 0x2011,
4455 "Entries in ID list (%d).\n", entries);
4456 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2075,
4457 (uint8_t *)ha->gid_list,
4458 entries * sizeof(struct gid_list_info));
4460 /* Allocate temporary fcport for any new fcports discovered. */
4461 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
4462 if (new_fcport == NULL) {
4463 ql_log(ql_log_warn, vha, 0x2012,
4464 "Memory allocation failed for fcport.\n");
4465 rval = QLA_MEMORY_ALLOC_FAILED;
4466 goto cleanup_allocation;
4468 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
4471 * Mark local devices that were present with FCF_DEVICE_LOST for now.
4473 list_for_each_entry(fcport, &vha->vp_fcports, list) {
4474 if (atomic_read(&fcport->state) == FCS_ONLINE &&
4475 fcport->port_type != FCT_BROADCAST &&
4476 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
4478 ql_dbg(ql_dbg_disc, vha, 0x2096,
4479 "Marking port lost loop_id=0x%04x.\n",
4482 qla2x00_mark_device_lost(vha, fcport, 0, 0);
4486 /* Add devices to port list. */
4487 id_iter = (char *)ha->gid_list;
4488 for (index = 0; index < entries; index++) {
4489 domain = ((struct gid_list_info *)id_iter)->domain;
4490 area = ((struct gid_list_info *)id_iter)->area;
4491 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
4492 if (IS_QLA2100(ha) || IS_QLA2200(ha))
4493 loop_id = (uint16_t)
4494 ((struct gid_list_info *)id_iter)->loop_id_2100;
4496 loop_id = le16_to_cpu(
4497 ((struct gid_list_info *)id_iter)->loop_id);
4498 id_iter += ha->gid_list_info_size;
4500 /* Bypass reserved domain fields. */
4501 if ((domain & 0xf0) == 0xf0)
4504 /* Bypass if not same domain and area of adapter. */
4505 if (area && domain &&
4506 (area != vha->d_id.b.area || domain != vha->d_id.b.domain))
4509 /* Bypass invalid local loop ID. */
4510 if (loop_id > LAST_LOCAL_LOOP_ID)
4513 memset(new_fcport->port_name, 0, WWN_SIZE);
4515 /* Fill in member data. */
4516 new_fcport->d_id.b.domain = domain;
4517 new_fcport->d_id.b.area = area;
4518 new_fcport->d_id.b.al_pa = al_pa;
4519 new_fcport->loop_id = loop_id;
4521 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
4522 if (rval2 != QLA_SUCCESS) {
4523 ql_dbg(ql_dbg_disc, vha, 0x2097,
4524 "Failed to retrieve fcport information "
4525 "-- get_port_database=%x, loop_id=0x%04x.\n",
4526 rval2, new_fcport->loop_id);
4527 ql_dbg(ql_dbg_disc, vha, 0x2105,
4528 "Scheduling resync.\n");
4529 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4533 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
4534 /* Check for matching device in port list. */
4537 list_for_each_entry(fcport, &vha->vp_fcports, list) {
4538 if (memcmp(new_fcport->port_name, fcport->port_name,
4542 fcport->flags &= ~FCF_FABRIC_DEVICE;
4543 fcport->loop_id = new_fcport->loop_id;
4544 fcport->port_type = new_fcport->port_type;
4545 fcport->d_id.b24 = new_fcport->d_id.b24;
4546 memcpy(fcport->node_name, new_fcport->node_name,
4549 if (!fcport->login_succ) {
4550 vha->fcport_count++;
4551 fcport->login_succ = 1;
4552 fcport->disc_state = DSC_LOGIN_COMPLETE;
4560 /* New device, add to fcports list. */
4561 list_add_tail(&new_fcport->list, &vha->vp_fcports);
4563 /* Allocate a new replacement fcport. */
4564 fcport = new_fcport;
4565 if (!fcport->login_succ) {
4566 vha->fcport_count++;
4567 fcport->login_succ = 1;
4568 fcport->disc_state = DSC_LOGIN_COMPLETE;
4571 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
4573 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
4575 if (new_fcport == NULL) {
4576 ql_log(ql_log_warn, vha, 0xd031,
4577 "Failed to allocate memory for fcport.\n");
4578 rval = QLA_MEMORY_ALLOC_FAILED;
4579 goto cleanup_allocation;
4581 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
4582 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
4585 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
4587 /* Base iIDMA settings on HBA port speed. */
4588 fcport->fp_speed = ha->link_data_rate;
4590 qla2x00_update_fcport(vha, fcport);
4598 if (rval != QLA_SUCCESS) {
4599 ql_dbg(ql_dbg_disc, vha, 0x2098,
4600 "Configure local loop error exit: rval=%x.\n", rval);
4607 qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
4610 uint16_t mb[MAILBOX_REGISTER_COUNT];
4611 struct qla_hw_data *ha = vha->hw;
4613 if (!IS_IIDMA_CAPABLE(ha))
4616 if (atomic_read(&fcport->state) != FCS_ONLINE)
4619 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
4620 fcport->fp_speed > ha->link_data_rate ||
4621 !ha->flags.gpsc_supported)
4624 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
4626 if (rval != QLA_SUCCESS) {
4627 ql_dbg(ql_dbg_disc, vha, 0x2004,
4628 "Unable to adjust iIDMA %8phN -- %04x %x %04x %04x.\n",
4629 fcport->port_name, rval, fcport->fp_speed, mb[0], mb[1]);
4631 ql_dbg(ql_dbg_disc, vha, 0x2005,
4632 "iIDMA adjusted to %s GB/s on %8phN.\n",
4633 qla2x00_get_link_speed_str(ha, fcport->fp_speed),
4638 /* qla2x00_reg_remote_port is reserved for Initiator Mode only.*/
4640 qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
4642 struct fc_rport_identifiers rport_ids;
4643 struct fc_rport *rport;
4644 unsigned long flags;
4646 rport_ids.node_name = wwn_to_u64(fcport->node_name);
4647 rport_ids.port_name = wwn_to_u64(fcport->port_name);
4648 rport_ids.port_id = fcport->d_id.b.domain << 16 |
4649 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
4650 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
4651 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
4653 ql_log(ql_log_warn, vha, 0x2006,
4654 "Unable to allocate fc remote port.\n");
4658 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
4659 *((fc_port_t **)rport->dd_data) = fcport;
4660 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
4662 rport->supported_classes = fcport->supported_classes;
4664 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
4665 if (fcport->port_type == FCT_INITIATOR)
4666 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
4667 if (fcport->port_type == FCT_TARGET)
4668 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
4670 ql_dbg(ql_dbg_disc, vha, 0x20ee,
4671 "%s %8phN. rport %p is %s mode\n",
4672 __func__, fcport->port_name, rport,
4673 (fcport->port_type == FCT_TARGET) ? "tgt" : "ini");
4675 fc_remote_port_rolechg(rport, rport_ids.roles);
4679 * qla2x00_update_fcport
4680 * Updates device on list.
4683 * ha = adapter block pointer.
4684 * fcport = port structure pointer.
4694 qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
4698 if (IS_SW_RESV_ADDR(fcport->d_id))
4701 ql_dbg(ql_dbg_disc, vha, 0x20ef, "%s %8phC\n",
4702 __func__, fcport->port_name);
4704 if (IS_QLAFX00(vha->hw)) {
4705 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
4708 fcport->login_retry = 0;
4709 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
4710 fcport->disc_state = DSC_LOGIN_COMPLETE;
4711 fcport->deleted = 0;
4712 fcport->logout_on_delete = 1;
4714 if (fcport->fc4f_nvme) {
4715 qla_nvme_register_remote(vha, fcport);
4719 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
4720 qla2x00_iidma_fcport(vha, fcport);
4721 qla24xx_update_fcport_fcp_prio(vha, fcport);
4724 switch (vha->host->active_mode) {
4725 case MODE_INITIATOR:
4726 qla2x00_reg_remote_port(vha, fcport);
4729 if (!vha->vha_tgt.qla_tgt->tgt_stop &&
4730 !vha->vha_tgt.qla_tgt->tgt_stopped)
4731 qlt_fc_port_added(vha, fcport);
4734 qla2x00_reg_remote_port(vha, fcport);
4735 if (!vha->vha_tgt.qla_tgt->tgt_stop &&
4736 !vha->vha_tgt.qla_tgt->tgt_stopped)
4737 qlt_fc_port_added(vha, fcport);
4745 * qla2x00_configure_fabric
4746 * Setup SNS devices with loop ID's.
4749 * ha = adapter block pointer.
4756 qla2x00_configure_fabric(scsi_qla_host_t *vha)
4760 uint16_t mb[MAILBOX_REGISTER_COUNT];
4762 LIST_HEAD(new_fcports);
4763 struct qla_hw_data *ha = vha->hw;
4766 /* If FL port exists, then SNS is present */
4767 if (IS_FWI2_CAPABLE(ha))
4768 loop_id = NPH_F_PORT;
4770 loop_id = SNS_FL_PORT;
4771 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
4772 if (rval != QLA_SUCCESS) {
4773 ql_dbg(ql_dbg_disc, vha, 0x20a0,
4774 "MBX_GET_PORT_NAME failed, No FL Port.\n");
4776 vha->device_flags &= ~SWITCH_FOUND;
4777 return (QLA_SUCCESS);
4779 vha->device_flags |= SWITCH_FOUND;
4782 if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) {
4783 rval = qla2x00_send_change_request(vha, 0x3, 0);
4784 if (rval != QLA_SUCCESS)
4785 ql_log(ql_log_warn, vha, 0x121,
4786 "Failed to enable receiving of RSCN requests: 0x%x.\n",
4792 qla2x00_mgmt_svr_login(vha);
4795 if (ql2xfdmienable &&
4796 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
4797 qla2x00_fdmi_register(vha);
4799 /* Ensure we are logged into the SNS. */
4800 loop_id = NPH_SNS_LID(ha);
4801 rval = ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
4802 0xfc, mb, BIT_1|BIT_0);
4803 if (rval != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
4804 ql_dbg(ql_dbg_disc, vha, 0x20a1,
4805 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x mb[6]=%x mb[7]=%x (%x).\n",
4806 loop_id, mb[0], mb[1], mb[2], mb[6], mb[7], rval);
4807 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4810 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
4811 if (qla2x00_rft_id(vha)) {
4813 ql_dbg(ql_dbg_disc, vha, 0x20a2,
4814 "Register FC-4 TYPE failed.\n");
4815 if (test_bit(LOOP_RESYNC_NEEDED,
4819 if (qla2x00_rff_id(vha, FC4_TYPE_FCP_SCSI)) {
4821 ql_dbg(ql_dbg_disc, vha, 0x209a,
4822 "Register FC-4 Features failed.\n");
4823 if (test_bit(LOOP_RESYNC_NEEDED,
4827 if (vha->flags.nvme_enabled) {
4828 if (qla2x00_rff_id(vha, FC_TYPE_NVME)) {
4829 ql_dbg(ql_dbg_disc, vha, 0x2049,
4830 "Register NVME FC Type Features failed.\n");
4833 if (qla2x00_rnn_id(vha)) {
4835 ql_dbg(ql_dbg_disc, vha, 0x2104,
4836 "Register Node Name failed.\n");
4837 if (test_bit(LOOP_RESYNC_NEEDED,
4840 } else if (qla2x00_rsnn_nn(vha)) {
4842 ql_dbg(ql_dbg_disc, vha, 0x209b,
4843 "Register Symbolic Node Name failed.\n");
4844 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
4849 list_for_each_entry(fcport, &vha->vp_fcports, list) {
4850 fcport->scan_state = QLA_FCPORT_SCAN;
4853 /* Mark the time right before querying FW for connected ports.
4854 * This process is long, asynchronous and by the time it's done,
4855 * collected information might not be accurate anymore. E.g.
4856 * disconnected port might have re-connected and a brand new
4857 * session has been created. In this case session's generation
4858 * will be newer than discovery_gen. */
4859 qlt_do_generation_tick(vha, &discovery_gen);
4861 rval = qla2x00_find_all_fabric_devs(vha);
4862 if (rval != QLA_SUCCESS)
4866 if (!vha->nvme_local_port && vha->flags.nvme_enabled)
4867 qla_nvme_register_hba(vha);
4870 ql_dbg(ql_dbg_disc, vha, 0x2068,
4871 "Configure fabric error exit rval=%d.\n", rval);
4877 * qla2x00_find_all_fabric_devs
4880 * ha = adapter block pointer.
4881 * dev = database device entry pointer.
4890 qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha)
4894 fc_port_t *fcport, *new_fcport;
4899 int first_dev, last_dev;
4900 port_id_t wrap = {}, nxt_d_id;
4901 struct qla_hw_data *ha = vha->hw;
4902 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
4903 unsigned long flags;
4907 /* Try GID_PT to get device list, else GAN. */
4909 ha->swl = kcalloc(ha->max_fibre_devices, sizeof(sw_info_t),
4914 ql_dbg(ql_dbg_disc, vha, 0x209c,
4915 "GID_PT allocations failed, fallback on GA_NXT.\n");
4917 memset(swl, 0, ha->max_fibre_devices * sizeof(sw_info_t));
4918 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
4920 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
4922 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
4924 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
4926 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
4928 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
4930 } else if (qla2x00_gfpn_id(vha, swl) != QLA_SUCCESS) {
4932 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
4936 /* If other queries succeeded probe for FC-4 type */
4938 qla2x00_gff_id(vha, swl);
4939 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
4945 /* Allocate temporary fcport for any new fcports discovered. */
4946 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
4947 if (new_fcport == NULL) {
4948 ql_log(ql_log_warn, vha, 0x209d,
4949 "Failed to allocate memory for fcport.\n");
4950 return (QLA_MEMORY_ALLOC_FAILED);
4952 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
4953 /* Set start port ID scan at adapter ID. */
4957 /* Starting free loop ID. */
4958 loop_id = ha->min_external_loopid;
4959 for (; loop_id <= ha->max_loop_id; loop_id++) {
4960 if (qla2x00_is_reserved_id(vha, loop_id))
4963 if (ha->current_topology == ISP_CFG_FL &&
4964 (atomic_read(&vha->loop_down_timer) ||
4965 LOOP_TRANSITION(vha))) {
4966 atomic_set(&vha->loop_down_timer, 0);
4967 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4968 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
4974 wrap.b24 = new_fcport->d_id.b24;
4976 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
4977 memcpy(new_fcport->node_name,
4978 swl[swl_idx].node_name, WWN_SIZE);
4979 memcpy(new_fcport->port_name,
4980 swl[swl_idx].port_name, WWN_SIZE);
4981 memcpy(new_fcport->fabric_port_name,
4982 swl[swl_idx].fabric_port_name, WWN_SIZE);
4983 new_fcport->fp_speed = swl[swl_idx].fp_speed;
4984 new_fcport->fc4_type = swl[swl_idx].fc4_type;
4986 new_fcport->nvme_flag = 0;
4987 new_fcport->fc4f_nvme = 0;
4988 if (vha->flags.nvme_enabled &&
4989 swl[swl_idx].fc4f_nvme) {
4990 new_fcport->fc4f_nvme =
4991 swl[swl_idx].fc4f_nvme;
4992 ql_log(ql_log_info, vha, 0x2131,
4993 "FOUND: NVME port %8phC as FC Type 28h\n",
4994 new_fcport->port_name);
4997 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
5003 /* Send GA_NXT to the switch */
5004 rval = qla2x00_ga_nxt(vha, new_fcport);
5005 if (rval != QLA_SUCCESS) {
5006 ql_log(ql_log_warn, vha, 0x209e,
5007 "SNS scan failed -- assuming "
5008 "zero-entry result.\n");
5014 /* If wrap on switch device list, exit. */
5016 wrap.b24 = new_fcport->d_id.b24;
5018 } else if (new_fcport->d_id.b24 == wrap.b24) {
5019 ql_dbg(ql_dbg_disc, vha, 0x209f,
5020 "Device wrap (%02x%02x%02x).\n",
5021 new_fcport->d_id.b.domain,
5022 new_fcport->d_id.b.area,
5023 new_fcport->d_id.b.al_pa);
5027 /* Bypass if same physical adapter. */
5028 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
5031 /* Bypass virtual ports of the same host. */
5032 if (qla2x00_is_a_vp_did(vha, new_fcport->d_id.b24))
5035 /* Bypass if same domain and area of adapter. */
5036 if (((new_fcport->d_id.b24 & 0xffff00) ==
5037 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
5041 /* Bypass reserved domain fields. */
5042 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
5045 /* Bypass ports whose FCP-4 type is not FCP_SCSI */
5046 if (ql2xgffidenable &&
5047 (new_fcport->fc4_type != FC4_TYPE_FCP_SCSI &&
5048 new_fcport->fc4_type != FC4_TYPE_UNKNOWN))
5051 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5053 /* Locate matching device in database. */
5055 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5056 if (memcmp(new_fcport->port_name, fcport->port_name,
5060 fcport->scan_state = QLA_FCPORT_FOUND;
5064 /* Update port state. */
5065 memcpy(fcport->fabric_port_name,
5066 new_fcport->fabric_port_name, WWN_SIZE);
5067 fcport->fp_speed = new_fcport->fp_speed;
5070 * If address the same and state FCS_ONLINE
5071 * (or in target mode), nothing changed.
5073 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
5074 (atomic_read(&fcport->state) == FCS_ONLINE ||
5075 (vha->host->active_mode == MODE_TARGET))) {
5080 * If device was not a fabric device before.
5082 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
5083 fcport->d_id.b24 = new_fcport->d_id.b24;
5084 qla2x00_clear_loop_id(fcport);
5085 fcport->flags |= (FCF_FABRIC_DEVICE |
5091 * Port ID changed or device was marked to be updated;
5092 * Log it out if still logged in and mark it for
5095 if (qla_tgt_mode_enabled(base_vha)) {
5096 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf080,
5097 "port changed FC ID, %8phC"
5098 " old %x:%x:%x (loop_id 0x%04x)-> new %x:%x:%x\n",
5100 fcport->d_id.b.domain,
5101 fcport->d_id.b.area,
5102 fcport->d_id.b.al_pa,
5104 new_fcport->d_id.b.domain,
5105 new_fcport->d_id.b.area,
5106 new_fcport->d_id.b.al_pa);
5107 fcport->d_id.b24 = new_fcport->d_id.b24;
5111 fcport->d_id.b24 = new_fcport->d_id.b24;
5112 fcport->flags |= FCF_LOGIN_NEEDED;
5117 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5120 /* If device was not in our fcports list, then add it. */
5121 new_fcport->scan_state = QLA_FCPORT_FOUND;
5122 list_add_tail(&new_fcport->list, &vha->vp_fcports);
5124 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5127 /* Allocate a new replacement fcport. */
5128 nxt_d_id.b24 = new_fcport->d_id.b24;
5129 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5130 if (new_fcport == NULL) {
5131 ql_log(ql_log_warn, vha, 0xd032,
5132 "Memory allocation failed for fcport.\n");
5133 return (QLA_MEMORY_ALLOC_FAILED);
5135 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
5136 new_fcport->d_id.b24 = nxt_d_id.b24;
5139 qla2x00_free_fcport(new_fcport);
5142 * Logout all previous fabric dev marked lost, except FCP2 devices.
5144 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5145 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5148 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
5151 if (fcport->scan_state == QLA_FCPORT_SCAN) {
5152 if ((qla_dual_mode_enabled(vha) ||
5153 qla_ini_mode_enabled(vha)) &&
5154 atomic_read(&fcport->state) == FCS_ONLINE) {
5155 qla2x00_mark_device_lost(vha, fcport,
5156 ql2xplogiabsentdevice, 0);
5157 if (fcport->loop_id != FC_NO_LOOP_ID &&
5158 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
5159 fcport->port_type != FCT_INITIATOR &&
5160 fcport->port_type != FCT_BROADCAST) {
5161 ql_dbg(ql_dbg_disc, vha, 0x20f0,
5162 "%s %d %8phC post del sess\n",
5166 qlt_schedule_sess_for_deletion_lock
5173 if (fcport->scan_state == QLA_FCPORT_FOUND &&
5174 (fcport->flags & FCF_LOGIN_NEEDED) != 0)
5175 qla24xx_fcport_handle_login(vha, fcport);
5181 * qla2x00_find_new_loop_id
5182 * Scan through our port list and find a new usable loop ID.
5185 * ha: adapter state pointer.
5186 * dev: port structure pointer.
5189 * qla2x00 local function return status code.
5195 qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
5198 struct qla_hw_data *ha = vha->hw;
5199 unsigned long flags = 0;
5203 spin_lock_irqsave(&ha->vport_slock, flags);
5205 dev->loop_id = find_first_zero_bit(ha->loop_id_map,
5207 if (dev->loop_id >= LOOPID_MAP_SIZE ||
5208 qla2x00_is_reserved_id(vha, dev->loop_id)) {
5209 dev->loop_id = FC_NO_LOOP_ID;
5210 rval = QLA_FUNCTION_FAILED;
5212 set_bit(dev->loop_id, ha->loop_id_map);
5214 spin_unlock_irqrestore(&ha->vport_slock, flags);
5216 if (rval == QLA_SUCCESS)
5217 ql_dbg(ql_dbg_disc, dev->vha, 0x2086,
5218 "Assigning new loopid=%x, portid=%x.\n",
5219 dev->loop_id, dev->d_id.b24);
5221 ql_log(ql_log_warn, dev->vha, 0x2087,
5222 "No loop_id's available, portid=%x.\n",
5230 * qla2x00_fabric_login
5231 * Issue fabric login command.
5234 * ha = adapter block pointer.
5235 * device = pointer to FC device type structure.
5238 * 0 - Login successfully
5240 * 2 - Initiator device
5244 qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
5245 uint16_t *next_loopid)
5249 uint16_t tmp_loopid;
5250 uint16_t mb[MAILBOX_REGISTER_COUNT];
5251 struct qla_hw_data *ha = vha->hw;
5257 ql_dbg(ql_dbg_disc, vha, 0x2000,
5258 "Trying Fabric Login w/loop id 0x%04x for port "
5260 fcport->loop_id, fcport->d_id.b.domain,
5261 fcport->d_id.b.area, fcport->d_id.b.al_pa);
5263 /* Login fcport on switch. */
5264 rval = ha->isp_ops->fabric_login(vha, fcport->loop_id,
5265 fcport->d_id.b.domain, fcport->d_id.b.area,
5266 fcport->d_id.b.al_pa, mb, BIT_0);
5267 if (rval != QLA_SUCCESS) {
5270 if (mb[0] == MBS_PORT_ID_USED) {
5272 * Device has another loop ID. The firmware team
5273 * recommends the driver perform an implicit login with
5274 * the specified ID again. The ID we just used is save
5275 * here so we return with an ID that can be tried by
5279 tmp_loopid = fcport->loop_id;
5280 fcport->loop_id = mb[1];
5282 ql_dbg(ql_dbg_disc, vha, 0x2001,
5283 "Fabric Login: port in use - next loop "
5284 "id=0x%04x, port id= %02x%02x%02x.\n",
5285 fcport->loop_id, fcport->d_id.b.domain,
5286 fcport->d_id.b.area, fcport->d_id.b.al_pa);
5288 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
5293 /* A retry occurred before. */
5294 *next_loopid = tmp_loopid;
5297 * No retry occurred before. Just increment the
5298 * ID value for next login.
5300 *next_loopid = (fcport->loop_id + 1);
5303 if (mb[1] & BIT_0) {
5304 fcport->port_type = FCT_INITIATOR;
5306 fcport->port_type = FCT_TARGET;
5307 if (mb[1] & BIT_1) {
5308 fcport->flags |= FCF_FCP2_DEVICE;
5313 fcport->supported_classes |= FC_COS_CLASS2;
5315 fcport->supported_classes |= FC_COS_CLASS3;
5317 if (IS_FWI2_CAPABLE(ha)) {
5320 FCF_CONF_COMP_SUPPORTED;
5325 } else if (mb[0] == MBS_LOOP_ID_USED) {
5327 * Loop ID already used, try next loop ID.
5330 rval = qla2x00_find_new_loop_id(vha, fcport);
5331 if (rval != QLA_SUCCESS) {
5332 /* Ran out of loop IDs to use */
5335 } else if (mb[0] == MBS_COMMAND_ERROR) {
5337 * Firmware possibly timed out during login. If NO
5338 * retries are left to do then the device is declared
5341 *next_loopid = fcport->loop_id;
5342 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
5343 fcport->d_id.b.domain, fcport->d_id.b.area,
5344 fcport->d_id.b.al_pa);
5345 qla2x00_mark_device_lost(vha, fcport, 1, 0);
5351 * unrecoverable / not handled error
5353 ql_dbg(ql_dbg_disc, vha, 0x2002,
5354 "Failed=%x port_id=%02x%02x%02x loop_id=%x "
5355 "jiffies=%lx.\n", mb[0], fcport->d_id.b.domain,
5356 fcport->d_id.b.area, fcport->d_id.b.al_pa,
5357 fcport->loop_id, jiffies);
5359 *next_loopid = fcport->loop_id;
5360 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
5361 fcport->d_id.b.domain, fcport->d_id.b.area,
5362 fcport->d_id.b.al_pa);
5363 qla2x00_clear_loop_id(fcport);
5364 fcport->login_retry = 0;
5375 * qla2x00_local_device_login
5376 * Issue local device login command.
5379 * ha = adapter block pointer.
5380 * loop_id = loop id of device to login to.
5382 * Returns (Where's the #define!!!!):
5383 * 0 - Login successfully
5388 qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
5391 uint16_t mb[MAILBOX_REGISTER_COUNT];
5393 memset(mb, 0, sizeof(mb));
5394 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
5395 if (rval == QLA_SUCCESS) {
5396 /* Interrogate mailbox registers for any errors */
5397 if (mb[0] == MBS_COMMAND_ERROR)
5399 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
5400 /* device not in PCB table */
5408 * qla2x00_loop_resync
5409 * Resync with fibre channel devices.
5412 * ha = adapter block pointer.
5418 qla2x00_loop_resync(scsi_qla_host_t *vha)
5420 int rval = QLA_SUCCESS;
5422 struct req_que *req;
5423 struct rsp_que *rsp;
5428 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
5429 if (vha->flags.online) {
5430 if (!(rval = qla2x00_fw_ready(vha))) {
5431 /* Wait at most MAX_TARGET RSCNs for a stable link. */
5434 if (!IS_QLAFX00(vha->hw)) {
5436 * Issue a marker after FW becomes
5439 qla2x00_marker(vha, req, rsp, 0, 0,
5441 vha->marker_needed = 0;
5444 /* Remap devices on Loop. */
5445 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5447 if (IS_QLAFX00(vha->hw))
5448 qlafx00_configure_devices(vha);
5450 qla2x00_configure_loop(vha);
5453 } while (!atomic_read(&vha->loop_down_timer) &&
5454 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
5455 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
5460 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
5461 return (QLA_FUNCTION_FAILED);
5464 ql_dbg(ql_dbg_disc, vha, 0x206c,
5465 "%s *** FAILED ***.\n", __func__);
5471 * qla2x00_perform_loop_resync
5472 * Description: This function will set the appropriate flags and call
5473 * qla2x00_loop_resync. If successful loop will be resynced
5474 * Arguments : scsi_qla_host_t pointer
5475 * returm : Success or Failure
5478 int qla2x00_perform_loop_resync(scsi_qla_host_t *ha)
5482 if (!test_and_set_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags)) {
5483 /*Configure the flags so that resync happens properly*/
5484 atomic_set(&ha->loop_down_timer, 0);
5485 if (!(ha->device_flags & DFLG_NO_CABLE)) {
5486 atomic_set(&ha->loop_state, LOOP_UP);
5487 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
5488 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
5489 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
5491 rval = qla2x00_loop_resync(ha);
5493 atomic_set(&ha->loop_state, LOOP_DEAD);
5495 clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
5502 qla2x00_update_fcports(scsi_qla_host_t *base_vha)
5505 struct scsi_qla_host *vha;
5506 struct qla_hw_data *ha = base_vha->hw;
5507 unsigned long flags;
5509 spin_lock_irqsave(&ha->vport_slock, flags);
5510 /* Go with deferred removal of rport references. */
5511 list_for_each_entry(vha, &base_vha->hw->vp_list, list) {
5512 atomic_inc(&vha->vref_count);
5513 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5514 if (fcport->drport &&
5515 atomic_read(&fcport->state) != FCS_UNCONFIGURED) {
5516 spin_unlock_irqrestore(&ha->vport_slock, flags);
5517 qla2x00_rport_del(fcport);
5519 spin_lock_irqsave(&ha->vport_slock, flags);
5522 atomic_dec(&vha->vref_count);
5523 wake_up(&vha->vref_waitq);
5525 spin_unlock_irqrestore(&ha->vport_slock, flags);
5528 /* Assumes idc_lock always held on entry */
5530 qla83xx_reset_ownership(scsi_qla_host_t *vha)
5532 struct qla_hw_data *ha = vha->hw;
5533 uint32_t drv_presence, drv_presence_mask;
5534 uint32_t dev_part_info1, dev_part_info2, class_type;
5535 uint32_t class_type_mask = 0x3;
5536 uint16_t fcoe_other_function = 0xffff, i;
5538 if (IS_QLA8044(ha)) {
5539 drv_presence = qla8044_rd_direct(vha,
5540 QLA8044_CRB_DRV_ACTIVE_INDEX);
5541 dev_part_info1 = qla8044_rd_direct(vha,
5542 QLA8044_CRB_DEV_PART_INFO_INDEX);
5543 dev_part_info2 = qla8044_rd_direct(vha,
5544 QLA8044_CRB_DEV_PART_INFO2);
5546 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
5547 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO1, &dev_part_info1);
5548 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO2, &dev_part_info2);
5550 for (i = 0; i < 8; i++) {
5551 class_type = ((dev_part_info1 >> (i * 4)) & class_type_mask);
5552 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
5553 (i != ha->portnum)) {
5554 fcoe_other_function = i;
5558 if (fcoe_other_function == 0xffff) {
5559 for (i = 0; i < 8; i++) {
5560 class_type = ((dev_part_info2 >> (i * 4)) &
5562 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
5563 ((i + 8) != ha->portnum)) {
5564 fcoe_other_function = i + 8;
5570 * Prepare drv-presence mask based on fcoe functions present.
5571 * However consider only valid physical fcoe function numbers (0-15).
5573 drv_presence_mask = ~((1 << (ha->portnum)) |
5574 ((fcoe_other_function == 0xffff) ?
5575 0 : (1 << (fcoe_other_function))));
5577 /* We are the reset owner iff:
5578 * - No other protocol drivers present.
5579 * - This is the lowest among fcoe functions. */
5580 if (!(drv_presence & drv_presence_mask) &&
5581 (ha->portnum < fcoe_other_function)) {
5582 ql_dbg(ql_dbg_p3p, vha, 0xb07f,
5583 "This host is Reset owner.\n");
5584 ha->flags.nic_core_reset_owner = 1;
5589 __qla83xx_set_drv_ack(scsi_qla_host_t *vha)
5591 int rval = QLA_SUCCESS;
5592 struct qla_hw_data *ha = vha->hw;
5595 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
5596 if (rval == QLA_SUCCESS) {
5597 drv_ack |= (1 << ha->portnum);
5598 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
5605 __qla83xx_clear_drv_ack(scsi_qla_host_t *vha)
5607 int rval = QLA_SUCCESS;
5608 struct qla_hw_data *ha = vha->hw;
5611 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
5612 if (rval == QLA_SUCCESS) {
5613 drv_ack &= ~(1 << ha->portnum);
5614 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
5621 qla83xx_dev_state_to_string(uint32_t dev_state)
5623 switch (dev_state) {
5624 case QLA8XXX_DEV_COLD:
5625 return "COLD/RE-INIT";
5626 case QLA8XXX_DEV_INITIALIZING:
5627 return "INITIALIZING";
5628 case QLA8XXX_DEV_READY:
5630 case QLA8XXX_DEV_NEED_RESET:
5631 return "NEED RESET";
5632 case QLA8XXX_DEV_NEED_QUIESCENT:
5633 return "NEED QUIESCENT";
5634 case QLA8XXX_DEV_FAILED:
5636 case QLA8XXX_DEV_QUIESCENT:
5643 /* Assumes idc-lock always held on entry */
5645 qla83xx_idc_audit(scsi_qla_host_t *vha, int audit_type)
5647 struct qla_hw_data *ha = vha->hw;
5648 uint32_t idc_audit_reg = 0, duration_secs = 0;
5650 switch (audit_type) {
5651 case IDC_AUDIT_TIMESTAMP:
5652 ha->idc_audit_ts = (jiffies_to_msecs(jiffies) / 1000);
5653 idc_audit_reg = (ha->portnum) |
5654 (IDC_AUDIT_TIMESTAMP << 7) | (ha->idc_audit_ts << 8);
5655 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
5658 case IDC_AUDIT_COMPLETION:
5659 duration_secs = ((jiffies_to_msecs(jiffies) -
5660 jiffies_to_msecs(ha->idc_audit_ts)) / 1000);
5661 idc_audit_reg = (ha->portnum) |
5662 (IDC_AUDIT_COMPLETION << 7) | (duration_secs << 8);
5663 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
5667 ql_log(ql_log_warn, vha, 0xb078,
5668 "Invalid audit type specified.\n");
5673 /* Assumes idc_lock always held on entry */
5675 qla83xx_initiating_reset(scsi_qla_host_t *vha)
5677 struct qla_hw_data *ha = vha->hw;
5678 uint32_t idc_control, dev_state;
5680 __qla83xx_get_idc_control(vha, &idc_control);
5681 if ((idc_control & QLA83XX_IDC_RESET_DISABLED)) {
5682 ql_log(ql_log_info, vha, 0xb080,
5683 "NIC Core reset has been disabled. idc-control=0x%x\n",
5685 return QLA_FUNCTION_FAILED;
5688 /* Set NEED-RESET iff in READY state and we are the reset-owner */
5689 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5690 if (ha->flags.nic_core_reset_owner && dev_state == QLA8XXX_DEV_READY) {
5691 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
5692 QLA8XXX_DEV_NEED_RESET);
5693 ql_log(ql_log_info, vha, 0xb056, "HW State: NEED RESET.\n");
5694 qla83xx_idc_audit(vha, IDC_AUDIT_TIMESTAMP);
5696 const char *state = qla83xx_dev_state_to_string(dev_state);
5697 ql_log(ql_log_info, vha, 0xb057, "HW State: %s.\n", state);
5699 /* SV: XXX: Is timeout required here? */
5700 /* Wait for IDC state change READY -> NEED_RESET */
5701 while (dev_state == QLA8XXX_DEV_READY) {
5702 qla83xx_idc_unlock(vha, 0);
5704 qla83xx_idc_lock(vha, 0);
5705 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5709 /* Send IDC ack by writing to drv-ack register */
5710 __qla83xx_set_drv_ack(vha);
5716 __qla83xx_set_idc_control(scsi_qla_host_t *vha, uint32_t idc_control)
5718 return qla83xx_wr_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
5722 __qla83xx_get_idc_control(scsi_qla_host_t *vha, uint32_t *idc_control)
5724 return qla83xx_rd_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
5728 qla83xx_check_driver_presence(scsi_qla_host_t *vha)
5730 uint32_t drv_presence = 0;
5731 struct qla_hw_data *ha = vha->hw;
5733 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
5734 if (drv_presence & (1 << ha->portnum))
5737 return QLA_TEST_FAILED;
5741 qla83xx_nic_core_reset(scsi_qla_host_t *vha)
5743 int rval = QLA_SUCCESS;
5744 struct qla_hw_data *ha = vha->hw;
5746 ql_dbg(ql_dbg_p3p, vha, 0xb058,
5747 "Entered %s().\n", __func__);
5749 if (vha->device_flags & DFLG_DEV_FAILED) {
5750 ql_log(ql_log_warn, vha, 0xb059,
5751 "Device in unrecoverable FAILED state.\n");
5752 return QLA_FUNCTION_FAILED;
5755 qla83xx_idc_lock(vha, 0);
5757 if (qla83xx_check_driver_presence(vha) != QLA_SUCCESS) {
5758 ql_log(ql_log_warn, vha, 0xb05a,
5759 "Function=0x%x has been removed from IDC participation.\n",
5761 rval = QLA_FUNCTION_FAILED;
5765 qla83xx_reset_ownership(vha);
5767 rval = qla83xx_initiating_reset(vha);
5770 * Perform reset if we are the reset-owner,
5771 * else wait till IDC state changes to READY/FAILED.
5773 if (rval == QLA_SUCCESS) {
5774 rval = qla83xx_idc_state_handler(vha);
5776 if (rval == QLA_SUCCESS)
5777 ha->flags.nic_core_hung = 0;
5778 __qla83xx_clear_drv_ack(vha);
5782 qla83xx_idc_unlock(vha, 0);
5784 ql_dbg(ql_dbg_p3p, vha, 0xb05b, "Exiting %s.\n", __func__);
5790 qla2xxx_mctp_dump(scsi_qla_host_t *vha)
5792 struct qla_hw_data *ha = vha->hw;
5793 int rval = QLA_FUNCTION_FAILED;
5795 if (!IS_MCTP_CAPABLE(ha)) {
5796 /* This message can be removed from the final version */
5797 ql_log(ql_log_info, vha, 0x506d,
5798 "This board is not MCTP capable\n");
5802 if (!ha->mctp_dump) {
5803 ha->mctp_dump = dma_alloc_coherent(&ha->pdev->dev,
5804 MCTP_DUMP_SIZE, &ha->mctp_dump_dma, GFP_KERNEL);
5806 if (!ha->mctp_dump) {
5807 ql_log(ql_log_warn, vha, 0x506e,
5808 "Failed to allocate memory for mctp dump\n");
5813 #define MCTP_DUMP_STR_ADDR 0x00000000
5814 rval = qla2x00_dump_mctp_data(vha, ha->mctp_dump_dma,
5815 MCTP_DUMP_STR_ADDR, MCTP_DUMP_SIZE/4);
5816 if (rval != QLA_SUCCESS) {
5817 ql_log(ql_log_warn, vha, 0x506f,
5818 "Failed to capture mctp dump\n");
5820 ql_log(ql_log_info, vha, 0x5070,
5821 "Mctp dump capture for host (%ld/%p).\n",
5822 vha->host_no, ha->mctp_dump);
5823 ha->mctp_dumped = 1;
5826 if (!ha->flags.nic_core_reset_hdlr_active && !ha->portnum) {
5827 ha->flags.nic_core_reset_hdlr_active = 1;
5828 rval = qla83xx_restart_nic_firmware(vha);
5830 /* NIC Core reset failed. */
5831 ql_log(ql_log_warn, vha, 0x5071,
5832 "Failed to restart nic firmware\n");
5834 ql_dbg(ql_dbg_p3p, vha, 0xb084,
5835 "Restarted NIC firmware successfully.\n");
5836 ha->flags.nic_core_reset_hdlr_active = 0;
5844 * qla2x00_quiesce_io
5845 * Description: This function will block the new I/Os
5846 * Its not aborting any I/Os as context
5847 * is not destroyed during quiescence
5848 * Arguments: scsi_qla_host_t
5852 qla2x00_quiesce_io(scsi_qla_host_t *vha)
5854 struct qla_hw_data *ha = vha->hw;
5855 struct scsi_qla_host *vp;
5857 ql_dbg(ql_dbg_dpc, vha, 0x401d,
5858 "Quiescing I/O - ha=%p.\n", ha);
5860 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
5861 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
5862 atomic_set(&vha->loop_state, LOOP_DOWN);
5863 qla2x00_mark_all_devices_lost(vha, 0);
5864 list_for_each_entry(vp, &ha->vp_list, list)
5865 qla2x00_mark_all_devices_lost(vp, 0);
5867 if (!atomic_read(&vha->loop_down_timer))
5868 atomic_set(&vha->loop_down_timer,
5871 /* Wait for pending cmds to complete */
5872 qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST);
5876 qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha)
5878 struct qla_hw_data *ha = vha->hw;
5879 struct scsi_qla_host *vp;
5880 unsigned long flags;
5884 /* For ISP82XX, driver waits for completion of the commands.
5885 * online flag should be set.
5887 if (!(IS_P3P_TYPE(ha)))
5888 vha->flags.online = 0;
5889 ha->flags.chip_reset_done = 0;
5890 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
5891 vha->qla_stats.total_isp_aborts++;
5893 ql_log(ql_log_info, vha, 0x00af,
5894 "Performing ISP error recovery - ha=%p.\n", ha);
5896 /* For ISP82XX, reset_chip is just disabling interrupts.
5897 * Driver waits for the completion of the commands.
5898 * the interrupts need to be enabled.
5900 if (!(IS_P3P_TYPE(ha)))
5901 ha->isp_ops->reset_chip(vha);
5903 ha->flags.n2n_ae = 0;
5904 ha->flags.lip_ae = 0;
5905 ha->current_topology = 0;
5906 ha->flags.fw_started = 0;
5907 ha->flags.fw_init_done = 0;
5908 ha->base_qpair->chip_reset++;
5909 for (i = 0; i < ha->max_qpairs; i++) {
5910 if (ha->queue_pair_map[i])
5911 ha->queue_pair_map[i]->chip_reset =
5912 ha->base_qpair->chip_reset;
5915 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
5916 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
5917 atomic_set(&vha->loop_state, LOOP_DOWN);
5918 qla2x00_mark_all_devices_lost(vha, 0);
5920 spin_lock_irqsave(&ha->vport_slock, flags);
5921 list_for_each_entry(vp, &ha->vp_list, list) {
5922 atomic_inc(&vp->vref_count);
5923 spin_unlock_irqrestore(&ha->vport_slock, flags);
5925 qla2x00_mark_all_devices_lost(vp, 0);
5927 spin_lock_irqsave(&ha->vport_slock, flags);
5928 atomic_dec(&vp->vref_count);
5930 spin_unlock_irqrestore(&ha->vport_slock, flags);
5932 if (!atomic_read(&vha->loop_down_timer))
5933 atomic_set(&vha->loop_down_timer,
5937 /* Clear all async request states across all VPs. */
5938 list_for_each_entry(fcport, &vha->vp_fcports, list)
5939 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
5940 spin_lock_irqsave(&ha->vport_slock, flags);
5941 list_for_each_entry(vp, &ha->vp_list, list) {
5942 atomic_inc(&vp->vref_count);
5943 spin_unlock_irqrestore(&ha->vport_slock, flags);
5945 list_for_each_entry(fcport, &vp->vp_fcports, list)
5946 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
5948 spin_lock_irqsave(&ha->vport_slock, flags);
5949 atomic_dec(&vp->vref_count);
5951 spin_unlock_irqrestore(&ha->vport_slock, flags);
5953 if (!ha->flags.eeh_busy) {
5954 /* Make sure for ISP 82XX IO DMA is complete */
5955 if (IS_P3P_TYPE(ha)) {
5956 qla82xx_chip_reset_cleanup(vha);
5957 ql_log(ql_log_info, vha, 0x00b4,
5958 "Done chip reset cleanup.\n");
5960 /* Done waiting for pending commands.
5961 * Reset the online flag.
5963 vha->flags.online = 0;
5966 /* Requeue all commands in outstanding command list. */
5967 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
5969 /* memory barrier */
5975 * Resets ISP and aborts all outstanding commands.
5978 * ha = adapter block pointer.
5984 qla2x00_abort_isp(scsi_qla_host_t *vha)
5988 struct qla_hw_data *ha = vha->hw;
5989 struct scsi_qla_host *vp;
5990 struct req_que *req = ha->req_q_map[0];
5991 unsigned long flags;
5993 if (vha->flags.online) {
5994 qla2x00_abort_isp_cleanup(vha);
5996 if (IS_QLA8031(ha)) {
5997 ql_dbg(ql_dbg_p3p, vha, 0xb05c,
5998 "Clearing fcoe driver presence.\n");
5999 if (qla83xx_clear_drv_presence(vha) != QLA_SUCCESS)
6000 ql_dbg(ql_dbg_p3p, vha, 0xb073,
6001 "Error while clearing DRV-Presence.\n");
6004 if (unlikely(pci_channel_offline(ha->pdev) &&
6005 ha->flags.pci_channel_io_perm_failure)) {
6006 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6011 ha->isp_ops->get_flash_version(vha, req->ring);
6013 ha->isp_ops->nvram_config(vha);
6015 if (!qla2x00_restart_isp(vha)) {
6016 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
6018 if (!atomic_read(&vha->loop_down_timer)) {
6020 * Issue marker command only when we are going
6021 * to start the I/O .
6023 vha->marker_needed = 1;
6026 vha->flags.online = 1;
6028 ha->isp_ops->enable_intrs(ha);
6030 ha->isp_abort_cnt = 0;
6031 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6033 if (IS_QLA81XX(ha) || IS_QLA8031(ha))
6034 qla2x00_get_fw_version(vha);
6036 ha->flags.fce_enabled = 1;
6038 fce_calc_size(ha->fce_bufs));
6039 rval = qla2x00_enable_fce_trace(vha,
6040 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
6043 ql_log(ql_log_warn, vha, 0x8033,
6044 "Unable to reinitialize FCE "
6046 ha->flags.fce_enabled = 0;
6051 memset(ha->eft, 0, EFT_SIZE);
6052 rval = qla2x00_enable_eft_trace(vha,
6053 ha->eft_dma, EFT_NUM_BUFFERS);
6055 ql_log(ql_log_warn, vha, 0x8034,
6056 "Unable to reinitialize EFT "
6060 } else { /* failed the ISP abort */
6061 vha->flags.online = 1;
6062 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
6063 if (ha->isp_abort_cnt == 0) {
6064 ql_log(ql_log_fatal, vha, 0x8035,
6065 "ISP error recover failed - "
6066 "board disabled.\n");
6068 * The next call disables the board
6071 qla2x00_abort_isp_cleanup(vha);
6072 vha->flags.online = 0;
6073 clear_bit(ISP_ABORT_RETRY,
6076 } else { /* schedule another ISP abort */
6077 ha->isp_abort_cnt--;
6078 ql_dbg(ql_dbg_taskm, vha, 0x8020,
6079 "ISP abort - retry remaining %d.\n",
6084 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
6085 ql_dbg(ql_dbg_taskm, vha, 0x8021,
6086 "ISP error recovery - retrying (%d) "
6087 "more times.\n", ha->isp_abort_cnt);
6088 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6096 ql_dbg(ql_dbg_taskm, vha, 0x8022, "%s succeeded.\n", __func__);
6097 qla2x00_configure_hba(vha);
6098 spin_lock_irqsave(&ha->vport_slock, flags);
6099 list_for_each_entry(vp, &ha->vp_list, list) {
6101 atomic_inc(&vp->vref_count);
6102 spin_unlock_irqrestore(&ha->vport_slock, flags);
6104 qla2x00_vp_abort_isp(vp);
6106 spin_lock_irqsave(&ha->vport_slock, flags);
6107 atomic_dec(&vp->vref_count);
6110 spin_unlock_irqrestore(&ha->vport_slock, flags);
6112 if (IS_QLA8031(ha)) {
6113 ql_dbg(ql_dbg_p3p, vha, 0xb05d,
6114 "Setting back fcoe driver presence.\n");
6115 if (qla83xx_set_drv_presence(vha) != QLA_SUCCESS)
6116 ql_dbg(ql_dbg_p3p, vha, 0xb074,
6117 "Error while setting DRV-Presence.\n");
6120 ql_log(ql_log_warn, vha, 0x8023, "%s **** FAILED ****.\n",
6128 * qla2x00_restart_isp
6129 * restarts the ISP after a reset
6132 * ha = adapter block pointer.
6138 qla2x00_restart_isp(scsi_qla_host_t *vha)
6141 struct qla_hw_data *ha = vha->hw;
6142 struct req_que *req = ha->req_q_map[0];
6143 struct rsp_que *rsp = ha->rsp_q_map[0];
6145 /* If firmware needs to be loaded */
6146 if (qla2x00_isp_firmware(vha)) {
6147 vha->flags.online = 0;
6148 status = ha->isp_ops->chip_diag(vha);
6150 status = qla2x00_setup_chip(vha);
6153 if (!status && !(status = qla2x00_init_rings(vha))) {
6154 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
6155 ha->flags.chip_reset_done = 1;
6157 /* Initialize the queues in use */
6158 qla25xx_init_queues(ha);
6160 status = qla2x00_fw_ready(vha);
6162 /* Issue a marker after FW becomes ready. */
6163 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
6164 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
6167 /* if no cable then assume it's good */
6168 if ((vha->device_flags & DFLG_NO_CABLE))
6175 qla25xx_init_queues(struct qla_hw_data *ha)
6177 struct rsp_que *rsp = NULL;
6178 struct req_que *req = NULL;
6179 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
6183 for (i = 1; i < ha->max_rsp_queues; i++) {
6184 rsp = ha->rsp_q_map[i];
6185 if (rsp && test_bit(i, ha->rsp_qid_map)) {
6186 rsp->options &= ~BIT_0;
6187 ret = qla25xx_init_rsp_que(base_vha, rsp);
6188 if (ret != QLA_SUCCESS)
6189 ql_dbg(ql_dbg_init, base_vha, 0x00ff,
6190 "%s Rsp que: %d init failed.\n",
6193 ql_dbg(ql_dbg_init, base_vha, 0x0100,
6194 "%s Rsp que: %d inited.\n",
6198 for (i = 1; i < ha->max_req_queues; i++) {
6199 req = ha->req_q_map[i];
6200 if (req && test_bit(i, ha->req_qid_map)) {
6201 /* Clear outstanding commands array. */
6202 req->options &= ~BIT_0;
6203 ret = qla25xx_init_req_que(base_vha, req);
6204 if (ret != QLA_SUCCESS)
6205 ql_dbg(ql_dbg_init, base_vha, 0x0101,
6206 "%s Req que: %d init failed.\n",
6209 ql_dbg(ql_dbg_init, base_vha, 0x0102,
6210 "%s Req que: %d inited.\n",
6218 * qla2x00_reset_adapter
6222 * ha = adapter block pointer.
6225 qla2x00_reset_adapter(scsi_qla_host_t *vha)
6227 unsigned long flags = 0;
6228 struct qla_hw_data *ha = vha->hw;
6229 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
6231 vha->flags.online = 0;
6232 ha->isp_ops->disable_intrs(ha);
6234 spin_lock_irqsave(&ha->hardware_lock, flags);
6235 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
6236 RD_REG_WORD(®->hccr); /* PCI Posting. */
6237 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
6238 RD_REG_WORD(®->hccr); /* PCI Posting. */
6239 spin_unlock_irqrestore(&ha->hardware_lock, flags);
6243 qla24xx_reset_adapter(scsi_qla_host_t *vha)
6245 unsigned long flags = 0;
6246 struct qla_hw_data *ha = vha->hw;
6247 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
6249 if (IS_P3P_TYPE(ha))
6252 vha->flags.online = 0;
6253 ha->isp_ops->disable_intrs(ha);
6255 spin_lock_irqsave(&ha->hardware_lock, flags);
6256 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
6257 RD_REG_DWORD(®->hccr);
6258 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
6259 RD_REG_DWORD(®->hccr);
6260 spin_unlock_irqrestore(&ha->hardware_lock, flags);
6262 if (IS_NOPOLLING_TYPE(ha))
6263 ha->isp_ops->enable_intrs(ha);
6266 /* On sparc systems, obtain port and node WWN from firmware
6269 static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
6270 struct nvram_24xx *nv)
6273 struct qla_hw_data *ha = vha->hw;
6274 struct pci_dev *pdev = ha->pdev;
6275 struct device_node *dp = pci_device_to_OF_node(pdev);
6279 val = of_get_property(dp, "port-wwn", &len);
6280 if (val && len >= WWN_SIZE)
6281 memcpy(nv->port_name, val, WWN_SIZE);
6283 val = of_get_property(dp, "node-wwn", &len);
6284 if (val && len >= WWN_SIZE)
6285 memcpy(nv->node_name, val, WWN_SIZE);
6290 qla24xx_nvram_config(scsi_qla_host_t *vha)
6293 struct init_cb_24xx *icb;
6294 struct nvram_24xx *nv;
6296 uint8_t *dptr1, *dptr2;
6299 struct qla_hw_data *ha = vha->hw;
6302 icb = (struct init_cb_24xx *)ha->init_cb;
6305 /* Determine NVRAM starting address. */
6306 if (ha->port_no == 0) {
6307 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
6308 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
6310 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
6311 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
6314 ha->nvram_size = sizeof(struct nvram_24xx);
6315 ha->vpd_size = FA_NVRAM_VPD_SIZE;
6317 /* Get VPD data into cache */
6318 ha->vpd = ha->nvram + VPD_OFFSET;
6319 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
6320 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
6322 /* Get NVRAM data into cache and calculate checksum. */
6323 dptr = (uint32_t *)nv;
6324 ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
6326 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++)
6327 chksum += le32_to_cpu(*dptr);
6329 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x006a,
6330 "Contents of NVRAM\n");
6331 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x010d,
6332 (uint8_t *)nv, ha->nvram_size);
6334 /* Bad NVRAM data, set defaults parameters. */
6335 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
6336 || nv->id[3] != ' ' ||
6337 nv->nvram_version < cpu_to_le16(ICB_VERSION)) {
6338 /* Reset NVRAM data. */
6339 ql_log(ql_log_warn, vha, 0x006b,
6340 "Inconsistent NVRAM detected: checksum=0x%x id=%c "
6341 "version=0x%x.\n", chksum, nv->id[0], nv->nvram_version);
6342 ql_log(ql_log_warn, vha, 0x006c,
6343 "Falling back to functioning (yet invalid -- WWPN) "
6347 * Set default initialization control block.
6349 memset(nv, 0, ha->nvram_size);
6350 nv->nvram_version = cpu_to_le16(ICB_VERSION);
6351 nv->version = cpu_to_le16(ICB_VERSION);
6352 nv->frame_payload_size = 2048;
6353 nv->execution_throttle = cpu_to_le16(0xFFFF);
6354 nv->exchange_count = cpu_to_le16(0);
6355 nv->hard_address = cpu_to_le16(124);
6356 nv->port_name[0] = 0x21;
6357 nv->port_name[1] = 0x00 + ha->port_no + 1;
6358 nv->port_name[2] = 0x00;
6359 nv->port_name[3] = 0xe0;
6360 nv->port_name[4] = 0x8b;
6361 nv->port_name[5] = 0x1c;
6362 nv->port_name[6] = 0x55;
6363 nv->port_name[7] = 0x86;
6364 nv->node_name[0] = 0x20;
6365 nv->node_name[1] = 0x00;
6366 nv->node_name[2] = 0x00;
6367 nv->node_name[3] = 0xe0;
6368 nv->node_name[4] = 0x8b;
6369 nv->node_name[5] = 0x1c;
6370 nv->node_name[6] = 0x55;
6371 nv->node_name[7] = 0x86;
6372 qla24xx_nvram_wwn_from_ofw(vha, nv);
6373 nv->login_retry_count = cpu_to_le16(8);
6374 nv->interrupt_delay_timer = cpu_to_le16(0);
6375 nv->login_timeout = cpu_to_le16(0);
6376 nv->firmware_options_1 =
6377 cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
6378 nv->firmware_options_2 = cpu_to_le32(2 << 4);
6379 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
6380 nv->firmware_options_3 = cpu_to_le32(2 << 13);
6381 nv->host_p = cpu_to_le32(BIT_11|BIT_10);
6382 nv->efi_parameters = cpu_to_le32(0);
6383 nv->reset_delay = 5;
6384 nv->max_luns_per_target = cpu_to_le16(128);
6385 nv->port_down_retry_count = cpu_to_le16(30);
6386 nv->link_down_timeout = cpu_to_le16(30);
6391 if (qla_tgt_mode_enabled(vha)) {
6392 /* Don't enable full login after initial LIP */
6393 nv->firmware_options_1 &= cpu_to_le32(~BIT_13);
6394 /* Don't enable LIP full login for initiator */
6395 nv->host_p &= cpu_to_le32(~BIT_10);
6398 qlt_24xx_config_nvram_stage1(vha, nv);
6400 /* Reset Initialization control block */
6401 memset(icb, 0, ha->init_cb_size);
6403 /* Copy 1st segment. */
6404 dptr1 = (uint8_t *)icb;
6405 dptr2 = (uint8_t *)&nv->version;
6406 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
6408 *dptr1++ = *dptr2++;
6410 icb->login_retry_count = nv->login_retry_count;
6411 icb->link_down_on_nos = nv->link_down_on_nos;
6413 /* Copy 2nd segment. */
6414 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
6415 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
6416 cnt = (uint8_t *)&icb->reserved_3 -
6417 (uint8_t *)&icb->interrupt_delay_timer;
6419 *dptr1++ = *dptr2++;
6422 * Setup driver NVRAM options.
6424 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
6427 qlt_24xx_config_nvram_stage2(vha, icb);
6429 if (nv->host_p & cpu_to_le32(BIT_15)) {
6430 /* Use alternate WWN? */
6431 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
6432 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
6435 /* Prepare nodename */
6436 if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
6438 * Firmware will apply the following mask if the nodename was
6441 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
6442 icb->node_name[0] &= 0xF0;
6445 /* Set host adapter parameters. */
6446 ha->flags.disable_risc_code_load = 0;
6447 ha->flags.enable_lip_reset = 0;
6448 ha->flags.enable_lip_full_login =
6449 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
6450 ha->flags.enable_target_reset =
6451 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
6452 ha->flags.enable_led_scheme = 0;
6453 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
6455 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
6456 (BIT_6 | BIT_5 | BIT_4)) >> 4;
6458 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
6459 sizeof(ha->fw_seriallink_options24));
6461 /* save HBA serial number */
6462 ha->serial0 = icb->port_name[5];
6463 ha->serial1 = icb->port_name[6];
6464 ha->serial2 = icb->port_name[7];
6465 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
6466 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
6468 icb->execution_throttle = cpu_to_le16(0xFFFF);
6470 ha->retry_count = le16_to_cpu(nv->login_retry_count);
6472 /* Set minimum login_timeout to 4 seconds. */
6473 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
6474 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
6475 if (le16_to_cpu(nv->login_timeout) < 4)
6476 nv->login_timeout = cpu_to_le16(4);
6477 ha->login_timeout = le16_to_cpu(nv->login_timeout);
6479 /* Set minimum RATOV to 100 tenths of a second. */
6482 ha->loop_reset_delay = nv->reset_delay;
6484 /* Link Down Timeout = 0:
6486 * When Port Down timer expires we will start returning
6487 * I/O's to OS with "DID_NO_CONNECT".
6489 * Link Down Timeout != 0:
6491 * The driver waits for the link to come up after link down
6492 * before returning I/Os to OS with "DID_NO_CONNECT".
6494 if (le16_to_cpu(nv->link_down_timeout) == 0) {
6495 ha->loop_down_abort_time =
6496 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
6498 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
6499 ha->loop_down_abort_time =
6500 (LOOP_DOWN_TIME - ha->link_down_timeout);
6503 /* Need enough time to try and get the port back. */
6504 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
6505 if (qlport_down_retry)
6506 ha->port_down_retry_count = qlport_down_retry;
6508 /* Set login_retry_count */
6509 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
6510 if (ha->port_down_retry_count ==
6511 le16_to_cpu(nv->port_down_retry_count) &&
6512 ha->port_down_retry_count > 3)
6513 ha->login_retry_count = ha->port_down_retry_count;
6514 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
6515 ha->login_retry_count = ha->port_down_retry_count;
6516 if (ql2xloginretrycount)
6517 ha->login_retry_count = ql2xloginretrycount;
6520 if (!vha->flags.init_done) {
6521 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
6522 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
6523 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
6524 le16_to_cpu(icb->interrupt_delay_timer): 2;
6526 icb->firmware_options_2 &= cpu_to_le32(
6527 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
6528 vha->flags.process_response_queue = 0;
6529 if (ha->zio_mode != QLA_ZIO_DISABLED) {
6530 ha->zio_mode = QLA_ZIO_MODE_6;
6532 ql_log(ql_log_info, vha, 0x006f,
6533 "ZIO mode %d enabled; timer delay (%d us).\n",
6534 ha->zio_mode, ha->zio_timer * 100);
6536 icb->firmware_options_2 |= cpu_to_le32(
6537 (uint32_t)ha->zio_mode);
6538 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
6539 vha->flags.process_response_queue = 1;
6543 ql_log(ql_log_warn, vha, 0x0070,
6544 "NVRAM configuration failed.\n");
6549 uint8_t qla27xx_find_valid_image(struct scsi_qla_host *vha)
6551 struct qla27xx_image_status pri_image_status, sec_image_status;
6552 uint8_t valid_pri_image, valid_sec_image;
6554 uint32_t cnt, chksum, size;
6555 struct qla_hw_data *ha = vha->hw;
6557 valid_pri_image = valid_sec_image = 1;
6558 ha->active_image = 0;
6559 size = sizeof(struct qla27xx_image_status) / sizeof(uint32_t);
6561 if (!ha->flt_region_img_status_pri) {
6562 valid_pri_image = 0;
6563 goto check_sec_image;
6566 qla24xx_read_flash_data(vha, (uint32_t *)(&pri_image_status),
6567 ha->flt_region_img_status_pri, size);
6569 if (pri_image_status.signature != QLA27XX_IMG_STATUS_SIGN) {
6570 ql_dbg(ql_dbg_init, vha, 0x018b,
6571 "Primary image signature (0x%x) not valid\n",
6572 pri_image_status.signature);
6573 valid_pri_image = 0;
6574 goto check_sec_image;
6577 wptr = (uint32_t *)(&pri_image_status);
6580 for (chksum = 0; cnt--; wptr++)
6581 chksum += le32_to_cpu(*wptr);
6584 ql_dbg(ql_dbg_init, vha, 0x018c,
6585 "Checksum validation failed for primary image (0x%x)\n",
6587 valid_pri_image = 0;
6591 if (!ha->flt_region_img_status_sec) {
6592 valid_sec_image = 0;
6593 goto check_valid_image;
6596 qla24xx_read_flash_data(vha, (uint32_t *)(&sec_image_status),
6597 ha->flt_region_img_status_sec, size);
6599 if (sec_image_status.signature != QLA27XX_IMG_STATUS_SIGN) {
6600 ql_dbg(ql_dbg_init, vha, 0x018d,
6601 "Secondary image signature(0x%x) not valid\n",
6602 sec_image_status.signature);
6603 valid_sec_image = 0;
6604 goto check_valid_image;
6607 wptr = (uint32_t *)(&sec_image_status);
6609 for (chksum = 0; cnt--; wptr++)
6610 chksum += le32_to_cpu(*wptr);
6612 ql_dbg(ql_dbg_init, vha, 0x018e,
6613 "Checksum validation failed for secondary image (0x%x)\n",
6615 valid_sec_image = 0;
6619 if (valid_pri_image && (pri_image_status.image_status_mask & 0x1))
6620 ha->active_image = QLA27XX_PRIMARY_IMAGE;
6621 if (valid_sec_image && (sec_image_status.image_status_mask & 0x1)) {
6622 if (!ha->active_image ||
6623 pri_image_status.generation_number <
6624 sec_image_status.generation_number)
6625 ha->active_image = QLA27XX_SECONDARY_IMAGE;
6628 ql_dbg(ql_dbg_init, vha, 0x018f, "%s image\n",
6629 ha->active_image == 0 ? "default bootld and fw" :
6630 ha->active_image == 1 ? "primary" :
6631 ha->active_image == 2 ? "secondary" :
6634 return ha->active_image;
6638 qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
6641 int rval = QLA_SUCCESS;
6642 int segments, fragment;
6643 uint32_t *dcode, dlen;
6647 struct qla_hw_data *ha = vha->hw;
6648 struct req_que *req = ha->req_q_map[0];
6650 ql_dbg(ql_dbg_init, vha, 0x008b,
6651 "FW: Loading firmware from flash (%x).\n", faddr);
6655 segments = FA_RISC_CODE_SEGMENTS;
6656 dcode = (uint32_t *)req->ring;
6659 if (IS_QLA27XX(ha) &&
6660 qla27xx_find_valid_image(vha) == QLA27XX_SECONDARY_IMAGE)
6661 faddr = ha->flt_region_fw_sec;
6663 /* Validate firmware image by checking version. */
6664 qla24xx_read_flash_data(vha, dcode, faddr + 4, 4);
6665 for (i = 0; i < 4; i++)
6666 dcode[i] = be32_to_cpu(dcode[i]);
6667 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
6668 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
6669 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
6671 ql_log(ql_log_fatal, vha, 0x008c,
6672 "Unable to verify the integrity of flash firmware "
6674 ql_log(ql_log_fatal, vha, 0x008d,
6675 "Firmware data: %08x %08x %08x %08x.\n",
6676 dcode[0], dcode[1], dcode[2], dcode[3]);
6678 return QLA_FUNCTION_FAILED;
6681 while (segments && rval == QLA_SUCCESS) {
6682 /* Read segment's load information. */
6683 qla24xx_read_flash_data(vha, dcode, faddr, 4);
6685 risc_addr = be32_to_cpu(dcode[2]);
6686 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
6687 risc_size = be32_to_cpu(dcode[3]);
6690 while (risc_size > 0 && rval == QLA_SUCCESS) {
6691 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
6692 if (dlen > risc_size)
6695 ql_dbg(ql_dbg_init, vha, 0x008e,
6696 "Loading risc segment@ risc addr %x "
6697 "number of dwords 0x%x offset 0x%x.\n",
6698 risc_addr, dlen, faddr);
6700 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
6701 for (i = 0; i < dlen; i++)
6702 dcode[i] = swab32(dcode[i]);
6704 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
6707 ql_log(ql_log_fatal, vha, 0x008f,
6708 "Failed to load segment %d of firmware.\n",
6710 return QLA_FUNCTION_FAILED;
6723 if (!IS_QLA27XX(ha))
6726 if (ha->fw_dump_template)
6727 vfree(ha->fw_dump_template);
6728 ha->fw_dump_template = NULL;
6729 ha->fw_dump_template_len = 0;
6731 ql_dbg(ql_dbg_init, vha, 0x0161,
6732 "Loading fwdump template from %x\n", faddr);
6733 qla24xx_read_flash_data(vha, dcode, faddr, 7);
6734 risc_size = be32_to_cpu(dcode[2]);
6735 ql_dbg(ql_dbg_init, vha, 0x0162,
6736 "-> array size %x dwords\n", risc_size);
6737 if (risc_size == 0 || risc_size == ~0)
6738 goto default_template;
6740 dlen = (risc_size - 8) * sizeof(*dcode);
6741 ql_dbg(ql_dbg_init, vha, 0x0163,
6742 "-> template allocating %x bytes...\n", dlen);
6743 ha->fw_dump_template = vmalloc(dlen);
6744 if (!ha->fw_dump_template) {
6745 ql_log(ql_log_warn, vha, 0x0164,
6746 "Failed fwdump template allocate %x bytes.\n", risc_size);
6747 goto default_template;
6752 dcode = ha->fw_dump_template;
6753 qla24xx_read_flash_data(vha, dcode, faddr, risc_size);
6754 for (i = 0; i < risc_size; i++)
6755 dcode[i] = le32_to_cpu(dcode[i]);
6757 if (!qla27xx_fwdt_template_valid(dcode)) {
6758 ql_log(ql_log_warn, vha, 0x0165,
6759 "Failed fwdump template validate\n");
6760 goto default_template;
6763 dlen = qla27xx_fwdt_template_size(dcode);
6764 ql_dbg(ql_dbg_init, vha, 0x0166,
6765 "-> template size %x bytes\n", dlen);
6766 if (dlen > risc_size * sizeof(*dcode)) {
6767 ql_log(ql_log_warn, vha, 0x0167,
6768 "Failed fwdump template exceeds array by %zx bytes\n",
6769 (size_t)(dlen - risc_size * sizeof(*dcode)));
6770 goto default_template;
6772 ha->fw_dump_template_len = dlen;
6776 ql_log(ql_log_warn, vha, 0x0168, "Using default fwdump template\n");
6777 if (ha->fw_dump_template)
6778 vfree(ha->fw_dump_template);
6779 ha->fw_dump_template = NULL;
6780 ha->fw_dump_template_len = 0;
6782 dlen = qla27xx_fwdt_template_default_size();
6783 ql_dbg(ql_dbg_init, vha, 0x0169,
6784 "-> template allocating %x bytes...\n", dlen);
6785 ha->fw_dump_template = vmalloc(dlen);
6786 if (!ha->fw_dump_template) {
6787 ql_log(ql_log_warn, vha, 0x016a,
6788 "Failed fwdump template allocate %x bytes.\n", risc_size);
6789 goto failed_template;
6792 dcode = ha->fw_dump_template;
6793 risc_size = dlen / sizeof(*dcode);
6794 memcpy(dcode, qla27xx_fwdt_template_default(), dlen);
6795 for (i = 0; i < risc_size; i++)
6796 dcode[i] = be32_to_cpu(dcode[i]);
6798 if (!qla27xx_fwdt_template_valid(ha->fw_dump_template)) {
6799 ql_log(ql_log_warn, vha, 0x016b,
6800 "Failed fwdump template validate\n");
6801 goto failed_template;
6804 dlen = qla27xx_fwdt_template_size(ha->fw_dump_template);
6805 ql_dbg(ql_dbg_init, vha, 0x016c,
6806 "-> template size %x bytes\n", dlen);
6807 ha->fw_dump_template_len = dlen;
6811 ql_log(ql_log_warn, vha, 0x016d, "Failed default fwdump template\n");
6812 if (ha->fw_dump_template)
6813 vfree(ha->fw_dump_template);
6814 ha->fw_dump_template = NULL;
6815 ha->fw_dump_template_len = 0;
6819 #define QLA_FW_URL "http://ldriver.qlogic.com/firmware/"
6822 qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
6826 uint16_t *wcode, *fwcode;
6827 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
6828 struct fw_blob *blob;
6829 struct qla_hw_data *ha = vha->hw;
6830 struct req_que *req = ha->req_q_map[0];
6832 /* Load firmware blob. */
6833 blob = qla2x00_request_firmware(vha);
6835 ql_log(ql_log_info, vha, 0x0083,
6836 "Firmware image unavailable.\n");
6837 ql_log(ql_log_info, vha, 0x0084,
6838 "Firmware images can be retrieved from: "QLA_FW_URL ".\n");
6839 return QLA_FUNCTION_FAILED;
6844 wcode = (uint16_t *)req->ring;
6846 fwcode = (uint16_t *)blob->fw->data;
6849 /* Validate firmware image by checking version. */
6850 if (blob->fw->size < 8 * sizeof(uint16_t)) {
6851 ql_log(ql_log_fatal, vha, 0x0085,
6852 "Unable to verify integrity of firmware image (%zd).\n",
6854 goto fail_fw_integrity;
6856 for (i = 0; i < 4; i++)
6857 wcode[i] = be16_to_cpu(fwcode[i + 4]);
6858 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
6859 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
6860 wcode[2] == 0 && wcode[3] == 0)) {
6861 ql_log(ql_log_fatal, vha, 0x0086,
6862 "Unable to verify integrity of firmware image.\n");
6863 ql_log(ql_log_fatal, vha, 0x0087,
6864 "Firmware data: %04x %04x %04x %04x.\n",
6865 wcode[0], wcode[1], wcode[2], wcode[3]);
6866 goto fail_fw_integrity;
6870 while (*seg && rval == QLA_SUCCESS) {
6872 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
6873 risc_size = be16_to_cpu(fwcode[3]);
6875 /* Validate firmware image size. */
6876 fwclen += risc_size * sizeof(uint16_t);
6877 if (blob->fw->size < fwclen) {
6878 ql_log(ql_log_fatal, vha, 0x0088,
6879 "Unable to verify integrity of firmware image "
6880 "(%zd).\n", blob->fw->size);
6881 goto fail_fw_integrity;
6885 while (risc_size > 0 && rval == QLA_SUCCESS) {
6886 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
6887 if (wlen > risc_size)
6889 ql_dbg(ql_dbg_init, vha, 0x0089,
6890 "Loading risc segment@ risc addr %x number of "
6891 "words 0x%x.\n", risc_addr, wlen);
6893 for (i = 0; i < wlen; i++)
6894 wcode[i] = swab16(fwcode[i]);
6896 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
6899 ql_log(ql_log_fatal, vha, 0x008a,
6900 "Failed to load segment %d of firmware.\n",
6917 return QLA_FUNCTION_FAILED;
6921 qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
6924 int segments, fragment;
6925 uint32_t *dcode, dlen;
6929 struct fw_blob *blob;
6930 const uint32_t *fwcode;
6932 struct qla_hw_data *ha = vha->hw;
6933 struct req_que *req = ha->req_q_map[0];
6935 /* Load firmware blob. */
6936 blob = qla2x00_request_firmware(vha);
6938 ql_log(ql_log_warn, vha, 0x0090,
6939 "Firmware image unavailable.\n");
6940 ql_log(ql_log_warn, vha, 0x0091,
6941 "Firmware images can be retrieved from: "
6944 return QLA_FUNCTION_FAILED;
6947 ql_dbg(ql_dbg_init, vha, 0x0092,
6948 "FW: Loading via request-firmware.\n");
6952 segments = FA_RISC_CODE_SEGMENTS;
6953 dcode = (uint32_t *)req->ring;
6955 fwcode = (uint32_t *)blob->fw->data;
6958 /* Validate firmware image by checking version. */
6959 if (blob->fw->size < 8 * sizeof(uint32_t)) {
6960 ql_log(ql_log_fatal, vha, 0x0093,
6961 "Unable to verify integrity of firmware image (%zd).\n",
6963 return QLA_FUNCTION_FAILED;
6965 for (i = 0; i < 4; i++)
6966 dcode[i] = be32_to_cpu(fwcode[i + 4]);
6967 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
6968 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
6969 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
6971 ql_log(ql_log_fatal, vha, 0x0094,
6972 "Unable to verify integrity of firmware image (%zd).\n",
6974 ql_log(ql_log_fatal, vha, 0x0095,
6975 "Firmware data: %08x %08x %08x %08x.\n",
6976 dcode[0], dcode[1], dcode[2], dcode[3]);
6977 return QLA_FUNCTION_FAILED;
6980 while (segments && rval == QLA_SUCCESS) {
6981 risc_addr = be32_to_cpu(fwcode[2]);
6982 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
6983 risc_size = be32_to_cpu(fwcode[3]);
6985 /* Validate firmware image size. */
6986 fwclen += risc_size * sizeof(uint32_t);
6987 if (blob->fw->size < fwclen) {
6988 ql_log(ql_log_fatal, vha, 0x0096,
6989 "Unable to verify integrity of firmware image "
6990 "(%zd).\n", blob->fw->size);
6991 return QLA_FUNCTION_FAILED;
6995 while (risc_size > 0 && rval == QLA_SUCCESS) {
6996 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
6997 if (dlen > risc_size)
7000 ql_dbg(ql_dbg_init, vha, 0x0097,
7001 "Loading risc segment@ risc addr %x "
7002 "number of dwords 0x%x.\n", risc_addr, dlen);
7004 for (i = 0; i < dlen; i++)
7005 dcode[i] = swab32(fwcode[i]);
7007 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
7010 ql_log(ql_log_fatal, vha, 0x0098,
7011 "Failed to load segment %d of firmware.\n",
7013 return QLA_FUNCTION_FAILED;
7026 if (!IS_QLA27XX(ha))
7029 if (ha->fw_dump_template)
7030 vfree(ha->fw_dump_template);
7031 ha->fw_dump_template = NULL;
7032 ha->fw_dump_template_len = 0;
7034 ql_dbg(ql_dbg_init, vha, 0x171,
7035 "Loading fwdump template from %x\n",
7036 (uint32_t)((void *)fwcode - (void *)blob->fw->data));
7037 risc_size = be32_to_cpu(fwcode[2]);
7038 ql_dbg(ql_dbg_init, vha, 0x172,
7039 "-> array size %x dwords\n", risc_size);
7040 if (risc_size == 0 || risc_size == ~0)
7041 goto default_template;
7043 dlen = (risc_size - 8) * sizeof(*fwcode);
7044 ql_dbg(ql_dbg_init, vha, 0x0173,
7045 "-> template allocating %x bytes...\n", dlen);
7046 ha->fw_dump_template = vmalloc(dlen);
7047 if (!ha->fw_dump_template) {
7048 ql_log(ql_log_warn, vha, 0x0174,
7049 "Failed fwdump template allocate %x bytes.\n", risc_size);
7050 goto default_template;
7055 dcode = ha->fw_dump_template;
7056 for (i = 0; i < risc_size; i++)
7057 dcode[i] = le32_to_cpu(fwcode[i]);
7059 if (!qla27xx_fwdt_template_valid(dcode)) {
7060 ql_log(ql_log_warn, vha, 0x0175,
7061 "Failed fwdump template validate\n");
7062 goto default_template;
7065 dlen = qla27xx_fwdt_template_size(dcode);
7066 ql_dbg(ql_dbg_init, vha, 0x0176,
7067 "-> template size %x bytes\n", dlen);
7068 if (dlen > risc_size * sizeof(*fwcode)) {
7069 ql_log(ql_log_warn, vha, 0x0177,
7070 "Failed fwdump template exceeds array by %zx bytes\n",
7071 (size_t)(dlen - risc_size * sizeof(*fwcode)));
7072 goto default_template;
7074 ha->fw_dump_template_len = dlen;
7078 ql_log(ql_log_warn, vha, 0x0178, "Using default fwdump template\n");
7079 if (ha->fw_dump_template)
7080 vfree(ha->fw_dump_template);
7081 ha->fw_dump_template = NULL;
7082 ha->fw_dump_template_len = 0;
7084 dlen = qla27xx_fwdt_template_default_size();
7085 ql_dbg(ql_dbg_init, vha, 0x0179,
7086 "-> template allocating %x bytes...\n", dlen);
7087 ha->fw_dump_template = vmalloc(dlen);
7088 if (!ha->fw_dump_template) {
7089 ql_log(ql_log_warn, vha, 0x017a,
7090 "Failed fwdump template allocate %x bytes.\n", risc_size);
7091 goto failed_template;
7094 dcode = ha->fw_dump_template;
7095 risc_size = dlen / sizeof(*fwcode);
7096 fwcode = qla27xx_fwdt_template_default();
7097 for (i = 0; i < risc_size; i++)
7098 dcode[i] = be32_to_cpu(fwcode[i]);
7100 if (!qla27xx_fwdt_template_valid(ha->fw_dump_template)) {
7101 ql_log(ql_log_warn, vha, 0x017b,
7102 "Failed fwdump template validate\n");
7103 goto failed_template;
7106 dlen = qla27xx_fwdt_template_size(ha->fw_dump_template);
7107 ql_dbg(ql_dbg_init, vha, 0x017c,
7108 "-> template size %x bytes\n", dlen);
7109 ha->fw_dump_template_len = dlen;
7113 ql_log(ql_log_warn, vha, 0x017d, "Failed default fwdump template\n");
7114 if (ha->fw_dump_template)
7115 vfree(ha->fw_dump_template);
7116 ha->fw_dump_template = NULL;
7117 ha->fw_dump_template_len = 0;
7122 qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
7126 if (ql2xfwloadbin == 1)
7127 return qla81xx_load_risc(vha, srisc_addr);
7131 * 1) Firmware via request-firmware interface (.bin file).
7132 * 2) Firmware residing in flash.
7134 rval = qla24xx_load_risc_blob(vha, srisc_addr);
7135 if (rval == QLA_SUCCESS)
7138 return qla24xx_load_risc_flash(vha, srisc_addr,
7139 vha->hw->flt_region_fw);
7143 qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
7146 struct qla_hw_data *ha = vha->hw;
7148 if (ql2xfwloadbin == 2)
7153 * 1) Firmware residing in flash.
7154 * 2) Firmware via request-firmware interface (.bin file).
7155 * 3) Golden-Firmware residing in flash -- limited operation.
7157 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
7158 if (rval == QLA_SUCCESS)
7162 rval = qla24xx_load_risc_blob(vha, srisc_addr);
7163 if (rval == QLA_SUCCESS || !ha->flt_region_gold_fw)
7166 ql_log(ql_log_info, vha, 0x0099,
7167 "Attempting to fallback to golden firmware.\n");
7168 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
7169 if (rval != QLA_SUCCESS)
7172 ql_log(ql_log_info, vha, 0x009a, "Update operational firmware.\n");
7173 ha->flags.running_gold_fw = 1;
7178 qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
7181 struct qla_hw_data *ha = vha->hw;
7183 if (ha->flags.pci_channel_io_perm_failure)
7185 if (!IS_FWI2_CAPABLE(ha))
7187 if (!ha->fw_major_version)
7189 if (!ha->flags.fw_started)
7192 ret = qla2x00_stop_firmware(vha);
7193 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
7194 ret != QLA_INVALID_COMMAND && retries ; retries--) {
7195 ha->isp_ops->reset_chip(vha);
7196 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
7198 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
7200 ql_log(ql_log_info, vha, 0x8015,
7201 "Attempting retry of stop-firmware command.\n");
7202 ret = qla2x00_stop_firmware(vha);
7206 ha->flags.fw_init_done = 0;
7210 qla24xx_configure_vhba(scsi_qla_host_t *vha)
7212 int rval = QLA_SUCCESS;
7214 uint16_t mb[MAILBOX_REGISTER_COUNT];
7215 struct qla_hw_data *ha = vha->hw;
7216 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
7217 struct req_que *req;
7218 struct rsp_que *rsp;
7223 rval = qla2x00_fw_ready(base_vha);
7225 req = vha->qpair->req;
7227 req = ha->req_q_map[0];
7230 if (rval == QLA_SUCCESS) {
7231 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
7232 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
7235 vha->flags.management_server_logged_in = 0;
7237 /* Login to SNS first */
7238 rval2 = ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb,
7240 if (rval2 != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
7241 if (rval2 == QLA_MEMORY_ALLOC_FAILED)
7242 ql_dbg(ql_dbg_init, vha, 0x0120,
7243 "Failed SNS login: loop_id=%x, rval2=%d\n",
7246 ql_dbg(ql_dbg_init, vha, 0x0103,
7247 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
7248 "mb[2]=%x mb[6]=%x mb[7]=%x.\n",
7249 NPH_SNS, mb[0], mb[1], mb[2], mb[6], mb[7]);
7250 return (QLA_FUNCTION_FAILED);
7253 atomic_set(&vha->loop_down_timer, 0);
7254 atomic_set(&vha->loop_state, LOOP_UP);
7255 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
7256 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
7257 rval = qla2x00_loop_resync(base_vha);
7262 /* 84XX Support **************************************************************/
7264 static LIST_HEAD(qla_cs84xx_list);
7265 static DEFINE_MUTEX(qla_cs84xx_mutex);
7267 static struct qla_chip_state_84xx *
7268 qla84xx_get_chip(struct scsi_qla_host *vha)
7270 struct qla_chip_state_84xx *cs84xx;
7271 struct qla_hw_data *ha = vha->hw;
7273 mutex_lock(&qla_cs84xx_mutex);
7275 /* Find any shared 84xx chip. */
7276 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
7277 if (cs84xx->bus == ha->pdev->bus) {
7278 kref_get(&cs84xx->kref);
7283 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
7287 kref_init(&cs84xx->kref);
7288 spin_lock_init(&cs84xx->access_lock);
7289 mutex_init(&cs84xx->fw_update_mutex);
7290 cs84xx->bus = ha->pdev->bus;
7292 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
7294 mutex_unlock(&qla_cs84xx_mutex);
7299 __qla84xx_chip_release(struct kref *kref)
7301 struct qla_chip_state_84xx *cs84xx =
7302 container_of(kref, struct qla_chip_state_84xx, kref);
7304 mutex_lock(&qla_cs84xx_mutex);
7305 list_del(&cs84xx->list);
7306 mutex_unlock(&qla_cs84xx_mutex);
7311 qla84xx_put_chip(struct scsi_qla_host *vha)
7313 struct qla_hw_data *ha = vha->hw;
7315 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
7319 qla84xx_init_chip(scsi_qla_host_t *vha)
7323 struct qla_hw_data *ha = vha->hw;
7325 mutex_lock(&ha->cs84xx->fw_update_mutex);
7327 rval = qla84xx_verify_chip(vha, status);
7329 mutex_unlock(&ha->cs84xx->fw_update_mutex);
7331 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED:
7335 /* 81XX Support **************************************************************/
7338 qla81xx_nvram_config(scsi_qla_host_t *vha)
7341 struct init_cb_81xx *icb;
7342 struct nvram_81xx *nv;
7344 uint8_t *dptr1, *dptr2;
7347 struct qla_hw_data *ha = vha->hw;
7350 icb = (struct init_cb_81xx *)ha->init_cb;
7353 /* Determine NVRAM starting address. */
7354 ha->nvram_size = sizeof(struct nvram_81xx);
7355 ha->vpd_size = FA_NVRAM_VPD_SIZE;
7356 if (IS_P3P_TYPE(ha) || IS_QLA8031(ha))
7357 ha->vpd_size = FA_VPD_SIZE_82XX;
7359 /* Get VPD data into cache */
7360 ha->vpd = ha->nvram + VPD_OFFSET;
7361 ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
7364 /* Get NVRAM data into cache and calculate checksum. */
7365 ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
7367 dptr = (uint32_t *)nv;
7368 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++)
7369 chksum += le32_to_cpu(*dptr);
7371 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0111,
7372 "Contents of NVRAM:\n");
7373 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0112,
7374 (uint8_t *)nv, ha->nvram_size);
7376 /* Bad NVRAM data, set defaults parameters. */
7377 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
7378 || nv->id[3] != ' ' ||
7379 nv->nvram_version < cpu_to_le16(ICB_VERSION)) {
7380 /* Reset NVRAM data. */
7381 ql_log(ql_log_info, vha, 0x0073,
7382 "Inconsistent NVRAM detected: checksum=0x%x id=%c "
7383 "version=0x%x.\n", chksum, nv->id[0],
7384 le16_to_cpu(nv->nvram_version));
7385 ql_log(ql_log_info, vha, 0x0074,
7386 "Falling back to functioning (yet invalid -- WWPN) "
7390 * Set default initialization control block.
7392 memset(nv, 0, ha->nvram_size);
7393 nv->nvram_version = cpu_to_le16(ICB_VERSION);
7394 nv->version = cpu_to_le16(ICB_VERSION);
7395 nv->frame_payload_size = 2048;
7396 nv->execution_throttle = cpu_to_le16(0xFFFF);
7397 nv->exchange_count = cpu_to_le16(0);
7398 nv->port_name[0] = 0x21;
7399 nv->port_name[1] = 0x00 + ha->port_no + 1;
7400 nv->port_name[2] = 0x00;
7401 nv->port_name[3] = 0xe0;
7402 nv->port_name[4] = 0x8b;
7403 nv->port_name[5] = 0x1c;
7404 nv->port_name[6] = 0x55;
7405 nv->port_name[7] = 0x86;
7406 nv->node_name[0] = 0x20;
7407 nv->node_name[1] = 0x00;
7408 nv->node_name[2] = 0x00;
7409 nv->node_name[3] = 0xe0;
7410 nv->node_name[4] = 0x8b;
7411 nv->node_name[5] = 0x1c;
7412 nv->node_name[6] = 0x55;
7413 nv->node_name[7] = 0x86;
7414 nv->login_retry_count = cpu_to_le16(8);
7415 nv->interrupt_delay_timer = cpu_to_le16(0);
7416 nv->login_timeout = cpu_to_le16(0);
7417 nv->firmware_options_1 =
7418 cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
7419 nv->firmware_options_2 = cpu_to_le32(2 << 4);
7420 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
7421 nv->firmware_options_3 = cpu_to_le32(2 << 13);
7422 nv->host_p = cpu_to_le32(BIT_11|BIT_10);
7423 nv->efi_parameters = cpu_to_le32(0);
7424 nv->reset_delay = 5;
7425 nv->max_luns_per_target = cpu_to_le16(128);
7426 nv->port_down_retry_count = cpu_to_le16(30);
7427 nv->link_down_timeout = cpu_to_le16(180);
7428 nv->enode_mac[0] = 0x00;
7429 nv->enode_mac[1] = 0xC0;
7430 nv->enode_mac[2] = 0xDD;
7431 nv->enode_mac[3] = 0x04;
7432 nv->enode_mac[4] = 0x05;
7433 nv->enode_mac[5] = 0x06 + ha->port_no + 1;
7438 if (IS_T10_PI_CAPABLE(ha))
7439 nv->frame_payload_size &= ~7;
7441 qlt_81xx_config_nvram_stage1(vha, nv);
7443 /* Reset Initialization control block */
7444 memset(icb, 0, ha->init_cb_size);
7446 /* Copy 1st segment. */
7447 dptr1 = (uint8_t *)icb;
7448 dptr2 = (uint8_t *)&nv->version;
7449 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
7451 *dptr1++ = *dptr2++;
7453 icb->login_retry_count = nv->login_retry_count;
7455 /* Copy 2nd segment. */
7456 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
7457 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
7458 cnt = (uint8_t *)&icb->reserved_5 -
7459 (uint8_t *)&icb->interrupt_delay_timer;
7461 *dptr1++ = *dptr2++;
7463 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
7464 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
7465 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
7466 icb->enode_mac[0] = 0x00;
7467 icb->enode_mac[1] = 0xC0;
7468 icb->enode_mac[2] = 0xDD;
7469 icb->enode_mac[3] = 0x04;
7470 icb->enode_mac[4] = 0x05;
7471 icb->enode_mac[5] = 0x06 + ha->port_no + 1;
7474 /* Use extended-initialization control block. */
7475 memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
7478 * Setup driver NVRAM options.
7480 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
7483 qlt_81xx_config_nvram_stage2(vha, icb);
7485 /* Use alternate WWN? */
7486 if (nv->host_p & cpu_to_le32(BIT_15)) {
7487 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
7488 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
7491 /* Prepare nodename */
7492 if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
7494 * Firmware will apply the following mask if the nodename was
7497 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
7498 icb->node_name[0] &= 0xF0;
7501 /* Set host adapter parameters. */
7502 ha->flags.disable_risc_code_load = 0;
7503 ha->flags.enable_lip_reset = 0;
7504 ha->flags.enable_lip_full_login =
7505 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
7506 ha->flags.enable_target_reset =
7507 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
7508 ha->flags.enable_led_scheme = 0;
7509 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
7511 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
7512 (BIT_6 | BIT_5 | BIT_4)) >> 4;
7514 /* save HBA serial number */
7515 ha->serial0 = icb->port_name[5];
7516 ha->serial1 = icb->port_name[6];
7517 ha->serial2 = icb->port_name[7];
7518 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
7519 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
7521 icb->execution_throttle = cpu_to_le16(0xFFFF);
7523 ha->retry_count = le16_to_cpu(nv->login_retry_count);
7525 /* Set minimum login_timeout to 4 seconds. */
7526 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
7527 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
7528 if (le16_to_cpu(nv->login_timeout) < 4)
7529 nv->login_timeout = cpu_to_le16(4);
7530 ha->login_timeout = le16_to_cpu(nv->login_timeout);
7532 /* Set minimum RATOV to 100 tenths of a second. */
7535 ha->loop_reset_delay = nv->reset_delay;
7537 /* Link Down Timeout = 0:
7539 * When Port Down timer expires we will start returning
7540 * I/O's to OS with "DID_NO_CONNECT".
7542 * Link Down Timeout != 0:
7544 * The driver waits for the link to come up after link down
7545 * before returning I/Os to OS with "DID_NO_CONNECT".
7547 if (le16_to_cpu(nv->link_down_timeout) == 0) {
7548 ha->loop_down_abort_time =
7549 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
7551 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
7552 ha->loop_down_abort_time =
7553 (LOOP_DOWN_TIME - ha->link_down_timeout);
7556 /* Need enough time to try and get the port back. */
7557 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
7558 if (qlport_down_retry)
7559 ha->port_down_retry_count = qlport_down_retry;
7561 /* Set login_retry_count */
7562 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
7563 if (ha->port_down_retry_count ==
7564 le16_to_cpu(nv->port_down_retry_count) &&
7565 ha->port_down_retry_count > 3)
7566 ha->login_retry_count = ha->port_down_retry_count;
7567 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
7568 ha->login_retry_count = ha->port_down_retry_count;
7569 if (ql2xloginretrycount)
7570 ha->login_retry_count = ql2xloginretrycount;
7572 /* if not running MSI-X we need handshaking on interrupts */
7573 if (!vha->hw->flags.msix_enabled && (IS_QLA83XX(ha) || IS_QLA27XX(ha)))
7574 icb->firmware_options_2 |= cpu_to_le32(BIT_22);
7577 if (!vha->flags.init_done) {
7578 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
7579 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
7580 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
7581 le16_to_cpu(icb->interrupt_delay_timer): 2;
7583 icb->firmware_options_2 &= cpu_to_le32(
7584 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
7585 if (ha->zio_mode != QLA_ZIO_DISABLED) {
7586 ha->zio_mode = QLA_ZIO_MODE_6;
7588 ql_log(ql_log_info, vha, 0x0075,
7589 "ZIO mode %d enabled; timer delay (%d us).\n",
7591 ha->zio_timer * 100);
7593 icb->firmware_options_2 |= cpu_to_le32(
7594 (uint32_t)ha->zio_mode);
7595 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
7598 /* enable RIDA Format2 */
7599 if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha))
7600 icb->firmware_options_3 |= BIT_0;
7603 ql_log(ql_log_warn, vha, 0x0076,
7604 "NVRAM configuration failed.\n");
7610 qla82xx_restart_isp(scsi_qla_host_t *vha)
7613 struct qla_hw_data *ha = vha->hw;
7614 struct req_que *req = ha->req_q_map[0];
7615 struct rsp_que *rsp = ha->rsp_q_map[0];
7616 struct scsi_qla_host *vp;
7617 unsigned long flags;
7619 status = qla2x00_init_rings(vha);
7621 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
7622 ha->flags.chip_reset_done = 1;
7624 status = qla2x00_fw_ready(vha);
7626 /* Issue a marker after FW becomes ready. */
7627 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
7628 vha->flags.online = 1;
7629 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
7632 /* if no cable then assume it's good */
7633 if ((vha->device_flags & DFLG_NO_CABLE))
7638 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
7640 if (!atomic_read(&vha->loop_down_timer)) {
7642 * Issue marker command only when we are going
7643 * to start the I/O .
7645 vha->marker_needed = 1;
7648 ha->isp_ops->enable_intrs(ha);
7650 ha->isp_abort_cnt = 0;
7651 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
7653 /* Update the firmware version */
7654 status = qla82xx_check_md_needed(vha);
7657 ha->flags.fce_enabled = 1;
7659 fce_calc_size(ha->fce_bufs));
7660 rval = qla2x00_enable_fce_trace(vha,
7661 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
7664 ql_log(ql_log_warn, vha, 0x8001,
7665 "Unable to reinitialize FCE (%d).\n",
7667 ha->flags.fce_enabled = 0;
7672 memset(ha->eft, 0, EFT_SIZE);
7673 rval = qla2x00_enable_eft_trace(vha,
7674 ha->eft_dma, EFT_NUM_BUFFERS);
7676 ql_log(ql_log_warn, vha, 0x8010,
7677 "Unable to reinitialize EFT (%d).\n",
7684 ql_dbg(ql_dbg_taskm, vha, 0x8011,
7685 "qla82xx_restart_isp succeeded.\n");
7687 spin_lock_irqsave(&ha->vport_slock, flags);
7688 list_for_each_entry(vp, &ha->vp_list, list) {
7690 atomic_inc(&vp->vref_count);
7691 spin_unlock_irqrestore(&ha->vport_slock, flags);
7693 qla2x00_vp_abort_isp(vp);
7695 spin_lock_irqsave(&ha->vport_slock, flags);
7696 atomic_dec(&vp->vref_count);
7699 spin_unlock_irqrestore(&ha->vport_slock, flags);
7702 ql_log(ql_log_warn, vha, 0x8016,
7703 "qla82xx_restart_isp **** FAILED ****.\n");
7710 qla81xx_update_fw_options(scsi_qla_host_t *vha)
7712 struct qla_hw_data *ha = vha->hw;
7714 /* Hold status IOCBs until ABTS response received. */
7716 ha->fw_options[3] |= BIT_12;
7718 /* Set Retry FLOGI in case of P2P connection */
7719 if (ha->operating_mode == P2P) {
7720 ha->fw_options[2] |= BIT_3;
7721 ql_dbg(ql_dbg_disc, vha, 0x2103,
7722 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
7723 __func__, ha->fw_options[2]);
7726 /* Move PUREX, ABTS RX & RIDA to ATIOQ */
7727 if (ql2xmvasynctoatio) {
7728 if (qla_tgt_mode_enabled(vha) ||
7729 qla_dual_mode_enabled(vha))
7730 ha->fw_options[2] |= BIT_11;
7732 ha->fw_options[2] &= ~BIT_11;
7735 if (qla_tgt_mode_enabled(vha) ||
7736 qla_dual_mode_enabled(vha)) {
7737 /* FW auto send SCSI status during */
7738 ha->fw_options[1] |= BIT_8;
7739 ha->fw_options[10] |= (u16)SAM_STAT_BUSY << 8;
7741 /* FW perform Exchange validation */
7742 ha->fw_options[2] |= BIT_4;
7744 ha->fw_options[1] &= ~BIT_8;
7745 ha->fw_options[10] &= 0x00ff;
7747 ha->fw_options[2] &= ~BIT_4;
7750 if (ql2xetsenable) {
7751 /* Enable ETS Burst. */
7752 memset(ha->fw_options, 0, sizeof(ha->fw_options));
7753 ha->fw_options[2] |= BIT_9;
7756 ql_dbg(ql_dbg_init, vha, 0x00e9,
7757 "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n",
7758 __func__, ha->fw_options[1], ha->fw_options[2],
7759 ha->fw_options[3], vha->host->active_mode);
7761 qla2x00_set_fw_options(vha, ha->fw_options);
7765 * qla24xx_get_fcp_prio
7766 * Gets the fcp cmd priority value for the logged in port.
7767 * Looks for a match of the port descriptors within
7768 * each of the fcp prio config entries. If a match is found,
7769 * the tag (priority) value is returned.
7772 * vha = scsi host structure pointer.
7773 * fcport = port structure pointer.
7776 * non-zero (if found)
7783 qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
7786 uint8_t pid_match, wwn_match;
7788 uint32_t pid1, pid2;
7789 uint64_t wwn1, wwn2;
7790 struct qla_fcp_prio_entry *pri_entry;
7791 struct qla_hw_data *ha = vha->hw;
7793 if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled)
7797 entries = ha->fcp_prio_cfg->num_entries;
7798 pri_entry = &ha->fcp_prio_cfg->entry[0];
7800 for (i = 0; i < entries; i++) {
7801 pid_match = wwn_match = 0;
7803 if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) {
7808 /* check source pid for a match */
7809 if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) {
7810 pid1 = pri_entry->src_pid & INVALID_PORT_ID;
7811 pid2 = vha->d_id.b24 & INVALID_PORT_ID;
7812 if (pid1 == INVALID_PORT_ID)
7814 else if (pid1 == pid2)
7818 /* check destination pid for a match */
7819 if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) {
7820 pid1 = pri_entry->dst_pid & INVALID_PORT_ID;
7821 pid2 = fcport->d_id.b24 & INVALID_PORT_ID;
7822 if (pid1 == INVALID_PORT_ID)
7824 else if (pid1 == pid2)
7828 /* check source WWN for a match */
7829 if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) {
7830 wwn1 = wwn_to_u64(vha->port_name);
7831 wwn2 = wwn_to_u64(pri_entry->src_wwpn);
7832 if (wwn2 == (uint64_t)-1)
7834 else if (wwn1 == wwn2)
7838 /* check destination WWN for a match */
7839 if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) {
7840 wwn1 = wwn_to_u64(fcport->port_name);
7841 wwn2 = wwn_to_u64(pri_entry->dst_wwpn);
7842 if (wwn2 == (uint64_t)-1)
7844 else if (wwn1 == wwn2)
7848 if (pid_match == 2 || wwn_match == 2) {
7849 /* Found a matching entry */
7850 if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
7851 priority = pri_entry->tag;
7862 * qla24xx_update_fcport_fcp_prio
7863 * Activates fcp priority for the logged in fc port
7866 * vha = scsi host structure pointer.
7867 * fcp = port structure pointer.
7870 * QLA_SUCCESS or QLA_FUNCTION_FAILED
7876 qla24xx_update_fcport_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
7882 if (fcport->port_type != FCT_TARGET ||
7883 fcport->loop_id == FC_NO_LOOP_ID)
7884 return QLA_FUNCTION_FAILED;
7886 priority = qla24xx_get_fcp_prio(vha, fcport);
7888 return QLA_FUNCTION_FAILED;
7890 if (IS_P3P_TYPE(vha->hw)) {
7891 fcport->fcp_prio = priority & 0xf;
7895 ret = qla24xx_set_fcp_prio(vha, fcport->loop_id, priority, mb);
7896 if (ret == QLA_SUCCESS) {
7897 if (fcport->fcp_prio != priority)
7898 ql_dbg(ql_dbg_user, vha, 0x709e,
7899 "Updated FCP_CMND priority - value=%d loop_id=%d "
7900 "port_id=%02x%02x%02x.\n", priority,
7901 fcport->loop_id, fcport->d_id.b.domain,
7902 fcport->d_id.b.area, fcport->d_id.b.al_pa);
7903 fcport->fcp_prio = priority & 0xf;
7905 ql_dbg(ql_dbg_user, vha, 0x704f,
7906 "Unable to update FCP_CMND priority - ret=0x%x for "
7907 "loop_id=%d port_id=%02x%02x%02x.\n", ret, fcport->loop_id,
7908 fcport->d_id.b.domain, fcport->d_id.b.area,
7909 fcport->d_id.b.al_pa);
7914 * qla24xx_update_all_fcp_prio
7915 * Activates fcp priority for all the logged in ports
7918 * ha = adapter block pointer.
7921 * QLA_SUCCESS or QLA_FUNCTION_FAILED
7927 qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha)
7932 ret = QLA_FUNCTION_FAILED;
7933 /* We need to set priority for all logged in ports */
7934 list_for_each_entry(fcport, &vha->vp_fcports, list)
7935 ret = qla24xx_update_fcport_fcp_prio(vha, fcport);
7940 struct qla_qpair *qla2xxx_create_qpair(struct scsi_qla_host *vha, int qos,
7941 int vp_idx, bool startqp)
7946 struct qla_hw_data *ha = vha->hw;
7947 uint16_t qpair_id = 0;
7948 struct qla_qpair *qpair = NULL;
7949 struct qla_msix_entry *msix;
7951 if (!(ha->fw_attributes & BIT_6) || !ha->flags.msix_enabled) {
7952 ql_log(ql_log_warn, vha, 0x00181,
7953 "FW/Driver is not multi-queue capable.\n");
7957 if (ql2xmqsupport) {
7958 qpair = kzalloc(sizeof(struct qla_qpair), GFP_KERNEL);
7959 if (qpair == NULL) {
7960 ql_log(ql_log_warn, vha, 0x0182,
7961 "Failed to allocate memory for queue pair.\n");
7964 memset(qpair, 0, sizeof(struct qla_qpair));
7966 qpair->hw = vha->hw;
7968 qpair->qp_lock_ptr = &qpair->qp_lock;
7969 spin_lock_init(&qpair->qp_lock);
7970 qpair->use_shadow_reg = IS_SHADOW_REG_CAPABLE(ha) ? 1 : 0;
7972 /* Assign available que pair id */
7973 mutex_lock(&ha->mq_lock);
7974 qpair_id = find_first_zero_bit(ha->qpair_qid_map, ha->max_qpairs);
7975 if (ha->num_qpairs >= ha->max_qpairs) {
7976 mutex_unlock(&ha->mq_lock);
7977 ql_log(ql_log_warn, vha, 0x0183,
7978 "No resources to create additional q pair.\n");
7982 set_bit(qpair_id, ha->qpair_qid_map);
7983 ha->queue_pair_map[qpair_id] = qpair;
7984 qpair->id = qpair_id;
7985 qpair->vp_idx = vp_idx;
7986 qpair->fw_started = ha->flags.fw_started;
7987 INIT_LIST_HEAD(&qpair->hints_list);
7988 INIT_LIST_HEAD(&qpair->nvme_done_list);
7989 qpair->chip_reset = ha->base_qpair->chip_reset;
7990 qpair->enable_class_2 = ha->base_qpair->enable_class_2;
7991 qpair->enable_explicit_conf =
7992 ha->base_qpair->enable_explicit_conf;
7994 for (i = 0; i < ha->msix_count; i++) {
7995 msix = &ha->msix_entries[i];
7999 ql_dbg(ql_dbg_multiq, vha, 0xc00f,
8000 "Vector %x selected for qpair\n", msix->vector);
8004 ql_log(ql_log_warn, vha, 0x0184,
8005 "Out of MSI-X vectors!.\n");
8009 qpair->msix->in_use = 1;
8010 list_add_tail(&qpair->qp_list_elem, &vha->qp_list);
8011 qpair->pdev = ha->pdev;
8012 if (IS_QLA27XX(ha) || IS_QLA83XX(ha))
8013 qpair->reqq_start_iocbs = qla_83xx_start_iocbs;
8015 mutex_unlock(&ha->mq_lock);
8017 /* Create response queue first */
8018 rsp_id = qla25xx_create_rsp_que(ha, 0, 0, 0, qpair, startqp);
8020 ql_log(ql_log_warn, vha, 0x0185,
8021 "Failed to create response queue.\n");
8025 qpair->rsp = ha->rsp_q_map[rsp_id];
8027 /* Create request queue */
8028 req_id = qla25xx_create_req_que(ha, 0, vp_idx, 0, rsp_id, qos,
8031 ql_log(ql_log_warn, vha, 0x0186,
8032 "Failed to create request queue.\n");
8036 qpair->req = ha->req_q_map[req_id];
8037 qpair->rsp->req = qpair->req;
8038 qpair->rsp->qpair = qpair;
8039 /* init qpair to this cpu. Will adjust at run time. */
8040 qla_cpu_update(qpair, smp_processor_id());
8042 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
8043 if (ha->fw_attributes & BIT_4)
8044 qpair->difdix_supported = 1;
8047 qpair->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
8048 if (!qpair->srb_mempool) {
8049 ql_log(ql_log_warn, vha, 0xd036,
8050 "Failed to create srb mempool for qpair %d\n",
8055 /* Mark as online */
8058 if (!vha->flags.qpairs_available)
8059 vha->flags.qpairs_available = 1;
8061 ql_dbg(ql_dbg_multiq, vha, 0xc00d,
8062 "Request/Response queue pair created, id %d\n",
8064 ql_dbg(ql_dbg_init, vha, 0x0187,
8065 "Request/Response queue pair created, id %d\n",
8072 qla25xx_delete_rsp_que(vha, qpair->rsp);
8074 mutex_lock(&ha->mq_lock);
8075 qpair->msix->in_use = 0;
8076 list_del(&qpair->qp_list_elem);
8077 if (list_empty(&vha->qp_list))
8078 vha->flags.qpairs_available = 0;
8080 ha->queue_pair_map[qpair_id] = NULL;
8081 clear_bit(qpair_id, ha->qpair_qid_map);
8083 mutex_unlock(&ha->mq_lock);
8089 int qla2xxx_delete_qpair(struct scsi_qla_host *vha, struct qla_qpair *qpair)
8091 int ret = QLA_FUNCTION_FAILED;
8092 struct qla_hw_data *ha = qpair->hw;
8094 qpair->delete_in_progress = 1;
8096 ret = qla25xx_delete_req_que(vha, qpair->req);
8097 if (ret != QLA_SUCCESS)
8100 ret = qla25xx_delete_rsp_que(vha, qpair->rsp);
8101 if (ret != QLA_SUCCESS)
8104 mutex_lock(&ha->mq_lock);
8105 ha->queue_pair_map[qpair->id] = NULL;
8106 clear_bit(qpair->id, ha->qpair_qid_map);
8108 list_del(&qpair->qp_list_elem);
8109 if (list_empty(&vha->qp_list)) {
8110 vha->flags.qpairs_available = 0;
8111 vha->flags.qpairs_req_created = 0;
8112 vha->flags.qpairs_rsp_created = 0;
8114 mempool_destroy(qpair->srb_mempool);
8116 mutex_unlock(&ha->mq_lock);