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 *); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 44 | |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 45 | /* SRB Extensions ---------------------------------------------------------- */ |
| 46 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 47 | void |
Kees Cook | 8e5f4ba | 2017-09-03 13:23:32 -0700 | [diff] [blame] | 48 | qla2x00_sp_timeout(struct timer_list *t) |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 49 | { |
Kees Cook | 8e5f4ba | 2017-09-03 13:23:32 -0700 | [diff] [blame] | 50 | srb_t *sp = from_timer(sp, t, u.iocb_cmd.timer); |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 51 | struct srb_iocb *iocb; |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 52 | scsi_qla_host_t *vha = sp->vha; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 53 | struct req_que *req; |
| 54 | unsigned long flags; |
| 55 | |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 56 | spin_lock_irqsave(&vha->hw->hardware_lock, flags); |
| 57 | req = vha->hw->req_q_map[0]; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 58 | req->outstanding_cmds[sp->handle] = NULL; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 59 | iocb = &sp->u.iocb_cmd; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 60 | iocb->timeout(sp); |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 61 | sp->free(sp); |
| 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; |
| 103 | struct event_arg ea; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 104 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 105 | ql_dbg(ql_dbg_disc, fcport->vha, 0x2071, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 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 | |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 109 | fcport->flags &= ~FCF_ASYNC_SENT; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 110 | |
| 111 | switch (sp->type) { |
| 112 | case SRB_LOGIN_CMD: |
Andrew Vasquez | 6ac5260 | 2010-05-28 15:08:19 -0700 | [diff] [blame] | 113 | /* Retry as needed. */ |
| 114 | lio->u.logio.data[0] = MBS_COMMAND_ERROR; |
| 115 | lio->u.logio.data[1] = lio->u.logio.flags & SRB_LOGIN_RETRIED ? |
| 116 | QLA_LOGIO_LOGIN_RETRIED : 0; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 117 | memset(&ea, 0, sizeof(ea)); |
| 118 | ea.event = FCME_PLOGI_DONE; |
| 119 | ea.fcport = sp->fcport; |
| 120 | ea.data[0] = lio->u.logio.data[0]; |
| 121 | ea.data[1] = lio->u.logio.data[1]; |
| 122 | ea.sp = sp; |
| 123 | qla24xx_handle_plogi_done_event(fcport->vha, &ea); |
| 124 | break; |
| 125 | case SRB_LOGOUT_CMD: |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 126 | qlt_logo_completion_handler(fcport, QLA_FUNCTION_TIMEOUT); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 127 | break; |
| 128 | case SRB_CT_PTHRU_CMD: |
| 129 | case SRB_MB_IOCB: |
| 130 | case SRB_NACK_PLOGI: |
| 131 | case SRB_NACK_PRLI: |
| 132 | case SRB_NACK_LOGO: |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 133 | sp->done(sp, QLA_FUNCTION_TIMEOUT); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 134 | break; |
Andrew Vasquez | 6ac5260 | 2010-05-28 15:08:19 -0700 | [diff] [blame] | 135 | } |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 136 | } |
| 137 | |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 138 | static void |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 139 | qla2x00_async_login_sp_done(void *ptr, int res) |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 140 | { |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 141 | srb_t *sp = ptr; |
| 142 | struct scsi_qla_host *vha = sp->vha; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 143 | struct srb_iocb *lio = &sp->u.iocb_cmd; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 144 | struct event_arg ea; |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 145 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 146 | ql_dbg(ql_dbg_disc, vha, 0x20dd, |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 147 | "%s %8phC res %d \n", __func__, sp->fcport->port_name, res); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 148 | |
| 149 | sp->fcport->flags &= ~FCF_ASYNC_SENT; |
| 150 | if (!test_bit(UNLOADING, &vha->dpc_flags)) { |
| 151 | memset(&ea, 0, sizeof(ea)); |
| 152 | ea.event = FCME_PLOGI_DONE; |
| 153 | ea.fcport = sp->fcport; |
| 154 | ea.data[0] = lio->u.logio.data[0]; |
| 155 | ea.data[1] = lio->u.logio.data[1]; |
| 156 | ea.iop[0] = lio->u.logio.iop[0]; |
| 157 | ea.iop[1] = lio->u.logio.iop[1]; |
| 158 | ea.sp = sp; |
| 159 | qla2x00_fcport_event_handler(vha, &ea); |
| 160 | } |
| 161 | |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 162 | sp->free(sp); |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 163 | } |
| 164 | |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 165 | int |
| 166 | qla2x00_async_login(struct scsi_qla_host *vha, fc_port_t *fcport, |
| 167 | uint16_t *data) |
| 168 | { |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 169 | srb_t *sp; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 170 | struct srb_iocb *lio; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 171 | int rval = QLA_FUNCTION_FAILED; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 172 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 173 | if (!vha->flags.online) |
| 174 | goto done; |
| 175 | |
| 176 | if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) || |
| 177 | (fcport->fw_login_state == DSC_LS_PLOGI_COMP) || |
| 178 | (fcport->fw_login_state == DSC_LS_PRLI_PEND)) |
| 179 | goto done; |
| 180 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 181 | sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 182 | if (!sp) |
| 183 | goto done; |
| 184 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 185 | fcport->flags |= FCF_ASYNC_SENT; |
| 186 | fcport->logout_completed = 0; |
| 187 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 188 | sp->type = SRB_LOGIN_CMD; |
| 189 | sp->name = "login"; |
| 190 | qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2); |
| 191 | |
| 192 | lio = &sp->u.iocb_cmd; |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 193 | lio->timeout = qla2x00_async_iocb_timeout; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 194 | sp->done = qla2x00_async_login_sp_done; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 195 | lio->u.logio.flags |= SRB_LOGIN_COND_PLOGI; |
Duane Grigsby | a5d42f4 | 2017-06-21 13:48:41 -0700 | [diff] [blame] | 196 | |
| 197 | if (fcport->fc4f_nvme) |
| 198 | lio->u.logio.flags |= SRB_LOGIN_SKIP_PRLI; |
| 199 | |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 200 | if (data[1] & QLA_LOGIO_LOGIN_RETRIED) |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 201 | lio->u.logio.flags |= SRB_LOGIN_RETRIED; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 202 | rval = qla2x00_start_sp(sp); |
Chad Dupuis | 080c951 | 2016-01-27 12:03:37 -0500 | [diff] [blame] | 203 | if (rval != QLA_SUCCESS) { |
| 204 | fcport->flags &= ~FCF_ASYNC_SENT; |
| 205 | fcport->flags |= FCF_LOGIN_NEEDED; |
| 206 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 207 | goto done_free_sp; |
Chad Dupuis | 080c951 | 2016-01-27 12:03:37 -0500 | [diff] [blame] | 208 | } |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 209 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 210 | ql_dbg(ql_dbg_disc, vha, 0x2072, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 211 | "Async-login - %8phC hdl=%x, loopid=%x portid=%02x%02x%02x " |
| 212 | "retries=%d.\n", fcport->port_name, sp->handle, fcport->loop_id, |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 213 | fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa, |
| 214 | fcport->login_retry); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 215 | return rval; |
| 216 | |
| 217 | done_free_sp: |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 218 | sp->free(sp); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 219 | done: |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 220 | fcport->flags &= ~FCF_ASYNC_SENT; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 221 | return rval; |
| 222 | } |
| 223 | |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 224 | static void |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 225 | qla2x00_async_logout_sp_done(void *ptr, int res) |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 226 | { |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 227 | srb_t *sp = ptr; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 228 | struct srb_iocb *lio = &sp->u.iocb_cmd; |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 229 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 230 | sp->fcport->flags &= ~FCF_ASYNC_SENT; |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 231 | if (!test_bit(UNLOADING, &sp->vha->dpc_flags)) |
| 232 | qla2x00_post_async_logout_done_work(sp->vha, sp->fcport, |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 233 | lio->u.logio.data); |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 234 | sp->free(sp); |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 235 | } |
| 236 | |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 237 | int |
| 238 | qla2x00_async_logout(struct scsi_qla_host *vha, fc_port_t *fcport) |
| 239 | { |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 240 | srb_t *sp; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 241 | struct srb_iocb *lio; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 242 | int rval; |
| 243 | |
| 244 | rval = QLA_FUNCTION_FAILED; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 245 | fcport->flags |= FCF_ASYNC_SENT; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 246 | sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 247 | if (!sp) |
| 248 | goto done; |
| 249 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 250 | sp->type = SRB_LOGOUT_CMD; |
| 251 | sp->name = "logout"; |
| 252 | qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2); |
| 253 | |
| 254 | lio = &sp->u.iocb_cmd; |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 255 | lio->timeout = qla2x00_async_iocb_timeout; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 256 | sp->done = qla2x00_async_logout_sp_done; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 257 | rval = qla2x00_start_sp(sp); |
| 258 | if (rval != QLA_SUCCESS) |
| 259 | goto done_free_sp; |
| 260 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 261 | ql_dbg(ql_dbg_disc, vha, 0x2070, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 262 | "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] | 263 | sp->handle, fcport->loop_id, fcport->d_id.b.domain, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 264 | fcport->d_id.b.area, fcport->d_id.b.al_pa, |
| 265 | fcport->port_name); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 266 | return rval; |
| 267 | |
| 268 | done_free_sp: |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 269 | sp->free(sp); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 270 | done: |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 271 | fcport->flags &= ~FCF_ASYNC_SENT; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 272 | return rval; |
| 273 | } |
| 274 | |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 275 | static void |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 276 | qla2x00_async_adisc_sp_done(void *ptr, int res) |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 277 | { |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 278 | srb_t *sp = ptr; |
| 279 | struct scsi_qla_host *vha = sp->vha; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 280 | struct srb_iocb *lio = &sp->u.iocb_cmd; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 281 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 282 | if (!test_bit(UNLOADING, &vha->dpc_flags)) |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 283 | qla2x00_post_async_adisc_done_work(sp->vha, sp->fcport, |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 284 | lio->u.logio.data); |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 285 | sp->free(sp); |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | int |
| 289 | qla2x00_async_adisc(struct scsi_qla_host *vha, fc_port_t *fcport, |
| 290 | uint16_t *data) |
| 291 | { |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 292 | srb_t *sp; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 293 | struct srb_iocb *lio; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 294 | int rval; |
| 295 | |
| 296 | rval = QLA_FUNCTION_FAILED; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 297 | fcport->flags |= FCF_ASYNC_SENT; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 298 | sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 299 | if (!sp) |
| 300 | goto done; |
| 301 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 302 | sp->type = SRB_ADISC_CMD; |
| 303 | sp->name = "adisc"; |
| 304 | qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2); |
| 305 | |
| 306 | lio = &sp->u.iocb_cmd; |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 307 | lio->timeout = qla2x00_async_iocb_timeout; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 308 | sp->done = qla2x00_async_adisc_sp_done; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 309 | if (data[1] & QLA_LOGIO_LOGIN_RETRIED) |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 310 | lio->u.logio.flags |= SRB_LOGIN_RETRIED; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 311 | rval = qla2x00_start_sp(sp); |
| 312 | if (rval != QLA_SUCCESS) |
| 313 | goto done_free_sp; |
| 314 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 315 | ql_dbg(ql_dbg_disc, vha, 0x206f, |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 316 | "Async-adisc - hdl=%x loopid=%x portid=%02x%02x%02x.\n", |
| 317 | sp->handle, fcport->loop_id, fcport->d_id.b.domain, |
| 318 | fcport->d_id.b.area, fcport->d_id.b.al_pa); |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 319 | return rval; |
| 320 | |
| 321 | done_free_sp: |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 322 | sp->free(sp); |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 323 | done: |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 324 | fcport->flags &= ~FCF_ASYNC_SENT; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 325 | return rval; |
| 326 | } |
| 327 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 328 | static void qla24xx_handle_gnl_done_event(scsi_qla_host_t *vha, |
| 329 | struct event_arg *ea) |
| 330 | { |
| 331 | fc_port_t *fcport, *conflict_fcport; |
| 332 | struct get_name_list_extended *e; |
| 333 | u16 i, n, found = 0, loop_id; |
| 334 | port_id_t id; |
| 335 | u64 wwn; |
Duane Grigsby | a5d42f4 | 2017-06-21 13:48:41 -0700 | [diff] [blame] | 336 | u8 opt = 0, current_login_state; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 337 | |
| 338 | fcport = ea->fcport; |
| 339 | |
| 340 | if (ea->rc) { /* rval */ |
| 341 | if (fcport->login_retry == 0) { |
| 342 | fcport->login_retry = vha->hw->login_retry_count; |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 343 | ql_dbg(ql_dbg_disc, vha, 0x20de, |
| 344 | "GNL failed Port login retry %8phN, retry cnt=%d.\n", |
| 345 | fcport->port_name, fcport->login_retry); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 346 | } |
| 347 | return; |
| 348 | } |
| 349 | |
| 350 | if (fcport->last_rscn_gen != fcport->rscn_gen) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 351 | ql_dbg(ql_dbg_disc, vha, 0x20df, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 352 | "%s %8phC rscn gen changed rscn %d|%d \n", |
| 353 | __func__, fcport->port_name, |
| 354 | fcport->last_rscn_gen, fcport->rscn_gen); |
| 355 | qla24xx_post_gidpn_work(vha, fcport); |
| 356 | return; |
| 357 | } else if (fcport->last_login_gen != fcport->login_gen) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 358 | ql_dbg(ql_dbg_disc, vha, 0x20e0, |
| 359 | "%s %8phC login gen changed login %d|%d\n", |
| 360 | __func__, fcport->port_name, |
| 361 | fcport->last_login_gen, fcport->login_gen); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 362 | return; |
| 363 | } |
| 364 | |
| 365 | n = ea->data[0] / sizeof(struct get_name_list_extended); |
| 366 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 367 | ql_dbg(ql_dbg_disc, vha, 0x20e1, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 368 | "%s %d %8phC n %d %02x%02x%02x lid %d \n", |
| 369 | __func__, __LINE__, fcport->port_name, n, |
| 370 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 371 | fcport->d_id.b.al_pa, fcport->loop_id); |
| 372 | |
| 373 | for (i = 0; i < n; i++) { |
| 374 | e = &vha->gnl.l[i]; |
| 375 | wwn = wwn_to_u64(e->port_name); |
| 376 | |
| 377 | if (memcmp((u8 *)&wwn, fcport->port_name, WWN_SIZE)) |
| 378 | continue; |
| 379 | |
| 380 | found = 1; |
| 381 | id.b.domain = e->port_id[2]; |
| 382 | id.b.area = e->port_id[1]; |
| 383 | id.b.al_pa = e->port_id[0]; |
| 384 | id.b.rsvd_1 = 0; |
| 385 | |
| 386 | loop_id = le16_to_cpu(e->nport_handle); |
| 387 | loop_id = (loop_id & 0x7fff); |
| 388 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 389 | ql_dbg(ql_dbg_disc, vha, 0x20e2, |
| 390 | "%s found %8phC CLS [%d|%d] ID[%02x%02x%02x|%02x%02x%02x] lid[%d|%d]\n", |
| 391 | __func__, fcport->port_name, |
| 392 | e->current_login_state, fcport->fw_login_state, |
| 393 | id.b.domain, id.b.area, id.b.al_pa, |
| 394 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 395 | fcport->d_id.b.al_pa, loop_id, fcport->loop_id); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 396 | |
| 397 | if ((id.b24 != fcport->d_id.b24) || |
| 398 | ((fcport->loop_id != FC_NO_LOOP_ID) && |
| 399 | (fcport->loop_id != loop_id))) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 400 | ql_dbg(ql_dbg_disc, vha, 0x20e3, |
| 401 | "%s %d %8phC post del sess\n", |
| 402 | __func__, __LINE__, fcport->port_name); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 403 | qlt_schedule_sess_for_deletion(fcport, 1); |
| 404 | return; |
| 405 | } |
| 406 | |
| 407 | fcport->loop_id = loop_id; |
| 408 | |
| 409 | wwn = wwn_to_u64(fcport->port_name); |
| 410 | qlt_find_sess_invalidate_other(vha, wwn, |
| 411 | id, loop_id, &conflict_fcport); |
| 412 | |
| 413 | if (conflict_fcport) { |
| 414 | /* |
| 415 | * Another share fcport share the same loop_id & |
| 416 | * nport id. Conflict fcport needs to finish |
| 417 | * cleanup before this fcport can proceed to login. |
| 418 | */ |
| 419 | conflict_fcport->conflict = fcport; |
| 420 | fcport->login_pause = 1; |
| 421 | } |
| 422 | |
Duane Grigsby | a5d42f4 | 2017-06-21 13:48:41 -0700 | [diff] [blame] | 423 | if (fcport->fc4f_nvme) |
| 424 | current_login_state = e->current_login_state >> 4; |
| 425 | else |
| 426 | current_login_state = e->current_login_state & 0xf; |
| 427 | |
| 428 | switch (current_login_state) { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 429 | case DSC_LS_PRLI_COMP: |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 430 | ql_dbg(ql_dbg_disc, vha, 0x20e4, |
| 431 | "%s %d %8phC post gpdb\n", |
| 432 | __func__, __LINE__, fcport->port_name); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 433 | opt = PDO_FORCE_ADISC; |
| 434 | qla24xx_post_gpdb_work(vha, fcport, opt); |
| 435 | break; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 436 | case DSC_LS_PORT_UNAVAIL: |
| 437 | default: |
| 438 | if (fcport->loop_id == FC_NO_LOOP_ID) { |
| 439 | qla2x00_find_new_loop_id(vha, fcport); |
| 440 | fcport->fw_login_state = DSC_LS_PORT_UNAVAIL; |
| 441 | } |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 442 | ql_dbg(ql_dbg_disc, vha, 0x20e5, |
| 443 | "%s %d %8phC\n", |
| 444 | __func__, __LINE__, fcport->port_name); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 445 | qla24xx_fcport_handle_login(vha, fcport); |
| 446 | break; |
| 447 | } |
| 448 | } |
| 449 | |
| 450 | if (!found) { |
| 451 | /* fw has no record of this port */ |
| 452 | if (fcport->loop_id == FC_NO_LOOP_ID) { |
| 453 | qla2x00_find_new_loop_id(vha, fcport); |
| 454 | fcport->fw_login_state = DSC_LS_PORT_UNAVAIL; |
| 455 | } else { |
| 456 | for (i = 0; i < n; i++) { |
| 457 | e = &vha->gnl.l[i]; |
| 458 | id.b.domain = e->port_id[0]; |
| 459 | id.b.area = e->port_id[1]; |
| 460 | id.b.al_pa = e->port_id[2]; |
| 461 | id.b.rsvd_1 = 0; |
| 462 | loop_id = le16_to_cpu(e->nport_handle); |
| 463 | |
| 464 | if (fcport->d_id.b24 == id.b24) { |
| 465 | conflict_fcport = |
| 466 | qla2x00_find_fcport_by_wwpn(vha, |
| 467 | e->port_name, 0); |
| 468 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 469 | ql_dbg(ql_dbg_disc, vha, 0x20e6, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 470 | "%s %d %8phC post del sess\n", |
| 471 | __func__, __LINE__, |
| 472 | conflict_fcport->port_name); |
| 473 | qlt_schedule_sess_for_deletion |
| 474 | (conflict_fcport, 1); |
| 475 | } |
| 476 | |
| 477 | if (fcport->loop_id == loop_id) { |
| 478 | /* FW already picked this loop id for another fcport */ |
| 479 | qla2x00_find_new_loop_id(vha, fcport); |
| 480 | } |
| 481 | } |
| 482 | } |
| 483 | qla24xx_fcport_handle_login(vha, fcport); |
| 484 | } |
| 485 | } /* gnl_event */ |
| 486 | |
| 487 | static void |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 488 | qla24xx_async_gnl_sp_done(void *s, int res) |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 489 | { |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 490 | struct srb *sp = s; |
| 491 | struct scsi_qla_host *vha = sp->vha; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 492 | unsigned long flags; |
| 493 | struct fc_port *fcport = NULL, *tf; |
| 494 | u16 i, n = 0, loop_id; |
| 495 | struct event_arg ea; |
| 496 | struct get_name_list_extended *e; |
| 497 | u64 wwn; |
| 498 | struct list_head h; |
| 499 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 500 | ql_dbg(ql_dbg_disc, vha, 0x20e7, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 501 | "Async done-%s res %x mb[1]=%x mb[2]=%x \n", |
| 502 | sp->name, res, sp->u.iocb_cmd.u.mbx.in_mb[1], |
| 503 | sp->u.iocb_cmd.u.mbx.in_mb[2]); |
| 504 | |
| 505 | memset(&ea, 0, sizeof(ea)); |
| 506 | ea.sp = sp; |
| 507 | ea.rc = res; |
| 508 | ea.event = FCME_GNL_DONE; |
| 509 | |
| 510 | if (sp->u.iocb_cmd.u.mbx.in_mb[1] >= |
| 511 | sizeof(struct get_name_list_extended)) { |
| 512 | n = sp->u.iocb_cmd.u.mbx.in_mb[1] / |
| 513 | sizeof(struct get_name_list_extended); |
| 514 | ea.data[0] = sp->u.iocb_cmd.u.mbx.in_mb[1]; /* amnt xfered */ |
| 515 | } |
| 516 | |
| 517 | for (i = 0; i < n; i++) { |
| 518 | e = &vha->gnl.l[i]; |
| 519 | loop_id = le16_to_cpu(e->nport_handle); |
| 520 | /* mask out reserve bit */ |
| 521 | loop_id = (loop_id & 0x7fff); |
| 522 | set_bit(loop_id, vha->hw->loop_id_map); |
| 523 | wwn = wwn_to_u64(e->port_name); |
| 524 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 525 | ql_dbg(ql_dbg_disc + ql_dbg_verbose, vha, 0x20e8, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 526 | "%s %8phC %02x:%02x:%02x state %d/%d lid %x \n", |
| 527 | __func__, (void *)&wwn, e->port_id[2], e->port_id[1], |
| 528 | e->port_id[0], e->current_login_state, e->last_login_state, |
| 529 | (loop_id & 0x7fff)); |
| 530 | } |
| 531 | |
| 532 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
| 533 | vha->gnl.sent = 0; |
| 534 | |
| 535 | INIT_LIST_HEAD(&h); |
| 536 | fcport = tf = NULL; |
| 537 | if (!list_empty(&vha->gnl.fcports)) |
| 538 | list_splice_init(&vha->gnl.fcports, &h); |
| 539 | |
| 540 | list_for_each_entry_safe(fcport, tf, &h, gnl_entry) { |
| 541 | list_del_init(&fcport->gnl_entry); |
| 542 | fcport->flags &= ~FCF_ASYNC_SENT; |
| 543 | ea.fcport = fcport; |
| 544 | |
| 545 | qla2x00_fcport_event_handler(vha, &ea); |
| 546 | } |
| 547 | |
| 548 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
| 549 | |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 550 | sp->free(sp); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 551 | } |
| 552 | |
| 553 | int qla24xx_async_gnl(struct scsi_qla_host *vha, fc_port_t *fcport) |
| 554 | { |
| 555 | srb_t *sp; |
| 556 | struct srb_iocb *mbx; |
| 557 | int rval = QLA_FUNCTION_FAILED; |
| 558 | unsigned long flags; |
| 559 | u16 *mb; |
| 560 | |
| 561 | if (!vha->flags.online) |
| 562 | goto done; |
| 563 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 564 | ql_dbg(ql_dbg_disc, vha, 0x20d9, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 565 | "Async-gnlist WWPN %8phC \n", fcport->port_name); |
| 566 | |
| 567 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
| 568 | fcport->flags |= FCF_ASYNC_SENT; |
| 569 | fcport->disc_state = DSC_GNL; |
| 570 | fcport->last_rscn_gen = fcport->rscn_gen; |
| 571 | fcport->last_login_gen = fcport->login_gen; |
| 572 | |
| 573 | list_add_tail(&fcport->gnl_entry, &vha->gnl.fcports); |
| 574 | if (vha->gnl.sent) { |
| 575 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
| 576 | rval = QLA_SUCCESS; |
| 577 | goto done; |
| 578 | } |
| 579 | vha->gnl.sent = 1; |
| 580 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
| 581 | |
| 582 | sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); |
| 583 | if (!sp) |
| 584 | goto done; |
| 585 | sp->type = SRB_MB_IOCB; |
| 586 | sp->name = "gnlist"; |
| 587 | sp->gen1 = fcport->rscn_gen; |
| 588 | sp->gen2 = fcport->login_gen; |
| 589 | |
| 590 | qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha)+2); |
| 591 | |
| 592 | mb = sp->u.iocb_cmd.u.mbx.out_mb; |
| 593 | mb[0] = MBC_PORT_NODE_NAME_LIST; |
| 594 | mb[1] = BIT_2 | BIT_3; |
| 595 | mb[2] = MSW(vha->gnl.ldma); |
| 596 | mb[3] = LSW(vha->gnl.ldma); |
| 597 | mb[6] = MSW(MSD(vha->gnl.ldma)); |
| 598 | mb[7] = LSW(MSD(vha->gnl.ldma)); |
| 599 | mb[8] = vha->gnl.size; |
| 600 | mb[9] = vha->vp_idx; |
| 601 | |
| 602 | mbx = &sp->u.iocb_cmd; |
| 603 | mbx->timeout = qla2x00_async_iocb_timeout; |
| 604 | |
| 605 | sp->done = qla24xx_async_gnl_sp_done; |
| 606 | |
| 607 | rval = qla2x00_start_sp(sp); |
| 608 | if (rval != QLA_SUCCESS) |
| 609 | goto done_free_sp; |
| 610 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 611 | ql_dbg(ql_dbg_disc, vha, 0x20da, |
| 612 | "Async-%s - OUT WWPN %8phC hndl %x\n", |
| 613 | sp->name, fcport->port_name, sp->handle); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 614 | |
| 615 | return rval; |
| 616 | |
| 617 | done_free_sp: |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 618 | sp->free(sp); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 619 | done: |
| 620 | fcport->flags &= ~FCF_ASYNC_SENT; |
| 621 | return rval; |
| 622 | } |
| 623 | |
| 624 | int qla24xx_post_gnl_work(struct scsi_qla_host *vha, fc_port_t *fcport) |
| 625 | { |
| 626 | struct qla_work_evt *e; |
| 627 | |
| 628 | e = qla2x00_alloc_work(vha, QLA_EVT_GNL); |
| 629 | if (!e) |
| 630 | return QLA_FUNCTION_FAILED; |
| 631 | |
| 632 | e->u.fcport.fcport = fcport; |
| 633 | return qla2x00_post_work(vha, e); |
| 634 | } |
| 635 | |
| 636 | static |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 637 | void qla24xx_async_gpdb_sp_done(void *s, int res) |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 638 | { |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 639 | struct srb *sp = s; |
| 640 | struct scsi_qla_host *vha = sp->vha; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 641 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 642 | struct port_database_24xx *pd; |
| 643 | fc_port_t *fcport = sp->fcport; |
| 644 | u16 *mb = sp->u.iocb_cmd.u.mbx.in_mb; |
| 645 | int rval = QLA_SUCCESS; |
| 646 | struct event_arg ea; |
| 647 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 648 | ql_dbg(ql_dbg_disc, vha, 0x20db, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 649 | "Async done-%s res %x, WWPN %8phC mb[1]=%x mb[2]=%x \n", |
| 650 | sp->name, res, fcport->port_name, mb[1], mb[2]); |
| 651 | |
| 652 | fcport->flags &= ~FCF_ASYNC_SENT; |
| 653 | |
| 654 | if (res) { |
| 655 | rval = res; |
| 656 | goto gpd_error_out; |
| 657 | } |
| 658 | |
| 659 | pd = (struct port_database_24xx *)sp->u.iocb_cmd.u.mbx.in; |
| 660 | |
Quinn Tran | 15f30a5 | 2017-03-15 09:48:52 -0700 | [diff] [blame] | 661 | rval = __qla24xx_parse_gpdb(vha, fcport, pd); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 662 | |
| 663 | gpd_error_out: |
| 664 | memset(&ea, 0, sizeof(ea)); |
| 665 | ea.event = FCME_GPDB_DONE; |
| 666 | ea.rc = rval; |
| 667 | ea.fcport = fcport; |
| 668 | ea.sp = sp; |
| 669 | |
| 670 | qla2x00_fcport_event_handler(vha, &ea); |
| 671 | |
| 672 | dma_pool_free(ha->s_dma_pool, sp->u.iocb_cmd.u.mbx.in, |
| 673 | sp->u.iocb_cmd.u.mbx.in_dma); |
| 674 | |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 675 | sp->free(sp); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 676 | } |
| 677 | |
Duane Grigsby | a5d42f4 | 2017-06-21 13:48:41 -0700 | [diff] [blame] | 678 | static int qla24xx_post_prli_work(struct scsi_qla_host *vha, fc_port_t *fcport) |
| 679 | { |
| 680 | struct qla_work_evt *e; |
| 681 | |
| 682 | e = qla2x00_alloc_work(vha, QLA_EVT_PRLI); |
| 683 | if (!e) |
| 684 | return QLA_FUNCTION_FAILED; |
| 685 | |
| 686 | e->u.fcport.fcport = fcport; |
| 687 | |
| 688 | return qla2x00_post_work(vha, e); |
| 689 | } |
| 690 | |
| 691 | static void |
| 692 | qla2x00_async_prli_sp_done(void *ptr, int res) |
| 693 | { |
| 694 | srb_t *sp = ptr; |
| 695 | struct scsi_qla_host *vha = sp->vha; |
| 696 | struct srb_iocb *lio = &sp->u.iocb_cmd; |
| 697 | struct event_arg ea; |
| 698 | |
| 699 | ql_dbg(ql_dbg_disc, vha, 0x2129, |
| 700 | "%s %8phC res %d \n", __func__, |
| 701 | sp->fcport->port_name, res); |
| 702 | |
| 703 | sp->fcport->flags &= ~FCF_ASYNC_SENT; |
| 704 | |
| 705 | if (!test_bit(UNLOADING, &vha->dpc_flags)) { |
| 706 | memset(&ea, 0, sizeof(ea)); |
| 707 | ea.event = FCME_PRLI_DONE; |
| 708 | ea.fcport = sp->fcport; |
| 709 | ea.data[0] = lio->u.logio.data[0]; |
| 710 | ea.data[1] = lio->u.logio.data[1]; |
| 711 | ea.iop[0] = lio->u.logio.iop[0]; |
| 712 | ea.iop[1] = lio->u.logio.iop[1]; |
| 713 | ea.sp = sp; |
| 714 | |
| 715 | qla2x00_fcport_event_handler(vha, &ea); |
| 716 | } |
| 717 | |
| 718 | sp->free(sp); |
| 719 | } |
| 720 | |
| 721 | int |
| 722 | qla24xx_async_prli(struct scsi_qla_host *vha, fc_port_t *fcport) |
| 723 | { |
| 724 | srb_t *sp; |
| 725 | struct srb_iocb *lio; |
| 726 | int rval = QLA_FUNCTION_FAILED; |
| 727 | |
| 728 | if (!vha->flags.online) |
| 729 | return rval; |
| 730 | |
| 731 | if (fcport->fw_login_state == DSC_LS_PLOGI_PEND || |
| 732 | fcport->fw_login_state == DSC_LS_PLOGI_COMP || |
| 733 | fcport->fw_login_state == DSC_LS_PRLI_PEND) |
| 734 | return rval; |
| 735 | |
| 736 | sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); |
| 737 | if (!sp) |
| 738 | return rval; |
| 739 | |
| 740 | fcport->flags |= FCF_ASYNC_SENT; |
| 741 | fcport->logout_completed = 0; |
| 742 | |
| 743 | sp->type = SRB_PRLI_CMD; |
| 744 | sp->name = "prli"; |
| 745 | qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2); |
| 746 | |
| 747 | lio = &sp->u.iocb_cmd; |
| 748 | lio->timeout = qla2x00_async_iocb_timeout; |
| 749 | sp->done = qla2x00_async_prli_sp_done; |
| 750 | lio->u.logio.flags = 0; |
| 751 | |
| 752 | if (fcport->fc4f_nvme) |
| 753 | lio->u.logio.flags |= SRB_LOGIN_NVME_PRLI; |
| 754 | |
| 755 | rval = qla2x00_start_sp(sp); |
| 756 | if (rval != QLA_SUCCESS) { |
| 757 | fcport->flags &= ~FCF_ASYNC_SENT; |
| 758 | fcport->flags |= FCF_LOGIN_NEEDED; |
| 759 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
| 760 | goto done_free_sp; |
| 761 | } |
| 762 | |
| 763 | ql_dbg(ql_dbg_disc, vha, 0x211b, |
| 764 | "Async-prli - %8phC hdl=%x, loopid=%x portid=%06x retries=%d.\n", |
| 765 | fcport->port_name, sp->handle, fcport->loop_id, |
| 766 | fcport->d_id.b24, fcport->login_retry); |
| 767 | |
| 768 | return rval; |
| 769 | |
| 770 | done_free_sp: |
| 771 | sp->free(sp); |
| 772 | fcport->flags &= ~FCF_ASYNC_SENT; |
| 773 | return rval; |
| 774 | } |
| 775 | |
Quinn Tran | a07fc0a | 2017-08-23 15:05:21 -0700 | [diff] [blame] | 776 | 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] | 777 | { |
| 778 | struct qla_work_evt *e; |
| 779 | |
| 780 | e = qla2x00_alloc_work(vha, QLA_EVT_GPDB); |
| 781 | if (!e) |
| 782 | return QLA_FUNCTION_FAILED; |
| 783 | |
| 784 | e->u.fcport.fcport = fcport; |
| 785 | e->u.fcport.opt = opt; |
| 786 | return qla2x00_post_work(vha, e); |
| 787 | } |
| 788 | |
| 789 | int qla24xx_async_gpdb(struct scsi_qla_host *vha, fc_port_t *fcport, u8 opt) |
| 790 | { |
| 791 | srb_t *sp; |
| 792 | struct srb_iocb *mbx; |
| 793 | int rval = QLA_FUNCTION_FAILED; |
| 794 | u16 *mb; |
| 795 | dma_addr_t pd_dma; |
| 796 | struct port_database_24xx *pd; |
| 797 | struct qla_hw_data *ha = vha->hw; |
| 798 | |
| 799 | if (!vha->flags.online) |
| 800 | goto done; |
| 801 | |
| 802 | fcport->flags |= FCF_ASYNC_SENT; |
| 803 | fcport->disc_state = DSC_GPDB; |
| 804 | |
| 805 | sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); |
| 806 | if (!sp) |
| 807 | goto done; |
| 808 | |
Joe Carnuccio | e0824e6 | 2017-08-23 15:05:08 -0700 | [diff] [blame] | 809 | sp->type = SRB_MB_IOCB; |
| 810 | sp->name = "gpdb"; |
| 811 | sp->gen1 = fcport->rscn_gen; |
| 812 | sp->gen2 = fcport->login_gen; |
| 813 | qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2); |
| 814 | |
Thomas Meyer | 08eb7f4 | 2017-09-21 08:15:26 +0200 | [diff] [blame] | 815 | pd = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 816 | if (pd == NULL) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 817 | ql_log(ql_log_warn, vha, 0xd043, |
| 818 | "Failed to allocate port database structure.\n"); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 819 | goto done_free_sp; |
| 820 | } |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 821 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 822 | mb = sp->u.iocb_cmd.u.mbx.out_mb; |
| 823 | mb[0] = MBC_GET_PORT_DATABASE; |
| 824 | mb[1] = fcport->loop_id; |
| 825 | mb[2] = MSW(pd_dma); |
| 826 | mb[3] = LSW(pd_dma); |
| 827 | mb[6] = MSW(MSD(pd_dma)); |
| 828 | mb[7] = LSW(MSD(pd_dma)); |
| 829 | mb[9] = vha->vp_idx; |
| 830 | mb[10] = opt; |
| 831 | |
| 832 | mbx = &sp->u.iocb_cmd; |
| 833 | mbx->timeout = qla2x00_async_iocb_timeout; |
| 834 | mbx->u.mbx.in = (void *)pd; |
| 835 | mbx->u.mbx.in_dma = pd_dma; |
| 836 | |
| 837 | sp->done = qla24xx_async_gpdb_sp_done; |
| 838 | |
| 839 | rval = qla2x00_start_sp(sp); |
| 840 | if (rval != QLA_SUCCESS) |
| 841 | goto done_free_sp; |
| 842 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 843 | ql_dbg(ql_dbg_disc, vha, 0x20dc, |
| 844 | "Async-%s %8phC hndl %x opt %x\n", |
| 845 | sp->name, fcport->port_name, sp->handle, opt); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 846 | |
| 847 | return rval; |
| 848 | |
| 849 | done_free_sp: |
| 850 | if (pd) |
| 851 | dma_pool_free(ha->s_dma_pool, pd, pd_dma); |
| 852 | |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 853 | sp->free(sp); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 854 | done: |
| 855 | fcport->flags &= ~FCF_ASYNC_SENT; |
| 856 | qla24xx_post_gpdb_work(vha, fcport, opt); |
| 857 | return rval; |
| 858 | } |
| 859 | |
| 860 | static |
| 861 | void qla24xx_handle_gpdb_event(scsi_qla_host_t *vha, struct event_arg *ea) |
| 862 | { |
| 863 | int rval = ea->rc; |
| 864 | fc_port_t *fcport = ea->fcport; |
| 865 | unsigned long flags; |
Quinn Tran | 414d9ff | 2017-12-04 14:45:03 -0800 | [diff] [blame] | 866 | u16 opt = ea->sp->u.iocb_cmd.u.mbx.out_mb[10]; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 867 | |
| 868 | fcport->flags &= ~FCF_ASYNC_SENT; |
| 869 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 870 | ql_dbg(ql_dbg_disc, vha, 0x20d2, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 871 | "%s %8phC DS %d LS %d rval %d\n", __func__, fcport->port_name, |
| 872 | fcport->disc_state, fcport->fw_login_state, rval); |
| 873 | |
| 874 | if (ea->sp->gen2 != fcport->login_gen) { |
| 875 | /* target side must have changed it. */ |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 876 | ql_dbg(ql_dbg_disc, vha, 0x20d3, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 877 | "%s %8phC generation changed rscn %d|%d login %d|%d \n", |
| 878 | __func__, fcport->port_name, fcport->last_rscn_gen, |
| 879 | fcport->rscn_gen, fcport->last_login_gen, |
| 880 | fcport->login_gen); |
| 881 | return; |
| 882 | } else if (ea->sp->gen1 != fcport->rscn_gen) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 883 | ql_dbg(ql_dbg_disc, vha, 0x20d4, "%s %d %8phC post gidpn\n", |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 884 | __func__, __LINE__, fcport->port_name); |
| 885 | qla24xx_post_gidpn_work(vha, fcport); |
| 886 | return; |
| 887 | } |
| 888 | |
| 889 | if (rval != QLA_SUCCESS) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 890 | ql_dbg(ql_dbg_disc, vha, 0x20d5, "%s %d %8phC post del sess\n", |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 891 | __func__, __LINE__, fcport->port_name); |
| 892 | qlt_schedule_sess_for_deletion_lock(fcport); |
| 893 | return; |
| 894 | } |
| 895 | |
| 896 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
Quinn Tran | 414d9ff | 2017-12-04 14:45:03 -0800 | [diff] [blame] | 897 | if (opt != PDO_FORCE_ADISC) |
| 898 | ea->fcport->login_gen++; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 899 | ea->fcport->deleted = 0; |
| 900 | ea->fcport->logout_on_delete = 1; |
| 901 | |
| 902 | if (!ea->fcport->login_succ && !IS_SW_RESV_ADDR(ea->fcport->d_id)) { |
| 903 | vha->fcport_count++; |
| 904 | ea->fcport->login_succ = 1; |
| 905 | |
| 906 | if (!IS_IIDMA_CAPABLE(vha->hw) || |
| 907 | !vha->hw->flags.gpsc_supported) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 908 | ql_dbg(ql_dbg_disc, vha, 0x20d6, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 909 | "%s %d %8phC post upd_fcport fcp_cnt %d\n", |
| 910 | __func__, __LINE__, fcport->port_name, |
| 911 | vha->fcport_count); |
| 912 | |
| 913 | qla24xx_post_upd_fcport_work(vha, fcport); |
| 914 | } else { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 915 | ql_dbg(ql_dbg_disc, vha, 0x20d7, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 916 | "%s %d %8phC post gpsc fcp_cnt %d\n", |
| 917 | __func__, __LINE__, fcport->port_name, |
| 918 | vha->fcport_count); |
| 919 | |
| 920 | qla24xx_post_gpsc_work(vha, fcport); |
| 921 | } |
Quinn Tran | 414d9ff | 2017-12-04 14:45:03 -0800 | [diff] [blame] | 922 | } else if (ea->fcport->login_succ) { |
| 923 | /* |
| 924 | * We have an existing session. A late RSCN delivery |
| 925 | * must have triggered the session to be re-validate. |
| 926 | * session is still valid. |
| 927 | */ |
Quinn Tran | 5ef696a | 2017-12-04 14:45:05 -0800 | [diff] [blame] | 928 | ql_dbg(ql_dbg_disc, vha, 0x20d6, |
| 929 | "%s %d %8phC session revalidate success\n", |
| 930 | __func__, __LINE__, fcport->port_name); |
Quinn Tran | 414d9ff | 2017-12-04 14:45:03 -0800 | [diff] [blame] | 931 | fcport->disc_state = DSC_LOGIN_COMPLETE; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 932 | } |
| 933 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
| 934 | } /* gpdb event */ |
| 935 | |
| 936 | int qla24xx_fcport_handle_login(struct scsi_qla_host *vha, fc_port_t *fcport) |
| 937 | { |
| 938 | if (fcport->login_retry == 0) |
| 939 | return 0; |
| 940 | |
| 941 | if (fcport->scan_state != QLA_FCPORT_FOUND) |
| 942 | return 0; |
| 943 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 944 | ql_dbg(ql_dbg_disc, vha, 0x20d8, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 945 | "%s %8phC DS %d LS %d P %d fl %x confl %p rscn %d|%d login %d|%d retry %d lid %d\n", |
| 946 | __func__, fcport->port_name, fcport->disc_state, |
| 947 | fcport->fw_login_state, fcport->login_pause, fcport->flags, |
| 948 | fcport->conflict, fcport->last_rscn_gen, fcport->rscn_gen, |
| 949 | fcport->last_login_gen, fcport->login_gen, fcport->login_retry, |
| 950 | fcport->loop_id); |
| 951 | |
| 952 | fcport->login_retry--; |
| 953 | |
| 954 | if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) || |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 955 | (fcport->fw_login_state == DSC_LS_PRLI_PEND)) |
| 956 | return 0; |
| 957 | |
Quinn Tran | 5b33469 | 2017-03-15 09:48:48 -0700 | [diff] [blame] | 958 | if (fcport->fw_login_state == DSC_LS_PLOGI_COMP) { |
| 959 | if (time_before_eq(jiffies, fcport->plogi_nack_done_deadline)) |
| 960 | return 0; |
| 961 | } |
| 962 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 963 | /* for pure Target Mode. Login will not be initiated */ |
| 964 | if (vha->host->active_mode == MODE_TARGET) |
| 965 | return 0; |
| 966 | |
| 967 | if (fcport->flags & FCF_ASYNC_SENT) { |
| 968 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
| 969 | return 0; |
| 970 | } |
| 971 | |
| 972 | switch (fcport->disc_state) { |
| 973 | case DSC_DELETED: |
| 974 | if (fcport->loop_id == FC_NO_LOOP_ID) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 975 | ql_dbg(ql_dbg_disc, vha, 0x20bd, |
| 976 | "%s %d %8phC post gnl\n", |
| 977 | __func__, __LINE__, fcport->port_name); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 978 | qla24xx_async_gnl(vha, fcport); |
| 979 | } else { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 980 | ql_dbg(ql_dbg_disc, vha, 0x20bf, |
| 981 | "%s %d %8phC post login\n", |
| 982 | __func__, __LINE__, fcport->port_name); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 983 | fcport->disc_state = DSC_LOGIN_PEND; |
| 984 | qla2x00_post_async_login_work(vha, fcport, NULL); |
| 985 | } |
| 986 | break; |
| 987 | |
| 988 | case DSC_GNL: |
| 989 | if (fcport->login_pause) { |
| 990 | fcport->last_rscn_gen = fcport->rscn_gen; |
| 991 | fcport->last_login_gen = fcport->login_gen; |
| 992 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
| 993 | break; |
| 994 | } |
| 995 | |
| 996 | if (fcport->flags & FCF_FCP2_DEVICE) { |
| 997 | u8 opt = PDO_FORCE_ADISC; |
| 998 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 999 | ql_dbg(ql_dbg_disc, vha, 0x20c9, |
| 1000 | "%s %d %8phC post gpdb\n", |
| 1001 | __func__, __LINE__, fcport->port_name); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1002 | |
| 1003 | fcport->disc_state = DSC_GPDB; |
| 1004 | qla24xx_post_gpdb_work(vha, fcport, opt); |
| 1005 | } else { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1006 | ql_dbg(ql_dbg_disc, vha, 0x20cf, |
| 1007 | "%s %d %8phC post login\n", |
| 1008 | __func__, __LINE__, fcport->port_name); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1009 | fcport->disc_state = DSC_LOGIN_PEND; |
| 1010 | qla2x00_post_async_login_work(vha, fcport, NULL); |
| 1011 | } |
| 1012 | |
| 1013 | break; |
| 1014 | |
| 1015 | case DSC_LOGIN_FAILED: |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1016 | ql_dbg(ql_dbg_disc, vha, 0x20d0, |
| 1017 | "%s %d %8phC post gidpn\n", |
| 1018 | __func__, __LINE__, fcport->port_name); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1019 | |
| 1020 | qla24xx_post_gidpn_work(vha, fcport); |
| 1021 | break; |
| 1022 | |
| 1023 | case DSC_LOGIN_COMPLETE: |
| 1024 | /* recheck login state */ |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1025 | ql_dbg(ql_dbg_disc, vha, 0x20d1, |
| 1026 | "%s %d %8phC post gpdb\n", |
| 1027 | __func__, __LINE__, fcport->port_name); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1028 | |
| 1029 | qla24xx_post_gpdb_work(vha, fcport, PDO_FORCE_ADISC); |
| 1030 | break; |
| 1031 | |
| 1032 | default: |
| 1033 | break; |
| 1034 | } |
| 1035 | |
| 1036 | return 0; |
| 1037 | } |
| 1038 | |
| 1039 | static |
| 1040 | void qla24xx_handle_rscn_event(fc_port_t *fcport, struct event_arg *ea) |
| 1041 | { |
| 1042 | fcport->rscn_gen++; |
| 1043 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1044 | ql_dbg(ql_dbg_disc, fcport->vha, 0x210c, |
| 1045 | "%s %8phC DS %d LS %d\n", |
| 1046 | __func__, fcport->port_name, fcport->disc_state, |
| 1047 | fcport->fw_login_state); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1048 | |
| 1049 | if (fcport->flags & FCF_ASYNC_SENT) |
| 1050 | return; |
| 1051 | |
| 1052 | switch (fcport->disc_state) { |
| 1053 | case DSC_DELETED: |
| 1054 | case DSC_LOGIN_COMPLETE: |
Quinn Tran | 5ef696a | 2017-12-04 14:45:05 -0800 | [diff] [blame] | 1055 | qla24xx_post_gpnid_work(fcport->vha, &ea->id); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1056 | break; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1057 | default: |
| 1058 | break; |
| 1059 | } |
| 1060 | } |
| 1061 | |
| 1062 | int qla24xx_post_newsess_work(struct scsi_qla_host *vha, port_id_t *id, |
| 1063 | u8 *port_name, void *pla) |
| 1064 | { |
| 1065 | struct qla_work_evt *e; |
| 1066 | e = qla2x00_alloc_work(vha, QLA_EVT_NEW_SESS); |
| 1067 | if (!e) |
| 1068 | return QLA_FUNCTION_FAILED; |
| 1069 | |
| 1070 | e->u.new_sess.id = *id; |
| 1071 | e->u.new_sess.pla = pla; |
| 1072 | memcpy(e->u.new_sess.port_name, port_name, WWN_SIZE); |
| 1073 | |
| 1074 | return qla2x00_post_work(vha, e); |
| 1075 | } |
| 1076 | |
| 1077 | static |
| 1078 | int qla24xx_handle_delete_done_event(scsi_qla_host_t *vha, |
| 1079 | struct event_arg *ea) |
| 1080 | { |
| 1081 | fc_port_t *fcport = ea->fcport; |
| 1082 | |
| 1083 | if (test_bit(UNLOADING, &vha->dpc_flags)) |
| 1084 | return 0; |
| 1085 | |
| 1086 | switch (vha->host->active_mode) { |
| 1087 | case MODE_INITIATOR: |
| 1088 | case MODE_DUAL: |
| 1089 | if (fcport->scan_state == QLA_FCPORT_FOUND) |
| 1090 | qla24xx_fcport_handle_login(vha, fcport); |
| 1091 | break; |
| 1092 | |
| 1093 | case MODE_TARGET: |
| 1094 | default: |
| 1095 | /* no-op */ |
| 1096 | break; |
| 1097 | } |
| 1098 | |
| 1099 | return 0; |
| 1100 | } |
| 1101 | |
| 1102 | static |
| 1103 | void qla24xx_handle_relogin_event(scsi_qla_host_t *vha, |
| 1104 | struct event_arg *ea) |
| 1105 | { |
| 1106 | fc_port_t *fcport = ea->fcport; |
| 1107 | |
| 1108 | if (fcport->scan_state != QLA_FCPORT_FOUND) { |
| 1109 | fcport->login_retry++; |
| 1110 | return; |
| 1111 | } |
| 1112 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1113 | ql_dbg(ql_dbg_disc, vha, 0x2102, |
| 1114 | "%s %8phC DS %d LS %d P %d del %d cnfl %p rscn %d|%d login %d|%d fl %x\n", |
| 1115 | __func__, fcport->port_name, fcport->disc_state, |
| 1116 | fcport->fw_login_state, fcport->login_pause, |
| 1117 | fcport->deleted, fcport->conflict, |
| 1118 | fcport->last_rscn_gen, fcport->rscn_gen, |
| 1119 | fcport->last_login_gen, fcport->login_gen, |
| 1120 | fcport->flags); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1121 | |
| 1122 | if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) || |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1123 | (fcport->fw_login_state == DSC_LS_PRLI_PEND)) |
| 1124 | return; |
| 1125 | |
Quinn Tran | 5b33469 | 2017-03-15 09:48:48 -0700 | [diff] [blame] | 1126 | if (fcport->fw_login_state == DSC_LS_PLOGI_COMP) { |
| 1127 | if (time_before_eq(jiffies, fcport->plogi_nack_done_deadline)) |
| 1128 | return; |
| 1129 | } |
| 1130 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1131 | if (fcport->flags & FCF_ASYNC_SENT) { |
| 1132 | fcport->login_retry++; |
| 1133 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
| 1134 | return; |
| 1135 | } |
| 1136 | |
| 1137 | if (fcport->disc_state == DSC_DELETE_PEND) { |
| 1138 | fcport->login_retry++; |
| 1139 | return; |
| 1140 | } |
| 1141 | |
| 1142 | if (fcport->last_rscn_gen != fcport->rscn_gen) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1143 | 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] | 1144 | __func__, __LINE__, fcport->port_name); |
| 1145 | |
| 1146 | qla24xx_async_gidpn(vha, fcport); |
| 1147 | return; |
| 1148 | } |
| 1149 | |
| 1150 | qla24xx_fcport_handle_login(vha, fcport); |
| 1151 | } |
| 1152 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 1153 | 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] | 1154 | { |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 1155 | fc_port_t *fcport, *f, *tf; |
| 1156 | uint32_t id = 0, mask, rid; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1157 | int rc; |
| 1158 | |
| 1159 | switch (ea->event) { |
| 1160 | case FCME_RELOGIN: |
Quinn Tran | b98ae0d | 2017-06-02 09:12:00 -0700 | [diff] [blame] | 1161 | case FCME_RSCN: |
| 1162 | case FCME_GIDPN_DONE: |
| 1163 | case FCME_GPSC_DONE: |
| 1164 | case FCME_GPNID_DONE: |
| 1165 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) || |
| 1166 | test_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags)) |
| 1167 | return; |
| 1168 | break; |
| 1169 | default: |
| 1170 | break; |
| 1171 | } |
| 1172 | |
| 1173 | switch (ea->event) { |
| 1174 | case FCME_RELOGIN: |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1175 | if (test_bit(UNLOADING, &vha->dpc_flags)) |
| 1176 | return; |
| 1177 | |
| 1178 | qla24xx_handle_relogin_event(vha, ea); |
| 1179 | break; |
| 1180 | case FCME_RSCN: |
| 1181 | if (test_bit(UNLOADING, &vha->dpc_flags)) |
| 1182 | return; |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 1183 | switch (ea->id.b.rsvd_1) { |
| 1184 | case RSCN_PORT_ADDR: |
| 1185 | fcport = qla2x00_find_fcport_by_nportid(vha, &ea->id, 1); |
| 1186 | if (!fcport) { |
| 1187 | /* cable moved */ |
| 1188 | rc = qla24xx_post_gpnid_work(vha, &ea->id); |
| 1189 | if (rc) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1190 | ql_log(ql_log_warn, vha, 0xd044, |
| 1191 | "RSCN GPNID work failed %02x%02x%02x\n", |
| 1192 | ea->id.b.domain, ea->id.b.area, |
| 1193 | ea->id.b.al_pa); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 1194 | } |
| 1195 | } else { |
| 1196 | ea->fcport = fcport; |
| 1197 | qla24xx_handle_rscn_event(fcport, ea); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1198 | } |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 1199 | break; |
| 1200 | case RSCN_AREA_ADDR: |
| 1201 | case RSCN_DOM_ADDR: |
| 1202 | if (ea->id.b.rsvd_1 == RSCN_AREA_ADDR) { |
| 1203 | mask = 0xffff00; |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1204 | ql_dbg(ql_dbg_async, vha, 0x5044, |
| 1205 | "RSCN: Area 0x%06x was affected\n", |
| 1206 | ea->id.b24); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 1207 | } else { |
| 1208 | mask = 0xff0000; |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1209 | ql_dbg(ql_dbg_async, vha, 0x507a, |
| 1210 | "RSCN: Domain 0x%06x was affected\n", |
| 1211 | ea->id.b24); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 1212 | } |
| 1213 | |
| 1214 | rid = ea->id.b24 & mask; |
| 1215 | list_for_each_entry_safe(f, tf, &vha->vp_fcports, |
| 1216 | list) { |
| 1217 | id = f->d_id.b24 & mask; |
| 1218 | if (rid == id) { |
| 1219 | ea->fcport = f; |
| 1220 | qla24xx_handle_rscn_event(f, ea); |
| 1221 | } |
| 1222 | } |
| 1223 | break; |
| 1224 | case RSCN_FAB_ADDR: |
| 1225 | default: |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1226 | ql_log(ql_log_warn, vha, 0xd045, |
| 1227 | "RSCN: Fabric was affected. Addr format %d\n", |
| 1228 | ea->id.b.rsvd_1); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 1229 | qla2x00_mark_all_devices_lost(vha, 1); |
| 1230 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
| 1231 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1232 | } |
| 1233 | break; |
| 1234 | case FCME_GIDPN_DONE: |
| 1235 | qla24xx_handle_gidpn_event(vha, ea); |
| 1236 | break; |
| 1237 | case FCME_GNL_DONE: |
| 1238 | qla24xx_handle_gnl_done_event(vha, ea); |
| 1239 | break; |
| 1240 | case FCME_GPSC_DONE: |
| 1241 | qla24xx_post_upd_fcport_work(vha, ea->fcport); |
| 1242 | break; |
| 1243 | case FCME_PLOGI_DONE: /* Initiator side sent LLIOCB */ |
| 1244 | qla24xx_handle_plogi_done_event(vha, ea); |
| 1245 | break; |
Duane Grigsby | a5d42f4 | 2017-06-21 13:48:41 -0700 | [diff] [blame] | 1246 | case FCME_PRLI_DONE: |
| 1247 | qla24xx_handle_prli_done_event(vha, ea); |
| 1248 | break; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1249 | case FCME_GPDB_DONE: |
| 1250 | qla24xx_handle_gpdb_event(vha, ea); |
| 1251 | break; |
| 1252 | case FCME_GPNID_DONE: |
| 1253 | qla24xx_handle_gpnid_event(vha, ea); |
| 1254 | break; |
Duane Grigsby | d3bae93 | 2017-06-21 13:48:44 -0700 | [diff] [blame] | 1255 | case FCME_GFFID_DONE: |
| 1256 | qla24xx_handle_gffid_event(vha, ea); |
| 1257 | break; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1258 | case FCME_DELETE_DONE: |
| 1259 | qla24xx_handle_delete_done_event(vha, ea); |
| 1260 | break; |
| 1261 | default: |
| 1262 | BUG_ON(1); |
| 1263 | break; |
| 1264 | } |
| 1265 | } |
| 1266 | |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 1267 | static void |
Armen Baloyan | faef62d | 2014-02-26 04:15:17 -0500 | [diff] [blame] | 1268 | qla2x00_tmf_iocb_timeout(void *data) |
| 1269 | { |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 1270 | srb_t *sp = data; |
Armen Baloyan | faef62d | 2014-02-26 04:15:17 -0500 | [diff] [blame] | 1271 | struct srb_iocb *tmf = &sp->u.iocb_cmd; |
| 1272 | |
| 1273 | tmf->u.tmf.comp_status = CS_TIMEOUT; |
| 1274 | complete(&tmf->u.tmf.comp); |
| 1275 | } |
| 1276 | |
| 1277 | static void |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 1278 | qla2x00_tmf_sp_done(void *ptr, int res) |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 1279 | { |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 1280 | srb_t *sp = ptr; |
Armen Baloyan | faef62d | 2014-02-26 04:15:17 -0500 | [diff] [blame] | 1281 | struct srb_iocb *tmf = &sp->u.iocb_cmd; |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 1282 | |
Armen Baloyan | faef62d | 2014-02-26 04:15:17 -0500 | [diff] [blame] | 1283 | complete(&tmf->u.tmf.comp); |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 1284 | } |
| 1285 | |
| 1286 | int |
Armen Baloyan | faef62d | 2014-02-26 04:15:17 -0500 | [diff] [blame] | 1287 | 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] | 1288 | uint32_t tag) |
| 1289 | { |
| 1290 | struct scsi_qla_host *vha = fcport->vha; |
Armen Baloyan | faef62d | 2014-02-26 04:15:17 -0500 | [diff] [blame] | 1291 | struct srb_iocb *tm_iocb; |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 1292 | srb_t *sp; |
Armen Baloyan | faef62d | 2014-02-26 04:15:17 -0500 | [diff] [blame] | 1293 | int rval = QLA_FUNCTION_FAILED; |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 1294 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 1295 | sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 1296 | if (!sp) |
| 1297 | goto done; |
| 1298 | |
Armen Baloyan | faef62d | 2014-02-26 04:15:17 -0500 | [diff] [blame] | 1299 | tm_iocb = &sp->u.iocb_cmd; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 1300 | sp->type = SRB_TM_CMD; |
| 1301 | sp->name = "tmf"; |
Armen Baloyan | faef62d | 2014-02-26 04:15:17 -0500 | [diff] [blame] | 1302 | qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha)); |
| 1303 | tm_iocb->u.tmf.flags = flags; |
| 1304 | tm_iocb->u.tmf.lun = lun; |
| 1305 | tm_iocb->u.tmf.data = tag; |
| 1306 | sp->done = qla2x00_tmf_sp_done; |
| 1307 | tm_iocb->timeout = qla2x00_tmf_iocb_timeout; |
| 1308 | init_completion(&tm_iocb->u.tmf.comp); |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 1309 | |
| 1310 | rval = qla2x00_start_sp(sp); |
| 1311 | if (rval != QLA_SUCCESS) |
| 1312 | goto done_free_sp; |
| 1313 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1314 | ql_dbg(ql_dbg_taskm, vha, 0x802f, |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 1315 | "Async-tmf hdl=%x loop-id=%x portid=%02x%02x%02x.\n", |
| 1316 | sp->handle, fcport->loop_id, fcport->d_id.b.domain, |
| 1317 | fcport->d_id.b.area, fcport->d_id.b.al_pa); |
Armen Baloyan | faef62d | 2014-02-26 04:15:17 -0500 | [diff] [blame] | 1318 | |
| 1319 | wait_for_completion(&tm_iocb->u.tmf.comp); |
| 1320 | |
| 1321 | rval = tm_iocb->u.tmf.comp_status == CS_COMPLETE ? |
| 1322 | QLA_SUCCESS : QLA_FUNCTION_FAILED; |
| 1323 | |
| 1324 | if ((rval != QLA_SUCCESS) || tm_iocb->u.tmf.data) { |
| 1325 | ql_dbg(ql_dbg_taskm, vha, 0x8030, |
| 1326 | "TM IOCB failed (%x).\n", rval); |
| 1327 | } |
| 1328 | |
| 1329 | if (!test_bit(UNLOADING, &vha->dpc_flags) && !IS_QLAFX00(vha->hw)) { |
| 1330 | flags = tm_iocb->u.tmf.flags; |
| 1331 | lun = (uint16_t)tm_iocb->u.tmf.lun; |
| 1332 | |
| 1333 | /* Issue Marker IOCB */ |
| 1334 | qla2x00_marker(vha, vha->hw->req_q_map[0], |
| 1335 | vha->hw->rsp_q_map[0], sp->fcport->loop_id, lun, |
| 1336 | flags == TCF_LUN_RESET ? MK_SYNC_ID_LUN : MK_SYNC_ID); |
| 1337 | } |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 1338 | |
| 1339 | done_free_sp: |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 1340 | sp->free(sp); |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 1341 | done: |
| 1342 | return rval; |
| 1343 | } |
| 1344 | |
Armen Baloyan | 4440e46 | 2014-02-26 04:15:18 -0500 | [diff] [blame] | 1345 | static void |
| 1346 | qla24xx_abort_iocb_timeout(void *data) |
| 1347 | { |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 1348 | srb_t *sp = data; |
Armen Baloyan | 4440e46 | 2014-02-26 04:15:18 -0500 | [diff] [blame] | 1349 | struct srb_iocb *abt = &sp->u.iocb_cmd; |
| 1350 | |
| 1351 | abt->u.abt.comp_status = CS_TIMEOUT; |
| 1352 | complete(&abt->u.abt.comp); |
| 1353 | } |
| 1354 | |
| 1355 | static void |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 1356 | qla24xx_abort_sp_done(void *ptr, int res) |
Armen Baloyan | 4440e46 | 2014-02-26 04:15:18 -0500 | [diff] [blame] | 1357 | { |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 1358 | srb_t *sp = ptr; |
Armen Baloyan | 4440e46 | 2014-02-26 04:15:18 -0500 | [diff] [blame] | 1359 | struct srb_iocb *abt = &sp->u.iocb_cmd; |
| 1360 | |
| 1361 | complete(&abt->u.abt.comp); |
| 1362 | } |
| 1363 | |
Quinn Tran | 15f30a5 | 2017-03-15 09:48:52 -0700 | [diff] [blame] | 1364 | int |
Armen Baloyan | 4440e46 | 2014-02-26 04:15:18 -0500 | [diff] [blame] | 1365 | qla24xx_async_abort_cmd(srb_t *cmd_sp) |
| 1366 | { |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 1367 | scsi_qla_host_t *vha = cmd_sp->vha; |
Armen Baloyan | 4440e46 | 2014-02-26 04:15:18 -0500 | [diff] [blame] | 1368 | fc_port_t *fcport = cmd_sp->fcport; |
| 1369 | struct srb_iocb *abt_iocb; |
| 1370 | srb_t *sp; |
| 1371 | int rval = QLA_FUNCTION_FAILED; |
| 1372 | |
| 1373 | sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); |
| 1374 | if (!sp) |
| 1375 | goto done; |
| 1376 | |
| 1377 | abt_iocb = &sp->u.iocb_cmd; |
| 1378 | sp->type = SRB_ABT_CMD; |
| 1379 | sp->name = "abort"; |
| 1380 | qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha)); |
| 1381 | abt_iocb->u.abt.cmd_hndl = cmd_sp->handle; |
| 1382 | sp->done = qla24xx_abort_sp_done; |
| 1383 | abt_iocb->timeout = qla24xx_abort_iocb_timeout; |
| 1384 | init_completion(&abt_iocb->u.abt.comp); |
| 1385 | |
| 1386 | rval = qla2x00_start_sp(sp); |
| 1387 | if (rval != QLA_SUCCESS) |
| 1388 | goto done_free_sp; |
| 1389 | |
| 1390 | ql_dbg(ql_dbg_async, vha, 0x507c, |
| 1391 | "Abort command issued - hdl=%x, target_id=%x\n", |
| 1392 | cmd_sp->handle, fcport->tgt_id); |
| 1393 | |
| 1394 | wait_for_completion(&abt_iocb->u.abt.comp); |
| 1395 | |
| 1396 | rval = abt_iocb->u.abt.comp_status == CS_COMPLETE ? |
| 1397 | QLA_SUCCESS : QLA_FUNCTION_FAILED; |
| 1398 | |
| 1399 | done_free_sp: |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 1400 | sp->free(sp); |
Armen Baloyan | 4440e46 | 2014-02-26 04:15:18 -0500 | [diff] [blame] | 1401 | done: |
| 1402 | return rval; |
| 1403 | } |
| 1404 | |
| 1405 | int |
| 1406 | qla24xx_async_abort_command(srb_t *sp) |
| 1407 | { |
| 1408 | unsigned long flags = 0; |
| 1409 | |
| 1410 | uint32_t handle; |
| 1411 | fc_port_t *fcport = sp->fcport; |
| 1412 | struct scsi_qla_host *vha = fcport->vha; |
| 1413 | struct qla_hw_data *ha = vha->hw; |
| 1414 | struct req_que *req = vha->req; |
| 1415 | |
| 1416 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1417 | for (handle = 1; handle < req->num_outstanding_cmds; handle++) { |
| 1418 | if (req->outstanding_cmds[handle] == sp) |
| 1419 | break; |
| 1420 | } |
| 1421 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1422 | if (handle == req->num_outstanding_cmds) { |
| 1423 | /* Command not found. */ |
| 1424 | return QLA_FUNCTION_FAILED; |
| 1425 | } |
| 1426 | if (sp->type == SRB_FXIOCB_DCMD) |
| 1427 | return qlafx00_fx_disc(vha, &vha->hw->mr.fcport, |
| 1428 | FXDISC_ABORT_IOCTL); |
| 1429 | |
| 1430 | return qla24xx_async_abort_cmd(sp); |
| 1431 | } |
| 1432 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1433 | static void |
Duane Grigsby | a5d42f4 | 2017-06-21 13:48:41 -0700 | [diff] [blame] | 1434 | qla24xx_handle_prli_done_event(struct scsi_qla_host *vha, struct event_arg *ea) |
| 1435 | { |
| 1436 | switch (ea->data[0]) { |
| 1437 | case MBS_COMMAND_COMPLETE: |
| 1438 | ql_dbg(ql_dbg_disc, vha, 0x2118, |
| 1439 | "%s %d %8phC post gpdb\n", |
| 1440 | __func__, __LINE__, ea->fcport->port_name); |
| 1441 | |
| 1442 | ea->fcport->chip_reset = vha->hw->base_qpair->chip_reset; |
| 1443 | ea->fcport->logout_on_delete = 1; |
| 1444 | qla24xx_post_gpdb_work(vha, ea->fcport, 0); |
| 1445 | break; |
| 1446 | default: |
Duane Grigsby | edd05de | 2017-10-13 09:34:06 -0700 | [diff] [blame] | 1447 | if (ea->fcport->n2n_flag) { |
| 1448 | ql_dbg(ql_dbg_disc, vha, 0x2118, |
| 1449 | "%s %d %8phC post fc4 prli\n", |
| 1450 | __func__, __LINE__, ea->fcport->port_name); |
| 1451 | ea->fcport->fc4f_nvme = 0; |
| 1452 | ea->fcport->n2n_flag = 0; |
| 1453 | qla24xx_post_prli_work(vha, ea->fcport); |
| 1454 | } |
Duane Grigsby | a5d42f4 | 2017-06-21 13:48:41 -0700 | [diff] [blame] | 1455 | ql_dbg(ql_dbg_disc, vha, 0x2119, |
| 1456 | "%s %d %8phC unhandle event of %x\n", |
| 1457 | __func__, __LINE__, ea->fcport->port_name, ea->data[0]); |
| 1458 | break; |
| 1459 | } |
| 1460 | } |
| 1461 | |
| 1462 | static void |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1463 | 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] | 1464 | { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1465 | port_id_t cid; /* conflict Nport id */ |
Quinn Tran | a084fd6 | 2017-12-04 14:45:00 -0800 | [diff] [blame] | 1466 | u16 lid; |
| 1467 | struct fc_port *conflict_fcport; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1468 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1469 | switch (ea->data[0]) { |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1470 | case MBS_COMMAND_COMPLETE: |
Andrew Vasquez | a4f92a3 | 2011-03-30 11:46:31 -0700 | [diff] [blame] | 1471 | /* |
| 1472 | * Driver must validate login state - If PRLI not complete, |
| 1473 | * force a relogin attempt via implicit LOGO, PLOGI, and PRLI |
| 1474 | * requests. |
| 1475 | */ |
Duane Grigsby | a5d42f4 | 2017-06-21 13:48:41 -0700 | [diff] [blame] | 1476 | if (ea->fcport->fc4f_nvme) { |
| 1477 | ql_dbg(ql_dbg_disc, vha, 0x2117, |
| 1478 | "%s %d %8phC post prli\n", |
| 1479 | __func__, __LINE__, ea->fcport->port_name); |
| 1480 | qla24xx_post_prli_work(vha, ea->fcport); |
| 1481 | } else { |
| 1482 | ql_dbg(ql_dbg_disc, vha, 0x20ea, |
Quinn Tran | a084fd6 | 2017-12-04 14:45:00 -0800 | [diff] [blame] | 1483 | "%s %d %8phC LoopID 0x%x in use with %06x. post gnl\n", |
| 1484 | __func__, __LINE__, ea->fcport->port_name, |
| 1485 | ea->fcport->loop_id, ea->fcport->d_id.b24); |
| 1486 | |
| 1487 | set_bit(ea->fcport->loop_id, vha->hw->loop_id_map); |
| 1488 | ea->fcport->loop_id = FC_NO_LOOP_ID; |
Duane Grigsby | a5d42f4 | 2017-06-21 13:48:41 -0700 | [diff] [blame] | 1489 | ea->fcport->chip_reset = vha->hw->base_qpair->chip_reset; |
| 1490 | ea->fcport->logout_on_delete = 1; |
Quinn Tran | 3515832 | 2017-08-30 10:16:50 -0700 | [diff] [blame] | 1491 | ea->fcport->send_els_logo = 0; |
Duane Grigsby | a5d42f4 | 2017-06-21 13:48:41 -0700 | [diff] [blame] | 1492 | qla24xx_post_gpdb_work(vha, ea->fcport, 0); |
| 1493 | } |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1494 | break; |
| 1495 | case MBS_COMMAND_ERROR: |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1496 | 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] | 1497 | __func__, __LINE__, ea->fcport->port_name, ea->data[1]); |
| 1498 | |
| 1499 | ea->fcport->flags &= ~FCF_ASYNC_SENT; |
| 1500 | ea->fcport->disc_state = DSC_LOGIN_FAILED; |
| 1501 | if (ea->data[1] & QLA_LOGIO_LOGIN_RETRIED) |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1502 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
| 1503 | else |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1504 | qla2x00_mark_device_lost(vha, ea->fcport, 1, 0); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1505 | break; |
| 1506 | case MBS_LOOP_ID_USED: |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1507 | /* data[1] = IO PARAM 1 = nport ID */ |
| 1508 | cid.b.domain = (ea->iop[1] >> 16) & 0xff; |
| 1509 | cid.b.area = (ea->iop[1] >> 8) & 0xff; |
| 1510 | cid.b.al_pa = ea->iop[1] & 0xff; |
| 1511 | cid.b.rsvd_1 = 0; |
| 1512 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1513 | ql_dbg(ql_dbg_disc, vha, 0x20ec, |
| 1514 | "%s %d %8phC LoopID 0x%x in use post gnl\n", |
| 1515 | __func__, __LINE__, ea->fcport->port_name, |
| 1516 | ea->fcport->loop_id); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1517 | |
| 1518 | if (IS_SW_RESV_ADDR(cid)) { |
| 1519 | set_bit(ea->fcport->loop_id, vha->hw->loop_id_map); |
| 1520 | ea->fcport->loop_id = FC_NO_LOOP_ID; |
| 1521 | } else { |
| 1522 | qla2x00_clear_loop_id(ea->fcport); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1523 | } |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1524 | qla24xx_post_gnl_work(vha, ea->fcport); |
| 1525 | break; |
| 1526 | case MBS_PORT_ID_USED: |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1527 | ql_dbg(ql_dbg_disc, vha, 0x20ed, |
| 1528 | "%s %d %8phC NPortId %02x%02x%02x inuse post gidpn\n", |
| 1529 | __func__, __LINE__, ea->fcport->port_name, |
| 1530 | ea->fcport->d_id.b.domain, ea->fcport->d_id.b.area, |
| 1531 | ea->fcport->d_id.b.al_pa); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1532 | |
Quinn Tran | a084fd6 | 2017-12-04 14:45:00 -0800 | [diff] [blame] | 1533 | lid = ea->iop[1] & 0xffff; |
| 1534 | qlt_find_sess_invalidate_other(vha, |
| 1535 | wwn_to_u64(ea->fcport->port_name), |
| 1536 | ea->fcport->d_id, lid, &conflict_fcport); |
| 1537 | |
| 1538 | if (conflict_fcport) { |
| 1539 | /* |
| 1540 | * Another fcport share the same loop_id/nport id. |
| 1541 | * Conflict fcport needs to finish cleanup before this |
| 1542 | * fcport can proceed to login. |
| 1543 | */ |
| 1544 | conflict_fcport->conflict = ea->fcport; |
| 1545 | ea->fcport->login_pause = 1; |
| 1546 | |
| 1547 | ql_dbg(ql_dbg_disc, vha, 0x20ed, |
| 1548 | "%s %d %8phC NPortId %06x inuse with loopid 0x%x. post gidpn\n", |
| 1549 | __func__, __LINE__, ea->fcport->port_name, |
| 1550 | ea->fcport->d_id.b24, lid); |
| 1551 | qla2x00_clear_loop_id(ea->fcport); |
| 1552 | qla24xx_post_gidpn_work(vha, ea->fcport); |
| 1553 | } else { |
| 1554 | ql_dbg(ql_dbg_disc, vha, 0x20ed, |
| 1555 | "%s %d %8phC NPortId %06x inuse with loopid 0x%x. sched delete\n", |
| 1556 | __func__, __LINE__, ea->fcport->port_name, |
| 1557 | ea->fcport->d_id.b24, lid); |
| 1558 | |
| 1559 | qla2x00_clear_loop_id(ea->fcport); |
| 1560 | set_bit(lid, vha->hw->loop_id_map); |
| 1561 | ea->fcport->loop_id = lid; |
| 1562 | ea->fcport->keep_nport_handle = 0; |
| 1563 | qlt_schedule_sess_for_deletion(ea->fcport, false); |
| 1564 | } |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1565 | break; |
| 1566 | } |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 1567 | return; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1568 | } |
| 1569 | |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 1570 | void |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1571 | qla2x00_async_logout_done(struct scsi_qla_host *vha, fc_port_t *fcport, |
| 1572 | uint16_t *data) |
| 1573 | { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1574 | qla2x00_mark_device_lost(vha, fcport, 1, 0); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1575 | qlt_logo_completion_handler(fcport, data[0]); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1576 | fcport->login_gen++; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 1577 | return; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1578 | } |
| 1579 | |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 1580 | void |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 1581 | qla2x00_async_adisc_done(struct scsi_qla_host *vha, fc_port_t *fcport, |
| 1582 | uint16_t *data) |
| 1583 | { |
| 1584 | if (data[0] == MBS_COMMAND_COMPLETE) { |
| 1585 | qla2x00_update_fcport(vha, fcport); |
| 1586 | |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 1587 | return; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 1588 | } |
| 1589 | |
| 1590 | /* Retry login. */ |
| 1591 | fcport->flags &= ~FCF_ASYNC_SENT; |
| 1592 | if (data[1] & QLA_LOGIO_LOGIN_RETRIED) |
| 1593 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
| 1594 | else |
Andrew Vasquez | 80d7944 | 2011-03-30 11:46:17 -0700 | [diff] [blame] | 1595 | qla2x00_mark_device_lost(vha, fcport, 1, 0); |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 1596 | |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 1597 | return; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 1598 | } |
| 1599 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1600 | /****************************************************************************/ |
| 1601 | /* QLogic ISP2x00 Hardware Support Functions. */ |
| 1602 | /****************************************************************************/ |
| 1603 | |
Saurav Kashyap | fa49263 | 2012-11-21 02:40:29 -0500 | [diff] [blame] | 1604 | static int |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 1605 | qla83xx_nic_core_fw_load(scsi_qla_host_t *vha) |
| 1606 | { |
| 1607 | int rval = QLA_SUCCESS; |
| 1608 | struct qla_hw_data *ha = vha->hw; |
| 1609 | uint32_t idc_major_ver, idc_minor_ver; |
Saurav Kashyap | 711aa7f | 2012-08-22 14:21:15 -0400 | [diff] [blame] | 1610 | uint16_t config[4]; |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 1611 | |
| 1612 | qla83xx_idc_lock(vha, 0); |
| 1613 | |
| 1614 | /* SV: TODO: Assign initialization timeout from |
| 1615 | * flash-info / other param |
| 1616 | */ |
| 1617 | ha->fcoe_dev_init_timeout = QLA83XX_IDC_INITIALIZATION_TIMEOUT; |
| 1618 | ha->fcoe_reset_timeout = QLA83XX_IDC_RESET_ACK_TIMEOUT; |
| 1619 | |
| 1620 | /* Set our fcoe function presence */ |
| 1621 | if (__qla83xx_set_drv_presence(vha) != QLA_SUCCESS) { |
| 1622 | ql_dbg(ql_dbg_p3p, vha, 0xb077, |
| 1623 | "Error while setting DRV-Presence.\n"); |
| 1624 | rval = QLA_FUNCTION_FAILED; |
| 1625 | goto exit; |
| 1626 | } |
| 1627 | |
| 1628 | /* Decide the reset ownership */ |
| 1629 | qla83xx_reset_ownership(vha); |
| 1630 | |
| 1631 | /* |
| 1632 | * On first protocol driver load: |
| 1633 | * Init-Owner: Set IDC-Major-Version and Clear IDC-Lock-Recovery |
| 1634 | * register. |
| 1635 | * Others: Check compatibility with current IDC Major version. |
| 1636 | */ |
| 1637 | qla83xx_rd_reg(vha, QLA83XX_IDC_MAJOR_VERSION, &idc_major_ver); |
| 1638 | if (ha->flags.nic_core_reset_owner) { |
| 1639 | /* Set IDC Major version */ |
| 1640 | idc_major_ver = QLA83XX_SUPP_IDC_MAJOR_VERSION; |
| 1641 | qla83xx_wr_reg(vha, QLA83XX_IDC_MAJOR_VERSION, idc_major_ver); |
| 1642 | |
| 1643 | /* Clearing IDC-Lock-Recovery register */ |
| 1644 | qla83xx_wr_reg(vha, QLA83XX_IDC_LOCK_RECOVERY, 0); |
| 1645 | } else if (idc_major_ver != QLA83XX_SUPP_IDC_MAJOR_VERSION) { |
| 1646 | /* |
| 1647 | * Clear further IDC participation if we are not compatible with |
| 1648 | * the current IDC Major Version. |
| 1649 | */ |
| 1650 | ql_log(ql_log_warn, vha, 0xb07d, |
| 1651 | "Failing load, idc_major_ver=%d, expected_major_ver=%d.\n", |
| 1652 | idc_major_ver, QLA83XX_SUPP_IDC_MAJOR_VERSION); |
| 1653 | __qla83xx_clear_drv_presence(vha); |
| 1654 | rval = QLA_FUNCTION_FAILED; |
| 1655 | goto exit; |
| 1656 | } |
| 1657 | /* Each function sets its supported Minor version. */ |
| 1658 | qla83xx_rd_reg(vha, QLA83XX_IDC_MINOR_VERSION, &idc_minor_ver); |
| 1659 | idc_minor_ver |= (QLA83XX_SUPP_IDC_MINOR_VERSION << (ha->portnum * 2)); |
| 1660 | qla83xx_wr_reg(vha, QLA83XX_IDC_MINOR_VERSION, idc_minor_ver); |
| 1661 | |
Saurav Kashyap | 711aa7f | 2012-08-22 14:21:15 -0400 | [diff] [blame] | 1662 | if (ha->flags.nic_core_reset_owner) { |
| 1663 | memset(config, 0, sizeof(config)); |
| 1664 | if (!qla81xx_get_port_config(vha, config)) |
| 1665 | qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, |
| 1666 | QLA8XXX_DEV_READY); |
| 1667 | } |
| 1668 | |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 1669 | rval = qla83xx_idc_state_handler(vha); |
| 1670 | |
| 1671 | exit: |
| 1672 | qla83xx_idc_unlock(vha, 0); |
| 1673 | |
| 1674 | return rval; |
| 1675 | } |
| 1676 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1677 | /* |
| 1678 | * qla2x00_initialize_adapter |
| 1679 | * Initialize board. |
| 1680 | * |
| 1681 | * Input: |
| 1682 | * ha = adapter block pointer. |
| 1683 | * |
| 1684 | * Returns: |
| 1685 | * 0 = success |
| 1686 | */ |
| 1687 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1688 | qla2x00_initialize_adapter(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1689 | { |
| 1690 | int rval; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1691 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1692 | struct req_que *req = ha->req_q_map[0]; |
Lalit Chandivade | 2533cf6 | 2009-03-24 09:08:07 -0700 | [diff] [blame] | 1693 | |
Joe Carnuccio | fc90ada | 2016-07-06 11:14:23 -0400 | [diff] [blame] | 1694 | memset(&vha->qla_stats, 0, sizeof(vha->qla_stats)); |
| 1695 | memset(&vha->fc_host_stat, 0, sizeof(vha->fc_host_stat)); |
| 1696 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1697 | /* Clear adapter flags. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1698 | vha->flags.online = 0; |
Lalit Chandivade | 2533cf6 | 2009-03-24 09:08:07 -0700 | [diff] [blame] | 1699 | ha->flags.chip_reset_done = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1700 | vha->flags.reset_active = 0; |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 1701 | ha->flags.pci_channel_io_perm_failure = 0; |
| 1702 | ha->flags.eeh_busy = 0; |
Joe Carnuccio | fabbb8d | 2013-08-27 01:37:40 -0400 | [diff] [blame] | 1703 | vha->qla_stats.jiffies_at_last_reset = get_jiffies_64(); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1704 | atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME); |
| 1705 | atomic_set(&vha->loop_state, LOOP_DOWN); |
| 1706 | vha->device_flags = DFLG_NO_CABLE; |
| 1707 | vha->dpc_flags = 0; |
| 1708 | vha->flags.management_server_logged_in = 0; |
| 1709 | vha->marker_needed = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1710 | ha->isp_abort_cnt = 0; |
| 1711 | ha->beacon_blink_led = 0; |
| 1712 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1713 | set_bit(0, ha->req_qid_map); |
| 1714 | set_bit(0, ha->rsp_qid_map); |
| 1715 | |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 1716 | ql_dbg(ql_dbg_init, vha, 0x0040, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1717 | "Configuring PCI space...\n"); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1718 | rval = ha->isp_ops->pci_config(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1719 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1720 | ql_log(ql_log_warn, vha, 0x0044, |
| 1721 | "Unable to configure PCI space.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1722 | return (rval); |
| 1723 | } |
| 1724 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1725 | ha->isp_ops->reset_chip(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1726 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1727 | rval = qla2xxx_get_flash_info(vha); |
Andrew Vasquez | c00d899 | 2008-09-11 21:22:49 -0700 | [diff] [blame] | 1728 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1729 | ql_log(ql_log_fatal, vha, 0x004f, |
| 1730 | "Unable to validate FLASH data.\n"); |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 1731 | return rval; |
| 1732 | } |
| 1733 | |
| 1734 | if (IS_QLA8044(ha)) { |
| 1735 | qla8044_read_reset_template(vha); |
| 1736 | |
| 1737 | /* NOTE: If ql2xdontresethba==1, set IDC_CTRL DONTRESET_BIT0. |
| 1738 | * If DONRESET_BIT0 is set, drivers should not set dev_state |
| 1739 | * to NEED_RESET. But if NEED_RESET is set, drivers should |
| 1740 | * should honor the reset. */ |
| 1741 | if (ql2xdontresethba == 1) |
| 1742 | qla8044_set_idc_dontreset(vha); |
Andrew Vasquez | c00d899 | 2008-09-11 21:22:49 -0700 | [diff] [blame] | 1743 | } |
| 1744 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1745 | ha->isp_ops->get_flash_version(vha, req->ring); |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 1746 | ql_dbg(ql_dbg_init, vha, 0x0061, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1747 | "Configure NVRAM parameters...\n"); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1748 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1749 | ha->isp_ops->nvram_config(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1750 | |
Andrew Vasquez | d4c760c | 2006-06-23 16:10:39 -0700 | [diff] [blame] | 1751 | if (ha->flags.disable_serdes) { |
| 1752 | /* Mask HBA via NVRAM settings? */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1753 | ql_log(ql_log_info, vha, 0x0077, |
Oleksandr Khoshaba | 7b833558 | 2013-08-27 01:37:27 -0400 | [diff] [blame] | 1754 | "Masking HBA WWPN %8phN (via NVRAM).\n", vha->port_name); |
Andrew Vasquez | d4c760c | 2006-06-23 16:10:39 -0700 | [diff] [blame] | 1755 | return QLA_FUNCTION_FAILED; |
| 1756 | } |
| 1757 | |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 1758 | ql_dbg(ql_dbg_init, vha, 0x0078, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1759 | "Verifying loaded RISC code...\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1760 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1761 | if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) { |
| 1762 | rval = ha->isp_ops->chip_diag(vha); |
Andrew Vasquez | d19044c | 2006-11-22 08:22:19 -0800 | [diff] [blame] | 1763 | if (rval) |
| 1764 | return (rval); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1765 | rval = qla2x00_setup_chip(vha); |
Andrew Vasquez | d19044c | 2006-11-22 08:22:19 -0800 | [diff] [blame] | 1766 | if (rval) |
| 1767 | return (rval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1768 | } |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 1769 | |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 1770 | if (IS_QLA84XX(ha)) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1771 | ha->cs84xx = qla84xx_get_chip(vha); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 1772 | if (!ha->cs84xx) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1773 | ql_log(ql_log_warn, vha, 0x00d0, |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 1774 | "Unable to configure ISP84XX.\n"); |
| 1775 | return QLA_FUNCTION_FAILED; |
| 1776 | } |
| 1777 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1778 | |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 1779 | if (qla_ini_mode_enabled(vha) || qla_dual_mode_enabled(vha)) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1780 | rval = qla2x00_init_rings(vha); |
| 1781 | |
Lalit Chandivade | 2533cf6 | 2009-03-24 09:08:07 -0700 | [diff] [blame] | 1782 | ha->flags.chip_reset_done = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1783 | |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 1784 | if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) { |
Andrew Vasquez | 6c452a4 | 2010-03-19 17:04:02 -0700 | [diff] [blame] | 1785 | /* Issue verify 84xx FW IOCB to complete 84xx initialization */ |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 1786 | rval = qla84xx_init_chip(vha); |
| 1787 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1788 | ql_log(ql_log_warn, vha, 0x00d4, |
| 1789 | "Unable to initialize ISP84XX.\n"); |
Bart Van Assche | 8d2b21d | 2015-06-04 15:58:09 -0700 | [diff] [blame] | 1790 | qla84xx_put_chip(vha); |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 1791 | } |
| 1792 | } |
| 1793 | |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 1794 | /* Load the NIC Core f/w if we are the first protocol driver. */ |
| 1795 | if (IS_QLA8031(ha)) { |
| 1796 | rval = qla83xx_nic_core_fw_load(vha); |
| 1797 | if (rval) |
| 1798 | ql_log(ql_log_warn, vha, 0x0124, |
| 1799 | "Error in initializing NIC Core f/w.\n"); |
| 1800 | } |
| 1801 | |
Madhuranath Iyengar | 2f0f3f4 | 2010-07-23 15:28:24 +0500 | [diff] [blame] | 1802 | if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha)) |
| 1803 | qla24xx_read_fcp_prio_cfg(vha); |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 1804 | |
Joe Carnuccio | c46e65c | 2013-08-27 01:37:35 -0400 | [diff] [blame] | 1805 | if (IS_P3P_TYPE(ha)) |
| 1806 | qla82xx_set_driver_version(vha, QLA2XXX_VERSION); |
| 1807 | else |
| 1808 | qla25xx_set_driver_version(vha, QLA2XXX_VERSION); |
| 1809 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1810 | return (rval); |
| 1811 | } |
| 1812 | |
| 1813 | /** |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1814 | * qla2100_pci_config() - Setup ISP21xx PCI configuration registers. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1815 | * @ha: HA context |
| 1816 | * |
| 1817 | * Returns 0 on success. |
| 1818 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1819 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1820 | qla2100_pci_config(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1821 | { |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 1822 | uint16_t w; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1823 | unsigned long flags; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1824 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 1825 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1826 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1827 | pci_set_master(ha->pdev); |
Andrew Vasquez | af6177d | 2007-07-19 15:06:02 -0700 | [diff] [blame] | 1828 | pci_try_set_mwi(ha->pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1829 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1830 | pci_read_config_word(ha->pdev, PCI_COMMAND, &w); |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 1831 | w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1832 | pci_write_config_word(ha->pdev, PCI_COMMAND, w); |
| 1833 | |
Andrew Vasquez | 737faec | 2008-10-24 15:13:45 -0700 | [diff] [blame] | 1834 | pci_disable_rom(ha->pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1835 | |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1836 | /* Get PCI bus information. */ |
| 1837 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 1838 | ha->pci_attr = RD_REG_WORD(®->ctrl_status); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1839 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1840 | |
| 1841 | return QLA_SUCCESS; |
| 1842 | } |
| 1843 | |
| 1844 | /** |
| 1845 | * qla2300_pci_config() - Setup ISP23xx PCI configuration registers. |
| 1846 | * @ha: HA context |
| 1847 | * |
| 1848 | * Returns 0 on success. |
| 1849 | */ |
| 1850 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1851 | qla2300_pci_config(scsi_qla_host_t *vha) |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1852 | { |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 1853 | uint16_t w; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1854 | unsigned long flags = 0; |
| 1855 | uint32_t cnt; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1856 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 1857 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1858 | |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1859 | pci_set_master(ha->pdev); |
Andrew Vasquez | af6177d | 2007-07-19 15:06:02 -0700 | [diff] [blame] | 1860 | pci_try_set_mwi(ha->pdev); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1861 | |
| 1862 | pci_read_config_word(ha->pdev, PCI_COMMAND, &w); |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 1863 | w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1864 | |
| 1865 | if (IS_QLA2322(ha) || IS_QLA6322(ha)) |
| 1866 | w &= ~PCI_COMMAND_INTX_DISABLE; |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 1867 | pci_write_config_word(ha->pdev, PCI_COMMAND, w); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1868 | |
| 1869 | /* |
| 1870 | * If this is a 2300 card and not 2312, reset the |
| 1871 | * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately, |
| 1872 | * the 2310 also reports itself as a 2300 so we need to get the |
| 1873 | * fb revision level -- a 6 indicates it really is a 2300 and |
| 1874 | * not a 2310. |
| 1875 | */ |
| 1876 | if (IS_QLA2300(ha)) { |
| 1877 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1878 | |
| 1879 | /* Pause RISC. */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 1880 | WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1881 | for (cnt = 0; cnt < 30000; cnt++) { |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 1882 | if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) != 0) |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1883 | break; |
| 1884 | |
| 1885 | udelay(10); |
| 1886 | } |
| 1887 | |
| 1888 | /* Select FPM registers. */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 1889 | WRT_REG_WORD(®->ctrl_status, 0x20); |
| 1890 | RD_REG_WORD(®->ctrl_status); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1891 | |
| 1892 | /* Get the fb rev level */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 1893 | ha->fb_rev = RD_FB_CMD_REG(ha, reg); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1894 | |
| 1895 | if (ha->fb_rev == FPM_2300) |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 1896 | pci_clear_mwi(ha->pdev); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1897 | |
| 1898 | /* Deselect FPM registers. */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 1899 | WRT_REG_WORD(®->ctrl_status, 0x0); |
| 1900 | RD_REG_WORD(®->ctrl_status); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1901 | |
| 1902 | /* Release RISC module. */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 1903 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1904 | for (cnt = 0; cnt < 30000; cnt++) { |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 1905 | if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) == 0) |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1906 | break; |
| 1907 | |
| 1908 | udelay(10); |
| 1909 | } |
| 1910 | |
| 1911 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1912 | } |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1913 | |
| 1914 | pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80); |
| 1915 | |
Andrew Vasquez | 737faec | 2008-10-24 15:13:45 -0700 | [diff] [blame] | 1916 | pci_disable_rom(ha->pdev); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1917 | |
| 1918 | /* Get PCI bus information. */ |
| 1919 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 1920 | ha->pci_attr = RD_REG_WORD(®->ctrl_status); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1921 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1922 | |
| 1923 | return QLA_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1924 | } |
| 1925 | |
| 1926 | /** |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1927 | * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers. |
| 1928 | * @ha: HA context |
| 1929 | * |
| 1930 | * Returns 0 on success. |
| 1931 | */ |
| 1932 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1933 | qla24xx_pci_config(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1934 | { |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 1935 | uint16_t w; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1936 | unsigned long flags = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1937 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1938 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1939 | |
| 1940 | pci_set_master(ha->pdev); |
Andrew Vasquez | af6177d | 2007-07-19 15:06:02 -0700 | [diff] [blame] | 1941 | pci_try_set_mwi(ha->pdev); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1942 | |
| 1943 | pci_read_config_word(ha->pdev, PCI_COMMAND, &w); |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 1944 | w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1945 | w &= ~PCI_COMMAND_INTX_DISABLE; |
| 1946 | pci_write_config_word(ha->pdev, PCI_COMMAND, w); |
| 1947 | |
| 1948 | pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80); |
| 1949 | |
| 1950 | /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */ |
Andrew Vasquez | f85ec18 | 2007-07-19 15:06:01 -0700 | [diff] [blame] | 1951 | if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX)) |
| 1952 | pcix_set_mmrbc(ha->pdev, 2048); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1953 | |
| 1954 | /* PCIe -- adjust Maximum Read Request Size (2048). */ |
Jon Mason | e67f132 | 2012-07-10 14:57:56 -0700 | [diff] [blame] | 1955 | if (pci_is_pcie(ha->pdev)) |
Chad Dupuis | 5ffd3a5 | 2012-08-22 14:21:26 -0400 | [diff] [blame] | 1956 | pcie_set_readrq(ha->pdev, 4096); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1957 | |
Andrew Vasquez | 737faec | 2008-10-24 15:13:45 -0700 | [diff] [blame] | 1958 | pci_disable_rom(ha->pdev); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1959 | |
Auke Kok | 44c1013 | 2007-06-08 15:46:36 -0700 | [diff] [blame] | 1960 | ha->chip_revision = ha->pdev->revision; |
Andrew Vasquez | a8488ab | 2007-01-29 10:22:19 -0800 | [diff] [blame] | 1961 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1962 | /* Get PCI bus information. */ |
| 1963 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1964 | ha->pci_attr = RD_REG_DWORD(®->ctrl_status); |
| 1965 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1966 | |
| 1967 | return QLA_SUCCESS; |
| 1968 | } |
| 1969 | |
| 1970 | /** |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 1971 | * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers. |
| 1972 | * @ha: HA context |
| 1973 | * |
| 1974 | * Returns 0 on success. |
| 1975 | */ |
| 1976 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1977 | qla25xx_pci_config(scsi_qla_host_t *vha) |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 1978 | { |
| 1979 | uint16_t w; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1980 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 1981 | |
| 1982 | pci_set_master(ha->pdev); |
| 1983 | pci_try_set_mwi(ha->pdev); |
| 1984 | |
| 1985 | pci_read_config_word(ha->pdev, PCI_COMMAND, &w); |
| 1986 | w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR); |
| 1987 | w &= ~PCI_COMMAND_INTX_DISABLE; |
| 1988 | pci_write_config_word(ha->pdev, PCI_COMMAND, w); |
| 1989 | |
| 1990 | /* PCIe -- adjust Maximum Read Request Size (2048). */ |
Jon Mason | e67f132 | 2012-07-10 14:57:56 -0700 | [diff] [blame] | 1991 | if (pci_is_pcie(ha->pdev)) |
Chad Dupuis | 5ffd3a5 | 2012-08-22 14:21:26 -0400 | [diff] [blame] | 1992 | pcie_set_readrq(ha->pdev, 4096); |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 1993 | |
Andrew Vasquez | 737faec | 2008-10-24 15:13:45 -0700 | [diff] [blame] | 1994 | pci_disable_rom(ha->pdev); |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 1995 | |
| 1996 | ha->chip_revision = ha->pdev->revision; |
| 1997 | |
| 1998 | return QLA_SUCCESS; |
| 1999 | } |
| 2000 | |
| 2001 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2002 | * qla2x00_isp_firmware() - Choose firmware image. |
| 2003 | * @ha: HA context |
| 2004 | * |
| 2005 | * Returns 0 on success. |
| 2006 | */ |
| 2007 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2008 | qla2x00_isp_firmware(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2009 | { |
| 2010 | int rval; |
Andrew Vasquez | 42e421b | 2008-07-10 16:56:01 -0700 | [diff] [blame] | 2011 | uint16_t loop_id, topo, sw_cap; |
| 2012 | uint8_t domain, area, al_pa; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2013 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2014 | |
| 2015 | /* Assume loading risc code */ |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 2016 | rval = QLA_FUNCTION_FAILED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2017 | |
| 2018 | if (ha->flags.disable_risc_code_load) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2019 | ql_log(ql_log_info, vha, 0x0079, "RISC CODE NOT loaded.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2020 | |
| 2021 | /* Verify checksum of loaded RISC code. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2022 | rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address); |
Andrew Vasquez | 42e421b | 2008-07-10 16:56:01 -0700 | [diff] [blame] | 2023 | if (rval == QLA_SUCCESS) { |
| 2024 | /* And, verify we are not in ROM code. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2025 | rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa, |
Andrew Vasquez | 42e421b | 2008-07-10 16:56:01 -0700 | [diff] [blame] | 2026 | &area, &domain, &topo, &sw_cap); |
| 2027 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2028 | } |
| 2029 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2030 | if (rval) |
| 2031 | ql_dbg(ql_dbg_init, vha, 0x007a, |
| 2032 | "**** Load RISC code ****.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2033 | |
| 2034 | return (rval); |
| 2035 | } |
| 2036 | |
| 2037 | /** |
| 2038 | * qla2x00_reset_chip() - Reset ISP chip. |
| 2039 | * @ha: HA context |
| 2040 | * |
| 2041 | * Returns 0 on success. |
| 2042 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2043 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2044 | qla2x00_reset_chip(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2045 | { |
| 2046 | unsigned long flags = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2047 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 2048 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2049 | uint32_t cnt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2050 | uint16_t cmd; |
| 2051 | |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 2052 | if (unlikely(pci_channel_offline(ha->pdev))) |
| 2053 | return; |
| 2054 | |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 2055 | ha->isp_ops->disable_intrs(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2056 | |
| 2057 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 2058 | |
| 2059 | /* Turn off master enable */ |
| 2060 | cmd = 0; |
| 2061 | pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd); |
| 2062 | cmd &= ~PCI_COMMAND_MASTER; |
| 2063 | pci_write_config_word(ha->pdev, PCI_COMMAND, cmd); |
| 2064 | |
| 2065 | if (!IS_QLA2100(ha)) { |
| 2066 | /* Pause RISC. */ |
| 2067 | WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC); |
| 2068 | if (IS_QLA2200(ha) || IS_QLA2300(ha)) { |
| 2069 | for (cnt = 0; cnt < 30000; cnt++) { |
| 2070 | if ((RD_REG_WORD(®->hccr) & |
| 2071 | HCCR_RISC_PAUSE) != 0) |
| 2072 | break; |
| 2073 | udelay(100); |
| 2074 | } |
| 2075 | } else { |
| 2076 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 2077 | udelay(10); |
| 2078 | } |
| 2079 | |
| 2080 | /* Select FPM registers. */ |
| 2081 | WRT_REG_WORD(®->ctrl_status, 0x20); |
| 2082 | RD_REG_WORD(®->ctrl_status); /* PCI Posting. */ |
| 2083 | |
| 2084 | /* FPM Soft Reset. */ |
| 2085 | WRT_REG_WORD(®->fpm_diag_config, 0x100); |
| 2086 | RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */ |
| 2087 | |
| 2088 | /* Toggle Fpm Reset. */ |
| 2089 | if (!IS_QLA2200(ha)) { |
| 2090 | WRT_REG_WORD(®->fpm_diag_config, 0x0); |
| 2091 | RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */ |
| 2092 | } |
| 2093 | |
| 2094 | /* Select frame buffer registers. */ |
| 2095 | WRT_REG_WORD(®->ctrl_status, 0x10); |
| 2096 | RD_REG_WORD(®->ctrl_status); /* PCI Posting. */ |
| 2097 | |
| 2098 | /* Reset frame buffer FIFOs. */ |
| 2099 | if (IS_QLA2200(ha)) { |
| 2100 | WRT_FB_CMD_REG(ha, reg, 0xa000); |
| 2101 | RD_FB_CMD_REG(ha, reg); /* PCI Posting. */ |
| 2102 | } else { |
| 2103 | WRT_FB_CMD_REG(ha, reg, 0x00fc); |
| 2104 | |
| 2105 | /* Read back fb_cmd until zero or 3 seconds max */ |
| 2106 | for (cnt = 0; cnt < 3000; cnt++) { |
| 2107 | if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0) |
| 2108 | break; |
| 2109 | udelay(100); |
| 2110 | } |
| 2111 | } |
| 2112 | |
| 2113 | /* Select RISC module registers. */ |
| 2114 | WRT_REG_WORD(®->ctrl_status, 0); |
| 2115 | RD_REG_WORD(®->ctrl_status); /* PCI Posting. */ |
| 2116 | |
| 2117 | /* Reset RISC processor. */ |
| 2118 | WRT_REG_WORD(®->hccr, HCCR_RESET_RISC); |
| 2119 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 2120 | |
| 2121 | /* Release RISC processor. */ |
| 2122 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
| 2123 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 2124 | } |
| 2125 | |
| 2126 | WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT); |
| 2127 | WRT_REG_WORD(®->hccr, HCCR_CLR_HOST_INT); |
| 2128 | |
| 2129 | /* Reset ISP chip. */ |
| 2130 | WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET); |
| 2131 | |
| 2132 | /* Wait for RISC to recover from reset. */ |
| 2133 | if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) { |
| 2134 | /* |
| 2135 | * It is necessary to for a delay here since the card doesn't |
| 2136 | * respond to PCI reads during a reset. On some architectures |
| 2137 | * this will result in an MCA. |
| 2138 | */ |
| 2139 | udelay(20); |
| 2140 | for (cnt = 30000; cnt; cnt--) { |
| 2141 | if ((RD_REG_WORD(®->ctrl_status) & |
| 2142 | CSR_ISP_SOFT_RESET) == 0) |
| 2143 | break; |
| 2144 | udelay(100); |
| 2145 | } |
| 2146 | } else |
| 2147 | udelay(10); |
| 2148 | |
| 2149 | /* Reset RISC processor. */ |
| 2150 | WRT_REG_WORD(®->hccr, HCCR_RESET_RISC); |
| 2151 | |
| 2152 | WRT_REG_WORD(®->semaphore, 0); |
| 2153 | |
| 2154 | /* Release RISC processor. */ |
| 2155 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
| 2156 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 2157 | |
| 2158 | if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) { |
| 2159 | for (cnt = 0; cnt < 30000; cnt++) { |
Andrew Vasquez | ffb39f0 | 2006-05-17 15:09:06 -0700 | [diff] [blame] | 2160 | if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2161 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2162 | |
| 2163 | udelay(100); |
| 2164 | } |
| 2165 | } else |
| 2166 | udelay(100); |
| 2167 | |
| 2168 | /* Turn on master enable */ |
| 2169 | cmd |= PCI_COMMAND_MASTER; |
| 2170 | pci_write_config_word(ha->pdev, PCI_COMMAND, cmd); |
| 2171 | |
| 2172 | /* Disable RISC pause on FPM parity error. */ |
| 2173 | if (!IS_QLA2100(ha)) { |
| 2174 | WRT_REG_WORD(®->hccr, HCCR_DISABLE_PARITY_PAUSE); |
| 2175 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 2176 | } |
| 2177 | |
| 2178 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 2179 | } |
| 2180 | |
| 2181 | /** |
Madhuranath Iyengar | b1d46989 | 2010-09-03 15:20:54 -0700 | [diff] [blame] | 2182 | * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC. |
| 2183 | * |
| 2184 | * Returns 0 on success. |
| 2185 | */ |
Saurav Kashyap | fa49263 | 2012-11-21 02:40:29 -0500 | [diff] [blame] | 2186 | static int |
Madhuranath Iyengar | b1d46989 | 2010-09-03 15:20:54 -0700 | [diff] [blame] | 2187 | qla81xx_reset_mpi(scsi_qla_host_t *vha) |
| 2188 | { |
| 2189 | uint16_t mb[4] = {0x1010, 0, 1, 0}; |
| 2190 | |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 2191 | if (!IS_QLA81XX(vha->hw)) |
| 2192 | return QLA_SUCCESS; |
| 2193 | |
Madhuranath Iyengar | b1d46989 | 2010-09-03 15:20:54 -0700 | [diff] [blame] | 2194 | return qla81xx_write_mpi_register(vha, mb); |
| 2195 | } |
| 2196 | |
| 2197 | /** |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 2198 | * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC. |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2199 | * @ha: HA context |
| 2200 | * |
| 2201 | * Returns 0 on success. |
| 2202 | */ |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2203 | static inline int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2204 | qla24xx_reset_risc(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2205 | { |
| 2206 | unsigned long flags = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2207 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2208 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; |
Bart Van Assche | 52c8282 | 2015-07-09 07:23:26 -0700 | [diff] [blame] | 2209 | uint32_t cnt; |
Andrew Vasquez | 335a1cc | 2005-11-08 14:37:48 -0800 | [diff] [blame] | 2210 | uint16_t wd; |
Madhuranath Iyengar | b1d46989 | 2010-09-03 15:20:54 -0700 | [diff] [blame] | 2211 | static int abts_cnt; /* ISP abort retry counts */ |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2212 | int rval = QLA_SUCCESS; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2213 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2214 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 2215 | |
| 2216 | /* Reset RISC. */ |
| 2217 | WRT_REG_DWORD(®->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES); |
| 2218 | for (cnt = 0; cnt < 30000; cnt++) { |
| 2219 | if ((RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE) == 0) |
| 2220 | break; |
| 2221 | |
| 2222 | udelay(10); |
| 2223 | } |
| 2224 | |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2225 | if (!(RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE)) |
| 2226 | set_bit(DMA_SHUTDOWN_CMPL, &ha->fw_dump_cap_flags); |
| 2227 | |
| 2228 | ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017e, |
| 2229 | "HCCR: 0x%x, Control Status %x, DMA active status:0x%x\n", |
| 2230 | RD_REG_DWORD(®->hccr), |
| 2231 | RD_REG_DWORD(®->ctrl_status), |
| 2232 | (RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE)); |
| 2233 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2234 | WRT_REG_DWORD(®->ctrl_status, |
| 2235 | CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES); |
Andrew Vasquez | 335a1cc | 2005-11-08 14:37:48 -0800 | [diff] [blame] | 2236 | pci_read_config_word(ha->pdev, PCI_COMMAND, &wd); |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 2237 | |
Andrew Vasquez | 335a1cc | 2005-11-08 14:37:48 -0800 | [diff] [blame] | 2238 | udelay(100); |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2239 | |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 2240 | /* Wait for firmware to complete NVRAM accesses. */ |
Bart Van Assche | 52c8282 | 2015-07-09 07:23:26 -0700 | [diff] [blame] | 2241 | RD_REG_WORD(®->mailbox0); |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2242 | for (cnt = 10000; RD_REG_WORD(®->mailbox0) != 0 && |
| 2243 | rval == QLA_SUCCESS; cnt--) { |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 2244 | barrier(); |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2245 | if (cnt) |
| 2246 | udelay(5); |
| 2247 | else |
| 2248 | rval = QLA_FUNCTION_TIMEOUT; |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 2249 | } |
| 2250 | |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2251 | if (rval == QLA_SUCCESS) |
| 2252 | set_bit(ISP_MBX_RDY, &ha->fw_dump_cap_flags); |
| 2253 | |
| 2254 | ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017f, |
| 2255 | "HCCR: 0x%x, MailBox0 Status 0x%x\n", |
| 2256 | RD_REG_DWORD(®->hccr), |
| 2257 | RD_REG_DWORD(®->mailbox0)); |
| 2258 | |
Andrew Vasquez | 335a1cc | 2005-11-08 14:37:48 -0800 | [diff] [blame] | 2259 | /* Wait for soft-reset to complete. */ |
Bart Van Assche | 52c8282 | 2015-07-09 07:23:26 -0700 | [diff] [blame] | 2260 | RD_REG_DWORD(®->ctrl_status); |
Quinn Tran | 200ffb1 | 2016-12-23 18:06:12 -0800 | [diff] [blame] | 2261 | for (cnt = 0; cnt < 60; cnt++) { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2262 | barrier(); |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2263 | if ((RD_REG_DWORD(®->ctrl_status) & |
| 2264 | CSRX_ISP_SOFT_RESET) == 0) |
| 2265 | break; |
| 2266 | |
| 2267 | udelay(5); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2268 | } |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2269 | if (!(RD_REG_DWORD(®->ctrl_status) & CSRX_ISP_SOFT_RESET)) |
| 2270 | set_bit(ISP_SOFT_RESET_CMPL, &ha->fw_dump_cap_flags); |
| 2271 | |
| 2272 | ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015d, |
| 2273 | "HCCR: 0x%x, Soft Reset status: 0x%x\n", |
| 2274 | RD_REG_DWORD(®->hccr), |
| 2275 | RD_REG_DWORD(®->ctrl_status)); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2276 | |
Madhuranath Iyengar | b1d46989 | 2010-09-03 15:20:54 -0700 | [diff] [blame] | 2277 | /* If required, do an MPI FW reset now */ |
| 2278 | if (test_and_clear_bit(MPI_RESET_NEEDED, &vha->dpc_flags)) { |
| 2279 | if (qla81xx_reset_mpi(vha) != QLA_SUCCESS) { |
| 2280 | if (++abts_cnt < 5) { |
| 2281 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
| 2282 | set_bit(MPI_RESET_NEEDED, &vha->dpc_flags); |
| 2283 | } else { |
| 2284 | /* |
| 2285 | * We exhausted the ISP abort retries. We have to |
| 2286 | * set the board offline. |
| 2287 | */ |
| 2288 | abts_cnt = 0; |
| 2289 | vha->flags.online = 0; |
| 2290 | } |
| 2291 | } |
| 2292 | } |
| 2293 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2294 | WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET); |
| 2295 | RD_REG_DWORD(®->hccr); |
| 2296 | |
| 2297 | WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE); |
| 2298 | RD_REG_DWORD(®->hccr); |
| 2299 | |
| 2300 | WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_RESET); |
| 2301 | RD_REG_DWORD(®->hccr); |
| 2302 | |
Bart Van Assche | 52c8282 | 2015-07-09 07:23:26 -0700 | [diff] [blame] | 2303 | RD_REG_WORD(®->mailbox0); |
Quinn Tran | 200ffb1 | 2016-12-23 18:06:12 -0800 | [diff] [blame] | 2304 | for (cnt = 60; RD_REG_WORD(®->mailbox0) != 0 && |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2305 | rval == QLA_SUCCESS; cnt--) { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2306 | barrier(); |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2307 | if (cnt) |
| 2308 | udelay(5); |
| 2309 | else |
| 2310 | rval = QLA_FUNCTION_TIMEOUT; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2311 | } |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2312 | if (rval == QLA_SUCCESS) |
| 2313 | set_bit(RISC_RDY_AFT_RESET, &ha->fw_dump_cap_flags); |
| 2314 | |
| 2315 | ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015e, |
| 2316 | "Host Risc 0x%x, mailbox0 0x%x\n", |
| 2317 | RD_REG_DWORD(®->hccr), |
| 2318 | RD_REG_WORD(®->mailbox0)); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2319 | |
| 2320 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Andrew Vasquez | 124f85e | 2009-01-05 11:18:06 -0800 | [diff] [blame] | 2321 | |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2322 | ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015f, |
| 2323 | "Driver in %s mode\n", |
| 2324 | IS_NOPOLLING_TYPE(ha) ? "Interrupt" : "Polling"); |
| 2325 | |
Andrew Vasquez | 124f85e | 2009-01-05 11:18:06 -0800 | [diff] [blame] | 2326 | if (IS_NOPOLLING_TYPE(ha)) |
| 2327 | ha->isp_ops->enable_intrs(ha); |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2328 | |
| 2329 | return rval; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2330 | } |
| 2331 | |
Joe Carnuccio | 4ea2c9c | 2012-11-21 02:40:37 -0500 | [diff] [blame] | 2332 | static void |
| 2333 | qla25xx_read_risc_sema_reg(scsi_qla_host_t *vha, uint32_t *data) |
| 2334 | { |
| 2335 | struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24; |
| 2336 | |
| 2337 | WRT_REG_DWORD(®->iobase_addr, RISC_REGISTER_BASE_OFFSET); |
| 2338 | *data = RD_REG_DWORD(®->iobase_window + RISC_REGISTER_WINDOW_OFFET); |
| 2339 | |
| 2340 | } |
| 2341 | |
| 2342 | static void |
| 2343 | qla25xx_write_risc_sema_reg(scsi_qla_host_t *vha, uint32_t data) |
| 2344 | { |
| 2345 | struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24; |
| 2346 | |
| 2347 | WRT_REG_DWORD(®->iobase_addr, RISC_REGISTER_BASE_OFFSET); |
| 2348 | WRT_REG_DWORD(®->iobase_window + RISC_REGISTER_WINDOW_OFFET, data); |
| 2349 | } |
| 2350 | |
| 2351 | static void |
| 2352 | qla25xx_manipulate_risc_semaphore(scsi_qla_host_t *vha) |
| 2353 | { |
Joe Carnuccio | 4ea2c9c | 2012-11-21 02:40:37 -0500 | [diff] [blame] | 2354 | uint32_t wd32 = 0; |
| 2355 | uint delta_msec = 100; |
| 2356 | uint elapsed_msec = 0; |
| 2357 | uint timeout_msec; |
| 2358 | ulong n; |
| 2359 | |
Joe Carnuccio | cc79076 | 2015-08-04 13:37:53 -0400 | [diff] [blame] | 2360 | if (vha->hw->pdev->subsystem_device != 0x0175 && |
| 2361 | vha->hw->pdev->subsystem_device != 0x0240) |
Joe Carnuccio | 4ea2c9c | 2012-11-21 02:40:37 -0500 | [diff] [blame] | 2362 | return; |
| 2363 | |
Joe Carnuccio | 8dd7e3a | 2015-08-04 13:37:54 -0400 | [diff] [blame] | 2364 | WRT_REG_DWORD(&vha->hw->iobase->isp24.hccr, HCCRX_SET_RISC_PAUSE); |
| 2365 | udelay(100); |
| 2366 | |
Joe Carnuccio | 4ea2c9c | 2012-11-21 02:40:37 -0500 | [diff] [blame] | 2367 | attempt: |
| 2368 | timeout_msec = TIMEOUT_SEMAPHORE; |
| 2369 | n = timeout_msec / delta_msec; |
| 2370 | while (n--) { |
| 2371 | qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_SET); |
| 2372 | qla25xx_read_risc_sema_reg(vha, &wd32); |
| 2373 | if (wd32 & RISC_SEMAPHORE) |
| 2374 | break; |
| 2375 | msleep(delta_msec); |
| 2376 | elapsed_msec += delta_msec; |
| 2377 | if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED) |
| 2378 | goto force; |
| 2379 | } |
| 2380 | |
| 2381 | if (!(wd32 & RISC_SEMAPHORE)) |
| 2382 | goto force; |
| 2383 | |
| 2384 | if (!(wd32 & RISC_SEMAPHORE_FORCE)) |
| 2385 | goto acquired; |
| 2386 | |
| 2387 | qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_CLR); |
| 2388 | timeout_msec = TIMEOUT_SEMAPHORE_FORCE; |
| 2389 | n = timeout_msec / delta_msec; |
| 2390 | while (n--) { |
| 2391 | qla25xx_read_risc_sema_reg(vha, &wd32); |
| 2392 | if (!(wd32 & RISC_SEMAPHORE_FORCE)) |
| 2393 | break; |
| 2394 | msleep(delta_msec); |
| 2395 | elapsed_msec += delta_msec; |
| 2396 | if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED) |
| 2397 | goto force; |
| 2398 | } |
| 2399 | |
| 2400 | if (wd32 & RISC_SEMAPHORE_FORCE) |
| 2401 | qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_CLR); |
| 2402 | |
| 2403 | goto attempt; |
| 2404 | |
| 2405 | force: |
| 2406 | qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_SET); |
| 2407 | |
| 2408 | acquired: |
| 2409 | return; |
| 2410 | } |
| 2411 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2412 | /** |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 2413 | * qla24xx_reset_chip() - Reset ISP24xx chip. |
| 2414 | * @ha: HA context |
| 2415 | * |
| 2416 | * Returns 0 on success. |
| 2417 | */ |
| 2418 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2419 | qla24xx_reset_chip(scsi_qla_host_t *vha) |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 2420 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2421 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 2422 | |
| 2423 | if (pci_channel_offline(ha->pdev) && |
| 2424 | ha->flags.pci_channel_io_perm_failure) { |
| 2425 | return; |
| 2426 | } |
| 2427 | |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 2428 | ha->isp_ops->disable_intrs(ha); |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 2429 | |
Joe Carnuccio | 4ea2c9c | 2012-11-21 02:40:37 -0500 | [diff] [blame] | 2430 | qla25xx_manipulate_risc_semaphore(vha); |
| 2431 | |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 2432 | /* Perform RISC reset. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2433 | qla24xx_reset_risc(vha); |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 2434 | } |
| 2435 | |
| 2436 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2437 | * qla2x00_chip_diag() - Test chip for proper operation. |
| 2438 | * @ha: HA context |
| 2439 | * |
| 2440 | * Returns 0 on success. |
| 2441 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2442 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2443 | qla2x00_chip_diag(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2444 | { |
| 2445 | int rval; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2446 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 2447 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2448 | unsigned long flags = 0; |
| 2449 | uint16_t data; |
| 2450 | uint32_t cnt; |
| 2451 | uint16_t mb[5]; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2452 | struct req_que *req = ha->req_q_map[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2453 | |
| 2454 | /* Assume a failed state */ |
| 2455 | rval = QLA_FUNCTION_FAILED; |
| 2456 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2457 | ql_dbg(ql_dbg_init, vha, 0x007b, |
| 2458 | "Testing device at %lx.\n", (u_long)®->flash_address); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2459 | |
| 2460 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 2461 | |
| 2462 | /* Reset ISP chip. */ |
| 2463 | WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET); |
| 2464 | |
| 2465 | /* |
| 2466 | * We need to have a delay here since the card will not respond while |
| 2467 | * in reset causing an MCA on some architectures. |
| 2468 | */ |
| 2469 | udelay(20); |
| 2470 | data = qla2x00_debounce_register(®->ctrl_status); |
| 2471 | for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) { |
| 2472 | udelay(5); |
| 2473 | data = RD_REG_WORD(®->ctrl_status); |
| 2474 | barrier(); |
| 2475 | } |
| 2476 | |
| 2477 | if (!cnt) |
| 2478 | goto chip_diag_failed; |
| 2479 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2480 | ql_dbg(ql_dbg_init, vha, 0x007c, |
| 2481 | "Reset register cleared by chip reset.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2482 | |
| 2483 | /* Reset RISC processor. */ |
| 2484 | WRT_REG_WORD(®->hccr, HCCR_RESET_RISC); |
| 2485 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
| 2486 | |
| 2487 | /* Workaround for QLA2312 PCI parity error */ |
| 2488 | if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) { |
| 2489 | data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0)); |
| 2490 | for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) { |
| 2491 | udelay(5); |
| 2492 | data = RD_MAILBOX_REG(ha, reg, 0); |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 2493 | barrier(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2494 | } |
| 2495 | } else |
| 2496 | udelay(10); |
| 2497 | |
| 2498 | if (!cnt) |
| 2499 | goto chip_diag_failed; |
| 2500 | |
| 2501 | /* Check product ID of chip */ |
Milan P Gandhi | 5a68a1c | 2017-03-31 14:37:04 -0700 | [diff] [blame] | 2502 | 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] | 2503 | |
| 2504 | mb[1] = RD_MAILBOX_REG(ha, reg, 1); |
| 2505 | mb[2] = RD_MAILBOX_REG(ha, reg, 2); |
| 2506 | mb[3] = RD_MAILBOX_REG(ha, reg, 3); |
| 2507 | mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4)); |
| 2508 | if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) || |
| 2509 | mb[3] != PROD_ID_3) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2510 | ql_log(ql_log_warn, vha, 0x0062, |
| 2511 | "Wrong product ID = 0x%x,0x%x,0x%x.\n", |
| 2512 | mb[1], mb[2], mb[3]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2513 | |
| 2514 | goto chip_diag_failed; |
| 2515 | } |
| 2516 | ha->product_id[0] = mb[1]; |
| 2517 | ha->product_id[1] = mb[2]; |
| 2518 | ha->product_id[2] = mb[3]; |
| 2519 | ha->product_id[3] = mb[4]; |
| 2520 | |
| 2521 | /* Adjust fw RISC transfer size */ |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2522 | if (req->length > 1024) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2523 | ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024; |
| 2524 | else |
| 2525 | ha->fw_transfer_size = REQUEST_ENTRY_SIZE * |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2526 | req->length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2527 | |
| 2528 | if (IS_QLA2200(ha) && |
| 2529 | RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) { |
| 2530 | /* Limit firmware transfer size with a 2200A */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2531 | ql_dbg(ql_dbg_init, vha, 0x007e, "Found QLA2200A Chip.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2532 | |
andrew.vasquez@qlogic.com | ea5b638 | 2006-03-09 14:27:08 -0800 | [diff] [blame] | 2533 | ha->device_type |= DT_ISP2200A; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2534 | ha->fw_transfer_size = 128; |
| 2535 | } |
| 2536 | |
| 2537 | /* Wrap Incoming Mailboxes Test. */ |
| 2538 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 2539 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2540 | ql_dbg(ql_dbg_init, vha, 0x007f, "Checking mailboxes.\n"); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2541 | rval = qla2x00_mbx_reg_test(vha); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2542 | if (rval) |
| 2543 | ql_log(ql_log_warn, vha, 0x0080, |
| 2544 | "Failed mailbox send register test.\n"); |
| 2545 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2546 | /* Flag a successful rval */ |
| 2547 | rval = QLA_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2548 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 2549 | |
| 2550 | chip_diag_failed: |
| 2551 | if (rval) |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2552 | ql_log(ql_log_info, vha, 0x0081, |
| 2553 | "Chip diagnostics **** FAILED ****.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2554 | |
| 2555 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 2556 | |
| 2557 | return (rval); |
| 2558 | } |
| 2559 | |
| 2560 | /** |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2561 | * qla24xx_chip_diag() - Test ISP24xx for proper operation. |
| 2562 | * @ha: HA context |
| 2563 | * |
| 2564 | * Returns 0 on success. |
| 2565 | */ |
| 2566 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2567 | qla24xx_chip_diag(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2568 | { |
| 2569 | int rval; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2570 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2571 | struct req_que *req = ha->req_q_map[0]; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2572 | |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 2573 | if (IS_P3P_TYPE(ha)) |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 2574 | return QLA_SUCCESS; |
| 2575 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2576 | ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2577 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2578 | rval = qla2x00_mbx_reg_test(vha); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2579 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2580 | ql_log(ql_log_warn, vha, 0x0082, |
| 2581 | "Failed mailbox send register test.\n"); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2582 | } else { |
| 2583 | /* Flag a successful rval */ |
| 2584 | rval = QLA_SUCCESS; |
| 2585 | } |
| 2586 | |
| 2587 | return rval; |
| 2588 | } |
| 2589 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2590 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2591 | qla2x00_alloc_fw_dump(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2592 | { |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2593 | int rval; |
| 2594 | uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size, |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2595 | eft_size, fce_size, mq_size; |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 2596 | dma_addr_t tc_dma; |
| 2597 | void *tc; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2598 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2599 | struct req_que *req = ha->req_q_map[0]; |
| 2600 | struct rsp_que *rsp = ha->rsp_q_map[0]; |
Andrew Vasquez | d4e3e04 | 2006-05-17 15:09:50 -0700 | [diff] [blame] | 2601 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2602 | if (ha->fw_dump) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2603 | ql_dbg(ql_dbg_init, vha, 0x00bd, |
| 2604 | "Firmware dump already allocated.\n"); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2605 | return; |
Andrew Vasquez | d4e3e04 | 2006-05-17 15:09:50 -0700 | [diff] [blame] | 2606 | } |
| 2607 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2608 | ha->fw_dumped = 0; |
Hiral Patel | 61f098d | 2014-04-11 16:54:21 -0400 | [diff] [blame] | 2609 | ha->fw_dump_cap_flags = 0; |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 2610 | dump_size = fixed_size = mem_size = eft_size = fce_size = mq_size = 0; |
| 2611 | req_q_size = rsp_q_size = 0; |
| 2612 | |
| 2613 | if (IS_QLA27XX(ha)) |
| 2614 | goto try_fce; |
| 2615 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2616 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) { |
| 2617 | fixed_size = sizeof(struct qla2100_fw_dump); |
| 2618 | } else if (IS_QLA23XX(ha)) { |
| 2619 | fixed_size = offsetof(struct qla2300_fw_dump, data_ram); |
| 2620 | mem_size = (ha->fw_memory_size - 0x11000 + 1) * |
| 2621 | sizeof(uint16_t); |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 2622 | } else if (IS_FWI2_CAPABLE(ha)) { |
Himanshu Madhani | b20f02e | 2015-06-10 11:05:18 -0400 | [diff] [blame] | 2623 | if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 2624 | fixed_size = offsetof(struct qla83xx_fw_dump, ext_mem); |
| 2625 | else if (IS_QLA81XX(ha)) |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 2626 | fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem); |
| 2627 | else if (IS_QLA25XX(ha)) |
| 2628 | fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem); |
| 2629 | else |
| 2630 | fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem); |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 2631 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2632 | mem_size = (ha->fw_memory_size - 0x100000 + 1) * |
| 2633 | sizeof(uint32_t); |
Giridhar Malavali | 050c9bb | 2012-02-09 11:15:33 -0800 | [diff] [blame] | 2634 | if (ha->mqenable) { |
Himanshu Madhani | b20f02e | 2015-06-10 11:05:18 -0400 | [diff] [blame] | 2635 | if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha)) |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 2636 | mq_size = sizeof(struct qla2xxx_mq_chain); |
Giridhar Malavali | 050c9bb | 2012-02-09 11:15:33 -0800 | [diff] [blame] | 2637 | /* |
| 2638 | * Allocate maximum buffer size for all queues. |
| 2639 | * Resizing must be done at end-of-dump processing. |
| 2640 | */ |
| 2641 | mq_size += ha->max_req_queues * |
| 2642 | (req->length * sizeof(request_t)); |
| 2643 | mq_size += ha->max_rsp_queues * |
| 2644 | (rsp->length * sizeof(response_t)); |
| 2645 | } |
Arun Easi | 00876ae | 2013-03-25 02:21:37 -0400 | [diff] [blame] | 2646 | if (ha->tgt.atio_ring) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2647 | mq_size += ha->tgt.atio_q_length * sizeof(request_t); |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 2648 | /* Allocate memory for Fibre Channel Event Buffer. */ |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 2649 | if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) && |
| 2650 | !IS_QLA27XX(ha)) |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 2651 | goto try_eft; |
| 2652 | |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 2653 | try_fce: |
| 2654 | if (ha->fce) |
| 2655 | dma_free_coherent(&ha->pdev->dev, |
| 2656 | FCE_SIZE, ha->fce, ha->fce_dma); |
| 2657 | |
| 2658 | /* Allocate memory for Fibre Channel Event Buffer. */ |
Joe Perches | 0ea85b5 | 2014-06-15 13:37:51 -0700 | [diff] [blame] | 2659 | tc = dma_zalloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma, |
| 2660 | GFP_KERNEL); |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 2661 | if (!tc) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2662 | ql_log(ql_log_warn, vha, 0x00be, |
| 2663 | "Unable to allocate (%d KB) for FCE.\n", |
| 2664 | FCE_SIZE / 1024); |
Anirban Chakraborty | 17d9863 | 2008-12-18 10:06:15 -0800 | [diff] [blame] | 2665 | goto try_eft; |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 2666 | } |
| 2667 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2668 | rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS, |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 2669 | ha->fce_mb, &ha->fce_bufs); |
| 2670 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2671 | ql_log(ql_log_warn, vha, 0x00bf, |
| 2672 | "Unable to initialize FCE (%d).\n", rval); |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 2673 | dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc, |
| 2674 | tc_dma); |
| 2675 | ha->flags.fce_enabled = 0; |
Anirban Chakraborty | 17d9863 | 2008-12-18 10:06:15 -0800 | [diff] [blame] | 2676 | goto try_eft; |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 2677 | } |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 2678 | ql_dbg(ql_dbg_init, vha, 0x00c0, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2679 | "Allocate (%d KB) for FCE...\n", FCE_SIZE / 1024); |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 2680 | |
Giridhar Malavali | 7d9dade | 2009-03-24 09:07:58 -0700 | [diff] [blame] | 2681 | fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE; |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 2682 | ha->flags.fce_enabled = 1; |
| 2683 | ha->fce_dma = tc_dma; |
| 2684 | ha->fce = tc; |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 2685 | |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 2686 | try_eft: |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 2687 | if (ha->eft) |
| 2688 | dma_free_coherent(&ha->pdev->dev, |
| 2689 | EFT_SIZE, ha->eft, ha->eft_dma); |
| 2690 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2691 | /* Allocate memory for Extended Trace Buffer. */ |
Joe Perches | 0ea85b5 | 2014-06-15 13:37:51 -0700 | [diff] [blame] | 2692 | tc = dma_zalloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma, |
| 2693 | GFP_KERNEL); |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 2694 | if (!tc) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2695 | ql_log(ql_log_warn, vha, 0x00c1, |
| 2696 | "Unable to allocate (%d KB) for EFT.\n", |
| 2697 | EFT_SIZE / 1024); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2698 | goto cont_alloc; |
| 2699 | } |
| 2700 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2701 | rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2702 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2703 | ql_log(ql_log_warn, vha, 0x00c2, |
| 2704 | "Unable to initialize EFT (%d).\n", rval); |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 2705 | dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc, |
| 2706 | tc_dma); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2707 | goto cont_alloc; |
| 2708 | } |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 2709 | ql_dbg(ql_dbg_init, vha, 0x00c3, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2710 | "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2711 | |
| 2712 | eft_size = EFT_SIZE; |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 2713 | ha->eft_dma = tc_dma; |
| 2714 | ha->eft = tc; |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2715 | } |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 2716 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2717 | cont_alloc: |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 2718 | if (IS_QLA27XX(ha)) { |
| 2719 | if (!ha->fw_dump_template) { |
| 2720 | ql_log(ql_log_warn, vha, 0x00ba, |
| 2721 | "Failed missing fwdump template\n"); |
| 2722 | return; |
| 2723 | } |
| 2724 | dump_size = qla27xx_fwdt_calculate_dump_size(vha); |
| 2725 | ql_dbg(ql_dbg_init, vha, 0x00fa, |
| 2726 | "-> allocating fwdump (%x bytes)...\n", dump_size); |
| 2727 | goto allocate; |
| 2728 | } |
| 2729 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2730 | req_q_size = req->length * sizeof(request_t); |
| 2731 | rsp_q_size = rsp->length * sizeof(response_t); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2732 | dump_size = offsetof(struct qla2xxx_fw_dump, isp); |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 2733 | 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] | 2734 | ha->chain_offset = dump_size; |
| 2735 | dump_size += mq_size + fce_size; |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2736 | |
Quinn Tran | b945e77 | 2017-06-13 20:47:29 -0700 | [diff] [blame] | 2737 | if (ha->exchoffld_buf) |
| 2738 | dump_size += sizeof(struct qla2xxx_offld_chain) + |
| 2739 | ha->exchoffld_size; |
| 2740 | if (ha->exlogin_buf) |
| 2741 | dump_size += sizeof(struct qla2xxx_offld_chain) + |
| 2742 | ha->exlogin_size; |
| 2743 | |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 2744 | allocate: |
Andrew Vasquez | d4e3e04 | 2006-05-17 15:09:50 -0700 | [diff] [blame] | 2745 | ha->fw_dump = vmalloc(dump_size); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2746 | if (!ha->fw_dump) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2747 | ql_log(ql_log_warn, vha, 0x00c4, |
| 2748 | "Unable to allocate (%d KB) for firmware dump.\n", |
| 2749 | dump_size / 1024); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2750 | |
Madhuranath Iyengar | e30d175 | 2010-10-15 11:27:46 -0700 | [diff] [blame] | 2751 | if (ha->fce) { |
| 2752 | dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce, |
| 2753 | ha->fce_dma); |
| 2754 | ha->fce = NULL; |
| 2755 | ha->fce_dma = 0; |
| 2756 | } |
| 2757 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2758 | if (ha->eft) { |
| 2759 | dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft, |
| 2760 | ha->eft_dma); |
| 2761 | ha->eft = NULL; |
| 2762 | ha->eft_dma = 0; |
| 2763 | } |
| 2764 | return; |
| 2765 | } |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 2766 | ha->fw_dump_len = dump_size; |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 2767 | ql_dbg(ql_dbg_init, vha, 0x00c5, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2768 | "Allocated (%d KB) for firmware dump.\n", dump_size / 1024); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2769 | |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 2770 | if (IS_QLA27XX(ha)) |
| 2771 | return; |
| 2772 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2773 | ha->fw_dump->signature[0] = 'Q'; |
| 2774 | ha->fw_dump->signature[1] = 'L'; |
| 2775 | ha->fw_dump->signature[2] = 'G'; |
| 2776 | ha->fw_dump->signature[3] = 'C'; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2777 | ha->fw_dump->version = htonl(1); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2778 | |
| 2779 | ha->fw_dump->fixed_size = htonl(fixed_size); |
| 2780 | ha->fw_dump->mem_size = htonl(mem_size); |
| 2781 | ha->fw_dump->req_q_size = htonl(req_q_size); |
| 2782 | ha->fw_dump->rsp_q_size = htonl(rsp_q_size); |
| 2783 | |
| 2784 | ha->fw_dump->eft_size = htonl(eft_size); |
| 2785 | ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma)); |
| 2786 | ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma)); |
| 2787 | |
| 2788 | ha->fw_dump->header_size = |
| 2789 | htonl(offsetof(struct qla2xxx_fw_dump, isp)); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2790 | } |
| 2791 | |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 2792 | static int |
| 2793 | qla81xx_mpi_sync(scsi_qla_host_t *vha) |
| 2794 | { |
| 2795 | #define MPS_MASK 0xe0 |
| 2796 | int rval; |
| 2797 | uint16_t dc; |
| 2798 | uint32_t dw; |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 2799 | |
| 2800 | if (!IS_QLA81XX(vha->hw)) |
| 2801 | return QLA_SUCCESS; |
| 2802 | |
| 2803 | rval = qla2x00_write_ram_word(vha, 0x7c00, 1); |
| 2804 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2805 | ql_log(ql_log_warn, vha, 0x0105, |
| 2806 | "Unable to acquire semaphore.\n"); |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 2807 | goto done; |
| 2808 | } |
| 2809 | |
| 2810 | pci_read_config_word(vha->hw->pdev, 0x54, &dc); |
| 2811 | rval = qla2x00_read_ram_word(vha, 0x7a15, &dw); |
| 2812 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2813 | ql_log(ql_log_warn, vha, 0x0067, "Unable to read sync.\n"); |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 2814 | goto done_release; |
| 2815 | } |
| 2816 | |
| 2817 | dc &= MPS_MASK; |
| 2818 | if (dc == (dw & MPS_MASK)) |
| 2819 | goto done_release; |
| 2820 | |
| 2821 | dw &= ~MPS_MASK; |
| 2822 | dw |= dc; |
| 2823 | rval = qla2x00_write_ram_word(vha, 0x7a15, dw); |
| 2824 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2825 | ql_log(ql_log_warn, vha, 0x0114, "Unable to gain sync.\n"); |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 2826 | } |
| 2827 | |
| 2828 | done_release: |
| 2829 | rval = qla2x00_write_ram_word(vha, 0x7c00, 0); |
| 2830 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2831 | ql_log(ql_log_warn, vha, 0x006d, |
| 2832 | "Unable to release semaphore.\n"); |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 2833 | } |
| 2834 | |
| 2835 | done: |
| 2836 | return rval; |
| 2837 | } |
| 2838 | |
Chad Dupuis | 8d93f55 | 2013-01-30 03:34:37 -0500 | [diff] [blame] | 2839 | int |
| 2840 | qla2x00_alloc_outstanding_cmds(struct qla_hw_data *ha, struct req_que *req) |
| 2841 | { |
| 2842 | /* Don't try to reallocate the array */ |
| 2843 | if (req->outstanding_cmds) |
| 2844 | return QLA_SUCCESS; |
| 2845 | |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 2846 | if (!IS_FWI2_CAPABLE(ha)) |
Chad Dupuis | 8d93f55 | 2013-01-30 03:34:37 -0500 | [diff] [blame] | 2847 | req->num_outstanding_cmds = DEFAULT_OUTSTANDING_COMMANDS; |
| 2848 | else { |
Quinn Tran | 03e8c68 | 2015-12-17 14:56:59 -0500 | [diff] [blame] | 2849 | if (ha->cur_fw_xcb_count <= ha->cur_fw_iocb_count) |
| 2850 | req->num_outstanding_cmds = ha->cur_fw_xcb_count; |
Chad Dupuis | 8d93f55 | 2013-01-30 03:34:37 -0500 | [diff] [blame] | 2851 | else |
Quinn Tran | 03e8c68 | 2015-12-17 14:56:59 -0500 | [diff] [blame] | 2852 | req->num_outstanding_cmds = ha->cur_fw_iocb_count; |
Chad Dupuis | 8d93f55 | 2013-01-30 03:34:37 -0500 | [diff] [blame] | 2853 | } |
| 2854 | |
| 2855 | req->outstanding_cmds = kzalloc(sizeof(srb_t *) * |
| 2856 | req->num_outstanding_cmds, GFP_KERNEL); |
| 2857 | |
| 2858 | if (!req->outstanding_cmds) { |
| 2859 | /* |
| 2860 | * Try to allocate a minimal size just so we can get through |
| 2861 | * initialization. |
| 2862 | */ |
| 2863 | req->num_outstanding_cmds = MIN_OUTSTANDING_COMMANDS; |
| 2864 | req->outstanding_cmds = kzalloc(sizeof(srb_t *) * |
| 2865 | req->num_outstanding_cmds, GFP_KERNEL); |
| 2866 | |
| 2867 | if (!req->outstanding_cmds) { |
| 2868 | ql_log(ql_log_fatal, NULL, 0x0126, |
| 2869 | "Failed to allocate memory for " |
| 2870 | "outstanding_cmds for req_que %p.\n", req); |
| 2871 | req->num_outstanding_cmds = 0; |
| 2872 | return QLA_FUNCTION_FAILED; |
| 2873 | } |
| 2874 | } |
| 2875 | |
| 2876 | return QLA_SUCCESS; |
| 2877 | } |
| 2878 | |
Quinn Tran | e4e3a2c | 2017-08-23 15:05:07 -0700 | [diff] [blame] | 2879 | #define PRINT_FIELD(_field, _flag, _str) { \ |
| 2880 | if (a0->_field & _flag) {\ |
| 2881 | if (p) {\ |
| 2882 | strcat(ptr, "|");\ |
| 2883 | ptr++;\ |
| 2884 | leftover--;\ |
| 2885 | } \ |
| 2886 | len = snprintf(ptr, leftover, "%s", _str); \ |
| 2887 | p = 1;\ |
| 2888 | leftover -= len;\ |
| 2889 | ptr += len; \ |
| 2890 | } \ |
| 2891 | } |
| 2892 | |
| 2893 | static void qla2xxx_print_sfp_info(struct scsi_qla_host *vha) |
| 2894 | { |
| 2895 | #define STR_LEN 64 |
| 2896 | struct sff_8247_a0 *a0 = (struct sff_8247_a0 *)vha->hw->sfp_data; |
| 2897 | u8 str[STR_LEN], *ptr, p; |
| 2898 | int leftover, len; |
| 2899 | |
| 2900 | memset(str, 0, STR_LEN); |
| 2901 | snprintf(str, SFF_VEN_NAME_LEN+1, a0->vendor_name); |
| 2902 | ql_dbg(ql_dbg_init, vha, 0x015a, |
| 2903 | "SFP MFG Name: %s\n", str); |
| 2904 | |
| 2905 | memset(str, 0, STR_LEN); |
| 2906 | snprintf(str, SFF_PART_NAME_LEN+1, a0->vendor_pn); |
| 2907 | ql_dbg(ql_dbg_init, vha, 0x015c, |
| 2908 | "SFP Part Name: %s\n", str); |
| 2909 | |
| 2910 | /* media */ |
| 2911 | memset(str, 0, STR_LEN); |
| 2912 | ptr = str; |
| 2913 | leftover = STR_LEN; |
| 2914 | p = len = 0; |
| 2915 | PRINT_FIELD(fc_med_cc9, FC_MED_TW, "Twin AX"); |
| 2916 | PRINT_FIELD(fc_med_cc9, FC_MED_TP, "Twisted Pair"); |
| 2917 | PRINT_FIELD(fc_med_cc9, FC_MED_MI, "Min Coax"); |
| 2918 | PRINT_FIELD(fc_med_cc9, FC_MED_TV, "Video Coax"); |
| 2919 | PRINT_FIELD(fc_med_cc9, FC_MED_M6, "MultiMode 62.5um"); |
| 2920 | PRINT_FIELD(fc_med_cc9, FC_MED_M5, "MultiMode 50um"); |
| 2921 | PRINT_FIELD(fc_med_cc9, FC_MED_SM, "SingleMode"); |
| 2922 | ql_dbg(ql_dbg_init, vha, 0x0160, |
| 2923 | "SFP Media: %s\n", str); |
| 2924 | |
| 2925 | /* link length */ |
| 2926 | memset(str, 0, STR_LEN); |
| 2927 | ptr = str; |
| 2928 | leftover = STR_LEN; |
| 2929 | p = len = 0; |
| 2930 | PRINT_FIELD(fc_ll_cc7, FC_LL_VL, "Very Long"); |
| 2931 | PRINT_FIELD(fc_ll_cc7, FC_LL_S, "Short"); |
| 2932 | PRINT_FIELD(fc_ll_cc7, FC_LL_I, "Intermediate"); |
| 2933 | PRINT_FIELD(fc_ll_cc7, FC_LL_L, "Long"); |
| 2934 | PRINT_FIELD(fc_ll_cc7, FC_LL_M, "Medium"); |
| 2935 | ql_dbg(ql_dbg_init, vha, 0x0196, |
| 2936 | "SFP Link Length: %s\n", str); |
| 2937 | |
| 2938 | memset(str, 0, STR_LEN); |
| 2939 | ptr = str; |
| 2940 | leftover = STR_LEN; |
| 2941 | p = len = 0; |
| 2942 | PRINT_FIELD(fc_ll_cc7, FC_LL_SA, "Short Wave (SA)"); |
| 2943 | PRINT_FIELD(fc_ll_cc7, FC_LL_LC, "Long Wave(LC)"); |
| 2944 | PRINT_FIELD(fc_tec_cc8, FC_TEC_SN, "Short Wave (SN)"); |
| 2945 | PRINT_FIELD(fc_tec_cc8, FC_TEC_SL, "Short Wave (SL)"); |
| 2946 | PRINT_FIELD(fc_tec_cc8, FC_TEC_LL, "Long Wave (LL)"); |
| 2947 | ql_dbg(ql_dbg_init, vha, 0x016e, |
| 2948 | "SFP FC Link Tech: %s\n", str); |
| 2949 | |
| 2950 | if (a0->length_km) |
| 2951 | ql_dbg(ql_dbg_init, vha, 0x016f, |
| 2952 | "SFP Distant: %d km\n", a0->length_km); |
| 2953 | if (a0->length_100m) |
| 2954 | ql_dbg(ql_dbg_init, vha, 0x0170, |
| 2955 | "SFP Distant: %d m\n", a0->length_100m*100); |
| 2956 | if (a0->length_50um_10m) |
| 2957 | ql_dbg(ql_dbg_init, vha, 0x0189, |
| 2958 | "SFP Distant (WL=50um): %d m\n", a0->length_50um_10m * 10); |
| 2959 | if (a0->length_62um_10m) |
| 2960 | ql_dbg(ql_dbg_init, vha, 0x018a, |
| 2961 | "SFP Distant (WL=62.5um): %d m\n", a0->length_62um_10m * 10); |
| 2962 | if (a0->length_om4_10m) |
| 2963 | ql_dbg(ql_dbg_init, vha, 0x0194, |
| 2964 | "SFP Distant (OM4): %d m\n", a0->length_om4_10m * 10); |
| 2965 | if (a0->length_om3_10m) |
| 2966 | ql_dbg(ql_dbg_init, vha, 0x0195, |
| 2967 | "SFP Distant (OM3): %d m\n", a0->length_om3_10m * 10); |
| 2968 | } |
| 2969 | |
| 2970 | |
| 2971 | /* |
| 2972 | * Return Code: |
| 2973 | * QLA_SUCCESS: no action |
| 2974 | * QLA_INTERFACE_ERROR: SFP is not there. |
| 2975 | * QLA_FUNCTION_FAILED: detected New SFP |
| 2976 | */ |
| 2977 | int |
| 2978 | qla24xx_detect_sfp(scsi_qla_host_t *vha) |
| 2979 | { |
| 2980 | int rc = QLA_SUCCESS; |
| 2981 | struct sff_8247_a0 *a; |
| 2982 | struct qla_hw_data *ha = vha->hw; |
| 2983 | |
| 2984 | if (!AUTO_DETECT_SFP_SUPPORT(vha)) |
| 2985 | goto out; |
| 2986 | |
| 2987 | rc = qla2x00_read_sfp_dev(vha, NULL, 0); |
| 2988 | if (rc) |
| 2989 | goto out; |
| 2990 | |
| 2991 | a = (struct sff_8247_a0 *)vha->hw->sfp_data; |
| 2992 | qla2xxx_print_sfp_info(vha); |
| 2993 | |
| 2994 | if (a->fc_ll_cc7 & FC_LL_VL || a->fc_ll_cc7 & FC_LL_L) { |
| 2995 | /* long range */ |
| 2996 | ha->flags.detected_lr_sfp = 1; |
| 2997 | |
| 2998 | if (a->length_km > 5 || a->length_100m > 50) |
| 2999 | ha->long_range_distance = LR_DISTANCE_10K; |
| 3000 | else |
| 3001 | ha->long_range_distance = LR_DISTANCE_5K; |
| 3002 | |
| 3003 | if (ha->flags.detected_lr_sfp != ha->flags.using_lr_setting) |
| 3004 | ql_dbg(ql_dbg_async, vha, 0x507b, |
| 3005 | "Detected Long Range SFP.\n"); |
| 3006 | } else { |
| 3007 | /* short range */ |
| 3008 | ha->flags.detected_lr_sfp = 0; |
| 3009 | if (ha->flags.using_lr_setting) |
| 3010 | ql_dbg(ql_dbg_async, vha, 0x5084, |
| 3011 | "Detected Short Range SFP.\n"); |
| 3012 | } |
| 3013 | |
| 3014 | if (!vha->flags.init_done) |
| 3015 | rc = QLA_SUCCESS; |
| 3016 | out: |
| 3017 | return rc; |
| 3018 | } |
| 3019 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3020 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3021 | * qla2x00_setup_chip() - Load and start RISC firmware. |
| 3022 | * @ha: HA context |
| 3023 | * |
| 3024 | * Returns 0 on success. |
| 3025 | */ |
| 3026 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3027 | qla2x00_setup_chip(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3028 | { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3029 | int rval; |
| 3030 | uint32_t srisc_address = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3031 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3db0652 | 2008-01-31 12:33:49 -0800 | [diff] [blame] | 3032 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
| 3033 | unsigned long flags; |
Andrew Vasquez | dda772e | 2009-03-24 09:08:00 -0700 | [diff] [blame] | 3034 | uint16_t fw_major_version; |
Andrew Vasquez | 3db0652 | 2008-01-31 12:33:49 -0800 | [diff] [blame] | 3035 | |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 3036 | if (IS_P3P_TYPE(ha)) { |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 3037 | rval = ha->isp_ops->load_risc(vha, &srisc_address); |
Andrew Vasquez | 14e303d | 2010-07-23 15:28:29 +0500 | [diff] [blame] | 3038 | if (rval == QLA_SUCCESS) { |
| 3039 | qla2x00_stop_firmware(vha); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 3040 | goto enable_82xx_npiv; |
Andrew Vasquez | 14e303d | 2010-07-23 15:28:29 +0500 | [diff] [blame] | 3041 | } else |
Giridhar Malavali | b963752 | 2010-05-28 15:08:15 -0700 | [diff] [blame] | 3042 | goto failed; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 3043 | } |
| 3044 | |
Andrew Vasquez | 3db0652 | 2008-01-31 12:33:49 -0800 | [diff] [blame] | 3045 | if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) { |
| 3046 | /* Disable SRAM, Instruction RAM and GP RAM parity. */ |
| 3047 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 3048 | WRT_REG_WORD(®->hccr, (HCCR_ENABLE_PARITY + 0x0)); |
| 3049 | RD_REG_WORD(®->hccr); |
| 3050 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 3051 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3052 | |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 3053 | qla81xx_mpi_sync(vha); |
| 3054 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3055 | /* Load firmware sequences */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3056 | rval = ha->isp_ops->load_risc(vha, &srisc_address); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3057 | if (rval == QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3058 | ql_dbg(ql_dbg_init, vha, 0x00c9, |
| 3059 | "Verifying Checksum of loaded RISC code.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3060 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3061 | rval = qla2x00_verify_checksum(vha, srisc_address); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3062 | if (rval == QLA_SUCCESS) { |
| 3063 | /* Start firmware execution. */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3064 | ql_dbg(ql_dbg_init, vha, 0x00ca, |
| 3065 | "Starting firmware.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3066 | |
Himanshu Madhani | b0d6cab | 2015-12-17 14:56:56 -0500 | [diff] [blame] | 3067 | if (ql2xexlogins) |
| 3068 | ha->flags.exlogins_enabled = 1; |
| 3069 | |
Quinn Tran | 99e1b68 | 2017-06-02 09:12:03 -0700 | [diff] [blame] | 3070 | if (qla_is_exch_offld_enabled(vha)) |
Himanshu Madhani | 2f56a7f | 2015-12-17 14:56:57 -0500 | [diff] [blame] | 3071 | ha->flags.exchoffld_enabled = 1; |
| 3072 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3073 | rval = qla2x00_execute_fw(vha, srisc_address); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3074 | /* Retrieve firmware information. */ |
Andrew Vasquez | dda772e | 2009-03-24 09:08:00 -0700 | [diff] [blame] | 3075 | if (rval == QLA_SUCCESS) { |
Quinn Tran | e4e3a2c | 2017-08-23 15:05:07 -0700 | [diff] [blame] | 3076 | qla24xx_detect_sfp(vha); |
| 3077 | |
Himanshu Madhani | b0d6cab | 2015-12-17 14:56:56 -0500 | [diff] [blame] | 3078 | rval = qla2x00_set_exlogins_buffer(vha); |
| 3079 | if (rval != QLA_SUCCESS) |
| 3080 | goto failed; |
| 3081 | |
Himanshu Madhani | 2f56a7f | 2015-12-17 14:56:57 -0500 | [diff] [blame] | 3082 | rval = qla2x00_set_exchoffld_buffer(vha); |
| 3083 | if (rval != QLA_SUCCESS) |
| 3084 | goto failed; |
| 3085 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 3086 | enable_82xx_npiv: |
Andrew Vasquez | dda772e | 2009-03-24 09:08:00 -0700 | [diff] [blame] | 3087 | fw_major_version = ha->fw_major_version; |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 3088 | if (IS_P3P_TYPE(ha)) |
Giridhar Malavali | 3173167 | 2011-08-16 11:31:54 -0700 | [diff] [blame] | 3089 | qla82xx_check_md_needed(vha); |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 3090 | else |
| 3091 | rval = qla2x00_get_fw_version(vha); |
Andrew Vasquez | ca9e9c3 | 2009-06-03 09:55:20 -0700 | [diff] [blame] | 3092 | if (rval != QLA_SUCCESS) |
| 3093 | goto failed; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3094 | ha->flags.npiv_supported = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3095 | if (IS_QLA2XXX_MIDTYPE(ha) && |
Mike Hernandez | 946fb89 | 2008-08-13 21:36:59 -0700 | [diff] [blame] | 3096 | (ha->fw_attributes & BIT_2)) { |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3097 | ha->flags.npiv_supported = 1; |
Seokmann Ju | 4d0ea24 | 2007-09-20 14:07:43 -0700 | [diff] [blame] | 3098 | if ((!ha->max_npiv_vports) || |
| 3099 | ((ha->max_npiv_vports + 1) % |
Andrew Vasquez | eb66dc6 | 2007-11-12 10:30:58 -0800 | [diff] [blame] | 3100 | MIN_MULTI_ID_FABRIC)) |
Seokmann Ju | 4d0ea24 | 2007-09-20 14:07:43 -0700 | [diff] [blame] | 3101 | ha->max_npiv_vports = |
Andrew Vasquez | eb66dc6 | 2007-11-12 10:30:58 -0800 | [diff] [blame] | 3102 | MIN_MULTI_ID_FABRIC - 1; |
Seokmann Ju | 4d0ea24 | 2007-09-20 14:07:43 -0700 | [diff] [blame] | 3103 | } |
Quinn Tran | 03e8c68 | 2015-12-17 14:56:59 -0500 | [diff] [blame] | 3104 | qla2x00_get_resource_cnts(vha); |
Andrew Vasquez | d743de6 | 2009-03-24 09:08:15 -0700 | [diff] [blame] | 3105 | |
Chad Dupuis | 8d93f55 | 2013-01-30 03:34:37 -0500 | [diff] [blame] | 3106 | /* |
| 3107 | * Allocate the array of outstanding commands |
| 3108 | * now that we know the firmware resources. |
| 3109 | */ |
| 3110 | rval = qla2x00_alloc_outstanding_cmds(ha, |
| 3111 | vha->req); |
| 3112 | if (rval != QLA_SUCCESS) |
| 3113 | goto failed; |
| 3114 | |
Saurav Kashyap | be5ea3c | 2011-11-18 09:02:11 -0800 | [diff] [blame] | 3115 | if (!fw_major_version && ql2xallocfwdump |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 3116 | && !(IS_P3P_TYPE(ha))) |
Giridhar Malavali | 08de284 | 2011-08-16 11:31:44 -0700 | [diff] [blame] | 3117 | qla2x00_alloc_fw_dump(vha); |
Chad Dupuis | 3b6e5b9 | 2013-10-30 03:38:09 -0400 | [diff] [blame] | 3118 | } else { |
| 3119 | goto failed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3120 | } |
| 3121 | } else { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3122 | ql_log(ql_log_fatal, vha, 0x00cd, |
| 3123 | "ISP Firmware failed checksum.\n"); |
| 3124 | goto failed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3125 | } |
Andrew Vasquez | c74d88a | 2012-08-22 14:21:19 -0400 | [diff] [blame] | 3126 | } else |
| 3127 | goto failed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3128 | |
Andrew Vasquez | 3db0652 | 2008-01-31 12:33:49 -0800 | [diff] [blame] | 3129 | if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) { |
| 3130 | /* Enable proper parity. */ |
| 3131 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 3132 | if (IS_QLA2300(ha)) |
| 3133 | /* SRAM parity */ |
| 3134 | WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x1); |
| 3135 | else |
| 3136 | /* SRAM, Instruction RAM and GP RAM parity */ |
| 3137 | WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x7); |
| 3138 | RD_REG_WORD(®->hccr); |
| 3139 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 3140 | } |
| 3141 | |
Chad Dupuis | f3982d8 | 2014-09-25 05:16:57 -0400 | [diff] [blame] | 3142 | if (IS_QLA27XX(ha)) |
| 3143 | ha->flags.fac_supported = 1; |
| 3144 | else if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) { |
Joe Carnuccio | 1d2874d | 2009-03-24 09:08:06 -0700 | [diff] [blame] | 3145 | uint32_t size; |
| 3146 | |
| 3147 | rval = qla81xx_fac_get_sector_size(vha, &size); |
| 3148 | if (rval == QLA_SUCCESS) { |
| 3149 | ha->flags.fac_supported = 1; |
| 3150 | ha->fdt_block_size = size << 2; |
| 3151 | } else { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3152 | ql_log(ql_log_warn, vha, 0x00ce, |
Joe Carnuccio | 1d2874d | 2009-03-24 09:08:06 -0700 | [diff] [blame] | 3153 | "Unsupported FAC firmware (%d.%02d.%02d).\n", |
| 3154 | ha->fw_major_version, ha->fw_minor_version, |
| 3155 | ha->fw_subminor_version); |
Joe Carnuccio | 1ca60e3 | 2014-02-26 04:15:02 -0500 | [diff] [blame] | 3156 | |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 3157 | if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) { |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 3158 | ha->flags.fac_supported = 0; |
| 3159 | rval = QLA_SUCCESS; |
| 3160 | } |
Joe Carnuccio | 1d2874d | 2009-03-24 09:08:06 -0700 | [diff] [blame] | 3161 | } |
| 3162 | } |
Andrew Vasquez | ca9e9c3 | 2009-06-03 09:55:20 -0700 | [diff] [blame] | 3163 | failed: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3164 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3165 | ql_log(ql_log_fatal, vha, 0x00cf, |
| 3166 | "Setup chip ****FAILED****.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3167 | } |
| 3168 | |
| 3169 | return (rval); |
| 3170 | } |
| 3171 | |
| 3172 | /** |
| 3173 | * qla2x00_init_response_q_entries() - Initializes response queue entries. |
| 3174 | * @ha: HA context |
| 3175 | * |
| 3176 | * Beginning of request ring has initialization control block already built |
| 3177 | * by nvram config routine. |
| 3178 | * |
| 3179 | * Returns 0 on success. |
| 3180 | */ |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3181 | void |
| 3182 | qla2x00_init_response_q_entries(struct rsp_que *rsp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3183 | { |
| 3184 | uint16_t cnt; |
| 3185 | response_t *pkt; |
| 3186 | |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 3187 | rsp->ring_ptr = rsp->ring; |
| 3188 | rsp->ring_index = 0; |
| 3189 | rsp->status_srb = NULL; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3190 | pkt = rsp->ring_ptr; |
| 3191 | for (cnt = 0; cnt < rsp->length; cnt++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3192 | pkt->signature = RESPONSE_PROCESSED; |
| 3193 | pkt++; |
| 3194 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3195 | } |
| 3196 | |
| 3197 | /** |
| 3198 | * qla2x00_update_fw_options() - Read and process firmware options. |
| 3199 | * @ha: HA context |
| 3200 | * |
| 3201 | * Returns 0 on success. |
| 3202 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 3203 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3204 | qla2x00_update_fw_options(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3205 | { |
| 3206 | uint16_t swing, emphasis, tx_sens, rx_sens; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3207 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3208 | |
| 3209 | memset(ha->fw_options, 0, sizeof(ha->fw_options)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3210 | qla2x00_get_fw_options(vha, ha->fw_options); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3211 | |
| 3212 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) |
| 3213 | return; |
| 3214 | |
| 3215 | /* Serial Link options. */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3216 | ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0115, |
| 3217 | "Serial link options.\n"); |
| 3218 | ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0109, |
| 3219 | (uint8_t *)&ha->fw_seriallink_options, |
| 3220 | sizeof(ha->fw_seriallink_options)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3221 | |
| 3222 | ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING; |
| 3223 | if (ha->fw_seriallink_options[3] & BIT_2) { |
| 3224 | ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING; |
| 3225 | |
| 3226 | /* 1G settings */ |
| 3227 | swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0); |
| 3228 | emphasis = (ha->fw_seriallink_options[2] & |
| 3229 | (BIT_4 | BIT_3)) >> 3; |
| 3230 | tx_sens = ha->fw_seriallink_options[0] & |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 3231 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3232 | rx_sens = (ha->fw_seriallink_options[0] & |
| 3233 | (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4; |
| 3234 | ha->fw_options[10] = (emphasis << 14) | (swing << 8); |
| 3235 | if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) { |
| 3236 | if (rx_sens == 0x0) |
| 3237 | rx_sens = 0x3; |
| 3238 | ha->fw_options[10] |= (tx_sens << 4) | rx_sens; |
| 3239 | } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) |
| 3240 | ha->fw_options[10] |= BIT_5 | |
| 3241 | ((rx_sens & (BIT_1 | BIT_0)) << 2) | |
| 3242 | (tx_sens & (BIT_1 | BIT_0)); |
| 3243 | |
| 3244 | /* 2G settings */ |
| 3245 | swing = (ha->fw_seriallink_options[2] & |
| 3246 | (BIT_7 | BIT_6 | BIT_5)) >> 5; |
| 3247 | emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0); |
| 3248 | tx_sens = ha->fw_seriallink_options[1] & |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 3249 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3250 | rx_sens = (ha->fw_seriallink_options[1] & |
| 3251 | (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4; |
| 3252 | ha->fw_options[11] = (emphasis << 14) | (swing << 8); |
| 3253 | if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) { |
| 3254 | if (rx_sens == 0x0) |
| 3255 | rx_sens = 0x3; |
| 3256 | ha->fw_options[11] |= (tx_sens << 4) | rx_sens; |
| 3257 | } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) |
| 3258 | ha->fw_options[11] |= BIT_5 | |
| 3259 | ((rx_sens & (BIT_1 | BIT_0)) << 2) | |
| 3260 | (tx_sens & (BIT_1 | BIT_0)); |
| 3261 | } |
| 3262 | |
| 3263 | /* FCP2 options. */ |
| 3264 | /* Return command IOCBs without waiting for an ABTS to complete. */ |
| 3265 | ha->fw_options[3] |= BIT_13; |
| 3266 | |
| 3267 | /* LED scheme. */ |
| 3268 | if (ha->flags.enable_led_scheme) |
| 3269 | ha->fw_options[2] |= BIT_12; |
| 3270 | |
andrew.vasquez@qlogic.com | 48c02fd | 2006-03-09 14:27:18 -0800 | [diff] [blame] | 3271 | /* Detect ISP6312. */ |
| 3272 | if (IS_QLA6312(ha)) |
| 3273 | ha->fw_options[2] |= BIT_13; |
| 3274 | |
Giridhar Malavali | 088d09d | 2016-07-06 11:14:20 -0400 | [diff] [blame] | 3275 | /* Set Retry FLOGI in case of P2P connection */ |
| 3276 | if (ha->operating_mode == P2P) { |
| 3277 | ha->fw_options[2] |= BIT_3; |
| 3278 | ql_dbg(ql_dbg_disc, vha, 0x2100, |
| 3279 | "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n", |
| 3280 | __func__, ha->fw_options[2]); |
| 3281 | } |
| 3282 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3283 | /* Update firmware options. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3284 | qla2x00_set_fw_options(vha, ha->fw_options); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3285 | } |
| 3286 | |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 3287 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3288 | qla24xx_update_fw_options(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3289 | { |
| 3290 | int rval; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3291 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3292 | |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 3293 | if (IS_P3P_TYPE(ha)) |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 3294 | return; |
| 3295 | |
Himanshu Madhani | f198caf | 2016-01-27 12:03:30 -0500 | [diff] [blame] | 3296 | /* Hold status IOCBs until ABTS response received. */ |
| 3297 | if (ql2xfwholdabts) |
| 3298 | ha->fw_options[3] |= BIT_12; |
| 3299 | |
Giridhar Malavali | 088d09d | 2016-07-06 11:14:20 -0400 | [diff] [blame] | 3300 | /* Set Retry FLOGI in case of P2P connection */ |
| 3301 | if (ha->operating_mode == P2P) { |
| 3302 | ha->fw_options[2] |= BIT_3; |
| 3303 | ql_dbg(ql_dbg_disc, vha, 0x2101, |
| 3304 | "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n", |
| 3305 | __func__, ha->fw_options[2]); |
| 3306 | } |
| 3307 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 3308 | /* Move PUREX, ABTS RX & RIDA to ATIOQ */ |
Quinn Tran | 3c4810f | 2017-06-02 09:11:53 -0700 | [diff] [blame] | 3309 | if (ql2xmvasynctoatio && |
| 3310 | (IS_QLA83XX(ha) || IS_QLA27XX(ha))) { |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 3311 | if (qla_tgt_mode_enabled(vha) || |
| 3312 | qla_dual_mode_enabled(vha)) |
| 3313 | ha->fw_options[2] |= BIT_11; |
| 3314 | else |
| 3315 | ha->fw_options[2] &= ~BIT_11; |
| 3316 | } |
| 3317 | |
Quinn Tran | f7e761f | 2017-06-02 09:12:02 -0700 | [diff] [blame] | 3318 | if (IS_QLA25XX(ha) || IS_QLA83XX(ha) || IS_QLA27XX(ha)) { |
| 3319 | /* |
| 3320 | * Tell FW to track each exchange to prevent |
| 3321 | * driver from using stale exchange. |
| 3322 | */ |
| 3323 | if (qla_tgt_mode_enabled(vha) || |
| 3324 | qla_dual_mode_enabled(vha)) |
| 3325 | ha->fw_options[2] |= BIT_4; |
| 3326 | else |
| 3327 | ha->fw_options[2] &= ~BIT_4; |
| 3328 | } |
| 3329 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 3330 | ql_dbg(ql_dbg_init, vha, 0x00e8, |
| 3331 | "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n", |
| 3332 | __func__, ha->fw_options[1], ha->fw_options[2], |
| 3333 | ha->fw_options[3], vha->host->active_mode); |
Quinn Tran | 3c4810f | 2017-06-02 09:11:53 -0700 | [diff] [blame] | 3334 | |
| 3335 | if (ha->fw_options[1] || ha->fw_options[2] || ha->fw_options[3]) |
| 3336 | qla2x00_set_fw_options(vha, ha->fw_options); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 3337 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3338 | /* Update Serial Link options. */ |
andrew.vasquez@qlogic.com | f94097e | 2006-01-13 17:05:32 -0800 | [diff] [blame] | 3339 | if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3340 | return; |
| 3341 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3342 | rval = qla2x00_set_serdes_params(vha, |
andrew.vasquez@qlogic.com | f94097e | 2006-01-13 17:05:32 -0800 | [diff] [blame] | 3343 | le16_to_cpu(ha->fw_seriallink_options24[1]), |
| 3344 | le16_to_cpu(ha->fw_seriallink_options24[2]), |
| 3345 | le16_to_cpu(ha->fw_seriallink_options24[3])); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3346 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3347 | ql_log(ql_log_warn, vha, 0x0104, |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3348 | "Unable to update Serial Link options (%x).\n", rval); |
| 3349 | } |
| 3350 | } |
| 3351 | |
| 3352 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3353 | qla2x00_config_rings(struct scsi_qla_host *vha) |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 3354 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3355 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 3356 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3357 | struct req_que *req = ha->req_q_map[0]; |
| 3358 | struct rsp_que *rsp = ha->rsp_q_map[0]; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 3359 | |
| 3360 | /* Setup ring parameters in initialization control block. */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3361 | ha->init_cb->request_q_outpointer = cpu_to_le16(0); |
| 3362 | ha->init_cb->response_q_inpointer = cpu_to_le16(0); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3363 | ha->init_cb->request_q_length = cpu_to_le16(req->length); |
| 3364 | ha->init_cb->response_q_length = cpu_to_le16(rsp->length); |
| 3365 | ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma)); |
| 3366 | ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma)); |
| 3367 | ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma)); |
| 3368 | 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] | 3369 | |
| 3370 | WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0); |
| 3371 | WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0); |
| 3372 | WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0); |
| 3373 | WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0); |
| 3374 | RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */ |
| 3375 | } |
| 3376 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3377 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3378 | qla24xx_config_rings(struct scsi_qla_host *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3379 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3380 | struct qla_hw_data *ha = vha->hw; |
Bart Van Assche | 118e2ef | 2015-07-09 07:24:27 -0700 | [diff] [blame] | 3381 | device_reg_t *reg = ISP_QUE_REG(ha, 0); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3382 | struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp; |
| 3383 | struct qla_msix_entry *msix; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3384 | struct init_cb_24xx *icb; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3385 | uint16_t rid = 0; |
| 3386 | struct req_que *req = ha->req_q_map[0]; |
| 3387 | struct rsp_que *rsp = ha->rsp_q_map[0]; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3388 | |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 3389 | /* Setup ring parameters in initialization control block. */ |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3390 | icb = (struct init_cb_24xx *)ha->init_cb; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3391 | icb->request_q_outpointer = cpu_to_le16(0); |
| 3392 | icb->response_q_inpointer = cpu_to_le16(0); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3393 | icb->request_q_length = cpu_to_le16(req->length); |
| 3394 | icb->response_q_length = cpu_to_le16(rsp->length); |
| 3395 | icb->request_q_address[0] = cpu_to_le32(LSD(req->dma)); |
| 3396 | icb->request_q_address[1] = cpu_to_le32(MSD(req->dma)); |
| 3397 | icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma)); |
| 3398 | icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma)); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3399 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3400 | /* Setup ATIO queue dma pointers for target mode */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3401 | icb->atio_q_inpointer = cpu_to_le16(0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3402 | icb->atio_q_length = cpu_to_le16(ha->tgt.atio_q_length); |
| 3403 | icb->atio_q_address[0] = cpu_to_le32(LSD(ha->tgt.atio_dma)); |
| 3404 | icb->atio_q_address[1] = cpu_to_le32(MSD(ha->tgt.atio_dma)); |
| 3405 | |
Joe Carnuccio | 7c6300e | 2014-04-11 16:54:37 -0400 | [diff] [blame] | 3406 | if (IS_SHADOW_REG_CAPABLE(ha)) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3407 | icb->firmware_options_2 |= cpu_to_le32(BIT_30|BIT_29); |
Joe Carnuccio | 7c6300e | 2014-04-11 16:54:37 -0400 | [diff] [blame] | 3408 | |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 3409 | if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha)) { |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3410 | icb->qos = cpu_to_le16(QLA_DEFAULT_QUE_QOS); |
| 3411 | icb->rid = cpu_to_le16(rid); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3412 | if (ha->flags.msix_enabled) { |
| 3413 | msix = &ha->msix_entries[1]; |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 3414 | ql_dbg(ql_dbg_init, vha, 0x0019, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3415 | "Registering vector 0x%x for base que.\n", |
| 3416 | msix->entry); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3417 | icb->msix = cpu_to_le16(msix->entry); |
| 3418 | } |
| 3419 | /* Use alternate PCI bus number */ |
| 3420 | if (MSB(rid)) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3421 | icb->firmware_options_2 |= cpu_to_le32(BIT_19); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3422 | /* Use alternate PCI devfn */ |
| 3423 | if (LSB(rid)) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3424 | icb->firmware_options_2 |= cpu_to_le32(BIT_18); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3425 | |
Anirban Chakraborty | 3155754 | 2009-12-02 10:36:55 -0800 | [diff] [blame] | 3426 | /* Use Disable MSIX Handshake mode for capable adapters */ |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 3427 | if ((ha->fw_attributes & BIT_6) && (IS_MSIX_NACK_CAPABLE(ha)) && |
| 3428 | (ha->flags.msix_enabled)) { |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3429 | icb->firmware_options_2 &= cpu_to_le32(~BIT_22); |
Anirban Chakraborty | 3155754 | 2009-12-02 10:36:55 -0800 | [diff] [blame] | 3430 | ha->flags.disable_msix_handshake = 1; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3431 | ql_dbg(ql_dbg_init, vha, 0x00fe, |
| 3432 | "MSIX Handshake Disable Mode turned on.\n"); |
Anirban Chakraborty | 3155754 | 2009-12-02 10:36:55 -0800 | [diff] [blame] | 3433 | } else { |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3434 | icb->firmware_options_2 |= cpu_to_le32(BIT_22); |
Anirban Chakraborty | 3155754 | 2009-12-02 10:36:55 -0800 | [diff] [blame] | 3435 | } |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3436 | icb->firmware_options_2 |= cpu_to_le32(BIT_23); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3437 | |
| 3438 | WRT_REG_DWORD(®->isp25mq.req_q_in, 0); |
| 3439 | WRT_REG_DWORD(®->isp25mq.req_q_out, 0); |
| 3440 | WRT_REG_DWORD(®->isp25mq.rsp_q_in, 0); |
| 3441 | WRT_REG_DWORD(®->isp25mq.rsp_q_out, 0); |
| 3442 | } else { |
| 3443 | WRT_REG_DWORD(®->isp24.req_q_in, 0); |
| 3444 | WRT_REG_DWORD(®->isp24.req_q_out, 0); |
| 3445 | WRT_REG_DWORD(®->isp24.rsp_q_in, 0); |
| 3446 | WRT_REG_DWORD(®->isp24.rsp_q_out, 0); |
| 3447 | } |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 3448 | qlt_24xx_config_rings(vha); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3449 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3450 | /* PCI posting */ |
| 3451 | RD_REG_DWORD(&ioreg->hccr); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3452 | } |
| 3453 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3454 | /** |
| 3455 | * qla2x00_init_rings() - Initializes firmware. |
| 3456 | * @ha: HA context |
| 3457 | * |
| 3458 | * Beginning of request ring has initialization control block already built |
| 3459 | * by nvram config routine. |
| 3460 | * |
| 3461 | * Returns 0 on success. |
| 3462 | */ |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 3463 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3464 | qla2x00_init_rings(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3465 | { |
| 3466 | int rval; |
| 3467 | unsigned long flags = 0; |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 3468 | int cnt, que; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3469 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 3470 | struct req_que *req; |
| 3471 | struct rsp_que *rsp; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3472 | struct mid_init_cb_24xx *mid_init_cb = |
| 3473 | (struct mid_init_cb_24xx *) ha->init_cb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3474 | |
| 3475 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 3476 | |
| 3477 | /* Clear outstanding commands array. */ |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 3478 | for (que = 0; que < ha->max_req_queues; que++) { |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 3479 | req = ha->req_q_map[que]; |
Quinn Tran | cb43285 | 2016-02-04 11:45:16 -0500 | [diff] [blame] | 3480 | if (!req || !test_bit(que, ha->req_qid_map)) |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 3481 | continue; |
Joe Carnuccio | 7c6300e | 2014-04-11 16:54:37 -0400 | [diff] [blame] | 3482 | req->out_ptr = (void *)(req->ring + req->length); |
| 3483 | *req->out_ptr = 0; |
Chad Dupuis | 8d93f55 | 2013-01-30 03:34:37 -0500 | [diff] [blame] | 3484 | for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 3485 | req->outstanding_cmds[cnt] = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3486 | |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 3487 | req->current_outstanding_cmd = 1; |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 3488 | |
| 3489 | /* Initialize firmware. */ |
| 3490 | req->ring_ptr = req->ring; |
| 3491 | req->ring_index = 0; |
| 3492 | req->cnt = req->length; |
| 3493 | } |
| 3494 | |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 3495 | for (que = 0; que < ha->max_rsp_queues; que++) { |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 3496 | rsp = ha->rsp_q_map[que]; |
Quinn Tran | cb43285 | 2016-02-04 11:45:16 -0500 | [diff] [blame] | 3497 | if (!rsp || !test_bit(que, ha->rsp_qid_map)) |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 3498 | continue; |
Joe Carnuccio | 7c6300e | 2014-04-11 16:54:37 -0400 | [diff] [blame] | 3499 | rsp->in_ptr = (void *)(rsp->ring + rsp->length); |
| 3500 | *rsp->in_ptr = 0; |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 3501 | /* Initialize response queue entries */ |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 3502 | if (IS_QLAFX00(ha)) |
| 3503 | qlafx00_init_response_q_entries(rsp); |
| 3504 | else |
| 3505 | qla2x00_init_response_q_entries(rsp); |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 3506 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3507 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3508 | ha->tgt.atio_ring_ptr = ha->tgt.atio_ring; |
| 3509 | ha->tgt.atio_ring_index = 0; |
| 3510 | /* Initialize ATIO queue entries */ |
| 3511 | qlt_init_atio_q_entries(vha); |
| 3512 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3513 | ha->isp_ops->config_rings(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3514 | |
| 3515 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 3516 | |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 3517 | ql_dbg(ql_dbg_init, vha, 0x00d1, "Issue init firmware.\n"); |
| 3518 | |
| 3519 | if (IS_QLAFX00(ha)) { |
| 3520 | rval = qlafx00_init_firmware(vha, ha->init_cb_size); |
| 3521 | goto next_check; |
| 3522 | } |
| 3523 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3524 | /* Update any ISP specific firmware options before initialization. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3525 | ha->isp_ops->update_fw_options(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3526 | |
Lalit Chandivade | 605aa2b | 2009-03-05 11:07:01 -0800 | [diff] [blame] | 3527 | if (ha->flags.npiv_supported) { |
Saurav Kashyap | 45980cc | 2012-08-22 14:21:21 -0400 | [diff] [blame] | 3528 | if (ha->operating_mode == LOOP && !IS_CNA_CAPABLE(ha)) |
Lalit Chandivade | 605aa2b | 2009-03-05 11:07:01 -0800 | [diff] [blame] | 3529 | ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1; |
Seokmann Ju | c48339d | 2008-01-17 09:02:19 -0800 | [diff] [blame] | 3530 | mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports); |
Lalit Chandivade | 605aa2b | 2009-03-05 11:07:01 -0800 | [diff] [blame] | 3531 | } |
| 3532 | |
Andrew Vasquez | 24a0813 | 2009-03-24 09:08:16 -0700 | [diff] [blame] | 3533 | if (IS_FWI2_CAPABLE(ha)) { |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3534 | mid_init_cb->options = cpu_to_le16(BIT_1); |
Andrew Vasquez | 24a0813 | 2009-03-24 09:08:16 -0700 | [diff] [blame] | 3535 | mid_init_cb->init_cb.execution_throttle = |
Quinn Tran | 03e8c68 | 2015-12-17 14:56:59 -0500 | [diff] [blame] | 3536 | cpu_to_le16(ha->cur_fw_xcb_count); |
Joe Carnuccio | 40f3862 | 2016-07-06 11:14:28 -0400 | [diff] [blame] | 3537 | ha->flags.dport_enabled = |
| 3538 | (mid_init_cb->init_cb.firmware_options_1 & BIT_7) != 0; |
| 3539 | ql_dbg(ql_dbg_init, vha, 0x0191, "DPORT Support: %s.\n", |
| 3540 | (ha->flags.dport_enabled) ? "enabled" : "disabled"); |
| 3541 | /* FA-WWPN Status */ |
Himanshu Madhani | 2486c62 | 2014-09-25 05:17:00 -0400 | [diff] [blame] | 3542 | ha->flags.fawwpn_enabled = |
Joe Carnuccio | 40f3862 | 2016-07-06 11:14:28 -0400 | [diff] [blame] | 3543 | (mid_init_cb->init_cb.firmware_options_1 & BIT_6) != 0; |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 3544 | ql_dbg(ql_dbg_init, vha, 0x00bc, "FA-WWPN Support: %s.\n", |
Himanshu Madhani | 2486c62 | 2014-09-25 05:17:00 -0400 | [diff] [blame] | 3545 | (ha->flags.fawwpn_enabled) ? "enabled" : "disabled"); |
Andrew Vasquez | 24a0813 | 2009-03-24 09:08:16 -0700 | [diff] [blame] | 3546 | } |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3547 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3548 | rval = qla2x00_init_firmware(vha, ha->init_cb_size); |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 3549 | next_check: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3550 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3551 | ql_log(ql_log_fatal, vha, 0x00d2, |
| 3552 | "Init Firmware **** FAILED ****.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3553 | } else { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3554 | ql_dbg(ql_dbg_init, vha, 0x00d3, |
| 3555 | "Init Firmware -- success.\n"); |
Quinn Tran | 4b60c82 | 2017-06-13 20:47:21 -0700 | [diff] [blame] | 3556 | QLA_FW_STARTED(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3557 | } |
| 3558 | |
| 3559 | return (rval); |
| 3560 | } |
| 3561 | |
| 3562 | /** |
| 3563 | * qla2x00_fw_ready() - Waits for firmware ready. |
| 3564 | * @ha: HA context |
| 3565 | * |
| 3566 | * Returns 0 on success. |
| 3567 | */ |
| 3568 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3569 | qla2x00_fw_ready(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3570 | { |
| 3571 | int rval; |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 3572 | unsigned long wtime, mtime, cs84xx_time; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3573 | uint16_t min_wait; /* Minimum wait time if loop is down */ |
| 3574 | uint16_t wait_time; /* Wait time if loop is coming ready */ |
Joe Carnuccio | b5a340d | 2014-09-25 05:16:48 -0400 | [diff] [blame] | 3575 | uint16_t state[6]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3576 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3577 | |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 3578 | if (IS_QLAFX00(vha->hw)) |
| 3579 | return qlafx00_fw_ready(vha); |
| 3580 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3581 | rval = QLA_SUCCESS; |
| 3582 | |
Chad Dupuis | 33461491 | 2015-04-09 14:59:57 -0400 | [diff] [blame] | 3583 | /* Time to wait for loop down */ |
| 3584 | if (IS_P3P_TYPE(ha)) |
| 3585 | min_wait = 30; |
| 3586 | else |
| 3587 | min_wait = 20; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3588 | |
| 3589 | /* |
| 3590 | * Firmware should take at most one RATOV to login, plus 5 seconds for |
| 3591 | * our own processing. |
| 3592 | */ |
| 3593 | if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) { |
| 3594 | wait_time = min_wait; |
| 3595 | } |
| 3596 | |
| 3597 | /* Min wait time if loop down */ |
| 3598 | mtime = jiffies + (min_wait * HZ); |
| 3599 | |
| 3600 | /* wait time before firmware ready */ |
| 3601 | wtime = jiffies + (wait_time * HZ); |
| 3602 | |
| 3603 | /* Wait for ISP to finish LIP */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3604 | if (!vha->flags.init_done) |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3605 | ql_log(ql_log_info, vha, 0x801e, |
| 3606 | "Waiting for LIP to complete.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3607 | |
| 3608 | do { |
Andrew Vasquez | 5b93903 | 2012-11-21 02:40:26 -0500 | [diff] [blame] | 3609 | memset(state, -1, sizeof(state)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3610 | rval = qla2x00_get_firmware_state(vha, state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3611 | if (rval == QLA_SUCCESS) { |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 3612 | if (state[0] < FSTATE_LOSS_OF_SYNC) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3613 | vha->device_flags &= ~DFLG_NO_CABLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3614 | } |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 3615 | if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3616 | ql_dbg(ql_dbg_taskm, vha, 0x801f, |
| 3617 | "fw_state=%x 84xx=%x.\n", state[0], |
| 3618 | state[2]); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 3619 | if ((state[2] & FSTATE_LOGGED_IN) && |
| 3620 | (state[2] & FSTATE_WAITING_FOR_VERIFY)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3621 | ql_dbg(ql_dbg_taskm, vha, 0x8028, |
| 3622 | "Sending verify iocb.\n"); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 3623 | |
| 3624 | cs84xx_time = jiffies; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3625 | rval = qla84xx_init_chip(vha); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3626 | if (rval != QLA_SUCCESS) { |
| 3627 | ql_log(ql_log_warn, |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 3628 | vha, 0x8007, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3629 | "Init chip failed.\n"); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 3630 | break; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3631 | } |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 3632 | |
| 3633 | /* Add time taken to initialize. */ |
| 3634 | cs84xx_time = jiffies - cs84xx_time; |
| 3635 | wtime += cs84xx_time; |
| 3636 | mtime += cs84xx_time; |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 3637 | ql_dbg(ql_dbg_taskm, vha, 0x8008, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3638 | "Increasing wait time by %ld. " |
| 3639 | "New time %ld.\n", cs84xx_time, |
| 3640 | wtime); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 3641 | } |
| 3642 | } else if (state[0] == FSTATE_READY) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3643 | ql_dbg(ql_dbg_taskm, vha, 0x8037, |
| 3644 | "F/W Ready - OK.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3645 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3646 | qla2x00_get_retry_cnt(vha, &ha->retry_count, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3647 | &ha->login_timeout, &ha->r_a_tov); |
| 3648 | |
| 3649 | rval = QLA_SUCCESS; |
| 3650 | break; |
| 3651 | } |
| 3652 | |
| 3653 | rval = QLA_FUNCTION_FAILED; |
| 3654 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3655 | if (atomic_read(&vha->loop_down_timer) && |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 3656 | state[0] != FSTATE_READY) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3657 | /* Loop down. Timeout on min_wait for states |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 3658 | * other than Wait for Login. |
| 3659 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3660 | if (time_after_eq(jiffies, mtime)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3661 | ql_log(ql_log_info, vha, 0x8038, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3662 | "Cable is unplugged...\n"); |
| 3663 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3664 | vha->device_flags |= DFLG_NO_CABLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3665 | break; |
| 3666 | } |
| 3667 | } |
| 3668 | } else { |
| 3669 | /* Mailbox cmd failed. Timeout on min_wait. */ |
Santosh Vernekar | cdbb0a4f | 2010-05-28 15:08:25 -0700 | [diff] [blame] | 3670 | if (time_after_eq(jiffies, mtime) || |
Giridhar Malavali | 7190575 | 2011-02-23 15:27:10 -0800 | [diff] [blame] | 3671 | ha->flags.isp82xx_fw_hung) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3672 | break; |
| 3673 | } |
| 3674 | |
| 3675 | if (time_after_eq(jiffies, wtime)) |
| 3676 | break; |
| 3677 | |
| 3678 | /* Delay for a while */ |
| 3679 | msleep(500); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3680 | } while (1); |
| 3681 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3682 | ql_dbg(ql_dbg_taskm, vha, 0x803a, |
Joe Carnuccio | b5a340d | 2014-09-25 05:16:48 -0400 | [diff] [blame] | 3683 | "fw_state=%x (%x, %x, %x, %x %x) curr time=%lx.\n", state[0], |
| 3684 | state[1], state[2], state[3], state[4], state[5], jiffies); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3685 | |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 3686 | if (rval && !(vha->device_flags & DFLG_NO_CABLE)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3687 | ql_log(ql_log_warn, vha, 0x803b, |
| 3688 | "Firmware ready **** FAILED ****.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3689 | } |
| 3690 | |
| 3691 | return (rval); |
| 3692 | } |
| 3693 | |
| 3694 | /* |
| 3695 | * qla2x00_configure_hba |
| 3696 | * Setup adapter context. |
| 3697 | * |
| 3698 | * Input: |
| 3699 | * ha = adapter state pointer. |
| 3700 | * |
| 3701 | * Returns: |
| 3702 | * 0 = success |
| 3703 | * |
| 3704 | * Context: |
| 3705 | * Kernel context. |
| 3706 | */ |
| 3707 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3708 | qla2x00_configure_hba(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3709 | { |
| 3710 | int rval; |
| 3711 | uint16_t loop_id; |
| 3712 | uint16_t topo; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3713 | uint16_t sw_cap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3714 | uint8_t al_pa; |
| 3715 | uint8_t area; |
| 3716 | uint8_t domain; |
| 3717 | char connect_type[22]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3718 | struct qla_hw_data *ha = vha->hw; |
Joe Carnuccio | 61e1b26 | 2013-02-08 01:57:48 -0500 | [diff] [blame] | 3719 | scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev); |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 3720 | port_id_t id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3721 | |
| 3722 | /* Get host addresses. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3723 | rval = qla2x00_get_adapter_id(vha, |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3724 | &loop_id, &al_pa, &area, &domain, &topo, &sw_cap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3725 | if (rval != QLA_SUCCESS) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3726 | if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) || |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 3727 | IS_CNA_CAPABLE(ha) || |
Ravi Anand | 33135aa | 2005-11-08 14:37:20 -0800 | [diff] [blame] | 3728 | (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3729 | ql_dbg(ql_dbg_disc, vha, 0x2008, |
| 3730 | "Loop is in a transition state.\n"); |
Ravi Anand | 33135aa | 2005-11-08 14:37:20 -0800 | [diff] [blame] | 3731 | } else { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3732 | ql_log(ql_log_warn, vha, 0x2009, |
| 3733 | "Unable to get host loop ID.\n"); |
Joe Carnuccio | 61e1b26 | 2013-02-08 01:57:48 -0500 | [diff] [blame] | 3734 | if (IS_FWI2_CAPABLE(ha) && (vha == base_vha) && |
| 3735 | (rval == QLA_COMMAND_ERROR && loop_id == 0x1b)) { |
| 3736 | ql_log(ql_log_warn, vha, 0x1151, |
| 3737 | "Doing link init.\n"); |
| 3738 | if (qla24xx_link_initialize(vha) == QLA_SUCCESS) |
| 3739 | return rval; |
| 3740 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3741 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
Ravi Anand | 33135aa | 2005-11-08 14:37:20 -0800 | [diff] [blame] | 3742 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3743 | return (rval); |
| 3744 | } |
| 3745 | |
| 3746 | if (topo == 4) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3747 | ql_log(ql_log_info, vha, 0x200a, |
| 3748 | "Cannot get topology - retrying.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3749 | return (QLA_FUNCTION_FAILED); |
| 3750 | } |
| 3751 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3752 | vha->loop_id = loop_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3753 | |
| 3754 | /* initialize */ |
| 3755 | ha->min_external_loopid = SNS_FIRST_LOOP_ID; |
| 3756 | ha->operating_mode = LOOP; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3757 | ha->switch_cap = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3758 | |
| 3759 | switch (topo) { |
| 3760 | case 0: |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3761 | ql_dbg(ql_dbg_disc, vha, 0x200b, "HBA in NL topology.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3762 | ha->current_topology = ISP_CFG_NL; |
| 3763 | strcpy(connect_type, "(Loop)"); |
| 3764 | break; |
| 3765 | |
| 3766 | case 1: |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3767 | ql_dbg(ql_dbg_disc, vha, 0x200c, "HBA in FL topology.\n"); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3768 | ha->switch_cap = sw_cap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3769 | ha->current_topology = ISP_CFG_FL; |
| 3770 | strcpy(connect_type, "(FL_Port)"); |
| 3771 | break; |
| 3772 | |
| 3773 | case 2: |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3774 | 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] | 3775 | ha->operating_mode = P2P; |
| 3776 | ha->current_topology = ISP_CFG_N; |
| 3777 | strcpy(connect_type, "(N_Port-to-N_Port)"); |
| 3778 | break; |
| 3779 | |
| 3780 | case 3: |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3781 | 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] | 3782 | ha->switch_cap = sw_cap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3783 | ha->operating_mode = P2P; |
| 3784 | ha->current_topology = ISP_CFG_F; |
| 3785 | strcpy(connect_type, "(F_Port)"); |
| 3786 | break; |
| 3787 | |
| 3788 | default: |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3789 | ql_dbg(ql_dbg_disc, vha, 0x200f, |
| 3790 | "HBA in unknown topology %x, using NL.\n", topo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3791 | ha->current_topology = ISP_CFG_NL; |
| 3792 | strcpy(connect_type, "(Loop)"); |
| 3793 | break; |
| 3794 | } |
| 3795 | |
| 3796 | /* Save Host port and loop ID. */ |
| 3797 | /* byte order - Big Endian */ |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 3798 | id.b.domain = domain; |
| 3799 | id.b.area = area; |
| 3800 | id.b.al_pa = al_pa; |
| 3801 | id.b.rsvd_1 = 0; |
| 3802 | qlt_update_host_map(vha, id); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3803 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3804 | if (!vha->flags.init_done) |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3805 | ql_log(ql_log_info, vha, 0x2010, |
| 3806 | "Topology - %s, Host Loop address 0x%x.\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3807 | connect_type, vha->loop_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3808 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3809 | return(rval); |
| 3810 | } |
| 3811 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 3812 | inline void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3813 | qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len, |
| 3814 | char *def) |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 3815 | { |
| 3816 | char *st, *en; |
| 3817 | uint16_t index; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3818 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | ab67114 | 2009-08-25 11:36:17 -0700 | [diff] [blame] | 3819 | int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) && |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 3820 | !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha); |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 3821 | |
| 3822 | if (memcmp(model, BINZERO, len) != 0) { |
| 3823 | strncpy(ha->model_number, model, len); |
| 3824 | st = en = ha->model_number; |
| 3825 | en += len - 1; |
| 3826 | while (en > st) { |
| 3827 | if (*en != 0x20 && *en != 0x00) |
| 3828 | break; |
| 3829 | *en-- = '\0'; |
| 3830 | } |
| 3831 | |
| 3832 | index = (ha->pdev->subsystem_device & 0xff); |
Andrew Vasquez | 7d0dba1 | 2009-04-06 22:33:45 -0700 | [diff] [blame] | 3833 | if (use_tbl && |
| 3834 | ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC && |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 3835 | index < QLA_MODEL_NAMES) |
Joe Carnuccio | 1ee2714 | 2008-07-10 16:55:53 -0700 | [diff] [blame] | 3836 | strncpy(ha->model_desc, |
| 3837 | qla2x00_model_name[index * 2 + 1], |
| 3838 | sizeof(ha->model_desc) - 1); |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 3839 | } else { |
| 3840 | index = (ha->pdev->subsystem_device & 0xff); |
Andrew Vasquez | 7d0dba1 | 2009-04-06 22:33:45 -0700 | [diff] [blame] | 3841 | if (use_tbl && |
| 3842 | ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC && |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 3843 | index < QLA_MODEL_NAMES) { |
| 3844 | strcpy(ha->model_number, |
| 3845 | qla2x00_model_name[index * 2]); |
Joe Carnuccio | 1ee2714 | 2008-07-10 16:55:53 -0700 | [diff] [blame] | 3846 | strncpy(ha->model_desc, |
| 3847 | qla2x00_model_name[index * 2 + 1], |
| 3848 | sizeof(ha->model_desc) - 1); |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 3849 | } else { |
| 3850 | strcpy(ha->model_number, def); |
| 3851 | } |
| 3852 | } |
Joe Carnuccio | 1ee2714 | 2008-07-10 16:55:53 -0700 | [diff] [blame] | 3853 | if (IS_FWI2_CAPABLE(ha)) |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3854 | qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc, |
Joe Carnuccio | 1ee2714 | 2008-07-10 16:55:53 -0700 | [diff] [blame] | 3855 | sizeof(ha->model_desc)); |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 3856 | } |
| 3857 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 3858 | /* On sparc systems, obtain port and node WWN from firmware |
| 3859 | * properties. |
| 3860 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3861 | 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] | 3862 | { |
| 3863 | #ifdef CONFIG_SPARC |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3864 | struct qla_hw_data *ha = vha->hw; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 3865 | struct pci_dev *pdev = ha->pdev; |
David S. Miller | 15576bc | 2007-05-08 00:36:49 -0700 | [diff] [blame] | 3866 | struct device_node *dp = pci_device_to_OF_node(pdev); |
| 3867 | const u8 *val; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 3868 | int len; |
| 3869 | |
| 3870 | val = of_get_property(dp, "port-wwn", &len); |
| 3871 | if (val && len >= WWN_SIZE) |
| 3872 | memcpy(nv->port_name, val, WWN_SIZE); |
| 3873 | |
| 3874 | val = of_get_property(dp, "node-wwn", &len); |
| 3875 | if (val && len >= WWN_SIZE) |
| 3876 | memcpy(nv->node_name, val, WWN_SIZE); |
| 3877 | #endif |
| 3878 | } |
| 3879 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3880 | /* |
| 3881 | * NVRAM configuration for ISP 2xxx |
| 3882 | * |
| 3883 | * Input: |
| 3884 | * ha = adapter block pointer. |
| 3885 | * |
| 3886 | * Output: |
| 3887 | * initialization control block in response_ring |
| 3888 | * host adapters parameters in host adapter block |
| 3889 | * |
| 3890 | * Returns: |
| 3891 | * 0 = success. |
| 3892 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 3893 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3894 | qla2x00_nvram_config(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3895 | { |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 3896 | int rval; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3897 | uint8_t chksum = 0; |
| 3898 | uint16_t cnt; |
| 3899 | uint8_t *dptr1, *dptr2; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3900 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3901 | init_cb_t *icb = ha->init_cb; |
Seokmann Ju | 281afe1 | 2007-07-26 13:43:34 -0700 | [diff] [blame] | 3902 | nvram_t *nv = ha->nvram; |
| 3903 | uint8_t *ptr = ha->nvram; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 3904 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3905 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 3906 | rval = QLA_SUCCESS; |
| 3907 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3908 | /* Determine NVRAM starting address. */ |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3909 | ha->nvram_size = sizeof(nvram_t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3910 | ha->nvram_base = 0; |
| 3911 | if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha)) |
| 3912 | if ((RD_REG_WORD(®->ctrl_status) >> 14) == 1) |
| 3913 | ha->nvram_base = 0x80; |
| 3914 | |
| 3915 | /* Get NVRAM data and calculate checksum. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3916 | 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] | 3917 | for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++) |
| 3918 | chksum += *ptr++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3919 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3920 | ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x010f, |
| 3921 | "Contents of NVRAM.\n"); |
| 3922 | ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0110, |
| 3923 | (uint8_t *)nv, ha->nvram_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3924 | |
| 3925 | /* Bad NVRAM data, set defaults parameters. */ |
| 3926 | if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || |
| 3927 | nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) { |
| 3928 | /* Reset NVRAM data. */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3929 | ql_log(ql_log_warn, vha, 0x0064, |
Raul Porcel | 9e33652 | 2012-05-15 14:34:08 -0400 | [diff] [blame] | 3930 | "Inconsistent NVRAM " |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3931 | "detected: checksum=0x%x id=%c version=0x%x.\n", |
| 3932 | chksum, nv->id[0], nv->nvram_version); |
| 3933 | ql_log(ql_log_warn, vha, 0x0065, |
| 3934 | "Falling back to " |
| 3935 | "functioning (yet invalid -- WWPN) defaults.\n"); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 3936 | |
| 3937 | /* |
| 3938 | * Set default initialization control block. |
| 3939 | */ |
| 3940 | memset(nv, 0, ha->nvram_size); |
| 3941 | nv->parameter_block_version = ICB_VERSION; |
| 3942 | |
| 3943 | if (IS_QLA23XX(ha)) { |
| 3944 | nv->firmware_options[0] = BIT_2 | BIT_1; |
| 3945 | nv->firmware_options[1] = BIT_7 | BIT_5; |
| 3946 | nv->add_firmware_options[0] = BIT_5; |
| 3947 | nv->add_firmware_options[1] = BIT_5 | BIT_4; |
Joe Carnuccio | 98aee70 | 2014-09-25 05:16:38 -0400 | [diff] [blame] | 3948 | nv->frame_payload_size = 2048; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 3949 | nv->special_options[1] = BIT_7; |
| 3950 | } else if (IS_QLA2200(ha)) { |
| 3951 | nv->firmware_options[0] = BIT_2 | BIT_1; |
| 3952 | nv->firmware_options[1] = BIT_7 | BIT_5; |
| 3953 | nv->add_firmware_options[0] = BIT_5; |
| 3954 | nv->add_firmware_options[1] = BIT_5 | BIT_4; |
Joe Carnuccio | 98aee70 | 2014-09-25 05:16:38 -0400 | [diff] [blame] | 3955 | nv->frame_payload_size = 1024; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 3956 | } else if (IS_QLA2100(ha)) { |
| 3957 | nv->firmware_options[0] = BIT_3 | BIT_1; |
| 3958 | nv->firmware_options[1] = BIT_5; |
Joe Carnuccio | 98aee70 | 2014-09-25 05:16:38 -0400 | [diff] [blame] | 3959 | nv->frame_payload_size = 1024; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 3960 | } |
| 3961 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3962 | nv->max_iocb_allocation = cpu_to_le16(256); |
| 3963 | nv->execution_throttle = cpu_to_le16(16); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 3964 | nv->retry_count = 8; |
| 3965 | nv->retry_delay = 1; |
| 3966 | |
| 3967 | nv->port_name[0] = 33; |
| 3968 | nv->port_name[3] = 224; |
| 3969 | nv->port_name[4] = 139; |
| 3970 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3971 | qla2xxx_nvram_wwn_from_ofw(vha, nv); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 3972 | |
| 3973 | nv->login_timeout = 4; |
| 3974 | |
| 3975 | /* |
| 3976 | * Set default host adapter parameters |
| 3977 | */ |
| 3978 | nv->host_p[1] = BIT_2; |
| 3979 | nv->reset_delay = 5; |
| 3980 | nv->port_down_retry_count = 8; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3981 | nv->max_luns_per_target = cpu_to_le16(8); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 3982 | nv->link_down_timeout = 60; |
| 3983 | |
| 3984 | rval = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3985 | } |
| 3986 | |
| 3987 | #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2) |
| 3988 | /* |
| 3989 | * The SN2 does not provide BIOS emulation which means you can't change |
| 3990 | * potentially bogus BIOS settings. Force the use of default settings |
| 3991 | * for link rate and frame size. Hope that the rest of the settings |
| 3992 | * are valid. |
| 3993 | */ |
| 3994 | if (ia64_platform_is("sn2")) { |
Joe Carnuccio | 98aee70 | 2014-09-25 05:16:38 -0400 | [diff] [blame] | 3995 | nv->frame_payload_size = 2048; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3996 | if (IS_QLA23XX(ha)) |
| 3997 | nv->special_options[1] = BIT_7; |
| 3998 | } |
| 3999 | #endif |
| 4000 | |
| 4001 | /* Reset Initialization control block */ |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4002 | memset(icb, 0, ha->init_cb_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4003 | |
| 4004 | /* |
| 4005 | * Setup driver NVRAM options. |
| 4006 | */ |
| 4007 | nv->firmware_options[0] |= (BIT_6 | BIT_1); |
| 4008 | nv->firmware_options[0] &= ~(BIT_5 | BIT_4); |
| 4009 | nv->firmware_options[1] |= (BIT_5 | BIT_0); |
| 4010 | nv->firmware_options[1] &= ~BIT_4; |
| 4011 | |
| 4012 | if (IS_QLA23XX(ha)) { |
| 4013 | nv->firmware_options[0] |= BIT_2; |
| 4014 | nv->firmware_options[0] &= ~BIT_3; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4015 | nv->special_options[0] &= ~BIT_6; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4016 | nv->add_firmware_options[1] |= BIT_5 | BIT_4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4017 | |
| 4018 | if (IS_QLA2300(ha)) { |
| 4019 | if (ha->fb_rev == FPM_2310) { |
| 4020 | strcpy(ha->model_number, "QLA2310"); |
| 4021 | } else { |
| 4022 | strcpy(ha->model_number, "QLA2300"); |
| 4023 | } |
| 4024 | } else { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4025 | qla2x00_set_model_info(vha, nv->model_number, |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 4026 | sizeof(nv->model_number), "QLA23xx"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4027 | } |
| 4028 | } else if (IS_QLA2200(ha)) { |
| 4029 | nv->firmware_options[0] |= BIT_2; |
| 4030 | /* |
| 4031 | * 'Point-to-point preferred, else loop' is not a safe |
| 4032 | * connection mode setting. |
| 4033 | */ |
| 4034 | if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) == |
| 4035 | (BIT_5 | BIT_4)) { |
| 4036 | /* Force 'loop preferred, else point-to-point'. */ |
| 4037 | nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4); |
| 4038 | nv->add_firmware_options[0] |= BIT_5; |
| 4039 | } |
| 4040 | strcpy(ha->model_number, "QLA22xx"); |
| 4041 | } else /*if (IS_QLA2100(ha))*/ { |
| 4042 | strcpy(ha->model_number, "QLA2100"); |
| 4043 | } |
| 4044 | |
| 4045 | /* |
| 4046 | * Copy over NVRAM RISC parameter block to initialization control block. |
| 4047 | */ |
| 4048 | dptr1 = (uint8_t *)icb; |
| 4049 | dptr2 = (uint8_t *)&nv->parameter_block_version; |
| 4050 | cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version; |
| 4051 | while (cnt--) |
| 4052 | *dptr1++ = *dptr2++; |
| 4053 | |
| 4054 | /* Copy 2nd half. */ |
| 4055 | dptr1 = (uint8_t *)icb->add_firmware_options; |
| 4056 | cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options; |
| 4057 | while (cnt--) |
| 4058 | *dptr1++ = *dptr2++; |
| 4059 | |
Andrew Vasquez | 5341e86 | 2006-05-17 15:09:16 -0700 | [diff] [blame] | 4060 | /* Use alternate WWN? */ |
| 4061 | if (nv->host_p[1] & BIT_7) { |
| 4062 | memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE); |
| 4063 | memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE); |
| 4064 | } |
| 4065 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4066 | /* Prepare nodename */ |
| 4067 | if ((icb->firmware_options[1] & BIT_6) == 0) { |
| 4068 | /* |
| 4069 | * Firmware will apply the following mask if the nodename was |
| 4070 | * not provided. |
| 4071 | */ |
| 4072 | memcpy(icb->node_name, icb->port_name, WWN_SIZE); |
| 4073 | icb->node_name[0] &= 0xF0; |
| 4074 | } |
| 4075 | |
| 4076 | /* |
| 4077 | * Set host adapter parameters. |
| 4078 | */ |
Saurav Kashyap | 3ce8866 | 2011-07-14 12:00:12 -0700 | [diff] [blame] | 4079 | |
| 4080 | /* |
| 4081 | * BIT_7 in the host-parameters section allows for modification to |
| 4082 | * internal driver logging. |
| 4083 | */ |
Andrew Vasquez | 0181944 | 2006-06-23 16:11:10 -0700 | [diff] [blame] | 4084 | if (nv->host_p[0] & BIT_7) |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 4085 | ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4086 | ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0); |
| 4087 | /* Always load RISC code on non ISP2[12]00 chips. */ |
| 4088 | if (!IS_QLA2100(ha) && !IS_QLA2200(ha)) |
| 4089 | ha->flags.disable_risc_code_load = 0; |
| 4090 | ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0); |
| 4091 | ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0); |
| 4092 | 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] | 4093 | 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] | 4094 | ha->flags.disable_serdes = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4095 | |
| 4096 | ha->operating_mode = |
| 4097 | (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4; |
| 4098 | |
| 4099 | memcpy(ha->fw_seriallink_options, nv->seriallink_options, |
| 4100 | sizeof(ha->fw_seriallink_options)); |
| 4101 | |
| 4102 | /* save HBA serial number */ |
| 4103 | ha->serial0 = icb->port_name[5]; |
| 4104 | ha->serial1 = icb->port_name[6]; |
| 4105 | ha->serial2 = icb->port_name[7]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4106 | memcpy(vha->node_name, icb->node_name, WWN_SIZE); |
| 4107 | memcpy(vha->port_name, icb->port_name, WWN_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4108 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 4109 | icb->execution_throttle = cpu_to_le16(0xFFFF); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4110 | |
| 4111 | ha->retry_count = nv->retry_count; |
| 4112 | |
| 4113 | /* Set minimum login_timeout to 4 seconds. */ |
Andrew Vasquez | 5b91490 | 2010-05-28 15:08:30 -0700 | [diff] [blame] | 4114 | if (nv->login_timeout != ql2xlogintimeout) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4115 | nv->login_timeout = ql2xlogintimeout; |
| 4116 | if (nv->login_timeout < 4) |
| 4117 | nv->login_timeout = 4; |
| 4118 | ha->login_timeout = nv->login_timeout; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4119 | |
Andrew Vasquez | 00a537b | 2008-02-28 14:06:11 -0800 | [diff] [blame] | 4120 | /* Set minimum RATOV to 100 tenths of a second. */ |
| 4121 | ha->r_a_tov = 100; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4122 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4123 | ha->loop_reset_delay = nv->reset_delay; |
| 4124 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4125 | /* Link Down Timeout = 0: |
| 4126 | * |
| 4127 | * When Port Down timer expires we will start returning |
| 4128 | * I/O's to OS with "DID_NO_CONNECT". |
| 4129 | * |
| 4130 | * Link Down Timeout != 0: |
| 4131 | * |
| 4132 | * The driver waits for the link to come up after link down |
| 4133 | * before returning I/Os to OS with "DID_NO_CONNECT". |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 4134 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4135 | if (nv->link_down_timeout == 0) { |
| 4136 | ha->loop_down_abort_time = |
Andrew Vasquez | 354d6b2 | 2005-04-23 02:47:27 -0400 | [diff] [blame] | 4137 | (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4138 | } else { |
| 4139 | ha->link_down_timeout = nv->link_down_timeout; |
| 4140 | ha->loop_down_abort_time = |
| 4141 | (LOOP_DOWN_TIME - ha->link_down_timeout); |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 4142 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4143 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4144 | /* |
| 4145 | * Need enough time to try and get the port back. |
| 4146 | */ |
| 4147 | ha->port_down_retry_count = nv->port_down_retry_count; |
| 4148 | if (qlport_down_retry) |
| 4149 | ha->port_down_retry_count = qlport_down_retry; |
| 4150 | /* Set login_retry_count */ |
| 4151 | ha->login_retry_count = nv->retry_count; |
| 4152 | if (ha->port_down_retry_count == nv->port_down_retry_count && |
| 4153 | ha->port_down_retry_count > 3) |
| 4154 | ha->login_retry_count = ha->port_down_retry_count; |
| 4155 | else if (ha->port_down_retry_count > (int)ha->login_retry_count) |
| 4156 | ha->login_retry_count = ha->port_down_retry_count; |
| 4157 | if (ql2xloginretrycount) |
| 4158 | ha->login_retry_count = ql2xloginretrycount; |
| 4159 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 4160 | icb->lun_enables = cpu_to_le16(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4161 | icb->command_resource_count = 0; |
| 4162 | icb->immediate_notify_resource_count = 0; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 4163 | icb->timeout = cpu_to_le16(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4164 | |
| 4165 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) { |
| 4166 | /* Enable RIO */ |
| 4167 | icb->firmware_options[0] &= ~BIT_3; |
| 4168 | icb->add_firmware_options[0] &= |
| 4169 | ~(BIT_3 | BIT_2 | BIT_1 | BIT_0); |
| 4170 | icb->add_firmware_options[0] |= BIT_2; |
| 4171 | icb->response_accumulation_timer = 3; |
| 4172 | icb->interrupt_delay_timer = 5; |
| 4173 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4174 | vha->flags.process_response_queue = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4175 | } else { |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 4176 | /* Enable ZIO. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4177 | if (!vha->flags.init_done) { |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 4178 | ha->zio_mode = icb->add_firmware_options[0] & |
| 4179 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
| 4180 | ha->zio_timer = icb->interrupt_delay_timer ? |
| 4181 | icb->interrupt_delay_timer: 2; |
| 4182 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4183 | icb->add_firmware_options[0] &= |
| 4184 | ~(BIT_3 | BIT_2 | BIT_1 | BIT_0); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4185 | vha->flags.process_response_queue = 0; |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 4186 | if (ha->zio_mode != QLA_ZIO_DISABLED) { |
andrew.vasquez@qlogic.com | 4a59f71 | 2006-03-09 14:27:39 -0800 | [diff] [blame] | 4187 | ha->zio_mode = QLA_ZIO_MODE_6; |
| 4188 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4189 | ql_log(ql_log_info, vha, 0x0068, |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 4190 | "ZIO mode %d enabled; timer delay (%d us).\n", |
| 4191 | ha->zio_mode, ha->zio_timer * 100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4192 | |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 4193 | icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode; |
| 4194 | icb->interrupt_delay_timer = (uint8_t)ha->zio_timer; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4195 | vha->flags.process_response_queue = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4196 | } |
| 4197 | } |
| 4198 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4199 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4200 | ql_log(ql_log_warn, vha, 0x0069, |
| 4201 | "NVRAM configuration failed.\n"); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4202 | } |
| 4203 | return (rval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4204 | } |
| 4205 | |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 4206 | static void |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 4207 | qla2x00_rport_del(void *data) |
| 4208 | { |
| 4209 | fc_port_t *fcport = data; |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 4210 | struct fc_rport *rport; |
Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 4211 | unsigned long flags; |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 4212 | |
Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 4213 | spin_lock_irqsave(fcport->vha->host->host_lock, flags); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 4214 | rport = fcport->drport ? fcport->drport: fcport->rport; |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 4215 | fcport->drport = NULL; |
Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 4216 | spin_unlock_irqrestore(fcport->vha->host->host_lock, flags); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4217 | if (rport) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4218 | ql_dbg(ql_dbg_disc, fcport->vha, 0x210b, |
| 4219 | "%s %8phN. rport %p roles %x\n", |
| 4220 | __func__, fcport->port_name, rport, |
| 4221 | rport->roles); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4222 | |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 4223 | fc_remote_port_delete(rport); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4224 | } |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 4225 | } |
| 4226 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4227 | /** |
| 4228 | * qla2x00_alloc_fcport() - Allocate a generic fcport. |
| 4229 | * @ha: HA context |
| 4230 | * @flags: allocation flags |
| 4231 | * |
| 4232 | * Returns a pointer to the allocated fcport, or NULL, if none available. |
| 4233 | */ |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 4234 | fc_port_t * |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4235 | qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4236 | { |
| 4237 | fc_port_t *fcport; |
| 4238 | |
Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 4239 | fcport = kzalloc(sizeof(fc_port_t), flags); |
| 4240 | if (!fcport) |
| 4241 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4242 | |
| 4243 | /* Setup fcport template structure. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4244 | fcport->vha = vha; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4245 | fcport->port_type = FCT_UNKNOWN; |
| 4246 | fcport->loop_id = FC_NO_LOOP_ID; |
Chad Dupuis | ec426e1 | 2011-03-30 11:46:32 -0700 | [diff] [blame] | 4247 | qla2x00_set_fcport_state(fcport, FCS_UNCONFIGURED); |
Andrew Vasquez | ad3e0ed | 2005-08-26 19:08:10 -0700 | [diff] [blame] | 4248 | fcport->supported_classes = FC_COS_UNSPECIFIED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4249 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4250 | fcport->ct_desc.ct_sns = dma_alloc_coherent(&vha->hw->pdev->dev, |
| 4251 | sizeof(struct ct_sns_pkt), &fcport->ct_desc.ct_sns_dma, |
Quinn Tran | 6cb3216 | 2017-02-13 12:18:29 -0800 | [diff] [blame] | 4252 | flags); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4253 | fcport->disc_state = DSC_DELETED; |
| 4254 | fcport->fw_login_state = DSC_LS_PORT_UNAVAIL; |
| 4255 | fcport->deleted = QLA_SESS_DELETED; |
| 4256 | fcport->login_retry = vha->hw->login_retry_count; |
| 4257 | fcport->login_retry = 5; |
| 4258 | fcport->logout_on_delete = 1; |
| 4259 | |
| 4260 | if (!fcport->ct_desc.ct_sns) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4261 | ql_log(ql_log_warn, vha, 0xd049, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4262 | "Failed to allocate ct_sns request.\n"); |
| 4263 | kfree(fcport); |
| 4264 | fcport = NULL; |
| 4265 | } |
| 4266 | INIT_WORK(&fcport->del_work, qla24xx_delete_sess_fn); |
| 4267 | INIT_LIST_HEAD(&fcport->gnl_entry); |
| 4268 | INIT_LIST_HEAD(&fcport->list); |
| 4269 | |
Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 4270 | return fcport; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4271 | } |
| 4272 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4273 | void |
| 4274 | qla2x00_free_fcport(fc_port_t *fcport) |
| 4275 | { |
| 4276 | if (fcport->ct_desc.ct_sns) { |
| 4277 | dma_free_coherent(&fcport->vha->hw->pdev->dev, |
| 4278 | sizeof(struct ct_sns_pkt), fcport->ct_desc.ct_sns, |
| 4279 | fcport->ct_desc.ct_sns_dma); |
| 4280 | |
| 4281 | fcport->ct_desc.ct_sns = NULL; |
| 4282 | } |
| 4283 | kfree(fcport); |
| 4284 | } |
| 4285 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4286 | /* |
| 4287 | * qla2x00_configure_loop |
| 4288 | * Updates Fibre Channel Device Database with what is actually on loop. |
| 4289 | * |
| 4290 | * Input: |
| 4291 | * ha = adapter block pointer. |
| 4292 | * |
| 4293 | * Returns: |
| 4294 | * 0 = success. |
| 4295 | * 1 = error. |
| 4296 | * 2 = database was full and device was not configured. |
| 4297 | */ |
| 4298 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4299 | qla2x00_configure_loop(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4300 | { |
| 4301 | int rval; |
| 4302 | unsigned long flags, save_flags; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4303 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4304 | rval = QLA_SUCCESS; |
| 4305 | |
| 4306 | /* Get Initiator ID */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4307 | if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) { |
| 4308 | rval = qla2x00_configure_hba(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4309 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4310 | ql_dbg(ql_dbg_disc, vha, 0x2013, |
| 4311 | "Unable to configure HBA.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4312 | return (rval); |
| 4313 | } |
| 4314 | } |
| 4315 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4316 | save_flags = flags = vha->dpc_flags; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4317 | ql_dbg(ql_dbg_disc, vha, 0x2014, |
| 4318 | "Configure loop -- dpc flags = 0x%lx.\n", flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4319 | |
| 4320 | /* |
| 4321 | * If we have both an RSCN and PORT UPDATE pending then handle them |
| 4322 | * both at the same time. |
| 4323 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4324 | clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
| 4325 | clear_bit(RSCN_UPDATE, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4326 | |
Michael Hernandez | 3064ff3 | 2009-12-15 21:29:44 -0800 | [diff] [blame] | 4327 | qla2x00_get_data_rate(vha); |
| 4328 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4329 | /* Determine what we need to do */ |
| 4330 | if (ha->current_topology == ISP_CFG_FL && |
| 4331 | (test_bit(LOCAL_LOOP_UPDATE, &flags))) { |
| 4332 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4333 | set_bit(RSCN_UPDATE, &flags); |
| 4334 | |
| 4335 | } else if (ha->current_topology == ISP_CFG_F && |
| 4336 | (test_bit(LOCAL_LOOP_UPDATE, &flags))) { |
| 4337 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4338 | set_bit(RSCN_UPDATE, &flags); |
| 4339 | clear_bit(LOCAL_LOOP_UPDATE, &flags); |
| 4340 | |
Andrew Vasquez | 21333b4 | 2006-05-17 15:09:56 -0700 | [diff] [blame] | 4341 | } else if (ha->current_topology == ISP_CFG_N) { |
| 4342 | clear_bit(RSCN_UPDATE, &flags); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4343 | } else if (ha->current_topology == ISP_CFG_NL) { |
| 4344 | clear_bit(RSCN_UPDATE, &flags); |
| 4345 | set_bit(LOCAL_LOOP_UPDATE, &flags); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4346 | } else if (!vha->flags.online || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4347 | (test_bit(ABORT_ISP_ACTIVE, &flags))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4348 | set_bit(RSCN_UPDATE, &flags); |
| 4349 | set_bit(LOCAL_LOOP_UPDATE, &flags); |
| 4350 | } |
| 4351 | |
| 4352 | if (test_bit(LOCAL_LOOP_UPDATE, &flags)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4353 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) { |
| 4354 | ql_dbg(ql_dbg_disc, vha, 0x2015, |
| 4355 | "Loop resync needed, failing.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4356 | rval = QLA_FUNCTION_FAILED; |
Chad Dupuis | 642ef98 | 2012-02-09 11:15:57 -0800 | [diff] [blame] | 4357 | } else |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4358 | rval = qla2x00_configure_local_loop(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4359 | } |
| 4360 | |
| 4361 | if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4362 | if (LOOP_TRANSITION(vha)) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4363 | ql_dbg(ql_dbg_disc, vha, 0x2099, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4364 | "Needs RSCN update and loop transition.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4365 | rval = QLA_FUNCTION_FAILED; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4366 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4367 | else |
| 4368 | rval = qla2x00_configure_fabric(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4369 | } |
| 4370 | |
| 4371 | if (rval == QLA_SUCCESS) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4372 | if (atomic_read(&vha->loop_down_timer) || |
| 4373 | test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4374 | rval = QLA_FUNCTION_FAILED; |
| 4375 | } else { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4376 | atomic_set(&vha->loop_state, LOOP_READY); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4377 | ql_dbg(ql_dbg_disc, vha, 0x2069, |
| 4378 | "LOOP READY.\n"); |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 4379 | ha->flags.fw_init_done = 1; |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 4380 | |
| 4381 | /* |
| 4382 | * Process any ATIO queue entries that came in |
| 4383 | * while we weren't online. |
| 4384 | */ |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 4385 | if (qla_tgt_mode_enabled(vha) || |
| 4386 | qla_dual_mode_enabled(vha)) { |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 4387 | if (IS_QLA27XX(ha) || IS_QLA83XX(ha)) { |
| 4388 | spin_lock_irqsave(&ha->tgt.atio_lock, |
| 4389 | flags); |
| 4390 | qlt_24xx_process_atio_queue(vha, 0); |
| 4391 | spin_unlock_irqrestore( |
| 4392 | &ha->tgt.atio_lock, flags); |
| 4393 | } else { |
| 4394 | spin_lock_irqsave(&ha->hardware_lock, |
| 4395 | flags); |
| 4396 | qlt_24xx_process_atio_queue(vha, 1); |
| 4397 | spin_unlock_irqrestore( |
| 4398 | &ha->hardware_lock, flags); |
| 4399 | } |
| 4400 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4401 | } |
| 4402 | } |
| 4403 | |
| 4404 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4405 | ql_dbg(ql_dbg_disc, vha, 0x206a, |
| 4406 | "%s *** FAILED ***.\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4407 | } else { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4408 | ql_dbg(ql_dbg_disc, vha, 0x206b, |
| 4409 | "%s: exiting normally.\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4410 | } |
| 4411 | |
Bjorn Helgaas | cc3ef7b | 2008-09-11 21:22:51 -0700 | [diff] [blame] | 4412 | /* Restore state if a resync event occurred during processing */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4413 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4414 | if (test_bit(LOCAL_LOOP_UPDATE, &save_flags)) |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4415 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
Andrew Vasquez | f4658b6 | 2009-06-03 09:55:21 -0700 | [diff] [blame] | 4416 | if (test_bit(RSCN_UPDATE, &save_flags)) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4417 | set_bit(RSCN_UPDATE, &vha->dpc_flags); |
Andrew Vasquez | f4658b6 | 2009-06-03 09:55:21 -0700 | [diff] [blame] | 4418 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4419 | } |
| 4420 | |
| 4421 | return (rval); |
| 4422 | } |
| 4423 | |
Duane Grigsby | edd05de | 2017-10-13 09:34:06 -0700 | [diff] [blame] | 4424 | /* |
| 4425 | * N2N Login |
| 4426 | * Updates Fibre Channel Device Database with local loop devices. |
| 4427 | * |
| 4428 | * Input: |
| 4429 | * ha = adapter block pointer. |
| 4430 | * |
| 4431 | * Returns: |
| 4432 | */ |
| 4433 | static int qla24xx_n2n_handle_login(struct scsi_qla_host *vha, |
| 4434 | fc_port_t *fcport) |
| 4435 | { |
| 4436 | struct qla_hw_data *ha = vha->hw; |
| 4437 | int res = QLA_SUCCESS, rval; |
| 4438 | int greater_wwpn = 0; |
| 4439 | int logged_in = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4440 | |
Duane Grigsby | edd05de | 2017-10-13 09:34:06 -0700 | [diff] [blame] | 4441 | if (ha->current_topology != ISP_CFG_N) |
| 4442 | return res; |
| 4443 | |
| 4444 | if (wwn_to_u64(vha->port_name) > |
| 4445 | wwn_to_u64(vha->n2n_port_name)) { |
| 4446 | ql_dbg(ql_dbg_disc, vha, 0x2002, |
| 4447 | "HBA WWPN is greater %llx > target %llx\n", |
| 4448 | wwn_to_u64(vha->port_name), |
| 4449 | wwn_to_u64(vha->n2n_port_name)); |
| 4450 | greater_wwpn = 1; |
| 4451 | fcport->d_id.b24 = vha->n2n_id; |
| 4452 | } |
| 4453 | |
| 4454 | fcport->loop_id = vha->loop_id; |
| 4455 | fcport->fc4f_nvme = 0; |
| 4456 | fcport->query = 1; |
| 4457 | |
| 4458 | ql_dbg(ql_dbg_disc, vha, 0x4001, |
| 4459 | "Initiate N2N login handler: HBA port_id=%06x loopid=%d\n", |
| 4460 | fcport->d_id.b24, vha->loop_id); |
| 4461 | |
| 4462 | /* Fill in member data. */ |
| 4463 | if (!greater_wwpn) { |
| 4464 | rval = qla2x00_get_port_database(vha, fcport, 0); |
| 4465 | ql_dbg(ql_dbg_disc, vha, 0x1051, |
| 4466 | "Remote login-state (%x/%x) port_id=%06x loop_id=%x, rval=%d\n", |
| 4467 | fcport->current_login_state, fcport->last_login_state, |
| 4468 | fcport->d_id.b24, fcport->loop_id, rval); |
| 4469 | |
| 4470 | if (((fcport->current_login_state & 0xf) == 0x4) || |
| 4471 | ((fcport->current_login_state & 0xf) == 0x6)) |
| 4472 | logged_in = 1; |
| 4473 | } |
| 4474 | |
| 4475 | if (logged_in || greater_wwpn) { |
| 4476 | if (!vha->nvme_local_port && vha->flags.nvme_enabled) |
| 4477 | qla_nvme_register_hba(vha); |
| 4478 | |
| 4479 | /* Set connected N_Port d_id */ |
| 4480 | if (vha->flags.nvme_enabled) |
| 4481 | fcport->fc4f_nvme = 1; |
| 4482 | |
| 4483 | fcport->scan_state = QLA_FCPORT_FOUND; |
| 4484 | fcport->fw_login_state = DSC_LS_PORT_UNAVAIL; |
| 4485 | fcport->disc_state = DSC_GNL; |
| 4486 | fcport->n2n_flag = 1; |
| 4487 | fcport->flags = 3; |
| 4488 | vha->hw->flags.gpsc_supported = 0; |
| 4489 | |
| 4490 | if (greater_wwpn) { |
| 4491 | ql_dbg(ql_dbg_disc, vha, 0x20e5, |
| 4492 | "%s %d PLOGI ELS %8phC\n", |
| 4493 | __func__, __LINE__, fcport->port_name); |
| 4494 | |
| 4495 | res = qla24xx_els_dcmd2_iocb(vha, ELS_DCMD_PLOGI, |
| 4496 | fcport, fcport->d_id); |
| 4497 | } |
| 4498 | |
| 4499 | if (res != QLA_SUCCESS) { |
| 4500 | ql_log(ql_log_info, vha, 0xd04d, |
| 4501 | "PLOGI Failed: portid=%06x - retrying\n", |
| 4502 | fcport->d_id.b24); |
| 4503 | res = QLA_SUCCESS; |
| 4504 | } else { |
| 4505 | /* State 0x6 means FCP PRLI complete */ |
| 4506 | if ((fcport->current_login_state & 0xf) == 0x6) { |
| 4507 | ql_dbg(ql_dbg_disc, vha, 0x2118, |
| 4508 | "%s %d %8phC post GPDB work\n", |
| 4509 | __func__, __LINE__, fcport->port_name); |
| 4510 | fcport->chip_reset = |
| 4511 | vha->hw->base_qpair->chip_reset; |
| 4512 | qla24xx_post_gpdb_work(vha, fcport, 0); |
| 4513 | } else { |
| 4514 | ql_dbg(ql_dbg_disc, vha, 0x2118, |
| 4515 | "%s %d %8phC post NVMe PRLI\n", |
| 4516 | __func__, __LINE__, fcport->port_name); |
| 4517 | qla24xx_post_prli_work(vha, fcport); |
| 4518 | } |
| 4519 | } |
| 4520 | } else { |
| 4521 | /* Wait for next database change */ |
| 4522 | set_bit(N2N_LOGIN_NEEDED, &vha->dpc_flags); |
| 4523 | } |
| 4524 | |
| 4525 | return res; |
| 4526 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4527 | |
| 4528 | /* |
| 4529 | * qla2x00_configure_local_loop |
| 4530 | * Updates Fibre Channel Device Database with local loop devices. |
| 4531 | * |
| 4532 | * Input: |
| 4533 | * ha = adapter block pointer. |
| 4534 | * |
| 4535 | * Returns: |
| 4536 | * 0 = success. |
| 4537 | */ |
| 4538 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4539 | qla2x00_configure_local_loop(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4540 | { |
| 4541 | int rval, rval2; |
| 4542 | int found_devs; |
| 4543 | int found; |
| 4544 | fc_port_t *fcport, *new_fcport; |
| 4545 | |
| 4546 | uint16_t index; |
| 4547 | uint16_t entries; |
| 4548 | char *id_iter; |
| 4549 | uint16_t loop_id; |
| 4550 | uint8_t domain, area, al_pa; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4551 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4552 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4553 | |
| 4554 | found_devs = 0; |
| 4555 | new_fcport = NULL; |
Chad Dupuis | 642ef98 | 2012-02-09 11:15:57 -0800 | [diff] [blame] | 4556 | entries = MAX_FIBRE_DEVICES_LOOP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4557 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4558 | /* Get list of logged in devices. */ |
Chad Dupuis | 642ef98 | 2012-02-09 11:15:57 -0800 | [diff] [blame] | 4559 | memset(ha->gid_list, 0, qla2x00_gid_list_size(ha)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4560 | 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] | 4561 | &entries); |
| 4562 | if (rval != QLA_SUCCESS) |
| 4563 | goto cleanup_allocation; |
| 4564 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4565 | ql_dbg(ql_dbg_disc, vha, 0x2011, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4566 | "Entries in ID list (%d).\n", entries); |
| 4567 | ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2075, |
| 4568 | (uint8_t *)ha->gid_list, |
| 4569 | entries * sizeof(struct gid_list_info)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4570 | |
| 4571 | /* Allocate temporary fcport for any new fcports discovered. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4572 | new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4573 | if (new_fcport == NULL) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4574 | ql_log(ql_log_warn, vha, 0x2012, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4575 | "Memory allocation failed for fcport.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4576 | rval = QLA_MEMORY_ALLOC_FAILED; |
| 4577 | goto cleanup_allocation; |
| 4578 | } |
| 4579 | new_fcport->flags &= ~FCF_FABRIC_DEVICE; |
| 4580 | |
| 4581 | /* |
| 4582 | * Mark local devices that were present with FCF_DEVICE_LOST for now. |
| 4583 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4584 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4585 | if (atomic_read(&fcport->state) == FCS_ONLINE && |
| 4586 | fcport->port_type != FCT_BROADCAST && |
| 4587 | (fcport->flags & FCF_FABRIC_DEVICE) == 0) { |
| 4588 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4589 | ql_dbg(ql_dbg_disc, vha, 0x2096, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4590 | "Marking port lost loop_id=0x%04x.\n", |
| 4591 | fcport->loop_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4592 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4593 | qla2x00_mark_device_lost(vha, fcport, 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4594 | } |
| 4595 | } |
| 4596 | |
Duane Grigsby | edd05de | 2017-10-13 09:34:06 -0700 | [diff] [blame] | 4597 | /* Inititae N2N login. */ |
| 4598 | if (test_and_clear_bit(N2N_LOGIN_NEEDED, &vha->dpc_flags)) { |
| 4599 | rval = qla24xx_n2n_handle_login(vha, new_fcport); |
| 4600 | if (rval != QLA_SUCCESS) |
| 4601 | goto cleanup_allocation; |
| 4602 | return QLA_SUCCESS; |
| 4603 | } |
| 4604 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4605 | /* Add devices to port list. */ |
| 4606 | id_iter = (char *)ha->gid_list; |
| 4607 | for (index = 0; index < entries; index++) { |
| 4608 | domain = ((struct gid_list_info *)id_iter)->domain; |
| 4609 | area = ((struct gid_list_info *)id_iter)->area; |
| 4610 | al_pa = ((struct gid_list_info *)id_iter)->al_pa; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 4611 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4612 | loop_id = (uint16_t) |
| 4613 | ((struct gid_list_info *)id_iter)->loop_id_2100; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 4614 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4615 | loop_id = le16_to_cpu( |
| 4616 | ((struct gid_list_info *)id_iter)->loop_id); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 4617 | id_iter += ha->gid_list_info_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4618 | |
| 4619 | /* Bypass reserved domain fields. */ |
| 4620 | if ((domain & 0xf0) == 0xf0) |
| 4621 | continue; |
| 4622 | |
| 4623 | /* Bypass if not same domain and area of adapter. */ |
Andrew Vasquez | f7d289f | 2005-08-26 19:08:40 -0700 | [diff] [blame] | 4624 | if (area && domain && |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4625 | (area != vha->d_id.b.area || domain != vha->d_id.b.domain)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4626 | continue; |
| 4627 | |
| 4628 | /* Bypass invalid local loop ID. */ |
| 4629 | if (loop_id > LAST_LOCAL_LOOP_ID) |
| 4630 | continue; |
| 4631 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4632 | memset(new_fcport->port_name, 0, WWN_SIZE); |
Arun Easi | 370d550 | 2012-08-22 14:21:10 -0400 | [diff] [blame] | 4633 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4634 | /* Fill in member data. */ |
| 4635 | new_fcport->d_id.b.domain = domain; |
| 4636 | new_fcport->d_id.b.area = area; |
| 4637 | new_fcport->d_id.b.al_pa = al_pa; |
| 4638 | new_fcport->loop_id = loop_id; |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4639 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4640 | rval2 = qla2x00_get_port_database(vha, new_fcport, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4641 | if (rval2 != QLA_SUCCESS) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4642 | ql_dbg(ql_dbg_disc, vha, 0x2097, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4643 | "Failed to retrieve fcport information " |
| 4644 | "-- get_port_database=%x, loop_id=0x%04x.\n", |
| 4645 | rval2, new_fcport->loop_id); |
Duane Grigsby | edd05de | 2017-10-13 09:34:06 -0700 | [diff] [blame] | 4646 | /* Skip retry if N2N */ |
| 4647 | if (ha->current_topology != ISP_CFG_N) { |
| 4648 | ql_dbg(ql_dbg_disc, vha, 0x2105, |
| 4649 | "Scheduling resync.\n"); |
| 4650 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
| 4651 | continue; |
| 4652 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4653 | } |
| 4654 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4655 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4656 | /* Check for matching device in port list. */ |
| 4657 | found = 0; |
| 4658 | fcport = NULL; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4659 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4660 | if (memcmp(new_fcport->port_name, fcport->port_name, |
| 4661 | WWN_SIZE)) |
| 4662 | continue; |
| 4663 | |
Shyam Sundar | ddb9b12 | 2009-03-24 09:08:10 -0700 | [diff] [blame] | 4664 | fcport->flags &= ~FCF_FABRIC_DEVICE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4665 | fcport->loop_id = new_fcport->loop_id; |
| 4666 | fcport->port_type = new_fcport->port_type; |
| 4667 | fcport->d_id.b24 = new_fcport->d_id.b24; |
| 4668 | memcpy(fcport->node_name, new_fcport->node_name, |
| 4669 | WWN_SIZE); |
| 4670 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4671 | if (!fcport->login_succ) { |
| 4672 | vha->fcport_count++; |
| 4673 | fcport->login_succ = 1; |
| 4674 | fcport->disc_state = DSC_LOGIN_COMPLETE; |
| 4675 | } |
| 4676 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4677 | found++; |
| 4678 | break; |
| 4679 | } |
| 4680 | |
| 4681 | if (!found) { |
| 4682 | /* New device, add to fcports list. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4683 | list_add_tail(&new_fcport->list, &vha->vp_fcports); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4684 | |
| 4685 | /* Allocate a new replacement fcport. */ |
| 4686 | fcport = new_fcport; |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4687 | if (!fcport->login_succ) { |
| 4688 | vha->fcport_count++; |
| 4689 | fcport->login_succ = 1; |
| 4690 | fcport->disc_state = DSC_LOGIN_COMPLETE; |
| 4691 | } |
| 4692 | |
| 4693 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
| 4694 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4695 | new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4696 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4697 | if (new_fcport == NULL) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4698 | ql_log(ql_log_warn, vha, 0xd031, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4699 | "Failed to allocate memory for fcport.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4700 | rval = QLA_MEMORY_ALLOC_FAILED; |
| 4701 | goto cleanup_allocation; |
| 4702 | } |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4703 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4704 | new_fcport->flags &= ~FCF_FABRIC_DEVICE; |
| 4705 | } |
| 4706 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4707 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
| 4708 | |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 4709 | /* Base iIDMA settings on HBA port speed. */ |
Andrew Vasquez | a3cbdfa | 2007-08-13 10:13:18 -0700 | [diff] [blame] | 4710 | fcport->fp_speed = ha->link_data_rate; |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 4711 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4712 | qla2x00_update_fcport(vha, fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4713 | |
| 4714 | found_devs++; |
| 4715 | } |
| 4716 | |
| 4717 | cleanup_allocation: |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 4718 | kfree(new_fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4719 | |
| 4720 | if (rval != QLA_SUCCESS) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4721 | ql_dbg(ql_dbg_disc, vha, 0x2098, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4722 | "Configure local loop error exit: rval=%x.\n", rval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4723 | } |
| 4724 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4725 | return (rval); |
| 4726 | } |
| 4727 | |
| 4728 | static void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4729 | qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport) |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 4730 | { |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 4731 | int rval; |
Quinn Tran | 93f2bd6 | 2014-09-25 05:16:53 -0400 | [diff] [blame] | 4732 | uint16_t mb[MAILBOX_REGISTER_COUNT]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4733 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 4734 | |
Andrew Vasquez | c76f2c0 | 2007-07-19 15:05:57 -0700 | [diff] [blame] | 4735 | if (!IS_IIDMA_CAPABLE(ha)) |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 4736 | return; |
| 4737 | |
Giridhar Malavali | c9afb9a | 2010-09-03 15:20:48 -0700 | [diff] [blame] | 4738 | if (atomic_read(&fcport->state) != FCS_ONLINE) |
| 4739 | return; |
| 4740 | |
Andrew Vasquez | 39bd962 | 2007-09-20 14:07:34 -0700 | [diff] [blame] | 4741 | if (fcport->fp_speed == PORT_SPEED_UNKNOWN || |
| 4742 | fcport->fp_speed > ha->link_data_rate) |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 4743 | return; |
| 4744 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4745 | rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed, |
Andrew Vasquez | a3cbdfa | 2007-08-13 10:13:18 -0700 | [diff] [blame] | 4746 | mb); |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 4747 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4748 | ql_dbg(ql_dbg_disc, vha, 0x2004, |
Oleksandr Khoshaba | 7b833558 | 2013-08-27 01:37:27 -0400 | [diff] [blame] | 4749 | "Unable to adjust iIDMA %8phN -- %04x %x %04x %04x.\n", |
| 4750 | fcport->port_name, rval, fcport->fp_speed, mb[0], mb[1]); |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 4751 | } else { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4752 | ql_dbg(ql_dbg_disc, vha, 0x2005, |
Oleksandr Khoshaba | 7b833558 | 2013-08-27 01:37:27 -0400 | [diff] [blame] | 4753 | "iIDMA adjusted to %s GB/s on %8phN.\n", |
Joe Carnuccio | d0297c9 | 2012-11-21 02:40:40 -0500 | [diff] [blame] | 4754 | qla2x00_get_link_speed_str(ha, fcport->fp_speed), |
Oleksandr Khoshaba | 7b833558 | 2013-08-27 01:37:27 -0400 | [diff] [blame] | 4755 | fcport->port_name); |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 4756 | } |
| 4757 | } |
| 4758 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4759 | /* qla2x00_reg_remote_port is reserved for Initiator Mode only.*/ |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 4760 | static void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4761 | qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport) |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 4762 | { |
| 4763 | struct fc_rport_identifiers rport_ids; |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 4764 | struct fc_rport *rport; |
Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 4765 | unsigned long flags; |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 4766 | |
Andrew Vasquez | f8b02a8 | 2005-08-31 15:21:20 -0700 | [diff] [blame] | 4767 | rport_ids.node_name = wwn_to_u64(fcport->node_name); |
| 4768 | rport_ids.port_name = wwn_to_u64(fcport->port_name); |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 4769 | rport_ids.port_id = fcport->d_id.b.domain << 16 | |
| 4770 | fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa; |
| 4771 | rport_ids.roles = FC_RPORT_ROLE_UNKNOWN; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4772 | fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids); |
Andrew Vasquez | 77d7414 | 2005-07-08 18:00:36 -0700 | [diff] [blame] | 4773 | if (!rport) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4774 | ql_log(ql_log_warn, vha, 0x2006, |
| 4775 | "Unable to allocate fc remote port.\n"); |
Andrew Vasquez | 77d7414 | 2005-07-08 18:00:36 -0700 | [diff] [blame] | 4776 | return; |
| 4777 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4778 | |
Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 4779 | spin_lock_irqsave(fcport->vha->host->host_lock, flags); |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 4780 | *((fc_port_t **)rport->dd_data) = fcport; |
Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 4781 | spin_unlock_irqrestore(fcport->vha->host->host_lock, flags); |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 4782 | |
Andrew Vasquez | ad3e0ed | 2005-08-26 19:08:10 -0700 | [diff] [blame] | 4783 | rport->supported_classes = fcport->supported_classes; |
Andrew Vasquez | 77d7414 | 2005-07-08 18:00:36 -0700 | [diff] [blame] | 4784 | |
| 4785 | rport_ids.roles = FC_RPORT_ROLE_UNKNOWN; |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 4786 | if (fcport->port_type == FCT_INITIATOR) |
| 4787 | rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR; |
| 4788 | if (fcport->port_type == FCT_TARGET) |
| 4789 | rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4790 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4791 | ql_dbg(ql_dbg_disc, vha, 0x20ee, |
| 4792 | "%s %8phN. rport %p is %s mode\n", |
| 4793 | __func__, fcport->port_name, rport, |
| 4794 | (fcport->port_type == FCT_TARGET) ? "tgt" : "ini"); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4795 | |
Andrew Vasquez | 77d7414 | 2005-07-08 18:00:36 -0700 | [diff] [blame] | 4796 | fc_remote_port_rolechg(rport, rport_ids.roles); |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 4797 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4798 | |
| 4799 | /* |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 4800 | * qla2x00_update_fcport |
| 4801 | * Updates device on list. |
| 4802 | * |
| 4803 | * Input: |
| 4804 | * ha = adapter block pointer. |
| 4805 | * fcport = port structure pointer. |
| 4806 | * |
| 4807 | * Return: |
| 4808 | * 0 - Success |
| 4809 | * BIT_0 - error |
| 4810 | * |
| 4811 | * Context: |
| 4812 | * Kernel context. |
| 4813 | */ |
| 4814 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4815 | qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport) |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 4816 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4817 | fcport->vha = vha; |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 4818 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4819 | if (IS_SW_RESV_ADDR(fcport->d_id)) |
| 4820 | return; |
| 4821 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4822 | ql_dbg(ql_dbg_disc, vha, 0x20ef, "%s %8phC\n", |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4823 | __func__, fcport->port_name); |
| 4824 | |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 4825 | if (IS_QLAFX00(vha->hw)) { |
| 4826 | qla2x00_set_fcport_state(fcport, FCS_ONLINE); |
Alexei Potashnik | d20ed91 | 2015-07-14 16:00:47 -0400 | [diff] [blame] | 4827 | goto reg_port; |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 4828 | } |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 4829 | fcport->login_retry = 0; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 4830 | fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4831 | fcport->disc_state = DSC_LOGIN_COMPLETE; |
| 4832 | fcport->deleted = 0; |
| 4833 | fcport->logout_on_delete = 1; |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 4834 | |
Duane Grigsby | e84067d | 2017-06-21 13:48:43 -0700 | [diff] [blame] | 4835 | if (fcport->fc4f_nvme) { |
| 4836 | qla_nvme_register_remote(vha, fcport); |
| 4837 | return; |
| 4838 | } |
| 4839 | |
Joe Carnuccio | 1f93da52 | 2012-11-21 02:40:38 -0500 | [diff] [blame] | 4840 | qla2x00_set_fcport_state(fcport, FCS_ONLINE); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4841 | qla2x00_iidma_fcport(vha, fcport); |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 4842 | qla24xx_update_fcport_fcp_prio(vha, fcport); |
Alexei Potashnik | d20ed91 | 2015-07-14 16:00:47 -0400 | [diff] [blame] | 4843 | |
| 4844 | reg_port: |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4845 | switch (vha->host->active_mode) { |
| 4846 | case MODE_INITIATOR: |
Alexei Potashnik | d20ed91 | 2015-07-14 16:00:47 -0400 | [diff] [blame] | 4847 | qla2x00_reg_remote_port(vha, fcport); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4848 | break; |
| 4849 | case MODE_TARGET: |
| 4850 | if (!vha->vha_tgt.qla_tgt->tgt_stop && |
| 4851 | !vha->vha_tgt.qla_tgt->tgt_stopped) |
| 4852 | qlt_fc_port_added(vha, fcport); |
| 4853 | break; |
| 4854 | case MODE_DUAL: |
| 4855 | qla2x00_reg_remote_port(vha, fcport); |
| 4856 | if (!vha->vha_tgt.qla_tgt->tgt_stop && |
| 4857 | !vha->vha_tgt.qla_tgt->tgt_stopped) |
| 4858 | qlt_fc_port_added(vha, fcport); |
| 4859 | break; |
| 4860 | default: |
| 4861 | break; |
Alexei Potashnik | d20ed91 | 2015-07-14 16:00:47 -0400 | [diff] [blame] | 4862 | } |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 4863 | } |
| 4864 | |
| 4865 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4866 | * qla2x00_configure_fabric |
| 4867 | * Setup SNS devices with loop ID's. |
| 4868 | * |
| 4869 | * Input: |
| 4870 | * ha = adapter block pointer. |
| 4871 | * |
| 4872 | * Returns: |
| 4873 | * 0 = success. |
| 4874 | * BIT_0 = error |
| 4875 | */ |
| 4876 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4877 | qla2x00_configure_fabric(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4878 | { |
Arun Easi | b3b02e6 | 2012-02-09 11:15:39 -0800 | [diff] [blame] | 4879 | int rval; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4880 | fc_port_t *fcport; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4881 | uint16_t mb[MAILBOX_REGISTER_COUNT]; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4882 | uint16_t loop_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4883 | LIST_HEAD(new_fcports); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4884 | struct qla_hw_data *ha = vha->hw; |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 4885 | int discovery_gen; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4886 | |
| 4887 | /* If FL port exists, then SNS is present */ |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 4888 | if (IS_FWI2_CAPABLE(ha)) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4889 | loop_id = NPH_F_PORT; |
| 4890 | else |
| 4891 | loop_id = SNS_FL_PORT; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4892 | 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] | 4893 | if (rval != QLA_SUCCESS) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4894 | ql_dbg(ql_dbg_disc, vha, 0x20a0, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4895 | "MBX_GET_PORT_NAME failed, No FL Port.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4896 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4897 | vha->device_flags &= ~SWITCH_FOUND; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4898 | return (QLA_SUCCESS); |
| 4899 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4900 | vha->device_flags |= SWITCH_FOUND; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4901 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4902 | |
| 4903 | if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) { |
| 4904 | rval = qla2x00_send_change_request(vha, 0x3, 0); |
| 4905 | if (rval != QLA_SUCCESS) |
| 4906 | ql_log(ql_log_warn, vha, 0x121, |
| 4907 | "Failed to enable receiving of RSCN requests: 0x%x.\n", |
| 4908 | rval); |
| 4909 | } |
| 4910 | |
| 4911 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4912 | do { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4913 | qla2x00_mgmt_svr_login(vha); |
| 4914 | |
Andrew Vasquez | cca5335 | 2005-08-26 19:08:30 -0700 | [diff] [blame] | 4915 | /* FDMI support. */ |
| 4916 | if (ql2xfdmienable && |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4917 | test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags)) |
| 4918 | qla2x00_fdmi_register(vha); |
Andrew Vasquez | cca5335 | 2005-08-26 19:08:30 -0700 | [diff] [blame] | 4919 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4920 | /* Ensure we are logged into the SNS. */ |
Joe Carnuccio | a14c771 | 2017-08-23 15:05:12 -0700 | [diff] [blame] | 4921 | loop_id = NPH_SNS_LID(ha); |
Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 4922 | rval = ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff, |
| 4923 | 0xfc, mb, BIT_1|BIT_0); |
Joe Carnuccio | a14c771 | 2017-08-23 15:05:12 -0700 | [diff] [blame] | 4924 | if (rval != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) { |
| 4925 | ql_dbg(ql_dbg_disc, vha, 0x20a1, |
| 4926 | "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x mb[6]=%x mb[7]=%x (%x).\n", |
| 4927 | 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] | 4928 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
Joe Carnuccio | e452ceb | 2013-02-08 01:57:56 -0500 | [diff] [blame] | 4929 | return rval; |
Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 4930 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4931 | if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) { |
| 4932 | if (qla2x00_rft_id(vha)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4933 | /* EMPTY */ |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4934 | ql_dbg(ql_dbg_disc, vha, 0x20a2, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4935 | "Register FC-4 TYPE failed.\n"); |
Quinn Tran | b98ae0d | 2017-06-02 09:12:00 -0700 | [diff] [blame] | 4936 | if (test_bit(LOOP_RESYNC_NEEDED, |
| 4937 | &vha->dpc_flags)) |
| 4938 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4939 | } |
Duane Grigsby | d3bae93 | 2017-06-21 13:48:44 -0700 | [diff] [blame] | 4940 | if (qla2x00_rff_id(vha, FC4_TYPE_FCP_SCSI)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4941 | /* EMPTY */ |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4942 | ql_dbg(ql_dbg_disc, vha, 0x209a, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4943 | "Register FC-4 Features failed.\n"); |
Quinn Tran | b98ae0d | 2017-06-02 09:12:00 -0700 | [diff] [blame] | 4944 | if (test_bit(LOOP_RESYNC_NEEDED, |
| 4945 | &vha->dpc_flags)) |
| 4946 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4947 | } |
Duane Grigsby | d3bae93 | 2017-06-21 13:48:44 -0700 | [diff] [blame] | 4948 | if (vha->flags.nvme_enabled) { |
| 4949 | if (qla2x00_rff_id(vha, FC_TYPE_NVME)) { |
| 4950 | ql_dbg(ql_dbg_disc, vha, 0x2049, |
| 4951 | "Register NVME FC Type Features failed.\n"); |
| 4952 | } |
| 4953 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4954 | if (qla2x00_rnn_id(vha)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4955 | /* EMPTY */ |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4956 | ql_dbg(ql_dbg_disc, vha, 0x2104, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4957 | "Register Node Name failed.\n"); |
Quinn Tran | b98ae0d | 2017-06-02 09:12:00 -0700 | [diff] [blame] | 4958 | if (test_bit(LOOP_RESYNC_NEEDED, |
| 4959 | &vha->dpc_flags)) |
| 4960 | break; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4961 | } else if (qla2x00_rsnn_nn(vha)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4962 | /* EMPTY */ |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4963 | ql_dbg(ql_dbg_disc, vha, 0x209b, |
Colin Ian King | 0bf0efa | 2017-06-30 14:47:41 +0100 | [diff] [blame] | 4964 | "Register Symbolic Node Name failed.\n"); |
Quinn Tran | b98ae0d | 2017-06-02 09:12:00 -0700 | [diff] [blame] | 4965 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) |
| 4966 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4967 | } |
| 4968 | } |
| 4969 | |
Joe Carnuccio | 827210b | 2013-02-08 01:57:57 -0500 | [diff] [blame] | 4970 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
| 4971 | fcport->scan_state = QLA_FCPORT_SCAN; |
| 4972 | } |
| 4973 | |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 4974 | /* Mark the time right before querying FW for connected ports. |
| 4975 | * This process is long, asynchronous and by the time it's done, |
| 4976 | * collected information might not be accurate anymore. E.g. |
| 4977 | * disconnected port might have re-connected and a brand new |
| 4978 | * session has been created. In this case session's generation |
| 4979 | * will be newer than discovery_gen. */ |
| 4980 | qlt_do_generation_tick(vha, &discovery_gen); |
| 4981 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4982 | rval = qla2x00_find_all_fabric_devs(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4983 | if (rval != QLA_SUCCESS) |
| 4984 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4985 | } while (0); |
| 4986 | |
Duane Grigsby | e84067d | 2017-06-21 13:48:43 -0700 | [diff] [blame] | 4987 | if (!vha->nvme_local_port && vha->flags.nvme_enabled) |
| 4988 | qla_nvme_register_hba(vha); |
| 4989 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4990 | if (rval) |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4991 | ql_dbg(ql_dbg_disc, vha, 0x2068, |
| 4992 | "Configure fabric error exit rval=%d.\n", rval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4993 | |
| 4994 | return (rval); |
| 4995 | } |
| 4996 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4997 | /* |
| 4998 | * qla2x00_find_all_fabric_devs |
| 4999 | * |
| 5000 | * Input: |
| 5001 | * ha = adapter block pointer. |
| 5002 | * dev = database device entry pointer. |
| 5003 | * |
| 5004 | * Returns: |
| 5005 | * 0 = success. |
| 5006 | * |
| 5007 | * Context: |
| 5008 | * Kernel context. |
| 5009 | */ |
| 5010 | static int |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5011 | qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5012 | { |
| 5013 | int rval; |
| 5014 | uint16_t loop_id; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5015 | fc_port_t *fcport, *new_fcport; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5016 | int found; |
| 5017 | |
| 5018 | sw_info_t *swl; |
| 5019 | int swl_idx; |
| 5020 | int first_dev, last_dev; |
Mike Waychison | 1516ef4 | 2010-05-04 15:01:31 -0700 | [diff] [blame] | 5021 | port_id_t wrap = {}, nxt_d_id; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5022 | struct qla_hw_data *ha = vha->hw; |
Chad Dupuis | bb4cf5b | 2013-02-08 01:58:01 -0500 | [diff] [blame] | 5023 | struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5024 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5025 | |
| 5026 | rval = QLA_SUCCESS; |
| 5027 | |
| 5028 | /* Try GID_PT to get device list, else GAN. */ |
Andrew Vasquez | 7a67735 | 2012-02-09 11:15:56 -0800 | [diff] [blame] | 5029 | if (!ha->swl) |
Chad Dupuis | 642ef98 | 2012-02-09 11:15:57 -0800 | [diff] [blame] | 5030 | ha->swl = kcalloc(ha->max_fibre_devices, sizeof(sw_info_t), |
Andrew Vasquez | 7a67735 | 2012-02-09 11:15:56 -0800 | [diff] [blame] | 5031 | GFP_KERNEL); |
| 5032 | swl = ha->swl; |
Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 5033 | if (!swl) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5034 | /*EMPTY*/ |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 5035 | ql_dbg(ql_dbg_disc, vha, 0x209c, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5036 | "GID_PT allocations failed, fallback on GA_NXT.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5037 | } else { |
Chad Dupuis | 642ef98 | 2012-02-09 11:15:57 -0800 | [diff] [blame] | 5038 | memset(swl, 0, ha->max_fibre_devices * sizeof(sw_info_t)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5039 | if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5040 | swl = NULL; |
Quinn Tran | b98ae0d | 2017-06-02 09:12:00 -0700 | [diff] [blame] | 5041 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) |
| 5042 | return rval; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5043 | } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5044 | swl = NULL; |
Quinn Tran | b98ae0d | 2017-06-02 09:12:00 -0700 | [diff] [blame] | 5045 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) |
| 5046 | return rval; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5047 | } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5048 | swl = NULL; |
Quinn Tran | b98ae0d | 2017-06-02 09:12:00 -0700 | [diff] [blame] | 5049 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) |
| 5050 | return rval; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5051 | } else if (qla2x00_gfpn_id(vha, swl) != QLA_SUCCESS) { |
| 5052 | swl = NULL; |
Quinn Tran | b98ae0d | 2017-06-02 09:12:00 -0700 | [diff] [blame] | 5053 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) |
| 5054 | return rval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5055 | } |
Chad Dupuis | e8c72ba | 2010-07-23 15:28:25 +0500 | [diff] [blame] | 5056 | |
| 5057 | /* If other queries succeeded probe for FC-4 type */ |
Quinn Tran | b98ae0d | 2017-06-02 09:12:00 -0700 | [diff] [blame] | 5058 | if (swl) { |
Chad Dupuis | e8c72ba | 2010-07-23 15:28:25 +0500 | [diff] [blame] | 5059 | qla2x00_gff_id(vha, swl); |
Quinn Tran | b98ae0d | 2017-06-02 09:12:00 -0700 | [diff] [blame] | 5060 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) |
| 5061 | return rval; |
| 5062 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5063 | } |
| 5064 | swl_idx = 0; |
| 5065 | |
| 5066 | /* Allocate temporary fcport for any new fcports discovered. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5067 | new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5068 | if (new_fcport == NULL) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 5069 | ql_log(ql_log_warn, vha, 0x209d, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5070 | "Failed to allocate memory for fcport.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5071 | return (QLA_MEMORY_ALLOC_FAILED); |
| 5072 | } |
| 5073 | new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5074 | /* Set start port ID scan at adapter ID. */ |
| 5075 | first_dev = 1; |
| 5076 | last_dev = 0; |
| 5077 | |
| 5078 | /* Starting free loop ID. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5079 | loop_id = ha->min_external_loopid; |
| 5080 | for (; loop_id <= ha->max_loop_id; loop_id++) { |
| 5081 | if (qla2x00_is_reserved_id(vha, loop_id)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5082 | continue; |
| 5083 | |
Giridhar Malavali | 3a6478d | 2010-05-28 15:08:20 -0700 | [diff] [blame] | 5084 | if (ha->current_topology == ISP_CFG_FL && |
| 5085 | (atomic_read(&vha->loop_down_timer) || |
| 5086 | LOOP_TRANSITION(vha))) { |
Andrew Vasquez | bb2d52b | 2010-02-18 10:07:27 -0800 | [diff] [blame] | 5087 | atomic_set(&vha->loop_down_timer, 0); |
| 5088 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
| 5089 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5090 | break; |
Andrew Vasquez | bb2d52b | 2010-02-18 10:07:27 -0800 | [diff] [blame] | 5091 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5092 | |
| 5093 | if (swl != NULL) { |
| 5094 | if (last_dev) { |
| 5095 | wrap.b24 = new_fcport->d_id.b24; |
| 5096 | } else { |
| 5097 | new_fcport->d_id.b24 = swl[swl_idx].d_id.b24; |
| 5098 | memcpy(new_fcport->node_name, |
| 5099 | swl[swl_idx].node_name, WWN_SIZE); |
| 5100 | memcpy(new_fcport->port_name, |
| 5101 | swl[swl_idx].port_name, WWN_SIZE); |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 5102 | memcpy(new_fcport->fabric_port_name, |
| 5103 | swl[swl_idx].fabric_port_name, WWN_SIZE); |
| 5104 | new_fcport->fp_speed = swl[swl_idx].fp_speed; |
Chad Dupuis | e8c72ba | 2010-07-23 15:28:25 +0500 | [diff] [blame] | 5105 | new_fcport->fc4_type = swl[swl_idx].fc4_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5106 | |
Duane Grigsby | a5d42f4 | 2017-06-21 13:48:41 -0700 | [diff] [blame] | 5107 | new_fcport->nvme_flag = 0; |
Darren Trap | 1a28faa | 2017-08-30 10:16:48 -0700 | [diff] [blame] | 5108 | new_fcport->fc4f_nvme = 0; |
Duane Grigsby | a5d42f4 | 2017-06-21 13:48:41 -0700 | [diff] [blame] | 5109 | if (vha->flags.nvme_enabled && |
| 5110 | swl[swl_idx].fc4f_nvme) { |
| 5111 | new_fcport->fc4f_nvme = |
| 5112 | swl[swl_idx].fc4f_nvme; |
| 5113 | ql_log(ql_log_info, vha, 0x2131, |
| 5114 | "FOUND: NVME port %8phC as FC Type 28h\n", |
| 5115 | new_fcport->port_name); |
| 5116 | } |
| 5117 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5118 | if (swl[swl_idx].d_id.b.rsvd_1 != 0) { |
| 5119 | last_dev = 1; |
| 5120 | } |
| 5121 | swl_idx++; |
| 5122 | } |
| 5123 | } else { |
| 5124 | /* Send GA_NXT to the switch */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5125 | rval = qla2x00_ga_nxt(vha, new_fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5126 | if (rval != QLA_SUCCESS) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 5127 | ql_log(ql_log_warn, vha, 0x209e, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5128 | "SNS scan failed -- assuming " |
| 5129 | "zero-entry result.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5130 | rval = QLA_SUCCESS; |
| 5131 | break; |
| 5132 | } |
| 5133 | } |
| 5134 | |
| 5135 | /* If wrap on switch device list, exit. */ |
| 5136 | if (first_dev) { |
| 5137 | wrap.b24 = new_fcport->d_id.b24; |
| 5138 | first_dev = 0; |
| 5139 | } else if (new_fcport->d_id.b24 == wrap.b24) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 5140 | ql_dbg(ql_dbg_disc, vha, 0x209f, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5141 | "Device wrap (%02x%02x%02x).\n", |
| 5142 | new_fcport->d_id.b.domain, |
| 5143 | new_fcport->d_id.b.area, |
| 5144 | new_fcport->d_id.b.al_pa); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5145 | break; |
| 5146 | } |
| 5147 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 5148 | /* Bypass if same physical adapter. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5149 | if (new_fcport->d_id.b24 == base_vha->d_id.b24) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5150 | continue; |
| 5151 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 5152 | /* Bypass virtual ports of the same host. */ |
Chad Dupuis | bb4cf5b | 2013-02-08 01:58:01 -0500 | [diff] [blame] | 5153 | if (qla2x00_is_a_vp_did(vha, new_fcport->d_id.b24)) |
| 5154 | continue; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 5155 | |
Andrew Vasquez | f7d289f | 2005-08-26 19:08:40 -0700 | [diff] [blame] | 5156 | /* Bypass if same domain and area of adapter. */ |
| 5157 | if (((new_fcport->d_id.b24 & 0xffff00) == |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5158 | (vha->d_id.b24 & 0xffff00)) && ha->current_topology == |
Andrew Vasquez | f7d289f | 2005-08-26 19:08:40 -0700 | [diff] [blame] | 5159 | ISP_CFG_FL) |
| 5160 | continue; |
| 5161 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5162 | /* Bypass reserved domain fields. */ |
| 5163 | if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0) |
| 5164 | continue; |
| 5165 | |
Chad Dupuis | e8c72ba | 2010-07-23 15:28:25 +0500 | [diff] [blame] | 5166 | /* Bypass ports whose FCP-4 type is not FCP_SCSI */ |
Chad Dupuis | 4da26e1 | 2010-10-15 11:27:40 -0700 | [diff] [blame] | 5167 | if (ql2xgffidenable && |
| 5168 | (new_fcport->fc4_type != FC4_TYPE_FCP_SCSI && |
| 5169 | new_fcport->fc4_type != FC4_TYPE_UNKNOWN)) |
Chad Dupuis | e8c72ba | 2010-07-23 15:28:25 +0500 | [diff] [blame] | 5170 | continue; |
| 5171 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5172 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
| 5173 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5174 | /* Locate matching device in database. */ |
| 5175 | found = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5176 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5177 | if (memcmp(new_fcport->port_name, fcport->port_name, |
| 5178 | WWN_SIZE)) |
| 5179 | continue; |
| 5180 | |
Joe Carnuccio | 827210b | 2013-02-08 01:57:57 -0500 | [diff] [blame] | 5181 | fcport->scan_state = QLA_FCPORT_FOUND; |
Arun Easi | b3b02e6 | 2012-02-09 11:15:39 -0800 | [diff] [blame] | 5182 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5183 | found++; |
| 5184 | |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 5185 | /* Update port state. */ |
| 5186 | memcpy(fcport->fabric_port_name, |
| 5187 | new_fcport->fabric_port_name, WWN_SIZE); |
| 5188 | fcport->fp_speed = new_fcport->fp_speed; |
| 5189 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5190 | /* |
Roland Dreier | b2032fd | 2015-07-14 16:00:42 -0400 | [diff] [blame] | 5191 | * If address the same and state FCS_ONLINE |
| 5192 | * (or in target mode), nothing changed. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5193 | */ |
| 5194 | if (fcport->d_id.b24 == new_fcport->d_id.b24 && |
Roland Dreier | b2032fd | 2015-07-14 16:00:42 -0400 | [diff] [blame] | 5195 | (atomic_read(&fcport->state) == FCS_ONLINE || |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5196 | (vha->host->active_mode == MODE_TARGET))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5197 | break; |
| 5198 | } |
| 5199 | |
| 5200 | /* |
| 5201 | * If device was not a fabric device before. |
| 5202 | */ |
| 5203 | if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) { |
| 5204 | fcport->d_id.b24 = new_fcport->d_id.b24; |
Chad Dupuis | 5f16b33 | 2012-08-22 14:21:00 -0400 | [diff] [blame] | 5205 | qla2x00_clear_loop_id(fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5206 | fcport->flags |= (FCF_FABRIC_DEVICE | |
| 5207 | FCF_LOGIN_NEEDED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5208 | break; |
| 5209 | } |
| 5210 | |
| 5211 | /* |
| 5212 | * Port ID changed or device was marked to be updated; |
| 5213 | * Log it out if still logged in and mark it for |
| 5214 | * relogin later. |
| 5215 | */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5216 | if (qla_tgt_mode_enabled(base_vha)) { |
Roland Dreier | b2032fd | 2015-07-14 16:00:42 -0400 | [diff] [blame] | 5217 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf080, |
| 5218 | "port changed FC ID, %8phC" |
| 5219 | " old %x:%x:%x (loop_id 0x%04x)-> new %x:%x:%x\n", |
| 5220 | fcport->port_name, |
| 5221 | fcport->d_id.b.domain, |
| 5222 | fcport->d_id.b.area, |
| 5223 | fcport->d_id.b.al_pa, |
| 5224 | fcport->loop_id, |
| 5225 | new_fcport->d_id.b.domain, |
| 5226 | new_fcport->d_id.b.area, |
| 5227 | new_fcport->d_id.b.al_pa); |
| 5228 | fcport->d_id.b24 = new_fcport->d_id.b24; |
| 5229 | break; |
| 5230 | } |
| 5231 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5232 | fcport->d_id.b24 = new_fcport->d_id.b24; |
| 5233 | fcport->flags |= FCF_LOGIN_NEEDED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5234 | break; |
| 5235 | } |
| 5236 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5237 | if (found) { |
| 5238 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5239 | continue; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5240 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5241 | /* If device was not in our fcports list, then add it. */ |
Roland Dreier | b2032fd | 2015-07-14 16:00:42 -0400 | [diff] [blame] | 5242 | new_fcport->scan_state = QLA_FCPORT_FOUND; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5243 | list_add_tail(&new_fcport->list, &vha->vp_fcports); |
| 5244 | |
| 5245 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
| 5246 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5247 | |
| 5248 | /* Allocate a new replacement fcport. */ |
| 5249 | nxt_d_id.b24 = new_fcport->d_id.b24; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5250 | new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5251 | if (new_fcport == NULL) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 5252 | ql_log(ql_log_warn, vha, 0xd032, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5253 | "Memory allocation failed for fcport.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5254 | return (QLA_MEMORY_ALLOC_FAILED); |
| 5255 | } |
| 5256 | new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED); |
| 5257 | new_fcport->d_id.b24 = nxt_d_id.b24; |
| 5258 | } |
| 5259 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5260 | qla2x00_free_fcport(new_fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5261 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5262 | /* |
| 5263 | * Logout all previous fabric dev marked lost, except FCP2 devices. |
| 5264 | */ |
| 5265 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
| 5266 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) |
| 5267 | break; |
| 5268 | |
| 5269 | if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 || |
| 5270 | (fcport->flags & FCF_LOGIN_NEEDED) == 0) |
| 5271 | continue; |
| 5272 | |
| 5273 | if (fcport->scan_state == QLA_FCPORT_SCAN) { |
| 5274 | if ((qla_dual_mode_enabled(vha) || |
| 5275 | qla_ini_mode_enabled(vha)) && |
| 5276 | atomic_read(&fcport->state) == FCS_ONLINE) { |
| 5277 | qla2x00_mark_device_lost(vha, fcport, |
| 5278 | ql2xplogiabsentdevice, 0); |
| 5279 | if (fcport->loop_id != FC_NO_LOOP_ID && |
| 5280 | (fcport->flags & FCF_FCP2_DEVICE) == 0 && |
| 5281 | fcport->port_type != FCT_INITIATOR && |
| 5282 | fcport->port_type != FCT_BROADCAST) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 5283 | ql_dbg(ql_dbg_disc, vha, 0x20f0, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5284 | "%s %d %8phC post del sess\n", |
| 5285 | __func__, __LINE__, |
| 5286 | fcport->port_name); |
| 5287 | |
| 5288 | qlt_schedule_sess_for_deletion_lock |
| 5289 | (fcport); |
| 5290 | continue; |
| 5291 | } |
| 5292 | } |
| 5293 | } |
| 5294 | |
| 5295 | if (fcport->scan_state == QLA_FCPORT_FOUND) |
| 5296 | qla24xx_fcport_handle_login(vha, fcport); |
| 5297 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5298 | return (rval); |
| 5299 | } |
| 5300 | |
| 5301 | /* |
| 5302 | * qla2x00_find_new_loop_id |
| 5303 | * Scan through our port list and find a new usable loop ID. |
| 5304 | * |
| 5305 | * Input: |
| 5306 | * ha: adapter state pointer. |
| 5307 | * dev: port structure pointer. |
| 5308 | * |
| 5309 | * Returns: |
| 5310 | * qla2x00 local function return status code. |
| 5311 | * |
| 5312 | * Context: |
| 5313 | * Kernel context. |
| 5314 | */ |
Joe Carnuccio | 03bcfb5 | 2011-03-30 11:46:27 -0700 | [diff] [blame] | 5315 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5316 | 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] | 5317 | { |
| 5318 | int rval; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5319 | struct qla_hw_data *ha = vha->hw; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5320 | unsigned long flags = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5321 | |
| 5322 | rval = QLA_SUCCESS; |
| 5323 | |
Chad Dupuis | 5f16b33 | 2012-08-22 14:21:00 -0400 | [diff] [blame] | 5324 | spin_lock_irqsave(&ha->vport_slock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5325 | |
Chad Dupuis | 5f16b33 | 2012-08-22 14:21:00 -0400 | [diff] [blame] | 5326 | dev->loop_id = find_first_zero_bit(ha->loop_id_map, |
| 5327 | LOOPID_MAP_SIZE); |
| 5328 | if (dev->loop_id >= LOOPID_MAP_SIZE || |
| 5329 | qla2x00_is_reserved_id(vha, dev->loop_id)) { |
| 5330 | dev->loop_id = FC_NO_LOOP_ID; |
| 5331 | rval = QLA_FUNCTION_FAILED; |
| 5332 | } else |
| 5333 | set_bit(dev->loop_id, ha->loop_id_map); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5334 | |
Chad Dupuis | 5f16b33 | 2012-08-22 14:21:00 -0400 | [diff] [blame] | 5335 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5336 | |
Chad Dupuis | 5f16b33 | 2012-08-22 14:21:00 -0400 | [diff] [blame] | 5337 | if (rval == QLA_SUCCESS) |
| 5338 | ql_dbg(ql_dbg_disc, dev->vha, 0x2086, |
| 5339 | "Assigning new loopid=%x, portid=%x.\n", |
| 5340 | dev->loop_id, dev->d_id.b24); |
| 5341 | else |
| 5342 | ql_log(ql_log_warn, dev->vha, 0x2087, |
| 5343 | "No loop_id's available, portid=%x.\n", |
| 5344 | dev->d_id.b24); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5345 | |
| 5346 | return (rval); |
| 5347 | } |
| 5348 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5349 | |
| 5350 | /* |
| 5351 | * qla2x00_fabric_login |
| 5352 | * Issue fabric login command. |
| 5353 | * |
| 5354 | * Input: |
| 5355 | * ha = adapter block pointer. |
| 5356 | * device = pointer to FC device type structure. |
| 5357 | * |
| 5358 | * Returns: |
| 5359 | * 0 - Login successfully |
| 5360 | * 1 - Login failed |
| 5361 | * 2 - Initiator device |
| 5362 | * 3 - Fatal error |
| 5363 | */ |
| 5364 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5365 | qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5366 | uint16_t *next_loopid) |
| 5367 | { |
| 5368 | int rval; |
| 5369 | int retry; |
| 5370 | uint16_t tmp_loopid; |
| 5371 | uint16_t mb[MAILBOX_REGISTER_COUNT]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5372 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5373 | |
| 5374 | retry = 0; |
| 5375 | tmp_loopid = 0; |
| 5376 | |
| 5377 | for (;;) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5378 | ql_dbg(ql_dbg_disc, vha, 0x2000, |
| 5379 | "Trying Fabric Login w/loop id 0x%04x for port " |
| 5380 | "%02x%02x%02x.\n", |
| 5381 | fcport->loop_id, fcport->d_id.b.domain, |
| 5382 | fcport->d_id.b.area, fcport->d_id.b.al_pa); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5383 | |
| 5384 | /* Login fcport on switch. */ |
Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 5385 | rval = ha->isp_ops->fabric_login(vha, fcport->loop_id, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5386 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 5387 | fcport->d_id.b.al_pa, mb, BIT_0); |
Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 5388 | if (rval != QLA_SUCCESS) { |
| 5389 | return rval; |
| 5390 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5391 | if (mb[0] == MBS_PORT_ID_USED) { |
| 5392 | /* |
| 5393 | * Device has another loop ID. The firmware team |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5394 | * recommends the driver perform an implicit login with |
| 5395 | * the specified ID again. The ID we just used is save |
| 5396 | * here so we return with an ID that can be tried by |
| 5397 | * the next login. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5398 | */ |
| 5399 | retry++; |
| 5400 | tmp_loopid = fcport->loop_id; |
| 5401 | fcport->loop_id = mb[1]; |
| 5402 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5403 | ql_dbg(ql_dbg_disc, vha, 0x2001, |
| 5404 | "Fabric Login: port in use - next loop " |
| 5405 | "id=0x%04x, port id= %02x%02x%02x.\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5406 | fcport->loop_id, fcport->d_id.b.domain, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5407 | fcport->d_id.b.area, fcport->d_id.b.al_pa); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5408 | |
| 5409 | } else if (mb[0] == MBS_COMMAND_COMPLETE) { |
| 5410 | /* |
| 5411 | * Login succeeded. |
| 5412 | */ |
| 5413 | if (retry) { |
| 5414 | /* A retry occurred before. */ |
| 5415 | *next_loopid = tmp_loopid; |
| 5416 | } else { |
| 5417 | /* |
| 5418 | * No retry occurred before. Just increment the |
| 5419 | * ID value for next login. |
| 5420 | */ |
| 5421 | *next_loopid = (fcport->loop_id + 1); |
| 5422 | } |
| 5423 | |
| 5424 | if (mb[1] & BIT_0) { |
| 5425 | fcport->port_type = FCT_INITIATOR; |
| 5426 | } else { |
| 5427 | fcport->port_type = FCT_TARGET; |
| 5428 | if (mb[1] & BIT_1) { |
Santosh Vernekar | 8474f3a | 2009-08-25 11:36:16 -0700 | [diff] [blame] | 5429 | fcport->flags |= FCF_FCP2_DEVICE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5430 | } |
| 5431 | } |
| 5432 | |
Andrew Vasquez | ad3e0ed | 2005-08-26 19:08:10 -0700 | [diff] [blame] | 5433 | if (mb[10] & BIT_0) |
| 5434 | fcport->supported_classes |= FC_COS_CLASS2; |
| 5435 | if (mb[10] & BIT_1) |
| 5436 | fcport->supported_classes |= FC_COS_CLASS3; |
| 5437 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5438 | if (IS_FWI2_CAPABLE(ha)) { |
| 5439 | if (mb[10] & BIT_7) |
| 5440 | fcport->flags |= |
| 5441 | FCF_CONF_COMP_SUPPORTED; |
| 5442 | } |
| 5443 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5444 | rval = QLA_SUCCESS; |
| 5445 | break; |
| 5446 | } else if (mb[0] == MBS_LOOP_ID_USED) { |
| 5447 | /* |
| 5448 | * Loop ID already used, try next loop ID. |
| 5449 | */ |
| 5450 | fcport->loop_id++; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5451 | rval = qla2x00_find_new_loop_id(vha, fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5452 | if (rval != QLA_SUCCESS) { |
| 5453 | /* Ran out of loop IDs to use */ |
| 5454 | break; |
| 5455 | } |
| 5456 | } else if (mb[0] == MBS_COMMAND_ERROR) { |
| 5457 | /* |
| 5458 | * Firmware possibly timed out during login. If NO |
| 5459 | * retries are left to do then the device is declared |
| 5460 | * dead. |
| 5461 | */ |
| 5462 | *next_loopid = fcport->loop_id; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5463 | ha->isp_ops->fabric_logout(vha, fcport->loop_id, |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 5464 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 5465 | fcport->d_id.b.al_pa); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5466 | qla2x00_mark_device_lost(vha, fcport, 1, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5467 | |
| 5468 | rval = 1; |
| 5469 | break; |
| 5470 | } else { |
| 5471 | /* |
| 5472 | * unrecoverable / not handled error |
| 5473 | */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5474 | ql_dbg(ql_dbg_disc, vha, 0x2002, |
| 5475 | "Failed=%x port_id=%02x%02x%02x loop_id=%x " |
| 5476 | "jiffies=%lx.\n", mb[0], fcport->d_id.b.domain, |
| 5477 | fcport->d_id.b.area, fcport->d_id.b.al_pa, |
| 5478 | fcport->loop_id, jiffies); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5479 | |
| 5480 | *next_loopid = fcport->loop_id; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5481 | ha->isp_ops->fabric_logout(vha, fcport->loop_id, |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 5482 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 5483 | fcport->d_id.b.al_pa); |
Chad Dupuis | 5f16b33 | 2012-08-22 14:21:00 -0400 | [diff] [blame] | 5484 | qla2x00_clear_loop_id(fcport); |
Andrew Vasquez | 0eedfcf | 2005-10-27 11:09:38 -0700 | [diff] [blame] | 5485 | fcport->login_retry = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5486 | |
| 5487 | rval = 3; |
| 5488 | break; |
| 5489 | } |
| 5490 | } |
| 5491 | |
| 5492 | return (rval); |
| 5493 | } |
| 5494 | |
| 5495 | /* |
| 5496 | * qla2x00_local_device_login |
| 5497 | * Issue local device login command. |
| 5498 | * |
| 5499 | * Input: |
| 5500 | * ha = adapter block pointer. |
| 5501 | * loop_id = loop id of device to login to. |
| 5502 | * |
| 5503 | * Returns (Where's the #define!!!!): |
| 5504 | * 0 - Login successfully |
| 5505 | * 1 - Login failed |
| 5506 | * 3 - Fatal error |
| 5507 | */ |
| 5508 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5509 | 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] | 5510 | { |
| 5511 | int rval; |
| 5512 | uint16_t mb[MAILBOX_REGISTER_COUNT]; |
| 5513 | |
| 5514 | memset(mb, 0, sizeof(mb)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5515 | rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5516 | if (rval == QLA_SUCCESS) { |
| 5517 | /* Interrogate mailbox registers for any errors */ |
| 5518 | if (mb[0] == MBS_COMMAND_ERROR) |
| 5519 | rval = 1; |
| 5520 | else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR) |
| 5521 | /* device not in PCB table */ |
| 5522 | rval = 3; |
| 5523 | } |
| 5524 | |
| 5525 | return (rval); |
| 5526 | } |
| 5527 | |
| 5528 | /* |
| 5529 | * qla2x00_loop_resync |
| 5530 | * Resync with fibre channel devices. |
| 5531 | * |
| 5532 | * Input: |
| 5533 | * ha = adapter block pointer. |
| 5534 | * |
| 5535 | * Returns: |
| 5536 | * 0 = success |
| 5537 | */ |
| 5538 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5539 | qla2x00_loop_resync(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5540 | { |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5541 | int rval = QLA_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5542 | uint32_t wait_time; |
Anirban Chakraborty | 67c2e93 | 2009-04-06 22:33:42 -0700 | [diff] [blame] | 5543 | struct req_que *req; |
| 5544 | struct rsp_que *rsp; |
| 5545 | |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 5546 | req = vha->req; |
Anirban Chakraborty | 67c2e93 | 2009-04-06 22:33:42 -0700 | [diff] [blame] | 5547 | rsp = req->rsp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5548 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5549 | clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags); |
| 5550 | if (vha->flags.online) { |
| 5551 | if (!(rval = qla2x00_fw_ready(vha))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5552 | /* Wait at most MAX_TARGET RSCNs for a stable link. */ |
| 5553 | wait_time = 256; |
| 5554 | do { |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 5555 | if (!IS_QLAFX00(vha->hw)) { |
| 5556 | /* |
| 5557 | * Issue a marker after FW becomes |
| 5558 | * ready. |
| 5559 | */ |
| 5560 | qla2x00_marker(vha, req, rsp, 0, 0, |
| 5561 | MK_SYNC_ALL); |
| 5562 | vha->marker_needed = 0; |
| 5563 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5564 | |
| 5565 | /* Remap devices on Loop. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5566 | clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5567 | |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 5568 | if (IS_QLAFX00(vha->hw)) |
| 5569 | qlafx00_configure_devices(vha); |
| 5570 | else |
| 5571 | qla2x00_configure_loop(vha); |
| 5572 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5573 | wait_time--; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5574 | } while (!atomic_read(&vha->loop_down_timer) && |
| 5575 | !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) |
| 5576 | && wait_time && (test_bit(LOOP_RESYNC_NEEDED, |
| 5577 | &vha->dpc_flags))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5578 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5579 | } |
| 5580 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5581 | if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5582 | return (QLA_FUNCTION_FAILED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5583 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5584 | if (rval) |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5585 | ql_dbg(ql_dbg_disc, vha, 0x206c, |
| 5586 | "%s *** FAILED ***.\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5587 | |
| 5588 | return (rval); |
| 5589 | } |
| 5590 | |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 5591 | /* |
| 5592 | * qla2x00_perform_loop_resync |
| 5593 | * Description: This function will set the appropriate flags and call |
| 5594 | * qla2x00_loop_resync. If successful loop will be resynced |
| 5595 | * Arguments : scsi_qla_host_t pointer |
| 5596 | * returm : Success or Failure |
| 5597 | */ |
| 5598 | |
| 5599 | int qla2x00_perform_loop_resync(scsi_qla_host_t *ha) |
| 5600 | { |
| 5601 | int32_t rval = 0; |
| 5602 | |
| 5603 | if (!test_and_set_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags)) { |
| 5604 | /*Configure the flags so that resync happens properly*/ |
| 5605 | atomic_set(&ha->loop_down_timer, 0); |
| 5606 | if (!(ha->device_flags & DFLG_NO_CABLE)) { |
| 5607 | atomic_set(&ha->loop_state, LOOP_UP); |
| 5608 | set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags); |
| 5609 | set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags); |
| 5610 | set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags); |
| 5611 | |
| 5612 | rval = qla2x00_loop_resync(ha); |
| 5613 | } else |
| 5614 | atomic_set(&ha->loop_state, LOOP_DEAD); |
| 5615 | |
| 5616 | clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags); |
| 5617 | } |
| 5618 | |
| 5619 | return rval; |
| 5620 | } |
| 5621 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5622 | void |
Andrew Vasquez | 67becc0 | 2009-08-25 11:36:20 -0700 | [diff] [blame] | 5623 | qla2x00_update_fcports(scsi_qla_host_t *base_vha) |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 5624 | { |
| 5625 | fc_port_t *fcport; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5626 | struct scsi_qla_host *vha; |
| 5627 | struct qla_hw_data *ha = base_vha->hw; |
| 5628 | unsigned long flags; |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 5629 | |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5630 | spin_lock_irqsave(&ha->vport_slock, flags); |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 5631 | /* Go with deferred removal of rport references. */ |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5632 | list_for_each_entry(vha, &base_vha->hw->vp_list, list) { |
| 5633 | atomic_inc(&vha->vref_count); |
| 5634 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
Dan Carpenter | 8ae598d | 2010-12-21 16:00:15 -0800 | [diff] [blame] | 5635 | if (fcport->drport && |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5636 | atomic_read(&fcport->state) != FCS_UNCONFIGURED) { |
| 5637 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
Andrew Vasquez | 67becc0 | 2009-08-25 11:36:20 -0700 | [diff] [blame] | 5638 | qla2x00_rport_del(fcport); |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 5639 | |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5640 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 5641 | } |
| 5642 | } |
| 5643 | atomic_dec(&vha->vref_count); |
Joe Carnuccio | c4a9b53 | 2017-03-15 09:48:43 -0700 | [diff] [blame] | 5644 | wake_up(&vha->vref_waitq); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5645 | } |
| 5646 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 5647 | } |
| 5648 | |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 5649 | /* Assumes idc_lock always held on entry */ |
| 5650 | void |
| 5651 | qla83xx_reset_ownership(scsi_qla_host_t *vha) |
| 5652 | { |
| 5653 | struct qla_hw_data *ha = vha->hw; |
| 5654 | uint32_t drv_presence, drv_presence_mask; |
| 5655 | uint32_t dev_part_info1, dev_part_info2, class_type; |
| 5656 | uint32_t class_type_mask = 0x3; |
| 5657 | uint16_t fcoe_other_function = 0xffff, i; |
| 5658 | |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 5659 | if (IS_QLA8044(ha)) { |
| 5660 | drv_presence = qla8044_rd_direct(vha, |
| 5661 | QLA8044_CRB_DRV_ACTIVE_INDEX); |
| 5662 | dev_part_info1 = qla8044_rd_direct(vha, |
| 5663 | QLA8044_CRB_DEV_PART_INFO_INDEX); |
| 5664 | dev_part_info2 = qla8044_rd_direct(vha, |
| 5665 | QLA8044_CRB_DEV_PART_INFO2); |
| 5666 | } else { |
| 5667 | qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence); |
| 5668 | qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO1, &dev_part_info1); |
| 5669 | qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO2, &dev_part_info2); |
| 5670 | } |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 5671 | for (i = 0; i < 8; i++) { |
| 5672 | class_type = ((dev_part_info1 >> (i * 4)) & class_type_mask); |
| 5673 | if ((class_type == QLA83XX_CLASS_TYPE_FCOE) && |
| 5674 | (i != ha->portnum)) { |
| 5675 | fcoe_other_function = i; |
| 5676 | break; |
| 5677 | } |
| 5678 | } |
| 5679 | if (fcoe_other_function == 0xffff) { |
| 5680 | for (i = 0; i < 8; i++) { |
| 5681 | class_type = ((dev_part_info2 >> (i * 4)) & |
| 5682 | class_type_mask); |
| 5683 | if ((class_type == QLA83XX_CLASS_TYPE_FCOE) && |
| 5684 | ((i + 8) != ha->portnum)) { |
| 5685 | fcoe_other_function = i + 8; |
| 5686 | break; |
| 5687 | } |
| 5688 | } |
| 5689 | } |
| 5690 | /* |
| 5691 | * Prepare drv-presence mask based on fcoe functions present. |
| 5692 | * However consider only valid physical fcoe function numbers (0-15). |
| 5693 | */ |
| 5694 | drv_presence_mask = ~((1 << (ha->portnum)) | |
| 5695 | ((fcoe_other_function == 0xffff) ? |
| 5696 | 0 : (1 << (fcoe_other_function)))); |
| 5697 | |
| 5698 | /* We are the reset owner iff: |
| 5699 | * - No other protocol drivers present. |
| 5700 | * - This is the lowest among fcoe functions. */ |
| 5701 | if (!(drv_presence & drv_presence_mask) && |
| 5702 | (ha->portnum < fcoe_other_function)) { |
| 5703 | ql_dbg(ql_dbg_p3p, vha, 0xb07f, |
| 5704 | "This host is Reset owner.\n"); |
| 5705 | ha->flags.nic_core_reset_owner = 1; |
| 5706 | } |
| 5707 | } |
| 5708 | |
Saurav Kashyap | fa49263 | 2012-11-21 02:40:29 -0500 | [diff] [blame] | 5709 | static int |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 5710 | __qla83xx_set_drv_ack(scsi_qla_host_t *vha) |
| 5711 | { |
| 5712 | int rval = QLA_SUCCESS; |
| 5713 | struct qla_hw_data *ha = vha->hw; |
| 5714 | uint32_t drv_ack; |
| 5715 | |
| 5716 | rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack); |
| 5717 | if (rval == QLA_SUCCESS) { |
| 5718 | drv_ack |= (1 << ha->portnum); |
| 5719 | rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack); |
| 5720 | } |
| 5721 | |
| 5722 | return rval; |
| 5723 | } |
| 5724 | |
Saurav Kashyap | fa49263 | 2012-11-21 02:40:29 -0500 | [diff] [blame] | 5725 | static int |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 5726 | __qla83xx_clear_drv_ack(scsi_qla_host_t *vha) |
| 5727 | { |
| 5728 | int rval = QLA_SUCCESS; |
| 5729 | struct qla_hw_data *ha = vha->hw; |
| 5730 | uint32_t drv_ack; |
| 5731 | |
| 5732 | rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack); |
| 5733 | if (rval == QLA_SUCCESS) { |
| 5734 | drv_ack &= ~(1 << ha->portnum); |
| 5735 | rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack); |
| 5736 | } |
| 5737 | |
| 5738 | return rval; |
| 5739 | } |
| 5740 | |
Saurav Kashyap | fa49263 | 2012-11-21 02:40:29 -0500 | [diff] [blame] | 5741 | static const char * |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 5742 | qla83xx_dev_state_to_string(uint32_t dev_state) |
| 5743 | { |
| 5744 | switch (dev_state) { |
| 5745 | case QLA8XXX_DEV_COLD: |
| 5746 | return "COLD/RE-INIT"; |
| 5747 | case QLA8XXX_DEV_INITIALIZING: |
| 5748 | return "INITIALIZING"; |
| 5749 | case QLA8XXX_DEV_READY: |
| 5750 | return "READY"; |
| 5751 | case QLA8XXX_DEV_NEED_RESET: |
| 5752 | return "NEED RESET"; |
| 5753 | case QLA8XXX_DEV_NEED_QUIESCENT: |
| 5754 | return "NEED QUIESCENT"; |
| 5755 | case QLA8XXX_DEV_FAILED: |
| 5756 | return "FAILED"; |
| 5757 | case QLA8XXX_DEV_QUIESCENT: |
| 5758 | return "QUIESCENT"; |
| 5759 | default: |
| 5760 | return "Unknown"; |
| 5761 | } |
| 5762 | } |
| 5763 | |
| 5764 | /* Assumes idc-lock always held on entry */ |
| 5765 | void |
| 5766 | qla83xx_idc_audit(scsi_qla_host_t *vha, int audit_type) |
| 5767 | { |
| 5768 | struct qla_hw_data *ha = vha->hw; |
| 5769 | uint32_t idc_audit_reg = 0, duration_secs = 0; |
| 5770 | |
| 5771 | switch (audit_type) { |
| 5772 | case IDC_AUDIT_TIMESTAMP: |
| 5773 | ha->idc_audit_ts = (jiffies_to_msecs(jiffies) / 1000); |
| 5774 | idc_audit_reg = (ha->portnum) | |
| 5775 | (IDC_AUDIT_TIMESTAMP << 7) | (ha->idc_audit_ts << 8); |
| 5776 | qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg); |
| 5777 | break; |
| 5778 | |
| 5779 | case IDC_AUDIT_COMPLETION: |
| 5780 | duration_secs = ((jiffies_to_msecs(jiffies) - |
| 5781 | jiffies_to_msecs(ha->idc_audit_ts)) / 1000); |
| 5782 | idc_audit_reg = (ha->portnum) | |
| 5783 | (IDC_AUDIT_COMPLETION << 7) | (duration_secs << 8); |
| 5784 | qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg); |
| 5785 | break; |
| 5786 | |
| 5787 | default: |
| 5788 | ql_log(ql_log_warn, vha, 0xb078, |
| 5789 | "Invalid audit type specified.\n"); |
| 5790 | break; |
| 5791 | } |
| 5792 | } |
| 5793 | |
| 5794 | /* Assumes idc_lock always held on entry */ |
Saurav Kashyap | fa49263 | 2012-11-21 02:40:29 -0500 | [diff] [blame] | 5795 | static int |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 5796 | qla83xx_initiating_reset(scsi_qla_host_t *vha) |
| 5797 | { |
| 5798 | struct qla_hw_data *ha = vha->hw; |
| 5799 | uint32_t idc_control, dev_state; |
| 5800 | |
| 5801 | __qla83xx_get_idc_control(vha, &idc_control); |
| 5802 | if ((idc_control & QLA83XX_IDC_RESET_DISABLED)) { |
| 5803 | ql_log(ql_log_info, vha, 0xb080, |
| 5804 | "NIC Core reset has been disabled. idc-control=0x%x\n", |
| 5805 | idc_control); |
| 5806 | return QLA_FUNCTION_FAILED; |
| 5807 | } |
| 5808 | |
| 5809 | /* Set NEED-RESET iff in READY state and we are the reset-owner */ |
| 5810 | qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state); |
| 5811 | if (ha->flags.nic_core_reset_owner && dev_state == QLA8XXX_DEV_READY) { |
| 5812 | qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, |
| 5813 | QLA8XXX_DEV_NEED_RESET); |
| 5814 | ql_log(ql_log_info, vha, 0xb056, "HW State: NEED RESET.\n"); |
| 5815 | qla83xx_idc_audit(vha, IDC_AUDIT_TIMESTAMP); |
| 5816 | } else { |
| 5817 | const char *state = qla83xx_dev_state_to_string(dev_state); |
| 5818 | ql_log(ql_log_info, vha, 0xb057, "HW State: %s.\n", state); |
| 5819 | |
| 5820 | /* SV: XXX: Is timeout required here? */ |
| 5821 | /* Wait for IDC state change READY -> NEED_RESET */ |
| 5822 | while (dev_state == QLA8XXX_DEV_READY) { |
| 5823 | qla83xx_idc_unlock(vha, 0); |
| 5824 | msleep(200); |
| 5825 | qla83xx_idc_lock(vha, 0); |
| 5826 | qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state); |
| 5827 | } |
| 5828 | } |
| 5829 | |
| 5830 | /* Send IDC ack by writing to drv-ack register */ |
| 5831 | __qla83xx_set_drv_ack(vha); |
| 5832 | |
| 5833 | return QLA_SUCCESS; |
| 5834 | } |
| 5835 | |
| 5836 | int |
| 5837 | __qla83xx_set_idc_control(scsi_qla_host_t *vha, uint32_t idc_control) |
| 5838 | { |
| 5839 | return qla83xx_wr_reg(vha, QLA83XX_IDC_CONTROL, idc_control); |
| 5840 | } |
| 5841 | |
| 5842 | int |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 5843 | __qla83xx_get_idc_control(scsi_qla_host_t *vha, uint32_t *idc_control) |
| 5844 | { |
| 5845 | return qla83xx_rd_reg(vha, QLA83XX_IDC_CONTROL, idc_control); |
| 5846 | } |
| 5847 | |
Saurav Kashyap | fa49263 | 2012-11-21 02:40:29 -0500 | [diff] [blame] | 5848 | static int |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 5849 | qla83xx_check_driver_presence(scsi_qla_host_t *vha) |
| 5850 | { |
| 5851 | uint32_t drv_presence = 0; |
| 5852 | struct qla_hw_data *ha = vha->hw; |
| 5853 | |
| 5854 | qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence); |
| 5855 | if (drv_presence & (1 << ha->portnum)) |
| 5856 | return QLA_SUCCESS; |
| 5857 | else |
| 5858 | return QLA_TEST_FAILED; |
| 5859 | } |
| 5860 | |
| 5861 | int |
| 5862 | qla83xx_nic_core_reset(scsi_qla_host_t *vha) |
| 5863 | { |
| 5864 | int rval = QLA_SUCCESS; |
| 5865 | struct qla_hw_data *ha = vha->hw; |
| 5866 | |
| 5867 | ql_dbg(ql_dbg_p3p, vha, 0xb058, |
| 5868 | "Entered %s().\n", __func__); |
| 5869 | |
| 5870 | if (vha->device_flags & DFLG_DEV_FAILED) { |
| 5871 | ql_log(ql_log_warn, vha, 0xb059, |
| 5872 | "Device in unrecoverable FAILED state.\n"); |
| 5873 | return QLA_FUNCTION_FAILED; |
| 5874 | } |
| 5875 | |
| 5876 | qla83xx_idc_lock(vha, 0); |
| 5877 | |
| 5878 | if (qla83xx_check_driver_presence(vha) != QLA_SUCCESS) { |
| 5879 | ql_log(ql_log_warn, vha, 0xb05a, |
| 5880 | "Function=0x%x has been removed from IDC participation.\n", |
| 5881 | ha->portnum); |
| 5882 | rval = QLA_FUNCTION_FAILED; |
| 5883 | goto exit; |
| 5884 | } |
| 5885 | |
| 5886 | qla83xx_reset_ownership(vha); |
| 5887 | |
| 5888 | rval = qla83xx_initiating_reset(vha); |
| 5889 | |
| 5890 | /* |
| 5891 | * Perform reset if we are the reset-owner, |
| 5892 | * else wait till IDC state changes to READY/FAILED. |
| 5893 | */ |
| 5894 | if (rval == QLA_SUCCESS) { |
| 5895 | rval = qla83xx_idc_state_handler(vha); |
| 5896 | |
| 5897 | if (rval == QLA_SUCCESS) |
| 5898 | ha->flags.nic_core_hung = 0; |
| 5899 | __qla83xx_clear_drv_ack(vha); |
| 5900 | } |
| 5901 | |
| 5902 | exit: |
| 5903 | qla83xx_idc_unlock(vha, 0); |
| 5904 | |
| 5905 | ql_dbg(ql_dbg_p3p, vha, 0xb05b, "Exiting %s.\n", __func__); |
| 5906 | |
| 5907 | return rval; |
| 5908 | } |
| 5909 | |
Saurav Kashyap | 8117877 | 2012-08-22 14:21:04 -0400 | [diff] [blame] | 5910 | int |
| 5911 | qla2xxx_mctp_dump(scsi_qla_host_t *vha) |
| 5912 | { |
| 5913 | struct qla_hw_data *ha = vha->hw; |
| 5914 | int rval = QLA_FUNCTION_FAILED; |
| 5915 | |
| 5916 | if (!IS_MCTP_CAPABLE(ha)) { |
| 5917 | /* This message can be removed from the final version */ |
| 5918 | ql_log(ql_log_info, vha, 0x506d, |
| 5919 | "This board is not MCTP capable\n"); |
| 5920 | return rval; |
| 5921 | } |
| 5922 | |
| 5923 | if (!ha->mctp_dump) { |
| 5924 | ha->mctp_dump = dma_alloc_coherent(&ha->pdev->dev, |
| 5925 | MCTP_DUMP_SIZE, &ha->mctp_dump_dma, GFP_KERNEL); |
| 5926 | |
| 5927 | if (!ha->mctp_dump) { |
| 5928 | ql_log(ql_log_warn, vha, 0x506e, |
| 5929 | "Failed to allocate memory for mctp dump\n"); |
| 5930 | return rval; |
| 5931 | } |
| 5932 | } |
| 5933 | |
| 5934 | #define MCTP_DUMP_STR_ADDR 0x00000000 |
| 5935 | rval = qla2x00_dump_mctp_data(vha, ha->mctp_dump_dma, |
| 5936 | MCTP_DUMP_STR_ADDR, MCTP_DUMP_SIZE/4); |
| 5937 | if (rval != QLA_SUCCESS) { |
| 5938 | ql_log(ql_log_warn, vha, 0x506f, |
| 5939 | "Failed to capture mctp dump\n"); |
| 5940 | } else { |
| 5941 | ql_log(ql_log_info, vha, 0x5070, |
| 5942 | "Mctp dump capture for host (%ld/%p).\n", |
| 5943 | vha->host_no, ha->mctp_dump); |
| 5944 | ha->mctp_dumped = 1; |
| 5945 | } |
| 5946 | |
Saurav Kashyap | 409ee0f | 2012-08-22 14:21:29 -0400 | [diff] [blame] | 5947 | if (!ha->flags.nic_core_reset_hdlr_active && !ha->portnum) { |
Saurav Kashyap | 8117877 | 2012-08-22 14:21:04 -0400 | [diff] [blame] | 5948 | ha->flags.nic_core_reset_hdlr_active = 1; |
| 5949 | rval = qla83xx_restart_nic_firmware(vha); |
| 5950 | if (rval) |
| 5951 | /* NIC Core reset failed. */ |
| 5952 | ql_log(ql_log_warn, vha, 0x5071, |
| 5953 | "Failed to restart nic firmware\n"); |
| 5954 | else |
| 5955 | ql_dbg(ql_dbg_p3p, vha, 0xb084, |
| 5956 | "Restarted NIC firmware successfully.\n"); |
| 5957 | ha->flags.nic_core_reset_hdlr_active = 0; |
| 5958 | } |
| 5959 | |
| 5960 | return rval; |
| 5961 | |
| 5962 | } |
| 5963 | |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 5964 | /* |
Chad Dupuis | 8fcd6b8 | 2012-08-22 14:21:06 -0400 | [diff] [blame] | 5965 | * qla2x00_quiesce_io |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 5966 | * Description: This function will block the new I/Os |
| 5967 | * Its not aborting any I/Os as context |
| 5968 | * is not destroyed during quiescence |
| 5969 | * Arguments: scsi_qla_host_t |
| 5970 | * return : void |
| 5971 | */ |
| 5972 | void |
Chad Dupuis | 8fcd6b8 | 2012-08-22 14:21:06 -0400 | [diff] [blame] | 5973 | qla2x00_quiesce_io(scsi_qla_host_t *vha) |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 5974 | { |
| 5975 | struct qla_hw_data *ha = vha->hw; |
| 5976 | struct scsi_qla_host *vp; |
| 5977 | |
Chad Dupuis | 8fcd6b8 | 2012-08-22 14:21:06 -0400 | [diff] [blame] | 5978 | ql_dbg(ql_dbg_dpc, vha, 0x401d, |
| 5979 | "Quiescing I/O - ha=%p.\n", ha); |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 5980 | |
| 5981 | atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME); |
| 5982 | if (atomic_read(&vha->loop_state) != LOOP_DOWN) { |
| 5983 | atomic_set(&vha->loop_state, LOOP_DOWN); |
| 5984 | qla2x00_mark_all_devices_lost(vha, 0); |
| 5985 | list_for_each_entry(vp, &ha->vp_list, list) |
Chad Dupuis | 8fcd6b8 | 2012-08-22 14:21:06 -0400 | [diff] [blame] | 5986 | qla2x00_mark_all_devices_lost(vp, 0); |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 5987 | } else { |
| 5988 | if (!atomic_read(&vha->loop_down_timer)) |
| 5989 | atomic_set(&vha->loop_down_timer, |
| 5990 | LOOP_DOWN_TIME); |
| 5991 | } |
| 5992 | /* Wait for pending cmds to complete */ |
| 5993 | qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST); |
| 5994 | } |
| 5995 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5996 | void |
| 5997 | qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha) |
| 5998 | { |
| 5999 | struct qla_hw_data *ha = vha->hw; |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 6000 | struct scsi_qla_host *vp; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 6001 | unsigned long flags; |
Andrew Vasquez | 6aef87b | 2011-02-23 15:27:13 -0800 | [diff] [blame] | 6002 | fc_port_t *fcport; |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 6003 | u16 i; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 6004 | |
Saurav Kashyap | e46ef00 | 2011-02-23 15:27:16 -0800 | [diff] [blame] | 6005 | /* For ISP82XX, driver waits for completion of the commands. |
| 6006 | * online flag should be set. |
| 6007 | */ |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 6008 | if (!(IS_P3P_TYPE(ha))) |
Saurav Kashyap | e46ef00 | 2011-02-23 15:27:16 -0800 | [diff] [blame] | 6009 | vha->flags.online = 0; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 6010 | ha->flags.chip_reset_done = 0; |
| 6011 | clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
Saurav Kashyap | 2be21fa | 2012-05-15 14:34:16 -0400 | [diff] [blame] | 6012 | vha->qla_stats.total_isp_aborts++; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 6013 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6014 | ql_log(ql_log_info, vha, 0x00af, |
| 6015 | "Performing ISP error recovery - ha=%p.\n", ha); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 6016 | |
Saurav Kashyap | e46ef00 | 2011-02-23 15:27:16 -0800 | [diff] [blame] | 6017 | /* For ISP82XX, reset_chip is just disabling interrupts. |
| 6018 | * Driver waits for the completion of the commands. |
| 6019 | * the interrupts need to be enabled. |
| 6020 | */ |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 6021 | if (!(IS_P3P_TYPE(ha))) |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 6022 | ha->isp_ops->reset_chip(vha); |
| 6023 | |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 6024 | ha->flags.n2n_ae = 0; |
| 6025 | ha->flags.lip_ae = 0; |
| 6026 | ha->current_topology = 0; |
| 6027 | ha->flags.fw_started = 0; |
| 6028 | ha->flags.fw_init_done = 0; |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 6029 | ha->base_qpair->chip_reset++; |
| 6030 | for (i = 0; i < ha->max_qpairs; i++) { |
| 6031 | if (ha->queue_pair_map[i]) |
| 6032 | ha->queue_pair_map[i]->chip_reset = |
| 6033 | ha->base_qpair->chip_reset; |
| 6034 | } |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6035 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 6036 | atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME); |
| 6037 | if (atomic_read(&vha->loop_state) != LOOP_DOWN) { |
| 6038 | atomic_set(&vha->loop_state, LOOP_DOWN); |
| 6039 | qla2x00_mark_all_devices_lost(vha, 0); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 6040 | |
| 6041 | spin_lock_irqsave(&ha->vport_slock, flags); |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 6042 | list_for_each_entry(vp, &ha->vp_list, list) { |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 6043 | atomic_inc(&vp->vref_count); |
| 6044 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 6045 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 6046 | qla2x00_mark_all_devices_lost(vp, 0); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 6047 | |
| 6048 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 6049 | atomic_dec(&vp->vref_count); |
| 6050 | } |
| 6051 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 6052 | } else { |
| 6053 | if (!atomic_read(&vha->loop_down_timer)) |
| 6054 | atomic_set(&vha->loop_down_timer, |
| 6055 | LOOP_DOWN_TIME); |
| 6056 | } |
| 6057 | |
Andrew Vasquez | 6aef87b | 2011-02-23 15:27:13 -0800 | [diff] [blame] | 6058 | /* Clear all async request states across all VPs. */ |
| 6059 | list_for_each_entry(fcport, &vha->vp_fcports, list) |
| 6060 | fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT); |
| 6061 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 6062 | list_for_each_entry(vp, &ha->vp_list, list) { |
| 6063 | atomic_inc(&vp->vref_count); |
| 6064 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 6065 | |
| 6066 | list_for_each_entry(fcport, &vp->vp_fcports, list) |
| 6067 | fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT); |
| 6068 | |
| 6069 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 6070 | atomic_dec(&vp->vref_count); |
| 6071 | } |
| 6072 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 6073 | |
Lalit Chandivade | bddd2d6 | 2010-09-03 15:20:53 -0700 | [diff] [blame] | 6074 | if (!ha->flags.eeh_busy) { |
| 6075 | /* Make sure for ISP 82XX IO DMA is complete */ |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 6076 | if (IS_P3P_TYPE(ha)) { |
Giridhar Malavali | 7190575 | 2011-02-23 15:27:10 -0800 | [diff] [blame] | 6077 | qla82xx_chip_reset_cleanup(vha); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6078 | ql_log(ql_log_info, vha, 0x00b4, |
| 6079 | "Done chip reset cleanup.\n"); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 6080 | |
Saurav Kashyap | e46ef00 | 2011-02-23 15:27:16 -0800 | [diff] [blame] | 6081 | /* Done waiting for pending commands. |
| 6082 | * Reset the online flag. |
| 6083 | */ |
| 6084 | vha->flags.online = 0; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 6085 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6086 | |
Lalit Chandivade | bddd2d6 | 2010-09-03 15:20:53 -0700 | [diff] [blame] | 6087 | /* Requeue all commands in outstanding command list. */ |
| 6088 | qla2x00_abort_all_cmds(vha, DID_RESET << 16); |
| 6089 | } |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 6090 | /* memory barrier */ |
| 6091 | wmb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6092 | } |
| 6093 | |
| 6094 | /* |
| 6095 | * qla2x00_abort_isp |
| 6096 | * Resets ISP and aborts all outstanding commands. |
| 6097 | * |
| 6098 | * Input: |
| 6099 | * ha = adapter block pointer. |
| 6100 | * |
| 6101 | * Returns: |
| 6102 | * 0 = success |
| 6103 | */ |
| 6104 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6105 | qla2x00_abort_isp(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6106 | { |
Andrew Vasquez | 476e897 | 2006-08-23 14:54:55 -0700 | [diff] [blame] | 6107 | int rval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6108 | uint8_t status = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6109 | struct qla_hw_data *ha = vha->hw; |
| 6110 | struct scsi_qla_host *vp; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6111 | struct req_que *req = ha->req_q_map[0]; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 6112 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6113 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6114 | if (vha->flags.online) { |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 6115 | qla2x00_abort_isp_cleanup(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6116 | |
Santosh Vernekar | a6171297 | 2012-08-22 14:21:13 -0400 | [diff] [blame] | 6117 | if (IS_QLA8031(ha)) { |
| 6118 | ql_dbg(ql_dbg_p3p, vha, 0xb05c, |
| 6119 | "Clearing fcoe driver presence.\n"); |
| 6120 | if (qla83xx_clear_drv_presence(vha) != QLA_SUCCESS) |
| 6121 | ql_dbg(ql_dbg_p3p, vha, 0xb073, |
| 6122 | "Error while clearing DRV-Presence.\n"); |
| 6123 | } |
| 6124 | |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 6125 | if (unlikely(pci_channel_offline(ha->pdev) && |
| 6126 | ha->flags.pci_channel_io_perm_failure)) { |
| 6127 | clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags); |
| 6128 | status = 0; |
| 6129 | return status; |
| 6130 | } |
| 6131 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6132 | ha->isp_ops->get_flash_version(vha, req->ring); |
Andrew Vasquez | 30c4766 | 2007-01-29 10:22:21 -0800 | [diff] [blame] | 6133 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6134 | ha->isp_ops->nvram_config(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6135 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6136 | if (!qla2x00_restart_isp(vha)) { |
| 6137 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6138 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6139 | if (!atomic_read(&vha->loop_down_timer)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6140 | /* |
| 6141 | * Issue marker command only when we are going |
| 6142 | * to start the I/O . |
| 6143 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6144 | vha->marker_needed = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6145 | } |
| 6146 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6147 | vha->flags.online = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6148 | |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 6149 | ha->isp_ops->enable_intrs(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6150 | |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 6151 | ha->isp_abort_cnt = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6152 | clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags); |
Andrew Vasquez | 476e897 | 2006-08-23 14:54:55 -0700 | [diff] [blame] | 6153 | |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 6154 | if (IS_QLA81XX(ha) || IS_QLA8031(ha)) |
| 6155 | qla2x00_get_fw_version(vha); |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 6156 | if (ha->fce) { |
| 6157 | ha->flags.fce_enabled = 1; |
| 6158 | memset(ha->fce, 0, |
| 6159 | fce_calc_size(ha->fce_bufs)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6160 | rval = qla2x00_enable_fce_trace(vha, |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 6161 | ha->fce_dma, ha->fce_bufs, ha->fce_mb, |
| 6162 | &ha->fce_bufs); |
| 6163 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6164 | ql_log(ql_log_warn, vha, 0x8033, |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 6165 | "Unable to reinitialize FCE " |
| 6166 | "(%d).\n", rval); |
| 6167 | ha->flags.fce_enabled = 0; |
| 6168 | } |
| 6169 | } |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 6170 | |
| 6171 | if (ha->eft) { |
| 6172 | memset(ha->eft, 0, EFT_SIZE); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6173 | rval = qla2x00_enable_eft_trace(vha, |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 6174 | ha->eft_dma, EFT_NUM_BUFFERS); |
| 6175 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6176 | ql_log(ql_log_warn, vha, 0x8034, |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 6177 | "Unable to reinitialize EFT " |
| 6178 | "(%d).\n", rval); |
| 6179 | } |
| 6180 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6181 | } else { /* failed the ISP abort */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6182 | vha->flags.online = 1; |
| 6183 | if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6184 | if (ha->isp_abort_cnt == 0) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6185 | ql_log(ql_log_fatal, vha, 0x8035, |
| 6186 | "ISP error recover failed - " |
| 6187 | "board disabled.\n"); |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 6188 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6189 | * The next call disables the board |
| 6190 | * completely. |
| 6191 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6192 | ha->isp_ops->reset_adapter(vha); |
| 6193 | vha->flags.online = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6194 | clear_bit(ISP_ABORT_RETRY, |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6195 | &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6196 | status = 0; |
| 6197 | } else { /* schedule another ISP abort */ |
| 6198 | ha->isp_abort_cnt--; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6199 | ql_dbg(ql_dbg_taskm, vha, 0x8020, |
| 6200 | "ISP abort - retry remaining %d.\n", |
| 6201 | ha->isp_abort_cnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6202 | status = 1; |
| 6203 | } |
| 6204 | } else { |
| 6205 | ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6206 | ql_dbg(ql_dbg_taskm, vha, 0x8021, |
| 6207 | "ISP error recovery - retrying (%d) " |
| 6208 | "more times.\n", ha->isp_abort_cnt); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6209 | set_bit(ISP_ABORT_RETRY, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6210 | status = 1; |
| 6211 | } |
| 6212 | } |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 6213 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6214 | } |
| 6215 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6216 | if (!status) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6217 | ql_dbg(ql_dbg_taskm, vha, 0x8022, "%s succeeded.\n", __func__); |
Quinn Tran | 1608cc4 | 2017-08-23 15:05:03 -0700 | [diff] [blame] | 6218 | qla2x00_configure_hba(vha); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 6219 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 6220 | list_for_each_entry(vp, &ha->vp_list, list) { |
| 6221 | if (vp->vp_idx) { |
| 6222 | atomic_inc(&vp->vref_count); |
| 6223 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 6224 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6225 | qla2x00_vp_abort_isp(vp); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 6226 | |
| 6227 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 6228 | atomic_dec(&vp->vref_count); |
| 6229 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6230 | } |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 6231 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 6232 | |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 6233 | if (IS_QLA8031(ha)) { |
| 6234 | ql_dbg(ql_dbg_p3p, vha, 0xb05d, |
| 6235 | "Setting back fcoe driver presence.\n"); |
| 6236 | if (qla83xx_set_drv_presence(vha) != QLA_SUCCESS) |
| 6237 | ql_dbg(ql_dbg_p3p, vha, 0xb074, |
| 6238 | "Error while setting DRV-Presence.\n"); |
| 6239 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6240 | } else { |
Joe Perches | d8424f6 | 2011-11-18 09:03:06 -0800 | [diff] [blame] | 6241 | ql_log(ql_log_warn, vha, 0x8023, "%s **** FAILED ****.\n", |
| 6242 | __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6243 | } |
| 6244 | |
| 6245 | return(status); |
| 6246 | } |
| 6247 | |
| 6248 | /* |
| 6249 | * qla2x00_restart_isp |
| 6250 | * restarts the ISP after a reset |
| 6251 | * |
| 6252 | * Input: |
| 6253 | * ha = adapter block pointer. |
| 6254 | * |
| 6255 | * Returns: |
| 6256 | * 0 = success |
| 6257 | */ |
| 6258 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6259 | qla2x00_restart_isp(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6260 | { |
Andrew Vasquez | c6b2fca | 2009-03-05 11:07:03 -0800 | [diff] [blame] | 6261 | int status = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6262 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6263 | struct req_que *req = ha->req_q_map[0]; |
| 6264 | struct rsp_que *rsp = ha->rsp_q_map[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6265 | |
| 6266 | /* If firmware needs to be loaded */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6267 | if (qla2x00_isp_firmware(vha)) { |
| 6268 | vha->flags.online = 0; |
| 6269 | status = ha->isp_ops->chip_diag(vha); |
| 6270 | if (!status) |
| 6271 | status = qla2x00_setup_chip(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6272 | } |
| 6273 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6274 | if (!status && !(status = qla2x00_init_rings(vha))) { |
| 6275 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); |
Lalit Chandivade | 2533cf6 | 2009-03-24 09:08:07 -0700 | [diff] [blame] | 6276 | ha->flags.chip_reset_done = 1; |
Chad Dupuis | 7108b76 | 2014-04-11 16:54:45 -0400 | [diff] [blame] | 6277 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6278 | /* Initialize the queues in use */ |
| 6279 | qla25xx_init_queues(ha); |
| 6280 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6281 | status = qla2x00_fw_ready(vha); |
| 6282 | if (!status) { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6283 | /* Issue a marker after FW becomes ready. */ |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6284 | qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL); |
Chad Dupuis | 7108b76 | 2014-04-11 16:54:45 -0400 | [diff] [blame] | 6285 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6286 | } |
| 6287 | |
| 6288 | /* if no cable then assume it's good */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6289 | if ((vha->device_flags & DFLG_NO_CABLE)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6290 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6291 | } |
| 6292 | return (status); |
| 6293 | } |
| 6294 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6295 | static int |
| 6296 | qla25xx_init_queues(struct qla_hw_data *ha) |
| 6297 | { |
| 6298 | struct rsp_que *rsp = NULL; |
| 6299 | struct req_que *req = NULL; |
| 6300 | struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev); |
| 6301 | int ret = -1; |
| 6302 | int i; |
| 6303 | |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 6304 | for (i = 1; i < ha->max_rsp_queues; i++) { |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6305 | rsp = ha->rsp_q_map[i]; |
Quinn Tran | cb43285 | 2016-02-04 11:45:16 -0500 | [diff] [blame] | 6306 | if (rsp && test_bit(i, ha->rsp_qid_map)) { |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6307 | rsp->options &= ~BIT_0; |
Anirban Chakraborty | 618a752 | 2009-02-08 20:50:11 -0800 | [diff] [blame] | 6308 | ret = qla25xx_init_rsp_que(base_vha, rsp); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6309 | if (ret != QLA_SUCCESS) |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6310 | ql_dbg(ql_dbg_init, base_vha, 0x00ff, |
| 6311 | "%s Rsp que: %d init failed.\n", |
| 6312 | __func__, rsp->id); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6313 | else |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6314 | ql_dbg(ql_dbg_init, base_vha, 0x0100, |
| 6315 | "%s Rsp que: %d inited.\n", |
| 6316 | __func__, rsp->id); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6317 | } |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 6318 | } |
| 6319 | for (i = 1; i < ha->max_req_queues; i++) { |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6320 | req = ha->req_q_map[i]; |
Quinn Tran | cb43285 | 2016-02-04 11:45:16 -0500 | [diff] [blame] | 6321 | if (req && test_bit(i, ha->req_qid_map)) { |
| 6322 | /* Clear outstanding commands array. */ |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6323 | req->options &= ~BIT_0; |
Anirban Chakraborty | 618a752 | 2009-02-08 20:50:11 -0800 | [diff] [blame] | 6324 | ret = qla25xx_init_req_que(base_vha, req); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6325 | if (ret != QLA_SUCCESS) |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6326 | ql_dbg(ql_dbg_init, base_vha, 0x0101, |
| 6327 | "%s Req que: %d init failed.\n", |
| 6328 | __func__, req->id); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6329 | else |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6330 | ql_dbg(ql_dbg_init, base_vha, 0x0102, |
| 6331 | "%s Req que: %d inited.\n", |
| 6332 | __func__, req->id); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6333 | } |
| 6334 | } |
| 6335 | return ret; |
| 6336 | } |
| 6337 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6338 | /* |
| 6339 | * qla2x00_reset_adapter |
| 6340 | * Reset adapter. |
| 6341 | * |
| 6342 | * Input: |
| 6343 | * ha = adapter block pointer. |
| 6344 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 6345 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6346 | qla2x00_reset_adapter(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6347 | { |
| 6348 | unsigned long flags = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6349 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 6350 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6351 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6352 | vha->flags.online = 0; |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 6353 | ha->isp_ops->disable_intrs(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6354 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6355 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 6356 | WRT_REG_WORD(®->hccr, HCCR_RESET_RISC); |
| 6357 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 6358 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
| 6359 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 6360 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 6361 | } |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6362 | |
| 6363 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6364 | qla24xx_reset_adapter(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6365 | { |
| 6366 | unsigned long flags = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6367 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6368 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; |
| 6369 | |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 6370 | if (IS_P3P_TYPE(ha)) |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 6371 | return; |
| 6372 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6373 | vha->flags.online = 0; |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 6374 | ha->isp_ops->disable_intrs(ha); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6375 | |
| 6376 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 6377 | WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET); |
| 6378 | RD_REG_DWORD(®->hccr); |
| 6379 | WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE); |
| 6380 | RD_REG_DWORD(®->hccr); |
| 6381 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Andrew Vasquez | 09ff36d | 2009-01-22 09:45:30 -0800 | [diff] [blame] | 6382 | |
| 6383 | if (IS_NOPOLLING_TYPE(ha)) |
| 6384 | ha->isp_ops->enable_intrs(ha); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6385 | } |
| 6386 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 6387 | /* On sparc systems, obtain port and node WWN from firmware |
| 6388 | * properties. |
| 6389 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6390 | static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, |
| 6391 | struct nvram_24xx *nv) |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 6392 | { |
| 6393 | #ifdef CONFIG_SPARC |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6394 | struct qla_hw_data *ha = vha->hw; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 6395 | struct pci_dev *pdev = ha->pdev; |
David S. Miller | 15576bc | 2007-05-08 00:36:49 -0700 | [diff] [blame] | 6396 | struct device_node *dp = pci_device_to_OF_node(pdev); |
| 6397 | const u8 *val; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 6398 | int len; |
| 6399 | |
| 6400 | val = of_get_property(dp, "port-wwn", &len); |
| 6401 | if (val && len >= WWN_SIZE) |
| 6402 | memcpy(nv->port_name, val, WWN_SIZE); |
| 6403 | |
| 6404 | val = of_get_property(dp, "node-wwn", &len); |
| 6405 | if (val && len >= WWN_SIZE) |
| 6406 | memcpy(nv->node_name, val, WWN_SIZE); |
| 6407 | #endif |
| 6408 | } |
| 6409 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6410 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6411 | qla24xx_nvram_config(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6412 | { |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 6413 | int rval; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6414 | struct init_cb_24xx *icb; |
| 6415 | struct nvram_24xx *nv; |
| 6416 | uint32_t *dptr; |
| 6417 | uint8_t *dptr1, *dptr2; |
| 6418 | uint32_t chksum; |
| 6419 | uint16_t cnt; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6420 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6421 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 6422 | rval = QLA_SUCCESS; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6423 | icb = (struct init_cb_24xx *)ha->init_cb; |
Seokmann Ju | 281afe1 | 2007-07-26 13:43:34 -0700 | [diff] [blame] | 6424 | nv = ha->nvram; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6425 | |
| 6426 | /* Determine NVRAM starting address. */ |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 6427 | if (ha->port_no == 0) { |
Anirban Chakraborty | e5b68a6 | 2009-04-06 22:33:50 -0700 | [diff] [blame] | 6428 | ha->nvram_base = FA_NVRAM_FUNC0_ADDR; |
| 6429 | ha->vpd_base = FA_NVRAM_VPD0_ADDR; |
| 6430 | } else { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6431 | ha->nvram_base = FA_NVRAM_FUNC1_ADDR; |
andrew.vasquez@qlogic.com | 6f64179 | 2006-03-09 14:27:34 -0800 | [diff] [blame] | 6432 | ha->vpd_base = FA_NVRAM_VPD1_ADDR; |
| 6433 | } |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 6434 | |
Anirban Chakraborty | e5b68a6 | 2009-04-06 22:33:50 -0700 | [diff] [blame] | 6435 | ha->nvram_size = sizeof(struct nvram_24xx); |
| 6436 | ha->vpd_size = FA_NVRAM_VPD_SIZE; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6437 | |
Seokmann Ju | 281afe1 | 2007-07-26 13:43:34 -0700 | [diff] [blame] | 6438 | /* Get VPD data into cache */ |
| 6439 | ha->vpd = ha->nvram + VPD_OFFSET; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6440 | ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd, |
Seokmann Ju | 281afe1 | 2007-07-26 13:43:34 -0700 | [diff] [blame] | 6441 | ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4); |
| 6442 | |
| 6443 | /* Get NVRAM data into cache and calculate checksum. */ |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6444 | dptr = (uint32_t *)nv; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6445 | ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base, |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6446 | ha->nvram_size); |
Joe Carnuccio | da08ef5 | 2016-01-27 12:03:34 -0500 | [diff] [blame] | 6447 | for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++) |
| 6448 | chksum += le32_to_cpu(*dptr); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6449 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6450 | ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x006a, |
| 6451 | "Contents of NVRAM\n"); |
| 6452 | ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x010d, |
| 6453 | (uint8_t *)nv, ha->nvram_size); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6454 | |
| 6455 | /* Bad NVRAM data, set defaults parameters. */ |
| 6456 | if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P' |
| 6457 | || nv->id[3] != ' ' || |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6458 | nv->nvram_version < cpu_to_le16(ICB_VERSION)) { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6459 | /* Reset NVRAM data. */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6460 | ql_log(ql_log_warn, vha, 0x006b, |
Raul Porcel | 9e33652 | 2012-05-15 14:34:08 -0400 | [diff] [blame] | 6461 | "Inconsistent NVRAM detected: checksum=0x%x id=%c " |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6462 | "version=0x%x.\n", chksum, nv->id[0], nv->nvram_version); |
| 6463 | ql_log(ql_log_warn, vha, 0x006c, |
| 6464 | "Falling back to functioning (yet invalid -- WWPN) " |
| 6465 | "defaults.\n"); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 6466 | |
| 6467 | /* |
| 6468 | * Set default initialization control block. |
| 6469 | */ |
| 6470 | memset(nv, 0, ha->nvram_size); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6471 | nv->nvram_version = cpu_to_le16(ICB_VERSION); |
| 6472 | nv->version = cpu_to_le16(ICB_VERSION); |
Joe Carnuccio | 98aee70 | 2014-09-25 05:16:38 -0400 | [diff] [blame] | 6473 | nv->frame_payload_size = 2048; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6474 | nv->execution_throttle = cpu_to_le16(0xFFFF); |
| 6475 | nv->exchange_count = cpu_to_le16(0); |
| 6476 | nv->hard_address = cpu_to_le16(124); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 6477 | nv->port_name[0] = 0x21; |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 6478 | nv->port_name[1] = 0x00 + ha->port_no + 1; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 6479 | nv->port_name[2] = 0x00; |
| 6480 | nv->port_name[3] = 0xe0; |
| 6481 | nv->port_name[4] = 0x8b; |
| 6482 | nv->port_name[5] = 0x1c; |
| 6483 | nv->port_name[6] = 0x55; |
| 6484 | nv->port_name[7] = 0x86; |
| 6485 | nv->node_name[0] = 0x20; |
| 6486 | nv->node_name[1] = 0x00; |
| 6487 | nv->node_name[2] = 0x00; |
| 6488 | nv->node_name[3] = 0xe0; |
| 6489 | nv->node_name[4] = 0x8b; |
| 6490 | nv->node_name[5] = 0x1c; |
| 6491 | nv->node_name[6] = 0x55; |
| 6492 | nv->node_name[7] = 0x86; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6493 | qla24xx_nvram_wwn_from_ofw(vha, nv); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6494 | nv->login_retry_count = cpu_to_le16(8); |
| 6495 | nv->interrupt_delay_timer = cpu_to_le16(0); |
| 6496 | nv->login_timeout = cpu_to_le16(0); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 6497 | nv->firmware_options_1 = |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6498 | cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1); |
| 6499 | nv->firmware_options_2 = cpu_to_le32(2 << 4); |
| 6500 | nv->firmware_options_2 |= cpu_to_le32(BIT_12); |
| 6501 | nv->firmware_options_3 = cpu_to_le32(2 << 13); |
| 6502 | nv->host_p = cpu_to_le32(BIT_11|BIT_10); |
| 6503 | nv->efi_parameters = cpu_to_le32(0); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 6504 | nv->reset_delay = 5; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6505 | nv->max_luns_per_target = cpu_to_le16(128); |
| 6506 | nv->port_down_retry_count = cpu_to_le16(30); |
| 6507 | nv->link_down_timeout = cpu_to_le16(30); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 6508 | |
| 6509 | rval = 1; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6510 | } |
| 6511 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6512 | if (qla_tgt_mode_enabled(vha)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6513 | /* Don't enable full login after initial LIP */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6514 | nv->firmware_options_1 &= cpu_to_le32(~BIT_13); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6515 | /* Don't enable LIP full login for initiator */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6516 | nv->host_p &= cpu_to_le32(~BIT_10); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6517 | } |
| 6518 | |
| 6519 | qlt_24xx_config_nvram_stage1(vha, nv); |
| 6520 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6521 | /* Reset Initialization control block */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6522 | memset(icb, 0, ha->init_cb_size); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6523 | |
| 6524 | /* Copy 1st segment. */ |
| 6525 | dptr1 = (uint8_t *)icb; |
| 6526 | dptr2 = (uint8_t *)&nv->version; |
| 6527 | cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version; |
| 6528 | while (cnt--) |
| 6529 | *dptr1++ = *dptr2++; |
| 6530 | |
| 6531 | icb->login_retry_count = nv->login_retry_count; |
Andrew Vasquez | 3ea66e2 | 2006-06-23 16:11:27 -0700 | [diff] [blame] | 6532 | icb->link_down_on_nos = nv->link_down_on_nos; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6533 | |
| 6534 | /* Copy 2nd segment. */ |
| 6535 | dptr1 = (uint8_t *)&icb->interrupt_delay_timer; |
| 6536 | dptr2 = (uint8_t *)&nv->interrupt_delay_timer; |
| 6537 | cnt = (uint8_t *)&icb->reserved_3 - |
| 6538 | (uint8_t *)&icb->interrupt_delay_timer; |
| 6539 | while (cnt--) |
| 6540 | *dptr1++ = *dptr2++; |
| 6541 | |
| 6542 | /* |
| 6543 | * Setup driver NVRAM options. |
| 6544 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6545 | qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name), |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 6546 | "QLA2462"); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6547 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6548 | qlt_24xx_config_nvram_stage2(vha, icb); |
| 6549 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6550 | if (nv->host_p & cpu_to_le32(BIT_15)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6551 | /* Use alternate WWN? */ |
Andrew Vasquez | 5341e86 | 2006-05-17 15:09:16 -0700 | [diff] [blame] | 6552 | memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE); |
| 6553 | memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE); |
| 6554 | } |
| 6555 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6556 | /* Prepare nodename */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6557 | if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6558 | /* |
| 6559 | * Firmware will apply the following mask if the nodename was |
| 6560 | * not provided. |
| 6561 | */ |
| 6562 | memcpy(icb->node_name, icb->port_name, WWN_SIZE); |
| 6563 | icb->node_name[0] &= 0xF0; |
| 6564 | } |
| 6565 | |
| 6566 | /* Set host adapter parameters. */ |
| 6567 | ha->flags.disable_risc_code_load = 0; |
Andrew Vasquez | 0c8c39a | 2006-12-13 19:20:30 -0800 | [diff] [blame] | 6568 | ha->flags.enable_lip_reset = 0; |
| 6569 | ha->flags.enable_lip_full_login = |
| 6570 | le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0; |
| 6571 | ha->flags.enable_target_reset = |
| 6572 | le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6573 | ha->flags.enable_led_scheme = 0; |
Andrew Vasquez | d4c760c | 2006-06-23 16:10:39 -0700 | [diff] [blame] | 6574 | 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] | 6575 | |
Andrew Vasquez | fd0e7e4 | 2006-05-17 15:09:11 -0700 | [diff] [blame] | 6576 | ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) & |
| 6577 | (BIT_6 | BIT_5 | BIT_4)) >> 4; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6578 | |
| 6579 | memcpy(ha->fw_seriallink_options24, nv->seriallink_options, |
| 6580 | sizeof(ha->fw_seriallink_options24)); |
| 6581 | |
| 6582 | /* save HBA serial number */ |
| 6583 | ha->serial0 = icb->port_name[5]; |
| 6584 | ha->serial1 = icb->port_name[6]; |
| 6585 | ha->serial2 = icb->port_name[7]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6586 | memcpy(vha->node_name, icb->node_name, WWN_SIZE); |
| 6587 | memcpy(vha->port_name, icb->port_name, WWN_SIZE); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6588 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6589 | icb->execution_throttle = cpu_to_le16(0xFFFF); |
andrew.vasquez@qlogic.com | bc8fb3c | 2006-01-13 17:05:42 -0800 | [diff] [blame] | 6590 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6591 | ha->retry_count = le16_to_cpu(nv->login_retry_count); |
| 6592 | |
| 6593 | /* Set minimum login_timeout to 4 seconds. */ |
| 6594 | if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout) |
| 6595 | nv->login_timeout = cpu_to_le16(ql2xlogintimeout); |
| 6596 | if (le16_to_cpu(nv->login_timeout) < 4) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6597 | nv->login_timeout = cpu_to_le16(4); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6598 | ha->login_timeout = le16_to_cpu(nv->login_timeout); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6599 | |
Andrew Vasquez | 00a537b | 2008-02-28 14:06:11 -0800 | [diff] [blame] | 6600 | /* Set minimum RATOV to 100 tenths of a second. */ |
| 6601 | ha->r_a_tov = 100; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6602 | |
| 6603 | ha->loop_reset_delay = nv->reset_delay; |
| 6604 | |
| 6605 | /* Link Down Timeout = 0: |
| 6606 | * |
| 6607 | * When Port Down timer expires we will start returning |
| 6608 | * I/O's to OS with "DID_NO_CONNECT". |
| 6609 | * |
| 6610 | * Link Down Timeout != 0: |
| 6611 | * |
| 6612 | * The driver waits for the link to come up after link down |
| 6613 | * before returning I/Os to OS with "DID_NO_CONNECT". |
| 6614 | */ |
| 6615 | if (le16_to_cpu(nv->link_down_timeout) == 0) { |
| 6616 | ha->loop_down_abort_time = |
| 6617 | (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT); |
| 6618 | } else { |
| 6619 | ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout); |
| 6620 | ha->loop_down_abort_time = |
| 6621 | (LOOP_DOWN_TIME - ha->link_down_timeout); |
| 6622 | } |
| 6623 | |
| 6624 | /* Need enough time to try and get the port back. */ |
| 6625 | ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count); |
| 6626 | if (qlport_down_retry) |
| 6627 | ha->port_down_retry_count = qlport_down_retry; |
| 6628 | |
| 6629 | /* Set login_retry_count */ |
| 6630 | ha->login_retry_count = le16_to_cpu(nv->login_retry_count); |
| 6631 | if (ha->port_down_retry_count == |
| 6632 | le16_to_cpu(nv->port_down_retry_count) && |
| 6633 | ha->port_down_retry_count > 3) |
| 6634 | ha->login_retry_count = ha->port_down_retry_count; |
| 6635 | else if (ha->port_down_retry_count > (int)ha->login_retry_count) |
| 6636 | ha->login_retry_count = ha->port_down_retry_count; |
| 6637 | if (ql2xloginretrycount) |
| 6638 | ha->login_retry_count = ql2xloginretrycount; |
| 6639 | |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 6640 | /* Enable ZIO. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6641 | if (!vha->flags.init_done) { |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 6642 | ha->zio_mode = le32_to_cpu(icb->firmware_options_2) & |
| 6643 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
| 6644 | ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ? |
| 6645 | le16_to_cpu(icb->interrupt_delay_timer): 2; |
| 6646 | } |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6647 | icb->firmware_options_2 &= cpu_to_le32( |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 6648 | ~(BIT_3 | BIT_2 | BIT_1 | BIT_0)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6649 | vha->flags.process_response_queue = 0; |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 6650 | if (ha->zio_mode != QLA_ZIO_DISABLED) { |
andrew.vasquez@qlogic.com | 4a59f71 | 2006-03-09 14:27:39 -0800 | [diff] [blame] | 6651 | ha->zio_mode = QLA_ZIO_MODE_6; |
| 6652 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6653 | ql_log(ql_log_info, vha, 0x006f, |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 6654 | "ZIO mode %d enabled; timer delay (%d us).\n", |
| 6655 | ha->zio_mode, ha->zio_timer * 100); |
| 6656 | |
| 6657 | icb->firmware_options_2 |= cpu_to_le32( |
| 6658 | (uint32_t)ha->zio_mode); |
| 6659 | icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6660 | vha->flags.process_response_queue = 1; |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 6661 | } |
| 6662 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 6663 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6664 | ql_log(ql_log_warn, vha, 0x0070, |
| 6665 | "NVRAM configuration failed.\n"); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 6666 | } |
| 6667 | return (rval); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6668 | } |
| 6669 | |
Sawan Chandak | 4243c11 | 2016-01-27 12:03:31 -0500 | [diff] [blame] | 6670 | uint8_t qla27xx_find_valid_image(struct scsi_qla_host *vha) |
| 6671 | { |
| 6672 | struct qla27xx_image_status pri_image_status, sec_image_status; |
| 6673 | uint8_t valid_pri_image, valid_sec_image; |
| 6674 | uint32_t *wptr; |
| 6675 | uint32_t cnt, chksum, size; |
| 6676 | struct qla_hw_data *ha = vha->hw; |
| 6677 | |
| 6678 | valid_pri_image = valid_sec_image = 1; |
| 6679 | ha->active_image = 0; |
| 6680 | size = sizeof(struct qla27xx_image_status) / sizeof(uint32_t); |
| 6681 | |
| 6682 | if (!ha->flt_region_img_status_pri) { |
| 6683 | valid_pri_image = 0; |
| 6684 | goto check_sec_image; |
| 6685 | } |
| 6686 | |
| 6687 | qla24xx_read_flash_data(vha, (uint32_t *)(&pri_image_status), |
| 6688 | ha->flt_region_img_status_pri, size); |
| 6689 | |
| 6690 | if (pri_image_status.signature != QLA27XX_IMG_STATUS_SIGN) { |
| 6691 | ql_dbg(ql_dbg_init, vha, 0x018b, |
| 6692 | "Primary image signature (0x%x) not valid\n", |
| 6693 | pri_image_status.signature); |
| 6694 | valid_pri_image = 0; |
| 6695 | goto check_sec_image; |
| 6696 | } |
| 6697 | |
| 6698 | wptr = (uint32_t *)(&pri_image_status); |
| 6699 | cnt = size; |
| 6700 | |
Joe Carnuccio | da08ef5 | 2016-01-27 12:03:34 -0500 | [diff] [blame] | 6701 | for (chksum = 0; cnt--; wptr++) |
| 6702 | chksum += le32_to_cpu(*wptr); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 6703 | |
Sawan Chandak | 4243c11 | 2016-01-27 12:03:31 -0500 | [diff] [blame] | 6704 | if (chksum) { |
| 6705 | ql_dbg(ql_dbg_init, vha, 0x018c, |
| 6706 | "Checksum validation failed for primary image (0x%x)\n", |
| 6707 | chksum); |
| 6708 | valid_pri_image = 0; |
| 6709 | } |
| 6710 | |
| 6711 | check_sec_image: |
| 6712 | if (!ha->flt_region_img_status_sec) { |
| 6713 | valid_sec_image = 0; |
| 6714 | goto check_valid_image; |
| 6715 | } |
| 6716 | |
| 6717 | qla24xx_read_flash_data(vha, (uint32_t *)(&sec_image_status), |
| 6718 | ha->flt_region_img_status_sec, size); |
| 6719 | |
| 6720 | if (sec_image_status.signature != QLA27XX_IMG_STATUS_SIGN) { |
| 6721 | ql_dbg(ql_dbg_init, vha, 0x018d, |
| 6722 | "Secondary image signature(0x%x) not valid\n", |
| 6723 | sec_image_status.signature); |
| 6724 | valid_sec_image = 0; |
| 6725 | goto check_valid_image; |
| 6726 | } |
| 6727 | |
| 6728 | wptr = (uint32_t *)(&sec_image_status); |
| 6729 | cnt = size; |
Joe Carnuccio | da08ef5 | 2016-01-27 12:03:34 -0500 | [diff] [blame] | 6730 | for (chksum = 0; cnt--; wptr++) |
| 6731 | chksum += le32_to_cpu(*wptr); |
Sawan Chandak | 4243c11 | 2016-01-27 12:03:31 -0500 | [diff] [blame] | 6732 | if (chksum) { |
| 6733 | ql_dbg(ql_dbg_init, vha, 0x018e, |
| 6734 | "Checksum validation failed for secondary image (0x%x)\n", |
| 6735 | chksum); |
| 6736 | valid_sec_image = 0; |
| 6737 | } |
| 6738 | |
| 6739 | check_valid_image: |
| 6740 | if (valid_pri_image && (pri_image_status.image_status_mask & 0x1)) |
| 6741 | ha->active_image = QLA27XX_PRIMARY_IMAGE; |
| 6742 | if (valid_sec_image && (sec_image_status.image_status_mask & 0x1)) { |
| 6743 | if (!ha->active_image || |
| 6744 | pri_image_status.generation_number < |
| 6745 | sec_image_status.generation_number) |
| 6746 | ha->active_image = QLA27XX_SECONDARY_IMAGE; |
| 6747 | } |
| 6748 | |
| 6749 | ql_dbg(ql_dbg_init, vha, 0x018f, "%s image\n", |
| 6750 | ha->active_image == 0 ? "default bootld and fw" : |
| 6751 | ha->active_image == 1 ? "primary" : |
| 6752 | ha->active_image == 2 ? "secondary" : |
| 6753 | "Invalid"); |
| 6754 | |
| 6755 | return ha->active_image; |
| 6756 | } |
| 6757 | |
Adrian Bunk | 413975a | 2006-06-30 02:33:06 -0700 | [diff] [blame] | 6758 | static int |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 6759 | qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr, |
| 6760 | uint32_t faddr) |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 6761 | { |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6762 | int rval = QLA_SUCCESS; |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 6763 | int segments, fragment; |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 6764 | uint32_t *dcode, dlen; |
| 6765 | uint32_t risc_addr; |
| 6766 | uint32_t risc_size; |
| 6767 | uint32_t i; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6768 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6769 | struct req_que *req = ha->req_q_map[0]; |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 6770 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6771 | ql_dbg(ql_dbg_init, vha, 0x008b, |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 6772 | "FW: Loading firmware from flash (%x).\n", faddr); |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 6773 | |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 6774 | rval = QLA_SUCCESS; |
| 6775 | |
| 6776 | segments = FA_RISC_CODE_SEGMENTS; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6777 | dcode = (uint32_t *)req->ring; |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 6778 | *srisc_addr = 0; |
| 6779 | |
Sawan Chandak | 4243c11 | 2016-01-27 12:03:31 -0500 | [diff] [blame] | 6780 | if (IS_QLA27XX(ha) && |
| 6781 | qla27xx_find_valid_image(vha) == QLA27XX_SECONDARY_IMAGE) |
| 6782 | faddr = ha->flt_region_fw_sec; |
| 6783 | |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 6784 | /* Validate firmware image by checking version. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6785 | qla24xx_read_flash_data(vha, dcode, faddr + 4, 4); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 6786 | for (i = 0; i < 4; i++) |
| 6787 | dcode[i] = be32_to_cpu(dcode[i]); |
| 6788 | if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff && |
| 6789 | dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) || |
| 6790 | (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 && |
| 6791 | dcode[3] == 0)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6792 | ql_log(ql_log_fatal, vha, 0x008c, |
| 6793 | "Unable to verify the integrity of flash firmware " |
| 6794 | "image.\n"); |
| 6795 | ql_log(ql_log_fatal, vha, 0x008d, |
| 6796 | "Firmware data: %08x %08x %08x %08x.\n", |
| 6797 | dcode[0], dcode[1], dcode[2], dcode[3]); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 6798 | |
| 6799 | return QLA_FUNCTION_FAILED; |
| 6800 | } |
| 6801 | |
| 6802 | while (segments && rval == QLA_SUCCESS) { |
| 6803 | /* Read segment's load information. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6804 | qla24xx_read_flash_data(vha, dcode, faddr, 4); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 6805 | |
| 6806 | risc_addr = be32_to_cpu(dcode[2]); |
| 6807 | *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr; |
| 6808 | risc_size = be32_to_cpu(dcode[3]); |
| 6809 | |
| 6810 | fragment = 0; |
| 6811 | while (risc_size > 0 && rval == QLA_SUCCESS) { |
| 6812 | dlen = (uint32_t)(ha->fw_transfer_size >> 2); |
| 6813 | if (dlen > risc_size) |
| 6814 | dlen = risc_size; |
| 6815 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6816 | ql_dbg(ql_dbg_init, vha, 0x008e, |
| 6817 | "Loading risc segment@ risc addr %x " |
| 6818 | "number of dwords 0x%x offset 0x%x.\n", |
| 6819 | risc_addr, dlen, faddr); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 6820 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6821 | qla24xx_read_flash_data(vha, dcode, faddr, dlen); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 6822 | for (i = 0; i < dlen; i++) |
| 6823 | dcode[i] = swab32(dcode[i]); |
| 6824 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6825 | rval = qla2x00_load_ram(vha, req->dma, risc_addr, |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 6826 | dlen); |
| 6827 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6828 | ql_log(ql_log_fatal, vha, 0x008f, |
| 6829 | "Failed to load segment %d of firmware.\n", |
| 6830 | fragment); |
Chad Dupuis | f261f7a | 2014-09-25 05:17:03 -0400 | [diff] [blame] | 6831 | return QLA_FUNCTION_FAILED; |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 6832 | } |
| 6833 | |
| 6834 | faddr += dlen; |
| 6835 | risc_addr += dlen; |
| 6836 | risc_size -= dlen; |
| 6837 | fragment++; |
| 6838 | } |
| 6839 | |
| 6840 | /* Next segment. */ |
| 6841 | segments--; |
| 6842 | } |
| 6843 | |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 6844 | if (!IS_QLA27XX(ha)) |
| 6845 | return rval; |
| 6846 | |
| 6847 | if (ha->fw_dump_template) |
| 6848 | vfree(ha->fw_dump_template); |
| 6849 | ha->fw_dump_template = NULL; |
| 6850 | ha->fw_dump_template_len = 0; |
| 6851 | |
| 6852 | ql_dbg(ql_dbg_init, vha, 0x0161, |
| 6853 | "Loading fwdump template from %x\n", faddr); |
| 6854 | qla24xx_read_flash_data(vha, dcode, faddr, 7); |
| 6855 | risc_size = be32_to_cpu(dcode[2]); |
| 6856 | ql_dbg(ql_dbg_init, vha, 0x0162, |
| 6857 | "-> array size %x dwords\n", risc_size); |
| 6858 | if (risc_size == 0 || risc_size == ~0) |
| 6859 | goto default_template; |
| 6860 | |
| 6861 | dlen = (risc_size - 8) * sizeof(*dcode); |
| 6862 | ql_dbg(ql_dbg_init, vha, 0x0163, |
| 6863 | "-> template allocating %x bytes...\n", dlen); |
| 6864 | ha->fw_dump_template = vmalloc(dlen); |
| 6865 | if (!ha->fw_dump_template) { |
| 6866 | ql_log(ql_log_warn, vha, 0x0164, |
| 6867 | "Failed fwdump template allocate %x bytes.\n", risc_size); |
| 6868 | goto default_template; |
| 6869 | } |
| 6870 | |
| 6871 | faddr += 7; |
| 6872 | risc_size -= 8; |
| 6873 | dcode = ha->fw_dump_template; |
| 6874 | qla24xx_read_flash_data(vha, dcode, faddr, risc_size); |
| 6875 | for (i = 0; i < risc_size; i++) |
| 6876 | dcode[i] = le32_to_cpu(dcode[i]); |
| 6877 | |
| 6878 | if (!qla27xx_fwdt_template_valid(dcode)) { |
| 6879 | ql_log(ql_log_warn, vha, 0x0165, |
| 6880 | "Failed fwdump template validate\n"); |
| 6881 | goto default_template; |
| 6882 | } |
| 6883 | |
| 6884 | dlen = qla27xx_fwdt_template_size(dcode); |
| 6885 | ql_dbg(ql_dbg_init, vha, 0x0166, |
| 6886 | "-> template size %x bytes\n", dlen); |
| 6887 | if (dlen > risc_size * sizeof(*dcode)) { |
| 6888 | ql_log(ql_log_warn, vha, 0x0167, |
Himanshu Madhani | 4fae52b | 2017-06-06 13:55:23 -0700 | [diff] [blame] | 6889 | "Failed fwdump template exceeds array by %zx bytes\n", |
Joe Carnuccio | 383a298 | 2017-06-02 09:11:55 -0700 | [diff] [blame] | 6890 | (size_t)(dlen - risc_size * sizeof(*dcode))); |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 6891 | goto default_template; |
| 6892 | } |
| 6893 | ha->fw_dump_template_len = dlen; |
| 6894 | return rval; |
| 6895 | |
| 6896 | default_template: |
| 6897 | ql_log(ql_log_warn, vha, 0x0168, "Using default fwdump template\n"); |
| 6898 | if (ha->fw_dump_template) |
| 6899 | vfree(ha->fw_dump_template); |
| 6900 | ha->fw_dump_template = NULL; |
| 6901 | ha->fw_dump_template_len = 0; |
| 6902 | |
| 6903 | dlen = qla27xx_fwdt_template_default_size(); |
| 6904 | ql_dbg(ql_dbg_init, vha, 0x0169, |
| 6905 | "-> template allocating %x bytes...\n", dlen); |
| 6906 | ha->fw_dump_template = vmalloc(dlen); |
| 6907 | if (!ha->fw_dump_template) { |
| 6908 | ql_log(ql_log_warn, vha, 0x016a, |
| 6909 | "Failed fwdump template allocate %x bytes.\n", risc_size); |
| 6910 | goto failed_template; |
| 6911 | } |
| 6912 | |
| 6913 | dcode = ha->fw_dump_template; |
| 6914 | risc_size = dlen / sizeof(*dcode); |
| 6915 | memcpy(dcode, qla27xx_fwdt_template_default(), dlen); |
| 6916 | for (i = 0; i < risc_size; i++) |
| 6917 | dcode[i] = be32_to_cpu(dcode[i]); |
| 6918 | |
| 6919 | if (!qla27xx_fwdt_template_valid(ha->fw_dump_template)) { |
| 6920 | ql_log(ql_log_warn, vha, 0x016b, |
| 6921 | "Failed fwdump template validate\n"); |
| 6922 | goto failed_template; |
| 6923 | } |
| 6924 | |
| 6925 | dlen = qla27xx_fwdt_template_size(ha->fw_dump_template); |
| 6926 | ql_dbg(ql_dbg_init, vha, 0x016c, |
| 6927 | "-> template size %x bytes\n", dlen); |
| 6928 | ha->fw_dump_template_len = dlen; |
| 6929 | return rval; |
| 6930 | |
| 6931 | failed_template: |
| 6932 | ql_log(ql_log_warn, vha, 0x016d, "Failed default fwdump template\n"); |
| 6933 | if (ha->fw_dump_template) |
| 6934 | vfree(ha->fw_dump_template); |
| 6935 | ha->fw_dump_template = NULL; |
| 6936 | ha->fw_dump_template_len = 0; |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 6937 | return rval; |
| 6938 | } |
| 6939 | |
Giridhar Malavali | e9454a8 | 2013-02-08 01:57:47 -0500 | [diff] [blame] | 6940 | #define QLA_FW_URL "http://ldriver.qlogic.com/firmware/" |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 6941 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6942 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6943 | qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr) |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6944 | { |
| 6945 | int rval; |
| 6946 | int i, fragment; |
| 6947 | uint16_t *wcode, *fwcode; |
| 6948 | uint32_t risc_addr, risc_size, fwclen, wlen, *seg; |
| 6949 | struct fw_blob *blob; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6950 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6951 | struct req_que *req = ha->req_q_map[0]; |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6952 | |
| 6953 | /* Load firmware blob. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6954 | blob = qla2x00_request_firmware(vha); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6955 | if (!blob) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6956 | ql_log(ql_log_info, vha, 0x0083, |
Yannick Guerrini | 94bcf83 | 2015-02-26 22:49:34 +0100 | [diff] [blame] | 6957 | "Firmware image unavailable.\n"); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6958 | ql_log(ql_log_info, vha, 0x0084, |
| 6959 | "Firmware images can be retrieved from: "QLA_FW_URL ".\n"); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6960 | return QLA_FUNCTION_FAILED; |
| 6961 | } |
| 6962 | |
| 6963 | rval = QLA_SUCCESS; |
| 6964 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6965 | wcode = (uint16_t *)req->ring; |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6966 | *srisc_addr = 0; |
| 6967 | fwcode = (uint16_t *)blob->fw->data; |
| 6968 | fwclen = 0; |
| 6969 | |
| 6970 | /* Validate firmware image by checking version. */ |
| 6971 | if (blob->fw->size < 8 * sizeof(uint16_t)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6972 | ql_log(ql_log_fatal, vha, 0x0085, |
Alexey Dobriyan | 5b5e092 | 2017-02-27 14:30:02 -0800 | [diff] [blame] | 6973 | "Unable to verify integrity of firmware image (%zd).\n", |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6974 | blob->fw->size); |
| 6975 | goto fail_fw_integrity; |
| 6976 | } |
| 6977 | for (i = 0; i < 4; i++) |
| 6978 | wcode[i] = be16_to_cpu(fwcode[i + 4]); |
| 6979 | if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff && |
| 6980 | wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 && |
| 6981 | wcode[2] == 0 && wcode[3] == 0)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6982 | ql_log(ql_log_fatal, vha, 0x0086, |
| 6983 | "Unable to verify integrity of firmware image.\n"); |
| 6984 | ql_log(ql_log_fatal, vha, 0x0087, |
| 6985 | "Firmware data: %04x %04x %04x %04x.\n", |
| 6986 | wcode[0], wcode[1], wcode[2], wcode[3]); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6987 | goto fail_fw_integrity; |
| 6988 | } |
| 6989 | |
| 6990 | seg = blob->segs; |
| 6991 | while (*seg && rval == QLA_SUCCESS) { |
| 6992 | risc_addr = *seg; |
| 6993 | *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr; |
| 6994 | risc_size = be16_to_cpu(fwcode[3]); |
| 6995 | |
| 6996 | /* Validate firmware image size. */ |
| 6997 | fwclen += risc_size * sizeof(uint16_t); |
| 6998 | if (blob->fw->size < fwclen) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6999 | ql_log(ql_log_fatal, vha, 0x0088, |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 7000 | "Unable to verify integrity of firmware image " |
Alexey Dobriyan | 5b5e092 | 2017-02-27 14:30:02 -0800 | [diff] [blame] | 7001 | "(%zd).\n", blob->fw->size); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 7002 | goto fail_fw_integrity; |
| 7003 | } |
| 7004 | |
| 7005 | fragment = 0; |
| 7006 | while (risc_size > 0 && rval == QLA_SUCCESS) { |
| 7007 | wlen = (uint16_t)(ha->fw_transfer_size >> 1); |
| 7008 | if (wlen > risc_size) |
| 7009 | wlen = risc_size; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7010 | ql_dbg(ql_dbg_init, vha, 0x0089, |
| 7011 | "Loading risc segment@ risc addr %x number of " |
| 7012 | "words 0x%x.\n", risc_addr, wlen); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 7013 | |
| 7014 | for (i = 0; i < wlen; i++) |
| 7015 | wcode[i] = swab16(fwcode[i]); |
| 7016 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 7017 | rval = qla2x00_load_ram(vha, req->dma, risc_addr, |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 7018 | wlen); |
| 7019 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7020 | ql_log(ql_log_fatal, vha, 0x008a, |
| 7021 | "Failed to load segment %d of firmware.\n", |
| 7022 | fragment); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 7023 | break; |
| 7024 | } |
| 7025 | |
| 7026 | fwcode += wlen; |
| 7027 | risc_addr += wlen; |
| 7028 | risc_size -= wlen; |
| 7029 | fragment++; |
| 7030 | } |
| 7031 | |
| 7032 | /* Next segment. */ |
| 7033 | seg++; |
| 7034 | } |
| 7035 | return rval; |
| 7036 | |
| 7037 | fail_fw_integrity: |
| 7038 | return QLA_FUNCTION_FAILED; |
| 7039 | } |
| 7040 | |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 7041 | static int |
| 7042 | 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] | 7043 | { |
| 7044 | int rval; |
| 7045 | int segments, fragment; |
| 7046 | uint32_t *dcode, dlen; |
| 7047 | uint32_t risc_addr; |
| 7048 | uint32_t risc_size; |
| 7049 | uint32_t i; |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 7050 | struct fw_blob *blob; |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 7051 | const uint32_t *fwcode; |
| 7052 | uint32_t fwclen; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7053 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 7054 | struct req_que *req = ha->req_q_map[0]; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 7055 | |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 7056 | /* Load firmware blob. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7057 | blob = qla2x00_request_firmware(vha); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 7058 | if (!blob) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7059 | ql_log(ql_log_warn, vha, 0x0090, |
Yannick Guerrini | 94bcf83 | 2015-02-26 22:49:34 +0100 | [diff] [blame] | 7060 | "Firmware image unavailable.\n"); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7061 | ql_log(ql_log_warn, vha, 0x0091, |
| 7062 | "Firmware images can be retrieved from: " |
| 7063 | QLA_FW_URL ".\n"); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 7064 | |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 7065 | return QLA_FUNCTION_FAILED; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 7066 | } |
| 7067 | |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 7068 | ql_dbg(ql_dbg_init, vha, 0x0092, |
| 7069 | "FW: Loading via request-firmware.\n"); |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 7070 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 7071 | rval = QLA_SUCCESS; |
| 7072 | |
| 7073 | segments = FA_RISC_CODE_SEGMENTS; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 7074 | dcode = (uint32_t *)req->ring; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 7075 | *srisc_addr = 0; |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 7076 | fwcode = (uint32_t *)blob->fw->data; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 7077 | fwclen = 0; |
| 7078 | |
| 7079 | /* Validate firmware image by checking version. */ |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 7080 | if (blob->fw->size < 8 * sizeof(uint32_t)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7081 | ql_log(ql_log_fatal, vha, 0x0093, |
Alexey Dobriyan | 5b5e092 | 2017-02-27 14:30:02 -0800 | [diff] [blame] | 7082 | "Unable to verify integrity of firmware image (%zd).\n", |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 7083 | blob->fw->size); |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 7084 | return QLA_FUNCTION_FAILED; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 7085 | } |
| 7086 | for (i = 0; i < 4; i++) |
| 7087 | dcode[i] = be32_to_cpu(fwcode[i + 4]); |
| 7088 | if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff && |
| 7089 | dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) || |
| 7090 | (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 && |
| 7091 | dcode[3] == 0)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7092 | ql_log(ql_log_fatal, vha, 0x0094, |
Alexey Dobriyan | 5b5e092 | 2017-02-27 14:30:02 -0800 | [diff] [blame] | 7093 | "Unable to verify integrity of firmware image (%zd).\n", |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7094 | blob->fw->size); |
| 7095 | ql_log(ql_log_fatal, vha, 0x0095, |
| 7096 | "Firmware data: %08x %08x %08x %08x.\n", |
| 7097 | dcode[0], dcode[1], dcode[2], dcode[3]); |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 7098 | return QLA_FUNCTION_FAILED; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 7099 | } |
| 7100 | |
| 7101 | while (segments && rval == QLA_SUCCESS) { |
| 7102 | risc_addr = be32_to_cpu(fwcode[2]); |
| 7103 | *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr; |
| 7104 | risc_size = be32_to_cpu(fwcode[3]); |
| 7105 | |
| 7106 | /* Validate firmware image size. */ |
| 7107 | fwclen += risc_size * sizeof(uint32_t); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 7108 | if (blob->fw->size < fwclen) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7109 | ql_log(ql_log_fatal, vha, 0x0096, |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 7110 | "Unable to verify integrity of firmware image " |
Alexey Dobriyan | 5b5e092 | 2017-02-27 14:30:02 -0800 | [diff] [blame] | 7111 | "(%zd).\n", blob->fw->size); |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 7112 | return QLA_FUNCTION_FAILED; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 7113 | } |
| 7114 | |
| 7115 | fragment = 0; |
| 7116 | while (risc_size > 0 && rval == QLA_SUCCESS) { |
| 7117 | dlen = (uint32_t)(ha->fw_transfer_size >> 2); |
| 7118 | if (dlen > risc_size) |
| 7119 | dlen = risc_size; |
| 7120 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7121 | ql_dbg(ql_dbg_init, vha, 0x0097, |
| 7122 | "Loading risc segment@ risc addr %x " |
| 7123 | "number of dwords 0x%x.\n", risc_addr, dlen); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 7124 | |
| 7125 | for (i = 0; i < dlen; i++) |
| 7126 | dcode[i] = swab32(fwcode[i]); |
| 7127 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 7128 | rval = qla2x00_load_ram(vha, req->dma, risc_addr, |
andrew.vasquez@qlogic.com | 590f98e | 2006-01-13 17:05:37 -0800 | [diff] [blame] | 7129 | dlen); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 7130 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7131 | ql_log(ql_log_fatal, vha, 0x0098, |
| 7132 | "Failed to load segment %d of firmware.\n", |
| 7133 | fragment); |
Chad Dupuis | f261f7a | 2014-09-25 05:17:03 -0400 | [diff] [blame] | 7134 | return QLA_FUNCTION_FAILED; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 7135 | } |
| 7136 | |
| 7137 | fwcode += dlen; |
| 7138 | risc_addr += dlen; |
| 7139 | risc_size -= dlen; |
| 7140 | fragment++; |
| 7141 | } |
| 7142 | |
| 7143 | /* Next segment. */ |
| 7144 | segments--; |
| 7145 | } |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 7146 | |
| 7147 | if (!IS_QLA27XX(ha)) |
| 7148 | return rval; |
| 7149 | |
| 7150 | if (ha->fw_dump_template) |
| 7151 | vfree(ha->fw_dump_template); |
| 7152 | ha->fw_dump_template = NULL; |
| 7153 | ha->fw_dump_template_len = 0; |
| 7154 | |
| 7155 | ql_dbg(ql_dbg_init, vha, 0x171, |
Chad Dupuis | 97ea702 | 2014-03-13 14:16:40 -0400 | [diff] [blame] | 7156 | "Loading fwdump template from %x\n", |
| 7157 | (uint32_t)((void *)fwcode - (void *)blob->fw->data)); |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 7158 | risc_size = be32_to_cpu(fwcode[2]); |
| 7159 | ql_dbg(ql_dbg_init, vha, 0x172, |
| 7160 | "-> array size %x dwords\n", risc_size); |
| 7161 | if (risc_size == 0 || risc_size == ~0) |
| 7162 | goto default_template; |
| 7163 | |
| 7164 | dlen = (risc_size - 8) * sizeof(*fwcode); |
| 7165 | ql_dbg(ql_dbg_init, vha, 0x0173, |
| 7166 | "-> template allocating %x bytes...\n", dlen); |
| 7167 | ha->fw_dump_template = vmalloc(dlen); |
| 7168 | if (!ha->fw_dump_template) { |
| 7169 | ql_log(ql_log_warn, vha, 0x0174, |
| 7170 | "Failed fwdump template allocate %x bytes.\n", risc_size); |
| 7171 | goto default_template; |
| 7172 | } |
| 7173 | |
| 7174 | fwcode += 7; |
| 7175 | risc_size -= 8; |
| 7176 | dcode = ha->fw_dump_template; |
| 7177 | for (i = 0; i < risc_size; i++) |
| 7178 | dcode[i] = le32_to_cpu(fwcode[i]); |
| 7179 | |
| 7180 | if (!qla27xx_fwdt_template_valid(dcode)) { |
| 7181 | ql_log(ql_log_warn, vha, 0x0175, |
| 7182 | "Failed fwdump template validate\n"); |
| 7183 | goto default_template; |
| 7184 | } |
| 7185 | |
| 7186 | dlen = qla27xx_fwdt_template_size(dcode); |
| 7187 | ql_dbg(ql_dbg_init, vha, 0x0176, |
| 7188 | "-> template size %x bytes\n", dlen); |
| 7189 | if (dlen > risc_size * sizeof(*fwcode)) { |
| 7190 | ql_log(ql_log_warn, vha, 0x0177, |
Himanshu Madhani | 4fae52b | 2017-06-06 13:55:23 -0700 | [diff] [blame] | 7191 | "Failed fwdump template exceeds array by %zx bytes\n", |
Joe Carnuccio | 383a298 | 2017-06-02 09:11:55 -0700 | [diff] [blame] | 7192 | (size_t)(dlen - risc_size * sizeof(*fwcode))); |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 7193 | goto default_template; |
| 7194 | } |
| 7195 | ha->fw_dump_template_len = dlen; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 7196 | return rval; |
| 7197 | |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 7198 | default_template: |
| 7199 | ql_log(ql_log_warn, vha, 0x0178, "Using default fwdump template\n"); |
| 7200 | if (ha->fw_dump_template) |
| 7201 | vfree(ha->fw_dump_template); |
| 7202 | ha->fw_dump_template = NULL; |
| 7203 | ha->fw_dump_template_len = 0; |
| 7204 | |
| 7205 | dlen = qla27xx_fwdt_template_default_size(); |
| 7206 | ql_dbg(ql_dbg_init, vha, 0x0179, |
| 7207 | "-> template allocating %x bytes...\n", dlen); |
| 7208 | ha->fw_dump_template = vmalloc(dlen); |
| 7209 | if (!ha->fw_dump_template) { |
| 7210 | ql_log(ql_log_warn, vha, 0x017a, |
| 7211 | "Failed fwdump template allocate %x bytes.\n", risc_size); |
| 7212 | goto failed_template; |
| 7213 | } |
| 7214 | |
| 7215 | dcode = ha->fw_dump_template; |
| 7216 | risc_size = dlen / sizeof(*fwcode); |
| 7217 | fwcode = qla27xx_fwdt_template_default(); |
| 7218 | for (i = 0; i < risc_size; i++) |
| 7219 | dcode[i] = be32_to_cpu(fwcode[i]); |
| 7220 | |
| 7221 | if (!qla27xx_fwdt_template_valid(ha->fw_dump_template)) { |
| 7222 | ql_log(ql_log_warn, vha, 0x017b, |
| 7223 | "Failed fwdump template validate\n"); |
| 7224 | goto failed_template; |
| 7225 | } |
| 7226 | |
| 7227 | dlen = qla27xx_fwdt_template_size(ha->fw_dump_template); |
| 7228 | ql_dbg(ql_dbg_init, vha, 0x017c, |
| 7229 | "-> template size %x bytes\n", dlen); |
| 7230 | ha->fw_dump_template_len = dlen; |
| 7231 | return rval; |
| 7232 | |
| 7233 | failed_template: |
| 7234 | ql_log(ql_log_warn, vha, 0x017d, "Failed default fwdump template\n"); |
| 7235 | if (ha->fw_dump_template) |
| 7236 | vfree(ha->fw_dump_template); |
| 7237 | ha->fw_dump_template = NULL; |
| 7238 | ha->fw_dump_template_len = 0; |
| 7239 | return rval; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 7240 | } |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 7241 | |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 7242 | int |
| 7243 | qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr) |
| 7244 | { |
| 7245 | int rval; |
| 7246 | |
Andrew Vasquez | e337d90 | 2009-04-06 22:33:49 -0700 | [diff] [blame] | 7247 | if (ql2xfwloadbin == 1) |
| 7248 | return qla81xx_load_risc(vha, srisc_addr); |
| 7249 | |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 7250 | /* |
| 7251 | * FW Load priority: |
| 7252 | * 1) Firmware via request-firmware interface (.bin file). |
| 7253 | * 2) Firmware residing in flash. |
| 7254 | */ |
| 7255 | rval = qla24xx_load_risc_blob(vha, srisc_addr); |
| 7256 | if (rval == QLA_SUCCESS) |
| 7257 | return rval; |
| 7258 | |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 7259 | return qla24xx_load_risc_flash(vha, srisc_addr, |
| 7260 | vha->hw->flt_region_fw); |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 7261 | } |
| 7262 | |
| 7263 | int |
| 7264 | qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr) |
| 7265 | { |
| 7266 | int rval; |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 7267 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 7268 | |
Andrew Vasquez | e337d90 | 2009-04-06 22:33:49 -0700 | [diff] [blame] | 7269 | if (ql2xfwloadbin == 2) |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 7270 | goto try_blob_fw; |
Andrew Vasquez | e337d90 | 2009-04-06 22:33:49 -0700 | [diff] [blame] | 7271 | |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 7272 | /* |
| 7273 | * FW Load priority: |
| 7274 | * 1) Firmware residing in flash. |
| 7275 | * 2) Firmware via request-firmware interface (.bin file). |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 7276 | * 3) Golden-Firmware residing in flash -- limited operation. |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 7277 | */ |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 7278 | rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw); |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 7279 | if (rval == QLA_SUCCESS) |
| 7280 | return rval; |
| 7281 | |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 7282 | try_blob_fw: |
| 7283 | rval = qla24xx_load_risc_blob(vha, srisc_addr); |
| 7284 | if (rval == QLA_SUCCESS || !ha->flt_region_gold_fw) |
| 7285 | return rval; |
| 7286 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7287 | ql_log(ql_log_info, vha, 0x0099, |
| 7288 | "Attempting to fallback to golden firmware.\n"); |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 7289 | rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw); |
| 7290 | if (rval != QLA_SUCCESS) |
| 7291 | return rval; |
| 7292 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7293 | ql_log(ql_log_info, vha, 0x009a, "Update operational firmware.\n"); |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 7294 | ha->flags.running_gold_fw = 1; |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 7295 | return rval; |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 7296 | } |
| 7297 | |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 7298 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7299 | qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha) |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 7300 | { |
| 7301 | int ret, retries; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7302 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 7303 | |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 7304 | if (ha->flags.pci_channel_io_perm_failure) |
| 7305 | return; |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 7306 | if (!IS_FWI2_CAPABLE(ha)) |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 7307 | return; |
Andrew Vasquez | 75edf81 | 2007-05-07 07:43:00 -0700 | [diff] [blame] | 7308 | if (!ha->fw_major_version) |
| 7309 | return; |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 7310 | if (!ha->flags.fw_started) |
| 7311 | return; |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 7312 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7313 | ret = qla2x00_stop_firmware(vha); |
Andrew Vasquez | 7c7f1f2 | 2008-02-28 14:06:09 -0800 | [diff] [blame] | 7314 | for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT && |
Andrew Vasquez | b469a7c | 2009-04-06 22:33:48 -0700 | [diff] [blame] | 7315 | ret != QLA_INVALID_COMMAND && retries ; retries--) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7316 | ha->isp_ops->reset_chip(vha); |
| 7317 | if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS) |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 7318 | continue; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7319 | if (qla2x00_setup_chip(vha) != QLA_SUCCESS) |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 7320 | continue; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7321 | ql_log(ql_log_info, vha, 0x8015, |
| 7322 | "Attempting retry of stop-firmware command.\n"); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7323 | ret = qla2x00_stop_firmware(vha); |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 7324 | } |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 7325 | |
Quinn Tran | 4b60c82 | 2017-06-13 20:47:21 -0700 | [diff] [blame] | 7326 | QLA_FW_STOPPED(ha); |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 7327 | ha->flags.fw_init_done = 0; |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 7328 | } |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 7329 | |
| 7330 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7331 | qla24xx_configure_vhba(scsi_qla_host_t *vha) |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 7332 | { |
| 7333 | int rval = QLA_SUCCESS; |
Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 7334 | int rval2; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 7335 | uint16_t mb[MAILBOX_REGISTER_COUNT]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7336 | struct qla_hw_data *ha = vha->hw; |
| 7337 | struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev); |
Anirban Chakraborty | 67c2e93 | 2009-04-06 22:33:42 -0700 | [diff] [blame] | 7338 | struct req_que *req; |
| 7339 | struct rsp_que *rsp; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 7340 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7341 | if (!vha->vp_idx) |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 7342 | return -EINVAL; |
| 7343 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7344 | rval = qla2x00_fw_ready(base_vha); |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 7345 | if (vha->qpair) |
| 7346 | req = vha->qpair->req; |
Anirban Chakraborty | 67c2e93 | 2009-04-06 22:33:42 -0700 | [diff] [blame] | 7347 | else |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 7348 | req = ha->req_q_map[0]; |
Anirban Chakraborty | 67c2e93 | 2009-04-06 22:33:42 -0700 | [diff] [blame] | 7349 | rsp = req->rsp; |
| 7350 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 7351 | if (rval == QLA_SUCCESS) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7352 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 7353 | qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 7354 | } |
| 7355 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7356 | vha->flags.management_server_logged_in = 0; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 7357 | |
| 7358 | /* Login to SNS first */ |
Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 7359 | rval2 = ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb, |
| 7360 | BIT_1); |
| 7361 | if (rval2 != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) { |
| 7362 | if (rval2 == QLA_MEMORY_ALLOC_FAILED) |
| 7363 | ql_dbg(ql_dbg_init, vha, 0x0120, |
| 7364 | "Failed SNS login: loop_id=%x, rval2=%d\n", |
| 7365 | NPH_SNS, rval2); |
| 7366 | else |
| 7367 | ql_dbg(ql_dbg_init, vha, 0x0103, |
| 7368 | "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x " |
| 7369 | "mb[2]=%x mb[6]=%x mb[7]=%x.\n", |
| 7370 | NPH_SNS, mb[0], mb[1], mb[2], mb[6], mb[7]); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 7371 | return (QLA_FUNCTION_FAILED); |
| 7372 | } |
| 7373 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7374 | atomic_set(&vha->loop_down_timer, 0); |
| 7375 | atomic_set(&vha->loop_state, LOOP_UP); |
| 7376 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
| 7377 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
| 7378 | rval = qla2x00_loop_resync(base_vha); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 7379 | |
| 7380 | return rval; |
| 7381 | } |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 7382 | |
| 7383 | /* 84XX Support **************************************************************/ |
| 7384 | |
| 7385 | static LIST_HEAD(qla_cs84xx_list); |
| 7386 | static DEFINE_MUTEX(qla_cs84xx_mutex); |
| 7387 | |
| 7388 | static struct qla_chip_state_84xx * |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7389 | qla84xx_get_chip(struct scsi_qla_host *vha) |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 7390 | { |
| 7391 | struct qla_chip_state_84xx *cs84xx; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7392 | struct qla_hw_data *ha = vha->hw; |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 7393 | |
| 7394 | mutex_lock(&qla_cs84xx_mutex); |
| 7395 | |
| 7396 | /* Find any shared 84xx chip. */ |
| 7397 | list_for_each_entry(cs84xx, &qla_cs84xx_list, list) { |
| 7398 | if (cs84xx->bus == ha->pdev->bus) { |
| 7399 | kref_get(&cs84xx->kref); |
| 7400 | goto done; |
| 7401 | } |
| 7402 | } |
| 7403 | |
| 7404 | cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL); |
| 7405 | if (!cs84xx) |
| 7406 | goto done; |
| 7407 | |
| 7408 | kref_init(&cs84xx->kref); |
| 7409 | spin_lock_init(&cs84xx->access_lock); |
| 7410 | mutex_init(&cs84xx->fw_update_mutex); |
| 7411 | cs84xx->bus = ha->pdev->bus; |
| 7412 | |
| 7413 | list_add_tail(&cs84xx->list, &qla_cs84xx_list); |
| 7414 | done: |
| 7415 | mutex_unlock(&qla_cs84xx_mutex); |
| 7416 | return cs84xx; |
| 7417 | } |
| 7418 | |
| 7419 | static void |
| 7420 | __qla84xx_chip_release(struct kref *kref) |
| 7421 | { |
| 7422 | struct qla_chip_state_84xx *cs84xx = |
| 7423 | container_of(kref, struct qla_chip_state_84xx, kref); |
| 7424 | |
| 7425 | mutex_lock(&qla_cs84xx_mutex); |
| 7426 | list_del(&cs84xx->list); |
| 7427 | mutex_unlock(&qla_cs84xx_mutex); |
| 7428 | kfree(cs84xx); |
| 7429 | } |
| 7430 | |
| 7431 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7432 | qla84xx_put_chip(struct scsi_qla_host *vha) |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 7433 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7434 | struct qla_hw_data *ha = vha->hw; |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 7435 | if (ha->cs84xx) |
| 7436 | kref_put(&ha->cs84xx->kref, __qla84xx_chip_release); |
| 7437 | } |
| 7438 | |
| 7439 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7440 | qla84xx_init_chip(scsi_qla_host_t *vha) |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 7441 | { |
| 7442 | int rval; |
| 7443 | uint16_t status[2]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7444 | struct qla_hw_data *ha = vha->hw; |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 7445 | |
| 7446 | mutex_lock(&ha->cs84xx->fw_update_mutex); |
| 7447 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7448 | rval = qla84xx_verify_chip(vha, status); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 7449 | |
| 7450 | mutex_unlock(&ha->cs84xx->fw_update_mutex); |
| 7451 | |
| 7452 | return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED: |
| 7453 | QLA_SUCCESS; |
| 7454 | } |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7455 | |
| 7456 | /* 81XX Support **************************************************************/ |
| 7457 | |
| 7458 | int |
| 7459 | qla81xx_nvram_config(scsi_qla_host_t *vha) |
| 7460 | { |
| 7461 | int rval; |
| 7462 | struct init_cb_81xx *icb; |
| 7463 | struct nvram_81xx *nv; |
| 7464 | uint32_t *dptr; |
| 7465 | uint8_t *dptr1, *dptr2; |
| 7466 | uint32_t chksum; |
| 7467 | uint16_t cnt; |
| 7468 | struct qla_hw_data *ha = vha->hw; |
| 7469 | |
| 7470 | rval = QLA_SUCCESS; |
| 7471 | icb = (struct init_cb_81xx *)ha->init_cb; |
| 7472 | nv = ha->nvram; |
| 7473 | |
| 7474 | /* Determine NVRAM starting address. */ |
| 7475 | ha->nvram_size = sizeof(struct nvram_81xx); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7476 | ha->vpd_size = FA_NVRAM_VPD_SIZE; |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 7477 | if (IS_P3P_TYPE(ha) || IS_QLA8031(ha)) |
| 7478 | ha->vpd_size = FA_VPD_SIZE_82XX; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7479 | |
| 7480 | /* Get VPD data into cache */ |
| 7481 | ha->vpd = ha->nvram + VPD_OFFSET; |
Andrew Vasquez | 3d79038f | 2009-03-24 09:08:14 -0700 | [diff] [blame] | 7482 | ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2, |
| 7483 | ha->vpd_size); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7484 | |
| 7485 | /* Get NVRAM data into cache and calculate checksum. */ |
Andrew Vasquez | 3d79038f | 2009-03-24 09:08:14 -0700 | [diff] [blame] | 7486 | 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] | 7487 | ha->nvram_size); |
Andrew Vasquez | 3d79038f | 2009-03-24 09:08:14 -0700 | [diff] [blame] | 7488 | dptr = (uint32_t *)nv; |
Joe Carnuccio | da08ef5 | 2016-01-27 12:03:34 -0500 | [diff] [blame] | 7489 | for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++) |
| 7490 | chksum += le32_to_cpu(*dptr); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7491 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7492 | ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0111, |
| 7493 | "Contents of NVRAM:\n"); |
| 7494 | ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0112, |
| 7495 | (uint8_t *)nv, ha->nvram_size); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7496 | |
| 7497 | /* Bad NVRAM data, set defaults parameters. */ |
| 7498 | if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P' |
| 7499 | || nv->id[3] != ' ' || |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7500 | nv->nvram_version < cpu_to_le16(ICB_VERSION)) { |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7501 | /* Reset NVRAM data. */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7502 | ql_log(ql_log_info, vha, 0x0073, |
Raul Porcel | 9e33652 | 2012-05-15 14:34:08 -0400 | [diff] [blame] | 7503 | "Inconsistent NVRAM detected: checksum=0x%x id=%c " |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7504 | "version=0x%x.\n", chksum, nv->id[0], |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7505 | le16_to_cpu(nv->nvram_version)); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7506 | ql_log(ql_log_info, vha, 0x0074, |
| 7507 | "Falling back to functioning (yet invalid -- WWPN) " |
| 7508 | "defaults.\n"); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7509 | |
| 7510 | /* |
| 7511 | * Set default initialization control block. |
| 7512 | */ |
| 7513 | memset(nv, 0, ha->nvram_size); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7514 | nv->nvram_version = cpu_to_le16(ICB_VERSION); |
| 7515 | nv->version = cpu_to_le16(ICB_VERSION); |
Joe Carnuccio | 98aee70 | 2014-09-25 05:16:38 -0400 | [diff] [blame] | 7516 | nv->frame_payload_size = 2048; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7517 | nv->execution_throttle = cpu_to_le16(0xFFFF); |
| 7518 | nv->exchange_count = cpu_to_le16(0); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7519 | nv->port_name[0] = 0x21; |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 7520 | nv->port_name[1] = 0x00 + ha->port_no + 1; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7521 | nv->port_name[2] = 0x00; |
| 7522 | nv->port_name[3] = 0xe0; |
| 7523 | nv->port_name[4] = 0x8b; |
| 7524 | nv->port_name[5] = 0x1c; |
| 7525 | nv->port_name[6] = 0x55; |
| 7526 | nv->port_name[7] = 0x86; |
| 7527 | nv->node_name[0] = 0x20; |
| 7528 | nv->node_name[1] = 0x00; |
| 7529 | nv->node_name[2] = 0x00; |
| 7530 | nv->node_name[3] = 0xe0; |
| 7531 | nv->node_name[4] = 0x8b; |
| 7532 | nv->node_name[5] = 0x1c; |
| 7533 | nv->node_name[6] = 0x55; |
| 7534 | nv->node_name[7] = 0x86; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7535 | nv->login_retry_count = cpu_to_le16(8); |
| 7536 | nv->interrupt_delay_timer = cpu_to_le16(0); |
| 7537 | nv->login_timeout = cpu_to_le16(0); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7538 | nv->firmware_options_1 = |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7539 | cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1); |
| 7540 | nv->firmware_options_2 = cpu_to_le32(2 << 4); |
| 7541 | nv->firmware_options_2 |= cpu_to_le32(BIT_12); |
| 7542 | nv->firmware_options_3 = cpu_to_le32(2 << 13); |
| 7543 | nv->host_p = cpu_to_le32(BIT_11|BIT_10); |
| 7544 | nv->efi_parameters = cpu_to_le32(0); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7545 | nv->reset_delay = 5; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7546 | nv->max_luns_per_target = cpu_to_le16(128); |
| 7547 | nv->port_down_retry_count = cpu_to_le16(30); |
| 7548 | nv->link_down_timeout = cpu_to_le16(180); |
Andrew Vasquez | eeebcc9 | 2009-06-03 09:55:24 -0700 | [diff] [blame] | 7549 | nv->enode_mac[0] = 0x00; |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 7550 | nv->enode_mac[1] = 0xC0; |
| 7551 | nv->enode_mac[2] = 0xDD; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7552 | nv->enode_mac[3] = 0x04; |
| 7553 | nv->enode_mac[4] = 0x05; |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 7554 | nv->enode_mac[5] = 0x06 + ha->port_no + 1; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7555 | |
| 7556 | rval = 1; |
| 7557 | } |
| 7558 | |
Arun Easi | 9e522cd | 2012-08-22 14:21:31 -0400 | [diff] [blame] | 7559 | if (IS_T10_PI_CAPABLE(ha)) |
| 7560 | nv->frame_payload_size &= ~7; |
| 7561 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 7562 | qlt_81xx_config_nvram_stage1(vha, nv); |
| 7563 | |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7564 | /* Reset Initialization control block */ |
Andrew Vasquez | 773120e | 2011-05-10 11:30:14 -0700 | [diff] [blame] | 7565 | memset(icb, 0, ha->init_cb_size); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7566 | |
| 7567 | /* Copy 1st segment. */ |
| 7568 | dptr1 = (uint8_t *)icb; |
| 7569 | dptr2 = (uint8_t *)&nv->version; |
| 7570 | cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version; |
| 7571 | while (cnt--) |
| 7572 | *dptr1++ = *dptr2++; |
| 7573 | |
| 7574 | icb->login_retry_count = nv->login_retry_count; |
| 7575 | |
| 7576 | /* Copy 2nd segment. */ |
| 7577 | dptr1 = (uint8_t *)&icb->interrupt_delay_timer; |
| 7578 | dptr2 = (uint8_t *)&nv->interrupt_delay_timer; |
| 7579 | cnt = (uint8_t *)&icb->reserved_5 - |
| 7580 | (uint8_t *)&icb->interrupt_delay_timer; |
| 7581 | while (cnt--) |
| 7582 | *dptr1++ = *dptr2++; |
| 7583 | |
| 7584 | memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac)); |
| 7585 | /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */ |
| 7586 | 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] | 7587 | icb->enode_mac[0] = 0x00; |
| 7588 | icb->enode_mac[1] = 0xC0; |
| 7589 | icb->enode_mac[2] = 0xDD; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7590 | icb->enode_mac[3] = 0x04; |
| 7591 | icb->enode_mac[4] = 0x05; |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 7592 | icb->enode_mac[5] = 0x06 + ha->port_no + 1; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7593 | } |
| 7594 | |
Andrew Vasquez | b64b0e8 | 2009-03-24 09:08:01 -0700 | [diff] [blame] | 7595 | /* Use extended-initialization control block. */ |
| 7596 | memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb)); |
| 7597 | |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7598 | /* |
| 7599 | * Setup driver NVRAM options. |
| 7600 | */ |
| 7601 | qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name), |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7602 | "QLE8XXX"); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7603 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 7604 | qlt_81xx_config_nvram_stage2(vha, icb); |
| 7605 | |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7606 | /* Use alternate WWN? */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7607 | if (nv->host_p & cpu_to_le32(BIT_15)) { |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7608 | memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE); |
| 7609 | memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE); |
| 7610 | } |
| 7611 | |
| 7612 | /* Prepare nodename */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7613 | if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) { |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7614 | /* |
| 7615 | * Firmware will apply the following mask if the nodename was |
| 7616 | * not provided. |
| 7617 | */ |
| 7618 | memcpy(icb->node_name, icb->port_name, WWN_SIZE); |
| 7619 | icb->node_name[0] &= 0xF0; |
| 7620 | } |
| 7621 | |
| 7622 | /* Set host adapter parameters. */ |
| 7623 | ha->flags.disable_risc_code_load = 0; |
| 7624 | ha->flags.enable_lip_reset = 0; |
| 7625 | ha->flags.enable_lip_full_login = |
| 7626 | le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0; |
| 7627 | ha->flags.enable_target_reset = |
| 7628 | le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0; |
| 7629 | ha->flags.enable_led_scheme = 0; |
| 7630 | ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0; |
| 7631 | |
| 7632 | ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) & |
| 7633 | (BIT_6 | BIT_5 | BIT_4)) >> 4; |
| 7634 | |
| 7635 | /* save HBA serial number */ |
| 7636 | ha->serial0 = icb->port_name[5]; |
| 7637 | ha->serial1 = icb->port_name[6]; |
| 7638 | ha->serial2 = icb->port_name[7]; |
| 7639 | memcpy(vha->node_name, icb->node_name, WWN_SIZE); |
| 7640 | memcpy(vha->port_name, icb->port_name, WWN_SIZE); |
| 7641 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7642 | icb->execution_throttle = cpu_to_le16(0xFFFF); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7643 | |
| 7644 | ha->retry_count = le16_to_cpu(nv->login_retry_count); |
| 7645 | |
| 7646 | /* Set minimum login_timeout to 4 seconds. */ |
| 7647 | if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout) |
| 7648 | nv->login_timeout = cpu_to_le16(ql2xlogintimeout); |
| 7649 | if (le16_to_cpu(nv->login_timeout) < 4) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7650 | nv->login_timeout = cpu_to_le16(4); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7651 | ha->login_timeout = le16_to_cpu(nv->login_timeout); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7652 | |
| 7653 | /* Set minimum RATOV to 100 tenths of a second. */ |
| 7654 | ha->r_a_tov = 100; |
| 7655 | |
| 7656 | ha->loop_reset_delay = nv->reset_delay; |
| 7657 | |
| 7658 | /* Link Down Timeout = 0: |
| 7659 | * |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 7660 | * When Port Down timer expires we will start returning |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7661 | * I/O's to OS with "DID_NO_CONNECT". |
| 7662 | * |
| 7663 | * Link Down Timeout != 0: |
| 7664 | * |
| 7665 | * The driver waits for the link to come up after link down |
| 7666 | * before returning I/Os to OS with "DID_NO_CONNECT". |
| 7667 | */ |
| 7668 | if (le16_to_cpu(nv->link_down_timeout) == 0) { |
| 7669 | ha->loop_down_abort_time = |
| 7670 | (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT); |
| 7671 | } else { |
| 7672 | ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout); |
| 7673 | ha->loop_down_abort_time = |
| 7674 | (LOOP_DOWN_TIME - ha->link_down_timeout); |
| 7675 | } |
| 7676 | |
| 7677 | /* Need enough time to try and get the port back. */ |
| 7678 | ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count); |
| 7679 | if (qlport_down_retry) |
| 7680 | ha->port_down_retry_count = qlport_down_retry; |
| 7681 | |
| 7682 | /* Set login_retry_count */ |
| 7683 | ha->login_retry_count = le16_to_cpu(nv->login_retry_count); |
| 7684 | if (ha->port_down_retry_count == |
| 7685 | le16_to_cpu(nv->port_down_retry_count) && |
| 7686 | ha->port_down_retry_count > 3) |
| 7687 | ha->login_retry_count = ha->port_down_retry_count; |
| 7688 | else if (ha->port_down_retry_count > (int)ha->login_retry_count) |
| 7689 | ha->login_retry_count = ha->port_down_retry_count; |
| 7690 | if (ql2xloginretrycount) |
| 7691 | ha->login_retry_count = ql2xloginretrycount; |
| 7692 | |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 7693 | /* if not running MSI-X we need handshaking on interrupts */ |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 7694 | 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] | 7695 | icb->firmware_options_2 |= cpu_to_le32(BIT_22); |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 7696 | |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7697 | /* Enable ZIO. */ |
| 7698 | if (!vha->flags.init_done) { |
| 7699 | ha->zio_mode = le32_to_cpu(icb->firmware_options_2) & |
| 7700 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
| 7701 | ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ? |
| 7702 | le16_to_cpu(icb->interrupt_delay_timer): 2; |
| 7703 | } |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7704 | icb->firmware_options_2 &= cpu_to_le32( |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7705 | ~(BIT_3 | BIT_2 | BIT_1 | BIT_0)); |
| 7706 | vha->flags.process_response_queue = 0; |
| 7707 | if (ha->zio_mode != QLA_ZIO_DISABLED) { |
| 7708 | ha->zio_mode = QLA_ZIO_MODE_6; |
| 7709 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7710 | ql_log(ql_log_info, vha, 0x0075, |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7711 | "ZIO mode %d enabled; timer delay (%d us).\n", |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7712 | ha->zio_mode, |
| 7713 | ha->zio_timer * 100); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7714 | |
| 7715 | icb->firmware_options_2 |= cpu_to_le32( |
| 7716 | (uint32_t)ha->zio_mode); |
| 7717 | icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer); |
| 7718 | vha->flags.process_response_queue = 1; |
| 7719 | } |
| 7720 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 7721 | /* enable RIDA Format2 */ |
| 7722 | if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) |
| 7723 | icb->firmware_options_3 |= BIT_0; |
| 7724 | |
Duane Grigsby | edd05de | 2017-10-13 09:34:06 -0700 | [diff] [blame] | 7725 | if (IS_QLA27XX(ha)) { |
| 7726 | icb->firmware_options_3 |= BIT_8; |
| 7727 | ql_dbg(ql_log_info, vha, 0x0075, |
| 7728 | "Enabling direct connection.\n"); |
| 7729 | } |
| 7730 | |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7731 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7732 | ql_log(ql_log_warn, vha, 0x0076, |
| 7733 | "NVRAM configuration failed.\n"); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7734 | } |
| 7735 | return (rval); |
| 7736 | } |
| 7737 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7738 | int |
| 7739 | qla82xx_restart_isp(scsi_qla_host_t *vha) |
| 7740 | { |
| 7741 | int status, rval; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7742 | struct qla_hw_data *ha = vha->hw; |
| 7743 | struct req_que *req = ha->req_q_map[0]; |
| 7744 | struct rsp_que *rsp = ha->rsp_q_map[0]; |
| 7745 | struct scsi_qla_host *vp; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 7746 | unsigned long flags; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7747 | |
| 7748 | status = qla2x00_init_rings(vha); |
| 7749 | if (!status) { |
| 7750 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); |
| 7751 | ha->flags.chip_reset_done = 1; |
| 7752 | |
| 7753 | status = qla2x00_fw_ready(vha); |
| 7754 | if (!status) { |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7755 | /* Issue a marker after FW becomes ready. */ |
| 7756 | qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7757 | vha->flags.online = 1; |
Chad Dupuis | 7108b76 | 2014-04-11 16:54:45 -0400 | [diff] [blame] | 7758 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7759 | } |
| 7760 | |
| 7761 | /* if no cable then assume it's good */ |
| 7762 | if ((vha->device_flags & DFLG_NO_CABLE)) |
| 7763 | status = 0; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7764 | } |
| 7765 | |
| 7766 | if (!status) { |
| 7767 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); |
| 7768 | |
| 7769 | if (!atomic_read(&vha->loop_down_timer)) { |
| 7770 | /* |
| 7771 | * Issue marker command only when we are going |
| 7772 | * to start the I/O . |
| 7773 | */ |
| 7774 | vha->marker_needed = 1; |
| 7775 | } |
| 7776 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7777 | ha->isp_ops->enable_intrs(ha); |
| 7778 | |
| 7779 | ha->isp_abort_cnt = 0; |
| 7780 | clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags); |
| 7781 | |
Saurav Kashyap | 5329678 | 2011-05-10 11:30:06 -0700 | [diff] [blame] | 7782 | /* Update the firmware version */ |
Giridhar Malavali | 3173167 | 2011-08-16 11:31:54 -0700 | [diff] [blame] | 7783 | status = qla82xx_check_md_needed(vha); |
Saurav Kashyap | 5329678 | 2011-05-10 11:30:06 -0700 | [diff] [blame] | 7784 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7785 | if (ha->fce) { |
| 7786 | ha->flags.fce_enabled = 1; |
| 7787 | memset(ha->fce, 0, |
| 7788 | fce_calc_size(ha->fce_bufs)); |
| 7789 | rval = qla2x00_enable_fce_trace(vha, |
| 7790 | ha->fce_dma, ha->fce_bufs, ha->fce_mb, |
| 7791 | &ha->fce_bufs); |
| 7792 | if (rval) { |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 7793 | ql_log(ql_log_warn, vha, 0x8001, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7794 | "Unable to reinitialize FCE (%d).\n", |
| 7795 | rval); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7796 | ha->flags.fce_enabled = 0; |
| 7797 | } |
| 7798 | } |
| 7799 | |
| 7800 | if (ha->eft) { |
| 7801 | memset(ha->eft, 0, EFT_SIZE); |
| 7802 | rval = qla2x00_enable_eft_trace(vha, |
| 7803 | ha->eft_dma, EFT_NUM_BUFFERS); |
| 7804 | if (rval) { |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 7805 | ql_log(ql_log_warn, vha, 0x8010, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7806 | "Unable to reinitialize EFT (%d).\n", |
| 7807 | rval); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7808 | } |
| 7809 | } |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7810 | } |
| 7811 | |
| 7812 | if (!status) { |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 7813 | ql_dbg(ql_dbg_taskm, vha, 0x8011, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7814 | "qla82xx_restart_isp succeeded.\n"); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 7815 | |
| 7816 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 7817 | list_for_each_entry(vp, &ha->vp_list, list) { |
| 7818 | if (vp->vp_idx) { |
| 7819 | atomic_inc(&vp->vref_count); |
| 7820 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 7821 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7822 | qla2x00_vp_abort_isp(vp); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 7823 | |
| 7824 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 7825 | atomic_dec(&vp->vref_count); |
| 7826 | } |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7827 | } |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 7828 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 7829 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7830 | } else { |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 7831 | ql_log(ql_log_warn, vha, 0x8016, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7832 | "qla82xx_restart_isp **** FAILED ****.\n"); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7833 | } |
| 7834 | |
| 7835 | return status; |
| 7836 | } |
| 7837 | |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7838 | void |
Andrew Vasquez | ae97c91 | 2010-02-18 10:07:28 -0800 | [diff] [blame] | 7839 | qla81xx_update_fw_options(scsi_qla_host_t *vha) |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7840 | { |
Andrew Vasquez | ae97c91 | 2010-02-18 10:07:28 -0800 | [diff] [blame] | 7841 | struct qla_hw_data *ha = vha->hw; |
| 7842 | |
Himanshu Madhani | f198caf | 2016-01-27 12:03:30 -0500 | [diff] [blame] | 7843 | /* Hold status IOCBs until ABTS response received. */ |
| 7844 | if (ql2xfwholdabts) |
| 7845 | ha->fw_options[3] |= BIT_12; |
| 7846 | |
Giridhar Malavali | 088d09d | 2016-07-06 11:14:20 -0400 | [diff] [blame] | 7847 | /* Set Retry FLOGI in case of P2P connection */ |
| 7848 | if (ha->operating_mode == P2P) { |
| 7849 | ha->fw_options[2] |= BIT_3; |
| 7850 | ql_dbg(ql_dbg_disc, vha, 0x2103, |
| 7851 | "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n", |
| 7852 | __func__, ha->fw_options[2]); |
| 7853 | } |
| 7854 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 7855 | /* Move PUREX, ABTS RX & RIDA to ATIOQ */ |
| 7856 | if (ql2xmvasynctoatio) { |
| 7857 | if (qla_tgt_mode_enabled(vha) || |
| 7858 | qla_dual_mode_enabled(vha)) |
| 7859 | ha->fw_options[2] |= BIT_11; |
| 7860 | else |
| 7861 | ha->fw_options[2] &= ~BIT_11; |
| 7862 | } |
Andrew Vasquez | ae97c91 | 2010-02-18 10:07:28 -0800 | [diff] [blame] | 7863 | |
Quinn Tran | f7e761f | 2017-06-02 09:12:02 -0700 | [diff] [blame] | 7864 | if (qla_tgt_mode_enabled(vha) || |
Quinn Tran | 2da5273 | 2017-06-02 09:12:05 -0700 | [diff] [blame] | 7865 | qla_dual_mode_enabled(vha)) { |
| 7866 | /* FW auto send SCSI status during */ |
| 7867 | ha->fw_options[1] |= BIT_8; |
| 7868 | ha->fw_options[10] |= (u16)SAM_STAT_BUSY << 8; |
| 7869 | |
| 7870 | /* FW perform Exchange validation */ |
Quinn Tran | f7e761f | 2017-06-02 09:12:02 -0700 | [diff] [blame] | 7871 | ha->fw_options[2] |= BIT_4; |
Quinn Tran | 2da5273 | 2017-06-02 09:12:05 -0700 | [diff] [blame] | 7872 | } else { |
| 7873 | ha->fw_options[1] &= ~BIT_8; |
| 7874 | ha->fw_options[10] &= 0x00ff; |
| 7875 | |
Quinn Tran | f7e761f | 2017-06-02 09:12:02 -0700 | [diff] [blame] | 7876 | ha->fw_options[2] &= ~BIT_4; |
Quinn Tran | 2da5273 | 2017-06-02 09:12:05 -0700 | [diff] [blame] | 7877 | } |
Quinn Tran | f7e761f | 2017-06-02 09:12:02 -0700 | [diff] [blame] | 7878 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 7879 | if (ql2xetsenable) { |
| 7880 | /* Enable ETS Burst. */ |
| 7881 | memset(ha->fw_options, 0, sizeof(ha->fw_options)); |
| 7882 | ha->fw_options[2] |= BIT_9; |
| 7883 | } |
| 7884 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 7885 | ql_dbg(ql_dbg_init, vha, 0x00e9, |
| 7886 | "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n", |
| 7887 | __func__, ha->fw_options[1], ha->fw_options[2], |
| 7888 | ha->fw_options[3], vha->host->active_mode); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 7889 | |
Andrew Vasquez | ae97c91 | 2010-02-18 10:07:28 -0800 | [diff] [blame] | 7890 | qla2x00_set_fw_options(vha, ha->fw_options); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7891 | } |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 7892 | |
| 7893 | /* |
| 7894 | * qla24xx_get_fcp_prio |
| 7895 | * Gets the fcp cmd priority value for the logged in port. |
| 7896 | * Looks for a match of the port descriptors within |
| 7897 | * each of the fcp prio config entries. If a match is found, |
| 7898 | * the tag (priority) value is returned. |
| 7899 | * |
| 7900 | * Input: |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 7901 | * vha = scsi host structure pointer. |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 7902 | * fcport = port structure pointer. |
| 7903 | * |
| 7904 | * Return: |
Andrew Vasquez | 6c452a4 | 2010-03-19 17:04:02 -0700 | [diff] [blame] | 7905 | * non-zero (if found) |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 7906 | * -1 (if not found) |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 7907 | * |
| 7908 | * Context: |
| 7909 | * Kernel context |
| 7910 | */ |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 7911 | static int |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 7912 | qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport) |
| 7913 | { |
| 7914 | int i, entries; |
| 7915 | uint8_t pid_match, wwn_match; |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 7916 | int priority; |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 7917 | uint32_t pid1, pid2; |
| 7918 | uint64_t wwn1, wwn2; |
| 7919 | struct qla_fcp_prio_entry *pri_entry; |
| 7920 | struct qla_hw_data *ha = vha->hw; |
| 7921 | |
| 7922 | if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled) |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 7923 | return -1; |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 7924 | |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 7925 | priority = -1; |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 7926 | entries = ha->fcp_prio_cfg->num_entries; |
| 7927 | pri_entry = &ha->fcp_prio_cfg->entry[0]; |
| 7928 | |
| 7929 | for (i = 0; i < entries; i++) { |
| 7930 | pid_match = wwn_match = 0; |
| 7931 | |
| 7932 | if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) { |
| 7933 | pri_entry++; |
| 7934 | continue; |
| 7935 | } |
| 7936 | |
| 7937 | /* check source pid for a match */ |
| 7938 | if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) { |
| 7939 | pid1 = pri_entry->src_pid & INVALID_PORT_ID; |
| 7940 | pid2 = vha->d_id.b24 & INVALID_PORT_ID; |
| 7941 | if (pid1 == INVALID_PORT_ID) |
| 7942 | pid_match++; |
| 7943 | else if (pid1 == pid2) |
| 7944 | pid_match++; |
| 7945 | } |
| 7946 | |
| 7947 | /* check destination pid for a match */ |
| 7948 | if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) { |
| 7949 | pid1 = pri_entry->dst_pid & INVALID_PORT_ID; |
| 7950 | pid2 = fcport->d_id.b24 & INVALID_PORT_ID; |
| 7951 | if (pid1 == INVALID_PORT_ID) |
| 7952 | pid_match++; |
| 7953 | else if (pid1 == pid2) |
| 7954 | pid_match++; |
| 7955 | } |
| 7956 | |
| 7957 | /* check source WWN for a match */ |
| 7958 | if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) { |
| 7959 | wwn1 = wwn_to_u64(vha->port_name); |
| 7960 | wwn2 = wwn_to_u64(pri_entry->src_wwpn); |
| 7961 | if (wwn2 == (uint64_t)-1) |
| 7962 | wwn_match++; |
| 7963 | else if (wwn1 == wwn2) |
| 7964 | wwn_match++; |
| 7965 | } |
| 7966 | |
| 7967 | /* check destination WWN for a match */ |
| 7968 | if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) { |
| 7969 | wwn1 = wwn_to_u64(fcport->port_name); |
| 7970 | wwn2 = wwn_to_u64(pri_entry->dst_wwpn); |
| 7971 | if (wwn2 == (uint64_t)-1) |
| 7972 | wwn_match++; |
| 7973 | else if (wwn1 == wwn2) |
| 7974 | wwn_match++; |
| 7975 | } |
| 7976 | |
| 7977 | if (pid_match == 2 || wwn_match == 2) { |
| 7978 | /* Found a matching entry */ |
| 7979 | if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID) |
| 7980 | priority = pri_entry->tag; |
| 7981 | break; |
| 7982 | } |
| 7983 | |
| 7984 | pri_entry++; |
| 7985 | } |
| 7986 | |
| 7987 | return priority; |
| 7988 | } |
| 7989 | |
| 7990 | /* |
| 7991 | * qla24xx_update_fcport_fcp_prio |
| 7992 | * Activates fcp priority for the logged in fc port |
| 7993 | * |
| 7994 | * Input: |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 7995 | * vha = scsi host structure pointer. |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 7996 | * fcp = port structure pointer. |
| 7997 | * |
| 7998 | * Return: |
| 7999 | * QLA_SUCCESS or QLA_FUNCTION_FAILED |
| 8000 | * |
| 8001 | * Context: |
| 8002 | * Kernel context. |
| 8003 | */ |
| 8004 | int |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 8005 | 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] | 8006 | { |
| 8007 | int ret; |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 8008 | int priority; |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 8009 | uint16_t mb[5]; |
| 8010 | |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 8011 | if (fcport->port_type != FCT_TARGET || |
| 8012 | fcport->loop_id == FC_NO_LOOP_ID) |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 8013 | return QLA_FUNCTION_FAILED; |
| 8014 | |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 8015 | priority = qla24xx_get_fcp_prio(vha, fcport); |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 8016 | if (priority < 0) |
| 8017 | return QLA_FUNCTION_FAILED; |
| 8018 | |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 8019 | if (IS_P3P_TYPE(vha->hw)) { |
Saurav Kashyap | a00f629 | 2011-11-18 09:03:19 -0800 | [diff] [blame] | 8020 | fcport->fcp_prio = priority & 0xf; |
| 8021 | return QLA_SUCCESS; |
| 8022 | } |
| 8023 | |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 8024 | ret = qla24xx_set_fcp_prio(vha, fcport->loop_id, priority, mb); |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 8025 | if (ret == QLA_SUCCESS) { |
| 8026 | if (fcport->fcp_prio != priority) |
| 8027 | ql_dbg(ql_dbg_user, vha, 0x709e, |
| 8028 | "Updated FCP_CMND priority - value=%d loop_id=%d " |
| 8029 | "port_id=%02x%02x%02x.\n", priority, |
| 8030 | fcport->loop_id, fcport->d_id.b.domain, |
| 8031 | fcport->d_id.b.area, fcport->d_id.b.al_pa); |
Saurav Kashyap | a00f629 | 2011-11-18 09:03:19 -0800 | [diff] [blame] | 8032 | fcport->fcp_prio = priority & 0xf; |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 8033 | } else |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 8034 | ql_dbg(ql_dbg_user, vha, 0x704f, |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 8035 | "Unable to update FCP_CMND priority - ret=0x%x for " |
| 8036 | "loop_id=%d port_id=%02x%02x%02x.\n", ret, fcport->loop_id, |
| 8037 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 8038 | fcport->d_id.b.al_pa); |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 8039 | return ret; |
| 8040 | } |
| 8041 | |
| 8042 | /* |
| 8043 | * qla24xx_update_all_fcp_prio |
| 8044 | * Activates fcp priority for all the logged in ports |
| 8045 | * |
| 8046 | * Input: |
| 8047 | * ha = adapter block pointer. |
| 8048 | * |
| 8049 | * Return: |
| 8050 | * QLA_SUCCESS or QLA_FUNCTION_FAILED |
| 8051 | * |
| 8052 | * Context: |
| 8053 | * Kernel context. |
| 8054 | */ |
| 8055 | int |
| 8056 | qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha) |
| 8057 | { |
| 8058 | int ret; |
| 8059 | fc_port_t *fcport; |
| 8060 | |
| 8061 | ret = QLA_FUNCTION_FAILED; |
| 8062 | /* We need to set priority for all logged in ports */ |
| 8063 | list_for_each_entry(fcport, &vha->vp_fcports, list) |
| 8064 | ret = qla24xx_update_fcport_fcp_prio(vha, fcport); |
| 8065 | |
| 8066 | return ret; |
| 8067 | } |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 8068 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 8069 | struct qla_qpair *qla2xxx_create_qpair(struct scsi_qla_host *vha, int qos, |
| 8070 | int vp_idx, bool startqp) |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 8071 | { |
| 8072 | int rsp_id = 0; |
| 8073 | int req_id = 0; |
| 8074 | int i; |
| 8075 | struct qla_hw_data *ha = vha->hw; |
| 8076 | uint16_t qpair_id = 0; |
| 8077 | struct qla_qpair *qpair = NULL; |
| 8078 | struct qla_msix_entry *msix; |
| 8079 | |
| 8080 | if (!(ha->fw_attributes & BIT_6) || !ha->flags.msix_enabled) { |
| 8081 | ql_log(ql_log_warn, vha, 0x00181, |
| 8082 | "FW/Driver is not multi-queue capable.\n"); |
| 8083 | return NULL; |
| 8084 | } |
| 8085 | |
Himanshu Madhani | c38d1ba | 2017-10-13 15:43:22 -0700 | [diff] [blame] | 8086 | if (ql2xmqsupport || ql2xnvmeenable) { |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 8087 | qpair = kzalloc(sizeof(struct qla_qpair), GFP_KERNEL); |
| 8088 | if (qpair == NULL) { |
| 8089 | ql_log(ql_log_warn, vha, 0x0182, |
| 8090 | "Failed to allocate memory for queue pair.\n"); |
| 8091 | return NULL; |
| 8092 | } |
| 8093 | memset(qpair, 0, sizeof(struct qla_qpair)); |
| 8094 | |
| 8095 | qpair->hw = vha->hw; |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 8096 | qpair->vha = vha; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 8097 | qpair->qp_lock_ptr = &qpair->qp_lock; |
| 8098 | spin_lock_init(&qpair->qp_lock); |
Quinn Tran | af7bb38 | 2017-06-13 20:47:23 -0700 | [diff] [blame] | 8099 | qpair->use_shadow_reg = IS_SHADOW_REG_CAPABLE(ha) ? 1 : 0; |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 8100 | |
| 8101 | /* Assign available que pair id */ |
| 8102 | mutex_lock(&ha->mq_lock); |
| 8103 | 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] | 8104 | if (ha->num_qpairs >= ha->max_qpairs) { |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 8105 | mutex_unlock(&ha->mq_lock); |
| 8106 | ql_log(ql_log_warn, vha, 0x0183, |
| 8107 | "No resources to create additional q pair.\n"); |
| 8108 | goto fail_qid_map; |
| 8109 | } |
Sawan Chandak | b95b945 | 2017-05-24 18:06:20 -0700 | [diff] [blame] | 8110 | ha->num_qpairs++; |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 8111 | set_bit(qpair_id, ha->qpair_qid_map); |
| 8112 | ha->queue_pair_map[qpair_id] = qpair; |
| 8113 | qpair->id = qpair_id; |
| 8114 | qpair->vp_idx = vp_idx; |
himanshu.madhani@cavium.com | e6373f33 | 2017-08-23 15:04:57 -0700 | [diff] [blame] | 8115 | qpair->fw_started = ha->flags.fw_started; |
Quinn Tran | e326d22 | 2017-06-13 20:47:18 -0700 | [diff] [blame] | 8116 | INIT_LIST_HEAD(&qpair->hints_list); |
Duane Grigsby | cf19c45 | 2017-08-23 15:04:58 -0700 | [diff] [blame] | 8117 | INIT_LIST_HEAD(&qpair->nvme_done_list); |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 8118 | qpair->chip_reset = ha->base_qpair->chip_reset; |
| 8119 | qpair->enable_class_2 = ha->base_qpair->enable_class_2; |
| 8120 | qpair->enable_explicit_conf = |
| 8121 | ha->base_qpair->enable_explicit_conf; |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 8122 | |
| 8123 | for (i = 0; i < ha->msix_count; i++) { |
Quinn Tran | 093df73 | 2016-12-12 14:40:09 -0800 | [diff] [blame] | 8124 | msix = &ha->msix_entries[i]; |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 8125 | if (msix->in_use) |
| 8126 | continue; |
| 8127 | qpair->msix = msix; |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 8128 | ql_dbg(ql_dbg_multiq, vha, 0xc00f, |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 8129 | "Vector %x selected for qpair\n", msix->vector); |
| 8130 | break; |
| 8131 | } |
| 8132 | if (!qpair->msix) { |
| 8133 | ql_log(ql_log_warn, vha, 0x0184, |
| 8134 | "Out of MSI-X vectors!.\n"); |
| 8135 | goto fail_msix; |
| 8136 | } |
| 8137 | |
| 8138 | qpair->msix->in_use = 1; |
| 8139 | list_add_tail(&qpair->qp_list_elem, &vha->qp_list); |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 8140 | qpair->pdev = ha->pdev; |
| 8141 | if (IS_QLA27XX(ha) || IS_QLA83XX(ha)) |
| 8142 | qpair->reqq_start_iocbs = qla_83xx_start_iocbs; |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 8143 | |
| 8144 | mutex_unlock(&ha->mq_lock); |
| 8145 | |
| 8146 | /* Create response queue first */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 8147 | rsp_id = qla25xx_create_rsp_que(ha, 0, 0, 0, qpair, startqp); |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 8148 | if (!rsp_id) { |
| 8149 | ql_log(ql_log_warn, vha, 0x0185, |
| 8150 | "Failed to create response queue.\n"); |
| 8151 | goto fail_rsp; |
| 8152 | } |
| 8153 | |
| 8154 | qpair->rsp = ha->rsp_q_map[rsp_id]; |
| 8155 | |
| 8156 | /* Create request queue */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 8157 | req_id = qla25xx_create_req_que(ha, 0, vp_idx, 0, rsp_id, qos, |
| 8158 | startqp); |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 8159 | if (!req_id) { |
| 8160 | ql_log(ql_log_warn, vha, 0x0186, |
| 8161 | "Failed to create request queue.\n"); |
| 8162 | goto fail_req; |
| 8163 | } |
| 8164 | |
| 8165 | qpair->req = ha->req_q_map[req_id]; |
| 8166 | qpair->rsp->req = qpair->req; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 8167 | qpair->rsp->qpair = qpair; |
Quinn Tran | e326d22 | 2017-06-13 20:47:18 -0700 | [diff] [blame] | 8168 | /* init qpair to this cpu. Will adjust at run time. */ |
| 8169 | qla_cpu_update(qpair, smp_processor_id()); |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 8170 | |
| 8171 | if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) { |
| 8172 | if (ha->fw_attributes & BIT_4) |
| 8173 | qpair->difdix_supported = 1; |
| 8174 | } |
| 8175 | |
| 8176 | qpair->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep); |
| 8177 | if (!qpair->srb_mempool) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 8178 | ql_log(ql_log_warn, vha, 0xd036, |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 8179 | "Failed to create srb mempool for qpair %d\n", |
| 8180 | qpair->id); |
| 8181 | goto fail_mempool; |
| 8182 | } |
| 8183 | |
| 8184 | /* Mark as online */ |
| 8185 | qpair->online = 1; |
| 8186 | |
| 8187 | if (!vha->flags.qpairs_available) |
| 8188 | vha->flags.qpairs_available = 1; |
| 8189 | |
| 8190 | ql_dbg(ql_dbg_multiq, vha, 0xc00d, |
| 8191 | "Request/Response queue pair created, id %d\n", |
| 8192 | qpair->id); |
| 8193 | ql_dbg(ql_dbg_init, vha, 0x0187, |
| 8194 | "Request/Response queue pair created, id %d\n", |
| 8195 | qpair->id); |
| 8196 | } |
| 8197 | return qpair; |
| 8198 | |
| 8199 | fail_mempool: |
| 8200 | fail_req: |
| 8201 | qla25xx_delete_rsp_que(vha, qpair->rsp); |
| 8202 | fail_rsp: |
| 8203 | mutex_lock(&ha->mq_lock); |
| 8204 | qpair->msix->in_use = 0; |
| 8205 | list_del(&qpair->qp_list_elem); |
| 8206 | if (list_empty(&vha->qp_list)) |
| 8207 | vha->flags.qpairs_available = 0; |
| 8208 | fail_msix: |
| 8209 | ha->queue_pair_map[qpair_id] = NULL; |
| 8210 | clear_bit(qpair_id, ha->qpair_qid_map); |
Sawan Chandak | b95b945 | 2017-05-24 18:06:20 -0700 | [diff] [blame] | 8211 | ha->num_qpairs--; |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 8212 | mutex_unlock(&ha->mq_lock); |
| 8213 | fail_qid_map: |
| 8214 | kfree(qpair); |
| 8215 | return NULL; |
| 8216 | } |
| 8217 | |
| 8218 | int qla2xxx_delete_qpair(struct scsi_qla_host *vha, struct qla_qpair *qpair) |
| 8219 | { |
Sawan Chandak | d65237c | 2017-06-13 20:47:19 -0700 | [diff] [blame] | 8220 | int ret = QLA_FUNCTION_FAILED; |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 8221 | struct qla_hw_data *ha = qpair->hw; |
| 8222 | |
Sawan Chandak | d65237c | 2017-06-13 20:47:19 -0700 | [diff] [blame] | 8223 | if (!vha->flags.qpairs_req_created && !vha->flags.qpairs_rsp_created) |
| 8224 | goto fail; |
| 8225 | |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 8226 | qpair->delete_in_progress = 1; |
| 8227 | while (atomic_read(&qpair->ref_count)) |
| 8228 | msleep(500); |
| 8229 | |
| 8230 | ret = qla25xx_delete_req_que(vha, qpair->req); |
| 8231 | if (ret != QLA_SUCCESS) |
| 8232 | goto fail; |
| 8233 | ret = qla25xx_delete_rsp_que(vha, qpair->rsp); |
| 8234 | if (ret != QLA_SUCCESS) |
| 8235 | goto fail; |
| 8236 | |
| 8237 | mutex_lock(&ha->mq_lock); |
| 8238 | ha->queue_pair_map[qpair->id] = NULL; |
| 8239 | clear_bit(qpair->id, ha->qpair_qid_map); |
Sawan Chandak | b95b945 | 2017-05-24 18:06:20 -0700 | [diff] [blame] | 8240 | ha->num_qpairs--; |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 8241 | list_del(&qpair->qp_list_elem); |
Sawan Chandak | d65237c | 2017-06-13 20:47:19 -0700 | [diff] [blame] | 8242 | if (list_empty(&vha->qp_list)) { |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 8243 | vha->flags.qpairs_available = 0; |
Sawan Chandak | d65237c | 2017-06-13 20:47:19 -0700 | [diff] [blame] | 8244 | vha->flags.qpairs_req_created = 0; |
| 8245 | vha->flags.qpairs_rsp_created = 0; |
| 8246 | } |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 8247 | mempool_destroy(qpair->srb_mempool); |
| 8248 | kfree(qpair); |
| 8249 | mutex_unlock(&ha->mq_lock); |
| 8250 | |
| 8251 | return QLA_SUCCESS; |
| 8252 | fail: |
| 8253 | return ret; |
| 8254 | } |