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 *, struct list_head *);
34 static int qla2x00_fabric_dev_login(scsi_qla_host_t *, fc_port_t *,
37 static int qla2x00_restart_isp(scsi_qla_host_t *);
39 static struct qla_chip_state_84xx *qla84xx_get_chip(struct scsi_qla_host *);
40 static int qla84xx_init_chip(scsi_qla_host_t *);
41 static int qla25xx_init_queues(struct qla_hw_data *);
43 /* SRB Extensions ---------------------------------------------------------- */
46 qla2x00_sp_timeout(unsigned long __data)
48 srb_t *sp = (srb_t *)__data;
49 struct srb_iocb *iocb;
50 fc_port_t *fcport = sp->fcport;
51 struct qla_hw_data *ha = fcport->vha->hw;
55 spin_lock_irqsave(&ha->hardware_lock, flags);
56 req = ha->req_q_map[0];
57 req->outstanding_cmds[sp->handle] = NULL;
58 iocb = &sp->u.iocb_cmd;
60 sp->free(fcport->vha, sp);
61 spin_unlock_irqrestore(&ha->hardware_lock, flags);
65 qla2x00_sp_free(void *data, void *ptr)
67 srb_t *sp = (srb_t *)ptr;
68 struct srb_iocb *iocb = &sp->u.iocb_cmd;
69 struct scsi_qla_host *vha = (scsi_qla_host_t *)data;
71 del_timer(&iocb->timer);
72 qla2x00_rel_sp(vha, sp);
75 /* Asynchronous Login/Logout Routines -------------------------------------- */
78 qla2x00_get_async_timeout(struct scsi_qla_host *vha)
81 struct qla_hw_data *ha = vha->hw;
83 /* Firmware should use switch negotiated r_a_tov for timeout. */
84 tmo = ha->r_a_tov / 10 * 2;
86 tmo = FX00_DEF_RATOV * 2;
87 } else if (!IS_FWI2_CAPABLE(ha)) {
89 * Except for earlier ISPs where the timeout is seeded from the
90 * initialization control block.
92 tmo = ha->login_timeout;
98 qla2x00_async_iocb_timeout(void *data)
100 srb_t *sp = (srb_t *)data;
101 fc_port_t *fcport = sp->fcport;
103 ql_dbg(ql_dbg_disc, fcport->vha, 0x2071,
104 "Async-%s timeout - hdl=%x portid=%02x%02x%02x.\n",
105 sp->name, sp->handle, fcport->d_id.b.domain, fcport->d_id.b.area,
106 fcport->d_id.b.al_pa);
108 fcport->flags &= ~FCF_ASYNC_SENT;
109 if (sp->type == SRB_LOGIN_CMD) {
110 struct srb_iocb *lio = &sp->u.iocb_cmd;
111 qla2x00_post_async_logout_work(fcport->vha, fcport, NULL);
112 /* Retry as needed. */
113 lio->u.logio.data[0] = MBS_COMMAND_ERROR;
114 lio->u.logio.data[1] = lio->u.logio.flags & SRB_LOGIN_RETRIED ?
115 QLA_LOGIO_LOGIN_RETRIED : 0;
116 qla2x00_post_async_login_done_work(fcport->vha, fcport,
118 } else if (sp->type == SRB_LOGOUT_CMD) {
119 qlt_logo_completion_handler(fcport, QLA_FUNCTION_TIMEOUT);
124 qla2x00_async_login_sp_done(void *data, void *ptr, int res)
126 srb_t *sp = (srb_t *)ptr;
127 struct srb_iocb *lio = &sp->u.iocb_cmd;
128 struct scsi_qla_host *vha = (scsi_qla_host_t *)data;
130 if (!test_bit(UNLOADING, &vha->dpc_flags))
131 qla2x00_post_async_login_done_work(sp->fcport->vha, sp->fcport,
133 sp->free(sp->fcport->vha, sp);
137 qla2x00_async_login(struct scsi_qla_host *vha, fc_port_t *fcport,
141 struct srb_iocb *lio;
144 rval = QLA_FUNCTION_FAILED;
145 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
149 sp->type = SRB_LOGIN_CMD;
151 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
153 lio = &sp->u.iocb_cmd;
154 lio->timeout = qla2x00_async_iocb_timeout;
155 sp->done = qla2x00_async_login_sp_done;
156 lio->u.logio.flags |= SRB_LOGIN_COND_PLOGI;
157 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
158 lio->u.logio.flags |= SRB_LOGIN_RETRIED;
159 rval = qla2x00_start_sp(sp);
160 if (rval != QLA_SUCCESS)
163 ql_dbg(ql_dbg_disc, vha, 0x2072,
164 "Async-login - hdl=%x, loopid=%x portid=%02x%02x%02x "
165 "retries=%d.\n", sp->handle, fcport->loop_id,
166 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa,
167 fcport->login_retry);
171 sp->free(fcport->vha, sp);
177 qla2x00_async_logout_sp_done(void *data, void *ptr, int res)
179 srb_t *sp = (srb_t *)ptr;
180 struct srb_iocb *lio = &sp->u.iocb_cmd;
181 struct scsi_qla_host *vha = (scsi_qla_host_t *)data;
183 if (!test_bit(UNLOADING, &vha->dpc_flags))
184 qla2x00_post_async_logout_done_work(sp->fcport->vha, sp->fcport,
186 sp->free(sp->fcport->vha, sp);
190 qla2x00_async_logout(struct scsi_qla_host *vha, fc_port_t *fcport)
193 struct srb_iocb *lio;
196 rval = QLA_FUNCTION_FAILED;
197 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
201 sp->type = SRB_LOGOUT_CMD;
203 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
205 lio = &sp->u.iocb_cmd;
206 lio->timeout = qla2x00_async_iocb_timeout;
207 sp->done = qla2x00_async_logout_sp_done;
208 rval = qla2x00_start_sp(sp);
209 if (rval != QLA_SUCCESS)
212 ql_dbg(ql_dbg_disc, vha, 0x2070,
213 "Async-logout - hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
214 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
215 fcport->d_id.b.area, fcport->d_id.b.al_pa);
219 sp->free(fcport->vha, sp);
225 qla2x00_async_adisc_sp_done(void *data, void *ptr, int res)
227 srb_t *sp = (srb_t *)ptr;
228 struct srb_iocb *lio = &sp->u.iocb_cmd;
229 struct scsi_qla_host *vha = (scsi_qla_host_t *)data;
231 if (!test_bit(UNLOADING, &vha->dpc_flags))
232 qla2x00_post_async_adisc_done_work(sp->fcport->vha, sp->fcport,
234 sp->free(sp->fcport->vha, sp);
238 qla2x00_async_adisc(struct scsi_qla_host *vha, fc_port_t *fcport,
242 struct srb_iocb *lio;
245 rval = QLA_FUNCTION_FAILED;
246 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
250 sp->type = SRB_ADISC_CMD;
252 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
254 lio = &sp->u.iocb_cmd;
255 lio->timeout = qla2x00_async_iocb_timeout;
256 sp->done = qla2x00_async_adisc_sp_done;
257 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
258 lio->u.logio.flags |= SRB_LOGIN_RETRIED;
259 rval = qla2x00_start_sp(sp);
260 if (rval != QLA_SUCCESS)
263 ql_dbg(ql_dbg_disc, vha, 0x206f,
264 "Async-adisc - hdl=%x loopid=%x portid=%02x%02x%02x.\n",
265 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
266 fcport->d_id.b.area, fcport->d_id.b.al_pa);
270 sp->free(fcport->vha, sp);
276 qla2x00_tmf_iocb_timeout(void *data)
278 srb_t *sp = (srb_t *)data;
279 struct srb_iocb *tmf = &sp->u.iocb_cmd;
281 tmf->u.tmf.comp_status = CS_TIMEOUT;
282 complete(&tmf->u.tmf.comp);
286 qla2x00_tmf_sp_done(void *data, void *ptr, int res)
288 srb_t *sp = (srb_t *)ptr;
289 struct srb_iocb *tmf = &sp->u.iocb_cmd;
290 complete(&tmf->u.tmf.comp);
294 qla2x00_async_tm_cmd(fc_port_t *fcport, uint32_t flags, uint32_t lun,
297 struct scsi_qla_host *vha = fcport->vha;
298 struct srb_iocb *tm_iocb;
300 int rval = QLA_FUNCTION_FAILED;
302 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
306 tm_iocb = &sp->u.iocb_cmd;
307 sp->type = SRB_TM_CMD;
309 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha));
310 tm_iocb->u.tmf.flags = flags;
311 tm_iocb->u.tmf.lun = lun;
312 tm_iocb->u.tmf.data = tag;
313 sp->done = qla2x00_tmf_sp_done;
314 tm_iocb->timeout = qla2x00_tmf_iocb_timeout;
315 init_completion(&tm_iocb->u.tmf.comp);
317 rval = qla2x00_start_sp(sp);
318 if (rval != QLA_SUCCESS)
321 ql_dbg(ql_dbg_taskm, vha, 0x802f,
322 "Async-tmf hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
323 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
324 fcport->d_id.b.area, fcport->d_id.b.al_pa);
326 wait_for_completion(&tm_iocb->u.tmf.comp);
328 rval = tm_iocb->u.tmf.comp_status == CS_COMPLETE ?
329 QLA_SUCCESS : QLA_FUNCTION_FAILED;
331 if ((rval != QLA_SUCCESS) || tm_iocb->u.tmf.data) {
332 ql_dbg(ql_dbg_taskm, vha, 0x8030,
333 "TM IOCB failed (%x).\n", rval);
336 if (!test_bit(UNLOADING, &vha->dpc_flags) && !IS_QLAFX00(vha->hw)) {
337 flags = tm_iocb->u.tmf.flags;
338 lun = (uint16_t)tm_iocb->u.tmf.lun;
340 /* Issue Marker IOCB */
341 qla2x00_marker(vha, vha->hw->req_q_map[0],
342 vha->hw->rsp_q_map[0], sp->fcport->loop_id, lun,
343 flags == TCF_LUN_RESET ? MK_SYNC_ID_LUN : MK_SYNC_ID);
353 qla24xx_abort_iocb_timeout(void *data)
355 srb_t *sp = (srb_t *)data;
356 struct srb_iocb *abt = &sp->u.iocb_cmd;
358 abt->u.abt.comp_status = CS_TIMEOUT;
359 complete(&abt->u.abt.comp);
363 qla24xx_abort_sp_done(void *data, void *ptr, int res)
365 srb_t *sp = (srb_t *)ptr;
366 struct srb_iocb *abt = &sp->u.iocb_cmd;
368 complete(&abt->u.abt.comp);
372 qla24xx_async_abort_cmd(srb_t *cmd_sp)
374 scsi_qla_host_t *vha = cmd_sp->fcport->vha;
375 fc_port_t *fcport = cmd_sp->fcport;
376 struct srb_iocb *abt_iocb;
378 int rval = QLA_FUNCTION_FAILED;
380 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
384 abt_iocb = &sp->u.iocb_cmd;
385 sp->type = SRB_ABT_CMD;
387 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha));
388 abt_iocb->u.abt.cmd_hndl = cmd_sp->handle;
389 sp->done = qla24xx_abort_sp_done;
390 abt_iocb->timeout = qla24xx_abort_iocb_timeout;
391 init_completion(&abt_iocb->u.abt.comp);
393 rval = qla2x00_start_sp(sp);
394 if (rval != QLA_SUCCESS)
397 ql_dbg(ql_dbg_async, vha, 0x507c,
398 "Abort command issued - hdl=%x, target_id=%x\n",
399 cmd_sp->handle, fcport->tgt_id);
401 wait_for_completion(&abt_iocb->u.abt.comp);
403 rval = abt_iocb->u.abt.comp_status == CS_COMPLETE ?
404 QLA_SUCCESS : QLA_FUNCTION_FAILED;
413 qla24xx_async_abort_command(srb_t *sp)
415 unsigned long flags = 0;
418 fc_port_t *fcport = sp->fcport;
419 struct scsi_qla_host *vha = fcport->vha;
420 struct qla_hw_data *ha = vha->hw;
421 struct req_que *req = vha->req;
423 spin_lock_irqsave(&ha->hardware_lock, flags);
424 for (handle = 1; handle < req->num_outstanding_cmds; handle++) {
425 if (req->outstanding_cmds[handle] == sp)
428 spin_unlock_irqrestore(&ha->hardware_lock, flags);
429 if (handle == req->num_outstanding_cmds) {
430 /* Command not found. */
431 return QLA_FUNCTION_FAILED;
433 if (sp->type == SRB_FXIOCB_DCMD)
434 return qlafx00_fx_disc(vha, &vha->hw->mr.fcport,
437 return qla24xx_async_abort_cmd(sp);
441 qla2x00_async_login_done(struct scsi_qla_host *vha, fc_port_t *fcport,
447 case MBS_COMMAND_COMPLETE:
449 * Driver must validate login state - If PRLI not complete,
450 * force a relogin attempt via implicit LOGO, PLOGI, and PRLI
453 rval = qla2x00_get_port_database(vha, fcport, 0);
454 if (rval == QLA_NOT_LOGGED_IN) {
455 fcport->flags &= ~FCF_ASYNC_SENT;
456 fcport->flags |= FCF_LOGIN_NEEDED;
457 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
461 if (rval != QLA_SUCCESS) {
462 qla2x00_post_async_logout_work(vha, fcport, NULL);
463 qla2x00_post_async_login_work(vha, fcport, NULL);
466 if (fcport->flags & FCF_FCP2_DEVICE) {
467 qla2x00_post_async_adisc_work(vha, fcport, data);
470 qla2x00_update_fcport(vha, fcport);
472 case MBS_COMMAND_ERROR:
473 fcport->flags &= ~FCF_ASYNC_SENT;
474 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
475 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
477 qla2x00_mark_device_lost(vha, fcport, 1, 0);
479 case MBS_PORT_ID_USED:
480 fcport->loop_id = data[1];
481 qla2x00_post_async_logout_work(vha, fcport, NULL);
482 qla2x00_post_async_login_work(vha, fcport, NULL);
484 case MBS_LOOP_ID_USED:
486 rval = qla2x00_find_new_loop_id(vha, fcport);
487 if (rval != QLA_SUCCESS) {
488 fcport->flags &= ~FCF_ASYNC_SENT;
489 qla2x00_mark_device_lost(vha, fcport, 1, 0);
492 qla2x00_post_async_login_work(vha, fcport, NULL);
499 qla2x00_async_logout_done(struct scsi_qla_host *vha, fc_port_t *fcport,
502 /* Don't re-login in target mode */
503 if (!fcport->tgt_session)
504 qla2x00_mark_device_lost(vha, fcport, 1, 0);
505 qlt_logo_completion_handler(fcport, data[0]);
510 qla2x00_async_adisc_done(struct scsi_qla_host *vha, fc_port_t *fcport,
513 if (data[0] == MBS_COMMAND_COMPLETE) {
514 qla2x00_update_fcport(vha, fcport);
520 fcport->flags &= ~FCF_ASYNC_SENT;
521 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
522 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
524 qla2x00_mark_device_lost(vha, fcport, 1, 0);
529 /****************************************************************************/
530 /* QLogic ISP2x00 Hardware Support Functions. */
531 /****************************************************************************/
534 qla83xx_nic_core_fw_load(scsi_qla_host_t *vha)
536 int rval = QLA_SUCCESS;
537 struct qla_hw_data *ha = vha->hw;
538 uint32_t idc_major_ver, idc_minor_ver;
541 qla83xx_idc_lock(vha, 0);
543 /* SV: TODO: Assign initialization timeout from
544 * flash-info / other param
546 ha->fcoe_dev_init_timeout = QLA83XX_IDC_INITIALIZATION_TIMEOUT;
547 ha->fcoe_reset_timeout = QLA83XX_IDC_RESET_ACK_TIMEOUT;
549 /* Set our fcoe function presence */
550 if (__qla83xx_set_drv_presence(vha) != QLA_SUCCESS) {
551 ql_dbg(ql_dbg_p3p, vha, 0xb077,
552 "Error while setting DRV-Presence.\n");
553 rval = QLA_FUNCTION_FAILED;
557 /* Decide the reset ownership */
558 qla83xx_reset_ownership(vha);
561 * On first protocol driver load:
562 * Init-Owner: Set IDC-Major-Version and Clear IDC-Lock-Recovery
564 * Others: Check compatibility with current IDC Major version.
566 qla83xx_rd_reg(vha, QLA83XX_IDC_MAJOR_VERSION, &idc_major_ver);
567 if (ha->flags.nic_core_reset_owner) {
568 /* Set IDC Major version */
569 idc_major_ver = QLA83XX_SUPP_IDC_MAJOR_VERSION;
570 qla83xx_wr_reg(vha, QLA83XX_IDC_MAJOR_VERSION, idc_major_ver);
572 /* Clearing IDC-Lock-Recovery register */
573 qla83xx_wr_reg(vha, QLA83XX_IDC_LOCK_RECOVERY, 0);
574 } else if (idc_major_ver != QLA83XX_SUPP_IDC_MAJOR_VERSION) {
576 * Clear further IDC participation if we are not compatible with
577 * the current IDC Major Version.
579 ql_log(ql_log_warn, vha, 0xb07d,
580 "Failing load, idc_major_ver=%d, expected_major_ver=%d.\n",
581 idc_major_ver, QLA83XX_SUPP_IDC_MAJOR_VERSION);
582 __qla83xx_clear_drv_presence(vha);
583 rval = QLA_FUNCTION_FAILED;
586 /* Each function sets its supported Minor version. */
587 qla83xx_rd_reg(vha, QLA83XX_IDC_MINOR_VERSION, &idc_minor_ver);
588 idc_minor_ver |= (QLA83XX_SUPP_IDC_MINOR_VERSION << (ha->portnum * 2));
589 qla83xx_wr_reg(vha, QLA83XX_IDC_MINOR_VERSION, idc_minor_ver);
591 if (ha->flags.nic_core_reset_owner) {
592 memset(config, 0, sizeof(config));
593 if (!qla81xx_get_port_config(vha, config))
594 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
598 rval = qla83xx_idc_state_handler(vha);
601 qla83xx_idc_unlock(vha, 0);
607 * qla2x00_initialize_adapter
611 * ha = adapter block pointer.
617 qla2x00_initialize_adapter(scsi_qla_host_t *vha)
620 struct qla_hw_data *ha = vha->hw;
621 struct req_que *req = ha->req_q_map[0];
623 /* Clear adapter flags. */
624 vha->flags.online = 0;
625 ha->flags.chip_reset_done = 0;
626 vha->flags.reset_active = 0;
627 ha->flags.pci_channel_io_perm_failure = 0;
628 ha->flags.eeh_busy = 0;
629 vha->qla_stats.jiffies_at_last_reset = get_jiffies_64();
630 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
631 atomic_set(&vha->loop_state, LOOP_DOWN);
632 vha->device_flags = DFLG_NO_CABLE;
634 vha->flags.management_server_logged_in = 0;
635 vha->marker_needed = 0;
636 ha->isp_abort_cnt = 0;
637 ha->beacon_blink_led = 0;
639 set_bit(0, ha->req_qid_map);
640 set_bit(0, ha->rsp_qid_map);
642 ql_dbg(ql_dbg_init, vha, 0x0040,
643 "Configuring PCI space...\n");
644 rval = ha->isp_ops->pci_config(vha);
646 ql_log(ql_log_warn, vha, 0x0044,
647 "Unable to configure PCI space.\n");
651 ha->isp_ops->reset_chip(vha);
653 rval = qla2xxx_get_flash_info(vha);
655 ql_log(ql_log_fatal, vha, 0x004f,
656 "Unable to validate FLASH data.\n");
660 if (IS_QLA8044(ha)) {
661 qla8044_read_reset_template(vha);
663 /* NOTE: If ql2xdontresethba==1, set IDC_CTRL DONTRESET_BIT0.
664 * If DONRESET_BIT0 is set, drivers should not set dev_state
665 * to NEED_RESET. But if NEED_RESET is set, drivers should
666 * should honor the reset. */
667 if (ql2xdontresethba == 1)
668 qla8044_set_idc_dontreset(vha);
671 ha->isp_ops->get_flash_version(vha, req->ring);
672 ql_dbg(ql_dbg_init, vha, 0x0061,
673 "Configure NVRAM parameters...\n");
675 ha->isp_ops->nvram_config(vha);
677 if (ha->flags.disable_serdes) {
678 /* Mask HBA via NVRAM settings? */
679 ql_log(ql_log_info, vha, 0x0077,
680 "Masking HBA WWPN %8phN (via NVRAM).\n", vha->port_name);
681 return QLA_FUNCTION_FAILED;
684 ql_dbg(ql_dbg_init, vha, 0x0078,
685 "Verifying loaded RISC code...\n");
687 if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) {
688 rval = ha->isp_ops->chip_diag(vha);
691 rval = qla2x00_setup_chip(vha);
696 if (IS_QLA84XX(ha)) {
697 ha->cs84xx = qla84xx_get_chip(vha);
699 ql_log(ql_log_warn, vha, 0x00d0,
700 "Unable to configure ISP84XX.\n");
701 return QLA_FUNCTION_FAILED;
705 if (qla_ini_mode_enabled(vha))
706 rval = qla2x00_init_rings(vha);
708 ha->flags.chip_reset_done = 1;
710 if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) {
711 /* Issue verify 84xx FW IOCB to complete 84xx initialization */
712 rval = qla84xx_init_chip(vha);
713 if (rval != QLA_SUCCESS) {
714 ql_log(ql_log_warn, vha, 0x00d4,
715 "Unable to initialize ISP84XX.\n");
716 qla84xx_put_chip(vha);
720 /* Load the NIC Core f/w if we are the first protocol driver. */
721 if (IS_QLA8031(ha)) {
722 rval = qla83xx_nic_core_fw_load(vha);
724 ql_log(ql_log_warn, vha, 0x0124,
725 "Error in initializing NIC Core f/w.\n");
728 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha))
729 qla24xx_read_fcp_prio_cfg(vha);
732 qla82xx_set_driver_version(vha, QLA2XXX_VERSION);
734 qla25xx_set_driver_version(vha, QLA2XXX_VERSION);
740 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
743 * Returns 0 on success.
746 qla2100_pci_config(scsi_qla_host_t *vha)
750 struct qla_hw_data *ha = vha->hw;
751 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
753 pci_set_master(ha->pdev);
754 pci_try_set_mwi(ha->pdev);
756 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
757 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
758 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
760 pci_disable_rom(ha->pdev);
762 /* Get PCI bus information. */
763 spin_lock_irqsave(&ha->hardware_lock, flags);
764 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
765 spin_unlock_irqrestore(&ha->hardware_lock, flags);
771 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
774 * Returns 0 on success.
777 qla2300_pci_config(scsi_qla_host_t *vha)
780 unsigned long flags = 0;
782 struct qla_hw_data *ha = vha->hw;
783 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
785 pci_set_master(ha->pdev);
786 pci_try_set_mwi(ha->pdev);
788 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
789 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
791 if (IS_QLA2322(ha) || IS_QLA6322(ha))
792 w &= ~PCI_COMMAND_INTX_DISABLE;
793 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
796 * If this is a 2300 card and not 2312, reset the
797 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
798 * the 2310 also reports itself as a 2300 so we need to get the
799 * fb revision level -- a 6 indicates it really is a 2300 and
802 if (IS_QLA2300(ha)) {
803 spin_lock_irqsave(&ha->hardware_lock, flags);
806 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
807 for (cnt = 0; cnt < 30000; cnt++) {
808 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) != 0)
814 /* Select FPM registers. */
815 WRT_REG_WORD(®->ctrl_status, 0x20);
816 RD_REG_WORD(®->ctrl_status);
818 /* Get the fb rev level */
819 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
821 if (ha->fb_rev == FPM_2300)
822 pci_clear_mwi(ha->pdev);
824 /* Deselect FPM registers. */
825 WRT_REG_WORD(®->ctrl_status, 0x0);
826 RD_REG_WORD(®->ctrl_status);
828 /* Release RISC module. */
829 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
830 for (cnt = 0; cnt < 30000; cnt++) {
831 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) == 0)
837 spin_unlock_irqrestore(&ha->hardware_lock, flags);
840 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
842 pci_disable_rom(ha->pdev);
844 /* Get PCI bus information. */
845 spin_lock_irqsave(&ha->hardware_lock, flags);
846 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
847 spin_unlock_irqrestore(&ha->hardware_lock, flags);
853 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
856 * Returns 0 on success.
859 qla24xx_pci_config(scsi_qla_host_t *vha)
862 unsigned long flags = 0;
863 struct qla_hw_data *ha = vha->hw;
864 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
866 pci_set_master(ha->pdev);
867 pci_try_set_mwi(ha->pdev);
869 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
870 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
871 w &= ~PCI_COMMAND_INTX_DISABLE;
872 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
874 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
876 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
877 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
878 pcix_set_mmrbc(ha->pdev, 2048);
880 /* PCIe -- adjust Maximum Read Request Size (2048). */
881 if (pci_is_pcie(ha->pdev))
882 pcie_set_readrq(ha->pdev, 4096);
884 pci_disable_rom(ha->pdev);
886 ha->chip_revision = ha->pdev->revision;
888 /* Get PCI bus information. */
889 spin_lock_irqsave(&ha->hardware_lock, flags);
890 ha->pci_attr = RD_REG_DWORD(®->ctrl_status);
891 spin_unlock_irqrestore(&ha->hardware_lock, flags);
897 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
900 * Returns 0 on success.
903 qla25xx_pci_config(scsi_qla_host_t *vha)
906 struct qla_hw_data *ha = vha->hw;
908 pci_set_master(ha->pdev);
909 pci_try_set_mwi(ha->pdev);
911 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
912 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
913 w &= ~PCI_COMMAND_INTX_DISABLE;
914 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
916 /* PCIe -- adjust Maximum Read Request Size (2048). */
917 if (pci_is_pcie(ha->pdev))
918 pcie_set_readrq(ha->pdev, 4096);
920 pci_disable_rom(ha->pdev);
922 ha->chip_revision = ha->pdev->revision;
928 * qla2x00_isp_firmware() - Choose firmware image.
931 * Returns 0 on success.
934 qla2x00_isp_firmware(scsi_qla_host_t *vha)
937 uint16_t loop_id, topo, sw_cap;
938 uint8_t domain, area, al_pa;
939 struct qla_hw_data *ha = vha->hw;
941 /* Assume loading risc code */
942 rval = QLA_FUNCTION_FAILED;
944 if (ha->flags.disable_risc_code_load) {
945 ql_log(ql_log_info, vha, 0x0079, "RISC CODE NOT loaded.\n");
947 /* Verify checksum of loaded RISC code. */
948 rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address);
949 if (rval == QLA_SUCCESS) {
950 /* And, verify we are not in ROM code. */
951 rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
952 &area, &domain, &topo, &sw_cap);
957 ql_dbg(ql_dbg_init, vha, 0x007a,
958 "**** Load RISC code ****.\n");
964 * qla2x00_reset_chip() - Reset ISP chip.
967 * Returns 0 on success.
970 qla2x00_reset_chip(scsi_qla_host_t *vha)
972 unsigned long flags = 0;
973 struct qla_hw_data *ha = vha->hw;
974 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
978 if (unlikely(pci_channel_offline(ha->pdev)))
981 ha->isp_ops->disable_intrs(ha);
983 spin_lock_irqsave(&ha->hardware_lock, flags);
985 /* Turn off master enable */
987 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
988 cmd &= ~PCI_COMMAND_MASTER;
989 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
991 if (!IS_QLA2100(ha)) {
993 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
994 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
995 for (cnt = 0; cnt < 30000; cnt++) {
996 if ((RD_REG_WORD(®->hccr) &
997 HCCR_RISC_PAUSE) != 0)
1002 RD_REG_WORD(®->hccr); /* PCI Posting. */
1006 /* Select FPM registers. */
1007 WRT_REG_WORD(®->ctrl_status, 0x20);
1008 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
1010 /* FPM Soft Reset. */
1011 WRT_REG_WORD(®->fpm_diag_config, 0x100);
1012 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
1014 /* Toggle Fpm Reset. */
1015 if (!IS_QLA2200(ha)) {
1016 WRT_REG_WORD(®->fpm_diag_config, 0x0);
1017 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
1020 /* Select frame buffer registers. */
1021 WRT_REG_WORD(®->ctrl_status, 0x10);
1022 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
1024 /* Reset frame buffer FIFOs. */
1025 if (IS_QLA2200(ha)) {
1026 WRT_FB_CMD_REG(ha, reg, 0xa000);
1027 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
1029 WRT_FB_CMD_REG(ha, reg, 0x00fc);
1031 /* Read back fb_cmd until zero or 3 seconds max */
1032 for (cnt = 0; cnt < 3000; cnt++) {
1033 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
1039 /* Select RISC module registers. */
1040 WRT_REG_WORD(®->ctrl_status, 0);
1041 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
1043 /* Reset RISC processor. */
1044 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
1045 RD_REG_WORD(®->hccr); /* PCI Posting. */
1047 /* Release RISC processor. */
1048 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
1049 RD_REG_WORD(®->hccr); /* PCI Posting. */
1052 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
1053 WRT_REG_WORD(®->hccr, HCCR_CLR_HOST_INT);
1055 /* Reset ISP chip. */
1056 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
1058 /* Wait for RISC to recover from reset. */
1059 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
1061 * It is necessary to for a delay here since the card doesn't
1062 * respond to PCI reads during a reset. On some architectures
1063 * this will result in an MCA.
1066 for (cnt = 30000; cnt; cnt--) {
1067 if ((RD_REG_WORD(®->ctrl_status) &
1068 CSR_ISP_SOFT_RESET) == 0)
1075 /* Reset RISC processor. */
1076 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
1078 WRT_REG_WORD(®->semaphore, 0);
1080 /* Release RISC processor. */
1081 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
1082 RD_REG_WORD(®->hccr); /* PCI Posting. */
1084 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
1085 for (cnt = 0; cnt < 30000; cnt++) {
1086 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
1094 /* Turn on master enable */
1095 cmd |= PCI_COMMAND_MASTER;
1096 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
1098 /* Disable RISC pause on FPM parity error. */
1099 if (!IS_QLA2100(ha)) {
1100 WRT_REG_WORD(®->hccr, HCCR_DISABLE_PARITY_PAUSE);
1101 RD_REG_WORD(®->hccr); /* PCI Posting. */
1104 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1108 * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC.
1110 * Returns 0 on success.
1113 qla81xx_reset_mpi(scsi_qla_host_t *vha)
1115 uint16_t mb[4] = {0x1010, 0, 1, 0};
1117 if (!IS_QLA81XX(vha->hw))
1120 return qla81xx_write_mpi_register(vha, mb);
1124 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
1127 * Returns 0 on success.
1130 qla24xx_reset_risc(scsi_qla_host_t *vha)
1132 unsigned long flags = 0;
1133 struct qla_hw_data *ha = vha->hw;
1134 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1137 static int abts_cnt; /* ISP abort retry counts */
1138 int rval = QLA_SUCCESS;
1140 spin_lock_irqsave(&ha->hardware_lock, flags);
1143 WRT_REG_DWORD(®->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
1144 for (cnt = 0; cnt < 30000; cnt++) {
1145 if ((RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
1151 if (!(RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE))
1152 set_bit(DMA_SHUTDOWN_CMPL, &ha->fw_dump_cap_flags);
1154 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017e,
1155 "HCCR: 0x%x, Control Status %x, DMA active status:0x%x\n",
1156 RD_REG_DWORD(®->hccr),
1157 RD_REG_DWORD(®->ctrl_status),
1158 (RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE));
1160 WRT_REG_DWORD(®->ctrl_status,
1161 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
1162 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
1166 /* Wait for firmware to complete NVRAM accesses. */
1167 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
1168 for (cnt = 10000; RD_REG_WORD(®->mailbox0) != 0 &&
1169 rval == QLA_SUCCESS; cnt--) {
1174 rval = QLA_FUNCTION_TIMEOUT;
1177 if (rval == QLA_SUCCESS)
1178 set_bit(ISP_MBX_RDY, &ha->fw_dump_cap_flags);
1180 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017f,
1181 "HCCR: 0x%x, MailBox0 Status 0x%x\n",
1182 RD_REG_DWORD(®->hccr),
1183 RD_REG_DWORD(®->mailbox0));
1185 /* Wait for soft-reset to complete. */
1186 d2 = RD_REG_DWORD(®->ctrl_status);
1187 for (cnt = 0; cnt < 6000000; cnt++) {
1189 if ((RD_REG_DWORD(®->ctrl_status) &
1190 CSRX_ISP_SOFT_RESET) == 0)
1195 if (!(RD_REG_DWORD(®->ctrl_status) & CSRX_ISP_SOFT_RESET))
1196 set_bit(ISP_SOFT_RESET_CMPL, &ha->fw_dump_cap_flags);
1198 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015d,
1199 "HCCR: 0x%x, Soft Reset status: 0x%x\n",
1200 RD_REG_DWORD(®->hccr),
1201 RD_REG_DWORD(®->ctrl_status));
1203 /* If required, do an MPI FW reset now */
1204 if (test_and_clear_bit(MPI_RESET_NEEDED, &vha->dpc_flags)) {
1205 if (qla81xx_reset_mpi(vha) != QLA_SUCCESS) {
1206 if (++abts_cnt < 5) {
1207 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1208 set_bit(MPI_RESET_NEEDED, &vha->dpc_flags);
1211 * We exhausted the ISP abort retries. We have to
1212 * set the board offline.
1215 vha->flags.online = 0;
1220 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
1221 RD_REG_DWORD(®->hccr);
1223 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
1224 RD_REG_DWORD(®->hccr);
1226 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_RESET);
1227 RD_REG_DWORD(®->hccr);
1229 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
1230 for (cnt = 6000000; RD_REG_WORD(®->mailbox0) != 0 &&
1231 rval == QLA_SUCCESS; cnt--) {
1236 rval = QLA_FUNCTION_TIMEOUT;
1238 if (rval == QLA_SUCCESS)
1239 set_bit(RISC_RDY_AFT_RESET, &ha->fw_dump_cap_flags);
1241 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015e,
1242 "Host Risc 0x%x, mailbox0 0x%x\n",
1243 RD_REG_DWORD(®->hccr),
1244 RD_REG_WORD(®->mailbox0));
1246 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1248 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015f,
1249 "Driver in %s mode\n",
1250 IS_NOPOLLING_TYPE(ha) ? "Interrupt" : "Polling");
1252 if (IS_NOPOLLING_TYPE(ha))
1253 ha->isp_ops->enable_intrs(ha);
1259 qla25xx_read_risc_sema_reg(scsi_qla_host_t *vha, uint32_t *data)
1261 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
1263 WRT_REG_DWORD(®->iobase_addr, RISC_REGISTER_BASE_OFFSET);
1264 *data = RD_REG_DWORD(®->iobase_window + RISC_REGISTER_WINDOW_OFFET);
1269 qla25xx_write_risc_sema_reg(scsi_qla_host_t *vha, uint32_t data)
1271 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
1273 WRT_REG_DWORD(®->iobase_addr, RISC_REGISTER_BASE_OFFSET);
1274 WRT_REG_DWORD(®->iobase_window + RISC_REGISTER_WINDOW_OFFET, data);
1278 qla25xx_manipulate_risc_semaphore(scsi_qla_host_t *vha)
1280 struct qla_hw_data *ha = vha->hw;
1282 uint delta_msec = 100;
1283 uint elapsed_msec = 0;
1287 if (!IS_QLA25XX(ha) && !IS_QLA2031(ha))
1291 timeout_msec = TIMEOUT_SEMAPHORE;
1292 n = timeout_msec / delta_msec;
1294 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_SET);
1295 qla25xx_read_risc_sema_reg(vha, &wd32);
1296 if (wd32 & RISC_SEMAPHORE)
1299 elapsed_msec += delta_msec;
1300 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
1304 if (!(wd32 & RISC_SEMAPHORE))
1307 if (!(wd32 & RISC_SEMAPHORE_FORCE))
1310 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_CLR);
1311 timeout_msec = TIMEOUT_SEMAPHORE_FORCE;
1312 n = timeout_msec / delta_msec;
1314 qla25xx_read_risc_sema_reg(vha, &wd32);
1315 if (!(wd32 & RISC_SEMAPHORE_FORCE))
1318 elapsed_msec += delta_msec;
1319 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
1323 if (wd32 & RISC_SEMAPHORE_FORCE)
1324 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_CLR);
1329 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_SET);
1336 * qla24xx_reset_chip() - Reset ISP24xx chip.
1339 * Returns 0 on success.
1342 qla24xx_reset_chip(scsi_qla_host_t *vha)
1344 struct qla_hw_data *ha = vha->hw;
1346 if (pci_channel_offline(ha->pdev) &&
1347 ha->flags.pci_channel_io_perm_failure) {
1351 ha->isp_ops->disable_intrs(ha);
1353 qla25xx_manipulate_risc_semaphore(vha);
1355 /* Perform RISC reset. */
1356 qla24xx_reset_risc(vha);
1360 * qla2x00_chip_diag() - Test chip for proper operation.
1363 * Returns 0 on success.
1366 qla2x00_chip_diag(scsi_qla_host_t *vha)
1369 struct qla_hw_data *ha = vha->hw;
1370 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1371 unsigned long flags = 0;
1375 struct req_que *req = ha->req_q_map[0];
1377 /* Assume a failed state */
1378 rval = QLA_FUNCTION_FAILED;
1380 ql_dbg(ql_dbg_init, vha, 0x007b,
1381 "Testing device at %lx.\n", (u_long)®->flash_address);
1383 spin_lock_irqsave(&ha->hardware_lock, flags);
1385 /* Reset ISP chip. */
1386 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
1389 * We need to have a delay here since the card will not respond while
1390 * in reset causing an MCA on some architectures.
1393 data = qla2x00_debounce_register(®->ctrl_status);
1394 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
1396 data = RD_REG_WORD(®->ctrl_status);
1401 goto chip_diag_failed;
1403 ql_dbg(ql_dbg_init, vha, 0x007c,
1404 "Reset register cleared by chip reset.\n");
1406 /* Reset RISC processor. */
1407 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
1408 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
1410 /* Workaround for QLA2312 PCI parity error */
1411 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
1412 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
1413 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
1415 data = RD_MAILBOX_REG(ha, reg, 0);
1422 goto chip_diag_failed;
1424 /* Check product ID of chip */
1425 ql_dbg(ql_dbg_init, vha, 0x007d, "Checking product Id of chip.\n");
1427 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
1428 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
1429 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
1430 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
1431 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
1432 mb[3] != PROD_ID_3) {
1433 ql_log(ql_log_warn, vha, 0x0062,
1434 "Wrong product ID = 0x%x,0x%x,0x%x.\n",
1435 mb[1], mb[2], mb[3]);
1437 goto chip_diag_failed;
1439 ha->product_id[0] = mb[1];
1440 ha->product_id[1] = mb[2];
1441 ha->product_id[2] = mb[3];
1442 ha->product_id[3] = mb[4];
1444 /* Adjust fw RISC transfer size */
1445 if (req->length > 1024)
1446 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
1448 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
1451 if (IS_QLA2200(ha) &&
1452 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
1453 /* Limit firmware transfer size with a 2200A */
1454 ql_dbg(ql_dbg_init, vha, 0x007e, "Found QLA2200A Chip.\n");
1456 ha->device_type |= DT_ISP2200A;
1457 ha->fw_transfer_size = 128;
1460 /* Wrap Incoming Mailboxes Test. */
1461 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1463 ql_dbg(ql_dbg_init, vha, 0x007f, "Checking mailboxes.\n");
1464 rval = qla2x00_mbx_reg_test(vha);
1466 ql_log(ql_log_warn, vha, 0x0080,
1467 "Failed mailbox send register test.\n");
1469 /* Flag a successful rval */
1471 spin_lock_irqsave(&ha->hardware_lock, flags);
1475 ql_log(ql_log_info, vha, 0x0081,
1476 "Chip diagnostics **** FAILED ****.\n");
1478 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1484 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
1487 * Returns 0 on success.
1490 qla24xx_chip_diag(scsi_qla_host_t *vha)
1493 struct qla_hw_data *ha = vha->hw;
1494 struct req_que *req = ha->req_q_map[0];
1496 if (IS_P3P_TYPE(ha))
1499 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
1501 rval = qla2x00_mbx_reg_test(vha);
1503 ql_log(ql_log_warn, vha, 0x0082,
1504 "Failed mailbox send register test.\n");
1506 /* Flag a successful rval */
1514 qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
1517 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
1518 eft_size, fce_size, mq_size;
1521 struct qla_hw_data *ha = vha->hw;
1522 struct req_que *req = ha->req_q_map[0];
1523 struct rsp_que *rsp = ha->rsp_q_map[0];
1526 ql_dbg(ql_dbg_init, vha, 0x00bd,
1527 "Firmware dump already allocated.\n");
1532 ha->fw_dump_cap_flags = 0;
1533 dump_size = fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
1534 req_q_size = rsp_q_size = 0;
1539 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1540 fixed_size = sizeof(struct qla2100_fw_dump);
1541 } else if (IS_QLA23XX(ha)) {
1542 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
1543 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
1545 } else if (IS_FWI2_CAPABLE(ha)) {
1546 if (IS_QLA83XX(ha) || IS_QLA27XX(ha))
1547 fixed_size = offsetof(struct qla83xx_fw_dump, ext_mem);
1548 else if (IS_QLA81XX(ha))
1549 fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem);
1550 else if (IS_QLA25XX(ha))
1551 fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem);
1553 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
1555 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
1558 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha))
1559 mq_size = sizeof(struct qla2xxx_mq_chain);
1561 * Allocate maximum buffer size for all queues.
1562 * Resizing must be done at end-of-dump processing.
1564 mq_size += ha->max_req_queues *
1565 (req->length * sizeof(request_t));
1566 mq_size += ha->max_rsp_queues *
1567 (rsp->length * sizeof(response_t));
1569 if (ha->tgt.atio_ring)
1570 mq_size += ha->tgt.atio_q_length * sizeof(request_t);
1571 /* Allocate memory for Fibre Channel Event Buffer. */
1572 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
1578 dma_free_coherent(&ha->pdev->dev,
1579 FCE_SIZE, ha->fce, ha->fce_dma);
1581 /* Allocate memory for Fibre Channel Event Buffer. */
1582 tc = dma_zalloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
1585 ql_log(ql_log_warn, vha, 0x00be,
1586 "Unable to allocate (%d KB) for FCE.\n",
1591 rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
1592 ha->fce_mb, &ha->fce_bufs);
1594 ql_log(ql_log_warn, vha, 0x00bf,
1595 "Unable to initialize FCE (%d).\n", rval);
1596 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc,
1598 ha->flags.fce_enabled = 0;
1601 ql_dbg(ql_dbg_init, vha, 0x00c0,
1602 "Allocate (%d KB) for FCE...\n", FCE_SIZE / 1024);
1604 fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
1605 ha->flags.fce_enabled = 1;
1606 ha->fce_dma = tc_dma;
1611 dma_free_coherent(&ha->pdev->dev,
1612 EFT_SIZE, ha->eft, ha->eft_dma);
1614 /* Allocate memory for Extended Trace Buffer. */
1615 tc = dma_zalloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
1618 ql_log(ql_log_warn, vha, 0x00c1,
1619 "Unable to allocate (%d KB) for EFT.\n",
1624 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
1626 ql_log(ql_log_warn, vha, 0x00c2,
1627 "Unable to initialize EFT (%d).\n", rval);
1628 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
1632 ql_dbg(ql_dbg_init, vha, 0x00c3,
1633 "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024);
1635 eft_size = EFT_SIZE;
1636 ha->eft_dma = tc_dma;
1641 if (IS_QLA27XX(ha)) {
1642 if (!ha->fw_dump_template) {
1643 ql_log(ql_log_warn, vha, 0x00ba,
1644 "Failed missing fwdump template\n");
1647 dump_size = qla27xx_fwdt_calculate_dump_size(vha);
1648 ql_dbg(ql_dbg_init, vha, 0x00fa,
1649 "-> allocating fwdump (%x bytes)...\n", dump_size);
1653 req_q_size = req->length * sizeof(request_t);
1654 rsp_q_size = rsp->length * sizeof(response_t);
1655 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
1656 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size + eft_size;
1657 ha->chain_offset = dump_size;
1658 dump_size += mq_size + fce_size;
1661 ha->fw_dump = vmalloc(dump_size);
1663 ql_log(ql_log_warn, vha, 0x00c4,
1664 "Unable to allocate (%d KB) for firmware dump.\n",
1668 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce,
1675 dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft,
1682 ha->fw_dump_len = dump_size;
1683 ql_dbg(ql_dbg_init, vha, 0x00c5,
1684 "Allocated (%d KB) for firmware dump.\n", dump_size / 1024);
1689 ha->fw_dump->signature[0] = 'Q';
1690 ha->fw_dump->signature[1] = 'L';
1691 ha->fw_dump->signature[2] = 'G';
1692 ha->fw_dump->signature[3] = 'C';
1693 ha->fw_dump->version = __constant_htonl(1);
1695 ha->fw_dump->fixed_size = htonl(fixed_size);
1696 ha->fw_dump->mem_size = htonl(mem_size);
1697 ha->fw_dump->req_q_size = htonl(req_q_size);
1698 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
1700 ha->fw_dump->eft_size = htonl(eft_size);
1701 ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
1702 ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
1704 ha->fw_dump->header_size =
1705 htonl(offsetof(struct qla2xxx_fw_dump, isp));
1709 qla81xx_mpi_sync(scsi_qla_host_t *vha)
1711 #define MPS_MASK 0xe0
1716 if (!IS_QLA81XX(vha->hw))
1719 rval = qla2x00_write_ram_word(vha, 0x7c00, 1);
1720 if (rval != QLA_SUCCESS) {
1721 ql_log(ql_log_warn, vha, 0x0105,
1722 "Unable to acquire semaphore.\n");
1726 pci_read_config_word(vha->hw->pdev, 0x54, &dc);
1727 rval = qla2x00_read_ram_word(vha, 0x7a15, &dw);
1728 if (rval != QLA_SUCCESS) {
1729 ql_log(ql_log_warn, vha, 0x0067, "Unable to read sync.\n");
1734 if (dc == (dw & MPS_MASK))
1739 rval = qla2x00_write_ram_word(vha, 0x7a15, dw);
1740 if (rval != QLA_SUCCESS) {
1741 ql_log(ql_log_warn, vha, 0x0114, "Unable to gain sync.\n");
1745 rval = qla2x00_write_ram_word(vha, 0x7c00, 0);
1746 if (rval != QLA_SUCCESS) {
1747 ql_log(ql_log_warn, vha, 0x006d,
1748 "Unable to release semaphore.\n");
1756 qla2x00_alloc_outstanding_cmds(struct qla_hw_data *ha, struct req_que *req)
1758 /* Don't try to reallocate the array */
1759 if (req->outstanding_cmds)
1762 if (!IS_FWI2_CAPABLE(ha) || (ha->mqiobase &&
1763 (ql2xmultique_tag || ql2xmaxqueues > 1)))
1764 req->num_outstanding_cmds = DEFAULT_OUTSTANDING_COMMANDS;
1766 if (ha->fw_xcb_count <= ha->fw_iocb_count)
1767 req->num_outstanding_cmds = ha->fw_xcb_count;
1769 req->num_outstanding_cmds = ha->fw_iocb_count;
1772 req->outstanding_cmds = kzalloc(sizeof(srb_t *) *
1773 req->num_outstanding_cmds, GFP_KERNEL);
1775 if (!req->outstanding_cmds) {
1777 * Try to allocate a minimal size just so we can get through
1780 req->num_outstanding_cmds = MIN_OUTSTANDING_COMMANDS;
1781 req->outstanding_cmds = kzalloc(sizeof(srb_t *) *
1782 req->num_outstanding_cmds, GFP_KERNEL);
1784 if (!req->outstanding_cmds) {
1785 ql_log(ql_log_fatal, NULL, 0x0126,
1786 "Failed to allocate memory for "
1787 "outstanding_cmds for req_que %p.\n", req);
1788 req->num_outstanding_cmds = 0;
1789 return QLA_FUNCTION_FAILED;
1797 * qla2x00_setup_chip() - Load and start RISC firmware.
1800 * Returns 0 on success.
1803 qla2x00_setup_chip(scsi_qla_host_t *vha)
1806 uint32_t srisc_address = 0;
1807 struct qla_hw_data *ha = vha->hw;
1808 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1809 unsigned long flags;
1810 uint16_t fw_major_version;
1812 if (IS_P3P_TYPE(ha)) {
1813 rval = ha->isp_ops->load_risc(vha, &srisc_address);
1814 if (rval == QLA_SUCCESS) {
1815 qla2x00_stop_firmware(vha);
1816 goto enable_82xx_npiv;
1821 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1822 /* Disable SRAM, Instruction RAM and GP RAM parity. */
1823 spin_lock_irqsave(&ha->hardware_lock, flags);
1824 WRT_REG_WORD(®->hccr, (HCCR_ENABLE_PARITY + 0x0));
1825 RD_REG_WORD(®->hccr);
1826 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1829 qla81xx_mpi_sync(vha);
1831 /* Load firmware sequences */
1832 rval = ha->isp_ops->load_risc(vha, &srisc_address);
1833 if (rval == QLA_SUCCESS) {
1834 ql_dbg(ql_dbg_init, vha, 0x00c9,
1835 "Verifying Checksum of loaded RISC code.\n");
1837 rval = qla2x00_verify_checksum(vha, srisc_address);
1838 if (rval == QLA_SUCCESS) {
1839 /* Start firmware execution. */
1840 ql_dbg(ql_dbg_init, vha, 0x00ca,
1841 "Starting firmware.\n");
1843 rval = qla2x00_execute_fw(vha, srisc_address);
1844 /* Retrieve firmware information. */
1845 if (rval == QLA_SUCCESS) {
1847 fw_major_version = ha->fw_major_version;
1848 if (IS_P3P_TYPE(ha))
1849 qla82xx_check_md_needed(vha);
1851 rval = qla2x00_get_fw_version(vha);
1852 if (rval != QLA_SUCCESS)
1854 ha->flags.npiv_supported = 0;
1855 if (IS_QLA2XXX_MIDTYPE(ha) &&
1856 (ha->fw_attributes & BIT_2)) {
1857 ha->flags.npiv_supported = 1;
1858 if ((!ha->max_npiv_vports) ||
1859 ((ha->max_npiv_vports + 1) %
1860 MIN_MULTI_ID_FABRIC))
1861 ha->max_npiv_vports =
1862 MIN_MULTI_ID_FABRIC - 1;
1864 qla2x00_get_resource_cnts(vha, NULL,
1865 &ha->fw_xcb_count, NULL, &ha->fw_iocb_count,
1866 &ha->max_npiv_vports, NULL);
1869 * Allocate the array of outstanding commands
1870 * now that we know the firmware resources.
1872 rval = qla2x00_alloc_outstanding_cmds(ha,
1874 if (rval != QLA_SUCCESS)
1877 if (!fw_major_version && ql2xallocfwdump
1878 && !(IS_P3P_TYPE(ha)))
1879 qla2x00_alloc_fw_dump(vha);
1884 ql_log(ql_log_fatal, vha, 0x00cd,
1885 "ISP Firmware failed checksum.\n");
1891 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1892 /* Enable proper parity. */
1893 spin_lock_irqsave(&ha->hardware_lock, flags);
1896 WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x1);
1898 /* SRAM, Instruction RAM and GP RAM parity */
1899 WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x7);
1900 RD_REG_WORD(®->hccr);
1901 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1905 ha->flags.fac_supported = 1;
1906 else if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) {
1909 rval = qla81xx_fac_get_sector_size(vha, &size);
1910 if (rval == QLA_SUCCESS) {
1911 ha->flags.fac_supported = 1;
1912 ha->fdt_block_size = size << 2;
1914 ql_log(ql_log_warn, vha, 0x00ce,
1915 "Unsupported FAC firmware (%d.%02d.%02d).\n",
1916 ha->fw_major_version, ha->fw_minor_version,
1917 ha->fw_subminor_version);
1919 if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
1920 ha->flags.fac_supported = 0;
1927 ql_log(ql_log_fatal, vha, 0x00cf,
1928 "Setup chip ****FAILED****.\n");
1935 * qla2x00_init_response_q_entries() - Initializes response queue entries.
1938 * Beginning of request ring has initialization control block already built
1939 * by nvram config routine.
1941 * Returns 0 on success.
1944 qla2x00_init_response_q_entries(struct rsp_que *rsp)
1949 rsp->ring_ptr = rsp->ring;
1950 rsp->ring_index = 0;
1951 rsp->status_srb = NULL;
1952 pkt = rsp->ring_ptr;
1953 for (cnt = 0; cnt < rsp->length; cnt++) {
1954 pkt->signature = RESPONSE_PROCESSED;
1960 * qla2x00_update_fw_options() - Read and process firmware options.
1963 * Returns 0 on success.
1966 qla2x00_update_fw_options(scsi_qla_host_t *vha)
1968 uint16_t swing, emphasis, tx_sens, rx_sens;
1969 struct qla_hw_data *ha = vha->hw;
1971 memset(ha->fw_options, 0, sizeof(ha->fw_options));
1972 qla2x00_get_fw_options(vha, ha->fw_options);
1974 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1977 /* Serial Link options. */
1978 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0115,
1979 "Serial link options.\n");
1980 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0109,
1981 (uint8_t *)&ha->fw_seriallink_options,
1982 sizeof(ha->fw_seriallink_options));
1984 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
1985 if (ha->fw_seriallink_options[3] & BIT_2) {
1986 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
1989 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
1990 emphasis = (ha->fw_seriallink_options[2] &
1991 (BIT_4 | BIT_3)) >> 3;
1992 tx_sens = ha->fw_seriallink_options[0] &
1993 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
1994 rx_sens = (ha->fw_seriallink_options[0] &
1995 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1996 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
1997 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
2000 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
2001 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
2002 ha->fw_options[10] |= BIT_5 |
2003 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
2004 (tx_sens & (BIT_1 | BIT_0));
2007 swing = (ha->fw_seriallink_options[2] &
2008 (BIT_7 | BIT_6 | BIT_5)) >> 5;
2009 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
2010 tx_sens = ha->fw_seriallink_options[1] &
2011 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
2012 rx_sens = (ha->fw_seriallink_options[1] &
2013 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
2014 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
2015 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
2018 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
2019 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
2020 ha->fw_options[11] |= BIT_5 |
2021 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
2022 (tx_sens & (BIT_1 | BIT_0));
2026 /* Return command IOCBs without waiting for an ABTS to complete. */
2027 ha->fw_options[3] |= BIT_13;
2030 if (ha->flags.enable_led_scheme)
2031 ha->fw_options[2] |= BIT_12;
2033 /* Detect ISP6312. */
2035 ha->fw_options[2] |= BIT_13;
2037 /* Update firmware options. */
2038 qla2x00_set_fw_options(vha, ha->fw_options);
2042 qla24xx_update_fw_options(scsi_qla_host_t *vha)
2045 struct qla_hw_data *ha = vha->hw;
2047 if (IS_P3P_TYPE(ha))
2050 /* Update Serial Link options. */
2051 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
2054 rval = qla2x00_set_serdes_params(vha,
2055 le16_to_cpu(ha->fw_seriallink_options24[1]),
2056 le16_to_cpu(ha->fw_seriallink_options24[2]),
2057 le16_to_cpu(ha->fw_seriallink_options24[3]));
2058 if (rval != QLA_SUCCESS) {
2059 ql_log(ql_log_warn, vha, 0x0104,
2060 "Unable to update Serial Link options (%x).\n", rval);
2065 qla2x00_config_rings(struct scsi_qla_host *vha)
2067 struct qla_hw_data *ha = vha->hw;
2068 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2069 struct req_que *req = ha->req_q_map[0];
2070 struct rsp_que *rsp = ha->rsp_q_map[0];
2072 /* Setup ring parameters in initialization control block. */
2073 ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
2074 ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
2075 ha->init_cb->request_q_length = cpu_to_le16(req->length);
2076 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
2077 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
2078 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
2079 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
2080 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
2082 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
2083 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
2084 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
2085 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
2086 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
2090 qla24xx_config_rings(struct scsi_qla_host *vha)
2092 struct qla_hw_data *ha = vha->hw;
2093 device_reg_t __iomem *reg = ISP_QUE_REG(ha, 0);
2094 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
2095 struct qla_msix_entry *msix;
2096 struct init_cb_24xx *icb;
2098 struct req_que *req = ha->req_q_map[0];
2099 struct rsp_que *rsp = ha->rsp_q_map[0];
2101 /* Setup ring parameters in initialization control block. */
2102 icb = (struct init_cb_24xx *)ha->init_cb;
2103 icb->request_q_outpointer = __constant_cpu_to_le16(0);
2104 icb->response_q_inpointer = __constant_cpu_to_le16(0);
2105 icb->request_q_length = cpu_to_le16(req->length);
2106 icb->response_q_length = cpu_to_le16(rsp->length);
2107 icb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
2108 icb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
2109 icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
2110 icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
2112 /* Setup ATIO queue dma pointers for target mode */
2113 icb->atio_q_inpointer = __constant_cpu_to_le16(0);
2114 icb->atio_q_length = cpu_to_le16(ha->tgt.atio_q_length);
2115 icb->atio_q_address[0] = cpu_to_le32(LSD(ha->tgt.atio_dma));
2116 icb->atio_q_address[1] = cpu_to_le32(MSD(ha->tgt.atio_dma));
2118 if (IS_SHADOW_REG_CAPABLE(ha))
2119 icb->firmware_options_2 |=
2120 __constant_cpu_to_le32(BIT_30|BIT_29);
2122 if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
2123 icb->qos = __constant_cpu_to_le16(QLA_DEFAULT_QUE_QOS);
2124 icb->rid = __constant_cpu_to_le16(rid);
2125 if (ha->flags.msix_enabled) {
2126 msix = &ha->msix_entries[1];
2127 ql_dbg(ql_dbg_init, vha, 0x00fd,
2128 "Registering vector 0x%x for base que.\n",
2130 icb->msix = cpu_to_le16(msix->entry);
2132 /* Use alternate PCI bus number */
2134 icb->firmware_options_2 |=
2135 __constant_cpu_to_le32(BIT_19);
2136 /* Use alternate PCI devfn */
2138 icb->firmware_options_2 |=
2139 __constant_cpu_to_le32(BIT_18);
2141 /* Use Disable MSIX Handshake mode for capable adapters */
2142 if ((ha->fw_attributes & BIT_6) && (IS_MSIX_NACK_CAPABLE(ha)) &&
2143 (ha->flags.msix_enabled)) {
2144 icb->firmware_options_2 &=
2145 __constant_cpu_to_le32(~BIT_22);
2146 ha->flags.disable_msix_handshake = 1;
2147 ql_dbg(ql_dbg_init, vha, 0x00fe,
2148 "MSIX Handshake Disable Mode turned on.\n");
2150 icb->firmware_options_2 |=
2151 __constant_cpu_to_le32(BIT_22);
2153 icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_23);
2155 WRT_REG_DWORD(®->isp25mq.req_q_in, 0);
2156 WRT_REG_DWORD(®->isp25mq.req_q_out, 0);
2157 WRT_REG_DWORD(®->isp25mq.rsp_q_in, 0);
2158 WRT_REG_DWORD(®->isp25mq.rsp_q_out, 0);
2160 WRT_REG_DWORD(®->isp24.req_q_in, 0);
2161 WRT_REG_DWORD(®->isp24.req_q_out, 0);
2162 WRT_REG_DWORD(®->isp24.rsp_q_in, 0);
2163 WRT_REG_DWORD(®->isp24.rsp_q_out, 0);
2165 qlt_24xx_config_rings(vha);
2168 RD_REG_DWORD(&ioreg->hccr);
2172 * qla2x00_init_rings() - Initializes firmware.
2175 * Beginning of request ring has initialization control block already built
2176 * by nvram config routine.
2178 * Returns 0 on success.
2181 qla2x00_init_rings(scsi_qla_host_t *vha)
2184 unsigned long flags = 0;
2186 struct qla_hw_data *ha = vha->hw;
2187 struct req_que *req;
2188 struct rsp_que *rsp;
2189 struct mid_init_cb_24xx *mid_init_cb =
2190 (struct mid_init_cb_24xx *) ha->init_cb;
2192 spin_lock_irqsave(&ha->hardware_lock, flags);
2194 /* Clear outstanding commands array. */
2195 for (que = 0; que < ha->max_req_queues; que++) {
2196 req = ha->req_q_map[que];
2199 req->out_ptr = (void *)(req->ring + req->length);
2201 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++)
2202 req->outstanding_cmds[cnt] = NULL;
2204 req->current_outstanding_cmd = 1;
2206 /* Initialize firmware. */
2207 req->ring_ptr = req->ring;
2208 req->ring_index = 0;
2209 req->cnt = req->length;
2212 for (que = 0; que < ha->max_rsp_queues; que++) {
2213 rsp = ha->rsp_q_map[que];
2216 rsp->in_ptr = (void *)(rsp->ring + rsp->length);
2218 /* Initialize response queue entries */
2220 qlafx00_init_response_q_entries(rsp);
2222 qla2x00_init_response_q_entries(rsp);
2225 ha->tgt.atio_ring_ptr = ha->tgt.atio_ring;
2226 ha->tgt.atio_ring_index = 0;
2227 /* Initialize ATIO queue entries */
2228 qlt_init_atio_q_entries(vha);
2230 ha->isp_ops->config_rings(vha);
2232 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2234 ql_dbg(ql_dbg_init, vha, 0x00d1, "Issue init firmware.\n");
2236 if (IS_QLAFX00(ha)) {
2237 rval = qlafx00_init_firmware(vha, ha->init_cb_size);
2241 /* Update any ISP specific firmware options before initialization. */
2242 ha->isp_ops->update_fw_options(vha);
2244 if (ha->flags.npiv_supported) {
2245 if (ha->operating_mode == LOOP && !IS_CNA_CAPABLE(ha))
2246 ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
2247 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
2250 if (IS_FWI2_CAPABLE(ha)) {
2251 mid_init_cb->options = __constant_cpu_to_le16(BIT_1);
2252 mid_init_cb->init_cb.execution_throttle =
2253 cpu_to_le16(ha->fw_xcb_count);
2255 if (IS_DPORT_CAPABLE(ha))
2256 mid_init_cb->init_cb.firmware_options_1 |=
2258 /* Enable FA-WWPN */
2259 ha->flags.fawwpn_enabled =
2260 (mid_init_cb->init_cb.firmware_options_1 & BIT_6) ? 1 : 0;
2261 ql_dbg(ql_dbg_init, vha, 0x0141, "FA-WWPN Support: %s.\n",
2262 (ha->flags.fawwpn_enabled) ? "enabled" : "disabled");
2265 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
2268 ql_log(ql_log_fatal, vha, 0x00d2,
2269 "Init Firmware **** FAILED ****.\n");
2271 ql_dbg(ql_dbg_init, vha, 0x00d3,
2272 "Init Firmware -- success.\n");
2279 * qla2x00_fw_ready() - Waits for firmware ready.
2282 * Returns 0 on success.
2285 qla2x00_fw_ready(scsi_qla_host_t *vha)
2288 unsigned long wtime, mtime, cs84xx_time;
2289 uint16_t min_wait; /* Minimum wait time if loop is down */
2290 uint16_t wait_time; /* Wait time if loop is coming ready */
2292 struct qla_hw_data *ha = vha->hw;
2294 if (IS_QLAFX00(vha->hw))
2295 return qlafx00_fw_ready(vha);
2299 /* Time to wait for loop down */
2300 if (IS_P3P_TYPE(ha))
2306 * Firmware should take at most one RATOV to login, plus 5 seconds for
2307 * our own processing.
2309 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
2310 wait_time = min_wait;
2313 /* Min wait time if loop down */
2314 mtime = jiffies + (min_wait * HZ);
2316 /* wait time before firmware ready */
2317 wtime = jiffies + (wait_time * HZ);
2319 /* Wait for ISP to finish LIP */
2320 if (!vha->flags.init_done)
2321 ql_log(ql_log_info, vha, 0x801e,
2322 "Waiting for LIP to complete.\n");
2325 memset(state, -1, sizeof(state));
2326 rval = qla2x00_get_firmware_state(vha, state);
2327 if (rval == QLA_SUCCESS) {
2328 if (state[0] < FSTATE_LOSS_OF_SYNC) {
2329 vha->device_flags &= ~DFLG_NO_CABLE;
2331 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
2332 ql_dbg(ql_dbg_taskm, vha, 0x801f,
2333 "fw_state=%x 84xx=%x.\n", state[0],
2335 if ((state[2] & FSTATE_LOGGED_IN) &&
2336 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
2337 ql_dbg(ql_dbg_taskm, vha, 0x8028,
2338 "Sending verify iocb.\n");
2340 cs84xx_time = jiffies;
2341 rval = qla84xx_init_chip(vha);
2342 if (rval != QLA_SUCCESS) {
2345 "Init chip failed.\n");
2349 /* Add time taken to initialize. */
2350 cs84xx_time = jiffies - cs84xx_time;
2351 wtime += cs84xx_time;
2352 mtime += cs84xx_time;
2353 ql_dbg(ql_dbg_taskm, vha, 0x8008,
2354 "Increasing wait time by %ld. "
2355 "New time %ld.\n", cs84xx_time,
2358 } else if (state[0] == FSTATE_READY) {
2359 ql_dbg(ql_dbg_taskm, vha, 0x8037,
2360 "F/W Ready - OK.\n");
2362 qla2x00_get_retry_cnt(vha, &ha->retry_count,
2363 &ha->login_timeout, &ha->r_a_tov);
2369 rval = QLA_FUNCTION_FAILED;
2371 if (atomic_read(&vha->loop_down_timer) &&
2372 state[0] != FSTATE_READY) {
2373 /* Loop down. Timeout on min_wait for states
2374 * other than Wait for Login.
2376 if (time_after_eq(jiffies, mtime)) {
2377 ql_log(ql_log_info, vha, 0x8038,
2378 "Cable is unplugged...\n");
2380 vha->device_flags |= DFLG_NO_CABLE;
2385 /* Mailbox cmd failed. Timeout on min_wait. */
2386 if (time_after_eq(jiffies, mtime) ||
2387 ha->flags.isp82xx_fw_hung)
2391 if (time_after_eq(jiffies, wtime))
2394 /* Delay for a while */
2398 ql_dbg(ql_dbg_taskm, vha, 0x803a,
2399 "fw_state=%x (%x, %x, %x, %x %x) curr time=%lx.\n", state[0],
2400 state[1], state[2], state[3], state[4], state[5], jiffies);
2402 if (rval && !(vha->device_flags & DFLG_NO_CABLE)) {
2403 ql_log(ql_log_warn, vha, 0x803b,
2404 "Firmware ready **** FAILED ****.\n");
2411 * qla2x00_configure_hba
2412 * Setup adapter context.
2415 * ha = adapter state pointer.
2424 qla2x00_configure_hba(scsi_qla_host_t *vha)
2433 char connect_type[22];
2434 struct qla_hw_data *ha = vha->hw;
2435 unsigned long flags;
2436 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
2438 /* Get host addresses. */
2439 rval = qla2x00_get_adapter_id(vha,
2440 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
2441 if (rval != QLA_SUCCESS) {
2442 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
2443 IS_CNA_CAPABLE(ha) ||
2444 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
2445 ql_dbg(ql_dbg_disc, vha, 0x2008,
2446 "Loop is in a transition state.\n");
2448 ql_log(ql_log_warn, vha, 0x2009,
2449 "Unable to get host loop ID.\n");
2450 if (IS_FWI2_CAPABLE(ha) && (vha == base_vha) &&
2451 (rval == QLA_COMMAND_ERROR && loop_id == 0x1b)) {
2452 ql_log(ql_log_warn, vha, 0x1151,
2453 "Doing link init.\n");
2454 if (qla24xx_link_initialize(vha) == QLA_SUCCESS)
2457 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
2463 ql_log(ql_log_info, vha, 0x200a,
2464 "Cannot get topology - retrying.\n");
2465 return (QLA_FUNCTION_FAILED);
2468 vha->loop_id = loop_id;
2471 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
2472 ha->operating_mode = LOOP;
2477 ql_dbg(ql_dbg_disc, vha, 0x200b, "HBA in NL topology.\n");
2478 ha->current_topology = ISP_CFG_NL;
2479 strcpy(connect_type, "(Loop)");
2483 ql_dbg(ql_dbg_disc, vha, 0x200c, "HBA in FL topology.\n");
2484 ha->switch_cap = sw_cap;
2485 ha->current_topology = ISP_CFG_FL;
2486 strcpy(connect_type, "(FL_Port)");
2490 ql_dbg(ql_dbg_disc, vha, 0x200d, "HBA in N P2P topology.\n");
2491 ha->operating_mode = P2P;
2492 ha->current_topology = ISP_CFG_N;
2493 strcpy(connect_type, "(N_Port-to-N_Port)");
2497 ql_dbg(ql_dbg_disc, vha, 0x200e, "HBA in F P2P topology.\n");
2498 ha->switch_cap = sw_cap;
2499 ha->operating_mode = P2P;
2500 ha->current_topology = ISP_CFG_F;
2501 strcpy(connect_type, "(F_Port)");
2505 ql_dbg(ql_dbg_disc, vha, 0x200f,
2506 "HBA in unknown topology %x, using NL.\n", topo);
2507 ha->current_topology = ISP_CFG_NL;
2508 strcpy(connect_type, "(Loop)");
2512 /* Save Host port and loop ID. */
2513 /* byte order - Big Endian */
2514 vha->d_id.b.domain = domain;
2515 vha->d_id.b.area = area;
2516 vha->d_id.b.al_pa = al_pa;
2518 spin_lock_irqsave(&ha->vport_slock, flags);
2519 qlt_update_vp_map(vha, SET_AL_PA);
2520 spin_unlock_irqrestore(&ha->vport_slock, flags);
2522 if (!vha->flags.init_done)
2523 ql_log(ql_log_info, vha, 0x2010,
2524 "Topology - %s, Host Loop address 0x%x.\n",
2525 connect_type, vha->loop_id);
2531 qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
2536 struct qla_hw_data *ha = vha->hw;
2537 int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) &&
2538 !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha);
2540 if (memcmp(model, BINZERO, len) != 0) {
2541 strncpy(ha->model_number, model, len);
2542 st = en = ha->model_number;
2545 if (*en != 0x20 && *en != 0x00)
2550 index = (ha->pdev->subsystem_device & 0xff);
2552 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
2553 index < QLA_MODEL_NAMES)
2554 strncpy(ha->model_desc,
2555 qla2x00_model_name[index * 2 + 1],
2556 sizeof(ha->model_desc) - 1);
2558 index = (ha->pdev->subsystem_device & 0xff);
2560 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
2561 index < QLA_MODEL_NAMES) {
2562 strcpy(ha->model_number,
2563 qla2x00_model_name[index * 2]);
2564 strncpy(ha->model_desc,
2565 qla2x00_model_name[index * 2 + 1],
2566 sizeof(ha->model_desc) - 1);
2568 strcpy(ha->model_number, def);
2571 if (IS_FWI2_CAPABLE(ha))
2572 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
2573 sizeof(ha->model_desc));
2576 /* On sparc systems, obtain port and node WWN from firmware
2579 static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
2582 struct qla_hw_data *ha = vha->hw;
2583 struct pci_dev *pdev = ha->pdev;
2584 struct device_node *dp = pci_device_to_OF_node(pdev);
2588 val = of_get_property(dp, "port-wwn", &len);
2589 if (val && len >= WWN_SIZE)
2590 memcpy(nv->port_name, val, WWN_SIZE);
2592 val = of_get_property(dp, "node-wwn", &len);
2593 if (val && len >= WWN_SIZE)
2594 memcpy(nv->node_name, val, WWN_SIZE);
2599 * NVRAM configuration for ISP 2xxx
2602 * ha = adapter block pointer.
2605 * initialization control block in response_ring
2606 * host adapters parameters in host adapter block
2612 qla2x00_nvram_config(scsi_qla_host_t *vha)
2617 uint8_t *dptr1, *dptr2;
2618 struct qla_hw_data *ha = vha->hw;
2619 init_cb_t *icb = ha->init_cb;
2620 nvram_t *nv = ha->nvram;
2621 uint8_t *ptr = ha->nvram;
2622 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2626 /* Determine NVRAM starting address. */
2627 ha->nvram_size = sizeof(nvram_t);
2629 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
2630 if ((RD_REG_WORD(®->ctrl_status) >> 14) == 1)
2631 ha->nvram_base = 0x80;
2633 /* Get NVRAM data and calculate checksum. */
2634 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
2635 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
2638 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x010f,
2639 "Contents of NVRAM.\n");
2640 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0110,
2641 (uint8_t *)nv, ha->nvram_size);
2643 /* Bad NVRAM data, set defaults parameters. */
2644 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
2645 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
2646 /* Reset NVRAM data. */
2647 ql_log(ql_log_warn, vha, 0x0064,
2648 "Inconsistent NVRAM "
2649 "detected: checksum=0x%x id=%c version=0x%x.\n",
2650 chksum, nv->id[0], nv->nvram_version);
2651 ql_log(ql_log_warn, vha, 0x0065,
2653 "functioning (yet invalid -- WWPN) defaults.\n");
2656 * Set default initialization control block.
2658 memset(nv, 0, ha->nvram_size);
2659 nv->parameter_block_version = ICB_VERSION;
2661 if (IS_QLA23XX(ha)) {
2662 nv->firmware_options[0] = BIT_2 | BIT_1;
2663 nv->firmware_options[1] = BIT_7 | BIT_5;
2664 nv->add_firmware_options[0] = BIT_5;
2665 nv->add_firmware_options[1] = BIT_5 | BIT_4;
2666 nv->frame_payload_size = 2048;
2667 nv->special_options[1] = BIT_7;
2668 } else if (IS_QLA2200(ha)) {
2669 nv->firmware_options[0] = BIT_2 | BIT_1;
2670 nv->firmware_options[1] = BIT_7 | BIT_5;
2671 nv->add_firmware_options[0] = BIT_5;
2672 nv->add_firmware_options[1] = BIT_5 | BIT_4;
2673 nv->frame_payload_size = 1024;
2674 } else if (IS_QLA2100(ha)) {
2675 nv->firmware_options[0] = BIT_3 | BIT_1;
2676 nv->firmware_options[1] = BIT_5;
2677 nv->frame_payload_size = 1024;
2680 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
2681 nv->execution_throttle = __constant_cpu_to_le16(16);
2682 nv->retry_count = 8;
2683 nv->retry_delay = 1;
2685 nv->port_name[0] = 33;
2686 nv->port_name[3] = 224;
2687 nv->port_name[4] = 139;
2689 qla2xxx_nvram_wwn_from_ofw(vha, nv);
2691 nv->login_timeout = 4;
2694 * Set default host adapter parameters
2696 nv->host_p[1] = BIT_2;
2697 nv->reset_delay = 5;
2698 nv->port_down_retry_count = 8;
2699 nv->max_luns_per_target = __constant_cpu_to_le16(8);
2700 nv->link_down_timeout = 60;
2705 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
2707 * The SN2 does not provide BIOS emulation which means you can't change
2708 * potentially bogus BIOS settings. Force the use of default settings
2709 * for link rate and frame size. Hope that the rest of the settings
2712 if (ia64_platform_is("sn2")) {
2713 nv->frame_payload_size = 2048;
2715 nv->special_options[1] = BIT_7;
2719 /* Reset Initialization control block */
2720 memset(icb, 0, ha->init_cb_size);
2723 * Setup driver NVRAM options.
2725 nv->firmware_options[0] |= (BIT_6 | BIT_1);
2726 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
2727 nv->firmware_options[1] |= (BIT_5 | BIT_0);
2728 nv->firmware_options[1] &= ~BIT_4;
2730 if (IS_QLA23XX(ha)) {
2731 nv->firmware_options[0] |= BIT_2;
2732 nv->firmware_options[0] &= ~BIT_3;
2733 nv->special_options[0] &= ~BIT_6;
2734 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
2736 if (IS_QLA2300(ha)) {
2737 if (ha->fb_rev == FPM_2310) {
2738 strcpy(ha->model_number, "QLA2310");
2740 strcpy(ha->model_number, "QLA2300");
2743 qla2x00_set_model_info(vha, nv->model_number,
2744 sizeof(nv->model_number), "QLA23xx");
2746 } else if (IS_QLA2200(ha)) {
2747 nv->firmware_options[0] |= BIT_2;
2749 * 'Point-to-point preferred, else loop' is not a safe
2750 * connection mode setting.
2752 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
2754 /* Force 'loop preferred, else point-to-point'. */
2755 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
2756 nv->add_firmware_options[0] |= BIT_5;
2758 strcpy(ha->model_number, "QLA22xx");
2759 } else /*if (IS_QLA2100(ha))*/ {
2760 strcpy(ha->model_number, "QLA2100");
2764 * Copy over NVRAM RISC parameter block to initialization control block.
2766 dptr1 = (uint8_t *)icb;
2767 dptr2 = (uint8_t *)&nv->parameter_block_version;
2768 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
2770 *dptr1++ = *dptr2++;
2772 /* Copy 2nd half. */
2773 dptr1 = (uint8_t *)icb->add_firmware_options;
2774 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
2776 *dptr1++ = *dptr2++;
2778 /* Use alternate WWN? */
2779 if (nv->host_p[1] & BIT_7) {
2780 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
2781 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
2784 /* Prepare nodename */
2785 if ((icb->firmware_options[1] & BIT_6) == 0) {
2787 * Firmware will apply the following mask if the nodename was
2790 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
2791 icb->node_name[0] &= 0xF0;
2795 * Set host adapter parameters.
2799 * BIT_7 in the host-parameters section allows for modification to
2800 * internal driver logging.
2802 if (nv->host_p[0] & BIT_7)
2803 ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK;
2804 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
2805 /* Always load RISC code on non ISP2[12]00 chips. */
2806 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
2807 ha->flags.disable_risc_code_load = 0;
2808 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
2809 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
2810 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
2811 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
2812 ha->flags.disable_serdes = 0;
2814 ha->operating_mode =
2815 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
2817 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
2818 sizeof(ha->fw_seriallink_options));
2820 /* save HBA serial number */
2821 ha->serial0 = icb->port_name[5];
2822 ha->serial1 = icb->port_name[6];
2823 ha->serial2 = icb->port_name[7];
2824 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
2825 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
2827 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
2829 ha->retry_count = nv->retry_count;
2831 /* Set minimum login_timeout to 4 seconds. */
2832 if (nv->login_timeout != ql2xlogintimeout)
2833 nv->login_timeout = ql2xlogintimeout;
2834 if (nv->login_timeout < 4)
2835 nv->login_timeout = 4;
2836 ha->login_timeout = nv->login_timeout;
2837 icb->login_timeout = nv->login_timeout;
2839 /* Set minimum RATOV to 100 tenths of a second. */
2842 ha->loop_reset_delay = nv->reset_delay;
2844 /* Link Down Timeout = 0:
2846 * When Port Down timer expires we will start returning
2847 * I/O's to OS with "DID_NO_CONNECT".
2849 * Link Down Timeout != 0:
2851 * The driver waits for the link to come up after link down
2852 * before returning I/Os to OS with "DID_NO_CONNECT".
2854 if (nv->link_down_timeout == 0) {
2855 ha->loop_down_abort_time =
2856 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
2858 ha->link_down_timeout = nv->link_down_timeout;
2859 ha->loop_down_abort_time =
2860 (LOOP_DOWN_TIME - ha->link_down_timeout);
2864 * Need enough time to try and get the port back.
2866 ha->port_down_retry_count = nv->port_down_retry_count;
2867 if (qlport_down_retry)
2868 ha->port_down_retry_count = qlport_down_retry;
2869 /* Set login_retry_count */
2870 ha->login_retry_count = nv->retry_count;
2871 if (ha->port_down_retry_count == nv->port_down_retry_count &&
2872 ha->port_down_retry_count > 3)
2873 ha->login_retry_count = ha->port_down_retry_count;
2874 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
2875 ha->login_retry_count = ha->port_down_retry_count;
2876 if (ql2xloginretrycount)
2877 ha->login_retry_count = ql2xloginretrycount;
2879 icb->lun_enables = __constant_cpu_to_le16(0);
2880 icb->command_resource_count = 0;
2881 icb->immediate_notify_resource_count = 0;
2882 icb->timeout = __constant_cpu_to_le16(0);
2884 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
2886 icb->firmware_options[0] &= ~BIT_3;
2887 icb->add_firmware_options[0] &=
2888 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
2889 icb->add_firmware_options[0] |= BIT_2;
2890 icb->response_accumulation_timer = 3;
2891 icb->interrupt_delay_timer = 5;
2893 vha->flags.process_response_queue = 1;
2896 if (!vha->flags.init_done) {
2897 ha->zio_mode = icb->add_firmware_options[0] &
2898 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
2899 ha->zio_timer = icb->interrupt_delay_timer ?
2900 icb->interrupt_delay_timer: 2;
2902 icb->add_firmware_options[0] &=
2903 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
2904 vha->flags.process_response_queue = 0;
2905 if (ha->zio_mode != QLA_ZIO_DISABLED) {
2906 ha->zio_mode = QLA_ZIO_MODE_6;
2908 ql_log(ql_log_info, vha, 0x0068,
2909 "ZIO mode %d enabled; timer delay (%d us).\n",
2910 ha->zio_mode, ha->zio_timer * 100);
2912 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
2913 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
2914 vha->flags.process_response_queue = 1;
2919 ql_log(ql_log_warn, vha, 0x0069,
2920 "NVRAM configuration failed.\n");
2926 qla2x00_rport_del(void *data)
2928 fc_port_t *fcport = data;
2929 struct fc_rport *rport;
2930 unsigned long flags;
2932 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
2933 rport = fcport->drport ? fcport->drport: fcport->rport;
2934 fcport->drport = NULL;
2935 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
2937 fc_remote_port_delete(rport);
2941 * qla2x00_alloc_fcport() - Allocate a generic fcport.
2943 * @flags: allocation flags
2945 * Returns a pointer to the allocated fcport, or NULL, if none available.
2948 qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
2952 fcport = kzalloc(sizeof(fc_port_t), flags);
2956 /* Setup fcport template structure. */
2958 fcport->port_type = FCT_UNKNOWN;
2959 fcport->loop_id = FC_NO_LOOP_ID;
2960 qla2x00_set_fcport_state(fcport, FCS_UNCONFIGURED);
2961 fcport->supported_classes = FC_COS_UNSPECIFIED;
2967 * qla2x00_configure_loop
2968 * Updates Fibre Channel Device Database with what is actually on loop.
2971 * ha = adapter block pointer.
2976 * 2 = database was full and device was not configured.
2979 qla2x00_configure_loop(scsi_qla_host_t *vha)
2982 unsigned long flags, save_flags;
2983 struct qla_hw_data *ha = vha->hw;
2986 /* Get Initiator ID */
2987 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
2988 rval = qla2x00_configure_hba(vha);
2989 if (rval != QLA_SUCCESS) {
2990 ql_dbg(ql_dbg_disc, vha, 0x2013,
2991 "Unable to configure HBA.\n");
2996 save_flags = flags = vha->dpc_flags;
2997 ql_dbg(ql_dbg_disc, vha, 0x2014,
2998 "Configure loop -- dpc flags = 0x%lx.\n", flags);
3001 * If we have both an RSCN and PORT UPDATE pending then handle them
3002 * both at the same time.
3004 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
3005 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
3007 qla2x00_get_data_rate(vha);
3009 /* Determine what we need to do */
3010 if (ha->current_topology == ISP_CFG_FL &&
3011 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
3013 set_bit(RSCN_UPDATE, &flags);
3015 } else if (ha->current_topology == ISP_CFG_F &&
3016 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
3018 set_bit(RSCN_UPDATE, &flags);
3019 clear_bit(LOCAL_LOOP_UPDATE, &flags);
3021 } else if (ha->current_topology == ISP_CFG_N) {
3022 clear_bit(RSCN_UPDATE, &flags);
3024 } else if (!vha->flags.online ||
3025 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
3027 set_bit(RSCN_UPDATE, &flags);
3028 set_bit(LOCAL_LOOP_UPDATE, &flags);
3031 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
3032 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
3033 ql_dbg(ql_dbg_disc, vha, 0x2015,
3034 "Loop resync needed, failing.\n");
3035 rval = QLA_FUNCTION_FAILED;
3037 rval = qla2x00_configure_local_loop(vha);
3040 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
3041 if (LOOP_TRANSITION(vha)) {
3042 ql_dbg(ql_dbg_disc, vha, 0x201e,
3043 "Needs RSCN update and loop transition.\n");
3044 rval = QLA_FUNCTION_FAILED;
3047 rval = qla2x00_configure_fabric(vha);
3050 if (rval == QLA_SUCCESS) {
3051 if (atomic_read(&vha->loop_down_timer) ||
3052 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
3053 rval = QLA_FUNCTION_FAILED;
3055 atomic_set(&vha->loop_state, LOOP_READY);
3056 ql_dbg(ql_dbg_disc, vha, 0x2069,
3062 ql_dbg(ql_dbg_disc, vha, 0x206a,
3063 "%s *** FAILED ***.\n", __func__);
3065 ql_dbg(ql_dbg_disc, vha, 0x206b,
3066 "%s: exiting normally.\n", __func__);
3069 /* Restore state if a resync event occurred during processing */
3070 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
3071 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
3072 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
3073 if (test_bit(RSCN_UPDATE, &save_flags)) {
3074 set_bit(RSCN_UPDATE, &vha->dpc_flags);
3084 * qla2x00_configure_local_loop
3085 * Updates Fibre Channel Device Database with local loop devices.
3088 * ha = adapter block pointer.
3094 qla2x00_configure_local_loop(scsi_qla_host_t *vha)
3099 fc_port_t *fcport, *new_fcport;
3105 uint8_t domain, area, al_pa;
3106 struct qla_hw_data *ha = vha->hw;
3110 entries = MAX_FIBRE_DEVICES_LOOP;
3112 /* Get list of logged in devices. */
3113 memset(ha->gid_list, 0, qla2x00_gid_list_size(ha));
3114 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
3116 if (rval != QLA_SUCCESS)
3117 goto cleanup_allocation;
3119 ql_dbg(ql_dbg_disc, vha, 0x2017,
3120 "Entries in ID list (%d).\n", entries);
3121 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2075,
3122 (uint8_t *)ha->gid_list,
3123 entries * sizeof(struct gid_list_info));
3125 /* Allocate temporary fcport for any new fcports discovered. */
3126 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
3127 if (new_fcport == NULL) {
3128 ql_log(ql_log_warn, vha, 0x2018,
3129 "Memory allocation failed for fcport.\n");
3130 rval = QLA_MEMORY_ALLOC_FAILED;
3131 goto cleanup_allocation;
3133 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
3136 * Mark local devices that were present with FCF_DEVICE_LOST for now.
3138 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3139 if (atomic_read(&fcport->state) == FCS_ONLINE &&
3140 fcport->port_type != FCT_BROADCAST &&
3141 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
3143 ql_dbg(ql_dbg_disc, vha, 0x2019,
3144 "Marking port lost loop_id=0x%04x.\n",
3147 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
3151 /* Add devices to port list. */
3152 id_iter = (char *)ha->gid_list;
3153 for (index = 0; index < entries; index++) {
3154 domain = ((struct gid_list_info *)id_iter)->domain;
3155 area = ((struct gid_list_info *)id_iter)->area;
3156 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
3157 if (IS_QLA2100(ha) || IS_QLA2200(ha))
3158 loop_id = (uint16_t)
3159 ((struct gid_list_info *)id_iter)->loop_id_2100;
3161 loop_id = le16_to_cpu(
3162 ((struct gid_list_info *)id_iter)->loop_id);
3163 id_iter += ha->gid_list_info_size;
3165 /* Bypass reserved domain fields. */
3166 if ((domain & 0xf0) == 0xf0)
3169 /* Bypass if not same domain and area of adapter. */
3170 if (area && domain &&
3171 (area != vha->d_id.b.area || domain != vha->d_id.b.domain))
3174 /* Bypass invalid local loop ID. */
3175 if (loop_id > LAST_LOCAL_LOOP_ID)
3178 memset(new_fcport, 0, sizeof(fc_port_t));
3180 /* Fill in member data. */
3181 new_fcport->d_id.b.domain = domain;
3182 new_fcport->d_id.b.area = area;
3183 new_fcport->d_id.b.al_pa = al_pa;
3184 new_fcport->loop_id = loop_id;
3185 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
3186 if (rval2 != QLA_SUCCESS) {
3187 ql_dbg(ql_dbg_disc, vha, 0x201a,
3188 "Failed to retrieve fcport information "
3189 "-- get_port_database=%x, loop_id=0x%04x.\n",
3190 rval2, new_fcport->loop_id);
3191 ql_dbg(ql_dbg_disc, vha, 0x201b,
3192 "Scheduling resync.\n");
3193 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
3197 /* Check for matching device in port list. */
3200 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3201 if (memcmp(new_fcport->port_name, fcport->port_name,
3205 fcport->flags &= ~FCF_FABRIC_DEVICE;
3206 fcport->loop_id = new_fcport->loop_id;
3207 fcport->port_type = new_fcport->port_type;
3208 fcport->d_id.b24 = new_fcport->d_id.b24;
3209 memcpy(fcport->node_name, new_fcport->node_name,
3217 /* New device, add to fcports list. */
3218 list_add_tail(&new_fcport->list, &vha->vp_fcports);
3220 /* Allocate a new replacement fcport. */
3221 fcport = new_fcport;
3222 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
3223 if (new_fcport == NULL) {
3224 ql_log(ql_log_warn, vha, 0x201c,
3225 "Failed to allocate memory for fcport.\n");
3226 rval = QLA_MEMORY_ALLOC_FAILED;
3227 goto cleanup_allocation;
3229 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
3232 /* Base iIDMA settings on HBA port speed. */
3233 fcport->fp_speed = ha->link_data_rate;
3235 qla2x00_update_fcport(vha, fcport);
3243 if (rval != QLA_SUCCESS) {
3244 ql_dbg(ql_dbg_disc, vha, 0x201d,
3245 "Configure local loop error exit: rval=%x.\n", rval);
3252 qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
3255 uint16_t mb[MAILBOX_REGISTER_COUNT];
3256 struct qla_hw_data *ha = vha->hw;
3258 if (!IS_IIDMA_CAPABLE(ha))
3261 if (atomic_read(&fcport->state) != FCS_ONLINE)
3264 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
3265 fcport->fp_speed > ha->link_data_rate)
3268 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
3270 if (rval != QLA_SUCCESS) {
3271 ql_dbg(ql_dbg_disc, vha, 0x2004,
3272 "Unable to adjust iIDMA %8phN -- %04x %x %04x %04x.\n",
3273 fcport->port_name, rval, fcport->fp_speed, mb[0], mb[1]);
3275 ql_dbg(ql_dbg_disc, vha, 0x2005,
3276 "iIDMA adjusted to %s GB/s on %8phN.\n",
3277 qla2x00_get_link_speed_str(ha, fcport->fp_speed),
3283 qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
3285 struct fc_rport_identifiers rport_ids;
3286 struct fc_rport *rport;
3287 unsigned long flags;
3289 rport_ids.node_name = wwn_to_u64(fcport->node_name);
3290 rport_ids.port_name = wwn_to_u64(fcport->port_name);
3291 rport_ids.port_id = fcport->d_id.b.domain << 16 |
3292 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
3293 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
3294 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
3296 ql_log(ql_log_warn, vha, 0x2006,
3297 "Unable to allocate fc remote port.\n");
3301 * Create target mode FC NEXUS in qla_target.c if target mode is
3305 qlt_fc_port_added(vha, fcport);
3307 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
3308 *((fc_port_t **)rport->dd_data) = fcport;
3309 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
3311 rport->supported_classes = fcport->supported_classes;
3313 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
3314 if (fcport->port_type == FCT_INITIATOR)
3315 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
3316 if (fcport->port_type == FCT_TARGET)
3317 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
3318 fc_remote_port_rolechg(rport, rport_ids.roles);
3322 * qla2x00_update_fcport
3323 * Updates device on list.
3326 * ha = adapter block pointer.
3327 * fcport = port structure pointer.
3337 qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
3341 if (IS_QLAFX00(vha->hw)) {
3342 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
3345 fcport->login_retry = 0;
3346 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
3348 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
3349 qla2x00_iidma_fcport(vha, fcport);
3350 qla24xx_update_fcport_fcp_prio(vha, fcport);
3353 if (qla_ini_mode_enabled(vha))
3354 qla2x00_reg_remote_port(vha, fcport);
3357 * Create target mode FC NEXUS in qla_target.c
3359 qlt_fc_port_added(vha, fcport);
3364 * qla2x00_configure_fabric
3365 * Setup SNS devices with loop ID's.
3368 * ha = adapter block pointer.
3375 qla2x00_configure_fabric(scsi_qla_host_t *vha)
3378 fc_port_t *fcport, *fcptemp;
3379 uint16_t next_loopid;
3380 uint16_t mb[MAILBOX_REGISTER_COUNT];
3382 LIST_HEAD(new_fcports);
3383 struct qla_hw_data *ha = vha->hw;
3384 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
3387 /* If FL port exists, then SNS is present */
3388 if (IS_FWI2_CAPABLE(ha))
3389 loop_id = NPH_F_PORT;
3391 loop_id = SNS_FL_PORT;
3392 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
3393 if (rval != QLA_SUCCESS) {
3394 ql_dbg(ql_dbg_disc, vha, 0x201f,
3395 "MBX_GET_PORT_NAME failed, No FL Port.\n");
3397 vha->device_flags &= ~SWITCH_FOUND;
3398 return (QLA_SUCCESS);
3400 vha->device_flags |= SWITCH_FOUND;
3404 if (ql2xfdmienable &&
3405 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
3406 qla2x00_fdmi_register(vha);
3408 /* Ensure we are logged into the SNS. */
3409 if (IS_FWI2_CAPABLE(ha))
3412 loop_id = SIMPLE_NAME_SERVER;
3413 rval = ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
3414 0xfc, mb, BIT_1|BIT_0);
3415 if (rval != QLA_SUCCESS) {
3416 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
3419 if (mb[0] != MBS_COMMAND_COMPLETE) {
3420 ql_dbg(ql_dbg_disc, vha, 0x2042,
3421 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x "
3422 "mb[6]=%x mb[7]=%x.\n", loop_id, mb[0], mb[1],
3423 mb[2], mb[6], mb[7]);
3424 return (QLA_SUCCESS);
3427 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
3428 if (qla2x00_rft_id(vha)) {
3430 ql_dbg(ql_dbg_disc, vha, 0x2045,
3431 "Register FC-4 TYPE failed.\n");
3433 if (qla2x00_rff_id(vha)) {
3435 ql_dbg(ql_dbg_disc, vha, 0x2049,
3436 "Register FC-4 Features failed.\n");
3438 if (qla2x00_rnn_id(vha)) {
3440 ql_dbg(ql_dbg_disc, vha, 0x204f,
3441 "Register Node Name failed.\n");
3442 } else if (qla2x00_rsnn_nn(vha)) {
3444 ql_dbg(ql_dbg_disc, vha, 0x2053,
3445 "Register Symobilic Node Name failed.\n");
3449 #define QLA_FCPORT_SCAN 1
3450 #define QLA_FCPORT_FOUND 2
3452 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3453 fcport->scan_state = QLA_FCPORT_SCAN;
3456 /* Mark the time right before querying FW for connected ports.
3457 * This process is long, asynchronous and by the time it's done,
3458 * collected information might not be accurate anymore. E.g.
3459 * disconnected port might have re-connected and a brand new
3460 * session has been created. In this case session's generation
3461 * will be newer than discovery_gen. */
3462 qlt_do_generation_tick(vha, &discovery_gen);
3464 rval = qla2x00_find_all_fabric_devs(vha, &new_fcports);
3465 if (rval != QLA_SUCCESS)
3469 * Logout all previous fabric devices marked lost, except
3472 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3473 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
3476 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
3479 if (fcport->scan_state == QLA_FCPORT_SCAN) {
3480 if (qla_ini_mode_enabled(base_vha) &&
3481 atomic_read(&fcport->state) == FCS_ONLINE) {
3482 qla2x00_mark_device_lost(vha, fcport,
3483 ql2xplogiabsentdevice, 0);
3484 if (fcport->loop_id != FC_NO_LOOP_ID &&
3485 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
3486 fcport->port_type != FCT_INITIATOR &&
3487 fcport->port_type != FCT_BROADCAST) {
3488 ha->isp_ops->fabric_logout(vha,
3490 fcport->d_id.b.domain,
3491 fcport->d_id.b.area,
3492 fcport->d_id.b.al_pa);
3493 qla2x00_clear_loop_id(fcport);
3495 } else if (!qla_ini_mode_enabled(base_vha)) {
3497 * In target mode, explicitly kill
3498 * sessions and log out of devices
3499 * that are gone, so that we don't
3500 * end up with an initiator using the
3501 * wrong ACL (if the fabric recycles
3502 * an FC address and we have a stale
3503 * session around) and so that we don't
3504 * report initiators that are no longer
3507 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf077,
3508 "port gone, logging out/killing session: "
3509 "%8phC state 0x%x flags 0x%x fc4_type 0x%x "
3512 atomic_read(&fcport->state),
3513 fcport->flags, fcport->fc4_type,
3514 fcport->scan_state);
3515 qlt_fc_port_deleted(vha, fcport,
3521 /* Starting free loop ID. */
3522 next_loopid = ha->min_external_loopid;
3525 * Scan through our port list and login entries that need to be
3528 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3529 if (atomic_read(&vha->loop_down_timer) ||
3530 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
3533 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
3534 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
3538 * If we're not an initiator, skip looking for devices
3539 * and logging in. There's no reason for us to do it,
3540 * and it seems to actively cause problems in target
3541 * mode if we race with the initiator logging into us
3542 * (we might get the "port ID used" status back from
3543 * our login command and log out the initiator, which
3544 * seems to cause havoc).
3546 if (!qla_ini_mode_enabled(base_vha)) {
3547 if (fcport->scan_state == QLA_FCPORT_FOUND) {
3548 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf078,
3549 "port %8phC state 0x%x flags 0x%x fc4_type 0x%x "
3550 "scan_state %d (initiator mode disabled; skipping "
3551 "login)\n", fcport->port_name,
3552 atomic_read(&fcport->state),
3553 fcport->flags, fcport->fc4_type,
3554 fcport->scan_state);
3559 if (fcport->loop_id == FC_NO_LOOP_ID) {
3560 fcport->loop_id = next_loopid;
3561 rval = qla2x00_find_new_loop_id(
3563 if (rval != QLA_SUCCESS) {
3564 /* Ran out of IDs to use */
3568 /* Login and update database */
3569 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
3572 /* Exit if out of loop IDs. */
3573 if (rval != QLA_SUCCESS) {
3578 * Login and add the new devices to our port list.
3580 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
3581 if (atomic_read(&vha->loop_down_timer) ||
3582 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
3586 * If we're not an initiator, skip looking for devices
3587 * and logging in. There's no reason for us to do it,
3588 * and it seems to actively cause problems in target
3589 * mode if we race with the initiator logging into us
3590 * (we might get the "port ID used" status back from
3591 * our login command and log out the initiator, which
3592 * seems to cause havoc).
3594 if (qla_ini_mode_enabled(base_vha)) {
3595 /* Find a new loop ID to use. */
3596 fcport->loop_id = next_loopid;
3597 rval = qla2x00_find_new_loop_id(base_vha,
3599 if (rval != QLA_SUCCESS) {
3600 /* Ran out of IDs to use */
3604 /* Login and update database */
3605 qla2x00_fabric_dev_login(vha, fcport,
3608 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf079,
3609 "new port %8phC state 0x%x flags 0x%x fc4_type "
3610 "0x%x scan_state %d (initiator mode disabled; "
3611 "skipping login)\n",
3613 atomic_read(&fcport->state),
3614 fcport->flags, fcport->fc4_type,
3615 fcport->scan_state);
3618 list_move_tail(&fcport->list, &vha->vp_fcports);
3622 /* Free all new device structures not processed. */
3623 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
3624 list_del(&fcport->list);
3629 ql_dbg(ql_dbg_disc, vha, 0x2068,
3630 "Configure fabric error exit rval=%d.\n", rval);
3637 * qla2x00_find_all_fabric_devs
3640 * ha = adapter block pointer.
3641 * dev = database device entry pointer.
3650 qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha,
3651 struct list_head *new_fcports)
3655 fc_port_t *fcport, *new_fcport, *fcptemp;
3660 int first_dev, last_dev;
3661 port_id_t wrap = {}, nxt_d_id;
3662 struct qla_hw_data *ha = vha->hw;
3663 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
3667 /* Try GID_PT to get device list, else GAN. */
3669 ha->swl = kcalloc(ha->max_fibre_devices, sizeof(sw_info_t),
3674 ql_dbg(ql_dbg_disc, vha, 0x2054,
3675 "GID_PT allocations failed, fallback on GA_NXT.\n");
3677 memset(swl, 0, ha->max_fibre_devices * sizeof(sw_info_t));
3678 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
3680 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
3682 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
3684 } else if (ql2xiidmaenable &&
3685 qla2x00_gfpn_id(vha, swl) == QLA_SUCCESS) {
3686 qla2x00_gpsc(vha, swl);
3689 /* If other queries succeeded probe for FC-4 type */
3691 qla2x00_gff_id(vha, swl);
3695 /* Allocate temporary fcport for any new fcports discovered. */
3696 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
3697 if (new_fcport == NULL) {
3698 ql_log(ql_log_warn, vha, 0x205e,
3699 "Failed to allocate memory for fcport.\n");
3700 return (QLA_MEMORY_ALLOC_FAILED);
3702 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
3703 /* Set start port ID scan at adapter ID. */
3707 /* Starting free loop ID. */
3708 loop_id = ha->min_external_loopid;
3709 for (; loop_id <= ha->max_loop_id; loop_id++) {
3710 if (qla2x00_is_reserved_id(vha, loop_id))
3713 if (ha->current_topology == ISP_CFG_FL &&
3714 (atomic_read(&vha->loop_down_timer) ||
3715 LOOP_TRANSITION(vha))) {
3716 atomic_set(&vha->loop_down_timer, 0);
3717 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
3718 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
3724 wrap.b24 = new_fcport->d_id.b24;
3726 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
3727 memcpy(new_fcport->node_name,
3728 swl[swl_idx].node_name, WWN_SIZE);
3729 memcpy(new_fcport->port_name,
3730 swl[swl_idx].port_name, WWN_SIZE);
3731 memcpy(new_fcport->fabric_port_name,
3732 swl[swl_idx].fabric_port_name, WWN_SIZE);
3733 new_fcport->fp_speed = swl[swl_idx].fp_speed;
3734 new_fcport->fc4_type = swl[swl_idx].fc4_type;
3736 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
3742 /* Send GA_NXT to the switch */
3743 rval = qla2x00_ga_nxt(vha, new_fcport);
3744 if (rval != QLA_SUCCESS) {
3745 ql_log(ql_log_warn, vha, 0x2064,
3746 "SNS scan failed -- assuming "
3747 "zero-entry result.\n");
3748 list_for_each_entry_safe(fcport, fcptemp,
3749 new_fcports, list) {
3750 list_del(&fcport->list);
3758 /* If wrap on switch device list, exit. */
3760 wrap.b24 = new_fcport->d_id.b24;
3762 } else if (new_fcport->d_id.b24 == wrap.b24) {
3763 ql_dbg(ql_dbg_disc, vha, 0x2065,
3764 "Device wrap (%02x%02x%02x).\n",
3765 new_fcport->d_id.b.domain,
3766 new_fcport->d_id.b.area,
3767 new_fcport->d_id.b.al_pa);
3771 /* Bypass if same physical adapter. */
3772 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
3775 /* Bypass virtual ports of the same host. */
3776 if (qla2x00_is_a_vp_did(vha, new_fcport->d_id.b24))
3779 /* Bypass if same domain and area of adapter. */
3780 if (((new_fcport->d_id.b24 & 0xffff00) ==
3781 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
3785 /* Bypass reserved domain fields. */
3786 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
3789 /* Bypass ports whose FCP-4 type is not FCP_SCSI */
3790 if (ql2xgffidenable &&
3791 (new_fcport->fc4_type != FC4_TYPE_FCP_SCSI &&
3792 new_fcport->fc4_type != FC4_TYPE_UNKNOWN))
3795 /* Locate matching device in database. */
3797 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3798 if (memcmp(new_fcport->port_name, fcport->port_name,
3802 fcport->scan_state = QLA_FCPORT_FOUND;
3806 /* Update port state. */
3807 memcpy(fcport->fabric_port_name,
3808 new_fcport->fabric_port_name, WWN_SIZE);
3809 fcport->fp_speed = new_fcport->fp_speed;
3812 * If address the same and state FCS_ONLINE
3813 * (or in target mode), nothing changed.
3815 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
3816 (atomic_read(&fcport->state) == FCS_ONLINE ||
3817 !qla_ini_mode_enabled(base_vha))) {
3822 * If device was not a fabric device before.
3824 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
3825 fcport->d_id.b24 = new_fcport->d_id.b24;
3826 qla2x00_clear_loop_id(fcport);
3827 fcport->flags |= (FCF_FABRIC_DEVICE |
3833 * Port ID changed or device was marked to be updated;
3834 * Log it out if still logged in and mark it for
3837 if (!qla_ini_mode_enabled(base_vha)) {
3838 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf080,
3839 "port changed FC ID, %8phC"
3840 " old %x:%x:%x (loop_id 0x%04x)-> new %x:%x:%x\n",
3842 fcport->d_id.b.domain,
3843 fcport->d_id.b.area,
3844 fcport->d_id.b.al_pa,
3846 new_fcport->d_id.b.domain,
3847 new_fcport->d_id.b.area,
3848 new_fcport->d_id.b.al_pa);
3849 fcport->d_id.b24 = new_fcport->d_id.b24;
3853 fcport->d_id.b24 = new_fcport->d_id.b24;
3854 fcport->flags |= FCF_LOGIN_NEEDED;
3855 if (fcport->loop_id != FC_NO_LOOP_ID &&
3856 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
3857 (fcport->flags & FCF_ASYNC_SENT) == 0 &&
3858 fcport->port_type != FCT_INITIATOR &&
3859 fcport->port_type != FCT_BROADCAST) {
3860 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
3861 fcport->d_id.b.domain, fcport->d_id.b.area,
3862 fcport->d_id.b.al_pa);
3863 qla2x00_clear_loop_id(fcport);
3871 /* If device was not in our fcports list, then add it. */
3872 new_fcport->scan_state = QLA_FCPORT_FOUND;
3873 list_add_tail(&new_fcport->list, new_fcports);
3875 /* Allocate a new replacement fcport. */
3876 nxt_d_id.b24 = new_fcport->d_id.b24;
3877 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
3878 if (new_fcport == NULL) {
3879 ql_log(ql_log_warn, vha, 0x2066,
3880 "Memory allocation failed for fcport.\n");
3881 return (QLA_MEMORY_ALLOC_FAILED);
3883 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
3884 new_fcport->d_id.b24 = nxt_d_id.b24;
3893 * qla2x00_find_new_loop_id
3894 * Scan through our port list and find a new usable loop ID.
3897 * ha: adapter state pointer.
3898 * dev: port structure pointer.
3901 * qla2x00 local function return status code.
3907 qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
3910 struct qla_hw_data *ha = vha->hw;
3911 unsigned long flags = 0;
3915 spin_lock_irqsave(&ha->vport_slock, flags);
3917 dev->loop_id = find_first_zero_bit(ha->loop_id_map,
3919 if (dev->loop_id >= LOOPID_MAP_SIZE ||
3920 qla2x00_is_reserved_id(vha, dev->loop_id)) {
3921 dev->loop_id = FC_NO_LOOP_ID;
3922 rval = QLA_FUNCTION_FAILED;
3924 set_bit(dev->loop_id, ha->loop_id_map);
3926 spin_unlock_irqrestore(&ha->vport_slock, flags);
3928 if (rval == QLA_SUCCESS)
3929 ql_dbg(ql_dbg_disc, dev->vha, 0x2086,
3930 "Assigning new loopid=%x, portid=%x.\n",
3931 dev->loop_id, dev->d_id.b24);
3933 ql_log(ql_log_warn, dev->vha, 0x2087,
3934 "No loop_id's available, portid=%x.\n",
3941 * qla2x00_fabric_dev_login
3942 * Login fabric target device and update FC port database.
3945 * ha: adapter state pointer.
3946 * fcport: port structure list pointer.
3947 * next_loopid: contains value of a new loop ID that can be used
3948 * by the next login attempt.
3951 * qla2x00 local function return status code.
3957 qla2x00_fabric_dev_login(scsi_qla_host_t *vha, fc_port_t *fcport,
3958 uint16_t *next_loopid)
3963 struct qla_hw_data *ha = vha->hw;
3968 if (IS_ALOGIO_CAPABLE(ha)) {
3969 if (fcport->flags & FCF_ASYNC_SENT)
3971 fcport->flags |= FCF_ASYNC_SENT;
3972 rval = qla2x00_post_async_login_work(vha, fcport, NULL);
3977 fcport->flags &= ~FCF_ASYNC_SENT;
3978 rval = qla2x00_fabric_login(vha, fcport, next_loopid);
3979 if (rval == QLA_SUCCESS) {
3980 /* Send an ADISC to FCP2 devices.*/
3982 if (fcport->flags & FCF_FCP2_DEVICE)
3984 rval = qla2x00_get_port_database(vha, fcport, opts);
3985 if (rval != QLA_SUCCESS) {
3986 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
3987 fcport->d_id.b.domain, fcport->d_id.b.area,
3988 fcport->d_id.b.al_pa);
3989 qla2x00_mark_device_lost(vha, fcport, 1, 0);
3991 qla2x00_update_fcport(vha, fcport);
3995 qla2x00_mark_device_lost(vha, fcport, 1, 0);
4002 * qla2x00_fabric_login
4003 * Issue fabric login command.
4006 * ha = adapter block pointer.
4007 * device = pointer to FC device type structure.
4010 * 0 - Login successfully
4012 * 2 - Initiator device
4016 qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
4017 uint16_t *next_loopid)
4021 uint16_t tmp_loopid;
4022 uint16_t mb[MAILBOX_REGISTER_COUNT];
4023 struct qla_hw_data *ha = vha->hw;
4029 ql_dbg(ql_dbg_disc, vha, 0x2000,
4030 "Trying Fabric Login w/loop id 0x%04x for port "
4032 fcport->loop_id, fcport->d_id.b.domain,
4033 fcport->d_id.b.area, fcport->d_id.b.al_pa);
4035 /* Login fcport on switch. */
4036 rval = ha->isp_ops->fabric_login(vha, fcport->loop_id,
4037 fcport->d_id.b.domain, fcport->d_id.b.area,
4038 fcport->d_id.b.al_pa, mb, BIT_0);
4039 if (rval != QLA_SUCCESS) {
4042 if (mb[0] == MBS_PORT_ID_USED) {
4044 * Device has another loop ID. The firmware team
4045 * recommends the driver perform an implicit login with
4046 * the specified ID again. The ID we just used is save
4047 * here so we return with an ID that can be tried by
4051 tmp_loopid = fcport->loop_id;
4052 fcport->loop_id = mb[1];
4054 ql_dbg(ql_dbg_disc, vha, 0x2001,
4055 "Fabric Login: port in use - next loop "
4056 "id=0x%04x, port id= %02x%02x%02x.\n",
4057 fcport->loop_id, fcport->d_id.b.domain,
4058 fcport->d_id.b.area, fcport->d_id.b.al_pa);
4060 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
4065 /* A retry occurred before. */
4066 *next_loopid = tmp_loopid;
4069 * No retry occurred before. Just increment the
4070 * ID value for next login.
4072 *next_loopid = (fcport->loop_id + 1);
4075 if (mb[1] & BIT_0) {
4076 fcport->port_type = FCT_INITIATOR;
4078 fcport->port_type = FCT_TARGET;
4079 if (mb[1] & BIT_1) {
4080 fcport->flags |= FCF_FCP2_DEVICE;
4085 fcport->supported_classes |= FC_COS_CLASS2;
4087 fcport->supported_classes |= FC_COS_CLASS3;
4089 if (IS_FWI2_CAPABLE(ha)) {
4092 FCF_CONF_COMP_SUPPORTED;
4097 } else if (mb[0] == MBS_LOOP_ID_USED) {
4099 * Loop ID already used, try next loop ID.
4102 rval = qla2x00_find_new_loop_id(vha, fcport);
4103 if (rval != QLA_SUCCESS) {
4104 /* Ran out of loop IDs to use */
4107 } else if (mb[0] == MBS_COMMAND_ERROR) {
4109 * Firmware possibly timed out during login. If NO
4110 * retries are left to do then the device is declared
4113 *next_loopid = fcport->loop_id;
4114 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
4115 fcport->d_id.b.domain, fcport->d_id.b.area,
4116 fcport->d_id.b.al_pa);
4117 qla2x00_mark_device_lost(vha, fcport, 1, 0);
4123 * unrecoverable / not handled error
4125 ql_dbg(ql_dbg_disc, vha, 0x2002,
4126 "Failed=%x port_id=%02x%02x%02x loop_id=%x "
4127 "jiffies=%lx.\n", mb[0], fcport->d_id.b.domain,
4128 fcport->d_id.b.area, fcport->d_id.b.al_pa,
4129 fcport->loop_id, jiffies);
4131 *next_loopid = fcport->loop_id;
4132 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
4133 fcport->d_id.b.domain, fcport->d_id.b.area,
4134 fcport->d_id.b.al_pa);
4135 qla2x00_clear_loop_id(fcport);
4136 fcport->login_retry = 0;
4147 * qla2x00_local_device_login
4148 * Issue local device login command.
4151 * ha = adapter block pointer.
4152 * loop_id = loop id of device to login to.
4154 * Returns (Where's the #define!!!!):
4155 * 0 - Login successfully
4160 qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
4163 uint16_t mb[MAILBOX_REGISTER_COUNT];
4165 memset(mb, 0, sizeof(mb));
4166 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
4167 if (rval == QLA_SUCCESS) {
4168 /* Interrogate mailbox registers for any errors */
4169 if (mb[0] == MBS_COMMAND_ERROR)
4171 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
4172 /* device not in PCB table */
4180 * qla2x00_loop_resync
4181 * Resync with fibre channel devices.
4184 * ha = adapter block pointer.
4190 qla2x00_loop_resync(scsi_qla_host_t *vha)
4192 int rval = QLA_SUCCESS;
4194 struct req_que *req;
4195 struct rsp_que *rsp;
4197 if (vha->hw->flags.cpu_affinity_enabled)
4198 req = vha->hw->req_q_map[0];
4203 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
4204 if (vha->flags.online) {
4205 if (!(rval = qla2x00_fw_ready(vha))) {
4206 /* Wait at most MAX_TARGET RSCNs for a stable link. */
4209 if (!IS_QLAFX00(vha->hw)) {
4211 * Issue a marker after FW becomes
4214 qla2x00_marker(vha, req, rsp, 0, 0,
4216 vha->marker_needed = 0;
4219 /* Remap devices on Loop. */
4220 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4222 if (IS_QLAFX00(vha->hw))
4223 qlafx00_configure_devices(vha);
4225 qla2x00_configure_loop(vha);
4228 } while (!atomic_read(&vha->loop_down_timer) &&
4229 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
4230 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
4235 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
4236 return (QLA_FUNCTION_FAILED);
4239 ql_dbg(ql_dbg_disc, vha, 0x206c,
4240 "%s *** FAILED ***.\n", __func__);
4246 * qla2x00_perform_loop_resync
4247 * Description: This function will set the appropriate flags and call
4248 * qla2x00_loop_resync. If successful loop will be resynced
4249 * Arguments : scsi_qla_host_t pointer
4250 * returm : Success or Failure
4253 int qla2x00_perform_loop_resync(scsi_qla_host_t *ha)
4257 if (!test_and_set_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags)) {
4258 /*Configure the flags so that resync happens properly*/
4259 atomic_set(&ha->loop_down_timer, 0);
4260 if (!(ha->device_flags & DFLG_NO_CABLE)) {
4261 atomic_set(&ha->loop_state, LOOP_UP);
4262 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
4263 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
4264 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
4266 rval = qla2x00_loop_resync(ha);
4268 atomic_set(&ha->loop_state, LOOP_DEAD);
4270 clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
4277 qla2x00_update_fcports(scsi_qla_host_t *base_vha)
4280 struct scsi_qla_host *vha;
4281 struct qla_hw_data *ha = base_vha->hw;
4282 unsigned long flags;
4284 spin_lock_irqsave(&ha->vport_slock, flags);
4285 /* Go with deferred removal of rport references. */
4286 list_for_each_entry(vha, &base_vha->hw->vp_list, list) {
4287 atomic_inc(&vha->vref_count);
4288 list_for_each_entry(fcport, &vha->vp_fcports, list) {
4289 if (fcport->drport &&
4290 atomic_read(&fcport->state) != FCS_UNCONFIGURED) {
4291 spin_unlock_irqrestore(&ha->vport_slock, flags);
4292 qla2x00_rport_del(fcport);
4295 * Release the target mode FC NEXUS in
4296 * qla_target.c, if target mod is enabled.
4298 qlt_fc_port_deleted(vha, fcport,
4299 base_vha->total_fcport_update_gen);
4301 spin_lock_irqsave(&ha->vport_slock, flags);
4304 atomic_dec(&vha->vref_count);
4306 spin_unlock_irqrestore(&ha->vport_slock, flags);
4309 /* Assumes idc_lock always held on entry */
4311 qla83xx_reset_ownership(scsi_qla_host_t *vha)
4313 struct qla_hw_data *ha = vha->hw;
4314 uint32_t drv_presence, drv_presence_mask;
4315 uint32_t dev_part_info1, dev_part_info2, class_type;
4316 uint32_t class_type_mask = 0x3;
4317 uint16_t fcoe_other_function = 0xffff, i;
4319 if (IS_QLA8044(ha)) {
4320 drv_presence = qla8044_rd_direct(vha,
4321 QLA8044_CRB_DRV_ACTIVE_INDEX);
4322 dev_part_info1 = qla8044_rd_direct(vha,
4323 QLA8044_CRB_DEV_PART_INFO_INDEX);
4324 dev_part_info2 = qla8044_rd_direct(vha,
4325 QLA8044_CRB_DEV_PART_INFO2);
4327 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
4328 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO1, &dev_part_info1);
4329 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO2, &dev_part_info2);
4331 for (i = 0; i < 8; i++) {
4332 class_type = ((dev_part_info1 >> (i * 4)) & class_type_mask);
4333 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
4334 (i != ha->portnum)) {
4335 fcoe_other_function = i;
4339 if (fcoe_other_function == 0xffff) {
4340 for (i = 0; i < 8; i++) {
4341 class_type = ((dev_part_info2 >> (i * 4)) &
4343 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
4344 ((i + 8) != ha->portnum)) {
4345 fcoe_other_function = i + 8;
4351 * Prepare drv-presence mask based on fcoe functions present.
4352 * However consider only valid physical fcoe function numbers (0-15).
4354 drv_presence_mask = ~((1 << (ha->portnum)) |
4355 ((fcoe_other_function == 0xffff) ?
4356 0 : (1 << (fcoe_other_function))));
4358 /* We are the reset owner iff:
4359 * - No other protocol drivers present.
4360 * - This is the lowest among fcoe functions. */
4361 if (!(drv_presence & drv_presence_mask) &&
4362 (ha->portnum < fcoe_other_function)) {
4363 ql_dbg(ql_dbg_p3p, vha, 0xb07f,
4364 "This host is Reset owner.\n");
4365 ha->flags.nic_core_reset_owner = 1;
4370 __qla83xx_set_drv_ack(scsi_qla_host_t *vha)
4372 int rval = QLA_SUCCESS;
4373 struct qla_hw_data *ha = vha->hw;
4376 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
4377 if (rval == QLA_SUCCESS) {
4378 drv_ack |= (1 << ha->portnum);
4379 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
4386 __qla83xx_clear_drv_ack(scsi_qla_host_t *vha)
4388 int rval = QLA_SUCCESS;
4389 struct qla_hw_data *ha = vha->hw;
4392 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
4393 if (rval == QLA_SUCCESS) {
4394 drv_ack &= ~(1 << ha->portnum);
4395 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
4402 qla83xx_dev_state_to_string(uint32_t dev_state)
4404 switch (dev_state) {
4405 case QLA8XXX_DEV_COLD:
4406 return "COLD/RE-INIT";
4407 case QLA8XXX_DEV_INITIALIZING:
4408 return "INITIALIZING";
4409 case QLA8XXX_DEV_READY:
4411 case QLA8XXX_DEV_NEED_RESET:
4412 return "NEED RESET";
4413 case QLA8XXX_DEV_NEED_QUIESCENT:
4414 return "NEED QUIESCENT";
4415 case QLA8XXX_DEV_FAILED:
4417 case QLA8XXX_DEV_QUIESCENT:
4424 /* Assumes idc-lock always held on entry */
4426 qla83xx_idc_audit(scsi_qla_host_t *vha, int audit_type)
4428 struct qla_hw_data *ha = vha->hw;
4429 uint32_t idc_audit_reg = 0, duration_secs = 0;
4431 switch (audit_type) {
4432 case IDC_AUDIT_TIMESTAMP:
4433 ha->idc_audit_ts = (jiffies_to_msecs(jiffies) / 1000);
4434 idc_audit_reg = (ha->portnum) |
4435 (IDC_AUDIT_TIMESTAMP << 7) | (ha->idc_audit_ts << 8);
4436 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
4439 case IDC_AUDIT_COMPLETION:
4440 duration_secs = ((jiffies_to_msecs(jiffies) -
4441 jiffies_to_msecs(ha->idc_audit_ts)) / 1000);
4442 idc_audit_reg = (ha->portnum) |
4443 (IDC_AUDIT_COMPLETION << 7) | (duration_secs << 8);
4444 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
4448 ql_log(ql_log_warn, vha, 0xb078,
4449 "Invalid audit type specified.\n");
4454 /* Assumes idc_lock always held on entry */
4456 qla83xx_initiating_reset(scsi_qla_host_t *vha)
4458 struct qla_hw_data *ha = vha->hw;
4459 uint32_t idc_control, dev_state;
4461 __qla83xx_get_idc_control(vha, &idc_control);
4462 if ((idc_control & QLA83XX_IDC_RESET_DISABLED)) {
4463 ql_log(ql_log_info, vha, 0xb080,
4464 "NIC Core reset has been disabled. idc-control=0x%x\n",
4466 return QLA_FUNCTION_FAILED;
4469 /* Set NEED-RESET iff in READY state and we are the reset-owner */
4470 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
4471 if (ha->flags.nic_core_reset_owner && dev_state == QLA8XXX_DEV_READY) {
4472 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
4473 QLA8XXX_DEV_NEED_RESET);
4474 ql_log(ql_log_info, vha, 0xb056, "HW State: NEED RESET.\n");
4475 qla83xx_idc_audit(vha, IDC_AUDIT_TIMESTAMP);
4477 const char *state = qla83xx_dev_state_to_string(dev_state);
4478 ql_log(ql_log_info, vha, 0xb057, "HW State: %s.\n", state);
4480 /* SV: XXX: Is timeout required here? */
4481 /* Wait for IDC state change READY -> NEED_RESET */
4482 while (dev_state == QLA8XXX_DEV_READY) {
4483 qla83xx_idc_unlock(vha, 0);
4485 qla83xx_idc_lock(vha, 0);
4486 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
4490 /* Send IDC ack by writing to drv-ack register */
4491 __qla83xx_set_drv_ack(vha);
4497 __qla83xx_set_idc_control(scsi_qla_host_t *vha, uint32_t idc_control)
4499 return qla83xx_wr_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
4503 __qla83xx_get_idc_control(scsi_qla_host_t *vha, uint32_t *idc_control)
4505 return qla83xx_rd_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
4509 qla83xx_check_driver_presence(scsi_qla_host_t *vha)
4511 uint32_t drv_presence = 0;
4512 struct qla_hw_data *ha = vha->hw;
4514 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
4515 if (drv_presence & (1 << ha->portnum))
4518 return QLA_TEST_FAILED;
4522 qla83xx_nic_core_reset(scsi_qla_host_t *vha)
4524 int rval = QLA_SUCCESS;
4525 struct qla_hw_data *ha = vha->hw;
4527 ql_dbg(ql_dbg_p3p, vha, 0xb058,
4528 "Entered %s().\n", __func__);
4530 if (vha->device_flags & DFLG_DEV_FAILED) {
4531 ql_log(ql_log_warn, vha, 0xb059,
4532 "Device in unrecoverable FAILED state.\n");
4533 return QLA_FUNCTION_FAILED;
4536 qla83xx_idc_lock(vha, 0);
4538 if (qla83xx_check_driver_presence(vha) != QLA_SUCCESS) {
4539 ql_log(ql_log_warn, vha, 0xb05a,
4540 "Function=0x%x has been removed from IDC participation.\n",
4542 rval = QLA_FUNCTION_FAILED;
4546 qla83xx_reset_ownership(vha);
4548 rval = qla83xx_initiating_reset(vha);
4551 * Perform reset if we are the reset-owner,
4552 * else wait till IDC state changes to READY/FAILED.
4554 if (rval == QLA_SUCCESS) {
4555 rval = qla83xx_idc_state_handler(vha);
4557 if (rval == QLA_SUCCESS)
4558 ha->flags.nic_core_hung = 0;
4559 __qla83xx_clear_drv_ack(vha);
4563 qla83xx_idc_unlock(vha, 0);
4565 ql_dbg(ql_dbg_p3p, vha, 0xb05b, "Exiting %s.\n", __func__);
4571 qla2xxx_mctp_dump(scsi_qla_host_t *vha)
4573 struct qla_hw_data *ha = vha->hw;
4574 int rval = QLA_FUNCTION_FAILED;
4576 if (!IS_MCTP_CAPABLE(ha)) {
4577 /* This message can be removed from the final version */
4578 ql_log(ql_log_info, vha, 0x506d,
4579 "This board is not MCTP capable\n");
4583 if (!ha->mctp_dump) {
4584 ha->mctp_dump = dma_alloc_coherent(&ha->pdev->dev,
4585 MCTP_DUMP_SIZE, &ha->mctp_dump_dma, GFP_KERNEL);
4587 if (!ha->mctp_dump) {
4588 ql_log(ql_log_warn, vha, 0x506e,
4589 "Failed to allocate memory for mctp dump\n");
4594 #define MCTP_DUMP_STR_ADDR 0x00000000
4595 rval = qla2x00_dump_mctp_data(vha, ha->mctp_dump_dma,
4596 MCTP_DUMP_STR_ADDR, MCTP_DUMP_SIZE/4);
4597 if (rval != QLA_SUCCESS) {
4598 ql_log(ql_log_warn, vha, 0x506f,
4599 "Failed to capture mctp dump\n");
4601 ql_log(ql_log_info, vha, 0x5070,
4602 "Mctp dump capture for host (%ld/%p).\n",
4603 vha->host_no, ha->mctp_dump);
4604 ha->mctp_dumped = 1;
4607 if (!ha->flags.nic_core_reset_hdlr_active && !ha->portnum) {
4608 ha->flags.nic_core_reset_hdlr_active = 1;
4609 rval = qla83xx_restart_nic_firmware(vha);
4611 /* NIC Core reset failed. */
4612 ql_log(ql_log_warn, vha, 0x5071,
4613 "Failed to restart nic firmware\n");
4615 ql_dbg(ql_dbg_p3p, vha, 0xb084,
4616 "Restarted NIC firmware successfully.\n");
4617 ha->flags.nic_core_reset_hdlr_active = 0;
4625 * qla2x00_quiesce_io
4626 * Description: This function will block the new I/Os
4627 * Its not aborting any I/Os as context
4628 * is not destroyed during quiescence
4629 * Arguments: scsi_qla_host_t
4633 qla2x00_quiesce_io(scsi_qla_host_t *vha)
4635 struct qla_hw_data *ha = vha->hw;
4636 struct scsi_qla_host *vp;
4638 ql_dbg(ql_dbg_dpc, vha, 0x401d,
4639 "Quiescing I/O - ha=%p.\n", ha);
4641 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
4642 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
4643 atomic_set(&vha->loop_state, LOOP_DOWN);
4644 qla2x00_mark_all_devices_lost(vha, 0);
4645 list_for_each_entry(vp, &ha->vp_list, list)
4646 qla2x00_mark_all_devices_lost(vp, 0);
4648 if (!atomic_read(&vha->loop_down_timer))
4649 atomic_set(&vha->loop_down_timer,
4652 /* Wait for pending cmds to complete */
4653 qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST);
4657 qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha)
4659 struct qla_hw_data *ha = vha->hw;
4660 struct scsi_qla_host *vp;
4661 unsigned long flags;
4664 /* For ISP82XX, driver waits for completion of the commands.
4665 * online flag should be set.
4667 if (!(IS_P3P_TYPE(ha)))
4668 vha->flags.online = 0;
4669 ha->flags.chip_reset_done = 0;
4670 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
4671 vha->qla_stats.total_isp_aborts++;
4673 ql_log(ql_log_info, vha, 0x00af,
4674 "Performing ISP error recovery - ha=%p.\n", ha);
4676 /* For ISP82XX, reset_chip is just disabling interrupts.
4677 * Driver waits for the completion of the commands.
4678 * the interrupts need to be enabled.
4680 if (!(IS_P3P_TYPE(ha)))
4681 ha->isp_ops->reset_chip(vha);
4683 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
4684 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
4685 atomic_set(&vha->loop_state, LOOP_DOWN);
4686 qla2x00_mark_all_devices_lost(vha, 0);
4688 spin_lock_irqsave(&ha->vport_slock, flags);
4689 list_for_each_entry(vp, &ha->vp_list, list) {
4690 atomic_inc(&vp->vref_count);
4691 spin_unlock_irqrestore(&ha->vport_slock, flags);
4693 qla2x00_mark_all_devices_lost(vp, 0);
4695 spin_lock_irqsave(&ha->vport_slock, flags);
4696 atomic_dec(&vp->vref_count);
4698 spin_unlock_irqrestore(&ha->vport_slock, flags);
4700 if (!atomic_read(&vha->loop_down_timer))
4701 atomic_set(&vha->loop_down_timer,
4705 /* Clear all async request states across all VPs. */
4706 list_for_each_entry(fcport, &vha->vp_fcports, list)
4707 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
4708 spin_lock_irqsave(&ha->vport_slock, flags);
4709 list_for_each_entry(vp, &ha->vp_list, list) {
4710 atomic_inc(&vp->vref_count);
4711 spin_unlock_irqrestore(&ha->vport_slock, flags);
4713 list_for_each_entry(fcport, &vp->vp_fcports, list)
4714 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
4716 spin_lock_irqsave(&ha->vport_slock, flags);
4717 atomic_dec(&vp->vref_count);
4719 spin_unlock_irqrestore(&ha->vport_slock, flags);
4721 if (!ha->flags.eeh_busy) {
4722 /* Make sure for ISP 82XX IO DMA is complete */
4723 if (IS_P3P_TYPE(ha)) {
4724 qla82xx_chip_reset_cleanup(vha);
4725 ql_log(ql_log_info, vha, 0x00b4,
4726 "Done chip reset cleanup.\n");
4728 /* Done waiting for pending commands.
4729 * Reset the online flag.
4731 vha->flags.online = 0;
4734 /* Requeue all commands in outstanding command list. */
4735 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
4739 /* memory barrier */
4745 * Resets ISP and aborts all outstanding commands.
4748 * ha = adapter block pointer.
4754 qla2x00_abort_isp(scsi_qla_host_t *vha)
4758 struct qla_hw_data *ha = vha->hw;
4759 struct scsi_qla_host *vp;
4760 struct req_que *req = ha->req_q_map[0];
4761 unsigned long flags;
4763 if (vha->flags.online) {
4764 qla2x00_abort_isp_cleanup(vha);
4766 if (IS_QLA8031(ha)) {
4767 ql_dbg(ql_dbg_p3p, vha, 0xb05c,
4768 "Clearing fcoe driver presence.\n");
4769 if (qla83xx_clear_drv_presence(vha) != QLA_SUCCESS)
4770 ql_dbg(ql_dbg_p3p, vha, 0xb073,
4771 "Error while clearing DRV-Presence.\n");
4774 if (unlikely(pci_channel_offline(ha->pdev) &&
4775 ha->flags.pci_channel_io_perm_failure)) {
4776 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
4781 ha->isp_ops->get_flash_version(vha, req->ring);
4783 ha->isp_ops->nvram_config(vha);
4785 if (!qla2x00_restart_isp(vha)) {
4786 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
4788 if (!atomic_read(&vha->loop_down_timer)) {
4790 * Issue marker command only when we are going
4791 * to start the I/O .
4793 vha->marker_needed = 1;
4796 vha->flags.online = 1;
4798 ha->isp_ops->enable_intrs(ha);
4800 ha->isp_abort_cnt = 0;
4801 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
4803 if (IS_QLA81XX(ha) || IS_QLA8031(ha))
4804 qla2x00_get_fw_version(vha);
4806 ha->flags.fce_enabled = 1;
4808 fce_calc_size(ha->fce_bufs));
4809 rval = qla2x00_enable_fce_trace(vha,
4810 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
4813 ql_log(ql_log_warn, vha, 0x8033,
4814 "Unable to reinitialize FCE "
4816 ha->flags.fce_enabled = 0;
4821 memset(ha->eft, 0, EFT_SIZE);
4822 rval = qla2x00_enable_eft_trace(vha,
4823 ha->eft_dma, EFT_NUM_BUFFERS);
4825 ql_log(ql_log_warn, vha, 0x8034,
4826 "Unable to reinitialize EFT "
4830 } else { /* failed the ISP abort */
4831 vha->flags.online = 1;
4832 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
4833 if (ha->isp_abort_cnt == 0) {
4834 ql_log(ql_log_fatal, vha, 0x8035,
4835 "ISP error recover failed - "
4836 "board disabled.\n");
4838 * The next call disables the board
4841 ha->isp_ops->reset_adapter(vha);
4842 vha->flags.online = 0;
4843 clear_bit(ISP_ABORT_RETRY,
4846 } else { /* schedule another ISP abort */
4847 ha->isp_abort_cnt--;
4848 ql_dbg(ql_dbg_taskm, vha, 0x8020,
4849 "ISP abort - retry remaining %d.\n",
4854 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
4855 ql_dbg(ql_dbg_taskm, vha, 0x8021,
4856 "ISP error recovery - retrying (%d) "
4857 "more times.\n", ha->isp_abort_cnt);
4858 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
4866 ql_dbg(ql_dbg_taskm, vha, 0x8022, "%s succeeded.\n", __func__);
4868 spin_lock_irqsave(&ha->vport_slock, flags);
4869 list_for_each_entry(vp, &ha->vp_list, list) {
4871 atomic_inc(&vp->vref_count);
4872 spin_unlock_irqrestore(&ha->vport_slock, flags);
4874 qla2x00_vp_abort_isp(vp);
4876 spin_lock_irqsave(&ha->vport_slock, flags);
4877 atomic_dec(&vp->vref_count);
4880 spin_unlock_irqrestore(&ha->vport_slock, flags);
4882 if (IS_QLA8031(ha)) {
4883 ql_dbg(ql_dbg_p3p, vha, 0xb05d,
4884 "Setting back fcoe driver presence.\n");
4885 if (qla83xx_set_drv_presence(vha) != QLA_SUCCESS)
4886 ql_dbg(ql_dbg_p3p, vha, 0xb074,
4887 "Error while setting DRV-Presence.\n");
4890 ql_log(ql_log_warn, vha, 0x8023, "%s **** FAILED ****.\n",
4898 * qla2x00_restart_isp
4899 * restarts the ISP after a reset
4902 * ha = adapter block pointer.
4908 qla2x00_restart_isp(scsi_qla_host_t *vha)
4911 struct qla_hw_data *ha = vha->hw;
4912 struct req_que *req = ha->req_q_map[0];
4913 struct rsp_que *rsp = ha->rsp_q_map[0];
4914 unsigned long flags;
4916 /* If firmware needs to be loaded */
4917 if (qla2x00_isp_firmware(vha)) {
4918 vha->flags.online = 0;
4919 status = ha->isp_ops->chip_diag(vha);
4921 status = qla2x00_setup_chip(vha);
4924 if (!status && !(status = qla2x00_init_rings(vha))) {
4925 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
4926 ha->flags.chip_reset_done = 1;
4928 /* Initialize the queues in use */
4929 qla25xx_init_queues(ha);
4931 status = qla2x00_fw_ready(vha);
4933 /* Issue a marker after FW becomes ready. */
4934 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
4936 vha->flags.online = 1;
4939 * Process any ATIO queue entries that came in
4940 * while we weren't online.
4942 spin_lock_irqsave(&ha->hardware_lock, flags);
4943 if (qla_tgt_mode_enabled(vha))
4944 qlt_24xx_process_atio_queue(vha);
4945 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4947 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4950 /* if no cable then assume it's good */
4951 if ((vha->device_flags & DFLG_NO_CABLE))
4958 qla25xx_init_queues(struct qla_hw_data *ha)
4960 struct rsp_que *rsp = NULL;
4961 struct req_que *req = NULL;
4962 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
4966 for (i = 1; i < ha->max_rsp_queues; i++) {
4967 rsp = ha->rsp_q_map[i];
4969 rsp->options &= ~BIT_0;
4970 ret = qla25xx_init_rsp_que(base_vha, rsp);
4971 if (ret != QLA_SUCCESS)
4972 ql_dbg(ql_dbg_init, base_vha, 0x00ff,
4973 "%s Rsp que: %d init failed.\n",
4976 ql_dbg(ql_dbg_init, base_vha, 0x0100,
4977 "%s Rsp que: %d inited.\n",
4981 for (i = 1; i < ha->max_req_queues; i++) {
4982 req = ha->req_q_map[i];
4984 /* Clear outstanding commands array. */
4985 req->options &= ~BIT_0;
4986 ret = qla25xx_init_req_que(base_vha, req);
4987 if (ret != QLA_SUCCESS)
4988 ql_dbg(ql_dbg_init, base_vha, 0x0101,
4989 "%s Req que: %d init failed.\n",
4992 ql_dbg(ql_dbg_init, base_vha, 0x0102,
4993 "%s Req que: %d inited.\n",
5001 * qla2x00_reset_adapter
5005 * ha = adapter block pointer.
5008 qla2x00_reset_adapter(scsi_qla_host_t *vha)
5010 unsigned long flags = 0;
5011 struct qla_hw_data *ha = vha->hw;
5012 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
5014 vha->flags.online = 0;
5015 ha->isp_ops->disable_intrs(ha);
5017 spin_lock_irqsave(&ha->hardware_lock, flags);
5018 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
5019 RD_REG_WORD(®->hccr); /* PCI Posting. */
5020 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
5021 RD_REG_WORD(®->hccr); /* PCI Posting. */
5022 spin_unlock_irqrestore(&ha->hardware_lock, flags);
5026 qla24xx_reset_adapter(scsi_qla_host_t *vha)
5028 unsigned long flags = 0;
5029 struct qla_hw_data *ha = vha->hw;
5030 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
5032 if (IS_P3P_TYPE(ha))
5035 vha->flags.online = 0;
5036 ha->isp_ops->disable_intrs(ha);
5038 spin_lock_irqsave(&ha->hardware_lock, flags);
5039 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
5040 RD_REG_DWORD(®->hccr);
5041 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
5042 RD_REG_DWORD(®->hccr);
5043 spin_unlock_irqrestore(&ha->hardware_lock, flags);
5045 if (IS_NOPOLLING_TYPE(ha))
5046 ha->isp_ops->enable_intrs(ha);
5049 /* On sparc systems, obtain port and node WWN from firmware
5052 static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
5053 struct nvram_24xx *nv)
5056 struct qla_hw_data *ha = vha->hw;
5057 struct pci_dev *pdev = ha->pdev;
5058 struct device_node *dp = pci_device_to_OF_node(pdev);
5062 val = of_get_property(dp, "port-wwn", &len);
5063 if (val && len >= WWN_SIZE)
5064 memcpy(nv->port_name, val, WWN_SIZE);
5066 val = of_get_property(dp, "node-wwn", &len);
5067 if (val && len >= WWN_SIZE)
5068 memcpy(nv->node_name, val, WWN_SIZE);
5073 qla24xx_nvram_config(scsi_qla_host_t *vha)
5076 struct init_cb_24xx *icb;
5077 struct nvram_24xx *nv;
5079 uint8_t *dptr1, *dptr2;
5082 struct qla_hw_data *ha = vha->hw;
5085 icb = (struct init_cb_24xx *)ha->init_cb;
5088 /* Determine NVRAM starting address. */
5089 if (ha->port_no == 0) {
5090 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
5091 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
5093 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
5094 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
5097 ha->nvram_size = sizeof(struct nvram_24xx);
5098 ha->vpd_size = FA_NVRAM_VPD_SIZE;
5100 /* Get VPD data into cache */
5101 ha->vpd = ha->nvram + VPD_OFFSET;
5102 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
5103 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
5105 /* Get NVRAM data into cache and calculate checksum. */
5106 dptr = (uint32_t *)nv;
5107 ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
5109 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
5110 chksum += le32_to_cpu(*dptr++);
5112 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x006a,
5113 "Contents of NVRAM\n");
5114 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x010d,
5115 (uint8_t *)nv, ha->nvram_size);
5117 /* Bad NVRAM data, set defaults parameters. */
5118 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
5119 || nv->id[3] != ' ' ||
5120 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
5121 /* Reset NVRAM data. */
5122 ql_log(ql_log_warn, vha, 0x006b,
5123 "Inconsistent NVRAM detected: checksum=0x%x id=%c "
5124 "version=0x%x.\n", chksum, nv->id[0], nv->nvram_version);
5125 ql_log(ql_log_warn, vha, 0x006c,
5126 "Falling back to functioning (yet invalid -- WWPN) "
5130 * Set default initialization control block.
5132 memset(nv, 0, ha->nvram_size);
5133 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
5134 nv->version = __constant_cpu_to_le16(ICB_VERSION);
5135 nv->frame_payload_size = 2048;
5136 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
5137 nv->exchange_count = __constant_cpu_to_le16(0);
5138 nv->hard_address = __constant_cpu_to_le16(124);
5139 nv->port_name[0] = 0x21;
5140 nv->port_name[1] = 0x00 + ha->port_no + 1;
5141 nv->port_name[2] = 0x00;
5142 nv->port_name[3] = 0xe0;
5143 nv->port_name[4] = 0x8b;
5144 nv->port_name[5] = 0x1c;
5145 nv->port_name[6] = 0x55;
5146 nv->port_name[7] = 0x86;
5147 nv->node_name[0] = 0x20;
5148 nv->node_name[1] = 0x00;
5149 nv->node_name[2] = 0x00;
5150 nv->node_name[3] = 0xe0;
5151 nv->node_name[4] = 0x8b;
5152 nv->node_name[5] = 0x1c;
5153 nv->node_name[6] = 0x55;
5154 nv->node_name[7] = 0x86;
5155 qla24xx_nvram_wwn_from_ofw(vha, nv);
5156 nv->login_retry_count = __constant_cpu_to_le16(8);
5157 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
5158 nv->login_timeout = __constant_cpu_to_le16(0);
5159 nv->firmware_options_1 =
5160 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
5161 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
5162 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
5163 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
5164 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
5165 nv->efi_parameters = __constant_cpu_to_le32(0);
5166 nv->reset_delay = 5;
5167 nv->max_luns_per_target = __constant_cpu_to_le16(128);
5168 nv->port_down_retry_count = __constant_cpu_to_le16(30);
5169 nv->link_down_timeout = __constant_cpu_to_le16(30);
5174 if (!qla_ini_mode_enabled(vha)) {
5175 /* Don't enable full login after initial LIP */
5176 nv->firmware_options_1 &= __constant_cpu_to_le32(~BIT_13);
5177 /* Don't enable LIP full login for initiator */
5178 nv->host_p &= __constant_cpu_to_le32(~BIT_10);
5181 qlt_24xx_config_nvram_stage1(vha, nv);
5183 /* Reset Initialization control block */
5184 memset(icb, 0, ha->init_cb_size);
5186 /* Copy 1st segment. */
5187 dptr1 = (uint8_t *)icb;
5188 dptr2 = (uint8_t *)&nv->version;
5189 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
5191 *dptr1++ = *dptr2++;
5193 icb->login_retry_count = nv->login_retry_count;
5194 icb->link_down_on_nos = nv->link_down_on_nos;
5196 /* Copy 2nd segment. */
5197 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
5198 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
5199 cnt = (uint8_t *)&icb->reserved_3 -
5200 (uint8_t *)&icb->interrupt_delay_timer;
5202 *dptr1++ = *dptr2++;
5205 * Setup driver NVRAM options.
5207 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
5210 qlt_24xx_config_nvram_stage2(vha, icb);
5212 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
5213 /* Use alternate WWN? */
5214 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
5215 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
5218 /* Prepare nodename */
5219 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
5221 * Firmware will apply the following mask if the nodename was
5224 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
5225 icb->node_name[0] &= 0xF0;
5228 /* Set host adapter parameters. */
5229 ha->flags.disable_risc_code_load = 0;
5230 ha->flags.enable_lip_reset = 0;
5231 ha->flags.enable_lip_full_login =
5232 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
5233 ha->flags.enable_target_reset =
5234 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
5235 ha->flags.enable_led_scheme = 0;
5236 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
5238 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
5239 (BIT_6 | BIT_5 | BIT_4)) >> 4;
5241 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
5242 sizeof(ha->fw_seriallink_options24));
5244 /* save HBA serial number */
5245 ha->serial0 = icb->port_name[5];
5246 ha->serial1 = icb->port_name[6];
5247 ha->serial2 = icb->port_name[7];
5248 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
5249 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
5251 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
5253 ha->retry_count = le16_to_cpu(nv->login_retry_count);
5255 /* Set minimum login_timeout to 4 seconds. */
5256 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
5257 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
5258 if (le16_to_cpu(nv->login_timeout) < 4)
5259 nv->login_timeout = __constant_cpu_to_le16(4);
5260 ha->login_timeout = le16_to_cpu(nv->login_timeout);
5261 icb->login_timeout = nv->login_timeout;
5263 /* Set minimum RATOV to 100 tenths of a second. */
5266 ha->loop_reset_delay = nv->reset_delay;
5268 /* Link Down Timeout = 0:
5270 * When Port Down timer expires we will start returning
5271 * I/O's to OS with "DID_NO_CONNECT".
5273 * Link Down Timeout != 0:
5275 * The driver waits for the link to come up after link down
5276 * before returning I/Os to OS with "DID_NO_CONNECT".
5278 if (le16_to_cpu(nv->link_down_timeout) == 0) {
5279 ha->loop_down_abort_time =
5280 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
5282 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
5283 ha->loop_down_abort_time =
5284 (LOOP_DOWN_TIME - ha->link_down_timeout);
5287 /* Need enough time to try and get the port back. */
5288 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
5289 if (qlport_down_retry)
5290 ha->port_down_retry_count = qlport_down_retry;
5292 /* Set login_retry_count */
5293 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
5294 if (ha->port_down_retry_count ==
5295 le16_to_cpu(nv->port_down_retry_count) &&
5296 ha->port_down_retry_count > 3)
5297 ha->login_retry_count = ha->port_down_retry_count;
5298 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
5299 ha->login_retry_count = ha->port_down_retry_count;
5300 if (ql2xloginretrycount)
5301 ha->login_retry_count = ql2xloginretrycount;
5304 if (!vha->flags.init_done) {
5305 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
5306 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
5307 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
5308 le16_to_cpu(icb->interrupt_delay_timer): 2;
5310 icb->firmware_options_2 &= __constant_cpu_to_le32(
5311 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
5312 vha->flags.process_response_queue = 0;
5313 if (ha->zio_mode != QLA_ZIO_DISABLED) {
5314 ha->zio_mode = QLA_ZIO_MODE_6;
5316 ql_log(ql_log_info, vha, 0x006f,
5317 "ZIO mode %d enabled; timer delay (%d us).\n",
5318 ha->zio_mode, ha->zio_timer * 100);
5320 icb->firmware_options_2 |= cpu_to_le32(
5321 (uint32_t)ha->zio_mode);
5322 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
5323 vha->flags.process_response_queue = 1;
5327 ql_log(ql_log_warn, vha, 0x0070,
5328 "NVRAM configuration failed.\n");
5334 qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
5337 int rval = QLA_SUCCESS;
5338 int segments, fragment;
5339 uint32_t *dcode, dlen;
5343 struct qla_hw_data *ha = vha->hw;
5344 struct req_que *req = ha->req_q_map[0];
5346 ql_dbg(ql_dbg_init, vha, 0x008b,
5347 "FW: Loading firmware from flash (%x).\n", faddr);
5351 segments = FA_RISC_CODE_SEGMENTS;
5352 dcode = (uint32_t *)req->ring;
5355 /* Validate firmware image by checking version. */
5356 qla24xx_read_flash_data(vha, dcode, faddr + 4, 4);
5357 for (i = 0; i < 4; i++)
5358 dcode[i] = be32_to_cpu(dcode[i]);
5359 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
5360 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
5361 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
5363 ql_log(ql_log_fatal, vha, 0x008c,
5364 "Unable to verify the integrity of flash firmware "
5366 ql_log(ql_log_fatal, vha, 0x008d,
5367 "Firmware data: %08x %08x %08x %08x.\n",
5368 dcode[0], dcode[1], dcode[2], dcode[3]);
5370 return QLA_FUNCTION_FAILED;
5373 while (segments && rval == QLA_SUCCESS) {
5374 /* Read segment's load information. */
5375 qla24xx_read_flash_data(vha, dcode, faddr, 4);
5377 risc_addr = be32_to_cpu(dcode[2]);
5378 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
5379 risc_size = be32_to_cpu(dcode[3]);
5382 while (risc_size > 0 && rval == QLA_SUCCESS) {
5383 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
5384 if (dlen > risc_size)
5387 ql_dbg(ql_dbg_init, vha, 0x008e,
5388 "Loading risc segment@ risc addr %x "
5389 "number of dwords 0x%x offset 0x%x.\n",
5390 risc_addr, dlen, faddr);
5392 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
5393 for (i = 0; i < dlen; i++)
5394 dcode[i] = swab32(dcode[i]);
5396 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
5399 ql_log(ql_log_fatal, vha, 0x008f,
5400 "Failed to load segment %d of firmware.\n",
5402 return QLA_FUNCTION_FAILED;
5415 if (!IS_QLA27XX(ha))
5418 if (ha->fw_dump_template)
5419 vfree(ha->fw_dump_template);
5420 ha->fw_dump_template = NULL;
5421 ha->fw_dump_template_len = 0;
5423 ql_dbg(ql_dbg_init, vha, 0x0161,
5424 "Loading fwdump template from %x\n", faddr);
5425 qla24xx_read_flash_data(vha, dcode, faddr, 7);
5426 risc_size = be32_to_cpu(dcode[2]);
5427 ql_dbg(ql_dbg_init, vha, 0x0162,
5428 "-> array size %x dwords\n", risc_size);
5429 if (risc_size == 0 || risc_size == ~0)
5430 goto default_template;
5432 dlen = (risc_size - 8) * sizeof(*dcode);
5433 ql_dbg(ql_dbg_init, vha, 0x0163,
5434 "-> template allocating %x bytes...\n", dlen);
5435 ha->fw_dump_template = vmalloc(dlen);
5436 if (!ha->fw_dump_template) {
5437 ql_log(ql_log_warn, vha, 0x0164,
5438 "Failed fwdump template allocate %x bytes.\n", risc_size);
5439 goto default_template;
5444 dcode = ha->fw_dump_template;
5445 qla24xx_read_flash_data(vha, dcode, faddr, risc_size);
5446 for (i = 0; i < risc_size; i++)
5447 dcode[i] = le32_to_cpu(dcode[i]);
5449 if (!qla27xx_fwdt_template_valid(dcode)) {
5450 ql_log(ql_log_warn, vha, 0x0165,
5451 "Failed fwdump template validate\n");
5452 goto default_template;
5455 dlen = qla27xx_fwdt_template_size(dcode);
5456 ql_dbg(ql_dbg_init, vha, 0x0166,
5457 "-> template size %x bytes\n", dlen);
5458 if (dlen > risc_size * sizeof(*dcode)) {
5459 ql_log(ql_log_warn, vha, 0x0167,
5460 "Failed fwdump template exceeds array by %x bytes\n",
5461 (uint32_t)(dlen - risc_size * sizeof(*dcode)));
5462 goto default_template;
5464 ha->fw_dump_template_len = dlen;
5468 ql_log(ql_log_warn, vha, 0x0168, "Using default fwdump template\n");
5469 if (ha->fw_dump_template)
5470 vfree(ha->fw_dump_template);
5471 ha->fw_dump_template = NULL;
5472 ha->fw_dump_template_len = 0;
5474 dlen = qla27xx_fwdt_template_default_size();
5475 ql_dbg(ql_dbg_init, vha, 0x0169,
5476 "-> template allocating %x bytes...\n", dlen);
5477 ha->fw_dump_template = vmalloc(dlen);
5478 if (!ha->fw_dump_template) {
5479 ql_log(ql_log_warn, vha, 0x016a,
5480 "Failed fwdump template allocate %x bytes.\n", risc_size);
5481 goto failed_template;
5484 dcode = ha->fw_dump_template;
5485 risc_size = dlen / sizeof(*dcode);
5486 memcpy(dcode, qla27xx_fwdt_template_default(), dlen);
5487 for (i = 0; i < risc_size; i++)
5488 dcode[i] = be32_to_cpu(dcode[i]);
5490 if (!qla27xx_fwdt_template_valid(ha->fw_dump_template)) {
5491 ql_log(ql_log_warn, vha, 0x016b,
5492 "Failed fwdump template validate\n");
5493 goto failed_template;
5496 dlen = qla27xx_fwdt_template_size(ha->fw_dump_template);
5497 ql_dbg(ql_dbg_init, vha, 0x016c,
5498 "-> template size %x bytes\n", dlen);
5499 ha->fw_dump_template_len = dlen;
5503 ql_log(ql_log_warn, vha, 0x016d, "Failed default fwdump template\n");
5504 if (ha->fw_dump_template)
5505 vfree(ha->fw_dump_template);
5506 ha->fw_dump_template = NULL;
5507 ha->fw_dump_template_len = 0;
5511 #define QLA_FW_URL "http://ldriver.qlogic.com/firmware/"
5514 qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
5518 uint16_t *wcode, *fwcode;
5519 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
5520 struct fw_blob *blob;
5521 struct qla_hw_data *ha = vha->hw;
5522 struct req_que *req = ha->req_q_map[0];
5524 /* Load firmware blob. */
5525 blob = qla2x00_request_firmware(vha);
5527 ql_log(ql_log_info, vha, 0x0083,
5528 "Firmware image unavailable.\n");
5529 ql_log(ql_log_info, vha, 0x0084,
5530 "Firmware images can be retrieved from: "QLA_FW_URL ".\n");
5531 return QLA_FUNCTION_FAILED;
5536 wcode = (uint16_t *)req->ring;
5538 fwcode = (uint16_t *)blob->fw->data;
5541 /* Validate firmware image by checking version. */
5542 if (blob->fw->size < 8 * sizeof(uint16_t)) {
5543 ql_log(ql_log_fatal, vha, 0x0085,
5544 "Unable to verify integrity of firmware image (%Zd).\n",
5546 goto fail_fw_integrity;
5548 for (i = 0; i < 4; i++)
5549 wcode[i] = be16_to_cpu(fwcode[i + 4]);
5550 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
5551 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
5552 wcode[2] == 0 && wcode[3] == 0)) {
5553 ql_log(ql_log_fatal, vha, 0x0086,
5554 "Unable to verify integrity of firmware image.\n");
5555 ql_log(ql_log_fatal, vha, 0x0087,
5556 "Firmware data: %04x %04x %04x %04x.\n",
5557 wcode[0], wcode[1], wcode[2], wcode[3]);
5558 goto fail_fw_integrity;
5562 while (*seg && rval == QLA_SUCCESS) {
5564 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
5565 risc_size = be16_to_cpu(fwcode[3]);
5567 /* Validate firmware image size. */
5568 fwclen += risc_size * sizeof(uint16_t);
5569 if (blob->fw->size < fwclen) {
5570 ql_log(ql_log_fatal, vha, 0x0088,
5571 "Unable to verify integrity of firmware image "
5572 "(%Zd).\n", blob->fw->size);
5573 goto fail_fw_integrity;
5577 while (risc_size > 0 && rval == QLA_SUCCESS) {
5578 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
5579 if (wlen > risc_size)
5581 ql_dbg(ql_dbg_init, vha, 0x0089,
5582 "Loading risc segment@ risc addr %x number of "
5583 "words 0x%x.\n", risc_addr, wlen);
5585 for (i = 0; i < wlen; i++)
5586 wcode[i] = swab16(fwcode[i]);
5588 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
5591 ql_log(ql_log_fatal, vha, 0x008a,
5592 "Failed to load segment %d of firmware.\n",
5609 return QLA_FUNCTION_FAILED;
5613 qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
5616 int segments, fragment;
5617 uint32_t *dcode, dlen;
5621 struct fw_blob *blob;
5622 const uint32_t *fwcode;
5624 struct qla_hw_data *ha = vha->hw;
5625 struct req_que *req = ha->req_q_map[0];
5627 /* Load firmware blob. */
5628 blob = qla2x00_request_firmware(vha);
5630 ql_log(ql_log_warn, vha, 0x0090,
5631 "Firmware image unavailable.\n");
5632 ql_log(ql_log_warn, vha, 0x0091,
5633 "Firmware images can be retrieved from: "
5636 return QLA_FUNCTION_FAILED;
5639 ql_dbg(ql_dbg_init, vha, 0x0092,
5640 "FW: Loading via request-firmware.\n");
5644 segments = FA_RISC_CODE_SEGMENTS;
5645 dcode = (uint32_t *)req->ring;
5647 fwcode = (uint32_t *)blob->fw->data;
5650 /* Validate firmware image by checking version. */
5651 if (blob->fw->size < 8 * sizeof(uint32_t)) {
5652 ql_log(ql_log_fatal, vha, 0x0093,
5653 "Unable to verify integrity of firmware image (%Zd).\n",
5655 return QLA_FUNCTION_FAILED;
5657 for (i = 0; i < 4; i++)
5658 dcode[i] = be32_to_cpu(fwcode[i + 4]);
5659 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
5660 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
5661 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
5663 ql_log(ql_log_fatal, vha, 0x0094,
5664 "Unable to verify integrity of firmware image (%Zd).\n",
5666 ql_log(ql_log_fatal, vha, 0x0095,
5667 "Firmware data: %08x %08x %08x %08x.\n",
5668 dcode[0], dcode[1], dcode[2], dcode[3]);
5669 return QLA_FUNCTION_FAILED;
5672 while (segments && rval == QLA_SUCCESS) {
5673 risc_addr = be32_to_cpu(fwcode[2]);
5674 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
5675 risc_size = be32_to_cpu(fwcode[3]);
5677 /* Validate firmware image size. */
5678 fwclen += risc_size * sizeof(uint32_t);
5679 if (blob->fw->size < fwclen) {
5680 ql_log(ql_log_fatal, vha, 0x0096,
5681 "Unable to verify integrity of firmware image "
5682 "(%Zd).\n", blob->fw->size);
5683 return QLA_FUNCTION_FAILED;
5687 while (risc_size > 0 && rval == QLA_SUCCESS) {
5688 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
5689 if (dlen > risc_size)
5692 ql_dbg(ql_dbg_init, vha, 0x0097,
5693 "Loading risc segment@ risc addr %x "
5694 "number of dwords 0x%x.\n", risc_addr, dlen);
5696 for (i = 0; i < dlen; i++)
5697 dcode[i] = swab32(fwcode[i]);
5699 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
5702 ql_log(ql_log_fatal, vha, 0x0098,
5703 "Failed to load segment %d of firmware.\n",
5705 return QLA_FUNCTION_FAILED;
5718 if (!IS_QLA27XX(ha))
5721 if (ha->fw_dump_template)
5722 vfree(ha->fw_dump_template);
5723 ha->fw_dump_template = NULL;
5724 ha->fw_dump_template_len = 0;
5726 ql_dbg(ql_dbg_init, vha, 0x171,
5727 "Loading fwdump template from %x\n",
5728 (uint32_t)((void *)fwcode - (void *)blob->fw->data));
5729 risc_size = be32_to_cpu(fwcode[2]);
5730 ql_dbg(ql_dbg_init, vha, 0x172,
5731 "-> array size %x dwords\n", risc_size);
5732 if (risc_size == 0 || risc_size == ~0)
5733 goto default_template;
5735 dlen = (risc_size - 8) * sizeof(*fwcode);
5736 ql_dbg(ql_dbg_init, vha, 0x0173,
5737 "-> template allocating %x bytes...\n", dlen);
5738 ha->fw_dump_template = vmalloc(dlen);
5739 if (!ha->fw_dump_template) {
5740 ql_log(ql_log_warn, vha, 0x0174,
5741 "Failed fwdump template allocate %x bytes.\n", risc_size);
5742 goto default_template;
5747 dcode = ha->fw_dump_template;
5748 for (i = 0; i < risc_size; i++)
5749 dcode[i] = le32_to_cpu(fwcode[i]);
5751 if (!qla27xx_fwdt_template_valid(dcode)) {
5752 ql_log(ql_log_warn, vha, 0x0175,
5753 "Failed fwdump template validate\n");
5754 goto default_template;
5757 dlen = qla27xx_fwdt_template_size(dcode);
5758 ql_dbg(ql_dbg_init, vha, 0x0176,
5759 "-> template size %x bytes\n", dlen);
5760 if (dlen > risc_size * sizeof(*fwcode)) {
5761 ql_log(ql_log_warn, vha, 0x0177,
5762 "Failed fwdump template exceeds array by %x bytes\n",
5763 (uint32_t)(dlen - risc_size * sizeof(*fwcode)));
5764 goto default_template;
5766 ha->fw_dump_template_len = dlen;
5770 ql_log(ql_log_warn, vha, 0x0178, "Using default fwdump template\n");
5771 if (ha->fw_dump_template)
5772 vfree(ha->fw_dump_template);
5773 ha->fw_dump_template = NULL;
5774 ha->fw_dump_template_len = 0;
5776 dlen = qla27xx_fwdt_template_default_size();
5777 ql_dbg(ql_dbg_init, vha, 0x0179,
5778 "-> template allocating %x bytes...\n", dlen);
5779 ha->fw_dump_template = vmalloc(dlen);
5780 if (!ha->fw_dump_template) {
5781 ql_log(ql_log_warn, vha, 0x017a,
5782 "Failed fwdump template allocate %x bytes.\n", risc_size);
5783 goto failed_template;
5786 dcode = ha->fw_dump_template;
5787 risc_size = dlen / sizeof(*fwcode);
5788 fwcode = qla27xx_fwdt_template_default();
5789 for (i = 0; i < risc_size; i++)
5790 dcode[i] = be32_to_cpu(fwcode[i]);
5792 if (!qla27xx_fwdt_template_valid(ha->fw_dump_template)) {
5793 ql_log(ql_log_warn, vha, 0x017b,
5794 "Failed fwdump template validate\n");
5795 goto failed_template;
5798 dlen = qla27xx_fwdt_template_size(ha->fw_dump_template);
5799 ql_dbg(ql_dbg_init, vha, 0x017c,
5800 "-> template size %x bytes\n", dlen);
5801 ha->fw_dump_template_len = dlen;
5805 ql_log(ql_log_warn, vha, 0x017d, "Failed default fwdump template\n");
5806 if (ha->fw_dump_template)
5807 vfree(ha->fw_dump_template);
5808 ha->fw_dump_template = NULL;
5809 ha->fw_dump_template_len = 0;
5814 qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
5818 if (ql2xfwloadbin == 1)
5819 return qla81xx_load_risc(vha, srisc_addr);
5823 * 1) Firmware via request-firmware interface (.bin file).
5824 * 2) Firmware residing in flash.
5826 rval = qla24xx_load_risc_blob(vha, srisc_addr);
5827 if (rval == QLA_SUCCESS)
5830 return qla24xx_load_risc_flash(vha, srisc_addr,
5831 vha->hw->flt_region_fw);
5835 qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
5838 struct qla_hw_data *ha = vha->hw;
5840 if (ql2xfwloadbin == 2)
5845 * 1) Firmware residing in flash.
5846 * 2) Firmware via request-firmware interface (.bin file).
5847 * 3) Golden-Firmware residing in flash -- limited operation.
5849 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
5850 if (rval == QLA_SUCCESS)
5854 rval = qla24xx_load_risc_blob(vha, srisc_addr);
5855 if (rval == QLA_SUCCESS || !ha->flt_region_gold_fw)
5858 ql_log(ql_log_info, vha, 0x0099,
5859 "Attempting to fallback to golden firmware.\n");
5860 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
5861 if (rval != QLA_SUCCESS)
5864 ql_log(ql_log_info, vha, 0x009a, "Update operational firmware.\n");
5865 ha->flags.running_gold_fw = 1;
5870 qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
5873 struct qla_hw_data *ha = vha->hw;
5875 if (ha->flags.pci_channel_io_perm_failure)
5877 if (!IS_FWI2_CAPABLE(ha))
5879 if (!ha->fw_major_version)
5882 ret = qla2x00_stop_firmware(vha);
5883 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
5884 ret != QLA_INVALID_COMMAND && retries ; retries--) {
5885 ha->isp_ops->reset_chip(vha);
5886 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
5888 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
5890 ql_log(ql_log_info, vha, 0x8015,
5891 "Attempting retry of stop-firmware command.\n");
5892 ret = qla2x00_stop_firmware(vha);
5897 qla24xx_configure_vhba(scsi_qla_host_t *vha)
5899 int rval = QLA_SUCCESS;
5901 uint16_t mb[MAILBOX_REGISTER_COUNT];
5902 struct qla_hw_data *ha = vha->hw;
5903 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
5904 struct req_que *req;
5905 struct rsp_que *rsp;
5910 rval = qla2x00_fw_ready(base_vha);
5911 if (ha->flags.cpu_affinity_enabled)
5912 req = ha->req_q_map[0];
5917 if (rval == QLA_SUCCESS) {
5918 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
5919 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
5922 vha->flags.management_server_logged_in = 0;
5924 /* Login to SNS first */
5925 rval2 = ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb,
5927 if (rval2 != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
5928 if (rval2 == QLA_MEMORY_ALLOC_FAILED)
5929 ql_dbg(ql_dbg_init, vha, 0x0120,
5930 "Failed SNS login: loop_id=%x, rval2=%d\n",
5933 ql_dbg(ql_dbg_init, vha, 0x0103,
5934 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
5935 "mb[2]=%x mb[6]=%x mb[7]=%x.\n",
5936 NPH_SNS, mb[0], mb[1], mb[2], mb[6], mb[7]);
5937 return (QLA_FUNCTION_FAILED);
5940 atomic_set(&vha->loop_down_timer, 0);
5941 atomic_set(&vha->loop_state, LOOP_UP);
5942 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5943 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5944 rval = qla2x00_loop_resync(base_vha);
5949 /* 84XX Support **************************************************************/
5951 static LIST_HEAD(qla_cs84xx_list);
5952 static DEFINE_MUTEX(qla_cs84xx_mutex);
5954 static struct qla_chip_state_84xx *
5955 qla84xx_get_chip(struct scsi_qla_host *vha)
5957 struct qla_chip_state_84xx *cs84xx;
5958 struct qla_hw_data *ha = vha->hw;
5960 mutex_lock(&qla_cs84xx_mutex);
5962 /* Find any shared 84xx chip. */
5963 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
5964 if (cs84xx->bus == ha->pdev->bus) {
5965 kref_get(&cs84xx->kref);
5970 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
5974 kref_init(&cs84xx->kref);
5975 spin_lock_init(&cs84xx->access_lock);
5976 mutex_init(&cs84xx->fw_update_mutex);
5977 cs84xx->bus = ha->pdev->bus;
5979 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
5981 mutex_unlock(&qla_cs84xx_mutex);
5986 __qla84xx_chip_release(struct kref *kref)
5988 struct qla_chip_state_84xx *cs84xx =
5989 container_of(kref, struct qla_chip_state_84xx, kref);
5991 mutex_lock(&qla_cs84xx_mutex);
5992 list_del(&cs84xx->list);
5993 mutex_unlock(&qla_cs84xx_mutex);
5998 qla84xx_put_chip(struct scsi_qla_host *vha)
6000 struct qla_hw_data *ha = vha->hw;
6002 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
6006 qla84xx_init_chip(scsi_qla_host_t *vha)
6010 struct qla_hw_data *ha = vha->hw;
6012 mutex_lock(&ha->cs84xx->fw_update_mutex);
6014 rval = qla84xx_verify_chip(vha, status);
6016 mutex_unlock(&ha->cs84xx->fw_update_mutex);
6018 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED:
6022 /* 81XX Support **************************************************************/
6025 qla81xx_nvram_config(scsi_qla_host_t *vha)
6028 struct init_cb_81xx *icb;
6029 struct nvram_81xx *nv;
6031 uint8_t *dptr1, *dptr2;
6034 struct qla_hw_data *ha = vha->hw;
6037 icb = (struct init_cb_81xx *)ha->init_cb;
6040 /* Determine NVRAM starting address. */
6041 ha->nvram_size = sizeof(struct nvram_81xx);
6042 ha->vpd_size = FA_NVRAM_VPD_SIZE;
6043 if (IS_P3P_TYPE(ha) || IS_QLA8031(ha))
6044 ha->vpd_size = FA_VPD_SIZE_82XX;
6046 /* Get VPD data into cache */
6047 ha->vpd = ha->nvram + VPD_OFFSET;
6048 ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
6051 /* Get NVRAM data into cache and calculate checksum. */
6052 ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
6054 dptr = (uint32_t *)nv;
6055 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
6056 chksum += le32_to_cpu(*dptr++);
6058 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0111,
6059 "Contents of NVRAM:\n");
6060 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0112,
6061 (uint8_t *)nv, ha->nvram_size);
6063 /* Bad NVRAM data, set defaults parameters. */
6064 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
6065 || nv->id[3] != ' ' ||
6066 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
6067 /* Reset NVRAM data. */
6068 ql_log(ql_log_info, vha, 0x0073,
6069 "Inconsistent NVRAM detected: checksum=0x%x id=%c "
6070 "version=0x%x.\n", chksum, nv->id[0],
6071 le16_to_cpu(nv->nvram_version));
6072 ql_log(ql_log_info, vha, 0x0074,
6073 "Falling back to functioning (yet invalid -- WWPN) "
6077 * Set default initialization control block.
6079 memset(nv, 0, ha->nvram_size);
6080 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
6081 nv->version = __constant_cpu_to_le16(ICB_VERSION);
6082 nv->frame_payload_size = 2048;
6083 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
6084 nv->exchange_count = __constant_cpu_to_le16(0);
6085 nv->port_name[0] = 0x21;
6086 nv->port_name[1] = 0x00 + ha->port_no + 1;
6087 nv->port_name[2] = 0x00;
6088 nv->port_name[3] = 0xe0;
6089 nv->port_name[4] = 0x8b;
6090 nv->port_name[5] = 0x1c;
6091 nv->port_name[6] = 0x55;
6092 nv->port_name[7] = 0x86;
6093 nv->node_name[0] = 0x20;
6094 nv->node_name[1] = 0x00;
6095 nv->node_name[2] = 0x00;
6096 nv->node_name[3] = 0xe0;
6097 nv->node_name[4] = 0x8b;
6098 nv->node_name[5] = 0x1c;
6099 nv->node_name[6] = 0x55;
6100 nv->node_name[7] = 0x86;
6101 nv->login_retry_count = __constant_cpu_to_le16(8);
6102 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
6103 nv->login_timeout = __constant_cpu_to_le16(0);
6104 nv->firmware_options_1 =
6105 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
6106 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
6107 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
6108 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
6109 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
6110 nv->efi_parameters = __constant_cpu_to_le32(0);
6111 nv->reset_delay = 5;
6112 nv->max_luns_per_target = __constant_cpu_to_le16(128);
6113 nv->port_down_retry_count = __constant_cpu_to_le16(30);
6114 nv->link_down_timeout = __constant_cpu_to_le16(180);
6115 nv->enode_mac[0] = 0x00;
6116 nv->enode_mac[1] = 0xC0;
6117 nv->enode_mac[2] = 0xDD;
6118 nv->enode_mac[3] = 0x04;
6119 nv->enode_mac[4] = 0x05;
6120 nv->enode_mac[5] = 0x06 + ha->port_no + 1;
6125 if (IS_T10_PI_CAPABLE(ha))
6126 nv->frame_payload_size &= ~7;
6128 qlt_81xx_config_nvram_stage1(vha, nv);
6130 /* Reset Initialization control block */
6131 memset(icb, 0, ha->init_cb_size);
6133 /* Copy 1st segment. */
6134 dptr1 = (uint8_t *)icb;
6135 dptr2 = (uint8_t *)&nv->version;
6136 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
6138 *dptr1++ = *dptr2++;
6140 icb->login_retry_count = nv->login_retry_count;
6142 /* Copy 2nd segment. */
6143 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
6144 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
6145 cnt = (uint8_t *)&icb->reserved_5 -
6146 (uint8_t *)&icb->interrupt_delay_timer;
6148 *dptr1++ = *dptr2++;
6150 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
6151 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
6152 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
6153 icb->enode_mac[0] = 0x00;
6154 icb->enode_mac[1] = 0xC0;
6155 icb->enode_mac[2] = 0xDD;
6156 icb->enode_mac[3] = 0x04;
6157 icb->enode_mac[4] = 0x05;
6158 icb->enode_mac[5] = 0x06 + ha->port_no + 1;
6161 /* Use extended-initialization control block. */
6162 memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
6165 * Setup driver NVRAM options.
6167 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
6170 qlt_81xx_config_nvram_stage2(vha, icb);
6172 /* Use alternate WWN? */
6173 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
6174 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
6175 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
6178 /* Prepare nodename */
6179 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
6181 * Firmware will apply the following mask if the nodename was
6184 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
6185 icb->node_name[0] &= 0xF0;
6188 /* Set host adapter parameters. */
6189 ha->flags.disable_risc_code_load = 0;
6190 ha->flags.enable_lip_reset = 0;
6191 ha->flags.enable_lip_full_login =
6192 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
6193 ha->flags.enable_target_reset =
6194 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
6195 ha->flags.enable_led_scheme = 0;
6196 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
6198 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
6199 (BIT_6 | BIT_5 | BIT_4)) >> 4;
6201 /* save HBA serial number */
6202 ha->serial0 = icb->port_name[5];
6203 ha->serial1 = icb->port_name[6];
6204 ha->serial2 = icb->port_name[7];
6205 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
6206 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
6208 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
6210 ha->retry_count = le16_to_cpu(nv->login_retry_count);
6212 /* Set minimum login_timeout to 4 seconds. */
6213 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
6214 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
6215 if (le16_to_cpu(nv->login_timeout) < 4)
6216 nv->login_timeout = __constant_cpu_to_le16(4);
6217 ha->login_timeout = le16_to_cpu(nv->login_timeout);
6218 icb->login_timeout = nv->login_timeout;
6220 /* Set minimum RATOV to 100 tenths of a second. */
6223 ha->loop_reset_delay = nv->reset_delay;
6225 /* Link Down Timeout = 0:
6227 * When Port Down timer expires we will start returning
6228 * I/O's to OS with "DID_NO_CONNECT".
6230 * Link Down Timeout != 0:
6232 * The driver waits for the link to come up after link down
6233 * before returning I/Os to OS with "DID_NO_CONNECT".
6235 if (le16_to_cpu(nv->link_down_timeout) == 0) {
6236 ha->loop_down_abort_time =
6237 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
6239 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
6240 ha->loop_down_abort_time =
6241 (LOOP_DOWN_TIME - ha->link_down_timeout);
6244 /* Need enough time to try and get the port back. */
6245 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
6246 if (qlport_down_retry)
6247 ha->port_down_retry_count = qlport_down_retry;
6249 /* Set login_retry_count */
6250 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
6251 if (ha->port_down_retry_count ==
6252 le16_to_cpu(nv->port_down_retry_count) &&
6253 ha->port_down_retry_count > 3)
6254 ha->login_retry_count = ha->port_down_retry_count;
6255 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
6256 ha->login_retry_count = ha->port_down_retry_count;
6257 if (ql2xloginretrycount)
6258 ha->login_retry_count = ql2xloginretrycount;
6260 /* if not running MSI-X we need handshaking on interrupts */
6261 if (!vha->hw->flags.msix_enabled && (IS_QLA83XX(ha) || IS_QLA27XX(ha)))
6262 icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_22);
6265 if (!vha->flags.init_done) {
6266 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
6267 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
6268 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
6269 le16_to_cpu(icb->interrupt_delay_timer): 2;
6271 icb->firmware_options_2 &= __constant_cpu_to_le32(
6272 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
6273 vha->flags.process_response_queue = 0;
6274 if (ha->zio_mode != QLA_ZIO_DISABLED) {
6275 ha->zio_mode = QLA_ZIO_MODE_6;
6277 ql_log(ql_log_info, vha, 0x0075,
6278 "ZIO mode %d enabled; timer delay (%d us).\n",
6280 ha->zio_timer * 100);
6282 icb->firmware_options_2 |= cpu_to_le32(
6283 (uint32_t)ha->zio_mode);
6284 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
6285 vha->flags.process_response_queue = 1;
6289 ql_log(ql_log_warn, vha, 0x0076,
6290 "NVRAM configuration failed.\n");
6296 qla82xx_restart_isp(scsi_qla_host_t *vha)
6299 struct qla_hw_data *ha = vha->hw;
6300 struct req_que *req = ha->req_q_map[0];
6301 struct rsp_que *rsp = ha->rsp_q_map[0];
6302 struct scsi_qla_host *vp;
6303 unsigned long flags;
6305 status = qla2x00_init_rings(vha);
6307 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
6308 ha->flags.chip_reset_done = 1;
6310 status = qla2x00_fw_ready(vha);
6312 /* Issue a marker after FW becomes ready. */
6313 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
6314 vha->flags.online = 1;
6315 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
6318 /* if no cable then assume it's good */
6319 if ((vha->device_flags & DFLG_NO_CABLE))
6324 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
6326 if (!atomic_read(&vha->loop_down_timer)) {
6328 * Issue marker command only when we are going
6329 * to start the I/O .
6331 vha->marker_needed = 1;
6334 ha->isp_ops->enable_intrs(ha);
6336 ha->isp_abort_cnt = 0;
6337 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6339 /* Update the firmware version */
6340 status = qla82xx_check_md_needed(vha);
6343 ha->flags.fce_enabled = 1;
6345 fce_calc_size(ha->fce_bufs));
6346 rval = qla2x00_enable_fce_trace(vha,
6347 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
6350 ql_log(ql_log_warn, vha, 0x8001,
6351 "Unable to reinitialize FCE (%d).\n",
6353 ha->flags.fce_enabled = 0;
6358 memset(ha->eft, 0, EFT_SIZE);
6359 rval = qla2x00_enable_eft_trace(vha,
6360 ha->eft_dma, EFT_NUM_BUFFERS);
6362 ql_log(ql_log_warn, vha, 0x8010,
6363 "Unable to reinitialize EFT (%d).\n",
6370 ql_dbg(ql_dbg_taskm, vha, 0x8011,
6371 "qla82xx_restart_isp succeeded.\n");
6373 spin_lock_irqsave(&ha->vport_slock, flags);
6374 list_for_each_entry(vp, &ha->vp_list, list) {
6376 atomic_inc(&vp->vref_count);
6377 spin_unlock_irqrestore(&ha->vport_slock, flags);
6379 qla2x00_vp_abort_isp(vp);
6381 spin_lock_irqsave(&ha->vport_slock, flags);
6382 atomic_dec(&vp->vref_count);
6385 spin_unlock_irqrestore(&ha->vport_slock, flags);
6388 ql_log(ql_log_warn, vha, 0x8016,
6389 "qla82xx_restart_isp **** FAILED ****.\n");
6396 qla81xx_update_fw_options(scsi_qla_host_t *vha)
6398 struct qla_hw_data *ha = vha->hw;
6403 /* Enable ETS Burst. */
6404 memset(ha->fw_options, 0, sizeof(ha->fw_options));
6405 ha->fw_options[2] |= BIT_9;
6406 qla2x00_set_fw_options(vha, ha->fw_options);
6410 * qla24xx_get_fcp_prio
6411 * Gets the fcp cmd priority value for the logged in port.
6412 * Looks for a match of the port descriptors within
6413 * each of the fcp prio config entries. If a match is found,
6414 * the tag (priority) value is returned.
6417 * vha = scsi host structure pointer.
6418 * fcport = port structure pointer.
6421 * non-zero (if found)
6428 qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
6431 uint8_t pid_match, wwn_match;
6433 uint32_t pid1, pid2;
6434 uint64_t wwn1, wwn2;
6435 struct qla_fcp_prio_entry *pri_entry;
6436 struct qla_hw_data *ha = vha->hw;
6438 if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled)
6442 entries = ha->fcp_prio_cfg->num_entries;
6443 pri_entry = &ha->fcp_prio_cfg->entry[0];
6445 for (i = 0; i < entries; i++) {
6446 pid_match = wwn_match = 0;
6448 if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) {
6453 /* check source pid for a match */
6454 if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) {
6455 pid1 = pri_entry->src_pid & INVALID_PORT_ID;
6456 pid2 = vha->d_id.b24 & INVALID_PORT_ID;
6457 if (pid1 == INVALID_PORT_ID)
6459 else if (pid1 == pid2)
6463 /* check destination pid for a match */
6464 if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) {
6465 pid1 = pri_entry->dst_pid & INVALID_PORT_ID;
6466 pid2 = fcport->d_id.b24 & INVALID_PORT_ID;
6467 if (pid1 == INVALID_PORT_ID)
6469 else if (pid1 == pid2)
6473 /* check source WWN for a match */
6474 if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) {
6475 wwn1 = wwn_to_u64(vha->port_name);
6476 wwn2 = wwn_to_u64(pri_entry->src_wwpn);
6477 if (wwn2 == (uint64_t)-1)
6479 else if (wwn1 == wwn2)
6483 /* check destination WWN for a match */
6484 if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) {
6485 wwn1 = wwn_to_u64(fcport->port_name);
6486 wwn2 = wwn_to_u64(pri_entry->dst_wwpn);
6487 if (wwn2 == (uint64_t)-1)
6489 else if (wwn1 == wwn2)
6493 if (pid_match == 2 || wwn_match == 2) {
6494 /* Found a matching entry */
6495 if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
6496 priority = pri_entry->tag;
6507 * qla24xx_update_fcport_fcp_prio
6508 * Activates fcp priority for the logged in fc port
6511 * vha = scsi host structure pointer.
6512 * fcp = port structure pointer.
6515 * QLA_SUCCESS or QLA_FUNCTION_FAILED
6521 qla24xx_update_fcport_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
6527 if (fcport->port_type != FCT_TARGET ||
6528 fcport->loop_id == FC_NO_LOOP_ID)
6529 return QLA_FUNCTION_FAILED;
6531 priority = qla24xx_get_fcp_prio(vha, fcport);
6533 return QLA_FUNCTION_FAILED;
6535 if (IS_P3P_TYPE(vha->hw)) {
6536 fcport->fcp_prio = priority & 0xf;
6540 ret = qla24xx_set_fcp_prio(vha, fcport->loop_id, priority, mb);
6541 if (ret == QLA_SUCCESS) {
6542 if (fcport->fcp_prio != priority)
6543 ql_dbg(ql_dbg_user, vha, 0x709e,
6544 "Updated FCP_CMND priority - value=%d loop_id=%d "
6545 "port_id=%02x%02x%02x.\n", priority,
6546 fcport->loop_id, fcport->d_id.b.domain,
6547 fcport->d_id.b.area, fcport->d_id.b.al_pa);
6548 fcport->fcp_prio = priority & 0xf;
6550 ql_dbg(ql_dbg_user, vha, 0x704f,
6551 "Unable to update FCP_CMND priority - ret=0x%x for "
6552 "loop_id=%d port_id=%02x%02x%02x.\n", ret, fcport->loop_id,
6553 fcport->d_id.b.domain, fcport->d_id.b.area,
6554 fcport->d_id.b.al_pa);
6559 * qla24xx_update_all_fcp_prio
6560 * Activates fcp priority for all the logged in ports
6563 * ha = adapter block pointer.
6566 * QLA_SUCCESS or QLA_FUNCTION_FAILED
6572 qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha)
6577 ret = QLA_FUNCTION_FAILED;
6578 /* We need to set priority for all logged in ports */
6579 list_for_each_entry(fcport, &vha->vp_fcports, list)
6580 ret = qla24xx_update_fcport_fcp_prio(vha, fcport);