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 *,
44 static void __qla24xx_handle_gpdb_event(scsi_qla_host_t *, struct event_arg *);
46 /* SRB Extensions ---------------------------------------------------------- */
49 qla2x00_sp_timeout(struct timer_list *t)
51 srb_t *sp = from_timer(sp, t, u.iocb_cmd.timer);
52 struct srb_iocb *iocb;
53 scsi_qla_host_t *vha = sp->vha;
57 spin_lock_irqsave(&vha->hw->hardware_lock, flags);
58 req = vha->hw->req_q_map[0];
59 req->outstanding_cmds[sp->handle] = NULL;
60 iocb = &sp->u.iocb_cmd;
62 if (sp->type != SRB_ELS_DCMD)
64 spin_unlock_irqrestore(&vha->hw->hardware_lock, flags);
68 qla2x00_sp_free(void *ptr)
71 struct srb_iocb *iocb = &sp->u.iocb_cmd;
73 del_timer(&iocb->timer);
77 /* Asynchronous Login/Logout Routines -------------------------------------- */
80 qla2x00_get_async_timeout(struct scsi_qla_host *vha)
83 struct qla_hw_data *ha = vha->hw;
85 /* Firmware should use switch negotiated r_a_tov for timeout. */
86 tmo = ha->r_a_tov / 10 * 2;
88 tmo = FX00_DEF_RATOV * 2;
89 } else if (!IS_FWI2_CAPABLE(ha)) {
91 * Except for earlier ISPs where the timeout is seeded from the
92 * initialization control block.
94 tmo = ha->login_timeout;
100 qla2x00_async_iocb_timeout(void *data)
103 fc_port_t *fcport = sp->fcport;
104 struct srb_iocb *lio = &sp->u.iocb_cmd;
108 ql_dbg(ql_dbg_disc, fcport->vha, 0x2071,
109 "Async-%s timeout - hdl=%x portid=%06x %8phC.\n",
110 sp->name, sp->handle, fcport->d_id.b24, fcport->port_name);
112 fcport->flags &= ~FCF_ASYNC_SENT;
114 pr_info("Async-%s timeout - hdl=%x.\n",
115 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);
133 qlt_logo_completion_handler(fcport, QLA_FUNCTION_TIMEOUT);
135 case SRB_CT_PTHRU_CMD:
141 sp->done(sp, QLA_FUNCTION_TIMEOUT);
147 qla2x00_async_login_sp_done(void *ptr, int res)
150 struct scsi_qla_host *vha = sp->vha;
151 struct srb_iocb *lio = &sp->u.iocb_cmd;
154 ql_dbg(ql_dbg_disc, vha, 0x20dd,
155 "%s %8phC res %d \n", __func__, sp->fcport->port_name, res);
157 sp->fcport->flags &= ~FCF_ASYNC_SENT;
158 if (!test_bit(UNLOADING, &vha->dpc_flags)) {
159 memset(&ea, 0, sizeof(ea));
160 ea.event = FCME_PLOGI_DONE;
161 ea.fcport = sp->fcport;
162 ea.data[0] = lio->u.logio.data[0];
163 ea.data[1] = lio->u.logio.data[1];
164 ea.iop[0] = lio->u.logio.iop[0];
165 ea.iop[1] = lio->u.logio.iop[1];
167 qla2x00_fcport_event_handler(vha, &ea);
174 qla2x00_async_login(struct scsi_qla_host *vha, fc_port_t *fcport,
178 struct srb_iocb *lio;
179 int rval = QLA_FUNCTION_FAILED;
181 if (!vha->flags.online)
184 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
188 fcport->flags |= FCF_ASYNC_SENT;
189 fcport->logout_completed = 0;
191 fcport->disc_state = DSC_LOGIN_PEND;
192 sp->type = SRB_LOGIN_CMD;
194 sp->gen1 = fcport->rscn_gen;
195 sp->gen2 = fcport->login_gen;
196 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
198 lio = &sp->u.iocb_cmd;
199 lio->timeout = qla2x00_async_iocb_timeout;
200 sp->done = qla2x00_async_login_sp_done;
201 lio->u.logio.flags |= SRB_LOGIN_COND_PLOGI;
203 if (fcport->fc4f_nvme)
204 lio->u.logio.flags |= SRB_LOGIN_SKIP_PRLI;
206 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
207 lio->u.logio.flags |= SRB_LOGIN_RETRIED;
208 rval = qla2x00_start_sp(sp);
209 if (rval != QLA_SUCCESS) {
210 fcport->flags &= ~FCF_ASYNC_SENT;
211 fcport->flags |= FCF_LOGIN_NEEDED;
212 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
216 ql_dbg(ql_dbg_disc, vha, 0x2072,
217 "Async-login - %8phC hdl=%x, loopid=%x portid=%02x%02x%02x "
218 "retries=%d.\n", fcport->port_name, sp->handle, fcport->loop_id,
219 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa,
220 fcport->login_retry);
226 fcport->flags &= ~FCF_ASYNC_SENT;
231 qla2x00_async_logout_sp_done(void *ptr, int res)
234 struct srb_iocb *lio = &sp->u.iocb_cmd;
236 sp->fcport->flags &= ~FCF_ASYNC_SENT;
237 if (!test_bit(UNLOADING, &sp->vha->dpc_flags))
238 qla2x00_post_async_logout_done_work(sp->vha, sp->fcport,
244 qla2x00_async_logout(struct scsi_qla_host *vha, fc_port_t *fcport)
247 struct srb_iocb *lio;
250 rval = QLA_FUNCTION_FAILED;
251 fcport->flags |= FCF_ASYNC_SENT;
252 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
256 sp->type = SRB_LOGOUT_CMD;
258 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
260 lio = &sp->u.iocb_cmd;
261 lio->timeout = qla2x00_async_iocb_timeout;
262 sp->done = qla2x00_async_logout_sp_done;
263 rval = qla2x00_start_sp(sp);
264 if (rval != QLA_SUCCESS)
267 ql_dbg(ql_dbg_disc, vha, 0x2070,
268 "Async-logout - hdl=%x loop-id=%x portid=%02x%02x%02x %8phC.\n",
269 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
270 fcport->d_id.b.area, fcport->d_id.b.al_pa,
277 fcport->flags &= ~FCF_ASYNC_SENT;
282 qla2x00_async_prlo_done(struct scsi_qla_host *vha, fc_port_t *fcport,
285 /* Don't re-login in target mode */
286 if (!fcport->tgt_session)
287 qla2x00_mark_device_lost(vha, fcport, 1, 0);
288 qlt_logo_completion_handler(fcport, data[0]);
292 qla2x00_async_prlo_sp_done(void *s, int res)
294 srb_t *sp = (srb_t *)s;
295 struct srb_iocb *lio = &sp->u.iocb_cmd;
296 struct scsi_qla_host *vha = sp->vha;
298 if (!test_bit(UNLOADING, &vha->dpc_flags))
299 qla2x00_post_async_prlo_done_work(sp->fcport->vha, sp->fcport,
305 qla2x00_async_prlo(struct scsi_qla_host *vha, fc_port_t *fcport)
308 struct srb_iocb *lio;
311 rval = QLA_FUNCTION_FAILED;
312 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
316 sp->type = SRB_PRLO_CMD;
318 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
320 lio = &sp->u.iocb_cmd;
321 lio->timeout = qla2x00_async_iocb_timeout;
322 sp->done = qla2x00_async_prlo_sp_done;
323 rval = qla2x00_start_sp(sp);
324 if (rval != QLA_SUCCESS)
327 ql_dbg(ql_dbg_disc, vha, 0x2070,
328 "Async-prlo - hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
329 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
330 fcport->d_id.b.area, fcport->d_id.b.al_pa);
340 void qla24xx_handle_adisc_event(scsi_qla_host_t *vha, struct event_arg *ea)
342 struct fc_port *fcport = ea->fcport;
344 ql_dbg(ql_dbg_disc, vha, 0x20d2,
345 "%s %8phC DS %d LS %d rc %d login %d|%d rscn %d|%d lid %d\n",
346 __func__, fcport->port_name, fcport->disc_state,
347 fcport->fw_login_state, ea->rc, fcport->login_gen, ea->sp->gen2,
348 fcport->rscn_gen, ea->sp->gen1, fcport->loop_id);
350 if (ea->data[0] != MBS_COMMAND_COMPLETE) {
351 ql_dbg(ql_dbg_disc, vha, 0x2066,
352 "%s %8phC: adisc fail: post delete\n",
353 __func__, ea->fcport->port_name);
354 qlt_schedule_sess_for_deletion(ea->fcport, 1);
358 if (ea->fcport->disc_state == DSC_DELETE_PEND)
361 if (ea->sp->gen2 != ea->fcport->login_gen) {
362 /* target side must have changed it. */
363 ql_dbg(ql_dbg_disc, vha, 0x20d3,
364 "%s %8phC generation changed\n",
365 __func__, ea->fcport->port_name);
367 } else if (ea->sp->gen1 != ea->fcport->rscn_gen) {
368 ql_dbg(ql_dbg_disc, vha, 0x20d4, "%s %d %8phC post gidpn\n",
369 __func__, __LINE__, ea->fcport->port_name);
370 qla24xx_post_gidpn_work(vha, ea->fcport);
374 __qla24xx_handle_gpdb_event(vha, ea);
378 qla2x00_async_adisc_sp_done(void *ptr, int res)
381 struct scsi_qla_host *vha = sp->vha;
383 struct srb_iocb *lio = &sp->u.iocb_cmd;
385 ql_dbg(ql_dbg_disc, vha, 0x2066,
386 "Async done-%s res %x %8phC\n",
387 sp->name, res, sp->fcport->port_name);
389 memset(&ea, 0, sizeof(ea));
390 ea.event = FCME_ADISC_DONE;
392 ea.data[0] = lio->u.logio.data[0];
393 ea.data[1] = lio->u.logio.data[1];
394 ea.iop[0] = lio->u.logio.iop[0];
395 ea.iop[1] = lio->u.logio.iop[1];
396 ea.fcport = sp->fcport;
399 qla2x00_fcport_event_handler(vha, &ea);
405 qla2x00_async_adisc(struct scsi_qla_host *vha, fc_port_t *fcport,
409 struct srb_iocb *lio;
412 rval = QLA_FUNCTION_FAILED;
413 fcport->flags |= FCF_ASYNC_SENT;
414 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
418 sp->type = SRB_ADISC_CMD;
420 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
422 lio = &sp->u.iocb_cmd;
423 lio->timeout = qla2x00_async_iocb_timeout;
424 sp->done = qla2x00_async_adisc_sp_done;
425 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
426 lio->u.logio.flags |= SRB_LOGIN_RETRIED;
427 rval = qla2x00_start_sp(sp);
428 if (rval != QLA_SUCCESS)
431 ql_dbg(ql_dbg_disc, vha, 0x206f,
432 "Async-adisc - hdl=%x loopid=%x portid=%06x %8phC.\n",
433 sp->handle, fcport->loop_id, fcport->d_id.b24, fcport->port_name);
439 fcport->flags &= ~FCF_ASYNC_SENT;
440 qla2x00_post_async_adisc_work(vha, fcport, data);
444 static void qla24xx_handle_gnl_done_event(scsi_qla_host_t *vha,
445 struct event_arg *ea)
447 fc_port_t *fcport, *conflict_fcport;
448 struct get_name_list_extended *e;
449 u16 i, n, found = 0, loop_id;
453 u8 current_login_state;
456 ql_dbg(ql_dbg_disc, vha, 0xffff,
457 "%s %8phC DS %d LS rc %d %d login %d|%d rscn %d|%d lid %d\n",
458 __func__, fcport->port_name, fcport->disc_state,
459 fcport->fw_login_state, ea->rc,
460 fcport->login_gen, fcport->last_login_gen,
461 fcport->rscn_gen, fcport->last_rscn_gen, vha->loop_id);
463 if (fcport->disc_state == DSC_DELETE_PEND)
466 if (ea->rc) { /* rval */
467 if (fcport->login_retry == 0) {
468 fcport->login_retry = vha->hw->login_retry_count;
469 ql_dbg(ql_dbg_disc, vha, 0x20de,
470 "GNL failed Port login retry %8phN, retry cnt=%d.\n",
471 fcport->port_name, fcport->login_retry);
476 if (fcport->last_rscn_gen != fcport->rscn_gen) {
477 ql_dbg(ql_dbg_disc, vha, 0x20df,
478 "%s %8phC rscn gen changed rscn %d|%d \n",
479 __func__, fcport->port_name,
480 fcport->last_rscn_gen, fcport->rscn_gen);
481 qla24xx_post_gidpn_work(vha, fcport);
483 } else if (fcport->last_login_gen != fcport->login_gen) {
484 ql_dbg(ql_dbg_disc, vha, 0x20e0,
485 "%s %8phC login gen changed\n",
486 __func__, fcport->port_name);
490 n = ea->data[0] / sizeof(struct get_name_list_extended);
492 ql_dbg(ql_dbg_disc, vha, 0x20e1,
493 "%s %d %8phC n %d %02x%02x%02x lid %d \n",
494 __func__, __LINE__, fcport->port_name, n,
495 fcport->d_id.b.domain, fcport->d_id.b.area,
496 fcport->d_id.b.al_pa, fcport->loop_id);
498 for (i = 0; i < n; i++) {
500 wwn = wwn_to_u64(e->port_name);
502 if (memcmp((u8 *)&wwn, fcport->port_name, WWN_SIZE))
506 id.b.domain = e->port_id[2];
507 id.b.area = e->port_id[1];
508 id.b.al_pa = e->port_id[0];
511 loop_id = le16_to_cpu(e->nport_handle);
512 loop_id = (loop_id & 0x7fff);
514 ql_dbg(ql_dbg_disc, vha, 0x20e2,
515 "%s found %8phC CLS [%d|%d] ID[%02x%02x%02x|%02x%02x%02x] lid[%d|%d]\n",
516 __func__, fcport->port_name,
517 e->current_login_state, fcport->fw_login_state,
518 id.b.domain, id.b.area, id.b.al_pa,
519 fcport->d_id.b.domain, fcport->d_id.b.area,
520 fcport->d_id.b.al_pa, loop_id, fcport->loop_id);
522 if ((id.b24 != fcport->d_id.b24) ||
523 ((fcport->loop_id != FC_NO_LOOP_ID) &&
524 (fcport->loop_id != loop_id))) {
525 ql_dbg(ql_dbg_disc, vha, 0x20e3,
526 "%s %d %8phC post del sess\n",
527 __func__, __LINE__, fcport->port_name);
528 qlt_schedule_sess_for_deletion(fcport, 1);
532 fcport->loop_id = loop_id;
534 wwn = wwn_to_u64(fcport->port_name);
535 qlt_find_sess_invalidate_other(vha, wwn,
536 id, loop_id, &conflict_fcport);
538 if (conflict_fcport) {
540 * Another share fcport share the same loop_id &
541 * nport id. Conflict fcport needs to finish
542 * cleanup before this fcport can proceed to login.
544 conflict_fcport->conflict = fcport;
545 fcport->login_pause = 1;
548 if (fcport->fc4f_nvme)
549 current_login_state = e->current_login_state >> 4;
551 current_login_state = e->current_login_state & 0xf;
553 switch (current_login_state) {
554 case DSC_LS_PRLI_COMP:
555 ql_dbg(ql_dbg_disc, vha, 0x20e4,
556 "%s %d %8phC post gpdb\n",
557 __func__, __LINE__, fcport->port_name);
559 if ((e->prli_svc_param_word_3[0] & BIT_4) == 0)
560 fcport->port_type = FCT_INITIATOR;
562 fcport->port_type = FCT_TARGET;
564 data[0] = data[1] = 0;
565 qla2x00_post_async_adisc_work(vha, fcport, data);
567 case DSC_LS_PORT_UNAVAIL:
569 if (fcport->loop_id == FC_NO_LOOP_ID) {
570 qla2x00_find_new_loop_id(vha, fcport);
571 fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
573 ql_dbg(ql_dbg_disc, vha, 0x20e5,
575 __func__, __LINE__, fcport->port_name);
576 qla24xx_fcport_handle_login(vha, fcport);
582 /* fw has no record of this port */
583 if (fcport->loop_id == FC_NO_LOOP_ID) {
584 qla2x00_find_new_loop_id(vha, fcport);
585 fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
587 for (i = 0; i < n; i++) {
589 id.b.domain = e->port_id[0];
590 id.b.area = e->port_id[1];
591 id.b.al_pa = e->port_id[2];
593 loop_id = le16_to_cpu(e->nport_handle);
595 if (fcport->d_id.b24 == id.b24) {
597 qla2x00_find_fcport_by_wwpn(vha,
600 ql_dbg(ql_dbg_disc, vha, 0x20e6,
601 "%s %d %8phC post del sess\n",
603 conflict_fcport->port_name);
604 qlt_schedule_sess_for_deletion
605 (conflict_fcport, 1);
608 if (fcport->loop_id == loop_id) {
609 /* FW already picked this loop id for another fcport */
610 qla2x00_find_new_loop_id(vha, fcport);
614 qla24xx_fcport_handle_login(vha, fcport);
619 qla24xx_async_gnl_sp_done(void *s, int res)
622 struct scsi_qla_host *vha = sp->vha;
624 struct fc_port *fcport = NULL, *tf;
625 u16 i, n = 0, loop_id;
627 struct get_name_list_extended *e;
632 ql_dbg(ql_dbg_disc, vha, 0x20e7,
633 "Async done-%s res %x mb[1]=%x mb[2]=%x \n",
634 sp->name, res, sp->u.iocb_cmd.u.mbx.in_mb[1],
635 sp->u.iocb_cmd.u.mbx.in_mb[2]);
637 memset(&ea, 0, sizeof(ea));
640 ea.event = FCME_GNL_DONE;
642 if (sp->u.iocb_cmd.u.mbx.in_mb[1] >=
643 sizeof(struct get_name_list_extended)) {
644 n = sp->u.iocb_cmd.u.mbx.in_mb[1] /
645 sizeof(struct get_name_list_extended);
646 ea.data[0] = sp->u.iocb_cmd.u.mbx.in_mb[1]; /* amnt xfered */
649 for (i = 0; i < n; i++) {
651 loop_id = le16_to_cpu(e->nport_handle);
652 /* mask out reserve bit */
653 loop_id = (loop_id & 0x7fff);
654 set_bit(loop_id, vha->hw->loop_id_map);
655 wwn = wwn_to_u64(e->port_name);
657 ql_dbg(ql_dbg_disc + ql_dbg_verbose, vha, 0x20e8,
658 "%s %8phC %02x:%02x:%02x state %d/%d lid %x \n",
659 __func__, (void *)&wwn, e->port_id[2], e->port_id[1],
660 e->port_id[0], e->current_login_state, e->last_login_state,
664 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
669 if (!list_empty(&vha->gnl.fcports))
670 list_splice_init(&vha->gnl.fcports, &h);
672 list_for_each_entry_safe(fcport, tf, &h, gnl_entry) {
673 list_del_init(&fcport->gnl_entry);
674 fcport->flags &= ~FCF_ASYNC_SENT;
677 qla2x00_fcport_event_handler(vha, &ea);
680 /* create new fcport if fw has knowledge of new sessions */
681 for (i = 0; i < n; i++) {
686 wwn = wwn_to_u64(e->port_name);
689 list_for_each_entry_safe(fcport, tf, &vha->vp_fcports, list) {
690 if (!memcmp((u8 *)&wwn, fcport->port_name,
697 id.b.domain = e->port_id[2];
698 id.b.area = e->port_id[1];
699 id.b.al_pa = e->port_id[0];
702 if (!found && wwn && !IS_SW_RESV_ADDR(id)) {
703 ql_dbg(ql_dbg_disc, vha, 0x2065,
704 "%s %d %8phC %06x post new sess\n",
705 __func__, __LINE__, (u8 *)&wwn, id.b24);
706 wwnn = wwn_to_u64(e->node_name);
707 qla24xx_post_newsess_work(vha, &id, (u8 *)&wwn,
708 (u8 *)&wwnn, NULL, FC4_TYPE_UNKNOWN);
712 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
717 int qla24xx_async_gnl(struct scsi_qla_host *vha, fc_port_t *fcport)
720 struct srb_iocb *mbx;
721 int rval = QLA_FUNCTION_FAILED;
725 if (!vha->flags.online)
728 ql_dbg(ql_dbg_disc, vha, 0x20d9,
729 "Async-gnlist WWPN %8phC \n", fcport->port_name);
731 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
732 fcport->flags |= FCF_ASYNC_SENT;
733 fcport->disc_state = DSC_GNL;
734 fcport->last_rscn_gen = fcport->rscn_gen;
735 fcport->last_login_gen = fcport->login_gen;
737 list_add_tail(&fcport->gnl_entry, &vha->gnl.fcports);
739 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
744 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
746 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
749 sp->type = SRB_MB_IOCB;
751 sp->gen1 = fcport->rscn_gen;
752 sp->gen2 = fcport->login_gen;
754 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha)+2);
756 mb = sp->u.iocb_cmd.u.mbx.out_mb;
757 mb[0] = MBC_PORT_NODE_NAME_LIST;
758 mb[1] = BIT_2 | BIT_3;
759 mb[2] = MSW(vha->gnl.ldma);
760 mb[3] = LSW(vha->gnl.ldma);
761 mb[6] = MSW(MSD(vha->gnl.ldma));
762 mb[7] = LSW(MSD(vha->gnl.ldma));
763 mb[8] = vha->gnl.size;
766 mbx = &sp->u.iocb_cmd;
767 mbx->timeout = qla2x00_async_iocb_timeout;
769 sp->done = qla24xx_async_gnl_sp_done;
771 rval = qla2x00_start_sp(sp);
772 if (rval != QLA_SUCCESS)
775 ql_dbg(ql_dbg_disc, vha, 0x20da,
776 "Async-%s - OUT WWPN %8phC hndl %x\n",
777 sp->name, fcport->port_name, sp->handle);
784 fcport->flags &= ~FCF_ASYNC_SENT;
788 int qla24xx_post_gnl_work(struct scsi_qla_host *vha, fc_port_t *fcport)
790 struct qla_work_evt *e;
792 e = qla2x00_alloc_work(vha, QLA_EVT_GNL);
794 return QLA_FUNCTION_FAILED;
796 e->u.fcport.fcport = fcport;
797 return qla2x00_post_work(vha, e);
801 void qla24xx_async_gpdb_sp_done(void *s, int res)
804 struct scsi_qla_host *vha = sp->vha;
805 struct qla_hw_data *ha = vha->hw;
806 fc_port_t *fcport = sp->fcport;
807 u16 *mb = sp->u.iocb_cmd.u.mbx.in_mb;
810 ql_dbg(ql_dbg_disc, vha, 0x20db,
811 "Async done-%s res %x, WWPN %8phC mb[1]=%x mb[2]=%x \n",
812 sp->name, res, fcport->port_name, mb[1], mb[2]);
814 fcport->flags &= ~FCF_ASYNC_SENT;
816 memset(&ea, 0, sizeof(ea));
817 ea.event = FCME_GPDB_DONE;
821 qla2x00_fcport_event_handler(vha, &ea);
823 dma_pool_free(ha->s_dma_pool, sp->u.iocb_cmd.u.mbx.in,
824 sp->u.iocb_cmd.u.mbx.in_dma);
829 static int qla24xx_post_prli_work(struct scsi_qla_host *vha, fc_port_t *fcport)
831 struct qla_work_evt *e;
833 e = qla2x00_alloc_work(vha, QLA_EVT_PRLI);
835 return QLA_FUNCTION_FAILED;
837 e->u.fcport.fcport = fcport;
839 return qla2x00_post_work(vha, e);
843 qla2x00_async_prli_sp_done(void *ptr, int res)
846 struct scsi_qla_host *vha = sp->vha;
847 struct srb_iocb *lio = &sp->u.iocb_cmd;
850 ql_dbg(ql_dbg_disc, vha, 0x2129,
851 "%s %8phC res %d \n", __func__,
852 sp->fcport->port_name, res);
854 sp->fcport->flags &= ~FCF_ASYNC_SENT;
856 if (!test_bit(UNLOADING, &vha->dpc_flags)) {
857 memset(&ea, 0, sizeof(ea));
858 ea.event = FCME_PRLI_DONE;
859 ea.fcport = sp->fcport;
860 ea.data[0] = lio->u.logio.data[0];
861 ea.data[1] = lio->u.logio.data[1];
862 ea.iop[0] = lio->u.logio.iop[0];
863 ea.iop[1] = lio->u.logio.iop[1];
866 qla2x00_fcport_event_handler(vha, &ea);
873 qla24xx_async_prli(struct scsi_qla_host *vha, fc_port_t *fcport)
876 struct srb_iocb *lio;
877 int rval = QLA_FUNCTION_FAILED;
879 if (!vha->flags.online)
882 if (fcport->fw_login_state == DSC_LS_PLOGI_PEND ||
883 fcport->fw_login_state == DSC_LS_PLOGI_COMP ||
884 fcport->fw_login_state == DSC_LS_PRLI_PEND)
887 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
891 fcport->flags |= FCF_ASYNC_SENT;
892 fcport->logout_completed = 0;
894 sp->type = SRB_PRLI_CMD;
896 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
898 lio = &sp->u.iocb_cmd;
899 lio->timeout = qla2x00_async_iocb_timeout;
900 sp->done = qla2x00_async_prli_sp_done;
901 lio->u.logio.flags = 0;
903 if (fcport->fc4f_nvme)
904 lio->u.logio.flags |= SRB_LOGIN_NVME_PRLI;
906 rval = qla2x00_start_sp(sp);
907 if (rval != QLA_SUCCESS) {
908 fcport->flags &= ~FCF_ASYNC_SENT;
909 fcport->flags |= FCF_LOGIN_NEEDED;
910 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
914 ql_dbg(ql_dbg_disc, vha, 0x211b,
915 "Async-prli - %8phC hdl=%x, loopid=%x portid=%06x retries=%d.\n",
916 fcport->port_name, sp->handle, fcport->loop_id,
917 fcport->d_id.b24, fcport->login_retry);
923 fcport->flags &= ~FCF_ASYNC_SENT;
927 int qla24xx_post_gpdb_work(struct scsi_qla_host *vha, fc_port_t *fcport, u8 opt)
929 struct qla_work_evt *e;
931 e = qla2x00_alloc_work(vha, QLA_EVT_GPDB);
933 return QLA_FUNCTION_FAILED;
935 e->u.fcport.fcport = fcport;
936 e->u.fcport.opt = opt;
937 return qla2x00_post_work(vha, e);
940 int qla24xx_async_gpdb(struct scsi_qla_host *vha, fc_port_t *fcport, u8 opt)
943 struct srb_iocb *mbx;
944 int rval = QLA_FUNCTION_FAILED;
947 struct port_database_24xx *pd;
948 struct qla_hw_data *ha = vha->hw;
950 if (!vha->flags.online)
953 fcport->flags |= FCF_ASYNC_SENT;
954 fcport->disc_state = DSC_GPDB;
956 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
960 sp->type = SRB_MB_IOCB;
962 sp->gen1 = fcport->rscn_gen;
963 sp->gen2 = fcport->login_gen;
964 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
966 pd = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
968 ql_log(ql_log_warn, vha, 0xd043,
969 "Failed to allocate port database structure.\n");
973 mb = sp->u.iocb_cmd.u.mbx.out_mb;
974 mb[0] = MBC_GET_PORT_DATABASE;
975 mb[1] = fcport->loop_id;
978 mb[6] = MSW(MSD(pd_dma));
979 mb[7] = LSW(MSD(pd_dma));
983 mbx = &sp->u.iocb_cmd;
984 mbx->timeout = qla2x00_async_iocb_timeout;
985 mbx->u.mbx.in = (void *)pd;
986 mbx->u.mbx.in_dma = pd_dma;
988 sp->done = qla24xx_async_gpdb_sp_done;
990 rval = qla2x00_start_sp(sp);
991 if (rval != QLA_SUCCESS)
994 ql_dbg(ql_dbg_disc, vha, 0x20dc,
995 "Async-%s %8phC hndl %x opt %x\n",
996 sp->name, fcport->port_name, sp->handle, opt);
1002 dma_pool_free(ha->s_dma_pool, pd, pd_dma);
1006 fcport->flags &= ~FCF_ASYNC_SENT;
1007 qla24xx_post_gpdb_work(vha, fcport, opt);
1012 void __qla24xx_handle_gpdb_event(scsi_qla_host_t *vha, struct event_arg *ea)
1014 unsigned long flags;
1016 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1017 ea->fcport->login_gen++;
1018 ea->fcport->deleted = 0;
1019 ea->fcport->logout_on_delete = 1;
1021 if (!ea->fcport->login_succ && !IS_SW_RESV_ADDR(ea->fcport->d_id)) {
1022 vha->fcport_count++;
1023 ea->fcport->login_succ = 1;
1025 if (!IS_IIDMA_CAPABLE(vha->hw) ||
1026 !vha->hw->flags.gpsc_supported) {
1027 ql_dbg(ql_dbg_disc, vha, 0x20d6,
1028 "%s %d %8phC post upd_fcport fcp_cnt %d\n",
1029 __func__, __LINE__, ea->fcport->port_name,
1032 qla24xx_post_upd_fcport_work(vha, ea->fcport);
1034 if (ea->fcport->id_changed) {
1035 ea->fcport->id_changed = 0;
1036 ql_dbg(ql_dbg_disc, vha, 0x20d7,
1037 "%s %d %8phC post gfpnid fcp_cnt %d\n",
1038 __func__, __LINE__, ea->fcport->port_name,
1040 qla24xx_post_gfpnid_work(vha, ea->fcport);
1042 ql_dbg(ql_dbg_disc, vha, 0x20d7,
1043 "%s %d %8phC post gpsc fcp_cnt %d\n",
1044 __func__, __LINE__, ea->fcport->port_name,
1046 qla24xx_post_gpsc_work(vha, ea->fcport);
1049 } else if (ea->fcport->login_succ) {
1051 * We have an existing session. A late RSCN delivery
1052 * must have triggered the session to be re-validate.
1053 * Session is still valid.
1055 ql_dbg(ql_dbg_disc, vha, 0x20d6,
1056 "%s %d %8phC session revalidate success\n",
1057 __func__, __LINE__, ea->fcport->port_name);
1058 ea->fcport->disc_state = DSC_LOGIN_COMPLETE;
1060 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1064 void qla24xx_handle_gpdb_event(scsi_qla_host_t *vha, struct event_arg *ea)
1066 fc_port_t *fcport = ea->fcport;
1067 struct port_database_24xx *pd;
1068 struct srb *sp = ea->sp;
1070 pd = (struct port_database_24xx *)sp->u.iocb_cmd.u.mbx.in;
1072 fcport->flags &= ~FCF_ASYNC_SENT;
1074 ql_dbg(ql_dbg_disc, vha, 0x20d2,
1075 "%s %8phC DS %d LS %d rc %d\n", __func__, fcport->port_name,
1076 fcport->disc_state, pd->current_login_state, ea->rc);
1078 if (fcport->disc_state == DSC_DELETE_PEND)
1081 switch (pd->current_login_state) {
1082 case PDS_PRLI_COMPLETE:
1083 __qla24xx_parse_gpdb(vha, fcport, pd);
1085 case PDS_PLOGI_PENDING:
1086 case PDS_PLOGI_COMPLETE:
1087 case PDS_PRLI_PENDING:
1088 case PDS_PRLI2_PENDING:
1089 ql_dbg(ql_dbg_disc, vha, 0x20d5, "%s %d %8phC relogin needed\n",
1090 __func__, __LINE__, fcport->port_name);
1091 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1093 case PDS_LOGO_PENDING:
1094 case PDS_PORT_UNAVAILABLE:
1096 ql_dbg(ql_dbg_disc, vha, 0x20d5, "%s %d %8phC post del sess\n",
1097 __func__, __LINE__, fcport->port_name);
1098 qlt_schedule_sess_for_deletion_lock(fcport);
1101 __qla24xx_handle_gpdb_event(vha, ea);
1104 static void qla_chk_n2n_b4_login(struct scsi_qla_host *vha, fc_port_t *fcport)
1108 if (qla_tgt_mode_enabled(vha))
1111 if (qla_dual_mode_enabled(vha)) {
1112 if (N2N_TOPO(vha->hw)) {
1115 mywwn = wwn_to_u64(vha->port_name);
1116 wwn = wwn_to_u64(fcport->port_name);
1119 else if ((fcport->fw_login_state == DSC_LS_PLOGI_COMP)
1120 && time_after_eq(jiffies,
1121 fcport->plogi_nack_done_deadline))
1127 /* initiator mode */
1132 ql_dbg(ql_dbg_disc, vha, 0x20bf,
1133 "%s %d %8phC post login\n",
1134 __func__, __LINE__, fcport->port_name);
1135 fcport->disc_state = DSC_LOGIN_PEND;
1136 qla2x00_post_async_login_work(vha, fcport, NULL);
1140 int qla24xx_fcport_handle_login(struct scsi_qla_host *vha, fc_port_t *fcport)
1145 ql_dbg(ql_dbg_disc, vha, 0x20d8,
1146 "%s %8phC DS %d LS %d P %d fl %x confl %p rscn %d|%d login %d retry %d lid %d scan %d\n",
1147 __func__, fcport->port_name, fcport->disc_state,
1148 fcport->fw_login_state, fcport->login_pause, fcport->flags,
1149 fcport->conflict, fcport->last_rscn_gen, fcport->rscn_gen,
1150 fcport->login_gen, fcport->login_retry,
1151 fcport->loop_id, fcport->scan_state);
1153 if (fcport->login_retry == 0)
1156 if (fcport->scan_state != QLA_FCPORT_FOUND)
1159 if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
1160 (fcport->fw_login_state == DSC_LS_PRLI_PEND))
1163 if (fcport->fw_login_state == DSC_LS_PLOGI_COMP) {
1164 if (time_before_eq(jiffies, fcport->plogi_nack_done_deadline)) {
1165 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1170 /* for pure Target Mode. Login will not be initiated */
1171 if (vha->host->active_mode == MODE_TARGET)
1174 if (fcport->flags & FCF_ASYNC_SENT) {
1175 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1179 fcport->login_retry--;
1181 switch (fcport->disc_state) {
1183 wwn = wwn_to_u64(fcport->node_name);
1185 ql_dbg(ql_dbg_disc, vha, 0xffff,
1186 "%s %d %8phC post GNNID\n",
1187 __func__, __LINE__, fcport->port_name);
1188 qla24xx_post_gnnid_work(vha, fcport);
1189 } else if (fcport->loop_id == FC_NO_LOOP_ID) {
1190 ql_dbg(ql_dbg_disc, vha, 0x20bd,
1191 "%s %d %8phC post gnl\n",
1192 __func__, __LINE__, fcport->port_name);
1193 qla24xx_post_gnl_work(vha, fcport);
1195 qla_chk_n2n_b4_login(vha, fcport);
1200 if (fcport->login_pause) {
1201 fcport->last_rscn_gen = fcport->rscn_gen;
1202 fcport->last_login_gen = fcport->login_gen;
1203 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1207 qla_chk_n2n_b4_login(vha, fcport);
1210 case DSC_LOGIN_FAILED:
1211 ql_dbg(ql_dbg_disc, vha, 0x20d0,
1212 "%s %d %8phC post gidpn\n",
1213 __func__, __LINE__, fcport->port_name);
1214 if (N2N_TOPO(vha->hw))
1215 qla_chk_n2n_b4_login(vha, fcport);
1217 qla24xx_post_gidpn_work(vha, fcport);
1220 case DSC_LOGIN_COMPLETE:
1221 /* recheck login state */
1222 ql_dbg(ql_dbg_disc, vha, 0x20d1,
1223 "%s %d %8phC post adisc\n",
1224 __func__, __LINE__, fcport->port_name);
1225 data[0] = data[1] = 0;
1226 qla2x00_post_async_adisc_work(vha, fcport, data);
1237 void qla24xx_handle_rscn_event(fc_port_t *fcport, struct event_arg *ea)
1241 ql_dbg(ql_dbg_disc, fcport->vha, 0x210c,
1242 "%s %8phC DS %d LS %d\n",
1243 __func__, fcport->port_name, fcport->disc_state,
1244 fcport->fw_login_state);
1246 if (fcport->flags & FCF_ASYNC_SENT)
1249 switch (fcport->disc_state) {
1251 case DSC_LOGIN_COMPLETE:
1252 qla24xx_post_gpnid_work(fcport->vha, &ea->id);
1259 int qla24xx_post_newsess_work(struct scsi_qla_host *vha, port_id_t *id,
1260 u8 *port_name, u8 *node_name, void *pla, u8 fc4_type)
1262 struct qla_work_evt *e;
1263 e = qla2x00_alloc_work(vha, QLA_EVT_NEW_SESS);
1265 return QLA_FUNCTION_FAILED;
1267 e->u.new_sess.id = *id;
1268 e->u.new_sess.pla = pla;
1269 e->u.new_sess.fc4_type = fc4_type;
1270 memcpy(e->u.new_sess.port_name, port_name, WWN_SIZE);
1272 memcpy(e->u.new_sess.node_name, node_name, WWN_SIZE);
1274 return qla2x00_post_work(vha, e);
1278 void qla24xx_handle_relogin_event(scsi_qla_host_t *vha,
1279 struct event_arg *ea)
1281 fc_port_t *fcport = ea->fcport;
1283 ql_dbg(ql_dbg_disc, vha, 0x2102,
1284 "%s %8phC DS %d LS %d P %d del %d cnfl %p rscn %d|%d login %d|%d fl %x\n",
1285 __func__, fcport->port_name, fcport->disc_state,
1286 fcport->fw_login_state, fcport->login_pause,
1287 fcport->deleted, fcport->conflict,
1288 fcport->last_rscn_gen, fcport->rscn_gen,
1289 fcport->last_login_gen, fcport->login_gen,
1292 if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
1293 (fcport->fw_login_state == DSC_LS_PRLI_PEND))
1296 if (fcport->fw_login_state == DSC_LS_PLOGI_COMP) {
1297 if (time_before_eq(jiffies, fcport->plogi_nack_done_deadline)) {
1298 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1303 if (fcport->flags & FCF_ASYNC_SENT) {
1304 fcport->login_retry++;
1305 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1309 if (fcport->disc_state == DSC_DELETE_PEND) {
1310 fcport->login_retry++;
1314 if (fcport->last_rscn_gen != fcport->rscn_gen) {
1315 ql_dbg(ql_dbg_disc, vha, 0x20e9, "%s %d %8phC post gidpn\n",
1316 __func__, __LINE__, fcport->port_name);
1318 qla24xx_post_gidpn_work(vha, fcport);
1322 qla24xx_fcport_handle_login(vha, fcport);
1325 void qla2x00_fcport_event_handler(scsi_qla_host_t *vha, struct event_arg *ea)
1328 uint32_t id = 0, mask, rid;
1329 unsigned long flags;
1331 switch (ea->event) {
1333 case FCME_GIDPN_DONE:
1334 case FCME_GPSC_DONE:
1335 case FCME_GPNID_DONE:
1336 case FCME_GNNID_DONE:
1337 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) ||
1338 test_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags))
1345 switch (ea->event) {
1347 if (test_bit(UNLOADING, &vha->dpc_flags))
1350 qla24xx_handle_relogin_event(vha, ea);
1353 if (test_bit(UNLOADING, &vha->dpc_flags))
1355 switch (ea->id.b.rsvd_1) {
1356 case RSCN_PORT_ADDR:
1357 spin_lock_irqsave(&vha->work_lock, flags);
1358 if (vha->scan.scan_flags == 0) {
1359 ql_dbg(ql_dbg_disc, vha, 0xffff,
1360 "%s: schedule\n", __func__);
1361 vha->scan.scan_flags |= SF_QUEUED;
1362 schedule_delayed_work(&vha->scan.scan_work, 5);
1364 spin_unlock_irqrestore(&vha->work_lock, flags);
1367 case RSCN_AREA_ADDR:
1369 if (ea->id.b.rsvd_1 == RSCN_AREA_ADDR) {
1371 ql_dbg(ql_dbg_async, vha, 0x5044,
1372 "RSCN: Area 0x%06x was affected\n",
1376 ql_dbg(ql_dbg_async, vha, 0x507a,
1377 "RSCN: Domain 0x%06x was affected\n",
1381 rid = ea->id.b24 & mask;
1382 list_for_each_entry_safe(f, tf, &vha->vp_fcports,
1384 id = f->d_id.b24 & mask;
1387 qla24xx_handle_rscn_event(f, ea);
1393 ql_log(ql_log_warn, vha, 0xd045,
1394 "RSCN: Fabric was affected. Addr format %d\n",
1396 qla2x00_mark_all_devices_lost(vha, 1);
1397 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
1398 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
1401 case FCME_GIDPN_DONE:
1402 qla24xx_handle_gidpn_event(vha, ea);
1405 qla24xx_handle_gnl_done_event(vha, ea);
1407 case FCME_GPSC_DONE:
1408 qla24xx_handle_gpsc_event(vha, ea);
1410 case FCME_PLOGI_DONE: /* Initiator side sent LLIOCB */
1411 qla24xx_handle_plogi_done_event(vha, ea);
1413 case FCME_PRLI_DONE:
1414 qla24xx_handle_prli_done_event(vha, ea);
1416 case FCME_GPDB_DONE:
1417 qla24xx_handle_gpdb_event(vha, ea);
1419 case FCME_GPNID_DONE:
1420 qla24xx_handle_gpnid_event(vha, ea);
1422 case FCME_GFFID_DONE:
1423 qla24xx_handle_gffid_event(vha, ea);
1425 case FCME_ADISC_DONE:
1426 qla24xx_handle_adisc_event(vha, ea);
1428 case FCME_GNNID_DONE:
1429 qla24xx_handle_gnnid_event(vha, ea);
1431 case FCME_GFPNID_DONE:
1432 qla24xx_handle_gfpnid_event(vha, ea);
1441 qla2x00_tmf_iocb_timeout(void *data)
1444 struct srb_iocb *tmf = &sp->u.iocb_cmd;
1446 tmf->u.tmf.comp_status = CS_TIMEOUT;
1447 complete(&tmf->u.tmf.comp);
1451 qla2x00_tmf_sp_done(void *ptr, int res)
1454 struct srb_iocb *tmf = &sp->u.iocb_cmd;
1456 complete(&tmf->u.tmf.comp);
1460 qla2x00_async_tm_cmd(fc_port_t *fcport, uint32_t flags, uint32_t lun,
1463 struct scsi_qla_host *vha = fcport->vha;
1464 struct srb_iocb *tm_iocb;
1466 int rval = QLA_FUNCTION_FAILED;
1468 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1472 tm_iocb = &sp->u.iocb_cmd;
1473 sp->type = SRB_TM_CMD;
1475 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha));
1476 tm_iocb->u.tmf.flags = flags;
1477 tm_iocb->u.tmf.lun = lun;
1478 tm_iocb->u.tmf.data = tag;
1479 sp->done = qla2x00_tmf_sp_done;
1480 tm_iocb->timeout = qla2x00_tmf_iocb_timeout;
1481 init_completion(&tm_iocb->u.tmf.comp);
1483 rval = qla2x00_start_sp(sp);
1484 if (rval != QLA_SUCCESS)
1487 ql_dbg(ql_dbg_taskm, vha, 0x802f,
1488 "Async-tmf hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
1489 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
1490 fcport->d_id.b.area, fcport->d_id.b.al_pa);
1492 wait_for_completion(&tm_iocb->u.tmf.comp);
1494 rval = tm_iocb->u.tmf.comp_status == CS_COMPLETE ?
1495 QLA_SUCCESS : QLA_FUNCTION_FAILED;
1497 if ((rval != QLA_SUCCESS) || tm_iocb->u.tmf.data) {
1498 ql_dbg(ql_dbg_taskm, vha, 0x8030,
1499 "TM IOCB failed (%x).\n", rval);
1502 if (!test_bit(UNLOADING, &vha->dpc_flags) && !IS_QLAFX00(vha->hw)) {
1503 flags = tm_iocb->u.tmf.flags;
1504 lun = (uint16_t)tm_iocb->u.tmf.lun;
1506 /* Issue Marker IOCB */
1507 qla2x00_marker(vha, vha->hw->req_q_map[0],
1508 vha->hw->rsp_q_map[0], sp->fcport->loop_id, lun,
1509 flags == TCF_LUN_RESET ? MK_SYNC_ID_LUN : MK_SYNC_ID);
1519 qla24xx_abort_iocb_timeout(void *data)
1522 struct srb_iocb *abt = &sp->u.iocb_cmd;
1524 abt->u.abt.comp_status = CS_TIMEOUT;
1525 complete(&abt->u.abt.comp);
1529 qla24xx_abort_sp_done(void *ptr, int res)
1532 struct srb_iocb *abt = &sp->u.iocb_cmd;
1534 complete(&abt->u.abt.comp);
1538 qla24xx_async_abort_cmd(srb_t *cmd_sp)
1540 scsi_qla_host_t *vha = cmd_sp->vha;
1541 fc_port_t *fcport = cmd_sp->fcport;
1542 struct srb_iocb *abt_iocb;
1544 int rval = QLA_FUNCTION_FAILED;
1546 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1550 abt_iocb = &sp->u.iocb_cmd;
1551 sp->type = SRB_ABT_CMD;
1553 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha));
1554 abt_iocb->u.abt.cmd_hndl = cmd_sp->handle;
1555 sp->done = qla24xx_abort_sp_done;
1556 abt_iocb->timeout = qla24xx_abort_iocb_timeout;
1557 init_completion(&abt_iocb->u.abt.comp);
1559 rval = qla2x00_start_sp(sp);
1560 if (rval != QLA_SUCCESS)
1563 ql_dbg(ql_dbg_async, vha, 0x507c,
1564 "Abort command issued - hdl=%x, target_id=%x\n",
1565 cmd_sp->handle, fcport->tgt_id);
1567 wait_for_completion(&abt_iocb->u.abt.comp);
1569 rval = abt_iocb->u.abt.comp_status == CS_COMPLETE ?
1570 QLA_SUCCESS : QLA_FUNCTION_FAILED;
1579 qla24xx_async_abort_command(srb_t *sp)
1581 unsigned long flags = 0;
1584 fc_port_t *fcport = sp->fcport;
1585 struct scsi_qla_host *vha = fcport->vha;
1586 struct qla_hw_data *ha = vha->hw;
1587 struct req_que *req = vha->req;
1589 spin_lock_irqsave(&ha->hardware_lock, flags);
1590 for (handle = 1; handle < req->num_outstanding_cmds; handle++) {
1591 if (req->outstanding_cmds[handle] == sp)
1594 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1595 if (handle == req->num_outstanding_cmds) {
1596 /* Command not found. */
1597 return QLA_FUNCTION_FAILED;
1599 if (sp->type == SRB_FXIOCB_DCMD)
1600 return qlafx00_fx_disc(vha, &vha->hw->mr.fcport,
1601 FXDISC_ABORT_IOCTL);
1603 return qla24xx_async_abort_cmd(sp);
1607 qla24xx_handle_prli_done_event(struct scsi_qla_host *vha, struct event_arg *ea)
1609 switch (ea->data[0]) {
1610 case MBS_COMMAND_COMPLETE:
1611 ql_dbg(ql_dbg_disc, vha, 0x2118,
1612 "%s %d %8phC post gpdb\n",
1613 __func__, __LINE__, ea->fcport->port_name);
1615 ea->fcport->chip_reset = vha->hw->base_qpair->chip_reset;
1616 ea->fcport->logout_on_delete = 1;
1617 qla24xx_post_gpdb_work(vha, ea->fcport, 0);
1620 if (ea->fcport->n2n_flag) {
1621 ql_dbg(ql_dbg_disc, vha, 0x2118,
1622 "%s %d %8phC post fc4 prli\n",
1623 __func__, __LINE__, ea->fcport->port_name);
1624 ea->fcport->fc4f_nvme = 0;
1625 ea->fcport->n2n_flag = 0;
1626 qla24xx_post_prli_work(vha, ea->fcport);
1628 ql_dbg(ql_dbg_disc, vha, 0x2119,
1629 "%s %d %8phC unhandle event of %x\n",
1630 __func__, __LINE__, ea->fcport->port_name, ea->data[0]);
1636 qla24xx_handle_plogi_done_event(struct scsi_qla_host *vha, struct event_arg *ea)
1638 port_id_t cid; /* conflict Nport id */
1640 struct fc_port *conflict_fcport;
1641 unsigned long flags;
1642 struct fc_port *fcport = ea->fcport;
1644 ql_dbg(ql_dbg_disc, vha, 0xffff,
1645 "%s %8phC DS %d LS %d rc %d login %d|%d rscn %d|%d data %x|%x iop %x|%x\n",
1646 __func__, fcport->port_name, fcport->disc_state,
1647 fcport->fw_login_state, ea->rc, ea->sp->gen2, fcport->login_gen,
1648 ea->sp->gen2, fcport->rscn_gen|ea->sp->gen1,
1649 ea->data[0], ea->data[1], ea->iop[0], ea->iop[1]);
1651 if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
1652 (fcport->fw_login_state == DSC_LS_PRLI_PEND)) {
1653 ql_dbg(ql_dbg_disc, vha, 0x20ea,
1654 "%s %d %8phC Remote is trying to login\n",
1655 __func__, __LINE__, fcport->port_name);
1659 if (fcport->disc_state == DSC_DELETE_PEND)
1662 if (ea->sp->gen2 != fcport->login_gen) {
1663 /* target side must have changed it. */
1664 ql_dbg(ql_dbg_disc, vha, 0x20d3,
1665 "%s %8phC generation changed\n",
1666 __func__, fcport->port_name);
1667 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1669 } else if (ea->sp->gen1 != fcport->rscn_gen) {
1670 ql_dbg(ql_dbg_disc, vha, 0x20d4, "%s %d %8phC post gidpn\n",
1671 __func__, __LINE__, fcport->port_name);
1672 qla24xx_post_gidpn_work(vha, fcport);
1676 switch (ea->data[0]) {
1677 case MBS_COMMAND_COMPLETE:
1679 * Driver must validate login state - If PRLI not complete,
1680 * force a relogin attempt via implicit LOGO, PLOGI, and PRLI
1683 if (ea->fcport->fc4f_nvme) {
1684 ql_dbg(ql_dbg_disc, vha, 0x2117,
1685 "%s %d %8phC post prli\n",
1686 __func__, __LINE__, ea->fcport->port_name);
1687 qla24xx_post_prli_work(vha, ea->fcport);
1689 ql_dbg(ql_dbg_disc, vha, 0x20ea,
1690 "%s %d %8phC LoopID 0x%x in use with %06x. post gnl\n",
1691 __func__, __LINE__, ea->fcport->port_name,
1692 ea->fcport->loop_id, ea->fcport->d_id.b24);
1694 set_bit(ea->fcport->loop_id, vha->hw->loop_id_map);
1695 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1696 ea->fcport->loop_id = FC_NO_LOOP_ID;
1697 ea->fcport->chip_reset = vha->hw->base_qpair->chip_reset;
1698 ea->fcport->logout_on_delete = 1;
1699 ea->fcport->send_els_logo = 0;
1700 ea->fcport->fw_login_state = DSC_LS_PRLI_COMP;
1701 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1703 qla24xx_post_gpdb_work(vha, ea->fcport, 0);
1706 case MBS_COMMAND_ERROR:
1707 ql_dbg(ql_dbg_disc, vha, 0x20eb, "%s %d %8phC cmd error %x\n",
1708 __func__, __LINE__, ea->fcport->port_name, ea->data[1]);
1710 ea->fcport->flags &= ~FCF_ASYNC_SENT;
1711 ea->fcport->disc_state = DSC_LOGIN_FAILED;
1712 if (ea->data[1] & QLA_LOGIO_LOGIN_RETRIED)
1713 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1715 qla2x00_mark_device_lost(vha, ea->fcport, 1, 0);
1717 case MBS_LOOP_ID_USED:
1718 /* data[1] = IO PARAM 1 = nport ID */
1719 cid.b.domain = (ea->iop[1] >> 16) & 0xff;
1720 cid.b.area = (ea->iop[1] >> 8) & 0xff;
1721 cid.b.al_pa = ea->iop[1] & 0xff;
1724 ql_dbg(ql_dbg_disc, vha, 0x20ec,
1725 "%s %d %8phC LoopID 0x%x in use post gnl\n",
1726 __func__, __LINE__, ea->fcport->port_name,
1727 ea->fcport->loop_id);
1729 if (IS_SW_RESV_ADDR(cid)) {
1730 set_bit(ea->fcport->loop_id, vha->hw->loop_id_map);
1731 ea->fcport->loop_id = FC_NO_LOOP_ID;
1733 qla2x00_clear_loop_id(ea->fcport);
1735 qla24xx_post_gnl_work(vha, ea->fcport);
1737 case MBS_PORT_ID_USED:
1738 ql_dbg(ql_dbg_disc, vha, 0x20ed,
1739 "%s %d %8phC NPortId %02x%02x%02x inuse post gidpn\n",
1740 __func__, __LINE__, ea->fcport->port_name,
1741 ea->fcport->d_id.b.domain, ea->fcport->d_id.b.area,
1742 ea->fcport->d_id.b.al_pa);
1744 lid = ea->iop[1] & 0xffff;
1745 qlt_find_sess_invalidate_other(vha,
1746 wwn_to_u64(ea->fcport->port_name),
1747 ea->fcport->d_id, lid, &conflict_fcport);
1749 if (conflict_fcport) {
1751 * Another fcport share the same loop_id/nport id.
1752 * Conflict fcport needs to finish cleanup before this
1753 * fcport can proceed to login.
1755 conflict_fcport->conflict = ea->fcport;
1756 ea->fcport->login_pause = 1;
1758 ql_dbg(ql_dbg_disc, vha, 0x20ed,
1759 "%s %d %8phC NPortId %06x inuse with loopid 0x%x. post gidpn\n",
1760 __func__, __LINE__, ea->fcport->port_name,
1761 ea->fcport->d_id.b24, lid);
1762 qla2x00_clear_loop_id(ea->fcport);
1763 qla24xx_post_gidpn_work(vha, ea->fcport);
1765 ql_dbg(ql_dbg_disc, vha, 0x20ed,
1766 "%s %d %8phC NPortId %06x inuse with loopid 0x%x. sched delete\n",
1767 __func__, __LINE__, ea->fcport->port_name,
1768 ea->fcport->d_id.b24, lid);
1770 qla2x00_clear_loop_id(ea->fcport);
1771 set_bit(lid, vha->hw->loop_id_map);
1772 ea->fcport->loop_id = lid;
1773 ea->fcport->keep_nport_handle = 0;
1774 qlt_schedule_sess_for_deletion(ea->fcport, false);
1782 qla2x00_async_logout_done(struct scsi_qla_host *vha, fc_port_t *fcport,
1785 qla2x00_mark_device_lost(vha, fcport, 1, 0);
1786 qlt_logo_completion_handler(fcport, data[0]);
1787 fcport->login_gen++;
1792 qla2x00_async_adisc_done(struct scsi_qla_host *vha, fc_port_t *fcport,
1795 if (data[0] == MBS_COMMAND_COMPLETE) {
1796 qla2x00_update_fcport(vha, fcport);
1802 fcport->flags &= ~FCF_ASYNC_SENT;
1803 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
1804 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1806 qla2x00_mark_device_lost(vha, fcport, 1, 0);
1811 /****************************************************************************/
1812 /* QLogic ISP2x00 Hardware Support Functions. */
1813 /****************************************************************************/
1816 qla83xx_nic_core_fw_load(scsi_qla_host_t *vha)
1818 int rval = QLA_SUCCESS;
1819 struct qla_hw_data *ha = vha->hw;
1820 uint32_t idc_major_ver, idc_minor_ver;
1823 qla83xx_idc_lock(vha, 0);
1825 /* SV: TODO: Assign initialization timeout from
1826 * flash-info / other param
1828 ha->fcoe_dev_init_timeout = QLA83XX_IDC_INITIALIZATION_TIMEOUT;
1829 ha->fcoe_reset_timeout = QLA83XX_IDC_RESET_ACK_TIMEOUT;
1831 /* Set our fcoe function presence */
1832 if (__qla83xx_set_drv_presence(vha) != QLA_SUCCESS) {
1833 ql_dbg(ql_dbg_p3p, vha, 0xb077,
1834 "Error while setting DRV-Presence.\n");
1835 rval = QLA_FUNCTION_FAILED;
1839 /* Decide the reset ownership */
1840 qla83xx_reset_ownership(vha);
1843 * On first protocol driver load:
1844 * Init-Owner: Set IDC-Major-Version and Clear IDC-Lock-Recovery
1846 * Others: Check compatibility with current IDC Major version.
1848 qla83xx_rd_reg(vha, QLA83XX_IDC_MAJOR_VERSION, &idc_major_ver);
1849 if (ha->flags.nic_core_reset_owner) {
1850 /* Set IDC Major version */
1851 idc_major_ver = QLA83XX_SUPP_IDC_MAJOR_VERSION;
1852 qla83xx_wr_reg(vha, QLA83XX_IDC_MAJOR_VERSION, idc_major_ver);
1854 /* Clearing IDC-Lock-Recovery register */
1855 qla83xx_wr_reg(vha, QLA83XX_IDC_LOCK_RECOVERY, 0);
1856 } else if (idc_major_ver != QLA83XX_SUPP_IDC_MAJOR_VERSION) {
1858 * Clear further IDC participation if we are not compatible with
1859 * the current IDC Major Version.
1861 ql_log(ql_log_warn, vha, 0xb07d,
1862 "Failing load, idc_major_ver=%d, expected_major_ver=%d.\n",
1863 idc_major_ver, QLA83XX_SUPP_IDC_MAJOR_VERSION);
1864 __qla83xx_clear_drv_presence(vha);
1865 rval = QLA_FUNCTION_FAILED;
1868 /* Each function sets its supported Minor version. */
1869 qla83xx_rd_reg(vha, QLA83XX_IDC_MINOR_VERSION, &idc_minor_ver);
1870 idc_minor_ver |= (QLA83XX_SUPP_IDC_MINOR_VERSION << (ha->portnum * 2));
1871 qla83xx_wr_reg(vha, QLA83XX_IDC_MINOR_VERSION, idc_minor_ver);
1873 if (ha->flags.nic_core_reset_owner) {
1874 memset(config, 0, sizeof(config));
1875 if (!qla81xx_get_port_config(vha, config))
1876 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
1880 rval = qla83xx_idc_state_handler(vha);
1883 qla83xx_idc_unlock(vha, 0);
1889 * qla2x00_initialize_adapter
1893 * ha = adapter block pointer.
1899 qla2x00_initialize_adapter(scsi_qla_host_t *vha)
1902 struct qla_hw_data *ha = vha->hw;
1903 struct req_que *req = ha->req_q_map[0];
1905 memset(&vha->qla_stats, 0, sizeof(vha->qla_stats));
1906 memset(&vha->fc_host_stat, 0, sizeof(vha->fc_host_stat));
1908 /* Clear adapter flags. */
1909 vha->flags.online = 0;
1910 ha->flags.chip_reset_done = 0;
1911 vha->flags.reset_active = 0;
1912 ha->flags.pci_channel_io_perm_failure = 0;
1913 ha->flags.eeh_busy = 0;
1914 vha->qla_stats.jiffies_at_last_reset = get_jiffies_64();
1915 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
1916 atomic_set(&vha->loop_state, LOOP_DOWN);
1917 vha->device_flags = DFLG_NO_CABLE;
1919 vha->flags.management_server_logged_in = 0;
1920 vha->marker_needed = 0;
1921 ha->isp_abort_cnt = 0;
1922 ha->beacon_blink_led = 0;
1924 set_bit(0, ha->req_qid_map);
1925 set_bit(0, ha->rsp_qid_map);
1927 ql_dbg(ql_dbg_init, vha, 0x0040,
1928 "Configuring PCI space...\n");
1929 rval = ha->isp_ops->pci_config(vha);
1931 ql_log(ql_log_warn, vha, 0x0044,
1932 "Unable to configure PCI space.\n");
1936 ha->isp_ops->reset_chip(vha);
1938 rval = qla2xxx_get_flash_info(vha);
1940 ql_log(ql_log_fatal, vha, 0x004f,
1941 "Unable to validate FLASH data.\n");
1945 if (IS_QLA8044(ha)) {
1946 qla8044_read_reset_template(vha);
1948 /* NOTE: If ql2xdontresethba==1, set IDC_CTRL DONTRESET_BIT0.
1949 * If DONRESET_BIT0 is set, drivers should not set dev_state
1950 * to NEED_RESET. But if NEED_RESET is set, drivers should
1951 * should honor the reset. */
1952 if (ql2xdontresethba == 1)
1953 qla8044_set_idc_dontreset(vha);
1956 ha->isp_ops->get_flash_version(vha, req->ring);
1957 ql_dbg(ql_dbg_init, vha, 0x0061,
1958 "Configure NVRAM parameters...\n");
1960 ha->isp_ops->nvram_config(vha);
1962 if (ha->flags.disable_serdes) {
1963 /* Mask HBA via NVRAM settings? */
1964 ql_log(ql_log_info, vha, 0x0077,
1965 "Masking HBA WWPN %8phN (via NVRAM).\n", vha->port_name);
1966 return QLA_FUNCTION_FAILED;
1969 ql_dbg(ql_dbg_init, vha, 0x0078,
1970 "Verifying loaded RISC code...\n");
1972 if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) {
1973 rval = ha->isp_ops->chip_diag(vha);
1976 rval = qla2x00_setup_chip(vha);
1981 if (IS_QLA84XX(ha)) {
1982 ha->cs84xx = qla84xx_get_chip(vha);
1984 ql_log(ql_log_warn, vha, 0x00d0,
1985 "Unable to configure ISP84XX.\n");
1986 return QLA_FUNCTION_FAILED;
1990 if (qla_ini_mode_enabled(vha) || qla_dual_mode_enabled(vha))
1991 rval = qla2x00_init_rings(vha);
1993 ha->flags.chip_reset_done = 1;
1995 if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) {
1996 /* Issue verify 84xx FW IOCB to complete 84xx initialization */
1997 rval = qla84xx_init_chip(vha);
1998 if (rval != QLA_SUCCESS) {
1999 ql_log(ql_log_warn, vha, 0x00d4,
2000 "Unable to initialize ISP84XX.\n");
2001 qla84xx_put_chip(vha);
2005 /* Load the NIC Core f/w if we are the first protocol driver. */
2006 if (IS_QLA8031(ha)) {
2007 rval = qla83xx_nic_core_fw_load(vha);
2009 ql_log(ql_log_warn, vha, 0x0124,
2010 "Error in initializing NIC Core f/w.\n");
2013 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha))
2014 qla24xx_read_fcp_prio_cfg(vha);
2016 if (IS_P3P_TYPE(ha))
2017 qla82xx_set_driver_version(vha, QLA2XXX_VERSION);
2019 qla25xx_set_driver_version(vha, QLA2XXX_VERSION);
2025 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
2028 * Returns 0 on success.
2031 qla2100_pci_config(scsi_qla_host_t *vha)
2034 unsigned long flags;
2035 struct qla_hw_data *ha = vha->hw;
2036 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2038 pci_set_master(ha->pdev);
2039 pci_try_set_mwi(ha->pdev);
2041 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2042 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2043 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2045 pci_disable_rom(ha->pdev);
2047 /* Get PCI bus information. */
2048 spin_lock_irqsave(&ha->hardware_lock, flags);
2049 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
2050 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2056 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
2059 * Returns 0 on success.
2062 qla2300_pci_config(scsi_qla_host_t *vha)
2065 unsigned long flags = 0;
2067 struct qla_hw_data *ha = vha->hw;
2068 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2070 pci_set_master(ha->pdev);
2071 pci_try_set_mwi(ha->pdev);
2073 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2074 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2076 if (IS_QLA2322(ha) || IS_QLA6322(ha))
2077 w &= ~PCI_COMMAND_INTX_DISABLE;
2078 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2081 * If this is a 2300 card and not 2312, reset the
2082 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
2083 * the 2310 also reports itself as a 2300 so we need to get the
2084 * fb revision level -- a 6 indicates it really is a 2300 and
2087 if (IS_QLA2300(ha)) {
2088 spin_lock_irqsave(&ha->hardware_lock, flags);
2091 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
2092 for (cnt = 0; cnt < 30000; cnt++) {
2093 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) != 0)
2099 /* Select FPM registers. */
2100 WRT_REG_WORD(®->ctrl_status, 0x20);
2101 RD_REG_WORD(®->ctrl_status);
2103 /* Get the fb rev level */
2104 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
2106 if (ha->fb_rev == FPM_2300)
2107 pci_clear_mwi(ha->pdev);
2109 /* Deselect FPM registers. */
2110 WRT_REG_WORD(®->ctrl_status, 0x0);
2111 RD_REG_WORD(®->ctrl_status);
2113 /* Release RISC module. */
2114 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
2115 for (cnt = 0; cnt < 30000; cnt++) {
2116 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) == 0)
2122 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2125 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
2127 pci_disable_rom(ha->pdev);
2129 /* Get PCI bus information. */
2130 spin_lock_irqsave(&ha->hardware_lock, flags);
2131 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
2132 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2138 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
2141 * Returns 0 on success.
2144 qla24xx_pci_config(scsi_qla_host_t *vha)
2147 unsigned long flags = 0;
2148 struct qla_hw_data *ha = vha->hw;
2149 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2151 pci_set_master(ha->pdev);
2152 pci_try_set_mwi(ha->pdev);
2154 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2155 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2156 w &= ~PCI_COMMAND_INTX_DISABLE;
2157 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2159 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
2161 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
2162 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
2163 pcix_set_mmrbc(ha->pdev, 2048);
2165 /* PCIe -- adjust Maximum Read Request Size (2048). */
2166 if (pci_is_pcie(ha->pdev))
2167 pcie_set_readrq(ha->pdev, 4096);
2169 pci_disable_rom(ha->pdev);
2171 ha->chip_revision = ha->pdev->revision;
2173 /* Get PCI bus information. */
2174 spin_lock_irqsave(&ha->hardware_lock, flags);
2175 ha->pci_attr = RD_REG_DWORD(®->ctrl_status);
2176 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2182 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
2185 * Returns 0 on success.
2188 qla25xx_pci_config(scsi_qla_host_t *vha)
2191 struct qla_hw_data *ha = vha->hw;
2193 pci_set_master(ha->pdev);
2194 pci_try_set_mwi(ha->pdev);
2196 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2197 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2198 w &= ~PCI_COMMAND_INTX_DISABLE;
2199 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2201 /* PCIe -- adjust Maximum Read Request Size (2048). */
2202 if (pci_is_pcie(ha->pdev))
2203 pcie_set_readrq(ha->pdev, 4096);
2205 pci_disable_rom(ha->pdev);
2207 ha->chip_revision = ha->pdev->revision;
2213 * qla2x00_isp_firmware() - Choose firmware image.
2216 * Returns 0 on success.
2219 qla2x00_isp_firmware(scsi_qla_host_t *vha)
2222 uint16_t loop_id, topo, sw_cap;
2223 uint8_t domain, area, al_pa;
2224 struct qla_hw_data *ha = vha->hw;
2226 /* Assume loading risc code */
2227 rval = QLA_FUNCTION_FAILED;
2229 if (ha->flags.disable_risc_code_load) {
2230 ql_log(ql_log_info, vha, 0x0079, "RISC CODE NOT loaded.\n");
2232 /* Verify checksum of loaded RISC code. */
2233 rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address);
2234 if (rval == QLA_SUCCESS) {
2235 /* And, verify we are not in ROM code. */
2236 rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
2237 &area, &domain, &topo, &sw_cap);
2242 ql_dbg(ql_dbg_init, vha, 0x007a,
2243 "**** Load RISC code ****.\n");
2249 * qla2x00_reset_chip() - Reset ISP chip.
2252 * Returns 0 on success.
2255 qla2x00_reset_chip(scsi_qla_host_t *vha)
2257 unsigned long flags = 0;
2258 struct qla_hw_data *ha = vha->hw;
2259 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2263 if (unlikely(pci_channel_offline(ha->pdev)))
2266 ha->isp_ops->disable_intrs(ha);
2268 spin_lock_irqsave(&ha->hardware_lock, flags);
2270 /* Turn off master enable */
2272 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
2273 cmd &= ~PCI_COMMAND_MASTER;
2274 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
2276 if (!IS_QLA2100(ha)) {
2278 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
2279 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
2280 for (cnt = 0; cnt < 30000; cnt++) {
2281 if ((RD_REG_WORD(®->hccr) &
2282 HCCR_RISC_PAUSE) != 0)
2287 RD_REG_WORD(®->hccr); /* PCI Posting. */
2291 /* Select FPM registers. */
2292 WRT_REG_WORD(®->ctrl_status, 0x20);
2293 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
2295 /* FPM Soft Reset. */
2296 WRT_REG_WORD(®->fpm_diag_config, 0x100);
2297 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
2299 /* Toggle Fpm Reset. */
2300 if (!IS_QLA2200(ha)) {
2301 WRT_REG_WORD(®->fpm_diag_config, 0x0);
2302 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
2305 /* Select frame buffer registers. */
2306 WRT_REG_WORD(®->ctrl_status, 0x10);
2307 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
2309 /* Reset frame buffer FIFOs. */
2310 if (IS_QLA2200(ha)) {
2311 WRT_FB_CMD_REG(ha, reg, 0xa000);
2312 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
2314 WRT_FB_CMD_REG(ha, reg, 0x00fc);
2316 /* Read back fb_cmd until zero or 3 seconds max */
2317 for (cnt = 0; cnt < 3000; cnt++) {
2318 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
2324 /* Select RISC module registers. */
2325 WRT_REG_WORD(®->ctrl_status, 0);
2326 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
2328 /* Reset RISC processor. */
2329 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
2330 RD_REG_WORD(®->hccr); /* PCI Posting. */
2332 /* Release RISC processor. */
2333 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
2334 RD_REG_WORD(®->hccr); /* PCI Posting. */
2337 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
2338 WRT_REG_WORD(®->hccr, HCCR_CLR_HOST_INT);
2340 /* Reset ISP chip. */
2341 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
2343 /* Wait for RISC to recover from reset. */
2344 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
2346 * It is necessary to for a delay here since the card doesn't
2347 * respond to PCI reads during a reset. On some architectures
2348 * this will result in an MCA.
2351 for (cnt = 30000; cnt; cnt--) {
2352 if ((RD_REG_WORD(®->ctrl_status) &
2353 CSR_ISP_SOFT_RESET) == 0)
2360 /* Reset RISC processor. */
2361 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
2363 WRT_REG_WORD(®->semaphore, 0);
2365 /* Release RISC processor. */
2366 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
2367 RD_REG_WORD(®->hccr); /* PCI Posting. */
2369 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
2370 for (cnt = 0; cnt < 30000; cnt++) {
2371 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
2379 /* Turn on master enable */
2380 cmd |= PCI_COMMAND_MASTER;
2381 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
2383 /* Disable RISC pause on FPM parity error. */
2384 if (!IS_QLA2100(ha)) {
2385 WRT_REG_WORD(®->hccr, HCCR_DISABLE_PARITY_PAUSE);
2386 RD_REG_WORD(®->hccr); /* PCI Posting. */
2389 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2393 * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC.
2395 * Returns 0 on success.
2398 qla81xx_reset_mpi(scsi_qla_host_t *vha)
2400 uint16_t mb[4] = {0x1010, 0, 1, 0};
2402 if (!IS_QLA81XX(vha->hw))
2405 return qla81xx_write_mpi_register(vha, mb);
2409 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
2412 * Returns 0 on success.
2415 qla24xx_reset_risc(scsi_qla_host_t *vha)
2417 unsigned long flags = 0;
2418 struct qla_hw_data *ha = vha->hw;
2419 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2422 static int abts_cnt; /* ISP abort retry counts */
2423 int rval = QLA_SUCCESS;
2425 spin_lock_irqsave(&ha->hardware_lock, flags);
2428 WRT_REG_DWORD(®->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
2429 for (cnt = 0; cnt < 30000; cnt++) {
2430 if ((RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
2436 if (!(RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE))
2437 set_bit(DMA_SHUTDOWN_CMPL, &ha->fw_dump_cap_flags);
2439 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017e,
2440 "HCCR: 0x%x, Control Status %x, DMA active status:0x%x\n",
2441 RD_REG_DWORD(®->hccr),
2442 RD_REG_DWORD(®->ctrl_status),
2443 (RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE));
2445 WRT_REG_DWORD(®->ctrl_status,
2446 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
2447 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
2451 /* Wait for firmware to complete NVRAM accesses. */
2452 RD_REG_WORD(®->mailbox0);
2453 for (cnt = 10000; RD_REG_WORD(®->mailbox0) != 0 &&
2454 rval == QLA_SUCCESS; cnt--) {
2459 rval = QLA_FUNCTION_TIMEOUT;
2462 if (rval == QLA_SUCCESS)
2463 set_bit(ISP_MBX_RDY, &ha->fw_dump_cap_flags);
2465 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017f,
2466 "HCCR: 0x%x, MailBox0 Status 0x%x\n",
2467 RD_REG_DWORD(®->hccr),
2468 RD_REG_DWORD(®->mailbox0));
2470 /* Wait for soft-reset to complete. */
2471 RD_REG_DWORD(®->ctrl_status);
2472 for (cnt = 0; cnt < 60; cnt++) {
2474 if ((RD_REG_DWORD(®->ctrl_status) &
2475 CSRX_ISP_SOFT_RESET) == 0)
2480 if (!(RD_REG_DWORD(®->ctrl_status) & CSRX_ISP_SOFT_RESET))
2481 set_bit(ISP_SOFT_RESET_CMPL, &ha->fw_dump_cap_flags);
2483 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015d,
2484 "HCCR: 0x%x, Soft Reset status: 0x%x\n",
2485 RD_REG_DWORD(®->hccr),
2486 RD_REG_DWORD(®->ctrl_status));
2488 /* If required, do an MPI FW reset now */
2489 if (test_and_clear_bit(MPI_RESET_NEEDED, &vha->dpc_flags)) {
2490 if (qla81xx_reset_mpi(vha) != QLA_SUCCESS) {
2491 if (++abts_cnt < 5) {
2492 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
2493 set_bit(MPI_RESET_NEEDED, &vha->dpc_flags);
2496 * We exhausted the ISP abort retries. We have to
2497 * set the board offline.
2500 vha->flags.online = 0;
2505 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
2506 RD_REG_DWORD(®->hccr);
2508 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
2509 RD_REG_DWORD(®->hccr);
2511 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_RESET);
2512 RD_REG_DWORD(®->hccr);
2514 RD_REG_WORD(®->mailbox0);
2515 for (cnt = 60; RD_REG_WORD(®->mailbox0) != 0 &&
2516 rval == QLA_SUCCESS; cnt--) {
2521 rval = QLA_FUNCTION_TIMEOUT;
2523 if (rval == QLA_SUCCESS)
2524 set_bit(RISC_RDY_AFT_RESET, &ha->fw_dump_cap_flags);
2526 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015e,
2527 "Host Risc 0x%x, mailbox0 0x%x\n",
2528 RD_REG_DWORD(®->hccr),
2529 RD_REG_WORD(®->mailbox0));
2531 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2533 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015f,
2534 "Driver in %s mode\n",
2535 IS_NOPOLLING_TYPE(ha) ? "Interrupt" : "Polling");
2537 if (IS_NOPOLLING_TYPE(ha))
2538 ha->isp_ops->enable_intrs(ha);
2544 qla25xx_read_risc_sema_reg(scsi_qla_host_t *vha, uint32_t *data)
2546 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
2548 WRT_REG_DWORD(®->iobase_addr, RISC_REGISTER_BASE_OFFSET);
2549 *data = RD_REG_DWORD(®->iobase_window + RISC_REGISTER_WINDOW_OFFET);
2554 qla25xx_write_risc_sema_reg(scsi_qla_host_t *vha, uint32_t data)
2556 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
2558 WRT_REG_DWORD(®->iobase_addr, RISC_REGISTER_BASE_OFFSET);
2559 WRT_REG_DWORD(®->iobase_window + RISC_REGISTER_WINDOW_OFFET, data);
2563 qla25xx_manipulate_risc_semaphore(scsi_qla_host_t *vha)
2566 uint delta_msec = 100;
2567 uint elapsed_msec = 0;
2571 if (vha->hw->pdev->subsystem_device != 0x0175 &&
2572 vha->hw->pdev->subsystem_device != 0x0240)
2575 WRT_REG_DWORD(&vha->hw->iobase->isp24.hccr, HCCRX_SET_RISC_PAUSE);
2579 timeout_msec = TIMEOUT_SEMAPHORE;
2580 n = timeout_msec / delta_msec;
2582 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_SET);
2583 qla25xx_read_risc_sema_reg(vha, &wd32);
2584 if (wd32 & RISC_SEMAPHORE)
2587 elapsed_msec += delta_msec;
2588 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
2592 if (!(wd32 & RISC_SEMAPHORE))
2595 if (!(wd32 & RISC_SEMAPHORE_FORCE))
2598 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_CLR);
2599 timeout_msec = TIMEOUT_SEMAPHORE_FORCE;
2600 n = timeout_msec / delta_msec;
2602 qla25xx_read_risc_sema_reg(vha, &wd32);
2603 if (!(wd32 & RISC_SEMAPHORE_FORCE))
2606 elapsed_msec += delta_msec;
2607 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
2611 if (wd32 & RISC_SEMAPHORE_FORCE)
2612 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_CLR);
2617 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_SET);
2624 * qla24xx_reset_chip() - Reset ISP24xx chip.
2627 * Returns 0 on success.
2630 qla24xx_reset_chip(scsi_qla_host_t *vha)
2632 struct qla_hw_data *ha = vha->hw;
2634 if (pci_channel_offline(ha->pdev) &&
2635 ha->flags.pci_channel_io_perm_failure) {
2639 ha->isp_ops->disable_intrs(ha);
2641 qla25xx_manipulate_risc_semaphore(vha);
2643 /* Perform RISC reset. */
2644 qla24xx_reset_risc(vha);
2648 * qla2x00_chip_diag() - Test chip for proper operation.
2651 * Returns 0 on success.
2654 qla2x00_chip_diag(scsi_qla_host_t *vha)
2657 struct qla_hw_data *ha = vha->hw;
2658 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2659 unsigned long flags = 0;
2663 struct req_que *req = ha->req_q_map[0];
2665 /* Assume a failed state */
2666 rval = QLA_FUNCTION_FAILED;
2668 ql_dbg(ql_dbg_init, vha, 0x007b,
2669 "Testing device at %lx.\n", (u_long)®->flash_address);
2671 spin_lock_irqsave(&ha->hardware_lock, flags);
2673 /* Reset ISP chip. */
2674 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
2677 * We need to have a delay here since the card will not respond while
2678 * in reset causing an MCA on some architectures.
2681 data = qla2x00_debounce_register(®->ctrl_status);
2682 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
2684 data = RD_REG_WORD(®->ctrl_status);
2689 goto chip_diag_failed;
2691 ql_dbg(ql_dbg_init, vha, 0x007c,
2692 "Reset register cleared by chip reset.\n");
2694 /* Reset RISC processor. */
2695 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
2696 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
2698 /* Workaround for QLA2312 PCI parity error */
2699 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
2700 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
2701 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
2703 data = RD_MAILBOX_REG(ha, reg, 0);
2710 goto chip_diag_failed;
2712 /* Check product ID of chip */
2713 ql_dbg(ql_dbg_init, vha, 0x007d, "Checking product ID of chip.\n");
2715 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
2716 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
2717 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
2718 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
2719 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
2720 mb[3] != PROD_ID_3) {
2721 ql_log(ql_log_warn, vha, 0x0062,
2722 "Wrong product ID = 0x%x,0x%x,0x%x.\n",
2723 mb[1], mb[2], mb[3]);
2725 goto chip_diag_failed;
2727 ha->product_id[0] = mb[1];
2728 ha->product_id[1] = mb[2];
2729 ha->product_id[2] = mb[3];
2730 ha->product_id[3] = mb[4];
2732 /* Adjust fw RISC transfer size */
2733 if (req->length > 1024)
2734 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
2736 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
2739 if (IS_QLA2200(ha) &&
2740 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
2741 /* Limit firmware transfer size with a 2200A */
2742 ql_dbg(ql_dbg_init, vha, 0x007e, "Found QLA2200A Chip.\n");
2744 ha->device_type |= DT_ISP2200A;
2745 ha->fw_transfer_size = 128;
2748 /* Wrap Incoming Mailboxes Test. */
2749 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2751 ql_dbg(ql_dbg_init, vha, 0x007f, "Checking mailboxes.\n");
2752 rval = qla2x00_mbx_reg_test(vha);
2754 ql_log(ql_log_warn, vha, 0x0080,
2755 "Failed mailbox send register test.\n");
2757 /* Flag a successful rval */
2759 spin_lock_irqsave(&ha->hardware_lock, flags);
2763 ql_log(ql_log_info, vha, 0x0081,
2764 "Chip diagnostics **** FAILED ****.\n");
2766 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2772 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
2775 * Returns 0 on success.
2778 qla24xx_chip_diag(scsi_qla_host_t *vha)
2781 struct qla_hw_data *ha = vha->hw;
2782 struct req_que *req = ha->req_q_map[0];
2784 if (IS_P3P_TYPE(ha))
2787 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
2789 rval = qla2x00_mbx_reg_test(vha);
2791 ql_log(ql_log_warn, vha, 0x0082,
2792 "Failed mailbox send register test.\n");
2794 /* Flag a successful rval */
2802 qla2x00_alloc_offload_mem(scsi_qla_host_t *vha)
2807 struct qla_hw_data *ha = vha->hw;
2810 ql_dbg(ql_dbg_init, vha, 0x00bd,
2811 "%s: Offload Mem is already allocated.\n",
2816 if (IS_FWI2_CAPABLE(ha)) {
2817 /* Allocate memory for Fibre Channel Event Buffer. */
2818 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
2823 dma_free_coherent(&ha->pdev->dev,
2824 FCE_SIZE, ha->fce, ha->fce_dma);
2826 /* Allocate memory for Fibre Channel Event Buffer. */
2827 tc = dma_zalloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
2830 ql_log(ql_log_warn, vha, 0x00be,
2831 "Unable to allocate (%d KB) for FCE.\n",
2836 rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
2837 ha->fce_mb, &ha->fce_bufs);
2839 ql_log(ql_log_warn, vha, 0x00bf,
2840 "Unable to initialize FCE (%d).\n", rval);
2841 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc,
2843 ha->flags.fce_enabled = 0;
2846 ql_dbg(ql_dbg_init, vha, 0x00c0,
2847 "Allocate (%d KB) for FCE...\n", FCE_SIZE / 1024);
2849 ha->flags.fce_enabled = 1;
2850 ha->fce_dma = tc_dma;
2855 dma_free_coherent(&ha->pdev->dev,
2856 EFT_SIZE, ha->eft, ha->eft_dma);
2858 /* Allocate memory for Extended Trace Buffer. */
2859 tc = dma_zalloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
2862 ql_log(ql_log_warn, vha, 0x00c1,
2863 "Unable to allocate (%d KB) for EFT.\n",
2868 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
2870 ql_log(ql_log_warn, vha, 0x00c2,
2871 "Unable to initialize EFT (%d).\n", rval);
2872 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
2876 ql_dbg(ql_dbg_init, vha, 0x00c3,
2877 "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024);
2879 ha->eft_dma = tc_dma;
2888 qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
2890 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
2891 eft_size, fce_size, mq_size;
2892 struct qla_hw_data *ha = vha->hw;
2893 struct req_que *req = ha->req_q_map[0];
2894 struct rsp_que *rsp = ha->rsp_q_map[0];
2895 struct qla2xxx_fw_dump *fw_dump;
2897 dump_size = fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
2898 req_q_size = rsp_q_size = 0;
2900 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
2901 fixed_size = sizeof(struct qla2100_fw_dump);
2902 } else if (IS_QLA23XX(ha)) {
2903 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
2904 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
2906 } else if (IS_FWI2_CAPABLE(ha)) {
2907 if (IS_QLA83XX(ha) || IS_QLA27XX(ha))
2908 fixed_size = offsetof(struct qla83xx_fw_dump, ext_mem);
2909 else if (IS_QLA81XX(ha))
2910 fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem);
2911 else if (IS_QLA25XX(ha))
2912 fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem);
2914 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
2916 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
2919 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha))
2920 mq_size = sizeof(struct qla2xxx_mq_chain);
2922 * Allocate maximum buffer size for all queues.
2923 * Resizing must be done at end-of-dump processing.
2925 mq_size += ha->max_req_queues *
2926 (req->length * sizeof(request_t));
2927 mq_size += ha->max_rsp_queues *
2928 (rsp->length * sizeof(response_t));
2930 if (ha->tgt.atio_ring)
2931 mq_size += ha->tgt.atio_q_length * sizeof(request_t);
2932 /* Allocate memory for Fibre Channel Event Buffer. */
2933 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
2937 fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
2939 ql_dbg(ql_dbg_init, vha, 0x00c3,
2940 "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024);
2941 eft_size = EFT_SIZE;
2944 if (IS_QLA27XX(ha)) {
2945 if (!ha->fw_dump_template) {
2946 ql_log(ql_log_warn, vha, 0x00ba,
2947 "Failed missing fwdump template\n");
2950 dump_size = qla27xx_fwdt_calculate_dump_size(vha);
2951 ql_dbg(ql_dbg_init, vha, 0x00fa,
2952 "-> allocating fwdump (%x bytes)...\n", dump_size);
2956 req_q_size = req->length * sizeof(request_t);
2957 rsp_q_size = rsp->length * sizeof(response_t);
2958 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
2959 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size + eft_size;
2960 ha->chain_offset = dump_size;
2961 dump_size += mq_size + fce_size;
2963 if (ha->exchoffld_buf)
2964 dump_size += sizeof(struct qla2xxx_offld_chain) +
2966 if (ha->exlogin_buf)
2967 dump_size += sizeof(struct qla2xxx_offld_chain) +
2971 if (!ha->fw_dump_len || dump_size != ha->fw_dump_len) {
2972 fw_dump = vmalloc(dump_size);
2974 ql_log(ql_log_warn, vha, 0x00c4,
2975 "Unable to allocate (%d KB) for firmware dump.\n",
2980 ha->fw_dump = fw_dump;
2982 ha->fw_dump_len = dump_size;
2983 ql_dbg(ql_dbg_init, vha, 0x00c5,
2984 "Allocated (%d KB) for firmware dump.\n",
2990 ha->fw_dump->signature[0] = 'Q';
2991 ha->fw_dump->signature[1] = 'L';
2992 ha->fw_dump->signature[2] = 'G';
2993 ha->fw_dump->signature[3] = 'C';
2994 ha->fw_dump->version = htonl(1);
2996 ha->fw_dump->fixed_size = htonl(fixed_size);
2997 ha->fw_dump->mem_size = htonl(mem_size);
2998 ha->fw_dump->req_q_size = htonl(req_q_size);
2999 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
3001 ha->fw_dump->eft_size = htonl(eft_size);
3002 ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
3003 ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
3005 ha->fw_dump->header_size =
3006 htonl(offsetof(struct qla2xxx_fw_dump, isp));
3012 qla81xx_mpi_sync(scsi_qla_host_t *vha)
3014 #define MPS_MASK 0xe0
3019 if (!IS_QLA81XX(vha->hw))
3022 rval = qla2x00_write_ram_word(vha, 0x7c00, 1);
3023 if (rval != QLA_SUCCESS) {
3024 ql_log(ql_log_warn, vha, 0x0105,
3025 "Unable to acquire semaphore.\n");
3029 pci_read_config_word(vha->hw->pdev, 0x54, &dc);
3030 rval = qla2x00_read_ram_word(vha, 0x7a15, &dw);
3031 if (rval != QLA_SUCCESS) {
3032 ql_log(ql_log_warn, vha, 0x0067, "Unable to read sync.\n");
3037 if (dc == (dw & MPS_MASK))
3042 rval = qla2x00_write_ram_word(vha, 0x7a15, dw);
3043 if (rval != QLA_SUCCESS) {
3044 ql_log(ql_log_warn, vha, 0x0114, "Unable to gain sync.\n");
3048 rval = qla2x00_write_ram_word(vha, 0x7c00, 0);
3049 if (rval != QLA_SUCCESS) {
3050 ql_log(ql_log_warn, vha, 0x006d,
3051 "Unable to release semaphore.\n");
3059 qla2x00_alloc_outstanding_cmds(struct qla_hw_data *ha, struct req_que *req)
3061 /* Don't try to reallocate the array */
3062 if (req->outstanding_cmds)
3065 if (!IS_FWI2_CAPABLE(ha))
3066 req->num_outstanding_cmds = DEFAULT_OUTSTANDING_COMMANDS;
3068 if (ha->cur_fw_xcb_count <= ha->cur_fw_iocb_count)
3069 req->num_outstanding_cmds = ha->cur_fw_xcb_count;
3071 req->num_outstanding_cmds = ha->cur_fw_iocb_count;
3074 req->outstanding_cmds = kzalloc(sizeof(srb_t *) *
3075 req->num_outstanding_cmds, GFP_KERNEL);
3077 if (!req->outstanding_cmds) {
3079 * Try to allocate a minimal size just so we can get through
3082 req->num_outstanding_cmds = MIN_OUTSTANDING_COMMANDS;
3083 req->outstanding_cmds = kzalloc(sizeof(srb_t *) *
3084 req->num_outstanding_cmds, GFP_KERNEL);
3086 if (!req->outstanding_cmds) {
3087 ql_log(ql_log_fatal, NULL, 0x0126,
3088 "Failed to allocate memory for "
3089 "outstanding_cmds for req_que %p.\n", req);
3090 req->num_outstanding_cmds = 0;
3091 return QLA_FUNCTION_FAILED;
3098 #define PRINT_FIELD(_field, _flag, _str) { \
3099 if (a0->_field & _flag) {\
3105 len = snprintf(ptr, leftover, "%s", _str); \
3112 static void qla2xxx_print_sfp_info(struct scsi_qla_host *vha)
3115 struct sff_8247_a0 *a0 = (struct sff_8247_a0 *)vha->hw->sfp_data;
3116 u8 str[STR_LEN], *ptr, p;
3119 memset(str, 0, STR_LEN);
3120 snprintf(str, SFF_VEN_NAME_LEN+1, a0->vendor_name);
3121 ql_dbg(ql_dbg_init, vha, 0x015a,
3122 "SFP MFG Name: %s\n", str);
3124 memset(str, 0, STR_LEN);
3125 snprintf(str, SFF_PART_NAME_LEN+1, a0->vendor_pn);
3126 ql_dbg(ql_dbg_init, vha, 0x015c,
3127 "SFP Part Name: %s\n", str);
3130 memset(str, 0, STR_LEN);
3134 PRINT_FIELD(fc_med_cc9, FC_MED_TW, "Twin AX");
3135 PRINT_FIELD(fc_med_cc9, FC_MED_TP, "Twisted Pair");
3136 PRINT_FIELD(fc_med_cc9, FC_MED_MI, "Min Coax");
3137 PRINT_FIELD(fc_med_cc9, FC_MED_TV, "Video Coax");
3138 PRINT_FIELD(fc_med_cc9, FC_MED_M6, "MultiMode 62.5um");
3139 PRINT_FIELD(fc_med_cc9, FC_MED_M5, "MultiMode 50um");
3140 PRINT_FIELD(fc_med_cc9, FC_MED_SM, "SingleMode");
3141 ql_dbg(ql_dbg_init, vha, 0x0160,
3142 "SFP Media: %s\n", str);
3145 memset(str, 0, STR_LEN);
3149 PRINT_FIELD(fc_ll_cc7, FC_LL_VL, "Very Long");
3150 PRINT_FIELD(fc_ll_cc7, FC_LL_S, "Short");
3151 PRINT_FIELD(fc_ll_cc7, FC_LL_I, "Intermediate");
3152 PRINT_FIELD(fc_ll_cc7, FC_LL_L, "Long");
3153 PRINT_FIELD(fc_ll_cc7, FC_LL_M, "Medium");
3154 ql_dbg(ql_dbg_init, vha, 0x0196,
3155 "SFP Link Length: %s\n", str);
3157 memset(str, 0, STR_LEN);
3161 PRINT_FIELD(fc_ll_cc7, FC_LL_SA, "Short Wave (SA)");
3162 PRINT_FIELD(fc_ll_cc7, FC_LL_LC, "Long Wave(LC)");
3163 PRINT_FIELD(fc_tec_cc8, FC_TEC_SN, "Short Wave (SN)");
3164 PRINT_FIELD(fc_tec_cc8, FC_TEC_SL, "Short Wave (SL)");
3165 PRINT_FIELD(fc_tec_cc8, FC_TEC_LL, "Long Wave (LL)");
3166 ql_dbg(ql_dbg_init, vha, 0x016e,
3167 "SFP FC Link Tech: %s\n", str);
3170 ql_dbg(ql_dbg_init, vha, 0x016f,
3171 "SFP Distant: %d km\n", a0->length_km);
3172 if (a0->length_100m)
3173 ql_dbg(ql_dbg_init, vha, 0x0170,
3174 "SFP Distant: %d m\n", a0->length_100m*100);
3175 if (a0->length_50um_10m)
3176 ql_dbg(ql_dbg_init, vha, 0x0189,
3177 "SFP Distant (WL=50um): %d m\n", a0->length_50um_10m * 10);
3178 if (a0->length_62um_10m)
3179 ql_dbg(ql_dbg_init, vha, 0x018a,
3180 "SFP Distant (WL=62.5um): %d m\n", a0->length_62um_10m * 10);
3181 if (a0->length_om4_10m)
3182 ql_dbg(ql_dbg_init, vha, 0x0194,
3183 "SFP Distant (OM4): %d m\n", a0->length_om4_10m * 10);
3184 if (a0->length_om3_10m)
3185 ql_dbg(ql_dbg_init, vha, 0x0195,
3186 "SFP Distant (OM3): %d m\n", a0->length_om3_10m * 10);
3192 * QLA_SUCCESS: no action
3193 * QLA_INTERFACE_ERROR: SFP is not there.
3194 * QLA_FUNCTION_FAILED: detected New SFP
3197 qla24xx_detect_sfp(scsi_qla_host_t *vha)
3199 int rc = QLA_SUCCESS;
3200 struct sff_8247_a0 *a;
3201 struct qla_hw_data *ha = vha->hw;
3203 if (!AUTO_DETECT_SFP_SUPPORT(vha))
3206 rc = qla2x00_read_sfp_dev(vha, NULL, 0);
3210 a = (struct sff_8247_a0 *)vha->hw->sfp_data;
3211 qla2xxx_print_sfp_info(vha);
3213 if (a->fc_ll_cc7 & FC_LL_VL || a->fc_ll_cc7 & FC_LL_L) {
3215 ha->flags.detected_lr_sfp = 1;
3217 if (a->length_km > 5 || a->length_100m > 50)
3218 ha->long_range_distance = LR_DISTANCE_10K;
3220 ha->long_range_distance = LR_DISTANCE_5K;
3222 if (ha->flags.detected_lr_sfp != ha->flags.using_lr_setting)
3223 ql_dbg(ql_dbg_async, vha, 0x507b,
3224 "Detected Long Range SFP.\n");
3227 ha->flags.detected_lr_sfp = 0;
3228 if (ha->flags.using_lr_setting)
3229 ql_dbg(ql_dbg_async, vha, 0x5084,
3230 "Detected Short Range SFP.\n");
3233 if (!vha->flags.init_done)
3240 * qla2x00_setup_chip() - Load and start RISC firmware.
3243 * Returns 0 on success.
3246 qla2x00_setup_chip(scsi_qla_host_t *vha)
3249 uint32_t srisc_address = 0;
3250 struct qla_hw_data *ha = vha->hw;
3251 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3252 unsigned long flags;
3253 uint16_t fw_major_version;
3255 if (IS_P3P_TYPE(ha)) {
3256 rval = ha->isp_ops->load_risc(vha, &srisc_address);
3257 if (rval == QLA_SUCCESS) {
3258 qla2x00_stop_firmware(vha);
3259 goto enable_82xx_npiv;
3264 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
3265 /* Disable SRAM, Instruction RAM and GP RAM parity. */
3266 spin_lock_irqsave(&ha->hardware_lock, flags);
3267 WRT_REG_WORD(®->hccr, (HCCR_ENABLE_PARITY + 0x0));
3268 RD_REG_WORD(®->hccr);
3269 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3272 qla81xx_mpi_sync(vha);
3274 /* Load firmware sequences */
3275 rval = ha->isp_ops->load_risc(vha, &srisc_address);
3276 if (rval == QLA_SUCCESS) {
3277 ql_dbg(ql_dbg_init, vha, 0x00c9,
3278 "Verifying Checksum of loaded RISC code.\n");
3280 rval = qla2x00_verify_checksum(vha, srisc_address);
3281 if (rval == QLA_SUCCESS) {
3282 /* Start firmware execution. */
3283 ql_dbg(ql_dbg_init, vha, 0x00ca,
3284 "Starting firmware.\n");
3287 ha->flags.exlogins_enabled = 1;
3289 if (qla_is_exch_offld_enabled(vha))
3290 ha->flags.exchoffld_enabled = 1;
3292 rval = qla2x00_execute_fw(vha, srisc_address);
3293 /* Retrieve firmware information. */
3294 if (rval == QLA_SUCCESS) {
3295 qla24xx_detect_sfp(vha);
3297 rval = qla2x00_set_exlogins_buffer(vha);
3298 if (rval != QLA_SUCCESS)
3301 rval = qla2x00_set_exchoffld_buffer(vha);
3302 if (rval != QLA_SUCCESS)
3306 fw_major_version = ha->fw_major_version;
3307 if (IS_P3P_TYPE(ha))
3308 qla82xx_check_md_needed(vha);
3310 rval = qla2x00_get_fw_version(vha);
3311 if (rval != QLA_SUCCESS)
3313 ha->flags.npiv_supported = 0;
3314 if (IS_QLA2XXX_MIDTYPE(ha) &&
3315 (ha->fw_attributes & BIT_2)) {
3316 ha->flags.npiv_supported = 1;
3317 if ((!ha->max_npiv_vports) ||
3318 ((ha->max_npiv_vports + 1) %
3319 MIN_MULTI_ID_FABRIC))
3320 ha->max_npiv_vports =
3321 MIN_MULTI_ID_FABRIC - 1;
3323 qla2x00_get_resource_cnts(vha);
3326 * Allocate the array of outstanding commands
3327 * now that we know the firmware resources.
3329 rval = qla2x00_alloc_outstanding_cmds(ha,
3331 if (rval != QLA_SUCCESS)
3334 if (!fw_major_version && !(IS_P3P_TYPE(ha)))
3335 qla2x00_alloc_offload_mem(vha);
3337 if (ql2xallocfwdump && !(IS_P3P_TYPE(ha)))
3338 qla2x00_alloc_fw_dump(vha);
3344 ql_log(ql_log_fatal, vha, 0x00cd,
3345 "ISP Firmware failed checksum.\n");
3351 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
3352 /* Enable proper parity. */
3353 spin_lock_irqsave(&ha->hardware_lock, flags);
3356 WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x1);
3358 /* SRAM, Instruction RAM and GP RAM parity */
3359 WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x7);
3360 RD_REG_WORD(®->hccr);
3361 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3365 ha->flags.fac_supported = 1;
3366 else if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) {
3369 rval = qla81xx_fac_get_sector_size(vha, &size);
3370 if (rval == QLA_SUCCESS) {
3371 ha->flags.fac_supported = 1;
3372 ha->fdt_block_size = size << 2;
3374 ql_log(ql_log_warn, vha, 0x00ce,
3375 "Unsupported FAC firmware (%d.%02d.%02d).\n",
3376 ha->fw_major_version, ha->fw_minor_version,
3377 ha->fw_subminor_version);
3379 if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
3380 ha->flags.fac_supported = 0;
3387 ql_log(ql_log_fatal, vha, 0x00cf,
3388 "Setup chip ****FAILED****.\n");
3395 * qla2x00_init_response_q_entries() - Initializes response queue entries.
3398 * Beginning of request ring has initialization control block already built
3399 * by nvram config routine.
3401 * Returns 0 on success.
3404 qla2x00_init_response_q_entries(struct rsp_que *rsp)
3409 rsp->ring_ptr = rsp->ring;
3410 rsp->ring_index = 0;
3411 rsp->status_srb = NULL;
3412 pkt = rsp->ring_ptr;
3413 for (cnt = 0; cnt < rsp->length; cnt++) {
3414 pkt->signature = RESPONSE_PROCESSED;
3420 * qla2x00_update_fw_options() - Read and process firmware options.
3423 * Returns 0 on success.
3426 qla2x00_update_fw_options(scsi_qla_host_t *vha)
3428 uint16_t swing, emphasis, tx_sens, rx_sens;
3429 struct qla_hw_data *ha = vha->hw;
3431 memset(ha->fw_options, 0, sizeof(ha->fw_options));
3432 qla2x00_get_fw_options(vha, ha->fw_options);
3434 if (IS_QLA2100(ha) || IS_QLA2200(ha))
3437 /* Serial Link options. */
3438 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0115,
3439 "Serial link options.\n");
3440 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0109,
3441 (uint8_t *)&ha->fw_seriallink_options,
3442 sizeof(ha->fw_seriallink_options));
3444 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
3445 if (ha->fw_seriallink_options[3] & BIT_2) {
3446 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
3449 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
3450 emphasis = (ha->fw_seriallink_options[2] &
3451 (BIT_4 | BIT_3)) >> 3;
3452 tx_sens = ha->fw_seriallink_options[0] &
3453 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
3454 rx_sens = (ha->fw_seriallink_options[0] &
3455 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
3456 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
3457 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
3460 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
3461 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
3462 ha->fw_options[10] |= BIT_5 |
3463 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
3464 (tx_sens & (BIT_1 | BIT_0));
3467 swing = (ha->fw_seriallink_options[2] &
3468 (BIT_7 | BIT_6 | BIT_5)) >> 5;
3469 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
3470 tx_sens = ha->fw_seriallink_options[1] &
3471 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
3472 rx_sens = (ha->fw_seriallink_options[1] &
3473 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
3474 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
3475 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
3478 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
3479 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
3480 ha->fw_options[11] |= BIT_5 |
3481 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
3482 (tx_sens & (BIT_1 | BIT_0));
3486 /* Return command IOCBs without waiting for an ABTS to complete. */
3487 ha->fw_options[3] |= BIT_13;
3490 if (ha->flags.enable_led_scheme)
3491 ha->fw_options[2] |= BIT_12;
3493 /* Detect ISP6312. */
3495 ha->fw_options[2] |= BIT_13;
3497 /* Set Retry FLOGI in case of P2P connection */
3498 if (ha->operating_mode == P2P) {
3499 ha->fw_options[2] |= BIT_3;
3500 ql_dbg(ql_dbg_disc, vha, 0x2100,
3501 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
3502 __func__, ha->fw_options[2]);
3505 /* Update firmware options. */
3506 qla2x00_set_fw_options(vha, ha->fw_options);
3510 qla24xx_update_fw_options(scsi_qla_host_t *vha)
3513 struct qla_hw_data *ha = vha->hw;
3515 if (IS_P3P_TYPE(ha))
3518 /* Hold status IOCBs until ABTS response received. */
3520 ha->fw_options[3] |= BIT_12;
3522 /* Set Retry FLOGI in case of P2P connection */
3523 if (ha->operating_mode == P2P) {
3524 ha->fw_options[2] |= BIT_3;
3525 ql_dbg(ql_dbg_disc, vha, 0x2101,
3526 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
3527 __func__, ha->fw_options[2]);
3530 /* Move PUREX, ABTS RX & RIDA to ATIOQ */
3531 if (ql2xmvasynctoatio &&
3532 (IS_QLA83XX(ha) || IS_QLA27XX(ha))) {
3533 if (qla_tgt_mode_enabled(vha) ||
3534 qla_dual_mode_enabled(vha))
3535 ha->fw_options[2] |= BIT_11;
3537 ha->fw_options[2] &= ~BIT_11;
3540 if (IS_QLA25XX(ha) || IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
3542 * Tell FW to track each exchange to prevent
3543 * driver from using stale exchange.
3545 if (qla_tgt_mode_enabled(vha) ||
3546 qla_dual_mode_enabled(vha))
3547 ha->fw_options[2] |= BIT_4;
3549 ha->fw_options[2] &= ~BIT_4;
3551 /* Reserve 1/2 of emergency exchanges for ELS.*/
3552 if (qla2xuseresexchforels)
3553 ha->fw_options[2] |= BIT_8;
3555 ha->fw_options[2] &= ~BIT_8;
3558 ql_dbg(ql_dbg_init, vha, 0x00e8,
3559 "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n",
3560 __func__, ha->fw_options[1], ha->fw_options[2],
3561 ha->fw_options[3], vha->host->active_mode);
3563 if (ha->fw_options[1] || ha->fw_options[2] || ha->fw_options[3])
3564 qla2x00_set_fw_options(vha, ha->fw_options);
3566 /* Update Serial Link options. */
3567 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
3570 rval = qla2x00_set_serdes_params(vha,
3571 le16_to_cpu(ha->fw_seriallink_options24[1]),
3572 le16_to_cpu(ha->fw_seriallink_options24[2]),
3573 le16_to_cpu(ha->fw_seriallink_options24[3]));
3574 if (rval != QLA_SUCCESS) {
3575 ql_log(ql_log_warn, vha, 0x0104,
3576 "Unable to update Serial Link options (%x).\n", rval);
3581 qla2x00_config_rings(struct scsi_qla_host *vha)
3583 struct qla_hw_data *ha = vha->hw;
3584 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3585 struct req_que *req = ha->req_q_map[0];
3586 struct rsp_que *rsp = ha->rsp_q_map[0];
3588 /* Setup ring parameters in initialization control block. */
3589 ha->init_cb->request_q_outpointer = cpu_to_le16(0);
3590 ha->init_cb->response_q_inpointer = cpu_to_le16(0);
3591 ha->init_cb->request_q_length = cpu_to_le16(req->length);
3592 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
3593 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
3594 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
3595 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
3596 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
3598 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
3599 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
3600 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
3601 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
3602 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
3606 qla24xx_config_rings(struct scsi_qla_host *vha)
3608 struct qla_hw_data *ha = vha->hw;
3609 device_reg_t *reg = ISP_QUE_REG(ha, 0);
3610 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
3611 struct qla_msix_entry *msix;
3612 struct init_cb_24xx *icb;
3614 struct req_que *req = ha->req_q_map[0];
3615 struct rsp_que *rsp = ha->rsp_q_map[0];
3617 /* Setup ring parameters in initialization control block. */
3618 icb = (struct init_cb_24xx *)ha->init_cb;
3619 icb->request_q_outpointer = cpu_to_le16(0);
3620 icb->response_q_inpointer = cpu_to_le16(0);
3621 icb->request_q_length = cpu_to_le16(req->length);
3622 icb->response_q_length = cpu_to_le16(rsp->length);
3623 icb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
3624 icb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
3625 icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
3626 icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
3628 /* Setup ATIO queue dma pointers for target mode */
3629 icb->atio_q_inpointer = cpu_to_le16(0);
3630 icb->atio_q_length = cpu_to_le16(ha->tgt.atio_q_length);
3631 icb->atio_q_address[0] = cpu_to_le32(LSD(ha->tgt.atio_dma));
3632 icb->atio_q_address[1] = cpu_to_le32(MSD(ha->tgt.atio_dma));
3634 if (IS_SHADOW_REG_CAPABLE(ha))
3635 icb->firmware_options_2 |= cpu_to_le32(BIT_30|BIT_29);
3637 if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
3638 icb->qos = cpu_to_le16(QLA_DEFAULT_QUE_QOS);
3639 icb->rid = cpu_to_le16(rid);
3640 if (ha->flags.msix_enabled) {
3641 msix = &ha->msix_entries[1];
3642 ql_dbg(ql_dbg_init, vha, 0x0019,
3643 "Registering vector 0x%x for base que.\n",
3645 icb->msix = cpu_to_le16(msix->entry);
3647 /* Use alternate PCI bus number */
3649 icb->firmware_options_2 |= cpu_to_le32(BIT_19);
3650 /* Use alternate PCI devfn */
3652 icb->firmware_options_2 |= cpu_to_le32(BIT_18);
3654 /* Use Disable MSIX Handshake mode for capable adapters */
3655 if ((ha->fw_attributes & BIT_6) && (IS_MSIX_NACK_CAPABLE(ha)) &&
3656 (ha->flags.msix_enabled)) {
3657 icb->firmware_options_2 &= cpu_to_le32(~BIT_22);
3658 ha->flags.disable_msix_handshake = 1;
3659 ql_dbg(ql_dbg_init, vha, 0x00fe,
3660 "MSIX Handshake Disable Mode turned on.\n");
3662 icb->firmware_options_2 |= cpu_to_le32(BIT_22);
3664 icb->firmware_options_2 |= cpu_to_le32(BIT_23);
3666 WRT_REG_DWORD(®->isp25mq.req_q_in, 0);
3667 WRT_REG_DWORD(®->isp25mq.req_q_out, 0);
3668 WRT_REG_DWORD(®->isp25mq.rsp_q_in, 0);
3669 WRT_REG_DWORD(®->isp25mq.rsp_q_out, 0);
3671 WRT_REG_DWORD(®->isp24.req_q_in, 0);
3672 WRT_REG_DWORD(®->isp24.req_q_out, 0);
3673 WRT_REG_DWORD(®->isp24.rsp_q_in, 0);
3674 WRT_REG_DWORD(®->isp24.rsp_q_out, 0);
3676 qlt_24xx_config_rings(vha);
3679 RD_REG_DWORD(&ioreg->hccr);
3683 * qla2x00_init_rings() - Initializes firmware.
3686 * Beginning of request ring has initialization control block already built
3687 * by nvram config routine.
3689 * Returns 0 on success.
3692 qla2x00_init_rings(scsi_qla_host_t *vha)
3695 unsigned long flags = 0;
3697 struct qla_hw_data *ha = vha->hw;
3698 struct req_que *req;
3699 struct rsp_que *rsp;
3700 struct mid_init_cb_24xx *mid_init_cb =
3701 (struct mid_init_cb_24xx *) ha->init_cb;
3703 spin_lock_irqsave(&ha->hardware_lock, flags);
3705 /* Clear outstanding commands array. */
3706 for (que = 0; que < ha->max_req_queues; que++) {
3707 req = ha->req_q_map[que];
3708 if (!req || !test_bit(que, ha->req_qid_map))
3710 req->out_ptr = (void *)(req->ring + req->length);
3712 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++)
3713 req->outstanding_cmds[cnt] = NULL;
3715 req->current_outstanding_cmd = 1;
3717 /* Initialize firmware. */
3718 req->ring_ptr = req->ring;
3719 req->ring_index = 0;
3720 req->cnt = req->length;
3723 for (que = 0; que < ha->max_rsp_queues; que++) {
3724 rsp = ha->rsp_q_map[que];
3725 if (!rsp || !test_bit(que, ha->rsp_qid_map))
3727 rsp->in_ptr = (void *)(rsp->ring + rsp->length);
3729 /* Initialize response queue entries */
3731 qlafx00_init_response_q_entries(rsp);
3733 qla2x00_init_response_q_entries(rsp);
3736 ha->tgt.atio_ring_ptr = ha->tgt.atio_ring;
3737 ha->tgt.atio_ring_index = 0;
3738 /* Initialize ATIO queue entries */
3739 qlt_init_atio_q_entries(vha);
3741 ha->isp_ops->config_rings(vha);
3743 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3745 ql_dbg(ql_dbg_init, vha, 0x00d1, "Issue init firmware.\n");
3747 if (IS_QLAFX00(ha)) {
3748 rval = qlafx00_init_firmware(vha, ha->init_cb_size);
3752 /* Update any ISP specific firmware options before initialization. */
3753 ha->isp_ops->update_fw_options(vha);
3755 if (ha->flags.npiv_supported) {
3756 if (ha->operating_mode == LOOP && !IS_CNA_CAPABLE(ha))
3757 ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
3758 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
3761 if (IS_FWI2_CAPABLE(ha)) {
3762 mid_init_cb->options = cpu_to_le16(BIT_1);
3763 mid_init_cb->init_cb.execution_throttle =
3764 cpu_to_le16(ha->cur_fw_xcb_count);
3765 ha->flags.dport_enabled =
3766 (mid_init_cb->init_cb.firmware_options_1 & BIT_7) != 0;
3767 ql_dbg(ql_dbg_init, vha, 0x0191, "DPORT Support: %s.\n",
3768 (ha->flags.dport_enabled) ? "enabled" : "disabled");
3769 /* FA-WWPN Status */
3770 ha->flags.fawwpn_enabled =
3771 (mid_init_cb->init_cb.firmware_options_1 & BIT_6) != 0;
3772 ql_dbg(ql_dbg_init, vha, 0x00bc, "FA-WWPN Support: %s.\n",
3773 (ha->flags.fawwpn_enabled) ? "enabled" : "disabled");
3776 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
3779 ql_log(ql_log_fatal, vha, 0x00d2,
3780 "Init Firmware **** FAILED ****.\n");
3782 ql_dbg(ql_dbg_init, vha, 0x00d3,
3783 "Init Firmware -- success.\n");
3791 * qla2x00_fw_ready() - Waits for firmware ready.
3794 * Returns 0 on success.
3797 qla2x00_fw_ready(scsi_qla_host_t *vha)
3800 unsigned long wtime, mtime, cs84xx_time;
3801 uint16_t min_wait; /* Minimum wait time if loop is down */
3802 uint16_t wait_time; /* Wait time if loop is coming ready */
3804 struct qla_hw_data *ha = vha->hw;
3806 if (IS_QLAFX00(vha->hw))
3807 return qlafx00_fw_ready(vha);
3811 /* Time to wait for loop down */
3812 if (IS_P3P_TYPE(ha))
3818 * Firmware should take at most one RATOV to login, plus 5 seconds for
3819 * our own processing.
3821 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
3822 wait_time = min_wait;
3825 /* Min wait time if loop down */
3826 mtime = jiffies + (min_wait * HZ);
3828 /* wait time before firmware ready */
3829 wtime = jiffies + (wait_time * HZ);
3831 /* Wait for ISP to finish LIP */
3832 if (!vha->flags.init_done)
3833 ql_log(ql_log_info, vha, 0x801e,
3834 "Waiting for LIP to complete.\n");
3837 memset(state, -1, sizeof(state));
3838 rval = qla2x00_get_firmware_state(vha, state);
3839 if (rval == QLA_SUCCESS) {
3840 if (state[0] < FSTATE_LOSS_OF_SYNC) {
3841 vha->device_flags &= ~DFLG_NO_CABLE;
3843 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
3844 ql_dbg(ql_dbg_taskm, vha, 0x801f,
3845 "fw_state=%x 84xx=%x.\n", state[0],
3847 if ((state[2] & FSTATE_LOGGED_IN) &&
3848 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
3849 ql_dbg(ql_dbg_taskm, vha, 0x8028,
3850 "Sending verify iocb.\n");
3852 cs84xx_time = jiffies;
3853 rval = qla84xx_init_chip(vha);
3854 if (rval != QLA_SUCCESS) {
3857 "Init chip failed.\n");
3861 /* Add time taken to initialize. */
3862 cs84xx_time = jiffies - cs84xx_time;
3863 wtime += cs84xx_time;
3864 mtime += cs84xx_time;
3865 ql_dbg(ql_dbg_taskm, vha, 0x8008,
3866 "Increasing wait time by %ld. "
3867 "New time %ld.\n", cs84xx_time,
3870 } else if (state[0] == FSTATE_READY) {
3871 ql_dbg(ql_dbg_taskm, vha, 0x8037,
3872 "F/W Ready - OK.\n");
3874 qla2x00_get_retry_cnt(vha, &ha->retry_count,
3875 &ha->login_timeout, &ha->r_a_tov);
3881 rval = QLA_FUNCTION_FAILED;
3883 if (atomic_read(&vha->loop_down_timer) &&
3884 state[0] != FSTATE_READY) {
3885 /* Loop down. Timeout on min_wait for states
3886 * other than Wait for Login.
3888 if (time_after_eq(jiffies, mtime)) {
3889 ql_log(ql_log_info, vha, 0x8038,
3890 "Cable is unplugged...\n");
3892 vha->device_flags |= DFLG_NO_CABLE;
3897 /* Mailbox cmd failed. Timeout on min_wait. */
3898 if (time_after_eq(jiffies, mtime) ||
3899 ha->flags.isp82xx_fw_hung)
3903 if (time_after_eq(jiffies, wtime))
3906 /* Delay for a while */
3910 ql_dbg(ql_dbg_taskm, vha, 0x803a,
3911 "fw_state=%x (%x, %x, %x, %x %x) curr time=%lx.\n", state[0],
3912 state[1], state[2], state[3], state[4], state[5], jiffies);
3914 if (rval && !(vha->device_flags & DFLG_NO_CABLE)) {
3915 ql_log(ql_log_warn, vha, 0x803b,
3916 "Firmware ready **** FAILED ****.\n");
3923 * qla2x00_configure_hba
3924 * Setup adapter context.
3927 * ha = adapter state pointer.
3936 qla2x00_configure_hba(scsi_qla_host_t *vha)
3945 char connect_type[22];
3946 struct qla_hw_data *ha = vha->hw;
3947 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
3949 unsigned long flags;
3951 /* Get host addresses. */
3952 rval = qla2x00_get_adapter_id(vha,
3953 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
3954 if (rval != QLA_SUCCESS) {
3955 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
3956 IS_CNA_CAPABLE(ha) ||
3957 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
3958 ql_dbg(ql_dbg_disc, vha, 0x2008,
3959 "Loop is in a transition state.\n");
3961 ql_log(ql_log_warn, vha, 0x2009,
3962 "Unable to get host loop ID.\n");
3963 if (IS_FWI2_CAPABLE(ha) && (vha == base_vha) &&
3964 (rval == QLA_COMMAND_ERROR && loop_id == 0x1b)) {
3965 ql_log(ql_log_warn, vha, 0x1151,
3966 "Doing link init.\n");
3967 if (qla24xx_link_initialize(vha) == QLA_SUCCESS)
3970 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
3976 ql_log(ql_log_info, vha, 0x200a,
3977 "Cannot get topology - retrying.\n");
3978 return (QLA_FUNCTION_FAILED);
3981 vha->loop_id = loop_id;
3984 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
3985 ha->operating_mode = LOOP;
3990 ql_dbg(ql_dbg_disc, vha, 0x200b, "HBA in NL topology.\n");
3991 ha->current_topology = ISP_CFG_NL;
3992 strcpy(connect_type, "(Loop)");
3996 ql_dbg(ql_dbg_disc, vha, 0x200c, "HBA in FL topology.\n");
3997 ha->switch_cap = sw_cap;
3998 ha->current_topology = ISP_CFG_FL;
3999 strcpy(connect_type, "(FL_Port)");
4003 ql_dbg(ql_dbg_disc, vha, 0x200d, "HBA in N P2P topology.\n");
4004 ha->operating_mode = P2P;
4005 ha->current_topology = ISP_CFG_N;
4006 strcpy(connect_type, "(N_Port-to-N_Port)");
4010 ql_dbg(ql_dbg_disc, vha, 0x200e, "HBA in F P2P topology.\n");
4011 ha->switch_cap = sw_cap;
4012 ha->operating_mode = P2P;
4013 ha->current_topology = ISP_CFG_F;
4014 strcpy(connect_type, "(F_Port)");
4018 ql_dbg(ql_dbg_disc, vha, 0x200f,
4019 "HBA in unknown topology %x, using NL.\n", topo);
4020 ha->current_topology = ISP_CFG_NL;
4021 strcpy(connect_type, "(Loop)");
4025 /* Save Host port and loop ID. */
4026 /* byte order - Big Endian */
4027 id.b.domain = domain;
4031 spin_lock_irqsave(&ha->hardware_lock, flags);
4032 qlt_update_host_map(vha, id);
4033 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4035 if (!vha->flags.init_done)
4036 ql_log(ql_log_info, vha, 0x2010,
4037 "Topology - %s, Host Loop address 0x%x.\n",
4038 connect_type, vha->loop_id);
4044 qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
4049 struct qla_hw_data *ha = vha->hw;
4050 int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) &&
4051 !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha);
4053 if (memcmp(model, BINZERO, len) != 0) {
4054 strncpy(ha->model_number, model, len);
4055 st = en = ha->model_number;
4058 if (*en != 0x20 && *en != 0x00)
4063 index = (ha->pdev->subsystem_device & 0xff);
4065 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
4066 index < QLA_MODEL_NAMES)
4067 strncpy(ha->model_desc,
4068 qla2x00_model_name[index * 2 + 1],
4069 sizeof(ha->model_desc) - 1);
4071 index = (ha->pdev->subsystem_device & 0xff);
4073 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
4074 index < QLA_MODEL_NAMES) {
4075 strcpy(ha->model_number,
4076 qla2x00_model_name[index * 2]);
4077 strncpy(ha->model_desc,
4078 qla2x00_model_name[index * 2 + 1],
4079 sizeof(ha->model_desc) - 1);
4081 strcpy(ha->model_number, def);
4084 if (IS_FWI2_CAPABLE(ha))
4085 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
4086 sizeof(ha->model_desc));
4089 /* On sparc systems, obtain port and node WWN from firmware
4092 static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
4095 struct qla_hw_data *ha = vha->hw;
4096 struct pci_dev *pdev = ha->pdev;
4097 struct device_node *dp = pci_device_to_OF_node(pdev);
4101 val = of_get_property(dp, "port-wwn", &len);
4102 if (val && len >= WWN_SIZE)
4103 memcpy(nv->port_name, val, WWN_SIZE);
4105 val = of_get_property(dp, "node-wwn", &len);
4106 if (val && len >= WWN_SIZE)
4107 memcpy(nv->node_name, val, WWN_SIZE);
4112 * NVRAM configuration for ISP 2xxx
4115 * ha = adapter block pointer.
4118 * initialization control block in response_ring
4119 * host adapters parameters in host adapter block
4125 qla2x00_nvram_config(scsi_qla_host_t *vha)
4130 uint8_t *dptr1, *dptr2;
4131 struct qla_hw_data *ha = vha->hw;
4132 init_cb_t *icb = ha->init_cb;
4133 nvram_t *nv = ha->nvram;
4134 uint8_t *ptr = ha->nvram;
4135 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
4139 /* Determine NVRAM starting address. */
4140 ha->nvram_size = sizeof(nvram_t);
4142 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
4143 if ((RD_REG_WORD(®->ctrl_status) >> 14) == 1)
4144 ha->nvram_base = 0x80;
4146 /* Get NVRAM data and calculate checksum. */
4147 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
4148 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
4151 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x010f,
4152 "Contents of NVRAM.\n");
4153 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0110,
4154 (uint8_t *)nv, ha->nvram_size);
4156 /* Bad NVRAM data, set defaults parameters. */
4157 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
4158 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
4159 /* Reset NVRAM data. */
4160 ql_log(ql_log_warn, vha, 0x0064,
4161 "Inconsistent NVRAM "
4162 "detected: checksum=0x%x id=%c version=0x%x.\n",
4163 chksum, nv->id[0], nv->nvram_version);
4164 ql_log(ql_log_warn, vha, 0x0065,
4166 "functioning (yet invalid -- WWPN) defaults.\n");
4169 * Set default initialization control block.
4171 memset(nv, 0, ha->nvram_size);
4172 nv->parameter_block_version = ICB_VERSION;
4174 if (IS_QLA23XX(ha)) {
4175 nv->firmware_options[0] = BIT_2 | BIT_1;
4176 nv->firmware_options[1] = BIT_7 | BIT_5;
4177 nv->add_firmware_options[0] = BIT_5;
4178 nv->add_firmware_options[1] = BIT_5 | BIT_4;
4179 nv->frame_payload_size = 2048;
4180 nv->special_options[1] = BIT_7;
4181 } else if (IS_QLA2200(ha)) {
4182 nv->firmware_options[0] = BIT_2 | BIT_1;
4183 nv->firmware_options[1] = BIT_7 | BIT_5;
4184 nv->add_firmware_options[0] = BIT_5;
4185 nv->add_firmware_options[1] = BIT_5 | BIT_4;
4186 nv->frame_payload_size = 1024;
4187 } else if (IS_QLA2100(ha)) {
4188 nv->firmware_options[0] = BIT_3 | BIT_1;
4189 nv->firmware_options[1] = BIT_5;
4190 nv->frame_payload_size = 1024;
4193 nv->max_iocb_allocation = cpu_to_le16(256);
4194 nv->execution_throttle = cpu_to_le16(16);
4195 nv->retry_count = 8;
4196 nv->retry_delay = 1;
4198 nv->port_name[0] = 33;
4199 nv->port_name[3] = 224;
4200 nv->port_name[4] = 139;
4202 qla2xxx_nvram_wwn_from_ofw(vha, nv);
4204 nv->login_timeout = 4;
4207 * Set default host adapter parameters
4209 nv->host_p[1] = BIT_2;
4210 nv->reset_delay = 5;
4211 nv->port_down_retry_count = 8;
4212 nv->max_luns_per_target = cpu_to_le16(8);
4213 nv->link_down_timeout = 60;
4218 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
4220 * The SN2 does not provide BIOS emulation which means you can't change
4221 * potentially bogus BIOS settings. Force the use of default settings
4222 * for link rate and frame size. Hope that the rest of the settings
4225 if (ia64_platform_is("sn2")) {
4226 nv->frame_payload_size = 2048;
4228 nv->special_options[1] = BIT_7;
4232 /* Reset Initialization control block */
4233 memset(icb, 0, ha->init_cb_size);
4236 * Setup driver NVRAM options.
4238 nv->firmware_options[0] |= (BIT_6 | BIT_1);
4239 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
4240 nv->firmware_options[1] |= (BIT_5 | BIT_0);
4241 nv->firmware_options[1] &= ~BIT_4;
4243 if (IS_QLA23XX(ha)) {
4244 nv->firmware_options[0] |= BIT_2;
4245 nv->firmware_options[0] &= ~BIT_3;
4246 nv->special_options[0] &= ~BIT_6;
4247 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
4249 if (IS_QLA2300(ha)) {
4250 if (ha->fb_rev == FPM_2310) {
4251 strcpy(ha->model_number, "QLA2310");
4253 strcpy(ha->model_number, "QLA2300");
4256 qla2x00_set_model_info(vha, nv->model_number,
4257 sizeof(nv->model_number), "QLA23xx");
4259 } else if (IS_QLA2200(ha)) {
4260 nv->firmware_options[0] |= BIT_2;
4262 * 'Point-to-point preferred, else loop' is not a safe
4263 * connection mode setting.
4265 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
4267 /* Force 'loop preferred, else point-to-point'. */
4268 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
4269 nv->add_firmware_options[0] |= BIT_5;
4271 strcpy(ha->model_number, "QLA22xx");
4272 } else /*if (IS_QLA2100(ha))*/ {
4273 strcpy(ha->model_number, "QLA2100");
4277 * Copy over NVRAM RISC parameter block to initialization control block.
4279 dptr1 = (uint8_t *)icb;
4280 dptr2 = (uint8_t *)&nv->parameter_block_version;
4281 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
4283 *dptr1++ = *dptr2++;
4285 /* Copy 2nd half. */
4286 dptr1 = (uint8_t *)icb->add_firmware_options;
4287 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
4289 *dptr1++ = *dptr2++;
4291 /* Use alternate WWN? */
4292 if (nv->host_p[1] & BIT_7) {
4293 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
4294 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
4297 /* Prepare nodename */
4298 if ((icb->firmware_options[1] & BIT_6) == 0) {
4300 * Firmware will apply the following mask if the nodename was
4303 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
4304 icb->node_name[0] &= 0xF0;
4308 * Set host adapter parameters.
4312 * BIT_7 in the host-parameters section allows for modification to
4313 * internal driver logging.
4315 if (nv->host_p[0] & BIT_7)
4316 ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK;
4317 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
4318 /* Always load RISC code on non ISP2[12]00 chips. */
4319 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
4320 ha->flags.disable_risc_code_load = 0;
4321 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
4322 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
4323 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
4324 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
4325 ha->flags.disable_serdes = 0;
4327 ha->operating_mode =
4328 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
4330 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
4331 sizeof(ha->fw_seriallink_options));
4333 /* save HBA serial number */
4334 ha->serial0 = icb->port_name[5];
4335 ha->serial1 = icb->port_name[6];
4336 ha->serial2 = icb->port_name[7];
4337 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
4338 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
4340 icb->execution_throttle = cpu_to_le16(0xFFFF);
4342 ha->retry_count = nv->retry_count;
4344 /* Set minimum login_timeout to 4 seconds. */
4345 if (nv->login_timeout != ql2xlogintimeout)
4346 nv->login_timeout = ql2xlogintimeout;
4347 if (nv->login_timeout < 4)
4348 nv->login_timeout = 4;
4349 ha->login_timeout = nv->login_timeout;
4351 /* Set minimum RATOV to 100 tenths of a second. */
4354 ha->loop_reset_delay = nv->reset_delay;
4356 /* Link Down Timeout = 0:
4358 * When Port Down timer expires we will start returning
4359 * I/O's to OS with "DID_NO_CONNECT".
4361 * Link Down Timeout != 0:
4363 * The driver waits for the link to come up after link down
4364 * before returning I/Os to OS with "DID_NO_CONNECT".
4366 if (nv->link_down_timeout == 0) {
4367 ha->loop_down_abort_time =
4368 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
4370 ha->link_down_timeout = nv->link_down_timeout;
4371 ha->loop_down_abort_time =
4372 (LOOP_DOWN_TIME - ha->link_down_timeout);
4376 * Need enough time to try and get the port back.
4378 ha->port_down_retry_count = nv->port_down_retry_count;
4379 if (qlport_down_retry)
4380 ha->port_down_retry_count = qlport_down_retry;
4381 /* Set login_retry_count */
4382 ha->login_retry_count = nv->retry_count;
4383 if (ha->port_down_retry_count == nv->port_down_retry_count &&
4384 ha->port_down_retry_count > 3)
4385 ha->login_retry_count = ha->port_down_retry_count;
4386 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
4387 ha->login_retry_count = ha->port_down_retry_count;
4388 if (ql2xloginretrycount)
4389 ha->login_retry_count = ql2xloginretrycount;
4391 icb->lun_enables = cpu_to_le16(0);
4392 icb->command_resource_count = 0;
4393 icb->immediate_notify_resource_count = 0;
4394 icb->timeout = cpu_to_le16(0);
4396 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
4398 icb->firmware_options[0] &= ~BIT_3;
4399 icb->add_firmware_options[0] &=
4400 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
4401 icb->add_firmware_options[0] |= BIT_2;
4402 icb->response_accumulation_timer = 3;
4403 icb->interrupt_delay_timer = 5;
4405 vha->flags.process_response_queue = 1;
4408 if (!vha->flags.init_done) {
4409 ha->zio_mode = icb->add_firmware_options[0] &
4410 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4411 ha->zio_timer = icb->interrupt_delay_timer ?
4412 icb->interrupt_delay_timer: 2;
4414 icb->add_firmware_options[0] &=
4415 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
4416 vha->flags.process_response_queue = 0;
4417 if (ha->zio_mode != QLA_ZIO_DISABLED) {
4418 ha->zio_mode = QLA_ZIO_MODE_6;
4420 ql_log(ql_log_info, vha, 0x0068,
4421 "ZIO mode %d enabled; timer delay (%d us).\n",
4422 ha->zio_mode, ha->zio_timer * 100);
4424 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
4425 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
4426 vha->flags.process_response_queue = 1;
4431 ql_log(ql_log_warn, vha, 0x0069,
4432 "NVRAM configuration failed.\n");
4438 qla2x00_rport_del(void *data)
4440 fc_port_t *fcport = data;
4441 struct fc_rport *rport;
4442 unsigned long flags;
4444 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
4445 rport = fcport->drport ? fcport->drport: fcport->rport;
4446 fcport->drport = NULL;
4447 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
4449 ql_dbg(ql_dbg_disc, fcport->vha, 0x210b,
4450 "%s %8phN. rport %p roles %x\n",
4451 __func__, fcport->port_name, rport,
4454 fc_remote_port_delete(rport);
4459 * qla2x00_alloc_fcport() - Allocate a generic fcport.
4461 * @flags: allocation flags
4463 * Returns a pointer to the allocated fcport, or NULL, if none available.
4466 qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
4470 fcport = kzalloc(sizeof(fc_port_t), flags);
4474 /* Setup fcport template structure. */
4476 fcport->port_type = FCT_UNKNOWN;
4477 fcport->loop_id = FC_NO_LOOP_ID;
4478 qla2x00_set_fcport_state(fcport, FCS_UNCONFIGURED);
4479 fcport->supported_classes = FC_COS_UNSPECIFIED;
4481 fcport->ct_desc.ct_sns = dma_alloc_coherent(&vha->hw->pdev->dev,
4482 sizeof(struct ct_sns_pkt), &fcport->ct_desc.ct_sns_dma,
4484 fcport->disc_state = DSC_DELETED;
4485 fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
4486 fcport->deleted = QLA_SESS_DELETED;
4487 fcport->login_retry = vha->hw->login_retry_count;
4488 fcport->login_retry = 5;
4489 fcport->logout_on_delete = 1;
4491 if (!fcport->ct_desc.ct_sns) {
4492 ql_log(ql_log_warn, vha, 0xd049,
4493 "Failed to allocate ct_sns request.\n");
4497 INIT_WORK(&fcport->del_work, qla24xx_delete_sess_fn);
4498 INIT_LIST_HEAD(&fcport->gnl_entry);
4499 INIT_LIST_HEAD(&fcport->list);
4505 qla2x00_free_fcport(fc_port_t *fcport)
4507 if (fcport->ct_desc.ct_sns) {
4508 dma_free_coherent(&fcport->vha->hw->pdev->dev,
4509 sizeof(struct ct_sns_pkt), fcport->ct_desc.ct_sns,
4510 fcport->ct_desc.ct_sns_dma);
4512 fcport->ct_desc.ct_sns = NULL;
4518 * qla2x00_configure_loop
4519 * Updates Fibre Channel Device Database with what is actually on loop.
4522 * ha = adapter block pointer.
4527 * 2 = database was full and device was not configured.
4530 qla2x00_configure_loop(scsi_qla_host_t *vha)
4533 unsigned long flags, save_flags;
4534 struct qla_hw_data *ha = vha->hw;
4537 /* Get Initiator ID */
4538 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
4539 rval = qla2x00_configure_hba(vha);
4540 if (rval != QLA_SUCCESS) {
4541 ql_dbg(ql_dbg_disc, vha, 0x2013,
4542 "Unable to configure HBA.\n");
4547 save_flags = flags = vha->dpc_flags;
4548 ql_dbg(ql_dbg_disc, vha, 0x2014,
4549 "Configure loop -- dpc flags = 0x%lx.\n", flags);
4552 * If we have both an RSCN and PORT UPDATE pending then handle them
4553 * both at the same time.
4555 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
4556 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
4558 qla2x00_get_data_rate(vha);
4560 /* Determine what we need to do */
4561 if (ha->current_topology == ISP_CFG_FL &&
4562 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
4564 set_bit(RSCN_UPDATE, &flags);
4566 } else if (ha->current_topology == ISP_CFG_F &&
4567 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
4569 set_bit(RSCN_UPDATE, &flags);
4570 clear_bit(LOCAL_LOOP_UPDATE, &flags);
4572 } else if (ha->current_topology == ISP_CFG_N) {
4573 clear_bit(RSCN_UPDATE, &flags);
4574 if (ha->flags.rida_fmt2) {
4575 /* With Rida Format 2, the login is already triggered.
4576 * We know who is on the other side of the wire.
4577 * No need to login to do login to find out or drop into
4578 * qla2x00_configure_local_loop().
4580 clear_bit(LOCAL_LOOP_UPDATE, &flags);
4581 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
4583 if (qla_tgt_mode_enabled(vha)) {
4584 /* allow the other side to start the login */
4585 clear_bit(LOCAL_LOOP_UPDATE, &flags);
4586 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
4589 } else if (ha->current_topology == ISP_CFG_NL) {
4590 clear_bit(RSCN_UPDATE, &flags);
4591 set_bit(LOCAL_LOOP_UPDATE, &flags);
4592 } else if (!vha->flags.online ||
4593 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
4594 set_bit(RSCN_UPDATE, &flags);
4595 set_bit(LOCAL_LOOP_UPDATE, &flags);
4598 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
4599 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
4600 ql_dbg(ql_dbg_disc, vha, 0x2015,
4601 "Loop resync needed, failing.\n");
4602 rval = QLA_FUNCTION_FAILED;
4604 rval = qla2x00_configure_local_loop(vha);
4607 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
4608 if (LOOP_TRANSITION(vha)) {
4609 ql_dbg(ql_dbg_disc, vha, 0x2099,
4610 "Needs RSCN update and loop transition.\n");
4611 rval = QLA_FUNCTION_FAILED;
4614 rval = qla2x00_configure_fabric(vha);
4617 if (rval == QLA_SUCCESS) {
4618 if (atomic_read(&vha->loop_down_timer) ||
4619 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
4620 rval = QLA_FUNCTION_FAILED;
4622 atomic_set(&vha->loop_state, LOOP_READY);
4623 ql_dbg(ql_dbg_disc, vha, 0x2069,
4625 ha->flags.fw_init_done = 1;
4628 * Process any ATIO queue entries that came in
4629 * while we weren't online.
4631 if (qla_tgt_mode_enabled(vha) ||
4632 qla_dual_mode_enabled(vha)) {
4633 if (IS_QLA27XX(ha) || IS_QLA83XX(ha)) {
4634 spin_lock_irqsave(&ha->tgt.atio_lock,
4636 qlt_24xx_process_atio_queue(vha, 0);
4637 spin_unlock_irqrestore(
4638 &ha->tgt.atio_lock, flags);
4640 spin_lock_irqsave(&ha->hardware_lock,
4642 qlt_24xx_process_atio_queue(vha, 1);
4643 spin_unlock_irqrestore(
4644 &ha->hardware_lock, flags);
4651 ql_dbg(ql_dbg_disc, vha, 0x206a,
4652 "%s *** FAILED ***.\n", __func__);
4654 ql_dbg(ql_dbg_disc, vha, 0x206b,
4655 "%s: exiting normally.\n", __func__);
4658 /* Restore state if a resync event occurred during processing */
4659 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
4660 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
4661 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
4662 if (test_bit(RSCN_UPDATE, &save_flags)) {
4663 set_bit(RSCN_UPDATE, &vha->dpc_flags);
4672 * Updates Fibre Channel Device Database with local loop devices.
4675 * ha = adapter block pointer.
4679 static int qla24xx_n2n_handle_login(struct scsi_qla_host *vha,
4682 struct qla_hw_data *ha = vha->hw;
4683 int res = QLA_SUCCESS, rval;
4684 int greater_wwpn = 0;
4687 if (ha->current_topology != ISP_CFG_N)
4690 if (wwn_to_u64(vha->port_name) >
4691 wwn_to_u64(vha->n2n_port_name)) {
4692 ql_dbg(ql_dbg_disc, vha, 0x2002,
4693 "HBA WWPN is greater %llx > target %llx\n",
4694 wwn_to_u64(vha->port_name),
4695 wwn_to_u64(vha->n2n_port_name));
4697 fcport->d_id.b24 = vha->n2n_id;
4700 fcport->loop_id = vha->loop_id;
4701 fcport->fc4f_nvme = 0;
4704 ql_dbg(ql_dbg_disc, vha, 0x4001,
4705 "Initiate N2N login handler: HBA port_id=%06x loopid=%d\n",
4706 fcport->d_id.b24, vha->loop_id);
4708 /* Fill in member data. */
4709 if (!greater_wwpn) {
4710 rval = qla2x00_get_port_database(vha, fcport, 0);
4711 ql_dbg(ql_dbg_disc, vha, 0x1051,
4712 "Remote login-state (%x/%x) port_id=%06x loop_id=%x, rval=%d\n",
4713 fcport->current_login_state, fcport->last_login_state,
4714 fcport->d_id.b24, fcport->loop_id, rval);
4716 if (((fcport->current_login_state & 0xf) == 0x4) ||
4717 ((fcport->current_login_state & 0xf) == 0x6))
4721 if (logged_in || greater_wwpn) {
4722 if (!vha->nvme_local_port && vha->flags.nvme_enabled)
4723 qla_nvme_register_hba(vha);
4725 /* Set connected N_Port d_id */
4726 if (vha->flags.nvme_enabled)
4727 fcport->fc4f_nvme = 1;
4729 fcport->scan_state = QLA_FCPORT_FOUND;
4730 fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
4731 fcport->disc_state = DSC_GNL;
4732 fcport->n2n_flag = 1;
4734 vha->hw->flags.gpsc_supported = 0;
4737 ql_dbg(ql_dbg_disc, vha, 0x20e5,
4738 "%s %d PLOGI ELS %8phC\n",
4739 __func__, __LINE__, fcport->port_name);
4741 res = qla24xx_els_dcmd2_iocb(vha, ELS_DCMD_PLOGI,
4742 fcport, fcport->d_id);
4745 if (res != QLA_SUCCESS) {
4746 ql_log(ql_log_info, vha, 0xd04d,
4747 "PLOGI Failed: portid=%06x - retrying\n",
4751 /* State 0x6 means FCP PRLI complete */
4752 if ((fcport->current_login_state & 0xf) == 0x6) {
4753 ql_dbg(ql_dbg_disc, vha, 0x2118,
4754 "%s %d %8phC post GPDB work\n",
4755 __func__, __LINE__, fcport->port_name);
4756 fcport->chip_reset =
4757 vha->hw->base_qpair->chip_reset;
4758 qla24xx_post_gpdb_work(vha, fcport, 0);
4760 ql_dbg(ql_dbg_disc, vha, 0x2118,
4761 "%s %d %8phC post NVMe PRLI\n",
4762 __func__, __LINE__, fcport->port_name);
4763 qla24xx_post_prli_work(vha, fcport);
4767 /* Wait for next database change */
4768 set_bit(N2N_LOGIN_NEEDED, &vha->dpc_flags);
4775 * qla2x00_configure_local_loop
4776 * Updates Fibre Channel Device Database with local loop devices.
4779 * ha = adapter block pointer.
4785 qla2x00_configure_local_loop(scsi_qla_host_t *vha)
4790 fc_port_t *fcport, *new_fcport;
4796 uint8_t domain, area, al_pa;
4797 struct qla_hw_data *ha = vha->hw;
4798 unsigned long flags;
4802 entries = MAX_FIBRE_DEVICES_LOOP;
4804 /* Get list of logged in devices. */
4805 memset(ha->gid_list, 0, qla2x00_gid_list_size(ha));
4806 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
4808 if (rval != QLA_SUCCESS)
4809 goto cleanup_allocation;
4811 ql_dbg(ql_dbg_disc, vha, 0x2011,
4812 "Entries in ID list (%d).\n", entries);
4813 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2075,
4814 (uint8_t *)ha->gid_list,
4815 entries * sizeof(struct gid_list_info));
4817 list_for_each_entry(fcport, &vha->vp_fcports, list) {
4818 fcport->scan_state = QLA_FCPORT_SCAN;
4821 /* Allocate temporary fcport for any new fcports discovered. */
4822 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
4823 if (new_fcport == NULL) {
4824 ql_log(ql_log_warn, vha, 0x2012,
4825 "Memory allocation failed for fcport.\n");
4826 rval = QLA_MEMORY_ALLOC_FAILED;
4827 goto cleanup_allocation;
4829 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
4831 /* Inititae N2N login. */
4832 if (test_and_clear_bit(N2N_LOGIN_NEEDED, &vha->dpc_flags)) {
4833 rval = qla24xx_n2n_handle_login(vha, new_fcport);
4834 if (rval != QLA_SUCCESS)
4835 goto cleanup_allocation;
4839 /* Add devices to port list. */
4840 id_iter = (char *)ha->gid_list;
4841 for (index = 0; index < entries; index++) {
4842 domain = ((struct gid_list_info *)id_iter)->domain;
4843 area = ((struct gid_list_info *)id_iter)->area;
4844 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
4845 if (IS_QLA2100(ha) || IS_QLA2200(ha))
4846 loop_id = (uint16_t)
4847 ((struct gid_list_info *)id_iter)->loop_id_2100;
4849 loop_id = le16_to_cpu(
4850 ((struct gid_list_info *)id_iter)->loop_id);
4851 id_iter += ha->gid_list_info_size;
4853 /* Bypass reserved domain fields. */
4854 if ((domain & 0xf0) == 0xf0)
4857 /* Bypass if not same domain and area of adapter. */
4858 if (area && domain &&
4859 (area != vha->d_id.b.area || domain != vha->d_id.b.domain))
4862 /* Bypass invalid local loop ID. */
4863 if (loop_id > LAST_LOCAL_LOOP_ID)
4866 memset(new_fcport->port_name, 0, WWN_SIZE);
4868 /* Fill in member data. */
4869 new_fcport->d_id.b.domain = domain;
4870 new_fcport->d_id.b.area = area;
4871 new_fcport->d_id.b.al_pa = al_pa;
4872 new_fcport->loop_id = loop_id;
4873 new_fcport->scan_state = QLA_FCPORT_FOUND;
4875 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
4876 if (rval2 != QLA_SUCCESS) {
4877 ql_dbg(ql_dbg_disc, vha, 0x2097,
4878 "Failed to retrieve fcport information "
4879 "-- get_port_database=%x, loop_id=0x%04x.\n",
4880 rval2, new_fcport->loop_id);
4881 /* Skip retry if N2N */
4882 if (ha->current_topology != ISP_CFG_N) {
4883 ql_dbg(ql_dbg_disc, vha, 0x2105,
4884 "Scheduling resync.\n");
4885 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4890 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
4891 /* Check for matching device in port list. */
4894 list_for_each_entry(fcport, &vha->vp_fcports, list) {
4895 if (memcmp(new_fcport->port_name, fcport->port_name,
4899 fcport->flags &= ~FCF_FABRIC_DEVICE;
4900 fcport->loop_id = new_fcport->loop_id;
4901 fcport->port_type = new_fcport->port_type;
4902 fcport->d_id.b24 = new_fcport->d_id.b24;
4903 memcpy(fcport->node_name, new_fcport->node_name,
4905 fcport->scan_state = QLA_FCPORT_FOUND;
4911 /* New device, add to fcports list. */
4912 list_add_tail(&new_fcport->list, &vha->vp_fcports);
4914 /* Allocate a new replacement fcport. */
4915 fcport = new_fcport;
4917 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
4919 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
4921 if (new_fcport == NULL) {
4922 ql_log(ql_log_warn, vha, 0xd031,
4923 "Failed to allocate memory for fcport.\n");
4924 rval = QLA_MEMORY_ALLOC_FAILED;
4925 goto cleanup_allocation;
4927 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
4928 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
4931 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
4933 /* Base iIDMA settings on HBA port speed. */
4934 fcport->fp_speed = ha->link_data_rate;
4939 list_for_each_entry(fcport, &vha->vp_fcports, list) {
4940 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
4943 if (fcport->scan_state == QLA_FCPORT_SCAN) {
4944 if ((qla_dual_mode_enabled(vha) ||
4945 qla_ini_mode_enabled(vha)) &&
4946 atomic_read(&fcport->state) == FCS_ONLINE) {
4947 qla2x00_mark_device_lost(vha, fcport,
4948 ql2xplogiabsentdevice, 0);
4949 if (fcport->loop_id != FC_NO_LOOP_ID &&
4950 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
4951 fcport->port_type != FCT_INITIATOR &&
4952 fcport->port_type != FCT_BROADCAST) {
4953 ql_dbg(ql_dbg_disc, vha, 0x20f0,
4954 "%s %d %8phC post del sess\n",
4958 qlt_schedule_sess_for_deletion_lock
4965 if (fcport->scan_state == QLA_FCPORT_FOUND)
4966 qla24xx_fcport_handle_login(vha, fcport);
4972 if (rval != QLA_SUCCESS) {
4973 ql_dbg(ql_dbg_disc, vha, 0x2098,
4974 "Configure local loop error exit: rval=%x.\n", rval);
4981 qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
4984 uint16_t mb[MAILBOX_REGISTER_COUNT];
4985 struct qla_hw_data *ha = vha->hw;
4987 if (!IS_IIDMA_CAPABLE(ha))
4990 if (atomic_read(&fcport->state) != FCS_ONLINE)
4993 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
4994 fcport->fp_speed > ha->link_data_rate)
4997 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
4999 if (rval != QLA_SUCCESS) {
5000 ql_dbg(ql_dbg_disc, vha, 0x2004,
5001 "Unable to adjust iIDMA %8phN -- %04x %x %04x %04x.\n",
5002 fcport->port_name, rval, fcport->fp_speed, mb[0], mb[1]);
5004 ql_dbg(ql_dbg_disc, vha, 0x2005,
5005 "iIDMA adjusted to %s GB/s on %8phN.\n",
5006 qla2x00_get_link_speed_str(ha, fcport->fp_speed),
5011 /* qla2x00_reg_remote_port is reserved for Initiator Mode only.*/
5013 qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
5015 struct fc_rport_identifiers rport_ids;
5016 struct fc_rport *rport;
5017 unsigned long flags;
5019 rport_ids.node_name = wwn_to_u64(fcport->node_name);
5020 rport_ids.port_name = wwn_to_u64(fcport->port_name);
5021 rport_ids.port_id = fcport->d_id.b.domain << 16 |
5022 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
5023 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
5024 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
5026 ql_log(ql_log_warn, vha, 0x2006,
5027 "Unable to allocate fc remote port.\n");
5031 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
5032 *((fc_port_t **)rport->dd_data) = fcport;
5033 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
5035 rport->supported_classes = fcport->supported_classes;
5037 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
5038 if (fcport->port_type == FCT_INITIATOR)
5039 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
5040 if (fcport->port_type == FCT_TARGET)
5041 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
5043 ql_dbg(ql_dbg_disc, vha, 0x20ee,
5044 "%s %8phN. rport %p is %s mode\n",
5045 __func__, fcport->port_name, rport,
5046 (fcport->port_type == FCT_TARGET) ? "tgt" : "ini");
5048 fc_remote_port_rolechg(rport, rport_ids.roles);
5052 * qla2x00_update_fcport
5053 * Updates device on list.
5056 * ha = adapter block pointer.
5057 * fcport = port structure pointer.
5067 qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
5071 if (IS_SW_RESV_ADDR(fcport->d_id))
5074 ql_dbg(ql_dbg_disc, vha, 0x20ef, "%s %8phC\n",
5075 __func__, fcport->port_name);
5077 if (IS_QLAFX00(vha->hw)) {
5078 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
5081 fcport->login_retry = 0;
5082 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
5083 fcport->disc_state = DSC_LOGIN_COMPLETE;
5084 fcport->deleted = 0;
5085 fcport->logout_on_delete = 1;
5087 if (fcport->fc4f_nvme) {
5088 qla_nvme_register_remote(vha, fcport);
5092 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
5093 qla2x00_iidma_fcport(vha, fcport);
5094 qla24xx_update_fcport_fcp_prio(vha, fcport);
5097 switch (vha->host->active_mode) {
5098 case MODE_INITIATOR:
5099 qla2x00_reg_remote_port(vha, fcport);
5102 if (!vha->vha_tgt.qla_tgt->tgt_stop &&
5103 !vha->vha_tgt.qla_tgt->tgt_stopped)
5104 qlt_fc_port_added(vha, fcport);
5107 qla2x00_reg_remote_port(vha, fcport);
5108 if (!vha->vha_tgt.qla_tgt->tgt_stop &&
5109 !vha->vha_tgt.qla_tgt->tgt_stopped)
5110 qlt_fc_port_added(vha, fcport);
5118 * qla2x00_configure_fabric
5119 * Setup SNS devices with loop ID's.
5122 * ha = adapter block pointer.
5129 qla2x00_configure_fabric(scsi_qla_host_t *vha)
5133 uint16_t mb[MAILBOX_REGISTER_COUNT];
5135 LIST_HEAD(new_fcports);
5136 struct qla_hw_data *ha = vha->hw;
5139 /* If FL port exists, then SNS is present */
5140 if (IS_FWI2_CAPABLE(ha))
5141 loop_id = NPH_F_PORT;
5143 loop_id = SNS_FL_PORT;
5144 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
5145 if (rval != QLA_SUCCESS) {
5146 ql_dbg(ql_dbg_disc, vha, 0x20a0,
5147 "MBX_GET_PORT_NAME failed, No FL Port.\n");
5149 vha->device_flags &= ~SWITCH_FOUND;
5150 return (QLA_SUCCESS);
5152 vha->device_flags |= SWITCH_FOUND;
5155 if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) {
5156 rval = qla2x00_send_change_request(vha, 0x3, 0);
5157 if (rval != QLA_SUCCESS)
5158 ql_log(ql_log_warn, vha, 0x121,
5159 "Failed to enable receiving of RSCN requests: 0x%x.\n",
5165 qla2x00_mgmt_svr_login(vha);
5168 if (ql2xfdmienable &&
5169 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
5170 qla2x00_fdmi_register(vha);
5172 /* Ensure we are logged into the SNS. */
5173 loop_id = NPH_SNS_LID(ha);
5174 rval = ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
5175 0xfc, mb, BIT_1|BIT_0);
5176 if (rval != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
5177 ql_dbg(ql_dbg_disc, vha, 0x20a1,
5178 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x mb[6]=%x mb[7]=%x (%x).\n",
5179 loop_id, mb[0], mb[1], mb[2], mb[6], mb[7], rval);
5180 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5183 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
5184 if (qla2x00_rft_id(vha)) {
5186 ql_dbg(ql_dbg_disc, vha, 0x20a2,
5187 "Register FC-4 TYPE failed.\n");
5188 if (test_bit(LOOP_RESYNC_NEEDED,
5192 if (qla2x00_rff_id(vha, FC4_TYPE_FCP_SCSI)) {
5194 ql_dbg(ql_dbg_disc, vha, 0x209a,
5195 "Register FC-4 Features failed.\n");
5196 if (test_bit(LOOP_RESYNC_NEEDED,
5200 if (vha->flags.nvme_enabled) {
5201 if (qla2x00_rff_id(vha, FC_TYPE_NVME)) {
5202 ql_dbg(ql_dbg_disc, vha, 0x2049,
5203 "Register NVME FC Type Features failed.\n");
5206 if (qla2x00_rnn_id(vha)) {
5208 ql_dbg(ql_dbg_disc, vha, 0x2104,
5209 "Register Node Name failed.\n");
5210 if (test_bit(LOOP_RESYNC_NEEDED,
5213 } else if (qla2x00_rsnn_nn(vha)) {
5215 ql_dbg(ql_dbg_disc, vha, 0x209b,
5216 "Register Symbolic Node Name failed.\n");
5217 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5223 /* Mark the time right before querying FW for connected ports.
5224 * This process is long, asynchronous and by the time it's done,
5225 * collected information might not be accurate anymore. E.g.
5226 * disconnected port might have re-connected and a brand new
5227 * session has been created. In this case session's generation
5228 * will be newer than discovery_gen. */
5229 qlt_do_generation_tick(vha, &discovery_gen);
5231 if (USE_ASYNC_SCAN(ha)) {
5233 rval = qla24xx_async_gpnft(vha, FC4_TYPE_FCP_SCSI);
5235 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5237 list_for_each_entry(fcport, &vha->vp_fcports, list)
5238 fcport->scan_state = QLA_FCPORT_SCAN;
5240 rval = qla2x00_find_all_fabric_devs(vha);
5242 if (rval != QLA_SUCCESS)
5246 if (!vha->nvme_local_port && vha->flags.nvme_enabled)
5247 qla_nvme_register_hba(vha);
5250 ql_dbg(ql_dbg_disc, vha, 0x2068,
5251 "Configure fabric error exit rval=%d.\n", rval);
5257 * qla2x00_find_all_fabric_devs
5260 * ha = adapter block pointer.
5261 * dev = database device entry pointer.
5270 qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha)
5274 fc_port_t *fcport, *new_fcport;
5279 int first_dev, last_dev;
5280 port_id_t wrap = {}, nxt_d_id;
5281 struct qla_hw_data *ha = vha->hw;
5282 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
5283 unsigned long flags;
5287 /* Try GID_PT to get device list, else GAN. */
5289 ha->swl = kcalloc(ha->max_fibre_devices, sizeof(sw_info_t),
5294 ql_dbg(ql_dbg_disc, vha, 0x209c,
5295 "GID_PT allocations failed, fallback on GA_NXT.\n");
5297 memset(swl, 0, ha->max_fibre_devices * sizeof(sw_info_t));
5298 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
5300 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5302 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
5304 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5306 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
5308 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5310 } else if (qla2x00_gfpn_id(vha, swl) != QLA_SUCCESS) {
5312 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5316 /* If other queries succeeded probe for FC-4 type */
5318 qla2x00_gff_id(vha, swl);
5319 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5325 /* Allocate temporary fcport for any new fcports discovered. */
5326 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5327 if (new_fcport == NULL) {
5328 ql_log(ql_log_warn, vha, 0x209d,
5329 "Failed to allocate memory for fcport.\n");
5330 return (QLA_MEMORY_ALLOC_FAILED);
5332 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
5333 /* Set start port ID scan at adapter ID. */
5337 /* Starting free loop ID. */
5338 loop_id = ha->min_external_loopid;
5339 for (; loop_id <= ha->max_loop_id; loop_id++) {
5340 if (qla2x00_is_reserved_id(vha, loop_id))
5343 if (ha->current_topology == ISP_CFG_FL &&
5344 (atomic_read(&vha->loop_down_timer) ||
5345 LOOP_TRANSITION(vha))) {
5346 atomic_set(&vha->loop_down_timer, 0);
5347 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5348 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5354 wrap.b24 = new_fcport->d_id.b24;
5356 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
5357 memcpy(new_fcport->node_name,
5358 swl[swl_idx].node_name, WWN_SIZE);
5359 memcpy(new_fcport->port_name,
5360 swl[swl_idx].port_name, WWN_SIZE);
5361 memcpy(new_fcport->fabric_port_name,
5362 swl[swl_idx].fabric_port_name, WWN_SIZE);
5363 new_fcport->fp_speed = swl[swl_idx].fp_speed;
5364 new_fcport->fc4_type = swl[swl_idx].fc4_type;
5366 new_fcport->nvme_flag = 0;
5367 new_fcport->fc4f_nvme = 0;
5368 if (vha->flags.nvme_enabled &&
5369 swl[swl_idx].fc4f_nvme) {
5370 new_fcport->fc4f_nvme =
5371 swl[swl_idx].fc4f_nvme;
5372 ql_log(ql_log_info, vha, 0x2131,
5373 "FOUND: NVME port %8phC as FC Type 28h\n",
5374 new_fcport->port_name);
5377 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
5383 /* Send GA_NXT to the switch */
5384 rval = qla2x00_ga_nxt(vha, new_fcport);
5385 if (rval != QLA_SUCCESS) {
5386 ql_log(ql_log_warn, vha, 0x209e,
5387 "SNS scan failed -- assuming "
5388 "zero-entry result.\n");
5394 /* If wrap on switch device list, exit. */
5396 wrap.b24 = new_fcport->d_id.b24;
5398 } else if (new_fcport->d_id.b24 == wrap.b24) {
5399 ql_dbg(ql_dbg_disc, vha, 0x209f,
5400 "Device wrap (%02x%02x%02x).\n",
5401 new_fcport->d_id.b.domain,
5402 new_fcport->d_id.b.area,
5403 new_fcport->d_id.b.al_pa);
5407 /* Bypass if same physical adapter. */
5408 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
5411 /* Bypass virtual ports of the same host. */
5412 if (qla2x00_is_a_vp_did(vha, new_fcport->d_id.b24))
5415 /* Bypass if same domain and area of adapter. */
5416 if (((new_fcport->d_id.b24 & 0xffff00) ==
5417 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
5421 /* Bypass reserved domain fields. */
5422 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
5425 /* Bypass ports whose FCP-4 type is not FCP_SCSI */
5426 if (ql2xgffidenable &&
5427 (new_fcport->fc4_type != FC4_TYPE_FCP_SCSI &&
5428 new_fcport->fc4_type != FC4_TYPE_UNKNOWN))
5431 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5433 /* Locate matching device in database. */
5435 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5436 if (memcmp(new_fcport->port_name, fcport->port_name,
5440 fcport->scan_state = QLA_FCPORT_FOUND;
5444 /* Update port state. */
5445 memcpy(fcport->fabric_port_name,
5446 new_fcport->fabric_port_name, WWN_SIZE);
5447 fcport->fp_speed = new_fcport->fp_speed;
5450 * If address the same and state FCS_ONLINE
5451 * (or in target mode), nothing changed.
5453 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
5454 (atomic_read(&fcport->state) == FCS_ONLINE ||
5455 (vha->host->active_mode == MODE_TARGET))) {
5460 * If device was not a fabric device before.
5462 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
5463 fcport->d_id.b24 = new_fcport->d_id.b24;
5464 qla2x00_clear_loop_id(fcport);
5465 fcport->flags |= (FCF_FABRIC_DEVICE |
5471 * Port ID changed or device was marked to be updated;
5472 * Log it out if still logged in and mark it for
5475 if (qla_tgt_mode_enabled(base_vha)) {
5476 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf080,
5477 "port changed FC ID, %8phC"
5478 " old %x:%x:%x (loop_id 0x%04x)-> new %x:%x:%x\n",
5480 fcport->d_id.b.domain,
5481 fcport->d_id.b.area,
5482 fcport->d_id.b.al_pa,
5484 new_fcport->d_id.b.domain,
5485 new_fcport->d_id.b.area,
5486 new_fcport->d_id.b.al_pa);
5487 fcport->d_id.b24 = new_fcport->d_id.b24;
5491 fcport->d_id.b24 = new_fcport->d_id.b24;
5492 fcport->flags |= FCF_LOGIN_NEEDED;
5497 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5500 /* If device was not in our fcports list, then add it. */
5501 new_fcport->scan_state = QLA_FCPORT_FOUND;
5502 list_add_tail(&new_fcport->list, &vha->vp_fcports);
5504 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5507 /* Allocate a new replacement fcport. */
5508 nxt_d_id.b24 = new_fcport->d_id.b24;
5509 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5510 if (new_fcport == NULL) {
5511 ql_log(ql_log_warn, vha, 0xd032,
5512 "Memory allocation failed for fcport.\n");
5513 return (QLA_MEMORY_ALLOC_FAILED);
5515 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
5516 new_fcport->d_id.b24 = nxt_d_id.b24;
5519 qla2x00_free_fcport(new_fcport);
5522 * Logout all previous fabric dev marked lost, except FCP2 devices.
5524 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5525 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5528 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
5529 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
5532 if (fcport->scan_state == QLA_FCPORT_SCAN) {
5533 if ((qla_dual_mode_enabled(vha) ||
5534 qla_ini_mode_enabled(vha)) &&
5535 atomic_read(&fcport->state) == FCS_ONLINE) {
5536 qla2x00_mark_device_lost(vha, fcport,
5537 ql2xplogiabsentdevice, 0);
5538 if (fcport->loop_id != FC_NO_LOOP_ID &&
5539 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
5540 fcport->port_type != FCT_INITIATOR &&
5541 fcport->port_type != FCT_BROADCAST) {
5542 ql_dbg(ql_dbg_disc, vha, 0x20f0,
5543 "%s %d %8phC post del sess\n",
5547 qlt_schedule_sess_for_deletion_lock
5554 if (fcport->scan_state == QLA_FCPORT_FOUND)
5555 qla24xx_fcport_handle_login(vha, fcport);
5561 * qla2x00_find_new_loop_id
5562 * Scan through our port list and find a new usable loop ID.
5565 * ha: adapter state pointer.
5566 * dev: port structure pointer.
5569 * qla2x00 local function return status code.
5575 qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
5578 struct qla_hw_data *ha = vha->hw;
5579 unsigned long flags = 0;
5583 spin_lock_irqsave(&ha->vport_slock, flags);
5585 dev->loop_id = find_first_zero_bit(ha->loop_id_map,
5587 if (dev->loop_id >= LOOPID_MAP_SIZE ||
5588 qla2x00_is_reserved_id(vha, dev->loop_id)) {
5589 dev->loop_id = FC_NO_LOOP_ID;
5590 rval = QLA_FUNCTION_FAILED;
5592 set_bit(dev->loop_id, ha->loop_id_map);
5594 spin_unlock_irqrestore(&ha->vport_slock, flags);
5596 if (rval == QLA_SUCCESS)
5597 ql_dbg(ql_dbg_disc, dev->vha, 0x2086,
5598 "Assigning new loopid=%x, portid=%x.\n",
5599 dev->loop_id, dev->d_id.b24);
5601 ql_log(ql_log_warn, dev->vha, 0x2087,
5602 "No loop_id's available, portid=%x.\n",
5610 * qla2x00_fabric_login
5611 * Issue fabric login command.
5614 * ha = adapter block pointer.
5615 * device = pointer to FC device type structure.
5618 * 0 - Login successfully
5620 * 2 - Initiator device
5624 qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
5625 uint16_t *next_loopid)
5629 uint16_t tmp_loopid;
5630 uint16_t mb[MAILBOX_REGISTER_COUNT];
5631 struct qla_hw_data *ha = vha->hw;
5637 ql_dbg(ql_dbg_disc, vha, 0x2000,
5638 "Trying Fabric Login w/loop id 0x%04x for port "
5640 fcport->loop_id, fcport->d_id.b.domain,
5641 fcport->d_id.b.area, fcport->d_id.b.al_pa);
5643 /* Login fcport on switch. */
5644 rval = ha->isp_ops->fabric_login(vha, fcport->loop_id,
5645 fcport->d_id.b.domain, fcport->d_id.b.area,
5646 fcport->d_id.b.al_pa, mb, BIT_0);
5647 if (rval != QLA_SUCCESS) {
5650 if (mb[0] == MBS_PORT_ID_USED) {
5652 * Device has another loop ID. The firmware team
5653 * recommends the driver perform an implicit login with
5654 * the specified ID again. The ID we just used is save
5655 * here so we return with an ID that can be tried by
5659 tmp_loopid = fcport->loop_id;
5660 fcport->loop_id = mb[1];
5662 ql_dbg(ql_dbg_disc, vha, 0x2001,
5663 "Fabric Login: port in use - next loop "
5664 "id=0x%04x, port id= %02x%02x%02x.\n",
5665 fcport->loop_id, fcport->d_id.b.domain,
5666 fcport->d_id.b.area, fcport->d_id.b.al_pa);
5668 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
5673 /* A retry occurred before. */
5674 *next_loopid = tmp_loopid;
5677 * No retry occurred before. Just increment the
5678 * ID value for next login.
5680 *next_loopid = (fcport->loop_id + 1);
5683 if (mb[1] & BIT_0) {
5684 fcport->port_type = FCT_INITIATOR;
5686 fcport->port_type = FCT_TARGET;
5687 if (mb[1] & BIT_1) {
5688 fcport->flags |= FCF_FCP2_DEVICE;
5693 fcport->supported_classes |= FC_COS_CLASS2;
5695 fcport->supported_classes |= FC_COS_CLASS3;
5697 if (IS_FWI2_CAPABLE(ha)) {
5700 FCF_CONF_COMP_SUPPORTED;
5705 } else if (mb[0] == MBS_LOOP_ID_USED) {
5707 * Loop ID already used, try next loop ID.
5710 rval = qla2x00_find_new_loop_id(vha, fcport);
5711 if (rval != QLA_SUCCESS) {
5712 /* Ran out of loop IDs to use */
5715 } else if (mb[0] == MBS_COMMAND_ERROR) {
5717 * Firmware possibly timed out during login. If NO
5718 * retries are left to do then the device is declared
5721 *next_loopid = fcport->loop_id;
5722 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
5723 fcport->d_id.b.domain, fcport->d_id.b.area,
5724 fcport->d_id.b.al_pa);
5725 qla2x00_mark_device_lost(vha, fcport, 1, 0);
5731 * unrecoverable / not handled error
5733 ql_dbg(ql_dbg_disc, vha, 0x2002,
5734 "Failed=%x port_id=%02x%02x%02x loop_id=%x "
5735 "jiffies=%lx.\n", mb[0], fcport->d_id.b.domain,
5736 fcport->d_id.b.area, fcport->d_id.b.al_pa,
5737 fcport->loop_id, jiffies);
5739 *next_loopid = fcport->loop_id;
5740 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
5741 fcport->d_id.b.domain, fcport->d_id.b.area,
5742 fcport->d_id.b.al_pa);
5743 qla2x00_clear_loop_id(fcport);
5744 fcport->login_retry = 0;
5755 * qla2x00_local_device_login
5756 * Issue local device login command.
5759 * ha = adapter block pointer.
5760 * loop_id = loop id of device to login to.
5762 * Returns (Where's the #define!!!!):
5763 * 0 - Login successfully
5768 qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
5771 uint16_t mb[MAILBOX_REGISTER_COUNT];
5773 memset(mb, 0, sizeof(mb));
5774 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
5775 if (rval == QLA_SUCCESS) {
5776 /* Interrogate mailbox registers for any errors */
5777 if (mb[0] == MBS_COMMAND_ERROR)
5779 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
5780 /* device not in PCB table */
5788 * qla2x00_loop_resync
5789 * Resync with fibre channel devices.
5792 * ha = adapter block pointer.
5798 qla2x00_loop_resync(scsi_qla_host_t *vha)
5800 int rval = QLA_SUCCESS;
5802 struct req_que *req;
5803 struct rsp_que *rsp;
5808 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
5809 if (vha->flags.online) {
5810 if (!(rval = qla2x00_fw_ready(vha))) {
5811 /* Wait at most MAX_TARGET RSCNs for a stable link. */
5814 if (!IS_QLAFX00(vha->hw)) {
5816 * Issue a marker after FW becomes
5819 qla2x00_marker(vha, req, rsp, 0, 0,
5821 vha->marker_needed = 0;
5824 /* Remap devices on Loop. */
5825 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5827 if (IS_QLAFX00(vha->hw))
5828 qlafx00_configure_devices(vha);
5830 qla2x00_configure_loop(vha);
5833 } while (!atomic_read(&vha->loop_down_timer) &&
5834 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
5835 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
5840 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
5841 return (QLA_FUNCTION_FAILED);
5844 ql_dbg(ql_dbg_disc, vha, 0x206c,
5845 "%s *** FAILED ***.\n", __func__);
5851 * qla2x00_perform_loop_resync
5852 * Description: This function will set the appropriate flags and call
5853 * qla2x00_loop_resync. If successful loop will be resynced
5854 * Arguments : scsi_qla_host_t pointer
5855 * returm : Success or Failure
5858 int qla2x00_perform_loop_resync(scsi_qla_host_t *ha)
5862 if (!test_and_set_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags)) {
5863 /*Configure the flags so that resync happens properly*/
5864 atomic_set(&ha->loop_down_timer, 0);
5865 if (!(ha->device_flags & DFLG_NO_CABLE)) {
5866 atomic_set(&ha->loop_state, LOOP_UP);
5867 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
5868 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
5869 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
5871 rval = qla2x00_loop_resync(ha);
5873 atomic_set(&ha->loop_state, LOOP_DEAD);
5875 clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
5882 qla2x00_update_fcports(scsi_qla_host_t *base_vha)
5885 struct scsi_qla_host *vha;
5886 struct qla_hw_data *ha = base_vha->hw;
5887 unsigned long flags;
5889 spin_lock_irqsave(&ha->vport_slock, flags);
5890 /* Go with deferred removal of rport references. */
5891 list_for_each_entry(vha, &base_vha->hw->vp_list, list) {
5892 atomic_inc(&vha->vref_count);
5893 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5894 if (fcport->drport &&
5895 atomic_read(&fcport->state) != FCS_UNCONFIGURED) {
5896 spin_unlock_irqrestore(&ha->vport_slock, flags);
5897 qla2x00_rport_del(fcport);
5899 spin_lock_irqsave(&ha->vport_slock, flags);
5902 atomic_dec(&vha->vref_count);
5903 wake_up(&vha->vref_waitq);
5905 spin_unlock_irqrestore(&ha->vport_slock, flags);
5908 /* Assumes idc_lock always held on entry */
5910 qla83xx_reset_ownership(scsi_qla_host_t *vha)
5912 struct qla_hw_data *ha = vha->hw;
5913 uint32_t drv_presence, drv_presence_mask;
5914 uint32_t dev_part_info1, dev_part_info2, class_type;
5915 uint32_t class_type_mask = 0x3;
5916 uint16_t fcoe_other_function = 0xffff, i;
5918 if (IS_QLA8044(ha)) {
5919 drv_presence = qla8044_rd_direct(vha,
5920 QLA8044_CRB_DRV_ACTIVE_INDEX);
5921 dev_part_info1 = qla8044_rd_direct(vha,
5922 QLA8044_CRB_DEV_PART_INFO_INDEX);
5923 dev_part_info2 = qla8044_rd_direct(vha,
5924 QLA8044_CRB_DEV_PART_INFO2);
5926 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
5927 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO1, &dev_part_info1);
5928 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO2, &dev_part_info2);
5930 for (i = 0; i < 8; i++) {
5931 class_type = ((dev_part_info1 >> (i * 4)) & class_type_mask);
5932 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
5933 (i != ha->portnum)) {
5934 fcoe_other_function = i;
5938 if (fcoe_other_function == 0xffff) {
5939 for (i = 0; i < 8; i++) {
5940 class_type = ((dev_part_info2 >> (i * 4)) &
5942 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
5943 ((i + 8) != ha->portnum)) {
5944 fcoe_other_function = i + 8;
5950 * Prepare drv-presence mask based on fcoe functions present.
5951 * However consider only valid physical fcoe function numbers (0-15).
5953 drv_presence_mask = ~((1 << (ha->portnum)) |
5954 ((fcoe_other_function == 0xffff) ?
5955 0 : (1 << (fcoe_other_function))));
5957 /* We are the reset owner iff:
5958 * - No other protocol drivers present.
5959 * - This is the lowest among fcoe functions. */
5960 if (!(drv_presence & drv_presence_mask) &&
5961 (ha->portnum < fcoe_other_function)) {
5962 ql_dbg(ql_dbg_p3p, vha, 0xb07f,
5963 "This host is Reset owner.\n");
5964 ha->flags.nic_core_reset_owner = 1;
5969 __qla83xx_set_drv_ack(scsi_qla_host_t *vha)
5971 int rval = QLA_SUCCESS;
5972 struct qla_hw_data *ha = vha->hw;
5975 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
5976 if (rval == QLA_SUCCESS) {
5977 drv_ack |= (1 << ha->portnum);
5978 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
5985 __qla83xx_clear_drv_ack(scsi_qla_host_t *vha)
5987 int rval = QLA_SUCCESS;
5988 struct qla_hw_data *ha = vha->hw;
5991 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
5992 if (rval == QLA_SUCCESS) {
5993 drv_ack &= ~(1 << ha->portnum);
5994 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
6001 qla83xx_dev_state_to_string(uint32_t dev_state)
6003 switch (dev_state) {
6004 case QLA8XXX_DEV_COLD:
6005 return "COLD/RE-INIT";
6006 case QLA8XXX_DEV_INITIALIZING:
6007 return "INITIALIZING";
6008 case QLA8XXX_DEV_READY:
6010 case QLA8XXX_DEV_NEED_RESET:
6011 return "NEED RESET";
6012 case QLA8XXX_DEV_NEED_QUIESCENT:
6013 return "NEED QUIESCENT";
6014 case QLA8XXX_DEV_FAILED:
6016 case QLA8XXX_DEV_QUIESCENT:
6023 /* Assumes idc-lock always held on entry */
6025 qla83xx_idc_audit(scsi_qla_host_t *vha, int audit_type)
6027 struct qla_hw_data *ha = vha->hw;
6028 uint32_t idc_audit_reg = 0, duration_secs = 0;
6030 switch (audit_type) {
6031 case IDC_AUDIT_TIMESTAMP:
6032 ha->idc_audit_ts = (jiffies_to_msecs(jiffies) / 1000);
6033 idc_audit_reg = (ha->portnum) |
6034 (IDC_AUDIT_TIMESTAMP << 7) | (ha->idc_audit_ts << 8);
6035 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
6038 case IDC_AUDIT_COMPLETION:
6039 duration_secs = ((jiffies_to_msecs(jiffies) -
6040 jiffies_to_msecs(ha->idc_audit_ts)) / 1000);
6041 idc_audit_reg = (ha->portnum) |
6042 (IDC_AUDIT_COMPLETION << 7) | (duration_secs << 8);
6043 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
6047 ql_log(ql_log_warn, vha, 0xb078,
6048 "Invalid audit type specified.\n");
6053 /* Assumes idc_lock always held on entry */
6055 qla83xx_initiating_reset(scsi_qla_host_t *vha)
6057 struct qla_hw_data *ha = vha->hw;
6058 uint32_t idc_control, dev_state;
6060 __qla83xx_get_idc_control(vha, &idc_control);
6061 if ((idc_control & QLA83XX_IDC_RESET_DISABLED)) {
6062 ql_log(ql_log_info, vha, 0xb080,
6063 "NIC Core reset has been disabled. idc-control=0x%x\n",
6065 return QLA_FUNCTION_FAILED;
6068 /* Set NEED-RESET iff in READY state and we are the reset-owner */
6069 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
6070 if (ha->flags.nic_core_reset_owner && dev_state == QLA8XXX_DEV_READY) {
6071 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
6072 QLA8XXX_DEV_NEED_RESET);
6073 ql_log(ql_log_info, vha, 0xb056, "HW State: NEED RESET.\n");
6074 qla83xx_idc_audit(vha, IDC_AUDIT_TIMESTAMP);
6076 const char *state = qla83xx_dev_state_to_string(dev_state);
6077 ql_log(ql_log_info, vha, 0xb057, "HW State: %s.\n", state);
6079 /* SV: XXX: Is timeout required here? */
6080 /* Wait for IDC state change READY -> NEED_RESET */
6081 while (dev_state == QLA8XXX_DEV_READY) {
6082 qla83xx_idc_unlock(vha, 0);
6084 qla83xx_idc_lock(vha, 0);
6085 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
6089 /* Send IDC ack by writing to drv-ack register */
6090 __qla83xx_set_drv_ack(vha);
6096 __qla83xx_set_idc_control(scsi_qla_host_t *vha, uint32_t idc_control)
6098 return qla83xx_wr_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
6102 __qla83xx_get_idc_control(scsi_qla_host_t *vha, uint32_t *idc_control)
6104 return qla83xx_rd_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
6108 qla83xx_check_driver_presence(scsi_qla_host_t *vha)
6110 uint32_t drv_presence = 0;
6111 struct qla_hw_data *ha = vha->hw;
6113 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
6114 if (drv_presence & (1 << ha->portnum))
6117 return QLA_TEST_FAILED;
6121 qla83xx_nic_core_reset(scsi_qla_host_t *vha)
6123 int rval = QLA_SUCCESS;
6124 struct qla_hw_data *ha = vha->hw;
6126 ql_dbg(ql_dbg_p3p, vha, 0xb058,
6127 "Entered %s().\n", __func__);
6129 if (vha->device_flags & DFLG_DEV_FAILED) {
6130 ql_log(ql_log_warn, vha, 0xb059,
6131 "Device in unrecoverable FAILED state.\n");
6132 return QLA_FUNCTION_FAILED;
6135 qla83xx_idc_lock(vha, 0);
6137 if (qla83xx_check_driver_presence(vha) != QLA_SUCCESS) {
6138 ql_log(ql_log_warn, vha, 0xb05a,
6139 "Function=0x%x has been removed from IDC participation.\n",
6141 rval = QLA_FUNCTION_FAILED;
6145 qla83xx_reset_ownership(vha);
6147 rval = qla83xx_initiating_reset(vha);
6150 * Perform reset if we are the reset-owner,
6151 * else wait till IDC state changes to READY/FAILED.
6153 if (rval == QLA_SUCCESS) {
6154 rval = qla83xx_idc_state_handler(vha);
6156 if (rval == QLA_SUCCESS)
6157 ha->flags.nic_core_hung = 0;
6158 __qla83xx_clear_drv_ack(vha);
6162 qla83xx_idc_unlock(vha, 0);
6164 ql_dbg(ql_dbg_p3p, vha, 0xb05b, "Exiting %s.\n", __func__);
6170 qla2xxx_mctp_dump(scsi_qla_host_t *vha)
6172 struct qla_hw_data *ha = vha->hw;
6173 int rval = QLA_FUNCTION_FAILED;
6175 if (!IS_MCTP_CAPABLE(ha)) {
6176 /* This message can be removed from the final version */
6177 ql_log(ql_log_info, vha, 0x506d,
6178 "This board is not MCTP capable\n");
6182 if (!ha->mctp_dump) {
6183 ha->mctp_dump = dma_alloc_coherent(&ha->pdev->dev,
6184 MCTP_DUMP_SIZE, &ha->mctp_dump_dma, GFP_KERNEL);
6186 if (!ha->mctp_dump) {
6187 ql_log(ql_log_warn, vha, 0x506e,
6188 "Failed to allocate memory for mctp dump\n");
6193 #define MCTP_DUMP_STR_ADDR 0x00000000
6194 rval = qla2x00_dump_mctp_data(vha, ha->mctp_dump_dma,
6195 MCTP_DUMP_STR_ADDR, MCTP_DUMP_SIZE/4);
6196 if (rval != QLA_SUCCESS) {
6197 ql_log(ql_log_warn, vha, 0x506f,
6198 "Failed to capture mctp dump\n");
6200 ql_log(ql_log_info, vha, 0x5070,
6201 "Mctp dump capture for host (%ld/%p).\n",
6202 vha->host_no, ha->mctp_dump);
6203 ha->mctp_dumped = 1;
6206 if (!ha->flags.nic_core_reset_hdlr_active && !ha->portnum) {
6207 ha->flags.nic_core_reset_hdlr_active = 1;
6208 rval = qla83xx_restart_nic_firmware(vha);
6210 /* NIC Core reset failed. */
6211 ql_log(ql_log_warn, vha, 0x5071,
6212 "Failed to restart nic firmware\n");
6214 ql_dbg(ql_dbg_p3p, vha, 0xb084,
6215 "Restarted NIC firmware successfully.\n");
6216 ha->flags.nic_core_reset_hdlr_active = 0;
6224 * qla2x00_quiesce_io
6225 * Description: This function will block the new I/Os
6226 * Its not aborting any I/Os as context
6227 * is not destroyed during quiescence
6228 * Arguments: scsi_qla_host_t
6232 qla2x00_quiesce_io(scsi_qla_host_t *vha)
6234 struct qla_hw_data *ha = vha->hw;
6235 struct scsi_qla_host *vp;
6237 ql_dbg(ql_dbg_dpc, vha, 0x401d,
6238 "Quiescing I/O - ha=%p.\n", ha);
6240 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
6241 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
6242 atomic_set(&vha->loop_state, LOOP_DOWN);
6243 qla2x00_mark_all_devices_lost(vha, 0);
6244 list_for_each_entry(vp, &ha->vp_list, list)
6245 qla2x00_mark_all_devices_lost(vp, 0);
6247 if (!atomic_read(&vha->loop_down_timer))
6248 atomic_set(&vha->loop_down_timer,
6251 /* Wait for pending cmds to complete */
6252 qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST);
6256 qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha)
6258 struct qla_hw_data *ha = vha->hw;
6259 struct scsi_qla_host *vp;
6260 unsigned long flags;
6264 /* For ISP82XX, driver waits for completion of the commands.
6265 * online flag should be set.
6267 if (!(IS_P3P_TYPE(ha)))
6268 vha->flags.online = 0;
6269 ha->flags.chip_reset_done = 0;
6270 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
6271 vha->qla_stats.total_isp_aborts++;
6273 ql_log(ql_log_info, vha, 0x00af,
6274 "Performing ISP error recovery - ha=%p.\n", ha);
6276 /* For ISP82XX, reset_chip is just disabling interrupts.
6277 * Driver waits for the completion of the commands.
6278 * the interrupts need to be enabled.
6280 if (!(IS_P3P_TYPE(ha)))
6281 ha->isp_ops->reset_chip(vha);
6284 ha->flags.rida_fmt2 = 0;
6285 ha->flags.n2n_ae = 0;
6286 ha->flags.lip_ae = 0;
6287 ha->current_topology = 0;
6288 ha->flags.fw_started = 0;
6289 ha->flags.fw_init_done = 0;
6290 ha->base_qpair->chip_reset++;
6291 for (i = 0; i < ha->max_qpairs; i++) {
6292 if (ha->queue_pair_map[i])
6293 ha->queue_pair_map[i]->chip_reset =
6294 ha->base_qpair->chip_reset;
6297 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
6298 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
6299 atomic_set(&vha->loop_state, LOOP_DOWN);
6300 qla2x00_mark_all_devices_lost(vha, 0);
6302 spin_lock_irqsave(&ha->vport_slock, flags);
6303 list_for_each_entry(vp, &ha->vp_list, list) {
6304 atomic_inc(&vp->vref_count);
6305 spin_unlock_irqrestore(&ha->vport_slock, flags);
6307 qla2x00_mark_all_devices_lost(vp, 0);
6309 spin_lock_irqsave(&ha->vport_slock, flags);
6310 atomic_dec(&vp->vref_count);
6312 spin_unlock_irqrestore(&ha->vport_slock, flags);
6314 if (!atomic_read(&vha->loop_down_timer))
6315 atomic_set(&vha->loop_down_timer,
6319 /* Clear all async request states across all VPs. */
6320 list_for_each_entry(fcport, &vha->vp_fcports, list)
6321 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
6322 spin_lock_irqsave(&ha->vport_slock, flags);
6323 list_for_each_entry(vp, &ha->vp_list, list) {
6324 atomic_inc(&vp->vref_count);
6325 spin_unlock_irqrestore(&ha->vport_slock, flags);
6327 list_for_each_entry(fcport, &vp->vp_fcports, list)
6328 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
6330 spin_lock_irqsave(&ha->vport_slock, flags);
6331 atomic_dec(&vp->vref_count);
6333 spin_unlock_irqrestore(&ha->vport_slock, flags);
6335 if (!ha->flags.eeh_busy) {
6336 /* Make sure for ISP 82XX IO DMA is complete */
6337 if (IS_P3P_TYPE(ha)) {
6338 qla82xx_chip_reset_cleanup(vha);
6339 ql_log(ql_log_info, vha, 0x00b4,
6340 "Done chip reset cleanup.\n");
6342 /* Done waiting for pending commands.
6343 * Reset the online flag.
6345 vha->flags.online = 0;
6348 /* Requeue all commands in outstanding command list. */
6349 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
6351 /* memory barrier */
6357 * Resets ISP and aborts all outstanding commands.
6360 * ha = adapter block pointer.
6366 qla2x00_abort_isp(scsi_qla_host_t *vha)
6370 struct qla_hw_data *ha = vha->hw;
6371 struct scsi_qla_host *vp;
6372 struct req_que *req = ha->req_q_map[0];
6373 unsigned long flags;
6375 if (vha->flags.online) {
6376 qla2x00_abort_isp_cleanup(vha);
6378 if (IS_QLA8031(ha)) {
6379 ql_dbg(ql_dbg_p3p, vha, 0xb05c,
6380 "Clearing fcoe driver presence.\n");
6381 if (qla83xx_clear_drv_presence(vha) != QLA_SUCCESS)
6382 ql_dbg(ql_dbg_p3p, vha, 0xb073,
6383 "Error while clearing DRV-Presence.\n");
6386 if (unlikely(pci_channel_offline(ha->pdev) &&
6387 ha->flags.pci_channel_io_perm_failure)) {
6388 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6393 ha->isp_ops->get_flash_version(vha, req->ring);
6395 ha->isp_ops->nvram_config(vha);
6397 if (!qla2x00_restart_isp(vha)) {
6398 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
6400 if (!atomic_read(&vha->loop_down_timer)) {
6402 * Issue marker command only when we are going
6403 * to start the I/O .
6405 vha->marker_needed = 1;
6408 vha->flags.online = 1;
6410 ha->isp_ops->enable_intrs(ha);
6412 ha->isp_abort_cnt = 0;
6413 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6415 if (IS_QLA81XX(ha) || IS_QLA8031(ha))
6416 qla2x00_get_fw_version(vha);
6418 ha->flags.fce_enabled = 1;
6420 fce_calc_size(ha->fce_bufs));
6421 rval = qla2x00_enable_fce_trace(vha,
6422 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
6425 ql_log(ql_log_warn, vha, 0x8033,
6426 "Unable to reinitialize FCE "
6428 ha->flags.fce_enabled = 0;
6433 memset(ha->eft, 0, EFT_SIZE);
6434 rval = qla2x00_enable_eft_trace(vha,
6435 ha->eft_dma, EFT_NUM_BUFFERS);
6437 ql_log(ql_log_warn, vha, 0x8034,
6438 "Unable to reinitialize EFT "
6442 } else { /* failed the ISP abort */
6443 vha->flags.online = 1;
6444 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
6445 if (ha->isp_abort_cnt == 0) {
6446 ql_log(ql_log_fatal, vha, 0x8035,
6447 "ISP error recover failed - "
6448 "board disabled.\n");
6450 * The next call disables the board
6453 ha->isp_ops->reset_adapter(vha);
6454 vha->flags.online = 0;
6455 clear_bit(ISP_ABORT_RETRY,
6458 } else { /* schedule another ISP abort */
6459 ha->isp_abort_cnt--;
6460 ql_dbg(ql_dbg_taskm, vha, 0x8020,
6461 "ISP abort - retry remaining %d.\n",
6466 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
6467 ql_dbg(ql_dbg_taskm, vha, 0x8021,
6468 "ISP error recovery - retrying (%d) "
6469 "more times.\n", ha->isp_abort_cnt);
6470 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6478 ql_dbg(ql_dbg_taskm, vha, 0x8022, "%s succeeded.\n", __func__);
6479 qla2x00_configure_hba(vha);
6480 spin_lock_irqsave(&ha->vport_slock, flags);
6481 list_for_each_entry(vp, &ha->vp_list, list) {
6483 atomic_inc(&vp->vref_count);
6484 spin_unlock_irqrestore(&ha->vport_slock, flags);
6486 qla2x00_vp_abort_isp(vp);
6488 spin_lock_irqsave(&ha->vport_slock, flags);
6489 atomic_dec(&vp->vref_count);
6492 spin_unlock_irqrestore(&ha->vport_slock, flags);
6494 if (IS_QLA8031(ha)) {
6495 ql_dbg(ql_dbg_p3p, vha, 0xb05d,
6496 "Setting back fcoe driver presence.\n");
6497 if (qla83xx_set_drv_presence(vha) != QLA_SUCCESS)
6498 ql_dbg(ql_dbg_p3p, vha, 0xb074,
6499 "Error while setting DRV-Presence.\n");
6502 ql_log(ql_log_warn, vha, 0x8023, "%s **** FAILED ****.\n",
6510 * qla2x00_restart_isp
6511 * restarts the ISP after a reset
6514 * ha = adapter block pointer.
6520 qla2x00_restart_isp(scsi_qla_host_t *vha)
6523 struct qla_hw_data *ha = vha->hw;
6524 struct req_que *req = ha->req_q_map[0];
6525 struct rsp_que *rsp = ha->rsp_q_map[0];
6527 /* If firmware needs to be loaded */
6528 if (qla2x00_isp_firmware(vha)) {
6529 vha->flags.online = 0;
6530 status = ha->isp_ops->chip_diag(vha);
6532 status = qla2x00_setup_chip(vha);
6535 if (!status && !(status = qla2x00_init_rings(vha))) {
6536 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
6537 ha->flags.chip_reset_done = 1;
6539 /* Initialize the queues in use */
6540 qla25xx_init_queues(ha);
6542 status = qla2x00_fw_ready(vha);
6544 /* Issue a marker after FW becomes ready. */
6545 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
6546 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
6549 /* if no cable then assume it's good */
6550 if ((vha->device_flags & DFLG_NO_CABLE))
6557 qla25xx_init_queues(struct qla_hw_data *ha)
6559 struct rsp_que *rsp = NULL;
6560 struct req_que *req = NULL;
6561 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
6565 for (i = 1; i < ha->max_rsp_queues; i++) {
6566 rsp = ha->rsp_q_map[i];
6567 if (rsp && test_bit(i, ha->rsp_qid_map)) {
6568 rsp->options &= ~BIT_0;
6569 ret = qla25xx_init_rsp_que(base_vha, rsp);
6570 if (ret != QLA_SUCCESS)
6571 ql_dbg(ql_dbg_init, base_vha, 0x00ff,
6572 "%s Rsp que: %d init failed.\n",
6575 ql_dbg(ql_dbg_init, base_vha, 0x0100,
6576 "%s Rsp que: %d inited.\n",
6580 for (i = 1; i < ha->max_req_queues; i++) {
6581 req = ha->req_q_map[i];
6582 if (req && test_bit(i, ha->req_qid_map)) {
6583 /* Clear outstanding commands array. */
6584 req->options &= ~BIT_0;
6585 ret = qla25xx_init_req_que(base_vha, req);
6586 if (ret != QLA_SUCCESS)
6587 ql_dbg(ql_dbg_init, base_vha, 0x0101,
6588 "%s Req que: %d init failed.\n",
6591 ql_dbg(ql_dbg_init, base_vha, 0x0102,
6592 "%s Req que: %d inited.\n",
6600 * qla2x00_reset_adapter
6604 * ha = adapter block pointer.
6607 qla2x00_reset_adapter(scsi_qla_host_t *vha)
6609 unsigned long flags = 0;
6610 struct qla_hw_data *ha = vha->hw;
6611 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
6613 vha->flags.online = 0;
6614 ha->isp_ops->disable_intrs(ha);
6616 spin_lock_irqsave(&ha->hardware_lock, flags);
6617 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
6618 RD_REG_WORD(®->hccr); /* PCI Posting. */
6619 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
6620 RD_REG_WORD(®->hccr); /* PCI Posting. */
6621 spin_unlock_irqrestore(&ha->hardware_lock, flags);
6625 qla24xx_reset_adapter(scsi_qla_host_t *vha)
6627 unsigned long flags = 0;
6628 struct qla_hw_data *ha = vha->hw;
6629 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
6631 if (IS_P3P_TYPE(ha))
6634 vha->flags.online = 0;
6635 ha->isp_ops->disable_intrs(ha);
6637 spin_lock_irqsave(&ha->hardware_lock, flags);
6638 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
6639 RD_REG_DWORD(®->hccr);
6640 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
6641 RD_REG_DWORD(®->hccr);
6642 spin_unlock_irqrestore(&ha->hardware_lock, flags);
6644 if (IS_NOPOLLING_TYPE(ha))
6645 ha->isp_ops->enable_intrs(ha);
6648 /* On sparc systems, obtain port and node WWN from firmware
6651 static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
6652 struct nvram_24xx *nv)
6655 struct qla_hw_data *ha = vha->hw;
6656 struct pci_dev *pdev = ha->pdev;
6657 struct device_node *dp = pci_device_to_OF_node(pdev);
6661 val = of_get_property(dp, "port-wwn", &len);
6662 if (val && len >= WWN_SIZE)
6663 memcpy(nv->port_name, val, WWN_SIZE);
6665 val = of_get_property(dp, "node-wwn", &len);
6666 if (val && len >= WWN_SIZE)
6667 memcpy(nv->node_name, val, WWN_SIZE);
6672 qla24xx_nvram_config(scsi_qla_host_t *vha)
6675 struct init_cb_24xx *icb;
6676 struct nvram_24xx *nv;
6678 uint8_t *dptr1, *dptr2;
6681 struct qla_hw_data *ha = vha->hw;
6684 icb = (struct init_cb_24xx *)ha->init_cb;
6687 /* Determine NVRAM starting address. */
6688 if (ha->port_no == 0) {
6689 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
6690 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
6692 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
6693 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
6696 ha->nvram_size = sizeof(struct nvram_24xx);
6697 ha->vpd_size = FA_NVRAM_VPD_SIZE;
6699 /* Get VPD data into cache */
6700 ha->vpd = ha->nvram + VPD_OFFSET;
6701 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
6702 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
6704 /* Get NVRAM data into cache and calculate checksum. */
6705 dptr = (uint32_t *)nv;
6706 ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
6708 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++)
6709 chksum += le32_to_cpu(*dptr);
6711 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x006a,
6712 "Contents of NVRAM\n");
6713 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x010d,
6714 (uint8_t *)nv, ha->nvram_size);
6716 /* Bad NVRAM data, set defaults parameters. */
6717 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
6718 || nv->id[3] != ' ' ||
6719 nv->nvram_version < cpu_to_le16(ICB_VERSION)) {
6720 /* Reset NVRAM data. */
6721 ql_log(ql_log_warn, vha, 0x006b,
6722 "Inconsistent NVRAM detected: checksum=0x%x id=%c "
6723 "version=0x%x.\n", chksum, nv->id[0], nv->nvram_version);
6724 ql_log(ql_log_warn, vha, 0x006c,
6725 "Falling back to functioning (yet invalid -- WWPN) "
6729 * Set default initialization control block.
6731 memset(nv, 0, ha->nvram_size);
6732 nv->nvram_version = cpu_to_le16(ICB_VERSION);
6733 nv->version = cpu_to_le16(ICB_VERSION);
6734 nv->frame_payload_size = 2048;
6735 nv->execution_throttle = cpu_to_le16(0xFFFF);
6736 nv->exchange_count = cpu_to_le16(0);
6737 nv->hard_address = cpu_to_le16(124);
6738 nv->port_name[0] = 0x21;
6739 nv->port_name[1] = 0x00 + ha->port_no + 1;
6740 nv->port_name[2] = 0x00;
6741 nv->port_name[3] = 0xe0;
6742 nv->port_name[4] = 0x8b;
6743 nv->port_name[5] = 0x1c;
6744 nv->port_name[6] = 0x55;
6745 nv->port_name[7] = 0x86;
6746 nv->node_name[0] = 0x20;
6747 nv->node_name[1] = 0x00;
6748 nv->node_name[2] = 0x00;
6749 nv->node_name[3] = 0xe0;
6750 nv->node_name[4] = 0x8b;
6751 nv->node_name[5] = 0x1c;
6752 nv->node_name[6] = 0x55;
6753 nv->node_name[7] = 0x86;
6754 qla24xx_nvram_wwn_from_ofw(vha, nv);
6755 nv->login_retry_count = cpu_to_le16(8);
6756 nv->interrupt_delay_timer = cpu_to_le16(0);
6757 nv->login_timeout = cpu_to_le16(0);
6758 nv->firmware_options_1 =
6759 cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
6760 nv->firmware_options_2 = cpu_to_le32(2 << 4);
6761 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
6762 nv->firmware_options_3 = cpu_to_le32(2 << 13);
6763 nv->host_p = cpu_to_le32(BIT_11|BIT_10);
6764 nv->efi_parameters = cpu_to_le32(0);
6765 nv->reset_delay = 5;
6766 nv->max_luns_per_target = cpu_to_le16(128);
6767 nv->port_down_retry_count = cpu_to_le16(30);
6768 nv->link_down_timeout = cpu_to_le16(30);
6773 if (qla_tgt_mode_enabled(vha)) {
6774 /* Don't enable full login after initial LIP */
6775 nv->firmware_options_1 &= cpu_to_le32(~BIT_13);
6776 /* Don't enable LIP full login for initiator */
6777 nv->host_p &= cpu_to_le32(~BIT_10);
6780 qlt_24xx_config_nvram_stage1(vha, nv);
6782 /* Reset Initialization control block */
6783 memset(icb, 0, ha->init_cb_size);
6785 /* Copy 1st segment. */
6786 dptr1 = (uint8_t *)icb;
6787 dptr2 = (uint8_t *)&nv->version;
6788 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
6790 *dptr1++ = *dptr2++;
6792 icb->login_retry_count = nv->login_retry_count;
6793 icb->link_down_on_nos = nv->link_down_on_nos;
6795 /* Copy 2nd segment. */
6796 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
6797 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
6798 cnt = (uint8_t *)&icb->reserved_3 -
6799 (uint8_t *)&icb->interrupt_delay_timer;
6801 *dptr1++ = *dptr2++;
6804 * Setup driver NVRAM options.
6806 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
6809 qlt_24xx_config_nvram_stage2(vha, icb);
6811 if (nv->host_p & cpu_to_le32(BIT_15)) {
6812 /* Use alternate WWN? */
6813 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
6814 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
6817 /* Prepare nodename */
6818 if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
6820 * Firmware will apply the following mask if the nodename was
6823 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
6824 icb->node_name[0] &= 0xF0;
6827 /* Set host adapter parameters. */
6828 ha->flags.disable_risc_code_load = 0;
6829 ha->flags.enable_lip_reset = 0;
6830 ha->flags.enable_lip_full_login =
6831 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
6832 ha->flags.enable_target_reset =
6833 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
6834 ha->flags.enable_led_scheme = 0;
6835 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
6837 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
6838 (BIT_6 | BIT_5 | BIT_4)) >> 4;
6840 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
6841 sizeof(ha->fw_seriallink_options24));
6843 /* save HBA serial number */
6844 ha->serial0 = icb->port_name[5];
6845 ha->serial1 = icb->port_name[6];
6846 ha->serial2 = icb->port_name[7];
6847 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
6848 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
6850 icb->execution_throttle = cpu_to_le16(0xFFFF);
6852 ha->retry_count = le16_to_cpu(nv->login_retry_count);
6854 /* Set minimum login_timeout to 4 seconds. */
6855 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
6856 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
6857 if (le16_to_cpu(nv->login_timeout) < 4)
6858 nv->login_timeout = cpu_to_le16(4);
6859 ha->login_timeout = le16_to_cpu(nv->login_timeout);
6861 /* Set minimum RATOV to 100 tenths of a second. */
6864 ha->loop_reset_delay = nv->reset_delay;
6866 /* Link Down Timeout = 0:
6868 * When Port Down timer expires we will start returning
6869 * I/O's to OS with "DID_NO_CONNECT".
6871 * Link Down Timeout != 0:
6873 * The driver waits for the link to come up after link down
6874 * before returning I/Os to OS with "DID_NO_CONNECT".
6876 if (le16_to_cpu(nv->link_down_timeout) == 0) {
6877 ha->loop_down_abort_time =
6878 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
6880 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
6881 ha->loop_down_abort_time =
6882 (LOOP_DOWN_TIME - ha->link_down_timeout);
6885 /* Need enough time to try and get the port back. */
6886 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
6887 if (qlport_down_retry)
6888 ha->port_down_retry_count = qlport_down_retry;
6890 /* Set login_retry_count */
6891 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
6892 if (ha->port_down_retry_count ==
6893 le16_to_cpu(nv->port_down_retry_count) &&
6894 ha->port_down_retry_count > 3)
6895 ha->login_retry_count = ha->port_down_retry_count;
6896 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
6897 ha->login_retry_count = ha->port_down_retry_count;
6898 if (ql2xloginretrycount)
6899 ha->login_retry_count = ql2xloginretrycount;
6902 if (!vha->flags.init_done) {
6903 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
6904 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
6905 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
6906 le16_to_cpu(icb->interrupt_delay_timer): 2;
6908 icb->firmware_options_2 &= cpu_to_le32(
6909 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
6910 vha->flags.process_response_queue = 0;
6911 if (ha->zio_mode != QLA_ZIO_DISABLED) {
6912 ha->zio_mode = QLA_ZIO_MODE_6;
6914 ql_log(ql_log_info, vha, 0x006f,
6915 "ZIO mode %d enabled; timer delay (%d us).\n",
6916 ha->zio_mode, ha->zio_timer * 100);
6918 icb->firmware_options_2 |= cpu_to_le32(
6919 (uint32_t)ha->zio_mode);
6920 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
6921 vha->flags.process_response_queue = 1;
6925 ql_log(ql_log_warn, vha, 0x0070,
6926 "NVRAM configuration failed.\n");
6931 uint8_t qla27xx_find_valid_image(struct scsi_qla_host *vha)
6933 struct qla27xx_image_status pri_image_status, sec_image_status;
6934 uint8_t valid_pri_image, valid_sec_image;
6936 uint32_t cnt, chksum, size;
6937 struct qla_hw_data *ha = vha->hw;
6939 valid_pri_image = valid_sec_image = 1;
6940 ha->active_image = 0;
6941 size = sizeof(struct qla27xx_image_status) / sizeof(uint32_t);
6943 if (!ha->flt_region_img_status_pri) {
6944 valid_pri_image = 0;
6945 goto check_sec_image;
6948 qla24xx_read_flash_data(vha, (uint32_t *)(&pri_image_status),
6949 ha->flt_region_img_status_pri, size);
6951 if (pri_image_status.signature != QLA27XX_IMG_STATUS_SIGN) {
6952 ql_dbg(ql_dbg_init, vha, 0x018b,
6953 "Primary image signature (0x%x) not valid\n",
6954 pri_image_status.signature);
6955 valid_pri_image = 0;
6956 goto check_sec_image;
6959 wptr = (uint32_t *)(&pri_image_status);
6962 for (chksum = 0; cnt--; wptr++)
6963 chksum += le32_to_cpu(*wptr);
6966 ql_dbg(ql_dbg_init, vha, 0x018c,
6967 "Checksum validation failed for primary image (0x%x)\n",
6969 valid_pri_image = 0;
6973 if (!ha->flt_region_img_status_sec) {
6974 valid_sec_image = 0;
6975 goto check_valid_image;
6978 qla24xx_read_flash_data(vha, (uint32_t *)(&sec_image_status),
6979 ha->flt_region_img_status_sec, size);
6981 if (sec_image_status.signature != QLA27XX_IMG_STATUS_SIGN) {
6982 ql_dbg(ql_dbg_init, vha, 0x018d,
6983 "Secondary image signature(0x%x) not valid\n",
6984 sec_image_status.signature);
6985 valid_sec_image = 0;
6986 goto check_valid_image;
6989 wptr = (uint32_t *)(&sec_image_status);
6991 for (chksum = 0; cnt--; wptr++)
6992 chksum += le32_to_cpu(*wptr);
6994 ql_dbg(ql_dbg_init, vha, 0x018e,
6995 "Checksum validation failed for secondary image (0x%x)\n",
6997 valid_sec_image = 0;
7001 if (valid_pri_image && (pri_image_status.image_status_mask & 0x1))
7002 ha->active_image = QLA27XX_PRIMARY_IMAGE;
7003 if (valid_sec_image && (sec_image_status.image_status_mask & 0x1)) {
7004 if (!ha->active_image ||
7005 pri_image_status.generation_number <
7006 sec_image_status.generation_number)
7007 ha->active_image = QLA27XX_SECONDARY_IMAGE;
7010 ql_dbg(ql_dbg_init, vha, 0x018f, "%s image\n",
7011 ha->active_image == 0 ? "default bootld and fw" :
7012 ha->active_image == 1 ? "primary" :
7013 ha->active_image == 2 ? "secondary" :
7016 return ha->active_image;
7020 qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
7023 int rval = QLA_SUCCESS;
7024 int segments, fragment;
7025 uint32_t *dcode, dlen;
7029 struct qla_hw_data *ha = vha->hw;
7030 struct req_que *req = ha->req_q_map[0];
7032 ql_dbg(ql_dbg_init, vha, 0x008b,
7033 "FW: Loading firmware from flash (%x).\n", faddr);
7037 segments = FA_RISC_CODE_SEGMENTS;
7038 dcode = (uint32_t *)req->ring;
7041 if (IS_QLA27XX(ha) &&
7042 qla27xx_find_valid_image(vha) == QLA27XX_SECONDARY_IMAGE)
7043 faddr = ha->flt_region_fw_sec;
7045 /* Validate firmware image by checking version. */
7046 qla24xx_read_flash_data(vha, dcode, faddr + 4, 4);
7047 for (i = 0; i < 4; i++)
7048 dcode[i] = be32_to_cpu(dcode[i]);
7049 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
7050 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
7051 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
7053 ql_log(ql_log_fatal, vha, 0x008c,
7054 "Unable to verify the integrity of flash firmware "
7056 ql_log(ql_log_fatal, vha, 0x008d,
7057 "Firmware data: %08x %08x %08x %08x.\n",
7058 dcode[0], dcode[1], dcode[2], dcode[3]);
7060 return QLA_FUNCTION_FAILED;
7063 while (segments && rval == QLA_SUCCESS) {
7064 /* Read segment's load information. */
7065 qla24xx_read_flash_data(vha, dcode, faddr, 4);
7067 risc_addr = be32_to_cpu(dcode[2]);
7068 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
7069 risc_size = be32_to_cpu(dcode[3]);
7072 while (risc_size > 0 && rval == QLA_SUCCESS) {
7073 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
7074 if (dlen > risc_size)
7077 ql_dbg(ql_dbg_init, vha, 0x008e,
7078 "Loading risc segment@ risc addr %x "
7079 "number of dwords 0x%x offset 0x%x.\n",
7080 risc_addr, dlen, faddr);
7082 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
7083 for (i = 0; i < dlen; i++)
7084 dcode[i] = swab32(dcode[i]);
7086 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
7089 ql_log(ql_log_fatal, vha, 0x008f,
7090 "Failed to load segment %d of firmware.\n",
7092 return QLA_FUNCTION_FAILED;
7105 if (!IS_QLA27XX(ha))
7108 if (ha->fw_dump_template)
7109 vfree(ha->fw_dump_template);
7110 ha->fw_dump_template = NULL;
7111 ha->fw_dump_template_len = 0;
7113 ql_dbg(ql_dbg_init, vha, 0x0161,
7114 "Loading fwdump template from %x\n", faddr);
7115 qla24xx_read_flash_data(vha, dcode, faddr, 7);
7116 risc_size = be32_to_cpu(dcode[2]);
7117 ql_dbg(ql_dbg_init, vha, 0x0162,
7118 "-> array size %x dwords\n", risc_size);
7119 if (risc_size == 0 || risc_size == ~0)
7120 goto default_template;
7122 dlen = (risc_size - 8) * sizeof(*dcode);
7123 ql_dbg(ql_dbg_init, vha, 0x0163,
7124 "-> template allocating %x bytes...\n", dlen);
7125 ha->fw_dump_template = vmalloc(dlen);
7126 if (!ha->fw_dump_template) {
7127 ql_log(ql_log_warn, vha, 0x0164,
7128 "Failed fwdump template allocate %x bytes.\n", risc_size);
7129 goto default_template;
7134 dcode = ha->fw_dump_template;
7135 qla24xx_read_flash_data(vha, dcode, faddr, risc_size);
7136 for (i = 0; i < risc_size; i++)
7137 dcode[i] = le32_to_cpu(dcode[i]);
7139 if (!qla27xx_fwdt_template_valid(dcode)) {
7140 ql_log(ql_log_warn, vha, 0x0165,
7141 "Failed fwdump template validate\n");
7142 goto default_template;
7145 dlen = qla27xx_fwdt_template_size(dcode);
7146 ql_dbg(ql_dbg_init, vha, 0x0166,
7147 "-> template size %x bytes\n", dlen);
7148 if (dlen > risc_size * sizeof(*dcode)) {
7149 ql_log(ql_log_warn, vha, 0x0167,
7150 "Failed fwdump template exceeds array by %zx bytes\n",
7151 (size_t)(dlen - risc_size * sizeof(*dcode)));
7152 goto default_template;
7154 ha->fw_dump_template_len = dlen;
7158 ql_log(ql_log_warn, vha, 0x0168, "Using default fwdump template\n");
7159 if (ha->fw_dump_template)
7160 vfree(ha->fw_dump_template);
7161 ha->fw_dump_template = NULL;
7162 ha->fw_dump_template_len = 0;
7164 dlen = qla27xx_fwdt_template_default_size();
7165 ql_dbg(ql_dbg_init, vha, 0x0169,
7166 "-> template allocating %x bytes...\n", dlen);
7167 ha->fw_dump_template = vmalloc(dlen);
7168 if (!ha->fw_dump_template) {
7169 ql_log(ql_log_warn, vha, 0x016a,
7170 "Failed fwdump template allocate %x bytes.\n", risc_size);
7171 goto failed_template;
7174 dcode = ha->fw_dump_template;
7175 risc_size = dlen / sizeof(*dcode);
7176 memcpy(dcode, qla27xx_fwdt_template_default(), dlen);
7177 for (i = 0; i < risc_size; i++)
7178 dcode[i] = be32_to_cpu(dcode[i]);
7180 if (!qla27xx_fwdt_template_valid(ha->fw_dump_template)) {
7181 ql_log(ql_log_warn, vha, 0x016b,
7182 "Failed fwdump template validate\n");
7183 goto failed_template;
7186 dlen = qla27xx_fwdt_template_size(ha->fw_dump_template);
7187 ql_dbg(ql_dbg_init, vha, 0x016c,
7188 "-> template size %x bytes\n", dlen);
7189 ha->fw_dump_template_len = dlen;
7193 ql_log(ql_log_warn, vha, 0x016d, "Failed default fwdump template\n");
7194 if (ha->fw_dump_template)
7195 vfree(ha->fw_dump_template);
7196 ha->fw_dump_template = NULL;
7197 ha->fw_dump_template_len = 0;
7201 #define QLA_FW_URL "http://ldriver.qlogic.com/firmware/"
7204 qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
7208 uint16_t *wcode, *fwcode;
7209 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
7210 struct fw_blob *blob;
7211 struct qla_hw_data *ha = vha->hw;
7212 struct req_que *req = ha->req_q_map[0];
7214 /* Load firmware blob. */
7215 blob = qla2x00_request_firmware(vha);
7217 ql_log(ql_log_info, vha, 0x0083,
7218 "Firmware image unavailable.\n");
7219 ql_log(ql_log_info, vha, 0x0084,
7220 "Firmware images can be retrieved from: "QLA_FW_URL ".\n");
7221 return QLA_FUNCTION_FAILED;
7226 wcode = (uint16_t *)req->ring;
7228 fwcode = (uint16_t *)blob->fw->data;
7231 /* Validate firmware image by checking version. */
7232 if (blob->fw->size < 8 * sizeof(uint16_t)) {
7233 ql_log(ql_log_fatal, vha, 0x0085,
7234 "Unable to verify integrity of firmware image (%zd).\n",
7236 goto fail_fw_integrity;
7238 for (i = 0; i < 4; i++)
7239 wcode[i] = be16_to_cpu(fwcode[i + 4]);
7240 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
7241 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
7242 wcode[2] == 0 && wcode[3] == 0)) {
7243 ql_log(ql_log_fatal, vha, 0x0086,
7244 "Unable to verify integrity of firmware image.\n");
7245 ql_log(ql_log_fatal, vha, 0x0087,
7246 "Firmware data: %04x %04x %04x %04x.\n",
7247 wcode[0], wcode[1], wcode[2], wcode[3]);
7248 goto fail_fw_integrity;
7252 while (*seg && rval == QLA_SUCCESS) {
7254 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
7255 risc_size = be16_to_cpu(fwcode[3]);
7257 /* Validate firmware image size. */
7258 fwclen += risc_size * sizeof(uint16_t);
7259 if (blob->fw->size < fwclen) {
7260 ql_log(ql_log_fatal, vha, 0x0088,
7261 "Unable to verify integrity of firmware image "
7262 "(%zd).\n", blob->fw->size);
7263 goto fail_fw_integrity;
7267 while (risc_size > 0 && rval == QLA_SUCCESS) {
7268 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
7269 if (wlen > risc_size)
7271 ql_dbg(ql_dbg_init, vha, 0x0089,
7272 "Loading risc segment@ risc addr %x number of "
7273 "words 0x%x.\n", risc_addr, wlen);
7275 for (i = 0; i < wlen; i++)
7276 wcode[i] = swab16(fwcode[i]);
7278 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
7281 ql_log(ql_log_fatal, vha, 0x008a,
7282 "Failed to load segment %d of firmware.\n",
7299 return QLA_FUNCTION_FAILED;
7303 qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
7306 int segments, fragment;
7307 uint32_t *dcode, dlen;
7311 struct fw_blob *blob;
7312 const uint32_t *fwcode;
7314 struct qla_hw_data *ha = vha->hw;
7315 struct req_que *req = ha->req_q_map[0];
7317 /* Load firmware blob. */
7318 blob = qla2x00_request_firmware(vha);
7320 ql_log(ql_log_warn, vha, 0x0090,
7321 "Firmware image unavailable.\n");
7322 ql_log(ql_log_warn, vha, 0x0091,
7323 "Firmware images can be retrieved from: "
7326 return QLA_FUNCTION_FAILED;
7329 ql_dbg(ql_dbg_init, vha, 0x0092,
7330 "FW: Loading via request-firmware.\n");
7334 segments = FA_RISC_CODE_SEGMENTS;
7335 dcode = (uint32_t *)req->ring;
7337 fwcode = (uint32_t *)blob->fw->data;
7340 /* Validate firmware image by checking version. */
7341 if (blob->fw->size < 8 * sizeof(uint32_t)) {
7342 ql_log(ql_log_fatal, vha, 0x0093,
7343 "Unable to verify integrity of firmware image (%zd).\n",
7345 return QLA_FUNCTION_FAILED;
7347 for (i = 0; i < 4; i++)
7348 dcode[i] = be32_to_cpu(fwcode[i + 4]);
7349 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
7350 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
7351 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
7353 ql_log(ql_log_fatal, vha, 0x0094,
7354 "Unable to verify integrity of firmware image (%zd).\n",
7356 ql_log(ql_log_fatal, vha, 0x0095,
7357 "Firmware data: %08x %08x %08x %08x.\n",
7358 dcode[0], dcode[1], dcode[2], dcode[3]);
7359 return QLA_FUNCTION_FAILED;
7362 while (segments && rval == QLA_SUCCESS) {
7363 risc_addr = be32_to_cpu(fwcode[2]);
7364 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
7365 risc_size = be32_to_cpu(fwcode[3]);
7367 /* Validate firmware image size. */
7368 fwclen += risc_size * sizeof(uint32_t);
7369 if (blob->fw->size < fwclen) {
7370 ql_log(ql_log_fatal, vha, 0x0096,
7371 "Unable to verify integrity of firmware image "
7372 "(%zd).\n", blob->fw->size);
7373 return QLA_FUNCTION_FAILED;
7377 while (risc_size > 0 && rval == QLA_SUCCESS) {
7378 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
7379 if (dlen > risc_size)
7382 ql_dbg(ql_dbg_init, vha, 0x0097,
7383 "Loading risc segment@ risc addr %x "
7384 "number of dwords 0x%x.\n", risc_addr, dlen);
7386 for (i = 0; i < dlen; i++)
7387 dcode[i] = swab32(fwcode[i]);
7389 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
7392 ql_log(ql_log_fatal, vha, 0x0098,
7393 "Failed to load segment %d of firmware.\n",
7395 return QLA_FUNCTION_FAILED;
7408 if (!IS_QLA27XX(ha))
7411 if (ha->fw_dump_template)
7412 vfree(ha->fw_dump_template);
7413 ha->fw_dump_template = NULL;
7414 ha->fw_dump_template_len = 0;
7416 ql_dbg(ql_dbg_init, vha, 0x171,
7417 "Loading fwdump template from %x\n",
7418 (uint32_t)((void *)fwcode - (void *)blob->fw->data));
7419 risc_size = be32_to_cpu(fwcode[2]);
7420 ql_dbg(ql_dbg_init, vha, 0x172,
7421 "-> array size %x dwords\n", risc_size);
7422 if (risc_size == 0 || risc_size == ~0)
7423 goto default_template;
7425 dlen = (risc_size - 8) * sizeof(*fwcode);
7426 ql_dbg(ql_dbg_init, vha, 0x0173,
7427 "-> template allocating %x bytes...\n", dlen);
7428 ha->fw_dump_template = vmalloc(dlen);
7429 if (!ha->fw_dump_template) {
7430 ql_log(ql_log_warn, vha, 0x0174,
7431 "Failed fwdump template allocate %x bytes.\n", risc_size);
7432 goto default_template;
7437 dcode = ha->fw_dump_template;
7438 for (i = 0; i < risc_size; i++)
7439 dcode[i] = le32_to_cpu(fwcode[i]);
7441 if (!qla27xx_fwdt_template_valid(dcode)) {
7442 ql_log(ql_log_warn, vha, 0x0175,
7443 "Failed fwdump template validate\n");
7444 goto default_template;
7447 dlen = qla27xx_fwdt_template_size(dcode);
7448 ql_dbg(ql_dbg_init, vha, 0x0176,
7449 "-> template size %x bytes\n", dlen);
7450 if (dlen > risc_size * sizeof(*fwcode)) {
7451 ql_log(ql_log_warn, vha, 0x0177,
7452 "Failed fwdump template exceeds array by %zx bytes\n",
7453 (size_t)(dlen - risc_size * sizeof(*fwcode)));
7454 goto default_template;
7456 ha->fw_dump_template_len = dlen;
7460 ql_log(ql_log_warn, vha, 0x0178, "Using default fwdump template\n");
7461 if (ha->fw_dump_template)
7462 vfree(ha->fw_dump_template);
7463 ha->fw_dump_template = NULL;
7464 ha->fw_dump_template_len = 0;
7466 dlen = qla27xx_fwdt_template_default_size();
7467 ql_dbg(ql_dbg_init, vha, 0x0179,
7468 "-> template allocating %x bytes...\n", dlen);
7469 ha->fw_dump_template = vmalloc(dlen);
7470 if (!ha->fw_dump_template) {
7471 ql_log(ql_log_warn, vha, 0x017a,
7472 "Failed fwdump template allocate %x bytes.\n", risc_size);
7473 goto failed_template;
7476 dcode = ha->fw_dump_template;
7477 risc_size = dlen / sizeof(*fwcode);
7478 fwcode = qla27xx_fwdt_template_default();
7479 for (i = 0; i < risc_size; i++)
7480 dcode[i] = be32_to_cpu(fwcode[i]);
7482 if (!qla27xx_fwdt_template_valid(ha->fw_dump_template)) {
7483 ql_log(ql_log_warn, vha, 0x017b,
7484 "Failed fwdump template validate\n");
7485 goto failed_template;
7488 dlen = qla27xx_fwdt_template_size(ha->fw_dump_template);
7489 ql_dbg(ql_dbg_init, vha, 0x017c,
7490 "-> template size %x bytes\n", dlen);
7491 ha->fw_dump_template_len = dlen;
7495 ql_log(ql_log_warn, vha, 0x017d, "Failed default fwdump template\n");
7496 if (ha->fw_dump_template)
7497 vfree(ha->fw_dump_template);
7498 ha->fw_dump_template = NULL;
7499 ha->fw_dump_template_len = 0;
7504 qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
7508 if (ql2xfwloadbin == 1)
7509 return qla81xx_load_risc(vha, srisc_addr);
7513 * 1) Firmware via request-firmware interface (.bin file).
7514 * 2) Firmware residing in flash.
7516 rval = qla24xx_load_risc_blob(vha, srisc_addr);
7517 if (rval == QLA_SUCCESS)
7520 return qla24xx_load_risc_flash(vha, srisc_addr,
7521 vha->hw->flt_region_fw);
7525 qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
7528 struct qla_hw_data *ha = vha->hw;
7530 if (ql2xfwloadbin == 2)
7535 * 1) Firmware residing in flash.
7536 * 2) Firmware via request-firmware interface (.bin file).
7537 * 3) Golden-Firmware residing in flash -- limited operation.
7539 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
7540 if (rval == QLA_SUCCESS)
7544 rval = qla24xx_load_risc_blob(vha, srisc_addr);
7545 if (rval == QLA_SUCCESS || !ha->flt_region_gold_fw)
7548 ql_log(ql_log_info, vha, 0x0099,
7549 "Attempting to fallback to golden firmware.\n");
7550 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
7551 if (rval != QLA_SUCCESS)
7554 ql_log(ql_log_info, vha, 0x009a, "Update operational firmware.\n");
7555 ha->flags.running_gold_fw = 1;
7560 qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
7563 struct qla_hw_data *ha = vha->hw;
7565 if (ha->flags.pci_channel_io_perm_failure)
7567 if (!IS_FWI2_CAPABLE(ha))
7569 if (!ha->fw_major_version)
7571 if (!ha->flags.fw_started)
7574 ret = qla2x00_stop_firmware(vha);
7575 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
7576 ret != QLA_INVALID_COMMAND && retries ; retries--) {
7577 ha->isp_ops->reset_chip(vha);
7578 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
7580 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
7582 ql_log(ql_log_info, vha, 0x8015,
7583 "Attempting retry of stop-firmware command.\n");
7584 ret = qla2x00_stop_firmware(vha);
7588 ha->flags.fw_init_done = 0;
7592 qla24xx_configure_vhba(scsi_qla_host_t *vha)
7594 int rval = QLA_SUCCESS;
7596 uint16_t mb[MAILBOX_REGISTER_COUNT];
7597 struct qla_hw_data *ha = vha->hw;
7598 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
7599 struct req_que *req;
7600 struct rsp_que *rsp;
7605 rval = qla2x00_fw_ready(base_vha);
7607 req = vha->qpair->req;
7609 req = ha->req_q_map[0];
7612 if (rval == QLA_SUCCESS) {
7613 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
7614 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
7617 vha->flags.management_server_logged_in = 0;
7619 /* Login to SNS first */
7620 rval2 = ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb,
7622 if (rval2 != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
7623 if (rval2 == QLA_MEMORY_ALLOC_FAILED)
7624 ql_dbg(ql_dbg_init, vha, 0x0120,
7625 "Failed SNS login: loop_id=%x, rval2=%d\n",
7628 ql_dbg(ql_dbg_init, vha, 0x0103,
7629 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
7630 "mb[2]=%x mb[6]=%x mb[7]=%x.\n",
7631 NPH_SNS, mb[0], mb[1], mb[2], mb[6], mb[7]);
7632 return (QLA_FUNCTION_FAILED);
7635 atomic_set(&vha->loop_down_timer, 0);
7636 atomic_set(&vha->loop_state, LOOP_UP);
7637 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
7638 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
7639 rval = qla2x00_loop_resync(base_vha);
7644 /* 84XX Support **************************************************************/
7646 static LIST_HEAD(qla_cs84xx_list);
7647 static DEFINE_MUTEX(qla_cs84xx_mutex);
7649 static struct qla_chip_state_84xx *
7650 qla84xx_get_chip(struct scsi_qla_host *vha)
7652 struct qla_chip_state_84xx *cs84xx;
7653 struct qla_hw_data *ha = vha->hw;
7655 mutex_lock(&qla_cs84xx_mutex);
7657 /* Find any shared 84xx chip. */
7658 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
7659 if (cs84xx->bus == ha->pdev->bus) {
7660 kref_get(&cs84xx->kref);
7665 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
7669 kref_init(&cs84xx->kref);
7670 spin_lock_init(&cs84xx->access_lock);
7671 mutex_init(&cs84xx->fw_update_mutex);
7672 cs84xx->bus = ha->pdev->bus;
7674 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
7676 mutex_unlock(&qla_cs84xx_mutex);
7681 __qla84xx_chip_release(struct kref *kref)
7683 struct qla_chip_state_84xx *cs84xx =
7684 container_of(kref, struct qla_chip_state_84xx, kref);
7686 mutex_lock(&qla_cs84xx_mutex);
7687 list_del(&cs84xx->list);
7688 mutex_unlock(&qla_cs84xx_mutex);
7693 qla84xx_put_chip(struct scsi_qla_host *vha)
7695 struct qla_hw_data *ha = vha->hw;
7697 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
7701 qla84xx_init_chip(scsi_qla_host_t *vha)
7705 struct qla_hw_data *ha = vha->hw;
7707 mutex_lock(&ha->cs84xx->fw_update_mutex);
7709 rval = qla84xx_verify_chip(vha, status);
7711 mutex_unlock(&ha->cs84xx->fw_update_mutex);
7713 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED:
7717 /* 81XX Support **************************************************************/
7720 qla81xx_nvram_config(scsi_qla_host_t *vha)
7723 struct init_cb_81xx *icb;
7724 struct nvram_81xx *nv;
7726 uint8_t *dptr1, *dptr2;
7729 struct qla_hw_data *ha = vha->hw;
7732 icb = (struct init_cb_81xx *)ha->init_cb;
7735 /* Determine NVRAM starting address. */
7736 ha->nvram_size = sizeof(struct nvram_81xx);
7737 ha->vpd_size = FA_NVRAM_VPD_SIZE;
7738 if (IS_P3P_TYPE(ha) || IS_QLA8031(ha))
7739 ha->vpd_size = FA_VPD_SIZE_82XX;
7741 /* Get VPD data into cache */
7742 ha->vpd = ha->nvram + VPD_OFFSET;
7743 ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
7746 /* Get NVRAM data into cache and calculate checksum. */
7747 ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
7749 dptr = (uint32_t *)nv;
7750 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++)
7751 chksum += le32_to_cpu(*dptr);
7753 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0111,
7754 "Contents of NVRAM:\n");
7755 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0112,
7756 (uint8_t *)nv, ha->nvram_size);
7758 /* Bad NVRAM data, set defaults parameters. */
7759 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
7760 || nv->id[3] != ' ' ||
7761 nv->nvram_version < cpu_to_le16(ICB_VERSION)) {
7762 /* Reset NVRAM data. */
7763 ql_log(ql_log_info, vha, 0x0073,
7764 "Inconsistent NVRAM detected: checksum=0x%x id=%c "
7765 "version=0x%x.\n", chksum, nv->id[0],
7766 le16_to_cpu(nv->nvram_version));
7767 ql_log(ql_log_info, vha, 0x0074,
7768 "Falling back to functioning (yet invalid -- WWPN) "
7772 * Set default initialization control block.
7774 memset(nv, 0, ha->nvram_size);
7775 nv->nvram_version = cpu_to_le16(ICB_VERSION);
7776 nv->version = cpu_to_le16(ICB_VERSION);
7777 nv->frame_payload_size = 2048;
7778 nv->execution_throttle = cpu_to_le16(0xFFFF);
7779 nv->exchange_count = cpu_to_le16(0);
7780 nv->port_name[0] = 0x21;
7781 nv->port_name[1] = 0x00 + ha->port_no + 1;
7782 nv->port_name[2] = 0x00;
7783 nv->port_name[3] = 0xe0;
7784 nv->port_name[4] = 0x8b;
7785 nv->port_name[5] = 0x1c;
7786 nv->port_name[6] = 0x55;
7787 nv->port_name[7] = 0x86;
7788 nv->node_name[0] = 0x20;
7789 nv->node_name[1] = 0x00;
7790 nv->node_name[2] = 0x00;
7791 nv->node_name[3] = 0xe0;
7792 nv->node_name[4] = 0x8b;
7793 nv->node_name[5] = 0x1c;
7794 nv->node_name[6] = 0x55;
7795 nv->node_name[7] = 0x86;
7796 nv->login_retry_count = cpu_to_le16(8);
7797 nv->interrupt_delay_timer = cpu_to_le16(0);
7798 nv->login_timeout = cpu_to_le16(0);
7799 nv->firmware_options_1 =
7800 cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
7801 nv->firmware_options_2 = cpu_to_le32(2 << 4);
7802 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
7803 nv->firmware_options_3 = cpu_to_le32(2 << 13);
7804 nv->host_p = cpu_to_le32(BIT_11|BIT_10);
7805 nv->efi_parameters = cpu_to_le32(0);
7806 nv->reset_delay = 5;
7807 nv->max_luns_per_target = cpu_to_le16(128);
7808 nv->port_down_retry_count = cpu_to_le16(30);
7809 nv->link_down_timeout = cpu_to_le16(180);
7810 nv->enode_mac[0] = 0x00;
7811 nv->enode_mac[1] = 0xC0;
7812 nv->enode_mac[2] = 0xDD;
7813 nv->enode_mac[3] = 0x04;
7814 nv->enode_mac[4] = 0x05;
7815 nv->enode_mac[5] = 0x06 + ha->port_no + 1;
7820 if (IS_T10_PI_CAPABLE(ha))
7821 nv->frame_payload_size &= ~7;
7823 qlt_81xx_config_nvram_stage1(vha, nv);
7825 /* Reset Initialization control block */
7826 memset(icb, 0, ha->init_cb_size);
7828 /* Copy 1st segment. */
7829 dptr1 = (uint8_t *)icb;
7830 dptr2 = (uint8_t *)&nv->version;
7831 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
7833 *dptr1++ = *dptr2++;
7835 icb->login_retry_count = nv->login_retry_count;
7837 /* Copy 2nd segment. */
7838 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
7839 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
7840 cnt = (uint8_t *)&icb->reserved_5 -
7841 (uint8_t *)&icb->interrupt_delay_timer;
7843 *dptr1++ = *dptr2++;
7845 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
7846 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
7847 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
7848 icb->enode_mac[0] = 0x00;
7849 icb->enode_mac[1] = 0xC0;
7850 icb->enode_mac[2] = 0xDD;
7851 icb->enode_mac[3] = 0x04;
7852 icb->enode_mac[4] = 0x05;
7853 icb->enode_mac[5] = 0x06 + ha->port_no + 1;
7856 /* Use extended-initialization control block. */
7857 memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
7860 * Setup driver NVRAM options.
7862 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
7865 qlt_81xx_config_nvram_stage2(vha, icb);
7867 /* Use alternate WWN? */
7868 if (nv->host_p & cpu_to_le32(BIT_15)) {
7869 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
7870 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
7873 /* Prepare nodename */
7874 if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
7876 * Firmware will apply the following mask if the nodename was
7879 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
7880 icb->node_name[0] &= 0xF0;
7883 /* Set host adapter parameters. */
7884 ha->flags.disable_risc_code_load = 0;
7885 ha->flags.enable_lip_reset = 0;
7886 ha->flags.enable_lip_full_login =
7887 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
7888 ha->flags.enable_target_reset =
7889 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
7890 ha->flags.enable_led_scheme = 0;
7891 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
7893 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
7894 (BIT_6 | BIT_5 | BIT_4)) >> 4;
7896 /* save HBA serial number */
7897 ha->serial0 = icb->port_name[5];
7898 ha->serial1 = icb->port_name[6];
7899 ha->serial2 = icb->port_name[7];
7900 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
7901 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
7903 icb->execution_throttle = cpu_to_le16(0xFFFF);
7905 ha->retry_count = le16_to_cpu(nv->login_retry_count);
7907 /* Set minimum login_timeout to 4 seconds. */
7908 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
7909 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
7910 if (le16_to_cpu(nv->login_timeout) < 4)
7911 nv->login_timeout = cpu_to_le16(4);
7912 ha->login_timeout = le16_to_cpu(nv->login_timeout);
7914 /* Set minimum RATOV to 100 tenths of a second. */
7917 ha->loop_reset_delay = nv->reset_delay;
7919 /* Link Down Timeout = 0:
7921 * When Port Down timer expires we will start returning
7922 * I/O's to OS with "DID_NO_CONNECT".
7924 * Link Down Timeout != 0:
7926 * The driver waits for the link to come up after link down
7927 * before returning I/Os to OS with "DID_NO_CONNECT".
7929 if (le16_to_cpu(nv->link_down_timeout) == 0) {
7930 ha->loop_down_abort_time =
7931 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
7933 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
7934 ha->loop_down_abort_time =
7935 (LOOP_DOWN_TIME - ha->link_down_timeout);
7938 /* Need enough time to try and get the port back. */
7939 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
7940 if (qlport_down_retry)
7941 ha->port_down_retry_count = qlport_down_retry;
7943 /* Set login_retry_count */
7944 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
7945 if (ha->port_down_retry_count ==
7946 le16_to_cpu(nv->port_down_retry_count) &&
7947 ha->port_down_retry_count > 3)
7948 ha->login_retry_count = ha->port_down_retry_count;
7949 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
7950 ha->login_retry_count = ha->port_down_retry_count;
7951 if (ql2xloginretrycount)
7952 ha->login_retry_count = ql2xloginretrycount;
7954 /* if not running MSI-X we need handshaking on interrupts */
7955 if (!vha->hw->flags.msix_enabled && (IS_QLA83XX(ha) || IS_QLA27XX(ha)))
7956 icb->firmware_options_2 |= cpu_to_le32(BIT_22);
7959 if (!vha->flags.init_done) {
7960 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
7961 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
7962 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
7963 le16_to_cpu(icb->interrupt_delay_timer): 2;
7965 icb->firmware_options_2 &= cpu_to_le32(
7966 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
7967 vha->flags.process_response_queue = 0;
7968 if (ha->zio_mode != QLA_ZIO_DISABLED) {
7969 ha->zio_mode = QLA_ZIO_MODE_6;
7971 ql_log(ql_log_info, vha, 0x0075,
7972 "ZIO mode %d enabled; timer delay (%d us).\n",
7974 ha->zio_timer * 100);
7976 icb->firmware_options_2 |= cpu_to_le32(
7977 (uint32_t)ha->zio_mode);
7978 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
7979 vha->flags.process_response_queue = 1;
7982 /* enable RIDA Format2 */
7983 if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha))
7984 icb->firmware_options_3 |= BIT_0;
7986 if (IS_QLA27XX(ha)) {
7987 icb->firmware_options_3 |= BIT_8;
7988 ql_dbg(ql_log_info, vha, 0x0075,
7989 "Enabling direct connection.\n");
7993 ql_log(ql_log_warn, vha, 0x0076,
7994 "NVRAM configuration failed.\n");
8000 qla82xx_restart_isp(scsi_qla_host_t *vha)
8003 struct qla_hw_data *ha = vha->hw;
8004 struct req_que *req = ha->req_q_map[0];
8005 struct rsp_que *rsp = ha->rsp_q_map[0];
8006 struct scsi_qla_host *vp;
8007 unsigned long flags;
8009 status = qla2x00_init_rings(vha);
8011 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
8012 ha->flags.chip_reset_done = 1;
8014 status = qla2x00_fw_ready(vha);
8016 /* Issue a marker after FW becomes ready. */
8017 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
8018 vha->flags.online = 1;
8019 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
8022 /* if no cable then assume it's good */
8023 if ((vha->device_flags & DFLG_NO_CABLE))
8028 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
8030 if (!atomic_read(&vha->loop_down_timer)) {
8032 * Issue marker command only when we are going
8033 * to start the I/O .
8035 vha->marker_needed = 1;
8038 ha->isp_ops->enable_intrs(ha);
8040 ha->isp_abort_cnt = 0;
8041 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
8043 /* Update the firmware version */
8044 status = qla82xx_check_md_needed(vha);
8047 ha->flags.fce_enabled = 1;
8049 fce_calc_size(ha->fce_bufs));
8050 rval = qla2x00_enable_fce_trace(vha,
8051 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
8054 ql_log(ql_log_warn, vha, 0x8001,
8055 "Unable to reinitialize FCE (%d).\n",
8057 ha->flags.fce_enabled = 0;
8062 memset(ha->eft, 0, EFT_SIZE);
8063 rval = qla2x00_enable_eft_trace(vha,
8064 ha->eft_dma, EFT_NUM_BUFFERS);
8066 ql_log(ql_log_warn, vha, 0x8010,
8067 "Unable to reinitialize EFT (%d).\n",
8074 ql_dbg(ql_dbg_taskm, vha, 0x8011,
8075 "qla82xx_restart_isp succeeded.\n");
8077 spin_lock_irqsave(&ha->vport_slock, flags);
8078 list_for_each_entry(vp, &ha->vp_list, list) {
8080 atomic_inc(&vp->vref_count);
8081 spin_unlock_irqrestore(&ha->vport_slock, flags);
8083 qla2x00_vp_abort_isp(vp);
8085 spin_lock_irqsave(&ha->vport_slock, flags);
8086 atomic_dec(&vp->vref_count);
8089 spin_unlock_irqrestore(&ha->vport_slock, flags);
8092 ql_log(ql_log_warn, vha, 0x8016,
8093 "qla82xx_restart_isp **** FAILED ****.\n");
8100 qla81xx_update_fw_options(scsi_qla_host_t *vha)
8102 struct qla_hw_data *ha = vha->hw;
8104 /* Hold status IOCBs until ABTS response received. */
8106 ha->fw_options[3] |= BIT_12;
8108 /* Set Retry FLOGI in case of P2P connection */
8109 if (ha->operating_mode == P2P) {
8110 ha->fw_options[2] |= BIT_3;
8111 ql_dbg(ql_dbg_disc, vha, 0x2103,
8112 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
8113 __func__, ha->fw_options[2]);
8116 /* Move PUREX, ABTS RX & RIDA to ATIOQ */
8117 if (ql2xmvasynctoatio) {
8118 if (qla_tgt_mode_enabled(vha) ||
8119 qla_dual_mode_enabled(vha))
8120 ha->fw_options[2] |= BIT_11;
8122 ha->fw_options[2] &= ~BIT_11;
8125 if (qla_tgt_mode_enabled(vha) ||
8126 qla_dual_mode_enabled(vha)) {
8127 /* FW auto send SCSI status during */
8128 ha->fw_options[1] |= BIT_8;
8129 ha->fw_options[10] |= (u16)SAM_STAT_BUSY << 8;
8131 /* FW perform Exchange validation */
8132 ha->fw_options[2] |= BIT_4;
8134 ha->fw_options[1] &= ~BIT_8;
8135 ha->fw_options[10] &= 0x00ff;
8137 ha->fw_options[2] &= ~BIT_4;
8140 if (ql2xetsenable) {
8141 /* Enable ETS Burst. */
8142 memset(ha->fw_options, 0, sizeof(ha->fw_options));
8143 ha->fw_options[2] |= BIT_9;
8146 ql_dbg(ql_dbg_init, vha, 0x00e9,
8147 "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n",
8148 __func__, ha->fw_options[1], ha->fw_options[2],
8149 ha->fw_options[3], vha->host->active_mode);
8151 qla2x00_set_fw_options(vha, ha->fw_options);
8155 * qla24xx_get_fcp_prio
8156 * Gets the fcp cmd priority value for the logged in port.
8157 * Looks for a match of the port descriptors within
8158 * each of the fcp prio config entries. If a match is found,
8159 * the tag (priority) value is returned.
8162 * vha = scsi host structure pointer.
8163 * fcport = port structure pointer.
8166 * non-zero (if found)
8173 qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
8176 uint8_t pid_match, wwn_match;
8178 uint32_t pid1, pid2;
8179 uint64_t wwn1, wwn2;
8180 struct qla_fcp_prio_entry *pri_entry;
8181 struct qla_hw_data *ha = vha->hw;
8183 if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled)
8187 entries = ha->fcp_prio_cfg->num_entries;
8188 pri_entry = &ha->fcp_prio_cfg->entry[0];
8190 for (i = 0; i < entries; i++) {
8191 pid_match = wwn_match = 0;
8193 if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) {
8198 /* check source pid for a match */
8199 if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) {
8200 pid1 = pri_entry->src_pid & INVALID_PORT_ID;
8201 pid2 = vha->d_id.b24 & INVALID_PORT_ID;
8202 if (pid1 == INVALID_PORT_ID)
8204 else if (pid1 == pid2)
8208 /* check destination pid for a match */
8209 if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) {
8210 pid1 = pri_entry->dst_pid & INVALID_PORT_ID;
8211 pid2 = fcport->d_id.b24 & INVALID_PORT_ID;
8212 if (pid1 == INVALID_PORT_ID)
8214 else if (pid1 == pid2)
8218 /* check source WWN for a match */
8219 if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) {
8220 wwn1 = wwn_to_u64(vha->port_name);
8221 wwn2 = wwn_to_u64(pri_entry->src_wwpn);
8222 if (wwn2 == (uint64_t)-1)
8224 else if (wwn1 == wwn2)
8228 /* check destination WWN for a match */
8229 if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) {
8230 wwn1 = wwn_to_u64(fcport->port_name);
8231 wwn2 = wwn_to_u64(pri_entry->dst_wwpn);
8232 if (wwn2 == (uint64_t)-1)
8234 else if (wwn1 == wwn2)
8238 if (pid_match == 2 || wwn_match == 2) {
8239 /* Found a matching entry */
8240 if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
8241 priority = pri_entry->tag;
8252 * qla24xx_update_fcport_fcp_prio
8253 * Activates fcp priority for the logged in fc port
8256 * vha = scsi host structure pointer.
8257 * fcp = port structure pointer.
8260 * QLA_SUCCESS or QLA_FUNCTION_FAILED
8266 qla24xx_update_fcport_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
8272 if (fcport->port_type != FCT_TARGET ||
8273 fcport->loop_id == FC_NO_LOOP_ID)
8274 return QLA_FUNCTION_FAILED;
8276 priority = qla24xx_get_fcp_prio(vha, fcport);
8278 return QLA_FUNCTION_FAILED;
8280 if (IS_P3P_TYPE(vha->hw)) {
8281 fcport->fcp_prio = priority & 0xf;
8285 ret = qla24xx_set_fcp_prio(vha, fcport->loop_id, priority, mb);
8286 if (ret == QLA_SUCCESS) {
8287 if (fcport->fcp_prio != priority)
8288 ql_dbg(ql_dbg_user, vha, 0x709e,
8289 "Updated FCP_CMND priority - value=%d loop_id=%d "
8290 "port_id=%02x%02x%02x.\n", priority,
8291 fcport->loop_id, fcport->d_id.b.domain,
8292 fcport->d_id.b.area, fcport->d_id.b.al_pa);
8293 fcport->fcp_prio = priority & 0xf;
8295 ql_dbg(ql_dbg_user, vha, 0x704f,
8296 "Unable to update FCP_CMND priority - ret=0x%x for "
8297 "loop_id=%d port_id=%02x%02x%02x.\n", ret, fcport->loop_id,
8298 fcport->d_id.b.domain, fcport->d_id.b.area,
8299 fcport->d_id.b.al_pa);
8304 * qla24xx_update_all_fcp_prio
8305 * Activates fcp priority for all the logged in ports
8308 * ha = adapter block pointer.
8311 * QLA_SUCCESS or QLA_FUNCTION_FAILED
8317 qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha)
8322 ret = QLA_FUNCTION_FAILED;
8323 /* We need to set priority for all logged in ports */
8324 list_for_each_entry(fcport, &vha->vp_fcports, list)
8325 ret = qla24xx_update_fcport_fcp_prio(vha, fcport);
8330 struct qla_qpair *qla2xxx_create_qpair(struct scsi_qla_host *vha, int qos,
8331 int vp_idx, bool startqp)
8336 struct qla_hw_data *ha = vha->hw;
8337 uint16_t qpair_id = 0;
8338 struct qla_qpair *qpair = NULL;
8339 struct qla_msix_entry *msix;
8341 if (!(ha->fw_attributes & BIT_6) || !ha->flags.msix_enabled) {
8342 ql_log(ql_log_warn, vha, 0x00181,
8343 "FW/Driver is not multi-queue capable.\n");
8347 if (ql2xmqsupport || ql2xnvmeenable) {
8348 qpair = kzalloc(sizeof(struct qla_qpair), GFP_KERNEL);
8349 if (qpair == NULL) {
8350 ql_log(ql_log_warn, vha, 0x0182,
8351 "Failed to allocate memory for queue pair.\n");
8354 memset(qpair, 0, sizeof(struct qla_qpair));
8356 qpair->hw = vha->hw;
8358 qpair->qp_lock_ptr = &qpair->qp_lock;
8359 spin_lock_init(&qpair->qp_lock);
8360 qpair->use_shadow_reg = IS_SHADOW_REG_CAPABLE(ha) ? 1 : 0;
8362 /* Assign available que pair id */
8363 mutex_lock(&ha->mq_lock);
8364 qpair_id = find_first_zero_bit(ha->qpair_qid_map, ha->max_qpairs);
8365 if (ha->num_qpairs >= ha->max_qpairs) {
8366 mutex_unlock(&ha->mq_lock);
8367 ql_log(ql_log_warn, vha, 0x0183,
8368 "No resources to create additional q pair.\n");
8372 set_bit(qpair_id, ha->qpair_qid_map);
8373 ha->queue_pair_map[qpair_id] = qpair;
8374 qpair->id = qpair_id;
8375 qpair->vp_idx = vp_idx;
8376 qpair->fw_started = ha->flags.fw_started;
8377 INIT_LIST_HEAD(&qpair->hints_list);
8378 INIT_LIST_HEAD(&qpair->nvme_done_list);
8379 qpair->chip_reset = ha->base_qpair->chip_reset;
8380 qpair->enable_class_2 = ha->base_qpair->enable_class_2;
8381 qpair->enable_explicit_conf =
8382 ha->base_qpair->enable_explicit_conf;
8384 for (i = 0; i < ha->msix_count; i++) {
8385 msix = &ha->msix_entries[i];
8389 ql_dbg(ql_dbg_multiq, vha, 0xc00f,
8390 "Vector %x selected for qpair\n", msix->vector);
8394 ql_log(ql_log_warn, vha, 0x0184,
8395 "Out of MSI-X vectors!.\n");
8399 qpair->msix->in_use = 1;
8400 list_add_tail(&qpair->qp_list_elem, &vha->qp_list);
8401 qpair->pdev = ha->pdev;
8402 if (IS_QLA27XX(ha) || IS_QLA83XX(ha))
8403 qpair->reqq_start_iocbs = qla_83xx_start_iocbs;
8405 mutex_unlock(&ha->mq_lock);
8407 /* Create response queue first */
8408 rsp_id = qla25xx_create_rsp_que(ha, 0, 0, 0, qpair, startqp);
8410 ql_log(ql_log_warn, vha, 0x0185,
8411 "Failed to create response queue.\n");
8415 qpair->rsp = ha->rsp_q_map[rsp_id];
8417 /* Create request queue */
8418 req_id = qla25xx_create_req_que(ha, 0, vp_idx, 0, rsp_id, qos,
8421 ql_log(ql_log_warn, vha, 0x0186,
8422 "Failed to create request queue.\n");
8426 qpair->req = ha->req_q_map[req_id];
8427 qpair->rsp->req = qpair->req;
8428 qpair->rsp->qpair = qpair;
8429 /* init qpair to this cpu. Will adjust at run time. */
8430 qla_cpu_update(qpair, smp_processor_id());
8432 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
8433 if (ha->fw_attributes & BIT_4)
8434 qpair->difdix_supported = 1;
8437 qpair->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
8438 if (!qpair->srb_mempool) {
8439 ql_log(ql_log_warn, vha, 0xd036,
8440 "Failed to create srb mempool for qpair %d\n",
8445 /* Mark as online */
8448 if (!vha->flags.qpairs_available)
8449 vha->flags.qpairs_available = 1;
8451 ql_dbg(ql_dbg_multiq, vha, 0xc00d,
8452 "Request/Response queue pair created, id %d\n",
8454 ql_dbg(ql_dbg_init, vha, 0x0187,
8455 "Request/Response queue pair created, id %d\n",
8462 qla25xx_delete_rsp_que(vha, qpair->rsp);
8464 mutex_lock(&ha->mq_lock);
8465 qpair->msix->in_use = 0;
8466 list_del(&qpair->qp_list_elem);
8467 if (list_empty(&vha->qp_list))
8468 vha->flags.qpairs_available = 0;
8470 ha->queue_pair_map[qpair_id] = NULL;
8471 clear_bit(qpair_id, ha->qpair_qid_map);
8473 mutex_unlock(&ha->mq_lock);
8479 int qla2xxx_delete_qpair(struct scsi_qla_host *vha, struct qla_qpair *qpair)
8481 int ret = QLA_FUNCTION_FAILED;
8482 struct qla_hw_data *ha = qpair->hw;
8484 qpair->delete_in_progress = 1;
8485 while (atomic_read(&qpair->ref_count))
8488 ret = qla25xx_delete_req_que(vha, qpair->req);
8489 if (ret != QLA_SUCCESS)
8492 ret = qla25xx_delete_rsp_que(vha, qpair->rsp);
8493 if (ret != QLA_SUCCESS)
8496 mutex_lock(&ha->mq_lock);
8497 ha->queue_pair_map[qpair->id] = NULL;
8498 clear_bit(qpair->id, ha->qpair_qid_map);
8500 list_del(&qpair->qp_list_elem);
8501 if (list_empty(&vha->qp_list)) {
8502 vha->flags.qpairs_available = 0;
8503 vha->flags.qpairs_req_created = 0;
8504 vha->flags.qpairs_rsp_created = 0;
8506 mempool_destroy(qpair->srb_mempool);
8508 mutex_unlock(&ha->mq_lock);