Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Andrew Vasquez | fa90c54 | 2005-10-27 11:10:08 -0700 | [diff] [blame] | 2 | * QLogic Fibre Channel HBA Driver |
Armen Baloyan | bd21eaf | 2014-04-11 16:54:24 -0400 | [diff] [blame] | 3 | * Copyright (c) 2003-2014 QLogic Corporation |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * |
Andrew Vasquez | fa90c54 | 2005-10-27 11:10:08 -0700 | [diff] [blame] | 5 | * See LICENSE.qla2xxx for copyright and licensing details. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | */ |
| 7 | #include "qla_def.h" |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 8 | #include "qla_gbl.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | |
| 10 | #include <linux/delay.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 11 | #include <linux/slab.h> |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 12 | #include <linux/vmalloc.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | |
| 14 | #include "qla_devtbl.h" |
| 15 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 16 | #ifdef CONFIG_SPARC |
| 17 | #include <asm/prom.h> |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 18 | #endif |
| 19 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 20 | #include <target/target_core_base.h> |
| 21 | #include "qla_target.h" |
| 22 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | /* |
| 24 | * QLogic ISP2x00 Hardware Support Function Prototypes. |
| 25 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | static int qla2x00_isp_firmware(scsi_qla_host_t *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | static int qla2x00_setup_chip(scsi_qla_host_t *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | static int qla2x00_fw_ready(scsi_qla_host_t *); |
| 29 | static int qla2x00_configure_hba(scsi_qla_host_t *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | static int qla2x00_configure_loop(scsi_qla_host_t *); |
| 31 | static int qla2x00_configure_local_loop(scsi_qla_host_t *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | static int qla2x00_configure_fabric(scsi_qla_host_t *); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 33 | static int qla2x00_find_all_fabric_devs(scsi_qla_host_t *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | static int qla2x00_restart_isp(scsi_qla_host_t *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 36 | static struct qla_chip_state_84xx *qla84xx_get_chip(struct scsi_qla_host *); |
| 37 | static int qla84xx_init_chip(scsi_qla_host_t *); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 38 | static int qla25xx_init_queues(struct qla_hw_data *); |
Duane Grigsby | a5d42f4 | 2017-06-21 13:48:41 -0700 | [diff] [blame] | 39 | static int qla24xx_post_prli_work(struct scsi_qla_host*, fc_port_t *); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 40 | static void qla24xx_handle_plogi_done_event(struct scsi_qla_host *, |
| 41 | struct event_arg *); |
Duane Grigsby | a5d42f4 | 2017-06-21 13:48:41 -0700 | [diff] [blame] | 42 | static void qla24xx_handle_prli_done_event(struct scsi_qla_host *, |
| 43 | struct event_arg *); |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 44 | static void __qla24xx_handle_gpdb_event(scsi_qla_host_t *, struct event_arg *); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 45 | |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 46 | /* SRB Extensions ---------------------------------------------------------- */ |
| 47 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 48 | void |
Kees Cook | 8e5f4ba | 2017-09-03 13:23:32 -0700 | [diff] [blame] | 49 | qla2x00_sp_timeout(struct timer_list *t) |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 50 | { |
Kees Cook | 8e5f4ba | 2017-09-03 13:23:32 -0700 | [diff] [blame] | 51 | srb_t *sp = from_timer(sp, t, u.iocb_cmd.timer); |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 52 | struct srb_iocb *iocb; |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 53 | scsi_qla_host_t *vha = sp->vha; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 54 | struct req_que *req; |
| 55 | unsigned long flags; |
| 56 | |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 57 | spin_lock_irqsave(&vha->hw->hardware_lock, flags); |
| 58 | req = vha->hw->req_q_map[0]; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 59 | req->outstanding_cmds[sp->handle] = NULL; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 60 | iocb = &sp->u.iocb_cmd; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 61 | iocb->timeout(sp); |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 62 | spin_unlock_irqrestore(&vha->hw->hardware_lock, flags); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 63 | } |
| 64 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 65 | void |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 66 | qla2x00_sp_free(void *ptr) |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 67 | { |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 68 | srb_t *sp = ptr; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 69 | struct srb_iocb *iocb = &sp->u.iocb_cmd; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 70 | |
Chad Dupuis | 4d97cc5 | 2010-10-15 11:27:41 -0700 | [diff] [blame] | 71 | del_timer(&iocb->timer); |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 72 | qla2x00_rel_sp(sp); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 73 | } |
| 74 | |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 75 | /* Asynchronous Login/Logout Routines -------------------------------------- */ |
| 76 | |
Saurav Kashyap | a9b6f72 | 2012-08-22 14:21:01 -0400 | [diff] [blame] | 77 | unsigned long |
Andrew Vasquez | 5b91490 | 2010-05-28 15:08:30 -0700 | [diff] [blame] | 78 | qla2x00_get_async_timeout(struct scsi_qla_host *vha) |
| 79 | { |
| 80 | unsigned long tmo; |
| 81 | struct qla_hw_data *ha = vha->hw; |
| 82 | |
| 83 | /* Firmware should use switch negotiated r_a_tov for timeout. */ |
| 84 | tmo = ha->r_a_tov / 10 * 2; |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 85 | if (IS_QLAFX00(ha)) { |
| 86 | tmo = FX00_DEF_RATOV * 2; |
| 87 | } else if (!IS_FWI2_CAPABLE(ha)) { |
Andrew Vasquez | 5b91490 | 2010-05-28 15:08:30 -0700 | [diff] [blame] | 88 | /* |
| 89 | * Except for earlier ISPs where the timeout is seeded from the |
| 90 | * initialization control block. |
| 91 | */ |
| 92 | tmo = ha->login_timeout; |
| 93 | } |
| 94 | return tmo; |
| 95 | } |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 96 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 97 | void |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 98 | qla2x00_async_iocb_timeout(void *data) |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 99 | { |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 100 | srb_t *sp = data; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 101 | fc_port_t *fcport = sp->fcport; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 102 | struct srb_iocb *lio = &sp->u.iocb_cmd; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 103 | |
Quinn Tran | 5c25d45 | 2017-12-28 12:33:09 -0800 | [diff] [blame] | 104 | if (fcport) { |
| 105 | ql_dbg(ql_dbg_disc, fcport->vha, 0x2071, |
| 106 | "Async-%s timeout - hdl=%x portid=%06x %8phC.\n", |
| 107 | sp->name, sp->handle, fcport->d_id.b24, fcport->port_name); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 108 | |
Quinn Tran | 6d674927 | 2017-12-28 12:33:41 -0800 | [diff] [blame] | 109 | fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE); |
Quinn Tran | 5c25d45 | 2017-12-28 12:33:09 -0800 | [diff] [blame] | 110 | } else { |
| 111 | pr_info("Async-%s timeout - hdl=%x.\n", |
| 112 | sp->name, sp->handle); |
| 113 | } |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 114 | |
| 115 | switch (sp->type) { |
| 116 | case SRB_LOGIN_CMD: |
Andrew Vasquez | 6ac5260 | 2010-05-28 15:08:19 -0700 | [diff] [blame] | 117 | /* Retry as needed. */ |
| 118 | lio->u.logio.data[0] = MBS_COMMAND_ERROR; |
| 119 | lio->u.logio.data[1] = lio->u.logio.flags & SRB_LOGIN_RETRIED ? |
| 120 | QLA_LOGIO_LOGIN_RETRIED : 0; |
Quinn Tran | eaf75d1 | 2018-02-01 10:33:17 -0800 | [diff] [blame] | 121 | sp->done(sp, QLA_FUNCTION_TIMEOUT); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 122 | break; |
| 123 | case SRB_LOGOUT_CMD: |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 124 | case SRB_CT_PTHRU_CMD: |
| 125 | case SRB_MB_IOCB: |
| 126 | case SRB_NACK_PLOGI: |
| 127 | case SRB_NACK_PRLI: |
| 128 | case SRB_NACK_LOGO: |
Quinn Tran | 2853192 | 2017-12-28 12:33:10 -0800 | [diff] [blame] | 129 | case SRB_CTRL_VP: |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 130 | sp->done(sp, QLA_FUNCTION_TIMEOUT); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 131 | break; |
Andrew Vasquez | 6ac5260 | 2010-05-28 15:08:19 -0700 | [diff] [blame] | 132 | } |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 133 | } |
| 134 | |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 135 | static void |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 136 | qla2x00_async_login_sp_done(void *ptr, int res) |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 137 | { |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 138 | srb_t *sp = ptr; |
| 139 | struct scsi_qla_host *vha = sp->vha; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 140 | struct srb_iocb *lio = &sp->u.iocb_cmd; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 141 | struct event_arg ea; |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 142 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 143 | ql_dbg(ql_dbg_disc, vha, 0x20dd, |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 144 | "%s %8phC res %d \n", __func__, sp->fcport->port_name, res); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 145 | |
Quinn Tran | 6d674927 | 2017-12-28 12:33:41 -0800 | [diff] [blame] | 146 | sp->fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE); |
| 147 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 148 | if (!test_bit(UNLOADING, &vha->dpc_flags)) { |
| 149 | memset(&ea, 0, sizeof(ea)); |
| 150 | ea.event = FCME_PLOGI_DONE; |
| 151 | ea.fcport = sp->fcport; |
| 152 | ea.data[0] = lio->u.logio.data[0]; |
| 153 | ea.data[1] = lio->u.logio.data[1]; |
| 154 | ea.iop[0] = lio->u.logio.iop[0]; |
| 155 | ea.iop[1] = lio->u.logio.iop[1]; |
| 156 | ea.sp = sp; |
| 157 | qla2x00_fcport_event_handler(vha, &ea); |
| 158 | } |
| 159 | |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 160 | sp->free(sp); |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 161 | } |
| 162 | |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 163 | int |
| 164 | qla2x00_async_login(struct scsi_qla_host *vha, fc_port_t *fcport, |
| 165 | uint16_t *data) |
| 166 | { |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 167 | srb_t *sp; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 168 | struct srb_iocb *lio; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 169 | int rval = QLA_FUNCTION_FAILED; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 170 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 171 | if (!vha->flags.online) |
| 172 | goto done; |
| 173 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 174 | sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 175 | if (!sp) |
| 176 | goto done; |
| 177 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 178 | fcport->flags |= FCF_ASYNC_SENT; |
| 179 | fcport->logout_completed = 0; |
| 180 | |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 181 | fcport->disc_state = DSC_LOGIN_PEND; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 182 | sp->type = SRB_LOGIN_CMD; |
| 183 | sp->name = "login"; |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 184 | sp->gen1 = fcport->rscn_gen; |
| 185 | sp->gen2 = fcport->login_gen; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 186 | qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2); |
| 187 | |
| 188 | lio = &sp->u.iocb_cmd; |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 189 | lio->timeout = qla2x00_async_iocb_timeout; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 190 | sp->done = qla2x00_async_login_sp_done; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 191 | lio->u.logio.flags |= SRB_LOGIN_COND_PLOGI; |
Duane Grigsby | a5d42f4 | 2017-06-21 13:48:41 -0700 | [diff] [blame] | 192 | |
| 193 | if (fcport->fc4f_nvme) |
| 194 | lio->u.logio.flags |= SRB_LOGIN_SKIP_PRLI; |
| 195 | |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 196 | if (data[1] & QLA_LOGIO_LOGIN_RETRIED) |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 197 | lio->u.logio.flags |= SRB_LOGIN_RETRIED; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 198 | rval = qla2x00_start_sp(sp); |
Chad Dupuis | 080c951 | 2016-01-27 12:03:37 -0500 | [diff] [blame] | 199 | if (rval != QLA_SUCCESS) { |
Chad Dupuis | 080c951 | 2016-01-27 12:03:37 -0500 | [diff] [blame] | 200 | fcport->flags |= FCF_LOGIN_NEEDED; |
| 201 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 202 | goto done_free_sp; |
Chad Dupuis | 080c951 | 2016-01-27 12:03:37 -0500 | [diff] [blame] | 203 | } |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 204 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 205 | ql_dbg(ql_dbg_disc, vha, 0x2072, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 206 | "Async-login - %8phC hdl=%x, loopid=%x portid=%02x%02x%02x " |
| 207 | "retries=%d.\n", fcport->port_name, sp->handle, fcport->loop_id, |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 208 | fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa, |
| 209 | fcport->login_retry); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 210 | return rval; |
| 211 | |
| 212 | done_free_sp: |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 213 | sp->free(sp); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 214 | fcport->flags &= ~FCF_ASYNC_SENT; |
Quinn Tran | 3dbec59 | 2017-12-28 12:33:40 -0800 | [diff] [blame] | 215 | done: |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 216 | return rval; |
| 217 | } |
| 218 | |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 219 | static void |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 220 | qla2x00_async_logout_sp_done(void *ptr, int res) |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 221 | { |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 222 | srb_t *sp = ptr; |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 223 | |
Quinn Tran | 6d674927 | 2017-12-28 12:33:41 -0800 | [diff] [blame] | 224 | sp->fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE); |
Quinn Tran | eaf75d1 | 2018-02-01 10:33:17 -0800 | [diff] [blame] | 225 | sp->fcport->login_gen++; |
| 226 | qlt_logo_completion_handler(sp->fcport, res); |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 227 | sp->free(sp); |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 228 | } |
| 229 | |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 230 | int |
| 231 | qla2x00_async_logout(struct scsi_qla_host *vha, fc_port_t *fcport) |
| 232 | { |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 233 | srb_t *sp; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 234 | struct srb_iocb *lio; |
Quinn Tran | 3dbec59 | 2017-12-28 12:33:40 -0800 | [diff] [blame] | 235 | int rval = QLA_FUNCTION_FAILED; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 236 | |
Quinn Tran | 3dbec59 | 2017-12-28 12:33:40 -0800 | [diff] [blame] | 237 | if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT)) |
| 238 | return rval; |
| 239 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 240 | fcport->flags |= FCF_ASYNC_SENT; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 241 | sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 242 | if (!sp) |
| 243 | goto done; |
| 244 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 245 | sp->type = SRB_LOGOUT_CMD; |
| 246 | sp->name = "logout"; |
| 247 | qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2); |
| 248 | |
| 249 | lio = &sp->u.iocb_cmd; |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 250 | lio->timeout = qla2x00_async_iocb_timeout; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 251 | sp->done = qla2x00_async_logout_sp_done; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 252 | rval = qla2x00_start_sp(sp); |
| 253 | if (rval != QLA_SUCCESS) |
| 254 | goto done_free_sp; |
| 255 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 256 | ql_dbg(ql_dbg_disc, vha, 0x2070, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 257 | "Async-logout - hdl=%x loop-id=%x portid=%02x%02x%02x %8phC.\n", |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 258 | sp->handle, fcport->loop_id, fcport->d_id.b.domain, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 259 | fcport->d_id.b.area, fcport->d_id.b.al_pa, |
| 260 | fcport->port_name); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 261 | return rval; |
| 262 | |
| 263 | done_free_sp: |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 264 | sp->free(sp); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 265 | done: |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 266 | fcport->flags &= ~FCF_ASYNC_SENT; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 267 | return rval; |
| 268 | } |
Quinn Tran | 11aea16 | 2017-12-28 12:33:20 -0800 | [diff] [blame] | 269 | |
| 270 | void |
| 271 | qla2x00_async_prlo_done(struct scsi_qla_host *vha, fc_port_t *fcport, |
| 272 | uint16_t *data) |
| 273 | { |
| 274 | /* Don't re-login in target mode */ |
| 275 | if (!fcport->tgt_session) |
| 276 | qla2x00_mark_device_lost(vha, fcport, 1, 0); |
| 277 | qlt_logo_completion_handler(fcport, data[0]); |
| 278 | } |
| 279 | |
| 280 | static void |
| 281 | qla2x00_async_prlo_sp_done(void *s, int res) |
| 282 | { |
| 283 | srb_t *sp = (srb_t *)s; |
| 284 | struct srb_iocb *lio = &sp->u.iocb_cmd; |
| 285 | struct scsi_qla_host *vha = sp->vha; |
| 286 | |
| 287 | if (!test_bit(UNLOADING, &vha->dpc_flags)) |
| 288 | qla2x00_post_async_prlo_done_work(sp->fcport->vha, sp->fcport, |
| 289 | lio->u.logio.data); |
| 290 | sp->free(sp); |
| 291 | } |
| 292 | |
| 293 | int |
| 294 | qla2x00_async_prlo(struct scsi_qla_host *vha, fc_port_t *fcport) |
| 295 | { |
| 296 | srb_t *sp; |
| 297 | struct srb_iocb *lio; |
| 298 | int rval; |
| 299 | |
| 300 | rval = QLA_FUNCTION_FAILED; |
| 301 | sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); |
| 302 | if (!sp) |
| 303 | goto done; |
| 304 | |
| 305 | sp->type = SRB_PRLO_CMD; |
| 306 | sp->name = "prlo"; |
| 307 | qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2); |
| 308 | |
| 309 | lio = &sp->u.iocb_cmd; |
| 310 | lio->timeout = qla2x00_async_iocb_timeout; |
| 311 | sp->done = qla2x00_async_prlo_sp_done; |
| 312 | rval = qla2x00_start_sp(sp); |
| 313 | if (rval != QLA_SUCCESS) |
| 314 | goto done_free_sp; |
| 315 | |
| 316 | ql_dbg(ql_dbg_disc, vha, 0x2070, |
| 317 | "Async-prlo - hdl=%x loop-id=%x portid=%02x%02x%02x.\n", |
| 318 | sp->handle, fcport->loop_id, fcport->d_id.b.domain, |
| 319 | fcport->d_id.b.area, fcport->d_id.b.al_pa); |
| 320 | return rval; |
| 321 | |
| 322 | done_free_sp: |
| 323 | sp->free(sp); |
| 324 | done: |
| 325 | return rval; |
| 326 | } |
| 327 | |
Quinn Tran | f13515a | 2017-12-28 12:33:15 -0800 | [diff] [blame] | 328 | static |
| 329 | void qla24xx_handle_adisc_event(scsi_qla_host_t *vha, struct event_arg *ea) |
| 330 | { |
Quinn Tran | 0616e96 | 2017-12-28 12:33:34 -0800 | [diff] [blame] | 331 | struct fc_port *fcport = ea->fcport; |
| 332 | |
| 333 | ql_dbg(ql_dbg_disc, vha, 0x20d2, |
| 334 | "%s %8phC DS %d LS %d rc %d login %d|%d rscn %d|%d lid %d\n", |
| 335 | __func__, fcport->port_name, fcport->disc_state, |
| 336 | fcport->fw_login_state, ea->rc, fcport->login_gen, ea->sp->gen2, |
| 337 | fcport->rscn_gen, ea->sp->gen1, fcport->loop_id); |
| 338 | |
| 339 | if (ea->data[0] != MBS_COMMAND_COMPLETE) { |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 340 | ql_dbg(ql_dbg_disc, vha, 0x2066, |
| 341 | "%s %8phC: adisc fail: post delete\n", |
| 342 | __func__, ea->fcport->port_name); |
Quinn Tran | 94cff6e | 2017-12-28 12:33:42 -0800 | [diff] [blame] | 343 | qlt_schedule_sess_for_deletion(ea->fcport); |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 344 | return; |
| 345 | } |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 346 | |
| 347 | if (ea->fcport->disc_state == DSC_DELETE_PEND) |
| 348 | return; |
| 349 | |
| 350 | if (ea->sp->gen2 != ea->fcport->login_gen) { |
| 351 | /* target side must have changed it. */ |
| 352 | ql_dbg(ql_dbg_disc, vha, 0x20d3, |
Quinn Tran | 0616e96 | 2017-12-28 12:33:34 -0800 | [diff] [blame] | 353 | "%s %8phC generation changed\n", |
| 354 | __func__, ea->fcport->port_name); |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 355 | return; |
| 356 | } else if (ea->sp->gen1 != ea->fcport->rscn_gen) { |
| 357 | ql_dbg(ql_dbg_disc, vha, 0x20d4, "%s %d %8phC post gidpn\n", |
| 358 | __func__, __LINE__, ea->fcport->port_name); |
| 359 | qla24xx_post_gidpn_work(vha, ea->fcport); |
| 360 | return; |
| 361 | } |
| 362 | |
| 363 | __qla24xx_handle_gpdb_event(vha, ea); |
Quinn Tran | f13515a | 2017-12-28 12:33:15 -0800 | [diff] [blame] | 364 | } |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 365 | |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 366 | static void |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 367 | qla2x00_async_adisc_sp_done(void *ptr, int res) |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 368 | { |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 369 | srb_t *sp = ptr; |
| 370 | struct scsi_qla_host *vha = sp->vha; |
Quinn Tran | f13515a | 2017-12-28 12:33:15 -0800 | [diff] [blame] | 371 | struct event_arg ea; |
Quinn Tran | 0616e96 | 2017-12-28 12:33:34 -0800 | [diff] [blame] | 372 | struct srb_iocb *lio = &sp->u.iocb_cmd; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 373 | |
Quinn Tran | f13515a | 2017-12-28 12:33:15 -0800 | [diff] [blame] | 374 | ql_dbg(ql_dbg_disc, vha, 0x2066, |
| 375 | "Async done-%s res %x %8phC\n", |
| 376 | sp->name, res, sp->fcport->port_name); |
| 377 | |
| 378 | memset(&ea, 0, sizeof(ea)); |
| 379 | ea.event = FCME_ADISC_DONE; |
| 380 | ea.rc = res; |
Quinn Tran | 0616e96 | 2017-12-28 12:33:34 -0800 | [diff] [blame] | 381 | ea.data[0] = lio->u.logio.data[0]; |
| 382 | ea.data[1] = lio->u.logio.data[1]; |
| 383 | ea.iop[0] = lio->u.logio.iop[0]; |
| 384 | ea.iop[1] = lio->u.logio.iop[1]; |
Quinn Tran | f13515a | 2017-12-28 12:33:15 -0800 | [diff] [blame] | 385 | ea.fcport = sp->fcport; |
| 386 | ea.sp = sp; |
| 387 | |
| 388 | qla2x00_fcport_event_handler(vha, &ea); |
| 389 | |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 390 | sp->free(sp); |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 391 | } |
| 392 | |
| 393 | int |
| 394 | qla2x00_async_adisc(struct scsi_qla_host *vha, fc_port_t *fcport, |
| 395 | uint16_t *data) |
| 396 | { |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 397 | srb_t *sp; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 398 | struct srb_iocb *lio; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 399 | int rval; |
| 400 | |
| 401 | rval = QLA_FUNCTION_FAILED; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 402 | fcport->flags |= FCF_ASYNC_SENT; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 403 | sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 404 | if (!sp) |
| 405 | goto done; |
| 406 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 407 | sp->type = SRB_ADISC_CMD; |
| 408 | sp->name = "adisc"; |
| 409 | qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2); |
| 410 | |
| 411 | lio = &sp->u.iocb_cmd; |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 412 | lio->timeout = qla2x00_async_iocb_timeout; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 413 | sp->done = qla2x00_async_adisc_sp_done; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 414 | if (data[1] & QLA_LOGIO_LOGIN_RETRIED) |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 415 | lio->u.logio.flags |= SRB_LOGIN_RETRIED; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 416 | rval = qla2x00_start_sp(sp); |
| 417 | if (rval != QLA_SUCCESS) |
| 418 | goto done_free_sp; |
| 419 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 420 | ql_dbg(ql_dbg_disc, vha, 0x206f, |
Quinn Tran | f13515a | 2017-12-28 12:33:15 -0800 | [diff] [blame] | 421 | "Async-adisc - hdl=%x loopid=%x portid=%06x %8phC.\n", |
| 422 | sp->handle, fcport->loop_id, fcport->d_id.b24, fcport->port_name); |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 423 | return rval; |
| 424 | |
| 425 | done_free_sp: |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 426 | sp->free(sp); |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 427 | done: |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 428 | fcport->flags &= ~FCF_ASYNC_SENT; |
Quinn Tran | f13515a | 2017-12-28 12:33:15 -0800 | [diff] [blame] | 429 | qla2x00_post_async_adisc_work(vha, fcport, data); |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 430 | return rval; |
| 431 | } |
| 432 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 433 | static void qla24xx_handle_gnl_done_event(scsi_qla_host_t *vha, |
| 434 | struct event_arg *ea) |
| 435 | { |
| 436 | fc_port_t *fcport, *conflict_fcport; |
| 437 | struct get_name_list_extended *e; |
| 438 | u16 i, n, found = 0, loop_id; |
| 439 | port_id_t id; |
| 440 | u64 wwn; |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 441 | u16 data[2]; |
| 442 | u8 current_login_state; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 443 | |
| 444 | fcport = ea->fcport; |
Quinn Tran | f352eeb | 2017-12-28 12:33:35 -0800 | [diff] [blame] | 445 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 446 | "%s %8phC DS %d LS rc %d %d login %d|%d rscn %d|%d lid %d\n", |
| 447 | __func__, fcport->port_name, fcport->disc_state, |
| 448 | fcport->fw_login_state, ea->rc, |
| 449 | fcport->login_gen, fcport->last_login_gen, |
| 450 | fcport->rscn_gen, fcport->last_rscn_gen, vha->loop_id); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 451 | |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 452 | if (fcport->disc_state == DSC_DELETE_PEND) |
| 453 | return; |
| 454 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 455 | if (ea->rc) { /* rval */ |
| 456 | if (fcport->login_retry == 0) { |
| 457 | fcport->login_retry = vha->hw->login_retry_count; |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 458 | ql_dbg(ql_dbg_disc, vha, 0x20de, |
| 459 | "GNL failed Port login retry %8phN, retry cnt=%d.\n", |
| 460 | fcport->port_name, fcport->login_retry); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 461 | } |
| 462 | return; |
| 463 | } |
| 464 | |
| 465 | if (fcport->last_rscn_gen != fcport->rscn_gen) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 466 | ql_dbg(ql_dbg_disc, vha, 0x20df, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 467 | "%s %8phC rscn gen changed rscn %d|%d \n", |
| 468 | __func__, fcport->port_name, |
| 469 | fcport->last_rscn_gen, fcport->rscn_gen); |
| 470 | qla24xx_post_gidpn_work(vha, fcport); |
| 471 | return; |
| 472 | } else if (fcport->last_login_gen != fcport->login_gen) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 473 | ql_dbg(ql_dbg_disc, vha, 0x20e0, |
Quinn Tran | f352eeb | 2017-12-28 12:33:35 -0800 | [diff] [blame] | 474 | "%s %8phC login gen changed\n", |
| 475 | __func__, fcport->port_name); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 476 | return; |
| 477 | } |
| 478 | |
| 479 | n = ea->data[0] / sizeof(struct get_name_list_extended); |
| 480 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 481 | ql_dbg(ql_dbg_disc, vha, 0x20e1, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 482 | "%s %d %8phC n %d %02x%02x%02x lid %d \n", |
| 483 | __func__, __LINE__, fcport->port_name, n, |
| 484 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 485 | fcport->d_id.b.al_pa, fcport->loop_id); |
| 486 | |
| 487 | for (i = 0; i < n; i++) { |
| 488 | e = &vha->gnl.l[i]; |
| 489 | wwn = wwn_to_u64(e->port_name); |
| 490 | |
| 491 | if (memcmp((u8 *)&wwn, fcport->port_name, WWN_SIZE)) |
| 492 | continue; |
| 493 | |
| 494 | found = 1; |
| 495 | id.b.domain = e->port_id[2]; |
| 496 | id.b.area = e->port_id[1]; |
| 497 | id.b.al_pa = e->port_id[0]; |
| 498 | id.b.rsvd_1 = 0; |
| 499 | |
| 500 | loop_id = le16_to_cpu(e->nport_handle); |
| 501 | loop_id = (loop_id & 0x7fff); |
| 502 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 503 | ql_dbg(ql_dbg_disc, vha, 0x20e2, |
| 504 | "%s found %8phC CLS [%d|%d] ID[%02x%02x%02x|%02x%02x%02x] lid[%d|%d]\n", |
| 505 | __func__, fcport->port_name, |
| 506 | e->current_login_state, fcport->fw_login_state, |
| 507 | id.b.domain, id.b.area, id.b.al_pa, |
| 508 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 509 | fcport->d_id.b.al_pa, loop_id, fcport->loop_id); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 510 | |
| 511 | if ((id.b24 != fcport->d_id.b24) || |
| 512 | ((fcport->loop_id != FC_NO_LOOP_ID) && |
| 513 | (fcport->loop_id != loop_id))) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 514 | ql_dbg(ql_dbg_disc, vha, 0x20e3, |
| 515 | "%s %d %8phC post del sess\n", |
| 516 | __func__, __LINE__, fcport->port_name); |
Quinn Tran | 94cff6e | 2017-12-28 12:33:42 -0800 | [diff] [blame] | 517 | qlt_schedule_sess_for_deletion(fcport); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 518 | return; |
| 519 | } |
| 520 | |
| 521 | fcport->loop_id = loop_id; |
| 522 | |
| 523 | wwn = wwn_to_u64(fcport->port_name); |
| 524 | qlt_find_sess_invalidate_other(vha, wwn, |
| 525 | id, loop_id, &conflict_fcport); |
| 526 | |
| 527 | if (conflict_fcport) { |
| 528 | /* |
| 529 | * Another share fcport share the same loop_id & |
| 530 | * nport id. Conflict fcport needs to finish |
| 531 | * cleanup before this fcport can proceed to login. |
| 532 | */ |
| 533 | conflict_fcport->conflict = fcport; |
| 534 | fcport->login_pause = 1; |
| 535 | } |
| 536 | |
Duane Grigsby | a5d42f4 | 2017-06-21 13:48:41 -0700 | [diff] [blame] | 537 | if (fcport->fc4f_nvme) |
| 538 | current_login_state = e->current_login_state >> 4; |
| 539 | else |
| 540 | current_login_state = e->current_login_state & 0xf; |
| 541 | |
| 542 | switch (current_login_state) { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 543 | case DSC_LS_PRLI_COMP: |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 544 | ql_dbg(ql_dbg_disc, vha, 0x20e4, |
| 545 | "%s %d %8phC post gpdb\n", |
| 546 | __func__, __LINE__, fcport->port_name); |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 547 | |
| 548 | if ((e->prli_svc_param_word_3[0] & BIT_4) == 0) |
| 549 | fcport->port_type = FCT_INITIATOR; |
| 550 | else |
| 551 | fcport->port_type = FCT_TARGET; |
| 552 | |
| 553 | data[0] = data[1] = 0; |
| 554 | qla2x00_post_async_adisc_work(vha, fcport, data); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 555 | break; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 556 | case DSC_LS_PORT_UNAVAIL: |
| 557 | default: |
| 558 | if (fcport->loop_id == FC_NO_LOOP_ID) { |
| 559 | qla2x00_find_new_loop_id(vha, fcport); |
| 560 | fcport->fw_login_state = DSC_LS_PORT_UNAVAIL; |
| 561 | } |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 562 | ql_dbg(ql_dbg_disc, vha, 0x20e5, |
| 563 | "%s %d %8phC\n", |
| 564 | __func__, __LINE__, fcport->port_name); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 565 | qla24xx_fcport_handle_login(vha, fcport); |
| 566 | break; |
| 567 | } |
| 568 | } |
| 569 | |
| 570 | if (!found) { |
| 571 | /* fw has no record of this port */ |
Quinn Tran | 040036b | 2017-12-28 12:33:38 -0800 | [diff] [blame] | 572 | for (i = 0; i < n; i++) { |
| 573 | e = &vha->gnl.l[i]; |
| 574 | id.b.domain = e->port_id[0]; |
| 575 | id.b.area = e->port_id[1]; |
| 576 | id.b.al_pa = e->port_id[2]; |
| 577 | id.b.rsvd_1 = 0; |
| 578 | loop_id = le16_to_cpu(e->nport_handle); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 579 | |
Quinn Tran | 040036b | 2017-12-28 12:33:38 -0800 | [diff] [blame] | 580 | if (fcport->d_id.b24 == id.b24) { |
| 581 | conflict_fcport = |
| 582 | qla2x00_find_fcport_by_wwpn(vha, |
| 583 | e->port_name, 0); |
| 584 | ql_dbg(ql_dbg_disc, vha, 0x20e6, |
| 585 | "%s %d %8phC post del sess\n", |
| 586 | __func__, __LINE__, |
| 587 | conflict_fcport->port_name); |
| 588 | qlt_schedule_sess_for_deletion |
Quinn Tran | 94cff6e | 2017-12-28 12:33:42 -0800 | [diff] [blame] | 589 | (conflict_fcport); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 590 | } |
Quinn Tran | 040036b | 2017-12-28 12:33:38 -0800 | [diff] [blame] | 591 | |
| 592 | /* FW already picked this loop id for another fcport */ |
| 593 | if (fcport->loop_id == loop_id) |
| 594 | fcport->loop_id = FC_NO_LOOP_ID; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 595 | } |
| 596 | qla24xx_fcport_handle_login(vha, fcport); |
| 597 | } |
| 598 | } /* gnl_event */ |
| 599 | |
| 600 | static void |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 601 | qla24xx_async_gnl_sp_done(void *s, int res) |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 602 | { |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 603 | struct srb *sp = s; |
| 604 | struct scsi_qla_host *vha = sp->vha; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 605 | unsigned long flags; |
| 606 | struct fc_port *fcport = NULL, *tf; |
| 607 | u16 i, n = 0, loop_id; |
| 608 | struct event_arg ea; |
| 609 | struct get_name_list_extended *e; |
| 610 | u64 wwn; |
| 611 | struct list_head h; |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 612 | bool found = false; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 613 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 614 | ql_dbg(ql_dbg_disc, vha, 0x20e7, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 615 | "Async done-%s res %x mb[1]=%x mb[2]=%x \n", |
| 616 | sp->name, res, sp->u.iocb_cmd.u.mbx.in_mb[1], |
| 617 | sp->u.iocb_cmd.u.mbx.in_mb[2]); |
| 618 | |
| 619 | memset(&ea, 0, sizeof(ea)); |
| 620 | ea.sp = sp; |
| 621 | ea.rc = res; |
| 622 | ea.event = FCME_GNL_DONE; |
| 623 | |
| 624 | if (sp->u.iocb_cmd.u.mbx.in_mb[1] >= |
| 625 | sizeof(struct get_name_list_extended)) { |
| 626 | n = sp->u.iocb_cmd.u.mbx.in_mb[1] / |
| 627 | sizeof(struct get_name_list_extended); |
| 628 | ea.data[0] = sp->u.iocb_cmd.u.mbx.in_mb[1]; /* amnt xfered */ |
| 629 | } |
| 630 | |
| 631 | for (i = 0; i < n; i++) { |
| 632 | e = &vha->gnl.l[i]; |
| 633 | loop_id = le16_to_cpu(e->nport_handle); |
| 634 | /* mask out reserve bit */ |
| 635 | loop_id = (loop_id & 0x7fff); |
| 636 | set_bit(loop_id, vha->hw->loop_id_map); |
| 637 | wwn = wwn_to_u64(e->port_name); |
| 638 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 639 | ql_dbg(ql_dbg_disc + ql_dbg_verbose, vha, 0x20e8, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 640 | "%s %8phC %02x:%02x:%02x state %d/%d lid %x \n", |
| 641 | __func__, (void *)&wwn, e->port_id[2], e->port_id[1], |
| 642 | e->port_id[0], e->current_login_state, e->last_login_state, |
| 643 | (loop_id & 0x7fff)); |
| 644 | } |
| 645 | |
Hannes Reinecke | 1c6cacf | 2018-02-22 09:49:35 +0100 | [diff] [blame^] | 646 | spin_lock_irqsave(&vha->gnl.fcports_lock, flags); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 647 | |
| 648 | INIT_LIST_HEAD(&h); |
| 649 | fcport = tf = NULL; |
| 650 | if (!list_empty(&vha->gnl.fcports)) |
| 651 | list_splice_init(&vha->gnl.fcports, &h); |
| 652 | |
| 653 | list_for_each_entry_safe(fcport, tf, &h, gnl_entry) { |
| 654 | list_del_init(&fcport->gnl_entry); |
Hannes Reinecke | 1c6cacf | 2018-02-22 09:49:35 +0100 | [diff] [blame^] | 655 | spin_lock(&vha->hw->tgt.sess_lock); |
Quinn Tran | 6d674927 | 2017-12-28 12:33:41 -0800 | [diff] [blame] | 656 | fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE); |
Hannes Reinecke | 1c6cacf | 2018-02-22 09:49:35 +0100 | [diff] [blame^] | 657 | spin_unlock(&vha->hw->tgt.sess_lock); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 658 | ea.fcport = fcport; |
| 659 | |
| 660 | qla2x00_fcport_event_handler(vha, &ea); |
| 661 | } |
Hannes Reinecke | 1c6cacf | 2018-02-22 09:49:35 +0100 | [diff] [blame^] | 662 | spin_unlock_irqrestore(&vha->gnl.fcports_lock, flags); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 663 | |
Hannes Reinecke | 1c6cacf | 2018-02-22 09:49:35 +0100 | [diff] [blame^] | 664 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 665 | /* create new fcport if fw has knowledge of new sessions */ |
| 666 | for (i = 0; i < n; i++) { |
| 667 | port_id_t id; |
| 668 | u64 wwnn; |
| 669 | |
| 670 | e = &vha->gnl.l[i]; |
| 671 | wwn = wwn_to_u64(e->port_name); |
| 672 | |
| 673 | found = false; |
| 674 | list_for_each_entry_safe(fcport, tf, &vha->vp_fcports, list) { |
| 675 | if (!memcmp((u8 *)&wwn, fcport->port_name, |
| 676 | WWN_SIZE)) { |
| 677 | found = true; |
| 678 | break; |
| 679 | } |
| 680 | } |
| 681 | |
Quinn Tran | cf055fb | 2017-12-28 12:33:33 -0800 | [diff] [blame] | 682 | id.b.domain = e->port_id[2]; |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 683 | id.b.area = e->port_id[1]; |
Quinn Tran | cf055fb | 2017-12-28 12:33:33 -0800 | [diff] [blame] | 684 | id.b.al_pa = e->port_id[0]; |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 685 | id.b.rsvd_1 = 0; |
| 686 | |
| 687 | if (!found && wwn && !IS_SW_RESV_ADDR(id)) { |
| 688 | ql_dbg(ql_dbg_disc, vha, 0x2065, |
Quinn Tran | cf055fb | 2017-12-28 12:33:33 -0800 | [diff] [blame] | 689 | "%s %d %8phC %06x post new sess\n", |
| 690 | __func__, __LINE__, (u8 *)&wwn, id.b24); |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 691 | wwnn = wwn_to_u64(e->node_name); |
| 692 | qla24xx_post_newsess_work(vha, &id, (u8 *)&wwn, |
| 693 | (u8 *)&wwnn, NULL, FC4_TYPE_UNKNOWN); |
| 694 | } |
| 695 | } |
| 696 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 697 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
| 698 | |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 699 | sp->free(sp); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 700 | } |
| 701 | |
| 702 | int qla24xx_async_gnl(struct scsi_qla_host *vha, fc_port_t *fcport) |
| 703 | { |
| 704 | srb_t *sp; |
| 705 | struct srb_iocb *mbx; |
| 706 | int rval = QLA_FUNCTION_FAILED; |
| 707 | unsigned long flags; |
| 708 | u16 *mb; |
| 709 | |
Quinn Tran | 3dbec59 | 2017-12-28 12:33:40 -0800 | [diff] [blame] | 710 | if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT)) |
| 711 | return rval; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 712 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 713 | ql_dbg(ql_dbg_disc, vha, 0x20d9, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 714 | "Async-gnlist WWPN %8phC \n", fcport->port_name); |
| 715 | |
Hannes Reinecke | 1c6cacf | 2018-02-22 09:49:35 +0100 | [diff] [blame^] | 716 | spin_lock_irqsave(&vha->gnl.fcports_lock, flags); |
| 717 | if (!list_empty(&fcport->gnl_entry)) { |
| 718 | spin_unlock_irqrestore(&vha->gnl.fcports_lock, flags); |
| 719 | rval = QLA_SUCCESS; |
| 720 | goto done; |
| 721 | } |
| 722 | |
| 723 | spin_lock(&vha->hw->tgt.sess_lock); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 724 | fcport->disc_state = DSC_GNL; |
| 725 | fcport->last_rscn_gen = fcport->rscn_gen; |
| 726 | fcport->last_login_gen = fcport->login_gen; |
Hannes Reinecke | 1c6cacf | 2018-02-22 09:49:35 +0100 | [diff] [blame^] | 727 | spin_unlock(&vha->hw->tgt.sess_lock); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 728 | |
| 729 | list_add_tail(&fcport->gnl_entry, &vha->gnl.fcports); |
Hannes Reinecke | 1c6cacf | 2018-02-22 09:49:35 +0100 | [diff] [blame^] | 730 | spin_unlock_irqrestore(&vha->gnl.fcports_lock, flags); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 731 | |
| 732 | sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); |
| 733 | if (!sp) |
| 734 | goto done; |
Quinn Tran | 3dbec59 | 2017-12-28 12:33:40 -0800 | [diff] [blame] | 735 | |
| 736 | fcport->flags |= FCF_ASYNC_SENT; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 737 | sp->type = SRB_MB_IOCB; |
| 738 | sp->name = "gnlist"; |
| 739 | sp->gen1 = fcport->rscn_gen; |
| 740 | sp->gen2 = fcport->login_gen; |
| 741 | |
| 742 | qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha)+2); |
| 743 | |
| 744 | mb = sp->u.iocb_cmd.u.mbx.out_mb; |
| 745 | mb[0] = MBC_PORT_NODE_NAME_LIST; |
| 746 | mb[1] = BIT_2 | BIT_3; |
| 747 | mb[2] = MSW(vha->gnl.ldma); |
| 748 | mb[3] = LSW(vha->gnl.ldma); |
| 749 | mb[6] = MSW(MSD(vha->gnl.ldma)); |
| 750 | mb[7] = LSW(MSD(vha->gnl.ldma)); |
| 751 | mb[8] = vha->gnl.size; |
| 752 | mb[9] = vha->vp_idx; |
| 753 | |
| 754 | mbx = &sp->u.iocb_cmd; |
| 755 | mbx->timeout = qla2x00_async_iocb_timeout; |
| 756 | |
| 757 | sp->done = qla24xx_async_gnl_sp_done; |
| 758 | |
| 759 | rval = qla2x00_start_sp(sp); |
| 760 | if (rval != QLA_SUCCESS) |
| 761 | goto done_free_sp; |
| 762 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 763 | ql_dbg(ql_dbg_disc, vha, 0x20da, |
| 764 | "Async-%s - OUT WWPN %8phC hndl %x\n", |
| 765 | sp->name, fcport->port_name, sp->handle); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 766 | |
| 767 | return rval; |
| 768 | |
| 769 | done_free_sp: |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 770 | sp->free(sp); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 771 | fcport->flags &= ~FCF_ASYNC_SENT; |
Quinn Tran | 3dbec59 | 2017-12-28 12:33:40 -0800 | [diff] [blame] | 772 | done: |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 773 | return rval; |
| 774 | } |
| 775 | |
| 776 | int qla24xx_post_gnl_work(struct scsi_qla_host *vha, fc_port_t *fcport) |
| 777 | { |
| 778 | struct qla_work_evt *e; |
| 779 | |
| 780 | e = qla2x00_alloc_work(vha, QLA_EVT_GNL); |
| 781 | if (!e) |
| 782 | return QLA_FUNCTION_FAILED; |
| 783 | |
| 784 | e->u.fcport.fcport = fcport; |
Quinn Tran | 6d674927 | 2017-12-28 12:33:41 -0800 | [diff] [blame] | 785 | fcport->flags |= FCF_ASYNC_ACTIVE; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 786 | return qla2x00_post_work(vha, e); |
| 787 | } |
| 788 | |
| 789 | static |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 790 | void qla24xx_async_gpdb_sp_done(void *s, int res) |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 791 | { |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 792 | struct srb *sp = s; |
| 793 | struct scsi_qla_host *vha = sp->vha; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 794 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 795 | fc_port_t *fcport = sp->fcport; |
| 796 | u16 *mb = sp->u.iocb_cmd.u.mbx.in_mb; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 797 | struct event_arg ea; |
| 798 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 799 | ql_dbg(ql_dbg_disc, vha, 0x20db, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 800 | "Async done-%s res %x, WWPN %8phC mb[1]=%x mb[2]=%x \n", |
| 801 | sp->name, res, fcport->port_name, mb[1], mb[2]); |
| 802 | |
Quinn Tran | 6d674927 | 2017-12-28 12:33:41 -0800 | [diff] [blame] | 803 | fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 804 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 805 | memset(&ea, 0, sizeof(ea)); |
| 806 | ea.event = FCME_GPDB_DONE; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 807 | ea.fcport = fcport; |
| 808 | ea.sp = sp; |
| 809 | |
| 810 | qla2x00_fcport_event_handler(vha, &ea); |
| 811 | |
| 812 | dma_pool_free(ha->s_dma_pool, sp->u.iocb_cmd.u.mbx.in, |
| 813 | sp->u.iocb_cmd.u.mbx.in_dma); |
| 814 | |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 815 | sp->free(sp); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 816 | } |
| 817 | |
Duane Grigsby | a5d42f4 | 2017-06-21 13:48:41 -0700 | [diff] [blame] | 818 | static int qla24xx_post_prli_work(struct scsi_qla_host *vha, fc_port_t *fcport) |
| 819 | { |
| 820 | struct qla_work_evt *e; |
| 821 | |
| 822 | e = qla2x00_alloc_work(vha, QLA_EVT_PRLI); |
| 823 | if (!e) |
| 824 | return QLA_FUNCTION_FAILED; |
| 825 | |
| 826 | e->u.fcport.fcport = fcport; |
| 827 | |
| 828 | return qla2x00_post_work(vha, e); |
| 829 | } |
| 830 | |
| 831 | static void |
| 832 | qla2x00_async_prli_sp_done(void *ptr, int res) |
| 833 | { |
| 834 | srb_t *sp = ptr; |
| 835 | struct scsi_qla_host *vha = sp->vha; |
| 836 | struct srb_iocb *lio = &sp->u.iocb_cmd; |
| 837 | struct event_arg ea; |
| 838 | |
| 839 | ql_dbg(ql_dbg_disc, vha, 0x2129, |
| 840 | "%s %8phC res %d \n", __func__, |
| 841 | sp->fcport->port_name, res); |
| 842 | |
| 843 | sp->fcport->flags &= ~FCF_ASYNC_SENT; |
| 844 | |
| 845 | if (!test_bit(UNLOADING, &vha->dpc_flags)) { |
| 846 | memset(&ea, 0, sizeof(ea)); |
| 847 | ea.event = FCME_PRLI_DONE; |
| 848 | ea.fcport = sp->fcport; |
| 849 | ea.data[0] = lio->u.logio.data[0]; |
| 850 | ea.data[1] = lio->u.logio.data[1]; |
| 851 | ea.iop[0] = lio->u.logio.iop[0]; |
| 852 | ea.iop[1] = lio->u.logio.iop[1]; |
| 853 | ea.sp = sp; |
| 854 | |
| 855 | qla2x00_fcport_event_handler(vha, &ea); |
| 856 | } |
| 857 | |
| 858 | sp->free(sp); |
| 859 | } |
| 860 | |
| 861 | int |
| 862 | qla24xx_async_prli(struct scsi_qla_host *vha, fc_port_t *fcport) |
| 863 | { |
| 864 | srb_t *sp; |
| 865 | struct srb_iocb *lio; |
| 866 | int rval = QLA_FUNCTION_FAILED; |
| 867 | |
| 868 | if (!vha->flags.online) |
| 869 | return rval; |
| 870 | |
| 871 | if (fcport->fw_login_state == DSC_LS_PLOGI_PEND || |
| 872 | fcport->fw_login_state == DSC_LS_PLOGI_COMP || |
| 873 | fcport->fw_login_state == DSC_LS_PRLI_PEND) |
| 874 | return rval; |
| 875 | |
| 876 | sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); |
| 877 | if (!sp) |
| 878 | return rval; |
| 879 | |
| 880 | fcport->flags |= FCF_ASYNC_SENT; |
| 881 | fcport->logout_completed = 0; |
| 882 | |
| 883 | sp->type = SRB_PRLI_CMD; |
| 884 | sp->name = "prli"; |
| 885 | qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2); |
| 886 | |
| 887 | lio = &sp->u.iocb_cmd; |
| 888 | lio->timeout = qla2x00_async_iocb_timeout; |
| 889 | sp->done = qla2x00_async_prli_sp_done; |
| 890 | lio->u.logio.flags = 0; |
| 891 | |
| 892 | if (fcport->fc4f_nvme) |
| 893 | lio->u.logio.flags |= SRB_LOGIN_NVME_PRLI; |
| 894 | |
| 895 | rval = qla2x00_start_sp(sp); |
| 896 | if (rval != QLA_SUCCESS) { |
Duane Grigsby | a5d42f4 | 2017-06-21 13:48:41 -0700 | [diff] [blame] | 897 | fcport->flags |= FCF_LOGIN_NEEDED; |
| 898 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
| 899 | goto done_free_sp; |
| 900 | } |
| 901 | |
| 902 | ql_dbg(ql_dbg_disc, vha, 0x211b, |
| 903 | "Async-prli - %8phC hdl=%x, loopid=%x portid=%06x retries=%d.\n", |
| 904 | fcport->port_name, sp->handle, fcport->loop_id, |
| 905 | fcport->d_id.b24, fcport->login_retry); |
| 906 | |
| 907 | return rval; |
| 908 | |
| 909 | done_free_sp: |
| 910 | sp->free(sp); |
| 911 | fcport->flags &= ~FCF_ASYNC_SENT; |
| 912 | return rval; |
| 913 | } |
| 914 | |
Quinn Tran | a07fc0a | 2017-08-23 15:05:21 -0700 | [diff] [blame] | 915 | int qla24xx_post_gpdb_work(struct scsi_qla_host *vha, fc_port_t *fcport, u8 opt) |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 916 | { |
| 917 | struct qla_work_evt *e; |
| 918 | |
| 919 | e = qla2x00_alloc_work(vha, QLA_EVT_GPDB); |
| 920 | if (!e) |
| 921 | return QLA_FUNCTION_FAILED; |
| 922 | |
| 923 | e->u.fcport.fcport = fcport; |
| 924 | e->u.fcport.opt = opt; |
Quinn Tran | 6d674927 | 2017-12-28 12:33:41 -0800 | [diff] [blame] | 925 | fcport->flags |= FCF_ASYNC_ACTIVE; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 926 | return qla2x00_post_work(vha, e); |
| 927 | } |
| 928 | |
| 929 | int qla24xx_async_gpdb(struct scsi_qla_host *vha, fc_port_t *fcport, u8 opt) |
| 930 | { |
| 931 | srb_t *sp; |
| 932 | struct srb_iocb *mbx; |
| 933 | int rval = QLA_FUNCTION_FAILED; |
| 934 | u16 *mb; |
| 935 | dma_addr_t pd_dma; |
| 936 | struct port_database_24xx *pd; |
| 937 | struct qla_hw_data *ha = vha->hw; |
| 938 | |
Quinn Tran | 3dbec59 | 2017-12-28 12:33:40 -0800 | [diff] [blame] | 939 | if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT)) |
| 940 | return rval; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 941 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 942 | fcport->disc_state = DSC_GPDB; |
| 943 | |
| 944 | sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); |
| 945 | if (!sp) |
| 946 | goto done; |
| 947 | |
Quinn Tran | 3dbec59 | 2017-12-28 12:33:40 -0800 | [diff] [blame] | 948 | fcport->flags |= FCF_ASYNC_SENT; |
Joe Carnuccio | e0824e6 | 2017-08-23 15:05:08 -0700 | [diff] [blame] | 949 | sp->type = SRB_MB_IOCB; |
| 950 | sp->name = "gpdb"; |
| 951 | sp->gen1 = fcport->rscn_gen; |
| 952 | sp->gen2 = fcport->login_gen; |
| 953 | qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2); |
| 954 | |
Thomas Meyer | 08eb7f4 | 2017-09-21 08:15:26 +0200 | [diff] [blame] | 955 | pd = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 956 | if (pd == NULL) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 957 | ql_log(ql_log_warn, vha, 0xd043, |
| 958 | "Failed to allocate port database structure.\n"); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 959 | goto done_free_sp; |
| 960 | } |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 961 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 962 | mb = sp->u.iocb_cmd.u.mbx.out_mb; |
| 963 | mb[0] = MBC_GET_PORT_DATABASE; |
| 964 | mb[1] = fcport->loop_id; |
| 965 | mb[2] = MSW(pd_dma); |
| 966 | mb[3] = LSW(pd_dma); |
| 967 | mb[6] = MSW(MSD(pd_dma)); |
| 968 | mb[7] = LSW(MSD(pd_dma)); |
| 969 | mb[9] = vha->vp_idx; |
| 970 | mb[10] = opt; |
| 971 | |
| 972 | mbx = &sp->u.iocb_cmd; |
| 973 | mbx->timeout = qla2x00_async_iocb_timeout; |
| 974 | mbx->u.mbx.in = (void *)pd; |
| 975 | mbx->u.mbx.in_dma = pd_dma; |
| 976 | |
| 977 | sp->done = qla24xx_async_gpdb_sp_done; |
| 978 | |
| 979 | rval = qla2x00_start_sp(sp); |
| 980 | if (rval != QLA_SUCCESS) |
| 981 | goto done_free_sp; |
| 982 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 983 | ql_dbg(ql_dbg_disc, vha, 0x20dc, |
| 984 | "Async-%s %8phC hndl %x opt %x\n", |
| 985 | sp->name, fcport->port_name, sp->handle, opt); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 986 | |
| 987 | return rval; |
| 988 | |
| 989 | done_free_sp: |
| 990 | if (pd) |
| 991 | dma_pool_free(ha->s_dma_pool, pd, pd_dma); |
| 992 | |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 993 | sp->free(sp); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 994 | fcport->flags &= ~FCF_ASYNC_SENT; |
Quinn Tran | 3dbec59 | 2017-12-28 12:33:40 -0800 | [diff] [blame] | 995 | done: |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 996 | qla24xx_post_gpdb_work(vha, fcport, opt); |
| 997 | return rval; |
| 998 | } |
| 999 | |
| 1000 | static |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 1001 | void __qla24xx_handle_gpdb_event(scsi_qla_host_t *vha, struct event_arg *ea) |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1002 | { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1003 | unsigned long flags; |
| 1004 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1005 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
Quinn Tran | f13515a | 2017-12-28 12:33:15 -0800 | [diff] [blame] | 1006 | ea->fcport->login_gen++; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1007 | ea->fcport->deleted = 0; |
| 1008 | ea->fcport->logout_on_delete = 1; |
| 1009 | |
| 1010 | if (!ea->fcport->login_succ && !IS_SW_RESV_ADDR(ea->fcport->d_id)) { |
| 1011 | vha->fcport_count++; |
| 1012 | ea->fcport->login_succ = 1; |
| 1013 | |
| 1014 | if (!IS_IIDMA_CAPABLE(vha->hw) || |
| 1015 | !vha->hw->flags.gpsc_supported) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1016 | ql_dbg(ql_dbg_disc, vha, 0x20d6, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1017 | "%s %d %8phC post upd_fcport fcp_cnt %d\n", |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 1018 | __func__, __LINE__, ea->fcport->port_name, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1019 | vha->fcport_count); |
| 1020 | |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 1021 | qla24xx_post_upd_fcport_work(vha, ea->fcport); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1022 | } else { |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 1023 | if (ea->fcport->id_changed) { |
| 1024 | ea->fcport->id_changed = 0; |
| 1025 | ql_dbg(ql_dbg_disc, vha, 0x20d7, |
| 1026 | "%s %d %8phC post gfpnid fcp_cnt %d\n", |
| 1027 | __func__, __LINE__, ea->fcport->port_name, |
| 1028 | vha->fcport_count); |
| 1029 | qla24xx_post_gfpnid_work(vha, ea->fcport); |
| 1030 | } else { |
| 1031 | ql_dbg(ql_dbg_disc, vha, 0x20d7, |
| 1032 | "%s %d %8phC post gpsc fcp_cnt %d\n", |
| 1033 | __func__, __LINE__, ea->fcport->port_name, |
| 1034 | vha->fcport_count); |
| 1035 | qla24xx_post_gpsc_work(vha, ea->fcport); |
| 1036 | } |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1037 | } |
Quinn Tran | 414d9ff | 2017-12-04 14:45:03 -0800 | [diff] [blame] | 1038 | } else if (ea->fcport->login_succ) { |
| 1039 | /* |
| 1040 | * We have an existing session. A late RSCN delivery |
| 1041 | * must have triggered the session to be re-validate. |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 1042 | * Session is still valid. |
Quinn Tran | 414d9ff | 2017-12-04 14:45:03 -0800 | [diff] [blame] | 1043 | */ |
Quinn Tran | 5ef696a | 2017-12-04 14:45:05 -0800 | [diff] [blame] | 1044 | ql_dbg(ql_dbg_disc, vha, 0x20d6, |
| 1045 | "%s %d %8phC session revalidate success\n", |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 1046 | __func__, __LINE__, ea->fcport->port_name); |
himanshu.madhani@cavium.com | 8a7eac2 | 2018-01-15 20:46:50 -0800 | [diff] [blame] | 1047 | ea->fcport->disc_state = DSC_LOGIN_COMPLETE; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1048 | } |
| 1049 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 1050 | } |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1051 | |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 1052 | static |
| 1053 | void qla24xx_handle_gpdb_event(scsi_qla_host_t *vha, struct event_arg *ea) |
| 1054 | { |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 1055 | fc_port_t *fcport = ea->fcport; |
| 1056 | struct port_database_24xx *pd; |
| 1057 | struct srb *sp = ea->sp; |
| 1058 | |
| 1059 | pd = (struct port_database_24xx *)sp->u.iocb_cmd.u.mbx.in; |
| 1060 | |
| 1061 | fcport->flags &= ~FCF_ASYNC_SENT; |
| 1062 | |
| 1063 | ql_dbg(ql_dbg_disc, vha, 0x20d2, |
Quinn Tran | f352eeb | 2017-12-28 12:33:35 -0800 | [diff] [blame] | 1064 | "%s %8phC DS %d LS %d rc %d\n", __func__, fcport->port_name, |
| 1065 | fcport->disc_state, pd->current_login_state, ea->rc); |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 1066 | |
| 1067 | if (fcport->disc_state == DSC_DELETE_PEND) |
| 1068 | return; |
| 1069 | |
| 1070 | switch (pd->current_login_state) { |
| 1071 | case PDS_PRLI_COMPLETE: |
| 1072 | __qla24xx_parse_gpdb(vha, fcport, pd); |
| 1073 | break; |
| 1074 | case PDS_PLOGI_PENDING: |
| 1075 | case PDS_PLOGI_COMPLETE: |
| 1076 | case PDS_PRLI_PENDING: |
| 1077 | case PDS_PRLI2_PENDING: |
| 1078 | ql_dbg(ql_dbg_disc, vha, 0x20d5, "%s %d %8phC relogin needed\n", |
| 1079 | __func__, __LINE__, fcport->port_name); |
| 1080 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
| 1081 | return; |
| 1082 | case PDS_LOGO_PENDING: |
| 1083 | case PDS_PORT_UNAVAILABLE: |
| 1084 | default: |
| 1085 | ql_dbg(ql_dbg_disc, vha, 0x20d5, "%s %d %8phC post del sess\n", |
| 1086 | __func__, __LINE__, fcport->port_name); |
Quinn Tran | d8630bb | 2017-12-28 12:33:43 -0800 | [diff] [blame] | 1087 | qlt_schedule_sess_for_deletion(fcport); |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 1088 | return; |
| 1089 | } |
| 1090 | __qla24xx_handle_gpdb_event(vha, ea); |
| 1091 | } /* gpdb event */ |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 1092 | |
| 1093 | static void qla_chk_n2n_b4_login(struct scsi_qla_host *vha, fc_port_t *fcport) |
| 1094 | { |
| 1095 | u8 login = 0; |
Quinn Tran | 040036b | 2017-12-28 12:33:38 -0800 | [diff] [blame] | 1096 | int rc; |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 1097 | |
| 1098 | if (qla_tgt_mode_enabled(vha)) |
| 1099 | return; |
| 1100 | |
| 1101 | if (qla_dual_mode_enabled(vha)) { |
| 1102 | if (N2N_TOPO(vha->hw)) { |
| 1103 | u64 mywwn, wwn; |
| 1104 | |
| 1105 | mywwn = wwn_to_u64(vha->port_name); |
| 1106 | wwn = wwn_to_u64(fcport->port_name); |
| 1107 | if (mywwn > wwn) |
| 1108 | login = 1; |
| 1109 | else if ((fcport->fw_login_state == DSC_LS_PLOGI_COMP) |
| 1110 | && time_after_eq(jiffies, |
| 1111 | fcport->plogi_nack_done_deadline)) |
| 1112 | login = 1; |
| 1113 | } else { |
| 1114 | login = 1; |
| 1115 | } |
| 1116 | } else { |
| 1117 | /* initiator mode */ |
| 1118 | login = 1; |
| 1119 | } |
| 1120 | |
| 1121 | if (login) { |
Quinn Tran | 040036b | 2017-12-28 12:33:38 -0800 | [diff] [blame] | 1122 | if (fcport->loop_id == FC_NO_LOOP_ID) { |
| 1123 | fcport->fw_login_state = DSC_LS_PORT_UNAVAIL; |
| 1124 | rc = qla2x00_find_new_loop_id(vha, fcport); |
| 1125 | if (rc) { |
| 1126 | ql_dbg(ql_dbg_disc, vha, 0x20e6, |
| 1127 | "%s %d %8phC post del sess - out of loopid\n", |
| 1128 | __func__, __LINE__, fcport->port_name); |
| 1129 | fcport->scan_state = 0; |
Quinn Tran | 94cff6e | 2017-12-28 12:33:42 -0800 | [diff] [blame] | 1130 | qlt_schedule_sess_for_deletion(fcport); |
Quinn Tran | 040036b | 2017-12-28 12:33:38 -0800 | [diff] [blame] | 1131 | return; |
| 1132 | } |
| 1133 | } |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 1134 | ql_dbg(ql_dbg_disc, vha, 0x20bf, |
| 1135 | "%s %d %8phC post login\n", |
| 1136 | __func__, __LINE__, fcport->port_name); |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 1137 | qla2x00_post_async_login_work(vha, fcport, NULL); |
| 1138 | } |
| 1139 | } |
| 1140 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1141 | int qla24xx_fcport_handle_login(struct scsi_qla_host *vha, fc_port_t *fcport) |
| 1142 | { |
Quinn Tran | f13515a | 2017-12-28 12:33:15 -0800 | [diff] [blame] | 1143 | u16 data[2]; |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 1144 | u64 wwn; |
| 1145 | |
| 1146 | ql_dbg(ql_dbg_disc, vha, 0x20d8, |
Quinn Tran | f352eeb | 2017-12-28 12:33:35 -0800 | [diff] [blame] | 1147 | "%s %8phC DS %d LS %d P %d fl %x confl %p rscn %d|%d login %d retry %d lid %d scan %d\n", |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 1148 | __func__, fcport->port_name, fcport->disc_state, |
| 1149 | fcport->fw_login_state, fcport->login_pause, fcport->flags, |
| 1150 | fcport->conflict, fcport->last_rscn_gen, fcport->rscn_gen, |
Quinn Tran | f352eeb | 2017-12-28 12:33:35 -0800 | [diff] [blame] | 1151 | fcport->login_gen, fcport->login_retry, |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 1152 | fcport->loop_id, fcport->scan_state); |
| 1153 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1154 | if (fcport->login_retry == 0) |
| 1155 | return 0; |
| 1156 | |
| 1157 | if (fcport->scan_state != QLA_FCPORT_FOUND) |
| 1158 | return 0; |
| 1159 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1160 | if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) || |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1161 | (fcport->fw_login_state == DSC_LS_PRLI_PEND)) |
| 1162 | return 0; |
| 1163 | |
Quinn Tran | 5b33469 | 2017-03-15 09:48:48 -0700 | [diff] [blame] | 1164 | if (fcport->fw_login_state == DSC_LS_PLOGI_COMP) { |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 1165 | if (time_before_eq(jiffies, fcport->plogi_nack_done_deadline)) { |
| 1166 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
Quinn Tran | 5b33469 | 2017-03-15 09:48:48 -0700 | [diff] [blame] | 1167 | return 0; |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 1168 | } |
Quinn Tran | 5b33469 | 2017-03-15 09:48:48 -0700 | [diff] [blame] | 1169 | } |
| 1170 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1171 | /* for pure Target Mode. Login will not be initiated */ |
| 1172 | if (vha->host->active_mode == MODE_TARGET) |
| 1173 | return 0; |
| 1174 | |
| 1175 | if (fcport->flags & FCF_ASYNC_SENT) { |
| 1176 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
| 1177 | return 0; |
| 1178 | } |
| 1179 | |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 1180 | fcport->login_retry--; |
| 1181 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1182 | switch (fcport->disc_state) { |
| 1183 | case DSC_DELETED: |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 1184 | wwn = wwn_to_u64(fcport->node_name); |
| 1185 | if (wwn == 0) { |
| 1186 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 1187 | "%s %d %8phC post GNNID\n", |
| 1188 | __func__, __LINE__, fcport->port_name); |
| 1189 | qla24xx_post_gnnid_work(vha, fcport); |
| 1190 | } else if (fcport->loop_id == FC_NO_LOOP_ID) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1191 | ql_dbg(ql_dbg_disc, vha, 0x20bd, |
| 1192 | "%s %d %8phC post gnl\n", |
| 1193 | __func__, __LINE__, fcport->port_name); |
Giridhar Malavali | 5d3300a | 2017-12-04 14:45:13 -0800 | [diff] [blame] | 1194 | qla24xx_post_gnl_work(vha, fcport); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1195 | } else { |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 1196 | qla_chk_n2n_b4_login(vha, fcport); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1197 | } |
| 1198 | break; |
| 1199 | |
| 1200 | case DSC_GNL: |
| 1201 | if (fcport->login_pause) { |
| 1202 | fcport->last_rscn_gen = fcport->rscn_gen; |
| 1203 | fcport->last_login_gen = fcport->login_gen; |
| 1204 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
| 1205 | break; |
| 1206 | } |
| 1207 | |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 1208 | qla_chk_n2n_b4_login(vha, fcport); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1209 | break; |
| 1210 | |
| 1211 | case DSC_LOGIN_FAILED: |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1212 | ql_dbg(ql_dbg_disc, vha, 0x20d0, |
| 1213 | "%s %d %8phC post gidpn\n", |
| 1214 | __func__, __LINE__, fcport->port_name); |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 1215 | if (N2N_TOPO(vha->hw)) |
| 1216 | qla_chk_n2n_b4_login(vha, fcport); |
| 1217 | else |
| 1218 | qla24xx_post_gidpn_work(vha, fcport); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1219 | break; |
| 1220 | |
| 1221 | case DSC_LOGIN_COMPLETE: |
| 1222 | /* recheck login state */ |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1223 | ql_dbg(ql_dbg_disc, vha, 0x20d1, |
Quinn Tran | f13515a | 2017-12-28 12:33:15 -0800 | [diff] [blame] | 1224 | "%s %d %8phC post adisc\n", |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1225 | __func__, __LINE__, fcport->port_name); |
Quinn Tran | f13515a | 2017-12-28 12:33:15 -0800 | [diff] [blame] | 1226 | data[0] = data[1] = 0; |
| 1227 | qla2x00_post_async_adisc_work(vha, fcport, data); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1228 | break; |
| 1229 | |
| 1230 | default: |
| 1231 | break; |
| 1232 | } |
| 1233 | |
| 1234 | return 0; |
| 1235 | } |
| 1236 | |
| 1237 | static |
| 1238 | void qla24xx_handle_rscn_event(fc_port_t *fcport, struct event_arg *ea) |
| 1239 | { |
| 1240 | fcport->rscn_gen++; |
| 1241 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1242 | ql_dbg(ql_dbg_disc, fcport->vha, 0x210c, |
| 1243 | "%s %8phC DS %d LS %d\n", |
| 1244 | __func__, fcport->port_name, fcport->disc_state, |
| 1245 | fcport->fw_login_state); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1246 | |
| 1247 | if (fcport->flags & FCF_ASYNC_SENT) |
| 1248 | return; |
| 1249 | |
| 1250 | switch (fcport->disc_state) { |
| 1251 | case DSC_DELETED: |
| 1252 | case DSC_LOGIN_COMPLETE: |
Quinn Tran | 5ef696a | 2017-12-04 14:45:05 -0800 | [diff] [blame] | 1253 | qla24xx_post_gpnid_work(fcport->vha, &ea->id); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1254 | break; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1255 | default: |
| 1256 | break; |
| 1257 | } |
| 1258 | } |
| 1259 | |
| 1260 | int qla24xx_post_newsess_work(struct scsi_qla_host *vha, port_id_t *id, |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 1261 | u8 *port_name, u8 *node_name, void *pla, u8 fc4_type) |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1262 | { |
| 1263 | struct qla_work_evt *e; |
| 1264 | e = qla2x00_alloc_work(vha, QLA_EVT_NEW_SESS); |
| 1265 | if (!e) |
| 1266 | return QLA_FUNCTION_FAILED; |
| 1267 | |
| 1268 | e->u.new_sess.id = *id; |
| 1269 | e->u.new_sess.pla = pla; |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 1270 | e->u.new_sess.fc4_type = fc4_type; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1271 | memcpy(e->u.new_sess.port_name, port_name, WWN_SIZE); |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 1272 | if (node_name) |
| 1273 | memcpy(e->u.new_sess.node_name, node_name, WWN_SIZE); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1274 | |
| 1275 | return qla2x00_post_work(vha, e); |
| 1276 | } |
| 1277 | |
| 1278 | static |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1279 | void qla24xx_handle_relogin_event(scsi_qla_host_t *vha, |
| 1280 | struct event_arg *ea) |
| 1281 | { |
| 1282 | fc_port_t *fcport = ea->fcport; |
| 1283 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1284 | ql_dbg(ql_dbg_disc, vha, 0x2102, |
| 1285 | "%s %8phC DS %d LS %d P %d del %d cnfl %p rscn %d|%d login %d|%d fl %x\n", |
| 1286 | __func__, fcport->port_name, fcport->disc_state, |
| 1287 | fcport->fw_login_state, fcport->login_pause, |
| 1288 | fcport->deleted, fcport->conflict, |
| 1289 | fcport->last_rscn_gen, fcport->rscn_gen, |
| 1290 | fcport->last_login_gen, fcport->login_gen, |
| 1291 | fcport->flags); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1292 | |
| 1293 | if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) || |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1294 | (fcport->fw_login_state == DSC_LS_PRLI_PEND)) |
| 1295 | return; |
| 1296 | |
Quinn Tran | 5b33469 | 2017-03-15 09:48:48 -0700 | [diff] [blame] | 1297 | if (fcport->fw_login_state == DSC_LS_PLOGI_COMP) { |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 1298 | if (time_before_eq(jiffies, fcport->plogi_nack_done_deadline)) { |
| 1299 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
Quinn Tran | 5b33469 | 2017-03-15 09:48:48 -0700 | [diff] [blame] | 1300 | return; |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 1301 | } |
Quinn Tran | 5b33469 | 2017-03-15 09:48:48 -0700 | [diff] [blame] | 1302 | } |
| 1303 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1304 | if (fcport->flags & FCF_ASYNC_SENT) { |
| 1305 | fcport->login_retry++; |
| 1306 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
| 1307 | return; |
| 1308 | } |
| 1309 | |
| 1310 | if (fcport->disc_state == DSC_DELETE_PEND) { |
| 1311 | fcport->login_retry++; |
| 1312 | return; |
| 1313 | } |
| 1314 | |
| 1315 | if (fcport->last_rscn_gen != fcport->rscn_gen) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1316 | ql_dbg(ql_dbg_disc, vha, 0x20e9, "%s %d %8phC post gidpn\n", |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1317 | __func__, __LINE__, fcport->port_name); |
| 1318 | |
Giridhar Malavali | 5d3300a | 2017-12-04 14:45:13 -0800 | [diff] [blame] | 1319 | qla24xx_post_gidpn_work(vha, fcport); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1320 | return; |
| 1321 | } |
| 1322 | |
| 1323 | qla24xx_fcport_handle_login(vha, fcport); |
| 1324 | } |
| 1325 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 1326 | void qla2x00_fcport_event_handler(scsi_qla_host_t *vha, struct event_arg *ea) |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1327 | { |
Quinn Tran | f352eeb | 2017-12-28 12:33:35 -0800 | [diff] [blame] | 1328 | fc_port_t *f, *tf; |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 1329 | uint32_t id = 0, mask, rid; |
Quinn Tran | f352eeb | 2017-12-28 12:33:35 -0800 | [diff] [blame] | 1330 | unsigned long flags; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1331 | |
| 1332 | switch (ea->event) { |
Quinn Tran | b98ae0d | 2017-06-02 09:12:00 -0700 | [diff] [blame] | 1333 | case FCME_RSCN: |
| 1334 | case FCME_GIDPN_DONE: |
| 1335 | case FCME_GPSC_DONE: |
| 1336 | case FCME_GPNID_DONE: |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 1337 | case FCME_GNNID_DONE: |
Quinn Tran | b98ae0d | 2017-06-02 09:12:00 -0700 | [diff] [blame] | 1338 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) || |
| 1339 | test_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags)) |
| 1340 | return; |
| 1341 | break; |
| 1342 | default: |
| 1343 | break; |
| 1344 | } |
| 1345 | |
| 1346 | switch (ea->event) { |
| 1347 | case FCME_RELOGIN: |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1348 | if (test_bit(UNLOADING, &vha->dpc_flags)) |
| 1349 | return; |
| 1350 | |
| 1351 | qla24xx_handle_relogin_event(vha, ea); |
| 1352 | break; |
| 1353 | case FCME_RSCN: |
| 1354 | if (test_bit(UNLOADING, &vha->dpc_flags)) |
| 1355 | return; |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 1356 | switch (ea->id.b.rsvd_1) { |
| 1357 | case RSCN_PORT_ADDR: |
Quinn Tran | f352eeb | 2017-12-28 12:33:35 -0800 | [diff] [blame] | 1358 | spin_lock_irqsave(&vha->work_lock, flags); |
| 1359 | if (vha->scan.scan_flags == 0) { |
| 1360 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 1361 | "%s: schedule\n", __func__); |
| 1362 | vha->scan.scan_flags |= SF_QUEUED; |
| 1363 | schedule_delayed_work(&vha->scan.scan_work, 5); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1364 | } |
Quinn Tran | f352eeb | 2017-12-28 12:33:35 -0800 | [diff] [blame] | 1365 | spin_unlock_irqrestore(&vha->work_lock, flags); |
| 1366 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 1367 | break; |
| 1368 | case RSCN_AREA_ADDR: |
| 1369 | case RSCN_DOM_ADDR: |
| 1370 | if (ea->id.b.rsvd_1 == RSCN_AREA_ADDR) { |
| 1371 | mask = 0xffff00; |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1372 | ql_dbg(ql_dbg_async, vha, 0x5044, |
| 1373 | "RSCN: Area 0x%06x was affected\n", |
| 1374 | ea->id.b24); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 1375 | } else { |
| 1376 | mask = 0xff0000; |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1377 | ql_dbg(ql_dbg_async, vha, 0x507a, |
| 1378 | "RSCN: Domain 0x%06x was affected\n", |
| 1379 | ea->id.b24); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 1380 | } |
| 1381 | |
| 1382 | rid = ea->id.b24 & mask; |
| 1383 | list_for_each_entry_safe(f, tf, &vha->vp_fcports, |
| 1384 | list) { |
| 1385 | id = f->d_id.b24 & mask; |
| 1386 | if (rid == id) { |
| 1387 | ea->fcport = f; |
| 1388 | qla24xx_handle_rscn_event(f, ea); |
| 1389 | } |
| 1390 | } |
| 1391 | break; |
| 1392 | case RSCN_FAB_ADDR: |
| 1393 | default: |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1394 | ql_log(ql_log_warn, vha, 0xd045, |
| 1395 | "RSCN: Fabric was affected. Addr format %d\n", |
| 1396 | ea->id.b.rsvd_1); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 1397 | qla2x00_mark_all_devices_lost(vha, 1); |
| 1398 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
| 1399 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1400 | } |
| 1401 | break; |
| 1402 | case FCME_GIDPN_DONE: |
| 1403 | qla24xx_handle_gidpn_event(vha, ea); |
| 1404 | break; |
| 1405 | case FCME_GNL_DONE: |
| 1406 | qla24xx_handle_gnl_done_event(vha, ea); |
| 1407 | break; |
| 1408 | case FCME_GPSC_DONE: |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 1409 | qla24xx_handle_gpsc_event(vha, ea); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1410 | break; |
| 1411 | case FCME_PLOGI_DONE: /* Initiator side sent LLIOCB */ |
| 1412 | qla24xx_handle_plogi_done_event(vha, ea); |
| 1413 | break; |
Duane Grigsby | a5d42f4 | 2017-06-21 13:48:41 -0700 | [diff] [blame] | 1414 | case FCME_PRLI_DONE: |
| 1415 | qla24xx_handle_prli_done_event(vha, ea); |
| 1416 | break; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1417 | case FCME_GPDB_DONE: |
| 1418 | qla24xx_handle_gpdb_event(vha, ea); |
| 1419 | break; |
| 1420 | case FCME_GPNID_DONE: |
| 1421 | qla24xx_handle_gpnid_event(vha, ea); |
| 1422 | break; |
Duane Grigsby | d3bae93 | 2017-06-21 13:48:44 -0700 | [diff] [blame] | 1423 | case FCME_GFFID_DONE: |
| 1424 | qla24xx_handle_gffid_event(vha, ea); |
| 1425 | break; |
Quinn Tran | f13515a | 2017-12-28 12:33:15 -0800 | [diff] [blame] | 1426 | case FCME_ADISC_DONE: |
| 1427 | qla24xx_handle_adisc_event(vha, ea); |
| 1428 | break; |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 1429 | case FCME_GNNID_DONE: |
| 1430 | qla24xx_handle_gnnid_event(vha, ea); |
| 1431 | break; |
| 1432 | case FCME_GFPNID_DONE: |
| 1433 | qla24xx_handle_gfpnid_event(vha, ea); |
| 1434 | break; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1435 | default: |
| 1436 | BUG_ON(1); |
| 1437 | break; |
| 1438 | } |
| 1439 | } |
| 1440 | |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 1441 | static void |
Armen Baloyan | faef62d | 2014-02-26 04:15:17 -0500 | [diff] [blame] | 1442 | qla2x00_tmf_iocb_timeout(void *data) |
| 1443 | { |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 1444 | srb_t *sp = data; |
Armen Baloyan | faef62d | 2014-02-26 04:15:17 -0500 | [diff] [blame] | 1445 | struct srb_iocb *tmf = &sp->u.iocb_cmd; |
| 1446 | |
| 1447 | tmf->u.tmf.comp_status = CS_TIMEOUT; |
| 1448 | complete(&tmf->u.tmf.comp); |
| 1449 | } |
| 1450 | |
| 1451 | static void |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 1452 | qla2x00_tmf_sp_done(void *ptr, int res) |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 1453 | { |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 1454 | srb_t *sp = ptr; |
Armen Baloyan | faef62d | 2014-02-26 04:15:17 -0500 | [diff] [blame] | 1455 | struct srb_iocb *tmf = &sp->u.iocb_cmd; |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 1456 | |
Armen Baloyan | faef62d | 2014-02-26 04:15:17 -0500 | [diff] [blame] | 1457 | complete(&tmf->u.tmf.comp); |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 1458 | } |
| 1459 | |
| 1460 | int |
Armen Baloyan | faef62d | 2014-02-26 04:15:17 -0500 | [diff] [blame] | 1461 | qla2x00_async_tm_cmd(fc_port_t *fcport, uint32_t flags, uint32_t lun, |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 1462 | uint32_t tag) |
| 1463 | { |
| 1464 | struct scsi_qla_host *vha = fcport->vha; |
Armen Baloyan | faef62d | 2014-02-26 04:15:17 -0500 | [diff] [blame] | 1465 | struct srb_iocb *tm_iocb; |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 1466 | srb_t *sp; |
Armen Baloyan | faef62d | 2014-02-26 04:15:17 -0500 | [diff] [blame] | 1467 | int rval = QLA_FUNCTION_FAILED; |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 1468 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 1469 | sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 1470 | if (!sp) |
| 1471 | goto done; |
| 1472 | |
Armen Baloyan | faef62d | 2014-02-26 04:15:17 -0500 | [diff] [blame] | 1473 | tm_iocb = &sp->u.iocb_cmd; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 1474 | sp->type = SRB_TM_CMD; |
| 1475 | sp->name = "tmf"; |
Armen Baloyan | faef62d | 2014-02-26 04:15:17 -0500 | [diff] [blame] | 1476 | qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha)); |
| 1477 | tm_iocb->u.tmf.flags = flags; |
| 1478 | tm_iocb->u.tmf.lun = lun; |
| 1479 | tm_iocb->u.tmf.data = tag; |
| 1480 | sp->done = qla2x00_tmf_sp_done; |
| 1481 | tm_iocb->timeout = qla2x00_tmf_iocb_timeout; |
| 1482 | init_completion(&tm_iocb->u.tmf.comp); |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 1483 | |
| 1484 | rval = qla2x00_start_sp(sp); |
| 1485 | if (rval != QLA_SUCCESS) |
| 1486 | goto done_free_sp; |
| 1487 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1488 | ql_dbg(ql_dbg_taskm, vha, 0x802f, |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 1489 | "Async-tmf hdl=%x loop-id=%x portid=%02x%02x%02x.\n", |
| 1490 | sp->handle, fcport->loop_id, fcport->d_id.b.domain, |
| 1491 | fcport->d_id.b.area, fcport->d_id.b.al_pa); |
Armen Baloyan | faef62d | 2014-02-26 04:15:17 -0500 | [diff] [blame] | 1492 | |
| 1493 | wait_for_completion(&tm_iocb->u.tmf.comp); |
| 1494 | |
| 1495 | rval = tm_iocb->u.tmf.comp_status == CS_COMPLETE ? |
| 1496 | QLA_SUCCESS : QLA_FUNCTION_FAILED; |
| 1497 | |
| 1498 | if ((rval != QLA_SUCCESS) || tm_iocb->u.tmf.data) { |
| 1499 | ql_dbg(ql_dbg_taskm, vha, 0x8030, |
| 1500 | "TM IOCB failed (%x).\n", rval); |
| 1501 | } |
| 1502 | |
| 1503 | if (!test_bit(UNLOADING, &vha->dpc_flags) && !IS_QLAFX00(vha->hw)) { |
| 1504 | flags = tm_iocb->u.tmf.flags; |
| 1505 | lun = (uint16_t)tm_iocb->u.tmf.lun; |
| 1506 | |
| 1507 | /* Issue Marker IOCB */ |
| 1508 | qla2x00_marker(vha, vha->hw->req_q_map[0], |
| 1509 | vha->hw->rsp_q_map[0], sp->fcport->loop_id, lun, |
| 1510 | flags == TCF_LUN_RESET ? MK_SYNC_ID_LUN : MK_SYNC_ID); |
| 1511 | } |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 1512 | |
| 1513 | done_free_sp: |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 1514 | sp->free(sp); |
Quinn Tran | 6d674927 | 2017-12-28 12:33:41 -0800 | [diff] [blame] | 1515 | sp->fcport->flags &= ~FCF_ASYNC_SENT; |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 1516 | done: |
| 1517 | return rval; |
| 1518 | } |
| 1519 | |
Armen Baloyan | 4440e46 | 2014-02-26 04:15:18 -0500 | [diff] [blame] | 1520 | static void |
| 1521 | qla24xx_abort_iocb_timeout(void *data) |
| 1522 | { |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 1523 | srb_t *sp = data; |
Armen Baloyan | 4440e46 | 2014-02-26 04:15:18 -0500 | [diff] [blame] | 1524 | struct srb_iocb *abt = &sp->u.iocb_cmd; |
| 1525 | |
| 1526 | abt->u.abt.comp_status = CS_TIMEOUT; |
| 1527 | complete(&abt->u.abt.comp); |
| 1528 | } |
| 1529 | |
| 1530 | static void |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 1531 | qla24xx_abort_sp_done(void *ptr, int res) |
Armen Baloyan | 4440e46 | 2014-02-26 04:15:18 -0500 | [diff] [blame] | 1532 | { |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 1533 | srb_t *sp = ptr; |
Armen Baloyan | 4440e46 | 2014-02-26 04:15:18 -0500 | [diff] [blame] | 1534 | struct srb_iocb *abt = &sp->u.iocb_cmd; |
| 1535 | |
himanshu.madhani@cavium.com | 1514839 | 2018-02-12 10:28:14 -0800 | [diff] [blame] | 1536 | del_timer(&sp->u.iocb_cmd.timer); |
Armen Baloyan | 4440e46 | 2014-02-26 04:15:18 -0500 | [diff] [blame] | 1537 | complete(&abt->u.abt.comp); |
| 1538 | } |
| 1539 | |
Quinn Tran | 15f30a5 | 2017-03-15 09:48:52 -0700 | [diff] [blame] | 1540 | int |
Armen Baloyan | 4440e46 | 2014-02-26 04:15:18 -0500 | [diff] [blame] | 1541 | qla24xx_async_abort_cmd(srb_t *cmd_sp) |
| 1542 | { |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 1543 | scsi_qla_host_t *vha = cmd_sp->vha; |
Armen Baloyan | 4440e46 | 2014-02-26 04:15:18 -0500 | [diff] [blame] | 1544 | fc_port_t *fcport = cmd_sp->fcport; |
| 1545 | struct srb_iocb *abt_iocb; |
| 1546 | srb_t *sp; |
| 1547 | int rval = QLA_FUNCTION_FAILED; |
| 1548 | |
| 1549 | sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); |
| 1550 | if (!sp) |
| 1551 | goto done; |
| 1552 | |
| 1553 | abt_iocb = &sp->u.iocb_cmd; |
| 1554 | sp->type = SRB_ABT_CMD; |
| 1555 | sp->name = "abort"; |
| 1556 | qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha)); |
| 1557 | abt_iocb->u.abt.cmd_hndl = cmd_sp->handle; |
Darren Trapp | b027a5a | 2018-01-15 20:46:51 -0800 | [diff] [blame] | 1558 | |
| 1559 | if (vha->flags.qpairs_available && cmd_sp->qpair) |
| 1560 | abt_iocb->u.abt.req_que_no = |
| 1561 | cpu_to_le16(cmd_sp->qpair->req->id); |
| 1562 | else |
| 1563 | abt_iocb->u.abt.req_que_no = cpu_to_le16(vha->req->id); |
| 1564 | |
Armen Baloyan | 4440e46 | 2014-02-26 04:15:18 -0500 | [diff] [blame] | 1565 | sp->done = qla24xx_abort_sp_done; |
| 1566 | abt_iocb->timeout = qla24xx_abort_iocb_timeout; |
| 1567 | init_completion(&abt_iocb->u.abt.comp); |
| 1568 | |
| 1569 | rval = qla2x00_start_sp(sp); |
| 1570 | if (rval != QLA_SUCCESS) |
| 1571 | goto done_free_sp; |
| 1572 | |
| 1573 | ql_dbg(ql_dbg_async, vha, 0x507c, |
| 1574 | "Abort command issued - hdl=%x, target_id=%x\n", |
| 1575 | cmd_sp->handle, fcport->tgt_id); |
| 1576 | |
| 1577 | wait_for_completion(&abt_iocb->u.abt.comp); |
| 1578 | |
| 1579 | rval = abt_iocb->u.abt.comp_status == CS_COMPLETE ? |
| 1580 | QLA_SUCCESS : QLA_FUNCTION_FAILED; |
| 1581 | |
| 1582 | done_free_sp: |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 1583 | sp->free(sp); |
Armen Baloyan | 4440e46 | 2014-02-26 04:15:18 -0500 | [diff] [blame] | 1584 | done: |
| 1585 | return rval; |
| 1586 | } |
| 1587 | |
| 1588 | int |
| 1589 | qla24xx_async_abort_command(srb_t *sp) |
| 1590 | { |
| 1591 | unsigned long flags = 0; |
| 1592 | |
| 1593 | uint32_t handle; |
| 1594 | fc_port_t *fcport = sp->fcport; |
| 1595 | struct scsi_qla_host *vha = fcport->vha; |
| 1596 | struct qla_hw_data *ha = vha->hw; |
| 1597 | struct req_que *req = vha->req; |
| 1598 | |
Darren Trapp | b027a5a | 2018-01-15 20:46:51 -0800 | [diff] [blame] | 1599 | if (vha->flags.qpairs_available && sp->qpair) |
| 1600 | req = sp->qpair->req; |
| 1601 | |
Armen Baloyan | 4440e46 | 2014-02-26 04:15:18 -0500 | [diff] [blame] | 1602 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1603 | for (handle = 1; handle < req->num_outstanding_cmds; handle++) { |
| 1604 | if (req->outstanding_cmds[handle] == sp) |
| 1605 | break; |
| 1606 | } |
| 1607 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1608 | if (handle == req->num_outstanding_cmds) { |
| 1609 | /* Command not found. */ |
| 1610 | return QLA_FUNCTION_FAILED; |
| 1611 | } |
| 1612 | if (sp->type == SRB_FXIOCB_DCMD) |
| 1613 | return qlafx00_fx_disc(vha, &vha->hw->mr.fcport, |
| 1614 | FXDISC_ABORT_IOCTL); |
| 1615 | |
| 1616 | return qla24xx_async_abort_cmd(sp); |
| 1617 | } |
| 1618 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1619 | static void |
Duane Grigsby | a5d42f4 | 2017-06-21 13:48:41 -0700 | [diff] [blame] | 1620 | qla24xx_handle_prli_done_event(struct scsi_qla_host *vha, struct event_arg *ea) |
| 1621 | { |
| 1622 | switch (ea->data[0]) { |
| 1623 | case MBS_COMMAND_COMPLETE: |
| 1624 | ql_dbg(ql_dbg_disc, vha, 0x2118, |
| 1625 | "%s %d %8phC post gpdb\n", |
| 1626 | __func__, __LINE__, ea->fcport->port_name); |
| 1627 | |
| 1628 | ea->fcport->chip_reset = vha->hw->base_qpair->chip_reset; |
| 1629 | ea->fcport->logout_on_delete = 1; |
| 1630 | qla24xx_post_gpdb_work(vha, ea->fcport, 0); |
| 1631 | break; |
| 1632 | default: |
Duane Grigsby | edd05de | 2017-10-13 09:34:06 -0700 | [diff] [blame] | 1633 | if (ea->fcport->n2n_flag) { |
| 1634 | ql_dbg(ql_dbg_disc, vha, 0x2118, |
| 1635 | "%s %d %8phC post fc4 prli\n", |
| 1636 | __func__, __LINE__, ea->fcport->port_name); |
| 1637 | ea->fcport->fc4f_nvme = 0; |
| 1638 | ea->fcport->n2n_flag = 0; |
| 1639 | qla24xx_post_prli_work(vha, ea->fcport); |
| 1640 | } |
Duane Grigsby | a5d42f4 | 2017-06-21 13:48:41 -0700 | [diff] [blame] | 1641 | ql_dbg(ql_dbg_disc, vha, 0x2119, |
| 1642 | "%s %d %8phC unhandle event of %x\n", |
| 1643 | __func__, __LINE__, ea->fcport->port_name, ea->data[0]); |
| 1644 | break; |
| 1645 | } |
| 1646 | } |
| 1647 | |
| 1648 | static void |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1649 | qla24xx_handle_plogi_done_event(struct scsi_qla_host *vha, struct event_arg *ea) |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1650 | { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1651 | port_id_t cid; /* conflict Nport id */ |
Quinn Tran | a084fd6 | 2017-12-04 14:45:00 -0800 | [diff] [blame] | 1652 | u16 lid; |
| 1653 | struct fc_port *conflict_fcport; |
Quinn Tran | 82abdca | 2017-12-28 12:33:22 -0800 | [diff] [blame] | 1654 | unsigned long flags; |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 1655 | struct fc_port *fcport = ea->fcport; |
| 1656 | |
Quinn Tran | f352eeb | 2017-12-28 12:33:35 -0800 | [diff] [blame] | 1657 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 1658 | "%s %8phC DS %d LS %d rc %d login %d|%d rscn %d|%d data %x|%x iop %x|%x\n", |
| 1659 | __func__, fcport->port_name, fcport->disc_state, |
| 1660 | fcport->fw_login_state, ea->rc, ea->sp->gen2, fcport->login_gen, |
| 1661 | ea->sp->gen2, fcport->rscn_gen|ea->sp->gen1, |
| 1662 | ea->data[0], ea->data[1], ea->iop[0], ea->iop[1]); |
| 1663 | |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 1664 | if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) || |
| 1665 | (fcport->fw_login_state == DSC_LS_PRLI_PEND)) { |
| 1666 | ql_dbg(ql_dbg_disc, vha, 0x20ea, |
| 1667 | "%s %d %8phC Remote is trying to login\n", |
| 1668 | __func__, __LINE__, fcport->port_name); |
| 1669 | return; |
| 1670 | } |
| 1671 | |
| 1672 | if (fcport->disc_state == DSC_DELETE_PEND) |
| 1673 | return; |
| 1674 | |
| 1675 | if (ea->sp->gen2 != fcport->login_gen) { |
| 1676 | /* target side must have changed it. */ |
| 1677 | ql_dbg(ql_dbg_disc, vha, 0x20d3, |
Quinn Tran | f352eeb | 2017-12-28 12:33:35 -0800 | [diff] [blame] | 1678 | "%s %8phC generation changed\n", |
| 1679 | __func__, fcport->port_name); |
| 1680 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 1681 | return; |
| 1682 | } else if (ea->sp->gen1 != fcport->rscn_gen) { |
| 1683 | ql_dbg(ql_dbg_disc, vha, 0x20d4, "%s %d %8phC post gidpn\n", |
| 1684 | __func__, __LINE__, fcport->port_name); |
| 1685 | qla24xx_post_gidpn_work(vha, fcport); |
| 1686 | return; |
| 1687 | } |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1688 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1689 | switch (ea->data[0]) { |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1690 | case MBS_COMMAND_COMPLETE: |
Andrew Vasquez | a4f92a3 | 2011-03-30 11:46:31 -0700 | [diff] [blame] | 1691 | /* |
| 1692 | * Driver must validate login state - If PRLI not complete, |
| 1693 | * force a relogin attempt via implicit LOGO, PLOGI, and PRLI |
| 1694 | * requests. |
| 1695 | */ |
Duane Grigsby | a5d42f4 | 2017-06-21 13:48:41 -0700 | [diff] [blame] | 1696 | if (ea->fcport->fc4f_nvme) { |
| 1697 | ql_dbg(ql_dbg_disc, vha, 0x2117, |
| 1698 | "%s %d %8phC post prli\n", |
| 1699 | __func__, __LINE__, ea->fcport->port_name); |
| 1700 | qla24xx_post_prli_work(vha, ea->fcport); |
| 1701 | } else { |
| 1702 | ql_dbg(ql_dbg_disc, vha, 0x20ea, |
Quinn Tran | a084fd6 | 2017-12-04 14:45:00 -0800 | [diff] [blame] | 1703 | "%s %d %8phC LoopID 0x%x in use with %06x. post gnl\n", |
| 1704 | __func__, __LINE__, ea->fcport->port_name, |
| 1705 | ea->fcport->loop_id, ea->fcport->d_id.b24); |
| 1706 | |
| 1707 | set_bit(ea->fcport->loop_id, vha->hw->loop_id_map); |
Quinn Tran | 82abdca | 2017-12-28 12:33:22 -0800 | [diff] [blame] | 1708 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
Quinn Tran | a084fd6 | 2017-12-04 14:45:00 -0800 | [diff] [blame] | 1709 | ea->fcport->loop_id = FC_NO_LOOP_ID; |
Duane Grigsby | a5d42f4 | 2017-06-21 13:48:41 -0700 | [diff] [blame] | 1710 | ea->fcport->chip_reset = vha->hw->base_qpair->chip_reset; |
| 1711 | ea->fcport->logout_on_delete = 1; |
Quinn Tran | 3515832 | 2017-08-30 10:16:50 -0700 | [diff] [blame] | 1712 | ea->fcport->send_els_logo = 0; |
Quinn Tran | 82abdca | 2017-12-28 12:33:22 -0800 | [diff] [blame] | 1713 | ea->fcport->fw_login_state = DSC_LS_PRLI_COMP; |
| 1714 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
| 1715 | |
Duane Grigsby | a5d42f4 | 2017-06-21 13:48:41 -0700 | [diff] [blame] | 1716 | qla24xx_post_gpdb_work(vha, ea->fcport, 0); |
| 1717 | } |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1718 | break; |
| 1719 | case MBS_COMMAND_ERROR: |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1720 | ql_dbg(ql_dbg_disc, vha, 0x20eb, "%s %d %8phC cmd error %x\n", |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1721 | __func__, __LINE__, ea->fcport->port_name, ea->data[1]); |
| 1722 | |
| 1723 | ea->fcport->flags &= ~FCF_ASYNC_SENT; |
| 1724 | ea->fcport->disc_state = DSC_LOGIN_FAILED; |
| 1725 | if (ea->data[1] & QLA_LOGIO_LOGIN_RETRIED) |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1726 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
| 1727 | else |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1728 | qla2x00_mark_device_lost(vha, ea->fcport, 1, 0); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1729 | break; |
| 1730 | case MBS_LOOP_ID_USED: |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1731 | /* data[1] = IO PARAM 1 = nport ID */ |
| 1732 | cid.b.domain = (ea->iop[1] >> 16) & 0xff; |
| 1733 | cid.b.area = (ea->iop[1] >> 8) & 0xff; |
| 1734 | cid.b.al_pa = ea->iop[1] & 0xff; |
| 1735 | cid.b.rsvd_1 = 0; |
| 1736 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1737 | ql_dbg(ql_dbg_disc, vha, 0x20ec, |
| 1738 | "%s %d %8phC LoopID 0x%x in use post gnl\n", |
| 1739 | __func__, __LINE__, ea->fcport->port_name, |
| 1740 | ea->fcport->loop_id); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1741 | |
| 1742 | if (IS_SW_RESV_ADDR(cid)) { |
| 1743 | set_bit(ea->fcport->loop_id, vha->hw->loop_id_map); |
| 1744 | ea->fcport->loop_id = FC_NO_LOOP_ID; |
| 1745 | } else { |
| 1746 | qla2x00_clear_loop_id(ea->fcport); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1747 | } |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1748 | qla24xx_post_gnl_work(vha, ea->fcport); |
| 1749 | break; |
| 1750 | case MBS_PORT_ID_USED: |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1751 | ql_dbg(ql_dbg_disc, vha, 0x20ed, |
| 1752 | "%s %d %8phC NPortId %02x%02x%02x inuse post gidpn\n", |
| 1753 | __func__, __LINE__, ea->fcport->port_name, |
| 1754 | ea->fcport->d_id.b.domain, ea->fcport->d_id.b.area, |
| 1755 | ea->fcport->d_id.b.al_pa); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1756 | |
Quinn Tran | a084fd6 | 2017-12-04 14:45:00 -0800 | [diff] [blame] | 1757 | lid = ea->iop[1] & 0xffff; |
| 1758 | qlt_find_sess_invalidate_other(vha, |
| 1759 | wwn_to_u64(ea->fcport->port_name), |
| 1760 | ea->fcport->d_id, lid, &conflict_fcport); |
| 1761 | |
| 1762 | if (conflict_fcport) { |
| 1763 | /* |
| 1764 | * Another fcport share the same loop_id/nport id. |
| 1765 | * Conflict fcport needs to finish cleanup before this |
| 1766 | * fcport can proceed to login. |
| 1767 | */ |
| 1768 | conflict_fcport->conflict = ea->fcport; |
| 1769 | ea->fcport->login_pause = 1; |
| 1770 | |
| 1771 | ql_dbg(ql_dbg_disc, vha, 0x20ed, |
| 1772 | "%s %d %8phC NPortId %06x inuse with loopid 0x%x. post gidpn\n", |
| 1773 | __func__, __LINE__, ea->fcport->port_name, |
| 1774 | ea->fcport->d_id.b24, lid); |
| 1775 | qla2x00_clear_loop_id(ea->fcport); |
| 1776 | qla24xx_post_gidpn_work(vha, ea->fcport); |
| 1777 | } else { |
| 1778 | ql_dbg(ql_dbg_disc, vha, 0x20ed, |
| 1779 | "%s %d %8phC NPortId %06x inuse with loopid 0x%x. sched delete\n", |
| 1780 | __func__, __LINE__, ea->fcport->port_name, |
| 1781 | ea->fcport->d_id.b24, lid); |
| 1782 | |
| 1783 | qla2x00_clear_loop_id(ea->fcport); |
| 1784 | set_bit(lid, vha->hw->loop_id_map); |
| 1785 | ea->fcport->loop_id = lid; |
| 1786 | ea->fcport->keep_nport_handle = 0; |
Quinn Tran | 94cff6e | 2017-12-28 12:33:42 -0800 | [diff] [blame] | 1787 | qlt_schedule_sess_for_deletion(ea->fcport); |
Quinn Tran | a084fd6 | 2017-12-04 14:45:00 -0800 | [diff] [blame] | 1788 | } |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1789 | break; |
| 1790 | } |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 1791 | return; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1792 | } |
| 1793 | |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 1794 | void |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1795 | qla2x00_async_logout_done(struct scsi_qla_host *vha, fc_port_t *fcport, |
| 1796 | uint16_t *data) |
| 1797 | { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1798 | qla2x00_mark_device_lost(vha, fcport, 1, 0); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1799 | qlt_logo_completion_handler(fcport, data[0]); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1800 | fcport->login_gen++; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 1801 | return; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1802 | } |
| 1803 | |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 1804 | void |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 1805 | qla2x00_async_adisc_done(struct scsi_qla_host *vha, fc_port_t *fcport, |
| 1806 | uint16_t *data) |
| 1807 | { |
| 1808 | if (data[0] == MBS_COMMAND_COMPLETE) { |
| 1809 | qla2x00_update_fcport(vha, fcport); |
| 1810 | |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 1811 | return; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 1812 | } |
| 1813 | |
| 1814 | /* Retry login. */ |
| 1815 | fcport->flags &= ~FCF_ASYNC_SENT; |
| 1816 | if (data[1] & QLA_LOGIO_LOGIN_RETRIED) |
| 1817 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
| 1818 | else |
Andrew Vasquez | 80d7944 | 2011-03-30 11:46:17 -0700 | [diff] [blame] | 1819 | qla2x00_mark_device_lost(vha, fcport, 1, 0); |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 1820 | |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 1821 | return; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 1822 | } |
| 1823 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1824 | /****************************************************************************/ |
| 1825 | /* QLogic ISP2x00 Hardware Support Functions. */ |
| 1826 | /****************************************************************************/ |
| 1827 | |
Saurav Kashyap | fa49263 | 2012-11-21 02:40:29 -0500 | [diff] [blame] | 1828 | static int |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 1829 | qla83xx_nic_core_fw_load(scsi_qla_host_t *vha) |
| 1830 | { |
| 1831 | int rval = QLA_SUCCESS; |
| 1832 | struct qla_hw_data *ha = vha->hw; |
| 1833 | uint32_t idc_major_ver, idc_minor_ver; |
Saurav Kashyap | 711aa7f | 2012-08-22 14:21:15 -0400 | [diff] [blame] | 1834 | uint16_t config[4]; |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 1835 | |
| 1836 | qla83xx_idc_lock(vha, 0); |
| 1837 | |
| 1838 | /* SV: TODO: Assign initialization timeout from |
| 1839 | * flash-info / other param |
| 1840 | */ |
| 1841 | ha->fcoe_dev_init_timeout = QLA83XX_IDC_INITIALIZATION_TIMEOUT; |
| 1842 | ha->fcoe_reset_timeout = QLA83XX_IDC_RESET_ACK_TIMEOUT; |
| 1843 | |
| 1844 | /* Set our fcoe function presence */ |
| 1845 | if (__qla83xx_set_drv_presence(vha) != QLA_SUCCESS) { |
| 1846 | ql_dbg(ql_dbg_p3p, vha, 0xb077, |
| 1847 | "Error while setting DRV-Presence.\n"); |
| 1848 | rval = QLA_FUNCTION_FAILED; |
| 1849 | goto exit; |
| 1850 | } |
| 1851 | |
| 1852 | /* Decide the reset ownership */ |
| 1853 | qla83xx_reset_ownership(vha); |
| 1854 | |
| 1855 | /* |
| 1856 | * On first protocol driver load: |
| 1857 | * Init-Owner: Set IDC-Major-Version and Clear IDC-Lock-Recovery |
| 1858 | * register. |
| 1859 | * Others: Check compatibility with current IDC Major version. |
| 1860 | */ |
| 1861 | qla83xx_rd_reg(vha, QLA83XX_IDC_MAJOR_VERSION, &idc_major_ver); |
| 1862 | if (ha->flags.nic_core_reset_owner) { |
| 1863 | /* Set IDC Major version */ |
| 1864 | idc_major_ver = QLA83XX_SUPP_IDC_MAJOR_VERSION; |
| 1865 | qla83xx_wr_reg(vha, QLA83XX_IDC_MAJOR_VERSION, idc_major_ver); |
| 1866 | |
| 1867 | /* Clearing IDC-Lock-Recovery register */ |
| 1868 | qla83xx_wr_reg(vha, QLA83XX_IDC_LOCK_RECOVERY, 0); |
| 1869 | } else if (idc_major_ver != QLA83XX_SUPP_IDC_MAJOR_VERSION) { |
| 1870 | /* |
| 1871 | * Clear further IDC participation if we are not compatible with |
| 1872 | * the current IDC Major Version. |
| 1873 | */ |
| 1874 | ql_log(ql_log_warn, vha, 0xb07d, |
| 1875 | "Failing load, idc_major_ver=%d, expected_major_ver=%d.\n", |
| 1876 | idc_major_ver, QLA83XX_SUPP_IDC_MAJOR_VERSION); |
| 1877 | __qla83xx_clear_drv_presence(vha); |
| 1878 | rval = QLA_FUNCTION_FAILED; |
| 1879 | goto exit; |
| 1880 | } |
| 1881 | /* Each function sets its supported Minor version. */ |
| 1882 | qla83xx_rd_reg(vha, QLA83XX_IDC_MINOR_VERSION, &idc_minor_ver); |
| 1883 | idc_minor_ver |= (QLA83XX_SUPP_IDC_MINOR_VERSION << (ha->portnum * 2)); |
| 1884 | qla83xx_wr_reg(vha, QLA83XX_IDC_MINOR_VERSION, idc_minor_ver); |
| 1885 | |
Saurav Kashyap | 711aa7f | 2012-08-22 14:21:15 -0400 | [diff] [blame] | 1886 | if (ha->flags.nic_core_reset_owner) { |
| 1887 | memset(config, 0, sizeof(config)); |
| 1888 | if (!qla81xx_get_port_config(vha, config)) |
| 1889 | qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, |
| 1890 | QLA8XXX_DEV_READY); |
| 1891 | } |
| 1892 | |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 1893 | rval = qla83xx_idc_state_handler(vha); |
| 1894 | |
| 1895 | exit: |
| 1896 | qla83xx_idc_unlock(vha, 0); |
| 1897 | |
| 1898 | return rval; |
| 1899 | } |
| 1900 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1901 | /* |
| 1902 | * qla2x00_initialize_adapter |
| 1903 | * Initialize board. |
| 1904 | * |
| 1905 | * Input: |
| 1906 | * ha = adapter block pointer. |
| 1907 | * |
| 1908 | * Returns: |
| 1909 | * 0 = success |
| 1910 | */ |
| 1911 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1912 | qla2x00_initialize_adapter(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1913 | { |
| 1914 | int rval; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1915 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1916 | struct req_que *req = ha->req_q_map[0]; |
Lalit Chandivade | 2533cf6 | 2009-03-24 09:08:07 -0700 | [diff] [blame] | 1917 | |
Joe Carnuccio | fc90ada | 2016-07-06 11:14:23 -0400 | [diff] [blame] | 1918 | memset(&vha->qla_stats, 0, sizeof(vha->qla_stats)); |
| 1919 | memset(&vha->fc_host_stat, 0, sizeof(vha->fc_host_stat)); |
| 1920 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1921 | /* Clear adapter flags. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1922 | vha->flags.online = 0; |
Lalit Chandivade | 2533cf6 | 2009-03-24 09:08:07 -0700 | [diff] [blame] | 1923 | ha->flags.chip_reset_done = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1924 | vha->flags.reset_active = 0; |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 1925 | ha->flags.pci_channel_io_perm_failure = 0; |
| 1926 | ha->flags.eeh_busy = 0; |
Joe Carnuccio | fabbb8d | 2013-08-27 01:37:40 -0400 | [diff] [blame] | 1927 | vha->qla_stats.jiffies_at_last_reset = get_jiffies_64(); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1928 | atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME); |
| 1929 | atomic_set(&vha->loop_state, LOOP_DOWN); |
| 1930 | vha->device_flags = DFLG_NO_CABLE; |
| 1931 | vha->dpc_flags = 0; |
| 1932 | vha->flags.management_server_logged_in = 0; |
| 1933 | vha->marker_needed = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1934 | ha->isp_abort_cnt = 0; |
| 1935 | ha->beacon_blink_led = 0; |
| 1936 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1937 | set_bit(0, ha->req_qid_map); |
| 1938 | set_bit(0, ha->rsp_qid_map); |
| 1939 | |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 1940 | ql_dbg(ql_dbg_init, vha, 0x0040, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1941 | "Configuring PCI space...\n"); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1942 | rval = ha->isp_ops->pci_config(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1943 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1944 | ql_log(ql_log_warn, vha, 0x0044, |
| 1945 | "Unable to configure PCI space.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1946 | return (rval); |
| 1947 | } |
| 1948 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1949 | ha->isp_ops->reset_chip(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1950 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1951 | rval = qla2xxx_get_flash_info(vha); |
Andrew Vasquez | c00d899 | 2008-09-11 21:22:49 -0700 | [diff] [blame] | 1952 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1953 | ql_log(ql_log_fatal, vha, 0x004f, |
| 1954 | "Unable to validate FLASH data.\n"); |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 1955 | return rval; |
| 1956 | } |
| 1957 | |
| 1958 | if (IS_QLA8044(ha)) { |
| 1959 | qla8044_read_reset_template(vha); |
| 1960 | |
| 1961 | /* NOTE: If ql2xdontresethba==1, set IDC_CTRL DONTRESET_BIT0. |
| 1962 | * If DONRESET_BIT0 is set, drivers should not set dev_state |
| 1963 | * to NEED_RESET. But if NEED_RESET is set, drivers should |
| 1964 | * should honor the reset. */ |
| 1965 | if (ql2xdontresethba == 1) |
| 1966 | qla8044_set_idc_dontreset(vha); |
Andrew Vasquez | c00d899 | 2008-09-11 21:22:49 -0700 | [diff] [blame] | 1967 | } |
| 1968 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1969 | ha->isp_ops->get_flash_version(vha, req->ring); |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 1970 | ql_dbg(ql_dbg_init, vha, 0x0061, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1971 | "Configure NVRAM parameters...\n"); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1972 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1973 | ha->isp_ops->nvram_config(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1974 | |
Andrew Vasquez | d4c760c | 2006-06-23 16:10:39 -0700 | [diff] [blame] | 1975 | if (ha->flags.disable_serdes) { |
| 1976 | /* Mask HBA via NVRAM settings? */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1977 | ql_log(ql_log_info, vha, 0x0077, |
Oleksandr Khoshaba | 7b833558 | 2013-08-27 01:37:27 -0400 | [diff] [blame] | 1978 | "Masking HBA WWPN %8phN (via NVRAM).\n", vha->port_name); |
Andrew Vasquez | d4c760c | 2006-06-23 16:10:39 -0700 | [diff] [blame] | 1979 | return QLA_FUNCTION_FAILED; |
| 1980 | } |
| 1981 | |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 1982 | ql_dbg(ql_dbg_init, vha, 0x0078, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1983 | "Verifying loaded RISC code...\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1984 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1985 | if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) { |
| 1986 | rval = ha->isp_ops->chip_diag(vha); |
Andrew Vasquez | d19044c | 2006-11-22 08:22:19 -0800 | [diff] [blame] | 1987 | if (rval) |
| 1988 | return (rval); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1989 | rval = qla2x00_setup_chip(vha); |
Andrew Vasquez | d19044c | 2006-11-22 08:22:19 -0800 | [diff] [blame] | 1990 | if (rval) |
| 1991 | return (rval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1992 | } |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 1993 | |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 1994 | if (IS_QLA84XX(ha)) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1995 | ha->cs84xx = qla84xx_get_chip(vha); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 1996 | if (!ha->cs84xx) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1997 | ql_log(ql_log_warn, vha, 0x00d0, |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 1998 | "Unable to configure ISP84XX.\n"); |
| 1999 | return QLA_FUNCTION_FAILED; |
| 2000 | } |
| 2001 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2002 | |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 2003 | if (qla_ini_mode_enabled(vha) || qla_dual_mode_enabled(vha)) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2004 | rval = qla2x00_init_rings(vha); |
| 2005 | |
Lalit Chandivade | 2533cf6 | 2009-03-24 09:08:07 -0700 | [diff] [blame] | 2006 | ha->flags.chip_reset_done = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2007 | |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 2008 | if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) { |
Andrew Vasquez | 6c452a4 | 2010-03-19 17:04:02 -0700 | [diff] [blame] | 2009 | /* Issue verify 84xx FW IOCB to complete 84xx initialization */ |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 2010 | rval = qla84xx_init_chip(vha); |
| 2011 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2012 | ql_log(ql_log_warn, vha, 0x00d4, |
| 2013 | "Unable to initialize ISP84XX.\n"); |
Bart Van Assche | 8d2b21d | 2015-06-04 15:58:09 -0700 | [diff] [blame] | 2014 | qla84xx_put_chip(vha); |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 2015 | } |
| 2016 | } |
| 2017 | |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 2018 | /* Load the NIC Core f/w if we are the first protocol driver. */ |
| 2019 | if (IS_QLA8031(ha)) { |
| 2020 | rval = qla83xx_nic_core_fw_load(vha); |
| 2021 | if (rval) |
| 2022 | ql_log(ql_log_warn, vha, 0x0124, |
| 2023 | "Error in initializing NIC Core f/w.\n"); |
| 2024 | } |
| 2025 | |
Madhuranath Iyengar | 2f0f3f4 | 2010-07-23 15:28:24 +0500 | [diff] [blame] | 2026 | if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha)) |
| 2027 | qla24xx_read_fcp_prio_cfg(vha); |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 2028 | |
Joe Carnuccio | c46e65c | 2013-08-27 01:37:35 -0400 | [diff] [blame] | 2029 | if (IS_P3P_TYPE(ha)) |
| 2030 | qla82xx_set_driver_version(vha, QLA2XXX_VERSION); |
| 2031 | else |
| 2032 | qla25xx_set_driver_version(vha, QLA2XXX_VERSION); |
| 2033 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2034 | return (rval); |
| 2035 | } |
| 2036 | |
| 2037 | /** |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2038 | * qla2100_pci_config() - Setup ISP21xx PCI configuration registers. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2039 | * @ha: HA context |
| 2040 | * |
| 2041 | * Returns 0 on success. |
| 2042 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2043 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2044 | qla2100_pci_config(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2045 | { |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 2046 | uint16_t w; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2047 | unsigned long flags; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2048 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 2049 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2050 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2051 | pci_set_master(ha->pdev); |
Andrew Vasquez | af6177d | 2007-07-19 15:06:02 -0700 | [diff] [blame] | 2052 | pci_try_set_mwi(ha->pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2053 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2054 | pci_read_config_word(ha->pdev, PCI_COMMAND, &w); |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 2055 | w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2056 | pci_write_config_word(ha->pdev, PCI_COMMAND, w); |
| 2057 | |
Andrew Vasquez | 737faec | 2008-10-24 15:13:45 -0700 | [diff] [blame] | 2058 | pci_disable_rom(ha->pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2059 | |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2060 | /* Get PCI bus information. */ |
| 2061 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 2062 | ha->pci_attr = RD_REG_WORD(®->ctrl_status); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2063 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 2064 | |
| 2065 | return QLA_SUCCESS; |
| 2066 | } |
| 2067 | |
| 2068 | /** |
| 2069 | * qla2300_pci_config() - Setup ISP23xx PCI configuration registers. |
| 2070 | * @ha: HA context |
| 2071 | * |
| 2072 | * Returns 0 on success. |
| 2073 | */ |
| 2074 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2075 | qla2300_pci_config(scsi_qla_host_t *vha) |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2076 | { |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 2077 | uint16_t w; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2078 | unsigned long flags = 0; |
| 2079 | uint32_t cnt; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2080 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 2081 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2082 | |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2083 | pci_set_master(ha->pdev); |
Andrew Vasquez | af6177d | 2007-07-19 15:06:02 -0700 | [diff] [blame] | 2084 | pci_try_set_mwi(ha->pdev); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2085 | |
| 2086 | pci_read_config_word(ha->pdev, PCI_COMMAND, &w); |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 2087 | w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2088 | |
| 2089 | if (IS_QLA2322(ha) || IS_QLA6322(ha)) |
| 2090 | w &= ~PCI_COMMAND_INTX_DISABLE; |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 2091 | pci_write_config_word(ha->pdev, PCI_COMMAND, w); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2092 | |
| 2093 | /* |
| 2094 | * If this is a 2300 card and not 2312, reset the |
| 2095 | * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately, |
| 2096 | * the 2310 also reports itself as a 2300 so we need to get the |
| 2097 | * fb revision level -- a 6 indicates it really is a 2300 and |
| 2098 | * not a 2310. |
| 2099 | */ |
| 2100 | if (IS_QLA2300(ha)) { |
| 2101 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 2102 | |
| 2103 | /* Pause RISC. */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 2104 | WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2105 | for (cnt = 0; cnt < 30000; cnt++) { |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 2106 | if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) != 0) |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2107 | break; |
| 2108 | |
| 2109 | udelay(10); |
| 2110 | } |
| 2111 | |
| 2112 | /* Select FPM registers. */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 2113 | WRT_REG_WORD(®->ctrl_status, 0x20); |
| 2114 | RD_REG_WORD(®->ctrl_status); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2115 | |
| 2116 | /* Get the fb rev level */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 2117 | ha->fb_rev = RD_FB_CMD_REG(ha, reg); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2118 | |
| 2119 | if (ha->fb_rev == FPM_2300) |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 2120 | pci_clear_mwi(ha->pdev); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2121 | |
| 2122 | /* Deselect FPM registers. */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 2123 | WRT_REG_WORD(®->ctrl_status, 0x0); |
| 2124 | RD_REG_WORD(®->ctrl_status); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2125 | |
| 2126 | /* Release RISC module. */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 2127 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2128 | for (cnt = 0; cnt < 30000; cnt++) { |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 2129 | if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) == 0) |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2130 | break; |
| 2131 | |
| 2132 | udelay(10); |
| 2133 | } |
| 2134 | |
| 2135 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 2136 | } |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2137 | |
| 2138 | pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80); |
| 2139 | |
Andrew Vasquez | 737faec | 2008-10-24 15:13:45 -0700 | [diff] [blame] | 2140 | pci_disable_rom(ha->pdev); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2141 | |
| 2142 | /* Get PCI bus information. */ |
| 2143 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 2144 | ha->pci_attr = RD_REG_WORD(®->ctrl_status); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2145 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 2146 | |
| 2147 | return QLA_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2148 | } |
| 2149 | |
| 2150 | /** |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2151 | * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers. |
| 2152 | * @ha: HA context |
| 2153 | * |
| 2154 | * Returns 0 on success. |
| 2155 | */ |
| 2156 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2157 | qla24xx_pci_config(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2158 | { |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 2159 | uint16_t w; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2160 | unsigned long flags = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2161 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2162 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2163 | |
| 2164 | pci_set_master(ha->pdev); |
Andrew Vasquez | af6177d | 2007-07-19 15:06:02 -0700 | [diff] [blame] | 2165 | pci_try_set_mwi(ha->pdev); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2166 | |
| 2167 | pci_read_config_word(ha->pdev, PCI_COMMAND, &w); |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 2168 | w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2169 | w &= ~PCI_COMMAND_INTX_DISABLE; |
| 2170 | pci_write_config_word(ha->pdev, PCI_COMMAND, w); |
| 2171 | |
| 2172 | pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80); |
| 2173 | |
| 2174 | /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */ |
Andrew Vasquez | f85ec18 | 2007-07-19 15:06:01 -0700 | [diff] [blame] | 2175 | if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX)) |
| 2176 | pcix_set_mmrbc(ha->pdev, 2048); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2177 | |
| 2178 | /* PCIe -- adjust Maximum Read Request Size (2048). */ |
Jon Mason | e67f132 | 2012-07-10 14:57:56 -0700 | [diff] [blame] | 2179 | if (pci_is_pcie(ha->pdev)) |
Chad Dupuis | 5ffd3a5 | 2012-08-22 14:21:26 -0400 | [diff] [blame] | 2180 | pcie_set_readrq(ha->pdev, 4096); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2181 | |
Andrew Vasquez | 737faec | 2008-10-24 15:13:45 -0700 | [diff] [blame] | 2182 | pci_disable_rom(ha->pdev); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2183 | |
Auke Kok | 44c1013 | 2007-06-08 15:46:36 -0700 | [diff] [blame] | 2184 | ha->chip_revision = ha->pdev->revision; |
Andrew Vasquez | a8488ab | 2007-01-29 10:22:19 -0800 | [diff] [blame] | 2185 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2186 | /* Get PCI bus information. */ |
| 2187 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 2188 | ha->pci_attr = RD_REG_DWORD(®->ctrl_status); |
| 2189 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 2190 | |
| 2191 | return QLA_SUCCESS; |
| 2192 | } |
| 2193 | |
| 2194 | /** |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 2195 | * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers. |
| 2196 | * @ha: HA context |
| 2197 | * |
| 2198 | * Returns 0 on success. |
| 2199 | */ |
| 2200 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2201 | qla25xx_pci_config(scsi_qla_host_t *vha) |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 2202 | { |
| 2203 | uint16_t w; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2204 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 2205 | |
| 2206 | pci_set_master(ha->pdev); |
| 2207 | pci_try_set_mwi(ha->pdev); |
| 2208 | |
| 2209 | pci_read_config_word(ha->pdev, PCI_COMMAND, &w); |
| 2210 | w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR); |
| 2211 | w &= ~PCI_COMMAND_INTX_DISABLE; |
| 2212 | pci_write_config_word(ha->pdev, PCI_COMMAND, w); |
| 2213 | |
| 2214 | /* PCIe -- adjust Maximum Read Request Size (2048). */ |
Jon Mason | e67f132 | 2012-07-10 14:57:56 -0700 | [diff] [blame] | 2215 | if (pci_is_pcie(ha->pdev)) |
Chad Dupuis | 5ffd3a5 | 2012-08-22 14:21:26 -0400 | [diff] [blame] | 2216 | pcie_set_readrq(ha->pdev, 4096); |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 2217 | |
Andrew Vasquez | 737faec | 2008-10-24 15:13:45 -0700 | [diff] [blame] | 2218 | pci_disable_rom(ha->pdev); |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 2219 | |
| 2220 | ha->chip_revision = ha->pdev->revision; |
| 2221 | |
| 2222 | return QLA_SUCCESS; |
| 2223 | } |
| 2224 | |
| 2225 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2226 | * qla2x00_isp_firmware() - Choose firmware image. |
| 2227 | * @ha: HA context |
| 2228 | * |
| 2229 | * Returns 0 on success. |
| 2230 | */ |
| 2231 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2232 | qla2x00_isp_firmware(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2233 | { |
| 2234 | int rval; |
Andrew Vasquez | 42e421b | 2008-07-10 16:56:01 -0700 | [diff] [blame] | 2235 | uint16_t loop_id, topo, sw_cap; |
| 2236 | uint8_t domain, area, al_pa; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2237 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2238 | |
| 2239 | /* Assume loading risc code */ |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 2240 | rval = QLA_FUNCTION_FAILED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2241 | |
| 2242 | if (ha->flags.disable_risc_code_load) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2243 | ql_log(ql_log_info, vha, 0x0079, "RISC CODE NOT loaded.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2244 | |
| 2245 | /* Verify checksum of loaded RISC code. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2246 | rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address); |
Andrew Vasquez | 42e421b | 2008-07-10 16:56:01 -0700 | [diff] [blame] | 2247 | if (rval == QLA_SUCCESS) { |
| 2248 | /* And, verify we are not in ROM code. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2249 | rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa, |
Andrew Vasquez | 42e421b | 2008-07-10 16:56:01 -0700 | [diff] [blame] | 2250 | &area, &domain, &topo, &sw_cap); |
| 2251 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2252 | } |
| 2253 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2254 | if (rval) |
| 2255 | ql_dbg(ql_dbg_init, vha, 0x007a, |
| 2256 | "**** Load RISC code ****.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2257 | |
| 2258 | return (rval); |
| 2259 | } |
| 2260 | |
| 2261 | /** |
| 2262 | * qla2x00_reset_chip() - Reset ISP chip. |
| 2263 | * @ha: HA context |
| 2264 | * |
| 2265 | * Returns 0 on success. |
| 2266 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2267 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2268 | qla2x00_reset_chip(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2269 | { |
| 2270 | unsigned long flags = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2271 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 2272 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2273 | uint32_t cnt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2274 | uint16_t cmd; |
| 2275 | |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 2276 | if (unlikely(pci_channel_offline(ha->pdev))) |
| 2277 | return; |
| 2278 | |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 2279 | ha->isp_ops->disable_intrs(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2280 | |
| 2281 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 2282 | |
| 2283 | /* Turn off master enable */ |
| 2284 | cmd = 0; |
| 2285 | pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd); |
| 2286 | cmd &= ~PCI_COMMAND_MASTER; |
| 2287 | pci_write_config_word(ha->pdev, PCI_COMMAND, cmd); |
| 2288 | |
| 2289 | if (!IS_QLA2100(ha)) { |
| 2290 | /* Pause RISC. */ |
| 2291 | WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC); |
| 2292 | if (IS_QLA2200(ha) || IS_QLA2300(ha)) { |
| 2293 | for (cnt = 0; cnt < 30000; cnt++) { |
| 2294 | if ((RD_REG_WORD(®->hccr) & |
| 2295 | HCCR_RISC_PAUSE) != 0) |
| 2296 | break; |
| 2297 | udelay(100); |
| 2298 | } |
| 2299 | } else { |
| 2300 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 2301 | udelay(10); |
| 2302 | } |
| 2303 | |
| 2304 | /* Select FPM registers. */ |
| 2305 | WRT_REG_WORD(®->ctrl_status, 0x20); |
| 2306 | RD_REG_WORD(®->ctrl_status); /* PCI Posting. */ |
| 2307 | |
| 2308 | /* FPM Soft Reset. */ |
| 2309 | WRT_REG_WORD(®->fpm_diag_config, 0x100); |
| 2310 | RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */ |
| 2311 | |
| 2312 | /* Toggle Fpm Reset. */ |
| 2313 | if (!IS_QLA2200(ha)) { |
| 2314 | WRT_REG_WORD(®->fpm_diag_config, 0x0); |
| 2315 | RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */ |
| 2316 | } |
| 2317 | |
| 2318 | /* Select frame buffer registers. */ |
| 2319 | WRT_REG_WORD(®->ctrl_status, 0x10); |
| 2320 | RD_REG_WORD(®->ctrl_status); /* PCI Posting. */ |
| 2321 | |
| 2322 | /* Reset frame buffer FIFOs. */ |
| 2323 | if (IS_QLA2200(ha)) { |
| 2324 | WRT_FB_CMD_REG(ha, reg, 0xa000); |
| 2325 | RD_FB_CMD_REG(ha, reg); /* PCI Posting. */ |
| 2326 | } else { |
| 2327 | WRT_FB_CMD_REG(ha, reg, 0x00fc); |
| 2328 | |
| 2329 | /* Read back fb_cmd until zero or 3 seconds max */ |
| 2330 | for (cnt = 0; cnt < 3000; cnt++) { |
| 2331 | if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0) |
| 2332 | break; |
| 2333 | udelay(100); |
| 2334 | } |
| 2335 | } |
| 2336 | |
| 2337 | /* Select RISC module registers. */ |
| 2338 | WRT_REG_WORD(®->ctrl_status, 0); |
| 2339 | RD_REG_WORD(®->ctrl_status); /* PCI Posting. */ |
| 2340 | |
| 2341 | /* Reset RISC processor. */ |
| 2342 | WRT_REG_WORD(®->hccr, HCCR_RESET_RISC); |
| 2343 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 2344 | |
| 2345 | /* Release RISC processor. */ |
| 2346 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
| 2347 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 2348 | } |
| 2349 | |
| 2350 | WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT); |
| 2351 | WRT_REG_WORD(®->hccr, HCCR_CLR_HOST_INT); |
| 2352 | |
| 2353 | /* Reset ISP chip. */ |
| 2354 | WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET); |
| 2355 | |
| 2356 | /* Wait for RISC to recover from reset. */ |
| 2357 | if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) { |
| 2358 | /* |
| 2359 | * It is necessary to for a delay here since the card doesn't |
| 2360 | * respond to PCI reads during a reset. On some architectures |
| 2361 | * this will result in an MCA. |
| 2362 | */ |
| 2363 | udelay(20); |
| 2364 | for (cnt = 30000; cnt; cnt--) { |
| 2365 | if ((RD_REG_WORD(®->ctrl_status) & |
| 2366 | CSR_ISP_SOFT_RESET) == 0) |
| 2367 | break; |
| 2368 | udelay(100); |
| 2369 | } |
| 2370 | } else |
| 2371 | udelay(10); |
| 2372 | |
| 2373 | /* Reset RISC processor. */ |
| 2374 | WRT_REG_WORD(®->hccr, HCCR_RESET_RISC); |
| 2375 | |
| 2376 | WRT_REG_WORD(®->semaphore, 0); |
| 2377 | |
| 2378 | /* Release RISC processor. */ |
| 2379 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
| 2380 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 2381 | |
| 2382 | if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) { |
| 2383 | for (cnt = 0; cnt < 30000; cnt++) { |
Andrew Vasquez | ffb39f0 | 2006-05-17 15:09:06 -0700 | [diff] [blame] | 2384 | if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2385 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2386 | |
| 2387 | udelay(100); |
| 2388 | } |
| 2389 | } else |
| 2390 | udelay(100); |
| 2391 | |
| 2392 | /* Turn on master enable */ |
| 2393 | cmd |= PCI_COMMAND_MASTER; |
| 2394 | pci_write_config_word(ha->pdev, PCI_COMMAND, cmd); |
| 2395 | |
| 2396 | /* Disable RISC pause on FPM parity error. */ |
| 2397 | if (!IS_QLA2100(ha)) { |
| 2398 | WRT_REG_WORD(®->hccr, HCCR_DISABLE_PARITY_PAUSE); |
| 2399 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 2400 | } |
| 2401 | |
| 2402 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 2403 | } |
| 2404 | |
| 2405 | /** |
Madhuranath Iyengar | b1d46989 | 2010-09-03 15:20:54 -0700 | [diff] [blame] | 2406 | * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC. |
| 2407 | * |
| 2408 | * Returns 0 on success. |
| 2409 | */ |
Saurav Kashyap | fa49263 | 2012-11-21 02:40:29 -0500 | [diff] [blame] | 2410 | static int |
Madhuranath Iyengar | b1d46989 | 2010-09-03 15:20:54 -0700 | [diff] [blame] | 2411 | qla81xx_reset_mpi(scsi_qla_host_t *vha) |
| 2412 | { |
| 2413 | uint16_t mb[4] = {0x1010, 0, 1, 0}; |
| 2414 | |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 2415 | if (!IS_QLA81XX(vha->hw)) |
| 2416 | return QLA_SUCCESS; |
| 2417 | |
Madhuranath Iyengar | b1d46989 | 2010-09-03 15:20:54 -0700 | [diff] [blame] | 2418 | return qla81xx_write_mpi_register(vha, mb); |
| 2419 | } |
| 2420 | |
| 2421 | /** |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 2422 | * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC. |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2423 | * @ha: HA context |
| 2424 | * |
| 2425 | * Returns 0 on success. |
| 2426 | */ |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2427 | static inline int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2428 | qla24xx_reset_risc(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2429 | { |
| 2430 | unsigned long flags = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2431 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2432 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; |
Bart Van Assche | 52c8282 | 2015-07-09 07:23:26 -0700 | [diff] [blame] | 2433 | uint32_t cnt; |
Andrew Vasquez | 335a1cc | 2005-11-08 14:37:48 -0800 | [diff] [blame] | 2434 | uint16_t wd; |
Madhuranath Iyengar | b1d46989 | 2010-09-03 15:20:54 -0700 | [diff] [blame] | 2435 | static int abts_cnt; /* ISP abort retry counts */ |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2436 | int rval = QLA_SUCCESS; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2437 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2438 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 2439 | |
| 2440 | /* Reset RISC. */ |
| 2441 | WRT_REG_DWORD(®->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES); |
| 2442 | for (cnt = 0; cnt < 30000; cnt++) { |
| 2443 | if ((RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE) == 0) |
| 2444 | break; |
| 2445 | |
| 2446 | udelay(10); |
| 2447 | } |
| 2448 | |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2449 | if (!(RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE)) |
| 2450 | set_bit(DMA_SHUTDOWN_CMPL, &ha->fw_dump_cap_flags); |
| 2451 | |
| 2452 | ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017e, |
| 2453 | "HCCR: 0x%x, Control Status %x, DMA active status:0x%x\n", |
| 2454 | RD_REG_DWORD(®->hccr), |
| 2455 | RD_REG_DWORD(®->ctrl_status), |
| 2456 | (RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE)); |
| 2457 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2458 | WRT_REG_DWORD(®->ctrl_status, |
| 2459 | CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES); |
Andrew Vasquez | 335a1cc | 2005-11-08 14:37:48 -0800 | [diff] [blame] | 2460 | pci_read_config_word(ha->pdev, PCI_COMMAND, &wd); |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 2461 | |
Andrew Vasquez | 335a1cc | 2005-11-08 14:37:48 -0800 | [diff] [blame] | 2462 | udelay(100); |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2463 | |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 2464 | /* Wait for firmware to complete NVRAM accesses. */ |
Bart Van Assche | 52c8282 | 2015-07-09 07:23:26 -0700 | [diff] [blame] | 2465 | RD_REG_WORD(®->mailbox0); |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2466 | for (cnt = 10000; RD_REG_WORD(®->mailbox0) != 0 && |
| 2467 | rval == QLA_SUCCESS; cnt--) { |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 2468 | barrier(); |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2469 | if (cnt) |
| 2470 | udelay(5); |
| 2471 | else |
| 2472 | rval = QLA_FUNCTION_TIMEOUT; |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 2473 | } |
| 2474 | |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2475 | if (rval == QLA_SUCCESS) |
| 2476 | set_bit(ISP_MBX_RDY, &ha->fw_dump_cap_flags); |
| 2477 | |
| 2478 | ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017f, |
| 2479 | "HCCR: 0x%x, MailBox0 Status 0x%x\n", |
| 2480 | RD_REG_DWORD(®->hccr), |
| 2481 | RD_REG_DWORD(®->mailbox0)); |
| 2482 | |
Andrew Vasquez | 335a1cc | 2005-11-08 14:37:48 -0800 | [diff] [blame] | 2483 | /* Wait for soft-reset to complete. */ |
Bart Van Assche | 52c8282 | 2015-07-09 07:23:26 -0700 | [diff] [blame] | 2484 | RD_REG_DWORD(®->ctrl_status); |
Quinn Tran | 200ffb1 | 2016-12-23 18:06:12 -0800 | [diff] [blame] | 2485 | for (cnt = 0; cnt < 60; cnt++) { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2486 | barrier(); |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2487 | if ((RD_REG_DWORD(®->ctrl_status) & |
| 2488 | CSRX_ISP_SOFT_RESET) == 0) |
| 2489 | break; |
| 2490 | |
| 2491 | udelay(5); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2492 | } |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2493 | if (!(RD_REG_DWORD(®->ctrl_status) & CSRX_ISP_SOFT_RESET)) |
| 2494 | set_bit(ISP_SOFT_RESET_CMPL, &ha->fw_dump_cap_flags); |
| 2495 | |
| 2496 | ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015d, |
| 2497 | "HCCR: 0x%x, Soft Reset status: 0x%x\n", |
| 2498 | RD_REG_DWORD(®->hccr), |
| 2499 | RD_REG_DWORD(®->ctrl_status)); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2500 | |
Madhuranath Iyengar | b1d46989 | 2010-09-03 15:20:54 -0700 | [diff] [blame] | 2501 | /* If required, do an MPI FW reset now */ |
| 2502 | if (test_and_clear_bit(MPI_RESET_NEEDED, &vha->dpc_flags)) { |
| 2503 | if (qla81xx_reset_mpi(vha) != QLA_SUCCESS) { |
| 2504 | if (++abts_cnt < 5) { |
| 2505 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
| 2506 | set_bit(MPI_RESET_NEEDED, &vha->dpc_flags); |
| 2507 | } else { |
| 2508 | /* |
| 2509 | * We exhausted the ISP abort retries. We have to |
| 2510 | * set the board offline. |
| 2511 | */ |
| 2512 | abts_cnt = 0; |
| 2513 | vha->flags.online = 0; |
| 2514 | } |
| 2515 | } |
| 2516 | } |
| 2517 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2518 | WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET); |
| 2519 | RD_REG_DWORD(®->hccr); |
| 2520 | |
| 2521 | WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE); |
| 2522 | RD_REG_DWORD(®->hccr); |
| 2523 | |
| 2524 | WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_RESET); |
| 2525 | RD_REG_DWORD(®->hccr); |
| 2526 | |
Bart Van Assche | 52c8282 | 2015-07-09 07:23:26 -0700 | [diff] [blame] | 2527 | RD_REG_WORD(®->mailbox0); |
Quinn Tran | 200ffb1 | 2016-12-23 18:06:12 -0800 | [diff] [blame] | 2528 | for (cnt = 60; RD_REG_WORD(®->mailbox0) != 0 && |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2529 | rval == QLA_SUCCESS; cnt--) { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2530 | barrier(); |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2531 | if (cnt) |
| 2532 | udelay(5); |
| 2533 | else |
| 2534 | rval = QLA_FUNCTION_TIMEOUT; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2535 | } |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2536 | if (rval == QLA_SUCCESS) |
| 2537 | set_bit(RISC_RDY_AFT_RESET, &ha->fw_dump_cap_flags); |
| 2538 | |
| 2539 | ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015e, |
| 2540 | "Host Risc 0x%x, mailbox0 0x%x\n", |
| 2541 | RD_REG_DWORD(®->hccr), |
| 2542 | RD_REG_WORD(®->mailbox0)); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2543 | |
| 2544 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Andrew Vasquez | 124f85e | 2009-01-05 11:18:06 -0800 | [diff] [blame] | 2545 | |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2546 | ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015f, |
| 2547 | "Driver in %s mode\n", |
| 2548 | IS_NOPOLLING_TYPE(ha) ? "Interrupt" : "Polling"); |
| 2549 | |
Andrew Vasquez | 124f85e | 2009-01-05 11:18:06 -0800 | [diff] [blame] | 2550 | if (IS_NOPOLLING_TYPE(ha)) |
| 2551 | ha->isp_ops->enable_intrs(ha); |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2552 | |
| 2553 | return rval; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2554 | } |
| 2555 | |
Joe Carnuccio | 4ea2c9c | 2012-11-21 02:40:37 -0500 | [diff] [blame] | 2556 | static void |
| 2557 | qla25xx_read_risc_sema_reg(scsi_qla_host_t *vha, uint32_t *data) |
| 2558 | { |
| 2559 | struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24; |
| 2560 | |
| 2561 | WRT_REG_DWORD(®->iobase_addr, RISC_REGISTER_BASE_OFFSET); |
| 2562 | *data = RD_REG_DWORD(®->iobase_window + RISC_REGISTER_WINDOW_OFFET); |
| 2563 | |
| 2564 | } |
| 2565 | |
| 2566 | static void |
| 2567 | qla25xx_write_risc_sema_reg(scsi_qla_host_t *vha, uint32_t data) |
| 2568 | { |
| 2569 | struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24; |
| 2570 | |
| 2571 | WRT_REG_DWORD(®->iobase_addr, RISC_REGISTER_BASE_OFFSET); |
| 2572 | WRT_REG_DWORD(®->iobase_window + RISC_REGISTER_WINDOW_OFFET, data); |
| 2573 | } |
| 2574 | |
| 2575 | static void |
| 2576 | qla25xx_manipulate_risc_semaphore(scsi_qla_host_t *vha) |
| 2577 | { |
Joe Carnuccio | 4ea2c9c | 2012-11-21 02:40:37 -0500 | [diff] [blame] | 2578 | uint32_t wd32 = 0; |
| 2579 | uint delta_msec = 100; |
| 2580 | uint elapsed_msec = 0; |
| 2581 | uint timeout_msec; |
| 2582 | ulong n; |
| 2583 | |
Joe Carnuccio | cc79076 | 2015-08-04 13:37:53 -0400 | [diff] [blame] | 2584 | if (vha->hw->pdev->subsystem_device != 0x0175 && |
| 2585 | vha->hw->pdev->subsystem_device != 0x0240) |
Joe Carnuccio | 4ea2c9c | 2012-11-21 02:40:37 -0500 | [diff] [blame] | 2586 | return; |
| 2587 | |
Joe Carnuccio | 8dd7e3a | 2015-08-04 13:37:54 -0400 | [diff] [blame] | 2588 | WRT_REG_DWORD(&vha->hw->iobase->isp24.hccr, HCCRX_SET_RISC_PAUSE); |
| 2589 | udelay(100); |
| 2590 | |
Joe Carnuccio | 4ea2c9c | 2012-11-21 02:40:37 -0500 | [diff] [blame] | 2591 | attempt: |
| 2592 | timeout_msec = TIMEOUT_SEMAPHORE; |
| 2593 | n = timeout_msec / delta_msec; |
| 2594 | while (n--) { |
| 2595 | qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_SET); |
| 2596 | qla25xx_read_risc_sema_reg(vha, &wd32); |
| 2597 | if (wd32 & RISC_SEMAPHORE) |
| 2598 | break; |
| 2599 | msleep(delta_msec); |
| 2600 | elapsed_msec += delta_msec; |
| 2601 | if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED) |
| 2602 | goto force; |
| 2603 | } |
| 2604 | |
| 2605 | if (!(wd32 & RISC_SEMAPHORE)) |
| 2606 | goto force; |
| 2607 | |
| 2608 | if (!(wd32 & RISC_SEMAPHORE_FORCE)) |
| 2609 | goto acquired; |
| 2610 | |
| 2611 | qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_CLR); |
| 2612 | timeout_msec = TIMEOUT_SEMAPHORE_FORCE; |
| 2613 | n = timeout_msec / delta_msec; |
| 2614 | while (n--) { |
| 2615 | qla25xx_read_risc_sema_reg(vha, &wd32); |
| 2616 | if (!(wd32 & RISC_SEMAPHORE_FORCE)) |
| 2617 | break; |
| 2618 | msleep(delta_msec); |
| 2619 | elapsed_msec += delta_msec; |
| 2620 | if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED) |
| 2621 | goto force; |
| 2622 | } |
| 2623 | |
| 2624 | if (wd32 & RISC_SEMAPHORE_FORCE) |
| 2625 | qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_CLR); |
| 2626 | |
| 2627 | goto attempt; |
| 2628 | |
| 2629 | force: |
| 2630 | qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_SET); |
| 2631 | |
| 2632 | acquired: |
| 2633 | return; |
| 2634 | } |
| 2635 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2636 | /** |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 2637 | * qla24xx_reset_chip() - Reset ISP24xx chip. |
| 2638 | * @ha: HA context |
| 2639 | * |
| 2640 | * Returns 0 on success. |
| 2641 | */ |
| 2642 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2643 | qla24xx_reset_chip(scsi_qla_host_t *vha) |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 2644 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2645 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 2646 | |
| 2647 | if (pci_channel_offline(ha->pdev) && |
| 2648 | ha->flags.pci_channel_io_perm_failure) { |
| 2649 | return; |
| 2650 | } |
| 2651 | |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 2652 | ha->isp_ops->disable_intrs(ha); |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 2653 | |
Joe Carnuccio | 4ea2c9c | 2012-11-21 02:40:37 -0500 | [diff] [blame] | 2654 | qla25xx_manipulate_risc_semaphore(vha); |
| 2655 | |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 2656 | /* Perform RISC reset. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2657 | qla24xx_reset_risc(vha); |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 2658 | } |
| 2659 | |
| 2660 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2661 | * qla2x00_chip_diag() - Test chip for proper operation. |
| 2662 | * @ha: HA context |
| 2663 | * |
| 2664 | * Returns 0 on success. |
| 2665 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2666 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2667 | qla2x00_chip_diag(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2668 | { |
| 2669 | int rval; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2670 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 2671 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2672 | unsigned long flags = 0; |
| 2673 | uint16_t data; |
| 2674 | uint32_t cnt; |
| 2675 | uint16_t mb[5]; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2676 | struct req_que *req = ha->req_q_map[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2677 | |
| 2678 | /* Assume a failed state */ |
| 2679 | rval = QLA_FUNCTION_FAILED; |
| 2680 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2681 | ql_dbg(ql_dbg_init, vha, 0x007b, |
| 2682 | "Testing device at %lx.\n", (u_long)®->flash_address); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2683 | |
| 2684 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 2685 | |
| 2686 | /* Reset ISP chip. */ |
| 2687 | WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET); |
| 2688 | |
| 2689 | /* |
| 2690 | * We need to have a delay here since the card will not respond while |
| 2691 | * in reset causing an MCA on some architectures. |
| 2692 | */ |
| 2693 | udelay(20); |
| 2694 | data = qla2x00_debounce_register(®->ctrl_status); |
| 2695 | for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) { |
| 2696 | udelay(5); |
| 2697 | data = RD_REG_WORD(®->ctrl_status); |
| 2698 | barrier(); |
| 2699 | } |
| 2700 | |
| 2701 | if (!cnt) |
| 2702 | goto chip_diag_failed; |
| 2703 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2704 | ql_dbg(ql_dbg_init, vha, 0x007c, |
| 2705 | "Reset register cleared by chip reset.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2706 | |
| 2707 | /* Reset RISC processor. */ |
| 2708 | WRT_REG_WORD(®->hccr, HCCR_RESET_RISC); |
| 2709 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
| 2710 | |
| 2711 | /* Workaround for QLA2312 PCI parity error */ |
| 2712 | if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) { |
| 2713 | data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0)); |
| 2714 | for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) { |
| 2715 | udelay(5); |
| 2716 | data = RD_MAILBOX_REG(ha, reg, 0); |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 2717 | barrier(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2718 | } |
| 2719 | } else |
| 2720 | udelay(10); |
| 2721 | |
| 2722 | if (!cnt) |
| 2723 | goto chip_diag_failed; |
| 2724 | |
| 2725 | /* Check product ID of chip */ |
Milan P Gandhi | 5a68a1c | 2017-03-31 14:37:04 -0700 | [diff] [blame] | 2726 | ql_dbg(ql_dbg_init, vha, 0x007d, "Checking product ID of chip.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2727 | |
| 2728 | mb[1] = RD_MAILBOX_REG(ha, reg, 1); |
| 2729 | mb[2] = RD_MAILBOX_REG(ha, reg, 2); |
| 2730 | mb[3] = RD_MAILBOX_REG(ha, reg, 3); |
| 2731 | mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4)); |
| 2732 | if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) || |
| 2733 | mb[3] != PROD_ID_3) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2734 | ql_log(ql_log_warn, vha, 0x0062, |
| 2735 | "Wrong product ID = 0x%x,0x%x,0x%x.\n", |
| 2736 | mb[1], mb[2], mb[3]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2737 | |
| 2738 | goto chip_diag_failed; |
| 2739 | } |
| 2740 | ha->product_id[0] = mb[1]; |
| 2741 | ha->product_id[1] = mb[2]; |
| 2742 | ha->product_id[2] = mb[3]; |
| 2743 | ha->product_id[3] = mb[4]; |
| 2744 | |
| 2745 | /* Adjust fw RISC transfer size */ |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2746 | if (req->length > 1024) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2747 | ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024; |
| 2748 | else |
| 2749 | ha->fw_transfer_size = REQUEST_ENTRY_SIZE * |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2750 | req->length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2751 | |
| 2752 | if (IS_QLA2200(ha) && |
| 2753 | RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) { |
| 2754 | /* Limit firmware transfer size with a 2200A */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2755 | ql_dbg(ql_dbg_init, vha, 0x007e, "Found QLA2200A Chip.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2756 | |
andrew.vasquez@qlogic.com | ea5b638 | 2006-03-09 14:27:08 -0800 | [diff] [blame] | 2757 | ha->device_type |= DT_ISP2200A; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2758 | ha->fw_transfer_size = 128; |
| 2759 | } |
| 2760 | |
| 2761 | /* Wrap Incoming Mailboxes Test. */ |
| 2762 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 2763 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2764 | ql_dbg(ql_dbg_init, vha, 0x007f, "Checking mailboxes.\n"); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2765 | rval = qla2x00_mbx_reg_test(vha); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2766 | if (rval) |
| 2767 | ql_log(ql_log_warn, vha, 0x0080, |
| 2768 | "Failed mailbox send register test.\n"); |
| 2769 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2770 | /* Flag a successful rval */ |
| 2771 | rval = QLA_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2772 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 2773 | |
| 2774 | chip_diag_failed: |
| 2775 | if (rval) |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2776 | ql_log(ql_log_info, vha, 0x0081, |
| 2777 | "Chip diagnostics **** FAILED ****.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2778 | |
| 2779 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 2780 | |
| 2781 | return (rval); |
| 2782 | } |
| 2783 | |
| 2784 | /** |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2785 | * qla24xx_chip_diag() - Test ISP24xx for proper operation. |
| 2786 | * @ha: HA context |
| 2787 | * |
| 2788 | * Returns 0 on success. |
| 2789 | */ |
| 2790 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2791 | qla24xx_chip_diag(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2792 | { |
| 2793 | int rval; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2794 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2795 | struct req_que *req = ha->req_q_map[0]; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2796 | |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 2797 | if (IS_P3P_TYPE(ha)) |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 2798 | return QLA_SUCCESS; |
| 2799 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2800 | ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2801 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2802 | rval = qla2x00_mbx_reg_test(vha); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2803 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2804 | ql_log(ql_log_warn, vha, 0x0082, |
| 2805 | "Failed mailbox send register test.\n"); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2806 | } else { |
| 2807 | /* Flag a successful rval */ |
| 2808 | rval = QLA_SUCCESS; |
| 2809 | } |
| 2810 | |
| 2811 | return rval; |
| 2812 | } |
| 2813 | |
Quinn Tran | ad0a0b0 | 2017-12-28 12:33:14 -0800 | [diff] [blame] | 2814 | static void |
| 2815 | qla2x00_alloc_offload_mem(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2816 | { |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2817 | int rval; |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 2818 | dma_addr_t tc_dma; |
| 2819 | void *tc; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2820 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | d4e3e04 | 2006-05-17 15:09:50 -0700 | [diff] [blame] | 2821 | |
Quinn Tran | ad0a0b0 | 2017-12-28 12:33:14 -0800 | [diff] [blame] | 2822 | if (ha->eft) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2823 | ql_dbg(ql_dbg_init, vha, 0x00bd, |
Quinn Tran | ad0a0b0 | 2017-12-28 12:33:14 -0800 | [diff] [blame] | 2824 | "%s: Offload Mem is already allocated.\n", |
| 2825 | __func__); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2826 | return; |
Andrew Vasquez | d4e3e04 | 2006-05-17 15:09:50 -0700 | [diff] [blame] | 2827 | } |
| 2828 | |
Quinn Tran | ad0a0b0 | 2017-12-28 12:33:14 -0800 | [diff] [blame] | 2829 | if (IS_FWI2_CAPABLE(ha)) { |
| 2830 | /* Allocate memory for Fibre Channel Event Buffer. */ |
| 2831 | if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) && |
| 2832 | !IS_QLA27XX(ha)) |
| 2833 | goto try_eft; |
| 2834 | |
| 2835 | if (ha->fce) |
| 2836 | dma_free_coherent(&ha->pdev->dev, |
| 2837 | FCE_SIZE, ha->fce, ha->fce_dma); |
| 2838 | |
| 2839 | /* Allocate memory for Fibre Channel Event Buffer. */ |
| 2840 | tc = dma_zalloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma, |
| 2841 | GFP_KERNEL); |
| 2842 | if (!tc) { |
| 2843 | ql_log(ql_log_warn, vha, 0x00be, |
| 2844 | "Unable to allocate (%d KB) for FCE.\n", |
| 2845 | FCE_SIZE / 1024); |
| 2846 | goto try_eft; |
| 2847 | } |
| 2848 | |
| 2849 | rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS, |
| 2850 | ha->fce_mb, &ha->fce_bufs); |
| 2851 | if (rval) { |
| 2852 | ql_log(ql_log_warn, vha, 0x00bf, |
| 2853 | "Unable to initialize FCE (%d).\n", rval); |
| 2854 | dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc, |
| 2855 | tc_dma); |
| 2856 | ha->flags.fce_enabled = 0; |
| 2857 | goto try_eft; |
| 2858 | } |
| 2859 | ql_dbg(ql_dbg_init, vha, 0x00c0, |
| 2860 | "Allocate (%d KB) for FCE...\n", FCE_SIZE / 1024); |
| 2861 | |
| 2862 | ha->flags.fce_enabled = 1; |
| 2863 | ha->fce_dma = tc_dma; |
| 2864 | ha->fce = tc; |
| 2865 | |
| 2866 | try_eft: |
| 2867 | if (ha->eft) |
| 2868 | dma_free_coherent(&ha->pdev->dev, |
| 2869 | EFT_SIZE, ha->eft, ha->eft_dma); |
| 2870 | |
| 2871 | /* Allocate memory for Extended Trace Buffer. */ |
| 2872 | tc = dma_zalloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma, |
| 2873 | GFP_KERNEL); |
| 2874 | if (!tc) { |
| 2875 | ql_log(ql_log_warn, vha, 0x00c1, |
| 2876 | "Unable to allocate (%d KB) for EFT.\n", |
| 2877 | EFT_SIZE / 1024); |
| 2878 | goto eft_err; |
| 2879 | } |
| 2880 | |
| 2881 | rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS); |
| 2882 | if (rval) { |
| 2883 | ql_log(ql_log_warn, vha, 0x00c2, |
| 2884 | "Unable to initialize EFT (%d).\n", rval); |
| 2885 | dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc, |
| 2886 | tc_dma); |
| 2887 | goto eft_err; |
| 2888 | } |
| 2889 | ql_dbg(ql_dbg_init, vha, 0x00c3, |
| 2890 | "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024); |
| 2891 | |
| 2892 | ha->eft_dma = tc_dma; |
| 2893 | ha->eft = tc; |
| 2894 | } |
| 2895 | |
| 2896 | eft_err: |
| 2897 | return; |
| 2898 | } |
| 2899 | |
| 2900 | void |
| 2901 | qla2x00_alloc_fw_dump(scsi_qla_host_t *vha) |
| 2902 | { |
| 2903 | uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size, |
| 2904 | eft_size, fce_size, mq_size; |
| 2905 | struct qla_hw_data *ha = vha->hw; |
| 2906 | struct req_que *req = ha->req_q_map[0]; |
| 2907 | struct rsp_que *rsp = ha->rsp_q_map[0]; |
| 2908 | struct qla2xxx_fw_dump *fw_dump; |
| 2909 | |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 2910 | dump_size = fixed_size = mem_size = eft_size = fce_size = mq_size = 0; |
| 2911 | req_q_size = rsp_q_size = 0; |
| 2912 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2913 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) { |
| 2914 | fixed_size = sizeof(struct qla2100_fw_dump); |
| 2915 | } else if (IS_QLA23XX(ha)) { |
| 2916 | fixed_size = offsetof(struct qla2300_fw_dump, data_ram); |
| 2917 | mem_size = (ha->fw_memory_size - 0x11000 + 1) * |
| 2918 | sizeof(uint16_t); |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 2919 | } else if (IS_FWI2_CAPABLE(ha)) { |
Himanshu Madhani | b20f02e | 2015-06-10 11:05:18 -0400 | [diff] [blame] | 2920 | if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 2921 | fixed_size = offsetof(struct qla83xx_fw_dump, ext_mem); |
| 2922 | else if (IS_QLA81XX(ha)) |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 2923 | fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem); |
| 2924 | else if (IS_QLA25XX(ha)) |
| 2925 | fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem); |
| 2926 | else |
| 2927 | fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem); |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 2928 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2929 | mem_size = (ha->fw_memory_size - 0x100000 + 1) * |
| 2930 | sizeof(uint32_t); |
Giridhar Malavali | 050c9bb | 2012-02-09 11:15:33 -0800 | [diff] [blame] | 2931 | if (ha->mqenable) { |
Himanshu Madhani | b20f02e | 2015-06-10 11:05:18 -0400 | [diff] [blame] | 2932 | if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha)) |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 2933 | mq_size = sizeof(struct qla2xxx_mq_chain); |
Giridhar Malavali | 050c9bb | 2012-02-09 11:15:33 -0800 | [diff] [blame] | 2934 | /* |
| 2935 | * Allocate maximum buffer size for all queues. |
| 2936 | * Resizing must be done at end-of-dump processing. |
| 2937 | */ |
| 2938 | mq_size += ha->max_req_queues * |
| 2939 | (req->length * sizeof(request_t)); |
| 2940 | mq_size += ha->max_rsp_queues * |
| 2941 | (rsp->length * sizeof(response_t)); |
| 2942 | } |
Arun Easi | 00876ae | 2013-03-25 02:21:37 -0400 | [diff] [blame] | 2943 | if (ha->tgt.atio_ring) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2944 | mq_size += ha->tgt.atio_q_length * sizeof(request_t); |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 2945 | /* Allocate memory for Fibre Channel Event Buffer. */ |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 2946 | if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) && |
| 2947 | !IS_QLA27XX(ha)) |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 2948 | goto try_eft; |
| 2949 | |
Giridhar Malavali | 7d9dade | 2009-03-24 09:07:58 -0700 | [diff] [blame] | 2950 | fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE; |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 2951 | try_eft: |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 2952 | ql_dbg(ql_dbg_init, vha, 0x00c3, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2953 | "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2954 | eft_size = EFT_SIZE; |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2955 | } |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 2956 | |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 2957 | if (IS_QLA27XX(ha)) { |
| 2958 | if (!ha->fw_dump_template) { |
| 2959 | ql_log(ql_log_warn, vha, 0x00ba, |
| 2960 | "Failed missing fwdump template\n"); |
| 2961 | return; |
| 2962 | } |
| 2963 | dump_size = qla27xx_fwdt_calculate_dump_size(vha); |
| 2964 | ql_dbg(ql_dbg_init, vha, 0x00fa, |
| 2965 | "-> allocating fwdump (%x bytes)...\n", dump_size); |
| 2966 | goto allocate; |
| 2967 | } |
| 2968 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2969 | req_q_size = req->length * sizeof(request_t); |
| 2970 | rsp_q_size = rsp->length * sizeof(response_t); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2971 | dump_size = offsetof(struct qla2xxx_fw_dump, isp); |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 2972 | dump_size += fixed_size + mem_size + req_q_size + rsp_q_size + eft_size; |
Andrew Vasquez | bb99de6 | 2009-01-05 11:18:08 -0800 | [diff] [blame] | 2973 | ha->chain_offset = dump_size; |
| 2974 | dump_size += mq_size + fce_size; |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2975 | |
Quinn Tran | b945e77 | 2017-06-13 20:47:29 -0700 | [diff] [blame] | 2976 | if (ha->exchoffld_buf) |
| 2977 | dump_size += sizeof(struct qla2xxx_offld_chain) + |
| 2978 | ha->exchoffld_size; |
| 2979 | if (ha->exlogin_buf) |
| 2980 | dump_size += sizeof(struct qla2xxx_offld_chain) + |
| 2981 | ha->exlogin_size; |
| 2982 | |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 2983 | allocate: |
Quinn Tran | ad0a0b0 | 2017-12-28 12:33:14 -0800 | [diff] [blame] | 2984 | if (!ha->fw_dump_len || dump_size != ha->fw_dump_len) { |
| 2985 | fw_dump = vmalloc(dump_size); |
| 2986 | if (!fw_dump) { |
| 2987 | ql_log(ql_log_warn, vha, 0x00c4, |
| 2988 | "Unable to allocate (%d KB) for firmware dump.\n", |
| 2989 | dump_size / 1024); |
| 2990 | } else { |
| 2991 | if (ha->fw_dump) |
| 2992 | vfree(ha->fw_dump); |
| 2993 | ha->fw_dump = fw_dump; |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2994 | |
Quinn Tran | ad0a0b0 | 2017-12-28 12:33:14 -0800 | [diff] [blame] | 2995 | ha->fw_dump_len = dump_size; |
| 2996 | ql_dbg(ql_dbg_init, vha, 0x00c5, |
| 2997 | "Allocated (%d KB) for firmware dump.\n", |
| 2998 | dump_size / 1024); |
Madhuranath Iyengar | e30d175 | 2010-10-15 11:27:46 -0700 | [diff] [blame] | 2999 | |
Quinn Tran | ad0a0b0 | 2017-12-28 12:33:14 -0800 | [diff] [blame] | 3000 | if (IS_QLA27XX(ha)) |
| 3001 | return; |
| 3002 | |
| 3003 | ha->fw_dump->signature[0] = 'Q'; |
| 3004 | ha->fw_dump->signature[1] = 'L'; |
| 3005 | ha->fw_dump->signature[2] = 'G'; |
| 3006 | ha->fw_dump->signature[3] = 'C'; |
| 3007 | ha->fw_dump->version = htonl(1); |
| 3008 | |
| 3009 | ha->fw_dump->fixed_size = htonl(fixed_size); |
| 3010 | ha->fw_dump->mem_size = htonl(mem_size); |
| 3011 | ha->fw_dump->req_q_size = htonl(req_q_size); |
| 3012 | ha->fw_dump->rsp_q_size = htonl(rsp_q_size); |
| 3013 | |
| 3014 | ha->fw_dump->eft_size = htonl(eft_size); |
| 3015 | ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma)); |
| 3016 | ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma)); |
| 3017 | |
| 3018 | ha->fw_dump->header_size = |
| 3019 | htonl(offsetof(struct qla2xxx_fw_dump, isp)); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 3020 | } |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 3021 | } |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3022 | } |
| 3023 | |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 3024 | static int |
| 3025 | qla81xx_mpi_sync(scsi_qla_host_t *vha) |
| 3026 | { |
| 3027 | #define MPS_MASK 0xe0 |
| 3028 | int rval; |
| 3029 | uint16_t dc; |
| 3030 | uint32_t dw; |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 3031 | |
| 3032 | if (!IS_QLA81XX(vha->hw)) |
| 3033 | return QLA_SUCCESS; |
| 3034 | |
| 3035 | rval = qla2x00_write_ram_word(vha, 0x7c00, 1); |
| 3036 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3037 | ql_log(ql_log_warn, vha, 0x0105, |
| 3038 | "Unable to acquire semaphore.\n"); |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 3039 | goto done; |
| 3040 | } |
| 3041 | |
| 3042 | pci_read_config_word(vha->hw->pdev, 0x54, &dc); |
| 3043 | rval = qla2x00_read_ram_word(vha, 0x7a15, &dw); |
| 3044 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3045 | ql_log(ql_log_warn, vha, 0x0067, "Unable to read sync.\n"); |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 3046 | goto done_release; |
| 3047 | } |
| 3048 | |
| 3049 | dc &= MPS_MASK; |
| 3050 | if (dc == (dw & MPS_MASK)) |
| 3051 | goto done_release; |
| 3052 | |
| 3053 | dw &= ~MPS_MASK; |
| 3054 | dw |= dc; |
| 3055 | rval = qla2x00_write_ram_word(vha, 0x7a15, dw); |
| 3056 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3057 | ql_log(ql_log_warn, vha, 0x0114, "Unable to gain sync.\n"); |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 3058 | } |
| 3059 | |
| 3060 | done_release: |
| 3061 | rval = qla2x00_write_ram_word(vha, 0x7c00, 0); |
| 3062 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3063 | ql_log(ql_log_warn, vha, 0x006d, |
| 3064 | "Unable to release semaphore.\n"); |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 3065 | } |
| 3066 | |
| 3067 | done: |
| 3068 | return rval; |
| 3069 | } |
| 3070 | |
Chad Dupuis | 8d93f55 | 2013-01-30 03:34:37 -0500 | [diff] [blame] | 3071 | int |
| 3072 | qla2x00_alloc_outstanding_cmds(struct qla_hw_data *ha, struct req_que *req) |
| 3073 | { |
| 3074 | /* Don't try to reallocate the array */ |
| 3075 | if (req->outstanding_cmds) |
| 3076 | return QLA_SUCCESS; |
| 3077 | |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 3078 | if (!IS_FWI2_CAPABLE(ha)) |
Chad Dupuis | 8d93f55 | 2013-01-30 03:34:37 -0500 | [diff] [blame] | 3079 | req->num_outstanding_cmds = DEFAULT_OUTSTANDING_COMMANDS; |
| 3080 | else { |
Quinn Tran | 03e8c68 | 2015-12-17 14:56:59 -0500 | [diff] [blame] | 3081 | if (ha->cur_fw_xcb_count <= ha->cur_fw_iocb_count) |
| 3082 | req->num_outstanding_cmds = ha->cur_fw_xcb_count; |
Chad Dupuis | 8d93f55 | 2013-01-30 03:34:37 -0500 | [diff] [blame] | 3083 | else |
Quinn Tran | 03e8c68 | 2015-12-17 14:56:59 -0500 | [diff] [blame] | 3084 | req->num_outstanding_cmds = ha->cur_fw_iocb_count; |
Chad Dupuis | 8d93f55 | 2013-01-30 03:34:37 -0500 | [diff] [blame] | 3085 | } |
| 3086 | |
| 3087 | req->outstanding_cmds = kzalloc(sizeof(srb_t *) * |
| 3088 | req->num_outstanding_cmds, GFP_KERNEL); |
| 3089 | |
| 3090 | if (!req->outstanding_cmds) { |
| 3091 | /* |
| 3092 | * Try to allocate a minimal size just so we can get through |
| 3093 | * initialization. |
| 3094 | */ |
| 3095 | req->num_outstanding_cmds = MIN_OUTSTANDING_COMMANDS; |
| 3096 | req->outstanding_cmds = kzalloc(sizeof(srb_t *) * |
| 3097 | req->num_outstanding_cmds, GFP_KERNEL); |
| 3098 | |
| 3099 | if (!req->outstanding_cmds) { |
| 3100 | ql_log(ql_log_fatal, NULL, 0x0126, |
| 3101 | "Failed to allocate memory for " |
| 3102 | "outstanding_cmds for req_que %p.\n", req); |
| 3103 | req->num_outstanding_cmds = 0; |
| 3104 | return QLA_FUNCTION_FAILED; |
| 3105 | } |
| 3106 | } |
| 3107 | |
| 3108 | return QLA_SUCCESS; |
| 3109 | } |
| 3110 | |
Quinn Tran | e4e3a2c | 2017-08-23 15:05:07 -0700 | [diff] [blame] | 3111 | #define PRINT_FIELD(_field, _flag, _str) { \ |
| 3112 | if (a0->_field & _flag) {\ |
| 3113 | if (p) {\ |
| 3114 | strcat(ptr, "|");\ |
| 3115 | ptr++;\ |
| 3116 | leftover--;\ |
| 3117 | } \ |
| 3118 | len = snprintf(ptr, leftover, "%s", _str); \ |
| 3119 | p = 1;\ |
| 3120 | leftover -= len;\ |
| 3121 | ptr += len; \ |
| 3122 | } \ |
| 3123 | } |
| 3124 | |
| 3125 | static void qla2xxx_print_sfp_info(struct scsi_qla_host *vha) |
| 3126 | { |
| 3127 | #define STR_LEN 64 |
| 3128 | struct sff_8247_a0 *a0 = (struct sff_8247_a0 *)vha->hw->sfp_data; |
| 3129 | u8 str[STR_LEN], *ptr, p; |
| 3130 | int leftover, len; |
| 3131 | |
| 3132 | memset(str, 0, STR_LEN); |
| 3133 | snprintf(str, SFF_VEN_NAME_LEN+1, a0->vendor_name); |
| 3134 | ql_dbg(ql_dbg_init, vha, 0x015a, |
| 3135 | "SFP MFG Name: %s\n", str); |
| 3136 | |
| 3137 | memset(str, 0, STR_LEN); |
| 3138 | snprintf(str, SFF_PART_NAME_LEN+1, a0->vendor_pn); |
| 3139 | ql_dbg(ql_dbg_init, vha, 0x015c, |
| 3140 | "SFP Part Name: %s\n", str); |
| 3141 | |
| 3142 | /* media */ |
| 3143 | memset(str, 0, STR_LEN); |
| 3144 | ptr = str; |
| 3145 | leftover = STR_LEN; |
| 3146 | p = len = 0; |
| 3147 | PRINT_FIELD(fc_med_cc9, FC_MED_TW, "Twin AX"); |
| 3148 | PRINT_FIELD(fc_med_cc9, FC_MED_TP, "Twisted Pair"); |
| 3149 | PRINT_FIELD(fc_med_cc9, FC_MED_MI, "Min Coax"); |
| 3150 | PRINT_FIELD(fc_med_cc9, FC_MED_TV, "Video Coax"); |
| 3151 | PRINT_FIELD(fc_med_cc9, FC_MED_M6, "MultiMode 62.5um"); |
| 3152 | PRINT_FIELD(fc_med_cc9, FC_MED_M5, "MultiMode 50um"); |
| 3153 | PRINT_FIELD(fc_med_cc9, FC_MED_SM, "SingleMode"); |
| 3154 | ql_dbg(ql_dbg_init, vha, 0x0160, |
| 3155 | "SFP Media: %s\n", str); |
| 3156 | |
| 3157 | /* link length */ |
| 3158 | memset(str, 0, STR_LEN); |
| 3159 | ptr = str; |
| 3160 | leftover = STR_LEN; |
| 3161 | p = len = 0; |
| 3162 | PRINT_FIELD(fc_ll_cc7, FC_LL_VL, "Very Long"); |
| 3163 | PRINT_FIELD(fc_ll_cc7, FC_LL_S, "Short"); |
| 3164 | PRINT_FIELD(fc_ll_cc7, FC_LL_I, "Intermediate"); |
| 3165 | PRINT_FIELD(fc_ll_cc7, FC_LL_L, "Long"); |
| 3166 | PRINT_FIELD(fc_ll_cc7, FC_LL_M, "Medium"); |
| 3167 | ql_dbg(ql_dbg_init, vha, 0x0196, |
| 3168 | "SFP Link Length: %s\n", str); |
| 3169 | |
| 3170 | memset(str, 0, STR_LEN); |
| 3171 | ptr = str; |
| 3172 | leftover = STR_LEN; |
| 3173 | p = len = 0; |
| 3174 | PRINT_FIELD(fc_ll_cc7, FC_LL_SA, "Short Wave (SA)"); |
| 3175 | PRINT_FIELD(fc_ll_cc7, FC_LL_LC, "Long Wave(LC)"); |
| 3176 | PRINT_FIELD(fc_tec_cc8, FC_TEC_SN, "Short Wave (SN)"); |
| 3177 | PRINT_FIELD(fc_tec_cc8, FC_TEC_SL, "Short Wave (SL)"); |
| 3178 | PRINT_FIELD(fc_tec_cc8, FC_TEC_LL, "Long Wave (LL)"); |
| 3179 | ql_dbg(ql_dbg_init, vha, 0x016e, |
| 3180 | "SFP FC Link Tech: %s\n", str); |
| 3181 | |
| 3182 | if (a0->length_km) |
| 3183 | ql_dbg(ql_dbg_init, vha, 0x016f, |
| 3184 | "SFP Distant: %d km\n", a0->length_km); |
| 3185 | if (a0->length_100m) |
| 3186 | ql_dbg(ql_dbg_init, vha, 0x0170, |
| 3187 | "SFP Distant: %d m\n", a0->length_100m*100); |
| 3188 | if (a0->length_50um_10m) |
| 3189 | ql_dbg(ql_dbg_init, vha, 0x0189, |
| 3190 | "SFP Distant (WL=50um): %d m\n", a0->length_50um_10m * 10); |
| 3191 | if (a0->length_62um_10m) |
| 3192 | ql_dbg(ql_dbg_init, vha, 0x018a, |
| 3193 | "SFP Distant (WL=62.5um): %d m\n", a0->length_62um_10m * 10); |
| 3194 | if (a0->length_om4_10m) |
| 3195 | ql_dbg(ql_dbg_init, vha, 0x0194, |
| 3196 | "SFP Distant (OM4): %d m\n", a0->length_om4_10m * 10); |
| 3197 | if (a0->length_om3_10m) |
| 3198 | ql_dbg(ql_dbg_init, vha, 0x0195, |
| 3199 | "SFP Distant (OM3): %d m\n", a0->length_om3_10m * 10); |
| 3200 | } |
| 3201 | |
| 3202 | |
| 3203 | /* |
| 3204 | * Return Code: |
| 3205 | * QLA_SUCCESS: no action |
| 3206 | * QLA_INTERFACE_ERROR: SFP is not there. |
| 3207 | * QLA_FUNCTION_FAILED: detected New SFP |
| 3208 | */ |
| 3209 | int |
| 3210 | qla24xx_detect_sfp(scsi_qla_host_t *vha) |
| 3211 | { |
| 3212 | int rc = QLA_SUCCESS; |
| 3213 | struct sff_8247_a0 *a; |
| 3214 | struct qla_hw_data *ha = vha->hw; |
| 3215 | |
| 3216 | if (!AUTO_DETECT_SFP_SUPPORT(vha)) |
| 3217 | goto out; |
| 3218 | |
| 3219 | rc = qla2x00_read_sfp_dev(vha, NULL, 0); |
| 3220 | if (rc) |
| 3221 | goto out; |
| 3222 | |
| 3223 | a = (struct sff_8247_a0 *)vha->hw->sfp_data; |
| 3224 | qla2xxx_print_sfp_info(vha); |
| 3225 | |
| 3226 | if (a->fc_ll_cc7 & FC_LL_VL || a->fc_ll_cc7 & FC_LL_L) { |
| 3227 | /* long range */ |
| 3228 | ha->flags.detected_lr_sfp = 1; |
| 3229 | |
| 3230 | if (a->length_km > 5 || a->length_100m > 50) |
| 3231 | ha->long_range_distance = LR_DISTANCE_10K; |
| 3232 | else |
| 3233 | ha->long_range_distance = LR_DISTANCE_5K; |
| 3234 | |
| 3235 | if (ha->flags.detected_lr_sfp != ha->flags.using_lr_setting) |
| 3236 | ql_dbg(ql_dbg_async, vha, 0x507b, |
| 3237 | "Detected Long Range SFP.\n"); |
| 3238 | } else { |
| 3239 | /* short range */ |
| 3240 | ha->flags.detected_lr_sfp = 0; |
| 3241 | if (ha->flags.using_lr_setting) |
| 3242 | ql_dbg(ql_dbg_async, vha, 0x5084, |
| 3243 | "Detected Short Range SFP.\n"); |
| 3244 | } |
| 3245 | |
| 3246 | if (!vha->flags.init_done) |
| 3247 | rc = QLA_SUCCESS; |
| 3248 | out: |
| 3249 | return rc; |
| 3250 | } |
| 3251 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3252 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3253 | * qla2x00_setup_chip() - Load and start RISC firmware. |
| 3254 | * @ha: HA context |
| 3255 | * |
| 3256 | * Returns 0 on success. |
| 3257 | */ |
| 3258 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3259 | qla2x00_setup_chip(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3260 | { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3261 | int rval; |
| 3262 | uint32_t srisc_address = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3263 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3db0652 | 2008-01-31 12:33:49 -0800 | [diff] [blame] | 3264 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
| 3265 | unsigned long flags; |
Andrew Vasquez | dda772e | 2009-03-24 09:08:00 -0700 | [diff] [blame] | 3266 | uint16_t fw_major_version; |
Andrew Vasquez | 3db0652 | 2008-01-31 12:33:49 -0800 | [diff] [blame] | 3267 | |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 3268 | if (IS_P3P_TYPE(ha)) { |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 3269 | rval = ha->isp_ops->load_risc(vha, &srisc_address); |
Andrew Vasquez | 14e303d | 2010-07-23 15:28:29 +0500 | [diff] [blame] | 3270 | if (rval == QLA_SUCCESS) { |
| 3271 | qla2x00_stop_firmware(vha); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 3272 | goto enable_82xx_npiv; |
Andrew Vasquez | 14e303d | 2010-07-23 15:28:29 +0500 | [diff] [blame] | 3273 | } else |
Giridhar Malavali | b963752 | 2010-05-28 15:08:15 -0700 | [diff] [blame] | 3274 | goto failed; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 3275 | } |
| 3276 | |
Andrew Vasquez | 3db0652 | 2008-01-31 12:33:49 -0800 | [diff] [blame] | 3277 | if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) { |
| 3278 | /* Disable SRAM, Instruction RAM and GP RAM parity. */ |
| 3279 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 3280 | WRT_REG_WORD(®->hccr, (HCCR_ENABLE_PARITY + 0x0)); |
| 3281 | RD_REG_WORD(®->hccr); |
| 3282 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 3283 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3284 | |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 3285 | qla81xx_mpi_sync(vha); |
| 3286 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3287 | /* Load firmware sequences */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3288 | rval = ha->isp_ops->load_risc(vha, &srisc_address); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3289 | if (rval == QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3290 | ql_dbg(ql_dbg_init, vha, 0x00c9, |
| 3291 | "Verifying Checksum of loaded RISC code.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3292 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3293 | rval = qla2x00_verify_checksum(vha, srisc_address); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3294 | if (rval == QLA_SUCCESS) { |
| 3295 | /* Start firmware execution. */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3296 | ql_dbg(ql_dbg_init, vha, 0x00ca, |
| 3297 | "Starting firmware.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3298 | |
Himanshu Madhani | b0d6cab | 2015-12-17 14:56:56 -0500 | [diff] [blame] | 3299 | if (ql2xexlogins) |
| 3300 | ha->flags.exlogins_enabled = 1; |
| 3301 | |
Quinn Tran | 99e1b68 | 2017-06-02 09:12:03 -0700 | [diff] [blame] | 3302 | if (qla_is_exch_offld_enabled(vha)) |
Himanshu Madhani | 2f56a7f | 2015-12-17 14:56:57 -0500 | [diff] [blame] | 3303 | ha->flags.exchoffld_enabled = 1; |
| 3304 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3305 | rval = qla2x00_execute_fw(vha, srisc_address); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3306 | /* Retrieve firmware information. */ |
Andrew Vasquez | dda772e | 2009-03-24 09:08:00 -0700 | [diff] [blame] | 3307 | if (rval == QLA_SUCCESS) { |
Quinn Tran | e4e3a2c | 2017-08-23 15:05:07 -0700 | [diff] [blame] | 3308 | qla24xx_detect_sfp(vha); |
| 3309 | |
Himanshu Madhani | b0d6cab | 2015-12-17 14:56:56 -0500 | [diff] [blame] | 3310 | rval = qla2x00_set_exlogins_buffer(vha); |
| 3311 | if (rval != QLA_SUCCESS) |
| 3312 | goto failed; |
| 3313 | |
Himanshu Madhani | 2f56a7f | 2015-12-17 14:56:57 -0500 | [diff] [blame] | 3314 | rval = qla2x00_set_exchoffld_buffer(vha); |
| 3315 | if (rval != QLA_SUCCESS) |
| 3316 | goto failed; |
| 3317 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 3318 | enable_82xx_npiv: |
Andrew Vasquez | dda772e | 2009-03-24 09:08:00 -0700 | [diff] [blame] | 3319 | fw_major_version = ha->fw_major_version; |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 3320 | if (IS_P3P_TYPE(ha)) |
Giridhar Malavali | 3173167 | 2011-08-16 11:31:54 -0700 | [diff] [blame] | 3321 | qla82xx_check_md_needed(vha); |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 3322 | else |
| 3323 | rval = qla2x00_get_fw_version(vha); |
Andrew Vasquez | ca9e9c3 | 2009-06-03 09:55:20 -0700 | [diff] [blame] | 3324 | if (rval != QLA_SUCCESS) |
| 3325 | goto failed; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3326 | ha->flags.npiv_supported = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3327 | if (IS_QLA2XXX_MIDTYPE(ha) && |
Mike Hernandez | 946fb89 | 2008-08-13 21:36:59 -0700 | [diff] [blame] | 3328 | (ha->fw_attributes & BIT_2)) { |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3329 | ha->flags.npiv_supported = 1; |
Seokmann Ju | 4d0ea24 | 2007-09-20 14:07:43 -0700 | [diff] [blame] | 3330 | if ((!ha->max_npiv_vports) || |
| 3331 | ((ha->max_npiv_vports + 1) % |
Andrew Vasquez | eb66dc6 | 2007-11-12 10:30:58 -0800 | [diff] [blame] | 3332 | MIN_MULTI_ID_FABRIC)) |
Seokmann Ju | 4d0ea24 | 2007-09-20 14:07:43 -0700 | [diff] [blame] | 3333 | ha->max_npiv_vports = |
Andrew Vasquez | eb66dc6 | 2007-11-12 10:30:58 -0800 | [diff] [blame] | 3334 | MIN_MULTI_ID_FABRIC - 1; |
Seokmann Ju | 4d0ea24 | 2007-09-20 14:07:43 -0700 | [diff] [blame] | 3335 | } |
Quinn Tran | 03e8c68 | 2015-12-17 14:56:59 -0500 | [diff] [blame] | 3336 | qla2x00_get_resource_cnts(vha); |
Andrew Vasquez | d743de6 | 2009-03-24 09:08:15 -0700 | [diff] [blame] | 3337 | |
Chad Dupuis | 8d93f55 | 2013-01-30 03:34:37 -0500 | [diff] [blame] | 3338 | /* |
| 3339 | * Allocate the array of outstanding commands |
| 3340 | * now that we know the firmware resources. |
| 3341 | */ |
| 3342 | rval = qla2x00_alloc_outstanding_cmds(ha, |
| 3343 | vha->req); |
| 3344 | if (rval != QLA_SUCCESS) |
| 3345 | goto failed; |
| 3346 | |
Quinn Tran | ad0a0b0 | 2017-12-28 12:33:14 -0800 | [diff] [blame] | 3347 | if (!fw_major_version && !(IS_P3P_TYPE(ha))) |
| 3348 | qla2x00_alloc_offload_mem(vha); |
| 3349 | |
| 3350 | if (ql2xallocfwdump && !(IS_P3P_TYPE(ha))) |
Giridhar Malavali | 08de284 | 2011-08-16 11:31:44 -0700 | [diff] [blame] | 3351 | qla2x00_alloc_fw_dump(vha); |
Quinn Tran | ad0a0b0 | 2017-12-28 12:33:14 -0800 | [diff] [blame] | 3352 | |
Chad Dupuis | 3b6e5b9 | 2013-10-30 03:38:09 -0400 | [diff] [blame] | 3353 | } else { |
| 3354 | goto failed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3355 | } |
| 3356 | } else { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3357 | ql_log(ql_log_fatal, vha, 0x00cd, |
| 3358 | "ISP Firmware failed checksum.\n"); |
| 3359 | goto failed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3360 | } |
Andrew Vasquez | c74d88a | 2012-08-22 14:21:19 -0400 | [diff] [blame] | 3361 | } else |
| 3362 | goto failed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3363 | |
Andrew Vasquez | 3db0652 | 2008-01-31 12:33:49 -0800 | [diff] [blame] | 3364 | if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) { |
| 3365 | /* Enable proper parity. */ |
| 3366 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 3367 | if (IS_QLA2300(ha)) |
| 3368 | /* SRAM parity */ |
| 3369 | WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x1); |
| 3370 | else |
| 3371 | /* SRAM, Instruction RAM and GP RAM parity */ |
| 3372 | WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x7); |
| 3373 | RD_REG_WORD(®->hccr); |
| 3374 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 3375 | } |
| 3376 | |
Chad Dupuis | f3982d8 | 2014-09-25 05:16:57 -0400 | [diff] [blame] | 3377 | if (IS_QLA27XX(ha)) |
| 3378 | ha->flags.fac_supported = 1; |
| 3379 | else if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) { |
Joe Carnuccio | 1d2874d | 2009-03-24 09:08:06 -0700 | [diff] [blame] | 3380 | uint32_t size; |
| 3381 | |
| 3382 | rval = qla81xx_fac_get_sector_size(vha, &size); |
| 3383 | if (rval == QLA_SUCCESS) { |
| 3384 | ha->flags.fac_supported = 1; |
| 3385 | ha->fdt_block_size = size << 2; |
| 3386 | } else { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3387 | ql_log(ql_log_warn, vha, 0x00ce, |
Joe Carnuccio | 1d2874d | 2009-03-24 09:08:06 -0700 | [diff] [blame] | 3388 | "Unsupported FAC firmware (%d.%02d.%02d).\n", |
| 3389 | ha->fw_major_version, ha->fw_minor_version, |
| 3390 | ha->fw_subminor_version); |
Joe Carnuccio | 1ca60e3 | 2014-02-26 04:15:02 -0500 | [diff] [blame] | 3391 | |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 3392 | if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) { |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 3393 | ha->flags.fac_supported = 0; |
| 3394 | rval = QLA_SUCCESS; |
| 3395 | } |
Joe Carnuccio | 1d2874d | 2009-03-24 09:08:06 -0700 | [diff] [blame] | 3396 | } |
| 3397 | } |
Andrew Vasquez | ca9e9c3 | 2009-06-03 09:55:20 -0700 | [diff] [blame] | 3398 | failed: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3399 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3400 | ql_log(ql_log_fatal, vha, 0x00cf, |
| 3401 | "Setup chip ****FAILED****.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3402 | } |
| 3403 | |
| 3404 | return (rval); |
| 3405 | } |
| 3406 | |
| 3407 | /** |
| 3408 | * qla2x00_init_response_q_entries() - Initializes response queue entries. |
| 3409 | * @ha: HA context |
| 3410 | * |
| 3411 | * Beginning of request ring has initialization control block already built |
| 3412 | * by nvram config routine. |
| 3413 | * |
| 3414 | * Returns 0 on success. |
| 3415 | */ |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3416 | void |
| 3417 | qla2x00_init_response_q_entries(struct rsp_que *rsp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3418 | { |
| 3419 | uint16_t cnt; |
| 3420 | response_t *pkt; |
| 3421 | |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 3422 | rsp->ring_ptr = rsp->ring; |
| 3423 | rsp->ring_index = 0; |
| 3424 | rsp->status_srb = NULL; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3425 | pkt = rsp->ring_ptr; |
| 3426 | for (cnt = 0; cnt < rsp->length; cnt++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3427 | pkt->signature = RESPONSE_PROCESSED; |
| 3428 | pkt++; |
| 3429 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3430 | } |
| 3431 | |
| 3432 | /** |
| 3433 | * qla2x00_update_fw_options() - Read and process firmware options. |
| 3434 | * @ha: HA context |
| 3435 | * |
| 3436 | * Returns 0 on success. |
| 3437 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 3438 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3439 | qla2x00_update_fw_options(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3440 | { |
| 3441 | uint16_t swing, emphasis, tx_sens, rx_sens; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3442 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3443 | |
| 3444 | memset(ha->fw_options, 0, sizeof(ha->fw_options)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3445 | qla2x00_get_fw_options(vha, ha->fw_options); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3446 | |
| 3447 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) |
| 3448 | return; |
| 3449 | |
| 3450 | /* Serial Link options. */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3451 | ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0115, |
| 3452 | "Serial link options.\n"); |
| 3453 | ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0109, |
| 3454 | (uint8_t *)&ha->fw_seriallink_options, |
| 3455 | sizeof(ha->fw_seriallink_options)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3456 | |
| 3457 | ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING; |
| 3458 | if (ha->fw_seriallink_options[3] & BIT_2) { |
| 3459 | ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING; |
| 3460 | |
| 3461 | /* 1G settings */ |
| 3462 | swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0); |
| 3463 | emphasis = (ha->fw_seriallink_options[2] & |
| 3464 | (BIT_4 | BIT_3)) >> 3; |
| 3465 | tx_sens = ha->fw_seriallink_options[0] & |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 3466 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3467 | rx_sens = (ha->fw_seriallink_options[0] & |
| 3468 | (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4; |
| 3469 | ha->fw_options[10] = (emphasis << 14) | (swing << 8); |
| 3470 | if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) { |
| 3471 | if (rx_sens == 0x0) |
| 3472 | rx_sens = 0x3; |
| 3473 | ha->fw_options[10] |= (tx_sens << 4) | rx_sens; |
| 3474 | } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) |
| 3475 | ha->fw_options[10] |= BIT_5 | |
| 3476 | ((rx_sens & (BIT_1 | BIT_0)) << 2) | |
| 3477 | (tx_sens & (BIT_1 | BIT_0)); |
| 3478 | |
| 3479 | /* 2G settings */ |
| 3480 | swing = (ha->fw_seriallink_options[2] & |
| 3481 | (BIT_7 | BIT_6 | BIT_5)) >> 5; |
| 3482 | emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0); |
| 3483 | tx_sens = ha->fw_seriallink_options[1] & |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 3484 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3485 | rx_sens = (ha->fw_seriallink_options[1] & |
| 3486 | (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4; |
| 3487 | ha->fw_options[11] = (emphasis << 14) | (swing << 8); |
| 3488 | if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) { |
| 3489 | if (rx_sens == 0x0) |
| 3490 | rx_sens = 0x3; |
| 3491 | ha->fw_options[11] |= (tx_sens << 4) | rx_sens; |
| 3492 | } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) |
| 3493 | ha->fw_options[11] |= BIT_5 | |
| 3494 | ((rx_sens & (BIT_1 | BIT_0)) << 2) | |
| 3495 | (tx_sens & (BIT_1 | BIT_0)); |
| 3496 | } |
| 3497 | |
| 3498 | /* FCP2 options. */ |
| 3499 | /* Return command IOCBs without waiting for an ABTS to complete. */ |
| 3500 | ha->fw_options[3] |= BIT_13; |
| 3501 | |
| 3502 | /* LED scheme. */ |
| 3503 | if (ha->flags.enable_led_scheme) |
| 3504 | ha->fw_options[2] |= BIT_12; |
| 3505 | |
andrew.vasquez@qlogic.com | 48c02fd | 2006-03-09 14:27:18 -0800 | [diff] [blame] | 3506 | /* Detect ISP6312. */ |
| 3507 | if (IS_QLA6312(ha)) |
| 3508 | ha->fw_options[2] |= BIT_13; |
| 3509 | |
Giridhar Malavali | 088d09d | 2016-07-06 11:14:20 -0400 | [diff] [blame] | 3510 | /* Set Retry FLOGI in case of P2P connection */ |
| 3511 | if (ha->operating_mode == P2P) { |
| 3512 | ha->fw_options[2] |= BIT_3; |
| 3513 | ql_dbg(ql_dbg_disc, vha, 0x2100, |
| 3514 | "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n", |
| 3515 | __func__, ha->fw_options[2]); |
| 3516 | } |
| 3517 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3518 | /* Update firmware options. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3519 | qla2x00_set_fw_options(vha, ha->fw_options); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3520 | } |
| 3521 | |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 3522 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3523 | qla24xx_update_fw_options(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3524 | { |
| 3525 | int rval; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3526 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3527 | |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 3528 | if (IS_P3P_TYPE(ha)) |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 3529 | return; |
| 3530 | |
Himanshu Madhani | f198caf | 2016-01-27 12:03:30 -0500 | [diff] [blame] | 3531 | /* Hold status IOCBs until ABTS response received. */ |
| 3532 | if (ql2xfwholdabts) |
| 3533 | ha->fw_options[3] |= BIT_12; |
| 3534 | |
Giridhar Malavali | 088d09d | 2016-07-06 11:14:20 -0400 | [diff] [blame] | 3535 | /* Set Retry FLOGI in case of P2P connection */ |
| 3536 | if (ha->operating_mode == P2P) { |
| 3537 | ha->fw_options[2] |= BIT_3; |
| 3538 | ql_dbg(ql_dbg_disc, vha, 0x2101, |
| 3539 | "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n", |
| 3540 | __func__, ha->fw_options[2]); |
| 3541 | } |
| 3542 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 3543 | /* Move PUREX, ABTS RX & RIDA to ATIOQ */ |
Quinn Tran | 3c4810f | 2017-06-02 09:11:53 -0700 | [diff] [blame] | 3544 | if (ql2xmvasynctoatio && |
| 3545 | (IS_QLA83XX(ha) || IS_QLA27XX(ha))) { |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 3546 | if (qla_tgt_mode_enabled(vha) || |
| 3547 | qla_dual_mode_enabled(vha)) |
| 3548 | ha->fw_options[2] |= BIT_11; |
| 3549 | else |
| 3550 | ha->fw_options[2] &= ~BIT_11; |
| 3551 | } |
| 3552 | |
Quinn Tran | f7e761f | 2017-06-02 09:12:02 -0700 | [diff] [blame] | 3553 | if (IS_QLA25XX(ha) || IS_QLA83XX(ha) || IS_QLA27XX(ha)) { |
| 3554 | /* |
| 3555 | * Tell FW to track each exchange to prevent |
| 3556 | * driver from using stale exchange. |
| 3557 | */ |
| 3558 | if (qla_tgt_mode_enabled(vha) || |
| 3559 | qla_dual_mode_enabled(vha)) |
| 3560 | ha->fw_options[2] |= BIT_4; |
| 3561 | else |
| 3562 | ha->fw_options[2] &= ~BIT_4; |
Quinn Tran | 9ecf0b0 | 2017-12-28 12:33:19 -0800 | [diff] [blame] | 3563 | |
| 3564 | /* Reserve 1/2 of emergency exchanges for ELS.*/ |
| 3565 | if (qla2xuseresexchforels) |
| 3566 | ha->fw_options[2] |= BIT_8; |
| 3567 | else |
| 3568 | ha->fw_options[2] &= ~BIT_8; |
Quinn Tran | f7e761f | 2017-06-02 09:12:02 -0700 | [diff] [blame] | 3569 | } |
| 3570 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 3571 | ql_dbg(ql_dbg_init, vha, 0x00e8, |
| 3572 | "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n", |
| 3573 | __func__, ha->fw_options[1], ha->fw_options[2], |
| 3574 | ha->fw_options[3], vha->host->active_mode); |
Quinn Tran | 3c4810f | 2017-06-02 09:11:53 -0700 | [diff] [blame] | 3575 | |
| 3576 | if (ha->fw_options[1] || ha->fw_options[2] || ha->fw_options[3]) |
| 3577 | qla2x00_set_fw_options(vha, ha->fw_options); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 3578 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3579 | /* Update Serial Link options. */ |
andrew.vasquez@qlogic.com | f94097e | 2006-01-13 17:05:32 -0800 | [diff] [blame] | 3580 | if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3581 | return; |
| 3582 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3583 | rval = qla2x00_set_serdes_params(vha, |
andrew.vasquez@qlogic.com | f94097e | 2006-01-13 17:05:32 -0800 | [diff] [blame] | 3584 | le16_to_cpu(ha->fw_seriallink_options24[1]), |
| 3585 | le16_to_cpu(ha->fw_seriallink_options24[2]), |
| 3586 | le16_to_cpu(ha->fw_seriallink_options24[3])); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3587 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3588 | ql_log(ql_log_warn, vha, 0x0104, |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3589 | "Unable to update Serial Link options (%x).\n", rval); |
| 3590 | } |
| 3591 | } |
| 3592 | |
| 3593 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3594 | qla2x00_config_rings(struct scsi_qla_host *vha) |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 3595 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3596 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 3597 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3598 | struct req_que *req = ha->req_q_map[0]; |
| 3599 | struct rsp_que *rsp = ha->rsp_q_map[0]; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 3600 | |
| 3601 | /* Setup ring parameters in initialization control block. */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3602 | ha->init_cb->request_q_outpointer = cpu_to_le16(0); |
| 3603 | ha->init_cb->response_q_inpointer = cpu_to_le16(0); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3604 | ha->init_cb->request_q_length = cpu_to_le16(req->length); |
| 3605 | ha->init_cb->response_q_length = cpu_to_le16(rsp->length); |
| 3606 | ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma)); |
| 3607 | ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma)); |
| 3608 | ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma)); |
| 3609 | ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma)); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 3610 | |
| 3611 | WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0); |
| 3612 | WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0); |
| 3613 | WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0); |
| 3614 | WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0); |
| 3615 | RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */ |
| 3616 | } |
| 3617 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3618 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3619 | qla24xx_config_rings(struct scsi_qla_host *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3620 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3621 | struct qla_hw_data *ha = vha->hw; |
Bart Van Assche | 118e2ef | 2015-07-09 07:24:27 -0700 | [diff] [blame] | 3622 | device_reg_t *reg = ISP_QUE_REG(ha, 0); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3623 | struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp; |
| 3624 | struct qla_msix_entry *msix; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3625 | struct init_cb_24xx *icb; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3626 | uint16_t rid = 0; |
| 3627 | struct req_que *req = ha->req_q_map[0]; |
| 3628 | struct rsp_que *rsp = ha->rsp_q_map[0]; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3629 | |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 3630 | /* Setup ring parameters in initialization control block. */ |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3631 | icb = (struct init_cb_24xx *)ha->init_cb; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3632 | icb->request_q_outpointer = cpu_to_le16(0); |
| 3633 | icb->response_q_inpointer = cpu_to_le16(0); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3634 | icb->request_q_length = cpu_to_le16(req->length); |
| 3635 | icb->response_q_length = cpu_to_le16(rsp->length); |
| 3636 | icb->request_q_address[0] = cpu_to_le32(LSD(req->dma)); |
| 3637 | icb->request_q_address[1] = cpu_to_le32(MSD(req->dma)); |
| 3638 | icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma)); |
| 3639 | icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma)); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3640 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3641 | /* Setup ATIO queue dma pointers for target mode */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3642 | icb->atio_q_inpointer = cpu_to_le16(0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3643 | icb->atio_q_length = cpu_to_le16(ha->tgt.atio_q_length); |
| 3644 | icb->atio_q_address[0] = cpu_to_le32(LSD(ha->tgt.atio_dma)); |
| 3645 | icb->atio_q_address[1] = cpu_to_le32(MSD(ha->tgt.atio_dma)); |
| 3646 | |
Joe Carnuccio | 7c6300e | 2014-04-11 16:54:37 -0400 | [diff] [blame] | 3647 | if (IS_SHADOW_REG_CAPABLE(ha)) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3648 | icb->firmware_options_2 |= cpu_to_le32(BIT_30|BIT_29); |
Joe Carnuccio | 7c6300e | 2014-04-11 16:54:37 -0400 | [diff] [blame] | 3649 | |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 3650 | if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha)) { |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3651 | icb->qos = cpu_to_le16(QLA_DEFAULT_QUE_QOS); |
| 3652 | icb->rid = cpu_to_le16(rid); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3653 | if (ha->flags.msix_enabled) { |
| 3654 | msix = &ha->msix_entries[1]; |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 3655 | ql_dbg(ql_dbg_init, vha, 0x0019, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3656 | "Registering vector 0x%x for base que.\n", |
| 3657 | msix->entry); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3658 | icb->msix = cpu_to_le16(msix->entry); |
| 3659 | } |
| 3660 | /* Use alternate PCI bus number */ |
| 3661 | if (MSB(rid)) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3662 | icb->firmware_options_2 |= cpu_to_le32(BIT_19); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3663 | /* Use alternate PCI devfn */ |
| 3664 | if (LSB(rid)) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3665 | icb->firmware_options_2 |= cpu_to_le32(BIT_18); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3666 | |
Anirban Chakraborty | 3155754 | 2009-12-02 10:36:55 -0800 | [diff] [blame] | 3667 | /* Use Disable MSIX Handshake mode for capable adapters */ |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 3668 | if ((ha->fw_attributes & BIT_6) && (IS_MSIX_NACK_CAPABLE(ha)) && |
| 3669 | (ha->flags.msix_enabled)) { |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3670 | icb->firmware_options_2 &= cpu_to_le32(~BIT_22); |
Anirban Chakraborty | 3155754 | 2009-12-02 10:36:55 -0800 | [diff] [blame] | 3671 | ha->flags.disable_msix_handshake = 1; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3672 | ql_dbg(ql_dbg_init, vha, 0x00fe, |
| 3673 | "MSIX Handshake Disable Mode turned on.\n"); |
Anirban Chakraborty | 3155754 | 2009-12-02 10:36:55 -0800 | [diff] [blame] | 3674 | } else { |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3675 | icb->firmware_options_2 |= cpu_to_le32(BIT_22); |
Anirban Chakraborty | 3155754 | 2009-12-02 10:36:55 -0800 | [diff] [blame] | 3676 | } |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3677 | icb->firmware_options_2 |= cpu_to_le32(BIT_23); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3678 | |
| 3679 | WRT_REG_DWORD(®->isp25mq.req_q_in, 0); |
| 3680 | WRT_REG_DWORD(®->isp25mq.req_q_out, 0); |
| 3681 | WRT_REG_DWORD(®->isp25mq.rsp_q_in, 0); |
| 3682 | WRT_REG_DWORD(®->isp25mq.rsp_q_out, 0); |
| 3683 | } else { |
| 3684 | WRT_REG_DWORD(®->isp24.req_q_in, 0); |
| 3685 | WRT_REG_DWORD(®->isp24.req_q_out, 0); |
| 3686 | WRT_REG_DWORD(®->isp24.rsp_q_in, 0); |
| 3687 | WRT_REG_DWORD(®->isp24.rsp_q_out, 0); |
| 3688 | } |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 3689 | qlt_24xx_config_rings(vha); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3690 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3691 | /* PCI posting */ |
| 3692 | RD_REG_DWORD(&ioreg->hccr); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3693 | } |
| 3694 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3695 | /** |
| 3696 | * qla2x00_init_rings() - Initializes firmware. |
| 3697 | * @ha: HA context |
| 3698 | * |
| 3699 | * Beginning of request ring has initialization control block already built |
| 3700 | * by nvram config routine. |
| 3701 | * |
| 3702 | * Returns 0 on success. |
| 3703 | */ |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 3704 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3705 | qla2x00_init_rings(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3706 | { |
| 3707 | int rval; |
| 3708 | unsigned long flags = 0; |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 3709 | int cnt, que; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3710 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 3711 | struct req_que *req; |
| 3712 | struct rsp_que *rsp; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3713 | struct mid_init_cb_24xx *mid_init_cb = |
| 3714 | (struct mid_init_cb_24xx *) ha->init_cb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3715 | |
| 3716 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 3717 | |
| 3718 | /* Clear outstanding commands array. */ |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 3719 | for (que = 0; que < ha->max_req_queues; que++) { |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 3720 | req = ha->req_q_map[que]; |
Quinn Tran | cb43285 | 2016-02-04 11:45:16 -0500 | [diff] [blame] | 3721 | if (!req || !test_bit(que, ha->req_qid_map)) |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 3722 | continue; |
Joe Carnuccio | 7c6300e | 2014-04-11 16:54:37 -0400 | [diff] [blame] | 3723 | req->out_ptr = (void *)(req->ring + req->length); |
| 3724 | *req->out_ptr = 0; |
Chad Dupuis | 8d93f55 | 2013-01-30 03:34:37 -0500 | [diff] [blame] | 3725 | for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 3726 | req->outstanding_cmds[cnt] = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3727 | |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 3728 | req->current_outstanding_cmd = 1; |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 3729 | |
| 3730 | /* Initialize firmware. */ |
| 3731 | req->ring_ptr = req->ring; |
| 3732 | req->ring_index = 0; |
| 3733 | req->cnt = req->length; |
| 3734 | } |
| 3735 | |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 3736 | for (que = 0; que < ha->max_rsp_queues; que++) { |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 3737 | rsp = ha->rsp_q_map[que]; |
Quinn Tran | cb43285 | 2016-02-04 11:45:16 -0500 | [diff] [blame] | 3738 | if (!rsp || !test_bit(que, ha->rsp_qid_map)) |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 3739 | continue; |
Joe Carnuccio | 7c6300e | 2014-04-11 16:54:37 -0400 | [diff] [blame] | 3740 | rsp->in_ptr = (void *)(rsp->ring + rsp->length); |
| 3741 | *rsp->in_ptr = 0; |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 3742 | /* Initialize response queue entries */ |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 3743 | if (IS_QLAFX00(ha)) |
| 3744 | qlafx00_init_response_q_entries(rsp); |
| 3745 | else |
| 3746 | qla2x00_init_response_q_entries(rsp); |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 3747 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3748 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3749 | ha->tgt.atio_ring_ptr = ha->tgt.atio_ring; |
| 3750 | ha->tgt.atio_ring_index = 0; |
| 3751 | /* Initialize ATIO queue entries */ |
| 3752 | qlt_init_atio_q_entries(vha); |
| 3753 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3754 | ha->isp_ops->config_rings(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3755 | |
| 3756 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 3757 | |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 3758 | ql_dbg(ql_dbg_init, vha, 0x00d1, "Issue init firmware.\n"); |
| 3759 | |
| 3760 | if (IS_QLAFX00(ha)) { |
| 3761 | rval = qlafx00_init_firmware(vha, ha->init_cb_size); |
| 3762 | goto next_check; |
| 3763 | } |
| 3764 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3765 | /* Update any ISP specific firmware options before initialization. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3766 | ha->isp_ops->update_fw_options(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3767 | |
Lalit Chandivade | 605aa2b | 2009-03-05 11:07:01 -0800 | [diff] [blame] | 3768 | if (ha->flags.npiv_supported) { |
Saurav Kashyap | 45980cc | 2012-08-22 14:21:21 -0400 | [diff] [blame] | 3769 | if (ha->operating_mode == LOOP && !IS_CNA_CAPABLE(ha)) |
Lalit Chandivade | 605aa2b | 2009-03-05 11:07:01 -0800 | [diff] [blame] | 3770 | ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1; |
Seokmann Ju | c48339d | 2008-01-17 09:02:19 -0800 | [diff] [blame] | 3771 | mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports); |
Lalit Chandivade | 605aa2b | 2009-03-05 11:07:01 -0800 | [diff] [blame] | 3772 | } |
| 3773 | |
Andrew Vasquez | 24a0813 | 2009-03-24 09:08:16 -0700 | [diff] [blame] | 3774 | if (IS_FWI2_CAPABLE(ha)) { |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3775 | mid_init_cb->options = cpu_to_le16(BIT_1); |
Andrew Vasquez | 24a0813 | 2009-03-24 09:08:16 -0700 | [diff] [blame] | 3776 | mid_init_cb->init_cb.execution_throttle = |
Quinn Tran | 03e8c68 | 2015-12-17 14:56:59 -0500 | [diff] [blame] | 3777 | cpu_to_le16(ha->cur_fw_xcb_count); |
Joe Carnuccio | 40f3862 | 2016-07-06 11:14:28 -0400 | [diff] [blame] | 3778 | ha->flags.dport_enabled = |
| 3779 | (mid_init_cb->init_cb.firmware_options_1 & BIT_7) != 0; |
| 3780 | ql_dbg(ql_dbg_init, vha, 0x0191, "DPORT Support: %s.\n", |
| 3781 | (ha->flags.dport_enabled) ? "enabled" : "disabled"); |
| 3782 | /* FA-WWPN Status */ |
Himanshu Madhani | 2486c62 | 2014-09-25 05:17:00 -0400 | [diff] [blame] | 3783 | ha->flags.fawwpn_enabled = |
Joe Carnuccio | 40f3862 | 2016-07-06 11:14:28 -0400 | [diff] [blame] | 3784 | (mid_init_cb->init_cb.firmware_options_1 & BIT_6) != 0; |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 3785 | ql_dbg(ql_dbg_init, vha, 0x00bc, "FA-WWPN Support: %s.\n", |
Himanshu Madhani | 2486c62 | 2014-09-25 05:17:00 -0400 | [diff] [blame] | 3786 | (ha->flags.fawwpn_enabled) ? "enabled" : "disabled"); |
Andrew Vasquez | 24a0813 | 2009-03-24 09:08:16 -0700 | [diff] [blame] | 3787 | } |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3788 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3789 | rval = qla2x00_init_firmware(vha, ha->init_cb_size); |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 3790 | next_check: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3791 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3792 | ql_log(ql_log_fatal, vha, 0x00d2, |
| 3793 | "Init Firmware **** FAILED ****.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3794 | } else { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3795 | ql_dbg(ql_dbg_init, vha, 0x00d3, |
| 3796 | "Init Firmware -- success.\n"); |
Quinn Tran | 4b60c82 | 2017-06-13 20:47:21 -0700 | [diff] [blame] | 3797 | QLA_FW_STARTED(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3798 | } |
| 3799 | |
| 3800 | return (rval); |
| 3801 | } |
| 3802 | |
| 3803 | /** |
| 3804 | * qla2x00_fw_ready() - Waits for firmware ready. |
| 3805 | * @ha: HA context |
| 3806 | * |
| 3807 | * Returns 0 on success. |
| 3808 | */ |
| 3809 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3810 | qla2x00_fw_ready(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3811 | { |
| 3812 | int rval; |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 3813 | unsigned long wtime, mtime, cs84xx_time; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3814 | uint16_t min_wait; /* Minimum wait time if loop is down */ |
| 3815 | uint16_t wait_time; /* Wait time if loop is coming ready */ |
Joe Carnuccio | b5a340d | 2014-09-25 05:16:48 -0400 | [diff] [blame] | 3816 | uint16_t state[6]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3817 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3818 | |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 3819 | if (IS_QLAFX00(vha->hw)) |
| 3820 | return qlafx00_fw_ready(vha); |
| 3821 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3822 | rval = QLA_SUCCESS; |
| 3823 | |
Chad Dupuis | 33461491 | 2015-04-09 14:59:57 -0400 | [diff] [blame] | 3824 | /* Time to wait for loop down */ |
| 3825 | if (IS_P3P_TYPE(ha)) |
| 3826 | min_wait = 30; |
| 3827 | else |
| 3828 | min_wait = 20; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3829 | |
| 3830 | /* |
| 3831 | * Firmware should take at most one RATOV to login, plus 5 seconds for |
| 3832 | * our own processing. |
| 3833 | */ |
| 3834 | if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) { |
| 3835 | wait_time = min_wait; |
| 3836 | } |
| 3837 | |
| 3838 | /* Min wait time if loop down */ |
| 3839 | mtime = jiffies + (min_wait * HZ); |
| 3840 | |
| 3841 | /* wait time before firmware ready */ |
| 3842 | wtime = jiffies + (wait_time * HZ); |
| 3843 | |
| 3844 | /* Wait for ISP to finish LIP */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3845 | if (!vha->flags.init_done) |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3846 | ql_log(ql_log_info, vha, 0x801e, |
| 3847 | "Waiting for LIP to complete.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3848 | |
| 3849 | do { |
Andrew Vasquez | 5b93903 | 2012-11-21 02:40:26 -0500 | [diff] [blame] | 3850 | memset(state, -1, sizeof(state)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3851 | rval = qla2x00_get_firmware_state(vha, state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3852 | if (rval == QLA_SUCCESS) { |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 3853 | if (state[0] < FSTATE_LOSS_OF_SYNC) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3854 | vha->device_flags &= ~DFLG_NO_CABLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3855 | } |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 3856 | if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3857 | ql_dbg(ql_dbg_taskm, vha, 0x801f, |
| 3858 | "fw_state=%x 84xx=%x.\n", state[0], |
| 3859 | state[2]); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 3860 | if ((state[2] & FSTATE_LOGGED_IN) && |
| 3861 | (state[2] & FSTATE_WAITING_FOR_VERIFY)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3862 | ql_dbg(ql_dbg_taskm, vha, 0x8028, |
| 3863 | "Sending verify iocb.\n"); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 3864 | |
| 3865 | cs84xx_time = jiffies; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3866 | rval = qla84xx_init_chip(vha); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3867 | if (rval != QLA_SUCCESS) { |
| 3868 | ql_log(ql_log_warn, |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 3869 | vha, 0x8007, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3870 | "Init chip failed.\n"); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 3871 | break; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3872 | } |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 3873 | |
| 3874 | /* Add time taken to initialize. */ |
| 3875 | cs84xx_time = jiffies - cs84xx_time; |
| 3876 | wtime += cs84xx_time; |
| 3877 | mtime += cs84xx_time; |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 3878 | ql_dbg(ql_dbg_taskm, vha, 0x8008, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3879 | "Increasing wait time by %ld. " |
| 3880 | "New time %ld.\n", cs84xx_time, |
| 3881 | wtime); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 3882 | } |
| 3883 | } else if (state[0] == FSTATE_READY) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3884 | ql_dbg(ql_dbg_taskm, vha, 0x8037, |
| 3885 | "F/W Ready - OK.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3886 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3887 | qla2x00_get_retry_cnt(vha, &ha->retry_count, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3888 | &ha->login_timeout, &ha->r_a_tov); |
| 3889 | |
| 3890 | rval = QLA_SUCCESS; |
| 3891 | break; |
| 3892 | } |
| 3893 | |
| 3894 | rval = QLA_FUNCTION_FAILED; |
| 3895 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3896 | if (atomic_read(&vha->loop_down_timer) && |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 3897 | state[0] != FSTATE_READY) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3898 | /* Loop down. Timeout on min_wait for states |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 3899 | * other than Wait for Login. |
| 3900 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3901 | if (time_after_eq(jiffies, mtime)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3902 | ql_log(ql_log_info, vha, 0x8038, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3903 | "Cable is unplugged...\n"); |
| 3904 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3905 | vha->device_flags |= DFLG_NO_CABLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3906 | break; |
| 3907 | } |
| 3908 | } |
| 3909 | } else { |
| 3910 | /* Mailbox cmd failed. Timeout on min_wait. */ |
Santosh Vernekar | cdbb0a4f | 2010-05-28 15:08:25 -0700 | [diff] [blame] | 3911 | if (time_after_eq(jiffies, mtime) || |
Giridhar Malavali | 7190575 | 2011-02-23 15:27:10 -0800 | [diff] [blame] | 3912 | ha->flags.isp82xx_fw_hung) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3913 | break; |
| 3914 | } |
| 3915 | |
| 3916 | if (time_after_eq(jiffies, wtime)) |
| 3917 | break; |
| 3918 | |
| 3919 | /* Delay for a while */ |
| 3920 | msleep(500); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3921 | } while (1); |
| 3922 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3923 | ql_dbg(ql_dbg_taskm, vha, 0x803a, |
Joe Carnuccio | b5a340d | 2014-09-25 05:16:48 -0400 | [diff] [blame] | 3924 | "fw_state=%x (%x, %x, %x, %x %x) curr time=%lx.\n", state[0], |
| 3925 | state[1], state[2], state[3], state[4], state[5], jiffies); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3926 | |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 3927 | if (rval && !(vha->device_flags & DFLG_NO_CABLE)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3928 | ql_log(ql_log_warn, vha, 0x803b, |
| 3929 | "Firmware ready **** FAILED ****.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3930 | } |
| 3931 | |
| 3932 | return (rval); |
| 3933 | } |
| 3934 | |
| 3935 | /* |
| 3936 | * qla2x00_configure_hba |
| 3937 | * Setup adapter context. |
| 3938 | * |
| 3939 | * Input: |
| 3940 | * ha = adapter state pointer. |
| 3941 | * |
| 3942 | * Returns: |
| 3943 | * 0 = success |
| 3944 | * |
| 3945 | * Context: |
| 3946 | * Kernel context. |
| 3947 | */ |
| 3948 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3949 | qla2x00_configure_hba(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3950 | { |
| 3951 | int rval; |
| 3952 | uint16_t loop_id; |
| 3953 | uint16_t topo; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3954 | uint16_t sw_cap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3955 | uint8_t al_pa; |
| 3956 | uint8_t area; |
| 3957 | uint8_t domain; |
| 3958 | char connect_type[22]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3959 | struct qla_hw_data *ha = vha->hw; |
Joe Carnuccio | 61e1b26 | 2013-02-08 01:57:48 -0500 | [diff] [blame] | 3960 | scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev); |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 3961 | port_id_t id; |
Quinn Tran | 9d1aa4e | 2017-12-28 12:33:27 -0800 | [diff] [blame] | 3962 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3963 | |
| 3964 | /* Get host addresses. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3965 | rval = qla2x00_get_adapter_id(vha, |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3966 | &loop_id, &al_pa, &area, &domain, &topo, &sw_cap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3967 | if (rval != QLA_SUCCESS) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3968 | if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) || |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 3969 | IS_CNA_CAPABLE(ha) || |
Ravi Anand | 33135aa | 2005-11-08 14:37:20 -0800 | [diff] [blame] | 3970 | (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3971 | ql_dbg(ql_dbg_disc, vha, 0x2008, |
| 3972 | "Loop is in a transition state.\n"); |
Ravi Anand | 33135aa | 2005-11-08 14:37:20 -0800 | [diff] [blame] | 3973 | } else { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3974 | ql_log(ql_log_warn, vha, 0x2009, |
| 3975 | "Unable to get host loop ID.\n"); |
Joe Carnuccio | 61e1b26 | 2013-02-08 01:57:48 -0500 | [diff] [blame] | 3976 | if (IS_FWI2_CAPABLE(ha) && (vha == base_vha) && |
| 3977 | (rval == QLA_COMMAND_ERROR && loop_id == 0x1b)) { |
| 3978 | ql_log(ql_log_warn, vha, 0x1151, |
| 3979 | "Doing link init.\n"); |
| 3980 | if (qla24xx_link_initialize(vha) == QLA_SUCCESS) |
| 3981 | return rval; |
| 3982 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3983 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
Ravi Anand | 33135aa | 2005-11-08 14:37:20 -0800 | [diff] [blame] | 3984 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3985 | return (rval); |
| 3986 | } |
| 3987 | |
| 3988 | if (topo == 4) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3989 | ql_log(ql_log_info, vha, 0x200a, |
| 3990 | "Cannot get topology - retrying.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3991 | return (QLA_FUNCTION_FAILED); |
| 3992 | } |
| 3993 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3994 | vha->loop_id = loop_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3995 | |
| 3996 | /* initialize */ |
| 3997 | ha->min_external_loopid = SNS_FIRST_LOOP_ID; |
| 3998 | ha->operating_mode = LOOP; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3999 | ha->switch_cap = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4000 | |
| 4001 | switch (topo) { |
| 4002 | case 0: |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4003 | ql_dbg(ql_dbg_disc, vha, 0x200b, "HBA in NL topology.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4004 | ha->current_topology = ISP_CFG_NL; |
| 4005 | strcpy(connect_type, "(Loop)"); |
| 4006 | break; |
| 4007 | |
| 4008 | case 1: |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4009 | ql_dbg(ql_dbg_disc, vha, 0x200c, "HBA in FL topology.\n"); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 4010 | ha->switch_cap = sw_cap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4011 | ha->current_topology = ISP_CFG_FL; |
| 4012 | strcpy(connect_type, "(FL_Port)"); |
| 4013 | break; |
| 4014 | |
| 4015 | case 2: |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4016 | ql_dbg(ql_dbg_disc, vha, 0x200d, "HBA in N P2P topology.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4017 | ha->operating_mode = P2P; |
| 4018 | ha->current_topology = ISP_CFG_N; |
| 4019 | strcpy(connect_type, "(N_Port-to-N_Port)"); |
| 4020 | break; |
| 4021 | |
| 4022 | case 3: |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4023 | ql_dbg(ql_dbg_disc, vha, 0x200e, "HBA in F P2P topology.\n"); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 4024 | ha->switch_cap = sw_cap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4025 | ha->operating_mode = P2P; |
| 4026 | ha->current_topology = ISP_CFG_F; |
| 4027 | strcpy(connect_type, "(F_Port)"); |
| 4028 | break; |
| 4029 | |
| 4030 | default: |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4031 | ql_dbg(ql_dbg_disc, vha, 0x200f, |
| 4032 | "HBA in unknown topology %x, using NL.\n", topo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4033 | ha->current_topology = ISP_CFG_NL; |
| 4034 | strcpy(connect_type, "(Loop)"); |
| 4035 | break; |
| 4036 | } |
| 4037 | |
| 4038 | /* Save Host port and loop ID. */ |
| 4039 | /* byte order - Big Endian */ |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 4040 | id.b.domain = domain; |
| 4041 | id.b.area = area; |
| 4042 | id.b.al_pa = al_pa; |
| 4043 | id.b.rsvd_1 = 0; |
Quinn Tran | 9d1aa4e | 2017-12-28 12:33:27 -0800 | [diff] [blame] | 4044 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 4045 | qlt_update_host_map(vha, id); |
Quinn Tran | 9d1aa4e | 2017-12-28 12:33:27 -0800 | [diff] [blame] | 4046 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4047 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4048 | if (!vha->flags.init_done) |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4049 | ql_log(ql_log_info, vha, 0x2010, |
| 4050 | "Topology - %s, Host Loop address 0x%x.\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4051 | connect_type, vha->loop_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4052 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4053 | return(rval); |
| 4054 | } |
| 4055 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 4056 | inline void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4057 | qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len, |
| 4058 | char *def) |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 4059 | { |
| 4060 | char *st, *en; |
| 4061 | uint16_t index; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4062 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | ab67114 | 2009-08-25 11:36:17 -0700 | [diff] [blame] | 4063 | int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) && |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 4064 | !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha); |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 4065 | |
| 4066 | if (memcmp(model, BINZERO, len) != 0) { |
| 4067 | strncpy(ha->model_number, model, len); |
| 4068 | st = en = ha->model_number; |
| 4069 | en += len - 1; |
| 4070 | while (en > st) { |
| 4071 | if (*en != 0x20 && *en != 0x00) |
| 4072 | break; |
| 4073 | *en-- = '\0'; |
| 4074 | } |
| 4075 | |
| 4076 | index = (ha->pdev->subsystem_device & 0xff); |
Andrew Vasquez | 7d0dba1 | 2009-04-06 22:33:45 -0700 | [diff] [blame] | 4077 | if (use_tbl && |
| 4078 | ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC && |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 4079 | index < QLA_MODEL_NAMES) |
Joe Carnuccio | 1ee2714 | 2008-07-10 16:55:53 -0700 | [diff] [blame] | 4080 | strncpy(ha->model_desc, |
| 4081 | qla2x00_model_name[index * 2 + 1], |
| 4082 | sizeof(ha->model_desc) - 1); |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 4083 | } else { |
| 4084 | index = (ha->pdev->subsystem_device & 0xff); |
Andrew Vasquez | 7d0dba1 | 2009-04-06 22:33:45 -0700 | [diff] [blame] | 4085 | if (use_tbl && |
| 4086 | ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC && |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 4087 | index < QLA_MODEL_NAMES) { |
| 4088 | strcpy(ha->model_number, |
| 4089 | qla2x00_model_name[index * 2]); |
Joe Carnuccio | 1ee2714 | 2008-07-10 16:55:53 -0700 | [diff] [blame] | 4090 | strncpy(ha->model_desc, |
| 4091 | qla2x00_model_name[index * 2 + 1], |
| 4092 | sizeof(ha->model_desc) - 1); |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 4093 | } else { |
| 4094 | strcpy(ha->model_number, def); |
| 4095 | } |
| 4096 | } |
Joe Carnuccio | 1ee2714 | 2008-07-10 16:55:53 -0700 | [diff] [blame] | 4097 | if (IS_FWI2_CAPABLE(ha)) |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4098 | qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc, |
Joe Carnuccio | 1ee2714 | 2008-07-10 16:55:53 -0700 | [diff] [blame] | 4099 | sizeof(ha->model_desc)); |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 4100 | } |
| 4101 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4102 | /* On sparc systems, obtain port and node WWN from firmware |
| 4103 | * properties. |
| 4104 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4105 | static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv) |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4106 | { |
| 4107 | #ifdef CONFIG_SPARC |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4108 | struct qla_hw_data *ha = vha->hw; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4109 | struct pci_dev *pdev = ha->pdev; |
David S. Miller | 15576bc | 2007-05-08 00:36:49 -0700 | [diff] [blame] | 4110 | struct device_node *dp = pci_device_to_OF_node(pdev); |
| 4111 | const u8 *val; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4112 | int len; |
| 4113 | |
| 4114 | val = of_get_property(dp, "port-wwn", &len); |
| 4115 | if (val && len >= WWN_SIZE) |
| 4116 | memcpy(nv->port_name, val, WWN_SIZE); |
| 4117 | |
| 4118 | val = of_get_property(dp, "node-wwn", &len); |
| 4119 | if (val && len >= WWN_SIZE) |
| 4120 | memcpy(nv->node_name, val, WWN_SIZE); |
| 4121 | #endif |
| 4122 | } |
| 4123 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4124 | /* |
| 4125 | * NVRAM configuration for ISP 2xxx |
| 4126 | * |
| 4127 | * Input: |
| 4128 | * ha = adapter block pointer. |
| 4129 | * |
| 4130 | * Output: |
| 4131 | * initialization control block in response_ring |
| 4132 | * host adapters parameters in host adapter block |
| 4133 | * |
| 4134 | * Returns: |
| 4135 | * 0 = success. |
| 4136 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 4137 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4138 | qla2x00_nvram_config(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4139 | { |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4140 | int rval; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4141 | uint8_t chksum = 0; |
| 4142 | uint16_t cnt; |
| 4143 | uint8_t *dptr1, *dptr2; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4144 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4145 | init_cb_t *icb = ha->init_cb; |
Seokmann Ju | 281afe1 | 2007-07-26 13:43:34 -0700 | [diff] [blame] | 4146 | nvram_t *nv = ha->nvram; |
| 4147 | uint8_t *ptr = ha->nvram; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 4148 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4149 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4150 | rval = QLA_SUCCESS; |
| 4151 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4152 | /* Determine NVRAM starting address. */ |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4153 | ha->nvram_size = sizeof(nvram_t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4154 | ha->nvram_base = 0; |
| 4155 | if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha)) |
| 4156 | if ((RD_REG_WORD(®->ctrl_status) >> 14) == 1) |
| 4157 | ha->nvram_base = 0x80; |
| 4158 | |
| 4159 | /* Get NVRAM data and calculate checksum. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4160 | ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4161 | for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++) |
| 4162 | chksum += *ptr++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4163 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4164 | ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x010f, |
| 4165 | "Contents of NVRAM.\n"); |
| 4166 | ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0110, |
| 4167 | (uint8_t *)nv, ha->nvram_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4168 | |
| 4169 | /* Bad NVRAM data, set defaults parameters. */ |
| 4170 | if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || |
| 4171 | nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) { |
| 4172 | /* Reset NVRAM data. */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4173 | ql_log(ql_log_warn, vha, 0x0064, |
Raul Porcel | 9e33652 | 2012-05-15 14:34:08 -0400 | [diff] [blame] | 4174 | "Inconsistent NVRAM " |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4175 | "detected: checksum=0x%x id=%c version=0x%x.\n", |
| 4176 | chksum, nv->id[0], nv->nvram_version); |
| 4177 | ql_log(ql_log_warn, vha, 0x0065, |
| 4178 | "Falling back to " |
| 4179 | "functioning (yet invalid -- WWPN) defaults.\n"); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4180 | |
| 4181 | /* |
| 4182 | * Set default initialization control block. |
| 4183 | */ |
| 4184 | memset(nv, 0, ha->nvram_size); |
| 4185 | nv->parameter_block_version = ICB_VERSION; |
| 4186 | |
| 4187 | if (IS_QLA23XX(ha)) { |
| 4188 | nv->firmware_options[0] = BIT_2 | BIT_1; |
| 4189 | nv->firmware_options[1] = BIT_7 | BIT_5; |
| 4190 | nv->add_firmware_options[0] = BIT_5; |
| 4191 | nv->add_firmware_options[1] = BIT_5 | BIT_4; |
Joe Carnuccio | 98aee70 | 2014-09-25 05:16:38 -0400 | [diff] [blame] | 4192 | nv->frame_payload_size = 2048; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4193 | nv->special_options[1] = BIT_7; |
| 4194 | } else if (IS_QLA2200(ha)) { |
| 4195 | nv->firmware_options[0] = BIT_2 | BIT_1; |
| 4196 | nv->firmware_options[1] = BIT_7 | BIT_5; |
| 4197 | nv->add_firmware_options[0] = BIT_5; |
| 4198 | nv->add_firmware_options[1] = BIT_5 | BIT_4; |
Joe Carnuccio | 98aee70 | 2014-09-25 05:16:38 -0400 | [diff] [blame] | 4199 | nv->frame_payload_size = 1024; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4200 | } else if (IS_QLA2100(ha)) { |
| 4201 | nv->firmware_options[0] = BIT_3 | BIT_1; |
| 4202 | nv->firmware_options[1] = BIT_5; |
Joe Carnuccio | 98aee70 | 2014-09-25 05:16:38 -0400 | [diff] [blame] | 4203 | nv->frame_payload_size = 1024; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4204 | } |
| 4205 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 4206 | nv->max_iocb_allocation = cpu_to_le16(256); |
| 4207 | nv->execution_throttle = cpu_to_le16(16); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4208 | nv->retry_count = 8; |
| 4209 | nv->retry_delay = 1; |
| 4210 | |
| 4211 | nv->port_name[0] = 33; |
| 4212 | nv->port_name[3] = 224; |
| 4213 | nv->port_name[4] = 139; |
| 4214 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4215 | qla2xxx_nvram_wwn_from_ofw(vha, nv); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4216 | |
| 4217 | nv->login_timeout = 4; |
| 4218 | |
| 4219 | /* |
| 4220 | * Set default host adapter parameters |
| 4221 | */ |
| 4222 | nv->host_p[1] = BIT_2; |
| 4223 | nv->reset_delay = 5; |
| 4224 | nv->port_down_retry_count = 8; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 4225 | nv->max_luns_per_target = cpu_to_le16(8); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4226 | nv->link_down_timeout = 60; |
| 4227 | |
| 4228 | rval = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4229 | } |
| 4230 | |
| 4231 | #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2) |
| 4232 | /* |
| 4233 | * The SN2 does not provide BIOS emulation which means you can't change |
| 4234 | * potentially bogus BIOS settings. Force the use of default settings |
| 4235 | * for link rate and frame size. Hope that the rest of the settings |
| 4236 | * are valid. |
| 4237 | */ |
| 4238 | if (ia64_platform_is("sn2")) { |
Joe Carnuccio | 98aee70 | 2014-09-25 05:16:38 -0400 | [diff] [blame] | 4239 | nv->frame_payload_size = 2048; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4240 | if (IS_QLA23XX(ha)) |
| 4241 | nv->special_options[1] = BIT_7; |
| 4242 | } |
| 4243 | #endif |
| 4244 | |
| 4245 | /* Reset Initialization control block */ |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4246 | memset(icb, 0, ha->init_cb_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4247 | |
| 4248 | /* |
| 4249 | * Setup driver NVRAM options. |
| 4250 | */ |
| 4251 | nv->firmware_options[0] |= (BIT_6 | BIT_1); |
| 4252 | nv->firmware_options[0] &= ~(BIT_5 | BIT_4); |
| 4253 | nv->firmware_options[1] |= (BIT_5 | BIT_0); |
| 4254 | nv->firmware_options[1] &= ~BIT_4; |
| 4255 | |
| 4256 | if (IS_QLA23XX(ha)) { |
| 4257 | nv->firmware_options[0] |= BIT_2; |
| 4258 | nv->firmware_options[0] &= ~BIT_3; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4259 | nv->special_options[0] &= ~BIT_6; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4260 | nv->add_firmware_options[1] |= BIT_5 | BIT_4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4261 | |
| 4262 | if (IS_QLA2300(ha)) { |
| 4263 | if (ha->fb_rev == FPM_2310) { |
| 4264 | strcpy(ha->model_number, "QLA2310"); |
| 4265 | } else { |
| 4266 | strcpy(ha->model_number, "QLA2300"); |
| 4267 | } |
| 4268 | } else { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4269 | qla2x00_set_model_info(vha, nv->model_number, |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 4270 | sizeof(nv->model_number), "QLA23xx"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4271 | } |
| 4272 | } else if (IS_QLA2200(ha)) { |
| 4273 | nv->firmware_options[0] |= BIT_2; |
| 4274 | /* |
| 4275 | * 'Point-to-point preferred, else loop' is not a safe |
| 4276 | * connection mode setting. |
| 4277 | */ |
| 4278 | if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) == |
| 4279 | (BIT_5 | BIT_4)) { |
| 4280 | /* Force 'loop preferred, else point-to-point'. */ |
| 4281 | nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4); |
| 4282 | nv->add_firmware_options[0] |= BIT_5; |
| 4283 | } |
| 4284 | strcpy(ha->model_number, "QLA22xx"); |
| 4285 | } else /*if (IS_QLA2100(ha))*/ { |
| 4286 | strcpy(ha->model_number, "QLA2100"); |
| 4287 | } |
| 4288 | |
| 4289 | /* |
| 4290 | * Copy over NVRAM RISC parameter block to initialization control block. |
| 4291 | */ |
| 4292 | dptr1 = (uint8_t *)icb; |
| 4293 | dptr2 = (uint8_t *)&nv->parameter_block_version; |
| 4294 | cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version; |
| 4295 | while (cnt--) |
| 4296 | *dptr1++ = *dptr2++; |
| 4297 | |
| 4298 | /* Copy 2nd half. */ |
| 4299 | dptr1 = (uint8_t *)icb->add_firmware_options; |
| 4300 | cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options; |
| 4301 | while (cnt--) |
| 4302 | *dptr1++ = *dptr2++; |
| 4303 | |
Andrew Vasquez | 5341e86 | 2006-05-17 15:09:16 -0700 | [diff] [blame] | 4304 | /* Use alternate WWN? */ |
| 4305 | if (nv->host_p[1] & BIT_7) { |
| 4306 | memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE); |
| 4307 | memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE); |
| 4308 | } |
| 4309 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4310 | /* Prepare nodename */ |
| 4311 | if ((icb->firmware_options[1] & BIT_6) == 0) { |
| 4312 | /* |
| 4313 | * Firmware will apply the following mask if the nodename was |
| 4314 | * not provided. |
| 4315 | */ |
| 4316 | memcpy(icb->node_name, icb->port_name, WWN_SIZE); |
| 4317 | icb->node_name[0] &= 0xF0; |
| 4318 | } |
| 4319 | |
| 4320 | /* |
| 4321 | * Set host adapter parameters. |
| 4322 | */ |
Saurav Kashyap | 3ce8866 | 2011-07-14 12:00:12 -0700 | [diff] [blame] | 4323 | |
| 4324 | /* |
| 4325 | * BIT_7 in the host-parameters section allows for modification to |
| 4326 | * internal driver logging. |
| 4327 | */ |
Andrew Vasquez | 0181944 | 2006-06-23 16:11:10 -0700 | [diff] [blame] | 4328 | if (nv->host_p[0] & BIT_7) |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 4329 | ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4330 | ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0); |
| 4331 | /* Always load RISC code on non ISP2[12]00 chips. */ |
| 4332 | if (!IS_QLA2100(ha) && !IS_QLA2200(ha)) |
| 4333 | ha->flags.disable_risc_code_load = 0; |
| 4334 | ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0); |
| 4335 | ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0); |
| 4336 | ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0); |
Andrew Vasquez | 06c22bd | 2005-08-26 19:09:00 -0700 | [diff] [blame] | 4337 | ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0; |
Andrew Vasquez | d4c760c | 2006-06-23 16:10:39 -0700 | [diff] [blame] | 4338 | ha->flags.disable_serdes = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4339 | |
| 4340 | ha->operating_mode = |
| 4341 | (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4; |
| 4342 | |
| 4343 | memcpy(ha->fw_seriallink_options, nv->seriallink_options, |
| 4344 | sizeof(ha->fw_seriallink_options)); |
| 4345 | |
| 4346 | /* save HBA serial number */ |
| 4347 | ha->serial0 = icb->port_name[5]; |
| 4348 | ha->serial1 = icb->port_name[6]; |
| 4349 | ha->serial2 = icb->port_name[7]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4350 | memcpy(vha->node_name, icb->node_name, WWN_SIZE); |
| 4351 | memcpy(vha->port_name, icb->port_name, WWN_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4352 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 4353 | icb->execution_throttle = cpu_to_le16(0xFFFF); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4354 | |
| 4355 | ha->retry_count = nv->retry_count; |
| 4356 | |
| 4357 | /* Set minimum login_timeout to 4 seconds. */ |
Andrew Vasquez | 5b91490 | 2010-05-28 15:08:30 -0700 | [diff] [blame] | 4358 | if (nv->login_timeout != ql2xlogintimeout) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4359 | nv->login_timeout = ql2xlogintimeout; |
| 4360 | if (nv->login_timeout < 4) |
| 4361 | nv->login_timeout = 4; |
| 4362 | ha->login_timeout = nv->login_timeout; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4363 | |
Andrew Vasquez | 00a537b | 2008-02-28 14:06:11 -0800 | [diff] [blame] | 4364 | /* Set minimum RATOV to 100 tenths of a second. */ |
| 4365 | ha->r_a_tov = 100; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4366 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4367 | ha->loop_reset_delay = nv->reset_delay; |
| 4368 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4369 | /* Link Down Timeout = 0: |
| 4370 | * |
| 4371 | * When Port Down timer expires we will start returning |
| 4372 | * I/O's to OS with "DID_NO_CONNECT". |
| 4373 | * |
| 4374 | * Link Down Timeout != 0: |
| 4375 | * |
| 4376 | * The driver waits for the link to come up after link down |
| 4377 | * before returning I/Os to OS with "DID_NO_CONNECT". |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 4378 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4379 | if (nv->link_down_timeout == 0) { |
| 4380 | ha->loop_down_abort_time = |
Andrew Vasquez | 354d6b2 | 2005-04-23 02:47:27 -0400 | [diff] [blame] | 4381 | (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4382 | } else { |
| 4383 | ha->link_down_timeout = nv->link_down_timeout; |
| 4384 | ha->loop_down_abort_time = |
| 4385 | (LOOP_DOWN_TIME - ha->link_down_timeout); |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 4386 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4387 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4388 | /* |
| 4389 | * Need enough time to try and get the port back. |
| 4390 | */ |
| 4391 | ha->port_down_retry_count = nv->port_down_retry_count; |
| 4392 | if (qlport_down_retry) |
| 4393 | ha->port_down_retry_count = qlport_down_retry; |
| 4394 | /* Set login_retry_count */ |
| 4395 | ha->login_retry_count = nv->retry_count; |
| 4396 | if (ha->port_down_retry_count == nv->port_down_retry_count && |
| 4397 | ha->port_down_retry_count > 3) |
| 4398 | ha->login_retry_count = ha->port_down_retry_count; |
| 4399 | else if (ha->port_down_retry_count > (int)ha->login_retry_count) |
| 4400 | ha->login_retry_count = ha->port_down_retry_count; |
| 4401 | if (ql2xloginretrycount) |
| 4402 | ha->login_retry_count = ql2xloginretrycount; |
| 4403 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 4404 | icb->lun_enables = cpu_to_le16(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4405 | icb->command_resource_count = 0; |
| 4406 | icb->immediate_notify_resource_count = 0; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 4407 | icb->timeout = cpu_to_le16(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4408 | |
| 4409 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) { |
| 4410 | /* Enable RIO */ |
| 4411 | icb->firmware_options[0] &= ~BIT_3; |
| 4412 | icb->add_firmware_options[0] &= |
| 4413 | ~(BIT_3 | BIT_2 | BIT_1 | BIT_0); |
| 4414 | icb->add_firmware_options[0] |= BIT_2; |
| 4415 | icb->response_accumulation_timer = 3; |
| 4416 | icb->interrupt_delay_timer = 5; |
| 4417 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4418 | vha->flags.process_response_queue = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4419 | } else { |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 4420 | /* Enable ZIO. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4421 | if (!vha->flags.init_done) { |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 4422 | ha->zio_mode = icb->add_firmware_options[0] & |
| 4423 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
| 4424 | ha->zio_timer = icb->interrupt_delay_timer ? |
| 4425 | icb->interrupt_delay_timer: 2; |
| 4426 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4427 | icb->add_firmware_options[0] &= |
| 4428 | ~(BIT_3 | BIT_2 | BIT_1 | BIT_0); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4429 | vha->flags.process_response_queue = 0; |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 4430 | if (ha->zio_mode != QLA_ZIO_DISABLED) { |
andrew.vasquez@qlogic.com | 4a59f71 | 2006-03-09 14:27:39 -0800 | [diff] [blame] | 4431 | ha->zio_mode = QLA_ZIO_MODE_6; |
| 4432 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4433 | ql_log(ql_log_info, vha, 0x0068, |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 4434 | "ZIO mode %d enabled; timer delay (%d us).\n", |
| 4435 | ha->zio_mode, ha->zio_timer * 100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4436 | |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 4437 | icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode; |
| 4438 | icb->interrupt_delay_timer = (uint8_t)ha->zio_timer; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4439 | vha->flags.process_response_queue = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4440 | } |
| 4441 | } |
| 4442 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4443 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4444 | ql_log(ql_log_warn, vha, 0x0069, |
| 4445 | "NVRAM configuration failed.\n"); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4446 | } |
| 4447 | return (rval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4448 | } |
| 4449 | |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 4450 | static void |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 4451 | qla2x00_rport_del(void *data) |
| 4452 | { |
| 4453 | fc_port_t *fcport = data; |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 4454 | struct fc_rport *rport; |
Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 4455 | unsigned long flags; |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 4456 | |
Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 4457 | spin_lock_irqsave(fcport->vha->host->host_lock, flags); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 4458 | rport = fcport->drport ? fcport->drport: fcport->rport; |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 4459 | fcport->drport = NULL; |
Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 4460 | spin_unlock_irqrestore(fcport->vha->host->host_lock, flags); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4461 | if (rport) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4462 | ql_dbg(ql_dbg_disc, fcport->vha, 0x210b, |
| 4463 | "%s %8phN. rport %p roles %x\n", |
| 4464 | __func__, fcport->port_name, rport, |
| 4465 | rport->roles); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4466 | |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 4467 | fc_remote_port_delete(rport); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4468 | } |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 4469 | } |
| 4470 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4471 | /** |
| 4472 | * qla2x00_alloc_fcport() - Allocate a generic fcport. |
| 4473 | * @ha: HA context |
| 4474 | * @flags: allocation flags |
| 4475 | * |
| 4476 | * Returns a pointer to the allocated fcport, or NULL, if none available. |
| 4477 | */ |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 4478 | fc_port_t * |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4479 | qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4480 | { |
| 4481 | fc_port_t *fcport; |
| 4482 | |
Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 4483 | fcport = kzalloc(sizeof(fc_port_t), flags); |
| 4484 | if (!fcport) |
| 4485 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4486 | |
| 4487 | /* Setup fcport template structure. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4488 | fcport->vha = vha; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4489 | fcport->port_type = FCT_UNKNOWN; |
| 4490 | fcport->loop_id = FC_NO_LOOP_ID; |
Chad Dupuis | ec426e1 | 2011-03-30 11:46:32 -0700 | [diff] [blame] | 4491 | qla2x00_set_fcport_state(fcport, FCS_UNCONFIGURED); |
Andrew Vasquez | ad3e0ed | 2005-08-26 19:08:10 -0700 | [diff] [blame] | 4492 | fcport->supported_classes = FC_COS_UNSPECIFIED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4493 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4494 | fcport->ct_desc.ct_sns = dma_alloc_coherent(&vha->hw->pdev->dev, |
| 4495 | sizeof(struct ct_sns_pkt), &fcport->ct_desc.ct_sns_dma, |
Quinn Tran | 6cb3216 | 2017-02-13 12:18:29 -0800 | [diff] [blame] | 4496 | flags); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4497 | fcport->disc_state = DSC_DELETED; |
| 4498 | fcport->fw_login_state = DSC_LS_PORT_UNAVAIL; |
| 4499 | fcport->deleted = QLA_SESS_DELETED; |
| 4500 | fcport->login_retry = vha->hw->login_retry_count; |
| 4501 | fcport->login_retry = 5; |
| 4502 | fcport->logout_on_delete = 1; |
| 4503 | |
| 4504 | if (!fcport->ct_desc.ct_sns) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4505 | ql_log(ql_log_warn, vha, 0xd049, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4506 | "Failed to allocate ct_sns request.\n"); |
| 4507 | kfree(fcport); |
| 4508 | fcport = NULL; |
| 4509 | } |
| 4510 | INIT_WORK(&fcport->del_work, qla24xx_delete_sess_fn); |
| 4511 | INIT_LIST_HEAD(&fcport->gnl_entry); |
| 4512 | INIT_LIST_HEAD(&fcport->list); |
| 4513 | |
Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 4514 | return fcport; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4515 | } |
| 4516 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4517 | void |
| 4518 | qla2x00_free_fcport(fc_port_t *fcport) |
| 4519 | { |
| 4520 | if (fcport->ct_desc.ct_sns) { |
| 4521 | dma_free_coherent(&fcport->vha->hw->pdev->dev, |
| 4522 | sizeof(struct ct_sns_pkt), fcport->ct_desc.ct_sns, |
| 4523 | fcport->ct_desc.ct_sns_dma); |
| 4524 | |
| 4525 | fcport->ct_desc.ct_sns = NULL; |
| 4526 | } |
| 4527 | kfree(fcport); |
| 4528 | } |
| 4529 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4530 | /* |
| 4531 | * qla2x00_configure_loop |
| 4532 | * Updates Fibre Channel Device Database with what is actually on loop. |
| 4533 | * |
| 4534 | * Input: |
| 4535 | * ha = adapter block pointer. |
| 4536 | * |
| 4537 | * Returns: |
| 4538 | * 0 = success. |
| 4539 | * 1 = error. |
| 4540 | * 2 = database was full and device was not configured. |
| 4541 | */ |
| 4542 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4543 | qla2x00_configure_loop(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4544 | { |
| 4545 | int rval; |
| 4546 | unsigned long flags, save_flags; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4547 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4548 | rval = QLA_SUCCESS; |
| 4549 | |
| 4550 | /* Get Initiator ID */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4551 | if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) { |
| 4552 | rval = qla2x00_configure_hba(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4553 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4554 | ql_dbg(ql_dbg_disc, vha, 0x2013, |
| 4555 | "Unable to configure HBA.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4556 | return (rval); |
| 4557 | } |
| 4558 | } |
| 4559 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4560 | save_flags = flags = vha->dpc_flags; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4561 | ql_dbg(ql_dbg_disc, vha, 0x2014, |
| 4562 | "Configure loop -- dpc flags = 0x%lx.\n", flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4563 | |
| 4564 | /* |
| 4565 | * If we have both an RSCN and PORT UPDATE pending then handle them |
| 4566 | * both at the same time. |
| 4567 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4568 | clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
| 4569 | clear_bit(RSCN_UPDATE, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4570 | |
Michael Hernandez | 3064ff3 | 2009-12-15 21:29:44 -0800 | [diff] [blame] | 4571 | qla2x00_get_data_rate(vha); |
| 4572 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4573 | /* Determine what we need to do */ |
| 4574 | if (ha->current_topology == ISP_CFG_FL && |
| 4575 | (test_bit(LOCAL_LOOP_UPDATE, &flags))) { |
| 4576 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4577 | set_bit(RSCN_UPDATE, &flags); |
| 4578 | |
| 4579 | } else if (ha->current_topology == ISP_CFG_F && |
| 4580 | (test_bit(LOCAL_LOOP_UPDATE, &flags))) { |
| 4581 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4582 | set_bit(RSCN_UPDATE, &flags); |
| 4583 | clear_bit(LOCAL_LOOP_UPDATE, &flags); |
| 4584 | |
Andrew Vasquez | 21333b4 | 2006-05-17 15:09:56 -0700 | [diff] [blame] | 4585 | } else if (ha->current_topology == ISP_CFG_N) { |
| 4586 | clear_bit(RSCN_UPDATE, &flags); |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 4587 | if (ha->flags.rida_fmt2) { |
| 4588 | /* With Rida Format 2, the login is already triggered. |
| 4589 | * We know who is on the other side of the wire. |
| 4590 | * No need to login to do login to find out or drop into |
| 4591 | * qla2x00_configure_local_loop(). |
| 4592 | */ |
| 4593 | clear_bit(LOCAL_LOOP_UPDATE, &flags); |
| 4594 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
| 4595 | } else { |
| 4596 | if (qla_tgt_mode_enabled(vha)) { |
| 4597 | /* allow the other side to start the login */ |
| 4598 | clear_bit(LOCAL_LOOP_UPDATE, &flags); |
| 4599 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
| 4600 | } |
| 4601 | } |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4602 | } else if (ha->current_topology == ISP_CFG_NL) { |
| 4603 | clear_bit(RSCN_UPDATE, &flags); |
| 4604 | set_bit(LOCAL_LOOP_UPDATE, &flags); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4605 | } else if (!vha->flags.online || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4606 | (test_bit(ABORT_ISP_ACTIVE, &flags))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4607 | set_bit(RSCN_UPDATE, &flags); |
| 4608 | set_bit(LOCAL_LOOP_UPDATE, &flags); |
| 4609 | } |
| 4610 | |
| 4611 | if (test_bit(LOCAL_LOOP_UPDATE, &flags)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4612 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) { |
| 4613 | ql_dbg(ql_dbg_disc, vha, 0x2015, |
| 4614 | "Loop resync needed, failing.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4615 | rval = QLA_FUNCTION_FAILED; |
Chad Dupuis | 642ef98 | 2012-02-09 11:15:57 -0800 | [diff] [blame] | 4616 | } else |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4617 | rval = qla2x00_configure_local_loop(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4618 | } |
| 4619 | |
| 4620 | if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4621 | if (LOOP_TRANSITION(vha)) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4622 | ql_dbg(ql_dbg_disc, vha, 0x2099, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4623 | "Needs RSCN update and loop transition.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4624 | rval = QLA_FUNCTION_FAILED; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4625 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4626 | else |
| 4627 | rval = qla2x00_configure_fabric(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4628 | } |
| 4629 | |
| 4630 | if (rval == QLA_SUCCESS) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4631 | if (atomic_read(&vha->loop_down_timer) || |
| 4632 | test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4633 | rval = QLA_FUNCTION_FAILED; |
| 4634 | } else { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4635 | atomic_set(&vha->loop_state, LOOP_READY); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4636 | ql_dbg(ql_dbg_disc, vha, 0x2069, |
| 4637 | "LOOP READY.\n"); |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 4638 | ha->flags.fw_init_done = 1; |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 4639 | |
| 4640 | /* |
| 4641 | * Process any ATIO queue entries that came in |
| 4642 | * while we weren't online. |
| 4643 | */ |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 4644 | if (qla_tgt_mode_enabled(vha) || |
| 4645 | qla_dual_mode_enabled(vha)) { |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 4646 | if (IS_QLA27XX(ha) || IS_QLA83XX(ha)) { |
| 4647 | spin_lock_irqsave(&ha->tgt.atio_lock, |
| 4648 | flags); |
| 4649 | qlt_24xx_process_atio_queue(vha, 0); |
| 4650 | spin_unlock_irqrestore( |
| 4651 | &ha->tgt.atio_lock, flags); |
| 4652 | } else { |
| 4653 | spin_lock_irqsave(&ha->hardware_lock, |
| 4654 | flags); |
| 4655 | qlt_24xx_process_atio_queue(vha, 1); |
| 4656 | spin_unlock_irqrestore( |
| 4657 | &ha->hardware_lock, flags); |
| 4658 | } |
| 4659 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4660 | } |
| 4661 | } |
| 4662 | |
| 4663 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4664 | ql_dbg(ql_dbg_disc, vha, 0x206a, |
| 4665 | "%s *** FAILED ***.\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4666 | } else { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4667 | ql_dbg(ql_dbg_disc, vha, 0x206b, |
| 4668 | "%s: exiting normally.\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4669 | } |
| 4670 | |
Bjorn Helgaas | cc3ef7b | 2008-09-11 21:22:51 -0700 | [diff] [blame] | 4671 | /* Restore state if a resync event occurred during processing */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4672 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4673 | if (test_bit(LOCAL_LOOP_UPDATE, &save_flags)) |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4674 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
Andrew Vasquez | f4658b6 | 2009-06-03 09:55:21 -0700 | [diff] [blame] | 4675 | if (test_bit(RSCN_UPDATE, &save_flags)) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4676 | set_bit(RSCN_UPDATE, &vha->dpc_flags); |
Andrew Vasquez | f4658b6 | 2009-06-03 09:55:21 -0700 | [diff] [blame] | 4677 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4678 | } |
| 4679 | |
| 4680 | return (rval); |
| 4681 | } |
| 4682 | |
Duane Grigsby | edd05de | 2017-10-13 09:34:06 -0700 | [diff] [blame] | 4683 | /* |
| 4684 | * N2N Login |
| 4685 | * Updates Fibre Channel Device Database with local loop devices. |
| 4686 | * |
| 4687 | * Input: |
| 4688 | * ha = adapter block pointer. |
| 4689 | * |
| 4690 | * Returns: |
| 4691 | */ |
| 4692 | static int qla24xx_n2n_handle_login(struct scsi_qla_host *vha, |
| 4693 | fc_port_t *fcport) |
| 4694 | { |
| 4695 | struct qla_hw_data *ha = vha->hw; |
| 4696 | int res = QLA_SUCCESS, rval; |
| 4697 | int greater_wwpn = 0; |
| 4698 | int logged_in = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4699 | |
Duane Grigsby | edd05de | 2017-10-13 09:34:06 -0700 | [diff] [blame] | 4700 | if (ha->current_topology != ISP_CFG_N) |
| 4701 | return res; |
| 4702 | |
| 4703 | if (wwn_to_u64(vha->port_name) > |
| 4704 | wwn_to_u64(vha->n2n_port_name)) { |
| 4705 | ql_dbg(ql_dbg_disc, vha, 0x2002, |
| 4706 | "HBA WWPN is greater %llx > target %llx\n", |
| 4707 | wwn_to_u64(vha->port_name), |
| 4708 | wwn_to_u64(vha->n2n_port_name)); |
| 4709 | greater_wwpn = 1; |
| 4710 | fcport->d_id.b24 = vha->n2n_id; |
| 4711 | } |
| 4712 | |
| 4713 | fcport->loop_id = vha->loop_id; |
| 4714 | fcport->fc4f_nvme = 0; |
| 4715 | fcport->query = 1; |
| 4716 | |
| 4717 | ql_dbg(ql_dbg_disc, vha, 0x4001, |
| 4718 | "Initiate N2N login handler: HBA port_id=%06x loopid=%d\n", |
| 4719 | fcport->d_id.b24, vha->loop_id); |
| 4720 | |
| 4721 | /* Fill in member data. */ |
| 4722 | if (!greater_wwpn) { |
| 4723 | rval = qla2x00_get_port_database(vha, fcport, 0); |
| 4724 | ql_dbg(ql_dbg_disc, vha, 0x1051, |
| 4725 | "Remote login-state (%x/%x) port_id=%06x loop_id=%x, rval=%d\n", |
| 4726 | fcport->current_login_state, fcport->last_login_state, |
| 4727 | fcport->d_id.b24, fcport->loop_id, rval); |
| 4728 | |
| 4729 | if (((fcport->current_login_state & 0xf) == 0x4) || |
| 4730 | ((fcport->current_login_state & 0xf) == 0x6)) |
| 4731 | logged_in = 1; |
| 4732 | } |
| 4733 | |
| 4734 | if (logged_in || greater_wwpn) { |
| 4735 | if (!vha->nvme_local_port && vha->flags.nvme_enabled) |
| 4736 | qla_nvme_register_hba(vha); |
| 4737 | |
| 4738 | /* Set connected N_Port d_id */ |
| 4739 | if (vha->flags.nvme_enabled) |
| 4740 | fcport->fc4f_nvme = 1; |
| 4741 | |
| 4742 | fcport->scan_state = QLA_FCPORT_FOUND; |
| 4743 | fcport->fw_login_state = DSC_LS_PORT_UNAVAIL; |
| 4744 | fcport->disc_state = DSC_GNL; |
| 4745 | fcport->n2n_flag = 1; |
| 4746 | fcport->flags = 3; |
| 4747 | vha->hw->flags.gpsc_supported = 0; |
| 4748 | |
| 4749 | if (greater_wwpn) { |
| 4750 | ql_dbg(ql_dbg_disc, vha, 0x20e5, |
| 4751 | "%s %d PLOGI ELS %8phC\n", |
| 4752 | __func__, __LINE__, fcport->port_name); |
| 4753 | |
| 4754 | res = qla24xx_els_dcmd2_iocb(vha, ELS_DCMD_PLOGI, |
| 4755 | fcport, fcport->d_id); |
| 4756 | } |
| 4757 | |
| 4758 | if (res != QLA_SUCCESS) { |
| 4759 | ql_log(ql_log_info, vha, 0xd04d, |
| 4760 | "PLOGI Failed: portid=%06x - retrying\n", |
| 4761 | fcport->d_id.b24); |
| 4762 | res = QLA_SUCCESS; |
| 4763 | } else { |
| 4764 | /* State 0x6 means FCP PRLI complete */ |
| 4765 | if ((fcport->current_login_state & 0xf) == 0x6) { |
| 4766 | ql_dbg(ql_dbg_disc, vha, 0x2118, |
| 4767 | "%s %d %8phC post GPDB work\n", |
| 4768 | __func__, __LINE__, fcport->port_name); |
| 4769 | fcport->chip_reset = |
| 4770 | vha->hw->base_qpair->chip_reset; |
| 4771 | qla24xx_post_gpdb_work(vha, fcport, 0); |
| 4772 | } else { |
| 4773 | ql_dbg(ql_dbg_disc, vha, 0x2118, |
| 4774 | "%s %d %8phC post NVMe PRLI\n", |
| 4775 | __func__, __LINE__, fcport->port_name); |
| 4776 | qla24xx_post_prli_work(vha, fcport); |
| 4777 | } |
| 4778 | } |
| 4779 | } else { |
| 4780 | /* Wait for next database change */ |
| 4781 | set_bit(N2N_LOGIN_NEEDED, &vha->dpc_flags); |
| 4782 | } |
| 4783 | |
| 4784 | return res; |
| 4785 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4786 | |
| 4787 | /* |
| 4788 | * qla2x00_configure_local_loop |
| 4789 | * Updates Fibre Channel Device Database with local loop devices. |
| 4790 | * |
| 4791 | * Input: |
| 4792 | * ha = adapter block pointer. |
| 4793 | * |
| 4794 | * Returns: |
| 4795 | * 0 = success. |
| 4796 | */ |
| 4797 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4798 | qla2x00_configure_local_loop(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4799 | { |
| 4800 | int rval, rval2; |
| 4801 | int found_devs; |
| 4802 | int found; |
| 4803 | fc_port_t *fcport, *new_fcport; |
| 4804 | |
| 4805 | uint16_t index; |
| 4806 | uint16_t entries; |
| 4807 | char *id_iter; |
| 4808 | uint16_t loop_id; |
| 4809 | uint8_t domain, area, al_pa; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4810 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4811 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4812 | |
| 4813 | found_devs = 0; |
| 4814 | new_fcport = NULL; |
Chad Dupuis | 642ef98 | 2012-02-09 11:15:57 -0800 | [diff] [blame] | 4815 | entries = MAX_FIBRE_DEVICES_LOOP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4816 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4817 | /* Get list of logged in devices. */ |
Chad Dupuis | 642ef98 | 2012-02-09 11:15:57 -0800 | [diff] [blame] | 4818 | memset(ha->gid_list, 0, qla2x00_gid_list_size(ha)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4819 | rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4820 | &entries); |
| 4821 | if (rval != QLA_SUCCESS) |
| 4822 | goto cleanup_allocation; |
| 4823 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4824 | ql_dbg(ql_dbg_disc, vha, 0x2011, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4825 | "Entries in ID list (%d).\n", entries); |
| 4826 | ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2075, |
| 4827 | (uint8_t *)ha->gid_list, |
| 4828 | entries * sizeof(struct gid_list_info)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4829 | |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 4830 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
| 4831 | fcport->scan_state = QLA_FCPORT_SCAN; |
| 4832 | } |
| 4833 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4834 | /* Allocate temporary fcport for any new fcports discovered. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4835 | new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4836 | if (new_fcport == NULL) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4837 | ql_log(ql_log_warn, vha, 0x2012, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4838 | "Memory allocation failed for fcport.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4839 | rval = QLA_MEMORY_ALLOC_FAILED; |
| 4840 | goto cleanup_allocation; |
| 4841 | } |
| 4842 | new_fcport->flags &= ~FCF_FABRIC_DEVICE; |
| 4843 | |
Duane Grigsby | edd05de | 2017-10-13 09:34:06 -0700 | [diff] [blame] | 4844 | /* Inititae N2N login. */ |
| 4845 | if (test_and_clear_bit(N2N_LOGIN_NEEDED, &vha->dpc_flags)) { |
| 4846 | rval = qla24xx_n2n_handle_login(vha, new_fcport); |
| 4847 | if (rval != QLA_SUCCESS) |
| 4848 | goto cleanup_allocation; |
| 4849 | return QLA_SUCCESS; |
| 4850 | } |
| 4851 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4852 | /* Add devices to port list. */ |
| 4853 | id_iter = (char *)ha->gid_list; |
| 4854 | for (index = 0; index < entries; index++) { |
| 4855 | domain = ((struct gid_list_info *)id_iter)->domain; |
| 4856 | area = ((struct gid_list_info *)id_iter)->area; |
| 4857 | al_pa = ((struct gid_list_info *)id_iter)->al_pa; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 4858 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4859 | loop_id = (uint16_t) |
| 4860 | ((struct gid_list_info *)id_iter)->loop_id_2100; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 4861 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4862 | loop_id = le16_to_cpu( |
| 4863 | ((struct gid_list_info *)id_iter)->loop_id); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 4864 | id_iter += ha->gid_list_info_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4865 | |
| 4866 | /* Bypass reserved domain fields. */ |
| 4867 | if ((domain & 0xf0) == 0xf0) |
| 4868 | continue; |
| 4869 | |
| 4870 | /* Bypass if not same domain and area of adapter. */ |
Andrew Vasquez | f7d289f | 2005-08-26 19:08:40 -0700 | [diff] [blame] | 4871 | if (area && domain && |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4872 | (area != vha->d_id.b.area || domain != vha->d_id.b.domain)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4873 | continue; |
| 4874 | |
| 4875 | /* Bypass invalid local loop ID. */ |
| 4876 | if (loop_id > LAST_LOCAL_LOOP_ID) |
| 4877 | continue; |
| 4878 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4879 | memset(new_fcport->port_name, 0, WWN_SIZE); |
Arun Easi | 370d550 | 2012-08-22 14:21:10 -0400 | [diff] [blame] | 4880 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4881 | /* Fill in member data. */ |
| 4882 | new_fcport->d_id.b.domain = domain; |
| 4883 | new_fcport->d_id.b.area = area; |
| 4884 | new_fcport->d_id.b.al_pa = al_pa; |
| 4885 | new_fcport->loop_id = loop_id; |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 4886 | new_fcport->scan_state = QLA_FCPORT_FOUND; |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4887 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4888 | rval2 = qla2x00_get_port_database(vha, new_fcport, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4889 | if (rval2 != QLA_SUCCESS) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4890 | ql_dbg(ql_dbg_disc, vha, 0x2097, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4891 | "Failed to retrieve fcport information " |
| 4892 | "-- get_port_database=%x, loop_id=0x%04x.\n", |
| 4893 | rval2, new_fcport->loop_id); |
Duane Grigsby | edd05de | 2017-10-13 09:34:06 -0700 | [diff] [blame] | 4894 | /* Skip retry if N2N */ |
| 4895 | if (ha->current_topology != ISP_CFG_N) { |
| 4896 | ql_dbg(ql_dbg_disc, vha, 0x2105, |
| 4897 | "Scheduling resync.\n"); |
| 4898 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
| 4899 | continue; |
| 4900 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4901 | } |
| 4902 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4903 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4904 | /* Check for matching device in port list. */ |
| 4905 | found = 0; |
| 4906 | fcport = NULL; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4907 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4908 | if (memcmp(new_fcport->port_name, fcport->port_name, |
| 4909 | WWN_SIZE)) |
| 4910 | continue; |
| 4911 | |
Shyam Sundar | ddb9b12 | 2009-03-24 09:08:10 -0700 | [diff] [blame] | 4912 | fcport->flags &= ~FCF_FABRIC_DEVICE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4913 | fcport->loop_id = new_fcport->loop_id; |
| 4914 | fcport->port_type = new_fcport->port_type; |
| 4915 | fcport->d_id.b24 = new_fcport->d_id.b24; |
| 4916 | memcpy(fcport->node_name, new_fcport->node_name, |
| 4917 | WWN_SIZE); |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 4918 | fcport->scan_state = QLA_FCPORT_FOUND; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4919 | found++; |
| 4920 | break; |
| 4921 | } |
| 4922 | |
| 4923 | if (!found) { |
| 4924 | /* New device, add to fcports list. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4925 | list_add_tail(&new_fcport->list, &vha->vp_fcports); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4926 | |
| 4927 | /* Allocate a new replacement fcport. */ |
| 4928 | fcport = new_fcport; |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4929 | |
| 4930 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
| 4931 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4932 | new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4933 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4934 | if (new_fcport == NULL) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4935 | ql_log(ql_log_warn, vha, 0xd031, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4936 | "Failed to allocate memory for fcport.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4937 | rval = QLA_MEMORY_ALLOC_FAILED; |
| 4938 | goto cleanup_allocation; |
| 4939 | } |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4940 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4941 | new_fcport->flags &= ~FCF_FABRIC_DEVICE; |
| 4942 | } |
| 4943 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4944 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
| 4945 | |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 4946 | /* Base iIDMA settings on HBA port speed. */ |
Andrew Vasquez | a3cbdfa | 2007-08-13 10:13:18 -0700 | [diff] [blame] | 4947 | fcport->fp_speed = ha->link_data_rate; |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 4948 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4949 | found_devs++; |
| 4950 | } |
| 4951 | |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 4952 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
| 4953 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) |
| 4954 | break; |
| 4955 | |
| 4956 | if (fcport->scan_state == QLA_FCPORT_SCAN) { |
| 4957 | if ((qla_dual_mode_enabled(vha) || |
| 4958 | qla_ini_mode_enabled(vha)) && |
| 4959 | atomic_read(&fcport->state) == FCS_ONLINE) { |
| 4960 | qla2x00_mark_device_lost(vha, fcport, |
| 4961 | ql2xplogiabsentdevice, 0); |
| 4962 | if (fcport->loop_id != FC_NO_LOOP_ID && |
| 4963 | (fcport->flags & FCF_FCP2_DEVICE) == 0 && |
| 4964 | fcport->port_type != FCT_INITIATOR && |
| 4965 | fcport->port_type != FCT_BROADCAST) { |
| 4966 | ql_dbg(ql_dbg_disc, vha, 0x20f0, |
| 4967 | "%s %d %8phC post del sess\n", |
| 4968 | __func__, __LINE__, |
| 4969 | fcport->port_name); |
| 4970 | |
Quinn Tran | d8630bb | 2017-12-28 12:33:43 -0800 | [diff] [blame] | 4971 | qlt_schedule_sess_for_deletion(fcport); |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 4972 | continue; |
| 4973 | } |
| 4974 | } |
| 4975 | } |
| 4976 | |
| 4977 | if (fcport->scan_state == QLA_FCPORT_FOUND) |
| 4978 | qla24xx_fcport_handle_login(vha, fcport); |
| 4979 | } |
| 4980 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4981 | cleanup_allocation: |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 4982 | kfree(new_fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4983 | |
| 4984 | if (rval != QLA_SUCCESS) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4985 | ql_dbg(ql_dbg_disc, vha, 0x2098, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4986 | "Configure local loop error exit: rval=%x.\n", rval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4987 | } |
| 4988 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4989 | return (rval); |
| 4990 | } |
| 4991 | |
| 4992 | static void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4993 | qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport) |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 4994 | { |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 4995 | int rval; |
Quinn Tran | 93f2bd6 | 2014-09-25 05:16:53 -0400 | [diff] [blame] | 4996 | uint16_t mb[MAILBOX_REGISTER_COUNT]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4997 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 4998 | |
Andrew Vasquez | c76f2c0 | 2007-07-19 15:05:57 -0700 | [diff] [blame] | 4999 | if (!IS_IIDMA_CAPABLE(ha)) |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 5000 | return; |
| 5001 | |
Giridhar Malavali | c9afb9a | 2010-09-03 15:20:48 -0700 | [diff] [blame] | 5002 | if (atomic_read(&fcport->state) != FCS_ONLINE) |
| 5003 | return; |
| 5004 | |
Andrew Vasquez | 39bd962 | 2007-09-20 14:07:34 -0700 | [diff] [blame] | 5005 | if (fcport->fp_speed == PORT_SPEED_UNKNOWN || |
| 5006 | fcport->fp_speed > ha->link_data_rate) |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 5007 | return; |
| 5008 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5009 | rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed, |
Andrew Vasquez | a3cbdfa | 2007-08-13 10:13:18 -0700 | [diff] [blame] | 5010 | mb); |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 5011 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5012 | ql_dbg(ql_dbg_disc, vha, 0x2004, |
Oleksandr Khoshaba | 7b833558 | 2013-08-27 01:37:27 -0400 | [diff] [blame] | 5013 | "Unable to adjust iIDMA %8phN -- %04x %x %04x %04x.\n", |
| 5014 | fcport->port_name, rval, fcport->fp_speed, mb[0], mb[1]); |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 5015 | } else { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5016 | ql_dbg(ql_dbg_disc, vha, 0x2005, |
Oleksandr Khoshaba | 7b833558 | 2013-08-27 01:37:27 -0400 | [diff] [blame] | 5017 | "iIDMA adjusted to %s GB/s on %8phN.\n", |
Joe Carnuccio | d0297c9 | 2012-11-21 02:40:40 -0500 | [diff] [blame] | 5018 | qla2x00_get_link_speed_str(ha, fcport->fp_speed), |
Oleksandr Khoshaba | 7b833558 | 2013-08-27 01:37:27 -0400 | [diff] [blame] | 5019 | fcport->port_name); |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 5020 | } |
| 5021 | } |
| 5022 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5023 | /* qla2x00_reg_remote_port is reserved for Initiator Mode only.*/ |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 5024 | static void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5025 | qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport) |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 5026 | { |
| 5027 | struct fc_rport_identifiers rport_ids; |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 5028 | struct fc_rport *rport; |
Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 5029 | unsigned long flags; |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 5030 | |
Andrew Vasquez | f8b02a8 | 2005-08-31 15:21:20 -0700 | [diff] [blame] | 5031 | rport_ids.node_name = wwn_to_u64(fcport->node_name); |
| 5032 | rport_ids.port_name = wwn_to_u64(fcport->port_name); |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 5033 | rport_ids.port_id = fcport->d_id.b.domain << 16 | |
| 5034 | fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa; |
| 5035 | rport_ids.roles = FC_RPORT_ROLE_UNKNOWN; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5036 | fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids); |
Andrew Vasquez | 77d7414 | 2005-07-08 18:00:36 -0700 | [diff] [blame] | 5037 | if (!rport) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5038 | ql_log(ql_log_warn, vha, 0x2006, |
| 5039 | "Unable to allocate fc remote port.\n"); |
Andrew Vasquez | 77d7414 | 2005-07-08 18:00:36 -0700 | [diff] [blame] | 5040 | return; |
| 5041 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5042 | |
Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 5043 | spin_lock_irqsave(fcport->vha->host->host_lock, flags); |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 5044 | *((fc_port_t **)rport->dd_data) = fcport; |
Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 5045 | spin_unlock_irqrestore(fcport->vha->host->host_lock, flags); |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 5046 | |
Andrew Vasquez | ad3e0ed | 2005-08-26 19:08:10 -0700 | [diff] [blame] | 5047 | rport->supported_classes = fcport->supported_classes; |
Andrew Vasquez | 77d7414 | 2005-07-08 18:00:36 -0700 | [diff] [blame] | 5048 | |
| 5049 | rport_ids.roles = FC_RPORT_ROLE_UNKNOWN; |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 5050 | if (fcport->port_type == FCT_INITIATOR) |
| 5051 | rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR; |
| 5052 | if (fcport->port_type == FCT_TARGET) |
| 5053 | rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5054 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 5055 | ql_dbg(ql_dbg_disc, vha, 0x20ee, |
| 5056 | "%s %8phN. rport %p is %s mode\n", |
| 5057 | __func__, fcport->port_name, rport, |
| 5058 | (fcport->port_type == FCT_TARGET) ? "tgt" : "ini"); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5059 | |
Andrew Vasquez | 77d7414 | 2005-07-08 18:00:36 -0700 | [diff] [blame] | 5060 | fc_remote_port_rolechg(rport, rport_ids.roles); |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 5061 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5062 | |
| 5063 | /* |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 5064 | * qla2x00_update_fcport |
| 5065 | * Updates device on list. |
| 5066 | * |
| 5067 | * Input: |
| 5068 | * ha = adapter block pointer. |
| 5069 | * fcport = port structure pointer. |
| 5070 | * |
| 5071 | * Return: |
| 5072 | * 0 - Success |
| 5073 | * BIT_0 - error |
| 5074 | * |
| 5075 | * Context: |
| 5076 | * Kernel context. |
| 5077 | */ |
| 5078 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5079 | qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport) |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 5080 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5081 | fcport->vha = vha; |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 5082 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5083 | if (IS_SW_RESV_ADDR(fcport->d_id)) |
| 5084 | return; |
| 5085 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 5086 | ql_dbg(ql_dbg_disc, vha, 0x20ef, "%s %8phC\n", |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5087 | __func__, fcport->port_name); |
| 5088 | |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 5089 | if (IS_QLAFX00(vha->hw)) { |
| 5090 | qla2x00_set_fcport_state(fcport, FCS_ONLINE); |
Alexei Potashnik | d20ed91 | 2015-07-14 16:00:47 -0400 | [diff] [blame] | 5091 | goto reg_port; |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 5092 | } |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 5093 | fcport->login_retry = 0; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 5094 | fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5095 | fcport->disc_state = DSC_LOGIN_COMPLETE; |
| 5096 | fcport->deleted = 0; |
| 5097 | fcport->logout_on_delete = 1; |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 5098 | |
Duane Grigsby | e84067d | 2017-06-21 13:48:43 -0700 | [diff] [blame] | 5099 | if (fcport->fc4f_nvme) { |
| 5100 | qla_nvme_register_remote(vha, fcport); |
| 5101 | return; |
| 5102 | } |
| 5103 | |
Joe Carnuccio | 1f93da52 | 2012-11-21 02:40:38 -0500 | [diff] [blame] | 5104 | qla2x00_set_fcport_state(fcport, FCS_ONLINE); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5105 | qla2x00_iidma_fcport(vha, fcport); |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 5106 | qla24xx_update_fcport_fcp_prio(vha, fcport); |
Alexei Potashnik | d20ed91 | 2015-07-14 16:00:47 -0400 | [diff] [blame] | 5107 | |
| 5108 | reg_port: |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5109 | switch (vha->host->active_mode) { |
| 5110 | case MODE_INITIATOR: |
Alexei Potashnik | d20ed91 | 2015-07-14 16:00:47 -0400 | [diff] [blame] | 5111 | qla2x00_reg_remote_port(vha, fcport); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5112 | break; |
| 5113 | case MODE_TARGET: |
| 5114 | if (!vha->vha_tgt.qla_tgt->tgt_stop && |
| 5115 | !vha->vha_tgt.qla_tgt->tgt_stopped) |
| 5116 | qlt_fc_port_added(vha, fcport); |
| 5117 | break; |
| 5118 | case MODE_DUAL: |
| 5119 | qla2x00_reg_remote_port(vha, fcport); |
| 5120 | if (!vha->vha_tgt.qla_tgt->tgt_stop && |
| 5121 | !vha->vha_tgt.qla_tgt->tgt_stopped) |
| 5122 | qlt_fc_port_added(vha, fcport); |
| 5123 | break; |
| 5124 | default: |
| 5125 | break; |
Alexei Potashnik | d20ed91 | 2015-07-14 16:00:47 -0400 | [diff] [blame] | 5126 | } |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 5127 | } |
| 5128 | |
| 5129 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5130 | * qla2x00_configure_fabric |
| 5131 | * Setup SNS devices with loop ID's. |
| 5132 | * |
| 5133 | * Input: |
| 5134 | * ha = adapter block pointer. |
| 5135 | * |
| 5136 | * Returns: |
| 5137 | * 0 = success. |
| 5138 | * BIT_0 = error |
| 5139 | */ |
| 5140 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5141 | qla2x00_configure_fabric(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5142 | { |
Arun Easi | b3b02e6 | 2012-02-09 11:15:39 -0800 | [diff] [blame] | 5143 | int rval; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5144 | fc_port_t *fcport; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5145 | uint16_t mb[MAILBOX_REGISTER_COUNT]; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5146 | uint16_t loop_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5147 | LIST_HEAD(new_fcports); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5148 | struct qla_hw_data *ha = vha->hw; |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 5149 | int discovery_gen; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5150 | |
| 5151 | /* If FL port exists, then SNS is present */ |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 5152 | if (IS_FWI2_CAPABLE(ha)) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5153 | loop_id = NPH_F_PORT; |
| 5154 | else |
| 5155 | loop_id = SNS_FL_PORT; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5156 | rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5157 | if (rval != QLA_SUCCESS) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 5158 | ql_dbg(ql_dbg_disc, vha, 0x20a0, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5159 | "MBX_GET_PORT_NAME failed, No FL Port.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5160 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5161 | vha->device_flags &= ~SWITCH_FOUND; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5162 | return (QLA_SUCCESS); |
| 5163 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5164 | vha->device_flags |= SWITCH_FOUND; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5165 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 5166 | |
| 5167 | if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) { |
| 5168 | rval = qla2x00_send_change_request(vha, 0x3, 0); |
| 5169 | if (rval != QLA_SUCCESS) |
| 5170 | ql_log(ql_log_warn, vha, 0x121, |
| 5171 | "Failed to enable receiving of RSCN requests: 0x%x.\n", |
| 5172 | rval); |
| 5173 | } |
| 5174 | |
| 5175 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5176 | do { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5177 | qla2x00_mgmt_svr_login(vha); |
| 5178 | |
Andrew Vasquez | cca5335 | 2005-08-26 19:08:30 -0700 | [diff] [blame] | 5179 | /* FDMI support. */ |
| 5180 | if (ql2xfdmienable && |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5181 | test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags)) |
| 5182 | qla2x00_fdmi_register(vha); |
Andrew Vasquez | cca5335 | 2005-08-26 19:08:30 -0700 | [diff] [blame] | 5183 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5184 | /* Ensure we are logged into the SNS. */ |
Joe Carnuccio | a14c771 | 2017-08-23 15:05:12 -0700 | [diff] [blame] | 5185 | loop_id = NPH_SNS_LID(ha); |
Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 5186 | rval = ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff, |
| 5187 | 0xfc, mb, BIT_1|BIT_0); |
Joe Carnuccio | a14c771 | 2017-08-23 15:05:12 -0700 | [diff] [blame] | 5188 | if (rval != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) { |
| 5189 | ql_dbg(ql_dbg_disc, vha, 0x20a1, |
| 5190 | "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x mb[6]=%x mb[7]=%x (%x).\n", |
| 5191 | loop_id, mb[0], mb[1], mb[2], mb[6], mb[7], rval); |
Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 5192 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
Joe Carnuccio | e452ceb | 2013-02-08 01:57:56 -0500 | [diff] [blame] | 5193 | return rval; |
Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 5194 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5195 | if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) { |
| 5196 | if (qla2x00_rft_id(vha)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5197 | /* EMPTY */ |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 5198 | ql_dbg(ql_dbg_disc, vha, 0x20a2, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5199 | "Register FC-4 TYPE failed.\n"); |
Quinn Tran | b98ae0d | 2017-06-02 09:12:00 -0700 | [diff] [blame] | 5200 | if (test_bit(LOOP_RESYNC_NEEDED, |
| 5201 | &vha->dpc_flags)) |
| 5202 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5203 | } |
Duane Grigsby | d3bae93 | 2017-06-21 13:48:44 -0700 | [diff] [blame] | 5204 | if (qla2x00_rff_id(vha, FC4_TYPE_FCP_SCSI)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5205 | /* EMPTY */ |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 5206 | ql_dbg(ql_dbg_disc, vha, 0x209a, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5207 | "Register FC-4 Features failed.\n"); |
Quinn Tran | b98ae0d | 2017-06-02 09:12:00 -0700 | [diff] [blame] | 5208 | if (test_bit(LOOP_RESYNC_NEEDED, |
| 5209 | &vha->dpc_flags)) |
| 5210 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5211 | } |
Duane Grigsby | d3bae93 | 2017-06-21 13:48:44 -0700 | [diff] [blame] | 5212 | if (vha->flags.nvme_enabled) { |
| 5213 | if (qla2x00_rff_id(vha, FC_TYPE_NVME)) { |
| 5214 | ql_dbg(ql_dbg_disc, vha, 0x2049, |
| 5215 | "Register NVME FC Type Features failed.\n"); |
| 5216 | } |
| 5217 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5218 | if (qla2x00_rnn_id(vha)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5219 | /* EMPTY */ |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 5220 | ql_dbg(ql_dbg_disc, vha, 0x2104, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5221 | "Register Node Name failed.\n"); |
Quinn Tran | b98ae0d | 2017-06-02 09:12:00 -0700 | [diff] [blame] | 5222 | if (test_bit(LOOP_RESYNC_NEEDED, |
| 5223 | &vha->dpc_flags)) |
| 5224 | break; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5225 | } else if (qla2x00_rsnn_nn(vha)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5226 | /* EMPTY */ |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 5227 | ql_dbg(ql_dbg_disc, vha, 0x209b, |
Colin Ian King | 0bf0efa | 2017-06-30 14:47:41 +0100 | [diff] [blame] | 5228 | "Register Symbolic Node Name failed.\n"); |
Quinn Tran | b98ae0d | 2017-06-02 09:12:00 -0700 | [diff] [blame] | 5229 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) |
| 5230 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5231 | } |
| 5232 | } |
| 5233 | |
Joe Carnuccio | 827210b | 2013-02-08 01:57:57 -0500 | [diff] [blame] | 5234 | |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 5235 | /* Mark the time right before querying FW for connected ports. |
| 5236 | * This process is long, asynchronous and by the time it's done, |
| 5237 | * collected information might not be accurate anymore. E.g. |
| 5238 | * disconnected port might have re-connected and a brand new |
| 5239 | * session has been created. In this case session's generation |
| 5240 | * will be newer than discovery_gen. */ |
| 5241 | qlt_do_generation_tick(vha, &discovery_gen); |
| 5242 | |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 5243 | if (USE_ASYNC_SCAN(ha)) { |
| 5244 | rval = QLA_SUCCESS; |
| 5245 | rval = qla24xx_async_gpnft(vha, FC4_TYPE_FCP_SCSI); |
| 5246 | if (rval) |
| 5247 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
| 5248 | } else { |
Quinn Tran | f352eeb | 2017-12-28 12:33:35 -0800 | [diff] [blame] | 5249 | list_for_each_entry(fcport, &vha->vp_fcports, list) |
| 5250 | fcport->scan_state = QLA_FCPORT_SCAN; |
| 5251 | |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 5252 | rval = qla2x00_find_all_fabric_devs(vha); |
| 5253 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5254 | if (rval != QLA_SUCCESS) |
| 5255 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5256 | } while (0); |
| 5257 | |
Duane Grigsby | e84067d | 2017-06-21 13:48:43 -0700 | [diff] [blame] | 5258 | if (!vha->nvme_local_port && vha->flags.nvme_enabled) |
| 5259 | qla_nvme_register_hba(vha); |
| 5260 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5261 | if (rval) |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5262 | ql_dbg(ql_dbg_disc, vha, 0x2068, |
| 5263 | "Configure fabric error exit rval=%d.\n", rval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5264 | |
| 5265 | return (rval); |
| 5266 | } |
| 5267 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5268 | /* |
| 5269 | * qla2x00_find_all_fabric_devs |
| 5270 | * |
| 5271 | * Input: |
| 5272 | * ha = adapter block pointer. |
| 5273 | * dev = database device entry pointer. |
| 5274 | * |
| 5275 | * Returns: |
| 5276 | * 0 = success. |
| 5277 | * |
| 5278 | * Context: |
| 5279 | * Kernel context. |
| 5280 | */ |
| 5281 | static int |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5282 | qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5283 | { |
| 5284 | int rval; |
| 5285 | uint16_t loop_id; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5286 | fc_port_t *fcport, *new_fcport; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5287 | int found; |
| 5288 | |
| 5289 | sw_info_t *swl; |
| 5290 | int swl_idx; |
| 5291 | int first_dev, last_dev; |
Mike Waychison | 1516ef4 | 2010-05-04 15:01:31 -0700 | [diff] [blame] | 5292 | port_id_t wrap = {}, nxt_d_id; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5293 | struct qla_hw_data *ha = vha->hw; |
Chad Dupuis | bb4cf5b | 2013-02-08 01:58:01 -0500 | [diff] [blame] | 5294 | struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5295 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5296 | |
| 5297 | rval = QLA_SUCCESS; |
| 5298 | |
| 5299 | /* Try GID_PT to get device list, else GAN. */ |
Andrew Vasquez | 7a67735 | 2012-02-09 11:15:56 -0800 | [diff] [blame] | 5300 | if (!ha->swl) |
Chad Dupuis | 642ef98 | 2012-02-09 11:15:57 -0800 | [diff] [blame] | 5301 | ha->swl = kcalloc(ha->max_fibre_devices, sizeof(sw_info_t), |
Andrew Vasquez | 7a67735 | 2012-02-09 11:15:56 -0800 | [diff] [blame] | 5302 | GFP_KERNEL); |
| 5303 | swl = ha->swl; |
Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 5304 | if (!swl) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5305 | /*EMPTY*/ |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 5306 | ql_dbg(ql_dbg_disc, vha, 0x209c, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5307 | "GID_PT allocations failed, fallback on GA_NXT.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5308 | } else { |
Chad Dupuis | 642ef98 | 2012-02-09 11:15:57 -0800 | [diff] [blame] | 5309 | memset(swl, 0, ha->max_fibre_devices * sizeof(sw_info_t)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5310 | if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5311 | swl = NULL; |
Quinn Tran | b98ae0d | 2017-06-02 09:12:00 -0700 | [diff] [blame] | 5312 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) |
| 5313 | return rval; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5314 | } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5315 | swl = NULL; |
Quinn Tran | b98ae0d | 2017-06-02 09:12:00 -0700 | [diff] [blame] | 5316 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) |
| 5317 | return rval; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5318 | } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5319 | swl = NULL; |
Quinn Tran | b98ae0d | 2017-06-02 09:12:00 -0700 | [diff] [blame] | 5320 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) |
| 5321 | return rval; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5322 | } else if (qla2x00_gfpn_id(vha, swl) != QLA_SUCCESS) { |
| 5323 | swl = NULL; |
Quinn Tran | b98ae0d | 2017-06-02 09:12:00 -0700 | [diff] [blame] | 5324 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) |
| 5325 | return rval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5326 | } |
Chad Dupuis | e8c72ba | 2010-07-23 15:28:25 +0500 | [diff] [blame] | 5327 | |
| 5328 | /* If other queries succeeded probe for FC-4 type */ |
Quinn Tran | b98ae0d | 2017-06-02 09:12:00 -0700 | [diff] [blame] | 5329 | if (swl) { |
Chad Dupuis | e8c72ba | 2010-07-23 15:28:25 +0500 | [diff] [blame] | 5330 | qla2x00_gff_id(vha, swl); |
Quinn Tran | b98ae0d | 2017-06-02 09:12:00 -0700 | [diff] [blame] | 5331 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) |
| 5332 | return rval; |
| 5333 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5334 | } |
| 5335 | swl_idx = 0; |
| 5336 | |
| 5337 | /* Allocate temporary fcport for any new fcports discovered. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5338 | new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5339 | if (new_fcport == NULL) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 5340 | ql_log(ql_log_warn, vha, 0x209d, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5341 | "Failed to allocate memory for fcport.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5342 | return (QLA_MEMORY_ALLOC_FAILED); |
| 5343 | } |
| 5344 | new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5345 | /* Set start port ID scan at adapter ID. */ |
| 5346 | first_dev = 1; |
| 5347 | last_dev = 0; |
| 5348 | |
| 5349 | /* Starting free loop ID. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5350 | loop_id = ha->min_external_loopid; |
| 5351 | for (; loop_id <= ha->max_loop_id; loop_id++) { |
| 5352 | if (qla2x00_is_reserved_id(vha, loop_id)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5353 | continue; |
| 5354 | |
Giridhar Malavali | 3a6478d | 2010-05-28 15:08:20 -0700 | [diff] [blame] | 5355 | if (ha->current_topology == ISP_CFG_FL && |
| 5356 | (atomic_read(&vha->loop_down_timer) || |
| 5357 | LOOP_TRANSITION(vha))) { |
Andrew Vasquez | bb2d52b | 2010-02-18 10:07:27 -0800 | [diff] [blame] | 5358 | atomic_set(&vha->loop_down_timer, 0); |
| 5359 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
| 5360 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5361 | break; |
Andrew Vasquez | bb2d52b | 2010-02-18 10:07:27 -0800 | [diff] [blame] | 5362 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5363 | |
| 5364 | if (swl != NULL) { |
| 5365 | if (last_dev) { |
| 5366 | wrap.b24 = new_fcport->d_id.b24; |
| 5367 | } else { |
| 5368 | new_fcport->d_id.b24 = swl[swl_idx].d_id.b24; |
| 5369 | memcpy(new_fcport->node_name, |
| 5370 | swl[swl_idx].node_name, WWN_SIZE); |
| 5371 | memcpy(new_fcport->port_name, |
| 5372 | swl[swl_idx].port_name, WWN_SIZE); |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 5373 | memcpy(new_fcport->fabric_port_name, |
| 5374 | swl[swl_idx].fabric_port_name, WWN_SIZE); |
| 5375 | new_fcport->fp_speed = swl[swl_idx].fp_speed; |
Chad Dupuis | e8c72ba | 2010-07-23 15:28:25 +0500 | [diff] [blame] | 5376 | new_fcport->fc4_type = swl[swl_idx].fc4_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5377 | |
Duane Grigsby | a5d42f4 | 2017-06-21 13:48:41 -0700 | [diff] [blame] | 5378 | new_fcport->nvme_flag = 0; |
Darren Trap | 1a28faa | 2017-08-30 10:16:48 -0700 | [diff] [blame] | 5379 | new_fcport->fc4f_nvme = 0; |
Duane Grigsby | a5d42f4 | 2017-06-21 13:48:41 -0700 | [diff] [blame] | 5380 | if (vha->flags.nvme_enabled && |
| 5381 | swl[swl_idx].fc4f_nvme) { |
| 5382 | new_fcport->fc4f_nvme = |
| 5383 | swl[swl_idx].fc4f_nvme; |
| 5384 | ql_log(ql_log_info, vha, 0x2131, |
| 5385 | "FOUND: NVME port %8phC as FC Type 28h\n", |
| 5386 | new_fcport->port_name); |
| 5387 | } |
| 5388 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5389 | if (swl[swl_idx].d_id.b.rsvd_1 != 0) { |
| 5390 | last_dev = 1; |
| 5391 | } |
| 5392 | swl_idx++; |
| 5393 | } |
| 5394 | } else { |
| 5395 | /* Send GA_NXT to the switch */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5396 | rval = qla2x00_ga_nxt(vha, new_fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5397 | if (rval != QLA_SUCCESS) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 5398 | ql_log(ql_log_warn, vha, 0x209e, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5399 | "SNS scan failed -- assuming " |
| 5400 | "zero-entry result.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5401 | rval = QLA_SUCCESS; |
| 5402 | break; |
| 5403 | } |
| 5404 | } |
| 5405 | |
| 5406 | /* If wrap on switch device list, exit. */ |
| 5407 | if (first_dev) { |
| 5408 | wrap.b24 = new_fcport->d_id.b24; |
| 5409 | first_dev = 0; |
| 5410 | } else if (new_fcport->d_id.b24 == wrap.b24) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 5411 | ql_dbg(ql_dbg_disc, vha, 0x209f, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5412 | "Device wrap (%02x%02x%02x).\n", |
| 5413 | new_fcport->d_id.b.domain, |
| 5414 | new_fcport->d_id.b.area, |
| 5415 | new_fcport->d_id.b.al_pa); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5416 | break; |
| 5417 | } |
| 5418 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 5419 | /* Bypass if same physical adapter. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5420 | if (new_fcport->d_id.b24 == base_vha->d_id.b24) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5421 | continue; |
| 5422 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 5423 | /* Bypass virtual ports of the same host. */ |
Chad Dupuis | bb4cf5b | 2013-02-08 01:58:01 -0500 | [diff] [blame] | 5424 | if (qla2x00_is_a_vp_did(vha, new_fcport->d_id.b24)) |
| 5425 | continue; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 5426 | |
Andrew Vasquez | f7d289f | 2005-08-26 19:08:40 -0700 | [diff] [blame] | 5427 | /* Bypass if same domain and area of adapter. */ |
| 5428 | if (((new_fcport->d_id.b24 & 0xffff00) == |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5429 | (vha->d_id.b24 & 0xffff00)) && ha->current_topology == |
Andrew Vasquez | f7d289f | 2005-08-26 19:08:40 -0700 | [diff] [blame] | 5430 | ISP_CFG_FL) |
| 5431 | continue; |
| 5432 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5433 | /* Bypass reserved domain fields. */ |
| 5434 | if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0) |
| 5435 | continue; |
| 5436 | |
Chad Dupuis | e8c72ba | 2010-07-23 15:28:25 +0500 | [diff] [blame] | 5437 | /* Bypass ports whose FCP-4 type is not FCP_SCSI */ |
Chad Dupuis | 4da26e1 | 2010-10-15 11:27:40 -0700 | [diff] [blame] | 5438 | if (ql2xgffidenable && |
| 5439 | (new_fcport->fc4_type != FC4_TYPE_FCP_SCSI && |
| 5440 | new_fcport->fc4_type != FC4_TYPE_UNKNOWN)) |
Chad Dupuis | e8c72ba | 2010-07-23 15:28:25 +0500 | [diff] [blame] | 5441 | continue; |
| 5442 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5443 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
| 5444 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5445 | /* Locate matching device in database. */ |
| 5446 | found = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5447 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5448 | if (memcmp(new_fcport->port_name, fcport->port_name, |
| 5449 | WWN_SIZE)) |
| 5450 | continue; |
| 5451 | |
Joe Carnuccio | 827210b | 2013-02-08 01:57:57 -0500 | [diff] [blame] | 5452 | fcport->scan_state = QLA_FCPORT_FOUND; |
Arun Easi | b3b02e6 | 2012-02-09 11:15:39 -0800 | [diff] [blame] | 5453 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5454 | found++; |
| 5455 | |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 5456 | /* Update port state. */ |
| 5457 | memcpy(fcport->fabric_port_name, |
| 5458 | new_fcport->fabric_port_name, WWN_SIZE); |
| 5459 | fcport->fp_speed = new_fcport->fp_speed; |
| 5460 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5461 | /* |
Roland Dreier | b2032fd | 2015-07-14 16:00:42 -0400 | [diff] [blame] | 5462 | * If address the same and state FCS_ONLINE |
| 5463 | * (or in target mode), nothing changed. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5464 | */ |
| 5465 | if (fcport->d_id.b24 == new_fcport->d_id.b24 && |
Roland Dreier | b2032fd | 2015-07-14 16:00:42 -0400 | [diff] [blame] | 5466 | (atomic_read(&fcport->state) == FCS_ONLINE || |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5467 | (vha->host->active_mode == MODE_TARGET))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5468 | break; |
| 5469 | } |
| 5470 | |
| 5471 | /* |
| 5472 | * If device was not a fabric device before. |
| 5473 | */ |
| 5474 | if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) { |
| 5475 | fcport->d_id.b24 = new_fcport->d_id.b24; |
Chad Dupuis | 5f16b33 | 2012-08-22 14:21:00 -0400 | [diff] [blame] | 5476 | qla2x00_clear_loop_id(fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5477 | fcport->flags |= (FCF_FABRIC_DEVICE | |
| 5478 | FCF_LOGIN_NEEDED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5479 | break; |
| 5480 | } |
| 5481 | |
| 5482 | /* |
| 5483 | * Port ID changed or device was marked to be updated; |
| 5484 | * Log it out if still logged in and mark it for |
| 5485 | * relogin later. |
| 5486 | */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5487 | if (qla_tgt_mode_enabled(base_vha)) { |
Roland Dreier | b2032fd | 2015-07-14 16:00:42 -0400 | [diff] [blame] | 5488 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf080, |
| 5489 | "port changed FC ID, %8phC" |
| 5490 | " old %x:%x:%x (loop_id 0x%04x)-> new %x:%x:%x\n", |
| 5491 | fcport->port_name, |
| 5492 | fcport->d_id.b.domain, |
| 5493 | fcport->d_id.b.area, |
| 5494 | fcport->d_id.b.al_pa, |
| 5495 | fcport->loop_id, |
| 5496 | new_fcport->d_id.b.domain, |
| 5497 | new_fcport->d_id.b.area, |
| 5498 | new_fcport->d_id.b.al_pa); |
| 5499 | fcport->d_id.b24 = new_fcport->d_id.b24; |
| 5500 | break; |
| 5501 | } |
| 5502 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5503 | fcport->d_id.b24 = new_fcport->d_id.b24; |
| 5504 | fcport->flags |= FCF_LOGIN_NEEDED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5505 | break; |
| 5506 | } |
| 5507 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5508 | if (found) { |
| 5509 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5510 | continue; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5511 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5512 | /* If device was not in our fcports list, then add it. */ |
Roland Dreier | b2032fd | 2015-07-14 16:00:42 -0400 | [diff] [blame] | 5513 | new_fcport->scan_state = QLA_FCPORT_FOUND; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5514 | list_add_tail(&new_fcport->list, &vha->vp_fcports); |
| 5515 | |
| 5516 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
| 5517 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5518 | |
| 5519 | /* Allocate a new replacement fcport. */ |
| 5520 | nxt_d_id.b24 = new_fcport->d_id.b24; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5521 | new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5522 | if (new_fcport == NULL) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 5523 | ql_log(ql_log_warn, vha, 0xd032, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5524 | "Memory allocation failed for fcport.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5525 | return (QLA_MEMORY_ALLOC_FAILED); |
| 5526 | } |
| 5527 | new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED); |
| 5528 | new_fcport->d_id.b24 = nxt_d_id.b24; |
| 5529 | } |
| 5530 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5531 | qla2x00_free_fcport(new_fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5532 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5533 | /* |
| 5534 | * Logout all previous fabric dev marked lost, except FCP2 devices. |
| 5535 | */ |
| 5536 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
| 5537 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) |
| 5538 | break; |
| 5539 | |
| 5540 | if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 || |
| 5541 | (fcport->flags & FCF_LOGIN_NEEDED) == 0) |
| 5542 | continue; |
| 5543 | |
| 5544 | if (fcport->scan_state == QLA_FCPORT_SCAN) { |
| 5545 | if ((qla_dual_mode_enabled(vha) || |
| 5546 | qla_ini_mode_enabled(vha)) && |
| 5547 | atomic_read(&fcport->state) == FCS_ONLINE) { |
| 5548 | qla2x00_mark_device_lost(vha, fcport, |
| 5549 | ql2xplogiabsentdevice, 0); |
| 5550 | if (fcport->loop_id != FC_NO_LOOP_ID && |
| 5551 | (fcport->flags & FCF_FCP2_DEVICE) == 0 && |
| 5552 | fcport->port_type != FCT_INITIATOR && |
| 5553 | fcport->port_type != FCT_BROADCAST) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 5554 | ql_dbg(ql_dbg_disc, vha, 0x20f0, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5555 | "%s %d %8phC post del sess\n", |
| 5556 | __func__, __LINE__, |
| 5557 | fcport->port_name); |
Quinn Tran | d8630bb | 2017-12-28 12:33:43 -0800 | [diff] [blame] | 5558 | qlt_schedule_sess_for_deletion(fcport); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5559 | continue; |
| 5560 | } |
| 5561 | } |
| 5562 | } |
| 5563 | |
| 5564 | if (fcport->scan_state == QLA_FCPORT_FOUND) |
| 5565 | qla24xx_fcport_handle_login(vha, fcport); |
| 5566 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5567 | return (rval); |
| 5568 | } |
| 5569 | |
| 5570 | /* |
| 5571 | * qla2x00_find_new_loop_id |
| 5572 | * Scan through our port list and find a new usable loop ID. |
| 5573 | * |
| 5574 | * Input: |
| 5575 | * ha: adapter state pointer. |
| 5576 | * dev: port structure pointer. |
| 5577 | * |
| 5578 | * Returns: |
| 5579 | * qla2x00 local function return status code. |
| 5580 | * |
| 5581 | * Context: |
| 5582 | * Kernel context. |
| 5583 | */ |
Joe Carnuccio | 03bcfb5 | 2011-03-30 11:46:27 -0700 | [diff] [blame] | 5584 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5585 | qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5586 | { |
| 5587 | int rval; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5588 | struct qla_hw_data *ha = vha->hw; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5589 | unsigned long flags = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5590 | |
| 5591 | rval = QLA_SUCCESS; |
| 5592 | |
Chad Dupuis | 5f16b33 | 2012-08-22 14:21:00 -0400 | [diff] [blame] | 5593 | spin_lock_irqsave(&ha->vport_slock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5594 | |
Chad Dupuis | 5f16b33 | 2012-08-22 14:21:00 -0400 | [diff] [blame] | 5595 | dev->loop_id = find_first_zero_bit(ha->loop_id_map, |
| 5596 | LOOPID_MAP_SIZE); |
| 5597 | if (dev->loop_id >= LOOPID_MAP_SIZE || |
| 5598 | qla2x00_is_reserved_id(vha, dev->loop_id)) { |
| 5599 | dev->loop_id = FC_NO_LOOP_ID; |
| 5600 | rval = QLA_FUNCTION_FAILED; |
| 5601 | } else |
| 5602 | set_bit(dev->loop_id, ha->loop_id_map); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5603 | |
Chad Dupuis | 5f16b33 | 2012-08-22 14:21:00 -0400 | [diff] [blame] | 5604 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5605 | |
Chad Dupuis | 5f16b33 | 2012-08-22 14:21:00 -0400 | [diff] [blame] | 5606 | if (rval == QLA_SUCCESS) |
| 5607 | ql_dbg(ql_dbg_disc, dev->vha, 0x2086, |
| 5608 | "Assigning new loopid=%x, portid=%x.\n", |
| 5609 | dev->loop_id, dev->d_id.b24); |
| 5610 | else |
| 5611 | ql_log(ql_log_warn, dev->vha, 0x2087, |
| 5612 | "No loop_id's available, portid=%x.\n", |
| 5613 | dev->d_id.b24); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5614 | |
| 5615 | return (rval); |
| 5616 | } |
| 5617 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5618 | |
| 5619 | /* |
| 5620 | * qla2x00_fabric_login |
| 5621 | * Issue fabric login command. |
| 5622 | * |
| 5623 | * Input: |
| 5624 | * ha = adapter block pointer. |
| 5625 | * device = pointer to FC device type structure. |
| 5626 | * |
| 5627 | * Returns: |
| 5628 | * 0 - Login successfully |
| 5629 | * 1 - Login failed |
| 5630 | * 2 - Initiator device |
| 5631 | * 3 - Fatal error |
| 5632 | */ |
| 5633 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5634 | qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5635 | uint16_t *next_loopid) |
| 5636 | { |
| 5637 | int rval; |
| 5638 | int retry; |
| 5639 | uint16_t tmp_loopid; |
| 5640 | uint16_t mb[MAILBOX_REGISTER_COUNT]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5641 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5642 | |
| 5643 | retry = 0; |
| 5644 | tmp_loopid = 0; |
| 5645 | |
| 5646 | for (;;) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5647 | ql_dbg(ql_dbg_disc, vha, 0x2000, |
| 5648 | "Trying Fabric Login w/loop id 0x%04x for port " |
| 5649 | "%02x%02x%02x.\n", |
| 5650 | fcport->loop_id, fcport->d_id.b.domain, |
| 5651 | fcport->d_id.b.area, fcport->d_id.b.al_pa); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5652 | |
| 5653 | /* Login fcport on switch. */ |
Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 5654 | rval = ha->isp_ops->fabric_login(vha, fcport->loop_id, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5655 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 5656 | fcport->d_id.b.al_pa, mb, BIT_0); |
Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 5657 | if (rval != QLA_SUCCESS) { |
| 5658 | return rval; |
| 5659 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5660 | if (mb[0] == MBS_PORT_ID_USED) { |
| 5661 | /* |
| 5662 | * Device has another loop ID. The firmware team |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5663 | * recommends the driver perform an implicit login with |
| 5664 | * the specified ID again. The ID we just used is save |
| 5665 | * here so we return with an ID that can be tried by |
| 5666 | * the next login. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5667 | */ |
| 5668 | retry++; |
| 5669 | tmp_loopid = fcport->loop_id; |
| 5670 | fcport->loop_id = mb[1]; |
| 5671 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5672 | ql_dbg(ql_dbg_disc, vha, 0x2001, |
| 5673 | "Fabric Login: port in use - next loop " |
| 5674 | "id=0x%04x, port id= %02x%02x%02x.\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5675 | fcport->loop_id, fcport->d_id.b.domain, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5676 | fcport->d_id.b.area, fcport->d_id.b.al_pa); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5677 | |
| 5678 | } else if (mb[0] == MBS_COMMAND_COMPLETE) { |
| 5679 | /* |
| 5680 | * Login succeeded. |
| 5681 | */ |
| 5682 | if (retry) { |
| 5683 | /* A retry occurred before. */ |
| 5684 | *next_loopid = tmp_loopid; |
| 5685 | } else { |
| 5686 | /* |
| 5687 | * No retry occurred before. Just increment the |
| 5688 | * ID value for next login. |
| 5689 | */ |
| 5690 | *next_loopid = (fcport->loop_id + 1); |
| 5691 | } |
| 5692 | |
| 5693 | if (mb[1] & BIT_0) { |
| 5694 | fcport->port_type = FCT_INITIATOR; |
| 5695 | } else { |
| 5696 | fcport->port_type = FCT_TARGET; |
| 5697 | if (mb[1] & BIT_1) { |
Santosh Vernekar | 8474f3a | 2009-08-25 11:36:16 -0700 | [diff] [blame] | 5698 | fcport->flags |= FCF_FCP2_DEVICE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5699 | } |
| 5700 | } |
| 5701 | |
Andrew Vasquez | ad3e0ed | 2005-08-26 19:08:10 -0700 | [diff] [blame] | 5702 | if (mb[10] & BIT_0) |
| 5703 | fcport->supported_classes |= FC_COS_CLASS2; |
| 5704 | if (mb[10] & BIT_1) |
| 5705 | fcport->supported_classes |= FC_COS_CLASS3; |
| 5706 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5707 | if (IS_FWI2_CAPABLE(ha)) { |
| 5708 | if (mb[10] & BIT_7) |
| 5709 | fcport->flags |= |
| 5710 | FCF_CONF_COMP_SUPPORTED; |
| 5711 | } |
| 5712 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5713 | rval = QLA_SUCCESS; |
| 5714 | break; |
| 5715 | } else if (mb[0] == MBS_LOOP_ID_USED) { |
| 5716 | /* |
| 5717 | * Loop ID already used, try next loop ID. |
| 5718 | */ |
| 5719 | fcport->loop_id++; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5720 | rval = qla2x00_find_new_loop_id(vha, fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5721 | if (rval != QLA_SUCCESS) { |
| 5722 | /* Ran out of loop IDs to use */ |
| 5723 | break; |
| 5724 | } |
| 5725 | } else if (mb[0] == MBS_COMMAND_ERROR) { |
| 5726 | /* |
| 5727 | * Firmware possibly timed out during login. If NO |
| 5728 | * retries are left to do then the device is declared |
| 5729 | * dead. |
| 5730 | */ |
| 5731 | *next_loopid = fcport->loop_id; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5732 | ha->isp_ops->fabric_logout(vha, fcport->loop_id, |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 5733 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 5734 | fcport->d_id.b.al_pa); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5735 | qla2x00_mark_device_lost(vha, fcport, 1, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5736 | |
| 5737 | rval = 1; |
| 5738 | break; |
| 5739 | } else { |
| 5740 | /* |
| 5741 | * unrecoverable / not handled error |
| 5742 | */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5743 | ql_dbg(ql_dbg_disc, vha, 0x2002, |
| 5744 | "Failed=%x port_id=%02x%02x%02x loop_id=%x " |
| 5745 | "jiffies=%lx.\n", mb[0], fcport->d_id.b.domain, |
| 5746 | fcport->d_id.b.area, fcport->d_id.b.al_pa, |
| 5747 | fcport->loop_id, jiffies); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5748 | |
| 5749 | *next_loopid = fcport->loop_id; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5750 | ha->isp_ops->fabric_logout(vha, fcport->loop_id, |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 5751 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 5752 | fcport->d_id.b.al_pa); |
Chad Dupuis | 5f16b33 | 2012-08-22 14:21:00 -0400 | [diff] [blame] | 5753 | qla2x00_clear_loop_id(fcport); |
Andrew Vasquez | 0eedfcf | 2005-10-27 11:09:38 -0700 | [diff] [blame] | 5754 | fcport->login_retry = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5755 | |
| 5756 | rval = 3; |
| 5757 | break; |
| 5758 | } |
| 5759 | } |
| 5760 | |
| 5761 | return (rval); |
| 5762 | } |
| 5763 | |
| 5764 | /* |
| 5765 | * qla2x00_local_device_login |
| 5766 | * Issue local device login command. |
| 5767 | * |
| 5768 | * Input: |
| 5769 | * ha = adapter block pointer. |
| 5770 | * loop_id = loop id of device to login to. |
| 5771 | * |
| 5772 | * Returns (Where's the #define!!!!): |
| 5773 | * 0 - Login successfully |
| 5774 | * 1 - Login failed |
| 5775 | * 3 - Fatal error |
| 5776 | */ |
| 5777 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5778 | qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5779 | { |
| 5780 | int rval; |
| 5781 | uint16_t mb[MAILBOX_REGISTER_COUNT]; |
| 5782 | |
| 5783 | memset(mb, 0, sizeof(mb)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5784 | rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5785 | if (rval == QLA_SUCCESS) { |
| 5786 | /* Interrogate mailbox registers for any errors */ |
| 5787 | if (mb[0] == MBS_COMMAND_ERROR) |
| 5788 | rval = 1; |
| 5789 | else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR) |
| 5790 | /* device not in PCB table */ |
| 5791 | rval = 3; |
| 5792 | } |
| 5793 | |
| 5794 | return (rval); |
| 5795 | } |
| 5796 | |
| 5797 | /* |
| 5798 | * qla2x00_loop_resync |
| 5799 | * Resync with fibre channel devices. |
| 5800 | * |
| 5801 | * Input: |
| 5802 | * ha = adapter block pointer. |
| 5803 | * |
| 5804 | * Returns: |
| 5805 | * 0 = success |
| 5806 | */ |
| 5807 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5808 | qla2x00_loop_resync(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5809 | { |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5810 | int rval = QLA_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5811 | uint32_t wait_time; |
Anirban Chakraborty | 67c2e93 | 2009-04-06 22:33:42 -0700 | [diff] [blame] | 5812 | struct req_que *req; |
| 5813 | struct rsp_que *rsp; |
| 5814 | |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 5815 | req = vha->req; |
Anirban Chakraborty | 67c2e93 | 2009-04-06 22:33:42 -0700 | [diff] [blame] | 5816 | rsp = req->rsp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5817 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5818 | clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags); |
| 5819 | if (vha->flags.online) { |
| 5820 | if (!(rval = qla2x00_fw_ready(vha))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5821 | /* Wait at most MAX_TARGET RSCNs for a stable link. */ |
| 5822 | wait_time = 256; |
| 5823 | do { |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 5824 | if (!IS_QLAFX00(vha->hw)) { |
| 5825 | /* |
| 5826 | * Issue a marker after FW becomes |
| 5827 | * ready. |
| 5828 | */ |
| 5829 | qla2x00_marker(vha, req, rsp, 0, 0, |
| 5830 | MK_SYNC_ALL); |
| 5831 | vha->marker_needed = 0; |
| 5832 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5833 | |
| 5834 | /* Remap devices on Loop. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5835 | clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5836 | |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 5837 | if (IS_QLAFX00(vha->hw)) |
| 5838 | qlafx00_configure_devices(vha); |
| 5839 | else |
| 5840 | qla2x00_configure_loop(vha); |
| 5841 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5842 | wait_time--; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5843 | } while (!atomic_read(&vha->loop_down_timer) && |
| 5844 | !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) |
| 5845 | && wait_time && (test_bit(LOOP_RESYNC_NEEDED, |
| 5846 | &vha->dpc_flags))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5847 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5848 | } |
| 5849 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5850 | if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5851 | return (QLA_FUNCTION_FAILED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5852 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5853 | if (rval) |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5854 | ql_dbg(ql_dbg_disc, vha, 0x206c, |
| 5855 | "%s *** FAILED ***.\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5856 | |
| 5857 | return (rval); |
| 5858 | } |
| 5859 | |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 5860 | /* |
| 5861 | * qla2x00_perform_loop_resync |
| 5862 | * Description: This function will set the appropriate flags and call |
| 5863 | * qla2x00_loop_resync. If successful loop will be resynced |
| 5864 | * Arguments : scsi_qla_host_t pointer |
| 5865 | * returm : Success or Failure |
| 5866 | */ |
| 5867 | |
| 5868 | int qla2x00_perform_loop_resync(scsi_qla_host_t *ha) |
| 5869 | { |
| 5870 | int32_t rval = 0; |
| 5871 | |
| 5872 | if (!test_and_set_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags)) { |
| 5873 | /*Configure the flags so that resync happens properly*/ |
| 5874 | atomic_set(&ha->loop_down_timer, 0); |
| 5875 | if (!(ha->device_flags & DFLG_NO_CABLE)) { |
| 5876 | atomic_set(&ha->loop_state, LOOP_UP); |
| 5877 | set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags); |
| 5878 | set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags); |
| 5879 | set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags); |
| 5880 | |
| 5881 | rval = qla2x00_loop_resync(ha); |
| 5882 | } else |
| 5883 | atomic_set(&ha->loop_state, LOOP_DEAD); |
| 5884 | |
| 5885 | clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags); |
| 5886 | } |
| 5887 | |
| 5888 | return rval; |
| 5889 | } |
| 5890 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5891 | void |
Andrew Vasquez | 67becc0 | 2009-08-25 11:36:20 -0700 | [diff] [blame] | 5892 | qla2x00_update_fcports(scsi_qla_host_t *base_vha) |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 5893 | { |
| 5894 | fc_port_t *fcport; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5895 | struct scsi_qla_host *vha; |
| 5896 | struct qla_hw_data *ha = base_vha->hw; |
| 5897 | unsigned long flags; |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 5898 | |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5899 | spin_lock_irqsave(&ha->vport_slock, flags); |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 5900 | /* Go with deferred removal of rport references. */ |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5901 | list_for_each_entry(vha, &base_vha->hw->vp_list, list) { |
| 5902 | atomic_inc(&vha->vref_count); |
| 5903 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
Dan Carpenter | 8ae598d | 2010-12-21 16:00:15 -0800 | [diff] [blame] | 5904 | if (fcport->drport && |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5905 | atomic_read(&fcport->state) != FCS_UNCONFIGURED) { |
| 5906 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
Andrew Vasquez | 67becc0 | 2009-08-25 11:36:20 -0700 | [diff] [blame] | 5907 | qla2x00_rport_del(fcport); |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 5908 | |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5909 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 5910 | } |
| 5911 | } |
| 5912 | atomic_dec(&vha->vref_count); |
Joe Carnuccio | c4a9b53 | 2017-03-15 09:48:43 -0700 | [diff] [blame] | 5913 | wake_up(&vha->vref_waitq); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5914 | } |
| 5915 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 5916 | } |
| 5917 | |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 5918 | /* Assumes idc_lock always held on entry */ |
| 5919 | void |
| 5920 | qla83xx_reset_ownership(scsi_qla_host_t *vha) |
| 5921 | { |
| 5922 | struct qla_hw_data *ha = vha->hw; |
| 5923 | uint32_t drv_presence, drv_presence_mask; |
| 5924 | uint32_t dev_part_info1, dev_part_info2, class_type; |
| 5925 | uint32_t class_type_mask = 0x3; |
| 5926 | uint16_t fcoe_other_function = 0xffff, i; |
| 5927 | |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 5928 | if (IS_QLA8044(ha)) { |
| 5929 | drv_presence = qla8044_rd_direct(vha, |
| 5930 | QLA8044_CRB_DRV_ACTIVE_INDEX); |
| 5931 | dev_part_info1 = qla8044_rd_direct(vha, |
| 5932 | QLA8044_CRB_DEV_PART_INFO_INDEX); |
| 5933 | dev_part_info2 = qla8044_rd_direct(vha, |
| 5934 | QLA8044_CRB_DEV_PART_INFO2); |
| 5935 | } else { |
| 5936 | qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence); |
| 5937 | qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO1, &dev_part_info1); |
| 5938 | qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO2, &dev_part_info2); |
| 5939 | } |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 5940 | for (i = 0; i < 8; i++) { |
| 5941 | class_type = ((dev_part_info1 >> (i * 4)) & class_type_mask); |
| 5942 | if ((class_type == QLA83XX_CLASS_TYPE_FCOE) && |
| 5943 | (i != ha->portnum)) { |
| 5944 | fcoe_other_function = i; |
| 5945 | break; |
| 5946 | } |
| 5947 | } |
| 5948 | if (fcoe_other_function == 0xffff) { |
| 5949 | for (i = 0; i < 8; i++) { |
| 5950 | class_type = ((dev_part_info2 >> (i * 4)) & |
| 5951 | class_type_mask); |
| 5952 | if ((class_type == QLA83XX_CLASS_TYPE_FCOE) && |
| 5953 | ((i + 8) != ha->portnum)) { |
| 5954 | fcoe_other_function = i + 8; |
| 5955 | break; |
| 5956 | } |
| 5957 | } |
| 5958 | } |
| 5959 | /* |
| 5960 | * Prepare drv-presence mask based on fcoe functions present. |
| 5961 | * However consider only valid physical fcoe function numbers (0-15). |
| 5962 | */ |
| 5963 | drv_presence_mask = ~((1 << (ha->portnum)) | |
| 5964 | ((fcoe_other_function == 0xffff) ? |
| 5965 | 0 : (1 << (fcoe_other_function)))); |
| 5966 | |
| 5967 | /* We are the reset owner iff: |
| 5968 | * - No other protocol drivers present. |
| 5969 | * - This is the lowest among fcoe functions. */ |
| 5970 | if (!(drv_presence & drv_presence_mask) && |
| 5971 | (ha->portnum < fcoe_other_function)) { |
| 5972 | ql_dbg(ql_dbg_p3p, vha, 0xb07f, |
| 5973 | "This host is Reset owner.\n"); |
| 5974 | ha->flags.nic_core_reset_owner = 1; |
| 5975 | } |
| 5976 | } |
| 5977 | |
Saurav Kashyap | fa49263 | 2012-11-21 02:40:29 -0500 | [diff] [blame] | 5978 | static int |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 5979 | __qla83xx_set_drv_ack(scsi_qla_host_t *vha) |
| 5980 | { |
| 5981 | int rval = QLA_SUCCESS; |
| 5982 | struct qla_hw_data *ha = vha->hw; |
| 5983 | uint32_t drv_ack; |
| 5984 | |
| 5985 | rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack); |
| 5986 | if (rval == QLA_SUCCESS) { |
| 5987 | drv_ack |= (1 << ha->portnum); |
| 5988 | rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack); |
| 5989 | } |
| 5990 | |
| 5991 | return rval; |
| 5992 | } |
| 5993 | |
Saurav Kashyap | fa49263 | 2012-11-21 02:40:29 -0500 | [diff] [blame] | 5994 | static int |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 5995 | __qla83xx_clear_drv_ack(scsi_qla_host_t *vha) |
| 5996 | { |
| 5997 | int rval = QLA_SUCCESS; |
| 5998 | struct qla_hw_data *ha = vha->hw; |
| 5999 | uint32_t drv_ack; |
| 6000 | |
| 6001 | rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack); |
| 6002 | if (rval == QLA_SUCCESS) { |
| 6003 | drv_ack &= ~(1 << ha->portnum); |
| 6004 | rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack); |
| 6005 | } |
| 6006 | |
| 6007 | return rval; |
| 6008 | } |
| 6009 | |
Saurav Kashyap | fa49263 | 2012-11-21 02:40:29 -0500 | [diff] [blame] | 6010 | static const char * |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 6011 | qla83xx_dev_state_to_string(uint32_t dev_state) |
| 6012 | { |
| 6013 | switch (dev_state) { |
| 6014 | case QLA8XXX_DEV_COLD: |
| 6015 | return "COLD/RE-INIT"; |
| 6016 | case QLA8XXX_DEV_INITIALIZING: |
| 6017 | return "INITIALIZING"; |
| 6018 | case QLA8XXX_DEV_READY: |
| 6019 | return "READY"; |
| 6020 | case QLA8XXX_DEV_NEED_RESET: |
| 6021 | return "NEED RESET"; |
| 6022 | case QLA8XXX_DEV_NEED_QUIESCENT: |
| 6023 | return "NEED QUIESCENT"; |
| 6024 | case QLA8XXX_DEV_FAILED: |
| 6025 | return "FAILED"; |
| 6026 | case QLA8XXX_DEV_QUIESCENT: |
| 6027 | return "QUIESCENT"; |
| 6028 | default: |
| 6029 | return "Unknown"; |
| 6030 | } |
| 6031 | } |
| 6032 | |
| 6033 | /* Assumes idc-lock always held on entry */ |
| 6034 | void |
| 6035 | qla83xx_idc_audit(scsi_qla_host_t *vha, int audit_type) |
| 6036 | { |
| 6037 | struct qla_hw_data *ha = vha->hw; |
| 6038 | uint32_t idc_audit_reg = 0, duration_secs = 0; |
| 6039 | |
| 6040 | switch (audit_type) { |
| 6041 | case IDC_AUDIT_TIMESTAMP: |
| 6042 | ha->idc_audit_ts = (jiffies_to_msecs(jiffies) / 1000); |
| 6043 | idc_audit_reg = (ha->portnum) | |
| 6044 | (IDC_AUDIT_TIMESTAMP << 7) | (ha->idc_audit_ts << 8); |
| 6045 | qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg); |
| 6046 | break; |
| 6047 | |
| 6048 | case IDC_AUDIT_COMPLETION: |
| 6049 | duration_secs = ((jiffies_to_msecs(jiffies) - |
| 6050 | jiffies_to_msecs(ha->idc_audit_ts)) / 1000); |
| 6051 | idc_audit_reg = (ha->portnum) | |
| 6052 | (IDC_AUDIT_COMPLETION << 7) | (duration_secs << 8); |
| 6053 | qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg); |
| 6054 | break; |
| 6055 | |
| 6056 | default: |
| 6057 | ql_log(ql_log_warn, vha, 0xb078, |
| 6058 | "Invalid audit type specified.\n"); |
| 6059 | break; |
| 6060 | } |
| 6061 | } |
| 6062 | |
| 6063 | /* Assumes idc_lock always held on entry */ |
Saurav Kashyap | fa49263 | 2012-11-21 02:40:29 -0500 | [diff] [blame] | 6064 | static int |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 6065 | qla83xx_initiating_reset(scsi_qla_host_t *vha) |
| 6066 | { |
| 6067 | struct qla_hw_data *ha = vha->hw; |
| 6068 | uint32_t idc_control, dev_state; |
| 6069 | |
| 6070 | __qla83xx_get_idc_control(vha, &idc_control); |
| 6071 | if ((idc_control & QLA83XX_IDC_RESET_DISABLED)) { |
| 6072 | ql_log(ql_log_info, vha, 0xb080, |
| 6073 | "NIC Core reset has been disabled. idc-control=0x%x\n", |
| 6074 | idc_control); |
| 6075 | return QLA_FUNCTION_FAILED; |
| 6076 | } |
| 6077 | |
| 6078 | /* Set NEED-RESET iff in READY state and we are the reset-owner */ |
| 6079 | qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state); |
| 6080 | if (ha->flags.nic_core_reset_owner && dev_state == QLA8XXX_DEV_READY) { |
| 6081 | qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, |
| 6082 | QLA8XXX_DEV_NEED_RESET); |
| 6083 | ql_log(ql_log_info, vha, 0xb056, "HW State: NEED RESET.\n"); |
| 6084 | qla83xx_idc_audit(vha, IDC_AUDIT_TIMESTAMP); |
| 6085 | } else { |
| 6086 | const char *state = qla83xx_dev_state_to_string(dev_state); |
| 6087 | ql_log(ql_log_info, vha, 0xb057, "HW State: %s.\n", state); |
| 6088 | |
| 6089 | /* SV: XXX: Is timeout required here? */ |
| 6090 | /* Wait for IDC state change READY -> NEED_RESET */ |
| 6091 | while (dev_state == QLA8XXX_DEV_READY) { |
| 6092 | qla83xx_idc_unlock(vha, 0); |
| 6093 | msleep(200); |
| 6094 | qla83xx_idc_lock(vha, 0); |
| 6095 | qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state); |
| 6096 | } |
| 6097 | } |
| 6098 | |
| 6099 | /* Send IDC ack by writing to drv-ack register */ |
| 6100 | __qla83xx_set_drv_ack(vha); |
| 6101 | |
| 6102 | return QLA_SUCCESS; |
| 6103 | } |
| 6104 | |
| 6105 | int |
| 6106 | __qla83xx_set_idc_control(scsi_qla_host_t *vha, uint32_t idc_control) |
| 6107 | { |
| 6108 | return qla83xx_wr_reg(vha, QLA83XX_IDC_CONTROL, idc_control); |
| 6109 | } |
| 6110 | |
| 6111 | int |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 6112 | __qla83xx_get_idc_control(scsi_qla_host_t *vha, uint32_t *idc_control) |
| 6113 | { |
| 6114 | return qla83xx_rd_reg(vha, QLA83XX_IDC_CONTROL, idc_control); |
| 6115 | } |
| 6116 | |
Saurav Kashyap | fa49263 | 2012-11-21 02:40:29 -0500 | [diff] [blame] | 6117 | static int |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 6118 | qla83xx_check_driver_presence(scsi_qla_host_t *vha) |
| 6119 | { |
| 6120 | uint32_t drv_presence = 0; |
| 6121 | struct qla_hw_data *ha = vha->hw; |
| 6122 | |
| 6123 | qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence); |
| 6124 | if (drv_presence & (1 << ha->portnum)) |
| 6125 | return QLA_SUCCESS; |
| 6126 | else |
| 6127 | return QLA_TEST_FAILED; |
| 6128 | } |
| 6129 | |
| 6130 | int |
| 6131 | qla83xx_nic_core_reset(scsi_qla_host_t *vha) |
| 6132 | { |
| 6133 | int rval = QLA_SUCCESS; |
| 6134 | struct qla_hw_data *ha = vha->hw; |
| 6135 | |
| 6136 | ql_dbg(ql_dbg_p3p, vha, 0xb058, |
| 6137 | "Entered %s().\n", __func__); |
| 6138 | |
| 6139 | if (vha->device_flags & DFLG_DEV_FAILED) { |
| 6140 | ql_log(ql_log_warn, vha, 0xb059, |
| 6141 | "Device in unrecoverable FAILED state.\n"); |
| 6142 | return QLA_FUNCTION_FAILED; |
| 6143 | } |
| 6144 | |
| 6145 | qla83xx_idc_lock(vha, 0); |
| 6146 | |
| 6147 | if (qla83xx_check_driver_presence(vha) != QLA_SUCCESS) { |
| 6148 | ql_log(ql_log_warn, vha, 0xb05a, |
| 6149 | "Function=0x%x has been removed from IDC participation.\n", |
| 6150 | ha->portnum); |
| 6151 | rval = QLA_FUNCTION_FAILED; |
| 6152 | goto exit; |
| 6153 | } |
| 6154 | |
| 6155 | qla83xx_reset_ownership(vha); |
| 6156 | |
| 6157 | rval = qla83xx_initiating_reset(vha); |
| 6158 | |
| 6159 | /* |
| 6160 | * Perform reset if we are the reset-owner, |
| 6161 | * else wait till IDC state changes to READY/FAILED. |
| 6162 | */ |
| 6163 | if (rval == QLA_SUCCESS) { |
| 6164 | rval = qla83xx_idc_state_handler(vha); |
| 6165 | |
| 6166 | if (rval == QLA_SUCCESS) |
| 6167 | ha->flags.nic_core_hung = 0; |
| 6168 | __qla83xx_clear_drv_ack(vha); |
| 6169 | } |
| 6170 | |
| 6171 | exit: |
| 6172 | qla83xx_idc_unlock(vha, 0); |
| 6173 | |
| 6174 | ql_dbg(ql_dbg_p3p, vha, 0xb05b, "Exiting %s.\n", __func__); |
| 6175 | |
| 6176 | return rval; |
| 6177 | } |
| 6178 | |
Saurav Kashyap | 8117877 | 2012-08-22 14:21:04 -0400 | [diff] [blame] | 6179 | int |
| 6180 | qla2xxx_mctp_dump(scsi_qla_host_t *vha) |
| 6181 | { |
| 6182 | struct qla_hw_data *ha = vha->hw; |
| 6183 | int rval = QLA_FUNCTION_FAILED; |
| 6184 | |
| 6185 | if (!IS_MCTP_CAPABLE(ha)) { |
| 6186 | /* This message can be removed from the final version */ |
| 6187 | ql_log(ql_log_info, vha, 0x506d, |
| 6188 | "This board is not MCTP capable\n"); |
| 6189 | return rval; |
| 6190 | } |
| 6191 | |
| 6192 | if (!ha->mctp_dump) { |
| 6193 | ha->mctp_dump = dma_alloc_coherent(&ha->pdev->dev, |
| 6194 | MCTP_DUMP_SIZE, &ha->mctp_dump_dma, GFP_KERNEL); |
| 6195 | |
| 6196 | if (!ha->mctp_dump) { |
| 6197 | ql_log(ql_log_warn, vha, 0x506e, |
| 6198 | "Failed to allocate memory for mctp dump\n"); |
| 6199 | return rval; |
| 6200 | } |
| 6201 | } |
| 6202 | |
| 6203 | #define MCTP_DUMP_STR_ADDR 0x00000000 |
| 6204 | rval = qla2x00_dump_mctp_data(vha, ha->mctp_dump_dma, |
| 6205 | MCTP_DUMP_STR_ADDR, MCTP_DUMP_SIZE/4); |
| 6206 | if (rval != QLA_SUCCESS) { |
| 6207 | ql_log(ql_log_warn, vha, 0x506f, |
| 6208 | "Failed to capture mctp dump\n"); |
| 6209 | } else { |
| 6210 | ql_log(ql_log_info, vha, 0x5070, |
| 6211 | "Mctp dump capture for host (%ld/%p).\n", |
| 6212 | vha->host_no, ha->mctp_dump); |
| 6213 | ha->mctp_dumped = 1; |
| 6214 | } |
| 6215 | |
Saurav Kashyap | 409ee0f | 2012-08-22 14:21:29 -0400 | [diff] [blame] | 6216 | if (!ha->flags.nic_core_reset_hdlr_active && !ha->portnum) { |
Saurav Kashyap | 8117877 | 2012-08-22 14:21:04 -0400 | [diff] [blame] | 6217 | ha->flags.nic_core_reset_hdlr_active = 1; |
| 6218 | rval = qla83xx_restart_nic_firmware(vha); |
| 6219 | if (rval) |
| 6220 | /* NIC Core reset failed. */ |
| 6221 | ql_log(ql_log_warn, vha, 0x5071, |
| 6222 | "Failed to restart nic firmware\n"); |
| 6223 | else |
| 6224 | ql_dbg(ql_dbg_p3p, vha, 0xb084, |
| 6225 | "Restarted NIC firmware successfully.\n"); |
| 6226 | ha->flags.nic_core_reset_hdlr_active = 0; |
| 6227 | } |
| 6228 | |
| 6229 | return rval; |
| 6230 | |
| 6231 | } |
| 6232 | |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 6233 | /* |
Chad Dupuis | 8fcd6b8 | 2012-08-22 14:21:06 -0400 | [diff] [blame] | 6234 | * qla2x00_quiesce_io |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 6235 | * Description: This function will block the new I/Os |
| 6236 | * Its not aborting any I/Os as context |
| 6237 | * is not destroyed during quiescence |
| 6238 | * Arguments: scsi_qla_host_t |
| 6239 | * return : void |
| 6240 | */ |
| 6241 | void |
Chad Dupuis | 8fcd6b8 | 2012-08-22 14:21:06 -0400 | [diff] [blame] | 6242 | qla2x00_quiesce_io(scsi_qla_host_t *vha) |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 6243 | { |
| 6244 | struct qla_hw_data *ha = vha->hw; |
| 6245 | struct scsi_qla_host *vp; |
| 6246 | |
Chad Dupuis | 8fcd6b8 | 2012-08-22 14:21:06 -0400 | [diff] [blame] | 6247 | ql_dbg(ql_dbg_dpc, vha, 0x401d, |
| 6248 | "Quiescing I/O - ha=%p.\n", ha); |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 6249 | |
| 6250 | atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME); |
| 6251 | if (atomic_read(&vha->loop_state) != LOOP_DOWN) { |
| 6252 | atomic_set(&vha->loop_state, LOOP_DOWN); |
| 6253 | qla2x00_mark_all_devices_lost(vha, 0); |
| 6254 | list_for_each_entry(vp, &ha->vp_list, list) |
Chad Dupuis | 8fcd6b8 | 2012-08-22 14:21:06 -0400 | [diff] [blame] | 6255 | qla2x00_mark_all_devices_lost(vp, 0); |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 6256 | } else { |
| 6257 | if (!atomic_read(&vha->loop_down_timer)) |
| 6258 | atomic_set(&vha->loop_down_timer, |
| 6259 | LOOP_DOWN_TIME); |
| 6260 | } |
| 6261 | /* Wait for pending cmds to complete */ |
| 6262 | qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST); |
| 6263 | } |
| 6264 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 6265 | void |
| 6266 | qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha) |
| 6267 | { |
| 6268 | struct qla_hw_data *ha = vha->hw; |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 6269 | struct scsi_qla_host *vp; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 6270 | unsigned long flags; |
Andrew Vasquez | 6aef87b | 2011-02-23 15:27:13 -0800 | [diff] [blame] | 6271 | fc_port_t *fcport; |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 6272 | u16 i; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 6273 | |
Saurav Kashyap | e46ef00 | 2011-02-23 15:27:16 -0800 | [diff] [blame] | 6274 | /* For ISP82XX, driver waits for completion of the commands. |
| 6275 | * online flag should be set. |
| 6276 | */ |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 6277 | if (!(IS_P3P_TYPE(ha))) |
Saurav Kashyap | e46ef00 | 2011-02-23 15:27:16 -0800 | [diff] [blame] | 6278 | vha->flags.online = 0; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 6279 | ha->flags.chip_reset_done = 0; |
| 6280 | clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
Saurav Kashyap | 2be21fa | 2012-05-15 14:34:16 -0400 | [diff] [blame] | 6281 | vha->qla_stats.total_isp_aborts++; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 6282 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6283 | ql_log(ql_log_info, vha, 0x00af, |
| 6284 | "Performing ISP error recovery - ha=%p.\n", ha); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 6285 | |
Saurav Kashyap | e46ef00 | 2011-02-23 15:27:16 -0800 | [diff] [blame] | 6286 | /* For ISP82XX, reset_chip is just disabling interrupts. |
| 6287 | * Driver waits for the completion of the commands. |
| 6288 | * the interrupts need to be enabled. |
| 6289 | */ |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 6290 | if (!(IS_P3P_TYPE(ha))) |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 6291 | ha->isp_ops->reset_chip(vha); |
| 6292 | |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 6293 | SAVE_TOPO(ha); |
| 6294 | ha->flags.rida_fmt2 = 0; |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 6295 | ha->flags.n2n_ae = 0; |
| 6296 | ha->flags.lip_ae = 0; |
| 6297 | ha->current_topology = 0; |
| 6298 | ha->flags.fw_started = 0; |
| 6299 | ha->flags.fw_init_done = 0; |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 6300 | ha->base_qpair->chip_reset++; |
| 6301 | for (i = 0; i < ha->max_qpairs; i++) { |
| 6302 | if (ha->queue_pair_map[i]) |
| 6303 | ha->queue_pair_map[i]->chip_reset = |
| 6304 | ha->base_qpair->chip_reset; |
| 6305 | } |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6306 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 6307 | atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME); |
| 6308 | if (atomic_read(&vha->loop_state) != LOOP_DOWN) { |
| 6309 | atomic_set(&vha->loop_state, LOOP_DOWN); |
| 6310 | qla2x00_mark_all_devices_lost(vha, 0); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 6311 | |
| 6312 | spin_lock_irqsave(&ha->vport_slock, flags); |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 6313 | list_for_each_entry(vp, &ha->vp_list, list) { |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 6314 | atomic_inc(&vp->vref_count); |
| 6315 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 6316 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 6317 | qla2x00_mark_all_devices_lost(vp, 0); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 6318 | |
| 6319 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 6320 | atomic_dec(&vp->vref_count); |
| 6321 | } |
| 6322 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 6323 | } else { |
| 6324 | if (!atomic_read(&vha->loop_down_timer)) |
| 6325 | atomic_set(&vha->loop_down_timer, |
| 6326 | LOOP_DOWN_TIME); |
| 6327 | } |
| 6328 | |
Andrew Vasquez | 6aef87b | 2011-02-23 15:27:13 -0800 | [diff] [blame] | 6329 | /* Clear all async request states across all VPs. */ |
| 6330 | list_for_each_entry(fcport, &vha->vp_fcports, list) |
| 6331 | fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT); |
| 6332 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 6333 | list_for_each_entry(vp, &ha->vp_list, list) { |
| 6334 | atomic_inc(&vp->vref_count); |
| 6335 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 6336 | |
| 6337 | list_for_each_entry(fcport, &vp->vp_fcports, list) |
| 6338 | fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT); |
| 6339 | |
| 6340 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 6341 | atomic_dec(&vp->vref_count); |
| 6342 | } |
| 6343 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 6344 | |
Lalit Chandivade | bddd2d6 | 2010-09-03 15:20:53 -0700 | [diff] [blame] | 6345 | if (!ha->flags.eeh_busy) { |
| 6346 | /* Make sure for ISP 82XX IO DMA is complete */ |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 6347 | if (IS_P3P_TYPE(ha)) { |
Giridhar Malavali | 7190575 | 2011-02-23 15:27:10 -0800 | [diff] [blame] | 6348 | qla82xx_chip_reset_cleanup(vha); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6349 | ql_log(ql_log_info, vha, 0x00b4, |
| 6350 | "Done chip reset cleanup.\n"); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 6351 | |
Saurav Kashyap | e46ef00 | 2011-02-23 15:27:16 -0800 | [diff] [blame] | 6352 | /* Done waiting for pending commands. |
| 6353 | * Reset the online flag. |
| 6354 | */ |
| 6355 | vha->flags.online = 0; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 6356 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6357 | |
Lalit Chandivade | bddd2d6 | 2010-09-03 15:20:53 -0700 | [diff] [blame] | 6358 | /* Requeue all commands in outstanding command list. */ |
| 6359 | qla2x00_abort_all_cmds(vha, DID_RESET << 16); |
| 6360 | } |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 6361 | /* memory barrier */ |
| 6362 | wmb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6363 | } |
| 6364 | |
| 6365 | /* |
| 6366 | * qla2x00_abort_isp |
| 6367 | * Resets ISP and aborts all outstanding commands. |
| 6368 | * |
| 6369 | * Input: |
| 6370 | * ha = adapter block pointer. |
| 6371 | * |
| 6372 | * Returns: |
| 6373 | * 0 = success |
| 6374 | */ |
| 6375 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6376 | qla2x00_abort_isp(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6377 | { |
Andrew Vasquez | 476e897 | 2006-08-23 14:54:55 -0700 | [diff] [blame] | 6378 | int rval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6379 | uint8_t status = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6380 | struct qla_hw_data *ha = vha->hw; |
| 6381 | struct scsi_qla_host *vp; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6382 | struct req_que *req = ha->req_q_map[0]; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 6383 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6384 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6385 | if (vha->flags.online) { |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 6386 | qla2x00_abort_isp_cleanup(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6387 | |
Santosh Vernekar | a6171297 | 2012-08-22 14:21:13 -0400 | [diff] [blame] | 6388 | if (IS_QLA8031(ha)) { |
| 6389 | ql_dbg(ql_dbg_p3p, vha, 0xb05c, |
| 6390 | "Clearing fcoe driver presence.\n"); |
| 6391 | if (qla83xx_clear_drv_presence(vha) != QLA_SUCCESS) |
| 6392 | ql_dbg(ql_dbg_p3p, vha, 0xb073, |
| 6393 | "Error while clearing DRV-Presence.\n"); |
| 6394 | } |
| 6395 | |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 6396 | if (unlikely(pci_channel_offline(ha->pdev) && |
| 6397 | ha->flags.pci_channel_io_perm_failure)) { |
| 6398 | clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags); |
| 6399 | status = 0; |
| 6400 | return status; |
| 6401 | } |
| 6402 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6403 | ha->isp_ops->get_flash_version(vha, req->ring); |
Andrew Vasquez | 30c4766 | 2007-01-29 10:22:21 -0800 | [diff] [blame] | 6404 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6405 | ha->isp_ops->nvram_config(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6406 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6407 | if (!qla2x00_restart_isp(vha)) { |
| 6408 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6409 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6410 | if (!atomic_read(&vha->loop_down_timer)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6411 | /* |
| 6412 | * Issue marker command only when we are going |
| 6413 | * to start the I/O . |
| 6414 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6415 | vha->marker_needed = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6416 | } |
| 6417 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6418 | vha->flags.online = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6419 | |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 6420 | ha->isp_ops->enable_intrs(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6421 | |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 6422 | ha->isp_abort_cnt = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6423 | clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags); |
Andrew Vasquez | 476e897 | 2006-08-23 14:54:55 -0700 | [diff] [blame] | 6424 | |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 6425 | if (IS_QLA81XX(ha) || IS_QLA8031(ha)) |
| 6426 | qla2x00_get_fw_version(vha); |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 6427 | if (ha->fce) { |
| 6428 | ha->flags.fce_enabled = 1; |
| 6429 | memset(ha->fce, 0, |
| 6430 | fce_calc_size(ha->fce_bufs)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6431 | rval = qla2x00_enable_fce_trace(vha, |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 6432 | ha->fce_dma, ha->fce_bufs, ha->fce_mb, |
| 6433 | &ha->fce_bufs); |
| 6434 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6435 | ql_log(ql_log_warn, vha, 0x8033, |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 6436 | "Unable to reinitialize FCE " |
| 6437 | "(%d).\n", rval); |
| 6438 | ha->flags.fce_enabled = 0; |
| 6439 | } |
| 6440 | } |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 6441 | |
| 6442 | if (ha->eft) { |
| 6443 | memset(ha->eft, 0, EFT_SIZE); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6444 | rval = qla2x00_enable_eft_trace(vha, |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 6445 | ha->eft_dma, EFT_NUM_BUFFERS); |
| 6446 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6447 | ql_log(ql_log_warn, vha, 0x8034, |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 6448 | "Unable to reinitialize EFT " |
| 6449 | "(%d).\n", rval); |
| 6450 | } |
| 6451 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6452 | } else { /* failed the ISP abort */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6453 | vha->flags.online = 1; |
| 6454 | if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6455 | if (ha->isp_abort_cnt == 0) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6456 | ql_log(ql_log_fatal, vha, 0x8035, |
| 6457 | "ISP error recover failed - " |
| 6458 | "board disabled.\n"); |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 6459 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6460 | * The next call disables the board |
| 6461 | * completely. |
| 6462 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6463 | ha->isp_ops->reset_adapter(vha); |
| 6464 | vha->flags.online = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6465 | clear_bit(ISP_ABORT_RETRY, |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6466 | &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6467 | status = 0; |
| 6468 | } else { /* schedule another ISP abort */ |
| 6469 | ha->isp_abort_cnt--; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6470 | ql_dbg(ql_dbg_taskm, vha, 0x8020, |
| 6471 | "ISP abort - retry remaining %d.\n", |
| 6472 | ha->isp_abort_cnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6473 | status = 1; |
| 6474 | } |
| 6475 | } else { |
| 6476 | ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6477 | ql_dbg(ql_dbg_taskm, vha, 0x8021, |
| 6478 | "ISP error recovery - retrying (%d) " |
| 6479 | "more times.\n", ha->isp_abort_cnt); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6480 | set_bit(ISP_ABORT_RETRY, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6481 | status = 1; |
| 6482 | } |
| 6483 | } |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 6484 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6485 | } |
| 6486 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6487 | if (!status) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6488 | ql_dbg(ql_dbg_taskm, vha, 0x8022, "%s succeeded.\n", __func__); |
Quinn Tran | 1608cc4 | 2017-08-23 15:05:03 -0700 | [diff] [blame] | 6489 | qla2x00_configure_hba(vha); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 6490 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 6491 | list_for_each_entry(vp, &ha->vp_list, list) { |
| 6492 | if (vp->vp_idx) { |
| 6493 | atomic_inc(&vp->vref_count); |
| 6494 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 6495 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6496 | qla2x00_vp_abort_isp(vp); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 6497 | |
| 6498 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 6499 | atomic_dec(&vp->vref_count); |
| 6500 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6501 | } |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 6502 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 6503 | |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 6504 | if (IS_QLA8031(ha)) { |
| 6505 | ql_dbg(ql_dbg_p3p, vha, 0xb05d, |
| 6506 | "Setting back fcoe driver presence.\n"); |
| 6507 | if (qla83xx_set_drv_presence(vha) != QLA_SUCCESS) |
| 6508 | ql_dbg(ql_dbg_p3p, vha, 0xb074, |
| 6509 | "Error while setting DRV-Presence.\n"); |
| 6510 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6511 | } else { |
Joe Perches | d8424f6 | 2011-11-18 09:03:06 -0800 | [diff] [blame] | 6512 | ql_log(ql_log_warn, vha, 0x8023, "%s **** FAILED ****.\n", |
| 6513 | __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6514 | } |
| 6515 | |
| 6516 | return(status); |
| 6517 | } |
| 6518 | |
| 6519 | /* |
| 6520 | * qla2x00_restart_isp |
| 6521 | * restarts the ISP after a reset |
| 6522 | * |
| 6523 | * Input: |
| 6524 | * ha = adapter block pointer. |
| 6525 | * |
| 6526 | * Returns: |
| 6527 | * 0 = success |
| 6528 | */ |
| 6529 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6530 | qla2x00_restart_isp(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6531 | { |
Andrew Vasquez | c6b2fca | 2009-03-05 11:07:03 -0800 | [diff] [blame] | 6532 | int status = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6533 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6534 | struct req_que *req = ha->req_q_map[0]; |
| 6535 | struct rsp_que *rsp = ha->rsp_q_map[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6536 | |
| 6537 | /* If firmware needs to be loaded */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6538 | if (qla2x00_isp_firmware(vha)) { |
| 6539 | vha->flags.online = 0; |
| 6540 | status = ha->isp_ops->chip_diag(vha); |
| 6541 | if (!status) |
| 6542 | status = qla2x00_setup_chip(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6543 | } |
| 6544 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6545 | if (!status && !(status = qla2x00_init_rings(vha))) { |
| 6546 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); |
Lalit Chandivade | 2533cf6 | 2009-03-24 09:08:07 -0700 | [diff] [blame] | 6547 | ha->flags.chip_reset_done = 1; |
Chad Dupuis | 7108b76 | 2014-04-11 16:54:45 -0400 | [diff] [blame] | 6548 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6549 | /* Initialize the queues in use */ |
| 6550 | qla25xx_init_queues(ha); |
| 6551 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6552 | status = qla2x00_fw_ready(vha); |
| 6553 | if (!status) { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6554 | /* Issue a marker after FW becomes ready. */ |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6555 | qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL); |
Chad Dupuis | 7108b76 | 2014-04-11 16:54:45 -0400 | [diff] [blame] | 6556 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6557 | } |
| 6558 | |
| 6559 | /* if no cable then assume it's good */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6560 | if ((vha->device_flags & DFLG_NO_CABLE)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6561 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6562 | } |
| 6563 | return (status); |
| 6564 | } |
| 6565 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6566 | static int |
| 6567 | qla25xx_init_queues(struct qla_hw_data *ha) |
| 6568 | { |
| 6569 | struct rsp_que *rsp = NULL; |
| 6570 | struct req_que *req = NULL; |
| 6571 | struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev); |
| 6572 | int ret = -1; |
| 6573 | int i; |
| 6574 | |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 6575 | for (i = 1; i < ha->max_rsp_queues; i++) { |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6576 | rsp = ha->rsp_q_map[i]; |
Quinn Tran | cb43285 | 2016-02-04 11:45:16 -0500 | [diff] [blame] | 6577 | if (rsp && test_bit(i, ha->rsp_qid_map)) { |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6578 | rsp->options &= ~BIT_0; |
Anirban Chakraborty | 618a752 | 2009-02-08 20:50:11 -0800 | [diff] [blame] | 6579 | ret = qla25xx_init_rsp_que(base_vha, rsp); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6580 | if (ret != QLA_SUCCESS) |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6581 | ql_dbg(ql_dbg_init, base_vha, 0x00ff, |
| 6582 | "%s Rsp que: %d init failed.\n", |
| 6583 | __func__, rsp->id); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6584 | else |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6585 | ql_dbg(ql_dbg_init, base_vha, 0x0100, |
| 6586 | "%s Rsp que: %d inited.\n", |
| 6587 | __func__, rsp->id); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6588 | } |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 6589 | } |
| 6590 | for (i = 1; i < ha->max_req_queues; i++) { |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6591 | req = ha->req_q_map[i]; |
Quinn Tran | cb43285 | 2016-02-04 11:45:16 -0500 | [diff] [blame] | 6592 | if (req && test_bit(i, ha->req_qid_map)) { |
| 6593 | /* Clear outstanding commands array. */ |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6594 | req->options &= ~BIT_0; |
Anirban Chakraborty | 618a752 | 2009-02-08 20:50:11 -0800 | [diff] [blame] | 6595 | ret = qla25xx_init_req_que(base_vha, req); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6596 | if (ret != QLA_SUCCESS) |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6597 | ql_dbg(ql_dbg_init, base_vha, 0x0101, |
| 6598 | "%s Req que: %d init failed.\n", |
| 6599 | __func__, req->id); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6600 | else |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6601 | ql_dbg(ql_dbg_init, base_vha, 0x0102, |
| 6602 | "%s Req que: %d inited.\n", |
| 6603 | __func__, req->id); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6604 | } |
| 6605 | } |
| 6606 | return ret; |
| 6607 | } |
| 6608 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6609 | /* |
| 6610 | * qla2x00_reset_adapter |
| 6611 | * Reset adapter. |
| 6612 | * |
| 6613 | * Input: |
| 6614 | * ha = adapter block pointer. |
| 6615 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 6616 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6617 | qla2x00_reset_adapter(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6618 | { |
| 6619 | unsigned long flags = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6620 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 6621 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6622 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6623 | vha->flags.online = 0; |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 6624 | ha->isp_ops->disable_intrs(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6625 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6626 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 6627 | WRT_REG_WORD(®->hccr, HCCR_RESET_RISC); |
| 6628 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 6629 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
| 6630 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 6631 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 6632 | } |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6633 | |
| 6634 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6635 | qla24xx_reset_adapter(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6636 | { |
| 6637 | unsigned long flags = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6638 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6639 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; |
| 6640 | |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 6641 | if (IS_P3P_TYPE(ha)) |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 6642 | return; |
| 6643 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6644 | vha->flags.online = 0; |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 6645 | ha->isp_ops->disable_intrs(ha); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6646 | |
| 6647 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 6648 | WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET); |
| 6649 | RD_REG_DWORD(®->hccr); |
| 6650 | WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE); |
| 6651 | RD_REG_DWORD(®->hccr); |
| 6652 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Andrew Vasquez | 09ff36d | 2009-01-22 09:45:30 -0800 | [diff] [blame] | 6653 | |
| 6654 | if (IS_NOPOLLING_TYPE(ha)) |
| 6655 | ha->isp_ops->enable_intrs(ha); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6656 | } |
| 6657 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 6658 | /* On sparc systems, obtain port and node WWN from firmware |
| 6659 | * properties. |
| 6660 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6661 | static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, |
| 6662 | struct nvram_24xx *nv) |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 6663 | { |
| 6664 | #ifdef CONFIG_SPARC |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6665 | struct qla_hw_data *ha = vha->hw; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 6666 | struct pci_dev *pdev = ha->pdev; |
David S. Miller | 15576bc | 2007-05-08 00:36:49 -0700 | [diff] [blame] | 6667 | struct device_node *dp = pci_device_to_OF_node(pdev); |
| 6668 | const u8 *val; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 6669 | int len; |
| 6670 | |
| 6671 | val = of_get_property(dp, "port-wwn", &len); |
| 6672 | if (val && len >= WWN_SIZE) |
| 6673 | memcpy(nv->port_name, val, WWN_SIZE); |
| 6674 | |
| 6675 | val = of_get_property(dp, "node-wwn", &len); |
| 6676 | if (val && len >= WWN_SIZE) |
| 6677 | memcpy(nv->node_name, val, WWN_SIZE); |
| 6678 | #endif |
| 6679 | } |
| 6680 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6681 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6682 | qla24xx_nvram_config(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6683 | { |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 6684 | int rval; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6685 | struct init_cb_24xx *icb; |
| 6686 | struct nvram_24xx *nv; |
| 6687 | uint32_t *dptr; |
| 6688 | uint8_t *dptr1, *dptr2; |
| 6689 | uint32_t chksum; |
| 6690 | uint16_t cnt; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6691 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6692 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 6693 | rval = QLA_SUCCESS; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6694 | icb = (struct init_cb_24xx *)ha->init_cb; |
Seokmann Ju | 281afe1 | 2007-07-26 13:43:34 -0700 | [diff] [blame] | 6695 | nv = ha->nvram; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6696 | |
| 6697 | /* Determine NVRAM starting address. */ |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 6698 | if (ha->port_no == 0) { |
Anirban Chakraborty | e5b68a6 | 2009-04-06 22:33:50 -0700 | [diff] [blame] | 6699 | ha->nvram_base = FA_NVRAM_FUNC0_ADDR; |
| 6700 | ha->vpd_base = FA_NVRAM_VPD0_ADDR; |
| 6701 | } else { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6702 | ha->nvram_base = FA_NVRAM_FUNC1_ADDR; |
andrew.vasquez@qlogic.com | 6f64179 | 2006-03-09 14:27:34 -0800 | [diff] [blame] | 6703 | ha->vpd_base = FA_NVRAM_VPD1_ADDR; |
| 6704 | } |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 6705 | |
Anirban Chakraborty | e5b68a6 | 2009-04-06 22:33:50 -0700 | [diff] [blame] | 6706 | ha->nvram_size = sizeof(struct nvram_24xx); |
| 6707 | ha->vpd_size = FA_NVRAM_VPD_SIZE; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6708 | |
Seokmann Ju | 281afe1 | 2007-07-26 13:43:34 -0700 | [diff] [blame] | 6709 | /* Get VPD data into cache */ |
| 6710 | ha->vpd = ha->nvram + VPD_OFFSET; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6711 | ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd, |
Seokmann Ju | 281afe1 | 2007-07-26 13:43:34 -0700 | [diff] [blame] | 6712 | ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4); |
| 6713 | |
| 6714 | /* Get NVRAM data into cache and calculate checksum. */ |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6715 | dptr = (uint32_t *)nv; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6716 | ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base, |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6717 | ha->nvram_size); |
Joe Carnuccio | da08ef5 | 2016-01-27 12:03:34 -0500 | [diff] [blame] | 6718 | for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++) |
| 6719 | chksum += le32_to_cpu(*dptr); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6720 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6721 | ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x006a, |
| 6722 | "Contents of NVRAM\n"); |
| 6723 | ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x010d, |
| 6724 | (uint8_t *)nv, ha->nvram_size); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6725 | |
| 6726 | /* Bad NVRAM data, set defaults parameters. */ |
| 6727 | if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P' |
| 6728 | || nv->id[3] != ' ' || |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6729 | nv->nvram_version < cpu_to_le16(ICB_VERSION)) { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6730 | /* Reset NVRAM data. */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6731 | ql_log(ql_log_warn, vha, 0x006b, |
Raul Porcel | 9e33652 | 2012-05-15 14:34:08 -0400 | [diff] [blame] | 6732 | "Inconsistent NVRAM detected: checksum=0x%x id=%c " |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6733 | "version=0x%x.\n", chksum, nv->id[0], nv->nvram_version); |
| 6734 | ql_log(ql_log_warn, vha, 0x006c, |
| 6735 | "Falling back to functioning (yet invalid -- WWPN) " |
| 6736 | "defaults.\n"); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 6737 | |
| 6738 | /* |
| 6739 | * Set default initialization control block. |
| 6740 | */ |
| 6741 | memset(nv, 0, ha->nvram_size); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6742 | nv->nvram_version = cpu_to_le16(ICB_VERSION); |
| 6743 | nv->version = cpu_to_le16(ICB_VERSION); |
Joe Carnuccio | 98aee70 | 2014-09-25 05:16:38 -0400 | [diff] [blame] | 6744 | nv->frame_payload_size = 2048; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6745 | nv->execution_throttle = cpu_to_le16(0xFFFF); |
| 6746 | nv->exchange_count = cpu_to_le16(0); |
| 6747 | nv->hard_address = cpu_to_le16(124); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 6748 | nv->port_name[0] = 0x21; |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 6749 | nv->port_name[1] = 0x00 + ha->port_no + 1; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 6750 | nv->port_name[2] = 0x00; |
| 6751 | nv->port_name[3] = 0xe0; |
| 6752 | nv->port_name[4] = 0x8b; |
| 6753 | nv->port_name[5] = 0x1c; |
| 6754 | nv->port_name[6] = 0x55; |
| 6755 | nv->port_name[7] = 0x86; |
| 6756 | nv->node_name[0] = 0x20; |
| 6757 | nv->node_name[1] = 0x00; |
| 6758 | nv->node_name[2] = 0x00; |
| 6759 | nv->node_name[3] = 0xe0; |
| 6760 | nv->node_name[4] = 0x8b; |
| 6761 | nv->node_name[5] = 0x1c; |
| 6762 | nv->node_name[6] = 0x55; |
| 6763 | nv->node_name[7] = 0x86; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6764 | qla24xx_nvram_wwn_from_ofw(vha, nv); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6765 | nv->login_retry_count = cpu_to_le16(8); |
| 6766 | nv->interrupt_delay_timer = cpu_to_le16(0); |
| 6767 | nv->login_timeout = cpu_to_le16(0); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 6768 | nv->firmware_options_1 = |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6769 | cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1); |
| 6770 | nv->firmware_options_2 = cpu_to_le32(2 << 4); |
| 6771 | nv->firmware_options_2 |= cpu_to_le32(BIT_12); |
| 6772 | nv->firmware_options_3 = cpu_to_le32(2 << 13); |
| 6773 | nv->host_p = cpu_to_le32(BIT_11|BIT_10); |
| 6774 | nv->efi_parameters = cpu_to_le32(0); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 6775 | nv->reset_delay = 5; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6776 | nv->max_luns_per_target = cpu_to_le16(128); |
| 6777 | nv->port_down_retry_count = cpu_to_le16(30); |
| 6778 | nv->link_down_timeout = cpu_to_le16(30); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 6779 | |
| 6780 | rval = 1; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6781 | } |
| 6782 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6783 | if (qla_tgt_mode_enabled(vha)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6784 | /* Don't enable full login after initial LIP */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6785 | nv->firmware_options_1 &= cpu_to_le32(~BIT_13); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6786 | /* Don't enable LIP full login for initiator */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6787 | nv->host_p &= cpu_to_le32(~BIT_10); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6788 | } |
| 6789 | |
| 6790 | qlt_24xx_config_nvram_stage1(vha, nv); |
| 6791 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6792 | /* Reset Initialization control block */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6793 | memset(icb, 0, ha->init_cb_size); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6794 | |
| 6795 | /* Copy 1st segment. */ |
| 6796 | dptr1 = (uint8_t *)icb; |
| 6797 | dptr2 = (uint8_t *)&nv->version; |
| 6798 | cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version; |
| 6799 | while (cnt--) |
| 6800 | *dptr1++ = *dptr2++; |
| 6801 | |
| 6802 | icb->login_retry_count = nv->login_retry_count; |
Andrew Vasquez | 3ea66e2 | 2006-06-23 16:11:27 -0700 | [diff] [blame] | 6803 | icb->link_down_on_nos = nv->link_down_on_nos; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6804 | |
| 6805 | /* Copy 2nd segment. */ |
| 6806 | dptr1 = (uint8_t *)&icb->interrupt_delay_timer; |
| 6807 | dptr2 = (uint8_t *)&nv->interrupt_delay_timer; |
| 6808 | cnt = (uint8_t *)&icb->reserved_3 - |
| 6809 | (uint8_t *)&icb->interrupt_delay_timer; |
| 6810 | while (cnt--) |
| 6811 | *dptr1++ = *dptr2++; |
| 6812 | |
| 6813 | /* |
| 6814 | * Setup driver NVRAM options. |
| 6815 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6816 | qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name), |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 6817 | "QLA2462"); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6818 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6819 | qlt_24xx_config_nvram_stage2(vha, icb); |
| 6820 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6821 | if (nv->host_p & cpu_to_le32(BIT_15)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6822 | /* Use alternate WWN? */ |
Andrew Vasquez | 5341e86 | 2006-05-17 15:09:16 -0700 | [diff] [blame] | 6823 | memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE); |
| 6824 | memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE); |
| 6825 | } |
| 6826 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6827 | /* Prepare nodename */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6828 | if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6829 | /* |
| 6830 | * Firmware will apply the following mask if the nodename was |
| 6831 | * not provided. |
| 6832 | */ |
| 6833 | memcpy(icb->node_name, icb->port_name, WWN_SIZE); |
| 6834 | icb->node_name[0] &= 0xF0; |
| 6835 | } |
| 6836 | |
| 6837 | /* Set host adapter parameters. */ |
| 6838 | ha->flags.disable_risc_code_load = 0; |
Andrew Vasquez | 0c8c39a | 2006-12-13 19:20:30 -0800 | [diff] [blame] | 6839 | ha->flags.enable_lip_reset = 0; |
| 6840 | ha->flags.enable_lip_full_login = |
| 6841 | le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0; |
| 6842 | ha->flags.enable_target_reset = |
| 6843 | le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6844 | ha->flags.enable_led_scheme = 0; |
Andrew Vasquez | d4c760c | 2006-06-23 16:10:39 -0700 | [diff] [blame] | 6845 | ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6846 | |
Andrew Vasquez | fd0e7e4 | 2006-05-17 15:09:11 -0700 | [diff] [blame] | 6847 | ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) & |
| 6848 | (BIT_6 | BIT_5 | BIT_4)) >> 4; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6849 | |
| 6850 | memcpy(ha->fw_seriallink_options24, nv->seriallink_options, |
| 6851 | sizeof(ha->fw_seriallink_options24)); |
| 6852 | |
| 6853 | /* save HBA serial number */ |
| 6854 | ha->serial0 = icb->port_name[5]; |
| 6855 | ha->serial1 = icb->port_name[6]; |
| 6856 | ha->serial2 = icb->port_name[7]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6857 | memcpy(vha->node_name, icb->node_name, WWN_SIZE); |
| 6858 | memcpy(vha->port_name, icb->port_name, WWN_SIZE); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6859 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6860 | icb->execution_throttle = cpu_to_le16(0xFFFF); |
andrew.vasquez@qlogic.com | bc8fb3c | 2006-01-13 17:05:42 -0800 | [diff] [blame] | 6861 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6862 | ha->retry_count = le16_to_cpu(nv->login_retry_count); |
| 6863 | |
| 6864 | /* Set minimum login_timeout to 4 seconds. */ |
| 6865 | if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout) |
| 6866 | nv->login_timeout = cpu_to_le16(ql2xlogintimeout); |
| 6867 | if (le16_to_cpu(nv->login_timeout) < 4) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6868 | nv->login_timeout = cpu_to_le16(4); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6869 | ha->login_timeout = le16_to_cpu(nv->login_timeout); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6870 | |
Andrew Vasquez | 00a537b | 2008-02-28 14:06:11 -0800 | [diff] [blame] | 6871 | /* Set minimum RATOV to 100 tenths of a second. */ |
| 6872 | ha->r_a_tov = 100; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6873 | |
| 6874 | ha->loop_reset_delay = nv->reset_delay; |
| 6875 | |
| 6876 | /* Link Down Timeout = 0: |
| 6877 | * |
| 6878 | * When Port Down timer expires we will start returning |
| 6879 | * I/O's to OS with "DID_NO_CONNECT". |
| 6880 | * |
| 6881 | * Link Down Timeout != 0: |
| 6882 | * |
| 6883 | * The driver waits for the link to come up after link down |
| 6884 | * before returning I/Os to OS with "DID_NO_CONNECT". |
| 6885 | */ |
| 6886 | if (le16_to_cpu(nv->link_down_timeout) == 0) { |
| 6887 | ha->loop_down_abort_time = |
| 6888 | (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT); |
| 6889 | } else { |
| 6890 | ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout); |
| 6891 | ha->loop_down_abort_time = |
| 6892 | (LOOP_DOWN_TIME - ha->link_down_timeout); |
| 6893 | } |
| 6894 | |
| 6895 | /* Need enough time to try and get the port back. */ |
| 6896 | ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count); |
| 6897 | if (qlport_down_retry) |
| 6898 | ha->port_down_retry_count = qlport_down_retry; |
| 6899 | |
| 6900 | /* Set login_retry_count */ |
| 6901 | ha->login_retry_count = le16_to_cpu(nv->login_retry_count); |
| 6902 | if (ha->port_down_retry_count == |
| 6903 | le16_to_cpu(nv->port_down_retry_count) && |
| 6904 | ha->port_down_retry_count > 3) |
| 6905 | ha->login_retry_count = ha->port_down_retry_count; |
| 6906 | else if (ha->port_down_retry_count > (int)ha->login_retry_count) |
| 6907 | ha->login_retry_count = ha->port_down_retry_count; |
| 6908 | if (ql2xloginretrycount) |
| 6909 | ha->login_retry_count = ql2xloginretrycount; |
| 6910 | |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 6911 | /* Enable ZIO. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6912 | if (!vha->flags.init_done) { |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 6913 | ha->zio_mode = le32_to_cpu(icb->firmware_options_2) & |
| 6914 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
| 6915 | ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ? |
| 6916 | le16_to_cpu(icb->interrupt_delay_timer): 2; |
| 6917 | } |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6918 | icb->firmware_options_2 &= cpu_to_le32( |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 6919 | ~(BIT_3 | BIT_2 | BIT_1 | BIT_0)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6920 | vha->flags.process_response_queue = 0; |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 6921 | if (ha->zio_mode != QLA_ZIO_DISABLED) { |
andrew.vasquez@qlogic.com | 4a59f71 | 2006-03-09 14:27:39 -0800 | [diff] [blame] | 6922 | ha->zio_mode = QLA_ZIO_MODE_6; |
| 6923 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6924 | ql_log(ql_log_info, vha, 0x006f, |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 6925 | "ZIO mode %d enabled; timer delay (%d us).\n", |
| 6926 | ha->zio_mode, ha->zio_timer * 100); |
| 6927 | |
| 6928 | icb->firmware_options_2 |= cpu_to_le32( |
| 6929 | (uint32_t)ha->zio_mode); |
| 6930 | icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6931 | vha->flags.process_response_queue = 1; |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 6932 | } |
| 6933 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 6934 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6935 | ql_log(ql_log_warn, vha, 0x0070, |
| 6936 | "NVRAM configuration failed.\n"); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 6937 | } |
| 6938 | return (rval); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6939 | } |
| 6940 | |
Sawan Chandak | 4243c11 | 2016-01-27 12:03:31 -0500 | [diff] [blame] | 6941 | uint8_t qla27xx_find_valid_image(struct scsi_qla_host *vha) |
| 6942 | { |
| 6943 | struct qla27xx_image_status pri_image_status, sec_image_status; |
| 6944 | uint8_t valid_pri_image, valid_sec_image; |
| 6945 | uint32_t *wptr; |
| 6946 | uint32_t cnt, chksum, size; |
| 6947 | struct qla_hw_data *ha = vha->hw; |
| 6948 | |
| 6949 | valid_pri_image = valid_sec_image = 1; |
| 6950 | ha->active_image = 0; |
| 6951 | size = sizeof(struct qla27xx_image_status) / sizeof(uint32_t); |
| 6952 | |
| 6953 | if (!ha->flt_region_img_status_pri) { |
| 6954 | valid_pri_image = 0; |
| 6955 | goto check_sec_image; |
| 6956 | } |
| 6957 | |
| 6958 | qla24xx_read_flash_data(vha, (uint32_t *)(&pri_image_status), |
| 6959 | ha->flt_region_img_status_pri, size); |
| 6960 | |
| 6961 | if (pri_image_status.signature != QLA27XX_IMG_STATUS_SIGN) { |
| 6962 | ql_dbg(ql_dbg_init, vha, 0x018b, |
| 6963 | "Primary image signature (0x%x) not valid\n", |
| 6964 | pri_image_status.signature); |
| 6965 | valid_pri_image = 0; |
| 6966 | goto check_sec_image; |
| 6967 | } |
| 6968 | |
| 6969 | wptr = (uint32_t *)(&pri_image_status); |
| 6970 | cnt = size; |
| 6971 | |
Joe Carnuccio | da08ef5 | 2016-01-27 12:03:34 -0500 | [diff] [blame] | 6972 | for (chksum = 0; cnt--; wptr++) |
| 6973 | chksum += le32_to_cpu(*wptr); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 6974 | |
Sawan Chandak | 4243c11 | 2016-01-27 12:03:31 -0500 | [diff] [blame] | 6975 | if (chksum) { |
| 6976 | ql_dbg(ql_dbg_init, vha, 0x018c, |
| 6977 | "Checksum validation failed for primary image (0x%x)\n", |
| 6978 | chksum); |
| 6979 | valid_pri_image = 0; |
| 6980 | } |
| 6981 | |
| 6982 | check_sec_image: |
| 6983 | if (!ha->flt_region_img_status_sec) { |
| 6984 | valid_sec_image = 0; |
| 6985 | goto check_valid_image; |
| 6986 | } |
| 6987 | |
| 6988 | qla24xx_read_flash_data(vha, (uint32_t *)(&sec_image_status), |
| 6989 | ha->flt_region_img_status_sec, size); |
| 6990 | |
| 6991 | if (sec_image_status.signature != QLA27XX_IMG_STATUS_SIGN) { |
| 6992 | ql_dbg(ql_dbg_init, vha, 0x018d, |
| 6993 | "Secondary image signature(0x%x) not valid\n", |
| 6994 | sec_image_status.signature); |
| 6995 | valid_sec_image = 0; |
| 6996 | goto check_valid_image; |
| 6997 | } |
| 6998 | |
| 6999 | wptr = (uint32_t *)(&sec_image_status); |
| 7000 | cnt = size; |
Joe Carnuccio | da08ef5 | 2016-01-27 12:03:34 -0500 | [diff] [blame] | 7001 | for (chksum = 0; cnt--; wptr++) |
| 7002 | chksum += le32_to_cpu(*wptr); |
Sawan Chandak | 4243c11 | 2016-01-27 12:03:31 -0500 | [diff] [blame] | 7003 | if (chksum) { |
| 7004 | ql_dbg(ql_dbg_init, vha, 0x018e, |
| 7005 | "Checksum validation failed for secondary image (0x%x)\n", |
| 7006 | chksum); |
| 7007 | valid_sec_image = 0; |
| 7008 | } |
| 7009 | |
| 7010 | check_valid_image: |
| 7011 | if (valid_pri_image && (pri_image_status.image_status_mask & 0x1)) |
| 7012 | ha->active_image = QLA27XX_PRIMARY_IMAGE; |
| 7013 | if (valid_sec_image && (sec_image_status.image_status_mask & 0x1)) { |
| 7014 | if (!ha->active_image || |
| 7015 | pri_image_status.generation_number < |
| 7016 | sec_image_status.generation_number) |
| 7017 | ha->active_image = QLA27XX_SECONDARY_IMAGE; |
| 7018 | } |
| 7019 | |
| 7020 | ql_dbg(ql_dbg_init, vha, 0x018f, "%s image\n", |
| 7021 | ha->active_image == 0 ? "default bootld and fw" : |
| 7022 | ha->active_image == 1 ? "primary" : |
| 7023 | ha->active_image == 2 ? "secondary" : |
| 7024 | "Invalid"); |
| 7025 | |
| 7026 | return ha->active_image; |
| 7027 | } |
| 7028 | |
Adrian Bunk | 413975a | 2006-06-30 02:33:06 -0700 | [diff] [blame] | 7029 | static int |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 7030 | qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr, |
| 7031 | uint32_t faddr) |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 7032 | { |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 7033 | int rval = QLA_SUCCESS; |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 7034 | int segments, fragment; |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 7035 | uint32_t *dcode, dlen; |
| 7036 | uint32_t risc_addr; |
| 7037 | uint32_t risc_size; |
| 7038 | uint32_t i; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7039 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 7040 | struct req_que *req = ha->req_q_map[0]; |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 7041 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7042 | ql_dbg(ql_dbg_init, vha, 0x008b, |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 7043 | "FW: Loading firmware from flash (%x).\n", faddr); |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 7044 | |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 7045 | rval = QLA_SUCCESS; |
| 7046 | |
| 7047 | segments = FA_RISC_CODE_SEGMENTS; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 7048 | dcode = (uint32_t *)req->ring; |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 7049 | *srisc_addr = 0; |
| 7050 | |
Sawan Chandak | 4243c11 | 2016-01-27 12:03:31 -0500 | [diff] [blame] | 7051 | if (IS_QLA27XX(ha) && |
| 7052 | qla27xx_find_valid_image(vha) == QLA27XX_SECONDARY_IMAGE) |
| 7053 | faddr = ha->flt_region_fw_sec; |
| 7054 | |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 7055 | /* Validate firmware image by checking version. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7056 | qla24xx_read_flash_data(vha, dcode, faddr + 4, 4); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 7057 | for (i = 0; i < 4; i++) |
| 7058 | dcode[i] = be32_to_cpu(dcode[i]); |
| 7059 | if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff && |
| 7060 | dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) || |
| 7061 | (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 && |
| 7062 | dcode[3] == 0)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7063 | ql_log(ql_log_fatal, vha, 0x008c, |
| 7064 | "Unable to verify the integrity of flash firmware " |
| 7065 | "image.\n"); |
| 7066 | ql_log(ql_log_fatal, vha, 0x008d, |
| 7067 | "Firmware data: %08x %08x %08x %08x.\n", |
| 7068 | dcode[0], dcode[1], dcode[2], dcode[3]); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 7069 | |
| 7070 | return QLA_FUNCTION_FAILED; |
| 7071 | } |
| 7072 | |
| 7073 | while (segments && rval == QLA_SUCCESS) { |
| 7074 | /* Read segment's load information. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7075 | qla24xx_read_flash_data(vha, dcode, faddr, 4); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 7076 | |
| 7077 | risc_addr = be32_to_cpu(dcode[2]); |
| 7078 | *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr; |
| 7079 | risc_size = be32_to_cpu(dcode[3]); |
| 7080 | |
| 7081 | fragment = 0; |
| 7082 | while (risc_size > 0 && rval == QLA_SUCCESS) { |
| 7083 | dlen = (uint32_t)(ha->fw_transfer_size >> 2); |
| 7084 | if (dlen > risc_size) |
| 7085 | dlen = risc_size; |
| 7086 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7087 | ql_dbg(ql_dbg_init, vha, 0x008e, |
| 7088 | "Loading risc segment@ risc addr %x " |
| 7089 | "number of dwords 0x%x offset 0x%x.\n", |
| 7090 | risc_addr, dlen, faddr); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 7091 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7092 | qla24xx_read_flash_data(vha, dcode, faddr, dlen); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 7093 | for (i = 0; i < dlen; i++) |
| 7094 | dcode[i] = swab32(dcode[i]); |
| 7095 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 7096 | rval = qla2x00_load_ram(vha, req->dma, risc_addr, |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 7097 | dlen); |
| 7098 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7099 | ql_log(ql_log_fatal, vha, 0x008f, |
| 7100 | "Failed to load segment %d of firmware.\n", |
| 7101 | fragment); |
Chad Dupuis | f261f7a | 2014-09-25 05:17:03 -0400 | [diff] [blame] | 7102 | return QLA_FUNCTION_FAILED; |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 7103 | } |
| 7104 | |
| 7105 | faddr += dlen; |
| 7106 | risc_addr += dlen; |
| 7107 | risc_size -= dlen; |
| 7108 | fragment++; |
| 7109 | } |
| 7110 | |
| 7111 | /* Next segment. */ |
| 7112 | segments--; |
| 7113 | } |
| 7114 | |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 7115 | if (!IS_QLA27XX(ha)) |
| 7116 | return rval; |
| 7117 | |
| 7118 | if (ha->fw_dump_template) |
| 7119 | vfree(ha->fw_dump_template); |
| 7120 | ha->fw_dump_template = NULL; |
| 7121 | ha->fw_dump_template_len = 0; |
| 7122 | |
| 7123 | ql_dbg(ql_dbg_init, vha, 0x0161, |
| 7124 | "Loading fwdump template from %x\n", faddr); |
| 7125 | qla24xx_read_flash_data(vha, dcode, faddr, 7); |
| 7126 | risc_size = be32_to_cpu(dcode[2]); |
| 7127 | ql_dbg(ql_dbg_init, vha, 0x0162, |
| 7128 | "-> array size %x dwords\n", risc_size); |
| 7129 | if (risc_size == 0 || risc_size == ~0) |
| 7130 | goto default_template; |
| 7131 | |
| 7132 | dlen = (risc_size - 8) * sizeof(*dcode); |
| 7133 | ql_dbg(ql_dbg_init, vha, 0x0163, |
| 7134 | "-> template allocating %x bytes...\n", dlen); |
| 7135 | ha->fw_dump_template = vmalloc(dlen); |
| 7136 | if (!ha->fw_dump_template) { |
| 7137 | ql_log(ql_log_warn, vha, 0x0164, |
| 7138 | "Failed fwdump template allocate %x bytes.\n", risc_size); |
| 7139 | goto default_template; |
| 7140 | } |
| 7141 | |
| 7142 | faddr += 7; |
| 7143 | risc_size -= 8; |
| 7144 | dcode = ha->fw_dump_template; |
| 7145 | qla24xx_read_flash_data(vha, dcode, faddr, risc_size); |
| 7146 | for (i = 0; i < risc_size; i++) |
| 7147 | dcode[i] = le32_to_cpu(dcode[i]); |
| 7148 | |
| 7149 | if (!qla27xx_fwdt_template_valid(dcode)) { |
| 7150 | ql_log(ql_log_warn, vha, 0x0165, |
| 7151 | "Failed fwdump template validate\n"); |
| 7152 | goto default_template; |
| 7153 | } |
| 7154 | |
| 7155 | dlen = qla27xx_fwdt_template_size(dcode); |
| 7156 | ql_dbg(ql_dbg_init, vha, 0x0166, |
| 7157 | "-> template size %x bytes\n", dlen); |
| 7158 | if (dlen > risc_size * sizeof(*dcode)) { |
| 7159 | ql_log(ql_log_warn, vha, 0x0167, |
Himanshu Madhani | 4fae52b | 2017-06-06 13:55:23 -0700 | [diff] [blame] | 7160 | "Failed fwdump template exceeds array by %zx bytes\n", |
Joe Carnuccio | 383a298 | 2017-06-02 09:11:55 -0700 | [diff] [blame] | 7161 | (size_t)(dlen - risc_size * sizeof(*dcode))); |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 7162 | goto default_template; |
| 7163 | } |
| 7164 | ha->fw_dump_template_len = dlen; |
| 7165 | return rval; |
| 7166 | |
| 7167 | default_template: |
| 7168 | ql_log(ql_log_warn, vha, 0x0168, "Using default fwdump template\n"); |
| 7169 | if (ha->fw_dump_template) |
| 7170 | vfree(ha->fw_dump_template); |
| 7171 | ha->fw_dump_template = NULL; |
| 7172 | ha->fw_dump_template_len = 0; |
| 7173 | |
| 7174 | dlen = qla27xx_fwdt_template_default_size(); |
| 7175 | ql_dbg(ql_dbg_init, vha, 0x0169, |
| 7176 | "-> template allocating %x bytes...\n", dlen); |
| 7177 | ha->fw_dump_template = vmalloc(dlen); |
| 7178 | if (!ha->fw_dump_template) { |
| 7179 | ql_log(ql_log_warn, vha, 0x016a, |
| 7180 | "Failed fwdump template allocate %x bytes.\n", risc_size); |
| 7181 | goto failed_template; |
| 7182 | } |
| 7183 | |
| 7184 | dcode = ha->fw_dump_template; |
| 7185 | risc_size = dlen / sizeof(*dcode); |
| 7186 | memcpy(dcode, qla27xx_fwdt_template_default(), dlen); |
| 7187 | for (i = 0; i < risc_size; i++) |
| 7188 | dcode[i] = be32_to_cpu(dcode[i]); |
| 7189 | |
| 7190 | if (!qla27xx_fwdt_template_valid(ha->fw_dump_template)) { |
| 7191 | ql_log(ql_log_warn, vha, 0x016b, |
| 7192 | "Failed fwdump template validate\n"); |
| 7193 | goto failed_template; |
| 7194 | } |
| 7195 | |
| 7196 | dlen = qla27xx_fwdt_template_size(ha->fw_dump_template); |
| 7197 | ql_dbg(ql_dbg_init, vha, 0x016c, |
| 7198 | "-> template size %x bytes\n", dlen); |
| 7199 | ha->fw_dump_template_len = dlen; |
| 7200 | return rval; |
| 7201 | |
| 7202 | failed_template: |
| 7203 | ql_log(ql_log_warn, vha, 0x016d, "Failed default fwdump template\n"); |
| 7204 | if (ha->fw_dump_template) |
| 7205 | vfree(ha->fw_dump_template); |
| 7206 | ha->fw_dump_template = NULL; |
| 7207 | ha->fw_dump_template_len = 0; |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 7208 | return rval; |
| 7209 | } |
| 7210 | |
Giridhar Malavali | e9454a8 | 2013-02-08 01:57:47 -0500 | [diff] [blame] | 7211 | #define QLA_FW_URL "http://ldriver.qlogic.com/firmware/" |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 7212 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 7213 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7214 | qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr) |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 7215 | { |
| 7216 | int rval; |
| 7217 | int i, fragment; |
| 7218 | uint16_t *wcode, *fwcode; |
| 7219 | uint32_t risc_addr, risc_size, fwclen, wlen, *seg; |
| 7220 | struct fw_blob *blob; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7221 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 7222 | struct req_que *req = ha->req_q_map[0]; |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 7223 | |
| 7224 | /* Load firmware blob. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7225 | blob = qla2x00_request_firmware(vha); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 7226 | if (!blob) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7227 | ql_log(ql_log_info, vha, 0x0083, |
Yannick Guerrini | 94bcf83 | 2015-02-26 22:49:34 +0100 | [diff] [blame] | 7228 | "Firmware image unavailable.\n"); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7229 | ql_log(ql_log_info, vha, 0x0084, |
| 7230 | "Firmware images can be retrieved from: "QLA_FW_URL ".\n"); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 7231 | return QLA_FUNCTION_FAILED; |
| 7232 | } |
| 7233 | |
| 7234 | rval = QLA_SUCCESS; |
| 7235 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 7236 | wcode = (uint16_t *)req->ring; |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 7237 | *srisc_addr = 0; |
| 7238 | fwcode = (uint16_t *)blob->fw->data; |
| 7239 | fwclen = 0; |
| 7240 | |
| 7241 | /* Validate firmware image by checking version. */ |
| 7242 | if (blob->fw->size < 8 * sizeof(uint16_t)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7243 | ql_log(ql_log_fatal, vha, 0x0085, |
Alexey Dobriyan | 5b5e092 | 2017-02-27 14:30:02 -0800 | [diff] [blame] | 7244 | "Unable to verify integrity of firmware image (%zd).\n", |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 7245 | blob->fw->size); |
| 7246 | goto fail_fw_integrity; |
| 7247 | } |
| 7248 | for (i = 0; i < 4; i++) |
| 7249 | wcode[i] = be16_to_cpu(fwcode[i + 4]); |
| 7250 | if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff && |
| 7251 | wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 && |
| 7252 | wcode[2] == 0 && wcode[3] == 0)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7253 | ql_log(ql_log_fatal, vha, 0x0086, |
| 7254 | "Unable to verify integrity of firmware image.\n"); |
| 7255 | ql_log(ql_log_fatal, vha, 0x0087, |
| 7256 | "Firmware data: %04x %04x %04x %04x.\n", |
| 7257 | wcode[0], wcode[1], wcode[2], wcode[3]); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 7258 | goto fail_fw_integrity; |
| 7259 | } |
| 7260 | |
| 7261 | seg = blob->segs; |
| 7262 | while (*seg && rval == QLA_SUCCESS) { |
| 7263 | risc_addr = *seg; |
| 7264 | *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr; |
| 7265 | risc_size = be16_to_cpu(fwcode[3]); |
| 7266 | |
| 7267 | /* Validate firmware image size. */ |
| 7268 | fwclen += risc_size * sizeof(uint16_t); |
| 7269 | if (blob->fw->size < fwclen) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7270 | ql_log(ql_log_fatal, vha, 0x0088, |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 7271 | "Unable to verify integrity of firmware image " |
Alexey Dobriyan | 5b5e092 | 2017-02-27 14:30:02 -0800 | [diff] [blame] | 7272 | "(%zd).\n", blob->fw->size); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 7273 | goto fail_fw_integrity; |
| 7274 | } |
| 7275 | |
| 7276 | fragment = 0; |
| 7277 | while (risc_size > 0 && rval == QLA_SUCCESS) { |
| 7278 | wlen = (uint16_t)(ha->fw_transfer_size >> 1); |
| 7279 | if (wlen > risc_size) |
| 7280 | wlen = risc_size; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7281 | ql_dbg(ql_dbg_init, vha, 0x0089, |
| 7282 | "Loading risc segment@ risc addr %x number of " |
| 7283 | "words 0x%x.\n", risc_addr, wlen); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 7284 | |
| 7285 | for (i = 0; i < wlen; i++) |
| 7286 | wcode[i] = swab16(fwcode[i]); |
| 7287 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 7288 | rval = qla2x00_load_ram(vha, req->dma, risc_addr, |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 7289 | wlen); |
| 7290 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7291 | ql_log(ql_log_fatal, vha, 0x008a, |
| 7292 | "Failed to load segment %d of firmware.\n", |
| 7293 | fragment); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 7294 | break; |
| 7295 | } |
| 7296 | |
| 7297 | fwcode += wlen; |
| 7298 | risc_addr += wlen; |
| 7299 | risc_size -= wlen; |
| 7300 | fragment++; |
| 7301 | } |
| 7302 | |
| 7303 | /* Next segment. */ |
| 7304 | seg++; |
| 7305 | } |
| 7306 | return rval; |
| 7307 | |
| 7308 | fail_fw_integrity: |
| 7309 | return QLA_FUNCTION_FAILED; |
| 7310 | } |
| 7311 | |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 7312 | static int |
| 7313 | qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 7314 | { |
| 7315 | int rval; |
| 7316 | int segments, fragment; |
| 7317 | uint32_t *dcode, dlen; |
| 7318 | uint32_t risc_addr; |
| 7319 | uint32_t risc_size; |
| 7320 | uint32_t i; |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 7321 | struct fw_blob *blob; |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 7322 | const uint32_t *fwcode; |
| 7323 | uint32_t fwclen; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7324 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 7325 | struct req_que *req = ha->req_q_map[0]; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 7326 | |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 7327 | /* Load firmware blob. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7328 | blob = qla2x00_request_firmware(vha); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 7329 | if (!blob) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7330 | ql_log(ql_log_warn, vha, 0x0090, |
Yannick Guerrini | 94bcf83 | 2015-02-26 22:49:34 +0100 | [diff] [blame] | 7331 | "Firmware image unavailable.\n"); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7332 | ql_log(ql_log_warn, vha, 0x0091, |
| 7333 | "Firmware images can be retrieved from: " |
| 7334 | QLA_FW_URL ".\n"); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 7335 | |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 7336 | return QLA_FUNCTION_FAILED; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 7337 | } |
| 7338 | |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 7339 | ql_dbg(ql_dbg_init, vha, 0x0092, |
| 7340 | "FW: Loading via request-firmware.\n"); |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 7341 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 7342 | rval = QLA_SUCCESS; |
| 7343 | |
| 7344 | segments = FA_RISC_CODE_SEGMENTS; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 7345 | dcode = (uint32_t *)req->ring; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 7346 | *srisc_addr = 0; |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 7347 | fwcode = (uint32_t *)blob->fw->data; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 7348 | fwclen = 0; |
| 7349 | |
| 7350 | /* Validate firmware image by checking version. */ |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 7351 | if (blob->fw->size < 8 * sizeof(uint32_t)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7352 | ql_log(ql_log_fatal, vha, 0x0093, |
Alexey Dobriyan | 5b5e092 | 2017-02-27 14:30:02 -0800 | [diff] [blame] | 7353 | "Unable to verify integrity of firmware image (%zd).\n", |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 7354 | blob->fw->size); |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 7355 | return QLA_FUNCTION_FAILED; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 7356 | } |
| 7357 | for (i = 0; i < 4; i++) |
| 7358 | dcode[i] = be32_to_cpu(fwcode[i + 4]); |
| 7359 | if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff && |
| 7360 | dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) || |
| 7361 | (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 && |
| 7362 | dcode[3] == 0)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7363 | ql_log(ql_log_fatal, vha, 0x0094, |
Alexey Dobriyan | 5b5e092 | 2017-02-27 14:30:02 -0800 | [diff] [blame] | 7364 | "Unable to verify integrity of firmware image (%zd).\n", |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7365 | blob->fw->size); |
| 7366 | ql_log(ql_log_fatal, vha, 0x0095, |
| 7367 | "Firmware data: %08x %08x %08x %08x.\n", |
| 7368 | dcode[0], dcode[1], dcode[2], dcode[3]); |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 7369 | return QLA_FUNCTION_FAILED; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 7370 | } |
| 7371 | |
| 7372 | while (segments && rval == QLA_SUCCESS) { |
| 7373 | risc_addr = be32_to_cpu(fwcode[2]); |
| 7374 | *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr; |
| 7375 | risc_size = be32_to_cpu(fwcode[3]); |
| 7376 | |
| 7377 | /* Validate firmware image size. */ |
| 7378 | fwclen += risc_size * sizeof(uint32_t); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 7379 | if (blob->fw->size < fwclen) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7380 | ql_log(ql_log_fatal, vha, 0x0096, |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 7381 | "Unable to verify integrity of firmware image " |
Alexey Dobriyan | 5b5e092 | 2017-02-27 14:30:02 -0800 | [diff] [blame] | 7382 | "(%zd).\n", blob->fw->size); |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 7383 | return QLA_FUNCTION_FAILED; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 7384 | } |
| 7385 | |
| 7386 | fragment = 0; |
| 7387 | while (risc_size > 0 && rval == QLA_SUCCESS) { |
| 7388 | dlen = (uint32_t)(ha->fw_transfer_size >> 2); |
| 7389 | if (dlen > risc_size) |
| 7390 | dlen = risc_size; |
| 7391 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7392 | ql_dbg(ql_dbg_init, vha, 0x0097, |
| 7393 | "Loading risc segment@ risc addr %x " |
| 7394 | "number of dwords 0x%x.\n", risc_addr, dlen); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 7395 | |
| 7396 | for (i = 0; i < dlen; i++) |
| 7397 | dcode[i] = swab32(fwcode[i]); |
| 7398 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 7399 | rval = qla2x00_load_ram(vha, req->dma, risc_addr, |
andrew.vasquez@qlogic.com | 590f98e | 2006-01-13 17:05:37 -0800 | [diff] [blame] | 7400 | dlen); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 7401 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7402 | ql_log(ql_log_fatal, vha, 0x0098, |
| 7403 | "Failed to load segment %d of firmware.\n", |
| 7404 | fragment); |
Chad Dupuis | f261f7a | 2014-09-25 05:17:03 -0400 | [diff] [blame] | 7405 | return QLA_FUNCTION_FAILED; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 7406 | } |
| 7407 | |
| 7408 | fwcode += dlen; |
| 7409 | risc_addr += dlen; |
| 7410 | risc_size -= dlen; |
| 7411 | fragment++; |
| 7412 | } |
| 7413 | |
| 7414 | /* Next segment. */ |
| 7415 | segments--; |
| 7416 | } |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 7417 | |
| 7418 | if (!IS_QLA27XX(ha)) |
| 7419 | return rval; |
| 7420 | |
| 7421 | if (ha->fw_dump_template) |
| 7422 | vfree(ha->fw_dump_template); |
| 7423 | ha->fw_dump_template = NULL; |
| 7424 | ha->fw_dump_template_len = 0; |
| 7425 | |
| 7426 | ql_dbg(ql_dbg_init, vha, 0x171, |
Chad Dupuis | 97ea702 | 2014-03-13 14:16:40 -0400 | [diff] [blame] | 7427 | "Loading fwdump template from %x\n", |
| 7428 | (uint32_t)((void *)fwcode - (void *)blob->fw->data)); |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 7429 | risc_size = be32_to_cpu(fwcode[2]); |
| 7430 | ql_dbg(ql_dbg_init, vha, 0x172, |
| 7431 | "-> array size %x dwords\n", risc_size); |
| 7432 | if (risc_size == 0 || risc_size == ~0) |
| 7433 | goto default_template; |
| 7434 | |
| 7435 | dlen = (risc_size - 8) * sizeof(*fwcode); |
| 7436 | ql_dbg(ql_dbg_init, vha, 0x0173, |
| 7437 | "-> template allocating %x bytes...\n", dlen); |
| 7438 | ha->fw_dump_template = vmalloc(dlen); |
| 7439 | if (!ha->fw_dump_template) { |
| 7440 | ql_log(ql_log_warn, vha, 0x0174, |
| 7441 | "Failed fwdump template allocate %x bytes.\n", risc_size); |
| 7442 | goto default_template; |
| 7443 | } |
| 7444 | |
| 7445 | fwcode += 7; |
| 7446 | risc_size -= 8; |
| 7447 | dcode = ha->fw_dump_template; |
| 7448 | for (i = 0; i < risc_size; i++) |
| 7449 | dcode[i] = le32_to_cpu(fwcode[i]); |
| 7450 | |
| 7451 | if (!qla27xx_fwdt_template_valid(dcode)) { |
| 7452 | ql_log(ql_log_warn, vha, 0x0175, |
| 7453 | "Failed fwdump template validate\n"); |
| 7454 | goto default_template; |
| 7455 | } |
| 7456 | |
| 7457 | dlen = qla27xx_fwdt_template_size(dcode); |
| 7458 | ql_dbg(ql_dbg_init, vha, 0x0176, |
| 7459 | "-> template size %x bytes\n", dlen); |
| 7460 | if (dlen > risc_size * sizeof(*fwcode)) { |
| 7461 | ql_log(ql_log_warn, vha, 0x0177, |
Himanshu Madhani | 4fae52b | 2017-06-06 13:55:23 -0700 | [diff] [blame] | 7462 | "Failed fwdump template exceeds array by %zx bytes\n", |
Joe Carnuccio | 383a298 | 2017-06-02 09:11:55 -0700 | [diff] [blame] | 7463 | (size_t)(dlen - risc_size * sizeof(*fwcode))); |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 7464 | goto default_template; |
| 7465 | } |
| 7466 | ha->fw_dump_template_len = dlen; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 7467 | return rval; |
| 7468 | |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 7469 | default_template: |
| 7470 | ql_log(ql_log_warn, vha, 0x0178, "Using default fwdump template\n"); |
| 7471 | if (ha->fw_dump_template) |
| 7472 | vfree(ha->fw_dump_template); |
| 7473 | ha->fw_dump_template = NULL; |
| 7474 | ha->fw_dump_template_len = 0; |
| 7475 | |
| 7476 | dlen = qla27xx_fwdt_template_default_size(); |
| 7477 | ql_dbg(ql_dbg_init, vha, 0x0179, |
| 7478 | "-> template allocating %x bytes...\n", dlen); |
| 7479 | ha->fw_dump_template = vmalloc(dlen); |
| 7480 | if (!ha->fw_dump_template) { |
| 7481 | ql_log(ql_log_warn, vha, 0x017a, |
| 7482 | "Failed fwdump template allocate %x bytes.\n", risc_size); |
| 7483 | goto failed_template; |
| 7484 | } |
| 7485 | |
| 7486 | dcode = ha->fw_dump_template; |
| 7487 | risc_size = dlen / sizeof(*fwcode); |
| 7488 | fwcode = qla27xx_fwdt_template_default(); |
| 7489 | for (i = 0; i < risc_size; i++) |
| 7490 | dcode[i] = be32_to_cpu(fwcode[i]); |
| 7491 | |
| 7492 | if (!qla27xx_fwdt_template_valid(ha->fw_dump_template)) { |
| 7493 | ql_log(ql_log_warn, vha, 0x017b, |
| 7494 | "Failed fwdump template validate\n"); |
| 7495 | goto failed_template; |
| 7496 | } |
| 7497 | |
| 7498 | dlen = qla27xx_fwdt_template_size(ha->fw_dump_template); |
| 7499 | ql_dbg(ql_dbg_init, vha, 0x017c, |
| 7500 | "-> template size %x bytes\n", dlen); |
| 7501 | ha->fw_dump_template_len = dlen; |
| 7502 | return rval; |
| 7503 | |
| 7504 | failed_template: |
| 7505 | ql_log(ql_log_warn, vha, 0x017d, "Failed default fwdump template\n"); |
| 7506 | if (ha->fw_dump_template) |
| 7507 | vfree(ha->fw_dump_template); |
| 7508 | ha->fw_dump_template = NULL; |
| 7509 | ha->fw_dump_template_len = 0; |
| 7510 | return rval; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 7511 | } |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 7512 | |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 7513 | int |
| 7514 | qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr) |
| 7515 | { |
| 7516 | int rval; |
| 7517 | |
Andrew Vasquez | e337d90 | 2009-04-06 22:33:49 -0700 | [diff] [blame] | 7518 | if (ql2xfwloadbin == 1) |
| 7519 | return qla81xx_load_risc(vha, srisc_addr); |
| 7520 | |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 7521 | /* |
| 7522 | * FW Load priority: |
| 7523 | * 1) Firmware via request-firmware interface (.bin file). |
| 7524 | * 2) Firmware residing in flash. |
| 7525 | */ |
| 7526 | rval = qla24xx_load_risc_blob(vha, srisc_addr); |
| 7527 | if (rval == QLA_SUCCESS) |
| 7528 | return rval; |
| 7529 | |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 7530 | return qla24xx_load_risc_flash(vha, srisc_addr, |
| 7531 | vha->hw->flt_region_fw); |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 7532 | } |
| 7533 | |
| 7534 | int |
| 7535 | qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr) |
| 7536 | { |
| 7537 | int rval; |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 7538 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 7539 | |
Andrew Vasquez | e337d90 | 2009-04-06 22:33:49 -0700 | [diff] [blame] | 7540 | if (ql2xfwloadbin == 2) |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 7541 | goto try_blob_fw; |
Andrew Vasquez | e337d90 | 2009-04-06 22:33:49 -0700 | [diff] [blame] | 7542 | |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 7543 | /* |
| 7544 | * FW Load priority: |
| 7545 | * 1) Firmware residing in flash. |
| 7546 | * 2) Firmware via request-firmware interface (.bin file). |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 7547 | * 3) Golden-Firmware residing in flash -- limited operation. |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 7548 | */ |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 7549 | rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw); |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 7550 | if (rval == QLA_SUCCESS) |
| 7551 | return rval; |
| 7552 | |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 7553 | try_blob_fw: |
| 7554 | rval = qla24xx_load_risc_blob(vha, srisc_addr); |
| 7555 | if (rval == QLA_SUCCESS || !ha->flt_region_gold_fw) |
| 7556 | return rval; |
| 7557 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7558 | ql_log(ql_log_info, vha, 0x0099, |
| 7559 | "Attempting to fallback to golden firmware.\n"); |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 7560 | rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw); |
| 7561 | if (rval != QLA_SUCCESS) |
| 7562 | return rval; |
| 7563 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7564 | ql_log(ql_log_info, vha, 0x009a, "Update operational firmware.\n"); |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 7565 | ha->flags.running_gold_fw = 1; |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 7566 | return rval; |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 7567 | } |
| 7568 | |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 7569 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7570 | qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha) |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 7571 | { |
| 7572 | int ret, retries; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7573 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 7574 | |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 7575 | if (ha->flags.pci_channel_io_perm_failure) |
| 7576 | return; |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 7577 | if (!IS_FWI2_CAPABLE(ha)) |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 7578 | return; |
Andrew Vasquez | 75edf81 | 2007-05-07 07:43:00 -0700 | [diff] [blame] | 7579 | if (!ha->fw_major_version) |
| 7580 | return; |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 7581 | if (!ha->flags.fw_started) |
| 7582 | return; |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 7583 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7584 | ret = qla2x00_stop_firmware(vha); |
Andrew Vasquez | 7c7f1f2 | 2008-02-28 14:06:09 -0800 | [diff] [blame] | 7585 | for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT && |
Andrew Vasquez | b469a7c | 2009-04-06 22:33:48 -0700 | [diff] [blame] | 7586 | ret != QLA_INVALID_COMMAND && retries ; retries--) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7587 | ha->isp_ops->reset_chip(vha); |
| 7588 | if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS) |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 7589 | continue; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7590 | if (qla2x00_setup_chip(vha) != QLA_SUCCESS) |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 7591 | continue; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7592 | ql_log(ql_log_info, vha, 0x8015, |
| 7593 | "Attempting retry of stop-firmware command.\n"); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7594 | ret = qla2x00_stop_firmware(vha); |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 7595 | } |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 7596 | |
Quinn Tran | 4b60c82 | 2017-06-13 20:47:21 -0700 | [diff] [blame] | 7597 | QLA_FW_STOPPED(ha); |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 7598 | ha->flags.fw_init_done = 0; |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 7599 | } |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 7600 | |
| 7601 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7602 | qla24xx_configure_vhba(scsi_qla_host_t *vha) |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 7603 | { |
| 7604 | int rval = QLA_SUCCESS; |
Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 7605 | int rval2; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 7606 | uint16_t mb[MAILBOX_REGISTER_COUNT]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7607 | struct qla_hw_data *ha = vha->hw; |
| 7608 | struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev); |
Anirban Chakraborty | 67c2e93 | 2009-04-06 22:33:42 -0700 | [diff] [blame] | 7609 | struct req_que *req; |
| 7610 | struct rsp_que *rsp; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 7611 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7612 | if (!vha->vp_idx) |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 7613 | return -EINVAL; |
| 7614 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7615 | rval = qla2x00_fw_ready(base_vha); |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 7616 | if (vha->qpair) |
| 7617 | req = vha->qpair->req; |
Anirban Chakraborty | 67c2e93 | 2009-04-06 22:33:42 -0700 | [diff] [blame] | 7618 | else |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 7619 | req = ha->req_q_map[0]; |
Anirban Chakraborty | 67c2e93 | 2009-04-06 22:33:42 -0700 | [diff] [blame] | 7620 | rsp = req->rsp; |
| 7621 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 7622 | if (rval == QLA_SUCCESS) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7623 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 7624 | qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 7625 | } |
| 7626 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7627 | vha->flags.management_server_logged_in = 0; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 7628 | |
| 7629 | /* Login to SNS first */ |
Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 7630 | rval2 = ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb, |
| 7631 | BIT_1); |
| 7632 | if (rval2 != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) { |
| 7633 | if (rval2 == QLA_MEMORY_ALLOC_FAILED) |
| 7634 | ql_dbg(ql_dbg_init, vha, 0x0120, |
| 7635 | "Failed SNS login: loop_id=%x, rval2=%d\n", |
| 7636 | NPH_SNS, rval2); |
| 7637 | else |
| 7638 | ql_dbg(ql_dbg_init, vha, 0x0103, |
| 7639 | "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x " |
| 7640 | "mb[2]=%x mb[6]=%x mb[7]=%x.\n", |
| 7641 | NPH_SNS, mb[0], mb[1], mb[2], mb[6], mb[7]); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 7642 | return (QLA_FUNCTION_FAILED); |
| 7643 | } |
| 7644 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7645 | atomic_set(&vha->loop_down_timer, 0); |
| 7646 | atomic_set(&vha->loop_state, LOOP_UP); |
| 7647 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
| 7648 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
| 7649 | rval = qla2x00_loop_resync(base_vha); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 7650 | |
| 7651 | return rval; |
| 7652 | } |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 7653 | |
| 7654 | /* 84XX Support **************************************************************/ |
| 7655 | |
| 7656 | static LIST_HEAD(qla_cs84xx_list); |
| 7657 | static DEFINE_MUTEX(qla_cs84xx_mutex); |
| 7658 | |
| 7659 | static struct qla_chip_state_84xx * |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7660 | qla84xx_get_chip(struct scsi_qla_host *vha) |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 7661 | { |
| 7662 | struct qla_chip_state_84xx *cs84xx; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7663 | struct qla_hw_data *ha = vha->hw; |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 7664 | |
| 7665 | mutex_lock(&qla_cs84xx_mutex); |
| 7666 | |
| 7667 | /* Find any shared 84xx chip. */ |
| 7668 | list_for_each_entry(cs84xx, &qla_cs84xx_list, list) { |
| 7669 | if (cs84xx->bus == ha->pdev->bus) { |
| 7670 | kref_get(&cs84xx->kref); |
| 7671 | goto done; |
| 7672 | } |
| 7673 | } |
| 7674 | |
| 7675 | cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL); |
| 7676 | if (!cs84xx) |
| 7677 | goto done; |
| 7678 | |
| 7679 | kref_init(&cs84xx->kref); |
| 7680 | spin_lock_init(&cs84xx->access_lock); |
| 7681 | mutex_init(&cs84xx->fw_update_mutex); |
| 7682 | cs84xx->bus = ha->pdev->bus; |
| 7683 | |
| 7684 | list_add_tail(&cs84xx->list, &qla_cs84xx_list); |
| 7685 | done: |
| 7686 | mutex_unlock(&qla_cs84xx_mutex); |
| 7687 | return cs84xx; |
| 7688 | } |
| 7689 | |
| 7690 | static void |
| 7691 | __qla84xx_chip_release(struct kref *kref) |
| 7692 | { |
| 7693 | struct qla_chip_state_84xx *cs84xx = |
| 7694 | container_of(kref, struct qla_chip_state_84xx, kref); |
| 7695 | |
| 7696 | mutex_lock(&qla_cs84xx_mutex); |
| 7697 | list_del(&cs84xx->list); |
| 7698 | mutex_unlock(&qla_cs84xx_mutex); |
| 7699 | kfree(cs84xx); |
| 7700 | } |
| 7701 | |
| 7702 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7703 | qla84xx_put_chip(struct scsi_qla_host *vha) |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 7704 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7705 | struct qla_hw_data *ha = vha->hw; |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 7706 | if (ha->cs84xx) |
| 7707 | kref_put(&ha->cs84xx->kref, __qla84xx_chip_release); |
| 7708 | } |
| 7709 | |
| 7710 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7711 | qla84xx_init_chip(scsi_qla_host_t *vha) |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 7712 | { |
| 7713 | int rval; |
| 7714 | uint16_t status[2]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7715 | struct qla_hw_data *ha = vha->hw; |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 7716 | |
| 7717 | mutex_lock(&ha->cs84xx->fw_update_mutex); |
| 7718 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7719 | rval = qla84xx_verify_chip(vha, status); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 7720 | |
| 7721 | mutex_unlock(&ha->cs84xx->fw_update_mutex); |
| 7722 | |
| 7723 | return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED: |
| 7724 | QLA_SUCCESS; |
| 7725 | } |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7726 | |
| 7727 | /* 81XX Support **************************************************************/ |
| 7728 | |
| 7729 | int |
| 7730 | qla81xx_nvram_config(scsi_qla_host_t *vha) |
| 7731 | { |
| 7732 | int rval; |
| 7733 | struct init_cb_81xx *icb; |
| 7734 | struct nvram_81xx *nv; |
| 7735 | uint32_t *dptr; |
| 7736 | uint8_t *dptr1, *dptr2; |
| 7737 | uint32_t chksum; |
| 7738 | uint16_t cnt; |
| 7739 | struct qla_hw_data *ha = vha->hw; |
| 7740 | |
| 7741 | rval = QLA_SUCCESS; |
| 7742 | icb = (struct init_cb_81xx *)ha->init_cb; |
| 7743 | nv = ha->nvram; |
| 7744 | |
| 7745 | /* Determine NVRAM starting address. */ |
| 7746 | ha->nvram_size = sizeof(struct nvram_81xx); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7747 | ha->vpd_size = FA_NVRAM_VPD_SIZE; |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 7748 | if (IS_P3P_TYPE(ha) || IS_QLA8031(ha)) |
| 7749 | ha->vpd_size = FA_VPD_SIZE_82XX; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7750 | |
| 7751 | /* Get VPD data into cache */ |
| 7752 | ha->vpd = ha->nvram + VPD_OFFSET; |
Andrew Vasquez | 3d79038f | 2009-03-24 09:08:14 -0700 | [diff] [blame] | 7753 | ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2, |
| 7754 | ha->vpd_size); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7755 | |
| 7756 | /* Get NVRAM data into cache and calculate checksum. */ |
Andrew Vasquez | 3d79038f | 2009-03-24 09:08:14 -0700 | [diff] [blame] | 7757 | ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2, |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7758 | ha->nvram_size); |
Andrew Vasquez | 3d79038f | 2009-03-24 09:08:14 -0700 | [diff] [blame] | 7759 | dptr = (uint32_t *)nv; |
Joe Carnuccio | da08ef5 | 2016-01-27 12:03:34 -0500 | [diff] [blame] | 7760 | for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++) |
| 7761 | chksum += le32_to_cpu(*dptr); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7762 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7763 | ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0111, |
| 7764 | "Contents of NVRAM:\n"); |
| 7765 | ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0112, |
| 7766 | (uint8_t *)nv, ha->nvram_size); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7767 | |
| 7768 | /* Bad NVRAM data, set defaults parameters. */ |
| 7769 | if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P' |
| 7770 | || nv->id[3] != ' ' || |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7771 | nv->nvram_version < cpu_to_le16(ICB_VERSION)) { |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7772 | /* Reset NVRAM data. */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7773 | ql_log(ql_log_info, vha, 0x0073, |
Raul Porcel | 9e33652 | 2012-05-15 14:34:08 -0400 | [diff] [blame] | 7774 | "Inconsistent NVRAM detected: checksum=0x%x id=%c " |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7775 | "version=0x%x.\n", chksum, nv->id[0], |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7776 | le16_to_cpu(nv->nvram_version)); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7777 | ql_log(ql_log_info, vha, 0x0074, |
| 7778 | "Falling back to functioning (yet invalid -- WWPN) " |
| 7779 | "defaults.\n"); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7780 | |
| 7781 | /* |
| 7782 | * Set default initialization control block. |
| 7783 | */ |
| 7784 | memset(nv, 0, ha->nvram_size); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7785 | nv->nvram_version = cpu_to_le16(ICB_VERSION); |
| 7786 | nv->version = cpu_to_le16(ICB_VERSION); |
Joe Carnuccio | 98aee70 | 2014-09-25 05:16:38 -0400 | [diff] [blame] | 7787 | nv->frame_payload_size = 2048; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7788 | nv->execution_throttle = cpu_to_le16(0xFFFF); |
| 7789 | nv->exchange_count = cpu_to_le16(0); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7790 | nv->port_name[0] = 0x21; |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 7791 | nv->port_name[1] = 0x00 + ha->port_no + 1; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7792 | nv->port_name[2] = 0x00; |
| 7793 | nv->port_name[3] = 0xe0; |
| 7794 | nv->port_name[4] = 0x8b; |
| 7795 | nv->port_name[5] = 0x1c; |
| 7796 | nv->port_name[6] = 0x55; |
| 7797 | nv->port_name[7] = 0x86; |
| 7798 | nv->node_name[0] = 0x20; |
| 7799 | nv->node_name[1] = 0x00; |
| 7800 | nv->node_name[2] = 0x00; |
| 7801 | nv->node_name[3] = 0xe0; |
| 7802 | nv->node_name[4] = 0x8b; |
| 7803 | nv->node_name[5] = 0x1c; |
| 7804 | nv->node_name[6] = 0x55; |
| 7805 | nv->node_name[7] = 0x86; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7806 | nv->login_retry_count = cpu_to_le16(8); |
| 7807 | nv->interrupt_delay_timer = cpu_to_le16(0); |
| 7808 | nv->login_timeout = cpu_to_le16(0); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7809 | nv->firmware_options_1 = |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7810 | cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1); |
| 7811 | nv->firmware_options_2 = cpu_to_le32(2 << 4); |
| 7812 | nv->firmware_options_2 |= cpu_to_le32(BIT_12); |
| 7813 | nv->firmware_options_3 = cpu_to_le32(2 << 13); |
| 7814 | nv->host_p = cpu_to_le32(BIT_11|BIT_10); |
| 7815 | nv->efi_parameters = cpu_to_le32(0); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7816 | nv->reset_delay = 5; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7817 | nv->max_luns_per_target = cpu_to_le16(128); |
| 7818 | nv->port_down_retry_count = cpu_to_le16(30); |
| 7819 | nv->link_down_timeout = cpu_to_le16(180); |
Andrew Vasquez | eeebcc9 | 2009-06-03 09:55:24 -0700 | [diff] [blame] | 7820 | nv->enode_mac[0] = 0x00; |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 7821 | nv->enode_mac[1] = 0xC0; |
| 7822 | nv->enode_mac[2] = 0xDD; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7823 | nv->enode_mac[3] = 0x04; |
| 7824 | nv->enode_mac[4] = 0x05; |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 7825 | nv->enode_mac[5] = 0x06 + ha->port_no + 1; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7826 | |
| 7827 | rval = 1; |
| 7828 | } |
| 7829 | |
Arun Easi | 9e522cd | 2012-08-22 14:21:31 -0400 | [diff] [blame] | 7830 | if (IS_T10_PI_CAPABLE(ha)) |
| 7831 | nv->frame_payload_size &= ~7; |
| 7832 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 7833 | qlt_81xx_config_nvram_stage1(vha, nv); |
| 7834 | |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7835 | /* Reset Initialization control block */ |
Andrew Vasquez | 773120e | 2011-05-10 11:30:14 -0700 | [diff] [blame] | 7836 | memset(icb, 0, ha->init_cb_size); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7837 | |
| 7838 | /* Copy 1st segment. */ |
| 7839 | dptr1 = (uint8_t *)icb; |
| 7840 | dptr2 = (uint8_t *)&nv->version; |
| 7841 | cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version; |
| 7842 | while (cnt--) |
| 7843 | *dptr1++ = *dptr2++; |
| 7844 | |
| 7845 | icb->login_retry_count = nv->login_retry_count; |
| 7846 | |
| 7847 | /* Copy 2nd segment. */ |
| 7848 | dptr1 = (uint8_t *)&icb->interrupt_delay_timer; |
| 7849 | dptr2 = (uint8_t *)&nv->interrupt_delay_timer; |
| 7850 | cnt = (uint8_t *)&icb->reserved_5 - |
| 7851 | (uint8_t *)&icb->interrupt_delay_timer; |
| 7852 | while (cnt--) |
| 7853 | *dptr1++ = *dptr2++; |
| 7854 | |
| 7855 | memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac)); |
| 7856 | /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */ |
| 7857 | if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) { |
Andrew Vasquez | 69e5f1e | 2012-02-09 11:15:35 -0800 | [diff] [blame] | 7858 | icb->enode_mac[0] = 0x00; |
| 7859 | icb->enode_mac[1] = 0xC0; |
| 7860 | icb->enode_mac[2] = 0xDD; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7861 | icb->enode_mac[3] = 0x04; |
| 7862 | icb->enode_mac[4] = 0x05; |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 7863 | icb->enode_mac[5] = 0x06 + ha->port_no + 1; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7864 | } |
| 7865 | |
Andrew Vasquez | b64b0e8 | 2009-03-24 09:08:01 -0700 | [diff] [blame] | 7866 | /* Use extended-initialization control block. */ |
| 7867 | memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb)); |
| 7868 | |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7869 | /* |
| 7870 | * Setup driver NVRAM options. |
| 7871 | */ |
| 7872 | qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name), |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7873 | "QLE8XXX"); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7874 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 7875 | qlt_81xx_config_nvram_stage2(vha, icb); |
| 7876 | |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7877 | /* Use alternate WWN? */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7878 | if (nv->host_p & cpu_to_le32(BIT_15)) { |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7879 | memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE); |
| 7880 | memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE); |
| 7881 | } |
| 7882 | |
| 7883 | /* Prepare nodename */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7884 | if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) { |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7885 | /* |
| 7886 | * Firmware will apply the following mask if the nodename was |
| 7887 | * not provided. |
| 7888 | */ |
| 7889 | memcpy(icb->node_name, icb->port_name, WWN_SIZE); |
| 7890 | icb->node_name[0] &= 0xF0; |
| 7891 | } |
| 7892 | |
| 7893 | /* Set host adapter parameters. */ |
| 7894 | ha->flags.disable_risc_code_load = 0; |
| 7895 | ha->flags.enable_lip_reset = 0; |
| 7896 | ha->flags.enable_lip_full_login = |
| 7897 | le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0; |
| 7898 | ha->flags.enable_target_reset = |
| 7899 | le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0; |
| 7900 | ha->flags.enable_led_scheme = 0; |
| 7901 | ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0; |
| 7902 | |
| 7903 | ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) & |
| 7904 | (BIT_6 | BIT_5 | BIT_4)) >> 4; |
| 7905 | |
| 7906 | /* save HBA serial number */ |
| 7907 | ha->serial0 = icb->port_name[5]; |
| 7908 | ha->serial1 = icb->port_name[6]; |
| 7909 | ha->serial2 = icb->port_name[7]; |
| 7910 | memcpy(vha->node_name, icb->node_name, WWN_SIZE); |
| 7911 | memcpy(vha->port_name, icb->port_name, WWN_SIZE); |
| 7912 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7913 | icb->execution_throttle = cpu_to_le16(0xFFFF); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7914 | |
| 7915 | ha->retry_count = le16_to_cpu(nv->login_retry_count); |
| 7916 | |
| 7917 | /* Set minimum login_timeout to 4 seconds. */ |
| 7918 | if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout) |
| 7919 | nv->login_timeout = cpu_to_le16(ql2xlogintimeout); |
| 7920 | if (le16_to_cpu(nv->login_timeout) < 4) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7921 | nv->login_timeout = cpu_to_le16(4); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7922 | ha->login_timeout = le16_to_cpu(nv->login_timeout); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7923 | |
| 7924 | /* Set minimum RATOV to 100 tenths of a second. */ |
| 7925 | ha->r_a_tov = 100; |
| 7926 | |
| 7927 | ha->loop_reset_delay = nv->reset_delay; |
| 7928 | |
| 7929 | /* Link Down Timeout = 0: |
| 7930 | * |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 7931 | * When Port Down timer expires we will start returning |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7932 | * I/O's to OS with "DID_NO_CONNECT". |
| 7933 | * |
| 7934 | * Link Down Timeout != 0: |
| 7935 | * |
| 7936 | * The driver waits for the link to come up after link down |
| 7937 | * before returning I/Os to OS with "DID_NO_CONNECT". |
| 7938 | */ |
| 7939 | if (le16_to_cpu(nv->link_down_timeout) == 0) { |
| 7940 | ha->loop_down_abort_time = |
| 7941 | (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT); |
| 7942 | } else { |
| 7943 | ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout); |
| 7944 | ha->loop_down_abort_time = |
| 7945 | (LOOP_DOWN_TIME - ha->link_down_timeout); |
| 7946 | } |
| 7947 | |
| 7948 | /* Need enough time to try and get the port back. */ |
| 7949 | ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count); |
| 7950 | if (qlport_down_retry) |
| 7951 | ha->port_down_retry_count = qlport_down_retry; |
| 7952 | |
| 7953 | /* Set login_retry_count */ |
| 7954 | ha->login_retry_count = le16_to_cpu(nv->login_retry_count); |
| 7955 | if (ha->port_down_retry_count == |
| 7956 | le16_to_cpu(nv->port_down_retry_count) && |
| 7957 | ha->port_down_retry_count > 3) |
| 7958 | ha->login_retry_count = ha->port_down_retry_count; |
| 7959 | else if (ha->port_down_retry_count > (int)ha->login_retry_count) |
| 7960 | ha->login_retry_count = ha->port_down_retry_count; |
| 7961 | if (ql2xloginretrycount) |
| 7962 | ha->login_retry_count = ql2xloginretrycount; |
| 7963 | |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 7964 | /* if not running MSI-X we need handshaking on interrupts */ |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 7965 | if (!vha->hw->flags.msix_enabled && (IS_QLA83XX(ha) || IS_QLA27XX(ha))) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7966 | icb->firmware_options_2 |= cpu_to_le32(BIT_22); |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 7967 | |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7968 | /* Enable ZIO. */ |
| 7969 | if (!vha->flags.init_done) { |
| 7970 | ha->zio_mode = le32_to_cpu(icb->firmware_options_2) & |
| 7971 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
| 7972 | ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ? |
| 7973 | le16_to_cpu(icb->interrupt_delay_timer): 2; |
| 7974 | } |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7975 | icb->firmware_options_2 &= cpu_to_le32( |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7976 | ~(BIT_3 | BIT_2 | BIT_1 | BIT_0)); |
| 7977 | vha->flags.process_response_queue = 0; |
| 7978 | if (ha->zio_mode != QLA_ZIO_DISABLED) { |
| 7979 | ha->zio_mode = QLA_ZIO_MODE_6; |
| 7980 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7981 | ql_log(ql_log_info, vha, 0x0075, |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7982 | "ZIO mode %d enabled; timer delay (%d us).\n", |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7983 | ha->zio_mode, |
| 7984 | ha->zio_timer * 100); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7985 | |
| 7986 | icb->firmware_options_2 |= cpu_to_le32( |
| 7987 | (uint32_t)ha->zio_mode); |
| 7988 | icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer); |
| 7989 | vha->flags.process_response_queue = 1; |
| 7990 | } |
| 7991 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 7992 | /* enable RIDA Format2 */ |
| 7993 | if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) |
| 7994 | icb->firmware_options_3 |= BIT_0; |
| 7995 | |
Duane Grigsby | edd05de | 2017-10-13 09:34:06 -0700 | [diff] [blame] | 7996 | if (IS_QLA27XX(ha)) { |
| 7997 | icb->firmware_options_3 |= BIT_8; |
| 7998 | ql_dbg(ql_log_info, vha, 0x0075, |
| 7999 | "Enabling direct connection.\n"); |
| 8000 | } |
| 8001 | |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 8002 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 8003 | ql_log(ql_log_warn, vha, 0x0076, |
| 8004 | "NVRAM configuration failed.\n"); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 8005 | } |
| 8006 | return (rval); |
| 8007 | } |
| 8008 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 8009 | int |
| 8010 | qla82xx_restart_isp(scsi_qla_host_t *vha) |
| 8011 | { |
| 8012 | int status, rval; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 8013 | struct qla_hw_data *ha = vha->hw; |
| 8014 | struct req_que *req = ha->req_q_map[0]; |
| 8015 | struct rsp_que *rsp = ha->rsp_q_map[0]; |
| 8016 | struct scsi_qla_host *vp; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 8017 | unsigned long flags; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 8018 | |
| 8019 | status = qla2x00_init_rings(vha); |
| 8020 | if (!status) { |
| 8021 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); |
| 8022 | ha->flags.chip_reset_done = 1; |
| 8023 | |
| 8024 | status = qla2x00_fw_ready(vha); |
| 8025 | if (!status) { |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 8026 | /* Issue a marker after FW becomes ready. */ |
| 8027 | qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 8028 | vha->flags.online = 1; |
Chad Dupuis | 7108b76 | 2014-04-11 16:54:45 -0400 | [diff] [blame] | 8029 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 8030 | } |
| 8031 | |
| 8032 | /* if no cable then assume it's good */ |
| 8033 | if ((vha->device_flags & DFLG_NO_CABLE)) |
| 8034 | status = 0; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 8035 | } |
| 8036 | |
| 8037 | if (!status) { |
| 8038 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); |
| 8039 | |
| 8040 | if (!atomic_read(&vha->loop_down_timer)) { |
| 8041 | /* |
| 8042 | * Issue marker command only when we are going |
| 8043 | * to start the I/O . |
| 8044 | */ |
| 8045 | vha->marker_needed = 1; |
| 8046 | } |
| 8047 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 8048 | ha->isp_ops->enable_intrs(ha); |
| 8049 | |
| 8050 | ha->isp_abort_cnt = 0; |
| 8051 | clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags); |
| 8052 | |
Saurav Kashyap | 5329678 | 2011-05-10 11:30:06 -0700 | [diff] [blame] | 8053 | /* Update the firmware version */ |
Giridhar Malavali | 3173167 | 2011-08-16 11:31:54 -0700 | [diff] [blame] | 8054 | status = qla82xx_check_md_needed(vha); |
Saurav Kashyap | 5329678 | 2011-05-10 11:30:06 -0700 | [diff] [blame] | 8055 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 8056 | if (ha->fce) { |
| 8057 | ha->flags.fce_enabled = 1; |
| 8058 | memset(ha->fce, 0, |
| 8059 | fce_calc_size(ha->fce_bufs)); |
| 8060 | rval = qla2x00_enable_fce_trace(vha, |
| 8061 | ha->fce_dma, ha->fce_bufs, ha->fce_mb, |
| 8062 | &ha->fce_bufs); |
| 8063 | if (rval) { |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 8064 | ql_log(ql_log_warn, vha, 0x8001, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 8065 | "Unable to reinitialize FCE (%d).\n", |
| 8066 | rval); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 8067 | ha->flags.fce_enabled = 0; |
| 8068 | } |
| 8069 | } |
| 8070 | |
| 8071 | if (ha->eft) { |
| 8072 | memset(ha->eft, 0, EFT_SIZE); |
| 8073 | rval = qla2x00_enable_eft_trace(vha, |
| 8074 | ha->eft_dma, EFT_NUM_BUFFERS); |
| 8075 | if (rval) { |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 8076 | ql_log(ql_log_warn, vha, 0x8010, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 8077 | "Unable to reinitialize EFT (%d).\n", |
| 8078 | rval); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 8079 | } |
| 8080 | } |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 8081 | } |
| 8082 | |
| 8083 | if (!status) { |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 8084 | ql_dbg(ql_dbg_taskm, vha, 0x8011, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 8085 | "qla82xx_restart_isp succeeded.\n"); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 8086 | |
| 8087 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 8088 | list_for_each_entry(vp, &ha->vp_list, list) { |
| 8089 | if (vp->vp_idx) { |
| 8090 | atomic_inc(&vp->vref_count); |
| 8091 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 8092 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 8093 | qla2x00_vp_abort_isp(vp); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 8094 | |
| 8095 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 8096 | atomic_dec(&vp->vref_count); |
| 8097 | } |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 8098 | } |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 8099 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 8100 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 8101 | } else { |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 8102 | ql_log(ql_log_warn, vha, 0x8016, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 8103 | "qla82xx_restart_isp **** FAILED ****.\n"); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 8104 | } |
| 8105 | |
| 8106 | return status; |
| 8107 | } |
| 8108 | |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 8109 | void |
Andrew Vasquez | ae97c91 | 2010-02-18 10:07:28 -0800 | [diff] [blame] | 8110 | qla81xx_update_fw_options(scsi_qla_host_t *vha) |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 8111 | { |
Andrew Vasquez | ae97c91 | 2010-02-18 10:07:28 -0800 | [diff] [blame] | 8112 | struct qla_hw_data *ha = vha->hw; |
| 8113 | |
Himanshu Madhani | f198caf | 2016-01-27 12:03:30 -0500 | [diff] [blame] | 8114 | /* Hold status IOCBs until ABTS response received. */ |
| 8115 | if (ql2xfwholdabts) |
| 8116 | ha->fw_options[3] |= BIT_12; |
| 8117 | |
Giridhar Malavali | 088d09d | 2016-07-06 11:14:20 -0400 | [diff] [blame] | 8118 | /* Set Retry FLOGI in case of P2P connection */ |
| 8119 | if (ha->operating_mode == P2P) { |
| 8120 | ha->fw_options[2] |= BIT_3; |
| 8121 | ql_dbg(ql_dbg_disc, vha, 0x2103, |
| 8122 | "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n", |
| 8123 | __func__, ha->fw_options[2]); |
| 8124 | } |
| 8125 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 8126 | /* Move PUREX, ABTS RX & RIDA to ATIOQ */ |
| 8127 | if (ql2xmvasynctoatio) { |
| 8128 | if (qla_tgt_mode_enabled(vha) || |
| 8129 | qla_dual_mode_enabled(vha)) |
| 8130 | ha->fw_options[2] |= BIT_11; |
| 8131 | else |
| 8132 | ha->fw_options[2] &= ~BIT_11; |
| 8133 | } |
Andrew Vasquez | ae97c91 | 2010-02-18 10:07:28 -0800 | [diff] [blame] | 8134 | |
Quinn Tran | f7e761f | 2017-06-02 09:12:02 -0700 | [diff] [blame] | 8135 | if (qla_tgt_mode_enabled(vha) || |
Quinn Tran | 2da5273 | 2017-06-02 09:12:05 -0700 | [diff] [blame] | 8136 | qla_dual_mode_enabled(vha)) { |
| 8137 | /* FW auto send SCSI status during */ |
| 8138 | ha->fw_options[1] |= BIT_8; |
| 8139 | ha->fw_options[10] |= (u16)SAM_STAT_BUSY << 8; |
| 8140 | |
| 8141 | /* FW perform Exchange validation */ |
Quinn Tran | f7e761f | 2017-06-02 09:12:02 -0700 | [diff] [blame] | 8142 | ha->fw_options[2] |= BIT_4; |
Quinn Tran | 2da5273 | 2017-06-02 09:12:05 -0700 | [diff] [blame] | 8143 | } else { |
| 8144 | ha->fw_options[1] &= ~BIT_8; |
| 8145 | ha->fw_options[10] &= 0x00ff; |
| 8146 | |
Quinn Tran | f7e761f | 2017-06-02 09:12:02 -0700 | [diff] [blame] | 8147 | ha->fw_options[2] &= ~BIT_4; |
Quinn Tran | 2da5273 | 2017-06-02 09:12:05 -0700 | [diff] [blame] | 8148 | } |
Quinn Tran | f7e761f | 2017-06-02 09:12:02 -0700 | [diff] [blame] | 8149 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 8150 | if (ql2xetsenable) { |
| 8151 | /* Enable ETS Burst. */ |
| 8152 | memset(ha->fw_options, 0, sizeof(ha->fw_options)); |
| 8153 | ha->fw_options[2] |= BIT_9; |
| 8154 | } |
| 8155 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 8156 | ql_dbg(ql_dbg_init, vha, 0x00e9, |
| 8157 | "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n", |
| 8158 | __func__, ha->fw_options[1], ha->fw_options[2], |
| 8159 | ha->fw_options[3], vha->host->active_mode); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 8160 | |
Andrew Vasquez | ae97c91 | 2010-02-18 10:07:28 -0800 | [diff] [blame] | 8161 | qla2x00_set_fw_options(vha, ha->fw_options); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 8162 | } |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 8163 | |
| 8164 | /* |
| 8165 | * qla24xx_get_fcp_prio |
| 8166 | * Gets the fcp cmd priority value for the logged in port. |
| 8167 | * Looks for a match of the port descriptors within |
| 8168 | * each of the fcp prio config entries. If a match is found, |
| 8169 | * the tag (priority) value is returned. |
| 8170 | * |
| 8171 | * Input: |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 8172 | * vha = scsi host structure pointer. |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 8173 | * fcport = port structure pointer. |
| 8174 | * |
| 8175 | * Return: |
Andrew Vasquez | 6c452a4 | 2010-03-19 17:04:02 -0700 | [diff] [blame] | 8176 | * non-zero (if found) |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 8177 | * -1 (if not found) |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 8178 | * |
| 8179 | * Context: |
| 8180 | * Kernel context |
| 8181 | */ |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 8182 | static int |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 8183 | qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport) |
| 8184 | { |
| 8185 | int i, entries; |
| 8186 | uint8_t pid_match, wwn_match; |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 8187 | int priority; |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 8188 | uint32_t pid1, pid2; |
| 8189 | uint64_t wwn1, wwn2; |
| 8190 | struct qla_fcp_prio_entry *pri_entry; |
| 8191 | struct qla_hw_data *ha = vha->hw; |
| 8192 | |
| 8193 | if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled) |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 8194 | return -1; |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 8195 | |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 8196 | priority = -1; |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 8197 | entries = ha->fcp_prio_cfg->num_entries; |
| 8198 | pri_entry = &ha->fcp_prio_cfg->entry[0]; |
| 8199 | |
| 8200 | for (i = 0; i < entries; i++) { |
| 8201 | pid_match = wwn_match = 0; |
| 8202 | |
| 8203 | if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) { |
| 8204 | pri_entry++; |
| 8205 | continue; |
| 8206 | } |
| 8207 | |
| 8208 | /* check source pid for a match */ |
| 8209 | if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) { |
| 8210 | pid1 = pri_entry->src_pid & INVALID_PORT_ID; |
| 8211 | pid2 = vha->d_id.b24 & INVALID_PORT_ID; |
| 8212 | if (pid1 == INVALID_PORT_ID) |
| 8213 | pid_match++; |
| 8214 | else if (pid1 == pid2) |
| 8215 | pid_match++; |
| 8216 | } |
| 8217 | |
| 8218 | /* check destination pid for a match */ |
| 8219 | if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) { |
| 8220 | pid1 = pri_entry->dst_pid & INVALID_PORT_ID; |
| 8221 | pid2 = fcport->d_id.b24 & INVALID_PORT_ID; |
| 8222 | if (pid1 == INVALID_PORT_ID) |
| 8223 | pid_match++; |
| 8224 | else if (pid1 == pid2) |
| 8225 | pid_match++; |
| 8226 | } |
| 8227 | |
| 8228 | /* check source WWN for a match */ |
| 8229 | if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) { |
| 8230 | wwn1 = wwn_to_u64(vha->port_name); |
| 8231 | wwn2 = wwn_to_u64(pri_entry->src_wwpn); |
| 8232 | if (wwn2 == (uint64_t)-1) |
| 8233 | wwn_match++; |
| 8234 | else if (wwn1 == wwn2) |
| 8235 | wwn_match++; |
| 8236 | } |
| 8237 | |
| 8238 | /* check destination WWN for a match */ |
| 8239 | if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) { |
| 8240 | wwn1 = wwn_to_u64(fcport->port_name); |
| 8241 | wwn2 = wwn_to_u64(pri_entry->dst_wwpn); |
| 8242 | if (wwn2 == (uint64_t)-1) |
| 8243 | wwn_match++; |
| 8244 | else if (wwn1 == wwn2) |
| 8245 | wwn_match++; |
| 8246 | } |
| 8247 | |
| 8248 | if (pid_match == 2 || wwn_match == 2) { |
| 8249 | /* Found a matching entry */ |
| 8250 | if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID) |
| 8251 | priority = pri_entry->tag; |
| 8252 | break; |
| 8253 | } |
| 8254 | |
| 8255 | pri_entry++; |
| 8256 | } |
| 8257 | |
| 8258 | return priority; |
| 8259 | } |
| 8260 | |
| 8261 | /* |
| 8262 | * qla24xx_update_fcport_fcp_prio |
| 8263 | * Activates fcp priority for the logged in fc port |
| 8264 | * |
| 8265 | * Input: |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 8266 | * vha = scsi host structure pointer. |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 8267 | * fcp = port structure pointer. |
| 8268 | * |
| 8269 | * Return: |
| 8270 | * QLA_SUCCESS or QLA_FUNCTION_FAILED |
| 8271 | * |
| 8272 | * Context: |
| 8273 | * Kernel context. |
| 8274 | */ |
| 8275 | int |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 8276 | qla24xx_update_fcport_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport) |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 8277 | { |
| 8278 | int ret; |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 8279 | int priority; |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 8280 | uint16_t mb[5]; |
| 8281 | |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 8282 | if (fcport->port_type != FCT_TARGET || |
| 8283 | fcport->loop_id == FC_NO_LOOP_ID) |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 8284 | return QLA_FUNCTION_FAILED; |
| 8285 | |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 8286 | priority = qla24xx_get_fcp_prio(vha, fcport); |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 8287 | if (priority < 0) |
| 8288 | return QLA_FUNCTION_FAILED; |
| 8289 | |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 8290 | if (IS_P3P_TYPE(vha->hw)) { |
Saurav Kashyap | a00f629 | 2011-11-18 09:03:19 -0800 | [diff] [blame] | 8291 | fcport->fcp_prio = priority & 0xf; |
| 8292 | return QLA_SUCCESS; |
| 8293 | } |
| 8294 | |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 8295 | ret = qla24xx_set_fcp_prio(vha, fcport->loop_id, priority, mb); |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 8296 | if (ret == QLA_SUCCESS) { |
| 8297 | if (fcport->fcp_prio != priority) |
| 8298 | ql_dbg(ql_dbg_user, vha, 0x709e, |
| 8299 | "Updated FCP_CMND priority - value=%d loop_id=%d " |
| 8300 | "port_id=%02x%02x%02x.\n", priority, |
| 8301 | fcport->loop_id, fcport->d_id.b.domain, |
| 8302 | fcport->d_id.b.area, fcport->d_id.b.al_pa); |
Saurav Kashyap | a00f629 | 2011-11-18 09:03:19 -0800 | [diff] [blame] | 8303 | fcport->fcp_prio = priority & 0xf; |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 8304 | } else |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 8305 | ql_dbg(ql_dbg_user, vha, 0x704f, |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 8306 | "Unable to update FCP_CMND priority - ret=0x%x for " |
| 8307 | "loop_id=%d port_id=%02x%02x%02x.\n", ret, fcport->loop_id, |
| 8308 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 8309 | fcport->d_id.b.al_pa); |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 8310 | return ret; |
| 8311 | } |
| 8312 | |
| 8313 | /* |
| 8314 | * qla24xx_update_all_fcp_prio |
| 8315 | * Activates fcp priority for all the logged in ports |
| 8316 | * |
| 8317 | * Input: |
| 8318 | * ha = adapter block pointer. |
| 8319 | * |
| 8320 | * Return: |
| 8321 | * QLA_SUCCESS or QLA_FUNCTION_FAILED |
| 8322 | * |
| 8323 | * Context: |
| 8324 | * Kernel context. |
| 8325 | */ |
| 8326 | int |
| 8327 | qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha) |
| 8328 | { |
| 8329 | int ret; |
| 8330 | fc_port_t *fcport; |
| 8331 | |
| 8332 | ret = QLA_FUNCTION_FAILED; |
| 8333 | /* We need to set priority for all logged in ports */ |
| 8334 | list_for_each_entry(fcport, &vha->vp_fcports, list) |
| 8335 | ret = qla24xx_update_fcport_fcp_prio(vha, fcport); |
| 8336 | |
| 8337 | return ret; |
| 8338 | } |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 8339 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 8340 | struct qla_qpair *qla2xxx_create_qpair(struct scsi_qla_host *vha, int qos, |
| 8341 | int vp_idx, bool startqp) |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 8342 | { |
| 8343 | int rsp_id = 0; |
| 8344 | int req_id = 0; |
| 8345 | int i; |
| 8346 | struct qla_hw_data *ha = vha->hw; |
| 8347 | uint16_t qpair_id = 0; |
| 8348 | struct qla_qpair *qpair = NULL; |
| 8349 | struct qla_msix_entry *msix; |
| 8350 | |
| 8351 | if (!(ha->fw_attributes & BIT_6) || !ha->flags.msix_enabled) { |
| 8352 | ql_log(ql_log_warn, vha, 0x00181, |
| 8353 | "FW/Driver is not multi-queue capable.\n"); |
| 8354 | return NULL; |
| 8355 | } |
| 8356 | |
Himanshu Madhani | c38d1ba | 2017-10-13 15:43:22 -0700 | [diff] [blame] | 8357 | if (ql2xmqsupport || ql2xnvmeenable) { |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 8358 | qpair = kzalloc(sizeof(struct qla_qpair), GFP_KERNEL); |
| 8359 | if (qpair == NULL) { |
| 8360 | ql_log(ql_log_warn, vha, 0x0182, |
| 8361 | "Failed to allocate memory for queue pair.\n"); |
| 8362 | return NULL; |
| 8363 | } |
| 8364 | memset(qpair, 0, sizeof(struct qla_qpair)); |
| 8365 | |
| 8366 | qpair->hw = vha->hw; |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 8367 | qpair->vha = vha; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 8368 | qpair->qp_lock_ptr = &qpair->qp_lock; |
| 8369 | spin_lock_init(&qpair->qp_lock); |
Quinn Tran | af7bb38 | 2017-06-13 20:47:23 -0700 | [diff] [blame] | 8370 | qpair->use_shadow_reg = IS_SHADOW_REG_CAPABLE(ha) ? 1 : 0; |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 8371 | |
| 8372 | /* Assign available que pair id */ |
| 8373 | mutex_lock(&ha->mq_lock); |
| 8374 | qpair_id = find_first_zero_bit(ha->qpair_qid_map, ha->max_qpairs); |
Sawan Chandak | b95b945 | 2017-05-24 18:06:20 -0700 | [diff] [blame] | 8375 | if (ha->num_qpairs >= ha->max_qpairs) { |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 8376 | mutex_unlock(&ha->mq_lock); |
| 8377 | ql_log(ql_log_warn, vha, 0x0183, |
| 8378 | "No resources to create additional q pair.\n"); |
| 8379 | goto fail_qid_map; |
| 8380 | } |
Sawan Chandak | b95b945 | 2017-05-24 18:06:20 -0700 | [diff] [blame] | 8381 | ha->num_qpairs++; |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 8382 | set_bit(qpair_id, ha->qpair_qid_map); |
| 8383 | ha->queue_pair_map[qpair_id] = qpair; |
| 8384 | qpair->id = qpair_id; |
| 8385 | qpair->vp_idx = vp_idx; |
himanshu.madhani@cavium.com | e6373f33 | 2017-08-23 15:04:57 -0700 | [diff] [blame] | 8386 | qpair->fw_started = ha->flags.fw_started; |
Quinn Tran | e326d22 | 2017-06-13 20:47:18 -0700 | [diff] [blame] | 8387 | INIT_LIST_HEAD(&qpair->hints_list); |
Duane Grigsby | cf19c45 | 2017-08-23 15:04:58 -0700 | [diff] [blame] | 8388 | INIT_LIST_HEAD(&qpair->nvme_done_list); |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 8389 | qpair->chip_reset = ha->base_qpair->chip_reset; |
| 8390 | qpair->enable_class_2 = ha->base_qpair->enable_class_2; |
| 8391 | qpair->enable_explicit_conf = |
| 8392 | ha->base_qpair->enable_explicit_conf; |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 8393 | |
| 8394 | for (i = 0; i < ha->msix_count; i++) { |
Quinn Tran | 093df73 | 2016-12-12 14:40:09 -0800 | [diff] [blame] | 8395 | msix = &ha->msix_entries[i]; |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 8396 | if (msix->in_use) |
| 8397 | continue; |
| 8398 | qpair->msix = msix; |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 8399 | ql_dbg(ql_dbg_multiq, vha, 0xc00f, |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 8400 | "Vector %x selected for qpair\n", msix->vector); |
| 8401 | break; |
| 8402 | } |
| 8403 | if (!qpair->msix) { |
| 8404 | ql_log(ql_log_warn, vha, 0x0184, |
| 8405 | "Out of MSI-X vectors!.\n"); |
| 8406 | goto fail_msix; |
| 8407 | } |
| 8408 | |
| 8409 | qpair->msix->in_use = 1; |
| 8410 | list_add_tail(&qpair->qp_list_elem, &vha->qp_list); |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 8411 | qpair->pdev = ha->pdev; |
| 8412 | if (IS_QLA27XX(ha) || IS_QLA83XX(ha)) |
| 8413 | qpair->reqq_start_iocbs = qla_83xx_start_iocbs; |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 8414 | |
| 8415 | mutex_unlock(&ha->mq_lock); |
| 8416 | |
| 8417 | /* Create response queue first */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 8418 | rsp_id = qla25xx_create_rsp_que(ha, 0, 0, 0, qpair, startqp); |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 8419 | if (!rsp_id) { |
| 8420 | ql_log(ql_log_warn, vha, 0x0185, |
| 8421 | "Failed to create response queue.\n"); |
| 8422 | goto fail_rsp; |
| 8423 | } |
| 8424 | |
| 8425 | qpair->rsp = ha->rsp_q_map[rsp_id]; |
| 8426 | |
| 8427 | /* Create request queue */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 8428 | req_id = qla25xx_create_req_que(ha, 0, vp_idx, 0, rsp_id, qos, |
| 8429 | startqp); |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 8430 | if (!req_id) { |
| 8431 | ql_log(ql_log_warn, vha, 0x0186, |
| 8432 | "Failed to create request queue.\n"); |
| 8433 | goto fail_req; |
| 8434 | } |
| 8435 | |
| 8436 | qpair->req = ha->req_q_map[req_id]; |
| 8437 | qpair->rsp->req = qpair->req; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 8438 | qpair->rsp->qpair = qpair; |
Quinn Tran | e326d22 | 2017-06-13 20:47:18 -0700 | [diff] [blame] | 8439 | /* init qpair to this cpu. Will adjust at run time. */ |
| 8440 | qla_cpu_update(qpair, smp_processor_id()); |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 8441 | |
| 8442 | if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) { |
| 8443 | if (ha->fw_attributes & BIT_4) |
| 8444 | qpair->difdix_supported = 1; |
| 8445 | } |
| 8446 | |
| 8447 | qpair->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep); |
| 8448 | if (!qpair->srb_mempool) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 8449 | ql_log(ql_log_warn, vha, 0xd036, |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 8450 | "Failed to create srb mempool for qpair %d\n", |
| 8451 | qpair->id); |
| 8452 | goto fail_mempool; |
| 8453 | } |
| 8454 | |
| 8455 | /* Mark as online */ |
| 8456 | qpair->online = 1; |
| 8457 | |
| 8458 | if (!vha->flags.qpairs_available) |
| 8459 | vha->flags.qpairs_available = 1; |
| 8460 | |
| 8461 | ql_dbg(ql_dbg_multiq, vha, 0xc00d, |
| 8462 | "Request/Response queue pair created, id %d\n", |
| 8463 | qpair->id); |
| 8464 | ql_dbg(ql_dbg_init, vha, 0x0187, |
| 8465 | "Request/Response queue pair created, id %d\n", |
| 8466 | qpair->id); |
| 8467 | } |
| 8468 | return qpair; |
| 8469 | |
| 8470 | fail_mempool: |
| 8471 | fail_req: |
| 8472 | qla25xx_delete_rsp_que(vha, qpair->rsp); |
| 8473 | fail_rsp: |
| 8474 | mutex_lock(&ha->mq_lock); |
| 8475 | qpair->msix->in_use = 0; |
| 8476 | list_del(&qpair->qp_list_elem); |
| 8477 | if (list_empty(&vha->qp_list)) |
| 8478 | vha->flags.qpairs_available = 0; |
| 8479 | fail_msix: |
| 8480 | ha->queue_pair_map[qpair_id] = NULL; |
| 8481 | clear_bit(qpair_id, ha->qpair_qid_map); |
Sawan Chandak | b95b945 | 2017-05-24 18:06:20 -0700 | [diff] [blame] | 8482 | ha->num_qpairs--; |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 8483 | mutex_unlock(&ha->mq_lock); |
| 8484 | fail_qid_map: |
| 8485 | kfree(qpair); |
| 8486 | return NULL; |
| 8487 | } |
| 8488 | |
| 8489 | int qla2xxx_delete_qpair(struct scsi_qla_host *vha, struct qla_qpair *qpair) |
| 8490 | { |
Sawan Chandak | d65237c | 2017-06-13 20:47:19 -0700 | [diff] [blame] | 8491 | int ret = QLA_FUNCTION_FAILED; |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 8492 | struct qla_hw_data *ha = qpair->hw; |
| 8493 | |
| 8494 | qpair->delete_in_progress = 1; |
| 8495 | while (atomic_read(&qpair->ref_count)) |
| 8496 | msleep(500); |
| 8497 | |
| 8498 | ret = qla25xx_delete_req_que(vha, qpair->req); |
| 8499 | if (ret != QLA_SUCCESS) |
| 8500 | goto fail; |
himanshu.madhani@cavium.com | 7867b98 | 2017-12-04 14:45:16 -0800 | [diff] [blame] | 8501 | |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 8502 | ret = qla25xx_delete_rsp_que(vha, qpair->rsp); |
| 8503 | if (ret != QLA_SUCCESS) |
| 8504 | goto fail; |
| 8505 | |
| 8506 | mutex_lock(&ha->mq_lock); |
| 8507 | ha->queue_pair_map[qpair->id] = NULL; |
| 8508 | clear_bit(qpair->id, ha->qpair_qid_map); |
Sawan Chandak | b95b945 | 2017-05-24 18:06:20 -0700 | [diff] [blame] | 8509 | ha->num_qpairs--; |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 8510 | list_del(&qpair->qp_list_elem); |
Sawan Chandak | d65237c | 2017-06-13 20:47:19 -0700 | [diff] [blame] | 8511 | if (list_empty(&vha->qp_list)) { |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 8512 | vha->flags.qpairs_available = 0; |
Sawan Chandak | d65237c | 2017-06-13 20:47:19 -0700 | [diff] [blame] | 8513 | vha->flags.qpairs_req_created = 0; |
| 8514 | vha->flags.qpairs_rsp_created = 0; |
| 8515 | } |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 8516 | mempool_destroy(qpair->srb_mempool); |
| 8517 | kfree(qpair); |
| 8518 | mutex_unlock(&ha->mq_lock); |
| 8519 | |
| 8520 | return QLA_SUCCESS; |
| 8521 | fail: |
| 8522 | return ret; |
| 8523 | } |